From 01b1ecb46714c148f36403420ec91da7d6b64ef8 Mon Sep 17 00:00:00 2001 From: bal Date: Tue, 16 Apr 1985 15:24:23 +0000 Subject: [PATCH 0001/1625] Bug fixed for pattern 'sti $1 > 4' (ADDREG -> ADDSCR) Bug was present since version 1.1 --- mach/m68k2/cg/table | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/m68k2/cg/table b/mach/m68k2/cg/table index 2a327bf7..ef2ee0a8 100644 --- a/mach/m68k2/cg/table +++ b/mach/m68k2/cg/table @@ -461,7 +461,7 @@ sti $1 == 2 | ADDREG ANY | remove(MEM_ALL) move(%[2],{IADDREG,%[1]}) | | | sti $1 == 4 | ADDREG ANY4 | remove(MEM_ALL) move(%[2],{IADDREG4,%[1]}) | | | -sti $1 > 4 | ADDREG | remove(ALL) +sti $1 > 4 | ADDSCR | remove(ALL) allocate(DATAREG4={IMMEDIATE4,$1/2-1}) "1:" "move.w (sp)+,(%[1])+" From 37c5e5344e0cc8aa7d5f7b95cf042db4ae622b02 Mon Sep 17 00:00:00 2001 From: keie Date: Tue, 16 Apr 1985 16:14:55 +0000 Subject: [PATCH 0002/1625] Added provision to print (possibly in mach.h defined) modhead on the output assmble file as the very first text. --- mach/proto/cg/fillem.c | 6 ++++++ mach/proto/cg/main.c | 1 + 2 files changed, 7 insertions(+) diff --git a/mach/proto/cg/fillem.c b/mach/proto/cg/fillem.c index 074d4454..c4bf21d8 100644 --- a/mach/proto/cg/fillem.c +++ b/mach/proto/cg/fillem.c @@ -111,6 +111,12 @@ in_init(filename) char *filename; { error("Bad format %s",filename); } +in_start() { +#ifdef modhead + fprintf(codefile,"%s",modhead) ; +#endif +} + in_finish() { } diff --git a/mach/proto/cg/main.c b/mach/proto/cg/main.c index 08d5c46c..dc1c5113 100644 --- a/mach/proto/cg/main.c +++ b/mach/proto/cg/main.c @@ -67,6 +67,7 @@ main(argc,argv) char **argv; { error("Usage: %s EMfile [ asfile ]",progname); in_init(argv[0]); out_init(argv[1]); + in_start(); codegen(startupcode,maxply,TRUE,MAXINT,0); in_finish(); if (!endofprog) From 2aa3a9a5c5c6eff8f00f0cd54881f48634959aaa Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 17 Apr 1985 13:38:36 +0000 Subject: [PATCH 0003/1625] Er zat een bug in het patroon lol adp stl met $1 < 0. Ten onrechte werd in de gegenereerde code het AP register gebruikt. Dit moest natuurlijk FP zijn. --- mach/vax4/cg/table | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/vax4/cg/table b/mach/vax4/cg/table index 942fd12a..51117dc1 100644 --- a/mach/vax4/cg/table +++ b/mach/vax4/cg/table @@ -1830,7 +1830,7 @@ lol adp stl $1==$3 && inreg($1)==2 lol adp stl $1==$3 && $1<0 | | remove(displaced) remove(LOCALS,%[num]<=$1+3 && %[num]+%[size]>$1) - "addl2\t$$$2,$1(ap)" + "addl2\t$$$2,$1(fp)" setcc({LOCAL4,LB,$1,4}) | | | lol adp stl $1==$3 && $1>=0 | | remove(displaced) From f1bf649e1d2ac2d04f48615c165426bc79e33fad Mon Sep 17 00:00:00 2001 From: bal Date: Thu, 18 Apr 1985 15:12:06 +0000 Subject: [PATCH 0004/1625] Extra systems calls added --- mach/m68k2/libsys/LIST | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mach/m68k2/libsys/LIST b/mach/m68k2/libsys/LIST index 4fccdc16..6bc9b935 100644 --- a/mach/m68k2/libsys/LIST +++ b/mach/m68k2/libsys/LIST @@ -2,15 +2,20 @@ tail_mon.a exit.s _exit.s access.s +acct.s alarm.s chdir.s chmod.s +chown.s chroot.s close.s creat.s +dup.s +dup2.s execl.s execve.s fork.s +ftime.s getegid.s getgid.s getpid.s @@ -20,12 +25,15 @@ gtty.s ioctl.s kill.s link.s +lock.s lseek.s mknod.s mount.s nice.s open.s pause.s +pipe.s +profil.s read.s setgid.s setuid.s @@ -34,8 +42,10 @@ stime.s sync.s time.s times.s +umask.s umount.s unlink.s +utime.s write.s brk.s wait.s From 288206f080eb3260b886cdfa965adfa3beab9232 Mon Sep 17 00:00:00 2001 From: bal Date: Thu, 18 Apr 1985 15:12:29 +0000 Subject: [PATCH 0005/1625] Bug fixed: incorrect return value New version adapted from m68k4 version. --- mach/m68k2/libsys/signal.s | 47 ++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/mach/m68k2/libsys/signal.s b/mach/m68k2/libsys/signal.s index 8f18c1f8..90acbc54 100644 --- a/mach/m68k2/libsys/signal.s +++ b/mach/m68k2/libsys/signal.s @@ -1,9 +1,10 @@ + .define _signal .extern _signal NSIG=32 _signal: move.w 4(sp), d0 - ext.l d0 + ext.l d0 cmp.l #NSIG,d0 bcc 1f move.l 6(sp),d1 @@ -16,7 +17,9 @@ _signal: beq 2f btst #0,d1 bne 2f - move.l #enter,d1 + move.l #jmptab,d1 + add.l d0,d1 + add.l d0,d1 2: move.l d0,a0 move.w #0x30,d0 @@ -26,16 +29,52 @@ _signal: bne 4f move.l a1,d0 4: + clr.l d1 rts 1: move.l #22,d0 3: jmp cerror +jmptab: bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter enter: movem.l d0/d1/a0/a1,-(sp) - move.l 16(sp),a0 - move.l a0,-(sp) + move.l 16(sp),d0 + sub.l #jmptab+2,d0 + asr.l #1,d0 + move.l d0,-(sp) + move.l d0,a0 add.l a0,a0 add.l a0,a0 add.l #dvect,a0 From f45af8c7f435faaaddf06bb0d6e9ac5907b17884 Mon Sep 17 00:00:00 2001 From: bal Date: Thu, 18 Apr 1985 15:14:37 +0000 Subject: [PATCH 0006/1625] Initial revision --- mach/m68k2/libsys/acct.s | 6 ++++++ mach/m68k2/libsys/chown.s | 9 +++++++++ mach/m68k2/libsys/dup.s | 6 ++++++ mach/m68k2/libsys/dup2.s | 9 +++++++++ mach/m68k2/libsys/ftime.s | 6 ++++++ mach/m68k2/libsys/lock.s | 6 ++++++ mach/m68k2/libsys/pipe.s | 13 +++++++++++++ mach/m68k2/libsys/profil.s | 12 ++++++++++++ mach/m68k2/libsys/umask.s | 6 ++++++ mach/m68k2/libsys/utime.s | 7 +++++++ 10 files changed, 80 insertions(+) create mode 100644 mach/m68k2/libsys/acct.s create mode 100644 mach/m68k2/libsys/chown.s create mode 100644 mach/m68k2/libsys/dup.s create mode 100644 mach/m68k2/libsys/dup2.s create mode 100644 mach/m68k2/libsys/ftime.s create mode 100644 mach/m68k2/libsys/lock.s create mode 100644 mach/m68k2/libsys/pipe.s create mode 100644 mach/m68k2/libsys/profil.s create mode 100644 mach/m68k2/libsys/umask.s create mode 100644 mach/m68k2/libsys/utime.s diff --git a/mach/m68k2/libsys/acct.s b/mach/m68k2/libsys/acct.s new file mode 100644 index 00000000..b4ba8b61 --- /dev/null +++ b/mach/m68k2/libsys/acct.s @@ -0,0 +1,6 @@ +.define _acct +.extern _acct +.text +_acct: move.w #0x33,d0 + move.l 4(sp),a0 + jmp callc diff --git a/mach/m68k2/libsys/chown.s b/mach/m68k2/libsys/chown.s new file mode 100644 index 00000000..3e33b170 --- /dev/null +++ b/mach/m68k2/libsys/chown.s @@ -0,0 +1,9 @@ +.define _chown +.extern _chown +.text +_chown: move.w #0x10,d0 + move.l 4(sp),a0 + move.w 8(sp),d1 + ext.l d1 + move.w 10(sp),a1 + jmp callc diff --git a/mach/m68k2/libsys/dup.s b/mach/m68k2/libsys/dup.s new file mode 100644 index 00000000..75be7dde --- /dev/null +++ b/mach/m68k2/libsys/dup.s @@ -0,0 +1,6 @@ +.define _dup +.extern _dup +.text +_dup: move.w #0x29,d0 + move.w 4(sp),a0 + jmp call diff --git a/mach/m68k2/libsys/dup2.s b/mach/m68k2/libsys/dup2.s new file mode 100644 index 00000000..0227703c --- /dev/null +++ b/mach/m68k2/libsys/dup2.s @@ -0,0 +1,9 @@ +.define _dup2 +.extern _dup2 +.text +_dup2: move.w #0x29,d0 + move.w 4(sp),a0 + move.w 6(sp),d1 + ext.l d1 + add.l #0x40,a0 + jmp call diff --git a/mach/m68k2/libsys/ftime.s b/mach/m68k2/libsys/ftime.s new file mode 100644 index 00000000..432ed3f0 --- /dev/null +++ b/mach/m68k2/libsys/ftime.s @@ -0,0 +1,6 @@ +.define _ftime +.extern _ftime +.text +_ftime: move.w #0x23,d0 + move.l 4(sp),a0 + jmp callc diff --git a/mach/m68k2/libsys/lock.s b/mach/m68k2/libsys/lock.s new file mode 100644 index 00000000..9ed99574 --- /dev/null +++ b/mach/m68k2/libsys/lock.s @@ -0,0 +1,6 @@ +.define _lock +.extern _lock +.text +_lock: move.w #0x35,d0 + move.w 4(sp),a0 + jmp callc diff --git a/mach/m68k2/libsys/pipe.s b/mach/m68k2/libsys/pipe.s new file mode 100644 index 00000000..017adecf --- /dev/null +++ b/mach/m68k2/libsys/pipe.s @@ -0,0 +1,13 @@ +.define _pipe +.extern _pipe +_pipe: + move.w #0x2A,d0 + trap #0 + bcc 1f + jmp cerror +1: + move.l 4(sp),a0 + move.w d0,(a0)+ + move.w d1,(a0) + clr.l d0 + rts diff --git a/mach/m68k2/libsys/profil.s b/mach/m68k2/libsys/profil.s new file mode 100644 index 00000000..c38e4981 --- /dev/null +++ b/mach/m68k2/libsys/profil.s @@ -0,0 +1,12 @@ +.define _profil +.extern _profil +.text +_profil: move.w #0x2C,d0 + move.l 4(sp),a0 + move.w 8(sp),d1 + ext.l d1 + move.w 10(sp),a1 + move.w 12(sp),d2 + ext.l d2 + trap #0 + rts diff --git a/mach/m68k2/libsys/umask.s b/mach/m68k2/libsys/umask.s new file mode 100644 index 00000000..8eae00cd --- /dev/null +++ b/mach/m68k2/libsys/umask.s @@ -0,0 +1,6 @@ +.define _umask +.extern _umask +.text +_umask: move.w #0x3C,d0 + move.w 4(sp),a0 + jmp call diff --git a/mach/m68k2/libsys/utime.s b/mach/m68k2/libsys/utime.s new file mode 100644 index 00000000..0e0b6dd9 --- /dev/null +++ b/mach/m68k2/libsys/utime.s @@ -0,0 +1,7 @@ +.define _utime +.extern _utime +.text +_utime: move.w #0x1E,d0 + move.l 4(sp),a0 + move.l 8(sp),d1 + jmp callc From 7d5733c9d2b5b574251ac635b62b5de945431b8c Mon Sep 17 00:00:00 2001 From: keie Date: Thu, 18 Apr 1985 15:21:16 +0000 Subject: [PATCH 0007/1625] Now using arch.h, out.h and ranlib.h from ../../h --- util/led/archive.c | 10 +++++----- util/led/error.c | 2 +- util/led/extract.c | 2 +- util/led/finish.c | 2 +- util/led/main.c | 2 +- util/led/memory.c | 2 +- util/led/output.c | 2 +- util/led/read.c | 50 ++++++++++++++++++++++++++++++++++------------ util/led/save.c | 4 ++-- util/led/scan.c | 6 +++--- util/led/sym.c | 2 +- util/led/write.c | 2 +- 12 files changed, 55 insertions(+), 31 deletions(-) diff --git a/util/led/archive.c b/util/led/archive.c index f453256e..57e6fbdf 100644 --- a/util/led/archive.c +++ b/util/led/archive.c @@ -2,9 +2,9 @@ static char rcsid[] = "$Header$"; #endif -#include "arch.h" -#include "out.h" -#include "ranlib.h" +#include "../../h/arch.h" +#include "../../h/out.h" +#include "../../h/ranlib.h" #include "const.h" #include "debug.h" #include "defs.h" @@ -107,7 +107,7 @@ arch() get_archive_header(&arhdr); modulname = arhdr.ar_name; debug("%s defines %s\n", modulname, string, 0, 0); - position = ran->ran_pos + SZ_ARCH; + position = ran->ran_pos + AR_SIZE; resolved = TRUE; /* * This archive member is going to be linked, @@ -170,7 +170,7 @@ arch2() get_archive_header(&arhdr); modulname = arhdr.ar_name; debug("%s: archive member\n", modulname, 0, 0, 0); - position = *pos + SZ_ARCH; + position = *pos + AR_SIZE; finish(); } localpos += sizeof(long); /* Skip ENDLIB. */ diff --git a/util/led/error.c b/util/led/error.c index 59c011e2..689dfd6e 100644 --- a/util/led/error.c +++ b/util/led/error.c @@ -4,7 +4,7 @@ static char rcsid[] = "$Header$"; #include #include -#include "out.h" +#include "../../h/out.h" #include "const.h" static short nerrors = 0; diff --git a/util/led/extract.c b/util/led/extract.c index 1b186f3a..ef2b83ab 100644 --- a/util/led/extract.c +++ b/util/led/extract.c @@ -2,7 +2,7 @@ static char rcsid[] = "$Header$"; #endif -#include "out.h" +#include "../../h/out.h" #include "const.h" #include "debug.h" #include "defs.h" diff --git a/util/led/finish.c b/util/led/finish.c index 00125f67..57db0aa2 100644 --- a/util/led/finish.c +++ b/util/led/finish.c @@ -2,7 +2,7 @@ static char rcsid[] = "$Header$"; #endif -#include "out.h" +#include "../../h/out.h" #include "const.h" #include "defs.h" #include "memory.h" diff --git a/util/led/main.c b/util/led/main.c index 9f47cd16..e8a33420 100644 --- a/util/led/main.c +++ b/util/led/main.c @@ -7,7 +7,7 @@ static char rcsid[] = "$Header$"; */ #include -#include "out.h" +#include "../../h/out.h" #include "const.h" #include "debug.h" #include "defs.h" diff --git a/util/led/memory.c b/util/led/memory.c index 8069af18..8f4f527d 100644 --- a/util/led/memory.c +++ b/util/led/memory.c @@ -9,7 +9,7 @@ static char rcsid[] = "$Header$"; * is done and pieces after the one that requested the growth are moved up. */ -#include "out.h" +#include "../../h/out.h" #include "const.h" #include "assert.h" #include "debug.h" diff --git a/util/led/output.c b/util/led/output.c index 9547e9eb..42fc3a37 100644 --- a/util/led/output.c +++ b/util/led/output.c @@ -2,7 +2,7 @@ static char rcsid[] = "$Header$"; #endif -#include "out.h" +#include "../../h/out.h" #include "const.h" #include "memory.h" diff --git a/util/led/read.c b/util/led/read.c index f888a71a..d33da712 100644 --- a/util/led/read.c +++ b/util/led/read.c @@ -6,9 +6,9 @@ static char rcsid[] = "$Header$"; * Routines to read in the various parts of the object file. */ -#include "arch.h" -#include "out.h" -#include "ranlib.h" +#include "../../h/arch.h" +#include "../../h/out.h" +#include "../../h/ranlib.h" #include "const.h" #include "assert.h" @@ -52,19 +52,43 @@ read_head(head) fatal("bad magic number"); } -/* - * Someone inadvertently misaligned a long, thereby creating a hole. - * Therefore we can't read the header in one chunk. - */ +read1(fd, val) +char *val ; { + if ( read(fd, val, 1)!=1 ) return 0 ; + return 1 ; +} +read2(fd, val) +int *val ; { + char rch[2] ; + if ( read(fd, rch, 2)!=2 ) return 0 ; + *val= (rch[0]&0377) + ((rch[1]&0377)<<8) ; + return 1 ; +} +read4(fd, val) +long *val ; { + int v1,v2 ; + if ( !read2(fd, &v1) ) return 0 ; + if ( !read2(fd, &v2) ) return 0 ; + *val = ((long)v1<<16) + (unsigned)v2 ; + return 1 ; +} + + read_arhdr(arhdr) register struct ar_hdr *arhdr; { - if (read(infile, (char *)arhdr, 14) != 14) - fatal("premature EOF"); - if (read(infile, (char *)&arhdr->ar_date, SZ_ARCH - 14) != SZ_ARCH - 14) - fatal("premature EOF"); - if (bytes_reversed || words_reversed) - swap((char *)&arhdr->ar_date, SF_ARCH); + if ( read(infile,arhdr->ar_name,sizeof arhdr->ar_name)!= + sizeof arhdr->ar_name) { + goto peof ; + } + if ( !read4(infile,&arhdr->ar_date) ) goto peof ; + if ( !read1(infile,&arhdr->ar_uid) ) goto peof ; + if ( !read1(infile,&arhdr->ar_gid) ) goto peof ; + if ( !read2(infile,&arhdr->ar_mode) ) goto peof ; + if ( !read4(infile,&arhdr->ar_size) ) goto peof ; + return ; +peof: + fatal("Prematute EOF") ; } read_table(ran, cnt) diff --git a/util/led/save.c b/util/led/save.c index 807c79e6..26181996 100644 --- a/util/led/save.c +++ b/util/led/save.c @@ -6,8 +6,8 @@ static char rcsid[] = "$Header$"; * If everything is kept in core, we must save some things for the second pass. */ -#include "arch.h" -#include "out.h" +#include "../../h/arch.h" +#include "../../h/out.h" #include "const.h" #include "assert.h" #include "memory.h" diff --git a/util/led/scan.c b/util/led/scan.c index 32ed1efd..c98e51e9 100644 --- a/util/led/scan.c +++ b/util/led/scan.c @@ -6,9 +6,9 @@ static char rcsid[] = "$Header$"; #include #include #endif SYMDBUG -#include "arch.h" -#include "out.h" -#include "ranlib.h" +#include "../../h/arch.h" +#include "../../h/out.h" +#include "../../h/ranlib.h" #include "const.h" #include "assert.h" #include "memory.h" diff --git a/util/led/sym.c b/util/led/sym.c index b257fba6..335c404f 100644 --- a/util/led/sym.c +++ b/util/led/sym.c @@ -6,7 +6,7 @@ static char rcsid[] = "$Header$"; * Symbol table management. */ -#include "out.h" +#include "../../h/out.h" #include "const.h" #include "memory.h" diff --git a/util/led/write.c b/util/led/write.c index bb4014dc..c73d9b66 100644 --- a/util/led/write.c +++ b/util/led/write.c @@ -11,7 +11,7 @@ static char rcsid[] = "$Header$"; */ #include -#include "out.h" +#include "../../h/out.h" #include "const.h" #include "assert.h" #include "memory.h" From 08d8ed86d79011e446b0116a5986aad7b0fab456 Mon Sep 17 00:00:00 2001 From: keie Date: Thu, 18 Apr 1985 15:22:22 +0000 Subject: [PATCH 0008/1625] Now using out.h from ../../h --- util/led/relocate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/led/relocate.c b/util/led/relocate.c index 05d60482..4164a7af 100644 --- a/util/led/relocate.c +++ b/util/led/relocate.c @@ -2,7 +2,7 @@ static char rcsid[] = "$Header$"; #endif -#include "out.h" +#include "../../h/out.h" #include "const.h" #include "debug.h" #include "defs.h" From cd93fdaeb04819b912321f94669ff3600fc0e6a2 Mon Sep 17 00:00:00 2001 From: keie Date: Fri, 19 Apr 1985 13:28:56 +0000 Subject: [PATCH 0009/1625] Added assignment for debuuging info. --- util/led/extract.c | 1 + 1 file changed, 1 insertion(+) diff --git a/util/led/extract.c b/util/led/extract.c index ef2b83ab..d0b9b723 100644 --- a/util/led/extract.c +++ b/util/led/extract.c @@ -175,6 +175,7 @@ getexternal(name) entername(name, h); } else if (!ISUNDEFINED(name)) { if (ISUNDEFINED(old)) { + name->on_mptr = string; /* Just for convenience. */ transfer(name, old); } else { name->on_mptr = string; /* Just for convenience. */ From 8ab4d76d42ef5abf034d89f9493b55c2ae8836db Mon Sep 17 00:00:00 2001 From: em Date: Mon, 22 Apr 1985 14:12:26 +0000 Subject: [PATCH 0010/1625] *** empty log message *** --- mach/m68k2/cv/Makefile | 21 ++++++++ mach/m68k2/cv/cv.prev.c | 104 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 mach/m68k2/cv/Makefile create mode 100644 mach/m68k2/cv/cv.prev.c diff --git a/mach/m68k2/cv/Makefile b/mach/m68k2/cv/Makefile new file mode 100644 index 00000000..d3203806 --- /dev/null +++ b/mach/m68k2/cv/Makefile @@ -0,0 +1,21 @@ +CFLAGS=-O -I../../../h + +cv: cv.o + $(CC) -o cv -n cv.o + +install: ins_cv +ins_cv: cv + ../../install cv + +cmp: cmp_cv +cmp_cv: cv + -../../compare cv + +opr: + make pr | opr + +pr: + @pr `pwd`/cv.c + +clean: + -rm -f *.o *.old cv diff --git a/mach/m68k2/cv/cv.prev.c b/mach/m68k2/cv/cv.prev.c new file mode 100644 index 00000000..89087415 --- /dev/null +++ b/mach/m68k2/cv/cv.prev.c @@ -0,0 +1,104 @@ +#include +#include "out.h" + +#define ASSERT(x) switch (2) { case 0: case (x): ; } + +/* + * Header and section table of new format object file. + */ +struct outhead outhead; +struct outsect outsect[S_MAX]; + +char *output_file; +int output_file_created; + +main(argc, argv) + int argc; + char *argv[]; +{ + register int nsect; + register struct outsect *sectp; + register FILE *input; + register FILE *output; + + ASSERT(sizeof(struct outhead) == SZ_HEAD); + ASSERT(sizeof(struct outsect) == SZ_SECT); + + input = stdin; output = stdout; + switch (argc) { + case 1: break; + case 3: if ((output = fopen(argv[2], "w")) == (FILE *)0) + fatal("Can't write %s.\n", argv[2]); + output_file = argv[2]; + output_file_created = 1; + /* FALLTHROUGH */ + case 2: if ((input = fopen(argv[1], "r")) == (FILE *)0) + fatal("Can't read %s.\n", argv[1]); + break; + default:fatal("Usage: %s
.\n", argv[0]); + } + if (fread((char *)&outhead, SZ_HEAD, 1, input) != 1) + fatal("Reading header failed.\n"); + if (BADMAGIC(outhead)) + fatal("Not an ack object file.\n"); + if (outhead.oh_nrelo > 0) + fprintf(stderr, "Warning: relocation information present.\n"); + nsect = outhead.oh_nsect; + if (fread((char *)outsect, SZ_SECT, nsect, input) != nsect) + fatal("Reading section table failed.\n"); + sectp = outsect; + while (nsect--) { + register long flen; +#ifdef DO_BSS + register long zero; +#endif DO_BSS + long base; + short cnt; + char buffer[BUFSIZ]; + + base = sectp->os_base; + flen = sectp->os_flen; +#ifdef DO_BSS + zero = sectp->os_size - flen; +#endif DO_BSS + + while (flen) { + cnt = flen > BUFSIZ ? BUFSIZ : flen; + if (fread((char *)buffer, 1, cnt, input) != cnt) + fatal("Reading code bytes failed.\n"); + if (fwrite((char *)&base, 4, 1, output) != 1) + fatal("Writing start address failed.\n"); + if (fwrite((char *)&cnt, 2, 1, output) != 1) + fatal("Writing byte count failed.\n"); + if (fwrite((char *)buffer, 1, cnt, output) != cnt) + fatal("Writing byte count failed.\n"); + base += cnt; + flen -= cnt; + } +#ifdef DO_BSS + while (zero) { + cnt = zero > BUFSIZ ? BUFSIZ : zero; + if (fwrite((char *)&base, 4, 1, output) != 1) + fatal("Writing start address failed.\n"); + if (fwrite((char *)&cnt, 2, 1, output) != 1) + fatal("Writing byte count failed.\n"); + if (fseek(output, (long)cnt, 1) < (long)0) + fatal("Fseek failed.\n"); + base += cnt; + zero -= cnt; + } +#endif DO_BSS + sectp++; + } + exit(0); +} + +/* VARARGS1 */ +fatal(s, a1, a2) + char *s; +{ + fprintf(stderr, s, a1, a2); + if (output_file_created) + unlink(output_file); + exit(-1); +} From 733ac47e2235d6a51371525857ad9e9dcd4a3c57 Mon Sep 17 00:00:00 2001 From: em Date: Mon, 22 Apr 1985 15:13:24 +0000 Subject: [PATCH 0011/1625] The reading of the input is now machine independent. --- mach/m68k2/cv/cv.prev.c | 68 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 3 deletions(-) diff --git a/mach/m68k2/cv/cv.prev.c b/mach/m68k2/cv/cv.prev.c index 89087415..ba342fb9 100644 --- a/mach/m68k2/cv/cv.prev.c +++ b/mach/m68k2/cv/cv.prev.c @@ -1,6 +1,10 @@ #include #include "out.h" +#ifndef NORCSID +static char rcs_id[] = "$Header$" ; +#endif + #define ASSERT(x) switch (2) { case 0: case (x): ; } /* @@ -12,6 +16,8 @@ struct outsect outsect[S_MAX]; char *output_file; int output_file_created; +char *program ; + main(argc, argv) int argc; char *argv[]; @@ -25,6 +31,7 @@ main(argc, argv) ASSERT(sizeof(struct outsect) == SZ_SECT); input = stdin; output = stdout; + program= argv[0] ; switch (argc) { case 1: break; case 3: if ((output = fopen(argv[2], "w")) == (FILE *)0) @@ -37,15 +44,16 @@ main(argc, argv) break; default:fatal("Usage: %s
.\n", argv[0]); } - if (fread((char *)&outhead, SZ_HEAD, 1, input) != 1) + if ( !rhead(input,&outhead) ) fatal("Reading header failed.\n"); if (BADMAGIC(outhead)) fatal("Not an ack object file.\n"); if (outhead.oh_nrelo > 0) fprintf(stderr, "Warning: relocation information present.\n"); + for ( nsect=0 ; nsect9 ) fatal("illegal out.h format string\n"); + value=0 ; + i=last ; + while ( i-- ) { + value = (value<<8) + (ni[i]&0xFF) ; + } + switch ( last ) { + case 0 : break ; + case 1 : *no= value ; break ; + case 2 : *(unsigned short *)no = value ; break ; + case 4 : *(long *)no = value ; break ; + default : + fatal("illegal out.h format string\n"); + } + ni += last ; no += last ; + } +} + /* VARARGS1 */ fatal(s, a1, a2) char *s; { + fprintf(stderr,"%s: ",program) ; fprintf(stderr, s, a1, a2); if (output_file_created) unlink(output_file); From eb92039acddce4302dd152a691747a099c935b56 Mon Sep 17 00:00:00 2001 From: keie Date: Tue, 23 Apr 1985 12:55:01 +0000 Subject: [PATCH 0012/1625] Add hoc solution of .align problem. --- mach/proto/as/comm6.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mach/proto/as/comm6.c b/mach/proto/as/comm6.c index 624b143a..da76ed95 100644 --- a/mach/proto/as/comm6.c +++ b/mach/proto/as/comm6.c @@ -254,8 +254,9 @@ valu_t bytes; DOTGAIN += (bytes - 1) - gap; #endif } - DOTVAL += gap; - sp->s_zero += gap; + /* I don't play the os_zero game here, but plainly write out zero's */ + /* Led abuses trailing zero parts */ + while (gap--) emit1(0) ; } #ifdef RELOCATION From aeb2d50790ff2d9c5e519d03c1739835e11dc4aa Mon Sep 17 00:00:00 2001 From: keie Date: Thu, 25 Apr 1985 13:37:59 +0000 Subject: [PATCH 0013/1625] Changed trap number into bit shifted by number for ignore mask. The whole example is, at leat, unclear. The trap for EFOVL never occurs! --- doc/em/iotrap.nr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/em/iotrap.nr b/doc/em/iotrap.nr index c5a5fa2d..716f363b 100644 --- a/doc/em/iotrap.nr +++ b/doc/em/iotrap.nr @@ -338,7 +338,7 @@ msave lim ; get current ignore mask ste msave ; save it lim - loc 4 ; bit for EFOVFL + loc 16 ; bit for EFOVFL ior 2 ; set in mask sim ; ignore EFOVFL from now on lpi $catch ; load procedure identifier From 7c28e6c98a4fadbe4163a75e6d1a2c2b96299d4e Mon Sep 17 00:00:00 2001 From: keie Date: Mon, 29 Apr 1985 11:55:30 +0000 Subject: [PATCH 0014/1625] Added a message to the effect that 'local commons' can not be handled. --- util/led/extract.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/util/led/extract.c b/util/led/extract.c index d0b9b723..4ed5cec5 100644 --- a/util/led/extract.c +++ b/util/led/extract.c @@ -139,8 +139,10 @@ namerelocate(name, sects) if ((type & S_TYP) == S_UND || (type & S_TYP) == S_ABS) return; - if (type & S_COM) + if (type & S_COM) { + if ( ! (type&S_EXT) ) fatal("local commons should be handled by the assembler") ; return; + } sectindex = (type & S_TYP) - S_MIN; if (name->on_valu >= sects[sectindex].os_flen) { From 4028e98820b0790360be6e7ea4e82568141fd6f2 Mon Sep 17 00:00:00 2001 From: bal Date: Wed, 1 May 1985 12:53:33 +0000 Subject: [PATCH 0015/1625] Bug fixed: cg generated instructions like "and.l #2,a4", which are not allowed on the 68000. The condition "inreg($...) < 2" is added to every EM-pattern that accesses local non-register variables. So the ordering of the patterns for regvar/non-regvar is no longer important. --- mach/m68k2/cg/table | 108 +++++++++++++++----------------------------- 1 file changed, 36 insertions(+), 72 deletions(-) diff --git a/mach/m68k2/cg/table b/mach/m68k2/cg/table index ef2ee0a8..9fc55736 100644 --- a/mach/m68k2/cg/table +++ b/mach/m68k2/cg/table @@ -682,18 +682,6 @@ loc lil and sil $2 == $4 && $3 == 2 && inreg($2)==2 | | lil and sil $1 == $3 && $2 == 2 && inreg($1)==2 | DATAREG | remove(MEM_ALL) "and.w %[1],(%(regvar($1)%))" | | | -ldl ldc and sdl $1 == $4 && $3 == 4 && inreg($1)==2 | | - remove(regvar($1)) - "and.l #$2,%(regvar($1)%)" - erase(regvar($1)) | | | -ldc ldl and sdl $2 == $4 && $3 == 4 && inreg($2)==2 | | - remove(regvar($2)) - "and.l #$1,%(regvar($2)%)" - erase(regvar($2)) | | | -ldl and sdl $1 == $3 && $2 == 4 && inreg($1)==2 | DATAREG4 | - remove(regvar($1)) - "and.l %[1],%(regvar($1)%)" - erase(regvar($1)) | | | lol ior stl $1 == $3 && $2 == 2 && inreg($1)==2 | ANY | remove(regvar($1)) "or.w %[1],%(regvar($1)%)" @@ -704,18 +692,6 @@ lil ior sil $1 == $3 && $2 == 2 && inreg($1)==2 | DATAREG | loc lil ior sil $2 == $4 && $3 == 2 && inreg($2)==2 | | remove(MEM_ALL) "or.w #$1,(%(regvar($2)%))" | | | -ldl ldc ior sdl $1 == $4 && $3 == 4 && inreg($1)==2 | | - remove(regvar($1)) - "or.l #$2,%(regvar($1)%)" - erase(regvar($1)) | | | -ldc ldl ior sdl $2 == $4 && $3 == 4 && inreg($2)==2 | | - remove(regvar($2)) - "or.l #$1,%(regvar($2)%)" - erase(regvar($2)) | | | -ldl ior sdl $1 == $3 && $2 == 4 && inreg($1)==2 | DATAREG4 | - remove(regvar($1)) - "or.l %[1],%(regvar($1)%)" - erase(regvar($1)) | | | lol loc xor stl $1 == $4 && $3 == 2 && inreg($1)==2 | | remove(regvar($1)) "eor.w #$2,%(regvar($1)%)" @@ -734,18 +710,6 @@ lol xor stl $1 == $3 && $2 == 2 && inreg($1)==2 | DATAREG | lil xor sil $1 == $3 && $2 == 2 && inreg($1)==2 | DATAREG | remove(MEM_ALL) "eor.w %[1],(%(regvar($1)%))" | | | -ldl ldc xor sdl $1 == $4 && $3 == 4 && inreg($1)==2 | | - remove(regvar($1)) - "eor.l #$2,%(regvar($1)%)" - erase(regvar($1)) | | | -ldc ldl xor sdl $2 == $4 && $3 == 4 && inreg($2)==2 | | - remove(regvar($2)) - "eor.l #$1,%(regvar($2)%)" - erase(regvar($2)) | | | -ldl xor sdl $1 == $3 && $2 == 4 && inreg($1)==2 | DATAREG4 | - remove(regvar($1)) - "eor.l %[1],%(regvar($1)%)" - erase(regvar($1)) | | | #endif /* G R O U P III AND IV : I N T E G E R A R I T H M E T I C */ @@ -784,10 +748,10 @@ adi $1 == 4 | ANY4 DATASCR4 | "add.l %[1],%[2]" ... | DATASCR4 ANY4 | "add.l %[2],%[1]" erase(%[1]) setcc(%[1]) | %[1] | | (2,3)+%[2] -ldl ldc adi sdl $1 == $4 && $3 == 4 | | +ldl ldc adi sdl $1 == $4 && $3 == 4 && inreg($1) < 2 | | remove(MEM_ALL) "add.l #$2,$1(a6)" | | | (8,16) -ldc ldl adi sdl $2 == $4 && $3 == 4 | | +ldc ldl adi sdl $2 == $4 && $3 == 4 && inreg($2) < 2 | | remove(MEM_ALL) "add.l #$1,$2(a6)" | | | (8,16) lde ldc adi sde $3 == 4 && $1 == $4 | | @@ -796,7 +760,7 @@ lde ldc adi sde $3 == 4 && $1 == $4 | | ldc lde adi sde $3 == 4 && $2 == $4 | | remove(MEM_ALL) "add.l #$1,$2" | | | (9,17) -ldl adi sdl $1 == $3 && $2 == 4 | DATAREG4 | +ldl adi sdl $1 == $3 && $2 == 4 && inreg($1) < 2 | DATAREG4 | remove(MEM_ALL) "add.l %[1],$1(a6)" | | | lde adi sde $1 == $3 && $2 == 4 | DATAREG4 | @@ -805,7 +769,7 @@ lde adi sde $1 == $3 && $2 == 4 | DATAREG4 | sbi $1 == 2 | ANY DATASCR | "sub.w %[1],%[2]" erase(%[2]) setcc(%[2]) | %[2] | | (2,2)+%[1] -lol loc sbi stl $1 == $4 && $3 == 2 | | +lol loc sbi stl $1 == $4 && $3 == 2 && inreg($1) < 2 | | remove(MEM_ALL) "sub.w #$2,$1(a6)" | | | (6,10) loe loc sbi ste $3 == 2 && $1 == $4 | | @@ -818,7 +782,7 @@ lil loc adi sil $1 == $4 && $3 == 2 | | sbi $1 == 4 | ANY4 DATASCR4 | "sub.l %[1],%[2]" erase(%[2]) setcc(%[2]) | %[2] | | (2,3)+%[1] -ldl ldc sbi sdl $1 == $4 && $3 == 4 | | +ldl ldc sbi sdl $1 == $4 && $3 == 4 && inreg($1) < 2 | | remove(MEM_ALL) "sub.l #$2,$1(a6)" | | | (8,16) lde ldc sbi sde $3 == 4 && $1 == $4 | | @@ -847,7 +811,7 @@ rmi $1 == 4 | | remove(ALL) ngi $1 == 2 | DATASCR | "neg %[1]" erase(%[1]) setcc(%[1]) | %[1] | | -lol ngi stl $1 == $3 && $2 == 2 | | +lol ngi stl $1 == $3 && $2 == 2 && inreg($1) < 2 | | remove(MEM_ALL) "neg.w $1(a6)" | | | loe ngi ste $1 == $3 && $2 == 2 | | @@ -860,7 +824,7 @@ lil ngi sil $1 == $3 && $2 == 2 | | ngi $1 == 4 | DATASCR4 | "neg.l %[1]" erase(%[1]) setcc(%[1]) | %[1] | | -lol ngi stl $1 == $3 && $2 == 4 | | +lol ngi stl $1 == $3 && $2 == 4 && inreg($1) < 2 | | remove(MEM_ALL) "neg.l $1(a6)" | | | loe ngi ste $1 == $3 && $2 == 4 | | @@ -884,7 +848,7 @@ lol loc sli ads inreg($1) == 2 && $2 == 1 && $3 == 2 && $4 == 2 | ADDSCR | "add.w %(regvar($1)%),%[1]" "add.w %(regvar($1)%),%[1]" erase(%[1]) | %[1] | | -lol loc sli stl $1 == $4 && $2 == 1 && $3 == 2 | | +lol loc sli stl $1 == $4 && $2 == 1 && $3 == 2 && inreg($1) < 2 | | remove(MEM_ALL) "asl.w #1, $1(a6)" | | | loe loc sli ste $1 == $4 && $2 == 1 && $3 == 2 | | @@ -902,7 +866,7 @@ loc sri $1 >= 1 && $1 <= 8 && $2 == 2 | DATASCR | loc sri $1 >= 1 && $1 <= 8 && $2 == 4 | DATASCR4 | "asr.l #$1,%[1]" erase(%[1]) | %[1] | | -lol loc sri stl $1 == $4 && $2 == 1 && $3 == 2 | | +lol loc sri stl $1 == $4 && $2 == 1 && $3 == 2 && inreg($1) < 2 | | remove(MEM_ALL) "asr.w #1,$1(a6)" | | | loe loc sri ste $1 == $4 && $2 == 1 && $3 == 2 | | @@ -941,7 +905,7 @@ loc sru $1 >= 1 && $1 <= 8 && $2 == 2 | DATASCR | loc sru $1 >= 1 && $1 <= 8 && $2 == 4 | DATASCR4 | "lsr.l #$1,%[1]" erase(%[1]) | %[1] | | -lol loc sru stl $1 == $4 && $2 == 1 && $3 == 2 | | +lol loc sru stl $1 == $4 && $2 == 1 && $3 == 2 && inreg($1) < 2 | | remove(MEM_ALL) "lsr.w #1,$1(a6)" | | | loe loc sru ste $1 == $4 && $2 == 1 && $3 == 2 | | @@ -985,10 +949,10 @@ loe loc adu ste $3 == 2 && $1 == $4 | | loc loe adu ste $3 == 2 && $2 == $4 | | remove(MEM_ALL) "add.w #$1,$2" | | | (7,11) -ldl ldc adu sdl $1 == $4 && $3 == 4 | | +ldl ldc adu sdl $1 == $4 && $3 == 4 && inreg($1) < 2 | | remove(MEM_ALL) "add.l #$2,$1(a6)" | | | (8,16) -ldc ldl adu sdl $2 == $4 && $3 == 4 | | +ldc ldl adu sdl $2 == $4 && $3 == 4 && inreg($2) < 2 | | remove(MEM_ALL) "add.l #$1,$2(a6)" | | | (8,16) lde ldc adu sde $3 == 4 && $1 == $4 | | @@ -997,13 +961,13 @@ lde ldc adu sde $3 == 4 && $1 == $4 | | ldc lde adu sde $3 == 4 && $2 == $4 | | remove(MEM_ALL) "add.l #$1,$2" | | | (9,17) -ldl adu sdl $1 == $3 && $2 == 4 | DATAREG4 | +ldl adu sdl $1 == $3 && $2 == 4 && inreg($1) < 2 | DATAREG4 | remove(MEM_ALL) "add.l %[1],$1(a6)" | | | lde adu sde $1 == $3 && $2 == 4 | DATAREG4 | remove(MEM_ALL) "add.l %[1],$1" | | | -lol loc sbu stl $1 == $4 && $3 == 2 | | +lol loc sbu stl $1 == $4 && $3 == 2 && inreg($1) < 2 | | remove(MEM_ALL) "sub.w #$2,$1(a6)" | | | (6,10) loe loc sbu ste $3 == 2 && $1 == $4 | | @@ -1013,7 +977,7 @@ lil loc adu sil $1 == $4 && $3 == 2 | | allocate(ADDREG = {DISPL4,LB,$1}) remove(MEM_ALL) "add.w #$2,(%[a])" | | | -ldl ldc sbu sdl $1 == $4 && $3 == 4 | | +ldl ldc sbu sdl $1 == $4 && $3 == 4 && inreg($1) < 2 | | remove(MEM_ALL) "sub.l #$2,$1(a6)" | | | (8,16) lde ldc sbu sde $3 == 4 && $1 == $4 | | @@ -1025,7 +989,7 @@ loc slu $1 >= 1 && $1 <= 8 && $2 == 2 | DATASCR | loc slu $1 >= 1 && $1 <= 8 && $2 == 4 | DATASCR4 | "asl.l #$1,%[1]" erase(%[1]) | %[1] | | -lol loc slu stl $1 == $4 && $2 == 1 && $3 == 2 | | +lol loc slu stl $1 == $4 && $2 == 1 && $3 == 2 && inreg($1) < 2 | | remove(MEM_ALL) "asl.w #1,$1(a6)" | | | loe loc slu ste $1 == $4 && $2 == 1 && $3 == 2 | | @@ -1108,7 +1072,7 @@ adp | nocoercions: EXTERNAL_ADDR | | {EXTERNAL_ADDR,%[1.off] + "+" setcc(%[1]) | %[1] | | /* The next patterns are for efficient translation of "*p++" in C */ -ldl ldl adp sdl $1 == $2 && $2 == $4 | | +ldl ldl adp sdl $1 == $2 && $2 == $4 && inreg($1) < 2 | | allocate(ADDREG={DISPL4,LB,$1}) remove(DISPL,%[reg] == LB && (%[dis] == $1 || %[dis] == $1+2)) remove(DISPL4,%[reg] == LB && (%[dis] >= $1-2 && @@ -1130,7 +1094,7 @@ lde lde adp sde $1 == $2 && $2 == $4 | | remove(DISPL1,%[reg] != LB) remove(ALL_ACCESSIBLE) "add.l #$3,$1" | %[a] | | -ldl adp sdl $1 == $3 | | remove(MEM_ALL) +ldl adp sdl $1 == $3 && inreg($1) < 2 | | remove(MEM_ALL) "add.l #$2,$1(a6)" | | | (8,16) lde adp sde $1 == $3 | | remove(MEM_ALL) "add.l #$2,$1" | | | (9,17) @@ -1140,16 +1104,16 @@ ads $1 == 2 | ANY ADDSCR | "add.w %[1],%[2]" ads $1 == 4 | ANY4 ADDSCR | "add.l %[1],%[2]" erase(%[2]) setcc(%[2]) | %[2] | | -loc ldl ads sdl $2 == $4 && $3 == 2 | | +loc ldl ads sdl $2 == $4 && $3 == 2 && inreg($2) < 2 | | remove(MEM_ALL) "add.l #$1,$2(a6)" | | | (8,16) lde loc ads sde $3 == 2 && $1 == $4 | | remove(MEM_ALL) "add.l #$2,$1" | | | (9,17) -ldl ldc ads sdl $1 == $4 && $3 == 4 | | +ldl ldc ads sdl $1 == $4 && $3 == 4 && inreg($1) < 2 | | remove(MEM_ALL) "add.l #$2,$1(a6)" | | | (8,16) -ldc ldl ads sdl $2 == $4 && $3 == 4 | | +ldc ldl ads sdl $2 == $4 && $3 == 4 && inreg($2) < 2 | | remove(MEM_ALL) "add.l #$1,$2(a6)" | | | (8,16) lde ldc ads sde $3 == 4 && $1 == $4 | | @@ -1202,7 +1166,7 @@ zrl inreg($1)==2 | | remove(regvar($1)) erase(regvar($1)) setcc(regvar($1)) | | | #endif -inl | | remove(DISPL,%[reg] == LB && %[dis] == $1) +inl inreg($1) < 2 | | remove(DISPL,%[reg] == LB && %[dis] == $1) remove(DISPL4,%[reg] == LB && (%[dis] == $1-2 || %[dis] == $1)) remove(DISPL1,%[reg] == LB && (%[dis] == $1 || @@ -1227,7 +1191,7 @@ dec | DATASCR | "sub.w #1,%[1]" erase(%[1]) setcc(%[1]) | %[1] | | ... | STACK | "sub.w #1,(sp)" | | | -del | | remove(DISPL,%[reg] == LB && %[dis] == $1) +del inreg($1) < 2 | | remove(DISPL,%[reg] == LB && %[dis] == $1) remove(DISPL4,%[reg] == LB && (%[dis] == $1-2 || %[dis] == $1)) remove(DISPL1,%[reg] == LB && (%[dis] == $1 || @@ -1248,7 +1212,7 @@ dee | | remove(ALL_ACCESSIBLE) "sub.w #1,$1" setcc({ABS,$1}) | | | -zrl | | remove(DISPL,%[reg] == LB && %[dis] == $1) +zrl inreg($1) < 2 | | remove(DISPL,%[reg] == LB && %[dis] == $1) remove(DISPL4,%[reg] == LB && (%[dis] == $1-2 || %[dis] == $1)) remove(DISPL1,%[reg] == LB && (%[dis] == $1 || @@ -1474,10 +1438,10 @@ and defined($1) && $1 == 4 | ANY4-ADDREG DATASCR4 | "and.l %[2],%[1]" erase(%[1]) setcc(%[1]) | %[1] | | (2,3)+%[2] -ldl ldc and sdl $1 == $4 && $3 == 4 | | +ldl ldc and sdl $1 == $4 && $3 == 4 && inreg($1) < 2 | | remove(MEM_ALL) "and.l #$2,$1(a6)" | | | (8,16) -ldc ldl and sdl $2 == $4 && $3 == 4 | | +ldc ldl and sdl $2 == $4 && $3 == 4 && inreg($2) < 2 | | remove(MEM_ALL) "and.l #$1,$2(a6)" | | | (8,16) lde ldc and sde $3 == 4 && $1 == $4 | | @@ -1486,7 +1450,7 @@ lde ldc and sde $3 == 4 && $1 == $4 | | ldc lde and sde $3 == 4 && $2 == $4 | | remove(MEM_ALL) "and.l #$1,$2" | | | (9,17) -ldl and sdl $1 == $3 && $2 == 4 | DATAREG4 | +ldl and sdl $1 == $3 && $2 == 4 && inreg($1) < 2 | DATAREG4 | remove(MEM_ALL) "and.l %[1],$1(a6)" | | | lde and sde $1 == $3 && $2 == 4 | DATAREG4 | @@ -1554,10 +1518,10 @@ ior defined($1) && $1 == 4 | ANY4-ADDREG DATASCR4 | "or.l %[2],%[1]" erase(%[1]) setcc(%[1]) | %[1] | |(2,3)+%[2] -ldl ldc ior sdl $1 == $4 && $3 == 4 | | +ldl ldc ior sdl $1 == $4 && $3 == 4 && inreg($1) < 2 | | remove(MEM_ALL) "or.l #$2,$1(a6)" | | | (8,16) -ldc ldl ior sdl $2 == $4 && $3 == 4 | | +ldc ldl ior sdl $2 == $4 && $3 == 4 && inreg($2) < 2 | | remove(MEM_ALL) "or.l #$1,$2(a6)" | | | (8,16) lde ldc ior sde $3 == 4 && $1 == $4 | | @@ -1566,7 +1530,7 @@ lde ldc ior sde $3 == 4 && $1 == $4 | | ldc lde ior sde $3 == 4 && $2 == $4 | | remove(MEM_ALL) "or.l #$1,$2" | | | (9,17) -ldl ior sdl $1 == $3 && $2 == 4 | DATAREG4 | +ldl ior sdl $1 == $3 && $2 == 4 && inreg($1) < 2 | DATAREG4 | remove(MEM_ALL) "or.l %[1],$1(a6)" | | | lde ior sde $1 == $3 && $2 == 4 | DATAREG4 | @@ -1603,10 +1567,10 @@ lal loi xor lal sti $1 == $4 && $2 == 1 && $3 == 2 && $5 == 1 && inreg($1) < 2 | DATAREG | remove(MEM_ALL) "eor.b %[1],$1(a6)" | | | -lol loc xor stl $1 == $4 && $3 == 2 | | +lol loc xor stl $1 == $4 && $3 == 2 && inreg($1) < 2 | | remove(MEM_ALL) "eor.w #$2,$1(a6)" | | | (6,10) -loc lol xor stl $2 == $4 && $3 == 2 | | +loc lol xor stl $2 == $4 && $3 == 2 && inreg($2) < 2 | | remove(MEM_ALL) "eor.w #$1,$2(a6)" | | | (6,10) loe loc xor ste $3 == 2 && $1 == $4 | | @@ -1619,7 +1583,7 @@ loc lil xor sil $2 == $4 && $3 == 2 | | allocate(ADDREG = {DISPL4,LB,$2}) remove(MEM_ALL) "eor.w #$1,(%[a])" | | | -lol xor stl $1 == $3 && $2 == 2 | DATAREG | +lol xor stl $1 == $3 && $2 == 2 && inreg($1) < 2 | DATAREG | remove(MEM_ALL) "eor.w %[1],$1(a6)" | | | loe xor ste $1 == $3 && $2 == 2 | DATAREG | @@ -1637,10 +1601,10 @@ xor defined($1) && $1 == 4 | DATAREG4 DATASCR4 | "eor.l %[2],%[1]" erase(%[1]) setcc(%[1]) | %[1] | | (2,3)+%[2] -ldl ldc xor sdl $1 == $4 && $3 == 4 | | +ldl ldc xor sdl $1 == $4 && $3 == 4 && inreg($1) < 2 | | remove(MEM_ALL) "eor.l #$2,$1(a6)" | | | (8,16) -ldc ldl xor sdl $2 == $4 && $3 == 4 | | +ldc ldl xor sdl $2 == $4 && $3 == 4 && inreg($2) < 2 | | remove(MEM_ALL) "eor.l #$1,$2(a6)" | | | (8,16) lde ldc xor sde $3 == 4 && $1 == $4 | | @@ -1649,7 +1613,7 @@ lde ldc xor sde $3 == 4 && $1 == $4 | | ldc lde xor sde $3 == 4 && $2 == $4 | | remove(MEM_ALL) "eor.l #$1,$2" | | | (9,17) -ldl xor sdl $1 == $3 && $2 == 4 | DATAREG4 | +ldl xor sdl $1 == $3 && $2 == 4 && inreg($1) < 2 | DATAREG4 | remove(MEM_ALL) "eor.l %[1],$1(a6)" | | | lde xor sde $1 == $3 && $2 == 4 | DATAREG4 | From 9a3a07734e5597265e612ac2926f2dbe9f5589a2 Mon Sep 17 00:00:00 2001 From: keie Date: Mon, 13 May 1985 11:06:30 +0000 Subject: [PATCH 0016/1625] *** empty log message *** --- mach/m68k2/cv/cv.c | 385 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 385 insertions(+) create mode 100644 mach/m68k2/cv/cv.c diff --git a/mach/m68k2/cv/cv.c b/mach/m68k2/cv/cv.c new file mode 100644 index 00000000..2781307f --- /dev/null +++ b/mach/m68k2/cv/cv.c @@ -0,0 +1,385 @@ +/* + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. + * + * This product is part of the Amsterdam Compiler Kit. + * + * Permission to use, sell, duplicate or disclose this software must be + * obtained in writing. Requests for such permissions may be sent to + * + * Dr. Andrew S. Tanenbaum + * Wiskundig Seminarium + * Vrije Universiteit + * Postbox 7161 + * 1007 MC Amsterdam + * The Netherlands + * + */ + +#include +#include "out.h" + +#ifndef NORCSID +static char rcs_id[] = "$Header$" ; +#endif + +/* BUG: + There is a problem with Bleasdale 'nm' and the namelist produced + by this program. + nm always acts as if there were no name list, while adb + understands a.out's with namelists without any complaint. + The cause is unclear. All sizes in the header and file are correct. + Setting the symbol table size to a size smaller than actually + present in the a.out causes 'adb' to produce error messages + about name list problems, but nm suddenly prints the namelist, + INCLUDING the entrie outside the size indicated in the a.out header. +*/ +#define ASSERT(x) switch (2) { case 0: case (x): ; } + +/* + * Header and section table of new format object file. + */ +struct outhead outhead; +struct outsect outsect[S_MAX]; +char *stringarea ; + +char *output_file; +int output_file_created; + +char *program ; + +char flag ; + +#define readf(a, b, c) fread((a), (b), (int)(c), input) +#define writef(a, b, c) fwrite((a), (b), (int)(c), output) + +/* Output file definitions and such */ + +#define HDR_LENGTH 32 + +char hdr[HDR_LENGTH] ; + +#define TEXT 0 +#define ROM 1 +#define DATA 2 +#define BSS 3 +#define LSECT BSS+1 +#define NSECT LSECT+1 + + +#define N_EXT 040 +#define N_UNDEF 00 +#define N_ABS 01 +#define N_TEXT 02 +#define N_DATA 03 +#define N_BSS 04 +#define N_FN 037 + +FILE *input; +FILE *output; + +main(argc, argv) + int argc; + char *argv[]; +{ + register int nsect; + long magic ; + long textsize ; + long datasize ; + + ASSERT(sizeof(struct outhead) == SZ_HEAD); + ASSERT(sizeof(struct outsect) == SZ_SECT); + + input = stdin; output = stdout; + program= argv[0] ; + if ( argc>1 && argv[1][0]=='-' ) { + flag=argv[1][1] ; + argc-- ; argv++ ; + } + switch (argc) { + case 1: break; + case 3: if ((output = fopen(argv[2], "w")) == (FILE *)0) + fatal("Can't write %s.\n", argv[2]); + output_file = argv[2]; + output_file_created = 1; + /* FALLTHROUGH */ + case 2: if ((input = fopen(argv[1], "r")) == (FILE *)0) + fatal("Can't read %s.\n", argv[1]); + break; + default:fatal("Usage: %s
.\n", argv[0]); + } + if ( !rhead(input,&outhead) ) + fatal("Reading header failed.\n"); + if (BADMAGIC(outhead)) + fatal("Not an ack object file.\n"); + if (outhead.oh_nrelo > 0) + fprintf(stderr, "Warning: relocation information present.\n"); + if ( outhead.oh_nsect!=LSECT && outhead.oh_nsect!=NSECT ) + fatal("Input file must have %d sections, not %ld\n", + NSECT,outhead.oh_nsect) ; + for ( nsect=0 ; nsectos_flen ; + while (n > 0) { + blk = n > BUFSIZ ? BUFSIZ : n; + readf(buffer, 1, blk); + writef(buffer, 1, blk); + n -= blk; + } + if ( section->os_flen!=section->os_size ) { + for ( n=BUFSIZ-1 ; n ; n-- ) buffer[n]=0 ; + n= section->os_size - section->os_flen ; + while (n > 0) { + blk = n > BUFSIZ ? BUFSIZ : n; + writef(buffer, 1, blk); + n -= blk; + } + } +} + +/* + * Copy the name table, except the last outhead.oh_nsect. + * These are assumed to be section names. + * + */ +names() +{ + register ushort n = outhead.oh_nname - outhead.oh_nsect; + int type = 0 ; + struct outname outname ; + char buffer[100] ; + char *s1, *s2 ; + long length, fullength ; + + fseek(input,OFF_CHAR(outhead),0) ; + chars() ; + if ( !stringarea ) return ; + fseek(input,OFF_NAME(outhead),0) ; + fullength=0 ; buffer[1]=0 ; + while (n--) { + rname(input,&outname) ; + if (outname.on_foff == 0) + continue ; + if (outname.on_type & S_ETC ) { + switch (outname.on_type & S_ETC ) { + /* ??? + case S_FIL : + type |= N_FN ; + */ + case S_COM : + break ; + default : + continue ; + } + } + set4(buffer,2,outname.on_valu ) ; + switch (outname.on_type & S_TYP) { + case S_UND: + type = N_UNDEF; + break; + case S_ABS: + type = N_ABS; + break; + case S_MIN + TEXT: + type = N_TEXT; + break; + case S_MIN + DATA: + type = N_DATA; + break; + case S_MIN + BSS: + case S_MIN + LSECT: + type = N_BSS; + break ; + } + + if (outname.on_type & S_EXT) + type |= N_EXT; + buffer[0]= type ; + s1=buffer+6 ; s2= stringarea+outname.on_foff-OFF_CHAR(outhead); + length= 6 ; + while ( (++length 0) { + blk = n > BUFSIZ ? BUFSIZ : n; + readf(curr, 1, blk); + curr += blk ; + n -= blk; + } +} +rhead(f,head) struct outhead *head ; FILE *f ; { + char buf[SZ_HEAD] ; + if ( fread(buf,SZ_HEAD,1,f)!=1 ) return 0 ; + iconvert(buf,(char *)head,SF_HEAD) ; + return 1 ; +} + +rsect(f,sect) struct outsect *sect ; FILE *f ; { + char buf[SZ_SECT] ; + if ( fread(buf,SZ_SECT,1,f)!=1 ) return 0 ; + iconvert(buf,(char *)sect,SF_SECT) ; + return 1 ; +} + +rrelo(f,relo) struct outrelo *relo ; FILE *f ; { + char buf[SZ_RELO] ; + if ( fread(buf,SZ_RELO,1,f)!=1 ) return 0 ; + iconvert(buf,(char *)relo,SF_RELO) ; + return 1 ; +} + +rname(f,name) struct outname *name ; FILE *f ; { + char buf[SZ_NAME] ; + if ( fread(buf,SZ_NAME,1,f)!=1 ) return 0 ; + iconvert(buf,(char *)name,SF_NAME) ; + return 1 ; +} + +iconvert(buf,str,fmt) char *buf, *str, *fmt ; { + register char *nf, *ni, *no ; + int last, i ; + long value ; + ni=buf ; no=str ; nf=fmt ; + while ( last = *nf++ ) { + last -= '0' ; + if ( last<1 || last >9 ) fatal("illegal out.h format string\n"); + value=0 ; + i=last ; + while ( i-- ) { + value = (value<<8) + (ni[i]&0xFF) ; + } + switch ( last ) { + case 0 : break ; + case 1 : *no= value ; break ; + case 2 : *(unsigned short *)no = value ; break ; + case 4 : *(long *)no = value ; break ; + default : + fatal("illegal out.h format string\n"); + } + ni += last ; no += last ; + } +} + +set2(buf,off,val) char *buf ; int val ; { + buf[off+0] = val>>8 ; + buf[off+1] = val ; +} + +set4(buf,off,val) char *buf ; long val ; { + buf[off] = val>>24 ; + buf[off+1] = val>>16 ; + buf[off+2] = val>>8 ; + buf[off+3] = val ; +} + +/* VARARGS1 */ +fatal(s, a1, a2) + char *s; +{ + fprintf(stderr,"%s: ",program) ; + fprintf(stderr, s, a1, a2); + if (output_file_created) + unlink(output_file); + exit(-1); +} From 2a6784012f98d703384bd7b237f459c620d14d6f Mon Sep 17 00:00:00 2001 From: keie Date: Mon, 13 May 1985 11:09:53 +0000 Subject: [PATCH 0017/1625] Adapted to installation in the EM tree. --- util/led/Makefile | 58 +++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/util/led/Makefile b/util/led/Makefile index 2589cc20..39008c0b 100644 --- a/util/led/Makefile +++ b/util/led/Makefile @@ -14,6 +14,7 @@ # Definitions for the making programs. +LIBDIR=../../lib PREFLAGS= -DNDEBUG -DNASSERT CFLAGS = -O $(PREFLAGS) LDFLAGS = @@ -28,10 +29,8 @@ CFILES = archive.c byte_order.c error.c extract.c finish.c main.c memory.c\ CVFILES = archive.c,v byte_order.c,v error.c,v extract.c,v finish.c,v main.c,v\ memory.c,v output.c,v read.c,v relocate.c,v save.c,v scan.c,v\ sym.c,v write.c,v -HFILES = arch.h assert.h const.h debug.h defs.h memory.h orig.h out.h\ - ranlib.h scan.h -HVFILES = arch.h,v assert.h,v const.h,v debug.h,v defs.h,v memory.h,v orig.h,v\ - out.h,v ranlib.h,v scan.h,v +HFILES = assert.h const.h debug.h defs.h memory.h orig.h scan.h +HVFILES = assert.h,v const.h,v debug.h,v defs.h,v memory.h,v orig.h,v scan.h,v OFILES = archive.o byte_order.o error.o extract.o finish.o main.o memory.o\ output.o read.o relocate.o save.o scan.o sym.o write.o @@ -43,6 +42,12 @@ led: $(OFILES) mach.c: mach.c,v co -q mach.c +install:led + cp led $(LIBDIR)/em_led + +cmp: led + cmp led $(LIBDIR)/em_led + lint: -for i in $(CFILES) $(HFILES) mach.c; do\ if test ! -f $$i; then\ @@ -58,6 +63,11 @@ pr: $(CVFILES) $(HVFILES) mach.c co -q -p $$i | $(PR) $(PRFLAGS) -h `basename $$i ,v`;\ done @touch pr +opr: + make pr | opr + +clean: + rm *.o led depend: -for i in $(CFILES); do\ @@ -71,72 +81,72 @@ depend: # The next lines are generated automatically. # AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO -archive.o: arch.h +archive.o: ../../h/arch.h +archive.o: ../../h/out.h +archive.o: ../../h/ranlib.h archive.o: const.h archive.o: debug.h archive.o: defs.h archive.o: memory.h -archive.o: out.h -archive.o: ranlib.h byte_order.o: assert.h byte_order.o: const.h +error.o: ../../h/out.h error.o: const.h -error.o: out.h +extract.o: ../../h/out.h extract.o: const.h extract.o: debug.h extract.o: defs.h extract.o: memory.h extract.o: orig.h -extract.o: out.h extract.o: scan.h +finish.o: ../../h/out.h finish.o: const.h finish.o: defs.h finish.o: memory.h finish.o: orig.h -finish.o: out.h finish.o: scan.h +main.o: ../../h/out.h main.o: const.h main.o: debug.h main.o: defs.h main.o: memory.h main.o: orig.h -main.o: out.h +memory.o: ../../h/out.h memory.o: assert.h memory.o: const.h memory.o: debug.h memory.o: mach.c memory.o: memory.h -memory.o: out.h +output.o: ../../h/out.h output.o: const.h output.o: memory.h -output.o: out.h -read.o: arch.h +read.o: ../../h/arch.h +read.o: ../../h/out.h +read.o: ../../h/ranlib.h read.o: assert.h read.o: const.h -read.o: out.h -read.o: ranlib.h +relocate.o: ../../h/out.h relocate.o: const.h relocate.o: debug.h relocate.o: defs.h relocate.o: orig.h -relocate.o: out.h -save.o: arch.h +save.o: ../../h/arch.h +save.o: ../../h/out.h save.o: assert.h save.o: const.h save.o: memory.h -save.o: out.h -scan.o: arch.h +scan.o: ../../h/arch.h +scan.o: ../../h/out.h +scan.o: ../../h/ranlib.h scan.o: assert.h scan.o: const.h scan.o: memory.h -scan.o: out.h -scan.o: ranlib.h scan.o: scan.h +sym.o: ../../h/out.h sym.o: const.h sym.o: memory.h -sym.o: out.h +write.o: ../../h/out.h write.o: assert.h write.o: const.h write.o: memory.h write.o: orig.h -write.o: out.h From 30c4ef1be92fd695454c62c679728f529c37a364 Mon Sep 17 00:00:00 2001 From: keie Date: Mon, 13 May 1985 11:19:24 +0000 Subject: [PATCH 0018/1625] *** empty log message *** --- mach/6500/as/Makefile | 20 +- mach/6800/as/Makefile | 20 +- mach/6805/as/Makefile | 20 +- mach/6809/as/Makefile | 20 +- mach/arm/as/Makefile | 20 +- mach/i386/as/Makefile | 20 +- mach/i80/as/Makefile | 20 +- mach/i86/as/Makefile | 20 +- mach/m68020/as/Makefile | 20 +- mach/m68k2/as/Makefile | 20 +- mach/m68k2/as/mach0.c | 28 ++ mach/m68k2/as/mach1.c | 58 ++++ mach/m68k2/as/mach2.c | 42 +++ mach/m68k2/as/mach3.c | 171 ++++++++++++ mach/m68k2/as/mach4.c | 196 +++++++++++++ mach/m68k2/as/mach5.c | 460 ++++++++++++++++++++++++++++++ mach/ns/as/Makefile | 20 +- mach/pdp/as/Makefile | 20 +- mach/proto/as/Makefile | 20 +- mach/s2650/as/Makefile | 20 +- mach/vax4/as/Makefile | 20 +- mach/z80/as/Makefile | 20 +- mach/z8000/as/Makefile | 20 +- util/led/READ_ME | 600 ++++++++++++++++++++++++++++++++++++++++ util/led/WRONG | 72 +++++ util/led/makedepend | 23 ++ 26 files changed, 1922 insertions(+), 68 deletions(-) create mode 100644 mach/m68k2/as/mach0.c create mode 100644 mach/m68k2/as/mach1.c create mode 100644 mach/m68k2/as/mach2.c create mode 100644 mach/m68k2/as/mach3.c create mode 100644 mach/m68k2/as/mach4.c create mode 100644 mach/m68k2/as/mach5.c create mode 100644 util/led/READ_ME create mode 100644 util/led/WRONG create mode 100755 util/led/makedepend diff --git a/mach/6500/as/Makefile b/mach/6500/as/Makefile index 012b0382..695d2b20 100644 --- a/mach/6500/as/Makefile +++ b/mach/6500/as/Makefile @@ -6,14 +6,14 @@ CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I$h $(DEF) +CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) YFLAGS = -d LDFLAGS = $(FFLAG) -i CSRC = $(CDIR)/comm3.c $(CDIR)/comm4.c $(CDIR)/comm5.c \ $(CDIR)/comm6.c $(CDIR)/comm7.c $(CDIR)/comm8.c -COBJ = $(CDIR)/comm3.o $(CDIR)/comm4.o $(CDIR)/comm5.o \ - $(CDIR)/comm6.o $(CDIR)/comm7.o $(CDIR)/comm8.o +COBJ = comm3.o comm4.o comm5.o \ + comm6.o comm7.o comm8.o MACH = mach0.c mach1.c mach2.c mach3.c mach4.c mach5.c COMM = $(CDIR)/comm0.h $(CDIR)/comm1.h $(CDIR)/comm2.y $(CSRC) @@ -37,7 +37,7 @@ as: $(COBJ) as.o $(CC) $(LDFLAGS) $(COBJ) as.o -o as as.y: $(CDIR)/comm2.y - $(CPP) -P -I$h $(DEF) $(CDIR)/comm2.y >as.y + $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c @@ -51,3 +51,15 @@ as.y: mach2.c comm3.o: mach3.c as.y: mach4.c comm8.o: mach5.c +comm3.o: $(CDIR)/comm3.c + $(CC) -c $(CFLAGS) $(CDIR)/comm3.c +comm4.o: $(CDIR)/comm4.c + $(CC) -c $(CFLAGS) $(CDIR)/comm4.c +comm5.o: $(CDIR)/comm5.c + $(CC) -c $(CFLAGS) $(CDIR)/comm5.c +comm6.o: $(CDIR)/comm6.c + $(CC) -c $(CFLAGS) $(CDIR)/comm6.c +comm7.o: $(CDIR)/comm7.c + $(CC) -c $(CFLAGS) $(CDIR)/comm7.c +comm8.o: $(CDIR)/comm8.c + $(CC) -c $(CFLAGS) $(CDIR)/comm8.c diff --git a/mach/6800/as/Makefile b/mach/6800/as/Makefile index 012b0382..695d2b20 100644 --- a/mach/6800/as/Makefile +++ b/mach/6800/as/Makefile @@ -6,14 +6,14 @@ CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I$h $(DEF) +CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) YFLAGS = -d LDFLAGS = $(FFLAG) -i CSRC = $(CDIR)/comm3.c $(CDIR)/comm4.c $(CDIR)/comm5.c \ $(CDIR)/comm6.c $(CDIR)/comm7.c $(CDIR)/comm8.c -COBJ = $(CDIR)/comm3.o $(CDIR)/comm4.o $(CDIR)/comm5.o \ - $(CDIR)/comm6.o $(CDIR)/comm7.o $(CDIR)/comm8.o +COBJ = comm3.o comm4.o comm5.o \ + comm6.o comm7.o comm8.o MACH = mach0.c mach1.c mach2.c mach3.c mach4.c mach5.c COMM = $(CDIR)/comm0.h $(CDIR)/comm1.h $(CDIR)/comm2.y $(CSRC) @@ -37,7 +37,7 @@ as: $(COBJ) as.o $(CC) $(LDFLAGS) $(COBJ) as.o -o as as.y: $(CDIR)/comm2.y - $(CPP) -P -I$h $(DEF) $(CDIR)/comm2.y >as.y + $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c @@ -51,3 +51,15 @@ as.y: mach2.c comm3.o: mach3.c as.y: mach4.c comm8.o: mach5.c +comm3.o: $(CDIR)/comm3.c + $(CC) -c $(CFLAGS) $(CDIR)/comm3.c +comm4.o: $(CDIR)/comm4.c + $(CC) -c $(CFLAGS) $(CDIR)/comm4.c +comm5.o: $(CDIR)/comm5.c + $(CC) -c $(CFLAGS) $(CDIR)/comm5.c +comm6.o: $(CDIR)/comm6.c + $(CC) -c $(CFLAGS) $(CDIR)/comm6.c +comm7.o: $(CDIR)/comm7.c + $(CC) -c $(CFLAGS) $(CDIR)/comm7.c +comm8.o: $(CDIR)/comm8.c + $(CC) -c $(CFLAGS) $(CDIR)/comm8.c diff --git a/mach/6805/as/Makefile b/mach/6805/as/Makefile index 012b0382..695d2b20 100644 --- a/mach/6805/as/Makefile +++ b/mach/6805/as/Makefile @@ -6,14 +6,14 @@ CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I$h $(DEF) +CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) YFLAGS = -d LDFLAGS = $(FFLAG) -i CSRC = $(CDIR)/comm3.c $(CDIR)/comm4.c $(CDIR)/comm5.c \ $(CDIR)/comm6.c $(CDIR)/comm7.c $(CDIR)/comm8.c -COBJ = $(CDIR)/comm3.o $(CDIR)/comm4.o $(CDIR)/comm5.o \ - $(CDIR)/comm6.o $(CDIR)/comm7.o $(CDIR)/comm8.o +COBJ = comm3.o comm4.o comm5.o \ + comm6.o comm7.o comm8.o MACH = mach0.c mach1.c mach2.c mach3.c mach4.c mach5.c COMM = $(CDIR)/comm0.h $(CDIR)/comm1.h $(CDIR)/comm2.y $(CSRC) @@ -37,7 +37,7 @@ as: $(COBJ) as.o $(CC) $(LDFLAGS) $(COBJ) as.o -o as as.y: $(CDIR)/comm2.y - $(CPP) -P -I$h $(DEF) $(CDIR)/comm2.y >as.y + $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c @@ -51,3 +51,15 @@ as.y: mach2.c comm3.o: mach3.c as.y: mach4.c comm8.o: mach5.c +comm3.o: $(CDIR)/comm3.c + $(CC) -c $(CFLAGS) $(CDIR)/comm3.c +comm4.o: $(CDIR)/comm4.c + $(CC) -c $(CFLAGS) $(CDIR)/comm4.c +comm5.o: $(CDIR)/comm5.c + $(CC) -c $(CFLAGS) $(CDIR)/comm5.c +comm6.o: $(CDIR)/comm6.c + $(CC) -c $(CFLAGS) $(CDIR)/comm6.c +comm7.o: $(CDIR)/comm7.c + $(CC) -c $(CFLAGS) $(CDIR)/comm7.c +comm8.o: $(CDIR)/comm8.c + $(CC) -c $(CFLAGS) $(CDIR)/comm8.c diff --git a/mach/6809/as/Makefile b/mach/6809/as/Makefile index 012b0382..695d2b20 100644 --- a/mach/6809/as/Makefile +++ b/mach/6809/as/Makefile @@ -6,14 +6,14 @@ CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I$h $(DEF) +CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) YFLAGS = -d LDFLAGS = $(FFLAG) -i CSRC = $(CDIR)/comm3.c $(CDIR)/comm4.c $(CDIR)/comm5.c \ $(CDIR)/comm6.c $(CDIR)/comm7.c $(CDIR)/comm8.c -COBJ = $(CDIR)/comm3.o $(CDIR)/comm4.o $(CDIR)/comm5.o \ - $(CDIR)/comm6.o $(CDIR)/comm7.o $(CDIR)/comm8.o +COBJ = comm3.o comm4.o comm5.o \ + comm6.o comm7.o comm8.o MACH = mach0.c mach1.c mach2.c mach3.c mach4.c mach5.c COMM = $(CDIR)/comm0.h $(CDIR)/comm1.h $(CDIR)/comm2.y $(CSRC) @@ -37,7 +37,7 @@ as: $(COBJ) as.o $(CC) $(LDFLAGS) $(COBJ) as.o -o as as.y: $(CDIR)/comm2.y - $(CPP) -P -I$h $(DEF) $(CDIR)/comm2.y >as.y + $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c @@ -51,3 +51,15 @@ as.y: mach2.c comm3.o: mach3.c as.y: mach4.c comm8.o: mach5.c +comm3.o: $(CDIR)/comm3.c + $(CC) -c $(CFLAGS) $(CDIR)/comm3.c +comm4.o: $(CDIR)/comm4.c + $(CC) -c $(CFLAGS) $(CDIR)/comm4.c +comm5.o: $(CDIR)/comm5.c + $(CC) -c $(CFLAGS) $(CDIR)/comm5.c +comm6.o: $(CDIR)/comm6.c + $(CC) -c $(CFLAGS) $(CDIR)/comm6.c +comm7.o: $(CDIR)/comm7.c + $(CC) -c $(CFLAGS) $(CDIR)/comm7.c +comm8.o: $(CDIR)/comm8.c + $(CC) -c $(CFLAGS) $(CDIR)/comm8.c diff --git a/mach/arm/as/Makefile b/mach/arm/as/Makefile index 012b0382..695d2b20 100644 --- a/mach/arm/as/Makefile +++ b/mach/arm/as/Makefile @@ -6,14 +6,14 @@ CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I$h $(DEF) +CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) YFLAGS = -d LDFLAGS = $(FFLAG) -i CSRC = $(CDIR)/comm3.c $(CDIR)/comm4.c $(CDIR)/comm5.c \ $(CDIR)/comm6.c $(CDIR)/comm7.c $(CDIR)/comm8.c -COBJ = $(CDIR)/comm3.o $(CDIR)/comm4.o $(CDIR)/comm5.o \ - $(CDIR)/comm6.o $(CDIR)/comm7.o $(CDIR)/comm8.o +COBJ = comm3.o comm4.o comm5.o \ + comm6.o comm7.o comm8.o MACH = mach0.c mach1.c mach2.c mach3.c mach4.c mach5.c COMM = $(CDIR)/comm0.h $(CDIR)/comm1.h $(CDIR)/comm2.y $(CSRC) @@ -37,7 +37,7 @@ as: $(COBJ) as.o $(CC) $(LDFLAGS) $(COBJ) as.o -o as as.y: $(CDIR)/comm2.y - $(CPP) -P -I$h $(DEF) $(CDIR)/comm2.y >as.y + $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c @@ -51,3 +51,15 @@ as.y: mach2.c comm3.o: mach3.c as.y: mach4.c comm8.o: mach5.c +comm3.o: $(CDIR)/comm3.c + $(CC) -c $(CFLAGS) $(CDIR)/comm3.c +comm4.o: $(CDIR)/comm4.c + $(CC) -c $(CFLAGS) $(CDIR)/comm4.c +comm5.o: $(CDIR)/comm5.c + $(CC) -c $(CFLAGS) $(CDIR)/comm5.c +comm6.o: $(CDIR)/comm6.c + $(CC) -c $(CFLAGS) $(CDIR)/comm6.c +comm7.o: $(CDIR)/comm7.c + $(CC) -c $(CFLAGS) $(CDIR)/comm7.c +comm8.o: $(CDIR)/comm8.c + $(CC) -c $(CFLAGS) $(CDIR)/comm8.c diff --git a/mach/i386/as/Makefile b/mach/i386/as/Makefile index 012b0382..695d2b20 100644 --- a/mach/i386/as/Makefile +++ b/mach/i386/as/Makefile @@ -6,14 +6,14 @@ CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I$h $(DEF) +CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) YFLAGS = -d LDFLAGS = $(FFLAG) -i CSRC = $(CDIR)/comm3.c $(CDIR)/comm4.c $(CDIR)/comm5.c \ $(CDIR)/comm6.c $(CDIR)/comm7.c $(CDIR)/comm8.c -COBJ = $(CDIR)/comm3.o $(CDIR)/comm4.o $(CDIR)/comm5.o \ - $(CDIR)/comm6.o $(CDIR)/comm7.o $(CDIR)/comm8.o +COBJ = comm3.o comm4.o comm5.o \ + comm6.o comm7.o comm8.o MACH = mach0.c mach1.c mach2.c mach3.c mach4.c mach5.c COMM = $(CDIR)/comm0.h $(CDIR)/comm1.h $(CDIR)/comm2.y $(CSRC) @@ -37,7 +37,7 @@ as: $(COBJ) as.o $(CC) $(LDFLAGS) $(COBJ) as.o -o as as.y: $(CDIR)/comm2.y - $(CPP) -P -I$h $(DEF) $(CDIR)/comm2.y >as.y + $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c @@ -51,3 +51,15 @@ as.y: mach2.c comm3.o: mach3.c as.y: mach4.c comm8.o: mach5.c +comm3.o: $(CDIR)/comm3.c + $(CC) -c $(CFLAGS) $(CDIR)/comm3.c +comm4.o: $(CDIR)/comm4.c + $(CC) -c $(CFLAGS) $(CDIR)/comm4.c +comm5.o: $(CDIR)/comm5.c + $(CC) -c $(CFLAGS) $(CDIR)/comm5.c +comm6.o: $(CDIR)/comm6.c + $(CC) -c $(CFLAGS) $(CDIR)/comm6.c +comm7.o: $(CDIR)/comm7.c + $(CC) -c $(CFLAGS) $(CDIR)/comm7.c +comm8.o: $(CDIR)/comm8.c + $(CC) -c $(CFLAGS) $(CDIR)/comm8.c diff --git a/mach/i80/as/Makefile b/mach/i80/as/Makefile index 012b0382..695d2b20 100644 --- a/mach/i80/as/Makefile +++ b/mach/i80/as/Makefile @@ -6,14 +6,14 @@ CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I$h $(DEF) +CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) YFLAGS = -d LDFLAGS = $(FFLAG) -i CSRC = $(CDIR)/comm3.c $(CDIR)/comm4.c $(CDIR)/comm5.c \ $(CDIR)/comm6.c $(CDIR)/comm7.c $(CDIR)/comm8.c -COBJ = $(CDIR)/comm3.o $(CDIR)/comm4.o $(CDIR)/comm5.o \ - $(CDIR)/comm6.o $(CDIR)/comm7.o $(CDIR)/comm8.o +COBJ = comm3.o comm4.o comm5.o \ + comm6.o comm7.o comm8.o MACH = mach0.c mach1.c mach2.c mach3.c mach4.c mach5.c COMM = $(CDIR)/comm0.h $(CDIR)/comm1.h $(CDIR)/comm2.y $(CSRC) @@ -37,7 +37,7 @@ as: $(COBJ) as.o $(CC) $(LDFLAGS) $(COBJ) as.o -o as as.y: $(CDIR)/comm2.y - $(CPP) -P -I$h $(DEF) $(CDIR)/comm2.y >as.y + $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c @@ -51,3 +51,15 @@ as.y: mach2.c comm3.o: mach3.c as.y: mach4.c comm8.o: mach5.c +comm3.o: $(CDIR)/comm3.c + $(CC) -c $(CFLAGS) $(CDIR)/comm3.c +comm4.o: $(CDIR)/comm4.c + $(CC) -c $(CFLAGS) $(CDIR)/comm4.c +comm5.o: $(CDIR)/comm5.c + $(CC) -c $(CFLAGS) $(CDIR)/comm5.c +comm6.o: $(CDIR)/comm6.c + $(CC) -c $(CFLAGS) $(CDIR)/comm6.c +comm7.o: $(CDIR)/comm7.c + $(CC) -c $(CFLAGS) $(CDIR)/comm7.c +comm8.o: $(CDIR)/comm8.c + $(CC) -c $(CFLAGS) $(CDIR)/comm8.c diff --git a/mach/i86/as/Makefile b/mach/i86/as/Makefile index 012b0382..695d2b20 100644 --- a/mach/i86/as/Makefile +++ b/mach/i86/as/Makefile @@ -6,14 +6,14 @@ CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I$h $(DEF) +CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) YFLAGS = -d LDFLAGS = $(FFLAG) -i CSRC = $(CDIR)/comm3.c $(CDIR)/comm4.c $(CDIR)/comm5.c \ $(CDIR)/comm6.c $(CDIR)/comm7.c $(CDIR)/comm8.c -COBJ = $(CDIR)/comm3.o $(CDIR)/comm4.o $(CDIR)/comm5.o \ - $(CDIR)/comm6.o $(CDIR)/comm7.o $(CDIR)/comm8.o +COBJ = comm3.o comm4.o comm5.o \ + comm6.o comm7.o comm8.o MACH = mach0.c mach1.c mach2.c mach3.c mach4.c mach5.c COMM = $(CDIR)/comm0.h $(CDIR)/comm1.h $(CDIR)/comm2.y $(CSRC) @@ -37,7 +37,7 @@ as: $(COBJ) as.o $(CC) $(LDFLAGS) $(COBJ) as.o -o as as.y: $(CDIR)/comm2.y - $(CPP) -P -I$h $(DEF) $(CDIR)/comm2.y >as.y + $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c @@ -51,3 +51,15 @@ as.y: mach2.c comm3.o: mach3.c as.y: mach4.c comm8.o: mach5.c +comm3.o: $(CDIR)/comm3.c + $(CC) -c $(CFLAGS) $(CDIR)/comm3.c +comm4.o: $(CDIR)/comm4.c + $(CC) -c $(CFLAGS) $(CDIR)/comm4.c +comm5.o: $(CDIR)/comm5.c + $(CC) -c $(CFLAGS) $(CDIR)/comm5.c +comm6.o: $(CDIR)/comm6.c + $(CC) -c $(CFLAGS) $(CDIR)/comm6.c +comm7.o: $(CDIR)/comm7.c + $(CC) -c $(CFLAGS) $(CDIR)/comm7.c +comm8.o: $(CDIR)/comm8.c + $(CC) -c $(CFLAGS) $(CDIR)/comm8.c diff --git a/mach/m68020/as/Makefile b/mach/m68020/as/Makefile index 012b0382..695d2b20 100644 --- a/mach/m68020/as/Makefile +++ b/mach/m68020/as/Makefile @@ -6,14 +6,14 @@ CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I$h $(DEF) +CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) YFLAGS = -d LDFLAGS = $(FFLAG) -i CSRC = $(CDIR)/comm3.c $(CDIR)/comm4.c $(CDIR)/comm5.c \ $(CDIR)/comm6.c $(CDIR)/comm7.c $(CDIR)/comm8.c -COBJ = $(CDIR)/comm3.o $(CDIR)/comm4.o $(CDIR)/comm5.o \ - $(CDIR)/comm6.o $(CDIR)/comm7.o $(CDIR)/comm8.o +COBJ = comm3.o comm4.o comm5.o \ + comm6.o comm7.o comm8.o MACH = mach0.c mach1.c mach2.c mach3.c mach4.c mach5.c COMM = $(CDIR)/comm0.h $(CDIR)/comm1.h $(CDIR)/comm2.y $(CSRC) @@ -37,7 +37,7 @@ as: $(COBJ) as.o $(CC) $(LDFLAGS) $(COBJ) as.o -o as as.y: $(CDIR)/comm2.y - $(CPP) -P -I$h $(DEF) $(CDIR)/comm2.y >as.y + $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c @@ -51,3 +51,15 @@ as.y: mach2.c comm3.o: mach3.c as.y: mach4.c comm8.o: mach5.c +comm3.o: $(CDIR)/comm3.c + $(CC) -c $(CFLAGS) $(CDIR)/comm3.c +comm4.o: $(CDIR)/comm4.c + $(CC) -c $(CFLAGS) $(CDIR)/comm4.c +comm5.o: $(CDIR)/comm5.c + $(CC) -c $(CFLAGS) $(CDIR)/comm5.c +comm6.o: $(CDIR)/comm6.c + $(CC) -c $(CFLAGS) $(CDIR)/comm6.c +comm7.o: $(CDIR)/comm7.c + $(CC) -c $(CFLAGS) $(CDIR)/comm7.c +comm8.o: $(CDIR)/comm8.c + $(CC) -c $(CFLAGS) $(CDIR)/comm8.c diff --git a/mach/m68k2/as/Makefile b/mach/m68k2/as/Makefile index 012b0382..695d2b20 100644 --- a/mach/m68k2/as/Makefile +++ b/mach/m68k2/as/Makefile @@ -6,14 +6,14 @@ CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I$h $(DEF) +CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) YFLAGS = -d LDFLAGS = $(FFLAG) -i CSRC = $(CDIR)/comm3.c $(CDIR)/comm4.c $(CDIR)/comm5.c \ $(CDIR)/comm6.c $(CDIR)/comm7.c $(CDIR)/comm8.c -COBJ = $(CDIR)/comm3.o $(CDIR)/comm4.o $(CDIR)/comm5.o \ - $(CDIR)/comm6.o $(CDIR)/comm7.o $(CDIR)/comm8.o +COBJ = comm3.o comm4.o comm5.o \ + comm6.o comm7.o comm8.o MACH = mach0.c mach1.c mach2.c mach3.c mach4.c mach5.c COMM = $(CDIR)/comm0.h $(CDIR)/comm1.h $(CDIR)/comm2.y $(CSRC) @@ -37,7 +37,7 @@ as: $(COBJ) as.o $(CC) $(LDFLAGS) $(COBJ) as.o -o as as.y: $(CDIR)/comm2.y - $(CPP) -P -I$h $(DEF) $(CDIR)/comm2.y >as.y + $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c @@ -51,3 +51,15 @@ as.y: mach2.c comm3.o: mach3.c as.y: mach4.c comm8.o: mach5.c +comm3.o: $(CDIR)/comm3.c + $(CC) -c $(CFLAGS) $(CDIR)/comm3.c +comm4.o: $(CDIR)/comm4.c + $(CC) -c $(CFLAGS) $(CDIR)/comm4.c +comm5.o: $(CDIR)/comm5.c + $(CC) -c $(CFLAGS) $(CDIR)/comm5.c +comm6.o: $(CDIR)/comm6.c + $(CC) -c $(CFLAGS) $(CDIR)/comm6.c +comm7.o: $(CDIR)/comm7.c + $(CC) -c $(CFLAGS) $(CDIR)/comm7.c +comm8.o: $(CDIR)/comm8.c + $(CC) -c $(CFLAGS) $(CDIR)/comm8.c diff --git a/mach/m68k2/as/mach0.c b/mach/m68k2/as/mach0.c new file mode 100644 index 00000000..76d1a7a0 --- /dev/null +++ b/mach/m68k2/as/mach0.c @@ -0,0 +1,28 @@ +#define DUK +/* @(#)mach0.c 1.5 */ +/* + * Motorola 68000/68010 options + */ +#undef BITMAX +#define BITMAX 8000 + +#define THREE_PASS /* branch and offset optimization */ +#define BYTES_REVERSED /* high order byte has lowest address */ +#define WORDS_REVERSED /* high order word has lowest address */ +#define LISTING /* enable listing facilities */ +#define RELOCATION /* generate relocatable code */ + +#undef valu_t +#define valu_t long +#undef addr_t +#define addr_t long + +#undef ALIGNWORD +#define ALIGNWORD 2 +#undef ALIGNSECT +#define ALIGNSECT 2 + +#undef VALWIDTH +#define VALWIDTH 8 + +#define NOLD /* Added by Duk Bekema. */ diff --git a/mach/m68k2/as/mach1.c b/mach/m68k2/as/mach1.c new file mode 100644 index 00000000..175eca0c --- /dev/null +++ b/mach/m68k2/as/mach1.c @@ -0,0 +1,58 @@ +/* @(#)mach1.c 1.8 */ +/* + * Motorola 68000/68010 dependent C declarations + */ + +#define low3(z) ((short)(z) & 07) +#define low4(z) ((short)(z) & 017) + +#define fit3(z) ((((z)-1) & ~07) == 0) +#define fit4(z) (((z) & ~017) == 0) +#define fit8(z) (((z) & ~0xFF) == 0) +#define fit16(z) (((z) & ~0xFFFF) == 0) + +#define SIZE_B 0000 +#define SIZE_W 0100 +#define SIZE_L 0200 +#define SIZE_NON 0300 +#define SIZE_DEF SIZE_W + +extern int mrg_1,mrg_2; +extern expr_t exp_1,exp_2; +#ifndef ASLD +extern valu_t rel_1,rel_2; +#endif +extern int model; /* 68000/68010 */ + +/* addressing mode bits */ +#define DTA 0x01 +#define MEM 0x02 +#define CTR 0x04 +#define ALT 0x08 +#define FITB 0x10 +#define FITW 0x20 +#define PUTW 0x40 +#define PUTL 0x80 + +#ifndef extern +extern short eamode[]; +#else +short eamode[] = { +/* 00A */ DTA |ALT, +/* 01A */ ALT, +/* 02A */ DTA|MEM|CTR|ALT, +/* 03A */ DTA|MEM |ALT, +/* 04A */ DTA|MEM |ALT, +/* 05A */ DTA|MEM|CTR|ALT|FITW|PUTW | (RELO2 )<<8, +/* 06A */ DTA|MEM|CTR|ALT |PUTW | (RELO1 )<<8, +/* 07x */ 0, +/* 070 */ DTA|MEM|CTR|ALT|FITW|PUTW | (RELO2 )<<8, +/* 071 */ DTA|MEM|CTR|ALT |PUTL | (RELO4 )<<8, +/* 072 */ DTA|MEM|CTR |FITW|PUTW | (RELO2|RELPC)<<8, +/* 073 */ DTA|MEM|CTR |PUTW | (RELO1|RELPC)<<8, +/* 074x */ 0, +/* 074B */ DTA|MEM |FITB|PUTW | (RELO1 )<<8, +/* 074W */ DTA|MEM |FITW|PUTW | (RELO2 )<<8, +/* 074L */ DTA|MEM |PUTL | (RELO4 )<<8, +}; +#endif diff --git a/mach/m68k2/as/mach2.c b/mach/m68k2/as/mach2.c new file mode 100644 index 00000000..1274e860 --- /dev/null +++ b/mach/m68k2/as/mach2.c @@ -0,0 +1,42 @@ +/* @(#)mach2.c 1.5 */ +/* + * Motorola 68000/68010 tokens + */ + +%token SIZE +%token DREG +%token AREG +%token PC +%token CREG +%token SPEC +%token ABCD +%token ADDX +%token ADD +%token AND +%token BITOP +%token SHIFT +%token SZ_EA +%token OP_EA +%token OP_NOOP +%token OP_EA_D +%token LEA +%token DBR +%token BR +%token CMP +%token MOVE +%token MOVEP +%token MOVEM +%token MOVEC +%token MOVES +%token SWAP +%token LINK +%token UNLK +%token TRAP +%token STOP +%token EXG +%token OP_EXT +%token RTD +%token MODEL + +%type bcdx op_ea regs rrange +%type reg sizedef sizenon creg diff --git a/mach/m68k2/as/mach3.c b/mach/m68k2/as/mach3.c new file mode 100644 index 00000000..363aae76 --- /dev/null +++ b/mach/m68k2/as/mach3.c @@ -0,0 +1,171 @@ +/* @(#)mach3.c 1.4 */ +/* + * Motorola 68000/68010 keywords + */ + +0, SIZE, SIZE_B, ".b", +0, SIZE, SIZE_W, ".w", +0, SIZE, SIZE_L, ".l", + +0, DREG, 00, "d0", +0, DREG, 01, "d1", +0, DREG, 02, "d2", +0, DREG, 03, "d3", +0, DREG, 04, "d4", +0, DREG, 05, "d5", +0, DREG, 06, "d6", +0, DREG, 07, "d7", + +0, AREG, 00, "a0", +0, AREG, 01, "a1", +0, AREG, 02, "a2", +0, AREG, 03, "a3", +0, AREG, 04, "a4", +0, AREG, 05, "a5", +0, AREG, 06, "a6", +0, AREG, 07, "a7", +0, AREG, 07, "sp", + +0, PC, 8, "pc", + +0, MODEL, 0, ".68000", +0, MODEL, 1, ".68010", + +0, CREG, 04001, "vbr", +0, CREG, 0, "sfc", +0, CREG, 00001, "dfc", + +0, SPEC, 075, "usp", +0, SPEC, 076, "ccr", +0, SPEC, 077, "sr", + +0, ABCD, 0140400, "abcd", +0, ABCD, 0100400, "sbcd", + +0, ADDX, 0150400, "addx", +0, ADDX, 0110400, "subx", + +0, ADD, 0153300, "add", +0, ADD, 0112700, "sub", + +0, AND, 0141000, "and", +0, AND, 0135000, "eor", +0, AND, 0100000, "or", + +0, BITOP, 0000, "btst", +0, BITOP, 0100, "bchg", +0, BITOP, 0200, "bclr", +0, BITOP, 0300, "bset", + +0, SHIFT, 0160340, "asr", +0, SHIFT, 0160740, "asl", +0, SHIFT, 0161350, "lsr", +0, SHIFT, 0161750, "lsl", +0, SHIFT, 0162360, "roxr", +0, SHIFT, 0162760, "roxl", +0, SHIFT, 0163370, "ror", +0, SHIFT, 0163770, "rol", + +0, SZ_EA, 041000|DTA|ALT, "clr", +0, SZ_EA, 042000|DTA|ALT, "neg", +0, SZ_EA, 040000|DTA|ALT, "negx", +0, SZ_EA, 043000|DTA|ALT, "not", +0, SZ_EA, 045000|DTA|ALT, "tst", + +0, OP_EA, 044000|DTA|ALT, "nbcd", +0, OP_EA, 045300|DTA|ALT, "tas", +0, OP_EA, 047200|CTR, "jsr", +0, OP_EA, 047300|CTR, "jmp", +0, OP_EA, 044100|CTR, "pea", + +0, OP_EA, 050300, "st", +0, OP_EA, 050700, "sf", +0, OP_EA, 051300, "shi", +0, OP_EA, 051700, "sls", +0, OP_EA, 052300, "scc", +0, OP_EA, 052700, "scs", +0, OP_EA, 053300, "sne", +0, OP_EA, 053700, "seq", +0, OP_EA, 054300, "svc", +0, OP_EA, 054700, "svs", +0, OP_EA, 055300, "spl", +0, OP_EA, 055700, "smi", +0, OP_EA, 056300, "sge", +0, OP_EA, 056700, "slt", +0, OP_EA, 057300, "sgt", +0, OP_EA, 057700, "sle", + +0, OP_NOOP, 047160, "reset", +0, OP_NOOP, 047161, "nop", +0, OP_NOOP, 047163, "rte", +0, OP_NOOP, 047165, "rts", +0, OP_NOOP, 047166, "trapv", +0, OP_NOOP, 047167, "rtr", +0, OP_NOOP, 045374, "illegal", + +0, OP_EA_D, 040600, "chk", +0, OP_EA_D, 0100300, "divu", +0, OP_EA_D, 0100700, "divs", +0, OP_EA_D, 0140300, "mulu", +0, OP_EA_D, 0140700, "muls", + +0, BR, 060000, "bra", +0, BR, 060400, "bsr", +0, BR, 061000, "bhi", +0, BR, 061400, "bls", +0, BR, 062000, "bcc", +0, BR, 062400, "bcs", +0, BR, 063000, "bne", +0, BR, 063400, "beq", +0, BR, 064000, "bvc", +0, BR, 064400, "bvs", +0, BR, 065000, "bpl", +0, BR, 065400, "bmi", +0, BR, 066000, "bge", +0, BR, 066400, "blt", +0, BR, 067000, "bgt", +0, BR, 067400, "ble", + +0, DBR, 050310, "dbt", +0, DBR, 050710, "dbf", +0, DBR, 050710, "dbra", +0, DBR, 051310, "dbhi", +0, DBR, 051710, "dbls", +0, DBR, 052310, "dbcc", +0, DBR, 052710, "dbcs", +0, DBR, 053310, "dbne", +0, DBR, 053710, "dbeq", +0, DBR, 054310, "dbvc", +0, DBR, 054710, "dbvs", +0, DBR, 055310, "dbpl", +0, DBR, 055710, "dbmi", +0, DBR, 056310, "dbge", +0, DBR, 056710, "dblt", +0, DBR, 057310, "dbgt", +0, DBR, 057710, "dble", + +0, CMP, 0, "cmp", + +0, MOVE, 0, "move", +0, MOVEP, 0, "movep", +0, MOVEM, 0, "movem", +0, MOVES, 0, "moves", +0, MOVEC, 0, "movec", + +0, SWAP, 0, "swap", + +0, LINK, 0, "link", + +0, UNLK, 0, "unlk", + +0, TRAP, 0, "trap", + +0, STOP, 047162, "stop", + +0, EXG, 0, "exg", + +0, OP_EXT, 0, "ext", + +0, LEA, 0, "lea", + +0, RTD, 0, "rtd", diff --git a/mach/m68k2/as/mach4.c b/mach/m68k2/as/mach4.c new file mode 100644 index 00000000..070a09be --- /dev/null +++ b/mach/m68k2/as/mach4.c @@ -0,0 +1,196 @@ +/* @(#)mach4.c 1.11 */ +/* + * Motorola 68000/68010 syntax rules + */ + +operation + : bcdx DREG ',' DREG + { emit2($1 | $2 | $4<<9);} + | bcdx '-' '(' AREG ')' ',' '-' '(' AREG ')' + { emit2($1 | $4 | $9<<9 | 010);} + | ADD sizedef ea_ea + { add($1, $2);} + | AND sizenon ea_ea + { and($1, $2);} + | SHIFT sizedef ea_ea + { shift_op($1, $2);} + | BR expr + { branch($1, $2);} + | DBR DREG ',' expr + { $4.val -= (DOTVAL+2); + fit(fitw($4.val)); + emit2($1 | $2); +#ifdef RELOCATION +#ifdef DUK + newrelo($4.typ, RELPC|RELO2|RELBR|RELWR); +#else DUK + newrelo($4.typ, RELPC|RELO2); +#endif DUK +#endif + emit2(loww($4.val)); + } + | BITOP ea_ea + { bitop($1);} + | OP_EA_D ea ',' DREG + { emit2($1 | mrg_2 | $4<<9); + ea_2(SIZE_W, DTA); + } + | LEA ea ',' AREG + { emit2(040700 | mrg_2 | $4<<9); + ea_2(SIZE_L, CTR); + } + | op_ea ea + { emit2(($1&0177700) | mrg_2); + ea_2($1&0300, $1&017); + } + | OP_NOOP + { emit2($1);} + | CMP sizedef ea_ea + { cmp($2);} + | MOVE sizenon ea_ea + { move($2);} + | MOVEP sizedef ea_ea + { movep($2);} + | MOVEM sizedef regs ',' notimmreg + { movem(0, $2, $3);} + | MOVEM sizedef notimmreg ',' regs + { movem(1, $2, $5);} + | MOVES sizedef ea_ea + { test68010(); + if (mrg_1 <= 017) { + emit2(007000 | $2 | mrg_2); + emit2(mrg_1 << 12 | 04000); + ea_2($2,ALT|MEM); + } else if (mrg_2 <= 017) { + emit2(007000 | $2 | mrg_1); + emit2(mrg_2 << 12); + ea_1($2,ALT|MEM); + } else + badoperand(); + } + | MOVEC creg ',' reg + { test68010(); + emit2(047172); emit2($2 | $4<<12); + } + | MOVEC reg ',' creg + { test68010(); + emit2(047173); emit2($4 | $2<<12); + } + | EXG reg ',' reg + { if (($2 & 010) == 0) + emit2( + (0140500|$4|$2<<9) + + + (($4&010)<<3) + ); + else + emit2( + (0140600|$2|($4&07)<<9) + - + (($4&010)<<3) + ); + } + | OP_EXT sizedef DREG + { checksize($2, 2|4); emit2(044000 | $2+0100 | $3);} + | SWAP DREG + { emit2(044100 | $2);} + | STOP imm + { emit2($1); ea_2(SIZE_W, 0);} + | LINK AREG ',' imm + { emit2(047120 | $2); ea_2(SIZE_W, 0);} + | UNLK AREG + { emit2(047130 | $2);} + | TRAP '#' absexp + { fit(fit4($3)); emit2(047100|low4($3));} + | RTD imm + { test68010(); + emit2(047164); + ea_2(SIZE_W, 0); + } + | MODEL + { model = $1;} + ; +bcdx : ABCD + | ADDX sizedef + { $$ = $1 | $2;} + ; +creg : CREG + | SPEC { if ($1 != 075) badoperand(); $$ = 04000;} + ; +op_ea : OP_EA + | SZ_EA sizedef + { $$ = $1 | $2;} + ; +regs : rrange + | regs '/' rrange + { $$ = $1 | $3;} + ; +rrange : reg + { $$ = 1<<$1;} + | reg '-' reg + { if ($1 > $3) + badoperand(); + for ($$ = 0; $1 <= $3; $1++) + $$ |= (1<<$1); + } + ; +ea : DREG + { mrg_2 = $1;} + | AREG + { mrg_2 = 010 | $1;} + | SPEC + { mrg_2 = $1;} + | notimmreg + | imm + ; +notimmreg + : '(' AREG ')' + { mrg_2 = 020 | $2;} + | '(' AREG ')' '+' + { mrg_2 = 030 | $2;} + | '-' '(' AREG ')' + { mrg_2 = 040 | $3;} + | expr sizenon + { exp_2 = $1; ea707172($2); + RELOMOVE(rel_2, relonami); + } + | expr '(' reg sizenon ')' + { exp_2 = $1; ea5x73($3, $4); + RELOMOVE(rel_2, relonami); + } + | expr '(' AREG ',' reg sizedef ')' + { exp_2 = $1; ea6x($3, $5, $6); + RELOMOVE(rel_2, relonami); + } + | expr '(' PC ')' + { exp_2 = $1; ea72(); + RELOMOVE(rel_2, relonami); + } + | expr '(' PC ',' reg sizedef ')' + { exp_2 = $1; ea73($5, $6); + RELOMOVE(rel_2, relonami); + } + ; +imm : '#' expr + { mrg_2 = 074; exp_2 = $2; + RELOMOVE(rel_2, relonami); + } + ; +reg : DREG + | AREG + { $$ = $1 | 010;} + ; +sizedef : /* empty */ + { $$ = SIZE_DEF;} + | SIZE + ; +sizenon : /* empty */ + { $$ = SIZE_NON;} + | SIZE + ; +ea_ea : ea ',' + { mrg_1 = mrg_2; exp_1 = exp_2; + RELOMOVE(rel_1, rel_2); + } + ea + ; diff --git a/mach/m68k2/as/mach5.c b/mach/m68k2/as/mach5.c new file mode 100644 index 00000000..bec9624a --- /dev/null +++ b/mach/m68k2/as/mach5.c @@ -0,0 +1,460 @@ +/* @(#)mach5.c 1.16 */ +/* + * Motorola 68000/68010 auxiliary functions + */ + +ea_1(sz, bits) +{ + register flag; + + if (mrg_1 > 074) + serror("no specials"); + if ((flag = eamode[mrg_1>>3]) == 0) + if ((flag = eamode[010 + (mrg_1&07)]) == 0) + flag = eamode[015 + (sz>>6)]; + if ((mrg_1 & 070) == 010) + checksize(sz, 2|4); + bits &= ~flag; + if (bits) + serror("bad addressing categorie"); + if (flag & FITW) + if ( + ! fitw(exp_1.val) + && + (mrg_1 != 074 || ! fit16(exp_1.val)) + ) + nofit(); + if (flag & FITB) { + if ( + ! fitb(exp_1.val) + && + (mrg_1 != 074 || ! fit8(exp_1.val)) + ) + nofit(); + if (mrg_1 == 074) + exp_1.val &= 0xFF; + } +#ifdef RELOCATION + RELOMOVE(relonami, rel_1); + if (flag & ~0xFF) +#ifdef DUK + newrelo(exp_1.typ, (flag>>8) | RELBR | RELWR); +#else DUK + newrelo(exp_1.typ, flag>>8); +#endif DUK +#endif + if (flag & PUTL) + emit4(exp_1.val); + if (flag & PUTW) + emit2(loww(exp_1.val)); +} + +ea_2(sz, bits) +{ + mrg_1 = mrg_2; + exp_1 = exp_2; + RELOMOVE(rel_1, rel_2); + ea_1(sz, bits); +} + +index(hibyte) +{ + fit(fitb(exp_2.val)); + exp_2.val = hibyte | lowb(exp_2.val); +} + +checksize(sz, bits) +{ + if ((bits & (1 << (sz>>6))) == 0) + serror("bad size"); +} + +test68010() +{ + if (model != 1) + warning("68010 instruction"); +} + +badoperand() +{ + serror("bad operands"); +} + +shift_op(opc, sz) +{ + if (mrg_1 < 010 && mrg_2 < 010) { + emit2((opc&0170470) | sz | mrg_1<<9 | mrg_2); + return; + } + if (exp_1.typ != S_ABS || mrg_1 != 074) { + badoperand(); + return; + } + if (mrg_2 < 010) { + fit(fit3(exp_1.val)); + emit2((opc&0170430) | sz | low3(exp_1.val)<<9 | mrg_2); + return; + } + checksize(sz, 2); + fit(exp_1.val == 1); + emit2((opc&0177700) | mrg_2); + ea_2(SIZE_W, MEM|ALT); +} + +bitop(opc) +{ + register bits; + + bits = DTA|ALT; + if (opc == 0 && (mrg_1 < 010 || mrg_2 != 074)) + bits = DTA; + if (mrg_1 < 010) { + emit2(opc | 0400 | mrg_1<<9 | mrg_2); + ea_2(0, bits); + return; + } + if (mrg_1 == 074) { + emit2(opc | 04000 | mrg_2); + ea_1(SIZE_W, 0); + ea_2(0, bits); + return; + } + badoperand(); +} + +add(opc, sz) +{ + if ((mrg_2 & 070) == 010) + checksize(sz, 2|4); + if ( + mrg_1 == 074 + && + small( + exp_1.typ==S_ABS && fit3(exp_1.val), + sz==SIZE_L ? 4 : 2 + ) + ) { + emit2((opc&0400) | 050000 | low3(exp_1.val)<<9 | sz | mrg_2); + ea_2(sz, ALT); + return; + } + if (mrg_1 == 074 && (mrg_2 & 070) != 010) { + emit2((opc&03000) | sz | mrg_2); + ea_1(sz, 0); + ea_2(sz, DTA|ALT); + return; + } + if ((mrg_2 & 070) == 010) { + emit2((opc&0170300) | (mrg_2&7)<<9 | sz<<1 | mrg_1); + ea_1(sz, 0); + return; + } + if (to_dreg(opc, sz, 0)) + return; + if (from_dreg(opc, sz, ALT|MEM)) + return; + badoperand(); +} + +and(opc, sz) +{ + if (mrg_1 == 074 && mrg_2 >= 076) { /* ccr or sr */ + if (sz != SIZE_NON) + checksize(sz, mrg_2==076 ? 1 : 2); + else + sz = (mrg_2==076 ? SIZE_B : SIZE_W); + emit2((opc&07400) | sz | 074); + ea_1(sz, 0); + return; + } + if (sz == SIZE_NON) + sz = SIZE_DEF; + if (mrg_1 == 074) { + emit2((opc&07400) | sz | mrg_2); + ea_1(sz, 0); + ea_2(sz, DTA|ALT); + return; + } + if ((opc & 010000) == 0 && to_dreg(opc, sz, DTA)) + return; + if (from_dreg(opc, sz, (opc & 010000) ? DTA|ALT : ALT|MEM)) + return; + badoperand(); +} + +to_dreg(opc, sz, bits) +{ + if ((mrg_2 & 070) != 000) + return(0); + emit2((opc & 0170000) | sz | (mrg_2&7)<<9 | mrg_1); + ea_1(sz, bits); + return(1); +} + +from_dreg(opc, sz, bits) +{ + if ((mrg_1 & 070) != 000) + return(0); + emit2((opc & 0170000) | sz | (mrg_1&7)<<9 | 0400 | mrg_2); + ea_2(sz, bits); + return(1); +} + +cmp(sz) +{ + register opc; + + if ((mrg_1&070) == 030 && (mrg_2&070) == 030) { + emit2(0130410 | sz | (mrg_1&7) | (mrg_2&7)<<9); + return; + } + if (mrg_1 == 074 && (mrg_2 & 070) != 010) { + emit2(06000 | sz | mrg_2); + ea_1(sz, 0); + ea_2(sz, DTA|ALT); + return; + } + if (mrg_2 < 020) { + if (mrg_2 >= 010) { + checksize(sz, 2|4); + opc = 0130300 | sz<<1; + mrg_2 &= 7; + } else + opc = 0130000 | sz; + emit2(opc | mrg_2<<9 | mrg_1); + ea_1(sz, 0); + return; + } + badoperand(); +} + +move(sz) +{ + register opc; + + if (mrg_1 > 074 || mrg_2 > 074) { + move_special(sz); + return; + } + if (sz == SIZE_NON) + sz = SIZE_DEF; + if ( + mrg_2<010 + && + mrg_1==074 + && + sz==SIZE_L + && + small(exp_1.typ==S_ABS && fitb(exp_1.val), 4) + ) { + emit2(070000 | mrg_2<<9 | lowb(exp_1.val)); + return; + } + switch (sz) { + case SIZE_B: opc = 010000; break; + case SIZE_W: opc = 030000; break; + case SIZE_L: opc = 020000; break; + } + emit2(opc | mrg_1 | (mrg_2&7)<<9 | (mrg_2&070)<<3); + ea_1(sz, 0); + ea_2(sz, ALT); +} + +move_special(sz) +{ + if (mrg_2 >= 076) { + if (sz != SIZE_NON) + checksize(sz, 2); + emit2(042300 | (mrg_2==076?0:01000) | mrg_1); + ea_1(SIZE_W, DTA); + return; + } + if (mrg_1 >= 076) { + if (mrg_1 == 076) + test68010(); + if (sz != SIZE_NON) + checksize(sz, 2); + emit2(040300 | (mrg_1==076?01000:0) | mrg_2); + ea_2(SIZE_W, DTA|ALT); + return; + } + if (sz != SIZE_NON) + checksize(sz, 4); + if (mrg_1==075 && (mrg_2&070)==010) { + emit2(047150 | (mrg_2&7)); + return; + } + if (mrg_2==075 && (mrg_1&070)==010) { + emit2(047140 | (mrg_1&7)); + return; + } + badoperand(); +} + +movem(dr, sz, regs) +{ + register i; + register r; + + if ((mrg_2>>3) == 04) { + r = regs; regs = 0; + for (i = 0; i < 16; i++) { + regs <<= 1; + if (r & 1) + regs++; + r >>= 1; + } + } + checksize(sz, 2|4); + if ((mrg_2>>3)-3 == dr) + badoperand(); + emit2(044200 | dr<<10 | (sz & 0200) >> 1 | mrg_2); + emit2(regs); + i = CTR; + if (dr == 0 && (mrg_2&070) == 040) + i = MEM; + if (dr != 0 && (mrg_2&070) == 030) + i = MEM; + if (dr == 0) + i |= ALT; + ea_2(sz, i); +} + +movep(sz) +{ + checksize(sz, 2|4); + if (mrg_1<010 && (mrg_2&070)==050) { + emit2(0610 | (sz & 0200)>>1 | mrg_1<<9 | (mrg_2&7)); + ea_2(sz, 0); + return; + } + if (mrg_2<010 && (mrg_1&070)==050) { + emit2(0410 | (sz & 0200)>>1 | mrg_2<<9 | (mrg_1&7)); + ea_1(sz, 0); + return; + } + badoperand(); +} + +branch(opc, exp) +expr_t exp; +{ + register sm; + + exp.val -= (DOTVAL + 2); + if ((pass == PASS_2) + && + (exp.val > 0) + && + ((exp.typ & S_DOT) == 0) + ) + exp.val -= DOTGAIN; + sm = fitb(exp.val); + if ((exp.typ & ~S_DOT) != DOTTYP) + sm = 0; + if (small(sm,2)) { + if (exp.val == 0) + emit2(047161); /* NOP */ + else + emit2(opc | lowb(exp.val)); + } else { + fit(fitw(exp.val)); + emit2(opc); +#ifdef RELOCATION +#ifdef DUK + newrelo(exp.typ, RELPC|RELO2|RELBR|RELWR); +#else DUK + newrelo(exp.typ, RELPC|RELO2); +#endif DUK +#endif + emit2(loww(exp.val)); + } +} + +ea5x73(rg, sz) +{ + if ((exp_2.typ & ~S_DOT) == DOTTYP) { + /* pc relative with index */ + if (sz == SIZE_NON) + sz = SIZE_DEF; + exp_2.val -= (DOTVAL + 2); + mrg_2 = 073; + checksize(sz, 2|4); + index(rg<<12 | (sz&0200)<<4); + return; + } + /* displacement */ + mrg_2 = 050 | rg; + if (pass == PASS_1) /* tricky, maybe 073 in next passes */ + return; + if ((rg & 010) == 0 || sz != SIZE_NON) + badoperand(); +} + +ea707172(sz) +{ + register sm; + + mrg_2 = 071; + switch (sz) { + case SIZE_B: + badoperand(); + case SIZE_W: + mrg_2 = 070; + case SIZE_L: + return; + case SIZE_NON: + break; + } + if (pass == PASS_1) { + /* + * reserve a bit in the bittable + * in the following passes one call to small() + * will be done, but we don't know which one + * since exp_2.typ cannot be trusted + */ + small(0, 2); + return; + } + if ((exp_2.typ & ~S_DOT) == DOTTYP) { + sm = fitw(exp_2.val-(DOTVAL+2)); + sm = small(sm, 2); + if (sm) { /* pc relative */ + exp_2.val -= (DOTVAL+2); + mrg_2 = 072; + } + } else { + sm = fitw(exp_2.val); +#ifdef ASLD + if (exp_2.typ & S_VAR) + sm = 0; +#else + if (exp_2.typ != S_ABS) + sm = 0; +#endif ASLD + sm = small(sm, 2); + if (sm) + mrg_2 = 070; + } +} + +ea6x(rg, ir, sz) +{ + mrg_2 = 060 | rg; + checksize(sz, 2|4); + index(ir<<12 | (sz&0200)<<4); +} + +ea72() +{ + mrg_2 = 072; + exp_2.val -= (DOTVAL + 2); +} + +ea73(ri, sz) +{ + mrg_2 = 073; + exp_2.val -= (DOTVAL + 2); + checksize(sz, 2|4); + index(ri<<12 | (sz&0200)<<4); +} diff --git a/mach/ns/as/Makefile b/mach/ns/as/Makefile index 012b0382..695d2b20 100644 --- a/mach/ns/as/Makefile +++ b/mach/ns/as/Makefile @@ -6,14 +6,14 @@ CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I$h $(DEF) +CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) YFLAGS = -d LDFLAGS = $(FFLAG) -i CSRC = $(CDIR)/comm3.c $(CDIR)/comm4.c $(CDIR)/comm5.c \ $(CDIR)/comm6.c $(CDIR)/comm7.c $(CDIR)/comm8.c -COBJ = $(CDIR)/comm3.o $(CDIR)/comm4.o $(CDIR)/comm5.o \ - $(CDIR)/comm6.o $(CDIR)/comm7.o $(CDIR)/comm8.o +COBJ = comm3.o comm4.o comm5.o \ + comm6.o comm7.o comm8.o MACH = mach0.c mach1.c mach2.c mach3.c mach4.c mach5.c COMM = $(CDIR)/comm0.h $(CDIR)/comm1.h $(CDIR)/comm2.y $(CSRC) @@ -37,7 +37,7 @@ as: $(COBJ) as.o $(CC) $(LDFLAGS) $(COBJ) as.o -o as as.y: $(CDIR)/comm2.y - $(CPP) -P -I$h $(DEF) $(CDIR)/comm2.y >as.y + $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c @@ -51,3 +51,15 @@ as.y: mach2.c comm3.o: mach3.c as.y: mach4.c comm8.o: mach5.c +comm3.o: $(CDIR)/comm3.c + $(CC) -c $(CFLAGS) $(CDIR)/comm3.c +comm4.o: $(CDIR)/comm4.c + $(CC) -c $(CFLAGS) $(CDIR)/comm4.c +comm5.o: $(CDIR)/comm5.c + $(CC) -c $(CFLAGS) $(CDIR)/comm5.c +comm6.o: $(CDIR)/comm6.c + $(CC) -c $(CFLAGS) $(CDIR)/comm6.c +comm7.o: $(CDIR)/comm7.c + $(CC) -c $(CFLAGS) $(CDIR)/comm7.c +comm8.o: $(CDIR)/comm8.c + $(CC) -c $(CFLAGS) $(CDIR)/comm8.c diff --git a/mach/pdp/as/Makefile b/mach/pdp/as/Makefile index 012b0382..695d2b20 100644 --- a/mach/pdp/as/Makefile +++ b/mach/pdp/as/Makefile @@ -6,14 +6,14 @@ CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I$h $(DEF) +CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) YFLAGS = -d LDFLAGS = $(FFLAG) -i CSRC = $(CDIR)/comm3.c $(CDIR)/comm4.c $(CDIR)/comm5.c \ $(CDIR)/comm6.c $(CDIR)/comm7.c $(CDIR)/comm8.c -COBJ = $(CDIR)/comm3.o $(CDIR)/comm4.o $(CDIR)/comm5.o \ - $(CDIR)/comm6.o $(CDIR)/comm7.o $(CDIR)/comm8.o +COBJ = comm3.o comm4.o comm5.o \ + comm6.o comm7.o comm8.o MACH = mach0.c mach1.c mach2.c mach3.c mach4.c mach5.c COMM = $(CDIR)/comm0.h $(CDIR)/comm1.h $(CDIR)/comm2.y $(CSRC) @@ -37,7 +37,7 @@ as: $(COBJ) as.o $(CC) $(LDFLAGS) $(COBJ) as.o -o as as.y: $(CDIR)/comm2.y - $(CPP) -P -I$h $(DEF) $(CDIR)/comm2.y >as.y + $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c @@ -51,3 +51,15 @@ as.y: mach2.c comm3.o: mach3.c as.y: mach4.c comm8.o: mach5.c +comm3.o: $(CDIR)/comm3.c + $(CC) -c $(CFLAGS) $(CDIR)/comm3.c +comm4.o: $(CDIR)/comm4.c + $(CC) -c $(CFLAGS) $(CDIR)/comm4.c +comm5.o: $(CDIR)/comm5.c + $(CC) -c $(CFLAGS) $(CDIR)/comm5.c +comm6.o: $(CDIR)/comm6.c + $(CC) -c $(CFLAGS) $(CDIR)/comm6.c +comm7.o: $(CDIR)/comm7.c + $(CC) -c $(CFLAGS) $(CDIR)/comm7.c +comm8.o: $(CDIR)/comm8.c + $(CC) -c $(CFLAGS) $(CDIR)/comm8.c diff --git a/mach/proto/as/Makefile b/mach/proto/as/Makefile index 012b0382..695d2b20 100644 --- a/mach/proto/as/Makefile +++ b/mach/proto/as/Makefile @@ -6,14 +6,14 @@ CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I$h $(DEF) +CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) YFLAGS = -d LDFLAGS = $(FFLAG) -i CSRC = $(CDIR)/comm3.c $(CDIR)/comm4.c $(CDIR)/comm5.c \ $(CDIR)/comm6.c $(CDIR)/comm7.c $(CDIR)/comm8.c -COBJ = $(CDIR)/comm3.o $(CDIR)/comm4.o $(CDIR)/comm5.o \ - $(CDIR)/comm6.o $(CDIR)/comm7.o $(CDIR)/comm8.o +COBJ = comm3.o comm4.o comm5.o \ + comm6.o comm7.o comm8.o MACH = mach0.c mach1.c mach2.c mach3.c mach4.c mach5.c COMM = $(CDIR)/comm0.h $(CDIR)/comm1.h $(CDIR)/comm2.y $(CSRC) @@ -37,7 +37,7 @@ as: $(COBJ) as.o $(CC) $(LDFLAGS) $(COBJ) as.o -o as as.y: $(CDIR)/comm2.y - $(CPP) -P -I$h $(DEF) $(CDIR)/comm2.y >as.y + $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c @@ -51,3 +51,15 @@ as.y: mach2.c comm3.o: mach3.c as.y: mach4.c comm8.o: mach5.c +comm3.o: $(CDIR)/comm3.c + $(CC) -c $(CFLAGS) $(CDIR)/comm3.c +comm4.o: $(CDIR)/comm4.c + $(CC) -c $(CFLAGS) $(CDIR)/comm4.c +comm5.o: $(CDIR)/comm5.c + $(CC) -c $(CFLAGS) $(CDIR)/comm5.c +comm6.o: $(CDIR)/comm6.c + $(CC) -c $(CFLAGS) $(CDIR)/comm6.c +comm7.o: $(CDIR)/comm7.c + $(CC) -c $(CFLAGS) $(CDIR)/comm7.c +comm8.o: $(CDIR)/comm8.c + $(CC) -c $(CFLAGS) $(CDIR)/comm8.c diff --git a/mach/s2650/as/Makefile b/mach/s2650/as/Makefile index 012b0382..695d2b20 100644 --- a/mach/s2650/as/Makefile +++ b/mach/s2650/as/Makefile @@ -6,14 +6,14 @@ CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I$h $(DEF) +CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) YFLAGS = -d LDFLAGS = $(FFLAG) -i CSRC = $(CDIR)/comm3.c $(CDIR)/comm4.c $(CDIR)/comm5.c \ $(CDIR)/comm6.c $(CDIR)/comm7.c $(CDIR)/comm8.c -COBJ = $(CDIR)/comm3.o $(CDIR)/comm4.o $(CDIR)/comm5.o \ - $(CDIR)/comm6.o $(CDIR)/comm7.o $(CDIR)/comm8.o +COBJ = comm3.o comm4.o comm5.o \ + comm6.o comm7.o comm8.o MACH = mach0.c mach1.c mach2.c mach3.c mach4.c mach5.c COMM = $(CDIR)/comm0.h $(CDIR)/comm1.h $(CDIR)/comm2.y $(CSRC) @@ -37,7 +37,7 @@ as: $(COBJ) as.o $(CC) $(LDFLAGS) $(COBJ) as.o -o as as.y: $(CDIR)/comm2.y - $(CPP) -P -I$h $(DEF) $(CDIR)/comm2.y >as.y + $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c @@ -51,3 +51,15 @@ as.y: mach2.c comm3.o: mach3.c as.y: mach4.c comm8.o: mach5.c +comm3.o: $(CDIR)/comm3.c + $(CC) -c $(CFLAGS) $(CDIR)/comm3.c +comm4.o: $(CDIR)/comm4.c + $(CC) -c $(CFLAGS) $(CDIR)/comm4.c +comm5.o: $(CDIR)/comm5.c + $(CC) -c $(CFLAGS) $(CDIR)/comm5.c +comm6.o: $(CDIR)/comm6.c + $(CC) -c $(CFLAGS) $(CDIR)/comm6.c +comm7.o: $(CDIR)/comm7.c + $(CC) -c $(CFLAGS) $(CDIR)/comm7.c +comm8.o: $(CDIR)/comm8.c + $(CC) -c $(CFLAGS) $(CDIR)/comm8.c diff --git a/mach/vax4/as/Makefile b/mach/vax4/as/Makefile index 012b0382..695d2b20 100644 --- a/mach/vax4/as/Makefile +++ b/mach/vax4/as/Makefile @@ -6,14 +6,14 @@ CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I$h $(DEF) +CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) YFLAGS = -d LDFLAGS = $(FFLAG) -i CSRC = $(CDIR)/comm3.c $(CDIR)/comm4.c $(CDIR)/comm5.c \ $(CDIR)/comm6.c $(CDIR)/comm7.c $(CDIR)/comm8.c -COBJ = $(CDIR)/comm3.o $(CDIR)/comm4.o $(CDIR)/comm5.o \ - $(CDIR)/comm6.o $(CDIR)/comm7.o $(CDIR)/comm8.o +COBJ = comm3.o comm4.o comm5.o \ + comm6.o comm7.o comm8.o MACH = mach0.c mach1.c mach2.c mach3.c mach4.c mach5.c COMM = $(CDIR)/comm0.h $(CDIR)/comm1.h $(CDIR)/comm2.y $(CSRC) @@ -37,7 +37,7 @@ as: $(COBJ) as.o $(CC) $(LDFLAGS) $(COBJ) as.o -o as as.y: $(CDIR)/comm2.y - $(CPP) -P -I$h $(DEF) $(CDIR)/comm2.y >as.y + $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c @@ -51,3 +51,15 @@ as.y: mach2.c comm3.o: mach3.c as.y: mach4.c comm8.o: mach5.c +comm3.o: $(CDIR)/comm3.c + $(CC) -c $(CFLAGS) $(CDIR)/comm3.c +comm4.o: $(CDIR)/comm4.c + $(CC) -c $(CFLAGS) $(CDIR)/comm4.c +comm5.o: $(CDIR)/comm5.c + $(CC) -c $(CFLAGS) $(CDIR)/comm5.c +comm6.o: $(CDIR)/comm6.c + $(CC) -c $(CFLAGS) $(CDIR)/comm6.c +comm7.o: $(CDIR)/comm7.c + $(CC) -c $(CFLAGS) $(CDIR)/comm7.c +comm8.o: $(CDIR)/comm8.c + $(CC) -c $(CFLAGS) $(CDIR)/comm8.c diff --git a/mach/z80/as/Makefile b/mach/z80/as/Makefile index 012b0382..695d2b20 100644 --- a/mach/z80/as/Makefile +++ b/mach/z80/as/Makefile @@ -6,14 +6,14 @@ CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I$h $(DEF) +CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) YFLAGS = -d LDFLAGS = $(FFLAG) -i CSRC = $(CDIR)/comm3.c $(CDIR)/comm4.c $(CDIR)/comm5.c \ $(CDIR)/comm6.c $(CDIR)/comm7.c $(CDIR)/comm8.c -COBJ = $(CDIR)/comm3.o $(CDIR)/comm4.o $(CDIR)/comm5.o \ - $(CDIR)/comm6.o $(CDIR)/comm7.o $(CDIR)/comm8.o +COBJ = comm3.o comm4.o comm5.o \ + comm6.o comm7.o comm8.o MACH = mach0.c mach1.c mach2.c mach3.c mach4.c mach5.c COMM = $(CDIR)/comm0.h $(CDIR)/comm1.h $(CDIR)/comm2.y $(CSRC) @@ -37,7 +37,7 @@ as: $(COBJ) as.o $(CC) $(LDFLAGS) $(COBJ) as.o -o as as.y: $(CDIR)/comm2.y - $(CPP) -P -I$h $(DEF) $(CDIR)/comm2.y >as.y + $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c @@ -51,3 +51,15 @@ as.y: mach2.c comm3.o: mach3.c as.y: mach4.c comm8.o: mach5.c +comm3.o: $(CDIR)/comm3.c + $(CC) -c $(CFLAGS) $(CDIR)/comm3.c +comm4.o: $(CDIR)/comm4.c + $(CC) -c $(CFLAGS) $(CDIR)/comm4.c +comm5.o: $(CDIR)/comm5.c + $(CC) -c $(CFLAGS) $(CDIR)/comm5.c +comm6.o: $(CDIR)/comm6.c + $(CC) -c $(CFLAGS) $(CDIR)/comm6.c +comm7.o: $(CDIR)/comm7.c + $(CC) -c $(CFLAGS) $(CDIR)/comm7.c +comm8.o: $(CDIR)/comm8.c + $(CC) -c $(CFLAGS) $(CDIR)/comm8.c diff --git a/mach/z8000/as/Makefile b/mach/z8000/as/Makefile index 012b0382..695d2b20 100644 --- a/mach/z8000/as/Makefile +++ b/mach/z8000/as/Makefile @@ -6,14 +6,14 @@ CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I$h $(DEF) +CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) YFLAGS = -d LDFLAGS = $(FFLAG) -i CSRC = $(CDIR)/comm3.c $(CDIR)/comm4.c $(CDIR)/comm5.c \ $(CDIR)/comm6.c $(CDIR)/comm7.c $(CDIR)/comm8.c -COBJ = $(CDIR)/comm3.o $(CDIR)/comm4.o $(CDIR)/comm5.o \ - $(CDIR)/comm6.o $(CDIR)/comm7.o $(CDIR)/comm8.o +COBJ = comm3.o comm4.o comm5.o \ + comm6.o comm7.o comm8.o MACH = mach0.c mach1.c mach2.c mach3.c mach4.c mach5.c COMM = $(CDIR)/comm0.h $(CDIR)/comm1.h $(CDIR)/comm2.y $(CSRC) @@ -37,7 +37,7 @@ as: $(COBJ) as.o $(CC) $(LDFLAGS) $(COBJ) as.o -o as as.y: $(CDIR)/comm2.y - $(CPP) -P -I$h $(DEF) $(CDIR)/comm2.y >as.y + $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c @@ -51,3 +51,15 @@ as.y: mach2.c comm3.o: mach3.c as.y: mach4.c comm8.o: mach5.c +comm3.o: $(CDIR)/comm3.c + $(CC) -c $(CFLAGS) $(CDIR)/comm3.c +comm4.o: $(CDIR)/comm4.c + $(CC) -c $(CFLAGS) $(CDIR)/comm4.c +comm5.o: $(CDIR)/comm5.c + $(CC) -c $(CFLAGS) $(CDIR)/comm5.c +comm6.o: $(CDIR)/comm6.c + $(CC) -c $(CFLAGS) $(CDIR)/comm6.c +comm7.o: $(CDIR)/comm7.c + $(CC) -c $(CFLAGS) $(CDIR)/comm7.c +comm8.o: $(CDIR)/comm8.c + $(CC) -c $(CFLAGS) $(CDIR)/comm8.c diff --git a/util/led/READ_ME b/util/led/READ_ME new file mode 100644 index 00000000..e612fa34 --- /dev/null +++ b/util/led/READ_ME @@ -0,0 +1,600 @@ +You may want to change mach.c in this directory. + +Archives MUST have a table of contents. Arch in subdirectory arch +automatically makes one when you change an archive. + +Several changes in the assembler were needed to have it generate the +necessary output. +A contextual diff follows. You can apply them as follows: +patch -d /usr/em/philips/mach/68000/as < READ_ME + +*** comm0.h.old Thu Dec 6 16:18:39 1984 +--- comm0.h Thu Dec 6 17:49:51 1984 +*************** +*** 213,218 + + /* + * extra type bits out of S_ETC, internal use only + * S_COM: + * - symbols declared by .comm + * S_VAR: + +--- 213,219 ----- + + /* + * extra type bits out of S_ETC, internal use only ++ #ifndef DUK + * S_COM: + * - symbols declared by .comm + #endif DUK +*************** +*** 215,220 + * extra type bits out of S_ETC, internal use only + * S_COM: + * - symbols declared by .comm + * S_VAR: + * - type not known at end of PASS_1 (S_VAR|S_UND) + * - value not known at end of PASS_2 (S_VAR|S_ABS) + +--- 216,222 ----- + #ifndef DUK + * S_COM: + * - symbols declared by .comm ++ #endif DUK + * S_VAR: + * - type not known at end of PASS_1 (S_VAR|S_UND) + * - value not known at end of PASS_2 (S_VAR|S_ABS) +*************** +*** 221,226 + * S_DOT: + * - dot expression + */ + #define S_COM 0x0100 + #define S_VAR 0x0200 + #define S_DOT 0x0400 + +--- 223,229 ----- + * S_DOT: + * - dot expression + */ ++ #ifndef DUK + #define S_COM 0x0100 + #endif DUK + #define S_VAR 0x0200 +*************** +*** 222,227 + * - dot expression + */ + #define S_COM 0x0100 + #define S_VAR 0x0200 + #define S_DOT 0x0400 + /* should be tested by preprocessor + +--- 225,231 ----- + */ + #ifndef DUK + #define S_COM 0x0100 ++ #endif DUK + #define S_VAR 0x0200 + #define S_DOT 0x0400 + /* should be tested by preprocessor +*** comm2.y.old Thu Dec 6 16:19:07 1984 +--- comm2.y Thu Dec 6 16:02:19 1984 +*************** +*** 229,234 + { + #ifdef RELOCATION + if (rflag != 0 && PASS_RELO) + newrelo($1.typ, (int)$0); + #endif + emitx($1.val, (int)$0); + +--- 229,239 ----- + { + #ifdef RELOCATION + if (rflag != 0 && PASS_RELO) ++ #ifdef DUK ++ newrelo($1.typ, ++ (int)$0 | RELBR | RELWR ++ ); ++ #else DUK + newrelo($1.typ, (int)$0); + #endif DUK + #endif +*************** +*** 230,235 + #ifdef RELOCATION + if (rflag != 0 && PASS_RELO) + newrelo($1.typ, (int)$0); + #endif + emitx($1.val, (int)$0); + } + +--- 235,241 ----- + ); + #else DUK + newrelo($1.typ, (int)$0); ++ #endif DUK + #endif + emitx($1.val, (int)$0); + } +*************** +*** 237,242 + { + #ifdef RELOCATION + if (rflag != 0 && PASS_RELO) + newrelo($3.typ, (int)$0); + #endif + emitx($3.val, (int)$0); + +--- 243,253 ----- + { + #ifdef RELOCATION + if (rflag != 0 && PASS_RELO) ++ #ifdef DUK ++ newrelo($3.typ, ++ (int)$0 | RELBR | RELWR ++ ); ++ #else DUK + newrelo($3.typ, (int)$0); + #endif DUK + #endif +*************** +*** 238,243 + #ifdef RELOCATION + if (rflag != 0 && PASS_RELO) + newrelo($3.typ, (int)$0); + #endif + emitx($3.val, (int)$0); + } + +--- 249,255 ----- + ); + #else DUK + newrelo($3.typ, (int)$0); ++ #endif DUK + #endif + emitx($3.val, (int)$0); + } +*** comm3.c.old Wed Jul 11 09:22:24 1984 +--- comm3.c Fri Dec 7 13:06:26 1984 +*************** +*** 11,16 + + struct outhead outhead = { + O_MAGIC, O_STAMP, 0 + #ifdef BYTES_REVERSED + | HF_BREV + #endif + +--- 11,17 ----- + + struct outhead outhead = { + O_MAGIC, O_STAMP, 0 ++ #ifndef DUK + #ifdef BYTES_REVERSED + | HF_BREV + #endif +*************** +*** 17,22 + #ifdef WORDS_REVERSED + | HF_WREV + #endif + }; + + #include "y.tab.h" + +--- 18,24 ----- + #ifdef WORDS_REVERSED + | HF_WREV + #endif ++ #endif DUK + }; + + #include "y.tab.h" +*** comm5.c.old Thu Dec 6 16:19:40 1984 +--- comm5.c Thu Oct 11 14:03:27 1984 +*************** +*** 162,167 + #endif + case STRING: + p = stringbuf; + *p++ = n = getc(tempfile); break; + case OP_EQ: + case OP_NE: + +--- 162,172 ----- + #endif + case STRING: + p = stringbuf; ++ #ifdef DUK ++ *p++ = n = getc(tempfile); ++ p[n] = '\0'; ++ break; ++ #else DUK + *p++ = n = getc(tempfile); break; + #endif DUK + case OP_EQ: +*************** +*** 163,168 + case STRING: + p = stringbuf; + *p++ = n = getc(tempfile); break; + case OP_EQ: + case OP_NE: + case OP_LE: + +--- 168,174 ----- + break; + #else DUK + *p++ = n = getc(tempfile); break; ++ #endif DUK + case OP_EQ: + case OP_NE: + case OP_LE: +*************** +*** 354,359 + break; + if (c == '\\') + c = inescape(); + if (p >= &stringbuf[STRINGMAX]) + fatal("string buffer overflow"); + *p++ = c; + +--- 360,368 ----- + break; + if (c == '\\') + c = inescape(); ++ #ifdef DUK ++ if (p >= &stringbuf[STRINGMAX - 1]) ++ #else DUK + if (p >= &stringbuf[STRINGMAX]) + #endif DUK + fatal("string buffer overflow"); +*************** +*** 355,360 + if (c == '\\') + c = inescape(); + if (p >= &stringbuf[STRINGMAX]) + fatal("string buffer overflow"); + *p++ = c; + } + +--- 364,370 ----- + if (p >= &stringbuf[STRINGMAX - 1]) + #else DUK + if (p >= &stringbuf[STRINGMAX]) ++ #endif DUK + fatal("string buffer overflow"); + *p++ = c; + } +*************** +*** 359,364 + *p++ = c; + } + stringbuf[0] = p - stringbuf - 1; + return(STRING); + } + + +--- 369,377 ----- + *p++ = c; + } + stringbuf[0] = p - stringbuf - 1; ++ #ifdef DUK ++ *p = '\0'; ++ #endif DUK + return(STRING); + } + +*** comm6.c.old Thu Dec 6 16:20:22 1984 +--- comm6.c Wed Oct 3 15:59:31 1984 +*************** +*** 106,111 + sp = §[typ - S_MIN]; + sp->s_item = ip; + sp->s_lign = ALIGNSECT; + ip->i_type = typ | S_EXT; + ip->i_valu = 0; + } else if (typ >= S_MIN) { + +--- 106,114 ----- + sp = §[typ - S_MIN]; + sp->s_item = ip; + sp->s_lign = ALIGNSECT; ++ #ifdef DUK ++ ip->i_type = typ; ++ #else DUK + ip->i_type = typ | S_EXT; + #endif DUK + ip->i_valu = 0; +*************** +*** 107,112 + sp->s_item = ip; + sp->s_lign = ALIGNSECT; + ip->i_type = typ | S_EXT; + ip->i_valu = 0; + } else if (typ >= S_MIN) { + sp = §[typ - S_MIN]; + +--- 110,116 ----- + ip->i_type = typ; + #else DUK + ip->i_type = typ | S_EXT; ++ #endif DUK + ip->i_valu = 0; + } else if (typ >= S_MIN) { + sp = §[typ - S_MIN]; +*************** +*** 180,185 + * for possible relocation + */ + ip->i_valu = outhead.oh_nname; + newsymb(ip->i_name, S_EXT|DOTTYP, (short)0, val); + #endif + } + +--- 184,192 ----- + * for possible relocation + */ + ip->i_valu = outhead.oh_nname; ++ #ifdef DUK ++ newsymb(ip->i_name, S_COM|S_EXT|DOTTYP, (short)0, val); ++ #else DUK + newsymb(ip->i_name, S_EXT|DOTTYP, (short)0, val); + #endif DUK + #endif +*************** +*** 181,186 + */ + ip->i_valu = outhead.oh_nname; + newsymb(ip->i_name, S_EXT|DOTTYP, (short)0, val); + #endif + } + + +--- 188,194 ----- + newsymb(ip->i_name, S_COM|S_EXT|DOTTYP, (short)0, val); + #else DUK + newsymb(ip->i_name, S_EXT|DOTTYP, (short)0, val); ++ #endif DUK + #endif + } + +*************** +*** 255,260 + short s; + { + struct outrelo outrelo; + + if (rflag == 0) + return; + +--- 263,271 ----- + short s; + { + struct outrelo outrelo; ++ #ifdef DUK ++ int iscomm; ++ #endif DUK + + if (rflag == 0) + return; +*************** +*** 272,277 + * b=a + * a: .data2 0 + */ + s &= ~S_COM; + if ((n & RELPC) == 0 && s == S_ABS) + return; + +--- 283,291 ----- + * b=a + * a: .data2 0 + */ ++ #ifdef DUK ++ iscomm = s & S_COM; ++ #endif DUK + s &= ~S_COM; + if ((n & RELPC) == 0 && s == S_ABS) + return; +*************** +*** 285,290 + outrelo.or_type = (char)n; + outrelo.or_sect = (char)DOTTYP; + #ifndef ASLD + if (s == S_UND) { + assert(relonami != 0); + outrelo.or_nami = relonami-1; + +--- 299,307 ----- + outrelo.or_type = (char)n; + outrelo.or_sect = (char)DOTTYP; + #ifndef ASLD ++ #ifdef DUK ++ if (s == S_UND || iscomm) { ++ #else DUK + if (s == S_UND) { + #endif DUK + assert(relonami != 0); +*************** +*** 286,291 + outrelo.or_sect = (char)DOTTYP; + #ifndef ASLD + if (s == S_UND) { + assert(relonami != 0); + outrelo.or_nami = relonami-1; + relonami = 0; + +--- 303,309 ----- + if (s == S_UND || iscomm) { + #else DUK + if (s == S_UND) { ++ #endif DUK + assert(relonami != 0); + outrelo.or_nami = relonami-1; + relonami = 0; +*** comm7.c.old Thu Dec 6 16:20:50 1984 +--- comm7.c Wed Oct 3 16:35:31 1984 +*************** +*** 19,24 + return(ip->i_valu); + return(ip->i_valu + sect[typ].s_base); + #else + if ((ip->i_type & S_TYP) == S_UND) { + if (pass == PASS_3) { + if (relonami != 0) + +--- 19,27 ----- + return(ip->i_valu); + return(ip->i_valu + sect[typ].s_base); + #else ++ #ifdef DUK ++ if ((ip->i_type & S_TYP) == S_UND || (ip->i_type & S_COM)) { ++ #else DUK + if ((ip->i_type & S_TYP) == S_UND) { + #endif DUK + if (pass == PASS_3) { +*************** +*** 20,25 + return(ip->i_valu + sect[typ].s_base); + #else + if ((ip->i_type & S_TYP) == S_UND) { + if (pass == PASS_3) { + if (relonami != 0) + serror("relocation error"); + +--- 23,29 ----- + if ((ip->i_type & S_TYP) == S_UND || (ip->i_type & S_COM)) { + #else DUK + if ((ip->i_type & S_TYP) == S_UND) { ++ #endif DUK + if (pass == PASS_3) { + if (relonami != 0) + serror("relocation error"); +*** mach0.c.old Thu Dec 6 16:21:11 1984 +--- mach0.c Fri Sep 14 14:15:54 1984 +*************** +*** 1,3 + /* @(#)mach0.c 1.5 */ + /* + * Motorola 68000/68010 options + +--- 1,4 ----- ++ #define DUK + /* @(#)mach0.c 1.5 */ + /* + * Motorola 68000/68010 options +*** mach4.c.old Thu Dec 6 16:21:30 1984 +--- mach4.c Thu Dec 6 16:05:00 1984 +*************** +*** 21,26 + fit(fitw($4.val)); + emit2($1 | $2); + #ifdef RELOCATION + newrelo($4.typ, RELPC|RELO2); + #endif + emit2(loww($4.val)); + +--- 21,29 ----- + fit(fitw($4.val)); + emit2($1 | $2); + #ifdef RELOCATION ++ #ifdef DUK ++ newrelo($4.typ, RELPC|RELO2|RELBR|RELWR); ++ #else DUK + newrelo($4.typ, RELPC|RELO2); + #endif DUK + #endif +*************** +*** 22,27 + emit2($1 | $2); + #ifdef RELOCATION + newrelo($4.typ, RELPC|RELO2); + #endif + emit2(loww($4.val)); + } + +--- 25,31 ----- + newrelo($4.typ, RELPC|RELO2|RELBR|RELWR); + #else DUK + newrelo($4.typ, RELPC|RELO2); ++ #endif DUK + #endif + emit2(loww($4.val)); + } +*** mach5.c.old Thu Dec 6 16:21:54 1984 +--- mach5.c Thu Dec 6 16:07:05 1984 +*************** +*** 37,42 + #ifdef RELOCATION + RELOMOVE(relonami, rel_1); + if (flag & ~0xFF) + newrelo(exp_1.typ, flag>>8); + #endif + if (flag & PUTL) + +--- 37,45 ----- + #ifdef RELOCATION + RELOMOVE(relonami, rel_1); + if (flag & ~0xFF) ++ #ifdef DUK ++ newrelo(exp_1.typ, (flag>>8) | RELBR | RELWR); ++ #else DUK + newrelo(exp_1.typ, flag>>8); + #endif DUK + #endif +*************** +*** 38,43 + RELOMOVE(relonami, rel_1); + if (flag & ~0xFF) + newrelo(exp_1.typ, flag>>8); + #endif + if (flag & PUTL) + emit4(exp_1.val); + +--- 41,47 ----- + newrelo(exp_1.typ, (flag>>8) | RELBR | RELWR); + #else DUK + newrelo(exp_1.typ, flag>>8); ++ #endif DUK + #endif + if (flag & PUTL) + emit4(exp_1.val); +*************** +*** 357,362 + fit(fitw(exp.val)); + emit2(opc); + #ifdef RELOCATION + newrelo(exp.typ, RELPC|RELO2); + #endif + emit2(loww(exp.val)); + +--- 361,369 ----- + fit(fitw(exp.val)); + emit2(opc); + #ifdef RELOCATION ++ #ifdef DUK ++ newrelo(exp.typ, RELPC|RELO2|RELBR|RELWR); ++ #else DUK + newrelo(exp.typ, RELPC|RELO2); + #endif DUK + #endif +*************** +*** 358,363 + emit2(opc); + #ifdef RELOCATION + newrelo(exp.typ, RELPC|RELO2); + #endif + emit2(loww(exp.val)); + } + +--- 365,371 ----- + newrelo(exp.typ, RELPC|RELO2|RELBR|RELWR); + #else DUK + newrelo(exp.typ, RELPC|RELO2); ++ #endif DUK + #endif + emit2(loww(exp.val)); + } diff --git a/util/led/WRONG b/util/led/WRONG new file mode 100644 index 00000000..1c3a17b4 --- /dev/null +++ b/util/led/WRONG @@ -0,0 +1,72 @@ +This file contains a summary of the bugs/features/inconsistencies +Robbert and Ed found while making the linker usable for the 68000 and amoeba. + +There is something wrong with the way the combination of +assembler and linker handle bss. +In the original (Duk's) the assembler translated .space and, worse, .align +to a sequence of zero's. If this sequence was at the end of a segment +within a module the assembler didn't put zero in the segment but sets +os_flen to the amount of space initialized before the zero space +and os_size to the segements size. (os_size - os_flen) is then the +size of the space filled by zeroes. +For the sake of clarity, let us call 0...os_flen-1 initialized space +and os_flen..os_size-1 uninitialized space. +Now the linker, it does a nasty trick. It gathers the uninitialized space +of all modules within a segment and puts it consequtively at the end +of the segment. I think that I understand the reason: This way you can keep +your resultant a.out smaller and you don't need a special bss segment +(a la unix). But it is incorrect, the net effect is that the .align's +at the end of segments within a module do have the desired effect, +the space thus allocated is removed to 'higher spheres' thereby +leaving the first items of that segment in the inmediatly following +modules at unaligned boundaries. +What should be done is that the linker leaves the initialized and +the unitialized code alone and regards the whole a a chunk that can be +relocated. Only producing a difference of os_size and os_flen for +the zeroes at the very end of the segment. Thereby collapsing all +.space (and .align) commands into zero space only if they +are in consequtive modules at the end of the segment, with modules +NOT containing any initialized data. +I already, ad-hoc, changed the code of the assembler to producing 'hard' +zeroes when aligning. The trick could also be done for .space +but is a bit harder here. +The reason: .space is also used to allocate space in the BSS segment +if that produced zeroes in the a.out file (0..bss_size) we would +have a.out files that are far too large. +This feature of the linker also caused weird effects for names that +are defined as the very last in a section within a module, without +any data (initialized or uninitialezed) after it. +The names a regarded as pointing into the uninitialized space and +thus relocated to the end of the section. +The sequence + .sect .data +begdata: + .sect .... +in an head_em.s resulted in the relocation of begdata to the END +of the .data segment. + +Another problem form the commons: +1 - Local commons are not handled by led and not produced by as. + using .comm for unitialized data is not correct because (from C) + two uninitialized static declarations for the same name in + different modules will be handled as external commons and thus + be overlayed. +2 - The commons are allocated at the very end of the first pass, after the + initialezed data has been allocated in the segments. The order on which + the commons are allocated seems to be random. That way it is impossible + to produce a label that is guaranteed to point to the last byte (+1) + of a segment containing commons. + The currently used trick is to declare an extra segment after the + segment containing the commons. The first bytre in this segment + inmediatly follows the commons and can be used as _end or endbss. + +The archiver (aal) with the automatic ranlib is buggy. +The only thing that seems to work at the moment is creation of a fresh +archive. +replacing/adding/deleting modules is likely to produce libraries +with incorrect ranlib entries. +The major troublemaker seems to be the extra padding byte at the end +of odd sized modules. + +Led should return a non-zero value when it has found Undefined symbols +or has another reason for not being able to produce a correct output file. diff --git a/util/led/makedepend b/util/led/makedepend new file mode 100755 index 00000000..3726c27b --- /dev/null +++ b/util/led/makedepend @@ -0,0 +1,23 @@ +: 'Without arguments, this program clears the dependencies between' +: '.o files and included files in Makefile.' +: 'With arguments, it replaces the dependencies between the .o files' +: 'resulting from the argument files, and the included files in Makefile.' +: 'Makefile must contain a line with on it the pattern AUTOAUTOAUTO.' +: 'WARNING: a temporary file is created in the current directory.' +: 'It is however rather unlikely that this file already exists' +grep -s AUTOAUTOAUTO Makefile || { + echo "Makefile has wrong format." 1>&2 + exit 1 +} +for file do + ofile=`echo $file | sed 's/.$/o/'` + grep '^# *include.*"' $file | sed "s/.*\"\(.*\)\".*/$ofile: \1/" +done | sort -u > @@**##$$ +echo "Non-empty line." >> Makefile +ed - Makefile <<'!' +/AUTOAUTOAUTO/+,$d +w +q +! +cat @@**##$$ >> Makefile +rm -f @@**##$$ From bf133215a60186c26174d6f52450e5b0f893d090 Mon Sep 17 00:00:00 2001 From: em Date: Thu, 23 May 1985 13:56:24 +0000 Subject: [PATCH 0019/1625] *** empty log message *** --- mach/ns/libcc/Makefile | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 mach/ns/libcc/Makefile diff --git a/mach/ns/libcc/Makefile b/mach/ns/libcc/Makefile new file mode 100644 index 00000000..a5cbcec5 --- /dev/null +++ b/mach/ns/libcc/Makefile @@ -0,0 +1,49 @@ +MAKEFILE=../../proto/libg/Makefile +MACHDEF="MACH=ns" "SUF=o" +STDIO="PREF=cc" "SUB=.1s" "SRC=lang/cem/libcc/stdio" +GEN="PREF=cc" "SUB=.2g" "SRC=lang/cem/libcc/gen" +MON="PREF=mon" "SRC=lang/cem/libcc/mon" +LIBM="PREF=m" "SRC=lang/cem/libcc/libm" +LIBLN="PREF=ln" "SRC=lang/cem/libcc/libln" + +install: cpstdio cpgen cpmon + +cpstdio: + make -f $(MAKEFILE) $(STDIO) $(MACHDEF) tailcp +cpgen: + make -f $(MAKEFILE) $(GEN) $(MACHDEF) cp +cpmon: + make -f $(MAKEFILE) $(MON) $(MACHDEF) tailcp +cplibm: + make -f $(MAKEFILE) $(LIBM) $(MACHDEF) tailcp +cplibln: + make -f $(MAKEFILE) $(LIBLN) $(MACHDEF) tailcp + +cmp: cmpstdio cmpgen cmpmon cmplib cmplibln + +cmpstdio: + make -f $(MAKEFILE) $(STDIO) $(MACHDEF) tail + -../../compare tail_cc.1s +cmpgen: + make -f $(MAKEFILE) $(GEN) $(MACHDEF) head + -../../compare head_cc + make -f $(MAKEFILE) $(GEN) $(MACHDEF) tail + -../../compare tail_cc.2g +cmpmon: + make -f $(MAKEFILE) $(MON) $(MACHDEF) tail + -../../compare tail_mon +cmplibm: + make -f $(MAKEFILE) $(LIBM) $(MACHDEF) tail + -../../compare tail_m +cmplibln: + make -f $(MAKEFILE) $(LIBLN) $(MACHDEF) tail + -../../compare tail_ln + +clean: + -rm -f *.old *.[ce$(SUF)] tail* head* + +opr: + make pr | opr + +pr: + @pr Makefile From f3e4341a27776741a017ed44c53c930a02ce2039 Mon Sep 17 00:00:00 2001 From: em Date: Tue, 28 May 1985 15:57:52 +0000 Subject: [PATCH 0020/1625] Added one remark intended for bug circumvention. --- doc/ncg.doc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/ncg.doc b/doc/ncg.doc index 4abfdbad..e43fc781 100644 --- a/doc/ncg.doc +++ b/doc/ncg.doc @@ -425,6 +425,10 @@ Registers are allocated by asking for a property, so if for some reason in later parts of the table one particular register must be allocated it has to have a unique property. +.PP +There is a bug in the codegenerator that can be circumvented by +providing a dummy property at the start of the property list. +The example has not been updated to show this. .NH 2 Register definition .PP From 339358a174cb4011a04968415e7446e76d291972 Mon Sep 17 00:00:00 2001 From: em Date: Tue, 4 Jun 1985 09:48:00 +0000 Subject: [PATCH 0021/1625] Adapted to using the new linker. --- lib/m68k2/descr | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/m68k2/descr b/lib/m68k2/descr index d173268c..ba066443 100644 --- a/lib/m68k2/descr +++ b/lib/m68k2/descr @@ -11,6 +11,8 @@ var LIB=lib/{M}/tail_ var RT=lib/{M}/head_ var CPP_F=-Dunix var INCLUDES=-I{EM}/include -I/usr/include +# 407 align is the default +var ALIGN=-a0:2 -a1:2 -a2:2 -a3:2 name be from .m.g to .s @@ -19,18 +21,27 @@ name be stdout need .e end -name asld - from .s.a - to .out +name as + from .s + to .o program {EM}/lib/{M}/as + args - -o > < + prep cond +end +name led + from .o.a + to .out + program {EM}/lib/em_led mapflag -l* LNAME={EM}/{LIB}* - args (.e:{HEAD}={EM}/{RT}em) \ + mapflag -i ALIGN=-a0:2 -a1:2 -a2:0x8000 -a3:2 + mapflag -n ALIGN=-a0:2 -a1:2 -a2:0x8000 -a3:2 + mapflag -nr ALIGN=-a0:2 -a1:0x8000 -a2:2 -a3:2 + args (.e:{HEAD}=-b0:0x20000 {ALIGN} {EM}/{RT}em) \ ({RTS}:.b.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \ (.p:{TAIL}={EM}/{LIB}pc) \ (.b:{TAIL}={EM}/{LIB}bc) \ (.b.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \ - (.e:{TAIL}={EM}/{LIB}em.rt {EM}/{LIB}mon {EM}/lib/{M}/end_em.s) - prep cond + (.e:{TAIL}={EM}/{LIB}em.rt {EM}/{LIB}mon {EM}/lib/{M}/end_em) linker end name cv From 43b079111c532834ff26c56a7f70dce4ff156174 Mon Sep 17 00:00:00 2001 From: keie Date: Tue, 4 Jun 1985 10:21:15 +0000 Subject: [PATCH 0022/1625] 1 - Changed %D into %ld. 2 - Adapted to the new linker. --- mach/m68k2/cg/mach.c | 18 +++++++++--------- mach/m68k2/cg/mach.h | 14 +++++++------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/mach/m68k2/cg/mach.c b/mach/m68k2/cg/mach.c index 65fb301e..3c5848c1 100644 --- a/mach/m68k2/cg/mach.c +++ b/mach/m68k2/cg/mach.c @@ -23,7 +23,7 @@ static char rcsid[] = "$Header$"; * machine dependent back end routines for the Motorola 68000 */ -#define IEEEFLOAT +/* #define IEEEFLOAT */ #ifdef IEEEFLOAT #include "FP.h" @@ -58,7 +58,7 @@ con_mult(sz) word sz; { if (sz != 4) fatal("bad icon/ucon size"); - fprintf(codefile,".long %s\n",str); + fprintf(codefile,".data4 %s\n",str); } #ifdef IEEEFLOAT @@ -86,7 +86,7 @@ con_float() sz = argval; if (sz!= 4 && sz!= 8) { - sprintf(mesg,"con_float(): bad fcon size %d %D\nstr: %s\n\0", + sprintf(mesg,"con_float(): bad fcon size %d %ld\nstr: %s\n\0", sz,sz,str); fatal(mesg); } @@ -104,7 +104,7 @@ con_float() #endif IEEEFLOAT while ( sz ) { - fprintf(codefile,"\t.word 0x%x,0x%x !float test %s\n", + fprintf(codefile,"\t.data2 0x%x,0x%x !float test %s\n", (int)(*l)&0xFFFF,(int)(*l>>16)&0xFFFF,str); sz -=4 ; l++; @@ -235,7 +235,7 @@ regreturn() prolog(nlocals) full nlocals; { - fprintf(codefile,"tst.b -%D(sp)\nlink\ta6,#-%D\n",nlocals+40,nlocals); + fprintf(codefile,"tst.b -%ld(sp)\nlink\ta6,#-%ld\n",nlocals+40,nlocals); } @@ -264,8 +264,8 @@ mes(type) word type ; { char *segname[] = { - ".text", /* SEGTXT */ - ".data", /* SEGCON */ - ".data", /* SEGROM */ - ".bss" /* SEGBSS */ + ".sect .text", /* SEGTXT */ + ".sect .data", /* SEGCON */ + ".sect .rom", /* SEGROM */ + ".sect .bss" /* SEGBSS */ }; diff --git a/mach/m68k2/cg/mach.h b/mach/m68k2/cg/mach.h index 62a2e1fd..92a56218 100644 --- a/mach/m68k2/cg/mach.h +++ b/mach/m68k2/cg/mach.h @@ -4,11 +4,11 @@ #define newilb(x) fprintf(codefile,"%s:\n",x) #define newdlb(x) fprintf(codefile,"%s:\n",x) #define dlbdlb(x,y) fprintf(codefile,"%s = %s\n",x,y) -#define newlbss(l,x) fprintf(codefile,"%s:.space\t%D\n",l,x); +#define newlbss(l,x) fprintf(codefile,"%s:.space\t%ld\n",l,x); #define pop_fmt "(sp)+" -#define cst_fmt "%D" -#define off_fmt "%D" +#define cst_fmt "%ld" +#define off_fmt "%ld" #define ilb_fmt "I%03x%x" #define dlb_fmt "_%d" #define hol_fmt "hol%d" @@ -17,11 +17,11 @@ #define arg_off "8+%d(a6)" #define hol_off "%d+hol%d" -#define con_cst(x) fprintf(codefile,".short\t%d\n",x) -#define con_ilb(x) fprintf(codefile,".long\t%s\n",x) -#define con_dlb(x) fprintf(codefile,".long\t%s\n",x) +#define con_cst(x) fprintf(codefile,".data2\t%d\n",x) +#define con_ilb(x) fprintf(codefile,".data4\t%s\n",x) +#define con_dlb(x) fprintf(codefile,".data4\t%s\n",x) -#define modhead "" +#define modhead ".sect .text;.sect .rom;.sect .data;.sect .bss\n" #define id_first '_' #define BSS_INIT 0 From cd8fc63f5806643e300156e328dc2e4a61a1bf71 Mon Sep 17 00:00:00 2001 From: keie Date: Tue, 4 Jun 1985 10:25:30 +0000 Subject: [PATCH 0023/1625] Adapted tu use new assembler & linker. --- mach/m68k2/libcc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/m68k2/libcc/Makefile b/mach/m68k2/libcc/Makefile index 8f20caf8..b260f410 100644 --- a/mach/m68k2/libcc/Makefile +++ b/mach/m68k2/libcc/Makefile @@ -1,5 +1,5 @@ MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=m68k2" "SUF=s" +MACHDEF="MACH=m68k2 -DNOFLOAT" "SUF=o" "ASAR=aal" STDIO="PREF=cc" "SUB=.1s" "SRC=lang/cem/libcc/stdio" GEN="PREF=cc" "SUB=.2g" "SRC=lang/cem/libcc/gen" MON="PREF=mon" "SRC=lang/cem/libcc/mon" From f42366dd914e073b5636b912a1b7b85e77ffd562 Mon Sep 17 00:00:00 2001 From: keie Date: Tue, 4 Jun 1985 10:26:06 +0000 Subject: [PATCH 0024/1625] A version that tells march to not try to include objects of modules that failed to translate in the library. --- mach/m68k2/libcc/compmodule | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mach/m68k2/libcc/compmodule b/mach/m68k2/libcc/compmodule index 28461326..6327cb99 100755 --- a/mach/m68k2/libcc/compmodule +++ b/mach/m68k2/libcc/compmodule @@ -1,2 +1,6 @@ -${MACH?} -I../../../h ${MACHFL?} $1 1>&2 -echo `basename $1 $2`.s +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then + echo `basename $1 $2`.o +else + exit 1 +fi From a106011442927e9f43dbaddd788348daf9bb6ebb Mon Sep 17 00:00:00 2001 From: keie Date: Tue, 4 Jun 1985 10:29:56 +0000 Subject: [PATCH 0025/1625] Adapted to use of the new assembler and linker. --- mach/m68k2/libpc/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mach/m68k2/libpc/Makefile b/mach/m68k2/libpc/Makefile index 37a8e880..b1525ce9 100644 --- a/mach/m68k2/libpc/Makefile +++ b/mach/m68k2/libpc/Makefile @@ -1,5 +1,5 @@ MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=m68k2" "SUF=s" +MACHDEF="MACH=m68k2" "SUF=o" "ASAR=aal" PCDEF="PREF=pc" "SUB=" "SRC=lang/pc/libpc" install: @@ -11,7 +11,7 @@ cmp: -../../compare tail_pc clean: - -rm -f *.old *.[ce$(SUF)] tail* head* + -rm -f *.old *.[ceo] tail* head* opr: make pr | opr From 398bce6ecb881b1acfc0a3785b059dd9a88b4e8a Mon Sep 17 00:00:00 2001 From: keie Date: Tue, 4 Jun 1985 10:30:18 +0000 Subject: [PATCH 0026/1625] More adapted to use by march. --- mach/m68k2/libpc/compmodule | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mach/m68k2/libpc/compmodule b/mach/m68k2/libpc/compmodule index 28461326..6327cb99 100755 --- a/mach/m68k2/libpc/compmodule +++ b/mach/m68k2/libpc/compmodule @@ -1,2 +1,6 @@ -${MACH?} -I../../../h ${MACHFL?} $1 1>&2 -echo `basename $1 $2`.s +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then + echo `basename $1 $2`.o +else + exit 1 +fi From cc7a30274685c6f6816c7cc80911b4c302cef789 Mon Sep 17 00:00:00 2001 From: keie Date: Tue, 4 Jun 1985 10:32:07 +0000 Subject: [PATCH 0027/1625] Adapted to use of new assmbler and linker. --- mach/m68k2/libbc/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mach/m68k2/libbc/Makefile b/mach/m68k2/libbc/Makefile index f3e9eef2..9f9c5c02 100644 --- a/mach/m68k2/libbc/Makefile +++ b/mach/m68k2/libbc/Makefile @@ -1,5 +1,5 @@ MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=m68k2" "SUF=s" +MACHDEF="MACH=m68k2" "SUF=o" "ASAR=aal" BCDEF="PREF=bc" "SUB=" "SRC=lang/basic/lib" install: @@ -11,7 +11,7 @@ cmp: -../../compare tail_bc clean: - -rm -f *.old *.[ce$(SUF)] tail* head* + -rm -f *.old *.[ceo] tail* head* opr: make pr | opr From 10d7e482964fd9fa93d96d0108c784b99587d06d Mon Sep 17 00:00:00 2001 From: keie Date: Tue, 4 Jun 1985 10:32:27 +0000 Subject: [PATCH 0028/1625] Now prevents inclusion of failed compilations into libraries. --- mach/m68k2/libbc/compmodule | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mach/m68k2/libbc/compmodule b/mach/m68k2/libbc/compmodule index 28461326..6327cb99 100755 --- a/mach/m68k2/libbc/compmodule +++ b/mach/m68k2/libbc/compmodule @@ -1,2 +1,6 @@ -${MACH?} -I../../../h ${MACHFL?} $1 1>&2 -echo `basename $1 $2`.s +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then + echo `basename $1 $2`.o +else + exit 1 +fi From eae06603f38ed3ac6ab2707d5d628b087175bb44 Mon Sep 17 00:00:00 2001 From: keie Date: Tue, 4 Jun 1985 10:39:45 +0000 Subject: [PATCH 0029/1625] Added a module for fake floating point. --- mach/m68k2/libem/LIST | 1 + 1 file changed, 1 insertion(+) diff --git a/mach/m68k2/libem/LIST b/mach/m68k2/libem/LIST index 47778703..666363bf 100644 --- a/mach/m68k2/libem/LIST +++ b/mach/m68k2/libem/LIST @@ -25,6 +25,7 @@ shp.s sig.s cms.s gto.s +ffp.s fat.s trp.s dia.s From 409bbbe31bd36cb8ef253f5361a09082da4b1667 Mon Sep 17 00:00:00 2001 From: keie Date: Tue, 4 Jun 1985 10:40:50 +0000 Subject: [PATCH 0030/1625] Adapted to using the new assembler & linker. --- mach/m68k2/libem/Makefile | 40 ++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/mach/m68k2/libem/Makefile b/mach/m68k2/libem/Makefile index 1af8fa3b..15239122 100644 --- a/mach/m68k2/libem/Makefile +++ b/mach/m68k2/libem/Makefile @@ -1,19 +1,33 @@ -install: - ../../install head_em.s head_em - ../../install libem_s.a tail_em.rt - ../../install end.s end_em.s +# $Header$ +MACH=m68k2 +install: all + ../../install head_em.o head_em + ../../install libem_o.a tail_em.rt + ../../install end.o end_em -cmp: - -../../compare head_em.s head_em - -../../compare libem_s.a tail_em.rt - -../../compare end.s end_em.s +cmp: all + -../../compare head_em.o head_em + -../../compare libem_o.a tail_em.rt + -../../compare end.o end_em -clean : +all: head_em.o libem_o.a end.o +end.o: end.s + $(MACH) -I../../../h -c end.s + +head_em.o: head_em.s + $(MACH) -I../../../h -c head_em.s + +libem_o.a: libem_s.a + ASAR=aal ; export ASAR ;\ + march . libem_o.a + +clean: + rm -f *.o opr : - make pr | opr + make pr | opr pr: - @pr `pwd`/head_em.s - @arch pv libem_s.a | pr -h `pwd`/libem_s.a - @pr `pwd`/end.s + @pr `pwd`/head_em.s + @arch pv libem_s.a | pr -h `pwd`/libem_s.a + @pr `pwd`/end.s From 4f58008ca3723b554867e8b7ef2f77c0daa83036 Mon Sep 17 00:00:00 2001 From: keie Date: Tue, 4 Jun 1985 10:44:10 +0000 Subject: [PATCH 0031/1625] Adapted to use of new linker & assembler. --- mach/m68k2/libem/compmodule | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/m68k2/libem/compmodule b/mach/m68k2/libem/compmodule index eb1ccef3..02105f21 100755 --- a/mach/m68k2/libem/compmodule +++ b/mach/m68k2/libem/compmodule @@ -1,4 +1,4 @@ if m68k2 -c $1 1>&2 -then echo `basename $1 $2`.s +then echo `basename $1 $2`.o else exit 1 fi From 7aea0d76f7d830fa71b0f54adf52e2702aa26e93 Mon Sep 17 00:00:00 2001 From: keie Date: Tue, 4 Jun 1985 10:57:42 +0000 Subject: [PATCH 0032/1625] Adapted to use of new assembler & linker --- mach/m68k2/libem/ara.s | 6 +++++- mach/m68k2/libem/cii.s | 6 +++++- mach/m68k2/libem/cmi.s | 6 +++++- mach/m68k2/libem/cmp.s | 6 +++++- mach/m68k2/libem/cms.s | 6 +++++- mach/m68k2/libem/cmu.s | 6 +++++- mach/m68k2/libem/csa.s | 6 +++++- mach/m68k2/libem/csb.s | 6 +++++- mach/m68k2/libem/cuu.s | 6 +++++- mach/m68k2/libem/cvf.s | 6 +++++- mach/m68k2/libem/dia.s | 10 ++++++--- mach/m68k2/libem/dvi.s | 6 +++++- mach/m68k2/libem/dvu.s | 6 +++++- mach/m68k2/libem/end.s | 16 ++++++++------ mach/m68k2/libem/exg.s | 6 +++++- mach/m68k2/libem/fat.s | 6 +++++- mach/m68k2/libem/ffp.s | 18 ++++++++++++++++ mach/m68k2/libem/gto.s | 12 +++++++---- mach/m68k2/libem/inn.s | 6 +++++- mach/m68k2/libem/los.s | 6 +++++- mach/m68k2/libem/lpb.s | 4 ++++ mach/m68k2/libem/lxa.s | 4 ++++ mach/m68k2/libem/lxl.s | 4 ++++ mach/m68k2/libem/mli.s | 6 +++++- mach/m68k2/libem/mlu.s | 6 +++++- mach/m68k2/libem/mon.s | 8 +++++-- mach/m68k2/libem/nop.s | 8 +++++-- mach/m68k2/libem/printf.s | 36 +++++++++++++++++-------------- mach/m68k2/libem/rck.s | 6 +++++- mach/m68k2/libem/ret.s | 6 +++++- mach/m68k2/libem/set.s | 6 +++++- mach/m68k2/libem/shp.s | 6 +++++- mach/m68k2/libem/sig.s | 6 +++++- mach/m68k2/libem/sts.s | 6 +++++- mach/m68k2/libem/trp.s | 10 ++++++--- mach/m68k2/libsys/head_em.s | 43 +++++++++++++++---------------------- 36 files changed, 230 insertions(+), 87 deletions(-) create mode 100644 mach/m68k2/libem/ffp.s diff --git a/mach/m68k2/libem/ara.s b/mach/m68k2/libem/ara.s index 3c3f179a..41869eb9 100644 --- a/mach/m68k2/libem/ara.s +++ b/mach/m68k2/libem/ara.s @@ -1,12 +1,16 @@ .define .sar .define .lar .define .aar +.sect .text +.sect .rom +.sect .data +.sect .bss !register usage: ! a0 : descriptor address ! d0 : index ! a1 : base address - .text + .sect .text .aar: move.l (sp)+,d2 ! return address move.l (sp)+,a0 diff --git a/mach/m68k2/libem/cii.s b/mach/m68k2/libem/cii.s index 045d7c72..3859107c 100644 --- a/mach/m68k2/libem/cii.s +++ b/mach/m68k2/libem/cii.s @@ -1,6 +1,10 @@ .define .cii +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text .cii: move.l (sp)+,a0 ! return address move (sp)+,d0 ! destination size diff --git a/mach/m68k2/libem/cmi.s b/mach/m68k2/libem/cmi.s index dd5e554c..6de1fee9 100644 --- a/mach/m68k2/libem/cmi.s +++ b/mach/m68k2/libem/cmi.s @@ -1,8 +1,12 @@ .define .cmi, .cmi_ +.sect .text +.sect .rom +.sect .data +.sect .bss ! NUM == 4 ! result in d1 - .text + .sect .text .cmi: .cmi_: move.l (sp)+,a0 diff --git a/mach/m68k2/libem/cmp.s b/mach/m68k2/libem/cmp.s index f2d962f9..15b95b1c 100644 --- a/mach/m68k2/libem/cmp.s +++ b/mach/m68k2/libem/cmp.s @@ -1,6 +1,10 @@ .define .cmp +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text .cmp: move.l (sp)+,a0 ! return address move.l #1,d1 diff --git a/mach/m68k2/libem/cms.s b/mach/m68k2/libem/cms.s index 1ff61a85..18101dc6 100644 --- a/mach/m68k2/libem/cms.s +++ b/mach/m68k2/libem/cms.s @@ -1,8 +1,12 @@ .define .cms +.sect .text +.sect .rom +.sect .data +.sect .bss ! d0 contains set size - .text + .sect .text .cms: move.l (sp)+,d2 ! return address move.l sp,a0 diff --git a/mach/m68k2/libem/cmu.s b/mach/m68k2/libem/cmu.s index 624e2cb6..87b8a184 100644 --- a/mach/m68k2/libem/cmu.s +++ b/mach/m68k2/libem/cmu.s @@ -1,7 +1,11 @@ .define .cmu +.sect .text +.sect .rom +.sect .data +.sect .bss ! d0 : # bytes of 1 block - .text + .sect .text .cmu: move.l (sp)+,d2 ! reta move.l sp,a0 ! top block diff --git a/mach/m68k2/libem/csa.s b/mach/m68k2/libem/csa.s index 9d3e036f..b16313db 100644 --- a/mach/m68k2/libem/csa.s +++ b/mach/m68k2/libem/csa.s @@ -1,6 +1,10 @@ .define .csa +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text .csa: move.l (sp)+,a0 ! case descriptor move (sp)+,d0 ! index diff --git a/mach/m68k2/libem/csb.s b/mach/m68k2/libem/csb.s index c36ecf00..5d25385a 100644 --- a/mach/m68k2/libem/csb.s +++ b/mach/m68k2/libem/csb.s @@ -1,6 +1,10 @@ .define .csb +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text .csb: move.l (sp)+,a0 ! case descriptor move (sp)+,d0 ! index diff --git a/mach/m68k2/libem/cuu.s b/mach/m68k2/libem/cuu.s index d1db8f5c..fb3989c5 100644 --- a/mach/m68k2/libem/cuu.s +++ b/mach/m68k2/libem/cuu.s @@ -1,8 +1,12 @@ .define .ciu .define .cui .define .cuu +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text .ciu: .cui: .cuu: diff --git a/mach/m68k2/libem/cvf.s b/mach/m68k2/libem/cvf.s index d0b081dd..dc2c5d2e 100644 --- a/mach/m68k2/libem/cvf.s +++ b/mach/m68k2/libem/cvf.s @@ -1,6 +1,10 @@ .define .cfi,.cif,.cfu,.cuf,.cff +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text ! this is a dummy float conversion routine .cfi: diff --git a/mach/m68k2/libem/dia.s b/mach/m68k2/libem/dia.s index 849f29e2..dd7e6a0c 100644 --- a/mach/m68k2/libem/dia.s +++ b/mach/m68k2/libem/dia.s @@ -1,12 +1,16 @@ .define .diagnos +.sect .text +.sect .rom +.sect .data +.sect .bss space = 040 del = 0177 - .text + .sect .text .diagnos: move.w hol0,-(sp) - move.l hol0+FILN_AD,d2 + move.l hol0+4,d2 beq 1f move.l d2,a0 move.l #40,d0 @@ -31,7 +35,7 @@ del = 0177 move.l #unknwn,d2 bra 2b - .data + .sect .data fmt: .asciz "%s, line %d: " unknwn: .asciz "unknown file" .align 2 diff --git a/mach/m68k2/libem/dvi.s b/mach/m68k2/libem/dvi.s index 508f6670..a17ad0f7 100644 --- a/mach/m68k2/libem/dvi.s +++ b/mach/m68k2/libem/dvi.s @@ -1,7 +1,11 @@ .define .dvi +.sect .text +.sect .rom +.sect .data +.sect .bss ! signed long divide - .text + .sect .text .dvi: move.l (sp)+,a0 ! return address move.l (sp)+,d0 diff --git a/mach/m68k2/libem/dvu.s b/mach/m68k2/libem/dvu.s index 2c3dea8d..7efdd441 100644 --- a/mach/m68k2/libem/dvu.s +++ b/mach/m68k2/libem/dvu.s @@ -1,4 +1,8 @@ .define .dvu +.sect .text +.sect .rom +.sect .data +.sect .bss ! unsigned long divide ! register usage: @@ -6,7 +10,7 @@ ! d1 dividend ! exit : d1 quotient ! d2 remainder - .text + .sect .text .dvu: move.l (sp)+,a1 ! return address move.l (sp)+,d0 diff --git a/mach/m68k2/libem/end.s b/mach/m68k2/libem/end.s index e05364bd..37e1cef2 100644 --- a/mach/m68k2/libem/end.s +++ b/mach/m68k2/libem/end.s @@ -1,14 +1,16 @@ .define endtext,enddata,endbss,_etext,_edata,_end +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .end ! only for declaration of _end and endbss. - .text - .align 2 + .sect .text endtext: _etext: - .data - .align 2 + .sect .data enddata: _edata: - .bss - .align 2 -endbss: + .sect .end _end: +endbss: diff --git a/mach/m68k2/libem/exg.s b/mach/m68k2/libem/exg.s index 042f80fb..8d9da163 100644 --- a/mach/m68k2/libem/exg.s +++ b/mach/m68k2/libem/exg.s @@ -1,7 +1,11 @@ .define .exg +.sect .text +.sect .rom +.sect .data +.sect .bss ! d0 : exchange size in bytes - .text + .sect .text .exg: move.l (sp)+,d2 ! return address move.l sp,a1 diff --git a/mach/m68k2/libem/fat.s b/mach/m68k2/libem/fat.s index fe2e0782..9c1e2b94 100644 --- a/mach/m68k2/libem/fat.s +++ b/mach/m68k2/libem/fat.s @@ -1,6 +1,10 @@ .define .fat +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text .fat: jsr .trp jmp EXIT diff --git a/mach/m68k2/libem/ffp.s b/mach/m68k2/libem/ffp.s new file mode 100644 index 00000000..d6bd1303 --- /dev/null +++ b/mach/m68k2/libem/ffp.s @@ -0,0 +1,18 @@ +.define .cmf8, .cif8, .dvf8, .adf8, .ngf8, .mlf8, .fif8, .fef8, .cff4 +.sect .text +.sect .rom +.sect .data +.sect .bss + +.sect .text +.cmf8: +.cif8: +.dvf8: +.adf8: +.ngf8: +.mlf8: +.fif8: +.fef8: +.cff4: + move.w #EILLINS,-(sp) + jmp .fat diff --git a/mach/m68k2/libem/gto.s b/mach/m68k2/libem/gto.s index c78ca22a..3a394f81 100644 --- a/mach/m68k2/libem/gto.s +++ b/mach/m68k2/libem/gto.s @@ -1,4 +1,8 @@ .define .gto +.sect .text +.sect .rom +.sect .data +.sect .bss .extern .gto .gto: @@ -69,7 +73,7 @@ etabd: etaba: move.l d2,a1 jmp (a1) ! return -.data -savd0: .long 0 -savd1: .long 0 -.text +.sect .data +savd0: .data4 0 +savd1: .data4 0 +.sect .text diff --git a/mach/m68k2/libem/inn.s b/mach/m68k2/libem/inn.s index 79d057c5..28c60db8 100644 --- a/mach/m68k2/libem/inn.s +++ b/mach/m68k2/libem/inn.s @@ -1,9 +1,13 @@ .define .inn +.sect .text +.sect .rom +.sect .data +.sect .bss ! d0 : set size in bytes ! d1 : bitnumber - .text + .sect .text .inn: move.l (sp)+,d2 ! return address move.w (sp)+,d1 diff --git a/mach/m68k2/libem/los.s b/mach/m68k2/libem/los.s index 5bc40cc8..84b68328 100644 --- a/mach/m68k2/libem/los.s +++ b/mach/m68k2/libem/los.s @@ -1,8 +1,12 @@ .define .los +.sect .text +.sect .rom +.sect .data +.sect .bss ! d0 : # bytes ! a0 : source address - .text + .sect .text .los: move.l (sp)+,a1 move.w (sp)+,d0 diff --git a/mach/m68k2/libem/lpb.s b/mach/m68k2/libem/lpb.s index 32567735..177fac45 100644 --- a/mach/m68k2/libem/lpb.s +++ b/mach/m68k2/libem/lpb.s @@ -1,4 +1,8 @@ .define .lpb +.sect .text +.sect .rom +.sect .data +.sect .bss .extern .lpb .lpb: ! convert local to argument base diff --git a/mach/m68k2/libem/lxa.s b/mach/m68k2/libem/lxa.s index ff0df426..9172a3d6 100644 --- a/mach/m68k2/libem/lxa.s +++ b/mach/m68k2/libem/lxa.s @@ -1,4 +1,8 @@ .define .lxa +.sect .text +.sect .rom +.sect .data +.sect .bss .extern .lxa .lxa: ! #levels (>= 0) on stack diff --git a/mach/m68k2/libem/lxl.s b/mach/m68k2/libem/lxl.s index 7ab2354e..e41f8318 100644 --- a/mach/m68k2/libem/lxl.s +++ b/mach/m68k2/libem/lxl.s @@ -1,4 +1,8 @@ .define .lxl +.sect .text +.sect .rom +.sect .data +.sect .bss .extern .lxl .lxl: ! #levels on stack (> 0) diff --git a/mach/m68k2/libem/mli.s b/mach/m68k2/libem/mli.s index fdf9242c..a0aa9a4f 100644 --- a/mach/m68k2/libem/mli.s +++ b/mach/m68k2/libem/mli.s @@ -1,7 +1,11 @@ .define .mli +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text .mli: move.l (sp)+,a0 move.l (sp)+,d1 diff --git a/mach/m68k2/libem/mlu.s b/mach/m68k2/libem/mlu.s index b8522da4..f3146c09 100644 --- a/mach/m68k2/libem/mlu.s +++ b/mach/m68k2/libem/mlu.s @@ -1,11 +1,15 @@ .define .mlu +.sect .text +.sect .rom +.sect .data +.sect .bss ! entry : d0 multiplicand ! d1 multiplier ! exit : d0 high order result ! d1 low order result - .text + .sect .text .mlu: move.l (sp)+,a1 move.l (sp)+,d1 diff --git a/mach/m68k2/libem/mon.s b/mach/m68k2/libem/mon.s index dabe65a9..dffaaede 100644 --- a/mach/m68k2/libem/mon.s +++ b/mach/m68k2/libem/mon.s @@ -1,5 +1,9 @@ .define .mon - .text +.sect .text +.sect .rom +.sect .data +.sect .bss + .sect .text .mon: move.l (sp)+,a0 pea fmt @@ -7,6 +11,6 @@ add #6,sp jmp EXIT - .data + .sect .data fmt: .asciz "system call %d not implemented" .align 2 diff --git a/mach/m68k2/libem/nop.s b/mach/m68k2/libem/nop.s index f7dd9db1..47e242c0 100644 --- a/mach/m68k2/libem/nop.s +++ b/mach/m68k2/libem/nop.s @@ -1,6 +1,10 @@ .define .nop +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text .nop: move.w hol0,-(sp) pea fmt @@ -8,6 +12,6 @@ add #6,sp rts - .data + .sect .data fmt: .asciz "test %d\n" .align 2 diff --git a/mach/m68k2/libem/printf.s b/mach/m68k2/libem/printf.s index cc79a696..044484df 100644 --- a/mach/m68k2/libem/printf.s +++ b/mach/m68k2/libem/printf.s @@ -1,6 +1,10 @@ .define _printn .define _printf -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _putchar: move.w #1,-(sp) pea 7(sp) @@ -10,14 +14,14 @@ _putchar: rts _printf: link a6,#-12 -.data +.sect .data _12: - .short 28786 - .short 26990 - .short 29798 - .short 11875 - .short 0 -.text + .data2 28786 + .data2 26990 + .data2 29798 + .data2 11875 + .data2 0 +.sect .text pea 8+4(a6) move.l (sp)+,-6(a6) I004: @@ -138,15 +142,15 @@ I002: rts _printn: link a6,#-2 -.data +.sect .data _15: - .short 12337 - .short 12851 - .short 13365 - .short 13879 - .short 14393 - .short 0 -.text + .data2 12337 + .data2 12851 + .data2 13365 + .data2 13879 + .data2 14393 + .data2 0 +.sect .text move.w 8+0(a6),-(sp) move.w #10,-(sp) move.w (sp)+,d0 diff --git a/mach/m68k2/libem/rck.s b/mach/m68k2/libem/rck.s index 52af333a..73bae4ae 100644 --- a/mach/m68k2/libem/rck.s +++ b/mach/m68k2/libem/rck.s @@ -1,6 +1,10 @@ .define .rck +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text .rck: move.l (sp)+,a1 move.l (sp)+,a0 ! descriptor address diff --git a/mach/m68k2/libem/ret.s b/mach/m68k2/libem/ret.s index a1b394de..c18c42ac 100644 --- a/mach/m68k2/libem/ret.s +++ b/mach/m68k2/libem/ret.s @@ -1,6 +1,10 @@ .define .ret +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text .ret: beq 3f cmp #2,d0 diff --git a/mach/m68k2/libem/set.s b/mach/m68k2/libem/set.s index 7d32c69d..42111bbe 100644 --- a/mach/m68k2/libem/set.s +++ b/mach/m68k2/libem/set.s @@ -1,8 +1,12 @@ .define .set +.sect .text +.sect .rom +.sect .data +.sect .bss ! d0 : setsize in bytes ! d1 : bitnumber - .text + .sect .text .set: move.l (sp)+,a0 move.w (sp)+,d1 diff --git a/mach/m68k2/libem/shp.s b/mach/m68k2/libem/shp.s index 88421e45..912af4fc 100644 --- a/mach/m68k2/libem/shp.s +++ b/mach/m68k2/libem/shp.s @@ -1,6 +1,10 @@ .define .strhp +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text .strhp: move.l (sp)+,a0 move.l (sp)+,d0 ! heap pointer diff --git a/mach/m68k2/libem/sig.s b/mach/m68k2/libem/sig.s index 3fa3e0bc..f93c9f8a 100644 --- a/mach/m68k2/libem/sig.s +++ b/mach/m68k2/libem/sig.s @@ -1,6 +1,10 @@ .define .sig +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text .sig: move.l (sp)+,a0 move.l (sp)+,a1 ! trap pc diff --git a/mach/m68k2/libem/sts.s b/mach/m68k2/libem/sts.s index 937c9304..3c1bf917 100644 --- a/mach/m68k2/libem/sts.s +++ b/mach/m68k2/libem/sts.s @@ -1,8 +1,12 @@ .define .sts +.sect .text +.sect .rom +.sect .data +.sect .bss ! d0 : # bytes ! a0 : destination address - .text + .sect .text .sts: move.l (sp)+,a1 move.w (sp)+,d0 diff --git a/mach/m68k2/libem/trp.s b/mach/m68k2/libem/trp.s index 36045db4..bd6f15d7 100644 --- a/mach/m68k2/libem/trp.s +++ b/mach/m68k2/libem/trp.s @@ -1,6 +1,10 @@ .define .trp +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text .trp: move.l (sp)+,a1 ! return address move.w (sp)+,d0 ! error number @@ -30,7 +34,7 @@ jsr .diagnos jmp EXIT - .data -.rettrp: .long 0 + .sect .data +.rettrp: .data4 0 fmt: .asciz "trap %d called\n" .align 2 diff --git a/mach/m68k2/libsys/head_em.s b/mach/m68k2/libsys/head_em.s index 7c7eb12b..a47d8eea 100644 --- a/mach/m68k2/libsys/head_em.s +++ b/mach/m68k2/libsys/head_em.s @@ -1,23 +1,18 @@ -.define CERASE,CKILL,CSTOP,CSTART .define .lino,.filn - -.define F_DUM,EXIT - +.define EXIT .define begtext,begdata,begbss .define EARRAY,ERANGE,ESET,EIDIVZ,EHEAP,EILLINS,ECASE,EBADGTO .define hol0,.reghp,.limhp,.trpim,.trppc -.define LINO_AD,FILN_AD +.sect .text +.sect .rom +.sect .data +.sect .bss + + ! EM runtime start-off for the Bleasdale 68000 system -CERASE = 010 -CKILL = 030 -CSTART = 021 -CSTOP = 023 -F_DUM = 0 - - LINO_AD = 0 FILN_AD = 4 @@ -30,8 +25,7 @@ EILLINS = 18 ECASE = 20 EBADGTO = 27 -.base 0x20000 - .text + .sect .text begtext: ! Bleasdale puts the argument and environment vectors ! themselves on top of the stack, instead of POINTERS @@ -57,30 +51,27 @@ begtext: ! envp pointer. add.l #2,sp !convert argc from 4-byte to 2-byte - pea endbss - jsr _brk - add.l #4,sp jsr _m_a_i_n add #010,sp EXIT: jsr __exit - .data + .sect .data begdata: hol0: .lino: - .short 0,0 ! lino + .data2 0,0 ! lino .filn: - .long 0 ! filn + .data4 0 ! filn .reghp: - .long endbss + .data4 endbss .limhp: - .long endbss + .data4 endbss .trppc: - .long 0 + .data4 0 .trpim: - .short 0 + .data2 0 - .bss -begbss: + .sect .bss +begbss: !initialization is not needed because ALL entries are in zero space! From 850c53b4a82aee1bad59f5580fd044a901923409 Mon Sep 17 00:00:00 2001 From: keie Date: Tue, 4 Jun 1985 11:18:09 +0000 Subject: [PATCH 0033/1625] Adapted to use of the new assembler & linker --- mach/m68k2/libsys/Makefile | 20 ++++++++++---- mach/m68k2/libsys/_exit.s | 6 ++++- mach/m68k2/libsys/access.s | 6 ++++- mach/m68k2/libsys/alarm.s | 6 ++++- mach/m68k2/libsys/brk.s | 12 ++++++--- mach/m68k2/libsys/call.s | 10 ++++--- mach/m68k2/libsys/chdir.s | 6 ++++- mach/m68k2/libsys/chmod.s | 6 ++++- mach/m68k2/libsys/chroot.s | 6 ++++- mach/m68k2/libsys/cleanup.s | 6 ++++- mach/m68k2/libsys/close.s | 6 ++++- mach/m68k2/libsys/creat.s | 6 ++++- mach/m68k2/libsys/execl.s | 4 +++ mach/m68k2/libsys/execve.s | 6 ++++- mach/m68k2/libsys/exit.s | 6 ++++- mach/m68k2/libsys/fork.s | 6 ++++- mach/m68k2/libsys/fstat.s | 4 +++ mach/m68k2/libsys/getegid.s | 6 ++++- mach/m68k2/libsys/getgid.s | 6 ++++- mach/m68k2/libsys/getpid.s | 6 ++++- mach/m68k2/libsys/getuid.s | 6 ++++- mach/m68k2/libsys/gtty.s | 6 ++++- mach/m68k2/libsys/ioctl.s | 6 ++++- mach/m68k2/libsys/kill.s | 6 ++++- mach/m68k2/libsys/link.s | 6 ++++- mach/m68k2/libsys/lseek.s | 6 ++++- mach/m68k2/libsys/mknod.s | 6 ++++- mach/m68k2/libsys/mount.s | 8 ++++-- mach/m68k2/libsys/nice.s | 6 ++++- mach/m68k2/libsys/open.s | 6 ++++- mach/m68k2/libsys/pause.s | 6 ++++- mach/m68k2/libsys/read.s | 6 ++++- mach/m68k2/libsys/setgid.s | 6 ++++- mach/m68k2/libsys/setuid.s | 6 ++++- mach/m68k2/libsys/signal.s | 53 +++++++------------------------------ mach/m68k2/libsys/stat.s | 6 ++++- mach/m68k2/libsys/stime.s | 6 ++++- mach/m68k2/libsys/stty.s | 6 ++++- mach/m68k2/libsys/sync.s | 6 ++++- mach/m68k2/libsys/time.s | 6 ++++- mach/m68k2/libsys/times.s | 6 ++++- mach/m68k2/libsys/umount.s | 6 ++++- mach/m68k2/libsys/unlink.s | 6 ++++- mach/m68k2/libsys/wait.s | 4 +++ mach/m68k2/libsys/write.s | 6 ++++- 45 files changed, 242 insertions(+), 95 deletions(-) diff --git a/mach/m68k2/libsys/Makefile b/mach/m68k2/libsys/Makefile index 5cc6f2ca..b3cdc928 100644 --- a/mach/m68k2/libsys/Makefile +++ b/mach/m68k2/libsys/Makefile @@ -1,11 +1,21 @@ # $Header$ -install: - ../../install tail_mon.a tail_mon +MACH=m68k2 +all: tail_mon +install: all + ../../install tail_mon -clean : +cmp: all + -../../compare tail_mon + +tail_mon: + ASAR=aal ; export ASAR ;\ + march . tail_mon + +clean: + rm -f *.o opr : - make pr | opr + make pr | opr pr: - @ar pv tail_mon.a + @ar pv tail_mon.a diff --git a/mach/m68k2/libsys/_exit.s b/mach/m68k2/libsys/_exit.s index 398c9390..253c6839 100644 --- a/mach/m68k2/libsys/_exit.s +++ b/mach/m68k2/libsys/_exit.s @@ -1,6 +1,10 @@ .define __exit +.sect .text +.sect .rom +.sect .data +.sect .bss .extern __exit -.text +.sect .text __exit: move.w #0x1,d0 move.w 4(sp),a0 trap #0 diff --git a/mach/m68k2/libsys/access.s b/mach/m68k2/libsys/access.s index fdceffbf..ae81a1e4 100644 --- a/mach/m68k2/libsys/access.s +++ b/mach/m68k2/libsys/access.s @@ -1,6 +1,10 @@ .define _access +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _access -.text +.sect .text _access: move.w #0x21,d0 move.l 4(sp),a0 move.w 8(sp),d1 diff --git a/mach/m68k2/libsys/alarm.s b/mach/m68k2/libsys/alarm.s index 98781a70..2d682210 100644 --- a/mach/m68k2/libsys/alarm.s +++ b/mach/m68k2/libsys/alarm.s @@ -1,6 +1,10 @@ .define _alarm +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _alarm -.text +.sect .text _alarm: clr.l d0 move.w 4(sp),d0 move.l d0,a0 diff --git a/mach/m68k2/libsys/brk.s b/mach/m68k2/libsys/brk.s index 0d33d073..9f211508 100644 --- a/mach/m68k2/libsys/brk.s +++ b/mach/m68k2/libsys/brk.s @@ -1,8 +1,12 @@ .define _brk .define _sbrk +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _brk .extern _sbrk -.text +.sect .text _sbrk: move.l nd,a0 add.w 4(sp),a0 move.w #0x11,d0 @@ -21,6 +25,6 @@ _brk: move.w #0x11,d0 move.l 4(sp),nd clr.l d0 rts -.data -nd: .long endbss -.text +.sect .data +nd: .data4 endbss +.sect .text diff --git a/mach/m68k2/libsys/call.s b/mach/m68k2/libsys/call.s index 846fb779..a76c593c 100644 --- a/mach/m68k2/libsys/call.s +++ b/mach/m68k2/libsys/call.s @@ -3,12 +3,16 @@ .define calle .define cerror .define _errno +.sect .text +.sect .rom +.sect .data +.sect .bss .extern call .extern callc .extern calle .extern cerror .extern _errno -.text +.sect .text call: trap #0 bcs cerror rts @@ -23,6 +27,6 @@ cerror: move.w d0,_errno move.l #-1,d0 rts -.bss +.sect .bss _errno: .space 4 -.text +.sect .text diff --git a/mach/m68k2/libsys/chdir.s b/mach/m68k2/libsys/chdir.s index d03224ae..3965b699 100644 --- a/mach/m68k2/libsys/chdir.s +++ b/mach/m68k2/libsys/chdir.s @@ -1,6 +1,10 @@ .define _chdir +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _chdir -.text +.sect .text _chdir: move.w #0xC,d0 move.l 4(sp),a0 jmp callc diff --git a/mach/m68k2/libsys/chmod.s b/mach/m68k2/libsys/chmod.s index 6c86e3a2..312c119d 100644 --- a/mach/m68k2/libsys/chmod.s +++ b/mach/m68k2/libsys/chmod.s @@ -1,6 +1,10 @@ .define _chmod +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _chmod -.text +.sect .text _chmod: move.w #0xF,d0 move.l 4(sp),a0 move.w 8(sp),d1 diff --git a/mach/m68k2/libsys/chroot.s b/mach/m68k2/libsys/chroot.s index ebf9f6a4..5e8f79bc 100644 --- a/mach/m68k2/libsys/chroot.s +++ b/mach/m68k2/libsys/chroot.s @@ -1,6 +1,10 @@ .define _chroot +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _chroot -.text +.sect .text _chroot: move.w #0x3D,d0 move.l 4(sp),a0 jmp callc diff --git a/mach/m68k2/libsys/cleanup.s b/mach/m68k2/libsys/cleanup.s index 7df1860b..e47393f0 100644 --- a/mach/m68k2/libsys/cleanup.s +++ b/mach/m68k2/libsys/cleanup.s @@ -1,6 +1,10 @@ .define __cleanup +.sect .text +.sect .rom +.sect .data +.sect .bss .extern __cleanup -.text +.sect .text __cleanup: tst.b -40(sp) link a6,#-0 diff --git a/mach/m68k2/libsys/close.s b/mach/m68k2/libsys/close.s index add7e701..0d0e04d9 100644 --- a/mach/m68k2/libsys/close.s +++ b/mach/m68k2/libsys/close.s @@ -1,6 +1,10 @@ .define _close +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _close -.text +.sect .text _close: move.w #0x6,d0 move.w 4(sp),a0 jmp callc diff --git a/mach/m68k2/libsys/creat.s b/mach/m68k2/libsys/creat.s index 73e7db84..a8e0e051 100644 --- a/mach/m68k2/libsys/creat.s +++ b/mach/m68k2/libsys/creat.s @@ -1,6 +1,10 @@ .define _creat +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _creat -.text +.sect .text _creat: move.w #0x8,d0 move.l 4(sp),a0 move.w 8(sp),d1 diff --git a/mach/m68k2/libsys/execl.s b/mach/m68k2/libsys/execl.s index 21e03dc9..0fbfd8ae 100644 --- a/mach/m68k2/libsys/execl.s +++ b/mach/m68k2/libsys/execl.s @@ -1,4 +1,8 @@ .define _execl +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _execl _execl: link a6,#0 tst.b -132(sp) diff --git a/mach/m68k2/libsys/execve.s b/mach/m68k2/libsys/execve.s index 2b2de5f8..e6d6a950 100644 --- a/mach/m68k2/libsys/execve.s +++ b/mach/m68k2/libsys/execve.s @@ -1,6 +1,10 @@ .define _execve +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _execve -.text +.sect .text _execve: move.w #0x3B,d0 move.l 4(sp),a0 move.l 8(sp),d1 diff --git a/mach/m68k2/libsys/exit.s b/mach/m68k2/libsys/exit.s index d766750e..79e4358c 100644 --- a/mach/m68k2/libsys/exit.s +++ b/mach/m68k2/libsys/exit.s @@ -1,6 +1,10 @@ .define _exit +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _exit -.text +.sect .text _exit: tst.b -40(sp) link a6,#-0 diff --git a/mach/m68k2/libsys/fork.s b/mach/m68k2/libsys/fork.s index 0401e631..bccd3dd5 100644 --- a/mach/m68k2/libsys/fork.s +++ b/mach/m68k2/libsys/fork.s @@ -1,6 +1,10 @@ .define _fork +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _fork -.text +.sect .text _fork: move.w #0x2,d0 trap #0 bra 1f diff --git a/mach/m68k2/libsys/fstat.s b/mach/m68k2/libsys/fstat.s index 1dd3d66c..bfda6d9b 100644 --- a/mach/m68k2/libsys/fstat.s +++ b/mach/m68k2/libsys/fstat.s @@ -1,4 +1,8 @@ .define _fstat +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _fstat _fstat: move.w #0x1C,d0 move.w 4(sp),a0 diff --git a/mach/m68k2/libsys/getegid.s b/mach/m68k2/libsys/getegid.s index b4da40c1..557c8fe2 100644 --- a/mach/m68k2/libsys/getegid.s +++ b/mach/m68k2/libsys/getegid.s @@ -1,6 +1,10 @@ .define _getegid +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _getegid -.text +.sect .text _getegid: move.w #0x2F,d0 trap #0 move.l d1,d0 diff --git a/mach/m68k2/libsys/getgid.s b/mach/m68k2/libsys/getgid.s index 3ef4def3..d24e82ef 100644 --- a/mach/m68k2/libsys/getgid.s +++ b/mach/m68k2/libsys/getgid.s @@ -1,6 +1,10 @@ .define _getgid +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _getgid -.text +.sect .text _getgid: move.w #0x2F,d0 trap #0 rts diff --git a/mach/m68k2/libsys/getpid.s b/mach/m68k2/libsys/getpid.s index 1bf2aba7..6d8274f3 100644 --- a/mach/m68k2/libsys/getpid.s +++ b/mach/m68k2/libsys/getpid.s @@ -1,6 +1,10 @@ .define _getpid +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _getpid -.text +.sect .text _getpid: move.w #0x14,d0 trap #0 rts diff --git a/mach/m68k2/libsys/getuid.s b/mach/m68k2/libsys/getuid.s index d0e15a1b..bbc7e3f3 100644 --- a/mach/m68k2/libsys/getuid.s +++ b/mach/m68k2/libsys/getuid.s @@ -1,6 +1,10 @@ .define _getuid +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _getuid -.text +.sect .text _getuid: move.w #0x18,d0 trap #0 rts diff --git a/mach/m68k2/libsys/gtty.s b/mach/m68k2/libsys/gtty.s index ee9f096c..2ed35917 100644 --- a/mach/m68k2/libsys/gtty.s +++ b/mach/m68k2/libsys/gtty.s @@ -1,6 +1,10 @@ .define _gtty +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _gtty -.text +.sect .text _gtty: tst.b -40(sp) link a6,#-0 diff --git a/mach/m68k2/libsys/ioctl.s b/mach/m68k2/libsys/ioctl.s index 75d16214..3887f124 100644 --- a/mach/m68k2/libsys/ioctl.s +++ b/mach/m68k2/libsys/ioctl.s @@ -1,6 +1,10 @@ .define _ioctl +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _ioctl -.text +.sect .text _ioctl: move.w #0x36,d0 move.w 4(sp),a0 move.w 6(sp),d1 diff --git a/mach/m68k2/libsys/kill.s b/mach/m68k2/libsys/kill.s index c5c4038c..7e2fdbb8 100644 --- a/mach/m68k2/libsys/kill.s +++ b/mach/m68k2/libsys/kill.s @@ -1,6 +1,10 @@ .define _kill +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _kill -.text +.sect .text _kill: move.w #0x25,d0 move.w 4(sp),a0 move.w 6(sp),d1 diff --git a/mach/m68k2/libsys/link.s b/mach/m68k2/libsys/link.s index 161ca6d1..990a2ed1 100644 --- a/mach/m68k2/libsys/link.s +++ b/mach/m68k2/libsys/link.s @@ -1,6 +1,10 @@ .define _link +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _link -.text +.sect .text _link: move.w #0x9,d0 move.l 4(sp),a0 move.w 8(sp),d1 diff --git a/mach/m68k2/libsys/lseek.s b/mach/m68k2/libsys/lseek.s index 96f670e7..b7d7eeb1 100644 --- a/mach/m68k2/libsys/lseek.s +++ b/mach/m68k2/libsys/lseek.s @@ -1,6 +1,10 @@ .define _lseek +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _lseek -.text +.sect .text _lseek: move.w #0x13,d0 move.w 4(sp),a0 move.l 6(sp),d1 diff --git a/mach/m68k2/libsys/mknod.s b/mach/m68k2/libsys/mknod.s index 21d86ad0..58ea7a74 100644 --- a/mach/m68k2/libsys/mknod.s +++ b/mach/m68k2/libsys/mknod.s @@ -1,6 +1,10 @@ .define _mknod +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _mknod -.text +.sect .text _mknod: move.w #0xE,d0 move.l 4(sp),a0 move.w 8(sp),d1 diff --git a/mach/m68k2/libsys/mount.s b/mach/m68k2/libsys/mount.s index b7d37737..2c757d81 100644 --- a/mach/m68k2/libsys/mount.s +++ b/mach/m68k2/libsys/mount.s @@ -1,7 +1,11 @@ - .define _mount +.sect .text +.sect .rom +.sect .data +.sect .bss + .extern _mount -.text +.sect .text _mount: move.w #0x15,d0 move.l 4(sp),a0 move.l 8(sp),d1 diff --git a/mach/m68k2/libsys/nice.s b/mach/m68k2/libsys/nice.s index 4929617b..563a5ab1 100644 --- a/mach/m68k2/libsys/nice.s +++ b/mach/m68k2/libsys/nice.s @@ -1,6 +1,10 @@ .define _nice +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _nice -.text +.sect .text _nice: move.w #0x22,d0 move.w 4(sp),a0 jmp callc diff --git a/mach/m68k2/libsys/open.s b/mach/m68k2/libsys/open.s index 04b3b505..3d377e4e 100644 --- a/mach/m68k2/libsys/open.s +++ b/mach/m68k2/libsys/open.s @@ -1,6 +1,10 @@ .define _open +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _open -.text +.sect .text _open: move.w #0x5,d0 move.l 4(sp),a0 move.w 8(sp),d1 diff --git a/mach/m68k2/libsys/pause.s b/mach/m68k2/libsys/pause.s index 53b99d73..d4d27a77 100644 --- a/mach/m68k2/libsys/pause.s +++ b/mach/m68k2/libsys/pause.s @@ -1,6 +1,10 @@ .define _pause +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _pause -.text +.sect .text _pause: move.w #0x1D,d0 trap #0 rts diff --git a/mach/m68k2/libsys/read.s b/mach/m68k2/libsys/read.s index a5e0449a..532a9df2 100644 --- a/mach/m68k2/libsys/read.s +++ b/mach/m68k2/libsys/read.s @@ -1,6 +1,10 @@ .define _read +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _read -.text +.sect .text _read: move.w #0x3,d0 move.w 4(sp),a0 move.l 6(sp),d1 diff --git a/mach/m68k2/libsys/setgid.s b/mach/m68k2/libsys/setgid.s index 5ad03004..1a53660a 100644 --- a/mach/m68k2/libsys/setgid.s +++ b/mach/m68k2/libsys/setgid.s @@ -1,6 +1,10 @@ .define _setgid +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _setgid -.text +.sect .text _setgid: move.w #0x2E,d0 move.w 4(sp),a0 jmp callc diff --git a/mach/m68k2/libsys/setuid.s b/mach/m68k2/libsys/setuid.s index 94cc45ef..689fb00c 100644 --- a/mach/m68k2/libsys/setuid.s +++ b/mach/m68k2/libsys/setuid.s @@ -1,6 +1,10 @@ .define _setuid +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _setuid -.text +.sect .text _setuid: move.w #0x17,d0 move.w 4(sp),a0 jmp callc diff --git a/mach/m68k2/libsys/signal.s b/mach/m68k2/libsys/signal.s index 90acbc54..01f5df5e 100644 --- a/mach/m68k2/libsys/signal.s +++ b/mach/m68k2/libsys/signal.s @@ -1,10 +1,13 @@ - .define _signal +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _signal NSIG=32 _signal: move.w 4(sp), d0 - ext.l d0 + ext.l d0 cmp.l #NSIG,d0 bcc 1f move.l 6(sp),d1 @@ -17,9 +20,7 @@ _signal: beq 2f btst #0,d1 bne 2f - move.l #jmptab,d1 - add.l d0,d1 - add.l d0,d1 + move.l #enter,d1 2: move.l d0,a0 move.w #0x30,d0 @@ -29,52 +30,16 @@ _signal: bne 4f move.l a1,d0 4: - clr.l d1 rts 1: move.l #22,d0 3: jmp cerror -jmptab: bsr enter - bsr enter - bsr enter - bsr enter - bsr enter - bsr enter - bsr enter - bsr enter - bsr enter - bsr enter - bsr enter - bsr enter - bsr enter - bsr enter - bsr enter - bsr enter - bsr enter - bsr enter - bsr enter - bsr enter - bsr enter - bsr enter - bsr enter - bsr enter - bsr enter - bsr enter - bsr enter - bsr enter - bsr enter - bsr enter - bsr enter - bsr enter enter: movem.l d0/d1/a0/a1,-(sp) - move.l 16(sp),d0 - sub.l #jmptab+2,d0 - asr.l #1,d0 - move.l d0,-(sp) - move.l d0,a0 + move.l 16(sp),a0 + move.l a0,-(sp) add.l a0,a0 add.l a0,a0 add.l #dvect,a0 @@ -84,5 +49,5 @@ enter: movem.l (sp)+,d0/d1/a0/a1 add.l #4,sp rtr -.bss +.sect .bss dvect: .space 4*NSIG diff --git a/mach/m68k2/libsys/stat.s b/mach/m68k2/libsys/stat.s index 304c38b1..b41a8a6c 100644 --- a/mach/m68k2/libsys/stat.s +++ b/mach/m68k2/libsys/stat.s @@ -1,6 +1,10 @@ .define _stat +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _stat -.text +.sect .text _stat: move.w #0x12,d0 move.l 4(sp),a0 move.w 8(sp),d1 diff --git a/mach/m68k2/libsys/stime.s b/mach/m68k2/libsys/stime.s index bac6386d..139e7c06 100644 --- a/mach/m68k2/libsys/stime.s +++ b/mach/m68k2/libsys/stime.s @@ -1,6 +1,10 @@ .define _stime +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _stime -.text +.sect .text _stime: move.w #0x19,d0 move.l 4(sp),a0 move.l (a0),a0 diff --git a/mach/m68k2/libsys/stty.s b/mach/m68k2/libsys/stty.s index 46a497cd..0fb9199e 100644 --- a/mach/m68k2/libsys/stty.s +++ b/mach/m68k2/libsys/stty.s @@ -1,6 +1,10 @@ .define _stty +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _stty -.text +.sect .text _stty: tst.b -40(sp) link a6,#-0 diff --git a/mach/m68k2/libsys/sync.s b/mach/m68k2/libsys/sync.s index 3c38a8ad..8941aa29 100644 --- a/mach/m68k2/libsys/sync.s +++ b/mach/m68k2/libsys/sync.s @@ -1,6 +1,10 @@ .define _sync +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _sync -.text +.sect .text _sync: move.w #0x24,d0 trap #0 rts diff --git a/mach/m68k2/libsys/time.s b/mach/m68k2/libsys/time.s index 87b9d8bd..dc7aecb7 100644 --- a/mach/m68k2/libsys/time.s +++ b/mach/m68k2/libsys/time.s @@ -1,6 +1,10 @@ .define _time +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _time -.text +.sect .text _time: move.w #0xD,d0 trap #0 tst.l 4(sp) diff --git a/mach/m68k2/libsys/times.s b/mach/m68k2/libsys/times.s index 6e74fe9a..4854e859 100644 --- a/mach/m68k2/libsys/times.s +++ b/mach/m68k2/libsys/times.s @@ -1,6 +1,10 @@ .define _times +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _times -.text +.sect .text _times: move.w #0x2B,d0 move.l 4(sp),a0 trap #0 diff --git a/mach/m68k2/libsys/umount.s b/mach/m68k2/libsys/umount.s index 59354ee9..d6143017 100644 --- a/mach/m68k2/libsys/umount.s +++ b/mach/m68k2/libsys/umount.s @@ -1,6 +1,10 @@ .define _umount +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _umount -.text +.sect .text _umount: move.w #0x16,d0 move.l 4(sp),a0 jmp callc diff --git a/mach/m68k2/libsys/unlink.s b/mach/m68k2/libsys/unlink.s index 99e856a5..f0b20054 100644 --- a/mach/m68k2/libsys/unlink.s +++ b/mach/m68k2/libsys/unlink.s @@ -1,6 +1,10 @@ .define _unlink +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _unlink -.text +.sect .text _unlink: move.w #0xA,d0 move.l 4(sp),a0 jmp callc diff --git a/mach/m68k2/libsys/wait.s b/mach/m68k2/libsys/wait.s index a0ea1a5e..c5a5de10 100644 --- a/mach/m68k2/libsys/wait.s +++ b/mach/m68k2/libsys/wait.s @@ -1,4 +1,8 @@ .define _wait +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _wait _wait: move.w #0x7,d0 move.l 4(sp),a0 diff --git a/mach/m68k2/libsys/write.s b/mach/m68k2/libsys/write.s index 192d7adb..fce2cdb2 100644 --- a/mach/m68k2/libsys/write.s +++ b/mach/m68k2/libsys/write.s @@ -1,6 +1,10 @@ .define _write +.sect .text +.sect .rom +.sect .data +.sect .bss .extern _write -.text +.sect .text _write: move.w #0x4,d0 move.w 4(sp),a0 move.l 6(sp),d1 From 8fb74f31991b041b0dea84fc61109de93775b93f Mon Sep 17 00:00:00 2001 From: keie Date: Tue, 4 Jun 1985 11:18:43 +0000 Subject: [PATCH 0034/1625] *** empty log message *** --- mach/m68k2/libsys/compmodule | 4 ++++ 1 file changed, 4 insertions(+) create mode 100755 mach/m68k2/libsys/compmodule diff --git a/mach/m68k2/libsys/compmodule b/mach/m68k2/libsys/compmodule new file mode 100755 index 00000000..2949d131 --- /dev/null +++ b/mach/m68k2/libsys/compmodule @@ -0,0 +1,4 @@ +if l68k2 -c $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 +fi From dc41f07f89da5238226cc98308522f183cdb2e17 Mon Sep 17 00:00:00 2001 From: keie Date: Tue, 4 Jun 1985 11:30:54 +0000 Subject: [PATCH 0035/1625] Adapated to use of new linker & assembler. --- mach/m68k2/libsys/acct.s | 7 ++++++- mach/m68k2/libsys/chown.s | 7 ++++++- mach/m68k2/libsys/dup.s | 7 ++++++- mach/m68k2/libsys/dup2.s | 7 ++++++- mach/m68k2/libsys/ftime.s | 7 ++++++- mach/m68k2/libsys/lock.s | 7 ++++++- mach/m68k2/libsys/pipe.s | 5 +++++ mach/m68k2/libsys/profil.s | 7 ++++++- mach/m68k2/libsys/umask.s | 7 ++++++- mach/m68k2/libsys/utime.s | 7 ++++++- 10 files changed, 59 insertions(+), 9 deletions(-) diff --git a/mach/m68k2/libsys/acct.s b/mach/m68k2/libsys/acct.s index b4ba8b61..9fb1131d 100644 --- a/mach/m68k2/libsys/acct.s +++ b/mach/m68k2/libsys/acct.s @@ -1,6 +1,11 @@ .define _acct +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _acct -.text +.sect .text _acct: move.w #0x33,d0 move.l 4(sp),a0 jmp callc diff --git a/mach/m68k2/libsys/chown.s b/mach/m68k2/libsys/chown.s index 3e33b170..e45f08cc 100644 --- a/mach/m68k2/libsys/chown.s +++ b/mach/m68k2/libsys/chown.s @@ -1,6 +1,11 @@ .define _chown +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _chown -.text +.sect .text _chown: move.w #0x10,d0 move.l 4(sp),a0 move.w 8(sp),d1 diff --git a/mach/m68k2/libsys/dup.s b/mach/m68k2/libsys/dup.s index 75be7dde..760c411f 100644 --- a/mach/m68k2/libsys/dup.s +++ b/mach/m68k2/libsys/dup.s @@ -1,6 +1,11 @@ .define _dup +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _dup -.text +.sect .text _dup: move.w #0x29,d0 move.w 4(sp),a0 jmp call diff --git a/mach/m68k2/libsys/dup2.s b/mach/m68k2/libsys/dup2.s index 0227703c..444a3829 100644 --- a/mach/m68k2/libsys/dup2.s +++ b/mach/m68k2/libsys/dup2.s @@ -1,6 +1,11 @@ .define _dup2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _dup2 -.text +.sect .text _dup2: move.w #0x29,d0 move.w 4(sp),a0 move.w 6(sp),d1 diff --git a/mach/m68k2/libsys/ftime.s b/mach/m68k2/libsys/ftime.s index 432ed3f0..d9c7a914 100644 --- a/mach/m68k2/libsys/ftime.s +++ b/mach/m68k2/libsys/ftime.s @@ -1,6 +1,11 @@ .define _ftime +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _ftime -.text +.sect .text _ftime: move.w #0x23,d0 move.l 4(sp),a0 jmp callc diff --git a/mach/m68k2/libsys/lock.s b/mach/m68k2/libsys/lock.s index 9ed99574..0a7a9340 100644 --- a/mach/m68k2/libsys/lock.s +++ b/mach/m68k2/libsys/lock.s @@ -1,6 +1,11 @@ .define _lock +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _lock -.text +.sect .text _lock: move.w #0x35,d0 move.w 4(sp),a0 jmp callc diff --git a/mach/m68k2/libsys/pipe.s b/mach/m68k2/libsys/pipe.s index 017adecf..4060386d 100644 --- a/mach/m68k2/libsys/pipe.s +++ b/mach/m68k2/libsys/pipe.s @@ -1,4 +1,9 @@ .define _pipe +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _pipe _pipe: move.w #0x2A,d0 diff --git a/mach/m68k2/libsys/profil.s b/mach/m68k2/libsys/profil.s index c38e4981..1ef072e9 100644 --- a/mach/m68k2/libsys/profil.s +++ b/mach/m68k2/libsys/profil.s @@ -1,6 +1,11 @@ .define _profil +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _profil -.text +.sect .text _profil: move.w #0x2C,d0 move.l 4(sp),a0 move.w 8(sp),d1 diff --git a/mach/m68k2/libsys/umask.s b/mach/m68k2/libsys/umask.s index 8eae00cd..066c7ffe 100644 --- a/mach/m68k2/libsys/umask.s +++ b/mach/m68k2/libsys/umask.s @@ -1,6 +1,11 @@ .define _umask +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _umask -.text +.sect .text _umask: move.w #0x3C,d0 move.w 4(sp),a0 jmp call diff --git a/mach/m68k2/libsys/utime.s b/mach/m68k2/libsys/utime.s index 0e0b6dd9..634d449c 100644 --- a/mach/m68k2/libsys/utime.s +++ b/mach/m68k2/libsys/utime.s @@ -1,6 +1,11 @@ .define _utime +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _utime -.text +.sect .text _utime: move.w #0x1E,d0 move.l 4(sp),a0 move.l 8(sp),d1 From 617010fa56adab0c84a30d527d091a16ac31f06b Mon Sep 17 00:00:00 2001 From: keie Date: Tue, 4 Jun 1985 11:43:01 +0000 Subject: [PATCH 0036/1625] Using new assembler & linker. --- mach/m68k2/Action | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mach/m68k2/Action b/mach/m68k2/Action index 258a3e23..ad0eb0da 100644 --- a/mach/m68k2/Action +++ b/mach/m68k2/Action @@ -1,5 +1,5 @@ name "Motorola 68000 assembler" -dir as +dir nas end name "Motorola 68000 2-4 backend" dir cg @@ -9,7 +9,7 @@ system m68* dir int end name "Motorola 68000 2-4 conversion program" -dir cv +dir ncv end name "Motorola 68000 2-4 C libraries" dir libcc From ee7dc029658778b4a3a48efc88de0b6d2862d266 Mon Sep 17 00:00:00 2001 From: keie Date: Mon, 10 Jun 1985 10:48:49 +0000 Subject: [PATCH 0037/1625] Changed to get led working under amoeba. Author: K.S. Mullender. --- util/led/debug.h | 2 +- util/led/error.c | 4 +++- util/led/extract.c | 6 ++++++ util/led/finish.c | 5 +++++ util/led/main.c | 26 ++++++++++++++++++++++---- util/led/memory.c | 16 +++++++++++++--- util/led/memory.h | 2 +- util/led/output.c | 2 ++ util/led/scan.c | 11 +++++++++++ util/led/write.c | 3 +++ 10 files changed, 67 insertions(+), 10 deletions(-) diff --git a/util/led/debug.h b/util/led/debug.h index 16fff039..25ca825a 100644 --- a/util/led/debug.h +++ b/util/led/debug.h @@ -2,7 +2,7 @@ #ifdef NDEBUG -#define debug(s, a1, a2, a3, a4) +#define debug(s, a1, a2, a3, a4) dummy() #else diff --git a/util/led/error.c b/util/led/error.c index 689dfd6e..f5f2517c 100644 --- a/util/led/error.c +++ b/util/led/error.c @@ -8,8 +8,8 @@ static char rcsid[] = "$Header$"; #include "const.h" static short nerrors = 0; +static diag(); -static stop() { extern char *outputname; @@ -61,6 +61,8 @@ diag(tail, format, a1, a2, a3, a4) { extern char *progname, *archname, *modulname; +extern int errno; +fprintf(stderr, "errno = %d\n", errno); fprintf(stderr, "%s: ", progname); if (archname) fprintf(stderr, "%s: ", archname); diff --git a/util/led/extract.c b/util/led/extract.c index 4ed5cec5..dd6753ba 100644 --- a/util/led/extract.c +++ b/util/led/extract.c @@ -10,6 +10,12 @@ static char rcsid[] = "$Header$"; #include "orig.h" #include "scan.h" +static get_name(); +static process(); +static getexternal(); +static redefine(); +static transfer(); + /* * Get section sizes and symboltable information from present module. */ diff --git a/util/led/finish.c b/util/led/finish.c index 57db0aa2..c2592859 100644 --- a/util/led/finish.c +++ b/util/led/finish.c @@ -12,6 +12,11 @@ static char rcsid[] = "$Header$"; extern bool incore; extern int flagword; +static adjust_names(); +static handle_relos(); +static put_locals(); +static compute_origins(); + /* * We know all there is to know about the current module. * Now we relocate the values in the emitted bytes and write diff --git a/util/led/main.c b/util/led/main.c index e8a33420..30cbd246 100644 --- a/util/led/main.c +++ b/util/led/main.c @@ -16,6 +16,21 @@ static char rcsid[] = "$Header$"; extern bool incore; +static initializations(); +static first_pass(); +static long number(); +static setlign(); +static setbase(); +static struct outname *makename(); +static pass1(); +static evaluate(); +static norm_commons(); +static complete_sections(); +static change_names(); +static bool tstbit(); +static second_pass(); +static pass2(); + main(argc, argv) int argc; char **argv; @@ -27,7 +42,7 @@ main(argc, argv) beginoutput(); second_pass(argv); endoutput(); - exit(0); + stop(); } char *progname; /* Name this program was invoked with. */ @@ -75,11 +90,9 @@ first_pass(argv) int sectno; int h; extern int atoi(); - extern long number(); extern char *index(); extern int hash(); extern struct outname *searchname(); - extern struct outname *makename(); while (*++argv) { argp = *argv; @@ -382,7 +395,6 @@ complete_sections() register long base = 0; register long foff; register int sectindex; - extern bool tstbit(); foff = SZ_HEAD + outhead.oh_nsect * SZ_SECT; for (sectindex = 0; sectindex < outhead.oh_nsect; sectindex++) { @@ -552,3 +564,9 @@ pass2(file) } closefile(file); } + +#ifdef NDEBUG + +dummy() { ; } + +#endif diff --git a/util/led/memory.c b/util/led/memory.c index 8f4f527d..0f41696b 100644 --- a/util/led/memory.c +++ b/util/led/memory.c @@ -15,6 +15,14 @@ static char rcsid[] = "$Header$"; #include "debug.h" #include "memory.h" +static copy_down(); +static copy_up(); +static free_saved_moduls(); +static writelong(); +static sectswap(); +static reloswap(); +static namecpy(); + struct memory mems[NMEMS]; bool incore = TRUE; /* TRUE while everything can be kept in core. */ @@ -32,11 +40,13 @@ init_core() register ind_t total_size; register struct memory *mem; extern char *sbrk(); + extern char *brk(); +char *BASE; #include "mach.c" total_size = (ind_t)0; /* Will accumulate the sizes. */ - base = sbrk(0); /* First free. */ + BASE = base = sbrk(0); /* First free. */ for (mem = mems; mem < &mems[NMEMS]; mem++) { mem->mem_base = base; mem->mem_full = (ind_t)0; @@ -59,7 +69,7 @@ init_core() mems[ALLOLCHR].mem_full = 1; mems[ALLOGCHR].mem_full = 1; - if (total_size != (int)total_size || (int)sbrk((int)total_size) == -1) { + if (brk(BASE + total_size) == (char *) -1) { incore = FALSE; /* In core strategy failed. */ if ((int)sbrk(AT_LEAST) == -1) fatal("no core at all"); @@ -80,7 +90,7 @@ move_up(piece, incr) extern char *sbrk(); debug("move_up(%d, %d)\n", piece, (int)incr, 0, 0); - if (incr != (int)incr || (int)sbrk((int)incr) == -1) + if (incr != (int)incr || sbrk((int)incr) == (char *) -1) return FALSE; for (mem = &mems[NMEMS - 1]; mem > &mems[piece]; mem--) diff --git a/util/led/memory.h b/util/led/memory.h index e78b065d..b5615ef8 100644 --- a/util/led/memory.h +++ b/util/led/memory.h @@ -19,7 +19,7 @@ #define INCRSIZE 1024 -typedef unsigned int ind_t; +typedef long ind_t; #define BADOFF ((ind_t)-1) struct memory { diff --git a/util/led/output.c b/util/led/output.c index 42fc3a37..b02337c3 100644 --- a/util/led/output.c +++ b/util/led/output.c @@ -6,6 +6,8 @@ static char rcsid[] = "$Header$"; #include "const.h" #include "memory.h" +static generate_section_names(); + extern struct outhead outhead; extern bool incore; extern int flagword; diff --git a/util/led/scan.c b/util/led/scan.c index c98e51e9..5edccb75 100644 --- a/util/led/scan.c +++ b/util/led/scan.c @@ -37,6 +37,17 @@ long objectsize; static long align(); static char *modulbase; static long modulsize(); +static scan_modul(); +static bool all_alloc(); +static bool direct_alloc(); +static bool indirect_alloc(); +static bool putemitindex(); +static bool putreloindex(); +#ifdef SYMDBUG +static bool putdbugindex(); +#endif SYMDBUG +static get_indirect(); +static read_modul(); /* * Open the file with name `filename' (if necessary) and examine the first diff --git a/util/led/write.c b/util/led/write.c index c73d9b66..36d8a95d 100644 --- a/util/led/write.c +++ b/util/led/write.c @@ -17,6 +17,9 @@ static char rcsid[] = "$Header$"; #include "memory.h" #include "orig.h" +static openoutput(); +static wrt_head(); +static wrt_sect(); extern long lseek(); #define WRITE 1 /* Argument to open(). */ From 4242c54c88f086e4691ad004e95804108bd2d7d4 Mon Sep 17 00:00:00 2001 From: keie Date: Mon, 10 Jun 1985 10:53:15 +0000 Subject: [PATCH 0038/1625] Adapted by Sjoerd to amoeba. --- util/led/byte_order.c | 2 +- util/led/mach.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/util/led/byte_order.c b/util/led/byte_order.c index 0172ec3d..08120b0b 100644 --- a/util/led/byte_order.c +++ b/util/led/byte_order.c @@ -26,7 +26,7 @@ determine_ordering() bytes_reversed = TRUE; sp = (short *)&l; sp[0] = 0x0001; sp[1] = 0x0002; - if (l != 0x0001 + (0x0002 << 16)) + if (l != 0x0001 + (0x0002L << 16)) words_reversed = TRUE; } diff --git a/util/led/mach.c b/util/led/mach.c index e17bf121..b9355076 100644 --- a/util/led/mach.c +++ b/util/led/mach.c @@ -6,7 +6,7 @@ * Now for Vax 11/750. */ -#define K 1024 +#define K 1024L mems[ALLOEMIT + 0].mem_left = 64 * K; mems[ALLOEMIT + 1].mem_left = 64 * K; From ec849d32573a32c81724bd2cee6e7cec06027a42 Mon Sep 17 00:00:00 2001 From: keie Date: Mon, 10 Jun 1985 11:23:22 +0000 Subject: [PATCH 0039/1625] Removed debugging printout. --- util/led/error.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/util/led/error.c b/util/led/error.c index f5f2517c..63b047b6 100644 --- a/util/led/error.c +++ b/util/led/error.c @@ -61,8 +61,6 @@ diag(tail, format, a1, a2, a3, a4) { extern char *progname, *archname, *modulname; -extern int errno; -fprintf(stderr, "errno = %d\n", errno); fprintf(stderr, "%s: ", progname); if (archname) fprintf(stderr, "%s: ", archname); From 2d43d88d60010e520b13110f5fd320035ed8f83f Mon Sep 17 00:00:00 2001 From: keie Date: Mon, 10 Jun 1985 11:28:06 +0000 Subject: [PATCH 0040/1625] Added AALMAG, for making distiction between 'led' archives with SYMDEF and archives made/altered with 'arch'. --- h/arch.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/h/arch.h b/h/arch.h index 0c8e9bff..816509fa 100644 --- a/h/arch.h +++ b/h/arch.h @@ -1,4 +1,6 @@ #define ARMAG 0177545 +#define AALMAG 0177454 + struct ar_hdr { char ar_name[14]; long ar_date; From 967fe97690f08a92cba41582514617b90c809148 Mon Sep 17 00:00:00 2001 From: keie Date: Mon, 10 Jun 1985 12:41:51 +0000 Subject: [PATCH 0041/1625] Using new magic number for 'aal' archives. --- util/led/scan.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/util/led/scan.c b/util/led/scan.c index 5edccb75..facb4adf 100644 --- a/util/led/scan.c +++ b/util/led/scan.c @@ -93,6 +93,8 @@ getfile(filename) modulname = filename; return PLAIN; case ARMAG: + warning("Using out-of-date archive %s",filename) ; + case AALMAG: archname = filename; if (passnumber == FIRST) { read_arhdr(&archive_header); From fccdec5cdb4cf4412ea16994f294b1cd163a3c32 Mon Sep 17 00:00:00 2001 From: keie Date: Mon, 10 Jun 1985 13:50:36 +0000 Subject: [PATCH 0042/1625] *** empty log message *** --- mach/6500/as/mach0.c | 10 +++ mach/6500/as/mach1.c | 7 ++ mach/6500/as/mach2.c | 28 ++++++++ mach/6500/as/mach3.c | 69 +++++++++++++++++++ mach/6500/as/mach4.c | 157 +++++++++++++++++++++++++++++++++++++++++++ mach/6500/as/mach5.c | 41 +++++++++++ 6 files changed, 312 insertions(+) create mode 100644 mach/6500/as/mach0.c create mode 100644 mach/6500/as/mach1.c create mode 100644 mach/6500/as/mach2.c create mode 100644 mach/6500/as/mach3.c create mode 100644 mach/6500/as/mach4.c create mode 100644 mach/6500/as/mach5.c diff --git a/mach/6500/as/mach0.c b/mach/6500/as/mach0.c new file mode 100644 index 00000000..7cf4e3b7 --- /dev/null +++ b/mach/6500/as/mach0.c @@ -0,0 +1,10 @@ +#define DUK +#define RCSID0 "$Header$" + +/* + * Mostek 6500 options. + */ +#define THREE_PASS /* Distinguish short and long branches. */ +#define LISTING /* Enable listing facilities. */ +#define RELOCATION /* Produce relocation information. */ +#define NOLD /* Output must be fed into separate linker. */ diff --git a/mach/6500/as/mach1.c b/mach/6500/as/mach1.c new file mode 100644 index 00000000..118df68f --- /dev/null +++ b/mach/6500/as/mach1.c @@ -0,0 +1,7 @@ +#define RCSID1 "$Header$" + +/* + * Mostek 6500 dependent C declarations. + */ + +#define fits_zeropage(x) (lowb(x) == (int)(x)) diff --git a/mach/6500/as/mach2.c b/mach/6500/as/mach2.c new file mode 100644 index 00000000..b1bc5498 --- /dev/null +++ b/mach/6500/as/mach2.c @@ -0,0 +1,28 @@ +#define RCSID2 "$Header$" + +/* + * Mostek 6500 tokens. + */ + +%token A +%token X +%token Y +%token EXTENSION +%token ADDOP +%token ROLOP +%token BRAOP +%token BITOP +%token NOPOP +%token CPXOP +%token INCOP +%token JMPOP +%token JSROP +%token LDXOP +%token LDYOP +%token STXOP +%token STYOP +%token PSEU + +%type addop + +%nonassoc EXTENSION diff --git a/mach/6500/as/mach3.c b/mach/6500/as/mach3.c new file mode 100644 index 00000000..ce701582 --- /dev/null +++ b/mach/6500/as/mach3.c @@ -0,0 +1,69 @@ +#define RCSID3 "$Header$" + +/* + * Mostek 6500 keywords + */ + +0, EXTENSION, 0, ".l", +0, EXTENSION, 8, ".h", +0, A, 0, "a", +0, X, 0, "x", +0, Y, 0, "y", +0, ADDOP, 0x60, "adc", +0, ADDOP, 0x20, "and", +0, ADDOP, 0xC0, "cmp", +0, ADDOP, 0x40, "eor", +0, ADDOP, 0xA0, "lda", +0, ADDOP, 0x00, "ora", +0, ADDOP, 0xE0, "sbc", +0, ADDOP, 0x80, "sta", +0, ROLOP, 0x00, "asl", +0, ROLOP, 0x40, "lsr", +0, ROLOP, 0x20, "rol", +0, ROLOP, 0x60, "ror", +0, BRAOP, 0x90, "bcc", +0, BRAOP, 0xB0, "bcs", +0, BRAOP, 0xF0, "beq", +0, BRAOP, 0x30, "bmi", +0, BRAOP, 0xD0, "bne", +0, BRAOP, 0x10, "bpl", +0, BRAOP, 0x50, "bvc", +0, BRAOP, 0x70, "bvs", +0, BITOP, 0x24, "bit", +0, NOPOP, 0x00, "brk", +0, NOPOP, 0x18, "clc", +0, NOPOP, 0xD8, "cld", +0, NOPOP, 0x58, "cli", +0, NOPOP, 0xB8, "clv", +0, NOPOP, 0xCA, "dex", +0, NOPOP, 0x88, "dey", +0, NOPOP, 0xE8, "inx", +0, NOPOP, 0xC8, "iny", +0, NOPOP, 0xEA, "nop", +0, NOPOP, 0x48, "pha", +0, NOPOP, 0x08, "php", +0, NOPOP, 0x68, "pla", +0, NOPOP, 0x28, "plp", +0, NOPOP, 0x40, "rti", +0, NOPOP, 0x60, "rts", +0, NOPOP, 0x38, "sec", +0, NOPOP, 0xF8, "sed", +0, NOPOP, 0x78, "sei", +0, NOPOP, 0xAA, "tax", +0, NOPOP, 0xA8, "tay", +0, NOPOP, 0x98, "tya", +0, NOPOP, 0xBA, "tsx", +0, NOPOP, 0x8A, "txa", +0, NOPOP, 0x9A, "txs", +0, CPXOP, 0xE0, "cpx", +0, CPXOP, 0xC0, "cpy", +0, INCOP, 0xC0, "dec", +0, INCOP, 0xE0, "inc", +0, JMPOP, 0x4C, "jmp", +0, JSROP, 0x20, "jsr", +0, LDXOP, 0xA0, "ldx", +0, LDYOP, 0xA0, "ldy", +0, STXOP, 0x80, "stx", +0, STYOP, 0x80, "sty", +0, PSEU, 0x1860, "add", +0, PSEU, 0x38E0, "sub", diff --git a/mach/6500/as/mach4.c b/mach/6500/as/mach4.c new file mode 100644 index 00000000..bbef6538 --- /dev/null +++ b/mach/6500/as/mach4.c @@ -0,0 +1,157 @@ +#define RCSID4 "$Header$" + +/* + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. + * + * This product is part of the Amsterdam Compiler Kit. + * + * Permission to use, sell, duplicate or disclose this software must be + * obtained in writing. Requests for such permissions may be sent to + * + * Dr. Andrew S. Tanenbaum + * Wiskundig Seminarium + * Vrije Universiteit + * Postbox 7161 + * 1007 MC Amsterdam + * The Netherlands + * + */ + +/* + * Mostek 6500 parsing tables. + */ + +expr + : expr EXTENSION + { $$.val = ($1.val >> $2) & 0xFF; + $$.typ = combine($1.typ, S_ABS, '&'); + } + ; +operation + : NOPOP + { emit1($1); } + | BITOP expr + { code($2,$1,$1+8); } + | JMPOP expr + { emit1($1); +#ifdef RELOCATION + newrelo($2.typ, RELO2); +#endif + emit2($2.val); + } + | JMPOP '(' expr ')' + { emit1($1+0x20); +#ifdef RELOCATION + newrelo($3.typ, RELO2); +#endif + emit2($3.val); + } + | JSROP expr + { emit1($1); +#ifdef RELOCATION + newrelo($2.typ, RELO2); +#endif + emit2($2.val); + } + | LDXOP '#' expr + { emit1(0xA2); +#ifdef RELOCATION + newrelo($3.typ, RELO1); +#endif + emit1($3); + } + | LDXOP expr + { code($2,0xA6,0xAE); } + | LDXOP expr ',' Y + { code($2,0xB6,0xBE); } + | LDYOP '#' expr + { emit1(0xA0); +#ifdef RELOCATION + newrelo($3.typ, RELO1); +#endif + emit1($3); + } + | LDYOP expr + { code($2,0xA4,0xAC); } + | LDYOP expr ',' X + { code($2,0xB4,0xBC); } + | STXOP expr + { code($2,$1+0x06,$1+0x0E); } + | STXOP expr ',' Y + { emit1($1+0x16); +#ifdef RELOCATION + newrelo($2.typ, RELO1); +#endif + emit1(lowb($2.val)); + } + | STYOP expr + { code($2,$1+0x04,$1+0x0C); } + | STYOP expr ',' X + { emit1($1+0x14); +#ifdef RELOCATION + newrelo($2.typ, RELO1); +#endif + emit1(lowb($2.val)); + } + | addop '#' expr + { if ($1==0x80) serror("no store immediate"); + emit1($1+0x09); +#ifdef RELOCATION + newrelo($3.typ, RELO1); +#endif + emit1($3); + } + | addop expr + { code($2,$1+0x05,$1+0x0D); } + | addop expr ',' X + { code($2,$1+0x15,$1+0x1D); } + | addop expr ',' Y + { emit1($1+0x19); +#ifdef RELOCATION + newrelo($2.typ, RELO2); +#endif + emit2($2.val); + } + | addop '(' expr ',' X ')' + { emit1($1+0x01); +#ifdef RELOCATION + newrelo($3.typ, RELO1); +#endif + emit1(lowb($3.val)); + } + | addop '(' expr ')' ',' Y + { emit1($1+0x11); +#ifdef RELOCATION + newrelo($3.typ, RELO1); +#endif + emit1(lowb($3.val)); + } + | ROLOP /* Default is A. */ + { emit1($1+0x0A); } + | ROLOP A + { emit1($1+0x0A); } + | ROLOP expr + { code($2,$1+0x06,$1+0x0E); } + | ROLOP expr ',' X + { code($2,$1+0x16,$1+0x1E); } + | BRAOP expr + { branch($1,$2); } + | CPXOP '#' expr + { emit1($1+0x00); +#ifdef RELOCATION + newrelo($3.typ, RELO1); +#endif + emit1($3); + } + | CPXOP expr + { code($2,$1+0x04,$1+0x0C); } + | INCOP expr + { code($2,$1+0x06,$1+0x0E); } + | INCOP expr ',' X + { code($2,$1+0x16,$1+0x1E); } + ; +addop + : ADDOP + | PSEU + { emit1($1>>8); $$ = $1 & 0xFF; } + ; diff --git a/mach/6500/as/mach5.c b/mach/6500/as/mach5.c new file mode 100644 index 00000000..2f45af9e --- /dev/null +++ b/mach/6500/as/mach5.c @@ -0,0 +1,41 @@ +#define RCSID5 "$Header$" + +/* + * Mostek 6500 special routines. + */ + +branch(opc, exp) +register int opc; +expr_t exp; +{ + register int dist; + + dist = exp.val - (DOTVAL + 2); + if (pass == PASS_2 && dist > 0 && !(exp.typ & S_DOT)) + dist -= DOTGAIN; + if (small(fitb(dist) && (exp.typ & ~S_DOT) == DOTTYP, 3)) { + emit1(opc); emit1(dist); + } else { + emit1(opc^0x20); emit1(0x03); /* Skip over ... */ + emit1(0x4C); /* ... far jump. */ +#ifdef RELOCATION + newrelo(exp.typ, RELO2); +#endif + emit2(exp.val); + } +} + +code(exp, opc1, opc2) +expr_t exp; +register int opc1, opc2; +{ + if (small((exp.typ & S_TYP) == S_ABS && fits_zeropage(exp.val), 1)) { + emit1(opc1); emit1(exp.val); + } else { + emit1(opc2); +#ifdef RELOCATION + newrelo(exp.typ, RELO2); +#endif + emit2(exp.val); + } +} From 91234b2e4f41e66c4e43538a5fe02373028c3e24 Mon Sep 17 00:00:00 2001 From: keie Date: Mon, 10 Jun 1985 13:55:48 +0000 Subject: [PATCH 0043/1625] *** empty log message *** --- mach/6500/as/READ_ME | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 mach/6500/as/READ_ME diff --git a/mach/6500/as/READ_ME b/mach/6500/as/READ_ME new file mode 100644 index 00000000..136f1877 --- /dev/null +++ b/mach/6500/as/READ_ME @@ -0,0 +1,15 @@ +De .h en .l extensions van expressies zijn hard nodig. +Ze zorgen er echter ook voor dat er geen relocatable code geproduceerd +kan worden. Beschouw het volgende voorbeeld: + +(file 1) +.sect .text ! 1 +lda #[endbss].l ! 2 +ldx #[endbss].h ! 3 + +(file 2) +.sect .bss ! 4 +endbss: ! 5 + +Wat voor relocation struct moet er nu voor de instructie in regel 3 +worden geproduceerd? From 74c3cfca9b00fcabfaa53e383613817910997d4c Mon Sep 17 00:00:00 2001 From: keie Date: Mon, 10 Jun 1985 14:52:43 +0000 Subject: [PATCH 0044/1625] *** empty log message *** --- mach/6800/as/mach0.c | 13 +++++ mach/6800/as/mach1.c | 5 ++ mach/6800/as/mach2.c | 13 +++++ mach/6800/as/mach3.c | 114 +++++++++++++++++++++++++++++++++++++++++++ mach/6800/as/mach4.c | 79 ++++++++++++++++++++++++++++++ mach/6800/as/mach5.c | 42 ++++++++++++++++ 6 files changed, 266 insertions(+) create mode 100644 mach/6800/as/mach0.c create mode 100644 mach/6800/as/mach1.c create mode 100644 mach/6800/as/mach2.c create mode 100644 mach/6800/as/mach3.c create mode 100644 mach/6800/as/mach4.c create mode 100644 mach/6800/as/mach5.c diff --git a/mach/6800/as/mach0.c b/mach/6800/as/mach0.c new file mode 100644 index 00000000..d979ec92 --- /dev/null +++ b/mach/6800/as/mach0.c @@ -0,0 +1,13 @@ +#define DUK +#define RCSID0 "$Header$" + +/* + * Motorola 6800 options + */ + +#define BYTES_REVERSED +#define WORDS_REVERSED +#define THREE_PASS +#define LISTING +#define RELOCATION +#define NOLD diff --git a/mach/6800/as/mach1.c b/mach/6800/as/mach1.c new file mode 100644 index 00000000..74a0ac73 --- /dev/null +++ b/mach/6800/as/mach1.c @@ -0,0 +1,5 @@ +#define RCSID1 "$Header$" + +/* + * Motorola 6800 C declarations + */ diff --git a/mach/6800/as/mach2.c b/mach/6800/as/mach2.c new file mode 100644 index 00000000..50035ae8 --- /dev/null +++ b/mach/6800/as/mach2.c @@ -0,0 +1,13 @@ +#define RCSID2 "$Header$" + +/* + * Motorola 6800 tokens + */ + +%token X +%token NOARG +%token BRANCH +%token AOP +%token XOP + +%type memref diff --git a/mach/6800/as/mach3.c b/mach/6800/as/mach3.c new file mode 100644 index 00000000..6ceff1e5 --- /dev/null +++ b/mach/6800/as/mach3.c @@ -0,0 +1,114 @@ +#define RCSID3 "$Header$" + +/* + * Motorola 6800 keywords + */ +0, X, 0, "x", +0, BRANCH, 0x20, "bra", +0, BRANCH, 0x22, "bhi", +0, BRANCH, 0x23, "bls", +0, BRANCH, 0x24, "bhs", /* bcc */ +0, BRANCH, 0x24, "bcc", +0, BRANCH, 0x25, "blo", /* bcs */ +0, BRANCH, 0x25, "bcs", +0, BRANCH, 0x26, "bne", +0, BRANCH, 0x27, "beq", +0, BRANCH, 0x28, "bvc", +0, BRANCH, 0x29, "bvs", +0, BRANCH, 0x2A, "bpl", +0, BRANCH, 0x2B, "bmi", +0, BRANCH, 0x2C, "bge", +0, BRANCH, 0x2D, "blt", +0, BRANCH, 0x2E, "bgt", +0, BRANCH, 0x2F, "ble", +0, BRANCH, 0x8D, "bsr", +0, XOP, 0xA0, "suba", +0, XOP, 0xA1, "cmpa", +0, XOP, 0xA2, "sbca", +0, XOP, 0xA4, "anda", +0, XOP, 0xA5, "bita", +0, XOP, 0xA6, "ldaa", +0, XOP, 0xA8, "eora", +0, XOP, 0xA9, "adca", +0, XOP, 0xAA, "oraa", +0, XOP, 0xAB, "adda", +0, XOP, 0xE0, "subb", +0, XOP, 0xE1, "cmpb", +0, XOP, 0xE2, "sbcb", +0, XOP, 0xE4, "andb", +0, XOP, 0xE5, "bitb", +0, XOP, 0xE6, "ldab", +0, XOP, 0xE8, "eorb", +0, XOP, 0xE9, "adcb", +0, XOP, 0xEA, "orab", +0, XOP, 0xEB, "addb", +0, AOP, 0x60, "neg", +0, NOARG, 0x40, "nega", +0, NOARG, 0x50, "negb", +0, AOP, 0x63, "com", +0, NOARG, 0x43, "coma", +0, NOARG, 0x53, "comb", +0, AOP, 0x64, "lsr", +0, NOARG, 0x44, "lsra", +0, NOARG, 0x54, "lsrb", +0, AOP, 0x66, "ror", +0, NOARG, 0x46, "rora", +0, NOARG, 0x56, "rorb", +0, AOP, 0x67, "asr", +0, NOARG, 0x47, "asra", +0, NOARG, 0x57, "asrb", +0, AOP, 0x68, "asl", +0, NOARG, 0x48, "asla", +0, NOARG, 0x58, "aslb", +0, AOP, 0x68, "lsl", +0, NOARG, 0x48, "lsla", +0, NOARG, 0x58, "lslb", +0, AOP, 0x69, "rol", +0, NOARG, 0x49, "rola", +0, NOARG, 0x59, "rolb", +0, AOP, 0x6A, "dec", +0, NOARG, 0x4A, "deca", +0, NOARG, 0x5A, "decb", +0, AOP, 0x6C, "inc", +0, NOARG, 0x4C, "inca", +0, NOARG, 0x5C, "incb", +0, AOP, 0x6D, "tst", +0, NOARG, 0x4D, "tsta", +0, NOARG, 0x5D, "tstb", +0, AOP, 0x6F, "clr", +0, NOARG, 0x4F, "clra", +0, NOARG, 0x5F, "clrb", +0, XOP, 0x6E, "jmp", +0, XOP, 0xAD, "jsr", +0, XOP, 0xAC, "cpx", +0, XOP, 0xAE, "ldx", +0, XOP, 0xEE, "lds", +0, XOP, 0xA7, "sta", +0, XOP, 0xE7, "stb", +0, XOP, 0xAF, "stx", +0, XOP, 0xEF, "sts", +0, NOARG, 0x19, "daa", +0, NOARG, 0x01, "nop", +0, NOARG, 0x3B, "rti", +0, NOARG, 0x39, "rts", +0, NOARG, 0x3F, "swi", +0, NOARG, 0x0C, "clc", +0, NOARG, 0x0D, "sec", +0, NOARG, 0x0E, "cli", +0, NOARG, 0x0F, "sei", +0, NOARG, 0x0A, "clv", +0, NOARG, 0x0B, "sev", +0, NOARG, 0x3E, "wai", +0, NOARG, 0x06, "tap", +0, NOARG, 0x07, "tpa", +0, NOARG, 0x1B, "aba", +0, NOARG, 0x11, "cba", +0, NOARG, 0x10, "sba", +0, NOARG, 0x16, "tab", +0, NOARG, 0x17, "tba", +0, NOARG, 0x09, "dex", +0, NOARG, 0x08, "inx", +0, NOARG, 0x34, "des", +0, NOARG, 0x31, "ins", +0, NOARG, 0x35, "txs", +0, NOARG, 0x30, "tsx", diff --git a/mach/6800/as/mach4.c b/mach/6800/as/mach4.c new file mode 100644 index 00000000..d50d198f --- /dev/null +++ b/mach/6800/as/mach4.c @@ -0,0 +1,79 @@ +#define RCSID4 "$Header$" + +/* + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. + * + * This product is part of the Amsterdam Compiler Kit. + * + * Permission to use, sell, duplicate or disclose this software must be + * obtained in writing. Requests for such permissions may be sent to + * + * Dr. Andrew S. Tanenbaum + * Wiskundig Seminarium + * Vrije Universiteit + * Postbox 7161 + * 1007 MC Amsterdam + * The Netherlands + * + */ + +/* + * Motorola 6800 parsing rules + */ + +operation + : + NOARG + { emit1($1);} + | + BRANCH expr + { branch($1,$2);} + | + XOP '#' expr + { emit1($1 - 0x20); + switch ($1 & 0x0F) { + case 0x03: + case 0x0C: + case 0x0E: +#ifdef RELOCATION + newrelo($3.typ, RELBR | RELO2); +#endif + emit2($3.val); + break; + default: +#ifdef RELOCATION + newrelo($3.typ, RELO1); +#endif + emit1($3.val); + } + } + | + XOP '<' expr + { emit1($1 - 0x10); +#ifdef RELOCATION + newrelo($3.typ, RELO1); +#endif + emit1($3.val); + } + | + memref expr + { emit1($1 + 0x10); +#ifdef RELOCATION + newrelo($2.typ, RELO2); +#endif + emit2($2.val); + } + | + memref expr ',' X + { emit1($1); +#ifdef RELOCATION + newrelo($2.typ, RELO1); +#endif + emit1($2.val); + } + ; +memref : + AOP + | + XOP + ; diff --git a/mach/6800/as/mach5.c b/mach/6800/as/mach5.c new file mode 100644 index 00000000..b582dc7f --- /dev/null +++ b/mach/6800/as/mach5.c @@ -0,0 +1,42 @@ +#define RCSID5 "$Header$" + +/* + * Motorola 6800 special routines + */ + +branch(opc,exp) register opc; expr_t exp; { + register sm, dist; + int saving; + + dist = exp.val - (DOTVAL + 2); + if (pass == PASS_2 && dist > 0 && !(exp.typ & S_DOT)) + dist -= DOTGAIN; + sm = fitb(dist); + if ((exp.typ & ~S_DOT) != DOTTYP) + sm = 0; + if (opc == 0x8D || opc == 0x20) + saving = 1; + else + saving = 3; + if (small(sm,saving)) { + emit1(opc); + emit1(dist); + } else { + if (opc == 0x8D) /* bsr */ + emit1(0xBD); /* jsr */ + else { + if (opc != 0x20) { /* bra */ + + /* reverse condition : */ + + emit1(opc ^ 1); + emit1(3); + } + emit1(0x7E); /* jmp */ + } +#ifdef RELOCATION + newrelo(exp.typ, RELO2 | RELBR); +#endif + emit2(exp.val); + } +} From 6491a49d46f202bf049bfd71daab00bef1d7210d Mon Sep 17 00:00:00 2001 From: keie Date: Mon, 10 Jun 1985 15:32:18 +0000 Subject: [PATCH 0045/1625] *** empty log message *** --- mach/6809/as/mach0.c | 12 +++ mach/6809/as/mach1.c | 40 +++++++++ mach/6809/as/mach2.c | 19 ++++ mach/6809/as/mach3.c | 166 +++++++++++++++++++++++++++++++++++ mach/6809/as/mach4.c | 204 +++++++++++++++++++++++++++++++++++++++++++ mach/6809/as/mach5.c | 99 +++++++++++++++++++++ 6 files changed, 540 insertions(+) create mode 100644 mach/6809/as/mach0.c create mode 100644 mach/6809/as/mach1.c create mode 100644 mach/6809/as/mach2.c create mode 100644 mach/6809/as/mach3.c create mode 100644 mach/6809/as/mach4.c create mode 100644 mach/6809/as/mach5.c diff --git a/mach/6809/as/mach0.c b/mach/6809/as/mach0.c new file mode 100644 index 00000000..679af47e --- /dev/null +++ b/mach/6809/as/mach0.c @@ -0,0 +1,12 @@ +#define DUK +#define RCSID0 "$Header$" + +/* + * Motorola 6809 options + */ +#define BYTES_REVERSED +#define WORDS_REVERSED +#define THREE_PASS +#define LISTING +#define RELOCATION +#define NOLD diff --git a/mach/6809/as/mach1.c b/mach/6809/as/mach1.c new file mode 100644 index 00000000..3909c5d3 --- /dev/null +++ b/mach/6809/as/mach1.c @@ -0,0 +1,40 @@ +#define RCSID1 "$Header$" + +/* + * Motorola 6809 C declarations + */ + +extern int dpvalue INIT(-1); /* for setdp pseudo-op */ + +#ifndef extern +extern int regbit[]; +#else +int regbit[] = { /* push-pull coding */ + 6, /* D */ + 0x10, /* X */ + 0x20, /* Y */ + 0x40, /* U */ + 0x40, /* S */ + 0x80, /* PC */ + -1, -1, + 2, /* A */ + 4, /* B */ + 1, /* CC */ + 8, /* DP */ +}; +#endif + +/* + * Motorola 6809 register names + */ + +#define D 0 +#define X 1 +#define Y 2 +#define U 3 +#define S 4 +#define PC 5 +#define A 8 +#define B 9 +#define CC 10 +#define DP 11 diff --git a/mach/6809/as/mach2.c b/mach/6809/as/mach2.c new file mode 100644 index 00000000..3d88c040 --- /dev/null +++ b/mach/6809/as/mach2.c @@ -0,0 +1,19 @@ +#define RCSID2 "$Header$" + +/* + * Motorola 6809 tokens + */ + +%token REG +%token ALL +%token SETDP +%token NOARG +%token BRANCH +%token LBRNCH +%token SBRNCH +%token STACK +%token IMMED +%token TWOREG +%token XOP + +%type reglist xyus xmode diff --git a/mach/6809/as/mach3.c b/mach/6809/as/mach3.c new file mode 100644 index 00000000..a2795e59 --- /dev/null +++ b/mach/6809/as/mach3.c @@ -0,0 +1,166 @@ +#define RCSID3 "$Header$" + +/* + * Motorola 6809 keywords + */ + +0, REG, A, "a", +0, REG, B, "b", +0, REG, CC, "cc", +0, REG, DP, "dp", +0, REG, D, "d", +0, REG, X, "x", +0, REG, Y, "y", +0, REG, U, "u", +0, REG, S, "s", +0, REG, PC, "pc", +0, ALL, 0xFF, "all", +0, SETDP, 0, "setdp", +0, NOARG, 0x3A, "abx", +0, NOARG, 0x19, "daa", +0, NOARG, 0x3D, "mul", +0, NOARG, 0x12, "nop", +0, NOARG, 0x10, "page2", +0, NOARG, 0x11, "page3", +0, NOARG, 0x3B, "rti", +0, NOARG, 0x4F, "clra", +0, NOARG, 0x5F, "clrb", +0, NOARG, 0x4A, "deca", +0, NOARG, 0x5A, "decb", +0, NOARG, 0x43, "coma", +0, NOARG, 0x53, "comb", +0, NOARG, 0x44, "lsra", +0, NOARG, 0x54, "lsrb", +0, NOARG, 0x40, "nega", +0, NOARG, 0x50, "negb", +0, NOARG, 0x46, "rora", +0, NOARG, 0x56, "rorb", +0, NOARG, 0x47, "asra", +0, NOARG, 0x57, "asrb", +0, NOARG, 0x49, "rola", +0, NOARG, 0x59, "rolb", +0, NOARG, 0x48, "asla", +0, NOARG, 0x58, "aslb", +0, NOARG, 0x48, "lsla", +0, NOARG, 0x58, "lslb", +0, NOARG, 0x4C, "inca", +0, NOARG, 0x5C, "incb", +0, NOARG, 0x4D, "tsta", +0, NOARG, 0x5D, "tstb", +0, NOARG, 0x39, "rts", +0, NOARG, 0x1D, "sex", +0, NOARG, 0x3F, "swi", +0, NOARG, 0x103F, "swi2", +0, NOARG, 0x113F, "swi3", +0, NOARG, 0x13, "sync", +0, BRANCH, 0x20, "bra", +0, BRANCH, 0x21, "brn", +0, BRANCH, 0x22, "bhi", +0, BRANCH, 0x23, "bls", +0, BRANCH, 0x24, "bhs", +0, BRANCH, 0x24, "bcc", +0, BRANCH, 0x25, "blo", +0, BRANCH, 0x25, "bcs", +0, BRANCH, 0x26, "bne", +0, BRANCH, 0x27, "beq", +0, BRANCH, 0x28, "bvc", +0, BRANCH, 0x29, "bvs", +0, BRANCH, 0x2A, "bpl", +0, BRANCH, 0x2B, "bmi", +0, BRANCH, 0x2C, "bge", +0, BRANCH, 0x2D, "blt", +0, BRANCH, 0x2E, "bgt", +0, BRANCH, 0x2F, "ble", +0, BRANCH, 0x8D, "bsr", +0, STACK, 0x34, "pshs", +0, STACK, 0x35, "puls", +0, STACK, 0x36, "pshu", +0, STACK, 0x37, "pulu", +0, IMMED, 0x1A, "orcc", +0, IMMED, 0x1C, "andcc", +0, IMMED, 0x3C, "cwai", +0, TWOREG, 0x1E, "exg", +0, TWOREG, 0x1F, "tfr", +0, XOP, 0xA0, "suba", +0, XOP, 0xA1, "cmpa", +0, XOP, 0xA2, "sbca", +0, XOP, 0xA4, "anda", +0, XOP, 0xA5, "bita", +0, XOP, 0xA6, "lda", +0, XOP, 0xA8, "eora", +0, XOP, 0xA9, "adca", +0, XOP, 0xAA, "ora", +0, XOP, 0xAB, "adda", +0, XOP, 0xE0, "subb", +0, XOP, 0xE1, "cmpb", +0, XOP, 0xE2, "sbcb", +0, XOP, 0xE4, "andb", +0, XOP, 0xE5, "bitb", +0, XOP, 0xE6, "ldb", +0, XOP, 0xE8, "eorb", +0, XOP, 0xE9, "adcb", +0, XOP, 0xEA, "orb", +0, XOP, 0xEB, "addb", +0, XOP, 0x30, "leax", +0, XOP, 0x31, "leay", +0, XOP, 0x32, "leas", +0, XOP, 0x33, "leau", +0, XOP, 0x60, "neg", +0, XOP, 0x63, "com", +0, XOP, 0x64, "lsr", +0, XOP, 0x66, "ror", +0, XOP, 0x67, "asr", +0, XOP, 0x68, "asl", +0, XOP, 0x68, "lsl", +0, XOP, 0x69, "rol", +0, XOP, 0x6A, "dec", +0, XOP, 0x6C, "inc", +0, XOP, 0x6D, "tst", +0, XOP, 0x6F, "clr", +0, XOP, 0x6E, "jmp", +0, XOP, 0xA3, "subd", +0, XOP, 0x10A3, "cmpd", +0, XOP, 0x11A3, "cmpu", +0, XOP, 0xAC, "cmpx", +0, XOP, 0x10AC, "cmpy", +0, XOP, 0x11AC, "cmps", +0, XOP, 0xAE, "ldx", +0, XOP, 0x10AE, "ldy", +0, XOP, 0xE3, "addd", +0, XOP, 0xEC, "ldd", +0, XOP, 0xEE, "ldu", +0, XOP, 0x10EE, "lds", +0, XOP, 0xA7, "sta", +0, XOP, 0xAD, "jsr", +0, XOP, 0xAF, "stx", +0, XOP, 0x10AF, "sty", +0, XOP, 0xE7, "stb", +0, XOP, 0xED, "std", +0, XOP, 0xEF, "stu", +0, XOP, 0x10EF, "sts", +0, LBRNCH, 0x21, "lbrn", +0, LBRNCH, 0x22, "lbhi", +0, LBRNCH, 0x23, "lbls", +0, LBRNCH, 0x24, "lbhs", +0, LBRNCH, 0x24, "lbcc", +0, LBRNCH, 0x25, "lblo", +0, LBRNCH, 0x25, "lbcs", +0, LBRNCH, 0x26, "lbne", +0, LBRNCH, 0x27, "lbeq", +0, LBRNCH, 0x28, "lbvc", +0, LBRNCH, 0x29, "lbvs", +0, LBRNCH, 0x2A, "lbpl", +0, LBRNCH, 0x2B, "lbmi", +0, LBRNCH, 0x2C, "lbge", +0, LBRNCH, 0x2D, "lblt", +0, LBRNCH, 0x2E, "lbgt", +0, LBRNCH, 0x2F, "lble", +0, SBRNCH, 0x16, "lbra", +0, SBRNCH, 0x17, "lbsr", +0, NOARG, 0x1CFE, "clc", +0, NOARG, 0x1A01, "sec", +0, NOARG, 0x1CEF, "cli", +0, NOARG, 0x1A10, "sei", +0, NOARG, 0x1CFD, "clv", +0, NOARG, 0x1A02, "sev", +0, NOARG, 0x3CFF, "wai", diff --git a/mach/6809/as/mach4.c b/mach/6809/as/mach4.c new file mode 100644 index 00000000..5d64544c --- /dev/null +++ b/mach/6809/as/mach4.c @@ -0,0 +1,204 @@ +#define RCSID4 "$Header$" + +/* + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. + * + * This product is part of the Amsterdam Compiler Kit. + * + * Permission to use, sell, duplicate or disclose this software must be + * obtained in writing. Requests for such permissions may be sent to + * + * Dr. Andrew S. Tanenbaum + * Wiskundig Seminarium + * Vrije Universiteit + * Postbox 7161 + * 1007 MC Amsterdam + * The Netherlands + * + */ + +/* + * Motorola 6809 parsing rules + */ + +operation + : SETDP expr + { dpvalue = $2.val;} + | + NOARG + { emit1or2($1);} + | + BRANCH expr + { branch($1,$2);} + | + LBRNCH expr + { emit1(0x10); emit1($1); + $2.val -= (DOTVAL+2); +#ifdef RELOCATION + newrelo($2.typ, RELPC|RELO2|RELBR); +#endif + emit2($2.val); + } + | + SBRNCH expr + { emit1($1); + $2.val -= (DOTVAL+2); +#ifdef RELOCATION + newrelo($2.typ, RELPC|RELO2|RELBR); +#endif + emit2($2.val); + } + | + IMMED '#' expr + { emit1($1); +#ifdef RELOCATION + newrelo($3.typ, RELO1); +#endif + emit1($3.val); + } + | + XOP '#' expr + { emit1or2($1 - 0x20); + switch ($1 & 0x0F) { + case 0x03: + case 0x0C: + case 0x0E: +#ifdef RELOCATION + newrelo($3.typ, RELO2|RELBR); +#endif + emit2($3.val); + break; + default: +#ifdef RELOCATION + newrelo($3.typ, RELO1); +#endif + emit1($3.val); + break; + } + } + | + XOP '<' expr + { if (0 <= $1 && $1 < 0x80) + emit1(($1-0x10) & 0x3F); + else + emit1or2($1 - 0x10); +#ifdef RELOCATION + newrelo($3.typ, RELO1); +#endif + emit1($3.val); + } + | + XOP '>' expr + { emit1or2($1 + 0x10); +#ifdef RELOCATION + newrelo($3.typ, RELO2|RELBR); +#endif + emit2($3.val); + } + | + STACK reglist + { emit1($1); emit1($2);} + | + TWOREG REG ',' REG + { + emit1($1); + emit1($2 << 4 | $4); + } + | + XOP REG + { switch ($2) { + case A: emit1($1 - 0x20); + break; + case B: emit1($1 - 0x10); + break; + default:serror("register error"); + } + } + | + XOP expr ',' REG + { emit1or2($1); + offset($4,$2,0); + } + | + XOP '(' expr ',' REG ')' + { emit1or2($1); + offset($5,$3,0x10); + } + | + XOP '(' expr ')' + { emit1or2($1); + emit1(0x9F); +#ifdef RELOCATION + newrelo($3.typ, RELO1); +#endif + emit1($3.val); + } + | + XOP xmode + { emit1or2($1); + emit1($2); + } + | + XOP '(' xmode ')' + { if (($3 & 0x8D) == 0x80) + serror("invalid index mode"); + emit1or2($1); + emit1($3 + 0x10); + } + | + XOP expr + { if (($2.typ & S_TYP) == S_ABS && + ((unsigned)$2.val >> 8) == dpvalue + ) { + if (0 <= $1 && $1 < 0x80) + emit1(($1-0x20) & 0x3F); + else + emit1or2($1 - 0x10); + emit1($2.val); + } else { + emit1or2($1 + 0x10); +#ifdef RELOCATION + newrelo($2.typ, RELO2|RELBR); +#endif + emit2($2.val); + } + } + ; +reglist : ALL + | REG + { if (($$ = regbit[$1]) < 0) serror("register error");} + | + reglist ',' REG + { register i; + if ((i = regbit[$3]) < 0 || ($1 & i) != 0) + serror("register error"); + $$ = $1 | i; + } + ; +xyus : REG + { if (($$ = regno($1)) < 0) serror("register error");} + ; +xmode : ',' xyus '+' '+' + { $$ = 0x81 + $2;} + | + ',' xyus '+' + { $$ = 0x80 + $2;} + | + ',' xyus + { $$ = 0x84 + $2;} + | + ',' '-' '-' xyus + { $$ = 0x83 + $4;} + | + ',' '-' xyus + { $$ = 0x82 + $3;} + | + REG ',' xyus + { switch($1) { + case A: $$ = 0x86 + $3; break; + case B: $$ = 0x85 + $3; break; + case D: $$ = 0x8B + $3; break; + default: serror("register error"); + } + } + ; diff --git a/mach/6809/as/mach5.c b/mach/6809/as/mach5.c new file mode 100644 index 00000000..b820c571 --- /dev/null +++ b/mach/6809/as/mach5.c @@ -0,0 +1,99 @@ +#define RCSID5 "$Header$" + +/* + * Motorola 6809 special routines + */ + +branch(opc, exp) +register int opc; +expr_t exp; +{ + register int sm, dist; + int saving; + + dist = exp.val - (DOTVAL + 2); + if (pass == PASS_2 && dist > 0 && !(exp.typ & S_DOT)) + dist -= DOTGAIN; + sm = fitb(dist); + if ((exp.typ & ~S_DOT) != DOTTYP) + sm = 0; + if (opc == 0x8D || opc == 0x20) + saving = 1; + else + saving = 2; + if ((sm = small(sm,saving)) == 0) { + dist--; + if (opc == 0x8D) /* bsr */ + opc = 0x17; + else if (opc == 0x20) /* bra */ + opc = 0x16; + else { + emit1(0x10); + dist--; + } + } + emit1(opc); + if (sm == 0) { +#ifdef RELOCATION + newrelo(exp.typ, RELPC|RELO2|RELBR); +#endif + emit2(dist); + } else + emit1(lowb(dist)); +} + +regno(r) register r; { + switch (r) { + case X: return 0; + case Y: return 0x20; + case U: return 0x40; + case S: return 0x60; + } + return -1; +} + +emit1or2(n) { + if (n & ~0xFF) + emit1(n >> 8); + emit1(n); +} + +offset(reg, exp, ind) +register int reg, ind; +expr_t exp; +{ + if (reg == PC) { + int sm, dist; + + dist = exp.val - (DOTVAL + 2); + if (pass == PASS_2 && dist > 0 && !(exp.typ & S_DOT)) + dist -= DOTGAIN; + sm = fitb(dist); + if ((exp.typ & S_TYP) != DOTTYP) + sm = 0; + if (small(sm,0)) { + emit1(0x8C + ind); + emit1(dist); + } else { + emit1(0x8D + ind); + emit1(dist - 1); + } + } else if ((reg = regno(reg)) < 0) + serror("register error"); + else if ((exp.typ & S_TYP) == S_ABS && exp.val == 0) + emit1(0x84 + reg + ind); /* XOP 0, REG == XOP , REG */ + else if (ind == 0 && (exp.typ & S_TYP) == S_ABS && + -16 <= exp.val && exp.val <= 15 + ) + emit1(reg + ind + (exp.val & 037)); + else if ((exp.typ&S_TYP)==S_ABS && -256<=exp.val && exp.val<=255) { + emit1(0x88 + reg + ind); + emit1(exp.val); + } else { + emit1(0x89 + reg + ind); +#ifdef RELOCATION + newrelo(exp.typ, RELO2|RELBR); +#endif + emit2(exp.val); + } +} From 91ff69f4e564a1a2d040857c324a7a09d4fec2fc Mon Sep 17 00:00:00 2001 From: keie Date: Mon, 10 Jun 1985 16:05:04 +0000 Subject: [PATCH 0046/1625] *** empty log message *** --- mach/i80/as/mach0.c | 9 +++++ mach/i80/as/mach1.c | 19 +++++++++ mach/i80/as/mach2.c | 19 +++++++++ mach/i80/as/mach3.c | 95 ++++++++++++++++++++++++++++++++++++++++++++ mach/i80/as/mach4.c | 97 +++++++++++++++++++++++++++++++++++++++++++++ mach/i80/as/mach5.c | 0 6 files changed, 239 insertions(+) create mode 100644 mach/i80/as/mach0.c create mode 100644 mach/i80/as/mach1.c create mode 100644 mach/i80/as/mach2.c create mode 100644 mach/i80/as/mach3.c create mode 100644 mach/i80/as/mach4.c create mode 100644 mach/i80/as/mach5.c diff --git a/mach/i80/as/mach0.c b/mach/i80/as/mach0.c new file mode 100644 index 00000000..94fae314 --- /dev/null +++ b/mach/i80/as/mach0.c @@ -0,0 +1,9 @@ +#define DUK +#define RCSID0 "$Header$" + +/* + * Intel 8080 options + */ +#define LISTING +#define RELOCATION +#define NOLD diff --git a/mach/i80/as/mach1.c b/mach/i80/as/mach1.c new file mode 100644 index 00000000..888e567e --- /dev/null +++ b/mach/i80/as/mach1.c @@ -0,0 +1,19 @@ +#define RCSID1 "$Header$" + +/* + * Intel 8080 register names + */ + +#define B 0 +#define C 1 +#define D 2 +#define E 3 +#define H 4 +#define L 5 +#define M 6 +#define A 7 +#define SP 6 +#define PSW 6 + +#define low3(z) ((z) & 07) +#define fit3(z) (low3(z) == (z)) diff --git a/mach/i80/as/mach2.c b/mach/i80/as/mach2.c new file mode 100644 index 00000000..4ca1fd2d --- /dev/null +++ b/mach/i80/as/mach2.c @@ -0,0 +1,19 @@ +#define RCSID2 "$Header$" + +/* + * Intel 8080 tokens + */ +%token REG +%token NOOPOP +%token DSTOP +%token SRCOP +%token D8OP +%token D16OP +%token R16OP +%token MOV +%token MVI +%token LXI +%token RST +%token STLDAX + +%type r16 r8 diff --git a/mach/i80/as/mach3.c b/mach/i80/as/mach3.c new file mode 100644 index 00000000..05b2867f --- /dev/null +++ b/mach/i80/as/mach3.c @@ -0,0 +1,95 @@ +#define RCSID3 "$Header$" + +/* + * Intel 8080 keywords + */ +0, REG, B, "b", +0, REG, C, "c", +0, REG, D, "d", +0, REG, E, "e", +0, REG, H, "h", +0, REG, L, "l", +0, REG, M, "m", +0, REG, A, "a", +0, REG, SP, "sp", +0, REG, PSW, "psw", +0, D16OP, 0315, "call", +0, D16OP, 0334, "cc", +0, D16OP, 0324, "cnc", +0, D16OP, 0314, "cz", +0, D16OP, 0304, "cnz", +0, D16OP, 0364, "cp", +0, D16OP, 0374, "cm", +0, D16OP, 0354, "cpe", +0, D16OP, 0344, "cpo", +0, NOOPOP, 0311, "ret", +0, NOOPOP, 0330, "rc", +0, NOOPOP, 0320, "rnc", +0, NOOPOP, 0310, "rz", +0, NOOPOP, 0300, "rnz", +0, NOOPOP, 0360, "rp", +0, NOOPOP, 0370, "rm", +0, NOOPOP, 0350, "rpe", +0, NOOPOP, 0340, "rpo", +0, RST, 0307, "rst", +0, D8OP, 0333, "in", +0, D8OP, 0323, "out", +0, LXI, 0001, "lxi", +0, R16OP, 0305, "push", +0, R16OP, 0301, "pop", +0, D16OP, 0062, "sta", +0, D16OP, 0072, "lda", +0, NOOPOP, 0353, "xchg", +0, NOOPOP, 0343, "xthl", +0, NOOPOP, 0371, "sphl", +0, NOOPOP, 0351, "pchl", +0, R16OP, 0011, "dad", +0, STLDAX, 0002, "stax", +0, STLDAX, 0012, "ldax", +0, R16OP, 0003, "inx", +0, MOV, 0100, "mov", +0, NOOPOP, 0166, "hlt", +0, MVI, 0006, "mvi", +0, DSTOP, 0004, "inr", +0, DSTOP, 0005, "dcr", +0, SRCOP, 0200, "add", +0, SRCOP, 0210, "adc", +0, SRCOP, 0220, "sub", +0, SRCOP, 0230, "sbb", +0, SRCOP, 0240, "ana", +0, SRCOP, 0250, "xra", +0, SRCOP, 0260, "ora", +0, SRCOP, 0270, "cmp", +0, D8OP, 0306, "adi", +0, D8OP, 0316, "aci", +0, D8OP, 0326, "sui", +0, D8OP, 0336, "sbi", +0, D8OP, 0346, "ani", +0, D8OP, 0356, "xri", +0, D8OP, 0366, "ori", +0, D8OP, 0376, "cpi", +0, NOOPOP, 0007, "rlc", +0, NOOPOP, 0017, "rrc", +0, NOOPOP, 0027, "ral", +0, NOOPOP, 0037, "rar", +0, D16OP, 0303, "jmp", +0, D16OP, 0332, "jc", +0, D16OP, 0322, "jnc", +0, D16OP, 0312, "jz", +0, D16OP, 0302, "jnz", +0, D16OP, 0362, "jp", +0, D16OP, 0372, "jm", +0, D16OP, 0352, "jpe", +0, D16OP, 0342, "jpo", +0, R16OP, 0013, "dcx", +0, NOOPOP, 0057, "cma", +0, NOOPOP, 0067, "stc", +0, NOOPOP, 0077, "cmc", +0, NOOPOP, 0047, "daa", +0, D16OP, 0042, "shld", +0, D16OP, 0052, "lhld", +0, NOOPOP, 0373, "ei", +0, NOOPOP, 0363, "di", +0, NOOPOP, 0000, "nop", +0, NOOPOP, 0040, "rim", /* 8085 */ +0, NOOPOP, 0060, "sim", /* 8085 */ diff --git a/mach/i80/as/mach4.c b/mach/i80/as/mach4.c new file mode 100644 index 00000000..30e083b6 --- /dev/null +++ b/mach/i80/as/mach4.c @@ -0,0 +1,97 @@ +#define RCSID4 "$Header$" + +/* + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. + * + * This product is part of the Amsterdam Compiler Kit. + * + * Permission to use, sell, duplicate or disclose this software must be + * obtained in writing. Requests for such permissions may be sent to + * + * Dr. Andrew S. Tanenbaum + * Wiskundig Seminarium + * Vrije Universiteit + * Postbox 7161 + * 1007 MC Amsterdam + * The Netherlands + * + */ + +/* + * Intel 8080 parsing rules + */ +operation + : NOOPOP + { emit1($1);} + | + D8OP expr + { emit1($1); +#ifdef RELOCATION + newrelo($2.typ, RELO1); +#endif + emit1($2.val); + } + | + D16OP expr + { emit1($1); +#ifdef RELOCATION + newrelo($2.typ, RELO2); +#endif + emit2($2.val); + } + | + R16OP r16 + { emit1($1 | ($2 << 3));} + | + MOV r8 ',' r8 + { if ($2 == M && $4 == M) + serror("register error"); + emit1($1 | ($2 << 3) | $4); + } + | + MVI r8 ',' expr + { emit1($1 | ($2 << 3)); +#ifdef RELOCATION + newrelo($4.typ, RELO1); +#endif + emit1($4.val); + } + | + LXI r16 ',' expr + { emit1($1 | ($2 << 3)); +#ifdef RELOCATION + newrelo($4.typ, RELO2); +#endif + emit2($4.val); + } + | + SRCOP r8 + { emit1($1 | $2);} + | + DSTOP r8 + { emit1($1 | ($2 << 3));} + | + RST absexp + { fit(fit3($2)); + emit1($1 | (low3($2) << 3)); + } + | + STLDAX r16 + { + if ($2 != B && $2 != D) + serror("register error"); + emit1($1 | (($2 & 02) << 3)); + } + ; +r16 : REG + { if ($1 & ~06) + serror("register error"); + $$ = $1 & 06; + } + ; +r8 : REG + { if (($1 & ~07) != 0) + serror("register error"); + $$ = $1 & 07; + } + ; diff --git a/mach/i80/as/mach5.c b/mach/i80/as/mach5.c new file mode 100644 index 00000000..e69de29b From 7edec0e32163cdafb2e10105f9a53240c28cbfa2 Mon Sep 17 00:00:00 2001 From: keie Date: Mon, 10 Jun 1985 16:57:01 +0000 Subject: [PATCH 0047/1625] *** empty log message *** --- mach/i86/as/READ_ME | 5 + mach/i86/as/mach0.c | 10 ++ mach/i86/as/mach1.c | 37 +++++ mach/i86/as/mach2.c | 28 ++++ mach/i86/as/mach3.c | 176 ++++++++++++++++++++++ mach/i86/as/mach4.c | 132 ++++++++++++++++ mach/i86/as/mach5.c | 266 ++++++++++++++++++++++++++++++++ mach/s2650/as/mach0.c | 11 ++ mach/s2650/as/mach1.c | 20 +++ mach/s2650/as/mach2.c | 23 +++ mach/s2650/as/mach3.c | 90 +++++++++++ mach/s2650/as/mach4.c | 139 +++++++++++++++++ mach/s2650/as/mach5.c | 86 +++++++++++ mach/z80/as/mach0.c | 10 ++ mach/z80/as/mach1.c | 32 ++++ mach/z80/as/mach2.c | 30 ++++ mach/z80/as/mach3.c | 98 ++++++++++++ mach/z80/as/mach4.c | 343 ++++++++++++++++++++++++++++++++++++++++++ mach/z80/as/mach5.c | 57 +++++++ 19 files changed, 1593 insertions(+) create mode 100644 mach/i86/as/READ_ME create mode 100644 mach/i86/as/mach0.c create mode 100644 mach/i86/as/mach1.c create mode 100644 mach/i86/as/mach2.c create mode 100644 mach/i86/as/mach3.c create mode 100644 mach/i86/as/mach4.c create mode 100644 mach/i86/as/mach5.c create mode 100644 mach/s2650/as/mach0.c create mode 100644 mach/s2650/as/mach1.c create mode 100644 mach/s2650/as/mach2.c create mode 100644 mach/s2650/as/mach3.c create mode 100644 mach/s2650/as/mach4.c create mode 100644 mach/s2650/as/mach5.c create mode 100644 mach/z80/as/mach0.c create mode 100644 mach/z80/as/mach1.c create mode 100644 mach/z80/as/mach2.c create mode 100644 mach/z80/as/mach3.c create mode 100644 mach/z80/as/mach4.c create mode 100644 mach/z80/as/mach5.c diff --git a/mach/i86/as/READ_ME b/mach/i86/as/READ_ME new file mode 100644 index 00000000..c4a937c5 --- /dev/null +++ b/mach/i86/as/READ_ME @@ -0,0 +1,5 @@ +The mach?.c files in this directory were made for an earlier version of +the universal assembler and are too dependent on its innards. +I have no idea in what way they should be changed. + + Duk Bekema diff --git a/mach/i86/as/mach0.c b/mach/i86/as/mach0.c new file mode 100644 index 00000000..d5bce732 --- /dev/null +++ b/mach/i86/as/mach0.c @@ -0,0 +1,10 @@ +#define DUK +#define RCSID0 "$Header$" + +/* + * INTEL 8086 options + */ +#define THREE_PASS /* branch and offset optimization */ +#define LISTING /* enable listing facilities */ +#define RELOCATION +#define NOLD diff --git a/mach/i86/as/mach1.c b/mach/i86/as/mach1.c new file mode 100644 index 00000000..ff247ba0 --- /dev/null +++ b/mach/i86/as/mach1.c @@ -0,0 +1,37 @@ +#define RCSID1 "$Header$" + +/* + * INTEL 8086 C declarations + */ + +#define low6(z) (z & 077) +#define fit6(z) (low6(z) == z) + +extern int mrg_1,mrg_2; +extern expr_t exp_1,exp_2; +#ifndef ASLD +extern int rel_1, rel_2; +#endif + +#ifndef extern +extern char sr_m[8]; +#else +char sr_m[8] = { + -1, -1, -1, 7, -1, 6, 4, 5 +}; +#endif + +#ifndef extern +extern char dr_m[8][8]; +#else +char dr_m[8][8] = { + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 0, 1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 2, 3, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1 +}; +#endif diff --git a/mach/i86/as/mach2.c b/mach/i86/as/mach2.c new file mode 100644 index 00000000..3ee68cb3 --- /dev/null +++ b/mach/i86/as/mach2.c @@ -0,0 +1,28 @@ +#define RCSID2 "$Header$" + +/* + * INTEL 8086 tokens + */ + +%token R16 +%token R8 +%token RSEG +%token PREFIX +%token NOOP_1 +%token NOOP_2 +%token JOP +%token PUSHOP +%token IOOP +%token ADDOP +%token ROLOP +%token INCOP +%token NOTOP +%token CALLOP +%token CALFOP +%token LEAOP +%token ESC +%token INT +%token RET +%token XCHG +%token TEST +%token MOV diff --git a/mach/i86/as/mach3.c b/mach/i86/as/mach3.c new file mode 100644 index 00000000..717bd60b --- /dev/null +++ b/mach/i86/as/mach3.c @@ -0,0 +1,176 @@ +#define RCSID3 "$Header$" + +/* + * INTEL 8086 keywords + */ + +0, R16, 0, "ax", +0, R16, 1, "cx", +0, R16, 2, "dx", +0, R16, 3, "bx", +0, R16, 4, "sp", +0, R16, 5, "bp", +0, R16, 6, "si", +0, R16, 7, "di", +0, R8, 0, "al", +0, R8, 1, "cl", +0, R8, 2, "dl", +0, R8, 3, "bl", +0, R8, 4, "ah", +0, R8, 5, "ch", +0, R8, 6, "dh", +0, R8, 7, "bh", +0, RSEG, 0, "es", +0, RSEG, 1, "cs", +0, RSEG, 2, "ss", +0, RSEG, 3, "ds", +0, PREFIX, 046, "eseg", +0, PREFIX, 056, "cseg", +0, PREFIX, 066, "sseg", +0, PREFIX, 076, "dseg", +0, PREFIX, 0360, "lock", +0, PREFIX, 0362, "rep", +0, PREFIX, 0362, "repne", +0, PREFIX, 0362, "repnz", +0, PREFIX, 0363, "repe", +0, PREFIX, 0363, "repz", +0, NOOP_1, 047, "daa", +0, NOOP_1, 057, "das", +0, NOOP_1, 067, "aaa", +0, NOOP_1, 077, "aas", +0, NOOP_1, 0220, "nop", +0, NOOP_1, 0230, "cbw", +0, NOOP_1, 0231, "cwd", +0, NOOP_1, 0233, "wait", +0, NOOP_1, 0234, "pushf", +0, NOOP_1, 0235, "popf", +0, NOOP_1, 0236, "sahf", +0, NOOP_1, 0237, "lahf", +0, NOOP_1, 0244, "movsb", +0, NOOP_1, 0245, "movs", +0, NOOP_1, 0246, "cmpsb", +0, NOOP_1, 0247, "cmps", +0, NOOP_1, 0252, "stosb", +0, NOOP_1, 0253, "stos", +0, NOOP_1, 0254, "lodsb", +0, NOOP_1, 0255, "lods", +0, NOOP_1, 0256, "scasb", +0, NOOP_1, 0257, "scas", +0, NOOP_1, 0316, "into", +0, NOOP_1, 0317, "iret", +0, NOOP_1, 0327, "xlat", +0, NOOP_1, 0364, "hlt", +0, NOOP_1, 0365, "cmc", +0, NOOP_1, 0370, "clc", +0, NOOP_1, 0371, "stc", +0, NOOP_1, 0372, "cli", +0, NOOP_1, 0373, "sti", +0, NOOP_1, 0374, "cld", +0, NOOP_1, 0375, "std", +0, NOOP_2, 0324+012<<8, "aam", +0, NOOP_2, 0325+012<<8, "aad", +0, JOP, 0340, "loopne", +0, JOP, 0340, "loopnz", +0, JOP, 0341, "loope", +0, JOP, 0341, "loopz", +0, JOP, 0342, "loop", +0, JOP, 0343, "jcxz", +0, JOP, 0160, "jo", +0, JOP, 0161, "jno", +0, JOP, 0162, "jb", +0, JOP, 0162, "jnae", +0, JOP, 0163, "jae", +0, JOP, 0163, "jnb", +0, JOP, 0164, "je", +0, JOP, 0164, "jz", +0, JOP, 0165, "jne", +0, JOP, 0165, "jnz", +0, JOP, 0166, "jbe", +0, JOP, 0166, "jna", +0, JOP, 0167, "ja", +0, JOP, 0167, "jnbe", +0, JOP, 0170, "js", +0, JOP, 0171, "jns", +0, JOP, 0172, "jp", +0, JOP, 0172, "jpe", +0, JOP, 0173, "jnp", +0, JOP, 0173, "jpo", +0, JOP, 0174, "jl", +0, JOP, 0174, "jnge", +0, JOP, 0175, "jge", +0, JOP, 0175, "jnl", +0, JOP, 0176, "jle", +0, JOP, 0176, "jng", +0, JOP, 0177, "jg", +0, JOP, 0177, "jnle", +0, PUSHOP, 0, "push", +0, PUSHOP, 1, "pop", +0, IOOP, 0344, "inb", +0, IOOP, 0345, "in", +0, IOOP, 0346, "outb", +0, IOOP, 0347, "out", +0, ADDOP, 000, "addb", +0, ADDOP, 001, "add", +0, ADDOP, 010, "orb", +0, ADDOP, 011, "or", +0, ADDOP, 020, "adcb", +0, ADDOP, 021, "adc", +0, ADDOP, 030, "sbbb", +0, ADDOP, 031, "sbb", +0, ADDOP, 040, "andb", +0, ADDOP, 041, "and", +0, ADDOP, 050, "subb", +0, ADDOP, 051, "sub", +0, ADDOP, 060, "xorb", +0, ADDOP, 061, "xor", +0, ADDOP, 070, "cmpb", +0, ADDOP, 071, "cmp", +0, ROLOP, 000, "rolb", +0, ROLOP, 001, "rol", +0, ROLOP, 010, "rorb", +0, ROLOP, 011, "ror", +0, ROLOP, 020, "rclb", +0, ROLOP, 021, "rcl", +0, ROLOP, 030, "rcrb", +0, ROLOP, 031, "rcr", +0, ROLOP, 040, "salb", +0, ROLOP, 040, "shlb", +0, ROLOP, 041, "sal", +0, ROLOP, 041, "shl", +0, ROLOP, 050, "shrb", +0, ROLOP, 051, "shr", +0, ROLOP, 070, "sarb", +0, ROLOP, 071, "sar", +0, INCOP, 000, "incb", +0, INCOP, 001, "inc", +0, INCOP, 010, "decb", +0, INCOP, 011, "dec", +0, NOTOP, 020, "notb", +0, NOTOP, 021, "not", +0, NOTOP, 030, "negb", +0, NOTOP, 031, "neg", +0, NOTOP, 040, "mulb", +0, NOTOP, 041, "mul", +0, NOTOP, 050, "imulb", +0, NOTOP, 051, "imul", +0, NOTOP, 060, "divb", +0, NOTOP, 061, "div", +0, NOTOP, 070, "idivb", +0, NOTOP, 071, "idiv", +0, CALLOP, 020+(0350<<8), "call", +0, CALLOP, 040+(0351<<8), "jmp", +0, CALFOP, 030+(0232<<8), "callf", +0, CALFOP, 050+(0352<<8), "jmpf", +0, LEAOP, 0215, "lea", +0, LEAOP, 0304, "les", +0, LEAOP, 0305, "lds", +0, ESC, 0, "esc", +0, INT, 0, "int", +0, RET, 0303, "ret", +0, RET, 0313, "retf", +0, XCHG, 0, "xchgb", +0, XCHG, 1, "xchg", +0, TEST, 0, "testb", +0, TEST, 1, "test", +0, MOV, 0, "movb", +0, MOV, 1, "mov", diff --git a/mach/i86/as/mach4.c b/mach/i86/as/mach4.c new file mode 100644 index 00000000..2a0c3534 --- /dev/null +++ b/mach/i86/as/mach4.c @@ -0,0 +1,132 @@ +#define RCSID4 "$Header$" + +/* + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. + * + * This product is part of the Amsterdam Compiler Kit. + * + * Permission to use, sell, duplicate or disclose this software must be + * obtained in writing. Requests for such permissions may be sent to + * + * Dr. Andrew S. Tanenbaum + * Wiskundig Seminarium + * Vrije Universiteit + * Postbox 7161 + * 1007 MC Amsterdam + * The Netherlands + * + */ + +operation + : prefix oper + ; +prefix : /* empty */ + | prefix PREFIX + { emit1($2);} + ; +oper : NOOP_1 + { emit1($1);} + | NOOP_2 + { emit2($1);} + | JOP expr + { branch($1,$2);} + | PUSHOP ea_1 + { pushop($1);} + | IOOP expr + { emit1($1); +#ifdef RELOCATION + newrelo($2.typ, RELO1); +#endif + emit1($2.val); + } + | IOOP R16 + { if ($2!=2) serror("register error"); + emit1($1+010); + } + | ADDOP ea_ea + { addop($1);} + | ROLOP ea_ea + { rolop($1);} + | INCOP ea_1 + { incop($1);} + | NOTOP ea_1 + { regsize($1); emit1(0366|($1&1)); ea_1($1&070);} + | CALLOP ea_1 + { callop($1&0xFFFF);} + | CALFOP expr ':' expr + { emit1($1>>8); +#ifdef RELOCATION + newrelo($4.typ, RELO2); +#endif + emit2($4.val); +#ifdef RELOCATION + newrelo($2.typ, RELO2); +#endif + emit2($2.val); + } + | CALFOP mem + { emit1(0377); ea_2($1&0xFF);} + | LEAOP R16 ',' mem + { emit1($1); ea_2($2<<3);} + | ESC absexp ',' mem + { fit(fit6($2)); + emit1(0330 | $2>>3); + ea_2(($2&7)<<3); + } + | INT absexp + { if ($2==3) + emit1(0314); + else { + emit1(0315); emit1($2); + } + } + | RET + { emit1($1);} + | RET expr + { emit1($1-1); +#ifdef RELOCATION + newrelo($2.typ, RELO2); +#endif + emit2($2.val); + } + | XCHG ea_ea + { xchg($1);} + | TEST ea_ea + { test($1);} + | MOV ea_ea + { mov($1);} +mem : '(' expr ')' + { mrg_2 = 6; exp_2 = $2; + RELOMOVE(rel_2, relonami); + } + | bases + { exp_2.val = 0; exp_2.typ = S_ABS; indexed();} + | expr bases + { exp_2 = $1; indexed(); + RELOMOVE(rel_2, relonami); + } + ; +bases : '(' R16 ')' + { mrg_2 = sr_m[$2];} + | '(' R16 ')' '(' R16 ')' + { mrg_2 = dr_m[$2][$5];} + ; +ea_2 : mem + | R8 + { mrg_2 = $1 | 0300;} + | R16 + { mrg_2 = $1 | 0310;} + | RSEG + { mrg_2 = $1 | 020;} + | expr + { mrg_2 = 040; exp_2 = $1; + RELOMOVE(rel_2, relonami); + } + ; +ea_1 : ea_2 + { mrg_1 = mrg_2; exp_1 = exp_2; + RELOMOVE(rel_1, rel_2); + } + ; +ea_ea : ea_1 ',' ea_2 + ; diff --git a/mach/i86/as/mach5.c b/mach/i86/as/mach5.c new file mode 100644 index 00000000..ecb8bd15 --- /dev/null +++ b/mach/i86/as/mach5.c @@ -0,0 +1,266 @@ +#define RCSID5 "$Header$" + +/* + * INTEL 8086 special routines + */ + +ea_1(param) { + + if ((mrg_1 & 070) || (param & ~070)) + serror("bad operand"); + emit1(mrg_1 | param); + switch(mrg_1 >> 6) { + case 0: + if (mrg_1 == 6) { +#ifdef RELOCATION + RELOMOVE(relonami, rel_1); + newrelo(exp_1.typ, RELO2); +#endif + emit2(exp_1.val); + } + break; + case 1: +#ifdef RELOCATION + RELOMOVE(relonami, rel_1); + newrelo(exp_1.typ, RELO1); +#endif + emit1(exp_1.val); + break; + case 2: +#ifdef RELOCATION + RELOMOVE(relonami, rel_1); + newrelo(exp_1.typ, RELO2); +#endif + emit2(exp_1.val); + break; + } +} + +ea_2(param) { + + mrg_1 = mrg_2; + exp_1 = exp_2; + RELOMOVE(rel_1, rel_2); + ea_1(param); +} + +reverse() { + register m, r; expr_t e; + + m = mrg_1; mrg_1 = mrg_2; mrg_2 = m; + e = exp_1; exp_1 = exp_2; exp_2 = e; +#ifndef ASLD + r = rel_1; rel_1 = rel_2; rel_2 = r; +#endif +} + +badsyntax() { + + serror("bad operands"); +} + +regsize(sz) register sz; { + register bit; + + sz <<= 3; + bit = 010; + sz &= bit; + if ((mrg_1 >= 0300 && (mrg_1 & bit) != sz) || + (mrg_2 >= 0300 && (mrg_2 & bit) != sz)) + serror("register error"); + mrg_1 &= ~bit; + mrg_2 &= ~bit; +} + +indexed() { + + if (mrg_2 & ~7) + serror("register error"); + if (exp_2.typ != S_ABS || fitb(exp_2.val) == 0) + mrg_2 |= 0200; + else if (exp_2.val != 0 || mrg_2 == 6) + mrg_2 |= 0100; +} + +branch(opc,exp) register opc; expr_t exp; { + register sm,dist; + int saving; + + dist = exp.val - (DOTVAL + 2); + if (pass == PASS_2 && dist > 0 && !(exp.typ & S_DOT)) + dist -= DOTGAIN; + sm = fitb(dist); + if ((exp.typ & ~S_DOT) != DOTTYP) + sm = 0; + if ((opc & 0370) == 0340) { + fit(sm); + sm = 1; + } else { + saving = opc == 0353 ? 1 : 3; + if ((sm = small(sm,saving)) == 0) { + if (opc != 0353) { + emit1(opc^1); + emit1(3); + dist -= 2; + } + opc = 0351; + dist--; + } + } + emit1(opc); + if (sm == 0) { +#ifdef RELOCATION + newrelo(exp.typ, RELPC | RELO2); +#endif + emit2(dist); + } else + emit1(dist); +} + +pushop(opc) register opc; { + + regsize(1); + if (mrg_1 & 020) { + if ( (mrg_1&3) == 1 && opc==1 ) badsyntax() ; + emit1(6 | opc | (mrg_1&3)<<3); + } else if (mrg_1 >= 0300) { + emit1(0120 | opc<<3 | (mrg_1&7)); + } else if (opc == 0) { + emit1(0377); ea_1(6<<3); + } else { + emit1(0217); ea_1(0<<3); + } +} + +addop(opc) register opc; { + + regsize(opc); + if (mrg_2 >= 0300) { + emit1(opc); ea_1((mrg_2&7)<<3); + } else if ((mrg_2 & 040) && mrg_1 == 0300) { + emit1(opc | 4); emitx((opc&1)+1,exp_2.val); + } else if (mrg_2 & 040) { + if ((opc&1) == 0) { + emit1(0200); + } else if (exp_2.typ != S_ABS || fitb(exp_2.val) == 0 || + opc==011 || opc==041 || opc==061 ) { + emit1(0201); + } else { + emit1(0203); opc &= ~1; + } + ea_1(opc & 070); emitx((opc&1)+1,exp_2.val); + } else if (mrg_1 >= 0300) { + emit1(opc | 2); ea_2((mrg_1&7)<<3); + } else + badsyntax(); +} + +rolop(opc) register opc; { + register cmrg; + + cmrg = mrg_2; + mrg_2 = mrg_1; + regsize(opc); + if (cmrg == 0301) { + emit1(0322 | (opc&1)); ea_1(opc&070); + } else if ((cmrg & 040) && exp_2.val == 1) { + emit1(0320 | (opc&1)); ea_1(opc&070); + } else + badsyntax(); +} + +incop(opc) register opc; { + + regsize(opc); + if ((opc&1) && mrg_1>=0300) { + emit1(0100 | (opc&010) | (mrg_1&7)); + } else { + emit1(0376 | (opc&1)); + ea_1(opc & 010); + } +} + +callop(opc) register opc; { + + regsize(1); + if (mrg_1 & 040) { + if (opc == (040+(0351<<8))) { + branch(0353,exp_1); + } else { + exp_1.val -= (DOTVAL+3); + emit1(opc>>8); +#ifdef RELOCATION + RELOMOVE(relonami, rel_1); + newrelo(exp_1.typ, RELPC | RELO2); +#endif + emit2(exp_1.val); + } + } else { + emit1(0377); ea_1(opc&070); + } +} + +xchg(opc) register opc; { + + regsize(opc); + if (mrg_2 == 0300 || mrg_1 < 0300) + reverse(); + if (opc == 1 && mrg_1 == 0300 && mrg_2 >= 0300) { + emit1(0220 | (mrg_2&7)); + } else if (mrg_1 >= 0300) { + emit1(0206 | opc); ea_2((mrg_1&7)<<3); + } else + badsyntax(); +} + +test(opc) register opc; { + + regsize(opc); + if ((mrg_1 & 040) || mrg_2 >= 0300) + reverse(); + if ((mrg_2 & 040) && mrg_1 == 0300) { + emit1(0250 | opc); emitx((opc&1)+1,exp_2.val); + } else if (mrg_2 & 040) { + emit1(0366 | opc); ea_1(0<<3); emitx((opc&1)+1,exp_2.val); + } else if (mrg_1 >= 0300) { + emit1(0204 | opc); ea_2((mrg_1&7)<<3); + } else + badsyntax(); +} + +mov(opc) register opc; { + + regsize(opc); + if (mrg_1 & 020) { + emit1(0216); ea_2((mrg_1&3)<<3); + } else if (mrg_2 & 020) { + emit1(0214); ea_1((mrg_2&3)<<3); + } else if (mrg_2 & 040) { + if (mrg_1 >= 0300) { + emit1(0260 | opc<<3 | (mrg_1&7)); + emitx((opc&1)+1,exp_2.val); + } else { + emit1(0306 | opc); ea_1(0<<3); + emitx((opc&1)+1,exp_2.val); + } + } else if (mrg_2 == 0300 && mrg_1 == 6) { + emit1(0242 | opc); +#ifdef RELOCATION + RELOMOVE(relonami, rel_1); + newrelo(exp_1.typ, RELO2); +#endif + emit2(exp_1.val); + } else if (mrg_1 == 0300 && mrg_2 == 6) { + emit1(0240 | opc); +#ifdef RELOCATION + RELOMOVE(relonami, rel_1); + newrelo(exp_1.typ, RELO2); +#endif + emit2(exp_2.val); + } else if (mrg_2 >= 0300) { + emit1(0210 | opc); ea_1((mrg_2&7)<<3); + } else if (mrg_1 >= 0300) { + emit1(0212 | opc); ea_2((mrg_1&7)<<3); + } else + badsyntax(); +} diff --git a/mach/s2650/as/mach0.c b/mach/s2650/as/mach0.c new file mode 100644 index 00000000..6a2eda23 --- /dev/null +++ b/mach/s2650/as/mach0.c @@ -0,0 +1,11 @@ +#define DUK +#define RCSID0 "$Header$" + +/* + * Signetics 2650 options + */ +#define LISTING +#define BYTES_REVERSED +#define THREE_PASS +#define RELOCATION +#define NOLD diff --git a/mach/s2650/as/mach1.c b/mach/s2650/as/mach1.c new file mode 100644 index 00000000..934c7ba5 --- /dev/null +++ b/mach/s2650/as/mach1.c @@ -0,0 +1,20 @@ +#define RCSID1 "$Header$" + +/* + * Signetics 2650 register names + */ + +#define R0 0 +#define R1 1 +#define R2 2 +#define R3 3 + +#define low7(z) (z & 0x7F) +#define low13(z) (z & 0x1FFF) + +#define fit7(z) (low7(z) == z) +#define fit13(z) (low13(z) == z) + +extern expr_t par_exp; +extern unsigned p_indirect; +extern int p_indexed; diff --git a/mach/s2650/as/mach2.c b/mach/s2650/as/mach2.c new file mode 100644 index 00000000..a3150449 --- /dev/null +++ b/mach/s2650/as/mach2.c @@ -0,0 +1,23 @@ +#define RCSID2 "$Header$" + +/* + * Signetics 2650 tokens + */ +%token REG +%token NOOP +%token CC +%token INDE +%token ZERO +%token ZEROX +%token IMMED +%token REL +%token ABSO +%token PSWM +%token RET +%token BRANCR +%token BRANCRX +%token BRANCA +%token BRANCAX +%token BRANRA +%token ZBRR +%token BXSA diff --git a/mach/s2650/as/mach3.c b/mach/s2650/as/mach3.c new file mode 100644 index 00000000..53bd5408 --- /dev/null +++ b/mach/s2650/as/mach3.c @@ -0,0 +1,90 @@ +#define RCSID3 "$Header$" + +/* + * Signetics 2650 keywords + */ +0, REG, R0, "r0", +0, REG, R1, "r1", +0, REG, R2, "r2", +0, REG, R3, "r3", +0, CC, 0, "eq", +0, CC, 0, "z", +0, CC, 1, "gt", +0, CC, 2, "lt", +0, CC, 3, "un", +0, INDE, 0x6000, "i", +0, ZERO, 0x0, "lodz", +0, ZERO, 0x80, "addz", +0, ZERO, 0xA0, "subz", +0, ZERO, 0x94, "dar", +0, ZEROX, 0x40, "andz", +0, ZERO, 0x60, "iorz", +0, ZERO, 0x20, "eorz", +0, ZERO, 0xE0, "comz", +0, ZERO, 0xF0, "wrtd", +0, ZERO, 0x70, "redd", +0, ZERO, 0xB0, "wrtc", +0, ZERO, 0x30, "redc", +0, ZERO, 0x50, "rrr", +0, ZERO, 0xD0, "rrl", +0, ZEROX, 0xC0, "strz", +0, IMMED, 0x04, "lodi", +0, IMMED, 0x84, "addi", +0, IMMED, 0xA4, "subi", +0, IMMED, 0x44, "andi", +0, IMMED, 0x64, "iori", +0, IMMED, 0x24, "eori", +0, IMMED, 0xE4, "comi", +0, IMMED, 0xD4, "wrte", +0, IMMED, 0x54, "rede", +0, IMMED, 0xF4, "tmi", +0, NOOP, 0x1E, "halt", +0, NOOP, 0xC0, "nop", +0, NOOP, 0x92, "lpsu", +0, NOOP, 0x93, "lpsl", +0, NOOP, 0x12, "spsu", +0, NOOP, 0x13, "spsl", +0, REL, 0x08, "lodr", +0, REL, 0xC8, "strr", +0, REL, 0x98, "addr", +0, REL, 0xA8, "subr", +0, REL, 0x48, "andr", +0, REL, 0x68, "iorr", +0, REL, 0x28, "eorr", +0, REL, 0xE8, "comr", +0, ABSO, 0x0C, "loda", +0, ABSO, 0xCC, "stra", +0, ABSO, 0x8C, "adda", +0, ABSO, 0xAC, "suba", +0, ABSO, 0x4C, "anda", +0, ABSO, 0x6C, "iora", +0, ABSO, 0x2C, "eora", +0, ABSO, 0xEC, "coma", +0, PSWM, 0x74, "cpsu", +0, PSWM, 0x75, "cpsl", +0, PSWM, 0x76, "ppsu", +0, PSWM, 0x77, "ppsl", +0, PSWM, 0xB4, "tpsu", +0, PSWM, 0xB5, "tpsl", +0, RET, 0x14, "retc", +0, RET, 0x34, "rete", +0, BRANCR, 0x18, "bctr", +0, BRANCRX, 0x98, "bcfr", +0, REL, 0x58, "brnr", +0, REL, 0xD8, "birr", +0, REL, 0xF8, "bdrr", +0, BRANCR, 0x38, "bstr", +0, BRANCRX, 0xB8, "bsfr", +0, REL, 0x78, "bsnr", +0, BRANCA, 0x1E, "bcta", +0, BRANCAX, 0x9E, "bcfa", +0, BRANRA, 0x5E, "brna", +0, BRANRA, 0xDE, "bira", +0, BRANRA, 0xFE, "bdra", +0, BRANCA, 0x3E, "bsta", +0, BRANCAX, 0xBE, "bsfa", +0, BRANRA, 0x7E, "bsna", +0, ZBRR, 0x9B, "zbrr", +0, ZBRR, 0xBB, "zbsr", +0, BXSA, 0x9F, "bxa", +0, BXSA, 0xBF, "bsxa", diff --git a/mach/s2650/as/mach4.c b/mach/s2650/as/mach4.c new file mode 100644 index 00000000..b24f3043 --- /dev/null +++ b/mach/s2650/as/mach4.c @@ -0,0 +1,139 @@ +#define RCSID4 "$Header$" + +/* + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. + * + * This product is part of the Amsterdam Compiler Kit. + * + * Permission to use, sell, duplicate or disclose this software must be + * obtained in writing. Requests for such permissions may be sent to + * + * Dr. Andrew S. Tanenbaum + * Wiskundig Seminarium + * Vrije Universiteit + * Postbox 7161 + * 1007 MC Amsterdam + * The Netherlands + * + */ + +/* Author: Leo van Moergestel */ + +/* + * Signetics 2650 parsing rules + */ +operation: + NOOP + { emit1($1);} + | + ZERO ',' REG + { emit1($1 | $3); } + | + IMMED ',' REG expr + { emit1($1 | $3); page(); +#ifdef RELOCATION + newrelo($4.typ, RELO1); +#endif + emit1($4.val); + } + | + REL ',' REG expr + { emit1($1 | $3); rela($4, 0);} + | + REL ',' REG '*' expr + { emit1($1 | $3); rela($5, 0x80);} + | + ZEROX ',' REG + { if ($3 == R0) + serror("register error"); + emit1($1 | $3); + } + | + ABSO ',' REG param + { emit1($1 | $3); + absoa(par_exp, p_indexed, p_indirect); + } + | + PSWM expr + { emit1($1); page(); +#ifdef RELOCATION + newrelo($2.typ, RELO1); +#endif + emit1($2.val); + } + | + RET ',' CC + { emit1($1 | $3);} + | + BRANCR ',' CC expr + { emit1($1 | $3); rela($4, 0);} + | + BRANCR ',' CC '*' expr + { emit1($1 | $3); rela($5, 0x80);} + | + BRANCRX ',' CC expr + { if($3 == 3) + serror("wrong condition"); + emit1($1 | $3); rela($4, 0);} + | + BRANCRX ',' CC '*' expr + { if($3 == 3) + serror("wrong condition"); + emit1($1 | $3); rela($5, 0x80);} + | + BRANCA ',' CC expr + { emit1($1 | $3); absob($4, 0);} + | + BRANCA ',' CC '*' expr + { emit1($1 | $3); absob($5, 0x8000);} + | + BRANCAX ',' CC expr + { if($3 == 3) + serror("wrong condition"); + emit1($1 | $3); absob($4, 0);} + | + BRANCAX ',' CC '*' expr + { if($3 == 3) + serror("wrong condition"); + emit1($1 | $3); absob($5, 0x8000);} + | + BRANRA ',' REG expr + { emit1($1 | $3); absob($4, 0);} + | + BRANRA ',' REG '*' expr + { emit1($1 | $3); absob($5, 0x8000);} + | + ZBRR expr + { emit1($1); rela($2, 0);} + | + ZBRR '*' expr + { emit1($1); rela($3, 0x80);} + | + BXSA expr + { emit1($1); absob($2, 0);} + | + BXSA '*' expr + { emit1($1); absob($3, 0x8000);} + ; + +param: + indir_opt + { p_indexed = 0;} + | + indir_opt ',' INDE + { p_indexed = 0x6000;} + | + indir_opt ',' '+' + { p_indexed = 0x2000;} + | + indir_opt ',' '-' + { p_indexed = 0x4000;} + ; + +indir_opt: + expr + { par_exp = $1; p_indirect = 0;} + | + '*' expr + { par_exp = $2; p_indirect = 0x8000;} + ; diff --git a/mach/s2650/as/mach5.c b/mach/s2650/as/mach5.c new file mode 100644 index 00000000..670255dc --- /dev/null +++ b/mach/s2650/as/mach5.c @@ -0,0 +1,86 @@ +#define RCSID5 "$Header$" + +/* + * Signetics 2650 special routines + */ + +#define MASK 0x6000 +#define MASK1 0x1FFF +#define MASK2 0x1FFE + +page() + { + if(((DOTVAL - 1) & MASK1) == MASK1) + serror("page violation"); + } + +pag2() + { + if(((DOTVAL - 1) & MASK1) >= MASK2) + serror("page violation"); + } + +rela(exp,ind) +expr_t exp; +int ind; + { + int c, d; + page(); + if(pass == PASS_3){ +#ifdef ASLD + if((DOTVAL & MASK) != (exp.val & MASK)) + serror("relative address outside page"); +#endif + d = low13(DOTVAL); + c = low13(exp.val); +#ifdef ASLD + /* + * I (Duk Bekema) think the next two if's are meant to + * handle wrap around, but the original author didn't give + * any comment here and I don't know anything about the + * Signetics 2650. + */ + if(c - d > 0x1F80) + d |= 0x2000; + if(d - c > 0x1F80) + c |= 0x2000; +#endif + c -= d + 1; + fit(fit7(c)); + } +#ifdef RELOCATION + newrelo(exp.typ, RELPC | RELO1); +#endif + emit1(low7(c) | ind); +} + +absoa(exp, ix, ind) +expr_t exp; +int ix; +unsigned ind; + { + pag2(); +#ifdef ASLD + if(pass == PASS_3 && (exp.val & MASK) != (DOTVAL & MASK)) + serror("page violation"); +#endif +#ifdef RELOCATION + newrelo(exp.typ, RELO2 | RELBR); +#endif + emit2(low13(exp.val) | ind | ix); +} + +absob(exp, ind) +expr_t exp; +unsigned ind; + { + pag2(); +#ifdef ASLD + if (exp.val < 0) + serror("branch to nonexistent memory"); +#endif +#ifdef RELOCATION + newrelo(exp.typ, RELO2 | RELBR); +#endif + emit2(exp.val | ind); +} diff --git a/mach/z80/as/mach0.c b/mach/z80/as/mach0.c new file mode 100644 index 00000000..e7718347 --- /dev/null +++ b/mach/z80/as/mach0.c @@ -0,0 +1,10 @@ +#define DUK +#define RCSID0 "$Header$" + +/* + * Zilog Z80 options + */ +#define THREE_PASS /* distinguish short and long branches */ +#define LISTING /* enable listing facilities */ +#define RELOCATION +#define NOLD diff --git a/mach/z80/as/mach1.c b/mach/z80/as/mach1.c new file mode 100644 index 00000000..1b1e2678 --- /dev/null +++ b/mach/z80/as/mach1.c @@ -0,0 +1,32 @@ +#define RCSID1 "$Header$" + +/* + * Zilog Z80 dependent C declarations. + */ + +#define B 0 +#define C 1 +#define D 2 +#define E 3 +#define H 4 +#define L 5 +#define F 6 +#define A 7 +#define I 8 +#define R 9 +#define BC 0 +#define DE 1 +#define HL 2 +#define SP 3 +#define AF 4 +#define AF2 5 +#define IX 6 +#define IY 7 + +#define low3(z) ((z) & 07) +#define fit3(z) (low3(z) == (z)) + +extern expr_t exp_ind; +#ifndef ASLD +extern int rel_ind; +#endif diff --git a/mach/z80/as/mach2.c b/mach/z80/as/mach2.c new file mode 100644 index 00000000..d1290b3e --- /dev/null +++ b/mach/z80/as/mach2.c @@ -0,0 +1,30 @@ +#define RCSID2 "$Header$" + +/* + * Zilog Z80 tokens + */ +%token R8 +%token R16 +%token CC +%token NOOPOP +%token E_ED +%token LDOP +%token PSHPOP +%token EXOP +%token ADDOP +%token ADCSBC +%token INCDEC +%token ARI8 +%token IMOP +%token ROTATE +%token BITS +%token JP +%token JR +%token DJNZ +%token CALL +%token RET +%token RST +%token IN +%token OUT + +%type ari8 r8 indir index ind coco diff --git a/mach/z80/as/mach3.c b/mach/z80/as/mach3.c new file mode 100644 index 00000000..8ebf1656 --- /dev/null +++ b/mach/z80/as/mach3.c @@ -0,0 +1,98 @@ +#define RCSID3 "$Header$" + +/* + * Zilog Z80 keywords + */ + +0, R8, B, "b", +0, R8, C, "c", +0, R8, D, "d", +0, R8, E, "e", +0, R8, H, "h", +0, R8, L, "l", +0, R8, F, "f", +0, R8, A, "a", +0, R8, I, "i", +0, R8, R, "r", +0, R16, BC, "bc", +0, R16, DE, "de", +0, R16, HL, "hl", +0, R16, SP, "sp", +0, R16, AF, "af", +0, R16, AF2, "af2", +0, R16, IX, "ix", +0, R16, IY, "iy", +0, CC, 0, "nz", +0, CC, 1, "z", +0, CC, 2, "nc", +0, CC, 4, "po", +0, CC, 5, "pe", +0, CC, 6, "p", +0, CC, 7, "m", +0, LDOP, 0, "ld", +0, PSHPOP, 0305, "push", +0, PSHPOP, 0301, "pop", +0, EXOP, 0343, "ex", +0, NOOPOP, 0331, "exx", +0, E_ED, 0240, "ldi", +0, E_ED, 0260, "ldir", +0, E_ED, 0250, "ldd", +0, E_ED, 0270, "lddr", +0, E_ED, 0241, "cpi", +0, E_ED, 0261, "cpir", +0, E_ED, 0251, "cpd", +0, E_ED, 0271, "cpdr", +0, ADDOP, 0200, "add", +0, ADCSBC, 0210, "adc", +0, ADCSBC, 0230, "sbc", +0, ARI8, 0220, "sub", +0, ARI8, 0240, "and", +0, ARI8, 0260, "or", +0, ARI8, 0250, "xor", +0, ARI8, 0270, "cp", +0, INCDEC, 04, "inc", +0, INCDEC, 05, "dec", +0, NOOPOP, 047, "daa", +0, NOOPOP, 057, "cpl", +0, E_ED, 0104, "neg", +0, NOOPOP, 077, "ccf", +0, NOOPOP, 067, "scf", +0, NOOPOP, 0, "nop", +0, NOOPOP, 0166, "halt", +0, NOOPOP, 0363, "di", +0, NOOPOP, 0373, "ei", +0, IMOP, 0106, "im", +0, NOOPOP, 07, "rlca", +0, NOOPOP, 027, "rla", +0, NOOPOP, 017, "rrca", +0, NOOPOP, 037, "rra", +0, ROTATE, 0, "rlc", +0, ROTATE, 020, "rl", +0, ROTATE, 010, "rrc", +0, ROTATE, 030, "rr", +0, ROTATE, 040, "sla", +0, ROTATE, 050, "sra", +0, ROTATE, 070, "srl", +0, E_ED, 0157, "rld", +0, E_ED, 0147, "rrd", +0, BITS, 0100, "bit", +0, BITS, 0200, "res", +0, BITS, 0300, "set", +0, JP, 0303, "jp", +0, JR, 030, "jr", +0, DJNZ, 020, "djnz", +0, CALL, 0315, "call", +0, RET, 0311, "ret", +0, E_ED, 0115, "reti", +0, E_ED, 0105, "retn", +0, RST, 0307, "rst", +0, IN, 0333, "in", +0, E_ED, 0242, "ini", +0, E_ED, 0262, "inir", +0, E_ED, 0252, "ind", +0, E_ED, 0272, "indr", +0, OUT, 0323, "out", +0, E_ED, 0243, "outi", +0, E_ED, 0263, "otir", +0, E_ED, 0253, "outd", +0, E_ED, 0273, "otdr", diff --git a/mach/z80/as/mach4.c b/mach/z80/as/mach4.c new file mode 100644 index 00000000..d3ee6917 --- /dev/null +++ b/mach/z80/as/mach4.c @@ -0,0 +1,343 @@ +#define RCSID4 "$Header$" + +/* + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. + * + * This product is part of the Amsterdam Compiler Kit. + * + * Permission to use, sell, duplicate or disclose this software must be + * obtained in writing. Requests for such permissions may be sent to + * + * Dr. Andrew S. Tanenbaum + * Wiskundig Seminarium + * Vrije Universiteit + * Postbox 7161 + * 1007 MC Amsterdam + * The Netherlands + * + */ + +/* + * Zilog Z80 parsing rules + */ +operation + : NOOPOP + { emit1($1);} + | LDOP ldargs + | PSHPOP R16 + { switch ($2) { + case BC: emit1($1); break; + case DE: emit1($1 | 020); break; + case AF: emit1($1 | 060); break; + case HL: + case IX: + case IY: xyreg($2,$1 | 040); break; + default: serror("register error"); + } + } + | EXOP R16 ',' R16 + { if ($2==DE && $4==HL) + emit1(0353); + else if ($2==AF && $4==AF2) + emit1(010); + else serror("register error"); + } + | EXOP '(' R16 ')' ',' R16 + { if ($3!=SP) serror("register error"); + xyreg($6,$1); + } + | E_ED + { emit1(0355); emit1($1);} + | ADDOP R16 ',' R16 + { if ($4 == $2) + xyreg($2,051); + else { + if ($4==HL || $4>SP) + serror("register error"); + xyreg($2,011 | $4<<4); + } + } + | ADCSBC R16 ',' R16 + { if ($2!=HL || $4>SP) serror("register error"); + emit1(0355); + emit1(($1==0210 ? 0112 : 0102) | ($4<<4)); + } + | INCDEC R16 + { switch ($2) { + case BC: case DE: case SP: + emit1(($1==04 ? 03 : 013) | $2<<4); + break; + case HL: case IX: case IY: + xyreg($2,$1==04 ? 043 : 053); + break; + default: serror("register error"); + } + } + | INCDEC r8 + { emit1($1 | $2<<3);} + | INCDEC ind + { xymem($2,$1 | 060);} + | ari8 r8 + { emit1($1 | $2);} + | ari8 expr + { emit1($1 | 0106); emit1($2.val);} + | ari8 ind + { xymem($2,$1 | 06);} + | IMOP absexp + { emit1(0355); + switch ($2) { + case 0: emit1(0106); break; + case 1: emit1(0126); break; + case 2: emit1(0136); break; + default: serror("range 0..2"); + } + } + | ROTATE r8 + { emit1(0313); emit1($1 | $2);} + | ROTATE ind + { xymem($2,0313); emit1($1 | 06);} + | BITS absexp ',' r8 + { fit(fit3($2.val)); + emit1(0313); emit1($1 | low3($2)<<3 | $4); + } + | BITS absexp ',' ind + { fit(fit3($2)); + xymem($4,0313); + emit1($1 | low3($2)<<3 | 06); + } + | JP expr + { emit1($1); +#ifdef RELOCATION + newrelo($2.typ, RELO2); +#endif + emit2($2.val); + } + | JP coco ',' expr + { emit1(0302 | $2<<3); +#ifdef RELOCATION + newrelo($4.typ, RELO2); +#endif + emit2($4.val); + } + | JP indir + { xyreg($2,0351);} + | JR expr + { branch($1,$2);} + | JR coco ',' expr + { if ($2 > 3) serror("bad condition code"); + branch(040 | ($2<<3), $4); + } + | DJNZ expr + { branch($1,$2);} + | CALL expr + { emit1($1); +#ifdef RELOCATION + newrelo($2.typ, RELO2); +#endif + emit2($2.val); + } + | CALL coco ',' expr + { emit1(0304 | $2<<3); +#ifdef RELOCATION + newrelo($4.typ, RELO2); +#endif + emit2($4.val); + } + | RET + { emit1($1);} + | RET coco + { emit1(0300 | $2<<3);} + | RST absexp + { if (($2&070)!=$2) + serror("rst expression out of range"); + emit1($1 | $2); + } + | IN R8 ',' expr + { if ($2 != A) serror("register error"); + emit1($1); +#ifdef RELOCATION + newrelo($4.typ, RELO1); +#endif + emit1($4.val); + } + | IN R8 ',' R8 + { if ($4 != C) serror("register error"); + emit1(0355); emit1(0100 | $2<<3); + } + | OUT expr ',' R8 + { if ($4 != A) serror("register error"); + emit1($1); +#ifdef RELOCATION + newrelo($2.typ, RELO1); +#endif + emit1($2.val); + } + | OUT R8 ',' R8 + { if ($2 != C) serror("register error"); + emit1(0355); emit1(0101 | $4<<3); + } + ; +ari8 : ARI8 + | ADDOP R8 ',' + { if ($2 != A) serror("register error");} + | ADCSBC R8 ',' + { if ($2 != A) serror("register error");} + ; +ldargs : R8 ',' R8 + { if ($1==F || $3==F) serror("register error"); + if ($1<=A && $3<=A) + emit1(0100 | $1<<3 | $3); + else { + emit1(0355); + if ((($1==A) ^ ($3==A)) == 0) + serror("register error"); + emit1( 0107 | + ($1==R||$3==R)<<3 | + ($1==A)<<4 + ); + } + } + | R8 ',' expr + { if ($1==F || $1==I || $1==R) + serror("register error"); + emit1(06 | $1<<3); +#ifdef RELOCATION + newrelo($3.typ, RELO1); +#endif + emit1($3.val); + } + | R8 ',' indir + { if ($1==F || $1==I || $1==R) + serror("register error"); + if ($1==A && ($3==BC || $3==DE)) + emit1($3==BC ? 012 : 032); + else + xymem($3,0106 | $1<<3); + } + | R8 ',' index + { if ($1==F || $1==I || $1==R) + serror("register error"); + xymem($3,0106 | $1<<3); + } + | R8 ',' '(' expr ')' + { if ($1!=A) serror("register error"); + emit1(072); +#ifdef RELOCATION + newrelo($4.typ, RELO2); +#endif + emit2($4.val); + } + | indir ',' r8 + { if ($3==A && ($1==BC || $1==DE)) + emit1($1==BC ? 02 : 022); + else + xymem($1,0160 | $3); + } + | index ',' r8 + { xymem($1,0160 | $3);} + | indir ',' expr + { xymem($1,066); +#ifdef RELOCATION + newrelo($3.typ, RELO1); +#endif + emit1($3.val); + } + | index ',' expr + { xymem($1,066); +#ifdef RELOCATION + newrelo($3.typ, RELO1); +#endif + emit1($3.val); + } + | R16 ',' expr + { switch ($1) { + case BC: case DE: case HL: case SP: + emit1(01 | $1<<4); break; + case IX: case IY: + xyreg($1,041); break; + default: serror("register error"); + } +#ifdef RELOCATION + newrelo($3.typ, RELO2); +#endif + emit2($3.val); + } + | R16 ',' R16 + { if ($1!=SP) serror("register error"); + xyreg($3,0371); + } + | R16 ',' '(' expr ')' + { switch ($1) { + case BC: case DE: case SP: + emit1(0355); emit1(0113 | $1<<4); break; + case HL: case IX: case IY: + xyreg($1,052); break; + default: serror("register error"); + } +#ifdef RELOCATION + newrelo($4.typ, RELO2); +#endif + emit2($4.val); + } + | '(' expr ')' ',' R8 + { if ($5!=A) serror("register error"); + emit1(062); +#ifdef RELOCATION + newrelo($2.typ, RELO2); +#endif + emit2($2.val); + } + | '(' expr ')' ',' R16 + { switch ($5) { + case BC: case DE: case SP: + emit1(0355); emit1(0103 | $5<<4); break; + case HL: case IX: case IY: + xyreg($5,042); break; + default: serror("register error"); + } +#ifdef RELOCATION + newrelo($2.typ, RELO2); +#endif + emit2($2.val); + } + ; +r8 : R8 + { if ($1==F || $1==I || $1==R) + serror("register error"); + } + ; +indir : '(' R16 ')' + { if ($2>=SP && $2!=IX && $2!=IY) + serror("register error"); + exp_ind.typ = S_ABS; exp_ind.val = 0; + $$ = $2; + } + ; +index : '(' R16 '+' expr ')' + { if ($2!=IX && $2!=IY) serror("register error"); + exp_ind = $4; + RELOMOVE(rel_ind, relonami); + $$ = $2; + } + | '(' R16 '-' expr ')' + { +#ifdef ASLD + if ($2!=IX && $2!=IY) serror("register error"); + fit(fitb($4.val)); + exp_ind = $4; + RELOMOVE(rel_ind, relonami); + $$ = $2; +#else ASLD + serror("relocation error"); +#endif ASLD + } + ; +ind : indir + | index + ; +coco : CC + | R8 + { if ($1 != C) serror("bad condition code"); + $$ = 3; + } + ; diff --git a/mach/z80/as/mach5.c b/mach/z80/as/mach5.c new file mode 100644 index 00000000..99a7ec33 --- /dev/null +++ b/mach/z80/as/mach5.c @@ -0,0 +1,57 @@ +#define RCSID5 "$Header$" + +/* + * Zilog Z80 special routines + */ + +xyreg(r,byte) { + + if (r==IX) + emit1(0335); + else if (r==IY) + emit1(0375); + else if (r!=HL) + serror("register error"); + emit1(byte); +} + +xymem(r,byte) { + + xyreg(r,byte); + if (r != HL) { +#ifdef RELOCATION + RELOMOVE(relonami, rel_ind); + newrelo(exp_ind.typ, RELO1); +#endif + emit1(exp_ind.val); + } +} + +branch(opc,exp) register opc; expr_t exp; { + register sm,dist; + + dist = exp.val - (DOTVAL + 2); + if (pass == PASS_2 && dist > 0 && !(exp.typ & S_DOT)) + dist -= DOTGAIN; + sm = fitb(dist); + if ((exp.typ & ~S_DOT) != DOTTYP) + sm = 0; + if (opc == 020) { /* DJNZ must be short */ + fit(sm); + sm = 1; + } else if ((sm = small(sm,1)) == 0) { + if (opc == 030) /* 'JR exp' */ + opc = 0303; /* replace by 'JP exp' */ + else /* 'JR CC,exp' */ + opc ^= 0342; /* replace by 'JP CC,exp' */ + } + emit1(opc); + if (sm == 0) { +#ifdef RELOCATION + newrelo(exp.typ, RELPC | RELO2); +#endif + emit2(exp.val); + } else { + emit1(lowb(dist)); + } +} From 8e9fee915b15e8fd3342024de512044a75426a7c Mon Sep 17 00:00:00 2001 From: keie Date: Wed, 12 Jun 1985 10:31:28 +0000 Subject: [PATCH 0048/1625] Now using AALMAG instead of ARMAG for led libraries. --- util/led/save.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/led/save.c b/util/led/save.c index 26181996..b9483a40 100644 --- a/util/led/save.c +++ b/util/led/save.c @@ -23,7 +23,7 @@ savemagic() return; if ((p = core_alloc(ALLOMODL, (long)sizeof(ushort))) != (char *)0) { - *(ushort *)p = ARMAG; + *(ushort *)p = AALMAG; core_position += sizeof(ushort); } } From 505abd69c5c35327ec1d6f7ed642a415e148fae7 Mon Sep 17 00:00:00 2001 From: keie Date: Wed, 19 Jun 1985 13:42:49 +0000 Subject: [PATCH 0049/1625] *** empty log message *** --- lang/cem/ctest/Out4.nf.std | 828 +++++++++++++++++++++++++++++++++++++ lang/cem/ctest/Out4.std | 631 ++++++++++++++++++++++++++++ 2 files changed, 1459 insertions(+) create mode 100644 lang/cem/ctest/Out4.nf.std create mode 100644 lang/cem/ctest/Out4.std diff --git a/lang/cem/ctest/Out4.nf.std b/lang/cem/ctest/Out4.nf.std new file mode 100644 index 00000000..0bb40477 --- /dev/null +++ b/lang/cem/ctest/Out4.nf.std @@ -0,0 +1,828 @@ +Fri Mar 15 14:44:59 GMT 1985 +***** ctconv +acc -mm68k4 -DNOFLOAT conv.c +conv.c +"conv.c", line 48: warning: Overflow in constant expression +running conv.cem +comparing conv +2a3,4 +> (float) 12 = 12.000000 +> (int) 3.14 = 3 +11,$c13,$ +< char 255, int 255, unsigned 377, long 255 +< char 255, int 255, unsigned 377, long 255 +< From integer +< char 192, int -64, unsigned 37777777700, long -64 +< From long +< char 253, int -3, unsigned 37777777775, long -3 +< a[l] (l==3) -17 +< a[3l] -17 +--- +> float 127.000000 +> char 255, int 255, unsigned 377, long 255 +> float 255.000000 +> char 255, int 255, unsigned 377, long 255 +> float 255.000000 +> From integer +> char 192, int -64, unsigned 177700, long -64 +> float -64.000000 +> From long +> char 253, int -3, unsigned 177775, long -3 +> float -3.000000 +> From float +> char 121, int 121, unsigned 171, long 121, float 121.500000 +> char 0, int 0, unsigned 0, long 0, float 0.000100 +> int 32766, unsigned 77776, long 32766, float 32766.000000 +> long 1223432064, float 1223432064.000000 +> a[l] (l==3) -17 +> a[3l] -17 +***** ctdecl +acc -mm68k4 -DNOFLOAT decl.c +decl.c +running decl.cem +comparing decl +***** ctdivers +acc -mm68k4 -DNOFLOAT ops.c +ops.c +running ops.cem +comparing ops +24,39c24,39 +< u<<1 321632 +< u<<2 643464 +< u<<3 1507150 +< u<<4 3216320 +< u<<5 6434640 +< u<<6 15071500 +< u<<7 32163200 +< u<<8 64346400 +< u<<9 150715000 +< u<<10 321632000 +< u<<11 643464000 +< u<<12 1507150000 +< u<<13 3216320000 +< u<<14 6434640000 +< u<<15 15071500000 +< u<<16 32163200000 +--- +> u<<1 121632 +> u<<2 043464 +> u<<3 107150 +> u<<4 016320 +> u<<5 034640 +> u<<6 071500 +> u<<7 163200 +> u<<8 146400 +> u<<9 115000 +> u<<10 032000 +> u<<11 064000 +> u<<12 150000 +> u<<13 120000 +> u<<14 040000 +> u<<15 100000 +> u<<16 000000 +***** cterr +acc -mm68k4 -DNOFLOAT bugs.c +bugs.c +"bugs.c", line 98: warning: Overflow in constant expression +running bugs.cem +comparing bugs +***** ctest1 +acc -mm68k4 -DNOFLOAT test.c +test.c +running test.cem +comparing test +1,$c1,$ +< End of test program, 10 tests completed, 0 errors detected +--- +> End of test program, 11 tests completed, 0 errors detected +***** ctest2 +acc -mm68k4 -DNOFLOAT t7.c +t7.c +"t7.c", line 163: warning: statement not reached +"t7.c", line 180: warning: statement not reached +"t7.c", line 184: warning: statement not reached +"t7.c", line 188: warning: statement not reached +"t7.c", line 192: warning: statement not reached +"t7.c", line 196: warning: statement not reached +"t7.c", line 200: warning: statement not reached +"t7.c", line 207: warning: statement not reached +"t7.c", line 209: warning: statement not reached +"t7.c", line 213: warning: statement not reached +"t7.c", line 215: warning: statement not reached +"t7.c", line 289: warning: statement not reached +"t7.c", line 296: warning: statement not reached +"t7.c", line 302: warning: statement not reached +"t7.c", line 309: warning: statement not reached +"t7.c", line 345: warning: statement not reached +"t7.c", line 346: warning: statement not reached +"t7.c", line 347: warning: statement not reached +"t7.c", line 348: warning: statement not reached +"t7.c", line 350: warning: statement not reached +"t7.c", line 454: warning: statement not reached +"t7.c", line 563: warning: statement not reached +"t7.c", line 591: warning: statement not reached +running t7.cem +comparing t7 +***** ctest3 +acc -mm68k4 -DNOFLOAT test2.c +test2.c +running test2.cem +comparing test2 +***** ctest5 +acc -mm68k4 -DNOFLOAT test1.c +test1.c +"test1.c", line 386: warning: illegal pointer combination +"test1.c", line 387: warning: illegal pointer combination +"test1.c", line 388: warning: illegal pointer combination +"test1.c", line 400: warning: illegal pointer combination +"test1.c", line 423: warning: illegal pointer combination +"test1.c", line 424: warning: illegal pointer combination +"test1.c", line 425: warning: illegal pointer combination +"test1.c", line 437: warning: illegal pointer combination +running test1.cem +comparing test1 +1,$c1,$ +< program test1 +< 10 tests completed. Number of errors = 0 +--- +> error 13 in test 11 +> program test1 +> 11 tests completed. Number of errors = 1 +***** ctgen +sed -f bf.sed bf.c +acc -mm68k4 -DNOFLOAT bf.c +bf.c +running bf.cem +comparing bf +39c39 +< bfs.bf4 = ( bfs.bf1 - bfs.bf2 ) 65529 +--- +> bfs.bf4 = ( bfs.bf1 - bfs.bf2 ) -7 +50,52c50,52 +< bfs.bf4 = ( -bfs.bf1 ) 65535 +< bfs.bf4 = ( !bfs.bf1 ) 0 +< bfs.bf4 = ( ~bfs.bf1 ) 65534 +--- +> bfs.bf4 = ( -bfs.bf1 ) -1 +> bfs.bf4 = ( !bfs.bf1 ) 0 +> bfs.bf4 = ( ~bfs.bf1 ) -2 +sed -f cel.sed cel.c +acc -mm68k4 -DNOFLOAT cel.c +cel.c +running cel.cem +comparing cel +sed -f clu.sed clu.c +acc -mm68k4 -DNOFLOAT clu.c +clu.c +running clu.cem +comparing clu +23,31c23,31 +< x = 40000 40000 +< x += 40000 40010 +< x -= 40000 -39990 +< x /= 40000 0 +< x %= 40000 10 +< x *= 40000 400000 +< x &= 40000 0 +< x |= 40000 40010 +< x ^= 40000 40010 +--- +> x = 40000 -25536 +> x += 40000 -25526 +> x -= 40000 25546 +> x /= 40000 0 +> x %= 40000 10 +> x *= 40000 6784 +> x &= 40000 0 +> x |= 40000 -25526 +> x ^= 40000 -25526 +38c38 +< y = ( 40000 + 8012 ) 48012 +--- +> y = ( 40000 + 8012 ) -17524 +42,52c42,52 +< y = ( 40000 * 8012 ) 320480000 +< y = ( 40000 & 8012 ) 7232 +< y = ( 40000 | 8012 ) 40780 +< y = ( 40000 ^ 8012 ) 33548 +< y = ( 40000 || 8012 ) 1 +< y = ( 40000 && 8012 ) 1 +< y = ( 40000 << 9 ) 20480000 +< y = ( 40000 >> 9 ) 78 +< y = ( -40000 ) -40000 +< y = ( !40000 ) 0 +< y = ( ~40000 ) -40001 +--- +> y = ( 40000 * 8012 ) 8960 +> y = ( 40000 & 8012 ) 7232 +> y = ( 40000 | 8012 ) -24756 +> y = ( 40000 ^ 8012 ) -31988 +> y = ( 40000 || 8012 ) 1 +> y = ( 40000 && 8012 ) 1 +> y = ( 40000 << 9 ) -32768 +> y = ( 40000 >> 9 ) 78 +> y = ( -40000 ) 25536 +> y = ( !40000 ) 0 +> y = ( ~40000 ) 25535 +59,68c59,68 +< y = ( 40000 ? 40000 : 8012 ) 40000 +< y = ( x = 40000 ) 40000 40000 +< y = ( x += 40000 ) 40010 40010 +< y = ( x -= 40000 ) -39990 -39990 +< y = ( x /= 40000 ) 0 0 +< y = ( x %= 40000 ) 10 10 +< y = ( x *= 40000 ) 400000 400000 +< y = ( x &= 40000 ) 0 0 +< y = ( x |= 40000 ) 40010 40010 +< y = ( x ^= 40000 ) 40010 40010 +--- +> y = ( 40000 ? 40000 : 8012 ) -25536 +> y = ( x = 40000 ) -25536 -25536 +> y = ( x += 40000 ) -25526 -25526 +> y = ( x -= 40000 ) 25546 25546 +> y = ( x /= 40000 ) 0 0 +> y = ( x %= 40000 ) 10 10 +> y = ( x *= 40000 ) 6784 6784 +> y = ( x &= 40000 ) 0 0 +> y = ( x |= 40000 ) -25526 -25526 +> y = ( x ^= 40000 ) -25526 -25526 +97,105c97,105 +< yes if ( x = 40000 ) yes() ; else no() 40000 +< yes if ( x += 40000 ) yes() ; else no() 40010 +< yes if ( x -= 40000 ) yes() ; else no() -39990 +< no if ( x /= 40000 ) yes() ; else no() 0 +< yes if ( x %= 40000 ) yes() ; else no() 10 +< yes if ( x *= 40000 ) yes() ; else no() 400000 +< no if ( x &= 40000 ) yes() ; else no() 0 +< yes if ( x |= 40000 ) yes() ; else no() 40010 +< yes if ( x ^= 40000 ) yes() ; else no() 40010 +--- +> yes if ( x = 40000 ) yes() ; else no() -25536 +> yes if ( x += 40000 ) yes() ; else no() -25526 +> yes if ( x -= 40000 ) yes() ; else no() 25546 +> no if ( x /= 40000 ) yes() ; else no() 0 +> yes if ( x %= 40000 ) yes() ; else no() 10 +> yes if ( x *= 40000 ) yes() ; else no() 6784 +> no if ( x &= 40000 ) yes() ; else no() 0 +> yes if ( x |= 40000 ) yes() ; else no() -25526 +> yes if ( x ^= 40000 ) yes() ; else no() -25526 +sed -f ec.sed ec.c +acc -mm68k4 -DNOFLOAT ec.c +ec.c +"ec.c", line 58: warning: Overflow in constant expression +"ec.c", line 64: warning: Overflow in constant expression +running ec.cem +comparing ec +sed -f ef.sed ef.c +acc -mm68k4 -DNOFLOAT ef.c +ef.c +Warning : dummy float-constant(s) +running ef.cem +*** Error code 18 (ignored) +comparing ef +5,$c5,$ +< ef.c, line 13: trap 18 called +--- +> .4e-5 || .3e-5 +> .4e-5 && .3e-5 +> -.4e-5 +> !.4e-5 +> .4e-5 == .3e-5 +> .4e-5 != .3e-5 +> .4e-5 <= .3e-5 +> .4e-5 >= .3e-5 +> .4e-5 < .3e-5 +> .4e-5 > .3e-5 +> .4e-5 ? .4e-5 : .3e-5 +> x = .4e-5 4.000000e-06 +> x += .4e-5 3.141504e+00 +> x -= .4e-5 3.141496e+00 +> x /= .4e-5 7.853750e+05 +> x *= .4e-5 1.256600e-05 +> x ++ 4.141500e+00 +> x -- 2.141500e+00 +> -- x 2.141500e+00 +> ++ x 4.141500e+00 +> y = ( .4e-5 + .3e-5 ) 7.000000e-06 +> y = ( .4e-5 - .3e-5 ) 1.000000e-06 +> y = ( .4e-5 / .3e-5 ) 1.333333e+00 +> y = ( .4e-5 * .3e-5 ) 1.200000e-11 +> y = ( .4e-5 || .3e-5 ) 1.000000e+00 +> y = ( .4e-5 && .3e-5 ) 1.000000e+00 +> y = ( -.4e-5 ) -4.000000e-06 +> y = ( !.4e-5 ) 0.000000e+00 +> y = ( .4e-5 == .3e-5 ) 0.000000e+00 +> y = ( .4e-5 != .3e-5 ) 1.000000e+00 +> y = ( .4e-5 <= .3e-5 ) 0.000000e+00 +> y = ( .4e-5 >= .3e-5 ) 1.000000e+00 +> y = ( .4e-5 < .3e-5 ) 0.000000e+00 +> y = ( .4e-5 > .3e-5 ) 1.000000e+00 +> y = ( .4e-5 ? .4e-5 : .3e-5 ) 4.000000e-06 +> y = ( x = .4e-5 ) 4.000000e-06 4.000000e-06 +> y = ( x += .4e-5 ) 3.141504e+00 3.141504e+00 +> y = ( x -= .4e-5 ) 3.141496e+00 3.141496e+00 +> y = ( x /= .4e-5 ) 7.853750e+05 7.853750e+05 +> y = ( x *= .4e-5 ) 1.256600e-05 1.256600e-05 +> y = ( x ++ ) 4.141500e+00 3.141500e+00 +> y = ( x -- ) 2.141500e+00 3.141500e+00 +> y = ( -- x ) 2.141500e+00 2.141500e+00 +> y = ( ++ x ) 4.141500e+00 4.141500e+00 +> yes if ( .4e-5 + .3e-5 ) yes() ; else no() +> yes if ( .4e-5 - .3e-5 ) yes() ; else no() +> yes if ( .4e-5 / .3e-5 ) yes() ; else no() +> yes if ( .4e-5 * .3e-5 ) yes() ; else no() +> yes if ( .4e-5 || .3e-5 ) yes() ; else no() +> yes if ( .4e-5 && .3e-5 ) yes() ; else no() +> yes if ( -.4e-5 ) yes() ; else no() +> no if ( !.4e-5 ) yes() ; else no() +> no if ( .4e-5 == .3e-5 ) yes() ; else no() +> yes if ( .4e-5 != .3e-5 ) yes() ; else no() +> no if ( .4e-5 <= .3e-5 ) yes() ; else no() +> yes if ( .4e-5 >= .3e-5 ) yes() ; else no() +> no if ( .4e-5 < .3e-5 ) yes() ; else no() +> yes if ( .4e-5 > .3e-5 ) yes() ; else no() +> yes if ( .4e-5 ? .4e-5 : .3e-5 ) yes() ; else no() +> yes if ( x = .4e-5 ) yes() ; else no() 4.000000e-06 +> yes if ( x += .4e-5 ) yes() ; else no() 3.141504e+00 +> yes if ( x -= .4e-5 ) yes() ; else no() 3.141496e+00 +> yes if ( x /= .4e-5 ) yes() ; else no() 7.853750e+05 +> yes if ( x *= .4e-5 ) yes() ; else no() 1.256600e-05 +> yes if ( x ++ ) yes() ; else no() 4.141500e+00 +> yes if ( x -- ) yes() ; else no() 2.141500e+00 +> yes if ( -- x ) yes() ; else no() 2.141500e+00 +> yes if ( ++ x ) yes() ; else no() 4.141500e+00 +sed -f ei.sed ei.c +acc -mm68k4 -DNOFLOAT ei.c +ei.c +running ei.cem +comparing ei +32c32 +< x <<= 15 8355840 +--- +> x <<= 15 -32768 +48c48 +< y = ( 4 << 15 ) 131072 +--- +> y = ( 4 << 15 ) 0 +69c69 +< y = ( x <<= 15 ) 8355840 8355840 +--- +> y = ( x <<= 15 ) -32768 -32768 +85c85 +< yes if ( 4 << 15 ) yes() ; else no() +--- +> no if ( 4 << 15 ) yes() ; else no() +106c106 +< yes if ( x <<= 15 ) yes() ; else no() 8355840 +--- +> yes if ( x <<= 15 ) yes() ; else no() -32768 +sed -f el.sed el.c +acc -mm68k4 -DNOFLOAT el.c +el.c +running el.cem +comparing el +sed -f eu.sed eu.c +acc -mm68k4 -DNOFLOAT eu.c +eu.c +running eu.cem +comparing eu +23,31c23,31 +< x = 40000 40000 +< x += 40000 40010 +< x -= 40000 -39990 +< x /= 40000 0 +< x %= 40000 10 +< x *= 40000 400000 +< x &= 40000 0 +< x |= 40000 40010 +< x ^= 40000 40010 +--- +> x = 40000 -25536 +> x += 40000 -25526 +> x -= 40000 25546 +> x /= 40000 0 +> x %= 40000 10 +> x *= 40000 6784 +> x &= 40000 0 +> x |= 40000 -25526 +> x ^= 40000 -25526 +38c38 +< y = ( 40000 + 8012 ) 48012 +--- +> y = ( 40000 + 8012 ) -17524 +42,52c42,52 +< y = ( 40000 * 8012 ) 320480000 +< y = ( 40000 & 8012 ) 7232 +< y = ( 40000 | 8012 ) 40780 +< y = ( 40000 ^ 8012 ) 33548 +< y = ( 40000 || 8012 ) 1 +< y = ( 40000 && 8012 ) 1 +< y = ( 40000 << 9 ) 20480000 +< y = ( 40000 >> 9 ) 78 +< y = ( -40000 ) -40000 +< y = ( !40000 ) 0 +< y = ( ~40000 ) -40001 +--- +> y = ( 40000 * 8012 ) 8960 +> y = ( 40000 & 8012 ) 7232 +> y = ( 40000 | 8012 ) -24756 +> y = ( 40000 ^ 8012 ) -31988 +> y = ( 40000 || 8012 ) 1 +> y = ( 40000 && 8012 ) 1 +> y = ( 40000 << 9 ) -32768 +> y = ( 40000 >> 9 ) 78 +> y = ( -40000 ) 25536 +> y = ( !40000 ) 0 +> y = ( ~40000 ) 25535 +59,68c59,68 +< y = ( 40000 ? 40000 : 8012 ) 40000 +< y = ( x = 40000 ) 40000 40000 +< y = ( x += 40000 ) 40010 40010 +< y = ( x -= 40000 ) -39990 -39990 +< y = ( x /= 40000 ) 0 0 +< y = ( x %= 40000 ) 10 10 +< y = ( x *= 40000 ) 400000 400000 +< y = ( x &= 40000 ) 0 0 +< y = ( x |= 40000 ) 40010 40010 +< y = ( x ^= 40000 ) 40010 40010 +--- +> y = ( 40000 ? 40000 : 8012 ) -25536 +> y = ( x = 40000 ) -25536 -25536 +> y = ( x += 40000 ) -25526 -25526 +> y = ( x -= 40000 ) 25546 25546 +> y = ( x /= 40000 ) 0 0 +> y = ( x %= 40000 ) 10 10 +> y = ( x *= 40000 ) 6784 6784 +> y = ( x &= 40000 ) 0 0 +> y = ( x |= 40000 ) -25526 -25526 +> y = ( x ^= 40000 ) -25526 -25526 +97,105c97,105 +< yes if ( x = 40000 ) yes() ; else no() 40000 +< yes if ( x += 40000 ) yes() ; else no() 40010 +< yes if ( x -= 40000 ) yes() ; else no() -39990 +< no if ( x /= 40000 ) yes() ; else no() 0 +< yes if ( x %= 40000 ) yes() ; else no() 10 +< yes if ( x *= 40000 ) yes() ; else no() 400000 +< no if ( x &= 40000 ) yes() ; else no() 0 +< yes if ( x |= 40000 ) yes() ; else no() 40010 +< yes if ( x ^= 40000 ) yes() ; else no() 40010 +--- +> yes if ( x = 40000 ) yes() ; else no() -25536 +> yes if ( x += 40000 ) yes() ; else no() -25526 +> yes if ( x -= 40000 ) yes() ; else no() 25546 +> no if ( x /= 40000 ) yes() ; else no() 0 +> yes if ( x %= 40000 ) yes() ; else no() 10 +> yes if ( x *= 40000 ) yes() ; else no() 6784 +> no if ( x &= 40000 ) yes() ; else no() 0 +> yes if ( x |= 40000 ) yes() ; else no() -25526 +> yes if ( x ^= 40000 ) yes() ; else no() -25526 +sed -f lc.sed lc.c +acc -mm68k4 -DNOFLOAT lc.c +lc.c +"lc.c", line 60: warning: Overflow in constant expression +"lc.c", line 66: warning: Overflow in constant expression +running lc.cem +comparing lc +sed -f ld.sed ld.c +acc -mm68k4 -DNOFLOAT ld.c +ld.c +Warning : dummy float-constant(s) +running ld.cem +*** Error code 18 (ignored) +comparing ld +5,$c5,$ +< ld.c, line 13: trap 18 called +--- +> .4e-5 || .3e-5 +> .4e-5 && .3e-5 +> -.4e-5 +> !.4e-5 +> .4e-5 == .3e-5 +> .4e-5 != .3e-5 +> .4e-5 <= .3e-5 +> .4e-5 >= .3e-5 +> .4e-5 < .3e-5 +> .4e-5 > .3e-5 +> .4e-5 ? .4e-5 : .3e-5 +> x = .4e-5 4.000000e-06 +> x += .4e-5 3.141504e+00 +> x -= .4e-5 3.141496e+00 +> x /= .4e-5 7.853750e+05 +> x *= .4e-5 1.256600e-05 +> x ++ 4.141500e+00 +> x -- 2.141500e+00 +> -- x 2.141500e+00 +> ++ x 4.141500e+00 +> y = ( .4e-5 + .3e-5 ) 7.000000e-06 +> y = ( .4e-5 - .3e-5 ) 1.000000e-06 +> y = ( .4e-5 / .3e-5 ) 1.333333e+00 +> y = ( .4e-5 * .3e-5 ) 1.200000e-11 +> y = ( .4e-5 || .3e-5 ) 1.000000e+00 +> y = ( .4e-5 && .3e-5 ) 1.000000e+00 +> y = ( -.4e-5 ) -4.000000e-06 +> y = ( !.4e-5 ) 0.000000e+00 +> y = ( .4e-5 == .3e-5 ) 0.000000e+00 +> y = ( .4e-5 != .3e-5 ) 1.000000e+00 +> y = ( .4e-5 <= .3e-5 ) 0.000000e+00 +> y = ( .4e-5 >= .3e-5 ) 1.000000e+00 +> y = ( .4e-5 < .3e-5 ) 0.000000e+00 +> y = ( .4e-5 > .3e-5 ) 1.000000e+00 +> y = ( .4e-5 ? .4e-5 : .3e-5 ) 4.000000e-06 +> y = ( x = .4e-5 ) 4.000000e-06 4.000000e-06 +> y = ( x += .4e-5 ) 3.141504e+00 3.141504e+00 +> y = ( x -= .4e-5 ) 3.141496e+00 3.141496e+00 +> y = ( x /= .4e-5 ) 7.853750e+05 7.853750e+05 +> y = ( x *= .4e-5 ) 1.256600e-05 1.256600e-05 +> y = ( x ++ ) 4.141500e+00 3.141500e+00 +> y = ( x -- ) 2.141500e+00 3.141500e+00 +> y = ( -- x ) 2.141500e+00 2.141500e+00 +> y = ( ++ x ) 4.141500e+00 4.141500e+00 +> yes if ( .4e-5 + .3e-5 ) yes() ; else no() +> yes if ( .4e-5 - .3e-5 ) yes() ; else no() +> yes if ( .4e-5 / .3e-5 ) yes() ; else no() +> yes if ( .4e-5 * .3e-5 ) yes() ; else no() +> yes if ( .4e-5 || .3e-5 ) yes() ; else no() +> yes if ( .4e-5 && .3e-5 ) yes() ; else no() +> yes if ( -.4e-5 ) yes() ; else no() +> no if ( !.4e-5 ) yes() ; else no() +> no if ( .4e-5 == .3e-5 ) yes() ; else no() +> yes if ( .4e-5 != .3e-5 ) yes() ; else no() +> no if ( .4e-5 <= .3e-5 ) yes() ; else no() +> yes if ( .4e-5 >= .3e-5 ) yes() ; else no() +> no if ( .4e-5 < .3e-5 ) yes() ; else no() +> yes if ( .4e-5 > .3e-5 ) yes() ; else no() +> yes if ( .4e-5 ? .4e-5 : .3e-5 ) yes() ; else no() +> yes if ( x = .4e-5 ) yes() ; else no() 4.000000e-06 +> yes if ( x += .4e-5 ) yes() ; else no() 3.141504e+00 +> yes if ( x -= .4e-5 ) yes() ; else no() 3.141496e+00 +> yes if ( x /= .4e-5 ) yes() ; else no() 7.853750e+05 +> yes if ( x *= .4e-5 ) yes() ; else no() 1.256600e-05 +> yes if ( x ++ ) yes() ; else no() 4.141500e+00 +> yes if ( x -- ) yes() ; else no() 2.141500e+00 +> yes if ( -- x ) yes() ; else no() 2.141500e+00 +> yes if ( ++ x ) yes() ; else no() 4.141500e+00 +sed -f lf.sed lf.c +acc -mm68k4 -DNOFLOAT lf.c +lf.c +Warning : dummy float-constant(s) +running lf.cem +*** Error code 18 (ignored) +comparing lf +1,$c1,$ +< lf.c, line 8: trap 18 called +--- +> .4e-5 + .3e-5 +> .4e-5 - .3e-5 +> .4e-5 / .3e-5 +> .4e-5 * .3e-5 +> .4e-5 || .3e-5 +> .4e-5 && .3e-5 +> -.4e-5 +> !.4e-5 +> .4e-5 == .3e-5 +> .4e-5 != .3e-5 +> .4e-5 <= .3e-5 +> .4e-5 >= .3e-5 +> .4e-5 < .3e-5 +> .4e-5 > .3e-5 +> .4e-5 ? .4e-5 : .3e-5 +> x = .4e-5 4.000000e-06 +> x += .4e-5 3.141504e+00 +> x -= .4e-5 3.141496e+00 +> x /= .4e-5 7.853750e+05 +> x *= .4e-5 1.256600e-05 +> x ++ 4.141500e+00 +> x -- 2.141500e+00 +> -- x 2.141500e+00 +> ++ x 4.141500e+00 +> y = ( .4e-5 + .3e-5 ) 7.000000e-06 +> y = ( .4e-5 - .3e-5 ) 1.000000e-06 +> y = ( .4e-5 / .3e-5 ) 1.333333e+00 +> y = ( .4e-5 * .3e-5 ) 1.200000e-11 +> y = ( .4e-5 || .3e-5 ) 1.000000e+00 +> y = ( .4e-5 && .3e-5 ) 1.000000e+00 +> y = ( -.4e-5 ) -4.000000e-06 +> y = ( !.4e-5 ) 0.000000e+00 +> y = ( .4e-5 == .3e-5 ) 0.000000e+00 +> y = ( .4e-5 != .3e-5 ) 1.000000e+00 +> y = ( .4e-5 <= .3e-5 ) 0.000000e+00 +> y = ( .4e-5 >= .3e-5 ) 1.000000e+00 +> y = ( .4e-5 < .3e-5 ) 0.000000e+00 +> y = ( .4e-5 > .3e-5 ) 1.000000e+00 +> y = ( .4e-5 ? .4e-5 : .3e-5 ) 4.000000e-06 +> y = ( x = .4e-5 ) 4.000000e-06 4.000000e-06 +> y = ( x += .4e-5 ) 3.141504e+00 3.141504e+00 +> y = ( x -= .4e-5 ) 3.141496e+00 3.141496e+00 +> y = ( x /= .4e-5 ) 7.853750e+05 7.853750e+05 +> y = ( x *= .4e-5 ) 1.256600e-05 1.256600e-05 +> y = ( x ++ ) 4.141500e+00 3.141500e+00 +> y = ( x -- ) 2.141500e+00 3.141500e+00 +> y = ( -- x ) 2.141500e+00 2.141500e+00 +> y = ( ++ x ) 4.141500e+00 4.141500e+00 +> yes if ( .4e-5 + .3e-5 ) yes() ; else no() +> yes if ( .4e-5 - .3e-5 ) yes() ; else no() +> yes if ( .4e-5 / .3e-5 ) yes() ; else no() +> yes if ( .4e-5 * .3e-5 ) yes() ; else no() +> yes if ( .4e-5 || .3e-5 ) yes() ; else no() +> yes if ( .4e-5 && .3e-5 ) yes() ; else no() +> yes if ( -.4e-5 ) yes() ; else no() +> no if ( !.4e-5 ) yes() ; else no() +> no if ( .4e-5 == .3e-5 ) yes() ; else no() +> yes if ( .4e-5 != .3e-5 ) yes() ; else no() +> no if ( .4e-5 <= .3e-5 ) yes() ; else no() +> yes if ( .4e-5 >= .3e-5 ) yes() ; else no() +> no if ( .4e-5 < .3e-5 ) yes() ; else no() +> yes if ( .4e-5 > .3e-5 ) yes() ; else no() +> yes if ( .4e-5 ? .4e-5 : .3e-5 ) yes() ; else no() +> yes if ( x = .4e-5 ) yes() ; else no() 4.000000e-06 +> yes if ( x += .4e-5 ) yes() ; else no() 3.141504e+00 +> yes if ( x -= .4e-5 ) yes() ; else no() 3.141496e+00 +> yes if ( x /= .4e-5 ) yes() ; else no() 7.853750e+05 +> yes if ( x *= .4e-5 ) yes() ; else no() 1.256600e-05 +> yes if ( x ++ ) yes() ; else no() 4.141500e+00 +> yes if ( x -- ) yes() ; else no() 2.141500e+00 +> yes if ( -- x ) yes() ; else no() 2.141500e+00 +> yes if ( ++ x ) yes() ; else no() 4.141500e+00 +sed -f li.sed li.c +acc -mm68k4 -DNOFLOAT li.c +li.c +running li.cem +comparing li +32c32 +< x <<= 15 8355840 +--- +> x <<= 15 -32768 +48c48 +< y = ( 4 << 15 ) 131072 +--- +> y = ( 4 << 15 ) 0 +69c69 +< y = ( x <<= 15 ) 8355840 8355840 +--- +> y = ( x <<= 15 ) -32768 -32768 +85c85 +< yes if ( 4 << 15 ) yes() ; else no() +--- +> no if ( 4 << 15 ) yes() ; else no() +106c106 +< yes if ( x <<= 15 ) yes() ; else no() 8355840 +--- +> yes if ( x <<= 15 ) yes() ; else no() -32768 +sed -f ll.sed ll.c +acc -mm68k4 -DNOFLOAT ll.c +ll.c +running ll.cem +comparing ll +sed -f lu.sed lu.c +acc -mm68k4 -DNOFLOAT lu.c +lu.c +running lu.cem +comparing lu +23,31c23,31 +< z = x 40234 +< z += x 40244 +< z -= x -40224 +< z /= x 0 +< z %= x 10 +< z *= x 402340 +< z &= x 10 +< z |= x 40234 +< z ^= x 40224 +--- +> z = x -25302 +> z += x -25292 +> z -= x 25312 +> z /= x 0 +> z %= x 10 +> z *= x 9124 +> z &= x 10 +> z |= x -25302 +> z ^= x -25312 +38c38 +< y = ( x + 8012 ) 48246 +--- +> y = ( x + 8012 ) -17290 +42,52c42,52 +< y = ( x * 8012 ) 322354808 +< y = ( x & 8012 ) 7432 +< y = ( x | 8012 ) 40814 +< y = ( x ^ 8012 ) 33382 +< y = ( x || 8012 ) 1 +< y = ( x && 8012 ) 1 +< y = ( x << 9 ) 20599808 +< y = ( x >> 9 ) 78 +< y = ( -x ) -40234 +< y = ( !x ) 0 +< y = ( ~x ) -40235 +--- +> y = ( x * 8012 ) -16776 +> y = ( x & 8012 ) 7432 +> y = ( x | 8012 ) -24722 +> y = ( x ^ 8012 ) -32154 +> y = ( x || 8012 ) 1 +> y = ( x && 8012 ) 1 +> y = ( x << 9 ) 21504 +> y = ( x >> 9 ) 78 +> y = ( -x ) 25302 +> y = ( !x ) 0 +> y = ( ~x ) 25301 +59,68c59,68 +< y = ( x ? x : 8012 ) 40234 +< y = ( z = x ) 40234 40234 +< y = ( z += x ) 40244 40244 +< y = ( z -= x ) -40224 -40224 +< y = ( z /= x ) 0 0 +< y = ( z %= x ) 10 10 +< y = ( z *= x ) 402340 402340 +< y = ( z &= x ) 10 10 +< y = ( z |= x ) 40234 40234 +< y = ( z ^= x ) 40224 40224 +--- +> y = ( x ? x : 8012 ) -25302 +> y = ( z = x ) -25302 -25302 +> y = ( z += x ) -25292 -25292 +> y = ( z -= x ) 25312 25312 +> y = ( z /= x ) 0 0 +> y = ( z %= x ) 10 10 +> y = ( z *= x ) 9124 9124 +> y = ( z &= x ) 10 10 +> y = ( z |= x ) -25302 -25302 +> y = ( z ^= x ) -25312 -25312 +97,105c97,105 +< yes if ( z = x ) yes() ; else no() 40234 +< yes if ( z += x ) yes() ; else no() 40244 +< yes if ( z -= x ) yes() ; else no() -40224 +< no if ( z /= x ) yes() ; else no() 0 +< yes if ( z %= x ) yes() ; else no() 10 +< yes if ( z *= x ) yes() ; else no() 402340 +< yes if ( z &= x ) yes() ; else no() 10 +< yes if ( z |= x ) yes() ; else no() 40234 +< yes if ( z ^= x ) yes() ; else no() 40224 +--- +> yes if ( z = x ) yes() ; else no() -25302 +> yes if ( z += x ) yes() ; else no() -25292 +> yes if ( z -= x ) yes() ; else no() 25312 +> no if ( z /= x ) yes() ; else no() 0 +> yes if ( z %= x ) yes() ; else no() 10 +> yes if ( z *= x ) yes() ; else no() 9124 +> yes if ( z &= x ) yes() ; else no() 10 +> yes if ( z |= x ) yes() ; else no() -25302 +> yes if ( z ^= x ) yes() ; else no() -25312 +***** ctill +----- All program(s) in this directory should fail to compile. +acc -mm68k4 -DNOFLOAT noarg.c +noarg.c +"noarg.c", line 10: declared argument name is missing +*** Error code 1 +`gen' not remade because of errors +***** ctinit +acc -mm68k4 -DNOFLOAT init.c +init.c +"init.c", line 183: warning: Overflow in constant expression (U-) +"init.c", line 224: compiler problem: initialization alignment error +*** Error code 1 +`gen' not remade because of errors +***** ctmargt +acc -mm68k4 -DNOFLOAT margt.c +margt.c +running margt.cem +comparing margt +5,$c5,$ +< HOME=/usr/em +< NAME=em +< PATH=:/bin/:/usr/bin:/usr/em/bin +< SHELL=/bin/sh +< TERM=d80 +--- +> HOME=/other/keie +> PATH=:/other/keie/bin:/bin:/usr/bin +> TERM=MiniBee +***** ctprof +test profiling +procentry.c +acc -mm68k4 -DNOFLOAT tp.c procentry.k +tp.c +procentry.k +running tp +comparing tp +sh: 3905 Memory fault - core dumped +*** Error code -117 (ignored) +***** ctstruct +acc -mm68k4 -DNOFLOAT str.c +str.c +running str.cem +comparing str +***** ctsys +acc -mm68k4 -DNOFLOAT tfork.c +tfork.c +running tfork.cem +comparing tfork +1,$c1,$ +< childno 3944 +< Child 3944, status 0x800 +< fork/wait ok +--- +> childno N +> Child N, status 0x800 +> fork/wait ok +Fri Mar 15 16:15:13 GMT 1985 diff --git a/lang/cem/ctest/Out4.std b/lang/cem/ctest/Out4.std new file mode 100644 index 00000000..136b96be --- /dev/null +++ b/lang/cem/ctest/Out4.std @@ -0,0 +1,631 @@ +Tue Feb 5 15:35:34 MET 1985 +***** ctconv +vax4 conv.c +conv.c +"conv.c", line 41: warning: Overflow in constant expression +running conv.cem +comparing conv +16,18c16,18 +< char 192, int -64, unsigned 37777777700, long -64, float -64.000000 +< From long +< char 253, int -3, unsigned 37777777775, long -3, float -3.000000 +--- +> char 192, int -64, unsigned 177700, long -64, float -64.000000 +> From long +> char 253, int -3, unsigned 177775, long -3, float -3.000000 +***** ctdecl +vax4 decl.c +decl.c +running decl.cem +comparing decl +***** ctdivers +vax4 ops.c +ops.c +running ops.cem +comparing ops +24,39c24,39 +< u<<1 321632 +< u<<2 643464 +< u<<3 1507150 +< u<<4 3216320 +< u<<5 6434640 +< u<<6 15071500 +< u<<7 32163200 +< u<<8 64346400 +< u<<9 150715000 +< u<<10 321632000 +< u<<11 643464000 +< u<<12 1507150000 +< u<<13 3216320000 +< u<<14 6434640000 +< u<<15 15071500000 +< u<<16 32163200000 +--- +> u<<1 121632 +> u<<2 043464 +> u<<3 107150 +> u<<4 016320 +> u<<5 034640 +> u<<6 071500 +> u<<7 163200 +> u<<8 146400 +> u<<9 115000 +> u<<10 032000 +> u<<11 064000 +> u<<12 150000 +> u<<13 120000 +> u<<14 040000 +> u<<15 100000 +> u<<16 000000 +***** cterr +vax4 bugs.c +bugs.c +"bugs.c", line 92: warning: Overflow in constant expression +running bugs.cem +comparing bugs +***** ctest1 +vax4 test.c +test.c +running test.cem +comparing test +***** ctest2 +vax4 t7.c +t7.c +"t7.c", line 161: warning: statement not reached +"t7.c", line 178: warning: statement not reached +"t7.c", line 182: warning: statement not reached +"t7.c", line 186: warning: statement not reached +"t7.c", line 190: warning: statement not reached +"t7.c", line 194: warning: statement not reached +"t7.c", line 198: warning: statement not reached +"t7.c", line 205: warning: statement not reached +"t7.c", line 207: warning: statement not reached +"t7.c", line 211: warning: statement not reached +"t7.c", line 213: warning: statement not reached +"t7.c", line 287: warning: statement not reached +"t7.c", line 294: warning: statement not reached +"t7.c", line 300: warning: statement not reached +"t7.c", line 307: warning: statement not reached +"t7.c", line 343: warning: statement not reached +"t7.c", line 344: warning: statement not reached +"t7.c", line 345: warning: statement not reached +"t7.c", line 346: warning: statement not reached +"t7.c", line 348: warning: statement not reached +"t7.c", line 452: warning: statement not reached +"t7.c", line 561: warning: statement not reached +"t7.c", line 589: warning: statement not reached +running t7.cem +comparing t7 +***** ctest3 +vax4 test2.c +test2.c +running test2.cem +comparing test2 +***** ctest5 +vax4 test1.c +test1.c +"test1.c", line 101: warning: Illegal shift count in constant expression +"test1.c", line 370: warning: illegal pointer combination +"test1.c", line 371: warning: illegal pointer combination +"test1.c", line 372: warning: illegal pointer combination +"test1.c", line 384: warning: illegal pointer combination +"test1.c", line 407: warning: illegal pointer combination +"test1.c", line 408: warning: illegal pointer combination +"test1.c", line 409: warning: illegal pointer combination +"test1.c", line 421: warning: illegal pointer combination +running test1.cem +comparing test1 +***** ctgen +sed -f bf.sed bf.c +vax4 bf.c +bf.c +running bf.cem +comparing bf +39c39 +< bfs.bf4 = ( bfs.bf1 - bfs.bf2 ) 65529 +--- +> bfs.bf4 = ( bfs.bf1 - bfs.bf2 ) -7 +50,52c50,52 +< bfs.bf4 = ( -bfs.bf1 ) 65535 +< bfs.bf4 = ( !bfs.bf1 ) 0 +< bfs.bf4 = ( ~bfs.bf1 ) 65534 +--- +> bfs.bf4 = ( -bfs.bf1 ) -1 +> bfs.bf4 = ( !bfs.bf1 ) 0 +> bfs.bf4 = ( ~bfs.bf1 ) -2 +sed -f cel.sed cel.c +vax4 cel.c +cel.c +running cel.cem +comparing cel +sed -f clu.sed clu.c +vax4 clu.c +clu.c +running clu.cem +comparing clu +23,31c23,31 +< x = 40000 40000 +< x += 40000 40010 +< x -= 40000 -39990 +< x /= 40000 0 +< x %= 40000 10 +< x *= 40000 400000 +< x &= 40000 0 +< x |= 40000 40010 +< x ^= 40000 40010 +--- +> x = 40000 -25536 +> x += 40000 -25526 +> x -= 40000 25546 +> x /= 40000 0 +> x %= 40000 10 +> x *= 40000 6784 +> x &= 40000 0 +> x |= 40000 -25526 +> x ^= 40000 -25526 +38c38 +< y = ( 40000 + 8012 ) 48012 +--- +> y = ( 40000 + 8012 ) -17524 +42,52c42,52 +< y = ( 40000 * 8012 ) 320480000 +< y = ( 40000 & 8012 ) 7232 +< y = ( 40000 | 8012 ) 40780 +< y = ( 40000 ^ 8012 ) 33548 +< y = ( 40000 || 8012 ) 1 +< y = ( 40000 && 8012 ) 1 +< y = ( 40000 << 9 ) 20480000 +< y = ( 40000 >> 9 ) 78 +< y = ( -40000 ) -40000 +< y = ( !40000 ) 0 +< y = ( ~40000 ) -40001 +--- +> y = ( 40000 * 8012 ) 8960 +> y = ( 40000 & 8012 ) 7232 +> y = ( 40000 | 8012 ) -24756 +> y = ( 40000 ^ 8012 ) -31988 +> y = ( 40000 || 8012 ) 1 +> y = ( 40000 && 8012 ) 1 +> y = ( 40000 << 9 ) -32768 +> y = ( 40000 >> 9 ) 78 +> y = ( -40000 ) 25536 +> y = ( !40000 ) 0 +> y = ( ~40000 ) 25535 +59,68c59,68 +< y = ( 40000 ? 40000 : 8012 ) 40000 +< y = ( x = 40000 ) 40000 40000 +< y = ( x += 40000 ) 40010 40010 +< y = ( x -= 40000 ) -39990 -39990 +< y = ( x /= 40000 ) 0 0 +< y = ( x %= 40000 ) 10 10 +< y = ( x *= 40000 ) 400000 400000 +< y = ( x &= 40000 ) 0 0 +< y = ( x |= 40000 ) 40010 40010 +< y = ( x ^= 40000 ) 40010 40010 +--- +> y = ( 40000 ? 40000 : 8012 ) -25536 +> y = ( x = 40000 ) -25536 -25536 +> y = ( x += 40000 ) -25526 -25526 +> y = ( x -= 40000 ) 25546 25546 +> y = ( x /= 40000 ) 0 0 +> y = ( x %= 40000 ) 10 10 +> y = ( x *= 40000 ) 6784 6784 +> y = ( x &= 40000 ) 0 0 +> y = ( x |= 40000 ) -25526 -25526 +> y = ( x ^= 40000 ) -25526 -25526 +97,105c97,105 +< yes if ( x = 40000 ) yes() ; else no() 40000 +< yes if ( x += 40000 ) yes() ; else no() 40010 +< yes if ( x -= 40000 ) yes() ; else no() -39990 +< no if ( x /= 40000 ) yes() ; else no() 0 +< yes if ( x %= 40000 ) yes() ; else no() 10 +< yes if ( x *= 40000 ) yes() ; else no() 400000 +< no if ( x &= 40000 ) yes() ; else no() 0 +< yes if ( x |= 40000 ) yes() ; else no() 40010 +< yes if ( x ^= 40000 ) yes() ; else no() 40010 +--- +> yes if ( x = 40000 ) yes() ; else no() -25536 +> yes if ( x += 40000 ) yes() ; else no() -25526 +> yes if ( x -= 40000 ) yes() ; else no() 25546 +> no if ( x /= 40000 ) yes() ; else no() 0 +> yes if ( x %= 40000 ) yes() ; else no() 10 +> yes if ( x *= 40000 ) yes() ; else no() 6784 +> no if ( x &= 40000 ) yes() ; else no() 0 +> yes if ( x |= 40000 ) yes() ; else no() -25526 +> yes if ( x ^= 40000 ) yes() ; else no() -25526 +sed -f ec.sed ec.c +vax4 ec.c +ec.c +"ec.c", line 58: warning: Overflow in constant expression +"ec.c", line 64: warning: Overflow in constant expression +running ec.cem +comparing ec +sed -f ef.sed ef.c +vax4 ef.c +ef.c +running ef.cem +comparing ef +sed -f ei.sed ei.c +vax4 ei.c +ei.c +running ei.cem +comparing ei +32c32 +< x <<= 15 8355840 +--- +> x <<= 15 -32768 +48c48 +< y = ( 4 << 15 ) 131072 +--- +> y = ( 4 << 15 ) 0 +69c69 +< y = ( x <<= 15 ) 8355840 8355840 +--- +> y = ( x <<= 15 ) -32768 -32768 +85c85 +< yes if ( 4 << 15 ) yes() ; else no() +--- +> no if ( 4 << 15 ) yes() ; else no() +106c106 +< yes if ( x <<= 15 ) yes() ; else no() 8355840 +--- +> yes if ( x <<= 15 ) yes() ; else no() -32768 +sed -f el.sed el.c +vax4 el.c +el.c +running el.cem +comparing el +sed -f eu.sed eu.c +vax4 eu.c +eu.c +running eu.cem +comparing eu +23,31c23,31 +< x = 40000 40000 +< x += 40000 40010 +< x -= 40000 -39990 +< x /= 40000 0 +< x %= 40000 10 +< x *= 40000 400000 +< x &= 40000 0 +< x |= 40000 40010 +< x ^= 40000 40010 +--- +> x = 40000 -25536 +> x += 40000 -25526 +> x -= 40000 25546 +> x /= 40000 0 +> x %= 40000 10 +> x *= 40000 6784 +> x &= 40000 0 +> x |= 40000 -25526 +> x ^= 40000 -25526 +38c38 +< y = ( 40000 + 8012 ) 48012 +--- +> y = ( 40000 + 8012 ) -17524 +42,52c42,52 +< y = ( 40000 * 8012 ) 320480000 +< y = ( 40000 & 8012 ) 7232 +< y = ( 40000 | 8012 ) 40780 +< y = ( 40000 ^ 8012 ) 33548 +< y = ( 40000 || 8012 ) 1 +< y = ( 40000 && 8012 ) 1 +< y = ( 40000 << 9 ) 20480000 +< y = ( 40000 >> 9 ) 78 +< y = ( -40000 ) -40000 +< y = ( !40000 ) 0 +< y = ( ~40000 ) -40001 +--- +> y = ( 40000 * 8012 ) 8960 +> y = ( 40000 & 8012 ) 7232 +> y = ( 40000 | 8012 ) -24756 +> y = ( 40000 ^ 8012 ) -31988 +> y = ( 40000 || 8012 ) 1 +> y = ( 40000 && 8012 ) 1 +> y = ( 40000 << 9 ) -32768 +> y = ( 40000 >> 9 ) 78 +> y = ( -40000 ) 25536 +> y = ( !40000 ) 0 +> y = ( ~40000 ) 25535 +59,68c59,68 +< y = ( 40000 ? 40000 : 8012 ) 40000 +< y = ( x = 40000 ) 40000 40000 +< y = ( x += 40000 ) 40010 40010 +< y = ( x -= 40000 ) -39990 -39990 +< y = ( x /= 40000 ) 0 0 +< y = ( x %= 40000 ) 10 10 +< y = ( x *= 40000 ) 400000 400000 +< y = ( x &= 40000 ) 0 0 +< y = ( x |= 40000 ) 40010 40010 +< y = ( x ^= 40000 ) 40010 40010 +--- +> y = ( 40000 ? 40000 : 8012 ) -25536 +> y = ( x = 40000 ) -25536 -25536 +> y = ( x += 40000 ) -25526 -25526 +> y = ( x -= 40000 ) 25546 25546 +> y = ( x /= 40000 ) 0 0 +> y = ( x %= 40000 ) 10 10 +> y = ( x *= 40000 ) 6784 6784 +> y = ( x &= 40000 ) 0 0 +> y = ( x |= 40000 ) -25526 -25526 +> y = ( x ^= 40000 ) -25526 -25526 +97,105c97,105 +< yes if ( x = 40000 ) yes() ; else no() 40000 +< yes if ( x += 40000 ) yes() ; else no() 40010 +< yes if ( x -= 40000 ) yes() ; else no() -39990 +< no if ( x /= 40000 ) yes() ; else no() 0 +< yes if ( x %= 40000 ) yes() ; else no() 10 +< yes if ( x *= 40000 ) yes() ; else no() 400000 +< no if ( x &= 40000 ) yes() ; else no() 0 +< yes if ( x |= 40000 ) yes() ; else no() 40010 +< yes if ( x ^= 40000 ) yes() ; else no() 40010 +--- +> yes if ( x = 40000 ) yes() ; else no() -25536 +> yes if ( x += 40000 ) yes() ; else no() -25526 +> yes if ( x -= 40000 ) yes() ; else no() 25546 +> no if ( x /= 40000 ) yes() ; else no() 0 +> yes if ( x %= 40000 ) yes() ; else no() 10 +> yes if ( x *= 40000 ) yes() ; else no() 6784 +> no if ( x &= 40000 ) yes() ; else no() 0 +> yes if ( x |= 40000 ) yes() ; else no() -25526 +> yes if ( x ^= 40000 ) yes() ; else no() -25526 +sed -f id.sed id.c +vax4 id.c +id.c +running id.cem +comparing id +26,28c26,28 +< y = ( (-40) - 300 ) 50346 +< y = ( (-40) / 300 ) 0 +< y = ( (-40) * 300 ) -2147432645 +--- +> y = ( (-40) - 300 ) -15190 +> y = ( (-40) / 300 ) 0 +> y = ( (-40) * 300 ) -14533 +39,48c39,48 +< y = ( (-40) ? (-40) : 300 ) 49952 +< y = ( x = (-40) ) -4.000000e+01 49952 +< y = ( x += (-40) ) -3.685850e+01 1864024851 +< y = ( x -= (-40) ) 4.314150e+01 -1864023252 +< y = ( x /= (-40) ) -7.853750e-02 -666583392 +< y = ( x *= (-40) ) -1.256600e+02 1374405627 +< y = ( x ++ ) 4.141500e+00 240533833 +< y = ( x -- ) 2.141500e+00 240533833 +< y = ( -- x ) 2.141500e+00 240533769 +< y = ( ++ x ) 4.141500e+00 -2027208316 +--- +> y = ( (-40) ? (-40) : 300 ) -15584 +> y = ( x = (-40) ) -4.000000e+01 -15584 +> y = ( x += (-40) ) -3.685850e+01 -15597 +> y = ( x -= (-40) ) 4.314150e+01 17196 +> y = ( x /= (-40) ) -7.853750e-02 -16736 +> y = ( x *= (-40) ) -1.256600e+02 -15365 +> y = ( x ++ ) 4.141500e+00 16713 +> y = ( x -- ) 2.141500e+00 16713 +> y = ( -- x ) 2.141500e+00 16649 +> y = ( ++ x ) 4.141500e+00 16772 +sed -f lc.sed lc.c +vax4 lc.c +lc.c +"lc.c", line 60: warning: Overflow in constant expression +"lc.c", line 66: warning: Overflow in constant expression +running lc.cem +comparing lc +sed -f ld.sed ld.c +vax4 ld.c +ld.c +running ld.cem +comparing ld +sed -f lf.sed lf.c +vax4 lf.c +lf.c +running lf.cem +comparing lf +sed -f li.sed li.c +vax4 li.c +li.c +running li.cem +comparing li +32c32 +< x <<= 15 8355840 +--- +> x <<= 15 -32768 +48c48 +< y = ( 4 << 15 ) 131072 +--- +> y = ( 4 << 15 ) 0 +69c69 +< y = ( x <<= 15 ) 8355840 8355840 +--- +> y = ( x <<= 15 ) -32768 -32768 +85c85 +< yes if ( 4 << 15 ) yes() ; else no() +--- +> no if ( 4 << 15 ) yes() ; else no() +106c106 +< yes if ( x <<= 15 ) yes() ; else no() 8355840 +--- +> yes if ( x <<= 15 ) yes() ; else no() -32768 +sed -f ll.sed ll.c +vax4 ll.c +ll.c +running ll.cem +comparing ll +sed -f lu.sed lu.c +vax4 lu.c +lu.c +running lu.cem +comparing lu +23,31c23,31 +< z = x 40234 +< z += x 40244 +< z -= x -40224 +< z /= x 0 +< z %= x 10 +< z *= x 402340 +< z &= x 10 +< z |= x 40234 +< z ^= x 40224 +--- +> z = x -25302 +> z += x -25292 +> z -= x 25312 +> z /= x 0 +> z %= x 10 +> z *= x 9124 +> z &= x 10 +> z |= x -25302 +> z ^= x -25312 +38c38 +< y = ( x + 8012 ) 48246 +--- +> y = ( x + 8012 ) -17290 +42,52c42,52 +< y = ( x * 8012 ) 322354808 +< y = ( x & 8012 ) 7432 +< y = ( x | 8012 ) 40814 +< y = ( x ^ 8012 ) 33382 +< y = ( x || 8012 ) 1 +< y = ( x && 8012 ) 1 +< y = ( x << 9 ) 20599808 +< y = ( x >> 9 ) 78 +< y = ( -x ) -40234 +< y = ( !x ) 0 +< y = ( ~x ) -40235 +--- +> y = ( x * 8012 ) -16776 +> y = ( x & 8012 ) 7432 +> y = ( x | 8012 ) -24722 +> y = ( x ^ 8012 ) -32154 +> y = ( x || 8012 ) 1 +> y = ( x && 8012 ) 1 +> y = ( x << 9 ) 21504 +> y = ( x >> 9 ) 78 +> y = ( -x ) 25302 +> y = ( !x ) 0 +> y = ( ~x ) 25301 +59,68c59,68 +< y = ( x ? x : 8012 ) 40234 +< y = ( z = x ) 40234 40234 +< y = ( z += x ) 40244 40244 +< y = ( z -= x ) -40224 -40224 +< y = ( z /= x ) 0 0 +< y = ( z %= x ) 10 10 +< y = ( z *= x ) 402340 402340 +< y = ( z &= x ) 10 10 +< y = ( z |= x ) 40234 40234 +< y = ( z ^= x ) 40224 40224 +--- +> y = ( x ? x : 8012 ) -25302 +> y = ( z = x ) -25302 -25302 +> y = ( z += x ) -25292 -25292 +> y = ( z -= x ) 25312 25312 +> y = ( z /= x ) 0 0 +> y = ( z %= x ) 10 10 +> y = ( z *= x ) 9124 9124 +> y = ( z &= x ) 10 10 +> y = ( z |= x ) -25302 -25302 +> y = ( z ^= x ) -25312 -25312 +97,105c97,105 +< yes if ( z = x ) yes() ; else no() 40234 +< yes if ( z += x ) yes() ; else no() 40244 +< yes if ( z -= x ) yes() ; else no() -40224 +< no if ( z /= x ) yes() ; else no() 0 +< yes if ( z %= x ) yes() ; else no() 10 +< yes if ( z *= x ) yes() ; else no() 402340 +< yes if ( z &= x ) yes() ; else no() 10 +< yes if ( z |= x ) yes() ; else no() 40234 +< yes if ( z ^= x ) yes() ; else no() 40224 +--- +> yes if ( z = x ) yes() ; else no() -25302 +> yes if ( z += x ) yes() ; else no() -25292 +> yes if ( z -= x ) yes() ; else no() 25312 +> no if ( z /= x ) yes() ; else no() 0 +> yes if ( z %= x ) yes() ; else no() 10 +> yes if ( z *= x ) yes() ; else no() 9124 +> yes if ( z &= x ) yes() ; else no() 10 +> yes if ( z |= x ) yes() ; else no() -25302 +> yes if ( z ^= x ) yes() ; else no() -25312 +***** ctill +----- An missing argument error should be reported +vax4 noarg.c +noarg.c +"noarg.c", line 8: declared argument name is missing +*** Error code 1 +`gen' not remade because of errors +***** ctinit +vax4 init.c +init.c +"init.c", line 179: warning: Overflow in constant expression (U-) +running init.cem +comparing init +48c48 +< fl6 1.70141173319264427000e+38 +--- +> fl6 1.70141163178059625000e+38 +110,$c110,$ +< sizeof stb 8 +< stb 1 2 3 4 3 6 7 +< +--- +> sizeof stb 6 +> stb 1 2 3 4 3 6 7 +> +***** ctmargt +vax4 margt.c +margt.c +running margt.cem +comparing margt +5,$c5,$ +< BELL= +< BIN=/user0/keie/bin +< CDPATH=:/usr/em/util:/usr/em/mach:/usr/em/lang +< DIT=/user0/keie/ditroff/troff/a.out +< HOME=/usr/em +< MAILHEADER=To: botter!vu44!mcvax!%t +< Subject: Re: %S +< Newsgroups: %n +< In-Reply-To: %i +< %(%[references]!=^$?References\: %[references] +< )Organization: %o +< Cc: +< Bcc: +< +< +< PATH=:/user0/keie/bin:/usr/local:/usr/ucb:/bin:/usr/bin:/usr/em/bin:/usr/new +< SHELL=/usr/local/dsh +< TERM=d80 +< TERMCAP=ME|ampex|d80|dialogue|dialogue80:am:bs:pt:if=/usr/lib/tabset/stdcrt:cl=\E;:cm=\E=%+\040%+\040:al=10\EE:ic=3\EQ:im=:ei=:dl=10\ER:dc=\EW:is=\EA:ho=^^:ce=\ET:cd=\EY:so=\Ej:se=\Ek:us=\El:ue=\Em:ul:li#24:co#80:nd=^L:up=^K:we=\Eo:ws=\En +< USER=keie +--- +> HOME=/other/keie +> PATH=:/other/keie/bin:/bin:/usr/bin +> TERM=MiniBee +***** ctprof +test profiling +procentry.c +vax4 tp.c procentry.k +tp.c +procentry.k +running tp +comparing tp +***** ctstruct +vax4 str.c +str.c +running str.cem +comparing str +***** ctsys +vax4 tfork.c +tfork.c +running tfork.cem +comparing tfork +1,$c1,$ +< childno 6340 +< Child 6340, status 0x800 +< fork/wait ok +--- +> childno N +> Child N, status 0x800 +> fork/wait ok +Tue Feb 5 17:29:23 MET 1985 From c765b06883f0e2d3f63e969efac4f6514f6d0ed9 Mon Sep 17 00:00:00 2001 From: keie Date: Fri, 21 Jun 1985 12:55:17 +0000 Subject: [PATCH 0050/1625] %D => %ld --- util/misc/decode.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/util/misc/decode.c b/util/misc/decode.c index 6edcc8b6..55950546 100644 --- a/util/misc/decode.c +++ b/util/misc/decode.c @@ -322,7 +322,7 @@ int table3(i) { case sp_ilb2: argval = get16(); if ( argval<0 ) { - error("illegal instruction label %D",argval); + error("illegal instruction label %ld",argval); argval=0 ; } break; @@ -421,12 +421,12 @@ puttyp(t) { break; case sp_cst2: case sp_cst4: - printf("%D",argval); + printf("%ld",argval); break; case sp_doff: puttyp(offtyp); if (argval >= 0) putchar('+'); - printf("%D",argval); + printf("%ld",argval); break; case sp_pnam: putstr('$',0); @@ -436,15 +436,15 @@ puttyp(t) { break; case sp_icon: putstr(0,'I'); - printf("%D",argval); + printf("%ld",argval); break; case sp_ucon: putstr(0,'U'); - printf("%D",argval); + printf("%ld",argval); break; case sp_fcon: putstr(0,'F'); - printf("%D",argval); + printf("%ld",argval); break; case sp_cend: putchar('?'); From 6fa0c54586a1487a84207007b73e47188a16fe6c Mon Sep 17 00:00:00 2001 From: bal Date: Thu, 18 Jul 1985 14:52:56 +0000 Subject: [PATCH 0051/1625] .sect .text added --- mach/m68k2/libem/gto.s | 1 + mach/m68k2/libem/lpb.s | 1 + mach/m68k2/libem/lxa.s | 1 + mach/m68k2/libem/lxl.s | 1 + 4 files changed, 4 insertions(+) diff --git a/mach/m68k2/libem/gto.s b/mach/m68k2/libem/gto.s index 3a394f81..23943151 100644 --- a/mach/m68k2/libem/gto.s +++ b/mach/m68k2/libem/gto.s @@ -5,6 +5,7 @@ .sect .bss .extern .gto + .sect .text .gto: ! nonlocal goto ! the argument on the stack is a pointer to a GTO-descriptor containing: diff --git a/mach/m68k2/libem/lpb.s b/mach/m68k2/libem/lpb.s index 177fac45..61b6a874 100644 --- a/mach/m68k2/libem/lpb.s +++ b/mach/m68k2/libem/lpb.s @@ -4,6 +4,7 @@ .sect .data .sect .bss .extern .lpb + .sect .text .lpb: ! convert local to argument base ! should not destroy register d2 (used by lxa/lxl) diff --git a/mach/m68k2/libem/lxa.s b/mach/m68k2/libem/lxa.s index 9172a3d6..8d1df55c 100644 --- a/mach/m68k2/libem/lxa.s +++ b/mach/m68k2/libem/lxa.s @@ -4,6 +4,7 @@ .sect .data .sect .bss .extern .lxa + .sect .text .lxa: ! #levels (>= 0) on stack diff --git a/mach/m68k2/libem/lxl.s b/mach/m68k2/libem/lxl.s index e41f8318..4b94320d 100644 --- a/mach/m68k2/libem/lxl.s +++ b/mach/m68k2/libem/lxl.s @@ -4,6 +4,7 @@ .sect .data .sect .bss .extern .lxl + .sect .text .lxl: ! #levels on stack (> 0) From 34ef18311c40284726d078a4a2ce566f65433b7a Mon Sep 17 00:00:00 2001 From: bal Date: Fri, 19 Jul 1985 13:43:03 +0000 Subject: [PATCH 0052/1625] .sect .text added --- mach/m68k2/libsys/execl.s | 1 + mach/m68k2/libsys/fstat.s | 1 + mach/m68k2/libsys/signal.s | 1 + mach/m68k2/libsys/wait.s | 1 + 4 files changed, 4 insertions(+) diff --git a/mach/m68k2/libsys/execl.s b/mach/m68k2/libsys/execl.s index 0fbfd8ae..6dcbdb4b 100644 --- a/mach/m68k2/libsys/execl.s +++ b/mach/m68k2/libsys/execl.s @@ -4,6 +4,7 @@ .sect .data .sect .bss .extern _execl + .sect .text _execl: link a6,#0 tst.b -132(sp) move.l _environ,-(sp) diff --git a/mach/m68k2/libsys/fstat.s b/mach/m68k2/libsys/fstat.s index bfda6d9b..9912b4d3 100644 --- a/mach/m68k2/libsys/fstat.s +++ b/mach/m68k2/libsys/fstat.s @@ -4,6 +4,7 @@ .sect .data .sect .bss .extern _fstat + .sect .text _fstat: move.w #0x1C,d0 move.w 4(sp),a0 move.l 6(sp),d1 diff --git a/mach/m68k2/libsys/signal.s b/mach/m68k2/libsys/signal.s index 01f5df5e..c7744161 100644 --- a/mach/m68k2/libsys/signal.s +++ b/mach/m68k2/libsys/signal.s @@ -5,6 +5,7 @@ .sect .bss .extern _signal NSIG=32 + .sect .text _signal: move.w 4(sp), d0 ext.l d0 diff --git a/mach/m68k2/libsys/wait.s b/mach/m68k2/libsys/wait.s index c5a5de10..18a85f15 100644 --- a/mach/m68k2/libsys/wait.s +++ b/mach/m68k2/libsys/wait.s @@ -4,6 +4,7 @@ .sect .data .sect .bss .extern _wait + .sect .text _wait: move.w #0x7,d0 move.l 4(sp),a0 trap #0 From 85a027feeb8f10d6a77a6e65f0679176264dd41c Mon Sep 17 00:00:00 2001 From: bal Date: Fri, 19 Jul 1985 17:58:34 +0000 Subject: [PATCH 0053/1625] patterns for "loc loc cii/cui/ciu/cuu $1==$2" added. --- mach/m68k2/cg/table | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mach/m68k2/cg/table b/mach/m68k2/cg/table index 9fc55736..14f04da0 100644 --- a/mach/m68k2/cg/table +++ b/mach/m68k2/cg/table @@ -1264,6 +1264,11 @@ zrf | | | | zer $1 | /* G R O U P VIII : C O N V E R T */ +loc loc cii $1==$2 | | | | | +loc loc cuu $1==$2 | | | | | +loc loc ciu $1==$2 | | | | | +loc loc cui $1==$2 | | | | | + cii | | remove(ALL) "jsr .cii" | | | From bcce387bb6c12eacf50f611358d9290d8aa226e0 Mon Sep 17 00:00:00 2001 From: bal Date: Fri, 19 Jul 1985 18:02:25 +0000 Subject: [PATCH 0054/1625] bugs for ngf 8 and fif 4 fixed (asp 16 --> asp 8). --- mach/m68k2/cg/table | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mach/m68k2/cg/table b/mach/m68k2/cg/table index 14f04da0..c7212479 100644 --- a/mach/m68k2/cg/table +++ b/mach/m68k2/cg/table @@ -1029,10 +1029,10 @@ ngf $1==4 | | "jsr .ngf4" | | asp 4 lfr 4 | ngf $1==8 | | remove(ALL) - "jsr .ngf8" | | asp 16 lfr 4 loi 8 | + "jsr .ngf8" | | asp 8 lfr 4 loi 8 | fif $1==4 | | remove(ALL) - "jsr .fif4" | | asp 16 lfr 4 loi 8 | + "jsr .fif4" | | asp 8 lfr 4 loi 8 | fif $1==8 | | remove(ALL) "jsr .fif8" | | asp 16 lfr 4 loi 16 | From 07606c3af33417e60615787246ada490793dc786 Mon Sep 17 00:00:00 2001 From: ceriel Date: Sun, 21 Jul 1985 11:34:33 +0000 Subject: [PATCH 0055/1625] There was a bug in the "str $1==0" instruction. It said: str $1==0 | source4 | remove(ALL) "jsb\t.strlb" | | | It should of course have been str $1==0 | STACK | jsb\t.strlb" | | | --- mach/vax4/cg/table | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mach/vax4/cg/table b/mach/vax4/cg/table index 51117dc1..7975d2e6 100644 --- a/mach/vax4/cg/table +++ b/mach/vax4/cg/table @@ -4434,8 +4434,7 @@ sig | STACK | "jsb\t.sig" | | | sim | STACK | "jsb\t.sim" | | | -str $1==0 | source4 | - remove(ALL) +str $1==0 | STACK | "jsb\t.strlb" | | | str $1==1 | source4 | remove(ALL) From 4617b590566b2839f8f22d0214601a75ef8d3f52 Mon Sep 17 00:00:00 2001 From: em Date: Fri, 26 Jul 1985 11:05:30 +0000 Subject: [PATCH 0056/1625] Initial revision --- mach/ns/libbc/Makefile | 20 ++++++++++++++++++++ mach/ns/libbc/compmodule | 2 ++ mach/ns/libcc/compmodule | 2 ++ 3 files changed, 24 insertions(+) create mode 100644 mach/ns/libbc/Makefile create mode 100755 mach/ns/libbc/compmodule create mode 100755 mach/ns/libcc/compmodule diff --git a/mach/ns/libbc/Makefile b/mach/ns/libbc/Makefile new file mode 100644 index 00000000..333eb2fa --- /dev/null +++ b/mach/ns/libbc/Makefile @@ -0,0 +1,20 @@ +MAKEFILE=../../proto/libg/Makefile +MACHDEF="MACH=ns" "SUF=o" +BCDEF="PREF=bc" "SUB=" "SRC=lang/basic/lib" + +install: + make -f $(MAKEFILE) $(BCDEF) $(MACHDEF) tailcp + +cmp: + make -f $(MAKEFILE) $(BCDEF) $(MACHDEF) tail + -../../compare head_bc + -../../compare tail_bc + +clean: + -rm -f *.old *.[ce$(SUF)] tail* head* + +opr: + make pr | opr + +pr: + @pr Makefile diff --git a/mach/ns/libbc/compmodule b/mach/ns/libbc/compmodule new file mode 100755 index 00000000..491f6d25 --- /dev/null +++ b/mach/ns/libbc/compmodule @@ -0,0 +1,2 @@ +${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +echo `basename $1 $2`.o diff --git a/mach/ns/libcc/compmodule b/mach/ns/libcc/compmodule new file mode 100755 index 00000000..491f6d25 --- /dev/null +++ b/mach/ns/libcc/compmodule @@ -0,0 +1,2 @@ +${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +echo `basename $1 $2`.o From e33e92caac1d956b160f59ae88f0aadc8c8751ab Mon Sep 17 00:00:00 2001 From: em Date: Fri, 26 Jul 1985 11:29:08 +0000 Subject: [PATCH 0057/1625] *** empty log message *** --- mach/ns/ncg/mach.c | 143 +++++++++++++++++++++++++++++++++++++++++++++ mach/ns/ncg/mach.h | 22 +++++++ 2 files changed, 165 insertions(+) create mode 100644 mach/ns/ncg/mach.c create mode 100644 mach/ns/ncg/mach.h diff --git a/mach/ns/ncg/mach.c b/mach/ns/ncg/mach.c new file mode 100644 index 00000000..fd4b55ec --- /dev/null +++ b/mach/ns/ncg/mach.c @@ -0,0 +1,143 @@ +con_part(sz, w) + register int sz; + word w; +{ + while (part_size % sz) part_size++; + + if (part_size == TEM_WSIZE) + part_flush(); + if (sz == 1 || sz == 2) { + w &= (sz == 1 ? 0xFF : 0xFFFF); + w <<= 8 * part_size; + part_word |= w; + } else { + assert(sz == 4); + part_word = w; + } + part_size += sz; +} + +con_mult(sz) + word sz; +{ + if (sz != 4) + fatal("bad icon/ucon size"); + fprintf(codefile,".long\t%s\n",str); +} + +#ifdef REGVARS +full lbytes; +struct regadm { + char *ra_str; + long ra_off; +} regadm[4]; +int n_regvars; + +regscore(off,size,typ,score,totyp) long off; { + + /*This function is copied from pdp/ncg + */ + /* + * This function is full of magic constants. + * They are a result of experimentation. + */ + + if (size != 2) + return(-1); + score -= 1; /* allow for save/restore */ + if (off>=0) + score -= 2; + if (typ==reg_pointer) + score *= 17; + else if (typ==reg_loop) + score = 10*score+50; /* Guestimate */ + else + score *= 10; + return(score); /* 10 * estimated # of words of profit */ +} + +i_regsave() { + + n_regvars=0; +} + +f_regsave(){ + register i; + + fprintf(codefile, "enter ["); + if (n_regvars>=1){ + fprintf(codefile,"%s",regadm[0].ra_str); + for (i=1; i=0) + fprintf(codefile, "movd %ld(fp), %s", + regadm[i].ra_off, regadm[i].ra_str); +} + +regsave(regstr,off,size) char *regstr; long off; { + + fprintf(codefile,"\t! Local %ld into %s\n",off,regstr); + regadm[n_regvars].ra_str = regstr; + regadm[n_regvars].ra_off = off; + n_regvars++; +} + +regreturn() { + register int i; + + fprintf(codefile, "exit ["); + if (n_regvars>=1){ + fprintf(codefile,"%s",regadm[0].ra_str); + for (i=1; i Date: Fri, 26 Jul 1985 11:38:59 +0000 Subject: [PATCH 0058/1625] Initial revision --- mach/ns/ncg/table | 2187 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 2187 insertions(+) create mode 100644 mach/ns/ncg/table diff --git a/mach/ns/ncg/table b/mach/ns/ncg/table new file mode 100644 index 00000000..a7e5b050 --- /dev/null +++ b/mach/ns/ncg/table @@ -0,0 +1,2187 @@ +/***************************************************************** + * * + * N S 1 6 0 3 2 B A C K - E N D T A B L E * + * * + * * + * Author: Annita Wilschut. * + * * + *****************************************************************/ + +/* + * Deze tabel implementeert, naast gewone, ook floating point + * instructies. Bij gebrek aan een floating point processor + * is het betreffende onderdeel van de tabel echter niet + * getest. Wanneer NOFLOAT "aan" is worden er zeker geen + * floating point instructies gegenereerd. Na verwijdering van + * alle ifdef's worden er bij de vertaling van een programma dat + * geen floating point gebruikt, hoogst waarschhijnlijk ook + * geen floating point instructies gegenereerd. Dit is echter niet + * uitgebreid getest. + */ + +EM_WSIZE=4 +EM_PSIZE=4 +EM_BSIZE=8 + +#define NOFLOAT + +PROPERTIES + +USELESS /* Bug circumvention */ +REG /* Normal registers */ +FREG /* Floating point registers */ +DFREG(8) /* double floating reg for double precision */ +MEMREG /* sp, fp en sb */ +REGPAIR(8) /* register pair for extended integer instr */ +PROGRAMCOUNTER +STACKPOINTER +STATICBASE +LOCALBASE + + +REGISTERS + +r0,r1,r2,r7 : REG. +r3,r4,r5,r6 : REG regvar . +f0,f1,f2,f3,f4,f5,f6,f7 : FREG. +f01("f0")=f0+f1, +f23("f2")=f2+f3, +f45("f4")=f4+f5, +f67("f6")=f6+f7 : DFREG. +r01("r0")=r0+r1,r23("r2")=r2+r3 : REGPAIR. +sp : STACKPOINTER, MEMREG. +pc : PROGRAMCOUNTER. +fp : LOCALBASE, MEMREG. +sb : STATICBASE, MEMREG. + + +TOKENS + +const4 = { INT num; } 4 num . +LOCAL = { INT ind;} 4 ind "(fp)" . +DLOCAL = { INT ind;} 8 ind "(fp)". + + +addr_local = { INT ind; } 4 . +addr_external = { ADDR disp; } 4 disp . + +regrel1 = { REG reg; ADDR disp; } 4 disp "(" reg ")" . +regrel2 = { REG reg; ADDR disp; } 4 disp "(" reg ")" . +regrel4 = { REG reg; ADDR disp; } 4 disp "(" reg ")" . +regrel8 = { REG reg; ADDR disp; } 8 disp "(" reg ")" . +memregrel1 = { MEMREG reg; ADDR disp; } 4 disp "(" reg ")" . +memregrel2 = { MEMREG reg; ADDR disp; } 4 disp "(" reg ")" . +memregrel4 = { MEMREG reg; ADDR disp; } 4 disp "(" reg ")" . +memregrel8 = { MEMREG reg; ADDR disp; } 8 disp "(" reg ")" . +memrel1 = { MEMREG reg; ADDR disp1; ADDR disp2; } 4 disp2 "(" + disp1 "(" reg "))" . +memrel2 = { MEMREG reg; ADDR disp1; ADDR disp2; } 4 disp2 "(" + disp1 "(" reg "))" . +memrel4 = { MEMREG reg; ADDR disp1; ADDR disp2; } 4 disp2 "(" + disp1 "(" reg "))" . +memrel8 = { MEMREG reg; ADDR disp1; ADDR disp2; } 8 disp2 "(" + disp1 "(" reg "))" . +absolute1 = { ADDR disp; } 4 "@" disp . +absolute2 = { ADDR disp; } 4 "@" disp . +absolute4 = { ADDR disp; } 4 "@" disp . +absolute8 = { ADDR disp; } 8 "@" disp . +TOS = {} 4 "tos" . + +regcon4 = { REG reg; ADDR disp; } 4 . +memregcon4 = { MEMREG reg; ADDR disp; } 4 . +memregrelcon4 = { MEMREG reg; ADDR disp1; ADDR disp2;} 4 . + +label = {ADDR disp; } 4 disp . + +memregrelsid = {INT ind; MEMREG reg1; REG reg2; } 4 ind "(" reg1 + ")[" reg2 ":d]" . +abssid = {ADDR disp; REG reg; } 4 "@" disp "[" reg ":d]" . +fprelsid = {ADDR disp1; ADDR disp2; REG reg; } 4 + disp2 "(" disp1 "(fp))[" reg ":d]" . +sprelsid = {ADDR disp1; ADDR disp2; REG reg; } 4 + disp2 "(" disp1 "(sp))[" reg ":d]" . + +SETS + +src1 = regrel1 + memregrel1 + memrel1 + absolute1 . +src2 = regrel2 + memregrel2 + memrel2 + absolute2 . +src4 = REG + const4 + LOCAL + regrel4 + memrel4 + + memregrel4 + memregrelsid + abssid + absolute4 + + addr_external. +con4 = regcon4 + memregcon4 + memregrelcon4 . +tossrc4 = TOS + src4 . +consrc4 = con4 + src4 . +fsrc4 = FREG + LOCAL + regrel4 + memrel4 + + memregrel4 + memregrelsid + abssid + absolute4 . +tosfsrc4 = TOS + fsrc4 . +fsrc8 = DFREG + DLOCAL + regrel8 + memrel8 + + memregrel8 + absolute8 . +tosfsrc8 = TOS + fsrc8 . +dst1 = src1 . +tosdst1 = TOS + dst1 . +dst2 = src2 . +tosdst2 = TOS + dst2 . +dst4 = REG + LOCAL + regrel4 + memregrel4 + memrel4 + + absolute4 + memregrelsid + abssid . +tosdst4 = TOS + dst4 . +fdst4 = FREG + LOCAL + regrel4 + memregrel4 + memrel4 + + absolute4 + memregrelsid + abssid . +tosfdst4 = TOS + fdst4 . +fdst8 = fsrc8 . +tosfdst8 = tosfsrc8 . +regrel = regrel1 + regrel2 + regrel4 +regrel8 . +memregrel = memregrel1 + memregrel2 + memregrel4 +memregrel8 . +memrel = memrel1 + memrel2 + memrel4 +memrel8 . +rel = regrel + memregrel + memrel + memregrelsid + + fprelsid + sprelsid . +absolute = absolute1 + absolute2 + absolute4 + absolute8 + abssid . +regs = REG + FREG + DFREG + MEMREG + REGPAIR . +allmincon = ALL - (regs + const4 + addr_local + addr_external + + regcon4 + memregcon4) . +src24 = src2 + src4 . +src124 = src1 + src2 + src4 . +tossrc24 = TOS + src24 . +tossrc124 = TOS + src124 . + + +INSTRUCTIONS + + +movb tossrc124:ro, tosdst1:wo . +movw tossrc24:ro, tosdst2:wo . +movd tossrc4:ro, tosdst4:wo . +movf tosfsrc4:ro, tosfdst4:wo . +movl tosfsrc8:ro, tosfdst8:wo . +movdf tossrc4:ro, tosfdst4:wo . +movdl tossrc4:ro, tosfdst8:wo . +movfl tosfsrc4:ro, tosfdst8:wo . +movlf tosfsrc8:ro, tosfdst4:wo . +truncfd tosfsrc4:ro, tosdst4:wo . +truncld tosfsrc8:ro, tosdst4:wo . +cmpb tossrc124:ro, src1:ro . +cmpw tossrc24:ro, src2:ro . +cmpd tossrc4:ro, tossrc4:ro . +cmpf tosfsrc4:ro, tosfsrc4:ro . +cmpl tosfsrc8:ro, tosfsrc8:ro . +addd tossrc4:ro, tosdst4:rw . +addcd tossrc4:ro, tosdst4:rw . +addf tosfsrc4:ro, tosfdst4:rw . +addl tosfsrc8:ro, tosfdst8:rw . +subd tossrc4:ro, tosdst4:rw . +subcd tossrc4:ro, tosdst4:rw . +subf tosfsrc4:ro, tosfdst4:rw . +subl tosfsrc8:ro, tosfdst8:rw . +muld tossrc4:ro, tosdst4:rw . +mulf tosfsrc4:ro, tosfdst4:rw . +mull tosfsrc8:ro, tosfdst8:rw . +quod tossrc4:ro, tosdst4:rw . +divd tossrc4:ro, tosdst4:rw . +divf tosfsrc4:ro, tosfdst4:rw . +divl tosfsrc8:ro, tosfdst8:rw . +remd tossrc4:ro, tosdst4:rw . +modd tossrc4:ro, tosdst4:rw . +negd tossrc4:ro, tosdst4:wo . +negf tosfsrc4:ro, tosfdst4:wo . +negl tosfsrc8:ro, tosfdst8:wo . +roundfd tosfsrc4:ro, tosdst4:wo . +roundld tosfsrc8:ro, tosdst4:wo . +andd tossrc4:ro, tosdst4:wo . +ord tossrc4:ro, tosdst4:wo . +xord tossrc4:ro, tosdst4:rw . +comd tossrc4:ro, tosdst4:rw . +ashd tossrc124:ro, tosdst4:rw . +lshd tossrc124:ro, tosdst4:rw . +rotd tossrc124:ro, tosdst4:rw . +movzbd tossrc124:ro, tosdst4:wo . +movzwd tossrc24:ro, tosdst4:wo . +movxbd tossrc124:ro, tosdst4:wo . +movxwd tossrc124:ro, tosdst4:wo . +addr tosdst4:ro, tosdst4:wo . +movqd const4:ro, tosdst4:wo . +cmpqd const4:ro, tossrc4:ro . +meid tossrc4:ro, REGPAIR:rw . +sxx tosdst4:wo . +seqd tosdst4:wo . +sned tosdst4:wo . +sltd tosdst4:wo . +sled tosdst4:wo . +sgtd tosdst4:wo . +sged tosdst4:wo . +shid tosdst4:wo . +sfsd tosdst4:wo . +tbitd tossrc4:ro, tosdst4:ro . +cbitd tossrc4:ro, tosdst4:rw . +sbitd tossrc4:ro, tosdst4:rw . +movmd tosdst4:ro, tosdst4:rw, const4 . +indexd REG, tossrc4:ro, tossrc4:ro . +brxx label . +beq label . +bne label . +ble label . +blt label . +bge label . +bgt label . +bfc label . +bfs label . +blo label . +bls label . +bhs label . +bhi label . +br label . +acbd const4:ro, tosdst4:rw, label . +jsr tosdst4+label . +ret const4:ro . +adjspd tossrc4:ro . +exit label . + + + +MOVES + + +from memregrelcon4 to tosdst4 +gen addr {memrel4, %1.reg, %1.disp1, %1.disp2}, %2 + +from regcon4 to tosdst4 +gen addr {regrel4, %1.reg, %1.disp}, %2 + +from memregcon4 to tosdst4 +gen addr {memregrel4, %1.reg, %1.disp}, %2 + +from tossrc4 to tosdst4 +gen movd %1, %2 + +from tossrc124 to tosdst1 +gen movb %1, %2 + +from tossrc24 to tosdst2 +gen movw %1, %2 + +#ifndef NOFLOAT +from tosfsrc4 to FREG +gen movf %1, %2 + +from FREG to tosfdst4 +gen movf %1, %2 + +from tosfsrc8 to DFREG +gen movl %1, %2 + +from DFREG to tosfdst8 +gen movl %1, %2 +#endif + + +STACKINGRULES + + +from src1 to STACK +gen movzbd %1, {TOS} + +from src2 to STACK +gen movzwd %1, {TOS} + +from src4 to STACK +gen movd %1, {TOS} + +#ifndef NOFLOAT +from FREG to STACK +gen movf %1, {TOS} + +from DFREG to STACK +gen movl %1, {TOS} +#endif + +from MEMREG to STACK +gen addr {memregrel4, %1, 0}, {TOS} + +from addr_local to STACK +gen addr {memregrel4, fp, %1.ind}, {TOS} + +from regcon4 to STACK +gen addr {regrel4, %1.reg, %1.disp}, {TOS} + +from memregcon4 to STACK +gen addr {memregrel4, %1.reg, %1.disp}, {TOS} + +from memregrelcon4 to STACK +gen addr {memrel4, %1.reg, %1.disp1, %1.disp2}, {TOS} + +from DLOCAL to STACK +gen movd {LOCAL, %1.ind+4}, {TOS} + movd {LOCAL, %1.ind}, {TOS} + +from absolute8 to STACK +gen movd {absolute4, %1.disp+4}, {TOS} + movd {absolute4, %1.disp}, {TOS} + +from memrel8 to STACK +gen movd {memrel4, %1.reg, %1.disp1, %1.disp2+4}, {TOS} + movd {memrel4, %1.reg, %1.disp1, %1.disp2}, {TOS} + +from regrel8 to STACK +gen movd {regrel4, %1.reg, %1.disp+4}, {TOS} + movd {regrel4, %1.reg, %1.disp}, {TOS} + +from memregrel8 to STACK +gen movd {memregrel4, %1.reg, %1.disp+4}, {TOS} + movd {memregrel4, %1.reg, %1.disp}, {TOS} + +COERCIONS + + +from STACK +uses REG +gen move {TOS}, %a yields %a + +#ifndef NOFLOAT +from STACK +uses FREG +gen move {TOS}, %a yields %a + +from STACK +uses DFREG +gen move {TOS}, %a yields %a +#endif + +from STACK +uses REG +gen move {TOS}, %a yields {regcon4, %a, 0} + +from MEMREG yields {memregcon4, %1, 0} + +from MEMREG +uses REG +gen addr {memregrel4, %1, 0}, %a yields %a + +from REG yields {regcon4, %1, 0} + +from regcon4 +gen addr {regrel4, %1.reg, %1.disp}, %1.reg + yields %1.reg + +from memregcon4 +uses REG +gen addr {memregrel4, %1.reg, %1.disp}, %a + yields %a + +from LOCAL yields {memregrel4, fp, %1.ind} + +from addr_local +uses REG +gen addr {LOCAL, %1.ind}, %a yields %a + +from src4 +uses reusing %1, REG=%1 yields %a + +from src4 +uses reusing %1, REG=%1 yields {regcon4, %a, 0} + +from memregrelcon4 +uses REG +gen addr {memrel4, %1.reg, %1.disp1, %1.disp2}, %a + yields %a + +from memregrel4 yields {memregrelcon4, %1.reg, + %1.disp, 0} + +from src1 +uses REG + gen movzbd %1, %a yields %a + +from src2 +uses REG + gen movzwd %1, %a yields %a + +from DLOCAL yields {LOCAL, %1.ind+4} + {LOCAL, %1.ind} + +from absolute8 yields {absolute4, %1.disp+4} + {absolute4, %1.disp} + +from memrel8 yields {memrel4, %1.reg, + %1.disp1, %1.disp1+4} + {memrel4, %1.reg, + %1.disp1, %1.disp1} + +from regrel8 yields {regrel4, %1.reg, %1.disp+4} + {regrel4, %1.reg, %1.disp} + +from memregrel8 yields {memregrel4, %1.reg, %1.disp+4} + {memregrel4, %1.reg, %1.disp} + +PATTERNS + +/********************************************************************** + * Group1 : load instructions * + **********************************************************************/ + +pat loc yields {const4, $1} + +pat ldc leaving loc 18 + trp + +pat lol yields {LOCAL, $1} + +pat loe yields {absolute4, $1} + +pat lil yields {memrel4, fp, $1, 0} + +pat lol lof yields {memrel4, fp, $1, $2} + +pat lal lof yields {LOCAL, $1+$2} + +pat lae lof yields {absolute4, $1+$2} + +pat lof +with exact MEMREG yields {memregrel4, %1, 0} +with REG yields {regrel4, %1, $1} +with exact addr_external yields {absolute4, %1.disp+$1} +with exact addr_local yields {LOCAL, %1.ind+$1} +with exact memregrel4 yields {memrel4, %1.reg, + %1.disp, $1} +with exact memregrelcon4 yields {memrel4, %1.reg, + %1.disp1, $1+%1.disp2} +with exact memregcon4 yields {memregrel4, %1.reg, %1.disp+$1} +with exact regcon4 yields {regrel4, %1.reg, %1.disp+$1} +with exact LOCAL yields {memrel4, fp, %1.ind, $1} + +pat lxl $1==0 yields fp + +pat lxl $1==1 yields {LOCAL, 8} + +pat lxl $1==2 yields {memrel4, fp, 8, 8} + +pat lxl $1>2 + uses REG={memrel4, fp, 8, 8}, + REG={const4, $1-2} + gen 1: + move {regrel4, %a, 8}, %a + acbd {const4, 0-1}, %b, {label, "1b"} + yields %a + +pat lxa $1==0 yields {addr_local, 8} + +pat lxa $1==1 yields {memregrelcon4, fp, 8, 8} + +pat lxa $1==2 + uses REG={memrel4, fp, 8, 8} yields {regcon4, %a, 8} + +pat lxa $1>2 + uses REG={memrel4, fp, 8, 8}, + REG={const4, $1-2} + gen 1: + move {regrel4, %a, 8}, %a + acbd {const4, 0-1}, %b, {label, "1b"} + yields {regcon4, %a, 8} + +pat lol loi $2==1 yields {memrel1, fp, $1, 0} + +pat lal loi $2==1 yields {memregrel1, fp, $1} + +pat lae loi $2==1 yields {absolute1, $1} + +pat lol loi $2==4 yields {memrel4, fp, $1, 0} + +pat lal loi $2==4 yields {LOCAL, $1} + +pat lae loi $2==4 yields {absolute4, $1} + +pat lal yields {addr_local, $1} + +pat lae yields {addr_external, $1} + +pat loi $1==1 +with exact MEMREG yields {memregrel1, %1, 0} +with REG yields {regrel1, %1, 0} +with exact memregcon4 yields {memregrel1, %1.reg, %1.disp} +with exact regcon4 yields {regrel1, %1.reg, %1.disp} +with exact memregrel4 yields {memrel1, %1.reg, %1.disp, 0} +with exact memregrelcon4 yields {memrel1, %1.reg, + %1.disp1, %1.disp2} +with exact addr_local yields {memregrel1, fp, %1.ind} +with exact addr_external yields {absolute1, %1.disp} +with exact LOCAL yields {memrel1, fp, %1.ind, 0} + +pat loi $1==2 +with exact MEMREG yields {memregrel2, %1, 0} +with REG yields {regrel2, %1, 0} +with exact memregcon4 yields {memregrel2, %1.reg, %1.disp} +with exact regcon4 yields {regrel2, %1.reg, %1.disp} +with exact memregrel4 yields {memrel2, %1.reg, %1.disp, 0} +with exact memregrelcon4 yields {memrel2, %1.reg, + %1.disp1, %1.disp2} +with exact addr_local yields {memregrel2, fp, %1.ind} +with exact addr_external yields {absolute2, %1.disp} +with exact LOCAL yields {memrel2, fp, %1.ind, 0} + +pat loi $1==4 +with exact MEMREG yields {memregrel4, %1, 0} +with REG yields {regrel4, %1, 0} +with exact memregcon4 yields {memregrel4, %1.reg, %1.disp} +with exact regcon4 yields {regrel4, %1.reg, %1.disp} +with exact memregrel4 yields {memrel4,%1.reg,%1.disp,0} +with exact memregrelcon4 yields {memrel4, %1.reg, + %1.disp1,%1.disp2} +with exact addr_local yields {LOCAL, %1.ind} +with exact addr_external yields {absolute4, %1.disp} +with exact LOCAL yields {memrel4, fp, %1.ind, 0} + +pat loi $1==8 +with REG yields {regrel8, %1, 0} +with exact addr_local yields {DLOCAL, %1.ind} +with exact addr_external yields {absolute8, %1.disp} +with exact LOCAL yields {memrel8, fp, %1.ind, 0} + +pat loi defined($1) +with USELESS +with REG STACK + uses REG = {const4, $1} + gen addd %a, %1 + 1: + subd {const4, 4}, %1 + movd {regrel4, %1, 0}, {TOS} + acbd {const4, 0-4}, %a, {label, "1b"} + +pat los $1==4 +with STACK + gen jsr {absolute4, ".los"} + +pat ldl yields {DLOCAL, $1} + +pat lde yields {absolute8, $1} + +pat ldf +with exact addr_local yields {DLOCAL, %1.ind+$1} +with exact addr_external yields {absolute8, %1.disp+$1} +with regcon4 yields {regrel8, %1.reg, + %1.disp+$1} + +pat lpi yields {addr_external, $1} + + +/***************************************************************** + * Group2 : store instructions * + *****************************************************************/ + +pat stl +with src4 + con4 +kills rel, LOCAL %ind-4 < $1 && %ind+4 > $1 +gen move %1, {LOCAL, $1} +with exact STACK +gen move {TOS}, {LOCAL, $1} +with exact src1 +kills rel, LOCAL %ind-4 < $1 && %ind+4 > $1 +gen movzbd %1, {LOCAL, $1} +#ifndef NOFLOAT +with FREG +kills rel, LOCAL %ind-4 < $1 && %ind+4 > $1 +gen move %1, {LOCAL, $1} +#endif + +pat ste +with src4 + con4 +kills absolute + rel + memregrelcon4 +gen move %1, {absolute4, $1} +with exact src1 +kills absolute + rel + memregrelcon4 +gen movzbd %1, {absolute4, $1} +#ifndef NOFLOAT +with FREG +kills absolute + rel + memregrelcon4 +gen move %1, {absolute4, $1} +#endif + +pat sil +with src4 + con4 +kills allmincon +gen move %1, {memrel4, fp, $1, 0} +with exact src1 +kills allmincon +gen movzbd %1, {memrel4, fp, $1, 0} +#ifndef NOFLOAT +with FREG +kills allmincon +gen move %1, {memrel4, fp, $1, 0} +#endif + +pat stf +with exact MEMREG src4 + con4 + kills allmincon + gen move %2, {memregrel4, %1, $1} +with REG src4 + con4 + kills allmincon + gen move %2, {regrel4, %1, $1} +with exact memregcon4 src4 + con4 + kills allmincon + gen move %2, {memregrel4, %1.reg, $1 + %1.disp} +with exact regcon4 consrc4 + kills allmincon + gen move %2, {regrel4, %1.reg, $1 + %1.disp} +with exact memregrel4 consrc4 + kills allmincon + gen move %2, {memrel4, %1.reg, %1.disp, $1} +with exact memregrelcon4 consrc4 + kills allmincon + gen move %2, {memrel4, %1.reg, %1.disp1, %1.disp2 + $1} +with exact addr_external consrc4 + kills allmincon + gen move %2, {absolute4, %1.disp + $1} +with exact addr_local consrc4 + kills allmincon + gen move %2, {LOCAL,%1.ind + $1} +#ifndef NOFLOAT +with REG FREG + kills allmincon + gen move %2, {regrel4, %1, $1} +#endif + +pat lal sti $2==4 +with consrc4 + kills allmincon + gen move %1, {LOCAL, $1} + +pat lae sti $2==4 +with consrc4 + kills allmincon + gen move %1, {absolute4, $1} + +pat lol sti $2==4 +with consrc4 + kills allmincon + gen move %1, {memrel4, fp, $1, 0} + +pat lol sti $2==1 +with src124 + kills allmincon + gen move %1, {memrel1, fp, $1, 0} + +pat sti $1 == 4 +with exact MEMREG consrc4 + kills allmincon + gen move %2, {memregrel4, %1, 0} +with REG consrc4 + kills allmincon + gen move %2, {regrel4, %1, 0} +#ifndef NOFLOAT +with REG FREG + kills allmincon + gen movf %2, {regrel4, %1, 0} +#endif +with exact memregcon4 consrc4 + kills allmincon + gen move %2, {memregrel4, %1.reg, %1.disp} +with exact regcon4 consrc4 + kills allmincon + gen move %2, {regrel4, %1.reg, %1.disp} +with exact memregrel4 consrc4 + kills allmincon + gen move %2, {memrel4, %1.reg, %1.disp, 0} +with exact memregrelcon4 consrc4 + kills allmincon + gen move %2, {memrel4, %1.reg, %1.disp1, %1.disp2} +with exact addr_external consrc4 + kills allmincon + gen move %2, {absolute4, %1.disp} +with exact addr_local consrc4 + kills allmincon + gen move %2, {LOCAL, %1.ind} +with exact LOCAL consrc4 + kills allmincon + gen move %2, {memrel4, fp, %1.ind, 0} + +pat sti $1 == 2 +with regcon4 src24 + kills allmincon + gen move %2, {regrel2, %1.reg, %1.disp} +with exact addr_external src24 + kills allmincon + gen move %2, {absolute2, %1.disp} +with exact addr_local src24 + kills allmincon + gen move %2, {memregrel2, fp, %1.ind} + +pat sti $1 == 1 +with exact MEMREG src124 + kills allmincon + gen move %2, {memregrel1, %1, 0} +with REG src124 + kills allmincon + gen move %2, {regrel1, %1, 0} +with exact memregcon4 src124 + kills allmincon + gen move %2, {memregrel1, %1.reg, %1.disp} +with exact regcon4 src124 + kills allmincon + gen move %2, {regrel1, %1.reg, %1.disp} +with exact memregrel4 src124 + kills allmincon + gen move %2, {memrel1, %1.reg, %1.disp, 0} +with exact memregrelcon4 src124 + kills allmincon + gen move %2, {memrel1, %1.reg, %1.disp1, %1.disp2} +with exact addr_external src124 + kills allmincon + gen move %2, {absolute1, %1.disp} +with exact addr_local src124 + kills allmincon + gen move %2, {memregrel1, fp, %1.ind} +with exact LOCAL src124 + kills allmincon + gen move %2, {memrel1, fp, %1.ind, 0} + +pat sti $1==8 +#ifndef NOFLOAT +with regcon4 DFREG + kills allmincon + gen move %2, {regrel8, %1.reg, %1.disp} +with exact addr_external DFREG + kills allmincon + gen move %2, {absolute8, %1.disp} +with exact addr_local DFREG + kills allmincon + gen move %2, {memregrel8, fp, %1.ind} +#endif +with regcon4 consrc4 consrc4 + kills allmincon + gen move %1, {regrel4, %1.reg, %1.disp} + move %2, {regrel4, %1.reg, %1.disp+4} + +pat sti defined($1) +with USELESS +with REG STACK + uses REG={const4, $1} + gen 1: + movd {TOS}, {regrel4, %1, 0} + addr {regrel4, %1, 4}, %1 + acbd {const4, 0-4}, %a, {label, "1b"} + +pat sts +with STACK + gen jsr {absolute4, ".sts"} + +pat sdl +with consrc4 consrc4 +kills rel, LOCAL %ind-8 < $1 && %ind+8 > $1 +gen move %1, {LOCAL, $1} + move %2, {LOCAL, $1+4} +#ifndef NOFLOAT +with DFREG +kills rel, LOCAL %ind-8 < $1 && %ind+8 > $1 +gen move %1, {DLOCAL, $1} +#endif + +pat sde +with consrc4 consrc4 +kills absolute + rel + memregrelcon4 +gen move %1, {absolute4, $1} + move %2, {absolute4, $1+4} +#ifndef NOFLOAT +with DFREG +kills absolute + rel + memregrelcon4 +gen move %1, {absolute8, $1} +#endif + +pat sdf +with exact addr_local consrc4 consrc4 + kills allmincon + gen move %2, {LOCAL, %1.ind+$1} + move %3, {LOCAL, %1.ind+4+$1} +with exact addr_external consrc4 consrc4 + kills allmincon + gen move %2, {absolute4, %1.disp+$1} + move %3, {absolute4, %1.disp+4+$1} +with regcon4 consrc4 consrc4 + kills allmincon + gen move %2, {regrel4, %1.reg, %1.disp+$1} + move %3, {regrel4, %1.reg, %1.disp+$1+4} +#ifndef NOFLOAT +with exact addr_local DFREG + kills allmincon + gen move %2, {DLOCAL, %1.ind+$1} +with exact addr_external DFREG + kills allmincon + gen move %2, {absolute8, %1.disp+$1} +with exact regcon4 DFREG + kills allmincon + gen move %2, {regrel8, %1.reg, %1.disp+$1} +#endif + +/***************************************************************** + * Group3 : integer arithmetic * + *****************************************************************/ +pat loe loc adi ste $3==4 && $1==$4 +kills absolute + rel + memregrelcon4 +gen addd {const4, $2}, {absolute4, $1} + +pat lol loc adi stl $3==4 && $1==$4 +kills rel, LOCAL %ind-4 < $1 && %ind+4 > $1 +gen addd {const4, $2}, {LOCAL, $1} + +pat lil loc adi sil $3==4 && $1==$4 +kills allmincon +gen addd {const4, $2}, {memrel4, fp, $1, 0} + +pat lol adi stl $1==$3 && $2==4 +with src4 +kills rel, LOCAL %ind-4 < $1 && %ind+4 > $1 +gen addd %1, {LOCAL, $1} + +pat lil adi sil $1==$3 && $2==4 +with src4 +kills allmincon +gen addd %1, {memrel4, fp, $1, 0} + +pat loe adi ste $1==$3 && $2==4 +with src4 +kills absolute + rel + memregrelcon4 +gen addd %1, {absolute4, $1} + +pat adi $1 == 4 +with exact MEMREG const4 yields {memregcon4, %1, %2.num} +with exact REG const4 yields {regcon4, %1, %2.num} +with exact const4 REG yields {regcon4, %2, %1.num} +with exact memregrel4 const4 yields {memregrelcon4, %1.reg, + %1.disp, %2.num} +with exact memregcon4 const4 yields {memregcon4, %1.reg, + %1.disp + %2.num} +with exact regcon4 const4 yields {regcon4, %1.reg, + %1.disp + %2.num} +with exact memregrelcon4 const4 yields {memregrelcon4, %1.reg, + %1.disp1, %1.disp2+%2.num} +with exact addr_local const4 yields {addr_local, %1.ind+%2.num} +with exact LOCAL const4 yields {memregrelcon4, fp, + %1.ind, %2.num} +with exact const4 LOCAL yields {memregrelcon4, fp, + %2.ind, %1.num} +with exact const4 addr_local yields {addr_local, %2.ind+%1.num} +with exact MEMREG addr_external yields {memregcon4, %1, %2.disp} +with exact REG addr_external yields {regcon4, %1, %2.disp} +with exact memregrel4 addr_external yields {memregrelcon4, %1.reg, + %1.disp, %2.disp} +with exact memregcon4 addr_external yields {memregcon4, %1.reg, + %1.disp + %2.disp} +with exact regcon4 addr_external yields {regcon4, %1.reg, + %1.disp + %2.disp} +with exact memregrelcon4 addr_external yields {memregrelcon4, %1.reg, + %1.disp1, %1.disp2+%2.disp} +with src4 REG + gen addd %1, %2 yields %2 +with REG src4 + gen addd %2, %1 yields %1 + +pat loe loc sbi ste $3==4 && $1==$4 +kills absolute + rel + memregrelcon4 +gen addd {const4, 0-$2}, {absolute4, $1} + +pat lol loc sbi stl $3==4 && $1==$4 +kills rel, LOCAL %ind-4 < $1 && %ind+4 > $1 +gen addd {const4, 0-$2}, {LOCAL, $1} + +pat lil loc sbi sil $3==4 && $1==$4 +kills allmincon +gen addd {const4, 0-$2}, {memrel4, fp, $1, 0} + +pat sbi $1 == 4 +with src4 REG + gen subd %1, %2 yields %2 +with const4 REG + gen addd {const4, 0-%1.num}, %2 yields %2 +with exact addr_local addr_local + uses REG={const4, %2.ind} + gen subd {const4, %1.ind}, %a yields %a + +pat mli $1 == 4 +with src4 REG + gen muld %1, %2 yields %2 +with REG src4 + gen muld %2, %1 yields %1 + +pat dvi $1 == 4 +with src4 REG + gen quod %1,%2 yields %2 + +pat rmi $1 == 4 +with src4 REG + gen remd %1, %2 yields %2 + +pat ngi $1 == 4 +with src4 + uses reusing %1, REG + gen negd %1, %a yields %a + +pat lol ngi stl $1==$3 && $2==4 +kills rel, LOCAL %ind-4 < $1 && %ind+4 > $1 + gen negd {LOCAL, $1}, {LOCAL, $1} + +pat loe ngi ste $1==$3 && $2==4 +kills absolute + rel + memregrelcon4 + gen negd {absolute4, $1}, {absolute4, $1} + +pat lil ngi sil $1==$3 && $2==4 +kills allmincon + gen negd {memrel4, fp, $1, 0}, {memrel4, fp, $1, 0} + +pat sli $1 == 4 +with src124 REG + gen ashd %1, %2 yields %2 + +pat lol loc sli stl $1==$4 && $3==4 +kills rel, LOCAL %ind-4 < $1 && %ind+4 > $1 + gen ashd {const4, $2}, {LOCAL, $1} + +pat loe loc sli ste $1==$4 && $3==4 +kills absolute + rel + memregrelcon4 + gen ashd {const4, $2}, {absolute4, $1} + +pat loc sri $2 == 4 +with USELESS +with REG + gen ashd {const4,0-$1}, %1 yields %1 + +pat sri $1 == 4 +with USELESS +with REG REG +gen negd %1, %1 + ashd %1, %2 yields %2 + +pat lol loc sri stl $1==$4 && $3==4 +kills rel, LOCAL %ind-4 < $1 && %ind+4 > $1 + gen ashd {const4, 0-$2}, {LOCAL, $1} + +pat loe loc sri ste $1==$4 && $3==4 +kills absolute + rel + memregrelcon4 + gen ashd {const4, 0-$2}, {absolute4, $1} + + +/***************************************************************** + * Group4 : unsigned arithmetic * + *****************************************************************/ + +pat loe loc adu ste $3==4 && $1==$4 +kills absolute + rel + memregrelcon4 +gen addd {const4, $2}, {absolute4, $1} + +pat lol loc adu stl $3==4 && $1==$4 +kills rel, LOCAL %ind-4 < $1 && %ind+4 > $1 +gen addd {const4, $2}, {LOCAL, $1} + +pat lil loc adu sil $3==4 && $1==$4 +kills allmincon +gen addd {const4, $2}, {memrel4, fp, $1, 0} + +pat lol adu stl $1==$3 && $2==4 +with src4 +kills rel, LOCAL %ind-4 < $1 && %ind+4 > $1 +gen addd %1, {LOCAL, $1} + +pat lil adu sil $1==$3 && $2==4 +with src4 +kills allmincon +gen addd %1, {memrel4, fp, $1, 0} + +pat loe adu ste $1==$3 && $2==4 +with src4 +kills absolute + rel + memregrelcon4 +gen addd %1, {absolute4, $1} + +pat adu leaving adi $1 + +pat loe loc sbu ste $3==4 && $1==$4 +kills absolute + rel + memregrelcon4 +gen addd {const4, 0-$2}, {absolute4, $1} + +pat lol loc sbu stl $3==4 && $1==$4 +kills rel, LOCAL %ind-4 < $1 && %ind+4 > $1 +gen addd {const4, 0-$2}, {LOCAL, $1} + +pat lil loc sbu sil $3==4 && $1==$4 +kills allmincon +gen addd {const4, 0-$2}, {memrel4, fp, $1, 0} + +pat sbu leaving sbi $1 + +pat mlu $1 == 4 +with src4 src4 + uses reusing %1, REGPAIR + gen move %1, %a.1 + meid %2, %a yields %a.1 + +pat dvu $1 == 4 +with STACK + gen jsr {absolute4, ".dvu"} yields r0 + +pat rmu $1 == 4 +with STACK + gen jsr {absolute4, ".rmu"} yields r0 + +pat slu leaving sli $1 + +pat loc sru $2 == 4 +with USELESS +with REG + gen lshd {const4, 0-$1}, %1 yields %1 + +pat sru $1 == 4 +with USELESS +with REG REG + gen negd %1, %1 + lshd %1, %2 yields %2 + + +/***************************************************************** + * Group5 : floating point arithmetic * + *****************************************************************/ + +#ifndef NOFLOAT +pat adf $1==4 +with fsrc4 FREG + gen addf %1, %2 yields %2 + +pat adf $1==8 +with fsrc8 DFREG + gen addl %1, %2 yields %2 + +pat sbf $1==4 +with fsrc4 FREG + gen subf %1, %2 yields %2 + +pat sbf $1==8 +with fsrc8 DFREG + gen subl %1, %2 yields %2 + +pat mlf $1==4 +with fsrc4 FREG + gen mulf %1, %2 yields %2 + +pat mlf $1==8 +with fsrc8 DFREG + gen mull %1, %2 yields %2 + +pat dvf $1==4 +with fsrc4 FREG + gen divf %1, %2 yields %2 + +pat dvf $1==8 +with fsrc8 DFREG + gen divl %1, %2 yields %2 + +pat ngf $1==4 +with FREG + gen negf %1, %1 yields %1 + +pat ngf $1==8 +with DFREG + gen negl %1, %1 yields %1 + +pat fif $1==4 +with fsrc4 FREG +uses FREG, REG + gen mulf %1, %2 + truncfd %2, %b + movdf %b, %a + subf %a, %2 yields %a %2 + +pat fif $1==8 +with fsrc8 DFREG +uses DFREG, REG + gen mull %1, %2 + truncld %2, %b + movdl %b, %a + subl %a, %2 yields %a %2 + +pat fef $1==4 +with FREG +uses REG + gen movf %1, {TOS} + movf %1, {TOS} + lshd {const4, 1}, {TOS} + lshd {const4, 0-24}, {TOS} + movd {TOS}, %a + subd {const4, 127}, %a + ord {const4, 0x3F000000}, {TOS} + lshd {const4,2},{TOS} + lshd {const4,0-2},{TOS} + cbitd {const4, 23},{TOS} + movf {TOS}, %1 yields %1 %a + +pat fef $1==8 +with DFREG +uses REG + gen movl %1, {TOS} + movl %1, {TOS} + adjspd {const4, 0-4} + lshd {const4, 1}, {TOS} + lshd {const4, 0-21}, {TOS} + movd {TOS}, %a + subd {const4, 1023}, %a + ord {const4, 0x3FE00000}, {memregrel4, sp, 4} + lshd {const4,2},{memregrel4, sp, 4} + lshd {const4,0-2},{memregrel4, sp, 4} + cbitd {const4, 52},{TOS} + movl {TOS}, %1 yields %1 %a + +#else + +pat adf leaving loc 18 trp +pat sbf leaving loc 18 trp +pat mlf leaving loc 18 trp +pat dvf leaving loc 18 trp +pat ngf leaving loc 18 trp +pat fif leaving loc 18 trp +pat fef leaving loc 18 trp + +#endif + +/***************************************************************** + * Group6 : pointer arithmetic * + *****************************************************************/ + +pat lol lol adp stl $1==$2 && $2==$4 +kills allmincon +uses REG={LOCAL, $1} +gen addr {memrel4, fp, $1, $3}, {LOCAL, $1} yields %a + +pat loe loe adp ste $1==$2 && $2==$4 +kills allmincon +uses REG={absolute4, $1} +gen addd {const4, $3}, {absolute4, $1} + +pat lol adp stl $1==$3 +kills allmincon +gen addr {memrel4, fp, $1, $2}, {LOCAL, $1} + +pat loe adp ste $1==$3 +kills allmincon +gen addd {const4, $2}, {absolute4, $1} + +pat adp +with exact MEMREG yields {memregcon4, %1, $1} +with REG yields {regcon4, %1, $1} +with exact memregcon4 yields {memregcon4, %1.reg, + %1.disp + $1} +with exact regcon4 yields {regcon4, %1.reg, + %1.disp + $1} +with exact memregrel4 yields {memregrelcon4, %1.reg, + %1.disp, $1} +with exact memregrelcon4 yields {memregrelcon4, %1.reg, + %1.disp1, %1.disp2 + $1} +with exact addr_external yields {addr_external, $1+%1.disp} +with exact addr_local yields {addr_local, %1.ind + $1} +with exact LOCAL yields {memregrelcon4, fp, + %1.ind, $1} + +pat loe loc ads ste $3==4 && $1==$4 +kills absolute + rel + memregrelcon4 +gen addd {const4, $2}, {absolute4, $1} + +pat lol loc ads stl $3==4 && $1==$4 +kills rel, LOCAL %ind-4 < $1 && %ind+4 > $1 +gen addd {const4, $2}, {LOCAL, $1} + +pat lol ads stl $1==$3 && $2==4 +with src4 +kills rel, LOCAL %ind-4 < $1 && %ind+4 > $1 +gen addd %1, {LOCAL, $1} + +pat loe ads ste $1==$3 && $2==4 +with src4 +kills absolute + rel + memregrelcon4 +gen addd %1, {absolute4, $1} + +pat ads $1==4 leaving adi 4 + +pat sbs $1==4 leaving sbi 4 + +/***************************************************************** + * Group7 : increment/decrement/zero * + *****************************************************************/ + +pat inc +with USELESS +with REG + gen addd {const4,1}, %1 yields %1 +with exact STACK + gen addd {const4, 1},{TOS} + +pat loc inc yields {const4, $1+1} + +pat lol inc stl $1==$3 +kills allmincon +gen addd {const4, 1}, {LOCAL, $1} + +pat lol dec stl $1==$3 +kills allmincon +gen addd {const4, 0-1}, {LOCAL, $1} + +pat lil inc sil $1==$3 +kills allmincon +gen addd {const4, 1}, {memrel4, fp, $1, 0} + +pat lil dec sil $1==$3 +kills allmincon +gen addd {const4, 0-1}, {memrel4, fp, $1, 0} + +pat inl +kills rel, LOCAL %ind-4 < $1 && %ind+4 > $1 + gen addd {const4,1},{LOCAL, $1} + +pat ine +kills absolute, rel, memregrelcon4 + gen addd {const4,1},{absolute4, $1} + +pat dec +with USELESS +with REG + gen addd {const4,0-1}, %1 yields %1 +with exact STACK + gen addd {const4,0-1}, {TOS} + +pat loc dec yields {const4, $1-1} + +pat del +kills rel, LOCAL %ind-4 < $1 && %ind+4 > $1 + gen addd {const4,0-1},{LOCAL, $1} + +pat dee +kills absolute, rel, memregrelcon4 + gen addd {const4,0-1},{absolute4, $1} + +pat zrl +kills rel, LOCAL %ind-4 < $1 && %ind+4 > $1 + gen move {const4, 0}, {LOCAL, $1} + +pat zre +kills absolute, rel, memregrelcon4 + gen move {const4, 0}, {absolute4, $1} + +#ifndef NOFLOAT +pat zrf $1==4 +with STACK +gen movd {const4, 0}, {TOS} + +pat zrf $1==8 +with STACK +gen movd {const4, 0}, {TOS} + movd {const4, 0}, {TOS} +#else +pat zrf leaving loc 18 trp +#endif + +pat zer $1==4 yields {const4, 0} + +pat zer $1==8 yields {const4, 0} + {const4, 0} + +pat zer $1==12 yields {const4, 0} + {const4, 0} + {const4, 0} + +pat zer $1>12 +with STACK + uses REG={const4, $1/4} + gen 1: + movqd {const4, 0}, {TOS} + acbd {const4, 0-1}, %a, {label, "1b"} + +/***************************************************************** + * Group8 : convert * + *****************************************************************/ + +pat loc loc cii $1==4 && $2==4 + +pat loc loc cii $1==1 && $2==4 +with src124 +uses reusing %1, REG + gen movxbd %1, %a yields %a + +pat loc loc cii $1==2 && $2==4 +with src24 +uses reusing %1, REG + gen movxwd %1, %a yields %a + +pat cii +with STACK + gen jsr {absolute4, ".cii"} + +pat cui +with src4 src4 + +#ifndef NOFLOAT +pat loc loc cfi $1==8 && $2==4 +with fsrc8 +uses REG + gen roundld %1, %a yields %a + +pat loc loc cfi $1==4 && $2==4 +with fsrc4 +uses REG + gen roundfd %1, %a yields %a + +pat cfi +with STACK + gen jsr {absolute4, ".cfi"} + +pat loc loc cif $1==4 && $2==8 +with src4 +uses DFREG + gen movdl %1, %a yields %a + +pat loc loc cif $1==4 && $2==4 +with src4 +uses FREG + gen movdf %1, %a yields %a + +pat cif +with STACK + gen jsr {absolute4, ".cif"} + +pat cuf + leaving loc 18 trp + +pat loc loc cff $1==4 && $2==4 + +pat loc loc cff $1==8 && $2==8 + +pat loc loc cff $1==4 && $2==8 +with fsrc4 +uses DFREG + gen movfl %1, %a yields %a + +pat loc loc cff $1==8 && $2==4 +with fsrc8 +uses FREG + gen movlf %1, %a yields %a + +pat cff +with STACK + gen jsr {absolute4, ".cff"} + +#else + +pat cif leaving loc 18 trp +pat cfi leaving loc 18 trp +pat cuf leaving loc 18 trp +pat cfu leaving loc 18 trp +pat cff leaving loc 18 trp + +#endif +pat ciu +with src4 src4 + +pat cuu +with src4 src4 + +pat cfu + leaving loc 18 trp + +/***************************************************************** + * Group9 : logical * + *****************************************************************/ + +pat loe loc and ste $3==4 && $1==$4 +kills absolute + rel + memregrelcon4 +gen andd {const4, $2}, {absolute4, $1} + +pat lol loc and stl $3==4 && $1==$4 +kills rel, LOCAL %ind-4 < $1 && %ind+4 > $1 +gen andd {const4, $2}, {LOCAL, $1} + +pat lil loc and sil $3==4 && $1==$4 +kills allmincon +gen andd {const4, $2}, {memrel4, fp, $1, 0} + +pat lol and stl $1==$3 && $2==4 +with src4 +kills rel, LOCAL %ind-4 < $1 && %ind+4 > $1 +gen andd %1, {LOCAL, $1} + +pat lil and sil $1==$3 && $2==4 +with src4 +kills allmincon +gen andd %1, {memrel4, fp, $1, 0} + +pat loe and ste $1==$3 && $2==4 +with src4 +kills absolute + rel + memregrelcon4 +gen andd %1, {absolute4, $1} + +pat and $1==4 +with src4 REG + gen andd %1, %2 yields %2 +with REG src4 + gen andd %2, %1 yields %1 + +pat and $1>4 +with STACK + gen move {const4, $1}, r0 + addr {memregrel4, sp, $1}, r1 + 1: + andd {TOS}, {regrel4, r1, 0} + addr {regrel4, r1, 4}, r1 + acbd {const4, 0-4}, r0, {label, "1b"} + +pat lol ior stl $1==$3 && $2==4 +with src4 +kills rel, LOCAL %ind-4 < $1 && %ind+4 > $1 +gen ord %1, {LOCAL, $1} + +pat lol loc ior stl $3==4 && $1==$4 +kills rel, LOCAL %ind-4 < $1 && %ind+4 > $1 +gen ord {const4, $2}, {LOCAL, $1} + +pat lil loc ior sil $3==4 && $1==$4 +kills allmincon +gen ord {const4, $2}, {memrel4, fp, $1, 0} + +pat lil ior sil $1==$3 && $2==4 +with src4 +kills allmincon +gen ord %1, {memrel4, fp, $1, 0} + +pat loe ior ste $1==$3 && $2==4 +with src4 +kills absolute + rel + memregrelcon4 +gen ord %1, {absolute4, $1} + +pat lol loc xor stl $3==4 && $1==$4 +kills rel, LOCAL %ind-4 < $1 && %ind+4 > $1 +gen xord {const4, $2}, {LOCAL, $1} + +pat lil loc xor sil $3==4 && $1==$4 +kills allmincon +gen xord {const4, $2}, {memrel4, fp, $1, 0} + +pat lol xor stl $1==$3 && $2==4 +with src4 +kills rel, LOCAL %ind-4 < $1 && %ind+4 > $1 +gen xord %1, {LOCAL, $1} + +pat lil xor sil $1==$3 && $2==4 +with src4 +kills allmincon +gen xord %1, {memrel4, fp, $1, 0} + +pat loe xor ste $1==$3 && $2==4 +with src4 +kills absolute + rel + memregrelcon4 +gen xord %1, {absolute4, $1} + +pat ior $1==4 +with src4 REG + gen ord %1, %2 yields %2 +with REG src4 + gen ord %2, %1 yields %1 + +pat ior $1>4 +with STACK + gen move {const4, $1}, r0 + addr {memregrel4, sp, $1}, r1 + 1: + ord {TOS}, {regrel4, r1, 0} + addr {regrel4, r1, 4}, r1 + acbd {const4, 0-4}, r0, {label, "1b"} + +pat xor $1==4 +with src4 REG + gen xord %1, %2 yields %2 +with REG src4 + gen xord %2, %1 yields %1 + +pat xor $1>4 +with STACK + gen move {const4, $1}, r0 + addr {memregrel4, sp, $1}, r1 + 1: + xord {TOS}, {regrel4, r1, 0} + addr {regrel4, r1, 4}, r1 + acbd {const4, 0-4}, r0, {label, "1b"} + +pat com $1==4 +with USELESS +with REG + gen comd %1, %1 yields %1 + +pat com $1>4 +with STACK + gen move {const4, $1}, r0 + addr {memregrel4, sp, 0}, r1 + 1: + comd {regrel4, r1, 0}, {regrel4, r1, 0} + addr {regrel4, r1, 4}, r1 + acbd {const4, 0-4}, r0, {label, "1b"} + +pat rol $1 == 4 +with src124 REG + gen rotd %1, %2 yields %2 + +pat loc ror $2 == 4 +with USELESS +with REG + gen rotd {const4, 0-$1}, %1 yields %1 + +pat ror $1 == 4 +with USELESS +with REG REG + gen negd %1, %1 + rotd %1, %2 yields %2 + +/***************************************************************** + * Group10 : sets * + *****************************************************************/ + +pat inn zeq $1==4 +with src4 REG + gen cmpd {const4, 0}, %1 + bgt {label, $2} + tbitd %1, %2 + bfc {label, $2} + +pat inn zne $1==4 +with src4 REG + gen cmpd {const4, 0}, %1 + bgt {label, "1f"} + tbitd %1, %2 + bfs {label, $2} + 1: + +pat inn $1==4 +with src4 REG + uses REG + gen tbitd %1, %2 + sfsd %a + cmpd {const4,0}, %1 + ble {label, "1f"} + xord %a, %a + 1: yields %a + +pat inn $1>4 +with src4 STACK + uses REG + gen tbitd %1, {TOS} + adjspd {const4, 0-4} + sfsd %a + cmpd {const4,0}, %1 + ble {label, "1f"} + xord %a, %a + 1: yields %a + +pat inn !defined($1) +with src4 src4 STACK + uses REG + gen tbitd %2, {TOS} + adjspd {const4, 0-4} + sfsd %a + cmpd {const4,0}, %2 + ble {label, "1f"} + xord %a, %a + 1: yields %a + +pat set $1==4 +with src4 + uses REG={const4, 0} + gen sbitd %1, %a yields %a + +pat set $1>4 +with src4 STACK + uses REG={const4, $1/4} + gen 1: + movqd {const4, 0}, {TOS} + acbd {const4, 0-1}, %a, {label, "1b"} + sbitd %1, {TOS} + +pat set !defined($1) +with src4 src4 STACK + uses reusing %1, REG=%1 + gen quod {const4, 4}, %a + 1: + movqd {const4, 0}, {TOS} + acbd {const4, 0-1}, %a, {label, "1b"} + sbitd %2, {TOS} + +/***************************************************************** + * Group11 : array * + *****************************************************************/ + +pat lae aar $2==2 && rom($1,3)==1 && rom($1,1)==0 + leaving adi 2 + +pat lae aar $2==2 && rom($1,3)==1 && rom($1,1)!=0 + leaving adi 2 + adp 0-rom($1,1) + +pat lae aar $2==2 && rom($1,3)==2 && rom($1,1)==0 +with USELESS +with REG + gen ashd {const4, 1}, %1 yields %1 + leaving adi 2 + +pat lae aar $2==2 && rom($1,3)==2 && rom($1,1)!=0 +with USELESS +with REG + gen ashd {const4, 1}, %1 yields {regcon4, %1,(0-2)*rom($1,1)} + leaving adi 2 + +pat lae aar $2==4 && rom($1,3)==4 && rom($1,1)==0 +with USELESS +with REG addr_local +uses REG + gen addr {memregrelsid, %2.ind, fp, %1}, %a + yields %a +with REG addr_external +uses REG + gen addr {abssid, %2.disp, %1}, %a + yields %a +with leaving lae $1 aar $2 + +pat lae aar $2==4 && rom($1,3)==4 && rom($1,1)!=0 +with USELESS +with REG addr_local +uses REG + gen subd {const4, rom($1,1)}, %1 + addr {memregrelsid, %2.ind, fp, %1}, %a + yields %a +with REG addr_external +uses REG + gen subd {const4, rom($1,1)}, %1 + addr {abssid, %2.disp, %1}, %a + yields %a +with leaving lae $1 aar $2 + +pat lae lar $2==4 && rom($1,3)==4 && rom($1,1)==0 +with USELESS +with REG addr_local yields {memregrelsid, %2.ind, fp, %1} +with REG addr_external yields {abssid, %2.disp, %1} +with leaving lae $1 lar $2 + +pat lae lar $2==4 && rom($1,3)==4 && rom($1,1)!=0 +with USELESS +with REG addr_local + gen subd {const4, rom($1,1)}, %1 + yields {memregrelsid, %2.ind, fp, %1} +with REG addr_external + gen subd {const4, rom($1,1)}, %1 + yields {abssid, %2.disp, %1} +with leaving lae $1 lar $2 + +pat lae sar $2==4 && rom($1,3)==4 && rom($1,1)==0 +with src4 REG addr_local +kills allmincon + gen move %1, {memregrelsid, %3.ind, fp, %2} +with src4 REG addr_external +kills allmincon + gen move %1, {abssid, %3.disp, %2} +with leaving lae $1 sar $2 + +pat lae lar $2==4 && rom($1,3)==4 && rom($1,1)!=0 +with src4 REG addr_local +kills allmincon + gen subd {const4, rom($1,1)}, %2 + move %1, {memregrelsid, %3.ind, fp, %2} +with src4 REG addr_external +kills allmincon + gen subd {const4, rom($1,1)}, %2 + move %1, {abssid, %3.disp, %2} +with leaving lae $1 sar $2 + +pat lae aar $2==4 && rom($1,1)==0 +with src4 REG + gen indexd %2, {const4, rom($1,3)-1}, %1 yields %2 + +pat lae aar $2==4 && rom($1,1)!=0 +with USELESS +with REG REG + gen subd {const4,rom($1,1)}, %1 + indexd %2, {const4, rom($1,3)-1}, %1 yields %2 + +pat lae sar defined(rom($1,3)) + leaving lae $1 + aar $2 + sti rom($1,3) + +pat lae lar defined(rom($1,3)) + leaving lae $1 + aar $2 + loi rom($1,3) + +pat aar defined($1) +with STACK +gen jsr {absolute4, ".aar"} + +pat lar defined($1) +with STACK +gen jsr {absolute4, ".lar"} + +pat sar defined($1) +with STACK +gen jsr {absolute4, ".sar"} + +pat aar !defined($1) +with src4 STACK +gen jsr {absolute4, ".aar"} + +pat lar !defined($1) +with src4 STACK +gen jsr {absolute4, ".lar"} + +pat sar !defined($1) +with src4 STACK +gen jsr {absolute4, ".sar"} + +/***************************************************************** + * Group12 : compare * + *****************************************************************/ + +proc cmitxxand +with src4 src4 REG +gen cmpd %2, %1 + brxx* {label, "1f"} + xord %3, %3 + 1: + +proc cmitxxior +with src4 src4 REG +gen cmpd %2, %1 + brxx* {label, "1f"} + sbitd {const4, 0}, %3 + 1: + +proc txxand +with src4 REG +gen cmpd {const4, 0}, %1 + brxx* {label, "1f"} + xord %2, %2 + 1: + +proc txxior +with src4 REG +gen cmpd {const4, 0}, %1 + brxx* {label, "1f"} + sbitd {const4, 0}, %2 + 1: + +pat cmi tlt and $1==4 && $3==4 call cmitxxand("blt") +pat cmi tle and $1==4 && $3==4 call cmitxxand("ble") +pat cmi teq and $1==4 && $3==4 call cmitxxand("beq") +pat cmi tne and $1==4 && $3==4 call cmitxxand("bne") +pat cmi tge and $1==4 && $3==4 call cmitxxand("bge") +pat cmi tgt and $1==4 && $3==4 call cmitxxand("bgt") + +pat cmi tlt ior $1==4 && $3==4 call cmitxxior("blt") +pat cmi tle ior $1==4 && $3==4 call cmitxxior("ble") +pat cmi teq ior $1==4 && $3==4 call cmitxxior("beq") +pat cmi tne ior $1==4 && $3==4 call cmitxxior("bne") +pat cmi tge ior $1==4 && $3==4 call cmitxxior("bge") +pat cmi tgt ior $1==4 && $3==4 call cmitxxior("bgt") + +pat tlt and $2==4 call txxand("bgt") +pat tle and $2==4 call txxand("bge") +pat teq and $2==4 call txxand("beq") +pat tne and $2==4 call txxand("bne") +pat tge and $2==4 call txxand("ble") +pat tgt and $2==4 call txxand("blt") + +pat tlt ior $2==4 call txxior("bgt") +pat tle ior $2==4 call txxior("bge") +pat teq ior $2==4 call txxior("beq") +pat tne ior $2==4 call txxior("bne") +pat tge ior $2==4 call txxior("ble") +pat tgt ior $2==4 call txxior("blt") + +pat cmi $1==4 +with src4 REG + gen subd %1, %2 yields %2 + +#ifndef NOFLOAT +pat cmf $1==4 +with fsrc4 fsrc4 +uses REG = {const4, 0} + gen cmpf %1, %2 + beq {label, "1f"} + bgt {label, "2f"} + movd {const4, 1}, %a + br {label, "1f"} + 2: + movd {const4, 0-1}, %a + 1: yields %a + +pat cmf $1==8 +with fsrc8 fsrc8 +uses REG = {const4, 0} + gen cmpl %1, %2 + beq {label, "1f"} + bgt {label, "2f"} + movd {const4, 1}, %a + br {label, "1f"} + 2: + movd {const4, 0-1}, %a + 1: yields %a + +#else + +pat cmf leaving loc 18 trp + +#endif +pat cmu $1==4 +with src4 src4 + uses REG={const4, 0} + gen cmpd %2, %1 + blo {label, "1f"} + shid %a + br {label, "2f"} + 1: + addd {const4, 0-1}, %a + 2: yields %a + +pat cmu defined($1) +with STACK + gen move {const4, $1}, {TOS} + jsr {absolute4, ".cmu"} yields r1 + +pat cms $1==4 leaving cmi $1 + +pat cms $1!=4 +with STACK +gen move {const4, $1}, {TOS} + jsr {absolute4, ".cms"} yields r1 + +pat cms !defined($1) +with STACK +gen jsr {absolute4, ".cms"} yields r1 + +pat cmp +with exact addr_local addr_local yields {const4, %2.ind} + {const4, %1.ind} + leaving sbi 4 +with leaving cmu 4 + +proc txx +with src4 + uses REG + gen cmpqd {const4, 0}, %1 + sxx* %a yields %a + +pat tlt call txx("sgtd") +pat tle call txx("sged") +pat teq call txx("seqd") +pat tne call txx("sned") +pat tge call txx("sled") +pat tgt call txx("sltd") + +/***************************************************************** + * Group13 : branch * + *****************************************************************/ + +proc bxx example beq +with src4 src4 STACK + gen cmpd %2, %1 + brxx* {label, $1} +with exact src4 STACK + gen cmpd {TOS}, %1 + brxx* {label, $1} + +pat blt call bxx("blt") +pat ble call bxx("ble") +pat beq call bxx("beq") +pat bne call bxx("bne") +pat bge call bxx("bge") +pat bgt call bxx("bgt") + +pat bra +with STACK + gen br {label, $1} + +pat loc beq $1>=0 && $1<=127 +with exact src1 +kills ALL +gen cmpb {const4, $1}, %1 + beq {label, $2} +with yields {const4, $1} + leaving beq $2 + +pat loc bne $1>=0 && $1<=127 +with exact src1 +kills ALL +gen cmpb {const4, $1}, %1 + bne {label, $2} +with yields {const4, $1} + leaving bne $2 + +proc cmpzxx example cmp zeq +with src4 src4 STACK + gen cmpd %2,%1 + brxx* {label, $2} +with exact src4 STACK + gen cmpd {TOS}, %1 + brxx* {label, $2} +with exact addr_local addr_local + kills ALL + gen cmpd {const4, %2.ind}, {const4, %1.ind} + brxx* {label, $2} + +pat cmp zlt call cmpzxx("blo") +pat cmp zle call cmpzxx("bls") +pat cmp zeq call cmpzxx("beq") +pat cmp zne call cmpzxx("bne") +pat cmp zge call cmpzxx("bhs") +pat cmp zgt call cmpzxx("bhi") + +#ifndef NOFLOAT +proc cmf4zxx example cmf zeq +with fsrc4 fsrc4 STACK + gen cmpf %2,%1 + brxx* {label, $2} +with exact fsrc4 STACK + gen cmpf {TOS}, %1 + brxx* {label, $2} + +pat cmf zlt $1==4 call cmf4zxx("blo") +pat cmf zle $1==4 call cmf4zxx("bls") +pat cmf zeq $1==4 call cmf4zxx("beq") +pat cmf zne $1==4 call cmf4zxx("bne") +pat cmf zge $1==4 call cmf4zxx("bhs") +pat cmf zgt $1==4 call cmf4zxx("bhi") + +proc cmf8zxx example cmf zeq +with fsrc8 fsrc8 STACK + gen cmpl %2,%1 + brxx* {label, $2} +with exact fsrc8 STACK + gen cmpl {TOS}, %1 + brxx* {label, $2} + +pat cmf zlt $1==8 call cmf8zxx("blo") +pat cmf zle $1==8 call cmf8zxx("bls") +pat cmf zeq $1==8 call cmf8zxx("beq") +pat cmf zne $1==8 call cmf8zxx("bne") +pat cmf zge $1==8 call cmf8zxx("bhs") +pat cmf zgt $1==8 call cmf8zxx("bhi") +#endif + +proc zxx example zeq +with src4 STACK + gen cmpqd {const4,0}, %1 + brxx* {label, $1} +with exact STACK + gen cmpqd {const4,0}, {TOS} + brxx* {label, $1} + +pat zlt call zxx("bgt") +pat zle call zxx("bge") +pat zeq call zxx("beq") +pat zne call zxx("bne") +pat zge call zxx("ble") +pat zgt call zxx("blt") + +/***************************************************************** + * Group14 : procedure call * + *****************************************************************/ + +pat cal +with STACK + gen jsr {absolute4, $1} + +pat cai +with USELESS +with REG STACK + gen jsr %1 + +pat ret $1==0 +with STACK + gen exit {label, "[]"} + ret {const4, 0} + +pat ret $1==4 +with src4 STACK + gen move %1, r0 + exit {label, "[]"} + ret {const4, 0} + +pat ret $1==8 +with STACK + gen move {TOS}, r0 + move {TOS}, r1 + exit {label, "[]"} + ret {const4, 0} + +pat lfr $1==4 yields r0 + +pat lfr $1==8 yields r1 r0 + +/***************************************************************** + * Group15 : miscellaneous * + *****************************************************************/ + +pat asp +with STACK + gen adjspd {const4,0-$1} + +pat ass $1==4 +with USELESS +with REG STACK + gen negd %1, %1 + adjspd %1 +with const4 STACK + gen adjspd {const4,0-%1.num} + +pat blm $1==0 + +pat blm $1==4 +with USELESS +with REG REG +kills allmincon + gen move {regrel4, %2, 0}, {regrel4, %1, 0} + +pat blm $1>4 && $1<=16 +with USELESS +with REG REG +kills allmincon + gen movmd %2, %1, {const4, $1} +with exact addr_external addr_external +kills allmincon + gen movmd {absolute4, %2.disp}, {absolute4, %1.disp}, {const4, $1} +with exact addr_external addr_local +kills allmincon + gen movmd {LOCAL, %2.ind}, {absolute4, %1.disp}, {const4, $1} +with exact addr_local addr_external +kills allmincon + gen movmd {absolute4, %2.disp}, {LOCAL, %1.ind}, {const4, $1} +with exact addr_local addr_local +kills allmincon + gen movmd {LOCAL, %2.ind}, {LOCAL, %1.ind}, {const4, $1} + +pat blm $1>16 +with USELESS +with REG REG +kills allmincon + uses REG={const4,$1} + gen 1: + movd {regrel4, %2, 0}, {regrel4, %1, 0} + addr {regrel4, %1, 4}, %1 + addr {regrel4, %2, 4}, %2 + acbd {const4, 0-4}, %a, {label, "1b"} + +pat bls $1==4 +with USELESS +with REG +kills ALL + gen 1: + movd {memrel4, sp, 4, 0}, {memrel4, sp, 0, 0} + addr {memrel4, sp, 0, 4}, {memregrel4, sp, 0} + addr {memrel4, sp, 4, 4}, {memregrel4, sp, 4} + acbd {const4, 0-4}, %1, {label, "1b"} + adjspd {const4, 0-8} + +pat lae csa $2==4 +with src4 STACK + gen move %1, r0 + move {addr_external, $1}, r1 + jsr {absolute4, ".csa"} + +pat csa +with STACK + gen movd {TOS}, r1 + movd {TOS}, r0 + jsr {absolute4, ".csa"} + +pat lae csb $2==4 +with src4 STACK + gen move %1, r0 + move {addr_external, $1}, r1 + jsr {absolute4, ".csb"} + +pat csb +with STACK + gen movd {TOS}, r1 + movd {TOS}, r0 + jsr {absolute4, ".csb"} + +pat dch leaving loi 2 + +pat dup $1==4 +with src4 yields %1 %1 + +pat dup $1==8 +with src4 src4 yields %2 %1 %2 %1 +with exact DLOCAL yields %1 %1 +with exact absolute8 yields %1 %1 + +pat dup $1>8 +with STACK + gen move {const4, $1}, r0 + jsr {absolute4, ".dup"} + +pat dus $1==4 +with src4 STACK + gen move %1, r0 + jsr {absolute4, ".dup"} + +pat exg $1==4 +with src4 src4 yields %1 %2 + +pat exg $1==8 +with src4 src4 src4 src4 yields %2 %1 %4 %3 + +pat exg +with STACK + gen move {const4, $1}, r0 + jsr {absolute4, ".exg"} + +pat fil +gen move {addr_external, $1}, {absolute4, "hol0"+4} + +pat gto +with STACK + gen move {addr_external, $1}, r0 + br {label, ".gto"} + +pat lim yields {absolute2, ".ignmask"} + +pat lin +gen move {const4, $1}, {absolute4, "hol0"} + +pat lni +gen addd {const4, 1}, {absolute4, "hol0"} + +pat lor $1==0 yields fp + +pat lor $1==1 +with STACK yields sp + +pat lor $1==2 yields {absolute4, ".reghp"} + +pat lpb leaving adp 8 + +pat mon +with STACK +gen jsr {absolute4, ".mon"} + +pat nop +with STACK + gen move {absolute4, "hol0"}, {TOS} + jsr {absolute4, ".print"} + jsr {absolute4, ".prnl"} + +pat rck $1==4 +with STACK + gen jsr {absolute4, ".rck"} + +pat rtt leaving ret 0 + +pat sig +with src4 +uses REG + gen move {absolute4, ".trpreg"}, %a + move %1, {absolute4, ".trpreg"} yields %a + +pat sim +with src24 + gen movw %1, {absolute2, ".ignmask"} + +pat str $1==2 +with src4 +gen move %1, {absolute4, ".reghp"} + +pat trp +with STACK + gen jsr {absolute4, ".trp"} From a94fcddcf33941521a3709aa3e2711eab427b584 Mon Sep 17 00:00:00 2001 From: em Date: Fri, 26 Jul 1985 11:45:49 +0000 Subject: [PATCH 0059/1625] Added RCSID --- mach/ns/ncg/mach.c | 5 +++++ mach/ns/ncg/mach.h | 2 ++ mach/ns/ncg/table | 2 ++ 3 files changed, 9 insertions(+) diff --git a/mach/ns/ncg/mach.c b/mach/ns/ncg/mach.c index fd4b55ec..e875cf68 100644 --- a/mach/ns/ncg/mach.c +++ b/mach/ns/ncg/mach.c @@ -1,3 +1,8 @@ + +#ifndef NORCSID +static char rcsid[] = "$Header$" ; +#endif + con_part(sz, w) register int sz; word w; diff --git a/mach/ns/ncg/mach.h b/mach/ns/ncg/mach.h index d270fc56..91ce7f71 100644 --- a/mach/ns/ncg/mach.h +++ b/mach/ns/ncg/mach.h @@ -1,3 +1,5 @@ +/* $Header$ */ + #define ex_ap(y) fprintf(codefile,".extern %s\n",y) #define in_ap(y) /* nothing */ diff --git a/mach/ns/ncg/table b/mach/ns/ncg/table index a7e5b050..5e8f3ee1 100644 --- a/mach/ns/ncg/table +++ b/mach/ns/ncg/table @@ -1,3 +1,5 @@ +rcsid = "$Header$" + /***************************************************************** * * * N S 1 6 0 3 2 B A C K - E N D T A B L E * From b5338379c178aef042a9fd523c6ea3dad8a93788 Mon Sep 17 00:00:00 2001 From: em Date: Fri, 26 Jul 1985 11:47:54 +0000 Subject: [PATCH 0060/1625] Not using libmon. --- mach/ns/libcc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/ns/libcc/Makefile b/mach/ns/libcc/Makefile index a5cbcec5..323781a1 100644 --- a/mach/ns/libcc/Makefile +++ b/mach/ns/libcc/Makefile @@ -6,7 +6,7 @@ MON="PREF=mon" "SRC=lang/cem/libcc/mon" LIBM="PREF=m" "SRC=lang/cem/libcc/libm" LIBLN="PREF=ln" "SRC=lang/cem/libcc/libln" -install: cpstdio cpgen cpmon +install: cpstdio cpgen cpstdio: make -f $(MAKEFILE) $(STDIO) $(MACHDEF) tailcp From 901520e90a70b8052ce0a28e1a16486b9897d1ec Mon Sep 17 00:00:00 2001 From: em Date: Fri, 26 Jul 1985 11:56:24 +0000 Subject: [PATCH 0061/1625] Initial revision --- mach/ns/libem/LIST | 26 ++++++++++++++++++++ mach/ns/libem/Makefile | 18 ++++++++++++++ mach/ns/libem/aar.s | 10 ++++++++ mach/ns/libem/cff.s | 18 ++++++++++++++ mach/ns/libem/cfi.s | 15 ++++++++++++ mach/ns/libem/cif.s | 15 ++++++++++++ mach/ns/libem/cii.s | 28 ++++++++++++++++++++++ mach/ns/libem/cms.s | 25 +++++++++++++++++++ mach/ns/libem/cmu.s | 29 ++++++++++++++++++++++ mach/ns/libem/csa.s | 29 ++++++++++++++++++++++ mach/ns/libem/csb.s | 29 ++++++++++++++++++++++ mach/ns/libem/dup.s | 12 ++++++++++ mach/ns/libem/dvu.s | 21 ++++++++++++++++ mach/ns/libem/end.s | 15 ++++++++++++ mach/ns/libem/exg.s | 18 ++++++++++++++ mach/ns/libem/gto.s | 17 +++++++++++++ mach/ns/libem/lar.s | 15 ++++++++++++ mach/ns/libem/los.s | 26 ++++++++++++++++++++ mach/ns/libem/mon.s | 53 +++++++++++++++++++++++++++++++++++++++++ mach/ns/libem/print.s | 26 ++++++++++++++++++++ mach/ns/libem/prnl.s | 7 ++++++ mach/ns/libem/prstr.s | 18 ++++++++++++++ mach/ns/libem/putchar.s | 13 ++++++++++ mach/ns/libem/rck.s | 14 +++++++++++ mach/ns/libem/rmu.s | 16 +++++++++++++ mach/ns/libem/sar.s | 15 ++++++++++++ mach/ns/libem/sts.s | 27 +++++++++++++++++++++ mach/ns/libem/trp.s | 24 +++++++++++++++++++ 28 files changed, 579 insertions(+) create mode 100644 mach/ns/libem/LIST create mode 100644 mach/ns/libem/Makefile create mode 100644 mach/ns/libem/aar.s create mode 100644 mach/ns/libem/cff.s create mode 100644 mach/ns/libem/cfi.s create mode 100644 mach/ns/libem/cif.s create mode 100644 mach/ns/libem/cii.s create mode 100644 mach/ns/libem/cms.s create mode 100644 mach/ns/libem/cmu.s create mode 100644 mach/ns/libem/csa.s create mode 100644 mach/ns/libem/csb.s create mode 100644 mach/ns/libem/dup.s create mode 100644 mach/ns/libem/dvu.s create mode 100644 mach/ns/libem/end.s create mode 100644 mach/ns/libem/exg.s create mode 100644 mach/ns/libem/gto.s create mode 100644 mach/ns/libem/lar.s create mode 100644 mach/ns/libem/los.s create mode 100644 mach/ns/libem/mon.s create mode 100644 mach/ns/libem/print.s create mode 100644 mach/ns/libem/prnl.s create mode 100644 mach/ns/libem/prstr.s create mode 100644 mach/ns/libem/putchar.s create mode 100644 mach/ns/libem/rck.s create mode 100644 mach/ns/libem/rmu.s create mode 100644 mach/ns/libem/sar.s create mode 100644 mach/ns/libem/sts.s create mode 100644 mach/ns/libem/trp.s diff --git a/mach/ns/libem/LIST b/mach/ns/libem/LIST new file mode 100644 index 00000000..227c18ee --- /dev/null +++ b/mach/ns/libem/LIST @@ -0,0 +1,26 @@ +tail_em.a +dup.s +aar.s +lar.s +sar.s +los.s +rck.s +csb.s +csa.s +exg.s +sts.s +gto.s +cii.s +cms.s +mon.s +cmu.s +dvu.s +rmu.s +cff.s +cfi.s +cif.s +trp.s +print.s +prstr.s +prnl.s +putchar.s diff --git a/mach/ns/libem/Makefile b/mach/ns/libem/Makefile new file mode 100644 index 00000000..0a2dc3f5 --- /dev/null +++ b/mach/ns/libem/Makefile @@ -0,0 +1,18 @@ +# $Header$ +install: + arch t tail_em.a > LIST + ../../install tail_em.a tail_em + ../../install end.s tail_em.vend + +cmp: + -../../compare tail_em.a tail_em + -../../compare end.s end_em + +clean : + +opr : + make pr | opr + +pr: + @arch pv tail_em.a | pr -h `pwd`/tail_em.a + @pr `pwd`/end.s diff --git a/mach/ns/libem/aar.s b/mach/ns/libem/aar.s new file mode 100644 index 00000000..984c57f0 --- /dev/null +++ b/mach/ns/libem/aar.s @@ -0,0 +1,10 @@ +.define .aar + + .text + +.aar: + movd 8(sp), r7 + subd 0(4(sp)), r7 + muld 8(4(sp)), r7 + addd r7, 12(sp) + ret 8 diff --git a/mach/ns/libem/cff.s b/mach/ns/libem/cff.s new file mode 100644 index 00000000..f1cae1da --- /dev/null +++ b/mach/ns/libem/cff.s @@ -0,0 +1,18 @@ +.define .cff + + .text + +.cff : cmpd 4(sp), 8(sp) + beq 1f + cmpd 4, 4(sp) + beq 4f + cmpd 8, 4(sp) + beq 8f +1: + ret 8 +4: + movlf 12(sp),16(sp) + ret 12 +8: + movfl 12(sp), 8(sp) + ret 4 diff --git a/mach/ns/libem/cfi.s b/mach/ns/libem/cfi.s new file mode 100644 index 00000000..c0545626 --- /dev/null +++ b/mach/ns/libem/cfi.s @@ -0,0 +1,15 @@ +.define .cfi + + .text + +.cfi: cmpd 4, 8(sp) + beq 4f + cmpd 8, 8(sp) + beq 8f + ret 8 +4: + roundfd 12(sp),12(sp) + ret 8 +8: + roundld 12(sp), 16(sp) + ret 12 diff --git a/mach/ns/libem/cif.s b/mach/ns/libem/cif.s new file mode 100644 index 00000000..82098184 --- /dev/null +++ b/mach/ns/libem/cif.s @@ -0,0 +1,15 @@ +.define .cif + + .text + +.cif : cmpd 4, 4(sp) + beq 4f + cmpd 8, 4(sp) + beq 8f + ret 8 +4: + movdf 12(sp),12(sp) + ret 8 +8: + movdl 12(sp), 8(sp) + ret 4 diff --git a/mach/ns/libem/cii.s b/mach/ns/libem/cii.s new file mode 100644 index 00000000..d25b5fa2 --- /dev/null +++ b/mach/ns/libem/cii.s @@ -0,0 +1,28 @@ +.define .cii + + .text + +!r7 will save return addres +.cii: + movd tos, r7 + cmpqd 4, tos + bne 3f + movd tos, r0 + cmpqd 1, r0 + beq 1f + cmpqd 2, r0 + beq 2f + cmpqd 4, r0 + beq 4f +3: + movd EILLINS, tos + jsr @.trp +4: + movd r7, tos + ret 0 +1: + movxbd 0(sp), 0(sp) + br 4b +2: + movxwd 0(sp), 0(sp) + br 4b diff --git a/mach/ns/libem/cms.s b/mach/ns/libem/cms.s new file mode 100644 index 00000000..e8b0d501 --- /dev/null +++ b/mach/ns/libem/cms.s @@ -0,0 +1,25 @@ +.define .cms + + .text + +.cms: movd tos, r7 !return addres + addr 4(sp), r1 + movd r1, r2 + addd 0(sp), r2 + movd 0(sp), r0 + muld -2, r0 + subd 4, r0 +3: + cmpd 0(r2), 0(r1) + bne 2f + addr 4(r1), r1 + addr 4(r2), r2 + acbd -4, 0(sp), 3b + xord r1, r1 +4: + adjspd r0 + movd r7, tos + ret 0 +2: + movd 1, r1 + br 4b diff --git a/mach/ns/libem/cmu.s b/mach/ns/libem/cmu.s new file mode 100644 index 00000000..66d381c4 --- /dev/null +++ b/mach/ns/libem/cmu.s @@ -0,0 +1,29 @@ +.define .cmu + + .text + +.cmu: movd tos, r7 !return addres + addr 4(sp), r1 + movd r1, r2 + addd 0(sp), r2 + movd 0(sp), r0 + muld -2, r0 + subd 4, r0 +3: + cmpd 0(r2), 0(r1) + bhi 1f + blo 2f + addr 4(r1), r1 + addr 4(r2), r2 + acbd -4, 0(sp), 3b + xord r1, r1 +4: + adjspd r0 + movd r7, tos + ret 0 +1: + movd 1, r1 + br 4b +2: + movd -1, r1 + br 4b diff --git a/mach/ns/libem/csa.s b/mach/ns/libem/csa.s new file mode 100644 index 00000000..5f16e4b0 --- /dev/null +++ b/mach/ns/libem/csa.s @@ -0,0 +1,29 @@ +.define .csa + + .text + +!r0 contains index +!r1 contains pointer to csa descriptor +.csa: movd 4(r1), r2 !get lower bound + cmpd r2, r0 + bgt 1f !index out of range + addd 8(r1), r2 !get upper bound + cmpd r2, r0 + blt 1f !index out of range + addr 12(r1), r2 !pointer to first pointer + subd 4(r1), r0 + muld 4, r0 + addd r0,r2 !right pointer + cmpqd 0, 0(r2) + beq 1f !null pointer + movd 0(r2), tos !jump now + ret 4 +1: !jump to default pointer + cmpqd 0, 0(r1) + beq 2f !null pointer + movd 0(r1), tos + ret 4 +2: + movd ECASE, tos + jsr @.trp + ret 0 diff --git a/mach/ns/libem/csb.s b/mach/ns/libem/csb.s new file mode 100644 index 00000000..15bf815e --- /dev/null +++ b/mach/ns/libem/csb.s @@ -0,0 +1,29 @@ +.define .csb + + .text + +!r0 contains index +!r1 contains pointer to csb descriptor +.csb: + save[r2,r3] + movd 4(r1), r2 !number of entries + movd r1, r3 +1: + addd 8, r3 !find addres of next index + cmpd 0(r3), r0 !compare indices + beq 2f + acbd -1, r2, 1b +3: !r1 now contains right pointer + cmpqd 0, 0(r1) !test destination addres + beq 4f + restore[r2,r3] + movd 0(r1), tos !jump to destination + ret 4 +2: + addr 4(r3), r1 !put destination pointer in r1 + br 3b +4: + movd ECASE, tos + jsr @.trp + restore[r2,r3] + ret 0 diff --git a/mach/ns/libem/dup.s b/mach/ns/libem/dup.s new file mode 100644 index 00000000..9252019d --- /dev/null +++ b/mach/ns/libem/dup.s @@ -0,0 +1,12 @@ +.define .dup + + .text + +!r2 will save return addres +.dup: + movd tos, r2 + addr 0(sp), tos + movd r0, tos + jsr @.los + movd r2, tos + ret 0 diff --git a/mach/ns/libem/dvu.s b/mach/ns/libem/dvu.s new file mode 100644 index 00000000..34b8ba40 --- /dev/null +++ b/mach/ns/libem/dvu.s @@ -0,0 +1,21 @@ +.define .dvu + + .text + +.dvu: + enter[r1,r2],0 + movd 1,r2 + andd 12(fp), r2 + movd 12(fp), r0 + lshd -1,r0 + quod 8(fp), r0 + lshd 1,r0 + movd 12(fp), r1 + lshd -1,r1 + remd 8(fp), r1 + lshd 1,r1 + addd r2, r1 + quod 8(fp),r1 + addd r1, r0 + exit[r1,r2] + ret 8 diff --git a/mach/ns/libem/end.s b/mach/ns/libem/end.s new file mode 100644 index 00000000..9225bd8c --- /dev/null +++ b/mach/ns/libem/end.s @@ -0,0 +1,15 @@ +.define endtext,enddata,endbss +.define _end, _etext, _edata + + .text +endtext: +_etext: + .align 4 + .data +enddata: +_edata: + .align 4 + .bss + .align 4 +endbss: +_end: diff --git a/mach/ns/libem/exg.s b/mach/ns/libem/exg.s new file mode 100644 index 00000000..47bc38e3 --- /dev/null +++ b/mach/ns/libem/exg.s @@ -0,0 +1,18 @@ +.define .exg + + .text + +.exg: + save [r2,r3] + addr 8(sp), r3 + movd r3, r2 + addd r0, r3 +1: + movd 0(r2), r1 + movd 0(r3), 0(r2) + movd r1, 0(r3) + addr 4(r2), r2 + addr 4(r3), r3 + acbd -4, r0, 1b + restore[r2,r3] + ret 0 diff --git a/mach/ns/libem/gto.s b/mach/ns/libem/gto.s new file mode 100644 index 00000000..8d019990 --- /dev/null +++ b/mach/ns/libem/gto.s @@ -0,0 +1,17 @@ +.define .gto + + .text + +!r0 contains descriptor addres +.gto: + addr 0(sp), r7 !first put future localbase in sp + subd 8(r0), r7 + subd 4, r7 + adjspd r7 !done + movd -4(sp), r1 !save this memory location + enter[], 0 !adjust local base + movd r1, 0(sp) !restore saved memory location + addr 0(sp), r7 !adjust stackpointer now + subd 4(r0), r7 + adjspd r7 + jump r0 !adjust programcounter diff --git a/mach/ns/libem/lar.s b/mach/ns/libem/lar.s new file mode 100644 index 00000000..8de2d964 --- /dev/null +++ b/mach/ns/libem/lar.s @@ -0,0 +1,15 @@ +.define .lar + + .text + +.lar: + movd tos, r2 + movd 4(sp), r0 + subd 0(0(sp)), r0 + muld 8(0(sp)), r0 + addd r0, 8(sp) + movd 8(0(sp)), 4(sp) + adjspd -4 + jsr @.los + movd r2, tos + ret 0 diff --git a/mach/ns/libem/los.s b/mach/ns/libem/los.s new file mode 100644 index 00000000..daf36cfb --- /dev/null +++ b/mach/ns/libem/los.s @@ -0,0 +1,26 @@ +.define .los + + .text + +.los: + movd tos, r7 + movd tos, r0 + movd tos, r1 + cmpqd 1, r0 + beq 1f + cmpqd 2, r0 + beq 2f + addd r0, r1 +3: + addqd -4, r1 + movd 0(r1), tos + acbd -4, r0, 3b +4: + movd r7, tos + ret 0 +1: + movzbd 0(r1), tos + br 4b +2: + movzwd 0(r1), tos + br 4b diff --git a/mach/ns/libem/mon.s b/mach/ns/libem/mon.s new file mode 100644 index 00000000..57ef54a5 --- /dev/null +++ b/mach/ns/libem/mon.s @@ -0,0 +1,53 @@ +.define .mon + + .text + +.mon: + cmpd 1,4(sp) + beq 1f + cmpd 3,4(sp) + beq 3f + cmpd 4,4(sp) + beq 4f + cmpd 54,4(sp) + beq 5f + + movd .add1, tos + jsr @.prstr + movd 4(sp), tos + jsr @.print + movd .add2, tos + jsr @.prstr + ret 4 + +1: jump @.stop + +3: save [r0,r1,r2,r3] + movd 3,r0 + movd 28(sp),r1 + movd 32(sp),r2 + movd 0,r3 + svc + movd r2, 32(sp) + movd 0,28(sp) + restore [r0,r1,r2,r3] + ret 8 + +4: save [r0,r1,r2,r3] + movd 4,r0 + movd 28(sp),r1 + movd 32(sp),r2 + movd 0,r3 + svc + movd r2, 32(sp) + movd 0,28(sp) + restore [r0,r1,r2,r3] + ret 8 + +5: movd 0, 16(sp) + ret 12 + +.data +.add1: .asciz "monitor call " +.add2: .asciz " not implemented\n" +.align diff --git a/mach/ns/libem/print.s b/mach/ns/libem/print.s new file mode 100644 index 00000000..fa44c1ff --- /dev/null +++ b/mach/ns/libem/print.s @@ -0,0 +1,26 @@ +.define .print + + .text + +.print: + save[r0,r1,r2] + movd 16(sp), r0 + movd 1000000000, r2 + cmpqd 0, r0 + ble 4f + movb "-", tos + jsr @.putchar + negd r0, r0 +4: +! deid r2, r0 + movd r0, r1 + divd r2, r1 + modd r2, r0 + addb "0", r1 + movb r1, tos + jsr @.putchar + divd 10, r2 + cmpqd 0, r2 + bne 4b + restore[r0,r1,r2] + ret 4 diff --git a/mach/ns/libem/prnl.s b/mach/ns/libem/prnl.s new file mode 100644 index 00000000..62130484 --- /dev/null +++ b/mach/ns/libem/prnl.s @@ -0,0 +1,7 @@ +.define .prnl + + .text + +.prnl: movb "\n", tos + jsr @.putchar + ret 0 diff --git a/mach/ns/libem/prstr.s b/mach/ns/libem/prstr.s new file mode 100644 index 00000000..8d7a61aa --- /dev/null +++ b/mach/ns/libem/prstr.s @@ -0,0 +1,18 @@ +.define .prstr + + .text + +!het adres van de af te drukken string staat op de stack. +.prstr: + save [r1] + movd 8(sp), r1 +1: + cmpqb 0, 0(r1) + beq 2f + movb 0(r1), tos + jsr @.putchar + addqd 1, r1 + br 1b +2: + restore [r1] + ret 4 diff --git a/mach/ns/libem/putchar.s b/mach/ns/libem/putchar.s new file mode 100644 index 00000000..d5fe98f2 --- /dev/null +++ b/mach/ns/libem/putchar.s @@ -0,0 +1,13 @@ +.define .putchar + + .text + +.putchar: + save [r0, r1, r2, r3] + movqd 4, r0 + addr 20(sp), r1 + movqd 1, r2 + xord r3, r3 + svc + restore[r0,r1,r2,r3] + ret 1 diff --git a/mach/ns/libem/rck.s b/mach/ns/libem/rck.s new file mode 100644 index 00000000..8a22761a --- /dev/null +++ b/mach/ns/libem/rck.s @@ -0,0 +1,14 @@ +.define .rck + + .text + +.rck: + cmpd 0(4(sp)), 8(sp) + bgt 1f + cmpd 4(4(sp)), 8(sp) + bge 2f +1: + movd ERANGE, tos + jsr @.trp +2: + ret 4 diff --git a/mach/ns/libem/rmu.s b/mach/ns/libem/rmu.s new file mode 100644 index 00000000..670a606f --- /dev/null +++ b/mach/ns/libem/rmu.s @@ -0,0 +1,16 @@ +.define .rmu + + .text + +.rmu: + enter[r2],0 + movd 1,r2 + andd 12(fp),r2 + movd 12(fp),r0 + lshd -1,r0 + remd 8(fp),r0 + lshd 1,r0 + addd r2,r0 + remd 8(fp), r0 + exit[r2] + ret 8 diff --git a/mach/ns/libem/sar.s b/mach/ns/libem/sar.s new file mode 100644 index 00000000..fe94845b --- /dev/null +++ b/mach/ns/libem/sar.s @@ -0,0 +1,15 @@ +.define .sar + + .text + +.sar: + movd tos, r2 + movd 4(sp), r0 + subd 0(0(sp)), r0 + muld 8(0(sp)), r0 + addd r0, 8(sp) + movd 8(0(sp)), 4(sp) + adjspd -4 + jsr @.sts + movd r2, tos + ret 0 diff --git a/mach/ns/libem/sts.s b/mach/ns/libem/sts.s new file mode 100644 index 00000000..b95f0ecd --- /dev/null +++ b/mach/ns/libem/sts.s @@ -0,0 +1,27 @@ +.define .sts + + .text + +.sts: + movd tos, r7 + movd tos, r0 + movd tos, r1 + cmpqd 1, r0 + beq 1f + cmpqd 2, r0 + beq 2f +3: + movd tos, 0(r1) + addqd 4, r1 + acbd -4, r0, 3b +4: + movd r7, tos + ret 0 +1: + movb tos, 0(r1) + adjspd -3 + br 4b +2: + movw tos, 0(r1) + adjspd -2 + br 4b diff --git a/mach/ns/libem/trp.s b/mach/ns/libem/trp.s new file mode 100644 index 00000000..cea74e4e --- /dev/null +++ b/mach/ns/libem/trp.s @@ -0,0 +1,24 @@ +.define .trp + + .text + +.trp: + save [r0, r1] + movd 12(sp), r0 !error number + cmpd r0, 16 + bge 1f + sbitd r0, r1 + andw @.ignmask, r1 + beq 1f + br 3f !do not trap +1: !do trap + movd @.trpreg, r1 + cmpqd 0, r1 + beq 2f + movqd 0, @.trpreg + jsr r1 +3: + restore [r0, r1] + ret 4 +2: + jump @.stop !no trapprocedure supplied From 36594308d35a7bcb9a495fdd071d7d2f27de31c5 Mon Sep 17 00:00:00 2001 From: em Date: Fri, 26 Jul 1985 12:51:45 +0000 Subject: [PATCH 0062/1625] *** empty log message *** --- mach/ns/libsys/_exit.s | 8 ++ mach/ns/libsys/access.s | 20 +++++ mach/ns/libsys/acct.s | 19 +++++ mach/ns/libsys/alarm.s | 12 +++ mach/ns/libsys/brk.s | 9 +++ mach/ns/libsys/chdir.s | 19 +++++ mach/ns/libsys/chmod.s | 20 +++++ mach/ns/libsys/chown.s | 25 ++++++ mach/ns/libsys/chroot.s | 19 +++++ mach/ns/libsys/cleanup.s | 7 ++ mach/ns/libsys/close.s | 6 ++ mach/ns/libsys/creat.s | 19 +++++ mach/ns/libsys/dup.s | 19 +++++ mach/ns/libsys/dup2.s | 21 ++++++ mach/ns/libsys/errno.s | 5 ++ mach/ns/libsys/execl.s | 15 ++++ mach/ns/libsys/execle.s | 26 +++++++ mach/ns/libsys/execv.s | 15 ++++ mach/ns/libsys/execve.s | 19 +++++ mach/ns/libsys/exit.s | 11 +++ mach/ns/libsys/fork.s | 29 +++++++ mach/ns/libsys/fstat.s | 20 +++++ mach/ns/libsys/ftime.s | 10 +++ mach/ns/libsys/getegid.s | 11 +++ mach/ns/libsys/geteuid.s | 11 +++ mach/ns/libsys/getgid.s | 12 +++ mach/ns/libsys/getpid.s | 11 +++ mach/ns/libsys/getuid.s | 12 +++ mach/ns/libsys/gtty.s | 12 +++ mach/ns/libsys/ioctl.s | 25 ++++++ mach/ns/libsys/kill.s | 20 +++++ mach/ns/libsys/link.s | 20 +++++ mach/ns/libsys/lock.s | 19 +++++ mach/ns/libsys/lseek.s | 24 ++++++ mach/ns/libsys/mknod.s | 25 ++++++ mach/ns/libsys/mount.s | 25 ++++++ mach/ns/libsys/mpxcall.s | 20 +++++ mach/ns/libsys/nice.s | 10 +++ mach/ns/libsys/open.s | 19 +++++ mach/ns/libsys/pause.s | 9 +++ mach/ns/libsys/pipe.s | 23 ++++++ mach/ns/libsys/prof.s | 16 ++++ mach/ns/libsys/ptrace.s | 25 ++++++ mach/ns/libsys/read.s | 15 ++++ mach/ns/libsys/sbrk.s | 11 +++ mach/ns/libsys/setgid.s | 19 +++++ mach/ns/libsys/setsig.s | 39 ++++++++++ mach/ns/libsys/setuid.s | 19 +++++ mach/ns/libsys/signal.s | 159 +++++++++++++++++++++++++++++++++++++++ mach/ns/libsys/sigtrp.s | 19 +++++ mach/ns/libsys/stat.s | 20 +++++ mach/ns/libsys/stime.s | 19 +++++ mach/ns/libsys/stty.s | 12 +++ mach/ns/libsys/sync.s | 9 +++ mach/ns/libsys/tell.s | 12 +++ mach/ns/libsys/time.s | 15 ++++ mach/ns/libsys/times.s | 10 +++ mach/ns/libsys/umask.s | 12 +++ mach/ns/libsys/umount.s | 19 +++++ mach/ns/libsys/unlink.s | 19 +++++ mach/ns/libsys/utime.s | 20 +++++ mach/ns/libsys/wait.s | 29 +++++++ mach/ns/libsys/write.s | 15 ++++ 63 files changed, 1214 insertions(+) create mode 100644 mach/ns/libsys/_exit.s create mode 100644 mach/ns/libsys/access.s create mode 100644 mach/ns/libsys/acct.s create mode 100644 mach/ns/libsys/alarm.s create mode 100644 mach/ns/libsys/brk.s create mode 100644 mach/ns/libsys/chdir.s create mode 100644 mach/ns/libsys/chmod.s create mode 100644 mach/ns/libsys/chown.s create mode 100644 mach/ns/libsys/chroot.s create mode 100644 mach/ns/libsys/cleanup.s create mode 100644 mach/ns/libsys/close.s create mode 100644 mach/ns/libsys/creat.s create mode 100644 mach/ns/libsys/dup.s create mode 100644 mach/ns/libsys/dup2.s create mode 100644 mach/ns/libsys/errno.s create mode 100644 mach/ns/libsys/execl.s create mode 100644 mach/ns/libsys/execle.s create mode 100644 mach/ns/libsys/execv.s create mode 100644 mach/ns/libsys/execve.s create mode 100644 mach/ns/libsys/exit.s create mode 100644 mach/ns/libsys/fork.s create mode 100644 mach/ns/libsys/fstat.s create mode 100644 mach/ns/libsys/ftime.s create mode 100644 mach/ns/libsys/getegid.s create mode 100644 mach/ns/libsys/geteuid.s create mode 100644 mach/ns/libsys/getgid.s create mode 100644 mach/ns/libsys/getpid.s create mode 100644 mach/ns/libsys/getuid.s create mode 100644 mach/ns/libsys/gtty.s create mode 100644 mach/ns/libsys/ioctl.s create mode 100644 mach/ns/libsys/kill.s create mode 100644 mach/ns/libsys/link.s create mode 100644 mach/ns/libsys/lock.s create mode 100644 mach/ns/libsys/lseek.s create mode 100644 mach/ns/libsys/mknod.s create mode 100644 mach/ns/libsys/mount.s create mode 100644 mach/ns/libsys/mpxcall.s create mode 100644 mach/ns/libsys/nice.s create mode 100644 mach/ns/libsys/open.s create mode 100644 mach/ns/libsys/pause.s create mode 100644 mach/ns/libsys/pipe.s create mode 100644 mach/ns/libsys/prof.s create mode 100644 mach/ns/libsys/ptrace.s create mode 100644 mach/ns/libsys/read.s create mode 100644 mach/ns/libsys/sbrk.s create mode 100644 mach/ns/libsys/setgid.s create mode 100644 mach/ns/libsys/setsig.s create mode 100644 mach/ns/libsys/setuid.s create mode 100644 mach/ns/libsys/signal.s create mode 100644 mach/ns/libsys/sigtrp.s create mode 100644 mach/ns/libsys/stat.s create mode 100644 mach/ns/libsys/stime.s create mode 100644 mach/ns/libsys/stty.s create mode 100644 mach/ns/libsys/sync.s create mode 100644 mach/ns/libsys/tell.s create mode 100644 mach/ns/libsys/time.s create mode 100644 mach/ns/libsys/times.s create mode 100644 mach/ns/libsys/umask.s create mode 100644 mach/ns/libsys/umount.s create mode 100644 mach/ns/libsys/unlink.s create mode 100644 mach/ns/libsys/utime.s create mode 100644 mach/ns/libsys/wait.s create mode 100644 mach/ns/libsys/write.s diff --git a/mach/ns/libsys/_exit.s b/mach/ns/libsys/_exit.s new file mode 100644 index 00000000..bcc38fd8 --- /dev/null +++ b/mach/ns/libsys/_exit.s @@ -0,0 +1,8 @@ +.define __exit +.extern __exit +.text +__exit: +enter[], 0 +movd 8(fp),tos +movd 1,tos +jsr @.mon diff --git a/mach/ns/libsys/access.s b/mach/ns/libsys/access.s new file mode 100644 index 00000000..0f2d0f7f --- /dev/null +++ b/mach/ns/libsys/access.s @@ -0,0 +1,20 @@ +.define _access +.extern _access +.text +_access: +enter[], 0 +movd 12(fp),tos +movd 8(fp),tos +movd 33,tos +jsr @.mon +cmpqd 0,tos +bne I0011 +movd 0,r4 +exit [] +ret 0 +I0011: +movd tos,r7 +movd r7,@_errno +movd -1,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/acct.s b/mach/ns/libsys/acct.s new file mode 100644 index 00000000..f7afd78a --- /dev/null +++ b/mach/ns/libsys/acct.s @@ -0,0 +1,19 @@ +.define _acct +.extern _acct +.text +_acct: +enter[], 0 +movd 8(fp),tos +movd 51,tos +jsr @.mon +cmpqd 0,tos +bne I0011 +movd 0,r4 +exit [] +ret 0 +I0011: +movd tos,r7 +movd r7,@_errno +movd -1,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/alarm.s b/mach/ns/libsys/alarm.s new file mode 100644 index 00000000..bedbddd0 --- /dev/null +++ b/mach/ns/libsys/alarm.s @@ -0,0 +1,12 @@ +.define _alarm +.extern _alarm +.text +_alarm: +enter[], 0 +movd 8(fp),tos +movd 27,tos +jsr @.mon +movd tos,r7 +movd r7,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/brk.s b/mach/ns/libsys/brk.s new file mode 100644 index 00000000..a3463ae6 --- /dev/null +++ b/mach/ns/libsys/brk.s @@ -0,0 +1,9 @@ +.define _brk +.extern _brk +.text +_brk: +enter[], 0 +movd 8(fp),@.reghp +movd 0,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/chdir.s b/mach/ns/libsys/chdir.s new file mode 100644 index 00000000..1840b74b --- /dev/null +++ b/mach/ns/libsys/chdir.s @@ -0,0 +1,19 @@ +.define _chdir +.extern _chdir +.text +_chdir: +enter[], 0 +movd 8(fp),tos +movd 12,tos +jsr @.mon +cmpqd 0,tos +bne I0011 +movd 0,r4 +exit [] +ret 0 +I0011: +movd tos,r7 +movd r7,@_errno +movd -1,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/chmod.s b/mach/ns/libsys/chmod.s new file mode 100644 index 00000000..03bf072c --- /dev/null +++ b/mach/ns/libsys/chmod.s @@ -0,0 +1,20 @@ +.define _chmod +.extern _chmod +.text +_chmod: +enter[], 0 +movd 12(fp),tos +movd 8(fp),tos +movd 15,tos +jsr @.mon +cmpqd 0,tos +bne I0011 +movd 0,r4 +exit [] +ret 0 +I0011: +movd tos,r7 +movd r7,@_errno +movd -1,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/chown.s b/mach/ns/libsys/chown.s new file mode 100644 index 00000000..72e5cfce --- /dev/null +++ b/mach/ns/libsys/chown.s @@ -0,0 +1,25 @@ +.define _chown +.extern _chown +.text +_chown: +enter[], 0 +addr 8(fp),r7 +movd 12,r0 +addd r0,r7 +1: +subd 4,r7 +movd 0(r7),tos +acbd -4,r0,1b +movd 16,tos +jsr @.mon +cmpqd 0,tos +bne I0011 +movd 0,r4 +exit [] +ret 0 +I0011: +movd tos,r7 +movd r7,@_errno +movd -1,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/chroot.s b/mach/ns/libsys/chroot.s new file mode 100644 index 00000000..2256b1a9 --- /dev/null +++ b/mach/ns/libsys/chroot.s @@ -0,0 +1,19 @@ +.define _chroot +.extern _chroot +.text +_chroot: +enter[], 0 +movd 8(fp),tos +movd 61,tos +jsr @.mon +cmpqd 0,tos +bne I0011 +movd 0,r4 +exit [] +ret 0 +I0011: +movd tos,r7 +movd r7,@_errno +movd -1,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/cleanup.s b/mach/ns/libsys/cleanup.s new file mode 100644 index 00000000..48c42520 --- /dev/null +++ b/mach/ns/libsys/cleanup.s @@ -0,0 +1,7 @@ +.define __cleanup +.extern __cleanup +.text +__cleanup: +enter[], 0 +exit [] +ret 0 diff --git a/mach/ns/libsys/close.s b/mach/ns/libsys/close.s new file mode 100644 index 00000000..b6e217c8 --- /dev/null +++ b/mach/ns/libsys/close.s @@ -0,0 +1,6 @@ +.define _close +.extern _close +.text +_close: +movd 0, r4 +ret 0 diff --git a/mach/ns/libsys/creat.s b/mach/ns/libsys/creat.s new file mode 100644 index 00000000..b0bf72e9 --- /dev/null +++ b/mach/ns/libsys/creat.s @@ -0,0 +1,19 @@ +.define _creat +.extern _creat +.text +_creat: +enter[], 0 +movd 12(fp),tos +movd 8(fp),tos +movd 8,tos +jsr @.mon +cmpqd 0,tos +beq I0011 +movd tos,r7 +movd r7,@_errno +movd -1,tos +I0011: +movd tos,r7 +movd r7,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/dup.s b/mach/ns/libsys/dup.s new file mode 100644 index 00000000..c4a353c2 --- /dev/null +++ b/mach/ns/libsys/dup.s @@ -0,0 +1,19 @@ +.define _dup +.extern _dup +.text +_dup: +enter[], 0 +movd 8(fp),tos +movd 8(fp),tos +movd 41,tos +jsr @.mon +cmpqd 0,tos +beq I0011 +movd tos,r7 +movd r7,@_errno +movd -1,tos +I0011: +movd tos,r7 +movd r7,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/dup2.s b/mach/ns/libsys/dup2.s new file mode 100644 index 00000000..6f45f4e5 --- /dev/null +++ b/mach/ns/libsys/dup2.s @@ -0,0 +1,21 @@ +.define _dup2 +.extern _dup2 +.text +_dup2: +enter[], 0 +movd 8(fp),r7 +ord 64,r7 +movd 12(fp),tos +movd r7,tos +movd 41,tos +jsr @.mon +cmpqd 0,tos +beq I0011 +movd tos,r7 +movd r7,@_errno +movd -1,tos +I0011: +movd tos,r7 +movd r7,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/errno.s b/mach/ns/libsys/errno.s new file mode 100644 index 00000000..35c87193 --- /dev/null +++ b/mach/ns/libsys/errno.s @@ -0,0 +1,5 @@ +.define _errno +.extern _errno +.bss +_errno:.space 4 +.text diff --git a/mach/ns/libsys/execl.s b/mach/ns/libsys/execl.s new file mode 100644 index 00000000..f637c229 --- /dev/null +++ b/mach/ns/libsys/execl.s @@ -0,0 +1,15 @@ +.define _execl +.extern _execl +.text +_execl: +enter[], 0 +movd @__penvp,tos +addr 12(fp),tos +movd 8(fp),tos +movd 59,tos +jsr @.mon +movd tos,r7 +movd r7,@_errno +movd -1,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/execle.s b/mach/ns/libsys/execle.s new file mode 100644 index 00000000..2bd53858 --- /dev/null +++ b/mach/ns/libsys/execle.s @@ -0,0 +1,26 @@ +.define _execle +.extern _execle +.text +_execle: +enter[], 0 +addr 12(fp),tos +I0011: +movd tos,r7 +movd r7,tos +cmpd 0(r7),0 +beq I0012 +movd tos,r7 +addr 4(r7),tos +br I0011 +I0012: +movd tos,r7 +movd 4(r7),tos +addr 12(fp),tos +movd 8(fp),tos +movd 59,tos +jsr @.mon +movd tos,r7 +movd r7,@_errno +movd -1,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/execv.s b/mach/ns/libsys/execv.s new file mode 100644 index 00000000..a38e9bdf --- /dev/null +++ b/mach/ns/libsys/execv.s @@ -0,0 +1,15 @@ +.define _execv +.extern _execv +.text +_execv: +enter[], 0 +movd @__penvp,tos +movd 12(fp),tos +movd 8(fp),tos +movd 59,tos +jsr @.mon +movd tos,r7 +movd r7,@_errno +movd -1,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/execve.s b/mach/ns/libsys/execve.s new file mode 100644 index 00000000..656278ec --- /dev/null +++ b/mach/ns/libsys/execve.s @@ -0,0 +1,19 @@ +.define _execve +.extern _execve +.text +_execve: +enter[], 0 +addr 8(fp),r7 +movd 12,r0 +addd r0,r7 +1: +subd 4,r7 +movd 0(r7),tos +acbd -4,r0,1b +movd 59,tos +jsr @.mon +movd tos,r7 +movd r7,@_errno +movd -1,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/exit.s b/mach/ns/libsys/exit.s new file mode 100644 index 00000000..a809dd17 --- /dev/null +++ b/mach/ns/libsys/exit.s @@ -0,0 +1,11 @@ +.define _exit +.extern _exit +.text +_exit: +enter[], 0 +jsr @__cleanup +movd 8(fp),tos +jsr @__exit +adjspd -4 +exit [] +ret 0 diff --git a/mach/ns/libsys/fork.s b/mach/ns/libsys/fork.s new file mode 100644 index 00000000..9670ddfb --- /dev/null +++ b/mach/ns/libsys/fork.s @@ -0,0 +1,29 @@ +.define _fork +.define _par_uid +.extern _par_uid +.bss +_par_uid:.space 4 +.extern _fork +.text +_fork: +enter[], 0 +movd 2,tos +jsr @.mon +cmpqd 0,tos +beq I0011 +movd tos,r7 +movd r7,@_errno +movd -1,r4 +exit [] +ret 0 +I0011: +cmpqd 0,tos +beq I0012 +movd tos,r7 +movd r7,@_par_uid +movd 0,tos +I0012: +movd tos,r7 +movd r7,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/fstat.s b/mach/ns/libsys/fstat.s new file mode 100644 index 00000000..4a8f2048 --- /dev/null +++ b/mach/ns/libsys/fstat.s @@ -0,0 +1,20 @@ +.define _fstat +.extern _fstat +.text +_fstat: +enter[], 0 +movd 12(fp),tos +movd 8(fp),tos +movd 28,tos +jsr @.mon +cmpqd 0,tos +bne I0011 +movd 0,r4 +exit [] +ret 0 +I0011: +movd tos,r7 +movd r7,@_errno +movd -1,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/ftime.s b/mach/ns/libsys/ftime.s new file mode 100644 index 00000000..b4a26323 --- /dev/null +++ b/mach/ns/libsys/ftime.s @@ -0,0 +1,10 @@ +.define _ftime +.extern _ftime +.text +_ftime: +enter[], 0 +movd 8(fp),tos +movd 35,tos +jsr @.mon +exit [] +ret 0 diff --git a/mach/ns/libsys/getegid.s b/mach/ns/libsys/getegid.s new file mode 100644 index 00000000..6f2ff7e8 --- /dev/null +++ b/mach/ns/libsys/getegid.s @@ -0,0 +1,11 @@ +.define _getegid +.extern _getegid +.text +_getegid: +enter[], 0 +movd 47,tos +jsr @.mon +movd tos,r7 +movd r7,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/geteuid.s b/mach/ns/libsys/geteuid.s new file mode 100644 index 00000000..c2a99dd9 --- /dev/null +++ b/mach/ns/libsys/geteuid.s @@ -0,0 +1,11 @@ +.define _geteuid +.extern _geteuid +.text +_geteuid: +enter[], 0 +movd 24,tos +jsr @.mon +movd tos,r7 +movd r7,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/getgid.s b/mach/ns/libsys/getgid.s new file mode 100644 index 00000000..011c894f --- /dev/null +++ b/mach/ns/libsys/getgid.s @@ -0,0 +1,12 @@ +.define _getgid +.extern _getgid +.text +_getgid: +enter[], 0 +movd 47,tos +jsr @.mon +adjspd -4 +movd tos,r7 +movd r7,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/getpid.s b/mach/ns/libsys/getpid.s new file mode 100644 index 00000000..c064bc5c --- /dev/null +++ b/mach/ns/libsys/getpid.s @@ -0,0 +1,11 @@ +.define _getpid +.extern _getpid +.text +_getpid: +enter[], 0 +movd 20,tos +jsr @.mon +movd tos,r7 +movd r7,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/getuid.s b/mach/ns/libsys/getuid.s new file mode 100644 index 00000000..1d3fabd1 --- /dev/null +++ b/mach/ns/libsys/getuid.s @@ -0,0 +1,12 @@ +.define _getuid +.extern _getuid +.text +_getuid: +enter[], 0 +movd 24,tos +jsr @.mon +adjspd -4 +movd tos,r7 +movd r7,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/gtty.s b/mach/ns/libsys/gtty.s new file mode 100644 index 00000000..bbe068d5 --- /dev/null +++ b/mach/ns/libsys/gtty.s @@ -0,0 +1,12 @@ +.define _gtty +.extern _gtty +.text +_gtty: +enter[], 0 +movd 12(fp),tos +movd 29704,tos +movd 8(fp),tos +jsr @_ioctl +adjspd -12 +exit [] +ret 0 diff --git a/mach/ns/libsys/ioctl.s b/mach/ns/libsys/ioctl.s new file mode 100644 index 00000000..906d270a --- /dev/null +++ b/mach/ns/libsys/ioctl.s @@ -0,0 +1,25 @@ +.define _ioctl +.extern _ioctl +.text +_ioctl: +enter[], 0 +addr 8(fp),r7 +movd 12,r0 +addd r0,r7 +1: +subd 4,r7 +movd 0(r7),tos +acbd -4,r0,1b +movd 54,tos +jsr @.mon +cmpqd 0,tos +bne I0011 +movd 0,r4 +exit [] +ret 0 +I0011: +movd tos,r7 +movd r7,@_errno +movd -1,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/kill.s b/mach/ns/libsys/kill.s new file mode 100644 index 00000000..7447642f --- /dev/null +++ b/mach/ns/libsys/kill.s @@ -0,0 +1,20 @@ +.define _kill +.extern _kill +.text +_kill: +enter[], 0 +movd 12(fp),tos +movd 8(fp),tos +movd 37,tos +jsr @.mon +cmpqd 0,tos +bne I0011 +movd 0,r4 +exit [] +ret 0 +I0011: +movd tos,r7 +movd r7,@_errno +movd -1,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/link.s b/mach/ns/libsys/link.s new file mode 100644 index 00000000..9b82bd2f --- /dev/null +++ b/mach/ns/libsys/link.s @@ -0,0 +1,20 @@ +.define _link +.extern _link +.text +_link: +enter[], 0 +movd 12(fp),tos +movd 8(fp),tos +movd 9,tos +jsr @.mon +cmpqd 0,tos +bne I0011 +movd 0,r4 +exit [] +ret 0 +I0011: +movd tos,r7 +movd r7,@_errno +movd -1,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/lock.s b/mach/ns/libsys/lock.s new file mode 100644 index 00000000..88fca256 --- /dev/null +++ b/mach/ns/libsys/lock.s @@ -0,0 +1,19 @@ +.define _lock +.extern _lock +.text +_lock: +enter[], 0 +movd 8(fp),tos +movd 53,tos +jsr @.mon +cmpqd 0,tos +bne I0011 +movd 0,r4 +exit [] +ret 0 +I0011: +movd tos,r7 +movd r7,@_errno +movd -1,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/lseek.s b/mach/ns/libsys/lseek.s new file mode 100644 index 00000000..8d50a6fd --- /dev/null +++ b/mach/ns/libsys/lseek.s @@ -0,0 +1,24 @@ +.define _lseek +.extern _lseek +.text +_lseek: +enter[], 0 +addr 8(fp),r7 +movd 16,r0 +addd r0,r7 +1: +subd 4,r7 +movd 0(r7),tos +acbd -4,r0,1b +movd 19,tos +jsr @.mon +cmpqd 0,tos +beq I0011 +movd tos,r7 +movd r7,@_errno +movd -1,tos +I0011: +movd tos,r4 +movd tos,r5 +exit [] +ret 0 diff --git a/mach/ns/libsys/mknod.s b/mach/ns/libsys/mknod.s new file mode 100644 index 00000000..3e85d2a1 --- /dev/null +++ b/mach/ns/libsys/mknod.s @@ -0,0 +1,25 @@ +.define _mknod +.extern _mknod +.text +_mknod: +enter[], 0 +addr 8(fp),r7 +movd 12,r0 +addd r0,r7 +1: +subd 4,r7 +movd 0(r7),tos +acbd -4,r0,1b +movd 14,tos +jsr @.mon +cmpqd 0,tos +bne I0011 +movd 0,r4 +exit [] +ret 0 +I0011: +movd tos,r7 +movd r7,@_errno +movd -1,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/mount.s b/mach/ns/libsys/mount.s new file mode 100644 index 00000000..216f5e27 --- /dev/null +++ b/mach/ns/libsys/mount.s @@ -0,0 +1,25 @@ +.define _mount +.extern _mount +.text +_mount: +enter[], 0 +addr 8(fp),r7 +movd 12,r0 +addd r0,r7 +1: +subd 4,r7 +movd 0(r7),tos +acbd -4,r0,1b +movd 21,tos +jsr @.mon +cmpqd 0,tos +bne I0011 +movd 0,r4 +exit [] +ret 0 +I0011: +movd tos,r7 +movd r7,@_errno +movd -1,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/mpxcall.s b/mach/ns/libsys/mpxcall.s new file mode 100644 index 00000000..9cdec1ab --- /dev/null +++ b/mach/ns/libsys/mpxcall.s @@ -0,0 +1,20 @@ +.define _mpxcall +.extern _mpxcall +.text +_mpxcall: +enter[], 0 +movd 12(fp),tos +movd 8(fp),tos +movd 56,tos +jsr @.mon +cmpqd 0,tos +bne I0011 +movd 0,r4 +exit [] +ret 0 +I0011: +movd tos,r7 +movd r7,@_errno +movd -1,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/nice.s b/mach/ns/libsys/nice.s new file mode 100644 index 00000000..e47a54d3 --- /dev/null +++ b/mach/ns/libsys/nice.s @@ -0,0 +1,10 @@ +.define _nice +.extern _nice +.text +_nice: +enter[], 0 +movd 8(fp),tos +movd 34,tos +jsr @.mon +exit [] +ret 0 diff --git a/mach/ns/libsys/open.s b/mach/ns/libsys/open.s new file mode 100644 index 00000000..4a0cf980 --- /dev/null +++ b/mach/ns/libsys/open.s @@ -0,0 +1,19 @@ +.define _open +.extern _open +.text +_open: +enter[], 0 +movd 12(fp),tos +movd 8(fp),tos +movd 5,tos +jsr @.mon +cmpqd 0,tos +beq I0011 +movd tos,r7 +movd r7,@_errno +movd -1,tos +I0011: +movd tos,r7 +movd r7,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/pause.s b/mach/ns/libsys/pause.s new file mode 100644 index 00000000..607a351b --- /dev/null +++ b/mach/ns/libsys/pause.s @@ -0,0 +1,9 @@ +.define _pause +.extern _pause +.text +_pause: +enter[], 0 +movd 29,tos +jsr @.mon +exit [] +ret 0 diff --git a/mach/ns/libsys/pipe.s b/mach/ns/libsys/pipe.s new file mode 100644 index 00000000..6915b443 --- /dev/null +++ b/mach/ns/libsys/pipe.s @@ -0,0 +1,23 @@ +.define _pipe +.extern _pipe +.text +_pipe: +enter[], 0 +movd 42,tos +jsr @.mon +cmpqd 0,tos +beq I0011 +movd tos,r7 +movd r7,@_errno +movd -1,r4 +exit [] +ret 0 +I0011: +movd 8(fp),r7 +movd tos,r6 +movd r6,4(r7) +movd tos,r6 +movd r6,0(8(fp)) +movd 0,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/prof.s b/mach/ns/libsys/prof.s new file mode 100644 index 00000000..822e5beb --- /dev/null +++ b/mach/ns/libsys/prof.s @@ -0,0 +1,16 @@ +.define _profil +.extern _profil +.text +_profil: +enter[], 0 +addr 8(fp),r7 +movd 16,r0 +addd r0,r7 +1: +subd 4,r7 +movd 0(r7),tos +acbd -4,r0,1b +movd 44,tos +jsr @.mon +exit [] +ret 0 diff --git a/mach/ns/libsys/ptrace.s b/mach/ns/libsys/ptrace.s new file mode 100644 index 00000000..a32ebdfc --- /dev/null +++ b/mach/ns/libsys/ptrace.s @@ -0,0 +1,25 @@ +.define _ptrace +.extern _ptrace +.text +_ptrace: +enter[], 0 +xord @_errno,@_errno +addr 8(fp),r7 +movd 16,r0 +addd r0,r7 +1: +subd 4,r7 +movd 0(r7),tos +acbd -4,r0,1b +movd 26,tos +jsr @.mon +cmpqd 0,tos +beq I0011 +movd tos,r7 +movd r7,@_errno +movd -1,tos +I0011: +movd tos,r7 +movd r7,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/read.s b/mach/ns/libsys/read.s new file mode 100644 index 00000000..dd3552db --- /dev/null +++ b/mach/ns/libsys/read.s @@ -0,0 +1,15 @@ +.define _read +.extern _read +.text +_read: +enter[], 0 +save [r0,r1,r2,r3] +movd 3,r0 +movd 12(fp),r1 +movd 16(fp),r2 +movd 0,r3 +svc +movd 16(fp),r4 +restore [r0,r1,r2,r3] +exit[] +ret 0 diff --git a/mach/ns/libsys/sbrk.s b/mach/ns/libsys/sbrk.s new file mode 100644 index 00000000..e7b080b5 --- /dev/null +++ b/mach/ns/libsys/sbrk.s @@ -0,0 +1,11 @@ +.define _sbrk +.extern _sbrk +.text +_sbrk: +enter[], 0 +movd @.reghp,r7 +addd 8(fp),r7 +movd r7,@.reghp +movd @.reghp,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/setgid.s b/mach/ns/libsys/setgid.s new file mode 100644 index 00000000..b9cc6698 --- /dev/null +++ b/mach/ns/libsys/setgid.s @@ -0,0 +1,19 @@ +.define _setgid +.extern _setgid +.text +_setgid: +enter[], 0 +movd 8(fp),tos +movd 46,tos +jsr @.mon +cmpqd 0,tos +bne I0011 +movd 0,r4 +exit [] +ret 0 +I0011: +movd tos,r7 +movd r7,@_errno +movd -1,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/setsig.s b/mach/ns/libsys/setsig.s new file mode 100644 index 00000000..4035a369 --- /dev/null +++ b/mach/ns/libsys/setsig.s @@ -0,0 +1,39 @@ +.define __setsig +.bss +_save:.space 4 +_trf:.space 4 +.extern __setsig +.text +__setsig: +enter[], 0 +movd 8(fp),@_trf +movd @.trpreg,r0 +movd _catchit,@.trpreg +movd r0,@_save +exit [] +ret 0 +_catchit: +enter[], 0 +movd @.trpreg,r0 +movd _catchit,@.trpreg +movd r0,tos +adjspd -4 +movd @_trf,r7 +movd 8(fp),tos +jsr r7 +cmpqd 0,r4 +bne I0021 +movd @.trpreg,r0 +movd @_save,@.trpreg +movd r0,tos +adjspd -4 +jsr @.trp +movd @.trpreg,r0 +movd _catchit,@.trpreg +movd r0,tos +adjspd -4 +movd tos,r7 +movd r7,@_save +I0021: +exit [] +ret 0 diff --git a/mach/ns/libsys/setuid.s b/mach/ns/libsys/setuid.s new file mode 100644 index 00000000..e9cfc095 --- /dev/null +++ b/mach/ns/libsys/setuid.s @@ -0,0 +1,19 @@ +.define _setuid +.extern _setuid +.text +_setuid: +enter[], 0 +movd 8(fp),tos +movd 23,tos +jsr @.mon +cmpqd 0,tos +bne I0011 +movd 0,r4 +exit [] +ret 0 +I0011: +movd tos,r7 +movd r7,@_errno +movd -1,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/signal.s b/mach/ns/libsys/signal.s new file mode 100644 index 00000000..97d50b24 --- /dev/null +++ b/mach/ns/libsys/signal.s @@ -0,0 +1,159 @@ +.define _signal +.data +_vector: +.long 0 +.long 0 +.long 0 +.long 0 +.long 0 +.long 0 +.long 0 +.long 0 +.long 0 +.long 0 +.long 0 +.long 0 +.long 0 +.long 0 +.long 0 +.long 0 +_mapvec: +.long 0 +.long 134219784 +.long 2048 +.long 0 +.long 2827 +.long 658176 +.long 3072 +firsttim: +.extern _signal +.long 1 +.text +_signal: +enter[], 16 +movd 8(fp),r7 +addd -1,r7 +movd r7,-4(fp) +cmpqd 0,-4(fp) +bgt I0014 +cmpd -4(fp),16 +blt I0013 +I0014: +movd -1,tos +br I0011 +I0013: +cmpqd 0,@firsttim +beq I0015 +xord @firsttim,@firsttim +movd catchtrp,tos +jsr @__setsig +adjspd -4 +I0015: +movd -4(fp),r7 +ashd 2,r7 +movd _vector(r7),-12(fp) +cmpd -12(fp),12(fp) +beq I0016 +movd -4(fp),r7 +ashd 2,r7 +movd 12(fp),_vector(r7) +cmpd 12(fp),1 +bne I0017 +movd -3,-16(fp) +br I0018 +I0017: +cmpqd 0,12(fp) +bne I0019 +movd -2,-16(fp) +br I0018 +I0019: +addr 128(8(fp)),-16(fp) +I0018: +movd 8(fp),tos +movd -16(fp),tos +jsr @_sigtrp +adjspd -8 +cmpd r4,-1 +bne I0016 +movd -1,tos +br I0011 +I0016: +movd -12(fp),tos +I0011: +movd tos,r7 +movd r7,r4 +exit [] +ret 0 +catchtrp: +enter[], 0 +cmpd 8(fp),128 +ble I0023 +cmpd 8(fp),144 +bgt I0023 +movd 8(fp),r7 +subd 128,r7 +movd r7,tos +jsr @procesig +adjspd -4 +movd r4,tos +br I0021 +I0023: +cmpqd 0,8(fp) +bgt I0024 +cmpd 8(fp),28 +bge I0024 +movd _mapvec,r7 +addd 8(fp),r7 +movzbd 0(r7),r6 +cmpqd 0,r6 +beq I0024 +movd _mapvec,r7 +addd 8(fp),r7 +movzbd 0(r7),tos +jsr @procesig +adjspd -4 +movd r4,tos +br I0021 +I0024: +movd 0,tos +I0021: +movd tos,r7 +movd r7,r4 +exit [] +ret 0 +procesig: +enter[], 8 +movd 8(fp),r7 +addd -1,r7 +movd r7,-4(fp) +movd -4(fp),r6 +ashd 2,r6 +movd _vector(r6),-8(fp) +cmpd -8(fp),1 +bne I0033 +movd 1,tos +br I0031 +I0033: +cmpd 8(fp),4 +beq I0034 +cmpd 8(fp),5 +beq I0034 +movd -4(fp),r7 +ashd 2,r7 +movd 1,_vector(r7) +I0034: +cmpqd 0,-8(fp) +bne I0035 +movd 0,tos +br I0031 +I0035: +movd -8(fp),r7 +movd 8(fp),tos +jsr r7 +adjspd -4 +movd 1,tos +I0031: +movd tos,r7 +movd r7,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/sigtrp.s b/mach/ns/libsys/sigtrp.s new file mode 100644 index 00000000..b20e9172 --- /dev/null +++ b/mach/ns/libsys/sigtrp.s @@ -0,0 +1,19 @@ +.define _sigtrp +.extern _sigtrp +.text +_sigtrp: +enter[], 0 +movd 12(fp),tos +movd 8(fp),tos +movd 48,tos +jsr @.mon +cmpqd 0,tos +beq I0011 +movd tos,r7 +movd r7,@_errno +movd -1,tos +I0011: +movd tos,r7 +movd r7,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/stat.s b/mach/ns/libsys/stat.s new file mode 100644 index 00000000..66ca3156 --- /dev/null +++ b/mach/ns/libsys/stat.s @@ -0,0 +1,20 @@ +.define _stat +.extern _stat +.text +_stat: +enter[], 0 +movd 12(fp),tos +movd 8(fp),tos +movd 18,tos +jsr @.mon +cmpqd 0,tos +bne I0011 +movd 0,r4 +exit [] +ret 0 +I0011: +movd tos,r7 +movd r7,@_errno +movd -1,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/stime.s b/mach/ns/libsys/stime.s new file mode 100644 index 00000000..a41bdde1 --- /dev/null +++ b/mach/ns/libsys/stime.s @@ -0,0 +1,19 @@ +.define _stime +.extern _stime +.text +_stime: +enter[], 0 +movd 0(8(fp)),tos +movd 25,tos +jsr @.mon +cmpqd 0,tos +bne I0011 +movd 0,r4 +exit [] +ret 0 +I0011: +movd tos,r7 +movd r7,@_errno +movd -1,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/stty.s b/mach/ns/libsys/stty.s new file mode 100644 index 00000000..2a3fcc44 --- /dev/null +++ b/mach/ns/libsys/stty.s @@ -0,0 +1,12 @@ +.define _stty +.extern _stty +.text +_stty: +enter[], 0 +movd 12(fp),tos +movd 29705,tos +movd 8(fp),tos +jsr @_ioctl +adjspd -12 +exit [] +ret 0 diff --git a/mach/ns/libsys/sync.s b/mach/ns/libsys/sync.s new file mode 100644 index 00000000..e0197ac6 --- /dev/null +++ b/mach/ns/libsys/sync.s @@ -0,0 +1,9 @@ +.define _sync +.extern _sync +.text +_sync: +enter[], 0 +movd 36,tos +jsr @.mon +exit [] +ret 0 diff --git a/mach/ns/libsys/tell.s b/mach/ns/libsys/tell.s new file mode 100644 index 00000000..4623614b --- /dev/null +++ b/mach/ns/libsys/tell.s @@ -0,0 +1,12 @@ +.define _tell +.extern _tell +.text +_tell: +enter[], 0 +movd 1,tos +movd 0,tos +movd 8(fp),tos +jsr @_lseek +adjspd -12 +exit [] +ret 0 diff --git a/mach/ns/libsys/time.s b/mach/ns/libsys/time.s new file mode 100644 index 00000000..9453664c --- /dev/null +++ b/mach/ns/libsys/time.s @@ -0,0 +1,15 @@ +.define _time +.extern _time +.text +_time: +enter[], 12 +addr -12(fp),tos +jsr @_ftime +adjspd -4 +cmpqd 0,8(fp) +beq I0013 +movd -12(fp),0(8(fp)) +I0013: +movd -12(fp),r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/times.s b/mach/ns/libsys/times.s new file mode 100644 index 00000000..d7a26712 --- /dev/null +++ b/mach/ns/libsys/times.s @@ -0,0 +1,10 @@ +.define _times +.extern _times +.text +_times: +enter[], 0 +movd 8(fp),tos +movd 43,tos +jsr @.mon +exit [] +ret 0 diff --git a/mach/ns/libsys/umask.s b/mach/ns/libsys/umask.s new file mode 100644 index 00000000..4f2f63cf --- /dev/null +++ b/mach/ns/libsys/umask.s @@ -0,0 +1,12 @@ +.define _umask +.extern _umask +.text +_umask: +enter[], 0 +movd 8(fp),tos +movd 60,tos +jsr @.mon +movd tos,r7 +movd r7,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/umount.s b/mach/ns/libsys/umount.s new file mode 100644 index 00000000..f1259bf0 --- /dev/null +++ b/mach/ns/libsys/umount.s @@ -0,0 +1,19 @@ +.define _umount +.extern _umount +.text +_umount: +enter[], 0 +movd 8(fp),tos +movd 22,tos +jsr @.mon +cmpqd 0,tos +bne I0011 +movd 0,r4 +exit [] +ret 0 +I0011: +movd tos,r7 +movd r7,@_errno +movd -1,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/unlink.s b/mach/ns/libsys/unlink.s new file mode 100644 index 00000000..d5617c1c --- /dev/null +++ b/mach/ns/libsys/unlink.s @@ -0,0 +1,19 @@ +.define _unlink +.extern _unlink +.text +_unlink: +enter[], 0 +movd 8(fp),tos +movd 10,tos +jsr @.mon +cmpqd 0,tos +bne I0011 +movd 0,r4 +exit [] +ret 0 +I0011: +movd tos,r7 +movd r7,@_errno +movd -1,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/utime.s b/mach/ns/libsys/utime.s new file mode 100644 index 00000000..0c98b789 --- /dev/null +++ b/mach/ns/libsys/utime.s @@ -0,0 +1,20 @@ +.define _utime +.extern _utime +.text +_utime: +enter[], 0 +movd 12(fp),tos +movd 8(fp),tos +movd 30,tos +jsr @.mon +cmpqd 0,tos +bne I0011 +movd 0,r4 +exit [] +ret 0 +I0011: +movd tos,r7 +movd r7,@_errno +movd -1,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/wait.s b/mach/ns/libsys/wait.s new file mode 100644 index 00000000..b63a2586 --- /dev/null +++ b/mach/ns/libsys/wait.s @@ -0,0 +1,29 @@ +.define _wait +.extern _wait +.text +_wait: +enter[], 0 +movd 7,tos +jsr @.mon +cmpqd 0,tos +bne I0011 +cmpqd 0,8(fp) +beq I0012 +movd tos,r7 +movd r7,0(8(fp)) +movd tos,r6 +movd r6,r4 +exit [] +ret 0 +I0012: +adjspd -4 +movd tos,r7 +movd r7,r4 +exit [] +ret 0 +I0011: +movd tos,r7 +movd r7,@_errno +movd -1,r4 +exit [] +ret 0 diff --git a/mach/ns/libsys/write.s b/mach/ns/libsys/write.s new file mode 100644 index 00000000..ab89b528 --- /dev/null +++ b/mach/ns/libsys/write.s @@ -0,0 +1,15 @@ +.define _write +.extern _write +.text +_write: +enter[], 0 +save [r0,r1,r2,r3] +movd 4,r0 +movd 12(fp),r1 +movd 16(fp),r2 +movd 0,r3 +svc +movd 16(fp),r4 +restore [r0,r1,r2,r3] +exit[] +ret 0 From e6dd02f9dd38a60c3ff5a2863ff4439c16e1d123 Mon Sep 17 00:00:00 2001 From: em Date: Fri, 26 Jul 1985 12:52:13 +0000 Subject: [PATCH 0063/1625] Initial revision --- mach/ns/libsys/LIST | 64 ++++++++++++++++++++++++++++++++++++++++ mach/ns/libsys/Makefile | 17 +++++++++++ mach/ns/libsys/head_em.s | 50 +++++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 mach/ns/libsys/LIST create mode 100644 mach/ns/libsys/Makefile create mode 100644 mach/ns/libsys/head_em.s diff --git a/mach/ns/libsys/LIST b/mach/ns/libsys/LIST new file mode 100644 index 00000000..30eb4de6 --- /dev/null +++ b/mach/ns/libsys/LIST @@ -0,0 +1,64 @@ +LIST +exit.o +gtty.o +signal.o +stty.o +tell.o +time.o +cleanup.o +access.o +acct.o +alarm.o +brk.o +chdir.o +chmod.o +chown.o +chroot.o +close.o +creat.o +dup.o +dup2.o +execl.o +execle.o +execv.o +execve.o +_exit.o +fork.o +fstat.o +ftime.o +getegid.o +geteuid.o +getgid.o +getpid.o +getuid.o +ioctl.o +kill.o +link.o +lock.o +lseek.o +mknod.o +mount.o +mpxcall.o +nice.o +open.o +pause.o +pipe.o +prof.o +ptrace.o +read.o +sbrk.o +setgid.o +setuid.o +setsig.o +sigtrp.o +stat.o +stime.o +sync.o +times.o +umask.o +umount.o +unlink.o +utime.o +wait.o +write.o +errno.o diff --git a/mach/ns/libsys/Makefile b/mach/ns/libsys/Makefile new file mode 100644 index 00000000..91f2cc35 --- /dev/null +++ b/mach/ns/libsys/Makefile @@ -0,0 +1,17 @@ +# $Header$ +install: + ../../install head_em.s head_em + ../../install tail_mon.a tail_mon + +compare: + -../../compare head_em.s head_em + -../../compare tail_mon.a tail_mon + +clean : + +opr : + make pr | opr + +pr: + @pr -h `pwd`/head_em.s head_em.s + @ar pv tail_mon.a | pr -h `pwd`/tail_mon.a diff --git a/mach/ns/libsys/head_em.s b/mach/ns/libsys/head_em.s new file mode 100644 index 00000000..ffcd6fe5 --- /dev/null +++ b/mach/ns/libsys/head_em.s @@ -0,0 +1,50 @@ +.define hol0,argv,.reghp,envp,begbss +.define .ignmask, .trpreg +.define .stop +.define ERANGE,EILLINS,ECASE + +base = 0x10000 +topmem = 0xFFFFFF + +ERANGE = 1 +EILLINS = 18 +ECASE = 20 + + .base base + .text + + movd begbss, r7 + movd endbss, r6 +1: + movqd 0, 0(r7) + addqd 4, r7 + cmpd r6,r7 + bgt 1b + + movd envp,tos + movd argv,tos + movd 1,tos + jsr @_m_a_i_n +.stop: + movb 0x7f,tos + jsr @.putchar + bpt + +.bss +begbss: +.data +hol0: + .long 0 + .long 0 +argv: + .long 3f +envp: + .long 0 +3: + .asciz 'PROGRAM' +.reghp: + .long endbss +.ignmask: + .short 0 +.trpreg: + .long 0 From 25dd9ad6310736fedb13abe41953cabf80ac2e24 Mon Sep 17 00:00:00 2001 From: em Date: Fri, 26 Jul 1985 15:37:11 +0000 Subject: [PATCH 0064/1625] removed a superfluous line. --- mach/ns/libem/Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/mach/ns/libem/Makefile b/mach/ns/libem/Makefile index 0a2dc3f5..7c0ddba4 100644 --- a/mach/ns/libem/Makefile +++ b/mach/ns/libem/Makefile @@ -1,6 +1,5 @@ # $Header$ install: - arch t tail_em.a > LIST ../../install tail_em.a tail_em ../../install end.s tail_em.vend From bb797e2241e8db90ef88561dc0137171a377159e Mon Sep 17 00:00:00 2001 From: em Date: Fri, 26 Jul 1985 17:04:31 +0000 Subject: [PATCH 0065/1625] This one works correctly for programs failing to translate. --- mach/ns/libbc/compmodule | 6 ++++-- mach/ns/libcc/compmodule | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/mach/ns/libbc/compmodule b/mach/ns/libbc/compmodule index 491f6d25..6b964394 100755 --- a/mach/ns/libbc/compmodule +++ b/mach/ns/libbc/compmodule @@ -1,2 +1,4 @@ -${MACH?} -I../../../h ${MACHFL?} $1 1>&2 -echo `basename $1 $2`.o +if ${MACH?ack} -I../../../h ${MACHFL?} $1 1>&2 +then echo `basename $1 $2`.o +else rm -f `basename $1 $2`.o +fi diff --git a/mach/ns/libcc/compmodule b/mach/ns/libcc/compmodule index 491f6d25..6b964394 100755 --- a/mach/ns/libcc/compmodule +++ b/mach/ns/libcc/compmodule @@ -1,2 +1,4 @@ -${MACH?} -I../../../h ${MACHFL?} $1 1>&2 -echo `basename $1 $2`.o +if ${MACH?ack} -I../../../h ${MACHFL?} $1 1>&2 +then echo `basename $1 $2`.o +else rm -f `basename $1 $2`.o +fi From 325f2c4c1af41e0f9d5c73602bd147bf4a505b1b Mon Sep 17 00:00:00 2001 From: em Date: Fri, 26 Jul 1985 17:14:13 +0000 Subject: [PATCH 0066/1625] Annita's versie --- lib/ns/descr | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/ns/descr b/lib/ns/descr index a0933e4f..8051f72f 100644 --- a/lib/ns/descr +++ b/lib/ns/descr @@ -10,8 +10,16 @@ var M=ns var LIB=lib/{M}/tail_ var RT=lib/{M}/head_ var INCLUDES=-I{EM}/include -I/usr/include +name be + from .m.g + to .o + program {EM}/lib/{M}/cg + args < + stdout + need .e +end name asld - from .s.a + from .o.s.a to .out outfile a.out program {EM}/lib/{M}/as From 65a20f33f1a1436dc54a5e1966c27a18fbd2c231 Mon Sep 17 00:00:00 2001 From: em Date: Fri, 26 Jul 1985 17:15:15 +0000 Subject: [PATCH 0067/1625] The identifier ns occurs in C programs. --- lib/ns/descr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ns/descr b/lib/ns/descr index 8051f72f..dd58316d 100644 --- a/lib/ns/descr +++ b/lib/ns/descr @@ -5,7 +5,7 @@ var s=2 var l=4 var f=4 var d=8 -var NAME=ns +var NAME=ns16032 var M=ns var LIB=lib/{M}/tail_ var RT=lib/{M}/head_ From a4c5892c11a391886e2d4793942e2007b6cf62a6 Mon Sep 17 00:00:00 2001 From: em Date: Fri, 26 Jul 1985 17:38:22 +0000 Subject: [PATCH 0068/1625] Added str0 and str 1. --- mach/ns/ncg/table | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mach/ns/ncg/table b/mach/ns/ncg/table index 5e8f3ee1..71f6de5e 100644 --- a/mach/ns/ncg/table +++ b/mach/ns/ncg/table @@ -235,6 +235,7 @@ jsr tosdst4+label . ret const4:ro . adjspd tossrc4:ro . exit label . +sprd tossrc4:ro, MEMREG:rw . @@ -2180,6 +2181,14 @@ pat sim with src24 gen movw %1, {absolute2, ".ignmask"} +pat str $1==0 +with src4 +gen sprd %1, fp + +pat str $1==1 +with src4 +gen sprd %1, sp + pat str $1==2 with src4 gen move %1, {absolute4, ".reghp"} From 4dd4bcef577f8569f4c70edf19aab2887375ad75 Mon Sep 17 00:00:00 2001 From: bal Date: Tue, 13 Aug 1985 14:03:23 +0000 Subject: [PATCH 0069/1625] bug fixed: null-pointer dereference. --- lang/basic/src.old/basic.lex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/basic/src.old/basic.lex b/lang/basic/src.old/basic.lex index 69b95686..526b37cf 100644 --- a/lang/basic/src.old/basic.lex +++ b/lang/basic/src.old/basic.lex @@ -232,7 +232,7 @@ lookup() for(c=cptr; *c && isalnum(*c);c++) if( isupper(*c) ) *c= tolower((*c)); - for(k= keywords+kex[*cptr-'a']; *(k->name)== *cptr;k++) + for(k= keywords+kex[*cptr-'a']; k->name != 0 && *(k->name)== *cptr;k++) if( strncmp(cptr,k->name,k->length)==0) { /* check functions first*/ From 047312216f098c64625346c2101f62449d3c58d4 Mon Sep 17 00:00:00 2001 From: bal Date: Fri, 6 Sep 1985 11:06:32 +0000 Subject: [PATCH 0070/1625] MAXSTAB set to 2500 (problem with argument list of ROM for new C front-end). --- mach/proto/cg/salloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/proto/cg/salloc.c b/mach/proto/cg/salloc.c index 0543c96a..62964013 100644 --- a/mach/proto/cg/salloc.c +++ b/mach/proto/cg/salloc.c @@ -35,7 +35,7 @@ static char rcsid[] = "$Header$"; * Every now and then call garbage_collect() from toplevel. */ -#define MAXSTAB 500 +#define MAXSTAB 2500 #define THRESHOLD 200 char *stab[MAXSTAB]; From 401fadafeca6bdeca3d6adbb1ecedac7f2ce5e85 Mon Sep 17 00:00:00 2001 From: bal Date: Fri, 6 Sep 1985 11:38:00 +0000 Subject: [PATCH 0071/1625] exit(0) added (trouble with make) --- util/ego/share/makewlen.c | 1 + 1 file changed, 1 insertion(+) diff --git a/util/ego/share/makewlen.c b/util/ego/share/makewlen.c index a26dc890..a20d9fdf 100644 --- a/util/ego/share/makewlen.c +++ b/util/ego/share/makewlen.c @@ -1,4 +1,5 @@ main() { printf("#define WORDLENGTH %d\n",sizeof(int) * 8); + exit(0); } From b048814b688ae265be6099f280a1319d76906f52 Mon Sep 17 00:00:00 2001 From: bal Date: Fri, 6 Sep 1985 11:39:06 +0000 Subject: [PATCH 0072/1625] sprintf does not return pointer to string so the assert(s==string) does not make any sense. --- util/ego/ic/ic_io.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/util/ego/ic/ic_io.c b/util/ego/ic/ic_io.c index 017ff1e6..4bb56b6e 100644 --- a/util/ego/ic/ic_io.c +++ b/util/ego/ic/ic_io.c @@ -91,11 +91,8 @@ offset get_off() { } STATIC make_string(n) int n; { - register char *s; - extern char *sprintf(); - s=sprintf(string,".%u",n); - assert(s == string); + sprintf(string,".%u",n); } STATIC inident() { From a9a88f29a0c747511814cabb83c5442915e344c2 Mon Sep 17 00:00:00 2001 From: bal Date: Wed, 18 Sep 1985 16:27:29 +0000 Subject: [PATCH 0073/1625] bug fixed: last instruction of first block in block fusion optimization can be a conditional branch. (bug detected by Ceriel). --- util/ego/bo/bo.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/util/ego/bo/bo.c b/util/ego/bo/bo.c index 693d67ed..bcefd098 100644 --- a/util/ego/bo/bo.c +++ b/util/ego/bo/bo.c @@ -192,7 +192,9 @@ STATIC mv_code(b1,b2) l = last_code(b2->b_start,TRUE); DLINK(l,b1->b_start); x = l->l_next; - if (INSTR(l) == op_bra) { + if (TYPE(l) == OPINSTRLAB) { + assert(INSTR(x) == op_lab); + assert(INSTRLAB(l) == INSTRLAB(x)); rm_line(l,b2); } if (INSTR(x) == op_lab) { From 8903bc749a8f364d5d721d118dc2f81a89eee600 Mon Sep 17 00:00:00 2001 From: bal Date: Thu, 19 Sep 1985 11:14:55 +0000 Subject: [PATCH 0074/1625] bug fixed: same problem as in r1.3, now with csb. Solution: only do block fusion if first block end on bra. --- util/ego/bo/bo.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/util/ego/bo/bo.c b/util/ego/bo/bo.c index bcefd098..02cb8640 100644 --- a/util/ego/bo/bo.c +++ b/util/ego/bo/bo.c @@ -190,13 +190,10 @@ STATIC mv_code(b1,b2) line_p l,x; l = last_code(b2->b_start,TRUE); + assert(INSTR(l) == op_bra); DLINK(l,b1->b_start); x = l->l_next; - if (TYPE(l) == OPINSTRLAB) { - assert(INSTR(x) == op_lab); - assert(INSTRLAB(l) == INSTRLAB(x)); - rm_line(l,b2); - } + rm_line(l,b2); if (INSTR(x) == op_lab) { rm_line(x,b2); } @@ -207,13 +204,15 @@ bo_switch(b) { bblock_p s,x; Lindex i; - line_p l; + line_p l,bra; if (Lnrelems(b->b_succ) == 1) { s = (bblock_p) Lelem(Lfirst(b->b_succ)); if (b->b_start != (line_p) 0 && s->b_start != (line_p) 0 && Lnrelems(s->b_pred) == 1 && + (bra = last_code(b->b_start,TRUE)) != (line_p) 0 && + INSTR(bra) == op_bra && (s->b_next == (bblock_p) 0 || !Lis_elem(s->b_next,s->b_succ))) { l = last_code(s->b_start,FALSE); From d32be9ac07431e2555a28628769f6bb780922b4e Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 19 Sep 1985 14:03:13 +0000 Subject: [PATCH 0075/1625] Name change : tail_em.vend -> end_em.s --- lib/pmds/descr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pmds/descr b/lib/pmds/descr index 7f0f99e1..34b56f7f 100644 --- a/lib/pmds/descr +++ b/lib/pmds/descr @@ -37,7 +37,7 @@ name asld (.p:{TAIL}={EM}/{LIB}pc) \ (.b:{TAIL}={EM}/{LIB}bc) \ (.b.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \ - (.e:{TAIL}={EM}/{LIB}em.rt {EM}/{PMDSLIB}mon {EM}/{LIB}em.vend) + (.e:{TAIL}={EM}/{LIB}em.rt {EM}/{PMDSLIB}mon {EM}/lib/{M}/end_em.s) prep cond linker end From cc731d51e2a0adb64bae6e9348001cc8acc45543 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 2 Oct 1985 22:20:04 +0000 Subject: [PATCH 0076/1625] Initial revision --- util/LLgen/src/compute.c | 812 ++++++++++++++++++++++++++++++++++++ util/LLgen/src/gencode.c | 877 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 1689 insertions(+) create mode 100644 util/LLgen/src/compute.c create mode 100644 util/LLgen/src/gencode.c diff --git a/util/LLgen/src/compute.c b/util/LLgen/src/compute.c new file mode 100644 index 00000000..04a1e36b --- /dev/null +++ b/util/LLgen/src/compute.c @@ -0,0 +1,812 @@ +/* + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. + * + * This product is part of the Amsterdam Compiler Kit. + * + * Permission to use, sell, duplicate or disclose this software must be + * obtained in writing. Requests for such permissions may be sent to + * + * Dr. Andrew S. Tanenbaum + * Wiskundig Seminarium + * Vrije Universiteit + * Postbox 7161 + * 1007 MC Amsterdam + * The Netherlands + * + */ + +/* + * L L G E N + * + * An Extended LL(1) Parser Generator + * + * Author : Ceriel J.H. Jacobs + */ + +/* + * compute.c + * Defines routines to compute FIRST, FOLLOW etc. + * Also checks the continuation grammar from the specified grammar. + */ + +# include "types.h" +# include "tunable.h" +# include "extern.h" +# include "sets.h" +# include "assert.h" +# ifndef NDEBUG +# include "io.h" +# endif + +# ifndef NORCSID +static string rcsid2 = "$Header$"; +# endif + +p_set setalloc(); + +/* Defined in this file : */ +extern createsets(); +STATIC walk(); +extern co_empty(); +extern empty(); +extern co_first(); +STATIC first(); +extern co_follow(); +STATIC follow(); +extern co_symb(); +STATIC co_dirsymb(); +STATIC co_others(); +STATIC do_checkdefault(); +STATIC checkdefault(); +extern co_contains(); +STATIC do_contains(); +STATIC contains(); +extern co_safes(); +STATIC int do_safes(); + +createsets() { + /* + * Allocate space for the sets + */ + register p_nont p; + + for (p = nonterms; p < maxnt; p++) { + p->n_first = setalloc(setsize); + p->n_follow = setalloc(setsize); + walk(p->n_rule); + } +} + +STATIC +walk(p) register p_gram p; { + /* + * Walk through the grammar rule p, allocating sets + */ + + for (;;) { + switch (g_gettype(p)) { + case TERM : { + register p_term q; + + q = (p_term) pentry[g_getcont(p)]; + q->t_first = setalloc(setsize); + q->t_follow = setalloc(setsize); + walk(q->t_rule); + break; } + case ALTERNATION : { + register p_link l; + + l = (p_link) pentry[g_getcont(p)]; + l->l_symbs = setalloc(setsize); + walk(l->l_rule); + break; } + case EORULE : + return; + } + p++; + } +} + +co_empty() { + /* + * Which nonterminals produce the empty string ? + */ + register int change; + register p_nont p; + + change = 1; + while (change) { + change = 0; + for (p=nonterms; p < maxnt; p++) { + if ((!(p->n_flags & EMPTY)) && empty(p->n_rule)) { + p->n_flags |= EMPTY; + change = 1; + } + } + } +} + +empty(p) register p_gram p; { + /* + * Does the rule pointed to by p produce empty ? + */ + + for (;;) { + switch (g_gettype(p)) { + case EORULE : + return 1; + case TERM : { + register p_term q; + + q = (p_term) pentry[g_getcont(p)]; + if (r_getkind(&(q->t_reps)) == STAR + || r_getkind(&(q->t_reps)) == OPT + || empty(q->t_rule) ) break; + return 0; } + case ALTERNATION : + if (empty(((p_link)pentry[g_getcont(p)])->l_rule)) { + return 1; + } + if (g_gettype(p+1) == EORULE) return 0; + break; + case NONTERM : + if (nonterms[g_getnont(p)].n_flags & EMPTY) { + break; + } + /* Fall through */ + case TERMINAL : + return 0; + } + p++; + } +} + +co_first() { + /* + * Compute the FIRST set for each nonterminal + */ + + register p_nont p; + register int change; + + change = 1; + while (change) { + change = 0; + for (p = nonterms; p < maxnt; p++) { + if (first(p->n_first,p->n_rule,0)) change = 1; + } + } +} + +STATIC +first(setp,p,flag) p_set setp; register p_gram p; { + /* + * Compute the FIRST set of rule p. + * If flag = 0, also the first sets for terms and alternations in + * the rule p are computed. + * The FIRST set is put in setp. + * return 1 if any of the sets changed + */ + register s; /* Will gather return value */ + int noenter;/* when set, unables entering of elements into + * setp. This is necessary to walk through the + * rest of rule p. + */ + + s = 0; + noenter = 0; + for (;;) { + switch (g_gettype(p)) { + case EORULE : + return s; + case TERM : { + register p_term q; + + q = (p_term) pentry[g_getcont(p)]; + if (flag == 0) s |= first(q->t_first,q->t_rule,0); + if (!noenter) s |= setunion(setp,q->t_first,setsize); + p++; + if (r_getkind(&(q->t_reps)) == STAR + || r_getkind(&(q->t_reps)) == OPT + || empty(q->t_rule) ) continue; + break; } + case ALTERNATION : { + register p_link l; + + l = (p_link) pentry[g_getcont(p)]; + if (flag == 0) s |= first(l->l_symbs,l->l_rule,0); + if (noenter == 0) { + s |= setunion(setp,l->l_symbs,setsize); + } + if (g_gettype(p+1) == EORULE) return s; + } + /* Fall Through */ + case ACTION : + p++; + continue; + case TERMINAL : + if ((noenter == 0) && !IN(setp,g_getcont(p))) { + s = 1; + PUTIN(setp,g_getcont(p)); + } + p++; + break; + case NONTERM : { + register p_nont n; + + n = &nonterms[g_getnont(p)]; + if (noenter == 0) { + s |= setunion(setp,n->n_first,setsize); + if (ntneeded && ! NTIN(setp,n-nonterms)) { + s = 1; + NTPUTIN(setp,n-nonterms); + } + } + p++; + if (n->n_flags & EMPTY) continue; + break; } + } + if (flag == 0) { + noenter = 1; + continue; + } + return s; + } +} + +co_follow() { + /* + * Compute the follow set for each nonterminal + */ + + register p_nont p; + register change; + register i; + p_start st; + + /* + * First put EOFILE in the follow set of the start symbols + */ + for (st = start; st; st = st->ff_next) PUTIN(st->ff_nont->n_follow,0); + change = 1; + i = 1; + while (change) { + change = 0; + for (p = nonterms; p < maxnt; p++) { + if (follow(p->n_follow,p->n_rule,i)) change = 1; + } + i = 0; + } +} + +STATIC +follow(setp,p,flag) p_set setp; register p_gram p; { + /* + * setp is the follow set for the rule p. + * Compute the follow sets in the rule p from this set. + * Return 1 if any set changed + * flag controls the use of "first" in the computation. + * It should be 1 the first time a rule is done, 0 otherwise. + */ + register s; /* Will gather return value */ + + s = 0; + for (;;) { + switch (g_gettype(p)) { + case EORULE : + return s; + case TERM : { + register p_term q; + + q = (p_term) pentry[g_getcont(p)]; + if (empty(p+1)) { + /* + * If what follows the term can be empty, + * everything that can follow the whole + * rule can also follow the term + */ + s |= setunion(q->t_follow,setp,setsize); + } + /* + * Everything that can start the rest of the rule + * can follow the term + */ + if (flag) s |= first(q->t_follow,p+1,1); + if (r_getkind(&(q->t_reps)) == STAR + || r_getkind(&(q->t_reps)) == PLUS + || r_getnum(&(q->t_reps)) ) { + /* + * If the term involves a repetition + * of possibly more than one, + * everything that can start the term + * can also follow it. + */ + s |= follow(q->t_first,q->t_rule,flag); + } + /* + * Now propagate the set computed sofar + */ + s |= follow(q->t_follow, q->t_rule,flag); + break; } + case ALTERNATION : + /* + * Just propagate setp + */ + s |= follow(setp,((p_link)pentry[g_getcont(p)])->l_rule, + flag); + break; + case NONTERM : { + register p_nont n; + + n = &nonterms[g_getnont(p)]; + if (flag) s |= first(n->n_follow,p+1,1); + if (empty(p+1)) { + /* + * If the rest of p can produce empty, + * everything that follows p can follow + * the nonterminal + */ + s |= setunion(n->n_follow,setp,setsize); + } + break; } + } + p++; + } +} + +co_symb() { + /* + * Compute the sets which determine which alternative to choose + * in case of a choice + * Also check the continuation grammar and see if rules do scan + * ahead. + */ + register p_nont p; + + for (p = nonterms; p < maxnt; p++) { + co_dirsymb(p->n_follow,p->n_rule); + } + for (p = nonterms; p < maxnt; p++) { + do_checkdefault(p); + } +} + +STATIC +co_dirsymb(setp,p) p_set setp; register p_gram p; { + /* + * Walk the rule p, doing the work for alternations + */ + register p_gram s = 0; + + for (;;) { + switch (g_gettype(p)) { + case EORULE : + return; + case TERM : { + register p_term q; + + q = (p_term) pentry[g_getcont(p)]; + co_dirsymb(q->t_follow,q->t_rule); + break; } + case ALTERNATION : { + register p_link l; + /* + * Save first alternative + */ + if (!s) s = p; + l = (p_link) pentry[g_getcont(p)]; + l->l_others = setalloc(setsize); + co_dirsymb(setp,l->l_rule); + if (empty(l->l_rule)) { + /* + * If the rule can produce empty, everything + * that follows it can also start it + */ + setunion(l->l_symbs,setp,setsize); + } + if (g_gettype(p+1) == EORULE) { + /* + * Every alternation is implemented as a + * choice between two alternatives : + * this one or one of the following. + * The l_others set will contain the starters + * of the other alternatives + */ + co_others(s); + return; + } } + } + p++; + } +} + +STATIC +co_others(p) register p_gram p; { + /* + * compute the l_others-sets for the list of alternatives + * indicated by p + */ + register p_link l1,l2; + + l1 = (p_link) pentry[g_getcont(p)]; + p++; + l2 = (p_link) pentry[g_getcont(p)]; + setunion(l1->l_others,l2->l_symbs,setsize); + if (g_gettype(p+1) != EORULE) { + /* + * First compute l2->l_others + */ + co_others(p); + /* + * and then l1->l_others + */ + setunion(l1->l_others,l2->l_others,setsize); + } +} + +STATIC +do_checkdefault(p) register p_nont p; { + /* + * check the continuation rule for nonterminal p, unless + * this is already being(!) done + */ + if (p->n_flags & BUSY) { + /* + * Error situation, recursion in continuation grammar + */ + p->n_flags ^= (RECURSIVE|BUSY); + return; + } + if (p->n_flags & CONTIN) { + /* + * Was already done + */ + return; + } + /* + * Now mark it as busy, and check the rule + */ + p->n_flags |= BUSY; + checkdefault(p->n_rule); + /* + * Now release the busy mark, and mark it as done + */ + p->n_flags ^= (CONTIN|BUSY); + return; +} + +STATIC +checkdefault(p) register p_gram p; { + /* + * Walk grammar rule p, checking the continuation grammar + */ + register p_link l; + register p_term q; + + for (;;) { + switch (g_gettype(p)) { + case EORULE : + return; + case ALTERNATION : + l = (p_link) pentry[g_getcont(p)]; + if (l->l_flag & DEF) { + /* + * This alternative belongs to the + * continuation grammar, so check it + */ + checkdefault(l->l_rule); + return; + } + break; + case TERM : + q = (p_term) pentry[g_getcont(p)]; + /* + * First check the rest of the rule + */ + checkdefault(p+1); + /* + * Now check the term if it belongs to the + * continuation grammar + */ + if (r_getkind(&(q->t_reps))==FIXED || + r_getkind(&(q->t_reps))==PLUS) { + checkdefault(q->t_rule); + return; + } + /* + * Here we have OPT or STAR + * Only in the continuation grammar if %persistent + */ + if (q->t_flags & PERSISTENT) { + checkdefault(q->t_rule); + } + return; + case NONTERM : + /* + * Check the continuation grammar for this nonterminal. + * Note that the nonterminal we are working on is + * marked as busy, so that direct or indirect recursion + * can be detected + */ + do_checkdefault(&nonterms[g_getnont(p)]); + break; + } + p++; + } +} + +co_contains() { + /* + * Compute the contains sets + */ + register p_nont p; + register p_set dummy; + + for (p = nonterms; p < maxnt; p++) do_contains(p); + dummy = setalloc(setsize); +# ifndef NDEBUG + if (debug) fputs("Contains 1 done\n", stderr); +# endif + free(dummy); + for (p = nonterms; p < maxnt; p++) contains(p->n_rule, (p_set) 0); +# ifndef NDEBUG + if (debug) fputs("Contains 2 done\n", stderr); +# endif + dummy = setalloc(setsize); + free(dummy); +} + +STATIC +do_contains(n) register p_nont n; { + /* + * Compute the total set of symbols that nonterminal n can + * produce + */ + + if (n->n_contains == 0) { + n->n_contains = setalloc(setsize); + contains(n->n_rule,n->n_contains); + /* + * If the rule can produce empty, delete all symbols that + * can follow the rule as well as be in the rule. + * This is needed because the contains-set may only contain + * symbols that are guaranteed to be eaten by the rule! + * Otherwise, the generated parser may loop forever + */ + if (n->n_flags & EMPTY) { + setminus(n->n_contains,n->n_follow,setsize); + } + /* + * But the symbols that can start the rule are always + * eaten + */ + setunion(n->n_contains,n->n_first,setsize); + } +} + +STATIC +contains(p,set) register p_gram p; register p_set set; { + /* + * Does the real computation of the contains-sets + */ + + for (;;) { + switch (g_gettype(p)) { + case EORULE : + return; + case TERM : { + register p_term q; + + q = (p_term) pentry[g_getcont(p)]; + if ((q->t_flags & PERSISTENT) || + r_getkind(&(q->t_reps)) == PLUS || + r_getkind(&(q->t_reps)) == FIXED) { + /* + * In these cases, the term belongs to the + * continuation grammar. + * Otherwise, q->t_contains is just + * q->t_first + */ + if (!q->t_contains) { + q->t_contains = setalloc(setsize); + } + contains(q->t_rule,q->t_contains); + if (empty(q->t_rule)) { + /* + * Same trouble as mentioned in the + * routine do_contains + */ + setminus(q->t_contains,q->t_follow, + setsize); + } + setunion(q->t_contains,q->t_first,setsize); + } else { + contains(q->t_rule, (p_set) 0); + q->t_contains = q->t_first; + } + if (set) setunion(set,q->t_contains,setsize); + break; } + case NONTERM : { + register p_nont n; + + n = &nonterms[g_getnont(p)]; + do_contains(n); + if(set) setunion(set, n->n_contains,setsize); + break; } + case ALTERNATION : { + register p_link l; + + l = (p_link) pentry[g_getcont(p)]; + contains(l->l_rule, + (l->l_flag & DEF) ? set : (p_set) 0); + break; } + case TERMINAL : { + register hulp; + + if (set) { + hulp = g_getcont(p); + assert(hulp < nterminals); + PUTIN(set,hulp); + }} + } + p++; + } +} + +static int change; + +co_safes() { + /* + * Compute the safety of each nonterminal and term. + * The safety gives an answer to the question whether a scan is done, + * and how it should be handled. + */ + + register p_nont p; + register i; + register p_start st; + + for (p = nonterms; p < maxnt; p++) { + /* + * Don't know anything yet + */ + setntsafe(&(p->n_flags), NOSAFETY); + } + for (st = start; st; st = st->ff_next) { + /* + * But start symbols are called with lookahead done + */ + p = st->ff_nont; + setntsafe(&(p->n_flags),SCANDONE); + } + change = 1; + while (change) { + change = 0; + for (p = nonterms; p < maxnt; p++) { + i = getntsafe(p->n_flags); + if (i == NOSAFETY) { + change = 1; + continue; + } + if (do_safes(p->n_rule, i) == 2 && + !(p->n_flags & NNOSCAN)) { + p->n_flags |= NNOSCAN; + change = 1; + } + } + } +} + +STATIC int +do_safes(p,safe) register p_gram p; { + /* + * Walk the grammar rule, doing the computation described in the + * comment of the procedure above this one. + */ + register retval; + + if (safe == NOSCANDONE) retval = 2; + else retval = 1; + for (;;) { + switch (g_gettype(p)) { + case ACTION: + p++; + continue; + case TERMINAL: + retval = 2; + break; + case TERM : { + register p_term q; + int i,rep; + + q = (p_term) pentry[g_getcont(p)]; + i = r_getnum(&(q->t_reps)); + rep = r_getkind(&(q->t_reps)); + retval = do_safes(q->t_rule, + t_safety(rep,i,q->t_flags&PERSISTENT,safe)); + if (retval == 2 && (!(q->t_flags & TNOSCAN))) { + q->t_flags |= TNOSCAN; + } + if (rep != FIXED || retval == 0) retval = 1; + break; } + case ALTERNATION : { + register p_link l; + int f, i; + + f = 1; + while (g_gettype(p) == ALTERNATION) { + l = (p_link) pentry[g_getcont(p)]; + if (safe && (l->l_flag & DEF)) { + i = do_safes(l->l_rule,SAFESCANDONE); + } + else i = do_safes(l->l_rule,SAFE); + if (f) retval = i; + else retval &= i; + p++; + f = 0; + } + return retval; } + case NONTERM : { + register p_nont n; + int nsafe; + + n = &nonterms[g_getnont(p)]; + nsafe = getntsafe(n->n_flags); + if (!(n->n_flags & NNOSCAN)) retval = 1; + else retval = 2; + if (safe == nsafe) break; + if (nsafe == NOSAFETY) { + change = 1; + setntsafe(&(n->n_flags), safe); + break; + } + if (safe == NOSCANDONE || nsafe == NOSCANDONE) { + if (nsafe != SCANDONE) { + change = 1; + setntsafe(&(n->n_flags), SCANDONE); + } + break; + } + if (safe > nsafe) { + setntsafe(&(n->n_flags), safe); + change = 1; + } + break; } + case EORULE : + return retval; + } + p++; + if (retval == 1) safe = SCANDONE; + else safe = NOSCANDONE; + } +} + +t_safety(rep, count, persistent, safety) { + + switch(rep) { + default: + assert(0); + case OPT: + if (!persistent) return SAFE; + if (safety < SAFESCANDONE) return safety; + return SAFESCANDONE; + case STAR: + if (persistent) return SAFESCANDONE; + return SAFE; + case PLUS: + if (safety == NOSCANDONE) safety = SCANDONE; + if (persistent) { + if (safety > SAFESCANDONE) return safety; + return SAFESCANDONE; + } + if (safety > SAFE) return safety; + return SAFE; + case FIXED: + if (!count) { + if (safety == NOSCANDONE) safety = SCANDONE; + return safety; + } + return SCANDONE; + } + /* NOTREACHED */ +} diff --git a/util/LLgen/src/gencode.c b/util/LLgen/src/gencode.c new file mode 100644 index 00000000..260f776b --- /dev/null +++ b/util/LLgen/src/gencode.c @@ -0,0 +1,877 @@ +/* + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. + * + * This product is part of the Amsterdam Compiler Kit. + * + * Permission to use, sell, duplicate or disclose this software must be + * obtained in writing. Requests for such permissions may be sent to + * + * Dr. Andrew S. Tanenbaum + * Wiskundig Seminarium + * Vrije Universiteit + * Postbox 7161 + * 1007 MC Amsterdam + * The Netherlands + * + */ + +/* + * L L G E N + * + * An Extended LL(1) Parser Generator + * + * Author : Ceriel J.H. Jacobs + */ + +/* + * gencode.c + * Defines the routine "gencode", which generates the parser + * we wanted so badly. + * This file is a mess, it should be cleaned up some time. + */ + +# include "types.h" +# include "io.h" +# include "tunable.h" +# include "extern.h" +# include "sets.h" +# include "assert.h" + +# ifndef NORCSID +static string rcsid3 = "$Header$"; +# endif NORCSID + +/* + * Some codestrings used more than once + */ + +static string c_arrend = "0 };\n"; +static string c_close = "}\n"; +static string c_LLptrmin = "LLptr++;\n"; +static string c_break = "break;\n"; +static string c_read = "LLread();\n"; + +/* Some constants used for reading from the action file */ +# define ENDDECL 0400 +# define IDENT 0401 + +static int nlabel; /* count for the generation of labels */ +static int nvar; /* count for generation of variables */ +static int pushlist[100]; +static int *ppushlist; +static int *lists,*maxlists,*plists; +p_mem ralloc(),alloc(); + +/* In this file the following routines are defined: */ +extern gencode(); +STATIC opentemp(); +STATIC geninclude(); +STATIC genrecovery(); +STATIC string genname(); +STATIC generate(); +STATIC prset(); +STATIC macro(); +STATIC controlline(); +STATIC getparams(); +STATIC gettok(); +STATIC rulecode(); +STATIC int dopush(); +STATIC pushcode(); +STATIC getaction(); +STATIC codeforterm(); +STATIC genifhead(); +STATIC gencases(); +STATIC genpush(); + +/* Macro to print a terminal */ +# define PTERM(f,p) fprintf(f,(p)->h_num<0400?"'%s'":"%s",(p)->h_name) + +gencode(argc) { + register p_file p = files; + + /* Generate include file Lpars.h */ + geninclude(); + + /* Set up for code generation */ + if ((fact = fopen(f_temp,"r")) == NULL) { + fatal(0,e_noopen,f_temp); + } + lists = (int *) alloc(50 * sizeof(int)); + plists = lists; + maxlists = lists+49; + + /* For every source file .... */ + while (argc--) { + /* Open temporary */ + f_input = p->f_name; + opentemp(f_input); + /* generate code ... */ + copyfile(0); + generate(p); + getaction(2); + if (ferror(fpars) != 0) { + fatal(0,"Write error on temporary"); + } + fclose(fpars); + /* And install */ + install(genname(p->f_name),p->f_name); + p++; + } + genrecovery(); +} + +STATIC +opentemp(str) string str; { + + if ((fpars = fopen(f_pars,"w")) == NULL) { + fatal(0,e_noopen,f_pars); + } + fprintf(fpars,LLgenid,str ? str : "."); +} + +STATIC +geninclude() { + register p_entry p; + register FILE *f; + + opentemp((string) 0); + f = fpars; + for (p = h_entry; p < max_t_ent; p++) { + if (p->h_num >= 0400) { + fprintf(f,"# define %s %d\n", p->h_name,p->h_num); + } + } + if (ferror(f) != 0) { + fatal(0,"write error on temporary"); + } + fclose(f); + install(HFILE, (string) 0); +} + +STATIC +genrecovery() { + register FILE *f; + register p_entry t; + register int i; + register int *q; + int index[256+NTERMINALS]; + register p_start st; + + opentemp((string) 0); + f = fpars; + copyfile(0); + /* Now generate the routines that call the startsymbols */ + fputs("#define LLSTSIZ 1024\n",f); + for (i = 1, st = start; st; st = st->ff_next) { + i++; + fputs(st->ff_name, f); + fputs("() {\n\tint LLstack[LLSTSIZ];\n\tLLnewlevel(LLstack);\n\tLLread();\n", f); + if (g_gettype(st->ff_nont->n_rule) == ALTERNATION) { + fprintf(f, "\tLLxx.LLx_p--; *LLxx.LLx_p = %d;\n", + findindex(&(st->ff_nont->n_contains))); + } + fprintf(f, "\tL%d_%s();\n", + st->ff_nont-nonterms, + (min_nt_ent+(st->ff_nont-nonterms))->h_name); + if (st->ff_nont->n_flags & NNOSCAN) { + fputs("\tLLscan(EOFILE);\n",f); + } + else fputs("\tif (LLsymb != EOFILE) LLerror(EOFILE);\n",f); + fputs("\tLLoldlevel();\n}\n",f); + } + fprintf(f,"#define LL_MAX %d\n#define LL_LEXI %s\n", i, lexical); + fputs("static short LLlists[] = {\n", f); + /* Now generate lists */ + q = lists; + while (q < plists) { + fprintf(f,"%d,\n",*q++); + } + fputs(c_arrend, f); + /* Now generate the sets */ + fputs("char LLsets[] = {\n",f); + for (i = 0; i < maxptr-setptr; i++) prset(setptr[i]); + fputs(c_arrend, f); + for (q = index; q <= &index[255 + NTERMINALS];) *q++ = -1; + for (t = h_entry; t < max_t_ent; t++) { + index[t->h_num] = t - h_entry; + } + fputs("short LLindex[] = {\n",f); + for (q = index; q <= &index[assval-1]; q++) { + fprintf(f, "%d,\n", *q); + } + fputs(c_arrend, f); + copyfile(1); + if (ferror(f) != 0) { + fatal(0,"write error on temporary"); + } + fclose(f); + install(RFILE, (string) 0); +} + +STATIC +generate(f) p_file f; { + /* + * Generates a parsing routine for every nonterminal + */ + register short *s; + register p_nont p; + register FILE *fd; + int i; + p_first ff; + int mustpop; + + /* Generate first sets */ + for (ff = f->f_firsts; ff; ff = ff->ff_next) { + macro(ff->ff_name,ff->ff_nont); + } + + /* For every nonterminal generate a function */ + fd = fpars; + for (s = f->f_start; s <= f->f_end; s++) { + p = &nonterms[*s]; + /* Generate functions in the order in which the nonterminals + * were defined in the grammar. This is important, because + * of synchronisation with the action file + */ + while (p->n_count--) getaction(1); + if (p->n_flags & PARAMS) controlline(); + fprintf(fd,"L%d_%s (",*s,(min_nt_ent + *s)->h_name); + if (p->n_flags & PARAMS) getparams(); + else fputs(") {\n", fd); + fputs("register struct LLxx *LLx = &LLxx;\n#ifdef lint\nLLx=LLx;\n#endif\n", fd); + if (p->n_flags & LOCALS) getaction(1); + i = getntsafe(p->n_flags); + mustpop = 0; + if (g_gettype(p->n_rule) == ALTERNATION) { + mustpop = 1; + if (i == NOSCANDONE) { + fputs(c_read, fd); + i = SCANDONE; + } + } + nlabel = 1; + rulecode(p->n_rule, + i, + !(p->n_flags & NNOSCAN), mustpop); + fputs(c_close, fd); + } +} + +STATIC +prset(p) p_set p; { + register int k; + register unsigned i; + int j; + + j = NBYTES(nterminals); + for (;;) { + i = (unsigned) *p++; + for (k = 0; k < sizeof(int); k++) { + fprintf(fpars,"0%o,",(i & 0377)); + i >>= 8; + if (--j == 0) { + fputs("\n",fpars); + return; + } + } + } + /* NOTREACHED */ +} + +STATIC +macro(s,n) string s; p_nont n; { + register FILE *f; + int i; + + f = fpars; + i = findindex(&(n->n_first)); + fprintf(f,"#define %s(x) ", s); + if (i < 0) { + fprintf(f, "((x) == %d)\n", -i); + return; + } + fprintf(f,"LLfirst((x), %d)\n", i); +} + +STATIC +controlline() { + /* Copy a compiler control line */ + register int l; + register FILE *f1,*f2; + + f1 = fact; f2 = fpars; + l = getc(f1); + assert(l == '\0'); + l = getc(f1); putc(l,f2); + assert( l == '#' ) ; + do { + l = getc(f1); + putc(l,f2); + } while ( l != '\n' ) ; +} + +STATIC +getparams() { + /* getparams is called if a nonterminal has parameters. The names + * of the parameters have to be found, and they should be declared + */ + long off; + register int l; + register FILE *f; + long ftell(); + char first; + + first = ' '; + f = fpars; + /* save offset in file to be able to copy the declaration later */ + off = ftell(fact); + /* First pass through declaration, find the parameter names */ + while ((l = gettok()) != ENDDECL) { + if (l == ';' || l == ',') { + /* + * The last identifier found before a ';' or a ',' + * must be a parameter + */ + fprintf(f,"%c%s", first, ltext); + first = ','; + } + } + fputs(") ",f); + /* + * Now copy the declarations + */ + fseek(fact,off,0); + getaction(0); + fputs(" {\n",f); +} + +STATIC +gettok() { + /* Read from the action file. */ + register int ch; + register string c; + register FILE *f; + + f = fact; + ch = getc(f); + switch(ch) { + case '\n': + ch = getc(f); + if (ch != EOF) { + ungetc(ch,f); + if (ch != '\0') return '\n'; + } + return ENDDECL; + case '\0': + ungetc(ch,f); + /* Fall through */ + case EOF : + return ENDDECL; + default : + if (isalpha(ch) || ch == '_') { + c = ltext; + while (isalnum(ch) || ch == '_') { + *c++ = ch; + if (c-ltext >= LTEXTSZ) --c; + ch = getc(f); + } + if (ch != EOF) ungetc(ch,f); + *c = '\0'; + return IDENT; + } + return ch; + } +} + +STATIC +rulecode(p,safety,mustscan,mustpop) register p_gram p; { + /* + * Code for a production rule. + */ + + register int toplevel = 1; + register FILE *f; + + /* + * First generate code to push the contains sets of this rule + * on a stack + */ + ppushlist = pushlist; + if (dopush(p,safety,1) > 0) pushcode(); + f = fpars; + for (;;) { + switch (g_gettype(p)) { + case EORULE : + if (mustscan && safety == NOSCANDONE) { + fputs(c_read,f); + } + return; + case TERMINAL : { + register p_entry t; + + t = &h_entry[g_getcont(p)]; + if (toplevel == 0 && safety != NOSCANDONE) { + fputs(c_LLptrmin,f); + } + if (safety == SAFE) { + fputs("LL_SAFE(",f); + } + else if (safety <= SCANDONE) { + fputs("LL_SCANDONE(",f); + } + else if (safety == NOSCANDONE) { + if (toplevel != 0) { + fputs("LL_T_NOSCANDONE(", f); + } + else fputs("LL_N_NOSCANDONE(", f); + } + PTERM(f,t); + fputs(");\n", f); + if (safety == SAFE && toplevel > 0) { + safety = NOSCANDONE; + toplevel = -1; + p++; + continue; + } + safety = NOSCANDONE; + break; } + case NONTERM : { + p_entry t; + register p_nont n; + int params; + + n = &nonterms[g_getnont(p)]; + t= min_nt_ent+(n-nonterms); + if (safety == NOSCANDONE && + getntsafe(n->n_flags) < NOSCANDONE) fputs(c_read, f); + if (toplevel == 0 && + g_gettype(n->n_rule) != ALTERNATION) { + fputs(c_LLptrmin, f); + } + params = g_getnpar(p); + if (params) controlline(); + fprintf(f,"L%d_%s(",n-nonterms, t->h_name); + if (params) getaction(0); + fputs(");\n",f); + safety = NOSCANDONE; + if (!(n->n_flags & NNOSCAN)) safety = SCANDONE; + break; } + case TERM : + safety = codeforterm((p_term) pentry[g_getcont(p)], + safety, + toplevel); + break; + case ACTION : + getaction(1); + p++; + continue; + case ALTERNATION : + alternation(p, safety, mustscan,mustpop, 0); + return; + } + p++; + toplevel = 0; + } +} + +alternation(p, safety, mustscan, mustpop, lb) register p_gram p; { + register FILE *f = fpars; + register p_link l; + int hulp, hulp1,hulp2; + int var; + int haddefault = 0; + int unsafe = 1; + p_set set; + p_set setalloc(); + + assert(safety < NOSCANDONE); + l = (p_link) pentry[g_getcont(p)]; + hulp = nlabel++; + hulp1 = nlabel++; + hulp2 = nlabel++; + var = nvar++; + if (!lb) lb = hulp1; + if (safety <= SAFESCANDONE) unsafe = 0; + if (unsafe && hulp1 == lb) fprintf(f,"L_%d: ", hulp1); + else if (mustpop) { + mustpop = 0; + fputs(c_LLptrmin, f); + } + if (unsafe) { + fprintf(f,"{ int LL_%d = 0;\n", var); + } + fputs("switch(LLcsymb) {\n", f); + while (g_gettype(p) != EORULE) { + l = (p_link) pentry[g_getcont(p)]; + if (unsafe && (l->l_flag & DEF)) { + haddefault = 1; + fprintf(f, +"default: if (!LL_%d && LLskip()) {LL_%d = 1; goto L_%d;}\ngoto L_%d;\n", + var, var, lb, hulp2); + } + if (l->l_flag & COND) { + set = setalloc(tsetsize); + setunion(set, l->l_others, tsetsize); + setintersect(set, l->l_symbs, tsetsize); + setminus(l->l_symbs, set, tsetsize); + setminus(l->l_others, set, tsetsize); + gencases(set); + free((p_mem) set); + controlline(); + fputs("if (!",f); + getaction(0); + fprintf(f,") goto L_%d;\n", hulp); + } + if (!unsafe && (l->l_flag & DEF)) { + fputs("default:\n", f); + haddefault = 1; + } + else gencases(l->l_symbs); + if (l->l_flag & DEF) { + if (unsafe) { + fprintf(f,"L_%d: ;\n", hulp2); + } + if (mustpop) fputs(c_LLptrmin, f); + rulecode(l->l_rule, SAFESCANDONE, mustscan, 0); + } + else { + if (mustpop) fputs(c_LLptrmin, f); + rulecode(l->l_rule, SAFE, mustscan, 0); + } + fputs(c_break,f); + if (l->l_flag & COND) { + if (!haddefault) { + fputs("default:\n", f); + } + else { + gencases(l->l_others); + safety = SAFE; + } + fprintf(f,"L_%d : ;\n",hulp); + p++; + if (!unsafe && g_gettype(p+1) == EORULE) { + if (mustpop) fputs(c_LLptrmin, f); + rulecode(((p_link)pentry[g_getcont(p)])->l_rule, + safety,mustscan,0); + } + else alternation(p,safety,mustscan,mustpop,lb); + break; + } + p++; + } + fputs(c_close, f); + if (unsafe) fputs(c_close, f); + return; +} + +STATIC int +dopush(p,safety,toplevel) register p_gram p; { + /* + * The safety only matters if toplevel != 0 + */ + register int count = 0; + + for (;;) { + switch(g_gettype(p)) { + case EORULE : + case ALTERNATION : + return count; + case TERM : { + register p_term q; + + q = (p_term) pentry[g_getcont(p)]; + count += dopush(p+1,SCANDONE,0); + *ppushlist++ = findindex(&(q->t_contains)); + return count+1; } + case TERMINAL : + if (toplevel > 0 && safety == SAFE) { + count += dopush(p+1,NOSCANDONE,-1); + } + else count += dopush(p+1, NOSCANDONE, 0); + if (toplevel != 0) { + return count; + } + *ppushlist++ = -h_entry[g_getcont(p)].h_num; + return count + 1; + case NONTERM : { + register p_nont n; + + n = &nonterms[g_getnont(p)]; + count += dopush(p+1, SCANDONE, 0); + if (toplevel == 0 || + g_gettype(n->n_rule) == ALTERNATION) { + *ppushlist++ = findindex(&n->n_contains); + count++; + } + return count; } + } + p++; + } +} + +# define max(a,b) ((a) < (b) ? (b) : (a)) +STATIC +pushcode() { + register int i,j,k; + register int *p = pushlist; + + if ((i = ppushlist - p) == 0) return; + if (i <= 2) { + genpush(p[0]); + if (i == 2) genpush(p[1]); + return; + } + fprintf(fpars,"\LLlpush(%d, %d);\n",plists-lists, i); + if (maxlists - plists < i) { + j = plists - lists; + k = maxlists-lists+max(i+1,50); + lists = (int *) ralloc( (p_mem)lists, + (unsigned)(k+1)*sizeof(int)); + plists = lists+j; + maxlists = lists+k; + } + while (i--) { + *plists++ = *p++; + } +} + +STATIC +getaction(flag) { + /* Read an action from the action file. + * flag = 1 if it is an action, + * 0 when reading parameters + */ + register int match,ch; + register FILE *f; + register int newline; + int mark = 0; + + if (flag == 1) { + controlline(); + } + f = fpars; + newline = 0; + for (;;) { + ch = gettok(); + switch(ch) { + case ENDDECL: + if (flag != 2) break; + ch = getc(fact); + assert(ch == '\0'); + fputs("\n",f); + if (mark) return; + mark = 1; + continue; + case '\n': + newline = 1; + break; + case '\'' : + case '"' : + if (newline) { + newline = 0; + } + match = ch; + putc(ch,f); + while (ch = getc(fact)) { + if (ch == match) break; + if (ch == '\\') { + putc(ch,f); + ch = getc(fact); + } + putc(ch,f); + } + break; + case IDENT : + if (newline) { + newline = 0; + } + fputs(ltext,f); + continue; + } + mark = 0; + if (ch == ENDDECL) break; + if (newline && ch != '\n') { + newline = 0; + } + putc(ch,f); + } + if (flag) fputs("\n",f); +} + +STATIC +codeforterm(q,safety,toplevel) register p_term q; { + /* + * Generate code for a term + */ + register FILE *f; + register int i; + register int rep; + int persistent; + int noscan; + + f = fpars; + i = r_getnum(&(q->t_reps)); + rep = r_getkind(&(q->t_reps)); + persistent = (q->t_flags & PERSISTENT); + noscan = (q->t_flags & TNOSCAN); + if (safety == NOSCANDONE && (rep != FIXED || i == 0)) { + fputs(c_read, f); + if (rep == FIXED && g_gettype(q->t_rule) != ALTERNATION) { + fputs(c_LLptrmin, f); + } + } + if (i) { + /* N > 0, so generate fixed forloop */ + fprintf(f,"{\nregister LL_i = %d;\n",i); + fputs("for (;;) {\nif (!LL_i--) {\nLLptr++;\n", f); + fputs("break;\n}\n", f); + if (rep == FIXED) { + if (noscan && safety == NOSCANDONE) { + fputs(c_read,f); + } + } + } + else if (rep != OPT && rep != FIXED) { + /* '+' or '*', so generate infinite loop */ + fputs("for (;;) {\n",f); + } + if (rep == STAR || rep == OPT) { + genifhead(q,rep); + } + rulecode(q->t_rule,t_safety(rep,i,persistent,safety), + rep != FIXED || !noscan, + rep == FIXED && i == 0 && g_gettype(q->t_rule) == ALTERNATION); + /* in the case of '+', the if is after the code for the rule */ + if (rep == PLUS) { + if (!persistent) { + fprintf(f, "*LLptr = %d;\n", findindex(&(q->t_first))); + } + genifhead(q,rep); + } + if (rep != OPT && rep != FIXED) fputs("continue;\n", f); + if (rep != FIXED) { + fputs(c_close, f); /* Close switch */ + if (rep != OPT) { + fputs("break;\n", f); + } + } + if (rep != OPT && (rep != FIXED || i > 0)) { + fputs(c_close, f); /* Close for */ + if (i > 0) { + fputs(c_close, f);/* Close Register ... */ + } + } + if (rep != FIXED || !noscan) return SCANDONE; + return NOSCANDONE; +} + +STATIC +genifhead(q,rep) register p_term q; { + /* + * Generate if statement for term q + */ + register FILE *f; + p_set p1; + p_set setalloc(); + int hulp, hulp1; + + f = fpars; + hulp = nlabel++; + hulp1 = nlabel++; + fprintf(f, "L_%d : switch(LLcsymb) {\n", hulp); + if (q->t_flags & RESOLVER) { + p1 = setalloc(tsetsize); + setunion(p1,q->t_first,tsetsize); + setintersect(p1,q->t_follow,tsetsize); + /* + * p1 now points to a set containing the conflicting + * symbols + */ + setminus(q->t_first, p1, tsetsize); + setminus(q->t_follow, p1, tsetsize); + gencases(p1); + free((p_mem) p1); + controlline(); + fputs("if (", f); + getaction(0); + fprintf(f, ") goto L_%d;\n", hulp1); + } + gencases(q->t_follow); + fputs("LLptr++; break;\n", f); + fprintf(f, "default: if (!LLnext()) goto L_%d;\n", hulp); + gencases(q->t_first); + if (q->t_flags & RESOLVER) { + fprintf(f, "L_%d : ;\n", hulp1); + } + if (rep == OPT) { + fputs(c_LLptrmin,f); + } +} + +STATIC +gencases(setp) register p_set setp; { + /* + * setp points to a bitset indicating which cases must + * be generated. + * YECH, the PCC compiler does not accept many cases without statements + * inbetween, so after every case label an empty statement is + * generated. + * The C-grammar used by PCC is really stupid on this point : + * it contains the rule + * statement : label statement + * which is right-recursive, and as is well known, LALR parsers don't + * handle these things very good. + * The grammar should have been written : + * labeledstatement : labels statement ; + * labels : labels label | ; + */ + register p_entry p; + register i; + + p = h_entry; + for (i=0; i < nterminals; i++) { + if (IN(setp,i)) { + fprintf(fpars, + p->h_num<0400 ? "case /* '%s' */ %d : ;\n" + : "case /* %s */ %d : ;\n", + p->h_name, i); + } + p++; + } +} + +STATIC +genpush(d) { + + fprintf(fpars, "LLptr--;\n*LLptr = %d;\n",d); +} + +static char namebuf[20]; + +STATIC string +genname(s) string s; { + /* + * Generate a target file name from the + * source file name s. + */ + register string c,d; + + c = namebuf; + while (*s) { + if (*s == '/') { + while (*s == '/') s++; + if (*s) c = namebuf; + else break; + } + *c++ = *s++; + } + for (d = c; --d > namebuf;) if (*d == '.') break; + if (d == namebuf) d = c; + if (d >= &namebuf[12]) { + fatal(0,"%s : filename too long",namebuf); + } + *d++ = '.'; + *d++ = 'c'; + *d = '\0'; + return namebuf; +} From eb87fd5c0a800c1fd56d63b66b84cb7f32acce9e Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 2 Oct 1985 22:49:16 +0000 Subject: [PATCH 0077/1625] A more precise safety after a term. --- util/LLgen/src/compute.c | 35 +++++++++++++++++++++++------------ util/LLgen/src/gencode.c | 3 +-- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/util/LLgen/src/compute.c b/util/LLgen/src/compute.c index 04a1e36b..9c2c66de 100644 --- a/util/LLgen/src/compute.c +++ b/util/LLgen/src/compute.c @@ -713,7 +713,7 @@ do_safes(p,safe) register p_gram p; { p++; continue; case TERMINAL: - retval = 2; + safe = NOSCANDONE; break; case TERM : { register p_term q; @@ -727,7 +727,7 @@ do_safes(p,safe) register p_gram p; { if (retval == 2 && (!(q->t_flags & TNOSCAN))) { q->t_flags |= TNOSCAN; } - if (rep != FIXED || retval == 0) retval = 1; + safe = t_after(rep, i, q->t_flags & TNOSCAN); break; } case ALTERNATION : { register p_link l; @@ -748,27 +748,30 @@ do_safes(p,safe) register p_gram p; { return retval; } case NONTERM : { register p_nont n; - int nsafe; + int nsafe, osafe;; n = &nonterms[g_getnont(p)]; nsafe = getntsafe(n->n_flags); - if (!(n->n_flags & NNOSCAN)) retval = 1; - else retval = 2; - if (safe == nsafe) break; + osafe = safe; + if (!(n->n_flags & NNOSCAN)) { + safe = SCANDONE; + } + else safe = NOSCANDONE; + if (osafe == nsafe) break; if (nsafe == NOSAFETY) { change = 1; - setntsafe(&(n->n_flags), safe); + setntsafe(&(n->n_flags), osafe); break; } - if (safe == NOSCANDONE || nsafe == NOSCANDONE) { + if (osafe == NOSCANDONE || nsafe == NOSCANDONE) { if (nsafe != SCANDONE) { change = 1; setntsafe(&(n->n_flags), SCANDONE); } break; } - if (safe > nsafe) { - setntsafe(&(n->n_flags), safe); + if (osafe > nsafe) { + setntsafe(&(n->n_flags), osafe); change = 1; } break; } @@ -776,8 +779,8 @@ do_safes(p,safe) register p_gram p; { return retval; } p++; - if (retval == 1) safe = SCANDONE; - else safe = NOSCANDONE; + if (safe == NOSCANDONE) retval = 2; + else retval = 1; } } @@ -810,3 +813,11 @@ t_safety(rep, count, persistent, safety) { } /* NOTREACHED */ } + +t_after(rep, count, noscan) { + if (count == 0 && (rep == STAR || rep == PLUS)) { + return SAFESCANDONE; + } + if (rep == FIXED && noscan) return NOSCANDONE; + return SCANDONE; +} diff --git a/util/LLgen/src/gencode.c b/util/LLgen/src/gencode.c index 260f776b..e3fe33dd 100644 --- a/util/LLgen/src/gencode.c +++ b/util/LLgen/src/gencode.c @@ -761,8 +761,7 @@ codeforterm(q,safety,toplevel) register p_term q; { fputs(c_close, f);/* Close Register ... */ } } - if (rep != FIXED || !noscan) return SCANDONE; - return NOSCANDONE; + return t_after(rep, i, noscan); } STATIC From 15b635c02133b5adff9c5a8c14c641baf3e061e2 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 3 Oct 1985 10:25:23 +0000 Subject: [PATCH 0078/1625] Initial revision --- util/LLgen/src/types.h | 241 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 241 insertions(+) create mode 100644 util/LLgen/src/types.h diff --git a/util/LLgen/src/types.h b/util/LLgen/src/types.h new file mode 100644 index 00000000..0188ce62 --- /dev/null +++ b/util/LLgen/src/types.h @@ -0,0 +1,241 @@ +/* + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. + * + * This product is part of the Amsterdam Compiler Kit. + * + * Permission to use, sell, duplicate or disclose this software must be + * obtained in writing. Requests for such permissions may be sent to + * + * Dr. Andrew S. Tanenbaum + * Wiskundig Seminarium + * Vrije Universiteit + * Postbox 7161 + * 1007 MC Amsterdam + * The Netherlands + * + */ + +/* + * L L G E N + * + * An Extended LL(1) Parser Generator + * + * Author : Ceriel J.H. Jacobs + */ + +/* + * types.h $Header$ + * Type and structure definitions + */ + +typedef int *p_set; /* pointer to bitset */ +typedef char *p_mem; /* pointer to some core */ +typedef char *string; + +/* + * structure for a token + */ +typedef struct token { + int t_tokno; /* Lexical token number */ + union { + string t_s; /* Attribute is either a string or */ + int t_v; /* an integer */ + } t_x; +# define t_string t_x.t_s +# define t_num t_x.t_v +} t_token; + +/* + * structure for the grammar elements + */ +typedef struct gram { + short x; /* for lay-out see comment below */ + short g_lineno; /* element found on this line number */ +} t_gram,*p_gram; + +/* + * Layout of the field x: + * + * 15 13 12 9 8 0 + * ------------------------------------------ + * | type | nparams | index | + * ------------------------------------------ + * of + * 15 13 12 0 + * ------------------------------------------ + * | type | index | + * ------------------------------------------ + * dependant on type + */ +# define UNDEFINED 000777 +# define EORULE 00 /* End of (sub)rule */ +# define ACTION 01 /* Imbedded action */ +# define NONTERM 02 /* A nonterminal */ +# define TERMINAL 03 /* A terminal */ +# define TERM 04 /* Something between square brackets */ +# define ALTERNATION 05 /* Alternation (|) */ + +/* + * Access macros for the x-field of a grammar element + */ +# define g_init(p) {(p)->x = 0;} +# define g_gettype(p) (((p)->x>>13)&07) +# define g_getcont(p) ((p)->x&017777) +# define g_getnont(p) ((p)->x&0777) +# define g_getnpar(p) (((p)->x>>9)&07) +# define g_settype(p,s) { assert(((unsigned)(s))<=07);(p)->x=((p)->x&017777)|((s)<<13);} +# define g_setcont(p,s) { assert(((unsigned)(s))<=017777);(p)->x=((p)->x&0160000)|(s);} +# define g_setnont(p,s) { assert(((unsigned)(s))<=0777);(p)->x=((p)->x&0177000)|(s);} +# define g_setnpar(p,s) { assert(((unsigned)(s))<=07);(p)->x=((p)->x&0170777)|((s)<<9);} + +/* + * Some constants to communicate with the symbol table search routine + */ +# define LITERAL 01 /* Not equal to NONTERM or TERMINAL */ +# define UNKNOWN 00 /* Not equal to NONTERM, TERMINAL or LITERAL */ + +/* + * Some constants for safety + */ +# define SAFE 0 +# define SAFESCANDONE 1 +# define SCANDONE 2 +# define NOSCANDONE 3 +# define NOSAFETY 4 + +/* + * nonterminal structure + */ +typedef struct { + short n_flags; /* low order three bits are reserved + * for "safety" information, + * the next three bits are reserved for + * the parameter count + */ +# define getntsafe(f) ((f)&07) +# define setntsafe(p,i) {assert(((unsigned)(i))<=7);*(p)&=~07;*(p)|=(i);} + +# define RECURSIVE 00100 /* Set if the default rule is recursive */ +# define NNOSCAN 00200 /* Set if the nonterminal does not scan ahead */ +# define CONTIN 00400 /* continuation already computed? */ +# define BUSY 01000 /* or are we busy computing it? */ +# define PARAMS 02000 /* tells if a nonterminal has parameters */ +# define PRODUCE 04000 /* tells if a nonterminal produces anything */ +# define EMPTY 010000 /* tells if a nonterminal produces empty */ +# define LOCALS 020000 /* local declarations ? */ +# define REACHABLE 040000 /* can this nonterminal be reached ? */ +# define VERBOSE 0100000 /* Set if in LL.output file */ + short n_count; /* pieces of code before this rule */ + int n_lineno; /* declared on line ... */ + p_gram n_rule; /* pointer to right hand side of rule */ + union { + p_set n_f; /* ptr to "first" set */ + string n_s; /* If this nonterminal is not declared, + * This field indicates the filename in + * which it occurred + */ + } n_x; +# define n_first n_x.n_f +# define n_string n_x.n_s + p_set n_follow; /* pointer to the "follow" set */ + p_set n_contains; /* pointer to symbols that can be produced */ +} t_nont, *p_nont; + +/* + * hash table structure + */ +typedef struct h_entry { + string h_name; /* pointer to name */ + int h_num; /* numbering of terminals */ + struct h_entry *h_next; /* next in hash chain */ +} t_entry, *p_entry; + +/* + * link structure to link alternations + */ +typedef struct link { + unsigned int l_flag; +# define COND 01 /* Set if this alternative has a %if */ +# define DEF 02 /* This alternative is default */ +# define PREFERING 010 /* %prefer */ +# define AVOIDING 020 /* %avoid */ +# define NOCONF 01000 /* Set if there is a resolver without + * conflict + */ + p_gram l_rule; /* pointer to this rule */ + p_set l_symbs; /* set, when to take this rule */ + p_set l_others; /* set, when to take another rule */ +} t_link, *p_link; + +/* + * Structure for a repitition specification + */ +typedef short t_reps,*p_reps; + +# define FIXED 00 /* a fixed number */ +# define STAR 01 /* 0 or more times */ +# define PLUS 02 /* 1 or more times */ +# define OPT 03 /* 0 or 1 times */ + +/* + * Access macros for repitition + */ +# define r_init(p) {*(p)=0;} +# define r_getkind(p) (*(p)&03) +# define r_getnum(p) ((*(p)>>2)&037777) +# define r_setkind(p,s) { assert(((unsigned)(s))<=03);*(p)=(*(p)&0177774)|(s);} +# define r_setnum(p,s) { assert(((unsigned)(s))<=037777);*(p)=(*(p)&03)|((s)<<2);} + +/* + * header structure for a term + */ +typedef struct term { + t_reps t_reps; /* repeats ? */ + short t_flags; +# define PERSISTENT 010 /* Set if this term has %persistent */ +# define RESOLVER 020 /* Set if this term has %while */ +# define EMPTYFIRST 0100 /* Error, empty first */ +# define EMPTYTERM 0200 /* Error, term can produce empty */ +# define TNOSCAN 0400 /* Set if this term does not scan ahead */ +/* # define NOCONF 01000 see link structure */ + + p_gram t_rule; /* pointer to this term */ + p_set t_follow; /* set of followers */ + p_set t_first; /* set of firsts */ + p_set t_contains; +} t_term, *p_term; + +/* + * structure for firstmacros list + */ +typedef struct ff_firsts { + string ff_name; /* Name of the macro */ + p_nont ff_nont; /* for this nonterminal */ + struct ff_firsts *ff_next; +} t_first, *p_first; + +/* + * structure for start symbol list + */ +typedef t_first t_start; +typedef p_first p_start; + +/* + * structure for file names and info + */ +typedef struct f_file { + string f_name; /* File name */ + p_first f_firsts; /* ptr to list of firstmacros that must be + * generated in the target file for this + * grammar file + */ + short *f_start,*f_end;/* pointers in the "order" array, + * Indicating which nonterminals were defined + * in this file + */ +} t_file, *p_file; +# ifdef NDEBUG +# define STATIC static +# else not NDEBUG +# define STATIC extern +# endif not NDEBUG From e04eb7db0d950782b6896628c95ad2fc614beb26 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 3 Oct 1985 10:25:40 +0000 Subject: [PATCH 0079/1625] *** empty log message *** From b601e61e521cd84105cde67d3b652080b7b71354 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 3 Oct 1985 10:35:55 +0000 Subject: [PATCH 0080/1625] Initial revision --- util/LLgen/src/LLgen.g | 548 +++++++++++++++++++++++++++++++++++++++++ util/LLgen/src/check.c | 476 +++++++++++++++++++++++++++++++++++ 2 files changed, 1024 insertions(+) create mode 100644 util/LLgen/src/LLgen.g create mode 100644 util/LLgen/src/check.c diff --git a/util/LLgen/src/LLgen.g b/util/LLgen/src/LLgen.g new file mode 100644 index 00000000..5519a4ec --- /dev/null +++ b/util/LLgen/src/LLgen.g @@ -0,0 +1,548 @@ +/* + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. + * + * This product is part of the Amsterdam Compiler Kit. + * + * Permission to use, sell, duplicate or disclose this software must be + * obtained in writing. Requests for such permissions may be sent to + * + * Dr. Andrew S. Tanenbaum + * Wiskundig Seminarium + * Vrije Universiteit + * Postbox 7161 + * 1007 MC Amsterdam + * The Netherlands + * + */ + +/* + * L L G E N + * + * An Extended LL(1) Parser Generator + * + * Author : Ceriel J.H. Jacobs + */ + +/* + * LLgen.g + * Defines the grammar of LLgen. + * Some routines that are included build the internal structure + */ + +{ +# include "types.h" +# include "io.h" +# include "tunable.h" +# include "extern.h" +# include "assert.h" + +# ifndef NORCSID +static string rcsidb = "$Header$"; +# endif +p_mem alloc(); +string store(); +t_gram search(); + +static int nparams; /* parameter count for nonterminals */ +static t_gram elem; /* temporary space */ +static int acount; /* count #of global actions */ + +/* Here are defined : */ +STATIC copyact(); +STATIC unsigned get(); +STATIC t_gram mkalt(); +STATIC t_gram mkterm(); +STATIC p_gram copyrule(); +} + +%start LLparse, spec; + +spec : { acount = 0; } + [ %persistent def ]* + { /* + * Put an endmarker in temporary file + */ + putc('\0',fact); putc('\0',fact); + } + ; + +def { register string p; } + : rule + /* + * A grammar rule + */ + | C_TOKEN listel [ ',' listel ]* ';' + /* + * A token declaration + */ + | C_START C_IDENT + { p = store(lextoken.t_string); } + ',' C_IDENT ';' + /* + * A start symbol declaration + */ + { /* + * Put the declaration in the list + * of start symbols + */ + t_gram temp; + register p_start ff; + + temp = search(NONTERM,lextoken.t_string,BOTH); + ff = (p_start) alloc(sizeof(t_start)); + ff->ff_nont = &nonterms[g_getnont(&temp)]; + ff->ff_name = p; + ff->ff_next = start; + start = ff; + } + | C_LEXICAL C_IDENT + { if (!lexical) { + lexical = store(lextoken.t_string); + } else error(linecount,"Duplicate %%lexical"); + } + ';' + /* + * Declaration of a name for the lexical analyser. + * May appear only once + */ + | action(0) { acount++; } + /* + * A global C-declaration + */ + | firsts + /* + * declarations for macros + */ + ; + +listel : C_IDENT { search(TERMINAL,lextoken.t_string,ENTERING); } + ; + +rule { register p_nont p;} + : /* + * grammar for a production rule + */ + C_IDENT { t_gram temp; + + temp = search(NONTERM,lextoken.t_string,BOTH); + p = &nonterms[g_getnont(&temp)]; + if (p->n_rule) { + error(linecount, + "nonterminal already defined"); + } + /* + * Remember the order in which the nonterminals + * were defined. Code must be generated in that + * order to keep track with the actions on the + * temporary file + */ + *maxorder++ = p - nonterms; + p->n_count = acount; + acount = 0; + p->n_lineno = linecount; + } + [ params(2) { p->n_flags |= PARAMS; + if (nparams > 7) { + error(linecount,"Too many parameters"); + } else p->n_flags |= (nparams << 3); + } + ]? + [ action(0) { p->n_flags |= LOCALS; } + ]? + ':' productions(&(p->n_rule)) ';' + ; + +action(int n;) + /* + * The parameter n is non-zero when the opening and closing + * bracket must be copied along with the action + */ + : '{' { copyact('{','}',n,0); } + '}' + ; + +productions(p_gram *p;) + /* + * One or more alternatives + */ + { p_gram prod; + int conflres = 0; + int t = 0; + int haddefault = 0; + t_gram alts[100]; + register p_gram p_alts = alts; + int o_lc, n_lc; + } : + { n_lc = o_lc = linecount; } + simpleproduction(p,&conflres) + [ '|' { n_lc = linecount; } + [ C_DEFAULT { if (haddefault) { + error(linecount, + "multiple %%default"); + } + haddefault = 1; + t |= DEF; + } + ]? + simpleproduction(&prod,&t) + { if (p_alts - alts >= 97) { + error(n_lc,"Too many alternatives"); + p_alts = alts; + } + *p_alts++ = mkalt(*p,conflres,o_lc); + o_lc = n_lc; + conflres = t; + t = 0; + *p = prod; + } + ]* { if (conflres & ~DEF) { + error(n_lc, + "Resolver on last alternative"); + } + if (p_alts > alts) { + *p_alts++ = mkalt(*p,conflres,n_lc); + g_settype(p_alts,EORULE); + *p = copyrule(alts,p_alts+1-alts); + if (!haddefault) { + ((p_link) pentry[g_getcont(*p)]) + ->l_flag |= DEF; + } + } + } + ; +{ + +STATIC t_gram +mkalt(prod,condition,lc) p_gram prod; { + /* + * Create an alternation, initialise it and return + * a grammar element containing it + */ + register unsigned hulp; + register p_link l; + t_gram r; + + g_init(&r); + hulp = get(sizeof(*l)); + l = (p_link) pentry[hulp]; + l->l_rule = prod; + l->l_flag = condition; + g_setcont(&r,hulp); + g_settype(&r,ALTERNATION); + r.g_lineno = lc; + return r; +} +} + +simpleproduction(p_gram *p; register int *conflres;) + { t_gram rule[100]; + register p_gram p_rule = rule; + t_reps reps; + } : + { r_init(&reps); } + [ + /* + * Optional conflict reslover + */ + C_IF expr { *conflres |= COND; } + | C_PREFER { *conflres |= PREFERING; } + | C_AVOID { *conflres |= AVOIDING; } + ]? + [ %persistent elem + { if (p_rule - rule >= 98) { + error(linecount,"Production too long"); + p_rule = rule; + } + r_setkind(&reps,FIXED); + r_setnum(&reps,0); + } + [ repeats(&reps) + { if (g_gettype(&elem) != TERM) { + *p_rule = elem; + g_settype(p_rule+1,EORULE); + elem = mkterm(copyrule(p_rule,2), + 0, + &reps, + p_rule->g_lineno); + } + } + ]? { if (g_gettype(&elem) == TERM) { + register p_term q; + + q = (p_term) pentry[g_getcont(&elem)]; + q->t_reps = reps; + if (q->t_flags & RESOLVER && + (r_getkind(&reps) == PLUS || + r_getkind(&reps) == FIXED)) { + error(linecount, + "illegal %%while"); + } + if (q->t_flags & PERSISTENT && + r_getkind(&reps) == FIXED) { + error(linecount, + "illegal %%persistent"); + } + } + *p_rule++ = elem; + } + ]* { register p_term q; + + g_settype(p_rule,EORULE); + if (g_gettype(&rule[0]) == TERM && + p_rule-rule == 1) { + q=(p_term)pentry[g_getcont(&rule[0])]; + if (r_getkind(&(q->t_reps))==FIXED && + r_getnum(&(q->t_reps)) == 0) { + *p = q->t_rule; + } + else *p = copyrule(rule,2); + } + else *p = copyrule(rule,p_rule-rule+1); + } + ; +{ + +STATIC t_gram +mkterm(prod,flags,reps,lc) p_gram prod; register p_reps reps; { + /* + * Create a term, initialise it and return + * a grammar element contianing it + */ + register p_term q; + register unsigned hulp; + t_gram r; + + g_init(&r); + hulp = get(sizeof(*q)); + q = (p_term) pentry[hulp]; + q->t_rule = prod; + q->t_contains = 0; + /* "*1" = "?" */ + if (r_getnum(reps) == 1 && r_getkind(reps) == STAR) { + r_setkind(reps,OPT); + } + q->t_reps = *reps; + q->t_flags = flags; + g_settype(&r,TERM); + g_setcont(&r,hulp); + r.g_lineno = lc; + return r; +} +} + +elem { register short t = 0; + p_gram p1; + t_reps reps; + int ln; + } : + '[' { ln = linecount; } + [ C_WHILE expr { t |= RESOLVER; } + ]? + [ C_PERSISTENT { t |= PERSISTENT; } + ]? + productions(&p1) + ']' { r_init(&reps); + elem = mkterm(p1,t,&reps,ln); + } + | %default + C_IDENT { elem = search(UNKNOWN,lextoken.t_string,BOTH); } + [ params(0) { if (nparams > 6) { + error(linecount,"Too many parameters"); + } else g_setnpar(&elem,nparams+1); + if (g_gettype(&elem) == TERMINAL) { + error(linecount, + "Terminal with parameters"); + } + } + ]? + | C_LITERAL { elem = search(LITERAL,lextoken.t_string,BOTH); } + | { g_settype(&elem,ACTION); + elem.g_lineno = linecount; + } + action(1) + ; + +params(int n;) + : '(' { copyact('(',')',n,0); } + ')' + ; + +expr : '(' { copyact('(',')',1,0); } + ')' + ; + +repeats(t_reps *t;) { int t1 = 0; } : + [ + '?' { r_setkind(t,OPT); } + | [ '*' { r_setkind(t,STAR); } + | '+' { r_setkind(t,PLUS); } + ] + number(&t1)? + { if (t1 == 1 && r_getkind(t) == PLUS) { + error(linecount, + "Illegal repetition specifier"); + } + } + | number(&t1) + ] { r_setnum(t,t1); } + ; + +number(int *t;) + : C_NUMBER + { *t = lextoken.t_num; + if (*t <= 0 || *t >= 8192) { + error(linecount,"Illegal number"); + } + } + ; + +firsts { register string p; } + : C_FIRST C_IDENT + { p = store(lextoken.t_string); } + ',' C_IDENT ';' + { /* + * Store this %first in the list belonging + * to this input file + */ + t_gram temp; + register p_first ff; + + temp = search(NONTERM,lextoken.t_string,BOTH); + ff = (p_first) alloc(sizeof(t_first)); + ff->ff_nont = &nonterms[g_getnont(&temp)]; + ff->ff_name = p; + ff->ff_next = pfile->f_firsts; + pfile->f_firsts = ff; + } + ; +{ + +STATIC +copyact(ch1,ch2,flag,level) char ch1,ch2; { + /* + * Copy an action to file f. Opening bracket is ch1, closing bracket + * is ch2. + * If flag = 1, copy opening and closing parameters too. + * If flag = 2, the copy is a parameter declaration copy. + * Give an error message if not ending on a ';' + */ + register FILE *f; + register ch; /* Current char */ + register match; /* used to read strings */ + int saved; /* save linecount */ + int semicolon = 0; + + f = fact; + if (!level) { + saved = linecount; + nparams = 0; /* count comma's */ + putc('\0',f); + fprintf(f,"# line %d \"%s\"\n", linecount,f_input); + if (flag == 1) putc(ch1,f); + } + else putc(ch1,f); + for (;;) { + ch = input(); + if (ch == ch2) { + if (!level) unput(ch); + if (level || flag == 1) putc(ch,f); + if ((!level) && flag == 2 && !semicolon) { + error(linecount,"missing ';'"); + } + return; + } + if (! isspace(ch)) semicolon = 0; + switch(ch) { + case ')': + case '}': + case ']': + error(linecount,"Parentheses mismatch"); + break; + case '(': + copyact('(',')',flag,level+1); + continue; + case '{': + copyact('{','}',flag,level+1); + continue; + case '[': + copyact('[',']',flag,level+1); + continue; + case '/': + ch = input(); + unput(ch); + if (ch == '*') { + skipcomment(1); + continue; + } + break; + case ';': + semicolon = 1; + /* Fall through */ + case ',': + if (!level) { /* + * Only ','s and ';'s on the + * outer level are counted + */ + nparams++; + } + break; + case '\'': + case '"' : + /* + * watch out for brackets in strings, they do not + * count ! + */ + match = ch; + putc(ch,f); + while((ch = input())) { + if (ch == match) break; + if (ch == '\\') { + putc(ch,f); + ch = input(); + } + if (ch == '\n') { + error(linecount,"newline in string"); + unput(match); + } + putc(ch,f); + } + if (ch == match) break; + /* Fall through */ + case EOF : + if (!level) error(saved,"Action does not terminate"); + return; + } + putc(ch,f); + } +} + +static int ecount; /* Index in "pentry" array */ +STATIC unsigned +get(size) unsigned size; { + /* + * Get some core, save a pointer to it in "pentry", + * return index in pentry + */ + + if (ecount >= ENTSIZ) fatal(linecount,"Entry table overflow"); + pentry[ecount] = alloc(size); + return ecount++; +} + +STATIC p_gram +copyrule(p,length) register p_gram p; register length; { + /* + * Returns a pointer to a grammar rule that was created in + * p. The space pointed to by p can now be reused + */ + register p_gram t; + p_gram rule; + + t = (p_gram) alloc((unsigned) length * sizeof(t_gram)); + rule = t; + while (length--) { + *t++ = *p++; + } + return rule; +} +} diff --git a/util/LLgen/src/check.c b/util/LLgen/src/check.c new file mode 100644 index 00000000..9d3a5b95 --- /dev/null +++ b/util/LLgen/src/check.c @@ -0,0 +1,476 @@ +/* + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. + * + * This product is part of the Amsterdam Compiler Kit. + * + * Permission to use, sell, duplicate or disclose this software must be + * obtained in writing. Requests for such permissions may be sent to + * + * Dr. Andrew S. Tanenbaum + * Wiskundig Seminarium + * Vrije Universiteit + * Postbox 7161 + * 1007 MC Amsterdam + * The Netherlands + * + */ + +/* + * L L G E N + * + * An Extended LL(1) Parser Generator + * + * Author : Ceriel J.H. Jacobs + */ + +/* + * check.c + * Several routines to perform checks and printouts + */ + +# include "types.h" +# include "extern.h" +# include "tunable.h" +# include "io.h" +# include "sets.h" +# include "assert.h" + +# ifndef NORCSID +static string rcsid1 = "$Header$"; +# endif + +# define PTERM(p) fprintf(fout,(p)->h_num < 0400 ? "'%s' " : "%s ",(p)->h_name); + +static string c_first = "> firstset "; +static string c_contains = "> containset "; +static string c_follow = "> followset "; +p_set setalloc(); +static string ntname; /* nonterminal that is currently checked */ +static p_nont nt; /* pointer to its struct */ +static int level; + +/* In this file are defined : */ +extern conflchecks(); +STATIC newline(); +STATIC printset(); +STATIC check(); +STATIC moreverbose(); +STATIC prrule(); +STATIC cfcheck(); +STATIC resolve(); +STATIC propagate(); +STATIC spaces(); + +conflchecks() { + /* + * Check for conflicts, that is, + * in a repeating term, the FIRST and FOLLOW must be disjunct, + * unless there is a disambiguating condition. + * in an alternation, the sets that determine the direction to take, + * must be disjunct. + */ + register p_nont p; + register FILE *f; + register short *s; + p_file x = files; + + f_input = x->f_name; + if (verbose >= 3) { + for (p = nonterms; p < maxnt; p++) p->n_flags |= VERBOSE; + } + if (verbose) { + if ((f = fopen(f_out,"w")) == NULL) fatal(1,e_noopen,f_out); + fout = f; + } + /* + * Check the rules in the order in which they are declared, + * and input file by input file, to give proper error messages + */ + for (; x->f_end < maxorder; x++) { + f_input = x->f_name; +# ifndef NDEBUG + if (debug) fprintf(stderr, "CHECK: file %s\n", f_input); +# endif + for (s = x->f_start; s <= x->f_end; s++) { + nt = p = &nonterms[*s]; + ntname = (min_nt_ent + *s)->h_name; +# ifndef NDEBUG + if (debug) fprintf(stderr,"CHECK: nonterminal %s\n", ntname); +# endif + if (p->n_flags & RECURSIVE) { + error(p->n_lineno, + "Recursion in default for nonterminal %s", + ntname); + } + check(p->n_rule); + /* + * If a printout is needed for this rule in + * LL.output, just do it + */ + if (verbose && (p->n_flags & VERBOSE)) { + fprintf(f,"\n%s :\n",ntname); + printset(p->n_first,c_first); + printset(p->n_contains,c_contains); + printset(p->n_follow,c_follow); + fputs("> rule\n\t",f); + level = 8; + prrule(p->n_rule); + level = 0; + newline(); + } + /* + * Now, the conflicts may be resolved + */ + resolve(p->n_rule); + } + } + if (verbose) fclose(f); +} + +STATIC +newline() { + /* + * Newline and "level" spaces indentation + */ + if (level > 0) fprintf(fout,"\n%*c",level,' '); + else putc('\n',fout); +} + +STATIC +printset(p,s) register p_set p; string s; { + /* + * Print the elements of a set + */ + register FILE *f; + register i; + register j; + int k; + int hulp; + + k = strlen(s)+1; + /* + * k contains relative level of indentation + */ + f = fout; + fprintf(f,"%s{ ",s); + j = level+1+k; + /* + * j will gather the total length of the line + */ + if (p == (p_set) 0) fputs(">non existent (yet?)< ",f); + else { + for (i = 0; i < nterminals; i++) { + if (IN(p,i)) { + hulp = strlen(h_entry[i].h_name)+1; + if (h_entry[i].h_num < 0400) hulp += 2; + if ((j += hulp) >= 78) { + /* + * Line becoming too long + */ + j = level+k+1+hulp; + newline(); + fprintf(f,">%*c",k,' '); + } + PTERM(&h_entry[i]); + } + } + if (ntprint) for (i = 0; i < nnonterms; i++) { + /* + * Nonterminals in the set must also be printed + */ + if (NTIN(p,i)) { + hulp = strlen((min_nt_ent+i)->h_name)+3; + if ((j += hulp) >= 78) { + j = level + k + 1 + hulp; + newline(); + fprintf(f,">%*c",k,' '); + } + fprintf(f,"<%s> ",(min_nt_ent+i)->h_name); + } + } + } + putc('}',f); + newline(); +} + +STATIC +check(p) register p_gram p; { + /* + * Search for conflicts in a grammar rule. + */ + p_set temp; + + for (;;) { + switch (g_gettype(p)) { + case EORULE : + return; + case NONTERM : + if (g_getnpar(p)!=((nonterms[g_getnont(p)].n_flags&077) >> 3)){ + error(p->g_lineno, + "Call of %s : parameter count mismatch", + (min_nt_ent+g_getnont(p))->h_name); + } + break; + case TERM : { + register p_term q; + + q = (p_term) pentry[g_getcont(p)]; + check(q->t_rule); + if (r_getkind(&(q->t_reps)) == FIXED) break; + if (setempty(q->t_first)) { + q->t_flags |= EMPTYFIRST; + nt->n_flags |= VERBOSE; + error(p->g_lineno, "No symbols in term"); + } + if (empty(q->t_rule)) { + q->t_flags |= EMPTYTERM; + nt->n_flags |= VERBOSE; + error(p->g_lineno, "Term produces empty"); + } + temp = setalloc(setsize); + setunion(temp,q->t_first,setsize); + if (!setintersect(temp,q->t_follow,setsize)) { + /* + * q->t_first * q->t_follow != EMPTY + */ + if (!(q->t_flags & RESOLVER)) { + /* + * No conflict resolver + */ + error(p->g_lineno, + "Repitition conflict"); + nt->n_flags |= VERBOSE; + if (verbose == 2) moreverbose(temp); + } + } else { + if (q->t_flags & RESOLVER) { + q->t_flags |= NOCONF; + error(p->g_lineno, + "%%while, no conflict"); + nt->n_flags |= VERBOSE; + } + } + free((p_mem) temp); + break; } + case ALTERNATION : { + register p_link l; + + l = (p_link) pentry[g_getcont(p)]; + temp = setalloc(setsize); + setunion(temp,l->l_symbs,setsize); + if(!setintersect(temp,l->l_others,setsize)) { + /* + * temp now contains the conflicting + * symbols + */ + if (!(l->l_flag & (COND|PREFERING|AVOIDING))) { + error(p->g_lineno, + "Alternation conflict"); + nt->n_flags |= VERBOSE; + if (verbose == 2) moreverbose(temp); + } + } else { + if (l->l_flag & (COND|PREFERING|AVOIDING)) { + l->l_flag |= NOCONF; + error(p->g_lineno,"No conflict"); + nt->n_flags |= VERBOSE; + } + } + free( (p_mem) temp); + check(l->l_rule); + break; } + } + p++; + } +} + +STATIC +moreverbose(t) register p_set t; { + /* + * t points to a set containing conflicting symbols and pssibly + * also containing nonterminals. + * Take care that a printout will be prepared for these nonterminals + */ + register i; + + if (verbose) for (i = 0; i < nnonterms; i++) { + if (NTIN(t,i)) nonterms[i].n_flags |= VERBOSE; + } +} + +STATIC +prrule(p) register p_gram p; { + /* + * Create a verbose printout of grammar rule p + */ + register FILE *f; + int present = 0; + + f = fout; + for (;;) { + switch (g_gettype(p)) { + case EORULE : + putc('\n',f); + return; + case TERM : { + register p_term q; + register c; + + q = (p_term) pentry[g_getcont(p)]; + if (present) newline(); + if (r_getkind(&(q->t_reps)) != FIXED || + r_getnum(&(q->t_reps)) != 0) { + fputs("[ ",f); + level += 4; + if (q->t_flags & RESOLVER) { + fputs("%%while (..)",f); + newline(); + } + if (r_getkind(&(q->t_reps)) != FIXED) { + printset(q->t_first, c_first); + printset(q->t_contains, c_contains); + printset(q->t_follow,c_follow); + if (q->t_flags & EMPTYFIRST) { + fputs(">>> empty first",f); + newline(); + } + if (q->t_flags & EMPTYTERM) { + fputs(">>> term produces empty",f); + newline(); + } + cfcheck(q->t_first,q->t_follow, + q->t_flags & RESOLVER); + } + prrule(q->t_rule); + level -= 4; + spaces(); + c = r_getkind(&(q->t_reps)); + putc(']',f); + if (c != FIXED) { + c = (c==STAR)?'*':(c==PLUS)?'+':'?'; + putc(c,f); + } + if (c = r_getnum(&(q->t_reps))) { + fprintf(f,"%d",c); + } + newline(); + } else { + prrule(q->t_rule); + spaces(); + } + break; } + case ACTION : + fputs("{..} ",f); + break; + case ALTERNATION : { + register p_link l; + + l = (p_link) pentry[g_getcont(p)]; + if (l->l_flag & (COND|PREFERING|AVOIDING)) { + printset(l->l_symbs,"> alt with resolver on "); + } else printset(l->l_symbs,"> alternative on "); + cfcheck(l->l_symbs, + l->l_others, + (int)(l->l_flag&(COND|PREFERING|AVOIDING))); + fputs(" ",f); + level += 4; + prrule(l->l_rule); + level -= 4; + spaces(); + if (g_gettype(p+1) == EORULE) { + fputs("> end alternatives\n",f); + return; + } + p++; continue; } + case TERMINAL : + PTERM(&h_entry[g_getcont(p)]); + break; + case NONTERM : + fprintf(f,"%s ",(g_getnont(p)+min_nt_ent)->h_name); + break; + } + p++; + present = 1; + } +} + +STATIC +cfcheck(s1,s2,flag) p_set s1,s2; { + /* + * Check if s1 and s2 have elements in common. + * If so, flag must be non-zero, indicating that there is a + * conflict resolver, otherwise, flag must be zero, indicating + * that there is not. + */ + register p_set temp; + + temp = setalloc(setsize); + setunion(temp,s1,setsize); + if (!setintersect(temp,s2,setsize)) { + if (! flag) { + printset(temp,">>> conflict on "); + newline(); + } + } else { + if (flag) { + fputs(">>> %if/%while, no conflict",fout); + newline(); + } + } + free((p_mem) temp); +} + +STATIC +resolve(p) register p_gram p; { + /* + * resolve conflicts, as specified by the user + */ + for (;;) { + switch (g_gettype(p)) { + case EORULE : + return; + case TERM : + resolve(((p_term) pentry[g_getcont(p)])->t_rule); + break; + case ALTERNATION : { + register p_link l; + + l = (p_link) pentry[g_getcont(p)]; + if (l->l_flag & AVOIDING) { + /* + * On conflicting symbols, this rule + * is never chosen + */ + setminus(l->l_symbs,l->l_others,setsize); + } + if (setempty(l->l_symbs)) { + /* + * This may be caused by the statement above + */ + error(p->g_lineno,"Alternative never chosen"); + } + resolve(l->l_rule); + if (l->l_flag & PREFERING) propagate(l->l_symbs,p+1); + break; } + } + p++; + } +} + +STATIC +propagate(set,p) p_set set; register p_gram p; { + /* + * Propagate the fact that on the elements of set the grammar rule + * p will not be chosen. + */ + while (g_gettype(p) != EORULE) { + setminus(((p_link) pentry[g_getcont(p)])->l_symbs,set,setsize); + p++; + } +} + +STATIC +spaces() { + + if (level > 0) fprintf(fout,"%*c",level,' '); +} From 5be4b432dcef0d19bbe1e3ae42a7e19e0db22938 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 3 Oct 1985 10:36:07 +0000 Subject: [PATCH 0081/1625] *** empty log message *** From c1d4bb25971158d81cf11dcbf97f9f00d6d10e87 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 3 Oct 1985 12:38:55 +0000 Subject: [PATCH 0082/1625] More safety, also after terms and nonterminals. --- util/LLgen/src/check.c | 9 ++++-- util/LLgen/src/compute.c | 61 +++++++++++++++++++++------------------- util/LLgen/src/gencode.c | 20 ++++++------- util/LLgen/src/types.h | 19 +++++++------ 4 files changed, 58 insertions(+), 51 deletions(-) diff --git a/util/LLgen/src/check.c b/util/LLgen/src/check.c index 9d3a5b95..ed4b3f89 100644 --- a/util/LLgen/src/check.c +++ b/util/LLgen/src/check.c @@ -204,13 +204,16 @@ check(p) register p_gram p; { switch (g_gettype(p)) { case EORULE : return; - case NONTERM : - if (g_getnpar(p)!=((nonterms[g_getnont(p)].n_flags&077) >> 3)){ + case NONTERM : { + register p_nont n; + + n = &nonterms[g_getnont(p)]; + if (g_getnpar(p) != getntparams(n)) { error(p->g_lineno, "Call of %s : parameter count mismatch", (min_nt_ent+g_getnont(p))->h_name); } - break; + break; } case TERM : { register p_term q; diff --git a/util/LLgen/src/compute.c b/util/LLgen/src/compute.c index 9c2c66de..30ca8777 100644 --- a/util/LLgen/src/compute.c +++ b/util/LLgen/src/compute.c @@ -670,28 +670,28 @@ co_safes() { /* * Don't know anything yet */ - setntsafe(&(p->n_flags), NOSAFETY); + setntsafe(p, NOSAFETY); + setntout(p, NOSAFETY); } for (st = start; st; st = st->ff_next) { /* * But start symbols are called with lookahead done */ p = st->ff_nont; - setntsafe(&(p->n_flags),SCANDONE); + setntsafe(p,SCANDONE); } change = 1; while (change) { change = 0; for (p = nonterms; p < maxnt; p++) { - i = getntsafe(p->n_flags); + i = getntsafe(p); if (i == NOSAFETY) { - change = 1; continue; } - if (do_safes(p->n_rule, i) == 2 && - !(p->n_flags & NNOSCAN)) { - p->n_flags |= NNOSCAN; + i = do_safes(p->n_rule, i); + if (getntout(p) != i) { change = 1; + setntout(p, i); } } } @@ -705,8 +705,6 @@ do_safes(p,safe) register p_gram p; { */ register retval; - if (safe == NOSCANDONE) retval = 2; - else retval = 1; for (;;) { switch (g_gettype(p)) { case ACTION: @@ -724,10 +722,10 @@ do_safes(p,safe) register p_gram p; { rep = r_getkind(&(q->t_reps)); retval = do_safes(q->t_rule, t_safety(rep,i,q->t_flags&PERSISTENT,safe)); - if (retval == 2 && (!(q->t_flags & TNOSCAN))) { - q->t_flags |= TNOSCAN; + if (retval != gettout(q)) { + settout(q, retval); } - safe = t_after(rep, i, q->t_flags & TNOSCAN); + safe = t_after(rep, i, gettout(q)); break; } case ALTERNATION : { register p_link l; @@ -736,51 +734,53 @@ do_safes(p,safe) register p_gram p; { f = 1; while (g_gettype(p) == ALTERNATION) { l = (p_link) pentry[g_getcont(p)]; - if (safe && (l->l_flag & DEF)) { + if (safe > SAFE && (l->l_flag & DEF)) { i = do_safes(l->l_rule,SAFESCANDONE); } else i = do_safes(l->l_rule,SAFE); if (f) retval = i; - else retval &= i; + else if (i != retval) { + if (i == NOSCANDONE || + retval == NOSCANDONE) { + retval = SCANDONE; + } + else if (i > retval) retval = i; + } p++; f = 0; } return retval; } case NONTERM : { register p_nont n; - int nsafe, osafe;; + int nsafe, osafe; n = &nonterms[g_getnont(p)]; - nsafe = getntsafe(n->n_flags); + nsafe = getntsafe(n); osafe = safe; - if (!(n->n_flags & NNOSCAN)) { - safe = SCANDONE; - } - else safe = NOSCANDONE; + safe = getntout(n); + if (safe == NOSAFETY) safe = SCANDONE; if (osafe == nsafe) break; if (nsafe == NOSAFETY) { change = 1; - setntsafe(&(n->n_flags), osafe); + setntsafe(n, osafe); break; } if (osafe == NOSCANDONE || nsafe == NOSCANDONE) { if (nsafe != SCANDONE) { change = 1; - setntsafe(&(n->n_flags), SCANDONE); + setntsafe(n, SCANDONE); } break; } if (osafe > nsafe) { - setntsafe(&(n->n_flags), osafe); + setntsafe(n, osafe); change = 1; } break; } case EORULE : - return retval; + return safe; } p++; - if (safe == NOSCANDONE) retval = 2; - else retval = 1; } } @@ -814,10 +814,13 @@ t_safety(rep, count, persistent, safety) { /* NOTREACHED */ } -t_after(rep, count, noscan) { +t_after(rep, count, outsafety) { if (count == 0 && (rep == STAR || rep == PLUS)) { return SAFESCANDONE; } - if (rep == FIXED && noscan) return NOSCANDONE; - return SCANDONE; + if (rep != FIXED) { + if (outsafety <= SAFESCANDONE) return SAFESCANDONE; + return SCANDONE; + } + return outsafety; } diff --git a/util/LLgen/src/gencode.c b/util/LLgen/src/gencode.c index e3fe33dd..751357c0 100644 --- a/util/LLgen/src/gencode.c +++ b/util/LLgen/src/gencode.c @@ -173,7 +173,7 @@ genrecovery() { fprintf(f, "\tL%d_%s();\n", st->ff_nont-nonterms, (min_nt_ent+(st->ff_nont-nonterms))->h_name); - if (st->ff_nont->n_flags & NNOSCAN) { + if (getntout(st->ff_nont) == NOSCANDONE) { fputs("\tLLscan(EOFILE);\n",f); } else fputs("\tif (LLsymb != EOFILE) LLerror(EOFILE);\n",f); @@ -240,7 +240,7 @@ generate(f) p_file f; { else fputs(") {\n", fd); fputs("register struct LLxx *LLx = &LLxx;\n#ifdef lint\nLLx=LLx;\n#endif\n", fd); if (p->n_flags & LOCALS) getaction(1); - i = getntsafe(p->n_flags); + i = getntsafe(p); mustpop = 0; if (g_gettype(p->n_rule) == ALTERNATION) { mustpop = 1; @@ -252,7 +252,8 @@ generate(f) p_file f; { nlabel = 1; rulecode(p->n_rule, i, - !(p->n_flags & NNOSCAN), mustpop); + getntout(p) != NOSCANDONE, + mustpop); fputs(c_close, fd); } } @@ -443,7 +444,7 @@ rulecode(p,safety,mustscan,mustpop) register p_gram p; { n = &nonterms[g_getnont(p)]; t= min_nt_ent+(n-nonterms); if (safety == NOSCANDONE && - getntsafe(n->n_flags) < NOSCANDONE) fputs(c_read, f); + getntsafe(n) < NOSCANDONE) fputs(c_read, f); if (toplevel == 0 && g_gettype(n->n_rule) != ALTERNATION) { fputs(c_LLptrmin, f); @@ -453,8 +454,7 @@ rulecode(p,safety,mustscan,mustpop) register p_gram p; { fprintf(f,"L%d_%s(",n-nonterms, t->h_name); if (params) getaction(0); fputs(");\n",f); - safety = NOSCANDONE; - if (!(n->n_flags & NNOSCAN)) safety = SCANDONE; + safety = getntout(n); break; } case TERM : safety = codeforterm((p_term) pentry[g_getcont(p)], @@ -707,13 +707,11 @@ codeforterm(q,safety,toplevel) register p_term q; { register int i; register int rep; int persistent; - int noscan; f = fpars; i = r_getnum(&(q->t_reps)); rep = r_getkind(&(q->t_reps)); persistent = (q->t_flags & PERSISTENT); - noscan = (q->t_flags & TNOSCAN); if (safety == NOSCANDONE && (rep != FIXED || i == 0)) { fputs(c_read, f); if (rep == FIXED && g_gettype(q->t_rule) != ALTERNATION) { @@ -726,7 +724,7 @@ codeforterm(q,safety,toplevel) register p_term q; { fputs("for (;;) {\nif (!LL_i--) {\nLLptr++;\n", f); fputs("break;\n}\n", f); if (rep == FIXED) { - if (noscan && safety == NOSCANDONE) { + if (gettout(q) == NOSCANDONE && safety == NOSCANDONE) { fputs(c_read,f); } } @@ -739,7 +737,7 @@ codeforterm(q,safety,toplevel) register p_term q; { genifhead(q,rep); } rulecode(q->t_rule,t_safety(rep,i,persistent,safety), - rep != FIXED || !noscan, + rep != FIXED || gettout(q) != NOSCANDONE, rep == FIXED && i == 0 && g_gettype(q->t_rule) == ALTERNATION); /* in the case of '+', the if is after the code for the rule */ if (rep == PLUS) { @@ -761,7 +759,7 @@ codeforterm(q,safety,toplevel) register p_term q; { fputs(c_close, f);/* Close Register ... */ } } - return t_after(rep, i, noscan); + return t_after(rep, i, gettout(q)); } STATIC diff --git a/util/LLgen/src/types.h b/util/LLgen/src/types.h index 0188ce62..49181bfc 100644 --- a/util/LLgen/src/types.h +++ b/util/LLgen/src/types.h @@ -108,15 +108,11 @@ typedef struct gram { */ typedef struct { short n_flags; /* low order three bits are reserved - * for "safety" information, - * the next three bits are reserved for * the parameter count */ -# define getntsafe(f) ((f)&07) -# define setntsafe(p,i) {assert(((unsigned)(i))<=7);*(p)&=~07;*(p)|=(i);} - +# define getntparams(p) ((p)->n_flags&07) +# define setntparams(p,i) {assert(((unsigned)(i))<=7);(p)->n_flags&=~07;(p)->n_flags|=(i);} # define RECURSIVE 00100 /* Set if the default rule is recursive */ -# define NNOSCAN 00200 /* Set if the nonterminal does not scan ahead */ # define CONTIN 00400 /* continuation already computed? */ # define BUSY 01000 /* or are we busy computing it? */ # define PARAMS 02000 /* tells if a nonterminal has parameters */ @@ -125,8 +121,14 @@ typedef struct { # define LOCALS 020000 /* local declarations ? */ # define REACHABLE 040000 /* can this nonterminal be reached ? */ # define VERBOSE 0100000 /* Set if in LL.output file */ + char n_insafety; + char n_outsafety; +# define getntsafe(p) ((p)->n_insafety) +# define setntsafe(p,i) {assert(((unsigned)(i))<=NOSAFETY);(p)->n_insafety=(i);} +# define getntout(p) ((p)->n_outsafety) +# define setntout(p,i) {assert(((unsigned)(i))<=NOSAFETY);(p)->n_outsafety=(i);} short n_count; /* pieces of code before this rule */ - int n_lineno; /* declared on line ... */ + short n_lineno; /* declared on line ... */ p_gram n_rule; /* pointer to right hand side of rule */ union { p_set n_f; /* ptr to "first" set */ @@ -192,11 +194,12 @@ typedef short t_reps,*p_reps; typedef struct term { t_reps t_reps; /* repeats ? */ short t_flags; +# define gettout(q) ((q)->t_flags&07) +# define settout(q,i) {assert(((unsigned)(i))<=NOSAFETY);(q)->t_flags&=~07;(q)->t_flags|=i;} # define PERSISTENT 010 /* Set if this term has %persistent */ # define RESOLVER 020 /* Set if this term has %while */ # define EMPTYFIRST 0100 /* Error, empty first */ # define EMPTYTERM 0200 /* Error, term can produce empty */ -# define TNOSCAN 0400 /* Set if this term does not scan ahead */ /* # define NOCONF 01000 see link structure */ p_gram t_rule; /* pointer to this term */ From f00b73148fb58266128b8e91af84ab0ce4cec60f Mon Sep 17 00:00:00 2001 From: bal Date: Thu, 3 Oct 1985 14:41:44 +0000 Subject: [PATCH 0083/1625] 0 / -1 confusion for properties (bug reported by sater). --- util/ncgg/coerc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/ncgg/coerc.c b/util/ncgg/coerc.c index a9991d3f..d18c9bac 100644 --- a/util/ncgg/coerc.c +++ b/util/ncgg/coerc.c @@ -201,7 +201,7 @@ n_coerc(ti,be,al,ge,rp,in) struct varinfo *al,*ge,*rp; iocc_t in; { c3p = & l_coercs[ncoercs-1]; c3p->c3_texpno = ti; c3p->c3_expr = be; - c3p->c3_prop = nallreg==0 ? 0 : allreg[0]; + c3p->c3_prop = nallreg==0 ? -1 : allreg[0]; c3p->c3_repl = rp->vi_int[0]; c3p->c3_codep = codeindex; dopattern(ti==0,VI_NULL,al,ge,rp,VI_NULL); From ede607455be8f8ffdef40c3b26d5e5a80e67ad4b Mon Sep 17 00:00:00 2001 From: bal Date: Thu, 3 Oct 1985 14:45:53 +0000 Subject: [PATCH 0084/1625] 0 / -1 confusion for properties (2 bugs reported by sater). --- mach/proto/ncg/codegen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mach/proto/ncg/codegen.c b/mach/proto/ncg/codegen.c index fd11d801..475d17d9 100644 --- a/mach/proto/ncg/codegen.c +++ b/mach/proto/ncg/codegen.c @@ -318,7 +318,7 @@ if (Debug>1) fprintf(stderr,"findcoerc returns %d at position %d\n",cp,i); CHKCOST(); break; } else { - if (cp->c3_prop==0) { + if (cp->c3_prop<0) { totalcost+=docoerc(tp,cp,ply,toplevel,0); CHKCOST(); } else { @@ -361,7 +361,7 @@ if(Debug>1) fprintf(stderr,"Pattern too long, %d with only %d items on stack\n", goto normalfailed; #endif } - if (cp->c3_prop==0) { + if (cp->c3_prop<0) { totalcost+=docoerc(tp,cp,ply,toplevel,0); CHKCOST(); } else { From 6003a5f2e951dae2ee54070c4893e86dd4e8be90 Mon Sep 17 00:00:00 2001 From: bal Date: Thu, 3 Oct 1985 14:47:28 +0000 Subject: [PATCH 0085/1625] 0 / -1 confusion for properties (bug reported by sater). --- mach/proto/ncg/subr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/proto/ncg/subr.c b/mach/proto/ncg/subr.c index 4f3f25e6..825786a4 100644 --- a/mach/proto/ncg/subr.c +++ b/mach/proto/ncg/subr.c @@ -575,7 +575,7 @@ c3_p findcoerc(tp,tep) token_p tp; set_p tep; { if (cp->c3_texpno!=0) continue; } - if (cp->c3_prop==0) { /* no reg needed */ + if (cp->c3_prop<0) { /* no reg needed */ cinstance(cp->c3_repl,&rtoken,tp,0); if (match(&rtoken,tep,0)) return(cp); From da5f8e5a144b7659a799c9c6c351110d299ad54e Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 3 Oct 1985 17:19:14 +0000 Subject: [PATCH 0086/1625] different interface. --- util/LLgen/src/LLgen.g | 2 +- util/LLgen/src/check.c | 6 ---- util/LLgen/src/compute.c | 11 ++++++ util/LLgen/src/gencode.c | 77 ++++++++++++++++++++++++++-------------- 4 files changed, 62 insertions(+), 34 deletions(-) diff --git a/util/LLgen/src/LLgen.g b/util/LLgen/src/LLgen.g index 5519a4ec..d6968728 100644 --- a/util/LLgen/src/LLgen.g +++ b/util/LLgen/src/LLgen.g @@ -144,7 +144,7 @@ rule { register p_nont p;} [ params(2) { p->n_flags |= PARAMS; if (nparams > 7) { error(linecount,"Too many parameters"); - } else p->n_flags |= (nparams << 3); + } else setntparams(p,nparams); } ]? [ action(0) { p->n_flags |= LOCALS; } diff --git a/util/LLgen/src/check.c b/util/LLgen/src/check.c index ed4b3f89..62815095 100644 --- a/util/LLgen/src/check.c +++ b/util/LLgen/src/check.c @@ -88,15 +88,9 @@ conflchecks() { */ for (; x->f_end < maxorder; x++) { f_input = x->f_name; -# ifndef NDEBUG - if (debug) fprintf(stderr, "CHECK: file %s\n", f_input); -# endif for (s = x->f_start; s <= x->f_end; s++) { nt = p = &nonterms[*s]; ntname = (min_nt_ent + *s)->h_name; -# ifndef NDEBUG - if (debug) fprintf(stderr,"CHECK: nonterminal %s\n", ntname); -# endif if (p->n_flags & RECURSIVE) { error(p->n_lineno, "Recursion in default for nonterminal %s", diff --git a/util/LLgen/src/compute.c b/util/LLgen/src/compute.c index 30ca8777..bfdef713 100644 --- a/util/LLgen/src/compute.c +++ b/util/LLgen/src/compute.c @@ -695,6 +695,17 @@ co_safes() { } } } +# ifndef NDEBUG + if (debug) { + fputs("Safeties:\n", stderr); + for (p = nonterms; p < maxnt; p++) { + fprintf(stderr, "%s\t%d\t%d\n", + (min_nt_ent + (p - nonterms))->h_name, + getntsafe(p), + getntout(p)); + } + } +# endif } STATIC int diff --git a/util/LLgen/src/gencode.c b/util/LLgen/src/gencode.c index 751357c0..c24952a3 100644 --- a/util/LLgen/src/gencode.c +++ b/util/LLgen/src/gencode.c @@ -411,7 +411,7 @@ rulecode(p,safety,mustscan,mustpop) register p_gram p; { register p_entry t; t = &h_entry[g_getcont(p)]; - if (toplevel == 0 && safety != NOSCANDONE) { + if (toplevel == 0) { fputs(c_LLptrmin,f); } if (safety == SAFE) { @@ -421,10 +421,7 @@ rulecode(p,safety,mustscan,mustpop) register p_gram p; { fputs("LL_SCANDONE(",f); } else if (safety == NOSCANDONE) { - if (toplevel != 0) { - fputs("LL_T_NOSCANDONE(", f); - } - else fputs("LL_N_NOSCANDONE(", f); + fputs("LL_T_NOSCANDONE(", f); } PTERM(f,t); fputs(");\n", f); @@ -481,6 +478,7 @@ alternation(p, safety, mustscan, mustpop, lb) register p_gram p; { int var; int haddefault = 0; int unsafe = 1; + int nsafe; p_set set; p_set setalloc(); @@ -492,13 +490,13 @@ alternation(p, safety, mustscan, mustpop, lb) register p_gram p; { var = nvar++; if (!lb) lb = hulp1; if (safety <= SAFESCANDONE) unsafe = 0; - if (unsafe && hulp1 == lb) fprintf(f,"L_%d: ", hulp1); - else if (mustpop) { + if (!unsafe && mustpop) { mustpop = 0; fputs(c_LLptrmin, f); } if (unsafe) { fprintf(f,"{ int LL_%d = 0;\n", var); + if (hulp1 == lb) fprintf(f, "L_%d: \n", hulp1); } fputs("switch(LLcsymb) {\n", f); while (g_gettype(p) != EORULE) { @@ -527,17 +525,15 @@ alternation(p, safety, mustscan, mustpop, lb) register p_gram p; { haddefault = 1; } else gencases(l->l_symbs); + nsafe = SAFE; if (l->l_flag & DEF) { if (unsafe) { fprintf(f,"L_%d: ;\n", hulp2); } - if (mustpop) fputs(c_LLptrmin, f); - rulecode(l->l_rule, SAFESCANDONE, mustscan, 0); - } - else { - if (mustpop) fputs(c_LLptrmin, f); - rulecode(l->l_rule, SAFE, mustscan, 0); + if (safety != SAFE) nsafe = SAFESCANDONE; } + if (mustpop) fputs(c_LLptrmin, f); + rulecode(l->l_rule, nsafe, mustscan, 0); fputs(c_break,f); if (l->l_flag & COND) { if (!haddefault) { @@ -578,9 +574,16 @@ dopush(p,safety,toplevel) register p_gram p; { return count; case TERM : { register p_term q; + int rep, cnt; q = (p_term) pentry[g_getcont(p)]; + rep = r_getkind(&(q->t_reps)); + cnt = r_getnum(&(q->t_reps)); count += dopush(p+1,SCANDONE,0); + if (toplevel > 0 && + (rep == OPT || (rep == FIXED && cnt == 0))) { + if (safety <= SAFESCANDONE) return count; + } *ppushlist++ = findindex(&(q->t_contains)); return count+1; } case TERMINAL : @@ -707,15 +710,25 @@ codeforterm(q,safety,toplevel) register p_term q; { register int i; register int rep; int persistent; + int ispushed; f = fpars; i = r_getnum(&(q->t_reps)); rep = r_getkind(&(q->t_reps)); + ispushed = !(toplevel > 0 && safety <= SAFESCANDONE && + (rep == OPT || (rep == FIXED && i == 0))); persistent = (q->t_flags & PERSISTENT); if (safety == NOSCANDONE && (rep != FIXED || i == 0)) { fputs(c_read, f); - if (rep == FIXED && g_gettype(q->t_rule) != ALTERNATION) { + safety = SCANDONE; + } + if (ispushed) { + if ((safety <= SAFESCANDONE && + (rep == OPT || (rep == FIXED && i == 0))) || + (rep == FIXED && i == 0 && + g_gettype(q->t_rule) != ALTERNATION)) { fputs(c_LLptrmin, f); + ispushed = 0; } } if (i) { @@ -726,6 +739,7 @@ codeforterm(q,safety,toplevel) register p_term q; { if (rep == FIXED) { if (gettout(q) == NOSCANDONE && safety == NOSCANDONE) { fputs(c_read,f); + safety = SCANDONE; } } } @@ -734,22 +748,24 @@ codeforterm(q,safety,toplevel) register p_term q; { fputs("for (;;) {\n",f); } if (rep == STAR || rep == OPT) { - genifhead(q,rep); + genifhead(q, rep, safety, ispushed); } rulecode(q->t_rule,t_safety(rep,i,persistent,safety), rep != FIXED || gettout(q) != NOSCANDONE, - rep == FIXED && i == 0 && g_gettype(q->t_rule) == ALTERNATION); + rep == FIXED && i == 0 && ispushed); /* in the case of '+', the if is after the code for the rule */ if (rep == PLUS) { if (!persistent) { fprintf(f, "*LLptr = %d;\n", findindex(&(q->t_first))); + /* ??? */ } - genifhead(q,rep); + genifhead(q,rep,safety, ispushed); } if (rep != OPT && rep != FIXED) fputs("continue;\n", f); if (rep != FIXED) { fputs(c_close, f); /* Close switch */ if (rep != OPT) { + if (ispushed) fputs(c_LLptrmin, f); fputs("break;\n", f); } } @@ -763,19 +779,24 @@ codeforterm(q,safety,toplevel) register p_term q; { } STATIC -genifhead(q,rep) register p_term q; { +genifhead(q, rep, safety, ispushed) register p_term q; { /* * Generate if statement for term q */ register FILE *f; p_set p1; p_set setalloc(); - int hulp, hulp1; + int hulp1; + int safeterm; f = fpars; - hulp = nlabel++; hulp1 = nlabel++; - fprintf(f, "L_%d : switch(LLcsymb) {\n", hulp); + if (rep == PLUS) safeterm = gettout(q) <= SAFESCANDONE; + else if (rep == OPT) safeterm = safety <= SAFESCANDONE; + else /* if (rep == STAR) */ { + safeterm = safety <= SAFESCANDONE && gettout(q) <= SAFESCANDONE; + } + fputs("switch(LLcsymb) {\n", f); if (q->t_flags & RESOLVER) { p1 = setalloc(tsetsize); setunion(p1,q->t_first,tsetsize); @@ -794,15 +815,17 @@ genifhead(q,rep) register p_term q; { fprintf(f, ") goto L_%d;\n", hulp1); } gencases(q->t_follow); - fputs("LLptr++; break;\n", f); - fprintf(f, "default: if (!LLnext()) goto L_%d;\n", hulp); - gencases(q->t_first); + if (ispushed && rep == OPT) fputs(c_LLptrmin, f); + fputs("break;\n", f); + if (!safeterm) { + fputs("default: if (!LLnext()) break;\n", f); + gencases(q->t_first); + } + else fputs("default: ;\n", f); if (q->t_flags & RESOLVER) { fprintf(f, "L_%d : ;\n", hulp1); } - if (rep == OPT) { - fputs(c_LLptrmin,f); - } + if (ispushed && rep == OPT) fputs(c_LLptrmin, f); } STATIC From 2f02820a56331e7c10a63d00ee2d65310cd5bb98 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 3 Oct 1985 18:31:47 +0000 Subject: [PATCH 0087/1625] Initial revision --- util/LLgen/src/sets.c | 225 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 225 insertions(+) create mode 100644 util/LLgen/src/sets.c diff --git a/util/LLgen/src/sets.c b/util/LLgen/src/sets.c new file mode 100644 index 00000000..c3710997 --- /dev/null +++ b/util/LLgen/src/sets.c @@ -0,0 +1,225 @@ +/* + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. + * + * This product is part of the Amsterdam Compiler Kit. + * + * Permission to use, sell, duplicate or disclose this software must be + * obtained in writing. Requests for such permissions may be sent to + * + * Dr. Andrew S. Tanenbaum + * Wiskundig Seminarium + * Vrije Universiteit + * Postbox 7161 + * 1007 MC Amsterdam + * The Netherlands + * + */ + +/* + * L L G E N + * + * An Extended LL(1) Parser Generator + * + * Author : Ceriel J.H. Jacobs + */ + +/* + * sets.c + * Some general setmanipulation routines are defined, + * and also two set allocating routines are defined + */ + +# include "types.h" +# include "extern.h" +# include "sets.h" +# include "assert.h" + +# ifndef NORCSID +static string rcsid9 = "$Header$"; +# endif + +/* In this file the following routines are defined: */ +extern setinit(); +extern p_set setalloc(); +extern int setunion(); +extern int setintersect(); +extern setminus(); +extern int setempty(); +extern int findindex(); +extern int setcount(); + +int tbitset; +int setsize,tsetsize; +p_set *setptr, *maxptr, *topptr; + +static unsigned size,nbytes; + +setinit(ntneeded) { + /* + * Initialises some variables needed for setcomputations + */ + register int bitset; + + nbytes = NBYTES(nterminals); + tbitset = ALIGN(nbytes); + tsetsize = NINTS(tbitset); + bitset = tbitset; + if (ntneeded) { + /* nonterminals must be included in the sets */ + bitset += NBYTES(nnonterms); + } + setsize = NINTS(bitset); + tbitset *= 8; +} + +p_set +setalloc(size) int size; { + /* + * Allocate a set of size "size" ints + */ + register p_set t; + register int i; + p_mem alloc(); + + assert(size == tsetsize || size == setsize); + t = (p_set) alloc((unsigned) (size * sizeof(int))); + i = size; + t += i; + for (; i; i--) { + *--t = 0; + } + return t; +} + +int +setunion(a,b,size) register p_set a,b; int size; { + /* + * a = a union b. + * Return 1 if the set a changed + */ + register i; + register j; + int nsub = 0; + + assert(size == tsetsize || size == setsize); + for (i = size; i; i--) { + *a = (j = *a) | *b++; + if (*a++ != j) { + nsub = 1; + } + } + return nsub; +} + +int +setintersect(a,b,size) register p_set a,b; int size; { + /* + * a = a intersect b. + * return 1 if the resut is empty + */ + register i; + register nempty; + + assert(size == tsetsize || size == setsize); + nempty = 1; + for (i = size; i; i--) { + if (*a++ &= *b++) nempty = 0; + } + return nempty; +} + +setminus(a,b,size) register p_set a,b; int size; { + /* + * a = a setminus b + */ + register i; + + assert(size == tsetsize || size == setsize); + for (i = size; i; i--) { + *a++ &= ~(*b++); + } +} + +int +setempty(p) register p_set p; { + /* + * Return 1 if the set p is empty + */ + register i; + + for (i = tsetsize; i; i--) { + if (*p++) return 0; + } + return 1; +} + +int +findindex(set) p_set *set; { + /* + * The set "set" will serve as a recovery set. + * Search for it in the table. If not present, enter it + */ + register p_set *t; + p_mem alloc(),ralloc(); + register p_set a; + register p_set b; + register i; + register j; + int saved; + + /* + * First search for the set in the table + */ + for (t = setptr; t < maxptr; t++) { + a = *t; + b = *set; + for (i = tsetsize; i; i--) { + if (*a++ != *b++) break; + } + if (i) continue; + /* + * Here, the sets are equal. + */ + return nbytes * (t - setptr); + } + /* + * Now check if the set consists of only one element. + * It would be a waste to use a set for that + */ + if (setcount(*set, &saved) == 1) return -h_entry[saved].h_num; + /* + * If it does, return its number as a negative number. + */ + if (maxptr >= topptr) { + /* + * Need new space for the list, in chunks of 50 pointers + */ + if (setptr == 0) { + setptr = (p_set *) alloc(50 * sizeof(p_set)); + size = 50; + maxptr = setptr; + } else { + setptr = (p_set *) ralloc((p_mem) setptr, + (50+size)*sizeof(p_set)); + maxptr = &setptr[size-1]; + size += 50; + } + topptr = &setptr[size-1]; + } + *maxptr = setalloc(tsetsize); + setunion(*maxptr, *set, tsetsize); + return nbytes * (maxptr++ - setptr); +} + +int +setcount(set, saved) register p_set set; int *saved; { + register int i, j; + + for (j = 0, i = 0; i < nterminals; i++) { + if (IN(set,i)) { + j++; + *saved = i; + } + } + return j; +} From d70f277ee61a7bcb434e5c15a7fad387cfa0519a Mon Sep 17 00:00:00 2001 From: bal Date: Mon, 14 Oct 1985 09:27:24 +0000 Subject: [PATCH 0088/1625] Several optimization patterns for DAS (Delftse Ada Subset) frontend added. --- mach/m68k2/cg/table | 71 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 3 deletions(-) diff --git a/mach/m68k2/cg/table b/mach/m68k2/cg/table index c7212479..17136980 100644 --- a/mach/m68k2/cg/table +++ b/mach/m68k2/cg/table @@ -235,6 +235,10 @@ lae | | | {EXTERNAL_ADDR,$1} | | lxl $1 == 0 | | | LB | | lxl $1 == 1 | | | {DISPL4,LB,8} | | +lxl $1 == 2 | | + allocate(ADDREG) + "move.l 8(a6),%[a]" + "move.l 8(%[a]),%[a]" | %[a] | | lxl $1>1 | | allocate(ADDREG,DATAREG = {IMMEDIATE,$1-1}) "move.l a6,%[a]" @@ -788,9 +792,14 @@ ldl ldc sbi sdl $1 == $4 && $3 == 4 && inreg($1) < 2 | | lde ldc sbi sde $3 == 4 && $1 == $4 | | remove(MEM_ALL) "sub.l #$2,$1" | | | (9,17) +mli $1 == 2 | DATASCR ANY | "muls %[2],%[1]" + erase(%[1]) + setcc(%[1]) | %[1] | | mli $1 == 2 | ANY DATASCR | "muls %[1],%[2]" erase(%[2]) setcc(%[2]) | %[2] | | +ldc mli loww(1) == 1 && highw(1) == 0 && $2 == 4 | | | | | +ldc mli loww(1) == 2 && highw(1) == 0 && $2 == 4 | | | | loc 1 sli 4 | mli $1 == 4 | | remove(ALL) "jsr .mli" | DD1 | | @@ -1062,9 +1071,7 @@ adp $1 >= 0-32767 && $1 <= 32767 ... | nocoercions: LOCAL_ADDR | | {LOCAL_ADDR,%[1.off]+$1} | | ... | nocoercions: REGOFF_ADDR | | {REGOFF_ADDR,%[1.reg],%[1.off]+$1} | | ... | nocoercions: ADDREG | | {REGOFF_ADDR,%[1],$1} | | -... | ADDSCR | "lea $1(%[1]),%[1]" - erase(%[1]) - setcc(%[1]) | %[1] | | +... | ADDSCR | | {REGOFF_ADDR,%[1],$1} | | adp | nocoercions: EXTERNAL_ADDR | | {EXTERNAL_ADDR,%[1.off] + "+" + tostring($1)} | | ... | ADDSCR | "add.l #$1,%[1]" @@ -1098,6 +1105,9 @@ ldl adp sdl $1 == $3 && inreg($1) < 2 | | remove(MEM_ALL) "add.l #$2,$1(a6)" | | | (8,16) lde adp sde $1 == $3 | | remove(MEM_ALL) "add.l #$2,$1" | | | (9,17) +ldc ads loww(1) == 0 && highw(1) == 0 && $2 == 4 | | | | | +ldc ads highw(1) == 0 && $2 == 4 | ADDREG | + | {REGOFF_ADDR,%[1],loww(1)} | | ads $1 == 2 | ANY ADDSCR | "add.w %[1],%[2]" erase(%[2]) setcc(%[2]) | %[2] | | @@ -1289,6 +1299,22 @@ loc loc cii $1==1 && $2==4 | ANY | "ext.l %[a]" erase(%[a]) setcc(%[a]) | %[a] | | +loc loc cuu $1==1 && $2==4 | nocoercions: DATASCR | + "and.l #255,%[1]" + erase(%[1]) + setcc(%[1]) | %[1] | | +... | ANY | + allocate(DATAREG4) + "clr.l %[a]" + move(%[1],%[a.1]) + erase(%[a]) + | %[a] | | +... | ANY1 | + allocate(DATAREG4) + "clr.l %[a]" + "move.b %[1],%[a.1]" + erase(%[a]) + | %[a] | | loc loc cii $1==2 && $2==4 | ANY | allocate(%[1],DATAREG4) move(%[1],%[a.1]) @@ -1299,6 +1325,9 @@ loc loc cuu $1==2 && $2==4 | | | {IMMEDIATE,0} | | loc loc ciu $1==2 && $2==4 | | | {IMMEDIATE,0} | | loc loc cui $1==2 && $2==4 | | | {IMMEDIATE,0} | | +loc loc loc cuu $1 == 0 && $2 == 1 && $3 == 4 | | | {DOUBLE,"0"} | | +loc loc loc ciu $1 == 0 && $2 == 1 && $3 == 4 | | | {DOUBLE,"0"} | | +loc loc loc cui $1 == 0 && $2 == 1 && $3 == 4 | | | {DOUBLE,"0"} | | loc loc loc cuu $1 == 0 && $2 == 2 && $3 == 4 | | | {DOUBLE,"0"} | | loc loc loc ciu $1 == 0 && $2 == 2 && $3 == 4 | | | {DOUBLE,"0"} | | loc loc loc cui $1 == 0 && $2 == 2 && $3 == 4 | | | {DOUBLE,"0"} | | @@ -1311,6 +1340,7 @@ loc loc ciu $1==4 && $2==2 | DATAREG4 | | %[1.1] | | ... | ANY | | | | loc loc cui $1==4 && $2==2 | DATAREG4 | | %[1.1] | | ... | ANY | | | | +loc loc loc cuu $2 == 1 && $3 == 4 && $1 > 0 && $1 < 128 | | | | ldc $1 | /* Floating point stuff */ @@ -2251,6 +2281,24 @@ ldc cmi zgt loww(1)==0&&highw(1)==0 && $2==4 | DATA_ALT4 STACK | test(%[1]) "bgt $3" | | | +ldc cmi zlt $2==4 | DATA_ALT4 STACK | + "cmp.l #$1,%[1]" + "blt $3" | | | +ldc cmi zle $2==4 | DATA_ALT4 STACK | + "cmp.l #$1,%[1]" + "ble $3" | | | +ldc cmi zeq $2==4 | DATA_ALT4 STACK | + "cmp.l #$1,%[1]" + "beq $3" | | | +ldc cmi zne $2==4 | DATA_ALT4 STACK | + "cmp.l #$1,%[1]" + "bne $3" | | | +ldc cmi zge $2==4 | DATA_ALT4 STACK | + "cmp.l #$1,%[1]" + "bge $3" | | | +ldc cmi zgt $2==4 | DATA_ALT4 STACK | + "cmp.l #$1,%[1]" + "bgt $3" | | | ldc cms zeq loww(1)==0&&highw(1)==0 && $2==4 | DATA_ALT4 STACK | test(%[1]) @@ -2258,6 +2306,12 @@ ldc cms zeq loww(1)==0&&highw(1)==0 && $2==4 | DATA_ALT4 STACK | ldc cms zne loww(1)==0&&highw(1)==0 && $2==4 | DATA_ALT4 STACK | test(%[1]) "bne $3" | | | +ldc cms zeq $2==4 | DATA_ALT4 STACK | + "cmp.l #$1,%[1]" + "beq $3" | | | +ldc cms zne $2==4 | DATA_ALT4 STACK | + "cmp.l #$1,%[1]" + "bne $3" | | | cmp tlt | ANY4 ADDREG | allocate(DATAREG={IMMEDIATE,1}) "cmp.l %[1],%[2]" @@ -2559,6 +2613,7 @@ zgt | DATA_ALT | remove(ALL) /* G R O U P : XIV P R O C E D U R E C A L L S */ +lpi cai | | | | cal $1 | cai | ADDREG | remove(ALL) "jsr (%[1])" | | | @@ -2739,6 +2794,16 @@ mon | STACK | "jsr .mon" | | | nop | STACK | "jsr .nop" | | | lim | | | {ABS4,".trpim"} | | lor $1 == 0 | | | LB | | +#ifdef REGVARS +lor sdl $1 == 1 && inreg($2) == 2 | + STACK | "move.l sp,%(regvar($1)%)" | | | +#endif +lor sdl $1 == 1 | STACK | "move.l sp,$2(a6)" | | | +lor adp $1 == 1 | STACK | allocate(ADDREG) + "move.l sp,%[a]" + "add.l #$2,%[a]" | %[a] | | +lor ldf $1 == 1 | STACK | allocate(ADDREG) + "move.l $2(sp),%[a]" | %[a] | | lor $1 == 1 | STACK | "move.l sp,-(sp)" | | | lor $1 == 2 | | | {ABS4,".reghp"} | | lpb | | | | adp 8 | From d9f72cc2dc3c1b7dbd2d467fd6494d1b86843ae2 Mon Sep 17 00:00:00 2001 From: keie Date: Tue, 15 Oct 1985 15:47:12 +0000 Subject: [PATCH 0089/1625] BSD4.3 size returns an error when it cannot find one of its arguments. --- util/opt/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/opt/Makefile b/util/opt/Makefile index e2c5e1dc..ed067c94 100644 --- a/util/opt/Makefile +++ b/util/opt/Makefile @@ -29,7 +29,7 @@ cmp : opt cmp opt ../../lib/em_opt install:opt - size opt ../../lib/em_opt + -size opt ../../lib/em_opt cp opt ../../lib/em_opt pattern.c: patterns mktab From 130885344be0cff2d6fe79f703c6484aaa9d312e Mon Sep 17 00:00:00 2001 From: keie Date: Tue, 15 Oct 1985 15:53:48 +0000 Subject: [PATCH 0090/1625] The extra BSD4.2 code caused two branches to be out of range. --- mach/vax4/libem/mon.s | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mach/vax4/libem/mon.s b/mach/vax4/libem/mon.s index 01e8c5b8..f81e9ead 100644 --- a/mach/vax4/libem/mon.s +++ b/mach/vax4/libem/mon.s @@ -227,9 +227,9 @@ Lsigtrp: movl 4(sp),r1 # Sig in r1 movl (sp)+,(sp) # Trapno on top of stack cmpl r1,$16 - bgtru badsig + jgtru badsig tstl r1 - beql badsig + jeql badsig #ifdef BSD42 movl $3,(ap)+ # sigvec(sig, vec, ovec) #else BSD42 From 4050d5e7e310b013ffd3ef8876356dcd613dbe61 Mon Sep 17 00:00:00 2001 From: bal Date: Mon, 18 Nov 1985 16:55:53 +0000 Subject: [PATCH 0091/1625] Yet another bug reported by sater. --- mach/proto/ncg/codegen.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/mach/proto/ncg/codegen.c b/mach/proto/ncg/codegen.c index 475d17d9..7894a1b6 100644 --- a/mach/proto/ncg/codegen.c +++ b/mach/proto/ncg/codegen.c @@ -565,14 +565,18 @@ normalfailed: if (stackpad!=tokpatlen) { * property. If none then some stacking has to take place. */ if (npos==0) { - if (stackheight<=tokpatlen) { - if (!toplevel) { - BROKE(); - } else - fatal("No regs available"); - } - totalcost += stackupto( &fakestack[0],ply,toplevel); - CHKCOST(); + if (stackheight<=tokpatlen) { + if (!toplevel) { + BROKE(); + } else { + if (paniced) + fatal("No regs available"); + totalcost += stackupto( &fakestack[0],ply,toplevel); + goto panic; + } + } + totalcost += stackupto( &fakestack[0],ply,toplevel); + CHKCOST(); } } while (npos==0); if (!exactmatch) { From 8abda5fb1d0c3d0ed5d42ba8974f681661612cc3 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 25 Nov 1985 15:47:51 +0000 Subject: [PATCH 0092/1625] Completely new version, generating a much faster parser. --- util/LLgen/src/LLgen.g | 316 ++++++++++-------- util/LLgen/src/Makefile | 22 +- util/LLgen/src/alloc.c | 49 ++- util/LLgen/src/check.c | 319 ++++++++++--------- util/LLgen/src/compute.c | 673 +++++++++++++++++++++------------------ util/LLgen/src/extern.h | 28 +- util/LLgen/src/gencode.c | 583 ++++++++++++++++++--------------- util/LLgen/src/global.c | 21 +- util/LLgen/src/io.h | 1 - util/LLgen/src/main.c | 176 +++++----- util/LLgen/src/name.c | 274 ++++++++-------- util/LLgen/src/reach.c | 25 +- util/LLgen/src/sets.c | 153 ++++----- util/LLgen/src/sets.h | 10 +- util/LLgen/src/tokens.g | 244 +++++++------- util/LLgen/src/types.h | 79 +++-- 16 files changed, 1579 insertions(+), 1394 deletions(-) diff --git a/util/LLgen/src/LLgen.g b/util/LLgen/src/LLgen.g index d6968728..c842ee5b 100644 --- a/util/LLgen/src/LLgen.g +++ b/util/LLgen/src/LLgen.g @@ -26,33 +26,64 @@ /* * LLgen.g * Defines the grammar of LLgen. - * Some routines that are included build the internal structure + * Some routines that build the internal structure are also included */ { # include "types.h" # include "io.h" -# include "tunable.h" # include "extern.h" # include "assert.h" +# include "cclass.h" # ifndef NORCSID -static string rcsidb = "$Header$"; +static string rcsid = "$Header$"; # endif -p_mem alloc(); +p_mem alloc(), new_mem(); string store(); -t_gram search(); +p_gram search(); static int nparams; /* parameter count for nonterminals */ -static t_gram elem; /* temporary space */ static int acount; /* count #of global actions */ +static t_info term_info, + link_info; +static p_order order, + maxorder; /* Here are defined : */ +extern a_init(); +STATIC p_order neworder(); STATIC copyact(); -STATIC unsigned get(); -STATIC t_gram mkalt(); -STATIC t_gram mkterm(); +STATIC mkalt(); +STATIC mkterm(); STATIC p_gram copyrule(); +/* and of course LLparse() */ + +a_init() { + term_info.i_esize = sizeof (t_term); + term_info.i_incr = 50; + link_info.i_esize = sizeof (t_link); + link_info.i_incr = 50; + name_init(); +} + +STATIC p_order +neworder(index) { + register p_order po; + + if ((po = order) == maxorder) { + po = (p_order) alloc(20 * sizeof(*order)); + maxorder = po + 20; + } + order = po + 1; + po->o_next = 0; + po->o_index = index; + if (porder) { + porder->o_next = po; + } + else sorder = po; + return po; +} } %start LLparse, spec; @@ -62,7 +93,7 @@ spec : { acount = 0; } { /* * Put an endmarker in temporary file */ - putc('\0',fact); putc('\0',fact); + fprintf(fact,"%c%c",'\0', '\0'); } ; @@ -85,12 +116,12 @@ def { register string p; } * Put the declaration in the list * of start symbols */ - t_gram temp; + register p_gram temp; register p_start ff; temp = search(NONTERM,lextoken.t_string,BOTH); ff = (p_start) alloc(sizeof(t_start)); - ff->ff_nont = &nonterms[g_getnont(&temp)]; + ff->ff_nont = g_getnont(temp); ff->ff_name = p; ff->ff_next = start; start = ff; @@ -98,7 +129,8 @@ def { register string p; } | C_LEXICAL C_IDENT { if (!lexical) { lexical = store(lextoken.t_string); - } else error(linecount,"Duplicate %%lexical"); + } + else error(linecount,"Duplicate %%lexical"); } ';' /* @@ -118,17 +150,18 @@ def { register string p; } listel : C_IDENT { search(TERMINAL,lextoken.t_string,ENTERING); } ; -rule { register p_nont p;} +rule { register p_nont p; + p_gram rr; + register p_gram temp; + } : /* * grammar for a production rule */ - C_IDENT { t_gram temp; - - temp = search(NONTERM,lextoken.t_string,BOTH); - p = &nonterms[g_getnont(&temp)]; + C_IDENT { temp = search(NONTERM,lextoken.t_string,BOTH); + p = &nonterms[g_getnont(temp)]; if (p->n_rule) { error(linecount, - "nonterminal already defined"); +"nonterminal %s already defined", lextoken.t_string); } /* * Remember the order in which the nonterminals @@ -136,20 +169,26 @@ rule { register p_nont p;} * order to keep track with the actions on the * temporary file */ - *maxorder++ = p - nonterms; + porder = neworder(p - nonterms); p->n_count = acount; acount = 0; p->n_lineno = linecount; } [ params(2) { p->n_flags |= PARAMS; - if (nparams > 7) { + if (nparams > 15) { error(linecount,"Too many parameters"); - } else setntparams(p,nparams); + } + else setntparams(p,nparams); } ]? [ action(0) { p->n_flags |= LOCALS; } ]? - ':' productions(&(p->n_rule)) ';' + ':' productions(&rr) ';' + /* + * Do not use p->n_rule now! The nonterms array + * might have been re-allocated. + */ + { nonterms[g_getnont(temp)].n_rule = rr;} ; action(int n;) @@ -173,73 +212,80 @@ productions(p_gram *p;) register p_gram p_alts = alts; int o_lc, n_lc; } : - { n_lc = o_lc = linecount; } + { o_lc = linecount; } simpleproduction(p,&conflres) - [ '|' { n_lc = linecount; } - [ C_DEFAULT { if (haddefault) { - error(linecount, - "multiple %%default"); - } - haddefault = 1; - t |= DEF; - } - ]? - simpleproduction(&prod,&t) + { if (conflres & DEF) haddefault = 1; } + [ + [ '|' { n_lc = linecount; } + simpleproduction(&prod,&t) { if (p_alts - alts >= 97) { error(n_lc,"Too many alternatives"); p_alts = alts; } - *p_alts++ = mkalt(*p,conflres,o_lc); + if (t & DEF) { + if (haddefault) { + error(n_lc, + "More than one %%default in alternation"); + } + haddefault = 1; + } + mkalt(*p,conflres,o_lc,p_alts++); o_lc = n_lc; conflres = t; t = 0; *p = prod; } - ]* { if (conflres & ~DEF) { + ]+ { if (conflres & ~DEF) { error(n_lc, - "Resolver on last alternative"); - } - if (p_alts > alts) { - *p_alts++ = mkalt(*p,conflres,n_lc); - g_settype(p_alts,EORULE); - *p = copyrule(alts,p_alts+1-alts); - if (!haddefault) { - ((p_link) pentry[g_getcont(*p)]) - ->l_flag |= DEF; - } + "Resolver on last alternative not allowed"); } + mkalt(*p,conflres,n_lc,p_alts++); + g_settype(p_alts,EORULE); + *p = copyrule(alts,p_alts+1-alts); } + | + { if (conflres & ~DEF) { + error(o_lc, + "No alternation conflict resolver allowed here"); + } + /* + if (conflres & DEF) { + error(o_lc, + "No %%default allowed here"); + } + */ + } + ] ; { -STATIC t_gram -mkalt(prod,condition,lc) p_gram prod; { +STATIC +mkalt(prod,condition,lc,res) p_gram prod; register p_gram res; { /* - * Create an alternation, initialise it and return - * a grammar element containing it + * Create an alternation and initialise it. */ - register unsigned hulp; + register int hulp; register p_link l; - t_gram r; - g_init(&r); - hulp = get(sizeof(*l)); - l = (p_link) pentry[hulp]; + l = (p_link) new_mem(&link_info); + links = (p_link) link_info.i_ptr; + hulp = l - links; l->l_rule = prod; l->l_flag = condition; - g_setcont(&r,hulp); - g_settype(&r,ALTERNATION); - r.g_lineno = lc; - return r; + g_setcont(res,hulp); + g_settype(res,ALTERNATION); + res->g_lineno = lc; } } simpleproduction(p_gram *p; register int *conflres;) { t_gram rule[100]; + t_gram elem; register p_gram p_rule = rule; - t_reps reps; + int cnt, kind; } : - { r_init(&reps); } + [ C_DEFAULT { *conflres = DEF; } + ]? [ /* * Optional conflict reslover @@ -248,92 +294,91 @@ simpleproduction(p_gram *p; register int *conflres;) | C_PREFER { *conflres |= PREFERING; } | C_AVOID { *conflres |= AVOIDING; } ]? - [ %persistent elem + [ %persistent elem(&elem) { if (p_rule - rule >= 98) { error(linecount,"Production too long"); p_rule = rule; } - r_setkind(&reps,FIXED); - r_setnum(&reps,0); + kind = FIXED; + cnt = 0; } - [ repeats(&reps) + [ repeats(&kind, &cnt) { if (g_gettype(&elem) != TERM) { *p_rule = elem; g_settype(p_rule+1,EORULE); - elem = mkterm(copyrule(p_rule,2), - 0, - &reps, - p_rule->g_lineno); + mkterm(copyrule(p_rule,2), + 0, + p_rule->g_lineno, + &elem); } } ]? { if (g_gettype(&elem) == TERM) { register p_term q; - q = (p_term) pentry[g_getcont(&elem)]; - q->t_reps = reps; - if (q->t_flags & RESOLVER && - (r_getkind(&reps) == PLUS || - r_getkind(&reps) == FIXED)) { + q = &terms[g_getcont(&elem)]; + r_setkind(q,kind); + r_setnum(q,cnt); + if ((q->t_flags & RESOLVER) && + (kind == PLUS || kind == FIXED)) { error(linecount, - "illegal %%while"); + "%%while not allowed in this term"); } - if (q->t_flags & PERSISTENT && - r_getkind(&reps) == FIXED) { + /* + * A persistent fixed term is the same + * as a non-persistent fixed term. + * Should we complain? + if ((q->t_flags & PERSISTENT) && + kind == FIXED) { error(linecount, "illegal %%persistent"); } + */ } *p_rule++ = elem; } ]* { register p_term q; g_settype(p_rule,EORULE); + *p = 0; if (g_gettype(&rule[0]) == TERM && p_rule-rule == 1) { - q=(p_term)pentry[g_getcont(&rule[0])]; - if (r_getkind(&(q->t_reps))==FIXED && - r_getnum(&(q->t_reps)) == 0) { + q = &terms[g_getcont(&rule[0])]; + if (r_getkind(q) == FIXED && + r_getnum(q) == 0) { *p = q->t_rule; } - else *p = copyrule(rule,2); } - else *p = copyrule(rule,p_rule-rule+1); + if (!*p) *p = copyrule(rule,p_rule-rule+1); } ; { -STATIC t_gram -mkterm(prod,flags,reps,lc) p_gram prod; register p_reps reps; { +STATIC +mkterm(prod,flags,lc, result) p_gram prod; register p_gram result; { /* * Create a term, initialise it and return - * a grammar element contianing it + * a grammar element containing it */ register p_term q; - register unsigned hulp; - t_gram r; + unsigned hulp; - g_init(&r); - hulp = get(sizeof(*q)); - q = (p_term) pentry[hulp]; + q = (p_term) new_mem(&term_info); + terms = (p_term) term_info.i_ptr; + hulp = q - terms; q->t_rule = prod; q->t_contains = 0; - /* "*1" = "?" */ - if (r_getnum(reps) == 1 && r_getkind(reps) == STAR) { - r_setkind(reps,OPT); - } - q->t_reps = *reps; q->t_flags = flags; - g_settype(&r,TERM); - g_setcont(&r,hulp); - r.g_lineno = lc; - return r; + g_settype(result,TERM); + g_setcont(result,hulp); + result->g_lineno = lc; } } -elem { register short t = 0; +elem (register p_gram pres;) + { register short t = 0; p_gram p1; - t_reps reps; int ln; + p_gram pe; } : '[' { ln = linecount; } [ C_WHILE expr { t |= RESOLVER; } @@ -341,23 +386,27 @@ elem { register short t = 0; [ C_PERSISTENT { t |= PERSISTENT; } ]? productions(&p1) - ']' { r_init(&reps); - elem = mkterm(p1,t,&reps,ln); + ']' { + mkterm(p1,t,ln,pres); } - | %default - C_IDENT { elem = search(UNKNOWN,lextoken.t_string,BOTH); } - [ params(0) { if (nparams > 6) { + | + C_IDENT { pe = search(UNKNOWN,lextoken.t_string,BOTH); + *pres = *pe; + } + [ params(0) { if (nparams > 14) { error(linecount,"Too many parameters"); - } else g_setnpar(&elem,nparams+1); - if (g_gettype(&elem) == TERMINAL) { + } else g_setnpar(pres,nparams+1); + if (g_gettype(pres) == TERMINAL) { error(linecount, "Terminal with parameters"); } } ]? - | C_LITERAL { elem = search(LITERAL,lextoken.t_string,BOTH); } - | { g_settype(&elem,ACTION); - elem.g_lineno = linecount; + | C_LITERAL { pe = search(LITERAL,lextoken.t_string,BOTH); + *pres = *pe; + } + | { g_settype(pres,ACTION); + pres->g_lineno = linecount; } action(1) ; @@ -371,20 +420,21 @@ expr : '(' { copyact('(',')',1,0); } ')' ; -repeats(t_reps *t;) { int t1 = 0; } : +repeats(int *kind, *cnt;) { int t1 = 0; } : [ - '?' { r_setkind(t,OPT); } - | [ '*' { r_setkind(t,STAR); } - | '+' { r_setkind(t,PLUS); } + '?' { *kind = OPT; } + | [ '*' { *kind = STAR; } + | '+' { *kind = PLUS; } ] number(&t1)? - { if (t1 == 1 && r_getkind(t) == PLUS) { - error(linecount, - "Illegal repetition specifier"); + { if (t1 == 1) { + t1 = 0; + if (*kind == STAR) *kind = OPT; + if (*kind == PLUS) *kind = FIXED; } } | number(&t1) - ] { r_setnum(t,t1); } + ] { *cnt = t1; } ; number(int *t;) @@ -404,12 +454,12 @@ firsts { register string p; } * Store this %first in the list belonging * to this input file */ - t_gram temp; + p_gram temp; register p_first ff; temp = search(NONTERM,lextoken.t_string,BOTH); ff = (p_first) alloc(sizeof(t_first)); - ff->ff_nont = &nonterms[g_getnont(&temp)]; + ff->ff_nont = g_getnont(temp); ff->ff_name = p; ff->ff_next = pfile->f_firsts; pfile->f_firsts = ff; @@ -436,11 +486,9 @@ copyact(ch1,ch2,flag,level) char ch1,ch2; { if (!level) { saved = linecount; nparams = 0; /* count comma's */ - putc('\0',f); - fprintf(f,"# line %d \"%s\"\n", linecount,f_input); - if (flag == 1) putc(ch1,f); + fprintf(f,"%c# line %d \"%s\"\n", '\0', linecount,f_input); } - else putc(ch1,f); + if (level || flag == 1) putc(ch1,f); for (;;) { ch = input(); if (ch == ch2) { @@ -451,7 +499,7 @@ copyact(ch1,ch2,flag,level) char ch1,ch2; { } return; } - if (! isspace(ch)) semicolon = 0; + if (c_class[ch] != ISSPA) semicolon = 0; switch(ch) { case ')': case '}': @@ -474,6 +522,7 @@ copyact(ch1,ch2,flag,level) char ch1,ch2; { skipcomment(1); continue; } + ch = '/'; break; case ';': semicolon = 1; @@ -516,21 +565,8 @@ copyact(ch1,ch2,flag,level) char ch1,ch2; { } } -static int ecount; /* Index in "pentry" array */ -STATIC unsigned -get(size) unsigned size; { - /* - * Get some core, save a pointer to it in "pentry", - * return index in pentry - */ - - if (ecount >= ENTSIZ) fatal(linecount,"Entry table overflow"); - pentry[ecount] = alloc(size); - return ecount++; -} - STATIC p_gram -copyrule(p,length) register p_gram p; register length; { +copyrule(p,length) register p_gram p; { /* * Returns a pointer to a grammar rule that was created in * p. The space pointed to by p can now be reused diff --git a/util/LLgen/src/Makefile b/util/LLgen/src/Makefile index 5e5f7ad9..1c9708a2 100644 --- a/util/LLgen/src/Makefile +++ b/util/LLgen/src/Makefile @@ -1,11 +1,11 @@ # $Header$ PROF= LLOPT= # -vvv -x -CFLAGS=$(PROF) -O -DNDEBUG # -R +CFLAGS=$(PROF) -O -DNDEBUG LDFLAGS=-i -OBJECTS = main.o gencode.o compute.o LLgen.o tokens.o check.o reach.o global.o name.o sets.o Lpars.o alloc.o machdep.o -CFILES = main.c gencode.c compute.c LLgen.c tokens.c check.c reach.c global.c name.c sets.c Lpars.c alloc.c machdep.c -FILES =types.h tunable.h extern.h io.h sets.h assert.h tokens.g LLgen.g main.c name.c compute.c sets.c gencode.c global.c check.c reach.c alloc.c machdep.c Makefile +OBJECTS = main.o gencode.o compute.o LLgen.o tokens.o check.o reach.o global.o name.o sets.o Lpars.o alloc.o machdep.o cclass.o +CFILES = main.c gencode.c compute.c LLgen.c tokens.c check.c reach.c global.c name.c sets.c Lpars.c alloc.c machdep.c cclass.c +FILES =types.h tunable.h extern.h io.h sets.h assert.h tokens.g LLgen.g main.c name.c compute.c sets.c gencode.c global.c check.c reach.c alloc.c machdep.c Makefile cclass.c GFILES = tokens.g LLgen.g LINT = lint -b -DNDEBUG -DNORCSID @@ -19,7 +19,7 @@ parser: $(GFILES) @touch parser LLgen: $(OBJECTS) - $(CC) $(PROF) $(LDFLAGS) $(OBJECTS) -o LLgen + $(CC) $(PROF) $(LDFLAGS) $(OBJECTS) -o LLgen @size LLgen pr : @@ -39,9 +39,9 @@ distr: # AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO LLgen.o: Lpars.h LLgen.o: assert.h +LLgen.o: cclass.h LLgen.o: extern.h LLgen.o: io.h -LLgen.o: tunable.h LLgen.o: types.h Lpars.o: Lpars.h alloc.o: extern.h @@ -50,22 +50,20 @@ check.o: assert.h check.o: extern.h check.o: io.h check.o: sets.h -check.o: tunable.h check.o: types.h compute.o: assert.h compute.o: extern.h compute.o: io.h compute.o: sets.h -compute.o: tunable.h compute.o: types.h gencode.o: assert.h +gencode.o: cclass.h gencode.o: extern.h gencode.o: io.h gencode.o: sets.h -gencode.o: tunable.h gencode.o: types.h +global.o: extern.h global.o: io.h -global.o: tunable.h global.o: types.h machdep.o: ../../../h/em_path.h machdep.o: types.h @@ -77,12 +75,10 @@ main.o: types.h name.o: assert.h name.o: extern.h name.o: io.h -name.o: tunable.h name.o: types.h reach.o: assert.h reach.o: extern.h reach.o: io.h -reach.o: tunable.h reach.o: types.h sets.o: assert.h sets.o: extern.h @@ -90,7 +86,7 @@ sets.o: sets.h sets.o: types.h tokens.o: Lpars.h tokens.o: assert.h +tokens.o: cclass.h tokens.o: extern.h tokens.o: io.h -tokens.o: tunable.h tokens.o: types.h diff --git a/util/LLgen/src/alloc.c b/util/LLgen/src/alloc.c index da86bbb9..2e8f2967 100644 --- a/util/LLgen/src/alloc.c +++ b/util/LLgen/src/alloc.c @@ -32,15 +32,18 @@ # include "extern.h" # ifndef NORCSID -static string rcsida = "$Header$"; +static string rcsid = "$Header$"; # endif static string e_nomem = "Out of memory"; p_mem alloc(size) unsigned size; { - register p_mem p; - p_mem malloc(); + /* + Allocate "size" bytes. Panic if it fails + */ + p_mem p; + p_mem malloc(); if ((p = malloc(size)) == 0) fatal(linecount,e_nomem); return p; @@ -48,9 +51,41 @@ alloc(size) unsigned size; { p_mem ralloc(p,size) p_mem p; unsigned size; { - register p_mem q; - p_mem realloc(); + /* + Re-allocate the chunk of memory indicated by "p", to + occupy "size" bytes + */ + p_mem realloc(); - if ((q = realloc(p,size)) == 0) fatal(linecount,e_nomem); - return q; + if ((p = realloc(p,size)) == 0) fatal(linecount,e_nomem); + return p; +} + +p_mem +new_mem(p) p_info p; { + /* + This routine implements arrays that can grow. + It must be called every time a new element is added to it. + Also, the array has associated with it a "info_alloc" structure, + which contains info on the element size, total allocated size, + a pointer to the array, a pointer to the first free element, + and a pointer to the top. + If the base of the array is remembered elsewhere, it should + be updated each time this routine is called + */ + p_mem rp; + unsigned sz; + + if (p->i_max >= p->i_top) { /* No more free elements */ + sz = p->i_size; + p->i_size += p->i_incr * p->i_esize; + p->i_ptr = !p->i_ptr ? + alloc(p->i_size) : + ralloc(p->i_ptr, p->i_size); + p->i_max = p->i_ptr + sz; + p->i_top = p->i_ptr + p->i_size; + } + rp = p->i_max; + p->i_max += p->i_esize; + return rp; } diff --git a/util/LLgen/src/check.c b/util/LLgen/src/check.c index 62815095..5c937c4e 100644 --- a/util/LLgen/src/check.c +++ b/util/LLgen/src/check.c @@ -30,7 +30,6 @@ # include "types.h" # include "extern.h" -# include "tunable.h" # include "io.h" # include "sets.h" # include "assert.h" @@ -39,21 +38,18 @@ static string rcsid1 = "$Header$"; # endif -# define PTERM(p) fprintf(fout,(p)->h_num < 0400 ? "'%s' " : "%s ",(p)->h_name); static string c_first = "> firstset "; static string c_contains = "> containset "; static string c_follow = "> followset "; p_set setalloc(); -static string ntname; /* nonterminal that is currently checked */ -static p_nont nt; /* pointer to its struct */ static int level; /* In this file are defined : */ extern conflchecks(); -STATIC newline(); +STATIC prline(); STATIC printset(); -STATIC check(); +STATIC int check(); STATIC moreverbose(); STATIC prrule(); STATIC cfcheck(); @@ -70,8 +66,7 @@ conflchecks() { * must be disjunct. */ register p_nont p; - register FILE *f; - register short *s; + register p_order s; p_file x = files; f_input = x->f_name; @@ -79,38 +74,43 @@ conflchecks() { for (p = nonterms; p < maxnt; p++) p->n_flags |= VERBOSE; } if (verbose) { - if ((f = fopen(f_out,"w")) == NULL) fatal(1,e_noopen,f_out); - fout = f; + if ((fout = fopen(f_out,"w")) == NULL) fatal(1,e_noopen,f_out); } /* * Check the rules in the order in which they are declared, * and input file by input file, to give proper error messages */ - for (; x->f_end < maxorder; x++) { + for (; x < maxfiles; x++) { f_input = x->f_name; - for (s = x->f_start; s <= x->f_end; s++) { - nt = p = &nonterms[*s]; - ntname = (min_nt_ent + *s)->h_name; + for (s = x->f_list; s; s = s->o_next) { + p = &nonterms[s->o_index]; + if (check(p->n_rule)) p->n_flags |= VERBOSE; + } + } + for (x = files; x < maxfiles; x++) { + f_input = x->f_name; + for (s = x->f_list; s; s = s->o_next) { + p = &nonterms[s->o_index]; if (p->n_flags & RECURSIVE) { error(p->n_lineno, "Recursion in default for nonterminal %s", - ntname); + p->n_name); } - check(p->n_rule); /* * If a printout is needed for this rule in * LL.output, just do it */ if (verbose && (p->n_flags & VERBOSE)) { - fprintf(f,"\n%s :\n",ntname); + fprintf(fout,"\n%s :\n",p->n_name); printset(p->n_first,c_first); printset(p->n_contains,c_contains); printset(p->n_follow,c_follow); - fputs("> rule\n\t",f); + fprintf(fout,"> rule%s\n\t", + p->n_flags&EMPTY ? "\t(EMPTY producing)" : ""); level = 8; prrule(p->n_rule); level = 0; - newline(); + prline("\n"); } /* * Now, the conflicts may be resolved @@ -118,16 +118,13 @@ conflchecks() { resolve(p->n_rule); } } - if (verbose) fclose(f); + if (verbose) fclose(fout); } STATIC -newline() { - /* - * Newline and "level" spaces indentation - */ - if (level > 0) fprintf(fout,"\n%*c",level,' '); - else putc('\n',fout); +prline(s) char *s; { + fputs(s, fout); + spaces(); } STATIC @@ -135,69 +132,68 @@ printset(p,s) register p_set p; string s; { /* * Print the elements of a set */ - register FILE *f; - register i; - register j; + register int i; + register int j; + register p_token pt; + string name; int k; int hulp; - k = strlen(s)+1; + k = strlen(s) + 2 + level; /* * k contains relative level of indentation */ - f = fout; - fprintf(f,"%s{ ",s); - j = level+1+k; + fprintf(fout,"%s{ ",s); + j = k; /* * j will gather the total length of the line */ - if (p == (p_set) 0) fputs(">non existent (yet?)< ",f); - else { - for (i = 0; i < nterminals; i++) { - if (IN(p,i)) { - hulp = strlen(h_entry[i].h_name)+1; - if (h_entry[i].h_num < 0400) hulp += 2; - if ((j += hulp) >= 78) { - /* - * Line becoming too long - */ - j = level+k+1+hulp; - newline(); - fprintf(f,">%*c",k,' '); - } - PTERM(&h_entry[i]); - } - } - if (ntprint) for (i = 0; i < nnonterms; i++) { - /* - * Nonterminals in the set must also be printed - */ - if (NTIN(p,i)) { - hulp = strlen((min_nt_ent+i)->h_name)+3; - if ((j += hulp) >= 78) { - j = level + k + 1 + hulp; - newline(); - fprintf(f,">%*c",k,' '); - } - fprintf(f,"<%s> ",(min_nt_ent+i)->h_name); + for (i = 0, pt = tokens; i < ntokens; i++,pt++) { + if (IN(p,i)) { + hulp = strlen(pt->t_string)+1; + if (pt->t_tokno < 0400) hulp += 2; + if ((j += hulp) >= 78) { + /* + * Line becoming too long + */ + j = k+hulp; + prline("\n"); + fprintf(fout,">%*c",k - level - 1,' '); } + fprintf(fout, pt->t_tokno<0400 ? "'%s' " : "%s ",pt->t_string); } } - putc('}',f); - newline(); + if (ntprint) for (i = 0; i < nnonterms; i++) { + /* + * Nonterminals in the set must also be printed + */ + if (NTIN(p,i)) { + name = nonterms[i].n_name; + hulp = strlen(name) + 3; + if ((j += hulp) >= 78) { + j = k + hulp; + prline("\n"); + fprintf(fout,">%*c",k - level - 1,' '); + } + fprintf(fout,"<%s> ",name); + } + } + prline("}\n"); } -STATIC +STATIC int check(p) register p_gram p; { /* * Search for conflicts in a grammar rule. */ - p_set temp; + register p_set temp; + register int retval; + retval = 0; for (;;) { switch (g_gettype(p)) { case EORULE : - return; + return retval; case NONTERM : { register p_nont n; @@ -205,28 +201,28 @@ check(p) register p_gram p; { if (g_getnpar(p) != getntparams(n)) { error(p->g_lineno, "Call of %s : parameter count mismatch", - (min_nt_ent+g_getnont(p))->h_name); + n->n_name); } break; } case TERM : { register p_term q; - q = (p_term) pentry[g_getcont(p)]; - check(q->t_rule); - if (r_getkind(&(q->t_reps)) == FIXED) break; + q = &terms[g_getcont(p)]; + retval |= check(q->t_rule); + if (r_getkind(q) == FIXED) break; if (setempty(q->t_first)) { q->t_flags |= EMPTYFIRST; - nt->n_flags |= VERBOSE; + retval = 1; error(p->g_lineno, "No symbols in term"); } if (empty(q->t_rule)) { q->t_flags |= EMPTYTERM; - nt->n_flags |= VERBOSE; + retval = 1; error(p->g_lineno, "Term produces empty"); } - temp = setalloc(setsize); - setunion(temp,q->t_first,setsize); - if (!setintersect(temp,q->t_follow,setsize)) { + temp = setalloc(); + setunion(temp,q->t_first); + if (!setintersect(temp,q->t_follow)) { /* * q->t_first * q->t_follow != EMPTY */ @@ -235,16 +231,17 @@ check(p) register p_gram p; { * No conflict resolver */ error(p->g_lineno, - "Repitition conflict"); - nt->n_flags |= VERBOSE; - if (verbose == 2) moreverbose(temp); + "Repetition conflict"); + retval = 1; + moreverbose(temp); } - } else { + } + else { if (q->t_flags & RESOLVER) { q->t_flags |= NOCONF; error(p->g_lineno, "%%while, no conflict"); - nt->n_flags |= VERBOSE; + retval = 1; } } free((p_mem) temp); @@ -252,29 +249,30 @@ check(p) register p_gram p; { case ALTERNATION : { register p_link l; - l = (p_link) pentry[g_getcont(p)]; - temp = setalloc(setsize); - setunion(temp,l->l_symbs,setsize); - if(!setintersect(temp,l->l_others,setsize)) { + l = &links[g_getcont(p)]; + temp = setalloc(); + setunion(temp,l->l_symbs); + if(!setintersect(temp,l->l_others)) { /* * temp now contains the conflicting * symbols */ if (!(l->l_flag & (COND|PREFERING|AVOIDING))) { error(p->g_lineno, - "Alternation conflict"); - nt->n_flags |= VERBOSE; - if (verbose == 2) moreverbose(temp); +"Alternation conflict"); + retval = 1; + moreverbose(temp); } } else { if (l->l_flag & (COND|PREFERING|AVOIDING)) { l->l_flag |= NOCONF; - error(p->g_lineno,"No conflict"); - nt->n_flags |= VERBOSE; + error(p->g_lineno, +"Conflict resolver without conflict"); + retval = 1; } } free( (p_mem) temp); - check(l->l_rule); + retval |= check(l->l_rule); break; } } p++; @@ -288,10 +286,11 @@ moreverbose(t) register p_set t; { * also containing nonterminals. * Take care that a printout will be prepared for these nonterminals */ - register i; + register int i; + register p_nont p; - if (verbose) for (i = 0; i < nnonterms; i++) { - if (NTIN(t,i)) nonterms[i].n_flags |= VERBOSE; + if (verbose == 2) for (i = 0, p = nonterms; i < nnonterms; i++, p++) { + if (NTIN(t,i)) p->n_flags |= VERBOSE; } } @@ -307,54 +306,45 @@ prrule(p) register p_gram p; { for (;;) { switch (g_gettype(p)) { case EORULE : - putc('\n',f); + fputs("\n",f); return; case TERM : { register p_term q; - register c; + register int c; - q = (p_term) pentry[g_getcont(p)]; - if (present) newline(); - if (r_getkind(&(q->t_reps)) != FIXED || - r_getnum(&(q->t_reps)) != 0) { - fputs("[ ",f); - level += 4; - if (q->t_flags & RESOLVER) { - fputs("%%while (..)",f); - newline(); - } - if (r_getkind(&(q->t_reps)) != FIXED) { - printset(q->t_first, c_first); - printset(q->t_contains, c_contains); - printset(q->t_follow,c_follow); - if (q->t_flags & EMPTYFIRST) { - fputs(">>> empty first",f); - newline(); - } - if (q->t_flags & EMPTYTERM) { - fputs(">>> term produces empty",f); - newline(); - } - cfcheck(q->t_first,q->t_follow, - q->t_flags & RESOLVER); - } - prrule(q->t_rule); - level -= 4; - spaces(); - c = r_getkind(&(q->t_reps)); - putc(']',f); - if (c != FIXED) { - c = (c==STAR)?'*':(c==PLUS)?'+':'?'; - putc(c,f); - } - if (c = r_getnum(&(q->t_reps))) { - fprintf(f,"%d",c); - } - newline(); - } else { - prrule(q->t_rule); - spaces(); + q = &terms[g_getcont(p)]; + if (present) prline("\n"); + fputs("[ ",f); + level += 4; + if (q->t_flags & RESOLVER) { + prline("%while (..)\n"); } + if (q->t_flags & PERSISTENT) { + prline("%persistent\n"); + } + if (r_getkind(q) != FIXED) { + printset(q->t_first, c_first); + printset(q->t_contains, c_contains); + printset(q->t_follow,c_follow); + if (q->t_flags & EMPTYFIRST) { + prline(">>> empty first\n"); + } + if (q->t_flags & EMPTYTERM) { + prline(">>> term produces empty\n"); + } + cfcheck(q->t_first,q->t_follow, + q->t_flags & RESOLVER); + } + prrule(q->t_rule); + level -= 4; + spaces(); + c = r_getkind(q); + fputs(c == STAR ? "]*" : c == PLUS ? "]+" : + c == OPT ? "]?" : "]", f); + if (c = r_getnum(q)) { + fprintf(f,"%d",c); + } + prline("\n"); break; } case ACTION : fputs("{..} ",f); @@ -362,28 +352,44 @@ prrule(p) register p_gram p; { case ALTERNATION : { register p_link l; - l = (p_link) pentry[g_getcont(p)]; - if (l->l_flag & (COND|PREFERING|AVOIDING)) { - printset(l->l_symbs,"> alt with resolver on "); - } else printset(l->l_symbs,"> alternative on "); + l = &links[g_getcont(p)]; + if (g_gettype(p-1) == ALTERNATION) { + prline("|\n"); + } + printset(l->l_symbs,"> alternative on "); cfcheck(l->l_symbs, l->l_others, (int)(l->l_flag&(COND|PREFERING|AVOIDING))); fputs(" ",f); level += 4; + if (l->l_flag & DEF) { + prline("%default\n"); + } + if (l->l_flag & AVOIDING) { + prline("%avoid\n"); + } + if (l->l_flag & PREFERING) { + prline("%prefer\n"); + } + if (l->l_flag & COND) { + prline("%if ( ... )\n"); + } prrule(l->l_rule); level -= 4; - spaces(); if (g_gettype(p+1) == EORULE) { - fputs("> end alternatives\n",f); return; } + spaces(); p++; continue; } - case TERMINAL : - PTERM(&h_entry[g_getcont(p)]); - break; + case LITERAL : + case TERMINAL : { + register p_token pt = &tokens[g_getcont(p)]; + + fprintf(f,pt->t_tokno<0400 ? + "'%s' " : "%s ", pt->t_string); + break; } case NONTERM : - fprintf(f,"%s ",(g_getnont(p)+min_nt_ent)->h_name); + fprintf(f,"%s ",nonterms[g_getnont(p)].n_name); break; } p++; @@ -401,17 +407,16 @@ cfcheck(s1,s2,flag) p_set s1,s2; { */ register p_set temp; - temp = setalloc(setsize); - setunion(temp,s1,setsize); - if (!setintersect(temp,s2,setsize)) { + temp = setalloc(); + setunion(temp,s1); + if (!setintersect(temp,s2)) { if (! flag) { printset(temp,">>> conflict on "); - newline(); + prline("\n"); } } else { if (flag) { - fputs(">>> %if/%while, no conflict",fout); - newline(); + prline(">>> %if/%while, no conflict\n"); } } free((p_mem) temp); @@ -427,18 +432,18 @@ resolve(p) register p_gram p; { case EORULE : return; case TERM : - resolve(((p_term) pentry[g_getcont(p)])->t_rule); + resolve(terms[g_getcont(p)].t_rule); break; case ALTERNATION : { register p_link l; - l = (p_link) pentry[g_getcont(p)]; + l = &links[g_getcont(p)]; if (l->l_flag & AVOIDING) { /* * On conflicting symbols, this rule * is never chosen */ - setminus(l->l_symbs,l->l_others,setsize); + setminus(l->l_symbs,l->l_others); } if (setempty(l->l_symbs)) { /* @@ -461,7 +466,7 @@ propagate(set,p) p_set set; register p_gram p; { * p will not be chosen. */ while (g_gettype(p) != EORULE) { - setminus(((p_link) pentry[g_getcont(p)])->l_symbs,set,setsize); + setminus(links[g_getcont(p)].l_symbs,set); p++; } } diff --git a/util/LLgen/src/compute.c b/util/LLgen/src/compute.c index bfdef713..00c74192 100644 --- a/util/LLgen/src/compute.c +++ b/util/LLgen/src/compute.c @@ -30,7 +30,6 @@ */ # include "types.h" -# include "tunable.h" # include "extern.h" # include "sets.h" # include "assert.h" @@ -39,31 +38,113 @@ # endif # ifndef NORCSID -static string rcsid2 = "$Header$"; +static string rcsid = "$Header$"; # endif -p_set setalloc(); +p_set get_set(); +typedef struct lngth { + /* Structure used to compute the shortest possible + * length of a terminal production of a rule. + * In case of a tie, the second field is used. + */ + int cnt; + int val; +} t_length, *p_length; /* Defined in this file : */ -extern createsets(); +extern do_compute(); +STATIC createsets(); STATIC walk(); -extern co_empty(); +STATIC co_trans(); +STATIC int nempty(); extern empty(); -extern co_first(); +STATIC int nfirst(); STATIC first(); -extern co_follow(); +STATIC int nfollow(); STATIC follow(); -extern co_symb(); STATIC co_dirsymb(); STATIC co_others(); -STATIC do_checkdefault(); -STATIC checkdefault(); -extern co_contains(); +STATIC int ncomplength(); +STATIC do_lengthcomp(); +STATIC complength(); +STATIC add(); +STATIC int compare(); +STATIC setdefaults(); STATIC do_contains(); STATIC contains(); -extern co_safes(); +STATIC int nsafes(); STATIC int do_safes(); +do_compute() { + /* + * Does all the work, by calling other routines (divide and conquer) + */ + register p_nont p; + register p_start st; + + createsets(); + co_trans(nempty); /* Which nonterminals produce empty? */ + co_trans(nfirst); /* Computes first sets */ + /* + * Compute FOLLOW sets. + * First put EOFILE in the follow set of the start nonterminals. + */ + for (st = start; st; st = st->ff_next) { + p = &nonterms[st->ff_nont]; + PUTIN(p->n_follow,0); + } + co_trans(nfollow); + /* + * Compute the sets which determine which alternative to choose + * in case of a choice + */ + for (p = nonterms; p < maxnt; p++) { + co_dirsymb(p->n_follow,p->n_rule); + } + /* + * Compute the minimum length of productions of nonterminals, + * and then determine the default choices + */ + do_lengthcomp(); + /* + * Compute the contains sets + */ + for (p = nonterms; p < maxnt; p++) do_contains(p); + for (p = nonterms; p < maxnt; p++) contains(p->n_rule, (p_set) 0); + /* + * Compute the safety of each nonterminal and term. + * The safety gives an answer to the question whether a scan is done, + * and how it should be handled. + */ + for (p = nonterms; p < maxnt; p++) { + /* + * Don't know anything yet + */ + setntsafe(p, NOSAFETY); + setntout(p, NOSAFETY); + } + for (st = start; st; st = st->ff_next) { + /* + * But start symbols are called with lookahead done + */ + p = &nonterms[st->ff_nont]; + setntsafe(p,SCANDONE); + } + co_trans(nsafes); +# ifndef NDEBUG + if (debug) { + fputs("Safeties:\n", stderr); + for (p = nonterms; p < maxnt; p++) { + fprintf(stderr, "%s\t%d\t%d\n", + p->n_name, + getntsafe(p), + getntout(p)); + } + } +# endif +} + +STATIC createsets() { /* * Allocate space for the sets @@ -71,8 +152,8 @@ createsets() { register p_nont p; for (p = nonterms; p < maxnt; p++) { - p->n_first = setalloc(setsize); - p->n_follow = setalloc(setsize); + p->n_first = get_set(); + p->n_follow = get_set(); walk(p->n_rule); } } @@ -88,16 +169,17 @@ walk(p) register p_gram p; { case TERM : { register p_term q; - q = (p_term) pentry[g_getcont(p)]; - q->t_first = setalloc(setsize); - q->t_follow = setalloc(setsize); + q = &terms[g_getcont(p)]; + q->t_first = get_set(); + q->t_follow = get_set(); walk(q->t_rule); break; } case ALTERNATION : { register p_link l; - l = (p_link) pentry[g_getcont(p)]; - l->l_symbs = setalloc(setsize); + l = &links[g_getcont(p)]; + l->l_symbs = get_set(); + l->l_others = get_set(); walk(l->l_rule); break; } case EORULE : @@ -107,23 +189,26 @@ walk(p) register p_gram p; { } } -co_empty() { - /* - * Which nonterminals produce the empty string ? - */ - register int change; - register p_nont p; +STATIC +co_trans(fc) int (*fc)(); { + register p_nont p; + register int change; - change = 1; - while (change) { + do { change = 0; - for (p=nonterms; p < maxnt; p++) { - if ((!(p->n_flags & EMPTY)) && empty(p->n_rule)) { - p->n_flags |= EMPTY; - change = 1; - } + for (p = nonterms; p < maxnt; p++) { + if ((*fc)(p)) change = 1; } + } while (change); +} + +STATIC int +nempty(p) register p_nont p; { + if (!(p->n_flags & EMPTY) && empty(p->n_rule)) { + p->n_flags |= EMPTY; + return 1; } + return 0; } empty(p) register p_gram p; { @@ -138,13 +223,13 @@ empty(p) register p_gram p; { case TERM : { register p_term q; - q = (p_term) pentry[g_getcont(p)]; - if (r_getkind(&(q->t_reps)) == STAR - || r_getkind(&(q->t_reps)) == OPT + q = &terms[g_getcont(p)]; + if (r_getkind(q) == STAR + || r_getkind(q) == OPT || empty(q->t_rule) ) break; return 0; } case ALTERNATION : - if (empty(((p_link)pentry[g_getcont(p)])->l_rule)) { + if (empty(links[g_getcont(p)].l_rule)) { return 1; } if (g_gettype(p+1) == EORULE) return 0; @@ -154,6 +239,7 @@ empty(p) register p_gram p; { break; } /* Fall through */ + case LITERAL : case TERMINAL : return 0; } @@ -161,21 +247,9 @@ empty(p) register p_gram p; { } } -co_first() { - /* - * Compute the FIRST set for each nonterminal - */ - - register p_nont p; - register int change; - - change = 1; - while (change) { - change = 0; - for (p = nonterms; p < maxnt; p++) { - if (first(p->n_first,p->n_rule,0)) change = 1; - } - } +STATIC int +nfirst(p) register p_nont p; { + return first(p->n_first, p->n_rule, 0); } STATIC @@ -185,7 +259,7 @@ first(setp,p,flag) p_set setp; register p_gram p; { * If flag = 0, also the first sets for terms and alternations in * the rule p are computed. * The FIRST set is put in setp. - * return 1 if any of the sets changed + * return 1 if the set refered to by "setp" changed */ register s; /* Will gather return value */ int noenter;/* when set, unables entering of elements into @@ -202,21 +276,25 @@ first(setp,p,flag) p_set setp; register p_gram p; { case TERM : { register p_term q; - q = (p_term) pentry[g_getcont(p)]; - if (flag == 0) s |= first(q->t_first,q->t_rule,0); - if (!noenter) s |= setunion(setp,q->t_first,setsize); + q = &terms[g_getcont(p)]; + if (flag == 0) { + if (first(q->t_first,q->t_rule,0))/*nothing*/; + } + if (!noenter) s |= setunion(setp,q->t_first); p++; - if (r_getkind(&(q->t_reps)) == STAR - || r_getkind(&(q->t_reps)) == OPT - || empty(q->t_rule) ) continue; + if (r_getkind(q) == STAR || + r_getkind(q) == OPT || + empty(q->t_rule)) continue; break; } case ALTERNATION : { register p_link l; - l = (p_link) pentry[g_getcont(p)]; - if (flag == 0) s |= first(l->l_symbs,l->l_rule,0); + l = &links[g_getcont(p)]; + if (flag == 0) { + if (first(l->l_symbs,l->l_rule,0))/*nothing*/; + } if (noenter == 0) { - s |= setunion(setp,l->l_symbs,setsize); + s |= setunion(setp,l->l_symbs); } if (g_gettype(p+1) == EORULE) return s; } @@ -224,6 +302,7 @@ first(setp,p,flag) p_set setp; register p_gram p; { case ACTION : p++; continue; + case LITERAL : case TERMINAL : if ((noenter == 0) && !IN(setp,g_getcont(p))) { s = 1; @@ -236,11 +315,8 @@ first(setp,p,flag) p_set setp; register p_gram p; { n = &nonterms[g_getnont(p)]; if (noenter == 0) { - s |= setunion(setp,n->n_first,setsize); - if (ntneeded && ! NTIN(setp,n-nonterms)) { - s = 1; - NTPUTIN(setp,n-nonterms); - } + s |= setunion(setp,n->n_first); + if (ntneeded) NTPUTIN(setp,g_getnont(p)); } p++; if (n->n_flags & EMPTY) continue; @@ -254,39 +330,17 @@ first(setp,p,flag) p_set setp; register p_gram p; { } } -co_follow() { - /* - * Compute the follow set for each nonterminal - */ - - register p_nont p; - register change; - register i; - p_start st; - - /* - * First put EOFILE in the follow set of the start symbols - */ - for (st = start; st; st = st->ff_next) PUTIN(st->ff_nont->n_follow,0); - change = 1; - i = 1; - while (change) { - change = 0; - for (p = nonterms; p < maxnt; p++) { - if (follow(p->n_follow,p->n_rule,i)) change = 1; - } - i = 0; - } +STATIC int +nfollow(p) register p_nont p; { + return follow(p->n_follow, p->n_rule); } STATIC -follow(setp,p,flag) p_set setp; register p_gram p; { +follow(setp,p) p_set setp; register p_gram p; { /* * setp is the follow set for the rule p. * Compute the follow sets in the rule p from this set. - * Return 1 if any set changed - * flag controls the use of "first" in the computation. - * It should be 1 the first time a rule is done, 0 otherwise. + * Return 1 if a follow set of a nonterminal changed. */ register s; /* Will gather return value */ @@ -298,55 +352,54 @@ follow(setp,p,flag) p_set setp; register p_gram p; { case TERM : { register p_term q; - q = (p_term) pentry[g_getcont(p)]; + q = &terms[g_getcont(p)]; if (empty(p+1)) { /* * If what follows the term can be empty, * everything that can follow the whole * rule can also follow the term */ - s |= setunion(q->t_follow,setp,setsize); + s |= setunion(q->t_follow,setp); } /* * Everything that can start the rest of the rule * can follow the term */ - if (flag) s |= first(q->t_follow,p+1,1); - if (r_getkind(&(q->t_reps)) == STAR - || r_getkind(&(q->t_reps)) == PLUS - || r_getnum(&(q->t_reps)) ) { + s |= first(q->t_follow,p+1,1); + if (r_getkind(q) == STAR || + r_getkind(q) == PLUS || + r_getnum(q) ) { /* * If the term involves a repetition * of possibly more than one, * everything that can start the term * can also follow it. */ - s |= follow(q->t_first,q->t_rule,flag); + s |= follow(q->t_first,q->t_rule); } /* * Now propagate the set computed sofar */ - s |= follow(q->t_follow, q->t_rule,flag); + s |= follow(q->t_follow, q->t_rule); break; } case ALTERNATION : /* * Just propagate setp */ - s |= follow(setp,((p_link)pentry[g_getcont(p)])->l_rule, - flag); + s |= follow(setp,links[g_getcont(p)].l_rule); break; case NONTERM : { register p_nont n; n = &nonterms[g_getnont(p)]; - if (flag) s |= first(n->n_follow,p+1,1); + s |= first(n->n_follow,p+1,1); if (empty(p+1)) { /* * If the rest of p can produce empty, * everything that follows p can follow * the nonterminal */ - s |= setunion(n->n_follow,setp,setsize); + s |= setunion(n->n_follow,setp); } break; } } @@ -354,23 +407,6 @@ follow(setp,p,flag) p_set setp; register p_gram p; { } } -co_symb() { - /* - * Compute the sets which determine which alternative to choose - * in case of a choice - * Also check the continuation grammar and see if rules do scan - * ahead. - */ - register p_nont p; - - for (p = nonterms; p < maxnt; p++) { - co_dirsymb(p->n_follow,p->n_rule); - } - for (p = nonterms; p < maxnt; p++) { - do_checkdefault(p); - } -} - STATIC co_dirsymb(setp,p) p_set setp; register p_gram p; { /* @@ -385,7 +421,7 @@ co_dirsymb(setp,p) p_set setp; register p_gram p; { case TERM : { register p_term q; - q = (p_term) pentry[g_getcont(p)]; + q = &terms[g_getcont(p)]; co_dirsymb(q->t_follow,q->t_rule); break; } case ALTERNATION : { @@ -394,15 +430,14 @@ co_dirsymb(setp,p) p_set setp; register p_gram p; { * Save first alternative */ if (!s) s = p; - l = (p_link) pentry[g_getcont(p)]; - l->l_others = setalloc(setsize); + l = &links[g_getcont(p)]; co_dirsymb(setp,l->l_rule); if (empty(l->l_rule)) { /* * If the rule can produce empty, everything * that follows it can also start it */ - setunion(l->l_symbs,setp,setsize); + setunion(l->l_symbs,setp); } if (g_gettype(p+1) == EORULE) { /* @@ -428,10 +463,10 @@ co_others(p) register p_gram p; { */ register p_link l1,l2; - l1 = (p_link) pentry[g_getcont(p)]; + l1 = &links[g_getcont(p)]; p++; - l2 = (p_link) pentry[g_getcont(p)]; - setunion(l1->l_others,l2->l_symbs,setsize); + l2 = &links[g_getcont(p)]; + setunion(l1->l_others,l2->l_symbs); if (g_gettype(p+1) != EORULE) { /* * First compute l2->l_others @@ -440,120 +475,183 @@ co_others(p) register p_gram p; { /* * and then l1->l_others */ - setunion(l1->l_others,l2->l_others,setsize); + setunion(l1->l_others,l2->l_others); } } +static p_length length; +# define INFINITY 32767 + STATIC -do_checkdefault(p) register p_nont p; { +do_lengthcomp() { /* - * check the continuation rule for nonterminal p, unless - * this is already being(!) done + * Compute the minimum length of a terminal production for each + * nonterminal. + * This length consists of two fields: the number of terminals, + * and a number that is composed of + * - the value of the first terminal + * - a crude measure of the number of terms and nonterminals in the + * production of this shortest string. */ - if (p->n_flags & BUSY) { - /* - * Error situation, recursion in continuation grammar - */ - p->n_flags ^= (RECURSIVE|BUSY); - return; + register p_length pl; + register p_nont p; + p_mem alloc(); + + length = (p_length) alloc((unsigned) (nnonterms * sizeof(*length))); + for (pl = &length[nnonterms-1]; pl >= length; pl--) { + pl->val = pl->cnt = INFINITY; } - if (p->n_flags & CONTIN) { - /* - * Was already done - */ - return; + co_trans(ncomplength); + pl = length; + for (p = nonterms; p < maxnt; p++, pl++) { + if (pl->cnt == INFINITY) { + p->n_flags |= RECURSIVE; + } + setdefaults(p->n_rule); } - /* - * Now mark it as busy, and check the rule - */ - p->n_flags |= BUSY; - checkdefault(p->n_rule); - /* - * Now release the busy mark, and mark it as done - */ - p->n_flags ^= (CONTIN|BUSY); - return; + free ((p_mem) length); +} + +STATIC int +ncomplength(p) register p_nont p; { + register p_length l; + + l = &length[p - nonterms]; + if (l->cnt == INFINITY) { + complength(p->n_rule, l); + if (l->cnt != INFINITY) return 1; + } + return 0; } STATIC -checkdefault(p) register p_gram p; { +complength(p,le) register p_gram p; register p_length le; { /* - * Walk grammar rule p, checking the continuation grammar + * Walk grammar rule p, computing minimum lengths */ register p_link l; register p_term q; + t_length i; + le->cnt = 0; + le->val = 0; for (;;) { switch (g_gettype(p)) { case EORULE : return; - case ALTERNATION : - l = (p_link) pentry[g_getcont(p)]; - if (l->l_flag & DEF) { - /* - * This alternative belongs to the - * continuation grammar, so check it - */ - checkdefault(l->l_rule); - return; - } + case LITERAL : + case TERMINAL : + if (!le->cnt) add(le, 1, g_getcont(p)); + else add(le, 1, 0); break; - case TERM : - q = (p_term) pentry[g_getcont(p)]; - /* - * First check the rest of the rule - */ - checkdefault(p+1); - /* - * Now check the term if it belongs to the - * continuation grammar - */ - if (r_getkind(&(q->t_reps))==FIXED || - r_getkind(&(q->t_reps))==PLUS) { - checkdefault(q->t_rule); - return; - } - /* - * Here we have OPT or STAR - * Only in the continuation grammar if %persistent - */ - if (q->t_flags & PERSISTENT) { - checkdefault(q->t_rule); + case ALTERNATION : + + le->cnt = INFINITY; + le->val = INFINITY; + while (g_gettype(p) != EORULE) { + l = &links[g_getcont(p)]; + complength(l->l_rule,&i); + if (l->l_flag & DEF) { + *le = i; + return; + } + if (compare(&i, le) < 0) { + *le = i; + } + p++; } return; - case NONTERM : - /* - * Check the continuation grammar for this nonterminal. - * Note that the nonterminal we are working on is - * marked as busy, so that direct or indirect recursion - * can be detected - */ - do_checkdefault(&nonterms[g_getnont(p)]); - break; + case TERM : { + register int rep; + + q = &terms[g_getcont(p)]; + rep = r_getkind(q); + if ((q->t_flags&PERSISTENT) || + rep==FIXED || rep==PLUS) { + complength(q->t_rule,&i); + add(le, i.cnt, i.val); + if (i.cnt == 0) le->val += ntokens; + if (rep == FIXED && r_getnum(q) > 0) { + for (rep = r_getnum(q) - 1; + rep > 0; rep--) { + add(le, i.cnt, i.val); + } + } + } + else { + /* Empty producing term on this path */ + le->val += ntokens; + } + break; } + case NONTERM : { + register p_length temp; + + temp = &length[g_getnont(p)]; + add(le, temp->cnt, temp->val); + if (temp->cnt == 0) { + /* Empty producing nonterminal */ + le->val += ntokens; + }} } p++; } } -co_contains() { - /* - * Compute the contains sets - */ - register p_nont p; - register p_set dummy; +STATIC +add(a, c, v) register p_length a; { - for (p = nonterms; p < maxnt; p++) do_contains(p); - dummy = setalloc(setsize); -# ifndef NDEBUG - if (debug) fputs("Contains 1 done\n", stderr); -# endif - free(dummy); - for (p = nonterms; p < maxnt; p++) contains(p->n_rule, (p_set) 0); -# ifndef NDEBUG - if (debug) fputs("Contains 2 done\n", stderr); -# endif - dummy = setalloc(setsize); - free(dummy); + if (c == INFINITY) { + a->cnt = INFINITY; + return; + } + if (a->cnt == 0) a->val = v; + a->cnt += c; +} + +STATIC int +compare(a, b) register p_length a, b; { + if (a->cnt != b->cnt) return a->cnt - b->cnt; + return a->val - b->val; +} + +STATIC +setdefaults(p) register p_gram p; { + for (;;) { + switch(g_gettype(p)) { + case EORULE: + return; + case TERM: + setdefaults(terms[g_getcont(p)].t_rule); + break; + case ALTERNATION: { + register p_link l, l1; + int temp = 0, temp1; + t_length count, i; + + count.cnt = INFINITY; + count.val = INFINITY; + l1 = &links[g_getcont(p)]; + do { + l = &links[g_getcont(p)]; + complength(l->l_rule,&i); + if (l->l_flag & DEF) temp = 1; + temp1 = compare(&i, &count); + if (temp1 < 0 || + (temp1 == 0 && l1->l_flag & AVOIDING)) { + l1 = l; + count = i; + } + setdefaults(l->l_rule); + p++; + } while (g_gettype(p) != EORULE); + if (!temp) { + /* No user specified default */ + l1->l_flag |= DEF; + } + return; } + } + p++; + } } STATIC @@ -564,7 +662,7 @@ do_contains(n) register p_nont n; { */ if (n->n_contains == 0) { - n->n_contains = setalloc(setsize); + n->n_contains = get_set(); contains(n->n_rule,n->n_contains); /* * If the rule can produce empty, delete all symbols that @@ -574,13 +672,13 @@ do_contains(n) register p_nont n; { * Otherwise, the generated parser may loop forever */ if (n->n_flags & EMPTY) { - setminus(n->n_contains,n->n_follow,setsize); + setminus(n->n_contains,n->n_follow); } /* * But the symbols that can start the rule are always * eaten */ - setunion(n->n_contains,n->n_first,setsize); + setunion(n->n_contains,n->n_first); } } @@ -596,11 +694,12 @@ contains(p,set) register p_gram p; register p_set set; { return; case TERM : { register p_term q; + int rep; - q = (p_term) pentry[g_getcont(p)]; + q = &terms[g_getcont(p)]; + rep = r_getkind(q); if ((q->t_flags & PERSISTENT) || - r_getkind(&(q->t_reps)) == PLUS || - r_getkind(&(q->t_reps)) == FIXED) { + rep == PLUS || rep == FIXED) { /* * In these cases, the term belongs to the * continuation grammar. @@ -608,44 +707,43 @@ contains(p,set) register p_gram p; register p_set set; { * q->t_first */ if (!q->t_contains) { - q->t_contains = setalloc(setsize); + q->t_contains = get_set(); } contains(q->t_rule,q->t_contains); - if (empty(q->t_rule)) { - /* - * Same trouble as mentioned in the - * routine do_contains - */ - setminus(q->t_contains,q->t_follow, - setsize); + if (rep != FIXED || empty(q->t_rule)) { + setminus(q->t_contains,q->t_follow); } - setunion(q->t_contains,q->t_first,setsize); + setunion(q->t_contains,q->t_first); } else { contains(q->t_rule, (p_set) 0); q->t_contains = q->t_first; } - if (set) setunion(set,q->t_contains,setsize); + if (set) setunion(set,q->t_contains); break; } case NONTERM : { register p_nont n; n = &nonterms[g_getnont(p)]; do_contains(n); - if(set) setunion(set, n->n_contains,setsize); + if (set) { + setunion(set, n->n_contains); + if (ntneeded) NTPUTIN(set, g_getnont(p)); + } break; } case ALTERNATION : { register p_link l; - l = (p_link) pentry[g_getcont(p)]; + l = &links[g_getcont(p)]; contains(l->l_rule, (l->l_flag & DEF) ? set : (p_set) 0); break; } + case LITERAL : case TERMINAL : { register hulp; if (set) { hulp = g_getcont(p); - assert(hulp < nterminals); + assert(hulp < ntokens); PUTIN(set,hulp); }} } @@ -653,74 +751,36 @@ contains(p,set) register p_gram p; register p_set set; { } } -static int change; +STATIC int nsafes(p) register p_nont p; { + int ch; + register int i; -co_safes() { - /* - * Compute the safety of each nonterminal and term. - * The safety gives an answer to the question whether a scan is done, - * and how it should be handled. - */ - - register p_nont p; - register i; - register p_start st; - - for (p = nonterms; p < maxnt; p++) { - /* - * Don't know anything yet - */ - setntsafe(p, NOSAFETY); - setntout(p, NOSAFETY); - } - for (st = start; st; st = st->ff_next) { - /* - * But start symbols are called with lookahead done - */ - p = st->ff_nont; - setntsafe(p,SCANDONE); - } - change = 1; - while (change) { - change = 0; - for (p = nonterms; p < maxnt; p++) { - i = getntsafe(p); - if (i == NOSAFETY) { - continue; - } - i = do_safes(p->n_rule, i); - if (getntout(p) != i) { - change = 1; - setntout(p, i); - } + ch = 0; + i = getntsafe(p); + if (i != NOSAFETY) { + i = do_safes(p->n_rule, i, &ch); + if (getntout(p) != i) { + ch = 1; + setntout(p,i); } } -# ifndef NDEBUG - if (debug) { - fputs("Safeties:\n", stderr); - for (p = nonterms; p < maxnt; p++) { - fprintf(stderr, "%s\t%d\t%d\n", - (min_nt_ent + (p - nonterms))->h_name, - getntsafe(p), - getntout(p)); - } - } -# endif + return ch; } STATIC int -do_safes(p,safe) register p_gram p; { +do_safes(p,safe,ch) register p_gram p; register int *ch; { /* * Walk the grammar rule, doing the computation described in the * comment of the procedure above this one. */ - register retval; + int retval; for (;;) { switch (g_gettype(p)) { case ACTION: p++; continue; + case LITERAL: case TERMINAL: safe = NOSCANDONE; break; @@ -728,27 +788,25 @@ do_safes(p,safe) register p_gram p; { register p_term q; int i,rep; - q = (p_term) pentry[g_getcont(p)]; - i = r_getnum(&(q->t_reps)); - rep = r_getkind(&(q->t_reps)); + q = &terms[g_getcont(p)]; + i = r_getnum(q); + rep = r_getkind(q); retval = do_safes(q->t_rule, - t_safety(rep,i,q->t_flags&PERSISTENT,safe)); - if (retval != gettout(q)) { - settout(q, retval); - } - safe = t_after(rep, i, gettout(q)); + t_safety(rep,i,q->t_flags&PERSISTENT,safe),ch); + settout(q, retval); + safe = t_after(rep, i, retval); break; } case ALTERNATION : { register p_link l; - int f, i; + register int i, f; f = 1; while (g_gettype(p) == ALTERNATION) { - l = (p_link) pentry[g_getcont(p)]; + l = &links[g_getcont(p)]; if (safe > SAFE && (l->l_flag & DEF)) { - i = do_safes(l->l_rule,SAFESCANDONE); + i = do_safes(l->l_rule,SAFESCANDONE,ch); } - else i = do_safes(l->l_rule,SAFE); + else i = do_safes(l->l_rule,SAFE,ch); if (f) retval = i; else if (i != retval) { if (i == NOSCANDONE || @@ -763,7 +821,7 @@ do_safes(p,safe) register p_gram p; { return retval; } case NONTERM : { register p_nont n; - int nsafe, osafe; + register int nsafe, osafe; n = &nonterms[g_getnont(p)]; nsafe = getntsafe(n); @@ -772,20 +830,20 @@ do_safes(p,safe) register p_gram p; { if (safe == NOSAFETY) safe = SCANDONE; if (osafe == nsafe) break; if (nsafe == NOSAFETY) { - change = 1; + *ch = 1; setntsafe(n, osafe); break; } if (osafe == NOSCANDONE || nsafe == NOSCANDONE) { if (nsafe != SCANDONE) { - change = 1; + *ch = 1; setntsafe(n, SCANDONE); } break; } if (osafe > nsafe) { setntsafe(n, osafe); - change = 1; + *ch = 1; } break; } case EORULE : @@ -797,29 +855,24 @@ do_safes(p,safe) register p_gram p; { t_safety(rep, count, persistent, safety) { + if (safety == NOSCANDONE) safety = SCANDONE; switch(rep) { default: assert(0); case OPT: - if (!persistent) return SAFE; - if (safety < SAFESCANDONE) return safety; + if (!persistent || safety < SAFESCANDONE) return SAFE; return SAFESCANDONE; case STAR: if (persistent) return SAFESCANDONE; return SAFE; case PLUS: - if (safety == NOSCANDONE) safety = SCANDONE; if (persistent) { if (safety > SAFESCANDONE) return safety; return SAFESCANDONE; } - if (safety > SAFE) return safety; - return SAFE; + return safety; case FIXED: - if (!count) { - if (safety == NOSCANDONE) safety = SCANDONE; - return safety; - } + if (!count) return safety; return SCANDONE; } /* NOTREACHED */ diff --git a/util/LLgen/src/extern.h b/util/LLgen/src/extern.h index c4f28a82..81563af5 100644 --- a/util/LLgen/src/extern.h +++ b/util/LLgen/src/extern.h @@ -29,10 +29,12 @@ * some variables that are visible in more than one file */ +# define LTEXTSZ 51 /* Size of longest token */ + /* * options for the identifier search routine */ -# define JUSTLOOKING 0 + # define ENTERING 1 # define BOTH 2 @@ -42,27 +44,22 @@ extern char ltext[]; /* input buffer */ extern int nnonterms; /* number of nonterminals */ -extern int nterminals; /* number of terminals */ +extern int ntokens; /* number of terminals */ extern p_start start; /* will contain startsymbols */ extern int linecount; /* line number */ extern int assval; /* to create difference between literals * and other terminals */ -extern t_nont nonterms[]; /* the nonterminal array */ +extern p_nont nonterms; /* the nonterminal array */ extern p_nont maxnt; /* is filled up until here */ -extern int order[]; /* order of nonterminals in the grammar, +extern p_token tokens; /* the token array */ +extern p_token maxt; /* is filled up until here */ +extern struct order *sorder, *porder; + /* order of nonterminals in the grammar, * important because actions are copied to * a temporary file in the order in which they * were read */ -extern int *maxorder; /* will contain &order[nnonterms] */ -extern t_entry h_entry[]; /* terminal and nonterminal entrys, - * first NTERMINAL entrys reserved - * for terminals - */ -extern p_entry max_t_ent; /* will contain &h_entry[nterminals] */ -# define min_nt_ent &h_entry[NTERMINALS] -extern string pentry[]; /* pointers to various allocated things */ extern string e_noopen; /* Error message string used often */ extern int verbose; /* Level of verbosity */ extern string lexical; /* name of lexical analyser */ @@ -78,9 +75,10 @@ extern int debug; extern p_file files,pfile; /* pointers to file structure. * "files" points to the start of the * list */ +extern p_file maxfiles; extern string LLgenid; /* LLgen identification string */ extern t_token lextoken; /* the current token */ extern int nerrors; -extern int fflag; /* Enable compiler to generate jump tables - * for switches? - */ +extern string rec_file, incl_file; +extern p_term terms; +extern p_link links; diff --git a/util/LLgen/src/gencode.c b/util/LLgen/src/gencode.c index c24952a3..528777e5 100644 --- a/util/LLgen/src/gencode.c +++ b/util/LLgen/src/gencode.c @@ -32,10 +32,10 @@ # include "types.h" # include "io.h" -# include "tunable.h" # include "extern.h" # include "sets.h" # include "assert.h" +# include "cclass.h" # ifndef NORCSID static string rcsid3 = "$Header$"; @@ -47,7 +47,6 @@ static string rcsid3 = "$Header$"; static string c_arrend = "0 };\n"; static string c_close = "}\n"; -static string c_LLptrmin = "LLptr++;\n"; static string c_break = "break;\n"; static string c_read = "LLread();\n"; @@ -57,10 +56,7 @@ static string c_read = "LLread();\n"; static int nlabel; /* count for the generation of labels */ static int nvar; /* count for generation of variables */ -static int pushlist[100]; -static int *ppushlist; -static int *lists,*maxlists,*plists; -p_mem ralloc(),alloc(); +static int firsts; /* are there any? */ /* In this file the following routines are defined: */ extern gencode(); @@ -75,30 +71,27 @@ STATIC controlline(); STATIC getparams(); STATIC gettok(); STATIC rulecode(); -STATIC int dopush(); -STATIC pushcode(); +STATIC int * dopush(); STATIC getaction(); +STATIC alternation(); STATIC codeforterm(); -STATIC genifhead(); +STATIC genswhead(); STATIC gencases(); STATIC genpush(); +STATIC genpop(); +STATIC genincrdecr(); -/* Macro to print a terminal */ -# define PTERM(f,p) fprintf(f,(p)->h_num<0400?"'%s'":"%s",(p)->h_name) +# define NOPOP -20000 + +p_mem alloc(); gencode(argc) { register p_file p = files; - /* Generate include file Lpars.h */ - geninclude(); - /* Set up for code generation */ if ((fact = fopen(f_temp,"r")) == NULL) { fatal(0,e_noopen,f_temp); } - lists = (int *) alloc(50 * sizeof(int)); - plists = lists; - maxlists = lists+49; /* For every source file .... */ while (argc--) { @@ -106,7 +99,7 @@ gencode(argc) { f_input = p->f_name; opentemp(f_input); /* generate code ... */ - copyfile(0); + copyfile(incl_file); generate(p); getaction(2); if (ferror(fpars) != 0) { @@ -117,6 +110,7 @@ gencode(argc) { install(genname(p->f_name),p->f_name); p++; } + geninclude(); genrecovery(); } @@ -126,86 +120,98 @@ opentemp(str) string str; { if ((fpars = fopen(f_pars,"w")) == NULL) { fatal(0,e_noopen,f_pars); } - fprintf(fpars,LLgenid,str ? str : "."); + if (!str) str = "."; + fprintf(fpars,LLgenid,str); } STATIC geninclude() { - register p_entry p; - register FILE *f; + register p_token p; opentemp((string) 0); - f = fpars; - for (p = h_entry; p < max_t_ent; p++) { - if (p->h_num >= 0400) { - fprintf(f,"# define %s %d\n", p->h_name,p->h_num); + for (p = tokens; p < maxt; p++) { + if (p->t_tokno >= 0400) { + fprintf(fpars,"# define %s %d\n", + p->t_string, + p->t_tokno); } } - if (ferror(f) != 0) { + if (ferror(fpars) != 0) { fatal(0,"write error on temporary"); } - fclose(f); - install(HFILE, (string) 0); + fclose(fpars); + install(HFILE, "."); } STATIC genrecovery() { register FILE *f; - register p_entry t; - register int i; + register p_token t; register int *q; - int index[256+NTERMINALS]; + register p_nont p; + register p_set *psetl; + int *index; + int i; register p_start st; opentemp((string) 0); f = fpars; - copyfile(0); + copyfile(incl_file); + if (!firsts) fputs("#define LLNOFIRSTS\n", f); + for (st = start; st; st = st->ff_next) { + /* Make sure that every set the parser needs is in the list + * before generating a define of the number of them! + */ + p = &nonterms[st->ff_nont]; + if (g_gettype(p->n_rule) == ALTERNATION) { + findindex(p->n_contains); + } + } + i = maxptr - setptr; + fprintf(fpars, +"#define LL_LEXI %s\n#define LL_SSIZE %d\n#define LL_NSETS %d\n#define LL_NTERMINALS %d\n", + lexical, + nbytes, + i > 0 ? i : 1, + ntokens); /* Now generate the routines that call the startsymbols */ - fputs("#define LLSTSIZ 1024\n",f); - for (i = 1, st = start; st; st = st->ff_next) { - i++; + for (st = start; st; st = st->ff_next) { fputs(st->ff_name, f); - fputs("() {\n\tint LLstack[LLSTSIZ];\n\tLLnewlevel(LLstack);\n\tLLread();\n", f); - if (g_gettype(st->ff_nont->n_rule) == ALTERNATION) { - fprintf(f, "\tLLxx.LLx_p--; *LLxx.LLx_p = %d;\n", - findindex(&(st->ff_nont->n_contains))); + p = &nonterms[st->ff_nont]; + fputs("() {\n\tunsigned int s[LL_NTERMINALS+LL_NSETS+1];\n\tLLnewlevel(s);\n\tLLread();\n", f); + if (g_gettype(p->n_rule) == ALTERNATION) { + genpush(findindex(p->n_contains)); } fprintf(f, "\tL%d_%s();\n", - st->ff_nont-nonterms, - (min_nt_ent+(st->ff_nont-nonterms))->h_name); - if (getntout(st->ff_nont) == NOSCANDONE) { + st->ff_nont, + p->n_name); + if (getntout(p) == NOSCANDONE) { fputs("\tLLscan(EOFILE);\n",f); } else fputs("\tif (LLsymb != EOFILE) LLerror(EOFILE);\n",f); - fputs("\tLLoldlevel();\n}\n",f); + fputs("\tLLoldlevel(s);\n}\n",f); } - fprintf(f,"#define LL_MAX %d\n#define LL_LEXI %s\n", i, lexical); - fputs("static short LLlists[] = {\n", f); - /* Now generate lists */ - q = lists; - while (q < plists) { - fprintf(f,"%d,\n",*q++); - } - fputs(c_arrend, f); /* Now generate the sets */ fputs("char LLsets[] = {\n",f); - for (i = 0; i < maxptr-setptr; i++) prset(setptr[i]); + for (psetl = setptr; psetl < maxptr; psetl++) prset(*psetl); fputs(c_arrend, f); - for (q = index; q <= &index[255 + NTERMINALS];) *q++ = -1; - for (t = h_entry; t < max_t_ent; t++) { - index[t->h_num] = t - h_entry; + index = (int *) alloc((unsigned) (assval * sizeof(int))); + for (q = index; q < &index[assval];) *q++ = -1; + for (t = tokens; t < maxt; t++) { + index[t->t_tokno] = t - tokens; } fputs("short LLindex[] = {\n",f); - for (q = index; q <= &index[assval-1]; q++) { + for (q = index; q < &index[assval]; q++) { fprintf(f, "%d,\n", *q); } fputs(c_arrend, f); - copyfile(1); + free((p_mem) index); + copyfile(rec_file); if (ferror(f) != 0) { fatal(0,"write error on temporary"); } fclose(f); - install(RFILE, (string) 0); + install(RFILE, "."); } STATIC @@ -213,48 +219,49 @@ generate(f) p_file f; { /* * Generates a parsing routine for every nonterminal */ - register short *s; + register p_order s; register p_nont p; - register FILE *fd; int i; - p_first ff; + register p_first ff; int mustpop; /* Generate first sets */ for (ff = f->f_firsts; ff; ff = ff->ff_next) { - macro(ff->ff_name,ff->ff_nont); + macro(ff->ff_name,&nonterms[ff->ff_nont]); } /* For every nonterminal generate a function */ - fd = fpars; - for (s = f->f_start; s <= f->f_end; s++) { - p = &nonterms[*s]; + for (s = f->f_list; s; s = s->o_next) { + p = &nonterms[s->o_index]; /* Generate functions in the order in which the nonterminals * were defined in the grammar. This is important, because * of synchronisation with the action file */ while (p->n_count--) getaction(1); - if (p->n_flags & PARAMS) controlline(); - fprintf(fd,"L%d_%s (",*s,(min_nt_ent + *s)->h_name); - if (p->n_flags & PARAMS) getparams(); - else fputs(") {\n", fd); - fputs("register struct LLxx *LLx = &LLxx;\n#ifdef lint\nLLx=LLx;\n#endif\n", fd); + fprintf(fpars,"L%d_%s (\n",s->o_index,p->n_name); + if (p->n_flags & PARAMS) { + controlline(); + getparams(); + } + else fputs(") {\n", fpars); if (p->n_flags & LOCALS) getaction(1); i = getntsafe(p); - mustpop = 0; - if (g_gettype(p->n_rule) == ALTERNATION) { - mustpop = 1; + mustpop = NOPOP; + if (g_gettype(p->n_rule) == ALTERNATION && + i > SAFESCANDONE) { + mustpop = findindex(p->n_contains); if (i == NOSCANDONE) { - fputs(c_read, fd); + fputs(c_read, fpars); i = SCANDONE; } } nlabel = 1; + nvar = 1; rulecode(p->n_rule, i, getntout(p) != NOSCANDONE, mustpop); - fputs(c_close, fd); + fputs(c_close, fpars); } } @@ -264,7 +271,7 @@ prset(p) p_set p; { register unsigned i; int j; - j = NBYTES(nterminals); + j = nbytes; for (;;) { i = (unsigned) *p++; for (k = 0; k < sizeof(int); k++) { @@ -281,17 +288,17 @@ prset(p) p_set p; { STATIC macro(s,n) string s; p_nont n; { - register FILE *f; int i; - f = fpars; - i = findindex(&(n->n_first)); - fprintf(f,"#define %s(x) ", s); + i = findindex(n->n_first); if (i < 0) { - fprintf(f, "((x) == %d)\n", -i); + fprintf(fpars, "#define %s(x) ((x) == %d)\n", + s, + tokens[-(i+1)].t_tokno); return; } - fprintf(f,"LLfirst((x), %d)\n", i); + firsts = 1; + fprintf(fpars,"#define %s(x) LLfirst((x), %d)\n", s, i); } STATIC @@ -303,8 +310,6 @@ controlline() { f1 = fact; f2 = fpars; l = getc(f1); assert(l == '\0'); - l = getc(f1); putc(l,f2); - assert( l == '#' ) ; do { l = getc(f1); putc(l,f2); @@ -318,12 +323,10 @@ getparams() { */ long off; register int l; - register FILE *f; long ftell(); char first; first = ' '; - f = fpars; /* save offset in file to be able to copy the declaration later */ off = ftell(fact); /* First pass through declaration, find the parameter names */ @@ -333,17 +336,17 @@ getparams() { * The last identifier found before a ';' or a ',' * must be a parameter */ - fprintf(f,"%c%s", first, ltext); + fprintf(fpars,"%c%s", first, ltext); first = ','; } } - fputs(") ",f); + fputs(") ",fpars); /* * Now copy the declarations */ fseek(fact,off,0); getaction(0); - fputs(" {\n",f); + fputs(" {\n",fpars); } STATIC @@ -369,13 +372,13 @@ gettok() { case EOF : return ENDDECL; default : - if (isalpha(ch) || ch == '_') { + if (c_class[ch] == ISLET) { c = ltext; - while (isalnum(ch) || ch == '_') { + do { *c++ = ch; if (c-ltext >= LTEXTSZ) --c; ch = getc(f); - } + } while (c_class[ch] == ISLET || c_class[ch] == ISDIG); if (ch != EOF) ungetc(ch,f); *c = '\0'; return IDENT; @@ -392,13 +395,27 @@ rulecode(p,safety,mustscan,mustpop) register p_gram p; { register int toplevel = 1; register FILE *f; + register int *ppu; + int pushlist[100]; + int *ppushlist; /* * First generate code to push the contains sets of this rule * on a stack */ - ppushlist = pushlist; - if (dopush(p,safety,1) > 0) pushcode(); + ppu = pushlist; + ppushlist = dopush(p,safety,1,ppu); + if (mustpop != NOPOP) for (; ppu < ppushlist; ppu++) { + if (*ppu == mustpop) { + *ppu = mustpop = NOPOP; + break; + } + } + if (g_gettype(p) != ALTERNATION) { + genpop(mustpop); + mustpop = NOPOP; + } + for (ppu = pushlist; ppu < ppushlist; ppu++) genpush(*ppu); f = fpars; for (;;) { switch (g_gettype(p)) { @@ -407,25 +424,31 @@ rulecode(p,safety,mustscan,mustpop) register p_gram p; { fputs(c_read,f); } return; + case LITERAL : case TERMINAL : { - register p_entry t; + register p_token t; + string s; - t = &h_entry[g_getcont(p)]; + t = &tokens[g_getcont(p)]; if (toplevel == 0) { - fputs(c_LLptrmin,f); + fprintf(f,"LLtdecr(%d);\n", g_getcont(p)); } if (safety == SAFE) { fputs("LL_SAFE(",f); } - else if (safety <= SCANDONE) { + else if (safety == SAFESCANDONE) { + fputs("LL_SSCANDONE(",f); + } + else if (safety == SCANDONE) { fputs("LL_SCANDONE(",f); } - else if (safety == NOSCANDONE) { + else /* if (safety == NOSCANDONE) */ { fputs("LL_T_NOSCANDONE(", f); } - PTERM(f,t); - fputs(");\n", f); - if (safety == SAFE && toplevel > 0) { + if (t->t_tokno < 0400) s = "'%s');\n"; + else s = "%s);\n"; + fprintf(f,s,t->t_string); + if (safety <= SAFESCANDONE && toplevel > 0) { safety = NOSCANDONE; toplevel = -1; p++; @@ -434,36 +457,35 @@ rulecode(p,safety,mustscan,mustpop) register p_gram p; { safety = NOSCANDONE; break; } case NONTERM : { - p_entry t; register p_nont n; - int params; n = &nonterms[g_getnont(p)]; - t= min_nt_ent+(n-nonterms); if (safety == NOSCANDONE && getntsafe(n) < NOSCANDONE) fputs(c_read, f); if (toplevel == 0 && - g_gettype(n->n_rule) != ALTERNATION) { - fputs(c_LLptrmin, f); + (g_gettype(n->n_rule) != ALTERNATION || + getntsafe(n) <= SAFESCANDONE)) { + genpop(findindex(n->n_contains)); + } + fprintf(f,"L%d_%s(\n",g_getnont(p), n->n_name); + if (g_getnpar(p)) { + controlline(); + getaction(0); } - params = g_getnpar(p); - if (params) controlline(); - fprintf(f,"L%d_%s(",n-nonterms, t->h_name); - if (params) getaction(0); fputs(");\n",f); safety = getntout(n); break; } case TERM : - safety = codeforterm((p_term) pentry[g_getcont(p)], - safety, - toplevel); + safety = codeforterm(&terms[g_getcont(p)], + safety, + toplevel); break; case ACTION : getaction(1); p++; continue; case ALTERNATION : - alternation(p, safety, mustscan,mustpop, 0); + alternation(p, safety, mustscan, mustpop, 0, 0); return; } p++; @@ -471,11 +493,11 @@ rulecode(p,safety,mustscan,mustpop) register p_gram p; { } } -alternation(p, safety, mustscan, mustpop, lb) register p_gram p; { +STATIC +alternation(p, safety, mustscan, mustpop, lb, var) register p_gram p; { register FILE *f = fpars; register p_link l; int hulp, hulp1,hulp2; - int var; int haddefault = 0; int unsafe = 1; int nsafe; @@ -483,24 +505,23 @@ alternation(p, safety, mustscan, mustpop, lb) register p_gram p; { p_set setalloc(); assert(safety < NOSCANDONE); - l = (p_link) pentry[g_getcont(p)]; + l = &links[g_getcont(p)]; hulp = nlabel++; hulp1 = nlabel++; hulp2 = nlabel++; - var = nvar++; if (!lb) lb = hulp1; if (safety <= SAFESCANDONE) unsafe = 0; - if (!unsafe && mustpop) { - mustpop = 0; - fputs(c_LLptrmin, f); + if (!unsafe) { + genpop(mustpop); + mustpop = NOPOP; } - if (unsafe) { - fprintf(f,"{ int LL_%d = 0;\n", var); - if (hulp1 == lb) fprintf(f, "L_%d: \n", hulp1); + if (unsafe && hulp1 == lb) { + var = ++nvar; + fprintf(f,"{ int LL_%d = 0;\nL_%d: \n", var, hulp1); } fputs("switch(LLcsymb) {\n", f); while (g_gettype(p) != EORULE) { - l = (p_link) pentry[g_getcont(p)]; + l = &links[g_getcont(p)]; if (unsafe && (l->l_flag & DEF)) { haddefault = 1; fprintf(f, @@ -508,19 +529,18 @@ alternation(p, safety, mustscan, mustpop, lb) register p_gram p; { var, var, lb, hulp2); } if (l->l_flag & COND) { - set = setalloc(tsetsize); - setunion(set, l->l_others, tsetsize); - setintersect(set, l->l_symbs, tsetsize); - setminus(l->l_symbs, set, tsetsize); - setminus(l->l_others, set, tsetsize); + set = setalloc(); + setunion(set, l->l_others); + setintersect(set, l->l_symbs); + setminus(l->l_symbs, set); + setminus(l->l_others, set); gencases(set); - free((p_mem) set); controlline(); fputs("if (!",f); getaction(0); fprintf(f,") goto L_%d;\n", hulp); } - if (!unsafe && (l->l_flag & DEF)) { + if (!haddefault && (l->l_flag & DEF)) { fputs("default:\n", f); haddefault = 1; } @@ -532,111 +552,91 @@ alternation(p, safety, mustscan, mustpop, lb) register p_gram p; { } if (safety != SAFE) nsafe = SAFESCANDONE; } - if (mustpop) fputs(c_LLptrmin, f); - rulecode(l->l_rule, nsafe, mustscan, 0); + rulecode(l->l_rule, nsafe, mustscan, mustpop); fputs(c_break,f); if (l->l_flag & COND) { + p++; + fprintf(f,"L_%d : ;\n",hulp); + if (g_gettype(p+1) == EORULE) { + setminus(links[g_getcont(p)].l_symbs, set); + free((p_mem) set); + continue; + } + free((p_mem) set); if (!haddefault) { fputs("default:\n", f); } else { gencases(l->l_others); - safety = SAFE; + safety = SAFE; } - fprintf(f,"L_%d : ;\n",hulp); - p++; - if (!unsafe && g_gettype(p+1) == EORULE) { - if (mustpop) fputs(c_LLptrmin, f); - rulecode(((p_link)pentry[g_getcont(p)])->l_rule, - safety,mustscan,0); + if (safety <= SAFESCANDONE) { + genpop(mustpop); + mustpop = NOPOP; } - else alternation(p,safety,mustscan,mustpop,lb); + alternation(p,safety,mustscan,mustpop,lb,var); break; } p++; } fputs(c_close, f); - if (unsafe) fputs(c_close, f); - return; + if (unsafe && hulp1 == lb) fputs(c_close, f); } -STATIC int -dopush(p,safety,toplevel) register p_gram p; { +STATIC int * +dopush(p,safety,toplevel,pp) register p_gram p; register int *pp; { /* * The safety only matters if toplevel != 0 */ - register int count = 0; for (;;) { switch(g_gettype(p)) { case EORULE : case ALTERNATION : - return count; + return pp; case TERM : { register p_term q; int rep, cnt; - q = (p_term) pentry[g_getcont(p)]; - rep = r_getkind(&(q->t_reps)); - cnt = r_getnum(&(q->t_reps)); - count += dopush(p+1,SCANDONE,0); - if (toplevel > 0 && - (rep == OPT || (rep == FIXED && cnt == 0))) { - if (safety <= SAFESCANDONE) return count; + q = &terms[g_getcont(p)]; + rep = r_getkind(q); + cnt = r_getnum(q); + if (!(toplevel > 0 && safety <= SAFESCANDONE && + (rep == OPT || (rep == FIXED && cnt == 0)))) { + *pp++ = findindex(q->t_contains); } - *ppushlist++ = findindex(&(q->t_contains)); - return count+1; } + break; } + case LITERAL : case TERMINAL : - if (toplevel > 0 && safety == SAFE) { - count += dopush(p+1,NOSCANDONE,-1); + if (toplevel > 0 && safety <= SAFESCANDONE) { + toplevel = -1; + p++; + safety = NOSCANDONE; + continue; } - else count += dopush(p+1, NOSCANDONE, 0); - if (toplevel != 0) { - return count; - } - *ppushlist++ = -h_entry[g_getcont(p)].h_num; - return count + 1; + if (toplevel == 0) *pp++ = -(g_getcont(p)+1); + break; case NONTERM : { register p_nont n; n = &nonterms[g_getnont(p)]; - count += dopush(p+1, SCANDONE, 0); if (toplevel == 0 || - g_gettype(n->n_rule) == ALTERNATION) { - *ppushlist++ = findindex(&n->n_contains); - count++; + (g_gettype(n->n_rule) == ALTERNATION && + getntsafe(n) > SAFESCANDONE)) { + *pp++ = findindex(n->n_contains); } - return count; } + break; } + case ACTION : + p++; + continue; } + toplevel = 0; + safety = NOSCANDONE; p++; } } # define max(a,b) ((a) < (b) ? (b) : (a)) -STATIC -pushcode() { - register int i,j,k; - register int *p = pushlist; - - if ((i = ppushlist - p) == 0) return; - if (i <= 2) { - genpush(p[0]); - if (i == 2) genpush(p[1]); - return; - } - fprintf(fpars,"\LLlpush(%d, %d);\n",plists-lists, i); - if (maxlists - plists < i) { - j = plists - lists; - k = maxlists-lists+max(i+1,50); - lists = (int *) ralloc( (p_mem)lists, - (unsigned)(k+1)*sizeof(int)); - plists = lists+j; - maxlists = lists+k; - } - while (i--) { - *plists++ = *p++; - } -} STATIC getaction(flag) { @@ -674,14 +674,14 @@ getaction(flag) { newline = 0; } match = ch; - putc(ch,f); - while (ch = getc(fact)) { - if (ch == match) break; + for (;;) { + putc(ch,f); + ch = getc(fact); + if (ch == match || !ch) break; if (ch == '\\') { putc(ch,f); ch = getc(fact); } - putc(ch,f); } break; case IDENT : @@ -711,35 +711,44 @@ codeforterm(q,safety,toplevel) register p_term q; { register int rep; int persistent; int ispushed; + int sw = SAFE; f = fpars; - i = r_getnum(&(q->t_reps)); - rep = r_getkind(&(q->t_reps)); - ispushed = !(toplevel > 0 && safety <= SAFESCANDONE && - (rep == OPT || (rep == FIXED && i == 0))); + i = r_getnum(q); + rep = r_getkind(q); persistent = (q->t_flags & PERSISTENT); - if (safety == NOSCANDONE && (rep != FIXED || i == 0)) { + ispushed = NOPOP; + if (!(toplevel > 0 && safety <= SAFESCANDONE && + (rep == OPT || (rep == FIXED && i == 0)))) { + ispushed = findindex(q->t_contains); + } + if (safety == NOSCANDONE && (rep != FIXED || i == 0 || + gettout(q) != NOSCANDONE)) { fputs(c_read, f); safety = SCANDONE; } - if (ispushed) { - if ((safety <= SAFESCANDONE && - (rep == OPT || (rep == FIXED && i == 0))) || - (rep == FIXED && i == 0 && - g_gettype(q->t_rule) != ALTERNATION)) { - fputs(c_LLptrmin, f); - ispushed = 0; + if (rep == PLUS && !persistent) { + int temp; + + temp = findindex(q->t_first); + if (temp != ispushed) { + genpop(ispushed); + ispushed = temp; + genpush(temp); } } if (i) { /* N > 0, so generate fixed forloop */ - fprintf(f,"{\nregister LL_i = %d;\n",i); - fputs("for (;;) {\nif (!LL_i--) {\nLLptr++;\n", f); - fputs("break;\n}\n", f); + fputs("{\nregister LL_i;\n", f); + assert(ispushed != NOPOP); + fprintf(f, "for (LL_i = %d; LL_i >= 0; LL_i--) {\n", i - 1); if (rep == FIXED) { - if (gettout(q) == NOSCANDONE && safety == NOSCANDONE) { - fputs(c_read,f); - safety = SCANDONE; + fputs("if (!LL_i) ", f); + genpop(ispushed); + genpush(ispushed); + if (safety == NOSCANDONE) { + assert(gettout(q) == NOSCANDONE); + fputs(c_read, f); } } } @@ -747,26 +756,36 @@ codeforterm(q,safety,toplevel) register p_term q; { /* '+' or '*', so generate infinite loop */ fputs("for (;;) {\n",f); } - if (rep == STAR || rep == OPT) { - genifhead(q, rep, safety, ispushed); + else if (safety <= SAFESCANDONE && rep == OPT) { + genpop(ispushed); + ispushed = NOPOP; + } + if (rep == STAR || rep == OPT) { + sw = genswhead(q, rep, i, safety, ispushed); + } + rulecode(q->t_rule, + t_safety(rep,i,persistent,safety), + gettout(q) != NOSCANDONE, + rep == FIXED ? ispushed : NOPOP); + if (gettout(q) == NOSCANDONE && rep != FIXED) { + fputs(c_read, f); } - rulecode(q->t_rule,t_safety(rep,i,persistent,safety), - rep != FIXED || gettout(q) != NOSCANDONE, - rep == FIXED && i == 0 && ispushed); /* in the case of '+', the if is after the code for the rule */ if (rep == PLUS) { - if (!persistent) { - fprintf(f, "*LLptr = %d;\n", findindex(&(q->t_first))); - /* ??? */ + if (i) { + fputs("if (!LL_i) break;\n", f); } - genifhead(q,rep,safety, ispushed); + sw = genswhead(q, rep, i, safety, ispushed); } if (rep != OPT && rep != FIXED) fputs("continue;\n", f); if (rep != FIXED) { fputs(c_close, f); /* Close switch */ + if (sw > SAFESCANDONE && (q->t_flags & RESOLVER)) { + fputs(c_close, f); + } if (rep != OPT) { - if (ispushed) fputs(c_LLptrmin, f); - fputs("break;\n", f); + genpop(ispushed); + fputs(c_break, f); } } if (rep != OPT && (rep != FIXED || i > 0)) { @@ -779,34 +798,38 @@ codeforterm(q,safety,toplevel) register p_term q; { } STATIC -genifhead(q, rep, safety, ispushed) register p_term q; { +genswhead(q, rep, cnt, safety, ispushed) register p_term q; { /* - * Generate if statement for term q + * Generate switch statement for term q */ register FILE *f; p_set p1; p_set setalloc(); - int hulp1; + int hulp1, hulp2, var; int safeterm; f = fpars; - hulp1 = nlabel++; - if (rep == PLUS) safeterm = gettout(q) <= SAFESCANDONE; - else if (rep == OPT) safeterm = safety <= SAFESCANDONE; - else /* if (rep == STAR) */ { - safeterm = safety <= SAFESCANDONE && gettout(q) <= SAFESCANDONE; + if (rep == PLUS) safeterm = gettout(q); + else if (rep == OPT) safeterm = safety; + else /* if (rep == STAR) */ safeterm = max(safety, gettout(q)); + if ((q->t_flags & RESOLVER) && safeterm > SAFESCANDONE) { + hulp2 = nlabel++; + var = nvar++; + fprintf(f, "{ int LL_%d = 0;\nL_%d : ", var, hulp2); } fputs("switch(LLcsymb) {\n", f); if (q->t_flags & RESOLVER) { - p1 = setalloc(tsetsize); - setunion(p1,q->t_first,tsetsize); - setintersect(p1,q->t_follow,tsetsize); + hulp1 = nlabel++; + p1 = setalloc(); + setunion(p1,q->t_first); + setintersect(p1,q->t_follow); /* * p1 now points to a set containing the conflicting * symbols */ - setminus(q->t_first, p1, tsetsize); - setminus(q->t_follow, p1, tsetsize); + setminus(q->t_first, p1); + setminus(q->t_follow, p1); + setminus(q->t_contains, p1); gencases(p1); free((p_mem) p1); controlline(); @@ -814,18 +837,42 @@ genifhead(q, rep, safety, ispushed) register p_term q; { getaction(0); fprintf(f, ") goto L_%d;\n", hulp1); } - gencases(q->t_follow); - if (ispushed && rep == OPT) fputs(c_LLptrmin, f); - fputs("break;\n", f); - if (!safeterm) { - fputs("default: if (!LLnext()) break;\n", f); - gencases(q->t_first); + if (safeterm <= SAFESCANDONE) fputs("default:\n", f); + else gencases(q->t_follow); + if (rep == OPT) genpop(ispushed); + fputs(c_break, f); + if (safeterm > SAFESCANDONE) { + int i; + + assert(ispushed != NOPOP); + if (ispushed >= 0) i = -ispushed; + else i = tokens[-(ispushed+1)].t_tokno; + fputs("default: if (", f); + if (q->t_flags & RESOLVER) { + fprintf(f, "LL_%d ||", var); + } + fprintf(f, "!LLnext(%d)) {\n", i); + if (rep == OPT) genpop(ispushed); + fputs(c_break, f); + fputs(c_close, f); + if (q->t_flags & RESOLVER) { + fprintf(f,"LL_%d = 1;\ngoto L_%d;\n", var, hulp2); + } } - else fputs("default: ;\n", f); + if ((q->t_flags & PERSISTENT) && safeterm != SAFE) { + gencases(q->t_contains); + } + else gencases(q->t_first); if (q->t_flags & RESOLVER) { fprintf(f, "L_%d : ;\n", hulp1); } - if (ispushed && rep == OPT) fputs(c_LLptrmin, f); + if (rep == OPT) genpop(ispushed); + if (cnt > 0) { + assert(ispushed != NOPOP); + fputs(rep == STAR ? "if (!LL_i) " : "if (LL_i == 1) ", f); + genpop(ispushed); + } + return safeterm; } STATIC @@ -845,27 +892,19 @@ gencases(setp) register p_set setp; { * labeledstatement : labels statement ; * labels : labels label | ; */ - register p_entry p; - register i; + register p_token p; + register int i; - p = h_entry; - for (i=0; i < nterminals; i++) { + for (i = 0, p = tokens; i < ntokens; i++, p++) { if (IN(setp,i)) { fprintf(fpars, - p->h_num<0400 ? "case /* '%s' */ %d : ;\n" + p->t_tokno<0400 ? "case /* '%s' */ %d : ;\n" : "case /* %s */ %d : ;\n", - p->h_name, i); + p->t_string, i); } - p++; } } -STATIC -genpush(d) { - - fprintf(fpars, "LLptr--;\n*LLptr = %d;\n",d); -} - static char namebuf[20]; STATIC string @@ -895,3 +934,23 @@ genname(s) string s; { *d = '\0'; return namebuf; } + +STATIC +genpush(d) { + genincrdecr("incr", d); +} + +STATIC +genincrdecr(s, d) string s; { + if (d == NOPOP) return; + if (d >= 0) { + fprintf(fpars, "LLs%s(%d);\n", s, d / nbytes); + return; + } + fprintf(fpars, "LLt%s(%d);\n", s, -(d + 1)); +} + +STATIC +genpop(d) { + genincrdecr("decr", d); +} diff --git a/util/LLgen/src/global.c b/util/LLgen/src/global.c index 33e8fc8b..ebd1061d 100644 --- a/util/LLgen/src/global.c +++ b/util/LLgen/src/global.c @@ -29,30 +29,28 @@ */ # include "types.h" +# include "extern.h" # include "io.h" -# include "tunable.h" # ifndef NORCSID static string rcsid4 = "$Header$"; # endif char ltext[LTEXTSZ]; -t_entry h_entry[NTERMINALS+NNONTERMS+1]; -p_entry max_t_ent; -t_nont nonterms[NNONTERMS+1]; +p_nont nonterms; +p_nont maxnt; int nnonterms; -int nterminals; -int order[NNONTERMS+1]; -int *maxorder; +p_token tokens; +p_token maxt; +int ntokens; +p_order porder, sorder; p_start start; int linecount; int assval; -string pentry[ENTSIZ]; FILE *fout; FILE *fpars; FILE *finput; FILE *fact; -p_nont maxnt; string f_pars = PARSERFILE; string f_out = OUTFILE; string f_temp = ACTFILE; @@ -66,8 +64,11 @@ int ntprint; int debug; # endif not NDEBUG p_file files; +p_file maxfiles; p_file pfile; string LLgenid = "/* LLgen generated code from source %s */\n"; t_token lextoken; int nerrors; -int fflag; +string rec_file, incl_file; +p_link links; +p_term terms; diff --git a/util/LLgen/src/io.h b/util/LLgen/src/io.h index 4c034070..617eff6e 100644 --- a/util/LLgen/src/io.h +++ b/util/LLgen/src/io.h @@ -29,7 +29,6 @@ */ # include -# include /* FILES */ diff --git a/util/LLgen/src/main.c b/util/LLgen/src/main.c index 964b08c8..c7db5a7a 100644 --- a/util/LLgen/src/main.c +++ b/util/LLgen/src/main.c @@ -38,12 +38,10 @@ static string rcsid6 = "$Header$"; # endif -static string rec_file; -static string incl_file; - /* In this file the following routines are defined: */ extern int main(); STATIC readgrammar(); +STATIC doparse(); extern error(); extern fatal(); extern comfatal(); @@ -56,11 +54,9 @@ extern badassertion(); main(argc,argv) register string argv[]; { register string arg; string libpath(); - int nflag = 0; /* Initialize */ - maxorder = order; assval = 0400; /* read options */ @@ -71,20 +67,11 @@ main(argc,argv) register string argv[]; { case 'V': verbose++; continue; - case 'n': - case 'N': - nflag++; - continue; - case 'f': - case 'F': - fflag++; - continue; # ifndef NDEBUG - case 'a': - case 'A': + case 'd': + case 'D': debug++; continue; -# endif not NDEBUG case 'r': case 'R': if (rec_file) { @@ -101,6 +88,7 @@ main(argc,argv) register string argv[]; { } incl_file = ++arg; break; +# endif not NDEBUG case 'x': case 'X': ntneeded = 1; @@ -110,7 +98,9 @@ main(argc,argv) register string argv[]; { fprintf(stderr,"illegal option : %c\n",*arg); return 1; } +# ifndef NDEBUG break; +# endif } argv++; argc--; @@ -119,46 +109,44 @@ main(argc,argv) register string argv[]; { * Now check wether the sets should include nonterminals */ if (verbose == 2) ntneeded = 1; - else if (! verbose) ntneeded = 0; /* * Initialise */ - if (!rec_file) rec_file = libpath("rec"); - if (!incl_file) incl_file = libpath("incl"); +# ifndef NDEBUG + if (!rec_file) { +# endif + rec_file = libpath("rec"); +# ifndef NDEBUG + } + if (!incl_file) { +# endif + incl_file = libpath("incl"); +# ifndef NDEBUG + } +# endif if ((fact = fopen(f_temp,"w")) == NULL) { fputs("Cannot create temporary\n",stderr); return 1; } - name_init(); + a_init(); readgrammar(argc,argv); - if (nflag) comfatal(); setinit(ntneeded); maxnt = &nonterms[nnonterms]; - max_t_ent = &h_entry[nterminals]; + maxt = &tokens[ntokens]; fclose(fact); /* * Now, the grammar is read. Do some computations */ co_reach(); /* Check for undefined and unreachable */ if (nerrors) comfatal(); - createsets(); - co_empty(); /* Which nonterminals produce empty? */ - co_first(); /* Computes first sets */ - co_follow(); /* Computes follow sets */ - co_symb(); /* Computes choice sets in alternations */ - conflchecks(); /* Checks for conflicts etc, and also - * takes care of LL.output etc - */ + do_compute(); + conflchecks(); if (nerrors) comfatal(); - co_contains(); /* Computes the contains sets */ - co_safes(); /* Computes safe terms and nonterminals. - * Safe means : always called with a terminal - * symbol that is guarantied to be eaten by - * the term - */ if (argc-- == 1) { - fputs("No code generation for input from standard input\n",stderr); - } else gencode(argc); + fputs("No code generation for input from standard input\n", + stderr); + } + else gencode(argc); UNLINK(f_temp); UNLINK(f_pars); return 0; @@ -180,32 +168,19 @@ readgrammar(argc,argv) char *argv[]; { files = p = (p_file) alloc((unsigned) (argc+1) * sizeof(t_file)); if (argc-- == 1) { finput = stdin; - p->f_name = f_input = "standard input"; - p->f_firsts = 0; - p->f_start = maxorder; - pfile = p; - LLparse(); - p->f_end = maxorder - 1; - p++; + f_input = "standard input"; + doparse(p++); } else { while (argc--) { if ((finput = fopen(f_input=argv[1],"r")) == NULL) { fatal(0,e_noopen,f_input); } - linecount = 0; - p->f_name = f_input; - p->f_start = maxorder; - p->f_firsts = 0; - pfile = p; - LLparse(); - p->f_end = maxorder-1; - p++; + doparse(p++); argv++; fclose(finput); } } - p->f_start = maxorder+1; - p->f_end = maxorder; + maxfiles = p; if (! lexical) lexical = "yylex"; /* * There must be a start symbol! @@ -216,19 +191,30 @@ readgrammar(argc,argv) char *argv[]; { if (nerrors) comfatal(); } +STATIC +doparse(p) register p_file p; { + + linecount = 0; + p->f_name = f_input; + p->f_firsts = 0; + pfile = p; + sorder = 0; + porder = 0; + LLparse(); + p->f_list = sorder; +} + /* VARARGS1 */ error(lineno,s,t,u) string s,t,u; { /* * Just an error message */ - register FILE *f; - f = stderr; ++nerrors; - if (lineno) fprintf(f,"\"%s\", line %d : ",f_input,lineno); - else fprintf(f,"\"%s\" : ",f_input); - fprintf(f,s,t,u); - putc('\n',f); + if (!lineno) lineno = 1; + fprintf(stderr,"\"%s\", line %d : ",f_input, lineno); + fprintf(stderr,s,t,u); + fputs("\n",stderr); } /* VARARGS1 */ @@ -253,16 +239,14 @@ comfatal() { exit(1); } -copyfile(n) { +copyfile(file) string file; { /* * Copies a file indicated by the parameter to filedescriptor fpars. - * If n != 0, the error recovery routines are copied, - * otherwise a standard header is. */ - register c; + register int c; register FILE *f; - if ((f = fopen(n?rec_file:incl_file,"r")) == NULL) { + if ((f = fopen(file,"r")) == NULL) { fatal(0,"Cannot open libraryfile, call an expert"); } while ((c = getc(f)) != EOF) putc(c,fpars); @@ -275,12 +259,9 @@ install(target, source) string target, source; { * if allowed (which means that the target must be generated * by LLgen from the source, or that the target is not present */ - register c; - register FILE *f1; - register FILE *f2; - register string s1; - register int i; - char buf[100]; + register int c1, c2; + register FILE *f1, *f2; + int cnt; /* * First open temporary, generated for source @@ -288,41 +269,38 @@ install(target, source) string target, source; { if ((f1 = fopen(f_pars,"r")) == NULL) { fatal(0,e_noopen,f_pars); } - i = 0; /* * Now open target for reading */ if ((f2 = fopen(target,"r")) == NULL) { - i = 1; fclose(f1); - } - else { - /* - * Create string recognised by LLgen. The target must - * start with that! - */ - (int) sprintf(buf,LLgenid,source ? source : "."); - s1 = buf; - while (*s1 != '\0' && *s1++ == getc(f2)) { /* nothing */ } - /* - * Ai,ai, it did not - */ - if (*s1 != '\0') { - fatal(0,"%s : not a file generated by LLgen",target); - } - rewind(f2); - /* - * Now compare the target with the temporary - */ - while ((c = getc(f1)) != EOF && c == getc(f2)) { /* nothing */} - if (c != EOF || getc(f2) != EOF) i = 1; - fclose(f1); - fclose(f2); + RENAME(f_pars, target); + return; } /* - * Here, if i != 0 the target must be recreated + * Compute length of LLgen identification string. The target must + * start with that! */ - if (i) RENAME(f_pars,target); + cnt = strlen(LLgenid) + strlen(source) - 2; + /* + * Now compare the target with the temporary + */ + do { + c1 = getc(f1); + c2 = getc(f2); + if (cnt >= 0) cnt--; + } while (c1 == c2 && c1 != EOF); + fclose(f1); + fclose(f2); + /* + * Here, if c1 != c2 the target must be recreated + */ + if (c1 != c2) { + if (cnt >= 0) { + fatal(0,"%s : not a file generated by LLgen",target); + } + RENAME(f_pars,target); + } } #ifndef NDEBUG diff --git a/util/LLgen/src/name.c b/util/LLgen/src/name.c index 2537b693..e9b1cf5c 100644 --- a/util/LLgen/src/name.c +++ b/util/LLgen/src/name.c @@ -25,11 +25,11 @@ /* * name.c - * Defines the symboltable search routine and an initialising routine + * Defines the symboltable search routine, a name store routine and an + * initialising routine. */ # include "types.h" -# include "tunable.h" # include "extern.h" # include "assert.h" # include "io.h" @@ -39,42 +39,68 @@ static string rcsid7 = "$Header$"; # endif # define HASHSIZE 128 +# define NMSIZ 2048 /* Room for names allocated NMSIZ bytes at a time */ -static char name[NAMESZ]; /* space for names */ -static int iname; /* index in nametable */ +static char *name, *maxname; static p_entry h_root[HASHSIZE]; /* hash table */ static string e_literal = "Illegal literal"; +static p_entry entries, maxentries; +static t_info token_info, nont_info; /* Defined in this file are: */ extern string store(); extern name_init(); STATIC int hash(); -extern t_gram search(); +STATIC p_entry newentry(); +extern p_gram search(); + +p_mem alloc(); +p_mem new_mem(); + +name_init() { + token_info.i_esize = sizeof (t_token); + token_info.i_incr = 25; + nont_info.i_esize = sizeof (t_nont); + nont_info.i_incr = 25; + search(TERMINAL,"EOFILE",ENTERING); +} + +STATIC p_entry +newentry(str, next) string str; p_entry next; { + register p_entry p; + + if ((p = entries) == maxentries) { + p = (p_entry) alloc(50 * sizeof(t_entry)); + maxentries = p + 50; + } + entries = p + 1; + p->h_name = str; + p->h_next = next; + p->h_type.g_lineno = linecount; + return p; +} string -store(s) register string s; { +store(s) string s; { /* * Store a string s in the name table */ - register string t,u; + register string s1, t ,u; - u = t = &name[iname]; - do { if (u > &name[NAMESZ-1]) fatal(linecount,"name table overflow"); - else *u++ = *s; - } while (*s++); - iname = u - name; - return t; -} - -name_init() { - /* - * Initialise hash-table and enter special terminal EOFILE - */ - register p_entry *p; - t_gram search(); - - for(p = h_root; p<= &h_root[HASHSIZE-1]; p++) *p = 0; - search(TERMINAL,"EOFILE",ENTERING); + u = name; + t = s; + s1 = u; + do { + if (u >= maxname) { + u = alloc(NMSIZ); + maxname = u + NMSIZ; + t = s; + s1 = u; + } + *u++ = *t; + } while (*t++); + name = u; + return s1; } STATIC int @@ -82,7 +108,7 @@ hash(str) string str; { /* * Compute the hash for string str */ - register i; + register int i; register string l; l = str; @@ -92,151 +118,133 @@ hash(str) string str; { return i % HASHSIZE; } -t_gram +p_gram search(type,str,option) register string str; { /* * Search for object str. * It has type UNKNOWN, LITERAL, TERMINAL or NONTERM. - * option can be ENTERING, JUSTLOOKING or BOTH. + * option can be ENTERING or BOTH (also looking). */ register int val; register p_entry p; - t_gram r; register int i; + int type1; - g_init(&r); - g_setcont(&r,UNDEFINED); - r.g_lineno = linecount; i = hash(str); /* * Walk hash chain */ for (p = h_root[i]; p != (p_entry) 0; p = p->h_next) { if(!strcmp(p->h_name,str)) { - val = p - h_entry; - if (type == LITERAL && - (val >= NTERMINALS || p->h_num >= 0400)) continue; - if (val>=NTERMINALS) { - /* Should be a nonterminal */ - if (type == TERMINAL) { - error(linecount, - "%s : terminal expected", - str); - } - g_settype(&r,NONTERM); - g_setnont(&r,val - NTERMINALS); - } else { - if (type != LITERAL && p->h_num < 0400) { + type1 = g_gettype(&(p->h_type)); + if (type1 != type) { + if (type1 == LITERAL || type == LITERAL) { continue; } - if (type == NONTERM) { + if (type != UNKNOWN) { error(linecount, - "%s : nonterminal expected", + "%s : illegal type", str); continue; } - g_setnont(&r, val); - g_settype(&r, TERMINAL); } if (option==ENTERING) { error(linecount, "%s : already defined",str); } - return r; + p->h_type.g_lineno = linecount; + return &(p->h_type); } } - if (option == JUSTLOOKING) return r; - if (type == TERMINAL || type == LITERAL) { - if (nterminals == NTERMINALS) { - fatal(linecount,"too many terminals"); - } - p = &h_entry[nterminals]; - } else { - /* - * type == NONTERM || type == UNKNOWN - * UNKNOWN and not yet declared means : NONTERM - */ - if (nnonterms == NNONTERMS) { - fatal(linecount,"too many nonterminals"); - } - p = &h_entry[NTERMINALS+nnonterms]; - } - p->h_name = store(str); - p->h_next = h_root[i]; + p = newentry(store(str), h_root[i]); h_root[i] = p; - if (type == NONTERM || type == UNKNOWN) { + if (type == TERMINAL || type == LITERAL) { + register p_token pt; + + pt = (p_token) new_mem(&token_info); + tokens = (p_token) token_info.i_ptr; + pt->t_string = p->h_name; + if (type == LITERAL) { + if (str[0] == '\\') { + /* + * Handle escapes in literals + */ + if (str[2] == '\0') { + switch(str[1]) { + case 'n' : + val = '\n'; + break; + case 'r' : + val = '\r'; + break; + case 'b' : + val = '\b'; + break; + case 'f' : + val = '\f'; + break; + case 't' : + val = '\t'; + break; + case '\'': + val = '\''; + break; + case '\\': + val = '\\'; + break; + default : + error(linecount,e_literal); + } + } else { + /* + * Here, str[2] != '\0' + */ + if (str[1] > '3' || str[1] < '0' || + str[2] > '7' || str[2] < '0' || + str[3] > '7' || str[3] < '0' || + str[4] != '\0') error(linecount,e_literal); + val = 64*str[1] - 73*'0' + + 8*str[2] + str[3]; + } + } else { + /* + * No escape in literal + */ + if (str[1] == '\0') val = str[0]; + else error(linecount,e_literal); + } + pt->t_tokno = val; + g_settype(&(p->h_type), LITERAL); + } else { + /* + * Here, type = TERMINAL + */ + pt->t_tokno = assval++; + g_settype(&(p->h_type), TERMINAL); + } + g_setcont(&(p->h_type), ntokens); + ntokens++; + return &(p->h_type); + } + /* + * type == NONTERM || type == UNKNOWN + * UNKNOWN and not yet declared means : NONTERM + */ + { register p_nont q; - q = &nonterms[nnonterms]; + q = (p_nont) new_mem(&nont_info); + nonterms = (p_nont) nont_info.i_ptr; + q->n_name = p->h_name; q->n_rule = 0; q->n_lineno = linecount; q->n_string = f_input; q->n_follow = 0; q->n_flags = 0; q->n_contains = 0; - p->h_num = 0; - g_settype(&r, NONTERM); - g_setnont(&r, nnonterms); + g_settype(&(p->h_type), NONTERM); + g_setcont(&(p->h_type), nnonterms); nnonterms++; - return r; + return &(p->h_type); } - if (type == LITERAL) { - if (str[0] == '\\') { - /* - * Handle escapes in literals - */ - if (str[2] == '\0') { - switch(str[1]) { - case 'n' : - val = '\n'; - break; - case 'r' : - val = '\r'; - break; - case 'b' : - val = '\b'; - break; - case 'f' : - val = '\f'; - break; - case 't' : - val = '\t'; - break; - case '\'': - val = '\''; - break; - case '\\': - val = '\\'; - break; - default : - error(linecount,e_literal); - } - } else { - /* - * Here, str[2] != '\0' - */ - if (str[1] > '3' || str[1] < '0' || - str[2] > '7' || str[2] < '0' || - str[3] > '7' || str[3] < '0' || - str[4] != '\0') error(linecount,e_literal); - val = 64*str[1] - 73*'0' + 8*str[2] + str[3]; - } - } else { - /* - * No escape in literal - */ - if (str[1] == '\0') val = str[0]; - else error(linecount,e_literal); - } - p->h_num = val; - } else { - /* - * Here, type = TERMINAL - */ - p->h_num = assval++; - } - g_settype(&r, TERMINAL); - g_setnont(&r, nterminals); - nterminals++; - return r; } diff --git a/util/LLgen/src/reach.c b/util/LLgen/src/reach.c index 233cc331..e2ccf159 100644 --- a/util/LLgen/src/reach.c +++ b/util/LLgen/src/reach.c @@ -29,7 +29,6 @@ * are all defined. */ -# include "tunable.h" # include "types.h" # include "extern.h" # include "io.h" @@ -51,15 +50,15 @@ co_reach() { */ register p_nont p; register p_start st; - register p_file x = files; - register int *s; + register p_file x; + register p_order s; /* Check for undefined nonterminals */ for (p = nonterms; p < maxnt; p++) { - if (! p->n_rule) { + if (! p->n_rule) { /* undefined */ f_input = p->n_string; error(p->n_lineno,"nonterminal %s not defined", - (min_nt_ent + (p - nonterms))->h_name); + p->n_name); } } /* @@ -67,17 +66,19 @@ co_reach() { * Mark the nonterminals that are encountered with the flag * REACHABLE, and walk their rules, if not done before */ - for (st = start; st; st = st->ff_next) reachable(st->ff_nont); + for (st = start; st; st = st->ff_next) { + reachable(&nonterms[st->ff_nont]); + } /* * Now check for unreachable nonterminals */ - for (; x->f_end < maxorder; x++) { + for (x = files; x < maxfiles; x++) { f_input = x->f_name; - for (s = x->f_start; s <= x->f_end; s++) { - p = &nonterms[*s]; + for (s = x->f_list; s; s = s->o_next) { + p = &nonterms[s->o_index]; if (! (p->n_flags & REACHABLE)) { error(p->n_lineno,"nonterminal %s unreachable", - (min_nt_ent + (p - nonterms))->h_name); + p->n_name); } } } @@ -107,10 +108,10 @@ reachwalk(p) register p_gram p; { for (;;) { switch(g_gettype(p)) { case ALTERNATION : - reachwalk(((p_link) pentry[g_getcont(p)])->l_rule); + reachwalk(links[g_getcont(p)].l_rule); break; case TERM : - reachwalk(((p_term) pentry[g_getcont(p)])->t_rule); + reachwalk(terms[g_getcont(p)].t_rule); break; case NONTERM : reachable(&nonterms[g_getnont(p)]); diff --git a/util/LLgen/src/sets.c b/util/LLgen/src/sets.c index c3710997..6d563c6e 100644 --- a/util/LLgen/src/sets.c +++ b/util/LLgen/src/sets.c @@ -25,8 +25,7 @@ /* * sets.c - * Some general setmanipulation routines are defined, - * and also two set allocating routines are defined + * Set manipulation and allocation routines. */ # include "types.h" @@ -41,6 +40,7 @@ static string rcsid9 = "$Header$"; /* In this file the following routines are defined: */ extern setinit(); extern p_set setalloc(); +extern p_set get_set(); extern int setunion(); extern int setintersect(); extern setminus(); @@ -48,11 +48,12 @@ extern int setempty(); extern int findindex(); extern int setcount(); -int tbitset; -int setsize,tsetsize; -p_set *setptr, *maxptr, *topptr; - -static unsigned size,nbytes; +int nbytes; +static int setsize; +int tsetsize; +p_set *setptr, *maxptr; +static t_info set_info; +p_mem alloc(); setinit(ntneeded) { /* @@ -60,84 +61,99 @@ setinit(ntneeded) { */ register int bitset; - nbytes = NBYTES(nterminals); - tbitset = ALIGN(nbytes); - tsetsize = NINTS(tbitset); - bitset = tbitset; + nbytes = NBYTES(ntokens); + bitset = ALIGN(nbytes); + tsetsize = NINTS(bitset); if (ntneeded) { /* nonterminals must be included in the sets */ bitset += NBYTES(nnonterms); } setsize = NINTS(bitset); - tbitset *= 8; + set_info.i_esize = sizeof(p_set); + set_info.i_incr = 20; } p_set -setalloc(size) int size; { +get_set() { /* - * Allocate a set of size "size" ints + * Allocate a set that cannot be freed */ - register p_set t; - register int i; - p_mem alloc(); + register p_set p, q; + static p_set sets, maxsets; - assert(size == tsetsize || size == setsize); - t = (p_set) alloc((unsigned) (size * sizeof(int))); - i = size; - t += i; - for (; i; i--) { - *--t = 0; + if ((p = sets) >= maxsets) { + q = p = (p_set) alloc((unsigned) (50*setsize*sizeof(*sets))); + maxsets = p + 50 * setsize; + do { + *q++ = 0; + } while (q < maxsets); } - return t; + sets = p + setsize;; + return p; +} + +p_set +setalloc() { + /* + * Allocate a set which can later be freed. + */ + register p_set p; + register int size = setsize; + + p = (p_set) alloc((unsigned) (size * sizeof(*p))) + size; + do { + *--p = 0; + } while (--size); + return p; } int -setunion(a,b,size) register p_set a,b; int size; { +setunion(a,b) register p_set a,b; { /* * a = a union b. * Return 1 if the set a changed */ - register i; - register j; - int nsub = 0; + register int i; + register int j; + register int nsub = 0; - assert(size == tsetsize || size == setsize); - for (i = size; i; i--) { + i = setsize; + do { *a = (j = *a) | *b++; if (*a++ != j) { nsub = 1; } - } + } while (--i); return nsub; } int -setintersect(a,b,size) register p_set a,b; int size; { +setintersect(a,b) register p_set a,b; { /* * a = a intersect b. - * return 1 if the resut is empty + * return 1 if the result is empty */ - register i; - register nempty; + register int i; + register int nempty; - assert(size == tsetsize || size == setsize); nempty = 1; - for (i = size; i; i--) { + i = setsize; + do { if (*a++ &= *b++) nempty = 0; - } + } while (--i); return nempty; } -setminus(a,b,size) register p_set a,b; int size; { +setminus(a,b) register p_set a,b; { /* * a = a setminus b */ - register i; + register int i; - assert(size == tsetsize || size == setsize); - for (i = size; i; i--) { + i = setsize; + do { *a++ &= ~(*b++); - } + } while (--i); } int @@ -145,26 +161,28 @@ setempty(p) register p_set p; { /* * Return 1 if the set p is empty */ - register i; + register int i; - for (i = tsetsize; i; i--) { + i = tsetsize; + do { if (*p++) return 0; - } + } while (--i); return 1; } int -findindex(set) p_set *set; { +findindex(set) p_set set; { /* * The set "set" will serve as a recovery set. - * Search for it in the table. If not present, enter it + * Search for it in the table. If not present, enter it. + * Here is room for improvement. At the moment, the list of + * sets is examined with linear search. */ register p_set *t; - p_mem alloc(),ralloc(); + p_mem new_mem(); register p_set a; register p_set b; - register i; - register j; + register int i; int saved; /* @@ -172,10 +190,11 @@ findindex(set) p_set *set; { */ for (t = setptr; t < maxptr; t++) { a = *t; - b = *set; - for (i = tsetsize; i; i--) { + b = set; + i = tsetsize; + do { if (*a++ != *b++) break; - } + } while (--i); if (i) continue; /* * Here, the sets are equal. @@ -186,28 +205,14 @@ findindex(set) p_set *set; { * Now check if the set consists of only one element. * It would be a waste to use a set for that */ - if (setcount(*set, &saved) == 1) return -h_entry[saved].h_num; + if (setcount(set, &saved) == 1) return -(saved + 1); /* * If it does, return its number as a negative number. */ - if (maxptr >= topptr) { - /* - * Need new space for the list, in chunks of 50 pointers - */ - if (setptr == 0) { - setptr = (p_set *) alloc(50 * sizeof(p_set)); - size = 50; - maxptr = setptr; - } else { - setptr = (p_set *) ralloc((p_mem) setptr, - (50+size)*sizeof(p_set)); - maxptr = &setptr[size-1]; - size += 50; - } - topptr = &setptr[size-1]; - } - *maxptr = setalloc(tsetsize); - setunion(*maxptr, *set, tsetsize); + maxptr = (p_set *) new_mem(&set_info); + setptr = (p_set *) set_info.i_ptr; + *maxptr = setalloc(); + setunion(*maxptr, set); return nbytes * (maxptr++ - setptr); } @@ -215,7 +220,7 @@ int setcount(set, saved) register p_set set; int *saved; { register int i, j; - for (j = 0, i = 0; i < nterminals; i++) { + for (j = 0, i = 0; i < ntokens; i++) { if (IN(set,i)) { j++; *saved = i; diff --git a/util/LLgen/src/sets.h b/util/LLgen/src/sets.h index bee31fcb..404a5c20 100644 --- a/util/LLgen/src/sets.h +++ b/util/LLgen/src/sets.h @@ -30,9 +30,9 @@ # define BITS (8 * sizeof (int)) # define IN(a,i) ((a)[(i)/BITS] & (1<<((i) % BITS))) -# define NTIN(a,i) ((a)[((i)+tbitset)/BITS]&(1<<((i)%BITS))) +# define NTIN(a,i) ((a)[(i)/BITS+tsetsize]&(1<<((i)%BITS))) # define PUTIN(a,i) ((a)[(i)/BITS] |=(1<<((i) % BITS))) -# define NTPUTIN(a,i) ((a)[((i)+tbitset)/BITS]|=(1<<((i)%BITS))) +# define NTPUTIN(a,i) ((a)[(i)/BITS+tsetsize]|=(1<<((i)%BITS))) # define NBYTES(n) (((n) + 7) / 8) /* * The next two macros operate on byte counts! @@ -40,6 +40,6 @@ # define NINTS(n) (((n) + (int) (sizeof(int) - 1)) / (int) sizeof(int)) # define ALIGN(n) (NINTS(n) * (int) sizeof (int)) -extern int tbitset; -extern p_set *setptr,*maxptr,*topptr; -extern int tsetsize,setsize; +extern int tsetsize; +extern p_set *setptr, *maxptr; +extern int nbytes; diff --git a/util/LLgen/src/tokens.g b/util/LLgen/src/tokens.g index 4f2f8567..be7d17e5 100644 --- a/util/LLgen/src/tokens.g +++ b/util/LLgen/src/tokens.g @@ -26,15 +26,15 @@ /* * tokens.g * Defines the tokens for the grammar of LLgen. - * The lexical analyser and LLmes are also included here. + * The lexical analyser and LLmessage are also included here. */ { # include "types.h" # include "io.h" -# include "tunable.h" # include "extern.h" # include "assert.h" +# include "cclass.h" # ifndef NORCSID static string rcsidc = "$Header$"; @@ -46,11 +46,12 @@ extern LLmessage(); extern int input(); extern unput(); extern skipcomment(); +# ifdef LINE_DIRECTIVE STATIC linedirective(); +# endif STATIC string cpy(); STATIC string vallookup(); } - /* Classes */ %token C_IDENT ; /* lextoken.t_string contains the identifier read */ @@ -78,17 +79,17 @@ STATIC string vallookup(); * Structure for a keyword */ -struct keyword { +typedef struct keyword { string w_word; int w_value; -}; +} t_keyw, *p_keyw; /* * The list of keywords, the most often used keywords come first. * Linear search is used, as there are not many keywords */ -static struct keyword resword[] = { +static t_keyw resword[] = { { "token", C_TOKEN }, { "avoid", C_AVOID }, { "prefer", C_PREFER }, @@ -103,108 +104,105 @@ static struct keyword resword[] = { }; static t_token savedtok; /* to save lextoken in case of an insertion */ +# ifdef LINE_DIRECTIVE static int nostartline; /* = 0 if at the start of a line */ +# endif scanner() { /* * Lexical analyser, what else */ - register ch; /* Current char */ - register i; - register reserved = 0; /* reserved word? */ + register int ch; /* Current char */ + register char *p = ltext; + int reserved = 0; /* reserved word? */ int last; /* Char before current char */ + char *max = <ext[LTEXTSZ - 1]; - if (savedtok.t_tokno) { /* - * A token has been inserted. + if (ch = savedtok.t_tokno) { + /* A token has been inserted. * Now deliver the last lextoken again */ lextoken = savedtok; savedtok.t_tokno = 0; - return lextoken.t_tokno; + return ch; } - for (;;) { /* - * First, skip space, comments, line directives, etc - */ - do ch = input(); - while(isspace(ch)); - if (ch == '/') skipcomment(0); - else if (ch == '#' && !nostartline) linedirective(); - else break; - } - /* - * Now we have a first character of a token - */ - switch(ch) { - case EOF : - return EOF; - case '\'': /* - * Literal, put it in ltext - */ - i = 0; - for (;;) { - last = ch; - ch = input(); - if (ch == '\n' || ch == EOF) { - error(linecount,"missing '"); - break; - } - if (ch == '\'' && last != '\\') break; - ltext[i] = ch; - if (i < LTEXTSZ - 1) ++i; - } - ltext[i] = '\0'; - lextoken.t_string = ltext; - return C_LITERAL; - case '%' : /* - * Start of a reserved word - */ - reserved = 1; + for (;;) { ch = input(); - /* Fall through */ - default : - i = 0; - if (isdigit(ch)) { - if (reserved) { - error(linecount," A reserved number ?"); + if (ch == EOF) return ch; +# ifdef LINE_DIRECTIVE + if (ch == '#' && !nostartline) { + linedirective(); + continue; + } +# endif + switch(c_class[ch]) { + case ISLIT : + for (;;) { + last = ch; + ch = input(); + if (ch == '\n' || ch == EOF) { + error(linecount,"missing '"); + break; + } + if (ch == '\'' && last != '\\') break; + *p++ = ch; + if (p > max) p--; } - while (isdigit(ch)) { + *p = '\0'; + lextoken.t_string = ltext; + return C_LITERAL; + case ISCOM : + skipcomment(0); + /* Fall through */ + case ISSPA : + continue; + case ISDIG : { + register i = 0; + do { i = 10 * i + (ch - '0'); ch= input(); - } + } while (c_class[ch] == ISDIG); lextoken.t_num = i; unput(ch); - return C_NUMBER; - } - if (isalpha(ch) || ch == '_') { + return C_NUMBER; } + default: + return ch; + case ISKEY : + reserved = 1; + ch = input(); + /* Fall through */ + case ISLET : do { - if (reserved && isupper(ch)) ch += 'a' - 'A'; - ltext[i] = ch; - if (i < LTEXTSZ - 1) ++i; + if (reserved && ch >= 'A' && ch <= 'Z') { + ch += 'a' - 'A'; + } + *p++ = ch; + if (p > max) p--; ch = input(); - } while (isalnum(ch) || ch == '_'); - } else return ch; - unput(ch); - } - ltext[i] = '\0'; - if (reserved) { /* - * Now search for the keyword - */ - register struct keyword *w; + } while (c_class[ch] == ISDIG || c_class[ch] == ISLET); + unput(ch); + *p = '\0'; + if (reserved) { /* + * Now search for the keyword + */ + register p_keyw w; - w = resword; - while (w->w_word) { - if (! strcmp(ltext,w->w_word)) { - /* - * Found it. Return token number. - */ - return w->w_value; + w = resword; + while (w->w_word) { + if (! strcmp(ltext,w->w_word)) { + /* + * Return token number. + */ + return w->w_value; + } + w++; + } + error(linecount,"illegal reserved word"); } - w++; + lextoken.t_string = ltext; + return C_IDENT; } - error(linecount,"illegal reserved word"); } - lextoken.t_string = ltext; - return C_IDENT; } static int backupc; /* for unput() */ @@ -215,21 +213,22 @@ input() { * Low level input routine, used by all other input routines */ register c; - register FILE *f; - if(backupc) { /* - * Last char was "unput()". Deliver it again + if (c = backupc) { + /* Last char was "unput()". Deliver it again */ - c = backupc; backupc = 0; return c; } - f = finput; - if ((c = getc(f)) == EOF) return c; + if ((c = getc(finput)) == EOF) return c; +# ifdef LINE_DIRECTIVE nostartline = 1; +# endif if (!nonline) { linecount++; +# ifdef LINE_DIRECTIVE nostartline = 0; +# endif nonline = 1; } if (c == '\n') nonline = 0; @@ -249,30 +248,29 @@ skipcomment(flag) { * of C-code, so the newlines in it must be copied to enable the * C-compiler to keep a correct line count */ - register ch; + register int ch; int saved; /* line count on which comment starts */ saved = linecount; if (input() != '*') error(linecount,"illegal comment"); - ch = input(); - while (ch != EOF) { - if (flag && ch == '\n') putc(ch,fact); + do { + ch = input(); while (ch == '*') { if ((ch = input()) == '/') return; - if (flag && ch == '\n') putc(ch,fact); } - ch = input(); - } + if (flag && ch == '\n') putc(ch,fact); + } while (ch != EOF); error(saved,"Comment does not terminate"); } +# ifdef LINE_DIRECTIVE STATIC linedirective() { /* * Read a line directive */ - register ch; - register i; + register int ch; + register int i; string s_error = "Illegal line directive"; string store(); register string c; @@ -282,17 +280,16 @@ linedirective() { * Do not skip newlines */ ch = input(); - } while (ch != '\n' && ! isdigit(ch)); + } while (ch != '\n' && c_class[ch] != ISDIG); if (ch == '\n') { error(linecount,s_error); return; } - i = ch - '0'; - ch = input(); - while (isdigit(ch)) { + i = 0; + do { i = i*10 + (ch - '0'); ch = input(); - } + } while (c_class[ch] == ISDIG); while (ch != '\n' && ch != '"') ch = input(); if (ch == '"') { c = ltext; @@ -314,13 +311,14 @@ linedirective() { } linecount = i; } +# endif STATIC string vallookup(s) { /* * Look up the keyword that has token number s */ - register struct keyword *p = resword; + register p_keyw p = resword; while (p->w_value) { if (p->w_value == s) return p->w_word; @@ -330,25 +328,24 @@ vallookup(s) { } STATIC string -cpy(s,p,flag) register s; register string p; { +cpy(s,p,inserted) register string p; { /* * Create a piece of error message for token s and put it at p. - * flag = 0 if the token s was deleted (in which case we have + * inserted = 0 if the token s was deleted (in which case we have * attributes), else it was inserted */ register string t = 0; switch(s) { case C_IDENT : - if (!flag) t = lextoken.t_string; + if (!inserted) t = lextoken.t_string; else t = "identifier"; break; case C_NUMBER : t = "number"; break; case C_LITERAL : - if (!flag) { - *p++ = '"'; + if (!inserted) { *p++ = '\''; t = lextoken.t_string; break; @@ -359,19 +356,15 @@ cpy(s,p,flag) register s; register string p; { t = "endoffile"; break; } - if (!t) { - t = vallookup(s); - if (t) { - *p++ = '%'; - } + if (!t && (t = vallookup(s))) { + *p++ = '%'; } if (t) { /* * We have a string for the token. Copy it */ while (*t) *p++ = *t++; - if (s == C_LITERAL && !flag) { + if (s == C_LITERAL && !inserted) { *p++ = '\''; - *p++ = '"'; } return p; } @@ -380,14 +373,17 @@ cpy(s,p,flag) register s; register string p; { */ *p++ = '\''; if (s >= 040 && s <= 0176) *p++ = s; - else switch(s) { - case '\b' : *p++ = '\\'; *p++ = 'b'; break; - case '\f' : *p++ = '\\'; *p++ = 'f'; break; - case '\n' : *p++ = '\\'; *p++ = 'n'; break; - case '\r' : *p++ = '\\'; *p++ = 'r'; break; - case '\t' : *p++ = '\\'; *p++ = 't'; break; - default : *p++='0'+((s&0377)>>6); *p++='0'+((s>>3)&07); - *p++='0'+(s&07); + else { + *p++ = '\\'; + switch(s) { + case '\b' : *p++ = 'b'; break; + case '\f' : *p++ = 'f'; break; + case '\n' : *p++ = 'n'; break; + case '\r' : *p++ = 'r'; break; + case '\t' : *p++ = 't'; break; + default : *p++='0'+((s&0377)>>6); *p++='0'+((s>>3)&07); + *p++='0'+(s&07); + } } *p++ = '\''; return p; diff --git a/util/LLgen/src/types.h b/util/LLgen/src/types.h index 49181bfc..6e37f27d 100644 --- a/util/LLgen/src/types.h +++ b/util/LLgen/src/types.h @@ -43,7 +43,7 @@ typedef struct token { } t_x; # define t_string t_x.t_s # define t_num t_x.t_v -} t_token; +} t_token, *p_token; /* * structure for the grammar elements @@ -74,49 +74,49 @@ typedef struct gram { # define TERMINAL 03 /* A terminal */ # define TERM 04 /* Something between square brackets */ # define ALTERNATION 05 /* Alternation (|) */ +# define LITERAL 06 /* Also a terminal */ /* * Access macros for the x-field of a grammar element */ -# define g_init(p) {(p)->x = 0;} # define g_gettype(p) (((p)->x>>13)&07) # define g_getcont(p) ((p)->x&017777) # define g_getnont(p) ((p)->x&0777) -# define g_getnpar(p) (((p)->x>>9)&07) +# define g_getnpar(p) (((p)->x>>9)&017) # define g_settype(p,s) { assert(((unsigned)(s))<=07);(p)->x=((p)->x&017777)|((s)<<13);} # define g_setcont(p,s) { assert(((unsigned)(s))<=017777);(p)->x=((p)->x&0160000)|(s);} # define g_setnont(p,s) { assert(((unsigned)(s))<=0777);(p)->x=((p)->x&0177000)|(s);} -# define g_setnpar(p,s) { assert(((unsigned)(s))<=07);(p)->x=((p)->x&0170777)|((s)<<9);} +# define g_setnpar(p,s) { assert(((unsigned)(s))<=017);(p)->x=((p)->x&0160777)|((s)<<9);} /* * Some constants to communicate with the symbol table search routine */ -# define LITERAL 01 /* Not equal to NONTERM or TERMINAL */ # define UNKNOWN 00 /* Not equal to NONTERM, TERMINAL or LITERAL */ /* * Some constants for safety */ -# define SAFE 0 -# define SAFESCANDONE 1 -# define SCANDONE 2 -# define NOSCANDONE 3 -# define NOSAFETY 4 +# define SAFE 0 /* Indicates that a scan is done, and that the + * token is correct + */ +# define SAFESCANDONE 1 /* Indicates that a scan is done, and that the + * token will not be skipped + */ +# define SCANDONE 2 /* Indicates that a scan is done */ +# define NOSCANDONE 3 /* Indicates that no scan is done */ +# define NOSAFETY 4 /* Safety not yet computed */ /* * nonterminal structure */ typedef struct { - short n_flags; /* low order three bits are reserved + short n_flags; /* low order four bits are reserved * the parameter count */ -# define getntparams(p) ((p)->n_flags&07) -# define setntparams(p,i) {assert(((unsigned)(i))<=7);(p)->n_flags&=~07;(p)->n_flags|=(i);} -# define RECURSIVE 00100 /* Set if the default rule is recursive */ -# define CONTIN 00400 /* continuation already computed? */ -# define BUSY 01000 /* or are we busy computing it? */ -# define PARAMS 02000 /* tells if a nonterminal has parameters */ -# define PRODUCE 04000 /* tells if a nonterminal produces anything */ +# define getntparams(p) ((p)->n_flags&017) +# define setntparams(p,i) {assert(((unsigned)(i))<=017);(p)->n_flags&=~017;(p)->n_flags|=(i);} +# define RECURSIVE 02000 /* Set if the default rule is recursive */ +# define PARAMS 04000 /* tells if a nonterminal has parameters */ # define EMPTY 010000 /* tells if a nonterminal produces empty */ # define LOCALS 020000 /* local declarations ? */ # define REACHABLE 040000 /* can this nonterminal be reached ? */ @@ -141,6 +141,7 @@ typedef struct { # define n_string n_x.n_s p_set n_follow; /* pointer to the "follow" set */ p_set n_contains; /* pointer to symbols that can be produced */ + string n_name; /* name of nonterminal */ } t_nont, *p_nont; /* @@ -148,7 +149,7 @@ typedef struct { */ typedef struct h_entry { string h_name; /* pointer to name */ - int h_num; /* numbering of terminals */ + t_gram h_type; /* Type and index */ struct h_entry *h_next; /* next in hash chain */ } t_entry, *p_entry; @@ -180,20 +181,19 @@ typedef short t_reps,*p_reps; # define OPT 03 /* 0 or 1 times */ /* - * Access macros for repitition + * Access macros for repitition in term */ -# define r_init(p) {*(p)=0;} -# define r_getkind(p) (*(p)&03) -# define r_getnum(p) ((*(p)>>2)&037777) -# define r_setkind(p,s) { assert(((unsigned)(s))<=03);*(p)=(*(p)&0177774)|(s);} -# define r_setnum(p,s) { assert(((unsigned)(s))<=037777);*(p)=(*(p)&03)|((s)<<2);} +# define r_getkind(q) ((q)->t_reps&03) +# define r_getnum(q) (((q)->t_reps>>2)&037777) +# define r_setkind(q,s) { assert(((unsigned)(s))<=03);(q)->t_reps=((q)->t_reps&0177774)|(s);} +# define r_setnum(q,s) { assert(((unsigned)(s))<=037777);(q)->t_reps=((q)->t_reps&03)|((s)<<2);} /* * header structure for a term */ typedef struct term { t_reps t_reps; /* repeats ? */ - short t_flags; + short t_flags; /* Low order three bits for safety */ # define gettout(q) ((q)->t_flags&07) # define settout(q,i) {assert(((unsigned)(i))<=NOSAFETY);(q)->t_flags&=~07;(q)->t_flags|=i;} # define PERSISTENT 010 /* Set if this term has %persistent */ @@ -205,7 +205,7 @@ typedef struct term { p_gram t_rule; /* pointer to this term */ p_set t_follow; /* set of followers */ p_set t_first; /* set of firsts */ - p_set t_contains; + p_set t_contains; /* contains set */ } t_term, *p_term; /* @@ -213,7 +213,7 @@ typedef struct term { */ typedef struct ff_firsts { string ff_name; /* Name of the macro */ - p_nont ff_nont; /* for this nonterminal */ + int ff_nont; /* for this nonterminal */ struct ff_firsts *ff_next; } t_first, *p_first; @@ -223,6 +223,11 @@ typedef struct ff_firsts { typedef t_first t_start; typedef p_first p_start; +typedef struct order { + int o_index; /* index in nonterminal array */ + struct order *o_next; +} t_order, *p_order; + /* * structure for file names and info */ @@ -232,11 +237,21 @@ typedef struct f_file { * generated in the target file for this * grammar file */ - short *f_start,*f_end;/* pointers in the "order" array, - * Indicating which nonterminals were defined - * in this file - */ + struct order *f_list; /* list of nonterminals in this file */ } t_file, *p_file; + +typedef struct info_alloc { + /* + * Structure used for dynamically growing arrays + */ + unsigned i_size; /* Size of the array */ + unsigned i_esize; /* Size of an element */ + unsigned i_incr; /* When filled, add room for i_incr elements */ + p_mem i_ptr; /* ptr to base of array */ + p_mem i_max; /* ptr to first free */ + p_mem i_top; /* ptr to top of array */ +} t_info, *p_info; + # ifdef NDEBUG # define STATIC static # else not NDEBUG From d9018274486f4eadf1a02434172c68ef05cd11ad Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 25 Nov 1985 15:48:42 +0000 Subject: [PATCH 0093/1625] Completely new version, generating a much faster parser --- util/LLgen/src/cclass.c | 131 ++++++++++++++++++++++++++++++++++++++++ util/LLgen/src/cclass.h | 9 +++ 2 files changed, 140 insertions(+) create mode 100644 util/LLgen/src/cclass.c create mode 100644 util/LLgen/src/cclass.h diff --git a/util/LLgen/src/cclass.c b/util/LLgen/src/cclass.c new file mode 100644 index 00000000..b3852872 --- /dev/null +++ b/util/LLgen/src/cclass.c @@ -0,0 +1,131 @@ +#include "cclass.h" +char c_class[] = { + 0, /* 00 */ + 0, /* 01 */ + 0, /* 02 */ + 0, /* 03 */ + 0, /* 04 */ + 0, /* 05 */ + 0, /* 06 */ + 0, /* 07 */ + 0, /* 010 */ + ISSPA, /* 011 */ + ISSPA, /* 012 */ + 0, /* 013 */ + ISSPA, /* 014 */ + ISSPA, /* 015 */ + 0, /* 016 */ + 0, /* 017 */ + 0, /* 020 */ + 0, /* 021 */ + 0, /* 022 */ + 0, /* 023 */ + 0, /* 024 */ + 0, /* 025 */ + 0, /* 026 */ + 0, /* 027 */ + 0, /* 030 */ + 0, /* 031 */ + 0, /* 032 */ + 0, /* 033 */ + 0, /* 034 */ + 0, /* 035 */ + 0, /* 036 */ + 0, /* 037 */ + ISSPA, /* ' ' */ + 0, /* '!' */ + 0, /* '"' */ + 0, /* '#' */ + 0, /* '$' */ + ISKEY, /* '%' */ + 0, /* '&' */ + ISLIT, /* ''' */ + ISTOK, /* '(' */ + ISTOK, /* ')' */ + ISTOK, /* '*' */ + ISTOK, /* '+' */ + ISTOK, /* ',' */ + 0, /* '-' */ + 0, /* '.' */ + ISCOM, /* '/' */ + ISDIG, /* '0' */ + ISDIG, /* '1' */ + ISDIG, /* '2' */ + ISDIG, /* '3' */ + ISDIG, /* '4' */ + ISDIG, /* '5' */ + ISDIG, /* '6' */ + ISDIG, /* '7' */ + ISDIG, /* '8' */ + ISDIG, /* '9' */ + ISTOK, /* ':' */ + ISTOK, /* ';' */ + 0, /* '<' */ + 0, /* '=' */ + 0, /* '>' */ + ISTOK, /* '?' */ + 0, /* '@' */ + ISLET, /* 'A' */ + ISLET, /* 'B' */ + ISLET, /* 'C' */ + ISLET, /* 'D' */ + ISLET, /* 'E' */ + ISLET, /* 'F' */ + ISLET, /* 'G' */ + ISLET, /* 'H' */ + ISLET, /* 'I' */ + ISLET, /* 'J' */ + ISLET, /* 'K' */ + ISLET, /* 'L' */ + ISLET, /* 'M' */ + ISLET, /* 'N' */ + ISLET, /* 'O' */ + ISLET, /* 'P' */ + ISLET, /* 'Q' */ + ISLET, /* 'R' */ + ISLET, /* 'S' */ + ISLET, /* 'T' */ + ISLET, /* 'U' */ + ISLET, /* 'V' */ + ISLET, /* 'W' */ + ISLET, /* 'X' */ + ISLET, /* 'Y' */ + ISLET, /* 'Z' */ + ISTOK, /* '[' */ + 0, /* '\' */ + ISTOK, /* ']' */ + 0, /* '^' */ + ISLET, /* '_' */ + 0, /* '`' */ + ISLET, /* 'a' */ + ISLET, /* 'b' */ + ISLET, /* 'c' */ + ISLET, /* 'd' */ + ISLET, /* 'e' */ + ISLET, /* 'f' */ + ISLET, /* 'g' */ + ISLET, /* 'h' */ + ISLET, /* 'i' */ + ISLET, /* 'j' */ + ISLET, /* 'k' */ + ISLET, /* 'l' */ + ISLET, /* 'm' */ + ISLET, /* 'n' */ + ISLET, /* 'o' */ + ISLET, /* 'p' */ + ISLET, /* 'q' */ + ISLET, /* 'r' */ + ISLET, /* 's' */ + ISLET, /* 't' */ + ISLET, /* 'u' */ + ISLET, /* 'v' */ + ISLET, /* 'w' */ + ISLET, /* 'x' */ + ISLET, /* 'y' */ + ISLET, /* 'z' */ + ISTOK, /* '{' */ + ISTOK, /* '|' */ + ISTOK, /* '}' */ + 0, /* '~' */ + 0 /* 0177 */ +}; diff --git a/util/LLgen/src/cclass.h b/util/LLgen/src/cclass.h new file mode 100644 index 00000000..890ad4a6 --- /dev/null +++ b/util/LLgen/src/cclass.h @@ -0,0 +1,9 @@ +extern char c_class[]; + +#define ISLET 1 +#define ISDIG 2 +#define ISSPA 3 +#define ISKEY 4 +#define ISTOK 5 +#define ISCOM 6 +#define ISLIT 7 From 31a4215cab498c48746bf20ca08642cd5cd86ce9 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 25 Nov 1985 15:50:19 +0000 Subject: [PATCH 0094/1625] New version, much faster --- util/LLgen/lib/rec | 292 ++++++++++++++++++--------------------------- 1 file changed, 113 insertions(+), 179 deletions(-) diff --git a/util/LLgen/lib/rec b/util/LLgen/lib/rec index 4403149f..eff58df1 100644 --- a/util/LLgen/lib/rec +++ b/util/LLgen/lib/rec @@ -3,215 +3,149 @@ * This file is copied into Lpars.c. */ -# ifndef NORCSID +# ifndef lint static char *rcsid = "$Header$"; # endif -#define LLSTSIZ 1024 -static short LLstack[LLSTSIZ]; /* Recovery stack */ -short * LLptr; /* ptr in it */ -#define LLmax (&LLstack[LLSTSIZ-1]) /* if beyond this, overflow */ -int LLscd; /* lookahead done or not? */ -int LLb,LLi; -int LLsymb; -int LLcsymb; -static int LLlevel; -static short * LLbase; +# ifdef LL_DEBUG +# include +# endif -static struct LLsaved { - int LLs_i, LLs_b, LLs_s, LLs_c, LLs_t; - short *LLs_p, *LLs_x; -} LLsaved[LL_MAX]; +int LLsymb; +unsigned int LLtcnt[LL_NTERMINALS]; +unsigned int LLscnt[LL_NSETS]; +int LLcsymb, LLsymb; +static int LLlevel; /* In this file are defined: */ -extern LLcheck(); +extern LLread(); +extern int LLskip(); +extern int LLnext(); extern LLscan(); -extern LLpush(); -extern LLlpush(); -extern int LLpop(); -extern int LLsskip(); -static LLerror(); +extern LLerror(); +# ifndef LLNOFIRSTS +extern int LLfirst(); +# endif extern LLnewlevel(); extern LLoldlevel(); -LLcheck() { - register c; - /* - * The symbol to be checked is on the stack. - */ - if (!LLscd) { - if ((c = LL_LEXI()) <= 0) c = EOFILE; - LLsymb = c; - } - else LLscd = 0; - if (LLsymb == *--LLptr) return; - /* - * If we come here, an error has been detected. - * LLpop will try and recover - */ - LLptr++; - while (LLindex[LLsymb] < 0) { - LLerror(0); - if ((LLsymb = LL_LEXI()) <= 0) LLsymb = EOFILE; - } - LLcsymb = LLindex[LLsymb]; - LLb = LLbyte[LLcsymb]; - LLi = LLcsymb>>3; - LLscd = 1; - if (!LLpop()) LLerror(*LLptr); - LLscd = 0; -} - LLscan(t) { /* * Check if the next symbol is equal to the parameter */ - if (!LLscd) { - if ((LLsymb = LL_LEXI()) <= 0) LLsymb = EOFILE; + if ((LLsymb = LL_LEXI()) <= 0) LLsymb = EOFILE; + if (LLsymb == t) { + return; } - else LLscd = 0; - if (LLsymb == t) return; /* * If we come here, an error has been detected */ - LLpush(t); - LLscd = 1; - while (LLindex[LLsymb] < 0) { - LLerror(0); - if ((LLsymb = LL_LEXI()) <= 0) LLsymb = EOFILE; - } - LLcsymb = LLindex[LLsymb]; - LLb = LLbyte[LLcsymb]; - LLi = LLcsymb>>3; - if (!LLpop()) LLerror(t); - LLscd = 0; + LLerror(t); } -LLpush(t) { - if (LLptr == LLmax) { - LLerror(-1); - } - *LLptr++ = t; -} - -LLlpush(d) { - register i; - register short *p; - - p = &LLlists[d]; - i = *p++; - while(i--) { - if (LLptr == LLmax) { - LLerror(-1); - } - *LLptr++ = *p++; - } -} - -LLsskip() { - /* - * Error recovery, and not only that! - * Skip symbols until one is found that is on the stack. - * Return 1 if it is on top of the stack - */ - register short *t; - register i; - +LLread() { for (;;) { - if (!LLscd) { -lab: - if ((i = LL_LEXI()) <= 0) i = EOFILE; - LLsymb = i; - if ((i = LLindex[i]) < 0) { - LLerror(0); - goto lab; - /* - * Ugly, but we want speed - * on possibly correct symbols !! - * So, no breaks out of "for (;;)" - */ + if ((LLsymb = LL_LEXI()) <= 0) LLsymb = EOFILE; + if ((LLcsymb = LLindex[LLsymb]) >= 0) return; + LLmessage(0); + } + /* NOTREACHED */ +} + +LLerror(t) { + register int i; + + if ((LLcsymb = LLindex[LLsymb]) < 0) { + LLmessage(0); + LLread(); + } + i = LLindex[t]; + LLtcnt[i]++; + if (LLskip()) /* nothing */; + LLtcnt[i]--; + if (LLsymb != t) LLmessage(t); +} + +# ifndef LLNOFIRSTS +LLfirst(x, d) { + register int i; + + return (i = LLindex[x]) >= 0 && + (LLsets[d + (i >> 3)] & (1 << (i & 07))); +} +# endif + +LLnext(n) { + + if (LLskip()) /* nothing */; + if (n <= 0) return (LLsets[(LLcsymb >> 3) - n] & (1 << (LLcsymb & 07))); + return LLsymb == n; +} + +LLskip() { + register int i; + int retval; + int LLi, LLb; + + retval = 0; + for (;;) { + if (LLtcnt[LLcsymb] != 0) return retval; + LLi = LLcsymb >> 3; + LLb = 1 << (LLcsymb & 07); + for (i = LL_NSETS - 1; i >= 0; i--) { + if (LLscnt[i] != 0) { + if (LLsets[LL_SSIZE*i+LLi] & LLb) return retval; } - LLcsymb = i; - LLb = LLbyte[i]; - LLi = (i>>3); - LLscd = 1; } - t = LLptr-1; - i = *t; - if (!((i<=0 && LLsets[LLi-i]&LLb)||i==LLsymb)) { - while (--t >= LLbase) { - /* - * If the element on the stack is negative, - * its opposite is an index in the setarray, - * otherwise it is a terminal symbol - */ - i = *t; - if ((i<=0&&LLsets[LLi-i]&LLb)||i==LLsymb){ - break; - } - } - if (t >= LLbase) break; - LLerror(0); - LLscd = 0; + retval = 1; + LLmessage(0); + LLread(); + } + /* NOTREACHED */ +} + +LLnewlevel(LLsinfo) unsigned int *LLsinfo; { + register int i; + + if (LLlevel++) { + LLsinfo[LL_NSETS+LL_NTERMINALS] = (unsigned) LLsymb; + LLsinfo[LL_NSETS+LL_NTERMINALS+1] = (unsigned) LLcsymb; + for (i = LL_NTERMINALS - 1; i >= 0; i--) { + LLsinfo[i] = LLtcnt[i]; + LLtcnt[i] = 0; } - else { - return 1; + for (i = LL_NSETS - 1; i >= 0; i--) { + LLsinfo[LL_NTERMINALS+i] = LLscnt[i]; + LLscnt[i] = 0; } } - return t == LLptr - 1; + LLtincr(0); } -LLpop() { - register i; +LLoldlevel(LLsinfo) unsigned int *LLsinfo; { + register int i; - i = LLsskip(); - LLptr--; - return i; -} - -static -LLerror(d) { - - LLmessage(d); - if (d < 0) exit(1); -} - -LLnewlevel() { - register struct LLsaved *p; - - if (!LLlevel++) { - LLptr = LLstack; - LLbase = LLstack; - LLpush(EOFILE); - } - else { - if (LLlevel > LL_MAX) LLerror(-1); - p = &LLsaved[LLlevel - 2]; - p->LLs_p = LLptr; - p->LLs_i = LLi; - p->LLs_b = LLb; - p->LLs_s = LLsymb; - p->LLs_t = LLcsymb; - p->LLs_c = LLscd; - p->LLs_x = LLbase; - LLbase = LLptr; - LLpush(EOFILE); - } -} - -LLoldlevel() { - register struct LLsaved *p; - - LLcheck(); + LLtdecr(0); +# ifdef LL_DEBUG + for (i = 0; i < LL_NTERMINALS; i++) LL_assert(LLtcnt[i] == 0); + for (i = 0; i < LL_NSETS; i++) LL_assert(LLscnt[i] == 0); +# endif if (--LLlevel) { - p = &LLsaved[LLlevel-1]; - LLptr = p->LLs_p; - LLi = p->LLs_i; - LLb = p->LLs_b; - LLsymb = p->LLs_s; - LLcsymb = p->LLs_t; - LLbase = p->LLs_x; - LLscd = p->LLs_c; + for (i = LL_NSETS - 1; i >= 0; i--) { + LLscnt[i] = LLsinfo[LL_NTERMINALS+i]; + } + for (i = LL_NTERMINALS - 1; i >= 0; i--) { + LLtcnt[i] = LLsinfo[i]; + } + LLsymb = (int) LLsinfo[LL_NSETS+LL_NTERMINALS]; + LLcsymb = (int) LLsinfo[LL_NSETS+LL_NTERMINALS+1]; } } +# ifdef LL_DEBUG +LL_badassertion(asstr,file,line) char *asstr, *file; { + + fprintf(stderr,"Assertion \"%s\" failed %s(%d)\n",asstr,file,line); + abort(); +} +# endif From 0d8959325e423d1e07f015d9b92be076739c69c1 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 25 Nov 1985 15:50:51 +0000 Subject: [PATCH 0095/1625] New version, with a much faster parser. --- util/LLgen/lib/incl | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/util/LLgen/lib/incl b/util/LLgen/lib/incl index 237ee69e..9ce5edd5 100644 --- a/util/LLgen/lib/incl +++ b/util/LLgen/lib/incl @@ -1,12 +1,26 @@ /* $Header$ */ +#ifdef LL_DEBUG +#define LL_assert(x) if(!(x)) LL_badassertion("x",__FILE__,__LINE__) +#else +#define LL_assert(x) /* nothing */ +#endif -#define LLin(x) (LLsets[(x)+LLi]&LLb) - -extern short *LLptr; -extern char LLsets[]; -extern int LLi, LLb; extern int LLsymb; -extern int LLcsymb; -extern int LLscd; +extern char LLsets[]; + +#define LL_SAFE(x) /* Nothing */ +#define LL_SSCANDONE(x) if (LLsymb != x) LLmessage(x); else +#define LL_SCANDONE(x) if (LLsymb != x) LLerror(x); else +#define LL_T_NOSCANDONE(x) LLscan(x) # include "Lpars.h" + +extern unsigned int LLscnt[]; +extern unsigned int LLtcnt[]; +extern int LLcsymb; +extern int LL_symb; + +#define LLsdecr(d) {LL_assert(LLscnt[d] > 0); LLscnt[d]--;} +#define LLtdecr(d) {LL_assert(LLtcnt[d] > 0); LLtcnt[d]--;} +#define LLsincr(d) LLscnt[d]++ +#define LLtincr(d) LLtcnt[d]++ From 6bcb797733cb9bad136f61beaadc2460157391d5 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 25 Nov 1985 15:52:56 +0000 Subject: [PATCH 0096/1625] New version of LLgen, new version of this Makefile ... --- util/LLgen/Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/util/LLgen/Makefile b/util/LLgen/Makefile index 54fc56f9..2c941488 100644 --- a/util/LLgen/Makefile +++ b/util/LLgen/Makefile @@ -27,4 +27,3 @@ opr: pr: @cd src; make pr - @pr lib/incl lib/rec From 58588da699b939c5c5282e73cf2073298f451266 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 25 Nov 1985 15:57:43 +0000 Subject: [PATCH 0097/1625] Changed dependancies --- util/LLgen/src/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/util/LLgen/src/Makefile b/util/LLgen/src/Makefile index 1c9708a2..39e9fe82 100644 --- a/util/LLgen/src/Makefile +++ b/util/LLgen/src/Makefile @@ -46,6 +46,7 @@ LLgen.o: types.h Lpars.o: Lpars.h alloc.o: extern.h alloc.o: types.h +cclass.o: cclass.h check.o: assert.h check.o: extern.h check.o: io.h From d74f1ba9df96092a4c5442205cc8b6d702106f47 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 25 Nov 1985 16:00:18 +0000 Subject: [PATCH 0098/1625] New manual page for a completely new version of LLgen. --- util/LLgen/LLgen.1 | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/util/LLgen/LLgen.1 b/util/LLgen/LLgen.1 index b91d0417..622a11a6 100644 --- a/util/LLgen/LLgen.1 +++ b/util/LLgen/LLgen.1 @@ -5,7 +5,7 @@ LLgen, an extended LL(1) parser generator .SH SYNOPSIS \fBLLgen\fP [ -\fB\-vVxXfF\fP +\fB\-vVxX\fP ] file ... .SH DESCRIPTION @@ -84,15 +84,6 @@ the sets that are computed are extended with the nonterminal symbols and these extended sets are also included in the \fILL.output\fP file. -.PP -If the -\fB\-f\fP -or the -\fB\-F\fP -flag is given, -\fILLgen\fP generates code, that enables the C-compiler to generate jump- -tables for switches. This option should only be used when a large address -space is available. .SH FILES LL.output verbose output file .br From 994eccc0ebe634e39923821323748a1aebdb9f42 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 25 Nov 1985 16:26:59 +0000 Subject: [PATCH 0099/1625] Remove targets before installing new ones --- util/LLgen/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/util/LLgen/Makefile b/util/LLgen/Makefile index 2c941488..deea77f0 100644 --- a/util/LLgen/Makefile +++ b/util/LLgen/Makefile @@ -9,6 +9,7 @@ clean: install: cd src; make + rm -f $(INSTALLDIR)/LLgen $(LIBDIR)/rec $(LIBDIR)/incl cp src/LLgen $(INSTALLDIR)/LLgen cp lib/rec $(LIBDIR)/rec cp lib/incl $(LIBDIR)/incl From 69caad4b6c08f7f27f56c37343817f94880cbe40 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 26 Nov 1985 13:27:51 +0000 Subject: [PATCH 0100/1625] A minor change in the LL.output format. --- util/LLgen/src/check.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/util/LLgen/src/check.c b/util/LLgen/src/check.c index 5c937c4e..82ce9867 100644 --- a/util/LLgen/src/check.c +++ b/util/LLgen/src/check.c @@ -301,6 +301,7 @@ prrule(p) register p_gram p; { */ register FILE *f; int present = 0; + int firstalt = 1; f = fout; for (;;) { @@ -323,8 +324,15 @@ prrule(p) register p_gram p; { prline("%persistent\n"); } if (r_getkind(q) != FIXED) { + if (!(q->t_flags & PERSISTENT)) { + prline("> continue repetition on the\n"); + } printset(q->t_first, c_first); + if (q->t_flags & PERSISTENT) { + prline("> continue repetition on the\n"); + } printset(q->t_contains, c_contains); + prline("> terminate repetition on the\n"); printset(q->t_follow,c_follow); if (q->t_flags & EMPTYFIRST) { prline(">>> empty first\n"); @@ -353,9 +361,10 @@ prrule(p) register p_gram p; { register p_link l; l = &links[g_getcont(p)]; - if (g_gettype(p-1) == ALTERNATION) { - prline("|\n"); + if (firstalt) { + firstalt = 0; } + else prline("|\n"); printset(l->l_symbs,"> alternative on "); cfcheck(l->l_symbs, l->l_others, From 8c0e3a58f60735398dae3cbc74301761cd08aff0 Mon Sep 17 00:00:00 2001 From: sater Date: Mon, 2 Dec 1985 13:55:06 +0000 Subject: [PATCH 0101/1625] Corrected error in otime of initialisation of booleans --- util/ncgg/cgg.y | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/util/ncgg/cgg.y b/util/ncgg/cgg.y index 34af468e..1fca1cc0 100644 --- a/util/ncgg/cgg.y +++ b/util/ncgg/cgg.y @@ -640,9 +640,11 @@ optsecondstring ; onepattern - : { inithall(); startline=lineno; tokpatlen=0; } + : { inithall(); startline=lineno; + tokpatlen=0; optexact=0; optstack=0; + } kills allocates generates yields leaving - { optexact=0; optstack=0; + { patindex[npatterns++]=codeindex; checkhall(); dopattern(0,$2,$3,$4,$5,$6); From 5ac7451566011725e51dcc846d49df181fbdccac Mon Sep 17 00:00:00 2001 From: sater Date: Wed, 4 Dec 1985 15:52:51 +0000 Subject: [PATCH 0102/1625] Changed to be printed on laserprinter. Removed paragraph about bug, since bug is now solved --- doc/ncg.doc | 347 ++++++++++++++++++++++++++-------------------------- 1 file changed, 173 insertions(+), 174 deletions(-) diff --git a/doc/ncg.doc b/doc/ncg.doc index e43fc781..16614b87 100644 --- a/doc/ncg.doc +++ b/doc/ncg.doc @@ -57,7 +57,7 @@ and the assembly code of the machine at hand. .NH 1 What has changed since version 1 ? .PP -This chapter can be skipped by anyone not familiar with the first version. +This section can be skipped by anyone not familiar with the first version. It is not needed to understand the current version. .PP This paper describes the second version of the code generator system. @@ -116,39 +116,40 @@ Alternatively one can think of the real stack as an infinite extension at the bottom of the fake stack. Both ways, the concatenation of the real stack and the fake stack will be the stack as it would have been on a real EM machine (see figure). -.KF -.DS L -.ta 8 16 24 32 40 48 56 64 72 - EM machine target machine - - | | | | - | | | | - | | | | - | | | | - | | | real stack | - | | | | | - | | | | | growing - | EM stack | | | | - | | |_______________| \e|/ - | | | | - | | | | - | | | | - | | | fake stack | - | | | | - |_______________| |_______________| +.TS +center; +cw(3.5c) cw(3c) cw(3.5c) +cw(3.5c) cw(3c) cw(3.5c) +|cw(3.5c)| cw(3c) |cw(3.5c)| . +EM machine target machine -.I - Relation between EM stack, real stack and fake stack. -.R -.DE -.KE + + + + real stack + stack + grows +EM stack \s+2\(br\s0 + \s+2\(br\s0 + \s+2\(br\s0 _ + \s+2\(br\s0 + \s+2\(da\s0 + fake stack + + + +_ _ +.T& +ci s s. +Relation between EM stack, real stack and fake stack. +.TE During code generation tokens will be kept on the fake stack as long as possible but when they are moved to the real stack, by generating code for the push, -all tokens above\u*\d +all tokens above\v'-.25m'\(dg\v'.25m' .FS -* in this document the stack is assumed to grow downwards, +\(dg in this document the stack is assumed to grow downwards, although the top of the stack will mean the first element that will be popped. .FE @@ -297,8 +298,9 @@ at will to improve legibility. Identifiers used in the table have the same syntax as C identifiers, upper and lower case considered different, all characters significant. Here is a list of reserved words; all of these are unavailable as identifiers. -.DS L -.ta 14 28 42 56 +.TS +box; +l l l l l. ADDR STACK from reg_any test COERCIONS STACKINGRULES gen reg_float to INSTRUCTIONS TESTS highw reg_loop ufit @@ -309,7 +311,7 @@ PROPERTIES cost loww reusing REGISTERS defined move rom SETS exact pat samesign SIZEFACTOR example proc sfit -.DE +.TE C style comments are accepted. .DS /* this is a comment */ @@ -330,7 +332,7 @@ NAME=value .DE value being an integer or string. Three constants must be defined here: -.IP EM_WSIZE 10 +.IP EM_WSIZE 14 Number of bytes in a machine word. This is the number of bytes a \fBloc\fP instruction will put on the stack. @@ -368,13 +370,13 @@ FORMAT= "0%o" to satisfy the old UNIX assembler that reads octal unless followed by a period, and the ACK assembler that follows C conventions. .PP -Tables under control of programs like +Tables under control of source code control systems like .I sccs or .I rcs can put their id-string here, for example .DS -rcsid="$Header$" +rcsid="$\&Header$" .DE These strings, like all strings in the table, will eventually end up in the binary code generator produced. @@ -385,6 +387,7 @@ same order of magnitude. This can be done as .DS SIZEFACTOR = C\d3\u/C\d4\u +.sp TIMEFACTOR = C\d1\u/C\d2\u .DE Above numbers must be read as rational numbers. @@ -403,32 +406,28 @@ It consists of a list of user-defined identifiers optionally followed by the size of the property in parentheses, default EM_WSIZE. Example for the PDP-11: -.DS -.ta 8 16 24 32 40 -PROPERTIES /* The header word for this section */ +.TS +l l. +PROPERTIES /* The header word for this section */ -GENREG /* All PDP registers */ -REG /* Normal registers (allocatable) */ -ODDREG /* All odd registers (allocatable) */ -REGPAIR(4) /* Register pairs for division */ -FLTREG(4) /* Floating point registers */ -DBLREG(8) /* Same, double precision */ -GENFREG(4) /* generic floating point */ -GENDREG(8) /* Same, double precision */ -FLTREGPAIR(8) /* register pair for modf */ -DBLREGPAIR(16) /* Same, double precision */ -LOCALBASE /* Guess what */ +GENREG /* All PDP registers */ +REG /* Normal registers (allocatable) */ +ODDREG /* All odd registers (allocatable) */ +REGPAIR(4) /* Register pairs for division */ +FLTREG(4) /* Floating point registers */ +DBLREG(8) /* Same, double precision */ +GENFREG(4) /* generic floating point */ +GENDREG(8) /* Same, double precision */ +FLTREGPAIR(8) /* register pair for modf */ +DBLREGPAIR(16) /* Same, double precision */ +LOCALBASE /* Guess what */ STACKPOINTER PROGRAMCOUNTER -.DE +.TE Registers are allocated by asking for a property, so if for some reason in later parts of the table one particular register must be allocated it has to have a unique property. -.PP -There is a bug in the codegenerator that can be circumvented by -providing a dummy property at the start of the property list. -The example has not been updated to show this. .NH 2 Register definition .PP @@ -442,22 +441,22 @@ Syntax: : ident [ '(' string ')' ] [ '=' ident [ '+' ident ] ] .DE Example for the PDP-11: -.DS L -.ta 8 16 24 32 40 48 56 64 +.TS +l l. REGISTERS -r0,r2,r4 : GENREG,REG. -r1,r3 : GENREG,REG,ODDREG. -r01("r0")=r0+r1 : REGPAIR. -fr0("r0"),fr1("r1"),fr2("r2"),fr3("r3") : GENFREG,FLTREG. +r0,r2,r4 : GENREG,REG. +r1,r3 : GENREG,REG,ODDREG. +r01("r0")=r0+r1 : REGPAIR. +fr0("r0"),fr1("r1"),fr2("r2"),fr3("r3") : GENFREG,FLTREG. dr0("r0")=fr0,dr1("r1")=fr1, - dr2("r2")=fr2,dr3("r3")=fr3 : GENDREG,DBLREG. + dr2("r2")=fr2,dr3("r3")=fr3 : GENDREG,DBLREG. fr01("r0")=fr0+fr1,fr23("r2")=fr2+fr3 : FLTREGPAIR. dr01("r0")=dr0+dr1,dr23("r2")=dr2+dr3 : DBLREGPAIR. -lb("r5") : GENREG,LOCALBASE. -sp : GENREG,STACKPOINTER. -pc : GENREG,PROGRAMCOUNTER. -.DE +lb("r5") : GENREG,LOCALBASE. +sp : GENREG,STACKPOINTER. +pc : GENREG,PROGRAMCOUNTER. +.TE .PP The names in the left hand lists are names of registers as used in the table. @@ -529,20 +528,21 @@ Tokens should usually be declared for every addressing mode of the machine at hand and for every size directly usable in a machine instruction. Example for the PDP-11 (incomplete): -.DS L +.TS +l l. TOKENS -const2 = { INT num; } 2 cost(2,300) "$" num . -addr_local = { INT ind; } 2 . -addr_external = { ADDR off; } 2 "$" off. +const2 = { INT num; } 2 cost(2,300) "$" num . +addr_local = { INT ind; } 2 . +addr_external = { ADDR off; } 2 "$" off. -regdef2 = { GENREG reg; } 2 "*" reg. -regind2 = { GENREG reg; ADDR off; } 2 off "(" reg ")" . -reginddef2 = { GENREG reg; ADDR off; } 2 "*" off "(" reg ")" . +regdef2 = { GENREG reg; } 2 "*" reg. +regind2 = { GENREG reg; ADDR off; } 2 off "(" reg ")" . +reginddef2 = { GENREG reg; ADDR off; } 2 "*" off "(" reg ")" . regconst2 = { GENREG reg; ADDR off; } 2 . relative2 = { ADDR off; } 2 off . -reldef2 = { ADDR off; } 2 "*" off. -.DE +reldef2 = { ADDR off; } 2 "*" off. +.TE .PP Types allowed in the struct are ADDR, INT and all register properties. The type ADDR means a string and an integer, @@ -624,21 +624,21 @@ in the remainder of the table, but for clarity it is usually better not to. .LP Example for the PDP-11 (incomplete): -.DS L -.ta 8 16 24 32 40 48 56 64 +.TS +l l. SETS -src2 = GENREG + regdef2 + regind2 + reginddef2 + relative2 + - reldef2 + addr_external + const2 + LOCAL + ILOCAL + - autodec + autoinc . -dst2 = src2 - ( const2 + addr_external ) . -xsrc2 = src2 + ftoint . -src1 = regdef1 + regind1 + reginddef1 + relative1 + reldef1 . -dst1 = src1 . -src1or2 = src1 + src2 . -src4 = relative4 + regdef4 + DLOCAL + regind4 . -dst4 = src4 . -.DE +src2 = GENREG + regdef2 + regind2 + reginddef2 + relative2 + + \h'\w'= 'u'reldef2 + addr_external + const2 + LOCAL + ILOCAL + + \h'\w'= 'u'autodec + autoinc . +dst2 = src2 - ( const2 + addr_external ) . +xsrc2 = src2 + ftoint . +src1 = regdef1 + regind1 + reginddef1 + relative1 + reldef1 . +dst1 = src1 . +src1or2 = src1 + src2 . +src4 = relative4 + regdef4 + DLOCAL + regind4 . +dst4 = src4 . +.TE Permissible in the set construction are all the usual set operators, i.e. .IP + set union @@ -1252,7 +1252,7 @@ The author of .I cgg could not get .I yacc -to be silent without it. +to accept his syntax without it. Sorry about this. .IP 2) a @@ -1370,20 +1370,19 @@ A list of examples for the PDP-11 is given here. Far from being complete it gives examples of most kinds of instructions. .DS -.ta 8 16 24 32 40 48 56 64 -pat loc yields {const2, $1} +.ta 7.5c +pat loc yields {const2, $1} -pat ldc yields {const2, loww($1)} - {const2, highw($1)} +pat ldc yields {const2, loww($1)} {const2, highw($1)} .DE These simple patterns just push one or more tokens onto the fake stack. .DS -.ta 8 16 24 32 40 48 56 64 +.ta 7.5c pat lof -with REG yields {regind2,%1,$1} -with exact regconst2 yields {regind2,%1.reg,$1+%1.off} -with exact addr_external yields {relative2,$1+%1.off} -with exact addr_local yields {LOCAL, %1.ind + $1,2} +with REG yields {regind2,%1,$1} +with exact regconst2 yields {regind2,%1.reg,$1+%1.off} +with exact addr_external yields {relative2,$1+%1.off} +with exact addr_local yields {LOCAL, %1.ind + $1,2} .DE This pattern shows the possibility to do different things depending on the fake stack contents, @@ -1393,13 +1392,12 @@ not preceded by that can always be taken after a coercion, if necessary. .DS -.ta 8 16 24 32 40 48 56 64 +.ta 7.5c pat lxl $1>3 -uses REG={LOCAL, SL, 2}, - REG={const2,$1-1} +uses REG={LOCAL, SL, 2}, REG={const2,$1-1} gen 1: move {regind2,%a, SL},%a - sob %b,{label,1b} yields %a + sob %b,{label,1b} yields %a .DE This rule shows register allocation with initialisation, and the use of a temporary label. @@ -1408,7 +1406,7 @@ of the static link, that is pushed by the Pascal compiler as the last argument of a function. .DS -.ta 8 16 24 32 40 48 56 64 +.ta 7.5c pat stf with regconst2 xsrc2 kills allexeptcon @@ -1423,7 +1421,7 @@ part in a store instruction. The set allexeptcon contains all tokens that can be the destination of an indirect store. .DS -.ta 8 16 24 32 40 48 56 64 +.ta 7.5c pat sde with exact FLTREG kills posextern @@ -1449,51 +1447,52 @@ The third rule is taken by default, resulting in two separate stores, nothing better exists on the PDP-11. .DS -.ta 8 16 24 32 40 48 56 64 +.ta 7.5c pat sbi $1==2 with src2 REG - gen sub %1,%2 yields %2 + gen sub %1,%2 yields %2 with exact REG src2-REG gen sub %2,%1 - neg %1 yields %1 + neg %1 yields %1 .DE This rule for .I sbi has a normal first part, and a hand optimized special case as it's second part. .DS -.ta 8 16 24 32 40 48 56 64 +.ta 7.5c pat mli $1==2 with ODDREG src2 - gen mul %2,%1 yields %1 + gen mul %2,%1 yields %1 with src2 ODDREG - gen mul %1,%2 yields %2 + gen mul %1,%2 yields %2 .DE This shows the general property for rules with commutative operators, heuristics or look ahead will have to decide which rule is the best. .DS -.ta 8 16 24 32 40 48 56 64 +.ta 7.5c pat loc sli $1==1 && $2==2 with REG -gen asl %1 yields %1 +gen asl %1 yields %1 .DE A simple rule involving a longer EM-pattern, to make use of a specialized instruction available. .DS -.ta 8 16 24 32 40 48 56 64 +.ta 7.5c pat loc loc cii $1==1 && $2==2 with src1or2 uses reusing %1,REG -gen movb %1,%a yields %a +gen movb %1,%a yields %a .DE A somewhat more complicated example of the same. Note the .I reusing clause. .DS -.ta 8 16 24 32 40 48 56 64 -pat loc loc loc cii $1>=0 && $2==2 && $3==4 leaving loc $1 loc 0 +.ta 7.5c +pat loc loc loc cii $1>=0 && $2==2 && $3==4 + leaving loc $1 loc 0 .DE Shows a trivial example of EM-replacement. This is a rule that could be done by the @@ -1502,40 +1501,40 @@ if word order in longs was defined in EM. On a `big-endian' machine the two replacement instructions would be the other way around. .DS -.ta 8 16 24 32 40 48 56 64 +.ta 7.5c pat and $1==2 with const2 REG - gen bic {const2,~%1.num},%2 yields %2 + gen bic {const2,~%1.num},%2 yields %2 with REG const2 - gen bic {const2,~%2.num},%1 yields %1 + gen bic {const2,~%2.num},%1 yields %1 with REG REG gen com %1 - bic %1,%2 yields %2 + bic %1,%2 yields %2 .DE Shows the way you have to twist the table, if an .I and -instruction is not available on your machine. .DS -.ta 8 16 24 32 40 48 56 64 +.ta 7.5c pat set $1==2 with REG uses REG={const2,1} -gen ash %1,%a yields %a +gen ash %1,%a yields %a .DE Shows the building of a word-size set. .DS -.ta 8 16 24 32 40 48 56 64 +.ta 7.5c pat lae aar $2==2 && rom($1,3)==1 && rom($1,1)==0 - leaving adi 2 + leaving adi 2 pat lae aar $2==2 && rom($1,3)==1 && rom($1,1)!=0 - leaving adi 2 adp 0-rom($1,1) + leaving adi 2 adp 0-rom($1,1) .DE Two rules showing the use of the rom pseudo function, and some array optimalisation. .DS -.ta 8 16 24 32 40 48 56 64 +.ta 7.5c pat bra with STACK gen jbr {label, $1} @@ -1544,7 +1543,7 @@ A simple jump. The stack pattern guarantees that everything will be stacked before the jump is taken. .DS -.ta 8 16 24 32 40 48 56 64 +.ta 7.5c pat cal with STACK gen jsr pc,{label, $1} @@ -1552,9 +1551,9 @@ gen jsr pc,{label, $1} A simple call. Same comments as previous rule. .DS -.ta 8 16 24 32 40 48 56 64 -pat lfr $1==2 yields r0 -pat lfr $1==4 yields r1 r0 +.ta 7.5c +pat lfr $1==2 yields r0 +pat lfr $1==4 yields r1 r0 .DE Shows the return area conventions of the PDP-11 table. At this point a reminder: @@ -1564,7 +1563,7 @@ instruction, and some other instructions must leave the function return area intact. See the defining document for EM for exact information. .DS -.ta 8 16 24 32 40 48 56 64 +.ta 7.5c pat ret $1==0 with STACK gen mov lb,sp @@ -1578,7 +1577,7 @@ In a table with register variables the part would just contain .I return . .DS -.ta 8 16 24 32 40 48 56 64 +.ta 7.5c pat blm with REG REG uses REG={const2,$1/2} @@ -1596,15 +1595,15 @@ It uses the marriage thesis from Hall, a thesis from combinatorial mathematics, to accomplish this. .DS -.ta 8 16 24 32 40 48 56 64 +.ta 7.5c pat exg $1==2 -with src2 src2 yields %1 %2 +with src2 src2 yields %1 %2 .DE This rule shows the exchanging of two elements on the fake stack. .NH 2 Code rules using procedures .PP -To start this chapter it must be admitted at once that the +To start this section it must be admitted at once that the word procedure is chosen here mainly for it's advertising value. It more resembles a glorified goto but this of course can @@ -1664,12 +1663,12 @@ The string `*' can be used as an equivalent for `[1]'. Just in case this is not clear, here is an example for a procedure to increment/decrement a register. .DS -.ta 8 16 24 32 40 48 56 64 +.ta 7.5c incop REG:rw:cc . /* in the INSTRUCTIONS part of course */ proc incdec with REG -gen incop* %1 yields %1 +gen incop* %1 yields %1 .DE The procedure is called with parameter "inc" or "dec". .PP @@ -1680,18 +1679,18 @@ call '(' string [ ',' string ] ')' .DE which leads to the following large example: .DS -.ta 8 16 24 32 40 48 56 64 +.ta 7.5c proc bxx example beq with src2 src2 STACK gen cmp %2,%1 jxx* {label, $1} -pat blt call bxx("jlt") -pat ble call bxx("jle") -pat beq call bxx("jeq") -pat bne call bxx("jne") -pat bgt call bxx("jgt") -pat bge call bxx("jge") +pat blt call bxx("jlt") +pat ble call bxx("jle") +pat beq call bxx("jeq") +pat bne call bxx("jne") +pat bgt call bxx("jgt") +pat bge call bxx("jge") .DE .NH 2 Move definitions @@ -1856,38 +1855,38 @@ The next part of the table defines the coercions that are possible on the defined tokens. Example for the PDP-11: .DS -.ta 8 16 24 32 40 48 56 64 +.ta 7.5c COERCIONS from STACK uses REG -gen mov {autoinc,sp},%a yields %a +gen mov {autoinc,sp},%a yields %a from STACK uses DBLREG -gen movf {autoinc,sp},%a yields %a +gen movf {autoinc,sp},%a yields %a from STACK uses REGPAIR gen mov {autoinc,sp},%a.1 - mov {autoinc,sp},%a.2 yields %a + mov {autoinc,sp},%a.2 yields %a .DE These three coercions just deliver a certain type of register by popping it from the real stack. .DS -.ta 8 16 24 32 40 48 56 64 -from LOCAL yields {regind2,lb,%1.ind} +.ta 7.5c +from LOCAL yields {regind2,lb,%1.ind} -from DLOCAL yields {regind4,lb,%1.ind} +from DLOCAL yields {regind4,lb,%1.ind} -from REG yields {regconst2, %1, 0} +from REG yields {regconst2, %1, 0} .DE These three are zero-cost rewriting rules. .DS -.ta 8 16 24 32 40 48 56 64 +.ta 7.5c from regconst2 %1.off==1 uses reusing %1,REG=%1.reg -gen inc %a yields %a +gen inc %a yields %a from regconst2 uses reusing %1,REG=%1.reg @@ -1896,7 +1895,7 @@ gen add {addr_external, %1.off},%a yields %a from addr_local uses REG gen mov lb,%a - add {const2, %1.ind},%a yields %a + add {const2, %1.ind},%a yields %a .DE The last three are three different cases of the coercion register+constant to register. @@ -1904,19 +1903,19 @@ Only in the last case is it always necessary to allocate an extra register, since arithmetic on the localbase is unthinkable. .DS -.ta 8 16 24 32 40 48 56 64 +.ta 7.5c from xsrc2 -uses reusing %1, REG=%1 yields %a +uses reusing %1, REG=%1 yields %a from longf4 -uses FLTREG=%1 yields %a +uses FLTREG=%1 yields %a from double8 -uses DBLREG=%1 yields %a +uses DBLREG=%1 yields %a from src1 uses REG={const2,0} -gen bisb %1,%a yields %a +gen bisb %1,%a yields %a .DE These examples show the coercion of different tokens to a register of the needed type. @@ -1925,14 +1924,14 @@ ensure bytes are not sign-extended. In EM it is defined that the result of a \fBloi\fP\ 1 instruction is an integer in the range 0..255. .DS -.ta 8 16 24 32 40 48 56 64 -from REGPAIR yields %1.2 %1.1 +.ta 7.5c +from REGPAIR yields %1.2 %1.1 -from regind4 yields {regind2,%1.reg,2+%1.off} - {regind2,%1.reg,%1.off} +from regind4 yields {regind2,%1.reg,2+%1.off} + {regind2,%1.reg,%1.off} -from relative4 yields {relative2,2+%1.off} - {relative2,%1.off} +from relative4 yields {relative2,2+%1.off} + {relative2,%1.off} .DE The last examples are splitting rules. .PP @@ -2086,23 +2085,23 @@ If omitted no initialization is assumed. .NH 3 Example mach.h for the PDP-11 .DS L -.ta 8 16 24 32 40 48 56 +.ta 4c #define ex_ap(y) fprintf(codefile,"\et.globl %s\en",y) #define in_ap(y) /* nothing */ #define newplb(x) fprintf(codefile,"%s:\en",x) #define newilb(x) fprintf(codefile,"%s:\en",x) #define newdlb(x) fprintf(codefile,"%s:\en",x) -#define dlbdlb(x,y) fprintf(codefile,"%s=%s\en",x,y) +#define dlbdlb(x,y) fprintf(codefile,"%s=%s\en",x,y) #define newlbss(l,x) fprintf(codefile,"%s:.=.+%d.\en",l,x); -#define cst_fmt "$%d." -#define off_fmt "%d." -#define ilb_fmt "I%02x%x" -#define dlb_fmt "_%d" -#define hol_fmt "hol%d" +#define cst_fmt "$%d." +#define off_fmt "%d." +#define ilb_fmt "I%02x%x" +#define dlb_fmt "_%d" +#define hol_fmt "hol%d" -#define hol_off "%d.+hol%d" +#define hol_off "%d.+hol%d" #define con_cst(x) fprintf(codefile,"%d.\en",x) #define con_ilb(x) fprintf(codefile,"%s\en",x) @@ -2157,7 +2156,7 @@ mes(w_mesno) This function is called when a .B mes pseudo is seen that is not handled by the machine independent part. -Example below shows all you probably have to know about that. +The example below shows all you probably have to know about that. .IP - segname[] .br @@ -2216,7 +2215,7 @@ Example mach.c for the PDP-11 As an example of the sort of code expected, the mach.c for the PDP-11 is presented here. .DS L -.ta 8 16 24 32 40 48 56 64 +.ta 0.5i 1i 1.5i 2i 2.5i 3i 3.5i 4i 4.5i /* * machine dependent back end routines for the PDP-11 */ From e218ae5baf1db238f455250603bbe6e9385d5269 Mon Sep 17 00:00:00 2001 From: sater Date: Wed, 4 Dec 1985 16:08:21 +0000 Subject: [PATCH 0103/1625] Some old changes by keie, plus added tbl to ncg.doc --- doc/Makefile | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/doc/Makefile b/doc/Makefile index 18989353..67da867c 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -4,7 +4,7 @@ SUF=pr PRINT=cat RESFILES=cref.$(SUF) pcref.$(SUF) val.$(SUF) v7bugs.$(SUF) install.$(SUF)\ ack.$(SUF) cg.$(SUF) regadd.$(SUF) peep.$(SUF) toolkit.$(SUF) LLgen.$(SUF)\ -basic.$(SUF) 6500.$(SUF) ncg.$(SUF) +basic.$(SUF) 6500.$(SUF) ncg.$(SUF) i80.$(SUF) NROFF=nroff MS=-ms @@ -17,7 +17,7 @@ ack.$(SUF): ack.doc cg.$(SUF): cg.doc $(NROFF) $(MS) $? >$@ ncg.$(SUF): ncg.doc - $(NROFF) $(MS) $? >$@ + tbl $? | $(NROFF) $(MS) >$@ regadd.$(SUF): regadd.doc $(NROFF) $(MS) $? >$@ install.$(SUF): install.doc @@ -33,14 +33,16 @@ val.$(SUF): val.doc toolkit.$(SUF): toolkit.doc $(NROFF) $(MS) $? >$@ LLgen.$(SUF): LLgen.doc - eqn $? | $(NROFF) $(MS) >$@ + eqn $? | tbl | $(NROFF) $(MS) >$@ 6500.$(SUF): 6500.doc $(NROFF) $(MS) $? >$@ +i80.$(SUF): i80.doc + $(NROFF) $(MS) $? >$@ install cmp: distr: install.doc - nroff -Tlp install.doc >install.pr + tbl install.doc | nroff -Tlp $(MS) >install.pr pr: @make "SUF="$SUF "NROFF="$NROFF "PRINT="$PRINT $(RESFILES) \ >make.pr.out 2>&1 From 7e47b13e67790698dd9c5bde16c6efe2497d9cbd Mon Sep 17 00:00:00 2001 From: dick Date: Mon, 20 Jan 1986 20:39:09 +0000 Subject: [PATCH 0104/1625] adapted to phototypesetter --- lang/pc/pem/em_pem.6 | 2 +- man/6500_as.1 | 31 +++++++++++++------------ man/6800_as.1 | 6 ++--- man/6805_as.1 | 42 ++++++++++++++++----------------- man/6809_as.1 | 44 +++++++++++++++++------------------ man/8080_as.1 | 2 +- man/i86_as.1 | 23 +++++++++--------- man/libmon.7 | 40 +++++++++++++++++--------------- man/libpc.7 | 25 ++++++++++---------- man/m68k2_as.1 | 26 ++++++++++----------- man/m68k_int.1 | 2 +- man/macro.v7 | 4 +++- man/ns_as.1 | 4 ++-- man/pc_prlib.7 | 55 +++++++++++++++++++++++--------------------- man/pdp_as.1 | 10 ++++---- man/uni_ass.6 | 8 +++---- man/z8000_as.1 | 22 +++++++++--------- man/z80_as.1 | 12 +++++----- util/ack/ack.1.X | 7 ++++-- util/cpp/cpp.6 | 5 ++-- 20 files changed, 192 insertions(+), 178 deletions(-) diff --git a/lang/pc/pem/em_pem.6 b/lang/pc/pem/em_pem.6 index f9e81729..6943b467 100644 --- a/lang/pc/pem/em_pem.6 +++ b/lang/pc/pem/em_pem.6 @@ -39,7 +39,7 @@ ISO/TC97/SC5-N462, received November 1979. .IP [4] J.W.Stevenson "The Amsterdam Compiler Kit Pascal reference manual". .br -(try 'nroff /usr/em/doc/pcref.doc') +(try \fInroff /usr/em/doc/pcref.doc\fP) .IP [5] \fIack\fP(I) .SH DIAGNOSTICS diff --git a/man/6500_as.1 b/man/6500_as.1 index d7c779d3..58b0d598 100644 --- a/man/6500_as.1 +++ b/man/6500_as.1 @@ -1,6 +1,5 @@ .\" $Header$ .TH 6500_AS 1 -.ad .SH NAME 6500_as \- assembler for Mostek 6500 .SH SYNOPSIS @@ -33,33 +32,35 @@ E.g. -1.h parses as -[1.h] which has value 0. You have to write [-1].h to get 0xFF. .IP "addressing modes" .nf -.ta 8 16 24 32 40 48 -syntax meaning (name) +.ta 16n 24n 32n 40n 48n +syntax meaning (name) -#expr 8-bit value (immediate) +#expr 8-bit value (immediate) -expr address (direct) +expr address (direct) -expr, x expr + contents of x - or or -expr, y expr + contents of y - yields address (indexed) +expr, x expr + contents of x + or or +expr, y expr + contents of y + yields address (indexed) -(expr) address of address (only with JMP) (indirect) +(expr) address of address (only with JMP) (indirect) +.fi -In the next two addressing modes `expr' has to be +In the next two addressing modes \fIexpr\fP has to be a zeropage expression. +.nf (expr, x) expr + contents of x - yields address (pre-indexed indirect) + yields address (pre-indexed indirect) (expr), y contents of expr + contents of y - yields address (post-indexed indirect) + yields address (post-indexed indirect) .fi .IP instructions There are two mnemonics that do not map onto one machine-instruction: -`add' and `sub'. `Add mode' maps onto `clc; adc mode'. -`Sub mode' maps onto `sec; sbc mode'. +\fIadd\fP and \fIsub\fP. \fIAdd mode\fP maps onto \fIclc; adc mode\fP. +\fISub mode\fP maps onto \fIsec; sbc mode\fP. .SH "SEE ALSO" uni_ass(6), ack(1) diff --git a/man/6800_as.1 b/man/6800_as.1 index e7341ec3..08791a50 100644 --- a/man/6800_as.1 +++ b/man/6800_as.1 @@ -15,7 +15,7 @@ to accumulator A, has an "a" as last character. In the same way a "b" means that the instruction uses B as accumulator. .IP "addressing modes" .nf -.ta 8 16 24 32 40 48 +.ta 8n 16n 24n 32n 40n 48n syntax meaning (name) #expr with cpx, ldx, lds a 2-byte value, @@ -40,7 +40,7 @@ Adam Osborne and Associates Inc., 1977 An example of Motorola 6800 assembly code. .sp 2 .nf -.ta 8 16 32 40 48 56 64 +.ta 8n 16n 32n 40n 48n 56n 64n .data val: 0 .text @@ -52,4 +52,4 @@ An example of Motorola 6800 assembly code. .fi .SH BUGS You have to specify whether an address fits in one byte -with the token `<'. It should be done automatically. +with the token \fI<\fP. It should be done automatically. diff --git a/man/6805_as.1 b/man/6805_as.1 index 4cb2a7dc..429667fc 100644 --- a/man/6805_as.1 +++ b/man/6805_as.1 @@ -27,7 +27,7 @@ range it is replaced by a reversed condition branch, followed by a jump, automatically. .sp .nf -.ta 8 16 24 32 40 48 +.ta 8n 16n 24n 32n 40n 48n syntax meaning (name) #expr a one byte value (immediate) @@ -68,26 +68,26 @@ Prentice-Hall, Inc., 1983, (ISBN 0-13-541375-3). An example of Motorola 6805 assembly code. .sp 2 .nf -.ta 8 16 32 40 48 56 64 -.dram -one: .space 1 ! a-port -.dprom -c1: .byte 1 -.text -start: ldx #c1 ! load address of c1 - txa - sta one - add c1 ! add one - brset 1,one,whoop ! jif bit one of aport - bset 1,one ! set it now -.data - .ascii "unused string" -.text -whoop: nop -.org 0xff8 - .word start ! set vector address -.text - nop ! resume code +.ta 8n 16n 32n 40n 48n 56n 64n + .dram + one: .space 1 ! a-port + .dprom + c1: .byte 1 + .text + start: ldx #c1 ! load address of c1 + txa + sta one + add c1 ! add one + brset 1,one,whoop ! jif bit one of aport + bset 1,one ! set it now + .data + .ascii "unused string" + .text + whoop: nop + .org 0xff8 + .word start ! set vector address + .text + nop ! resume code .fi .SH AUTHOR Written by Gijs Mos. diff --git a/man/6809_as.1 b/man/6809_as.1 index 7ac2ede8..10e38c1a 100644 --- a/man/6809_as.1 +++ b/man/6809_as.1 @@ -34,28 +34,28 @@ This is used for efficient address encoding of some addressing mode (see below). .IP "addressing modes" .nf -.ta 8 16 24 32 40 48 +.ta 8n 16n 24n 32n 40n 48n syntax meaning (name) -reg The operand of the instruction is in `reg'. +reg The operand of the instruction is in \fIreg\fP. -reglist `reglist' is a either list of registers, seperated +reglist \fIreglist\fP is a either list of registers, seperated by ','s, or the word "all". It encodes in a register save mask, where "all" means all registers, that can be used by the push-pull instructions pshs, pshu, puls, and pulu. -expr The two-byte value of `expr' is the exact memory +>expr The two-byte value of \fIexpr\fP is the exact memory address. Not that this mode always requires one byte more than "expr". (relative for branch-instructions) -#expr The value of `expr' is one- or two-byte immediate +#expr The value of \fIexpr\fP is one- or two-byte immediate data. (immediate) -(expr) The value of `expr' is a pointer to the address +(expr) The value of \fIexpr\fP is a pointer to the address of the operand. (indirect) -expr, reg The value of `expr' added to the contents of `reg' +expr, reg The value of \fIexpr\fP added to the contents of \fIreg\fP (which must be a 16-bit register) yields the effective address of the operand. (constant-offset indexed) -, ireg The contents of `ireg' (which must be indexable) +, ireg The contents of \fIireg\fP (which must be indexable) yields the effective address of the operand. (constant-offset indexed) -(expr, reg) The value of `expr' added to the contents of `reg' +(expr, reg) The value of \fIexpr\fP added to the contents of \fIreg\fP (which must be a 16-bit register) yields a pointer to the effective address of the operand. (constant-offset indexed indirect) -(, ireg) The contents of `ireg' (which must be indexable) +(, ireg) The contents of \fIireg\fP (which must be indexable) yields a pointer to the effective address of the operand. (constant-offset indexed indirect) -ac, ireg The contents of `ac' (which must be an accumulator) - added to the contents of `ireg' (which must be +ac, ireg The contents of \fIac\fP (which must be an accumulator) + added to the contents of \fIireg\fP (which must be indexable) yields the effective address of the operand. (accumulator indexed) -(ac, ireg) The contents of `ac' (which must be an accumulator) - added to the contents of `ireg' (which must be +(ac, ireg) The contents of \fIac\fP (which must be an accumulator) + added to the contents of \fIireg\fP (which must be indexable) yields a pointer to the effective address of the operand. (accumulator indexed indirect) ,ireg+ -,ireg++ The contents of `ireg' (which must be indexable) is +,ireg++ The contents of \fIireg\fP (which must be indexable) is used as effective address of the operand. After that it is incremented by 1 (+) or 2 (++). (auto-increment) -(,ireg++) The contents of `ireg' (which must be indexable) is +(,ireg++) The contents of \fIireg\fP (which must be indexable) is used as a pointer to the effective address of the operand. After that it is incremented by 2. (auto-increment indirect) ,-ireg -,--ireg `ireg' (which must be indexable) is decremented +,--ireg \fIireg\fP (which must be indexable) is decremented by 1 (-) or 2 (--). After that, its contents is used as effective address of the operand. (auto-decrement) -(,--ireg) `ireg (which must be indexable) is decremented by 2. +(,--ireg) \fIireg\fP (which must be indexable) is decremented by 2. After that, its contents is used as a pointer to the effective address of the operand. (auto-decrement indirect) @@ -133,7 +133,7 @@ MC6809 preliminary programming manual, Motorola Inc., First Edition, 1979 .SH EXAMPLE An example of 6809 assembly code. .nf -.ta 8 16 24 32 40 48 +.ta 8n 16n 24n 32n 40n 48n contby = 80 compgo: lda #contby diff --git a/man/8080_as.1 b/man/8080_as.1 index e8d8871a..4a156362 100644 --- a/man/8080_as.1 +++ b/man/8080_as.1 @@ -15,7 +15,7 @@ and two two-byte registers: sp and psw, respectively the stack pointer and the processor status word. .IP "addressing modes" .nf -.ta 8 16 24 32 40 48 +.ta 8n 16n 24n 32n 40n 48n syntax meaning expr one- or two-byte address or immediate diff --git a/man/i86_as.1 b/man/i86_as.1 index 11379011..9f694715 100644 --- a/man/i86_as.1 +++ b/man/i86_as.1 @@ -14,7 +14,8 @@ An address on the Intel 8086 consists of two pieces: a segment number and an offset. A memory address is computed as the segment number shifted left 4 bits + the offset. Assembly language addresses only give the offset, with the exception of -the address of an inter-segment jump or call (see `addressing modes' below). +the address of an inter-segment jump or call (see \fIaddressing modes\fP +below). For each segment type (.org, .text, .data, or .bss) the segment number must be given with the .sbase pseudo-instruction. The syntax is: @@ -40,10 +41,10 @@ Two index registers: si (source index) and di (destination index). Four segment registers: cs (code), ds (data), ss (stack), and es (extra). .IP "addressing modes" .nf -.ta 8 16 24 32 40 48 +.ta 8n 16n 24n 32n 40n 48n syntax meaning -expr the value of `expr' is immediate data or +expr the value of \fIexpr\fP is immediate data or an address offset. There is no special notation for immediate data. @@ -54,22 +55,22 @@ register one of the aforementioned general registers (expr) the value of expr is the address of the operand. (reg) -expr (reg) the value of `expr' (if present) + the contents of - `reg' (which must be a pointer or an index register) +expr (reg) the value of \fIexpr\fP (if present) + the contents of + \fIreg\fP (which must be a pointer or an index register) is the address of the operand. (preg) (ireg) expr (preg) (ireg) - the value of `expr' (if present) + the contents of - `preg' (which must be a pointer register) + the - contents of `ireg' (which must be an index register) + the value of \fIexpr\fP (if present) + the contents of + \fIpreg\fP (which must be a pointer register) + the + contents of \fIireg\fP (which must be an index register) is the address of the operand. The next addressing mode is only allowed with the instructions "callf" or "jmpf". -expr : expr the value of the first `expr' is a segment number, - the value of the second `expr' is an address offset. +expr : expr the value of the first \fIexpr\fP is a segment number, + the value of the second \fIexpr\fP is an address offset. The (absolute) address of the operand is computed as described above. .fi @@ -90,7 +91,7 @@ ack(1), MCS-86 assembly language reference manual, 1978, Intel Corporation .SH EXAMPLE .nf -.ta 8 16 24 32 40 48 +.ta 8n 16n 24n 32n 40n 48n An example of Intel 8086 assembly language: _panic: diff --git a/man/libmon.7 b/man/libmon.7 index 468c149f..65fcf1c4 100644 --- a/man/libmon.7 +++ b/man/libmon.7 @@ -6,25 +6,25 @@ libmon \- library of system call routines with EM calling sequence .SH DESCRIPTION The modules in this library contain the UNIX system calls with EM calling sequence. This library is written in EM assembly language and can be used -for interpreted programs, and 'a.out' programs. +for interpreted programs, and \fIa.out\fP programs. If these routines are used in Pascal programs, then the calling sequence requires some attention. Some hints may be useful: .IP - The c-option {$c+} allows you to declare zero-terminated string constants in Pascal like "/etc/passwd". -Moreover, the identifier 'string' is then defined as type identifier for +Moreover, the identifier \fIstring\fP is then defined as type identifier for a pointer to these zero-terminated strings. .IP - The d-option {$d+} allows you to use double precision integers (longs). The lseek system call, for instance, needs a long argument and returns a long result. .IP - -If the system call requires a pointer as argument use a 'var' parameter. +If the system call requires a pointer as argument use a \fIvar\fP parameter. For instance declare times as: .br procedure times(var t:timesbuf); extern; .br -Note that a 'string' is already a pointer. +Note that a \fIstring\fP is already a pointer. .IP - When defining types, use packed records if two bytes must be allocated in a single word, as in @@ -49,44 +49,48 @@ can be declared as: .br creatmode = set of XHIM..SUID; .IP - -There are special system call routines 'uread' and 'uwrite' in libpc(VII), -because the names 'read' and 'write' are blocked by similar functions in Pascal. +There are special system call routines \fIuread\fP and \fIuwrite\fP +in libpc(VII), +because the names \fIread\fP and \fIwrite\fP +are blocked by similar functions in Pascal. .PP -The system call 'signal' exists, but uses 'sigtrp'. +The system call \fIsignal\fP exists, but uses \fIsigtrp\fP. This EM system call has the following calling sequence: .br function sigtrp(signo,trapno:integer):integer; .br -The action values of 'signal', odd for 'ignore' and zero -for 'get back to default', +The action values of \fIsignal\fP, odd for \fIignore\fP and zero +for \fIget back to default\fP, may interfere with the EM procedure identification in some implementations. In most interpreters procedures in EM are numbered consecutively from zero up. -The first argument of 'sigtrp' is the signal number 'signo' as for 'signal'. -The second argument is an integer 'trapno', indicating the action to be performed +The first argument of \fIsigtrp\fP is the signal number \fIsigno\fP +as for \fIsignal\fP. +The second argument is an integer \fItrapno\fP, +indicating the action to be performed when the signal is issued: .IP -2 8 -Reset the action for signal 'signo' to the default. +Reset the action for signal \fIsigno\fP to the default. .IP -3 -Ignore signal 'signo'. +Ignore signal \fIsigno\fP. .IP "0-252" -Perform an EM instruction TRP with error code 'trapno', -whenever the signal 'signo' is issued. +Perform an EM instruction TRP with error code \fItrapno\fP, +whenever the signal \fIsigno\fP is issued. Note that the error codes 0-127 are reserved for EM machine errors and language runtime system errors. .PP -The routine 'sigtrp' returns the old 'trapno' or -1 if an erroneous +The routine \fIsigtrp\fP returns the old \fItrapno\fP or -1 if an erroneous signal number is specified. Only the signal numbers 1, 2, 3, 13, 14, 15 and 16 may be used as argument -for 'sigtrp'. +for \fIsigtrp\fP. .SH FILES .IP /usr/em/mach/*/lib/tail_mon .PD .SH "SEE ALSO" em(I), ack(I), *(II), libpc(VII) .SH DIAGNOSTICS -All routines put the UNIX error code in the global variable 'errno'. +All routines put the UNIX error code in the global variable \fIerrno\fP. Errno is not cleared by successful system calls, so it always gives the error of the last failed call. One exception: ptrace clears errno when successful. diff --git a/man/libpc.7 b/man/libpc.7 index 335f4746..47900673 100644 --- a/man/libpc.7 +++ b/man/libpc.7 @@ -4,7 +4,7 @@ .SH NAME libpc \- library of external routines for Pascal programs .SH SYNOPSIS -.ta 11 +.ta 11n const bufsize = ?; .br type br1 = 1..bufsize; @@ -90,7 +90,7 @@ Returns a pointer to the i-th environment string (i>=0). Returns nil if i is beyond the end of the environment list (UNIX version 7). .IP argshift Effectively deletes the first argument from the argument list. -Its function is equivalent to 'shift' in the UNIX shell: argv[2] becomes +Its function is equivalent to \fIshift\fP in the UNIX shell: argv[2] becomes argv[1], argv[3] becomes argv[2], etc. It is a useful procedure to skip optional flag arguments. Note that the matching of arguments and files @@ -163,26 +163,27 @@ Trap generates the trap passed as argument (0..252). The trap numbers 128..252 may be used freely. The others are reserved. .PD 0 .IP encaps -Encapsulate the execution of 'p' with the trap handler 'q'. -Encaps replaces the previous trap handler by 'q', calls 'p' and restores -the previous handler when 'p' returns. -If, during the execution of 'p', a trap occurs, -then 'q' is called with the trap number as parameter. -For the duration of 'q' the previous trap handler is restored, so that -you may handle only some of the errors in 'q'. All the other errors must -then be raised again by a call to 'trap'. +Encapsulate the execution of \fIp\fP with the trap handler \fIq\fP. +Encaps replaces the previous trap handler by \fIq\fP, calls \fIp\fP +and restores +the previous handler when \fIp\fP returns. +If, during the execution of \fIp\fP, a trap occurs, +then \fIq\fP is called with the trap number as parameter. +For the duration of \fIq\fP the previous trap handler is restored, so that +you may handle only some of the errors in \fIq\fP. All the other errors must +then be raised again by a call to \fItrap\fP. .br Encapsulations may be nested: you may encapsulate a procedure while executing an encapsulated routine. .br Jumping out of an encapsulated procedure (non-local goto) is dangerous, because the previous trap handler must be restored. -Therefore, you may only jump out of procedure 'p' from inside 'q' and +Therefore, you may only jump out of procedure \fIp\fP from inside \fIq\fP and you may only jump out of one level of encapsulation. If you want to exit several levels of encapsulation, use traps. See pc_emlib(VII) and pc_prlib(VII) for lists of trap numbers for EM machine errors and Pascal run time system errors. -Note that 'p' may not have parameters. +Note that \fIp\fP may not have parameters. .PD .PP .RE diff --git a/man/m68k2_as.1 b/man/m68k2_as.1 index deeb430e..77ef9308 100644 --- a/man/m68k2_as.1 +++ b/man/m68k2_as.1 @@ -19,40 +19,40 @@ a status register (sr), and a condition codes register (ccr) which is actually just the low order byte of the status register. .IP "addressing modes" .nf -.ta 8 16 24 32 40 48 +.ta 8n 16n 24n 32n 40n 48n syntax meaning (name) -reg contents of `reg' is operand, where `reg' is +reg contents of \fIreg\fP is operand, where \fIreg\fP is one of the registers mentioned above (register direct) -(areg) contents of `areg' is address of operand, where - `areg' is an address-register +(areg) contents of \fIareg\fP is address of operand, where + \fIareg\fP is an address-register (address register indirect) (areg)+ same as (areg), but after the address is used, - `areg' is incremented by the operand length + \fIareg\fP is incremented by the operand length (postincrement) -(areg) same as (areg), but before the address is used, - `areg' is decremented by the operand length + \fIareg\fP is decremented by the operand length (predecrement) expr(areg) -expr(pc) `expr' + the contents of the register yields the +expr(pc) \fIexpr\fP + the contents of the register yields the address of the operand (displacement) expr(areg, ireg) -expr(pc, ireg) `expr' + the contents of the register + the contents - of `ireg' yields the address of the operand. `ireg' is +expr(pc, ireg) \fIexpr\fP + the contents of the register + the contents + of \fIireg\fP yields the address of the operand. \fIireg\fP is an address- or a data-register. - `ireg' may be followed by .w or .l indicating whether + \fIireg\fP may be followed by .w or .l indicating whether the size of the index is a word or a long (displacement with index) -expr `expr' is the address of the operand +expr \fIexpr\fP is the address of the operand (absolute address) -#expr `expr' is the operand (immediate) +#expr \fIexpr\fP is the operand (immediate) .fi Some instructions have as operand a register list. This list consists of @@ -72,7 +72,7 @@ MC68000 16-bit microprocessor User's manual, Motorola Inc, 1979 .SH EXAMPLE .sp 2 .nf -.ta 8 16 24 32 40 48 56 64 +.ta 8n 16n 24n 32n 40n 48n 56n 64n .define .cii .text diff --git a/man/m68k_int.1 b/man/m68k_int.1 index 11b90fb7..9948e4e7 100644 --- a/man/m68k_int.1 +++ b/man/m68k_int.1 @@ -91,6 +91,6 @@ in the source. In that case adapt source file mloopc to your machine. Also the instruction that causes the machine to allocate stack space might differ . -In that case adapt the macro 'claimstack' in deffile. +In that case adapt the macro \fIclaimstack\fP in deffile. .SH AUTHOR Freek van Schagen diff --git a/man/macro.v7 b/man/macro.v7 index 2d3ab6c8..620e78cf 100644 --- a/man/macro.v7 +++ b/man/macro.v7 @@ -1,6 +1,8 @@ .\" $Header$ .de TH .PD +.br +.bp .lc .nr in 5 .de hd @@ -29,7 +31,7 @@ .sp \\n(pdu .ne 2 .fi -\s+3\fB\\$1\fP\s0 +\fB\\$1\fP .br .. .de LP diff --git a/man/ns_as.1 b/man/ns_as.1 index 20c31d13..d5fd34b9 100644 --- a/man/ns_as.1 +++ b/man/ns_as.1 @@ -62,7 +62,7 @@ The convention used to indicate offset length by appending :B, :W or :D to offsets is not implemented. The assembler tries to find out the minimal size needed for any constant in an operand of the instruction placed in the text segment. -Offsets in instructions outside '.text' are always four bytes. +Offsets in instructions outside \fI.text\fP are always four bytes. .PP All special operands, e.g. register list, configuration list, have the same format as in the Programmers Reference Manual. @@ -90,7 +90,7 @@ Two different possibilities are given for the encoding of the instructions movsu and movus. .SH EXAMPLE .nf -.ta 12 20 28 36 +.ta 12n 20n 28n 36n 00000000 0E0B02 setcfg [ m ] label: diff --git a/man/pc_prlib.7 b/man/pc_prlib.7 index f0055016..01171120 100644 --- a/man/pc_prlib.7 +++ b/man/pc_prlib.7 @@ -4,7 +4,7 @@ .SH NAME pc_prlib \- library of Pascal runtime routines .SH SYNOPSIS -.ta 11 +.ta 11n type alpha=packed array[1..8] of char; .br pstring= ^packed array[] of char; @@ -310,16 +310,18 @@ Array operations: The only useful form of packing implemented, is packing bytes into words. All other forms of packing and unpacking result in a plain copy. .IP _pac -Pack an unpacked array 'a' into a packed array 'z'. 'ap' and 'zp' -are pointers to 'a' and 'z'. 'ad' and 'zd' -are pointers to the descriptors of 'a' and 'z'. 'i' is -the index in 'a' of the first element to be packed. -Pack until 'z' is full. +Pack an unpacked array \fIa\fP into a packed array \fIz\fP. +\fIap\fP and \fIzp\fP +are pointers to \fIa\fP and \fIz\fP. \fIad\fP and \fIzd\fP +are pointers to the descriptors of \fIa\fP and \fIz\fP. \fIi\fP is +the index in \fIa\fP of the first element to be packed. +Pack until \fIz\fP is full. .PD 0 .IP _unp -Unpack 'z' into 'a'. 'ap', 'zp', 'ad' and 'zd' are as for _pac. 'i' is -the index in 'a' where the first element of 'z' is copied into. -Unpack all elements of 'z'. +Unpack \fIz\fP into \fIa\fP. +\fIap\fP, \fIzp\fP, \fIad\fP and \fIzd\fP are as for _pac. \fIi\fP is +the index in \fIa\fP where the first element of \fIz\fP is copied into. +Unpack all elements of \fIz\fP. .IP _asz Compute array size. Used for copying conformant arrays. .PD @@ -331,12 +333,13 @@ The compiler allows you to verify assertions. It generates a call to the routine _ass to check the assertion at runtime. Another feature of the compiler is that it enables you to trace the procedure calling sequence. If the correct option is turned on, then -a call to the procedure 'procentry' is generated at the start of each -compiled procedure or function. Likewise, the routine 'procexit' is called +a call to the procedure \fIprocentry\fP is generated at the start of each +compiled procedure or function. Likewise, the routine \fIprocexit\fP is called just before a procedure or function exits. -Default procedure 'procentry' and 'procexit' are available in this library. +Default procedure \fIprocentry\fP +and \fIprocexit\fP are available in this library. .IP _ass 10 -If 'b' is zero, then change eb[0] to 'line' +If \fIb\fP is zero, then change eb[0] to \fIline\fP (to give an error message with source line number) and call the error routine. .PD 0 .IP procentry @@ -489,7 +492,7 @@ Close a file. Closing of files is done for local files when the procedure in which they are declared exits. The compiler only closes local files if they are not part of a structured type. Files allocated in the heap are not closed when they are deallocated. -There is an external routine 'pclose' in libP(VII), that may be called +There is an external routine \fIpclose\fP in libP(VII), that may be called explicitly to do the closing in these cases. Closing may be necessary to flush buffers or to keep the number of simultaneously opened files below NFILES. @@ -548,40 +551,40 @@ fetch the next character first. Write a character, not preceeded by spaces. .IP _wsc Write a character, left padded with spaces up to a field width -of 'w'. +of \fIw\fP. .IP _wri Write an integer, left padded with spaces up to a field width of 6. .IP _wsi Write an integer, left padded with spaces up to a field width -of 'w'. +of \fIw\fP. .IP _wrl Write a long, left padded with spaces up to a field width of 11. .IP _wsl Write a long, left padded with spaces up to a field width -of 'w'. +of \fIw\fP. .IP _wrr Write a real in scientific format, left padded with spaces up to a field width of 13. .IP _wsr Write a real in scientific format, -left padded with spaces up to a field width of 'w'. +left padded with spaces up to a field width of \fIw\fP. .IP _wrf -Write a real in fixed point format, with exactly 'ndigit' digits +Write a real in fixed point format, with exactly \fIndigit\fP digits behind the decimal point, the last one rounded; it is left padded up to -a field width of 'w'. +a field width of \fIw\fP. .IP _wrs -Write a string of length 'l', without additional spaces. +Write a string of length \fIl\fP, without additional spaces. .IP _wss -Write a string of length 'l', left padded up to a field -width of 'w'. +Write a string of length \fIl\fP, left padded up to a field +width of \fIw\fP. .IP _wrb Write a boolean, represented by "true" or "false", left padded up to a field width of 5. .IP _wsb Write a boolean, represented by "true" or "false", left padded -up to a field width of 'w'. +up to a field width of \fIw\fP. .IP _wrz Write a C-type string up to the zero-byte. .IP _wsz @@ -670,7 +673,7 @@ ISO/TC97/SC5-N462, received November 1979. .IP [4] Ed Keizer, "The Amsterdam Compiler Kit reference manual". .br -(try 'nroff /usr/emi/doc/pcref.doc'). +(try \fInroff /usr/emi/doc/pcref.doc\fP). .IP [5] ack(I), pc_pem(VI) .PD @@ -723,7 +726,7 @@ array bound error in pack .IP 70 array bound error in unpack .IP 71 -only positive j in 'i mod j' +only positive j in \fIi mod j\fP .IP 72 file not yet open .IP 73 diff --git a/man/pdp_as.1 b/man/pdp_as.1 index 870f65dc..afd29b02 100644 --- a/man/pdp_as.1 +++ b/man/pdp_as.1 @@ -11,13 +11,13 @@ described in \fIuni_ass\fP(6). .SH SYNTAX .IP registers The pdp11 has seven general registers, numbered r0 through r7. -Of these, r6 is the stack pointer and can also be referenced to by `sp', -r7 is the program counter and has `pc' as synonym. There are also six +Of these, r6 is the stack pointer and can also be referenced to by \fIsp\fP, +r7 is the program counter and has \fIpc\fP as synonym. There are also six floating-point registers fr0 through fr5, but the names r0 through r5 can also be used. From the context will be derived what kind of register is meant. .IP "addressing modes" .nf -.ta 8 16 24 32 40 48 +.ta 8n 16n 24n 32n 40n 48n syntax meaning (name) reg contents of register reg is operand. @@ -75,7 +75,7 @@ in the handbook mentioned below. Synonyms ending in "d" for instructions ending in "f" are not recognized. Some instructions have different names; the mapping is as below. .nf -.ta 8 16 24 32 40 48 +.ta 8n 16n 24n 32n 40n 48n handbook pdp_as @@ -105,7 +105,7 @@ This instruction is synonymous with trap. .SH EXAMPLE An example of pdp11 assembly code. .nf -.ta 8 16 24 32 40 48 +.ta 8n 16n 24n 32n 40n 48n !this is the routine that reads numbers into r0 !the number is terminated by any non digit diff --git a/man/uni_ass.6 b/man/uni_ass.6 index b89b86e6..9161e164 100644 --- a/man/uni_ass.6 +++ b/man/uni_ass.6 @@ -136,9 +136,9 @@ if the number ends with an 'h' it is hexadecimal else if the number starts with '0' it is octal else it's decimal. .fi -Note that the number '0x10h' is an illegal hexadecimal number, -because 'x' is an illegal hexadecimal digit. -The number should be written as '0x10' or '10h'. +Note that the number \fI0x10h\fP is an illegal hexadecimal number, +because \fIx\fP is an illegal hexadecimal digit. +The number should be written as \fI0x10\fP or \fI10h\fP. The range of numbers depends on the machine. A rule of the thumb is that the width of the machine's registers the same is as the number of bits allowed in numbers. @@ -260,7 +260,7 @@ ack(I), arch(I), a.out(V) An example of INtel 8086 assembly code. .sp 2 .nf -.ta 8 16 32 40 48 56 64 +.ta 8n 16n 32n 40n 48n 56n 64n .define begbss .define hol0,.diverr,.reghp .define EIDIVZ diff --git a/man/z8000_as.1 b/man/z8000_as.1 index bf0295af..cb2bb777 100644 --- a/man/z8000_as.1 +++ b/man/z8000_as.1 @@ -10,8 +10,8 @@ described in \fIuni_ass\fP(6). .SH SYNTAX .IP instructions Instruction mnemonics are implemented exactly as described in -`Z8000 PLZ/ASM Assembly Language Programming Manual' and -`AmZ8001/2 Processor Instruction Set'. +\fIZ8000 PLZ/ASM Assembly Language Programming Manual\fP and +\fIAmZ8001/2 Processor Instruction Set\fP. .IP registers The z8000 has sixteen 16-bit general purpose registers specified as R0 through R15. All sixteen registers can be used as accumulators. @@ -24,9 +24,9 @@ indirect, index or base-address register. It is also possible to address registers as groups of 8, 32 or 64 bits. These registers are specified as follows. .nf -.ta 8 16 24 32 40 48 +.ta 8n 16n 24n 32n 40n 48n - RH0, RL0, RH1, RL1, ..., RH7, RL7 for 8-bit regis- - ters. (`H' stands for high-order byte, and `L' stands + ters. (\fIH\fP stands for high-order byte, and \fIL\fP stands for low-order byte within a word register). These registers overlap 16-bit registers R0 through R7. - RR0, RR2, ..., RR14 for 32-bit register pairs. @@ -35,7 +35,7 @@ These registers are specified as follows. Besides register pair RR14 is used as stackpointer. .IP "addressing modes" .nf -.ta 8 16 24 32 40 48 +.ta 8n 16n 24n 32n 40n 48n syntax meaning (name-mnemonic) $expr the value of expr is the operand. @@ -108,7 +108,7 @@ a corresponding `normal' jump/call (JP/CALL). .SH EXAMPLE An example of z8000 assembly code. .nf -.ta 8 16 24 32 40 48 +.ta 8n 16n 24n 32n 40n 48n ! This z8000 assembly routine converts a positive number !(in R1) to a string representing the number and puts this @@ -145,16 +145,16 @@ AmZ8001/2 Processor Instruction Set, 1979. .SH BUGS You cannot use (reg16) instead of 0(reg16). .br -Condition codes `Z' (meaning zero), `C' (meaning carry) and +Condition codes \fIZ\fP (meaning zero), \fIC\fP (meaning carry) and (meaning always false) are not implemented. The first two because they also represent flags and the third one because it's useless. -So for `Z'/`C' use `EQ'/`ULT'. +So for \fIZ\fP/\fIC\fP use \fIEQ\fP/\fIULT\fP. .br The z8000 assembly instruction set as described in the book -`AmZ8001/2 Processor Instruction Set' differs from the one -described in the manual `Z8000 PLZ/ASM Assembly Language Programming -Manual' in that the book includes CLRL, LDL (format F5.1) and +\fIAmZ8001/2 Processor Instruction Set\fP differs from the one +described in the manual \fIZ8000 PLZ/ASM Assembly Language Programming +Manual\fP in that the book includes CLRL, LDL (format F5.1) and PUSHL (format F5.1) which all in fact do not (!) work. .br On the other side the book excludes SIN, SIND, SINDR, SINI, SINIR, diff --git a/man/z80_as.1 b/man/z80_as.1 index b271ed09..be2efb43 100644 --- a/man/z80_as.1 +++ b/man/z80_as.1 @@ -23,11 +23,11 @@ contents of the accumulator and flag register can be exchanged with the contents of their alternates by the "ex af, af2"-instruction. .IP "addressing modes" .nf -.ta 8 16 24 32 40 48 +.ta 8n 16n 24n 32n 40n 48n syntax meaning expr dependent on the instruction, the - value of `expr' can be immediate + value of \fIexpr\fP can be immediate data or the address of the operand. There is no special notation for immediate data. @@ -35,16 +35,16 @@ expr dependent on the instruction, the (ireg + expr) (ireg - expr) the contents of ireg (which must be one of the index-registers) + or - - the - one byte - value of `expr' + the - one byte - value of \fIexpr\fP yield the address of the operand. -(expr) the value of `expr' is the address of +(expr) the value of \fIexpr\fP is the address of the operand. -reg the contents of `reg' - one of the above- +reg the contents of \fIreg\fP - one of the above- mentioned registers - is the operand. -(reg) the contents of `reg' - one of the 16-bit +(reg) the contents of \fIreg\fP - one of the 16-bit registers except pc - is the address of the operand. diff --git a/util/ack/ack.1.X b/util/ack/ack.1.X index 54eef0e8..a55c859e 100644 --- a/util/ack/ack.1.X +++ b/util/ack/ack.1.X @@ -2,9 +2,9 @@ .de SB .\" SuBheader .sp 1 +.PP .nr Sf \\n(.f .ft B -.PP \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9 .ft \\n(Sf .sp 1 @@ -22,6 +22,8 @@ ack \- Amsterdam Compiler Kit .br \fBabc\fP arguments .br +\fBint\fP arguments +.br \fImachine\fP arguments .SH DESCRIPTION This program transforms sources in several @@ -38,7 +40,8 @@ are also automatically included. Two types of load files can be distinguished, \fIa.out\fP files containing machine code and \fIe.out\fP files containing virtual EM machine code. -The last type is designed for interpretation. +The last type is designed for interpretation; it is obtained by calling +the compiler as \fIint\fP. Compilation time for interpretation is fast and gives many runtime checks, but execution is about seven times slower. diff --git a/util/cpp/cpp.6 b/util/cpp/cpp.6 index 38d46ed7..523ff376 100644 --- a/util/cpp/cpp.6 +++ b/util/cpp/cpp.6 @@ -1,5 +1,4 @@ -.TH -.I cpp +.TH CPP VI .SH NAME cpp \- C Pre-Processor .SH SYNOPSIS @@ -154,7 +153,7 @@ message handling. The following extensions to C are processed by cpp: .nf .sp 1 -.ta 4 27 +.ta 4n 27n #elif expression (#else #if) '\exNNN' (Hexadecimal constants) '\ea' (Ascii BELL) From 2e33b81ce65808c7563cc36d40327af88763b59f Mon Sep 17 00:00:00 2001 From: sater Date: Fri, 24 Jan 1986 16:08:34 +0000 Subject: [PATCH 0105/1625] Hex numbers didn't work. Corrected bug in myatoi(). --- util/ncgg/subr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/ncgg/subr.c b/util/ncgg/subr.c index 6ad80f47..fff05680 100644 --- a/util/ncgg/subr.c +++ b/util/ncgg/subr.c @@ -319,7 +319,7 @@ int myatoi(s) register char *s; { case 'e': case 'f': if (base!=16) error("Hexletter in number not expected"); - sum = sum*base + *s++ - 'a'; + sum = sum*base + 10 + *s++ - 'a'; break; case 'A': case 'B': @@ -328,7 +328,7 @@ int myatoi(s) register char *s; { case 'E': case 'F': if (base!=16) error("Hexletter in number not expected"); - sum = sum*base + *s++ - 'A'; + sum = sum*base + 10 + *s++ - 'A'; break; } } From d72f604a96fa674126e89f7ac02125a57c2f7efd Mon Sep 17 00:00:00 2001 From: em Date: Mon, 3 Feb 1986 14:30:19 +0000 Subject: [PATCH 0106/1625] fixed bug in number() -- hex letters mistreated --- util/led/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util/led/main.c b/util/led/main.c index 30cbd246..131e2c04 100644 --- a/util/led/main.c +++ b/util/led/main.c @@ -208,11 +208,11 @@ number(s) } while (digit = *s++) { if (digit >= 'A' && digit <= 'F') - digit -= 'A' + 10; + digit = digit - 'A' + 10; else if (digit >= 'a' && digit <= 'f') - digit -= 'a' + 10; + digit = digit - 'a' + 10; else if (digit >= '0' && digit <= '9') - digit -= '0'; + digit = digit - '0'; else fatal("wrong digit %c", digit); if (digit >= radix) From 80fd35f73661a353261cd3412db17acd3f2624d7 Mon Sep 17 00:00:00 2001 From: dick Date: Tue, 4 Feb 1986 17:37:41 +0000 Subject: [PATCH 0107/1625] updated for photo-typesetter --- doc/em/Makefile | 15 +- doc/em/READ_ME | 8 +- doc/em/app.codes.nr | 210 ++ doc/em/app.exam.nr | 270 +++ doc/em/app.int.nr | 8 + doc/em/assem.nr | 354 ++-- doc/em/cont.nr | 6 + doc/em/descr.nr | 13 +- doc/em/dspace.nr | 20 +- doc/em/env.nr | 209 ++ doc/em/intro.nr | 8 +- doc/em/ip.awk | 17 +- doc/em/itables | 4691 +++++++++++++++++++++++-------------------- doc/em/mach.nr | 56 +- doc/em/macr.nr | 28 +- doc/em/mapping.nr | 41 +- doc/em/title.nr | 2 +- doc/em/traps.nr | 171 ++ doc/em/types.nr | 17 +- 19 files changed, 3724 insertions(+), 2420 deletions(-) create mode 100644 doc/em/app.codes.nr create mode 100644 doc/em/app.exam.nr create mode 100644 doc/em/app.int.nr create mode 100644 doc/em/cont.nr create mode 100644 doc/em/env.nr create mode 100644 doc/em/traps.nr diff --git a/doc/em/Makefile b/doc/em/Makefile index 81cc36dc..b9dee4cb 100644 --- a/doc/em/Makefile +++ b/doc/em/Makefile @@ -1,11 +1,14 @@ head: doc.pr NROFF=nroff -FILES = macr.nr title.nr intro.nr mem.nr ispace.nr dspace.nr mapping.nr types.nr descr.nr iotrap.nr mach.nr assem.nr app.nr +TBL=tbl +FILES = macr.nr title.nr intro.nr mem.nr ispace.nr dspace.nr mapping.nr \ + types.nr descr.nr env.nr traps.nr mach.nr assem.nr \ + app.int.nr app.codes.nr app.exam.nr cont.nr IOP=../../util/ass/ip_spec.t -doc.pr: $(FILES) itables em.i - tbl $(FILES) | $(NROFF) >doc.pr +doc.pr: $(FILES) itables em.i Makefile + $(TBL) $(FILES) | $(NROFF) >doc.pr distr: $(FILES) itables em.i tbl $(FILES) | nroff -Tlp >doc.pr @@ -22,10 +25,10 @@ app.t: itables em.i em.i: int/em.p @echo Sorry, this copy was edited by hand from int/em.p -itables: $(IOP) - awk -f ip.awk $(IOP) | tbl >itables +itables: $(IOP) ip.awk + awk -f ip.awk $(IOP) | sed 's/-/\\-/g" | $(TBL) >itables .SUFFIXES : .pr .nr -.nr.pr: ; tbl macr.nr $*.nr | $(NROFF) >$@ +.nr.pr: ; $(TBL) macr.nr $*.nr | $(NROFF) >$@ cont.t intro.t mem.t ispace.t dspace.t mapping.t succ.t descr.t iotrap.t mach.t assem.t kern.t app.t: macr.nr diff --git a/doc/em/READ_ME b/doc/em/READ_ME index 1511d1dd..23001bcf 100644 --- a/doc/em/READ_ME +++ b/doc/em/READ_ME @@ -1 +1,7 @@ -Sorry, the kun macro package is not ours to distribute. +This it the text of IR-81, +DESCRIPTION OF A MACHINE ARCHITECTURE FOR USE WITH BLOCK STRUCTURED LANGUAGES + +To print, set NROFF and TBL in the Makefile and call make. +It uses the kun macro package which is also distributed. + +The directory int contains the interpreter. diff --git a/doc/em/app.codes.nr b/doc/em/app.codes.nr new file mode 100644 index 00000000..2e511ec5 --- /dev/null +++ b/doc/em/app.codes.nr @@ -0,0 +1,210 @@ +.BP +.AP "EM CODE TABLES" +The following table is used by the assembler for EM machine +language. +It specifies the opcodes used for each instruction and +how arguments are mapped to machine language arguments. +The table is presented in three columns, +each line in each column contains three or four fields. +Each line describes a range of interpreter opcodes by +specifying for which instruction the range is used, the type of the +opcodes (mini, shortie, etc..) and range for the instruction +argument. +.A +The first field on each line gives the EM instruction mnemonic, +the second field gives some flags. +If the opcodes are minis or shorties the third field specifies +how many minis/shorties are used. +The last field gives the number of the (first) interpreter +opcode. +.N 1 +Flags : +.IS 3 +.N 1 +Opcode type, only one of the following may be specified. +.PS - 5 " " +.PT \- +opcode without argument +.PT m +mini +.PT s +shortie +.PT 2 +opcode with 2-byte signed argument +.PT 4 +opcode with 4-byte signed argument +.PT 8 +opcode with 8-byte signed argument +.PE +Secondary (escaped) opcodes. +.PS - 5 " " +.PT e +The opcode thus marked is in the secondary opcode group instead +of the primary +.PE +restrictions on arguments +.PS - 5 " " +.PT N +Negative arguments only +.PT P +Positive and zero arguments only +.PE +mapping of arguments +.PS - 5 " " +.PT w +argument must be divisible by the wordsize and is divided by the +wordsize before use as opcode argument. +.PT o +argument ( possibly after division ) must be >= 1 and is +decremented before use as opcode argument +.PE +.IE +If the opcode type is 2,4 or 8 the resulting argument is used as +opcode argument (least significant byte first). +.N +If the opcode type is mini, the argument is added +to the first opcode \- if in range \- . +If the argument is negative, the absolute value minus one is +used in the algorithm above. +.N +For shorties with positive arguments the first opcode is used +for arguments in the range 0..255, the second for the range +256..511, etc.. +For shorties with negative arguments the first opcode is used +for arguments in the range \-1..\-256, the second for the range +\-257..\-512, etc.. +The byte following the opcode contains the least significant +byte of the argument. +First some examples of these specifications. +.PS - 5 +.PT "aar mwPo 1 34" +Indicates that opcode 34 is used as a mini for Positive +instruction arguments only. +The w and o indicate division and decrementing of the +instruction argument. +Because the resulting argument must be zero ( only opcode 34 may be used +), this mini can only be used for instruction argument 2. +Conclusion: opcode 34 is for "AAR 2". +.PT "adp sP 1 41" +Opcode 41 is used as shortie for ADP with arguments in the range +0..255. +.PT "bra sN 2 60" +Opcode 60 is used as shortie for BRA with arguments \-1..\-256, +61 is used for arguments \-257..\-512. +.PT "zer e\- 145" +Escaped opcode 145 is used for ZER. +.PE +The interpreter opcode table: +.N 1 +.IS 3 +.DS B +.so itables +.DE 0 +.IE +.P +The table above results in the following dispatch tables. +Dispatch tables are used by interpreters to jump to the +routines implementing the EM instructions, indexed by the next opcode. +Each line of the dispatch tables gives the routine names +of eight consecutive opcodes, preceded by the first opcode number +on that line. +Routine names consist of an EM mnemonic followed by a suffix. +The suffices show the encoding used for each opcode. +.N +The following suffices exist: +.N 1 +.VS 1 0 +.IS 4 +.PS - 11 +.PT .z +no arguments +.PT .l +16-bit argument +.PT .lw +16-bit argument divided by the wordsize +.PT .p +positive 16-bit argument +.PT .pw +positive 16-bit argument divided by the wordsize +.PT .n +negative 16-bit argument +.PT .nw +negative 16-bit argument divided by the wordsize +.PT .s +shortie with as high order argument byte +.PT .sw +shortie with argument divided by the wordsize +.PT . +mini with as argument +.PT .W +mini with *wordsize as argument +.PE 3 + is a possibly negative integer. +.VS 1 1 +.IE +The dispatch table for the 256 primary opcodes: +.DS B +.ta 7n 16n 25n 34n 43n 52n 61n 70n + 0 loc.0 loc.1 loc.2 loc.3 loc.4 loc.5 loc.6 loc.7 + 8 loc.8 loc.9 loc.10 loc.11 loc.12 loc.13 loc.14 loc.15 + 16 loc.16 loc.17 loc.18 loc.19 loc.20 loc.21 loc.22 loc.23 + 24 loc.24 loc.25 loc.26 loc.27 loc.28 loc.29 loc.30 loc.31 + 32 loc.32 loc.33 aar.1W adf.s0 adi.1W adi.2W adp.l adp.1 + 40 adp.2 adp.s0 adp.s\-1 ads.1W and.1W asp.1W asp.2W asp.3W + 48 asp.4W asp.5W asp.w0 beq.l beq.s0 bge.s0 bgt.s0 ble.s0 + 56 blm.s0 blt.s0 bne.s0 bra.l bra.s\-1 bra.s\-2 bra.s0 bra.s1 + 64 cal.1 cal.2 cal.3 cal.4 cal.5 cal.6 cal.7 cal.8 + 72 cal.9 cal.10 cal.11 cal.12 cal.13 cal.14 cal.15 cal.16 + 80 cal.17 cal.18 cal.19 cal.20 cal.21 cal.22 cal.23 cal.24 + 88 cal.25 cal.26 cal.27 cal.28 cal.s0 cff.z cif.z cii.z + 96 cmf.s0 cmi.1W cmi.2W cmp.z cms.s0 csa.1W csb.1W dec.z + 104 dee.w0 del.w\-1 dup.1W dvf.s0 dvi.1W fil.l inc.z ine.lw + 112 ine.w0 inl.\-1W inl.\-2W inl.\-3W inl.w\-1 inn.s0 ior.1W ior.s0 + 120 lae.l lae.w0 lae.w1 lae.w2 lae.w3 lae.w4 lae.w5 lae.w6 + 128 lal.p lal.n lal.0 lal.\-1 lal.w0 lal.w\-1 lal.w\-2 lar.W + 136 ldc.0 lde.lw lde.w0 ldl.0 ldl.w\-1 lfr.1W lfr.2W lfr.s0 + 144 lil.w\-1 lil.w0 lil.0 lil.1W lin.l lin.s0 lni.z loc.l + 152 loc.\-1 loc.s0 loc.s\-1 loe.lw loe.w0 loe.w1 loe.w2 loe.w3 + 160 loe.w4 lof.l lof.1W lof.2W lof.3W lof.4W lof.s0 loi.l + 168 loi.1 loi.1W loi.2W loi.3W loi.4W loi.s0 lol.pw lol.nw + 176 lol.0 lol.1W lol.2W lol.3W lol.\-1W lol.\-2W lol.\-3W lol.\-4W + 184 lol.\-5W lol.\-6W lol.\-7W lol.\-8W lol.w0 lol.w\-1 lxa.1 lxl.1 + 192 lxl.2 mlf.s0 mli.1W mli.2W rck.1W ret.0 ret.1W ret.s0 + 200 rmi.1W sar.1W sbf.s0 sbi.1W sbi.2W sdl.w\-1 set.s0 sil.w\-1 + 208 sil.w0 sli.1W ste.lw ste.w0 ste.w1 ste.w2 stf.l stf.W + 216 stf.2W stf.s0 sti.1 sti.1W sti.2W sti.3W sti.4W sti.s0 + 224 stl.pw stl.nw stl.0 stl.1W stl.\-1W stl.\-2W stl.\-3W stl.\-4W + 232 stl.\-5W stl.w\-1 teq.z tgt.z tlt.z tne.z zeq.l zeq.s0 + 240 zeq.s1 zer.s0 zge.s0 zgt.s0 zle.s0 zlt.s0 zne.s0 zne.s\-1 + 248 zre.lw zre.w0 zrl.\-1W zrl.\-2W zrl.w\-1 zrl.nw escape1 escape2 +.DE 2 +The list of secondary opcodes (escape1): +.N 1 +.DS B +.ta 7n 16n 25n 34n 43n 52n 61n 70n + 0 aar.l aar.z adf.l adf.z adi.l adi.z ads.l ads.z + 8 adu.l adu.z and.l and.z asp.lw ass.l ass.z bge.l + 16 bgt.l ble.l blm.l bls.l bls.z blt.l bne.l cai.z + 24 cal.l cfi.z cfu.z ciu.z cmf.l cmf.z cmi.l cmi.z + 32 cms.l cms.z cmu.l cmu.z com.l com.z csa.l csa.z + 40 csb.l csb.z cuf.z cui.z cuu.z dee.lw del.pw del.nw + 48 dup.l dus.l dus.z dvf.l dvf.z dvi.l dvi.z dvu.l + 56 dvu.z fef.l fef.z fif.l fif.z inl.pw inl.nw inn.l + 64 inn.z ior.l ior.z lar.l lar.z ldc.l ldf.l ldl.pw + 72 ldl.nw lfr.l lil.pw lil.nw lim.z los.l los.z lor.s0 + 80 lpi.l lxa.l lxl.l mlf.l mlf.z mli.l mli.z mlu.l + 88 mlu.z mon.z ngf.l ngf.z ngi.l ngi.z nop.z rck.l + 96 rck.z ret.l rmi.l rmi.z rmu.l rmu.z rol.l rol.z + 104 ror.l ror.z rtt.z sar.l sar.z sbf.l sbf.z sbi.l + 112 sbi.z sbs.l sbs.z sbu.l sbu.z sde.l sdf.l sdl.pw + 120 sdl.nw set.l set.z sig.z sil.pw sil.nw sim.z sli.l + 128 sli.z slu.l slu.z sri.l sri.z sru.l sru.z sti.l + 136 sts.l sts.z str.s0 tge.z tle.z trp.z xor.l xor.z + 144 zer.l zer.z zge.l zgt.l zle.l zlt.l zne.l zrf.l + 152 zrf.z zrl.pw dch.z exg.s0 exg.l exg.z lpb.z gto.l +.DE 2 +Finally, the list of opcodes with four byte arguments (escape2). +.DS +.ta 7n 16n 25n 34n 43n 52n 61n 70n + 0 loc +.DE 0 diff --git a/doc/em/app.exam.nr b/doc/em/app.exam.nr new file mode 100644 index 00000000..109d25b7 --- /dev/null +++ b/doc/em/app.exam.nr @@ -0,0 +1,270 @@ +.BP +.AP "AN EXAMPLE PROGRAM" +.DS B +.ta 4n 8n 12n 16n 20n + 1 program example(output); + 2 {This program just demonstrates typical EM code.} + 3 type rec = record r1: integer; r2:real; r3: boolean end; + 4 var mi: integer; mx:real; r:rec; + 5 + 6 function sum(a,b:integer):integer; + 7 begin + 8 sum := a + b + 9 end; +10 +11 procedure test(var r: rec); +12 label 1; +13 var i,j: integer; +14 x,y: real; +15 b: boolean; +16 c: char; +17 a: array[1..100] of integer; +18 +19 begin +20 j := 1; +21 i := 3 * j + 6; +22 x := 4.8; +23 y := x/0.5; +24 b := true; +25 c := 'z'; +26 for i:= 1 to 100 do a[i] := i * i; +27 r.r1 := j+27; +28 r.r3 := b; +29 r.r2 := x+y; +30 i := sum(r.r1, a[j]); +31 while i > 0 do begin j := j + r.r1; i := i - 1 end; +32 with r do begin r3 := b; r2 := x+y; r1 := 0 end; +33 goto 1; +34 1: writeln(j, i:6, x:9:3, b) +35 end; {test} +36 begin {main program} +37 mx := 15.96; +38 mi := 99; +39 test(r) +40 end. +.DE 0 +.BP +The EM code as produced by the Pascal-VU compiler is given below. Comments +have been added manually. Note that this code has already been optimized. +.DS B +.ta 1n 24n + mes 2,2,2 ; wordsize 2, pointersize 2 +.1 + rom 't.p\e000' ; the name of the source file + hol 552,\-32768,0 ; externals and buf occupy 552 bytes + exp $sum ; sum can be called from other modules + pro $sum,2 ; procedure sum ; 2 bytes local storage + lin 8 ; code from source line 8 + ldl 0 ; load two locals ( a and b ) + adi 2 ; add them + ret 2 ; return the result + end 2 ; end of procedure ( still two bytes local storage ) +.2 + rom 1,99,2 ; descriptor of array a[] + exp $test ; the compiler exports all level 0 procedures + pro $test,226 ; procedure test, 226 bytes local storage +.3 + rom 4.8F8 ; assemble Floating point 4.8 (8 bytes) in +.4 ; global storage + rom 0.5F8 ; same for 0.5 + mes 3,\-226,2,2 ; compiler temporary not referenced by address + mes 3,\-24,2,0 ; the same is true for i, j, b and c in test + mes 3,\-22,2,0 + mes 3,\-4,2,0 + mes 3,\-2,2,0 + mes 3,\-20,8,0 ; and for x and y + mes 3,\-12,8,0 + lin 20 ; maintain source line number + loc 1 + stl \-4 ; j := 1 + lni ; lin 21 prior to optimization + lol \-4 + loc 3 + mli 2 + loc 6 + adi 2 + stl \-2 ; i := 3 * j + 6 + lni ; lin 22 prior to optimization + lae .3 + loi 8 + lal \-12 + sti 8 ; x := 4.8 + lni ; lin 23 prior to optimization + lal \-12 + loi 8 + lae .4 + loi 8 + dvf 8 + lal \-20 + sti 8 ; y := x / 0.5 + lni ; lin 24 prior to optimization + loc 1 + stl \-22 ; b := true + lni ; lin 25 prior to optimization + loc 122 + stl \-24 ; c := 'z' + lni ; lin 26 prior to optimization + loc 1 + stl \-2 ; for i:= 1 + 2 + lol \-2 + dup 2 + mli 2 ; i*i + lal \-224 + lol \-2 + lae .2 + sar 2 ; a[i] := + lol \-2 + loc 100 + beq *3 ; to 100 do + inl \-2 ; increment i and loop + bra *2 + 3 + lin 27 + lol \-4 + loc 27 + adi 2 ; j + 27 + sil 0 ; r.r1 := + lni ; lin 28 prior to optimization + lol \-22 ; b + lol 0 + stf 10 ; r.r3 := + lni ; lin 29 prior to optimization + lal \-20 + loi 16 + adf 8 ; x + y + lol 0 + adp 2 + sti 8 ; r.r2 := + lni ; lin 23 prior to optimization + lal \-224 + lol \-4 + lae .2 + lar 2 ; a[j] + lil 0 ; r.r1 + cal $sum ; call now + asp 4 ; remove parameters from stack + lfr 2 ; get function result + stl \-2 ; i := + 4 + lin 31 + lol \-2 + zle *5 ; while i > 0 do + lol \-4 + lil 0 + adi 2 + stl \-4 ; j := j + r.r1 + del \-2 ; i := i - 1 + bra *4 ; loop + 5 + lin 32 + lol 0 + stl \-226 ; make copy of address of r + lol \-22 + lol \-226 + stf 10 ; r3 := b + lal \-20 + loi 16 + adf 8 + lol \-226 + adp 2 + sti 8 ; r2 := x + y + loc 0 + sil \-226 ; r1 := 0 + lin 34 ; note the abscence of the unnecesary jump + lae 22 ; address of output structure + lol \-4 + cal $_wri ; write integer with default width + asp 4 ; pop parameters + lae 22 + lol \-2 + loc 6 + cal $_wsi ; write integer width 6 + asp 6 + lae 22 + lal \-12 + loi 8 + loc 9 + loc 3 + cal $_wrf ; write fixed format real, width 9, precision 3 + asp 14 + lae 22 + lol \-22 + cal $_wrb ; write boolean, default width + asp 4 + lae 22 + cal $_wln ; writeln + asp 2 + ret 0 ; return, no result + end 226 + exp $_main + pro $_main,0 ; main program +.6 + con 2,\-1,22 ; description of external files +.5 + rom 15.96F8 + fil .1 ; maintain source file name + lae .6 ; description of external files + lae 0 ; base of hol area to relocate buffer addresses + cal $_ini ; initialize files, etc... + asp 4 + lin 37 + lae .5 + loi 8 + lae 2 + sti 8 ; mx := 15.96 + lni ; lin 38 prior to optimization + loc 99 + ste 0 ; mi := 99 + lni ; lin 39 prior to optimization + lae 10 ; address of r + cal $test + asp 2 + loc 0 ; normal exit + cal $_hlt ; cleanup and finish + asp 2 + end 0 + mes 5 ; reals were used +.DE 0 +The compact code corresponding to the above program is listed below. +Read it horizontally, line by line, not column by column. +Each number represents a byte of compact code, printed in decimal. +The first two bytes form the magic word. +.N 1 +.IS 3 +.Dr 33 + 173 0 159 122 122 122 255 242 1 161 250 124 116 46 112 0 + 255 156 245 40 2 245 0 128 120 155 249 123 115 117 109 160 + 249 123 115 117 109 122 67 128 63 120 3 122 88 122 152 122 + 242 2 161 121 219 122 255 155 249 124 116 101 115 116 160 249 + 124 116 101 115 116 245 226 0 242 3 161 253 128 123 52 46 + 56 255 242 4 161 253 128 123 48 46 53 255 159 123 245 30 + 255 122 122 255 159 123 96 122 120 255 159 123 98 122 120 255 + 159 123 116 122 120 255 159 123 118 122 120 255 159 123 100 128 + 120 255 159 123 108 128 120 255 67 140 69 121 113 116 68 73 + 116 69 123 81 122 69 126 3 122 113 118 68 57 242 3 72 + 128 58 108 112 128 68 58 108 72 128 57 242 4 72 128 44 + 128 58 100 112 128 68 69 121 113 98 68 69 245 122 0 113 + 96 68 69 121 113 118 182 73 118 42 122 81 122 58 245 32 + 255 73 118 57 242 2 94 122 73 118 69 220 10 123 54 118 + 18 122 183 67 147 73 116 69 147 3 122 104 120 68 73 98 + 73 120 111 130 68 58 100 72 136 2 128 73 120 4 122 112 + 128 68 58 245 32 255 73 116 57 242 2 59 122 65 120 20 + 249 123 115 117 109 8 124 64 122 113 118 184 67 151 73 118 + 128 125 73 116 65 120 3 122 113 116 41 118 18 124 185 67 + 152 73 120 113 245 30 255 73 98 73 245 30 255 111 130 58 + 100 72 136 2 128 73 245 30 255 4 122 112 128 69 120 104 + 245 30 255 67 154 57 142 73 116 20 249 124 95 119 114 105 + 8 124 57 142 73 118 69 126 20 249 124 95 119 115 105 8 + 126 57 142 58 108 72 128 69 129 69 123 20 249 124 95 119 + 114 102 8 134 57 142 73 98 20 249 124 95 119 114 98 8 + 124 57 142 20 249 124 95 119 108 110 8 122 88 120 152 245 + 226 0 155 249 125 95 109 97 105 110 160 249 125 95 109 97 + 105 110 120 242 6 151 122 119 142 255 242 5 161 253 128 125 + 49 53 46 57 54 255 50 242 1 57 242 6 57 120 20 249 + 124 95 105 110 105 8 124 67 157 57 242 5 72 128 57 122 + 112 128 68 69 219 110 120 68 57 130 20 249 124 116 101 115 + 116 8 122 69 120 20 249 124 95 104 108 116 8 122 152 120 + 159 124 160 255 159 125 255 +.De +.IE diff --git a/doc/em/app.int.nr b/doc/em/app.int.nr new file mode 100644 index 00000000..d77adde1 --- /dev/null +++ b/doc/em/app.int.nr @@ -0,0 +1,8 @@ +.BP +.AP "EM INTERPRETER" +.nf +.ft CW +.ta 8 16 24 32 40 48 56 64 72 80 +.so em.i +.ft P +.fi diff --git a/doc/em/assem.nr b/doc/em/assem.nr index c1987f6e..a22443f3 100644 --- a/doc/em/assem.nr +++ b/doc/em/assem.nr @@ -34,7 +34,7 @@ The scope of an instruction label is its procedure. .A The pseudoinstructions CON, ROM and BSS may be preceded by a line containing a -1-8 character data label, the first character of which is a +1\-8 character data label, the first character of which is a letter, period or underscore. The period may only be followed by digits, the others may be followed by letters, digits and underscores. @@ -66,7 +66,7 @@ They do not belong to a specific procedure. All constants in EM are interpreted in the decimal base. The ASCII assembly language accepts constant expressions wherever constants are allowed. -The operators recognized are: +, -, *, % and / with the usual +The operators recognized are: +, \-, *, % and / with the usual precedence order. Use of the parentheses ( and ) to alter the precedence order is allowed. .S3 "Instruction arguments" @@ -109,16 +109,16 @@ integers on top of the stack are to be compared. on top of the stack that specifies the size of the integers to be compared. Thus the following two sequences are equivalent: -.N 2 +.N 1 .TS center, tab(:) ; l r 30 l r. -LDL:-10:LDL:-10 -LDL:-14:LDL:-14 +LDL:\-10:LDL:\-10 +LDL:\-14:LDL:\-14 ::LOC:4 CMI:4:CMI: ZEQ:*1:ZEQ:*1 -.TE 2 +.TE 1 Section 11.1.6 shows the arguments allowed for each instruction. .S3 "Pseudoinstruction arguments" Pseudoinstruction arguments can be divided in two classes: @@ -139,7 +139,7 @@ initializer's size. This integer is governed by the same restrictions as for transfer of objects to/from memory. As in instruction arguments, initializers include expressions of the form: -\&"LABEL+offset" and "LABEL-offset". +\&"LABEL+offset" and "LABEL\-offset". The offset must be an unsigned decimal constant. The 'IUF' indicators cannot be used in the offsets. .P @@ -167,7 +167,7 @@ double quote:":\e" bit pattern:\fBddd\fP:\e\fBddd\fP .TE .DE -The escape \fBddd\fP consists of the backslash followed by 1, +The escape \fB\eddd\fP consists of the backslash followed by 1, 2, or 3 octal digits specifing the value of the desired character. If the character following a backslash is not one of those @@ -190,9 +190,9 @@ instructions and pseudoinstructions. .TS tab(:); l l l. -:\&=:integer constant (current range -2**31..2**31-1) +:\&=:integer constant (current range \-2**31..2**31\-1) :\&=:data label -:\&=: or or + or - +:\&=: or or + or \- :\&=:integer constant, unsigned constant, floating-point constant :\&=:string constant (surrounded by double quotes), :\&=:instruction label @@ -425,13 +425,13 @@ etc. represent the succeeding bytes. tab(:) ; rw17 4 l. 0:Reserved for future use -1-129:Machine instructions, see Appendix A, alphabetical list -130-149:Reserved for future use -150-161:BSS,CON,END,EXA,EXC,EXP,HOL,INA,INP,MES,PRO,ROM -162-179:Reserved for future pseudoinstructions -180-239:Instruction labels 0 - 59 (180 is local label 0 etc.) -240-244:See the Common Table below -245-255:Not used +1\-129:Machine instructions, see Appendix A, alphabetical list +130\-149:Reserved for future use +150\-161:BSS,CON,END,EXA,EXC,EXP,HOL,INA,INP,MES,PRO,ROM +162\-179:Reserved for future pseudoinstructions +180\-239:Instruction labels 0 \- 59 (180 is local label 0 etc.) +240\-244:See the Common Table below +245\-255:Not used .TE 1 .DE 0 After a label, the assembler is back in neutral state; it can immediately @@ -449,9 +449,9 @@ encoded as follows: .TS tab(:); r l. -0-239:Offsets from -120 to 119 +0\-239:Offsets from \-120 to 119 -240-255:See the Common Table below +240\-255:See the Common Table below .TE 1 Absence of an optional argument is indicated by a special byte. @@ -467,8 +467,8 @@ class:bytes:description :240:b1:Instruction label b1 (Not used for branches) :241:b1 b2:16 bit instruction label (256*b2 + b1) -:242:b1:Global label .0-.255, with b1 being the label -:243:b1 b2:Global label .0-.32767 +:242:b1:Global label .0\-.255, with b1 being the label +:243:b1 b2:Global label .0\-.32767 :::with 256*b2+b1 being the label :244::Global symbol not of the form .nnn :245:b1 b2:16 bit constant @@ -488,7 +488,7 @@ class:bytes:description The bytes specifying the value of a 16, 32 or 64 bit constant are presented in two's complement notation, with the least significant byte first. For example: the value of a 32 bit -constant is ((s4*256+b3)*256+b2)*256+b1, where s4 is b4-256 if +constant is ((s4*256+b3)*256+b2)*256+b1, where s4 is b4\-256 if b4 is greater than 128 else s4 takes the value of b4. A consists of a inmediatly followed by a sequence of bytes with length . @@ -498,10 +498,10 @@ The pseudoinstructions fall into several categories, depending on their arguments: .N 1 .DS - Group 1 -- EXC, BSS, HOL have a known number of arguments - Group 2 -- EXA, EXP, INA, INP have a string as argument - Group 3 -- CON, MES, ROM have a variable number of various things - Group 4 -- END, PRO have a trailing optional argument. + Group 1 \- EXC, BSS, HOL have a known number of arguments + Group 2 \- EXA, EXP, INA, INP have a string as argument + Group 3 \- CON, MES, ROM have a variable number of various things + Group 4 \- END, PRO have a trailing optional argument. .DE 1 Groups 1 and 2 use the encoding described above. @@ -522,7 +522,7 @@ Example ASCII|Example compact 2||182 1||181 LOC|10|69 130 - LOC|-10|69 110 + LOC|\-10|69 110 LOC|300|69 245 44 1 BRA|*19|18 139 300||241 44 1 @@ -531,7 +531,6 @@ Example ASCII|Example compact CON|.35|151 242 35 255 .TE 0 .IE 0 -.BP .S2 "Assembly language instruction list" .P For each instruction in the list the range of argument values @@ -556,7 +555,7 @@ are indicated by letters: .ds s \fBs\fP .ds z \fBz\fP .ds o \fBo\fP -.ds - \fB-\fP +.ds - \fB\-\fP .N 1 .TS tab(:); @@ -590,184 +589,185 @@ values and underflow or overflow are indicated below by (*). .N 1 .DS B -GROUP 1 - LOAD +.ta 12n +GROUP 1 \- LOAD - LOC \*c : Load constant (i.e. push one word onto the stack) - LDC \*d : Load double constant ( push two words ) - LOL \*l : Load word at \*l-th local (\*l<0) or parameter (\*l>=0) - LOE \*g : Load external word \*g - LIL \*l : Load word pointed to by \*l-th local or parameter - LOF \*f : Load offsetted (top of stack + \*f yield address) - LAL \*l : Load address of local or parameter - LAE \*g : Load address of external - LXL \*n : Load lexical (address of LB \*n static levels back) - LXA \*n : Load lexical (address of AB \*n static levels back) - LOI \*o : Load indirect \*o bytes (address is popped from the stack) - LOS \*w : Load indirect, \*w-byte integer on top of stack gives object size - LDL \*l : Load double local or parameter (two consecutive words are stacked) - LDE \*g : Load double external (two consecutive externals are stacked) - LDF \*f : Load double offsetted (top of stack + \*f yield address) - LPI \*p : Load procedure identifier + LOC \*c : Load constant (i.e. push one word onto the stack) + LDC \*d : Load double constant ( push two words ) + LOL \*l : Load word at \*l-th local (\*l<0) or parameter (\*l>=0) + LOE \*g : Load external word \*g + LIL \*l : Load word pointed to by \*l-th local or parameter + LOF \*f : Load offsetted (top of stack + \*f yield address) + LAL \*l : Load address of local or parameter + LAE \*g : Load address of external + LXL \*n : Load lexical (address of LB \*n static levels back) + LXA \*n : Load lexical (address of AB \*n static levels back) + LOI \*o : Load indirect \*o bytes (address is popped from the stack) + LOS \*w : Load indirect, \*w-byte integer on top of stack gives object size + LDL \*l : Load double local or parameter (two consecutive words are stacked) + LDE \*g : Load double external (two consecutive externals are stacked) + LDF \*f : Load double offsetted (top of stack + \*f yield address) + LPI \*p : Load procedure identifier -GROUP 2 - STORE +GROUP 2 \- STORE - STL \*l : Store local or parameter - STE \*g : Store external - SIL \*l : Store into word pointed to by \*l-th local or parameter - STF \*f : Store offsetted - STI \*o : Store indirect \*o bytes (pop address, then data) - STS \*w : Store indirect, \*w-byte integer on top of stack gives object size - SDL \*l : Store double local or parameter - SDE \*g : Store double external - SDF \*f : Store double offsetted + STL \*l : Store local or parameter + STE \*g : Store external + SIL \*l : Store into word pointed to by \*l-th local or parameter + STF \*f : Store offsetted + STI \*o : Store indirect \*o bytes (pop address, then data) + STS \*w : Store indirect, \*w-byte integer on top of stack gives object size + SDL \*l : Store double local or parameter + SDE \*g : Store double external + SDF \*f : Store double offsetted -GROUP 3 - INTEGER ARITHMETIC +GROUP 3 \- INTEGER ARITHMETIC - ADI \*w : Addition (*) - SBI \*w : Subtraction (*) - MLI \*w : Multiplication (*) - DVI \*w : Division (*) - RMI \*w : Remainder (*) - NGI \*w : Negate (two's complement) (*) - SLI \*w : Shift left (*) - SRI \*w : Shift right (*) + ADI \*w : Addition (*) + SBI \*w : Subtraction (*) + MLI \*w : Multiplication (*) + DVI \*w : Division (*) + RMI \*w : Remainder (*) + NGI \*w : Negate (two's complement) (*) + SLI \*w : Shift left (*) + SRI \*w : Shift right (*) -GROUP 4 - UNSIGNED ARITHMETIC +GROUP 4 \- UNSIGNED ARITHMETIC - ADU \*w : Addition - SBU \*w : Subtraction - MLU \*w : Multiplication - DVU \*w : Division - RMU \*w : Remainder - SLU \*w : Shift left - SRU \*w : Shift right + ADU \*w : Addition + SBU \*w : Subtraction + MLU \*w : Multiplication + DVU \*w : Division + RMU \*w : Remainder + SLU \*w : Shift left + SRU \*w : Shift right -GROUP 5 - FLOATING POINT ARITHMETIC +GROUP 5 \- FLOATING POINT ARITHMETIC - ADF \*w : Floating add (*) - SBF \*w : Floating subtract (*) - MLF \*w : Floating multiply (*) - DVF \*w : Floating divide (*) - NGF \*w : Floating negate (*) - FIF \*w : Floating multiply and split integer and fraction part (*) - FEF \*w : Split floating number in exponent and fraction part (*) + ADF \*w : Floating add (*) + SBF \*w : Floating subtract (*) + MLF \*w : Floating multiply (*) + DVF \*w : Floating divide (*) + NGF \*w : Floating negate (*) + FIF \*w : Floating multiply and split integer and fraction part (*) + FEF \*w : Split floating number in exponent and fraction part (*) -GROUP 6 - POINTER ARITHMETIC +GROUP 6 \- POINTER ARITHMETIC - ADP \*f : Add \*f to pointer on top of stack - ADS \*w : Add \*w-byte value and pointer - SBS \*w : Subtract pointers in same fragment and push diff as size \*w integer + ADP \*f : Add \*f to pointer on top of stack + ADS \*w : Add \*w-byte value and pointer + SBS \*w : Subtract pointers in same fragment and push diff as size \*w integer -GROUP 7 - INCREMENT/DECREMENT/ZERO +GROUP 7 \- INCREMENT/DECREMENT/ZERO - INC \*- : Increment word on top of stack by 1 (*) - INL \*l : Increment local or parameter (*) - INE \*g : Increment external (*) - DEC \*- : Decrement word on top of stack by 1 (*) - DEL \*l : Decrement local or parameter (*) - DEE \*g : Decrement external (*) - ZRL \*l : Zero local or parameter - ZRE \*g : Zero external - ZRF \*w : Load a floating zero of size \*w - ZER \*w : Load \*w zero bytes + INC \*- : Increment word on top of stack by 1 (*) + INL \*l : Increment local or parameter (*) + INE \*g : Increment external (*) + DEC \*- : Decrement word on top of stack by 1 (*) + DEL \*l : Decrement local or parameter (*) + DEE \*g : Decrement external (*) + ZRL \*l : Zero local or parameter + ZRE \*g : Zero external + ZRF \*w : Load a floating zero of size \*w + ZER \*w : Load \*w zero bytes -GROUP 8 - CONVERT (stack: source, source size, dest. size (top)) +GROUP 8 \- CONVERT (stack: source, source size, dest. size (top)) - CII \*- : Convert integer to integer (*) - CUI \*- : Convert unsigned to integer (*) - CFI \*- : Convert floating to integer (*) - CIF \*- : Convert integer to floating (*) - CUF \*- : Convert unsigned to floating (*) - CFF \*- : Convert floating to floating (*) - CIU \*- : Convert integer to unsigned - CUU \*- : Convert unsigned to unsigned - CFU \*- : Convert floating to unsigned + CII \*- : Convert integer to integer (*) + CUI \*- : Convert unsigned to integer (*) + CFI \*- : Convert floating to integer (*) + CIF \*- : Convert integer to floating (*) + CUF \*- : Convert unsigned to floating (*) + CFF \*- : Convert floating to floating (*) + CIU \*- : Convert integer to unsigned + CUU \*- : Convert unsigned to unsigned + CFU \*- : Convert floating to unsigned -GROUP 9 - LOGICAL +GROUP 9 \- LOGICAL - AND \*w : Boolean and on two groups of \*w bytes - IOR \*w : Boolean inclusive or on two groups of \*w bytes - XOR \*w : Boolean exclusive or on two groups of \*w bytes - COM \*w : Complement (one's complement of top \*w bytes) - ROL \*w : Rotate left a group of \*w bytes - ROR \*w : Rotate right a group of \*w bytes + AND \*w : Boolean and on two groups of \*w bytes + IOR \*w : Boolean inclusive or on two groups of \*w bytes + XOR \*w : Boolean exclusive or on two groups of \*w bytes + COM \*w : Complement (one's complement of top \*w bytes) + ROL \*w : Rotate left a group of \*w bytes + ROR \*w : Rotate right a group of \*w bytes -GROUP 10 - SETS +GROUP 10 \- SETS - INN \*w : Bit test on \*w byte set (bit number on top of stack) - SET \*w : Create singleton \*w byte set with bit n on (n is top of stack) + INN \*w : Bit test on \*w byte set (bit number on top of stack) + SET \*w : Create singleton \*w byte set with bit n on (n is top of stack) -GROUP 11 - ARRAY +GROUP 11 \- ARRAY - LAR \*w : Load array element, descriptor contains integers of size \*w - SAR \*w : Store array element - AAR \*w : Load address of array element + LAR \*w : Load array element, descriptor contains integers of size \*w + SAR \*w : Store array element + AAR \*w : Load address of array element -GROUP 12 - COMPARE +GROUP 12 \- COMPARE - CMI \*w : Compare \*w byte integers, Push negative, zero, positive for <, = or > - CMF \*w : Compare \*w byte reals - CMU \*w : Compare \*w byte unsigneds - CMS \*w : Compare \*w byte values, can only be used for bit for bit equality test - CMP \*- : Compare pointers + CMI \*w : Compare \*w byte integers, Push negative, zero, positive for <, = or > + CMF \*w : Compare \*w byte reals + CMU \*w : Compare \*w byte unsigneds + CMS \*w : Compare \*w byte values, can only be used for bit for bit equality test + CMP \*- : Compare pointers - TLT \*- : True if less, i.e. iff top of stack < 0 - TLE \*- : True if less or equal, i.e. iff top of stack <= 0 - TEQ \*- : True if equal, i.e. iff top of stack = 0 - TNE \*- : True if not equal, i.e. iff top of stack non zero - TGE \*- : True if greater or equal, i.e. iff top of stack >= 0 - TGT \*- : True if greater, i.e. iff top of stack > 0 + TLT \*- : True if less, i.e. iff top of stack < 0 + TLE \*- : True if less or equal, i.e. iff top of stack <= 0 + TEQ \*- : True if equal, i.e. iff top of stack = 0 + TNE \*- : True if not equal, i.e. iff top of stack non zero + TGE \*- : True if greater or equal, i.e. iff top of stack >= 0 + TGT \*- : True if greater, i.e. iff top of stack > 0 -GROUP 13 - BRANCH +GROUP 13 \- BRANCH - BRA \*b : Branch unconditionally to label \*b + BRA \*b : Branch unconditionally to label \*b - BLT \*b : Branch less (pop 2 words, branch if top > second) - BLE \*b : Branch less or equal - BEQ \*b : Branch equal - BNE \*b : Branch not equal - BGE \*b : Branch greater or equal - BGT \*b : Branch greater + BLT \*b : Branch less (pop 2 words, branch if top > second) + BLE \*b : Branch less or equal + BEQ \*b : Branch equal + BNE \*b : Branch not equal + BGE \*b : Branch greater or equal + BGT \*b : Branch greater - ZLT \*b : Branch less than zero (pop 1 word, branch negative) - ZLE \*b : Branch less or equal to zero - ZEQ \*b : Branch equal zero - ZNE \*b : Branch not zero - ZGE \*b : Branch greater or equal zero - ZGT \*b : Branch greater than zero + ZLT \*b : Branch less than zero (pop 1 word, branch negative) + ZLE \*b : Branch less or equal to zero + ZEQ \*b : Branch equal zero + ZNE \*b : Branch not zero + ZGE \*b : Branch greater or equal zero + ZGT \*b : Branch greater than zero -GROUP 14 - PROCEDURE CALL +GROUP 14 \- PROCEDURE CALL - CAI \*- : Call procedure (procedure identifier on stack) - CAL \*p : Call procedure (with identifier \*p) - LFR \*s : Load function result - RET \*z : Return (function result consists of top \*z bytes) + CAI \*- : Call procedure (procedure identifier on stack) + CAL \*p : Call procedure (with identifier \*p) + LFR \*s : Load function result + RET \*z : Return (function result consists of top \*z bytes) -GROUP 15 - MISCELLANEOUS +GROUP 15 \- MISCELLANEOUS - ASP \*f : Adjust the stack pointer by \*f - ASS \*w : Adjust the stack pointer by \*w-byte integer - BLM \*z : Block move \*z bytes; first pop destination addr, then source addr - BLS \*w : Block move, size is in \*w-byte integer on top of stack - CSA \*w : Case jump; address of jump table at top of stack - CSB \*w : Table lookup jump; address of jump table at top of stack - DCH \*- : Follow dynamic chain, convert LB to LB of caller - DUP \*s : Duplicate top \*s bytes - DUS \*w : Duplicate top \*w bytes - EXG \*w : Exchange top \*w bytes - FIL \*g : File name (external 4 := \*g) - GTO \*g : Non-local goto, descriptor at \*g - LIM \*- : Load 16 bit ignore mask - LIN \*n : Line number (external 0 := \*n) - LNI \*- : Line number increment - LOR \*r : Load register (0=LB, 1=SP, 2=HP) - LPB \*- : Convert local base to argument base - MON \*- : Monitor call - NOP \*- : No operation - RCK \*w : Range check; trap on error - RTT \*- : Return from trap - SIG \*- : Trap errors to proc identifier on top of stack, -2 resets default - SIM \*- : Store 16 bit ignore mask - STR \*r : Store register (0=LB, 1=SP, 2=HP) - TRP \*- : Cause trap to occur (Error number on stack) + ASP \*f : Adjust the stack pointer by \*f + ASS \*w : Adjust the stack pointer by \*w-byte integer + BLM \*z : Block move \*z bytes; first pop destination addr, then source addr + BLS \*w : Block move, size is in \*w-byte integer on top of stack + CSA \*w : Case jump; address of jump table at top of stack + CSB \*w : Table lookup jump; address of jump table at top of stack + DCH \*- : Follow dynamic chain, convert LB to LB of caller + DUP \*s : Duplicate top \*s bytes + DUS \*w : Duplicate top \*w bytes + EXG \*w : Exchange top \*w bytes + FIL \*g : File name (external 4 := \*g) + GTO \*g : Non-local goto, descriptor at \*g + LIM \*- : Load 16 bit ignore mask + LIN \*n : Line number (external 0 := \*n) + LNI \*- : Line number increment + LOR \*r : Load register (0=LB, 1=SP, 2=HP) + LPB \*- : Convert local base to argument base + MON \*- : Monitor call + NOP \*- : No operation + RCK \*w : Range check; trap on error + RTT \*- : Return from trap + SIG \*- : Trap errors to proc identifier on top of stack, \-2 resets default + SIM \*- : Store 16 bit ignore mask + STR \*r : Store register (0=LB, 1=SP, 2=HP) + TRP \*- : Cause trap to occur (Error number on stack) .DE 0 diff --git a/doc/em/cont.nr b/doc/em/cont.nr new file mode 100644 index 00000000..b020dca0 --- /dev/null +++ b/doc/em/cont.nr @@ -0,0 +1,6 @@ +.MS T A 0 +.ME +.BP +.MS B A 0 +.ME +.CT diff --git a/doc/em/descr.nr b/doc/em/descr.nr index a377e55d..0e01224c 100644 --- a/doc/em/descr.nr +++ b/doc/em/descr.nr @@ -36,7 +36,7 @@ Array descriptors contain the following three integers: .PT lower bound~~~~~~~~~~~~~~~~~~~~~signed .PT -upper bound - lower bound~~~~~~~unsigned +upper bound \- lower bound~~~~~~~unsigned .PT number of bytes per element~~~~~unsigned .PE @@ -60,7 +60,7 @@ LAR n (n is the size of the integers in the descriptor and I) All array instructions first pop the address of the descriptor and the index. If the index is not within the bounds specified, a trap occurs. -If ok, (I~-~lower bound) is multiplied +If ok, (I~\-~lower bound) is multiplied by the number of bytes per element (the third word). The result is added to the address of A and replaces A on the stack. .A @@ -128,12 +128,12 @@ each source language case statement is up to the front end. If the range of the index value is dense, i.e .DS -(highest value - lowest value) / number of cases +(highest value \- lowest value) / number of cases .DE 1 is less than some threshold, then CSA is the obvious choice. If the range is sparse, CSB is better. .N 2 -.DS +.Dr 30 |--------------------| |--------------------| high address | pointer for upb | | pointer n-1 | |--------------------| |- - - - - - - | @@ -157,7 +157,6 @@ If the range is sparse, CSB is better. |--------------------| |--------------------| CSA descriptor CSB descriptor - - +.Df Figure 4. Descriptor layout for CSA and CSB -.DE +.De diff --git a/doc/em/dspace.nr b/doc/em/dspace.nr index 7d58dea1..602eea58 100644 --- a/doc/em/dspace.nr +++ b/doc/em/dspace.nr @@ -23,7 +23,7 @@ Examples are LOE, LAE and STE. Part of the global data area is initialized by the compiler, the rest is not initialized at all or is initialized -with a value, typically -32768 or 0. +with a value, typically \-32768 or 0. Part of the initialized global data may be made read-only if the implementation supports protection. .P @@ -47,7 +47,7 @@ addressed with the use of the DCH instruction. .A Many instructions have offsets to LB as argument, for instance LOL, LAL and STL. -The arguments of these instructions range from -1 to some +The arguments of these instructions range from \-1 to some (negative) minimum for the access of local storage and from 0 to some (positive) maximum for parameter access. @@ -246,7 +246,7 @@ reserved. The parameters and local storage are accessed by the same instructions. Negative offsets are used for access to local variables. The highest byte, that is the byte nearest -to LB, has to be accessed with offset -1. +to LB, has to be accessed with offset \-1. The pseudoinstruction specifying the entry point of a procedure, has an argument that specifies the amount of local storage needed. @@ -255,7 +255,7 @@ are the only ones that can be accessed with a fixed negative offset. The initial value of the allocated words is not defined, but implementations that check for undefined values will probably initialize them with a -special 'undefined' pattern, typically -32768. +special 'undefined' pattern, typically \-32768. .A Fourth, any EM implementation is allowed to reserve a variable size block beneath the local variables. @@ -297,7 +297,7 @@ This can be done with the aforementioned ASP instruction. Each procedure frame is a separate fragment. Because any fragment may be placed anywhere in memory, procedure frames need not be contiguous. -.DS +.Dr 47 |===============================| | actual parameter n-1 | |-------------------------------| @@ -305,14 +305,14 @@ procedure frames need not be contiguous. | . | | . | |-------------------------------| - | actual parameter 0 | ( <- AB ) + | actual parameter 0 | ( <\- AB ) |===============================| |===============================| |///////////////////////////////| |///// return status block /////| - |///////////////////////////////| <- LB + |///////////////////////////////| <\- LB |===============================| | | | local variables | @@ -340,11 +340,11 @@ procedure frames need not be contiguous. | . | | . | |-------------------------------| - | parameter 0 | <- SP + | parameter 0 | <\- SP |===============================| - +.Df Figure 1. A sample procedure frame and parameters. -.DE +.De .S2 "Heap data area" The heap area starts empty, with HP pointing to the low end of it. diff --git a/doc/em/env.nr b/doc/em/env.nr new file mode 100644 index 00000000..f59c56bf --- /dev/null +++ b/doc/em/env.nr @@ -0,0 +1,209 @@ +.SN 8 +.VS 1 0 +.BP +.S1 "ENVIRONMENT INTERACTIONS" +EM programs can interact with their environment in three ways. +Two, starting/stopping and monitor calls, are dealt with in this chapter. +The remaining way to interact, interrupts, will be treated +together with traps in chapter 9. +.S2 "Program starting and stopping" +EM user programs start with a call to a procedure called +m_a_i_n. +The assembler and backends look for the definition of a procedure +with this name in their input. +The call passes three parameters to the procedure. +The parameters are similar to the parameters supplied by the +UNIX +.FS +UNIX is a Trademark of Bell Laboratories. +.FE +operating system to C programs. +These parameters are often called +.BW argc , +.B argv +and +.BW envp . +Argc is the parameter nearest to LB and is a wordsized integer. +The other two are pointers to the first element of an array of +string pointers. +.N +The +.B argv +array contains +.B argc +strings, the first of which contains the program call name. +The other strings in the +.B argv +array are the program parameters. +.P +The +.B envp +array contains strings in the form "name=string", where 'name' +is the name of an environment variable and string its value. +The +.B envp +is terminated by a zero pointer. +.P +An EM user program stops if the program returns from the first +invocation of m_a_i_n. +The contents of the function return area are used to procure a +wordsized program return code. +EM programs also stop when traps and interrupts occur that are +not caught and when the exit monitor call is executed. +.S2 "Input/Output and other monitor calls" +EM differs from most conventional machines in that it has high level i/o +instructions. +Typical instructions are OPEN FILE and READ FROM FILE instead +of low level instructions such as setting and clearing +bits in device registers. +By providing such high level i/o primitives, the task of implementing +EM on various non EM machines is made considerably easier. +.P +I/O is initiated by the MON instruction, which expects an iocode on top +of the stack. +Often there are also parameters which are pushed on the +stack in reverse order, that is: last +parameter first. +Some i/o functions also provide results, which are returned on the stack. +In the list of monitor calls we use several types of parameters and results, +these types consist of integers and unsigneds of varying sizes, but never +smaller than the wordsize, and the two pointer types. +.N 1 +The names of the types used are: +.IS 4 +.PS - 10 +.PT int +an integer of wordsize +.PT int2 +an integer whose size is the maximum of the wordsize and 2 +bytes +.PT int4 +an integer whose size is the maximum of the wordsize and 4 +bytes +.PT intp +an integer with the size of a pointer +.PT uns2 +an unsigned integer whose size is the maximum of the wordsize and 2 +.PT unsp +an unsigned integer with the size of a pointer +.PT ptr +a pointer into data space +.PE 1 +.IE 0 +The table below lists the i/o codes with their results and +parameters. +This list is similar to the system calls of the UNIX Version 7 +operating system. +.A +To execute a monitor call, proceed as follows: +.IS 2 +.N 1 +.PS a 4 "" ) +.PT +Stack the parameters, in reverse order, last parameter first. +.PT +Push the monitor call number (iocode) onto the stack. +.PT +Execute the MON instruction. +.PE 1 +.IE +An error code is present on the top of the stack after +execution of most monitor calls. +If this error code is zero, the call performed the action +requested and the results are available on top of the stack. +Non-zero error codes indicate a failure, in this case no +results are available and the error code has been pushed twice. +This construction enables programs to test for failure with a +single instruction (~TEQ or TNE~) and still find out the cause of +the failure. +The result name 'e' is reserved for the error code. +.N 1 +List of monitor calls. +.DS B +.ta 2n 8n 16n 32n 48n +number name parameters results function + + 1 Exit status:int Terminate this process + 2 Fork e,flag,pid:int Spawn new process + 3 Read fildes:int;buf:ptr;nbytes:unsp + e:int;rbytes:unsp Read from file + 4 Write fildes:int;buf:ptr;nbytes:unsp + e:int;wbytes:unsp Write on a file + 5 Open string:ptr;flag:int + e,fildes:int Open file for read and/or write + 6 Close fildes:int e:int Close a file + 7 Wait e:int;status,pid:int2 + Wait for child + 8 Creat string:ptr;mode:int + e,fildes:int Create a new file + 9 Link string1,string2:ptr + e:int Link to a file + 10 Unlink string:ptr e:int Remove directory entry + 12 Chdir string:ptr e:int Change default directory + 14 Mknod string:ptr;mode,addr:int2 + e:int Make a special file + 15 Chmod string:ptr;mode:int2 + e:int Change mode of file + 16 Chown string:ptr;owner,group:int2 + e:int Change owner/group of a file + 18 Stat string,statbuf:ptr + e:int Get file status + 19 Lseek fildes:int;off:int4;whence:int + e:int;oldoff:int4 Move read/write pointer + 20 Getpid pid:int2 Get process identification + 21 Mount special,string:ptr;rwflag:int + e:int Mount file system + 22 Umount special:ptr e:int Unmount file system + 23 Setuid userid:int2 e:int Set user ID + 24 Getuid e_uid,r_uid:int2 Get user ID + 25 Stime time:int4 e:int Set time and date + 26 Ptrace request:int;pid:int2;addr:ptr;data:int + e,value:int Process trace + 27 Alarm seconds:uns2 previous:uns2 Schedule signal + 28 Fstat fildes:int;statbuf:ptr + e:int Get file status + 29 Pause Stop until signal + 30 Utime string,timep:ptr + e:int Set file times + 33 Access string,mode:int e:int Determine file accessibility + 34 Nice incr:int Set program priority + 35 Ftime bufp:ptr e:int Get date and time + 36 Sync Update filesystem + 37 Kill pid:int2;sig:int + e:int Send signal to a process + 41 Dup fildes,newfildes:int + e,fildes:int Duplicate a file descriptor + 42 Pipe e,w_des,r_des:int Create a pipe + 43 Times buffer:ptr Get process times + 44 Profil buff:ptr;bufsiz,offset,scale:intp Execution time profile + 46 Setgid gid:int2 e:int Set group ID + 47 Getgid e_gid,r_gid:int Get group ID + 48 Sigtrp trapno,signo:int + e,prevtrap:int See below + 51 Acct file:ptr e:int Turn accounting on or off + 53 Lock flag:int e:int Lock a process + 54 Ioctl fildes,request:int;argp:ptr + e:int Control device + 56 Mpxcall cmd:int;vec:ptr e:int Multiplexed file handling + 59 Exece name,argv,envp:ptr + e:int Execute a file + 60 Umask complmode:int2 oldmask:int2 Set file creation mode mask + 61 Chroot string:ptr e:int Change root directory +.DE 1 +Codes 0, 11, 13, 17, 31, 32, 38, 39, 40, 45, 49, 50, 52, +55, 57, 58, 62, and 63 are +not used. +.P +All monitor calls, except fork and sigtrp +are the same as the UNIX version 7 system calls. +.P +The sigtrp entry maps UNIX signals onto EM interrupts. +Normally, trapno is in the range 0 to 252. +In that case it requests that signal signo +will cause trap trapno to occur. +When given trap number \-2, default signal handling is reset, and when given +trap number \-3, the signal is ignored. +.P +The flag returned by fork is 1 in the child process and 0 in +the parent. +The pid returned is the process-id of the other process. diff --git a/doc/em/intro.nr b/doc/em/intro.nr index 4b9c2667..4b37b7f8 100644 --- a/doc/em/intro.nr +++ b/doc/em/intro.nr @@ -90,11 +90,11 @@ few internal registers with specific functions as follows: .TS tab(:); l 1 l l. -PC:-:Program Counter:Pointer to next instruction -LB:-:Local Base:Points to base of the local variables \ +PC:\-:Program Counter:Pointer to next instruction +LB:\-:Local Base:Points to base of the local variables \ in the current procedure. -SP:-:Stack Pointer:Points to the highest occupied word on the stack. -HP:-:Heap Pointer:Points to the top of the heap area. +SP:\-:Stack Pointer:Points to the highest occupied word on the stack. +HP:\-:Heap Pointer:Points to the top of the heap area. .TE 1 .IE .A diff --git a/doc/em/ip.awk b/doc/em/ip.awk index 53839457..6c365869 100644 --- a/doc/em/ip.awk +++ b/doc/em/ip.awk @@ -1,6 +1,11 @@ -BEGIN { printf ".TS\nlw(6) lw(8) rw(3) rw(6) 14 lw(6) lw(8) rw(3) rw(6) 14 lw(6) lw(8) rw(3) rw(6).\n" } -NF == 4 { printf "%s\t%s\t%d\t%d",$1,$2,$3,$4 } -NF == 3 { printf "%s\t%s\t\t%d",$1,$2,$3 } - { if ( NR%3 == 0 ) printf("\n") ; else printf("\t"); } -END { if ( NR%3 != 0 ) printf("\n") - printf ".TE\n" } +BEGIN { printf(".TS\n"); + for (i = 0; i < 3; i++) + printf("lw(4) 0 lw(6) 0 rw(2) 0 rw(5) 8 "); + printf(".\n"); + } +NF == 4 { printf "%s\t%s\t%d\t%d",$1,$2,$3,$4 } +NF == 3 { printf "%s\t%s\t\t%d",$1,$2,$3 } + { if ( NR%3 == 0 ) printf("\n") ; else printf("\t"); } +END { if ( NR%3 != 0 ) printf("\n"); + printf(".TE\n"); + } diff --git a/doc/em/itables b/doc/em/itables index 27d9c41c..a4825dc9 100644 --- a/doc/em/itables +++ b/doc/em/itables @@ -10,2105 +10,2430 @@ .. .nf .nr #~ 0 -.if n .nr #~ 0.6n +.if \n(.T .if n .nr #~ 0.6n .ds #d .d .if \(ts\n(.z\(ts\(ts .ds #d nl .fc .nr 33 \n(.s -.rm 80 81 82 83 84 85 86 87 88 89 90 91 -.nr 80 0 +.rm 66 67 68 69 70 71 72 73 74 75 76 77 +.nr 66 0 .nr 38 \waar -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wadp -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wadp -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wasp -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wbeq -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wble -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wbne -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wbra -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wcff -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wcmf -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wcms -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wdec -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wdup -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wfil -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wine -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \winn -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wlae -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wlal -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wlal -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wldc -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wldl -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wlfr -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wlil -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wlni -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wloc -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wloe -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wlof -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wloi -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wlol -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wlol -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wlxa -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wmli -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wret -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wsbf -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wset -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wsli -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wstf -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wsti -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wstl -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wstl -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wtgt -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wzeq -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wzge -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wzlt -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wzre -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wzrl -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \waar -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wadi -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wads -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wand -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wass -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wbgt -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wbls -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wbne -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wcfi -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wcmf -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wcmi -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wcmu -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wcom -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wcsb -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wcui -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wdel -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wdus -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wdvf -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wdvu -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wfef -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \winl -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \winn -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wlar -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wldf -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wlfr -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wlim -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wlor -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wlxl -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wmli -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wmlu -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wngf -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wnop -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wret -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wrmu -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wrol -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wrtt -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wsbf -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wsbi -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wsbu -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wsdf -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wset -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wsil -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wsli -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wslu -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wsru -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wsts -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wtge -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wxor -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wzer -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wzle -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wzrf -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wdch -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wexg -.if \n(80<\n(38 .nr 80 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wldc -.if \n(80<\n(38 .nr 80 \n(38 -.80 -.rm 80 -.nr 38 6n -.if \n(80<\n(38 .nr 80 \n(38 -.nr 81 0 -.nr 38 \wmwPo -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \w2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wsN -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wmwPo -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wsP -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wsP -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wsP -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wsP -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \w- -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wsP -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wsP -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \w- -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wmwPo -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \w2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wsw -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wsP -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \w2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wN2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wswP -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wmP -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wmP -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wsP -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wmwP -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \w- -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wmN -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \ww2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wmwPo -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wmPo -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wwP2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wmwN -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wmPo -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wmwPo -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wsP -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wsP -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wsP -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wmwPo -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \w2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wmPo -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wwP2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wmwN -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \w- -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \w2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wsP -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wsP -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \ww2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wswN -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we- -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we- -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we- -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we- -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we- -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we- -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wewP2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we- -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we- -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wewP2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we- -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we- -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wesP -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we- -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we- -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we- -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we- -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we- -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we- -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \wewP2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we- -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we- -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we- -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we2 -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we- -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \we- -.if \n(81<\n(38 .nr 81 \n(38 -.nr 38 \w4 -.if \n(81<\n(38 .nr 81 \n(38 -.81 -.rm 81 -.nr 38 8n -.if \n(81<\n(38 .nr 81 \n(38 -.nr 82 0 -.nr 38 \w1 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w1 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w5 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w1 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w1 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w1 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w2 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w1 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w1 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w1 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w1 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w1 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w1 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w1 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w1 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w1 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w2 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w1 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w4 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w1 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w8 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w1 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w2 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w1 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w1 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w1 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w1 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w1 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w5 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w1 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w1 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w1 -.if \n(82<\n(38 .nr 82 \n(38 -.nr 38 \w1 -.if \n(82<\n(38 .nr 82 \n(38 -.82 -.rm 82 -.nr 38 3n -.if \n(82<\n(38 .nr 82 \n(38 -.nr 83 0 -.nr 38 \w34 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w38 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w42 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w45 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w52 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w55 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w58 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w62 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w93 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w96 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w100 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w103 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w106 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w109 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w112 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w117 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w120 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w129 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w132 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w136 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w139 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w143 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w146 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w150 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w152 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w155 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w162 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w168 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w174 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w180 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w190 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w194 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w199 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w202 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w206 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w209 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w214 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w218 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w224 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w228 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w235 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w238 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w242 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w245 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w248 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w252 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w1 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w4 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w7 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w10 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w13 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w16 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w19 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w22 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w25 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w28 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w31 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w34 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w37 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w40 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w43 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w46 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w49 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w52 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w55 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w58 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w61 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w64 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w67 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w70 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w73 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w76 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w79 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w82 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w85 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w88 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w91 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w94 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w97 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w100 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w103 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w106 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w109 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w112 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w115 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w118 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w121 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w124 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w127 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w130 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w133 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w136 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w139 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w142 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w145 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w148 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w151 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w154 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w157 -.if \n(83<\n(38 .nr 83 \n(38 -.nr 38 \w0 -.if \n(83<\n(38 .nr 83 \n(38 -.83 -.rm 83 -.nr 38 6n -.if \n(83<\n(38 .nr 83 \n(38 -.nr 84 0 -.nr 38 \wadf -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wadp -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wads -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wasp -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wbge -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wblm -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wbra -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wcal -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wcif -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wcmi -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wcsa -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wdee -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wdvf -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \winc -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \winl -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wior -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wlae -.if \n(84<\n(38 .nr 84 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wlal -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wlal -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wlde -.if \n(84<\n(38 .nr 84 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wldl -.if \n(84<\n(38 .nr 84 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wlil -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wlin -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wloc -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wloc -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wloe -.if \n(84<\n(38 .nr 84 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wlof -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wloi -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wlol -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wlol -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wlxl -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wrck -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wrmi -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wsbi -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wsil -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wste -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wstf -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wsti -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wstl -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wstl -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wtlt -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wzeq -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wzgt -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wzne -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wzre -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wzrl -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wadf -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wadi -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wadu -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wand -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wass -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wble -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wbls -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wcai -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wcfu -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wcmf -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wcms -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wcmu -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wcsa -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wcsb -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wcuu -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wdel -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wdus -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wdvi -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wdvu -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wfif -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \winl -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wior -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wlar -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wldl -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wlil -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wlos -.if \n(84<\n(38 .nr 84 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wlpi -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wmlf -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wmli -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wmon -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wngi -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wrck -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wrmi -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wrmu -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wror -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wsar -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wsbf -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wsbs -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wsbu -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wsdl -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wset -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wsil -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wsli -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wsri -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wsru -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wsts -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wtle -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wxor -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wzge -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wzlt -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wzrf -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wexg -.if \n(84<\n(38 .nr 84 \n(38 -.nr 38 \wlpb -.if \n(84<\n(38 .nr 84 \n(38 -.84 -.rm 84 -.nr 38 6n -.if \n(84<\n(38 .nr 84 \n(38 -.nr 85 0 -.nr 38 \wsP -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wmPo -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wmwPo -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wswP -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wsP -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wsP -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \w2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wmPo -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \w- -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wmwPo -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wmwPo -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wsw -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wsP -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \w- -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wmwN -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wmwPo -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wsw -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wm -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wswN -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \ww2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wswN -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wswN -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \w2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \w2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wsP -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wsw -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wsP -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wmwPo -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wwN2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wswP -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wmPo -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wmwPo -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wmwPo -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wmwPo -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wswN -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \ww2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wmwPo -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wmwPo -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wwN2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wswN -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \w- -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wsP -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wsP -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wsP -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wsw -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wwN2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we- -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we- -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we- -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we- -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we- -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we- -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we- -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we- -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we- -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we- -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wewN2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we- -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we- -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wewN2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we- -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wewP2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wewP2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we- -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we- -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we- -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we- -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we- -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wewP2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we- -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wewN2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we- -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we- -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we- -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we- -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we- -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we2 -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we- -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \wesP -.if \n(85<\n(38 .nr 85 \n(38 -.nr 38 \we- -.if \n(85<\n(38 .nr 85 \n(38 -.85 -.rm 85 -.nr 38 8n -.if \n(85<\n(38 .nr 85 \n(38 -.nr 86 0 -.nr 38 \w1 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w2 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w1 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w1 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w1 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w1 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w28 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w2 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w1 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w1 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w1 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w3 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w1 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w7 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w1 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w2 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w1 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w1 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w1 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w5 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w1 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w4 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w1 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w2 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w1 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w1 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w2 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w1 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w2 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w4 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w1 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w2 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w1 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w1 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w1 -.if \n(86<\n(38 .nr 86 \n(38 -.nr 38 \w1 -.if \n(86<\n(38 .nr 86 \n(38 -.86 -.rm 86 -.nr 38 3n -.if \n(86<\n(38 .nr 86 \n(38 -.nr 87 0 -.nr 38 \w35 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w39 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w43 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w50 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w53 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w56 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w59 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w64 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w94 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w97 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w101 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w104 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w107 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w110 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w113 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w118 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w121 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w130 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w133 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w137 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w140 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w144 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w148 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w151 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w153 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w156 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w166 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w169 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w175 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w188 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w191 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w196 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w200 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w203 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w207 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w210 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w215 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w219 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w225 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w233 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w236 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w239 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w243 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w246 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w249 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w253 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w2 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w5 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w8 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w11 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w14 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w17 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w20 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w23 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w26 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w29 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w32 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w35 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w38 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w41 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w44 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w47 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w50 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w53 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w56 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w59 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w62 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w65 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w68 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w71 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w74 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w77 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w80 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w83 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w86 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w89 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w92 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w95 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w98 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w101 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w104 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w107 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w110 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w113 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w116 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w119 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w122 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w125 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w128 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w131 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w134 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w137 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w140 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w143 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w146 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w149 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w152 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w155 -.if \n(87<\n(38 .nr 87 \n(38 -.nr 38 \w158 -.if \n(87<\n(38 .nr 87 \n(38 -.87 -.rm 87 -.nr 38 6n -.if \n(87<\n(38 .nr 87 \n(38 -.nr 88 0 -.nr 38 \wadi -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wadp -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wand -.if \n(88<\n(38 .nr 88 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wbeq -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wbgt -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wblt -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wbra -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wcal -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wcii -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wcmp -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wcsb -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wdel -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wdvi -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wine -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \winl -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wior -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wlal -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wlal -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wlar -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wlde -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wlfr -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wlil -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wlin -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wloc -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wloc -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wlof -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wloi -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wloi -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wlol -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wlol -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wmlf -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wret -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wsar -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wsdl -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wsil -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wste -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wstf -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wsti -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wstl -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wteq -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wtne -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wzer -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wzle -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wzne -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wzrl -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \waar -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wadf -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wads -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wadu -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wasp -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wbge -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wblm -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wblt -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wcal -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wciu -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wcmi -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wcms -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wcom -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wcsa -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wcuf -.if \n(88<\n(38 .nr 88 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 +.nr 38 \wble +.if \n(66<\n(38 .nr 66 \n(38 +.nr 38 \wbne +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wdee -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wdup -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wdvf -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wdvi -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wfef -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wfif -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \winn -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wior -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wldc -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wldl -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wlil -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wlos -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wlxa -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wmlf -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wmlu -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wngf -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wngi -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wrck -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wrmi -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wrol -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wror -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wsar -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wsbi -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wsbs -.if \n(88<\n(38 .nr 88 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 +.nr 38 \wfil +.if \n(66<\n(38 .nr 66 \n(38 +.nr 38 \winl +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wsde -.if \n(88<\n(38 .nr 88 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wsdl -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wsig -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wsim -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wslu -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wsri -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wsti -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wstr -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wtrp -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wzer -.if \n(88<\n(38 .nr 88 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 +.nr 38 \wste +.if \n(66<\n(38 .nr 66 \n(38 +.nr 38 \wstl +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wzgt -.if \n(88<\n(38 .nr 88 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wzne -.if \n(88<\n(38 .nr 88 \n(38 +.if \n(66<\n(38 .nr 66 \n(38 .nr 38 \wzrl -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wexg -.if \n(88<\n(38 .nr 88 \n(38 -.nr 38 \wgto -.if \n(88<\n(38 .nr 88 \n(38 -.88 -.rm 88 -.nr 38 6n -.if \n(88<\n(38 .nr 88 \n(38 -.nr 89 0 +.if \n(66<\n(38 .nr 66 \n(38 +.66 +.rm 66 +.nr 38 4n +.if \n(66<\n(38 .nr 66 \n(38 +.nr 67 0 .nr 38 \wmwPo -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wsP -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wmwPo -.if \n(89<\n(38 .nr 89 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \w2 -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wsP -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wsP -.if \n(89<\n(38 .nr 89 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \wsN -.if \n(89<\n(38 .nr 89 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wmwPo +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \wsP -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \w- -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \w- -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wmwPo -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wswN -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wmwPo -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \ww2 -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wswN -.if \n(89<\n(38 .nr 89 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \wsP -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wP2 -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wmN -.if \n(89<\n(38 .nr 89 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wsP +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wsP +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \w- +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wsP +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wsP +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \w- +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \wmwPo -.if \n(89<\n(38 .nr 89 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \w2 +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \wsw -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wmwPo -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wswP -.if \n(89<\n(38 .nr 89 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \wsP -.if \n(89<\n(38 .nr 89 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \w2 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wN2 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wswP +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \wmP -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wsN -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \w2 -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \w2 -.if \n(89<\n(38 .nr 89 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wmP +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \wsP -.if \n(89<\n(38 .nr 89 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \wmwP -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wswN -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wsP -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wmwP -.if \n(89<\n(38 .nr 89 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \w- +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wmN +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \ww2 +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \wmwPo -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wswN -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wswP -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wsw -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wsP -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wsP -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wmwP -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \w- -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \w- -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wsP -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wsP -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wsN -.if \n(89<\n(38 .nr 89 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wmPo +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wwP2 +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \wmwN -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we2 -.if \n(89<\n(38 .nr 89 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wmPo +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wmwPo +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wsP +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wsP +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wsP +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wmwPo +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \w2 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wmPo +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wwP2 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wmwN +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \w- +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \w2 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wsP +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wsP +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \ww2 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wswN +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \we- -.if \n(89<\n(38 .nr 89 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \we2 -.if \n(89<\n(38 .nr 89 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \we- -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wew2 -.if \n(89<\n(38 .nr 89 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \we2 -.if \n(89<\n(38 .nr 89 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \we2 -.if \n(89<\n(38 .nr 89 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \we2 -.if \n(89<\n(38 .nr 89 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \we2 -.if \n(89<\n(38 .nr 89 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we2 +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \we- -.if \n(89<\n(38 .nr 89 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \we2 -.if \n(89<\n(38 .nr 89 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \we- -.if \n(89<\n(38 .nr 89 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \we2 -.if \n(89<\n(38 .nr 89 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \we- -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we- -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wew2 -.if \n(89<\n(38 .nr 89 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \we2 -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we2 -.if \n(89<\n(38 .nr 89 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \we- -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we2 -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we- -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we2 -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we- -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we2 -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wewN2 -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wewN2 -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we- -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we2 -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we- -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we2 -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we2 -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we- -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we- -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we- -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we2 -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we- -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we- -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we2 -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we- -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we2 -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wewN2 -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we- -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we- -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we2 -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we- -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we2 -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \wesP -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we- -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we2 -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we2 -.if \n(89<\n(38 .nr 89 \n(38 -.nr 38 \we2 -.if \n(89<\n(38 .nr 89 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \wewP2 -.if \n(89<\n(38 .nr 89 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \we2 -.if \n(89<\n(38 .nr 89 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we- +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \we2 -.if \n(89<\n(38 .nr 89 \n(38 -.89 -.rm 89 -.nr 38 8n -.if \n(89<\n(38 .nr 89 \n(38 -.nr 90 0 -.nr 38 \w2 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w1 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w1 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w1 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w1 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w2 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w1 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w1 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w1 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w1 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w1 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w1 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w1 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w1 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w1 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w2 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w1 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w1 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w34 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w1 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w1 -.if \n(90<\n(38 .nr 90 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we- +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wewP2 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we- +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we2 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we2 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we2 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we- +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wesP +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we2 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we2 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we- +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we- +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we- +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we2 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we2 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we- +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we- +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we2 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we- +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we2 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we2 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we2 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wewP2 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we2 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we- +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we2 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we2 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we- +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we2 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we- +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we2 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we2 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we- +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \we- +.if \n(67<\n(38 .nr 67 \n(38 .nr 38 \w4 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w1 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w1 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w2 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w1 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w1 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w1 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w3 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w1 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w1 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w2 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w1 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w1 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w1 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w2 -.if \n(90<\n(38 .nr 90 \n(38 -.nr 38 \w1 -.if \n(90<\n(38 .nr 90 \n(38 -.90 -.rm 90 -.nr 38 3n -.if \n(90<\n(38 .nr 90 \n(38 -.nr 91 0 -.nr 38 \w36 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w41 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w44 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w51 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w54 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w57 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w60 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w92 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w95 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w99 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w102 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w105 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w108 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w111 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w116 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w119 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w128 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w131 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w135 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w138 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w141 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w145 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w149 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w0 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w154 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w161 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w167 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w173 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w176 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w189 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w193 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w197 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w201 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w205 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w208 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w211 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w217 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w223 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w226 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w234 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w237 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w241 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w244 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w247 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w250 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w0 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w3 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w6 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w9 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w12 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w15 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w18 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w21 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w24 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w27 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w30 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w33 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w36 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w39 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w42 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w45 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w48 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w51 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w54 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w57 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w60 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w63 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w66 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w69 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w72 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w75 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w78 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w81 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w84 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w87 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w90 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w93 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w96 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w99 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w102 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w105 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w108 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w111 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w114 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w117 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w120 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w123 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w126 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w129 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w132 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w135 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w138 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w141 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w144 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w147 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w150 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w153 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w156 -.if \n(91<\n(38 .nr 91 \n(38 -.nr 38 \w159 -.if \n(91<\n(38 .nr 91 \n(38 -.91 -.rm 91 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wN4 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wwP4 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wwN4 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \w4 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \w4 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \w4 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \w4 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \w4 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \ww4 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \w4 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wwP4 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \w4 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wwN4 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \ww4 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wwN4 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \w4 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \w4 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 38 \wwN4 +.if \n(67<\n(38 .nr 67 \n(38 +.67 +.rm 67 .nr 38 6n -.if \n(91<\n(38 .nr 91 \n(38 +.if \n(67<\n(38 .nr 67 \n(38 +.nr 68 0 +.nr 38 \w1 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w1 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w5 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w1 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w1 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w1 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w2 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w1 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w1 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w1 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w1 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w1 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w1 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w1 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w1 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w1 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w2 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w1 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w4 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w1 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w8 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w1 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w2 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w1 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w1 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w1 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w1 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w1 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w5 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w1 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w1 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w1 +.if \n(68<\n(38 .nr 68 \n(38 +.nr 38 \w1 +.if \n(68<\n(38 .nr 68 \n(38 +.68 +.rm 68 +.nr 38 2n +.if \n(68<\n(38 .nr 68 \n(38 +.nr 69 0 +.nr 38 \w34 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w38 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w42 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w45 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w52 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w55 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w58 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w62 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w93 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w96 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w100 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w103 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w106 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w109 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w112 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w117 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w120 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w129 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w132 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w136 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w139 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w143 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w146 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w150 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w152 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w155 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w162 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w168 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w174 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w180 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w190 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w194 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w199 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w202 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w206 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w209 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w214 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w218 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w224 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w228 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w235 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w238 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w242 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w245 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w248 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w252 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w1 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w4 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w7 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w10 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w13 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w16 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w19 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w22 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w25 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w28 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w31 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w34 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w37 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w40 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w43 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w46 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w49 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w52 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w55 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w58 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w61 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w64 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w67 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w70 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w73 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w76 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w79 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w82 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w85 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w88 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w91 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w94 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w97 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w100 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w103 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w106 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w109 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w112 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w115 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w118 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w121 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w124 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w127 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w130 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w133 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w136 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w139 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w142 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w145 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w148 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w151 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w154 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w157 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w0 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w3 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w6 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w9 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w12 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w15 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w18 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w21 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w24 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w27 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w30 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w33 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w36 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w39 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w42 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w45 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w48 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w51 +.if \n(69<\n(38 .nr 69 \n(38 +.nr 38 \w54 +.if \n(69<\n(38 .nr 69 \n(38 +.69 +.rm 69 +.nr 38 5n +.if \n(69<\n(38 .nr 69 \n(38 +.nr 70 0 +.nr 38 \wadf +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wadp +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wads +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wasp +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wbge +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wblm +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wbra +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wcal +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wcif +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wcmi +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wcsa +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wdee +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wdvf +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \winc +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \winl +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wior +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wlae +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wlal +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wlal +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wlde +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wldl +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wlil +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wlin +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wloc +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wloc +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wloe +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wlof +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wloi +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wlol +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wlol +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wlxl +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wrck +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wrmi +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wsbi +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wsil +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wste +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wstf +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wsti +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wstl +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wstl +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wtlt +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wzeq +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wzgt +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wzne +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wzre +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wzrl +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wadf +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wadi +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wadu +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wand +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wass +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wble +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wbls +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wcai +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wcfu +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wcmf +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wcms +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wcmu +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wcsa +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wcsb +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wcuu +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wdel +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wdus +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wdvi +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wdvu +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wfif +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \winl +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wior +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wlar +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wldl +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wlil +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wlos +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wlpi +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wmlf +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wmli +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wmon +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wngi +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wrck +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wrmi +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wrmu +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wror +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wsar +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wsbf +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wsbs +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wsbu +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wsdl +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wset +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wsil +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wsli +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wsri +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wsru +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wsts +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wtle +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wxor +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wzge +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wzlt +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wzrf +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wexg +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wlpb +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wlae +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wlde +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wldl +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wloc +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wlol +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wadp +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wbge +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wblm +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wbra +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wdel +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wgto +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \winl +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wsdf +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wsil +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wstf +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wzeq +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wzle +.if \n(70<\n(38 .nr 70 \n(38 +.nr 38 \wzre +.if \n(70<\n(38 .nr 70 \n(38 +.70 +.rm 70 +.nr 38 4n +.if \n(70<\n(38 .nr 70 \n(38 +.nr 71 0 +.nr 38 \wsP +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wmPo +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wmwPo +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wswP +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wsP +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wsP +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \w2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wmPo +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \w- +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wmwPo +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wmwPo +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wsw +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wsP +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \w- +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wmwN +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wmwPo +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wsw +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wmP +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wswN +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \ww2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wswN +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wswN +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \w2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \w2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wsP +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wsw +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wsP +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wmwPo +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wwN2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wswP +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wmPo +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wmwPo +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wmwPo +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wmwPo +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wswN +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \ww2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wmwPo +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wmwPo +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wwN2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wswN +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \w- +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wsP +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wsP +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wsP +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wsw +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wwN2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we- +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we- +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we- +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we- +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we- +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we- +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we- +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we- +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we- +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we- +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wewN2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we- +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we- +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wewN2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we- +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wewP2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wewP2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we- +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we- +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we- +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we- +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we- +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wewP2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we- +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wewN2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we- +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we- +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we- +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we- +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we- +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we2 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we- +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wesP +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \we- +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \w4 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \ww4 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wwN4 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \w4 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wwP4 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \w4 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \w4 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \w4 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \w4 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wwP4 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \w4 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wwN4 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \w4 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \wwP4 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \w4 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \w4 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \w4 +.if \n(71<\n(38 .nr 71 \n(38 +.nr 38 \ww4 +.if \n(71<\n(38 .nr 71 \n(38 +.71 +.rm 71 +.nr 38 6n +.if \n(71<\n(38 .nr 71 \n(38 +.nr 72 0 +.nr 38 \w1 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w2 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w1 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w1 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w1 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w1 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w28 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w2 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w1 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w1 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w1 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w3 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w1 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w7 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w1 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w2 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w1 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w1 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w1 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w5 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w1 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w4 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w1 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w2 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w1 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w1 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w2 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w1 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w2 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w4 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w1 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w2 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w1 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w1 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w1 +.if \n(72<\n(38 .nr 72 \n(38 +.nr 38 \w1 +.if \n(72<\n(38 .nr 72 \n(38 +.72 +.rm 72 +.nr 38 2n +.if \n(72<\n(38 .nr 72 \n(38 +.nr 73 0 +.nr 38 \w35 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w39 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w43 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w50 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w53 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w56 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w59 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w64 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w94 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w97 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w101 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w104 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w107 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w110 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w113 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w118 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w121 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w130 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w133 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w137 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w140 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w144 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w148 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w151 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w153 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w156 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w166 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w169 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w175 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w188 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w191 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w196 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w200 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w203 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w207 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w210 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w215 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w219 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w225 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w233 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w236 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w239 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w243 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w246 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w249 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w253 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w2 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w5 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w8 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w11 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w14 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w17 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w20 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w23 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w26 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w29 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w32 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w35 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w38 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w41 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w44 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w47 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w50 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w53 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w56 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w59 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w62 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w65 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w68 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w71 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w74 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w77 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w80 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w83 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w86 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w89 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w92 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w95 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w98 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w101 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w104 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w107 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w110 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w113 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w116 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w119 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w122 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w125 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w128 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w131 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w134 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w137 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w140 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w143 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w146 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w149 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w152 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w155 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w158 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w1 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w4 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w7 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w10 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w13 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w16 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w19 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w22 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w25 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w28 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w31 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w34 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w37 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w40 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w43 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w46 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w49 +.if \n(73<\n(38 .nr 73 \n(38 +.nr 38 \w52 +.if \n(73<\n(38 .nr 73 \n(38 +.73 +.rm 73 +.nr 38 5n +.if \n(73<\n(38 .nr 73 \n(38 +.nr 74 0 +.nr 38 \wadi +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wadp +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wand +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wbeq +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wbgt +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wblt +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wbra +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wcal +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wcii +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wcmp +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wcsb +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wdel +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wdvi +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wine +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \winl +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wior +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wlal +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wlal +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wlar +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wlde +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wlfr +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wlil +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wlin +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wloc +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wloc +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wlof +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wloi +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wloi +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wlol +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wlol +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wmlf +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wret +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wsar +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wsdl +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wsil +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wste +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wstf +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wsti +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wstl +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wteq +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wtne +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wzer +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wzle +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wzne +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wzrl +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \waar +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wadf +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wads +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wadu +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wasp +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wbge +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wblm +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wblt +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wcal +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wciu +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wcmi +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wcms +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wcom +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wcsa +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wcuf +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wdee +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wdup +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wdvf +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wdvi +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wfef +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wfif +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \winn +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wior +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wldc +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wldl +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wlil +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wlos +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wlxa +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wmlf +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wmlu +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wngf +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wngi +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wrck +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wrmi +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wrol +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wror +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wsar +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wsbi +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wsbs +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wsde +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wsdl +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wsig +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wsim +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wslu +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wsri +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wsti +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wstr +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wtrp +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wzer +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wzgt +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wzne +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wzrl +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wexg +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wgto +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wlal +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wldf +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wlil +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wloe +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wlol +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wasp +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wbgt +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wblt +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wcal +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wdel +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wine +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wlin +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wsdl +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wsil +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wstl +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wzge +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wzlt +.if \n(74<\n(38 .nr 74 \n(38 +.nr 38 \wzrl +.if \n(74<\n(38 .nr 74 \n(38 +.74 +.rm 74 +.nr 38 4n +.if \n(74<\n(38 .nr 74 \n(38 +.nr 75 0 +.nr 38 \wmwPo +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wsP +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wmwPo +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \w2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wsP +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wsP +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wsN +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wsP +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \w- +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \w- +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wmwPo +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wswN +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wmwPo +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \ww2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wswN +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wsP +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wP2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wmN +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wmwPo +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wsw +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wmwPo +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wswP +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wsP +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wmP +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wsN +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \w2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \w2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wsP +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wmwP +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wswN +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wsP +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wmwP +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wmwPo +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wswN +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wswP +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wsw +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wsP +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wsP +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wmwP +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \w- +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \w- +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wsP +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wsP +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wsN +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wmwN +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we- +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we- +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wew2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we- +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we- +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we- +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we- +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wew2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we- +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we- +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we- +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wewN2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wewN2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we- +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we- +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we- +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we- +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we- +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we- +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we- +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we- +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wewN2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we- +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we- +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we- +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wesP +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we- +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wewP2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \we2 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wP4 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \w4 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wwP4 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \ww4 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wwN4 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \ww4 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \w4 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \w4 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \w4 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wwN4 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \ww4 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \w4 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wwP4 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wwN4 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wwP4 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \w4 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \w4 +.if \n(75<\n(38 .nr 75 \n(38 +.nr 38 \wwP4 +.if \n(75<\n(38 .nr 75 \n(38 +.75 +.rm 75 +.nr 38 6n +.if \n(75<\n(38 .nr 75 \n(38 +.nr 76 0 +.nr 38 \w2 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w1 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w1 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w1 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w1 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w2 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w1 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w1 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w1 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w1 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w1 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w1 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w1 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w1 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w1 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w2 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w1 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w1 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w34 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w1 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w1 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w4 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w1 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w1 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w2 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w1 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w1 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w1 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w3 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w1 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w1 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w2 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w1 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w1 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w1 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w2 +.if \n(76<\n(38 .nr 76 \n(38 +.nr 38 \w1 +.if \n(76<\n(38 .nr 76 \n(38 +.76 +.rm 76 +.nr 38 2n +.if \n(76<\n(38 .nr 76 \n(38 +.nr 77 0 +.nr 38 \w36 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w41 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w44 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w51 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w54 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w57 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w60 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w92 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w95 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w99 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w102 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w105 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w108 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w111 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w116 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w119 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w128 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w131 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w135 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w138 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w141 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w145 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w149 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w0 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w154 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w161 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w167 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w173 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w176 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w189 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w193 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w197 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w201 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w205 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w208 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w211 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w217 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w223 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w226 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w234 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w237 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w241 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w244 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w247 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w250 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w0 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w3 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w6 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w9 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w12 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w15 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w18 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w21 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w24 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w27 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w30 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w33 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w36 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w39 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w42 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w45 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w48 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w51 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w54 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w57 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w60 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w63 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w66 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w69 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w72 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w75 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w78 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w81 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w84 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w87 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w90 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w93 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w96 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w99 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w102 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w105 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w108 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w111 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w114 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w117 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w120 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w123 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w126 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w129 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w132 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w135 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w138 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w141 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w144 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w147 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w150 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w153 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w156 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w159 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w2 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w5 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w8 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w11 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w14 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w17 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w20 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w23 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w26 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w29 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w32 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w35 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w38 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w41 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w44 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w47 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w50 +.if \n(77<\n(38 .nr 77 \n(38 +.nr 38 \w53 +.if \n(77<\n(38 .nr 77 \n(38 +.77 +.rm 77 +.nr 38 5n +.if \n(77<\n(38 .nr 77 \n(38 .nr 38 1n -.nr 79 0 -.nr 40 \n(79+(0*\n(38) -.nr 80 +\n(40 -.nr 41 \n(80+(3*\n(38) -.nr 81 +\n(41 -.nr 42 \n(81+(3*\n(38) -.nr 82 +\n(42 -.nr 43 \n(82+(3*\n(38) -.nr 83 +\n(43 -.nr 44 \n(83+(14*\n(38) -.nr 84 +\n(44 -.nr 45 \n(84+(3*\n(38) -.nr 85 +\n(45 -.nr 46 \n(85+(3*\n(38) -.nr 86 +\n(46 -.nr 47 \n(86+(3*\n(38) -.nr 87 +\n(47 -.nr 48 \n(87+(14*\n(38) -.nr 88 +\n(48 -.nr 49 \n(88+(3*\n(38) -.nr 89 +\n(49 -.nr 50 \n(89+(3*\n(38) -.nr 90 +\n(50 -.nr 51 \n(90+(3*\n(38) -.nr 91 +\n(51 -.nr TW \n(91 -.if t .if (\n(TW+\n(.o)>7.65i .tm Table at line 103 file Input is too wide - \n(TW units +.nr 65 0 +.nr 40 \n(65+((0*\n(38)/2) +.nr 66 +\n(40 +.nr 41 \n(66+((0*\n(38)/2) +.nr 67 +\n(41 +.nr 42 \n(67+((0*\n(38)/2) +.nr 68 +\n(42 +.nr 43 \n(68+((0*\n(38)/2) +.nr 69 +\n(43 +.nr 44 \n(69+((16*\n(38)/2) +.nr 70 +\n(44 +.nr 45 \n(70+((0*\n(38)/2) +.nr 71 +\n(45 +.nr 46 \n(71+((0*\n(38)/2) +.nr 72 +\n(46 +.nr 47 \n(72+((0*\n(38)/2) +.nr 73 +\n(47 +.nr 48 \n(73+((16*\n(38)/2) +.nr 74 +\n(48 +.nr 49 \n(74+((0*\n(38)/2) +.nr 75 +\n(49 +.nr 50 \n(75+((0*\n(38)/2) +.nr 76 +\n(50 +.nr 51 \n(76+((0*\n(38)/2) +.nr 77 +\n(51 +.nr TW \n(77 +.if t .if (\n(TW+\n(.o)>7.65i .tm Table at line 121 file Input is too wide - \n(TW units .fc   .nr #T 0-1 .nr #a 0-1 .eo .de T# +.nr 35 1m .ds #d .d .if \(ts\n(.z\(ts\(ts .ds #d nl .mk ## @@ -2117,409 +2442,481 @@ .ls .. .ec -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'aar\h'|\n(41u'mwPo\h'|\n(42u'1\h'|\n(43u'34\h'|\n(44u'adf\h'|\n(45u'sP\h'|\n(46u'1\h'|\n(47u'35\h'|\n(48u'adi\h'|\n(49u'mwPo\h'|\n(50u'2\h'|\n(51u'36 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'adp\h'|\n(41u'2\h'|\n(42u'\h'|\n(43u'38\h'|\n(44u'adp\h'|\n(45u'mPo\h'|\n(46u'2\h'|\n(47u'39\h'|\n(48u'adp\h'|\n(49u'sP\h'|\n(50u'1\h'|\n(51u'41 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'adp\h'|\n(41u'sN\h'|\n(42u'1\h'|\n(43u'42\h'|\n(44u'ads\h'|\n(45u'mwPo\h'|\n(46u'1\h'|\n(47u'43\h'|\n(48u'and\h'|\n(49u'mwPo\h'|\n(50u'1\h'|\n(51u'44 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'asp\h'|\n(41u'mwPo\h'|\n(42u'5\h'|\n(43u'45\h'|\n(44u'asp\h'|\n(45u'swP\h'|\n(46u'1\h'|\n(47u'50\h'|\n(48u'beq\h'|\n(49u'2\h'|\n(50u'\h'|\n(51u'51 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'beq\h'|\n(41u'sP\h'|\n(42u'1\h'|\n(43u'52\h'|\n(44u'bge\h'|\n(45u'sP\h'|\n(46u'1\h'|\n(47u'53\h'|\n(48u'bgt\h'|\n(49u'sP\h'|\n(50u'1\h'|\n(51u'54 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'ble\h'|\n(41u'sP\h'|\n(42u'1\h'|\n(43u'55\h'|\n(44u'blm\h'|\n(45u'sP\h'|\n(46u'1\h'|\n(47u'56\h'|\n(48u'blt\h'|\n(49u'sP\h'|\n(50u'1\h'|\n(51u'57 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'bne\h'|\n(41u'sP\h'|\n(42u'1\h'|\n(43u'58\h'|\n(44u'bra\h'|\n(45u'2\h'|\n(46u'\h'|\n(47u'59\h'|\n(48u'bra\h'|\n(49u'sN\h'|\n(50u'2\h'|\n(51u'60 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'bra\h'|\n(41u'sP\h'|\n(42u'2\h'|\n(43u'62\h'|\n(44u'cal\h'|\n(45u'mPo\h'|\n(46u'28\h'|\n(47u'64\h'|\n(48u'cal\h'|\n(49u'sP\h'|\n(50u'1\h'|\n(51u'92 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'cff\h'|\n(41u'-\h'|\n(42u'\h'|\n(43u'93\h'|\n(44u'cif\h'|\n(45u'-\h'|\n(46u'\h'|\n(47u'94\h'|\n(48u'cii\h'|\n(49u'-\h'|\n(50u'\h'|\n(51u'95 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'cmf\h'|\n(41u'sP\h'|\n(42u'1\h'|\n(43u'96\h'|\n(44u'cmi\h'|\n(45u'mwPo\h'|\n(46u'2\h'|\n(47u'97\h'|\n(48u'cmp\h'|\n(49u'-\h'|\n(50u'\h'|\n(51u'99 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'cms\h'|\n(41u'sP\h'|\n(42u'1\h'|\n(43u'100\h'|\n(44u'csa\h'|\n(45u'mwPo\h'|\n(46u'1\h'|\n(47u'101\h'|\n(48u'csb\h'|\n(49u'mwPo\h'|\n(50u'1\h'|\n(51u'102 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'dec\h'|\n(41u'-\h'|\n(42u'\h'|\n(43u'103\h'|\n(44u'dee\h'|\n(45u'sw\h'|\n(46u'1\h'|\n(47u'104\h'|\n(48u'del\h'|\n(49u'swN\h'|\n(50u'1\h'|\n(51u'105 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'dup\h'|\n(41u'mwPo\h'|\n(42u'1\h'|\n(43u'106\h'|\n(44u'dvf\h'|\n(45u'sP\h'|\n(46u'1\h'|\n(47u'107\h'|\n(48u'dvi\h'|\n(49u'mwPo\h'|\n(50u'1\h'|\n(51u'108 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'fil\h'|\n(41u'2\h'|\n(42u'\h'|\n(43u'109\h'|\n(44u'inc\h'|\n(45u'-\h'|\n(46u'\h'|\n(47u'110\h'|\n(48u'ine\h'|\n(49u'w2\h'|\n(50u'\h'|\n(51u'111 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'ine\h'|\n(41u'sw\h'|\n(42u'1\h'|\n(43u'112\h'|\n(44u'inl\h'|\n(45u'mwN\h'|\n(46u'3\h'|\n(47u'113\h'|\n(48u'inl\h'|\n(49u'swN\h'|\n(50u'1\h'|\n(51u'116 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'inn\h'|\n(41u'sP\h'|\n(42u'1\h'|\n(43u'117\h'|\n(44u'ior\h'|\n(45u'mwPo\h'|\n(46u'1\h'|\n(47u'118\h'|\n(48u'ior\h'|\n(49u'sP\h'|\n(50u'1\h'|\n(51u'119 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'lae\h'|\n(41u'2\h'|\n(42u'\h'|\n(43u'120\h'|\n(44u'lae\h'|\n(45u'sw\h'|\n(46u'7\h'|\n(47u'121\h'|\n(48u'lal\h'|\n(49u'P2\h'|\n(50u'\h'|\n(51u'128 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m -\&\h'|\n(40u'lal\h'|\n(41u'N2\h'|\n(42u'\h'|\n(43u'129\h'|\n(44u'lal\h'|\n(45u'm\h'|\n(46u'1\h'|\n(47u'130\h'|\n(48u'lal\h'|\n(49u'mN\h'|\n(50u'1\h'|\n(51u'131 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u .nr 31 \n(.f +\&\h'|\n(40u'lal\h'|\n(41u'N2\h'|\n(42u'\h'|\n(43u'129\h'|\n(44u'lal\h'|\n(45u'mP\h'|\n(46u'1\h'|\n(47u'130\h'|\n(48u'lal\h'|\n(49u'mN\h'|\n(50u'1\h'|\n(51u'131 +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'lal\h'|\n(41u'swP\h'|\n(42u'1\h'|\n(43u'132\h'|\n(44u'lal\h'|\n(45u'swN\h'|\n(46u'2\h'|\n(47u'133\h'|\n(48u'lar\h'|\n(49u'mwPo\h'|\n(50u'1\h'|\n(51u'135 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'ldc\h'|\n(41u'mP\h'|\n(42u'1\h'|\n(43u'136\h'|\n(44u'lde\h'|\n(45u'w2\h'|\n(46u'\h'|\n(47u'137\h'|\n(48u'lde\h'|\n(49u'sw\h'|\n(50u'1\h'|\n(51u'138 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'ldl\h'|\n(41u'mP\h'|\n(42u'1\h'|\n(43u'139\h'|\n(44u'ldl\h'|\n(45u'swN\h'|\n(46u'1\h'|\n(47u'140\h'|\n(48u'lfr\h'|\n(49u'mwPo\h'|\n(50u'2\h'|\n(51u'141 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'lfr\h'|\n(41u'sP\h'|\n(42u'1\h'|\n(43u'143\h'|\n(44u'lil\h'|\n(45u'swN\h'|\n(46u'1\h'|\n(47u'144\h'|\n(48u'lil\h'|\n(49u'swP\h'|\n(50u'1\h'|\n(51u'145 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'lil\h'|\n(41u'mwP\h'|\n(42u'2\h'|\n(43u'146\h'|\n(44u'lin\h'|\n(45u'2\h'|\n(46u'\h'|\n(47u'148\h'|\n(48u'lin\h'|\n(49u'sP\h'|\n(50u'1\h'|\n(51u'149 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'lni\h'|\n(41u'-\h'|\n(42u'\h'|\n(43u'150\h'|\n(44u'loc\h'|\n(45u'2\h'|\n(46u'\h'|\n(47u'151\h'|\n(48u'loc\h'|\n(49u'mP\h'|\n(50u'34\h'|\n(51u'0 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'loc\h'|\n(41u'mN\h'|\n(42u'1\h'|\n(43u'152\h'|\n(44u'loc\h'|\n(45u'sP\h'|\n(46u'1\h'|\n(47u'153\h'|\n(48u'loc\h'|\n(49u'sN\h'|\n(50u'1\h'|\n(51u'154 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'loe\h'|\n(41u'w2\h'|\n(42u'\h'|\n(43u'155\h'|\n(44u'loe\h'|\n(45u'sw\h'|\n(46u'5\h'|\n(47u'156\h'|\n(48u'lof\h'|\n(49u'2\h'|\n(50u'\h'|\n(51u'161 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'lof\h'|\n(41u'mwPo\h'|\n(42u'4\h'|\n(43u'162\h'|\n(44u'lof\h'|\n(45u'sP\h'|\n(46u'1\h'|\n(47u'166\h'|\n(48u'loi\h'|\n(49u'2\h'|\n(50u'\h'|\n(51u'167 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'loi\h'|\n(41u'mPo\h'|\n(42u'1\h'|\n(43u'168\h'|\n(44u'loi\h'|\n(45u'mwPo\h'|\n(46u'4\h'|\n(47u'169\h'|\n(48u'loi\h'|\n(49u'sP\h'|\n(50u'1\h'|\n(51u'173 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'lol\h'|\n(41u'wP2\h'|\n(42u'\h'|\n(43u'174\h'|\n(44u'lol\h'|\n(45u'wN2\h'|\n(46u'\h'|\n(47u'175\h'|\n(48u'lol\h'|\n(49u'mwP\h'|\n(50u'4\h'|\n(51u'176 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'lol\h'|\n(41u'mwN\h'|\n(42u'8\h'|\n(43u'180\h'|\n(44u'lol\h'|\n(45u'swP\h'|\n(46u'1\h'|\n(47u'188\h'|\n(48u'lol\h'|\n(49u'swN\h'|\n(50u'1\h'|\n(51u'189 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'lxa\h'|\n(41u'mPo\h'|\n(42u'1\h'|\n(43u'190\h'|\n(44u'lxl\h'|\n(45u'mPo\h'|\n(46u'2\h'|\n(47u'191\h'|\n(48u'mlf\h'|\n(49u'sP\h'|\n(50u'1\h'|\n(51u'193 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'mli\h'|\n(41u'mwPo\h'|\n(42u'2\h'|\n(43u'194\h'|\n(44u'rck\h'|\n(45u'mwPo\h'|\n(46u'1\h'|\n(47u'196\h'|\n(48u'ret\h'|\n(49u'mwP\h'|\n(50u'2\h'|\n(51u'197 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'ret\h'|\n(41u'sP\h'|\n(42u'1\h'|\n(43u'199\h'|\n(44u'rmi\h'|\n(45u'mwPo\h'|\n(46u'1\h'|\n(47u'200\h'|\n(48u'sar\h'|\n(49u'mwPo\h'|\n(50u'1\h'|\n(51u'201 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'sbf\h'|\n(41u'sP\h'|\n(42u'1\h'|\n(43u'202\h'|\n(44u'sbi\h'|\n(45u'mwPo\h'|\n(46u'2\h'|\n(47u'203\h'|\n(48u'sdl\h'|\n(49u'swN\h'|\n(50u'1\h'|\n(51u'205 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'set\h'|\n(41u'sP\h'|\n(42u'1\h'|\n(43u'206\h'|\n(44u'sil\h'|\n(45u'swN\h'|\n(46u'1\h'|\n(47u'207\h'|\n(48u'sil\h'|\n(49u'swP\h'|\n(50u'1\h'|\n(51u'208 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'sli\h'|\n(41u'mwPo\h'|\n(42u'1\h'|\n(43u'209\h'|\n(44u'ste\h'|\n(45u'w2\h'|\n(46u'\h'|\n(47u'210\h'|\n(48u'ste\h'|\n(49u'sw\h'|\n(50u'3\h'|\n(51u'211 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'stf\h'|\n(41u'2\h'|\n(42u'\h'|\n(43u'214\h'|\n(44u'stf\h'|\n(45u'mwPo\h'|\n(46u'2\h'|\n(47u'215\h'|\n(48u'stf\h'|\n(49u'sP\h'|\n(50u'1\h'|\n(51u'217 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'sti\h'|\n(41u'mPo\h'|\n(42u'1\h'|\n(43u'218\h'|\n(44u'sti\h'|\n(45u'mwPo\h'|\n(46u'4\h'|\n(47u'219\h'|\n(48u'sti\h'|\n(49u'sP\h'|\n(50u'1\h'|\n(51u'223 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'stl\h'|\n(41u'wP2\h'|\n(42u'\h'|\n(43u'224\h'|\n(44u'stl\h'|\n(45u'wN2\h'|\n(46u'\h'|\n(47u'225\h'|\n(48u'stl\h'|\n(49u'mwP\h'|\n(50u'2\h'|\n(51u'226 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'stl\h'|\n(41u'mwN\h'|\n(42u'5\h'|\n(43u'228\h'|\n(44u'stl\h'|\n(45u'swN\h'|\n(46u'1\h'|\n(47u'233\h'|\n(48u'teq\h'|\n(49u'-\h'|\n(50u'\h'|\n(51u'234 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'tgt\h'|\n(41u'-\h'|\n(42u'\h'|\n(43u'235\h'|\n(44u'tlt\h'|\n(45u'-\h'|\n(46u'\h'|\n(47u'236\h'|\n(48u'tne\h'|\n(49u'-\h'|\n(50u'\h'|\n(51u'237 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'zeq\h'|\n(41u'2\h'|\n(42u'\h'|\n(43u'238\h'|\n(44u'zeq\h'|\n(45u'sP\h'|\n(46u'2\h'|\n(47u'239\h'|\n(48u'zer\h'|\n(49u'sP\h'|\n(50u'1\h'|\n(51u'241 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'zge\h'|\n(41u'sP\h'|\n(42u'1\h'|\n(43u'242\h'|\n(44u'zgt\h'|\n(45u'sP\h'|\n(46u'1\h'|\n(47u'243\h'|\n(48u'zle\h'|\n(49u'sP\h'|\n(50u'1\h'|\n(51u'244 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'zlt\h'|\n(41u'sP\h'|\n(42u'1\h'|\n(43u'245\h'|\n(44u'zne\h'|\n(45u'sP\h'|\n(46u'1\h'|\n(47u'246\h'|\n(48u'zne\h'|\n(49u'sN\h'|\n(50u'1\h'|\n(51u'247 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'zre\h'|\n(41u'w2\h'|\n(42u'\h'|\n(43u'248\h'|\n(44u'zre\h'|\n(45u'sw\h'|\n(46u'1\h'|\n(47u'249\h'|\n(48u'zrl\h'|\n(49u'mwN\h'|\n(50u'2\h'|\n(51u'250 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'zrl\h'|\n(41u'swN\h'|\n(42u'1\h'|\n(43u'252\h'|\n(44u'zrl\h'|\n(45u'wN2\h'|\n(46u'\h'|\n(47u'253\h'|\n(48u'aar\h'|\n(49u'e2\h'|\n(50u'\h'|\n(51u'0 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'aar\h'|\n(41u'e-\h'|\n(42u'\h'|\n(43u'1\h'|\n(44u'adf\h'|\n(45u'e2\h'|\n(46u'\h'|\n(47u'2\h'|\n(48u'adf\h'|\n(49u'e-\h'|\n(50u'\h'|\n(51u'3 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'adi\h'|\n(41u'e2\h'|\n(42u'\h'|\n(43u'4\h'|\n(44u'adi\h'|\n(45u'e-\h'|\n(46u'\h'|\n(47u'5\h'|\n(48u'ads\h'|\n(49u'e2\h'|\n(50u'\h'|\n(51u'6 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'ads\h'|\n(41u'e-\h'|\n(42u'\h'|\n(43u'7\h'|\n(44u'adu\h'|\n(45u'e2\h'|\n(46u'\h'|\n(47u'8\h'|\n(48u'adu\h'|\n(49u'e-\h'|\n(50u'\h'|\n(51u'9 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'and\h'|\n(41u'e2\h'|\n(42u'\h'|\n(43u'10\h'|\n(44u'and\h'|\n(45u'e-\h'|\n(46u'\h'|\n(47u'11\h'|\n(48u'asp\h'|\n(49u'ew2\h'|\n(50u'\h'|\n(51u'12 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'ass\h'|\n(41u'e2\h'|\n(42u'\h'|\n(43u'13\h'|\n(44u'ass\h'|\n(45u'e-\h'|\n(46u'\h'|\n(47u'14\h'|\n(48u'bge\h'|\n(49u'e2\h'|\n(50u'\h'|\n(51u'15 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'bgt\h'|\n(41u'e2\h'|\n(42u'\h'|\n(43u'16\h'|\n(44u'ble\h'|\n(45u'e2\h'|\n(46u'\h'|\n(47u'17\h'|\n(48u'blm\h'|\n(49u'e2\h'|\n(50u'\h'|\n(51u'18 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'bls\h'|\n(41u'e2\h'|\n(42u'\h'|\n(43u'19\h'|\n(44u'bls\h'|\n(45u'e-\h'|\n(46u'\h'|\n(47u'20\h'|\n(48u'blt\h'|\n(49u'e2\h'|\n(50u'\h'|\n(51u'21 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'bne\h'|\n(41u'e2\h'|\n(42u'\h'|\n(43u'22\h'|\n(44u'cai\h'|\n(45u'e-\h'|\n(46u'\h'|\n(47u'23\h'|\n(48u'cal\h'|\n(49u'e2\h'|\n(50u'\h'|\n(51u'24 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'cfi\h'|\n(41u'e-\h'|\n(42u'\h'|\n(43u'25\h'|\n(44u'cfu\h'|\n(45u'e-\h'|\n(46u'\h'|\n(47u'26\h'|\n(48u'ciu\h'|\n(49u'e-\h'|\n(50u'\h'|\n(51u'27 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'cmf\h'|\n(41u'e2\h'|\n(42u'\h'|\n(43u'28\h'|\n(44u'cmf\h'|\n(45u'e-\h'|\n(46u'\h'|\n(47u'29\h'|\n(48u'cmi\h'|\n(49u'e2\h'|\n(50u'\h'|\n(51u'30 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'cmi\h'|\n(41u'e-\h'|\n(42u'\h'|\n(43u'31\h'|\n(44u'cms\h'|\n(45u'e2\h'|\n(46u'\h'|\n(47u'32\h'|\n(48u'cms\h'|\n(49u'e-\h'|\n(50u'\h'|\n(51u'33 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'cmu\h'|\n(41u'e2\h'|\n(42u'\h'|\n(43u'34\h'|\n(44u'cmu\h'|\n(45u'e-\h'|\n(46u'\h'|\n(47u'35\h'|\n(48u'com\h'|\n(49u'e2\h'|\n(50u'\h'|\n(51u'36 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'com\h'|\n(41u'e-\h'|\n(42u'\h'|\n(43u'37\h'|\n(44u'csa\h'|\n(45u'e2\h'|\n(46u'\h'|\n(47u'38\h'|\n(48u'csa\h'|\n(49u'e-\h'|\n(50u'\h'|\n(51u'39 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'csb\h'|\n(41u'e2\h'|\n(42u'\h'|\n(43u'40\h'|\n(44u'csb\h'|\n(45u'e-\h'|\n(46u'\h'|\n(47u'41\h'|\n(48u'cuf\h'|\n(49u'e-\h'|\n(50u'\h'|\n(51u'42 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'cui\h'|\n(41u'e-\h'|\n(42u'\h'|\n(43u'43\h'|\n(44u'cuu\h'|\n(45u'e-\h'|\n(46u'\h'|\n(47u'44\h'|\n(48u'dee\h'|\n(49u'ew2\h'|\n(50u'\h'|\n(51u'45 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'del\h'|\n(41u'ewP2\h'|\n(42u'\h'|\n(43u'46\h'|\n(44u'del\h'|\n(45u'ewN2\h'|\n(46u'\h'|\n(47u'47\h'|\n(48u'dup\h'|\n(49u'e2\h'|\n(50u'\h'|\n(51u'48 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'dus\h'|\n(41u'e2\h'|\n(42u'\h'|\n(43u'49\h'|\n(44u'dus\h'|\n(45u'e-\h'|\n(46u'\h'|\n(47u'50\h'|\n(48u'dvf\h'|\n(49u'e2\h'|\n(50u'\h'|\n(51u'51 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'dvf\h'|\n(41u'e-\h'|\n(42u'\h'|\n(43u'52\h'|\n(44u'dvi\h'|\n(45u'e2\h'|\n(46u'\h'|\n(47u'53\h'|\n(48u'dvi\h'|\n(49u'e-\h'|\n(50u'\h'|\n(51u'54 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'dvu\h'|\n(41u'e2\h'|\n(42u'\h'|\n(43u'55\h'|\n(44u'dvu\h'|\n(45u'e-\h'|\n(46u'\h'|\n(47u'56\h'|\n(48u'fef\h'|\n(49u'e2\h'|\n(50u'\h'|\n(51u'57 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'fef\h'|\n(41u'e-\h'|\n(42u'\h'|\n(43u'58\h'|\n(44u'fif\h'|\n(45u'e2\h'|\n(46u'\h'|\n(47u'59\h'|\n(48u'fif\h'|\n(49u'e-\h'|\n(50u'\h'|\n(51u'60 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'inl\h'|\n(41u'ewP2\h'|\n(42u'\h'|\n(43u'61\h'|\n(44u'inl\h'|\n(45u'ewN2\h'|\n(46u'\h'|\n(47u'62\h'|\n(48u'inn\h'|\n(49u'e2\h'|\n(50u'\h'|\n(51u'63 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'inn\h'|\n(41u'e-\h'|\n(42u'\h'|\n(43u'64\h'|\n(44u'ior\h'|\n(45u'e2\h'|\n(46u'\h'|\n(47u'65\h'|\n(48u'ior\h'|\n(49u'e-\h'|\n(50u'\h'|\n(51u'66 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'lar\h'|\n(41u'e2\h'|\n(42u'\h'|\n(43u'67\h'|\n(44u'lar\h'|\n(45u'e-\h'|\n(46u'\h'|\n(47u'68\h'|\n(48u'ldc\h'|\n(49u'e2\h'|\n(50u'\h'|\n(51u'69 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'ldf\h'|\n(41u'e2\h'|\n(42u'\h'|\n(43u'70\h'|\n(44u'ldl\h'|\n(45u'ewP2\h'|\n(46u'\h'|\n(47u'71\h'|\n(48u'ldl\h'|\n(49u'ewN2\h'|\n(50u'\h'|\n(51u'72 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'lfr\h'|\n(41u'e2\h'|\n(42u'\h'|\n(43u'73\h'|\n(44u'lil\h'|\n(45u'ewP2\h'|\n(46u'\h'|\n(47u'74\h'|\n(48u'lil\h'|\n(49u'ewN2\h'|\n(50u'\h'|\n(51u'75 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'lim\h'|\n(41u'e-\h'|\n(42u'\h'|\n(43u'76\h'|\n(44u'los\h'|\n(45u'e2\h'|\n(46u'\h'|\n(47u'77\h'|\n(48u'los\h'|\n(49u'e-\h'|\n(50u'\h'|\n(51u'78 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'lor\h'|\n(41u'esP\h'|\n(42u'1\h'|\n(43u'79\h'|\n(44u'lpi\h'|\n(45u'e2\h'|\n(46u'\h'|\n(47u'80\h'|\n(48u'lxa\h'|\n(49u'e2\h'|\n(50u'\h'|\n(51u'81 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'lxl\h'|\n(41u'e2\h'|\n(42u'\h'|\n(43u'82\h'|\n(44u'mlf\h'|\n(45u'e2\h'|\n(46u'\h'|\n(47u'83\h'|\n(48u'mlf\h'|\n(49u'e-\h'|\n(50u'\h'|\n(51u'84 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'mli\h'|\n(41u'e2\h'|\n(42u'\h'|\n(43u'85\h'|\n(44u'mli\h'|\n(45u'e-\h'|\n(46u'\h'|\n(47u'86\h'|\n(48u'mlu\h'|\n(49u'e2\h'|\n(50u'\h'|\n(51u'87 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'mlu\h'|\n(41u'e-\h'|\n(42u'\h'|\n(43u'88\h'|\n(44u'mon\h'|\n(45u'e-\h'|\n(46u'\h'|\n(47u'89\h'|\n(48u'ngf\h'|\n(49u'e2\h'|\n(50u'\h'|\n(51u'90 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'ngf\h'|\n(41u'e-\h'|\n(42u'\h'|\n(43u'91\h'|\n(44u'ngi\h'|\n(45u'e2\h'|\n(46u'\h'|\n(47u'92\h'|\n(48u'ngi\h'|\n(49u'e-\h'|\n(50u'\h'|\n(51u'93 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'nop\h'|\n(41u'e-\h'|\n(42u'\h'|\n(43u'94\h'|\n(44u'rck\h'|\n(45u'e2\h'|\n(46u'\h'|\n(47u'95\h'|\n(48u'rck\h'|\n(49u'e-\h'|\n(50u'\h'|\n(51u'96 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'ret\h'|\n(41u'e2\h'|\n(42u'\h'|\n(43u'97\h'|\n(44u'rmi\h'|\n(45u'e2\h'|\n(46u'\h'|\n(47u'98\h'|\n(48u'rmi\h'|\n(49u'e-\h'|\n(50u'\h'|\n(51u'99 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'rmu\h'|\n(41u'e2\h'|\n(42u'\h'|\n(43u'100\h'|\n(44u'rmu\h'|\n(45u'e-\h'|\n(46u'\h'|\n(47u'101\h'|\n(48u'rol\h'|\n(49u'e2\h'|\n(50u'\h'|\n(51u'102 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'rol\h'|\n(41u'e-\h'|\n(42u'\h'|\n(43u'103\h'|\n(44u'ror\h'|\n(45u'e2\h'|\n(46u'\h'|\n(47u'104\h'|\n(48u'ror\h'|\n(49u'e-\h'|\n(50u'\h'|\n(51u'105 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'rtt\h'|\n(41u'e-\h'|\n(42u'\h'|\n(43u'106\h'|\n(44u'sar\h'|\n(45u'e2\h'|\n(46u'\h'|\n(47u'107\h'|\n(48u'sar\h'|\n(49u'e-\h'|\n(50u'\h'|\n(51u'108 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'sbf\h'|\n(41u'e2\h'|\n(42u'\h'|\n(43u'109\h'|\n(44u'sbf\h'|\n(45u'e-\h'|\n(46u'\h'|\n(47u'110\h'|\n(48u'sbi\h'|\n(49u'e2\h'|\n(50u'\h'|\n(51u'111 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'sbi\h'|\n(41u'e-\h'|\n(42u'\h'|\n(43u'112\h'|\n(44u'sbs\h'|\n(45u'e2\h'|\n(46u'\h'|\n(47u'113\h'|\n(48u'sbs\h'|\n(49u'e-\h'|\n(50u'\h'|\n(51u'114 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'sbu\h'|\n(41u'e2\h'|\n(42u'\h'|\n(43u'115\h'|\n(44u'sbu\h'|\n(45u'e-\h'|\n(46u'\h'|\n(47u'116\h'|\n(48u'sde\h'|\n(49u'e2\h'|\n(50u'\h'|\n(51u'117 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'sdf\h'|\n(41u'e2\h'|\n(42u'\h'|\n(43u'118\h'|\n(44u'sdl\h'|\n(45u'ewP2\h'|\n(46u'\h'|\n(47u'119\h'|\n(48u'sdl\h'|\n(49u'ewN2\h'|\n(50u'\h'|\n(51u'120 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'set\h'|\n(41u'e2\h'|\n(42u'\h'|\n(43u'121\h'|\n(44u'set\h'|\n(45u'e-\h'|\n(46u'\h'|\n(47u'122\h'|\n(48u'sig\h'|\n(49u'e-\h'|\n(50u'\h'|\n(51u'123 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'sil\h'|\n(41u'ewP2\h'|\n(42u'\h'|\n(43u'124\h'|\n(44u'sil\h'|\n(45u'ewN2\h'|\n(46u'\h'|\n(47u'125\h'|\n(48u'sim\h'|\n(49u'e-\h'|\n(50u'\h'|\n(51u'126 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'sli\h'|\n(41u'e2\h'|\n(42u'\h'|\n(43u'127\h'|\n(44u'sli\h'|\n(45u'e-\h'|\n(46u'\h'|\n(47u'128\h'|\n(48u'slu\h'|\n(49u'e2\h'|\n(50u'\h'|\n(51u'129 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'slu\h'|\n(41u'e-\h'|\n(42u'\h'|\n(43u'130\h'|\n(44u'sri\h'|\n(45u'e2\h'|\n(46u'\h'|\n(47u'131\h'|\n(48u'sri\h'|\n(49u'e-\h'|\n(50u'\h'|\n(51u'132 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'sru\h'|\n(41u'e2\h'|\n(42u'\h'|\n(43u'133\h'|\n(44u'sru\h'|\n(45u'e-\h'|\n(46u'\h'|\n(47u'134\h'|\n(48u'sti\h'|\n(49u'e2\h'|\n(50u'\h'|\n(51u'135 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'sts\h'|\n(41u'e2\h'|\n(42u'\h'|\n(43u'136\h'|\n(44u'sts\h'|\n(45u'e-\h'|\n(46u'\h'|\n(47u'137\h'|\n(48u'str\h'|\n(49u'esP\h'|\n(50u'1\h'|\n(51u'138 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'tge\h'|\n(41u'e-\h'|\n(42u'\h'|\n(43u'139\h'|\n(44u'tle\h'|\n(45u'e-\h'|\n(46u'\h'|\n(47u'140\h'|\n(48u'trp\h'|\n(49u'e-\h'|\n(50u'\h'|\n(51u'141 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'xor\h'|\n(41u'e2\h'|\n(42u'\h'|\n(43u'142\h'|\n(44u'xor\h'|\n(45u'e-\h'|\n(46u'\h'|\n(47u'143\h'|\n(48u'zer\h'|\n(49u'e2\h'|\n(50u'\h'|\n(51u'144 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'zer\h'|\n(41u'e-\h'|\n(42u'\h'|\n(43u'145\h'|\n(44u'zge\h'|\n(45u'e2\h'|\n(46u'\h'|\n(47u'146\h'|\n(48u'zgt\h'|\n(49u'e2\h'|\n(50u'\h'|\n(51u'147 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'zle\h'|\n(41u'e2\h'|\n(42u'\h'|\n(43u'148\h'|\n(44u'zlt\h'|\n(45u'e2\h'|\n(46u'\h'|\n(47u'149\h'|\n(48u'zne\h'|\n(49u'e2\h'|\n(50u'\h'|\n(51u'150 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'zrf\h'|\n(41u'e2\h'|\n(42u'\h'|\n(43u'151\h'|\n(44u'zrf\h'|\n(45u'e-\h'|\n(46u'\h'|\n(47u'152\h'|\n(48u'zrl\h'|\n(49u'ewP2\h'|\n(50u'\h'|\n(51u'153 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'dch\h'|\n(41u'e-\h'|\n(42u'\h'|\n(43u'154\h'|\n(44u'exg\h'|\n(45u'esP\h'|\n(46u'1\h'|\n(47u'155\h'|\n(48u'exg\h'|\n(49u'e2\h'|\n(50u'\h'|\n(51u'156 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m +.nr 31 \n(.f \&\h'|\n(40u'exg\h'|\n(41u'e-\h'|\n(42u'\h'|\n(43u'157\h'|\n(44u'lpb\h'|\n(45u'e-\h'|\n(46u'\h'|\n(47u'158\h'|\n(48u'gto\h'|\n(49u'e2\h'|\n(50u'\h'|\n(51u'159 -.ta \n(80u \n(81u \n(82u \n(83u \n(84u \n(85u \n(86u \n(87u \n(88u \n(89u \n(90u \n(91u -.nr 31 \n(.f +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u .nr 35 1m -\&\h'|\n(40u'ldc\h'|\n(41u'4\h'|\n(42u'\h'|\n(43u'0\h'|\n(44u'\h'|\n(45u'\h'|\n(46u'\h'|\n(47u'\h'|\n(48u'\h'|\n(49u'\h'|\n(50u'\h'|\n(51u' +.nr 31 \n(.f +\&\h'|\n(40u'ldc\h'|\n(41u'4\h'|\n(42u'\h'|\n(43u'0\h'|\n(44u'lae\h'|\n(45u'4\h'|\n(46u'\h'|\n(47u'1\h'|\n(48u'lal\h'|\n(49u'P4\h'|\n(50u'\h'|\n(51u'2 +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u +.nr 35 1m +.nr 31 \n(.f +\&\h'|\n(40u'lal\h'|\n(41u'N4\h'|\n(42u'\h'|\n(43u'3\h'|\n(44u'lde\h'|\n(45u'w4\h'|\n(46u'\h'|\n(47u'4\h'|\n(48u'ldf\h'|\n(49u'4\h'|\n(50u'\h'|\n(51u'5 +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u +.nr 35 1m +.nr 31 \n(.f +\&\h'|\n(40u'ldl\h'|\n(41u'wP4\h'|\n(42u'\h'|\n(43u'6\h'|\n(44u'ldl\h'|\n(45u'wN4\h'|\n(46u'\h'|\n(47u'7\h'|\n(48u'lil\h'|\n(49u'wP4\h'|\n(50u'\h'|\n(51u'8 +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u +.nr 35 1m +.nr 31 \n(.f +\&\h'|\n(40u'lil\h'|\n(41u'wN4\h'|\n(42u'\h'|\n(43u'9\h'|\n(44u'loc\h'|\n(45u'4\h'|\n(46u'\h'|\n(47u'10\h'|\n(48u'loe\h'|\n(49u'w4\h'|\n(50u'\h'|\n(51u'11 +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u +.nr 35 1m +.nr 31 \n(.f +\&\h'|\n(40u'lof\h'|\n(41u'4\h'|\n(42u'\h'|\n(43u'12\h'|\n(44u'lol\h'|\n(45u'wP4\h'|\n(46u'\h'|\n(47u'13\h'|\n(48u'lol\h'|\n(49u'wN4\h'|\n(50u'\h'|\n(51u'14 +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u +.nr 35 1m +.nr 31 \n(.f +\&\h'|\n(40u'lpi\h'|\n(41u'4\h'|\n(42u'\h'|\n(43u'15\h'|\n(44u'adp\h'|\n(45u'4\h'|\n(46u'\h'|\n(47u'16\h'|\n(48u'asp\h'|\n(49u'w4\h'|\n(50u'\h'|\n(51u'17 +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u +.nr 35 1m +.nr 31 \n(.f +\&\h'|\n(40u'beq\h'|\n(41u'4\h'|\n(42u'\h'|\n(43u'18\h'|\n(44u'bge\h'|\n(45u'4\h'|\n(46u'\h'|\n(47u'19\h'|\n(48u'bgt\h'|\n(49u'4\h'|\n(50u'\h'|\n(51u'20 +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u +.nr 35 1m +.nr 31 \n(.f +\&\h'|\n(40u'ble\h'|\n(41u'4\h'|\n(42u'\h'|\n(43u'21\h'|\n(44u'blm\h'|\n(45u'4\h'|\n(46u'\h'|\n(47u'22\h'|\n(48u'blt\h'|\n(49u'4\h'|\n(50u'\h'|\n(51u'23 +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u +.nr 35 1m +.nr 31 \n(.f +\&\h'|\n(40u'bne\h'|\n(41u'4\h'|\n(42u'\h'|\n(43u'24\h'|\n(44u'bra\h'|\n(45u'4\h'|\n(46u'\h'|\n(47u'25\h'|\n(48u'cal\h'|\n(49u'4\h'|\n(50u'\h'|\n(51u'26 +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u +.nr 35 1m +.nr 31 \n(.f +\&\h'|\n(40u'dee\h'|\n(41u'w4\h'|\n(42u'\h'|\n(43u'27\h'|\n(44u'del\h'|\n(45u'wP4\h'|\n(46u'\h'|\n(47u'28\h'|\n(48u'del\h'|\n(49u'wN4\h'|\n(50u'\h'|\n(51u'29 +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u +.nr 35 1m +.nr 31 \n(.f +\&\h'|\n(40u'fil\h'|\n(41u'4\h'|\n(42u'\h'|\n(43u'30\h'|\n(44u'gto\h'|\n(45u'4\h'|\n(46u'\h'|\n(47u'31\h'|\n(48u'ine\h'|\n(49u'w4\h'|\n(50u'\h'|\n(51u'32 +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u +.nr 35 1m +.nr 31 \n(.f +\&\h'|\n(40u'inl\h'|\n(41u'wP4\h'|\n(42u'\h'|\n(43u'33\h'|\n(44u'inl\h'|\n(45u'wN4\h'|\n(46u'\h'|\n(47u'34\h'|\n(48u'lin\h'|\n(49u'4\h'|\n(50u'\h'|\n(51u'35 +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u +.nr 35 1m +.nr 31 \n(.f +\&\h'|\n(40u'sde\h'|\n(41u'4\h'|\n(42u'\h'|\n(43u'36\h'|\n(44u'sdf\h'|\n(45u'4\h'|\n(46u'\h'|\n(47u'37\h'|\n(48u'sdl\h'|\n(49u'wP4\h'|\n(50u'\h'|\n(51u'38 +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u +.nr 35 1m +.nr 31 \n(.f +\&\h'|\n(40u'sdl\h'|\n(41u'wN4\h'|\n(42u'\h'|\n(43u'39\h'|\n(44u'sil\h'|\n(45u'wP4\h'|\n(46u'\h'|\n(47u'40\h'|\n(48u'sil\h'|\n(49u'wN4\h'|\n(50u'\h'|\n(51u'41 +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u +.nr 35 1m +.nr 31 \n(.f +\&\h'|\n(40u'ste\h'|\n(41u'w4\h'|\n(42u'\h'|\n(43u'42\h'|\n(44u'stf\h'|\n(45u'4\h'|\n(46u'\h'|\n(47u'43\h'|\n(48u'stl\h'|\n(49u'wP4\h'|\n(50u'\h'|\n(51u'44 +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u +.nr 35 1m +.nr 31 \n(.f +\&\h'|\n(40u'stl\h'|\n(41u'wN4\h'|\n(42u'\h'|\n(43u'45\h'|\n(44u'zeq\h'|\n(45u'4\h'|\n(46u'\h'|\n(47u'46\h'|\n(48u'zge\h'|\n(49u'4\h'|\n(50u'\h'|\n(51u'47 +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u +.nr 35 1m +.nr 31 \n(.f +\&\h'|\n(40u'zgt\h'|\n(41u'4\h'|\n(42u'\h'|\n(43u'48\h'|\n(44u'zle\h'|\n(45u'4\h'|\n(46u'\h'|\n(47u'49\h'|\n(48u'zlt\h'|\n(49u'4\h'|\n(50u'\h'|\n(51u'50 +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u +.nr 35 1m +.nr 31 \n(.f +\&\h'|\n(40u'zne\h'|\n(41u'4\h'|\n(42u'\h'|\n(43u'51\h'|\n(44u'zre\h'|\n(45u'w4\h'|\n(46u'\h'|\n(47u'52\h'|\n(48u'zrl\h'|\n(49u'wP4\h'|\n(50u'\h'|\n(51u'53 +.ta \n(66u \n(67u \n(68u \n(69u \n(70u \n(71u \n(72u \n(73u \n(74u \n(75u \n(76u \n(77u +.nr 35 1m +.nr 31 \n(.f +\&\h'|\n(40u'zrl\h'|\n(41u'wN4\h'|\n(42u'\h'|\n(43u'54\h'|\n(44u'\h'|\n(45u'\h'|\n(46u'\h'|\n(47u'\h'|\n(48u'\h'|\n(49u'\h'|\n(50u'\h'|\n(51u' .fc .nr T. 1 .T# 1 .35 .TE -.if \n-(b.=0 .nr c. \n(.c-\n(d.-102 +.if \n-(b.=0 .nr c. \n(.c-\n(d.-120 diff --git a/doc/em/mach.nr b/doc/em/mach.nr index 1374eff3..158790ad 100644 --- a/doc/em/mach.nr +++ b/doc/em/mach.nr @@ -21,7 +21,7 @@ two groups of 256 secondary opcodes each. .A EM instructions without arguments have a single opcode assigned, possibly escaped: -.DS +.Dr 14 |--------------| | opcode | @@ -33,7 +33,7 @@ possibly escaped: | escape | opcode | |--------------|--------------| -.DE +.De The encoding for instructions with an argument is more complex. Several instructions have an address from the global data area as argument. @@ -42,7 +42,7 @@ and negative arguments. .N 1 There is always an opcode that takes the next two bytes as argument, high byte first: -.DS +.Dr 14 |--------------|--------------|--------------| | opcode | hibyte | lobyte | @@ -54,25 +54,25 @@ high byte first: | escape | opcode | hibyte | lobyte | |--------------|--------------|--------------|--------------| -.DE -.DS +.De An extra escape is provided for instructions with four or eight byte arguments. +.Dr 6 |--------------|--------------|--------------| |--------------| | ESCAPE | opcode | hibyte |...| lobyte | |--------------|--------------|--------------| |--------------| -.DE +.De For most instructions some argument values predominate. The most frequent combinations of instruction and argument will be encoded in a single byte, called a mini: -.DS +.Dr 6 |---------------| |opcode+argument| (mini) |---------------| -.DE +.De The number of minis is restricted, because only 254 primary opcodes are available. Many instructions have the bulk of their arguments @@ -85,7 +85,7 @@ that combines the instruction and the high byte of the argument into a single opcode. These opcodes are called shorties. Shorties may be escaped. -.DS +.Dr 14 |--------------|--------------| | opcode+high | lobyte | (shortie) @@ -97,7 +97,7 @@ Shorties may be escaped. | escape | opcode+high | lobyte | |--------------|--------------|--------------| -.DE +.De Escaped shorties are useless if the normal encoding has a primary opcode. Note that for some instruction-argument combinations several different encodings are available. @@ -266,66 +266,66 @@ contain a null terminated ASCII string .PE 1 .DE 0 .VS 1 1 -.DS +.Dr 6 ------------------- | 0 | n | repeat last initialization n times ------------------- -.DE -.DS +.De +.Dr 4 --------- | 1 | m | m uninitialized words --------- -.DE -.DS +.De +.Dr 6 ____________ / bytes \e ----------------- ----- | 2 | m | b | b |...| b | m initialized bytes ----------------- ----- -.DE -.DS +.De +.Dr 6 _________ / word \e ----------------------- | 3 | m | w |... m initialized wordsized integers ----------------------- -.DE -.DS +.De +.Dr 6 _________ / pointer \e ----------------------- | 4 | m | p |... m initialized data pointers ----------------------- -.DE -.DS +.De +.Dr 6 _________ / pointer \e ----------------------- | 5 | m | p |... m initialized instruction pointers ----------------------- -.DE -.DS +.De +.Dr 6 ____________ / bytes \e ------------------------- | 6 | m | b | b |...| b | initialized integer of size m ------------------------- -.DE -.DS +.De +.Dr 6 ____________ / bytes \e ------------------------- | 7 | m | b | b |...| b | initialized unsigned of size m ------------------------- -.DE -.DS +.De +.Dr 6 ____________ / string \e ------------------------- | 8 | m | s | initialized float of size m ------------------------- -.DE 3 +.De 3 .PS - 8 .PT type~0: If the last initialization initialized k bytes starting diff --git a/doc/em/macr.nr b/doc/em/macr.nr index 14c628c4..1c903f30 100644 --- a/doc/em/macr.nr +++ b/doc/em/macr.nr @@ -1,8 +1,7 @@ -.so /usr/lib/tmac/tmac.kun -.SS 6 +.if n .so /usr/lib/tmac/tmac.kun +.if t .so /usr/lib/ditroff/tmac/tmac.kun +.SS 10 .RP -.PL 12i 11i -.LL 89 .MS T E \!.TL '%''' .ME @@ -14,3 +13,24 @@ .ME .SM S1 B .SM S2 B +.\" below are three simple macros to get the drawings right +.\" added by Dick Grune +.de Dr \" Drawing $1 (size) +.N 1 +.NE \\$1 +.NA +.cs 1 18 \" constant spacing +.lg 0 \" no ligatures +.ss 18 \" bug in troff +.. +.de Df \" Drawing Footer +.br +.cs 1 +.ss 12 +.lg 1 +.. +.de De \" Drawing End $1 (lines) +.Df \" if it hasn't happened yet +.AD +.N \\$1 +.. diff --git a/doc/em/mapping.nr b/doc/em/mapping.nr index fbd0ff11..a165ab4f 100644 --- a/doc/em/mapping.nr +++ b/doc/em/mapping.nr @@ -14,46 +14,46 @@ with 64K bytes of address space. Here we use a member of the EM family with 2-byte word and pointer size. The most straightforward layout is shown in figure 2. -.N 1 -.DS - 65534 -> |-------------------------------| +.Dr 40 + 65534 \-> |-------------------------------| |///////////////////////////////| |//// unimplemented memory /////| |///////////////////////////////| - ML -> |-------------------------------| + ML \-> |-------------------------------| | | - | | <- LB + | | <\- LB | stack and local area | | | - |-------------------------------| <- SP + |-------------------------------| <\- SP |///////////////////////////////| |//////// inaccessible /////////| |///////////////////////////////| - |-------------------------------| <- HP + |-------------------------------| <\- HP | | | heap area | | | | | - HB -> |-------------------------------| + HB \-> |-------------------------------| | | | global data area | | | - EB -> |-------------------------------| + EB \-> |-------------------------------| | | - | program text | <- PC + | program text | <\- PC | | | ( and tables ) | | | | | - PB -> |-------------------------------| + PB \-> |-------------------------------| |///////////////////////////////| |////////// undefined //////////| |///////////////////////////////| - 0 -> |-------------------------------| - + 0 \-> |-------------------------------| +.Df Figure 2. Memory layout showing typical register positions during execution of an EM program. -.DE 2 +.De +.N 1 The base registers for the various memory pieces can be stored in target machine registers or memory. .IS @@ -123,8 +123,7 @@ upside down, as shown in figure 3. This is possible because the pointer format is explicitly undefined. The first element of a word array will have a lower physical address than the second element. -.N 2 -.DS +.Dr 18 | | | | | EB=60 | | ^ | | | | | | @@ -140,18 +139,18 @@ lower physical address than the second element. | | | | Type A Type B -.sp 2 +.Df Figure 3. Two possible memory implementations. Numbers within the boxes are EM addresses. The other numbers are physical addresses. -.DE 2 +.De .A 0 0 So, we have two different EM memory implementations: .IS .PS - 4 -.PT A~- +.PT A~\- stack downwards -.PT B~- +.PT B~\- stack upwards .PE .IE @@ -188,7 +187,7 @@ ADP:3:pop:r0:pop:r0 ::push:r0:push:r0 LOI:1:pop:r0:pop:r0 -::-::neg:r0 +::\-::neg:r0 ::clr:r1:clr:r1 ::bisb:eb(r0),r1:bisb:eb(r0),r1 ::push:r1:push:r1 diff --git a/doc/em/title.nr b/doc/em/title.nr index 348d55db..20f5a891 100644 --- a/doc/em/title.nr +++ b/doc/em/title.nr @@ -1,6 +1,6 @@ .po 0 .TP 1 -.ll 79 +.ll 79n .sp 15 .ce 4 DESCRIPTION OF A MACHINE diff --git a/doc/em/traps.nr b/doc/em/traps.nr new file mode 100644 index 00000000..b6d41261 --- /dev/null +++ b/doc/em/traps.nr @@ -0,0 +1,171 @@ +.SN 9 +.VS 1 0 +.BP +.S1 "TRAPS AND INTERRUPTS" +EM provides a means for the user program to catch all traps +generated by the program itself, the hardware, or external conditions. +This mechanism uses five instructions: LIM, SIM, SIG, TRP and RTT. +This section of the manual may be omitted on the first reading since it +presupposes knowledge of the EM instruction set. +.P +The action taken when a trap occures is determined by the value +of an internal EM trap register. +This register contains a pointer to a procedure. +Initially the pointer used is zero and all traps halt the +program with, hopefully, a useful message to the outside world. +The SIG instruction can be used to alter the trap register, +it pops a procedure pointer from the +stack into the trap register. +When a trap occurs after storing a nonzero value in the trap +register, the procedure pointed to by the trap register +is called with the trap number +as the only parameter (see below). +SIG returns the previous value of the trap register on the +stack. +Two consecutive SIGs are a no-op. +When a trap occurs, the trap register is reset to its initial +condition, to prevent recursive traps from hanging the machine up, +e.g. stack overflow in the stack overflow handling procedure. +.P +The runtime systems for some languages need to ignore some EM +traps. +EM offers a feature called the ignore mask. +It contains one bit for each of the lowest 16 trap numbers. +The bits are numbered 0 to 15, with the least significant bit +having number 0. +If a certain bit is 1 the corresponding trap never +occurs and processing simply continues. +The actions performed by the offending instruction are +described by the Pascal program in appendix A. +.N +If the bit is 0, traps are not ignored. +The instructions LIM and SIM allow copying and replacement of +the ignore mask.~ +.P +The TRP instruction generates a trap, the trap number being found on the +stack. +This is, among other things, +useful for library procedures and runtime systems. +It can also be used by a low level trap procedure to pass the trap to a +higher level one (see example below). +.P +The RTT instruction returns from the trap procedure and continues after the +trap. +In the list below all traps marked with an asterisk ('*') are +considered to be fatal and it is explicitly undefined what happens if +you try to restart after the trap. +.P +The way a trap procedure is called is completely compatible +with normal calling conventions. The only way a trap procedure +differs from normal procedures is the return. It has to use RTT instead +of RET. This is necessary because the complete runtime status is saved on the +stack before calling the procedure and all this status has to be reloaded. +Error numbers are in the range 0 to 252. +The trap numbers are divided into three categories: +.IS 4 +.N 1 +.PS - 10 +.PT ~~0\-~63 +EM machine errors, e.g. illegal instruction. +.PS - 8 +.PT ~0\-15 +maskable +.PT 16\-63 +not maskable +.PE +.PT ~64\-127 +Reserved for use by compilers, run time systems, etc. +.PT 128\-252 +Available for user programs. +.PE 1 +.IE +EM machine errors are numbered as follows: +.DS I 5 +.TS +tab(@); +n l l. +0@EARRAY@Array bound error +1@ERANGE@Range bound error +2@ESET@Set bound error +3@EIOVFL@Integer overflow +4@EFOVFL@Floating overflow +5@EFUNFL@Floating underflow +6@EIDIVZ@Divide by 0 +7@EFDIVZ@Divide by 0.0 +8@EIUND@Undefined integer +9@EFUND@Undefined float +10@ECONV@Conversion error +16*@ESTACK@Stack overflow +17*@EHEAP@Heap overflow +18*@EILLINS@Illegal instruction +19*@EODDZ@Illegal size argument +20*@ECASE@Case error +21*@EMEMFLT@Addressing non existent memory +22*@EBADPTR@Bad pointer used +23*@EBADPC@Program counter out of range +24@EBADLAE@Bad argument of LAE +25@EBADMON@Bad monitor call +26@EBADLIN@Argument of LIN too high +27@EBADGTO@GTO descriptor error +.TE +.DE 0 +.P +As an example, +suppose a subprocedure has to be written to do a numeric +calculation. +When an overflow occurs the computation has to be stopped and +the higher level procedure must be resumed. +This can be programmed as follows using the mechanism described above: +.DS B +.ta 1n 24n + mes 2,2,2 ; set sizes +ersave + bss 2,0,0 ; Room to save previous value of trap procedure +msave + bss 2,0,0 ; Room to save previous value of trap mask + + pro calcule,0 ; entry point + lxl 0 ; fill in non-local goto descriptor with LB + ste jmpbuf+4 + lor 1 ; and SP + ste jmpbuf+2 + lim ; get current ignore mask + ste msave ; save it + lim + loc 16 ; bit for EFOVFL + ior 2 ; set in mask + sim ; ignore EFOVFL from now on + lpi $catch ; load procedure identifier + sig ; catch wil get all traps now + ste ersave ; save previous trap procedure identifier + ; perform calculation now, possibly generating overflow +1 ; label jumped to by catch procedure + loe ersave ; get old trap procedure + sig ; refer all following trap to old procedure + asp 2 ; remove result of sig + loe msave ; restore previous mask + sim ; done now + ; load result of calculation + ret 2 ; return result +jmpbuf + con *1,0,0 + end +.DE 0 +.VS 1 1 +.DS +Example of catch procedure +.ta 1n 24n + pro catch,0 ; Local procedure that must catch the overflow trap + lol 2 ; Load trap number + loc 4 ; check for overflow + bne *1 ; if other trap, call higher trap procedure + gto jmpbuf ; return to procedure calcule +1 ; other trap has occurred + loe ersave ; previous trap procedure + sig ; other procedure will get the traps now + asp 2 ; remove the result of sig + lol 2 ; stack trap number + trp ; call other trap procedure + rtt ; if other procedure returns, do the same + end +.DE diff --git a/doc/em/types.nr b/doc/em/types.nr index c014a78a..27cb2c9d 100644 --- a/doc/em/types.nr +++ b/doc/em/types.nr @@ -33,7 +33,7 @@ restrictions imposed on the representation of the types used. A number \fBn\fP used in these paragraphs indicates the size of the object in \fIbits\fP. .S2 "Unsigned integers" -The range of unsigned integers is 0..2\v'-0.5m'\fBn\fP\v'0.5m'-1. +The range of unsigned integers is 0..2\v'-0.5m'\fBn\fP\v'0.5m'\-1. A binary representation is assumed. The order of the bits within an object is knowingly left unspecified. @@ -60,21 +60,22 @@ and expect a correct result. We assume existence of at least single word unsigned arithmetic in any implementation. .S2 "Signed Integers" -The range of signed integers is -2\v'-0.5m'\fBn\fP-1\v'0.5m'~..~2\v'-0.5m'\fBn\fP-1\v'0.5m'-1, +The range of signed integers is +\-2\v'-0.5m'\fBn\fP\-1\v'0.5m'~..~2\v'-0.5m'\fBn\fP\-1\v'0.5m'\-1, in other words the range of signed integers of \fBn\fP bits using two's complement arithmetic. -The representation is the same as for unsigned integers except -the range 2\v'-0.5m'\fBn\fP-1\v'0.5m'~..~2\v'-0.5m'\fBn\fP\v'0.5m'-1 is mapped on the -range -2\v'-0.5m'\fBn\fP-1\v'0.5m'~..~-1. +The representation is the same as for unsigned integers except the range +2\v'-0.5m'\fBn\fP\-1\v'0.5m'~..~2\v'-0.5m'\fBn\fP\v'0.5m'\-1 is mapped on the +range \-2\v'-0.5m'\fBn\fP\-1\v'0.5m'~..~\-1. In other words, the most significant bit is used as sign bit. The convert instructions between signed and unsigned integers of the same size can be used to catch errors. .A -The value -2\v'-0.5m'\fBn\fP-1\v'0.5m' is used for undefined +The value \-2\v'-0.5m'\fBn\fP\-1\v'0.5m' is used for undefined signed integers. EM implementations should trap when this value is used in an operation on signed integers. -The instruction mask, accessed with SIM and LIM -~see chapter 9~- , +The instruction mask, accessed with SIM and LIM \-~see chapter 9~\- , can be used to disable such traps. .A We assume existence of at least single word signed arithmetic @@ -126,5 +127,5 @@ the value of the unsigned integer is the summation of the Example: a 2-word bit set (wordsize 2) containing the elements 1, 6, 8, 15, 18, 21, 27 and 28 is composed of two integers, e.g. at addresses 40 and 42. -The word at 40 contains the value 33090 (or~-32446), +The word at 40 contains the value 33090 (or~\-32446), the word at 42 contains the value 6180. From 8002aeb6cc98690fcedb059e6a6071f6e3f9296e Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 10 Feb 1986 10:08:27 +0000 Subject: [PATCH 0108/1625] A minor improvement. --- mach/vax4/cg/table | 1 + 1 file changed, 1 insertion(+) diff --git a/mach/vax4/cg/table b/mach/vax4/cg/table index 7975d2e6..db86f3d9 100644 --- a/mach/vax4/cg/table +++ b/mach/vax4/cg/table @@ -1648,6 +1648,7 @@ adp | NC ADDR_EXTERNAL | | {aextdefind1,%[a],%[1.ind]} | | ... | NC adispl | | {adispl,%[1.reg],%[1.ind]+"+"+tostring($1)} | | ... | reg4 | | {adispl,%[1],tostring($1)} | | +adp sil | | | {CONST4,$1} | adi 4 sil $2 | adp stl | | | {CONST4,$1} | adi 4 stl $2 | adp ste | | | {CONST4,$1} | adi 4 ste $2 | adp dup $2==4 | | | {CONST4,$1} | adi 4 dup 4 | From b0609d40fcc16e0cf8a5b7774a00dd9be90cf9cf Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 10 Feb 1986 10:14:41 +0000 Subject: [PATCH 0109/1625] Added some new patterns involving multiplies with 0, 1 etc. --- util/opt/patterns | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/util/opt/patterns b/util/opt/patterns index 461d3a85..d1c607b2 100644 --- a/util/opt/patterns +++ b/util/opt/patterns @@ -119,6 +119,8 @@ loc sbi $1==-1 && $2==w: inc loc inc sfit($1+1,8*w) : loc $1+1 loc adi $1==0 && $2==w: ldc adi $1==0 && $2==2*w: +loc ads $1==0 && $2==w: +ldc ads $1==0 && $2==2*w: zer adi $1==$2: loc beq $1==0: zeq $2 loc bge $1==0: zge $2 @@ -132,6 +134,10 @@ loc cmi tgt $1==0 && $2==w: tgt loc cmi tle $1==0 && $2==w: tle loc cmi tlt $1==0 && $2==w: tlt loc cmi tne $1==0 && $2==w: tne +loc cmu teq $1==0 && $2==w: teq +loc cmu tne $1==0 && $2==w: tne +loc cmu zeq $1==0 && $2==w: zeq $3 +loc cmu zne $1==0 && $2==w: zne $3 loc ior $1==0 && $2==w: ldc ior $1==0 && $2==2*w: zer ior $1==$2: @@ -148,9 +154,18 @@ loc bge $1==1: zgt $2 loc blt $1==1: zle $2 loc dvi $1==1 && $2==w: ldc dvi $1==1 && $2==2*w: +loc dvu $1==1 && $2==w: +loc dvu $1==1 && $2==2*w: loc loe adi $1==1 && $3==w: loe $2 inc loc lol adi $1==1 && $3==w: lol $2 inc +loc mli $1==0 && $2==w: asp w loc 0 +ldc mli $1==0 && $2==2*w: asp 2*w ldc 0 +loc mlu $1==0 && $2==w: asp w loc 0 +ldc mlu $1==0 && $2==2*w: asp 2*w ldc 0 loc mli $1==1 && $2==w: +ldc mli $1==1 && $2==2*w: +loc mlu $1==1 && $2==w: +ldc mlu $1==1 && $2==2*w: loc sbi $1==1 && $2==w: dec loc loe mli $3==w: loe $2 loc $1 mli w loc lol mli $3==w: lol $2 loc $1 mli w From 233c959d2f65ec3d82cbdc258cb7d1ca4241dc78 Mon Sep 17 00:00:00 2001 From: bal Date: Mon, 10 Feb 1986 11:04:33 +0000 Subject: [PATCH 0110/1625] increased STACK_DEPTH from 50 to 250 --- util/ego/cs/cs_stack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/ego/cs/cs_stack.c b/util/ego/cs/cs_stack.c index 2070dad6..bb2cc302 100644 --- a/util/ego/cs/cs_stack.c +++ b/util/ego/cs/cs_stack.c @@ -8,7 +8,7 @@ #include "cs.h" #include "cs_aux.h" -#define STACK_DEPTH 50 +#define STACK_DEPTH 250 STATIC struct token Stack[STACK_DEPTH]; STATIC token_p free_token; From 17ef693ad4006a387ccb2790b2850aac0dac9e2e Mon Sep 17 00:00:00 2001 From: keie Date: Tue, 11 Feb 1986 11:13:41 +0000 Subject: [PATCH 0111/1625] Too long ago. --- mach/mantra/int/Makefile | 113 +++++++++++++++++++++++++-------------- 1 file changed, 72 insertions(+), 41 deletions(-) diff --git a/mach/mantra/int/Makefile b/mach/mantra/int/Makefile index a46b92ce..bbdb3db0 100644 --- a/mach/mantra/int/Makefile +++ b/mach/mantra/int/Makefile @@ -1,51 +1,82 @@ +INTS=em2_t--- em2_---- em2_t-cp em2_t-c- em2_t--p \ +em4_t--- em4_---- em4_t-cp em4_t-c- em4_t--p P = mloop -em2tl: a.out - cv a.out em2tl - rm a.out -a.out: $P02tl.s $P12tl.s $P22tl.s $P32tl.s $P42tl.s $P52tl.s $P62tl.s $P72tl.s $P82tl.s $P92tl.s $Pa2tl.s $Pb2tl.s $Pc2tl.s $Pe2tl.s - m68k2 -s $P?2tl.s >symem2tl -$P02tl.s: $P0 - prep $P0 $P02tl.s -$P12tl.s: $P1 - prep $P1 $P12tl.s -$P22tl.s: $P2 - prep $P2 $P22tl.s -$P32tl.s: $P3 - prep $P3 $P32tl.s -$P42tl.s: $P4 - prep $P4 $P42tl.s -$P52tl.s: $P5 - prep $P5 $P52tl.s -$P62tl.s: $P6 - prep $P6 $P62tl.s -$P72tl.s: $P7 - prep $P7 $P72tl.s -$P82tl.s: $P8 - prep $P8 $P82tl.s -$P92tl.s: $P9 - prep $P9 $P92tl.s -$Pa2tl.s: $Pa - prep $Pa $Pa2tl.s -$Pb2tl.s: $Pb - prep $Pb $Pb2tl.s -$Pc2tl.s: $Pc - prep $Pc $Pc2tl.s -$Pe2tl.s: $Pe - prep $Pe $Pe2tl.s +FILES=deffile $P0 $P1 $P2 $P3 $P4 $P5 $P6 $P7 $P8 $P9 $Pa $Pb $Pc $Pe +CPP=../../../lib/cpp +b=../../../lib/int -install: em2tl - rm -f ../../../bin/em - cp em2tl ../../../bin/em +all: $(INTS) em -cmp: em2tl - cmp em2tl ../../../bin/em +em: em.c + cc -o em -I../../../h em.c + +em2_t---: $(FILES) + cat $(FILES) | $(CPP) -P -Dopfreq=0 -Dlast=1 -Dcount=0 -Dtest=1 -Dflow=0 -Dprof=0 >tmp.s + m68k2 -o em2_t--- tmp.s + rm -f tmp.s + +em2_----: $(FILES) + cat $(FILES) | $(CPP) -P -Dopfreq=0 -Dlast=0 -Dcount=0 -Dtest=0 -Dflow=0 -Dprof=0 >tmp.s + m68k2 -o em2_---- tmp.s + rm -f tmp.s + +em2_t-cp: $(FILES) + cat $(FILES) | $(CPP) -P -Dopfreq=0 -Dlast=1 -Dcount=1 -Dtest=1 -Dflow=0 -Dprof=1 >tmp.s + m68k2 -o em2_t-cp tmp.s + rm -f tmp.s + +em2_t-c-: $(FILES) + cat $(FILES) | $(CPP) -P -Dopfreq=0 -Dlast=1 -Dcount=1 -Dtest=1 -Dflow=0 -Dprof=0 >tmp.s + m68k2 -o em2_t-c- tmp.s + rm -f tmp.s + +em2_t--p: $(FILES) + cat $(FILES) | $(CPP) -P -Dopfreq=0 -Dlast=1 -Dcount=0 -Dtest=1 -Dflow=0 -Dprof=1 >tmp.s + m68k2 -o em2_t--p tmp.s + rm -f tmp.s + +em4_t---: $(FILES) + cat $(FILES) | $(CPP) -P -Dlword -Dopfreq=0 -Dlast=1 -Dcount=0 -Dtest=1 -Dflow=0 -Dprof=0 >tmp.s + m68k2 -o em4_t--- tmp.s + rm -f tmp.s + +em4_----: $(FILES) + cat $(FILES) | $(CPP) -P -Dlword -Dopfreq=0 -Dlast=0 -Dcount=0 -Dtest=0 -Dflow=0 -Dprof=0 >tmp.s + m68k2 -o em4_---- tmp.s + rm -f tmp.s + +em4_t-cp: $(FILES) + cat $(FILES) | $(CPP) -P -Dlword -Dopfreq=0 -Dlast=1 -Dcount=1 -Dtest=1 -Dflow=0 -Dprof=1 >tmp.s + m68k2 -o em4_t-cp tmp.s + rm -f tmp.s + +em4_t-c-: $(FILES) + cat $(FILES) | $(CPP) -P -Dlword -Dopfreq=0 -Dlast=1 -Dcount=1 -Dtest=1 -Dflow=0 -Dprof=0 >tmp.s + m68k2 -o em4_t-c- tmp.s + rm -f tmp.s + +em4_t--p: $(FILES) + cat $(FILES) | $(CPP) -P -Dlword -Dopfreq=0 -Dlast=1 -Dcount=0 -Dtest=1 -Dflow=0 -Dprof=1 >tmp.s + m68k2 -o em4_t--p tmp.s + rm -f tmp.s + +install: all + -mkdir $b24 $b44 + ls em2_???? | sed 's:em2_\(.*\):cp & $b24/em_\1:' | sh + ls em4_???? | sed 's:em4_\(.*\):cp & $b44/em_\1:' | sh + cp em ../../../bin/em + +cmp: all + ls em2_???? | sed 's:em2_\(.*\):cmp & $b24/em_\1:' | sh + ls em4_???? | sed 's:em4_\(.*\):cmp & $b44/em_\1:' | sh + cmp em ../../../bin/em clean: - rm -f em2tl *.s temp.c + -rm -f *.o *.old a.out em tmp.s $(INTS) opr: make pr | opr pr: - @pr `pwd`/makefile `pwd`/prep - @pr `pwd`/header `pwd/deffile `pwd`/$P? + @pr `pwd`/makefile + @pr `pwd`/deffile `pwd`/$P? From dcfc21ba60fcaa80d4783c5fddea1fac4156a692 Mon Sep 17 00:00:00 2001 From: keie Date: Tue, 11 Feb 1986 11:14:11 +0000 Subject: [PATCH 0112/1625] *** empty log message *** --- mach/ns/Action | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mach/ns/Action b/mach/ns/Action index ba12d9fe..34520181 100644 --- a/mach/ns/Action +++ b/mach/ns/Action @@ -1,3 +1,18 @@ name "NS16032 assembler" dir as end +name "NS16032 backend" +dir cg +end +name "NS16032 EM library" +dir libem +end +name "NS16032 system call library" +dir libsys +end +name "NS16032 C libraries" +dir libcc +end +name "NS16032 Basic libraries" +dir libbc +end From 9c262a326644cf78d494930978cdec2033924538 Mon Sep 17 00:00:00 2001 From: keie Date: Tue, 11 Feb 1986 11:15:19 +0000 Subject: [PATCH 0113/1625] Ack is using good old cpp again. --- mach/em22/libcc/compmodule | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/em22/libcc/compmodule b/mach/em22/libcc/compmodule index 671dce6d..330b4aef 100755 --- a/mach/em22/libcc/compmodule +++ b/mach/em22/libcc/compmodule @@ -1,2 +1,2 @@ -${MACH?} -Rcpp=/lib/cpp -I/usr/em/h ${MACHFL?} -LIB $1 1>&2 +${MACH?} -I../../../h ${MACHFL?} -LIB $1 1>&2 echo `basename $1 $2`.m From 5113e35bb9626a8e7beede59c0b6415eb350047e Mon Sep 17 00:00:00 2001 From: keie Date: Tue, 11 Feb 1986 11:18:57 +0000 Subject: [PATCH 0114/1625] Added a warning message. --- lang/basic/src.old/basic.yacc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lang/basic/src.old/basic.yacc b/lang/basic/src.old/basic.yacc index 14eb16d6..091956bc 100644 --- a/lang/basic/src.old/basic.yacc +++ b/lang/basic/src.old/basic.yacc @@ -440,7 +440,8 @@ factor : INTVALUE {$$=loadint(ival);} | funcname { $$=fcnend(0);} | funcname funccall ')' { $$=fcnend($2);} | MIDSYM '$' midparms - { emcode("cal","$_mid"); + { warning("Unsupported function call"); + emcode("cal","$_mid"); emcode("asp",EMINTSIZE); emcode("asp",EMINTSIZE); emcode("asp",EMPTRSIZE); From d764fef59622079f715c7e248939c1ab5513a8fe Mon Sep 17 00:00:00 2001 From: keie Date: Tue, 11 Feb 1986 11:22:43 +0000 Subject: [PATCH 0115/1625] Adapted to our ack environment. --- util/amisc/Makefile | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/util/amisc/Makefile b/util/amisc/Makefile index 3cf60e34..2d72e5cc 100644 --- a/util/amisc/Makefile +++ b/util/amisc/Makefile @@ -1,19 +1,33 @@ # @(#)Makefile 1.1 EM = ../.. +BINDIR = $(EM)/bin h = $(EM)/h CFLAGS = -n -O -I$h -ALL = anm asize astrip -OFILES = anm.o asize.o astrip.o -CFILES = anm.c asize.c astrip.c +ALL = anm asize astrip aal +OFILES = anm.o asize.o astrip.o aal.o +CFILES = anm.c asize.c astrip.c aal.c all: $(ALL) -cp cmp: all - for i in $(ALL); do $@ $$i $$ROOT/usr/bin/$$i; done +anm: anm.c + $(CC) $(CFLAGS) -o anm anm.c +asize: asize.c + $(CC) $(CFLAGS) -o asize asize.c +astrip: astrip.c + $(CC) $(CFLAGS) -o astrip astrip.c +aal: aal.c + $(CC) $(CFLAGS) -DAUTORAN -o aal aal.c + +install: all + for i in $(ALL); do cp $$i $(BINDIR)/$$i; done + +cmp: all + for i in $(ALL); do cmp $$i $(BINDIR)/$$i; done clean: ; rm -f $(ALL) $(OFILES) -get: ; getall -unget: ; ungetall -print: $(CFILES) - pr -n Makefile $(CFILES) | lpr +pr: $(CFILES) + @pr -n Makefile $(CFILES) + +opr: + make pr | opr From c727e9b50289b07bda6959c54c4719fcd13716e7 Mon Sep 17 00:00:00 2001 From: dick Date: Thu, 27 Feb 1986 14:57:35 +0000 Subject: [PATCH 0116/1625] entry clean added --- doc/em/Makefile | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/doc/em/Makefile b/doc/em/Makefile index b9dee4cb..670d993d 100644 --- a/doc/em/Makefile +++ b/doc/em/Makefile @@ -17,18 +17,14 @@ opr: doc.pr make pr | opr pr: - @make "NROFF="$NROFF doc.pr >makepr.out 2>&1 + @make "NROFF="$(NROFF) TBL=$(TBL) doc.pr >makepr.out 2>&1 @cat doc.pr -app.t: itables em.i - -em.i: int/em.p - @echo Sorry, this copy was edited by hand from int/em.p - itables: $(IOP) ip.awk - awk -f ip.awk $(IOP) | sed 's/-/\\-/g" | $(TBL) >itables + awk -f ip.awk $(IOP) | sed 's/-/\\-/g' | $(TBL) >itables .SUFFIXES : .pr .nr .nr.pr: ; $(TBL) macr.nr $*.nr | $(NROFF) >$@ -cont.t intro.t mem.t ispace.t dspace.t mapping.t succ.t descr.t iotrap.t mach.t assem.t kern.t app.t: macr.nr +clean: + rm -f doc.pr itables From 2d7b3443bc782082e6a980347b447fafa54db347 Mon Sep 17 00:00:00 2001 From: dick Date: Fri, 28 Feb 1986 17:46:09 +0000 Subject: [PATCH 0117/1625] small adjustments --- doc/em/READ_ME | 4 +++- doc/em/assem.nr | 30 +++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/doc/em/READ_ME b/doc/em/READ_ME index 23001bcf..d41e5c97 100644 --- a/doc/em/READ_ME +++ b/doc/em/READ_ME @@ -1,5 +1,7 @@ This it the text of IR-81, -DESCRIPTION OF A MACHINE ARCHITECTURE FOR USE WITH BLOCK STRUCTURED LANGUAGES +DESCRIPTION OF A MACHINE ARCHITECTURE FOR USE WITH BLOCK STRUCTURED LANGUAGES + +The file em.i (text of the defining interpreter) was hand-edited from int/em.p To print, set NROFF and TBL in the Makefile and call make. It uses the kun macro package which is also distributed. diff --git a/doc/em/assem.nr b/doc/em/assem.nr index a22443f3..38b46fa6 100644 --- a/doc/em/assem.nr +++ b/doc/em/assem.nr @@ -588,7 +588,7 @@ Instructions that check for undefined integer or floating-point values and underflow or overflow are indicated below by (*). .N 1 -.DS B +.DS .ta 12n GROUP 1 \- LOAD @@ -608,7 +608,9 @@ GROUP 1 \- LOAD LDE \*g : Load double external (two consecutive externals are stacked) LDF \*f : Load double offsetted (top of stack + \*f yield address) LPI \*p : Load procedure identifier +.DE +.DS GROUP 2 \- STORE STL \*l : Store local or parameter @@ -620,7 +622,9 @@ GROUP 2 \- STORE SDL \*l : Store double local or parameter SDE \*g : Store double external SDF \*f : Store double offsetted +.DE +.DS GROUP 3 \- INTEGER ARITHMETIC ADI \*w : Addition (*) @@ -631,7 +635,9 @@ GROUP 3 \- INTEGER ARITHMETIC NGI \*w : Negate (two's complement) (*) SLI \*w : Shift left (*) SRI \*w : Shift right (*) +.DE +.DS GROUP 4 \- UNSIGNED ARITHMETIC ADU \*w : Addition @@ -641,7 +647,9 @@ GROUP 4 \- UNSIGNED ARITHMETIC RMU \*w : Remainder SLU \*w : Shift left SRU \*w : Shift right +.DE +.DS GROUP 5 \- FLOATING POINT ARITHMETIC ADF \*w : Floating add (*) @@ -651,13 +659,17 @@ GROUP 5 \- FLOATING POINT ARITHMETIC NGF \*w : Floating negate (*) FIF \*w : Floating multiply and split integer and fraction part (*) FEF \*w : Split floating number in exponent and fraction part (*) +.DE +.DS GROUP 6 \- POINTER ARITHMETIC ADP \*f : Add \*f to pointer on top of stack ADS \*w : Add \*w-byte value and pointer SBS \*w : Subtract pointers in same fragment and push diff as size \*w integer +.DE +.DS GROUP 7 \- INCREMENT/DECREMENT/ZERO INC \*- : Increment word on top of stack by 1 (*) @@ -670,7 +682,9 @@ GROUP 7 \- INCREMENT/DECREMENT/ZERO ZRE \*g : Zero external ZRF \*w : Load a floating zero of size \*w ZER \*w : Load \*w zero bytes +.DE +.DS \" ??? GROUP 8 \- CONVERT (stack: source, source size, dest. size (top)) CII \*- : Convert integer to integer (*) @@ -682,7 +696,9 @@ GROUP 8 \- CONVERT (stack: source, source size, dest. size (top)) CIU \*- : Convert integer to unsigned CUU \*- : Convert unsigned to unsigned CFU \*- : Convert floating to unsigned +.DE +.DS GROUP 9 \- LOGICAL AND \*w : Boolean and on two groups of \*w bytes @@ -691,18 +707,24 @@ GROUP 9 \- LOGICAL COM \*w : Complement (one's complement of top \*w bytes) ROL \*w : Rotate left a group of \*w bytes ROR \*w : Rotate right a group of \*w bytes +.DE +.DS GROUP 10 \- SETS INN \*w : Bit test on \*w byte set (bit number on top of stack) SET \*w : Create singleton \*w byte set with bit n on (n is top of stack) +.DE +.DS GROUP 11 \- ARRAY LAR \*w : Load array element, descriptor contains integers of size \*w SAR \*w : Store array element AAR \*w : Load address of array element +.DE +.DS GROUP 12 \- COMPARE CMI \*w : Compare \*w byte integers, Push negative, zero, positive for <, = or > @@ -717,7 +739,9 @@ GROUP 12 \- COMPARE TNE \*- : True if not equal, i.e. iff top of stack non zero TGE \*- : True if greater or equal, i.e. iff top of stack >= 0 TGT \*- : True if greater, i.e. iff top of stack > 0 +.DE +.DS \" ??? GROUP 13 \- BRANCH BRA \*b : Branch unconditionally to label \*b @@ -735,14 +759,18 @@ GROUP 13 \- BRANCH ZNE \*b : Branch not zero ZGE \*b : Branch greater or equal zero ZGT \*b : Branch greater than zero +.DE +.DS GROUP 14 \- PROCEDURE CALL CAI \*- : Call procedure (procedure identifier on stack) CAL \*p : Call procedure (with identifier \*p) LFR \*s : Load function result RET \*z : Return (function result consists of top \*z bytes) +.DE +.DS GROUP 15 \- MISCELLANEOUS ASP \*f : Adjust the stack pointer by \*f From c4936bbd48c782bacbdfdf508054eb7ae8186d01 Mon Sep 17 00:00:00 2001 From: dick Date: Fri, 28 Feb 1986 18:02:00 +0000 Subject: [PATCH 0118/1625] adapting to phototypesetter --- doc/6500.doc | 284 ++---------------------------------------------- doc/Makefile | 30 +++-- doc/ack.doc | 212 ++++++++++++++++++------------------ doc/cg.doc | 6 + doc/cref.doc | 1 - doc/i80.doc | 2 + doc/install.doc | 53 ++++----- doc/pcref.doc | 4 +- doc/toolkit.doc | 3 +- doc/val.doc | 2 +- doc/z80.doc | 70 +++++++----- 11 files changed, 213 insertions(+), 454 deletions(-) diff --git a/doc/6500.doc b/doc/6500.doc index aeef24a9..cdbcb990 100644 --- a/doc/6500.doc +++ b/doc/6500.doc @@ -1,6 +1,6 @@ . \" $Header$" -.po +10 -.ND +.RP +.ND Dec 1984 .TL .B A backend table for the 6500 microprocessor @@ -12,212 +12,6 @@ The backend table is part of the Amsterdam Compiler Kit (ACK). It translates the intermediate language family EM to a machine code for the MCS6500 microprocessor family. .AE -.PP -.bp -.NH -Introduction. -.PP -As more and more organizations aquire many micro and minicomputers, -the need for portable compilers is becoming more and more acute. -The present situation, in which each harware vendor provides its -own compilers -- each with its own deficiencies and extensions, and -none of them compatible -- leaves much to be desired. -The ideal situation would be an integrated system containing -a family of (cross) compilers, each compiler accepting a standard -source language and, producing code for a wide variety of target -machines. Furthermore, the compilers should be compatible, so programs -written in one language can call procedures written in another -language. Finally, the system should be designed so as to make -adding new languages and, new machines easy. Such an integerated -system is being built at the Vrije Universiteit. -.PP -The compiler building system, which is called the "Amsterdam Compiler -Kit" (ACK), can be thought of as a "tool kit." It consists of -a number of parts that can be combined to form compilers (and -interpreters) with various properties. The tool kit is based -on an idea (UNCOL) that was first suggested in 1960 [5], -but which never really caught on then. The problem which UNCOL -attemps to solve is how to make a compiler for each of -.B -N -.R -languages on -.B -M -.R -different machines without having to write -.B -N -.R -x -.B -M -.R -programs. -.PP -As shown in Fig. 1, the UNCOL approach is to write -.B -N -.R -"front ends," each of which translates -one source language to a common -intermediate language, UNCOL (UNiversal Computer Oriented -Language), and -.B -M -.R -"back ends," each of which translates programs -in UNCOL to a specific machine language. Under these conditions, -only -.B -N -.R -+ -.B -M -.R -programs must be written to provide all -.B -N -.R -languages on all -.B -M -.R -machines, instead of -.B -N -.R -x -.B -M -.R -programs. -.PP -Various reseachers have attempted to design a suitable UNCOL [1,6], -but none of these have become popular. It is the believe of the -designers of the Amsterdam Compiler Kit that previous attemps -have failed because they have been too ambitious, that is, they have -tried to cover all languages and all machines using a single UNCOL. -The approach of the designers is more modest: -they cater only to algebraic languages and machines whose memory -consist of 8-bit bytes, each with its own address. -Typical languages that could be handled include Ada, ALGOL 60, -ALGOL 68, BASIC, C, FORTRAN, Modula, Pascal, PL/I, PL/M, PLAIN and -RATFOR, where COBOL, LISP and SNOBOL would be less efficient. -Examples of machines that could be included are the Intel 8080 and -8086, Motorola 6800, 6809 and 68000, Zilog Z80 and Z8000, DEC PDP-11 -and Vax, MOS Technology MCS6500 family and IBM but not the Burroughs -6700, CDC Cyber or Univac 1108 (because they are not byte_oriented). -With these restrictions the designers believe that the old UNCOL -idea can be used as the basis of a practical compiler-building -system. -.sp 10 -.bp -.NH -An overview of the Amsterdam Compiler kit -.PP -The tool kit consists of eight components: -.IP 1. -The preprocessor. -.IP 2. -The front ends. -.IP 3. -The peephole optimizer. -.IP 4. -The global optimizer. -.IP 5. -The back end. -.IP 6. -The target machine optimizer. -.IP 7. -The universal assembler/linker. -.IP 8. -The utility package. -.PP -A fully optimizing compiler, depicted in Fig. 2, has seven cascaded -phases. Conceptually, each component reads an input file and writes -a transformed output file to be used as input to the next component. -In practice, some components may use temporary files to allow -multiple passes over the input or internal intermediate files. -.sp 20 -.PP -In the following paragraphs a brief decription of each component -is given. -A more detailed description of the back end will be given in the -rest of this document. For a more detailed descripiton on the rest -of the components see [7]. A program to be compiled is first fed -into the (language independed) preprocessor, which provides a -simple macro facility and similar textual facilities. -The preprocessor's ouput is a legal program in one of the programming -languages supported, whereas the input is a program possibly -augmented with macro's, etc. -.PP -This output goes into the appropriate front end, whose job it is to -produce intermediate cade. -This intermediate code (the UNCOL of ACK) is the machine language -for a simple stack machine EM (Encoding Machine). -A typical front end might build a parse tree from the input -and then use the parse tree to generate EM cade, -which is similar to reverse Polish. -In order to perform this work, the front end has to maintain tables of declare -tables of declared variables, labels, etc., determine where -to place the data structures in memory and so on. -.PP -The EM code generated by the front end is fed into the peephole -optimizer, which scans it with a window of a view instructions, -replacing certain inefficient code sequences by better ones. -Such a search is important because EM contains instructions to -handle numerous important special cases efficiently -(e.g. incrementing a variable by 1). -It is our strategy to relieve the front ends of the burden -of hunting for special cases because there are many front ends -and just one peephole optimizer. -By handeling the special cases in the peephole optimizer, -the front ends become simpler, easier to write and easier to maintain. -.PP -Following the peephole optimizer is a global optimizer [2], -which unlike the peephole optimizer, examines the program as a whole. -It builts a data flow graph to make possible a variety of global -optimizations, among them, moving invariant code out of loops, -avoiding redundant computations, live/dead analysis and -eliminating tail recursion. -Note that the output of the global optimizer is still EM code. -.PP -Next comes the back end, which differs from the front ends in a -fundamental way. -Each front end is a separate program, whereas the back end is a -single program that is driven by a machine dependent driving table. -The driving table for a specific machine tells how EM code is -mapped onto the machine's assembly language. -Although a simple driving table just might macro expand each -EM instruction into a sequence of target machine instructions, -a much more sophisticated translation strategy is normaly used, -as described later. -For speech, the back end does not actually read in the driving -table at run time. -Instead, the tables are compiled along with the back end in advance, -resulting in one binairy program per machine. -.PP -The output of the back end is a program in the assembly language -of some particular machine. -The next component in the pipeline reads this program and performs -peephole optimization on it. -The optimizations performed here involve idiosyncrasies of the -target machine that cannot be performed by the machine-independent -EM-to-EM peephole optimizer. -Typically these optimizations take advantage of the special -instructions or special addressing modes. -.PP -The optimized target machine assembly code then goes into the final -component in the pipeline, the universal assembler/linker. -This program assembles the input to object format, extracting -routines from libraries and including them as needed. -.PP -The final component of the tool kit is the utility package, -which contains various test programs, interpreters for EM code, -EM libraries, conversion programs and other aids for the -implementer and user. .bp .DS C .B @@ -264,7 +58,7 @@ manufactured by Acorn Computer Ltd.. The MOS Technology MCS6500 .PP The MCS6500 is as a family of CPU devices developed by MOS -Technology. +Technology [1]. The members of the MCS6500 family are the same chips in a different housing. The MCS6502, the big brother in the family, can handle 64k @@ -861,7 +655,7 @@ The above description of the machine table is a description of the table for the MCS6500. It uses only a part of the possibilities which the code generator generator offers. -For a more precise and detailed description see [4]. +For a more precise and detailed description see [2]. .DS C .B THE BACK END TABLE. @@ -1141,7 +935,7 @@ This subroutine expects the multiplicand in zero page at locations ARTH, ARTH+1, while the multiplier is in zero page locations ARTH+2, ARTH+3. For a description of the algorithms used for multiplication and -division, see [9]. +division, see [3]. A table content is: .sp 1 .br @@ -2071,34 +1865,6 @@ if it is to be used on a MCS6500. REFERENCES. .R .IP 1. -Haddon. B.K., and Waite, W.M. -Experience with the Universal Intermediate Language Janus. -.B -Software Practice & Experience 8 -.R -, -5 (Sept.-Oct. 1978), 601-616. -.RS -.PP -An intermediate language for use with Algol 68, Pascal, etc. -is described. -The paper discusses some problems encountered and how they were -dealt with. -.RE -.IP 2. -Lowry, E.S., and Medlock, C.W. Object Code Optimization. -.B -Commun. ACM 12 -.R -, -(Jan. 1969), 13-22. -.RS -.PP -A classical paper on global object code optimization. -It covers data flow analysis, common subexpressions, code motion, -register allocation and other techniques. -.RE -.IP 3. Osborn, A., Jacobson, S., and Kane, J. The Mos Technology MCS6500. .B An Introduction to Microcomputers , @@ -2109,7 +1875,7 @@ Volume II, Some Real Products (june 1977) chap. 9. A hardware description of some real existing CPU's, such as the Intel Z80, MCS6500, etc. is given in this book. .RE -.IP 4. +.IP 2. van Staveren, H. The table driven code generator from the Amsterdam Compiler Kit. Vrije Universiteit, Amsterdam, (July 11, 1983). @@ -2117,43 +1883,7 @@ Vrije Universiteit, Amsterdam, (July 11, 1983). .PP The defining document for writing a back end table. .RE -.IP 5. -Steel, T.B., Jr. UNCOL: The Myth and the Fact. in -.B -Ann. Rev. Auto. Prog. -.R -Goodman, R. (ed.), vol 2., (1960), 325-344. -.RS -.PP -An introduction to the UNCOL idea by its originator. -.RE -.IP 6. -Steel. T.B., Jr. A first Version of UNCOL. -.B -Proc. Western Joint Comp. Conf. -.R -, -(1961), 371-377. -.IP 7. -Tanenbaum, A.S., Stevenson, J.W., Keizer, E.G., and van Staveren, -H. -A Practical Tool Kit for Making Portable Compilers. -Informatica Rapport 74, Vrije Universiteit, Amsterdam, 1983. -.RS -.PP -An overview on the Amsterdam Compiler Kit. -.RE -.IP 8. -Tanenbaum, A.S., Stevenson, J.W., Keizer, E.G., and van Staveren, -H. -Description of an Experimental Machine Architecture for use with -Block Structured Languages. -Informatica Rapport 81, Vrije Universiteit, Amsterdam, 1983. -.RS -.PP -The defining document for EM. -.RE -.IP 9. +.IP 3. Tanenbaum, A.S. Structured Computer Organization. Prentice Hall. (1976). .RS diff --git a/doc/Makefile b/doc/Makefile index 67da867c..1c2d9992 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -2,14 +2,19 @@ SUF=pr PRINT=cat -RESFILES=cref.$(SUF) pcref.$(SUF) val.$(SUF) v7bugs.$(SUF) install.$(SUF)\ -ack.$(SUF) cg.$(SUF) regadd.$(SUF) peep.$(SUF) toolkit.$(SUF) LLgen.$(SUF)\ -basic.$(SUF) 6500.$(SUF) ncg.$(SUF) i80.$(SUF) NROFF=nroff +TBL=tbl +EQN=eqn MS=-ms +RESFILES= \ + toolkit.$(SUF) install.$(SUF) ack.$(SUF) v7bugs.$(SUF) \ + peep.$(SUF) cg.$(SUF) ncg.$(SUF) regadd.$(SUF) LLgen.$(SUF) \ + basic.$(SUF) cref.$(SUF) pcref.$(SUF) val.$(SUF) \ + 6500.$(SUF) i80.$(SUF) z80.$(SUF) + cref.$(SUF): cref.doc - tbl $? | $(NROFF) >$@ + $(TBL) $? | $(NROFF) >$@ v7bugs.$(SUF): v7bugs.doc $(NROFF) $(MS) $? >$@ ack.$(SUF): ack.doc @@ -17,11 +22,11 @@ ack.$(SUF): ack.doc cg.$(SUF): cg.doc $(NROFF) $(MS) $? >$@ ncg.$(SUF): ncg.doc - tbl $? | $(NROFF) $(MS) >$@ + $(TBL) $? | $(NROFF) $(MS) >$@ regadd.$(SUF): regadd.doc $(NROFF) $(MS) $? >$@ install.$(SUF): install.doc - $(NROFF) $(MS) $? >$@ + $(TBL) $? | $(NROFF) $(MS) >$@ pcref.$(SUF): pcref.doc $(NROFF) $? >$@ basic.$(SUF): basic.doc @@ -33,23 +38,26 @@ val.$(SUF): val.doc toolkit.$(SUF): toolkit.doc $(NROFF) $(MS) $? >$@ LLgen.$(SUF): LLgen.doc - eqn $? | tbl | $(NROFF) $(MS) >$@ + $(EQN) $? | $(TBL) | $(NROFF) $(MS) >$@ 6500.$(SUF): 6500.doc - $(NROFF) $(MS) $? >$@ + $(TBL) $? | $(NROFF) $(MS) >$@ i80.$(SUF): i80.doc $(NROFF) $(MS) $? >$@ +z80.$(SUF): z80.doc + $(NROFF) $(MS) $? >$@ install cmp: distr: install.doc tbl install.doc | nroff -Tlp $(MS) >install.pr + pr: - @make "SUF="$SUF "NROFF="$NROFF "PRINT="$PRINT $(RESFILES) \ - >make.pr.out 2>&1 + @make "SUF="$(SUF) "NROFF="$(NROFF) \ + $(RESFILES) >make.pr.out 2>&1 @$(PRINT) $(RESFILES) opr: make pr | opr clean: - -rm -f *.old $(RESFILES) *.t + -rm -f *.old $(RESFILES) *.t *.out diff --git a/doc/ack.doc b/doc/ack.doc index 3067ac96..3812d088 100644 --- a/doc/ack.doc +++ b/doc/ack.doc @@ -1,7 +1,6 @@ .\" $Header$ -.nr LL 7.5i -.tr ~ .nr PD 1v +.tr ~ .TL Ack Description File .br @@ -9,7 +8,7 @@ Reference Manual .AU Ed Keizer .AI -Wiskundig Seminarium +Vakgroep Informatica Vrije Universiteit Amsterdam .NH @@ -24,16 +23,16 @@ source file. Each transformation table entry tells which input suffixes are allowed and what suffix/name the output file has. When the output file does not already satisfy the request of the -user, with the flag \fB-c.suffix\fP, the table is scanned +user, with the flag \fB\-c.suffix\fP, the table is scanned starting with the next transformation in the table for another transformation that has as input suffix the output suffix of the previous transformation. A few special transformations are recognized, among them is the combiner. A program combining several files into one. -When no stop suffix was specified (flag \fB-c.suffix\fP) \fIack\fP -stops after executing the combiner with as arguments the - -possibly transformed - input files and libraries. +When no stop suffix was specified (flag \fB\-c.suffix\fP) \fIack\fP +stops after executing the combiner with as arguments the \- +possibly transformed \- input files and libraries. \fIAck\fP will only perform the transformations in the order in which they are presented in the table. .LP @@ -60,7 +59,7 @@ convoluted. First, when the last filename in the program call name is not one of \fIack\fP, \fIcc\fP, \fIacc\fP, \fIpc\fP or \fIapc\fP, this filename is used as the backend description name. -Second, when the \fB-m\fP is present the \fB-m\fP is chopped of this +Second, when the \fB\-m\fP is present the \fB\-m\fP is chopped of this flag and the rest is used as the backend description name. Third, when both failed the shell environment variable ACKM is used. @@ -119,8 +118,8 @@ Syntax: (\fIsuffix sequence\fP:\fIsuffix sequence\fP=\fItext\fP) .br Example: (.c.p.e:.e=tail_em) .br -If the two suffix sequences have a common member -~\&.e in this -case~- the text is produced. +If the two suffix sequences have a common member \-~\&.e in this +case~\- the text is produced. When no common member is present the empty string is produced. Thus the example given is a constant expression. Normally, one of the suffix sequences is produced by variable @@ -134,17 +133,17 @@ the text following the \fIneed\fP is appended to both the HEAD and TAIL variable. The value of the variable RTS is determined by the first transformation used with a \fIrts\fP property. -.LP +.IP Two runtime flags have effect on the value of one or more of these variables. -The flag \fB-.suffix\fP has the same effect on these three variables +The flag \fB\-.suffix\fP has the same effect on these three variables as if a file with that \fBsuffix\fP was included in the argument list and had to be translated. -The flag \fB-r.suffix\fP only has that effect on the TAIL +The flag \fB\-r.suffix\fP only has that effect on the TAIL variable. The program call names \fIacc\fP and \fIcc\fP have the effect -of an automatic \fB-.c\fB flag. -\fIApc\fP and \fIpc\fP have the effect of an automatic \fB-.p\fP flag. +of an automatic \fB\-.c\fP flag. +\fIApc\fP and \fIpc\fP have the effect of an automatic \fB\-.p\fP flag. .IP "Line splitting" .br The string is transformed into a sequence of strings by replacing @@ -168,7 +167,7 @@ of the line. Three special two-characters sequences exist: \e#, \e\e and \e. Their effect is described under 'backslashing' above. -Each - nonempty - line starts with a keyword, possibly +Each \- nonempty \- line starts with a keyword, possibly preceded by blank space. The keyword can be followed by a further specification. The two are separated by blank space. @@ -193,7 +192,7 @@ The lines in between associate properties to a transformation and may be presented in any order. The identifier after the \fIname\fP keyword determines the name of the transformation. -This name is used for debugging and by the \fB-R\fP flag. +This name is used for debugging and by the \fB\-R\fP flag. The keywords are used to specify which input suffices are recognized by that transformation, the program to run, the arguments to be handed to that program @@ -212,7 +211,7 @@ keyword. All other transformations do. .IP \fIto\fP .br followed by the suffix of the output file name or in the case of a -linker -~indicated by C option after the \fIprop\fP keyword~- +linker \-~indicated by C option after the \fIprop\fP keyword~\- the output file name. .IP \fIprogram\fP .br @@ -235,9 +234,9 @@ assignment separated by blank space. As soon as both description files are read, \fIack\fP looks at all transformations in these files to find a match for the flags given to \fIack\fP. -The flags \fB-m\fP, \fB-o\fP, -\fI-O\fP, \fB-r\fP, \fB-v\fP, \fB-g\fP, -\fB-c\fP, \fB-t\fP, -\fB-k\fP, \fB-R\fP and -\f-.\fP are specific to \fIack\fP and +The flags \fB\-m\fP, \fB\-o\fP, +\fB\-O\fP, \fB\-r\fP, \fB\-v\fP, \fB\-g\fP, \-\fB\-c\fP, \fB\-t\fP, +\fB\-k\fP, \fB\-R\fP and \-\fB\-.\fP are specific to \fIack\fP and not handed down to any transformation. The matching is performed in the order in which the entries appear in the definition. @@ -249,11 +248,11 @@ replaced by the characters matched by the * in the expression. The right hand part is also subject to variable replacement. The variable will probably be used in the program arguments. -The \fB-l\fP flags are special, +The \fB\-l\fP flags are special, the order in which they are presented to \fIack\fP must be preserved. The identifier LNAME is used in conjunction with the scanning of -\fB-l\fP flags. +\fB\-l\fP flags. The value assigned to LNAME is used to replace the flag. The example further on shows the use all this. .IP \fIargs\fP @@ -261,13 +260,13 @@ The example further on shows the use all this. The keyword is followed by the program call arguments. It is subject to backslashing, variable replacement, expression replacement, line splitting and IO replacement. -The variables assigned to by \fImapflags\P will probably be +The variables assigned to by \fImapflags\fP will probably be used here. The flags not recognized by \fIack\fP or any of the transformations are passed to the linker and inserted before all other arguments. -.IP \fIprop\fB +.IP \fIprop\fP .br -This -~optional~- keyword is followed by a sequence of options, +This \-~optional~\- keyword is followed by a sequence of options, each option is indicated by one character signifying a special property of the transformation. The possible options are: @@ -282,18 +281,18 @@ The possible options are: .DE .IP \fIrts\fP .br -This -~optional~- keyword indicates that the rest of the line must be +This \-~optional~\- keyword indicates that the rest of the line must be used to set the variable RTS, if it was not already set. Thus the variable RTS is set by the first transformation executed which such a property or as a result from \fIack\fP's program -call name (acc, cc, apc or pc) or by the \fB-.suffix\fP flag. +call name (acc, cc, apc or pc) or by the \fB\-.suffix\fP flag. .IP \fIneed\fP .br -This -~optional~- keyword indicates that the rest of the line must be +This \-~optional~\- keyword indicates that the rest of the line must be concatenated to the NEEDS variable. This is done once for every transformation used or indicated by one of the program call names mentioned above or indicated -by the \fB-.suffix\fP flag. +by the \fB\-.suffix\fP flag. .br .nr PD 1v .NH @@ -302,7 +301,7 @@ Conventions used in description files \fIAck\fP reads two description files. A few of the variables defined in the machine specific file are used by the descriptions of the front-ends. -Other variables, set by \fack\fB, are of use to all +Other variables, set by \fIack\fP, are of use to all transformations. .PP \fIAck\fP sets the variable EM to the home directory of the @@ -312,7 +311,7 @@ being massaged, this is usefull for debugging. .br The variable M indicates the directory in mach/{M}/lib/tail_..... and NAME is the string to -be defined by the preprocessor with -D{NAME}. +be defined by the preprocessor with \-D{NAME}. The definitions of {w}, {s}, {l}, {d}, {f} and {p} indicate EM_WSIZE, EM_SSIZE, EM_LSIZE, EM_DSIZE, EM_FSIZE and EM_PSIZE respectively. @@ -330,91 +329,94 @@ The variables HEAD, TAIL and RTS are set by \fIack\fP and used to compose the arguments for the linker. .NH Example -.sp 1 -description for front-end +.PP +Description for front-end .DS X -name cpp # the C-preprocessor - # no from, it's governed by the P property - to .i # result files have suffix i - program {EM}/lib/cpp # pathname of loadfile - mapflag -I* CPP_F={CPP_F?} -I* # grab -I.. -U.. and - mapflag -U* CPP_F={CPP_F?} -U* # -D.. to use as arguments - mapflag -D* CPP_F={CPP_F?} -D* # in the variable CPP_F - args {CPP_F?} {INCLUDES?} -D{NAME} -DEM_WSIZE={w} -DEM_PSIZE={p} \ --DEM_SSIZE={s} -DEM_LSIZE={l} -DEM_FSIZE={f} -DEM_DSIZE={d} < - # The arguments are: first the -[IUD]... - # then the include dir's for this machine - # then the NAME and size valeus finally - # followed by the input file name - prop >P # Output on stdout, is preprocessor +.ta 4n 40n +name cpp # the C-preprocessor + # no from, it's governed by the P property + to .i # result files have suffix i + program {EM}/lib/cpp # pathname of loadfile + mapflag \-I* CPP_F={CPP_F?} \-I* # grab \-I.. \-U.. and + mapflag \-U* CPP_F={CPP_F?} \-U* # \-D.. to use as arguments + mapflag \-D* CPP_F={CPP_F?} \-D* # in the variable CPP_F + args {CPP_F?} {INCLUDES?} \-D{NAME} \-DEM_WSIZE={w} \-DEM_PSIZE={p} \e + \-DEM_SSIZE={s} \-DEM_LSIZE={l} \-DEM_FSIZE={f} \-DEM_DSIZE={d} < + # The arguments are: first the \-[IUD]... + # then the include dir's for this machine + # then the NAME and size valeus finally + # followed by the input file name + prop >P # Output on stdout, is preprocessor end -name cem # the C-compiler proper - from .c # used for files with suffix .c - to .k # produces compact code files - program {EM}/lib/em_cem # pathname of loadfile - mapflag -p CEM_F={CEM_F?} -Xp # pass -p as -Xp to cem - mapflag -L CEM_F={CEM_F?} -l # pass -L as -l to cem - args -Vw{w}i{w}p{p}f{f}s{s}l{l}d{d} {CEM_F?} - # the arguments are the object sizes in - # the -V... flag and possibly -l and -Xp - prop <>p # input on stdin, output on stdout, use cpp - rts .c # use the C run-time system - need .c # use the C libraries +name cem # the C-compiler proper + from .c # used for files with suffix .c + to .k # produces compact code files + program {EM}/lib/em_cem # pathname of loadfile + mapflag \-p CEM_F={CEM_F?} \-Xp # pass \-p as \-Xp to cem + mapflag \-L CEM_F={CEM_F?} \-l # pass \-L as \-l to cem + args \-Vw{w}i{w}p{p}f{f}s{s}l{l}d{d} {CEM_F?} + # the arguments are the object sizes in + # the \-V... flag and possibly \-l and \-Xp + prop <>p # input on stdin, output on stdout, use cpp + rts .c # use the C run-time system + need .c # use the C libraries end -name decode # make human readable files from compact code - from .k.m # accept files with suffix .k or .m - to .e # produce .e files - program {EM}/lib/em_decode # pathname of loadfile - args < # the input file name is the only argument - prop > # the output comes on stdout +name decode # make human readable files from compact code + from .k.m # accept files with suffix .k or .m + to .e # produce .e files + program {EM}/lib/em_decode # pathname of loadfile + args < # the input file name is the only argument + prop > # the output comes on stdout end .DE .DS X +.ta 4n 40n Example of a backend, in this case the EM assembler/loader. -var w=2 # wordsize 2 -var p=2 # pointersize 2 -var s=2 # short size 2 -var l=4 # long size 4 -var f=4 # float size 4 -var d=8 # double size 8 -var M=int # Unused in this example -var NAME=int22 # for cpp (NAME=int results in #define int 1) -var LIB=mach/int/lib/tail_ # part of file name for libraries -var RT=mach/int/lib/head_ # part of file name for run-time startoff -var SIZE_FLAG=-sm # default internal table size flag -var INCLUDES=-I{EM}/include # use {EM}/include for #include files -name asld # Assembler/loader - from .k.m.a # accepts compact code and archives - to e.out # output file name - program {EM}/lib/em_ass # load file pathname - mapflag -l* LNAME={EM}/{LIB}* # e.g. -ly becomes - # {EM}/mach/int/lib/tail_y - mapflag -+* ASS_F={ASS_F?} -+* # recognize -+ and -- - mapflag --* ASS_F={ASS_F?} --* - mapflag -s* SIZE_FLAG=-s* # overwrite old value of SIZE_FLAG - args {SIZE_FLAG} \ - ({RTS}:.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \ - (.p:{TAIL}={EM}/{LIB}pc) \ - (.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \ - (.c.p:{TAIL}={EM}/{LIB}mon) - # -s[sml] must be first argument - # the next line contains the choice for head_cc or head_pc - # and the specification of in- and output. - # the last three args lines choose libraries - prop C # This is the final stage +var w=2 # wordsize 2 +var p=2 # pointersize 2 +var s=2 # short size 2 +var l=4 # long size 4 +var f=4 # float size 4 +var d=8 # double size 8 +var M=int # Unused in this example +var NAME=int22 # for cpp (NAME=int results in #define int 1) +var LIB=mach/int/lib/tail_ # part of file name for libraries +var RT=mach/int/lib/head_ # part of file name for run-time startoff +var SIZE_FLAG=\-sm # default internal table size flag +var INCLUDES=\-I{EM}/include # use {EM}/include for #include files +name asld # Assembler/loader + from .k.m.a # accepts compact code and archives + to e.out # output file name + program {EM}/lib/em_ass # load file pathname + mapflag \-l* LNAME={EM}/{LIB}* # e.g. \-ly becomes + # {EM}/mach/int/lib/tail_y + mapflag \-+* ASS_F={ASS_F?} \-+* # recognize \-+ and \-\- + mapflag \-\-* ASS_F={ASS_F?} \-\-* + mapflag \-s* SIZE_FLAG=\-s* # overwrite old value of SIZE_FLAG + args {SIZE_FLAG} \e + ({RTS}:.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) \-o > < \e + (.p:{TAIL}={EM}/{LIB}pc) \e + (.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \e + (.c.p:{TAIL}={EM}/{LIB}mon) + # \-s[sml] must be first argument + # the next line contains the choice for head_cc or head_pc + # and the specification of in- and output. + # the last three args lines choose libraries + prop C # This is the final stage end .DE -The command "ack -mint -v -v -I../h -L -ly prog.c" - would result in the following +The command \fIack \-mint \-v \-v \-I../h \-L \-ly prog.c\fP +would result in the following calls (with exec(II)): .DS X -1) /lib/cpp -I../h -I/usr/em/include -Dint22 -DEM_WSIZE=2 -DEM_PSIZE=2 - -DEM_SSIZE=2 -DEM_LSIZE=4 -DEM_FSIZE=4 -DEM_DSIZE=8 prog.c -2) /usr/em/lib/em_cem -Vw2i2p2f4s2l4d8 -l -3) /usr/em/lib/em_ass -sm /usr/em/mach/int/lib/head_cc -o e.out prog.k - /usr/em/mach/int/lib/tail_y /usr/em/mach/int/lib/tail_cc.1s - /usr/em/mach/int/lib/tail_cc.2g /usr/em/mach/int/lib/tail_mon +.ta 4n +1) /lib/cpp \-I../h \-I/usr/em/include \-Dint22 \-DEM_WSIZE=2 \-DEM_PSIZE=2 \e + \-DEM_SSIZE=2 \-DEM_LSIZE=4 \-DEM_FSIZE=4 \-DEM_DSIZE=8 prog.c +2) /usr/em/lib/em_cem \-Vw2i2p2f4s2l4d8 \-l +3) /usr/em/lib/em_ass \-sm /usr/em/mach/int/lib/head_cc \-o e.out prog.k + /usr/em/mach/int/lib/tail_y /usr/em/mach/int/lib/tail_cc.1s + /usr/em/mach/int/lib/tail_cc.2g /usr/em/mach/int/lib/tail_mon .DE diff --git a/doc/cg.doc b/doc/cg.doc index 9fe39b17..32ff45fe 100644 --- a/doc/cg.doc +++ b/doc/cg.doc @@ -1,5 +1,6 @@ .\" $Header$ .RP +.ND Nov 1984 .TL The table driven code generator from .br @@ -17,6 +18,11 @@ The Amsterdam Compiler Kit is such a collection of tools. This document provides a description of the internal workings of the table driven code generator in the Amsterdam Compiler Kit, and a description of syntax and semantics of the driving table. +.PP +>>> NOTE <<< +.br +This document pertains to the \fBold\fP code generator. Refer to the +"Second Revised Edition" for the new code generator. .AE .NH 1 Introduction diff --git a/doc/cref.doc b/doc/cref.doc index ccbb4f80..76c4f84d 100644 --- a/doc/cref.doc +++ b/doc/cref.doc @@ -1,5 +1,4 @@ .\" $Header$ -.ll 72 .nr ID 4 .de hd 'sp 2 diff --git a/doc/i80.doc b/doc/i80.doc index 52bbbfe0..8de34e9c 100644 --- a/doc/i80.doc +++ b/doc/i80.doc @@ -1,4 +1,6 @@ +. \" $Header$ .RP +.ND April 1985 .TL Back end table for the Intel 8080 micro-processor .AU diff --git a/doc/install.doc b/doc/install.doc index 81754201..cddcb4ce 100644 --- a/doc/install.doc +++ b/doc/install.doc @@ -1,12 +1,11 @@ .\" $Header$ -.nr LL 7.5i .nr PD 1v .TL -Amsterdam Compiler Kit installation guide +Amsterdam Compiler Kit Installation Guide .AU Ed Keizer .AI -Wiskundig Seminarium +Vakgroep Informatica Vrije Universiteit Amsterdam .NH @@ -33,16 +32,16 @@ The process of installing Amsterdam Compiler Kit is quite simple. It is important that the original Amsterdam Compiler Kit distribution tree structure is restored. Proceed as follows -.IP " -" 10 +.IP " \-" 10 Create a directory, for example /usr/em, on a device with at least 15 Megabytes left. -.IP " -" +.IP " \-" Change to that directory (cd ...); it will be the working directory. -.IP " -" +.IP " \-" Extract all files from the distribution medium, for instance magtape: \fBtar x\fP. -.IP " -" +.IP " \-" Keep a copy of the original distribution to be able to repeat the process of installation in case of disasters. This copy is also useful as a reference point for diff-listings. @@ -143,29 +142,31 @@ These directories have subdirectories named: .in +3n .TS l l. -as the assembler ( *.s + libraries => a.out ) cg the backend ( *.m => *.s ) ncg the new backend ( *.m => *.s ) +as the assembler ( *.s + libraries => a.out ) +cv Conversion programs for a.out files. +dl Down-load programs + +libem Sources for EM runtime system, intended to depend only on CPU type libbc Used to create Basic run-time system and libraries libcc Used to create C run-time system and libraries libpc Used to create Pascal run-time system and libraries -libem Sources for EM runtime system, intended to depend only on CPU type libsys Sources for system-dependent EM library test Various tests -dl Down-load programs -cv Conversion programs for a.out files. + int Source for an interpreter .TE .in -3n -The directory proto contains files used by most machines +The directory proto contains files used by most machines, like machine-independent sources and Makefiles. .in +3n .TS l l. -mach/proto/libg Makefile for compiling libraries. -mach/proto/as Assembler sources. mach/proto/cg Current backend sources. mach/proto/ncg New backend sources. +mach/proto/as Assembler sources. +mach/proto/libg Makefile for compiling libraries. .TE .IP "emtest" .br @@ -277,14 +278,14 @@ first in a directory of the same name. .LP These actions are: .sp 1 -.IP - +.IP \- Automatically checking whether you included the ACK bin directory in your shell PATH. See also the section on "commands". -.IP - +.IP \- Automatically setting the pathname of the parent directory in ../h/em_path.h. See also the section on "pathnames". -.IP - +.IP \- Asking you for the type of system you have and creating the shell script "ack_sys" in the Kit's bin directory. Several utilities make use of "ack_sys" to determine the type of @@ -313,12 +314,12 @@ For ANY you can use any name you fancy, but the Kit will not be able to compile programs for your system. If you want to do that you have to read the section about "compilation on a different machine". -.IP - +.IP \- Automatically setting the default machine for which code is produced to your own type of system according to the table above. This in done in the file "h/local.h". See also the section 8.2. -.IP - +.IP \- Automatically editing a few description files that tell ACK to use your system's assembler. On both the PDP and the VAX the Kit uses the native assembler and linker. @@ -326,14 +327,14 @@ The description files in lib/pdp/descr, lib/vax2/descr and lib/vax4/descr have to be altered to prevent attempts to assemble programs with unsuitable assemblers. The original descr files are copied to descr.orig. -.IP - +.IP \- Automatically installing the special include directory for vax2. This will only be done on VAX systems. The shell scripts needed by ACK for the vax2 backend differ slightly from the one issued by Berkeley. .br Note: this has only been tested under BSD4.1a. -.IP - +.IP \- Automatically editing the system.h file in mach/vax[24]/libem. Again, only on VAXen. These files reflect whether you have BSD4.1a, BSD4.1c or BSD4.2. @@ -341,7 +342,7 @@ These files reflect whether you have BSD4.1a, BSD4.1c or BSD4.2. .sp 1 Some actions still have to be done by hand. .sp 1 -.IP - +.IP \- The VAX backends cannot be booted on systems with a 16-bit address space systems. The program lib/cgg needs more memory than available to transform @@ -354,18 +355,18 @@ You will hardly be able to use these, because the code generated by these programs cannot be assembled and loaded without a native VAX assembler, but its nice to be able to look at the code produced. -.IP - +.IP \- The installation of the PUBMAC macro package is not done automatically because you needs super-user privileges to do that on most systems. This macro package is used with several of the documents provided in the Kit. -.IP - +.IP \- UNIX V7 as originally distributed contains a few bugs that prevent correct execution of some of the larger programs. See the section named "Fixes for the UNIX V7 system" about what to do. -.IP - +.IP \- The manual files for the Kit can be copied to their appropriate place in the system by giving the command "make install" in the man directory. @@ -788,7 +789,7 @@ Sometimes the system differs so much from V7 that certain manifest constants do not exist any more. At other times these include files were written for a compiler without a restriction on name length. -In that case - I've seen it happen - people tend to use differing +In that case \- I've seen it happen \- people tend to use differing identifiers that are identical in the first eight characters. All these problems you have to solve yourself, the libraries are only included as an extra and too much system diff --git a/doc/pcref.doc b/doc/pcref.doc index 0cf42031..db979f4a 100644 --- a/doc/pcref.doc +++ b/doc/pcref.doc @@ -2,7 +2,7 @@ .ds OF \\fBtest~off:~\\fR .ds ON \\fBtest~on:~~\\fR .ds AL \\fBtest~all:~\\fR -.ll 72 +.ll 72n .wh 0 hd .wh 60 fo .de hd @@ -37,7 +37,7 @@ by .de VU .sp 3 .ce 4 -Wiskundig Seminarium +Vakgroep Informatica Vrije Universiteit De Boelelaan 1081 Amsterdam diff --git a/doc/toolkit.doc b/doc/toolkit.doc index d6e7b5d5..3596ecfa 100644 --- a/doc/toolkit.doc +++ b/doc/toolkit.doc @@ -1,7 +1,6 @@ .\" $Header$ .RP -.ND -.nr LL 78m +.ND July 1984 .tr ~ .ds as * .TL diff --git a/doc/val.doc b/doc/val.doc index 2be0c093..958de128 100644 --- a/doc/val.doc +++ b/doc/val.doc @@ -1,5 +1,5 @@ .\" $Header$ -.ll 72 +.ll 72n .wh 0 hd .wh 60 fo .de hd diff --git a/doc/z80.doc b/doc/z80.doc index e8a15a08..1976ca26 100644 --- a/doc/z80.doc +++ b/doc/z80.doc @@ -1,16 +1,21 @@ +. \" $Header$ +.ND April 1985 +.TL THE Z80 BACK END TABLE - +.AU +Frans van Haarlem +.NH 1 INTRODUCTION - +.PP This table was written to make it run, not to make it clever! The effect is, that the table written for the intel 8080, which was made very clever runs faster and requiers less space!! So, for anyone to run programs on a z80 machine: You could try to make the table as clever as the one for the i80, or you could run the i80 table, for that can run on every z80 too. - +.NH IMPLEMENTATION - +.PP It will not be possible to run the entire Amsterdam Compiler Kit on a Z80-based computer system. One has to write a program on another @@ -24,31 +29,37 @@ for example by downloading or by storing it in ROM (Read Only Memory). Depending on the characteristics of the particular z80 based system, some adaptions have to be made: -1) In 'head_em': the base address, which is the address where the first - z80 instruction will be stored, and the initial value of the - stackpointer are set to 0x1000 and 0x7ffe respectivally. - The latter because it could run on a 32K machine as well. - Other systems require other values. -2) In 'head_em': before calling "_m_a_i_n", the environment - pointer, argument vector and argument count will have to be pushed - onto the stack. - Since this back-end is tested on a system without any knowledge - of these things, dummies are pushed now. -3) In 'tail_em': proper routines "putchar" and "getchar" should - be provided. - They should write resp. read a character on/from the monitor. - Maybe some conversions will have to be made. - The ones for the Nascom and Hermac z80 micro's are to be found - in the EM-library. -4) In 'head_em': an application program returns control to the monitor by - jumping to address 0x20. - If this is not the right way on your system, change it. - For an CPM-machine for example this should be 0x5, to provide a warm boot. -5) In 'tail_em': the current version of the z80 back-end has very limited I/O - capabilities, because it was tested on a system that - had no knowlegde of files. - So the implementation of the EM-instruction 'mon' is very simple; - it can only do the following things: +.IP 1) +In \fIhead_em\fP: the base address, which is the address where the first +z80 instruction will be stored, and the initial value of the +stackpointer are set to 0x1000 and 0x7ffe respectivally. +The latter because it could run on a 32K machine as well. +Other systems require other values. +.IP 2) +In \fIhead_em\fP: before calling "_m_a_i_n", the environment +pointer, argument vector and argument count will have to be pushed +onto the stack. +Since this back-end is tested on a system without any knowledge +of these things, dummies are pushed now. +.IP 3) +In \fItail_em\fP: proper routines "putchar" and "getchar" should +be provided. +They should write resp. read a character on/from the monitor. +Maybe some conversions will have to be made. +The ones for the Nascom and Hermac z80 micro's are to be found +in the EM-library. +.IP 4) +In \fIhead_em\fP: an application program returns control to the monitor by +jumping to address 0x20. +If this is not the right way on your system, change it. +For an CPM-machine for example this should be 0x5, to provide a warm boot. +.IP 5) +In \fItail_em\fP: the current version of the z80 back-end has very limited I/O +capabilities, because it was tested on a system that +had no knowlegde of files. +So the implementation of the EM-instruction \fImon\fP is very simple; +it can only do the following things: +.DS Monitor call 1: Exit Monitor call 3: @@ -64,5 +75,6 @@ adaptions have to be made: close file, returns error code = 0. Monitor call 54: io-control, returns error code = 0. +.DE If the system should do file-handling the routine ".mon" should be extended thoroughly. From d4ee0dbf15ecd2a95a2e33b1168188f9df93c0d9 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 4 Mar 1986 11:39:22 +0000 Subject: [PATCH 0119/1625] Bug fix: The "calls" instruction could be called with first argument > 255. This is corrected. --- mach/vax4/cg/table | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mach/vax4/cg/table b/mach/vax4/cg/table index db86f3d9..85254053 100644 --- a/mach/vax4/cg/table +++ b/mach/vax4/cg/table @@ -4233,14 +4233,14 @@ cms zne $1==4 | | | | cmp zne $2 | * Group 14 : Procedure call instructions * ************************************************/ -cai asp $2%4 == 0 && $2>=0 +cai asp $2%4 == 0 && $2>=0 && $2 < 1024 | reg4 | remove(ALL) "calls\t$$%($2/4%),(%[1])" | | | cai | reg4 | remove(ALL) "calls\t$$0,(%[1])" | | | -cal asp $2%4 == 0 && $2>=0 +cal asp $2%4 == 0 && $2>=0 && $2 < 1024 | | remove(ALL) "calls\t$$%($2/4%),$1" | | | cal | | remove(ALL) From 8fc95eda5f6bf0c4eea46e41ced1d47b2460a41f Mon Sep 17 00:00:00 2001 From: dick Date: Tue, 4 Mar 1986 15:30:45 +0000 Subject: [PATCH 0120/1625] adapting to phototypesetter --- doc/Makefile | 2 +- doc/v7bugs.doc | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/Makefile b/doc/Makefile index 1c2d9992..764fe7d9 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -16,7 +16,7 @@ RESFILES= \ cref.$(SUF): cref.doc $(TBL) $? | $(NROFF) >$@ v7bugs.$(SUF): v7bugs.doc - $(NROFF) $(MS) $? >$@ + $(NROFF) $? >$@ ack.$(SUF): ack.doc $(NROFF) $(MS) $? >$@ cg.$(SUF): cg.doc diff --git a/doc/v7bugs.doc b/doc/v7bugs.doc index 5a5f0a6a..b6618830 100644 --- a/doc/v7bugs.doc +++ b/doc/v7bugs.doc @@ -12,19 +12,19 @@ .br .ne 20 .sp 2 -.in 5 -.ti -5 +.in 5n +.ti -5n ERROR \\n+e: .. .de PS .sp .nf -.in +5 +.in +5n .. .de PE .sp .fi -.in -5 +.in -5n .. .sp 3 .ce From cf157a157a23b18681ecf1266bd06b7a093479ad Mon Sep 17 00:00:00 2001 From: em Date: Wed, 5 Mar 1986 13:45:38 +0000 Subject: [PATCH 0121/1625] Added a third field to the pseudos indicating the type(s) of argument(s). New types are: t cst {0,1} a par v val e dlb Also added : ?, * and +, having the usual regular expression meaning. --- etc/em_table | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/etc/em_table b/etc/em_table index 8dd963bb..38ca26d1 100644 --- a/etc/em_table +++ b/etc/em_table @@ -26,18 +26,18 @@ ucon 252 fcon 253 cend 255 -bss 0 -con 1 -end 2 -exa 3 -exc 4 -exp 5 -hol 6 -ina 7 -inp 8 -mes 9 -pro 10 -rom 11 +bss 0 nvt +con 1 a+ +end 2 n? +exa 3 e +exc 4 nn +exp 5 p +hol 6 nvt +ina 7 e +inp 8 p +mes 9 na* +pro 10 pn? +rom 11 a+ aar w- -p-a-p+p adf w- -a-a+a From 9b393e474f477df3842e52b38043e92749fddfe4 Mon Sep 17 00:00:00 2001 From: em Date: Wed, 5 Mar 1986 14:27:08 +0000 Subject: [PATCH 0122/1625] Added the possibility of a third field in the pseudo-instruction description. This change is upwards compatible with the previous version, t.i., it still works the same with the previous version of "em_table". --- etc/new_table | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/etc/new_table b/etc/new_table index ef83ccb0..b62e7a70 100755 --- a/etc/new_table +++ b/etc/new_table @@ -10,7 +10,7 @@ ed - em_table <<'A' > X 1,/^$/g/ /s// /gp A -ed - em_table <<'A' | awk '{print $1,$2+'$p'}' > Y +ed - em_table <<'A' | awk '{$2=$2+'$p'; print}' > Y 1,/^$/d 1,/^$/g/ /s// /gp A @@ -31,6 +31,7 @@ g/^/s//#define sp_/p A ed - Y <<'A' > $h/em_pseu.h +g/ \(.*\) .*/s// \1/ g/\(.*\) \(.*\)/s//#define ps_\1 \2/p A From edd633437c9dc243fb98369f8675f92bb1af49f7 Mon Sep 17 00:00:00 2001 From: dick Date: Wed, 5 Mar 1986 16:58:40 +0000 Subject: [PATCH 0123/1625] generated itables no longer in RCS; avoid overflow in app.codes.pr --- doc/em/Makefile | 10 ++++++++-- doc/em/app.codes.nr | 4 +--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/doc/em/Makefile b/doc/em/Makefile index 670d993d..39935149 100644 --- a/doc/em/Makefile +++ b/doc/em/Makefile @@ -1,11 +1,15 @@ +HOME=../.. + head: doc.pr NROFF=nroff TBL=tbl + FILES = macr.nr title.nr intro.nr mem.nr ispace.nr dspace.nr mapping.nr \ types.nr descr.nr env.nr traps.nr mach.nr assem.nr \ app.int.nr app.codes.nr app.exam.nr cont.nr -IOP=../../util/ass/ip_spec.t + +IOP=$(HOME)/util/ass/ip_spec.t# # to construct itables from doc.pr: $(FILES) itables em.i Makefile $(TBL) $(FILES) | $(NROFF) >doc.pr @@ -20,6 +24,8 @@ pr: @make "NROFF="$(NROFF) TBL=$(TBL) doc.pr >makepr.out 2>&1 @cat doc.pr +app.codes.pr: app.codes.nr itables + itables: $(IOP) ip.awk awk -f ip.awk $(IOP) | sed 's/-/\\-/g' | $(TBL) >itables @@ -27,4 +33,4 @@ itables: $(IOP) ip.awk .nr.pr: ; $(TBL) macr.nr $*.nr | $(NROFF) >$@ clean: - rm -f doc.pr itables + rm -f *.pr itables *.out diff --git a/doc/em/app.codes.nr b/doc/em/app.codes.nr index 2e511ec5..d7f43f44 100644 --- a/doc/em/app.codes.nr +++ b/doc/em/app.codes.nr @@ -97,9 +97,7 @@ Escaped opcode 145 is used for ZER. The interpreter opcode table: .N 1 .IS 3 -.DS B .so itables -.DE 0 .IE .P The table above results in the following dispatch tables. @@ -138,7 +136,7 @@ shortie with argument divided by the wordsize mini with as argument .PT .W mini with *wordsize as argument -.PE 3 +.PE 1 is a possibly negative integer. .VS 1 1 .IE From d566eb8d639ddddcbff45c7ffdeb5b538b3dd6f9 Mon Sep 17 00:00:00 2001 From: em Date: Wed, 5 Mar 1986 17:12:39 +0000 Subject: [PATCH 0124/1625] updated --- mach/m68k2/cv/Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mach/m68k2/cv/Makefile b/mach/m68k2/cv/Makefile index d3203806..5ea7243f 100644 --- a/mach/m68k2/cv/Makefile +++ b/mach/m68k2/cv/Makefile @@ -1,8 +1,11 @@ -CFLAGS=-O -I../../../h +CFLAGS=-I../../../h cv: cv.o $(CC) -o cv -n cv.o +cv.prev: cv.prev.o + $(CC) -o cv.prev -n cv.prev.o + install: ins_cv ins_cv: cv ../../install cv From 65c1ca3fd9ba944801b8422c4e16741cb4e35544 Mon Sep 17 00:00:00 2001 From: erikb Date: Mon, 10 Mar 1986 13:07:55 +0000 Subject: [PATCH 0125/1625] *** empty log message *** --- lang/cem/cemcom/LLlex.c | 563 ++++++++++++++++++ lang/cem/cemcom/LLlex.h | 54 ++ lang/cem/cemcom/LLmessage.c | 50 ++ lang/cem/cemcom/Makefile.erik | 215 +++++++ lang/cem/cemcom/Parameters | 144 +++++ lang/cem/cemcom/align.h | 9 + lang/cem/cemcom/alloc.c | 161 ++++++ lang/cem/cemcom/alloc.h | 16 + lang/cem/cemcom/arith.c | 465 +++++++++++++++ lang/cem/cemcom/arith.h | 23 + lang/cem/cemcom/asm.c | 10 + lang/cem/cemcom/assert.h | 17 + lang/cem/cemcom/atw.h | 6 + lang/cem/cemcom/blocks.c | 88 +++ lang/cem/cemcom/cem.1 | 238 ++++++++ lang/cem/cemcom/cem.c | 744 ++++++++++++++++++++++++ lang/cem/cemcom/cemcom.1 | 94 +++ lang/cem/cemcom/ch7.c | 409 +++++++++++++ lang/cem/cemcom/ch7bin.c | 308 ++++++++++ lang/cem/cemcom/ch7mon.c | 148 +++++ lang/cem/cemcom/char.tab | 58 ++ lang/cem/cemcom/class.h | 37 ++ lang/cem/cemcom/code.c | 491 ++++++++++++++++ lang/cem/cemcom/code.h | 23 + lang/cem/cemcom/code.str | 23 + lang/cem/cemcom/conversion.c | 130 +++++ lang/cem/cemcom/cstoper.c | 230 ++++++++ lang/cem/cemcom/dataflow.c | 34 ++ lang/cem/cemcom/declar.g | 473 +++++++++++++++ lang/cem/cemcom/declar.str | 45 ++ lang/cem/cemcom/declarator.c | 106 ++++ lang/cem/cemcom/declarator.h | 45 ++ lang/cem/cemcom/decspecs.c | 92 +++ lang/cem/cemcom/decspecs.h | 23 + lang/cem/cemcom/decspecs.str | 23 + lang/cem/cemcom/def.h | 37 ++ lang/cem/cemcom/def.str | 37 ++ lang/cem/cemcom/domacro.c | 673 +++++++++++++++++++++ lang/cem/cemcom/dumpidf.c | 367 ++++++++++++ lang/cem/cemcom/em.c | 219 +++++++ lang/cem/cemcom/em.h | 42 ++ lang/cem/cemcom/emcode.def | 123 ++++ lang/cem/cemcom/error.c | 212 +++++++ lang/cem/cemcom/eval.c | 1028 +++++++++++++++++++++++++++++++++ lang/cem/cemcom/expr.c | 408 +++++++++++++ lang/cem/cemcom/expr.h | 102 ++++ lang/cem/cemcom/expr.str | 102 ++++ lang/cem/cemcom/expression.g | 371 ++++++++++++ lang/cem/cemcom/faulty.h | 5 + lang/cem/cemcom/field.c | 199 +++++++ lang/cem/cemcom/field.h | 20 + lang/cem/cemcom/field.str | 20 + lang/cem/cemcom/idf.c | 697 ++++++++++++++++++++++ lang/cem/cemcom/idf.h | 68 +++ lang/cem/cemcom/idf.str | 68 +++ lang/cem/cemcom/init.c | 107 ++++ lang/cem/cemcom/input.c | 458 +++++++++++++++ lang/cem/cemcom/input.h | 13 + lang/cem/cemcom/interface.h | 3 + lang/cem/cemcom/ival.c | 792 +++++++++++++++++++++++++ lang/cem/cemcom/label.c | 88 +++ lang/cem/cemcom/label.h | 11 + lang/cem/cemcom/level.h | 15 + lang/cem/cemcom/macro.h | 52 ++ lang/cem/cemcom/macro.str | 52 ++ lang/cem/cemcom/main.c | 382 ++++++++++++ lang/cem/cemcom/make.emfun | 19 + lang/cem/cemcom/make.emmac | 10 + lang/cem/cemcom/make.hfiles | 35 ++ lang/cem/cemcom/make.next | 3 + lang/cem/cemcom/make.tokcase | 34 ++ lang/cem/cemcom/make.tokfile | 6 + lang/cem/cemcom/mcomm.c | 241 ++++++++ lang/cem/cemcom/mes.h | 4 + lang/cem/cemcom/options | 28 + lang/cem/cemcom/options.c | 252 ++++++++ lang/cem/cemcom/program.g | 190 ++++++ lang/cem/cemcom/replace.c | 158 +++++ lang/cem/cemcom/scan.c | 224 +++++++ lang/cem/cemcom/sizes.h | 8 + lang/cem/cemcom/skip.c | 73 +++ lang/cem/cemcom/specials.h | 14 + lang/cem/cemcom/stack.c | 280 +++++++++ lang/cem/cemcom/stack.h | 46 ++ lang/cem/cemcom/stack.str | 46 ++ lang/cem/cemcom/statement.g | 402 +++++++++++++ lang/cem/cemcom/stb.c | 11 + lang/cem/cemcom/storage.c | 67 +++ lang/cem/cemcom/storage.h | 9 + lang/cem/cemcom/string.c | 275 +++++++++ lang/cem/cemcom/string.h | 13 + lang/cem/cemcom/struct.c | 503 ++++++++++++++++ lang/cem/cemcom/struct.h | 44 ++ lang/cem/cemcom/struct.str | 44 ++ lang/cem/cemcom/switch.c | 184 ++++++ lang/cem/cemcom/switch.h | 40 ++ lang/cem/cemcom/switch.str | 40 ++ lang/cem/cemcom/system.c | 72 +++ lang/cem/cemcom/system.h | 34 ++ lang/cem/cemcom/tab.c | 295 ++++++++++ lang/cem/cemcom/tokenname.c | 143 +++++ lang/cem/cemcom/tokenname.h | 9 + lang/cem/cemcom/type.c | 217 +++++++ lang/cem/cemcom/type.h | 52 ++ lang/cem/cemcom/type.str | 52 ++ 105 files changed, 16543 insertions(+) create mode 100644 lang/cem/cemcom/LLlex.c create mode 100644 lang/cem/cemcom/LLlex.h create mode 100644 lang/cem/cemcom/LLmessage.c create mode 100644 lang/cem/cemcom/Makefile.erik create mode 100644 lang/cem/cemcom/Parameters create mode 100644 lang/cem/cemcom/align.h create mode 100644 lang/cem/cemcom/alloc.c create mode 100644 lang/cem/cemcom/alloc.h create mode 100644 lang/cem/cemcom/arith.c create mode 100644 lang/cem/cemcom/arith.h create mode 100644 lang/cem/cemcom/asm.c create mode 100644 lang/cem/cemcom/assert.h create mode 100644 lang/cem/cemcom/atw.h create mode 100644 lang/cem/cemcom/blocks.c create mode 100644 lang/cem/cemcom/cem.1 create mode 100644 lang/cem/cemcom/cem.c create mode 100644 lang/cem/cemcom/cemcom.1 create mode 100644 lang/cem/cemcom/ch7.c create mode 100644 lang/cem/cemcom/ch7bin.c create mode 100644 lang/cem/cemcom/ch7mon.c create mode 100644 lang/cem/cemcom/char.tab create mode 100644 lang/cem/cemcom/class.h create mode 100644 lang/cem/cemcom/code.c create mode 100644 lang/cem/cemcom/code.h create mode 100644 lang/cem/cemcom/code.str create mode 100644 lang/cem/cemcom/conversion.c create mode 100644 lang/cem/cemcom/cstoper.c create mode 100644 lang/cem/cemcom/dataflow.c create mode 100644 lang/cem/cemcom/declar.g create mode 100644 lang/cem/cemcom/declar.str create mode 100644 lang/cem/cemcom/declarator.c create mode 100644 lang/cem/cemcom/declarator.h create mode 100644 lang/cem/cemcom/decspecs.c create mode 100644 lang/cem/cemcom/decspecs.h create mode 100644 lang/cem/cemcom/decspecs.str create mode 100644 lang/cem/cemcom/def.h create mode 100644 lang/cem/cemcom/def.str create mode 100644 lang/cem/cemcom/domacro.c create mode 100644 lang/cem/cemcom/dumpidf.c create mode 100644 lang/cem/cemcom/em.c create mode 100644 lang/cem/cemcom/em.h create mode 100644 lang/cem/cemcom/emcode.def create mode 100644 lang/cem/cemcom/error.c create mode 100644 lang/cem/cemcom/eval.c create mode 100644 lang/cem/cemcom/expr.c create mode 100644 lang/cem/cemcom/expr.h create mode 100644 lang/cem/cemcom/expr.str create mode 100644 lang/cem/cemcom/expression.g create mode 100644 lang/cem/cemcom/faulty.h create mode 100644 lang/cem/cemcom/field.c create mode 100644 lang/cem/cemcom/field.h create mode 100644 lang/cem/cemcom/field.str create mode 100644 lang/cem/cemcom/idf.c create mode 100644 lang/cem/cemcom/idf.h create mode 100644 lang/cem/cemcom/idf.str create mode 100644 lang/cem/cemcom/init.c create mode 100644 lang/cem/cemcom/input.c create mode 100644 lang/cem/cemcom/input.h create mode 100644 lang/cem/cemcom/interface.h create mode 100644 lang/cem/cemcom/ival.c create mode 100644 lang/cem/cemcom/label.c create mode 100644 lang/cem/cemcom/label.h create mode 100644 lang/cem/cemcom/level.h create mode 100644 lang/cem/cemcom/macro.h create mode 100644 lang/cem/cemcom/macro.str create mode 100644 lang/cem/cemcom/main.c create mode 100755 lang/cem/cemcom/make.emfun create mode 100755 lang/cem/cemcom/make.emmac create mode 100755 lang/cem/cemcom/make.hfiles create mode 100755 lang/cem/cemcom/make.next create mode 100755 lang/cem/cemcom/make.tokcase create mode 100755 lang/cem/cemcom/make.tokfile create mode 100644 lang/cem/cemcom/mcomm.c create mode 100644 lang/cem/cemcom/mes.h create mode 100644 lang/cem/cemcom/options create mode 100644 lang/cem/cemcom/options.c create mode 100644 lang/cem/cemcom/program.g create mode 100644 lang/cem/cemcom/replace.c create mode 100644 lang/cem/cemcom/scan.c create mode 100644 lang/cem/cemcom/sizes.h create mode 100644 lang/cem/cemcom/skip.c create mode 100644 lang/cem/cemcom/specials.h create mode 100644 lang/cem/cemcom/stack.c create mode 100644 lang/cem/cemcom/stack.h create mode 100644 lang/cem/cemcom/stack.str create mode 100644 lang/cem/cemcom/statement.g create mode 100644 lang/cem/cemcom/stb.c create mode 100644 lang/cem/cemcom/storage.c create mode 100644 lang/cem/cemcom/storage.h create mode 100644 lang/cem/cemcom/string.c create mode 100644 lang/cem/cemcom/string.h create mode 100644 lang/cem/cemcom/struct.c create mode 100644 lang/cem/cemcom/struct.h create mode 100644 lang/cem/cemcom/struct.str create mode 100644 lang/cem/cemcom/switch.c create mode 100644 lang/cem/cemcom/switch.h create mode 100644 lang/cem/cemcom/switch.str create mode 100644 lang/cem/cemcom/system.c create mode 100644 lang/cem/cemcom/system.h create mode 100644 lang/cem/cemcom/tab.c create mode 100644 lang/cem/cemcom/tokenname.c create mode 100644 lang/cem/cemcom/tokenname.h create mode 100644 lang/cem/cemcom/type.c create mode 100644 lang/cem/cemcom/type.h create mode 100644 lang/cem/cemcom/type.str diff --git a/lang/cem/cemcom/LLlex.c b/lang/cem/cemcom/LLlex.c new file mode 100644 index 00000000..0c3e9f98 --- /dev/null +++ b/lang/cem/cemcom/LLlex.c @@ -0,0 +1,563 @@ +/* $Header$ */ +/* L E X I C A L A N A L Y Z E R */ + +#include "idfsize.h" +#include "numsize.h" +#include "debug.h" +#include "strsize.h" +#include "nopp.h" + +#include "input.h" +#include "alloc.h" +#include "arith.h" +#include "def.h" +#include "idf.h" +#include "LLlex.h" +#include "Lpars.h" +#include "class.h" +#include "assert.h" +#include "sizes.h" + +/* Data about the token yielded */ +struct token dot, ahead, aside; + +unsigned int LineNumber = 0; /* current LineNumber */ +char *FileName = 0; /* current filename */ + +int ReplaceMacros = 1; /* replacing macros */ +int EoiForNewline = 0; /* return EOI upon encountering newline */ +int PreProcKeys = 0; /* return preprocessor key */ +int AccFileSpecifier = 0; /* return filespecifier <...> */ +int AccDefined = 0; /* accept "defined(...)" */ +int UnknownIdIsZero = 0; /* interpret unknown id as integer 0 */ +int SkipEscNewline = 0; /* how to interpret backslash-newline */ + +#define MAX_LL_DEPTH 2 + +static struct token LexStack[MAX_LL_DEPTH]; +static LexSP = 0; + +/* In PushLex() the actions are taken in order to initialise or + re-initialise the lexical scanner. + E.g. at the invocation of a sub-parser that uses LLlex(), the + state of the current parser should be saved. +*/ +PushLex() +{ + ASSERT(LexSP < 2); + ASSERT(ASIDE == 0); /* ASIDE = 0; */ + GetToken(&ahead); + ahead.tk_line = LineNumber; + ahead.tk_file = FileName; + LexStack[LexSP++] = dot; +} + +PopLex() +{ + ASSERT(LexSP > 0); + dot = LexStack[--LexSP]; +} + +int +LLlex() +{ + /* LLlex() plays the role of Lexical Analyzer for the C parser. + The look-ahead and putting aside of tokens are taken into + account. + */ + if (ASIDE) { /* a token is put aside */ + dot = aside; + ASIDE = 0; + } + else { /* read ahead and return the old one */ + dot = ahead; + /* the following test is performed due to the dual + task of LLlex(): it is also called for parsing the + restricted constant expression following a #if or + #elif. The newline character causes EOF to be + returned in this case to stop the LLgen parsing task. + */ + if (DOT != EOI) + GetToken(&ahead); + else + DOT = EOF; + } + /* keep track of the place of the token in the file */ + ahead.tk_file = FileName; + ahead.tk_line = LineNumber; + return DOT; +} + +char *string_token(); + +int +GetToken(ptok) + register struct token *ptok; +{ + /* GetToken() is the actual token recognizer. It calls the + control line interpreter if it encounters a "\n#" + combination. Macro replacement is also performed if it is + needed. + */ + char buf[(IDFSIZE > NUMSIZE ? IDFSIZE : NUMSIZE) + 1]; + register int ch, nch; + +again: /* rescan the input after an error or replacement */ + LoadChar(ch); +go_on: /* rescan, the following character has been read */ + /* The following test is made to strip off the nonascii's */ + if ((ch & 0200) && ch != EOI) { + /* this is the only user-error which causes the + process to stop abruptly. + */ + fatal("non-ascii '\\%03o' read", ch & 0377); + } + switch (class(ch)) { /* detect character class */ + case STNL: /* newline, vertical space or formfeed */ + LineNumber++; /* also at vs and ff */ + if (EoiForNewline) /* called in control line */ + /* a newline in a control line indicates the + end-of-information of the line. + */ + return ptok->tk_symb = EOI; + while (LoadChar(ch), ch == '#') /* a control line follows */ + domacro(); + /* We have to loop here, because in + `domacro' the nl, vt or ff is read. The + character following it may again be a `#'. + */ + goto go_on; + case STSKIP: /* just skip the skip characters */ + goto again; + case STGARB: /* garbage character */ +#ifndef NOPP + if (SkipEscNewline && (ch == '\\')) { + /* a '\\' is allowed in #if/#elif expression */ + LoadChar(ch); + if (class(ch) == STNL) { /* vt , ff ? */ + ++LineNumber; + goto again; + } + PushBack(); + ch = '\\'; + } +#endif NOPP + if (040 < ch && ch < 0177) + lexerror("garbage char %c", ch); + else + lexerror("garbage char \\%03o", ch); + goto again; + case STSIMP: /* a simple character, no part of compound token*/ + if (ch == '/') { /* probably the start of comment */ + LoadChar(ch); + if (ch == '*') { + /* start of comment */ + skipcomment(); + goto again; + } + else { + PushBack(); + ch = '/'; /* restore ch */ + } + } + return ptok->tk_symb = ch; + case STCOMP: /* maybe the start of a compound token */ + LoadChar(nch); /* character lookahead */ + switch (ch) { + case '!': + if (nch == '=') + return ptok->tk_symb = NOTEQUAL; + PushBack(); + return ptok->tk_symb = ch; + case '&': + if (nch == '&') + return ptok->tk_symb = AND; + PushBack(); + return ptok->tk_symb = ch; + case '+': + if (nch == '+') + return ptok->tk_symb = PLUSPLUS; + PushBack(); + return ptok->tk_symb = ch; + case '-': + if (nch == '-') + return ptok->tk_symb = MINMIN; + if (nch == '>') + return ptok->tk_symb = ARROW; + PushBack(); + return ptok->tk_symb = ch; + case '<': + if (AccFileSpecifier) { + PushBack(); /* pushback nch */ + ptok->tk_str = + string_token("file specifier", '>'); + return ptok->tk_symb = FILESPECIFIER; + } + if (nch == '<') + return ptok->tk_symb = LEFT; + if (nch == '=') + return ptok->tk_symb = LESSEQ; + PushBack(); + return ptok->tk_symb = ch; + case '=': + if (nch == '=') + return ptok->tk_symb = EQUAL; + /* The following piece of code tries to recognise + old-fashioned assignment operators `=op' + */ + switch (nch) { + case '+': + return ptok->tk_symb = PLUSAB; + case '-': + return ptok->tk_symb = MINAB; + case '*': + return ptok->tk_symb = TIMESAB; + case '/': + return ptok->tk_symb = DIVAB; + case '%': + return ptok->tk_symb = MODAB; + case '>': + case '<': + LoadChar(ch); + if (ch != nch) { + PushBack(); + lexerror("illegal combination '=%c'", + nch); + } + return ptok->tk_symb = + nch == '<' ? LEFTAB : RIGHTAB; + case '&': + return ptok->tk_symb = ANDAB; + case '^': + return ptok->tk_symb = XORAB; + case '|': + return ptok->tk_symb = ORAB; + } + PushBack(); + return ptok->tk_symb = ch; + case '>': + if (nch == '=') + return ptok->tk_symb = GREATEREQ; + if (nch == '>') + return ptok->tk_symb = RIGHT; + PushBack(); + return ptok->tk_symb = ch; + case '|': + if (nch == '|') + return ptok->tk_symb = OR; + PushBack(); + return ptok->tk_symb = ch; + } + case STIDF: + { + register char *tg = &buf[0]; + register int pos = -1; + register int hash; + register struct idf *idef; + extern int idfsize; /* ??? */ + + hash = STARTHASH(); + do { /* read the identifier */ + if (++pos < idfsize) { + *tg++ = ch; + hash = ENHASH(hash, ch, pos); + } + LoadChar(ch); + } while (in_idf(ch)); + hash = STOPHASH(hash); + if (ch != EOI) + PushBack(); + *tg++ = '\0'; /* mark the end of the identifier */ + idef = ptok->tk_idf = idf_hashed(buf, tg - buf, hash); +#ifndef NOPP + if (idef->id_macro && ReplaceMacros) { + /* macro replacement should be performed */ + if (replace(idef)) + goto again; + /* arrived here: something went wrong in + replace, don't substitute in this case + */ + } + else + if (UnknownIdIsZero) { + ptok->tk_ival = (arith)0; + ptok->tk_fund = INT; + return ptok->tk_symb = INTEGER; + } +#endif NOPP + ptok->tk_symb = ( + idef->id_reserved ? + idef->id_reserved : + idef->id_def && idef->id_def->df_sc == TYPEDEF ? + TYPE_IDENTIFIER : + IDENTIFIER + ); + return IDENTIFIER; + } + case STCHAR: /* character constant */ + { + register arith val = 0, size = 0; + + LoadChar(ch); + if (ch == '\'') + lexerror("character constant too short"); + else + while (ch != '\'') { + if (ch == '\n') { + lexerror("newline in character constant"); + LineNumber++; + break; + } + if (ch == '\\') { + LoadChar(ch); + ch = quoted(ch); + } + val = val*256 + ch; + size++; + LoadChar(ch); + } + if (size > int_size) + lexerror("character constant too long"); + ptok->tk_ival = val; + ptok->tk_fund = INT; + return ptok->tk_symb = INTEGER; + } + case STSTR: /* string */ + ptok->tk_str = string_token("string", '"'); + return ptok->tk_symb = STRING; + case STNUM: /* a numeric constant */ + { + /* It should be noted that 099 means 81(decimal) and + 099.5 means 99.5 . This severely limits the tricks + we can use to scan a numeric value. + */ + register char *np = &buf[1]; + register int base = 10; + register int vch; + register arith val = 0; + + if (ch == '.') { /* an embarrassing ambiguity */ + LoadChar(vch); + PushBack(); + if (!is_dig(vch)) /* just a `.' */ + return ptok->tk_symb = ch; + *np++ = '0'; + /* in the rest of the compiler, all floats + have to start with a digit. + */ + } + if (ch == '0') { + *np++ = ch; + LoadChar(ch); + if (ch == 'x' || ch == 'X') { + base = 16; + LoadChar(ch); + } + else + base = 8; + } + while (vch = val_in_base(ch, base), vch >= 0) { + val = val*base + vch; + if (np < &buf[NUMSIZE]) + *np++ = ch; + LoadChar(ch); + } + if (ch == 'l' || ch == 'L') { + ptok->tk_ival = val; + ptok->tk_fund = LONG; + return ptok->tk_symb = INTEGER; + } + if (base == 16 || !(ch == '.' || ch == 'e' || ch == 'E')) { + PushBack(); + ptok->tk_ival = val; + /* The semantic analyser must know if the + integral constant is given in octal/hexa- + decimal form, in which case its type is + UNSIGNED, or in decimal form, in which case + its type is signed, indicated by + the fund INTEGER. + */ + ptok->tk_fund = + (base == 10 || (base == 8 && val == (arith)0)) + ? INTEGER : UNSIGNED; + return ptok->tk_symb = INTEGER; + } + /* where's the test for the length of the integral ??? */ + if (ch == '.'){ + if (np < &buf[NUMSIZE]) + *np++ = ch; + LoadChar(ch); + } + while (is_dig(ch)){ + if (np < &buf[NUMSIZE]) + *np++ = ch; + LoadChar(ch); + } + if (ch == 'e' || ch == 'E') { + if (np < &buf[NUMSIZE]) + *np++ = ch; + LoadChar(ch); + if (ch == '+' || ch == '-') { + if (np < &buf[NUMSIZE]) + *np++ = ch; + LoadChar(ch); + } + if (!is_dig(ch)) { + lexerror("malformed floating constant"); + if (np < &buf[NUMSIZE]) + *np++ = ch; + } + while (is_dig(ch)) { + if (np < &buf[NUMSIZE]) + *np++ = ch; + LoadChar(ch); + } + } + PushBack(); + *np++ = '\0'; + buf[0] = '-'; /* good heavens... */ + if (np == &buf[NUMSIZE+1]) { + lexerror("floating constant too long"); + ptok->tk_fval = Salloc("0.0", 5) + 1; + } + else + ptok->tk_fval = Salloc(buf, np - buf) + 1; + return ptok->tk_symb = FLOATING; + } + case STEOI: /* end of text on source file */ + return ptok->tk_symb = EOI; + default: /* this cannot happen */ + crash("bad class for char 0%o", ch); + } + /*NOTREACHED*/ +} + +skipcomment() +{ + /* The last character read has been the '*' of '/_*'. The + characters, except NL and EOI, between '/_*' and the first + occurring '*_/' are not interpreted. + NL only affects the LineNumber. EOI is not legal. + + Important note: it is not possible to stop skipping comment + beyond the end-of-file of an included file. + EOI is returned by LoadChar only on encountering EOF of the + top-level file... + */ + register int c; + + NoUnstack++; + LoadChar(c); + do { + while (c != '*') { + if (class(c) == STNL) + ++LineNumber; + else + if (c == EOI) { + NoUnstack--; + return; + } + LoadChar(c); + } + /* Last Character seen was '*' */ + LoadChar(c); + } while (c != '/'); + NoUnstack--; +} + +char * +string_token(nm, stop_char) + char *nm; +{ + register int ch; + register int str_size; + register char *str = Malloc(str_size = ISTRSIZE); + register int pos = 0; + + LoadChar(ch); + while (ch != stop_char) { + if (ch == '\n') { + lexerror("newline in %s", nm); + LineNumber++; + break; + } + if (ch == EOI) { + lexerror("end-of-file inside %s", nm); + break; + } + if (ch == '\\') { + register int nch; + + LoadChar(nch); + if (nch == '\n') { + LineNumber++; + LoadChar(ch); + continue; + } + else { + str[pos++] = '\\'; + if (pos == str_size) + str = Srealloc(str, str_size += RSTRSIZE); + ch = nch; + } + } + str[pos++] = ch; + if (pos == str_size) + str = Srealloc(str, str_size += RSTRSIZE); + LoadChar(ch); + } + str[pos++] = '\0'; + return str; +} + +int +quoted(ch) + register int ch; +{ + /* quoted() replaces an escaped character sequence by the + character meant. + */ + /* first char after backslash already in ch */ + if (!is_oct(ch)) { /* a quoted char */ + switch (ch) { + case 'n': + ch = '\n'; + break; + case 't': + ch = '\t'; + break; + case 'b': + ch = '\b'; + break; + case 'r': + ch = '\r'; + break; + case 'f': + ch = '\f'; + break; + } + } + else { /* a quoted octal */ + register int oct = 0, cnt = 0; + + do { + oct = oct*8 + (ch-'0'); + LoadChar(ch); + } while (is_oct(ch) && ++cnt < 3); + PushBack(); + ch = oct; + } + return ch&0377; +} + +/* provisional */ +int +val_in_base(ch, base) + register int ch; +{ + return + is_dig(ch) ? ch - '0' : + base != 16 ? -1 : + is_hex(ch) ? (ch - 'a' + 10) & 017 : + -1; +} diff --git a/lang/cem/cemcom/LLlex.h b/lang/cem/cemcom/LLlex.h new file mode 100644 index 00000000..fbc18ad0 --- /dev/null +++ b/lang/cem/cemcom/LLlex.h @@ -0,0 +1,54 @@ +/* $Header$ */ +/* D E F I N I T I O N S F O R T H E L E X I C A L A N A L Y Z E R */ + +/* A token from the input stream is represented by an integer, + called a "symbol", but it may have other information associated + to it. +*/ + +/* the structure of a token: */ +struct token { + int tok_symb; /* the token itself */ + char *tok_file; /* the file it (probably) comes from */ + unsigned int tok_line; /* the line it (probably) comes from */ + union { + struct idf *tok_idf; /* for IDENTIFIER & TYPE_IDENTIFIER */ + char *tok_str; /* for STRING: text */ + struct { /* for INTEGER */ + int tok_fund; /* INT or LONG */ + arith tok_ival; + } tok_integer; + char *tok_fval; + } tok_data; +}; + +#define tk_symb tok_symb +#define tk_file tok_file +#define tk_line tok_line +#define tk_idf tok_data.tok_idf +#define tk_str tok_data.tok_str +#define tk_fund tok_data.tok_integer.tok_fund +#define tk_ival tok_data.tok_integer.tok_ival +#define tk_fval tok_data.tok_fval + +extern struct token dot, ahead, aside; +extern unsigned int LineNumber; /* "LLlex.c" */ +extern char *FileName; /* "LLlex.c" */ + +extern int ReplaceMacros; /* "LLlex.c" */ +extern int EoiForNewline; /* "LLlex.c" */ +extern int PreProcKeys; /* "LLlex.c" */ +extern int AccFileSpecifier; /* "LLlex.c" */ +extern int AccDefined; /* "LLlex.c" */ +extern int UnknownIdIsZero; /* "LLlex.c" */ +extern int SkipEscNewline; /* "LLlex.c" */ + +extern int NoUnstack; /* buffer.c */ + +extern int err_occurred; /* "error.c" */ + +#define DOT dot.tk_symb +#define AHEAD ahead.tk_symb +#define ASIDE aside.tk_symb + +#define EOF (-1) diff --git a/lang/cem/cemcom/LLmessage.c b/lang/cem/cemcom/LLmessage.c new file mode 100644 index 00000000..acb3b9bc --- /dev/null +++ b/lang/cem/cemcom/LLmessage.c @@ -0,0 +1,50 @@ +/* $Header$ */ +/* PARSER ERROR ADMINISTRATION */ + +#include "idf.h" +#include "alloc.h" +#include "arith.h" +#include "LLlex.h" +#include "Lpars.h" + +extern char *symbol2str(); + +LLmessage(tk) { + err_occurred = 1; + if (tk < 0) + fatal("parser administration overflow"); + if (tk) { + error("%s missing", symbol2str(tk)); + insert_token(tk); + } + else + error("%s deleted", symbol2str(DOT)); +} + +insert_token(tk) + int tk; +{ + aside = dot; + + DOT = tk; + + switch (tk) { + /* The operands need some body */ + case IDENTIFIER: + dot.tk_idf = gen_idf(); + break; + case TYPE_IDENTIFIER: + dot.tk_idf = str2idf("int"); + break; + case STRING: + dot.tk_str = Salloc("", 1); + break; + case INTEGER: + dot.tk_fund = INT; + dot.tk_ival = 1; + break; + case FLOATING: + dot.tk_fval = Salloc("0.0", 4); + break; + } +} diff --git a/lang/cem/cemcom/Makefile.erik b/lang/cem/cemcom/Makefile.erik new file mode 100644 index 00000000..83f229fc --- /dev/null +++ b/lang/cem/cemcom/Makefile.erik @@ -0,0 +1,215 @@ +# $Header$ +# M A K E F I L E F O R A C K C - C O M P I L E R + +# Some paths +BIN =/user1/$$USER/bin# # provisional ??? +EM = /usr/em# # where to find the ACK tree +ACK = $(EM)/bin/ack# # old ACK C compiler +EM_INCLUDES =$(EM)/h# # directory containing EM interface definition + +# Where to install the compiler and its driver +CEMCOM = $(BIN)/cemcom +DRIVER = $(BIN)/cem + +# What C compiler to use and how +CC = $(ACK) -.c +CC = CC +CC = /bin/cc +COPTIONS = + +# What parser generator to use and how +GEN = /user0/ceriel/bin/LLgen +GENOPTIONS = -vv + +# Special #defines during compilation +CDEFS = $(MAP) -I$(EM_INCLUDES) +CFLAGS = $(CDEFS) $(COPTIONS) -O# # we cannot pass the COPTIONS to lint! + +# Grammar files and their objects +LSRC = tokenfile.g declar.g statement.g expression.g program.g +LOBJ = tokenfile.o declar.o statement.o expression.o program.o Lpars.o + +# Objects of hand-written C files +COBJ = main.o idf.o declarator.o decspecs.o struct.o \ + expr.o ch7.o ch7bin.o cstoper.o arith.o \ + alloc.o asm.o code.o dumpidf.o error.o field.o\ + tokenname.o LLlex.o LLmessage.o \ + input.o domacro.o replace.o init.o options.o \ + scan.o skip.o stack.o type.o ch7mon.o label.o eval.o \ + switch.o storage.o ival.o conversion.o \ + em.o blocks.o dataflow.o system.o string.o + +# Objects of other generated C files +GOBJ = char.o symbol2str.o next.o writeem.o + +# generated source files +GSRC = char.c symbol2str.c next.c writeem.c \ + writeem.h + +# .h files generated by `make hfiles'; PLEASE KEEP THIS UP-TO-DATE! +GHSRC = botch_free.h dataflow.h debug.h density.h errout.h \ + idepth.h idfsize.h ifdepth.h inputtype.h inumlength.h lapbuf.h \ + maxincl.h myalloc.h nobitfield.h nopp.h \ + nparams.h numsize.h parbufsize.h pathlength.h predefine.h \ + proc_intf.h strsize.h target_sizes.h textsize.h use_tmp.h \ + bufsiz.h str_params.h spec_arith.h + +# Other generated files, for 'make clean' only +GENERATED = tab tokenfile.g Lpars.h LLfiles LL.output lint.out \ + print Xref lxref hfiles cfiles + +# include files containing ALLOCDEF specifications +NEXTFILES = code.h declarator.h decspecs.h def.h expr.h field.h \ + idf.h macro.h stack.h struct.h switch.h type.h + +all: cc + +cc: + make hfiles + make LLfiles + make main + +cem: cem.c string.o + $(CC) -O cem.c string.o -o cem + +lint.cem: cem.c string.c + lint -abx cem.c + +hfiles: Parameters + ./make.hfiles Parameters + @touch hfiles + +LLfiles: $(LSRC) + $(GEN) $(GENOPTIONS) $(LSRC) + @touch LLfiles + +tokenfile.g: tokenname.c make.tokfile + tokenfile.g + +symbol2str.c: tokenname.c make.tokcase + symbol2str.c + +char.c: tab char.tab + tab -fchar.tab >char.c + +next.c: make.next $(NEXTFILES) + ./make.next $(NEXTFILES) >next.c + +writeem.c: make.emfun emcode.def + ./make.emfun emcode.def >writeem.c + +writeem.h: make.emmac emcode.def + ./make.emmac emcode.def >writeem.h + +# Objects needed for 'main' +OBJ = $(COBJ) $(LOBJ) $(GOBJ) + +main: $(OBJ) Makefile + $(CC) $(COPTIONS) $(LFLAGS) $(OBJ) -o main + size main + +cfiles: hfiles LLfiles $(GSRC) + @touch cfiles + +install: main cem + cp main $(CEMCOM) + cp cem $(DRIVER) + +print: files + pr `cat files` > print + +tags: cfiles + ctags `sources $(OBJ)` + +shar: files + shar `cat files` + +listcfiles: + @echo `sources $(OBJ)` + +listobjects: + @echo $(OBJ) + +depend: cfiles + sed '/^#AUTOAUTO/,$$d' Makefile >Makefile.new + echo '#AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO' >>Makefile.new + /user1/erikb/bin/mkdep `sources $(OBJ)` | \ + sed 's/\.c:/.o:/' >>Makefile.new + mv Makefile Makefile.old + mv Makefile.new Makefile + +xref: + ctags -x `grep "\.[ch]" files`|sed "s/).*/)/">Xref + +lxref: + lxref $(OBJ) -lc >lxref + +lint: lint.main lint.cem lint.tab + +lint.main: cfiles + lint -DNORCSID -bx $(CDEFS) `sources $(OBJ)` >lint.out + +cchk: + cchk `sources $(COBJ)` + +clean: + rm -f `sources $(LOBJ)` $(OBJ) $(GENERATED) $(GSRC) $(GHSRC) + +tab: + $(CC) tab.c -o tab + +lint.tab: + lint -abx tab.c + +sim: cfiles + $(SIM) $(SIMFLAGS) `sources $(COBJ)` $(GSRC) $(LSRC) + +#AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO +main.o: LLlex.h Lpars.h alloc.h arith.h bufsiz.h debug.h declarator.h idf.h input.h inputtype.h level.h maxincl.h myalloc.h nobitfield.h nopp.h spec_arith.h specials.h system.h target_sizes.h tokenname.h type.h use_tmp.h +idf.o: LLlex.h Lpars.h align.h alloc.h arith.h assert.h botch_free.h debug.h declarator.h decspecs.h def.h idf.h idfsize.h label.h level.h nobitfield.h nopp.h sizes.h spec_arith.h specials.h stack.h storage.h struct.h type.h +declarator.o: Lpars.h alloc.h arith.h botch_free.h declarator.h expr.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h type.h +decspecs.o: Lpars.h arith.h decspecs.h def.h level.h nobitfield.h spec_arith.h type.h +struct.o: LLlex.h Lpars.h align.h arith.h assert.h botch_free.h debug.h def.h field.h idf.h level.h nobitfield.h nopp.h sizes.h spec_arith.h stack.h storage.h struct.h type.h +expr.o: LLlex.h Lpars.h alloc.h arith.h botch_free.h declarator.h decspecs.h def.h expr.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h type.h +ch7.o: Lpars.h arith.h assert.h debug.h def.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h struct.h type.h +ch7bin.o: Lpars.h arith.h botch_free.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h storage.h struct.h type.h +cstoper.o: Lpars.h arith.h expr.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h target_sizes.h type.h +arith.o: Lpars.h alloc.h arith.h botch_free.h expr.h field.h idf.h label.h mes.h nobitfield.h nopp.h spec_arith.h storage.h type.h +alloc.o: alloc.h assert.h debug.h myalloc.h system.h +code.o: LLlex.h Lpars.h alloc.h arith.h assert.h atw.h botch_free.h code.h dataflow.h debug.h declarator.h decspecs.h def.h em.h expr.h idf.h label.h level.h mes.h nobitfield.h nopp.h proc_intf.h sizes.h spec_arith.h specials.h stack.h storage.h type.h use_tmp.h writeem.h +dumpidf.o: Lpars.h arith.h debug.h def.h expr.h field.h idf.h label.h nobitfield.h nopp.h spec_arith.h stack.h struct.h type.h +error.o: LLlex.h arith.h debug.h em.h errout.h expr.h label.h nopp.h proc_intf.h spec_arith.h string.h system.h tokenname.h use_tmp.h writeem.h +field.o: Lpars.h arith.h assert.h code.h debug.h em.h expr.h field.h idf.h label.h nobitfield.h nopp.h proc_intf.h sizes.h spec_arith.h type.h writeem.h +tokenname.o: LLlex.h Lpars.h arith.h idf.h nopp.h spec_arith.h tokenname.h +LLlex.o: LLlex.h Lpars.h alloc.h arith.h assert.h class.h debug.h def.h idf.h idfsize.h input.h nopp.h numsize.h sizes.h spec_arith.h strsize.h +LLmessage.o: LLlex.h Lpars.h alloc.h arith.h idf.h nopp.h spec_arith.h +input.o: LLlex.h alloc.h arith.h assert.h bufsiz.h debug.h idepth.h input.h inputtype.h interface.h nopp.h pathlength.h spec_arith.h system.h +domacro.o: LLlex.h Lpars.h alloc.h arith.h assert.h botch_free.h class.h debug.h idf.h idfsize.h ifdepth.h input.h interface.h macro.h nopp.h nparams.h parbufsize.h spec_arith.h storage.h textsize.h +replace.o: LLlex.h alloc.h arith.h assert.h class.h debug.h idf.h input.h interface.h macro.h nopp.h pathlength.h spec_arith.h string.h strsize.h +init.o: alloc.h class.h idf.h interface.h macro.h nopp.h predefine.h string.h system.h +options.o: align.h arith.h class.h idf.h idfsize.h macro.h maxincl.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h +scan.o: class.h idf.h input.h interface.h lapbuf.h macro.h nopp.h nparams.h +skip.o: LLlex.h arith.h class.h input.h interface.h nopp.h spec_arith.h +stack.o: Lpars.h alloc.h arith.h botch_free.h debug.h def.h em.h idf.h level.h mes.h nobitfield.h nopp.h proc_intf.h spec_arith.h stack.h storage.h struct.h system.h type.h use_tmp.h writeem.h +type.o: Lpars.h align.h alloc.h arith.h def.h idf.h nobitfield.h nopp.h sizes.h spec_arith.h type.h +ch7mon.o: Lpars.h arith.h botch_free.h def.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h storage.h type.h +label.o: Lpars.h arith.h def.h idf.h label.h level.h nobitfield.h nopp.h spec_arith.h type.h +eval.o: Lpars.h align.h arith.h assert.h atw.h code.h dataflow.h debug.h def.h em.h expr.h idf.h label.h level.h mes.h nobitfield.h nopp.h proc_intf.h sizes.h spec_arith.h stack.h string.h type.h writeem.h +switch.o: arith.h assert.h botch_free.h code.h debug.h density.h em.h expr.h idf.h label.h nobitfield.h nopp.h proc_intf.h spec_arith.h storage.h switch.h type.h writeem.h +storage.o: alloc.h assert.h botch_free.h debug.h storage.h +ival.o: Lpars.h align.h arith.h assert.h class.h debug.h def.h em.h expr.h field.h idf.h label.h level.h nobitfield.h nopp.h proc_intf.h sizes.h spec_arith.h string.h struct.h type.h writeem.h +conversion.o: Lpars.h arith.h em.h nobitfield.h proc_intf.h sizes.h spec_arith.h type.h writeem.h +em.o: arith.h bufsiz.h em.h label.h proc_intf.h spec_arith.h system.h writeem.h +blocks.o: arith.h atw.h em.h proc_intf.h sizes.h spec_arith.h writeem.h +dataflow.o: dataflow.h +system.o: inputtype.h system.h +string.o: arith.h nopp.h spec_arith.h str_params.h string.h system.h +tokenfile.o: Lpars.h +declar.o: LLlex.h Lpars.h arith.h debug.h declarator.h decspecs.h def.h expr.h field.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h struct.h type.h +statement.o: LLlex.h Lpars.h arith.h botch_free.h code.h debug.h def.h em.h expr.h idf.h label.h nobitfield.h nopp.h proc_intf.h spec_arith.h stack.h storage.h type.h writeem.h +expression.o: LLlex.h Lpars.h arith.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h type.h +program.o: LLlex.h Lpars.h alloc.h arith.h code.h declarator.h decspecs.h def.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h type.h +Lpars.o: Lpars.h +char.o: class.h +symbol2str.o: Lpars.h +writeem.o: arith.h em.h label.h proc_intf.h spec_arith.h writeem.h diff --git a/lang/cem/cemcom/Parameters b/lang/cem/cemcom/Parameters new file mode 100644 index 00000000..f0757da2 --- /dev/null +++ b/lang/cem/cemcom/Parameters @@ -0,0 +1,144 @@ +!File: myalloc.h +#define OWNALLOC 1 /* use own superfast allocation */ +#define ALLOCSIZ 4096 /* allocate pieces of 4K */ +#define ALIGNSIZE 8 /* needed for alloc.c */ + + +!File: pathlength.h +#define PATHLENGTH 1024 /* max. length of path to file */ + + +!File: idepth.h +#define IDEPTH 20 /* maximum nr of stacked input buffers */ + + +!File: errout.h +#define ERROUT stderr /* file pointer for writing messages */ +#define MAXERR_LINE 5 /* maximum number of error messages given + on the same input line. */ + + +!File: idfsize.h +#define IDFSIZE 30 /* maximum significant length of an identifier */ + + +!File: numsize.h +#define NUMSIZE 256 /* maximum length of a numeric constant */ + + +!File: nparams.h +#define NPARAMS 32 /* maximum number of parameters of macros */ + + +!File: ifdepth.h +#define IFDEPTH 256 /* maximum number of nested if-constructions */ + + +!File: maxincl.h +#define MAXINCL 8 /* maximum number of #include directories */ + + +!File: density.h +#define DENSITY 2 /* see switch.[ch] for an explanation */ + + +!File: predefine.h +#define PREDEFINE "vax,VAX,BSD4_1,bsd4_1" + + +!File: lapbuf.h +#define LAPBUF 4096 /* size of macro actual parameter buffer */ + + +!File: strsize.h +#define ISTRSIZE 32 /* minimum number of bytes allocated for + storing a string */ +#define RSTRSIZE 8 /* step size in enlarging the memory for + the storage of a string */ + + +!File: target_sizes.h +#define MAXSIZE 8 /* the maximum of the SZ_* constants */ + +/* target machine sizes */ +#define SZ_CHAR (arith)1 +#define SZ_SHORT (arith)2 +#define SZ_WORD (arith)4 +#define SZ_INT (arith)4 +#define SZ_LONG (arith)4 +#define SZ_FLOAT (arith)4 +#define SZ_DOUBLE (arith)8 +#define SZ_POINTER (arith)4 + +/* target machine alignment requirements */ +#define AL_CHAR 1 +#define AL_SHORT SZ_SHORT +#define AL_WORD SZ_WORD +#define AL_INT SZ_WORD +#define AL_LONG SZ_WORD +#define AL_FLOAT SZ_WORD +#define AL_DOUBLE SZ_WORD +#define AL_POINTER SZ_WORD +#define AL_STRUCT 1 +#define AL_UNION 1 + + +!File: botch_free.h +#undef BOTCH_FREE 1 /* botch freed memory, as a check */ + + +!File: dataflow.h +#define DATAFLOW 1 /* produce some compile-time xref */ + + +!File: debug.h +#define DEBUG 1 /* perform various self-tests */ + + +!File: proc_intf.h +#define PROC_INTF 1 /* compile with procedural EM interface */ + + +!File: use_tmp.h +#define USE_TMP 1 /* collect exa, exp, ina and inp commands + and let them precede the rest of + the generated compact code */ + + +!File: parbufsize.h +#define PARBUFSIZE 1024 + + +!File: textsize.h +#define ITEXTSIZE 8 /* 1st piece of memory for repl. text */ +#define RTEXTSIZE 8 /* stepsize for enlarging repl.text */ + + +!File: inputtype.h +#undef READ_IN_ONE 1 /* read input file in one */ + + +!File: nopp.h +#undef NOPP 1 /* use built-int preprocessor */ + + +!File: nobitfield.h +#undef NOBITFIELD 1 /* implement bitfields */ + + +!File: str_params.h +/* maximum number of characters in string representation of (unsigned) long +*/ +#define MAXWIDTH 32 + +#define SSIZE 1024 /* string-buffer size for print routines */ + + +!File: bufsiz.h +#define BUFSIZ 1024 /* system block size */ + + +!File: spec_arith.h +/* describes internal compiler arithmetics */ +#undef SPECIAL_ARITHMETICS /* something different from native long */ + diff --git a/lang/cem/cemcom/align.h b/lang/cem/cemcom/align.h new file mode 100644 index 00000000..b0be9d44 --- /dev/null +++ b/lang/cem/cemcom/align.h @@ -0,0 +1,9 @@ +/* $Header$ */ +/* A L I G N M E N T D E F I N I T I O N S */ + +extern int + short_align, word_align, int_align, long_align, + float_align, double_align, pointer_align, + struct_align, union_align; + +extern arith align(); diff --git a/lang/cem/cemcom/alloc.c b/lang/cem/cemcom/alloc.c new file mode 100644 index 00000000..064c2f09 --- /dev/null +++ b/lang/cem/cemcom/alloc.c @@ -0,0 +1,161 @@ +/* $Header$ */ +/* M E M O R Y A L L O C A T I O N R O U T I N E S */ + +/* The allocation of memory in this program, which plays an important + role in reading files, replacing macros and building expression + trees, is not performed by malloc etc. The reason for having own + memory allocation routines (malloc(), realloc() and free()) is + plain: the garbage collection performed by the library functions + malloc(), realloc() and free() costs a lot of time, while in most + cases (on a VAX) the freeing and reallocation of memory is not + necessary. The only reallocation done in this program is at + building strings in memory. This means that the last + (re-)allocated piece of memory can be extended. + + The (basic) memory allocating routines offered by this memory + handling package are: + + char *malloc(n) : allocate n bytes + char *realloc(ptr, n) : reallocate buffer to n bytes + (works only if ptr was last allocated) + free(ptr) : if ptr points to last allocated + memory, this memory is re-allocatable + Salloc(str, sz) : save string in malloc storage +*/ + +#include "myalloc.h" /* UF */ +#include "debug.h" /* UF */ + +#include "alloc.h" +#include "assert.h" +#include "system.h" + +#ifdef OWNALLOC + +#define SBRK_ERROR ((char *) -1) /* errors during allocation */ + +/* the following variables are used for book-keeping */ +static int nfreebytes = 0; /* # free bytes in sys_sbrk-ed space */ +static char *freeb; /* pointer to first free byte */ +static char *lastalloc; /* pointer to last malloced sp */ +static int lastnbytes; /* nr of bytes in last allocated */ + /* space */ +static char *firstfreeb = 0; + +#endif OWNALLOC + +char * +Salloc(str, sz) + register char str[]; + register int sz; +{ + /* Salloc() is not a primitive function: it just allocates a + piece of storage and copies a given string into it. + */ + char *res = Malloc(sz); + register char *m = res; + + while (sz--) + *m++ = *str++; + return res; +} + +#ifdef OWNALLOC + +#define ALIGN(m) (ALIGNSIZE * (((m) - 1) / ALIGNSIZE + 1)) + +char * +malloc(n) + unsigned n; +{ + /* malloc() is a very simple malloc(). + */ + n = ALIGN(n); + if (nfreebytes < n) { + register nbts = (n <= ALLOCSIZ) ? ALLOCSIZ : n; + + if (!nfreebytes) { + if ((freeb = sys_sbrk(nbts)) == SBRK_ERROR) + fatal("out of memory"); + } + else { + if (sys_sbrk(nbts) == SBRK_ERROR) + fatal("out of memory"); + } + nfreebytes += nbts; + } + lastalloc = freeb; + freeb = lastalloc + n; + lastnbytes = n; + nfreebytes -= n; + return lastalloc; +} + +/*ARGSUSED*/ +char * +realloc(ptr, n) + char *ptr; + unsigned n; +{ + /* realloc() is designed to append more bytes to the latest + allocated piece of memory. However reallocation should be + performed, even if the mentioned memory is not the latest + allocated one, this situation will not occur. To do so, + realloc should know how many bytes are allocated the last + time for that piece of memory. ???? + */ + register int nbytes = n; + + ASSERT(ptr == lastalloc); /* security */ + nbytes -= lastnbytes; /* # bytes required */ + if (nbytes == 0) /* no extra bytes */ + return lastalloc; + + /* if nbytes < 0: free last allocated bytes; + if nbytes > 0: allocate more bytes + */ + if (nbytes > 0) + nbytes = ALIGN(nbytes); + if (nfreebytes < nbytes) { + register int nbts = (nbytes < ALLOCSIZ) ? ALLOCSIZ : nbytes; + if (sys_sbrk(nbts) == SBRK_ERROR) + fatal("out of memory"); + nfreebytes += nbts; + } + freeb += nbytes; /* less bytes */ + lastnbytes += nbytes; /* change nr of last all. bytes */ + nfreebytes -= nbytes; /* less or more free bytes */ + return lastalloc; +} + +/* to ensure that the alloc library package will not be loaded: */ +/*ARGSUSED*/ +free(p) + char *p; +{} + +init_mem() +{ + firstfreeb = sys_sbrk(0); + /* align the first memory unit to ALIGNSIZE ??? */ + if ((long) firstfreeb % ALIGNSIZE != 0) { + register char *fb = firstfreeb; + + fb = (char *)ALIGN((long)fb); + firstfreeb = sys_sbrk(fb - firstfreeb); + firstfreeb = fb; + ASSERT((long)firstfreeb % ALIGNSIZE == 0); + } +} + +#ifdef DEBUG +mem_stat() +{ + extern char options[]; + + if (options['m']) + printf("Total nr of bytes allocated: %d\n", + sys_sbrk(0) - firstfreeb); +} +#endif DEBUG +#endif OWNALLOC diff --git a/lang/cem/cemcom/alloc.h b/lang/cem/cemcom/alloc.h new file mode 100644 index 00000000..a6bafae4 --- /dev/null +++ b/lang/cem/cemcom/alloc.h @@ -0,0 +1,16 @@ +/* $Header$ */ +/* PROGRAM'S INTERFACE TO MEMORY ALLOCATION ROUTINES */ + +/* This file serves as the interface between the program and the + memory allocating routines. + There are 3 memory allocation routines: + char *Malloc(n) to allocate n bytes + char *Salloc(str, n) to allocate n bytes + and fill them with string str + char *Realloc(str, n) reallocate the string at str to n bytes +*/ + +extern char *Salloc(), *malloc(), *realloc(); + +#define Malloc(n) malloc((unsigned)(n)) +#define Srealloc(ptr,n) realloc(ptr, (unsigned)(n)) diff --git a/lang/cem/cemcom/arith.c b/lang/cem/cemcom/arith.c new file mode 100644 index 00000000..04f843a2 --- /dev/null +++ b/lang/cem/cemcom/arith.c @@ -0,0 +1,465 @@ +/* $Header$ */ +/* A R I T H M E T I C C O N V E R S I O N S */ + +/* This file contains the routines for the various conversions that + may befall operands in C. It is structurally a mess, but I haven't + decided yet whether I can't find the right structure or the + semantics of C is a mess. +*/ + +#include "botch_free.h" +#include "nobitfield.h" +#include "alloc.h" +#include "idf.h" +#include "arith.h" +#include "type.h" +#include "label.h" +#include "expr.h" +#include "Lpars.h" +#include "storage.h" +#include "field.h" +#include "mes.h" + +extern char *symbol2str(); +extern char options[]; + +int +arithbalance(e1p, oper, e2p) /* RM 6.6 */ + struct expr **e1p, **e2p; +{ + /* The expressions *e1p and *e2p are balanced to be operands + of the arithmetic operator oper. + */ + register int t1, t2, u1, u2; + + t1 = any2arith(e1p, oper); + t2 = any2arith(e2p, oper); + + /* Now t1 and t2 are either INT or LONG or DOUBLE */ + if (t1 == DOUBLE && t2 != DOUBLE) + t2 = int2float(e2p, double_type); + else + if (t2 == DOUBLE && t1 != DOUBLE) + t1 = int2float(e1p, double_type); + else + if (t1 == DOUBLE) + return DOUBLE; + + /* Now they are INT or LONG */ + u1 = (*e1p)->ex_type->tp_unsigned; + u2 = (*e2p)->ex_type->tp_unsigned; + + /* if either is long, the other will be */ + if (t1 == LONG && t2 != LONG) + t2 = int2int(e2p, u2 ? ulong_type : long_type); + else + if (t2 == LONG && t1 != LONG) + t1 = int2int(e1p, u1 ? ulong_type : long_type); + + /* if either is unsigned, the other will be */ + if (u1 && !u2) + t2 = int2int(e2p, (t1 == LONG) ? ulong_type : uint_type); + else + if (!u1 && u2) + t1 = int2int(e1p, (t2 == LONG) ? ulong_type : uint_type); + + return t1; +} + +relbalance(e1p, oper, e2p) + register struct expr **e1p, **e2p; +{ + /* The expressions *e1p and *e2p are balanced to be operands + of the relational operator oper. + */ + if ((*e1p)->ex_type->tp_fund == FUNCTION) + function2pointer(e1p); + if ((*e2p)->ex_type->tp_fund == FUNCTION) + function2pointer(e2p); + if ((*e1p)->ex_type->tp_fund == POINTER) + ch76pointer(e2p, oper, (*e1p)->ex_type); + else + if ((*e2p)->ex_type->tp_fund == POINTER) + ch76pointer(e1p, oper, (*e2p)->ex_type); + else + if ( (*e1p)->ex_type == (*e2p)->ex_type && + (*e1p)->ex_type->tp_fund == ENUM + ) + {} + else + arithbalance(e1p, oper, e2p); +} + +ch76pointer(expp, oper, tp) + register struct expr **expp; + register struct type *tp; +{ + /* Checks whether *expp may be compared to tp using oper, + as described in chapter 7.6 and 7.7. + tp is known to be a pointer. + */ + if ((*expp)->ex_type->tp_fund == POINTER) { + if ((*expp)->ex_type != tp) + ch7cast(expp, oper, tp); + } + else + if ( is_integral_type((*expp)->ex_type) && + ( !options['R'] /* we don't care */ || + (oper == EQUAL || oper == NOTEQUAL || oper == ':') + ) + ) /* ch 7.7 */ + ch7cast(expp, CAST, tp); + else { + if ((*expp)->ex_type != error_type) + error("%s on %s and pointer", + symbol2str(oper), + symbol2str((*expp)->ex_type->tp_fund) + ); + (*expp)->ex_type = error_type; + ch7cast(expp, oper, tp); + } +} + +int +any2arith(expp, oper) + register struct expr **expp; +{ + /* Turns any expression into int_type, long_type or + double_type. + */ + int fund = (*expp)->ex_type->tp_fund; + + switch (fund) { + case CHAR: + case SHORT: + int2int(expp, + (*expp)->ex_type->tp_unsigned ? uint_type : int_type); + break; + case INT: + case LONG: + break; + case ENUM: + if ( is_test_op(oper) || oper == '=' || oper == PARCOMMA || + oper == ',' || oper == ':' || + ( !options['R'] && + (is_arith_op(oper) || is_asgn_op(oper)) + ) + ) + {} + else + warning("%s on enum", symbol2str(oper)); + int2int(expp, int_type); + break; + case FLOAT: + float2float(expp, double_type); + break; + case DOUBLE: + break; +#ifndef NOBITFIELD + case FIELD: + field2arith(expp); + break; +#endif NOBITFIELD + default: + error("operator %s on non-numerical operand (%s)", + symbol2str(oper), symbol2str(fund)); + case ERRONEOUS: + free_expression(*expp); + *expp = intexpr((arith)1, INT); + break; + } + + return (*expp)->ex_type->tp_fund; +} + +struct expr * +arith2arith(tp, oper, expr) + struct type *tp; + int oper; + struct expr *expr; +{ + /* arith2arith constructs a new expression containing a + run-time conversion between some arithmetic types. + */ + register struct expr *new = new_expr(); + + clear((char *)new, sizeof(struct expr)); + new->ex_file = expr->ex_file; + new->ex_line = expr->ex_line; + new->ex_type = tp; + new->ex_class = Type; + return new_oper(tp, new, oper, expr); +} + +int +int2int(expp, tp) + register struct expr **expp; + struct type *tp; +{ + /* The expression *expp, which is of some integral type, is + converted to the integral type tp. + */ + + if (is_cp_cst(*expp)) { + (*expp)->ex_type = tp; + cut_size(*expp); + } + else { + *expp = arith2arith(tp, INT2INT, *expp); + } + return (*expp)->ex_type->tp_fund; +} + +int +int2float(expp, tp) + struct expr **expp; + struct type *tp; +{ + /* The expression *expp, which is of some integral type, is + converted to the floating type tp. + */ + + fp_used = 1; + *expp = arith2arith(tp, INT2FLOAT, *expp); + return (*expp)->ex_type->tp_fund; +} + +float2int(expp, tp) + struct expr **expp; + struct type *tp; +{ + /* The expression *expp, which is of some floating type, is + converted to the integral type tp. + */ + + fp_used = 1; + *expp = arith2arith(tp, FLOAT2INT, *expp); +} + +float2float(expp, tp) + struct expr **expp; + struct type *tp; +{ + /* The expression *expp, which is of some floating type, is + converted to the floating type tp. + There is no need for an explicit conversion operator + if the expression is a constant. + */ + + fp_used = 1; + if ((*expp)->ex_class == Float) { + (*expp)->ex_type = tp; + } + else { + *expp = arith2arith(tp, FLOAT2FLOAT, *expp); + } +} + +array2pointer(expp) + struct expr **expp; +{ + /* The expression, which must be an array, it is converted + to a pointer. + */ + (*expp)->ex_type = + construct_type(POINTER, (*expp)->ex_type->tp_up, (arith)0); +} + +function2pointer(expp) + struct expr **expp; +{ + /* The expression, which must be a function, it is converted + to a pointer to the function. + */ + (*expp)->ex_type = + construct_type(POINTER, (*expp)->ex_type, (arith)0); +} + +opnd2integral(expp, oper) + struct expr **expp; + int oper; +{ + register int fund = (*expp)->ex_type->tp_fund; + + if (fund != INT && fund != LONG) { + if (fund != ERRONEOUS) + error("%s operand to %s", + symbol2str(fund), symbol2str(oper)); + *expp = intexpr((arith)1, INT); + /* fund = INT; */ + } +} + +opnd2logical(expp, oper) + struct expr **expp; + int oper; +{ + register int fund; + + if ((*expp)->ex_type->tp_fund == FUNCTION) + function2pointer(expp); +#ifndef NOBITFIELD + else + if ((*expp)->ex_type->tp_fund == FIELD) + field2arith(expp); +#endif NOBITFIELD + + fund = (*expp)->ex_type->tp_fund; + + switch (fund) { + + case CHAR: + case SHORT: + case INT: + case LONG: + case ENUM: + case POINTER: + case FLOAT: + case DOUBLE: + break; + default: + error("%s operand to %s", + symbol2str(fund), symbol2str(oper)); + case ERRONEOUS: + *expp = intexpr((arith)1, INT); + break; + } +} + +opnd2test(expp, oper) + struct expr **expp; +{ + opnd2logical(expp, oper); + if ((*expp)->ex_class == Oper && is_test_op((*expp)->OP_OPER)) + { /* It is already a test */ } + else + ch7bin(expp, NOTEQUAL, intexpr((arith)0, INT)); +} + +int +is_test_op(oper) +{ + switch (oper) { + case '<': + case '>': + case LESSEQ: + case GREATEREQ: + case EQUAL: + case NOTEQUAL: + case '!': + case AND: + case OR: /* && and || also impose a test */ + return 1; + default: + return 0; + } + /*NOTREACHED*/ +} + +int +is_arith_op(oper) +{ + switch (oper) { + case '*': + case '/': + case '%': + case '+': + case '-': + case LEFT: + case RIGHT: + case '&': + case '^': + case '|': + return 1; + default: + return 0; + } +} + +int +is_asgn_op(oper) +{ + switch (oper) { + case '=': + case PLUSAB: + case MINAB: + case TIMESAB: + case DIVAB: + case MODAB: + case LEFTAB: + case RIGHTAB: + case ANDAB: + case ORAB: + case XORAB: + return 1; + default: + return 0; + } +} + +any2opnd(expp, oper) + struct expr **expp; +{ + if (!*expp) + return; + switch ((*expp)->ex_type->tp_fund) { /* RM 7.1 */ + case CHAR: + case SHORT: + case ENUM: + case FLOAT: + any2arith(expp, oper); + break; + case ARRAY: + array2pointer(expp); + break; +#ifndef NOBITFIELD + case FIELD: + field2arith(expp); + break; +#endif NOBITFIELD + } +} + +#ifndef NOBITFIELD +field2arith(expp) + struct expr **expp; +{ + /* The expression to extract the bitfield value from the + memory word is put in the tree. + */ + register struct type *tp = (*expp)->ex_type->tp_up; + register struct field *fd = (*expp)->ex_type->tp_field; + register struct type *atype = tp->tp_unsigned ? uword_type : word_type; + + (*expp)->ex_type = atype; + + if (atype->tp_unsigned) { /* don't worry about the sign bit */ + ch7bin(expp, RIGHT, intexpr((arith)fd->fd_shift, INT)); + ch7bin(expp, '&', intexpr(fd->fd_mask, INT)); + } + else { /* take care of the sign bit: sign extend if needed */ + register arith bits_in_type = atype->tp_size * 8; + + ch7bin(expp, LEFT, + intexpr(bits_in_type - fd->fd_width - fd->fd_shift, INT) + ); + ch7bin(expp, RIGHT, intexpr(bits_in_type - fd->fd_width, INT)); + } + ch7cast(expp, CAST, tp); /* restore its original type */ +} +#endif NOBITFIELD + +/* switch_sign_fp() negates the given floating constant expression + The lexical analyser has reserved an extra byte of space in front + of the string containing the representation of the floating + constant. This byte contains the '-' character and we have to + take care of the first byte the fl_value pointer points to. +*/ +switch_sign_fp(expr) + struct expr *expr; +{ + if (*(expr->FL_VALUE) == '-') + ++(expr->FL_VALUE); + else + --(expr->FL_VALUE); +} diff --git a/lang/cem/cemcom/arith.h b/lang/cem/cemcom/arith.h new file mode 100644 index 00000000..551f7c90 --- /dev/null +++ b/lang/cem/cemcom/arith.h @@ -0,0 +1,23 @@ +/* $Header$ */ +/* COMPILER ARITHMETIC */ + +/* Normally the compiler does its internal arithmetics in longs + native to the source machine, which is always good for local + compilations, and generally OK too for cross compilations + downwards and sidewards. For upwards cross compilation and + to save storage on small machines, SPECIAL_ARITHMETICS will + be handy. +*/ + +#include "spec_arith.h" + +#ifndef SPECIAL_ARITHMETICS + +#define arith long /* native */ + +#else SPECIAL_ARITHMETICS + +/* not implemented yet */ +#define arith int /* dummy */ + +#endif SPECIAL_ARITHMETICS diff --git a/lang/cem/cemcom/asm.c b/lang/cem/cemcom/asm.c new file mode 100644 index 00000000..21daf1f5 --- /dev/null +++ b/lang/cem/cemcom/asm.c @@ -0,0 +1,10 @@ +/* $Header$ */ +/* A S M */ + +asm_seen(s) + char *s; +{ + /* 'asm' '(' string ')' ';' + */ + warning("\"asm(\"%s\")\" instruction skipped", s); +} diff --git a/lang/cem/cemcom/assert.h b/lang/cem/cemcom/assert.h new file mode 100644 index 00000000..6afd202f --- /dev/null +++ b/lang/cem/cemcom/assert.h @@ -0,0 +1,17 @@ +/* $Header$ */ +/* A S S E R T I O N M A C R O D E F I N I T I O N */ + +/* At some points in the program, it must be sure that some condition + holds true, due to further, successful, processing. As long as + there is no reasonable method to prove that a program is 100% + correct, these assertions are needed in some places. +*/ +#include "debug.h" /* UF */ + +#ifdef DEBUG +/* Note: this macro uses parameter substitution inside strings */ +#define ASSERT(exp) (exp || crash("in %s, %u: assertion %s failed", \ + __FILE__, __LINE__, "exp")) +#else +#define ASSERT(exp) +#endif DEBUG diff --git a/lang/cem/cemcom/atw.h b/lang/cem/cemcom/atw.h new file mode 100644 index 00000000..6dc02ee5 --- /dev/null +++ b/lang/cem/cemcom/atw.h @@ -0,0 +1,6 @@ +/* $Header$ */ +/* Align To Word boundary Definition */ + +extern int word_align; /* align of a word */ + +#define ATW(arg) ((((arg) + word_align - 1) / word_align) * word_align) diff --git a/lang/cem/cemcom/blocks.c b/lang/cem/cemcom/blocks.c new file mode 100644 index 00000000..799402e9 --- /dev/null +++ b/lang/cem/cemcom/blocks.c @@ -0,0 +1,88 @@ +/* $Header$ */ +/* B L O C K S T O R I N G A N D L O A D I N G */ + +#include "em.h" +#include "arith.h" +#include "sizes.h" +#include "atw.h" + +/* Because EM does not support the loading and storing of + objects having other sizes than word fragment and multiple, + we need to have a way of transferring these objects, whereby + we simulate "loi" and "sti": the address of the source resp. + destination is located on top of stack and a call is done + to load_block() resp. store_block(). + =============================================================== + # Loadblock() works on the stack as follows: ([ ] indicates the + # position of the stackpointer) + # lower address---> + # 1) | &object + # 2) | ... ATW(sz) bytes ... | sz | &stack_block | &object + # 3) | ... ATW(sz) bytes ... + =============================================================== + Loadblock() pushes ATW(sz) bytes directly onto the stack! + + Store_block() works on the stack as follows: + lower address---> + 1) | ... ATW(sz) bytes ... | &object + 2) | ... ATW(sz) bytes ... | &object | &stack_block | sz + 3) + + If sz is a legal argument for "loi" or "sti", just one EM + instruction is generated. + In the other cases, the notion of alignment is taken into account: + we only push an object of the size accepted by EM onto the stack, + while we need a loop to store the stack block into a memory object. +*/ +store_block(sz, al) + arith sz; + int al; +{ + /* Next condition contains Lots of Irritating Stupid Parentheses + */ + if ( + ((sz == al) && (word_align % al == 0)) || + ( + (sz % word_size == 0 || word_size % sz == 0) && + (al % word_align == 0) + ) + ) + C_sti(sz); + else { + /* address of destination lies on the stack */ + + /* push address of first byte of block on stack onto + the stack by computing it from the current stack + pointer position + */ + C_lor((arith)1); /* push current sp */ + C_adp(pointer_size); /* set & to 1st byte of block */ + C_loc(sz); /* number of bytes to transfer */ + C_cal("__stb"); /* call transfer routine */ + C_asp(pointer_size + pointer_size + int_size + ATW(sz)); + } +} + +load_block(sz, al) + arith sz; + int al; +{ + arith esz = ATW(sz); /* effective size == actual # pushed bytes */ + + if ((sz == al) && (word_align % al == 0)) + C_loi(sz); + else + if (al % word_align == 0) + C_loi(esz); + else { + /* do not try to understand this... */ + C_asp(-(esz - pointer_size)); /* allocate stack block */ + C_lor((arith)1); /* push & of stack block as dst */ + C_dup(pointer_size); /* fetch source address */ + C_adp(esz - pointer_size); + C_loi(pointer_size); + C_loc(sz); /* # bytes to copy */ + C_cal("__stb"); /* library copy routine */ + C_asp(int_size + pointer_size + pointer_size); + } +} diff --git a/lang/cem/cemcom/cem.1 b/lang/cem/cemcom/cem.1 new file mode 100644 index 00000000..b9162e0b --- /dev/null +++ b/lang/cem/cemcom/cem.1 @@ -0,0 +1,238 @@ +.TH CEM 1 local +.SH NAME +cem \- ACK C compiler +.SH SYNOPSIS +.B cem +[ option ] ... file ... +.SH DESCRIPTION +.I Cem +is a \fIcc\fP(1)-like +C compiler that uses the C front-end compiler \fIcemcom\fP(1) +of the Amsterdam Compiler Kit. +.I Cem +interprets its arguments not starting with a '\-' as +source files, to be compiled by the various parts of the compilation process, +which are listed below. +File arguments whose names end with \fB.\fP\fIcharacter\fP are interpreted as +follows: +.IP .[ao] +object file. +.IP .[ci] +C source code +.IP .e +EM assembler source file. +.IP .k +compact EM file, not yet optimised by the EM peephole optimiser. +.IP .m +compact EM file, already optimised by the peephole optimiser. +.IP .s +assembler file. +.LP +The actions to be taken by +.I cem +are directed by the type of file argument and the various options that are +presented to it. +.PP +The following options, which is a mixture of options interpreted by \fIcc\fP(1) +and \fIack\fP(?), +are interpreted by +.I cem . +(The options not specified here are passed to the front-end +compiler \fIcemcom\fP(1).) +.IP \fB\-B\fP\fIname\fP +Use \fIname\fP as front-end compiler instead of the default \fIcemcom\fP(1). +.br +Same as "\fB\-Rcem=\fP\fIname\fP". +.IP \fB\-C\fP +Run C preprocessor \fI/lib/cpp\fP only and prevent it from eliding comments. +.IP \fB\-D\fP\fIname\fP\fB=\fP\fIdef\fP +Define the \fIname\fP to the preprocessor, as if by "#define". +.IP \fB\-D\fP\fIname\fP +.br +Same as "\fB\-D\fP\fIname\fP\fB=1\fP". +.IP \fB\-E\fP +Run only the macro preprocessor on the named files and send the +result to standard output. +.IP \fB\-I\fP\fIdir\fP +\&"#include" files whose names do not begin with '/' are always +sought first in the directory of the \fIfile\fP argument, then in directories +in \fB\-I\fP options, then in directories on a standard list (which in fact +consists of "/usr/include"). +.IP \fB\-L\fP\fIdir\fP +Use \fIdir\fP as library-containing directory instead of the default. +.IP \fB\-P\fP +Same as \fB\-E\fP, but sending the result of input file \fIfile\fP\fB.[ceis]\fP +to \fIfile\fP\fB.i\fP. +.IP \fB\-R\fP +Passed to \fIcemcom\fP(1) in order to parse the named C programs according +to the C language as described in [K&R] (also called \fIRestricted\fP C). +.IP \fB\-R\fP\fIprog\fP\fB=\fP\fIname\fP +.br +Use \fIname\fP as program for phase \fIprog\fP of the compilation instead of +the default. +\&\fIProg\fP is one of the following names: +.RS +.IP \fBcpp\fP +macro preprocessor (default: /lib/cpp) +.IP \fBcem\fP +front\-end compiler (default: $CEM/bin/cemcom) +.IP \fBopt\fP +EM peephole optimiser (default: $EM/lib/em_opt) +.IP \fBdecode\fP +EM compact to EM assembler translator (default: $EM/lib/em_decode) +.IP \fBencode\fP +EM assembler to EM compact translator (default: $EM/lib/em_encode) +.IP \fBbe\fP +EM compact code to target\-machine assembly code compiler +(default: $EM/lib/vax4/cg) +.IP \fBcg\fP +same as \fBbe\fP +.IP \fBas\fP +assembler (default: /bin/as) +.IP \fBld\fP +linker/loader (default: /bin/ld) +.RE +.IP \fB\-R\fP\fIprog\fP\fB\-\fP\fIoption\fP +.br +Pass \fB\-\fP\fIoption\fP to the compilation phase indicated by \fIprog\fP. +.IP \fB\-S\fP +Same as \fB\-c.s\fP. +.IP \fB\-U\fP\fIname\fP +.br +Remove any initial definition of \fIname\fP. +.IP \fB\-V\fP\fIcm\fP.\fIn\fP,\ \fB\-V\fIcm\fP.\fIncm\fP.\fIn\fP\ ... +.br +Set the size and alignment requirements of the C constructs of the named +C input files. +The letter \fIc\fP indicates the simple type, which is one of +\fBs\fP(short), \fBi\fP(int), \fBl\fP(long), \fBf\fP(float), \fBd\fP(double) or +\fBp\fP(pointer). +The \fIm\fP parameter can be used to specify the length of the type (in bytes) +and the \fIn\fP parameter for the alignment of that type. +Absence of \fIm\fP or \fIn\fP causes the default value to be retained. +To specify that the bitfields should be right adjusted instead of the +default left adjustment, specify \fBr\fP as \fIc\fP parameter +without parameters. +.br +This option is passed directly to \fIcemcom\fP(1). +.IP \fB\-c\fP +Same as \fB\-c.o\fP. +.IP \fB\-c.e\fP +Produce EM assembly code on \fIfile\fP\fB.e\fP for the +named files \fIfile\fP\fB.[cikm]\fP +.IP \fB\-c.k\fP +Compile C source \fIfile\fP\fB.[ci]\fP or +encode EM assembly code from \fIfile\fP\fB.e\fP +into unoptimised compact EM code and write the result on \fIfile\fP\fB.k\fP +.IP \fB\-c.m\fP +Compile C source \fIfile\fP\fB.[ci]\fP, +translate unoptimised EM code from \fIfile\fP\fB.k\fP or +encode EM assembly code from \fIfile\fP\fB.e\fP +into optimised compact EM code and write the result on \fIfile\fP\fB.m\fP +.IP \fB\-c.o\fP +Suppress the loading phase of the compilation, and force an object file to +be produced even if only one program is compiled +.IP \fB\-c.s\fP +Compile the named \fIfile\fP\fB.[ceikm]\fP input files, and leave the +assembly language output on corresponding files suffixed ".s". +.IP \fB\-k\fP +Same as \fB\-c.k\fP. +.IP \fB\-l\fP\fIname\fP +.br +Append the library \fBlib\fP\fIname\fP\fB.a\fP to the list of files that +should be loaded and linked into the final output file. +The library is searched for in the library directory. +.IP \fB\-m\fP +Same as \fB\-c.m\fP. +.IP \fB\-o\fP\ \fIoutput\fP +.br +Name the final output file \fIoutput\fP. +If this option is used, the default "a.out" will be left undisturbed. +.IP \fB\-p\fP +Produce EM profiling code (\fBfil\fP and \fBlin\fP instructions to +enable an interpreter to keep track of the current location in the +source code) +.IP \fB\-t\fP +Keep the intermediate files, produced during the various phases of the +compilation. +The produced files are named \fIfile\fP\fB.\fP\fIcharacter\fP where +\&\fIcharacter\fP indicates the type of the file as listed before. +.IP \fB\-v\fP +Verbose. +Print the commands before they are executed. +.IP \fB\-vn\fP +Do not really execute (for debugging purposes only). +.IP \fB\-vd\fP +Print some additional information (for debugging purposes only). +.IP \fB\-\-\fP\fIanything\f +.br +Equivalent to \fB\-Rcem\-\-\fP\fIanything\fP. +The options +.B \-\-C , +.B \-\-E +and +.B \-\-P +all have the same effect as respectively +.B \-C , +.B \-E +and +.B \-P +except for the fact that the macro preprocessor is taken to be the +built\-in preprocessor of the \fBcem\fP phase. +Most "\-\-" options are used by +.I cemcom (1) +to set some internal debug switches. +.IP loader\ options +.br +The options +.B \-d , +.B \-e , +.B \-F , +.B \-n , +.B \-N , +.B \-r , +.B \-s , +.B \-u , +.B \-x , +.B \-X +and +.B \-z +are directly passed to the loader. +.SH FILES +$CEM/bin/cem: this program +.br +$CEM/src/cem.c: C source of the \fBcem\fP program +.br +$CEM/bin/cemcom: C front end compiler +.br +$CEM/lib: default library-containing directory +.br +$CEM/src/cem.1: this manual page +.br +$CEM/src/cemcom.1: manual page for the C front end compiler +.SH SEE ALSO +cemcom(1), cc(1), ack(?), as(1), ld(1) +.br +.IP [K&R] +B.W. Kernighan and D.M. Ritchie, \fIThe C Programming Language\fP, +Prentice-Hall, 1978. +.SH DIAGNOSTICS +Any failure of one of the phases is reported. +.SH NOTES +.IP \(bu +The names $CEM and $EM refer to the directories containing the CEM compiler +and the ACK distribution tree respectively. +.IP \(bu +This manual page contains references to programs that reside on our site +which is a VAX 11/750 running UNIX BSD4.1. +Setting up \fBcem\fP requires some names to be declared in $CEM/src/cem.c +.SH BUGS +.IP \(bu +All intermediate files are placed in the current working directory which +causes files with the same name as the intermediate files to be overwritten. +.IP \(bu +.B Cem +only accepts a limited number of arguments to be passed to the various phases. +(e.g. 256). +.IP \(bu +Please report suggestions and other bugs to erikb@tjalk.UUCP diff --git a/lang/cem/cemcom/cem.c b/lang/cem/cemcom/cem.c new file mode 100644 index 00000000..5e4c4819 --- /dev/null +++ b/lang/cem/cemcom/cem.c @@ -0,0 +1,744 @@ +/* $Header$ */ +/* + Driver for the CEMCOM compiler: works like /bin/cc and accepts the + options accepted by /bin/cc and /usr/em/bin/ack. + Date written: dec 4, 1985 + Author: Erik Baalbergen +*/ + +#include "string.h" +#include +#include +#include +#include + +#define MAXARGC 256 /* maximum number of arguments allowed in a list */ +#define USTR_SIZE 1024 /* maximum length of string variable */ + +struct arglist { + int al_argc; + char *al_argv[MAXARGC]; +}; + +/* some system-dependent variables */ +char *PP = "/lib/cpp"; +char *CEM = "/user1/erikb/bin/cemcom"; +char *AS_FIX = "/user1/erikb/bin/mcomm"; +char *ENCODE = "/usr/em/lib/em_encode"; +char *DECODE = "/usr/em/lib/em_decode"; +char *OPT = "/usr/em/lib/em_opt"; +char *CG = "/usr/em/lib/vax4/cg"; +char *AS = "/bin/as"; +char *LD = "/bin/ld"; +char *SHELL = "/bin/sh"; + +char *LIBDIR = "/user1/cem/lib"; + +char *V_FLAG = "-Vs2.2w4.4i4.4l4.4f4.4d8.4p4.4"; + +struct arglist LD_HEAD = { + 2, + { + "/usr/em/lib/vax4/head_em", + "/usr/em/lib/vax4/head_cc" + } +}; + +struct arglist LD_TAIL = { + 3, + { + "/user1/cem/lib/stb.o", + "/usr/em/lib/vax4/tail_mon", + "/usr/em/lib/vax4/tail_em" + } +}; + +char *o_FILE = "a.out"; + +#define remove(str) (((t_flag == 0) && unlink(str)), (str)[0] = '\0') +#define cleanup(str) (str && remove(str)) +#define mkname(dst, s1, s2) mkstr(dst, (s1), (s2), 0) +#define init(al) (al)->al_argc = 1 +#define library(nm) \ + mkstr(alloc((unsigned int)strlen(nm) + strlen(LIBDIR) + 7), \ + LIBDIR, "/lib", nm, ".a", 0) + +char *ProgCall = 0; + +struct arglist SRCFILES; +struct arglist LDFILES; +struct arglist GEN_LDFILES; + +struct arglist PP_FLAGS; +struct arglist CEM_FLAGS; + +int debug = 0; +int exec = 1; + +int RET_CODE = 0; + +struct arglist OPT_FLAGS; +struct arglist DECODE_FLAGS; +struct arglist ENCODE_FLAGS; +struct arglist CG_FLAGS; +struct arglist AS_FLAGS; +struct arglist LD_FLAGS; +struct arglist O_FLAGS; +struct arglist DEBUG_FLAGS; + +struct arglist CALL_VEC; + +int e_flag = 0; +int E_flag = 0; +int c_flag = 0; +int k_flag = 0; +int m_flag = 0; +int o_flag = 0; +int S_flag = 0; +int t_flag = 0; +int v_flag = 0; +int P_flag = 0; + +struct prog { + char *p_name; + char **p_task; + struct arglist *p_flags; +} ProgParts[] = { + { "cpp", &PP, &PP_FLAGS }, + { "cem", &CEM, &CEM_FLAGS }, + { "opt", &OPT, &OPT_FLAGS }, + { "decode", &DECODE, &DECODE_FLAGS }, + { "encode", &ENCODE, &ENCODE_FLAGS }, + { "be", &CG, &CG_FLAGS }, + { "cg", &CG, &CG_FLAGS }, + { "as", &AS, &AS_FLAGS }, + { "ld", &LD, &LD_FLAGS }, + { 0, 0, 0 } +}; + +int trap(); +char *mkstr(); +char *alloc(); +long sizeof_file(); + +main(argc, argv) + char *argv[]; +{ + char *str; + char **argvec; + int count; + int ext; + char Nfile[USTR_SIZE]; + char kfile[USTR_SIZE]; + char sfile[USTR_SIZE]; + char mfile[USTR_SIZE]; + char ofile[USTR_SIZE]; + register struct arglist *call = &CALL_VEC; + char BASE[USTR_SIZE]; + char *file; + char *ldfile = 0; + + set_traps(trap); + + ProgCall = *argv++; + + while (--argc > 0) { + if (*(str = *argv++) != '-') { + append(&SRCFILES, str); + continue; + } + + switch (str[1]) { + + case '-': + switch (str[2]) { + case 'C': + case 'E': + case 'P': + E_flag = 1; + append(&PP_FLAGS, str); + PP = CEM; + P_flag = (str[2] == 'P'); + break; + default: + append(&DEBUG_FLAGS, str); + break; + } + break; + + case 'B': + PP = CEM = &str[2]; + break; + case 'C': + case 'E': + case 'P': + E_flag = 1; + append(&PP_FLAGS, str); + P_flag = (str[1] == 'P'); + break; + case 'c': + if (str[2] == '.') { + switch (str[3]) { + + case 's': + S_flag = 1; + break; + case 'k': + k_flag = 1; + break; + case 'o': + c_flag = 1; + break; + case 'm': + m_flag = 1; + break; + case 'e': + e_flag = 1; + break; + default: + bad_option(str); + } + } + else + if (str[2] == '\0') + c_flag = 1; + else + bad_option(str); + break; + case 'D': + case 'I': + case 'U': + append(&PP_FLAGS, str); + break; + case 'k': + k_flag = 1; + break; + case 'l': + if (str[2] == '\0') /* no standard libraries */ + LD_HEAD.al_argc = LD_TAIL.al_argc = 0; + else /* use library from library directory */ + append(&SRCFILES, library(&str[2])); + break; + case 'L': /* change default library directory */ + LIBDIR = &str[2]; + break; + case 'm': + m_flag = 1; + break; + case 'o': + o_flag = 1; + if (argc-- < 0) + bad_option(str); + else + o_FILE = *argv++; + break; + case 'O': + append(&O_FLAGS, "-O"); + break; + case 'p': + append(&CEM_FLAGS, "-p"); + break; + case 'R': + if (str[2] == '\0') + append(&CEM_FLAGS, str); + else + Roption(str); + break; + case 'S': + S_flag = 1; + break; + case 't': + t_flag = 1; + break; + case 'v': /* set debug switches */ + v_flag = 1; + switch (str[2]) { + + case 'd': + debug = 1; + break; + case 'n': /* no execute */ + exec = 0; + break; + } + break; + case 'V': + V_FLAG = str; + break; + case 'e': + case 'F': + case 'd': + case 'n': + case 'N': + case 'r': + case 's': + case 'u': + case 'x': + case 'X': + case 'z': + append(&LD_FLAGS, str); + break; + default: + append(&CEM_FLAGS, str); + } + } + + if (debug) + report("Note: debug output"); + if (exec == 0) + report("Note: no execution"); + + count = SRCFILES.al_argc; + argvec = &(SRCFILES.al_argv[0]); + + Nfile[0] = '\0'; + + while (count-- > 0) { + basename(file = *argvec++, BASE); + + if (E_flag) { + char ifile[USTR_SIZE]; + + init(call); + append(call, PP); + concat(call, &DEBUG_FLAGS); + concat(call, &PP_FLAGS); + append(call, file); + runvec(call, P_flag ? mkname(ifile, BASE, ".i") : 0); + continue; + } + + ext = extension(file); + + /* .c to .k and .N */ + if (ext == 'c' || ext == 'i') { + init(call); + append(call, CEM); + concat(call, &DEBUG_FLAGS); + append(call, V_FLAG); + concat(call, &CEM_FLAGS); + concat(call, &PP_FLAGS); + append(call, file); + append(call, mkname(kfile, BASE, ".k")); + append(call, mkname(Nfile, BASE, ".N")); + + if (runvec(call, (char *)0)) { + file = kfile; + ext = 'k'; + if (sizeof_file(Nfile) <= 0L) + remove(Nfile); + } + else { + remove(kfile); + remove(Nfile); + continue; + } + } + + /* .e to .k */ + if (ext == 'e') { + init(call); + append(call, ENCODE); + concat(call, &ENCODE_FLAGS); + append(call, file); + append(call, mkname(kfile, BASE, ".k")); + if (runvec(call, (char *)0) == 0) + continue; + file = kfile; + ext = 'k'; + } + + if (k_flag) + continue; + + /* decode .k or .m */ + if (e_flag && (ext == 'k' || ext == 'm')) { + char efile[USTR_SIZE]; + + init(call); + append(call, DECODE); + concat(call, &DECODE_FLAGS); + append(call, file); + append(call, mkname(efile, BASE, ".e")); + runvec(call, (char *)0); + cleanup(kfile); + continue; + } + + /* .k to .m */ + if (ext == 'k') { + init(call); + append(call, OPT); + concat(call, &OPT_FLAGS); + append(call, file); + if (runvec(call, mkname(mfile, BASE, ".m")) == 0) + continue; + file = mfile; + ext = 'm'; + cleanup(kfile); + } + + if (m_flag) + continue; + + /* .m to .s */ + if (ext == 'm') { + init(call); + append(call, CG); + concat(call, &CG_FLAGS); + append(call, file); + append(call, mkname(sfile, BASE, ".s")); + if (runvec(call, (char *)0) == 0) + continue; + if (Nfile[0] != '\0') { + init(call); + append(call, AS_FIX); + append(call, Nfile); + append(call, sfile); + runvec(call, (char *)0); + remove(Nfile); + } + cleanup(mfile); + file = sfile; + ext = 's'; + } + + if (S_flag) + continue; + + /* .s to .o */ + if (ext == 's') { + ldfile = c_flag ? + ofile : + alloc((unsigned)strlen(BASE) + 3); + init(call); + append(call, AS); + concat(call, &AS_FLAGS); + append(call, "-o"); + append(call, mkname(ldfile, BASE, ".o")); + append(call, file); + if (runvec(call, (char *)0) == 0) + continue; + file = ldfile; + ext = 'o'; + cleanup(sfile); + } + + if (c_flag) + continue; + + append(&LDFILES, file); + if (ldfile) { + append(&GEN_LDFILES, ldfile); + ldfile = 0; + } + } + + /* *.o to a.out */ + if (RET_CODE == 0 && LDFILES.al_argc > 0) { + init(call); + append(call, LD); + concat(call, &LD_FLAGS); + append(call, "-o"); + append(call, o_FILE); + concat(call, &LD_HEAD); + concat(call, &LDFILES); + append(call, library("c")); + concat(call, &LD_TAIL); + if (runvec(call, (char *)0)) { + register i = GEN_LDFILES.al_argc; + + while (i-- > 0) + remove(GEN_LDFILES.al_argv[i]); + } + } + + exit(RET_CODE); +} + + +char * +alloc(u) + unsigned u; +{ +#define BUFSIZE (USTR_SIZE * MAXARGC) + static char buf[BUFSIZE]; + static char *bufptr = &buf[0]; + register char *p = bufptr; + + if ((bufptr += u) >= &buf[BUFSIZE]) + panic("no space"); + return p; +} + +append(al, arg) + struct arglist *al; + char *arg; +{ + if (al->al_argc >= MAXARGC) + panic("argument list overflow"); + al->al_argv[(al->al_argc)++] = arg; +} + +concat(al1, al2) + struct arglist *al1, *al2; +{ + register i = al2->al_argc; + register char **p = &(al1->al_argv[al1->al_argc]); + register char **q = &(al2->al_argv[0]); + + if ((al1->al_argc += i) >= MAXARGC) + panic("argument list overflow"); + while (i-- > 0) + *p++ = *q++; +} + +/* The next function is a dirty old one, taking a variable number of + arguments. + Take care that the last argument is a null-valued pointer! +*/ +/*VARARGS1*/ +char * +mkstr(dst, arg) + char *dst, *arg; +{ + char **vec = (char **) &arg; + register char *p; + register char *q = dst; + + while (p = *vec++) { + while (*q++ = *p++); + q--; + } + return dst; +} + +Roption(str) + char *str; /* of the form "prog=/-arg" */ +{ + char *eq; + char *prog, *arg; + char bc; + char *cindex(); + + prog = &str[2]; + + if (eq = cindex(prog, '=')) + bc = '='; + else + if (eq = cindex(prog, '-')) + bc = '-'; + else { + bad_option(str); + return; + } + + *eq++ = '\0'; + if (arg = eq) { + char *opt = 0; + struct prog *pp = &ProgParts[0]; + + if (bc == '-') { + opt = mkstr(alloc((unsigned)strlen(arg) + 2), + "-", arg, 0); + } + + while (pp->p_name) { + if (strcmp(prog, pp->p_name) == 0) { + if (opt) + append(pp->p_flags, opt); + else + *(pp->p_task) = arg; + return; + } + pp++; + } + } + bad_option(str); +} + +basename(str, dst) + char *str; + register char *dst; +{ + register char *p1 = str; + register char *p2 = p1; + + while (*p1) + if (*p1++ == '/') + p2 = p1; + p1--; + if (*--p1 == '.') + *p1 = '\0'; + while (*dst++ = *p2++); + *p1 = '.'; +} + +int +extension(fn) + register char *fn; +{ + char c; + + while (*fn++) ; + fn--; + c = *--fn; + return (*--fn == '.') ? c : 0; +} + +long +sizeof_file(nm) + char *nm; +{ + struct stat stbuf; + + if (stat(nm, &stbuf) == 0) + return stbuf.st_size; + return -1; +} + +char * sysmsg[] = { + 0, + "Hangup", + "Interrupt", + "Quit", + "Illegal instruction", + "Trace/BPT trap", + "IOT trap", + "EMT trap", + "Floating exception", + "Killed", + "Bus error", + "Memory fault", + "Bad system call", + "Broken pipe", + "Alarm call", + "Terminated", + "Signal 16" +}; + +runvec(vec, outp) + struct arglist *vec; + char *outp; +{ + int status, fd; + char *task = vec->al_argv[1]; + + vec->al_argv[vec->al_argc] = 0; + if (v_flag) + print_vec(vec); + if (exec == 0) + return 1; + if (fork() == 0) { /* start up the process */ + extern int errno; + + if (outp) { /* redirect standard output */ + if ((fd = creat(outp, 0666)) < 0) + panic("cannot create %s", outp); + if (dup2(fd, 1) == -1) + panic("dup failure"); + close(fd); + } + if (debug) report("exec %s", task); + execv(task, &(vec->al_argv[1])); + + /* not an a.out file, let's try it with the SHELL */ + if (debug) report("try it with %s", SHELL); + if (errno == ENOEXEC) { + vec->al_argv[0] = SHELL; + execv(SHELL, &(vec->al_argv[0])); + } + + /* failed, so ... */ + panic("cannot execute %s", task); + exit(1); + } + else { + int loworder, highorder, sig; + + wait(&status); + loworder = status & 0377; + highorder = (status >> 8) & 0377; + if (loworder == 0) { + if (highorder) + report("%s: exit status %d", task, highorder); + return highorder ? ((RET_CODE = 1), 0) : 1; + } + else { + sig = loworder & 0177; + if (sig == 0177) + report("%s: stopped by ptrace", task); + else + if (sysmsg[sig]) + report("%s: %s%s", task, sysmsg[sig], + (loworder & 0200) + ? " - core dumped" + : ""); + RET_CODE = 1; + return 0; + } + } + /*NOTREACHED*/ +} + +bad_option(str) + char *str; +{ + report("bad option %s", str); +} + +/*VARARGS1*/ +report(fmt, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) + char *fmt; +{ + fprintf(stderr, "%s: ", ProgCall); + fprintf(stderr, fmt, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); + fprintf(stderr, "\n"); +} + +/*VARARGS1*/ +panic(fmt, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) + char *fmt; +{ + fprintf(stderr, "%s: ", ProgCall); + fprintf(stderr, fmt, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); + fprintf(stderr, "\n"); + exit(1); +} + +set_traps(f) + int (*f)(); +{ + signal(SIGHUP, f); + signal(SIGINT, f); + signal(SIGQUIT, f); + signal(SIGALRM, f); + signal(SIGTERM, f); +} + +/*ARGSUSED*/ +trap(sig) +{ + set_traps(SIG_IGN); + panic("Trapped"); +} + +print_vec(vec) + struct arglist *vec; +{ + register i; + + for (i = 1; i < vec->al_argc; i++) + printf("%s ", vec->al_argv[i]); + printf("\n"); +} + +char * +cindex(s, c) + char *s, c; +{ + while (*s) + if (*s++ == c) + return s - 1; + return (char *) 0; +} diff --git a/lang/cem/cemcom/cemcom.1 b/lang/cem/cemcom/cemcom.1 new file mode 100644 index 00000000..ec84c40f --- /dev/null +++ b/lang/cem/cemcom/cemcom.1 @@ -0,0 +1,94 @@ +.TH CEMCOM 1 local +.SH NAME +cemcom \- C to EM compiler +.SH SYNOPSIS +\fBcemcom\fP [\fIoptions\fP] \fIsource \fP[\fIdestination \fP[\fInamelist\fP]] +.SH DESCRIPTION +\fICemcom\fP is a compiler that translates C programs +into EM compact code. +The input is taken from \fIsource\fP, while the +EM code is written on \fIdestination\fP. +If either of these two names is "\fB-\fP", standard input or output respectively +is taken. +The file \fInamelist\fP, if supplied, will contain a list of the names +of external, so-called \fBcommon\fP, variables. +When the preprocessor is invoked to run stand-alone, \fIdestination\fP +needs not be specified. +.br +\fIOptions\fP is a, possibly empty, sequence of the following combinations: +.IP \fB\-C\fR +list the sequence of input tokens while maintaining the comments. +.IP \fB\-D\fIname\fR=\fItext\fR +.br +define \fIname\fR as a macro with \fItext\fR as its replacement text. +.IP \fB\-D\fIname\fR +.br +the same as \fB\-D\fIname\fR=1. +.IP \fB\-E\fR +list the sequence of input tokens and delete any comments. +Control lines of the form +.RS +.RS +#\fBline\fR <\fIinteger\fR> "\fIfilename\fR" +.RE +are generated whenever needed. +.RE +.IP \fB\-I\fIdirname\fR +.br +insert \fIdirname\fR in the list of include directories. +.IP \fB\-M\fP\fIn\fP +set maximum identifier length to \fIn\fP. +.IP \fB\-n\fR +do not generate EM register messages. +The user-declared variables are not stored into registers on the target +machine. +.IP \fB\-p\fR +generate the EM \fBfil\fR and \fBlin\fR instructions in order to enable +an interpreter to keep track of the current location in the source code. +.IP \fB\-P\fR +like \fB\-E\fR but without #\fBline\fR control lines. +.IP \fB\-R\fR +interpret the input as restricted C (according to the language as +described in \fIThe C programming language\fR by Kernighan and Ritchie.) +.IP \fB\-U\fIname\fR +.br +get rid of the compiler-predefined macro \fIname\fR. +.IP \fB\-V\fIcm\fR.\fIn\fR,\ \fB\-V\fIcm\fR.\fIncm\fR.\fIn\fR\ ... +.br +set the size and alignment requirements. +The letter \fIc\fR indicates the simple type, which is one of +\fBs\fR(short), \fBi\fR(int), \fBl\fR(long), \fBf\fR(float), \fBd\fR(double) or +\fBp\fR(pointer). +The \fIm\fR parameter can be used to specify the length of the type (in bytes) +and the \fIn\fR parameter for the alignment of that type. +Absence of \fIm\fR or \fIn\fR causes the default value to be retained. +To specify that the bitfields should be right adjusted instead of the +default left adjustment, specify \fBr\fR as \fIc\fR parameter. +.IP \fB\-w\fR +suppress warning messages +.IP \fB\-\-\fItext\fR +.br +where \fItext\fR can be either of the above or +a debug flag of the compiler (which is not useful for the common user.) +This feature can be used in various shell scripts and surrounding programs +to force a certain option to be handed over to \fBcemcom\fR. +.LP +.SH FILES +.IR /user1/cem/bin/cemcom : +binary of the CEM compiler. +.br +.IR /user1/cem/bin/cem : +a \fIcc\fP(1)-like driver for the VAX running 4.1BSD UNIX. +.br +.IR /user1/sjoerd/bin/CC : +a \fIcc\fP(1)-like driver for the 68000 running Amoeba. +.SH DIAGNOSTICS +All warning and error messages are written on standard error output. +.SH BUGS +Debugging and profiling facilities may be present during the development +of \fIcemcom\fP. +.br +Please report all bugs to ..tjalk!cem or ..tjalk!erikb +.SH REFERENCE +Baalbergen, E.H., D. Grune, M. Waage ;"\fIThe CEM compiler\fR", +Informatica Manual IM-4 diff --git a/lang/cem/cemcom/ch7.c b/lang/cem/cemcom/ch7.c new file mode 100644 index 00000000..38fcbc21 --- /dev/null +++ b/lang/cem/cemcom/ch7.c @@ -0,0 +1,409 @@ +/* $Header$ */ +/* S E M A N T I C A N A L Y S I S -- C H A P T E R 7 RM */ + +#include "debug.h" +#include "nobitfield.h" +#include "idf.h" +#include "arith.h" +#include "type.h" +#include "struct.h" +#include "label.h" +#include "expr.h" +#include "def.h" +#include "Lpars.h" +#include "assert.h" + +#define is_zero(ex) \ + ((ex)->ex_class == Value && (ex)->VL_VALUE == (arith)0 && \ + (ex)->VL_IDF == 0) + +extern char options[]; +extern char *symbol2str(); + +/* Most expression-handling routines have a pointer to a + (struct type *) as first parameter. The object under the pointer + gets updated in the process. +*/ + +ch7sel(expp, oper, idf) + register struct expr **expp; + struct idf *idf; +{ + /* The selector idf is applied to *expp; oper may be '.' or + ARROW. + */ + register struct type *tp = (*expp)->ex_type; + register struct sdef *sd; + + if (oper == ARROW) { + if (tp->tp_fund == POINTER) /* normal case */ + tp = tp->tp_up; + else { /* constructions like "12->selector" and + "char c; c->selector" + */ + switch (tp->tp_fund) { + case CHAR: + case SHORT: + case INT: + case LONG: + case ENUM: + /* Allowed by RM 14.1 */ + ch7cast(expp, CAST, pa_type); + sd = idf2sdef(idf, tp); + tp = sd->sd_stype; + break; + default: + error("-> applied to %s", + symbol2str(tp->tp_fund)); + case ERRONEOUS: + (*expp)->ex_type = error_type; + return; + } + } /* tp->tp_fund != POINTER */ + } /* oper == ARROW */ + else { /* oper == '.' */ + /* filter out illegal expressions "non_lvalue.sel" */ + if (!(*expp)->ex_lvalue) { + error("dot requires lvalue"); + (*expp)->ex_type = error_type; + return; + } + } + switch (tp->tp_fund) { + case POINTER: /* for int *p; p->next = ... */ + case STRUCT: + case UNION: + break; + case CHAR: + case SHORT: + case INT: + case LONG: + case ENUM: + /* warning will be given by idf2sdef() */ + break; + default: + if (!is_anon_idf(idf)) + error("selector %s applied to %s", + idf->id_text, symbol2str(tp->tp_fund)); + case ERRONEOUS: + (*expp)->ex_type = error_type; + return; + } + sd = idf2sdef(idf, tp); + if (oper == '.') { + /* there are 3 cases in which the selection can be + performed compile-time: + I: n.sel (n either an identifier or a constant) + II: (e.s1).s2 (transformed into (e.(s1+s2))) + III: (e->s1).s2 (transformed into (e->(s1+s2))) + The code performing these conversions is + extremely obscure. + */ + if ((*expp)->ex_class == Value) { + /* It is an object we know the address of; so + we can calculate the address of the + selected member + */ + (*expp)->VL_VALUE += sd->sd_offset; + (*expp)->ex_type = sd->sd_type; + } + else + if ((*expp)->ex_class == Oper) { + struct oper *op = &((*expp)->ex_object.ex_oper); + + if (op->op_oper == '.' || op->op_oper == ARROW) { + op->op_right->VL_VALUE += sd->sd_offset; + (*expp)->ex_type = sd->sd_type; + } + else + *expp = new_oper(sd->sd_type, *expp, '.', + intexpr(sd->sd_offset, INT)); + } + } + else /* oper == ARROW */ + *expp = new_oper(sd->sd_type, + *expp, oper, intexpr(sd->sd_offset, INT)); + (*expp)->ex_lvalue = sd->sd_type->tp_fund != ARRAY; +} + +ch7incr(expp, oper) + register struct expr **expp; +{ + /* The monadic prefix/postfix incr/decr operator oper is + applied to *expp. + */ + arith addend; + struct expr *expr; + register int fund = (*expp)->ex_type->tp_fund; + + if (!(*expp)->ex_lvalue) { + error("no lvalue with %s", symbol2str(oper)); + return; + } + if (fund == ENUM) { + warning("%s on enum", symbol2str(oper)); + addend = (arith)1; + } + else + if (is_arith_type((*expp)->ex_type)) + addend = (arith)1; + else + if (fund == POINTER) + addend = size_of_type((*expp)->ex_type->tp_up, "object"); +#ifndef NOBITFIELD + else + if (fund == FIELD) + addend = (arith)1; +#endif NOBITFIELD + else { + if ((*expp)->ex_type != error_type) + error("%s on %s", + symbol2str(oper), + symbol2str((*expp)->ex_type->tp_fund) + ); + return; + } + expr = intexpr(addend, INT); + ch7cast(&expr, CAST, (*expp)->ex_type); +#ifndef NOBITFIELD + if (fund == FIELD) + *expp = new_oper((*expp)->ex_type->tp_up, *expp, oper, expr); + else +#endif NOBITFIELD + *expp = new_oper((*expp)->ex_type, *expp, oper, expr); +} + +ch7cast(expp, oper, tp) + register struct expr **expp; + register struct type *tp; +{ + /* The expression *expp is cast to type tp; the cast is + caused by the operator oper. If the cast has + to be passed on to run time, its left operand will be an + expression of class Type. + */ + register struct type *oldtp; + + if ((*expp)->ex_type->tp_fund == FUNCTION) + function2pointer(expp); + if ((*expp)->ex_type->tp_fund == ARRAY) + array2pointer(expp); + oldtp = (*expp)->ex_type; + if (oldtp == tp) + {} /* life is easy */ + else +#ifndef NOBITFIELD + if (oldtp->tp_fund == FIELD) { + field2arith(expp); + ch7cast(expp, oper, tp); + } + else + if (tp->tp_fund == FIELD) + ch7cast(expp, oper, tp->tp_up); + else +#endif NOBITFIELD + if (tp->tp_fund == VOID) /* Easy again */ + (*expp)->ex_type = void_type; + else + if (is_arith_type(oldtp) && is_arith_type(tp)) { + int oldi = is_integral_type(oldtp); + int i = is_integral_type(tp); + + if (oldi && i) { + if ( oldtp->tp_fund == ENUM && + tp->tp_fund == ENUM && + oper != CAST + ) + warning("%s on enums of different types", + symbol2str(oper)); + int2int(expp, tp); + } + else + if (oldi && !i) { + if (oldtp->tp_fund == ENUM && oper != CAST) + warning("conversion of enum to %s\n", + symbol2str(tp->tp_fund)); + int2float(expp, tp); + } + else + if (!oldi && i) + float2int(expp, tp); + else /* !oldi && !i */ + float2float(expp, tp); + } + else + if (oldtp->tp_fund == POINTER && tp->tp_fund == POINTER) { + if (oper != CAST) + warning("incompatible pointers in %s", + symbol2str(oper)); + (*expp)->ex_type = tp; /* free conversion */ + } + else + if (oldtp->tp_fund == POINTER && is_integral_type(tp)) { + /* from pointer to integral */ + if (oper != CAST) + warning("illegal conversion of pointer to %s", + symbol2str(tp->tp_fund)); + if (oldtp->tp_size > tp->tp_size) + warning("conversion of pointer to %s loses accuracy", + symbol2str(tp->tp_fund)); + if (oldtp->tp_size != tp->tp_size) + int2int(expp, tp); + else + (*expp)->ex_type = tp; + } + else + if (tp->tp_fund == POINTER && is_integral_type(oldtp)) { + /* from integral to pointer */ + switch (oper) { + case CAST: + break; + case EQUAL: + case NOTEQUAL: + case '=': + case RETURN: + if (is_zero(*expp)) + break; + default: + warning("illegal conversion of %s to pointer", + symbol2str(oldtp->tp_fund)); + break; + } + if (oldtp->tp_size > tp->tp_size) + warning("conversion of %s to pointer loses accuracy", + symbol2str(oldtp->tp_fund)); + if (oldtp->tp_size != tp->tp_size) + int2int(expp, tp); + else + (*expp)->ex_type = tp; + } + else + if (oldtp->tp_size == tp->tp_size && oper == CAST) { + warning("dubious conversion based on equal size"); + (*expp)->ex_type = tp; /* brute force */ + } + else + { + if (oldtp->tp_fund != ERRONEOUS && tp->tp_fund != ERRONEOUS) + expr_error(*expp, "cannot convert %s to %s", + symbol2str(oldtp->tp_fund), + symbol2str(tp->tp_fund) + ); + (*expp)->ex_type = tp; + } +} + +ch7asgn(expp, oper, expr) + register struct expr **expp; + struct expr *expr; +{ + /* The assignment operators. + */ + int fund = (*expp)->ex_type->tp_fund; + + /* We expect an lvalue */ + if (!(*expp)->ex_lvalue) { + error("no lvalue in lhs of %s", symbol2str(oper)); + (*expp)->ex_depth = 99; /* no direct store/load at EVAL() */ + /* what is 99 ??? DG */ + } + switch (oper) { + case '=': + ch7cast(&expr, oper, (*expp)->ex_type); + break; + case TIMESAB: + case DIVAB: + case MODAB: + if (!is_arith_type((*expp)->ex_type)) + error("%s on %s", symbol2str(oper), symbol2str(fund)); + any2arith(&expr, oper); + ch7cast(&expr, CAST, (*expp)->ex_type); + break; + case PLUSAB: + case MINAB: + any2arith(&expr, oper); + if (fund == POINTER) { + if (!is_integral_type(expr->ex_type)) + error("%s on non-integral type (%s)", + symbol2str(oper), symbol2str(fund)); + ch7bin(&expr, '*', + intexpr( + size_of_type( + (*expp)->ex_type->tp_up, + "object" + ), + pa_type->tp_fund + ) + ); + } + else + if (!is_arith_type((*expp)->ex_type)) + error("%s on %s", symbol2str(oper), symbol2str(fund)); + else + ch7cast(&expr, CAST, (*expp)->ex_type); + break; + case LEFTAB: + case RIGHTAB: + ch7cast(&expr, oper, int_type); + if (!is_integral_type((*expp)->ex_type)) + error("%s on %s", symbol2str(oper), symbol2str(fund)); + break; + case ANDAB: + case XORAB: + case ORAB: + if (!is_integral_type((*expp)->ex_type)) + error("%s on %s", symbol2str(oper), symbol2str(fund)); + ch7cast(&expr, oper, (*expp)->ex_type); + break; + } +#ifndef NOBITFIELD + if (fund == FIELD) + *expp = new_oper((*expp)->ex_type->tp_up, *expp, oper, expr); + else +#endif NOBITFIELD + *expp = new_oper((*expp)->ex_type, *expp, oper, expr); +} + +/* Some interesting (?) questions answered. +*/ +int +is_integral_type(tp) + struct type *tp; +{ + switch (tp->tp_fund) { + case CHAR: + case SHORT: + case INT: + case LONG: + case ENUM: + return 1; +#ifndef NOBITFIELD + case FIELD: + return is_integral_type(tp->tp_up); +#endif NOBITFIELD + default: + return 0; + } +} + +int +is_arith_type(tp) + struct type *tp; +{ + switch (tp->tp_fund) { + case CHAR: + case SHORT: + case INT: + case LONG: + case ENUM: + case FLOAT: + case DOUBLE: + return 1; +#ifndef NOBITFIELD + case FIELD: + return is_arith_type(tp->tp_up); +#endif NOBITFIELD + default: + return 0; + } +} diff --git a/lang/cem/cemcom/ch7bin.c b/lang/cem/cemcom/ch7bin.c new file mode 100644 index 00000000..ee30b03d --- /dev/null +++ b/lang/cem/cemcom/ch7bin.c @@ -0,0 +1,308 @@ +/* $Header$ */ +/* SEMANTIC ANALYSIS (CHAPTER 7RM) -- BINARY OPERATORS */ + +#include "botch_free.h" /* UF */ +#include "idf.h" +#include "arith.h" +#include "type.h" +#include "struct.h" +#include "label.h" +#include "expr.h" +#include "Lpars.h" +#include "storage.h" + +extern char options[]; +extern char *symbol2str(); + +/* This chapter asks for the repeated application of code to handle + an operation that may be executed at compile time or at run time, + depending on the constancy of the operands. +*/ + +ch7bin(expp, oper, expr) + register struct expr **expp; + struct expr *expr; +{ + /* apply binary operator oper between *expp and expr. + */ + any2opnd(expp, oper); + any2opnd(&expr, oper); + switch (oper) { + int fund; + case '[': /* RM 7.1 */ + /* RM 14.3 states that indexing follows the commutative laws */ + switch ((*expp)->ex_type->tp_fund) { + case POINTER: + case ARRAY: + break; + case ERRONEOUS: + return; + default: /* unindexable */ + switch (expr->ex_type->tp_fund) { + case POINTER: + case ARRAY: + break; + case ERRONEOUS: + return; + default: + error("indexing an object of type %s", + symbol2str((*expp)->ex_type->tp_fund)); + return; + } + break; + } + ch7bin(expp, '+', expr); + ch7mon('*', expp); + break; + case '(': /* RM 7.1 */ + if ( (*expp)->ex_type->tp_fund == POINTER && + (*expp)->ex_type->tp_up->tp_fund == FUNCTION + ) { + if (options['R']) + warning("function pointer called"); + ch7mon('*', expp); + } + if ((*expp)->ex_type->tp_fund != FUNCTION) { + if ((*expp)->ex_type != error_type) + error("call of non-function (%s)", + symbol2str((*expp)->ex_type->tp_fund)); + /* leave the expression; it may still serve */ + free_expression(expr); /* there go the parameters */ + } + else + *expp = new_oper((*expp)->ex_type->tp_up, + *expp, '(', expr); + break; + case PARCOMMA: /* RM 7.1 */ + if ((*expp)->ex_type->tp_fund == FUNCTION) + function2pointer(expp); + *expp = new_oper(expr->ex_type, *expp, PARCOMMA, expr); + break; + case '%': + fund = arithbalance(expp, oper, &expr); + if (fund == DOUBLE) { + error("floating operand to %%"); + *expp = intexpr((arith)1, INT); + } + else + non_commutative_binop(expp, oper, expr); + break; + case '/': + fund = arithbalance(expp, oper, &expr); + non_commutative_binop(expp, oper, expr); + break; + case '*': + fund = arithbalance(expp, oper, &expr); + commutative_binop(expp, oper, expr); + break; + case '+': + if (expr->ex_type->tp_fund == POINTER) { + /* swap operands */ + struct expr *etmp = expr; + expr = *expp; + *expp = etmp; + } + if ((*expp)->ex_type->tp_fund == POINTER) { + pointer_arithmetic(expp, oper, &expr); + if (expr->ex_type->tp_size != (*expp)->ex_type->tp_size) + ch7cast(&expr, CAST, (*expp)->ex_type); + pointer_binary(expp, oper, expr); + } + else { + fund = arithbalance(expp, oper, &expr); + commutative_binop(expp, oper, expr); + } + break; + case '-': + if ((*expp)->ex_type->tp_fund == POINTER) { + if (expr->ex_type->tp_fund == POINTER) + pntminuspnt(expp, oper, expr); + else { + pointer_arithmetic(expp, oper, &expr); + pointer_binary(expp, oper, expr); + } + } + else { + fund = arithbalance(expp, oper, &expr); + non_commutative_binop(expp, oper, expr); + } + break; + case LEFT: + case RIGHT: + opnd2integral(expp, oper); + opnd2integral(&expr, oper); + ch7cast(&expr, oper, int_type); /* leftop should be int */ + non_commutative_binop(expp, oper, expr); + break; + case '<': + case '>': + case LESSEQ: + case GREATEREQ: + case EQUAL: + case NOTEQUAL: + relbalance(expp, oper, &expr); + non_commutative_binop(expp, oper, expr); + (*expp)->ex_type = int_type; + break; + case '&': + case '^': + case '|': + opnd2integral(expp, oper); + opnd2integral(&expr, oper); + fund = arithbalance(expp, oper, &expr); /* <=== */ + commutative_binop(expp, oper, expr); + break; + case AND: + case OR: + opnd2test(expp, oper); + opnd2test(&expr, oper); + if (is_cp_cst(*expp)) { + struct expr *ex = *expp; + + /* the following condition is a short-hand for + ((oper == AND) && o1) || ((oper == OR) && !o1) + where o1 == (*expp)->VL_VALUE; + and ((oper == AND) || (oper == OR)) + */ + if ((oper == AND) == ((*expp)->VL_VALUE != (arith)0)) + *expp = expr; + else { + free_expression(expr); + *expp = intexpr((arith)((oper == AND) ? 0 : 1), + INT); + } + free_expression(ex); + } + else + if (is_cp_cst(expr)) { + /* Note!!!: the following condition is a short-hand for + ((oper == AND) && o2) || ((oper == OR) && !o2) + where o2 == expr->VL_VALUE + and ((oper == AND) || (oper == OR)) + */ + if ((oper == AND) == (expr->VL_VALUE != (arith)0)) + free_expression(expr); + else { + if (oper == OR) + expr->VL_VALUE = (arith)1; + ch7bin(expp, ',', expr); + } + } + else + *expp = new_oper(int_type, *expp, oper, expr); + (*expp)->ex_flags |= EX_LOGICAL; + break; + case ':': + if ( is_struct_or_union((*expp)->ex_type->tp_fund) + || is_struct_or_union(expr->ex_type->tp_fund) + ) { + if ((*expp)->ex_type != expr->ex_type) { + error("illegal balance"); + (*expp)->ex_type = error_type; + } + } + else { + relbalance(expp, oper, &expr); + } + *expp = new_oper((*expp)->ex_type, *expp, oper, expr); + break; + case '?': + opnd2logical(expp, oper); + if (is_cp_cst(*expp)) + *expp = (*expp)->VL_VALUE ? + expr->OP_LEFT : expr->OP_RIGHT; + else + *expp = new_oper(expr->ex_type, *expp, oper, expr); + break; + case ',': + if (is_cp_cst(*expp)) + *expp = expr; + else + *expp = new_oper(expr->ex_type, *expp, oper, expr); + (*expp)->ex_flags |= EX_COMMA; + break; + } +} + +pntminuspnt(expp, oper, expr) + register struct expr **expp, *expr; +{ + /* Subtracting two pointers is so complicated it merits a + routine of its own. + */ + struct type *up_type = (*expp)->ex_type->tp_up; + + if (up_type != expr->ex_type->tp_up) { + error("subtracting incompatible pointers"); + free_expression(expr); + free_expression(*expp); + *expp = intexpr((arith)0, INT); + return; + } + /* we hope the optimizer will eliminate the load-time + pointer subtraction + */ + *expp = new_oper((*expp)->ex_type, *expp, oper, expr); + ch7cast(expp, CAST, pa_type); /* ptr-ptr: result has pa_type */ + ch7bin(expp, '/', + intexpr(size_of_type(up_type, "object"), pa_type->tp_fund)); + ch7cast(expp, CAST, int_type); /* result will be an integer expr */ +} + +non_commutative_binop(expp, oper, expr) + register struct expr **expp, *expr; +{ + /* Constructs in *expp the operation indicated by the operands. + "oper" is a non-commutative operator + */ + if (is_cp_cst(expr) && is_cp_cst(*expp)) + cstbin(expp, oper, expr); + else + *expp = new_oper((*expp)->ex_type, *expp, oper, expr); +} + +commutative_binop(expp, oper, expr) + register struct expr **expp, *expr; +{ + /* Constructs in *expp the operation indicated by the operands. + "oper" is a commutative operator + */ + if (is_cp_cst(expr) && is_cp_cst(*expp)) + cstbin(expp, oper, expr); + else + if ((*expp)->ex_depth > expr->ex_depth) + *expp = new_oper((*expp)->ex_type, *expp, oper, expr); + else + *expp = new_oper((*expp)->ex_type, expr, oper, *expp); +} + +pointer_arithmetic(expp1, oper, expp2) + register struct expr **expp1, **expp2; +{ + /* prepares the integral expression expp2 in order to + apply it to the pointer expression expp1 + */ + if (any2arith(expp2, oper) == DOUBLE) { + expr_error(*expp2, + "illegal combination of float and pointer"); + free_expression(*expp2); + *expp2 = intexpr((arith)0, INT); + } + ch7bin( expp2, '*', + intexpr(size_of_type((*expp1)->ex_type->tp_up, "object"), + pa_type->tp_fund) + ); +} + +pointer_binary(expp, oper, expr) + register struct expr **expp, *expr; +{ + /* constructs the pointer arithmetic expression out of + a pointer expression, a binary operator and an integral + expression. + */ + if (is_ld_cst(expr) && is_ld_cst(*expp)) + cstbin(expp, oper, expr); + else + *expp = new_oper((*expp)->ex_type, *expp, oper, expr); +} diff --git a/lang/cem/cemcom/ch7mon.c b/lang/cem/cemcom/ch7mon.c new file mode 100644 index 00000000..061db817 --- /dev/null +++ b/lang/cem/cemcom/ch7mon.c @@ -0,0 +1,148 @@ +/* $Header$ */ +/* SEMANTIC ANALYSIS (CHAPTER 7RM) -- MONADIC OPERATORS */ + +#include "nobitfield.h" +#include "botch_free.h" +#include "Lpars.h" +#include "arith.h" +#include "type.h" +#include "label.h" +#include "expr.h" +#include "storage.h" +#include "idf.h" +#include "def.h" + +extern char options[]; +char *symbol2str(); + +ch7mon(oper, expp) + register struct expr **expp; +{ + /* The monadic prefix operator oper is applied to *expp. + */ + register struct expr *expr; + + switch (oper) { + case '*': /* RM 7.2 */ + /* no FIELD type allowed */ + if ((*expp)->ex_type->tp_fund == ARRAY) + array2pointer(expp); + if ((*expp)->ex_type->tp_fund != POINTER) { + if ((*expp)->ex_type != error_type) + error("* applied to non-pointer (%s)", + symbol2str((*expp)->ex_type->tp_fund)); + (*expp)->ex_type = error_type; + } + else { + expr = *expp; + if (expr->ex_lvalue == 0) + /* dereference in administration only */ + expr->ex_type = expr->ex_type->tp_up; + else /* runtime code */ + *expp = new_oper(expr->ex_type->tp_up, NILEXPR, + '*', expr); + (*expp)->ex_lvalue = ( + (*expp)->ex_type->tp_fund != ARRAY && + (*expp)->ex_type->tp_fund != FUNCTION); + } + break; + case '&': + if ((*expp)->ex_type->tp_fund == ARRAY) { + array2pointer(expp); + } + else + if ((*expp)->ex_type->tp_fund == FUNCTION) { + function2pointer(expp); + } + else +#ifndef NOBITFIELD + if ((*expp)->ex_type->tp_fund == FIELD) { + error("& applied to field variable"); + (*expp)->ex_type = error_type; + } + else +#endif NOBITFIELD + if (!(*expp)->ex_lvalue) { + error("& applied to non-lvalue"); + (*expp)->ex_type = error_type; + } + else { + /* assume that enums are already filtered out */ + if ((*expp)->ex_class == Value && (*expp)->VL_IDF) { + register struct def *def = + (*expp)->VL_IDF->id_def; + + /* & indicates that cannot + be used as register anymore + */ + if (def->df_sc == REGISTER) { + error("'&' on register variable not allowed"); + (*expp)->ex_type = error_type; + break; /* break case '&' */ + } + def->df_register = REG_NONE; + } + (*expp)->ex_type = pointer_to((*expp)->ex_type); + (*expp)->ex_lvalue = 0; + } + break; + case '~': + { + int fund = (*expp)->ex_type->tp_fund; + + if (fund == FLOAT || fund == DOUBLE) { + error("~ not allowed on %s operands", symbol2str(fund)); + *expp = intexpr((arith)1, INT); + break; + } + } + case '-': + any2arith(expp, oper); + if (is_cp_cst(*expp)) { + arith o1 = (*expp)->VL_VALUE; + if (oper == '-') + o1 = -o1; + else + o1 = ~o1; + (*expp)->VL_VALUE = o1; + } + else + if (is_fp_cst(*expp)) + switch_sign_fp(*expp); + else + *expp = new_oper((*expp)->ex_type, NILEXPR, oper, *expp); + break; + case '!': + if ((*expp)->ex_type->tp_fund == FUNCTION) + function2pointer(expp); + if ((*expp)->ex_type->tp_fund != POINTER) + any2arith(expp, oper); + opnd2test(expp, '!'); + if (is_cp_cst(*expp)) { + arith o1 = (*expp)->VL_VALUE; + o1 = !o1; + (*expp)->VL_VALUE = o1; + (*expp)->ex_type = int_type; + } + else + *expp = new_oper(int_type, NILEXPR, oper, *expp); + (*expp)->ex_flags |= EX_LOGICAL; + break; + case PLUSPLUS: + case MINMIN: + ch7incr(expp, oper); + break; + case SIZEOF: + if ( (*expp)->ex_class == Value + && (*expp)->VL_IDF + && (*expp)->VL_IDF->id_def->df_formal_array + ) + warning("sizeof formal array %s is sizeof pointer!", + (*expp)->VL_IDF->id_text); + expr = intexpr(size_of_type((*expp)->ex_type, "object"), INT); + free_expression(*expp); + *expp = expr; + (*expp)->ex_flags |= EX_SIZEOF; + break; + } +} diff --git a/lang/cem/cemcom/char.tab b/lang/cem/cemcom/char.tab new file mode 100644 index 00000000..480bdf1d --- /dev/null +++ b/lang/cem/cemcom/char.tab @@ -0,0 +1,58 @@ +% +% CHARACTER CLASSES +% +% some general settings: +%S129 +%F %s, +% +% START OF TOKEN +% +%C +STGARB:\000-\200 +STSKIP:\r \t +STNL:\n\f\013 +STCOMP:!&+-<=>| +STSIMP:%()*,/:;?[]^{}~ +STCHAR:' +STIDF:a-zA-Z_ +STNUM:.0-9 +STSTR:" +STEOI:\200 +%T/* character classes */ +%T#include "class.h" +%Tchar tkclass[] = { +%p +%T}; +% +% INIDF +% +%C +1:a-zA-Z_0-9 +%Tchar inidf[] = { +%F %s, +%p +%T}; +% +% ISDIG +% +%C +1:0-9 +%Tchar isdig[] = { +%p +%T}; +% +% ISHEX +% +%C +1:a-fA-F +%Tchar ishex[] = { +%p +%T}; +% +% ISOCT +% +%C +1:0-7 +%Tchar isoct[] = { +%p +%T}; diff --git a/lang/cem/cemcom/class.h b/lang/cem/cemcom/class.h new file mode 100644 index 00000000..faaff234 --- /dev/null +++ b/lang/cem/cemcom/class.h @@ -0,0 +1,37 @@ +/* $Header$ */ +/* U S E O F C H A R A C T E R C L A S S E S */ + +/* As a starter, chars are divided into classes, according to which + token they can be the start of. + At present such a class number is supposed to fit in 4 bits. +*/ + +#define class(ch) (tkclass[ch]) + +/* Being the start of a token is, fortunately, a mutual exclusive + property, so, although there are less than 16 classes they can be + packed in 4 bits. +*/ + +#define STSKIP 0 /* spaces and so on: skipped characters */ +#define STNL 1 /* newline character(s): update linenumber etc. */ +#define STGARB 2 /* garbage ascii character: not allowed in C */ +#define STSIMP 3 /* this character can occur as token in C */ +#define STCOMP 4 /* this one can start a compound token in C */ +#define STIDF 5 /* being the initial character of an identifier */ +#define STCHAR 6 /* the starter of a character constant */ +#define STSTR 7 /* the starter of a string */ +#define STNUM 8 /* the starter of a numeric constant */ +#define STEOI 9 /* End-Of-Information mark */ + +/* But occurring inside a token is not, so we need 1 bit for each + class. This is implemented as a collection of tables to speed up + the decision whether a character has a special meaning. +*/ +#define in_idf(ch) (inidf[ch]) +#define is_oct(ch) (isoct[ch]) +#define is_dig(ch) (isdig[ch]) +#define is_hex(ch) (ishex[ch]) + +extern char tkclass[]; +extern char inidf[], isoct[], isdig[], ishex[]; diff --git a/lang/cem/cemcom/code.c b/lang/cem/cemcom/code.c new file mode 100644 index 00000000..fb4e7e05 --- /dev/null +++ b/lang/cem/cemcom/code.c @@ -0,0 +1,491 @@ +/* $Header$ */ +/* C O D E - G E N E R A T I N G R O U T I N E S */ + +#include "dataflow.h" +#include "use_tmp.h" +#include "botch_free.h" + +#include "arith.h" +#include "type.h" +#include "idf.h" +#include "label.h" +#include "code.h" +#include "alloc.h" +#include "def.h" +#include "expr.h" +#include "sizes.h" +#include "stack.h" +#include "em.h" +#include "level.h" +#include "decspecs.h" +#include "declarator.h" +#include "Lpars.h" +#include "mes.h" +#include "LLlex.h" +#include "specials.h" +#include "storage.h" +#include "atw.h" +#include "assert.h" + +static struct stat_block *stat_sp, *stat_head; + +char *symbol2str(); +int fp_used; +label lab_count = 1; +label datlab_count = 1; + +extern char options[]; + +/* init_code() initialises the output file on which the compact + EM code is written +*/ +init_code(dst_file) + char *dst_file; +{ + if (C_open(dst_file) == 0) + fatal("cannot write to %s\n", dst_file); +#ifndef USE_TMP + famous_first_words(); +#endif USE_TMP + stat_sp = stat_head = new_stat_block(); + clear((char *)stat_sp, sizeof(struct stat_block)); +} + +famous_first_words() +{ + C_magic(); + C_ms_emx(word_size, pointer_size); +} + +end_code() +{ + /* end_code() performs the actions to be taken when closing + the output stream. + */ + C_ms_src((arith)(LineNumber - 2), FileName); + C_close(); +} + +#ifdef USE_TMP +prepend_scopes(dst_file) + char *dst_file; +{ + /* prepend_scopes() runs down the list of global idf's + and generates those exa's, exp's, ina's and inp's + that superior hindsight has provided, on the file dst_file. + */ + struct stack_entry *se = local_level->sl_entry; + + if (C_open(dst_file) == 0) + fatal("cannot create file %s", dst_file); + famous_first_words(); + while (se != 0) { + struct idf *idf = se->se_idf; + struct def *def = idf->id_def; + + if (def && + ( def->df_initialized || + def->df_used || + def->df_alloc + ) + ) + code_scope(idf->id_text, def); + se = se->next; + } + C_close(); +} +#endif USE_TMP + +code_scope(text, def) + char *text; + struct def *def; +{ + /* generates code for one name, text, of the storage class + as given by def, if meaningful. + */ + int fund = def->df_type->tp_fund; + + switch (def->df_sc) { + case EXTERN: + case GLOBAL: + case IMPLICIT: + if (fund == FUNCTION) + C_exp(text); + else + C_exa(text); + break; + case STATIC: + if (fund == FUNCTION) + C_inp(text); + else + C_ina(text); + break; + } +} + +static label return_label; +static char return_expr_occurred; +static struct type *func_tp; +static label func_res_label; +static char *last_fn_given = ""; +static label file_name_label; + +/* begin_proc() is called at the entrance of a new function + and performs the necessary code generation: + - a scope indicator (if needed) exp/inp + - the procedure entry pro $name + - reserves some space if the result of the function + does not fit in the return area + - a fil pseudo instruction +*/ +begin_proc(name, def) /* to be called when entering a procedure */ + char *name; + struct def *def; +{ + arith size; + +#ifndef USE_TMP + code_scope(name, def); +#endif USE_TMP +#ifdef DATAFLOW + if (options['d']) + DfaStartFunction(name); +#endif DATAFLOW + + func_tp = def->df_type->tp_up; + size = ATW(func_tp->tp_size); + C_pro_narg(name); + if (is_struct_or_union(func_tp->tp_fund)) { + C_ndlb(func_res_label = data_label()); + C_bss_cst(size, (arith)0, 1); + } + else + func_res_label = 0; + + /* Special arrangements if the function result doesn't fit in + the function return area of the EM machine. The size of + the function return area is implementation dependent. + */ + lab_count = (label) 1; + return_label = text_label(); + return_expr_occurred = 0; + + if (options['p']) { /* profiling */ + if (strcmp(last_fn_given, FileName) != 0) { + /* previous function came from other file */ + C_ndlb(file_name_label = data_label()); + C_con_begin(); + C_co_scon(last_fn_given = FileName, (arith)0); + C_con_end(); + } + /* enable debug trace of EM source */ + C_fil_ndlb(file_name_label, (arith)0); + C_lin((arith)LineNumber); + } +} + +/* end_proc() deals with the code to be generated at the end of + a function, as there is: + - the EM ret instruction: "ret 0" + - loading of the function result in the function result area + if there has been a return in the function body + (see do_return_expr()) + - indication of the use of floating points + - indication of the number of bytes used for formal parameters + - use of special identifiers such as "setjmp" + - "end" + number of bytes used for local variables +*/ +end_proc(fbytes, nbytes) + arith fbytes, nbytes; +{ + static int mes_flt_given = 0; /* once for the whole program */ + +#ifdef DATAFLOW + if (options['d']) + DfaEndFunction(); +#endif DATAFLOW + C_ret((arith)0); + if (return_expr_occurred != 0) { + C_ilb(return_label); + if (func_res_label != 0) { + C_lae_ndlb(func_res_label, (arith)0); + store_block(func_tp->tp_size, func_tp->tp_align); + C_lae_ndlb(func_res_label, (arith)0); + C_ret(pointer_size); + } + else + C_ret(ATW(func_tp->tp_size)); + } + if (fp_used && mes_flt_given == 0) { + /* floating point used */ + C_ms_flt(); + mes_flt_given++; + } + C_ms_par(fbytes); /* # bytes for formals */ + if (sp_occurred[SP_SETJMP]) { /* indicate use of "setjmp" */ + C_ms_gto(); + sp_occurred[SP_SETJMP] = 0; + } + C_end(ATW(nbytes)); +} + +do_return_expr(expr) + struct expr *expr; +{ + /* do_return_expr() generates the expression and the jump for + a return statement with an expression. + */ + ch7cast(&expr, RETURN, func_tp); + code_expr(expr, RVAL, TRUE, NO_LABEL, NO_LABEL); + C_bra(return_label); + return_expr_occurred = 1; +} + +code_declaration(idf, expr, lvl, sc) + struct idf *idf; /* idf to be declared */ + struct expr *expr; /* initialisation; NULL if absent */ + int lvl; /* declaration level */ + int sc; /* storage class, as in the declaration */ +{ + /* code_declaration() does the actual declaration of the + variable indicated by "idf" on declaration level "lvl". + If the variable is initialised, the expression is given + in "expr". + There are some cases to be considered: + - filter out typedefs, they don't correspond to code; + - global variables, coded only if initialized; + - local static variables; + - local automatic variables; + If there is a storage class indication (EXTERN/STATIC), + code_declaration() will generate an exa or ina. + The sc is the actual storage class, as given in the + declaration. This is to allow: + extern int a; + int a = 5; + while at the same time forbidding + extern int a = 5; + */ + char *text = idf->id_text; + struct def *def = idf->id_def; + arith size = def->df_type->tp_size; + int def_sc = def->df_sc; + + if (def_sc == TYPEDEF) /* no code for typedefs */ + return; + if (sc == EXTERN && expr && !is_anon_idf(idf)) + error("%s is extern; cannot initialize", text); + if (lvl == L_GLOBAL) { /* global variable */ + /* is this an allocating declaration? */ + if ( (sc == 0 || sc == STATIC) + && def->df_type->tp_fund != FUNCTION + && size >= 0 + ) + def->df_alloc = ALLOC_SEEN; + if (expr) { /* code only if initialized */ +#ifndef USE_TMP + code_scope(text, def); +#endif USE_TMP + def->df_alloc = ALLOC_DONE; + C_dnam(text); + do_ival(&(def->df_type), expr); + } + } + else + if (lvl >= L_LOCAL) { /* local variable */ + /* they are STATIC, EXTERN, GLOBAL, IMPLICIT, AUTO or + REGISTER + */ + switch (def_sc) { + case STATIC: + /* they are handled on the spot and get an + integer label in EM. + */ + C_ndlb((label)def->df_address); + if (expr) /* there is an initialisation */ + do_ival(&(def->df_type), expr); + else { /* produce blank space */ + if (size <= 0) { + error("size of \"%s\" unknown", text); + size = (arith)0; + } + C_bss_cst(align(size, word_align), (arith)0, 1); + } + break; + case EXTERN: + case GLOBAL: + case IMPLICIT: + /* we are sure there is no expression */ +#ifndef USE_TMP + code_scope(text, def); +#endif USE_TMP + break; + case AUTO: + case REGISTER: + if (expr) + loc_init(expr, idf); + break; + default: + crash("bad local storage class"); + break; + } + } +} + +loc_init(expr, id) + struct expr *expr; + struct idf *id; +{ + /* loc_init() generates code for the assignment of + expression expr to the local variable described by id. + */ + register struct type *tp = id->id_def->df_type; + + /* automatic aggregates cannot be initialised. */ + switch (tp->tp_fund) { + case ARRAY: + case STRUCT: + case UNION: + error("no automatic aggregate initialisation"); + return; + } + + if (ISCOMMA(expr)) { /* embraced: int i = {12}; */ + if (options['R']) { + if (ISCOMMA(expr->OP_LEFT)) /* int i = {{1}} */ + expr_error(expr, "extra braces not allowed"); + else + if (expr->OP_RIGHT != 0) /* int i = {1 , 2} */ + expr_error(expr, "too many initializers"); + } + while (expr) { + loc_init(expr->OP_LEFT, id); + expr = expr->OP_RIGHT; + } + } + else { /* not embraced */ + ch7cast(&expr, '=', tp); + EVAL(expr, RVAL, TRUE, NO_LABEL, NO_LABEL); + store_val(id, tp, (arith) 0); + } +} + +/* bss() allocates bss space for the global idf. +*/ +bss(idf) + struct idf *idf; +{ + register struct def *def = idf->id_def; + arith size = def->df_type->tp_size; + +#ifndef USE_TMP + code_scope(idf->id_text, def); +#endif USE_TMP + /* Since bss() is only called if df_alloc is non-zero, and + since df_alloc is only non-zero if size >= 0, we have: + */ + if (options['R'] && size == 0) + warning("actual array of size 0"); + C_dnam(idf->id_text); + C_bss_cst(align(size, word_align), (arith)0, 1); +} + +formal_cvt(def) + struct def *def; +{ + /* formal_cvt() converts a formal parameter of type char or + short from int to that type. + */ + register struct type* tp = def->df_type; + + if (tp->tp_size != int_size) + if (tp->tp_fund == CHAR || tp->tp_fund == SHORT) { + C_lol(def->df_address); + conversion(int_type, def->df_type); + C_lal(def->df_address); + C_sti(tp->tp_size); + def->df_register = REG_NONE; + } +} + +/* code_expr() is the parser's interface to the expression code + generator. + If line number trace is wanted, it generates a lin instruction. + EVAL() is called directly. +*/ +code_expr(expr, val, code, tlbl, flbl) + struct expr *expr; + label tlbl, flbl; +{ + if (options['p']) /* profiling */ + C_lin((arith)LineNumber); + EVAL(expr, val, code, tlbl, flbl); +} + +/* The FOR/WHILE/DO/SWITCH stacking mechanism: + stat_stack() has to be called at the entrance of a + for, while, do or switch statement to indicate the + EM labels where a subsequent break or continue causes + the program to jump to. +*/ +/* do_break() generates EM code needed at the occurrence of "break": + it generates a branch instruction to the break label of the + innermost statement in which break has a meaning. + As "break" is legal in any of 'while', 'do', 'for' or 'switch', + which are the only ones that are stacked, only the top of + the stack is interesting. + 0 is returned if the break cannot be bound to any enclosing + statement. +*/ +int +do_break() +{ + register struct stat_block *stat_ptr = stat_sp; + + if (stat_ptr) { + C_bra(stat_ptr->st_break); + return 1; + } + return 0; /* break is illegal */ +} + +/* do_continue() generates EM code needed at the occurrence of "continue": + it generates a branch instruction to the continue label of the + innermost statement in which continue has a meaning. + 0 is returned if the continue cannot be bound to any enclosing + statement. +*/ +int +do_continue() +{ + register struct stat_block *stat_ptr = stat_sp; + + while (stat_ptr) { + if (stat_ptr->st_continue) { + C_bra(stat_ptr->st_continue); + return 1; + } + stat_ptr = stat_ptr->next; + } + return 0; +} + +stat_stack(break_label, cont_label) + label break_label, cont_label; +{ + register struct stat_block *newb = new_stat_block(); + + newb->next = stat_sp; + newb->st_break = break_label; + newb->st_continue = cont_label; + stat_sp = newb; +} + +/* stat_unstack() unstacks the data of a statement + which may contain break or continue +*/ +stat_unstack() +{ + register struct stat_block *sbp = stat_sp; + stat_sp = stat_sp->next; + free_stat_block(sbp); +} diff --git a/lang/cem/cemcom/code.h b/lang/cem/cemcom/code.h new file mode 100644 index 00000000..3399b3e0 --- /dev/null +++ b/lang/cem/cemcom/code.h @@ -0,0 +1,23 @@ +/* $Header$ */ +/* C O D E - G E N E R A T O R D E F I N I T I O N S */ + +struct stat_block { + struct stat_block *next; + label st_break; + label st_continue; +}; + + +/* allocation definitions of struct stat_block */ +/* ALLOCDEF "stat_block" */ +extern char *st_alloc(); +extern struct stat_block *h_stat_block; +#define new_stat_block() ((struct stat_block *) \ + st_alloc((char **)&h_stat_block, sizeof(struct stat_block))) +#define free_stat_block(p) st_free(p, h_stat_block, sizeof(struct stat_block)) + + +#define LVAL 0 +#define RVAL 1 +#define FALSE 0 +#define TRUE 1 diff --git a/lang/cem/cemcom/code.str b/lang/cem/cemcom/code.str new file mode 100644 index 00000000..3399b3e0 --- /dev/null +++ b/lang/cem/cemcom/code.str @@ -0,0 +1,23 @@ +/* $Header$ */ +/* C O D E - G E N E R A T O R D E F I N I T I O N S */ + +struct stat_block { + struct stat_block *next; + label st_break; + label st_continue; +}; + + +/* allocation definitions of struct stat_block */ +/* ALLOCDEF "stat_block" */ +extern char *st_alloc(); +extern struct stat_block *h_stat_block; +#define new_stat_block() ((struct stat_block *) \ + st_alloc((char **)&h_stat_block, sizeof(struct stat_block))) +#define free_stat_block(p) st_free(p, h_stat_block, sizeof(struct stat_block)) + + +#define LVAL 0 +#define RVAL 1 +#define FALSE 0 +#define TRUE 1 diff --git a/lang/cem/cemcom/conversion.c b/lang/cem/cemcom/conversion.c new file mode 100644 index 00000000..07188d6c --- /dev/null +++ b/lang/cem/cemcom/conversion.c @@ -0,0 +1,130 @@ +/* $Header$ */ +/* C O N V E R S I O N - C O D E G E N E R A T O R */ + +#include "arith.h" +#include "type.h" +#include "em.h" +#include "sizes.h" +#include "Lpars.h" + +#define T_SIGNED 1 +#define T_UNSIGNED 2 +#define T_FLOATING 3 + +/* conversion() generates the EM code for a conversion between + the types char, short, int, long, float, double and pointer. + In case of integral type, the notion signed / unsigned is + taken into account. + The EM code to obtain this conversion looks like: + LOC sizeof(from_type) + LOC sizeof(to_type) + C?? +*/ + +conversion(from_type, to_type) + struct type *from_type, *to_type; +{ + arith from_size; + arith to_size; + + if (from_type == to_type) { /* a little optimisation */ + return; + } + + from_size = from_type->tp_size; + to_size = to_type->tp_size; + + switch (fundamental(from_type)) { + + case T_SIGNED: + switch (fundamental(to_type)) { + + case T_SIGNED: + C_loc(from_size); + C_loc(to_size < word_size ? word_size : to_size); + C_cii(); + break; + + case T_UNSIGNED: + C_loc(from_size < word_size ? word_size : from_size); + C_loc(to_size < word_size ? word_size : to_size); + C_ciu(); + break; + + case T_FLOATING: + C_loc(from_size < word_size ? word_size : from_size); + C_loc(to_size < word_size ? word_size : to_size); + C_cif(); + break; + } + break; + + case T_UNSIGNED: + C_loc(from_size < word_size ? word_size : from_size); + C_loc(to_size < word_size ? word_size : to_size); + + switch (fundamental(to_type)) { + + case T_SIGNED: + C_cui(); + break; + + case T_UNSIGNED: + C_cuu(); + break; + + case T_FLOATING: + C_cuf(); + break; + } + break; + + case T_FLOATING: + C_loc(from_size < word_size ? word_size : from_size); + C_loc(to_size < word_size ? word_size : to_size); + + switch (fundamental(to_type)) { + + case T_SIGNED: + C_cfi(); + break; + + case T_UNSIGNED: + C_cfu(); + break; + + case T_FLOATING: + C_cff(); + break; + } + break; + default: + crash("(conversion) illegal type conversion"); + } +} + +/* fundamental() returns in which category a given type falls: + signed, unsigned or floating +*/ +int +fundamental(tp) + struct type *tp; +{ + switch (tp->tp_fund) { + + case CHAR: + case SHORT: + case INT: + case LONG: + case ENUM: + return tp->tp_unsigned ? T_UNSIGNED : T_SIGNED; + + case FLOAT: + case DOUBLE: + return T_FLOATING; + + case POINTER: /* pointer : signed / unsigned ??? */ + return T_SIGNED; + } + return 0; +} diff --git a/lang/cem/cemcom/cstoper.c b/lang/cem/cemcom/cstoper.c new file mode 100644 index 00000000..414e18d6 --- /dev/null +++ b/lang/cem/cemcom/cstoper.c @@ -0,0 +1,230 @@ +/* $Header$ */ +/* C O N S T A N T E X P R E S S I O N H A N D L I N G */ + +#include "target_sizes.h" /* UF */ + +#include "idf.h" +#include "arith.h" +#include "type.h" +#include "label.h" +#include "expr.h" +#include "sizes.h" +#include "Lpars.h" + +long mach_long_sign; /* sign bit of the machine long */ +int mach_long_size; /* size of long on this machine == sizeof(long) */ +long full_mask[MAXSIZE];/* full_mask[1] == 0XFF, full_mask[2] == 0XFFFF, .. */ +arith max_int; /* maximum integer on target machine */ +arith max_unsigned; /* maximum unsigned on target machine */ + +cstbin(expp, oper, expr) + struct expr **expp, *expr; +{ + /* The operation oper is performed on the constant + expressions *expp and expr, and the result restored in + *expp. + */ + arith o1 = (*expp)->VL_VALUE; + arith o2 = expr->VL_VALUE; + int uns = (*expp)->ex_type->tp_unsigned; + + switch (oper) { + case '*': + o1 *= o2; + break; + case '/': + if (o2 == 0) { + error("division by 0"); + break; + } + if (uns) { + /* this is more of a problem than you might + think on C compilers which do not have + unsigned long. + */ + if (o2 & mach_long_sign) {/* o2 > max_long */ + o1 = ! (o1 >= 0 || o1 < o2); + /* this is the unsigned test + o1 < o2 for o2 > max_long + */ + } + else { /* o2 <= max_long */ + long half, bit, hdiv, hrem, rem; + + half = (o1 >> 1) & ~mach_long_sign; + bit = o1 & 01; + /* now o1 == 2 * half + bit + and half <= max_long + and bit <= max_long + */ + hdiv = half / o2; + hrem = half % o2; + rem = 2 * hrem + bit; + o1 = 2 * hdiv + (rem < 0 || rem >= o2); + /* that is the unsigned compare + rem >= o2 for o2 <= max_long + */ + } + } + else + o1 /= o2; + break; + case '%': + if (o2 == 0) { + error("modulo by 0"); + break; + } + if (uns) { + if (o2 & mach_long_sign) {/* o2 > max_long */ + o1 = (o1 >= 0 || o1 < o2) ? o1 : o1 - o2; + /* this is the unsigned test + o1 < o2 for o2 > max_long + */ + } + else { /* o2 <= max_long */ + long half, bit, hrem, rem; + + half = (o1 >> 1) & ~mach_long_sign; + bit = o1 & 01; + /* now o1 == 2 * half + bit + and half <= max_long + and bit <= max_long + */ + hrem = half % o2; + rem = 2 * hrem + bit; + o1 = (rem < 0 || rem >= o2) ? rem - o2 : rem; + } + } + else + o1 %= o2; + break; + case '+': + o1 += o2; + break; + case '-': + o1 -= o2; + break; + case LEFT: + o1 <<= o2; + break; + case RIGHT: + if (o2 == 0) + break; + if (uns) { + o1 >>= 1; + o1 & = ~mach_long_sign; + o1 >>= (o2-1); + } + else + o1 >>= o2; + break; + case '<': + if (uns) { + o1 = (o1 & mach_long_sign ? + (o2 & mach_long_sign ? o1 < o2 : 0) : + (o2 & mach_long_sign ? 1 : o1 < o2) + ); + } + else + o1 = o1 < o2; + break; + case '>': + if (uns) { + o1 = (o1 & mach_long_sign ? + (o2 & mach_long_sign ? o1 > o2 : 1) : + (o2 & mach_long_sign ? 0 : o1 > o2) + ); + } + else + o1 = o1 > o2; + break; + case LESSEQ: + if (uns) { + o1 = (o1 & mach_long_sign ? + (o2 & mach_long_sign ? o1 <= o2 : 0) : + (o2 & mach_long_sign ? 1 : o1 <= o2) + ); + } + else + o1 = o1 <= o2; + break; + case GREATEREQ: + if (uns) { + o1 = (o1 & mach_long_sign ? + (o2 & mach_long_sign ? o1 >= o2 : 1) : + (o2 & mach_long_sign ? 0 : o1 >= o2) + ); + } + else + o1 = o1 >= o2; + break; + case EQUAL: + o1 = o1 == o2; + break; + case NOTEQUAL: + o1 = o1 != o2; + break; + case '&': + o1 &= o2; + break; + case '|': + o1 |= o2; + break; + case '^': + o1 ^= o2; + break; + } + (*expp)->VL_VALUE = o1; + cut_size(*expp); + (*expp)->ex_flags |= expr->ex_flags; + (*expp)->ex_flags &= ~EX_PARENS; +} + +cut_size(expr) + struct expr *expr; +{ + /* The constant value of the expression expr is made to + conform to the size of the type of the expression. + */ + arith o1 = expr->VL_VALUE; + int uns = expr->ex_type->tp_unsigned; + int size = (int) expr->ex_type->tp_size; + + if (uns) { + if (o1 & ~full_mask[size]) + expr_warning(expr, + "overflow in unsigned constant expression"); + o1 &= full_mask[size]; + } + else { + int nbits = (int) (mach_long_size - size) * 8; + long remainder = o1 & ~full_mask[size]; + + if (remainder != 0 && remainder != ~full_mask[size]) + expr_warning(expr, "overflow in constant expression"); + o1 <<= nbits; /* ??? */ + o1 >>= nbits; + } + expr->VL_VALUE = o1; +} + +init_cst() +{ + int i = 0; + arith bt = (arith)0; + + while (!(bt < 0)) { + bt = (bt << 8) + 0377, i++; + if (i == MAXSIZE) + fatal("array full_mask too small for this machine"); + full_mask[i] = bt; + } + mach_long_size = i; + mach_long_sign = 1 << (mach_long_size * 8 - 1); + if (long_size < mach_long_size) + fatal("sizeof (long) insufficient on this machine"); + + + max_int = full_mask[int_size] & ~(1 << (int_size * 8 - 1)); + max_unsigned = full_mask[int_size]; +} diff --git a/lang/cem/cemcom/dataflow.c b/lang/cem/cemcom/dataflow.c new file mode 100644 index 00000000..7d1d8836 --- /dev/null +++ b/lang/cem/cemcom/dataflow.c @@ -0,0 +1,34 @@ +/* $Header$ */ +/* DATAFLOW ANALYSIS ON C PROGRAMS */ + +/* Compile the C compiler with flag DATAFLOW. + Use the compiler option --d. +*/ + +#include "dataflow.h" /* UF */ + +#ifdef DATAFLOW +char *CurrentFunction = 0; +int NumberOfCalls; + +DfaStartFunction(nm) + char *nm; +{ + CurrentFunction = nm; + NumberOfCalls = 0; +} + +DfaEndFunction() +{ + if (NumberOfCalls == 0) { + printf("DFA: %s: --none--\n", CurrentFunction); + } +} + +DfaCallFunction(s) + char *s; +{ + printf("DFA: %s: %s\n", CurrentFunction, s); + ++NumberOfCalls; +} +#endif DATAFLOW diff --git a/lang/cem/cemcom/declar.g b/lang/cem/cemcom/declar.g new file mode 100644 index 00000000..a758193b --- /dev/null +++ b/lang/cem/cemcom/declar.g @@ -0,0 +1,473 @@ +/* $Header$ */ +/* DECLARATION SYNTAX PARSER */ + +{ +#include "nobitfield.h" +#include "debug.h" +#include "arith.h" +#include "LLlex.h" +#include "idf.h" +#include "type.h" +#include "struct.h" +#include "field.h" +#include "decspecs.h" +#include "def.h" +#include "declarator.h" +#include "label.h" +#include "expr.h" +#include "sizes.h" + +extern char options[]; +} + +/* 8 */ +declaration + {struct decspecs Ds;} +: + {Ds = null_decspecs;} + decl_specifiers(&Ds) + init_declarator_list(&Ds)? + ';' +; + +/* A `decl_specifiers' describes a sequence of a storage_class_specifier, + an unsigned_specifier, a size_specifier and a simple type_specifier, + which may occur in arbitrary order and each of which may be absent; + at least one of them must be present, however, since the totally + empty case has already be dealt with in `external_definition'. + This means that something like: + unsigned extern int short xx; + is perfectly good C. + + On top of that, multiple occurrences of storage_class_specifiers, + unsigned_specifiers and size_specifiers are errors, but a second + type_specifier should end the decl_specifiers and be treated as + the name to be declared (see the thin ice in RM11.1). + Such a language is not easily expressed in a grammar; enumeration + of the permutations is unattractive. We solve the problem by + having a regular grammar for the "soft" items, handling the single + occurrence of the type_specifier in the grammar (we have no choice), + collecting all data in a `struct decspecs' and turning that data + structure into what we want. + + The existence of declarations like + short typedef yepp; + makes all hope of writing a specific grammar for typedefs illusory. +*/ + +decl_specifiers /* non-empty */ (struct decspecs *ds;) + /* Reads a non-empty decl_specifiers and fills the struct + decspecs *ds. + */ +: +[ + other_specifier(ds)+ + [%prefer /* the thin ice in R.M. 11.1 */ + single_type_specifier(ds) other_specifier(ds)* + | + empty + ] +| + single_type_specifier(ds) other_specifier(ds)* +] + {do_decspecs(ds);} +; + +/* 8.1 */ +other_specifier(struct decspecs *ds;): +[ + [ AUTO | STATIC | EXTERN | TYPEDEF | REGISTER ] + { if (ds->ds_sc_given) + error("repeated storage class specifier"); + else { + ds->ds_sc_given = 1; + ds->ds_sc = DOT; + } + } +| + [ SHORT | LONG ] + { if (ds->ds_size) + error("repeated size specifier"); + else ds->ds_size = DOT; + } +| + UNSIGNED + { if (ds->ds_unsigned) + error("unsigned specified twice"); + else ds->ds_unsigned = 1; + } +] +; + +/* 8.2 */ +type_specifier(struct type **tpp;) + /* Used in struct/union declarations and in casts; only the + type is relevant. + */ + {struct decspecs Ds; Ds = null_decspecs;} +: + decl_specifiers(&Ds) + { + if (Ds.ds_sc_given) + error("storage class ignored"); + if (Ds.ds_sc == REGISTER) + error("register ignored"); + } + {*tpp = Ds.ds_type;} +; + +single_type_specifier(struct decspecs *ds;): +[ + TYPE_IDENTIFIER /* this includes INT, CHAR, etc. */ + {idf2type(dot.tk_idf, &ds->ds_type);} +| + struct_or_union_specifier(&ds->ds_type) +| + enum_specifier(&ds->ds_type) +] +; + +/* 8.3 */ +init_declarator_list(struct decspecs *ds;): + init_declarator(ds) + [ ',' init_declarator(ds) ]* +; + +init_declarator(struct decspecs *ds;) + { + struct declarator Dc; + struct expr *expr = (struct expr *) 0; + } +: + { + Dc = null_declarator; + } +[ + declarator(&Dc) + { + reject_params(&Dc); + declare_idf(ds, &Dc, level); + } + initializer(Dc.dc_idf, &expr)? + { + code_declaration(Dc.dc_idf, expr, level, ds->ds_sc); + free_expression(expr); + } +] + {remove_declarator(&Dc);} +; + +/* + Functions yielding pointers to functions must be declared as, e.g., + int (*hehe(par1, par2))() char *par1, *par2; {} + Since the function heading is read as a normal declarator, + we just include the (formal) parameter list in the declarator + description list dc. +*/ +declarator(struct declarator *dc;) + { + arith count; + struct idstack_item *is = 0; + } +: +[ + primary_declarator(dc) + [%while(1) /* int i (M + 2) / 4; + is a function, not an + old-fashioned initialization. + */ + '(' + formal_list(&is) ? /* semantic check later... */ + ')' + { + add_decl_unary(dc, FUNCTION, (arith)0, is); + is = 0; + } + | + arrayer(&count) + {add_decl_unary(dc, ARRAY, count, NO_PARAMS);} + ]* +| + '*' declarator(dc) + {add_decl_unary(dc, POINTER, (arith)0, NO_PARAMS);} +] +; + +primary_declarator(struct declarator *dc;) : +[ + identifier(&dc->dc_idf) +| + '(' declarator(dc) ')' +] +; + +arrayer(arith *sizep;) + { struct expr *expr; } +: + '[' + [ + constant_expression(&expr) + { + array_subscript(expr); + *sizep = expr->VL_VALUE; + free_expression(expr); + } + | + empty + { *sizep = (arith)-1; } + ] + ']' +; + +formal_list (struct idstack_item **is;) +: + formal(is) [ ',' formal(is) ]* +; + +formal(struct idstack_item **is;) + {struct idf *idf; } +: + identifier(&idf) + { + struct idstack_item *new = new_idstack_item(); + + new->is_idf = idf; + new->next = *is; + *is = new; + } +; + +/* Change 2 */ +enum_specifier(struct type **tpp;) + { + struct idf *idf; + arith l = (arith)0; + } +: + ENUM + [ + {declare_struct(ENUM, (struct idf *) 0, tpp);} + enumerator_pack(*tpp, &l) + | + identifier(&idf) + [ + {declare_struct(ENUM, idf, tpp);} + enumerator_pack(*tpp, &l) + | + {apply_struct(ENUM, idf, tpp);} + empty + ] + ] +; + +enumerator_pack(struct type *tp; arith *lp;) : + '{' + enumerator(tp, lp) + [%while(AHEAD != '}') /* >>> conflict on ',' */ + ',' + enumerator(tp, lp) + ]* + ','? /* optional trailing comma */ + '}' + {tp->tp_size = int_size;} + /* fancy implementations that put small enums in 1 byte + or so should start here. + */ +; + +enumerator(struct type *tp; arith *lp;) + { + struct idf *idf; + struct expr *expr; + } +: + identifier(&idf) + [ + '=' + constant_expression(&expr) + { + *lp = expr->VL_VALUE; + free_expression(expr); + } + ]? + {declare_enum(tp, idf, (*lp)++);} +; + +/* 8.5 */ +struct_or_union_specifier(struct type **tpp;) + { + int fund; + struct idf *idf; + } +: + [ STRUCT | UNION ] + {fund = DOT;} + [ + { + declare_struct(fund, (struct idf *)0, tpp); + } + struct_declaration_pack(*tpp) + | + identifier(&idf) + [ + { + declare_struct(fund, idf, tpp); + (idf->id_struct->tg_busy)++; + } + struct_declaration_pack(*tpp) + { + (idf->id_struct->tg_busy)--; + } + | + {apply_struct(fund, idf, tpp);} + empty + ] + ] +; + +struct_declaration_pack(struct type *stp;) + { + struct sdef **sdefp = &stp->tp_sdef; + arith size = (arith)0; + } +: + /* The size is only filled in after the whole struct has + been read, to prevent recursive definitions. + */ + '{' + struct_declaration(stp, &sdefp, &size)+ + '}' + {stp->tp_size = align(size, stp->tp_align);} +; + +struct_declaration(struct type *stp; struct sdef ***sdefpp; arith *szp;) + {struct type *tp;} +: + type_specifier(&tp) + struct_declarator_list(tp, stp, sdefpp, szp) + [ /* in some standard UNIX compilers the semicolon + is optional, would you believe! + */ + ';' + | + empty + {warning("no semicolon after declarator");} + ] +; + +struct_declarator_list(struct type *tp, *stp; + struct sdef ***sdefpp; arith *szp;) +: + struct_declarator(tp, stp, sdefpp, szp) + [ ',' struct_declarator(tp, stp, sdefpp, szp) ]* +; + +struct_declarator(struct type *tp; struct type *stp; + struct sdef ***sdefpp; arith *szp;) + { + struct declarator Dc; + struct field *fd = 0; + } +: + { + Dc = null_declarator; + } +[ + declarator(&Dc) + {reject_params(&Dc);} + bit_expression(&fd)? +| + {Dc.dc_idf = gen_idf();} + bit_expression(&fd) +] + {add_sel(stp, declare_type(tp, &Dc), Dc.dc_idf, sdefpp, szp, fd);} + {remove_declarator(&Dc);} +; + +bit_expression(struct field **fd;) + { struct expr *expr; } +: + { + *fd = new_field(); + } + ':' + constant_expression(&expr) + { + (*fd)->fd_width = expr->VL_VALUE; + free_expression(expr); +#ifdef NOBITFIELD + error("bitfields are not implemented"); +#endif NOBITFIELD + } +; + +/* 8.6 */ +initializer(struct idf *idf; struct expr **expp;) : + [ + '=' + | + empty + {warning("old-fashioned initialization, insert =");} + /* This causes trouble at declarator and at + external_definition, q.v. + */ + ] + initial_value(expp) + { + if (idf->id_def->df_type->tp_fund == FUNCTION) { + error("illegal initialization of function"); + free_expression(*expp); + *expp = 0; + } + init_idf(idf); +#ifdef DEBUG + print_expr("initializer-expression", *expp); +#endif DEBUG + } +; + +/* 8.7 */ +cast(struct type **tpp;) {struct declarator Dc;} : + {Dc = null_declarator;} + '(' + type_specifier(tpp) + abstract_declarator(&Dc) + ')' + {*tpp = declare_type(*tpp, &Dc);} + {remove_declarator(&Dc);} +; + +/* This code is an abject copy of that of 'declarator', for lack of + a two-level grammar. +*/ +abstract_declarator(struct declarator *dc;) + {arith count;} +: +[ + primary_abstract_declarator(dc) + [ + '(' ')' + {add_decl_unary(dc, FUNCTION, (arith)0, NO_PARAMS);} + | + arrayer(&count) + {add_decl_unary(dc, ARRAY, count, NO_PARAMS);} + ]* +| + '*' abstract_declarator(dc) + {add_decl_unary(dc, POINTER, (arith)0, NO_PARAMS);} +] +; + +primary_abstract_declarator(struct declarator *dc;) : +[%if (AHEAD == ')') + empty +| + '(' abstract_declarator(dc) ')' +] +; + +empty: +; + +/* 8.8 */ +/* included in the IDENTIFIER/TYPE_IDENTIFIER mechanism */ diff --git a/lang/cem/cemcom/declar.str b/lang/cem/cemcom/declar.str new file mode 100644 index 00000000..5ecbb70c --- /dev/null +++ b/lang/cem/cemcom/declar.str @@ -0,0 +1,45 @@ +/* $Header$ */ +/* DEFINITION OF DECLARATOR DESCRIPTORS */ + +/* A 'declarator' consists of an idf and a linked list of + language-defined unary operations: *, [] and (), called + decl_unary's. +*/ + +struct declarator { + struct declarator *next; + struct idf *dc_idf; + struct decl_unary *dc_decl_unary; + struct idstack_item *dc_fparams; /* params for function */ +}; + + +/* allocation definitions of struct declarator */ +/* ALLOCDEF "declarator" */ +extern char *st_alloc(); +extern struct declarator *h_declarator; +#define new_declarator() ((struct declarator *) \ + st_alloc((char **)&h_declarator, sizeof(struct declarator))) +#define free_declarator(p) st_free(p, h_declarator, sizeof(struct declarator)) + + +#define NO_PARAMS ((struct idstack_item *) 0) + +struct decl_unary { + struct decl_unary *next; + int du_fund; /* POINTER, ARRAY or FUNCTION */ + arith du_count; /* for ARRAYs only */ +}; + + +/* allocation definitions of struct decl_unary */ +/* ALLOCDEF "decl_unary" */ +extern char *st_alloc(); +extern struct decl_unary *h_decl_unary; +#define new_decl_unary() ((struct decl_unary *) \ + st_alloc((char **)&h_decl_unary, sizeof(struct decl_unary))) +#define free_decl_unary(p) st_free(p, h_decl_unary, sizeof(struct decl_unary)) + + +extern struct type *declare_type(); +extern struct declarator null_declarator; diff --git a/lang/cem/cemcom/declarator.c b/lang/cem/cemcom/declarator.c new file mode 100644 index 00000000..c23cfcdc --- /dev/null +++ b/lang/cem/cemcom/declarator.c @@ -0,0 +1,106 @@ +/* $Header$ */ +/* D E C L A R A T O R M A N I P U L A T I O N */ + +#include "botch_free.h" /* UF */ +#include "alloc.h" +#include "arith.h" +#include "type.h" +#include "Lpars.h" +#include "declarator.h" +#include "storage.h" +#include "idf.h" +#include "label.h" +#include "expr.h" +#include "sizes.h" + +struct declarator null_declarator; + +struct type * +declare_type(tp, dc) + struct type *tp; + struct declarator *dc; +{ + /* Applies the decl_unary list starting at dc->dc_decl_unary + to the type tp and returns the result. + */ + register struct decl_unary *du = dc->dc_decl_unary; + + while (du) { + tp = construct_type(du->du_fund, tp, du->du_count); + du = du->next; + } + return tp; +} + +add_decl_unary(dc, fund, count, is) + struct declarator *dc; + arith count; + struct idstack_item *is; +{ + /* A decl_unary describing a constructor with fundamental + type fund and with size count is inserted in front of the + declarator dc. + */ + register struct decl_unary *new = new_decl_unary(); + + clear((char *)new, sizeof(struct decl_unary)); + new->next = dc->dc_decl_unary; + new->du_fund = fund; + new->du_count = count; + if (is) { + if (dc->dc_decl_unary) { + /* paramlist only allowed at first decl_unary */ + error("formal parameter list discarded"); + } + else { + /* register the parameters */ + dc->dc_fparams = is; + } + } + dc->dc_decl_unary = new; +} + +remove_declarator(dc) + struct declarator *dc; +{ + /* The decl_unary list starting at dc->dc_decl_unary is + removed. + */ + register struct decl_unary *du = dc->dc_decl_unary; + + while (du) { + struct decl_unary *old_du = du; + + du = du->next; + free_decl_unary(old_du); + } +} + +reject_params(dc) + struct declarator *dc; +{ + /* The declarator is checked to have no parameters, if it + is a function. + */ + if (dc->dc_fparams) { + error("non_empty formal parameter pack"); + del_idfstack(dc->dc_fparams); + dc->dc_fparams = 0; + } +} + +array_subscript(expr) + struct expr *expr; +{ + arith size = expr->VL_VALUE; + + if (size < 0) { + error("negative number of array elements"); + expr->VL_VALUE = (arith)1; + } + else + if (size & ~max_unsigned) { /* absolute ridiculous */ + expr_error(expr, "overflow in array size"); + expr->VL_VALUE = (arith)1; + } +} diff --git a/lang/cem/cemcom/declarator.h b/lang/cem/cemcom/declarator.h new file mode 100644 index 00000000..5ecbb70c --- /dev/null +++ b/lang/cem/cemcom/declarator.h @@ -0,0 +1,45 @@ +/* $Header$ */ +/* DEFINITION OF DECLARATOR DESCRIPTORS */ + +/* A 'declarator' consists of an idf and a linked list of + language-defined unary operations: *, [] and (), called + decl_unary's. +*/ + +struct declarator { + struct declarator *next; + struct idf *dc_idf; + struct decl_unary *dc_decl_unary; + struct idstack_item *dc_fparams; /* params for function */ +}; + + +/* allocation definitions of struct declarator */ +/* ALLOCDEF "declarator" */ +extern char *st_alloc(); +extern struct declarator *h_declarator; +#define new_declarator() ((struct declarator *) \ + st_alloc((char **)&h_declarator, sizeof(struct declarator))) +#define free_declarator(p) st_free(p, h_declarator, sizeof(struct declarator)) + + +#define NO_PARAMS ((struct idstack_item *) 0) + +struct decl_unary { + struct decl_unary *next; + int du_fund; /* POINTER, ARRAY or FUNCTION */ + arith du_count; /* for ARRAYs only */ +}; + + +/* allocation definitions of struct decl_unary */ +/* ALLOCDEF "decl_unary" */ +extern char *st_alloc(); +extern struct decl_unary *h_decl_unary; +#define new_decl_unary() ((struct decl_unary *) \ + st_alloc((char **)&h_decl_unary, sizeof(struct decl_unary))) +#define free_decl_unary(p) st_free(p, h_decl_unary, sizeof(struct decl_unary)) + + +extern struct type *declare_type(); +extern struct declarator null_declarator; diff --git a/lang/cem/cemcom/decspecs.c b/lang/cem/cemcom/decspecs.c new file mode 100644 index 00000000..7cc5a211 --- /dev/null +++ b/lang/cem/cemcom/decspecs.c @@ -0,0 +1,92 @@ +/* $Header$ */ +/* D E C L A R A T I O N S P E C I F I E R C H E C K I N G */ + +#include "Lpars.h" +#include "decspecs.h" +#include "arith.h" +#include "type.h" +#include "level.h" +#include "def.h" + +extern char options[]; +extern int level; +extern char *symbol2str(); + +struct decspecs null_decspecs; + +do_decspecs(ds) + struct decspecs *ds; +{ + /* The provisional decspecs ds as obtained from the program + is turned into a legal consistent decspecs. + */ + struct type *tp = ds->ds_type; + + if (level == L_FORMAL1) + crash("do_decspecs"); + + if ( level == L_GLOBAL && + (ds->ds_sc == AUTO || ds->ds_sc == REGISTER) + ) { + warning("no global %s variable allowed", + symbol2str(ds->ds_sc)); + ds->ds_sc = GLOBAL; + } + + if (level == L_FORMAL2) { + if (ds->ds_sc_given && ds->ds_sc != AUTO && + ds->ds_sc != REGISTER){ + extern char *symbol2str(); + error("%s formal illegal", symbol2str(ds->ds_sc)); + } + ds->ds_sc = FORMAL; + } + /* The tests concerning types require a full knowledge of the + type and will have to be postponed to declare_idf. + */ + + /* some adjustments as described in RM 8.2 */ + if (tp == 0) + tp = int_type; + switch (ds->ds_size) { + case SHORT: + if (tp == int_type) + tp = short_type; + else error("short with illegal type"); + break; + case LONG: + if (tp == int_type) + tp = long_type; + else + if (tp == float_type) + tp = double_type; + else error("long with illegal type"); + break; + } + if (ds->ds_unsigned) { + switch (tp->tp_fund) { + case CHAR: + if (options['R']) + warning("unsigned char not allowed"); + tp = uchar_type; + break; + case SHORT: + if (options['R']) + warning("unsigned short not allowed"); + tp = ushort_type; + break; + case INT: + tp = uint_type; + break; + case LONG: + if (options['R']) + warning("unsigned long not allowed"); + tp = ulong_type; + break; + default: + error("unsigned with illegal type"); + break; + } + } + ds->ds_type = tp; +} diff --git a/lang/cem/cemcom/decspecs.h b/lang/cem/cemcom/decspecs.h new file mode 100644 index 00000000..0b1598c0 --- /dev/null +++ b/lang/cem/cemcom/decspecs.h @@ -0,0 +1,23 @@ +/* $Header$ */ +/* DECLARATION SPECIFIER DEFINITION */ + +struct decspecs { + struct decspecs *next; + struct type *ds_type; /* single type */ + int ds_sc_given; /* 1 if the st. class is explicitly given */ + int ds_sc; /* storage class, given or implied */ + int ds_size; /* LONG, SHORT or 0 */ + int ds_unsigned; /* 0 or 1 */ +}; + + +/* allocation definitions of struct decspecs */ +/* ALLOCDEF "decspecs" */ +extern char *st_alloc(); +extern struct decspecs *h_decspecs; +#define new_decspecs() ((struct decspecs *) \ + st_alloc((char **)&h_decspecs, sizeof(struct decspecs))) +#define free_decspecs(p) st_free(p, h_decspecs, sizeof(struct decspecs)) + + +extern struct decspecs null_decspecs; diff --git a/lang/cem/cemcom/decspecs.str b/lang/cem/cemcom/decspecs.str new file mode 100644 index 00000000..0b1598c0 --- /dev/null +++ b/lang/cem/cemcom/decspecs.str @@ -0,0 +1,23 @@ +/* $Header$ */ +/* DECLARATION SPECIFIER DEFINITION */ + +struct decspecs { + struct decspecs *next; + struct type *ds_type; /* single type */ + int ds_sc_given; /* 1 if the st. class is explicitly given */ + int ds_sc; /* storage class, given or implied */ + int ds_size; /* LONG, SHORT or 0 */ + int ds_unsigned; /* 0 or 1 */ +}; + + +/* allocation definitions of struct decspecs */ +/* ALLOCDEF "decspecs" */ +extern char *st_alloc(); +extern struct decspecs *h_decspecs; +#define new_decspecs() ((struct decspecs *) \ + st_alloc((char **)&h_decspecs, sizeof(struct decspecs))) +#define free_decspecs(p) st_free(p, h_decspecs, sizeof(struct decspecs)) + + +extern struct decspecs null_decspecs; diff --git a/lang/cem/cemcom/def.h b/lang/cem/cemcom/def.h new file mode 100644 index 00000000..abb28155 --- /dev/null +++ b/lang/cem/cemcom/def.h @@ -0,0 +1,37 @@ +/* $Header$ */ +/* IDENTIFIER DEFINITION DESCRIPTOR */ + +struct def { /* for ordinary tags */ + struct def *next; + int df_level; + struct type *df_type; + int df_sc; /* may be: + GLOBAL, STATIC, EXTERN, IMPLICIT, + TYPEDEF, + FORMAL, AUTO, + ENUM, LABEL + */ + int df_register; /* REG_NONE, REG_DEFAULT or REG_BONUS */ + char df_initialized; /* an initialization has been generated */ + char df_alloc; /* 0, ALLOC_SEEN or ALLOC_DONE */ + char df_used; /* set if idf is used */ + char df_formal_array; /* to warn if sizeof is taken */ + arith df_address; +}; + +#define ALLOC_SEEN 1 /* an allocating declaration has been seen */ +#define ALLOC_DONE 2 /* the allocating declaration has been done */ + +#define REG_NONE 0 /* no register candidate */ +#define REG_DEFAULT 1 /* register candidate, not declared as such */ +#define REG_BONUS 10 /* register candidate, declared as such */ + + +/* allocation definitions of struct def */ +/* ALLOCDEF "def" */ +extern char *st_alloc(); +extern struct def *h_def; +#define new_def() ((struct def *) \ + st_alloc((char **)&h_def, sizeof(struct def))) +#define free_def(p) st_free(p, h_def, sizeof(struct def)) + diff --git a/lang/cem/cemcom/def.str b/lang/cem/cemcom/def.str new file mode 100644 index 00000000..abb28155 --- /dev/null +++ b/lang/cem/cemcom/def.str @@ -0,0 +1,37 @@ +/* $Header$ */ +/* IDENTIFIER DEFINITION DESCRIPTOR */ + +struct def { /* for ordinary tags */ + struct def *next; + int df_level; + struct type *df_type; + int df_sc; /* may be: + GLOBAL, STATIC, EXTERN, IMPLICIT, + TYPEDEF, + FORMAL, AUTO, + ENUM, LABEL + */ + int df_register; /* REG_NONE, REG_DEFAULT or REG_BONUS */ + char df_initialized; /* an initialization has been generated */ + char df_alloc; /* 0, ALLOC_SEEN or ALLOC_DONE */ + char df_used; /* set if idf is used */ + char df_formal_array; /* to warn if sizeof is taken */ + arith df_address; +}; + +#define ALLOC_SEEN 1 /* an allocating declaration has been seen */ +#define ALLOC_DONE 2 /* the allocating declaration has been done */ + +#define REG_NONE 0 /* no register candidate */ +#define REG_DEFAULT 1 /* register candidate, not declared as such */ +#define REG_BONUS 10 /* register candidate, declared as such */ + + +/* allocation definitions of struct def */ +/* ALLOCDEF "def" */ +extern char *st_alloc(); +extern struct def *h_def; +#define new_def() ((struct def *) \ + st_alloc((char **)&h_def, sizeof(struct def))) +#define free_def(p) st_free(p, h_def, sizeof(struct def)) + diff --git a/lang/cem/cemcom/domacro.c b/lang/cem/cemcom/domacro.c new file mode 100644 index 00000000..5407591a --- /dev/null +++ b/lang/cem/cemcom/domacro.c @@ -0,0 +1,673 @@ +/* $Header$ */ +/* PREPROCESSOR: CONTROLLINE INTERPRETER */ + +#include "interface.h" +#include "arith.h" +#include "LLlex.h" +#include "Lpars.h" +#include "debug.h" +#include "idf.h" +#include "input.h" +#include "nopp.h" + +#ifndef NOPP +#include "ifdepth.h" +#include "botch_free.h" +#include "nparams.h" +#include "parbufsize.h" +#include "textsize.h" +#include "idfsize.h" + +#include "assert.h" +#include "alloc.h" +#include "class.h" +#include "macro.h" +#include "storage.h" + +IMPORT char *inctable[]; /* list of include directories */ +PRIVATE char ifstack[IFDEPTH]; /* if-stack: the content of an entry is */ + /* 1 if a corresponding ELSE has been */ + /* encountered. */ +PRIVATE int nestlevel = -1; /* initially no nesting level. */ + +PRIVATE struct idf * +GetIdentifier() +{ + /* returns a pointer to the descriptor of the identifier that is + read from the input stream. A null-pointer is returned if + the input does not contain an identifier. + The substitution of macros is disabled. + */ + int tok; + struct token tk; + + ReplaceMacros = 0; + tok = GetToken(&tk); + ReplaceMacros = 1; + return tok == IDENTIFIER ? tk.tk_idf : (struct idf *)0; +} + +/* domacro() is the control line interpreter. The '#' has already + been read by the lexical analyzer by which domacro() is called. + The token appearing directly after the '#' is obtained by calling + the basic lexical analyzing function GetToken() and is interpreted + to perform the action belonging to that token. + An error message is produced when the token is not recognized, + i.e. it is not one of "define" .. "undef" , integer or newline. +*/ +EXPORT +domacro() +{ + struct token tk; /* the token itself */ + + EoiForNewline = 1; + SkipEscNewline = 1; + switch(GetToken(&tk)) { /* select control line action */ + case IDENTIFIER: /* is it a macro keyword? */ + switch (tk.tk_idf->id_resmac) { + case K_DEFINE: /* "define" */ + do_define(); + break; + case K_ELIF: /* "elif" */ + do_elif(); + break; + case K_ELSE: /* "else" */ + do_else(); + break; + case K_ENDIF: /* "endif" */ + do_endif(); + break; + case K_IF: /* "if" */ + do_if(); + break; + case K_IFDEF: /* "ifdef" */ + do_ifdef(1); + break; + case K_IFNDEF: /* "ifndef" */ + do_ifdef(0); + break; + case K_INCLUDE: /* "include" */ + do_include(); + break; + case K_LINE: /* "line" */ + /* set LineNumber and FileName according to + the arguments. + */ + if (GetToken(&tk) != INTEGER) { + lexerror("#line without linenumber"); + SkipRestOfLine(); + } + else + do_line((unsigned int)tk.tk_ival); + break; + case K_UNDEF: /* "undef" */ + do_undef(); + break; + default: + /* invalid word seen after the '#' */ + lexerror("%s: unknown control", tk.tk_idf->id_text); + SkipRestOfLine(); + } + break; + case INTEGER: /* # []? */ + do_line((unsigned int)tk.tk_ival); + break; + case EOI: /* only `#' on this line: do nothing, ignore */ + break; + default: /* invalid token following '#' */ + lexerror("illegal # line"); + SkipRestOfLine(); + } + EoiForNewline = 0; + SkipEscNewline = 0; +} + +PRIVATE +skip_block() +{ + /* skip_block() skips the input from + 1) a false #if, #ifdef, #ifndef or #elif until the + corresponding #elif (resulting in true), #else or + #endif is read. + 2) a #else corresponding to a true #if, #ifdef, + #ifndef or #elif until the corresponding #endif is + seen. + */ + register int ch; + register skiplevel = nestlevel; /* current nesting level */ + struct token tk; + + NoUnstack++; + for (;;) { + LoadChar(ch); /* read first character after newline */ + if (ch != '#') { + if (ch == EOI) { + NoUnstack--; + return; + } + SkipRestOfLine(); + continue; + } + if (GetToken(&tk) != IDENTIFIER) { + SkipRestOfLine(); + continue; + } + /* an IDENTIFIER: look for #if, #ifdef and #ifndef + without interpreting them. + Interpret #else, #elif and #endif if they occur + on the same level. + */ + switch(tk.tk_idf->id_resmac) { + case K_IF: + case K_IFDEF: + case K_IFNDEF: + push_if(); + break; + case K_ELIF: + if (nestlevel == skiplevel) { + nestlevel--; + push_if(); + if (ifexpr()) { + NoUnstack--; + return; + } + } + break; + case K_ELSE: + ++(ifstack[nestlevel]); + if (nestlevel == skiplevel) { + SkipRestOfLine(); + NoUnstack--; + return; + } + break; + case K_ENDIF: + ASSERT(nestlevel >= 0); + if (nestlevel == skiplevel) { + SkipRestOfLine(); + nestlevel--; + NoUnstack--; + return; + } + nestlevel--; + break; + } + } +} + +PRIVATE +ifexpr() +{ + /* ifexpr() returns whether the restricted constant + expression following #if or #elif evaluates to true. This + is done by calling the LLgen generated subparser for + constant expressions. The result of this expression will + be given in the extern long variable "ifval". + */ + IMPORT arith ifval; + int errors = err_occurred; + + ifval = (arith)0; + AccDefined = 1; + UnknownIdIsZero = 1; + PushLex(); /* NEW parser */ + If_expr(); /* invoke constant expression parser */ + PopLex(); /* OLD parser */ + AccDefined = 0; + UnknownIdIsZero = 0; + return (errors == err_occurred) && (ifval != (arith)0); +} + +PRIVATE +do_include() +{ + /* do_include() performs the inclusion of a file. + */ + char *filenm; + int tok; + struct token tk; + + AccFileSpecifier = 1; + if (((tok = GetToken(&tk)) == FILESPECIFIER) || tok == STRING) + filenm = tk.tk_str; + else { + lexerror("bad include syntax"); + filenm = (char *)0; + } + AccFileSpecifier = 0; + SkipRestOfLine(); + if (filenm && !InsertFile(filenm, &inctable[tok == FILESPECIFIER])) + lexerror("cannot find include file \"%s\"", filenm); +} + +PRIVATE +do_define() +{ + /* do_define() interprets a #define control line. + */ + struct idf *id; /* the #defined identifier's descriptor */ + int nformals = -1; /* keep track of the number of formals */ + char *formals[NPARAMS]; /* pointers to the names of the formals */ + char parbuf[PARBUFSIZE]; /* names of formals */ + char *repl_text; /* start of the replacement text */ + int length; /* length of the replacement text */ + register ch; + char *get_text(); + + /* read the #defined macro's name */ + if (!(id = GetIdentifier())) { + lexerror("#define: illegal macro name"); + SkipRestOfLine(); + return; + } + /* there is a formal parameter list if the identifier is + followed immediately by a '('. + */ + LoadChar(ch); + if (ch == '(') { + if ((nformals = getparams(formals, parbuf)) == -1) { + SkipRestOfLine(); + return; /* an error occurred */ + } + LoadChar(ch); + } + /* read the replacement text if there is any */ + ch = skipspaces(ch); /* find first character of the text */ + ASSERT(ch != EOI); + if (class(ch) == STNL) { + /* Treat `#define something' as `#define something ""' + */ + repl_text = ""; + length = 0; + } + else { + PushBack(); + repl_text = get_text((nformals > 0) ? formals : 0, &length); + } + macro_def(id, repl_text, nformals, length, NOFLAG); + LineNumber++; +} + +PRIVATE +push_if() +{ + if (nestlevel >= IFDEPTH) + fatal("too many nested #if/#ifdef/#ifndef"); + else + ifstack[++nestlevel] = 0; +} + +PRIVATE +do_elif() +{ + if (nestlevel < 0 || (ifstack[nestlevel])) { + /* invalid elif encountered.. */ + lexerror("#elif without corresponding #if"); + SkipRestOfLine(); + } + else { + /* restart at this level as if a #if + is detected. + */ + nestlevel--; + push_if(); + skip_block(); + } +} + +PRIVATE +do_else() +{ + SkipRestOfLine(); + if (nestlevel < 0 || (ifstack[nestlevel])) + lexerror("#else without corresponding #if"); + else { /* mark this level as else-d */ + ++(ifstack[nestlevel]); + skip_block(); + } +} + +PRIVATE +do_endif() +{ + SkipRestOfLine(); + if (nestlevel-- < 0) + lexerror("#endif without corresponding #if"); +} + +PRIVATE +do_if() +{ + push_if(); + if (!ifexpr()) /* a false #if/#elif expression */ + skip_block(); +} + +PRIVATE +do_ifdef(how) +{ + struct idf *id; + + /* how == 1 : ifdef; how == 0 : ifndef + */ + push_if(); + if (id = GetIdentifier()) { + if ((how && !(id && id->id_macro)) || + (!how && id && id->id_macro)) + { /* this id is not defined */ + skip_block(); + } + else + SkipRestOfLine(); + } + else { + lexerror("illegal #ifdef construction"); + SkipRestOfLine(); + } +} + +PRIVATE +do_undef() +{ + struct idf *id; + + /* Forget a macro definition. */ + if (id = GetIdentifier()) { + if (id && id->id_macro) { /* forget the macro */ + free_macro(id->id_macro); + id->id_macro = (struct macro *) 0; + } + /* else: don't complain */ + } + else + lexerror("illegal #undef construction"); + SkipRestOfLine(); +} + +PRIVATE +do_line(l) + unsigned int l; +{ + struct token tk; + + LineNumber = l; + /* is there a filespecifier? */ + if (GetToken(&tk) == STRING) + FileName = tk.tk_str; + SkipRestOfLine(); +} + +PRIVATE int +getparams(buf, parbuf) + char *buf[]; + char parbuf[]; +{ + /* getparams() reads the formal parameter list of a macro + definition. + The number of parameters is returned. + As a formal parameter list is expected when calling this + routine, -1 is returned if an error is detected, for + example: + #define one(1), where 1 is not an identifier. + Note that the '(' has already been eaten. + The names of the formal parameters are stored into parbuf. + */ + register count = 0; + register c; + register char *ptr = &parbuf[0]; + + LoadChar(c); + c = skipspaces(c); + if (c == ')') { /* no parameters: #define name() */ + buf[0] = (char *) 0; + return 0; + } + for (;;) { /* eat the formal parameter list */ + if (class(c) != STIDF) { /* not an identifier */ + lexerror("#define: bad formal parameter"); + return -1; + } + buf[count++] = ptr; /* name of the formal */ + *ptr++ = c; + if (ptr >= &parbuf[PARBUFSIZE]) + fatal("formal parameter buffer overflow"); + do { /* eat the identifier name */ + LoadChar(c); + *ptr++ = c; + if (ptr >= &parbuf[PARBUFSIZE]) + fatal("formal parameter buffer overflow"); + } while (in_idf(c)); + *(ptr - 1) = '\0'; /* mark end of the name */ + c = skipspaces(c); + if (c == ')') { /* end of the formal parameter list */ + buf[count] = (char *) 0; + return count; + } + if (c != ',') { + lexerror("#define: bad formal parameter list"); + return -1; + } + LoadChar(c); + c = skipspaces(c); + } +} + +EXPORT +macro_def(id, text, nformals, length, flags) + struct idf *id; + char *text; +{ + register struct macro *newdef = id->id_macro; + + /* macro_def() puts the contents and information of a macro + definition into a structure and stores it into the symbol + table entry belonging to the name of the macro. + A warning is given if the definition overwrites another + (unless predefined!) + */ + if (newdef) { /* is there a redefinition? */ + if ((newdef->mc_flag & PREDEF) == 0) { + if (macroeq(newdef->mc_text, text)) + return; + lexwarning("redefine \"%s\"", id->id_text); + } + /* else: overwrite pre-definition */ + } + else + id->id_macro = newdef = new_macro(); + newdef->mc_text = text; /* replacement text */ + newdef->mc_nps = nformals; /* nr of formals */ + newdef->mc_length = length; /* length of repl. text */ + newdef->mc_flag = flags; /* special flags */ +} + +PRIVATE int +find_name(nm, index) + char *nm, *index[]; +{ + /* find_name() returns the index of "nm" in the namelist + "index" if it can be found there. 0 is returned if it is + not there. + */ + register char **ip = &index[0]; + + while (*ip) + if (strcmp(nm, *ip++) == 0) + return ip - &index[0]; + /* arrived here, nm is not in the name list. */ + return 0; +} + +PRIVATE char * +get_text(formals, length) + char *formals[]; + int *length; +{ + /* get_text() copies the replacement text of a macro + definition with zero, one or more parameters, thereby + substituting each formal parameter by a special character + (non-ascii: 0200 & (order-number in the formal parameter + list)) in order to substitute this character later by the + actual parameter. The replacement text is copied into + itself because the copied text will contain fewer or the + same amount of characters. The length of the replacement + text is returned. + + Implementation: + finite automaton : we are only interested in + identifiers, because they might be replaced by some actual + parameter. Other tokens will not be seen as such. + */ + register c; + register text_size; + char *text = Malloc(text_size = ITEXTSIZE); + register pos = 0; + + LoadChar(c); + + while ((c != EOI) && (class(c) != STNL)) { + if (c == '\\') { /* check for "\\\n" */ + LoadChar(c); + if (c == '\n') { + /* more than one line is used for the + replacement text. Replace "\\\n" by " ". + */ + text[pos++] = ' '; + ++LineNumber; + LoadChar(c); + } + else + text[pos++] = '\\'; + if (pos == text_size) + text = Srealloc(text, text_size += RTEXTSIZE); + } + else + if ( c == '/') { + LoadChar(c); + if (c == '*') { + skipcomment(); + text[pos++] = ' '; + LoadChar(c); + } + else + text[pos++] = '/'; + if (pos == text_size) + text = Srealloc(text, text_size += RTEXTSIZE); + } + else + if (formals && class(c) == STIDF) { + char id_buf[IDFSIZE + 1]; + register id_size = 0; + register n; + + /* read identifier: it may be a formal parameter */ + id_buf[id_size++] = c; + do { + LoadChar(c); + if (id_size <= IDFSIZE) + id_buf[id_size++] = c; + } while (in_idf(c)); + id_buf[--id_size] = '\0'; + if (n = find_name(id_buf, formals)) { + /* construct the formal parameter mark */ + text[pos++] = FORMALP | (char) n; + if (pos == text_size) + text = Srealloc(text, + text_size += RTEXTSIZE); + } + else { + register char *ptr = &id_buf[0]; + + while (pos + id_size >= text_size) + text = Srealloc(text, + text_size += RTEXTSIZE); + while (text[pos++] = *ptr++) ; + pos--; + } + } + else { + text[pos++] = c; + if (pos == text_size) + text = Srealloc(text, text_size += RTEXTSIZE); + LoadChar(c); + } + } + text[pos++] = '\0'; + *length = pos - 1; + return text; +} + +#define BLANK(ch) ((ch == ' ') || (ch == '\t')) + +/* macroeq() decides whether two macro replacement texts are + identical. This version compares the texts, which occur + as strings, without taking care of the leading and trailing + blanks (spaces and tabs). +*/ +PRIVATE +macroeq(s, t) + register char *s, *t; +{ + + /* skip leading spaces */ + while (BLANK(*s)) s++; + while (BLANK(*t)) t++; + /* first non-blank encountered in both strings */ + /* The actual comparison loop: */ + while (*s && *s == *t) + s++, t++; + /* two cases are possible when arrived here: */ + if (*s == '\0') { /* *s == '\0' */ + while (BLANK(*t)) t++; + return *t == '\0'; + } + else { /* *s != *t */ + while (BLANK(*s)) s++; + while (BLANK(*t)) t++; + return (*s == '\0') && (*t == '\0'); + } +} +#else NOPP +EXPORT +domacro() +{ + int tok; + struct token tk; + + EoiForNewline = 1; + SkipEscNewline = 1; + if ((tok = GetToken(&tk)) == IDENTIFIER) { + if (strcmp(tk.tk_idf->id_text, "line") != 0) { + error("illegal # line"); + SkipRestOfLine(); + return; + } + tok = GetToken(&tk); + } + if (tok != INTEGER) { + error("illegal # line"); + SkipRestOfLine(); + return; + } + LineNumber = tk.tk_ival; + if ((tok = GetToken(&tk)) == STRING) + FileName = tk.tk_str; + else + if (tok != EOI) { + error("illegal # line"); + SkipRestOfLine(); + } + EoiForNewline = 0; + SkipEscNewline = 0; +} +#endif NOPP + +PRIVATE +SkipRestOfLine() +{ + /* we do a PushBack because we don't want to skip the next line + if the last character was a newline + */ + PushBack(); + skipline(); +} diff --git a/lang/cem/cemcom/dumpidf.c b/lang/cem/cemcom/dumpidf.c new file mode 100644 index 00000000..e370512b --- /dev/null +++ b/lang/cem/cemcom/dumpidf.c @@ -0,0 +1,367 @@ +/* $Header$ */ +/* DUMP ROUTINES */ + +#include "debug.h" + +#ifdef DEBUG +#include "nopp.h" +#include "nobitfield.h" +#include "arith.h" +#include "stack.h" +#include "idf.h" +#include "def.h" +#include "type.h" +#include "struct.h" +#include "field.h" +#include "Lpars.h" +#include "label.h" +#include "expr.h" + +/* Some routines (symbol2str, token2str, type2str) which should have + * yielded strings are written to yield a pointer to a transient piece + * of memory, containing the string, since this is the only reasonable + * thing to do in C. `Transient' means that the result may soon + * disappear, which is generally not a problem, since normally it is + * consumed immediately. Sometimes we need more than one of them, and + * MAXTRANS is the maximum number we will need simultaneously. + */ +#define MAXTRANS 6 + +extern char options[]; + +extern char *sprintf(); + +extern struct idf *idf_hashtable[]; +extern char *symbol2str(), *type2str(), *next_transient(); + +enum sdef_kind {selector, field}; /* parameter for dumpsdefs */ + +static int dumplevel; + +static +newline() { + int dl = dumplevel; + + printf("\n"); + while (dl >= 2) { + printf("\t"); + dl -= 2; + } + if (dl) + printf(" "); +} + +dumpidftab(msg, opt) + char msg[]; +{ + /* Dumps the identifier table in readable form (but in + arbitrary order). + Unless opt & 1, macros are not dumped. + Unless opt & 2, reserved identifiers are not dumped. + Unless opt & 4, universal identifiers are not dumped. + */ + int i; + + printf(">>> DUMPIDF, %s (start)", msg); + dumpstack(); + for (i = 0; i < HASHSIZE; i++) { + struct idf *notch = idf_hashtable[i]; + + while (notch) { + dumpidf(notch, opt); + notch = notch->next; + } + } + newline(); + printf(">>> DUMPIDF, %s (end)\n", msg); +} + +dumpstack() { + /* Dumps the identifier stack, starting at the top. + */ + struct stack_level *stl = local_level; + + while (stl) { + struct stack_entry *se = stl->sl_entry; + + newline(); + printf("%3d: ", stl->sl_level); + while (se) { + printf("%s ", se->se_idf->id_text); + se = se->next; + } + stl = stl->sl_previous; + } + printf("\n"); +} + +dumpidf(idf, opt) + struct idf *idf; +{ + /* All information about the identifier idf is divulged in a + hopefully readable format. + */ + int started = 0; + + if (!idf) + return; +#ifndef NOPP + if ((opt&1) && idf->id_macro) { + if (!started++) { + newline(); + printf("%s:", idf->id_text); + } + printf(" macro"); + } +#endif NOPP + if ((opt&2) && idf->id_reserved) { + if (!started++) { + newline(); + printf("%s:", idf->id_text); + } + printf(" reserved: %d;", idf->id_reserved); + } + if (idf->id_def && ((opt&4) || idf->id_def->df_level)) { + if (!started++) { + newline(); + printf("%s:", idf->id_text); + } + dumpdefs(idf->id_def, opt); + } + if (idf->id_sdef) { + if (!started++) { + newline(); + printf("%s:", idf->id_text); + } + dumpsdefs(idf->id_sdef, selector); + } + if (idf->id_struct) { + if (!started++) { + newline(); + printf("%s:", idf->id_text); + } + dumptags(idf->id_struct); + } + if (idf->id_enum) { + if (!started++) { + newline(); + printf("%s:", idf->id_text); + } + dumptags(idf->id_enum); + } +} + +dumpdefs(def, opt) + register struct def *def; +{ + dumplevel++; + while (def && ((opt&4) || def->df_level)) { + newline(); + printf("L%d: %s %s%s%s%s%s %lo;", + def->df_level, + symbol2str(def->df_sc), + (def->df_register != REG_NONE) ? "reg " : "", + def->df_initialized ? "init'd " : "", + def->df_used ? "used " : "", + type2str(def->df_type), + def->df_sc == ENUM ? ", =" : " at", + def->df_address + ); + def = def->next; + } + dumplevel--; +} + +dumptags(tag) + struct tag *tag; +{ + dumplevel++; + while (tag) { + register struct type *tp = tag->tg_type; + register int fund = tp->tp_fund; + + newline(); + printf("L%d: %s %s", + tag->tg_level, + fund == STRUCT ? "struct" : + fund == UNION ? "union" : + fund == ENUM ? "enum" : "", + tp->tp_idf->id_text + ); + if (is_struct_or_union(fund)) { + printf(" {"); + dumpsdefs(tp->tp_sdef, field); + newline(); + printf("}"); + } + printf(";"); + tag = tag->next; + } + dumplevel--; +} + +dumpsdefs(sdef, sdk) + struct sdef *sdef; + enum sdef_kind sdk; +{ + /* Since sdef's are members of two chains, there are actually + two dumpsdefs's, one following the chain of all selectors + belonging to the same idf, starting at idf->id_sdef; + and the other following the chain of all selectors belonging + to the same struct, starting at stp->tp_sdef. + */ + + dumplevel++; + while (sdef) { + newline(); + printf("L%d: ", sdef->sd_level); +#ifndef NOBITFIELD + if (sdk == selector) +#endif NOBITFIELD + printf("selector %s at offset %lu in %s;", + type2str(sdef->sd_type), + sdef->sd_offset, type2str(sdef->sd_stype) + ); +#ifndef NOBITFIELD + else printf("field %s at offset %lu;", + type2str(sdef->sd_type), sdef->sd_offset + ); +#endif NOBITFIELD + sdef = (sdk == selector ? sdef->next : sdef->sd_sdef); + } + dumplevel--; +} + +char * +type2str(tp) + struct type *tp; +{ + /* Yields a pointer to a one-line description of the type tp. + */ + char *buf = next_transient(); + int ops = 1; + + buf[0] = '\0'; + if (!tp) { + sprintf(buf, ""); + return buf; + } + sprintf(buf, "(@%lx, #%ld, &%d) ", tp, (long)tp->tp_size, tp->tp_align); + while (ops) { + switch (tp->tp_fund) { + case POINTER: + sprintf(buf, "%spointer to ", buf); + break; + case ARRAY: + sprintf(buf, "%sarray [%ld] of ", buf, tp->tp_size); + break; + case FUNCTION: + sprintf(buf, "%sfunction yielding ", buf); + break; + default: + sprintf(buf, "%s%s%s", buf, + tp->tp_unsigned ? "unsigned " : "", + symbol2str(tp->tp_fund) + ); + if (tp->tp_idf) + sprintf(buf, "%s %s", buf, + tp->tp_idf->id_text); +#ifndef NOBITFIELD + if (tp->tp_field) { + struct field *fd = tp->tp_field; + + sprintf(buf, "%s [s=%ld,w=%ld]", buf, + fd->fd_shift, fd->fd_width); + } +#endif NOBITFIELD + ops = 0; + break; + } + tp = tp->tp_up; + } + return buf; +} + +char * /* the ultimate transient buffer supplier */ +next_transient() { + static int bnum; + static char buf[MAXTRANS][300]; + + if (++bnum == MAXTRANS) + bnum = 0; + return buf[bnum]; +} + +print_expr(msg, expr) + char msg[]; + struct expr *expr; +{ + /* Provisional routine to print an expression preceded by a + message msg. + */ + if (options['x']) { + printf("\n%s: ", msg); + printf("(L=line, T=type, r/lV=r/lvalue, F=flags, D=depth)\n"); + p1_expr(0, expr); + } +} + +p1_expr(lvl, expr) + struct expr *expr; +{ + extern char *type2str(), *symbol2str(); + + p1_indent(lvl); + if (!expr) { + printf("NILEXPR\n"); + return; + } + printf("expr: L=%u, T=%s, %cV, F=%02o, D=%d, %s: ", + expr->ex_line, + type2str(expr->ex_type), + expr->ex_lvalue ? 'l' : 'r', + expr->ex_flags, + expr->ex_depth, + expr->ex_class == Value ? "Value" : + expr->ex_class == String ? "String" : + expr->ex_class == Float ? "Float" : + expr->ex_class == Oper ? "Oper" : + expr->ex_class == Type ? "Type" : "UNKNOWN CLASS" + ); + switch (expr->ex_class) { + struct value *v; + struct oper *o; + case Value: + v = &expr->ex_object.ex_value; + if (v->vl_idf) + printf("%s + ", v->vl_idf->id_text); + printf(expr->ex_type->tp_unsigned ? "%lu\n" : "%ld\n", + v->vl_value); + break; + case String: + printf("%s\n", expr->SG_VALUE); + break; + case Float: + printf("%s\n", expr->FL_VALUE); + break; + case Oper: + o = &expr->ex_object.ex_oper; + printf("\n"); + p1_expr(lvl+1, o->op_left); + p1_indent(lvl); printf("%s\n", symbol2str(o->op_oper)); + p1_expr(lvl+1, o->op_right); + break; + case Type: + printf("\n"); + break; + default: + printf("UNKNOWN CLASS\n"); + break; + } +} + +p1_indent(lvl) { + while (lvl--) + printf(" "); +} +#endif DEBUG diff --git a/lang/cem/cemcom/em.c b/lang/cem/cemcom/em.c new file mode 100644 index 00000000..62c6024d --- /dev/null +++ b/lang/cem/cemcom/em.c @@ -0,0 +1,219 @@ +/* $Header$ */ +/* EM CODE OUTPUT ROUTINES */ + +#define CMODE 0644 +#define MAX_ARG_CNT 32 + +#include "em.h" +#include "system.h" +#include "bufsiz.h" +#include "arith.h" +#include "label.h" + +/* + putbyte(), C_open() and C_close() are the basic routines for + respectively write on, open and close the output file. + The put_*() functions serve as formatting functions of the + various EM language constructs. + See "Description of a Machine Architecture for use with + Block Structured Languages" par. 11.2 for the meaning of these + names. +*/ + +/* supply a kind of buffered output */ +#define flush(x) sys_write(ofd, &obuf[0], x); + +static char obuf[BUFSIZ]; +static char *opp = &obuf[0]; +int ofd = -1; + +putbyte(b) /* shouldn't putbyte() be a macro ??? (EB) */ + int b; +{ + if (opp >= &obuf[BUFSIZ]) { /* flush if buffer overflows */ + flush(BUFSIZ); + opp = &obuf[0]; + } + *opp++ = (char) b; +} + +C_open(nm) /* open file for compact code output */ + char *nm; +{ + if (nm == 0) + ofd = 1; /* standard output */ + else + if ((ofd = sys_creat(nm, CMODE)) < 0) + return 0; + return 1; +} + +C_close() +{ + flush(opp - &obuf[0]); + opp = obuf; /* reset opp */ + sys_close(ofd); + ofd = -1; +} + +C_busy() +{ + return ofd >= 0; /* true if code is being generated */ +} + +/*** front end for generating long CON/ROM lists ***/ +static arg_count; +static arg_rom; + +DC_start(rom){ + arg_count = 0; + arg_rom = rom; +} + +DC_check(){ + if (arg_count++ >= MAX_ARG_CNT) { + switch (arg_rom) { + case ps_con: + C_con_end(); + C_con_begin(); + break; + case ps_rom: + C_rom_end(); + C_rom_begin(); + break; + } + } +} + +/*** the compact code generating routines ***/ +#define fit16i(x) ((x) >= (long)0xFFFF8000 && (x) <= (long)0x00007FFF) +#define fit8u(x) ((x) <= 0xFF) /* x is already unsigned */ + +put_ilb(l) + label l; +{ + if (fit8u(l)) { + put8(sp_ilb1); + put8((int)l); + } + else { + put8(sp_ilb2); + put16(l); + } +} + +put_dlb(l) + label l; +{ + if (fit8u(l)) { + put8(sp_dlb1); + put8((int)l); + } + else { + put8(sp_dlb2); + put16(l); + } +} + +put_cst(l) + arith l; +{ + if (l >= (arith) -sp_zcst0 && l < (arith) (sp_ncst0 - sp_zcst0)) { + /* we can convert 'l' to an int because its value + can be stored in a byte. + */ + put8((int) l + (sp_zcst0 + sp_fcst0)); + } + else + if (fit16i(l)) { /* the cast from long to int causes no trouble here */ + put8(sp_cst2); + put16((int) l); + } + else { + put8(sp_cst4); + put32(l); + } +} + +put_doff(l, v) + label l; + arith v; +{ + if (v == 0) + put_dlb(l); + else { + put8(sp_doff); + put_dlb(l); + put_cst(v); + } +} + +put_noff(s, v) + char *s; + arith v; +{ + if (v == 0) + put_dnam(s); + else { + put8(sp_doff); + put_dnam(s); + put_cst(v); + } +} + +put_dnam(s) + char *s; +{ + put8(sp_dnam); + put_str(s); +} + +put_pnam(s) + char *s; +{ + put8(sp_pnam); + put_str(s); +} + +#ifdef ____ +put_fcon(s, sz) + char *s; + arith sz; +{ + put8(sp_fcon); + put_cst(sz); + put_str(s); +} +#endif ____ + +put_wcon(sp, v, sz) /* sp_icon, sp_ucon or sp_fcon with int repr */ + int sp; + char *v; + arith sz; +{ + /* how 'bout signextension int --> long ??? */ + put8(sp); + put_cst(sz); + put_str(v); +} + +put_str(s) + char *s; +{ + register int len; + + put_cst((arith) (len = strlen(s))); + while (--len >= 0) + put8(*s++); +} + +put_cstr(s) + char *s; +{ + register int len = prepare_string(s); + + put8(sp_scon); + put_cst((arith) len); + while (--len >= 0) + put8(*s++); +} diff --git a/lang/cem/cemcom/em.h b/lang/cem/cemcom/em.h new file mode 100644 index 00000000..7d9de789 --- /dev/null +++ b/lang/cem/cemcom/em.h @@ -0,0 +1,42 @@ +/* $Header$ */ +/* DESCRIPTION OF INTERFACE TO EM CODE GENERATING ROUTINES */ + +#include "proc_intf.h" /* use macros or functions */ + +/* include the EM description files */ +#include +#include +#include +#include +#include + +/* macros used in the definitions of the interface functions C_* */ +#define OP(x) put_op(x) +#define CST(x) put_cst(x) +#define DCST(x) put_cst(x) +#define CSTR(x) put_cstr(x) +#define PS(x) put_ps(x) +#define DLB(x) put_dlb(x) +#define ILB(x) put_ilb(x) +#define NOFF(x,y) put_noff((x), (y)) +#define DOFF(x,y) put_doff((x), (y)) +#define PNAM(x) put_pnam(x) +#define DNAM(x) put_dnam(x) +#define CEND() put_cend() +#define WCON(x,y,z) put_wcon((x), (y), (z)) +#define FCON(x,y) put_fcon((x), (y)) + +/* variants of primitive "putbyte" */ +#define put8(x) putbyte(x) /* defined in "em.c" */ +#define put16(x) (put8((int) x), put8((int) (x >> 8))) +#define put32(x) (put16((int) x), put16((int) (x >> 16))) +#define put_cend() put8(sp_cend) +#define put_op(x) put8(x) +#define put_ps(x) put8(x) + +/* user interface */ +#define C_magic() put16(sp_magic) /* EM magic word */ + +#ifndef PROC_INTF +#include "writeem.h" +#endif PROC_INTF diff --git a/lang/cem/cemcom/emcode.def b/lang/cem/cemcom/emcode.def new file mode 100644 index 00000000..cf2530a2 --- /dev/null +++ b/lang/cem/cemcom/emcode.def @@ -0,0 +1,123 @@ +% emcode definitions for the CEM compiler -- intermediate code +C_adf(p) | arith p; | OP(op_adf), CST(p) +C_adi(p) | arith p; | OP(op_adi), CST(p) +C_adp(p) | arith p; | OP(op_adp), CST(p) +C_ads(p) | arith p; | OP(op_ads), CST(p) +C_adu(p) | arith p; | OP(op_adu), CST(p) +C_and(p) | arith p; | OP(op_and), CST(p) +C_asp(p) | arith p; | OP(op_asp), CST(p) +C_bra(l) | label l; | OP(op_bra), CST((arith)l) +C_cai() | | OP(op_cai) +C_cal(p) | char *p; | OP(op_cal), PNAM(p) +C_cff() | | OP(op_cff) +C_cfi() | | OP(op_cfi) +C_cfu() | | OP(op_cfu) +C_cif() | | OP(op_cif) +C_cii() | | OP(op_cii) +C_ciu() | | OP(op_ciu) +C_cmf(p) | arith p; | OP(op_cmf), CST(p) +C_cmi(p) | arith p; | OP(op_cmi), CST(p) +C_cmp() | | OP(op_cmp) +C_cmu(p) | arith p; | OP(op_cmu), CST(p) +C_com(p) | arith p; | OP(op_com), CST(p) +C_csa(p) | arith p; | OP(op_csa), CST(p) +C_csb(p) | arith p; | OP(op_csb), CST(p) +C_cuf() | | OP(op_cuf) +C_cui() | | OP(op_cui) +C_cuu() | | OP(op_cuu) +C_dup(p) | arith p; | OP(op_dup), CST(p) +C_dvf(p) | arith p; | OP(op_dvf), CST(p) +C_dvi(p) | arith p; | OP(op_dvi), CST(p) +C_dvu(p) | arith p; | OP(op_dvu), CST(p) +C_fil_ndlb(l, o) | label l; arith o; | OP(op_fil), DOFF(l, o) +C_ior(p) | arith p; | OP(op_ior), CST(p) +C_lae_dnam(p, o) | char *p; arith o; | OP(op_lae), NOFF(p, o) +C_lae_ndlb(l, o) | label l; arith o; | OP(op_lae), DOFF(l, o) +C_lal(p) | arith p; | OP(op_lal), CST(p) +C_ldc(p) | arith p; | OP(op_ldc), DCST(p) +C_lde_dnam(p, o) | char *p; arith o; | OP(op_lde), NOFF(p, o) +C_lde_ndlb(l, o) | label l; arith o; | OP(op_lde), DOFF(l, o) +C_ldl(p) | arith p; | OP(op_ldl), CST(p) +C_lfr(p) | arith p; | OP(op_lfr), CST(p) +C_lin(p) | arith p; | OP(op_lin), CST(p) +C_loc(p) | arith p; | OP(op_loc), CST(p) +C_loe_dnam(p, o) | char *p; arith o; | OP(op_loe), NOFF(p, o) +C_loe_ndlb(l, o) | label l; arith o; | OP(op_loe), DOFF(l, o) +C_loi(p) | arith p; | OP(op_loi), CST(p) +C_lol(p) | arith p; | OP(op_lol), CST(p) +C_lor(p) | arith p; | OP(op_lor), CST(p) +C_lpi(p) | char *p; | OP(op_lpi), PNAM(p) +C_mlf(p) | arith p; | OP(op_mlf), CST(p) +C_mli(p) | arith p; | OP(op_mli), CST(p) +C_mlu(p) | arith p; | OP(op_mlu), CST(p) +C_ngf(p) | arith p; | OP(op_ngf), CST(p) +C_ngi(p) | arith p; | OP(op_ngi), CST(p) +C_ret(p) | arith p; | OP(op_ret), CST(p) +C_rmi(p) | arith p; | OP(op_rmi), CST(p) +C_rmu(p) | arith p; | OP(op_rmu), CST(p) +C_sbf(p) | arith p; | OP(op_sbf), CST(p) +C_sbi(p) | arith p; | OP(op_sbi), CST(p) +C_sbs(p) | arith p; | OP(op_sbs), CST(p) +C_sbu(p) | arith p; | OP(op_sbu), CST(p) +C_sde_dnam(p, o) | char *p; arith o; | OP(op_sde), NOFF(p, o) +C_sde_ndlb(l, o) | label l; arith o; | OP(op_sde), DOFF(l, o) +C_sdl(p) | arith p; | OP(op_sdl), CST(p) +C_sli(p) | arith p; | OP(op_sli), CST(p) +C_slu(p) | arith p; | OP(op_slu), CST(p) +C_sri(p) | arith p; | OP(op_sri), CST(p) +C_sru(p) | arith p; | OP(op_sru), CST(p) +C_ste_dnam(p, o) | char *p; arith o; | OP(op_ste), NOFF(p, o) +C_ste_ndlb(l, o) | label l; arith o; | OP(op_ste), DOFF(l, o) +C_sti(p) | arith p; | OP(op_sti), CST(p) +C_stl(p) | arith p; | OP(op_stl), CST(p) +C_xor(p) | arith p; | OP(op_xor), CST(p) +C_zeq(l) | label l; | OP(op_zeq), CST((arith)l) +C_zge(l) | label l; | OP(op_zge), CST((arith)l) +C_zgt(l) | label l; | OP(op_zgt), CST((arith)l) +C_zle(l) | label l; | OP(op_zle), CST((arith)l) +C_zlt(l) | label l; | OP(op_zlt), CST((arith)l) +C_zne(l) | label l; | OP(op_zne), CST((arith)l) +% +C_ndlb(l) | label l; | DLB(l) +C_dnam(s) | char *s; | DNAM(s) +C_ilb(l) | label l; | ILB(l) +% +C_bss_cst(n, w, i) | arith n, w; int i; | + PS(ps_bss), DCST(n), CST(w), CST((arith)i) +% +C_con_begin() | | DC_start(ps_con), PS(ps_con) +C_con_end() | | CEND() +C_rom_begin() | | DC_start(ps_rom), PS(ps_rom) +C_rom_end() | | CEND() +C_co_cst(l) | arith l; | DC_check(), CST(l) +C_co_icon(val, siz) | char *val; arith siz; | + DC_check(), WCON(sp_icon, val, siz) +C_co_ucon(val, siz) | char *val; arith siz; | + DC_check(), WCON(sp_ucon, val, siz) +C_co_fcon(val, siz) | char *val; arith siz; | + DC_check(), WCON(sp_fcon, val, siz) +C_co_scon(str, siz) | char *str; arith siz; | DC_check(), CSTR(str) +C_co_dnam(str, val) | char *str; arith val; | DC_check(), NOFF(str, val) +C_co_ndlb(l, val) | label l; arith val; | DC_check(), DOFF(l, val) +C_co_pnam(str) | char *str; | DC_check(), PNAM(str) +C_co_ilb(l) | label l; | DC_check(), ILB(l) +% +C_pro_narg(p1) | char *p1; | PS(ps_pro), PNAM(p1), CEND() +C_end(l) | arith l; | PS(ps_end), CST(l) +% +C_exa(s) | char *s; | PS(ps_exa), DNAM(s) +C_exp(s) | char *s; | PS(ps_exp), PNAM(s) +C_ina_pt(l) | label l; | PS(ps_ina), DLB(l) +C_ina(s) | char *s; | PS(ps_ina), DNAM(s) +C_inp(s) | char *s; | PS(ps_inp), PNAM(s) +% +C_ms_err() | | PS(ps_mes), CST((arith)ms_err), CEND() +C_ms_emx(p1, p2) | arith p1, p2; | + PS(ps_mes), CST((arith)ms_emx), CST(p1), CST(p2), CEND() +C_ms_reg(a, b, c, d) | arith a, b; int c, d; | + PS(ps_mes), CST((arith)ms_reg), CST(a), CST(b), CST((arith)c), CST((arith)d), CEND() +C_ms_src(l, s) | arith l; char *s; | + PS(ps_mes), CST((arith)ms_src), CST(l), CSTR(s), CEND() +C_ms_flt() | | PS(ps_mes), CST((arith)ms_flt), CEND() +C_ms_par(l) | arith l; | PS(ps_mes), CST((arith)ms_par), CST(l), CEND() +C_ms_gto() | | PS(ps_mes), CST((arith)ms_gto), CEND() diff --git a/lang/cem/cemcom/error.c b/lang/cem/cemcom/error.c new file mode 100644 index 00000000..51d06b69 --- /dev/null +++ b/lang/cem/cemcom/error.c @@ -0,0 +1,212 @@ +/* $Header$ */ +/* E R R O R A N D D I A G N O S T I C R O U T I N E S */ + +#include "nopp.h" +#include "use_tmp.h" +#include "errout.h" +#include "debug.h" +#include "system.h" +#include "string.h" + +#include "tokenname.h" +#include "arith.h" +#include "label.h" +#include "expr.h" +#include "LLlex.h" +#include "em.h" + +/* This file contains the (non-portable) error-message and diagnostic + functions. Beware, they are called with a variable number of + arguments! +*/ + +/* error classes */ +#define ERROR 1 +#define WARNING 2 +#define LEXERROR 3 +#define LEXWARNING 4 +#define CRASH 5 +#define FATAL 6 + +int err_occurred; + +extern char *symbol2str(); +extern char options[]; + +/* There are three general error-message functions: + lexerror() lexical and pre-processor error messages + error() syntactic and semantic error messages + expr_error() errors in expressions + The difference lies in the place where the file name and line + number come from. + Lexical errors report from the global variables LineNumber and + FileName, expression errors get their information from the + expression, whereas other errors use the information in the token. +*/ + +/*VARARGS1*/ +error(fmt, args) + char *fmt; +{ + _error(ERROR, NILEXPR, fmt, &args); +} + +/*VARARGS2*/ +expr_error(expr, fmt, args) + struct expr *expr; + char *fmt; +{ + _error(ERROR, expr, fmt, &args); +} + +/*VARARGS1*/ +warning(fmt, args) + char *fmt; +{ + _error(WARNING, NILEXPR, fmt, &args); +} + +/*VARARGS2*/ +expr_warning(expr, fmt, args) + struct expr *expr; + char *fmt; +{ + _error(WARNING, expr, fmt, &args); +} + +/*VARARGS1*/ +lexerror(fmt, args) + char *fmt; +{ + _error(LEXERROR, NILEXPR, fmt, &args); +} + +#ifndef NOPP +/*VARARGS1*/ +lexwarning(fmt, args) char *fmt; { + _error(LEXWARNING, NILEXPR, fmt, &args); +} +#endif NOPP + +/*VARARGS1*/ +crash(fmt, args) + char *fmt; + int args; +{ + _error(CRASH, NILEXPR, fmt, &args); + C_close(); +#ifdef DEBUG + sys_stop(S_ABORT, 0); +#else DEBUG + sys_stop(S_EXIT, 1); +#endif DEBUG +} + +/*VARARGS1*/ +fatal(fmt, args) + char *fmt; + int args; +{ +#ifdef USE_TMP + extern char *tmpfile; /* main.c */ + + if (tmpfile) + sys_remove(tmpfile); /* may not successful! */ +#endif USE_TMP + + _error(FATAL, NILEXPR, fmt, &args); + sys_stop(S_EXIT, 1); +} + +_error(class, expr, fmt, argv) + int class; + struct expr *expr; + char *fmt; + int argv[]; +{ + /* _error attempts to limit the number of error messages + for a given line to MAXERR_LINE. + */ + static char *last_fn = 0; + static unsigned int last_ln = 0; + static int e_seen = 0; + char *fn = 0; + unsigned int ln = 0; + char *remark = 0; + + /* Since name and number are gathered from different places + depending on the class, we first collect the relevant + values and then decide what to print. + */ + /* preliminaries */ + switch (class) { + case ERROR: + case LEXERROR: + case CRASH: + case FATAL: + if (C_busy()) + C_ms_err(); + err_occurred = 1; + break; + + case WARNING: + case LEXWARNING: + if (options['w']) + return; + break; + } + + /* the remark */ + switch (class) { + case WARNING: + case LEXWARNING: + remark = "(warning)"; + break; + case CRASH: + remark = "CRASH\007"; + break; + case FATAL: + remark = "fatal error --"; + break; + } + + /* the place */ + switch (class) { + case WARNING: + case ERROR: + fn = expr ? expr->ex_file : dot.tk_file; + ln = expr ? expr->ex_line : dot.tk_line; + break; + case LEXWARNING: + case LEXERROR: + case CRASH: + case FATAL: + fn = FileName; + ln = LineNumber; + break; + } + + if (ln == last_ln && fn && last_fn && strcmp(fn, last_fn) == 0) { + /* we've seen this place before */ + e_seen++; + if (e_seen == MAXERR_LINE) + fmt = "etc ..."; + else + if (e_seen > MAXERR_LINE) + /* and too often, I'd say ! */ + return; + } + else { + /* brand new place */ + last_fn = fn; + last_ln = ln; + e_seen = 0; + } + + if (fn) + fprintf(ERROUT, "\"%s\", line %u: ", fn, ln); + if (remark) + fprintf(ERROUT, "%s ", remark); + doprnt(ERROUT, fmt, argv); /* contents of error */ + fprintf(ERROUT, "\n"); +} diff --git a/lang/cem/cemcom/eval.c b/lang/cem/cemcom/eval.c new file mode 100644 index 00000000..79b62a32 --- /dev/null +++ b/lang/cem/cemcom/eval.c @@ -0,0 +1,1028 @@ +/* $Header$ */ +/* EXPRESSION-CODE GENERATOR */ + +/* main functions : + EVAL() -- expression tree evaluator + tmp_pointer_var() -- deliver temporary pointer variable + free_tmp_var() -- return the pointer var + store_val() -- store primary expression + load_val() -- load primary expression + auxiliary functions: + assop() + compare() +*/ + +#include "debug.h" +#include "nobitfield.h" + +#include "string.h" +#include "dataflow.h" +#include "arith.h" +#include "type.h" +#include "idf.h" +#include "label.h" +#include "code.h" +#include "assert.h" +#include "def.h" +#include "expr.h" +#include "sizes.h" +#include "Lpars.h" +#include "level.h" +#include "stack.h" +#include "align.h" +#include "mes.h" +#include "atw.h" +#include "em.h" + +#define CRASH() crash("EVAL: CRASH at line %u", __LINE__) +#define roundup(n) ((n) < word_size ? word_size : (n)) + +char *symbol2str(); +arith tmp_pointer_var(); + +/* EVAL() serves as the main expression tree evaluator, which turns + any legal expression tree into legal EM code. + The parameters describe how EVAL should treat the expression tree: + + struct expr *expr: pointer to root of the expression tree to + be evaluated + + int val: indicates whether the resulting expression + is to be dereferenced (if val == RVAL and + expr->ex_lvalue == 1) or not (val == LVAL). + The latter case indicates that the resulting + expression is an lvalue expression which should + not be dereferenced by EVAL + + int code: indicates whether the expression tree must be + turned into EM code or not. E.g. the expression + statement "12;" delivers the expression "12" to + EVAL while this should not result in any EM code + + label false_label: + label true_label: if the expression is a logical or relational + expression and if the loop of the program + depends on the resulting value then EVAL + generates jumps to the specified program labels, + in case they are specified (i.e. are non-zero) +*/ + +EVAL(expr, val, code, true_label, false_label) + struct expr *expr; /* the expression tree itself */ + int val; /* either RVAL or LVAL */ + int code; /* generate explicit code or not */ + label true_label; + label false_label; /* labels to jump to in logical expr's */ +{ + register gencode = (code == TRUE); + + switch (expr->ex_class) { + + case Value: /* just a simple value */ + if (gencode) + load_val(expr, val); + break; + + case String: /* a string constant */ + if (gencode) { + label datlab = data_label(); + + C_ndlb(datlab); + C_con_begin(); + C_co_scon(expr->SG_VALUE, (arith)0); + C_con_end(); + C_lae_ndlb(datlab, (arith)0); + } + break; + + case Float: /* a floating constant */ + if (gencode) { + label datlab = data_label(); + + C_ndlb(datlab); + C_rom_begin(); + C_co_fcon(expr->FL_VALUE, expr->ex_type->tp_size); + C_rom_end(); + C_lae_ndlb(datlab, (arith)0); + C_loi(expr->ex_type->tp_size); + } + break; + + case Oper: /* compound expression */ + { + register int oper = expr->OP_OPER; + register struct expr *leftop = expr->OP_LEFT; + register struct expr *rightop = expr->OP_RIGHT; + register struct type *tp = expr->OP_TYPE; + + if (tp->tp_fund == ERRONEOUS) /* stop immediately */ + break; + + switch (oper) { + case '+': + /* We have the following possibilities : + int + int, pointer + int, pointer + long, + long + long, double + double + */ + EVAL(leftop, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); + + if (gencode) { + switch (tp->tp_fund) { + case INT: + case LONG: + if (tp->tp_unsigned) + C_adu(tp->tp_size); + else + C_adi(tp->tp_size); + break; + case POINTER: + C_ads(rightop->ex_type->tp_size); + break; + case DOUBLE: + C_adf(tp->tp_size); + break; + default: + crash("bad type +"); + } + } + break; + case '-': + if (leftop == 0) { /* unary */ + EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); + if (gencode) { + switch (tp->tp_fund) { + case DOUBLE: + C_ngf(tp->tp_size); + break; + case INT: + case LONG: + case POINTER: + C_ngi(tp->tp_size); + break; + default: + CRASH(); + } + } + break; + } + /* Binary: we have the following flavours: + int - int, pointer - int, pointer - long, + pointer - pointer, long - long, double - double + */ + EVAL(leftop, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); + + if (!gencode) + break; + switch (tp->tp_fund) { + case INT: + case LONG: + if (tp->tp_unsigned) + C_sbu(tp->tp_size); + else + C_sbi(tp->tp_size); + break; + case POINTER: + if (EXPRTYPE(rightop) == POINTER) + C_sbs(pointer_size); + else { + C_ngi(rightop->ex_type->tp_size); + C_ads(rightop->ex_type->tp_size); + } + break; + case DOUBLE: + C_sbf(tp->tp_size); + break; + default: + crash("bad type -"); + } + break; + case '*': + if (leftop == 0) /* unary */ + EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); + else { /* binary */ + EVAL(leftop, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); + if (gencode) + switch (tp->tp_fund) { + case INT: + case LONG: + case POINTER: + if (tp->tp_unsigned) + C_mlu(tp->tp_size); + else + C_mli(tp->tp_size); + break; + case DOUBLE: + C_mlf(double_size); + break; + default: + crash("bad type *"); + } + } + break; + case '/': + EVAL(leftop, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); + if (gencode) + switch (tp->tp_fund) { + case INT: + case LONG: + case POINTER: + if (tp->tp_unsigned) + C_dvu(tp->tp_size); + else + C_dvi(tp->tp_size); + break; + case DOUBLE: + C_dvf(double_size); + break; + default: + crash("bad type /"); + } + break; + case '%': + EVAL(leftop, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); + if (gencode) + if (tp->tp_fund == INT || tp->tp_fund == LONG) { + if (tp->tp_unsigned) + C_rmu(tp->tp_size); + else + C_rmi(tp->tp_size); + } + else + crash("bad type %%"); + break; + case LEFT: + EVAL(leftop, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); + if (gencode) + if (tp->tp_unsigned) + C_slu(tp->tp_size); + else + C_sli(tp->tp_size); + break; + case RIGHT: + EVAL(leftop, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); + if (gencode) + if (tp->tp_unsigned) + C_sru(tp->tp_size); + else + C_sri(tp->tp_size); + break; + case '<': + case LESSEQ: + case '>': + case GREATEREQ: + case EQUAL: + case NOTEQUAL: + EVAL(leftop, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); + if (gencode) { + /* The operands have the same type */ + switch (tp->tp_fund) { + case INT: + case LONG: + if (leftop->ex_type->tp_unsigned) + C_cmu(leftop->ex_type->tp_size); + else + C_cmi(leftop->ex_type->tp_size); + break; + case FLOAT: + case DOUBLE: + C_cmf(leftop->ex_type->tp_size); + break; + case POINTER: + C_cmp(); + break; + case ENUM: + C_cmi(leftop->ex_type->tp_size); + break; + default: + CRASH(); + } + if (true_label != 0) { + compare(oper, true_label); + C_bra(false_label); + } + else { + label l_true = text_label(); + label l_end = text_label(); + + compare(oper, l_true); + C_loc((arith)0); + C_bra(l_end); + C_ilb(l_true); + C_loc((arith)1); + C_ilb(l_end); + } + } + break; + case '&': + case '|': + case '^': + /* both operands should have type int */ + EVAL(leftop, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); + if (gencode) { + arith size = tp->tp_size; + + if (size < word_size) + size = word_size; + switch (oper) { + case '&': + C_and(size); + break; + case '|': + C_ior(size); + break; + case '^': + C_xor(size); + break; + } + } + break; + case '=': +#ifndef NOBITFIELD + if (leftop->ex_type->tp_fund == FIELD) { + /* assignment to bitfield variable + */ + eval_field(expr, code); + break; + } +#endif NOBITFIELD + EVAL(rightop, RVAL, TRUE, NO_LABEL, NO_LABEL); + if (gencode) + C_dup(ATW(tp->tp_size)); + + if (leftop->ex_class != Value) { + EVAL(leftop, LVAL, TRUE, NO_LABEL, NO_LABEL); + store_block(tp->tp_size, tp->tp_align); + } + else + store_val(leftop->VL_IDF, leftop->ex_type, + leftop->VL_VALUE); + break; + case PLUSAB: + case MINAB: + case TIMESAB: + case DIVAB: + case MODAB: + case LEFTAB: + case RIGHTAB: + case ANDAB: + case XORAB: + case ORAB: +#ifndef NOBITFIELD + if (leftop->ex_type->tp_fund == FIELD) { + eval_field(expr, code); + break; + } +#endif NOBITFIELD + if (leftop->ex_class != Value) { + arith old_offset; + arith tmpvar = tmp_pointer_var(&old_offset); + + EVAL(leftop, LVAL, TRUE, NO_LABEL, NO_LABEL); + C_lal(tmpvar); + C_sti(pointer_size); + C_lal(tmpvar); + C_loi(pointer_size); + C_loi(tp->tp_size); + EVAL(rightop, RVAL, TRUE, NO_LABEL, NO_LABEL); + assop(tp, oper); + if (gencode) + C_dup(roundup(tp->tp_size)); + C_lal(tmpvar); + C_loi(pointer_size); + C_sti(tp->tp_size); + free_tmp_var(old_offset); + } + else { + load_val(leftop, RVAL); + EVAL(rightop, RVAL, TRUE, NO_LABEL, NO_LABEL); + assop(tp, oper); + if (gencode) + C_dup(roundup(tp->tp_size)); + store_val(leftop->VL_IDF, leftop->ex_type, + leftop->VL_VALUE); + } + break; + case '(': + { + register struct expr *expr; + arith ParSize = (arith)0; + + if (expr = rightop) { + /* function call with parameters*/ + while ( expr->ex_class == Oper && + expr->OP_OPER == PARCOMMA + ) { + EVAL(expr->OP_RIGHT, RVAL, TRUE, + NO_LABEL, NO_LABEL); + ParSize += + ATW(expr->ex_type->tp_size); + expr = expr->OP_LEFT; + } + EVAL(expr, RVAL, TRUE, NO_LABEL, NO_LABEL); + ParSize += ATW(expr->ex_type->tp_size); + } + if (leftop->ex_class == Value && leftop->VL_IDF != 0) { + /* just an example: + main() { (*((int (*)())0))(); } + */ + C_cal(leftop->VL_IDF->id_text); +#ifdef DATAFLOW + { extern char options[]; + if (options['d']) + DfaCallFunction( + leftop->VL_IDF->id_text + ); + } +#endif DATAFLOW + } + else { + EVAL(leftop, LVAL, TRUE, NO_LABEL, NO_LABEL); + C_cai(); + } + /* remove parameters from stack */ + if (ParSize > (arith)0) + C_asp(ParSize); + if (!gencode) + break; + if (is_struct_or_union(tp->tp_fund)) { + C_lfr(pointer_size); + load_block(tp->tp_size, tp->tp_align); + } + else + C_lfr(ATW(tp->tp_size)); + break; + } + case '.': + EVAL(leftop, LVAL, code, NO_LABEL, NO_LABEL); + if (gencode) + C_adp(rightop->VL_VALUE); + break; + case ARROW: + EVAL(leftop, RVAL, code, NO_LABEL, NO_LABEL); + if (gencode) + C_adp(rightop->VL_VALUE); + break; + case ',': + EVAL(leftop, RVAL, FALSE, NO_LABEL, NO_LABEL); + EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); + break; + case '~': + EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); + if (gencode) + C_com(tp->tp_size); + break; + case POSTINCR: + case POSTDECR: + case PLUSPLUS: + case MINMIN: + { + arith old_offset, tmp; + arith esize = tp->tp_size; +#ifndef NOBITFIELD + if (leftop->ex_type->tp_fund == FIELD) { + eval_field(expr, code); + break; + } +#endif NOBITFIELD + if (leftop->ex_class != Value) { + tmp = tmp_pointer_var(&old_offset); + EVAL(leftop, LVAL, TRUE, NO_LABEL, NO_LABEL); + C_dup(pointer_size); + C_lal(tmp); + C_sti(pointer_size); + C_loi(tp->tp_size); + } + else + load_val(leftop, RVAL); + + /* We made the choice to put this stuff here + and not to put the conversion in the expression + tree because this conversion is EM dependent + and not described in C + */ + if (esize < word_size) { + conversion(tp, word_type); + esize = word_size; + } + + if (gencode && (oper == POSTINCR || oper == POSTDECR)) + C_dup(esize); + EVAL(rightop, RVAL, TRUE, NO_LABEL, NO_LABEL); + assop(tp, oper); + if (gencode && (oper == PLUSPLUS || oper == MINMIN)) + C_dup(esize); + if (tp->tp_size < word_size) + conversion(word_type, tp); + if (leftop->ex_class != Value) { + C_lal(tmp); /* always init'd */ + C_loi(pointer_size); + C_sti(tp->tp_size); + free_tmp_var(old_offset); + } + else + store_val(leftop->VL_IDF, leftop->ex_type, + leftop->VL_VALUE); + break; + } + case '?': /* must be followed by ':' */ + { + label l_true = text_label(); + label l_false = text_label(); + label l_end = text_label(); + + EVAL(leftop, RVAL, TRUE, l_true, l_false); + C_ilb(l_true); + EVAL(rightop->OP_LEFT, RVAL, code, NO_LABEL, NO_LABEL); + C_bra(l_end); + C_ilb(l_false); + EVAL(rightop->OP_RIGHT, RVAL, code, NO_LABEL, NO_LABEL); + C_ilb(l_end); + break; + } + case AND: + if (true_label == 0) { + label l_true = text_label(); + label l_false = text_label(); + label l_maybe = text_label(); + label l_end = text_label(); + + EVAL(leftop, RVAL, TRUE, l_maybe, l_false); + C_ilb(l_maybe); + if (gencode) { + EVAL(rightop, RVAL, TRUE, + l_true, l_false); + C_ilb(l_true); + C_loc((arith)1); + C_bra(l_end); + C_ilb(l_false); + C_loc((arith)0); + C_ilb(l_end); + } + else { + EVAL(rightop, RVAL, FALSE, l_false, + l_false); + C_ilb(l_false); + } + } + else { + label l_maybe = text_label(); + + EVAL(leftop, RVAL, TRUE, l_maybe, false_label); + C_ilb(l_maybe); + EVAL(rightop, RVAL, code, true_label, + false_label); + } + break; + case OR: + if (true_label == 0) { + label l_true = text_label(); + label l_false = text_label(); + label l_maybe = text_label(); + label l_end = text_label(); + + EVAL(leftop, RVAL, TRUE, l_true, l_maybe); + C_ilb(l_maybe); + if (gencode) { + EVAL(rightop, RVAL, TRUE, + l_true, l_false); + C_ilb(l_false); + C_loc((arith)0); + C_bra(l_end); + C_ilb(l_true); + C_loc((arith)1); + C_ilb(l_end); + } + else { + EVAL(rightop, RVAL, FALSE, l_true, + l_true); + C_ilb(l_true); + } + } + else { + label l_maybe = text_label(); + + EVAL(leftop, RVAL, TRUE, true_label, l_maybe); + C_ilb(l_maybe); + EVAL(rightop, RVAL, code, true_label, + false_label); + } + break; + case '!': + if (true_label == 0) { + if (gencode) { + label l_true = text_label(); + label l_false = text_label(); + label l_end = text_label(); + + EVAL(rightop, RVAL, TRUE, + l_false, l_true); + C_ilb(l_false); + C_loc((arith)0); + C_bra(l_end); + C_ilb(l_true); + C_loc((arith)1); + C_ilb(l_end); + } + else + EVAL(rightop, RVAL, FALSE, + NO_LABEL, NO_LABEL); + } + else + EVAL(rightop, RVAL, code, false_label, + true_label); + break; + case INT2INT: + case INT2FLOAT: + case FLOAT2INT: + case FLOAT2FLOAT: + EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); + if (gencode) + conversion(rightop->ex_type, leftop->ex_type); + break; + default: + crash("(EVAL) Bad operator %s\n", symbol2str(oper)); + } + + /* If the rvalue of the expression is required but + only its lvalue is evaluated, its rvalue is + loaded by the following statements: + */ + if (gencode && val == RVAL && expr->ex_lvalue == 1) + load_block(expr->ex_type->tp_size, + expr->ex_type->tp_align); + break; + } + case Type: + default: + crash("(EVAL) bad expression class"); + } +} + +/* compare() serves as an auxiliary function of EVAL */ +compare(relop, lbl) + int relop; + label lbl; +{ + switch (relop) { + case '<': + C_zlt(lbl); + break; + case LESSEQ: + C_zle(lbl); + break; + case '>': + C_zgt(lbl); + break; + case GREATEREQ: + C_zge(lbl); + break; + case EQUAL: + C_zeq(lbl); + break; + case NOTEQUAL: + C_zne(lbl); + break; + default: + CRASH(); + } +} + +/* assop() generates the opcode of an assignment operators op= */ +assop(type, oper) + struct type *type; + int oper; +{ + register arith size = type->tp_size; + register uns = type->tp_unsigned; + + if (size < word_size) + size = word_size; + switch (type->tp_fund) { + case CHAR: + case SHORT: + case INT: + case LONG: + case ENUM: + switch (oper) { + case PLUSAB: + case PLUSPLUS: + case POSTINCR: + if (uns) + C_adu(size); + else + C_adi(size); + break; + case MINAB: + case MINMIN: + case POSTDECR: + if (uns) + C_sbu(size); + else + C_sbi(size); + break; + case TIMESAB: + if (uns) + C_mlu(size); + else + C_mli(size); + break; + case DIVAB: + if (uns) + C_dvu(size); + else + C_dvi(size); + break; + case MODAB: + if (uns) + C_rmu(size); + else + C_rmi(size); + break; + case LEFTAB: + if (uns) + C_slu(size); + else + C_sli(size); + break; + case RIGHTAB: + if (uns) + C_sru(size); + else + C_sri(size); + break; + case ANDAB: + C_and(size); + break; + case XORAB: + C_xor(size); + break; + case ORAB: + C_ior(size); + break; + } + break; + case FLOAT: + case DOUBLE: + switch (oper) { + case PLUSAB: + case PLUSPLUS: + case POSTINCR: + C_adf(size); + break; + case MINAB: + case MINMIN: + case POSTDECR: + C_sbf(size); + break; + case TIMESAB: + C_mlf(size); + break; + case DIVAB: + C_dvf(size); + break; + } + break; + case POINTER: + if (oper == MINAB || oper == MINMIN || oper == POSTDECR) + C_ngi(size); + C_ads(size); + break; + case ERRONEOUS: + break; + default: + crash("(assop) bad type %s\n", symbol2str(type->tp_fund)); + } +} + +/* tmp_pointer_var() returns the EM address of a new temporary + pointer variable needed at increment, decrement and assignment + operations to store the address of some variable or lvalue-expression. +*/ +arith +tmp_pointer_var(oldoffset) + arith *oldoffset; /* previous allocated address */ +{ + struct stack_level *stl = local_level; + + *oldoffset = stl->sl_local_offset; + stl->sl_local_offset = + - align(-stl->sl_local_offset + pointer_size, pointer_align); + if (stl->sl_local_offset < stl->sl_max_block) + stl->sl_max_block = stl->sl_local_offset; + return stl->sl_local_offset; +} + +/* free_tmp_var() returns the address allocated by tmp_pointer_var() + and resets the last allocated address. +*/ +free_tmp_var(oldoffset) + arith oldoffset; +{ + local_level->sl_local_offset = oldoffset; +} + +/* store_val() generates code for a store operation. + There are four ways of storing data: + - into a global variable + - into an automatic local variable + - into a local static variable + - absolute addressing + When the destination is described by an (lvalue) expression, the call + is "store_val(ex->VL_IDF, ex->ex_type, ex->VL_VALUE)" +*/ +store_val(id, tp, offs) + register struct idf *id; + struct type *tp; + arith offs; +{ + arith size = tp->tp_size; + int tpalign = tp->tp_align; + + if (id) { + register struct def *df = id->id_def; + int al_on_word = (tpalign % word_align == 0); + register inword = (size == word_size && al_on_word); + register indword = (size == dword_size && al_on_word); + + if (df->df_level == L_GLOBAL) { + if (inword) + C_ste_dnam(id->id_text, offs); + else + if (indword) + C_sde_dnam(id->id_text, offs); + else { + C_lae_dnam(id->id_text, offs); + store_block(size, tpalign); + } + } + else + if (df->df_sc == STATIC) { + if (inword) + C_ste_ndlb((label)df->df_address, offs); + else + if (indword) + C_sde_ndlb((label)df->df_address, offs); + else { + C_lae_ndlb((label)df->df_address, offs); + store_block(size, tpalign); + } + } + else { + if (inword) + C_stl(df->df_address + offs); + else + if (indword) + C_sdl(df->df_address + offs); + else { + C_lal(df->df_address + offs); + store_block(size, tpalign); + df->df_register = REG_NONE; + } + } + } + else { /* absolute addressing */ + load_cst(offs, pointer_size); + store_block(size, tpalign); + } +} + + +/* load_val() generates code for stacking a certain value (from ex), + which can be obtained in one of the following ways: + - value from absolute addressed memory + - constant value + - function result + - global variable + - static variable + - local variable +*/ +load_val(expr, val) + struct expr *expr; /* expression containing the value */ + int val; /* generate either LVAL or RVAL */ +{ + register struct idf *id; + register struct type *tp = expr->ex_type; + register struct def *df; + register rvalue = (val == RVAL && expr->ex_lvalue != 0); + register arith exval = expr->VL_VALUE; + register arith size = tp->tp_size; + register tpalign = tp->tp_align; + register al_on_word = (tpalign % word_align == 0); + + if ((id = expr->VL_IDF) == 0) { + /* Note: enum constants are also dealt with here */ + if (rvalue) { + /* absolute addressing + */ + load_cst(exval, pointer_size); + load_block(size, tpalign); + } + else /* integer, unsigned, long, enum etc */ + load_cst(exval, size); + } + else + if ((df = id->id_def)->df_type->tp_fund == FUNCTION) + /* the previous statement tried to catch a function + identifier, which may be cast to a pointer to a + function. + ASSERT(!(rvalue)); ??? + */ + C_lpi(id->id_text); + else + if (df->df_level == L_GLOBAL) { + if (rvalue) { + if (size == word_size && al_on_word) + C_loe_dnam(id->id_text, exval); + else + if (size == dword_size && al_on_word) + C_lde_dnam(id->id_text, exval); + else { + C_lae_dnam(id->id_text, exval); + load_block(size, tpalign); + } + + } + else { + C_lae_dnam(id->id_text, (arith)0); + C_adp(exval); + } + } + else + if (df->df_sc == STATIC) { + if (rvalue) { + if (size == word_size && al_on_word) + C_loe_ndlb((label)df->df_address, exval); + else + if (size == dword_size && al_on_word) + C_lde_ndlb((label)df->df_address, exval); + else { + C_lae_ndlb((label)df->df_address, exval); + load_block(size, tpalign); + } + + } + else { + C_lae_ndlb((label)df->df_address, (arith)0); + C_adp(exval); + } + } + else { + if (rvalue) { + if (size == word_size && al_on_word) + C_lol(df->df_address + exval); + else + if (size == dword_size && al_on_word) + C_ldl(df->df_address + exval); + else { + C_lal(df->df_address + exval); + load_block(size, tpalign); + df->df_register = REG_NONE; + } + } + else { + /* following code may be used when + comparing addresses as in the following + example: + f() { + int a[10], *i; + for (i = &a[0]; i < &a[10]; i++) ...; + } + We don't accept the contents of a[10] to + be legitimate, so the RVAL of it may + contain a big mess. + */ + C_lal(df->df_address); + C_adp(exval); + df->df_register = REG_NONE; + } + } +} + +load_cst(val, siz) + arith val, siz; +{ + if (siz <= word_size) + C_loc(val); + else + if (siz == dword_size) + C_ldc(val); + else { + label datlab; + + C_ndlb(datlab = data_label()); + C_rom_begin(); + C_co_icon(itos(val), siz); + C_rom_end(); + C_lae_ndlb(datlab, (arith)0); + C_loi(siz); + } +} diff --git a/lang/cem/cemcom/expr.c b/lang/cem/cemcom/expr.c new file mode 100644 index 00000000..67d39b29 --- /dev/null +++ b/lang/cem/cemcom/expr.c @@ -0,0 +1,408 @@ +/* $Header$ */ +/* EXPRESSION TREE HANDLING */ + +#include "botch_free.h" /* UF */ +#include "alloc.h" +#include "idf.h" +#include "arith.h" +#include "def.h" +#include "type.h" +#include "label.h" +#include "expr.h" +#include "LLlex.h" +#include "Lpars.h" +#include "decspecs.h" +#include "declarator.h" +#include "storage.h" +#include "sizes.h" + +extern char *symbol2str(); +extern char options[]; + +int +rank_of(oper) + int oper; +{ + /* The rank of the operator oper is returned. + */ + switch (oper) { + default: + return 0; /* INT2INT etc. */ + case '[': + case '(': + case '.': + case ARROW: + case PARCOMMA: + return 1; + case '!': + case PLUSPLUS: + case MINMIN: + case CAST: + case SIZEOF: + return 2; /* monadic */ + case '*': + case '/': + case '%': + return 3; + case '+': + case '-': + return 4; + case LEFT: + case RIGHT: + return 5; + case '<': + case '>': + case LESSEQ: + case GREATEREQ: + return 6; + case EQUAL: + case NOTEQUAL: + return 7; + case '&': + return 8; + case '^': + return 9; + case '|': + return 10; + case AND: + return 11; + case OR: + return 12; + case '?': + case ':': + return 13; + case '=': + case PLUSAB: + case MINAB: + case TIMESAB: + case DIVAB: + case MODAB: + case RIGHTAB: + case LEFTAB: + case ANDAB: + case XORAB: + case ORAB: + return 14; + case ',': + return 15; + } + /*NOTREACHED*/ +} + +int +rank_of_expression(expr) + struct expr *expr; +{ + /* Returns the rank of the top node in the expression. + */ + if (!expr || (expr->ex_flags & EX_PARENS) || expr->ex_class != Oper) + return 0; + return rank_of(expr->OP_OPER); +} + +check_conditional(expr, oper, pos_descr) + struct expr *expr; + char *pos_descr; +{ + /* Warn if restricted C is in effect and the expression expr, + which occurs at the position pos_descr, is not lighter than + the operator oper. + */ + if (options['R'] && rank_of_expression(expr) >= rank_of(oper)) + warning("%s %s is ungrammatical", + symbol2str(expr->OP_OPER), pos_descr); +} + +dot2expr(expp) + struct expr **expp; +{ + /* The token in dot is converted into an expression, a + pointer to which is stored in *expp. + */ + *expp = new_expr(); + clear((char *)*expp, sizeof(struct expr)); + (*expp)->ex_file = dot.tk_file; + (*expp)->ex_line = dot.tk_line; + switch (DOT) { + case IDENTIFIER: + idf2expr(*expp); + break; + case STRING: + string2expr(*expp); + break; + case INTEGER: + *expp = intexpr(dot.tk_ival, dot.tk_fund); + break; + case FLOATING: + float2expr(*expp); + break; + default: + crash("bad conversion to expression"); + break; + } +} + +idf2expr(expr) + struct expr *expr; +{ + /* Dot contains an identifier which is turned into an + expression. + Note that this constitutes an applied occurrence of + the identifier. + */ + register struct idf *idf = dot.tk_idf; /* != 0*/ + register struct def *def = idf->id_def; + + if (def == 0) { + if (AHEAD == '(') { + /* Function call, so declare the name IMPLICITly. */ + /* See RM 13. */ + add_def(idf, IMPLICIT, funint_type, level); + } + else { + if (!is_anon_idf(idf)) + error("%s undefined", idf->id_text); + /* Declare the idf anyway */ + add_def(idf, 0, error_type, level); + } + def = idf->id_def; + } + /* now def != 0 */ + if (def->df_type->tp_fund == LABEL) { + error("illegal use of label %s", idf->id_text); + expr->ex_type = error_type; + } + else { + def->df_used = 1; + expr->ex_type = def->df_type; + } + expr->ex_lvalue = + ( def->df_type->tp_fund == FUNCTION || + def->df_type->tp_fund == ARRAY || + def->df_sc == ENUM + ) ? 0 : 1; + expr->ex_class = Value; + if (def->df_sc == ENUM) { + expr->VL_IDF = 0; + expr->VL_VALUE = def->df_address; + } + else { + expr->VL_IDF = idf; + expr->VL_VALUE = (arith)0; + } +} + +string2expr(expr) + struct expr *expr; +{ + /* Dot contains a string which is turned into an expression. + */ + expr->ex_type = string_type; + expr->ex_lvalue = 0; + expr->ex_class = String; + expr->SG_VALUE = dot.tk_str; + expr->SG_DATLAB = 0; +} + +struct expr* +intexpr(ivalue, fund) + arith ivalue; +{ + /* The value ivalue is turned into an integer expression of + the size indicated by fund. + */ + struct expr *expr = new_expr(); + + clear((char *)expr, sizeof(struct expr)); + expr->ex_file = dot.tk_file; + expr->ex_line = dot.tk_line; + + switch (fund) { + + case INT: + expr->ex_type = int_type; + break; + + case LONG: + expr->ex_type = long_type; + break; + + case UNSIGNED: + /* We cannot make a test like "ivalue <= max_unsigned" + because, if sizeof(long) == int_size holds, max_unsigned + may be a negative long in which case the comparison + results in an unexpected answer. We assume that + the type "unsigned long" is not part of portable C ! + */ + expr->ex_type = + (ivalue & ~max_unsigned) ? long_type : uint_type; + break; + + case INTEGER: + expr->ex_type = (ivalue <= max_int) ? int_type : long_type; + break; + + default: + crash("(intexpr) bad fund %s\n", symbol2str(fund)); + } + expr->ex_class = Value; + expr->VL_VALUE = ivalue; + + cut_size(expr); + return expr; +} + +float2expr(expr) + struct expr *expr; +{ + /* Dot contains a floating point constant which is turned + into an expression. + */ + expr->ex_type = double_type; + expr->ex_class = Float; + expr->FL_VALUE = dot.tk_fval; + expr->FL_DATLAB = 0; +} + +struct expr * +new_oper(tp, e1, oper, e2) + struct type *tp; + struct expr *e1, *e2; +{ + /* A new expression is constructed which consists of the + operator oper which has e1 and e2 as operands; for a + monadic operator e1 == NILEXPR. + During the construction of the right recursive initialisation + tree it is possible for e2 to be NILEXPR. + */ + struct expr *expr = new_expr(); + struct oper *op; + + clear((char *)expr, sizeof(struct expr)); + if (!e1 || !e2) { + expr->ex_file = dot.tk_file; + expr->ex_line = dot.tk_line; + } + else { + expr->ex_file = e2->ex_file; + expr->ex_line = e2->ex_line; + } + expr->ex_type = tp; + expr->ex_class = Oper; + /* combine depths and flags of both expressions */ + if (e2) { + int e1_depth = e1 ? e1->ex_depth : 0; + int e1_flags = e1 ? e1->ex_flags : 0; + + expr->ex_depth = + (e1_depth > e2->ex_depth ? e1_depth : e2->ex_depth) + + 1; + expr->ex_flags = (e1_flags | e2->ex_flags) & ~EX_PARENS; + } + op = &expr->ex_object.ex_oper; + op->op_type = tp; + op->op_oper = oper; + op->op_left = e1; + op->op_right = e2; + + return expr; +} + +chk_cst_expr(expp) + register struct expr **expp; +{ + /* The expression expr is checked for constancy. + + There are 6 places where constant expressions occur in C: + 1. after #if + 2. in a global initialization + 3. as size in an array declaration + 4. as value in an enum declaration + 5. as width in a bit field + 6. as case value in a switch + + The constant expression in a global initialization is + handled separately (by IVAL()). + + There are various disparate restrictions on each of + the others in the various C compilers. I have tried some + hypotheses to unify them, but all have failed. + + This routine will give a warning for those operators + not allowed by K&R, under the R-option only. The anomalies + are cast, logical operators and the expression comma. + Special problems (of which there is only one, sizeof in + Preprocessor #if) have to be dealt with locally + + Note that according to K&R the negation ! is illegal in + constant expressions and is indeed rejected by the + Ritchie compiler. + */ + register struct expr *expr = *expp; + register int fund = expr->ex_type->tp_fund; + register int flags = expr->ex_flags; + register int err = 0; + +#ifdef DEBUG + print_expr("constant_expression", expr); +#endif DEBUG + if ( fund != CHAR && fund != SHORT && fund != INT && + fund != ENUM && fund != LONG + ) { + expr_error(expr, "non-numerical constant expression"), err++; + } + else + if (!is_ld_cst(expr)) + expr_error(expr, "expression is not constant"), err++; + + if (options['R']) { + if (flags & EX_CAST) + expr_warning(expr, + "cast in constant expression"); + if (flags & EX_LOGICAL) + expr_warning(expr, + "logical operator in constant expression"); + if (flags & EX_COMMA) + expr_warning(expr, + "expression comma in constant expression"); + } + + if (err) { + free_expression(expr); + *expp = intexpr((arith)1, INT); + (*expp)->ex_type = error_type; + } +} + +init_expression(eppp, expr) + struct expr ***eppp, *expr; +{ + /* The expression expr is added to the tree designated + indirectly by **eppp. + The natural form of a tree representing an + initial_value_list is right-recursive, ie. with the + left-most comma as main operator. The iterative grammar in + expression.g, however, tends to produce a left-recursive + tree, ie. one with the right-most comma as its main + operator. + To produce a right-recursive tree from the iterative + grammar, we keep track of the address of the pointer where + the next expression must be hooked in. + */ + **eppp = new_oper(void_type, expr, INITCOMMA, NILEXPR); + *eppp = &(**eppp)->OP_RIGHT; +} + +free_expression(expr) + struct expr *expr; +{ + /* The expression expr is freed recursively. + */ + if (!expr) + return; + if (expr->ex_class == Oper) { + free_expression(expr->OP_LEFT); + free_expression(expr->OP_RIGHT); + } + free_expr(expr); +} diff --git a/lang/cem/cemcom/expr.h b/lang/cem/cemcom/expr.h new file mode 100644 index 00000000..46e658a0 --- /dev/null +++ b/lang/cem/cemcom/expr.h @@ -0,0 +1,102 @@ +/* $Header$ */ +/* EXPRESSION DESCRIPTOR */ + +/* What we want to define is the struct expr, but since it contains + a union of various goodies, we define them first; so be patient. +*/ + +struct value { + struct idf *vl_idf; /* idf of an external name or 0 */ + arith vl_value; /* constant, or offset if idf != 0 */ +}; + +struct string { + char *sg_value; /* string of characters repr. the constant */ + label sg_datlab; /* global data-label */ +}; + +struct floating { + char *fl_value; /* pointer to string repr. the fp const. */ + label fl_datlab; /* global data_label */ +}; + +struct oper { + struct type *op_type; /* resulting type of the operation */ + struct expr *op_left; + int op_oper; /* the symbol of the operator */ + struct expr *op_right; +}; + +/* The following constants indicate the class of the expression: */ +#define Value 0 /* it is a value known at load time */ +#define String 1 /* it is a string constant */ +#define Float 2 /* it is a floating point constant */ +#define Oper 3 /* it is a run-time expression */ +#define Type 4 /* only its type is relevant */ + +struct expr { + struct expr *next; + char *ex_file; /* the file it (probably) comes from */ + unsigned int ex_line; /* the line it (probably) comes from */ + struct type *ex_type; + char ex_lvalue; + char ex_flags; + int ex_class; + int ex_depth; + union { + struct value ex_value; + struct string ex_string; + struct floating ex_float; + struct oper ex_oper; + } ex_object; +}; + +/* some abbreviated selections */ +#define VL_VALUE ex_object.ex_value.vl_value +#define VL_IDF ex_object.ex_value.vl_idf +#define SG_VALUE ex_object.ex_string.sg_value +#define SG_DATLAB ex_object.ex_string.sg_datlab +#define FL_VALUE ex_object.ex_float.fl_value +#define FL_DATLAB ex_object.ex_float.fl_datlab +#define OP_TYPE ex_object.ex_oper.op_type +#define OP_LEFT ex_object.ex_oper.op_left +#define OP_OPER ex_object.ex_oper.op_oper +#define OP_RIGHT ex_object.ex_oper.op_right + +#define EXPRTYPE(e) ((e)->ex_type->tp_fund) + +/* An expression is a `load-time constant' if it is of the form + +/- or ; + it is a `compile-time constant' if it is an . +*/ +#define is_ld_cst(e) ((e)->ex_lvalue == 0 && (e)->ex_class == Value) +#define is_cp_cst(e) (is_ld_cst(e) && (e)->VL_IDF == 0) + +/* a floating constant expression ? +*/ +#define is_fp_cst(e) ((e)->ex_class == Float) + +/* some bits for the ex_flag field, to keep track of various + interesting properties of an expression. +*/ +#define EX_SIZEOF 001 /* contains sizeof operator */ +#define EX_CAST 002 /* contains cast */ +#define EX_LOGICAL 004 /* contains logical operator */ +#define EX_COMMA 010 /* contains expression comma */ +#define EX_PARENS 020 /* the top level is parenthesized */ + +#define NILEXPR ((struct expr *)0) + +extern struct expr *intexpr(), *new_oper(); + + +/* allocation definitions of struct expr */ +/* ALLOCDEF "expr" */ +extern char *st_alloc(); +extern struct expr *h_expr; +#define new_expr() ((struct expr *) \ + st_alloc((char **)&h_expr, sizeof(struct expr))) +#define free_expr(p) st_free(p, h_expr, sizeof(struct expr)) + + +#define ISCOMMA(e) ((e)->ex_class == Oper && (e)->OP_OPER == INITCOMMA) diff --git a/lang/cem/cemcom/expr.str b/lang/cem/cemcom/expr.str new file mode 100644 index 00000000..46e658a0 --- /dev/null +++ b/lang/cem/cemcom/expr.str @@ -0,0 +1,102 @@ +/* $Header$ */ +/* EXPRESSION DESCRIPTOR */ + +/* What we want to define is the struct expr, but since it contains + a union of various goodies, we define them first; so be patient. +*/ + +struct value { + struct idf *vl_idf; /* idf of an external name or 0 */ + arith vl_value; /* constant, or offset if idf != 0 */ +}; + +struct string { + char *sg_value; /* string of characters repr. the constant */ + label sg_datlab; /* global data-label */ +}; + +struct floating { + char *fl_value; /* pointer to string repr. the fp const. */ + label fl_datlab; /* global data_label */ +}; + +struct oper { + struct type *op_type; /* resulting type of the operation */ + struct expr *op_left; + int op_oper; /* the symbol of the operator */ + struct expr *op_right; +}; + +/* The following constants indicate the class of the expression: */ +#define Value 0 /* it is a value known at load time */ +#define String 1 /* it is a string constant */ +#define Float 2 /* it is a floating point constant */ +#define Oper 3 /* it is a run-time expression */ +#define Type 4 /* only its type is relevant */ + +struct expr { + struct expr *next; + char *ex_file; /* the file it (probably) comes from */ + unsigned int ex_line; /* the line it (probably) comes from */ + struct type *ex_type; + char ex_lvalue; + char ex_flags; + int ex_class; + int ex_depth; + union { + struct value ex_value; + struct string ex_string; + struct floating ex_float; + struct oper ex_oper; + } ex_object; +}; + +/* some abbreviated selections */ +#define VL_VALUE ex_object.ex_value.vl_value +#define VL_IDF ex_object.ex_value.vl_idf +#define SG_VALUE ex_object.ex_string.sg_value +#define SG_DATLAB ex_object.ex_string.sg_datlab +#define FL_VALUE ex_object.ex_float.fl_value +#define FL_DATLAB ex_object.ex_float.fl_datlab +#define OP_TYPE ex_object.ex_oper.op_type +#define OP_LEFT ex_object.ex_oper.op_left +#define OP_OPER ex_object.ex_oper.op_oper +#define OP_RIGHT ex_object.ex_oper.op_right + +#define EXPRTYPE(e) ((e)->ex_type->tp_fund) + +/* An expression is a `load-time constant' if it is of the form + +/- or ; + it is a `compile-time constant' if it is an . +*/ +#define is_ld_cst(e) ((e)->ex_lvalue == 0 && (e)->ex_class == Value) +#define is_cp_cst(e) (is_ld_cst(e) && (e)->VL_IDF == 0) + +/* a floating constant expression ? +*/ +#define is_fp_cst(e) ((e)->ex_class == Float) + +/* some bits for the ex_flag field, to keep track of various + interesting properties of an expression. +*/ +#define EX_SIZEOF 001 /* contains sizeof operator */ +#define EX_CAST 002 /* contains cast */ +#define EX_LOGICAL 004 /* contains logical operator */ +#define EX_COMMA 010 /* contains expression comma */ +#define EX_PARENS 020 /* the top level is parenthesized */ + +#define NILEXPR ((struct expr *)0) + +extern struct expr *intexpr(), *new_oper(); + + +/* allocation definitions of struct expr */ +/* ALLOCDEF "expr" */ +extern char *st_alloc(); +extern struct expr *h_expr; +#define new_expr() ((struct expr *) \ + st_alloc((char **)&h_expr, sizeof(struct expr))) +#define free_expr(p) st_free(p, h_expr, sizeof(struct expr)) + + +#define ISCOMMA(e) ((e)->ex_class == Oper && (e)->OP_OPER == INITCOMMA) diff --git a/lang/cem/cemcom/expression.g b/lang/cem/cemcom/expression.g new file mode 100644 index 00000000..94976c64 --- /dev/null +++ b/lang/cem/cemcom/expression.g @@ -0,0 +1,371 @@ +/* $Header$ */ +/* EXPRESSION SYNTAX PARSER */ + +{ +#include "arith.h" +#include "LLlex.h" +#include "type.h" +#include "idf.h" +#include "label.h" +#include "expr.h" + +extern char options[]; +extern struct expr *intexpr(); +} + +/* 7 */ +initial_value(struct expr **expp;) : +[ + assignment_expression(expp) + { + if ((*expp)->ex_type->tp_fund == ARRAY) + array2pointer(expp); + } +| + initial_value_pack(expp) +] +; + +initial_value_pack(struct expr **expp;) : + '{' + initial_value_list(expp) + '}' +; + +initial_value_list(struct expr **expp;) + {struct expr *e1;} +: + {*expp = NILEXPR;} + initial_value(&e1) + {init_expression(&expp, e1);} + [%while (AHEAD != '}') /* >>> conflict on ',' */ + ',' + initial_value(&e1) + {init_expression(&expp, e1);} + ]* + ','? /* optional trailing comma */ +; + + +/* 7.1 */ +primary(struct expr **expp;) : +[ + IDENTIFIER + {dot2expr(expp);} +| + constant(expp) +| + STRING + {dot2expr(expp);} +| + '(' expression(expp) ')' + {(*expp)->ex_flags |= EX_PARENS;} +] +; + +secundary(struct expr **expp;) : + primary(expp) + [ + index_pack(expp) + | + parameter_pack(expp) + | + selection(expp) + ]* +; + +index_pack(struct expr **expp;) + {struct expr *e1;} +: + '[' expression(&e1) ']' + {ch7bin(expp, '[', e1);} +; + +parameter_pack(struct expr **expp;) + {struct expr *e1 = 0;} +: + '(' parameter_list(&e1)? ')' + {ch7bin(expp, '(', e1);} +; + +selection(struct expr **expp;) + {int oper; struct idf *idf;} +: + [ '.' | ARROW ] + {oper = DOT;} + identifier(&idf) + {ch7sel(expp, oper, idf);} +; + +parameter_list(struct expr **expp;) + {struct expr *e1 = 0;} +: + assignment_expression(expp) + {any2opnd(expp, PARCOMMA);} + [ ',' + assignment_expression(&e1) + {any2opnd(&e1, PARCOMMA);} + {ch7bin(expp, PARCOMMA, e1);} + ]* +; + +/* 7.2 */ +postfixed(struct expr **expp;) + {int oper;} +: + secundary(expp) + [ + postop(&oper) + {ch7incr(expp, oper);} + | + empty + ] +; + +%first first_of_type_specifier, type_specifier; + +unary(struct expr **expp;) + {struct type *tp; int oper;} +: +[%if (first_of_type_specifier(AHEAD)) + cast(&tp) unary(expp) + { ch7cast(expp, CAST, tp); + (*expp)->ex_flags |= EX_CAST; + } +| + postfixed(expp) +| + unop(&oper) unary(expp) + {ch7mon(oper, expp);} +| + size_of(expp) +] +; + +size_of(struct expr **expp;) + {struct type *tp;} +: + SIZEOF + [%if (first_of_type_specifier(AHEAD)) + cast(&tp) + { + *expp = intexpr(size_of_type(tp, "type"), INT); + (*expp)->ex_flags |= EX_SIZEOF; + } + | + unary(expp) + {ch7mon(SIZEOF, expp);} + ] +; + +/* 7.3-7.12 */ +/* The set of operators in C is stratified in 15 levels, with level + N being treated in RM 7.N. In principle each operator is + assigned a rank, ranging from 1 to 15. Such an expression can + be parsed by a construct like: + binary_expression(int maxrank;) + {int oper;} + : + binary_expression(maxrank - 1) + [%if (rank_of(DOT) <= maxrank) + binop(&oper) + binary_expression(rank_of(oper)-1) + ]? + ; + except that some call of 'unary' is necessary, depending on the + grammar. + + This simple view is marred by three complications: + 1. Level 15 (comma operator) is not allowed in many + contexts and is different. + 2. Level 13 (conditional operator) is a ternary operator, + which does not fit this scheme at all. + 3. Level 14 (assignment operators) group right-to-left, as + opposed to 2-12, which group left-to-right (or are + immaterial). + 4. The operators in level 14 start with operators in levels + 2-13 (RM 7.14: The two parts of a compound assignment + operator are separate tokens.) This causes LL1 problems. + This forces us to have four rules: + binary_expression for level 2-12 + conditional_expression for level 13 + assignment_expression for level 14 and + expression for the most general expression +*/ + +binary_expression(int maxrank; struct expr **expp;) + {int oper; struct expr *e1;} +: + unary(expp) + [%while (rank_of(DOT) <= maxrank && AHEAD != '=') + /* '?', '=', and ',' are no binops, and the test + for AHEAD != '=' keeps the other assignment + operators out + */ + binop(&oper) + binary_expression(rank_of(oper)-1, &e1) + { + ch7bin(expp, oper, e1); + } + ]* +; + +/* 7.13 */ +conditional_expression(struct expr **expp;) +/* There is some unfortunate disagreement about what is allowed + between the '?' and the ':' of a conditional_expression. + Although the Ritchie compiler does not even allow + conditional_expressions there, some other compilers (e.g., VAX) + accept a full assignment_expression there, and programs + (like, e.g., emacs) rely on it. So we have little choice. +*/ + {struct expr *e1 = 0, *e2 = 0;} +: + /* allow all binary operators */ + binary_expression(rank_of('?') - 1, expp) + [ '?' + expression(&e1) + {check_conditional(e1, '?', "between ? and :");} + ':' + assignment_expression(&e2) + {check_conditional(e2, '=', "after :");} + { + ch7bin(&e1, ':', e2); + opnd2test(expp, NOTEQUAL); + ch7bin(expp, '?', e1); + } + ]? +; + +/* 7.14 */ +assignment_expression(struct expr **expp;) + { + int oper; + struct expr *e1 = 0; + } +: + conditional_expression(expp) + [%prefer /* (rank_of(DOT) <= maxrank) for any asgnop */ + asgnop(&oper) + assignment_expression(&e1) + {ch7asgn(expp, oper, e1);} + | + empty /* LLgen artefact ??? */ + ] +; + +/* 7.15 */ +expression(struct expr **expp;) + {struct expr *e1;} +: + assignment_expression(expp) + [ ',' + assignment_expression(&e1) + { + ch7bin(expp, ',', e1); + } + ]* +; + +unop(int *oper;) : + ['*' | '&' | '-' | '!' | '~' | PLUSPLUS | MINMIN] + {*oper = DOT;} +; + +postop(int *oper;): +[ + PLUSPLUS {*oper = POSTINCR;} +| + MINMIN {*oper = POSTDECR;} +] +; + +multop: + '*' | '/' | '%' +; + +addop: + '+' | '-' +; + +shiftop: + LEFT | RIGHT +; + +relop: + '<' | '>' | LESSEQ | GREATEREQ +; + +eqop: + EQUAL | NOTEQUAL +; + +arithop: + multop | addop | shiftop +| + '&' | '^' | '|' +; + +binop(int *oper;) : + [ arithop | relop | eqop | AND | OR ] + {*oper = DOT;} +; + +asgnop(int *oper;): +[ + '=' {*oper = DOT;} +| + '+' '=' {*oper = PLUSAB;} +| + '-' '=' {*oper = MINAB;} +| + '*' '=' {*oper = TIMESAB;} +| + '/' '=' {*oper = DIVAB;} +| + '%' '=' {*oper = MODAB;} +| + LEFT '=' {*oper = LEFTAB;} +| + RIGHT '=' {*oper = RIGHTAB;} +| + '&' '=' {*oper = ANDAB;} +| + '^' '=' {*oper = XORAB;} +| + '|' '=' {*oper = ORAB;} +| + [ PLUSAB | MINAB | TIMESAB | DIVAB | MODAB | + LEFTAB | RIGHTAB | ANDAB | XORAB | ORAB ] + { + char *symbol2str(); + + warning("old-fashioned assignment operator, use %s", + symbol2str(DOT)); + *oper = DOT; + } +] +; + +constant(struct expr **expp;) : +[ + INTEGER +| + FLOATING +] {dot2expr(expp);} +; + +/* 15 */ +constant_expression (struct expr **expp;) : + assignment_expression(expp) + {chk_cst_expr(expp);} +; + +identifier(struct idf **idfp;) : +[ + IDENTIFIER +| + TYPE_IDENTIFIER +] + {*idfp = dot.tk_idf;} +; diff --git a/lang/cem/cemcom/faulty.h b/lang/cem/cemcom/faulty.h new file mode 100644 index 00000000..8b1a754a --- /dev/null +++ b/lang/cem/cemcom/faulty.h @@ -0,0 +1,5 @@ +/* $Header$ */ +/* FAULTY DEFINITIONS */ + +#define faulty(tp) ((tp)_faulty(__FILE__, __LINE__)) +#define fault() (_faulty(__FILE__, __LINE__)) diff --git a/lang/cem/cemcom/field.c b/lang/cem/cemcom/field.c new file mode 100644 index 00000000..d9cc1e29 --- /dev/null +++ b/lang/cem/cemcom/field.c @@ -0,0 +1,199 @@ +/* $Header$ */ +/* BITFIELD EXPRESSION EVALUATOR */ + +#include "nobitfield.h" + +#ifndef NOBITFIELD +#include "debug.h" + +#include "arith.h" +#include "type.h" +#include "idf.h" +#include "label.h" +#include "code.h" +#include "assert.h" +#include "expr.h" +#include "sizes.h" +#include "Lpars.h" +#include "field.h" +#include "em.h" + +arith tmp_pointer_var(); /* eval.c */ +char *symbol2str(); /* symbol2str.c */ + +/* Eval_field() evaluates expressions involving bit fields. + The various instructions are not yet optimised in the expression + tree and are therefore dealt with in this function. + The actions taken at any operation are described clearly by the + code for this actions. + Note: the bitfields are packed in target machine integers! +*/ +eval_field(expr, code) + struct expr *expr; + int code; +{ + int op = expr->OP_OPER; + struct expr *leftop = expr->OP_LEFT; + struct expr *rightop = expr->OP_RIGHT; + struct field *fd = leftop->ex_type->tp_field; + struct type *tp = leftop->ex_type->tp_up; + arith old_offset, tmpvar; + + /* The type in which the bitfield arithmetic is done: + */ + struct type *atype = tp->tp_unsigned ? uword_type : word_type; + arith asize = atype->tp_size; + + ASSERT(leftop->ex_type->tp_fund == FIELD); + ASSERT(asize == word_size); /* make sure that C_loc() is legal */ + + leftop->ex_type = atype; /* this is cheating but it works... */ + + /* Note that op is either an assignment operator or an increment/ + decrement operator + */ + if (op == '=') { + /* F = E: f = ((E & mask)<fd_mask); + C_and(asize); + if (code == TRUE) { + C_dup(asize); + } + C_loc((arith)fd->fd_shift); + + if (atype->tp_unsigned) + C_slu(asize); + else + C_sli(asize); + + C_loc(~((fd->fd_mask << fd->fd_shift) | (~0 << (8 * asize)))); + + if (leftop->ex_depth == 0) { /* simple case */ + load_val(leftop, RVAL); + C_and(asize); + C_ior(asize); + store_val( + leftop->VL_IDF, + leftop->ex_type, + leftop->VL_VALUE + ); + } + else { /* complex case */ + tmpvar = tmp_pointer_var(&old_offset); + EVAL(leftop, LVAL, TRUE, NO_LABEL, NO_LABEL); + C_dup(pointer_size); + C_lal(tmpvar); + C_sti(pointer_size); + C_loi(asize); + C_and(asize); + C_ior(asize); + C_lal(tmpvar); + C_loi(pointer_size); + C_sti(asize); + free_tmp_var(old_offset); + } + } + else { /* treat ++F as F += 1 and --F as F -= 1 */ + + /* F op= e: f = (((((f>>shift)&mask) op e)&mask)<ex_depth == 0) { /* simple case */ + load_val(leftop, RVAL); + } + else { /* complex case */ + tmpvar = tmp_pointer_var(&old_offset); + EVAL(leftop, LVAL, TRUE, NO_LABEL, NO_LABEL); + C_dup(pointer_size); + C_lal(tmpvar); + C_sti(pointer_size); + C_loi(asize); + } + + C_loc((arith)fd->fd_shift); + + if (atype->tp_unsigned) + C_sru(asize); + else + C_sri(asize); + + C_loc(fd->fd_mask); + C_and(asize); + + if (code == TRUE && (op == POSTINCR || op == POSTDECR)) { + C_dup(asize); + } + + EVAL(rightop, RVAL, TRUE, NO_LABEL, NO_LABEL); + conversion(tp, atype); + + /* generate the code for the operator + */ + if (op == PLUSPLUS || op == POSTINCR) + assop(atype, PLUSAB); + else + if (op == MINMIN || op == POSTDECR) + assop(atype, MINAB); + else + assop(atype, op); + + C_loc(fd->fd_mask); + C_and(asize); + + if (code == TRUE && op != POSTINCR && op != POSTDECR) { + C_dup(asize); + } + + C_loc((arith)fd->fd_shift); + + if (atype->tp_unsigned) + C_slu(asize); + else + C_sli(asize); + + C_loc(~((fd->fd_mask << fd->fd_shift) | (~0 << (8 * asize)))); + + if (leftop->ex_depth == 0) { + load_val(leftop, RVAL); + C_and(asize); + C_ior(asize); + store_val( + leftop->VL_IDF, + leftop->ex_type, + leftop->VL_VALUE + ); + } + else { + C_lal(tmpvar); + C_loi(pointer_size); + C_loi(asize); + C_and(asize); + C_ior(asize); + C_lal(tmpvar); + C_loi(pointer_size); + C_sti(asize); + free_tmp_var(old_offset); + } + } + + if (code == TRUE) { + /* Take care that the effective value stored in + the bit field (i.e. the value that is got on + retrieval) is on top of stack. + */ + if (atype->tp_unsigned == 0) { /* sign extension */ + register arith shift = asize * 8 - fd->fd_width; + + C_loc(shift); + C_sli(asize); + C_loc(shift); + C_sri(asize); + } + + conversion(atype, tp); + } +} +#endif NOBITFIELD diff --git a/lang/cem/cemcom/field.h b/lang/cem/cemcom/field.h new file mode 100644 index 00000000..794920b6 --- /dev/null +++ b/lang/cem/cemcom/field.h @@ -0,0 +1,20 @@ +/* $Header$ */ +/* FIELD DESCRIPTOR */ + +struct field { /* for field specifiers */ + struct field *next; + arith fd_mask; + int fd_shift; + int fd_width; + struct sdef *fd_sdef; /* upward pointer */ +}; + + +/* allocation definitions of struct field */ +/* ALLOCDEF "field" */ +extern char *st_alloc(); +extern struct field *h_field; +#define new_field() ((struct field *) \ + st_alloc((char **)&h_field, sizeof(struct field))) +#define free_field(p) st_free(p, h_field, sizeof(struct field)) + diff --git a/lang/cem/cemcom/field.str b/lang/cem/cemcom/field.str new file mode 100644 index 00000000..794920b6 --- /dev/null +++ b/lang/cem/cemcom/field.str @@ -0,0 +1,20 @@ +/* $Header$ */ +/* FIELD DESCRIPTOR */ + +struct field { /* for field specifiers */ + struct field *next; + arith fd_mask; + int fd_shift; + int fd_width; + struct sdef *fd_sdef; /* upward pointer */ +}; + + +/* allocation definitions of struct field */ +/* ALLOCDEF "field" */ +extern char *st_alloc(); +extern struct field *h_field; +#define new_field() ((struct field *) \ + st_alloc((char **)&h_field, sizeof(struct field))) +#define free_field(p) st_free(p, h_field, sizeof(struct field)) + diff --git a/lang/cem/cemcom/idf.c b/lang/cem/cemcom/idf.c new file mode 100644 index 00000000..f29f43ba --- /dev/null +++ b/lang/cem/cemcom/idf.c @@ -0,0 +1,697 @@ +/* $Header$ */ +/* IDENTIFIER FIDDLING & SYMBOL TABLE HANDLING */ + +#include "debug.h" +#include "idfsize.h" +#include "botch_free.h" +#include "nopp.h" +#include "alloc.h" +#include "arith.h" +#include "align.h" +#include "LLlex.h" +#include "level.h" +#include "stack.h" +#include "idf.h" +#include "label.h" +#include "def.h" +#include "type.h" +#include "struct.h" +#include "declarator.h" +#include "decspecs.h" +#include "sizes.h" +#include "Lpars.h" +#include "assert.h" +#include "specials.h" /* registration of special identifiers */ +#include "storage.h" + +int idfsize = IDFSIZE; +extern char options[]; + +char sp_occurred[SP_TOTAL]; /* indicate occurrence of special id */ + +struct idf *idf_hashtable[HASHSIZE]; + /* All identifiers can in principle be reached through + idf_hashtable; idf_hashtable[hc] is the start of a chain of + idf's whose tags all hash to hc. Each idf is the start of + a chain of def's for that idf, sorted according to level, + with the most recent one on top. + Any identifier occurring on a level is entered into this + list, regardless of the nature of its declaration + (variable, selector, structure tag, etc.). + */ + +struct idf * +idf_hashed(tg, size, hc) + char *tg; + int size; /* includes the '\0' character */ + int hc; +{ + /* The tag tg with length size and known hash value hc is + looked up in the identifier table; if not found, it is + entered. A pointer to it is returned. + The identifier has already been truncated to idfsize + characters. + */ + register struct idf **hook = &idf_hashtable[hc], *notch; + + while ((notch = *hook)) { + register cmp = strcmp(tg, notch->id_text); + + if (cmp < 0) + break; + else + if (cmp == 0) { + /* suppose that special identifiers, as + "setjmp", are already inserted + */ + sp_occurred[notch->id_special] = 1; + return notch; + } + else + hook = ¬ch->next; + } + /* a new struct idf must be inserted at the hook */ + notch = new_idf(); + clear((char *)notch, sizeof(struct idf)); + notch->next = *hook; + *hook = notch; /* hooked in */ + notch->id_text = Salloc(tg, size); +#ifndef NOPP + notch->id_resmac = 0; +#endif NOPP + return notch; +} + +#ifdef DEBUG +hash_stat() +{ + if (options['h']) { + int i; + + printf("Hash table tally:\n"); + for (i = 0; i < HASHSIZE; i++) { + struct idf *notch = idf_hashtable[i]; + int cnt = 0; + + while (notch) { + cnt++; + notch = notch->next; + } + printf("%d %d\n", i, cnt); + } + printf("End hash table tally\n"); + } +} +#endif DEBUG + +struct idf * +str2idf(tg) + char tg[]; +{ + /* str2idf() returns an entry in the symbol table for the + identifier tg. If necessary, an entry is created. + It is used where the text of the identifier is available + but its hash value is not; otherwise idf_hashed() is to + be used. + */ + register char *cp = tg; + register int hash; + register int pos = -1; + register int ch; + char ntg[IDFSIZE + 1]; + register char *ncp = ntg; + + hash = STARTHASH(); + while (++pos < idfsize && (ch = *cp++)) { + *ncp++ = ch; + hash = ENHASH(hash, ch, pos); + } + hash = STOPHASH(hash); + *ncp++ = '\0'; + return idf_hashed(ntg, ncp - ntg, hash); +} + +struct idf * +gen_idf() +{ + /* A new idf is created out of nowhere, to serve as an + anonymous name. + */ + static int name_cnt; + char buff[100]; + char *sprintf(); + + sprintf(buff, "#%d in %s, line %u", + ++name_cnt, dot.tk_file, dot.tk_line); + return str2idf(buff); +} + +int +is_anon_idf(idf) + struct idf *idf; +{ + return idf->id_text[0] == '#'; +} + +declare_idf(ds, dc, lvl) + struct decspecs *ds; + struct declarator *dc; +{ + /* The identifier inside dc is declared on the level lvl, with + properties deduced from the decspecs ds and the declarator + dc. + The level is given explicitly to be able to insert, e.g., + labels on the outermost level inside the function. + This routine implements the rich semantics of C + declarations. + */ + register struct idf *idf = dc->dc_idf; + register int sc = ds->ds_sc; + /* This local copy is essential: + char b(), c; + makes b GLOBAL and c AUTO. + */ + register struct def *def = idf->id_def; /* may be NULL */ + register struct type *type; + struct stack_level *stl = stack_level_of(lvl); + char formal_array = 0; + + /* determine the present type */ + if (ds->ds_type == 0) { + /* at the L_FORMAL1 level there is no type specified yet + */ + ASSERT(lvl == L_FORMAL1); + type = 0; + } + else { + /* combine the decspecs and the declarator into one type */ + type = declare_type(ds->ds_type, dc); + if (type->tp_size == (arith)-1) { + /* the type is not yet known */ + if (actual_declaration(sc, type)) { + /* but it has to be: */ + extern char *symbol2str(); + error("unknown %s-type", + symbol2str(type->tp_fund)); + } + } + } + + /* some additional work for formal definitions */ + if (lvl == L_FORMAL2) { + switch (type->tp_fund) { + + case FUNCTION: + warning("%s is a function; cannot be formal", + idf->id_text); + type = construct_type(POINTER, type, (arith)0); + break; + case ARRAY: /* RM 10.1 */ + type = construct_type(POINTER, type->tp_up, (arith)0); + formal_array = 1; + break; + case FLOAT: /* RM 10.1 */ + type = double_type; + break; + case CHAR: + case SHORT: + /* The RM is not clear about this: we must + convert the parameter from int (they have + been pushed as ints) to the specified type. + The conversion to type int or uint is not + allowed. + */ + break; + } + } + + /* The tests on types, postponed from do_decspecs(), can now + be performed. + */ + /* update the storage class */ + if (type && type->tp_fund == FUNCTION) { + if (sc == 0 || (ds->ds_sc_given && sc == AUTO)) /* RM 8.1 */ + sc = GLOBAL; + else + if (sc == REGISTER) { + error("function has illegal storage class"); + ds->ds_sc = sc = GLOBAL; + } + } + else { /* non-FUNCTION */ + if (sc == 0) + sc = + lvl == L_GLOBAL ? + GLOBAL : + lvl == L_FORMAL1 || lvl == L_FORMAL2 ? + FORMAL : + AUTO; + } + + if (options['R']) { + /* some special K & R tests */ + + /* is it also an enum? */ + if (idf->id_enum && idf->id_enum->tg_level == level) + warning("%s is also an enum tag", idf->id_text); + + /* is it a universal typedef? */ + if (def && def->df_level == L_UNIVERSAL) + warning("redeclaring reserved word %s", idf->id_text); + } + if (def && def->df_level >= lvl) { + /* There is already a declaration for idf on this + level, or even more inside. + The rules differ for different levels. + */ + switch (lvl) { + case L_GLOBAL: + global_redecl(idf, sc, type); + break; + case L_FORMAL1: /* formal declaration */ + error("formal %s redeclared", idf->id_text); + break; + case L_FORMAL2: /* formal definition */ + default: /* local */ + error("%s redeclared", idf->id_text); + break; + } + } + else /* the idf is unknown on this level */ + if (lvl == L_FORMAL2 && sc != ENUM && good_formal(def, idf)) { + /* formal declaration, update only */ + def->df_type = type; + def->df_formal_array = formal_array; + def->df_sc = sc; + if (def->df_sc != FORMAL) + crash("non-formal formal"); + def->df_register = (sc == REGISTER) ? REG_BONUS : REG_DEFAULT; + } + else + if ( lvl >= L_LOCAL && + (type->tp_fund == FUNCTION || sc == EXTERN) + ) { + /* extern declaration inside function is treated the + same way as global extern declaration + */ + if ( options['R'] && + (sc == STATIC && type->tp_fund == FUNCTION) + ) { + if (!is_anon_idf(idf)) + warning("non-global static function %s", + idf->id_text); + } + declare_idf(ds, dc, L_GLOBAL); + } + else { + /* fill in the def block */ + register struct def *newdef = new_def(); + + clear((char *)newdef, sizeof(struct def)); + newdef->next = def; + newdef->df_level = lvl; + newdef->df_type = type; + newdef->df_sc = sc; + + /* link it into the name list in the proper place */ + idf->id_def = newdef; + update_ahead(idf); + stack_idf(idf, stl); + + /* We now calculate the address. + Globals have names and don't get addresses, they + get numbers instead (through data_label()). + Formals are handled by declare_formals(). + So here we hand out local addresses only. + */ + + if (lvl >= L_LOCAL) { + switch (sc) { + case 0: + crash("local sc == 0"); + break; + case REGISTER: + case AUTO: + if (type->tp_size == (arith)-1) { + error("size of local \"%s\" unknown", + idf->id_text); + type = idf->id_def->df_type = int_type; + } + idf->id_def->df_register = + (sc == REGISTER) + ? REG_BONUS : REG_DEFAULT; + idf->id_def->df_address = + stl->sl_max_block = + stl->sl_local_offset = + -align(-stl->sl_local_offset + + type->tp_size, type->tp_align); + break; + case STATIC: + idf->id_def->df_address = (arith) data_label(); + break; + } + } + } +} + +actual_declaration(sc, tp) + struct type *tp; +{ + /* An actual_declaration needs space, right here and now. + */ + register int fund = tp->tp_fund; + + /* virtual declarations */ + if (sc == ENUM || sc == TYPEDEF) + return 0; + /* allocation solved in other ways */ + if (fund == FUNCTION || fund == ARRAY) + return 0; + /* to be allocated */ + return 1; +} + +global_redecl(idf, new_sc, tp) + struct idf *idf; + struct type *tp; +{ + /* A global identifier may be declared several times, + provided the declarations do not conflict; they might + conflict in type (or supplement each other in the case of + an array) or they might conflict or supplement each other + in storage class. + */ + register struct def *def = idf->id_def; + + if (tp != def->df_type) { + struct type *otp = def->df_type; + + if ( tp->tp_fund != ARRAY || otp->tp_fund != ARRAY || + tp->tp_up != otp->tp_up + ) { + error("redeclaration of %s with different type", + idf->id_text); + return; + } + /* Multiple array declaration; this may be interesting */ + if (tp->tp_size < 0) { /* new decl has [] */ + /* nothing new */ + } + else + if (otp->tp_size < 0) { /* old decl has [] */ + def->df_type = tp; + } + else + if (tp->tp_size != otp->tp_size) + error("inconsistent size in redeclaration of array %s", + idf->id_text); + } + + /* Now we may be able to update the storage class. */ + /* Clean out this mess as soon as we know all the possibilities + for new_sc. + For now we have: + EXTERN: we have seen the word "extern" + GLOBAL: the item was declared on the outer + level, without either "extern" or + "static". + STATIC: we have seen the word "static" + IMPLICIT: function declaration inferred from + call + */ + if (new_sc == IMPLICIT) + return; /* no new information */ + + switch (def->df_sc) { /* the old storage class */ + + case EXTERN: + switch (new_sc) { /* the new storage class */ + + case EXTERN: + case GLOBAL: + break; + case STATIC: + if (def->df_initialized) { + error("cannot redeclare %s to static", + idf->id_text); + } + else { + warning("%s redeclared to static", + idf->id_text); + def->df_sc = STATIC; + } + def->df_sc = new_sc; + break; + default: + crash("bad storage class"); + break; + } + break; + + case GLOBAL: + switch (new_sc) { /* the new storage class */ + + case EXTERN: + def->df_sc = EXTERN; + break; + case GLOBAL: + break; + case STATIC: + if (def->df_initialized) { + error("cannot redeclare %s to static", + idf->id_text); + } + else { + if (options['R']) + warning("%s redeclared to static", + idf->id_text); + def->df_sc = STATIC; + } + break; + default: + crash("bad storage class"); + break; + } + break; + + case STATIC: + switch (new_sc) { /* the new storage class */ + + case EXTERN: + if (def->df_initialized) { + error("cannot redeclare %s to extern", + idf->id_text); + } + else { + warning("%s redeclared to extern", + idf->id_text); + def->df_sc = EXTERN; + } + break; + case GLOBAL: + case STATIC: + if (def->df_type->tp_fund != FUNCTION) + warning("%s was already static", + idf->id_text); + break; + default: + crash("bad storage class"); + break; + } + break; + + case IMPLICIT: + switch (new_sc) { /* the new storage class */ + + case EXTERN: + case GLOBAL: + def->df_sc = new_sc; + break; + case STATIC: + if (options['R']) + warning("%s was implicitly declared as extern", + idf->id_text); + def->df_sc = new_sc; + break; + default: + crash("bad storage class"); + break; + } + break; + + case ENUM: + case TYPEDEF: + error("illegal redeclaration of %s", idf->id_text); + break; + default: + crash("bad storage class"); + break; + } +} + +int +good_formal(def, idf) + register struct def *def; + struct idf *idf; +{ + /* Succeeds if def is a proper L_FORMAL1 definition and + gives an error message otherwise. + */ + if (!def || def->df_level != L_FORMAL1) { + /* not in parameter list */ + if (!is_anon_idf(idf)) + error("%s not in parameter list", + idf->id_text); + return 0; + } + return 1; +} + +declare_params(dc) + struct declarator *dc; +{ + /* Declares the formal parameters if they exist. + */ + register struct idstack_item *is = dc->dc_fparams; + + while (is) { + declare_parameter(is->is_idf); + is = is->next; + } + del_idfstack(dc->dc_fparams); + dc->dc_fparams = 0; +} + +init_idf(idf) + struct idf *idf; +{ + /* The topmost definition of idf is set to initialized. + */ + register struct def *def = idf->id_def; /* the topmost */ + + if (def->df_initialized) + error("multiple initialization of %s", idf->id_text); + if (def->df_sc == TYPEDEF) { + warning("typedef cannot be initialized"); + def->df_sc == EXTERN; /* ??? *//* What else ? */ + } + def->df_initialized = 1; +} + +declare_parameter(idf) + struct idf *idf; +{ + /* idf is declared as a formal. + */ + add_def(idf, FORMAL, (struct type *)0, level); +} + +declare_enum(tp, idf, l) + struct type *tp; + struct idf *idf; + arith l; +{ + /* idf is declared as an enum constant with value l. + */ + add_def(idf, ENUM, tp, level); + idf->id_def->df_address = l; +} + +declare_formals(fp) + arith *fp; +{ + /* Declares those formals as int that haven't been declared + by the user. + An address is assigned to each formal parameter. + The total size of the formals is returned in *fp; + */ + struct stack_entry *se = stack_level_of(L_FORMAL1)->sl_entry; + arith f_offset = (arith)0; + +#ifdef DEBUG + if (options['t']) + dumpidftab("start declare_formals", 0); +#endif DEBUG + while (se) { + struct idf *idf = se->se_idf; + struct def *def = idf->id_def; + + if (def->df_type == 0) + def->df_type = int_type; /* default type */ + def->df_address = f_offset; + + /* the alignment convention for parameters is: align on + word boundaries, i.e. take care that the following + parameter starts on a new word boundary. + */ + f_offset = align(f_offset + def->df_type->tp_size, + word_align); + + /* the following is absurd: any char or short formal + must be converted from integer to that type + */ + formal_cvt(def); + se = se->next; + } + *fp = f_offset; +} + +add_def(idf, sc, tp, lvl) + struct idf *idf; + struct type *tp; + int lvl; + int sc; +{ + /* The identifier idf is declared on level lvl with storage + class sc and type tp, through a faked C declaration. + This is probably the wrong way to structure the problem, + but it will have to do for the time being. + */ + struct decspecs Ds; struct declarator Dc; + + Ds = null_decspecs; + Ds.ds_type = tp; + Ds.ds_sc = sc; + Dc = null_declarator; + Dc.dc_idf = idf; + declare_idf(&Ds, &Dc, lvl); +} + +update_ahead(idf) + register struct idf *idf; +{ + /* The tk_symb of the token ahead is updated in the light of new + information about the identifier idf. + */ + register int tk_symb = AHEAD; + + if ( (tk_symb == IDENTIFIER || tk_symb == TYPE_IDENTIFIER) && + ahead.tk_idf == idf + ) + AHEAD = idf->id_def && idf->id_def->df_sc == TYPEDEF ? + TYPE_IDENTIFIER : IDENTIFIER; +} + +del_idfstack(is) + struct idstack_item *is; +{ + while (is) { + register struct idstack_item *tmp = is->next; + free_idstack_item(is); + is = tmp; + } +} + +char hmask[IDFSIZE]; + +init_hmask() { + /* A simple congruence random number generator, as + described in Knuth, vol 2. + */ + int h, rnd = HASH_X; + + for (h = 0; h < IDFSIZE; h++) { + hmask[h] = rnd; + rnd = (HASH_A * rnd + HASH_C) & HASHMASK; + } +} diff --git a/lang/cem/cemcom/idf.h b/lang/cem/cemcom/idf.h new file mode 100644 index 00000000..12496de1 --- /dev/null +++ b/lang/cem/cemcom/idf.h @@ -0,0 +1,68 @@ +/* $Header$ */ +/* IDENTIFIER DESCRIPTOR */ + +#include "nopp.h" + +/* Since the % operation in the calculation of the hash function + turns out to be expensive, it is replaced by the cheaper XOR (^). + Each character of the identifier is xored with an 8-bit mask which + depends on the position of the character; the sum of these results + is the hash value. The random masks are obtained from a + congruence generator in idf.c. +*/ + +#define HASHSIZE 256 /* must be a power of 2 */ +#define HASH_X 0253 /* Knuth's X */ +#define HASH_A 77 /* Knuth's a */ +#define HASH_C 153 /* Knuth's c */ + +extern char hmask[]; /* the random masks */ +#define HASHMASK (HASHSIZE-1) /* since it is a power of 2 */ +#define STARTHASH() (0) +#define ENHASH(hs,ch,ps) (hs + (ch ^ hmask[ps])) +#define STOPHASH(hs) (hs & HASHMASK) + +struct idstack_item { /* stack of identifiers */ + struct idstack_item *next; + struct idf *is_idf; +}; + + +/* allocation definitions of struct idstack_item */ +/* ALLOCDEF "idstack_item" */ +extern char *st_alloc(); +extern struct idstack_item *h_idstack_item; +#define new_idstack_item() ((struct idstack_item *) \ + st_alloc((char **)&h_idstack_item, sizeof(struct idstack_item))) +#define free_idstack_item(p) st_free(p, h_idstack_item, sizeof(struct idstack_item)) + + +struct idf { + struct idf *next; + char *id_text; +#ifndef NOPP + struct macro *id_macro; + int id_resmac; /* if nonzero: keyword of macroproc. */ +#endif NOPP + int id_reserved; /* non-zero for reserved words */ + struct def *id_def; /* variables, typedefs, enum-constants */ + struct sdef *id_sdef; /* selector tags */ + struct tag *id_struct; /* struct and union tags */ + struct tag *id_enum; /* enum tags */ + int id_special; /* special action needed at occurrence */ +}; + + +/* allocation definitions of struct idf */ +/* ALLOCDEF "idf" */ +extern char *st_alloc(); +extern struct idf *h_idf; +#define new_idf() ((struct idf *) \ + st_alloc((char **)&h_idf, sizeof(struct idf))) +#define free_idf(p) st_free(p, h_idf, sizeof(struct idf)) + + +extern struct idf *str2idf(), *idf_hashed(); + +extern int level; +extern struct idf *gen_idf(); diff --git a/lang/cem/cemcom/idf.str b/lang/cem/cemcom/idf.str new file mode 100644 index 00000000..12496de1 --- /dev/null +++ b/lang/cem/cemcom/idf.str @@ -0,0 +1,68 @@ +/* $Header$ */ +/* IDENTIFIER DESCRIPTOR */ + +#include "nopp.h" + +/* Since the % operation in the calculation of the hash function + turns out to be expensive, it is replaced by the cheaper XOR (^). + Each character of the identifier is xored with an 8-bit mask which + depends on the position of the character; the sum of these results + is the hash value. The random masks are obtained from a + congruence generator in idf.c. +*/ + +#define HASHSIZE 256 /* must be a power of 2 */ +#define HASH_X 0253 /* Knuth's X */ +#define HASH_A 77 /* Knuth's a */ +#define HASH_C 153 /* Knuth's c */ + +extern char hmask[]; /* the random masks */ +#define HASHMASK (HASHSIZE-1) /* since it is a power of 2 */ +#define STARTHASH() (0) +#define ENHASH(hs,ch,ps) (hs + (ch ^ hmask[ps])) +#define STOPHASH(hs) (hs & HASHMASK) + +struct idstack_item { /* stack of identifiers */ + struct idstack_item *next; + struct idf *is_idf; +}; + + +/* allocation definitions of struct idstack_item */ +/* ALLOCDEF "idstack_item" */ +extern char *st_alloc(); +extern struct idstack_item *h_idstack_item; +#define new_idstack_item() ((struct idstack_item *) \ + st_alloc((char **)&h_idstack_item, sizeof(struct idstack_item))) +#define free_idstack_item(p) st_free(p, h_idstack_item, sizeof(struct idstack_item)) + + +struct idf { + struct idf *next; + char *id_text; +#ifndef NOPP + struct macro *id_macro; + int id_resmac; /* if nonzero: keyword of macroproc. */ +#endif NOPP + int id_reserved; /* non-zero for reserved words */ + struct def *id_def; /* variables, typedefs, enum-constants */ + struct sdef *id_sdef; /* selector tags */ + struct tag *id_struct; /* struct and union tags */ + struct tag *id_enum; /* enum tags */ + int id_special; /* special action needed at occurrence */ +}; + + +/* allocation definitions of struct idf */ +/* ALLOCDEF "idf" */ +extern char *st_alloc(); +extern struct idf *h_idf; +#define new_idf() ((struct idf *) \ + st_alloc((char **)&h_idf, sizeof(struct idf))) +#define free_idf(p) st_free(p, h_idf, sizeof(struct idf)) + + +extern struct idf *str2idf(), *idf_hashed(); + +extern int level; +extern struct idf *gen_idf(); diff --git a/lang/cem/cemcom/init.c b/lang/cem/cemcom/init.c new file mode 100644 index 00000000..dbb5dec2 --- /dev/null +++ b/lang/cem/cemcom/init.c @@ -0,0 +1,107 @@ +/* $Header$ */ +/* PREPROCESSOR: INITIALIZATION ROUTINES */ + +#include "nopp.h" + +#ifndef NOPP +#include "predefine.h" /* UF */ +#include "alloc.h" +#include "class.h" +#include "macro.h" +#include "idf.h" +#include "interface.h" +#include "system.h" +#include "string.h" + +PRIVATE struct mkey { + char *mk_reserved; + int mk_key; +} mkey[] = { + {"define", K_DEFINE}, + {"elif", K_ELIF}, + {"else", K_ELSE}, + {"endif", K_ENDIF}, + {"if", K_IF}, + {"ifdef", K_IFDEF}, + {"ifndef", K_IFNDEF}, + {"include", K_INCLUDE}, + {"line", K_LINE}, + {"undef", K_UNDEF}, + {0, K_UNKNOWN} +}; + +EXPORT +init_pp() +{ + time_type clock; + static char date[30]; + char *ctime(); + + /* Initialise the control line keywords (if, include, define, etc) + Although the lexical analyzer treats them as identifiers, the + control line handler can recognize them as keywords by the + id_resmac field of the identifier. + */ + { + register struct mkey *mk = &mkey[0]; + + while (mk->mk_reserved) { + struct idf *idf = str2idf(mk->mk_reserved); + + if (idf->id_resmac) + fatal("maximum identifier length insufficient"); + idf->id_resmac = mk->mk_key; + mk++; + } + } + + /* Initialize __DATE__, __FILE__ and __LINE__ macro + definitions. The compile-time specified predefined macros + are also predefined: if this file is compiled with + -DPREDEFINE="vax,pdp", the macro definitions "vax" and + "pdp" are predefined macros. + */ + /* __DATE__ */ + clock = sys_time((time_type *) 0); + strcpy(&date[1], ctime(&clock)); + date[26] = '\0'; /* zap nl */ + date[0] = date[25] = '"'; + macro_def(str2idf("__DATE__"), date, -1, 26, NOFLAG); + + /* __LINE__ */ + macro_def(str2idf("__LINE__"), "0", -1, 1, FUNC); + + /* __FILE__ */ + macro_def(str2idf("__FILE__"), "", -1, 1, FUNC); + +#ifdef PREDEFINE + { + /* PREDEFINE is a compile-time defined string + containing a number of identifiers to be + predefined at the host machine (for example + -DPREDEFINE="vax,unix,pmds"). + Note that PREDEF causes the identifier not + to be substituted. + */ + register char *s = PREDEFINE; + register char *id; + char c; + + for (;;) { + while (*s && class(*s++) != STIDF); + if (*s) { + /* gobble identifier */ + id = s - 1; + while (in_idf(*s++)); + c = *--s; + *s = '\0'; + macro_def(str2idf(id), "", -1, 0, PREDEF); + *s = c; + } + else + break; + } + } +#endif PREDEFINE +} +#endif NOPP diff --git a/lang/cem/cemcom/input.c b/lang/cem/cemcom/input.c new file mode 100644 index 00000000..e3015cdd --- /dev/null +++ b/lang/cem/cemcom/input.c @@ -0,0 +1,458 @@ +/* $Header$ */ +/* INPUT AND BUFFER HANDLING MODULE */ + +/* + [input.c input.h] + Input buffering module: this module contains the routines that + offers an input buffering mechanism to the user. + + This module exports the following objects: + InsertFile() : suspend input from current buffer and obtain the + next input characters from the specified file + InsertText() : suspend input from current buffer and take the + specified text as stream of input characters + LoadChar() : (defined in input.h) read next character from + the input ; LoadChar() invokes loadbuf() on + encounting a ASCII NUL character + NoUnstack : if set to non-zero: + loadbuf() reports "unexpected EOF" on encounting + the end-of-file or end-of-stacked-text. + + Imported objects are: + IDEPTH, DEBUG, READ_IN_ONE, PATHLENGTH: compile-time parameters + Malloc(), Salloc(): memory allocation routines + fatal(), lexerror(): exception handling + FileName, LineNumber, WorkingDir: input trace for lexical analyser + + READ_IN_ONE DEFINED: every input file is read into memory completely + and made an input buffer + READ_IN_ONE NOT DEFINED: the input from files is buffered in + a fixed length input buffer +*/ + +#include "nopp.h" +#include "inputtype.h" /* UF */ +#include "interface.h" +#include "arith.h" +#include "LLlex.h" +#include "input.h" +#include "alloc.h" +#include "system.h" +#include "bufsiz.h" + +#ifndef NOPP +#include "idepth.h" /* UF */ +#include "debug.h" /* UF */ +#include "pathlength.h" /* UF */ +#include "assert.h" +#endif NOPP + +EXPORT char *ipp = 0; /* input pointer */ +EXPORT int NoUnstack = 0; /* if 1: report EOF */ + +#ifndef READ_IN_ONE +PRIVATE int FilDes = -1; /* current input medium */ +#endif READ_IN_ONE + +#ifndef NOPP +struct buffer_header { + char *bh_name; /* file name where the text comes from */ + unsigned int bh_lineno; + /* current lineno in file */ + long bh_size; /* = strlen (text), should be unsigned */ + char *bh_text; /* pointer to buffer containing text */ + char *bh_ipp; /* current read pointer (= stacked ipp) */ + char *bh_wdir; /* directory of current file */ + int bh_fd; /* >= 0 (fd if !READ_IN_ONE) in case of file */ +}; + +PRIVATE struct buffer_header instack[IDEPTH]; /* stack of input media */ +PRIVATE struct buffer_header *head = 0; /* current input buffer */ + +IMPORT char **WorkingDir; /* name of current working directory */ +#else NOPP +long isize; +char ibuf[BUFSIZ]; +#endif NOPP + +#ifdef READ_IN_ONE +/* readfile() creates a buffer in which the text of the file + is situated. A pointer to the start of this text is + returned. *size is initialized with the buffer length. + Note that the file input buffer is prepared for the + preprocessor by inserting a '\n' in the beginning of the + text and appending a '\n' at the end of the text. The + file text start at position 1 of the input buffer. This is + done to allow pushback. +*/ + +PRIVATE char * +readfile(filename, size) + char *filename; + long *size; +{ + int fd; /* filedescriptor for `filename' */ + char *cbuf; /* pointer to buffer to be returned */ + register tmp; + + if ((fd = sys_open(filename, OP_RDONLY)) < 0) /* can't open this file */ + return (char *) 0; + + if ((*size = sys_fsize(fd)) < 0) + fatal("(readfile) cannot get size of file"); + + /* allocate enough space to store contents of the file */ + cbuf = Malloc(*size + 2); + + tmp = sys_read(fd, cbuf + 1, (int) *size); /* read the file */ + if (tmp != *size) + fatal("(readfile) bad read count"); + + (*size)++; /* keep book of the size! */ + sys_close(fd); /* filedes no longer needed */ + cbuf[0] = '\0'; /* allow pushback of first char */ + cbuf[*size] = '\0'; /* invoke loadbuf() at end */ + return cbuf; +} +#endif READ_IN_ONE + +#ifndef NOPP +#ifndef READ_IN_ONE +/* Input buffer supplying routines: pushbuf() and popbuf() +*/ +PRIVATE char *bufstack[IDEPTH] = 0; +PRIVATE bufstptr = 0; + +PRIVATE char * +pushbuf() +{ + if (bufstptr >= IDEPTH) + fatal("ran out of input buffers"); + if (bufstack[bufstptr] == 0) { + bufstack[bufstptr] = Malloc(BUFSIZ + 4); + } + return bufstack[bufstptr++]; +} + +PRIVATE +popbuf() +{ + bufstptr--; + ASSERT(bufstptr >= 0); +} +#endif READ_IN_ONE +#endif NOPP + +#ifndef NOPP +/* Input buffer administration: push_bh() and pop_bh() +*/ +PRIVATE struct buffer_header * +push_bh() +{ + if (head) { + if (head >= &instack[IDEPTH - 1]) + fatal("too many nested input texts"); + head->bh_ipp = ipp; + head->bh_lineno = LineNumber; + head++; + } + else + head = &instack[0]; + + return head; +} +#endif NOPP + +#ifndef NOPP +/* pop_bh() uncovers the previous inputbuffer on the stack + of headers. 0 is returned if there are no more + inputbuffers on the stack, 1 is returned in the other case. +*/ +PRIVATE int +pop_bh() +{ + int pfd = head->bh_fd; + + if (NoUnstack) { + lexerror("unexpected EOF"); + } + + if (head <= &instack[0]) { /* no more entries */ + head = (struct buffer_header *) 0; + return 0; + } + + ipp = (--head)->bh_ipp; /* restore the previous input pointer */ + + if (pfd >= 0) { /* unstack a file */ +#ifndef READ_IN_ONE + closefile(pfd); + popbuf(); /* free last buffer */ +#endif READ_IN_ONE + LineNumber = head->bh_lineno; + FileName = head->bh_name; + *WorkingDir = head->bh_wdir; + } + +#ifndef READ_IN_ONE + FilDes = head->bh_fd; +#endif READ_IN_ONE + + return 1; +} +#endif NOPP + +#ifndef READ_IN_ONE +/* low level IO routines: openfile(), readblock() and closefile() +*/ + +PRIVATE int +openfile(filename) + char *filename; +{ + int fd; /* filedescriptor for `filename' */ + + if ((fd = sys_open(filename, OP_RDONLY)) < 0 && sys_errno == EMFILE) + fatal("too many files open"); + return fd; +} + +PRIVATE +closefile(fd) +{ + sys_close(fd); +} + +PRIVATE int +readblock(fd, buf) + char buf[]; +{ + register n; + + if ((n = sys_read(fd, &buf[1], BUFSIZ)) < 0) { + fatal("(readblock) bad read from file"); + } + buf[0] = buf[n + 1] = '\0'; + return n; +} +#endif READ_IN_ONE + +/* Interface routines : InsertFile(), InsertText() and loadbuf() +*/ + +EXPORT int +InsertFile(filnam, table) + char *filnam; + char *table[]; +{ + char *mk_filename(), *newfn; + char *strcpy(); + +#ifdef READ_IN_ONE + char *readfile(), *text; + long size; +#else READ_IN_ONE + int fd = -1; +#endif READ_IN_ONE + + if (!filnam) + return 0; + +#ifndef NOPP + if (table == 0 || filnam[0] == '/') { /* don't look in the table! */ +#endif NOPP +#ifdef READ_IN_ONE + text = readfile(filnam, &size); +#else READ_IN_ONE + fd = openfile(filnam); +#endif READ_IN_ONE +#ifndef NOPP + } + else { + while (*table) { /* look in the directory table */ + newfn = mk_filename(*table++, filnam); +#ifdef READ_IN_ONE + if (text = readfile(newfn, &size)) +#else READ_IN_ONE + if ((fd = openfile(newfn)) >= 0) +#endif READ_IN_ONE + { + /* free filnam ??? */ + filnam = Salloc(newfn, strlen(newfn) + 1); + break; + } + } + } +#endif NOPP + +#ifdef READ_IN_ONE + if (text) +#else READ_IN_ONE + if (fd >= 0) +#endif READ_IN_ONE +#ifndef NOPP + { + struct buffer_header *push_bh(); + register struct buffer_header *bh = push_bh(); + + setwdir(WorkingDir, filnam); + bh->bh_lineno = LineNumber = 0; + bh->bh_name = FileName = filnam; + bh->bh_wdir = *WorkingDir; +#ifdef READ_IN_ONE + bh->bh_size = size; + bh->bh_fd = 0; /* this is a file */ + ipp = bh->bh_text = text; +#else READ_IN_ONE + bh->bh_size = readblock(fd, ipp = bh->bh_text = pushbuf()) + 1; + FilDes = bh->bh_fd = fd; +#endif READ_IN_ONE + bh->bh_text[0] = '\n'; /* wake up pp if '#' comes first */ + return 1; + } +#else NOPP + { +#ifdef READ_IN_ONE + isize = size; + ipp = text; +#else READ_IN_ONE + isize = readblock(FilDes = fd, ipp = &ibuf[0]) + 1; +#endif READ_IN_ONE + ibuf[0] = '\n'; + return 1; + } +#endif NOPP + return 0; +} + +#ifndef NOPP +EXPORT +InsertText(text, length) + char *text; +{ + struct buffer_header *push_bh(); + register struct buffer_header *bh = push_bh(); + + bh->bh_name = FileName; + bh->bh_lineno = LineNumber; + bh->bh_size = (long) length; + bh->bh_text = text; + bh->bh_wdir = *WorkingDir; + bh->bh_fd = -1; /* this is no file ! */ + ipp = text + 1; +#ifndef READ_IN_ONE + FilDes = -1; +#endif READ_IN_ONE +} +#endif NOPP + +/* loadbuf() is called if LoadChar meets a '\0' character + which may be the end-of-buffer mark of the current input + buffer. The '\0' could be genuine although not likely. + Note: this routine is exported due to its occurence in the definition + of LoadChar [input.h], that is defined as a macro. +*/ +EXPORT int +loadbuf() +{ +#ifndef NOPP + if (!head) { + /* stack exhausted, EOF on sourcefile */ + return EOI; + } +#endif NOPP + +#ifndef NOPP + if (ipp < &(head->bh_text[head->bh_size])) +#else NOPP + if (ipp < &ibuf[isize]) +#endif NOPP + { + /* a genuine '\0' character has been seen */ + return '\0'; + } + +#ifndef READ_IN_ONE +#ifndef NOPP + if (FilDes >= 0 && (head->bh_size = readblock(FilDes, head->bh_text)) > 0) + return ipp = &(head->bh_text[1]), *ipp++; +#else NOPP + if (FilDes >= 0 && (isize = readblock(FilDes, &ibuf[0])) > 0) + return ipp = &ibuf[1], *ipp++; +#endif NOPP + +#endif READ_IN_ONE + +#ifdef NOPP + if (NoUnstack) + lexerror("unexpected EOF"); +#ifndef READ_IN_ONE + closefile(FilDes); +#endif READ_IN_ONE +#endif NOPP + + return +#ifndef NOPP + pop_bh() ? (*ipp ? *ipp++ : loadbuf()) : +#endif NOPP + (ipp = &"\0\0"[1], EOI); +} + +/* Some miscellaneous routines : setwdir() and mk_filename() +*/ + +#ifndef NOPP +/* setwdir() updates *wdir according to the old working + directory (*wdir) and the filename fn, which may contain + some path name. The algorithm used here is: + setwdir(DIR, FILE): + if (FILE == "/***") + *DIR = "/" + else + if (contains(FILE, '/')) + *DIR = directory(FILE) + else + *DIR remains unchanged +*/ +PRIVATE +setwdir(wdir, fn) + char *fn, **wdir; +{ + register char *p; + char *rindex(); + + p = rindex(fn, '/'); + while (p && *(p + 1) == '\0') { /* remove trailing /'s */ + *p = '\0'; + p = rindex(fn, '/'); + } + + if (fn[0] == '\0' || (fn[0] == '/' && p == &fn[0])) /* absolute path */ + *wdir = "/"; + else + if (p) { + *p = '\0'; + *wdir = Salloc(fn, p - &fn[0] + 1); + *p = '/'; + } +} +#endif NOPP + +#ifndef NOPP +/* mk_filename() concatenates a dir and filename. +*/ +PRIVATE char * +mk_filename(dir, file) + register char *dir, *file; +{ + static char newfn[PATHLENGTH]; + register char *dst = &newfn[0]; + + if (!(dir[0] == '.' && dir[1] == '\0')) { + while (*dst++ = *dir++); + *(dst - 1) = '/'; + } + while (*dst++ = *file++); + return &newfn[0]; +} +#endif NOPP diff --git a/lang/cem/cemcom/input.h b/lang/cem/cemcom/input.h new file mode 100644 index 00000000..11185622 --- /dev/null +++ b/lang/cem/cemcom/input.h @@ -0,0 +1,13 @@ +/* $Header$ */ +/* INPUT PRIMITIVES */ + +#define LoadChar(dest) ((dest = *ipp++) || (dest = loadbuf())) +#define PushBack() (ipp--) + +/* EOF may be defined as -1 in most programs but the character -1 may + be expanded to the int -1 which causes troubles at the indexing in + the class or boolean arrays. +*/ +#define EOI (0200) + +extern char *ipp; diff --git a/lang/cem/cemcom/interface.h b/lang/cem/cemcom/interface.h new file mode 100644 index 00000000..d4a8c651 --- /dev/null +++ b/lang/cem/cemcom/interface.h @@ -0,0 +1,3 @@ +#define PRIVATE +#define IMPORT extern +#define EXPORT diff --git a/lang/cem/cemcom/ival.c b/lang/cem/cemcom/ival.c new file mode 100644 index 00000000..3a54e02a --- /dev/null +++ b/lang/cem/cemcom/ival.c @@ -0,0 +1,792 @@ +/* $Header$ */ +/* CODE FOR THE INITIALISATION OF GLOBAL VARIABLES */ + +#include "debug.h" +#include "nobitfield.h" + +#include "string.h" +#include "em.h" +#include "arith.h" +#include "align.h" +#include "label.h" +#include "expr.h" +#include "type.h" +#include "struct.h" +#include "field.h" +#include "assert.h" +#include "Lpars.h" +#include "class.h" +#include "sizes.h" +#include "idf.h" +#include "level.h" +#include "def.h" + +extern char *symbol2str(); + +#define con_byte(c) C_co_ucon(itos((long)(c) & 0xFF), (arith)1) + +struct expr *do_array(), *do_struct(), *IVAL(); +struct expr *strings = 0; /* list of string constants within initialiser */ +static ConStarted; /* indicates the generation of a 'con' pseudo */ + +/* do_ival() performs the initialisation of a global variable + of type tp with the initialisation expression expr by calling IVAL(). + Guided by type tp, the expression is evaluated. +*/ +do_ival(tpp, expr) + struct type **tpp; + struct expr *expr; +{ + ConStarted = 0; + if (IVAL(tpp, expr) != 0) + too_many_initialisers(expr); + /* The following loop declares the string constants + used in the initialisation. + The code for these string constants may not appear in + the code of the initialisation because a data label + in EM causes the current initialisation to be completed. + E.g. char *s[] = {"hello", "world"}; + */ + C_con_end(); + while (strings != 0) { + C_ndlb(strings->SG_DATLAB); + C_con_begin(); + C_co_scon(strings->SG_VALUE, (arith)0); + C_con_end(); + strings = strings->next; + } +} + + +/* store_string() collects the string constants appearing in an + initialisation. +*/ +store_string(expr) + struct expr *expr; +{ + expr->next = strings; + strings = expr; +} + + +/* IVAL() recursively guides the initialisation expression through the + different routines for the different types of initialisation: + - array initialisation + - struct initialisation + - fundamental type initialisation + Upto now, the initialisation of a union is not allowed! + An initialisation expression tree consists of normal expressions + which can be joined together by ',' nodes, which operator acts + like the lisp function "cons" to build lists. + IVAL() returns a pointer to the remaining expression tree. +*/ +struct expr * +IVAL(tpp, expr) + struct type **tpp; /* type of global variable */ + struct expr *expr; /* initialiser expression */ +{ + register struct type *tp = *tpp; + + switch (tp->tp_fund) { + case ARRAY: /* array initialisation */ + if (valid_type(tp->tp_up, "array element") == 0) + return 0; + if (ISCOMMA(expr)) { + /* list of initialisation expressions */ + return do_array(expr, tpp); + } + /* There might be an initialisation of a string + like char s[] = "I am a string" + */ + if (tp->tp_up->tp_fund == CHAR && expr->ex_class == String) + init_string(tpp, expr); + else /* " int i[24] = 12;" */ + check_and_pad(expr, tpp); + return 0; /* nothing left */ + case STRUCT: /* struct initialisation */ + if (valid_type(tp, "struct") == 0) + return 0; + if (ISCOMMA(expr)) { + /* list of initialisation expressions */ + return do_struct(expr, tp); + } + /* "struct foo f = 12;" */ + check_and_pad(expr, tpp); + return 0; + case UNION: /* sorry, but .... */ + error("union initialisation not allowed"); + return 0; + case ERRONEOUS: + return 0; + default: /* fundamental type */ + if (ISCOMMA(expr)) { /* " int i = {12};" */ + if (IVAL(tpp, expr->OP_LEFT) != 0) + too_many_initialisers(expr); + /* return remainings of the list for the + other members of the aggregate, if this + item belongs to an aggregate. + */ + return expr->OP_RIGHT; + } + else { /* "int i = 12;" */ + check_ival(expr, tp); + return 0; + } + } + /* NOTREACHED */ +} + +/* do_array() initialises the members of an array described + by type tp with the expressions in expr. + Two important cases: + - the number of members is known + - the number of members is not known + In the latter case, do_array() digests the whole expression + tree it is given. + In the former case, do_array() eats as many members from + the expression tree as are needed for the array. + If there are not sufficient members for the array, the remaining + members are padded with zeroes +*/ +struct expr * +do_array(expr, tpp) + struct expr *expr; + struct type **tpp; +{ + /* it is certain that ISCOMMA(expr) and tp->tp_fund == ARRAY */ + register struct type *tp = *tpp; + register arith elem_count; + + ASSERT(tp->tp_fund == ARRAY); + /* the following test catches initialisations like + char c[] = {"just a string"}; + or + char d[] = {{"just another string"}} + The use of the brackets causes this problem. + Note: although the implementation of such initialisations + is completely foolish, we did it!! (no applause, thank you) + */ + if (tp->tp_up->tp_fund == CHAR) { + register struct expr *f = expr->OP_LEFT; + register struct expr *g = 0; + + while (ISCOMMA(f)) { /* eat the brackets!!! */ + g = f; + f = f->OP_LEFT; + } + if (f->ex_class == String) { /* hallelujah, it's a string! */ + init_string(tpp, f); + return g ? g->OP_RIGHT : expr->OP_RIGHT; + } + /* else: just go on with the next part of this function */ + if (g != 0) + expr = g; + } + if (tp->tp_size == (arith)-1) { + /* declared with unknown size: [] */ + for (elem_count = 0; expr; elem_count++) { + /* eat whole initialisation expression */ + if (ISCOMMA(expr->OP_LEFT)) { + /* the member expression is embraced */ + if (IVAL(&(tp->tp_up), expr->OP_LEFT) != 0) + too_many_initialisers(expr); + expr = expr->OP_RIGHT; + } + else { + if (aggregate_type(tp->tp_up)) + expr = IVAL(&(tp->tp_up), expr); + else { + check_ival(expr->OP_LEFT, tp->tp_up); + expr = expr->OP_RIGHT; + } + } + } + /* set the proper size */ + *tpp = construct_type(ARRAY, tp->tp_up, elem_count); + } + else { /* the number of members is already known */ + arith dim = tp->tp_size / tp->tp_up->tp_size; + + for (elem_count = 0; elem_count < dim && expr; elem_count++) { + if (ISCOMMA(expr->OP_LEFT)) { + /* embraced member initialisation */ + if (IVAL(&(tp->tp_up), expr->OP_LEFT) != 0) + too_many_initialisers(expr); + expr = expr->OP_RIGHT; + } + else { + if (aggregate_type(tp->tp_up)) + /* the member is an aggregate */ + expr = IVAL(&(tp->tp_up), expr); + else { + check_ival(expr->OP_LEFT, tp->tp_up); + expr = expr->OP_RIGHT; + } + } + } + if (expr && elem_count == dim) + /* all the members are initialised but there + remains a part of the expression tree which + is returned + */ + return expr; + if ((expr == 0) && elem_count < dim) { + /* the expression tree is completely absorbed + but there are still members which must be + initialised with zeroes + */ + do + pad(tp->tp_up); + while (++elem_count < dim); + } + } + return 0; +} + + +/* do_struct() initialises a struct of type tp with the expression expr. + The main loop is just controlled by the definition of the selectors + during which alignment is taken care of. +*/ +struct expr * +do_struct(expr, tp) + struct expr *expr; + struct type *tp; +{ + /* tp is a STRUCT and expr->OP_OPER == INITCOMMA */ + + struct sdef *sd = tp->tp_sdef; + arith bytes_upto_here = (arith)0; + arith last_offset = (arith)-1; + + /* as long as there are selectors and there is an initialiser.. */ + while (sd && expr) { + if (ISCOMMA(expr->OP_LEFT)) { /* embraced expression */ + if (IVAL(&(sd->sd_type), expr->OP_LEFT) != 0) + too_many_initialisers(expr); + expr = expr->OP_RIGHT; + } + else { + if (aggregate_type(sd->sd_type)) + /* selector is an aggregate itself */ + expr = IVAL(&(sd->sd_type), expr); + else { +#ifdef NOBITFIELD + /* fundamental type, not embraced */ + check_ival(expr->OP_LEFT, sd->sd_type); + expr = expr->OP_RIGHT; +#else + if (is_anon_idf(sd->sd_idf)) + /* a hole in the struct due to + the use of ";:n;" in a struct + definition. + */ + put_bf(sd->sd_type, (arith)0); + else { + /* fundamental type, not embraced */ + check_ival(expr->OP_LEFT, + sd->sd_type); + expr = expr->OP_RIGHT; + } +#endif NOBITFIELD + } + } + /* align upto the next selector boundary */ + if (sd->sd_sdef) + bytes_upto_here += zero_bytes(sd); + if (last_offset != sd->sd_offset) { + /* don't take the field-width more than once */ + bytes_upto_here += size_of_type(sd->sd_type, "selector"); + last_offset = sd->sd_offset; + } + sd = sd->sd_sdef; + } + /* perfect fit if (expr && (sd == 0)) holds */ + if ((expr == 0) && (sd != 0)) { + /* there are selectors left which must be padded with + zeroes + */ + do { + pad(sd->sd_type); + /* take care of the alignment restrictions */ + if (sd->sd_sdef) + bytes_upto_here += zero_bytes(sd); + /* no field thrown-outs here */ + bytes_upto_here += size_of_type(sd->sd_type, "selector"); + } while (sd = sd->sd_sdef); + } + /* keep on aligning... */ + while (bytes_upto_here++ < tp->tp_size) + con_byte(0); + return expr; +} + +/* check_and_pad() is given a simple initialisation expression + where the type can be either a simple or an aggregate type. + In the latter case, only the first member is initialised and + the rest is zeroed. +*/ +check_and_pad(expr, tpp) + struct expr *expr; + struct type **tpp; +{ + /* expr is of a fundamental type */ + struct type *tp = *tpp; + + if (tp->tp_fund == ARRAY) { + if (valid_type(tp->tp_up, "array element") == 0) + return; + check_and_pad(expr, &(tp->tp_up)); /* first member */ + if (tp->tp_size == (arith)-1) + /* no size specified upto here: just + set it to the size of one member. + */ + tp = *tpp = + construct_type(ARRAY, tp->tp_up, (arith)1); + else { + register dim = tp->tp_size / tp->tp_up->tp_size; + /* pad remaining members with zeroes */ + while (--dim > 0) + pad(tp->tp_up); + } + } + else + if (tp->tp_fund == STRUCT) { + register struct sdef *sd = tp->tp_sdef; + + if (valid_type(tp, "struct") == 0) + return; + check_and_pad(expr, &(sd->sd_type)); + /* Next selector is aligned by adding extra zeroes */ + if (sd->sd_sdef) + zero_bytes(sd); + while (sd = sd->sd_sdef) { /* pad remaining selectors */ + pad(sd->sd_type); + if (sd->sd_sdef) + zero_bytes(sd); + } + } + else /* simple type */ + check_ival(expr, tp); +} + +/* pad() fills an element of type tp with zeroes. + If the element is an aggregate, pad() is called recursively. +*/ +pad(tp) + struct type *tp; +{ + if (ConStarted == 0) { + C_con_begin(); + ConStarted = 1; + } + switch (tp->tp_fund) { + case ARRAY: + { + register long dim; + + if (valid_type(tp->tp_up, "array element") == 0) + return; + + dim = tp->tp_size / tp->tp_up->tp_size; + + /* Assume the dimension is known */ + while (dim-- > 0) + pad(tp->tp_up); + break; + } + case STRUCT: + { + register struct sdef *sdef = tp->tp_sdef; + + if (valid_type(tp, "struct") == 0) + return; + + do { + pad(sdef->sd_type); + if (sdef->sd_sdef) + zero_bytes(sdef); + } while (sdef = sdef->sd_sdef); + break; + } +#ifndef NOBITFIELD + case FIELD: + put_bf(tp, (arith)0); + break; +#endif NOBITFIELD + case INT: + case SHORT: + case LONG: + case CHAR: + case ENUM: + case POINTER: + C_co_ucon("0", tp->tp_size); + break; + case FLOAT: + case DOUBLE: + C_co_fcon("0", tp->tp_size); + break; + case UNION: + error("initialisation of unions not allowed"); + break; + case ERRONEOUS: + break; + default: + crash("(generate) bad fundamental type %s\n", + symbol2str(tp->tp_fund)); + } +} + +/* check_ival() checks whether the initialisation of an element + of a fundamental type is legal and, if so, performs the initialisation + by directly generating the necessary code. + No further comment is needed to explain the internal structure + of this straightforward function. +*/ +check_ival(expr, type) + struct expr *expr; + struct type *type; +{ + /* The philosophy here is that ch7cast puts an explicit + conversion node in front of the expression if the types + are not compatible. In this case, the initialisation is + not legal. ??? + */ + + switch (type->tp_fund) { + case CHAR: + case SHORT: + case INT: + case LONG: + if (expr->ex_class == Oper || expr->VL_IDF != 0) { + illegal_init_cst(expr); + break; + } + ch7cast(&expr, '=', type); + if (ConStarted == 0) { + C_con_begin(); + ConStarted = 1; + } + con_int(expr); + break; +#ifndef NOBITFIELD + case FIELD: + if (expr->ex_class == Oper || expr->VL_IDF != 0) { + illegal_init_cst(expr); + break; + } + ch7cast(&expr, '=', type->tp_up); + put_bf(type, expr->VL_VALUE); + break; +#endif NOBITFIELD + case ENUM: + if (expr->ex_class == Oper) { + illegal_init_cst(expr); + break; + } + ch7cast(&expr, '=', type); + if (ConStarted == 0) { + C_con_begin(); + ConStarted = 1; + } + con_int(expr); + break; + case FLOAT: + case DOUBLE: + ch7cast(&expr, '=', type); + if (ConStarted == 0) { + C_con_begin(); + ConStarted = 1; + } + if (expr->ex_class == Float) + C_co_fcon(expr->FL_VALUE, expr->ex_type->tp_size); + else + if (expr->ex_class == Oper && expr->OP_OPER == INT2FLOAT) { + expr = expr->OP_RIGHT; + if (expr->ex_class == Value && expr->VL_IDF == 0) + C_co_fcon(itos(expr->VL_VALUE), type->tp_size); + else + illegal_init_cst(expr); + } + else + illegal_init_cst(expr); + break; + case POINTER: + ch7cast(&expr, '=', type); + switch (expr->ex_class) { + case Oper: + illegal_init_cst(expr); + break; + case String: /* char *s = "...." */ + { + label datlab = data_label(); + + if (ConStarted) + C_con_end(); + else + ConStarted = 1; /* ??? */ + C_ina_pt(datlab); + C_con_begin(); + C_co_ndlb(datlab, (arith)0); + expr->SG_DATLAB = datlab; + store_string(expr); + break; + } + case Value: + { + struct value *vl = &(expr->ex_object.ex_value); + struct idf *idf = vl->vl_idf; + + ASSERT(expr->ex_type->tp_fund == POINTER); + if (ConStarted == 0) { + C_con_begin(); + ConStarted = 1; + } + if (expr->ex_type->tp_up->tp_fund == FUNCTION) { + if (idf) + C_co_pnam(idf->id_text); + else /* int (*func)() = 0 */ + con_int(expr); + } + else + if (idf) { + register struct def *def = idf->id_def; + + if (def->df_level >= L_LOCAL) { + if (def->df_sc != STATIC) + /* Eg. int a; + static int *p = &a; + */ + expr_error(expr, + "illegal initialisation"); + else + C_co_ndlb((label)def->df_address, + vl->vl_value); + } + else + C_co_dnam(idf->id_text, vl->vl_value); + } + else + con_int(expr); + break; + } + default: + crash("(check_ival) illegal initialisation expression"); + } + break; + case ERRONEOUS: + break; + default: + crash("(check_ival) bad fundamental type %s", + symbol2str(type->tp_fund)); + } +} + +/* init_string() initialises an array of characters by specifying + a string constant. + Escaped characters should be converted into its corresponding + ASCII character value. E.g. '\000' -> (char) 0. + Alignment is taken care of. +*/ +init_string(tpp, expr) + struct type **tpp; /* type tp = array of characters */ + struct expr *expr; +{ + register struct type *tp = *tpp; + register arith length; + char *s = expr->SG_VALUE; + arith ntopad; + + length = prepare_string(s); + if (tp->tp_size == (arith)-1) { + /* set the dimension */ + tp = *tpp = construct_type(ARRAY, tp->tp_up, length); + ntopad = align(tp->tp_size, word_align) - tp->tp_size; + } + else { + arith dim = tp->tp_size / tp->tp_up->tp_size; + + ntopad = align(dim, word_align) - length; + if (length > dim) + expr_error(expr, + "too many characters in initialiser string"); + } + if (ConStarted == 0) { + C_con_begin(); + ConStarted = 1; + } + /* throw out the characters of the already prepared string */ + do + con_byte(*s++); + while (--length > 0); + /* pad the allocated memory (the alignment has been calculated) */ + while (ntopad-- > 0) + con_byte(0); +} + +/* prepare_string() strips the escaped characters of a + string and replaces them by the ascii characters they stand for. + The ascii length of the resulting string is returned, including the + terminating null-character. +*/ +int +prepare_string(str) + register char *str; +{ + register char *t = str; + register count = 1; /* there's always a null at the end ! */ + + while (*str) { + count++; + if (*str == '\\') { + switch (*++str) { + case 'b': + *t++ = '\b'; + str++; + break; + case 'f': + *t++ = '\f'; + str++; + break; + case 'n': + *t++ = '\n'; + str++; + break; + case 'r': + *t++ = '\r'; + str++; + break; + case 't': + *t++ = '\t'; + str++; + break; + + /* octal value of: */ + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + { + register cnt = 0, oct = 0; + + do + oct = oct * 8 + *str - '0'; + while (is_oct(*++str) && ++cnt < 3); + *t++ = (char) oct; + break; + } + default: + *t++ = *str++; + break; + } + } + else + *t++ = *str++; + } + *t = '\0'; /* don't forget this one !!! */ + return count; +} + +#ifndef NOBITFIELD +/* put_bf() takes care of the initialisation of (bit-)field + selectors of a struct: each time such an initialisation takes place, + put_bf() is called instead of the normal code generating routines. + Put_bf() stores the given integral value into "field" and + "throws" the result of "field" out if the current selector + is the last of this number of fields stored at the same address. +*/ +put_bf(tp, val) + struct type *tp; + arith val; +{ + static long field = (arith)0; + static arith offset = (arith)-1; + register struct field *fd = tp->tp_field; + register struct sdef *sd = fd->fd_sdef; + static struct expr expr; + + ASSERT(sd); + if (offset == (arith)-1) { + /* first bitfield in this field */ + offset = sd->sd_offset; + expr.ex_type = tp->tp_up; + expr.ex_class = Value; + } + if (val != 0) /* insert the value into "field" */ + field |= (val & fd->fd_mask) << fd->fd_shift; + if (sd->sd_sdef == 0 || sd->sd_sdef->sd_offset != offset) { + /* the selector was the last stored at this address */ + expr.VL_VALUE = field; + if (ConStarted == 0) { + C_con_begin(); + ConStarted = 1; + } + con_int(&expr); + field = (arith)0; + offset = (arith)-1; + } +} +#endif NOBITFIELD + +int +zero_bytes(sd) + struct sdef *sd; +{ + /* fills the space between a selector of a struct + and the next selector of that struct with zero-bytes. + */ + register int n = + sd->sd_sdef->sd_offset - sd->sd_offset - + size_of_type(sd->sd_type, "struct member"); + register count = n; + + while (n-- > 0) + con_byte((arith)0); + return count; +} + +int +valid_type(tp, str) + struct type *tp; + char *str; +{ + if (tp->tp_size < 0) { + error("size of %s unknown", str); + return 0; + } + return 1; +} + +con_int(expr) + register struct expr *expr; +{ + register struct type *tp = expr->ex_type; + + if (tp->tp_unsigned) + C_co_ucon(itos(expr->VL_VALUE), tp->tp_size); + else + C_co_icon(itos(expr->VL_VALUE), tp->tp_size); +} + +illegal_init_cst(expr) + struct expr *expr; +{ + if (expr->ex_type->tp_fund != ERRONEOUS) + expr_error(expr, "illegal initialisation constant"); +} + +too_many_initialisers(expr) + struct expr *expr; +{ + expr_error(expr, "too many initialisers"); +} + +aggregate_type(tp) + struct type *tp; +{ + return tp->tp_fund == ARRAY || tp->tp_fund == STRUCT; +} diff --git a/lang/cem/cemcom/label.c b/lang/cem/cemcom/label.c new file mode 100644 index 00000000..0ced30b0 --- /dev/null +++ b/lang/cem/cemcom/label.c @@ -0,0 +1,88 @@ +/* $Header$ */ +/* L A B E L H A N D L I N G */ + +#include "Lpars.h" +#include "level.h" +#include "idf.h" +#include "label.h" +#include "arith.h" +#include "def.h" +#include "type.h" + +extern char options[]; + +define_label(idf) + struct idf *idf; +{ + /* The identifier idf is defined as a label. If it is new, + it is entered into the idf list with the largest possible + scope, i.e., on the lowest possible level. + */ + enter_label(idf, 1); +} + +apply_label(idf) + struct idf *idf; +{ + /* The identifier idf is applied as a label. It may or may + not be there, and if it is there, it may be from a + declaration or another application. + */ + enter_label(idf, 0); +} + +enter_label(idf, defining) + struct idf *idf; +{ + /* The identifier idf is entered as a label. If it is new, + it is entered into the idf list with the largest possible + scope, i.e., on the lowest possible level. + If defining, the label comes from a label statement. + */ + if (idf->id_def) { + struct def *def = idf->id_def; + + if (def->df_sc == LABEL) { + if (defining && def->df_initialized) + error("redeclaration of label %s", + idf->id_text); + } + else { /* there may still be room for it */ + int deflevel = def->df_level; + + if (options['R'] && def->df_sc == TYPEDEF) + warning("label %s is also a typedef", + idf->id_text); + + if (deflevel == level) /* but alas, no */ + error("%s is not a label", idf->id_text); + else { + int lvl; + + if (options['R'] && deflevel > L_LOCAL) + warning("label %s is not function-wide", + idf->id_text); + lvl = deflevel + 1; + if (lvl < L_LOCAL) + lvl = L_LOCAL; + add_def(idf, LABEL, label_type, lvl); + } + } + } + else { + add_def(idf, LABEL, label_type, L_LOCAL); + } + if (idf->id_def->df_address == 0) + idf->id_def->df_address = (arith) text_label(); + if (defining) + idf->id_def->df_initialized = 1; +} + +unstack_label(idf) + struct idf *idf; +{ + /* The scope in which the label idf occurred is left. + */ + if (!idf->id_def->df_initialized && !is_anon_idf(idf)) + error("label %s not defined", idf->id_text); +} diff --git a/lang/cem/cemcom/label.h b/lang/cem/cemcom/label.h new file mode 100644 index 00000000..dc93d5c3 --- /dev/null +++ b/lang/cem/cemcom/label.h @@ -0,0 +1,11 @@ +/* $Header$ */ +/* L A B E L D E F I N I T I O N */ + +#define label unsigned int +#define NO_LABEL (label) 0 + +extern label lab_count; +#define text_label() (lab_count++) /* returns a new text label */ + +extern label datlab_count; +#define data_label() (datlab_count++) /* returns a new data label */ diff --git a/lang/cem/cemcom/level.h b/lang/cem/cemcom/level.h new file mode 100644 index 00000000..f4ee6166 --- /dev/null +++ b/lang/cem/cemcom/level.h @@ -0,0 +1,15 @@ +/* $Header$ */ +/* LEVEL DEFINITIONS */ + +/* The level of the top-most stack_level is kept in a global variable + with the obvious name 'level'. Although this variable is consulted + by a variety of routines, it turns out that its actual value is of + importance in only a very few files. Therefore the names of the + values are put in a separate include-file. +*/ + +#define L_UNIVERSAL 0 +#define L_GLOBAL 1 +#define L_FORMAL1 2 /* formal declaration */ +#define L_FORMAL2 3 /* formal definition */ +#define L_LOCAL 4 /* and up */ diff --git a/lang/cem/cemcom/macro.h b/lang/cem/cemcom/macro.h new file mode 100644 index 00000000..cdd023f8 --- /dev/null +++ b/lang/cem/cemcom/macro.h @@ -0,0 +1,52 @@ +/* $Header$ */ +/* PREPROCESSOR: DEFINITION OF MACRO DESCRIPTOR */ + +#include "nopp.h" + +#ifndef NOPP +/* The flags of the mc_flag field of the macro structure. Note that + these flags can be set simultaneously. +*/ +#define NOFLAG 0 /* no special flags */ +#define FUNC 01 /* function attached */ +#define PREDEF 02 /* predefined macro */ + +#define FORMALP 0200 /* mask for creating macro formal parameter */ + +/* The macro descriptor is very simple, except the fact that the + mc_text, which points to the replacement text, contains the + non-ascii characters \201, \202, etc, indicating the position of a + formal parameter in this text. +*/ +struct macro { + struct macro *next; + char * mc_text; /* the replacement text */ + int mc_nps; /* number of formal parameters */ + int mc_length; /* length of replacement text */ + char mc_flag; /* marking this macro */ +}; + + +/* allocation definitions of struct macro */ +/* ALLOCDEF "macro" */ +extern char *st_alloc(); +extern struct macro *h_macro; +#define new_macro() ((struct macro *) \ + st_alloc((char **)&h_macro, sizeof(struct macro))) +#define free_macro(p) st_free(p, h_macro, sizeof(struct macro)) + + +/* `token' numbers of keywords of command-line processor +*/ +#define K_UNKNOWN 0 +#define K_DEFINE 1 +#define K_ELIF 2 +#define K_ELSE 3 +#define K_ENDIF 4 +#define K_IF 5 +#define K_IFDEF 6 +#define K_IFNDEF 7 +#define K_INCLUDE 8 +#define K_LINE 9 +#define K_UNDEF 10 +#endif NOPP diff --git a/lang/cem/cemcom/macro.str b/lang/cem/cemcom/macro.str new file mode 100644 index 00000000..cdd023f8 --- /dev/null +++ b/lang/cem/cemcom/macro.str @@ -0,0 +1,52 @@ +/* $Header$ */ +/* PREPROCESSOR: DEFINITION OF MACRO DESCRIPTOR */ + +#include "nopp.h" + +#ifndef NOPP +/* The flags of the mc_flag field of the macro structure. Note that + these flags can be set simultaneously. +*/ +#define NOFLAG 0 /* no special flags */ +#define FUNC 01 /* function attached */ +#define PREDEF 02 /* predefined macro */ + +#define FORMALP 0200 /* mask for creating macro formal parameter */ + +/* The macro descriptor is very simple, except the fact that the + mc_text, which points to the replacement text, contains the + non-ascii characters \201, \202, etc, indicating the position of a + formal parameter in this text. +*/ +struct macro { + struct macro *next; + char * mc_text; /* the replacement text */ + int mc_nps; /* number of formal parameters */ + int mc_length; /* length of replacement text */ + char mc_flag; /* marking this macro */ +}; + + +/* allocation definitions of struct macro */ +/* ALLOCDEF "macro" */ +extern char *st_alloc(); +extern struct macro *h_macro; +#define new_macro() ((struct macro *) \ + st_alloc((char **)&h_macro, sizeof(struct macro))) +#define free_macro(p) st_free(p, h_macro, sizeof(struct macro)) + + +/* `token' numbers of keywords of command-line processor +*/ +#define K_UNKNOWN 0 +#define K_DEFINE 1 +#define K_ELIF 2 +#define K_ELSE 3 +#define K_ENDIF 4 +#define K_IF 5 +#define K_IFDEF 6 +#define K_IFNDEF 7 +#define K_INCLUDE 8 +#define K_LINE 9 +#define K_UNDEF 10 +#endif NOPP diff --git a/lang/cem/cemcom/main.c b/lang/cem/cemcom/main.c new file mode 100644 index 00000000..ce3a88ac --- /dev/null +++ b/lang/cem/cemcom/main.c @@ -0,0 +1,382 @@ +/* $Header$ */ +/* MAIN PROGRAM */ + +#include "nopp.h" +#include "target_sizes.h" +#include "debug.h" +#include "myalloc.h" +#include "use_tmp.h" +#include "maxincl.h" +#include "system.h" +#include "inputtype.h" +#include "bufsiz.h" + +#include "input.h" +#include "level.h" +#include "idf.h" +#include "arith.h" +#include "type.h" +#include "declarator.h" +#include "tokenname.h" +#include "Lpars.h" +#include "LLlex.h" +#include "alloc.h" +#include "specials.h" + +extern struct tokenname tkidf[], tkother[]; +extern char *symbol2str(); +char options[128]; /* one for every char */ + +#ifndef NOPP +int inc_pos = 1; /* place where next -I goes */ +char *inctable[MAXINCL] = { /* list for includes */ + ".", + "/usr/include", + 0 +}; + +char **WorkingDir = &inctable[0]; +#endif NOPP + +struct sp_id special_ids[] = { + {"setjmp", SP_SETJMP}, /* non-local goto's are registered */ + {0, 0} +}; + +arith + short_size = SZ_SHORT, + word_size = SZ_WORD, + dword_size = (2 * SZ_WORD), + int_size = SZ_INT, + long_size = SZ_LONG, + float_size = SZ_FLOAT, + double_size = SZ_DOUBLE, + pointer_size = SZ_POINTER; + +int + short_align = AL_SHORT, + word_align = AL_WORD, + int_align = AL_INT, + long_align = AL_LONG, + float_align = AL_FLOAT, + double_align = AL_DOUBLE, + pointer_align = AL_POINTER, + struct_align = AL_STRUCT, + union_align = AL_UNION; + +#ifndef NOPP +arith ifval; /* ifval will contain the result of the #if expression */ +#endif NOPP + +char *prog_name; + +main(argc, argv) + char *argv[]; +{ + /* parse and interpret the command line options */ + prog_name = argv[0]; + +#ifdef OWNALLOC + init_mem(); +#endif OWNALLOC + + init_hmask(); +#ifndef NOPP + init_pp(); /* initialise the preprocessor macros */ +#endif NOPP + + /* Note: source file "-" indicates that the source is supplied + as standard input. This is only allowed if READ_IN_ONE is + not defined! + */ +#ifdef READ_IN_ONE + while (argc > 1 && *argv[1] == '-') { +#else READ_IN_ONE + while (argc > 1 && *argv[1] == '-' && argv[1][1] != '\0') { +#endif READ_IN_ONE + char *par = &argv[1][1]; + + if (*par == '-') + par++; + do_option(par); + argc--, argv++; + } + compile(argc - 1, &argv[1]); + +#ifdef OWNALLOC +#ifdef DEBUG + mem_stat(); +#endif DEBUG +#endif OWNALLOC + +#ifdef DEBUG + hash_stat(); +#endif DEBUG + + return err_occurred; +} + +char *source = 0; +char *destination = 0; + +char *nmlist = 0; + +#ifdef USE_TMP +extern char *mktemp(); /* library routine */ +static char tmpname[] = "/tmp/Cem.XXXXXX"; +char *tmpfile = 0; +#endif USE_TMP + +compile(argc, argv) + char *argv[]; +{ +#ifndef NOPP + int pp_only = options['E'] || options['P']; +#endif NOPP + + source = argv[0]; + + switch (argc) { + + case 1: +#ifndef NOPP + if (!pp_only) +#endif NOPP + fatal("%s: destination file not specified", prog_name); + break; + case 2: + destination = argv[1]; + break; + + case 3: + nmlist = argv[2]; + destination = argv[1]; + break; + default: + fatal("use: %s source destination [namelist]", prog_name); + break; + } + +#ifdef USE_TMP + tmpfile = mktemp(tmpname); +#endif USE_TMP + + if (!InsertFile(source, (char **) 0)) { + /* read the source file */ + fatal("%s: no source file %s\n", prog_name, source); + } + init(); + + /* needed ??? */ + FileName = source; + PushLex(); + +#ifndef NOPP + if (pp_only) { + /* run the preprocessor as if it is stand-alone */ + preprocess(); + } + else { +#endif NOPP + +#ifdef USE_TMP + init_code(tmpfile); +#else USE_TMP + init_code(destination); +#endif USE_TMP + + /* compile the source text */ + C_program(); + end_code(); + +#ifdef USE_TMP + prepend_scopes(destination); + AppendFile(tmpfile, destination); + sys_remove(tmpfile); +#endif USE_TMP + +#ifdef DEBUG + if (options['u']) /* unstack L_UNIVERSAL */ + unstack_level(); + if (options['f'] || options['t']) + dumpidftab("end of main", options['f'] ? 0 : 0); +#endif DEBUG +#ifndef NOPP + } +#endif NOPP + PopLex(); +} + +init() +{ + init_cst(); /* initialize variables of "cstoper.c" */ + reserve(tkidf); /* mark the C reserved words as such */ + init_specials(special_ids); /* mark special ids as such */ + + if (options['R']) + reserve(tkother); + + char_type = standard_type(CHAR, 0, 1, (arith)1); + uchar_type = standard_type(CHAR, UNSIGNED, 1, (arith)1); + + short_type = standard_type(SHORT, 0, short_align, short_size); + ushort_type = standard_type(SHORT, UNSIGNED, short_align, short_size); + + /* Treat type `word' as `int', having its own size and + alignment requirements. + This type is transparent to the user. + */ + word_type = standard_type(INT, 0, word_align, word_size); + uword_type = standard_type(INT, UNSIGNED, word_align, word_size); + + int_type = standard_type(INT, 0, int_align, int_size); + uint_type = standard_type(INT, UNSIGNED, int_align, int_size); + + long_type = standard_type(LONG, 0, long_align, long_size); + ulong_type = standard_type(LONG, UNSIGNED, long_align, long_size); + + float_type = standard_type(FLOAT, 0, float_align, float_size); + double_type = standard_type(DOUBLE, 0, double_align, double_size); + void_type = standard_type(VOID, 0, 0, (arith)0); + label_type = standard_type(LABEL, 0, 0, (arith)0); + error_type = standard_type(ERRONEOUS, 0, 1, (arith)1); + + /* Pointer Arithmetic type: all arithmetics concerning + pointers is supposed to be performed in the + pointer arithmetic type which is equal to either + int_type or long_type, depending on the pointer_size + */ + if (pointer_size == word_size) + pa_type = word_type; + else + if (pointer_size == short_size) + pa_type = short_type; + else + if (pointer_size == int_size) + pa_type = int_type; + else + if (pointer_size == long_size) + pa_type = long_type; + else + fatal("pointer size incompatible with any integral size"); + if (short_size > int_size || int_size > long_size) + fatal("sizes of short/int/long decreasing"); + + /* Build a type for function returning int, RM 13 */ + funint_type = construct_type(FUNCTION, int_type, (arith)0); + string_type = construct_type(POINTER, char_type, (arith)0); + + /* Define the standard type identifiers. */ + add_def(str2idf("char"), TYPEDEF, char_type, L_UNIVERSAL); + add_def(str2idf("int"), TYPEDEF, int_type, L_UNIVERSAL); + add_def(str2idf("float"), TYPEDEF, float_type, L_UNIVERSAL); + add_def(str2idf("double"), TYPEDEF, double_type, L_UNIVERSAL); + add_def(str2idf("void"), TYPEDEF, void_type, L_UNIVERSAL); + stack_level(); +} + +init_specials(si) + struct sp_id *si; +{ + while (si->si_identifier) { + struct idf *idf = str2idf(si->si_identifier); + + if (idf->id_special) + fatal("maximum identifier length insufficient"); + idf->id_special = si->si_flag; + si++; + } +} + +#ifndef NOPP +preprocess() +{ + /* preprocess() is the "stand-alone" preprocessor which + consecutively calls the lexical analyzer LLlex() to get + the tokens and prints them in a suitable way. + */ + static unsigned int lastlineno = 0; + static char *lastfilenm = ""; + + while (LLlex() != EOI) { + if (lastlineno != dot.tk_line) { + if (strcmp(lastfilenm, dot.tk_file) == 0) { + if (dot.tk_line - lastlineno <= 1) { + lastlineno++; + printf("\n"); + } + else { + lastlineno = dot.tk_line; + if (!options['P']) + printf("\n#line %ld \"%s\"\n", + lastlineno, lastfilenm); + } + } + else { + lastfilenm = dot.tk_file; + lastlineno = dot.tk_line; + if (!options['P']) + printf("\n#line %ld \"%s\"\n", + lastlineno, lastfilenm); + } + } + else + if (strcmp(lastfilenm, dot.tk_file) != 0) { + lastfilenm = dot.tk_file; + if (!options['P']) + printf("\n#line %ld \"%s\"\n", + lastlineno, lastfilenm); + } + + switch (DOT) { + + case IDENTIFIER: + case TYPE_IDENTIFIER: + printf(dot.tk_idf->id_text); + printf(" "); + break; + + case STRING: + printf("\"%s\" ", dot.tk_str); + break; + + case INTEGER: + printf("%ld ", dot.tk_ival); + break; + + case FLOATING: + printf("%s ", dot.tk_fval); + break; + + case EOI: + case EOF: + return; + + default: /* very expensive... */ + printf("%s ", symbol2str(DOT)); + } + } +} +#endif NOPP + +#ifdef USE_TMP +AppendFile(src, dst) + char *src, *dst; +{ + int fd_src, fd_dst; + char buf[BUFSIZ]; + int n; + + if ((fd_src = sys_open(src, OP_RDONLY)) < 0) { + fatal("cannot read %s", src); + } + if ((fd_dst = sys_open(dst, OP_APPEND)) < 0) { + fatal("cannot write to %s", src); + } + while ((n = sys_read(fd_src, buf, BUFSIZ)) > 0) { + sys_write(fd_dst, buf, n); + } + sys_close(fd_src); + sys_close(fd_dst); +} +#endif USE_TMP diff --git a/lang/cem/cemcom/make.emfun b/lang/cem/cemcom/make.emfun new file mode 100755 index 00000000..d3fe92f6 --- /dev/null +++ b/lang/cem/cemcom/make.emfun @@ -0,0 +1,19 @@ +ed - $1 <<'--EOI--' +g/^%/d +g/^ /.-1,.j +1,$s/^\([^|]*\)|\([^|]*\)|\(.*\)$/\ +\1 \2 {\ +\3;\ +}/ +1i +/* EM COMPACT CODE -- PROCEDURAL INTERFACE (generated from emcode.def) */ +#include "em.h" +#ifdef PROC_INTF +#include "label.h" +#include "arith.h" +. +$a +#endif PROC_INTF +. +1,$p +--EOI-- diff --git a/lang/cem/cemcom/make.emmac b/lang/cem/cemcom/make.emmac new file mode 100755 index 00000000..5337f40f --- /dev/null +++ b/lang/cem/cemcom/make.emmac @@ -0,0 +1,10 @@ +ed - $1 <<'--EOI--' +g/^%/d +g/^ /.-1,.j +1,$s/^\([^|]*\)|[^|]*|\(.*\)$/\ +#define \1 (\2)/ +1i +/* EM COMPACT CODE -- MACRO DEFINITIONS (generated from emcode.def) */ +. +1,$p +--EOI-- diff --git a/lang/cem/cemcom/make.hfiles b/lang/cem/cemcom/make.hfiles new file mode 100755 index 00000000..2132dd61 --- /dev/null +++ b/lang/cem/cemcom/make.hfiles @@ -0,0 +1,35 @@ +: Update Files from database + +PATH=/bin:/usr/bin + +case $# in +1) ;; +*) echo use: $0 file >&2 + exit 1 +esac + +( +IFCOMMAND="if (<\$FN) 2>/dev/null;\ + then if cmp -s \$FN \$TMP;\ + then rm \$TMP;\ + else mv \$TMP \$FN;\ + echo update \$FN;\ + fi;\ + else mv \$TMP \$FN;\ + echo create \$FN;\ + fi" +echo 'TMP=.uf$$' +echo 'FN=$TMP' +echo 'cat >$TMP <<\!EOF!' +sed -n '/^!File:/,${ +/^$/d +/^!File:[ ]*\(.*\)$/s@@!EOF!\ +'"$IFCOMMAND"'\ +FN=\1\ +cat >$TMP <<\\!EOF!@ +p +}' $1 +echo '!EOF!' +echo $IFCOMMAND +) | +sh diff --git a/lang/cem/cemcom/make.next b/lang/cem/cemcom/make.next new file mode 100755 index 00000000..be69d8d6 --- /dev/null +++ b/lang/cem/cemcom/make.next @@ -0,0 +1,3 @@ +sed -n ' +s:^.*ALLOCDEF.*"\(.*\)".*$:struct \1 *h_\1 = 0;:p +' $* diff --git a/lang/cem/cemcom/make.tokcase b/lang/cem/cemcom/make.tokcase new file mode 100755 index 00000000..ef32292f --- /dev/null +++ b/lang/cem/cemcom/make.tokcase @@ -0,0 +1,34 @@ +cat <<'--EOT--' +#include "Lpars.h" + +char * +symbol2str(tok) + int tok; +{ + static char buf[2] = { '\0', '\0' }; + + if (040 <= tok && tok < 0177) { + buf[0] = tok; + buf[1] = '\0'; + return buf; + } + switch (tok) { +--EOT-- +sed ' +/{[A-Z]/!d +s/.*{\(.*\),.*\(".*"\).*$/ case \1 :\ + return \2;/ +' +cat <<'--EOT--' + case '\n': + case '\f': + case '\v': + case '\r': + case '\t': + buf[0] = tok; + return buf; + default: + return "bad token"; + } +} +--EOT-- diff --git a/lang/cem/cemcom/make.tokfile b/lang/cem/cemcom/make.tokfile new file mode 100755 index 00000000..494b7e3c --- /dev/null +++ b/lang/cem/cemcom/make.tokfile @@ -0,0 +1,6 @@ +sed ' +/{[A-Z]/!d +s/.*{// +s/,.*// +s/.*/%token &;/ +' diff --git a/lang/cem/cemcom/mcomm.c b/lang/cem/cemcom/mcomm.c new file mode 100644 index 00000000..ea133d53 --- /dev/null +++ b/lang/cem/cemcom/mcomm.c @@ -0,0 +1,241 @@ +/* mcomm.c -- change ".lcomm name" into ".comm name" where "name" + is specified in a list. +*/ +#include + +#define IDFSIZE 4096 + +char *readfile(); + +struct node { + char *name; + struct node *left, *right; +}; + +char * +Malloc(n) + unsigned n; +{ + char *space; + char *malloc(); + + if ((space = malloc(n)) == 0) { + fprintf(stderr, "out of memory\n"); + exit(1); + } + return space; +} + +struct node *make_tree(); + +#define new_node() ((struct node *) Malloc(sizeof (struct node))) + +main(argc, argv) + char *argv[]; +{ + char *nl_file, *as_file; + char *nl_text, *as_text; + struct node *nl_tree = 0; + int nl_siz, as_siz; + + if (argc != 3) { + fprintf(stderr, "use: %s namelist assembler_file\n", argv[0]); + exit(1); + } + nl_file = argv[1]; + as_file = argv[2]; + + if ((nl_text = readfile(nl_file, &nl_siz)) == 0) { + fprintf(stderr, "%s: cannot read namelist %s\n", + argv[0], nl_file); + exit(1); + } + + if ((as_text = readfile(as_file, &as_siz)) == 0) { + fprintf(stderr, "%s: cannot read assembler file %s\n", + argv[0], as_file); + exit(1); + } + + nl_tree = make_tree(nl_text); + edit(as_text, nl_tree); + + if (writefile(as_file, as_text, as_siz) == 0) { + fprintf(stderr, "%s: cannot write to %s\n", argv[0], as_file); + exit(1); + } + return 0; +} + +#include +#include + +char * +readfile(filename, psiz) + char *filename; + int *psiz; +{ + struct stat stbuf; /* for `stat' to get filesize */ + register int fd; /* filedescriptor for `filename' */ + register char *cbuf; /* pointer to buffer to be returned */ + + if (((fd = open(filename, 0)) < 0) || (fstat(fd, &stbuf) != 0)) + return 0; + cbuf = Malloc(stbuf.st_size + 1); + if (read(fd, cbuf, stbuf.st_size) != stbuf.st_size) + return 0; + cbuf[stbuf.st_size] = '\0'; + close(fd); /* filedes no longer needed */ + *psiz = stbuf.st_size; + return cbuf; +} + +int +writefile(filename, text, size) + char *filename, *text; +{ + register fd; + + if ((fd = open(filename, 1)) < 0) + return 0; + if (write(fd, text, size) != size) + return 0; + close(fd); + return 1; +} + +struct node * +make_tree(nl) + char *nl; +{ + char *id = nl; + struct node *tree = 0; + + while (*nl) { + if (*nl == '\n') { + *nl = '\0'; + insert(&tree, id); + id = ++nl; + } + else { + ++nl; + } + } + return tree; +} + +insert(ptree, id) + struct node **ptree; + char *id; +{ + register cmp; + + if (*ptree == 0) { + register struct node *nnode = new_node(); + + nnode->name = id; + nnode->left = nnode->right = 0; + *ptree = nnode; + } + else + if ((cmp = strcmp((*ptree)->name, id)) < 0) + insert(&((*ptree)->right), id); + else + if (cmp > 0) + insert(&((*ptree)->left), id); +} + +struct node * +find(tree, id) + struct node *tree; + char *id; +{ + register cmp; + + if (tree == 0) + return 0; + if ((cmp = strcmp(tree->name, id)) < 0) + return find(tree->right, id); + if (cmp > 0) + return find(tree->left, id); + return tree; +} + +edit(text, tree) + char *text; + struct node *tree; +{ + register char *ptr = text; + char idbuf[IDFSIZE]; + register char *id; + register char *save_ptr; + + while (*ptr) { + if ( + *ptr == '.' && + *++ptr == 'l' && + *++ptr == 'c' && + *++ptr == 'o' && + *++ptr == 'm' && + *++ptr == 'm' && + (*++ptr == ' ' || *ptr == '\t') + ) + { + save_ptr = ptr - 6; + while (*++ptr == ' ' || *ptr == '\t') + ; + if (*ptr == '_') + ++ptr; + if (InId(*ptr)) { + id = &idbuf[0]; + *id++ = *ptr++; + while (InId(*ptr)) + *id++ = *ptr++; + *id = '\0'; + if (find(tree, idbuf) != 0) { + *save_ptr++ = ' '; + *save_ptr++ = '.'; + } + } + } + while (*ptr && *ptr++ != '\n') + ; + } +} + +InId(c) +{ + switch (c) { + + case 'a': case 'b': case 'c': case 'd': case 'e': + case 'f': case 'g': case 'h': case 'i': case 'j': + case 'k': case 'l': case 'm': case 'n': case 'o': + case 'p': case 'q': case 'r': case 's': case 't': + case 'u': case 'v': case 'w': case 'x': case 'y': + case 'z': + case 'A': case 'B': case 'C': case 'D': case 'E': + case 'F': case 'G': case 'H': case 'I': case 'J': + case 'K': case 'L': case 'M': case 'N': case 'O': + case 'P': case 'Q': case 'R': case 'S': case 'T': + case 'U': case 'V': case 'W': case 'X': case 'Y': + case 'Z': + case '_': + case '.': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + return 1; + + default: + return 0; + } +} + +puttree(nd) + struct node *nd; +{ + if (nd) { + puttree(nd->left); + printf("%s\n", nd->name); + puttree(nd->right); + } +} diff --git a/lang/cem/cemcom/mes.h b/lang/cem/cemcom/mes.h new file mode 100644 index 00000000..f5e3c403 --- /dev/null +++ b/lang/cem/cemcom/mes.h @@ -0,0 +1,4 @@ +/* $Header$ */ +/* MESSAGE ADMINISTRATION */ + +extern int fp_used; /* code.c */ diff --git a/lang/cem/cemcom/options b/lang/cem/cemcom/options new file mode 100644 index 00000000..378a540b --- /dev/null +++ b/lang/cem/cemcom/options @@ -0,0 +1,28 @@ +User options: + +C while running preprocessor, copy comment +D see identifier following as a macro +E run preprocessor only +I expand include table with directory name following +M set identifier length +n don't generate register messages +p generate linenumbers and filename indications + while generating compact EM code +P in running the preprocessor do not output '# line' lines +R restricted C +U undefine predefined name +V set objectsize and alignment requirements +w suppress warning diagnostics + + +Debug options: + +d perform a small dataflow analysis +f dump whole identifier table, including macros and reserved words +h supply hash table statistics +i print name of include files +m supply memory allocation statistics +r right-adjust bitfield +t dump table of identifiers +u unstack L_UNIVERSAL +x dump expressions diff --git a/lang/cem/cemcom/options.c b/lang/cem/cemcom/options.c new file mode 100644 index 00000000..a21456ea --- /dev/null +++ b/lang/cem/cemcom/options.c @@ -0,0 +1,252 @@ +/* $Header$ */ +/* U S E R O P T I O N - H A N D L I N G */ + +#include "nopp.h" +#include "idfsize.h" +#include "maxincl.h" +#include "nobitfield.h" +#include "class.h" +#include "macro.h" +#include "idf.h" +#include "arith.h" +#include "sizes.h" +#include "align.h" +#include "storage.h" + +#ifndef NOPP +extern char *inctable[MAXINCL]; +extern int inc_pos; +#endif NOPP + +extern char options[]; +extern int idfsize; + +int txt2int(); + +do_option(text) + char *text; +{ + switch(*text++) { + + default: + options[text[-1]] = 1; /* flags, debug options etc. */ + break; + + case 'C' : /* E option + comment output */ +#ifndef NOPP + options['E'] = 1; + warning("-C: comment is not output"); +#else NOPP + warning("-C option ignored"); +#endif NOPP + break; + + case 'D' : { /* -Dname : predefine name */ +#ifndef NOPP + register char *cp = text, *name, *mactext; + + if (class(*cp) != STIDF) { + error("identifier missing in -D%s", text); + break; + } + + name = cp; + + while (*cp && in_idf(*cp)) { + ++cp; + } + + if (!*cp) { /* -Dname */ + mactext = "1"; + } + else + if (*cp == '=') { /* -Dname=text */ + *cp++ = '\0'; /* end of name */ + mactext = cp; + } + else { /* -Dname?? */ + error("malformed option -D%s", text); + break; + } + + macro_def(str2idf(name), mactext, -1, strlen(mactext), + NOFLAG); +#else NOPP + warning("-D option ignored"); +#endif NOPP + break; + } + + case 'E' : /* run preprocessor only, with # */ +#ifndef NOPP + options['E'] = 1; +#else NOPP + warning("-E option ignored"); +#endif NOPP + break; + + case 'I' : /* -Ipath : insert "path" into include list */ +#ifndef NOPP + if (*text) { + register int i = inc_pos++; + register char *new = text; + + while (new) { + register char *tmp = inctable[i]; + + inctable[i++] = new; + if (i == MAXINCL) + fatal("too many -I options"); + new = tmp; + } + } +#else NOPP + warning("-I option ignored"); +#endif NOPP + break; + + case 'L' : + warning("-L: default no EM profiling; use -p for EM profiling"); + break; + + case 'M': /* maximum identifier length */ + idfsize = txt2int(&text); + if (*text || idfsize <= 0) + fatal("malformed -M option"); + if (idfsize > IDFSIZE) + fatal("maximum identifier length is %d", IDFSIZE); + break; + + case 'p' : /* generate profiling code (fil/lin) */ + options['p'] = 1; + break; + + case 'P' : /* run preprocessor stand-alone, without #'s */ +#ifndef NOPP + options['E'] = 1; + options['P'] = 1; +#else NOPP + warning("-P option ignored"); +#endif NOPP + break; + + case 'U' : { /* -Uname : undefine predefined */ +#ifndef NOPP + struct idf *idef; + + if (*text) { + if ((idef = str2idf(text))->id_macro) { + free_macro(idef->id_macro); + idef->id_macro = (struct macro *) 0; + } + } +#else NOPP + warning("-U option ignored"); +#endif NOPP + break; + } + + case 'V' : /* set object sizes and alignment requirements */ + { + arith size, align; + char c; + + while (c = *text++) { + size = txt2int(&text); + align = 0; + if (*text == '.') { + text++; + align = txt2int(&text); + } + switch (c) { + + case 's': /* short */ + if (size != (arith)0) + short_size = size; + if (align != 0) + short_align = align; + break; + case 'w': /* word */ + if (size != (arith)0) + dword_size = (word_size = size) << 1; + if (align != 0) + word_align = align; + break; + case 'i': /* int */ + if (size != (arith)0) + int_size = size; + if (align != 0) + int_align = align; + break; + case 'l': /* long */ + if (size != (arith)0) + long_size = size; + if (align != 0) + long_align = align; + break; + case 'f': /* float */ + if (size != (arith)0) + float_size = size; + if (align != 0) + float_align = align; + break; + case 'd': /* double */ + if (size != (arith)0) + double_size = size; + if (align != 0) + double_align = align; + break; + case 'p': /* pointer */ + if (size != (arith)0) + pointer_size = size; + if (align != 0) + pointer_align = align; + break; + case 'r': /* adjust bitfields right */ +#ifndef NOBITFIELD + options['r'] = 1; +#else NOBITFIELD + warning("bitfields are not implemented"); +#endif NOBITFIELD + break; + case 'S': /* initial struct alignment */ + if (size != (arith)0) + struct_align = size; + break; + case 'U': /* initial union alignment */ + if (size != (arith)0) + union_align = size; + break; + default: + error("-V: bad type indicator %c\n", c); + } + } + break; + } + + case 'n': + options['n'] = 1; /* use no registers */ + break; + + case 'w': + options['w'] = 1; /* no warnings will be given */ + break; + } +} + +int +txt2int(tp) + char **tp; +{ + /* the integer pointed to by *tp is read, while increasing + *tp; the resulting value is yielded. + */ + register int val = 0; + register int ch; + + while (ch = **tp, ch >= '0' && ch <= '9') { + val = val * 10 + ch - '0'; + (*tp)++; + } + return val; +} diff --git a/lang/cem/cemcom/program.g b/lang/cem/cemcom/program.g new file mode 100644 index 00000000..761e19db --- /dev/null +++ b/lang/cem/cemcom/program.g @@ -0,0 +1,190 @@ +/* $Header$ */ +/* PROGRAM PARSER */ + +/* The presence of typedef declarations renders it impossible to + make a context-free grammar of C. Consequently we need + context-sensitive parsing techniques, the simplest one being + a subtle cooperation between the parser and the lexical scanner. + The lexical scanner has to know whether to return IDENTIFIER + or TYPE_IDENTIFIER for a given tag, and it obtains this information + from the definition list, as constructed by the parser. + The present grammar is essentially LL(2), and is processed by + a parser generator which accepts LL(1) with tie breaking rules + in C, of the form %if(cond) and %while(cond). To solve the LL(1) + ambiguities, the lexical scanner does a one symbol look-ahead. + This symbol, however, cannot always be correctly assessed, since + the present symbol may cause a change in the definition list + which causes the identification of the look-ahead symbol to be + invalidated. + The lexical scanner relies on the parser (or its routines) to + detect this situation and then update the look-ahead symbol. + An alternative approach would be to reassess the look-ahead symbol + in the lexical scanner when it is promoted to dot symbol. This + would be more beautiful but less correct, since then for a short + while there would be a discrepancy between the look-ahead symbol + and the definition list; I think it would nevertheless work in + correct programs. + A third solution would be to enter the identifier as soon as it + is found; its storage class is then known, although its full type + isn't. We would have to fill that in afterwards. + + At block exit the situation is even worse. Upon reading the + closing brace, the names declared inside the function are cleared + from the name list. This action may expose a type identifier that + is the same as the identifier in the look-ahead symbol. This + situation certainly invalidates the third solution, and casts + doubts upon the second. +*/ + +%lexical LLlex; +%start C_program, program; +%start If_expr, control_if_expression; + +{ +#include "nopp.h" +#include "alloc.h" +#include "arith.h" +#include "LLlex.h" +#include "idf.h" +#include "label.h" +#include "type.h" +#include "declarator.h" +#include "decspecs.h" +#include "code.h" +#include "expr.h" +#include "def.h" + +#ifndef NOPP +extern arith ifval; +#endif NOPP + +/*VARARGS*/ +extern error(); +} + +control_if_expression + { + struct expr *expr; + } +: + constant_expression(&expr) + { +#ifndef NOPP + if (expr->ex_flags & EX_SIZEOF) + error("sizeof not allowed in preprocessor"); + ifval = expr->VL_VALUE; + free_expression(expr); +#endif NOPP + } +; + +/* 10 */ +program: + [%persistent external_definition]* + {unstack_world();} +; + +/* A C identifier definition is remarkable in that it formulates + the declaration in a way different from most other languages: + e.g., rather than defining x as a pointer-to-integer, it defines + *x as an integer and lets the compiler deduce that x is actually + pointer-to-integer. This has profound consequences, but for the + structure of an identifier definition and for the compiler. + + A definition starts with a decl_specifiers, which contains things + like + typedef int + which is implicitly repeated for every definition in the list, and + then for each identifier a declarator is given, of the form + *a() + or so. The decl_specifiers is kept in a struct decspecs, to be + used again and again, while the declarator is stored in a struct + declarator, only to be passed to declare_idf together with the + struct decspecs. +*/ + +external_definition + { + struct decspecs Ds; + struct declarator Dc; + } +: + { + Ds = null_decspecs; + Dc = null_declarator; + } +[ + ext_decl_specifiers(&Ds) + [ + declarator(&Dc) + {declare_idf(&Ds, &Dc, level);} + [%if (Dc.dc_idf->id_def->df_type->tp_fund == FUNCTION) + /* int i (1) {2, 3} + is a function, not an old-fashioned + initialization. + */ + function(&Dc) + | + non_function(&Ds, &Dc) + ] + | + ';' + ] + {remove_declarator(&Dc);} +| + asm_statement /* top level, would you believe */ +] +; + +ext_decl_specifiers(struct decspecs *ds;) : +[%prefer /* the thin ice in R.M. 11.1 */ + decl_specifiers(ds) +| + empty + {do_decspecs(ds);} +] +; + +non_function(struct decspecs *ds; struct declarator *dc;) + { + struct expr *expr = (struct expr *) 0; + } +: + {reject_params(dc);} + initializer(dc->dc_idf, &expr)? + { + code_declaration(dc->dc_idf, expr, level, ds->ds_sc); + free_expression(expr); + } + [ + ',' + init_declarator(ds) + ]* + ';' +; + +/* 10.1 */ +function(struct declarator *dc;) + { + arith fbytes, nbytes; + } +: + { struct idf *idf = dc->dc_idf; + + init_idf(idf); + stack_level(); /* L_FORMAL1 declarations */ + declare_params(dc); + begin_proc(idf->id_text, idf->id_def); + stack_level(); /* L_FORMAL2 declarations */ + } + declaration* + { + declare_formals(&fbytes); + } + compound_statement(&nbytes) + { + unstack_level(); /* L_FORMAL2 declarations */ + unstack_level(); /* L_FORMAL1 declarations */ + end_proc(fbytes, nbytes); + } +; diff --git a/lang/cem/cemcom/replace.c b/lang/cem/cemcom/replace.c new file mode 100644 index 00000000..24c93586 --- /dev/null +++ b/lang/cem/cemcom/replace.c @@ -0,0 +1,158 @@ +/* $Header$ */ +/* PREPROCESSOR: MACRO-TEXT REPLACEMENT ROUTINES */ + +#include "nopp.h" + +#ifndef NOPP +#include "debug.h" /* UF */ +#include "pathlength.h" /* UF */ +#include "strsize.h" /* UF */ + +#include "string.h" +#include "alloc.h" +#include "idf.h" +#include "input.h" +#include "macro.h" +#include "arith.h" +#include "LLlex.h" +#include "class.h" +#include "assert.h" +#include "interface.h" + +EXPORT int +replace(idef) + struct idf *idef; +{ + /* replace() is called by the lexical analyzer to perform + macro replacement. "idef" is the description of the + identifier which leads to the replacement. If the + optional actual parameters of the macro are OK, the text + of the macro is prepared to serve as an input buffer, + which is pushed onto the input stack. + replace() returns 1 if the replacement succeeded and 0 if + some error has occurred. + */ + register char c; + register char flags = idef->id_macro->mc_flag; + char **actpars, **getactuals(); + char *reptext, *macro2buffer(); + int size; + + if (idef->id_macro->mc_nps != -1) { /* with parameter list */ + LoadChar(c); + c = skipspaces(c); + + if (c != '(') { /* no replacement if no () */ + lexerror("(warning) macro %s needs arguments", + idef->id_text); + PushBack(); + return 0; + } + + actpars = getactuals(idef); /* get act.param. list */ + } + + if (flags & PREDEF) { /* don't replace this one... */ + return 0; + } + + if (flags & FUNC) { /* this macro leads to special action */ + macro_func(idef); + } + + /* create and input buffer */ + reptext = macro2buffer(idef, actpars, &size); + InsertText(reptext, size); + + return 1; +} + +PRIVATE +macro_func(idef) + struct idf *idef; +{ + /* macro_func() performs the special actions needed with some + macros. These macros are __FILE__ and __LINE__ which + replacement texts must be evaluated at the time they are + used. + */ + static char FilNamBuf[PATHLENGTH]; + + /* This switch is very blunt... */ + switch (idef->id_text[2]) { + + case 'F' : /* __FILE__ */ + FilNamBuf[0] = '"'; + strcpy(&FilNamBuf[1], FileName); + strcat(FilNamBuf, "\""); + idef->id_macro->mc_text = FilNamBuf; + idef->id_macro->mc_length = strlen(FilNamBuf); + break; + + case 'L' : /* __LINE__ */ + idef->id_macro->mc_text = itos(LineNumber); + idef->id_macro->mc_length = 1; + break; + + default : + crash("(macro_func) illegal macro %s\n", idef->id_text); + + } +} + +PRIVATE char * +macro2buffer(idef, actpars, siztext) + struct idf *idef; + char **actpars; + int *siztext; +{ + /* Macro2buffer() turns the macro replacement text, as it is + stored, into an input buffer, while each occurrence of the + non-ascii formal parameter mark is replaced by its + corresponding actual parameter specified in the actual + parameter list actpars. A pointer to the beginning of the + constructed text is returned, while *siztext is filled + with its length. + + If there are no parameters, this function behaves + the same as strcpy(). + */ + register int size = 8; + register char *text = Malloc(size); + register pos = 0; + register char *ptr = idef->id_macro->mc_text; + + text[pos++] = '\0'; /* allow pushback */ + + while (*ptr) { + if (*ptr & FORMALP) { /* non-asc formal param. mark */ + register int n = *ptr++ & 0177; + register char *p; + + ASSERT(n != 0); + + /* copy the text of the actual parameter + into the replacement text + */ + for (p = actpars[n - 1]; *p; p++) { + text[pos++] = *p; + + if (pos == size) { + text = Srealloc(text, size += RSTRSIZE); + } + } + } + else { + text[pos++] = *ptr++; + + if (pos == size) { + text = Srealloc(text, size += RSTRSIZE); + } + } + } + + text[pos] = '\0'; + *siztext = pos; + return text; +} +#endif NOPP diff --git a/lang/cem/cemcom/scan.c b/lang/cem/cemcom/scan.c new file mode 100644 index 00000000..c34edf4b --- /dev/null +++ b/lang/cem/cemcom/scan.c @@ -0,0 +1,224 @@ +/* $Header$ */ +/* PREPROCESSOR: SCANNER FOR THE ACTUAL PARAMETERS OF MACROS */ + +#include "nopp.h" + +#ifndef NOPP +/* This file contains the function getactuals() which scans an actual + parameter list and splits it up into a list of strings, each one + representing an actual parameter. +*/ + +#include "lapbuf.h" /* UF */ +#include "nparams.h" /* UF */ + +#include "input.h" +#include "class.h" +#include "idf.h" +#include "macro.h" +#include "interface.h" + +#define EOS '\0' +#define overflow() (fatal("actual parameter buffer overflow")) + +PRIVATE char apbuf[LAPBUF]; /* temporary storage for actual parameters */ +PRIVATE char *actparams[NPARAMS]; /* pointers to the text of the actuals */ +PRIVATE char *aptr; /* pointer to last inserted character in apbuf */ + +#define copy(ch) ((aptr < &apbuf[LAPBUF]) ? (*aptr++ = ch) : overflow()) + +PRIVATE int nr_of_params; /* number of actuals read until now */ + +PRIVATE char ** +getactuals(idef) + struct idf *idef; +{ + /* getactuals() collects the actual parameters and turns them + into a list of strings, a pointer to which is returned. + */ + register acnt = idef->id_macro->mc_nps; + + nr_of_params = 0; + actparams[0] = aptr = &apbuf[0]; + copyact('(', ')', 0); /* read the actual parameters */ + copy(EOS); /* mark the end of it all */ + + if (!nr_of_params++) { /* 0 or 1 parameter */ + /* there could be a ( ) + */ + register char *p = actparams[0]; + + while ((class(*p) == STSKIP) || (*p == '\n')) { + ++p; + } + + if (!*p) { /* the case () : 0 parameters */ + nr_of_params--; + } + } + + if (nr_of_params != acnt) { + /* argument mismatch: too many or too few + actual parameters. + */ + lexerror("argument mismatch, %s", idef->id_text); + + while (++nr_of_params < acnt) { + /* too few paraeters: remaining actuals are "" + */ + actparams[nr_of_params] = (char *) 0; + } + } + + return actparams; +} + +PRIVATE +copyact(ch1, ch2, level) + char ch1, ch2; + int level; +{ + /* copyact() is taken from Ceriel Jacobs' LLgen, with + permission. Its task is to build a list of actuals + parameters, which list is surrounded by '(' and ')' and in + which the parameters are separated by ',' if there are + more than 1. The balancing of '(',')' and '[',']' and + '{','}' is taken care of by calling this function + recursively. At each level, copyact() reads the input, + upto the corresponding closing bracket. + + Opening bracket is ch1, closing bracket is ch2. If + level != 0, copy opening and closing parameters too. + */ + register int ch; /* Current char */ + register int match; /* used to read strings */ + + if (level) { + copy(ch1); + } + + for (;;) { + LoadChar(ch); + + if (ch == ch2) { + if (level) { + copy(ch); + } + return; + } + + switch(ch) { + + case ')': + case '}': + case ']': + lexerror("unbalanced parenthesis"); + break; + + case '(': + copyact('(', ')', level+1); + break; + + case '{': + /* example: + #define declare(v, t) t v + declare(v, union{int i, j; float r;}); + */ + copyact('{', '}', level+1); + break; + + case '[': + copyact('[', ']', level+1); + break; + + case '\n': + while (LoadChar(ch), ch == '#') { + /* This piece of code needs some + explanation: consider the call of + the macro defined as: + #define sum(b,c) (b + c) + in the following form: + sum( + #include my_phone_number + ,2) + in which case the include must be + interpreted as such. + */ + domacro(); /* has read nl, vt or ff */ + /* Loop, for another control line */ + } + + PushBack(); + copy('\n'); + break; + + case '/': + LoadChar(ch); + + if (ch == '*') { /* skip comment */ + skipcomment(); + continue; + } + + PushBack(); + copy('/'); + break; + + case ',': + if (!level) { /* next parameter encountered */ + copy(EOS); + + if (++nr_of_params >= NPARAMS) { + fatal("(getact) too many actuals"); + } + + actparams[nr_of_params] = aptr; + } + else { + copy(ch); + } + break; + + case '\'': + case '"' : + /* watch out for brackets in strings, they do + not count ! + */ + match = ch; + copy(ch); + while (LoadChar(ch), ch != EOI) { + if (ch == match) { + break; + } + + if (ch == '\\') { + copy(ch); + LoadChar(ch); + } + else + if (ch == '\n') { + lexerror("newline in string"); + copy(match); + break; + } + + copy(ch); + } + + if (ch == match) { + copy(ch); + break; + } + /* Fall through */ + + case EOI : + lexerror("unterminated macro call"); + return; + + default: + copy(ch); + break; + } + } +} +#endif NOPP diff --git a/lang/cem/cemcom/sizes.h b/lang/cem/cemcom/sizes.h new file mode 100644 index 00000000..d0ae01e2 --- /dev/null +++ b/lang/cem/cemcom/sizes.h @@ -0,0 +1,8 @@ +/* $Header$ */ +/* VARIOUS TARGET MACHINE SIZE DESCRIPTORS */ + +extern arith + short_size, word_size, dword_size, int_size, long_size, + float_size, double_size, pointer_size; + +extern arith max_int, max_unsigned; /* cstoper.c */ diff --git a/lang/cem/cemcom/skip.c b/lang/cem/cemcom/skip.c new file mode 100644 index 00000000..64b8e137 --- /dev/null +++ b/lang/cem/cemcom/skip.c @@ -0,0 +1,73 @@ +/* $Header$ */ +/* PREPROCESSOR: INPUT SKIP FUNCTIONS */ + +#include "nopp.h" +#include "arith.h" +#include "LLlex.h" +#include "class.h" +#include "input.h" +#include "interface.h" + +#ifndef NOPP +PRIVATE int +skipspaces(ch) + register int ch; +{ + /* skipspaces() skips any white space and returns the first + non-space character. + */ + for (;;) { + while (class(ch) == STSKIP) + LoadChar(ch); + + /* How about "\\\n"????????? */ + + if (ch == '/') { + LoadChar(ch); + if (ch == '*') { + skipcomment(); + LoadChar(ch); + } + else { + PushBack(); + return '/'; + } + } + else + return ch; + } +} +#endif NOPP + +PRIVATE +skipline() +{ + /* skipline() skips all characters until a newline character + is seen, not escaped by a '\\'. + Any comment is skipped. + */ + register int c; + + LoadChar(c); + while (class(c) != STNL && c != EOI) { + if (c == '\\') { + LoadChar(c); + if (class(c) == STNL) + ++LineNumber; + } + if (c == '/') { + LoadChar(c); + if (c == '*') + skipcomment(); + else + continue; + } + LoadChar(c); + } + ++LineNumber; + + if (c == EOI) { /* garbage input... */ + lexerror("unexpected EOF while skipping text"); + PushBack(); + } +} diff --git a/lang/cem/cemcom/specials.h b/lang/cem/cemcom/specials.h new file mode 100644 index 00000000..33896b9a --- /dev/null +++ b/lang/cem/cemcom/specials.h @@ -0,0 +1,14 @@ +/* $Header$ */ +/* OCCURANCES OF SPECIAL IDENTIFIERS */ + +#define SP_SETJMP 1 + +#define SP_TOTAL 1 + +struct sp_id { + char *si_identifier; /* its name */ + int si_flag; /* index into sp_occurred array */ +}; + +extern char sp_occurred[]; /* idf.c */ +extern struct sp_id special_ids[]; /* main.c */ diff --git a/lang/cem/cemcom/stack.c b/lang/cem/cemcom/stack.c new file mode 100644 index 00000000..060d793c --- /dev/null +++ b/lang/cem/cemcom/stack.c @@ -0,0 +1,280 @@ +/* DERIVED FROM $Header$ */ +/* S T A C K / U N S T A C K R O U T I N E S */ + +#include "debug.h" +#include "use_tmp.h" +#include "botch_free.h" + +#include "system.h" +#include "alloc.h" +#include "Lpars.h" +#include "arith.h" +#include "stack.h" +#include "type.h" +#include "idf.h" +#include "def.h" +#include "struct.h" +#include "storage.h" +#include "level.h" +#include "mes.h" +#include "em.h" + +/* #include */ + +extern char options[]; + +static struct stack_level UniversalLevel; +struct stack_level *local_level = &UniversalLevel; +/* The main reason for having this secondary stacking + mechanism besides the linked lists pointed to by the idf's + is efficiency. + To remove the idf's of a given level, one could scan the + hash table and chase down the idf chains; with a hash + table size of 100 this is feasible, but with a size of say + 100000 this becomes painful. Therefore all idf's are also + kept in a stack of sets, one set for each level. +*/ + +int level; /* Always equal to local_level->sl_level. */ + +stack_level() { + /* A new level is added on top of the identifier stack. + */ + struct stack_level *stl = new_stack_level(); + + clear((char *)stl, sizeof(struct stack_level)); + local_level->sl_next = stl; + stl->sl_previous = local_level; + stl->sl_level = ++level; + stl->sl_local_offset = stl->sl_max_block = local_level->sl_local_offset; + local_level = stl; +} + +stack_idf(idf, stl) + struct idf *idf; + struct stack_level *stl; +{ + /* The identifier idf is inserted in the stack on level stl. + */ + register struct stack_entry *se = new_stack_entry(); + + clear((char *)se, sizeof(struct stack_entry)); + /* link it into the stack level */ + se->next = stl->sl_entry; + se->se_idf = idf; + stl->sl_entry = se; +} + +struct stack_level * +stack_level_of(lvl) +{ + /* The stack_level corresponding to level lvl is returned. + The stack should probably be an array, to be extended with + realloc where needed. + */ + if (lvl == level) + return local_level; + else { + register struct stack_level *stl = &UniversalLevel; + + while (stl->sl_level != lvl) + stl = stl->sl_next; + return stl; + } + /*NOTREACHED*/ +} + +unstack_level() +{ + /* The top level of the identifier stack is removed. + */ + struct stack_level *lastlvl; + +#ifdef DEBUG + if (options['t']) + dumpidftab("before unstackidfs", 0); +#endif DEBUG + /* The implementation below is more careful than strictly + necessary. Optimists may optimize it afterwards. + */ + while (local_level->sl_entry) { + register struct stack_entry *se = local_level->sl_entry; + register struct idf *idf = se->se_idf; + register struct def *def; + register struct sdef *sdef; + register struct tag *tag; + + /* unlink it from the local stack level */ + local_level->sl_entry = se->next; + free_stack_entry(se); + + while ((def = idf->id_def) && def->df_level >= level) { + /* unlink it from the def list under the idf block */ + if (def->df_sc == LABEL) + unstack_label(idf); + else + if (level == L_LOCAL || level == L_FORMAL1) { + if ( def->df_register != REG_NONE && + def->df_sc != STATIC && + options['n'] == 0 + ) { + int reg; + + switch (def->df_type->tp_fund) { + + case POINTER: + reg = reg_pointer; + break; + case FLOAT: + case DOUBLE: + reg = reg_float; + break; + default: + reg = reg_any; + break; + } + C_ms_reg(def->df_address, + def->df_type->tp_size, + reg, def->df_register + ); + } + } + idf->id_def = def->next; + free_def(def); + update_ahead(idf); + } + while ((sdef = idf->id_sdef) && sdef->sd_level >= level) { + /* unlink it from the sdef list under the idf block */ + idf->id_sdef = sdef->next; + free_sdef(sdef); + } + while ((tag = idf->id_struct) && tag->tg_level >= level) { + /* unlink it from the struct list under the idf block */ + idf->id_struct = tag->next; + free_tag(tag); + } + while ((tag = idf->id_enum) && tag->tg_level >= level) { + /* unlink it from the enum list under the idf block */ + idf->id_enum = tag->next; + free_tag(tag); + } + } + /* Unlink the local stack level from the stack. + */ + lastlvl = local_level; + local_level = local_level->sl_previous; + if (level > L_LOCAL && lastlvl->sl_max_block < local_level->sl_max_block) + local_level->sl_max_block = lastlvl->sl_max_block; + free_stack_level(lastlvl); + local_level->sl_next = (struct stack_level *) 0; + level = local_level->sl_level; + +#ifdef DEBUG + if (options['t']) + dumpidftab("after unstackidfs", 0); +#endif DEBUG +} + +unstack_world() +{ + /* The global level of identifiers is scanned, and final + decisions are taken about such issues as + extern/static/global and un/initialized. + Effects on the code generator: initialised variables + have already been encoded while the uninitialised ones + are not and have to be encoded at this moment. + */ + struct stack_entry *se = local_level->sl_entry; + + open_name_list(); + + while (se) { + register struct idf *idf = se->se_idf; + register struct def *def = idf->id_def; + + if (!def) { + /* global selectors, etc. */ + se = se->next; + continue; + } + +#ifdef DEBUG + if (options['a']) { + printf("\"%s\", %s, %s, %s\n", + idf->id_text, + (def->df_alloc == 0) ? "no alloc" : + (def->df_alloc == ALLOC_SEEN) ? "alloc seen" : + (def->df_alloc == ALLOC_DONE) ? "alloc done" : + "illegal alloc info", + def->df_initialized ? "init" : "no init", + def->df_used ? "used" : "not used"); + } +#endif DEBUG + /* find final storage class */ + if (def->df_sc == GLOBAL || def->df_sc == IMPLICIT) { + /* even now we still don't know */ + def->df_sc = EXTERN; + } + + if ( def->df_sc == STATIC + && def->df_type->tp_fund == FUNCTION + && !def->df_initialized + ) { + /* orphaned static function */ + if (options['R']) + warning("static function %s never defined, %s", + idf->id_text, + "changed to extern" + ); + def->df_sc = EXTERN; + } + + if ( def->df_alloc == ALLOC_SEEN && + !def->df_initialized + ) { + /* space must be allocated */ + bss(idf); + namelist(idf->id_text); /* may be common */ + def->df_alloc = ALLOC_DONE; + /* df_alloc must be set to ALLOC_DONE because + the idf entry may occur several times in + the list. + The reason is that the same name may be used + for different purposes on the same level, e.g + struct s {int s;} s; + is a legal definition and contains 3 defining + occurrences of s. Each definition has been + entered into the idfstack. Although only + one of them concerns a variable, we meet the + s 3 times when scanning the idfstack. + */ + } + se = se->next; + } +} + +/* A list of potential common names is kept, to be fed to + an understanding loader. The list is written to a file + the name of which is nmlist. If nmlist == NULL, no name + list is generated. +*/ +extern char *nmlist; /* BAH! -- main.c */ +static int nfd; + +open_name_list() +{ + if (nmlist) { + if ((nfd = sys_creat(nmlist, 0644)) < 0) { + fatal("cannot create namelist %s", nmlist); + } + } +} + +namelist(nm) + char *nm; +{ + if (nmlist) { + sys_write(nfd, nm, strlen(nm)); + sys_write(nfd, "\n", 1); + } +} diff --git a/lang/cem/cemcom/stack.h b/lang/cem/cemcom/stack.h new file mode 100644 index 00000000..27a7f312 --- /dev/null +++ b/lang/cem/cemcom/stack.h @@ -0,0 +1,46 @@ +/* $Header$ */ +/* IDENTIFIER STACK DEFINITIONS */ + +/* The identifier stack is implemented as a stack of sets. + The stack is implemented by a doubly linked list, + the sets by singly linked lists. +*/ + +struct stack_level { + struct stack_level *next; + struct stack_level *sl_next; /* upward link */ + struct stack_level *sl_previous; /* downward link */ + struct stack_entry *sl_entry; /* sideward link */ + arith sl_local_offset; /* @ for first coming object */ + arith sl_max_block; /* maximum size of sub-block */ + int sl_level; +}; + + +/* allocation definitions of struct stack_level */ +/* ALLOCDEF "stack_level" */ +extern char *st_alloc(); +extern struct stack_level *h_stack_level; +#define new_stack_level() ((struct stack_level *) \ + st_alloc((char **)&h_stack_level, sizeof(struct stack_level))) +#define free_stack_level(p) st_free(p, h_stack_level, sizeof(struct stack_level)) + + +struct stack_entry { + struct stack_entry *next; + struct idf *se_idf; +}; + + +/* allocation definitions of struct stack_entry */ +/* ALLOCDEF "stack_entry" */ +extern char *st_alloc(); +extern struct stack_entry *h_stack_entry; +#define new_stack_entry() ((struct stack_entry *) \ + st_alloc((char **)&h_stack_entry, sizeof(struct stack_entry))) +#define free_stack_entry(p) st_free(p, h_stack_entry, sizeof(struct stack_entry)) + + +extern struct stack_level *local_level; +extern struct stack_level *stack_level_of(); +extern int level; diff --git a/lang/cem/cemcom/stack.str b/lang/cem/cemcom/stack.str new file mode 100644 index 00000000..27a7f312 --- /dev/null +++ b/lang/cem/cemcom/stack.str @@ -0,0 +1,46 @@ +/* $Header$ */ +/* IDENTIFIER STACK DEFINITIONS */ + +/* The identifier stack is implemented as a stack of sets. + The stack is implemented by a doubly linked list, + the sets by singly linked lists. +*/ + +struct stack_level { + struct stack_level *next; + struct stack_level *sl_next; /* upward link */ + struct stack_level *sl_previous; /* downward link */ + struct stack_entry *sl_entry; /* sideward link */ + arith sl_local_offset; /* @ for first coming object */ + arith sl_max_block; /* maximum size of sub-block */ + int sl_level; +}; + + +/* allocation definitions of struct stack_level */ +/* ALLOCDEF "stack_level" */ +extern char *st_alloc(); +extern struct stack_level *h_stack_level; +#define new_stack_level() ((struct stack_level *) \ + st_alloc((char **)&h_stack_level, sizeof(struct stack_level))) +#define free_stack_level(p) st_free(p, h_stack_level, sizeof(struct stack_level)) + + +struct stack_entry { + struct stack_entry *next; + struct idf *se_idf; +}; + + +/* allocation definitions of struct stack_entry */ +/* ALLOCDEF "stack_entry" */ +extern char *st_alloc(); +extern struct stack_entry *h_stack_entry; +#define new_stack_entry() ((struct stack_entry *) \ + st_alloc((char **)&h_stack_entry, sizeof(struct stack_entry))) +#define free_stack_entry(p) st_free(p, h_stack_entry, sizeof(struct stack_entry)) + + +extern struct stack_level *local_level; +extern struct stack_level *stack_level_of(); +extern int level; diff --git a/lang/cem/cemcom/statement.g b/lang/cem/cemcom/statement.g new file mode 100644 index 00000000..ea5cbfb3 --- /dev/null +++ b/lang/cem/cemcom/statement.g @@ -0,0 +1,402 @@ +/* $Header$ */ +/* STATEMENT SYNTAX PARSER */ + +{ +#include "debug.h" +#include "botch_free.h" + +#include "arith.h" +#include "LLlex.h" +#include "type.h" +#include "idf.h" +#include "label.h" +#include "expr.h" +#include "code.h" +#include "storage.h" +#include "em.h" +#include "stack.h" +#include "def.h" + +extern int level; +} + +/* Each statement construction is stacked in order to trace a + statement to such a construction. Example: a case statement should + be recognized as a piece of the most enclosing switch statement. +*/ + +/* 9 */ +statement +: +[%if (AHEAD != ':') + expression_statement +| + label ':' statement +| + compound_statement((arith *)0) +| + if_statement +| + while_statement +| + do_statement +| + for_statement +| + switch_statement +| + case_statement +| + default_statement +| + break_statement +| + continue_statement +| + return_statement +| + jump +| + ';' +| + asm_statement +] +; + +expression_statement + { struct expr *expr; + } +: + expression(&expr) + ';' + { +#ifdef DEBUG + print_expr("Full expression", expr); +#endif DEBUG + code_expr(expr, RVAL, FALSE, NO_LABEL, NO_LABEL); + free_expression(expr); + } +; + +label + { struct idf *idf; + } +: + identifier(&idf) + { + /* This allows the following absurd case: + + typedef int grz; + main() { + grz: printf("A labelled statement\n"); + } + */ + define_label(idf); + C_ilb((label)idf->id_def->df_address); + } +; + +if_statement + { + struct expr *expr; + label l_true = text_label(); + label l_false = text_label(); + label l_end = text_label(); + } +: + IF + '(' + expression(&expr) + { + opnd2test(&expr, NOTEQUAL); + if (expr->ex_class != Value) { + /* What's happening here? If the + expression consisted of a constant + expression, the comparison has + been optimized to a 0 or 1. + */ + code_expr(expr, RVAL, TRUE, l_true, l_false); + C_ilb(l_true); + } + else { + if (expr->VL_VALUE == (arith)0) { + C_bra(l_false); + } + } + free_expression(expr); + } + ')' + statement + [%prefer + ELSE + { + C_bra(l_end); + C_ilb(l_false); + } + statement + { C_ilb(l_end); + } + | + empty + { C_ilb(l_false); + } + ] +; + +while_statement + { + struct expr *expr; + label l_break = text_label(); + label l_continue = text_label(); + label l_body = text_label(); + } +: + WHILE + { + stat_stack(l_break, l_continue); + C_ilb(l_continue); + } + '(' + expression(&expr) + { + opnd2test(&expr, NOTEQUAL); + if (expr->ex_class != Value) { + code_expr(expr, RVAL, TRUE, l_body, l_break); + C_ilb(l_body); + } + else { + if (expr->VL_VALUE == (arith)0) { + C_bra(l_break); + } + } + } + ')' + statement + { + C_bra(l_continue); + C_ilb(l_break); + stat_unstack(); + free_expression(expr); + } +; + +do_statement + { struct expr *expr; + label l_break = text_label(); + label l_continue = text_label(); + label l_body = text_label(); + } +: + DO + { C_ilb(l_body); + stat_stack(l_break, l_continue); + } + statement + WHILE + '(' + { C_ilb(l_continue); + } + expression(&expr) + { + opnd2test(&expr, NOTEQUAL); + if (expr->ex_class != Value) { + code_expr(expr, RVAL, TRUE, l_body, l_break); + } + else { + if (expr->VL_VALUE == (arith)1) { + C_bra(l_body); + } + } + C_ilb(l_break); + } + ')' + ';' + { + stat_unstack(); + free_expression(expr); + } +; + +for_statement + { struct expr *e_init = 0, *e_test = 0, *e_incr = 0; + label l_break = text_label(); + label l_continue = text_label(); + label l_body = text_label(); + label l_test = text_label(); + } +: + FOR + { stat_stack(l_break, l_continue); + } + '(' + [ + expression(&e_init) + { code_expr(e_init, RVAL, FALSE, NO_LABEL, NO_LABEL); + } + ]? + ';' + { C_ilb(l_test); + } + [ + expression(&e_test) + { + opnd2test(&e_test, NOTEQUAL); + if (e_test->ex_class != Value) { + code_expr(e_test, RVAL, TRUE, l_body, l_break); + C_ilb(l_body); + } + else { + if (e_test->VL_VALUE == (arith)0) { + C_bra(l_break); + } + } + } + ]? + ';' + expression(&e_incr)? + ')' + statement + { + C_ilb(l_continue); + if (e_incr) + code_expr(e_incr, RVAL, FALSE, NO_LABEL, NO_LABEL); + C_bra(l_test); + C_ilb(l_break); + stat_unstack(); + free_expression(e_init); + free_expression(e_test); + free_expression(e_incr); + } +; + +switch_statement + { + struct expr *expr; + } +: + SWITCH + '(' + expression(&expr) /* this must be an integer expression! */ + { + ch7cast(&expr, CAST, int_type); + code_startswitch(expr); + } + ')' + statement + { + code_endswitch(); + free_expression(expr); + } +; + +case_statement + { + struct expr *expr; + } +: + CASE + constant_expression(&expr) + { + code_case(expr->VL_VALUE); + free_expression(expr); + } + ':' + statement +; + +default_statement +: + DEFAULT + { + code_default(); + } + ':' + statement +; + +break_statement +: + BREAK + { + if (!do_break()) + error("invalid break"); + } + ';' +; + +continue_statement +: + CONTINUE + { + if (!do_continue()) + error("invalid continue"); + } + ';' +; + +return_statement + { struct expr *expr = 0; + } +: + RETURN + [ + expression(&expr) + { + do_return_expr(expr); + free_expression(expr); + } + | + empty + { + C_ret((arith)0); + } + ] + ';' +; + +jump + { struct idf *idf; + } +: + GOTO + identifier(&idf) + ';' + { + apply_label(idf); + C_bra((label)idf->id_def->df_address); + } +; + +compound_statement(arith *nbytes;): + '{' + { + stack_level(); + } + [%while (AHEAD != ':') /* >>> conflict on TYPE_IDENTIFIER */ + declaration + ]* + [%persistent + statement + ]* + '}' + { + if (nbytes) + *nbytes = (- local_level->sl_max_block); + unstack_level(); + } +; + +asm_statement + { char *asm_string; + } +: + ASM + '(' + STRING + { asm_string = dot.tk_str; + } + ')' + ';' + { asm_seen(asm_string); + } +; diff --git a/lang/cem/cemcom/stb.c b/lang/cem/cemcom/stb.c new file mode 100644 index 00000000..23ba9d94 --- /dev/null +++ b/lang/cem/cemcom/stb.c @@ -0,0 +1,11 @@ +/* $Header$ */ +/* library routine for copying structs */ + +__stb(n, f, t) + register char *f, *t; register n; +{ + if (n > 0) + do + *t++ = *f++; + while (--n); +} diff --git a/lang/cem/cemcom/storage.c b/lang/cem/cemcom/storage.c new file mode 100644 index 00000000..3bae164b --- /dev/null +++ b/lang/cem/cemcom/storage.c @@ -0,0 +1,67 @@ +/* $Header$ */ +/* S T R U C T U R E - S T O R A G E M A N A G E M E N T */ + +/* Assume that each structure contains a field "next", of pointer + type, as first tagfield. + struct xxx serves as a general structure: it just declares the + tagfield "next" as first field of a structure. + Please don't worry about any warnings when compiling this file + because some dirty tricks are performed to obtain the necessary + actions. +*/ + +#include "debug.h" /* UF */ +#include "botch_free.h" /* UF */ +#include "assert.h" +#include "alloc.h" +#include "storage.h" + +struct xxx { + char *next; +}; + +char * +st_alloc(phead, size) + char **phead; + int size; +{ + struct xxx *tmp; + + if (*phead == 0) { + return Malloc(size); + } + tmp = (struct xxx *) (*phead); + *phead = (char *) tmp->next; + return (char *) tmp; +} + +/* instead of Calloc: */ +clear(ptr, n) + char *ptr; + int n; +{ + ASSERT((long)ptr % sizeof (long) == 0); + while (n >= sizeof (long)) { /* high-speed clear loop */ + *(long *)ptr = 0L; + ptr += sizeof (long), n -= sizeof (long); + } + while (n--) + *ptr++ = '\0'; +} + +#ifdef BOTCH_FREE +botch(ptr, n) + char *ptr; + int n; +{ /* Writes garbage over n chars starting from ptr. + Used to check if freed memory is used inappropriately. + */ + ASSERT((long)ptr % sizeof (long) == 0); + while (n >= sizeof (long)) { /* high-speed botch loop */ + *(long *)ptr = 025252525252L; + ptr += sizeof (long), n -= sizeof (long); + } + while (n--) + *ptr++ = '\252'; +} +#endif BOTCH_FREE diff --git a/lang/cem/cemcom/storage.h b/lang/cem/cemcom/storage.h new file mode 100644 index 00000000..73b024b4 --- /dev/null +++ b/lang/cem/cemcom/storage.h @@ -0,0 +1,9 @@ +/* $Header$ */ +/* S T R U C T U R E - S T O R A G E D E F I N I T I O N S */ + +#ifndef BOTCH_FREE +#define st_free(ptr, head, size) {ptr->next = head; head = ptr;} +#else def BOTCH_FREE +#define st_free(ptr, head, size) {botch((char *)(ptr), size); \ + ptr->next = head; head = ptr;} +#endif BOTCH_FREE diff --git a/lang/cem/cemcom/string.c b/lang/cem/cemcom/string.c new file mode 100644 index 00000000..bb7ab486 --- /dev/null +++ b/lang/cem/cemcom/string.c @@ -0,0 +1,275 @@ +/* $Header$ */ +/* STRING MANIPULATION AND PRINT ROUTINES */ + +#include "string.h" +#include "nopp.h" +#include "str_params.h" +#include "arith.h" +#include "system.h" + +doprnt(fd, fmt, argp) + char *fmt; + int argp[]; +{ + char buf[SSIZE]; + + sys_write(fd, buf, format(buf, fmt, (char *)argp)); +} + +/*VARARGS1*/ +printf(fmt, args) + char *fmt; + char args; +{ + char buf[SSIZE]; + + sys_write(1, buf, format(buf, fmt, &args)); +} + +/*VARARGS1*/ +fprintf(fd, fmt, args) + char *fmt; + char args; +{ + char buf[SSIZE]; + + sys_write(fd, buf, format(buf, fmt, &args)); +} + +/*VARARGS1*/ +char * +sprintf(buf, fmt, args) + char *buf, *fmt; + char args; +{ + buf[format(buf, fmt, &args)] = '\0'; + return buf; +} + +int +format(buf, fmt, argp) + char *buf, *fmt; + char *argp; +{ + register char *pf = fmt, *pa = argp; + register char *pb = buf; + + while (*pf) { + if (*pf == '%') { + register width, base, pad, npad; + char *arg; + char cbuf[2]; + char *badformat = ""; + + /* get padder */ + if (*++pf == '0') { + pad = '0'; + ++pf; + } + else + pad = ' '; + + /* get width */ + width = 0; + while (*pf >= '0' && *pf <= '9') + width = 10 * width + *pf++ - '0'; + + /* get text and move pa */ + if (*pf == 's') { + arg = *(char **)pa; + pa += sizeof(char *); + } + else + if (*pf == 'c') { + cbuf[0] = * (char *) pa; + cbuf[1] = '\0'; + pa += sizeof(int); + arg = &cbuf[0]; + } + else + if (*pf == 'l') { + /* alignment ??? */ + if (base = integral(*++pf)) { + arg = int_str(*(long *)pa, base); + pa += sizeof(long); + } + else { + pf--; + arg = badformat; + } + } + else + if (base = integral(*pf)) { + arg = int_str((long)*(int *)pa, base); + pa += sizeof(int); + } + else + if (*pf == '%') + arg = "%"; + else + arg = badformat; + + npad = width - strlen(arg); + + while (npad-- > 0) + *pb++ = pad; + + while (*pb++ = *arg++); + pb--; + pf++; + } + else + *pb++ = *pf++; + } + return pb - buf; +} + +integral(c) +{ + switch (c) { + case 'b': + return -2; + case 'd': + return 10; + case 'o': + return -8; + case 'u': + return -10; + case 'x': + return -16; + } + return 0; +} + +/* Integer to String translator +*/ +char * +int_str(val, base) + register long val; + register base; +{ + /* int_str() is a very simple integer to string converter. + base < 0 : unsigned. + base must be an element of [-16,-2] V [2,16]. + */ + static char numbuf[MAXWIDTH]; + static char vec[] = "0123456789ABCDEF"; + register char *p = &numbuf[MAXWIDTH]; + int sign = (base > 0); + + *--p = '\0'; /* null-terminate string */ + if (val) { + if (base > 0) { + if (val < (arith)0) { + if ((val = -val) < (arith)0) + goto overflow; + } + else + sign = 0; + } + else + if (base < 0) { /* unsigned */ + base = -base; + if (val < (arith)0) { + register mod, i; + + overflow: + /* this takes a rainy Sunday afternoon to explain */ + /* ??? */ + mod = 0; + for (i = 0; i < 8 * sizeof val; i++) { + mod <<= 1; + if (val < 0) + mod++; + val <<= 1; + if (mod >= base) { + mod -= base; + val++; + } + } + *--p = vec[mod]; + } + } + + do { + *--p = vec[(int) (val % base)]; + val /= base; + } while (val != (arith)0); + + if (sign) + *--p = '-'; /* don't forget it !! */ + } + else + *--p = '0'; /* just a simple 0 */ + + return p; +} + +/* return negative, zero or positive value if + resp. s < t, s == t or s > t +*/ +int +strcmp(s, t) + register char *s, *t; +{ + while (*s == *t++) + if (*s++ == '\0') + return 0; + return *s - *--t; +} + +/* return length of s +*/ +int +strlen(s) + char *s; +{ + register char *b = s; + + while (*b++) + ; + return b - s - 1; +} + +#ifndef NOPP +/* append t to s +*/ +char * +strcat(s, t) + register char *s, *t; +{ + register char *b = s; + + while (*s++) + ; + s--; + while (*s++ = *t++) + ; + return b; +} + +/* Copy t into s +*/ +char * +strcpy(s, t) + register char *s, *t; +{ + register char *b = s; + + while (*s++ = *t++) + ; + return b; +} + +char * +rindex(str, chr) + register char *str, chr; +{ + register char *retptr = 0; + + while (*str) + if (*str++ == chr) + retptr = &str[-1]; + return retptr; +} +#endif NOPP diff --git a/lang/cem/cemcom/string.h b/lang/cem/cemcom/string.h new file mode 100644 index 00000000..ffeeb6bb --- /dev/null +++ b/lang/cem/cemcom/string.h @@ -0,0 +1,13 @@ +/* $Header$ */ +/* STRING-ROUTINE DEFINITIONS */ + +#define stdin 0 +#define stdout 1 +#define stderr 2 + +#define itos(n) int_str((long)(n), 10) + +char *sprintf(); /* string.h */ +char *int_str(); /* string.h */ + +char *strcpy(), *strcat(), *rindex(); diff --git a/lang/cem/cemcom/struct.c b/lang/cem/cemcom/struct.c new file mode 100644 index 00000000..752bcdf8 --- /dev/null +++ b/lang/cem/cemcom/struct.c @@ -0,0 +1,503 @@ +/* $Header$ */ +/* ADMINISTRATION OF STRUCT AND UNION DECLARATIONS */ + +#include "nobitfield.h" +#include "debug.h" +#include "botch_free.h" +#include "arith.h" +#include "stack.h" +#include "idf.h" +#include "def.h" +#include "type.h" +#include "struct.h" +#include "field.h" +#include "LLlex.h" +#include "Lpars.h" +#include "align.h" +#include "level.h" +#include "storage.h" +#include "assert.h" +#include "sizes.h" + +/* Type of previous selector declared with a field width specified, + if any. If a selector is declared with no field with it is set to 0. +*/ +static field_busy = 0; + +extern char options[]; +int lcm(); + +/* The semantics of the identification of structure/union tags is + obscure. Some highly regarded compilers are found out to accept, + e.g.: + f(xp) struct aap *xp; { + struct aap {char *za;}; + xp->za; + } + Equally highly regarded software uses this feature, so we shall + humbly oblige. + The rules we use are: + 1. A structure definition applies at the level where it is + found, unless there is a structure declaration without a + definition on an outer level, in which case the definition + is applied at that level. + 2. A selector is applied on the same level as on which its + structure is being defined. + + If below struct is mentioned, union is implied (and sometimes enum + as well). +*/ + +add_sel(stp, tp, idf, sdefpp, szp, fd) /* this is horrible */ + struct type *stp; /* type of the structure */ + struct type *tp; /* type of the selector */ + struct idf *idf; /* idf of the selector */ + struct sdef ***sdefpp; /* address of hook to selector definition */ + arith *szp; /* pointer to struct size upto here */ + struct field *fd; +{ + /* The selector idf with type tp is added to two chains: the + selector identification chain starting at idf->id_sdef, + and to the end of the member list starting at stp->tp_sdef. + The address of the hook in the latest member (sdef) is + given in sdefpp; the hook itself must still be empty. + */ + arith offset; +#ifndef NOBITFIELD + extern arith add_field(); +#endif NOBITFIELD + + register struct tag *tg = stp->tp_idf->id_struct; /* or union */ + register struct sdef *sdef = idf->id_sdef; + register struct sdef *newsdef; + int lvl = tg->tg_level; + +/* + * char *type2str(); + * printf("add_sel: \n stp = %s\n tp = %s\n name = %s\n *szp = %ld\n", + * type2str(stp), type2str(tp), idf->id_text, *szp); + * ASSERT(**sdefpp == 0); + * ASSERT(tg->tg_type == stp); + */ + + if (options['R'] && !is_anon_idf(idf)) { + /* a K & R test */ + if (idf->id_struct && idf->id_struct->tg_level == level + ) { + warning("%s is also a struct/union tag", + idf->id_text); + } + } + + if (stp->tp_fund == STRUCT) { +#ifndef NOBITFIELD + if (fd == 0) { /* no field width specified */ +#endif NOBITFIELD + offset = align(*szp, tp->tp_align); + field_busy = 0; +#ifndef NOBITFIELD + } + else { + /* if something is wrong, the type of the + specified selector remains unchanged; its + bitfield specifier, however, is thrown away. + */ + offset = add_field(szp, fd, &tp, idf, stp); + } +#endif NOBITFIELD + } + else { /* (stp->tp_fund == UNION) */ + if (fd) { + error("fields not allowed in unions"); + free_field(fd); + fd = 0; + } + offset = (arith)0; + } + + check_selector(idf, stp); + if (options['R']) { + if ( sdef && sdef->sd_level == lvl && + sdef->sd_offset != offset + ) /* RM 8.7 */ + warning("selector %s redeclared", idf->id_text); + } + + newsdef = new_sdef(); + newsdef->sd_sdef = (struct sdef *) 0; + + /* link into selector descriptor list of this id + */ + newsdef->next = sdef; + idf->id_sdef = newsdef; + + newsdef->sd_level = lvl; + newsdef->sd_idf = idf; + newsdef->sd_stype = stp; + newsdef->sd_type = tp; + newsdef->sd_offset = offset; + +#ifndef NOBITFIELD + if (tp->tp_fund == FIELD) { + tp->tp_field->fd_sdef = newsdef; + } +#endif NOBITFIELD + + stack_idf(idf, stack_level_of(lvl)); + + /* link into selector definition list of the struct/union + */ + **sdefpp = newsdef; + *sdefpp = &newsdef->sd_sdef; + + /* update the size of the struct/union upward */ + if (stp->tp_fund == STRUCT && fd == 0) { + /* Note: the case that a bitfield is declared is + handled by add_field() ! + */ + *szp = offset + size_of_type(tp, "member"); + stp->tp_align = lcm(stp->tp_align, tp->tp_align); + } + else + if (stp->tp_fund == UNION) { + arith sel_size = size_of_type(tp, "member"); + + if (*szp < sel_size) { + *szp = sel_size; + } + stp->tp_align = lcm(stp->tp_align, tp->tp_align); + } +} + +check_selector(idf, stp) + struct idf *idf; + struct type *stp; /* the type of the struct */ +{ + /* checks if idf occurs already as a selector in + struct or union *stp. + */ + struct sdef *sdef = stp->tp_sdef; + + while (sdef) { + if (sdef->sd_idf == idf) + error("multiple selector %s", idf->id_text); + sdef = sdef->sd_sdef; + } +} + +declare_struct(fund, idf, tpp) + struct idf *idf; + struct type **tpp; +{ + /* A struct, union or enum (depending on fund) with tag (!) + idf is declared, and its type (incomplete as it may be) is + returned in *tpp. + The idf may be missing (i.e. idf == 0), in which case an + anonymous struct etc. is defined. + */ + extern char *symbol2str(); + register struct tag **tgp; + register struct tag *tg; + + if (!idf) + idf = gen_idf(); + tgp = (fund == ENUM ? &idf->id_enum : &idf->id_struct); + + if (options['R'] && !is_anon_idf(idf)) { + /* a K & R test */ + if ( fund != ENUM && + idf->id_sdef && idf->id_sdef->sd_level == level + ) { + warning("%s is also a selector", idf->id_text); + } + if ( fund == ENUM && + idf->id_def && idf->id_def->df_level == level + ) { + warning("%s is also a variable", idf->id_text); + } + } + + tg = *tgp; + if (tg && tg->tg_type->tp_size < 0 && tg->tg_type->tp_fund == fund) { + /* An unfinished declaration has preceded it, possibly on + an earlier level. We just fill in the answer. + */ + if (tg->tg_busy) { + error("recursive declaration of struct/union %s", + idf->id_text); + declare_struct(fund, gen_idf(), tpp); + } + else { + if (options['R'] && tg->tg_level != level) + warning("%s declares %s in different range", + idf->id_text, symbol2str(fund)); + *tpp = tg->tg_type; + } + } + else + if (tg && tg->tg_level == level) { + /* There is an already defined struct/union of this name + on our level! + */ + error("redeclaration of struct/union %s", idf->id_text); + declare_struct(fund, gen_idf(), tpp); + /* to allow a second struct_declaration_pack */ + } + else { + /* The struct is new. */ + /* Hook in a new struct tag */ + tg = new_tag(); + tg->next = *tgp; + *tgp = tg; + tg->tg_level = level; + /* and supply room for a type */ + tg->tg_type = create_type(fund); + tg->tg_type->tp_align = + fund == ENUM ? int_align : + fund == STRUCT ? struct_align : + /* fund == UNION */ union_align; + tg->tg_type->tp_idf = idf; + *tpp = tg->tg_type; + stack_idf(idf, local_level); + } +} + +apply_struct(fund, idf, tpp) + struct idf *idf; + struct type **tpp; +{ + /* The occurrence of a struct, union or enum (depending on + fund) with tag idf is noted. It may or may not have been + declared before. Its type (complete or incomplete) is + returned in *tpp. + */ + register struct tag **tgp; + + tgp = (is_struct_or_union(fund) ? &idf->id_struct : &idf->id_enum); + + if (*tgp) + *tpp = (*tgp)->tg_type; + else + declare_struct(fund, idf, tpp); +} + +struct sdef * +idf2sdef(idf, tp) + struct idf *idf; + struct type *tp; +{ + /* The identifier idf is identified as a selector, preferably + in the struct tp, but we will settle for any unique + identification. + If the attempt fails, a selector of type error_type is + created. + */ + struct sdef **sdefp = &idf->id_sdef, *sdef; + + /* Follow chain from idf, to meet tp. */ + while ((sdef = *sdefp)) { + if (sdef->sd_stype == tp) + return sdef; + sdefp = &(*sdefp)->next; + } + + /* Tp not met; any unique identification will do. */ + if (sdef = idf->id_sdef) { + /* There is an identification */ + if (uniq_selector(sdef)) { + /* and it is unique, so we accept */ + warning("selector %s applied to alien type", + idf->id_text); + } + else { + /* it is ambiguous */ + error("ambiguous use of selector %s", idf->id_text); + } + return sdef; + } + + /* No luck; create an error entry. */ + if (!is_anon_idf(idf)) + error("unknown selector %s", idf->id_text); + *sdefp = sdef = new_sdef(); + clear((char *)sdef, sizeof(struct sdef)); + sdef->sd_idf = idf; + sdef->sd_type = error_type; + return sdef; +} + +int +uniq_selector(idf_sdef) + struct sdef *idf_sdef; +{ + /* Returns true if idf_sdef (which is guaranteed to exist) + is unique for this level, i.e there is no other selector + on this level with the same name or the other selectors + with the same name have the same offset. + See /usr/src/cmd/sed/sed.h for an example of this absurd + case! + */ + + struct sdef *sdef = idf_sdef->next; + + while (sdef && sdef->sd_level == idf_sdef->sd_level) { + if ( sdef->sd_type != idf_sdef->sd_type + || sdef->sd_offset != idf_sdef->sd_offset + ) { + return 0; /* ambiguity found */ + } + sdef = sdef->next; + } + return 1; +} + +#ifndef NOBITFIELD +arith +add_field(szp, fd, pfd_type, idf, stp) + arith *szp; /* size of struct upto here */ + struct field *fd; /* bitfield, containing width */ + struct type **pfd_type; /* type of selector */ + struct idf *idf; /* name of selector */ + struct type *stp; /* current struct descriptor */ +{ + /* The address where this selector is put is returned. If the + selector with specified width does not fit in the word, or + an explicit alignment is given, a new address is needed. + Note that the fields are packed into machine words (according + to the RM.) + */ + long bits_in_type = word_size * 8; + static int field_offset = (arith)0; + static struct type *current_struct = 0; + static long bits_declared; /* nr of bits used in *field_offset */ + + if (current_struct != stp) { + /* This struct differs from the last one + */ + field_busy = 0; + current_struct = stp; + } + + if ( fd->fd_width < 0 || + (fd->fd_width == 0 && !is_anon_idf(idf)) || + fd->fd_width > bits_in_type + ) { + error("illegal field-width specified"); + *pfd_type = error_type; + return field_offset; + } + + switch ((*pfd_type)->tp_fund) { + + case CHAR: + case SHORT: + case INT: + case ENUM: + case LONG: + /* right type; size OK? */ + if ((*pfd_type)->tp_size > word_size) { + error("bit field type %s doesn't fit in word", + symbol2str((*pfd_type)->tp_fund)); + *pfd_type = error_type; + return field_offset; + } + break; + + default: + /* wrong type altogether */ + error("illegal field type (%s)", + symbol2str((*pfd_type)->tp_fund)); + *pfd_type = error_type; + return field_offset; + } + + if (field_busy == 0) { + /* align this selector on the next boundary : + the previous selector wasn't a bitfield. + */ + field_offset = align(*szp, word_align); + *szp = field_offset + word_size; + stp->tp_align = lcm(stp->tp_align, word_align); + bits_declared = (arith)0; + field_busy = 1; + } + + if (fd->fd_width > bits_in_type - bits_declared) { + /* field overflow: fetch next memory unit + */ + field_offset = align(*szp, word_align); + *szp = field_offset + word_size; + stp->tp_align = lcm(stp->tp_align, word_align); + bits_declared = fd->fd_width; + } + else + if (fd->fd_width == 0) { + /* next field should be aligned on the next boundary. + This will take care that no field will fit in the + space allocated upto here. + */ + bits_declared = bits_in_type + 1; + } + else { /* the bitfield fits in the current field */ + bits_declared += fd->fd_width; + } + + /* Arrived here, the place where the selector is stored in the + struct is computed. + Now we need a mask to use its value in expressions. + */ + + *pfd_type = construct_type(FIELD, *pfd_type, (arith)0); + (*pfd_type)->tp_field = fd; + + /* Set the mask right shifted. This solution avoids the + problem of having sign extension when using the mask for + extracting the value from the field-int. + Sign extension could occur on some machines when shifting + the mask to the left. + */ + fd->fd_mask = (1 << fd->fd_width) - 1; + + if (options['r']) { /* adjust the field at the right */ + fd->fd_shift = bits_declared - fd->fd_width; + } + else { /* adjust the field at the left */ + fd->fd_shift = bits_in_type - bits_declared; + } + + return field_offset; +} +#endif NOBITFIELD + +/* some utilities */ +int +is_struct_or_union(fund) + register int fund; +{ + return fund == STRUCT || fund == UNION; +} + +/* Greatest Common Divisor + */ +int +gcd(m, n) + register int m, n; +{ + register int r; + + while (n) { + r = m % n; + m = n; + n = r; + } + return m; +} + +/* Least Common Multiple + */ +int +lcm(m, n) + register int m, n; +{ + return m * (n / gcd(m, n)); +} diff --git a/lang/cem/cemcom/struct.h b/lang/cem/cemcom/struct.h new file mode 100644 index 00000000..8caab678 --- /dev/null +++ b/lang/cem/cemcom/struct.h @@ -0,0 +1,44 @@ +/* $Header$ */ +/* SELECTOR DESCRIPTOR */ + +struct sdef { /* for selectors */ + struct sdef *next; + int sd_level; + struct idf *sd_idf; /* its name */ + struct sdef *sd_sdef; /* the next selector */ + struct type *sd_stype; /* the struct it belongs to */ + struct type *sd_type; /* its type */ + arith sd_offset; +}; + +extern char *st_alloc(); + + +/* allocation definitions of struct sdef */ +/* ALLOCDEF "sdef" */ +extern char *st_alloc(); +extern struct sdef *h_sdef; +#define new_sdef() ((struct sdef *) \ + st_alloc((char **)&h_sdef, sizeof(struct sdef))) +#define free_sdef(p) st_free(p, h_sdef, sizeof(struct sdef)) + + +struct tag { /* for struct-, union- and enum tags */ + struct tag *next; + int tg_level; + int tg_busy; /* non-zero during declaration of struct/union pack */ + struct type *tg_type; +}; + + + +/* allocation definitions of struct tag */ +/* ALLOCDEF "tag" */ +extern char *st_alloc(); +extern struct tag *h_tag; +#define new_tag() ((struct tag *) \ + st_alloc((char **)&h_tag, sizeof(struct tag))) +#define free_tag(p) st_free(p, h_tag, sizeof(struct tag)) + + +struct sdef *idf2sdef(); diff --git a/lang/cem/cemcom/struct.str b/lang/cem/cemcom/struct.str new file mode 100644 index 00000000..8caab678 --- /dev/null +++ b/lang/cem/cemcom/struct.str @@ -0,0 +1,44 @@ +/* $Header$ */ +/* SELECTOR DESCRIPTOR */ + +struct sdef { /* for selectors */ + struct sdef *next; + int sd_level; + struct idf *sd_idf; /* its name */ + struct sdef *sd_sdef; /* the next selector */ + struct type *sd_stype; /* the struct it belongs to */ + struct type *sd_type; /* its type */ + arith sd_offset; +}; + +extern char *st_alloc(); + + +/* allocation definitions of struct sdef */ +/* ALLOCDEF "sdef" */ +extern char *st_alloc(); +extern struct sdef *h_sdef; +#define new_sdef() ((struct sdef *) \ + st_alloc((char **)&h_sdef, sizeof(struct sdef))) +#define free_sdef(p) st_free(p, h_sdef, sizeof(struct sdef)) + + +struct tag { /* for struct-, union- and enum tags */ + struct tag *next; + int tg_level; + int tg_busy; /* non-zero during declaration of struct/union pack */ + struct type *tg_type; +}; + + + +/* allocation definitions of struct tag */ +/* ALLOCDEF "tag" */ +extern char *st_alloc(); +extern struct tag *h_tag; +#define new_tag() ((struct tag *) \ + st_alloc((char **)&h_tag, sizeof(struct tag))) +#define free_tag(p) st_free(p, h_tag, sizeof(struct tag)) + + +struct sdef *idf2sdef(); diff --git a/lang/cem/cemcom/switch.c b/lang/cem/cemcom/switch.c new file mode 100644 index 00000000..4ce1c181 --- /dev/null +++ b/lang/cem/cemcom/switch.c @@ -0,0 +1,184 @@ +/* $Header$ */ +/* S W I T C H - S T A T E M E N T A D M I N I S T R A T I O N */ + +#include "debug.h" +#include "botch_free.h" +#include "density.h" + +#include "idf.h" +#include "label.h" +#include "arith.h" +#include "switch.h" +#include "code.h" +#include "storage.h" +#include "assert.h" +#include "expr.h" +#include "type.h" +#include "em.h" + +#define compact(nr, low, up) (nr != 0 && (up - low) / nr <= (DENSITY - 1)) + +static struct switch_hdr *switch_stack = 0; + +code_startswitch(expr) + struct expr *expr; +{ + /* stack a new case header and fill in the necessary fields. + */ + register label l_table = text_label(); + register label l_break = text_label(); + register struct switch_hdr *sh = new_switch_hdr(); + + stat_stack(l_break, NO_LABEL); + sh->sh_break = l_break; + sh->sh_default = 0; + sh->sh_table = l_table; + sh->sh_nrofentries = 0; + sh->sh_type = expr->ex_type; /* the expression switched */ + sh->sh_lowerbd = sh->sh_upperbd = (arith)0; /* ??? */ + sh->sh_entries = (struct case_entry *) 0; /* case-entry list */ + sh->next = switch_stack; /* push onto switch-stack */ + switch_stack = sh; + code_expr(expr, RVAL, TRUE, NO_LABEL, NO_LABEL); + /* evaluate the switch expr. */ + C_bra(l_table); /* goto start of switch_table */ +} + +code_endswitch() +{ + register struct switch_hdr *sh = switch_stack; + register label tablabel; + register struct case_entry *ce, *tmp; + + if (sh->sh_default == 0) /* no default occurred yet */ + sh->sh_default = sh->sh_break; + C_bra(sh->sh_break); /* skip the switch table now */ + C_ilb(sh->sh_table); /* switch table entry */ + tablabel = data_label(); /* the rom must have a label */ + C_ndlb(tablabel); + C_rom_begin(); + C_co_ilb(sh->sh_default); + if (compact(sh->sh_nrofentries, sh->sh_lowerbd, sh->sh_upperbd)) { + /* CSA */ + register arith val; + + C_co_cst(sh->sh_lowerbd); + C_co_cst(sh->sh_upperbd - sh->sh_lowerbd); + ce = sh->sh_entries; + for (val = sh->sh_lowerbd; val <= sh->sh_upperbd; val++) { + ASSERT(ce); + if (val == ce->ce_value) { + C_co_ilb(ce->ce_label); + ce = ce->next; + } + else + C_co_ilb(sh->sh_default); + } + C_rom_end(); + C_lae_ndlb(tablabel, (arith)0); /* perform the switch */ + C_csa(sh->sh_type->tp_size); + } + else { /* CSB */ + C_co_cst((arith)sh->sh_nrofentries); + for (ce = sh->sh_entries; ce; ce = ce->next) { + /* generate the entries: value + prog.label */ + C_co_cst(ce->ce_value); + C_co_ilb(ce->ce_label); + } + C_rom_end(); + C_lae_ndlb(tablabel, (arith)0); /* perform the switch */ + C_csb(sh->sh_type->tp_size); + } + C_ilb(sh->sh_break); + switch_stack = sh->next; /* unstack the switch descriptor */ + /* free the allocated switch structure */ + for (ce = sh->sh_entries; ce; ce = tmp) { + tmp = ce->next; + free_case_entry(ce); + } + free_switch_hdr(sh); + stat_unstack(); +} + +code_case(val) + arith val; +{ + register struct case_entry *ce; + register struct switch_hdr *sh = switch_stack; + + if (sh == 0) { + error("case statement not in switch"); + return; + } + ce = new_case_entry(); + C_ilb(ce->ce_label = text_label()); + ce->ce_value = val; + if (sh->sh_entries == 0) { + /* first case entry */ + ce->next = (struct case_entry *) 0; + sh->sh_entries = ce; + sh->sh_lowerbd = sh->sh_upperbd = ce->ce_value; + sh->sh_nrofentries = 1; + } + else { + /* second etc. case entry */ + /* find the proper place to put ce into the list */ + register struct case_entry *c1 = sh->sh_entries, *c2 = 0; + + if (val < sh->sh_lowerbd) + sh->sh_lowerbd = val; + else + if (val > sh->sh_upperbd) + sh->sh_upperbd = val; + while (c1 && c1->ce_value < ce->ce_value) { + c2 = c1; + c1 = c1->next; + } + /* At this point three cases are possible: + 1: c1 != 0 && c2 != 0: + insert ce somewhere in the middle + 2: c1 != 0 && c2 == 0: + insert ce right after the head + 3: c1 == 0 && c2 != 0: + append ce to last element + The case c1 == 0 && c2 == 0 cannot occur! + */ + if (c1) { + if (c1->ce_value == ce->ce_value) { + error("multiple case entry for value %ld", + ce->ce_value); + free_case_entry(ce); + return; + } + if (c2) { + ce->next = c2->next; + c2->next = ce; + } + else { + ce->next = sh->sh_entries; + sh->sh_entries = ce; + } + } + else { + ASSERT(c2); + ce->next = (struct case_entry *) 0; + c2->next = ce; + } + (sh->sh_nrofentries)++; + } +} + +code_default() +{ + register struct switch_hdr *sh = switch_stack; + + if (sh == 0) { + error("default not in switch"); + return; + } + if (sh->sh_default != 0) { + error("multiple entry for default in switch"); + return; + } + C_ilb(sh->sh_default = text_label()); +} diff --git a/lang/cem/cemcom/switch.h b/lang/cem/cemcom/switch.h new file mode 100644 index 00000000..07998b9e --- /dev/null +++ b/lang/cem/cemcom/switch.h @@ -0,0 +1,40 @@ +/* $Header$ */ +/* S W I T C H - T A B L E - S T R U C T U R E */ + +struct switch_hdr { + struct switch_hdr *next; + label sh_break; + label sh_default; + label sh_table; + int sh_nrofentries; + struct type *sh_type; + arith sh_lowerbd; + arith sh_upperbd; + struct case_entry *sh_entries; +}; + + +/* allocation definitions of struct switch_hdr */ +/* ALLOCDEF "switch_hdr" */ +extern char *st_alloc(); +extern struct switch_hdr *h_switch_hdr; +#define new_switch_hdr() ((struct switch_hdr *) \ + st_alloc((char **)&h_switch_hdr, sizeof(struct switch_hdr))) +#define free_switch_hdr(p) st_free(p, h_switch_hdr, sizeof(struct switch_hdr)) + + +struct case_entry { + struct case_entry *next; + label ce_label; + arith ce_value; +}; + + +/* allocation definitions of struct case_entry */ +/* ALLOCDEF "case_entry" */ +extern char *st_alloc(); +extern struct case_entry *h_case_entry; +#define new_case_entry() ((struct case_entry *) \ + st_alloc((char **)&h_case_entry, sizeof(struct case_entry))) +#define free_case_entry(p) st_free(p, h_case_entry, sizeof(struct case_entry)) + diff --git a/lang/cem/cemcom/switch.str b/lang/cem/cemcom/switch.str new file mode 100644 index 00000000..07998b9e --- /dev/null +++ b/lang/cem/cemcom/switch.str @@ -0,0 +1,40 @@ +/* $Header$ */ +/* S W I T C H - T A B L E - S T R U C T U R E */ + +struct switch_hdr { + struct switch_hdr *next; + label sh_break; + label sh_default; + label sh_table; + int sh_nrofentries; + struct type *sh_type; + arith sh_lowerbd; + arith sh_upperbd; + struct case_entry *sh_entries; +}; + + +/* allocation definitions of struct switch_hdr */ +/* ALLOCDEF "switch_hdr" */ +extern char *st_alloc(); +extern struct switch_hdr *h_switch_hdr; +#define new_switch_hdr() ((struct switch_hdr *) \ + st_alloc((char **)&h_switch_hdr, sizeof(struct switch_hdr))) +#define free_switch_hdr(p) st_free(p, h_switch_hdr, sizeof(struct switch_hdr)) + + +struct case_entry { + struct case_entry *next; + label ce_label; + arith ce_value; +}; + + +/* allocation definitions of struct case_entry */ +/* ALLOCDEF "case_entry" */ +extern char *st_alloc(); +extern struct case_entry *h_case_entry; +#define new_case_entry() ((struct case_entry *) \ + st_alloc((char **)&h_case_entry, sizeof(struct case_entry))) +#define free_case_entry(p) st_free(p, h_case_entry, sizeof(struct case_entry)) + diff --git a/lang/cem/cemcom/system.c b/lang/cem/cemcom/system.c new file mode 100644 index 00000000..dd80863b --- /dev/null +++ b/lang/cem/cemcom/system.c @@ -0,0 +1,72 @@ +/* $Header$ */ +/* SYSTEM DEPENDENT ROUTINES */ + +#include "system.h" +#include "inputtype.h" +#include + +extern long lseek(); + +int +xopen(name, flag, mode) + char *name; +{ + if (name[0] == '-' && name[1] == '\0') + return (flag == OP_RDONLY) ? 0 : 1; + + switch (flag) { + + case OP_RDONLY: + return open(name, 0); + case OP_WRONLY: + return open(name, 1); + case OP_CREAT: + return creat(name, mode); + case OP_APPEND: + { + register fd; + + if ((fd = open(name, 1)) < 0) + return -1; + lseek(fd, 0L, 2); + return fd; + } + } + /*NOTREACHED*/ +} + +int +xclose(fildes) +{ + if (fildes != 0 && fildes != 1) + return close(fildes); + return -1; +} + +#ifdef READ_IN_ONE +long +xfsize(fildes) +{ + struct stat stbuf; + + if (fstat(fildes, &stbuf) != 0) + return -1; + return stbuf.st_size; +} +#endif READ_IN_ONE + +exit(n) +{ + _exit(n); +} + +xstop(how, stat) +{ + switch (how) { + case S_ABORT: + abort(); + case S_EXIT: + exit(stat); + } + /*NOTREACHED*/ +} diff --git a/lang/cem/cemcom/system.h b/lang/cem/cemcom/system.h new file mode 100644 index 00000000..ae69ff8c --- /dev/null +++ b/lang/cem/cemcom/system.h @@ -0,0 +1,34 @@ +/* $Header$ */ +/* SYSTEM DEPENDANT DEFINITIONS */ + +#include +#include + +#define OP_RDONLY 0 /* open for read */ +#define OP_WRONLY 1 /* open for write */ +#define OP_CREAT 2 /* create and open for write */ +#define OP_APPEND 3 /* open for write at end */ + +#define sys_open(name, flag) xopen(name, flag, 0) +#define sys_close(fildes) xclose(fildes) +#define sys_read(fildes, buffer, nbytes) read(fildes, buffer, nbytes) +#define sys_write(fildes, buffer, nbytes) write(fildes, buffer, nbytes) +#define sys_creat(name, mode) xopen(name, OP_CREAT, mode) +#define sys_remove(name) unlink(name) +#define sys_fsize(fd) xfsize(fd) +#define sys_sbrk(incr) sbrk(incr) +#define sys_stop(how, stat) xstop(how, stat) + +#define S_ABORT 1 +#define S_EXIT 2 + +char *sbrk(); +long xfsize(); + +extern int errno; + +#define sys_errno errno + +#define time_type time_t +#define sys_time(tloc) time(tloc) +time_type time(); diff --git a/lang/cem/cemcom/tab.c b/lang/cem/cemcom/tab.c new file mode 100644 index 00000000..8e39d7af --- /dev/null +++ b/lang/cem/cemcom/tab.c @@ -0,0 +1,295 @@ +/* $Header$ */ +/* @cc tab.c -o $INSTALLDIR/tab@ + tab - table generator + + Author: Erik Baalbergen (..tjalk!erikb) +*/ + +#include + +#define MAXTAB 10000 +#define MAXBUF 10000 +#define COMCOM '-' +#define FILECOM '%' + +int InputForm = 'c'; +char OutputForm[MAXBUF] = "%s,\n"; +int TabSize = 257; +char *Table[MAXTAB]; +char *ProgCall; + +main(argc, argv) + char *argv[]; +{ + ProgCall = *argv++; + argc--; + while (argc-- > 0) { + if (**argv == COMCOM) { + option(*argv++); + } + else { + process(*argv++, InputForm); + } + } +} + +char * +Salloc(s) + char *s; +{ + extern char *malloc(), *strcpy(); + char *ns = malloc((unsigned int)strlen(s) + 1); + + if (ns) { + strcpy(ns, s); + } + return ns; +} + +option(str) + char *str; +{ + /* note that *str indicates the source of the option: + either COMCOM (from command line) or FILECOM (from a file). + */ + extern char *sprintf(); + + switch (*++str) { + + case ' ': /* command */ + case '\t': + case '\0': + break; + case 'I': + InputForm = *++str; + break; + case 'f': + if (*++str == '\0') { + fprintf(stderr, "%s: -f: name expected\n", ProgCall); + exit(1); + } + DoFile(str); + break; + case 'F': + sprintf(OutputForm, "%s\n", ++str); + break; + case 'T': + printf("%s\n", ++str); + break; + case 'p': + PrintTable(); + break; + case 'C': + ClearTable(); + break; + case 'S': + { + register i = stoi(++str); + + if (i <= 0 || i > MAXTAB) { + fprintf(stderr, "%s: size would exceed maximum\n", + ProgCall); + } + else { + TabSize = i; + } + break; + } + default: + fprintf(stderr, "%s: bad option -%s\n", ProgCall, str); + } +} + +ClearTable() +{ + register i; + + for (i = 0; i < MAXTAB; i++) { + Table[i] = 0; + } +} + +PrintTable() +{ + register i; + + for (i = 0; i < TabSize; i++) { + if (Table[i]) { + printf(OutputForm, Table[i]); + } + else { + printf(OutputForm, "0"); + } + } +} + +process(str, format) + char *str; +{ + char *cstr = str; + char *Name = cstr; /* overwrite original string! */ + + /* strip of the entry name + */ + while (*str && *str != ':') { + if (*str == '\\') { + ++str; + } + *cstr++ = *str++; + } + + if (*str != ':') { + fprintf(stderr, "%s: bad specification: \"%s\", ignored\n", + ProgCall, Name); + return 0; + } + *cstr = '\0'; + str++; + + switch (format) { + + case 'c': + return c_proc(str, Name); + default: + fprintf(stderr, "%s: bad input format\n", ProgCall); + } + return 0; +} + +c_proc(str, Name) + char *str; + char *Name; +{ + int ch, ch2; + int quoted(); + + while (*str) { + if (*str == '\\') { + ch = quoted(&str); + } + else { + ch = *str++; + } + if (*str == '-') { + if (*++str == '\\') { + ch2 = quoted(&str); + } + else { + if (ch2 = *str++); + else str--; + } + if (ch > ch2) { + fprintf(stderr, "%s: bad range\n", ProgCall); + return 0; + } + if (ch >= 0 && ch2 <= 255) + while (ch <= ch2) + Table[ch++] = Salloc(Name); + } + else { + if (ch >= 0 && ch <= 255) + Table[ch] = Salloc(Name); + } + } + return 1; +} + +int +quoted(pstr) + char **pstr; +{ + register int ch; + register int i; + register char *str = *pstr; + + if ((*++str >= '0') && (*str <= '9')) { + ch = 0; + for (i = 0; i < 3; i++) { + ch = 8 * ch + *str - '0'; + if (*++str < '0' || *str > '9') + break; + } + } + else { + switch (*str++) { + + case 'n': + ch = '\n'; + break; + case 't': + ch = '\t'; + break; + case 'b': + ch = '\b'; + break; + case 'r': + ch = '\r'; + break; + case 'f': + ch = '\f'; + break; + default : + ch = *str; + } + } + *pstr = str; + return ch & 0377; +} + +int +stoi(str) + char *str; +{ + register i = 0; + + while (*str >= '0' && *str <= '9') { + i = i * 10 + *str++ - '0'; + } + return i; +} + +char * +getline(s, n, fp) + char *s; + FILE *fp; +{ + register c = getc(fp); + char *str = s; + + while (n--) { + if (c == EOF) { + return NULL; + } + else + if (c == '\n') { + *str++ = '\0'; + return s; + } + *str++ = c; + c = getc(fp); + } + s[n - 1] = '\0'; + return s; +} + +#define BUFSIZE 1024 + +DoFile(name) + char *name; +{ + char text[BUFSIZE]; + FILE *fp; + + if ((fp = fopen(name, "r")) == NULL) { + fprintf(stderr, "%s: cannot read file %s\n", ProgCall, name); + exit(1); + } + while (getline(text, BUFSIZE, fp) != NULL) { + if (text[0] == FILECOM) { + option(text); + } + else { + process(text, InputForm); + } + } +} diff --git a/lang/cem/cemcom/tokenname.c b/lang/cem/cemcom/tokenname.c new file mode 100644 index 00000000..d66ff723 --- /dev/null +++ b/lang/cem/cemcom/tokenname.c @@ -0,0 +1,143 @@ +/* $Header$ */ +/* TOKEN NAME DEFINITIONS */ + +#include "idf.h" +#include "arith.h" +#include "LLlex.h" +#include "tokenname.h" +#include "Lpars.h" + +/* To centralize the declaration of %tokens, their presence in this + file is taken as their declaration. The Makefile will produce + a grammar file (tokenfile.g) from this file. + Moreover, rather than looking up a symbol in all these lists + to find its printable name, a fast version of symbol2str() is + generated from these tables. + Consequenty some of these tables are not referenced explicitly + in the C text any more. To save space and to avoid lint confusion, + these have been made pseudo-invisible by #ifdefs. +*/ + +#ifdef ____ +struct tokenname tkspec[] = { /* the names of the special tokens */ + {IDENTIFIER, "identifier"}, + {TYPE_IDENTIFIER, "type_identifier"}, + {STRING, "string"}, + {FILESPECIFIER, "filespecifier"}, + {INTEGER, "integer"}, + {FLOATING, "floating"}, + {0, ""} +}; +#endif ____ + +#ifdef ____ +struct tokenname tkcomp[] = { /* names of the composite tokens */ + {NOTEQUAL, "!="}, + {AND, "&&"}, + {PLUSPLUS, "++"}, + {MINMIN, "--"}, + {ARROW, "->"}, + {LEFT, "<<"}, + {LESSEQ, "<="}, + {EQUAL, "=="}, + {GREATEREQ, ">="}, + {RIGHT, ">>"}, + {OR, "||"}, + {0, ""} +}; +#endif ____ + +struct tokenname tkidf[] = { /* names of the identifier tokens */ + {ASM, "asm"}, + {AUTO, "auto"}, + {BREAK, "break"}, + {CASE, "case"}, + {CONTINUE, "continue"}, + {DEFAULT, "default"}, + {DO, "do"}, + {ELSE, "else"}, + {ENUM, "enum"}, + {EXTERN, "extern"}, + {FOR, "for"}, + {GOTO, "goto"}, + {IF, "if"}, + {LONG, "long"}, + {REGISTER, "register"}, + {RETURN, "return"}, + {SHORT, "short"}, + {SIZEOF, "sizeof"}, + {STATIC, "static"}, + {STRUCT, "struct"}, + {SWITCH, "switch"}, + {TYPEDEF, "typedef"}, + {UNION, "union"}, + {UNSIGNED, "unsigned"}, + {WHILE, "while"}, + {0, ""} +}; + +struct tokenname tkother[] = { /* additional keywords from the RM */ + {ENTRY, "entry"}, + {FORTRAN, "fortran"}, + {0, ""} +}; + +#ifdef ____ +struct tokenname tkfunny[] = { /* internal keywords */ + {CHAR, "char"}, + {INT, "int"}, + {FLOAT, "float"}, + {DOUBLE, "double"}, + {VOID, "void"}, + + {ARRAY, "array"}, + {FUNCTION, "function"}, + {POINTER, "pointer"}, + {FIELD, "field"}, + {NEWLINE, "newline"}, + + {GLOBAL, "global"}, + {IMPLICIT, "implicit"}, + {FORMAL, "formal"}, + {LABEL, "label"}, + {ERRONEOUS, "erroneous"}, + + {PARCOMMA, "parcomma"}, + {INITCOMMA, "initcomma"}, + {CAST, "cast"}, + {POSTINCR, "postfix ++"}, + {POSTDECR, "postfix --"}, + {PLUSAB, "+="}, + {MINAB, "-="}, + {TIMESAB, "*="}, + {DIVAB, "/="}, + {MODAB, "%="}, + {LEFTAB, "<<="}, + {RIGHTAB, ">>="}, + {ANDAB, "&="}, + {XORAB, "^="}, + {ORAB, "|="}, + + {INT2INT, "int2int"}, + {INT2FLOAT, "int2float"}, + {FLOAT2INT, "float2int"}, + {FLOAT2FLOAT, "float2float"}, + {0, ""} +}; +#endif ____ + +reserve(resv) + register struct tokenname resv[]; +{ + /* The names of the tokens described in resv are entered + as reserved words. + */ + while (resv->tn_symbol) { + struct idf *idf = str2idf(resv->tn_name); + + if (idf->id_reserved) + fatal("maximum identifier length insufficient"); + idf->id_reserved = resv->tn_symbol; + resv++; + } +} diff --git a/lang/cem/cemcom/tokenname.h b/lang/cem/cemcom/tokenname.h new file mode 100644 index 00000000..7e5ea386 --- /dev/null +++ b/lang/cem/cemcom/tokenname.h @@ -0,0 +1,9 @@ +/* $Header$ */ +/* TOKENNAME DEFINITION */ + +struct tokenname { /* Used for defining the name of a + token as identified by its symbol + */ + int tn_symbol; + char *tn_name; +}; diff --git a/lang/cem/cemcom/type.c b/lang/cem/cemcom/type.c new file mode 100644 index 00000000..7ca93399 --- /dev/null +++ b/lang/cem/cemcom/type.c @@ -0,0 +1,217 @@ +/* $Header$ */ +/* T Y P E D E F I N I T I O N M E C H A N I S M */ + +#include "nobitfield.h" +#include "alloc.h" +#include "Lpars.h" +#include "arith.h" +#include "type.h" +#include "idf.h" +#include "def.h" +#include "sizes.h" +#include "align.h" + +struct type *function_of(), *array_of(); +#ifndef NOBITFIELD +struct type *field_of(); +#endif NOBITFIELD + +/* To be created dynamically in main() from defaults or from command + line parameters. +*/ +struct type + *char_type, *uchar_type, + *short_type, *ushort_type, + *word_type, *uword_type, + *int_type, *uint_type, + *long_type, *ulong_type, + *float_type, *double_type, + *void_type, *label_type, + *string_type, *funint_type, *error_type; + +struct type *pa_type; /* Pointer-Arithmetic type */ + +struct type * +create_type(fund) + register int fund; +{ + /* A brand new struct type is created, and its tp_fund set + to fund. + */ + register struct type *ntp = new_type(); + + clear((char *)ntp, sizeof(struct type)); + ntp->tp_fund = fund; + ntp->tp_size = (arith)-1; + + return ntp; +} + +struct type * +construct_type(fund, tp, count) + struct type *tp; + arith count; /* for fund == ARRAY only */ +{ + /* fund must be a type constructor: FIELD, FUNCTION, POINTER or + ARRAY. The pointer to the constructed type is returned. + */ + struct type *dtp; + + switch (fund) { +#ifndef NOBITFIELD + case FIELD: + dtp = field_of(tp); + break; +#endif NOBITFIELD + + case FUNCTION: + if (tp->tp_fund == FUNCTION) { + error("function cannot yield function"); + return error_type; + } + if (tp->tp_fund == ARRAY) { + error("function cannot yield array"); + return error_type; + } + + dtp = function_of(tp); + break; + case POINTER: + dtp = pointer_to(tp); + break; + case ARRAY: + if (tp->tp_size < 0) { + error("cannot construct array of unknown type"); + count = (arith)-1; + } + if (count >= (arith)0) + count *= tp->tp_size; + dtp = array_of(tp, count); + break; + } + return dtp; +} + +struct type * +function_of(tp) + struct type *tp; +{ + struct type *dtp = tp->tp_function; + + if (!dtp) { + tp->tp_function = dtp = create_type(FUNCTION); + dtp->tp_up = tp; + dtp->tp_size = pointer_size; + dtp->tp_align = pointer_align; + } + return dtp; +} + +struct type * +pointer_to(tp) + struct type *tp; +{ + struct type *dtp = tp->tp_pointer; + + if (!dtp) { + tp->tp_pointer = dtp = create_type(POINTER); + dtp->tp_unsigned = 1; + dtp->tp_up = tp; + dtp->tp_size = pointer_size; + dtp->tp_align = pointer_align; + } + return dtp; +} + +struct type * +array_of(tp, count) + struct type *tp; + arith count; +{ + struct type *dtp = tp->tp_array; + + /* look for a type with the right size */ + while (dtp && dtp->tp_size != count) + dtp = dtp->next; + + if (!dtp) { + dtp = create_type(ARRAY); + dtp->tp_up = tp; + dtp->tp_size = count; + dtp->tp_align = tp->tp_align; + dtp->next = tp->tp_array; + tp->tp_array = dtp; + } + return dtp; +} + +#ifndef NOBITFIELD +struct type * +field_of(tp) + struct type *tp; +{ + struct type *dtp = create_type(FIELD); + + dtp->tp_up = tp; + dtp->tp_align = tp->tp_align; + dtp->tp_size = tp->tp_size; + return dtp; +} +#endif NOBITFIELD + +arith +size_of_type(tp, nm) + struct type *tp; + char nm[]; +{ + arith sz = tp->tp_size; + + if (sz < 0) { + error("size of %s unknown", nm); + return (arith)1; + } + return sz; +} + +idf2type(idf, tpp) + struct idf *idf; + struct type **tpp; +{ + /* Decoding a typedef-ed identifier: if the size is yet + unknown we have to make copy of the type descriptor to + prevent garbage at the initialisation of arrays with + unknown size. + */ + if ( idf->id_def->df_type->tp_size < (arith)0 && + idf->id_def->df_type->tp_fund == ARRAY + ) { + struct type *ntp = new_type(); + *ntp = *(idf->id_def->df_type); + /* this is really a structure assignment, AAGH!!! */ + *tpp = ntp; + } + else { + *tpp = idf->id_def->df_type; + } +} + +arith +align(pos, al) + arith pos; + int al; +{ + return ((pos + al - 1) / al) * al; +} + +struct type * +standard_type(fund, sign, align, size) + int align; arith size; +{ + register struct type *tp = create_type(fund); + + tp->tp_unsigned = sign; + tp->tp_align = align; + tp->tp_size = size; + + return tp; +} diff --git a/lang/cem/cemcom/type.h b/lang/cem/cemcom/type.h new file mode 100644 index 00000000..1937a569 --- /dev/null +++ b/lang/cem/cemcom/type.h @@ -0,0 +1,52 @@ +/* $Header$ */ +/* TYPE DESCRIPTOR */ + +#include "nobitfield.h" + +struct type { + struct type *next; /* used only with ARRAY */ + short tp_fund; /* fundamental type */ + char tp_unsigned; + int tp_align; + arith tp_size; /* -1 if declared but not defined */ + struct idf *tp_idf; /* name of STRUCT, UNION or ENUM */ + struct sdef *tp_sdef; /* to first selector */ + struct type *tp_up; /* from FIELD, POINTER, ARRAY + or FUNCTION to fund. */ + struct field *tp_field; /* field descriptor if fund == FIELD */ + struct type *tp_pointer;/* to POINTER */ + struct type *tp_array; /* to ARRAY */ + struct type *tp_function;/* to FUNCTION */ +}; + +extern struct type + *create_type(), *standard_type(), *construct_type(), *pointer_to(), + *array_of(), *function_of(); + +#ifndef NOBITFIELD +extern struct type *field_of(); +#endif NOBITFIELD + +extern struct type + *char_type, *uchar_type, + *short_type, *ushort_type, + *word_type, *uword_type, + *int_type, *uint_type, + *long_type, *ulong_type, + *float_type, *double_type, + *void_type, *label_type, + *string_type, *funint_type, *error_type; + +extern struct type *pa_type; /* type.c */ + +extern arith size_of_type(), align(); + + +/* allocation definitions of struct type */ +/* ALLOCDEF "type" */ +extern char *st_alloc(); +extern struct type *h_type; +#define new_type() ((struct type *) \ + st_alloc((char **)&h_type, sizeof(struct type))) +#define free_type(p) st_free(p, h_type, sizeof(struct type)) + diff --git a/lang/cem/cemcom/type.str b/lang/cem/cemcom/type.str new file mode 100644 index 00000000..1937a569 --- /dev/null +++ b/lang/cem/cemcom/type.str @@ -0,0 +1,52 @@ +/* $Header$ */ +/* TYPE DESCRIPTOR */ + +#include "nobitfield.h" + +struct type { + struct type *next; /* used only with ARRAY */ + short tp_fund; /* fundamental type */ + char tp_unsigned; + int tp_align; + arith tp_size; /* -1 if declared but not defined */ + struct idf *tp_idf; /* name of STRUCT, UNION or ENUM */ + struct sdef *tp_sdef; /* to first selector */ + struct type *tp_up; /* from FIELD, POINTER, ARRAY + or FUNCTION to fund. */ + struct field *tp_field; /* field descriptor if fund == FIELD */ + struct type *tp_pointer;/* to POINTER */ + struct type *tp_array; /* to ARRAY */ + struct type *tp_function;/* to FUNCTION */ +}; + +extern struct type + *create_type(), *standard_type(), *construct_type(), *pointer_to(), + *array_of(), *function_of(); + +#ifndef NOBITFIELD +extern struct type *field_of(); +#endif NOBITFIELD + +extern struct type + *char_type, *uchar_type, + *short_type, *ushort_type, + *word_type, *uword_type, + *int_type, *uint_type, + *long_type, *ulong_type, + *float_type, *double_type, + *void_type, *label_type, + *string_type, *funint_type, *error_type; + +extern struct type *pa_type; /* type.c */ + +extern arith size_of_type(), align(); + + +/* allocation definitions of struct type */ +/* ALLOCDEF "type" */ +extern char *st_alloc(); +extern struct type *h_type; +#define new_type() ((struct type *) \ + st_alloc((char **)&h_type, sizeof(struct type))) +#define free_type(p) st_free(p, h_type, sizeof(struct type)) + From 7e05deae32f8d882c1c088bff4924f8f2faa3e04 Mon Sep 17 00:00:00 2001 From: erikb Date: Mon, 10 Mar 1986 13:15:40 +0000 Subject: [PATCH 0126/1625] *** empty log message *** --- lang/cem/cemcom/Files | 94 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 lang/cem/cemcom/Files diff --git a/lang/cem/cemcom/Files b/lang/cem/cemcom/Files new file mode 100644 index 00000000..2fd36917 --- /dev/null +++ b/lang/cem/cemcom/Files @@ -0,0 +1,94 @@ +Files +cem.1 +cem.c +cemcom.1 +Parameters +Makefile +LLlex.c +LLlex.h +LLmessage.c +align.h +alloc.c +alloc.h +arith.c +arith.h +asm.c +assert.h +atw.h +blocks.c +char.tab +ch7.c +ch7bin.c +ch7mon.c +class.h +code.c +code.h +conversion.c +cstoper.c +dataflow.c +declar.g +declarator.c +declarator.h +decspecs.c +decspecs.h +def.h +domacro.c +dumpidf.c +em.c +em.h +emcode.def +error.c +eval.c +expr.c +expr.h +expression.g +faulty.h +field.c +field.h +idf.c +idf.h +init.c +input.c +input.h +interface.h +ival.c +label.c +label.h +level.h +macro.h +main.c +make.emfun +make.emmac +make.hfiles +make.next +make.tokcase +make.tokfile +mcomm.c +mes.h +options +options.c +program.g +replace.c +scan.c +sizes.h +skip.c +specials.h +stack.c +stack.h +statement.g +stb.c +storage.c +storage.h +string.c +string.h +struct.c +struct.h +switch.c +switch.h +system.c +system.h +tab.c +tokenname.c +tokenname.h +type.c +type.h From 271ffc93716138960d823ed23705c5e3c3c726c4 Mon Sep 17 00:00:00 2001 From: erikb Date: Mon, 10 Mar 1986 15:10:56 +0000 Subject: [PATCH 0127/1625] renamed declarator.h as declar.h --- lang/cem/cemcom/code.c | 2 +- lang/cem/cemcom/declar.g | 2 +- lang/cem/cemcom/declarator.c | 2 +- lang/cem/cemcom/expr.c | 2 +- lang/cem/cemcom/idf.c | 2 +- lang/cem/cemcom/main.c | 2 +- lang/cem/cemcom/program.g | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lang/cem/cemcom/code.c b/lang/cem/cemcom/code.c index fb4e7e05..904c6b75 100644 --- a/lang/cem/cemcom/code.c +++ b/lang/cem/cemcom/code.c @@ -18,7 +18,7 @@ #include "em.h" #include "level.h" #include "decspecs.h" -#include "declarator.h" +#include "declar.h" #include "Lpars.h" #include "mes.h" #include "LLlex.h" diff --git a/lang/cem/cemcom/declar.g b/lang/cem/cemcom/declar.g index a758193b..c211724f 100644 --- a/lang/cem/cemcom/declar.g +++ b/lang/cem/cemcom/declar.g @@ -12,7 +12,7 @@ #include "field.h" #include "decspecs.h" #include "def.h" -#include "declarator.h" +#include "declar.h" #include "label.h" #include "expr.h" #include "sizes.h" diff --git a/lang/cem/cemcom/declarator.c b/lang/cem/cemcom/declarator.c index c23cfcdc..27a9d88c 100644 --- a/lang/cem/cemcom/declarator.c +++ b/lang/cem/cemcom/declarator.c @@ -6,7 +6,7 @@ #include "arith.h" #include "type.h" #include "Lpars.h" -#include "declarator.h" +#include "declar.h" #include "storage.h" #include "idf.h" #include "label.h" diff --git a/lang/cem/cemcom/expr.c b/lang/cem/cemcom/expr.c index 67d39b29..72c43ef7 100644 --- a/lang/cem/cemcom/expr.c +++ b/lang/cem/cemcom/expr.c @@ -12,7 +12,7 @@ #include "LLlex.h" #include "Lpars.h" #include "decspecs.h" -#include "declarator.h" +#include "declar.h" #include "storage.h" #include "sizes.h" diff --git a/lang/cem/cemcom/idf.c b/lang/cem/cemcom/idf.c index f29f43ba..9739c8a3 100644 --- a/lang/cem/cemcom/idf.c +++ b/lang/cem/cemcom/idf.c @@ -16,7 +16,7 @@ #include "def.h" #include "type.h" #include "struct.h" -#include "declarator.h" +#include "declar.h" #include "decspecs.h" #include "sizes.h" #include "Lpars.h" diff --git a/lang/cem/cemcom/main.c b/lang/cem/cemcom/main.c index ce3a88ac..b2b199f7 100644 --- a/lang/cem/cemcom/main.c +++ b/lang/cem/cemcom/main.c @@ -16,7 +16,7 @@ #include "idf.h" #include "arith.h" #include "type.h" -#include "declarator.h" +#include "declar.h" #include "tokenname.h" #include "Lpars.h" #include "LLlex.h" diff --git a/lang/cem/cemcom/program.g b/lang/cem/cemcom/program.g index 761e19db..5817aa0f 100644 --- a/lang/cem/cemcom/program.g +++ b/lang/cem/cemcom/program.g @@ -48,7 +48,7 @@ #include "idf.h" #include "label.h" #include "type.h" -#include "declarator.h" +#include "declar.h" #include "decspecs.h" #include "code.h" #include "expr.h" From d1e46d44248bf3c228350c200c97a430c6d1383f Mon Sep 17 00:00:00 2001 From: erikb Date: Mon, 10 Mar 1986 15:16:33 +0000 Subject: [PATCH 0128/1625] introduced the ALLOCDEF mechanism --- lang/cem/cemcom/code.str | 8 -------- lang/cem/cemcom/declar.str | 16 ---------------- lang/cem/cemcom/decspecs.str | 8 -------- lang/cem/cemcom/def.str | 8 -------- lang/cem/cemcom/expr.str | 8 -------- lang/cem/cemcom/field.str | 8 -------- lang/cem/cemcom/idf.str | 16 ---------------- lang/cem/cemcom/macro.str | 8 -------- lang/cem/cemcom/stack.str | 16 ---------------- lang/cem/cemcom/struct.str | 16 ---------------- lang/cem/cemcom/switch.str | 16 ---------------- lang/cem/cemcom/type.str | 8 -------- 12 files changed, 136 deletions(-) diff --git a/lang/cem/cemcom/code.str b/lang/cem/cemcom/code.str index 3399b3e0..11a00cb6 100644 --- a/lang/cem/cemcom/code.str +++ b/lang/cem/cemcom/code.str @@ -7,15 +7,7 @@ struct stat_block { label st_continue; }; - -/* allocation definitions of struct stat_block */ /* ALLOCDEF "stat_block" */ -extern char *st_alloc(); -extern struct stat_block *h_stat_block; -#define new_stat_block() ((struct stat_block *) \ - st_alloc((char **)&h_stat_block, sizeof(struct stat_block))) -#define free_stat_block(p) st_free(p, h_stat_block, sizeof(struct stat_block)) - #define LVAL 0 #define RVAL 1 diff --git a/lang/cem/cemcom/declar.str b/lang/cem/cemcom/declar.str index 5ecbb70c..9a25c58a 100644 --- a/lang/cem/cemcom/declar.str +++ b/lang/cem/cemcom/declar.str @@ -13,15 +13,7 @@ struct declarator { struct idstack_item *dc_fparams; /* params for function */ }; - -/* allocation definitions of struct declarator */ /* ALLOCDEF "declarator" */ -extern char *st_alloc(); -extern struct declarator *h_declarator; -#define new_declarator() ((struct declarator *) \ - st_alloc((char **)&h_declarator, sizeof(struct declarator))) -#define free_declarator(p) st_free(p, h_declarator, sizeof(struct declarator)) - #define NO_PARAMS ((struct idstack_item *) 0) @@ -31,15 +23,7 @@ struct decl_unary { arith du_count; /* for ARRAYs only */ }; - -/* allocation definitions of struct decl_unary */ /* ALLOCDEF "decl_unary" */ -extern char *st_alloc(); -extern struct decl_unary *h_decl_unary; -#define new_decl_unary() ((struct decl_unary *) \ - st_alloc((char **)&h_decl_unary, sizeof(struct decl_unary))) -#define free_decl_unary(p) st_free(p, h_decl_unary, sizeof(struct decl_unary)) - extern struct type *declare_type(); extern struct declarator null_declarator; diff --git a/lang/cem/cemcom/decspecs.str b/lang/cem/cemcom/decspecs.str index 0b1598c0..81764613 100644 --- a/lang/cem/cemcom/decspecs.str +++ b/lang/cem/cemcom/decspecs.str @@ -10,14 +10,6 @@ struct decspecs { int ds_unsigned; /* 0 or 1 */ }; - -/* allocation definitions of struct decspecs */ /* ALLOCDEF "decspecs" */ -extern char *st_alloc(); -extern struct decspecs *h_decspecs; -#define new_decspecs() ((struct decspecs *) \ - st_alloc((char **)&h_decspecs, sizeof(struct decspecs))) -#define free_decspecs(p) st_free(p, h_decspecs, sizeof(struct decspecs)) - extern struct decspecs null_decspecs; diff --git a/lang/cem/cemcom/def.str b/lang/cem/cemcom/def.str index abb28155..14b07dea 100644 --- a/lang/cem/cemcom/def.str +++ b/lang/cem/cemcom/def.str @@ -26,12 +26,4 @@ struct def { /* for ordinary tags */ #define REG_DEFAULT 1 /* register candidate, not declared as such */ #define REG_BONUS 10 /* register candidate, declared as such */ - -/* allocation definitions of struct def */ /* ALLOCDEF "def" */ -extern char *st_alloc(); -extern struct def *h_def; -#define new_def() ((struct def *) \ - st_alloc((char **)&h_def, sizeof(struct def))) -#define free_def(p) st_free(p, h_def, sizeof(struct def)) - diff --git a/lang/cem/cemcom/expr.str b/lang/cem/cemcom/expr.str index 46e658a0..87f61142 100644 --- a/lang/cem/cemcom/expr.str +++ b/lang/cem/cemcom/expr.str @@ -89,14 +89,6 @@ struct expr { extern struct expr *intexpr(), *new_oper(); - -/* allocation definitions of struct expr */ /* ALLOCDEF "expr" */ -extern char *st_alloc(); -extern struct expr *h_expr; -#define new_expr() ((struct expr *) \ - st_alloc((char **)&h_expr, sizeof(struct expr))) -#define free_expr(p) st_free(p, h_expr, sizeof(struct expr)) - #define ISCOMMA(e) ((e)->ex_class == Oper && (e)->OP_OPER == INITCOMMA) diff --git a/lang/cem/cemcom/field.str b/lang/cem/cemcom/field.str index 794920b6..79830abc 100644 --- a/lang/cem/cemcom/field.str +++ b/lang/cem/cemcom/field.str @@ -9,12 +9,4 @@ struct field { /* for field specifiers */ struct sdef *fd_sdef; /* upward pointer */ }; - -/* allocation definitions of struct field */ /* ALLOCDEF "field" */ -extern char *st_alloc(); -extern struct field *h_field; -#define new_field() ((struct field *) \ - st_alloc((char **)&h_field, sizeof(struct field))) -#define free_field(p) st_free(p, h_field, sizeof(struct field)) - diff --git a/lang/cem/cemcom/idf.str b/lang/cem/cemcom/idf.str index 12496de1..3b6f7021 100644 --- a/lang/cem/cemcom/idf.str +++ b/lang/cem/cemcom/idf.str @@ -27,15 +27,7 @@ struct idstack_item { /* stack of identifiers */ struct idf *is_idf; }; - -/* allocation definitions of struct idstack_item */ /* ALLOCDEF "idstack_item" */ -extern char *st_alloc(); -extern struct idstack_item *h_idstack_item; -#define new_idstack_item() ((struct idstack_item *) \ - st_alloc((char **)&h_idstack_item, sizeof(struct idstack_item))) -#define free_idstack_item(p) st_free(p, h_idstack_item, sizeof(struct idstack_item)) - struct idf { struct idf *next; @@ -52,15 +44,7 @@ struct idf { int id_special; /* special action needed at occurrence */ }; - -/* allocation definitions of struct idf */ /* ALLOCDEF "idf" */ -extern char *st_alloc(); -extern struct idf *h_idf; -#define new_idf() ((struct idf *) \ - st_alloc((char **)&h_idf, sizeof(struct idf))) -#define free_idf(p) st_free(p, h_idf, sizeof(struct idf)) - extern struct idf *str2idf(), *idf_hashed(); diff --git a/lang/cem/cemcom/macro.str b/lang/cem/cemcom/macro.str index cdd023f8..34a62dd5 100644 --- a/lang/cem/cemcom/macro.str +++ b/lang/cem/cemcom/macro.str @@ -26,15 +26,7 @@ struct macro { char mc_flag; /* marking this macro */ }; - -/* allocation definitions of struct macro */ /* ALLOCDEF "macro" */ -extern char *st_alloc(); -extern struct macro *h_macro; -#define new_macro() ((struct macro *) \ - st_alloc((char **)&h_macro, sizeof(struct macro))) -#define free_macro(p) st_free(p, h_macro, sizeof(struct macro)) - /* `token' numbers of keywords of command-line processor */ diff --git a/lang/cem/cemcom/stack.str b/lang/cem/cemcom/stack.str index 27a7f312..b2776ea4 100644 --- a/lang/cem/cemcom/stack.str +++ b/lang/cem/cemcom/stack.str @@ -16,30 +16,14 @@ struct stack_level { int sl_level; }; - -/* allocation definitions of struct stack_level */ /* ALLOCDEF "stack_level" */ -extern char *st_alloc(); -extern struct stack_level *h_stack_level; -#define new_stack_level() ((struct stack_level *) \ - st_alloc((char **)&h_stack_level, sizeof(struct stack_level))) -#define free_stack_level(p) st_free(p, h_stack_level, sizeof(struct stack_level)) - struct stack_entry { struct stack_entry *next; struct idf *se_idf; }; - -/* allocation definitions of struct stack_entry */ /* ALLOCDEF "stack_entry" */ -extern char *st_alloc(); -extern struct stack_entry *h_stack_entry; -#define new_stack_entry() ((struct stack_entry *) \ - st_alloc((char **)&h_stack_entry, sizeof(struct stack_entry))) -#define free_stack_entry(p) st_free(p, h_stack_entry, sizeof(struct stack_entry)) - extern struct stack_level *local_level; extern struct stack_level *stack_level_of(); diff --git a/lang/cem/cemcom/struct.str b/lang/cem/cemcom/struct.str index 8caab678..ccd3eaa7 100644 --- a/lang/cem/cemcom/struct.str +++ b/lang/cem/cemcom/struct.str @@ -13,15 +13,7 @@ struct sdef { /* for selectors */ extern char *st_alloc(); - -/* allocation definitions of struct sdef */ /* ALLOCDEF "sdef" */ -extern char *st_alloc(); -extern struct sdef *h_sdef; -#define new_sdef() ((struct sdef *) \ - st_alloc((char **)&h_sdef, sizeof(struct sdef))) -#define free_sdef(p) st_free(p, h_sdef, sizeof(struct sdef)) - struct tag { /* for struct-, union- and enum tags */ struct tag *next; @@ -31,14 +23,6 @@ struct tag { /* for struct-, union- and enum tags */ }; - -/* allocation definitions of struct tag */ /* ALLOCDEF "tag" */ -extern char *st_alloc(); -extern struct tag *h_tag; -#define new_tag() ((struct tag *) \ - st_alloc((char **)&h_tag, sizeof(struct tag))) -#define free_tag(p) st_free(p, h_tag, sizeof(struct tag)) - struct sdef *idf2sdef(); diff --git a/lang/cem/cemcom/switch.str b/lang/cem/cemcom/switch.str index 07998b9e..9f95fc0f 100644 --- a/lang/cem/cemcom/switch.str +++ b/lang/cem/cemcom/switch.str @@ -13,15 +13,7 @@ struct switch_hdr { struct case_entry *sh_entries; }; - -/* allocation definitions of struct switch_hdr */ /* ALLOCDEF "switch_hdr" */ -extern char *st_alloc(); -extern struct switch_hdr *h_switch_hdr; -#define new_switch_hdr() ((struct switch_hdr *) \ - st_alloc((char **)&h_switch_hdr, sizeof(struct switch_hdr))) -#define free_switch_hdr(p) st_free(p, h_switch_hdr, sizeof(struct switch_hdr)) - struct case_entry { struct case_entry *next; @@ -29,12 +21,4 @@ struct case_entry { arith ce_value; }; - -/* allocation definitions of struct case_entry */ /* ALLOCDEF "case_entry" */ -extern char *st_alloc(); -extern struct case_entry *h_case_entry; -#define new_case_entry() ((struct case_entry *) \ - st_alloc((char **)&h_case_entry, sizeof(struct case_entry))) -#define free_case_entry(p) st_free(p, h_case_entry, sizeof(struct case_entry)) - diff --git a/lang/cem/cemcom/type.str b/lang/cem/cemcom/type.str index 1937a569..9524ef16 100644 --- a/lang/cem/cemcom/type.str +++ b/lang/cem/cemcom/type.str @@ -41,12 +41,4 @@ extern struct type *pa_type; /* type.c */ extern arith size_of_type(), align(); - -/* allocation definitions of struct type */ /* ALLOCDEF "type" */ -extern char *st_alloc(); -extern struct type *h_type; -#define new_type() ((struct type *) \ - st_alloc((char **)&h_type, sizeof(struct type))) -#define free_type(p) st_free(p, h_type, sizeof(struct type)) - From 0ea6776657192fcf3d3bbaef8d74a0f5e62a47ed Mon Sep 17 00:00:00 2001 From: erikb Date: Mon, 10 Mar 1986 15:18:00 +0000 Subject: [PATCH 0129/1625] Introduction of ALLOCDEF --- lang/cem/cemcom/make.allocd | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100755 lang/cem/cemcom/make.allocd diff --git a/lang/cem/cemcom/make.allocd b/lang/cem/cemcom/make.allocd new file mode 100755 index 00000000..1c2469d8 --- /dev/null +++ b/lang/cem/cemcom/make.allocd @@ -0,0 +1,9 @@ +sed ' +s:^.*ALLOCDEF.*"\(.*\)".*$:\ +/* allocation definitions of struct \1 */\ +extern char *st_alloc();\ +extern struct \1 *h_\1;\ +#define new_\1() ((struct \1 *) \\\ + st_alloc((char **)\&h_\1, sizeof(struct \1)))\ +#define free_\1(p) st_free(p, h_\1, sizeof(struct \1))\ +:' From 1378e479b50f75b2d5f4523c6c7b207b94375b32 Mon Sep 17 00:00:00 2001 From: erikb Date: Mon, 10 Mar 1986 15:20:30 +0000 Subject: [PATCH 0130/1625] Introduced the ALLOCDEF mechanism --- lang/cem/cemcom/Files | 25 +++++++++++------------ lang/cem/cemcom/Makefile.erik | 37 ++++++++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/lang/cem/cemcom/Files b/lang/cem/cemcom/Files index 2fd36917..e0660c63 100644 --- a/lang/cem/cemcom/Files +++ b/lang/cem/cemcom/Files @@ -22,16 +22,16 @@ ch7bin.c ch7mon.c class.h code.c -code.h +code.str conversion.c cstoper.c dataflow.c declar.g declarator.c -declarator.h +declar.str decspecs.c -decspecs.h -def.h +decspecs.str +def.str domacro.c dumpidf.c em.c @@ -40,13 +40,13 @@ emcode.def error.c eval.c expr.c -expr.h +expr.str expression.g faulty.h field.c -field.h +field.str idf.c -idf.h +idf.str init.c input.c input.h @@ -55,8 +55,9 @@ ival.c label.c label.h level.h -macro.h +macro.str main.c +make.allocd make.emfun make.emmac make.hfiles @@ -74,7 +75,7 @@ sizes.h skip.c specials.h stack.c -stack.h +stack.str statement.g stb.c storage.c @@ -82,13 +83,13 @@ storage.h string.c string.h struct.c -struct.h +struct.str switch.c -switch.h +switch.str system.c system.h tab.c tokenname.c tokenname.h type.c -type.h +type.str diff --git a/lang/cem/cemcom/Makefile.erik b/lang/cem/cemcom/Makefile.erik index 83f229fc..3acc9a54 100644 --- a/lang/cem/cemcom/Makefile.erik +++ b/lang/cem/cemcom/Makefile.erik @@ -44,6 +44,8 @@ GOBJ = char.o symbol2str.o next.o writeem.o # generated source files GSRC = char.c symbol2str.c next.c writeem.c \ + code.h declar.h decspecs.h def.h expr.h field.h \ + idf.h macro.h stack.h struct.h switch.h type.h \ writeem.h # .h files generated by `make hfiles'; PLEASE KEEP THIS UP-TO-DATE! @@ -59,8 +61,12 @@ GENERATED = tab tokenfile.g Lpars.h LLfiles LL.output lint.out \ print Xref lxref hfiles cfiles # include files containing ALLOCDEF specifications -NEXTFILES = code.h declarator.h decspecs.h def.h expr.h field.h \ - idf.h macro.h stack.h struct.h switch.h type.h +NEXTFILES = code.str declarator.str decspecs.str def.str expr.str field.str \ + idf.str macro.str stack.str struct.str switch.str type.str + +.SUFFIXES: .str .h +.str.h: + ./make.allocd <$*.str >$*.h all: cc @@ -95,6 +101,19 @@ char.c: tab char.tab next.c: make.next $(NEXTFILES) ./make.next $(NEXTFILES) >next.c +code.h: make.allocd +declar.h: make.allocd +decspecs.h: make.allocd +def.h: make.allocd +expr.h: make.allocd +field.h: make.allocd +idf.h: make.allocd +macro.h: make.allocd +stack.h: make.allocd +struct.h: make.allocd +switch.h: make.allocd +type.h: make.allocd + writeem.c: make.emfun emcode.def ./make.emfun emcode.def >writeem.c @@ -165,18 +184,18 @@ sim: cfiles $(SIM) $(SIMFLAGS) `sources $(COBJ)` $(GSRC) $(LSRC) #AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO -main.o: LLlex.h Lpars.h alloc.h arith.h bufsiz.h debug.h declarator.h idf.h input.h inputtype.h level.h maxincl.h myalloc.h nobitfield.h nopp.h spec_arith.h specials.h system.h target_sizes.h tokenname.h type.h use_tmp.h -idf.o: LLlex.h Lpars.h align.h alloc.h arith.h assert.h botch_free.h debug.h declarator.h decspecs.h def.h idf.h idfsize.h label.h level.h nobitfield.h nopp.h sizes.h spec_arith.h specials.h stack.h storage.h struct.h type.h -declarator.o: Lpars.h alloc.h arith.h botch_free.h declarator.h expr.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h type.h +main.o: LLlex.h Lpars.h alloc.h arith.h bufsiz.h debug.h declar.h idf.h input.h inputtype.h level.h maxincl.h myalloc.h nobitfield.h nopp.h spec_arith.h specials.h system.h target_sizes.h tokenname.h type.h use_tmp.h +idf.o: LLlex.h Lpars.h align.h alloc.h arith.h assert.h botch_free.h debug.h declar.h decspecs.h def.h idf.h idfsize.h label.h level.h nobitfield.h nopp.h sizes.h spec_arith.h specials.h stack.h storage.h struct.h type.h +declarator.o: Lpars.h alloc.h arith.h botch_free.h declar.h expr.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h type.h decspecs.o: Lpars.h arith.h decspecs.h def.h level.h nobitfield.h spec_arith.h type.h struct.o: LLlex.h Lpars.h align.h arith.h assert.h botch_free.h debug.h def.h field.h idf.h level.h nobitfield.h nopp.h sizes.h spec_arith.h stack.h storage.h struct.h type.h -expr.o: LLlex.h Lpars.h alloc.h arith.h botch_free.h declarator.h decspecs.h def.h expr.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h type.h +expr.o: LLlex.h Lpars.h alloc.h arith.h botch_free.h declar.h decspecs.h def.h expr.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h type.h ch7.o: Lpars.h arith.h assert.h debug.h def.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h struct.h type.h ch7bin.o: Lpars.h arith.h botch_free.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h storage.h struct.h type.h cstoper.o: Lpars.h arith.h expr.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h target_sizes.h type.h arith.o: Lpars.h alloc.h arith.h botch_free.h expr.h field.h idf.h label.h mes.h nobitfield.h nopp.h spec_arith.h storage.h type.h alloc.o: alloc.h assert.h debug.h myalloc.h system.h -code.o: LLlex.h Lpars.h alloc.h arith.h assert.h atw.h botch_free.h code.h dataflow.h debug.h declarator.h decspecs.h def.h em.h expr.h idf.h label.h level.h mes.h nobitfield.h nopp.h proc_intf.h sizes.h spec_arith.h specials.h stack.h storage.h type.h use_tmp.h writeem.h +code.o: LLlex.h Lpars.h alloc.h arith.h assert.h atw.h botch_free.h code.h dataflow.h debug.h declar.h decspecs.h def.h em.h expr.h idf.h label.h level.h mes.h nobitfield.h nopp.h proc_intf.h sizes.h spec_arith.h specials.h stack.h storage.h type.h use_tmp.h writeem.h dumpidf.o: Lpars.h arith.h debug.h def.h expr.h field.h idf.h label.h nobitfield.h nopp.h spec_arith.h stack.h struct.h type.h error.o: LLlex.h arith.h debug.h em.h errout.h expr.h label.h nopp.h proc_intf.h spec_arith.h string.h system.h tokenname.h use_tmp.h writeem.h field.o: Lpars.h arith.h assert.h code.h debug.h em.h expr.h field.h idf.h label.h nobitfield.h nopp.h proc_intf.h sizes.h spec_arith.h type.h writeem.h @@ -205,10 +224,10 @@ dataflow.o: dataflow.h system.o: inputtype.h system.h string.o: arith.h nopp.h spec_arith.h str_params.h string.h system.h tokenfile.o: Lpars.h -declar.o: LLlex.h Lpars.h arith.h debug.h declarator.h decspecs.h def.h expr.h field.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h struct.h type.h +declar.o: LLlex.h Lpars.h arith.h debug.h declar.h decspecs.h def.h expr.h field.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h struct.h type.h statement.o: LLlex.h Lpars.h arith.h botch_free.h code.h debug.h def.h em.h expr.h idf.h label.h nobitfield.h nopp.h proc_intf.h spec_arith.h stack.h storage.h type.h writeem.h expression.o: LLlex.h Lpars.h arith.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h type.h -program.o: LLlex.h Lpars.h alloc.h arith.h code.h declarator.h decspecs.h def.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h type.h +program.o: LLlex.h Lpars.h alloc.h arith.h code.h declar.h decspecs.h def.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h type.h Lpars.o: Lpars.h char.o: class.h symbol2str.o: Lpars.h From 4a90cfec86d287677551d0d049e1dbec8ca226a1 Mon Sep 17 00:00:00 2001 From: erikb Date: Mon, 10 Mar 1986 15:59:43 +0000 Subject: [PATCH 0131/1625] removed a reference to declarator.str --- lang/cem/cemcom/Makefile.erik | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/cem/cemcom/Makefile.erik b/lang/cem/cemcom/Makefile.erik index 3acc9a54..4997c57e 100644 --- a/lang/cem/cemcom/Makefile.erik +++ b/lang/cem/cemcom/Makefile.erik @@ -61,7 +61,7 @@ GENERATED = tab tokenfile.g Lpars.h LLfiles LL.output lint.out \ print Xref lxref hfiles cfiles # include files containing ALLOCDEF specifications -NEXTFILES = code.str declarator.str decspecs.str def.str expr.str field.str \ +NEXTFILES = code.str declar.str decspecs.str def.str expr.str field.str \ idf.str macro.str stack.str struct.str switch.str type.str .SUFFIXES: .str .h From 52bf78e1fc6447558f03ba575b78af974bec5800 Mon Sep 17 00:00:00 2001 From: erikb Date: Tue, 11 Mar 1986 14:46:46 +0000 Subject: [PATCH 0132/1625] added the possibility to prepend your own libc.a before the default --- lang/cem/cemcom/cem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lang/cem/cemcom/cem.c b/lang/cem/cemcom/cem.c index 5e4c4819..f2d832f8 100644 --- a/lang/cem/cemcom/cem.c +++ b/lang/cem/cemcom/cem.c @@ -45,8 +45,9 @@ struct arglist LD_HEAD = { }; struct arglist LD_TAIL = { - 3, + 4, { + "/user1/cem/lib/libc.a", "/user1/cem/lib/stb.o", "/usr/em/lib/vax4/tail_mon", "/usr/em/lib/vax4/tail_em" @@ -443,7 +444,6 @@ main(argc, argv) append(call, o_FILE); concat(call, &LD_HEAD); concat(call, &LDFILES); - append(call, library("c")); concat(call, &LD_TAIL); if (runvec(call, (char *)0)) { register i = GEN_LDFILES.al_argc; From e0cf6e95efb572ba36446cf0f689154963a40e11 Mon Sep 17 00:00:00 2001 From: erikb Date: Tue, 11 Mar 1986 15:21:30 +0000 Subject: [PATCH 0133/1625] renamed some EM code functions according to the 86/03/11 EMCODE definition --- lang/cem/cemcom/code.c | 20 +++++------ lang/cem/cemcom/emcode.def | 36 +++++++++---------- lang/cem/cemcom/eval.c | 72 ++++++++++++++++++------------------- lang/cem/cemcom/ival.c | 26 +++++++------- lang/cem/cemcom/statement.g | 30 ++++++++-------- lang/cem/cemcom/switch.c | 30 ++++++++-------- 6 files changed, 107 insertions(+), 107 deletions(-) diff --git a/lang/cem/cemcom/code.c b/lang/cem/cemcom/code.c index 904c6b75..77c530a1 100644 --- a/lang/cem/cemcom/code.c +++ b/lang/cem/cemcom/code.c @@ -156,7 +156,7 @@ begin_proc(name, def) /* to be called when entering a procedure */ size = ATW(func_tp->tp_size); C_pro_narg(name); if (is_struct_or_union(func_tp->tp_fund)) { - C_ndlb(func_res_label = data_label()); + C_df_dlb(func_res_label = data_label()); C_bss_cst(size, (arith)0, 1); } else @@ -173,13 +173,13 @@ begin_proc(name, def) /* to be called when entering a procedure */ if (options['p']) { /* profiling */ if (strcmp(last_fn_given, FileName) != 0) { /* previous function came from other file */ - C_ndlb(file_name_label = data_label()); + C_df_dlb(file_name_label = data_label()); C_con_begin(); - C_co_scon(last_fn_given = FileName, (arith)0); + C_scon(last_fn_given = FileName, (arith)0); C_con_end(); } /* enable debug trace of EM source */ - C_fil_ndlb(file_name_label, (arith)0); + C_fil_dlb(file_name_label, (arith)0); C_lin((arith)LineNumber); } } @@ -206,11 +206,11 @@ end_proc(fbytes, nbytes) #endif DATAFLOW C_ret((arith)0); if (return_expr_occurred != 0) { - C_ilb(return_label); + C_df_ilb(return_label); if (func_res_label != 0) { - C_lae_ndlb(func_res_label, (arith)0); + C_lae_dlb(func_res_label, (arith)0); store_block(func_tp->tp_size, func_tp->tp_align); - C_lae_ndlb(func_res_label, (arith)0); + C_lae_dlb(func_res_label, (arith)0); C_ret(pointer_size); } else @@ -286,7 +286,7 @@ code_declaration(idf, expr, lvl, sc) code_scope(text, def); #endif USE_TMP def->df_alloc = ALLOC_DONE; - C_dnam(text); + C_df_dnam(text); do_ival(&(def->df_type), expr); } } @@ -300,7 +300,7 @@ code_declaration(idf, expr, lvl, sc) /* they are handled on the spot and get an integer label in EM. */ - C_ndlb((label)def->df_address); + C_df_dlb((label)def->df_address); if (expr) /* there is an initialisation */ do_ival(&(def->df_type), expr); else { /* produce blank space */ @@ -385,7 +385,7 @@ bss(idf) */ if (options['R'] && size == 0) warning("actual array of size 0"); - C_dnam(idf->id_text); + C_df_dnam(idf->id_text); C_bss_cst(align(size, word_align), (arith)0, 1); } diff --git a/lang/cem/cemcom/emcode.def b/lang/cem/cemcom/emcode.def index cf2530a2..5cc32d22 100644 --- a/lang/cem/cemcom/emcode.def +++ b/lang/cem/cemcom/emcode.def @@ -29,20 +29,20 @@ C_dup(p) | arith p; | OP(op_dup), CST(p) C_dvf(p) | arith p; | OP(op_dvf), CST(p) C_dvi(p) | arith p; | OP(op_dvi), CST(p) C_dvu(p) | arith p; | OP(op_dvu), CST(p) -C_fil_ndlb(l, o) | label l; arith o; | OP(op_fil), DOFF(l, o) +C_fil_dlb(l, o) | label l; arith o; | OP(op_fil), DOFF(l, o) C_ior(p) | arith p; | OP(op_ior), CST(p) C_lae_dnam(p, o) | char *p; arith o; | OP(op_lae), NOFF(p, o) -C_lae_ndlb(l, o) | label l; arith o; | OP(op_lae), DOFF(l, o) +C_lae_dlb(l, o) | label l; arith o; | OP(op_lae), DOFF(l, o) C_lal(p) | arith p; | OP(op_lal), CST(p) C_ldc(p) | arith p; | OP(op_ldc), DCST(p) C_lde_dnam(p, o) | char *p; arith o; | OP(op_lde), NOFF(p, o) -C_lde_ndlb(l, o) | label l; arith o; | OP(op_lde), DOFF(l, o) +C_lde_dlb(l, o) | label l; arith o; | OP(op_lde), DOFF(l, o) C_ldl(p) | arith p; | OP(op_ldl), CST(p) C_lfr(p) | arith p; | OP(op_lfr), CST(p) C_lin(p) | arith p; | OP(op_lin), CST(p) C_loc(p) | arith p; | OP(op_loc), CST(p) C_loe_dnam(p, o) | char *p; arith o; | OP(op_loe), NOFF(p, o) -C_loe_ndlb(l, o) | label l; arith o; | OP(op_loe), DOFF(l, o) +C_loe_dlb(l, o) | label l; arith o; | OP(op_loe), DOFF(l, o) C_loi(p) | arith p; | OP(op_loi), CST(p) C_lol(p) | arith p; | OP(op_lol), CST(p) C_lor(p) | arith p; | OP(op_lor), CST(p) @@ -60,14 +60,14 @@ C_sbi(p) | arith p; | OP(op_sbi), CST(p) C_sbs(p) | arith p; | OP(op_sbs), CST(p) C_sbu(p) | arith p; | OP(op_sbu), CST(p) C_sde_dnam(p, o) | char *p; arith o; | OP(op_sde), NOFF(p, o) -C_sde_ndlb(l, o) | label l; arith o; | OP(op_sde), DOFF(l, o) +C_sde_dlb(l, o) | label l; arith o; | OP(op_sde), DOFF(l, o) C_sdl(p) | arith p; | OP(op_sdl), CST(p) C_sli(p) | arith p; | OP(op_sli), CST(p) C_slu(p) | arith p; | OP(op_slu), CST(p) C_sri(p) | arith p; | OP(op_sri), CST(p) C_sru(p) | arith p; | OP(op_sru), CST(p) C_ste_dnam(p, o) | char *p; arith o; | OP(op_ste), NOFF(p, o) -C_ste_ndlb(l, o) | label l; arith o; | OP(op_ste), DOFF(l, o) +C_ste_dlb(l, o) | label l; arith o; | OP(op_ste), DOFF(l, o) C_sti(p) | arith p; | OP(op_sti), CST(p) C_stl(p) | arith p; | OP(op_stl), CST(p) C_xor(p) | arith p; | OP(op_xor), CST(p) @@ -78,9 +78,9 @@ C_zle(l) | label l; | OP(op_zle), CST((arith)l) C_zlt(l) | label l; | OP(op_zlt), CST((arith)l) C_zne(l) | label l; | OP(op_zne), CST((arith)l) % -C_ndlb(l) | label l; | DLB(l) -C_dnam(s) | char *s; | DNAM(s) -C_ilb(l) | label l; | ILB(l) +C_df_dlb(l) | label l; | DLB(l) +C_df_dnam(s) | char *s; | DNAM(s) +C_df_ilb(l) | label l; | ILB(l) % C_bss_cst(n, w, i) | arith n, w; int i; | PS(ps_bss), DCST(n), CST(w), CST((arith)i) @@ -89,18 +89,18 @@ C_con_begin() | | DC_start(ps_con), PS(ps_con) C_con_end() | | CEND() C_rom_begin() | | DC_start(ps_rom), PS(ps_rom) C_rom_end() | | CEND() -C_co_cst(l) | arith l; | DC_check(), CST(l) -C_co_icon(val, siz) | char *val; arith siz; | +C_cst(l) | arith l; | DC_check(), CST(l) +C_icon(val, siz) | char *val; arith siz; | DC_check(), WCON(sp_icon, val, siz) -C_co_ucon(val, siz) | char *val; arith siz; | +C_ucon(val, siz) | char *val; arith siz; | DC_check(), WCON(sp_ucon, val, siz) -C_co_fcon(val, siz) | char *val; arith siz; | +C_fcon(val, siz) | char *val; arith siz; | DC_check(), WCON(sp_fcon, val, siz) -C_co_scon(str, siz) | char *str; arith siz; | DC_check(), CSTR(str) -C_co_dnam(str, val) | char *str; arith val; | DC_check(), NOFF(str, val) -C_co_ndlb(l, val) | label l; arith val; | DC_check(), DOFF(l, val) -C_co_pnam(str) | char *str; | DC_check(), PNAM(str) -C_co_ilb(l) | label l; | DC_check(), ILB(l) +C_scon(str, siz) | char *str; arith siz; | DC_check(), CSTR(str) +C_dnam(str, val) | char *str; arith val; | DC_check(), NOFF(str, val) +C_dlb(l, val) | label l; arith val; | DC_check(), DOFF(l, val) +C_pnam(str) | char *str; | DC_check(), PNAM(str) +C_ilb(l) | label l; | DC_check(), ILB(l) % C_pro_narg(p1) | char *p1; | PS(ps_pro), PNAM(p1), CEND() C_end(l) | arith l; | PS(ps_end), CST(l) diff --git a/lang/cem/cemcom/eval.c b/lang/cem/cemcom/eval.c index 79b62a32..a0868ebc 100644 --- a/lang/cem/cemcom/eval.c +++ b/lang/cem/cemcom/eval.c @@ -87,11 +87,11 @@ EVAL(expr, val, code, true_label, false_label) if (gencode) { label datlab = data_label(); - C_ndlb(datlab); + C_df_dlb(datlab); C_con_begin(); - C_co_scon(expr->SG_VALUE, (arith)0); + C_scon(expr->SG_VALUE, (arith)0); C_con_end(); - C_lae_ndlb(datlab, (arith)0); + C_lae_dlb(datlab, (arith)0); } break; @@ -99,11 +99,11 @@ EVAL(expr, val, code, true_label, false_label) if (gencode) { label datlab = data_label(); - C_ndlb(datlab); + C_df_dlb(datlab); C_rom_begin(); - C_co_fcon(expr->FL_VALUE, expr->ex_type->tp_size); + C_fcon(expr->FL_VALUE, expr->ex_type->tp_size); C_rom_end(); - C_lae_ndlb(datlab, (arith)0); + C_lae_dlb(datlab, (arith)0); C_loi(expr->ex_type->tp_size); } break; @@ -315,9 +315,9 @@ EVAL(expr, val, code, true_label, false_label) compare(oper, l_true); C_loc((arith)0); C_bra(l_end); - C_ilb(l_true); + C_df_ilb(l_true); C_loc((arith)1); - C_ilb(l_end); + C_df_ilb(l_end); } } break; @@ -540,12 +540,12 @@ EVAL(expr, val, code, true_label, false_label) label l_end = text_label(); EVAL(leftop, RVAL, TRUE, l_true, l_false); - C_ilb(l_true); + C_df_ilb(l_true); EVAL(rightop->OP_LEFT, RVAL, code, NO_LABEL, NO_LABEL); C_bra(l_end); - C_ilb(l_false); + C_df_ilb(l_false); EVAL(rightop->OP_RIGHT, RVAL, code, NO_LABEL, NO_LABEL); - C_ilb(l_end); + C_df_ilb(l_end); break; } case AND: @@ -556,28 +556,28 @@ EVAL(expr, val, code, true_label, false_label) label l_end = text_label(); EVAL(leftop, RVAL, TRUE, l_maybe, l_false); - C_ilb(l_maybe); + C_df_ilb(l_maybe); if (gencode) { EVAL(rightop, RVAL, TRUE, l_true, l_false); - C_ilb(l_true); + C_df_ilb(l_true); C_loc((arith)1); C_bra(l_end); - C_ilb(l_false); + C_df_ilb(l_false); C_loc((arith)0); - C_ilb(l_end); + C_df_ilb(l_end); } else { EVAL(rightop, RVAL, FALSE, l_false, l_false); - C_ilb(l_false); + C_df_ilb(l_false); } } else { label l_maybe = text_label(); EVAL(leftop, RVAL, TRUE, l_maybe, false_label); - C_ilb(l_maybe); + C_df_ilb(l_maybe); EVAL(rightop, RVAL, code, true_label, false_label); } @@ -590,28 +590,28 @@ EVAL(expr, val, code, true_label, false_label) label l_end = text_label(); EVAL(leftop, RVAL, TRUE, l_true, l_maybe); - C_ilb(l_maybe); + C_df_ilb(l_maybe); if (gencode) { EVAL(rightop, RVAL, TRUE, l_true, l_false); - C_ilb(l_false); + C_df_ilb(l_false); C_loc((arith)0); C_bra(l_end); - C_ilb(l_true); + C_df_ilb(l_true); C_loc((arith)1); - C_ilb(l_end); + C_df_ilb(l_end); } else { EVAL(rightop, RVAL, FALSE, l_true, l_true); - C_ilb(l_true); + C_df_ilb(l_true); } } else { label l_maybe = text_label(); EVAL(leftop, RVAL, TRUE, true_label, l_maybe); - C_ilb(l_maybe); + C_df_ilb(l_maybe); EVAL(rightop, RVAL, code, true_label, false_label); } @@ -625,12 +625,12 @@ EVAL(expr, val, code, true_label, false_label) EVAL(rightop, RVAL, TRUE, l_false, l_true); - C_ilb(l_false); + C_df_ilb(l_false); C_loc((arith)0); C_bra(l_end); - C_ilb(l_true); + C_df_ilb(l_true); C_loc((arith)1); - C_ilb(l_end); + C_df_ilb(l_end); } else EVAL(rightop, RVAL, FALSE, @@ -867,12 +867,12 @@ store_val(id, tp, offs) else if (df->df_sc == STATIC) { if (inword) - C_ste_ndlb((label)df->df_address, offs); + C_ste_dlb((label)df->df_address, offs); else if (indword) - C_sde_ndlb((label)df->df_address, offs); + C_sde_dlb((label)df->df_address, offs); else { - C_lae_ndlb((label)df->df_address, offs); + C_lae_dlb((label)df->df_address, offs); store_block(size, tpalign); } } @@ -960,18 +960,18 @@ load_val(expr, val) if (df->df_sc == STATIC) { if (rvalue) { if (size == word_size && al_on_word) - C_loe_ndlb((label)df->df_address, exval); + C_loe_dlb((label)df->df_address, exval); else if (size == dword_size && al_on_word) - C_lde_ndlb((label)df->df_address, exval); + C_lde_dlb((label)df->df_address, exval); else { - C_lae_ndlb((label)df->df_address, exval); + C_lae_dlb((label)df->df_address, exval); load_block(size, tpalign); } } else { - C_lae_ndlb((label)df->df_address, (arith)0); + C_lae_dlb((label)df->df_address, (arith)0); C_adp(exval); } } @@ -1018,11 +1018,11 @@ load_cst(val, siz) else { label datlab; - C_ndlb(datlab = data_label()); + C_df_dlb(datlab = data_label()); C_rom_begin(); - C_co_icon(itos(val), siz); + C_icon(itos(val), siz); C_rom_end(); - C_lae_ndlb(datlab, (arith)0); + C_lae_dlb(datlab, (arith)0); C_loi(siz); } } diff --git a/lang/cem/cemcom/ival.c b/lang/cem/cemcom/ival.c index 3a54e02a..67c29c40 100644 --- a/lang/cem/cemcom/ival.c +++ b/lang/cem/cemcom/ival.c @@ -23,7 +23,7 @@ extern char *symbol2str(); -#define con_byte(c) C_co_ucon(itos((long)(c) & 0xFF), (arith)1) +#define con_byte(c) C_ucon(itos((long)(c) & 0xFF), (arith)1) struct expr *do_array(), *do_struct(), *IVAL(); struct expr *strings = 0; /* list of string constants within initialiser */ @@ -49,9 +49,9 @@ do_ival(tpp, expr) */ C_con_end(); while (strings != 0) { - C_ndlb(strings->SG_DATLAB); + C_df_dlb(strings->SG_DATLAB); C_con_begin(); - C_co_scon(strings->SG_VALUE, (arith)0); + C_scon(strings->SG_VALUE, (arith)0); C_con_end(); strings = strings->next; } @@ -420,11 +420,11 @@ pad(tp) case CHAR: case ENUM: case POINTER: - C_co_ucon("0", tp->tp_size); + C_ucon("0", tp->tp_size); break; case FLOAT: case DOUBLE: - C_co_fcon("0", tp->tp_size); + C_fcon("0", tp->tp_size); break; case UNION: error("initialisation of unions not allowed"); @@ -499,12 +499,12 @@ check_ival(expr, type) ConStarted = 1; } if (expr->ex_class == Float) - C_co_fcon(expr->FL_VALUE, expr->ex_type->tp_size); + C_fcon(expr->FL_VALUE, expr->ex_type->tp_size); else if (expr->ex_class == Oper && expr->OP_OPER == INT2FLOAT) { expr = expr->OP_RIGHT; if (expr->ex_class == Value && expr->VL_IDF == 0) - C_co_fcon(itos(expr->VL_VALUE), type->tp_size); + C_fcon(itos(expr->VL_VALUE), type->tp_size); else illegal_init_cst(expr); } @@ -527,7 +527,7 @@ check_ival(expr, type) ConStarted = 1; /* ??? */ C_ina_pt(datlab); C_con_begin(); - C_co_ndlb(datlab, (arith)0); + C_dlb(datlab, (arith)0); expr->SG_DATLAB = datlab; store_string(expr); break; @@ -544,7 +544,7 @@ check_ival(expr, type) } if (expr->ex_type->tp_up->tp_fund == FUNCTION) { if (idf) - C_co_pnam(idf->id_text); + C_pnam(idf->id_text); else /* int (*func)() = 0 */ con_int(expr); } @@ -560,11 +560,11 @@ check_ival(expr, type) expr_error(expr, "illegal initialisation"); else - C_co_ndlb((label)def->df_address, + C_dlb((label)def->df_address, vl->vl_value); } else - C_co_dnam(idf->id_text, vl->vl_value); + C_dnam(idf->id_text, vl->vl_value); } else con_int(expr); @@ -767,9 +767,9 @@ con_int(expr) register struct type *tp = expr->ex_type; if (tp->tp_unsigned) - C_co_ucon(itos(expr->VL_VALUE), tp->tp_size); + C_ucon(itos(expr->VL_VALUE), tp->tp_size); else - C_co_icon(itos(expr->VL_VALUE), tp->tp_size); + C_icon(itos(expr->VL_VALUE), tp->tp_size); } illegal_init_cst(expr) diff --git a/lang/cem/cemcom/statement.g b/lang/cem/cemcom/statement.g index ea5cbfb3..e35ac980 100644 --- a/lang/cem/cemcom/statement.g +++ b/lang/cem/cemcom/statement.g @@ -92,7 +92,7 @@ label } */ define_label(idf); - C_ilb((label)idf->id_def->df_address); + C_df_ilb((label)idf->id_def->df_address); } ; @@ -116,7 +116,7 @@ if_statement been optimized to a 0 or 1. */ code_expr(expr, RVAL, TRUE, l_true, l_false); - C_ilb(l_true); + C_df_ilb(l_true); } else { if (expr->VL_VALUE == (arith)0) { @@ -131,14 +131,14 @@ if_statement ELSE { C_bra(l_end); - C_ilb(l_false); + C_df_ilb(l_false); } statement - { C_ilb(l_end); + { C_df_ilb(l_end); } | empty - { C_ilb(l_false); + { C_df_ilb(l_false); } ] ; @@ -154,7 +154,7 @@ while_statement WHILE { stat_stack(l_break, l_continue); - C_ilb(l_continue); + C_df_ilb(l_continue); } '(' expression(&expr) @@ -162,7 +162,7 @@ while_statement opnd2test(&expr, NOTEQUAL); if (expr->ex_class != Value) { code_expr(expr, RVAL, TRUE, l_body, l_break); - C_ilb(l_body); + C_df_ilb(l_body); } else { if (expr->VL_VALUE == (arith)0) { @@ -174,7 +174,7 @@ while_statement statement { C_bra(l_continue); - C_ilb(l_break); + C_df_ilb(l_break); stat_unstack(); free_expression(expr); } @@ -188,13 +188,13 @@ do_statement } : DO - { C_ilb(l_body); + { C_df_ilb(l_body); stat_stack(l_break, l_continue); } statement WHILE '(' - { C_ilb(l_continue); + { C_df_ilb(l_continue); } expression(&expr) { @@ -207,7 +207,7 @@ do_statement C_bra(l_body); } } - C_ilb(l_break); + C_df_ilb(l_break); } ')' ';' @@ -235,7 +235,7 @@ for_statement } ]? ';' - { C_ilb(l_test); + { C_df_ilb(l_test); } [ expression(&e_test) @@ -243,7 +243,7 @@ for_statement opnd2test(&e_test, NOTEQUAL); if (e_test->ex_class != Value) { code_expr(e_test, RVAL, TRUE, l_body, l_break); - C_ilb(l_body); + C_df_ilb(l_body); } else { if (e_test->VL_VALUE == (arith)0) { @@ -257,11 +257,11 @@ for_statement ')' statement { - C_ilb(l_continue); + C_df_ilb(l_continue); if (e_incr) code_expr(e_incr, RVAL, FALSE, NO_LABEL, NO_LABEL); C_bra(l_test); - C_ilb(l_break); + C_df_ilb(l_break); stat_unstack(); free_expression(e_init); free_expression(e_test); diff --git a/lang/cem/cemcom/switch.c b/lang/cem/cemcom/switch.c index 4ce1c181..39cd033a 100644 --- a/lang/cem/cemcom/switch.c +++ b/lang/cem/cemcom/switch.c @@ -53,43 +53,43 @@ code_endswitch() if (sh->sh_default == 0) /* no default occurred yet */ sh->sh_default = sh->sh_break; C_bra(sh->sh_break); /* skip the switch table now */ - C_ilb(sh->sh_table); /* switch table entry */ + C_df_ilb(sh->sh_table); /* switch table entry */ tablabel = data_label(); /* the rom must have a label */ - C_ndlb(tablabel); + C_df_dlb(tablabel); C_rom_begin(); - C_co_ilb(sh->sh_default); + C_ilb(sh->sh_default); if (compact(sh->sh_nrofentries, sh->sh_lowerbd, sh->sh_upperbd)) { /* CSA */ register arith val; - C_co_cst(sh->sh_lowerbd); - C_co_cst(sh->sh_upperbd - sh->sh_lowerbd); + C_cst(sh->sh_lowerbd); + C_cst(sh->sh_upperbd - sh->sh_lowerbd); ce = sh->sh_entries; for (val = sh->sh_lowerbd; val <= sh->sh_upperbd; val++) { ASSERT(ce); if (val == ce->ce_value) { - C_co_ilb(ce->ce_label); + C_ilb(ce->ce_label); ce = ce->next; } else - C_co_ilb(sh->sh_default); + C_ilb(sh->sh_default); } C_rom_end(); - C_lae_ndlb(tablabel, (arith)0); /* perform the switch */ + C_lae_dlb(tablabel, (arith)0); /* perform the switch */ C_csa(sh->sh_type->tp_size); } else { /* CSB */ - C_co_cst((arith)sh->sh_nrofentries); + C_cst((arith)sh->sh_nrofentries); for (ce = sh->sh_entries; ce; ce = ce->next) { /* generate the entries: value + prog.label */ - C_co_cst(ce->ce_value); - C_co_ilb(ce->ce_label); + C_cst(ce->ce_value); + C_ilb(ce->ce_label); } C_rom_end(); - C_lae_ndlb(tablabel, (arith)0); /* perform the switch */ + C_lae_dlb(tablabel, (arith)0); /* perform the switch */ C_csb(sh->sh_type->tp_size); } - C_ilb(sh->sh_break); + C_df_ilb(sh->sh_break); switch_stack = sh->next; /* unstack the switch descriptor */ /* free the allocated switch structure */ for (ce = sh->sh_entries; ce; ce = tmp) { @@ -111,7 +111,7 @@ code_case(val) return; } ce = new_case_entry(); - C_ilb(ce->ce_label = text_label()); + C_df_ilb(ce->ce_label = text_label()); ce->ce_value = val; if (sh->sh_entries == 0) { /* first case entry */ @@ -180,5 +180,5 @@ code_default() error("multiple entry for default in switch"); return; } - C_ilb(sh->sh_default = text_label()); + C_df_ilb(sh->sh_default = text_label()); } From 19dec458191d122751c481cdf3d9e2f28a49d08b Mon Sep 17 00:00:00 2001 From: erikb Date: Thu, 13 Mar 1986 13:27:44 +0000 Subject: [PATCH 0134/1625] simplified the EM con/rom functions (86/03/13) --- lang/cem/cemcom/code.c | 4 +-- lang/cem/cemcom/em.c | 24 ------------- lang/cem/cemcom/emcode.def | 45 ++++++++++++++--------- lang/cem/cemcom/eval.c | 12 ++----- lang/cem/cemcom/ival.c | 73 ++++++++++---------------------------- lang/cem/cemcom/switch.c | 19 +++++----- 6 files changed, 60 insertions(+), 117 deletions(-) diff --git a/lang/cem/cemcom/code.c b/lang/cem/cemcom/code.c index 77c530a1..788e4dbd 100644 --- a/lang/cem/cemcom/code.c +++ b/lang/cem/cemcom/code.c @@ -174,9 +174,7 @@ begin_proc(name, def) /* to be called when entering a procedure */ if (strcmp(last_fn_given, FileName) != 0) { /* previous function came from other file */ C_df_dlb(file_name_label = data_label()); - C_con_begin(); - C_scon(last_fn_given = FileName, (arith)0); - C_con_end(); + C_con_scon(last_fn_given = FileName, (arith)0); } /* enable debug trace of EM source */ C_fil_dlb(file_name_label, (arith)0); diff --git a/lang/cem/cemcom/em.c b/lang/cem/cemcom/em.c index 62c6024d..eb1131cc 100644 --- a/lang/cem/cemcom/em.c +++ b/lang/cem/cemcom/em.c @@ -61,30 +61,6 @@ C_busy() return ofd >= 0; /* true if code is being generated */ } -/*** front end for generating long CON/ROM lists ***/ -static arg_count; -static arg_rom; - -DC_start(rom){ - arg_count = 0; - arg_rom = rom; -} - -DC_check(){ - if (arg_count++ >= MAX_ARG_CNT) { - switch (arg_rom) { - case ps_con: - C_con_end(); - C_con_begin(); - break; - case ps_rom: - C_rom_end(); - C_rom_begin(); - break; - } - } -} - /*** the compact code generating routines ***/ #define fit16i(x) ((x) >= (long)0xFFFF8000 && (x) <= (long)0x00007FFF) #define fit8u(x) ((x) <= 0xFF) /* x is already unsigned */ diff --git a/lang/cem/cemcom/emcode.def b/lang/cem/cemcom/emcode.def index 5cc32d22..0e27dcc5 100644 --- a/lang/cem/cemcom/emcode.def +++ b/lang/cem/cemcom/emcode.def @@ -85,22 +85,35 @@ C_df_ilb(l) | label l; | ILB(l) C_bss_cst(n, w, i) | arith n, w; int i; | PS(ps_bss), DCST(n), CST(w), CST((arith)i) % -C_con_begin() | | DC_start(ps_con), PS(ps_con) -C_con_end() | | CEND() -C_rom_begin() | | DC_start(ps_rom), PS(ps_rom) -C_rom_end() | | CEND() -C_cst(l) | arith l; | DC_check(), CST(l) -C_icon(val, siz) | char *val; arith siz; | - DC_check(), WCON(sp_icon, val, siz) -C_ucon(val, siz) | char *val; arith siz; | - DC_check(), WCON(sp_ucon, val, siz) -C_fcon(val, siz) | char *val; arith siz; | - DC_check(), WCON(sp_fcon, val, siz) -C_scon(str, siz) | char *str; arith siz; | DC_check(), CSTR(str) -C_dnam(str, val) | char *str; arith val; | DC_check(), NOFF(str, val) -C_dlb(l, val) | label l; arith val; | DC_check(), DOFF(l, val) -C_pnam(str) | char *str; | DC_check(), PNAM(str) -C_ilb(l) | label l; | DC_check(), ILB(l) +C_con_icon(val, siz) | char *val; arith siz; | + PS(ps_con), WCON(sp_icon, val, siz), CEND() +C_con_ucon(val, siz) | char *val; arith siz; | + PS(ps_con), WCON(sp_ucon, val, siz), CEND() +C_con_fcon(val, siz) | char *val; arith siz; | + PS(ps_con), WCON(sp_fcon, val, siz), CEND() +C_con_scon(str, siz) | char *str; arith siz; | PS(ps_con), CSTR(str), CEND() +C_con_dnam(str, val) | char *str; arith val; | + PS(ps_con), NOFF(str, val), CEND() +C_con_dlb(l, val) | label l; arith val; | + PS(ps_con), DOFF(l, val), CEND() +C_con_pnam(str) | char *str; | PS(ps_con), PNAM(str), CEND() +% +C_rom_cst(l) | arith l; | PS(ps_rom), CST(l), CEND() +C_rom_icon(val, siz) | char *val; arith siz; | + PS(ps_rom), WCON(sp_icon, val, siz), CEND() +C_rom_fcon(val, siz) | char *val; arith siz; | + PS(ps_rom), WCON(sp_fcon, val, siz), CEND() +C_rom_ilb(l) | label l; | PS(ps_rom), ILB(l), CEND() +% +C_cst(l) | arith l; | CST(l) +C_icon(val, siz) | char *val; arith siz; | WCON(sp_icon, val, siz) +C_ucon(val, siz) | char *val; arith siz; | WCON(sp_ucon, val, siz) +C_fcon(val, siz) | char *val; arith siz; | WCON(sp_fcon, val, siz) +C_scon(str, siz) | char *str; arith siz; | CSTR(str) +C_dnam(str, val) | char *str; arith val; | NOFF(str, val) +C_dlb(l, val) | label l; arith val; | DOFF(l, val) +C_pnam(str) | char *str; | PNAM(str) +C_ilb(l) | label l; | ILB(l) % C_pro_narg(p1) | char *p1; | PS(ps_pro), PNAM(p1), CEND() C_end(l) | arith l; | PS(ps_end), CST(l) diff --git a/lang/cem/cemcom/eval.c b/lang/cem/cemcom/eval.c index a0868ebc..d3e38a5e 100644 --- a/lang/cem/cemcom/eval.c +++ b/lang/cem/cemcom/eval.c @@ -88,9 +88,7 @@ EVAL(expr, val, code, true_label, false_label) label datlab = data_label(); C_df_dlb(datlab); - C_con_begin(); - C_scon(expr->SG_VALUE, (arith)0); - C_con_end(); + C_con_scon(expr->SG_VALUE, (arith)0); C_lae_dlb(datlab, (arith)0); } break; @@ -100,9 +98,7 @@ EVAL(expr, val, code, true_label, false_label) label datlab = data_label(); C_df_dlb(datlab); - C_rom_begin(); - C_fcon(expr->FL_VALUE, expr->ex_type->tp_size); - C_rom_end(); + C_rom_fcon(expr->FL_VALUE, expr->ex_type->tp_size); C_lae_dlb(datlab, (arith)0); C_loi(expr->ex_type->tp_size); } @@ -1019,9 +1015,7 @@ load_cst(val, siz) label datlab; C_df_dlb(datlab = data_label()); - C_rom_begin(); - C_icon(itos(val), siz); - C_rom_end(); + C_rom_icon(itos(val), siz); C_lae_dlb(datlab, (arith)0); C_loi(siz); } diff --git a/lang/cem/cemcom/ival.c b/lang/cem/cemcom/ival.c index 67c29c40..baf2b5e6 100644 --- a/lang/cem/cemcom/ival.c +++ b/lang/cem/cemcom/ival.c @@ -23,11 +23,10 @@ extern char *symbol2str(); -#define con_byte(c) C_ucon(itos((long)(c) & 0xFF), (arith)1) +#define con_byte(c) C_con_ucon(itos((long)(c) & 0xFF), (arith)1) struct expr *do_array(), *do_struct(), *IVAL(); struct expr *strings = 0; /* list of string constants within initialiser */ -static ConStarted; /* indicates the generation of a 'con' pseudo */ /* do_ival() performs the initialisation of a global variable of type tp with the initialisation expression expr by calling IVAL(). @@ -37,9 +36,9 @@ do_ival(tpp, expr) struct type **tpp; struct expr *expr; { - ConStarted = 0; if (IVAL(tpp, expr) != 0) too_many_initialisers(expr); + /* The following loop declares the string constants used in the initialisation. The code for these string constants may not appear in @@ -47,12 +46,9 @@ do_ival(tpp, expr) in EM causes the current initialisation to be completed. E.g. char *s[] = {"hello", "world"}; */ - C_con_end(); while (strings != 0) { C_df_dlb(strings->SG_DATLAB); - C_con_begin(); - C_scon(strings->SG_VALUE, (arith)0); - C_con_end(); + C_con_scon(strings->SG_VALUE, (arith)0); strings = strings->next; } } @@ -341,8 +337,7 @@ check_and_pad(expr, tpp) /* no size specified upto here: just set it to the size of one member. */ - tp = *tpp = - construct_type(ARRAY, tp->tp_up, (arith)1); + tp = *tpp = construct_type(ARRAY, tp->tp_up, (arith)1); else { register dim = tp->tp_size / tp->tp_up->tp_size; /* pad remaining members with zeroes */ @@ -376,10 +371,6 @@ check_and_pad(expr, tpp) pad(tp) struct type *tp; { - if (ConStarted == 0) { - C_con_begin(); - ConStarted = 1; - } switch (tp->tp_fund) { case ARRAY: { @@ -420,11 +411,11 @@ pad(tp) case CHAR: case ENUM: case POINTER: - C_ucon("0", tp->tp_size); + C_con_ucon("0", tp->tp_size); break; case FLOAT: case DOUBLE: - C_fcon("0", tp->tp_size); + C_con_fcon("0", tp->tp_size); break; case UNION: error("initialisation of unions not allowed"); @@ -463,10 +454,6 @@ check_ival(expr, type) break; } ch7cast(&expr, '=', type); - if (ConStarted == 0) { - C_con_begin(); - ConStarted = 1; - } con_int(expr); break; #ifndef NOBITFIELD @@ -485,26 +472,18 @@ check_ival(expr, type) break; } ch7cast(&expr, '=', type); - if (ConStarted == 0) { - C_con_begin(); - ConStarted = 1; - } con_int(expr); break; case FLOAT: case DOUBLE: ch7cast(&expr, '=', type); - if (ConStarted == 0) { - C_con_begin(); - ConStarted = 1; - } if (expr->ex_class == Float) - C_fcon(expr->FL_VALUE, expr->ex_type->tp_size); + C_con_fcon(expr->FL_VALUE, expr->ex_type->tp_size); else if (expr->ex_class == Oper && expr->OP_OPER == INT2FLOAT) { expr = expr->OP_RIGHT; if (expr->ex_class == Value && expr->VL_IDF == 0) - C_fcon(itos(expr->VL_VALUE), type->tp_size); + C_con_fcon(itos(expr->VL_VALUE), type->tp_size); else illegal_init_cst(expr); } @@ -521,13 +500,8 @@ check_ival(expr, type) { label datlab = data_label(); - if (ConStarted) - C_con_end(); - else - ConStarted = 1; /* ??? */ C_ina_pt(datlab); - C_con_begin(); - C_dlb(datlab, (arith)0); + C_con_dlb(datlab, (arith)0); expr->SG_DATLAB = datlab; store_string(expr); break; @@ -538,13 +512,9 @@ check_ival(expr, type) struct idf *idf = vl->vl_idf; ASSERT(expr->ex_type->tp_fund == POINTER); - if (ConStarted == 0) { - C_con_begin(); - ConStarted = 1; - } if (expr->ex_type->tp_up->tp_fund == FUNCTION) { if (idf) - C_pnam(idf->id_text); + C_con_pnam(idf->id_text); else /* int (*func)() = 0 */ con_int(expr); } @@ -558,13 +528,16 @@ check_ival(expr, type) static int *p = &a; */ expr_error(expr, - "illegal initialisation"); + "illegal initialisation" + ); else - C_dlb((label)def->df_address, - vl->vl_value); + C_con_dlb( + (label)def->df_address, + vl->vl_value + ); } else - C_dnam(idf->id_text, vl->vl_value); + C_con_dnam(idf->id_text, vl->vl_value); } else con_int(expr); @@ -611,10 +584,6 @@ init_string(tpp, expr) expr_error(expr, "too many characters in initialiser string"); } - if (ConStarted == 0) { - C_con_begin(); - ConStarted = 1; - } /* throw out the characters of the already prepared string */ do con_byte(*s++); @@ -721,10 +690,6 @@ put_bf(tp, val) if (sd->sd_sdef == 0 || sd->sd_sdef->sd_offset != offset) { /* the selector was the last stored at this address */ expr.VL_VALUE = field; - if (ConStarted == 0) { - C_con_begin(); - ConStarted = 1; - } con_int(&expr); field = (arith)0; offset = (arith)-1; @@ -767,9 +732,9 @@ con_int(expr) register struct type *tp = expr->ex_type; if (tp->tp_unsigned) - C_ucon(itos(expr->VL_VALUE), tp->tp_size); + C_con_ucon(itos(expr->VL_VALUE), tp->tp_size); else - C_icon(itos(expr->VL_VALUE), tp->tp_size); + C_con_icon(itos(expr->VL_VALUE), tp->tp_size); } illegal_init_cst(expr) diff --git a/lang/cem/cemcom/switch.c b/lang/cem/cemcom/switch.c index 39cd033a..8a695de2 100644 --- a/lang/cem/cemcom/switch.c +++ b/lang/cem/cemcom/switch.c @@ -56,36 +56,33 @@ code_endswitch() C_df_ilb(sh->sh_table); /* switch table entry */ tablabel = data_label(); /* the rom must have a label */ C_df_dlb(tablabel); - C_rom_begin(); - C_ilb(sh->sh_default); + C_rom_ilb(sh->sh_default); if (compact(sh->sh_nrofentries, sh->sh_lowerbd, sh->sh_upperbd)) { /* CSA */ register arith val; - C_cst(sh->sh_lowerbd); - C_cst(sh->sh_upperbd - sh->sh_lowerbd); + C_rom_cst(sh->sh_lowerbd); + C_rom_cst(sh->sh_upperbd - sh->sh_lowerbd); ce = sh->sh_entries; for (val = sh->sh_lowerbd; val <= sh->sh_upperbd; val++) { ASSERT(ce); if (val == ce->ce_value) { - C_ilb(ce->ce_label); + C_rom_ilb(ce->ce_label); ce = ce->next; } else - C_ilb(sh->sh_default); + C_rom_ilb(sh->sh_default); } - C_rom_end(); C_lae_dlb(tablabel, (arith)0); /* perform the switch */ C_csa(sh->sh_type->tp_size); } else { /* CSB */ - C_cst((arith)sh->sh_nrofentries); + C_rom_cst((arith)sh->sh_nrofentries); for (ce = sh->sh_entries; ce; ce = ce->next) { /* generate the entries: value + prog.label */ - C_cst(ce->ce_value); - C_ilb(ce->ce_label); + C_rom_cst(ce->ce_value); + C_rom_ilb(ce->ce_label); } - C_rom_end(); C_lae_dlb(tablabel, (arith)0); /* perform the switch */ C_csb(sh->sh_type->tp_size); } From acfe96c32c9003a406023c94b430b0991b193995 Mon Sep 17 00:00:00 2001 From: dick Date: Fri, 14 Mar 1986 16:15:16 +0000 Subject: [PATCH 0135/1625] improved error reporting for initialization expressions miscellaneous changes --- lang/cem/cemcom/arith.c | 19 +++++++--- lang/cem/cemcom/ch7.c | 6 +--- lang/cem/cemcom/ch7bin.c | 8 ++--- lang/cem/cemcom/ch7mon.c | 7 ++-- lang/cem/cemcom/code.c | 14 ++++++-- lang/cem/cemcom/cstoper.c | 4 +-- lang/cem/cemcom/eval.c | 4 +-- lang/cem/cemcom/expr.c | 70 +++++++++++++++++++++++++++--------- lang/cem/cemcom/expr.str | 13 ------- lang/cem/cemcom/expression.g | 2 +- lang/cem/cemcom/idf.c | 4 +-- lang/cem/cemcom/ival.c | 70 ++++++++++++++++++------------------ lang/cem/cemcom/statement.g | 60 +++++++++++++++---------------- lang/cem/cemcom/struct.c | 2 +- lang/cem/cemcom/switch.c | 50 +++++++++++++++++++------- 15 files changed, 197 insertions(+), 136 deletions(-) diff --git a/lang/cem/cemcom/arith.c b/lang/cem/cemcom/arith.c index 04f843a2..3b780bcf 100644 --- a/lang/cem/cemcom/arith.c +++ b/lang/cem/cemcom/arith.c @@ -164,14 +164,23 @@ any2arith(expp, oper) error("operator %s on non-numerical operand (%s)", symbol2str(oper), symbol2str(fund)); case ERRONEOUS: - free_expression(*expp); - *expp = intexpr((arith)1, INT); + erroneous2int(expp); break; } return (*expp)->ex_type->tp_fund; } +erroneous2int(expp) + struct expr **expp; +{ + /* the (erroneous) expression *expp is replaced by an + int expression + */ + free_expression(*expp); + *expp = intexpr((arith)0, INT); +} + struct expr * arith2arith(tp, oper, expr) struct type *tp; @@ -247,7 +256,7 @@ float2float(expp, tp) */ fp_used = 1; - if ((*expp)->ex_class == Float) { + if (is_fp_cst(*expp)) { (*expp)->ex_type = tp; } else { @@ -285,7 +294,7 @@ opnd2integral(expp, oper) if (fund != ERRONEOUS) error("%s operand to %s", symbol2str(fund), symbol2str(oper)); - *expp = intexpr((arith)1, INT); + erroneous2int(expp); /* fund = INT; */ } } @@ -321,7 +330,7 @@ opnd2logical(expp, oper) error("%s operand to %s", symbol2str(fund), symbol2str(oper)); case ERRONEOUS: - *expp = intexpr((arith)1, INT); + erroneous2int(expp); break; } } diff --git a/lang/cem/cemcom/ch7.c b/lang/cem/cemcom/ch7.c index 38fcbc21..2a6d564f 100644 --- a/lang/cem/cemcom/ch7.c +++ b/lang/cem/cemcom/ch7.c @@ -13,10 +13,6 @@ #include "Lpars.h" #include "assert.h" -#define is_zero(ex) \ - ((ex)->ex_class == Value && (ex)->VL_VALUE == (arith)0 && \ - (ex)->VL_IDF == 0) - extern char options[]; extern char *symbol2str(); @@ -262,7 +258,7 @@ ch7cast(expp, oper, tp) case NOTEQUAL: case '=': case RETURN: - if (is_zero(*expp)) + if (is_cp_cst(*expp) && (*expp)->VL_VALUE == (arith)0) break; default: warning("illegal conversion of %s to pointer", diff --git a/lang/cem/cemcom/ch7bin.c b/lang/cem/cemcom/ch7bin.c index ee30b03d..469a01e6 100644 --- a/lang/cem/cemcom/ch7bin.c +++ b/lang/cem/cemcom/ch7bin.c @@ -82,7 +82,7 @@ ch7bin(expp, oper, expr) fund = arithbalance(expp, oper, &expr); if (fund == DOUBLE) { error("floating operand to %%"); - *expp = intexpr((arith)1, INT); + erroneous2int(expp); } else non_commutative_binop(expp, oper, expr); @@ -235,8 +235,7 @@ pntminuspnt(expp, oper, expr) if (up_type != expr->ex_type->tp_up) { error("subtracting incompatible pointers"); free_expression(expr); - free_expression(*expp); - *expp = intexpr((arith)0, INT); + erroneous2int(expp); return; } /* we hope the optimizer will eliminate the load-time @@ -285,8 +284,7 @@ pointer_arithmetic(expp1, oper, expp2) if (any2arith(expp2, oper) == DOUBLE) { expr_error(*expp2, "illegal combination of float and pointer"); - free_expression(*expp2); - *expp2 = intexpr((arith)0, INT); + erroneous2int(expp2); } ch7bin( expp2, '*', intexpr(size_of_type((*expp1)->ex_type->tp_up, "object"), diff --git a/lang/cem/cemcom/ch7mon.c b/lang/cem/cemcom/ch7mon.c index 061db817..3c25f375 100644 --- a/lang/cem/cemcom/ch7mon.c +++ b/lang/cem/cemcom/ch7mon.c @@ -76,7 +76,7 @@ ch7mon(oper, expp) be used as register anymore */ if (def->df_sc == REGISTER) { - error("'&' on register variable not allowed"); + error("& on register variable not allowed"); (*expp)->ex_type = error_type; break; /* break case '&' */ } @@ -91,8 +91,9 @@ ch7mon(oper, expp) int fund = (*expp)->ex_type->tp_fund; if (fund == FLOAT || fund == DOUBLE) { - error("~ not allowed on %s operands", symbol2str(fund)); - *expp = intexpr((arith)1, INT); + error("~ not allowed on %s operands", + symbol2str(fund)); + erroneous2int(expp); break; } } diff --git a/lang/cem/cemcom/code.c b/lang/cem/cemcom/code.c index 788e4dbd..1d0df57a 100644 --- a/lang/cem/cemcom/code.c +++ b/lang/cem/cemcom/code.c @@ -18,7 +18,7 @@ #include "em.h" #include "level.h" #include "decspecs.h" -#include "declar.h" +#include "declarator.h" #include "Lpars.h" #include "mes.h" #include "LLlex.h" @@ -227,6 +227,13 @@ end_proc(fbytes, nbytes) C_end(ATW(nbytes)); } +do_return() +{ + /* do_return generates a direct return */ + /* isn't a jump to the return label smarter ??? */ + C_ret((arith)0); +} + do_return_expr(expr) struct expr *expr; { @@ -303,10 +310,11 @@ code_declaration(idf, expr, lvl, sc) do_ival(&(def->df_type), expr); else { /* produce blank space */ if (size <= 0) { - error("size of \"%s\" unknown", text); + error("size of %s unknown", text); size = (arith)0; } - C_bss_cst(align(size, word_align), (arith)0, 1); + C_bss_cst(align(size, word_align), + (arith)0, 1); } break; case EXTERN: diff --git a/lang/cem/cemcom/cstoper.c b/lang/cem/cemcom/cstoper.c index 414e18d6..9b4e09eb 100644 --- a/lang/cem/cemcom/cstoper.c +++ b/lang/cem/cemcom/cstoper.c @@ -34,7 +34,7 @@ cstbin(expp, oper, expr) break; case '/': if (o2 == 0) { - error("division by 0"); + expr_error(expr, "division by 0"); break; } if (uns) { @@ -71,7 +71,7 @@ cstbin(expp, oper, expr) break; case '%': if (o2 == 0) { - error("modulo by 0"); + expr_error(expr, "modulo by 0"); break; } if (uns) { diff --git a/lang/cem/cemcom/eval.c b/lang/cem/cemcom/eval.c index d3e38a5e..094cf625 100644 --- a/lang/cem/cemcom/eval.c +++ b/lang/cem/cemcom/eval.c @@ -180,7 +180,7 @@ EVAL(expr, val, code, true_label, false_label) C_sbi(tp->tp_size); break; case POINTER: - if (EXPRTYPE(rightop) == POINTER) + if (rightop->ex_type->tp_fund == POINTER) C_sbs(pointer_size); else { C_ngi(rightop->ex_type->tp_size); @@ -645,7 +645,7 @@ EVAL(expr, val, code, true_label, false_label) conversion(rightop->ex_type, leftop->ex_type); break; default: - crash("(EVAL) Bad operator %s\n", symbol2str(oper)); + crash("(EVAL) bad operator %s\n", symbol2str(oper)); } /* If the rvalue of the expression is required but diff --git a/lang/cem/cemcom/expr.c b/lang/cem/cemcom/expr.c index 72c43ef7..12760689 100644 --- a/lang/cem/cemcom/expr.c +++ b/lang/cem/cemcom/expr.c @@ -12,7 +12,7 @@ #include "LLlex.h" #include "Lpars.h" #include "decspecs.h" -#include "declar.h" +#include "declarator.h" #include "storage.h" #include "sizes.h" @@ -212,21 +212,18 @@ intexpr(ivalue, fund) the size indicated by fund. */ struct expr *expr = new_expr(); - + clear((char *)expr, sizeof(struct expr)); expr->ex_file = dot.tk_file; expr->ex_line = dot.tk_line; - + switch (fund) { - case INT: expr->ex_type = int_type; break; - case LONG: expr->ex_type = long_type; break; - case UNSIGNED: /* We cannot make a test like "ivalue <= max_unsigned" because, if sizeof(long) == int_size holds, max_unsigned @@ -237,17 +234,15 @@ intexpr(ivalue, fund) expr->ex_type = (ivalue & ~max_unsigned) ? long_type : uint_type; break; - case INTEGER: expr->ex_type = (ivalue <= max_int) ? int_type : long_type; break; - default: crash("(intexpr) bad fund %s\n", symbol2str(fund)); } expr->ex_class = Value; expr->VL_VALUE = ivalue; - + cut_size(expr); return expr; } @@ -279,13 +274,26 @@ new_oper(tp, e1, oper, e2) struct oper *op; clear((char *)expr, sizeof(struct expr)); - if (!e1 || !e2) { - expr->ex_file = dot.tk_file; - expr->ex_line = dot.tk_line; + if (e2) { + struct expr *e = e2; + + while (e->ex_class == Oper && e->OP_LEFT) + e = e->OP_LEFT; + expr->ex_file = e->ex_file; + expr->ex_line = e->ex_line; + } + else + if (e1) { + struct expr *e = e1; + + while (e->ex_class == Oper && e->OP_RIGHT) + e = e->OP_RIGHT; + expr->ex_file = e->ex_file; + expr->ex_line = e->ex_line; } else { - expr->ex_file = e2->ex_file; - expr->ex_line = e2->ex_line; + expr->ex_file = dot.tk_file; + expr->ex_line = dot.tk_line; } expr->ex_type = tp; expr->ex_class = Oper; @@ -333,7 +341,7 @@ chk_cst_expr(expp) are cast, logical operators and the expression comma. Special problems (of which there is only one, sizeof in Preprocessor #if) have to be dealt with locally - + Note that according to K&R the negation ! is illegal in constant expressions and is indeed rejected by the Ritchie compiler. @@ -369,7 +377,7 @@ chk_cst_expr(expp) if (err) { free_expression(expr); - *expp = intexpr((arith)1, INT); + erroneous2int(expp); (*expp)->ex_type = error_type; } } @@ -393,6 +401,36 @@ init_expression(eppp, expr) *eppp = &(**eppp)->OP_RIGHT; } +int +is_ld_cst(expr) + register struct expr *expr; +{ + /* An expression is a `load-time constant' if it is of the form + +/- or . + */ + return expr->ex_lvalue == 0 && expr->ex_class == Value; +} + +int +is_cp_cst(expr) + register struct expr *expr; +{ + /* An expression is a `compile-time constant' if it is a + load-time constant, and the idf is not there. + */ + return is_ld_cst(expr) && expr->VL_IDF == 0; +} + +int +is_fp_cst(expr) + register struct expr *expr; +{ + /* An expression is a `floating-point constant' if it consists + of the float only. + */ + return expr->ex_class == Float; +} + free_expression(expr) struct expr *expr; { diff --git a/lang/cem/cemcom/expr.str b/lang/cem/cemcom/expr.str index 87f61142..b322e899 100644 --- a/lang/cem/cemcom/expr.str +++ b/lang/cem/cemcom/expr.str @@ -63,19 +63,6 @@ struct expr { #define OP_OPER ex_object.ex_oper.op_oper #define OP_RIGHT ex_object.ex_oper.op_right -#define EXPRTYPE(e) ((e)->ex_type->tp_fund) - -/* An expression is a `load-time constant' if it is of the form - +/- or ; - it is a `compile-time constant' if it is an . -*/ -#define is_ld_cst(e) ((e)->ex_lvalue == 0 && (e)->ex_class == Value) -#define is_cp_cst(e) (is_ld_cst(e) && (e)->VL_IDF == 0) - -/* a floating constant expression ? -*/ -#define is_fp_cst(e) ((e)->ex_class == Float) - /* some bits for the ex_flag field, to keep track of various interesting properties of an expression. */ diff --git a/lang/cem/cemcom/expression.g b/lang/cem/cemcom/expression.g index 94976c64..9d9a4fdb 100644 --- a/lang/cem/cemcom/expression.g +++ b/lang/cem/cemcom/expression.g @@ -231,7 +231,7 @@ conditional_expression(struct expr **expp;) {check_conditional(e2, '=', "after :");} { ch7bin(&e1, ':', e2); - opnd2test(expp, NOTEQUAL); + opnd2test(expp, '?'); ch7bin(expp, '?', e1); } ]? diff --git a/lang/cem/cemcom/idf.c b/lang/cem/cemcom/idf.c index 9739c8a3..14868764 100644 --- a/lang/cem/cemcom/idf.c +++ b/lang/cem/cemcom/idf.c @@ -16,7 +16,7 @@ #include "def.h" #include "type.h" #include "struct.h" -#include "declar.h" +#include "declarator.h" #include "decspecs.h" #include "sizes.h" #include "Lpars.h" @@ -333,7 +333,7 @@ declare_idf(ds, dc, lvl) case REGISTER: case AUTO: if (type->tp_size == (arith)-1) { - error("size of local \"%s\" unknown", + error("size of local %s unknown", idf->id_text); type = idf->id_def->df_type = int_type; } diff --git a/lang/cem/cemcom/ival.c b/lang/cem/cemcom/ival.c index baf2b5e6..3a5efa36 100644 --- a/lang/cem/cemcom/ival.c +++ b/lang/cem/cemcom/ival.c @@ -84,7 +84,8 @@ IVAL(tpp, expr) register struct type *tp = *tpp; switch (tp->tp_fund) { - case ARRAY: /* array initialisation */ + case ARRAY: + /* array initialisation */ if (valid_type(tp->tp_up, "array element") == 0) return 0; if (ISCOMMA(expr)) { @@ -96,10 +97,13 @@ IVAL(tpp, expr) */ if (tp->tp_up->tp_fund == CHAR && expr->ex_class == String) init_string(tpp, expr); - else /* " int i[24] = 12;" */ + else { + /* " int i[24] = 12;" */ check_and_pad(expr, tpp); + } return 0; /* nothing left */ - case STRUCT: /* struct initialisation */ + case STRUCT: + /* struct initialisation */ if (valid_type(tp, "struct") == 0) return 0; if (ISCOMMA(expr)) { @@ -109,13 +113,16 @@ IVAL(tpp, expr) /* "struct foo f = 12;" */ check_and_pad(expr, tpp); return 0; - case UNION: /* sorry, but .... */ + case UNION: + /* sorry, but .... */ error("union initialisation not allowed"); return 0; case ERRONEOUS: return 0; - default: /* fundamental type */ - if (ISCOMMA(expr)) { /* " int i = {12};" */ + default: + /* fundamental type */ + if (ISCOMMA(expr)) { + /* " int i = {12};" */ if (IVAL(tpp, expr->OP_LEFT) != 0) too_many_initialisers(expr); /* return remainings of the list for the @@ -124,10 +131,9 @@ IVAL(tpp, expr) */ return expr->OP_RIGHT; } - else { /* "int i = 12;" */ - check_ival(expr, tp); - return 0; - } + /* "int i = 12;" */ + check_ival(expr, tp); + return 0; } /* NOTREACHED */ } @@ -149,15 +155,14 @@ do_array(expr, tpp) struct expr *expr; struct type **tpp; { - /* it is certain that ISCOMMA(expr) and tp->tp_fund == ARRAY */ register struct type *tp = *tpp; register arith elem_count; - ASSERT(tp->tp_fund == ARRAY); + ASSERT(tp->tp_fund == ARRAY && ISCOMMA(expr)); /* the following test catches initialisations like char c[] = {"just a string"}; or - char d[] = {{"just another string"}} + char d[] = {{"just another string"}}; The use of the brackets causes this problem. Note: although the implementation of such initialisations is completely foolish, we did it!! (no applause, thank you) @@ -249,12 +254,11 @@ do_struct(expr, tp) struct expr *expr; struct type *tp; { - /* tp is a STRUCT and expr->OP_OPER == INITCOMMA */ - struct sdef *sd = tp->tp_sdef; arith bytes_upto_here = (arith)0; arith last_offset = (arith)-1; - + + ASSERT(tp->tp_fund == STRUCT && ISCOMMA(expr)); /* as long as there are selectors and there is an initialiser.. */ while (sd && expr) { if (ISCOMMA(expr->OP_LEFT)) { /* embraced expression */ @@ -292,7 +296,8 @@ do_struct(expr, tp) bytes_upto_here += zero_bytes(sd); if (last_offset != sd->sd_offset) { /* don't take the field-width more than once */ - bytes_upto_here += size_of_type(sd->sd_type, "selector"); + bytes_upto_here += + size_of_type(sd->sd_type, "selector"); last_offset = sd->sd_offset; } sd = sd->sd_sdef; @@ -308,7 +313,8 @@ do_struct(expr, tp) if (sd->sd_sdef) bytes_upto_here += zero_bytes(sd); /* no field thrown-outs here */ - bytes_upto_here += size_of_type(sd->sd_type, "selector"); + bytes_upto_here += + size_of_type(sd->sd_type, "selector"); } while (sd = sd->sd_sdef); } /* keep on aligning... */ @@ -440,8 +446,8 @@ check_ival(expr, type) { /* The philosophy here is that ch7cast puts an explicit conversion node in front of the expression if the types - are not compatible. In this case, the initialisation is - not legal. ??? + are not compatible. In this case, the initialisation + expression is no longer a constant. */ switch (type->tp_fund) { @@ -449,31 +455,24 @@ check_ival(expr, type) case SHORT: case INT: case LONG: - if (expr->ex_class == Oper || expr->VL_IDF != 0) { + case ENUM: + ch7cast(&expr, '=', type); + if (expr->ex_class != Value || expr->VL_IDF != 0) { illegal_init_cst(expr); break; } - ch7cast(&expr, '=', type); con_int(expr); break; #ifndef NOBITFIELD case FIELD: - if (expr->ex_class == Oper || expr->VL_IDF != 0) { + ch7cast(&expr, '=', type->tp_up); + if (expr->ex_class != Value || expr->VL_IDF != 0) { illegal_init_cst(expr); break; } - ch7cast(&expr, '=', type->tp_up); put_bf(type, expr->VL_VALUE); break; #endif NOBITFIELD - case ENUM: - if (expr->ex_class == Oper) { - illegal_init_cst(expr); - break; - } - ch7cast(&expr, '=', type); - con_int(expr); - break; case FLOAT: case DOUBLE: ch7cast(&expr, '=', type); @@ -482,10 +481,11 @@ check_ival(expr, type) else if (expr->ex_class == Oper && expr->OP_OPER == INT2FLOAT) { expr = expr->OP_RIGHT; - if (expr->ex_class == Value && expr->VL_IDF == 0) - C_con_fcon(itos(expr->VL_VALUE), type->tp_size); - else + if (expr->ex_class != Value || expr->VL_IDF != 0) { illegal_init_cst(expr); + break; + } + C_con_fcon(itos(expr->VL_VALUE), type->tp_size); } else illegal_init_cst(expr); diff --git a/lang/cem/cemcom/statement.g b/lang/cem/cemcom/statement.g index e35ac980..af127420 100644 --- a/lang/cem/cemcom/statement.g +++ b/lang/cem/cemcom/statement.g @@ -108,20 +108,19 @@ if_statement '(' expression(&expr) { - opnd2test(&expr, NOTEQUAL); - if (expr->ex_class != Value) { - /* What's happening here? If the - expression consisted of a constant - expression, the comparison has - been optimized to a 0 or 1. + opnd2test(&expr, IF); + if (is_cp_cst(expr)) { + /* The comparison has been optimized + to a 0 or 1. */ - code_expr(expr, RVAL, TRUE, l_true, l_false); - C_df_ilb(l_true); - } - else { if (expr->VL_VALUE == (arith)0) { C_bra(l_false); } + /* else fall through */ + } + else { + code_expr(expr, RVAL, TRUE, l_true, l_false); + C_df_ilb(l_true); } free_expression(expr); } @@ -159,16 +158,16 @@ while_statement '(' expression(&expr) { - opnd2test(&expr, NOTEQUAL); - if (expr->ex_class != Value) { - code_expr(expr, RVAL, TRUE, l_body, l_break); - C_df_ilb(l_body); - } - else { + opnd2test(&expr, WHILE); + if (is_cp_cst(expr)) { if (expr->VL_VALUE == (arith)0) { C_bra(l_break); } } + else { + code_expr(expr, RVAL, TRUE, l_body, l_break); + C_df_ilb(l_body); + } } ')' statement @@ -198,15 +197,15 @@ do_statement } expression(&expr) { - opnd2test(&expr, NOTEQUAL); - if (expr->ex_class != Value) { - code_expr(expr, RVAL, TRUE, l_body, l_break); - } - else { + opnd2test(&expr, WHILE); + if (is_cp_cst(expr)) { if (expr->VL_VALUE == (arith)1) { C_bra(l_body); } } + else { + code_expr(expr, RVAL, TRUE, l_body, l_break); + } C_df_ilb(l_break); } ')' @@ -240,16 +239,16 @@ for_statement [ expression(&e_test) { - opnd2test(&e_test, NOTEQUAL); - if (e_test->ex_class != Value) { - code_expr(e_test, RVAL, TRUE, l_body, l_break); - C_df_ilb(l_body); - } - else { + opnd2test(&e_test, FOR); + if (is_cp_cst(e_test)) { if (e_test->VL_VALUE == (arith)0) { C_bra(l_break); } } + else { + code_expr(e_test, RVAL, TRUE, l_body, l_break); + C_df_ilb(l_body); + } } ]? ';' @@ -276,9 +275,8 @@ switch_statement : SWITCH '(' - expression(&expr) /* this must be an integer expression! */ + expression(&expr) { - ch7cast(&expr, CAST, int_type); code_startswitch(expr); } ')' @@ -297,7 +295,7 @@ case_statement CASE constant_expression(&expr) { - code_case(expr->VL_VALUE); + code_case(expr); free_expression(expr); } ':' @@ -348,7 +346,7 @@ return_statement | empty { - C_ret((arith)0); + do_return(); } ] ';' diff --git a/lang/cem/cemcom/struct.c b/lang/cem/cemcom/struct.c index 752bcdf8..6b194587 100644 --- a/lang/cem/cemcom/struct.c +++ b/lang/cem/cemcom/struct.c @@ -396,7 +396,7 @@ add_field(szp, fd, pfd_type, idf, stp) case LONG: /* right type; size OK? */ if ((*pfd_type)->tp_size > word_size) { - error("bit field type %s doesn't fit in word", + error("bit field type %s does not fit in a word", symbol2str((*pfd_type)->tp_fund)); *pfd_type = error_type; return field_offset; diff --git a/lang/cem/cemcom/switch.c b/lang/cem/cemcom/switch.c index 8a695de2..ba0c7458 100644 --- a/lang/cem/cemcom/switch.c +++ b/lang/cem/cemcom/switch.c @@ -5,6 +5,7 @@ #include "botch_free.h" #include "density.h" +#include "Lpars.h" #include "idf.h" #include "label.h" #include "arith.h" @@ -16,6 +17,8 @@ #include "type.h" #include "em.h" +extern char options[]; + #define compact(nr, low, up) (nr != 0 && (up - low) / nr <= (DENSITY - 1)) static struct switch_hdr *switch_stack = 0; @@ -23,19 +26,32 @@ static struct switch_hdr *switch_stack = 0; code_startswitch(expr) struct expr *expr; { - /* stack a new case header and fill in the necessary fields. + /* Check the expression, stack a new case header and + fill in the necessary fields. */ register label l_table = text_label(); register label l_break = text_label(); register struct switch_hdr *sh = new_switch_hdr(); - + int fund = any2arith(&expr, SWITCH); /* INT, LONG or DOUBLE */ + + switch (fund) { + case LONG: + if (options['R']) + warning("long in switch"); + break; + case DOUBLE: + error("float/double in switch"); + erroneous2int(&expr); + break; + } + stat_stack(l_break, NO_LABEL); sh->sh_break = l_break; sh->sh_default = 0; sh->sh_table = l_table; sh->sh_nrofentries = 0; sh->sh_type = expr->ex_type; /* the expression switched */ - sh->sh_lowerbd = sh->sh_upperbd = (arith)0; /* ??? */ + sh->sh_lowerbd = sh->sh_upperbd = (arith)0; /* immaterial ??? */ sh->sh_entries = (struct case_entry *) 0; /* case-entry list */ sh->next = switch_stack; /* push onto switch-stack */ switch_stack = sh; @@ -48,7 +64,7 @@ code_endswitch() { register struct switch_hdr *sh = switch_stack; register label tablabel; - register struct case_entry *ce, *tmp; + register struct case_entry *ce; if (sh->sh_default == 0) /* no default occurred yet */ sh->sh_default = sh->sh_break; @@ -88,33 +104,42 @@ code_endswitch() } C_df_ilb(sh->sh_break); switch_stack = sh->next; /* unstack the switch descriptor */ + /* free the allocated switch structure */ - for (ce = sh->sh_entries; ce; ce = tmp) { - tmp = ce->next; + ce = sh->sh_entries; + while (ce) { + register struct case_entry *tmp = ce->next; free_case_entry(ce); + ce = tmp; } free_switch_hdr(sh); stat_unstack(); } -code_case(val) - arith val; +code_case(expr) + struct expr *expr; { + register arith val; register struct case_entry *ce; register struct switch_hdr *sh = switch_stack; - + if (sh == 0) { error("case statement not in switch"); return; } + + expr->ex_type = sh->sh_type; + cut_size(expr); + ce = new_case_entry(); C_df_ilb(ce->ce_label = text_label()); - ce->ce_value = val; + ce->ce_value = val = expr->VL_VALUE; + if (sh->sh_entries == 0) { /* first case entry */ ce->next = (struct case_entry *) 0; sh->sh_entries = ce; - sh->sh_lowerbd = sh->sh_upperbd = ce->ce_value; + sh->sh_lowerbd = sh->sh_upperbd = val; sh->sh_nrofentries = 1; } else { @@ -138,7 +163,8 @@ code_case(val) insert ce right after the head 3: c1 == 0 && c2 != 0: append ce to last element - The case c1 == 0 && c2 == 0 cannot occur! + The case c1 == 0 && c2 == 0 cannot occur, since + the list is guaranteed not to be empty. */ if (c1) { if (c1->ce_value == ce->ce_value) { From 96963fede122ee0ef167fe305878d9b6f128d337 Mon Sep 17 00:00:00 2001 From: dick Date: Sat, 15 Mar 1986 18:16:30 +0000 Subject: [PATCH 0136/1625] more calls of expr_error() for better error reporting --- lang/cem/cemcom/arith.c | 10 ++--- lang/cem/cemcom/ch7.c | 84 ++++++++++++++++++++++++++-------------- lang/cem/cemcom/ch7bin.c | 11 +++--- lang/cem/cemcom/ch7mon.c | 12 +++--- lang/cem/cemcom/expr.c | 2 +- lang/cem/cemcom/ival.c | 6 +-- 6 files changed, 76 insertions(+), 49 deletions(-) diff --git a/lang/cem/cemcom/arith.c b/lang/cem/cemcom/arith.c index 3b780bcf..ab63a9c9 100644 --- a/lang/cem/cemcom/arith.c +++ b/lang/cem/cemcom/arith.c @@ -111,7 +111,7 @@ ch76pointer(expp, oper, tp) ch7cast(expp, CAST, tp); else { if ((*expp)->ex_type != error_type) - error("%s on %s and pointer", + expr_error(*expp, "%s on %s and pointer", symbol2str(oper), symbol2str((*expp)->ex_type->tp_fund) ); @@ -147,7 +147,7 @@ any2arith(expp, oper) ) {} else - warning("%s on enum", symbol2str(oper)); + expr_warning(*expp, "%s on enum", symbol2str(oper)); int2int(expp, int_type); break; case FLOAT: @@ -161,7 +161,7 @@ any2arith(expp, oper) break; #endif NOBITFIELD default: - error("operator %s on non-numerical operand (%s)", + expr_error(*expp, "operator %s on non-numerical operand (%s)", symbol2str(oper), symbol2str(fund)); case ERRONEOUS: erroneous2int(expp); @@ -292,7 +292,7 @@ opnd2integral(expp, oper) if (fund != INT && fund != LONG) { if (fund != ERRONEOUS) - error("%s operand to %s", + expr_error(*expp, "%s operand to %s", symbol2str(fund), symbol2str(oper)); erroneous2int(expp); /* fund = INT; */ @@ -327,7 +327,7 @@ opnd2logical(expp, oper) case DOUBLE: break; default: - error("%s operand to %s", + expr_error(*expp, "%s operand to %s", symbol2str(fund), symbol2str(oper)); case ERRONEOUS: erroneous2int(expp); diff --git a/lang/cem/cemcom/ch7.c b/lang/cem/cemcom/ch7.c index 2a6d564f..8a10fec8 100644 --- a/lang/cem/cemcom/ch7.c +++ b/lang/cem/cemcom/ch7.c @@ -49,7 +49,7 @@ ch7sel(expp, oper, idf) tp = sd->sd_stype; break; default: - error("-> applied to %s", + expr_error(*expp, "-> applied to %s", symbol2str(tp->tp_fund)); case ERRONEOUS: (*expp)->ex_type = error_type; @@ -60,7 +60,7 @@ ch7sel(expp, oper, idf) else { /* oper == '.' */ /* filter out illegal expressions "non_lvalue.sel" */ if (!(*expp)->ex_lvalue) { - error("dot requires lvalue"); + expr_error(*expp, "dot requires lvalue"); (*expp)->ex_type = error_type; return; } @@ -79,7 +79,7 @@ ch7sel(expp, oper, idf) break; default: if (!is_anon_idf(idf)) - error("selector %s applied to %s", + expr_error(*expp, "selector %s applied to %s", idf->id_text, symbol2str(tp->tp_fund)); case ERRONEOUS: (*expp)->ex_type = error_type; @@ -133,11 +133,11 @@ ch7incr(expp, oper) register int fund = (*expp)->ex_type->tp_fund; if (!(*expp)->ex_lvalue) { - error("no lvalue with %s", symbol2str(oper)); + expr_error(*expp, "no lvalue with %s", symbol2str(oper)); return; } if (fund == ENUM) { - warning("%s on enum", symbol2str(oper)); + expr_warning(*expp, "%s on enum", symbol2str(oper)); addend = (arith)1; } else @@ -153,7 +153,7 @@ ch7incr(expp, oper) #endif NOBITFIELD else { if ((*expp)->ex_type != error_type) - error("%s on %s", + expr_error(*expp, "%s on %s", symbol2str(oper), symbol2str((*expp)->ex_type->tp_fund) ); @@ -210,15 +210,17 @@ ch7cast(expp, oper, tp) tp->tp_fund == ENUM && oper != CAST ) - warning("%s on enums of different types", - symbol2str(oper)); + expr_warning(*expp, + "%s on enums of different types", + symbol2str(oper)); int2int(expp, tp); } else if (oldi && !i) { if (oldtp->tp_fund == ENUM && oper != CAST) - warning("conversion of enum to %s\n", - symbol2str(tp->tp_fund)); + expr_warning(*expp, + "conversion of enum to %s\n", + symbol2str(tp->tp_fund)); int2float(expp, tp); } else @@ -230,7 +232,7 @@ ch7cast(expp, oper, tp) else if (oldtp->tp_fund == POINTER && tp->tp_fund == POINTER) { if (oper != CAST) - warning("incompatible pointers in %s", + expr_warning(*expp, "incompatible pointers in %s", symbol2str(oper)); (*expp)->ex_type = tp; /* free conversion */ } @@ -238,10 +240,12 @@ ch7cast(expp, oper, tp) if (oldtp->tp_fund == POINTER && is_integral_type(tp)) { /* from pointer to integral */ if (oper != CAST) - warning("illegal conversion of pointer to %s", + expr_warning(*expp, + "illegal conversion of pointer to %s", symbol2str(tp->tp_fund)); if (oldtp->tp_size > tp->tp_size) - warning("conversion of pointer to %s loses accuracy", + expr_warning(*expp, + "conversion of pointer to %s loses accuracy", symbol2str(tp->tp_fund)); if (oldtp->tp_size != tp->tp_size) int2int(expp, tp); @@ -261,12 +265,14 @@ ch7cast(expp, oper, tp) if (is_cp_cst(*expp) && (*expp)->VL_VALUE == (arith)0) break; default: - warning("illegal conversion of %s to pointer", + expr_warning(*expp, + "illegal conversion of %s to pointer", symbol2str(oldtp->tp_fund)); break; } if (oldtp->tp_size > tp->tp_size) - warning("conversion of %s to pointer loses accuracy", + expr_warning(*expp, + "conversion of %s to pointer loses accuracy", symbol2str(oldtp->tp_fund)); if (oldtp->tp_size != tp->tp_size) int2int(expp, tp); @@ -275,7 +281,7 @@ ch7cast(expp, oper, tp) } else if (oldtp->tp_size == tp->tp_size && oper == CAST) { - warning("dubious conversion based on equal size"); + expr_warning(*expp, "dubious conversion based on equal size"); (*expp)->ex_type = tp; /* brute force */ } else @@ -299,7 +305,7 @@ ch7asgn(expp, oper, expr) /* We expect an lvalue */ if (!(*expp)->ex_lvalue) { - error("no lvalue in lhs of %s", symbol2str(oper)); + expr_error(*expp, "no lvalue in lhs of %s", symbol2str(oper)); (*expp)->ex_depth = 99; /* no direct store/load at EVAL() */ /* what is 99 ??? DG */ } @@ -310,8 +316,7 @@ ch7asgn(expp, oper, expr) case TIMESAB: case DIVAB: case MODAB: - if (!is_arith_type((*expp)->ex_type)) - error("%s on %s", symbol2str(oper), symbol2str(fund)); + check_arith_type(expp, oper); any2arith(&expr, oper); ch7cast(&expr, CAST, (*expp)->ex_type); break; @@ -319,9 +324,7 @@ ch7asgn(expp, oper, expr) case MINAB: any2arith(&expr, oper); if (fund == POINTER) { - if (!is_integral_type(expr->ex_type)) - error("%s on non-integral type (%s)", - symbol2str(oper), symbol2str(fund)); + check_integral_type(&expr, oper); ch7bin(&expr, '*', intexpr( size_of_type( @@ -332,23 +335,20 @@ ch7asgn(expp, oper, expr) ) ); } - else - if (!is_arith_type((*expp)->ex_type)) - error("%s on %s", symbol2str(oper), symbol2str(fund)); - else + else { + check_arith_type(expp, oper); ch7cast(&expr, CAST, (*expp)->ex_type); + } break; case LEFTAB: case RIGHTAB: + check_integral_type(expp, oper); ch7cast(&expr, oper, int_type); - if (!is_integral_type((*expp)->ex_type)) - error("%s on %s", symbol2str(oper), symbol2str(fund)); break; case ANDAB: case XORAB: case ORAB: - if (!is_integral_type((*expp)->ex_type)) - error("%s on %s", symbol2str(oper), symbol2str(fund)); + check_integral_type(expp, oper); ch7cast(&expr, oper, (*expp)->ex_type); break; } @@ -382,6 +382,18 @@ is_integral_type(tp) } } +check_integral_type(expp, oper) + struct expr **expp; +{ + register struct expr *expr = *expp; + + if (!is_integral_type(expr->ex_type)) { + expr_error(expr, "%s on non-integral type (%s)", + symbol2str(oper), symbol2str(expr->ex_type->tp_fund)); + } + erroneous2int(expp); +} + int is_arith_type(tp) struct type *tp; @@ -403,3 +415,15 @@ is_arith_type(tp) return 0; } } + +check_arith_type(expp, oper) + struct expr **expp; +{ + register struct expr *expr = *expp; + + if (!is_arith_type(expr->ex_type)) { + expr_error(expr, "%s on non-arithmetical type (%s)", + symbol2str(oper), symbol2str(expr->ex_type->tp_fund)); + } + erroneous2int(expp); +} diff --git a/lang/cem/cemcom/ch7bin.c b/lang/cem/cemcom/ch7bin.c index 469a01e6..cae35b11 100644 --- a/lang/cem/cemcom/ch7bin.c +++ b/lang/cem/cemcom/ch7bin.c @@ -45,7 +45,8 @@ ch7bin(expp, oper, expr) case ERRONEOUS: return; default: - error("indexing an object of type %s", + expr_error(*expp, + "indexing an object of type %s", symbol2str((*expp)->ex_type->tp_fund)); return; } @@ -64,7 +65,7 @@ ch7bin(expp, oper, expr) } if ((*expp)->ex_type->tp_fund != FUNCTION) { if ((*expp)->ex_type != error_type) - error("call of non-function (%s)", + expr_error(*expp, "call of non-function (%s)", symbol2str((*expp)->ex_type->tp_fund)); /* leave the expression; it may still serve */ free_expression(expr); /* there go the parameters */ @@ -81,7 +82,7 @@ ch7bin(expp, oper, expr) case '%': fund = arithbalance(expp, oper, &expr); if (fund == DOUBLE) { - error("floating operand to %%"); + expr_error(*expp, "floating operand to %%"); erroneous2int(expp); } else @@ -197,7 +198,7 @@ ch7bin(expp, oper, expr) || is_struct_or_union(expr->ex_type->tp_fund) ) { if ((*expp)->ex_type != expr->ex_type) { - error("illegal balance"); + expr_error(*expp, "illegal balance"); (*expp)->ex_type = error_type; } } @@ -233,7 +234,7 @@ pntminuspnt(expp, oper, expr) struct type *up_type = (*expp)->ex_type->tp_up; if (up_type != expr->ex_type->tp_up) { - error("subtracting incompatible pointers"); + expr_error(*expp, "subtracting incompatible pointers"); free_expression(expr); erroneous2int(expp); return; diff --git a/lang/cem/cemcom/ch7mon.c b/lang/cem/cemcom/ch7mon.c index 3c25f375..3018c116 100644 --- a/lang/cem/cemcom/ch7mon.c +++ b/lang/cem/cemcom/ch7mon.c @@ -29,7 +29,8 @@ ch7mon(oper, expp) array2pointer(expp); if ((*expp)->ex_type->tp_fund != POINTER) { if ((*expp)->ex_type != error_type) - error("* applied to non-pointer (%s)", + expr_error(*expp, + "* applied to non-pointer (%s)", symbol2str((*expp)->ex_type->tp_fund)); (*expp)->ex_type = error_type; } @@ -57,13 +58,13 @@ ch7mon(oper, expp) else #ifndef NOBITFIELD if ((*expp)->ex_type->tp_fund == FIELD) { - error("& applied to field variable"); + expr_error(*expp, "& applied to field variable"); (*expp)->ex_type = error_type; } else #endif NOBITFIELD if (!(*expp)->ex_lvalue) { - error("& applied to non-lvalue"); + expr_error(*expp, "& applied to non-lvalue"); (*expp)->ex_type = error_type; } else { @@ -76,7 +77,8 @@ ch7mon(oper, expp) be used as register anymore */ if (def->df_sc == REGISTER) { - error("& on register variable not allowed"); + expr_error(*expp, + "& on register variable not allowed"); (*expp)->ex_type = error_type; break; /* break case '&' */ } @@ -91,7 +93,7 @@ ch7mon(oper, expp) int fund = (*expp)->ex_type->tp_fund; if (fund == FLOAT || fund == DOUBLE) { - error("~ not allowed on %s operands", + expr_error(*expp, "~ not allowed on %s operands", symbol2str(fund)); erroneous2int(expp); break; diff --git a/lang/cem/cemcom/expr.c b/lang/cem/cemcom/expr.c index 12760689..ac646a32 100644 --- a/lang/cem/cemcom/expr.c +++ b/lang/cem/cemcom/expr.c @@ -109,7 +109,7 @@ check_conditional(expr, oper, pos_descr) the operator oper. */ if (options['R'] && rank_of_expression(expr) >= rank_of(oper)) - warning("%s %s is ungrammatical", + expr_warning(expr, "%s %s is ungrammatical", symbol2str(expr->OP_OPER), pos_descr); } diff --git a/lang/cem/cemcom/ival.c b/lang/cem/cemcom/ival.c index 3a5efa36..55cb9ff3 100644 --- a/lang/cem/cemcom/ival.c +++ b/lang/cem/cemcom/ival.c @@ -457,7 +457,7 @@ check_ival(expr, type) case LONG: case ENUM: ch7cast(&expr, '=', type); - if (expr->ex_class != Value || expr->VL_IDF != 0) { + if (!is_cp_cst(expr)) { illegal_init_cst(expr); break; } @@ -466,7 +466,7 @@ check_ival(expr, type) #ifndef NOBITFIELD case FIELD: ch7cast(&expr, '=', type->tp_up); - if (expr->ex_class != Value || expr->VL_IDF != 0) { + if (!is_cp_cst(expr)) { illegal_init_cst(expr); break; } @@ -481,7 +481,7 @@ check_ival(expr, type) else if (expr->ex_class == Oper && expr->OP_OPER == INT2FLOAT) { expr = expr->OP_RIGHT; - if (expr->ex_class != Value || expr->VL_IDF != 0) { + if (!is_cp_cst(expr)) { illegal_init_cst(expr); break; } From 56fef70c4367d33e2d53b7efc56687f1f7db531d Mon Sep 17 00:00:00 2001 From: dick Date: Mon, 17 Mar 1986 17:47:04 +0000 Subject: [PATCH 0137/1625] some long lines split --- lang/cem/cemcom/LLlex.c | 3 ++- lang/cem/cemcom/arith.c | 3 ++- lang/cem/cemcom/ch7bin.c | 5 ++++- lang/cem/cemcom/ch7mon.c | 5 +++-- lang/cem/cemcom/domacro.c | 5 +++-- lang/cem/cemcom/dumpidf.c | 3 ++- lang/cem/cemcom/eval.c | 28 ++++++++++++++++++---------- lang/cem/cemcom/expr.c | 13 ++++++++----- lang/cem/cemcom/input.c | 9 +++++++-- lang/cem/cemcom/main.c | 4 +++- lang/cem/cemcom/replace.c | 3 ++- lang/cem/cemcom/scan.c | 3 ++- lang/cem/cemcom/stack.c | 18 +++++++++++++----- lang/cem/cemcom/statement.g | 3 ++- 14 files changed, 71 insertions(+), 34 deletions(-) diff --git a/lang/cem/cemcom/LLlex.c b/lang/cem/cemcom/LLlex.c index 0c3e9f98..fce9dac6 100644 --- a/lang/cem/cemcom/LLlex.c +++ b/lang/cem/cemcom/LLlex.c @@ -497,7 +497,8 @@ string_token(nm, stop_char) else { str[pos++] = '\\'; if (pos == str_size) - str = Srealloc(str, str_size += RSTRSIZE); + str = Srealloc(str, + str_size += RSTRSIZE); ch = nch; } } diff --git a/lang/cem/cemcom/arith.c b/lang/cem/cemcom/arith.c index ab63a9c9..29755d4d 100644 --- a/lang/cem/cemcom/arith.c +++ b/lang/cem/cemcom/arith.c @@ -450,7 +450,8 @@ field2arith(expp) register arith bits_in_type = atype->tp_size * 8; ch7bin(expp, LEFT, - intexpr(bits_in_type - fd->fd_width - fd->fd_shift, INT) + intexpr(bits_in_type - fd->fd_width - fd->fd_shift, + INT) ); ch7bin(expp, RIGHT, intexpr(bits_in_type - fd->fd_width, INT)); } diff --git a/lang/cem/cemcom/ch7bin.c b/lang/cem/cemcom/ch7bin.c index cae35b11..12d92678 100644 --- a/lang/cem/cemcom/ch7bin.c +++ b/lang/cem/cemcom/ch7bin.c @@ -105,8 +105,11 @@ ch7bin(expp, oper, expr) } if ((*expp)->ex_type->tp_fund == POINTER) { pointer_arithmetic(expp, oper, &expr); - if (expr->ex_type->tp_size != (*expp)->ex_type->tp_size) + if ( expr->ex_type->tp_size != + (*expp)->ex_type->tp_size + ) { ch7cast(&expr, CAST, (*expp)->ex_type); + } pointer_binary(expp, oper, expr); } else { diff --git a/lang/cem/cemcom/ch7mon.c b/lang/cem/cemcom/ch7mon.c index 3018c116..5c144192 100644 --- a/lang/cem/cemcom/ch7mon.c +++ b/lang/cem/cemcom/ch7mon.c @@ -78,7 +78,7 @@ ch7mon(oper, expp) */ if (def->df_sc == REGISTER) { expr_error(*expp, - "& on register variable not allowed"); + "& on register variable not allowed"); (*expp)->ex_type = error_type; break; /* break case '&' */ } @@ -113,7 +113,8 @@ ch7mon(oper, expp) if (is_fp_cst(*expp)) switch_sign_fp(*expp); else - *expp = new_oper((*expp)->ex_type, NILEXPR, oper, *expp); + *expp = new_oper((*expp)->ex_type, + NILEXPR, oper, *expp); break; case '!': if ((*expp)->ex_type->tp_fund == FUNCTION) diff --git a/lang/cem/cemcom/domacro.c b/lang/cem/cemcom/domacro.c index 5407591a..f2d76d9e 100644 --- a/lang/cem/cemcom/domacro.c +++ b/lang/cem/cemcom/domacro.c @@ -529,8 +529,9 @@ get_text(formals, length) if (c == '\\') { /* check for "\\\n" */ LoadChar(c); if (c == '\n') { - /* more than one line is used for the - replacement text. Replace "\\\n" by " ". + /* More than one line is used for the + replacement text. + Replace "\\\n" by " ". */ text[pos++] = ' '; ++LineNumber; diff --git a/lang/cem/cemcom/dumpidf.c b/lang/cem/cemcom/dumpidf.c index e370512b..b2732bfd 100644 --- a/lang/cem/cemcom/dumpidf.c +++ b/lang/cem/cemcom/dumpidf.c @@ -246,7 +246,8 @@ type2str(tp) sprintf(buf, ""); return buf; } - sprintf(buf, "(@%lx, #%ld, &%d) ", tp, (long)tp->tp_size, tp->tp_align); + sprintf(buf, "(@%lx, #%ld, &%d) ", + tp, (long)tp->tp_size, tp->tp_align); while (ops) { switch (tp->tp_fund) { case POINTER: diff --git a/lang/cem/cemcom/eval.c b/lang/cem/cemcom/eval.c index 094cf625..719338bb 100644 --- a/lang/cem/cemcom/eval.c +++ b/lang/cem/cemcom/eval.c @@ -57,14 +57,16 @@ arith tmp_pointer_var(); int code: indicates whether the expression tree must be turned into EM code or not. E.g. the expression statement "12;" delivers the expression "12" to - EVAL while this should not result in any EM code + EVAL while this should not result in any EM + code label false_label: label true_label: if the expression is a logical or relational expression and if the loop of the program depends on the resulting value then EVAL - generates jumps to the specified program labels, - in case they are specified (i.e. are non-zero) + generates jumps to the specified program + labels, in case they are specified + (i.e. are non-zero) */ EVAL(expr, val, code, true_label, false_label) @@ -242,7 +244,9 @@ EVAL(expr, val, code, true_label, false_label) EVAL(leftop, RVAL, code, NO_LABEL, NO_LABEL); EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); if (gencode) - if (tp->tp_fund == INT || tp->tp_fund == LONG) { + if ( tp->tp_fund == INT + || tp->tp_fund == LONG + ) { if (tp->tp_unsigned) C_rmu(tp->tp_size); else @@ -279,23 +283,25 @@ EVAL(expr, val, code, true_label, false_label) EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); if (gencode) { /* The operands have the same type */ + arith size = leftop->ex_type->tp_size; + switch (tp->tp_fund) { case INT: case LONG: if (leftop->ex_type->tp_unsigned) - C_cmu(leftop->ex_type->tp_size); + C_cmu(size); else - C_cmi(leftop->ex_type->tp_size); + C_cmi(size); break; case FLOAT: case DOUBLE: - C_cmf(leftop->ex_type->tp_size); + C_cmf(size); break; case POINTER: C_cmp(); break; case ENUM: - C_cmi(leftop->ex_type->tp_size); + C_cmi(size); break; default: CRASH(); @@ -537,10 +543,12 @@ EVAL(expr, val, code, true_label, false_label) EVAL(leftop, RVAL, TRUE, l_true, l_false); C_df_ilb(l_true); - EVAL(rightop->OP_LEFT, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(rightop->OP_LEFT, RVAL, code, + NO_LABEL, NO_LABEL); C_bra(l_end); C_df_ilb(l_false); - EVAL(rightop->OP_RIGHT, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(rightop->OP_RIGHT, RVAL, code, + NO_LABEL, NO_LABEL); C_df_ilb(l_end); break; } diff --git a/lang/cem/cemcom/expr.c b/lang/cem/cemcom/expr.c index ac646a32..7dea8edb 100644 --- a/lang/cem/cemcom/expr.c +++ b/lang/cem/cemcom/expr.c @@ -225,11 +225,14 @@ intexpr(ivalue, fund) expr->ex_type = long_type; break; case UNSIGNED: - /* We cannot make a test like "ivalue <= max_unsigned" - because, if sizeof(long) == int_size holds, max_unsigned - may be a negative long in which case the comparison - results in an unexpected answer. We assume that - the type "unsigned long" is not part of portable C ! + /* We cannot make a test like + ivalue <= max_unsigned + because, if + sizeof(long) == int_size + holds, max_unsigned may be a negative long in + which case the comparison results in an unexpected + answer. We assume that the type "unsigned long" + is not part of portable C ! */ expr->ex_type = (ivalue & ~max_unsigned) ? long_type : uint_type; diff --git a/lang/cem/cemcom/input.c b/lang/cem/cemcom/input.c index e3015cdd..2838d823 100644 --- a/lang/cem/cemcom/input.c +++ b/lang/cem/cemcom/input.c @@ -95,8 +95,10 @@ readfile(filename, size) char *cbuf; /* pointer to buffer to be returned */ register tmp; - if ((fd = sys_open(filename, OP_RDONLY)) < 0) /* can't open this file */ + if ((fd = sys_open(filename, OP_RDONLY)) < 0) { + /* can't open this file */ return (char *) 0; + } if ((*size = sys_fsize(fd)) < 0) fatal("(readfile) cannot get size of file"); @@ -374,8 +376,11 @@ loadbuf() #ifndef READ_IN_ONE #ifndef NOPP - if (FilDes >= 0 && (head->bh_size = readblock(FilDes, head->bh_text)) > 0) + if ( FilDes >= 0 + && (head->bh_size = readblock(FilDes, head->bh_text)) > 0 + ) { return ipp = &(head->bh_text[1]), *ipp++; + } #else NOPP if (FilDes >= 0 && (isize = readblock(FilDes, &ibuf[0])) > 0) return ipp = &ibuf[1], *ipp++; diff --git a/lang/cem/cemcom/main.c b/lang/cem/cemcom/main.c index b2b199f7..b2e1a9d5 100644 --- a/lang/cem/cemcom/main.c +++ b/lang/cem/cemcom/main.c @@ -309,7 +309,9 @@ preprocess() lastlineno = dot.tk_line; if (!options['P']) printf("\n#line %ld \"%s\"\n", - lastlineno, lastfilenm); + lastlineno, + lastfilenm + ); } } else { diff --git a/lang/cem/cemcom/replace.c b/lang/cem/cemcom/replace.c index 24c93586..c76b5d7a 100644 --- a/lang/cem/cemcom/replace.c +++ b/lang/cem/cemcom/replace.c @@ -138,7 +138,8 @@ macro2buffer(idef, actpars, siztext) text[pos++] = *p; if (pos == size) { - text = Srealloc(text, size += RSTRSIZE); + text = Srealloc(text, + size += RSTRSIZE); } } } diff --git a/lang/cem/cemcom/scan.c b/lang/cem/cemcom/scan.c index c34edf4b..d75f8743 100644 --- a/lang/cem/cemcom/scan.c +++ b/lang/cem/cemcom/scan.c @@ -165,7 +165,8 @@ copyact(ch1, ch2, level) break; case ',': - if (!level) { /* next parameter encountered */ + if (!level) { + /* next parameter encountered */ copy(EOS); if (++nr_of_params >= NPARAMS) { diff --git a/lang/cem/cemcom/stack.c b/lang/cem/cemcom/stack.c index 060d793c..50ed04f6 100644 --- a/lang/cem/cemcom/stack.c +++ b/lang/cem/cemcom/stack.c @@ -46,7 +46,8 @@ stack_level() { local_level->sl_next = stl; stl->sl_previous = local_level; stl->sl_level = ++level; - stl->sl_local_offset = stl->sl_max_block = local_level->sl_local_offset; + stl->sl_local_offset = + stl->sl_max_block = local_level->sl_local_offset; local_level = stl; } @@ -143,12 +144,16 @@ unstack_level() free_def(def); update_ahead(idf); } - while ((sdef = idf->id_sdef) && sdef->sd_level >= level) { + while ( (sdef = idf->id_sdef) + && sdef->sd_level >= level + ) { /* unlink it from the sdef list under the idf block */ idf->id_sdef = sdef->next; free_sdef(sdef); } - while ((tag = idf->id_struct) && tag->tg_level >= level) { + while ( (tag = idf->id_struct) + && tag->tg_level >= level + ) { /* unlink it from the struct list under the idf block */ idf->id_struct = tag->next; free_tag(tag); @@ -163,8 +168,11 @@ unstack_level() */ lastlvl = local_level; local_level = local_level->sl_previous; - if (level > L_LOCAL && lastlvl->sl_max_block < local_level->sl_max_block) - local_level->sl_max_block = lastlvl->sl_max_block; + if ( level > L_LOCAL + && lastlvl->sl_max_block < local_level->sl_max_block + ) { + local_level->sl_max_block = lastlvl->sl_max_block; + } free_stack_level(lastlvl); local_level->sl_next = (struct stack_level *) 0; level = local_level->sl_level; diff --git a/lang/cem/cemcom/statement.g b/lang/cem/cemcom/statement.g index af127420..da25a947 100644 --- a/lang/cem/cemcom/statement.g +++ b/lang/cem/cemcom/statement.g @@ -258,7 +258,8 @@ for_statement { C_df_ilb(l_continue); if (e_incr) - code_expr(e_incr, RVAL, FALSE, NO_LABEL, NO_LABEL); + code_expr(e_incr, RVAL, FALSE, + NO_LABEL, NO_LABEL); C_bra(l_test); C_df_ilb(l_break); stat_unstack(); From 40e0784b593a4d872e4165160ccffafc1744ead0 Mon Sep 17 00:00:00 2001 From: erikb Date: Tue, 18 Mar 1986 09:01:59 +0000 Subject: [PATCH 0138/1625] last modifications in order to introduce the EM library mechanism --- lang/cem/cemcom/code.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lang/cem/cemcom/code.c b/lang/cem/cemcom/code.c index 1d0df57a..d679c965 100644 --- a/lang/cem/cemcom/code.c +++ b/lang/cem/cemcom/code.c @@ -42,6 +42,7 @@ extern char options[]; init_code(dst_file) char *dst_file; { + C_init(word_size, pointer_size); /* initialise EM module */ if (C_open(dst_file) == 0) fatal("cannot write to %s\n", dst_file); #ifndef USE_TMP From 43fe55f6347461b604583b574cdde9dee666bc39 Mon Sep 17 00:00:00 2001 From: erikb Date: Wed, 19 Mar 1986 12:31:05 +0000 Subject: [PATCH 0139/1625] Recovered from some inconsistencies. --- lang/cem/cemcom/code.c | 2 +- lang/cem/cemcom/expr.c | 2 +- lang/cem/cemcom/idf.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lang/cem/cemcom/code.c b/lang/cem/cemcom/code.c index d679c965..c3e8e923 100644 --- a/lang/cem/cemcom/code.c +++ b/lang/cem/cemcom/code.c @@ -18,7 +18,7 @@ #include "em.h" #include "level.h" #include "decspecs.h" -#include "declarator.h" +#include "declar.h" #include "Lpars.h" #include "mes.h" #include "LLlex.h" diff --git a/lang/cem/cemcom/expr.c b/lang/cem/cemcom/expr.c index 7dea8edb..11cef82f 100644 --- a/lang/cem/cemcom/expr.c +++ b/lang/cem/cemcom/expr.c @@ -12,7 +12,7 @@ #include "LLlex.h" #include "Lpars.h" #include "decspecs.h" -#include "declarator.h" +#include "declar.h" #include "storage.h" #include "sizes.h" diff --git a/lang/cem/cemcom/idf.c b/lang/cem/cemcom/idf.c index 14868764..c6d4eed3 100644 --- a/lang/cem/cemcom/idf.c +++ b/lang/cem/cemcom/idf.c @@ -16,7 +16,7 @@ #include "def.h" #include "type.h" #include "struct.h" -#include "declarator.h" +#include "declar.h" #include "decspecs.h" #include "sizes.h" #include "Lpars.h" From d89ee4fa723776286300ba28c75f412483a9ee3f Mon Sep 17 00:00:00 2001 From: erikb Date: Wed, 19 Mar 1986 12:36:02 +0000 Subject: [PATCH 0140/1625] Added C_init(), an empty-bodied routine --- lang/cem/cemcom/em.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lang/cem/cemcom/em.c b/lang/cem/cemcom/em.c index eb1131cc..bc3ae5cf 100644 --- a/lang/cem/cemcom/em.c +++ b/lang/cem/cemcom/em.c @@ -37,6 +37,10 @@ putbyte(b) /* shouldn't putbyte() be a macro ??? (EB) */ *opp++ = (char) b; } +C_init(wsize, psize) + arith wsize, psize; +{} + C_open(nm) /* open file for compact code output */ char *nm; { From 2586439ca451ae2f642bbee84fe569bec1f0d413 Mon Sep 17 00:00:00 2001 From: erikb Date: Wed, 19 Mar 1986 16:07:32 +0000 Subject: [PATCH 0141/1625] improved lay-out --- lang/cem/cemcom/cem.1 | 32 ++++++++++++++++++++++---------- lang/cem/cemcom/cemcom.1 | 2 +- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/lang/cem/cemcom/cem.1 b/lang/cem/cemcom/cem.1 index b9162e0b..93093514 100644 --- a/lang/cem/cemcom/cem.1 +++ b/lang/cem/cemcom/cem.1 @@ -1,4 +1,4 @@ -.TH CEM 1 local +.TH CEM 1L 86/03/10 .SH NAME cem \- ACK C compiler .SH SYNOPSIS @@ -6,8 +6,10 @@ cem \- ACK C compiler [ option ] ... file ... .SH DESCRIPTION .I Cem -is a \fIcc\fP(1)-like -C compiler that uses the C front-end compiler \fIcemcom\fP(1) +is a +.I cc (1)-like +C compiler that uses the C front-end compiler +.I cemcom (1) of the Amsterdam Compiler Kit. .I Cem interprets its arguments not starting with a '\-' as @@ -33,20 +35,30 @@ The actions to be taken by are directed by the type of file argument and the various options that are presented to it. .PP -The following options, which is a mixture of options interpreted by \fIcc\fP(1) -and \fIack\fP(?), +The following set of options, which is a mixture of options interpreted by +.I cc (1) +and +.I ack (?) are interpreted by .I cem . (The options not specified here are passed to the front-end -compiler \fIcemcom\fP(1).) +compiler +.I cemcom (1L).) .IP \fB\-B\fP\fIname\fP -Use \fIname\fP as front-end compiler instead of the default \fIcemcom\fP(1). +Use +.I name +as front-end compiler instead of the default +.I cemcom (1). .br Same as "\fB\-Rcem=\fP\fIname\fP". .IP \fB\-C\fP -Run C preprocessor \fI/lib/cpp\fP only and prevent it from eliding comments. +Run C preprocessor +.I /lib/cpp +only and prevent it from eliding comments. .IP \fB\-D\fP\fIname\fP\fB=\fP\fIdef\fP -Define the \fIname\fP to the preprocessor, as if by "#define". +Define the +.I name +to the preprocessor, as if by "#define". .IP \fB\-D\fP\fIname\fP .br Same as "\fB\-D\fP\fIname\fP\fB=1\fP". @@ -233,6 +245,6 @@ causes files with the same name as the intermediate files to be overwritten. .IP \(bu .B Cem only accepts a limited number of arguments to be passed to the various phases. -(e.g. 256). +(e.g., 256). .IP \(bu Please report suggestions and other bugs to erikb@tjalk.UUCP diff --git a/lang/cem/cemcom/cemcom.1 b/lang/cem/cemcom/cemcom.1 index ec84c40f..656742ba 100644 --- a/lang/cem/cemcom/cemcom.1 +++ b/lang/cem/cemcom/cemcom.1 @@ -1,4 +1,4 @@ -.TH CEMCOM 1 local +.TH CEMCOM 1L 86/03/10 .SH NAME cemcom \- C to EM compiler .SH SYNOPSIS From 5b9b6fa61e6e45ada0c3335ef65023ff59c04c5b Mon Sep 17 00:00:00 2001 From: sater Date: Wed, 19 Mar 1986 16:14:12 +0000 Subject: [PATCH 0142/1625] Relaxed input syntax for from STACK coercions No gen clause is necessary anymore. --- util/ncgg/cgg.y | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util/ncgg/cgg.y b/util/ncgg/cgg.y index 1fca1cc0..58c56f14 100644 --- a/util/ncgg/cgg.y +++ b/util/ncgg/cgg.y @@ -542,11 +542,11 @@ coercdeflist coercdeflist_el : FROM {startline = lineno; tokpatlen=0; inithall();} - STACK allocates GEN genlist YIELDS tokeninstance + STACK allocates generates YIELDS tokeninstance { checkhall(); - n_coerc(0,0,$4,$6,(struct varinfo *) 0,$8); + n_coerc(0,0,$4,$5,(struct varinfo *) 0,$7); freevi($4); - freevi($6); + freevi($5); } | FROM {startline = lineno;} From 691a1db69ae909142bdbac35c2526d778cbbb118 Mon Sep 17 00:00:00 2001 From: erikb Date: Thu, 20 Mar 1986 13:09:47 +0000 Subject: [PATCH 0143/1625] fixed a bug in check_*_expr() --- lang/cem/cemcom/ch7.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lang/cem/cemcom/ch7.c b/lang/cem/cemcom/ch7.c index 8a10fec8..9812e8f8 100644 --- a/lang/cem/cemcom/ch7.c +++ b/lang/cem/cemcom/ch7.c @@ -390,8 +390,8 @@ check_integral_type(expp, oper) if (!is_integral_type(expr->ex_type)) { expr_error(expr, "%s on non-integral type (%s)", symbol2str(oper), symbol2str(expr->ex_type->tp_fund)); + erroneous2int(expp); } - erroneous2int(expp); } int @@ -424,6 +424,6 @@ check_arith_type(expp, oper) if (!is_arith_type(expr->ex_type)) { expr_error(expr, "%s on non-arithmetical type (%s)", symbol2str(oper), symbol2str(expr->ex_type->tp_fund)); + erroneous2int(expp); } - erroneous2int(expp); } From 33604d21154d8ebe29f441a6b45b01a7745b247e Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 20 Mar 1986 14:52:03 +0000 Subject: [PATCH 0144/1625] Initial version --- lang/m2/comp/LLlex.c | 383 ++++++++++++++++++++++++++++++++++++++ lang/m2/comp/LLlex.h | 27 +++ lang/m2/comp/LLmessage.c | 69 +++++++ lang/m2/comp/Makefile | 78 ++++++++ lang/m2/comp/char.tab | 54 ++++++ lang/m2/comp/class.h | 38 ++++ lang/m2/comp/declar.g | 181 ++++++++++++++++++ lang/m2/comp/error.c | 170 +++++++++++++++++ lang/m2/comp/expression.g | 97 ++++++++++ lang/m2/comp/f_info.h | 11 ++ lang/m2/comp/idf.c | 4 + lang/m2/comp/idf.h | 5 + lang/m2/comp/idlist.H | 12 ++ lang/m2/comp/idlist.c | 20 ++ lang/m2/comp/input.c | 6 + lang/m2/comp/input.h | 7 + lang/m2/comp/main.c | 121 ++++++++++++ lang/m2/comp/make.allocd | 17 ++ lang/m2/comp/make.tokcase | 34 ++++ lang/m2/comp/make.tokfile | 6 + lang/m2/comp/param.h | 4 + lang/m2/comp/program.g | 116 ++++++++++++ lang/m2/comp/statement.g | 98 ++++++++++ lang/m2/comp/tab.c | 295 +++++++++++++++++++++++++++++ lang/m2/comp/tokenname.c | 99 ++++++++++ lang/m2/comp/tokenname.h | 7 + 26 files changed, 1959 insertions(+) create mode 100644 lang/m2/comp/LLlex.c create mode 100644 lang/m2/comp/LLlex.h create mode 100644 lang/m2/comp/LLmessage.c create mode 100644 lang/m2/comp/Makefile create mode 100644 lang/m2/comp/char.tab create mode 100644 lang/m2/comp/class.h create mode 100644 lang/m2/comp/declar.g create mode 100644 lang/m2/comp/error.c create mode 100644 lang/m2/comp/expression.g create mode 100644 lang/m2/comp/f_info.h create mode 100644 lang/m2/comp/idf.c create mode 100644 lang/m2/comp/idf.h create mode 100644 lang/m2/comp/idlist.H create mode 100644 lang/m2/comp/idlist.c create mode 100644 lang/m2/comp/input.c create mode 100644 lang/m2/comp/input.h create mode 100644 lang/m2/comp/main.c create mode 100755 lang/m2/comp/make.allocd create mode 100755 lang/m2/comp/make.tokcase create mode 100755 lang/m2/comp/make.tokfile create mode 100644 lang/m2/comp/param.h create mode 100644 lang/m2/comp/program.g create mode 100644 lang/m2/comp/statement.g create mode 100644 lang/m2/comp/tab.c create mode 100644 lang/m2/comp/tokenname.c create mode 100644 lang/m2/comp/tokenname.h diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c new file mode 100644 index 00000000..7380c3fe --- /dev/null +++ b/lang/m2/comp/LLlex.c @@ -0,0 +1,383 @@ +/* LEXICAL ANALYSER FOR MODULA-2 */ + +#include "input.h" +#include +#include "f_info.h" +#include "Lpars.h" +#include "class.h" +#include "param.h" +#include "idf.h" +#include "LLlex.h" + +long str2long(); +char *GetString(); + +struct token dot, aside; + +static char *RcsId = "$Header$"; + +int +LLlex() +{ + /* LLlex() plays the role of Lexical Analyzer for the parser. + The putting aside of tokens is taken into account. + */ + if (ASIDE) { /* a token is put aside */ + dot = aside; + ASIDE = 0; + } + else { + GetToken(&dot); + if (DOT == EOI) DOT = -1; + } + + return DOT; +} + +int +GetToken(tk) + register struct token *tk; +{ + char buf[(IDFSIZE > NUMSIZE ? IDFSIZE : NUMSIZE) + 1]; + register int ch, nch; + +again: + LoadChar(ch); + if ((ch & 0200) && ch != EOI) { + fatal("non-ascii '\\%03o' read", ch & 0377); + } + + switch (class(ch)) { + + case STSKIP: + goto again; + + case STNL: + LineNumber++; + goto again; + + case STGARB: + if (040 < ch && ch < 0177) { + lexerror("garbage char %c", ch); + } + else { + lexerror("garbage char \\%03o", ch); + } + goto again; + + case STSIMP: + if (ch == '(') { + LoadChar(nch); + if (nch == '*') { + SkipComment(); + goto again; + } + else { + PushBack(nch); + } + } + return tk->tk_symb = ch; + + case STCOMP: + LoadChar(nch); + switch (ch) { + + case '.': + if (nch == '.') { + return tk->tk_symb = UPTO; + } + PushBack(nch); + return tk->tk_symb = ch; + + case ':': + if (nch == '=') { + return tk->tk_symb = BECOMES; + } + PushBack(nch); + return tk->tk_symb = ch; + + case '<': + if (nch == '=') { + return tk->tk_symb = LESSEQUAL; + } + else + if (nch == '>') { + return tk->tk_symb = UNEQUAL; + } + PushBack(nch); + return tk->tk_symb = ch; + + case '>': + if (nch == '=') { + return tk->tk_symb = GREATEREQUAL; + } + PushBack(nch); + return tk->tk_symb = ch; + + default : + crash("bad STCOMP"); + } + + case STIDF: + { + register char *tg = &buf[0]; + register struct idf *id; + + do { + if (tg - buf < IDFSIZE) *tg++ = ch; + LoadChar(ch); + } while(in_idf(ch)); + + if (ch != EOI) + PushBack(ch); + *tg++ = '\0'; + + id = tk->TOK_IDF = str2idf(buf, 1); + if (!id) fatal("Out of memory"); + return tk->tk_symb = id->id_reserved ? id->id_reserved : IDENT; + } + + case STSTR: + tk->TOK_STR = GetString(ch); + return tk->tk_symb = STRING; + + case STNUM: + { + /* The problem arising with the "parsing" of a number + is that we don't know the base in advance so we + have to read the number with the help of a rather + complex finite automaton. + Excuses for the very ugly code! + */ + register char *np = &buf[1]; + /* allow a '-' to be added */ + + *np++ = ch; + + LoadChar(ch); + while (is_oct(ch)) { + if (np < &buf[NUMSIZE]) { + *np++ = ch; + } + LoadChar(ch); + } + switch (ch) { + case 'H': +Shex: *np++ = '\0'; + /* Type is integer */ + tk->TOK_INT = str2long(&buf[1], 16); + return tk->tk_symb = INTEGER; + + case '8': + case '9': + do { + if (np < &buf[NUMSIZE]) { + *np++ = ch; + } + LoadChar(ch); + } while (is_dig(ch)); + + if (is_hex(ch)) + goto S2; + if (ch == 'H') + goto Shex; + if (ch == '.') + goto Sreal; + PushBack(ch); + goto Sdec; + + case 'B': + case 'C': + if (np < &buf[NUMSIZE]) { + *np++ = ch; + } + LoadChar(ch); + if (ch == 'H') + goto Shex; + if (is_hex(ch)) + goto S2; + PushBack(ch); + ch = *--np; + *np++ = '\0'; + /* + * If (ch == 'C') type is a CHAR + * else type is an INTEGER + */ + tk->TOK_INT = str2long(&buf[1], 8); + return tk->tk_symb = INTEGER; + + case 'A': + case 'D': + case 'E': + case 'F': +S2: + do { + if (np < &buf[NUMSIZE]) { + *np++ = ch; + } + LoadChar(ch); + } while (is_hex(ch)); + if (ch != 'H') { + lexerror("H expected after hex number"); + PushBack(ch); + } + goto Shex; + + case '.': +Sreal: + /* This '.' could be the first of the '..' + token. At this point, we need a look-ahead + of two characters. + */ + LoadChar(ch); + if (ch == '.') { + /* Indeed the '..' token + */ + PushBack(ch); + PushBack(ch); + goto Sdec; + } + + /* a real constant */ + if (np < &buf[NUMSIZE]) { + *np++ = '.'; + } + + if (is_dig(ch)) { + /* Fractional part + */ + do { + if (np < &buf[NUMSIZE]) { + *np++ = ch; + } + LoadChar(ch); + } while (is_dig(ch)); + } + + if (ch == 'E') { + /* Scale factor + */ + if (np < &buf[NUMSIZE]) { + *np++ = 'E'; + } + LoadChar(ch); + if (ch == '+' || ch == '-') { + /* Signed scalefactor + */ + if (np < &buf[NUMSIZE]) { + *np++ = ch; + } + LoadChar(ch); + } + if (is_dig(ch)) { + do { + if (np < &buf[NUMSIZE]) { + *np++ = ch; + } + LoadChar(ch); + } while (is_dig(ch)); + } + else { + lexerror("bad scale factor"); + } + } + + PushBack(ch); + + if (np == &buf[NUMSIZE + 1]) { + lexerror("floating constant too long"); + tk->TOK_REL = Salloc("0.0", 5); + } + else { + tk->TOK_REL = Salloc(buf, np - buf) + 1; + } + return tk->tk_symb = REAL; + + default: + PushBack(ch); +Sdec: + *np++ = '\0'; + /* Type is an integer */ + tk->TOK_INT = str2long(&buf[1], 10); + return tk->tk_symb = INTEGER; + } + /*NOTREACHED*/ + } + + case STEOI: + return tk->tk_symb = EOI; + + case STCHAR: + default: + crash("bad character class %d", class(ch)); + } +} + +char * +GetString(upto) +{ + register int ch; + int str_size; + char *str = Malloc(str_size = 32); + register int pos = 0; + + LoadChar(ch); + while (ch != upto) { + if (class(ch) == STNL) { + lexerror("newline in string"); + LineNumber++; + break; + } + if (ch == EOI) { + lexerror("end-of-file in string"); + break; + } + str[pos++] = ch; + if (pos == str_size) { + str = Srealloc(str, str_size += 8); + } + LoadChar(ch); + } + str[pos] = '\0'; + return str; +} + +SkipComment() +{ + /* Skip Modula-2 like comment (* ... *). + Note that comment may be nested. + */ + + register int ch; + register int NestLevel = 0; + + LoadChar(ch); + for (;;) { + if (class(ch) == STNL) { + LineNumber++; + } + else + if (ch == '(') { + LoadChar(ch); + if (ch == '*') { + ++NestLevel; + } + else { + continue; + } + } + else + if (ch == '*') { + LoadChar(ch); + if (ch == ')') { + if (NestLevel-- == 0) { + return; + } + } + else { + continue; + } + } + LoadChar(ch); + } +} diff --git a/lang/m2/comp/LLlex.h b/lang/m2/comp/LLlex.h new file mode 100644 index 00000000..e6a2dd81 --- /dev/null +++ b/lang/m2/comp/LLlex.h @@ -0,0 +1,27 @@ +/* Token Descriptor Definition */ + +/* $Header$ */ + +struct token { + int tk_symb; /* token itself */ + union { + struct idf *tk_idf; /* IDENT */ + char *tk_str; /* STRING */ + struct { /* INTEGER */ + int tk_type; /* type */ + long tk_value; /* value */ + } tk_int; + char *tk_real; /* REAL */ + } tk_data; +}; + +#define TOK_IDF tk_data.tk_idf +#define TOK_STR tk_data.tk_str +#define TOK_ITP tk_data.tk_int.tk_type +#define TOK_INT tk_data.tk_int.tk_value +#define TOK_REL tk_data.tk_real + +extern struct token dot, aside; + +#define DOT dot.tk_symb +#define ASIDE aside.tk_symb diff --git a/lang/m2/comp/LLmessage.c b/lang/m2/comp/LLmessage.c new file mode 100644 index 00000000..fe10602b --- /dev/null +++ b/lang/m2/comp/LLmessage.c @@ -0,0 +1,69 @@ +#include +#include "f_info.h" +#include "idf.h" +#include "LLlex.h" +#include "Lpars.h" + +static char *RcsId = "$Header$"; + +extern char *symbol2str(); +int err_occurred = 0; + +LLmessage(tk) + int tk; +{ + ++err_occurred; + if (tk) { + error("%s missing", symbol2str(tk)); + insert_token(tk); + } + else + error("%s deleted", symbol2str(dot.tk_symb)); +} + +struct idf * +gen_anon_idf() +{ + /* A new idf is created out of nowhere, to serve as an + anonymous name. + */ + static int name_cnt; + char buff[100]; + char *sprintf(); + + sprintf(buff, "#%d in %s, line %u", + ++name_cnt, FileName, LineNumber); + return str2idf(buff, 1); +} + +int +is_anon_idf(idf) + struct idf *idf; +{ + return idf->id_text[0] == '#'; +} + +insert_token(tk) + int tk; +{ + aside = dot; + + dot.tk_symb = tk; + + switch (tk) { + /* The operands need some body */ + case IDENT: + dot.TOK_IDF = gen_anon_idf(); + break; + case STRING: + dot.TOK_STR = Salloc("", 1); + break; + case INTEGER: +/* dot.TOK_ITP = INT; */ + dot.TOK_INT = 1; + break; + case REAL: + dot.TOK_REL = Salloc("0.0", 4); + break; + } +} diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile new file mode 100644 index 00000000..c367db29 --- /dev/null +++ b/lang/m2/comp/Makefile @@ -0,0 +1,78 @@ +# make modula-2 "compiler" +# $Header$ + +HDIR = ../../em/h +PKGDIR = ../../em/pkg +LIBDIR = ../../em/lib +INCLUDES = -I$(HDIR) -I$(PKGDIR) -I/user1/erikb/h +LSRC = tokenfile.g program.g declar.g expression.g statement.g +CC = cc +GEN = LLgen +GENOPTIONS = +CFLAGS = -DDEBUG -O $(INCLUDES) +LOBJ = tokenfile.o program.o declar.o expression.o statement.o +COBJ = LLlex.o LLmessage.o char.o error.o main.o \ + symbol2str.o tokenname.o idf.o input.o idlist.o +OBJ = $(COBJ) $(LOBJ) Lpars.o +GENFILES= tokenfile.c \ + program.c declar.c expression.c statement.c \ + tokenfile.g symbol2str.c char.c Lpars.c Lpars.h + +all: + make LLfiles + make main + +LLfiles: $(LSRC) + $(GEN) $(GENOPTIONS) $(LSRC) + @touch LLfiles + +main: $(OBJ) Makefile + $(CC) $(LFLAGS) $(OBJ) $(LIBDIR)/libcomp.a /user1/erikb/em/lib/libstr.a /user1/erikb/lib/libsystem.a -o main + size main + +clean: + rm -f $(OBJ) $(GENFILES) LLfiles + +tokenfile.g: tokenname.c make.tokfile + make.tokfile tokenfile.g + +symbol2str.c: tokenname.c make.tokcase + make.tokcase symbol2str.c + +idlist.h: idlist.H make.allocd + +char.c: char.tab tab + ./tab -fchar.tab >char.c + +tab: + $(CC) tab.c -o tab + +depend: + sed '/^#AUTOAUTO/,$$d' Makefile > Makefile.new + echo '#AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO' >> Makefile.new + /user1/erikb/bin/mkdep `sources $(OBJ)` |\ + sed 's/\.c:/\.o:/' >> Makefile.new + mv Makefile Makefile.old + mv Makefile.new Makefile + +.SUFFIXES: .H .h .C +.H.h .C.c : + make.allocd < $< > $@ + +#AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO +LLlex.o: LLlex.h Lpars.h class.h f_info.h idf.h param.h +LLmessage.o: LLlex.h Lpars.h f_info.h idf.h +char.o: class.h +error.o: LLlex.h f_info.h +main.o: LLlex.h Lpars.h f_info.h idf.h +symbol2str.o: Lpars.h +tokenname.o: Lpars.h idf.h tokenname.h +idf.o: idf.h +input.o: f_info.h input.h +idlist.o: idf.h idlist.h +tokenfile.o: Lpars.h +program.o: Lpars.h idf.h idlist.h +declar.o: LLlex.h Lpars.h idf.h idlist.h +expression.o: Lpars.h +statement.o: Lpars.h +Lpars.o: Lpars.h diff --git a/lang/m2/comp/char.tab b/lang/m2/comp/char.tab new file mode 100644 index 00000000..53b2d69d --- /dev/null +++ b/lang/m2/comp/char.tab @@ -0,0 +1,54 @@ +% character tables for mod2 compiler +% $Header$ +%S129 +%F %s, +% +% CHARACTER CLASSES +% +%C +STGARB:\000-\200 +STSKIP: \r\t +STNL:\012\013\014 +STSIMP:#&()*+,-/;=[]^{|}~ +STCOMP:.:<> +STIDF:a-zA-Z +STSTR:"' +STNUM:0-9 +STEOI:\200 +%T#include "class.h" +%Tchar tkclass[] = { +%p +%T}; +% +% INIDF +% +%C +1:a-zA-Z_0-9 +%Tchar inidf[] = { +%F %s, +%p +%T}; +% +% ISDIG +% +%C +1:0-9 +%Tchar isdig[] = { +%p +%T}; +% +% ISHEX +% +%C +1:a-fA-F +%Tchar ishex[] = { +%p +%T}; +% +% ISOCT +% +%C +1:0-7 +%Tchar isoct[] = { +%p +%T}; diff --git a/lang/m2/comp/class.h b/lang/m2/comp/class.h new file mode 100644 index 00000000..322ac050 --- /dev/null +++ b/lang/m2/comp/class.h @@ -0,0 +1,38 @@ +/* U S E O F C H A R A C T E R C L A S S E S */ + +/* $Header$ */ + +/* As a starter, chars are divided into classes, according to which + token they can be the start of. + At present such a class number is supposed to fit in 4 bits. +*/ + +#define class(ch) (tkclass[ch]) + +/* Being the start of a token is, fortunately, a mutual exclusive + property, so, as there are less than 16 classes they can be + packed in 4 bits. +*/ + +#define STSKIP 0 /* spaces and so on: skipped characters */ +#define STNL 1 /* newline character(s): update linenumber etc. */ +#define STGARB 2 /* garbage ascii character: not allowed */ +#define STSIMP 3 /* this character can occur as token */ +#define STCOMP 4 /* this one can start a compound token */ +#define STIDF 5 /* being the initial character of an identifier */ +#define STCHAR 6 /* the starter of a character constant */ +#define STSTR 7 /* the starter of a string */ +#define STNUM 8 /* the starter of a numeric constant */ +#define STEOI 9 /* End-Of-Information mark */ + +/* But occurring inside a token is not, so we need 1 bit for each + class. This is implemented as a collection of tables to speed up + the decision whether a character has a special meaning. +*/ +#define in_idf(ch) (inidf[ch]) +#define is_oct(ch) (isoct[ch]) +#define is_dig(ch) (isdig[ch]) +#define is_hex(ch) (ishex[ch]) + +extern char tkclass[]; +extern char inidf[], isoct[], isdig[], ishex[]; diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g new file mode 100644 index 00000000..f1f77a05 --- /dev/null +++ b/lang/m2/comp/declar.g @@ -0,0 +1,181 @@ +{ +#include "idf.h" +#include "idlist.h" +#include "LLlex.h" + +static char *RcsId = "$Header$"; +} + +ProcedureDeclaration: + ProcedureHeading ';' block IDENT +; + +ProcedureHeading: + PROCEDURE IDENT FormalParameters? +; + +block: + declaration* [ BEGIN StatementSequence ]? END +; + +declaration: + CONST [ ConstantDeclaration ';' ]* +| + TYPE [ TypeDeclaration ';' ]* +| + VAR [ VariableDeclaration ';' ]* +| + ProcedureDeclaration ';' +| + ModuleDeclaration ';' +; + +FormalParameters: + '(' [ FPSection [ ';' FPSection ]* ]? ')' + [ ':' qualident ]? +; + +FPSection +{ + struct id_list *FPList; +} : + VAR? IdentList(&FPList) ':' FormalType +; + +FormalType: + [ ARRAY OF ]? qualident +; + +TypeDeclaration: + IDENT '=' type +; + +type: + SimpleType +| + ArrayType +| + RecordType +| + SetType +| + PointerType +| + ProcedureType +; + +SimpleType: + qualident + [ + + | + SubrangeType + /* + * The subrange type is given a base type by the + * qualident (this is new modula-2). + */ + ] +| + enumeration +| + SubrangeType +; + +enumeration +{ + struct id_list *EnumList; +} : + '(' IdentList(&EnumList) ')' +; + +IdentList(struct id_list **p;) +{ + register struct id_list *q = new_id_list(); +} : + IDENT { q->id_ptr = dot.TOK_IDF; } + [ + ',' IDENT { q->next = new_id_list(); + q = q->next; + q->id_ptr = dot.TOK_IDF; + } + ]* + { q->next = 0; + *p = q; + } +; + +SubrangeType: + /* + This is not exactly the rule in the new report, but see + the rule for "SimpleType". + */ + '[' ConstExpression UPTO ConstExpression ']' +; + +ArrayType: + ARRAY SimpleType [ ',' SimpleType ]* OF type +; + +RecordType: + RECORD FieldListSequence END +; + +FieldListSequence: + FieldList [ ';' FieldList ]* +; + +FieldList +{ + struct id_list *FldList; +} : +[ + IdentList(&FldList) ':' type +| + CASE IDENT? /* Changed rule in new modula-2 */ + ':' qualident + OF variant [ '|' variant ]* + [ ELSE FieldListSequence ]? + END +]? +; + +variant: + [ CaseLabelList ':' FieldListSequence ]? + /* Changed rule in new modula-2 */ +; + +CaseLabelList: + CaseLabels [ ',' CaseLabels ]* +; + +CaseLabels: + ConstExpression [ UPTO ConstExpression ]? +; + +SetType: + SET OF SimpleType +; + +PointerType: + POINTER TO type +; + +ProcedureType: + PROCEDURE FormalTypeList? +; + +FormalTypeList: + '(' [ VAR? FormalType [ ',' VAR? FormalType ]* ]? ')' + [ ':' qualident ]? +; + +ConstantDeclaration: + IDENT '=' ConstExpression +; + +VariableDeclaration +{ + struct id_list *VarList; +} : + IdentList(&VarList) ':' type +; diff --git a/lang/m2/comp/error.c b/lang/m2/comp/error.c new file mode 100644 index 00000000..3e04da2e --- /dev/null +++ b/lang/m2/comp/error.c @@ -0,0 +1,170 @@ +/* E R R O R A N D D I A G N O S T I C R O U T I N E S */ + +/* This file contains the (non-portable) error-message and diagnostic + giving functions. Be aware that they are called with a variable + number of arguments! +*/ + +#include +#include "input.h" +#include "f_info.h" +#include "LLlex.h" + +static char *RcsId = "$Header$"; + +#define ERROUT stderr + +#define ERROR 1 +#define WARNING 2 +#define LEXERROR 3 +#define LEXWARNING 4 +#define CRASH 5 +#define FATAL 6 +#define NONFATAL 7 +#ifdef DEBUG +#define VDEBUG 8 +#endif DEBUG + +int err_occurred; +/* + extern int ofd; /* compact.c * / + #define compiling (ofd >= 0) +*/ + +extern char options[]; + +/* There are two general error message giving functions: + error() : syntactic and semantic error messages + lexerror() : lexical and pre-processor error messages + The difference lies in the fact that the first function deals with + tokens already read in by the lexical analyzer so the name of the + file it comes from and the linenumber must be retrieved from the + token instead of looking at the global variables LineNumber and + FileName. +*/ + +/*VARARGS1*/ +error(fmt, args) + char *fmt; +{ + /* + if (compiling) + C_ms_err(); + */ + ++err_occurred; + _error(ERROR, fmt, &args); +} + +#ifdef DEBUG +debug(fmt, args) + char *fmt; +{ + if (options['D']) + _error(VDEBUG, fmt, &args); +} +#endif DEBUG + +/*VARARGS1*/ +lexerror(fmt, args) + char *fmt; +{ + /* + if (compiling) + C_ms_err(); + */ + ++err_occurred; + _error(LEXERROR, fmt, &args); +} + +/*VARARGS1*/ +lexwarning(fmt, args) char *fmt; { + if (options['w']) return; + _error(LEXWARNING, fmt, &args); +} + +/*VARARGS1*/ +crash(fmt, args) + char *fmt; + int args; +{ + /* + if (compiling) + C_ms_err(); + */ + _error(CRASH, fmt, &args); + fflush(ERROUT); + fflush(stderr); + fflush(stdout); + /* + cclose(); + */ + abort(); /* produce core by "Illegal Instruction" */ + /* this should be changed into exit(1) */ +} + +/*VARARGS1*/ +fatal(fmt, args) + char *fmt; + int args; +{ + /* + if (compiling) + C_ms_err(); + */ + _error(FATAL, fmt, &args); + exit(-1); +} + +/*VARARGS1*/ +nonfatal(fmt, args) + char *fmt; + int args; +{ + _error(NONFATAL, fmt, &args); +} + +/*VARARGS1*/ +warning(fmt, args) + char *fmt; +{ + if (options['w']) return; + _error(WARNING, fmt, &args); +} + +_error(class, fmt, argv) + int class; + char *fmt; + int argv[]; +{ + + switch (class) { + + case ERROR: + case LEXERROR: + fprintf(ERROUT, "%s, line %ld: ", FileName, LineNumber); + break; + case WARNING: + case LEXWARNING: + fprintf(ERROUT, "%s, line %ld: (warning) ", + FileName, LineNumber); + break; + case CRASH: + fprintf(ERROUT, "CRASH\007 %s, line %ld: \n", + FileName, LineNumber); + break; + case FATAL: + fprintf(ERROUT, "%s, line %ld: fatal error -- ", + FileName, LineNumber); + break; + case NONFATAL: + fprintf(ERROUT, "warning: "); /* no line number ??? */ + break; +#ifdef DEBUG + case VDEBUG: + fprintf(ERROUT, "-D "); + break; +#endif DEBUG + } + _doprnt(fmt, argv, ERROUT); + fprintf(ERROUT, "\n"); +} diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g new file mode 100644 index 00000000..c56441ff --- /dev/null +++ b/lang/m2/comp/expression.g @@ -0,0 +1,97 @@ +{ +static char *RcsId = "$Header$"; +} + +number: + INTEGER +| + REAL +; + +qualident: + IDENT selector* +; + +selector: + '.' /* field */ IDENT +; + +ExpList: + expression [ ',' expression ]* +; + +ConstExpression: + expression + /* + * Changed rule in new Modula-2. + * Check that the expression is a constant expression and evaluate! + */ +; + +expression: + SimpleExpression [ relation SimpleExpression ]? +; + +relation: + '=' | '#' | UNEQUAL | '<' | LESSEQUAL | '>' | GREATEREQUAL | IN +; + +SimpleExpression: + [ '+' | '-' ]? term [ AddOperator term ]* +; + +AddOperator: + '+' | '-' | OR +; + +term: + factor [ MulOperator factor ]* +; + +MulOperator: + '*' | '/' | DIV | MOD | AND | '&' +; + +factor: + qualident + [ + designator_tail? ActualParameters? + | + bare_set + ] +| + bare_set +| %default + number +| + STRING +| + '(' expression ')' +| + NOT factor +; + +bare_set: + '{' [ element [ ',' element ]* ]? '}' +; + +ActualParameters: + '(' ExpList? ')' +; + +element: + expression [ UPTO expression ]? +; + +designator: + qualident designator_tail? +; + +designator_tail: + visible_designator_tail + [ selector | visible_designator_tail ]* +; + +visible_designator_tail: + '[' ExpList ']' | '^' +; diff --git a/lang/m2/comp/f_info.h b/lang/m2/comp/f_info.h new file mode 100644 index 00000000..c04496ad --- /dev/null +++ b/lang/m2/comp/f_info.h @@ -0,0 +1,11 @@ +/* $Header$ */ + +struct f_info { + unsigned int f_lineno; + char *f_filename; + char *f_workingdir; +}; + +extern struct f_info file_info; +#define LineNumber file_info.f_lineno +#define FileName file_info.f_filename diff --git a/lang/m2/comp/idf.c b/lang/m2/comp/idf.c new file mode 100644 index 00000000..d1b0380a --- /dev/null +++ b/lang/m2/comp/idf.c @@ -0,0 +1,4 @@ +/* $Header$ */ + +#include "idf.h" +#include diff --git a/lang/m2/comp/idf.h b/lang/m2/comp/idf.h new file mode 100644 index 00000000..46f7af0e --- /dev/null +++ b/lang/m2/comp/idf.h @@ -0,0 +1,5 @@ +/* $Header$ */ + +#define IDF_TYPE int +#define id_reserved id_user +#include diff --git a/lang/m2/comp/idlist.H b/lang/m2/comp/idlist.H new file mode 100644 index 00000000..9d320bb9 --- /dev/null +++ b/lang/m2/comp/idlist.H @@ -0,0 +1,12 @@ +/* $Header$ */ + +#include + +/* Structure to link idf structures together +*/ +struct id_list { + struct id_list *next; + struct idf *id_ptr; +}; + +/* ALLOCDEF "id_list" */ diff --git a/lang/m2/comp/idlist.c b/lang/m2/comp/idlist.c new file mode 100644 index 00000000..3b067af2 --- /dev/null +++ b/lang/m2/comp/idlist.c @@ -0,0 +1,20 @@ +static char *RcsId = "$Header$"; + +#include "idf.h" +#include "idlist.h" + +struct id_list *h_id_list; /* Header of free list */ + +/* FreeIdList: take a list of id_list structures and put them + on the free list of id_list structures +*/ +FreeIdList(p) + struct id_list *p; +{ + register struct id_list *q; + + while (q = p) { + p = p->next; + free_id_list(q); + } +} diff --git a/lang/m2/comp/input.c b/lang/m2/comp/input.c new file mode 100644 index 00000000..a55c4fd5 --- /dev/null +++ b/lang/m2/comp/input.c @@ -0,0 +1,6 @@ +/* $Header$ */ + +#include "f_info.h" +struct f_info file_info; +#include "input.h" +#include diff --git a/lang/m2/comp/input.h b/lang/m2/comp/input.h new file mode 100644 index 00000000..3fcb7b8b --- /dev/null +++ b/lang/m2/comp/input.h @@ -0,0 +1,7 @@ +/* $Header$ */ + +#define INP_NPUSHBACK 2 +#define INP_TYPE struct f_info +#define INP_VAR file_info +#define INP_READ_IN_ONE +#include diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c new file mode 100644 index 00000000..ba0b0b97 --- /dev/null +++ b/lang/m2/comp/main.c @@ -0,0 +1,121 @@ +/* mod2 -- compiler , althans: een aanzet daartoe */ + +#include +#undef BUFSIZ /* Really neccesary??? */ +#include +#include "input.h" +#include "f_info.h" +#include "idf.h" +#include "LLlex.h" +#include "Lpars.h" + +static char *RcsId = "$Header:"; + +char options[128]; +char *ProgName; +extern int err_occurred; + +main(argc, argv) + char *argv[]; +{ + register Nargc = 1; + register char **Nargv = &argv[0]; + + ProgName = *argv++; + +# ifdef DEBUG + setbuf(stdout, (char *) 0); +# endif + while (--argc > 0) { + if (**argv == '-') + Option(*argv++); + else + Nargv[Nargc++] = *argv++; + } + Nargv[Nargc] = 0; /* terminate the arg vector */ + if (Nargc != 2) { + fprintf(stderr, "%s: Use one file argument\n", ProgName); + return 1; + } +#ifdef DEBUG + printf("Mod2 compiler -- Debug version\n"); + debug("-D: Debugging on"); +#endif DEBUG + return !Compile(Nargv[1]); +} + +Compile(src) + char *src; +{ + extern struct tokenname tkidf[]; + +#ifdef DEBUG + printf("%s\n", src); +#endif DEBUG + if (! InsertFile(src, (char **) 0)) { + fprintf(stderr,"%s: cannot open %s\n", ProgName, src); + return 0; + } + LineNumber = 1; + FileName = src; + init_idf(); + reserve(tkidf); +#ifdef DEBUG + if (options['L']) + LexScan(); + else if (options['T']) + TimeScan(); + else +#endif DEBUG + CompUnit(); +#ifdef DEBUG + if (options['h']) hash_stat(); +#endif DEBUG + if (err_occurred) return 0; + return 1; +} + +#ifdef DEBUG +LexScan() +{ + register int symb; + + while ((symb = LLlex()) != EOF) { + printf(">>> %s ", symbol2str(symb)); + switch(symb) { + + case IDENT: + printf("%s\n", dot.TOK_IDF->id_text); + break; + + case INTEGER: + printf("%ld\n", dot.TOK_INT); + break; + + case REAL: + printf("%s\n", dot.TOK_REL); + break; + + case STRING: + printf("\"%s\"\n", dot.TOK_STR); + break; + + default: + putchar('\n'); + } + } +} + +TimeScan() { + while (LLlex() != EOF) /* nothing */; +} +#endif + +Option(str) + char *str; +{ +#ifdef DEBUG + debug("option %c", str[1]); +#endif DEBUG + options[str[1]]++; /* switch option on */ +} diff --git a/lang/m2/comp/make.allocd b/lang/m2/comp/make.allocd new file mode 100755 index 00000000..450584aa --- /dev/null +++ b/lang/m2/comp/make.allocd @@ -0,0 +1,17 @@ +sed -e ' +s:^.*[ ]ALLOCDEF[ ].*"\(.*\)".*$:\ +/* allocation definitions of struct \1 */\ +extern char *st_alloc();\ +extern struct \1 *h_\1;\ +#define new_\1() ((struct \1 *) \\\ + st_alloc((char **)\&h_\1, sizeof(struct \1)))\ +#define free_\1(p) st_free(p, h_\1, sizeof(struct \1))\ +:' -e ' +s:^.*[ ]STATICALLOCDEF[ ].*"\(.*\)".*$:\ +/* allocation definitions of struct \1 */\ +extern char *st_alloc();\ +static struct \1 *h_\1;\ +#define new_\1() ((struct \1 *) \\\ + st_alloc((char **)\&h_\1, sizeof(struct \1)))\ +#define free_\1(p) st_free(p, h_\1, sizeof(struct \1))\ +:' diff --git a/lang/m2/comp/make.tokcase b/lang/m2/comp/make.tokcase new file mode 100755 index 00000000..ef32292f --- /dev/null +++ b/lang/m2/comp/make.tokcase @@ -0,0 +1,34 @@ +cat <<'--EOT--' +#include "Lpars.h" + +char * +symbol2str(tok) + int tok; +{ + static char buf[2] = { '\0', '\0' }; + + if (040 <= tok && tok < 0177) { + buf[0] = tok; + buf[1] = '\0'; + return buf; + } + switch (tok) { +--EOT-- +sed ' +/{[A-Z]/!d +s/.*{\(.*\),.*\(".*"\).*$/ case \1 :\ + return \2;/ +' +cat <<'--EOT--' + case '\n': + case '\f': + case '\v': + case '\r': + case '\t': + buf[0] = tok; + return buf; + default: + return "bad token"; + } +} +--EOT-- diff --git a/lang/m2/comp/make.tokfile b/lang/m2/comp/make.tokfile new file mode 100755 index 00000000..494b7e3c --- /dev/null +++ b/lang/m2/comp/make.tokfile @@ -0,0 +1,6 @@ +sed ' +/{[A-Z]/!d +s/.*{// +s/,.*// +s/.*/%token &;/ +' diff --git a/lang/m2/comp/param.h b/lang/m2/comp/param.h new file mode 100644 index 00000000..cd4d2cba --- /dev/null +++ b/lang/m2/comp/param.h @@ -0,0 +1,4 @@ +/* $Header$ */ + +#define IDFSIZE 256 +#define NUMSIZE 256 diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g new file mode 100644 index 00000000..89eef00a --- /dev/null +++ b/lang/m2/comp/program.g @@ -0,0 +1,116 @@ +/* + Program: Modula-2 grammar in LL(1) form + Version: Mon Feb 24 14:29:39 MET 1986 +*/ + +/* + The grammar as given by Wirth is already almost LL(1); the + main problem is that the full form of a qualified designator + may be: + [ module_ident '.' ]* IDENT [ '.' field_ident ]* + which is quite confusing to an LL(1) parser. Rather than + resorting to context-sensitive techniques, I have decided + to render this as: + IDENT [ '.' IDENT ]* + on the grounds that it is quite natural to consider the first + IDENT to be the name of the object and regard the others as + field identifiers. +*/ + +{ +#include "idf.h" +#include "idlist.h" + +static char *RcsId = "$Header$"; +} + +%lexical LLlex; + +%start CompUnit, CompilationUnit; + +ModuleDeclaration: + MODULE IDENT priority? ';' import* export? block IDENT +; + +priority: + '[' ConstExpression ']' +; + +export +{ + struct id_list *ExportList; +} : + EXPORT QUALIFIED? IdentList(&ExportList) ';' +; + +import +{ + struct id_list *ImportList; +} : + [ FROM + IDENT + ]? + IMPORT IdentList(&ImportList) ';' + /* + When parsing a global module, this is the place where we must + read already compiled definition modules. + If the FROM clause is present, the identifier in it is a module + name, otherwise the names in the import list are module names. + */ +; + +DefinitionModule: + DEFINITION + { +#ifdef DEBUG + debug("Definition module"); +#endif DEBUG + } + MODULE IDENT ';' import* + /* export? + + New Modula-2 does not have export lists in definition modules. + */ + definition* END IDENT '.' +; + +definition: + CONST [ ConstantDeclaration ';' ]* +| + TYPE + [ IDENT + [ '=' type + | /* empty */ + /* + Here, the exported type has a hidden implementation. + The export is said to be opaque. + It is restricted to pointer types. + */ + ] + ';' + ]* +| + VAR [ VariableDeclaration ';' ]* +| + ProcedureHeading ';' +; + +ProgramModule: + MODULE + { +#ifdef DEBUG + debug("Program module"); +#endif DEBUG + } + IDENT priority? ';' import* block IDENT '.' +; + +Module: + DefinitionModule +| + IMPLEMENTATION? ProgramModule +; + +CompilationUnit: + Module +; diff --git a/lang/m2/comp/statement.g b/lang/m2/comp/statement.g new file mode 100644 index 00000000..3e736a5a --- /dev/null +++ b/lang/m2/comp/statement.g @@ -0,0 +1,98 @@ +{ +static char *RcsId = "$Header$"; +} + +statement: +[ + /* + * This part is not in the reference grammar. The reference grammar + * states : assignment | ProcedureCall | ... + * but this gives LL(1) conflicts + */ + designator + [ + ActualParameters? + | + BECOMES expression + ] + /* + * end of changed part + */ +| + IfStatement +| + CaseStatement +| + WhileStatement +| + RepeatStatement +| + LoopStatement +| + ForStatement +| + WithStatement +| + EXIT +| + RETURN expression? +]? +; + +/* + * The next two rules in-line in "Statement", because of an LL(1) conflict + +assignment: + designator BECOMES expression +; + +ProcedureCall: + designator ActualParameters? +; +*/ + +StatementSequence: + statement [ ';' statement ]* +; + +IfStatement: + IF expression THEN StatementSequence + [ ELSIF expression THEN StatementSequence ]* + [ ELSE StatementSequence ]? + END +; + +CaseStatement: + CASE expression OF case [ '|' case ]* + [ ELSE StatementSequence ]? + END +; + +case: + [ CaseLabelList ':' StatementSequence ]? + /* This rule is changed in new modula-2 */ +; + +WhileStatement: + WHILE expression DO StatementSequence END +; + +RepeatStatement: + REPEAT StatementSequence UNTIL expression +; + +ForStatement: + FOR IDENT + BECOMES expression + TO expression + [ BY ConstExpression ]? + DO StatementSequence END +; + +LoopStatement: + LOOP StatementSequence END +; + +WithStatement: + WITH designator DO StatementSequence END +; diff --git a/lang/m2/comp/tab.c b/lang/m2/comp/tab.c new file mode 100644 index 00000000..17065cf9 --- /dev/null +++ b/lang/m2/comp/tab.c @@ -0,0 +1,295 @@ +/* @cc tab.c -o $INSTALLDIR/tab@ + tab - table generator + + Author: Erik Baalbergen (..tjalk!erikb) +*/ + +#include + +static char *RcsId = "$Header$"; + +#define MAXTAB 10000 +#define MAXBUF 10000 +#define COMCOM '-' +#define FILECOM '%' + +int InputForm = 'c'; +char OutputForm[MAXBUF] = "%s,\n"; +int TabSize = 257; +char *Table[MAXTAB]; +char *Name; +char *ProgCall; + +main(argc, argv) + char *argv[]; +{ + ProgCall = *argv++; + argc--; + while (argc-- > 0) { + if (**argv == COMCOM) { + option(*argv++); + } + else { + process(*argv++, InputForm); + } + } +} + +char * +Salloc(s) + char *s; +{ + char *malloc(); + char *ns = malloc(strlen(s) + 1); + + if (ns) { + strcpy(ns, s); + } + return ns; +} + +option(str) + char *str; +{ + /* note that *str indicates the source of the option: + either COMCOM (from command line) or FILECOM (from a file). + */ + switch (*++str) { + + case ' ': /* command */ + case '\t': + case '\0': + break; + case 'I': + InputForm = *++str; + break; + case 'f': + if (*++str == '\0') { + fprintf(stderr, "%s: -f: name expected\n", ProgCall); + exit(1); + } + DoFile(str); + break; + case 'F': + sprintf(OutputForm, "%s\n", ++str); + break; + case 'T': + printf("%s\n", ++str); + break; + case 'p': + PrintTable(); + break; + case 'C': + ClearTable(); + break; + case 'S': + { + register i = stoi(++str); + + if (i <= 0 || i > MAXTAB) { + fprintf(stderr, "%s: size would exceed maximum\n", + ProgCall); + } + else { + TabSize = i; + } + break; + } + default: + fprintf(stderr, "%s: bad option -%s\n", ProgCall, str); + } +} + +ClearTable() +{ + register i; + + for (i = 0; i < MAXTAB; i++) { + Table[i] = 0; + } +} + +PrintTable() +{ + register i; + + for (i = 0; i < TabSize; i++) { + if (Table[i]) { + printf(OutputForm, Table[i]); + } + else { + printf(OutputForm, "0"); + } + } +} + +process(str, format) + char *str; +{ + char *cstr = str; + char *Name = cstr; /* overwrite original string! */ + + /* strip of the entry name + */ + while (*str && *str != ':') { + if (*str == '\\') { + ++str; + } + *cstr++ = *str++; + } + + if (*str != ':') { + fprintf(stderr, "%s: bad specification: \"%s\", ignored\n", + ProgCall, Name); + return 0; + } + *cstr = '\0'; + str++; + + switch (format) { + + case 'c': + return c_proc(str, Name); + default: + fprintf(stderr, "%s: bad input format\n", ProgCall); + } + return 0; +} + +c_proc(str, Name) + char *str; + char *Name; +{ + int ch, ch2; + int quoted(); + + while (*str) { + if (*str == '\\') { + ch = quoted(&str); + } + else { + ch = *str++; + } + if (*str == '-') { + if (*++str == '\\') { + ch2 = quoted(&str); + } + else { + if (ch2 = *str++); + else str--; + } + if (ch > ch2) { + fprintf(stderr, "%s: bad range\n", ProgCall); + return 0; + } + if (ch >= 0 && ch2 <= 255) + while (ch <= ch2) + Table[ch++] = Salloc(Name); + } + else { + if (ch >= 0 && ch <= 255) + Table[ch] = Salloc(Name); + } + } + return 1; +} + +int +quoted(pstr) + char **pstr; +{ + register int ch; + register int i; + register char *str = *pstr; + + if ((*++str >= '0') && (*str <= '9')) { + ch = 0; + for (i = 0; i < 3; i++) { + ch = 8 * ch + *str - '0'; + if (*++str < '0' || *str > '9') + break; + } + } + else { + switch (*str++) { + + case 'n': + ch = '\n'; + break; + case 't': + ch = '\t'; + break; + case 'b': + ch = '\b'; + break; + case 'r': + ch = '\r'; + break; + case 'f': + ch = '\f'; + break; + default : + ch = *str; + } + } + *pstr = str; + return ch & 0377; +} + +int +stoi(str) + char *str; +{ + register i = 0; + + while (*str >= '0' && *str <= '9') { + i = i * 10 + *str++ - '0'; + } + return i; +} + +char * +getline(s, n, fp) + char *s; + FILE *fp; +{ + register c = getc(fp); + char *str = s; + + while (n--) { + if (c == EOF) { + return NULL; + } + else + if (c == '\n') { + *str++ = '\0'; + return s; + } + *str++ = c; + c = getc(fp); + } + s[n - 1] = '\0'; + return s; +} + +#define BUFSIZE 1024 + +DoFile(name) + char *name; +{ + char text[BUFSIZE]; + FILE *fp; + + if ((fp = fopen(name, "r")) == NULL) { + fprintf(stderr, "%s: cannot read file %s\n", ProgCall, name); + exit(1); + } + while (getline(text, BUFSIZE, fp) != NULL) { + if (text[0] == FILECOM) { + option(text); + } + else { + process(text, InputForm); + } + } +} diff --git a/lang/m2/comp/tokenname.c b/lang/m2/comp/tokenname.c new file mode 100644 index 00000000..32e658a1 --- /dev/null +++ b/lang/m2/comp/tokenname.c @@ -0,0 +1,99 @@ +#include "tokenname.h" +#include "Lpars.h" +#include "idf.h" + +/* To centralize the declaration of %tokens, their presence in this + file is taken as their declaration. The Makefile will produce + a grammar file (tokenfile.g) from this file. This scheme ensures + that all tokens have a printable name. + Also, the "token2str.c" file is produced from this file. +*/ + +static char *RcsId = "$Header$"; + +struct tokenname tkspec[] = { /* the names of the special tokens */ + {IDENT, "identifier"}, + {STRING, "string"}, + {INTEGER, "integer"}, + {REAL, "real"}, + {0, ""} +}; + +struct tokenname tkcomp[] = { /* names of the composite tokens */ + {UNEQUAL, "<>"}, + {LESSEQUAL, "<="}, + {GREATEREQUAL, ">="}, + {UPTO, ".."}, + {BECOMES, ":="}, + {0, ""} +}; + +struct tokenname tkidf[] = { /* names of the identifier tokens */ + {AND, "AND"}, + {ARRAY, "ARRAY"}, + {BEGIN, "BEGIN"}, + {BY, "BY"}, + {CASE, "CASE"}, + {CONST, "CONST"}, + {DEFINITION, "DEFINITION"}, + {DIV, "DIV"}, + {DO, "DO"}, + {ELSE, "ELSE"}, + {ELSIF, "ELSIF"}, + {END, "END"}, + {EXIT, "EXIT"}, + {EXPORT, "EXPORT"}, + {FOR, "FOR"}, + {FROM, "FROM"}, + {IF, "IF"}, + {IMPLEMENTATION, "IMPLEMENTATION"}, + {IMPORT, "IMPORT"}, + {IN, "IN"}, + {LOOP, "LOOP"}, + {MOD, "MOD"}, + {MODULE, "MODULE"}, + {NOT, "NOT"}, + {OF, "OF"}, + {OR, "OR"}, + {POINTER, "POINTER"}, + {PROCEDURE, "PROCEDURE"}, + {QUALIFIED, "QUALIFIED"}, + {RECORD, "RECORD"}, + {REPEAT, "REPEAT"}, + {RETURN, "RETURN"}, + {SET, "SET"}, + {THEN, "THEN"}, + {TO, "TO"}, + {TYPE, "TYPE"}, + {UNTIL, "UNTIL"}, + {VAR, "VAR"}, + {WHILE, "WHILE"}, + {WITH, "WITH"}, + {0, ""} +}; + +struct tokenname tkinternal[] = { /* internal keywords */ + {0, "0"} +}; + +struct tokenname tkstandard[] = { /* standard identifiers */ + {0, ""} +}; + +/* Some routines to handle tokennames */ + +reserve(resv) + register struct tokenname *resv; +{ + /* The names of the tokens described in resv are entered + as reserved words. + */ + register struct idf *p; + + while (resv->tn_symbol) { + p = str2idf(resv->tn_name, 0); + if (!p) fatal("Out of Memory"); + p->id_reserved = resv->tn_symbol; + resv++; + } +} diff --git a/lang/m2/comp/tokenname.h b/lang/m2/comp/tokenname.h new file mode 100644 index 00000000..2b545da4 --- /dev/null +++ b/lang/m2/comp/tokenname.h @@ -0,0 +1,7 @@ +/* $Header$ */ +struct tokenname { /* Used for defining the name of a + token as identified by its symbol + */ + int tn_symbol; + char *tn_name; +}; From 3fc938f8c5b2e970de9860bc73d4d13d3424338e Mon Sep 17 00:00:00 2001 From: erikb Date: Fri, 21 Mar 1986 13:26:28 +0000 Subject: [PATCH 0145/1625] fixed a garbage collection problem --- lang/cem/cemcom/expr.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lang/cem/cemcom/expr.c b/lang/cem/cemcom/expr.c index 11cef82f..3e4fcacf 100644 --- a/lang/cem/cemcom/expr.c +++ b/lang/cem/cemcom/expr.c @@ -379,7 +379,6 @@ chk_cst_expr(expp) } if (err) { - free_expression(expr); erroneous2int(expp); (*expp)->ex_type = error_type; } From 2ab00b6e06068c811333a709a0da73c9d770c8ec Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 24 Mar 1986 17:29:57 +0000 Subject: [PATCH 0146/1625] some improvements --- lang/m2/comp/LLlex.c | 172 ++++++++++++++++++++---------------------- lang/m2/comp/LLlex.h | 1 + lang/m2/comp/Makefile | 7 +- lang/m2/comp/declar.g | 6 +- lang/m2/comp/main.c | 2 +- 5 files changed, 94 insertions(+), 94 deletions(-) diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index 7380c3fe..17c92ad2 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -10,37 +10,97 @@ #include "LLlex.h" long str2long(); -char *GetString(); struct token dot, aside; static char *RcsId = "$Header$"; +/* Skip Modula-2 like comment (* ... *). + Note that comment may be nested. +*/ +static +SkipComment() +{ + register int ch; + register int NestLevel = 0; + + LoadChar(ch); + for (;;) { + if (class(ch) == STNL) { + LineNumber++; + } + else + if (ch == '(') { + LoadChar(ch); + if (ch == '*') { + ++NestLevel; + } + else { + continue; + } + } + else + if (ch == '*') { + LoadChar(ch); + if (ch == ')') { + if (NestLevel-- == 0) { + return; + } + } + else { + continue; + } + } + LoadChar(ch); + } +} + +static char * +GetString(upto) +{ + register int ch; + int str_size; + char *str = Malloc(str_size = 32); + register int pos = 0; + + LoadChar(ch); + while (ch != upto) { + if (class(ch) == STNL) { + lexerror("newline in string"); + LineNumber++; + break; + } + if (ch == EOI) { + lexerror("end-of-file in string"); + break; + } + str[pos++] = ch; + if (pos == str_size) { + str = Srealloc(str, str_size += 8); + } + LoadChar(ch); + } + str[pos] = '\0'; + return str; +} + +/* LLlex() plays the role of Lexical Analyzer for the parser. + The putting aside of tokens is taken into account. +*/ int LLlex() { - /* LLlex() plays the role of Lexical Analyzer for the parser. - The putting aside of tokens is taken into account. - */ - if (ASIDE) { /* a token is put aside */ - dot = aside; - ASIDE = 0; - } - else { - GetToken(&dot); - if (DOT == EOI) DOT = -1; - } - - return DOT; -} - -int -GetToken(tk) - register struct token *tk; -{ + register struct token *tk = ˙ char buf[(IDFSIZE > NUMSIZE ? IDFSIZE : NUMSIZE) + 1]; register int ch, nch; + if (ASIDE) { /* a token is put aside */ + *tk = aside; + ASIDE = 0; + return tk->tk_symb; + } + tk->tk_lineno = LineNumber; + again: LoadChar(ch); if ((ch & 0200) && ch != EOI) { @@ -54,6 +114,7 @@ again: case STNL: LineNumber++; + tk->tk_lineno++; goto again; case STGARB: @@ -305,79 +366,12 @@ Sdec: } case STEOI: - return tk->tk_symb = EOI; + return tk->tk_symb = -1; case STCHAR: default: crash("bad character class %d", class(ch)); } + /*NOTREACHED*/ } -char * -GetString(upto) -{ - register int ch; - int str_size; - char *str = Malloc(str_size = 32); - register int pos = 0; - - LoadChar(ch); - while (ch != upto) { - if (class(ch) == STNL) { - lexerror("newline in string"); - LineNumber++; - break; - } - if (ch == EOI) { - lexerror("end-of-file in string"); - break; - } - str[pos++] = ch; - if (pos == str_size) { - str = Srealloc(str, str_size += 8); - } - LoadChar(ch); - } - str[pos] = '\0'; - return str; -} - -SkipComment() -{ - /* Skip Modula-2 like comment (* ... *). - Note that comment may be nested. - */ - - register int ch; - register int NestLevel = 0; - - LoadChar(ch); - for (;;) { - if (class(ch) == STNL) { - LineNumber++; - } - else - if (ch == '(') { - LoadChar(ch); - if (ch == '*') { - ++NestLevel; - } - else { - continue; - } - } - else - if (ch == '*') { - LoadChar(ch); - if (ch == ')') { - if (NestLevel-- == 0) { - return; - } - } - else { - continue; - } - } - LoadChar(ch); - } -} diff --git a/lang/m2/comp/LLlex.h b/lang/m2/comp/LLlex.h index e6a2dd81..594a0cf5 100644 --- a/lang/m2/comp/LLlex.h +++ b/lang/m2/comp/LLlex.h @@ -4,6 +4,7 @@ struct token { int tk_symb; /* token itself */ + int tk_lineno; /* linenumber on which it occurred */ union { struct idf *tk_idf; /* IDENT */ char *tk_str; /* STRING */ diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index c367db29..e0c74595 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -4,12 +4,13 @@ HDIR = ../../em/h PKGDIR = ../../em/pkg LIBDIR = ../../em/lib -INCLUDES = -I$(HDIR) -I$(PKGDIR) -I/user1/erikb/h +INCLUDES = -I$(HDIR) -I$(PKGDIR) -I/user1/erikb/em/h LSRC = tokenfile.g program.g declar.g expression.g statement.g CC = cc GEN = LLgen GENOPTIONS = -CFLAGS = -DDEBUG -O $(INCLUDES) +CFLAGS = -DDEBUG -p $(INCLUDES) +LFLAGS = -p LOBJ = tokenfile.o program.o declar.o expression.o statement.o COBJ = LLlex.o LLmessage.o char.o error.o main.o \ symbol2str.o tokenname.o idf.o input.o idlist.o @@ -27,7 +28,7 @@ LLfiles: $(LSRC) @touch LLfiles main: $(OBJ) Makefile - $(CC) $(LFLAGS) $(OBJ) $(LIBDIR)/libcomp.a /user1/erikb/em/lib/libstr.a /user1/erikb/lib/libsystem.a -o main + $(CC) $(LFLAGS) $(OBJ) $(LIBDIR)/libcomp.a $(LIBDIR)/malloc.o /user1/erikb/em/lib/libstr.a /user1/erikb/em/lib/libsystem.a -o main size main clean: diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index f1f77a05..c3cc67c9 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -177,5 +177,9 @@ VariableDeclaration { struct id_list *VarList; } : - IdentList(&VarList) ':' type + IdentList(&VarList) + [ + ConstExpression + ]? + ':' type ; diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index ba0b0b97..b0cfbc3f 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -9,7 +9,7 @@ #include "LLlex.h" #include "Lpars.h" -static char *RcsId = "$Header:"; +static char *RcsId = "$Header$"; char options[128]; char *ProgName; From 80b36104efc7ead3ad048261f362ba1b8f48b5a6 Mon Sep 17 00:00:00 2001 From: erikb Date: Tue, 25 Mar 1986 10:39:23 +0000 Subject: [PATCH 0147/1625] adapted to the system(3L) interface --- lang/cem/cemcom/Files | 2 - lang/cem/cemcom/Makefile.erik | 32 ++++++------ lang/cem/cemcom/Parameters | 6 +-- lang/cem/cemcom/alloc.c | 22 ++++---- lang/cem/cemcom/code.c | 2 +- lang/cem/cemcom/em.c | 24 +++++---- lang/cem/cemcom/error.c | 8 +-- lang/cem/cemcom/init.c | 6 +-- lang/cem/cemcom/input.c | 95 ++++++++++++++++++----------------- lang/cem/cemcom/main.c | 51 +++++++++---------- lang/cem/cemcom/stack.c | 15 +++--- lang/cem/cemcom/string.c | 14 +++--- 12 files changed, 137 insertions(+), 140 deletions(-) diff --git a/lang/cem/cemcom/Files b/lang/cem/cemcom/Files index e0660c63..2d585286 100644 --- a/lang/cem/cemcom/Files +++ b/lang/cem/cemcom/Files @@ -86,8 +86,6 @@ struct.c struct.str switch.c switch.str -system.c -system.h tab.c tokenname.c tokenname.h diff --git a/lang/cem/cemcom/Makefile.erik b/lang/cem/cemcom/Makefile.erik index 4997c57e..af30e957 100644 --- a/lang/cem/cemcom/Makefile.erik +++ b/lang/cem/cemcom/Makefile.erik @@ -7,6 +7,11 @@ EM = /usr/em# # where to find the ACK tree ACK = $(EM)/bin/ack# # old ACK C compiler EM_INCLUDES =$(EM)/h# # directory containing EM interface definition +# Libraries +SYSLIB = /user1/erikb/em/lib/libsystem.a +LIBS = $(SYSLIB) +LIB_INCLUDES = /user1/erikb/em/h + # Where to install the compiler and its driver CEMCOM = $(BIN)/cemcom DRIVER = $(BIN)/cem @@ -22,7 +27,7 @@ GEN = /user0/ceriel/bin/LLgen GENOPTIONS = -vv # Special #defines during compilation -CDEFS = $(MAP) -I$(EM_INCLUDES) +CDEFS = $(MAP) -I$(EM_INCLUDES) -I$(LIB_INCLUDES) CFLAGS = $(CDEFS) $(COPTIONS) -O# # we cannot pass the COPTIONS to lint! # Grammar files and their objects @@ -37,7 +42,7 @@ COBJ = main.o idf.o declarator.o decspecs.o struct.o \ input.o domacro.o replace.o init.o options.o \ scan.o skip.o stack.o type.o ch7mon.o label.o eval.o \ switch.o storage.o ival.o conversion.o \ - em.o blocks.o dataflow.o system.o string.o + em.o blocks.o dataflow.o string.o # Objects of other generated C files GOBJ = char.o symbol2str.o next.o writeem.o @@ -54,7 +59,7 @@ GHSRC = botch_free.h dataflow.h debug.h density.h errout.h \ maxincl.h myalloc.h nobitfield.h nopp.h \ nparams.h numsize.h parbufsize.h pathlength.h predefine.h \ proc_intf.h strsize.h target_sizes.h textsize.h use_tmp.h \ - bufsiz.h str_params.h spec_arith.h + str_params.h spec_arith.h # Other generated files, for 'make clean' only GENERATED = tab tokenfile.g Lpars.h LLfiles LL.output lint.out \ @@ -76,7 +81,7 @@ cc: make main cem: cem.c string.o - $(CC) -O cem.c string.o -o cem + $(CC) -O cem.c string.o $(SYSLIB) -o cem lint.cem: cem.c string.c lint -abx cem.c @@ -124,7 +129,7 @@ writeem.h: make.emmac emcode.def OBJ = $(COBJ) $(LOBJ) $(GOBJ) main: $(OBJ) Makefile - $(CC) $(COPTIONS) $(LFLAGS) $(OBJ) -o main + $(CC) $(COPTIONS) $(LFLAGS) $(OBJ) $(LIBS) -o main size main cfiles: hfiles LLfiles $(GSRC) @@ -184,7 +189,7 @@ sim: cfiles $(SIM) $(SIMFLAGS) `sources $(COBJ)` $(GSRC) $(LSRC) #AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO -main.o: LLlex.h Lpars.h alloc.h arith.h bufsiz.h debug.h declar.h idf.h input.h inputtype.h level.h maxincl.h myalloc.h nobitfield.h nopp.h spec_arith.h specials.h system.h target_sizes.h tokenname.h type.h use_tmp.h +main.o: LLlex.h Lpars.h alloc.h arith.h debug.h declar.h idf.h input.h inputtype.h level.h maxincl.h myalloc.h nobitfield.h nopp.h spec_arith.h specials.h target_sizes.h tokenname.h type.h use_tmp.h idf.o: LLlex.h Lpars.h align.h alloc.h arith.h assert.h botch_free.h debug.h declar.h decspecs.h def.h idf.h idfsize.h label.h level.h nobitfield.h nopp.h sizes.h spec_arith.h specials.h stack.h storage.h struct.h type.h declarator.o: Lpars.h alloc.h arith.h botch_free.h declar.h expr.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h type.h decspecs.o: Lpars.h arith.h decspecs.h def.h level.h nobitfield.h spec_arith.h type.h @@ -194,22 +199,22 @@ ch7.o: Lpars.h arith.h assert.h debug.h def.h expr.h idf.h label.h nobitfield.h ch7bin.o: Lpars.h arith.h botch_free.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h storage.h struct.h type.h cstoper.o: Lpars.h arith.h expr.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h target_sizes.h type.h arith.o: Lpars.h alloc.h arith.h botch_free.h expr.h field.h idf.h label.h mes.h nobitfield.h nopp.h spec_arith.h storage.h type.h -alloc.o: alloc.h assert.h debug.h myalloc.h system.h +alloc.o: alloc.h assert.h debug.h myalloc.h code.o: LLlex.h Lpars.h alloc.h arith.h assert.h atw.h botch_free.h code.h dataflow.h debug.h declar.h decspecs.h def.h em.h expr.h idf.h label.h level.h mes.h nobitfield.h nopp.h proc_intf.h sizes.h spec_arith.h specials.h stack.h storage.h type.h use_tmp.h writeem.h dumpidf.o: Lpars.h arith.h debug.h def.h expr.h field.h idf.h label.h nobitfield.h nopp.h spec_arith.h stack.h struct.h type.h -error.o: LLlex.h arith.h debug.h em.h errout.h expr.h label.h nopp.h proc_intf.h spec_arith.h string.h system.h tokenname.h use_tmp.h writeem.h +error.o: LLlex.h arith.h debug.h em.h errout.h expr.h label.h nopp.h proc_intf.h spec_arith.h string.h tokenname.h use_tmp.h writeem.h field.o: Lpars.h arith.h assert.h code.h debug.h em.h expr.h field.h idf.h label.h nobitfield.h nopp.h proc_intf.h sizes.h spec_arith.h type.h writeem.h tokenname.o: LLlex.h Lpars.h arith.h idf.h nopp.h spec_arith.h tokenname.h LLlex.o: LLlex.h Lpars.h alloc.h arith.h assert.h class.h debug.h def.h idf.h idfsize.h input.h nopp.h numsize.h sizes.h spec_arith.h strsize.h LLmessage.o: LLlex.h Lpars.h alloc.h arith.h idf.h nopp.h spec_arith.h -input.o: LLlex.h alloc.h arith.h assert.h bufsiz.h debug.h idepth.h input.h inputtype.h interface.h nopp.h pathlength.h spec_arith.h system.h +input.o: LLlex.h alloc.h arith.h assert.h debug.h idepth.h input.h inputtype.h interface.h nopp.h pathlength.h spec_arith.h domacro.o: LLlex.h Lpars.h alloc.h arith.h assert.h botch_free.h class.h debug.h idf.h idfsize.h ifdepth.h input.h interface.h macro.h nopp.h nparams.h parbufsize.h spec_arith.h storage.h textsize.h replace.o: LLlex.h alloc.h arith.h assert.h class.h debug.h idf.h input.h interface.h macro.h nopp.h pathlength.h spec_arith.h string.h strsize.h -init.o: alloc.h class.h idf.h interface.h macro.h nopp.h predefine.h string.h system.h +init.o: alloc.h class.h idf.h interface.h macro.h nopp.h predefine.h string.h options.o: align.h arith.h class.h idf.h idfsize.h macro.h maxincl.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h scan.o: class.h idf.h input.h interface.h lapbuf.h macro.h nopp.h nparams.h skip.o: LLlex.h arith.h class.h input.h interface.h nopp.h spec_arith.h -stack.o: Lpars.h alloc.h arith.h botch_free.h debug.h def.h em.h idf.h level.h mes.h nobitfield.h nopp.h proc_intf.h spec_arith.h stack.h storage.h struct.h system.h type.h use_tmp.h writeem.h +stack.o: Lpars.h alloc.h arith.h botch_free.h debug.h def.h em.h idf.h level.h mes.h nobitfield.h nopp.h proc_intf.h spec_arith.h stack.h storage.h struct.h type.h use_tmp.h writeem.h type.o: Lpars.h align.h alloc.h arith.h def.h idf.h nobitfield.h nopp.h sizes.h spec_arith.h type.h ch7mon.o: Lpars.h arith.h botch_free.h def.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h storage.h type.h label.o: Lpars.h arith.h def.h idf.h label.h level.h nobitfield.h nopp.h spec_arith.h type.h @@ -218,11 +223,10 @@ switch.o: arith.h assert.h botch_free.h code.h debug.h density.h em.h expr.h idf storage.o: alloc.h assert.h botch_free.h debug.h storage.h ival.o: Lpars.h align.h arith.h assert.h class.h debug.h def.h em.h expr.h field.h idf.h label.h level.h nobitfield.h nopp.h proc_intf.h sizes.h spec_arith.h string.h struct.h type.h writeem.h conversion.o: Lpars.h arith.h em.h nobitfield.h proc_intf.h sizes.h spec_arith.h type.h writeem.h -em.o: arith.h bufsiz.h em.h label.h proc_intf.h spec_arith.h system.h writeem.h +em.o: arith.h em.h label.h proc_intf.h spec_arith.h writeem.h blocks.o: arith.h atw.h em.h proc_intf.h sizes.h spec_arith.h writeem.h dataflow.o: dataflow.h -system.o: inputtype.h system.h -string.o: arith.h nopp.h spec_arith.h str_params.h string.h system.h +string.o: arith.h nopp.h spec_arith.h str_params.h string.h tokenfile.o: Lpars.h declar.o: LLlex.h Lpars.h arith.h debug.h declar.h decspecs.h def.h expr.h field.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h struct.h type.h statement.o: LLlex.h Lpars.h arith.h botch_free.h code.h debug.h def.h em.h expr.h idf.h label.h nobitfield.h nopp.h proc_intf.h spec_arith.h stack.h storage.h type.h writeem.h diff --git a/lang/cem/cemcom/Parameters b/lang/cem/cemcom/Parameters index f0757da2..09c7a9d7 100644 --- a/lang/cem/cemcom/Parameters +++ b/lang/cem/cemcom/Parameters @@ -13,7 +13,7 @@ !File: errout.h -#define ERROUT stderr /* file pointer for writing messages */ +#define ERROUT STDERR /* file pointer for writing messages */ #define MAXERR_LINE 5 /* maximum number of error messages given on the same input line. */ @@ -134,10 +134,6 @@ #define SSIZE 1024 /* string-buffer size for print routines */ -!File: bufsiz.h -#define BUFSIZ 1024 /* system block size */ - - !File: spec_arith.h /* describes internal compiler arithmetics */ #undef SPECIAL_ARITHMETICS /* something different from native long */ diff --git a/lang/cem/cemcom/alloc.c b/lang/cem/cemcom/alloc.c index 064c2f09..b7f4df85 100644 --- a/lang/cem/cemcom/alloc.c +++ b/lang/cem/cemcom/alloc.c @@ -23,21 +23,19 @@ Salloc(str, sz) : save string in malloc storage */ +#include #include "myalloc.h" /* UF */ #include "debug.h" /* UF */ #include "alloc.h" #include "assert.h" -#include "system.h" #ifdef OWNALLOC - -#define SBRK_ERROR ((char *) -1) /* errors during allocation */ - +char *sys_break(); /* the following variables are used for book-keeping */ -static int nfreebytes = 0; /* # free bytes in sys_sbrk-ed space */ +static int nfreebytes = 0; /* # free bytes in sys_break space */ static char *freeb; /* pointer to first free byte */ -static char *lastalloc; /* pointer to last malloced sp */ +static char *lastalloc; /* pointer to last malloced sp */ static int lastnbytes; /* nr of bytes in last allocated */ /* space */ static char *firstfreeb = 0; @@ -75,11 +73,11 @@ malloc(n) register nbts = (n <= ALLOCSIZ) ? ALLOCSIZ : n; if (!nfreebytes) { - if ((freeb = sys_sbrk(nbts)) == SBRK_ERROR) + if ((freeb = sys_break(nbts)) == ILL_BREAK) fatal("out of memory"); } else { - if (sys_sbrk(nbts) == SBRK_ERROR) + if (sys_break(nbts) == ILL_BREAK) fatal("out of memory"); } nfreebytes += nbts; @@ -118,7 +116,7 @@ realloc(ptr, n) nbytes = ALIGN(nbytes); if (nfreebytes < nbytes) { register int nbts = (nbytes < ALLOCSIZ) ? ALLOCSIZ : nbytes; - if (sys_sbrk(nbts) == SBRK_ERROR) + if (sys_break(nbts) == ILL_BREAK) fatal("out of memory"); nfreebytes += nbts; } @@ -136,13 +134,13 @@ free(p) init_mem() { - firstfreeb = sys_sbrk(0); + firstfreeb = sys_break(0); /* align the first memory unit to ALIGNSIZE ??? */ if ((long) firstfreeb % ALIGNSIZE != 0) { register char *fb = firstfreeb; fb = (char *)ALIGN((long)fb); - firstfreeb = sys_sbrk(fb - firstfreeb); + firstfreeb = sys_break(fb - firstfreeb); firstfreeb = fb; ASSERT((long)firstfreeb % ALIGNSIZE == 0); } @@ -155,7 +153,7 @@ mem_stat() if (options['m']) printf("Total nr of bytes allocated: %d\n", - sys_sbrk(0) - firstfreeb); + sys_break(0) - firstfreeb); } #endif DEBUG #endif OWNALLOC diff --git a/lang/cem/cemcom/code.c b/lang/cem/cemcom/code.c index c3e8e923..5e2e7365 100644 --- a/lang/cem/cemcom/code.c +++ b/lang/cem/cemcom/code.c @@ -78,7 +78,7 @@ prepend_scopes(dst_file) struct stack_entry *se = local_level->sl_entry; if (C_open(dst_file) == 0) - fatal("cannot create file %s", dst_file); + fatal("cannot create %s", dst_file ? dst_file : "stdout"); famous_first_words(); while (se != 0) { struct idf *idf = se->se_idf; diff --git a/lang/cem/cemcom/em.c b/lang/cem/cemcom/em.c index bc3ae5cf..7bd0bd10 100644 --- a/lang/cem/cemcom/em.c +++ b/lang/cem/cemcom/em.c @@ -5,8 +5,7 @@ #define MAX_ARG_CNT 32 #include "em.h" -#include "system.h" -#include "bufsiz.h" +#include #include "arith.h" #include "label.h" @@ -21,17 +20,18 @@ */ /* supply a kind of buffered output */ -#define flush(x) sys_write(ofd, &obuf[0], x); +#define flush(x) sys_write(ofp, &obuf[0], x) static char obuf[BUFSIZ]; static char *opp = &obuf[0]; -int ofd = -1; +File *ofp = 0; putbyte(b) /* shouldn't putbyte() be a macro ??? (EB) */ int b; { if (opp >= &obuf[BUFSIZ]) { /* flush if buffer overflows */ - flush(BUFSIZ); + if (flush(BUFSIZ) == 0) + sys_stop(S_ABORT); opp = &obuf[0]; } *opp++ = (char) b; @@ -45,24 +45,26 @@ C_open(nm) /* open file for compact code output */ char *nm; { if (nm == 0) - ofd = 1; /* standard output */ + ofp = STDOUT; /* standard output */ else - if ((ofd = sys_creat(nm, CMODE)) < 0) + if (sys_open(nm, OP_WRITE, &ofp) == 0) return 0; return 1; } C_close() { - flush(opp - &obuf[0]); + if (flush(opp - &obuf[0]) == 0) + sys_stop(S_ABORT); opp = obuf; /* reset opp */ - sys_close(ofd); - ofd = -1; + if (ofp != STDOUT) + sys_close(ofp); + ofp = 0; } C_busy() { - return ofd >= 0; /* true if code is being generated */ + return ofp != 0; /* true if code is being generated */ } /*** the compact code generating routines ***/ diff --git a/lang/cem/cemcom/error.c b/lang/cem/cemcom/error.c index 51d06b69..f29e72cd 100644 --- a/lang/cem/cemcom/error.c +++ b/lang/cem/cemcom/error.c @@ -1,11 +1,11 @@ /* $Header$ */ /* E R R O R A N D D I A G N O S T I C R O U T I N E S */ +#include #include "nopp.h" #include "use_tmp.h" #include "errout.h" #include "debug.h" -#include "system.h" #include "string.h" #include "tokenname.h" @@ -96,9 +96,9 @@ crash(fmt, args) _error(CRASH, NILEXPR, fmt, &args); C_close(); #ifdef DEBUG - sys_stop(S_ABORT, 0); + sys_stop(S_ABORT); #else DEBUG - sys_stop(S_EXIT, 1); + sys_stop(S_EXIT); #endif DEBUG } @@ -115,7 +115,7 @@ fatal(fmt, args) #endif USE_TMP _error(FATAL, NILEXPR, fmt, &args); - sys_stop(S_EXIT, 1); + sys_stop(S_EXIT); } _error(class, expr, fmt, argv) diff --git a/lang/cem/cemcom/init.c b/lang/cem/cemcom/init.c index dbb5dec2..bd145643 100644 --- a/lang/cem/cemcom/init.c +++ b/lang/cem/cemcom/init.c @@ -4,13 +4,13 @@ #include "nopp.h" #ifndef NOPP +#include #include "predefine.h" /* UF */ #include "alloc.h" #include "class.h" #include "macro.h" #include "idf.h" #include "interface.h" -#include "system.h" #include "string.h" PRIVATE struct mkey { @@ -33,7 +33,7 @@ PRIVATE struct mkey { EXPORT init_pp() { - time_type clock; + long clock; static char date[30]; char *ctime(); @@ -62,7 +62,7 @@ init_pp() "pdp" are predefined macros. */ /* __DATE__ */ - clock = sys_time((time_type *) 0); + clock = sys_time(); strcpy(&date[1], ctime(&clock)); date[26] = '\0'; /* zap nl */ date[0] = date[25] = '"'; diff --git a/lang/cem/cemcom/input.c b/lang/cem/cemcom/input.c index 2838d823..45db4371 100644 --- a/lang/cem/cemcom/input.c +++ b/lang/cem/cemcom/input.c @@ -30,6 +30,7 @@ a fixed length input buffer */ +#include #include "nopp.h" #include "inputtype.h" /* UF */ #include "interface.h" @@ -37,8 +38,6 @@ #include "LLlex.h" #include "input.h" #include "alloc.h" -#include "system.h" -#include "bufsiz.h" #ifndef NOPP #include "idepth.h" /* UF */ @@ -51,7 +50,7 @@ EXPORT char *ipp = 0; /* input pointer */ EXPORT int NoUnstack = 0; /* if 1: report EOF */ #ifndef READ_IN_ONE -PRIVATE int FilDes = -1; /* current input medium */ +PRIVATE File *FilDes = 0; /* current input medium */ #endif READ_IN_ONE #ifndef NOPP @@ -63,7 +62,7 @@ struct buffer_header { char *bh_text; /* pointer to buffer containing text */ char *bh_ipp; /* current read pointer (= stacked ipp) */ char *bh_wdir; /* directory of current file */ - int bh_fd; /* >= 0 (fd if !READ_IN_ONE) in case of file */ + File *bh_fp; /* needed for files if !READ_IN_ONE */ }; PRIVATE struct buffer_header instack[IDEPTH]; /* stack of input media */ @@ -91,27 +90,21 @@ readfile(filename, size) char *filename; long *size; { - int fd; /* filedescriptor for `filename' */ + File *fp; /* filedescriptor for `filename' */ char *cbuf; /* pointer to buffer to be returned */ - register tmp; + int tmp; + long sys_filesize(); - if ((fd = sys_open(filename, OP_RDONLY)) < 0) { - /* can't open this file */ + if (sys_open(filename, OP_READ, &fp) == 0) /* can't open this file */ return (char *) 0; - } - - if ((*size = sys_fsize(fd)) < 0) + if ((*size = sys_filesize(filename)) == -1L) fatal("(readfile) cannot get size of file"); - /* allocate enough space to store contents of the file */ cbuf = Malloc(*size + 2); - - tmp = sys_read(fd, cbuf + 1, (int) *size); /* read the file */ - if (tmp != *size) - fatal("(readfile) bad read count"); - + if (sys_read(fp, cbuf + 1, (int) *size, &tmp) == 0 || tmp != *size) + fatal("(readfile) bad read"); (*size)++; /* keep book of the size! */ - sys_close(fd); /* filedes no longer needed */ + sys_close(fp); /* filedes no longer needed */ cbuf[0] = '\0'; /* allow pushback of first char */ cbuf[*size] = '\0'; /* invoke loadbuf() at end */ return cbuf; @@ -173,7 +166,7 @@ push_bh() PRIVATE int pop_bh() { - int pfd = head->bh_fd; + File *pfp = head->bh_fp; if (NoUnstack) { lexerror("unexpected EOF"); @@ -186,9 +179,9 @@ pop_bh() ipp = (--head)->bh_ipp; /* restore the previous input pointer */ - if (pfd >= 0) { /* unstack a file */ + if (pfp != 0) { /* unstack a file */ #ifndef READ_IN_ONE - closefile(pfd); + closefile(pfp); popbuf(); /* free last buffer */ #endif READ_IN_ONE LineNumber = head->bh_lineno; @@ -197,7 +190,7 @@ pop_bh() } #ifndef READ_IN_ONE - FilDes = head->bh_fd; + FilDes = head->bh_fp; #endif READ_IN_ONE return 1; @@ -208,32 +201,36 @@ pop_bh() /* low level IO routines: openfile(), readblock() and closefile() */ -PRIVATE int +PRIVATE File * openfile(filename) char *filename; { - int fd; /* filedescriptor for `filename' */ + File *fp; - if ((fd = sys_open(filename, OP_RDONLY)) < 0 && sys_errno == EMFILE) - fatal("too many files open"); - return fd; + if (filename == 0) + return STDIN; + if (sys_open(filename, OP_READ, &fp) == 0) + return (File *)0; + return fp; } PRIVATE -closefile(fd) +closefile(fp) + File *fp; { - sys_close(fd); + if (fp != STDIN) + sys_close(fp); } PRIVATE int -readblock(fd, buf) +readblock(fp, buf) + File *fp; char buf[]; { - register n; + int n; - if ((n = sys_read(fd, &buf[1], BUFSIZ)) < 0) { - fatal("(readblock) bad read from file"); - } + if (sys_read(fp, &buf[1], BUFSIZ, &n) == 0) + fatal("(readblock) bad read"); buf[0] = buf[n + 1] = '\0'; return n; } @@ -249,16 +246,19 @@ InsertFile(filnam, table) { char *mk_filename(), *newfn; char *strcpy(); + File *openfile(); #ifdef READ_IN_ONE char *readfile(), *text; long size; #else READ_IN_ONE - int fd = -1; + File *fp = 0; #endif READ_IN_ONE +#ifdef READ_IN_ONE if (!filnam) return 0; +#endif READ_IN_ONE #ifndef NOPP if (table == 0 || filnam[0] == '/') { /* don't look in the table! */ @@ -266,17 +266,20 @@ InsertFile(filnam, table) #ifdef READ_IN_ONE text = readfile(filnam, &size); #else READ_IN_ONE - fd = openfile(filnam); + fp = openfile(filnam); + if (filnam == 0) + filnam = "standard input"; #endif READ_IN_ONE #ifndef NOPP } else { + ASSERT(filnam != 0); while (*table) { /* look in the directory table */ newfn = mk_filename(*table++, filnam); #ifdef READ_IN_ONE if (text = readfile(newfn, &size)) #else READ_IN_ONE - if ((fd = openfile(newfn)) >= 0) + if ((fp = openfile(newfn)) != 0) #endif READ_IN_ONE { /* free filnam ??? */ @@ -290,7 +293,7 @@ InsertFile(filnam, table) #ifdef READ_IN_ONE if (text) #else READ_IN_ONE - if (fd >= 0) + if (fp != 0) #endif READ_IN_ONE #ifndef NOPP { @@ -303,11 +306,11 @@ InsertFile(filnam, table) bh->bh_wdir = *WorkingDir; #ifdef READ_IN_ONE bh->bh_size = size; - bh->bh_fd = 0; /* this is a file */ + bh->bh_fp = STDIN; /* this is a file */ ipp = bh->bh_text = text; #else READ_IN_ONE - bh->bh_size = readblock(fd, ipp = bh->bh_text = pushbuf()) + 1; - FilDes = bh->bh_fd = fd; + bh->bh_size = readblock(fp, ipp = bh->bh_text = pushbuf()) + 1; + FilDes = bh->bh_fp = fp; #endif READ_IN_ONE bh->bh_text[0] = '\n'; /* wake up pp if '#' comes first */ return 1; @@ -318,7 +321,7 @@ InsertFile(filnam, table) isize = size; ipp = text; #else READ_IN_ONE - isize = readblock(FilDes = fd, ipp = &ibuf[0]) + 1; + isize = readblock(FilDes = fp, ipp = &ibuf[0]) + 1; #endif READ_IN_ONE ibuf[0] = '\n'; return 1; @@ -340,10 +343,10 @@ InsertText(text, length) bh->bh_size = (long) length; bh->bh_text = text; bh->bh_wdir = *WorkingDir; - bh->bh_fd = -1; /* this is no file ! */ + bh->bh_fp = 0; /* this is not a file ! */ ipp = text + 1; #ifndef READ_IN_ONE - FilDes = -1; + FilDes = 0; #endif READ_IN_ONE } #endif NOPP @@ -376,13 +379,13 @@ loadbuf() #ifndef READ_IN_ONE #ifndef NOPP - if ( FilDes >= 0 + if ( FilDes != 0 && (head->bh_size = readblock(FilDes, head->bh_text)) > 0 ) { return ipp = &(head->bh_text[1]), *ipp++; } #else NOPP - if (FilDes >= 0 && (isize = readblock(FilDes, &ibuf[0])) > 0) + if (FilDes != 0 && (isize = readblock(FilDes, &ibuf[0])) > 0) return ipp = &ibuf[1], *ipp++; #endif NOPP diff --git a/lang/cem/cemcom/main.c b/lang/cem/cemcom/main.c index b2e1a9d5..b0354ceb 100644 --- a/lang/cem/cemcom/main.c +++ b/lang/cem/cemcom/main.c @@ -1,15 +1,14 @@ /* $Header$ */ /* MAIN PROGRAM */ +#include #include "nopp.h" #include "target_sizes.h" #include "debug.h" #include "myalloc.h" #include "use_tmp.h" #include "maxincl.h" -#include "system.h" #include "inputtype.h" -#include "bufsiz.h" #include "input.h" #include "level.h" @@ -134,10 +133,8 @@ compile(argc, argv) int pp_only = options['E'] || options['P']; #endif NOPP - source = argv[0]; - + source = strcmp(argv[0], "-") ? argv[0] : 0; switch (argc) { - case 1: #ifndef NOPP if (!pp_only) @@ -147,7 +144,6 @@ compile(argc, argv) case 2: destination = argv[1]; break; - case 3: nmlist = argv[2]; destination = argv[1]; @@ -160,22 +156,18 @@ compile(argc, argv) #ifdef USE_TMP tmpfile = mktemp(tmpname); #endif USE_TMP - - if (!InsertFile(source, (char **) 0)) { - /* read the source file */ - fatal("%s: no source file %s\n", prog_name, source); - } + if (strcmp(destination, "-") == 0) + destination = 0; + if (!InsertFile(source, (char **) 0)) /* read the source file */ + fatal("%s: no source file %s\n", prog_name, + source ? source : "stdin"); init(); - - /* needed ??? */ - FileName = source; + /* FileName = source; /* needed ??? */ PushLex(); #ifndef NOPP - if (pp_only) { - /* run the preprocessor as if it is stand-alone */ + if (pp_only) /* run the preprocessor as if it is stand-alone */ preprocess(); - } else { #endif NOPP @@ -365,20 +357,25 @@ preprocess() AppendFile(src, dst) char *src, *dst; { - int fd_src, fd_dst; + File *fp_src, *fp_dst; char buf[BUFSIZ]; int n; - if ((fd_src = sys_open(src, OP_RDONLY)) < 0) { + if (sys_open(src, OP_READ, &fp_src) == 0) fatal("cannot read %s", src); + if (dst) { + if (sys_open(dst, OP_APPEND, &fp_dst) == 0) + fatal("cannot write to %s", src); } - if ((fd_dst = sys_open(dst, OP_APPEND)) < 0) { - fatal("cannot write to %s", src); - } - while ((n = sys_read(fd_src, buf, BUFSIZ)) > 0) { - sys_write(fd_dst, buf, n); - } - sys_close(fd_src); - sys_close(fd_dst); + else + fp_dst = STDOUT; + while (sys_read(fp_src, buf, BUFSIZ, &n) != 0 && n > 0) + if (sys_write(fp_dst, buf, n) == 0) + fatal("(AppendFile) write error"); + if (n != 0) + fatal("(AppendFile) read error"); + sys_close(fp_src); + if (fp_dst != STDOUT) + sys_close(fp_dst); } #endif USE_TMP diff --git a/lang/cem/cemcom/stack.c b/lang/cem/cemcom/stack.c index 50ed04f6..5b509b4a 100644 --- a/lang/cem/cemcom/stack.c +++ b/lang/cem/cemcom/stack.c @@ -5,7 +5,7 @@ #include "use_tmp.h" #include "botch_free.h" -#include "system.h" +#include #include "alloc.h" #include "Lpars.h" #include "arith.h" @@ -267,22 +267,19 @@ unstack_world() list is generated. */ extern char *nmlist; /* BAH! -- main.c */ -static int nfd; +static File *nfp = 0; open_name_list() { - if (nmlist) { - if ((nfd = sys_creat(nmlist, 0644)) < 0) { - fatal("cannot create namelist %s", nmlist); - } - } + if (nmlist && sys_open(nmlist, OP_WRITE, &nfp) == 0) + fatal("cannot create namelist %s", nmlist); } namelist(nm) char *nm; { if (nmlist) { - sys_write(nfd, nm, strlen(nm)); - sys_write(nfd, "\n", 1); + sys_write(nfp, nm, strlen(nm)); + sys_write(nfp, "\n", 1); } } diff --git a/lang/cem/cemcom/string.c b/lang/cem/cemcom/string.c index bb7ab486..5a61cc30 100644 --- a/lang/cem/cemcom/string.c +++ b/lang/cem/cemcom/string.c @@ -1,19 +1,20 @@ /* $Header$ */ /* STRING MANIPULATION AND PRINT ROUTINES */ +#include #include "string.h" #include "nopp.h" #include "str_params.h" #include "arith.h" -#include "system.h" -doprnt(fd, fmt, argp) +doprnt(fp, fmt, argp) + File *fp; char *fmt; int argp[]; { char buf[SSIZE]; - sys_write(fd, buf, format(buf, fmt, (char *)argp)); + sys_write(fp, buf, format(buf, fmt, (char *)argp)); } /*VARARGS1*/ @@ -23,17 +24,18 @@ printf(fmt, args) { char buf[SSIZE]; - sys_write(1, buf, format(buf, fmt, &args)); + sys_write(STDOUT, buf, format(buf, fmt, &args)); } /*VARARGS1*/ -fprintf(fd, fmt, args) +fprintf(fp, fmt, args) + File *fp; char *fmt; char args; { char buf[SSIZE]; - sys_write(fd, buf, format(buf, fmt, &args)); + sys_write(fp, buf, format(buf, fmt, &args)); } /*VARARGS1*/ From 2511f931d976c1fce677867161c3521435f15276 Mon Sep 17 00:00:00 2001 From: erikb Date: Tue, 25 Mar 1986 16:40:43 +0000 Subject: [PATCH 0148/1625] introduced the em_code(3L) and em_mes(3L) modules --- lang/cem/cemcom/Files | 5 -- lang/cem/cemcom/LLlex.c | 35 ++++++------- lang/cem/cemcom/LLlex.h | 8 ++- lang/cem/cemcom/LLmessage.c | 3 +- lang/cem/cemcom/Makefile.erik | 51 +++++++++---------- lang/cem/cemcom/Parameters | 4 -- lang/cem/cemcom/arith.h | 2 +- lang/cem/cemcom/asm.c | 3 +- lang/cem/cemcom/blocks.c | 2 +- lang/cem/cemcom/code.c | 12 +++-- lang/cem/cemcom/conversion.c | 2 +- lang/cem/cemcom/domacro.c | 6 +-- lang/cem/cemcom/error.c | 3 +- lang/cem/cemcom/eval.c | 5 +- lang/cem/cemcom/expr.c | 3 +- lang/cem/cemcom/expr.str | 4 +- lang/cem/cemcom/field.c | 3 +- lang/cem/cemcom/ival.c | 93 ++++------------------------------- lang/cem/cemcom/label.h | 3 +- lang/cem/cemcom/main.c | 9 +--- lang/cem/cemcom/stack.c | 6 ++- lang/cem/cemcom/statement.g | 11 +++-- lang/cem/cemcom/switch.c | 3 +- 23 files changed, 99 insertions(+), 177 deletions(-) diff --git a/lang/cem/cemcom/Files b/lang/cem/cemcom/Files index 2d585286..80cfbaef 100644 --- a/lang/cem/cemcom/Files +++ b/lang/cem/cemcom/Files @@ -34,9 +34,6 @@ decspecs.str def.str domacro.c dumpidf.c -em.c -em.h -emcode.def error.c eval.c expr.c @@ -58,8 +55,6 @@ level.h macro.str main.c make.allocd -make.emfun -make.emmac make.hfiles make.next make.tokcase diff --git a/lang/cem/cemcom/LLlex.c b/lang/cem/cemcom/LLlex.c index fce9dac6..22013746 100644 --- a/lang/cem/cemcom/LLlex.c +++ b/lang/cem/cemcom/LLlex.c @@ -189,8 +189,12 @@ go_on: /* rescan, the following character has been read */ case '<': if (AccFileSpecifier) { PushBack(); /* pushback nch */ - ptok->tk_str = - string_token("file specifier", '>'); + ptok->tk_bts = + string_token( + "file specifier", + '>', + &(ptok->tk_len) + ); return ptok->tk_symb = FILESPECIFIER; } if (nch == '<') @@ -310,6 +314,8 @@ go_on: /* rescan, the following character has been read */ } if (ch == '\\') { LoadChar(ch); + if (ch == '\n') + LineNumber++; ch = quoted(ch); } val = val*256 + ch; @@ -323,7 +329,7 @@ go_on: /* rescan, the following character has been read */ return ptok->tk_symb = INTEGER; } case STSTR: /* string */ - ptok->tk_str = string_token("string", '"'); + ptok->tk_bts = string_token("string", '"', &(ptok->tk_len)); return ptok->tk_symb = STRING; case STNUM: /* a numeric constant */ { @@ -466,8 +472,9 @@ skipcomment() } char * -string_token(nm, stop_char) +string_token(nm, stop_char, plen) char *nm; + int *plen; { register int ch; register int str_size; @@ -486,28 +493,18 @@ string_token(nm, stop_char) break; } if (ch == '\\') { - register int nch; - - LoadChar(nch); - if (nch == '\n') { + LoadChar(ch); + if (ch == '\n') LineNumber++; - LoadChar(ch); - continue; - } - else { - str[pos++] = '\\'; - if (pos == str_size) - str = Srealloc(str, - str_size += RSTRSIZE); - ch = nch; - } + ch = quoted(ch); } str[pos++] = ch; if (pos == str_size) str = Srealloc(str, str_size += RSTRSIZE); LoadChar(ch); } - str[pos++] = '\0'; + str[pos++] = '\0'; /* for filenames etc. */ + *plen = pos; return str; } diff --git a/lang/cem/cemcom/LLlex.h b/lang/cem/cemcom/LLlex.h index fbc18ad0..392f6664 100644 --- a/lang/cem/cemcom/LLlex.h +++ b/lang/cem/cemcom/LLlex.h @@ -13,7 +13,10 @@ struct token { unsigned int tok_line; /* the line it (probably) comes from */ union { struct idf *tok_idf; /* for IDENTIFIER & TYPE_IDENTIFIER */ - char *tok_str; /* for STRING: text */ + struct { /* for STRING */ + char *tok_bts; /* row of bytes */ + int tok_len; /* length of row of bytes */ + } tok_string; struct { /* for INTEGER */ int tok_fund; /* INT or LONG */ arith tok_ival; @@ -26,7 +29,8 @@ struct token { #define tk_file tok_file #define tk_line tok_line #define tk_idf tok_data.tok_idf -#define tk_str tok_data.tok_str +#define tk_bts tok_data.tok_string.tok_bts +#define tk_len tok_data.tok_string.tok_len #define tk_fund tok_data.tok_integer.tok_fund #define tk_ival tok_data.tok_integer.tok_ival #define tk_fval tok_data.tok_fval diff --git a/lang/cem/cemcom/LLmessage.c b/lang/cem/cemcom/LLmessage.c index acb3b9bc..78ca57d0 100644 --- a/lang/cem/cemcom/LLmessage.c +++ b/lang/cem/cemcom/LLmessage.c @@ -37,7 +37,8 @@ insert_token(tk) dot.tk_idf = str2idf("int"); break; case STRING: - dot.tk_str = Salloc("", 1); + dot.tk_bts = Salloc("", 1); + dot.tk_len = 1; break; case INTEGER: dot.tk_fund = INT; diff --git a/lang/cem/cemcom/Makefile.erik b/lang/cem/cemcom/Makefile.erik index af30e957..f2348fa4 100644 --- a/lang/cem/cemcom/Makefile.erik +++ b/lang/cem/cemcom/Makefile.erik @@ -9,7 +9,9 @@ EM_INCLUDES =$(EM)/h# # directory containing EM interface definition # Libraries SYSLIB = /user1/erikb/em/lib/libsystem.a -LIBS = $(SYSLIB) +EMLIB = /user1/erikb/em/lib/libemk.a +EMMESLIB = /user1/erikb/em/lib/libem_mes.a +LIBS = $(EMMESLIB) $(EMLIB) $(SYSLIB) LIB_INCLUDES = /user1/erikb/em/h # Where to install the compiler and its driver @@ -42,23 +44,22 @@ COBJ = main.o idf.o declarator.o decspecs.o struct.o \ input.o domacro.o replace.o init.o options.o \ scan.o skip.o stack.o type.o ch7mon.o label.o eval.o \ switch.o storage.o ival.o conversion.o \ - em.o blocks.o dataflow.o string.o + blocks.o dataflow.o string.o # Objects of other generated C files -GOBJ = char.o symbol2str.o next.o writeem.o +GOBJ = char.o symbol2str.o next.o # generated source files -GSRC = char.c symbol2str.c next.c writeem.c \ +GSRC = char.c symbol2str.c next.c \ code.h declar.h decspecs.h def.h expr.h field.h \ - idf.h macro.h stack.h struct.h switch.h type.h \ - writeem.h + idf.h macro.h stack.h struct.h switch.h type.h # .h files generated by `make hfiles'; PLEASE KEEP THIS UP-TO-DATE! GHSRC = botch_free.h dataflow.h debug.h density.h errout.h \ idepth.h idfsize.h ifdepth.h inputtype.h inumlength.h lapbuf.h \ maxincl.h myalloc.h nobitfield.h nopp.h \ nparams.h numsize.h parbufsize.h pathlength.h predefine.h \ - proc_intf.h strsize.h target_sizes.h textsize.h use_tmp.h \ + strsize.h target_sizes.h textsize.h use_tmp.h \ str_params.h spec_arith.h # Other generated files, for 'make clean' only @@ -119,12 +120,6 @@ struct.h: make.allocd switch.h: make.allocd type.h: make.allocd -writeem.c: make.emfun emcode.def - ./make.emfun emcode.def >writeem.c - -writeem.h: make.emmac emcode.def - ./make.emmac emcode.def >writeem.h - # Objects needed for 'main' OBJ = $(COBJ) $(LOBJ) $(GOBJ) @@ -199,40 +194,38 @@ ch7.o: Lpars.h arith.h assert.h debug.h def.h expr.h idf.h label.h nobitfield.h ch7bin.o: Lpars.h arith.h botch_free.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h storage.h struct.h type.h cstoper.o: Lpars.h arith.h expr.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h target_sizes.h type.h arith.o: Lpars.h alloc.h arith.h botch_free.h expr.h field.h idf.h label.h mes.h nobitfield.h nopp.h spec_arith.h storage.h type.h -alloc.o: alloc.h assert.h debug.h myalloc.h -code.o: LLlex.h Lpars.h alloc.h arith.h assert.h atw.h botch_free.h code.h dataflow.h debug.h declar.h decspecs.h def.h em.h expr.h idf.h label.h level.h mes.h nobitfield.h nopp.h proc_intf.h sizes.h spec_arith.h specials.h stack.h storage.h type.h use_tmp.h writeem.h +alloc.o: alloc.h assert.h debug.h myalloc.h +code.o: LLlex.h Lpars.h alloc.h arith.h assert.h atw.h botch_free.h code.h dataflow.h debug.h declar.h decspecs.h def.h expr.h idf.h label.h level.h mes.h nobitfield.h nopp.h sizes.h spec_arith.h specials.h stack.h storage.h type.h use_tmp.h dumpidf.o: Lpars.h arith.h debug.h def.h expr.h field.h idf.h label.h nobitfield.h nopp.h spec_arith.h stack.h struct.h type.h -error.o: LLlex.h arith.h debug.h em.h errout.h expr.h label.h nopp.h proc_intf.h spec_arith.h string.h tokenname.h use_tmp.h writeem.h -field.o: Lpars.h arith.h assert.h code.h debug.h em.h expr.h field.h idf.h label.h nobitfield.h nopp.h proc_intf.h sizes.h spec_arith.h type.h writeem.h +error.o: LLlex.h arith.h debug.h errout.h expr.h label.h nopp.h spec_arith.h string.h tokenname.h use_tmp.h +field.o: Lpars.h arith.h assert.h code.h debug.h expr.h field.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h type.h tokenname.o: LLlex.h Lpars.h arith.h idf.h nopp.h spec_arith.h tokenname.h LLlex.o: LLlex.h Lpars.h alloc.h arith.h assert.h class.h debug.h def.h idf.h idfsize.h input.h nopp.h numsize.h sizes.h spec_arith.h strsize.h LLmessage.o: LLlex.h Lpars.h alloc.h arith.h idf.h nopp.h spec_arith.h -input.o: LLlex.h alloc.h arith.h assert.h debug.h idepth.h input.h inputtype.h interface.h nopp.h pathlength.h spec_arith.h +input.o: LLlex.h alloc.h arith.h assert.h debug.h idepth.h input.h inputtype.h interface.h nopp.h pathlength.h spec_arith.h domacro.o: LLlex.h Lpars.h alloc.h arith.h assert.h botch_free.h class.h debug.h idf.h idfsize.h ifdepth.h input.h interface.h macro.h nopp.h nparams.h parbufsize.h spec_arith.h storage.h textsize.h replace.o: LLlex.h alloc.h arith.h assert.h class.h debug.h idf.h input.h interface.h macro.h nopp.h pathlength.h spec_arith.h string.h strsize.h -init.o: alloc.h class.h idf.h interface.h macro.h nopp.h predefine.h string.h +init.o: alloc.h class.h idf.h interface.h macro.h nopp.h predefine.h string.h options.o: align.h arith.h class.h idf.h idfsize.h macro.h maxincl.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h scan.o: class.h idf.h input.h interface.h lapbuf.h macro.h nopp.h nparams.h skip.o: LLlex.h arith.h class.h input.h interface.h nopp.h spec_arith.h -stack.o: Lpars.h alloc.h arith.h botch_free.h debug.h def.h em.h idf.h level.h mes.h nobitfield.h nopp.h proc_intf.h spec_arith.h stack.h storage.h struct.h type.h use_tmp.h writeem.h +stack.o: Lpars.h alloc.h arith.h botch_free.h debug.h def.h idf.h level.h mes.h nobitfield.h nopp.h spec_arith.h stack.h storage.h struct.h type.h use_tmp.h type.o: Lpars.h align.h alloc.h arith.h def.h idf.h nobitfield.h nopp.h sizes.h spec_arith.h type.h ch7mon.o: Lpars.h arith.h botch_free.h def.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h storage.h type.h label.o: Lpars.h arith.h def.h idf.h label.h level.h nobitfield.h nopp.h spec_arith.h type.h -eval.o: Lpars.h align.h arith.h assert.h atw.h code.h dataflow.h debug.h def.h em.h expr.h idf.h label.h level.h mes.h nobitfield.h nopp.h proc_intf.h sizes.h spec_arith.h stack.h string.h type.h writeem.h -switch.o: arith.h assert.h botch_free.h code.h debug.h density.h em.h expr.h idf.h label.h nobitfield.h nopp.h proc_intf.h spec_arith.h storage.h switch.h type.h writeem.h +eval.o: Lpars.h align.h arith.h assert.h atw.h code.h dataflow.h debug.h def.h expr.h idf.h label.h level.h mes.h nobitfield.h nopp.h sizes.h spec_arith.h stack.h string.h type.h +switch.o: Lpars.h arith.h assert.h botch_free.h code.h debug.h density.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h storage.h switch.h type.h storage.o: alloc.h assert.h botch_free.h debug.h storage.h -ival.o: Lpars.h align.h arith.h assert.h class.h debug.h def.h em.h expr.h field.h idf.h label.h level.h nobitfield.h nopp.h proc_intf.h sizes.h spec_arith.h string.h struct.h type.h writeem.h -conversion.o: Lpars.h arith.h em.h nobitfield.h proc_intf.h sizes.h spec_arith.h type.h writeem.h -em.o: arith.h em.h label.h proc_intf.h spec_arith.h writeem.h -blocks.o: arith.h atw.h em.h proc_intf.h sizes.h spec_arith.h writeem.h +ival.o: Lpars.h align.h arith.h assert.h class.h debug.h def.h expr.h field.h idf.h label.h level.h nobitfield.h nopp.h sizes.h spec_arith.h string.h struct.h type.h +conversion.o: Lpars.h arith.h nobitfield.h sizes.h spec_arith.h type.h +blocks.o: arith.h atw.h sizes.h spec_arith.h dataflow.o: dataflow.h -string.o: arith.h nopp.h spec_arith.h str_params.h string.h +string.o: arith.h nopp.h spec_arith.h str_params.h string.h tokenfile.o: Lpars.h declar.o: LLlex.h Lpars.h arith.h debug.h declar.h decspecs.h def.h expr.h field.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h struct.h type.h -statement.o: LLlex.h Lpars.h arith.h botch_free.h code.h debug.h def.h em.h expr.h idf.h label.h nobitfield.h nopp.h proc_intf.h spec_arith.h stack.h storage.h type.h writeem.h +statement.o: LLlex.h Lpars.h arith.h botch_free.h code.h debug.h def.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h stack.h storage.h type.h expression.o: LLlex.h Lpars.h arith.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h type.h program.o: LLlex.h Lpars.h alloc.h arith.h code.h declar.h decspecs.h def.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h type.h Lpars.o: Lpars.h char.o: class.h symbol2str.o: Lpars.h -writeem.o: arith.h em.h label.h proc_intf.h spec_arith.h writeem.h diff --git a/lang/cem/cemcom/Parameters b/lang/cem/cemcom/Parameters index 09c7a9d7..1ae2b459 100644 --- a/lang/cem/cemcom/Parameters +++ b/lang/cem/cemcom/Parameters @@ -95,10 +95,6 @@ #define DEBUG 1 /* perform various self-tests */ -!File: proc_intf.h -#define PROC_INTF 1 /* compile with procedural EM interface */ - - !File: use_tmp.h #define USE_TMP 1 /* collect exa, exp, ina and inp commands and let them precede the rest of diff --git a/lang/cem/cemcom/arith.h b/lang/cem/cemcom/arith.h index 551f7c90..2e94f70b 100644 --- a/lang/cem/cemcom/arith.h +++ b/lang/cem/cemcom/arith.h @@ -13,7 +13,7 @@ #ifndef SPECIAL_ARITHMETICS -#define arith long /* native */ +#include /* obtain definition of "arith" */ #else SPECIAL_ARITHMETICS diff --git a/lang/cem/cemcom/asm.c b/lang/cem/cemcom/asm.c index 21daf1f5..3b8cd1f9 100644 --- a/lang/cem/cemcom/asm.c +++ b/lang/cem/cemcom/asm.c @@ -1,8 +1,9 @@ /* $Header$ */ /* A S M */ -asm_seen(s) +asm_seen(s, l) char *s; + int l; { /* 'asm' '(' string ')' ';' */ diff --git a/lang/cem/cemcom/blocks.c b/lang/cem/cemcom/blocks.c index 799402e9..3e4640d3 100644 --- a/lang/cem/cemcom/blocks.c +++ b/lang/cem/cemcom/blocks.c @@ -1,7 +1,7 @@ /* $Header$ */ /* B L O C K S T O R I N G A N D L O A D I N G */ -#include "em.h" +#include #include "arith.h" #include "sizes.h" #include "atw.h" diff --git a/lang/cem/cemcom/code.c b/lang/cem/cemcom/code.c index 5e2e7365..689daaa9 100644 --- a/lang/cem/cemcom/code.c +++ b/lang/cem/cemcom/code.c @@ -1,6 +1,8 @@ /* $Header$ */ /* C O D E - G E N E R A T I N G R O U T I N E S */ +#include + #include "dataflow.h" #include "use_tmp.h" #include "botch_free.h" @@ -15,7 +17,6 @@ #include "expr.h" #include "sizes.h" #include "stack.h" -#include "em.h" #include "level.h" #include "decspecs.h" #include "declar.h" @@ -113,13 +114,13 @@ code_scope(text, def) if (fund == FUNCTION) C_exp(text); else - C_exa(text); + C_exa_dnam(text); break; case STATIC: if (fund == FUNCTION) C_inp(text); else - C_ina(text); + C_ina_dnam(text); break; } } @@ -175,7 +176,10 @@ begin_proc(name, def) /* to be called when entering a procedure */ if (strcmp(last_fn_given, FileName) != 0) { /* previous function came from other file */ C_df_dlb(file_name_label = data_label()); - C_con_scon(last_fn_given = FileName, (arith)0); + C_con_scon( + last_fn_given = FileName, + (arith)(strlen(FileName) + 1) + ); } /* enable debug trace of EM source */ C_fil_dlb(file_name_label, (arith)0); diff --git a/lang/cem/cemcom/conversion.c b/lang/cem/cemcom/conversion.c index 07188d6c..b74f779b 100644 --- a/lang/cem/cemcom/conversion.c +++ b/lang/cem/cemcom/conversion.c @@ -1,9 +1,9 @@ /* $Header$ */ /* C O N V E R S I O N - C O D E G E N E R A T O R */ +#include #include "arith.h" #include "type.h" -#include "em.h" #include "sizes.h" #include "Lpars.h" diff --git a/lang/cem/cemcom/domacro.c b/lang/cem/cemcom/domacro.c index f2d76d9e..b0afb18d 100644 --- a/lang/cem/cemcom/domacro.c +++ b/lang/cem/cemcom/domacro.c @@ -229,7 +229,7 @@ do_include() AccFileSpecifier = 1; if (((tok = GetToken(&tk)) == FILESPECIFIER) || tok == STRING) - filenm = tk.tk_str; + filenm = tk.tk_bts; else { lexerror("bad include syntax"); filenm = (char *)0; @@ -393,7 +393,7 @@ do_line(l) LineNumber = l; /* is there a filespecifier? */ if (GetToken(&tk) == STRING) - FileName = tk.tk_str; + FileName = tk.tk_bts; SkipRestOfLine(); } @@ -652,7 +652,7 @@ domacro() } LineNumber = tk.tk_ival; if ((tok = GetToken(&tk)) == STRING) - FileName = tk.tk_str; + FileName = tk.tk_bts; else if (tok != EOI) { error("illegal # line"); diff --git a/lang/cem/cemcom/error.c b/lang/cem/cemcom/error.c index f29e72cd..bbfe23de 100644 --- a/lang/cem/cemcom/error.c +++ b/lang/cem/cemcom/error.c @@ -2,6 +2,8 @@ /* E R R O R A N D D I A G N O S T I C R O U T I N E S */ #include +#include + #include "nopp.h" #include "use_tmp.h" #include "errout.h" @@ -13,7 +15,6 @@ #include "label.h" #include "expr.h" #include "LLlex.h" -#include "em.h" /* This file contains the (non-portable) error-message and diagnostic functions. Beware, they are called with a variable number of diff --git a/lang/cem/cemcom/eval.c b/lang/cem/cemcom/eval.c index 719338bb..ab3af1cd 100644 --- a/lang/cem/cemcom/eval.c +++ b/lang/cem/cemcom/eval.c @@ -12,6 +12,8 @@ compare() */ +#include + #include "debug.h" #include "nobitfield.h" @@ -32,7 +34,6 @@ #include "align.h" #include "mes.h" #include "atw.h" -#include "em.h" #define CRASH() crash("EVAL: CRASH at line %u", __LINE__) #define roundup(n) ((n) < word_size ? word_size : (n)) @@ -90,7 +91,7 @@ EVAL(expr, val, code, true_label, false_label) label datlab = data_label(); C_df_dlb(datlab); - C_con_scon(expr->SG_VALUE, (arith)0); + C_con_scon(expr->SG_VALUE, (arith)expr->SG_LEN); C_lae_dlb(datlab, (arith)0); } break; diff --git a/lang/cem/cemcom/expr.c b/lang/cem/cemcom/expr.c index 3e4fcacf..f343c6ad 100644 --- a/lang/cem/cemcom/expr.c +++ b/lang/cem/cemcom/expr.c @@ -200,7 +200,8 @@ string2expr(expr) expr->ex_type = string_type; expr->ex_lvalue = 0; expr->ex_class = String; - expr->SG_VALUE = dot.tk_str; + expr->SG_VALUE = dot.tk_bts; + expr->SG_LEN = dot.tk_len; expr->SG_DATLAB = 0; } diff --git a/lang/cem/cemcom/expr.str b/lang/cem/cemcom/expr.str index b322e899..5809dcca 100644 --- a/lang/cem/cemcom/expr.str +++ b/lang/cem/cemcom/expr.str @@ -11,7 +11,8 @@ struct value { }; struct string { - char *sg_value; /* string of characters repr. the constant */ + char *sg_value; /* row of bytes repr. the constant */ + int sg_len; /* length of the row */ label sg_datlab; /* global data-label */ }; @@ -55,6 +56,7 @@ struct expr { #define VL_VALUE ex_object.ex_value.vl_value #define VL_IDF ex_object.ex_value.vl_idf #define SG_VALUE ex_object.ex_string.sg_value +#define SG_LEN ex_object.ex_string.sg_len #define SG_DATLAB ex_object.ex_string.sg_datlab #define FL_VALUE ex_object.ex_float.fl_value #define FL_DATLAB ex_object.ex_float.fl_datlab diff --git a/lang/cem/cemcom/field.c b/lang/cem/cemcom/field.c index d9cc1e29..bc0b76d2 100644 --- a/lang/cem/cemcom/field.c +++ b/lang/cem/cemcom/field.c @@ -4,6 +4,8 @@ #include "nobitfield.h" #ifndef NOBITFIELD +#include + #include "debug.h" #include "arith.h" @@ -16,7 +18,6 @@ #include "sizes.h" #include "Lpars.h" #include "field.h" -#include "em.h" arith tmp_pointer_var(); /* eval.c */ char *symbol2str(); /* symbol2str.c */ diff --git a/lang/cem/cemcom/ival.c b/lang/cem/cemcom/ival.c index 55cb9ff3..d843546d 100644 --- a/lang/cem/cemcom/ival.c +++ b/lang/cem/cemcom/ival.c @@ -1,11 +1,12 @@ /* $Header$ */ /* CODE FOR THE INITIALISATION OF GLOBAL VARIABLES */ +#include + #include "debug.h" #include "nobitfield.h" #include "string.h" -#include "em.h" #include "arith.h" #include "align.h" #include "label.h" @@ -48,7 +49,7 @@ do_ival(tpp, expr) */ while (strings != 0) { C_df_dlb(strings->SG_DATLAB); - C_con_scon(strings->SG_VALUE, (arith)0); + C_con_scon(strings->SG_VALUE, (arith)strings->SG_LEN); strings = strings->next; } } @@ -97,32 +98,25 @@ IVAL(tpp, expr) */ if (tp->tp_up->tp_fund == CHAR && expr->ex_class == String) init_string(tpp, expr); - else { - /* " int i[24] = 12;" */ + else /* " int i[24] = 12;" */ check_and_pad(expr, tpp); - } return 0; /* nothing left */ case STRUCT: /* struct initialisation */ if (valid_type(tp, "struct") == 0) return 0; - if (ISCOMMA(expr)) { - /* list of initialisation expressions */ + if (ISCOMMA(expr)) /* list of initialisation expressions */ return do_struct(expr, tp); - } /* "struct foo f = 12;" */ check_and_pad(expr, tpp); return 0; case UNION: - /* sorry, but .... */ error("union initialisation not allowed"); return 0; case ERRONEOUS: return 0; - default: - /* fundamental type */ - if (ISCOMMA(expr)) { - /* " int i = {12};" */ + default: /* fundamental type */ + if (ISCOMMA(expr)) { /* " int i = {12};" */ if (IVAL(tpp, expr->OP_LEFT) != 0) too_many_initialisers(expr); /* return remainings of the list for the @@ -500,7 +494,7 @@ check_ival(expr, type) { label datlab = data_label(); - C_ina_pt(datlab); + C_ina_dlb(datlab); C_con_dlb(datlab, (arith)0); expr->SG_DATLAB = datlab; store_string(expr); @@ -557,8 +551,6 @@ check_ival(expr, type) /* init_string() initialises an array of characters by specifying a string constant. - Escaped characters should be converted into its corresponding - ASCII character value. E.g. '\000' -> (char) 0. Alignment is taken care of. */ init_string(tpp, expr) @@ -570,7 +562,7 @@ init_string(tpp, expr) char *s = expr->SG_VALUE; arith ntopad; - length = prepare_string(s); + length = expr->SG_LEN; if (tp->tp_size == (arith)-1) { /* set the dimension */ tp = *tpp = construct_type(ARRAY, tp->tp_up, length); @@ -593,73 +585,6 @@ init_string(tpp, expr) con_byte(0); } -/* prepare_string() strips the escaped characters of a - string and replaces them by the ascii characters they stand for. - The ascii length of the resulting string is returned, including the - terminating null-character. -*/ -int -prepare_string(str) - register char *str; -{ - register char *t = str; - register count = 1; /* there's always a null at the end ! */ - - while (*str) { - count++; - if (*str == '\\') { - switch (*++str) { - case 'b': - *t++ = '\b'; - str++; - break; - case 'f': - *t++ = '\f'; - str++; - break; - case 'n': - *t++ = '\n'; - str++; - break; - case 'r': - *t++ = '\r'; - str++; - break; - case 't': - *t++ = '\t'; - str++; - break; - - /* octal value of: */ - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - { - register cnt = 0, oct = 0; - - do - oct = oct * 8 + *str - '0'; - while (is_oct(*++str) && ++cnt < 3); - *t++ = (char) oct; - break; - } - default: - *t++ = *str++; - break; - } - } - else - *t++ = *str++; - } - *t = '\0'; /* don't forget this one !!! */ - return count; -} - #ifndef NOBITFIELD /* put_bf() takes care of the initialisation of (bit-)field selectors of a struct: each time such an initialisation takes place, diff --git a/lang/cem/cemcom/label.h b/lang/cem/cemcom/label.h index dc93d5c3..27a1e768 100644 --- a/lang/cem/cemcom/label.h +++ b/lang/cem/cemcom/label.h @@ -1,7 +1,8 @@ /* $Header$ */ /* L A B E L D E F I N I T I O N */ -#define label unsigned int +#include /* obtain definition of "label" */ + #define NO_LABEL (label) 0 extern label lab_count; diff --git a/lang/cem/cemcom/main.c b/lang/cem/cemcom/main.c index b0354ceb..276b11f0 100644 --- a/lang/cem/cemcom/main.c +++ b/lang/cem/cemcom/main.c @@ -321,31 +321,24 @@ preprocess() printf("\n#line %ld \"%s\"\n", lastlineno, lastfilenm); } - switch (DOT) { - case IDENTIFIER: case TYPE_IDENTIFIER: printf(dot.tk_idf->id_text); printf(" "); break; - case STRING: - printf("\"%s\" ", dot.tk_str); + printf("\"%s\" ", dot.tk_bts); break; - case INTEGER: printf("%ld ", dot.tk_ival); break; - case FLOATING: printf("%s ", dot.tk_fval); break; - case EOI: case EOF: return; - default: /* very expensive... */ printf("%s ", symbol2str(DOT)); } diff --git a/lang/cem/cemcom/stack.c b/lang/cem/cemcom/stack.c index 5b509b4a..90e9562a 100644 --- a/lang/cem/cemcom/stack.c +++ b/lang/cem/cemcom/stack.c @@ -1,11 +1,14 @@ /* DERIVED FROM $Header$ */ /* S T A C K / U N S T A C K R O U T I N E S */ +#include +#include +#include + #include "debug.h" #include "use_tmp.h" #include "botch_free.h" -#include #include "alloc.h" #include "Lpars.h" #include "arith.h" @@ -17,7 +20,6 @@ #include "storage.h" #include "level.h" #include "mes.h" -#include "em.h" /* #include */ diff --git a/lang/cem/cemcom/statement.g b/lang/cem/cemcom/statement.g index da25a947..c2eb806f 100644 --- a/lang/cem/cemcom/statement.g +++ b/lang/cem/cemcom/statement.g @@ -2,6 +2,8 @@ /* STATEMENT SYNTAX PARSER */ { +#include + #include "debug.h" #include "botch_free.h" @@ -13,7 +15,6 @@ #include "expr.h" #include "code.h" #include "storage.h" -#include "em.h" #include "stack.h" #include "def.h" @@ -386,16 +387,18 @@ compound_statement(arith *nbytes;): ; asm_statement - { char *asm_string; + { char *asm_bts; + int asm_len; } : ASM '(' STRING - { asm_string = dot.tk_str; + { asm_bts = dot.tk_bts; + asm_len = dot.tk_len; } ')' ';' - { asm_seen(asm_string); + { asm_seen(asm_bts, asm_len); } ; diff --git a/lang/cem/cemcom/switch.c b/lang/cem/cemcom/switch.c index ba0c7458..7965c700 100644 --- a/lang/cem/cemcom/switch.c +++ b/lang/cem/cemcom/switch.c @@ -1,6 +1,8 @@ /* $Header$ */ /* S W I T C H - S T A T E M E N T A D M I N I S T R A T I O N */ +#include + #include "debug.h" #include "botch_free.h" #include "density.h" @@ -15,7 +17,6 @@ #include "assert.h" #include "expr.h" #include "type.h" -#include "em.h" extern char options[]; From a5ba27fd3bf6105372d60ff757ae728d2ac144e7 Mon Sep 17 00:00:00 2001 From: dick Date: Wed, 26 Mar 1986 14:01:10 +0000 Subject: [PATCH 0149/1625] identifier pfd_type renamed to fdtpp --- lang/cem/cemcom/struct.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lang/cem/cemcom/struct.c b/lang/cem/cemcom/struct.c index 6b194587..1fde0f76 100644 --- a/lang/cem/cemcom/struct.c +++ b/lang/cem/cemcom/struct.c @@ -353,10 +353,10 @@ uniq_selector(idf_sdef) #ifndef NOBITFIELD arith -add_field(szp, fd, pfd_type, idf, stp) +add_field(szp, fd, fdtpp, idf, stp) arith *szp; /* size of struct upto here */ struct field *fd; /* bitfield, containing width */ - struct type **pfd_type; /* type of selector */ + struct type **fdtpp; /* type of selector */ struct idf *idf; /* name of selector */ struct type *stp; /* current struct descriptor */ { @@ -383,11 +383,11 @@ add_field(szp, fd, pfd_type, idf, stp) fd->fd_width > bits_in_type ) { error("illegal field-width specified"); - *pfd_type = error_type; + *fdtpp = error_type; return field_offset; } - switch ((*pfd_type)->tp_fund) { + switch ((*fdtpp)->tp_fund) { case CHAR: case SHORT: @@ -395,10 +395,10 @@ add_field(szp, fd, pfd_type, idf, stp) case ENUM: case LONG: /* right type; size OK? */ - if ((*pfd_type)->tp_size > word_size) { + if ((*fdtpp)->tp_size > word_size) { error("bit field type %s does not fit in a word", - symbol2str((*pfd_type)->tp_fund)); - *pfd_type = error_type; + symbol2str((*fdtpp)->tp_fund)); + *fdtpp = error_type; return field_offset; } break; @@ -406,8 +406,8 @@ add_field(szp, fd, pfd_type, idf, stp) default: /* wrong type altogether */ error("illegal field type (%s)", - symbol2str((*pfd_type)->tp_fund)); - *pfd_type = error_type; + symbol2str((*fdtpp)->tp_fund)); + *fdtpp = error_type; return field_offset; } @@ -447,8 +447,8 @@ add_field(szp, fd, pfd_type, idf, stp) Now we need a mask to use its value in expressions. */ - *pfd_type = construct_type(FIELD, *pfd_type, (arith)0); - (*pfd_type)->tp_field = fd; + *fdtpp = construct_type(FIELD, *fdtpp, (arith)0); + (*fdtpp)->tp_field = fd; /* Set the mask right shifted. This solution avoids the problem of having sign extension when using the mask for From dc106691e08f3c7bb8c0d3715a32f9e424f38a4a Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 26 Mar 1986 15:11:02 +0000 Subject: [PATCH 0150/1625] A newer version, safety commit --- lang/m2/comp/LLlex.c | 25 +++-- lang/m2/comp/LLlex.h | 6 +- lang/m2/comp/LLmessage.c | 31 +----- lang/m2/comp/Makefile | 25 +++-- lang/m2/comp/class.h | 2 +- lang/m2/comp/declar.g | 70 +++++++++--- lang/m2/comp/def.H | 75 +++++++++++++ lang/m2/comp/def.c | 83 ++++++++++++++ lang/m2/comp/def_sizes.h | 22 ++++ lang/m2/comp/error.c | 235 ++++++++++++++++++++++----------------- lang/m2/comp/f_info.h | 2 + lang/m2/comp/idf.c | 2 + lang/m2/comp/idf.h | 13 ++- lang/m2/comp/input.c | 2 + lang/m2/comp/input.h | 2 + lang/m2/comp/main.c | 40 ++++--- lang/m2/comp/main.h | 8 ++ lang/m2/comp/misc.H | 12 ++ lang/m2/comp/misc.c | 63 +++++++++++ lang/m2/comp/print.c | 144 ++++++++++++++++++++++++ lang/m2/comp/program.g | 64 +++++------ lang/m2/comp/scope.C | 62 +++++++++++ lang/m2/comp/scope.h | 19 ++++ lang/m2/comp/statement.g | 2 + lang/m2/comp/tokenname.c | 20 +++- lang/m2/comp/tokenname.h | 3 + lang/m2/comp/type.H | 90 +++++++++++++++ lang/m2/comp/type.c | 134 ++++++++++++++++++++++ 28 files changed, 1034 insertions(+), 222 deletions(-) create mode 100644 lang/m2/comp/def.H create mode 100644 lang/m2/comp/def.c create mode 100644 lang/m2/comp/def_sizes.h create mode 100644 lang/m2/comp/main.h create mode 100644 lang/m2/comp/misc.H create mode 100644 lang/m2/comp/misc.c create mode 100644 lang/m2/comp/print.c create mode 100644 lang/m2/comp/scope.C create mode 100644 lang/m2/comp/scope.h create mode 100644 lang/m2/comp/type.H create mode 100644 lang/m2/comp/type.c diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index 17c92ad2..a6770108 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -1,20 +1,23 @@ -/* LEXICAL ANALYSER FOR MODULA-2 */ +/* L E X I C A L A N A L Y S E R F O R M O D U L A - 2 */ -#include "input.h" -#include -#include "f_info.h" -#include "Lpars.h" -#include "class.h" -#include "param.h" -#include "idf.h" -#include "LLlex.h" +static char *RcsId = "$Header$"; + +#include +#include +#include "input.h" +#include "f_info.h" +#include "Lpars.h" +#include "class.h" +#include "idf.h" +#include "LLlex.h" + +#define IDFSIZE 256 /* Number of significant characters in an identifier */ +#define NUMSIZE 256 /* maximum number of characters in a number */ long str2long(); struct token dot, aside; -static char *RcsId = "$Header$"; - /* Skip Modula-2 like comment (* ... *). Note that comment may be nested. */ diff --git a/lang/m2/comp/LLlex.h b/lang/m2/comp/LLlex.h index 594a0cf5..65690fd3 100644 --- a/lang/m2/comp/LLlex.h +++ b/lang/m2/comp/LLlex.h @@ -1,4 +1,4 @@ -/* Token Descriptor Definition */ +/* T O K E N D E S C R I P T O R D E F I N I T I O N */ /* $Header$ */ @@ -9,8 +9,8 @@ struct token { struct idf *tk_idf; /* IDENT */ char *tk_str; /* STRING */ struct { /* INTEGER */ - int tk_type; /* type */ - long tk_value; /* value */ + struct type *tk_type; /* type */ + arith tk_value; /* value */ } tk_int; char *tk_real; /* REAL */ } tk_data; diff --git a/lang/m2/comp/LLmessage.c b/lang/m2/comp/LLmessage.c index fe10602b..85591d60 100644 --- a/lang/m2/comp/LLmessage.c +++ b/lang/m2/comp/LLmessage.c @@ -1,12 +1,15 @@ +/* S Y N T A X E R R O R R E P O R T I N G */ + +static char *RcsId = "$Header$"; + #include -#include "f_info.h" +#include #include "idf.h" #include "LLlex.h" #include "Lpars.h" -static char *RcsId = "$Header$"; - extern char *symbol2str(); +extern struct idf *gen_anon_idf(); int err_occurred = 0; LLmessage(tk) @@ -21,28 +24,6 @@ LLmessage(tk) error("%s deleted", symbol2str(dot.tk_symb)); } -struct idf * -gen_anon_idf() -{ - /* A new idf is created out of nowhere, to serve as an - anonymous name. - */ - static int name_cnt; - char buff[100]; - char *sprintf(); - - sprintf(buff, "#%d in %s, line %u", - ++name_cnt, FileName, LineNumber); - return str2idf(buff, 1); -} - -int -is_anon_idf(idf) - struct idf *idf; -{ - return idf->id_text[0] == '#'; -} - insert_token(tk) int tk; { diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index e0c74595..8fc8d53f 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -13,7 +13,8 @@ CFLAGS = -DDEBUG -p $(INCLUDES) LFLAGS = -p LOBJ = tokenfile.o program.o declar.o expression.o statement.o COBJ = LLlex.o LLmessage.o char.o error.o main.o \ - symbol2str.o tokenname.o idf.o input.o idlist.o + symbol2str.o tokenname.o idf.o input.o type.o def.o \ + scope.o misc.o print.o OBJ = $(COBJ) $(LOBJ) Lpars.o GENFILES= tokenfile.c \ program.c declar.c expression.c statement.c \ @@ -40,7 +41,10 @@ tokenfile.g: tokenname.c make.tokfile symbol2str.c: tokenname.c make.tokcase make.tokcase symbol2str.c -idlist.h: idlist.H make.allocd +misc.h: misc.H make.allocd +def.h: def.H make.allocd +type.h: type.H make.allocd +scope.c: scope.C make.allocd char.c: char.tab tab ./tab -fchar.tab >char.c @@ -61,19 +65,22 @@ depend: make.allocd < $< > $@ #AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO -LLlex.o: LLlex.h Lpars.h class.h f_info.h idf.h param.h -LLmessage.o: LLlex.h Lpars.h f_info.h idf.h +LLlex.o: LLlex.h Lpars.h class.h f_info.h idf.h input.h +LLmessage.o: LLlex.h Lpars.h idf.h char.o: class.h -error.o: LLlex.h f_info.h -main.o: LLlex.h Lpars.h f_info.h idf.h +error.o: LLlex.h f_info.h input.h +main.o: LLlex.h Lpars.h debug.h f_info.h idf.h input.h main.h symbol2str.o: Lpars.h tokenname.o: Lpars.h idf.h tokenname.h idf.o: idf.h input.o: f_info.h input.h -idlist.o: idf.h idlist.h +type.o: Lpars.h def.h def_sizes.h idf.h type.h +def.o: Lpars.h def.h idf.h main.h scope.h +scope.o: scope.h +misc.o: LLlex.h f_info.h idf.h misc.h tokenfile.o: Lpars.h -program.o: Lpars.h idf.h idlist.h -declar.o: LLlex.h Lpars.h idf.h idlist.h +program.o: LLlex.h Lpars.h idf.h main.h misc.h +declar.o: LLlex.h Lpars.h def.h idf.h misc.h scope.h type.h expression.o: Lpars.h statement.o: Lpars.h Lpars.o: Lpars.h diff --git a/lang/m2/comp/class.h b/lang/m2/comp/class.h index 322ac050..72341981 100644 --- a/lang/m2/comp/class.h +++ b/lang/m2/comp/class.h @@ -1,4 +1,4 @@ -/* U S E O F C H A R A C T E R C L A S S E S */ +/* U S E O F C H A R A C T E R C L A S S E S */ /* $Header$ */ diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index c3cc67c9..72174767 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -1,17 +1,43 @@ -{ -#include "idf.h" -#include "idlist.h" -#include "LLlex.h" +/* D E C L A R A T I O N S */ +{ static char *RcsId = "$Header$"; + +#include +#include +#include "idf.h" +#include "misc.h" +#include "LLlex.h" +#include "def.h" +#include "type.h" +#include "scope.h" } -ProcedureDeclaration: - ProcedureHeading ';' block IDENT +ProcedureDeclaration +{ + register struct def *df; +} : + /* ProcedureHeading(&df) */ + PROCEDURE IDENT + { df = define(dot.TOK_IDF, CurrentScope, D_PROCEDURE); + open_scope(OPENSCOPE, 0); + } + FormalParameters? + ';' block IDENT + { match_id(dot.TOK_IDF, df->df_idf); + close_scope(); + } ; -ProcedureHeading: - PROCEDURE IDENT FormalParameters? +ProcedureHeading +{ + register struct def *df; +} : + /* Only used for definition modules + */ + PROCEDURE IDENT + { df = define(dot.TOK_IDF, CurrentScope, D_PROCHEAD); } + FormalParameters? ; block: @@ -32,22 +58,34 @@ declaration: FormalParameters: '(' [ FPSection [ ';' FPSection ]* ]? ')' - [ ':' qualident ]? + [ ':' qualident + ]? ; FPSection { struct id_list *FPList; + int VARflag = 0; } : - VAR? IdentList(&FPList) ':' FormalType + [ + VAR { VARflag = 1; } + ]? + IdentList(&FPList) ':' FormalType + { + FreeIdList(FPList); + } ; FormalType: [ ARRAY OF ]? qualident ; -TypeDeclaration: - IDENT '=' type +TypeDeclaration +{ + register struct def *df; +}: + IDENT { df = define(dot.TOK_IDF, CurrentScope, D_TYPE); } + '=' type ; type: @@ -169,8 +207,12 @@ FormalTypeList: [ ':' qualident ]? ; -ConstantDeclaration: - IDENT '=' ConstExpression +ConstantDeclaration +{ + register struct def *df; +}: + IDENT { df = define(dot.TOK_IDF, CurrentScope, D_CONST); } + '=' ConstExpression ; VariableDeclaration diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H new file mode 100644 index 00000000..21fe8cd2 --- /dev/null +++ b/lang/m2/comp/def.H @@ -0,0 +1,75 @@ +/* I D E N T I F I E R D E S C R I P T O R S T R U C T U R E */ + +/* $Header$ */ + +struct module { + int mo_priority; /* Priority of a module */ +}; + +struct variable { + char va_fixedaddress; /* Flag, set if an address was given */ + arith va_off; /* Address or offset of variable */ +}; + +struct constant { + struct expr *co_const; /* A constant expression */ +}; + +struct enumval { + unsigned int en_val; /* Value of this enumeration literal */ + struct def *en_next; /* Next enumeration literal */ +}; + +struct field { + arith fld_off; + struct variant { + struct caselabellist *fld_cases; + label fld_casedescr; + struct def *fld_varianttag; + } *fld_variant; +}; + +struct import { + int im_scopenr; /* Scope number from which imported */ +}; + +struct def { /* list of definitions for a name */ + struct def *next; + struct idf *df_idf; /* link back to the name */ + int df_scope; /* Scope in which this definition resides */ + char df_kind; /* The kind of this definition: */ +#define D_MODULE 0x00 +#define D_PROCEDURE 0x01 +#define D_VARIABLE 0x02 +#define D_FIELD 0x03 +#define D_TYPE 0x04 +#define D_ENUM 0x05 +#define D_CONST 0x06 +#define D_IMPORT 0x07 +#define D_PROCHEAD 0x08 /* A procedure heading in a definition module */ +#define D_HIDDEN 0x09 /* A hidden type */ +#define D_HTYPE 0x0A /* Definition of a hidden type seen */ +#define D_ISEXPORTED 0xFF /* Not yet defined */ + char df_flags; +#define D_ADDRESS 0x01 /* Set if address was taken */ +#define D_USED 0x02 /* Set if used */ +#define D_DEFINED 0x04 /* Set if it is assigned a value */ +#define D_VARPAR 0x08 /* Set if it is a VAR parameter */ +#define D_EXPORTED 0x40 /* Set if exported */ +#define D_QEXPORTED 0x80 /* Set if qualified exported */ + struct type *df_type; + union { + struct module df_module; + struct variable df_variable; + struct constant df_constant; + struct enumval df_enum; + struct field df_field; + struct import df_import; + } df_value; +}; + +/* ALLOCDEF "def" */ + +struct def + *define(), + *lookup(); diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c new file mode 100644 index 00000000..100cbad5 --- /dev/null +++ b/lang/m2/comp/def.c @@ -0,0 +1,83 @@ +/* D E F I N I T I O N M E C H A N I S M */ + +static char *RcsId = "$Header$"; + +#include +#include +#include +#include "Lpars.h" +#include "def.h" +#include "idf.h" +#include "main.h" +#include "scope.h" + +struct def *h_def; /* Pointer to free list of def structures */ + +struct def * +define(id, scope, kind) + register struct idf *id; + struct scope *scope; +{ + /* Declare an identifier in a scope, but first check if it + already has been defined. If so, error message. + */ + register struct def *df = lookup(id, scope); + + if (df) { + switch(df->df_kind) { + case D_PROCHEAD: + if (kind == D_PROCEDURE) { + df->df_kind = D_PROCEDURE; + return df; + } + break; + case D_HIDDEN: + if (kind == D_TYPE && state == IMPLEMENTATION) { + df->df_kind = D_HTYPE; + return df; + } + break; + case D_ISEXPORTED: + df->df_kind = kind; + return df; + break; + } + error("Identifier %s already declared", id->id_text); + return df; + } + df = new_def(); + df->df_idf = id; + df->df_scope = scope->sc_scope; + df->df_kind = kind; + df->next = id->id_def; + id->id_def = df; + return df; +} + +struct def * +lookup(id, scope) + register struct idf *id; + struct scope *scope; +{ + /* Look up a definition of an identifier in scope "scope". + Make the "def" list self-organizing. + Return a pointer to its "def" structure if it exists, + otherwise return 0. + */ + register struct def *df, *df1; + + df1 = 0; + df = id->id_def; + while (df) { + if (df->df_scope == scope->sc_scope) { + if (df1) { + df1->next = df->next; + df->next = id->id_def; + id->id_def = df; + } + return df; + } + df = df->next; + } + return 0; +} diff --git a/lang/m2/comp/def_sizes.h b/lang/m2/comp/def_sizes.h new file mode 100644 index 00000000..a8543f8b --- /dev/null +++ b/lang/m2/comp/def_sizes.h @@ -0,0 +1,22 @@ +/* D E F A U L T S I Z E S A N D A L I G N M E N T S */ + +/* $Header$ */ + +#define MAXSIZE 8 /* the maximum of the SZ_* constants */ +/* target machine sizes */ +#define SZ_CHAR (arith)1 +#define SZ_WORD (arith)4 +#define SZ_INT (arith)4 +#define SZ_LONG (arith)4 +#define SZ_FLOAT (arith)4 +#define SZ_DOUBLE (arith)8 +#define SZ_POINTER (arith)4 +/* target machine alignment requirements */ +#define AL_CHAR 1 +#define AL_WORD (int) SZ_WORD +#define AL_INT (int) SZ_WORD +#define AL_LONG (int) SZ_WORD +#define AL_FLOAT (int) SZ_WORD +#define AL_DOUBLE (int) SZ_WORD +#define AL_POINTER (int) SZ_WORD +#define AL_STRUCT 1 diff --git a/lang/m2/comp/error.c b/lang/m2/comp/error.c index 3e04da2e..4a853a44 100644 --- a/lang/m2/comp/error.c +++ b/lang/m2/comp/error.c @@ -1,105 +1,101 @@ -/* E R R O R A N D D I A G N O S T I C R O U T I N E S */ +/* E R R O R A N D D I A G N O S T I C R O U T I N E S */ /* This file contains the (non-portable) error-message and diagnostic giving functions. Be aware that they are called with a variable number of arguments! */ -#include +static char *RcsId = "$Header$"; + +#include +#include #include "input.h" #include "f_info.h" #include "LLlex.h" -static char *RcsId = "$Header$"; - -#define ERROUT stderr +#define MAXERR_LINE 5 /* Number of error messages on one line ... */ +#define ERROUT STDERR +/* error classes */ #define ERROR 1 #define WARNING 2 #define LEXERROR 3 #define LEXWARNING 4 #define CRASH 5 #define FATAL 6 -#define NONFATAL 7 -#ifdef DEBUG -#define VDEBUG 8 -#endif DEBUG +#ifdef DEBUG +#define VDEBUG 7 +#endif + +#define NILEXPR ((struct expr *) 0) int err_occurred; -/* - extern int ofd; /* compact.c * / - #define compiling (ofd >= 0) -*/ +extern char *symbol2str(); extern char options[]; -/* There are two general error message giving functions: - error() : syntactic and semantic error messages - lexerror() : lexical and pre-processor error messages - The difference lies in the fact that the first function deals with - tokens already read in by the lexical analyzer so the name of the - file it comes from and the linenumber must be retrieved from the - token instead of looking at the global variables LineNumber and - FileName. +/* There are three general error-message functions: + lexerror() lexical and pre-processor error messages + error() syntactic and semantic error messages + expr_error() errors in expressions + The difference lies in the place where the file name and line + number come from. + Lexical errors report from the global variables LineNumber and + FileName, expression errors get their information from the + expression, whereas other errors use the information in the token. */ +#ifdef DEBUG +/*VARARGS2*/ +debug(level, fmt, args) + char *fmt; +{ + if (level <= options['D']) _error(VDEBUG, NILEXPR, fmt, &args); +} +#endif DEBUG + /*VARARGS1*/ error(fmt, args) char *fmt; { - /* - if (compiling) - C_ms_err(); - */ - ++err_occurred; - _error(ERROR, fmt, &args); + _error(ERROR, NILEXPR, fmt, &args); } -#ifdef DEBUG -debug(fmt, args) +/*VARARGS2*/ +expr_error(expr, fmt, args) + struct expr *expr; char *fmt; { - if (options['D']) - _error(VDEBUG, fmt, &args); + _error(ERROR, expr, fmt, &args); +} + +/*VARARGS1*/ +warning(fmt, args) + char *fmt; +{ + _error(WARNING, NILEXPR, fmt, &args); +} + +/*VARARGS2*/ +expr_warning(expr, fmt, args) + struct expr *expr; + char *fmt; +{ + _error(WARNING, expr, fmt, &args); } -#endif DEBUG /*VARARGS1*/ lexerror(fmt, args) char *fmt; { - /* - if (compiling) - C_ms_err(); - */ - ++err_occurred; - _error(LEXERROR, fmt, &args); + _error(LEXERROR, NILEXPR, fmt, &args); } /*VARARGS1*/ -lexwarning(fmt, args) char *fmt; { - if (options['w']) return; - _error(LEXWARNING, fmt, &args); -} - -/*VARARGS1*/ -crash(fmt, args) +lexwarning(fmt, args) char *fmt; - int args; { - /* - if (compiling) - C_ms_err(); - */ - _error(CRASH, fmt, &args); - fflush(ERROUT); - fflush(stderr); - fflush(stdout); - /* - cclose(); - */ - abort(); /* produce core by "Illegal Instruction" */ - /* this should be changed into exit(1) */ + _error(LEXWARNING, NILEXPR, fmt, &args); } /*VARARGS1*/ @@ -107,64 +103,103 @@ fatal(fmt, args) char *fmt; int args; { - /* - if (compiling) - C_ms_err(); - */ - _error(FATAL, fmt, &args); - exit(-1); + + _error(FATAL, NILEXPR, fmt, &args); + sys_stop(S_EXIT); } -/*VARARGS1*/ -nonfatal(fmt, args) - char *fmt; - int args; -{ - _error(NONFATAL, fmt, &args); -} - -/*VARARGS1*/ -warning(fmt, args) - char *fmt; -{ - if (options['w']) return; - _error(WARNING, fmt, &args); -} - -_error(class, fmt, argv) +_error(class, expr, fmt, argv) int class; + struct expr *expr; char *fmt; int argv[]; { - + /* _error attempts to limit the number of error messages + for a given line to MAXERR_LINE. + */ + static unsigned int last_ln = 0; + static int e_seen = 0; + unsigned int ln = 0; + char *remark = 0; + + /* Since name and number are gathered from different places + depending on the class, we first collect the relevant + values and then decide what to print. + */ + /* preliminaries */ switch (class) { - case ERROR: case LEXERROR: - fprintf(ERROUT, "%s, line %ld: ", FileName, LineNumber); + case CRASH: + case FATAL: + /* + if (C_busy()) + C_ms_err(); + */ + err_occurred = 1; break; + case WARNING: case LEXWARNING: - fprintf(ERROUT, "%s, line %ld: (warning) ", - FileName, LineNumber); + if (options['w']) + return; + break; + } + + /* the remark */ + switch (class) { + case WARNING: + case LEXWARNING: + remark = "(warning)"; break; case CRASH: - fprintf(ERROUT, "CRASH\007 %s, line %ld: \n", - FileName, LineNumber); + remark = "CRASH\007"; break; case FATAL: - fprintf(ERROUT, "%s, line %ld: fatal error -- ", - FileName, LineNumber); + remark = "fatal error --"; break; - case NONFATAL: - fprintf(ERROUT, "warning: "); /* no line number ??? */ - break; -#ifdef DEBUG - case VDEBUG: - fprintf(ERROUT, "-D "); - break; -#endif DEBUG } - _doprnt(fmt, argv, ERROUT); + + /* the place */ + switch (class) { + case WARNING: + case ERROR: + ln = /* expr ? expr->ex_line : */ dot.tk_lineno; + break; + case LEXWARNING: + case LEXERROR: + case CRASH: + case FATAL: + ln = LineNumber; + break; + } + +#ifdef DEBUG + if (class != VDEBUG) { +#endif + if (ln == last_ln) { + /* we've seen this place before */ + e_seen++; + if (e_seen == MAXERR_LINE) + fmt = "etc ..."; + else + if (e_seen > MAXERR_LINE) + /* and too often, I'd say ! */ + return; + } + else { + /* brand new place */ + last_ln = ln; + e_seen = 0; + } + + if (FileName) + fprintf(ERROUT, "\"%s\", line %u: ", FileName, ln); + if (remark) + fprintf(ERROUT, "%s ", remark); +#ifdef DEBUG + } +#endif + doprnt(ERROUT, fmt, argv); /* contents of error */ fprintf(ERROUT, "\n"); } diff --git a/lang/m2/comp/f_info.h b/lang/m2/comp/f_info.h index c04496ad..92b1710a 100644 --- a/lang/m2/comp/f_info.h +++ b/lang/m2/comp/f_info.h @@ -1,3 +1,5 @@ +/* F I L E D E S C R I P T O R S T R U C T U R E */ + /* $Header$ */ struct f_info { diff --git a/lang/m2/comp/idf.c b/lang/m2/comp/idf.c index d1b0380a..3f59640a 100644 --- a/lang/m2/comp/idf.c +++ b/lang/m2/comp/idf.c @@ -1,3 +1,5 @@ +/* I N S T A N T I A T I O N O F I D F P A C K A G E */ + /* $Header$ */ #include "idf.h" diff --git a/lang/m2/comp/idf.h b/lang/m2/comp/idf.h index 46f7af0e..60322ff4 100644 --- a/lang/m2/comp/idf.h +++ b/lang/m2/comp/idf.h @@ -1,5 +1,14 @@ +/* U S E R D E C L A R E D P A R T O F I D F */ + /* $Header$ */ -#define IDF_TYPE int -#define id_reserved id_user +struct id_u { + int id_res; + struct def *id_df; +}; + +#define IDF_TYPE struct id_u +#define id_reserved id_user.id_res +#define id_def id_user.id_df + #include diff --git a/lang/m2/comp/input.c b/lang/m2/comp/input.c index a55c4fd5..bc608885 100644 --- a/lang/m2/comp/input.c +++ b/lang/m2/comp/input.c @@ -1,3 +1,5 @@ +/* I N S T A N T I A T I O N O F I N P U T P A C K A G E */ + /* $Header$ */ #include "f_info.h" diff --git a/lang/m2/comp/input.h b/lang/m2/comp/input.h index 3fcb7b8b..aa28ffc1 100644 --- a/lang/m2/comp/input.h +++ b/lang/m2/comp/input.h @@ -1,3 +1,5 @@ +/* I N S T A N T I A T I O N O F I N P U T M O D U L E */ + /* $Header$ */ #define INP_NPUSHBACK 2 diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index b0cfbc3f..811118ab 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -1,18 +1,20 @@ -/* mod2 -- compiler , althans: een aanzet daartoe */ - -#include -#undef BUFSIZ /* Really neccesary??? */ -#include -#include "input.h" -#include "f_info.h" -#include "idf.h" -#include "LLlex.h" -#include "Lpars.h" +/* M A I N P R O G R A M */ static char *RcsId = "$Header$"; +#include +#include +#include "input.h" +#include "f_info.h" +#include "idf.h" +#include "LLlex.h" +#include "Lpars.h" +#include "main.h" +#include "debug.h" + char options[128]; char *ProgName; +int state; extern int err_occurred; main(argc, argv) @@ -23,9 +25,6 @@ main(argc, argv) ProgName = *argv++; -# ifdef DEBUG - setbuf(stdout, (char *) 0); -# endif while (--argc > 0) { if (**argv == '-') Option(*argv++); @@ -34,13 +33,13 @@ main(argc, argv) } Nargv[Nargc] = 0; /* terminate the arg vector */ if (Nargc != 2) { - fprintf(stderr, "%s: Use one file argument\n", ProgName); + fprintf(STDERR, "%s: Use one file argument\n", ProgName); return 1; } #ifdef DEBUG printf("Mod2 compiler -- Debug version\n"); - debug("-D: Debugging on"); #endif DEBUG + DO_DEBUG(debug(1,"Debugging level: %d", options['D'])); return !Compile(Nargv[1]); } @@ -53,13 +52,15 @@ Compile(src) printf("%s\n", src); #endif DEBUG if (! InsertFile(src, (char **) 0)) { - fprintf(stderr,"%s: cannot open %s\n", ProgName, src); + fprintf(STDERR,"%s: cannot open %s\n", ProgName, src); return 0; } LineNumber = 1; FileName = src; init_idf(); reserve(tkidf); + init_scope(); + init_types(); #ifdef DEBUG if (options['L']) LexScan(); @@ -80,7 +81,7 @@ LexScan() { register int symb; - while ((symb = LLlex()) != EOF) { + while ((symb = LLlex()) != EOI) { printf(">>> %s ", symbol2str(symb)); switch(symb) { @@ -107,15 +108,12 @@ LexScan() } TimeScan() { - while (LLlex() != EOF) /* nothing */; + while (LLlex() != -1) /* nothing */; } #endif Option(str) char *str; { -#ifdef DEBUG - debug("option %c", str[1]); -#endif DEBUG options[str[1]]++; /* switch option on */ } diff --git a/lang/m2/comp/main.h b/lang/m2/comp/main.h new file mode 100644 index 00000000..884d2b34 --- /dev/null +++ b/lang/m2/comp/main.h @@ -0,0 +1,8 @@ +/* S O M E G L O B A L V A R I A B L E S */ + +/* $Header$ */ + +extern int + state; /* Indicates what we are compiling: A DEFINITION, + an IMPLEMENTATION, or a PROGRAM module + */ diff --git a/lang/m2/comp/misc.H b/lang/m2/comp/misc.H new file mode 100644 index 00000000..5ca8a003 --- /dev/null +++ b/lang/m2/comp/misc.H @@ -0,0 +1,12 @@ +/* M I S C E L L A N E O U S */ + +/* $Header$ */ + +/* Structure to link idf structures together +*/ +struct id_list { + struct id_list *next; + struct idf *id_ptr; +}; + +/* ALLOCDEF "id_list" */ diff --git a/lang/m2/comp/misc.c b/lang/m2/comp/misc.c new file mode 100644 index 00000000..7afd7202 --- /dev/null +++ b/lang/m2/comp/misc.c @@ -0,0 +1,63 @@ +/* M I S C E L L A N E O U S R O U T I N E S */ + +static char *RcsId = "$Header$"; + +#include +#include +#include "f_info.h" +#include "misc.h" +#include "LLlex.h" +#include "idf.h" + +match_id(id1, id2) + struct idf *id1, *id2; +{ + /* Check that identifiers id1 and id2 are equal. If they + are not, check that we did'nt generate them in the + first place, and if not, give an error message + */ + if (id1 != id2 && !is_anon_idf(id1) && !is_anon_idf(id2)) { + error("Identifier \"%s\" does not match identifier \"%s\"", + id1->id_text, + id2->id_text + ); + } +} + +struct id_list *h_id_list; /* Header of free list of id_list structures */ + +/* FreeIdList: take a list of id_list structures and put them + on the free list of id_list structures +*/ +FreeIdList(p) + struct id_list *p; +{ + register struct id_list *q; + + while (q = p) { + p = p->next; + free_id_list(q); + } +} + +struct idf * +gen_anon_idf() +{ + /* A new idf is created out of nowhere, to serve as an + anonymous name. + */ + static int name_cnt; + char buff[100]; + char *sprintf(); + + sprintf(buff, "#%d in %s, line %u", + ++name_cnt, FileName, LineNumber); + return str2idf(buff, 1); +} + +int +is_anon_idf(idf) + struct idf *idf; +{ + return idf->id_text[0] == '#'; +} diff --git a/lang/m2/comp/print.c b/lang/m2/comp/print.c new file mode 100644 index 00000000..ffb1a725 --- /dev/null +++ b/lang/m2/comp/print.c @@ -0,0 +1,144 @@ +/* P R I N T R O U T I N E S */ + +#include +#include + +#define SSIZE 1024 /* string-buffer size for print routines */ + +char *long2str(); + +doprnt(fp, fmt, argp) + File *fp; + char *fmt; + int argp[]; +{ + char buf[SSIZE]; + + sys_write(fp, buf, format(buf, fmt, (char *)argp)); +} + +/*VARARGS1*/ +printf(fmt, args) + char *fmt; + char args; +{ + char buf[SSIZE]; + + sys_write(STDOUT, buf, format(buf, fmt, &args)); +} + +/*VARARGS1*/ +fprintf(fp, fmt, args) + File *fp; + char *fmt; + char args; +{ + char buf[SSIZE]; + + sys_write(fp, buf, format(buf, fmt, &args)); +} + +/*VARARGS1*/ +char * +sprintf(buf, fmt, args) + char *buf, *fmt; + char args; +{ + buf[format(buf, fmt, &args)] = '\0'; + return buf; +} + +int +format(buf, fmt, argp) + char *buf, *fmt; + char *argp; +{ + register char *pf = fmt, *pa = argp; + register char *pb = buf; + + while (*pf) { + if (*pf == '%') { + register int width, base, pad, npad; + char *arg; + char cbuf[2]; + char *badformat = ""; + + /* get padder */ + if (*++pf == '0') { + pad = '0'; + ++pf; + } + else + pad = ' '; + + /* get width */ + width = 0; + while (*pf >= '0' && *pf <= '9') + width = 10 * width + *pf++ - '0'; + + /* get text and move pa */ + if (*pf == 's') { + arg = *(char **)pa; + pa += sizeof(char *); + } + else + if (*pf == 'c') { + cbuf[0] = * (char *) pa; + cbuf[1] = '\0'; + pa += sizeof(int); + arg = &cbuf[0]; + } + else + if (*pf == 'l') { + /* alignment ??? */ + if (base = integral(*++pf)) { + arg = long2str(*(long *)pa, base); + pa += sizeof(long); + } + else { + pf--; + arg = badformat; + } + } + else + if (base = integral(*pf)) { + arg = long2str((long)*(int *)pa, base); + pa += sizeof(int); + } + else + if (*pf == '%') + arg = "%"; + else + arg = badformat; + + npad = width - strlen(arg); + + while (npad-- > 0) + *pb++ = pad; + + while (*pb++ = *arg++); + pb--; + pf++; + } + else + *pb++ = *pf++; + } + return pb - buf; +} + +integral(c) +{ + switch (c) { + case 'b': + return -2; + case 'd': + return 10; + case 'o': + return -8; + case 'u': + return -10; + case 'x': + return -16; + } + return 0; +} diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 89eef00a..00c2c82f 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -1,8 +1,15 @@ -/* - Program: Modula-2 grammar in LL(1) form - Version: Mon Feb 24 14:29:39 MET 1986 -*/ +/* O V E R A L L S T R U C T U R E */ +{ +static char *RcsId = "$Header$"; + +#include +#include +#include "idf.h" +#include "misc.h" +#include "main.h" +#include "LLlex.h" +} /* The grammar as given by Wirth is already almost LL(1); the main problem is that the full form of a qualified designator @@ -17,19 +24,12 @@ field identifiers. */ -{ -#include "idf.h" -#include "idlist.h" - -static char *RcsId = "$Header$"; -} - %lexical LLlex; %start CompUnit, CompilationUnit; ModuleDeclaration: - MODULE IDENT priority? ';' import* export? block IDENT + MODULE IDENT priority? ';' import(1)* export? block IDENT ; priority: @@ -41,14 +41,18 @@ export struct id_list *ExportList; } : EXPORT QUALIFIED? IdentList(&ExportList) ';' + { + FreeIdList(ExportList); + } ; -import +import(int local;) { struct id_list *ImportList; + struct idf *id = 0; } : [ FROM - IDENT + IDENT { id = dot.TOK_IDF; } ]? IMPORT IdentList(&ImportList) ';' /* @@ -57,19 +61,19 @@ import If the FROM clause is present, the identifier in it is a module name, otherwise the names in the import list are module names. */ + { + FreeIdList(ImportList); + } ; DefinitionModule: - DEFINITION - { -#ifdef DEBUG - debug("Definition module"); -#endif DEBUG - } - MODULE IDENT ';' import* - /* export? + DEFINITION { state = DEFINITION; } + MODULE IDENT + ';' + import(0)* + /* export? - New Modula-2 does not have export lists in definition modules. + New Modula-2 does not have export lists in definition modules. */ definition* END IDENT '.' ; @@ -96,19 +100,17 @@ definition: ; ProgramModule: - MODULE - { -#ifdef DEBUG - debug("Program module"); -#endif DEBUG - } - IDENT priority? ';' import* block IDENT '.' + MODULE { if (state != IMPLEMENTATION) state = PROGRAM; } + IDENT priority? ';' import(0)* block IDENT '.' ; Module: DefinitionModule | - IMPLEMENTATION? ProgramModule + [ + IMPLEMENTATION { state = IMPLEMENTATION; } + ]? + ProgramModule ; CompilationUnit: diff --git a/lang/m2/comp/scope.C b/lang/m2/comp/scope.C new file mode 100644 index 00000000..63cbdb77 --- /dev/null +++ b/lang/m2/comp/scope.C @@ -0,0 +1,62 @@ +/* S C O P E M E C H A N I S M */ + +static char *RcsId = "$Header$"; + +#include +#include +#include "scope.h" + +static int maxscope; /* maximum assigned scope number */ + +struct scope *CurrentScope; + +/* STATICALLOCDEF "scope" */ + +/* Open a scope that is either open (automatic imports) or closed. + A closed scope is handled by adding an extra entry to the list + with scope number 0. This has two purposes: it makes scope 0 + visible, and it marks the end of a visibility list. + Scope 0 is the pervasive scope, the one that is always visible. + A disadvantage of this method is that we cannot open scope 0 + explicitly. +*/ +open_scope(scopetype, scopenr) +{ + register struct scope *sc = new_scope(); + register struct scope *sc1; + + sc->sc_scope = scopenr == 0 ? ++maxscope : scopenr; + assert(scopetype == OPENSCOPE || scopetype == CLOSEDSCOPE); + sc1 = CurrentScope; + if (scopetype == CLOSEDSCOPE) { + sc1 = new_scope(); + sc1->sc_scope = 0; /* Pervasive scope nr */ + sc1->next = CurrentScope; + } + sc->next = sc1; + CurrentScope = sc; +} + +close_scope() +{ + register struct scope *sc = CurrentScope; + + assert(sc != 0); + if (sc->next && (sc->next->sc_scope == 0)) { + struct scope *sc1 = sc; + + sc = sc->next; + free_scope(sc1); + } + CurrentScope = sc->next; + free_scope(sc); +} + +init_scope() +{ + register struct scope *sc = new_scope(); + + sc->sc_scope = 0; + sc->next = 0; + CurrentScope = sc; +} diff --git a/lang/m2/comp/scope.h b/lang/m2/comp/scope.h new file mode 100644 index 00000000..a1caef49 --- /dev/null +++ b/lang/m2/comp/scope.h @@ -0,0 +1,19 @@ +/* S C O P E M E C H A N I S M */ + +/* $Header$ */ + +#define OPENSCOPE 0 /* Indicating an open scope */ +#define CLOSEDSCOPE 1 /* Indicating a closed scope (module) */ + +struct scope { + struct scope *next; + int sc_scope; /* The scope number. Scope number 0 indicates + both the pervasive scope and the end of a + visibility range + */ +}; + +extern struct scope + *CurrentScope; + +#define nextvisible(x) ((x)->sc_scope ? (x)->next : (struct scope *) 0) diff --git a/lang/m2/comp/statement.g b/lang/m2/comp/statement.g index 3e736a5a..70e7b809 100644 --- a/lang/m2/comp/statement.g +++ b/lang/m2/comp/statement.g @@ -1,3 +1,5 @@ +/* S T A T E M E N T S */ + { static char *RcsId = "$Header$"; } diff --git a/lang/m2/comp/tokenname.c b/lang/m2/comp/tokenname.c index 32e658a1..e18ff871 100644 --- a/lang/m2/comp/tokenname.c +++ b/lang/m2/comp/tokenname.c @@ -1,6 +1,10 @@ -#include "tokenname.h" -#include "Lpars.h" -#include "idf.h" +/* T O K E N D E F I N I T I O N S */ + +static char *RcsId = "$Header$"; + +#include "tokenname.h" +#include "Lpars.h" +#include "idf.h" /* To centralize the declaration of %tokens, their presence in this file is taken as their declaration. The Makefile will produce @@ -9,8 +13,6 @@ Also, the "token2str.c" file is produced from this file. */ -static char *RcsId = "$Header$"; - struct tokenname tkspec[] = { /* the names of the special tokens */ {IDENT, "identifier"}, {STRING, "string"}, @@ -73,10 +75,18 @@ struct tokenname tkidf[] = { /* names of the identifier tokens */ }; struct tokenname tkinternal[] = { /* internal keywords */ + {PROGRAM, ""}, {0, "0"} }; struct tokenname tkstandard[] = { /* standard identifiers */ + {CHAR, "CHAR"}, + {BOOLEAN, "BOOLEAN"}, + {LONGINT, "LONGINT"}, + {CARDINAL, "CARDINAL"}, + {LONGREAL, "LONGREAL"}, + {SUBRANGE, ""}, + {ERRONEOUS, ""}, {0, ""} }; diff --git a/lang/m2/comp/tokenname.h b/lang/m2/comp/tokenname.h index 2b545da4..7838ae87 100644 --- a/lang/m2/comp/tokenname.h +++ b/lang/m2/comp/tokenname.h @@ -1,4 +1,7 @@ +/* T O K E N N A M E S T R U C T U R E */ + /* $Header$ */ + struct tokenname { /* Used for defining the name of a token as identified by its symbol */ diff --git a/lang/m2/comp/type.H b/lang/m2/comp/type.H new file mode 100644 index 00000000..6b76f1bb --- /dev/null +++ b/lang/m2/comp/type.H @@ -0,0 +1,90 @@ +/* T Y P E D E S C R I P T O R S T R U C T U R E */ + +/* $Header$ */ + +struct paramlist { /* structure for parameterlist of a PROCEDURE */ + struct paramlist *next; + struct type *par_type; /* Parameter type */ + int par_var; /* flag, set if VAR parameter */ +}; + +/* ALLOCDEF "paramlist" */ + +struct enume { + struct def *en_enums; /* Definitions of enumeration literals */ + unsigned int en_ncst; /* Number of constants */ + label en_rck; /* Label of range check descriptor */ +}; + +struct subrange { + arith su_lb, su_ub; /* Lower bound and upper bound */ + label su_rck; /* Label of range check descriptor */ +}; + +struct array { + struct type *ar_index; /* Type of index */ + arith ar_lb, ar_ub; /* Lower bound and upper bound */ + label ar_descr; /* Label of array descriptor */ +}; + +struct record { + int rc_scopenr; /* Scope number of this record */ + /* Members are in the symbol table */ +}; + +struct proc { + struct paramlist *pr_params; +}; + +struct type { + struct type *next; /* used with ARRAY, PROCEDURE, POINTER, SET, + SUBRANGE + */ + int tp_fund; /* fundamental type or constructor */ + int tp_align; /* alignment requirement of this type */ + arith tp_size; /* size of this type */ +/* struct idf *tp_idf; /* name of this type */ + union { + struct enume tp_enum; + struct subrange tp_subrange; + struct array tp_arr; + struct record tp_record; + struct proc tp_proc; + } tp_value; +}; + +/* ALLOCDEF "type" */ + +extern struct type + *char_type, + *int_type, + *card_type, + *longint_type, + *real_type, + *longreal_type, + *error_type; + +extern int + wrd_align, + int_align, + lint_align, + real_align, + lreal_align, + ptr_align, + record_align; + +extern arith + wrd_size, + int_size, + lint_size, + real_size, + lreal_size, + ptr_size; + +extern arith + align(); + +struct type + *create_type(), + *construct_type(), + *standard_type(); diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c new file mode 100644 index 00000000..856a5c05 --- /dev/null +++ b/lang/m2/comp/type.c @@ -0,0 +1,134 @@ +/* T Y P E D E F I N I T I O N M E C H A N I S M */ + +static char *RcsId = "$Header$"; + +#include +#include +#include +#include +#include "def_sizes.h" +#include "Lpars.h" +#include "def.h" +#include "type.h" +#include "idf.h" + +/* To be created dynamically in main() from defaults or from command + line parameters. +*/ +int + wrd_align = AL_WORD, + int_align = AL_INT, + lint_align = AL_LONG, + real_align = AL_FLOAT, + lreal_align = AL_DOUBLE, + ptr_align = AL_POINTER, + record_align = AL_STRUCT; + +arith + wrd_size = SZ_WORD, + int_size = SZ_INT, + lint_size = SZ_LONG, + real_size = SZ_FLOAT, + lreal_size = SZ_DOUBLE, + ptr_size = SZ_POINTER; + +struct type + *bool_type, + *char_type, + *int_type, + *card_type, + *longint_type, + *real_type, + *longreal_type, + *error_type; + +struct paramlist *h_paramlist; + +struct type *h_type; + +struct type * +create_type(fund) + register int fund; +{ + /* A brand new struct type is created, and its tp_fund set + to fund. + */ + register struct type *ntp = new_type(); + + clear((char *)ntp, sizeof(struct type)); + ntp->tp_fund = fund; + ntp->tp_size = (arith)-1; + + return ntp; +} + +struct type * +construct_type(fund, tp, count) + struct type *tp; + arith count; +{ + /* fund must be a type constructor. + The pointer to the constructed type is returned. + */ + struct type *dtp = create_type(fund); + + switch (fund) { + case PROCEDURE: + case POINTER: + dtp->tp_align = ptr_align; + dtp->tp_size = ptr_size; + dtp->next = tp; + break; + case SET: + dtp->tp_align = wrd_align; + dtp->tp_size = align((count + 7) / 8, wrd_align); + dtp->next = tp; + break; + case ARRAY: + dtp->tp_align = tp->tp_align; + if (tp->tp_size < 0) dtp->tp_size = -1; + else dtp->tp_size = count * tp->tp_size; + dtp->next = tp; + break; + case SUBRANGE: + dtp->tp_align = tp->tp_align; + dtp->tp_size = tp->tp_size; + dtp->next = tp; + break; + default: + assert(0); + } + return dtp; +} + +arith +align(pos, al) + arith pos; + int al; +{ + return ((pos + al - 1) / al) * al; +} + +struct type * +standard_type(fund, align, size) + int align; arith size; +{ + register struct type *tp = create_type(fund); + + tp->tp_align = align; + tp->tp_size = size; + + return tp; +} + +init_types() +{ + char_type = standard_type(CHAR, 1, (arith) 1); + bool_type = standard_type(BOOLEAN, 1, (arith) 1); + int_type = standard_type(INTEGER, int_align, int_size); + longint_type = standard_type(LONGINT, lint_align, lint_size); + card_type = standard_type(CARDINAL, int_align, int_size); + real_type = standard_type(REAL, real_align, real_size); + longreal_type = standard_type(LONGREAL, lreal_align, lreal_size); + error_type = standard_type(ERRONEOUS, 1, (arith) 1); +} From 7c5b41eec7a371fb69d5941985bc5388e52d4542 Mon Sep 17 00:00:00 2001 From: erikb Date: Wed, 26 Mar 1986 16:58:43 +0000 Subject: [PATCH 0151/1625] introduced the string(3L) module --- lang/cem/cemcom/Files | 3 +- lang/cem/cemcom/Makefile.erik | 25 +++--- lang/cem/cemcom/Parameters | 6 +- lang/cem/cemcom/cem.c | 2 +- lang/cem/cemcom/doprnt.c | 144 ++++++++++++++++++++++++++++++++++ lang/cem/cemcom/error.c | 1 - lang/cem/cemcom/eval.c | 4 +- lang/cem/cemcom/init.c | 3 +- lang/cem/cemcom/input.c | 6 +- lang/cem/cemcom/ival.c | 23 +++--- lang/cem/cemcom/replace.c | 6 +- 11 files changed, 184 insertions(+), 39 deletions(-) create mode 100644 lang/cem/cemcom/doprnt.c diff --git a/lang/cem/cemcom/Files b/lang/cem/cemcom/Files index 80cfbaef..125c0c28 100644 --- a/lang/cem/cemcom/Files +++ b/lang/cem/cemcom/Files @@ -33,6 +33,7 @@ decspecs.c decspecs.str def.str domacro.c +doprnt.c dumpidf.c error.c eval.c @@ -75,8 +76,6 @@ statement.g stb.c storage.c storage.h -string.c -string.h struct.c struct.str switch.c diff --git a/lang/cem/cemcom/Makefile.erik b/lang/cem/cemcom/Makefile.erik index f2348fa4..3fe90182 100644 --- a/lang/cem/cemcom/Makefile.erik +++ b/lang/cem/cemcom/Makefile.erik @@ -10,8 +10,9 @@ EM_INCLUDES =$(EM)/h# # directory containing EM interface definition # Libraries SYSLIB = /user1/erikb/em/lib/libsystem.a EMLIB = /user1/erikb/em/lib/libemk.a +STRLIB = /user1/erikb/em/lib/libstr.a EMMESLIB = /user1/erikb/em/lib/libem_mes.a -LIBS = $(EMMESLIB) $(EMLIB) $(SYSLIB) +LIBS = $(EMMESLIB) $(EMLIB) $(STRLIB) $(SYSLIB) LIB_INCLUDES = /user1/erikb/em/h # Where to install the compiler and its driver @@ -44,7 +45,7 @@ COBJ = main.o idf.o declarator.o decspecs.o struct.o \ input.o domacro.o replace.o init.o options.o \ scan.o skip.o stack.o type.o ch7mon.o label.o eval.o \ switch.o storage.o ival.o conversion.o \ - blocks.o dataflow.o string.o + blocks.o dataflow.o doprnt.o # Objects of other generated C files GOBJ = char.o symbol2str.o next.o @@ -60,7 +61,7 @@ GHSRC = botch_free.h dataflow.h debug.h density.h errout.h \ maxincl.h myalloc.h nobitfield.h nopp.h \ nparams.h numsize.h parbufsize.h pathlength.h predefine.h \ strsize.h target_sizes.h textsize.h use_tmp.h \ - str_params.h spec_arith.h + ssize.h spec_arith.h # Other generated files, for 'make clean' only GENERATED = tab tokenfile.g Lpars.h LLfiles LL.output lint.out \ @@ -81,10 +82,10 @@ cc: make LLfiles make main -cem: cem.c string.o - $(CC) -O cem.c string.o $(SYSLIB) -o cem +cem: cem.c + $(CC) -O cem.c $(SYSLIB) -o cem -lint.cem: cem.c string.c +lint.cem: cem.c lint -abx cem.c hfiles: Parameters @@ -197,15 +198,15 @@ arith.o: Lpars.h alloc.h arith.h botch_free.h expr.h field.h idf.h label.h mes.h alloc.o: alloc.h assert.h debug.h myalloc.h code.o: LLlex.h Lpars.h alloc.h arith.h assert.h atw.h botch_free.h code.h dataflow.h debug.h declar.h decspecs.h def.h expr.h idf.h label.h level.h mes.h nobitfield.h nopp.h sizes.h spec_arith.h specials.h stack.h storage.h type.h use_tmp.h dumpidf.o: Lpars.h arith.h debug.h def.h expr.h field.h idf.h label.h nobitfield.h nopp.h spec_arith.h stack.h struct.h type.h -error.o: LLlex.h arith.h debug.h errout.h expr.h label.h nopp.h spec_arith.h string.h tokenname.h use_tmp.h +error.o: LLlex.h arith.h debug.h errout.h expr.h label.h nopp.h spec_arith.h tokenname.h use_tmp.h field.o: Lpars.h arith.h assert.h code.h debug.h expr.h field.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h type.h tokenname.o: LLlex.h Lpars.h arith.h idf.h nopp.h spec_arith.h tokenname.h LLlex.o: LLlex.h Lpars.h alloc.h arith.h assert.h class.h debug.h def.h idf.h idfsize.h input.h nopp.h numsize.h sizes.h spec_arith.h strsize.h LLmessage.o: LLlex.h Lpars.h alloc.h arith.h idf.h nopp.h spec_arith.h input.o: LLlex.h alloc.h arith.h assert.h debug.h idepth.h input.h inputtype.h interface.h nopp.h pathlength.h spec_arith.h domacro.o: LLlex.h Lpars.h alloc.h arith.h assert.h botch_free.h class.h debug.h idf.h idfsize.h ifdepth.h input.h interface.h macro.h nopp.h nparams.h parbufsize.h spec_arith.h storage.h textsize.h -replace.o: LLlex.h alloc.h arith.h assert.h class.h debug.h idf.h input.h interface.h macro.h nopp.h pathlength.h spec_arith.h string.h strsize.h -init.o: alloc.h class.h idf.h interface.h macro.h nopp.h predefine.h string.h +replace.o: LLlex.h alloc.h arith.h assert.h class.h debug.h idf.h input.h interface.h macro.h nopp.h pathlength.h spec_arith.h strsize.h +init.o: alloc.h class.h idf.h interface.h macro.h nopp.h predefine.h options.o: align.h arith.h class.h idf.h idfsize.h macro.h maxincl.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h scan.o: class.h idf.h input.h interface.h lapbuf.h macro.h nopp.h nparams.h skip.o: LLlex.h arith.h class.h input.h interface.h nopp.h spec_arith.h @@ -213,14 +214,14 @@ stack.o: Lpars.h alloc.h arith.h botch_free.h debug.h def.h idf.h level.h mes.h type.o: Lpars.h align.h alloc.h arith.h def.h idf.h nobitfield.h nopp.h sizes.h spec_arith.h type.h ch7mon.o: Lpars.h arith.h botch_free.h def.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h storage.h type.h label.o: Lpars.h arith.h def.h idf.h label.h level.h nobitfield.h nopp.h spec_arith.h type.h -eval.o: Lpars.h align.h arith.h assert.h atw.h code.h dataflow.h debug.h def.h expr.h idf.h label.h level.h mes.h nobitfield.h nopp.h sizes.h spec_arith.h stack.h string.h type.h +eval.o: Lpars.h align.h arith.h assert.h atw.h code.h dataflow.h debug.h def.h expr.h idf.h label.h level.h mes.h nobitfield.h nopp.h sizes.h spec_arith.h stack.h type.h switch.o: Lpars.h arith.h assert.h botch_free.h code.h debug.h density.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h storage.h switch.h type.h storage.o: alloc.h assert.h botch_free.h debug.h storage.h -ival.o: Lpars.h align.h arith.h assert.h class.h debug.h def.h expr.h field.h idf.h label.h level.h nobitfield.h nopp.h sizes.h spec_arith.h string.h struct.h type.h +ival.o: Lpars.h align.h arith.h assert.h class.h debug.h def.h expr.h field.h idf.h label.h level.h nobitfield.h nopp.h sizes.h spec_arith.h struct.h type.h conversion.o: Lpars.h arith.h nobitfield.h sizes.h spec_arith.h type.h blocks.o: arith.h atw.h sizes.h spec_arith.h dataflow.o: dataflow.h -string.o: arith.h nopp.h spec_arith.h str_params.h string.h +doprnt.o: ssize.h tokenfile.o: Lpars.h declar.o: LLlex.h Lpars.h arith.h debug.h declar.h decspecs.h def.h expr.h field.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h struct.h type.h statement.o: LLlex.h Lpars.h arith.h botch_free.h code.h debug.h def.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h stack.h storage.h type.h diff --git a/lang/cem/cemcom/Parameters b/lang/cem/cemcom/Parameters index 1ae2b459..00cae78f 100644 --- a/lang/cem/cemcom/Parameters +++ b/lang/cem/cemcom/Parameters @@ -122,11 +122,7 @@ #undef NOBITFIELD 1 /* implement bitfields */ -!File: str_params.h -/* maximum number of characters in string representation of (unsigned) long -*/ -#define MAXWIDTH 32 - +!File: ssize.h #define SSIZE 1024 /* string-buffer size for print routines */ diff --git a/lang/cem/cemcom/cem.c b/lang/cem/cemcom/cem.c index f2d832f8..7f8a3495 100644 --- a/lang/cem/cemcom/cem.c +++ b/lang/cem/cemcom/cem.c @@ -6,7 +6,7 @@ Author: Erik Baalbergen */ -#include "string.h" +#include #include #include #include diff --git a/lang/cem/cemcom/doprnt.c b/lang/cem/cemcom/doprnt.c new file mode 100644 index 00000000..9cdc126f --- /dev/null +++ b/lang/cem/cemcom/doprnt.c @@ -0,0 +1,144 @@ +/* $Header$ */ +/* STRING MANIPULATION AND PRINT ROUTINES */ + +#include +#include "ssize.h" + +char *long2str(); + +static +integral(c) +{ + switch (c) { + case 'b': + return -2; + case 'd': + return 10; + case 'o': + return -8; + case 'u': + return -10; + case 'x': + return -16; + } + return 0; +} + +static int +format(buf, fmt, argp) + char *buf, *fmt; + char *argp; +{ + register char *pf = fmt, *pa = argp; + register char *pb = buf; + + while (*pf) { + if (*pf == '%') { + register width, base, pad, npad; + char *arg; + char cbuf[2]; + char *badformat = ""; + + /* get padder */ + if (*++pf == '0') { + pad = '0'; + ++pf; + } + else + pad = ' '; + + /* get width */ + width = 0; + while (*pf >= '0' && *pf <= '9') + width = 10 * width + *pf++ - '0'; + + /* get text and move pa */ + if (*pf == 's') { + arg = *(char **)pa; + pa += sizeof(char *); + } + else + if (*pf == 'c') { + cbuf[0] = * (char *) pa; + cbuf[1] = '\0'; + pa += sizeof(int); + arg = &cbuf[0]; + } + else + if (*pf == 'l') { + /* alignment ??? */ + if (base = integral(*++pf)) { + arg = long2str(*(long *)pa, base); + pa += sizeof(long); + } + else { + pf--; + arg = badformat; + } + } + else + if (base = integral(*pf)) { + arg = long2str((long)*(int *)pa, base); + pa += sizeof(int); + } + else + if (*pf == '%') + arg = "%"; + else + arg = badformat; + + npad = width - strlen(arg); + + while (npad-- > 0) + *pb++ = pad; + + while (*pb++ = *arg++); + pb--; + pf++; + } + else + *pb++ = *pf++; + } + return pb - buf; +} + +doprnt(fp, fmt, argp) + File *fp; + char *fmt; + int argp[]; +{ + char buf[SSIZE]; + + sys_write(fp, buf, format(buf, fmt, (char *)argp)); +} + +/*VARARGS1*/ +printf(fmt, args) + char *fmt; + char args; +{ + char buf[SSIZE]; + + sys_write(STDOUT, buf, format(buf, fmt, &args)); +} + +/*VARARGS1*/ +fprintf(fp, fmt, args) + File *fp; + char *fmt; + char args; +{ + char buf[SSIZE]; + + sys_write(fp, buf, format(buf, fmt, &args)); +} + +/*VARARGS1*/ +char * +sprintf(buf, fmt, args) + char *buf, *fmt; + char args; +{ + buf[format(buf, fmt, &args)] = '\0'; + return buf; +} diff --git a/lang/cem/cemcom/error.c b/lang/cem/cemcom/error.c index bbfe23de..7b1629ec 100644 --- a/lang/cem/cemcom/error.c +++ b/lang/cem/cemcom/error.c @@ -8,7 +8,6 @@ #include "use_tmp.h" #include "errout.h" #include "debug.h" -#include "string.h" #include "tokenname.h" #include "arith.h" diff --git a/lang/cem/cemcom/eval.c b/lang/cem/cemcom/eval.c index ab3af1cd..636e4287 100644 --- a/lang/cem/cemcom/eval.c +++ b/lang/cem/cemcom/eval.c @@ -17,7 +17,6 @@ #include "debug.h" #include "nobitfield.h" -#include "string.h" #include "dataflow.h" #include "arith.h" #include "type.h" @@ -39,6 +38,7 @@ #define roundup(n) ((n) < word_size ? word_size : (n)) char *symbol2str(); +char *long2str(); arith tmp_pointer_var(); /* EVAL() serves as the main expression tree evaluator, which turns @@ -1024,7 +1024,7 @@ load_cst(val, siz) label datlab; C_df_dlb(datlab = data_label()); - C_rom_icon(itos(val), siz); + C_rom_icon(long2str((long)val, 10), siz); C_lae_dlb(datlab, (arith)0); C_loi(siz); } diff --git a/lang/cem/cemcom/init.c b/lang/cem/cemcom/init.c index bd145643..fcfe547b 100644 --- a/lang/cem/cemcom/init.c +++ b/lang/cem/cemcom/init.c @@ -11,7 +11,6 @@ #include "macro.h" #include "idf.h" #include "interface.h" -#include "string.h" PRIVATE struct mkey { char *mk_reserved; @@ -30,6 +29,8 @@ PRIVATE struct mkey { {0, K_UNKNOWN} }; +char *strcpy(); + EXPORT init_pp() { diff --git a/lang/cem/cemcom/input.c b/lang/cem/cemcom/input.c index 45db4371..850f7f08 100644 --- a/lang/cem/cemcom/input.c +++ b/lang/cem/cemcom/input.c @@ -427,12 +427,12 @@ setwdir(wdir, fn) char *fn, **wdir; { register char *p; - char *rindex(); + char *strrindex(); - p = rindex(fn, '/'); + p = strrindex(fn, '/'); while (p && *(p + 1) == '\0') { /* remove trailing /'s */ *p = '\0'; - p = rindex(fn, '/'); + p = strrindex(fn, '/'); } if (fn[0] == '\0' || (fn[0] == '/' && p == &fn[0])) /* absolute path */ diff --git a/lang/cem/cemcom/ival.c b/lang/cem/cemcom/ival.c index d843546d..cbc7fb09 100644 --- a/lang/cem/cemcom/ival.c +++ b/lang/cem/cemcom/ival.c @@ -6,7 +6,6 @@ #include "debug.h" #include "nobitfield.h" -#include "string.h" #include "arith.h" #include "align.h" #include "label.h" @@ -22,9 +21,10 @@ #include "level.h" #include "def.h" -extern char *symbol2str(); +#define con_nullbyte() C_con_ucon("0", (arith)1) -#define con_byte(c) C_con_ucon(itos((long)(c) & 0xFF), (arith)1) +char *symbol2str(); +char *long2str(); struct expr *do_array(), *do_struct(), *IVAL(); struct expr *strings = 0; /* list of string constants within initialiser */ @@ -313,7 +313,7 @@ do_struct(expr, tp) } /* keep on aligning... */ while (bytes_upto_here++ < tp->tp_size) - con_byte(0); + con_nullbyte(); return expr; } @@ -479,7 +479,10 @@ check_ival(expr, type) illegal_init_cst(expr); break; } - C_con_fcon(itos(expr->VL_VALUE), type->tp_size); + C_con_fcon( + long2str((long)expr->VL_VALUE, 10), + type->tp_size + ); } else illegal_init_cst(expr); @@ -578,11 +581,11 @@ init_string(tpp, expr) } /* throw out the characters of the already prepared string */ do - con_byte(*s++); + C_con_ucon(long2str((long)*s++ & 0xFF, 10), (arith)1); while (--length > 0); /* pad the allocated memory (the alignment has been calculated) */ while (ntopad-- > 0) - con_byte(0); + con_nullbyte(); } #ifndef NOBITFIELD @@ -635,7 +638,7 @@ zero_bytes(sd) register count = n; while (n-- > 0) - con_byte((arith)0); + con_nullbyte(); return count; } @@ -657,9 +660,9 @@ con_int(expr) register struct type *tp = expr->ex_type; if (tp->tp_unsigned) - C_con_ucon(itos(expr->VL_VALUE), tp->tp_size); + C_con_ucon(long2str((long)expr->VL_VALUE, -10), tp->tp_size); else - C_con_icon(itos(expr->VL_VALUE), tp->tp_size); + C_con_icon(long2str((long)expr->VL_VALUE, 10), tp->tp_size); } illegal_init_cst(expr) diff --git a/lang/cem/cemcom/replace.c b/lang/cem/cemcom/replace.c index c76b5d7a..0b0f7302 100644 --- a/lang/cem/cemcom/replace.c +++ b/lang/cem/cemcom/replace.c @@ -8,7 +8,6 @@ #include "pathlength.h" /* UF */ #include "strsize.h" /* UF */ -#include "string.h" #include "alloc.h" #include "idf.h" #include "input.h" @@ -19,6 +18,9 @@ #include "assert.h" #include "interface.h" +char *strcpy(), *strcat(); +char *long2str(); + EXPORT int replace(idef) struct idf *idef; @@ -90,7 +92,7 @@ macro_func(idef) break; case 'L' : /* __LINE__ */ - idef->id_macro->mc_text = itos(LineNumber); + idef->id_macro->mc_text = long2str((long)LineNumber, 10); idef->id_macro->mc_length = 1; break; From bee901746d11e282559053177411bcdd2c4b64cd Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 26 Mar 1986 17:53:13 +0000 Subject: [PATCH 0152/1625] newer version, safety commit --- lang/m2/comp/Makefile | 9 +++--- lang/m2/comp/def.H | 3 ++ lang/m2/comp/def.c | 13 +++++---- lang/m2/comp/enter.c | 29 +++++++++++++++++++ lang/m2/comp/error.c | 18 ++++++------ lang/m2/comp/main.c | 62 ++++++++++++++++++++++++++++++++++++++-- lang/m2/comp/program.g | 14 +++++++-- lang/m2/comp/scope.C | 3 ++ lang/m2/comp/scope.h | 1 + lang/m2/comp/standards.h | 24 ++++++++++++++++ lang/m2/comp/tokenname.c | 10 +++---- lang/m2/comp/type.H | 2 ++ lang/m2/comp/type.c | 2 ++ 13 files changed, 163 insertions(+), 27 deletions(-) create mode 100644 lang/m2/comp/enter.c create mode 100644 lang/m2/comp/standards.h diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index 8fc8d53f..2a2bd1f0 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -14,7 +14,7 @@ LFLAGS = -p LOBJ = tokenfile.o program.o declar.o expression.o statement.o COBJ = LLlex.o LLmessage.o char.o error.o main.o \ symbol2str.o tokenname.o idf.o input.o type.o def.o \ - scope.o misc.o print.o + scope.o misc.o print.o enter.o OBJ = $(COBJ) $(LOBJ) Lpars.o GENFILES= tokenfile.c \ program.c declar.c expression.c statement.c \ @@ -69,17 +69,18 @@ LLlex.o: LLlex.h Lpars.h class.h f_info.h idf.h input.h LLmessage.o: LLlex.h Lpars.h idf.h char.o: class.h error.o: LLlex.h f_info.h input.h -main.o: LLlex.h Lpars.h debug.h f_info.h idf.h input.h main.h +main.o: LLlex.h Lpars.h debug.h def.h f_info.h idf.h input.h main.h standards.h type.h symbol2str.o: Lpars.h tokenname.o: Lpars.h idf.h tokenname.h idf.o: idf.h input.o: f_info.h input.h type.o: Lpars.h def.h def_sizes.h idf.h type.h def.o: Lpars.h def.h idf.h main.h scope.h -scope.o: scope.h +scope.o: debug.h scope.h misc.o: LLlex.h f_info.h idf.h misc.h +enter.o: def.h idf.h scope.h type.h tokenfile.o: Lpars.h -program.o: LLlex.h Lpars.h idf.h main.h misc.h +program.o: LLlex.h Lpars.h idf.h main.h misc.h scope.h declar.o: LLlex.h Lpars.h def.h idf.h misc.h scope.h type.h expression.o: Lpars.h statement.o: Lpars.h diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H index 21fe8cd2..ea764137 100644 --- a/lang/m2/comp/def.H +++ b/lang/m2/comp/def.H @@ -49,6 +49,8 @@ struct def { /* list of definitions for a name */ #define D_PROCHEAD 0x08 /* A procedure heading in a definition module */ #define D_HIDDEN 0x09 /* A hidden type */ #define D_HTYPE 0x0A /* Definition of a hidden type seen */ +#define D_STDPROC 0x0B /* A standard procedure */ +#define D_STDFUNC 0x0C /* A standard function */ #define D_ISEXPORTED 0xFF /* Not yet defined */ char df_flags; #define D_ADDRESS 0x01 /* Set if address was taken */ @@ -65,6 +67,7 @@ struct def { /* list of definitions for a name */ struct enumval df_enum; struct field df_field; struct import df_import; + int df_stdname; /* Define for standard name */ } df_value; }; diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index 100cbad5..336bee3a 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -16,14 +16,18 @@ struct def *h_def; /* Pointer to free list of def structures */ struct def * define(id, scope, kind) register struct idf *id; - struct scope *scope; + register struct scope *scope; { /* Declare an identifier in a scope, but first check if it already has been defined. If so, error message. */ - register struct def *df = lookup(id, scope); + register struct def *df = lookup(id, scope->sc_scope); - if (df) { + if ( /* Already in this scope */ + df + || /* A closed scope, and id defined in the pervasive scope */ + (scopeclosed(scope) && (df = lookup(id, 0))) + ) { switch(df->df_kind) { case D_PROCHEAD: if (kind == D_PROCEDURE) { @@ -57,7 +61,6 @@ define(id, scope, kind) struct def * lookup(id, scope) register struct idf *id; - struct scope *scope; { /* Look up a definition of an identifier in scope "scope". Make the "def" list self-organizing. @@ -69,7 +72,7 @@ lookup(id, scope) df1 = 0; df = id->id_def; while (df) { - if (df->df_scope == scope->sc_scope) { + if (df->df_scope == scope) { if (df1) { df1->next = df->next; df->next = id->id_def; diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c new file mode 100644 index 00000000..dc1d3110 --- /dev/null +++ b/lang/m2/comp/enter.c @@ -0,0 +1,29 @@ +/* H I G H L E V E L S Y M B O L E N T R Y A N D L O O K U P */ + +static char *RcsId = "$Header$"; + +#include +#include +#include "idf.h" +#include "def.h" +#include "type.h" +#include "scope.h" + +extern struct idf *str2idf(); +extern struct def *define(); + +Enter(name, kind, type, pnam) + char *name; + struct type *type; +{ + struct idf *id; + struct def *df; + + id = str2idf(name, 0); + if (!id) fatal("Out of core"); + df = define(id, CurrentScope, kind); + df->df_type = type; + if (kind == D_STDPROC || kind == D_STDFUNC) { + df->df_value.df_stdname = pnam; + } +} diff --git a/lang/m2/comp/error.c b/lang/m2/comp/error.c index 4a853a44..278a39d7 100644 --- a/lang/m2/comp/error.c +++ b/lang/m2/comp/error.c @@ -170,6 +170,9 @@ _error(class, expr, fmt, argv) case LEXERROR: case CRASH: case FATAL: +#ifdef DEBUG + case VDEBUG: +#endif DEBUG ln = LineNumber; break; } @@ -180,8 +183,7 @@ _error(class, expr, fmt, argv) if (ln == last_ln) { /* we've seen this place before */ e_seen++; - if (e_seen == MAXERR_LINE) - fmt = "etc ..."; + if (e_seen == MAXERR_LINE) fmt = "etc ..."; else if (e_seen > MAXERR_LINE) /* and too often, I'd say ! */ @@ -192,14 +194,14 @@ _error(class, expr, fmt, argv) last_ln = ln; e_seen = 0; } - - if (FileName) - fprintf(ERROUT, "\"%s\", line %u: ", FileName, ln); - if (remark) - fprintf(ERROUT, "%s ", remark); #ifdef DEBUG } -#endif +#endif DEBUG + + if (FileName) fprintf(ERROUT, "\"%s\", line %u: ", FileName, ln); + + if (remark) fprintf(ERROUT, "%s ", remark); + doprnt(ERROUT, fmt, argv); /* contents of error */ fprintf(ERROUT, "\n"); } diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index 811118ab..b245420a 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -4,6 +4,7 @@ static char *RcsId = "$Header$"; #include #include +#include #include "input.h" #include "f_info.h" #include "idf.h" @@ -11,6 +12,9 @@ static char *RcsId = "$Header$"; #include "Lpars.h" #include "main.h" #include "debug.h" +#include "type.h" +#include "def.h" +#include "standards.h" char options[128]; char *ProgName; @@ -48,9 +52,7 @@ Compile(src) { extern struct tokenname tkidf[]; -#ifdef DEBUG - printf("%s\n", src); -#endif DEBUG + DO_DEBUG(debug(1,"Filename : %s", src)); if (! InsertFile(src, (char **) 0)) { fprintf(STDERR,"%s: cannot open %s\n", ProgName, src); return 0; @@ -61,6 +63,7 @@ Compile(src) reserve(tkidf); init_scope(); init_types(); + add_standards(); #ifdef DEBUG if (options['L']) LexScan(); @@ -117,3 +120,56 @@ Option(str) { options[str[1]]++; /* switch option on */ } + +#define NULLTYPE ((struct type *) 0) + +add_standards() +{ + register struct def *df; + register struct type *tp; + struct def *Enter(); + + (void) Enter("ABS", D_STDFUNC, NULLTYPE, S_ABS); + (void) Enter("CAP", D_STDFUNC, NULLTYPE, S_CAP); + (void) Enter("CHR", D_STDFUNC, NULLTYPE, S_CHR); + (void) Enter("FLOAT", D_STDFUNC, NULLTYPE, S_FLOAT); + (void) Enter("HIGH", D_STDFUNC, NULLTYPE, S_HIGH); + (void) Enter("HALT", D_STDPROC, NULLTYPE, S_HALT); + (void) Enter("EXCL", D_STDPROC, NULLTYPE, S_EXCL); + (void) Enter("DEC", D_STDPROC, NULLTYPE, S_DEC); + (void) Enter("INC", D_STDPROC, NULLTYPE, S_INC); + (void) Enter("VAL", D_STDFUNC, NULLTYPE, S_VAL); + (void) Enter("TRUNC", D_STDFUNC, NULLTYPE, S_TRUNC); + (void) Enter("SIZE", D_STDFUNC, NULLTYPE, S_SIZE); + (void) Enter("ORD", D_STDFUNC, NULLTYPE, S_ORD); + (void) Enter("ODD", D_STDFUNC, NULLTYPE, S_ODD); + (void) Enter("MAX", D_STDFUNC, NULLTYPE, S_MAX); + (void) Enter("MIN", D_STDFUNC, NULLTYPE, S_MIN); + (void) Enter("INCL", D_STDPROC, NULLTYPE, S_INCL); + + (void) Enter("CHAR", D_TYPE, char_type, 0); + (void) Enter("INTEGER", D_TYPE, int_type, 0); + (void) Enter("LONGINT", D_TYPE, longint_type, 0); + (void) Enter("REAL", D_TYPE, real_type, 0); + (void) Enter("LONGREAL", D_TYPE, longreal_type, 0); + (void) Enter("BOOLEAN", D_TYPE, bool_type, 0); + (void) Enter("CARDINAL", D_TYPE, card_type, 0); + (void) Enter("NIL", D_CONST, nil_type, 0); + (void) Enter("PROC", + D_TYPE, + construct_type(PROCEDURE, NULLTYPE, (arith) 0), + 0); + tp = construct_type(SUBRANGE, int_type, (arith) 0); + tp->tp_value.tp_subrange.su_lb = 0; + tp->tp_value.tp_subrange.su_ub = wrd_size * 8 - 1; + (void) Enter("BITSET", + D_TYPE, + construct_type(SET, tp, wrd_size), + 0); + df = Enter("FALSE", D_ENUM, bool_type, 0); + df->df_value.df_enum.en_val = 0; + df->df_value.df_enum.en_next = Enter("TRUE", D_ENUM, bool_type, 0); + df = df->df_value.df_enum.en_next; + df->df_value.df_enum.en_val = 1; + df->df_value.df_enum.en_next = 0; +} diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 00c2c82f..662ba71c 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -9,6 +9,7 @@ static char *RcsId = "$Header$"; #include "misc.h" #include "main.h" #include "LLlex.h" +#include "scope.h" } /* The grammar as given by Wirth is already almost LL(1); the @@ -68,7 +69,7 @@ import(int local;) DefinitionModule: DEFINITION { state = DEFINITION; } - MODULE IDENT + MODULE IDENT { open_scope(CLOSEDSCOPE, 0); } ';' import(0)* /* export? @@ -76,6 +77,7 @@ DefinitionModule: New Modula-2 does not have export lists in definition modules. */ definition* END IDENT '.' + { close_scope(); } ; definition: @@ -101,7 +103,15 @@ definition: ProgramModule: MODULE { if (state != IMPLEMENTATION) state = PROGRAM; } - IDENT priority? ';' import(0)* block IDENT '.' + IDENT { if (state == IMPLEMENTATION) { + /* Re-open scope ??? */ + open_scope(CLOSEDSCOPE, 0); + } + else open_scope(CLOSEDSCOPE, 0); + } + priority? ';' import(0)* block IDENT + { close_scope(); } + '.' ; Module: diff --git a/lang/m2/comp/scope.C b/lang/m2/comp/scope.C index 63cbdb77..f46f3cfd 100644 --- a/lang/m2/comp/scope.C +++ b/lang/m2/comp/scope.C @@ -5,6 +5,7 @@ static char *RcsId = "$Header$"; #include #include #include "scope.h" +#include "debug.h" static int maxscope; /* maximum assigned scope number */ @@ -27,6 +28,7 @@ open_scope(scopetype, scopenr) sc->sc_scope = scopenr == 0 ? ++maxscope : scopenr; assert(scopetype == OPENSCOPE || scopetype == CLOSEDSCOPE); + DO_DEBUG(debug(1, "Opening a %s scope", scopetype == OPENSCOPE ? "open" : "closed")); sc1 = CurrentScope; if (scopetype == CLOSEDSCOPE) { sc1 = new_scope(); @@ -42,6 +44,7 @@ close_scope() register struct scope *sc = CurrentScope; assert(sc != 0); + DO_DEBUG(debug(1, "Closing a scope")); if (sc->next && (sc->next->sc_scope == 0)) { struct scope *sc1 = sc; diff --git a/lang/m2/comp/scope.h b/lang/m2/comp/scope.h index a1caef49..20e72ada 100644 --- a/lang/m2/comp/scope.h +++ b/lang/m2/comp/scope.h @@ -17,3 +17,4 @@ extern struct scope *CurrentScope; #define nextvisible(x) ((x)->sc_scope ? (x)->next : (struct scope *) 0) +#define scopeclosed(x) ((x)->next->sc_scope == 0) diff --git a/lang/m2/comp/standards.h b/lang/m2/comp/standards.h new file mode 100644 index 00000000..179aa892 --- /dev/null +++ b/lang/m2/comp/standards.h @@ -0,0 +1,24 @@ +/* S T A N D A R D P R O C E D U R E S A N D F U N C T I O N S */ + +/* $Header$ */ + +#define S_ABS 1 +#define S_CAP 2 +#define S_CHR 3 +#define S_DEC 4 +#define S_EXCL 5 +#define S_FLOAT 6 +#define S_HALT 7 +#define S_HIGH 8 +#define S_INC 9 +#define S_INCL 10 +#define S_MAX 11 +#define S_MIN 12 +#define S_ODD 13 +#define S_ORD 14 +#define S_SIZE 15 +#define S_TRUNC 16 +#define S_VAL 17 + +/* Standard procedures and functions defined in the SYSTEM module ... */ +/* PM ??? */ diff --git a/lang/m2/comp/tokenname.c b/lang/m2/comp/tokenname.c index e18ff871..97020e03 100644 --- a/lang/m2/comp/tokenname.c +++ b/lang/m2/comp/tokenname.c @@ -80,11 +80,11 @@ struct tokenname tkinternal[] = { /* internal keywords */ }; struct tokenname tkstandard[] = { /* standard identifiers */ - {CHAR, "CHAR"}, - {BOOLEAN, "BOOLEAN"}, - {LONGINT, "LONGINT"}, - {CARDINAL, "CARDINAL"}, - {LONGREAL, "LONGREAL"}, + {CHAR, ""}, + {BOOLEAN, ""}, + {LONGINT, ""}, + {CARDINAL, ""}, + {LONGREAL, ""}, {SUBRANGE, ""}, {ERRONEOUS, ""}, {0, ""} diff --git a/lang/m2/comp/type.H b/lang/m2/comp/type.H index 6b76f1bb..ca59a1f0 100644 --- a/lang/m2/comp/type.H +++ b/lang/m2/comp/type.H @@ -56,12 +56,14 @@ struct type { /* ALLOCDEF "type" */ extern struct type + *bool_type, *char_type, *int_type, *card_type, *longint_type, *real_type, *longreal_type, + *nil_type, *error_type; extern int diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index 856a5c05..37fb537a 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -40,6 +40,7 @@ struct type *longint_type, *real_type, *longreal_type, + *nil_type, *error_type; struct paramlist *h_paramlist; @@ -130,5 +131,6 @@ init_types() card_type = standard_type(CARDINAL, int_align, int_size); real_type = standard_type(REAL, real_align, real_size); longreal_type = standard_type(LONGREAL, lreal_align, lreal_size); + nil_type = standard_type(POINTER, ptr_align, ptr_size); error_type = standard_type(ERRONEOUS, 1, (arith) 1); } From 5c1fa6db8ce34ee590cb2b4ba1d0331f36b26966 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 26 Mar 1986 22:46:48 +0000 Subject: [PATCH 0153/1625] safety commit, newer version --- lang/m2/comp/LLlex.c | 2 +- lang/m2/comp/Makefile | 6 ++-- lang/m2/comp/declar.g | 77 ++++++++++++++++++++++++++++-------------- lang/m2/comp/def.H | 1 + lang/m2/comp/def.c | 6 +++- lang/m2/comp/enter.c | 26 ++++++++++++++ lang/m2/comp/misc.H | 2 ++ lang/m2/comp/misc.c | 9 +---- lang/m2/comp/program.g | 34 +++++++++++++++---- 9 files changed, 118 insertions(+), 45 deletions(-) diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index a6770108..d003cc70 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -196,7 +196,7 @@ again: PushBack(ch); *tg++ = '\0'; - id = tk->TOK_IDF = str2idf(buf, 1); + tk->TOK_IDF = id = str2idf(buf, 1); if (!id) fatal("Out of memory"); return tk->tk_symb = id->id_reserved ? id->id_reserved : IDENT; } diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index 2a2bd1f0..653a2fa5 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -75,12 +75,12 @@ tokenname.o: Lpars.h idf.h tokenname.h idf.o: idf.h input.o: f_info.h input.h type.o: Lpars.h def.h def_sizes.h idf.h type.h -def.o: Lpars.h def.h idf.h main.h scope.h +def.o: Lpars.h debug.h def.h idf.h main.h scope.h scope.o: debug.h scope.h misc.o: LLlex.h f_info.h idf.h misc.h -enter.o: def.h idf.h scope.h type.h +enter.o: def.h idf.h misc.h scope.h type.h tokenfile.o: Lpars.h -program.o: LLlex.h Lpars.h idf.h main.h misc.h scope.h +program.o: LLlex.h Lpars.h def.h idf.h main.h misc.h scope.h type.h declar.o: LLlex.h Lpars.h def.h idf.h misc.h scope.h type.h expression.o: Lpars.h statement.o: Lpars.h diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 72174767..e88573d9 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -5,6 +5,7 @@ static char *RcsId = "$Header$"; #include #include +#include #include "idf.h" #include "misc.h" #include "LLlex.h" @@ -15,29 +16,26 @@ static char *RcsId = "$Header$"; ProcedureDeclaration { - register struct def *df; + struct def *df; } : - /* ProcedureHeading(&df) */ - PROCEDURE IDENT - { df = define(dot.TOK_IDF, CurrentScope, D_PROCEDURE); - open_scope(OPENSCOPE, 0); - } - FormalParameters? + ProcedureHeading(&df, D_PROCEDURE) ';' block IDENT { match_id(dot.TOK_IDF, df->df_idf); close_scope(); } ; -ProcedureHeading +ProcedureHeading(struct def **pdf; int type;) { - register struct def *df; } : - /* Only used for definition modules - */ PROCEDURE IDENT - { df = define(dot.TOK_IDF, CurrentScope, D_PROCHEAD); } - FormalParameters? + { assert(type == D_PROCEDURE || type == D_PROCHEAD); + *pdf = define(dot.TOK_IDF, CurrentScope, D_PROCHEAD); + if (type == D_PROCEDURE) { + open_scope(OPENSCOPE, 0); + } + } + FormalParameters(type, &((*pdf)->df_type))? ; block: @@ -56,13 +54,13 @@ declaration: ModuleDeclaration ';' ; -FormalParameters: - '(' [ FPSection [ ';' FPSection ]* ]? ')' +FormalParameters(int doparams; struct type **tp;) : + '(' [ FPSection(doparams) [ ';' FPSection(doparams)]* ]? ')' [ ':' qualident ]? ; -FPSection +FPSection(int doparams;) { struct id_list *FPList; int VARflag = 0; @@ -72,6 +70,13 @@ FPSection ]? IdentList(&FPList) ':' FormalType { + if (doparams) { + EnterIdList(FPList, + D_VARIABLE, + VARflag, + (struct type *) 0 /* ???? */ + ); + } FreeIdList(FPList); } ; @@ -82,10 +87,13 @@ FormalType: TypeDeclaration { - register struct def *df; + struct def *df; + struct idf *id; }: - IDENT { df = define(dot.TOK_IDF, CurrentScope, D_TYPE); } - '=' type + IDENT { id = dot.TOK_IDF; } + '=' type { df = define(id, CurrentScope, D_TYPE); + /* ???? */ + } ; type: @@ -124,22 +132,29 @@ enumeration struct id_list *EnumList; } : '(' IdentList(&EnumList) ')' + { + EnterIdList(EnumList, + D_ENUM, + 0, + (struct type *) 0 /* ???? */ + ); + FreeIdList(EnumList); + } + ; IdentList(struct id_list **p;) { register struct id_list *q = new_id_list(); } : - IDENT { q->id_ptr = dot.TOK_IDF; } + IDENT { q->id_ptr = dot.TOK_IDF; *p = q;} [ ',' IDENT { q->next = new_id_list(); q = q->next; q->id_ptr = dot.TOK_IDF; } ]* - { q->next = 0; - *p = q; - } + { q->next = 0; } ; SubrangeType: @@ -209,10 +224,13 @@ FormalTypeList: ConstantDeclaration { - register struct def *df; + struct def *df; + struct idf *id; }: - IDENT { df = define(dot.TOK_IDF, CurrentScope, D_CONST); } - '=' ConstExpression + IDENT { id = dot.TOK_IDF; } + '=' ConstExpression { df = define(id, CurrentScope, D_CONST); + /* ???? */ + } ; VariableDeclaration @@ -224,4 +242,11 @@ VariableDeclaration ConstExpression ]? ':' type + { EnterIdList(VarList, + D_VARIABLE, + 0, + (struct type *) 0 /* ???? */ + ); + FreeIdList(VarList); + } ; diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H index ea764137..ba3604df 100644 --- a/lang/m2/comp/def.H +++ b/lang/m2/comp/def.H @@ -4,6 +4,7 @@ struct module { int mo_priority; /* Priority of a module */ + int mo_scope; /* Scope of this module */ }; struct variable { diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index 336bee3a..53e69b9d 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -10,6 +10,7 @@ static char *RcsId = "$Header$"; #include "idf.h" #include "main.h" #include "scope.h" +#include "debug.h" struct def *h_def; /* Pointer to free list of def structures */ @@ -23,6 +24,7 @@ define(id, scope, kind) */ register struct def *df = lookup(id, scope->sc_scope); + DO_DEBUG(debug(3,"Defining identifier %s in scope %d", id->id_text, scope->sc_scope)); if ( /* Already in this scope */ df || /* A closed scope, and id defined in the pervasive scope */ @@ -46,7 +48,7 @@ define(id, scope, kind) return df; break; } - error("Identifier %s already declared", id->id_text); + error("Identifier \"%s\" already declared", id->id_text); return df; } df = new_def(); @@ -71,6 +73,7 @@ lookup(id, scope) df1 = 0; df = id->id_def; + DO_DEBUG(debug(3,"Looking for identifier %s in scope %d", id->id_text, scope)); while (df) { if (df->df_scope == scope) { if (df1) { @@ -80,6 +83,7 @@ lookup(id, scope) } return df; } + df1 = df; df = df->next; } return 0; diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index dc1d3110..6dcc0480 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -2,16 +2,19 @@ static char *RcsId = "$Header$"; +#include #include #include #include "idf.h" #include "def.h" #include "type.h" #include "scope.h" +#include "misc.h" extern struct idf *str2idf(); extern struct def *define(); +struct def * Enter(name, kind, type, pnam) char *name; struct type *type; @@ -26,4 +29,27 @@ Enter(name, kind, type, pnam) if (kind == D_STDPROC || kind == D_STDFUNC) { df->df_value.df_stdname = pnam; } + return df; +} + +EnterIdList(idlist, kind, flags, type) + register struct id_list *idlist; + struct type *type; +{ + register struct def *df; + struct def *last = 0; + int assval = 0; + + while (idlist) { + df = define(idlist->id_ptr, CurrentScope, kind); + df->df_type = type; + df->df_flags = flags; + if (kind == D_ENUM) { + df->df_value.df_enum.en_val = assval++; + if (last) last->df_value.df_enum.en_next = df; + last = df; + } + idlist = idlist->next; + } + if (last) last->df_value.df_enum.en_next = 0; } diff --git a/lang/m2/comp/misc.H b/lang/m2/comp/misc.H index 5ca8a003..82deee35 100644 --- a/lang/m2/comp/misc.H +++ b/lang/m2/comp/misc.H @@ -10,3 +10,5 @@ struct id_list { }; /* ALLOCDEF "id_list" */ + +#define is_anon_idf(x) ((x)->id_text[0] == '#') diff --git a/lang/m2/comp/misc.c b/lang/m2/comp/misc.c index 7afd7202..7199fc11 100644 --- a/lang/m2/comp/misc.c +++ b/lang/m2/comp/misc.c @@ -17,7 +17,7 @@ match_id(id1, id2) first place, and if not, give an error message */ if (id1 != id2 && !is_anon_idf(id1) && !is_anon_idf(id2)) { - error("Identifier \"%s\" does not match identifier \"%s\"", + error("Name \"%s\" does not match block name \"%s\"", id1->id_text, id2->id_text ); @@ -54,10 +54,3 @@ gen_anon_idf() ++name_cnt, FileName, LineNumber); return str2idf(buff, 1); } - -int -is_anon_idf(idf) - struct idf *idf; -{ - return idf->id_text[0] == '#'; -} diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 662ba71c..32e888f8 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -5,11 +5,14 @@ static char *RcsId = "$Header$"; #include #include +#include #include "idf.h" #include "misc.h" #include "main.h" #include "LLlex.h" #include "scope.h" +#include "def.h" +#include "type.h" } /* The grammar as given by Wirth is already almost LL(1); the @@ -40,8 +43,13 @@ priority: export { struct id_list *ExportList; + int QUALflag = 0; } : - EXPORT QUALIFIED? IdentList(&ExportList) ';' + EXPORT + [ + QUALIFIED { QUALflag = 1; } + ]? + IdentList(&ExportList) ';' { FreeIdList(ExportList); } @@ -67,9 +75,16 @@ import(int local;) } ; -DefinitionModule: +DefinitionModule +{ + struct def *df; +} : DEFINITION { state = DEFINITION; } - MODULE IDENT { open_scope(CLOSEDSCOPE, 0); } + MODULE IDENT { + df = define(dot.TOK_IDF, CurrentScope, D_MODULE); + open_scope(CLOSEDSCOPE, 0); + df->df_value.df_module.mo_scope = CurrentScope->sc_scope; + } ';' import(0)* /* export? @@ -80,7 +95,10 @@ DefinitionModule: { close_scope(); } ; -definition: +definition +{ + struct def *df; +} : CONST [ ConstantDeclaration ';' ]* | TYPE @@ -98,13 +116,17 @@ definition: | VAR [ VariableDeclaration ';' ]* | - ProcedureHeading ';' + ProcedureHeading(&df, D_PROCHEAD) ';' ; ProgramModule: MODULE { if (state != IMPLEMENTATION) state = PROGRAM; } IDENT { if (state == IMPLEMENTATION) { - /* Re-open scope ??? */ + /* ???? + Read definition module, + Look for current identifier, + and find out its scope number + */ open_scope(CLOSEDSCOPE, 0); } else open_scope(CLOSEDSCOPE, 0); From 9476cc28992c418bc022898da7898ad652f6f712 Mon Sep 17 00:00:00 2001 From: erikb Date: Thu, 27 Mar 1986 11:01:12 +0000 Subject: [PATCH 0154/1625] modified the string-constant printing routines; bts2str() is invoked --- lang/cem/cemcom/Makefile.erik | 2 +- lang/cem/cemcom/dumpidf.c | 12 ++++++++++-- lang/cem/cemcom/main.c | 9 ++++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lang/cem/cemcom/Makefile.erik b/lang/cem/cemcom/Makefile.erik index 3fe90182..8acb5b6e 100644 --- a/lang/cem/cemcom/Makefile.erik +++ b/lang/cem/cemcom/Makefile.erik @@ -185,7 +185,7 @@ sim: cfiles $(SIM) $(SIMFLAGS) `sources $(COBJ)` $(GSRC) $(LSRC) #AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO -main.o: LLlex.h Lpars.h alloc.h arith.h debug.h declar.h idf.h input.h inputtype.h level.h maxincl.h myalloc.h nobitfield.h nopp.h spec_arith.h specials.h target_sizes.h tokenname.h type.h use_tmp.h +main.o: LLlex.h Lpars.h alloc.h arith.h debug.h declar.h idf.h input.h inputtype.h level.h maxincl.h myalloc.h nobitfield.h nopp.h spec_arith.h specials.h target_sizes.h tokenname.h type.h use_tmp.h ssize.h idf.o: LLlex.h Lpars.h align.h alloc.h arith.h assert.h botch_free.h debug.h declar.h decspecs.h def.h idf.h idfsize.h label.h level.h nobitfield.h nopp.h sizes.h spec_arith.h specials.h stack.h storage.h struct.h type.h declarator.o: Lpars.h alloc.h arith.h botch_free.h declar.h expr.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h type.h decspecs.o: Lpars.h arith.h decspecs.h def.h level.h nobitfield.h spec_arith.h type.h diff --git a/lang/cem/cemcom/dumpidf.c b/lang/cem/cemcom/dumpidf.c index b2732bfd..867b7317 100644 --- a/lang/cem/cemcom/dumpidf.c +++ b/lang/cem/cemcom/dumpidf.c @@ -284,7 +284,8 @@ type2str(tp) } char * /* the ultimate transient buffer supplier */ -next_transient() { +next_transient() +{ static int bnum; static char buf[MAXTRANS][300]; @@ -340,8 +341,15 @@ p1_expr(lvl, expr) v->vl_value); break; case String: - printf("%s\n", expr->SG_VALUE); + { + char bts2str(); + + printf( + "%s\n", + bts2str(expr->SG_VALUE, expr->SG_LEN, next_transient()) + ); break; + } case Float: printf("%s\n", expr->FL_VALUE); break; diff --git a/lang/cem/cemcom/main.c b/lang/cem/cemcom/main.c index 276b11f0..685f7830 100644 --- a/lang/cem/cemcom/main.c +++ b/lang/cem/cemcom/main.c @@ -21,6 +21,7 @@ #include "LLlex.h" #include "alloc.h" #include "specials.h" +#include "ssize.h" extern struct tokenname tkidf[], tkother[]; extern char *symbol2str(); @@ -328,8 +329,14 @@ preprocess() printf(" "); break; case STRING: - printf("\"%s\" ", dot.tk_bts); + { + char sbuf[SSIZE]; + char *bts2str(); + + printf("\"%s\" ", + bts2str(dot.tk_bts, dot.tk_len, sbuf)); break; + } case INTEGER: printf("%ld ", dot.tk_ival); break; From 2a200d721136aa5c7139cd4365051560376c9a1e Mon Sep 17 00:00:00 2001 From: sater Date: Thu, 27 Mar 1986 15:49:16 +0000 Subject: [PATCH 0155/1625] repaired inreg() pseudofunction, it delivered total nonsense --- mach/proto/ncg/compute.c | 3 +-- mach/proto/ncg/regvar.c | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/mach/proto/ncg/compute.c b/mach/proto/ncg/compute.c index 4682fb71..0de478fa 100644 --- a/mach/proto/ncg/compute.c +++ b/mach/proto/ncg/compute.c @@ -346,8 +346,7 @@ result_t compute(node) register node_p node; { #ifdef REGVARS case EX_INREG: assert(leaf1.e_typ == EV_INT); - if ((result.e_v.e_con = isregvar((long) leaf1.e_v.e_con))>0) - result.e_v.e_con = machregs[result.e_v.e_con].r_size; + result.e_v.e_con = isregtyp((long) leaf1.e_v.e_con); return(result); case EX_REGVAR: assert(leaf1.e_typ == EV_INT); diff --git a/mach/proto/ncg/regvar.c b/mach/proto/ncg/regvar.c index 9805d0ec..c0f48d5a 100644 --- a/mach/proto/ncg/regvar.c +++ b/mach/proto/ncg/regvar.c @@ -111,6 +111,7 @@ fixregvars(saveall) { } else if(regassigned[rvtyp][i].ra_score>0) { rv=regassigned[rvtyp][i].ra_rv; rv->rv_reg=rvnumbers[rvtyp][i]; + rv->rv_type = rvtyp; regsave(codestrings[machregs[rv->rv_reg].r_repr], rv->rv_off,rv->rv_size); } @@ -127,6 +128,15 @@ isregvar(off) long off; { return(-1); } +isregtyp(off) long off; { + register struct regvar *rvlp; + + for(rvlp=rvlist;rvlp!=0;rvlp=rvlp->rv_next) + if(rvlp->rv_off == off) + return(rvlp->rv_reg ? rvlp->rv_type+1 : 0); + return(-1); +} + unlinkregs() { register struct regvar *rvlp,*t; register struct regassigned *ra; From 0968b74220007dda10d2a5238ba11284aada19ef Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 27 Mar 1986 17:37:41 +0000 Subject: [PATCH 0156/1625] safety commit, newer version --- lang/m2/comp/Makefile | 4 +- lang/m2/comp/declar.g | 250 +++++++++++++++++++++++++++++--------- lang/m2/comp/def.H | 40 +++--- lang/m2/comp/def.c | 25 ++-- lang/m2/comp/enter.c | 34 +++++- lang/m2/comp/error.c | 4 +- lang/m2/comp/expression.g | 75 ++++++++++-- lang/m2/comp/main.c | 12 +- lang/m2/comp/misc.H | 3 + lang/m2/comp/program.g | 5 +- lang/m2/comp/scope.C | 81 ++++++++++-- lang/m2/comp/scope.h | 5 +- lang/m2/comp/tokenname.c | 1 + lang/m2/comp/type.H | 4 +- lang/m2/comp/type.c | 27 +++- 15 files changed, 444 insertions(+), 126 deletions(-) diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index 653a2fa5..d8a5804e 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -76,12 +76,12 @@ idf.o: idf.h input.o: f_info.h input.h type.o: Lpars.h def.h def_sizes.h idf.h type.h def.o: Lpars.h debug.h def.h idf.h main.h scope.h -scope.o: debug.h scope.h +scope.o: LLlex.h debug.h def.h idf.h scope.h type.h misc.o: LLlex.h f_info.h idf.h misc.h enter.o: def.h idf.h misc.h scope.h type.h tokenfile.o: Lpars.h program.o: LLlex.h Lpars.h def.h idf.h main.h misc.h scope.h type.h declar.o: LLlex.h Lpars.h def.h idf.h misc.h scope.h type.h -expression.o: Lpars.h +expression.o: LLlex.h Lpars.h def.h idf.h scope.h statement.o: Lpars.h Lpars.o: Lpars.h diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index e88573d9..3989bb68 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -27,15 +27,17 @@ ProcedureDeclaration ProcedureHeading(struct def **pdf; int type;) { + struct type *tp; + struct paramlist *params = 0; } : PROCEDURE IDENT { assert(type == D_PROCEDURE || type == D_PROCHEAD); - *pdf = define(dot.TOK_IDF, CurrentScope, D_PROCHEAD); + *pdf = define(dot.TOK_IDF, CurrentScope, type); if (type == D_PROCEDURE) { open_scope(OPENSCOPE, 0); } } - FormalParameters(type, &((*pdf)->df_type))? + FormalParameters(type, ¶ms, &tp)? ; block: @@ -54,15 +56,31 @@ declaration: ModuleDeclaration ';' ; -FormalParameters(int doparams; struct type **tp;) : - '(' [ FPSection(doparams) [ ';' FPSection(doparams)]* ]? ')' - [ ':' qualident +FormalParameters(int doparams; struct paramlist **pr; struct type **tp;) +{ + struct def *df; + register struct paramlist *pr1; +} : + '(' + [ + FPSection(doparams, pr) + [ + { for (pr1 = *pr; pr1->next; pr1 = pr1->next) ; } + ';' FPSection(doparams, &(pr1->next)) + ]* + ]? + ')' + { *tp = 0; } + [ ':' qualident(D_TYPE | D_HTYPE, &df, "type") + { /* ???? *tp = df->df_type; */ } ]? ; -FPSection(int doparams;) +FPSection(int doparams; struct paramlist **ppr;) { struct id_list *FPList; + register struct id_list *pid; + register struct paramlist *pr = 0; int VARflag = 0; } : [ @@ -74,70 +92,88 @@ FPSection(int doparams;) EnterIdList(FPList, D_VARIABLE, VARflag, - (struct type *) 0 /* ???? */ + (struct type *) 0 /* ???? */, + CurrentScope ); } + *ppr = pr = new_paramlist(); + pr->par_type = 0; /* ??? */ + pr->par_var = VARflag; + for (pid = FPList->next; pid; pid = pid->next) { + pr->next = new_paramlist(); + pr = pr->next; + pr->par_type = 0; /* ??? */ + pr->par_var = VARflag; + } + pr->next = 0; FreeIdList(FPList); } ; -FormalType: - [ ARRAY OF ]? qualident +FormalType +{ + struct def *df; + int ARRAYflag = 0; +} : + [ ARRAY OF { ARRAYflag = 1; } + ]? + qualident(D_TYPE | D_HTYPE, &df, "type") ; TypeDeclaration { struct def *df; - struct idf *id; + struct type *tp; }: - IDENT { id = dot.TOK_IDF; } - '=' type { df = define(id, CurrentScope, D_TYPE); - /* ???? */ + IDENT { df = define(dot.TOK_IDF, CurrentScope, D_TYPE); } + '=' type(&tp) + { df->df_type = tp; } ; -type: - SimpleType +type(struct type **ptp;): + SimpleType(ptp) | - ArrayType + ArrayType(ptp) | - RecordType + RecordType(ptp) | - SetType + SetType(ptp) | - PointerType + PointerType(ptp) | - ProcedureType + ProcedureType(ptp) ; -SimpleType: - qualident +SimpleType(struct type **ptp;) +{ + struct def *df; +} : + qualident(D_TYPE | D_HTYPE, &df, "type") [ | - SubrangeType + SubrangeType(ptp) /* * The subrange type is given a base type by the * qualident (this is new modula-2). */ + { /* ???? (*ptp)->next = df->df_type; */ } ] | - enumeration + enumeration(ptp) | - SubrangeType + SubrangeType(ptp) ; -enumeration +enumeration(struct type **ptp;) { struct id_list *EnumList; } : '(' IdentList(&EnumList) ')' { - EnterIdList(EnumList, - D_ENUM, - 0, - (struct type *) 0 /* ???? */ - ); + *ptp = standard_type(ENUMERATION,int_align,int_size); + EnterIdList(EnumList, D_ENUM, 0, *ptp, CurrentScope); FreeIdList(EnumList); } @@ -157,43 +193,102 @@ IdentList(struct id_list **p;) { q->next = 0; } ; -SubrangeType: +SubrangeType(struct type **ptp;) +{ + struct type *tp; +}: /* This is not exactly the rule in the new report, but see the rule for "SimpleType". */ - '[' ConstExpression UPTO ConstExpression ']' + '[' ConstExpression + UPTO ConstExpression + ']' + /* + Evaluate the expressions. Check that they are indeed constant. + ??? + Leave the basetype of the subrange in tp; + */ + { + /* For the time being: */ + tp = int_type; + tp = construct_type(SUBRANGE, tp, (arith) 0); + *ptp = tp; + } ; -ArrayType: - ARRAY SimpleType [ ',' SimpleType ]* OF type +ArrayType(struct type **ptp;) +{ + struct type *tp; + register struct type *tp2; +} : + ARRAY SimpleType(&tp) + { + *ptp = tp2 = construct_type(ARRAY, tp); + } + [ + ',' SimpleType(&tp) + { tp2 = tp2->tp_value.tp_arr.ar_elem = + construct_type(ARRAY, tp); + } + ]* OF type(&tp) + { tp2->tp_value.tp_arr.ar_elem = tp; } ; -RecordType: - RECORD FieldListSequence END +RecordType(struct type **ptp;) +{ + int scopenr; +} +: + RECORD + { scopenr = uniq_scope(); } + FieldListSequence(scopenr) + { + *ptp = standard_type(RECORD, record_align, (arith) 0 /* ???? */); + (*ptp)->tp_value.tp_record.rc_scopenr = scopenr; + } + END ; -FieldListSequence: - FieldList [ ';' FieldList ]* +FieldListSequence(int scopenr;): + FieldList(scopenr) + [ + ';' FieldList(scopenr) + ]* ; -FieldList +FieldList(int scopenr;) { struct id_list *FldList; + struct idf *id; + struct def *df, *df1; + struct type *tp; } : [ - IdentList(&FldList) ':' type + IdentList(&FldList) ':' type(&tp) | - CASE IDENT? /* Changed rule in new modula-2 */ - ':' qualident - OF variant [ '|' variant ]* - [ ELSE FieldListSequence ]? + CASE + [ + IDENT { id = dot.TOK_IDF; } + | + { id = gen_anon_idf(); } + ] /* Changed rule in new modula-2 */ + ':' qualident(D_TYPE|D_HTYPE, &df, "type") + { df1 = define(id, scopenr, D_FIELD); + df1->df_type = df->df_type; + } + OF variant(scopenr) + [ + '|' variant(scopenr) + ]* + [ ELSE FieldListSequence(scopenr) + ]? END ]? ; -variant: - [ CaseLabelList ':' FieldListSequence ]? +variant(int scopenr;): + [ CaseLabelList ':' FieldListSequence(scopenr) ]? /* Changed rule in new modula-2 */ ; @@ -205,21 +300,59 @@ CaseLabels: ConstExpression [ UPTO ConstExpression ]? ; -SetType: - SET OF SimpleType +SetType(struct type **ptp;) +{ + struct type *tp; +} : + SET OF SimpleType(&tp) + { + *ptp = construct_type(SET, tp, (arith) 0 /* ???? */); + } ; -PointerType: - POINTER TO type +PointerType(struct type **ptp;) +{ + struct type *tp; + register struct def *df; + struct def *lookfor(); +} : + POINTER TO + [ %if ( (df = lookup(dot.TOK_IDF, CurrentScope))) + IDENT + { + if (!(df->df_kind & (D_TYPE | D_HTYPE))) { + error("\"%s\" is not a type identifier", + df->df_idf->id_text); + } + if (!df->df_type) { + error("type \"%s\" not declared", + df->df_idf->id_text); + } + *ptp = df->df_type; + } + | %if (df = lookfor(dot.TOK_IDF, 0), df->df_kind == D_MODULE) + type(&tp) + { *ptp = construct_type(POINTER, tp); } + | + IDENT + { *ptp = construct_type(POINTER, NULLTYPE); + Forward(&dot, &((*ptp)->next)); + } + ] ; -ProcedureType: +ProcedureType(struct type **ptp;): PROCEDURE FormalTypeList? + { *ptp = 0; } ; -FormalTypeList: +FormalTypeList +{ + struct def *df; +} : '(' [ VAR? FormalType [ ',' VAR? FormalType ]* ]? ')' - [ ':' qualident ]? + [ ':' qualident(1, &df, "type") + ]? ; ConstantDeclaration @@ -236,17 +369,14 @@ ConstantDeclaration VariableDeclaration { struct id_list *VarList; + struct type *tp; } : IdentList(&VarList) [ ConstExpression ]? - ':' type - { EnterIdList(VarList, - D_VARIABLE, - 0, - (struct type *) 0 /* ???? */ - ); + ':' type(&tp) + { EnterIdList(VarList, D_VARIABLE, 0, tp, CurrentScope); FreeIdList(VarList); } ; diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H index ba3604df..24abd798 100644 --- a/lang/m2/comp/def.H +++ b/lang/m2/comp/def.H @@ -38,21 +38,24 @@ struct def { /* list of definitions for a name */ struct def *next; struct idf *df_idf; /* link back to the name */ int df_scope; /* Scope in which this definition resides */ - char df_kind; /* The kind of this definition: */ -#define D_MODULE 0x00 -#define D_PROCEDURE 0x01 -#define D_VARIABLE 0x02 -#define D_FIELD 0x03 -#define D_TYPE 0x04 -#define D_ENUM 0x05 -#define D_CONST 0x06 -#define D_IMPORT 0x07 -#define D_PROCHEAD 0x08 /* A procedure heading in a definition module */ -#define D_HIDDEN 0x09 /* A hidden type */ -#define D_HTYPE 0x0A /* Definition of a hidden type seen */ -#define D_STDPROC 0x0B /* A standard procedure */ -#define D_STDFUNC 0x0C /* A standard function */ -#define D_ISEXPORTED 0xFF /* Not yet defined */ + short df_kind; /* The kind of this definition: */ +#define D_MODULE 0x0001 +#define D_PROCEDURE 0x0002 +#define D_VARIABLE 0x0004 +#define D_FIELD 0x0008 +#define D_TYPE 0x0010 +#define D_ENUM 0x0020 +#define D_CONST 0x0040 +#define D_IMPORT 0x0080 +#define D_PROCHEAD 0x0100 /* A procedure heading in a definition module */ +#define D_HIDDEN 0x0200 /* A hidden type */ +#define D_HTYPE 0x0400 /* Definition of a hidden type seen */ +#define D_STDPROC 0x0800 /* A standard procedure */ +#define D_STDFUNC 0x1000 /* A standard function */ +#define D_ERROR 0x2000 /* A compiler generated definition for an + undefined variable + */ +#define D_ISEXPORTED 0x4000 /* Not yet defined */ char df_flags; #define D_ADDRESS 0x01 /* Set if address was taken */ #define D_USED 0x02 /* Set if used */ @@ -74,6 +77,9 @@ struct def { /* list of definitions for a name */ /* ALLOCDEF "def" */ -struct def +extern struct def *define(), - *lookup(); + *lookup(), + *ill_df; + +#define NULLDEF ((struct def *) 0) diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index 53e69b9d..5a815e9a 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -14,21 +14,30 @@ static char *RcsId = "$Header$"; struct def *h_def; /* Pointer to free list of def structures */ +static struct def illegal_def = + {0, 0, -20 /* Illegal scope */, D_ERROR}; + +struct def *ill_df = &illegal_def; + struct def * define(id, scope, kind) register struct idf *id; - register struct scope *scope; { /* Declare an identifier in a scope, but first check if it already has been defined. If so, error message. */ - register struct def *df = lookup(id, scope->sc_scope); + register struct def *df; - DO_DEBUG(debug(3,"Defining identifier %s in scope %d", id->id_text, scope->sc_scope)); + DO_DEBUG(debug(4,"Defining identifier %s in scope %d", id->id_text, scope)); + df = lookup(id, scope); if ( /* Already in this scope */ df || /* A closed scope, and id defined in the pervasive scope */ - (scopeclosed(scope) && (df = lookup(id, 0))) + ( CurrentScope == scope + && + scopeclosed(currscope) + && + (df = lookup(id, 0))) ) { switch(df->df_kind) { case D_PROCHEAD: @@ -43,17 +52,17 @@ define(id, scope, kind) return df; } break; + case D_ERROR: case D_ISEXPORTED: df->df_kind = kind; return df; - break; } - error("Identifier \"%s\" already declared", id->id_text); + error("identifier \"%s\" already declared", id->id_text); return df; } df = new_def(); df->df_idf = id; - df->df_scope = scope->sc_scope; + df->df_scope = scope; df->df_kind = kind; df->next = id->id_def; id->id_def = df; @@ -73,7 +82,7 @@ lookup(id, scope) df1 = 0; df = id->id_def; - DO_DEBUG(debug(3,"Looking for identifier %s in scope %d", id->id_text, scope)); + DO_DEBUG(debug(4,"Looking for identifier %s in scope %d", id->id_text, scope)); while (df) { if (df->df_scope == scope) { if (df1) { diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index 6dcc0480..d5c1322e 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -32,24 +32,50 @@ Enter(name, kind, type, pnam) return df; } -EnterIdList(idlist, kind, flags, type) +EnterIdList(idlist, kind, flags, type, scope) register struct id_list *idlist; struct type *type; { register struct def *df; - struct def *last = 0; + struct def *first = 0, *last = 0; int assval = 0; while (idlist) { - df = define(idlist->id_ptr, CurrentScope, kind); + df = define(idlist->id_ptr, scope, kind); df->df_type = type; df->df_flags = flags; if (kind == D_ENUM) { + if (!first) first = df; df->df_value.df_enum.en_val = assval++; if (last) last->df_value.df_enum.en_next = df; last = df; } idlist = idlist->next; } - if (last) last->df_value.df_enum.en_next = 0; + if (last) { + /* Also meaning : enumeration */ + last->df_value.df_enum.en_next = 0; + type->tp_value.tp_enum.en_enums = first; + type->tp_value.tp_enum.en_ncst = assval; + } +} + +/* Look for an identifier in the current visibility range. + If it is not defined, give an error message, and + create a dummy definition. +*/ +struct def * +lookfor(id, give_error) + struct idf *id; +{ + register struct scope *sc = currscope; + struct def *df; + + while (sc) { + df = lookup(id, sc->sc_scope); + if (df) return df; + sc = nextvisible(sc); + } + if (give_error) error("Identifier \"%s\" not declared", id->id_text); + return define(id, CurrentScope, D_ERROR); } diff --git a/lang/m2/comp/error.c b/lang/m2/comp/error.c index 278a39d7..1a769bce 100644 --- a/lang/m2/comp/error.c +++ b/lang/m2/comp/error.c @@ -132,7 +132,7 @@ _error(class, expr, fmt, argv) case LEXERROR: case CRASH: case FATAL: - /* + /* ???? if (C_busy()) C_ms_err(); */ @@ -164,7 +164,7 @@ _error(class, expr, fmt, argv) switch (class) { case WARNING: case ERROR: - ln = /* expr ? expr->ex_line : */ dot.tk_lineno; + ln = /* ???? expr ? expr->ex_line : */ dot.tk_lineno; break; case LEXWARNING: case LEXERROR: diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index c56441ff..38c08a76 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -1,5 +1,15 @@ +/* E X P R E S S I O N S */ + { static char *RcsId = "$Header$"; + +#include +#include +#include +#include "LLlex.h" +#include "idf.h" +#include "def.h" +#include "scope.h" } number: @@ -8,8 +18,44 @@ number: REAL ; -qualident: - IDENT selector* +qualident(int types; struct def **pdf; char *str;) +{ + int scope; + register struct def *df; + struct def *lookfor(); +} : + IDENT { if (types) { + df = lookfor(dot.TOK_IDF, 1); + if (df->df_kind == D_ERROR) { + *pdf = df; + types = 0; + } + } + } + [ + { if (types &&!(scope = has_selectors(df))) { + types = 0; + *pdf = ill_df; + } + } + /* selector */ + '.' IDENT + { if (types) { + df = lookup(dot.TOK_IDF, scope); + if (!df) { + error("identifier \"%s\" not declared", + dot.TOK_IDF->id_text); + types = 0; + df = ill_df; + } + } + } + ]* + { if (types && !(types & df->df_kind)) { + error("identifier \"%s\" is not a %s", + dot.TOK_IDF, str); + } + } ; selector: @@ -52,8 +98,11 @@ MulOperator: '*' | '/' | DIV | MOD | AND | '&' ; -factor: - qualident +factor +{ + struct def *df; +} : + qualident(0, &df, (char *) 0) [ designator_tail? ActualParameters? | @@ -83,15 +132,25 @@ element: expression [ UPTO expression ]? ; -designator: - qualident designator_tail? +designator +{ + struct def *df; +} : + qualident(0, &df, (char *) 0) + designator_tail? ; designator_tail: visible_designator_tail - [ selector | visible_designator_tail ]* + [ + selector + | + visible_designator_tail + ]* ; visible_designator_tail: - '[' ExpList ']' | '^' + '[' ExpList ']' +| + '^' ; diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index b245420a..7ff75edf 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -121,8 +121,6 @@ Option(str) options[str[1]]++; /* switch option on */ } -#define NULLTYPE ((struct type *) 0) - add_standards() { register struct def *df; @@ -157,15 +155,13 @@ add_standards() (void) Enter("NIL", D_CONST, nil_type, 0); (void) Enter("PROC", D_TYPE, - construct_type(PROCEDURE, NULLTYPE, (arith) 0), + construct_type(PROCEDURE, NULLTYPE), 0); - tp = construct_type(SUBRANGE, int_type, (arith) 0); + tp = construct_type(SUBRANGE, int_type); tp->tp_value.tp_subrange.su_lb = 0; tp->tp_value.tp_subrange.su_ub = wrd_size * 8 - 1; - (void) Enter("BITSET", - D_TYPE, - construct_type(SET, tp, wrd_size), - 0); + df = Enter("BITSET", D_TYPE, construct_type(SET, tp), 0); + df->df_type->tp_size = wrd_size; df = Enter("FALSE", D_ENUM, bool_type, 0); df->df_value.df_enum.en_val = 0; df->df_value.df_enum.en_next = Enter("TRUE", D_ENUM, bool_type, 0); diff --git a/lang/m2/comp/misc.H b/lang/m2/comp/misc.H index 82deee35..ef9a7815 100644 --- a/lang/m2/comp/misc.H +++ b/lang/m2/comp/misc.H @@ -12,3 +12,6 @@ struct id_list { /* ALLOCDEF "id_list" */ #define is_anon_idf(x) ((x)->id_text[0] == '#') + +extern struct idf + *gen_anon_idf(); diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 32e888f8..77751d7a 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -83,7 +83,7 @@ DefinitionModule MODULE IDENT { df = define(dot.TOK_IDF, CurrentScope, D_MODULE); open_scope(CLOSEDSCOPE, 0); - df->df_value.df_module.mo_scope = CurrentScope->sc_scope; + df->df_value.df_module.mo_scope = CurrentScope; } ';' import(0)* @@ -98,12 +98,13 @@ DefinitionModule definition { struct def *df; + struct type *tp; } : CONST [ ConstantDeclaration ';' ]* | TYPE [ IDENT - [ '=' type + [ '=' type(&tp) | /* empty */ /* Here, the exported type has a hidden implementation. diff --git a/lang/m2/comp/scope.C b/lang/m2/comp/scope.C index f46f3cfd..6eafc237 100644 --- a/lang/m2/comp/scope.C +++ b/lang/m2/comp/scope.C @@ -4,12 +4,18 @@ static char *RcsId = "$Header$"; #include #include +#include +#include +#include "LLlex.h" +#include "idf.h" #include "scope.h" +#include "type.h" +#include "def.h" #include "debug.h" static int maxscope; /* maximum assigned scope number */ -struct scope *CurrentScope; +struct scope *currscope; /* STATICALLOCDEF "scope" */ @@ -29,29 +35,32 @@ open_scope(scopetype, scopenr) sc->sc_scope = scopenr == 0 ? ++maxscope : scopenr; assert(scopetype == OPENSCOPE || scopetype == CLOSEDSCOPE); DO_DEBUG(debug(1, "Opening a %s scope", scopetype == OPENSCOPE ? "open" : "closed")); - sc1 = CurrentScope; + sc1 = currscope; if (scopetype == CLOSEDSCOPE) { sc1 = new_scope(); - sc1->sc_scope = 0; /* Pervasive scope nr */ - sc1->next = CurrentScope; + sc1->sc_scope = 0; /* Pervasive scope nr */ + sc1->next = currscope; } sc->next = sc1; - CurrentScope = sc; + currscope = sc; } +static rem_forwards(); + close_scope() { - register struct scope *sc = CurrentScope; + register struct scope *sc = currscope; assert(sc != 0); DO_DEBUG(debug(1, "Closing a scope")); + if (sc->sc_forw) rem_forwards(sc->sc_forw); if (sc->next && (sc->next->sc_scope == 0)) { struct scope *sc1 = sc; sc = sc->next; free_scope(sc1); } - CurrentScope = sc->next; + currscope = sc->next; free_scope(sc); } @@ -61,5 +70,61 @@ init_scope() sc->sc_scope = 0; sc->next = 0; - CurrentScope = sc; + currscope = sc; +} + +int +uniq_scope() +{ + return ++maxscope; +} + +struct forwards { + struct forwards *next; + struct token fo_tok; + struct type **fo_ptyp; +}; + +/* STATICALLOCDEF "forwards" */ + +/* Enter a forward reference into a list belonging to the + current scope. This is used for POINTER declarations, which + may have forward references that must howewer be declared in the + same scope. +*/ +Forward(tk, ptp) + struct token *tk; + struct type **ptp; +{ + register struct forwards *f = new_forwards(); + + f->fo_tok = *tk; + f->fo_ptyp = ptp; + f->next = currscope->sc_forw; + currscope->sc_forw = f; +} + +/* When closing a scope, all forward references must be resolved +*/ +static +rem_forwards(fo) + struct forwards *fo; +{ + register struct forwards *f; + struct token savetok; + register struct def *df; + struct def *lookfor(); + + savetok = dot; + while (f = fo) { + dot = f->fo_tok; + df = lookfor(dot.TOK_IDF, 1); + if (!(df->df_kind & (D_TYPE | D_HTYPE | D_ERROR))) { + error("identifier \"%s\" not a type", df->df_idf->id_text); + } + *(f->fo_ptyp) = df->df_type; + fo = f->next; + free_forwards(f); + } + dot = savetok; } diff --git a/lang/m2/comp/scope.h b/lang/m2/comp/scope.h index 20e72ada..f924b6b8 100644 --- a/lang/m2/comp/scope.h +++ b/lang/m2/comp/scope.h @@ -7,6 +7,7 @@ struct scope { struct scope *next; + struct forwards *sc_forw; int sc_scope; /* The scope number. Scope number 0 indicates both the pervasive scope and the end of a visibility range @@ -14,7 +15,9 @@ struct scope { }; extern struct scope - *CurrentScope; + *currscope; #define nextvisible(x) ((x)->sc_scope ? (x)->next : (struct scope *) 0) #define scopeclosed(x) ((x)->next->sc_scope == 0) +#define enclosing(x) ((x)->next->scope != 0 ? (struct scope *) 0 : (x)->next->next) +#define CurrentScope (currscope->sc_scope) diff --git a/lang/m2/comp/tokenname.c b/lang/m2/comp/tokenname.c index 97020e03..6d16fe3f 100644 --- a/lang/m2/comp/tokenname.c +++ b/lang/m2/comp/tokenname.c @@ -86,6 +86,7 @@ struct tokenname tkstandard[] = { /* standard identifiers */ {CARDINAL, ""}, {LONGREAL, ""}, {SUBRANGE, ""}, + {ENUMERATION, ""}, {ERRONEOUS, ""}, {0, ""} }; diff --git a/lang/m2/comp/type.H b/lang/m2/comp/type.H index ca59a1f0..942fcbf9 100644 --- a/lang/m2/comp/type.H +++ b/lang/m2/comp/type.H @@ -22,7 +22,7 @@ struct subrange { }; struct array { - struct type *ar_index; /* Type of index */ + struct type *ar_elem; /* Type of elements */ arith ar_lb, ar_ub; /* Lower bound and upper bound */ label ar_descr; /* Label of array descriptor */ }; @@ -90,3 +90,5 @@ struct type *create_type(), *construct_type(), *standard_type(); + +#define NULLTYPE ((struct type *) 0) diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index 37fb537a..a8eb5566 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -64,9 +64,8 @@ create_type(fund) } struct type * -construct_type(fund, tp, count) +construct_type(fund, tp) struct type *tp; - arith count; { /* fund must be a type constructor. The pointer to the constructed type is returned. @@ -82,13 +81,10 @@ construct_type(fund, tp, count) break; case SET: dtp->tp_align = wrd_align; - dtp->tp_size = align((count + 7) / 8, wrd_align); dtp->next = tp; break; case ARRAY: dtp->tp_align = tp->tp_align; - if (tp->tp_size < 0) dtp->tp_size = -1; - else dtp->tp_size = count * tp->tp_size; dtp->next = tp; break; case SUBRANGE: @@ -134,3 +130,24 @@ init_types() nil_type = standard_type(POINTER, ptr_align, ptr_size); error_type = standard_type(ERRONEOUS, 1, (arith) 1); } + +int +has_selectors(df) + register struct def *df; +{ + + switch(df->df_kind) { + case D_MODULE: + return df->df_value.df_module.mo_scope; + case D_VARIABLE: { + register struct type *tp = df->df_type; + + if (tp->tp_fund == RECORD) { + return tp->tp_value.tp_record.rc_scopenr; + } + break; + } + } + error("no selectors for \"%s\"", df->df_idf->id_text); + return 0; +} From 1581b2ecd848f20a5b5205721deaa4c1b54376d4 Mon Sep 17 00:00:00 2001 From: dick Date: Thu, 27 Mar 1986 18:17:48 +0000 Subject: [PATCH 0157/1625] expression nodes now can have a flag EX_ERROR --- lang/cem/cemcom/arith.c | 10 +++++----- lang/cem/cemcom/ch7.c | 24 ++++++++++++++++-------- lang/cem/cemcom/ch7bin.c | 6 ++---- lang/cem/cemcom/ch7mon.c | 11 +++-------- lang/cem/cemcom/dumpidf.c | 4 ++-- lang/cem/cemcom/error.c | 5 +++++ lang/cem/cemcom/expr.c | 6 +++--- lang/cem/cemcom/expr.str | 11 ++++++----- lang/cem/cemcom/ival.c | 3 +-- lang/cem/cemcom/program.g | 3 ++- lang/cem/cemcom/switch.c | 5 +++++ 11 files changed, 50 insertions(+), 38 deletions(-) diff --git a/lang/cem/cemcom/arith.c b/lang/cem/cemcom/arith.c index 29755d4d..629fbac0 100644 --- a/lang/cem/cemcom/arith.c +++ b/lang/cem/cemcom/arith.c @@ -110,12 +110,10 @@ ch76pointer(expp, oper, tp) ) /* ch 7.7 */ ch7cast(expp, CAST, tp); else { - if ((*expp)->ex_type != error_type) - expr_error(*expp, "%s on %s and pointer", + expr_error(*expp, "%s on %s and pointer", symbol2str(oper), symbol2str((*expp)->ex_type->tp_fund) ); - (*expp)->ex_type = error_type; ch7cast(expp, oper, tp); } } @@ -177,8 +175,11 @@ erroneous2int(expp) /* the (erroneous) expression *expp is replaced by an int expression */ + int flags = (*expp)->ex_flags; + free_expression(*expp); *expp = intexpr((arith)0, INT); + (*expp)->ex_flags = (flags | EX_ERROR); } struct expr * @@ -291,8 +292,7 @@ opnd2integral(expp, oper) register int fund = (*expp)->ex_type->tp_fund; if (fund != INT && fund != LONG) { - if (fund != ERRONEOUS) - expr_error(*expp, "%s operand to %s", + expr_error(*expp, "%s operand to %s", symbol2str(fund), symbol2str(oper)); erroneous2int(expp); /* fund = INT; */ diff --git a/lang/cem/cemcom/ch7.c b/lang/cem/cemcom/ch7.c index 9812e8f8..0f39bcfd 100644 --- a/lang/cem/cemcom/ch7.c +++ b/lang/cem/cemcom/ch7.c @@ -61,7 +61,6 @@ ch7sel(expp, oper, idf) /* filter out illegal expressions "non_lvalue.sel" */ if (!(*expp)->ex_lvalue) { expr_error(*expp, "dot requires lvalue"); - (*expp)->ex_type = error_type; return; } } @@ -102,6 +101,8 @@ ch7sel(expp, oper, idf) */ (*expp)->VL_VALUE += sd->sd_offset; (*expp)->ex_type = sd->sd_type; + if ((*expp)->ex_type == error_type) + (*expp)->ex_flags |= EX_ERROR; } else if ((*expp)->ex_class == Oper) { @@ -110,16 +111,20 @@ ch7sel(expp, oper, idf) if (op->op_oper == '.' || op->op_oper == ARROW) { op->op_right->VL_VALUE += sd->sd_offset; (*expp)->ex_type = sd->sd_type; + if ((*expp)->ex_type == error_type) + (*expp)->ex_flags |= EX_ERROR; } else *expp = new_oper(sd->sd_type, *expp, '.', intexpr(sd->sd_offset, INT)); } } - else /* oper == ARROW */ + else { + /* oper == ARROW */ *expp = new_oper(sd->sd_type, *expp, oper, intexpr(sd->sd_offset, INT)); - (*expp)->ex_lvalue = sd->sd_type->tp_fund != ARRAY; + } + (*expp)->ex_lvalue = (sd->sd_type->tp_fund != ARRAY); } ch7incr(expp, oper) @@ -152,8 +157,7 @@ ch7incr(expp, oper) addend = (arith)1; #endif NOBITFIELD else { - if ((*expp)->ex_type != error_type) - expr_error(*expp, "%s on %s", + expr_error(*expp, "%s on %s", symbol2str(oper), symbol2str((*expp)->ex_type->tp_fund) ); @@ -280,18 +284,22 @@ ch7cast(expp, oper, tp) (*expp)->ex_type = tp; } else + if (oldtp->tp_fund == ERRONEOUS) { + /* we just won't look */ + (*expp)->ex_type = tp; /* brute force */ + } + else if (oldtp->tp_size == tp->tp_size && oper == CAST) { expr_warning(*expp, "dubious conversion based on equal size"); (*expp)->ex_type = tp; /* brute force */ } - else - { + else { if (oldtp->tp_fund != ERRONEOUS && tp->tp_fund != ERRONEOUS) expr_error(*expp, "cannot convert %s to %s", symbol2str(oldtp->tp_fund), symbol2str(tp->tp_fund) ); - (*expp)->ex_type = tp; + (*expp)->ex_type = tp; /* brute force */ } } diff --git a/lang/cem/cemcom/ch7bin.c b/lang/cem/cemcom/ch7bin.c index 12d92678..217eecb5 100644 --- a/lang/cem/cemcom/ch7bin.c +++ b/lang/cem/cemcom/ch7bin.c @@ -64,9 +64,8 @@ ch7bin(expp, oper, expr) ch7mon('*', expp); } if ((*expp)->ex_type->tp_fund != FUNCTION) { - if ((*expp)->ex_type != error_type) - expr_error(*expp, "call of non-function (%s)", - symbol2str((*expp)->ex_type->tp_fund)); + expr_error(*expp, "call of non-function (%s)", + symbol2str((*expp)->ex_type->tp_fund)); /* leave the expression; it may still serve */ free_expression(expr); /* there go the parameters */ } @@ -202,7 +201,6 @@ ch7bin(expp, oper, expr) ) { if ((*expp)->ex_type != expr->ex_type) { expr_error(*expp, "illegal balance"); - (*expp)->ex_type = error_type; } } else { diff --git a/lang/cem/cemcom/ch7mon.c b/lang/cem/cemcom/ch7mon.c index 5c144192..f18969f3 100644 --- a/lang/cem/cemcom/ch7mon.c +++ b/lang/cem/cemcom/ch7mon.c @@ -28,11 +28,9 @@ ch7mon(oper, expp) if ((*expp)->ex_type->tp_fund == ARRAY) array2pointer(expp); if ((*expp)->ex_type->tp_fund != POINTER) { - if ((*expp)->ex_type != error_type) - expr_error(*expp, - "* applied to non-pointer (%s)", - symbol2str((*expp)->ex_type->tp_fund)); - (*expp)->ex_type = error_type; + expr_error(*expp, + "* applied to non-pointer (%s)", + symbol2str((*expp)->ex_type->tp_fund)); } else { expr = *expp; @@ -59,13 +57,11 @@ ch7mon(oper, expp) #ifndef NOBITFIELD if ((*expp)->ex_type->tp_fund == FIELD) { expr_error(*expp, "& applied to field variable"); - (*expp)->ex_type = error_type; } else #endif NOBITFIELD if (!(*expp)->ex_lvalue) { expr_error(*expp, "& applied to non-lvalue"); - (*expp)->ex_type = error_type; } else { /* assume that enums are already filtered out */ @@ -79,7 +75,6 @@ ch7mon(oper, expp) if (def->df_sc == REGISTER) { expr_error(*expp, "& on register variable not allowed"); - (*expp)->ex_type = error_type; break; /* break case '&' */ } def->df_register = REG_NONE; diff --git a/lang/cem/cemcom/dumpidf.c b/lang/cem/cemcom/dumpidf.c index 867b7317..1c20e88b 100644 --- a/lang/cem/cemcom/dumpidf.c +++ b/lang/cem/cemcom/dumpidf.c @@ -318,11 +318,11 @@ p1_expr(lvl, expr) printf("NILEXPR\n"); return; } - printf("expr: L=%u, T=%s, %cV, F=%02o, D=%d, %s: ", + printf("expr: L=%u, T=%s, %cV, F=%03o, D=%d, %s: ", expr->ex_line, type2str(expr->ex_type), expr->ex_lvalue ? 'l' : 'r', - expr->ex_flags, + expr->ex_flags & 0xFF, expr->ex_depth, expr->ex_class == Value ? "Value" : expr->ex_class == String ? "String" : diff --git a/lang/cem/cemcom/error.c b/lang/cem/cemcom/error.c index 7b1629ec..0917808d 100644 --- a/lang/cem/cemcom/error.c +++ b/lang/cem/cemcom/error.c @@ -56,7 +56,10 @@ expr_error(expr, fmt, args) struct expr *expr; char *fmt; { + if (expr->ex_flags & EX_ERROR) + return; /* to prevent proliferation */ _error(ERROR, expr, fmt, &args); + expr->ex_flags |= EX_ERROR; } /*VARARGS1*/ @@ -71,6 +74,8 @@ expr_warning(expr, fmt, args) struct expr *expr; char *fmt; { + if (expr->ex_flags & EX_ERROR) + return; /* to prevent proliferation */ _error(WARNING, expr, fmt, &args); } diff --git a/lang/cem/cemcom/expr.c b/lang/cem/cemcom/expr.c index f343c6ad..ba07d30c 100644 --- a/lang/cem/cemcom/expr.c +++ b/lang/cem/cemcom/expr.c @@ -169,12 +169,13 @@ idf2expr(expr) } /* now def != 0 */ if (def->df_type->tp_fund == LABEL) { - error("illegal use of label %s", idf->id_text); - expr->ex_type = error_type; + expr_error(expr, "illegal use of label %s", idf->id_text); } else { def->df_used = 1; expr->ex_type = def->df_type; + if (expr->ex_type == error_type) + expr->ex_flags |= EX_ERROR; } expr->ex_lvalue = ( def->df_type->tp_fund == FUNCTION || @@ -381,7 +382,6 @@ chk_cst_expr(expp) if (err) { erroneous2int(expp); - (*expp)->ex_type = error_type; } } diff --git a/lang/cem/cemcom/expr.str b/lang/cem/cemcom/expr.str index 5809dcca..2531672d 100644 --- a/lang/cem/cemcom/expr.str +++ b/lang/cem/cemcom/expr.str @@ -68,11 +68,12 @@ struct expr { /* some bits for the ex_flag field, to keep track of various interesting properties of an expression. */ -#define EX_SIZEOF 001 /* contains sizeof operator */ -#define EX_CAST 002 /* contains cast */ -#define EX_LOGICAL 004 /* contains logical operator */ -#define EX_COMMA 010 /* contains expression comma */ -#define EX_PARENS 020 /* the top level is parenthesized */ +#define EX_SIZEOF 0001 /* contains sizeof operator */ +#define EX_CAST 0002 /* contains cast */ +#define EX_LOGICAL 0004 /* contains logical operator */ +#define EX_COMMA 0010 /* contains expression comma */ +#define EX_PARENS 0020 /* the top level is parenthesized */ +#define EX_ERROR 0200 /* the expression is wrong */ #define NILEXPR ((struct expr *)0) diff --git a/lang/cem/cemcom/ival.c b/lang/cem/cemcom/ival.c index cbc7fb09..8e921e96 100644 --- a/lang/cem/cemcom/ival.c +++ b/lang/cem/cemcom/ival.c @@ -668,8 +668,7 @@ con_int(expr) illegal_init_cst(expr) struct expr *expr; { - if (expr->ex_type->tp_fund != ERRONEOUS) - expr_error(expr, "illegal initialisation constant"); + expr_error(expr, "illegal initialisation constant"); } too_many_initialisers(expr) diff --git a/lang/cem/cemcom/program.g b/lang/cem/cemcom/program.g index 5817aa0f..36da56e5 100644 --- a/lang/cem/cemcom/program.g +++ b/lang/cem/cemcom/program.g @@ -71,7 +71,8 @@ control_if_expression { #ifndef NOPP if (expr->ex_flags & EX_SIZEOF) - error("sizeof not allowed in preprocessor"); + expr_error(expr, + "sizeof not allowed in preprocessor"); ifval = expr->VL_VALUE; free_expression(expr); #endif NOPP diff --git a/lang/cem/cemcom/switch.c b/lang/cem/cemcom/switch.c index 7965c700..28db313f 100644 --- a/lang/cem/cemcom/switch.c +++ b/lang/cem/cemcom/switch.c @@ -129,6 +129,11 @@ code_case(expr) return; } + if (expr->ex_flags & EX_ERROR) { + /* is probably 0 anyway */ + return; + } + expr->ex_type = sh->sh_type; cut_size(expr); From d2d9a3c817c032ee25a1444530839ec2b7be68ee Mon Sep 17 00:00:00 2001 From: ceriel Date: Sat, 29 Mar 1986 01:04:49 +0000 Subject: [PATCH 0158/1625] Newer version, safety commit --- lang/m2/comp/Makefile | 4 +- lang/m2/comp/declar.g | 163 ++++++++++++++++++++++++-------------- lang/m2/comp/def.H | 42 ++++++---- lang/m2/comp/def.c | 97 ++++++++++++++++++++++- lang/m2/comp/enter.c | 4 +- lang/m2/comp/expression.g | 9 +-- lang/m2/comp/main.c | 4 +- lang/m2/comp/program.g | 45 ++++++++--- lang/m2/comp/scope.h | 3 +- lang/m2/comp/type.H | 12 +++ lang/m2/comp/type.c | 58 +++++++++++++- 11 files changed, 339 insertions(+), 102 deletions(-) diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index d8a5804e..ef03535e 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -74,8 +74,8 @@ symbol2str.o: Lpars.h tokenname.o: Lpars.h idf.h tokenname.h idf.o: idf.h input.o: f_info.h input.h -type.o: Lpars.h def.h def_sizes.h idf.h type.h -def.o: Lpars.h debug.h def.h idf.h main.h scope.h +type.o: Lpars.h def.h def_sizes.h idf.h misc.h type.h +def.o: Lpars.h debug.h def.h idf.h main.h misc.h scope.h scope.o: LLlex.h debug.h def.h idf.h scope.h type.h misc.o: LLlex.h f_info.h idf.h misc.h enter.o: def.h idf.h misc.h scope.h type.h diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 3989bb68..f6c492e9 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -31,13 +31,17 @@ ProcedureHeading(struct def **pdf; int type;) struct paramlist *params = 0; } : PROCEDURE IDENT - { assert(type == D_PROCEDURE || type == D_PROCHEAD); + { assert(type & (D_PROCEDURE | D_PROCHEAD)); *pdf = define(dot.TOK_IDF, CurrentScope, type); if (type == D_PROCEDURE) { open_scope(OPENSCOPE, 0); } } FormalParameters(type, ¶ms, &tp)? + { + (*pdf)->df_type = tp = construct_type(PROCEDURE, tp); + tp->prc_params = params; + } ; block: @@ -63,54 +67,47 @@ FormalParameters(int doparams; struct paramlist **pr; struct type **tp;) } : '(' [ - FPSection(doparams, pr) + FPSection(doparams, pr) + { pr1 = *pr; } [ - { for (pr1 = *pr; pr1->next; pr1 = pr1->next) ; } + { for (; pr1->next; pr1 = pr1->next) ; } ';' FPSection(doparams, &(pr1->next)) ]* ]? ')' { *tp = 0; } - [ ':' qualident(D_TYPE | D_HTYPE, &df, "type") - { /* ???? *tp = df->df_type; */ } + [ ':' qualident(D_TYPE | D_HTYPE, &df, "type") + { *tp = df->df_type; } ]? ; +/* In the next nonterminal, "doparams" is a flag indicating whether + the identifiers representing the parameters must be added to the + symbol table. We must not do so when reading a Definition Module, + because in this case we only read the header. The Implementation + might contain different identifiers representing the same paramters. +*/ FPSection(int doparams; struct paramlist **ppr;) { struct id_list *FPList; - register struct id_list *pid; - register struct paramlist *pr = 0; - int VARflag = 0; + struct paramlist *ParamList(); + struct type *tp; + int VARp = 0; } : [ - VAR { VARflag = 1; } + VAR { VARp = 1; } ]? - IdentList(&FPList) ':' FormalType - { - if (doparams) { - EnterIdList(FPList, - D_VARIABLE, - VARflag, - (struct type *) 0 /* ???? */, - CurrentScope - ); - } - *ppr = pr = new_paramlist(); - pr->par_type = 0; /* ??? */ - pr->par_var = VARflag; - for (pid = FPList->next; pid; pid = pid->next) { - pr->next = new_paramlist(); - pr = pr->next; - pr->par_type = 0; /* ??? */ - pr->par_var = VARflag; - } - pr->next = 0; - FreeIdList(FPList); - } + IdentList(&FPList) ':' FormalType(&tp) + { + if (doparams) { + EnterIdList(FPList, D_VARIABLE, VARp, tp, CurrentScope); + } + *ppr = ParamList(FPList, tp); + FreeIdList(FPList); + } ; -FormalType +FormalType(struct type **tp;) { struct def *df; int ARRAYflag = 0; @@ -118,6 +115,12 @@ FormalType [ ARRAY OF { ARRAYflag = 1; } ]? qualident(D_TYPE | D_HTYPE, &df, "type") + { if (ARRAYflag) { + *tp = construct_type(ARRAY, NULLTYPE); + (*tp)->arr_elem = df->df_type; + } + else *tp = df->df_type; + } ; TypeDeclaration @@ -127,8 +130,7 @@ TypeDeclaration }: IDENT { df = define(dot.TOK_IDF, CurrentScope, D_TYPE); } '=' type(&tp) - { df->df_type = tp; - } + { df->df_type = tp; } ; type(struct type **ptp;): @@ -148,17 +150,19 @@ type(struct type **ptp;): SimpleType(struct type **ptp;) { struct def *df; + struct type *tp; } : qualident(D_TYPE | D_HTYPE, &df, "type") [ - + /* nothing */ | SubrangeType(ptp) - /* - * The subrange type is given a base type by the - * qualident (this is new modula-2). - */ - { /* ???? (*ptp)->next = df->df_type; */ } + /* The subrange type is given a base type by the + qualident (this is new modula-2). + */ + { + chk_basesubrange(*ptp, tp); + } ] | enumeration(ptp) @@ -228,11 +232,11 @@ ArrayType(struct type **ptp;) } [ ',' SimpleType(&tp) - { tp2 = tp2->tp_value.tp_arr.ar_elem = + { tp2 = tp2->arr_elem = construct_type(ARRAY, tp); } ]* OF type(&tp) - { tp2->tp_value.tp_arr.ar_elem = tp; } + { tp2->arr_elem = tp; } ; RecordType(struct type **ptp;) @@ -245,7 +249,7 @@ RecordType(struct type **ptp;) FieldListSequence(scopenr) { *ptp = standard_type(RECORD, record_align, (arith) 0 /* ???? */); - (*ptp)->tp_value.tp_record.rc_scopenr = scopenr; + (*ptp)->rec_scopenr = scopenr; } END ; @@ -310,48 +314,87 @@ SetType(struct type **ptp;) } ; +/* In a pointer type definition, the type pointed at does not + have to be declared yet, so be careful about identifying + type-identifiers +*/ PointerType(struct type **ptp;) { struct type *tp; - register struct def *df; + struct def *df; struct def *lookfor(); } : POINTER TO [ %if ( (df = lookup(dot.TOK_IDF, CurrentScope))) - IDENT + /* Either a Module or a Type, but in both cases defined + in this scope, so this is the correct identification + */ + qualident(D_TYPE|D_HTYPE, &df, "type") { - if (!(df->df_kind & (D_TYPE | D_HTYPE))) { - error("\"%s\" is not a type identifier", - df->df_idf->id_text); - } if (!df->df_type) { error("type \"%s\" not declared", df->df_idf->id_text); + tp = error_type; } - *ptp = df->df_type; + else tp = df->df_type; } | %if (df = lookfor(dot.TOK_IDF, 0), df->df_kind == D_MODULE) type(&tp) - { *ptp = construct_type(POINTER, tp); } | IDENT - { *ptp = construct_type(POINTER, NULLTYPE); - Forward(&dot, &((*ptp)->next)); - } + { tp = NULLTYPE; } ] + { + *ptp = construct_type(POINTER, tp); + if (!tp) Forward(&dot, &((*ptp)->next)); + } ; -ProcedureType(struct type **ptp;): - PROCEDURE FormalTypeList? - { *ptp = 0; } +ProcedureType(struct type **ptp;) +{ + struct paramlist *pr = 0; + struct type *tp = 0; +} : + PROCEDURE FormalTypeList(&pr, &tp)? + { *ptp = construct_type(PROCEDURE, tp); + (*ptp)->prc_params = pr; + } ; -FormalTypeList +FormalTypeList(struct paramlist **ppr; struct type **ptp;) { struct def *df; + struct type *tp; + struct paramlist *p; + int VARp; } : - '(' [ VAR? FormalType [ ',' VAR? FormalType ]* ]? ')' - [ ':' qualident(1, &df, "type") + '(' { *ppr = 0; } + [ + [ VAR { VARp = 1; } + | { VARp = 0; } + ] + FormalType(&tp) + { *ppr = p = new_paramlist(); + p->par_type = tp; + p->par_var = VARp; + } + [ + ',' + [ VAR {VARp = 1; } + | {VARp = 0; } + ] + FormalType(&tp) + { p->next = new_paramlist(); + p = p->next; + p->par_type = tp; + p->par_var = VARp; + } + ]* + { p->next = 0; } + ]? + ')' + [ ':' qualident(D_TYPE|D_HTYPE, &df, "type") + { *ptp = df->df_type; } ]? ; diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H index 24abd798..49d5bc05 100644 --- a/lang/m2/comp/def.H +++ b/lang/m2/comp/def.H @@ -5,48 +5,58 @@ struct module { int mo_priority; /* Priority of a module */ int mo_scope; /* Scope of this module */ +#define mod_priority df_value.df_module.mo_priority +#define mod_scope df_value.df_module.mo_scope }; struct variable { - char va_fixedaddress; /* Flag, set if an address was given */ arith va_off; /* Address or offset of variable */ +#define var_off df_value.df_variable.va_off }; struct constant { - struct expr *co_const; /* A constant expression */ + arith co_const; /* result of a constant expression */ +#define con_const df_value.df_variable.con_const }; struct enumval { unsigned int en_val; /* Value of this enumeration literal */ struct def *en_next; /* Next enumeration literal */ +#define enm_val df_value.df_enum.en_val +#define enm_next df_value.df_enum.en_next }; struct field { - arith fld_off; + arith fd_off; struct variant { - struct caselabellist *fld_cases; - label fld_casedescr; - struct def *fld_varianttag; - } *fld_variant; + struct caselabellist *v_cases; + label v_casedescr; + struct def *v_varianttag; + } *fd_variant; +#define fld_off df_value.df_field.fd_off +#define fld_variant df_value.df_field.fd_variant }; struct import { int im_scopenr; /* Scope number from which imported */ +#define imp_scopenr df_value.df_import.im_scopenr }; struct def { /* list of definitions for a name */ - struct def *next; + struct def *next; /* next definition in definitions chain */ + struct def *df_nextinscope; + /* link all definitions in a scope */ struct idf *df_idf; /* link back to the name */ int df_scope; /* Scope in which this definition resides */ short df_kind; /* The kind of this definition: */ -#define D_MODULE 0x0001 -#define D_PROCEDURE 0x0002 -#define D_VARIABLE 0x0004 -#define D_FIELD 0x0008 -#define D_TYPE 0x0010 -#define D_ENUM 0x0020 -#define D_CONST 0x0040 -#define D_IMPORT 0x0080 +#define D_MODULE 0x0001 /* A module */ +#define D_PROCEDURE 0x0002 /* Procedure of function */ +#define D_VARIABLE 0x0004 /* A variable */ +#define D_FIELD 0x0008 /* A field in a record */ +#define D_TYPE 0x0010 /* A type */ +#define D_ENUM 0x0020 /* An enumeration literal */ +#define D_CONST 0x0040 /* A constant */ +#define D_IMPORT 0x0080 /* An imported definition */ #define D_PROCHEAD 0x0100 /* A procedure heading in a definition module */ #define D_HIDDEN 0x0200 /* A hidden type */ #define D_HTYPE 0x0400 /* Definition of a hidden type seen */ diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index 5a815e9a..2d4bfc24 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -5,9 +5,11 @@ static char *RcsId = "$Header$"; #include #include #include +#include #include "Lpars.h" #include "def.h" #include "idf.h" +#include "misc.h" #include "main.h" #include "scope.h" #include "debug.h" @@ -15,7 +17,7 @@ static char *RcsId = "$Header$"; struct def *h_def; /* Pointer to free list of def structures */ static struct def illegal_def = - {0, 0, -20 /* Illegal scope */, D_ERROR}; + {0, 0, 0, -20 /* Illegal scope */, D_ERROR}; struct def *ill_df = &illegal_def; @@ -27,6 +29,7 @@ define(id, scope, kind) already has been defined. If so, error message. */ register struct def *df; + register struct scope *sc; DO_DEBUG(debug(4,"Defining identifier %s in scope %d", id->id_text, scope)); df = lookup(id, scope); @@ -66,6 +69,15 @@ define(id, scope, kind) df->df_kind = kind; df->next = id->id_def; id->id_def = df; + + /* enter the definition in the list of definitions in this scope */ + sc = currscope; + while (sc->sc_scope != scope) { + sc = sc->next; + assert(sc != 0); + } + df->df_nextinscope = sc->sc_def; + sc->sc_def = df; return df; } @@ -85,6 +97,14 @@ lookup(id, scope) DO_DEBUG(debug(4,"Looking for identifier %s in scope %d", id->id_text, scope)); while (df) { if (df->df_scope == scope) { + if (df->df_kind == D_IMPORT) { + df = lookup(id, df->imp_scopenr); + assert(df != 0); + return df; + /* ??? But this does damage to the self- + organizing character of the list + */ + } if (df1) { df1->next = df->next; df->next = id->id_def; @@ -97,3 +117,78 @@ lookup(id, scope) } return 0; } + +/* From the current scope, the list of identifiers "ids" is + exported. Note this fact. If the export is not qualified, make + all the "ids" visible in the enclosing scope by defining them + in this scope as "imported". +*/ +Export(ids, qualified) + register struct id_list *ids; +{ + register struct def *df; + + while (ids) { + df = define(ids->id_ptr, CurrentScope, D_ISEXPORTED); + if (qualified) { + df->df_flags |= D_QEXPORTED; + } + else { + df->df_flags |= D_EXPORTED; + df = define(ids->id_ptr, enclosing(currscope)->sc_scope, + D_IMPORT); + } + ids = ids->next; + } +} + +/* "ids" is a list of imported identifiers. + If "id" is a null-pointer, the identifiers are imported from the + enclosing scope. Otherwise they are imported from the module + indicated by "id", ehich must be visible in the enclosing scope. + An exception must be made for imports of the Compilation Unit. + This case is indicated by the value 0 of the flag "local". + In this case, if "id" is a null pointer, the "ids" identifiers + are all module identifiers. Their Definition Modules must be read. + Otherwise "id" is a module identifier whose Definition Module must + be read. "ids" then represents a list of identifiers defined in + this module. +*/ +Import(ids, id, local) + register struct id_list *ids; + struct idf *id; +{ + register struct def *df; + int scope; + int kind; + struct def *lookfor(); + + if (local) { + kind = D_IMPORT; + if (!id) scope = enclosing(currscope)->sc_scope; + else { + df = lookfor(id, 1); + if (df->df_kind != D_MODULE) { + if (df->df_kind != D_ERROR) { +error("identifier \"%s\" does not represent a module", id->id_text); + } + /* enter all "ids" with type D_ERROR */ + kind = D_ERROR; + scope = enclosing(currscope)->sc_scope; + } + else scope = df->mod_scope; + } + while (ids) { + df = lookup(ids->id_ptr, scope); + if (!df) { + error("identifier \"%s\" not declared", + ids->id_ptr->id_text); + } + df = define(ids->id_ptr, CurrentScope, D_IMPORT); + df->imp_scopenr = scope; + ids = ids->next; + } + return; + } + /* ???? */ +} diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index d5c1322e..03b98330 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -55,8 +55,8 @@ EnterIdList(idlist, kind, flags, type, scope) if (last) { /* Also meaning : enumeration */ last->df_value.df_enum.en_next = 0; - type->tp_value.tp_enum.en_enums = first; - type->tp_value.tp_enum.en_ncst = assval; + type->enm_enums = first; + type->enm_ncst = assval; } } diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index 38c08a76..9d435798 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -25,11 +25,8 @@ qualident(int types; struct def **pdf; char *str;) struct def *lookfor(); } : IDENT { if (types) { - df = lookfor(dot.TOK_IDF, 1); - if (df->df_kind == D_ERROR) { - *pdf = df; - types = 0; - } + *pdf = df = lookfor(dot.TOK_IDF, 1); + if (df->df_kind == D_ERROR) types = 0; } } [ @@ -53,7 +50,7 @@ qualident(int types; struct def **pdf; char *str;) ]* { if (types && !(types & df->df_kind)) { error("identifier \"%s\" is not a %s", - dot.TOK_IDF, str); + df->df_idf->id_text, str); } } ; diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index 7ff75edf..2bd33a04 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -158,8 +158,8 @@ add_standards() construct_type(PROCEDURE, NULLTYPE), 0); tp = construct_type(SUBRANGE, int_type); - tp->tp_value.tp_subrange.su_lb = 0; - tp->tp_value.tp_subrange.su_ub = wrd_size * 8 - 1; + tp->sub_lb = 0; + tp->sub_ub = wrd_size * 8 - 1; df = Enter("BITSET", D_TYPE, construct_type(SET, tp), 0); df->df_type->tp_size = wrd_size; df = Enter("FALSE", D_ENUM, bool_type, 0); diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 77751d7a..691b08ce 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -32,8 +32,20 @@ static char *RcsId = "$Header$"; %start CompUnit, CompilationUnit; -ModuleDeclaration: - MODULE IDENT priority? ';' import(1)* export? block IDENT +ModuleDeclaration +{ + struct idf *id; +} : + MODULE IDENT { open_scope(CLOSEDSCOPE, 0); + id = dot.TOK_IDF; + } + priority? ';' + import(1)* + export? + block + IDENT { close_scope(); + match_id(id, dot.TOK_IDF); + } ; priority: @@ -51,6 +63,7 @@ export ]? IdentList(&ExportList) ';' { + Export(ExportList, QUALflag); FreeIdList(ExportList); } ; @@ -71,6 +84,7 @@ import(int local;) name, otherwise the names in the import list are module names. */ { + Import(ImportList, id, local); FreeIdList(ImportList); } ; @@ -78,12 +92,13 @@ import(int local;) DefinitionModule { struct def *df; + struct idf *id; } : DEFINITION { state = DEFINITION; } - MODULE IDENT { - df = define(dot.TOK_IDF, CurrentScope, D_MODULE); + MODULE IDENT { id = dot.TOK_IDF; + df = define(id, CurrentScope, D_MODULE); open_scope(CLOSEDSCOPE, 0); - df->df_value.df_module.mo_scope = CurrentScope; + df->mod_scope = CurrentScope; } ';' import(0)* @@ -92,7 +107,9 @@ DefinitionModule New Modula-2 does not have export lists in definition modules. */ definition* END IDENT '.' - { close_scope(); } + { close_scope(); + match_id(id, dot.TOK_IDF); + } ; definition @@ -120,7 +137,9 @@ definition ProcedureHeading(&df, D_PROCHEAD) ';' ; -ProgramModule: +ProgramModule { + struct idf *id; +} : MODULE { if (state != IMPLEMENTATION) state = PROGRAM; } IDENT { if (state == IMPLEMENTATION) { /* ???? @@ -128,12 +147,16 @@ ProgramModule: Look for current identifier, and find out its scope number */ - open_scope(CLOSEDSCOPE, 0); } - else open_scope(CLOSEDSCOPE, 0); + id = dot.TOK_IDF; + open_scope(CLOSEDSCOPE, 0); + } + priority? + ';' import(0)* + block IDENT + { close_scope(); + match_id(id, dot.TOK_IDF); } - priority? ';' import(0)* block IDENT - { close_scope(); } '.' ; diff --git a/lang/m2/comp/scope.h b/lang/m2/comp/scope.h index f924b6b8..35253bec 100644 --- a/lang/m2/comp/scope.h +++ b/lang/m2/comp/scope.h @@ -8,6 +8,7 @@ struct scope { struct scope *next; struct forwards *sc_forw; + struct def *sc_def; /* list of definitions in this scope */ int sc_scope; /* The scope number. Scope number 0 indicates both the pervasive scope and the end of a visibility range @@ -19,5 +20,5 @@ extern struct scope #define nextvisible(x) ((x)->sc_scope ? (x)->next : (struct scope *) 0) #define scopeclosed(x) ((x)->next->sc_scope == 0) -#define enclosing(x) ((x)->next->scope != 0 ? (struct scope *) 0 : (x)->next->next) +#define enclosing(x) (scopeclosed(x) ? (x)->next->next : (x)->next) #define CurrentScope (currscope->sc_scope) diff --git a/lang/m2/comp/type.H b/lang/m2/comp/type.H index 942fcbf9..0f2a2ee4 100644 --- a/lang/m2/comp/type.H +++ b/lang/m2/comp/type.H @@ -14,26 +14,38 @@ struct enume { struct def *en_enums; /* Definitions of enumeration literals */ unsigned int en_ncst; /* Number of constants */ label en_rck; /* Label of range check descriptor */ +#define enm_enums tp_value.tp_enum.en_enums +#define enm_ncst tp_value.tp_enum.en_ncst +#define enm_rck tp_value.tp_enum.enm_rck }; struct subrange { arith su_lb, su_ub; /* Lower bound and upper bound */ label su_rck; /* Label of range check descriptor */ +#define sub_lb tp_value.tp_subrange.su_lb +#define sub_ub tp_value.tp_subrange.su_ub +#define sub_rck tp_value.tp_subrange.su_rck }; struct array { struct type *ar_elem; /* Type of elements */ arith ar_lb, ar_ub; /* Lower bound and upper bound */ label ar_descr; /* Label of array descriptor */ +#define arr_elem tp_value.tp_arr.ar_elem +#define arr_lb tp_value.tp_arr.ar_lb +#define arr_ub tp_value.tp_arr.ar_ub +#define arr_descr tp_value.tp_arr.ar_descr }; struct record { int rc_scopenr; /* Scope number of this record */ /* Members are in the symbol table */ +#define rec_scopenr tp_value.tp_record.rc_scopenr }; struct proc { struct paramlist *pr_params; +#define prc_params tp_value.tp_proc.pr_params }; struct type { diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index a8eb5566..ae9aa6fb 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -11,6 +11,7 @@ static char *RcsId = "$Header$"; #include "def.h" #include "type.h" #include "idf.h" +#include "misc.h" /* To be created dynamically in main() from defaults or from command line parameters. @@ -143,7 +144,7 @@ has_selectors(df) register struct type *tp = df->df_type; if (tp->tp_fund == RECORD) { - return tp->tp_value.tp_record.rc_scopenr; + return tp->rec_scopenr; } break; } @@ -151,3 +152,58 @@ has_selectors(df) error("no selectors for \"%s\"", df->df_idf->id_text); return 0; } + +/* Create a parameterlist of a procedure and return a pointer to it. + "ids" indicates the list of identifiers, "tp" their type, and + "VARp" is set when the parameters are VAR-parameters. + Actually, "ids" is only used because it tells us how many parameters + there were with this type. +*/ +struct paramlist * +ParamList(ids, tp, VARp) + register struct id_list *ids; + struct type *tp; +{ + register struct paramlist *pr; + struct paramlist *pstart; + + pstart = pr = new_paramlist(); + pr->par_type = tp; + pr->par_var = VARp; + for (ids = ids->next; ids; ids = ids->next) { + pr->next = new_paramlist(); + pr = pr->next; + pr->par_type = tp; + pr->par_var = VARp; + } + pr->next = 0; + return pstart; +} + +/* A subrange had a specified base. Check that the bases conform ... +*/ +chk_basesubrange(tp, base) + register struct type *tp, *base; +{ + if (base->tp_fund == SUBRANGE) { + /* Check that the bounds of "tp" fall within the range + of "base" + */ + if (base->sub_lb > tp->sub_lb || base->sub_ub < tp->sub_ub) { + error("Base type has insufficient range"); + } + base = base->next; + } + if (base->tp_fund == ENUMERATION || base->tp_fund == CHAR) { + if (tp->next != base) { + error("Specified base does not conform"); + } + } + else if (base != card_type && base != int_type) { + error("Illegal base for a subrange"); + } + else if (base != tp->next && base != int_type) { + error("Specified base does not conform"); + } + tp->next = base; +} From 53af3f399a03e8fce486871afb946813b3a9ce39 Mon Sep 17 00:00:00 2001 From: erikb Date: Wed, 2 Apr 1986 08:37:17 +0000 Subject: [PATCH 0159/1625] revised the administration of Value expressions --- lang/cem/cemcom/Makefile.erik | 4 +- lang/cem/cemcom/arith.c | 30 ++++- lang/cem/cemcom/ch7.c | 3 + lang/cem/cemcom/ch7mon.c | 27 ++-- lang/cem/cemcom/code.c | 38 +++++- lang/cem/cemcom/code.str | 9 ++ lang/cem/cemcom/cstoper.c | 5 +- lang/cem/cemcom/dumpidf.c | 20 ++- lang/cem/cemcom/eval.c | 242 +++++++++++++++++----------------- lang/cem/cemcom/expr.c | 15 ++- lang/cem/cemcom/expr.str | 17 ++- lang/cem/cemcom/field.c | 44 ++----- lang/cem/cemcom/ival.c | 154 ++++++++-------------- lang/cem/cemcom/switch.c | 4 +- 14 files changed, 317 insertions(+), 295 deletions(-) diff --git a/lang/cem/cemcom/Makefile.erik b/lang/cem/cemcom/Makefile.erik index 8acb5b6e..dff19db6 100644 --- a/lang/cem/cemcom/Makefile.erik +++ b/lang/cem/cemcom/Makefile.erik @@ -190,10 +190,10 @@ idf.o: LLlex.h Lpars.h align.h alloc.h arith.h assert.h botch_free.h debug.h dec declarator.o: Lpars.h alloc.h arith.h botch_free.h declar.h expr.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h type.h decspecs.o: Lpars.h arith.h decspecs.h def.h level.h nobitfield.h spec_arith.h type.h struct.o: LLlex.h Lpars.h align.h arith.h assert.h botch_free.h debug.h def.h field.h idf.h level.h nobitfield.h nopp.h sizes.h spec_arith.h stack.h storage.h struct.h type.h -expr.o: LLlex.h Lpars.h alloc.h arith.h botch_free.h declar.h decspecs.h def.h expr.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h type.h +expr.o: LLlex.h Lpars.h alloc.h arith.h botch_free.h declar.h decspecs.h def.h expr.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h type.h level.h ch7.o: Lpars.h arith.h assert.h debug.h def.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h struct.h type.h ch7bin.o: Lpars.h arith.h botch_free.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h storage.h struct.h type.h -cstoper.o: Lpars.h arith.h expr.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h target_sizes.h type.h +cstoper.o: Lpars.h arith.h expr.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h target_sizes.h type.h assert.h arith.o: Lpars.h alloc.h arith.h botch_free.h expr.h field.h idf.h label.h mes.h nobitfield.h nopp.h spec_arith.h storage.h type.h alloc.o: alloc.h assert.h debug.h myalloc.h code.o: LLlex.h Lpars.h alloc.h arith.h assert.h atw.h botch_free.h code.h dataflow.h debug.h declar.h decspecs.h def.h expr.h idf.h label.h level.h mes.h nobitfield.h nopp.h sizes.h spec_arith.h specials.h stack.h storage.h type.h use_tmp.h diff --git a/lang/cem/cemcom/arith.c b/lang/cem/cemcom/arith.c index 629fbac0..61bdb6ef 100644 --- a/lang/cem/cemcom/arith.c +++ b/lang/cem/cemcom/arith.c @@ -257,18 +257,16 @@ float2float(expp, tp) */ fp_used = 1; - if (is_fp_cst(*expp)) { + if (is_fp_cst(*expp)) (*expp)->ex_type = tp; - } - else { + else *expp = arith2arith(tp, FLOAT2FLOAT, *expp); - } } array2pointer(expp) struct expr **expp; { - /* The expression, which must be an array, it is converted + /* The expression, which must be an array, is converted to a pointer. */ (*expp)->ex_type = @@ -278,13 +276,29 @@ array2pointer(expp) function2pointer(expp) struct expr **expp; { - /* The expression, which must be a function, it is converted + /* The expression, which must be a function, is converted to a pointer to the function. */ (*expp)->ex_type = construct_type(POINTER, (*expp)->ex_type, (arith)0); } +string2pointer(expp) + struct expr **expp; +{ + /* The expression, which must be a string constant, is converted + to a pointer to the string-containing area. + */ + struct expr *ex = *expp; + label lbl = data_label(); + + code_string(ex->SG_VALUE, ex->SG_LEN, lbl); + ex->ex_class = Value; + ex->VL_CLASS = Label; + ex->VL_LBL = lbl; + ex->VL_VALUE = (arith)0; +} + opnd2integral(expp, oper) struct expr **expp; int oper; @@ -421,6 +435,10 @@ any2opnd(expp, oper) case ARRAY: array2pointer(expp); break; + case POINTER: + if ((*expp)->ex_class == String) + string2pointer(expp); + break; #ifndef NOBITFIELD case FIELD: field2arith(expp); diff --git a/lang/cem/cemcom/ch7.c b/lang/cem/cemcom/ch7.c index 0f39bcfd..ab173731 100644 --- a/lang/cem/cemcom/ch7.c +++ b/lang/cem/cemcom/ch7.c @@ -109,6 +109,7 @@ ch7sel(expp, oper, idf) struct oper *op = &((*expp)->ex_object.ex_oper); if (op->op_oper == '.' || op->op_oper == ARROW) { + ASSERT(is_cp_cst(op->op_right)); op->op_right->VL_VALUE += sd->sd_offset; (*expp)->ex_type = sd->sd_type; if ((*expp)->ex_type == error_type) @@ -188,6 +189,8 @@ ch7cast(expp, oper, tp) function2pointer(expp); if ((*expp)->ex_type->tp_fund == ARRAY) array2pointer(expp); + if ((*expp)->ex_class == String) + string2pointer(expp); oldtp = (*expp)->ex_type; if (oldtp == tp) {} /* life is easy */ diff --git a/lang/cem/cemcom/ch7mon.c b/lang/cem/cemcom/ch7mon.c index f18969f3..b99925a1 100644 --- a/lang/cem/cemcom/ch7mon.c +++ b/lang/cem/cemcom/ch7mon.c @@ -46,13 +46,11 @@ ch7mon(oper, expp) } break; case '&': - if ((*expp)->ex_type->tp_fund == ARRAY) { + if ((*expp)->ex_type->tp_fund == ARRAY) array2pointer(expp); - } else - if ((*expp)->ex_type->tp_fund == FUNCTION) { + if ((*expp)->ex_type->tp_fund == FUNCTION) function2pointer(expp); - } else #ifndef NOBITFIELD if ((*expp)->ex_type->tp_fund == FIELD) { @@ -65,12 +63,15 @@ ch7mon(oper, expp) } else { /* assume that enums are already filtered out */ - if ((*expp)->ex_class == Value && (*expp)->VL_IDF) { + if ( (*expp)->ex_class == Value + && (*expp)->VL_CLASS == Name + ) { register struct def *def = (*expp)->VL_IDF->id_def; - /* & indicates that cannot - be used as register anymore + /* & indicates that + cannot be used as register + anymore */ if (def->df_sc == REGISTER) { expr_error(*expp, @@ -98,11 +99,7 @@ ch7mon(oper, expp) any2arith(expp, oper); if (is_cp_cst(*expp)) { arith o1 = (*expp)->VL_VALUE; - if (oper == '-') - o1 = -o1; - else - o1 = ~o1; - (*expp)->VL_VALUE = o1; + (*expp)->VL_VALUE = (oper == '-') ? -o1 : ~o1; } else if (is_fp_cst(*expp)) @@ -118,9 +115,7 @@ ch7mon(oper, expp) any2arith(expp, oper); opnd2test(expp, '!'); if (is_cp_cst(*expp)) { - arith o1 = (*expp)->VL_VALUE; - o1 = !o1; - (*expp)->VL_VALUE = o1; + (*expp)->VL_VALUE = !((*expp)->VL_VALUE); (*expp)->ex_type = int_type; } else @@ -133,7 +128,7 @@ ch7mon(oper, expp) break; case SIZEOF: if ( (*expp)->ex_class == Value - && (*expp)->VL_IDF + && (*expp)->VL_CLASS == Name && (*expp)->VL_IDF->id_def->df_formal_array ) warning("sizeof formal array %s is sizeof pointer!", diff --git a/lang/cem/cemcom/code.c b/lang/cem/cemcom/code.c index 689daaa9..098924f7 100644 --- a/lang/cem/cemcom/code.c +++ b/lang/cem/cemcom/code.c @@ -59,11 +59,41 @@ famous_first_words() C_ms_emx(word_size, pointer_size); } +static struct string_cst *str_list = 0; + +code_string(val, len, dlb) + char *val; + int len; + label dlb; +{ + struct string_cst *sc = new_string_cst(); + + C_ina_dlb(dlb); + sc->next = str_list; + str_list = sc; + sc->sc_value = val; + sc->sc_len = len; + sc->sc_dlb = dlb; +} + +def_strings(sc) + register struct string_cst *sc; +{ + if (sc) { + def_strings(sc->next); + C_df_dlb(sc->sc_dlb); + C_con_scon(sc->sc_value, sc->sc_len); + free_string_cst(sc); + } +} + end_code() { /* end_code() performs the actions to be taken when closing the output stream. */ + def_strings(str_list); + str_list = 0; C_ms_src((arith)(LineNumber - 2), FileName); C_close(); } @@ -351,6 +381,7 @@ loc_init(expr, id) */ register struct type *tp = id->id_def->df_type; + ASSERT(id->id_def->df_sc != STATIC); /* automatic aggregates cannot be initialised. */ switch (tp->tp_fund) { case ARRAY: @@ -374,9 +405,14 @@ loc_init(expr, id) } } else { /* not embraced */ + struct value vl; + ch7cast(&expr, '=', tp); EVAL(expr, RVAL, TRUE, NO_LABEL, NO_LABEL); - store_val(id, tp, (arith) 0); + vl.vl_class = Name; + vl.vl_data.vl_idf = id; + vl.vl_value = (arith)0; + store_val(&vl, tp); } } diff --git a/lang/cem/cemcom/code.str b/lang/cem/cemcom/code.str index 11a00cb6..2f2399ce 100644 --- a/lang/cem/cemcom/code.str +++ b/lang/cem/cemcom/code.str @@ -9,6 +9,15 @@ struct stat_block { /* ALLOCDEF "stat_block" */ +struct string_cst { /* storing string constants */ + struct string_cst *next; + char *sc_value; + int sc_len; + label sc_dlb; +}; + +/* ALLOCDEF "string_cst" */ + #define LVAL 0 #define RVAL 1 #define FALSE 0 diff --git a/lang/cem/cemcom/cstoper.c b/lang/cem/cemcom/cstoper.c index 9b4e09eb..1d31a1b2 100644 --- a/lang/cem/cemcom/cstoper.c +++ b/lang/cem/cemcom/cstoper.c @@ -10,6 +10,7 @@ #include "expr.h" #include "sizes.h" #include "Lpars.h" +#include "assert.h" long mach_long_sign; /* sign bit of the machine long */ int mach_long_size; /* size of long on this machine == sizeof(long) */ @@ -21,13 +22,14 @@ cstbin(expp, oper, expr) struct expr **expp, *expr; { /* The operation oper is performed on the constant - expressions *expp and expr, and the result restored in + expressions *expp(ld) and expr(ct), and the result restored in *expp. */ arith o1 = (*expp)->VL_VALUE; arith o2 = expr->VL_VALUE; int uns = (*expp)->ex_type->tp_unsigned; + ASSERT(is_ld_cst(*expp) && is_cp_cst(expr)); switch (oper) { case '*': o1 *= o2; @@ -190,6 +192,7 @@ cut_size(expr) int uns = expr->ex_type->tp_unsigned; int size = (int) expr->ex_type->tp_size; + ASSERT(expr->ex_class == Value); if (uns) { if (o1 & ~full_mask[size]) expr_warning(expr, diff --git a/lang/cem/cemcom/dumpidf.c b/lang/cem/cemcom/dumpidf.c index 1c20e88b..cd7e4694 100644 --- a/lang/cem/cemcom/dumpidf.c +++ b/lang/cem/cemcom/dumpidf.c @@ -331,14 +331,24 @@ p1_expr(lvl, expr) expr->ex_class == Type ? "Type" : "UNKNOWN CLASS" ); switch (expr->ex_class) { - struct value *v; struct oper *o; case Value: - v = &expr->ex_object.ex_value; - if (v->vl_idf) - printf("%s + ", v->vl_idf->id_text); + switch (expr->VL_CLASS) { + case Const: + printf("(Const) "); + break; + case Name: + printf("(Name) %s + ", expr->VL_IDF->id_text); + break; + case Label: + printf("(Label) .%lu + ", expr->VL_LBL); + break; + default: + printf("(Unknown) "); + break; + } printf(expr->ex_type->tp_unsigned ? "%lu\n" : "%ld\n", - v->vl_value); + expr->VL_VALUE); break; case String: { diff --git a/lang/cem/cemcom/eval.c b/lang/cem/cemcom/eval.c index 636e4287..b0f5f40c 100644 --- a/lang/cem/cemcom/eval.c +++ b/lang/cem/cemcom/eval.c @@ -80,22 +80,17 @@ EVAL(expr, val, code, true_label, false_label) register gencode = (code == TRUE); switch (expr->ex_class) { - case Value: /* just a simple value */ if (gencode) load_val(expr, val); break; - case String: /* a string constant */ + expr_warning(expr, "(DEBUG) value-class 'String' seen"); if (gencode) { - label datlab = data_label(); - - C_df_dlb(datlab); - C_con_scon(expr->SG_VALUE, (arith)expr->SG_LEN); - C_lae_dlb(datlab, (arith)0); + string2pointer(&expr); + C_lae_dlb(expr->VL_LBL, expr->VL_VALUE); } break; - case Float: /* a floating constant */ if (gencode) { label datlab = data_label(); @@ -106,7 +101,6 @@ EVAL(expr, val, code, true_label, false_label) C_loi(expr->ex_type->tp_size); } break; - case Oper: /* compound expression */ { register int oper = expr->OP_OPER; @@ -116,7 +110,6 @@ EVAL(expr, val, code, true_label, false_label) if (tp->tp_fund == ERRONEOUS) /* stop immediately */ break; - switch (oper) { case '+': /* We have the following possibilities : @@ -366,8 +359,10 @@ EVAL(expr, val, code, true_label, false_label) store_block(tp->tp_size, tp->tp_align); } else - store_val(leftop->VL_IDF, leftop->ex_type, - leftop->VL_VALUE); + store_val( + &(leftop->ex_object.ex_value), + leftop->ex_type + ); break; case PLUSAB: case MINAB: @@ -410,8 +405,10 @@ EVAL(expr, val, code, true_label, false_label) assop(tp, oper); if (gencode) C_dup(roundup(tp->tp_size)); - store_val(leftop->VL_IDF, leftop->ex_type, - leftop->VL_VALUE); + store_val( + &(leftop->ex_object.ex_value), + leftop->ex_type + ); } break; case '(': @@ -433,7 +430,9 @@ EVAL(expr, val, code, true_label, false_label) EVAL(expr, RVAL, TRUE, NO_LABEL, NO_LABEL); ParSize += ATW(expr->ex_type->tp_size); } - if (leftop->ex_class == Value && leftop->VL_IDF != 0) { + if ( leftop->ex_class == Value + && leftop->VL_CLASS == Name + ) { /* just an example: main() { (*((int (*)())0))(); } */ @@ -466,11 +465,13 @@ EVAL(expr, val, code, true_label, false_label) } case '.': EVAL(leftop, LVAL, code, NO_LABEL, NO_LABEL); + ASSERT(is_cp_cst(rightop)); if (gencode) C_adp(rightop->VL_VALUE); break; case ARROW: EVAL(leftop, RVAL, code, NO_LABEL, NO_LABEL); + ASSERT(is_cp_cst(rightop)); if (gencode) C_adp(rightop->VL_VALUE); break; @@ -532,8 +533,10 @@ EVAL(expr, val, code, true_label, false_label) free_tmp_var(old_offset); } else - store_val(leftop->VL_IDF, leftop->ex_type, - leftop->VL_VALUE); + store_val( + &(leftop->ex_object.ex_value), + leftop->ex_type + ); break; } case '?': /* must be followed by ':' */ @@ -841,62 +844,70 @@ free_tmp_var(oldoffset) - into an automatic local variable - into a local static variable - absolute addressing - When the destination is described by an (lvalue) expression, the call - is "store_val(ex->VL_IDF, ex->ex_type, ex->VL_VALUE)" */ -store_val(id, tp, offs) - register struct idf *id; +store_val(vl, tp) + register struct value *vl; struct type *tp; - arith offs; { arith size = tp->tp_size; int tpalign = tp->tp_align; + int al_on_word; + register int inword; + register int indword; + arith val = vl->vl_value; - if (id) { + if (vl->vl_class == Const) { /* absolute addressing */ + load_cst(val, pointer_size); + store_block(size, tpalign); + return; + } + + al_on_word = (tpalign % word_align == 0); + if (!(inword = (size == word_size && al_on_word))) + indword = (size == dword_size && al_on_word); + + if (vl->vl_class == Name) { + register struct idf *id = vl->vl_data.vl_idf; register struct def *df = id->id_def; - int al_on_word = (tpalign % word_align == 0); - register inword = (size == word_size && al_on_word); - register indword = (size == dword_size && al_on_word); if (df->df_level == L_GLOBAL) { if (inword) - C_ste_dnam(id->id_text, offs); + C_ste_dnam(id->id_text, val); else if (indword) - C_sde_dnam(id->id_text, offs); + C_sde_dnam(id->id_text, val); else { - C_lae_dnam(id->id_text, offs); - store_block(size, tpalign); - } - } - else - if (df->df_sc == STATIC) { - if (inword) - C_ste_dlb((label)df->df_address, offs); - else - if (indword) - C_sde_dlb((label)df->df_address, offs); - else { - C_lae_dlb((label)df->df_address, offs); + C_lae_dnam(id->id_text, val); store_block(size, tpalign); } } else { + ASSERT(df->df_sc != STATIC); if (inword) - C_stl(df->df_address + offs); + C_stl(df->df_address + val); else if (indword) - C_sdl(df->df_address + offs); + C_sdl(df->df_address + val); else { - C_lal(df->df_address + offs); + C_lal(df->df_address + val); store_block(size, tpalign); df->df_register = REG_NONE; } } } - else { /* absolute addressing */ - load_cst(offs, pointer_size); - store_block(size, tpalign); + else { + label dlb = vl->vl_data.vl_lbl; + + ASSERT(vl->vl_class == Label); + if (inword) + C_ste_dlb(dlb, val); + else + if (indword) + C_sde_dlb(dlb, val); + else { + C_lae_dlb(dlb, val); + store_block(size, tpalign); + } } } @@ -914,101 +925,96 @@ load_val(expr, val) struct expr *expr; /* expression containing the value */ int val; /* generate either LVAL or RVAL */ { - register struct idf *id; register struct type *tp = expr->ex_type; - register struct def *df; - register rvalue = (val == RVAL && expr->ex_lvalue != 0); - register arith exval = expr->VL_VALUE; + register int rvalue = (val == RVAL && expr->ex_lvalue != 0); register arith size = tp->tp_size; - register tpalign = tp->tp_align; - register al_on_word = (tpalign % word_align == 0); + register int tpalign = tp->tp_align; + register int al_on_word; + register int inword, indword; + register arith val = expr->VL_VALUE; - if ((id = expr->VL_IDF) == 0) { - /* Note: enum constants are also dealt with here */ - if (rvalue) { - /* absolute addressing - */ - load_cst(exval, pointer_size); + if (expr->VL_CLASS == Const) { + if (rvalue) { /* absolute addressing */ + load_cst(val, pointer_size); load_block(size, tpalign); } else /* integer, unsigned, long, enum etc */ - load_cst(exval, size); + load_cst(val, size); + return; } - else - if ((df = id->id_def)->df_type->tp_fund == FUNCTION) - /* the previous statement tried to catch a function - identifier, which may be cast to a pointer to a - function. - ASSERT(!(rvalue)); ??? - */ - C_lpi(id->id_text); - else - if (df->df_level == L_GLOBAL) { + if (rvalue) { + al_on_word = (tpalign % word_align == 0); + if (!(inword = (size == word_size && al_on_word))) + indword = (size == dword_size && al_on_word); + } + if (expr->VL_CLASS == Label) { if (rvalue) { - if (size == word_size && al_on_word) - C_loe_dnam(id->id_text, exval); + if (inword) + C_loe_dlb(expr->VL_LBL, val); else - if (size == dword_size && al_on_word) - C_lde_dnam(id->id_text, exval); + if (indword) + C_lde_dlb(expr->VL_LBL, val); else { - C_lae_dnam(id->id_text, exval); + C_lae_dlb(expr->VL_LBL, val); load_block(size, tpalign); } } else { - C_lae_dnam(id->id_text, (arith)0); - C_adp(exval); + C_lae_dlb(expr->VL_LBL, (arith)0); + C_adp(val); } } - else - if (df->df_sc == STATIC) { - if (rvalue) { - if (size == word_size && al_on_word) - C_loe_dlb((label)df->df_address, exval); - else - if (size == dword_size && al_on_word) - C_lde_dlb((label)df->df_address, exval); - else { - C_lae_dlb((label)df->df_address, exval); - load_block(size, tpalign); - } + else { + register struct idf *id = expr->VL_IDF; + register struct def *df; + ASSERT(expr->VL_CLASS == Name); + if ((df = id->id_def)->df_type->tp_fund == FUNCTION) + /* the previous statement tried to catch a function + identifier, which may be cast to a pointer to a + function. + ASSERT(!(rvalue)); ??? + */ + C_lpi(id->id_text); + else + if (df->df_level == L_GLOBAL) { + if (rvalue) { + if (inword) + C_loe_dnam(id->id_text, val); + else + if (indword) + C_lde_dnam(id->id_text, val); + else { + C_lae_dnam(id->id_text, val); + load_block(size, tpalign); + } + } + else { + C_lae_dnam(id->id_text, (arith)0); + C_adp(val); + } } else { - C_lae_dlb((label)df->df_address, (arith)0); - C_adp(exval); - } - } - else { - if (rvalue) { - if (size == word_size && al_on_word) - C_lol(df->df_address + exval); - else - if (size == dword_size && al_on_word) - C_ldl(df->df_address + exval); + ASSERT(df->df_sc != STATIC); + if (rvalue) { + if (inword) + C_lol(df->df_address + val); + else + if (indword) + C_ldl(df->df_address + val); + else { + C_lal(df->df_address + val); + load_block(size, tpalign); + df->df_register = REG_NONE; + } + } else { - C_lal(df->df_address + exval); - load_block(size, tpalign); + C_lal(df->df_address); + C_adp(val); df->df_register = REG_NONE; } } - else { - /* following code may be used when - comparing addresses as in the following - example: - f() { - int a[10], *i; - for (i = &a[0]; i < &a[10]; i++) ...; - } - We don't accept the contents of a[10] to - be legitimate, so the RVAL of it may - contain a big mess. - */ - C_lal(df->df_address); - C_adp(exval); - df->df_register = REG_NONE; - } } } diff --git a/lang/cem/cemcom/expr.c b/lang/cem/cemcom/expr.c index ba07d30c..0a8629e9 100644 --- a/lang/cem/cemcom/expr.c +++ b/lang/cem/cemcom/expr.c @@ -15,6 +15,7 @@ #include "declar.h" #include "storage.h" #include "sizes.h" +#include "level.h" extern char *symbol2str(); extern char options[]; @@ -184,10 +185,17 @@ idf2expr(expr) ) ? 0 : 1; expr->ex_class = Value; if (def->df_sc == ENUM) { - expr->VL_IDF = 0; + expr->VL_CLASS = Const; expr->VL_VALUE = def->df_address; } - else { + else + if (def->df_sc == STATIC && def->df_level >= L_LOCAL) { + expr->VL_CLASS = Label; + expr->VL_LBL = def->df_address; + expr->VL_VALUE = (arith)0; + } + else { + expr->VL_CLASS = Name; expr->VL_IDF = idf; expr->VL_VALUE = (arith)0; } @@ -246,6 +254,7 @@ intexpr(ivalue, fund) crash("(intexpr) bad fund %s\n", symbol2str(fund)); } expr->ex_class = Value; + expr->VL_CLASS = Const; expr->VL_VALUE = ivalue; cut_size(expr); @@ -421,7 +430,7 @@ is_cp_cst(expr) /* An expression is a `compile-time constant' if it is a load-time constant, and the idf is not there. */ - return is_ld_cst(expr) && expr->VL_IDF == 0; + return is_ld_cst(expr) && expr->VL_CLASS == Const; } int diff --git a/lang/cem/cemcom/expr.str b/lang/cem/cemcom/expr.str index 2531672d..1d627586 100644 --- a/lang/cem/cemcom/expr.str +++ b/lang/cem/cemcom/expr.str @@ -5,9 +5,18 @@ a union of various goodies, we define them first; so be patient. */ +/* classes of value */ +#define Const 1 +#define Name 2 +#define Label 3 + struct value { - struct idf *vl_idf; /* idf of an external name or 0 */ - arith vl_value; /* constant, or offset if idf != 0 */ + int vl_class; /* Const, Name or Label */ + arith vl_value; /* constant value or offset */ + union { + struct idf *vl_idf; /* external name */ + label vl_lbl; /* compiler-generated label */ + } vl_data; }; struct string { @@ -53,8 +62,10 @@ struct expr { }; /* some abbreviated selections */ +#define VL_CLASS ex_object.ex_value.vl_class #define VL_VALUE ex_object.ex_value.vl_value -#define VL_IDF ex_object.ex_value.vl_idf +#define VL_IDF ex_object.ex_value.vl_data.vl_idf +#define VL_LBL ex_object.ex_value.vl_data.vl_lbl #define SG_VALUE ex_object.ex_string.sg_value #define SG_LEN ex_object.ex_string.sg_len #define SG_DATLAB ex_object.ex_string.sg_datlab diff --git a/lang/cem/cemcom/field.c b/lang/cem/cemcom/field.c index bc0b76d2..6245ac86 100644 --- a/lang/cem/cemcom/field.c +++ b/lang/cem/cemcom/field.c @@ -47,7 +47,6 @@ eval_field(expr, code) ASSERT(leftop->ex_type->tp_fund == FIELD); ASSERT(asize == word_size); /* make sure that C_loc() is legal */ - leftop->ex_type = atype; /* this is cheating but it works... */ /* Note that op is either an assignment operator or an increment/ @@ -60,26 +59,21 @@ eval_field(expr, code) conversion(tp, atype); C_loc(fd->fd_mask); C_and(asize); - if (code == TRUE) { + if (code == TRUE) C_dup(asize); - } C_loc((arith)fd->fd_shift); - if (atype->tp_unsigned) C_slu(asize); else C_sli(asize); - C_loc(~((fd->fd_mask << fd->fd_shift) | (~0 << (8 * asize)))); - if (leftop->ex_depth == 0) { /* simple case */ load_val(leftop, RVAL); C_and(asize); C_ior(asize); store_val( - leftop->VL_IDF, - leftop->ex_type, - leftop->VL_VALUE + &(leftop->ex_object.ex_value), + leftop->ex_type ); } else { /* complex case */ @@ -98,13 +92,11 @@ eval_field(expr, code) } } else { /* treat ++F as F += 1 and --F as F -= 1 */ - /* F op= e: f = (((((f>>shift)&mask) op e)&mask)<ex_depth == 0) { /* simple case */ + if (leftop->ex_depth == 0) /* simple case */ load_val(leftop, RVAL); - } else { /* complex case */ tmpvar = tmp_pointer_var(&old_offset); EVAL(leftop, LVAL, TRUE, NO_LABEL, NO_LABEL); @@ -113,26 +105,18 @@ eval_field(expr, code) C_sti(pointer_size); C_loi(asize); } - C_loc((arith)fd->fd_shift); - if (atype->tp_unsigned) C_sru(asize); else C_sri(asize); - C_loc(fd->fd_mask); C_and(asize); - - if (code == TRUE && (op == POSTINCR || op == POSTDECR)) { + if (code == TRUE && (op == POSTINCR || op == POSTDECR)) C_dup(asize); - } - EVAL(rightop, RVAL, TRUE, NO_LABEL, NO_LABEL); conversion(tp, atype); - - /* generate the code for the operator - */ + /* generate code for the operator */ if (op == PLUSPLUS || op == POSTINCR) assop(atype, PLUSAB); else @@ -140,31 +124,23 @@ eval_field(expr, code) assop(atype, MINAB); else assop(atype, op); - C_loc(fd->fd_mask); C_and(asize); - - if (code == TRUE && op != POSTINCR && op != POSTDECR) { + if (code == TRUE && op != POSTINCR && op != POSTDECR) C_dup(asize); - } - C_loc((arith)fd->fd_shift); - if (atype->tp_unsigned) C_slu(asize); else C_sli(asize); - C_loc(~((fd->fd_mask << fd->fd_shift) | (~0 << (8 * asize)))); - if (leftop->ex_depth == 0) { load_val(leftop, RVAL); C_and(asize); C_ior(asize); store_val( - leftop->VL_IDF, - leftop->ex_type, - leftop->VL_VALUE + &(leftop->ex_object.ex_value), + leftop->ex_type ); } else { @@ -179,7 +155,6 @@ eval_field(expr, code) free_tmp_var(old_offset); } } - if (code == TRUE) { /* Take care that the effective value stored in the bit field (i.e. the value that is got on @@ -193,7 +168,6 @@ eval_field(expr, code) C_loc(shift); C_sri(asize); } - conversion(atype, tp); } } diff --git a/lang/cem/cemcom/ival.c b/lang/cem/cemcom/ival.c index 8e921e96..ff52c496 100644 --- a/lang/cem/cemcom/ival.c +++ b/lang/cem/cemcom/ival.c @@ -27,7 +27,6 @@ char *symbol2str(); char *long2str(); struct expr *do_array(), *do_struct(), *IVAL(); -struct expr *strings = 0; /* list of string constants within initialiser */ /* do_ival() performs the initialisation of a global variable of type tp with the initialisation expression expr by calling IVAL(). @@ -39,33 +38,8 @@ do_ival(tpp, expr) { if (IVAL(tpp, expr) != 0) too_many_initialisers(expr); - - /* The following loop declares the string constants - used in the initialisation. - The code for these string constants may not appear in - the code of the initialisation because a data label - in EM causes the current initialisation to be completed. - E.g. char *s[] = {"hello", "world"}; - */ - while (strings != 0) { - C_df_dlb(strings->SG_DATLAB); - C_con_scon(strings->SG_VALUE, (arith)strings->SG_LEN); - strings = strings->next; - } } - -/* store_string() collects the string constants appearing in an - initialisation. -*/ -store_string(expr) - struct expr *expr; -{ - expr->next = strings; - strings = expr; -} - - /* IVAL() recursively guides the initialisation expression through the different routines for the different types of initialisation: - array initialisation @@ -89,18 +63,14 @@ IVAL(tpp, expr) /* array initialisation */ if (valid_type(tp->tp_up, "array element") == 0) return 0; - if (ISCOMMA(expr)) { - /* list of initialisation expressions */ + if (ISCOMMA(expr)) /* list of initialisation expressions */ return do_array(expr, tpp); - } - /* There might be an initialisation of a string - like char s[] = "I am a string" - */ + /* catch initialisations like char s[] = "I am a string" */ if (tp->tp_up->tp_fund == CHAR && expr->ex_class == String) init_string(tpp, expr); else /* " int i[24] = 12;" */ check_and_pad(expr, tpp); - return 0; /* nothing left */ + break; case STRUCT: /* struct initialisation */ if (valid_type(tp, "struct") == 0) @@ -109,12 +79,12 @@ IVAL(tpp, expr) return do_struct(expr, tp); /* "struct foo f = 12;" */ check_and_pad(expr, tpp); - return 0; + break; case UNION: error("union initialisation not allowed"); - return 0; + break; case ERRONEOUS: - return 0; + break; default: /* fundamental type */ if (ISCOMMA(expr)) { /* " int i = {12};" */ if (IVAL(tpp, expr->OP_LEFT) != 0) @@ -127,9 +97,9 @@ IVAL(tpp, expr) } /* "int i = 12;" */ check_ival(expr, tp); - return 0; + break; } - /* NOTREACHED */ + return 0; } /* do_array() initialises the members of an array described @@ -451,20 +421,18 @@ check_ival(expr, type) case LONG: case ENUM: ch7cast(&expr, '=', type); - if (!is_cp_cst(expr)) { + if (is_cp_cst(expr)) + con_int(expr); + else illegal_init_cst(expr); - break; - } - con_int(expr); break; #ifndef NOBITFIELD case FIELD: ch7cast(&expr, '=', type->tp_up); - if (!is_cp_cst(expr)) { + if (is_cp_cst(expr)) + put_bf(type, expr->VL_VALUE); + else illegal_init_cst(expr); - break; - } - put_bf(type, expr->VL_VALUE); break; #endif NOBITFIELD case FLOAT: @@ -475,14 +443,13 @@ check_ival(expr, type) else if (expr->ex_class == Oper && expr->OP_OPER == INT2FLOAT) { expr = expr->OP_RIGHT; - if (!is_cp_cst(expr)) { + if (is_cp_cst(expr)) + C_con_fcon( + long2str((long)expr->VL_VALUE, 10), + type->tp_size + ); + else illegal_init_cst(expr); - break; - } - C_con_fcon( - long2str((long)expr->VL_VALUE, 10), - type->tp_size - ); } else illegal_init_cst(expr); @@ -493,55 +460,35 @@ check_ival(expr, type) case Oper: illegal_init_cst(expr); break; - case String: /* char *s = "...." */ - { - label datlab = data_label(); - - C_ina_dlb(datlab); - C_con_dlb(datlab, (arith)0); - expr->SG_DATLAB = datlab; - store_string(expr); - break; - } case Value: { - struct value *vl = &(expr->ex_object.ex_value); - struct idf *idf = vl->vl_idf; - ASSERT(expr->ex_type->tp_fund == POINTER); if (expr->ex_type->tp_up->tp_fund == FUNCTION) { - if (idf) - C_con_pnam(idf->id_text); + if (expr->VL_CLASS == Name) + C_con_pnam(expr->VL_IDF->id_text); else /* int (*func)() = 0 */ con_int(expr); } else - if (idf) { - register struct def *def = idf->id_def; + if (expr->VL_CLASS == Name) { + register struct idf *id = expr->VL_IDF; - if (def->df_level >= L_LOCAL) { - if (def->df_sc != STATIC) - /* Eg. int a; - static int *p = &a; - */ - expr_error(expr, - "illegal initialisation" - ); - else - C_con_dlb( - (label)def->df_address, - vl->vl_value - ); - } + if (id ->id_def->df_level >= L_LOCAL) + expr_error(expr, + "illegal initialisation"); else - C_con_dnam(idf->id_text, vl->vl_value); + C_con_dnam(id->id_text, expr->VL_VALUE); } + else + if (expr->VL_CLASS == Label) + C_con_dlb(expr->VL_LBL, expr->VL_VALUE); else con_int(expr); break; } + case String: default: - crash("(check_ival) illegal initialisation expression"); + crash("(check_ival) illegal value class"); } break; case ERRONEOUS: @@ -565,6 +512,7 @@ init_string(tpp, expr) char *s = expr->SG_VALUE; arith ntopad; + ASSERT(expr->ex_class == String); length = expr->SG_LEN; if (tp->tp_size == (arith)-1) { /* set the dimension */ @@ -604,21 +552,22 @@ put_bf(tp, val) static arith offset = (arith)-1; register struct field *fd = tp->tp_field; register struct sdef *sd = fd->fd_sdef; - static struct expr expr; + static struct expr exp; ASSERT(sd); if (offset == (arith)-1) { /* first bitfield in this field */ offset = sd->sd_offset; - expr.ex_type = tp->tp_up; - expr.ex_class = Value; + exp.ex_type = tp->tp_up; + exp.ex_class = Value; + exp.VL_CLASS = Const; } if (val != 0) /* insert the value into "field" */ field |= (val & fd->fd_mask) << fd->fd_shift; if (sd->sd_sdef == 0 || sd->sd_sdef->sd_offset != offset) { /* the selector was the last stored at this address */ - expr.VL_VALUE = field; - con_int(&expr); + exp.VL_VALUE = field; + con_int(&exp); field = (arith)0; offset = (arith)-1; } @@ -654,27 +603,28 @@ valid_type(tp, str) return 1; } -con_int(expr) - register struct expr *expr; +con_int(ex) + register struct expr *ex; { - register struct type *tp = expr->ex_type; + register struct type *tp = ex->ex_type; + ASSERT(is_cp_cst(ex)); if (tp->tp_unsigned) - C_con_ucon(long2str((long)expr->VL_VALUE, -10), tp->tp_size); + C_con_ucon(long2str((long)ex->VL_VALUE, -10), tp->tp_size); else - C_con_icon(long2str((long)expr->VL_VALUE, 10), tp->tp_size); + C_con_icon(long2str((long)ex->VL_VALUE, 10), tp->tp_size); } -illegal_init_cst(expr) - struct expr *expr; +illegal_init_cst(ex) + struct expr *ex; { - expr_error(expr, "illegal initialisation constant"); + expr_error(ex, "illegal initialisation constant"); } -too_many_initialisers(expr) - struct expr *expr; +too_many_initialisers(ex) + struct expr *ex; { - expr_error(expr, "too many initialisers"); + expr_error(ex, "too many initialisers"); } aggregate_type(tp) diff --git a/lang/cem/cemcom/switch.c b/lang/cem/cemcom/switch.c index 28db313f..3999206f 100644 --- a/lang/cem/cemcom/switch.c +++ b/lang/cem/cemcom/switch.c @@ -124,6 +124,7 @@ code_case(expr) register struct case_entry *ce; register struct switch_hdr *sh = switch_stack; + ASSERT(is_cp_cst(expr)); if (sh == 0) { error("case statement not in switch"); return; @@ -133,14 +134,11 @@ code_case(expr) /* is probably 0 anyway */ return; } - expr->ex_type = sh->sh_type; cut_size(expr); - ce = new_case_entry(); C_df_ilb(ce->ce_label = text_label()); ce->ce_value = val = expr->VL_VALUE; - if (sh->sh_entries == 0) { /* first case entry */ ce->next = (struct case_entry *) 0; From 5bf6f42cd71dd56011729af07e6745f8c145a0f9 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 2 Apr 1986 17:34:21 +0000 Subject: [PATCH 0160/1625] newer version, safety commit --- lang/m2/comp/LLlex.c | 5 +- lang/m2/comp/declar.g | 9 +++- lang/m2/comp/def.H | 4 +- lang/m2/comp/def.c | 101 +++++++++++++++++++++++++------------- lang/m2/comp/enter.c | 16 +++--- lang/m2/comp/expression.g | 9 +++- lang/m2/comp/program.g | 6 ++- lang/m2/comp/scope.C | 2 +- 8 files changed, 103 insertions(+), 49 deletions(-) diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index d003cc70..dedcca45 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -4,6 +4,7 @@ static char *RcsId = "$Header$"; #include #include +#include #include "input.h" #include "f_info.h" #include "Lpars.h" @@ -179,7 +180,7 @@ again: return tk->tk_symb = ch; default : - crash("bad STCOMP"); + assert(0); } case STIDF: @@ -373,7 +374,7 @@ Sdec: case STCHAR: default: - crash("bad character class %d", class(ch)); + assert(0); } /*NOTREACHED*/ } diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index f6c492e9..48a715df 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -130,7 +130,12 @@ TypeDeclaration }: IDENT { df = define(dot.TOK_IDF, CurrentScope, D_TYPE); } '=' type(&tp) - { df->df_type = tp; } + { df->df_type = tp; + if ((df->df_flags&D_EXPORTED) && + tp->tp_fund == ENUMERATION) { + exprt_literals(tp->enm_enums, enclosing(currscope)); + } + } ; type(struct type **ptp;): @@ -338,7 +343,7 @@ PointerType(struct type **ptp;) } else tp = df->df_type; } - | %if (df = lookfor(dot.TOK_IDF, 0), df->df_kind == D_MODULE) + | %if (df = lookfor(dot.TOK_IDF, currscope, 0), df->df_kind == D_MODULE) type(&tp) | IDENT diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H index 49d5bc05..3bc32260 100644 --- a/lang/m2/comp/def.H +++ b/lang/m2/comp/def.H @@ -38,8 +38,8 @@ struct field { }; struct import { - int im_scopenr; /* Scope number from which imported */ -#define imp_scopenr df_value.df_import.im_scopenr + struct def *im_def; /* Scope number from which imported */ +#define imp_def df_value.df_import.im_def }; struct def { /* list of definitions for a name */ diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index 2d4bfc24..df198a82 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -8,6 +8,7 @@ static char *RcsId = "$Header$"; #include #include "Lpars.h" #include "def.h" +#include "type.h" #include "idf.h" #include "misc.h" #include "main.h" @@ -60,7 +61,9 @@ define(id, scope, kind) df->df_kind = kind; return df; } - error("identifier \"%s\" already declared", id->id_text); + if (kind != D_ERROR) { + error("identifier \"%s\" already declared", id->id_text); + } return df; } df = new_def(); @@ -98,12 +101,9 @@ lookup(id, scope) while (df) { if (df->df_scope == scope) { if (df->df_kind == D_IMPORT) { - df = lookup(id, df->imp_scopenr); + df = df->imp_def; assert(df != 0); return df; - /* ??? But this does damage to the self- - organizing character of the list - */ } if (df1) { df1->next = df->next; @@ -118,14 +118,14 @@ lookup(id, scope) return 0; } -/* From the current scope, the list of identifiers "ids" is - exported. Note this fact. If the export is not qualified, make - all the "ids" visible in the enclosing scope by defining them - in this scope as "imported". -*/ Export(ids, qualified) register struct id_list *ids; { + /* From the current scope, the list of identifiers "ids" is + exported. Note this fact. If the export is not qualified, make + all the "ids" visible in the enclosing scope by defining them + in this scope as "imported". + */ register struct def *df; while (ids) { @@ -142,53 +142,88 @@ Export(ids, qualified) } } -/* "ids" is a list of imported identifiers. - If "id" is a null-pointer, the identifiers are imported from the - enclosing scope. Otherwise they are imported from the module - indicated by "id", ehich must be visible in the enclosing scope. - An exception must be made for imports of the Compilation Unit. - This case is indicated by the value 0 of the flag "local". - In this case, if "id" is a null pointer, the "ids" identifiers - are all module identifiers. Their Definition Modules must be read. - Otherwise "id" is a module identifier whose Definition Module must - be read. "ids" then represents a list of identifiers defined in - this module. -*/ Import(ids, id, local) register struct id_list *ids; struct idf *id; { + /* "ids" is a list of imported identifiers. + If "id" is a null-pointer, the identifiers are imported from the + enclosing scope. Otherwise they are imported from the module + indicated by "id", ehich must be visible in the enclosing scope. + An exception must be made for imports of the Compilation Unit. + This case is indicated by the value 0 of the flag "local". + In this case, if "id" is a null pointer, the "ids" identifiers + are all module identifiers. Their Definition Modules must be + read. Otherwise "id" is a module identifier whose Definition + Module must be read. "ids" then represents a list of + identifiers defined in this module. + */ register struct def *df; int scope; int kind; + int imp_kind; +#define FROM_MODULE 0 +#define FROM_ENCLOSING 1 struct def *lookfor(); if (local) { kind = D_IMPORT; - if (!id) scope = enclosing(currscope)->sc_scope; + scope = enclosing(currscope)->sc_scope; + if (!id) imp_kind = FROM_ENCLOSING; else { - df = lookfor(id, 1); + imp_kind = FROM_MODULE; + df = lookfor(id, enclosing(currscope), 1); if (df->df_kind != D_MODULE) { + /* enter all "ids" with type D_ERROR */ + kind = D_ERROR; if (df->df_kind != D_ERROR) { error("identifier \"%s\" does not represent a module", id->id_text); } - /* enter all "ids" with type D_ERROR */ - kind = D_ERROR; - scope = enclosing(currscope)->sc_scope; } else scope = df->mod_scope; } while (ids) { - df = lookup(ids->id_ptr, scope); - if (!df) { - error("identifier \"%s\" not declared", - ids->id_ptr->id_text); + if (imp_kind == FROM_MODULE) { + if (!(df = lookup(ids->id_ptr, scope))) { +error("identifier \"%s\" not declared in qualifying module", +ids->id_ptr->id_text); + df = ill_df; + } + else + if (!(df->df_flags&(D_EXPORTED|D_QEXPORTED))) { +error("identifier \"%s\" not exported from qualifying module", +ids->id_ptr->id_text); + } + } + else { + df = lookfor(ids->id_ptr, enclosing(currscope), 0); + if (df->df_kind == D_ERROR) { +error("identifier \"%s\" not visible in enclosing scope", +ids->id_ptr->id_text); + } + } + define(ids->id_ptr, CurrentScope, kind)->imp_def = df; + if (df->df_kind == D_TYPE && + df->df_type->tp_fund == ENUMERATION) { + /* Also import all enumeration literals */ + exprt_literals(df->df_type->enm_enums, currscope); } - df = define(ids->id_ptr, CurrentScope, D_IMPORT); - df->imp_scopenr = scope; ids = ids->next; } return; } /* ???? */ } + +exprt_literals(df, toscope) + register struct def *df; + register struct scope *toscope; +{ + /* A list of enumeration literals is exported. This is implemented + as an import from the scope "toscope". + */ + while (df) { + define(df->df_idf, toscope->sc_scope, D_IMPORT)->imp_def = df; + df = df->enm_next; + } +} diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index 03b98330..5c37e1ee 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -60,16 +60,18 @@ EnterIdList(idlist, kind, flags, type, scope) } } -/* Look for an identifier in the current visibility range. - If it is not defined, give an error message, and - create a dummy definition. -*/ struct def * -lookfor(id, give_error) +lookfor(id, scope, give_error) struct idf *id; + struct scope *scope; { - register struct scope *sc = currscope; + /* Look for an identifier in the visibility range started by + "scope". + If it is not defined, give an error message, and + create a dummy definition. + */ struct def *df; + register struct scope *sc = scope; while (sc) { df = lookup(id, sc->sc_scope); @@ -77,5 +79,5 @@ lookfor(id, give_error) sc = nextvisible(sc); } if (give_error) error("Identifier \"%s\" not declared", id->id_text); - return define(id, CurrentScope, D_ERROR); + return define(id, scope->sc_scope, D_ERROR); } diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index 9d435798..c4611915 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -21,11 +21,12 @@ number: qualident(int types; struct def **pdf; char *str;) { int scope; + int module; register struct def *df; struct def *lookfor(); } : IDENT { if (types) { - *pdf = df = lookfor(dot.TOK_IDF, 1); + *pdf = df = lookfor(dot.TOK_IDF, currscope, 1); if (df->df_kind == D_ERROR) types = 0; } } @@ -38,6 +39,7 @@ qualident(int types; struct def **pdf; char *str;) /* selector */ '.' IDENT { if (types) { + module = (df->df_kind == D_MODULE); df = lookup(dot.TOK_IDF, scope); if (!df) { error("identifier \"%s\" not declared", @@ -45,6 +47,11 @@ qualident(int types; struct def **pdf; char *str;) types = 0; df = ill_df; } + else + if (module && + !(df->df_flags&(D_EXPORTED|D_QEXPORTED))) { + error("identifier \"%s\" not exported from qualifying module", dot.TOK_IDF->id_text); + } } } ]* diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 691b08ce..c4c7b3d5 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -35,9 +35,13 @@ static char *RcsId = "$Header$"; ModuleDeclaration { struct idf *id; + struct def *df; } : - MODULE IDENT { open_scope(CLOSEDSCOPE, 0); + MODULE IDENT { id = dot.TOK_IDF; + df = define(id, CurrentScope, D_MODULE); + open_scope(CLOSEDSCOPE, 0); + df->mod_scope = CurrentScope; } priority? ';' import(1)* diff --git a/lang/m2/comp/scope.C b/lang/m2/comp/scope.C index 6eafc237..ef2080d4 100644 --- a/lang/m2/comp/scope.C +++ b/lang/m2/comp/scope.C @@ -118,7 +118,7 @@ rem_forwards(fo) savetok = dot; while (f = fo) { dot = f->fo_tok; - df = lookfor(dot.TOK_IDF, 1); + df = lookfor(dot.TOK_IDF, currscope, 1); if (!(df->df_kind & (D_TYPE | D_HTYPE | D_ERROR))) { error("identifier \"%s\" not a type", df->df_idf->id_text); } From a4e3f3b499622fcc1f0cd6a4da13b42fd0b78094 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 3 Apr 1986 00:44:39 +0000 Subject: [PATCH 0161/1625] Newer version, safety commit --- lang/m2/comp/Makefile | 9 ++-- lang/m2/comp/declar.g | 45 +++++++++++-------- lang/m2/comp/def.c | 93 +++++++++++++++++++-------------------- lang/m2/comp/defmodule.c | 66 +++++++++++++++++++++++++++ lang/m2/comp/enter.c | 8 ++-- lang/m2/comp/expression.g | 3 +- lang/m2/comp/input.h | 2 +- lang/m2/comp/main.c | 41 ++++++++++++++++- lang/m2/comp/program.g | 53 +++++++++++++--------- lang/m2/comp/scope.C | 65 ++++++++++++++------------- lang/m2/comp/scope.h | 4 +- lang/m2/comp/type.H | 4 +- lang/m2/comp/type.c | 2 +- 13 files changed, 261 insertions(+), 134 deletions(-) create mode 100644 lang/m2/comp/defmodule.c diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index ef03535e..b88cbb48 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -14,7 +14,7 @@ LFLAGS = -p LOBJ = tokenfile.o program.o declar.o expression.o statement.o COBJ = LLlex.o LLmessage.o char.o error.o main.o \ symbol2str.o tokenname.o idf.o input.o type.o def.o \ - scope.o misc.o print.o enter.o + scope.o misc.o print.o enter.o defmodule.o OBJ = $(COBJ) $(LOBJ) Lpars.o GENFILES= tokenfile.c \ program.c declar.c expression.c statement.c \ @@ -69,18 +69,19 @@ LLlex.o: LLlex.h Lpars.h class.h f_info.h idf.h input.h LLmessage.o: LLlex.h Lpars.h idf.h char.o: class.h error.o: LLlex.h f_info.h input.h -main.o: LLlex.h Lpars.h debug.h def.h f_info.h idf.h input.h main.h standards.h type.h +main.o: LLlex.h Lpars.h debug.h def.h f_info.h idf.h input.h main.h scope.h standards.h type.h symbol2str.o: Lpars.h tokenname.o: Lpars.h idf.h tokenname.h idf.o: idf.h input.o: f_info.h input.h type.o: Lpars.h def.h def_sizes.h idf.h misc.h type.h -def.o: Lpars.h debug.h def.h idf.h main.h misc.h scope.h +def.o: Lpars.h debug.h def.h idf.h main.h misc.h scope.h type.h scope.o: LLlex.h debug.h def.h idf.h scope.h type.h misc.o: LLlex.h f_info.h idf.h misc.h enter.o: def.h idf.h misc.h scope.h type.h +defmodule.o: LLlex.h def.h f_info.h idf.h input.h scope.h tokenfile.o: Lpars.h -program.o: LLlex.h Lpars.h def.h idf.h main.h misc.h scope.h type.h +program.o: LLlex.h Lpars.h debug.h def.h idf.h main.h misc.h scope.h type.h declar.o: LLlex.h Lpars.h def.h idf.h misc.h scope.h type.h expression.o: LLlex.h Lpars.h def.h idf.h scope.h statement.o: Lpars.h diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 48a715df..b773b6cc 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -37,7 +37,7 @@ ProcedureHeading(struct def **pdf; int type;) open_scope(OPENSCOPE, 0); } } - FormalParameters(type, ¶ms, &tp)? + FormalParameters(type == D_PROCEDURE, ¶ms, &tp)? { (*pdf)->df_type = tp = construct_type(PROCEDURE, tp); tp->prc_params = params; @@ -133,8 +133,14 @@ TypeDeclaration { df->df_type = tp; if ((df->df_flags&D_EXPORTED) && tp->tp_fund == ENUMERATION) { - exprt_literals(tp->enm_enums, enclosing(currscope)); + exprt_literals(tp->enm_enums, + enclosing(CurrentScope)); } + if (df->df_kind == D_HTYPE && + tp->tp_fund != POINTER) { +error("Opaque type \"%s\" is not a pointer type", df->df_idf->id_text); + } + } ; @@ -246,27 +252,29 @@ ArrayType(struct type **ptp;) RecordType(struct type **ptp;) { - int scopenr; + struct scope scope; } : RECORD - { scopenr = uniq_scope(); } - FieldListSequence(scopenr) + { scope.sc_scope = uniq_scope(); + scope.next = CurrentScope; + } + FieldListSequence(&scope) { *ptp = standard_type(RECORD, record_align, (arith) 0 /* ???? */); - (*ptp)->rec_scopenr = scopenr; + (*ptp)->rec_scope = scope.sc_scope; } END ; -FieldListSequence(int scopenr;): - FieldList(scopenr) +FieldListSequence(struct scope *scope;): + FieldList(scope) [ - ';' FieldList(scopenr) + ';' FieldList(scope) ]* ; -FieldList(int scopenr;) +FieldList(struct scope *scope;) { struct id_list *FldList; struct idf *id; @@ -283,21 +291,21 @@ FieldList(int scopenr;) { id = gen_anon_idf(); } ] /* Changed rule in new modula-2 */ ':' qualident(D_TYPE|D_HTYPE, &df, "type") - { df1 = define(id, scopenr, D_FIELD); + { df1 = define(id, scope, D_FIELD); df1->df_type = df->df_type; } - OF variant(scopenr) + OF variant(scope) [ - '|' variant(scopenr) + '|' variant(scope) ]* - [ ELSE FieldListSequence(scopenr) + [ ELSE FieldListSequence(scope) ]? END ]? ; -variant(int scopenr;): - [ CaseLabelList ':' FieldListSequence(scopenr) ]? +variant(struct scope *scope;): + [ CaseLabelList ':' FieldListSequence(scope) ]? /* Changed rule in new modula-2 */ ; @@ -330,7 +338,7 @@ PointerType(struct type **ptp;) struct def *lookfor(); } : POINTER TO - [ %if ( (df = lookup(dot.TOK_IDF, CurrentScope))) + [ %if ( (df = lookup(dot.TOK_IDF, CurrentScope->sc_scope))) /* Either a Module or a Type, but in both cases defined in this scope, so this is the correct identification */ @@ -343,7 +351,8 @@ PointerType(struct type **ptp;) } else tp = df->df_type; } - | %if (df = lookfor(dot.TOK_IDF, currscope, 0), df->df_kind == D_MODULE) + | %if (df = lookfor(dot.TOK_IDF, CurrentScope, 0), + df->df_kind == D_MODULE) type(&tp) | IDENT diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index df198a82..9a51998f 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -25,6 +25,7 @@ struct def *ill_df = &illegal_def; struct def * define(id, scope, kind) register struct idf *id; + struct scope *scope; { /* Declare an identifier in a scope, but first check if it already has been defined. If so, error message. @@ -32,14 +33,14 @@ define(id, scope, kind) register struct def *df; register struct scope *sc; - DO_DEBUG(debug(4,"Defining identifier %s in scope %d", id->id_text, scope)); - df = lookup(id, scope); + DO_DEBUG(debug(4,"Defining identifier %s in scope %d", id->id_text, scope->sc_scope)); + df = lookup(id, scope->sc_scope); if ( /* Already in this scope */ df || /* A closed scope, and id defined in the pervasive scope */ ( CurrentScope == scope && - scopeclosed(currscope) + scopeclosed(CurrentScope) && (df = lookup(id, 0))) ) { @@ -68,19 +69,14 @@ define(id, scope, kind) } df = new_def(); df->df_idf = id; - df->df_scope = scope; + df->df_scope = scope->sc_scope; df->df_kind = kind; df->next = id->id_def; id->id_def = df; /* enter the definition in the list of definitions in this scope */ - sc = currscope; - while (sc->sc_scope != scope) { - sc = sc->next; - assert(sc != 0); - } - df->df_nextinscope = sc->sc_def; - sc->sc_def = df; + df->df_nextinscope = scope->sc_def; + scope->sc_def = df; return df; } @@ -135,7 +131,7 @@ Export(ids, qualified) } else { df->df_flags |= D_EXPORTED; - df = define(ids->id_ptr, enclosing(currscope)->sc_scope, + df = define(ids->id_ptr, enclosing(CurrentScope), D_IMPORT); } ids = ids->next; @@ -164,55 +160,56 @@ Import(ids, id, local) int imp_kind; #define FROM_MODULE 0 #define FROM_ENCLOSING 1 - struct def *lookfor(); + struct def *lookfor(), *GetDefinitionModule(); - if (local) { - kind = D_IMPORT; - scope = enclosing(currscope)->sc_scope; - if (!id) imp_kind = FROM_ENCLOSING; - else { - imp_kind = FROM_MODULE; - df = lookfor(id, enclosing(currscope), 1); - if (df->df_kind != D_MODULE) { - /* enter all "ids" with type D_ERROR */ - kind = D_ERROR; - if (df->df_kind != D_ERROR) { + kind = D_IMPORT; + scope = enclosing(CurrentScope)->sc_scope; + if (!id) imp_kind = FROM_ENCLOSING; + else { + imp_kind = FROM_MODULE; + if (local) df = lookfor(id, enclosing(CurrentScope), 1); + else df = GetDefinitionModule(id); + if (df->df_kind != D_MODULE) { + /* enter all "ids" with type D_ERROR */ + kind = D_ERROR; + if (df->df_kind != D_ERROR) { error("identifier \"%s\" does not represent a module", id->id_text); - } } - else scope = df->mod_scope; } - while (ids) { - if (imp_kind == FROM_MODULE) { - if (!(df = lookup(ids->id_ptr, scope))) { + else scope = df->mod_scope; + } + while (ids) { + if (imp_kind == FROM_MODULE) { + if (!(df = lookup(ids->id_ptr, scope))) { error("identifier \"%s\" not declared in qualifying module", ids->id_ptr->id_text); - df = ill_df; - } - else - if (!(df->df_flags&(D_EXPORTED|D_QEXPORTED))) { + df = ill_df; + } + else + if (!(df->df_flags&(D_EXPORTED|D_QEXPORTED))) { error("identifier \"%s\" not exported from qualifying module", ids->id_ptr->id_text); - } } - else { - df = lookfor(ids->id_ptr, enclosing(currscope), 0); - if (df->df_kind == D_ERROR) { + } + else { + if (local) { + df = lookfor(ids->id_ptr, + enclosing(CurrentScope), 0); + } else df = GetDefinitionModule(ids->id_ptr); + if (df->df_kind == D_ERROR) { error("identifier \"%s\" not visible in enclosing scope", ids->id_ptr->id_text); - } } - define(ids->id_ptr, CurrentScope, kind)->imp_def = df; - if (df->df_kind == D_TYPE && - df->df_type->tp_fund == ENUMERATION) { - /* Also import all enumeration literals */ - exprt_literals(df->df_type->enm_enums, currscope); - } - ids = ids->next; } - return; + define(ids->id_ptr, CurrentScope, kind)->imp_def = df; + if (df->df_kind == D_TYPE && + df->df_type->tp_fund == ENUMERATION) { + /* Also import all enumeration literals */ + exprt_literals(df->df_type->enm_enums, + CurrentScope); + } + ids = ids->next; } - /* ???? */ } exprt_literals(df, toscope) @@ -223,7 +220,7 @@ exprt_literals(df, toscope) as an import from the scope "toscope". */ while (df) { - define(df->df_idf, toscope->sc_scope, D_IMPORT)->imp_def = df; + define(df->df_idf, toscope, D_IMPORT)->imp_def = df; df = df->enm_next; } } diff --git a/lang/m2/comp/defmodule.c b/lang/m2/comp/defmodule.c new file mode 100644 index 00000000..b007705d --- /dev/null +++ b/lang/m2/comp/defmodule.c @@ -0,0 +1,66 @@ +/* D E F I N I T I O N M O D U L E S */ + +#include +#include +#include +#include "idf.h" +#include "input.h" +#include "scope.h" +#include "def.h" +#include "LLlex.h" +#include "f_info.h" + +GetFile(name) + char *name; +{ + /* Try to find a file with basename "name" and extension ".def", + in the directories mentioned in "DEFPATH". + */ + extern char *DEFPATH[]; + char buf[256]; + + (void) strcpy(buf, name); + if (strlen(buf) > 10) { + (void) strcpy(&buf[10], ".def"); + } + else (void) strcat(buf, ".def"); + if (! InsertFile(buf, DEFPATH, &(FileName))) { + fatal("Could'nt find a DEFINITION MODULE for \"%s\"", name); + } + LineNumber = 1; +} + +struct def * +GetDefinitionModule(id) + struct idf *id; +{ + /* Return a pointer to the "def" structure of the definition + module indicated by "id". + We may have to read the definition module itself. + */ + struct def *df; + + df = lookup(id, GlobalScope->sc_scope); + if (!df) { + /* Read definition module. Make an exception for SYSTEM. + */ + if (!strcmp(id->id_text, "SYSTEM")) { + do_SYSTEM(); + } + else { + GetFile(id->id_text); + DefModule(); + } + df = lookup(id, GlobalScope->sc_scope); + } + assert(df != 0 && df->df_kind == D_MODULE); + return df; +} + +AtEoIF() +{ + /* Make the unstacking of input streams noticable by the + lexical analyzer + */ + return 1; +} diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index 5c37e1ee..1912eabd 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -11,9 +11,6 @@ static char *RcsId = "$Header$"; #include "scope.h" #include "misc.h" -extern struct idf *str2idf(); -extern struct def *define(); - struct def * Enter(name, kind, type, pnam) char *name; @@ -35,6 +32,7 @@ Enter(name, kind, type, pnam) EnterIdList(idlist, kind, flags, type, scope) register struct id_list *idlist; struct type *type; + struct scope *scope; { register struct def *df; struct def *first = 0, *last = 0; @@ -78,6 +76,6 @@ lookfor(id, scope, give_error) if (df) return df; sc = nextvisible(sc); } - if (give_error) error("Identifier \"%s\" not declared", id->id_text); - return define(id, scope->sc_scope, D_ERROR); + if (give_error) error("identifier \"%s\" not declared", id->id_text); + return define(id, scope, D_ERROR); } diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index c4611915..7f1c3ca3 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -26,7 +26,8 @@ qualident(int types; struct def **pdf; char *str;) struct def *lookfor(); } : IDENT { if (types) { - *pdf = df = lookfor(dot.TOK_IDF, currscope, 1); + df = lookfor(dot.TOK_IDF, CurrentScope, 1); + *pdf = df; if (df->df_kind == D_ERROR) types = 0; } } diff --git a/lang/m2/comp/input.h b/lang/m2/comp/input.h index aa28ffc1..550cdc50 100644 --- a/lang/m2/comp/input.h +++ b/lang/m2/comp/input.h @@ -5,5 +5,5 @@ #define INP_NPUSHBACK 2 #define INP_TYPE struct f_info #define INP_VAR file_info -#define INP_READ_IN_ONE + #include diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index 2bd33a04..8cccad74 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -14,12 +14,15 @@ static char *RcsId = "$Header$"; #include "debug.h" #include "type.h" #include "def.h" +#include "scope.h" #include "standards.h" char options[128]; char *ProgName; int state; extern int err_occurred; +char *DEFPATH[128]; +char *getenv(); main(argc, argv) char *argv[]; @@ -53,12 +56,13 @@ Compile(src) extern struct tokenname tkidf[]; DO_DEBUG(debug(1,"Filename : %s", src)); - if (! InsertFile(src, (char **) 0)) { + if (! InsertFile(src, (char **) 0, &src)) { fprintf(STDERR,"%s: cannot open %s\n", ProgName, src); return 0; } LineNumber = 1; FileName = src; + init_DEFPATH(); init_idf(); reserve(tkidf); init_scope(); @@ -69,10 +73,13 @@ Compile(src) LexScan(); else if (options['T']) TimeScan(); - else + else { #endif DEBUG + (void) open_scope(CLOSEDSCOPE, 0); + GlobalScope = CurrentScope; CompUnit(); #ifdef DEBUG + } if (options['h']) hash_stat(); #endif DEBUG if (err_occurred) return 0; @@ -169,3 +176,33 @@ add_standards() df->df_value.df_enum.en_val = 1; df->df_value.df_enum.en_next = 0; } + +init_DEFPATH() +{ + register char *p = getenv("M2path"); + register int i = 0; + + if (p) { + while (*p) { + DEFPATH[i++] = p; + while (*p && *p != ':') p++; + if (*p) *p++ = '\0'; + } + } + DEFPATH[i] = 0; +} + +do_SYSTEM() +{ + /* Simulate the reading of the SYSTEM definition module + */ + struct def *df; + struct idf *sys_id; + + sys_id = str2idf("SYSTEM", 0); + df = define(sys_id, GlobalScope, D_MODULE); + open_scope(CLOSEDSCOPE, 0); + df->mod_scope = CurrentScope->sc_scope; + /* ???? */ + close_scope(); +} diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index c4c7b3d5..68c5be23 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -13,6 +13,7 @@ static char *RcsId = "$Header$"; #include "scope.h" #include "def.h" #include "type.h" +#include "debug.h" } /* The grammar as given by Wirth is already almost LL(1); the @@ -31,6 +32,7 @@ static char *RcsId = "$Header$"; %lexical LLlex; %start CompUnit, CompilationUnit; +%start DefModule, DefinitionModule; ModuleDeclaration { @@ -41,11 +43,11 @@ ModuleDeclaration id = dot.TOK_IDF; df = define(id, CurrentScope, D_MODULE); open_scope(CLOSEDSCOPE, 0); - df->mod_scope = CurrentScope; + df->mod_scope = CurrentScope->sc_scope; } priority? ';' import(1)* - export? + export(0)? block IDENT { close_scope(); match_id(id, dot.TOK_IDF); @@ -56,7 +58,7 @@ priority: '[' ConstExpression ']' ; -export +export(int def;) { struct id_list *ExportList; int QUALflag = 0; @@ -67,7 +69,8 @@ export ]? IdentList(&ExportList) ';' { - Export(ExportList, QUALflag); + if (!def) Export(ExportList, QUALflag); + else warning("export list in definition module ignored"); FreeIdList(ExportList); } ; @@ -95,23 +98,31 @@ import(int local;) DefinitionModule { - struct def *df; + register struct def *df; struct idf *id; } : DEFINITION { state = DEFINITION; } MODULE IDENT { id = dot.TOK_IDF; - df = define(id, CurrentScope, D_MODULE); + df = define(id, GlobalScope, D_MODULE); open_scope(CLOSEDSCOPE, 0); - df->mod_scope = CurrentScope; + df->mod_scope = CurrentScope->sc_scope; + DO_DEBUG(debug(1, "Definition module \"%s\"", id->id_text)); } ';' import(0)* - /* export? + export(1)? - New Modula-2 does not have export lists in definition modules. + /* New Modula-2 does not have export lists in definition modules. */ definition* END IDENT '.' - { close_scope(); + { + df = CurrentScope->sc_def; + while (df) { + /* Make all definitions "QUALIFIED EXPORT" */ + df->df_flags |= D_QEXPORTED; + df = df->df_nextinscope; + } + close_scope(); match_id(id, dot.TOK_IDF); } ; @@ -124,7 +135,7 @@ definition CONST [ ConstantDeclaration ';' ]* | TYPE - [ IDENT + [ IDENT { df = define(dot.TOK_IDF, CurrentScope, D_TYPE); } [ '=' type(&tp) | /* empty */ /* @@ -132,6 +143,7 @@ definition The export is said to be opaque. It is restricted to pointer types. */ + { df->df_kind = D_HIDDEN; } ] ';' ]* @@ -141,19 +153,20 @@ definition ProcedureHeading(&df, D_PROCHEAD) ';' ; -ProgramModule { +ProgramModule +{ struct idf *id; + struct def *df, *GetDefinitionModule(); + int scope = 0; } : MODULE { if (state != IMPLEMENTATION) state = PROGRAM; } - IDENT { if (state == IMPLEMENTATION) { - /* ???? - Read definition module, - Look for current identifier, - and find out its scope number - */ - } + IDENT { id = dot.TOK_IDF; - open_scope(CLOSEDSCOPE, 0); + if (state == IMPLEMENTATION) { + df = GetDefinitionModule(id); + scope = df->mod_scope; + } + open_scope(CLOSEDSCOPE, scope); } priority? ';' import(0)* diff --git a/lang/m2/comp/scope.C b/lang/m2/comp/scope.C index ef2080d4..1a2badcd 100644 --- a/lang/m2/comp/scope.C +++ b/lang/m2/comp/scope.C @@ -15,41 +15,44 @@ static char *RcsId = "$Header$"; static int maxscope; /* maximum assigned scope number */ -struct scope *currscope; +struct scope *CurrentScope, *GlobalScope; /* STATICALLOCDEF "scope" */ -/* Open a scope that is either open (automatic imports) or closed. - A closed scope is handled by adding an extra entry to the list - with scope number 0. This has two purposes: it makes scope 0 - visible, and it marks the end of a visibility list. - Scope 0 is the pervasive scope, the one that is always visible. - A disadvantage of this method is that we cannot open scope 0 - explicitly. -*/ -open_scope(scopetype, scopenr) +open_scope(scopetype, scope) { + /* Open a scope that is either open (automatic imports) or closed. + A closed scope is handled by adding an extra entry to the list + with scope number 0. This has two purposes: it makes scope 0 + visible, and it marks the end of a visibility list. + Scope 0 is the pervasive scope, the one that is always visible. + A disadvantage of this method is that we cannot open scope 0 + explicitly. + */ register struct scope *sc = new_scope(); register struct scope *sc1; - sc->sc_scope = scopenr == 0 ? ++maxscope : scopenr; + sc->sc_scope = scope == 0 ? ++maxscope : scope; + sc->sc_forw = 0; sc->sc_def = 0; assert(scopetype == OPENSCOPE || scopetype == CLOSEDSCOPE); - DO_DEBUG(debug(1, "Opening a %s scope", scopetype == OPENSCOPE ? "open" : "closed")); - sc1 = currscope; + DO_DEBUG(debug(1, "Opening a %s scope", + scopetype == OPENSCOPE ? "open" : "closed")); + sc1 = CurrentScope; if (scopetype == CLOSEDSCOPE) { sc1 = new_scope(); sc1->sc_scope = 0; /* Pervasive scope nr */ - sc1->next = currscope; + sc1->sc_forw = 0; sc1->sc_def = 0; + sc1->next = CurrentScope; } sc->next = sc1; - currscope = sc; + CurrentScope = sc; } static rem_forwards(); close_scope() { - register struct scope *sc = currscope; + register struct scope *sc = CurrentScope; assert(sc != 0); DO_DEBUG(debug(1, "Closing a scope")); @@ -60,7 +63,7 @@ close_scope() sc = sc->next; free_scope(sc1); } - currscope = sc->next; + CurrentScope = sc->next; free_scope(sc); } @@ -69,8 +72,9 @@ init_scope() register struct scope *sc = new_scope(); sc->sc_scope = 0; - sc->next = 0; - currscope = sc; + sc->sc_forw = 0; + sc->sc_def = 0; + CurrentScope = sc; } int @@ -87,29 +91,29 @@ struct forwards { /* STATICALLOCDEF "forwards" */ -/* Enter a forward reference into a list belonging to the - current scope. This is used for POINTER declarations, which - may have forward references that must howewer be declared in the - same scope. -*/ Forward(tk, ptp) struct token *tk; struct type **ptp; { + /* Enter a forward reference into a list belonging to the + current scope. This is used for POINTER declarations, which + may have forward references that must howewer be declared in the + same scope. + */ register struct forwards *f = new_forwards(); f->fo_tok = *tk; f->fo_ptyp = ptp; - f->next = currscope->sc_forw; - currscope->sc_forw = f; + f->next = CurrentScope->sc_forw; + CurrentScope->sc_forw = f; } -/* When closing a scope, all forward references must be resolved -*/ static rem_forwards(fo) struct forwards *fo; { + /* When closing a scope, all forward references must be resolved + */ register struct forwards *f; struct token savetok; register struct def *df; @@ -118,9 +122,10 @@ rem_forwards(fo) savetok = dot; while (f = fo) { dot = f->fo_tok; - df = lookfor(dot.TOK_IDF, currscope, 1); + df = lookfor(dot.TOK_IDF, CurrentScope, 1); if (!(df->df_kind & (D_TYPE | D_HTYPE | D_ERROR))) { - error("identifier \"%s\" not a type", df->df_idf->id_text); + error("identifier \"%s\" not a type", + df->df_idf->id_text); } *(f->fo_ptyp) = df->df_type; fo = f->next; diff --git a/lang/m2/comp/scope.h b/lang/m2/comp/scope.h index 35253bec..c8e6d9c9 100644 --- a/lang/m2/comp/scope.h +++ b/lang/m2/comp/scope.h @@ -16,9 +16,9 @@ struct scope { }; extern struct scope - *currscope; + *CurrentScope, + *GlobalScope; #define nextvisible(x) ((x)->sc_scope ? (x)->next : (struct scope *) 0) #define scopeclosed(x) ((x)->next->sc_scope == 0) #define enclosing(x) (scopeclosed(x) ? (x)->next->next : (x)->next) -#define CurrentScope (currscope->sc_scope) diff --git a/lang/m2/comp/type.H b/lang/m2/comp/type.H index 0f2a2ee4..f2ebb802 100644 --- a/lang/m2/comp/type.H +++ b/lang/m2/comp/type.H @@ -38,9 +38,9 @@ struct array { }; struct record { - int rc_scopenr; /* Scope number of this record */ + int rc_scope; /* Scope number of this record */ /* Members are in the symbol table */ -#define rec_scopenr tp_value.tp_record.rc_scopenr +#define rec_scope tp_value.tp_record.rc_scope }; struct proc { diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index ae9aa6fb..3d5fe909 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -144,7 +144,7 @@ has_selectors(df) register struct type *tp = df->df_type; if (tp->tp_fund == RECORD) { - return tp->rec_scopenr; + return tp->rec_scope; } break; } From 22f6299fdb48f392fb60182ac7c6f3e28278a231 Mon Sep 17 00:00:00 2001 From: erikb Date: Thu, 3 Apr 1986 11:33:32 +0000 Subject: [PATCH 0162/1625] revised check_ival() (among some other small changes) --- lang/cem/cemcom/Makefile.erik | 10 +- lang/cem/cemcom/ch7mon.c | 26 ++-- lang/cem/cemcom/ival.c | 263 +++++++++++++++++----------------- lang/cem/cemcom/options | 1 - 4 files changed, 152 insertions(+), 148 deletions(-) diff --git a/lang/cem/cemcom/Makefile.erik b/lang/cem/cemcom/Makefile.erik index dff19db6..aa63546d 100644 --- a/lang/cem/cemcom/Makefile.erik +++ b/lang/cem/cemcom/Makefile.erik @@ -9,10 +9,12 @@ EM_INCLUDES =$(EM)/h# # directory containing EM interface definition # Libraries SYSLIB = /user1/erikb/em/lib/libsystem.a -EMLIB = /user1/erikb/em/lib/libemk.a +EMKLIB = /user1/erikb/em/lib/libemk.a +EMELIB = /user1/erikb/em/lib/libeme.a STRLIB = /user1/erikb/em/lib/libstr.a EMMESLIB = /user1/erikb/em/lib/libem_mes.a -LIBS = $(EMMESLIB) $(EMLIB) $(STRLIB) $(SYSLIB) +LIBS = $(EMMESLIB) $(EMKLIB) $(STRLIB) $(SYSLIB) +ELIBS = $(EMMESLIB) $(EMELIB) $(STRLIB) $(SYSLIB) LIB_INCLUDES = /user1/erikb/em/h # Where to install the compiler and its driver @@ -128,6 +130,10 @@ main: $(OBJ) Makefile $(CC) $(COPTIONS) $(LFLAGS) $(OBJ) $(LIBS) -o main size main +emain: $(OBJ) Makefile + $(CC) $(COPTIONS) $(LFLAGS) $(OBJ) $(ELIBS) -o emain + size emain + cfiles: hfiles LLfiles $(GSRC) @touch cfiles diff --git a/lang/cem/cemcom/ch7mon.c b/lang/cem/cemcom/ch7mon.c index b99925a1..64b3170e 100644 --- a/lang/cem/cemcom/ch7mon.c +++ b/lang/cem/cemcom/ch7mon.c @@ -46,21 +46,23 @@ ch7mon(oper, expp) } break; case '&': - if ((*expp)->ex_type->tp_fund == ARRAY) + if ((*expp)->ex_type->tp_fund == ARRAY) { + warning("& before array: ignored"); array2pointer(expp); + } else - if ((*expp)->ex_type->tp_fund == FUNCTION) + if ((*expp)->ex_type->tp_fund == FUNCTION) { + warning("& before function: ignored"); function2pointer(expp); + } else #ifndef NOBITFIELD - if ((*expp)->ex_type->tp_fund == FIELD) { + if ((*expp)->ex_type->tp_fund == FIELD) expr_error(*expp, "& applied to field variable"); - } else #endif NOBITFIELD - if (!(*expp)->ex_lvalue) { + if (!(*expp)->ex_lvalue) expr_error(*expp, "& applied to non-lvalue"); - } else { /* assume that enums are already filtered out */ if ( (*expp)->ex_class == Value @@ -89,11 +91,15 @@ ch7mon(oper, expp) int fund = (*expp)->ex_type->tp_fund; if (fund == FLOAT || fund == DOUBLE) { - expr_error(*expp, "~ not allowed on %s operands", - symbol2str(fund)); + expr_error( + *expp, + "~ not allowed on %s operands", + symbol2str(fund) + ); erroneous2int(expp); break; } + /* FALL THROUGH */ } case '-': any2arith(expp, oper); @@ -106,7 +112,7 @@ ch7mon(oper, expp) switch_sign_fp(*expp); else *expp = new_oper((*expp)->ex_type, - NILEXPR, oper, *expp); + NILEXPR, oper, *expp); break; case '!': if ((*expp)->ex_type->tp_fund == FUNCTION) @@ -116,7 +122,7 @@ ch7mon(oper, expp) opnd2test(expp, '!'); if (is_cp_cst(*expp)) { (*expp)->VL_VALUE = !((*expp)->VL_VALUE); - (*expp)->ex_type = int_type; + (*expp)->ex_type = int_type; /* a cast ???(EB) */ } else *expp = new_oper(int_type, NILEXPR, oper, *expp); diff --git a/lang/cem/cemcom/ival.c b/lang/cem/cemcom/ival.c index ff52c496..201c5028 100644 --- a/lang/cem/cemcom/ival.c +++ b/lang/cem/cemcom/ival.c @@ -32,12 +32,12 @@ struct expr *do_array(), *do_struct(), *IVAL(); of type tp with the initialisation expression expr by calling IVAL(). Guided by type tp, the expression is evaluated. */ -do_ival(tpp, expr) +do_ival(tpp, ex) struct type **tpp; - struct expr *expr; + struct expr *ex; { - if (IVAL(tpp, expr) != 0) - too_many_initialisers(expr); + if (IVAL(tpp, ex) != 0) + too_many_initialisers(ex); } /* IVAL() recursively guides the initialisation expression through the @@ -52,9 +52,9 @@ do_ival(tpp, expr) IVAL() returns a pointer to the remaining expression tree. */ struct expr * -IVAL(tpp, expr) +IVAL(tpp, ex) struct type **tpp; /* type of global variable */ - struct expr *expr; /* initialiser expression */ + struct expr *ex; /* initialiser expression */ { register struct type *tp = *tpp; @@ -63,22 +63,22 @@ IVAL(tpp, expr) /* array initialisation */ if (valid_type(tp->tp_up, "array element") == 0) return 0; - if (ISCOMMA(expr)) /* list of initialisation expressions */ - return do_array(expr, tpp); + if (ISCOMMA(ex)) /* list of initialisation expressions */ + return do_array(ex, tpp); /* catch initialisations like char s[] = "I am a string" */ - if (tp->tp_up->tp_fund == CHAR && expr->ex_class == String) - init_string(tpp, expr); + if (tp->tp_up->tp_fund == CHAR && ex->ex_class == String) + init_string(tpp, ex); else /* " int i[24] = 12;" */ - check_and_pad(expr, tpp); + check_and_pad(ex, tpp); break; case STRUCT: /* struct initialisation */ if (valid_type(tp, "struct") == 0) return 0; - if (ISCOMMA(expr)) /* list of initialisation expressions */ - return do_struct(expr, tp); + if (ISCOMMA(ex)) /* list of initialisation expressions */ + return do_struct(ex, tp); /* "struct foo f = 12;" */ - check_and_pad(expr, tpp); + check_and_pad(ex, tpp); break; case UNION: error("union initialisation not allowed"); @@ -86,17 +86,17 @@ IVAL(tpp, expr) case ERRONEOUS: break; default: /* fundamental type */ - if (ISCOMMA(expr)) { /* " int i = {12};" */ - if (IVAL(tpp, expr->OP_LEFT) != 0) - too_many_initialisers(expr); + if (ISCOMMA(ex)) { /* " int i = {12};" */ + if (IVAL(tpp, ex->OP_LEFT) != 0) + too_many_initialisers(ex); /* return remainings of the list for the other members of the aggregate, if this item belongs to an aggregate. */ - return expr->OP_RIGHT; + return ex->OP_RIGHT; } /* "int i = 12;" */ - check_ival(expr, tp); + check_ival(ex, tp); break; } return 0; @@ -115,14 +115,14 @@ IVAL(tpp, expr) members are padded with zeroes */ struct expr * -do_array(expr, tpp) - struct expr *expr; +do_array(ex, tpp) + struct expr *ex; struct type **tpp; { register struct type *tp = *tpp; register arith elem_count; - ASSERT(tp->tp_fund == ARRAY && ISCOMMA(expr)); + ASSERT(tp->tp_fund == ARRAY && ISCOMMA(ex)); /* the following test catches initialisations like char c[] = {"just a string"}; or @@ -132,7 +132,7 @@ do_array(expr, tpp) is completely foolish, we did it!! (no applause, thank you) */ if (tp->tp_up->tp_fund == CHAR) { - register struct expr *f = expr->OP_LEFT; + register struct expr *f = ex->OP_LEFT; register struct expr *g = 0; while (ISCOMMA(f)) { /* eat the brackets!!! */ @@ -141,28 +141,28 @@ do_array(expr, tpp) } if (f->ex_class == String) { /* hallelujah, it's a string! */ init_string(tpp, f); - return g ? g->OP_RIGHT : expr->OP_RIGHT; + return g ? g->OP_RIGHT : ex->OP_RIGHT; } /* else: just go on with the next part of this function */ if (g != 0) - expr = g; + ex = g; } if (tp->tp_size == (arith)-1) { /* declared with unknown size: [] */ - for (elem_count = 0; expr; elem_count++) { + for (elem_count = 0; ex; elem_count++) { /* eat whole initialisation expression */ - if (ISCOMMA(expr->OP_LEFT)) { + if (ISCOMMA(ex->OP_LEFT)) { /* the member expression is embraced */ - if (IVAL(&(tp->tp_up), expr->OP_LEFT) != 0) - too_many_initialisers(expr); - expr = expr->OP_RIGHT; + if (IVAL(&(tp->tp_up), ex->OP_LEFT) != 0) + too_many_initialisers(ex); + ex = ex->OP_RIGHT; } else { if (aggregate_type(tp->tp_up)) - expr = IVAL(&(tp->tp_up), expr); + ex = IVAL(&(tp->tp_up), ex); else { - check_ival(expr->OP_LEFT, tp->tp_up); - expr = expr->OP_RIGHT; + check_ival(ex->OP_LEFT, tp->tp_up); + ex = ex->OP_RIGHT; } } } @@ -172,30 +172,30 @@ do_array(expr, tpp) else { /* the number of members is already known */ arith dim = tp->tp_size / tp->tp_up->tp_size; - for (elem_count = 0; elem_count < dim && expr; elem_count++) { - if (ISCOMMA(expr->OP_LEFT)) { + for (elem_count = 0; elem_count < dim && ex; elem_count++) { + if (ISCOMMA(ex->OP_LEFT)) { /* embraced member initialisation */ - if (IVAL(&(tp->tp_up), expr->OP_LEFT) != 0) - too_many_initialisers(expr); - expr = expr->OP_RIGHT; + if (IVAL(&(tp->tp_up), ex->OP_LEFT) != 0) + too_many_initialisers(ex); + ex = ex->OP_RIGHT; } else { if (aggregate_type(tp->tp_up)) /* the member is an aggregate */ - expr = IVAL(&(tp->tp_up), expr); + ex = IVAL(&(tp->tp_up), ex); else { - check_ival(expr->OP_LEFT, tp->tp_up); - expr = expr->OP_RIGHT; + check_ival(ex->OP_LEFT, tp->tp_up); + ex = ex->OP_RIGHT; } } } - if (expr && elem_count == dim) + if (ex && elem_count == dim) /* all the members are initialised but there remains a part of the expression tree which is returned */ - return expr; - if ((expr == 0) && elem_count < dim) { + return ex; + if ((ex == 0) && elem_count < dim) { /* the expression tree is completely absorbed but there are still members which must be initialised with zeroes @@ -214,31 +214,31 @@ do_array(expr, tpp) during which alignment is taken care of. */ struct expr * -do_struct(expr, tp) - struct expr *expr; +do_struct(ex, tp) + struct expr *ex; struct type *tp; { struct sdef *sd = tp->tp_sdef; arith bytes_upto_here = (arith)0; arith last_offset = (arith)-1; - ASSERT(tp->tp_fund == STRUCT && ISCOMMA(expr)); + ASSERT(tp->tp_fund == STRUCT && ISCOMMA(ex)); /* as long as there are selectors and there is an initialiser.. */ - while (sd && expr) { - if (ISCOMMA(expr->OP_LEFT)) { /* embraced expression */ - if (IVAL(&(sd->sd_type), expr->OP_LEFT) != 0) - too_many_initialisers(expr); - expr = expr->OP_RIGHT; + while (sd && ex) { + if (ISCOMMA(ex->OP_LEFT)) { /* embraced expression */ + if (IVAL(&(sd->sd_type), ex->OP_LEFT) != 0) + too_many_initialisers(ex); + ex = ex->OP_RIGHT; } else { if (aggregate_type(sd->sd_type)) /* selector is an aggregate itself */ - expr = IVAL(&(sd->sd_type), expr); + ex = IVAL(&(sd->sd_type), ex); else { #ifdef NOBITFIELD /* fundamental type, not embraced */ - check_ival(expr->OP_LEFT, sd->sd_type); - expr = expr->OP_RIGHT; + check_ival(ex->OP_LEFT, sd->sd_type); + ex = ex->OP_RIGHT; #else if (is_anon_idf(sd->sd_idf)) /* a hole in the struct due to @@ -248,9 +248,9 @@ do_struct(expr, tp) put_bf(sd->sd_type, (arith)0); else { /* fundamental type, not embraced */ - check_ival(expr->OP_LEFT, + check_ival(ex->OP_LEFT, sd->sd_type); - expr = expr->OP_RIGHT; + ex = ex->OP_RIGHT; } #endif NOBITFIELD } @@ -266,8 +266,8 @@ do_struct(expr, tp) } sd = sd->sd_sdef; } - /* perfect fit if (expr && (sd == 0)) holds */ - if ((expr == 0) && (sd != 0)) { + /* perfect fit if (ex && (sd == 0)) holds */ + if ((ex == 0) && (sd != 0)) { /* there are selectors left which must be padded with zeroes */ @@ -284,7 +284,7 @@ do_struct(expr, tp) /* keep on aligning... */ while (bytes_upto_here++ < tp->tp_size) con_nullbyte(); - return expr; + return ex; } /* check_and_pad() is given a simple initialisation expression @@ -292,17 +292,17 @@ do_struct(expr, tp) In the latter case, only the first member is initialised and the rest is zeroed. */ -check_and_pad(expr, tpp) - struct expr *expr; +check_and_pad(ex, tpp) + struct expr *ex; struct type **tpp; { - /* expr is of a fundamental type */ + /* ex is of a fundamental type */ struct type *tp = *tpp; if (tp->tp_fund == ARRAY) { if (valid_type(tp->tp_up, "array element") == 0) return; - check_and_pad(expr, &(tp->tp_up)); /* first member */ + check_and_pad(ex, &(tp->tp_up)); /* first member */ if (tp->tp_size == (arith)-1) /* no size specified upto here: just set it to the size of one member. @@ -321,7 +321,7 @@ check_and_pad(expr, tpp) if (valid_type(tp, "struct") == 0) return; - check_and_pad(expr, &(sd->sd_type)); + check_and_pad(ex, &(sd->sd_type)); /* Next selector is aligned by adding extra zeroes */ if (sd->sd_sdef) zero_bytes(sd); @@ -332,7 +332,7 @@ check_and_pad(expr, tpp) } } else /* simple type */ - check_ival(expr, tp); + check_ival(ex, tp); } /* pad() fills an element of type tp with zeroes. @@ -404,9 +404,9 @@ pad(tp) No further comment is needed to explain the internal structure of this straightforward function. */ -check_ival(expr, type) - struct expr *expr; - struct type *type; +check_ival(ex, tp) + struct expr *ex; + struct type *tp; { /* The philosophy here is that ch7cast puts an explicit conversion node in front of the expression if the types @@ -414,88 +414,81 @@ check_ival(expr, type) expression is no longer a constant. */ - switch (type->tp_fund) { + switch (tp->tp_fund) { case CHAR: case SHORT: case INT: case LONG: case ENUM: - ch7cast(&expr, '=', type); - if (is_cp_cst(expr)) - con_int(expr); + case POINTER: + ch7cast(&ex, '=', tp); +#ifdef DEBUG + print_expr("init-expr after cast", ex); +#endif DEBUG + if (!is_ld_cst(ex)) + illegal_init_cst(ex); else - illegal_init_cst(expr); - break; -#ifndef NOBITFIELD - case FIELD: - ch7cast(&expr, '=', type->tp_up); - if (is_cp_cst(expr)) - put_bf(type, expr->VL_VALUE); + if (ex->VL_CLASS == Const) + con_int(ex); else - illegal_init_cst(expr); + if (ex->VL_CLASS == Name) { + register struct idf *id = ex->VL_IDF; + register struct def *df = id->id_def; + + if (df->df_level >= L_LOCAL) + illegal_init_cst(ex); + else /* e.g., int f(); int p = f; */ + if (df->df_type->tp_fund == FUNCTION) + C_con_pnam(id->id_text); + else /* e.g., int a; int *p = &a; */ + C_con_dnam(id->id_text, ex->VL_VALUE); + } + else { + ASSERT(ex->VL_CLASS == Label); + C_con_dlb(ex->VL_LBL, ex->VL_VALUE); + } break; -#endif NOBITFIELD case FLOAT: case DOUBLE: - ch7cast(&expr, '=', type); - if (expr->ex_class == Float) - C_con_fcon(expr->FL_VALUE, expr->ex_type->tp_size); + ch7cast(&ex, '=', tp); +#ifdef DEBUG + print_expr("init-expr after cast", ex); +#endif DEBUG + if (ex->ex_class == Float) + C_con_fcon(ex->FL_VALUE, ex->ex_type->tp_size); else - if (expr->ex_class == Oper && expr->OP_OPER == INT2FLOAT) { - expr = expr->OP_RIGHT; - if (is_cp_cst(expr)) + if (ex->ex_class == Oper && ex->OP_OPER == INT2FLOAT) { + /* float f = 1; */ + ex = ex->OP_RIGHT; + if (is_cp_cst(ex)) C_con_fcon( - long2str((long)expr->VL_VALUE, 10), - type->tp_size + long2str((long)ex->VL_VALUE, 10), + tp->tp_size ); else - illegal_init_cst(expr); + illegal_init_cst(ex); } else - illegal_init_cst(expr); + illegal_init_cst(ex); break; - case POINTER: - ch7cast(&expr, '=', type); - switch (expr->ex_class) { - case Oper: - illegal_init_cst(expr); - break; - case Value: - { - ASSERT(expr->ex_type->tp_fund == POINTER); - if (expr->ex_type->tp_up->tp_fund == FUNCTION) { - if (expr->VL_CLASS == Name) - C_con_pnam(expr->VL_IDF->id_text); - else /* int (*func)() = 0 */ - con_int(expr); - } - else - if (expr->VL_CLASS == Name) { - register struct idf *id = expr->VL_IDF; - if (id ->id_def->df_level >= L_LOCAL) - expr_error(expr, - "illegal initialisation"); - else - C_con_dnam(id->id_text, expr->VL_VALUE); - } - else - if (expr->VL_CLASS == Label) - C_con_dlb(expr->VL_LBL, expr->VL_VALUE); - else - con_int(expr); - break; - } - case String: - default: - crash("(check_ival) illegal value class"); - } +#ifndef NOBITFIELD + case FIELD: + ch7cast(&ex, '=', tp->tp_up); +#ifdef DEBUG + print_expr("init-expr after cast", ex); +#endif DEBUG + if (is_cp_cst(ex)) + put_bf(tp, ex->VL_VALUE); + else + illegal_init_cst(ex); break; +#endif NOBITFIELD + case ERRONEOUS: break; default: - crash("(check_ival) bad fundamental type %s", - symbol2str(type->tp_fund)); + crash("check_ival"); } } @@ -503,17 +496,17 @@ check_ival(expr, type) a string constant. Alignment is taken care of. */ -init_string(tpp, expr) +init_string(tpp, ex) struct type **tpp; /* type tp = array of characters */ - struct expr *expr; + struct expr *ex; { register struct type *tp = *tpp; register arith length; - char *s = expr->SG_VALUE; + char *s = ex->SG_VALUE; arith ntopad; - ASSERT(expr->ex_class == String); - length = expr->SG_LEN; + ASSERT(ex->ex_class == String); + length = ex->SG_LEN; if (tp->tp_size == (arith)-1) { /* set the dimension */ tp = *tpp = construct_type(ARRAY, tp->tp_up, length); @@ -524,7 +517,7 @@ init_string(tpp, expr) ntopad = align(dim, word_align) - length; if (length > dim) - expr_error(expr, + expr_error(ex, "too many characters in initialiser string"); } /* throw out the characters of the already prepared string */ diff --git a/lang/cem/cemcom/options b/lang/cem/cemcom/options index 378a540b..dc432c55 100644 --- a/lang/cem/cemcom/options +++ b/lang/cem/cemcom/options @@ -1,5 +1,4 @@ User options: - C while running preprocessor, copy comment D see identifier following as a macro E run preprocessor only From 2118a5eea0fb48b60a3d2093a33b28e526b7c69d Mon Sep 17 00:00:00 2001 From: erikb Date: Thu, 3 Apr 1986 14:32:56 +0000 Subject: [PATCH 0163/1625] adapted to print(3L) module --- lang/cem/cemcom/Files | 1 - lang/cem/cemcom/Makefile.erik | 17 +++--- lang/cem/cemcom/Parameters | 4 -- lang/cem/cemcom/alloc.c | 2 +- lang/cem/cemcom/dataflow.c | 7 ++- lang/cem/cemcom/dumpidf.c | 98 +++++++++++++++++------------------ lang/cem/cemcom/error.c | 6 +-- lang/cem/cemcom/idf.c | 10 ++-- lang/cem/cemcom/main.c | 23 ++++---- lang/cem/cemcom/stack.c | 2 +- lang/cem/cemcom/struct.c | 26 +++------- 11 files changed, 87 insertions(+), 109 deletions(-) diff --git a/lang/cem/cemcom/Files b/lang/cem/cemcom/Files index 125c0c28..9b7abae1 100644 --- a/lang/cem/cemcom/Files +++ b/lang/cem/cemcom/Files @@ -33,7 +33,6 @@ decspecs.c decspecs.str def.str domacro.c -doprnt.c dumpidf.c error.c eval.c diff --git a/lang/cem/cemcom/Makefile.erik b/lang/cem/cemcom/Makefile.erik index aa63546d..ca62a8f1 100644 --- a/lang/cem/cemcom/Makefile.erik +++ b/lang/cem/cemcom/Makefile.erik @@ -12,9 +12,10 @@ SYSLIB = /user1/erikb/em/lib/libsystem.a EMKLIB = /user1/erikb/em/lib/libemk.a EMELIB = /user1/erikb/em/lib/libeme.a STRLIB = /user1/erikb/em/lib/libstr.a +PRTLIB = /user1/erikb/em/lib/libprint.a EMMESLIB = /user1/erikb/em/lib/libem_mes.a -LIBS = $(EMMESLIB) $(EMKLIB) $(STRLIB) $(SYSLIB) -ELIBS = $(EMMESLIB) $(EMELIB) $(STRLIB) $(SYSLIB) +LIBS = $(EMMESLIB) $(EMKLIB) $(PRTLIB) $(STRLIB) $(SYSLIB) +ELIBS = $(EMMESLIB) $(EMELIB) $(PRTLIB) $(STRLIB) $(SYSLIB) LIB_INCLUDES = /user1/erikb/em/h # Where to install the compiler and its driver @@ -47,7 +48,7 @@ COBJ = main.o idf.o declarator.o decspecs.o struct.o \ input.o domacro.o replace.o init.o options.o \ scan.o skip.o stack.o type.o ch7mon.o label.o eval.o \ switch.o storage.o ival.o conversion.o \ - blocks.o dataflow.o doprnt.o + blocks.o dataflow.o # Objects of other generated C files GOBJ = char.o symbol2str.o next.o @@ -62,8 +63,7 @@ GHSRC = botch_free.h dataflow.h debug.h density.h errout.h \ idepth.h idfsize.h ifdepth.h inputtype.h inumlength.h lapbuf.h \ maxincl.h myalloc.h nobitfield.h nopp.h \ nparams.h numsize.h parbufsize.h pathlength.h predefine.h \ - strsize.h target_sizes.h textsize.h use_tmp.h \ - ssize.h spec_arith.h + strsize.h target_sizes.h textsize.h use_tmp.h spec_arith.h # Other generated files, for 'make clean' only GENERATED = tab tokenfile.g Lpars.h LLfiles LL.output lint.out \ @@ -191,15 +191,15 @@ sim: cfiles $(SIM) $(SIMFLAGS) `sources $(COBJ)` $(GSRC) $(LSRC) #AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO -main.o: LLlex.h Lpars.h alloc.h arith.h debug.h declar.h idf.h input.h inputtype.h level.h maxincl.h myalloc.h nobitfield.h nopp.h spec_arith.h specials.h target_sizes.h tokenname.h type.h use_tmp.h ssize.h +main.o: LLlex.h Lpars.h alloc.h arith.h debug.h declar.h idf.h input.h inputtype.h level.h maxincl.h myalloc.h nobitfield.h nopp.h spec_arith.h specials.h target_sizes.h tokenname.h type.h use_tmp.h idf.o: LLlex.h Lpars.h align.h alloc.h arith.h assert.h botch_free.h debug.h declar.h decspecs.h def.h idf.h idfsize.h label.h level.h nobitfield.h nopp.h sizes.h spec_arith.h specials.h stack.h storage.h struct.h type.h declarator.o: Lpars.h alloc.h arith.h botch_free.h declar.h expr.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h type.h decspecs.o: Lpars.h arith.h decspecs.h def.h level.h nobitfield.h spec_arith.h type.h struct.o: LLlex.h Lpars.h align.h arith.h assert.h botch_free.h debug.h def.h field.h idf.h level.h nobitfield.h nopp.h sizes.h spec_arith.h stack.h storage.h struct.h type.h -expr.o: LLlex.h Lpars.h alloc.h arith.h botch_free.h declar.h decspecs.h def.h expr.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h type.h level.h +expr.o: LLlex.h Lpars.h alloc.h arith.h botch_free.h declar.h decspecs.h def.h expr.h idf.h label.h level.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h type.h ch7.o: Lpars.h arith.h assert.h debug.h def.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h struct.h type.h ch7bin.o: Lpars.h arith.h botch_free.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h storage.h struct.h type.h -cstoper.o: Lpars.h arith.h expr.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h target_sizes.h type.h assert.h +cstoper.o: Lpars.h arith.h assert.h debug.h expr.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h target_sizes.h type.h arith.o: Lpars.h alloc.h arith.h botch_free.h expr.h field.h idf.h label.h mes.h nobitfield.h nopp.h spec_arith.h storage.h type.h alloc.o: alloc.h assert.h debug.h myalloc.h code.o: LLlex.h Lpars.h alloc.h arith.h assert.h atw.h botch_free.h code.h dataflow.h debug.h declar.h decspecs.h def.h expr.h idf.h label.h level.h mes.h nobitfield.h nopp.h sizes.h spec_arith.h specials.h stack.h storage.h type.h use_tmp.h @@ -227,7 +227,6 @@ ival.o: Lpars.h align.h arith.h assert.h class.h debug.h def.h expr.h field.h id conversion.o: Lpars.h arith.h nobitfield.h sizes.h spec_arith.h type.h blocks.o: arith.h atw.h sizes.h spec_arith.h dataflow.o: dataflow.h -doprnt.o: ssize.h tokenfile.o: Lpars.h declar.o: LLlex.h Lpars.h arith.h debug.h declar.h decspecs.h def.h expr.h field.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h struct.h type.h statement.o: LLlex.h Lpars.h arith.h botch_free.h code.h debug.h def.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h stack.h storage.h type.h diff --git a/lang/cem/cemcom/Parameters b/lang/cem/cemcom/Parameters index 00cae78f..3744c69b 100644 --- a/lang/cem/cemcom/Parameters +++ b/lang/cem/cemcom/Parameters @@ -122,10 +122,6 @@ #undef NOBITFIELD 1 /* implement bitfields */ -!File: ssize.h -#define SSIZE 1024 /* string-buffer size for print routines */ - - !File: spec_arith.h /* describes internal compiler arithmetics */ #undef SPECIAL_ARITHMETICS /* something different from native long */ diff --git a/lang/cem/cemcom/alloc.c b/lang/cem/cemcom/alloc.c index b7f4df85..cb431a4b 100644 --- a/lang/cem/cemcom/alloc.c +++ b/lang/cem/cemcom/alloc.c @@ -152,7 +152,7 @@ mem_stat() extern char options[]; if (options['m']) - printf("Total nr of bytes allocated: %d\n", + print("Total nr of bytes allocated: %d\n", sys_break(0) - firstfreeb); } #endif DEBUG diff --git a/lang/cem/cemcom/dataflow.c b/lang/cem/cemcom/dataflow.c index 7d1d8836..92fe1424 100644 --- a/lang/cem/cemcom/dataflow.c +++ b/lang/cem/cemcom/dataflow.c @@ -20,15 +20,14 @@ DfaStartFunction(nm) DfaEndFunction() { - if (NumberOfCalls == 0) { - printf("DFA: %s: --none--\n", CurrentFunction); - } + if (NumberOfCalls == 0) + print("DFA: %s: --none--\n", CurrentFunction); } DfaCallFunction(s) char *s; { - printf("DFA: %s: %s\n", CurrentFunction, s); + print("DFA: %s: %s\n", CurrentFunction, s); ++NumberOfCalls; } #endif DATAFLOW diff --git a/lang/cem/cemcom/dumpidf.c b/lang/cem/cemcom/dumpidf.c index cd7e4694..77c8f5ea 100644 --- a/lang/cem/cemcom/dumpidf.c +++ b/lang/cem/cemcom/dumpidf.c @@ -29,7 +29,7 @@ extern char options[]; -extern char *sprintf(); +extern char *sprint(); extern struct idf *idf_hashtable[]; extern char *symbol2str(), *type2str(), *next_transient(); @@ -42,13 +42,13 @@ static newline() { int dl = dumplevel; - printf("\n"); + print("\n"); while (dl >= 2) { - printf("\t"); + print("\t"); dl -= 2; } if (dl) - printf(" "); + print(" "); } dumpidftab(msg, opt) @@ -62,7 +62,7 @@ dumpidftab(msg, opt) */ int i; - printf(">>> DUMPIDF, %s (start)", msg); + print(">>> DUMPIDF, %s (start)", msg); dumpstack(); for (i = 0; i < HASHSIZE; i++) { struct idf *notch = idf_hashtable[i]; @@ -73,7 +73,7 @@ dumpidftab(msg, opt) } } newline(); - printf(">>> DUMPIDF, %s (end)\n", msg); + print(">>> DUMPIDF, %s (end)\n", msg); } dumpstack() { @@ -85,14 +85,14 @@ dumpstack() { struct stack_entry *se = stl->sl_entry; newline(); - printf("%3d: ", stl->sl_level); + print("%3d: ", stl->sl_level); while (se) { - printf("%s ", se->se_idf->id_text); + print("%s ", se->se_idf->id_text); se = se->next; } stl = stl->sl_previous; } - printf("\n"); + print("\n"); } dumpidf(idf, opt) @@ -109,43 +109,43 @@ dumpidf(idf, opt) if ((opt&1) && idf->id_macro) { if (!started++) { newline(); - printf("%s:", idf->id_text); + print("%s:", idf->id_text); } - printf(" macro"); + print(" macro"); } #endif NOPP if ((opt&2) && idf->id_reserved) { if (!started++) { newline(); - printf("%s:", idf->id_text); + print("%s:", idf->id_text); } - printf(" reserved: %d;", idf->id_reserved); + print(" reserved: %d;", idf->id_reserved); } if (idf->id_def && ((opt&4) || idf->id_def->df_level)) { if (!started++) { newline(); - printf("%s:", idf->id_text); + print("%s:", idf->id_text); } dumpdefs(idf->id_def, opt); } if (idf->id_sdef) { if (!started++) { newline(); - printf("%s:", idf->id_text); + print("%s:", idf->id_text); } dumpsdefs(idf->id_sdef, selector); } if (idf->id_struct) { if (!started++) { newline(); - printf("%s:", idf->id_text); + print("%s:", idf->id_text); } dumptags(idf->id_struct); } if (idf->id_enum) { if (!started++) { newline(); - printf("%s:", idf->id_text); + print("%s:", idf->id_text); } dumptags(idf->id_enum); } @@ -157,7 +157,7 @@ dumpdefs(def, opt) dumplevel++; while (def && ((opt&4) || def->df_level)) { newline(); - printf("L%d: %s %s%s%s%s%s %lo;", + print("L%d: %s %s%s%s%s%s %lo;", def->df_level, symbol2str(def->df_sc), (def->df_register != REG_NONE) ? "reg " : "", @@ -181,7 +181,7 @@ dumptags(tag) register int fund = tp->tp_fund; newline(); - printf("L%d: %s %s", + print("L%d: %s %s", tag->tg_level, fund == STRUCT ? "struct" : fund == UNION ? "union" : @@ -189,12 +189,12 @@ dumptags(tag) tp->tp_idf->id_text ); if (is_struct_or_union(fund)) { - printf(" {"); + print(" {"); dumpsdefs(tp->tp_sdef, field); newline(); - printf("}"); + print("}"); } - printf(";"); + print(";"); tag = tag->next; } dumplevel--; @@ -214,16 +214,16 @@ dumpsdefs(sdef, sdk) dumplevel++; while (sdef) { newline(); - printf("L%d: ", sdef->sd_level); + print("L%d: ", sdef->sd_level); #ifndef NOBITFIELD if (sdk == selector) #endif NOBITFIELD - printf("selector %s at offset %lu in %s;", + print("selector %s at offset %lu in %s;", type2str(sdef->sd_type), sdef->sd_offset, type2str(sdef->sd_stype) ); #ifndef NOBITFIELD - else printf("field %s at offset %lu;", + else print("field %s at offset %lu;", type2str(sdef->sd_type), sdef->sd_offset ); #endif NOBITFIELD @@ -243,35 +243,35 @@ type2str(tp) buf[0] = '\0'; if (!tp) { - sprintf(buf, ""); + sprint(buf, ""); return buf; } - sprintf(buf, "(@%lx, #%ld, &%d) ", + sprint(buf, "(@%lx, #%ld, &%d) ", tp, (long)tp->tp_size, tp->tp_align); while (ops) { switch (tp->tp_fund) { case POINTER: - sprintf(buf, "%spointer to ", buf); + sprint(buf, "%spointer to ", buf); break; case ARRAY: - sprintf(buf, "%sarray [%ld] of ", buf, tp->tp_size); + sprint(buf, "%sarray [%ld] of ", buf, tp->tp_size); break; case FUNCTION: - sprintf(buf, "%sfunction yielding ", buf); + sprint(buf, "%sfunction yielding ", buf); break; default: - sprintf(buf, "%s%s%s", buf, + sprint(buf, "%s%s%s", buf, tp->tp_unsigned ? "unsigned " : "", symbol2str(tp->tp_fund) ); if (tp->tp_idf) - sprintf(buf, "%s %s", buf, + sprint(buf, "%s %s", buf, tp->tp_idf->id_text); #ifndef NOBITFIELD if (tp->tp_field) { struct field *fd = tp->tp_field; - sprintf(buf, "%s [s=%ld,w=%ld]", buf, + sprint(buf, "%s [s=%ld,w=%ld]", buf, fd->fd_shift, fd->fd_width); } #endif NOBITFIELD @@ -302,8 +302,8 @@ print_expr(msg, expr) message msg. */ if (options['x']) { - printf("\n%s: ", msg); - printf("(L=line, T=type, r/lV=r/lvalue, F=flags, D=depth)\n"); + print("\n%s: ", msg); + print("(L=line, T=type, r/lV=r/lvalue, F=flags, D=depth)\n"); p1_expr(0, expr); } } @@ -315,10 +315,10 @@ p1_expr(lvl, expr) p1_indent(lvl); if (!expr) { - printf("NILEXPR\n"); + print("NILEXPR\n"); return; } - printf("expr: L=%u, T=%s, %cV, F=%03o, D=%d, %s: ", + print("expr: L=%u, T=%s, %cV, F=%03o, D=%d, %s: ", expr->ex_line, type2str(expr->ex_type), expr->ex_lvalue ? 'l' : 'r', @@ -335,52 +335,52 @@ p1_expr(lvl, expr) case Value: switch (expr->VL_CLASS) { case Const: - printf("(Const) "); + print("(Const) "); break; case Name: - printf("(Name) %s + ", expr->VL_IDF->id_text); + print("(Name) %s + ", expr->VL_IDF->id_text); break; case Label: - printf("(Label) .%lu + ", expr->VL_LBL); + print("(Label) .%lu + ", expr->VL_LBL); break; default: - printf("(Unknown) "); + print("(Unknown) "); break; } - printf(expr->ex_type->tp_unsigned ? "%lu\n" : "%ld\n", + print(expr->ex_type->tp_unsigned ? "%lu\n" : "%ld\n", expr->VL_VALUE); break; case String: { char bts2str(); - printf( + print( "%s\n", bts2str(expr->SG_VALUE, expr->SG_LEN, next_transient()) ); break; } case Float: - printf("%s\n", expr->FL_VALUE); + print("%s\n", expr->FL_VALUE); break; case Oper: o = &expr->ex_object.ex_oper; - printf("\n"); + print("\n"); p1_expr(lvl+1, o->op_left); - p1_indent(lvl); printf("%s\n", symbol2str(o->op_oper)); + p1_indent(lvl); print("%s\n", symbol2str(o->op_oper)); p1_expr(lvl+1, o->op_right); break; case Type: - printf("\n"); + print("\n"); break; default: - printf("UNKNOWN CLASS\n"); + print("UNKNOWN CLASS\n"); break; } } p1_indent(lvl) { while (lvl--) - printf(" "); + print(" "); } #endif DEBUG diff --git a/lang/cem/cemcom/error.c b/lang/cem/cemcom/error.c index 0917808d..054ee73b 100644 --- a/lang/cem/cemcom/error.c +++ b/lang/cem/cemcom/error.c @@ -209,9 +209,9 @@ _error(class, expr, fmt, argv) } if (fn) - fprintf(ERROUT, "\"%s\", line %u: ", fn, ln); + fprint(ERROUT, "\"%s\", line %u: ", fn, ln); if (remark) - fprintf(ERROUT, "%s ", remark); + fprint(ERROUT, "%s ", remark); doprnt(ERROUT, fmt, argv); /* contents of error */ - fprintf(ERROUT, "\n"); + fprint(ERROUT, "\n"); } diff --git a/lang/cem/cemcom/idf.c b/lang/cem/cemcom/idf.c index c6d4eed3..b948e206 100644 --- a/lang/cem/cemcom/idf.c +++ b/lang/cem/cemcom/idf.c @@ -88,7 +88,7 @@ hash_stat() if (options['h']) { int i; - printf("Hash table tally:\n"); + print("Hash table tally:\n"); for (i = 0; i < HASHSIZE; i++) { struct idf *notch = idf_hashtable[i]; int cnt = 0; @@ -97,9 +97,9 @@ hash_stat() cnt++; notch = notch->next; } - printf("%d %d\n", i, cnt); + print("%d %d\n", i, cnt); } - printf("End hash table tally\n"); + print("End hash table tally\n"); } } #endif DEBUG @@ -139,9 +139,9 @@ gen_idf() */ static int name_cnt; char buff[100]; - char *sprintf(); + char *sprint(); - sprintf(buff, "#%d in %s, line %u", + sprint(buff, "#%d in %s, line %u", ++name_cnt, dot.tk_file, dot.tk_line); return str2idf(buff); } diff --git a/lang/cem/cemcom/main.c b/lang/cem/cemcom/main.c index 685f7830..0cf9425d 100644 --- a/lang/cem/cemcom/main.c +++ b/lang/cem/cemcom/main.c @@ -21,7 +21,6 @@ #include "LLlex.h" #include "alloc.h" #include "specials.h" -#include "ssize.h" extern struct tokenname tkidf[], tkother[]; extern char *symbol2str(); @@ -296,12 +295,12 @@ preprocess() if (strcmp(lastfilenm, dot.tk_file) == 0) { if (dot.tk_line - lastlineno <= 1) { lastlineno++; - printf("\n"); + print("\n"); } else { lastlineno = dot.tk_line; if (!options['P']) - printf("\n#line %ld \"%s\"\n", + print("\n#line %ld \"%s\"\n", lastlineno, lastfilenm ); @@ -311,7 +310,7 @@ preprocess() lastfilenm = dot.tk_file; lastlineno = dot.tk_line; if (!options['P']) - printf("\n#line %ld \"%s\"\n", + print("\n#line %ld \"%s\"\n", lastlineno, lastfilenm); } } @@ -319,35 +318,33 @@ preprocess() if (strcmp(lastfilenm, dot.tk_file) != 0) { lastfilenm = dot.tk_file; if (!options['P']) - printf("\n#line %ld \"%s\"\n", + print("\n#line %ld \"%s\"\n", lastlineno, lastfilenm); } switch (DOT) { case IDENTIFIER: case TYPE_IDENTIFIER: - printf(dot.tk_idf->id_text); - printf(" "); + print("%s ", dot.tk_idf->id_text); break; case STRING: { - char sbuf[SSIZE]; + char sbuf[1024]; /* a transient buffer */ char *bts2str(); - printf("\"%s\" ", - bts2str(dot.tk_bts, dot.tk_len, sbuf)); + print("\"%s\" ", bts2str(dot.tk_bts, dot.tk_len, sbuf)); break; } case INTEGER: - printf("%ld ", dot.tk_ival); + print("%ld ", dot.tk_ival); break; case FLOATING: - printf("%s ", dot.tk_fval); + print("%s ", dot.tk_fval); break; case EOI: case EOF: return; default: /* very expensive... */ - printf("%s ", symbol2str(DOT)); + print("%s ", symbol2str(DOT)); } } } diff --git a/lang/cem/cemcom/stack.c b/lang/cem/cemcom/stack.c index 90e9562a..00b79081 100644 --- a/lang/cem/cemcom/stack.c +++ b/lang/cem/cemcom/stack.c @@ -210,7 +210,7 @@ unstack_world() #ifdef DEBUG if (options['a']) { - printf("\"%s\", %s, %s, %s\n", + print("\"%s\", %s, %s, %s\n", idf->id_text, (def->df_alloc == 0) ? "no alloc" : (def->df_alloc == ALLOC_SEEN) ? "alloc seen" : diff --git a/lang/cem/cemcom/struct.c b/lang/cem/cemcom/struct.c index 1fde0f76..b7e266e6 100644 --- a/lang/cem/cemcom/struct.c +++ b/lang/cem/cemcom/struct.c @@ -72,30 +72,17 @@ add_sel(stp, tp, idf, sdefpp, szp, fd) /* this is horrible */ register struct sdef *newsdef; int lvl = tg->tg_level; -/* - * char *type2str(); - * printf("add_sel: \n stp = %s\n tp = %s\n name = %s\n *szp = %ld\n", - * type2str(stp), type2str(tp), idf->id_text, *szp); - * ASSERT(**sdefpp == 0); - * ASSERT(tg->tg_type == stp); - */ - if (options['R'] && !is_anon_idf(idf)) { /* a K & R test */ - if (idf->id_struct && idf->id_struct->tg_level == level - ) { - warning("%s is also a struct/union tag", - idf->id_text); - } + if (idf->id_struct && idf->id_struct->tg_level == level) + warning("%s is also a struct/union tag", idf->id_text); } if (stp->tp_fund == STRUCT) { #ifndef NOBITFIELD if (fd == 0) { /* no field width specified */ -#endif NOBITFIELD offset = align(*szp, tp->tp_align); field_busy = 0; -#ifndef NOBITFIELD } else { /* if something is wrong, the type of the @@ -104,6 +91,9 @@ add_sel(stp, tp, idf, sdefpp, szp, fd) /* this is horrible */ */ offset = add_field(szp, fd, &tp, idf, stp); } +#else NOBITFIELD + offset = align(*szp, tp->tp_align); + field_busy = 0; #endif NOBITFIELD } else { /* (stp->tp_fund == UNION) */ @@ -138,9 +128,8 @@ add_sel(stp, tp, idf, sdefpp, szp, fd) /* this is horrible */ newsdef->sd_offset = offset; #ifndef NOBITFIELD - if (tp->tp_fund == FIELD) { + if (tp->tp_fund == FIELD) tp->tp_field->fd_sdef = newsdef; - } #endif NOBITFIELD stack_idf(idf, stack_level_of(lvl)); @@ -162,9 +151,8 @@ add_sel(stp, tp, idf, sdefpp, szp, fd) /* this is horrible */ if (stp->tp_fund == UNION) { arith sel_size = size_of_type(tp, "member"); - if (*szp < sel_size) { + if (*szp < sel_size) *szp = sel_size; - } stp->tp_align = lcm(stp->tp_align, tp->tp_align); } } From 5cdb2f787e10a3a27aa47c4f497a54870902d672 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 3 Apr 1986 17:41:26 +0000 Subject: [PATCH 0164/1625] newer version, safety commit --- lang/m2/comp/LLlex.c | 15 ++++++----- lang/m2/comp/Makefile | 13 +++++---- lang/m2/comp/def.c | 53 ++++++++++++++++++++++++++++++++++-- lang/m2/comp/enter.c | 2 +- lang/m2/comp/error.c | 8 +++--- lang/m2/comp/expression.g | 3 +-- lang/m2/comp/main.c | 57 +++++++++++++++++++++++++-------------- lang/m2/comp/main.h | 12 ++++++--- lang/m2/comp/misc.c | 15 +++++++++-- lang/m2/comp/program.g | 38 +++++++++++++++++++------- lang/m2/comp/standards.h | 6 ++++- lang/m2/comp/tokenname.c | 2 ++ lang/m2/comp/type.H | 3 ++- lang/m2/comp/type.c | 7 +++-- 14 files changed, 175 insertions(+), 59 deletions(-) diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index dedcca45..0eaa1730 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -19,12 +19,12 @@ long str2long(); struct token dot, aside; -/* Skip Modula-2 like comment (* ... *). - Note that comment may be nested. -*/ static SkipComment() { + /* Skip Modula-2 comments (* ... *). + Note that comments may be nested (par. 3.5). + */ register int ch; register int NestLevel = 0; @@ -62,6 +62,8 @@ SkipComment() static char * GetString(upto) { + /* Read a Modula-2 string, delimited by the character "upto". + */ register int ch; int str_size; char *str = Malloc(str_size = 32); @@ -88,12 +90,12 @@ GetString(upto) return str; } -/* LLlex() plays the role of Lexical Analyzer for the parser. - The putting aside of tokens is taken into account. -*/ int LLlex() { + /* LLlex() plays the role of Lexical Analyzer for the parser. + The putting aside of tokens is taken into account. + */ register struct token *tk = ˙ char buf[(IDFSIZE > NUMSIZE ? IDFSIZE : NUMSIZE) + 1]; register int ch, nch; @@ -378,4 +380,3 @@ Sdec: } /*NOTREACHED*/ } - diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index b88cbb48..211f60ec 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -4,17 +4,20 @@ HDIR = ../../em/h PKGDIR = ../../em/pkg LIBDIR = ../../em/lib + INCLUDES = -I$(HDIR) -I$(PKGDIR) -I/user1/erikb/em/h + LSRC = tokenfile.g program.g declar.g expression.g statement.g CC = cc GEN = LLgen GENOPTIONS = -CFLAGS = -DDEBUG -p $(INCLUDES) -LFLAGS = -p +PROFILE = +CFLAGS = -DDEBUG $(PROFILE) $(INCLUDES) +LFLAGS = $(PROFILE) LOBJ = tokenfile.o program.o declar.o expression.o statement.o COBJ = LLlex.o LLmessage.o char.o error.o main.o \ symbol2str.o tokenname.o idf.o input.o type.o def.o \ - scope.o misc.o print.o enter.o defmodule.o + scope.o misc.o enter.o defmodule.o OBJ = $(COBJ) $(LOBJ) Lpars.o GENFILES= tokenfile.c \ program.c declar.c expression.c statement.c \ @@ -29,7 +32,7 @@ LLfiles: $(LSRC) @touch LLfiles main: $(OBJ) Makefile - $(CC) $(LFLAGS) $(OBJ) $(LIBDIR)/libcomp.a $(LIBDIR)/malloc.o /user1/erikb/em/lib/libstr.a /user1/erikb/em/lib/libsystem.a -o main + $(CC) $(LFLAGS) $(OBJ) $(LIBDIR)/libcomp.a $(LIBDIR)/malloc.o /user1/erikb/em/lib/libprint.a /user1/erikb/em/lib/libstr.a /user1/erikb/em/lib/libsystem.a -o main size main clean: @@ -68,7 +71,7 @@ depend: LLlex.o: LLlex.h Lpars.h class.h f_info.h idf.h input.h LLmessage.o: LLlex.h Lpars.h idf.h char.o: class.h -error.o: LLlex.h f_info.h input.h +error.o: LLlex.h f_info.h input.h main.h main.o: LLlex.h Lpars.h debug.h def.h f_info.h idf.h input.h main.h scope.h standards.h type.h symbol2str.o: Lpars.h tokenname.o: Lpars.h idf.h tokenname.h diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index 9a51998f..231364b1 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -52,7 +52,7 @@ define(id, scope, kind) } break; case D_HIDDEN: - if (kind == D_TYPE && state == IMPLEMENTATION) { + if (kind == D_TYPE && !DefinitionModule) { df->df_kind = D_HTYPE; return df; } @@ -145,7 +145,7 @@ Import(ids, id, local) /* "ids" is a list of imported identifiers. If "id" is a null-pointer, the identifiers are imported from the enclosing scope. Otherwise they are imported from the module - indicated by "id", ehich must be visible in the enclosing scope. + indicated by "id", which must be visible in the enclosing scope. An exception must be made for imports of the Compilation Unit. This case is indicated by the value 0 of the flag "local". In this case, if "id" is a null pointer, the "ids" identifiers @@ -224,3 +224,52 @@ exprt_literals(df, toscope) df = df->enm_next; } } + +RemImports(pdf) + struct def **pdf; +{ + /* Remove all imports from a definition module. This is + neccesary because the implementation module might import + them again. + */ + register struct def *df = *pdf, *df1 = 0; + + while (df) { + if (df->df_kind == D_IMPORT) { + RemFromId(df); + if (df1) { + df1->df_nextinscope = df->df_nextinscope; + free_def(df); + df = df1->df_nextinscope; + } + else { + *pdf = df->df_nextinscope; + free_def(df); + df = *pdf; + } + } + else { + df1 = df; + df = df->df_nextinscope; + } + } +} + +RemFromId(df) + struct def *df; +{ + /* Remove definition "df" from the definition list + */ + register struct idf *id = df->df_idf; + register struct def *df1; + + if (id->id_def == df) id->id_def = df->next; + else { + df1 = id->id_def; + while (df1->next != df) { + assert(df1->next != 0); + df1 = df1->next; + } + df1->next = df->next; + } +} diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index 1912eabd..245e33ea 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -76,6 +76,6 @@ lookfor(id, scope, give_error) if (df) return df; sc = nextvisible(sc); } - if (give_error) error("identifier \"%s\" not declared", id->id_text); + if (give_error) id_not_declared(id); return define(id, scope, D_ERROR); } diff --git a/lang/m2/comp/error.c b/lang/m2/comp/error.c index 1a769bce..d3b23f40 100644 --- a/lang/m2/comp/error.c +++ b/lang/m2/comp/error.c @@ -12,6 +12,7 @@ static char *RcsId = "$Header$"; #include "input.h" #include "f_info.h" #include "LLlex.h" +#include "main.h" #define MAXERR_LINE 5 /* Number of error messages on one line ... */ #define ERROUT STDERR @@ -32,7 +33,6 @@ static char *RcsId = "$Header$"; int err_occurred; extern char *symbol2str(); -extern char options[]; /* There are three general error-message functions: lexerror() lexical and pre-processor error messages @@ -198,10 +198,10 @@ _error(class, expr, fmt, argv) } #endif DEBUG - if (FileName) fprintf(ERROUT, "\"%s\", line %u: ", FileName, ln); + if (FileName) fprint(ERROUT, "\"%s\", line %u: ", FileName, ln); - if (remark) fprintf(ERROUT, "%s ", remark); + if (remark) fprint(ERROUT, "%s ", remark); doprnt(ERROUT, fmt, argv); /* contents of error */ - fprintf(ERROUT, "\n"); + fprint(ERROUT, "\n"); } diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index 7f1c3ca3..d325eac5 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -43,10 +43,9 @@ qualident(int types; struct def **pdf; char *str;) module = (df->df_kind == D_MODULE); df = lookup(dot.TOK_IDF, scope); if (!df) { - error("identifier \"%s\" not declared", - dot.TOK_IDF->id_text); types = 0; df = ill_df; + id_not_declared(dot.TOK_IDF); } else if (module && diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index 8cccad74..caa9c4ee 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -17,12 +17,13 @@ static char *RcsId = "$Header$"; #include "scope.h" #include "standards.h" -char options[128]; -char *ProgName; -int state; +char options[128]; +int DefinitionModule; +int SYSTEMModule = 0; +char *ProgName; extern int err_occurred; -char *DEFPATH[128]; -char *getenv(); +char *DEFPATH[128]; +char *getenv(); main(argc, argv) char *argv[]; @@ -40,11 +41,11 @@ main(argc, argv) } Nargv[Nargc] = 0; /* terminate the arg vector */ if (Nargc != 2) { - fprintf(STDERR, "%s: Use one file argument\n", ProgName); + fprint(STDERR, "%s: Use one file argument\n", ProgName); return 1; } #ifdef DEBUG - printf("Mod2 compiler -- Debug version\n"); + print("Mod2 compiler -- Debug version\n"); #endif DEBUG DO_DEBUG(debug(1,"Debugging level: %d", options['D'])); return !Compile(Nargv[1]); @@ -57,7 +58,7 @@ Compile(src) DO_DEBUG(debug(1,"Filename : %s", src)); if (! InsertFile(src, (char **) 0, &src)) { - fprintf(STDERR,"%s: cannot open %s\n", ProgName, src); + fprint(STDERR,"%s: cannot open %s\n", ProgName, src); return 0; } LineNumber = 1; @@ -92,23 +93,23 @@ LexScan() register int symb; while ((symb = LLlex()) != EOI) { - printf(">>> %s ", symbol2str(symb)); + print(">>> %s ", symbol2str(symb)); switch(symb) { case IDENT: - printf("%s\n", dot.TOK_IDF->id_text); + print("%s\n", dot.TOK_IDF->id_text); break; case INTEGER: - printf("%ld\n", dot.TOK_INT); + print("%ld\n", dot.TOK_INT); break; case REAL: - printf("%s\n", dot.TOK_REL); + print("%s\n", dot.TOK_REL); break; case STRING: - printf("\"%s\"\n", dot.TOK_STR); + print("\"%s\"\n", dot.TOK_STR); break; default: @@ -159,7 +160,7 @@ add_standards() (void) Enter("LONGREAL", D_TYPE, longreal_type, 0); (void) Enter("BOOLEAN", D_TYPE, bool_type, 0); (void) Enter("CARDINAL", D_TYPE, card_type, 0); - (void) Enter("NIL", D_CONST, nil_type, 0); + (void) Enter("NIL", D_CONST, address_type, 0); (void) Enter("PROC", D_TYPE, construct_type(PROCEDURE, NULLTYPE), @@ -196,13 +197,29 @@ do_SYSTEM() { /* Simulate the reading of the SYSTEM definition module */ - struct def *df; - struct idf *sys_id; + char *SYSTEM = "\ +DEFINITION MODULE SYSTEM;\n\ +PROCEDURE NEWPROCESS(P:PROC; A:ADDRESS; n:CARDINAL; VAR p1:ADDRESS);\n\ +PROCEDURE TRANSFER(VAR p1,p2:ADDRESS);\n\ +END SYSTEM.\n"; - sys_id = str2idf("SYSTEM", 0); - df = define(sys_id, GlobalScope, D_MODULE); open_scope(CLOSEDSCOPE, 0); - df->mod_scope = CurrentScope->sc_scope; - /* ???? */ + (void) Enter("WORD", D_TYPE, word_type, 0); + (void) Enter("ADDRESS", D_TYPE, address_type, 0); + (void) Enter("ADR", D_STDFUNC, NULLTYPE, S_ADR); + (void) Enter("TSIZE", D_STDFUNC, NULLTYPE, S_TSIZE); + if (!InsertText(SYSTEM, strlen(SYSTEM))) { + fatal("Could not insert text"); + } + SYSTEMModule = 1; + DefModule(); close_scope(); + SYSTEMModule = 0; +} + +AtEoIT() +{ + /* Make the end of the text noticable + */ + return 1; } diff --git a/lang/m2/comp/main.h b/lang/m2/comp/main.h index 884d2b34..fd4502be 100644 --- a/lang/m2/comp/main.h +++ b/lang/m2/comp/main.h @@ -2,7 +2,13 @@ /* $Header$ */ -extern int - state; /* Indicates what we are compiling: A DEFINITION, - an IMPLEMENTATION, or a PROGRAM module +extern char options[]; /* Indicating which options were given */ + +extern int DefinitionModule; + /* Flag indicating that we are reading a definition + module + */ + +extern int SYSTEMModule;/* Flag indicating that we are handling the SYSTEM + module */ diff --git a/lang/m2/comp/misc.c b/lang/m2/comp/misc.c index 7199fc11..7a543978 100644 --- a/lang/m2/comp/misc.c +++ b/lang/m2/comp/misc.c @@ -48,9 +48,20 @@ gen_anon_idf() */ static int name_cnt; char buff[100]; - char *sprintf(); + char *sprint(); - sprintf(buff, "#%d in %s, line %u", + sprint(buff, "#%d in %s, line %u", ++name_cnt, FileName, LineNumber); return str2idf(buff, 1); } + +id_not_declared(id) + struct idf *id; +{ + /* The identifier "id" is not declared. If it is not generated, + give an error message + */ + if (!is_anon_idf(id)) { + error("identifier \"%s\" not declared", id->id_text); + } +} diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 68c5be23..994f6c40 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -14,6 +14,9 @@ static char *RcsId = "$Header$"; #include "def.h" #include "type.h" #include "debug.h" + +static struct idf *impl_name = 0; +static struct def *impl_df; } /* The grammar as given by Wirth is already almost LL(1); the @@ -101,30 +104,41 @@ DefinitionModule register struct def *df; struct idf *id; } : - DEFINITION { state = DEFINITION; } + DEFINITION MODULE IDENT { id = dot.TOK_IDF; df = define(id, GlobalScope, D_MODULE); - open_scope(CLOSEDSCOPE, 0); + if (!SYSTEMModule) open_scope(CLOSEDSCOPE, 0); df->mod_scope = CurrentScope->sc_scope; + DefinitionModule = 1; DO_DEBUG(debug(1, "Definition module \"%s\"", id->id_text)); } ';' import(0)* export(1)? - /* New Modula-2 does not have export lists in definition modules. + For the time being, we ignore export lists here, and a + warning is issued. */ - definition* END IDENT '.' + definition* END IDENT { + if (id == impl_name) { + /* Just read the definition module of the + implementation module being compiled + */ + RemImports(&(CurrentScope->sc_def)); + impl_df = CurrentScope->sc_def; + } df = CurrentScope->sc_def; while (df) { /* Make all definitions "QUALIFIED EXPORT" */ df->df_flags |= D_QEXPORTED; df = df->df_nextinscope; } - close_scope(); + if (!SYSTEMModule) close_scope(); + DefinitionModule = 0; match_id(id, dot.TOK_IDF); } + '.' ; definition @@ -153,20 +167,23 @@ definition ProcedureHeading(&df, D_PROCHEAD) ';' ; -ProgramModule +ProgramModule(int state;) { struct idf *id; struct def *df, *GetDefinitionModule(); int scope = 0; } : - MODULE { if (state != IMPLEMENTATION) state = PROGRAM; } + MODULE IDENT { id = dot.TOK_IDF; if (state == IMPLEMENTATION) { + impl_name = id; df = GetDefinitionModule(id); scope = df->mod_scope; } + DefinitionModule = 0; open_scope(CLOSEDSCOPE, scope); + CurrentScope->sc_def = impl_df; } priority? ';' import(0)* @@ -177,13 +194,16 @@ ProgramModule '.' ; -Module: +Module +{ + int state = PROGRAM; +} : DefinitionModule | [ IMPLEMENTATION { state = IMPLEMENTATION; } ]? - ProgramModule + ProgramModule(state) ; CompilationUnit: diff --git a/lang/m2/comp/standards.h b/lang/m2/comp/standards.h index 179aa892..c7841b0b 100644 --- a/lang/m2/comp/standards.h +++ b/lang/m2/comp/standards.h @@ -21,4 +21,8 @@ #define S_VAL 17 /* Standard procedures and functions defined in the SYSTEM module ... */ -/* PM ??? */ + +#define S_ADR 20 +#define S_TSIZE 21 +#define S_NEWPROCESS 22 +#define S_TRANSFER 23 diff --git a/lang/m2/comp/tokenname.c b/lang/m2/comp/tokenname.c index 6d16fe3f..10c28ac8 100644 --- a/lang/m2/comp/tokenname.c +++ b/lang/m2/comp/tokenname.c @@ -88,6 +88,8 @@ struct tokenname tkstandard[] = { /* standard identifiers */ {SUBRANGE, ""}, {ENUMERATION, ""}, {ERRONEOUS, ""}, + {WORD, ""}, + {ADDRESS, ""}, {0, ""} }; diff --git a/lang/m2/comp/type.H b/lang/m2/comp/type.H index f2ebb802..2de207c9 100644 --- a/lang/m2/comp/type.H +++ b/lang/m2/comp/type.H @@ -75,7 +75,8 @@ extern struct type *longint_type, *real_type, *longreal_type, - *nil_type, + *word_type, + *address_type, *error_type; extern int diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index 3d5fe909..520b2b68 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -41,7 +41,8 @@ struct type *longint_type, *real_type, *longreal_type, - *nil_type, + *word_type, + *address_type, *error_type; struct paramlist *h_paramlist; @@ -128,8 +129,10 @@ init_types() card_type = standard_type(CARDINAL, int_align, int_size); real_type = standard_type(REAL, real_align, real_size); longreal_type = standard_type(LONGREAL, lreal_align, lreal_size); - nil_type = standard_type(POINTER, ptr_align, ptr_size); + word_type = standard_type(WORD, wrd_align, wrd_size); + address_type = construct_type(POINTER, word_type); error_type = standard_type(ERRONEOUS, 1, (arith) 1); + } int From b69b512875b9dd591cdf1d8e7920dde179c24b7f Mon Sep 17 00:00:00 2001 From: erikb Date: Fri, 4 Apr 1986 09:54:50 +0000 Subject: [PATCH 0165/1625] revised the treatment of strings in initialisations --- lang/cem/cemcom/ival.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lang/cem/cemcom/ival.c b/lang/cem/cemcom/ival.c index 201c5028..b47cd0ad 100644 --- a/lang/cem/cemcom/ival.c +++ b/lang/cem/cemcom/ival.c @@ -514,16 +514,23 @@ init_string(tpp, ex) } else { arith dim = tp->tp_size / tp->tp_up->tp_size; + extern char options[]; + if (length > dim) { + if (options['R']) + too_many_initialisers(ex); + else { /* don't take the null byte into account */ + if (length > dim + 1) + expr_warning(ex, + "too many initialisers"); + length = dim; + } + } ntopad = align(dim, word_align) - length; - if (length > dim) - expr_error(ex, - "too many characters in initialiser string"); } /* throw out the characters of the already prepared string */ - do + while (length-- > 0) C_con_ucon(long2str((long)*s++ & 0xFF, 10), (arith)1); - while (--length > 0); /* pad the allocated memory (the alignment has been calculated) */ while (ntopad-- > 0) con_nullbyte(); From 80b9feb37f8d2dd9ffa249849b3cfd1ff46c798d Mon Sep 17 00:00:00 2001 From: erikb Date: Fri, 4 Apr 1986 11:31:03 +0000 Subject: [PATCH 0166/1625] corrected the treatment of PREDEF-ed macros --- lang/cem/cemcom/LLlex.c | 10 ++-------- lang/cem/cemcom/init.c | 4 +--- lang/cem/cemcom/replace.c | 33 +++++++-------------------------- 3 files changed, 10 insertions(+), 37 deletions(-) diff --git a/lang/cem/cemcom/LLlex.c b/lang/cem/cemcom/LLlex.c index 22013746..a1182d91 100644 --- a/lang/cem/cemcom/LLlex.c +++ b/lang/cem/cemcom/LLlex.c @@ -274,15 +274,9 @@ go_on: /* rescan, the following character has been read */ *tg++ = '\0'; /* mark the end of the identifier */ idef = ptok->tk_idf = idf_hashed(buf, tg - buf, hash); #ifndef NOPP - if (idef->id_macro && ReplaceMacros) { + if (idef->id_macro && ReplaceMacros && replace(idef)) /* macro replacement should be performed */ - if (replace(idef)) - goto again; - /* arrived here: something went wrong in - replace, don't substitute in this case - */ - } - else + goto again; if (UnknownIdIsZero) { ptok->tk_ival = (arith)0; ptok->tk_fund = INT; diff --git a/lang/cem/cemcom/init.c b/lang/cem/cemcom/init.c index fcfe547b..c5cf19cd 100644 --- a/lang/cem/cemcom/init.c +++ b/lang/cem/cemcom/init.c @@ -81,8 +81,6 @@ init_pp() containing a number of identifiers to be predefined at the host machine (for example -DPREDEFINE="vax,unix,pmds"). - Note that PREDEF causes the identifier not - to be substituted. */ register char *s = PREDEFINE; register char *id; @@ -96,7 +94,7 @@ init_pp() while (in_idf(*s++)); c = *--s; *s = '\0'; - macro_def(str2idf(id), "", -1, 0, PREDEF); + macro_def(str2idf(id), "1", -1, 1, PREDEF); *s = c; } else diff --git a/lang/cem/cemcom/replace.c b/lang/cem/cemcom/replace.c index 0b0f7302..8738fa0e 100644 --- a/lang/cem/cemcom/replace.c +++ b/lang/cem/cemcom/replace.c @@ -43,29 +43,22 @@ replace(idef) if (idef->id_macro->mc_nps != -1) { /* with parameter list */ LoadChar(c); c = skipspaces(c); - if (c != '(') { /* no replacement if no () */ lexerror("(warning) macro %s needs arguments", idef->id_text); PushBack(); return 0; } - actpars = getactuals(idef); /* get act.param. list */ } - - if (flags & PREDEF) { /* don't replace this one... */ - return 0; - } - - if (flags & FUNC) { /* this macro leads to special action */ + if ((flags & PREDEF) && (UnknownIdIsZero == 0)) + /* don't replace this one... */ + return 0; + if (flags & FUNC) /* this macro leads to special action */ macro_func(idef); - } - /* create and input buffer */ reptext = macro2buffer(idef, actpars, &size); InsertText(reptext, size); - return 1; } @@ -82,7 +75,6 @@ macro_func(idef) /* This switch is very blunt... */ switch (idef->id_text[2]) { - case 'F' : /* __FILE__ */ FilNamBuf[0] = '"'; strcpy(&FilNamBuf[1], FileName); @@ -90,15 +82,12 @@ macro_func(idef) idef->id_macro->mc_text = FilNamBuf; idef->id_macro->mc_length = strlen(FilNamBuf); break; - case 'L' : /* __LINE__ */ idef->id_macro->mc_text = long2str((long)LineNumber, 10); idef->id_macro->mc_length = 1; break; - default : - crash("(macro_func) illegal macro %s\n", idef->id_text); - + crash("(macro_func)"); } } @@ -115,7 +104,6 @@ macro2buffer(idef, actpars, siztext) parameter list actpars. A pointer to the beginning of the constructed text is returned, while *siztext is filled with its length. - If there are no parameters, this function behaves the same as strcpy(). */ @@ -125,35 +113,28 @@ macro2buffer(idef, actpars, siztext) register char *ptr = idef->id_macro->mc_text; text[pos++] = '\0'; /* allow pushback */ - while (*ptr) { if (*ptr & FORMALP) { /* non-asc formal param. mark */ register int n = *ptr++ & 0177; register char *p; ASSERT(n != 0); - /* copy the text of the actual parameter into the replacement text */ for (p = actpars[n - 1]; *p; p++) { text[pos++] = *p; - - if (pos == size) { + if (pos == size) text = Srealloc(text, size += RSTRSIZE); - } } } else { text[pos++] = *ptr++; - - if (pos == size) { + if (pos == size) text = Srealloc(text, size += RSTRSIZE); - } } } - text[pos] = '\0'; *siztext = pos; return text; From eadfa9ae0a710d31dab10aa2cc0f4b9e18be00f9 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 4 Apr 1986 13:47:04 +0000 Subject: [PATCH 0167/1625] A newer version --- lang/m2/comp/LLlex.c | 26 +++++++++------- lang/m2/comp/LLlex.h | 19 +++++++----- lang/m2/comp/LLmessage.c | 2 +- lang/m2/comp/Makefile | 3 +- lang/m2/comp/declar.g | 30 +++++++++++++++--- lang/m2/comp/def.H | 67 ++++++++++++++++++++++------------------ lang/m2/comp/defmodule.c | 2 ++ lang/m2/comp/tokenname.c | 7 +++-- lang/m2/comp/typequiv.c | 54 ++++++++++++++++++++++++++++++++ 9 files changed, 152 insertions(+), 58 deletions(-) create mode 100644 lang/m2/comp/typequiv.c diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index 0eaa1730..91817c10 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -18,6 +18,7 @@ static char *RcsId = "$Header$"; long str2long(); struct token dot, aside; +struct string string; static SkipComment() @@ -59,16 +60,16 @@ SkipComment() } } -static char * +static GetString(upto) { /* Read a Modula-2 string, delimited by the character "upto". */ register int ch; - int str_size; - char *str = Malloc(str_size = 32); - register int pos = 0; + register struct string *str = &string; + register char *p; + str->s_str = p = Malloc(str->s_length = 32); LoadChar(ch); while (ch != upto) { if (class(ch) == STNL) { @@ -80,14 +81,15 @@ GetString(upto) lexerror("end-of-file in string"); break; } - str[pos++] = ch; - if (pos == str_size) { - str = Srealloc(str, str_size += 8); + *p++ = ch; + if (p - str->s_str == str->s_length) { + str->s_str = Srealloc(str->s_str, str->s_length += 8); + p = str->s_str + (str->s_length - 8); } LoadChar(ch); } - str[pos] = '\0'; - return str; + *p = '\0'; + str->s_length = p - str->s_str; } int @@ -106,13 +108,14 @@ LLlex() return tk->tk_symb; } tk->tk_lineno = LineNumber; + tk->tk_filename = FileName; again: LoadChar(ch); if ((ch & 0200) && ch != EOI) { fatal("non-ascii '\\%03o' read", ch & 0377); } - + switch (class(ch)) { case STSKIP: @@ -205,7 +208,8 @@ again: } case STSTR: - tk->TOK_STR = GetString(ch); + GetString(ch); + tk->tk_data.tk_str = string; return tk->tk_symb = STRING; case STNUM: diff --git a/lang/m2/comp/LLlex.h b/lang/m2/comp/LLlex.h index 65690fd3..92bc5979 100644 --- a/lang/m2/comp/LLlex.h +++ b/lang/m2/comp/LLlex.h @@ -2,24 +2,27 @@ /* $Header$ */ +struct string { + int s_length; /* length of a string */ + char *s_str; /* the string itself */ +}; + struct token { int tk_symb; /* token itself */ + char *tk_filename; /* filename in which it occurred */ int tk_lineno; /* linenumber on which it occurred */ union { struct idf *tk_idf; /* IDENT */ - char *tk_str; /* STRING */ - struct { /* INTEGER */ - struct type *tk_type; /* type */ - arith tk_value; /* value */ - } tk_int; + struct string tk_str; /* STRING */ + arith tk_int; /* INTEGER */ char *tk_real; /* REAL */ } tk_data; }; #define TOK_IDF tk_data.tk_idf -#define TOK_STR tk_data.tk_str -#define TOK_ITP tk_data.tk_int.tk_type -#define TOK_INT tk_data.tk_int.tk_value +#define TOK_STR tk_data.tk_str.s_str +#define TOK_SLE tk_data.tk_str.s_length +#define TOK_INT tk_data.tk_int #define TOK_REL tk_data.tk_real extern struct token dot, aside; diff --git a/lang/m2/comp/LLmessage.c b/lang/m2/comp/LLmessage.c index 85591d60..ad6cd5be 100644 --- a/lang/m2/comp/LLmessage.c +++ b/lang/m2/comp/LLmessage.c @@ -37,10 +37,10 @@ insert_token(tk) dot.TOK_IDF = gen_anon_idf(); break; case STRING: + dot.TOK_SLE = 1; dot.TOK_STR = Salloc("", 1); break; case INTEGER: -/* dot.TOK_ITP = INT; */ dot.TOK_INT = 1; break; case REAL: diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index 211f60ec..2bff6e5e 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -17,7 +17,7 @@ LFLAGS = $(PROFILE) LOBJ = tokenfile.o program.o declar.o expression.o statement.o COBJ = LLlex.o LLmessage.o char.o error.o main.o \ symbol2str.o tokenname.o idf.o input.o type.o def.o \ - scope.o misc.o enter.o defmodule.o + scope.o misc.o enter.o defmodule.o typequiv.o OBJ = $(COBJ) $(LOBJ) Lpars.o GENFILES= tokenfile.c \ program.c declar.c expression.c statement.c \ @@ -83,6 +83,7 @@ scope.o: LLlex.h debug.h def.h idf.h scope.h type.h misc.o: LLlex.h f_info.h idf.h misc.h enter.o: def.h idf.h misc.h scope.h type.h defmodule.o: LLlex.h def.h f_info.h idf.h input.h scope.h +typequiv.o: Lpars.h def.h type.h tokenfile.o: Lpars.h program.o: LLlex.h Lpars.h debug.h def.h idf.h main.h misc.h scope.h type.h declar.o: LLlex.h Lpars.h def.h idf.h misc.h scope.h type.h diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index b773b6cc..1db02dbc 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -21,6 +21,7 @@ ProcedureDeclaration ProcedureHeading(&df, D_PROCEDURE) ';' block IDENT { match_id(dot.TOK_IDF, df->df_idf); + df->prc_scope = CurrentScope->sc_scope; close_scope(); } ; @@ -28,19 +29,37 @@ ProcedureDeclaration ProcedureHeading(struct def **pdf; int type;) { struct type *tp; + struct type *tp1 = 0; struct paramlist *params = 0; + register struct def *df; } : PROCEDURE IDENT { assert(type & (D_PROCEDURE | D_PROCHEAD)); - *pdf = define(dot.TOK_IDF, CurrentScope, type); - if (type == D_PROCEDURE) { + if (type == D_PROCHEAD) { + df = define(dot.TOK_IDF, CurrentScope, type); + } + else { + df = lookup(dot.TOK_IDF, + CurrentScope->sc_scope); + if (df && df->df_kind == D_PROCHEAD) { + df->df_kind = type; + tp1 = df->df_type; + } + else { + df = define(dot.TOK_IDF, + CurrentScope, type); + } open_scope(OPENSCOPE, 0); } } FormalParameters(type == D_PROCEDURE, ¶ms, &tp)? { - (*pdf)->df_type = tp = construct_type(PROCEDURE, tp); + df->df_type = tp = construct_type(PROCEDURE, tp); tp->prc_params = params; + if (tp1 && !TstTypeEquiv(tp, tp1)) { +error("inconsistent procedure declaration for \"%s\"", df->df_idf->id_text); + } + *pdf = df; } ; @@ -283,6 +302,9 @@ FieldList(struct scope *scope;) } : [ IdentList(&FldList) ':' type(&tp) + { EnterIdList(FldList, D_FIELD, 0, tp, scope); + FreeIdList(FldList); + } | CASE [ @@ -370,7 +392,7 @@ ProcedureType(struct type **ptp;) struct type *tp = 0; } : PROCEDURE FormalTypeList(&pr, &tp)? - { *ptp = construct_type(PROCEDURE, tp); + { *ptp = construct_type(PROCVAR, tp); (*ptp)->prc_params = pr; } ; diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H index 3bc32260..99c34b9c 100644 --- a/lang/m2/comp/def.H +++ b/lang/m2/comp/def.H @@ -3,14 +3,14 @@ /* $Header$ */ struct module { - int mo_priority; /* Priority of a module */ - int mo_scope; /* Scope of this module */ + int mo_priority; /* priority of a module */ + int mo_scope; /* scope of this module */ #define mod_priority df_value.df_module.mo_priority #define mod_scope df_value.df_module.mo_scope }; struct variable { - arith va_off; /* Address or offset of variable */ + arith va_off; /* address or offset of variable */ #define var_off df_value.df_variable.va_off }; @@ -20,8 +20,8 @@ struct constant { }; struct enumval { - unsigned int en_val; /* Value of this enumeration literal */ - struct def *en_next; /* Next enumeration literal */ + unsigned int en_val; /* value of this enumeration literal */ + struct def *en_next; /* next enumeration literal */ #define enm_val df_value.df_enum.en_val #define enm_next df_value.df_enum.en_next }; @@ -37,8 +37,13 @@ struct field { #define fld_variant df_value.df_field.fd_variant }; +struct dfproc { + int pr_scope; /* scope number of procedure */ +#define prc_scope df_value.df_proc.pr_scope +}; + struct import { - struct def *im_def; /* Scope number from which imported */ + struct def *im_def; /* imported definition */ #define imp_def df_value.df_import.im_def }; @@ -47,32 +52,33 @@ struct def { /* list of definitions for a name */ struct def *df_nextinscope; /* link all definitions in a scope */ struct idf *df_idf; /* link back to the name */ - int df_scope; /* Scope in which this definition resides */ - short df_kind; /* The kind of this definition: */ -#define D_MODULE 0x0001 /* A module */ -#define D_PROCEDURE 0x0002 /* Procedure of function */ -#define D_VARIABLE 0x0004 /* A variable */ -#define D_FIELD 0x0008 /* A field in a record */ -#define D_TYPE 0x0010 /* A type */ -#define D_ENUM 0x0020 /* An enumeration literal */ -#define D_CONST 0x0040 /* A constant */ -#define D_IMPORT 0x0080 /* An imported definition */ -#define D_PROCHEAD 0x0100 /* A procedure heading in a definition module */ -#define D_HIDDEN 0x0200 /* A hidden type */ -#define D_HTYPE 0x0400 /* Definition of a hidden type seen */ -#define D_STDPROC 0x0800 /* A standard procedure */ -#define D_STDFUNC 0x1000 /* A standard function */ -#define D_ERROR 0x2000 /* A compiler generated definition for an + int df_scope; /* scope in which this definition resides */ + short df_kind; /* the kind of this definition: */ +#define D_MODULE 0x0001 /* a module */ +#define D_PROCEDURE 0x0002 /* procedure of function */ +#define D_VARIABLE 0x0004 /* a variable */ +#define D_FIELD 0x0008 /* a field in a record */ +#define D_TYPE 0x0010 /* a type */ +#define D_ENUM 0x0020 /* an enumeration literal */ +#define D_CONST 0x0040 /* a constant */ +#define D_IMPORT 0x0080 /* an imported definition */ +#define D_PROCHEAD 0x0100 /* a procedure heading in a definition module */ +#define D_HIDDEN 0x0200 /* a hidden type */ +#define D_HTYPE 0x0400 /* definition of a hidden type seen */ +#define D_STDPROC 0x0800 /* a standard procedure */ +#define D_STDFUNC 0x1000 /* a standard function */ +#define D_ERROR 0x2000 /* a compiler generated definition for an undefined variable */ -#define D_ISEXPORTED 0x4000 /* Not yet defined */ +#define D_ISEXPORTED 0x4000 /* not yet defined */ char df_flags; -#define D_ADDRESS 0x01 /* Set if address was taken */ -#define D_USED 0x02 /* Set if used */ -#define D_DEFINED 0x04 /* Set if it is assigned a value */ -#define D_VARPAR 0x08 /* Set if it is a VAR parameter */ -#define D_EXPORTED 0x40 /* Set if exported */ -#define D_QEXPORTED 0x80 /* Set if qualified exported */ +#define D_ADDRESS 0x01 /* set if address was taken */ +#define D_USED 0x02 /* set if used */ +#define D_DEFINED 0x04 /* set if it is assigned a value */ +#define D_VARPAR 0x08 /* set if it is a VAR parameter */ +#define D_VALPAR 0x10 /* set if it is a value parameter */ +#define D_EXPORTED 0x40 /* set if exported */ +#define D_QEXPORTED 0x80 /* set if qualified exported */ struct type *df_type; union { struct module df_module; @@ -81,7 +87,8 @@ struct def { /* list of definitions for a name */ struct enumval df_enum; struct field df_field; struct import df_import; - int df_stdname; /* Define for standard name */ + struct dfproc df_proc; + int df_stdname; /* define for standard name */ } df_value; }; diff --git a/lang/m2/comp/defmodule.c b/lang/m2/comp/defmodule.c index b007705d..b781adc6 100644 --- a/lang/m2/comp/defmodule.c +++ b/lang/m2/comp/defmodule.c @@ -1,5 +1,7 @@ /* D E F I N I T I O N M O D U L E S */ +static char *RcsId = "$Header$"; + #include #include #include diff --git a/lang/m2/comp/tokenname.c b/lang/m2/comp/tokenname.c index 10c28ac8..b4ce2b5c 100644 --- a/lang/m2/comp/tokenname.c +++ b/lang/m2/comp/tokenname.c @@ -76,6 +76,10 @@ struct tokenname tkidf[] = { /* names of the identifier tokens */ struct tokenname tkinternal[] = { /* internal keywords */ {PROGRAM, ""}, + {SUBRANGE, ""}, + {ENUMERATION, ""}, + {ERRONEOUS, ""}, + {PROCVAR, ""}, {0, "0"} }; @@ -85,9 +89,6 @@ struct tokenname tkstandard[] = { /* standard identifiers */ {LONGINT, ""}, {CARDINAL, ""}, {LONGREAL, ""}, - {SUBRANGE, ""}, - {ENUMERATION, ""}, - {ERRONEOUS, ""}, {WORD, ""}, {ADDRESS, ""}, {0, ""} diff --git a/lang/m2/comp/typequiv.c b/lang/m2/comp/typequiv.c new file mode 100644 index 00000000..96f9e38a --- /dev/null +++ b/lang/m2/comp/typequiv.c @@ -0,0 +1,54 @@ +/* T Y P E E Q U I V A L E N C E */ + +static char *RcsId = "$Header$"; + +#include +#include +#include "type.h" +#include "def.h" +#include "Lpars.h" + +int +TstTypeEquiv(tp1, tp2) + register struct type *tp1, *tp2; +{ + /* test if two types are equivalent. The only complication comes + from the fact that for some procedures two declarations may + be given: one in the specification module and one in the + definition module. + */ + + return tp1 == tp2 + || + ( + tp1 && tp1->tp_fund == PROCEDURE + && + tp2 && tp2->tp_fund == PROCEDURE + && + TstProcEquiv(tp1, tp2) + ); + +} + +int +TstProcEquiv(tp1, tp2) + register struct type *tp1, *tp2; +{ + /* Test if two procedure types are equivalent. This routine + may also be used for the testing of assignment compatibility + between procedure variables and procedures. + */ + register struct paramlist *p1, *p2; + + if (!TstTypeEquiv(tp1->next, tp2->next)) return 0; + p1 = tp1->prc_params; + p2 = tp2->prc_params; + while (p1 && p2) { + if (p1->par_var != p2->par_var || + !TstTypeEquiv(p1->par_type, p2->par_type)) return 0; + p1 = p1->next; + p2 = p2->next; + } + if (p1 != p2) return 0; + return 1; +} From 95f9e56d532ec7502748c3c85fdfd991707b14c9 Mon Sep 17 00:00:00 2001 From: ceriel Date: Sun, 6 Apr 1986 17:42:56 +0000 Subject: [PATCH 0168/1625] newer version, partial parse trees --- lang/m2/comp/Makefile | 18 +-- lang/m2/comp/declar.g | 67 ++++++----- lang/m2/comp/def.c | 54 +++++---- lang/m2/comp/enter.c | 7 +- lang/m2/comp/error.c | 55 +++++---- lang/m2/comp/expression.g | 247 ++++++++++++++++++++++++++------------ lang/m2/comp/misc.H | 7 -- lang/m2/comp/misc.c | 16 --- lang/m2/comp/node.H | 31 +++++ lang/m2/comp/node.c | 41 +++++++ lang/m2/comp/program.g | 22 ++-- lang/m2/comp/statement.g | 68 ++++++++--- lang/m2/comp/type.c | 5 +- 13 files changed, 418 insertions(+), 220 deletions(-) create mode 100644 lang/m2/comp/node.H create mode 100644 lang/m2/comp/node.c diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index 2bff6e5e..bbd5a93d 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -17,7 +17,7 @@ LFLAGS = $(PROFILE) LOBJ = tokenfile.o program.o declar.o expression.o statement.o COBJ = LLlex.o LLmessage.o char.o error.o main.o \ symbol2str.o tokenname.o idf.o input.o type.o def.o \ - scope.o misc.o enter.o defmodule.o typequiv.o + scope.o misc.o enter.o defmodule.o typequiv.o node.o OBJ = $(COBJ) $(LOBJ) Lpars.o GENFILES= tokenfile.c \ program.c declar.c expression.c statement.c \ @@ -47,6 +47,7 @@ symbol2str.c: tokenname.c make.tokcase misc.h: misc.H make.allocd def.h: def.H make.allocd type.h: type.H make.allocd +node.h: node.H make.allocd scope.c: scope.C make.allocd char.c: char.tab tab @@ -71,22 +72,23 @@ depend: LLlex.o: LLlex.h Lpars.h class.h f_info.h idf.h input.h LLmessage.o: LLlex.h Lpars.h idf.h char.o: class.h -error.o: LLlex.h f_info.h input.h main.h +error.o: LLlex.h f_info.h input.h main.h node.h main.o: LLlex.h Lpars.h debug.h def.h f_info.h idf.h input.h main.h scope.h standards.h type.h symbol2str.o: Lpars.h tokenname.o: Lpars.h idf.h tokenname.h idf.o: idf.h input.o: f_info.h input.h -type.o: Lpars.h def.h def_sizes.h idf.h misc.h type.h -def.o: Lpars.h debug.h def.h idf.h main.h misc.h scope.h type.h +type.o: LLlex.h Lpars.h def.h def_sizes.h idf.h node.h type.h +def.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h type.h scope.o: LLlex.h debug.h def.h idf.h scope.h type.h misc.o: LLlex.h f_info.h idf.h misc.h -enter.o: def.h idf.h misc.h scope.h type.h +enter.o: LLlex.h def.h idf.h node.h scope.h type.h defmodule.o: LLlex.h def.h f_info.h idf.h input.h scope.h typequiv.o: Lpars.h def.h type.h +node.o: LLlex.h def.h node.h type.h tokenfile.o: Lpars.h -program.o: LLlex.h Lpars.h debug.h def.h idf.h main.h misc.h scope.h type.h -declar.o: LLlex.h Lpars.h def.h idf.h misc.h scope.h type.h -expression.o: LLlex.h Lpars.h def.h idf.h scope.h +program.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h type.h +declar.o: LLlex.h Lpars.h def.h idf.h misc.h node.h scope.h type.h +expression.o: LLlex.h Lpars.h def.h idf.h node.h scope.h statement.o: Lpars.h Lpars.o: Lpars.h diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 1db02dbc..09e77d3f 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -7,11 +7,12 @@ static char *RcsId = "$Header$"; #include #include #include "idf.h" -#include "misc.h" #include "LLlex.h" #include "def.h" #include "type.h" #include "scope.h" +#include "node.h" +#include "misc.h" } ProcedureDeclaration @@ -95,7 +96,7 @@ FormalParameters(int doparams; struct paramlist **pr; struct type **tp;) ]? ')' { *tp = 0; } - [ ':' qualident(D_TYPE | D_HTYPE, &df, "type") + [ ':' qualident(D_TYPE | D_HTYPE, &df, "type", (struct node **) 0) { *tp = df->df_type; } ]? ; @@ -108,7 +109,7 @@ FormalParameters(int doparams; struct paramlist **pr; struct type **tp;) */ FPSection(int doparams; struct paramlist **ppr;) { - struct id_list *FPList; + struct node *FPList; struct paramlist *ParamList(); struct type *tp; int VARp = 0; @@ -122,7 +123,7 @@ FPSection(int doparams; struct paramlist **ppr;) EnterIdList(FPList, D_VARIABLE, VARp, tp, CurrentScope); } *ppr = ParamList(FPList, tp); - FreeIdList(FPList); + FreeNode(FPList); } ; @@ -133,7 +134,7 @@ FormalType(struct type **tp;) } : [ ARRAY OF { ARRAYflag = 1; } ]? - qualident(D_TYPE | D_HTYPE, &df, "type") + qualident(D_TYPE | D_HTYPE, &df, "type", (struct node **) 0) { if (ARRAYflag) { *tp = construct_type(ARRAY, NULLTYPE); (*tp)->arr_elem = df->df_type; @@ -182,7 +183,7 @@ SimpleType(struct type **ptp;) struct def *df; struct type *tp; } : - qualident(D_TYPE | D_HTYPE, &df, "type") + qualident(D_TYPE | D_HTYPE, &df, "type", (struct node **) 0) [ /* nothing */ | @@ -202,41 +203,44 @@ SimpleType(struct type **ptp;) enumeration(struct type **ptp;) { - struct id_list *EnumList; + struct node *EnumList; } : '(' IdentList(&EnumList) ')' { *ptp = standard_type(ENUMERATION,int_align,int_size); EnterIdList(EnumList, D_ENUM, 0, *ptp, CurrentScope); - FreeIdList(EnumList); + FreeNode(EnumList); } ; -IdentList(struct id_list **p;) +IdentList(struct node **p;) { - register struct id_list *q = new_id_list(); + register struct node *q; } : - IDENT { q->id_ptr = dot.TOK_IDF; *p = q;} + IDENT { q = MkNode(Value, NULLNODE, NULLNODE, &dot); + *p = q; + } [ - ',' IDENT { q->next = new_id_list(); - q = q->next; - q->id_ptr = dot.TOK_IDF; - } + ',' IDENT + { q->next = MkNode(Value,NULLNODE,NULLNODE,&dot); + q = q->next; + } ]* - { q->next = 0; } + { q->next = 0; } ; SubrangeType(struct type **ptp;) { struct type *tp; + struct node *nd1 = 0, *nd2 = 0; }: /* This is not exactly the rule in the new report, but see the rule for "SimpleType". */ - '[' ConstExpression - UPTO ConstExpression + '[' ConstExpression(&nd1) + UPTO ConstExpression(&nd2) ']' /* Evaluate the expressions. Check that they are indeed constant. @@ -295,7 +299,7 @@ FieldListSequence(struct scope *scope;): FieldList(struct scope *scope;) { - struct id_list *FldList; + struct node *FldList; struct idf *id; struct def *df, *df1; struct type *tp; @@ -303,7 +307,7 @@ FieldList(struct scope *scope;) [ IdentList(&FldList) ':' type(&tp) { EnterIdList(FldList, D_FIELD, 0, tp, scope); - FreeIdList(FldList); + FreeNode(FldList); } | CASE @@ -312,7 +316,7 @@ FieldList(struct scope *scope;) | { id = gen_anon_idf(); } ] /* Changed rule in new modula-2 */ - ':' qualident(D_TYPE|D_HTYPE, &df, "type") + ':' qualident(D_TYPE|D_HTYPE, &df, "type", (struct node **) 0) { df1 = define(id, scope, D_FIELD); df1->df_type = df->df_type; } @@ -335,8 +339,11 @@ CaseLabelList: CaseLabels [ ',' CaseLabels ]* ; -CaseLabels: - ConstExpression [ UPTO ConstExpression ]? +CaseLabels +{ + struct node *nd1, *nd2 = 0; +}: + ConstExpression(&nd1) [ UPTO ConstExpression(&nd2) ]? ; SetType(struct type **ptp;) @@ -364,7 +371,7 @@ PointerType(struct type **ptp;) /* Either a Module or a Type, but in both cases defined in this scope, so this is the correct identification */ - qualident(D_TYPE|D_HTYPE, &df, "type") + qualident(D_TYPE|D_HTYPE, &df, "type", (struct node **) 0) { if (!df->df_type) { error("type \"%s\" not declared", @@ -429,7 +436,7 @@ FormalTypeList(struct paramlist **ppr; struct type **ptp;) { p->next = 0; } ]? ')' - [ ':' qualident(D_TYPE|D_HTYPE, &df, "type") + [ ':' qualident(D_TYPE|D_HTYPE, &df, "type", (struct node **) 0) { *ptp = df->df_type; } ]? ; @@ -438,24 +445,26 @@ ConstantDeclaration { struct def *df; struct idf *id; + struct node *nd; }: IDENT { id = dot.TOK_IDF; } - '=' ConstExpression { df = define(id, CurrentScope, D_CONST); + '=' ConstExpression(&nd){ df = define(id, CurrentScope, D_CONST); /* ???? */ } ; VariableDeclaration { - struct id_list *VarList; + struct node *VarList; struct type *tp; + struct node *nd = 0; } : IdentList(&VarList) [ - ConstExpression + ConstExpression(&nd) ]? ':' type(&tp) { EnterIdList(VarList, D_VARIABLE, 0, tp, CurrentScope); - FreeIdList(VarList); + FreeNode(VarList); } ; diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index 231364b1..8a5e2999 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -10,9 +10,10 @@ static char *RcsId = "$Header$"; #include "def.h" #include "type.h" #include "idf.h" -#include "misc.h" #include "main.h" #include "scope.h" +#include "LLlex.h" +#include "node.h" #include "debug.h" struct def *h_def; /* Pointer to free list of def structures */ @@ -63,7 +64,7 @@ define(id, scope, kind) return df; } if (kind != D_ERROR) { - error("identifier \"%s\" already declared", id->id_text); +error("identifier \"%s\" already declared", id->id_text); } return df; } @@ -115,7 +116,7 @@ lookup(id, scope) } Export(ids, qualified) - register struct id_list *ids; + register struct node *ids; { /* From the current scope, the list of identifiers "ids" is exported. Note this fact. If the export is not qualified, make @@ -125,36 +126,38 @@ Export(ids, qualified) register struct def *df; while (ids) { - df = define(ids->id_ptr, CurrentScope, D_ISEXPORTED); + df = define(ids->nd_IDF, CurrentScope, D_ISEXPORTED); if (qualified) { df->df_flags |= D_QEXPORTED; } else { df->df_flags |= D_EXPORTED; - df = define(ids->id_ptr, enclosing(CurrentScope), + df = define(ids->nd_IDF, enclosing(CurrentScope), D_IMPORT); } ids = ids->next; } } -Import(ids, id, local) - register struct id_list *ids; - struct idf *id; +Import(ids, idn, local) + register struct node *ids; + struct node *idn; { /* "ids" is a list of imported identifiers. - If "id" is a null-pointer, the identifiers are imported from the - enclosing scope. Otherwise they are imported from the module - indicated by "id", which must be visible in the enclosing scope. - An exception must be made for imports of the Compilation Unit. + If "idn" is a null-pointer, the identifiers are imported from + the enclosing scope. Otherwise they are imported from the module + indicated by "idn", which must be visible in the enclosing + scope. An exception must be made for imports of the + Compilation Unit. This case is indicated by the value 0 of the flag "local". - In this case, if "id" is a null pointer, the "ids" identifiers + In this case, if "idn" is a null pointer, the "ids" identifiers are all module identifiers. Their Definition Modules must be - read. Otherwise "id" is a module identifier whose Definition + read. Otherwise "idn" is a module identifier whose Definition Module must be read. "ids" then represents a list of identifiers defined in this module. */ register struct def *df; + register struct idf *id = 0; int scope; int kind; int imp_kind; @@ -162,6 +165,7 @@ Import(ids, id, local) #define FROM_ENCLOSING 1 struct def *lookfor(), *GetDefinitionModule(); + if (idn) id = idn->nd_IDF; kind = D_IMPORT; scope = enclosing(CurrentScope)->sc_scope; if (!id) imp_kind = FROM_ENCLOSING; @@ -173,35 +177,35 @@ Import(ids, id, local) /* enter all "ids" with type D_ERROR */ kind = D_ERROR; if (df->df_kind != D_ERROR) { -error("identifier \"%s\" does not represent a module", id->id_text); +node_error(idn, "identifier \"%s\" does not represent a module", id->id_text); } } else scope = df->mod_scope; } while (ids) { if (imp_kind == FROM_MODULE) { - if (!(df = lookup(ids->id_ptr, scope))) { -error("identifier \"%s\" not declared in qualifying module", -ids->id_ptr->id_text); + if (!(df = lookup(ids->nd_IDF, scope))) { +node_error(ids, "identifier \"%s\" not declared in qualifying module", +ids->nd_IDF->id_text); df = ill_df; } else if (!(df->df_flags&(D_EXPORTED|D_QEXPORTED))) { -error("identifier \"%s\" not exported from qualifying module", -ids->id_ptr->id_text); +node_error(ids,"identifier \"%s\" not exported from qualifying module", +ids->nd_IDF->id_text); } } else { if (local) { - df = lookfor(ids->id_ptr, + df = lookfor(ids->nd_IDF, enclosing(CurrentScope), 0); - } else df = GetDefinitionModule(ids->id_ptr); + } else df = GetDefinitionModule(ids->nd_IDF); if (df->df_kind == D_ERROR) { -error("identifier \"%s\" not visible in enclosing scope", -ids->id_ptr->id_text); +node_error(ids, "identifier \"%s\" not visible in enclosing scope", +ids->nd_IDF->id_text); } } - define(ids->id_ptr, CurrentScope, kind)->imp_def = df; + define(ids->nd_IDF, CurrentScope, kind)->imp_def = df; if (df->df_kind == D_TYPE && df->df_type->tp_fund == ENUMERATION) { /* Also import all enumeration literals */ diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index 245e33ea..85df442f 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -9,7 +9,8 @@ static char *RcsId = "$Header$"; #include "def.h" #include "type.h" #include "scope.h" -#include "misc.h" +#include "LLlex.h" +#include "node.h" struct def * Enter(name, kind, type, pnam) @@ -30,7 +31,7 @@ Enter(name, kind, type, pnam) } EnterIdList(idlist, kind, flags, type, scope) - register struct id_list *idlist; + register struct node *idlist; struct type *type; struct scope *scope; { @@ -39,7 +40,7 @@ EnterIdList(idlist, kind, flags, type, scope) int assval = 0; while (idlist) { - df = define(idlist->id_ptr, scope, kind); + df = define(idlist->nd_IDF, scope, kind); df->df_type = type; df->df_flags = flags; if (kind == D_ENUM) { diff --git a/lang/m2/comp/error.c b/lang/m2/comp/error.c index d3b23f40..8998e166 100644 --- a/lang/m2/comp/error.c +++ b/lang/m2/comp/error.c @@ -13,6 +13,7 @@ static char *RcsId = "$Header$"; #include "f_info.h" #include "LLlex.h" #include "main.h" +#include "node.h" #define MAXERR_LINE 5 /* Number of error messages on one line ... */ #define ERROUT STDERR @@ -28,8 +29,6 @@ static char *RcsId = "$Header$"; #define VDEBUG 7 #endif -#define NILEXPR ((struct expr *) 0) - int err_occurred; extern char *symbol2str(); @@ -37,12 +36,12 @@ extern char *symbol2str(); /* There are three general error-message functions: lexerror() lexical and pre-processor error messages error() syntactic and semantic error messages - expr_error() errors in expressions + node_error() errors in nodes The difference lies in the place where the file name and line number come from. Lexical errors report from the global variables LineNumber and - FileName, expression errors get their information from the - expression, whereas other errors use the information in the token. + FileName, node errors get their information from the + node, whereas other errors use the information in the token. */ #ifdef DEBUG @@ -50,7 +49,7 @@ extern char *symbol2str(); debug(level, fmt, args) char *fmt; { - if (level <= options['D']) _error(VDEBUG, NILEXPR, fmt, &args); + if (level <= options['D']) _error(VDEBUG, NULLNODE, fmt, &args); } #endif DEBUG @@ -58,44 +57,44 @@ debug(level, fmt, args) error(fmt, args) char *fmt; { - _error(ERROR, NILEXPR, fmt, &args); + _error(ERROR, NULLNODE, fmt, &args); } /*VARARGS2*/ -expr_error(expr, fmt, args) - struct expr *expr; +node_error(node, fmt, args) + struct node *node; char *fmt; { - _error(ERROR, expr, fmt, &args); + _error(ERROR, node, fmt, &args); } /*VARARGS1*/ warning(fmt, args) char *fmt; { - _error(WARNING, NILEXPR, fmt, &args); + _error(WARNING, NULLNODE, fmt, &args); } /*VARARGS2*/ -expr_warning(expr, fmt, args) - struct expr *expr; +node_warning(node, fmt, args) + struct node *node; char *fmt; { - _error(WARNING, expr, fmt, &args); + _error(WARNING, node, fmt, &args); } /*VARARGS1*/ lexerror(fmt, args) char *fmt; { - _error(LEXERROR, NILEXPR, fmt, &args); + _error(LEXERROR, NULLNODE, fmt, &args); } /*VARARGS1*/ lexwarning(fmt, args) char *fmt; { - _error(LEXWARNING, NILEXPR, fmt, &args); + _error(LEXWARNING, NULLNODE, fmt, &args); } /*VARARGS1*/ @@ -104,13 +103,13 @@ fatal(fmt, args) int args; { - _error(FATAL, NILEXPR, fmt, &args); + _error(FATAL, NULLNODE, fmt, &args); sys_stop(S_EXIT); } -_error(class, expr, fmt, argv) +_error(class, node, fmt, argv) int class; - struct expr *expr; + struct node *node; char *fmt; int argv[]; { @@ -118,8 +117,10 @@ _error(class, expr, fmt, argv) for a given line to MAXERR_LINE. */ static unsigned int last_ln = 0; - static int e_seen = 0; unsigned int ln = 0; + static char * last_fn = 0; + char *fn = 0; + static int e_seen = 0; char *remark = 0; /* Since name and number are gathered from different places @@ -158,13 +159,19 @@ _error(class, expr, fmt, argv) case FATAL: remark = "fatal error --"; break; +#ifdef DEBUG + case VDEBUG: + remark = "(debug)"; + break; +#endif DEBUG } /* the place */ switch (class) { case WARNING: case ERROR: - ln = /* ???? expr ? expr->ex_line : */ dot.tk_lineno; + fn = node ? node->nd_filename : dot.tk_filename; + ln = node ? node->nd_lineno : dot.tk_lineno; break; case LEXWARNING: case LEXERROR: @@ -174,13 +181,14 @@ _error(class, expr, fmt, argv) case VDEBUG: #endif DEBUG ln = LineNumber; + fn = FileName; break; } #ifdef DEBUG if (class != VDEBUG) { #endif - if (ln == last_ln) { + if (fn == last_fn && ln == last_ln) { /* we've seen this place before */ e_seen++; if (e_seen == MAXERR_LINE) fmt = "etc ..."; @@ -192,13 +200,14 @@ _error(class, expr, fmt, argv) else { /* brand new place */ last_ln = ln; + last_fn = fn; e_seen = 0; } #ifdef DEBUG } #endif DEBUG - if (FileName) fprint(ERROUT, "\"%s\", line %u: ", FileName, ln); + if (fn) fprint(ERROUT, "\"%s\", line %u: ", fn, ln); if (remark) fprint(ERROUT, "%s ", remark); diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index d325eac5..e35b7e33 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -10,15 +10,18 @@ static char *RcsId = "$Header$"; #include "idf.h" #include "def.h" #include "scope.h" +#include "node.h" } -number: +number(struct node **p;): +[ INTEGER | REAL +] { *p = MkNode(Value, NULLNODE, NULLNODE, dot); } ; -qualident(int types; struct def **pdf; char *str;) +qualident(int types; struct def **pdf; char *str; struct node **p;) { int scope; int module; @@ -30,6 +33,9 @@ qualident(int types; struct def **pdf; char *str;) *pdf = df; if (df->df_kind == D_ERROR) types = 0; } + if (p) { + *p = MkNode(Value, NULLNODE, NULLNODE,&dot); + } } [ { if (types &&!(scope = has_selectors(df))) { @@ -38,8 +44,13 @@ qualident(int types; struct def **pdf; char *str;) } } /* selector */ - '.' IDENT - { if (types) { + '.' { if (p) *p = MkNode(Link, *p, NULLNODE, &dot); } + IDENT + { if (p) { + p = &((*p)->nd_right); + *p = MkNode(Value, NULLNODE, NULLNODE,&dot); + } + if (types) { module = (df->df_kind == D_MODULE); df = lookup(dot.TOK_IDF, scope); if (!df) { @@ -62,99 +73,179 @@ qualident(int types; struct def **pdf; char *str;) } ; +/* Inline substituted wherever it occurred selector: - '.' /* field */ IDENT + '.' IDENT +; +*/ + +ExpList(struct node **pnd;) +{ + struct node **nd; +} : + expression(pnd) { nd = pnd; } + [ + ',' { *nd = MkNode(Link, *nd, NULLNODE, &dot); + nd = &(*nd)->nd_right; + } + expression(nd) + ]* ; -ExpList: - expression [ ',' expression ]* -; - -ConstExpression: - expression +ConstExpression(struct node **pnd;): + expression(pnd) /* * Changed rule in new Modula-2. * Check that the expression is a constant expression and evaluate! */ ; -expression: - SimpleExpression [ relation SimpleExpression ]? +expression(struct node **pnd;) +{ + struct node *nd; +} : + SimpleExpression(&nd) + [ + /* relation */ + [ '=' | '#' | UNEQUAL | '<' | LESSEQUAL | '>' | + GREATEREQUAL | IN + ] + { nd = MkNode(Oper, nd, NULLNODE, &dot); } + SimpleExpression(&(nd->nd_right)) + ]? + { *pnd = nd; } ; +/* Inline in expression relation: '=' | '#' | UNEQUAL | '<' | LESSEQUAL | '>' | GREATEREQUAL | IN ; +*/ -SimpleExpression: - [ '+' | '-' ]? term [ AddOperator term ]* -; - -AddOperator: - '+' | '-' | OR -; - -term: - factor [ MulOperator factor ]* -; - -MulOperator: - '*' | '/' | DIV | MOD | AND | '&' -; - -factor +SimpleExpression(struct node **pnd;) { - struct def *df; + register struct node *nd; } : - qualident(0, &df, (char *) 0) + [ '+' | '-' ]? + term(pnd) { nd = *pnd; } [ - designator_tail? ActualParameters? - | - bare_set - ] -| - bare_set -| %default - number -| - STRING -| - '(' expression ')' -| - NOT factor -; - -bare_set: - '{' [ element [ ',' element ]* ]? '}' -; - -ActualParameters: - '(' ExpList? ')' -; - -element: - expression [ UPTO expression ]? -; - -designator -{ - struct def *df; -} : - qualident(0, &df, (char *) 0) - designator_tail? -; - -designator_tail: - visible_designator_tail - [ - selector - | - visible_designator_tail + /* AddOperator */ + [ '+' | '-' | OR ] + { *pnd = nd = MkNode(Oper, nd, NULLNODE, &dot); } + term(&(nd->nd_right)) ]* ; -visible_designator_tail: - '[' ExpList ']' -| - '^' +/* Inline in "SimpleExpression" +AddOperator: + '+' | '-' | OR +; +*/ + +term(struct node **pnd;) +{ + register struct node *nd; +}: + factor(pnd) { nd = *pnd; } + [ + /* MulOperator */ + [ '*' | '/' | DIV | MOD | AND | '&' ] + { *pnd = nd = MkNode(Oper, nd, NULLNODE, &dot); } + factor(&(nd->nd_right)) + ]* +; + +/* inline in "term" +MulOperator: + '*' | '/' | DIV | MOD | AND | '&' +; +*/ + +factor(struct node **p;) +{ + struct def *df; +} : + qualident(0, &df, (char *) 0, p) + [ + designator_tail(p)? + [ + { *p = MkNode(Call, p, NULLNODE, &dot); } + ActualParameters(&((*p)->nd_right)) + ]? + | { *p = MkNode(Call, p, NULLNODE, &dot); } + bare_set(&((*p)->nd_right)) + ] +| + bare_set(p) +| %default + number(p) +| + STRING { *p = MkNode(Value, NULLNODE, NULLNODE, &dot); } +| + '(' expression(p) ')' +| + NOT { *p = MkNode(Uoper, NULLNODE, NULLNODE, &dot); } + factor(&((*p)->nd_left)) +; + +bare_set(struct node **pnd;) +{ + struct node **nd; +} : + '{' { + dot.tk_symb = SET; + *pnd = MkNode(Link, NULLNODE, NULLNODE, &dot); + nd = &((*pnd)->nd_left); + } + [ + element(nd) + [ + ',' { *nd = MkNode(Link, *nd, NULLNODE, &dot); + nd = &((*nd)->nd_right); + } + element(nd) + ]* + ]? + '}' +; + +ActualParameters(struct node **pnd;): + '(' ExpList(pnd)? ')' +; + +element(struct node **pnd;): + expression(pnd) + [ + UPTO { *pnd = MkNode(Link, *pnd, NULLNODE, &dot);} + expression(&((*pnd)->nd_right)) + ]? +; + +designator(struct node **pnd;) +{ + struct def *df; +} : + qualident(0, &df, (char *) 0, pnd) + designator_tail(pnd)? +; + +designator_tail(struct node **pnd;): + visible_designator_tail(pnd) + [ + /* selector */ + '.' { *pnd = MkNode(Oper, *pnd, NULLNODE, &dot); } + IDENT { (*pnd)->nd_right = + MkNode(Value, NULLNODE, NULLNODE, &dot); + } + | + visible_designator_tail(pnd) + ]* +; + +visible_designator_tail(struct node **pnd;): + '[' { *pnd = MkNode(Oper, *pnd, NULLNODE, &dot); } + ExpList(&((*pnd)->nd_right)) + ']' +| + '^' { *pnd = MkNode(Oper, *pnd, NULLNODE, &dot); } ; diff --git a/lang/m2/comp/misc.H b/lang/m2/comp/misc.H index ef9a7815..4f2ae65e 100644 --- a/lang/m2/comp/misc.H +++ b/lang/m2/comp/misc.H @@ -2,13 +2,6 @@ /* $Header$ */ -/* Structure to link idf structures together -*/ -struct id_list { - struct id_list *next; - struct idf *id_ptr; -}; - /* ALLOCDEF "id_list" */ #define is_anon_idf(x) ((x)->id_text[0] == '#') diff --git a/lang/m2/comp/misc.c b/lang/m2/comp/misc.c index 7a543978..e0063bb6 100644 --- a/lang/m2/comp/misc.c +++ b/lang/m2/comp/misc.c @@ -24,22 +24,6 @@ match_id(id1, id2) } } -struct id_list *h_id_list; /* Header of free list of id_list structures */ - -/* FreeIdList: take a list of id_list structures and put them - on the free list of id_list structures -*/ -FreeIdList(p) - struct id_list *p; -{ - register struct id_list *q; - - while (q = p) { - p = p->next; - free_id_list(q); - } -} - struct idf * gen_anon_idf() { diff --git a/lang/m2/comp/node.H b/lang/m2/comp/node.H new file mode 100644 index 00000000..2dd99b4e --- /dev/null +++ b/lang/m2/comp/node.H @@ -0,0 +1,31 @@ +/* N O D E O F A N A B S T R A C T P A R S E T R E E */ + +/* $Header$ */ + +struct node { + struct node *next; +#define nd_left next + struct node *nd_right; + int nd_class; /* kind of node */ +#define Value 1 /* idf or constant */ +#define Oper 2 /* binary operator */ +#define Uoper 3 /* unary operator */ +#define Call 4 /* cast or procedure - or function call */ +#define Link 5 + struct type *nd_type; /* type of this node */ + struct token nd_token; +#define nd_symb nd_token.tk_symb +#define nd_lineno nd_token.tk_lineno +#define nd_filename nd_token.tk_filename +#define nd_IDF nd_token.TOK_IDF +#define nd_STR nd_token.TOK_STR +#define nd_SLE nd_token.TOK_SLE +#define nd_INT nd_token.TOK_INT +#define nd_REL nd_token.TOK_REL +}; + +/* ALLOCDEF "node" */ + +extern struct node *MkNode(); + +#define NULLNODE ((struct node *) 0) diff --git a/lang/m2/comp/node.c b/lang/m2/comp/node.c new file mode 100644 index 00000000..dcd5a9ee --- /dev/null +++ b/lang/m2/comp/node.c @@ -0,0 +1,41 @@ +/* N O D E O F A N A B S T R A C T P A R S E T R E E */ + +static char *RcsId = "$Header$"; + +#include +#include +#include +#include "def.h" +#include "type.h" +#include "LLlex.h" +#include "node.h" + +struct node *h_node; /* header of free list */ + +struct node * +MkNode(class, left, right, token) + struct node *left, *right; + struct token *token; +{ + /* Create a node and initialize it with the given parameters + */ + register struct node *nd = new_node(); + + nd->nd_left = left; + nd->nd_right = right; + nd->nd_token = *token; + nd->nd_class = class; + nd->nd_type = NULLTYPE; + return nd; +} + +FreeNode(nd) + register struct node *nd; +{ + /* Put nodes that are no longer needed back onto the free + list + */ + if (nd->nd_left) FreeNode(nd->nd_left); + if (nd->nd_right) FreeNode(nd->nd_right); + free_node(nd); +} diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 994f6c40..5c17fd6f 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -7,12 +7,12 @@ static char *RcsId = "$Header$"; #include #include #include "idf.h" -#include "misc.h" #include "main.h" #include "LLlex.h" #include "scope.h" #include "def.h" #include "type.h" +#include "node.h" #include "debug.h" static struct idf *impl_name = 0; @@ -57,13 +57,16 @@ ModuleDeclaration } ; -priority: - '[' ConstExpression ']' +priority +{ + struct node *nd; +}: + '[' ConstExpression(&nd) ']' ; export(int def;) { - struct id_list *ExportList; + struct node *ExportList; int QUALflag = 0; } : EXPORT @@ -74,17 +77,17 @@ export(int def;) { if (!def) Export(ExportList, QUALflag); else warning("export list in definition module ignored"); - FreeIdList(ExportList); + FreeNode(ExportList); } ; import(int local;) { - struct id_list *ImportList; - struct idf *id = 0; + struct node *ImportList; + struct node *id = 0; } : [ FROM - IDENT { id = dot.TOK_IDF; } + IDENT { id = MkNode(Value, NULLNODE, NULLNODE, &dot); } ]? IMPORT IdentList(&ImportList) ';' /* @@ -95,7 +98,8 @@ import(int local;) */ { Import(ImportList, id, local); - FreeIdList(ImportList); + FreeNode(ImportList); + if (id) FreeNode(id); } ; diff --git a/lang/m2/comp/statement.g b/lang/m2/comp/statement.g index 70e7b809..6f675a26 100644 --- a/lang/m2/comp/statement.g +++ b/lang/m2/comp/statement.g @@ -2,20 +2,27 @@ { static char *RcsId = "$Header$"; + +#include +#include "LLlex.h" +#include "node.h" } -statement: +statement +{ + struct node *nd1, *nd2; +} : [ /* * This part is not in the reference grammar. The reference grammar * states : assignment | ProcedureCall | ... * but this gives LL(1) conflicts */ - designator + designator(&nd1) [ - ActualParameters? + ActualParameters(&nd2)? | - BECOMES expression + BECOMES expression(&nd2) ] /* * end of changed part @@ -37,7 +44,10 @@ statement: | EXIT | - RETURN expression? + RETURN + [ + expression(&nd1) + ]? ]? ; @@ -57,15 +67,21 @@ StatementSequence: statement [ ';' statement ]* ; -IfStatement: - IF expression THEN StatementSequence - [ ELSIF expression THEN StatementSequence ]* +IfStatement +{ + struct node *nd1; +} : + IF expression(&nd1) THEN StatementSequence + [ ELSIF expression(&nd1) THEN StatementSequence ]* [ ELSE StatementSequence ]? END ; -CaseStatement: - CASE expression OF case [ '|' case ]* +CaseStatement +{ + struct node *nd; +} : + CASE expression(&nd) OF case [ '|' case ]* [ ELSE StatementSequence ]? END ; @@ -75,19 +91,28 @@ case: /* This rule is changed in new modula-2 */ ; -WhileStatement: - WHILE expression DO StatementSequence END +WhileStatement +{ + struct node *nd; +}: + WHILE expression(&nd) DO StatementSequence END ; -RepeatStatement: - REPEAT StatementSequence UNTIL expression +RepeatStatement +{ + struct node *nd; +}: + REPEAT StatementSequence UNTIL expression(&nd) ; -ForStatement: +ForStatement +{ + struct node *nd1, *nd2, *nd3; +}: FOR IDENT - BECOMES expression - TO expression - [ BY ConstExpression ]? + BECOMES expression(&nd1) + TO expression(&nd2) + [ BY ConstExpression(&nd3) ]? DO StatementSequence END ; @@ -95,6 +120,9 @@ LoopStatement: LOOP StatementSequence END ; -WithStatement: - WITH designator DO StatementSequence END +WithStatement +{ + struct node *nd; +}: + WITH designator(&nd) DO StatementSequence END ; diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index 520b2b68..30097075 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -11,7 +11,8 @@ static char *RcsId = "$Header$"; #include "def.h" #include "type.h" #include "idf.h" -#include "misc.h" +#include "LLlex.h" +#include "node.h" /* To be created dynamically in main() from defaults or from command line parameters. @@ -164,7 +165,7 @@ has_selectors(df) */ struct paramlist * ParamList(ids, tp, VARp) - register struct id_list *ids; + register struct node *ids; struct type *tp; { register struct paramlist *pr; From e6978400f50fe3a82b225d3ca51450292decb181 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 7 Apr 1986 17:40:38 +0000 Subject: [PATCH 0169/1625] newer version --- lang/m2/comp/Makefile | 12 +- lang/m2/comp/const.h | 12 ++ lang/m2/comp/cstoper.c | 238 ++++++++++++++++++++++++++++++++++++++ lang/m2/comp/def.c | 4 +- lang/m2/comp/enter.c | 21 +++- lang/m2/comp/error.c | 4 +- lang/m2/comp/expression.g | 112 +++++++++++------- lang/m2/comp/main.c | 24 ++-- lang/m2/comp/node.c | 29 +++++ lang/m2/comp/program.g | 2 +- lang/m2/comp/scope.C | 5 +- lang/m2/comp/tokenname.c | 1 + lang/m2/comp/type.H | 13 ++- lang/m2/comp/type.c | 13 ++- lang/m2/comp/typequiv.c | 29 +++++ 15 files changed, 438 insertions(+), 81 deletions(-) create mode 100644 lang/m2/comp/const.h create mode 100644 lang/m2/comp/cstoper.c diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index bbd5a93d..c24ff052 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -17,7 +17,8 @@ LFLAGS = $(PROFILE) LOBJ = tokenfile.o program.o declar.o expression.o statement.o COBJ = LLlex.o LLmessage.o char.o error.o main.o \ symbol2str.o tokenname.o idf.o input.o type.o def.o \ - scope.o misc.o enter.o defmodule.o typequiv.o node.o + scope.o misc.o enter.o defmodule.o typequiv.o node.o \ + cstoper.o OBJ = $(COBJ) $(LOBJ) Lpars.o GENFILES= tokenfile.c \ program.c declar.c expression.c statement.c \ @@ -80,15 +81,16 @@ idf.o: idf.h input.o: f_info.h input.h type.o: LLlex.h Lpars.h def.h def_sizes.h idf.h node.h type.h def.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h type.h -scope.o: LLlex.h debug.h def.h idf.h scope.h type.h +scope.o: LLlex.h debug.h def.h idf.h main.h scope.h type.h misc.o: LLlex.h f_info.h idf.h misc.h enter.o: LLlex.h def.h idf.h node.h scope.h type.h defmodule.o: LLlex.h def.h f_info.h idf.h input.h scope.h typequiv.o: Lpars.h def.h type.h -node.o: LLlex.h def.h node.h type.h +node.o: LLlex.h debug.h def.h main.h node.h type.h +cstoper.o: Lpars.h def_sizes.h idf.h node.h type.h tokenfile.o: Lpars.h program.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h type.h declar.o: LLlex.h Lpars.h def.h idf.h misc.h node.h scope.h type.h -expression.o: LLlex.h Lpars.h def.h idf.h node.h scope.h -statement.o: Lpars.h +expression.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h +statement.o: LLlex.h Lpars.h node.h Lpars.o: Lpars.h diff --git a/lang/m2/comp/const.h b/lang/m2/comp/const.h new file mode 100644 index 00000000..02f7e28f --- /dev/null +++ b/lang/m2/comp/const.h @@ -0,0 +1,12 @@ +/* C O N S T A N T S F O R E X P R E S S I O N H A N D L I N G */ + +/* $Header$ */ + +extern long + mach_long_sign; /* sign bit of the machine long */ +extern int + mach_long_size; /* size of long on this machine == sizeof(long) */ +extern arith + max_int, /* maximum integer on target machine */ + max_unsigned, /* maximum unsigned on target machine */ + max_longint; /* maximum longint on target machine */ diff --git a/lang/m2/comp/cstoper.c b/lang/m2/comp/cstoper.c new file mode 100644 index 00000000..03e0cf25 --- /dev/null +++ b/lang/m2/comp/cstoper.c @@ -0,0 +1,238 @@ +/* C O N S T A N T E X P R E S S I O N H A N D L I N G */ + +static char *RcsId = "$Header$"; + +#include +#include +#include +#include "def_sizes.h" +#include "idf.h" +#include "type.h" +#include "LLlex.h" +#include "node.h" +#include "Lpars.h" + +long mach_long_sign; /* sign bit of the machine long */ +int mach_long_size; /* size of long on this machine == sizeof(long) */ +long full_mask[MAXSIZE];/* full_mask[1] == 0XFF, full_mask[2] == 0XFFFF, .. */ +arith max_int; /* maximum integer on target machine */ +arith max_unsigned; /* maximum unsigned on target machine */ +arith max_longint; /* maximum longint on target machine */ + +#if 0 + +cstbin(expp, oper, expr) + struct expr **expp, *expr; +{ + /* The operation oper is performed on the constant + expressions *expp(ld) and expr(ct), and the result restored in + *expp. + */ + arith o1 = (*expp)->VL_VALUE; + arith o2 = expr->VL_VALUE; + int uns = (*expp)->ex_type->tp_unsigned; + + ASSERT(is_ld_cst(*expp) && is_cp_cst(expr)); + switch (oper) { + case '*': + o1 *= o2; + break; + case '/': + if (o2 == 0) { + expr_error(expr, "division by 0"); + break; + } + if (uns) { + /* this is more of a problem than you might + think on C compilers which do not have + unsigned long. + */ + if (o2 & mach_long_sign) {/* o2 > max_long */ + o1 = ! (o1 >= 0 || o1 < o2); + /* this is the unsigned test + o1 < o2 for o2 > max_long + */ + } + else { /* o2 <= max_long */ + long half, bit, hdiv, hrem, rem; + + half = (o1 >> 1) & ~mach_long_sign; + bit = o1 & 01; + /* now o1 == 2 * half + bit + and half <= max_long + and bit <= max_long + */ + hdiv = half / o2; + hrem = half % o2; + rem = 2 * hrem + bit; + o1 = 2 * hdiv + (rem < 0 || rem >= o2); + /* that is the unsigned compare + rem >= o2 for o2 <= max_long + */ + } + } + else + o1 /= o2; + break; + case '%': + if (o2 == 0) { + expr_error(expr, "modulo by 0"); + break; + } + if (uns) { + if (o2 & mach_long_sign) {/* o2 > max_long */ + o1 = (o1 >= 0 || o1 < o2) ? o1 : o1 - o2; + /* this is the unsigned test + o1 < o2 for o2 > max_long + */ + } + else { /* o2 <= max_long */ + long half, bit, hrem, rem; + + half = (o1 >> 1) & ~mach_long_sign; + bit = o1 & 01; + /* now o1 == 2 * half + bit + and half <= max_long + and bit <= max_long + */ + hrem = half % o2; + rem = 2 * hrem + bit; + o1 = (rem < 0 || rem >= o2) ? rem - o2 : rem; + } + } + else + o1 %= o2; + break; + case '+': + o1 += o2; + break; + case '-': + o1 -= o2; + break; + case LEFT: + o1 <<= o2; + break; + case RIGHT: + if (o2 == 0) + break; + if (uns) { + o1 >>= 1; + o1 & = ~mach_long_sign; + o1 >>= (o2-1); + } + else + o1 >>= o2; + break; + case '<': + if (uns) { + o1 = (o1 & mach_long_sign ? + (o2 & mach_long_sign ? o1 < o2 : 0) : + (o2 & mach_long_sign ? 1 : o1 < o2) + ); + } + else + o1 = o1 < o2; + break; + case '>': + if (uns) { + o1 = (o1 & mach_long_sign ? + (o2 & mach_long_sign ? o1 > o2 : 1) : + (o2 & mach_long_sign ? 0 : o1 > o2) + ); + } + else + o1 = o1 > o2; + break; + case LESSEQ: + if (uns) { + o1 = (o1 & mach_long_sign ? + (o2 & mach_long_sign ? o1 <= o2 : 0) : + (o2 & mach_long_sign ? 1 : o1 <= o2) + ); + } + else + o1 = o1 <= o2; + break; + case GREATEREQ: + if (uns) { + o1 = (o1 & mach_long_sign ? + (o2 & mach_long_sign ? o1 >= o2 : 1) : + (o2 & mach_long_sign ? 0 : o1 >= o2) + ); + } + else + o1 = o1 >= o2; + break; + case EQUAL: + o1 = o1 == o2; + break; + case NOTEQUAL: + o1 = o1 != o2; + break; + case '&': + o1 &= o2; + break; + case '|': + o1 |= o2; + break; + case '^': + o1 ^= o2; + break; + } + (*expp)->VL_VALUE = o1; + cut_size(*expp); + (*expp)->ex_flags |= expr->ex_flags; + (*expp)->ex_flags &= ~EX_PARENS; +} + +cut_size(expr) + struct expr *expr; +{ + /* The constant value of the expression expr is made to + conform to the size of the type of the expression. + */ + arith o1 = expr->VL_VALUE; + int uns = expr->ex_type->tp_unsigned; + int size = (int) expr->ex_type->tp_size; + + ASSERT(expr->ex_class == Value); + if (uns) { + if (o1 & ~full_mask[size]) + expr_warning(expr, + "overflow in unsigned constant expression"); + o1 &= full_mask[size]; + } + else { + int nbits = (int) (mach_long_size - size) * 8; + long remainder = o1 & ~full_mask[size]; + + if (remainder != 0 && remainder != ~full_mask[size]) + expr_warning(expr, "overflow in constant expression"); + o1 <<= nbits; /* ??? */ + o1 >>= nbits; + } + expr->VL_VALUE = o1; +} + +# endif + +init_cst() +{ + int i = 0; + arith bt = (arith)0; + + while (!(bt < 0)) { + bt = (bt << 8) + 0377, i++; + if (i == MAXSIZE) + fatal("array full_mask too small for this machine"); + full_mask[i] = bt; + } + mach_long_size = i; + mach_long_sign = 1 << (mach_long_size * 8 - 1); + if (sizeof(long) < mach_long_size) + fatal("sizeof (long) insufficient on this machine"); + + max_int = full_mask[int_size] & ~(1 << (int_size * 8 - 1)); + max_longint = full_mask[lint_size] & ~(1 << (lint_size * 8 - 1)); + max_unsigned = full_mask[int_size]; +} diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index 8a5e2999..549167ca 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -34,7 +34,7 @@ define(id, scope, kind) register struct def *df; register struct scope *sc; - DO_DEBUG(debug(4,"Defining identifier %s in scope %d", id->id_text, scope->sc_scope)); + DO_DEBUG(5, debug("Defining identifier \"%s\" in scope %d", id->id_text, scope->sc_scope)); df = lookup(id, scope->sc_scope); if ( /* Already in this scope */ df @@ -94,7 +94,7 @@ lookup(id, scope) df1 = 0; df = id->id_def; - DO_DEBUG(debug(4,"Looking for identifier %s in scope %d", id->id_text, scope)); + DO_DEBUG(5, debug("Looking for identifier \"%s\" in scope %d", id->id_text, scope)); while (df) { if (df->df_scope == scope) { if (df->df_kind == D_IMPORT) { diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index 85df442f..df39a13a 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -5,6 +5,7 @@ static char *RcsId = "$Header$"; #include #include #include +#include #include "idf.h" #include "def.h" #include "type.h" @@ -17,6 +18,10 @@ Enter(name, kind, type, pnam) char *name; struct type *type; { + /* Enter a definition for "name" with kind "kind" and type + "type" in the Current Scope. If it is a standard name, also + put its number in the definition structure. + */ struct idf *id; struct def *df; @@ -35,6 +40,13 @@ EnterIdList(idlist, kind, flags, type, scope) struct type *type; struct scope *scope; { + /* Put a list of identifiers in the symbol table. + They all have kind "kind", and type "type", and are put + in scope "scope". "flags" initializes the "df_flags" field + of the definition structure. + Also assign numbers to enumeration literals, and link + them together. + */ register struct def *df; struct def *first = 0, *last = 0; int assval = 0; @@ -45,15 +57,16 @@ EnterIdList(idlist, kind, flags, type, scope) df->df_flags = flags; if (kind == D_ENUM) { if (!first) first = df; - df->df_value.df_enum.en_val = assval++; - if (last) last->df_value.df_enum.en_next = df; + df->enm_val = assval++; + if (last) last->enm_next = df; last = df; } idlist = idlist->next; } if (last) { - /* Also meaning : enumeration */ - last->df_value.df_enum.en_next = 0; + /* Also meaning : kind == D_ENUM */ + assert(kind == D_ENUM); + last->enm_next = 0; type->enm_enums = first; type->enm_ncst = assval; } diff --git a/lang/m2/comp/error.c b/lang/m2/comp/error.c index 8998e166..e72269c4 100644 --- a/lang/m2/comp/error.c +++ b/lang/m2/comp/error.c @@ -46,10 +46,10 @@ extern char *symbol2str(); #ifdef DEBUG /*VARARGS2*/ -debug(level, fmt, args) +debug(fmt, args) char *fmt; { - if (level <= options['D']) _error(VDEBUG, NULLNODE, fmt, &args); + _error(VDEBUG, NULLNODE, fmt, &args); } #endif DEBUG diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index e35b7e33..7a841bc3 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -6,19 +6,30 @@ static char *RcsId = "$Header$"; #include #include #include +#include "main.h" #include "LLlex.h" #include "idf.h" #include "def.h" #include "scope.h" #include "node.h" +#include "const.h" +#include "type.h" +#include "debug.h" } -number(struct node **p;): +number(struct node **p;) +{ + struct type *tp; +} : [ - INTEGER + INTEGER { tp = dot.TOK_INT <= max_int ? + intorcard_type : card_type; + } | - REAL -] { *p = MkNode(Value, NULLNODE, NULLNODE, dot); } + REAL { tp = real_type; } +] { *p = MkNode(Value, NULLNODE, NULLNODE, &dot); + (*p)->nd_type = tp; + } ; qualident(int types; struct def **pdf; char *str; struct node **p;) @@ -27,15 +38,16 @@ qualident(int types; struct def **pdf; char *str; struct node **p;) int module; register struct def *df; struct def *lookfor(); + register struct node **pnd; + struct node *nd; } : IDENT { if (types) { df = lookfor(dot.TOK_IDF, CurrentScope, 1); *pdf = df; if (df->df_kind == D_ERROR) types = 0; } - if (p) { - *p = MkNode(Value, NULLNODE, NULLNODE,&dot); - } + nd = MkNode(Value, NULLNODE, NULLNODE, &dot); + pnd = &nd; } [ { if (types &&!(scope = has_selectors(df))) { @@ -44,12 +56,11 @@ qualident(int types; struct def **pdf; char *str; struct node **p;) } } /* selector */ - '.' { if (p) *p = MkNode(Link, *p, NULLNODE, &dot); } + '.' { *pnd = MkNode(Link,*pnd,NULLNODE,&dot); + pnd = &(*pnd)->nd_right; + } IDENT - { if (p) { - p = &((*p)->nd_right); - *p = MkNode(Value, NULLNODE, NULLNODE,&dot); - } + { *pnd = MkNode(Value,NULLNODE,NULLNODE,&dot); if (types) { module = (df->df_kind == D_MODULE); df = lookup(dot.TOK_IDF, scope); @@ -70,6 +81,8 @@ qualident(int types; struct def **pdf; char *str; struct node **p;) error("identifier \"%s\" is not a %s", df->df_idf->id_text, str); } + if (!p) FreeNode(nd); + else *p = nd; } ; @@ -98,22 +111,24 @@ ConstExpression(struct node **pnd;): * Changed rule in new Modula-2. * Check that the expression is a constant expression and evaluate! */ + { DO_DEBUG(3, + ( debug("Constant expression:"), + PrNode(*pnd))); + } ; expression(struct node **pnd;) { - struct node *nd; } : - SimpleExpression(&nd) + SimpleExpression(pnd) [ /* relation */ [ '=' | '#' | UNEQUAL | '<' | LESSEQUAL | '>' | GREATEREQUAL | IN ] - { nd = MkNode(Oper, nd, NULLNODE, &dot); } - SimpleExpression(&(nd->nd_right)) + { *pnd = MkNode(Oper, *pnd, NULLNODE, &dot); } + SimpleExpression(&((*pnd)->nd_right)) ]? - { *pnd = nd; } ; /* Inline in expression @@ -124,15 +139,19 @@ relation: SimpleExpression(struct node **pnd;) { - register struct node *nd; } : - [ '+' | '-' ]? - term(pnd) { nd = *pnd; } + [ + [ '+' | '-' ] + { *pnd = MkNode(Uoper, NULLNODE, NULLNODE, &dot); + pnd = &((*pnd)->nd_right); + } + ]? + term(pnd) [ /* AddOperator */ [ '+' | '-' | OR ] - { *pnd = nd = MkNode(Oper, nd, NULLNODE, &dot); } - term(&(nd->nd_right)) + { *pnd = MkNode(Oper, *pnd, NULLNODE, &dot); } + term(&((*pnd)->nd_right)) ]* ; @@ -144,14 +163,13 @@ AddOperator: term(struct node **pnd;) { - register struct node *nd; }: - factor(pnd) { nd = *pnd; } + factor(pnd) [ /* MulOperator */ [ '*' | '/' | DIV | MOD | AND | '&' ] - { *pnd = nd = MkNode(Oper, nd, NULLNODE, &dot); } - factor(&(nd->nd_right)) + { *pnd = MkNode(Oper, *pnd, NULLNODE, &dot); } + factor(&((*pnd)->nd_right)) ]* ; @@ -164,23 +182,29 @@ MulOperator: factor(struct node **p;) { struct def *df; + struct node *nd; } : qualident(0, &df, (char *) 0, p) [ designator_tail(p)? [ - { *p = MkNode(Call, p, NULLNODE, &dot); } + { *p = MkNode(Call, *p, NULLNODE, &dot); } ActualParameters(&((*p)->nd_right)) ]? - | { *p = MkNode(Call, p, NULLNODE, &dot); } - bare_set(&((*p)->nd_right)) + | + bare_set(&nd) + { nd->nd_left = *p; + *p = nd; + } ] | bare_set(p) | %default number(p) | - STRING { *p = MkNode(Value, NULLNODE, NULLNODE, &dot); } + STRING { *p = MkNode(Value, NULLNODE, NULLNODE, &dot); + (*p)->nd_type = string_type; + } | '(' expression(p) ')' | @@ -190,20 +214,17 @@ factor(struct node **p;) bare_set(struct node **pnd;) { - struct node **nd; + register struct node *nd; } : '{' { dot.tk_symb = SET; - *pnd = MkNode(Link, NULLNODE, NULLNODE, &dot); - nd = &((*pnd)->nd_left); + *pnd = nd = MkNode(Link, NULLNODE, NULLNODE, &dot); + nd->nd_type = bitset_type; } [ element(nd) - [ - ',' { *nd = MkNode(Link, *nd, NULLNODE, &dot); - nd = &((*nd)->nd_right); - } - element(nd) + [ { nd = nd->nd_right; } + ',' element(nd) ]* ]? '}' @@ -213,12 +234,19 @@ ActualParameters(struct node **pnd;): '(' ExpList(pnd)? ')' ; -element(struct node **pnd;): - expression(pnd) +element(struct node *nd;) +{ + struct node *nd1; +} : + expression(&nd1) [ - UPTO { *pnd = MkNode(Link, *pnd, NULLNODE, &dot);} - expression(&((*pnd)->nd_right)) + UPTO + { nd1 = MkNode(Link, nd1, NULLNODE, &dot);} + expression(&(nd1->nd_right)) ]? + { nd->nd_right = MkNode(Link, nd1, NULLNODE, &dot); + nd->nd_right->nd_symb = ','; + } ; designator(struct node **pnd;) diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index caa9c4ee..ea8af67a 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -47,7 +47,7 @@ main(argc, argv) #ifdef DEBUG print("Mod2 compiler -- Debug version\n"); #endif DEBUG - DO_DEBUG(debug(1,"Debugging level: %d", options['D'])); + DO_DEBUG(1, debug("Debugging level: %d", options['D'])); return !Compile(Nargv[1]); } @@ -56,7 +56,7 @@ Compile(src) { extern struct tokenname tkidf[]; - DO_DEBUG(debug(1,"Filename : %s", src)); + DO_DEBUG(1, debug("Filename : %s", src)); if (! InsertFile(src, (char **) 0, &src)) { fprint(STDERR,"%s: cannot open %s\n", ProgName, src); return 0; @@ -65,15 +65,13 @@ Compile(src) FileName = src; init_DEFPATH(); init_idf(); + init_cst(); reserve(tkidf); init_scope(); init_types(); add_standards(); #ifdef DEBUG - if (options['L']) - LexScan(); - else if (options['T']) - TimeScan(); + if (options['L']) LexScan(); else { #endif DEBUG (void) open_scope(CLOSEDSCOPE, 0); @@ -92,7 +90,7 @@ LexScan() { register int symb; - while ((symb = LLlex()) != EOI) { + while ((symb = LLlex()) > 0) { print(">>> %s ", symbol2str(symb)); switch(symb) { @@ -113,14 +111,10 @@ LexScan() break; default: - putchar('\n'); + print("\n"); } } } - -TimeScan() { - while (LLlex() != -1) /* nothing */; -} #endif Option(str) @@ -165,11 +159,7 @@ add_standards() D_TYPE, construct_type(PROCEDURE, NULLTYPE), 0); - tp = construct_type(SUBRANGE, int_type); - tp->sub_lb = 0; - tp->sub_ub = wrd_size * 8 - 1; - df = Enter("BITSET", D_TYPE, construct_type(SET, tp), 0); - df->df_type->tp_size = wrd_size; + df = Enter("BITSET", D_TYPE, bitset_type, 0); df = Enter("FALSE", D_ENUM, bool_type, 0); df->df_value.df_enum.en_val = 0; df->df_value.df_enum.en_next = Enter("TRUE", D_ENUM, bool_type, 0); diff --git a/lang/m2/comp/node.c b/lang/m2/comp/node.c index dcd5a9ee..b50e30d0 100644 --- a/lang/m2/comp/node.c +++ b/lang/m2/comp/node.c @@ -5,10 +5,13 @@ static char *RcsId = "$Header$"; #include #include #include +#include +#include "main.h" #include "def.h" #include "type.h" #include "LLlex.h" #include "node.h" +#include "debug.h" struct node *h_node; /* header of free list */ @@ -26,6 +29,7 @@ MkNode(class, left, right, token) nd->nd_token = *token; nd->nd_class = class; nd->nd_type = NULLTYPE; + DO_DEBUG(4,(debug("Create node:"), PrNode(nd))); return nd; } @@ -39,3 +43,28 @@ FreeNode(nd) if (nd->nd_right) FreeNode(nd->nd_right); free_node(nd); } + +#ifdef DEBUG + +extern char *symbol2str(); + +static +printnode(nd) + register struct node *nd; +{ + fprint(STDERR, "("); + if (nd) { + printnode(nd->nd_left); + fprint(STDERR, " %s ", symbol2str(nd->nd_symb)); + printnode(nd->nd_right); + } + fprint(STDERR, ")"); +} + +PrNode(nd) + struct node *nd; +{ + printnode(nd); + fprint(STDERR, "\n"); +} +#endif DEBUG diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 5c17fd6f..5e33d6f1 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -114,7 +114,7 @@ DefinitionModule if (!SYSTEMModule) open_scope(CLOSEDSCOPE, 0); df->mod_scope = CurrentScope->sc_scope; DefinitionModule = 1; - DO_DEBUG(debug(1, "Definition module \"%s\"", id->id_text)); + DO_DEBUG(1, debug("Definition module \"%s\"", id->id_text)); } ';' import(0)* diff --git a/lang/m2/comp/scope.C b/lang/m2/comp/scope.C index 1a2badcd..697e810c 100644 --- a/lang/m2/comp/scope.C +++ b/lang/m2/comp/scope.C @@ -11,6 +11,7 @@ static char *RcsId = "$Header$"; #include "scope.h" #include "type.h" #include "def.h" +#include "main.h" #include "debug.h" static int maxscope; /* maximum assigned scope number */ @@ -35,7 +36,7 @@ open_scope(scopetype, scope) sc->sc_scope = scope == 0 ? ++maxscope : scope; sc->sc_forw = 0; sc->sc_def = 0; assert(scopetype == OPENSCOPE || scopetype == CLOSEDSCOPE); - DO_DEBUG(debug(1, "Opening a %s scope", + DO_DEBUG(1, debug("Opening a %s scope", scopetype == OPENSCOPE ? "open" : "closed")); sc1 = CurrentScope; if (scopetype == CLOSEDSCOPE) { @@ -55,7 +56,7 @@ close_scope() register struct scope *sc = CurrentScope; assert(sc != 0); - DO_DEBUG(debug(1, "Closing a scope")); + DO_DEBUG(1, debug("Closing a scope")); if (sc->sc_forw) rem_forwards(sc->sc_forw); if (sc->next && (sc->next->sc_scope == 0)) { struct scope *sc1 = sc; diff --git a/lang/m2/comp/tokenname.c b/lang/m2/comp/tokenname.c index b4ce2b5c..9e0ca1cb 100644 --- a/lang/m2/comp/tokenname.c +++ b/lang/m2/comp/tokenname.c @@ -80,6 +80,7 @@ struct tokenname tkinternal[] = { /* internal keywords */ {ENUMERATION, ""}, {ERRONEOUS, ""}, {PROCVAR, ""}, + {INTORCARD, ""}, {0, "0"} }; diff --git a/lang/m2/comp/type.H b/lang/m2/comp/type.H index 2de207c9..c67a8367 100644 --- a/lang/m2/comp/type.H +++ b/lang/m2/comp/type.H @@ -77,7 +77,10 @@ extern struct type *longreal_type, *word_type, *address_type, - *error_type; + *intorcard_type, + *string_type, + *bitset_type, + *error_type; /* All from type.c */ extern int wrd_align, @@ -86,7 +89,7 @@ extern int real_align, lreal_align, ptr_align, - record_align; + record_align; /* All from type.c */ extern arith wrd_size, @@ -94,14 +97,14 @@ extern arith lint_size, real_size, lreal_size, - ptr_size; + ptr_size; /* All from type.c */ extern arith - align(); + align(); /* type.c */ struct type *create_type(), *construct_type(), - *standard_type(); + *standard_type(); /* All from type.c */ #define NULLTYPE ((struct type *) 0) diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index 30097075..c5648613 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -44,6 +44,9 @@ struct type *longreal_type, *word_type, *address_type, + *intorcard_type, + *string_type, + *bitset_type, *error_type; struct paramlist *h_paramlist; @@ -123,6 +126,8 @@ standard_type(fund, align, size) init_types() { + register struct type *tp; + char_type = standard_type(CHAR, 1, (arith) 1); bool_type = standard_type(BOOLEAN, 1, (arith) 1); int_type = standard_type(INTEGER, int_align, int_size); @@ -131,9 +136,15 @@ init_types() real_type = standard_type(REAL, real_align, real_size); longreal_type = standard_type(LONGREAL, lreal_align, lreal_size); word_type = standard_type(WORD, wrd_align, wrd_size); + intorcard_type = standard_type(INTORCARD, int_align, int_size); + string_type = standard_type(STRING, 1, (arith) -1); address_type = construct_type(POINTER, word_type); + tp = construct_type(SUBRANGE, int_type); + tp->sub_lb = 0; + tp->sub_ub = wrd_size * 8 - 1; + bitset_type = construct_type(SET, tp); + bitset_type->tp_size = wrd_size; error_type = standard_type(ERRONEOUS, 1, (arith) 1); - } int diff --git a/lang/m2/comp/typequiv.c b/lang/m2/comp/typequiv.c index 96f9e38a..b1bf08af 100644 --- a/lang/m2/comp/typequiv.c +++ b/lang/m2/comp/typequiv.c @@ -52,3 +52,32 @@ TstProcEquiv(tp1, tp2) if (p1 != p2) return 0; return 1; } + +int +TstCompat(tp1, tp2) + register struct type *tp1, *tp2; +{ + /* test if two types are compatible. See section 6.3 of the + Modula-2 Report for a definition of "compatible". + */ + if (TstTypeEquiv(tp1, tp2)) return 1; + if (tp2->tp_fund == SUBRANGE) tp1 = tp1->next; + if (tp2->tp_fund == SUBRANGE) tp1 = tp1->next; + return tp1 == tp2 + || + ( tp1 == address_type + && + ( tp2 == card_type + || tp2 == intorcard_type + || tp2->tp_fund == POINTER + ) + ) + || + ( tp2 == address_type + && + ( tp1 == card_type + || tp1 == intorcard_type + || tp1->tp_fund == POINTER + ) + ); +} From 41b9a340d8b8f78bcdc824cf6aff213f47d35ae8 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 7 Apr 1986 22:15:08 +0000 Subject: [PATCH 0170/1625] newer version --- lang/m2/comp/cstoper.c | 158 ++++++++++++++++++++++++++--------------- lang/m2/comp/node.H | 7 +- 2 files changed, 105 insertions(+), 60 deletions(-) diff --git a/lang/m2/comp/cstoper.c b/lang/m2/comp/cstoper.c index 03e0cf25..80398a22 100644 --- a/lang/m2/comp/cstoper.c +++ b/lang/m2/comp/cstoper.c @@ -1,4 +1,4 @@ -/* C O N S T A N T E X P R E S S I O N H A N D L I N G */ +/* C O N S T A N T E X P R E S S I O N H A N D L I N G */ static char *RcsId = "$Header$"; @@ -14,33 +14,66 @@ static char *RcsId = "$Header$"; long mach_long_sign; /* sign bit of the machine long */ int mach_long_size; /* size of long on this machine == sizeof(long) */ -long full_mask[MAXSIZE];/* full_mask[1] == 0XFF, full_mask[2] == 0XFFFF, .. */ +long full_mask[MAXSIZE];/* full_mask[1] == 0xFF, full_mask[2] == 0xFFFF, .. */ arith max_int; /* maximum integer on target machine */ arith max_unsigned; /* maximum unsigned on target machine */ arith max_longint; /* maximum longint on target machine */ -#if 0 +cstunary(expp, oper) + register struct node *expp; +{ + /* The unary operation oper is performed on the constant + expression expp, and the result restored in expp. + */ + arith o1 = expp->nd_INT; + + switch(oper) { + case '+': + return; + case '-': + o1 = -o1; + break; + case NOT: + o1 = !o1; + break; + default: + assert(0); + } + expp->nd_INT = o1; + cut_size(expp); +} cstbin(expp, oper, expr) - struct expr **expp, *expr; + register struct node *expp, *expr; { - /* The operation oper is performed on the constant - expressions *expp(ld) and expr(ct), and the result restored in - *expp. + /* The binary operation oper is performed on the constant + expressions expp and expr, and the result restored in + expp. */ - arith o1 = (*expp)->VL_VALUE; - arith o2 = expr->VL_VALUE; - int uns = (*expp)->ex_type->tp_unsigned; + arith o1 = expp->nd_INT; + arith o2 = expr->nd_INT; + int uns = expp->nd_type != int_type; - ASSERT(is_ld_cst(*expp) && is_cp_cst(expr)); + assert(expp->nd_class == Value && expr->nd_class == Value); switch (oper) { + case IN: + /* ??? */ + return; case '*': + if (expp->nd_type->tp_fund == SET) { + /* ??? */ + return; + } o1 *= o2; break; case '/': + assert(expp->nd_type->tp_fund == SET); + /* ??? */ + return; + case DIV: if (o2 == 0) { - expr_error(expr, "division by 0"); - break; + node_error(expr, "division by 0"); + return; } if (uns) { /* this is more of a problem than you might @@ -74,10 +107,10 @@ cstbin(expp, oper, expr) else o1 /= o2; break; - case '%': + case MOD: if (o2 == 0) { - expr_error(expr, "modulo by 0"); - break; + node_error(expr, "modulo by 0"); + return; } if (uns) { if (o2 & mach_long_sign) {/* o2 > max_long */ @@ -104,24 +137,18 @@ cstbin(expp, oper, expr) o1 %= o2; break; case '+': + if (expp->nd_type->tp_fund == SET) { + /* ??? */ + return; + } o1 += o2; break; case '-': - o1 -= o2; - break; - case LEFT: - o1 <<= o2; - break; - case RIGHT: - if (o2 == 0) - break; - if (uns) { - o1 >>= 1; - o1 & = ~mach_long_sign; - o1 >>= (o2-1); + if (expp->nd_type->tp_fund == SET) { + /* ??? */ + return; } - else - o1 >>= o2; + o1 -= o2; break; case '<': if (uns) { @@ -143,7 +170,11 @@ cstbin(expp, oper, expr) else o1 = o1 > o2; break; - case LESSEQ: + case LESSEQUAL: + if (expp->nd_type->tp_fund == SET) { + /* ??? */ + return; + } if (uns) { o1 = (o1 & mach_long_sign ? (o2 & mach_long_sign ? o1 <= o2 : 0) : @@ -153,7 +184,11 @@ cstbin(expp, oper, expr) else o1 = o1 <= o2; break; - case GREATEREQ: + case GREATEREQUAL: + if (expp->nd_type->tp_fund == SET) { + /* ??? */ + return; + } if (uns) { o1 = (o1 & mach_long_sign ? (o2 & mach_long_sign ? o1 >= o2 : 1) : @@ -163,59 +198,64 @@ cstbin(expp, oper, expr) else o1 = o1 >= o2; break; - case EQUAL: + case '=': + if (expp->nd_type->tp_fund == SET) { + /* ??? */ + return; + } o1 = o1 == o2; break; - case NOTEQUAL: + case '#': + if (expp->nd_type->tp_fund == SET) { + /* ??? */ + return; + } o1 = o1 != o2; break; - case '&': - o1 &= o2; + case AND: + o1 = o1 && o2; break; - case '|': - o1 |= o2; - break; - case '^': - o1 ^= o2; + case OR: + o1 = o1 || o2; break; + default: + assert(0); } - (*expp)->VL_VALUE = o1; - cut_size(*expp); - (*expp)->ex_flags |= expr->ex_flags; - (*expp)->ex_flags &= ~EX_PARENS; + expp->nd_INT = o1; + cut_size(expp); } cut_size(expr) - struct expr *expr; + register struct node *expr; { /* The constant value of the expression expr is made to conform to the size of the type of the expression. */ - arith o1 = expr->VL_VALUE; - int uns = expr->ex_type->tp_unsigned; - int size = (int) expr->ex_type->tp_size; + arith o1 = expr->nd_INT; + int uns = expr->nd_type == card_type || expr->nd_type == intorcard_type; + int size = expr->nd_type->tp_size; - ASSERT(expr->ex_class == Value); + assert(expr->nd_class == Value); if (uns) { - if (o1 & ~full_mask[size]) - expr_warning(expr, - "overflow in unsigned constant expression"); + if (o1 & ~full_mask[size]) { + node_warning(expr, + "overflow in constant expression"); + } o1 &= full_mask[size]; } else { int nbits = (int) (mach_long_size - size) * 8; long remainder = o1 & ~full_mask[size]; - if (remainder != 0 && remainder != ~full_mask[size]) - expr_warning(expr, "overflow in constant expression"); - o1 <<= nbits; /* ??? */ + if (remainder != 0 && remainder != ~full_mask[size]) { + node_warning(expr, "overflow in constant expression"); + } + o1 <<= nbits; o1 >>= nbits; } - expr->VL_VALUE = o1; + expr->nd_INT = o1; } -# endif - init_cst() { int i = 0; diff --git a/lang/m2/comp/node.H b/lang/m2/comp/node.H index 2dd99b4e..ac9921f0 100644 --- a/lang/m2/comp/node.H +++ b/lang/m2/comp/node.H @@ -13,7 +13,12 @@ struct node { #define Call 4 /* cast or procedure - or function call */ #define Link 5 struct type *nd_type; /* type of this node */ - struct token nd_token; + union { + struct token ndu_token; + char *ndu_set; /* Pointer to a set constant */ + } nd_val; +#define nd_token nd_val.ndu_token +#define nd_set nd_val.ndu_set #define nd_symb nd_token.tk_symb #define nd_lineno nd_token.tk_lineno #define nd_filename nd_token.tk_filename From 1b014ed75ad41640438751c6716022ab7703a021 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 8 Apr 1986 18:15:46 +0000 Subject: [PATCH 0171/1625] newer version --- lang/m2/comp/LLlex.c | 1 + lang/m2/comp/Makefile | 20 +- lang/m2/comp/chk_expr.c | 379 ++++++++++++++++++++++++++++++++++++++ lang/m2/comp/cstoper.c | 98 +++++----- lang/m2/comp/declar.g | 21 ++- lang/m2/comp/def.H | 4 +- lang/m2/comp/def.c | 23 ++- lang/m2/comp/defmodule.c | 6 + lang/m2/comp/enter.c | 6 +- lang/m2/comp/expression.g | 51 ++--- lang/m2/comp/main.c | 13 +- lang/m2/comp/misc.c | 8 +- lang/m2/comp/node.H | 18 +- lang/m2/comp/node.c | 1 - lang/m2/comp/program.g | 5 +- lang/m2/comp/scope.C | 56 +++--- lang/m2/comp/typequiv.c | 3 +- 17 files changed, 543 insertions(+), 170 deletions(-) create mode 100644 lang/m2/comp/chk_expr.c diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index 91817c10..b0eb90e1 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -223,6 +223,7 @@ again: register char *np = &buf[1]; /* allow a '-' to be added */ + buf[0] = '-'; *np++ = ch; LoadChar(ch); diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index c24ff052..4175c01b 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -18,7 +18,7 @@ LOBJ = tokenfile.o program.o declar.o expression.o statement.o COBJ = LLlex.o LLmessage.o char.o error.o main.o \ symbol2str.o tokenname.o idf.o input.o type.o def.o \ scope.o misc.o enter.o defmodule.o typequiv.o node.o \ - cstoper.o + cstoper.o chk_expr.o OBJ = $(COBJ) $(LOBJ) Lpars.o GENFILES= tokenfile.c \ program.c declar.c expression.c statement.c \ @@ -39,6 +39,9 @@ main: $(OBJ) Makefile clean: rm -f $(OBJ) $(GENFILES) LLfiles +lint: LLfiles lintlist + lint $(INCLUDES) `cat lintlist` + tokenfile.g: tokenname.c make.tokfile make.tokfile tokenfile.g @@ -74,23 +77,24 @@ LLlex.o: LLlex.h Lpars.h class.h f_info.h idf.h input.h LLmessage.o: LLlex.h Lpars.h idf.h char.o: class.h error.o: LLlex.h f_info.h input.h main.h node.h -main.o: LLlex.h Lpars.h debug.h def.h f_info.h idf.h input.h main.h scope.h standards.h type.h +main.o: LLlex.h Lpars.h debug.h def.h f_info.h idf.h input.h scope.h standards.h tokenname.h type.h symbol2str.o: Lpars.h tokenname.o: Lpars.h idf.h tokenname.h idf.o: idf.h input.o: f_info.h input.h type.o: LLlex.h Lpars.h def.h def_sizes.h idf.h node.h type.h def.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h type.h -scope.o: LLlex.h debug.h def.h idf.h main.h scope.h type.h -misc.o: LLlex.h f_info.h idf.h misc.h +scope.o: LLlex.h debug.h def.h idf.h node.h scope.h type.h +misc.o: LLlex.h f_info.h idf.h misc.h node.h enter.o: LLlex.h def.h idf.h node.h scope.h type.h -defmodule.o: LLlex.h def.h f_info.h idf.h input.h scope.h +defmodule.o: LLlex.h debug.h def.h f_info.h idf.h input.h scope.h typequiv.o: Lpars.h def.h type.h -node.o: LLlex.h debug.h def.h main.h node.h type.h -cstoper.o: Lpars.h def_sizes.h idf.h node.h type.h +node.o: LLlex.h debug.h def.h node.h type.h +cstoper.o: LLlex.h Lpars.h def_sizes.h idf.h node.h type.h +chk_expr.o: LLlex.h Lpars.h def.h idf.h node.h scope.h type.h tokenfile.o: Lpars.h program.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h type.h declar.o: LLlex.h Lpars.h def.h idf.h misc.h node.h scope.h type.h -expression.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h +expression.o: LLlex.h Lpars.h const.h debug.h def.h idf.h node.h scope.h type.h statement.o: LLlex.h Lpars.h node.h Lpars.o: Lpars.h diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c new file mode 100644 index 00000000..a4e5fa51 --- /dev/null +++ b/lang/m2/comp/chk_expr.c @@ -0,0 +1,379 @@ +/* E X P R E S S I O N C H E C K I N G */ + +static char *RcsId = "$Header$"; + +/* Check expressions, and try to evaluate them as far as possible. +*/ +#include +#include +#include +#include "idf.h" +#include "type.h" +#include "def.h" +#include "LLlex.h" +#include "node.h" +#include "Lpars.h" +#include "scope.h" + +int +chk_expr(expp, const) + register struct node *expp; +{ + /* Check the expression indicated by expp for semantic errors, + identify identifiers used in it, replace constants by + their value. + */ + + switch(expp->nd_class) { + case Oper: + return chk_expr(expp->nd_left, const) && + chk_expr(expp->nd_right, const) && + chk_oper(expp, const); + case Uoper: + return chk_expr(expp->nd_right, const) && + chk_uoper(expp, const); + case Value: + switch(expp->nd_symb) { + case REAL: + case STRING: + case INTEGER: + return 1; + default: + assert(0); + } + break; + case Xset: + return chk_set(expp, const); + case Name: + return chk_name(expp, const); + case Call: + return chk_call(expp, const); + case Link: + return chk_name(expp, const); + } + /*NOTREACHED*/ +} + +int +chk_set(expp, const) + register struct node *expp; +{ + /* ??? */ + return 1; +} + +int +chk_call(expp, const) + register struct node *expp; +{ + /* ??? */ + return 1; +} + +struct def * +findname(expp) + register struct node *expp; +{ + /* Find the name indicated by "expp", starting from the current + scope. + */ + register struct def *df; + struct def *lookfor(); + register struct node *nd; + int scope; + int module; + + if (expp->nd_class == Name) { + return lookfor(expp, CurrentScope, 1); + } + assert(expp->nd_class == Link && expp->nd_symb == '.'); + assert(expp->nd_left->nd_class == Name); + df = lookfor(expp->nd_left, CurrentScope, 1); + if (df->df_kind == D_ERROR) return df; + nd = expp; + while (nd->nd_class == Link) { + struct node *nd1; + + if (!(scope = has_selectors(df))) { + node_error(nd, "identifier \"%s\" has no selectors", + df->df_idf->id_text); + return ill_df; + } + nd = nd->nd_right; + if (nd->nd_class == Name) nd1 = nd; + else nd1 = nd->nd_left; + module = (df->df_kind == D_MODULE); + df = lookup(nd1->nd_IDF, scope); + if (!df) { + id_not_declared(nd1); + return ill_df; + } + if (module && !(df->df_flags&(D_EXPORTED|D_QEXPORTED))) { +node_error(nd1, "identifier \"%s\" not exprted from qualifying module", +df->df_idf->id_text); + } + } + return df; +} + +int +chk_name(expp, const) + register struct node *expp; +{ + register struct def *df; + int retval = 1; + + df = findname(expp); + if (df->df_kind == D_ERROR) { + retval = 0; + } + expp->nd_type = df->df_type; + if (df->df_kind == D_ENUM || df->df_kind == D_CONST) { + if (expp->nd_left) FreeNode(expp->nd_left); + if (expp->nd_right) FreeNode(expp->nd_right); + if (df->df_kind == D_ENUM) { + expp->nd_left = expp->nd_right = 0; + expp->nd_class = Value; + expp->nd_INT = df->enm_val; + expp->nd_symb = INTEGER; + } + else if (df->df_kind == D_CONST) { + *expp = *(df->con_const); + } + } + else if (const) { + node_error(expp, "constant expected"); + retval = 0; + } + return retval; +} + +int +chk_oper(expp, const) + register struct node *expp; +{ + /* Check a binary operation. If "const" is set, also check + that it is constant. + The code is ugly ! + */ + register struct type *tpl = expp->nd_left->nd_type; + register struct type *tpr = expp->nd_right->nd_type; + char *symbol2str(); + int errval = 1; + + if (tpl == intorcard_type) { + if (tpr == int_type || tpr == card_type) { + expp->nd_left->nd_type = tpl = tpr; + } + } + if (tpr == intorcard_type) { + if (tpl == int_type || tpl == card_type) { + expp->nd_right->nd_type = tpr = tpl; + } + } + + if (expp->nd_symb == IN) { + /* Handle this one specially */ + expp->nd_type == bool_type; + if (tpr->tp_fund != SET) { +node_error(expp, "RHS of IN operator not a SET type"); + return 0; + } + if (!TstCompat(tpl, tpr->next)) { +node_error(expp, "IN operator: type of LHS not compatible with element type of RHS"); + return 0; + } + return 1; + } + + if (tpl->tp_fund == SUBRANGE) tpl = tpl->next; + expp->nd_type = tpl; + + if (!TstCompat(tpl, tpr)) { +node_error(expp, "Incompatible types for operator \"%s\"", symbol2str(expp->nd_symb)); + return 0; + } + + switch(expp->nd_symb) { + case '+': + case '-': + case '*': + switch(tpl->tp_fund) { + case INTEGER: + case INTORCARD: + case CARDINAL: + case LONGINT: + case SET: + if (expp->nd_left->nd_class == Value && + expp->nd_right->nd_class == Value) { + cstbin(expp); + } + return 1; + case REAL: + case LONGREAL: + if (const) { + errval = 2; + break; + } + return 1; + } + break; + case '/': + switch(tpl->tp_fund) { + case SET: + if (expp->nd_left->nd_class == Value && + expp->nd_right->nd_class == Value) { + cstbin(expp); + } + return 1; + case REAL: + case LONGREAL: + if (const) { + errval = 2; + break; + } + return 1; + } + break; + case DIV: + case MOD: + switch(tpl->tp_fund) { + case INTEGER: + case INTORCARD: + case CARDINAL: + case LONGINT: + if (expp->nd_left->nd_class == Value && + expp->nd_right->nd_class == Value) { + cstbin(expp); + } + return 1; + } + break; + case OR: + case AND: + if (tpl == bool_type) { + if (expp->nd_left->nd_class == Value && + expp->nd_right->nd_class == Value) { + cstbin(expp); + } + return 1; + } + errval = 3; + break; + case '=': + case '#': + case GREATEREQUAL: + case LESSEQUAL: + case '<': + case '>': + switch(tpl->tp_fund) { + case SET: + if (expp->nd_symb == '<' || expp->nd_symb == '>') { + break; + } + case INTEGER: + case INTORCARD: + case LONGINT: + case CARDINAL: + case ENUMERATION: /* includes boolean */ + case CHAR: + if (expp->nd_left->nd_class == Value && + expp->nd_right->nd_class == Value) { + cstbin(expp); + } + return 1; + case POINTER: + if (!(expp->nd_symb == '=' || expp->nd_symb == '#')) { + break; + } + /* Fall through */ + case REAL: + case LONGREAL: + if (const) { + errval = 2; + break; + } + return 1; + } + default: + assert(0); + } + switch(errval) { + case 1: + node_error(expp,"Operator \"%s\": illegal operand type(s)", symbol2str(expp->nd_symb)); + break; + case 2: + node_error(expp, "Expression not constant"); + break; + case 3: + node_error(expp, "BOOLEAN type(s) expected"); + break; + } + return 0; +} + +int +chk_uoper(expp, const) + register struct node *expp; +{ + /* Check an unary operation. If "const" is set, also check that + it can be evaluated compile-time. + */ + register struct type *tpr = expp->nd_right->nd_type; + + if (tpr->tp_fund == SUBRANGE) tpr = tpr->next; + expp->nd_type = tpr; + + switch(expp->nd_symb) { + case '+': + switch(tpr->tp_fund) { + case INTEGER: + case LONGINT: + case REAL: + case LONGREAL: + case CARDINAL: + case INTORCARD: + expp->nd_token = expp->nd_right->nd_token; + FreeNode(expp->nd_right); + expp->nd_right = 0; + return 1; + } + break; + case '-': + switch(tpr->tp_fund) { + case INTEGER: + case LONGINT: + case INTORCARD: + if (expp->nd_right->nd_class == Value) { + cstunary(expp); + } + return 1; + case REAL: + case LONGREAL: + if (expp->nd_right->nd_class == Value) { + expp->nd_token = expp->nd_right->nd_token; + if (*(expp->nd_REL) == '-') { + expp->nd_REL++; + } + else expp->nd_REL--; + FreeNode(expp->nd_right); + expp->nd_right = 0; + } + return 1; + } + break; + case NOT: + if (tpr == bool_type) { + if (expp->nd_right->nd_class == Value) { + cstunary(expp); + } + return 1; + } + break; + default: + assert(0); + } + node_error(expp, "Illegal operand for unary operator \"%s\"", + symbol2str(expp->nd_symb)); + return 0; +} diff --git a/lang/m2/comp/cstoper.c b/lang/m2/comp/cstoper.c index 80398a22..c276cf5a 100644 --- a/lang/m2/comp/cstoper.c +++ b/lang/m2/comp/cstoper.c @@ -19,17 +19,17 @@ arith max_int; /* maximum integer on target machine */ arith max_unsigned; /* maximum unsigned on target machine */ arith max_longint; /* maximum longint on target machine */ -cstunary(expp, oper) +cstunary(expp) register struct node *expp; { - /* The unary operation oper is performed on the constant - expression expp, and the result restored in expp. + /* The unary operation in "expp" is performed on the constant + expression below it, and the result restored in expp. */ - arith o1 = expp->nd_INT; + arith o1 = expp->nd_right->nd_INT; - switch(oper) { + switch(expp->nd_symb) { case '+': - return; + break; case '-': o1 = -o1; break; @@ -39,40 +39,37 @@ cstunary(expp, oper) default: assert(0); } + expp->nd_class = Value; + expp->nd_token = expp->nd_right->nd_token; expp->nd_INT = o1; cut_size(expp); + FreeNode(expp->nd_right); + expp->nd_right = 0; } -cstbin(expp, oper, expr) - register struct node *expp, *expr; +cstbin(expp) + register struct node *expp; { - /* The binary operation oper is performed on the constant - expressions expp and expr, and the result restored in + /* The binary operation in "expp" is performed on the constant + expressions below it, and the result restored in expp. */ - arith o1 = expp->nd_INT; - arith o2 = expr->nd_INT; + arith o1 = expp->nd_left->nd_INT; + arith o2 = expp->nd_right->nd_INT; int uns = expp->nd_type != int_type; - assert(expp->nd_class == Value && expr->nd_class == Value); - switch (oper) { - case IN: - /* ??? */ + assert(expp->nd_class == Oper); + if (expp->nd_right->nd_type->tp_fund == SET) { + cstset(expp); return; + } + switch (expp->nd_symb) { case '*': - if (expp->nd_type->tp_fund == SET) { - /* ??? */ - return; - } o1 *= o2; break; - case '/': - assert(expp->nd_type->tp_fund == SET); - /* ??? */ - return; case DIV: if (o2 == 0) { - node_error(expr, "division by 0"); + node_error(expp, "division by 0"); return; } if (uns) { @@ -109,7 +106,7 @@ cstbin(expp, oper, expr) break; case MOD: if (o2 == 0) { - node_error(expr, "modulo by 0"); + node_error(expp, "modulo by 0"); return; } if (uns) { @@ -137,17 +134,9 @@ cstbin(expp, oper, expr) o1 %= o2; break; case '+': - if (expp->nd_type->tp_fund == SET) { - /* ??? */ - return; - } o1 += o2; break; case '-': - if (expp->nd_type->tp_fund == SET) { - /* ??? */ - return; - } o1 -= o2; break; case '<': @@ -171,10 +160,6 @@ cstbin(expp, oper, expr) o1 = o1 > o2; break; case LESSEQUAL: - if (expp->nd_type->tp_fund == SET) { - /* ??? */ - return; - } if (uns) { o1 = (o1 & mach_long_sign ? (o2 & mach_long_sign ? o1 <= o2 : 0) : @@ -185,10 +170,6 @@ cstbin(expp, oper, expr) o1 = o1 <= o2; break; case GREATEREQUAL: - if (expp->nd_type->tp_fund == SET) { - /* ??? */ - return; - } if (uns) { o1 = (o1 & mach_long_sign ? (o2 & mach_long_sign ? o1 >= o2 : 1) : @@ -199,17 +180,9 @@ cstbin(expp, oper, expr) o1 = o1 >= o2; break; case '=': - if (expp->nd_type->tp_fund == SET) { - /* ??? */ - return; - } o1 = o1 == o2; break; case '#': - if (expp->nd_type->tp_fund == SET) { - /* ??? */ - return; - } o1 = o1 != o2; break; case AND: @@ -221,8 +194,33 @@ cstbin(expp, oper, expr) default: assert(0); } + expp->nd_class = Value; + expp->nd_token = expp->nd_right->nd_token; expp->nd_INT = o1; cut_size(expp); + FreeNode(expp->nd_left); + FreeNode(expp->nd_right); + expp->nd_left = expp->nd_right = 0; +} + +cstset(expp) + register struct node *expp; +{ + switch(expp->nd_symb) { + case IN: + case '+': + case '-': + case '*': + case '/': + case GREATEREQUAL: + case LESSEQUAL: + case '=': + case '#': + /* ??? */ + break; + default: + assert(0); + } } cut_size(expr) diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 09e77d3f..a67df311 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -5,6 +5,7 @@ static char *RcsId = "$Header$"; #include #include +#include #include #include "idf.h" #include "LLlex.h" @@ -122,7 +123,7 @@ FPSection(int doparams; struct paramlist **ppr;) if (doparams) { EnterIdList(FPList, D_VARIABLE, VARp, tp, CurrentScope); } - *ppr = ParamList(FPList, tp); + *ppr = ParamList(FPList, tp, VARp); FreeNode(FPList); } ; @@ -160,7 +161,7 @@ TypeDeclaration tp->tp_fund != POINTER) { error("Opaque type \"%s\" is not a pointer type", df->df_idf->id_text); } - + } ; @@ -181,18 +182,18 @@ type(struct type **ptp;): SimpleType(struct type **ptp;) { struct def *df; - struct type *tp; } : qualident(D_TYPE | D_HTYPE, &df, "type", (struct node **) 0) [ /* nothing */ + { *ptp = df->df_type; } | SubrangeType(ptp) /* The subrange type is given a base type by the qualident (this is new modula-2). */ { - chk_basesubrange(*ptp, tp); + chk_basesubrange(*ptp, df->df_type); } ] | @@ -250,7 +251,7 @@ SubrangeType(struct type **ptp;) { /* For the time being: */ tp = int_type; - tp = construct_type(SUBRANGE, tp, (arith) 0); + tp = construct_type(SUBRANGE, tp); *ptp = tp; } ; @@ -352,7 +353,7 @@ SetType(struct type **ptp;) } : SET OF SimpleType(&tp) { - *ptp = construct_type(SET, tp, (arith) 0 /* ???? */); + *ptp = construct_type(SET, tp); } ; @@ -365,6 +366,7 @@ PointerType(struct type **ptp;) struct type *tp; struct def *df; struct def *lookfor(); + struct node *nd; } : POINTER TO [ %if ( (df = lookup(dot.TOK_IDF, CurrentScope->sc_scope))) @@ -380,8 +382,9 @@ PointerType(struct type **ptp;) } else tp = df->df_type; } - | %if (df = lookfor(dot.TOK_IDF, CurrentScope, 0), - df->df_kind == D_MODULE) + | %if ( nd = new_node(), nd->nd_token = dot, + df = lookfor(nd, CurrentScope, 0), free_node(nd), + df->df_kind == D_MODULE) type(&tp) | IDENT @@ -449,7 +452,7 @@ ConstantDeclaration }: IDENT { id = dot.TOK_IDF; } '=' ConstExpression(&nd){ df = define(id, CurrentScope, D_CONST); - /* ???? */ + df->con_const = nd; } ; diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H index 99c34b9c..274f9290 100644 --- a/lang/m2/comp/def.H +++ b/lang/m2/comp/def.H @@ -15,8 +15,8 @@ struct variable { }; struct constant { - arith co_const; /* result of a constant expression */ -#define con_const df_value.df_variable.con_const + struct node *co_const; /* result of a constant expression */ +#define con_const df_value.df_constant.co_const }; struct enumval { diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index 549167ca..55df98c8 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -6,11 +6,11 @@ static char *RcsId = "$Header$"; #include #include #include +#include "main.h" #include "Lpars.h" #include "def.h" #include "type.h" #include "idf.h" -#include "main.h" #include "scope.h" #include "LLlex.h" #include "node.h" @@ -26,13 +26,12 @@ struct def *ill_df = &illegal_def; struct def * define(id, scope, kind) register struct idf *id; - struct scope *scope; + register struct scope *scope; { /* Declare an identifier in a scope, but first check if it already has been defined. If so, error message. */ register struct def *df; - register struct scope *sc; DO_DEBUG(5, debug("Defining identifier \"%s\" in scope %d", id->id_text, scope->sc_scope)); df = lookup(id, scope->sc_scope); @@ -157,7 +156,6 @@ Import(ids, idn, local) identifiers defined in this module. */ register struct def *df; - register struct idf *id = 0; int scope; int kind; int imp_kind; @@ -165,19 +163,18 @@ Import(ids, idn, local) #define FROM_ENCLOSING 1 struct def *lookfor(), *GetDefinitionModule(); - if (idn) id = idn->nd_IDF; kind = D_IMPORT; scope = enclosing(CurrentScope)->sc_scope; - if (!id) imp_kind = FROM_ENCLOSING; + if (!idn) imp_kind = FROM_ENCLOSING; else { imp_kind = FROM_MODULE; - if (local) df = lookfor(id, enclosing(CurrentScope), 1); - else df = GetDefinitionModule(id); + if (local) df = lookfor(idn, enclosing(CurrentScope), 1); + else df = GetDefinitionModule(idn->nd_IDF); if (df->df_kind != D_MODULE) { /* enter all "ids" with type D_ERROR */ kind = D_ERROR; if (df->df_kind != D_ERROR) { -node_error(idn, "identifier \"%s\" does not represent a module", id->id_text); +node_error(idn, "identifier \"%s\" does not represent a module", idn->nd_IDF->id_text); } } else scope = df->mod_scope; @@ -197,14 +194,14 @@ ids->nd_IDF->id_text); } else { if (local) { - df = lookfor(ids->nd_IDF, - enclosing(CurrentScope), 0); + df = lookfor(ids, enclosing(CurrentScope), 0); } else df = GetDefinitionModule(ids->nd_IDF); if (df->df_kind == D_ERROR) { node_error(ids, "identifier \"%s\" not visible in enclosing scope", ids->nd_IDF->id_text); } } + DO_DEBUG(2, debug("importing \"%s\", kind %d", ids->nd_IDF->id_text, df->df_kind)); define(ids->nd_IDF, CurrentScope, kind)->imp_def = df; if (df->df_kind == D_TYPE && df->df_type->tp_fund == ENUMERATION) { @@ -218,12 +215,14 @@ ids->nd_IDF->id_text); exprt_literals(df, toscope) register struct def *df; - register struct scope *toscope; + struct scope *toscope; { /* A list of enumeration literals is exported. This is implemented as an import from the scope "toscope". */ + DO_DEBUG(2, debug("enumeration import:")); while (df) { + DO_DEBUG(2, debug(df->df_idf->id_text)); define(df->df_idf, toscope, D_IMPORT)->imp_def = df; df = df->enm_next; } diff --git a/lang/m2/comp/defmodule.c b/lang/m2/comp/defmodule.c index b781adc6..3b4e2092 100644 --- a/lang/m2/comp/defmodule.c +++ b/lang/m2/comp/defmodule.c @@ -11,6 +11,11 @@ static char *RcsId = "$Header$"; #include "def.h" #include "LLlex.h" #include "f_info.h" +#include "debug.h" + +#ifdef DEBUG +long sys_filesize(); +#endif GetFile(name) char *name; @@ -30,6 +35,7 @@ GetFile(name) fatal("Could'nt find a DEFINITION MODULE for \"%s\"", name); } LineNumber = 1; + DO_DEBUG(1, debug("File %s : %ld characters", FileName, sys_filesize(FileName))); } struct def * diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index df39a13a..8ae0e285 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -74,7 +74,7 @@ EnterIdList(idlist, kind, flags, type, scope) struct def * lookfor(id, scope, give_error) - struct idf *id; + struct node *id; struct scope *scope; { /* Look for an identifier in the visibility range started by @@ -86,10 +86,10 @@ lookfor(id, scope, give_error) register struct scope *sc = scope; while (sc) { - df = lookup(id, sc->sc_scope); + df = lookup(id->nd_IDF, sc->sc_scope); if (df) return df; sc = nextvisible(sc); } if (give_error) id_not_declared(id); - return define(id, scope, D_ERROR); + return define(id->nd_IDF, scope, D_ERROR); } diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index 7a841bc3..c3db7e18 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -6,7 +6,6 @@ static char *RcsId = "$Header$"; #include #include #include -#include "main.h" #include "LLlex.h" #include "idf.h" #include "def.h" @@ -34,52 +33,29 @@ number(struct node **p;) qualident(int types; struct def **pdf; char *str; struct node **p;) { - int scope; - int module; register struct def *df; - struct def *lookfor(); register struct node **pnd; struct node *nd; + struct def *findname(); } : - IDENT { if (types) { - df = lookfor(dot.TOK_IDF, CurrentScope, 1); - *pdf = df; - if (df->df_kind == D_ERROR) types = 0; - } - nd = MkNode(Value, NULLNODE, NULLNODE, &dot); + IDENT { nd = MkNode(Name, NULLNODE, NULLNODE, &dot); pnd = &nd; } [ - { if (types &&!(scope = has_selectors(df))) { - types = 0; - *pdf = ill_df; - } - } /* selector */ '.' { *pnd = MkNode(Link,*pnd,NULLNODE,&dot); pnd = &(*pnd)->nd_right; } IDENT - { *pnd = MkNode(Value,NULLNODE,NULLNODE,&dot); - if (types) { - module = (df->df_kind == D_MODULE); - df = lookup(dot.TOK_IDF, scope); - if (!df) { - types = 0; - df = ill_df; - id_not_declared(dot.TOK_IDF); - } - else - if (module && - !(df->df_flags&(D_EXPORTED|D_QEXPORTED))) { - error("identifier \"%s\" not exported from qualifying module", dot.TOK_IDF->id_text); - } - } - } + { *pnd = MkNode(Name,NULLNODE,NULLNODE,&dot); } ]* - { if (types && !(types & df->df_kind)) { - error("identifier \"%s\" is not a %s", + { if (types) { + *pdf = df = findname(nd); + if (df->df_kind != D_ERROR && + !(types & df->df_kind)) { + error("identifier \"%s\" is not a %s", df->df_idf->id_text, str); + } } if (!p) FreeNode(nd); else *p = nd; @@ -114,6 +90,7 @@ ConstExpression(struct node **pnd;): { DO_DEBUG(3, ( debug("Constant expression:"), PrNode(*pnd))); + (void) chk_expr(*pnd, 1); } ; @@ -209,7 +186,7 @@ factor(struct node **p;) '(' expression(p) ')' | NOT { *p = MkNode(Uoper, NULLNODE, NULLNODE, &dot); } - factor(&((*p)->nd_left)) + factor(&((*p)->nd_right)) ; bare_set(struct node **pnd;) @@ -218,7 +195,7 @@ bare_set(struct node **pnd;) } : '{' { dot.tk_symb = SET; - *pnd = nd = MkNode(Link, NULLNODE, NULLNODE, &dot); + *pnd = nd = MkNode(Xset, NULLNODE, NULLNODE, &dot); nd->nd_type = bitset_type; } [ @@ -261,9 +238,9 @@ designator_tail(struct node **pnd;): visible_designator_tail(pnd) [ /* selector */ - '.' { *pnd = MkNode(Oper, *pnd, NULLNODE, &dot); } + '.' { *pnd = MkNode(Link, *pnd, NULLNODE, &dot); } IDENT { (*pnd)->nd_right = - MkNode(Value, NULLNODE, NULLNODE, &dot); + MkNode(Name, NULLNODE, NULLNODE, &dot); } | visible_designator_tail(pnd) diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index ea8af67a..c20c43f4 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -10,12 +10,12 @@ static char *RcsId = "$Header$"; #include "idf.h" #include "LLlex.h" #include "Lpars.h" -#include "main.h" #include "debug.h" #include "type.h" #include "def.h" #include "scope.h" #include "standards.h" +#include "tokenname.h" char options[128]; int DefinitionModule; @@ -126,7 +126,6 @@ Option(str) add_standards() { register struct def *df; - register struct type *tp; struct def *Enter(); (void) Enter("ABS", D_STDFUNC, NULLTYPE, S_ABS); @@ -161,11 +160,11 @@ add_standards() 0); df = Enter("BITSET", D_TYPE, bitset_type, 0); df = Enter("FALSE", D_ENUM, bool_type, 0); - df->df_value.df_enum.en_val = 0; - df->df_value.df_enum.en_next = Enter("TRUE", D_ENUM, bool_type, 0); - df = df->df_value.df_enum.en_next; - df->df_value.df_enum.en_val = 1; - df->df_value.df_enum.en_next = 0; + df->enm_val = 0; + df->enm_next = Enter("TRUE", D_ENUM, bool_type, 0); + df = df->enm_next; + df->enm_val = 1; + df->enm_next = 0; } init_DEFPATH() diff --git a/lang/m2/comp/misc.c b/lang/m2/comp/misc.c index e0063bb6..70c4f824 100644 --- a/lang/m2/comp/misc.c +++ b/lang/m2/comp/misc.c @@ -8,6 +8,7 @@ static char *RcsId = "$Header$"; #include "misc.h" #include "LLlex.h" #include "idf.h" +#include "node.h" match_id(id1, id2) struct idf *id1, *id2; @@ -40,12 +41,13 @@ gen_anon_idf() } id_not_declared(id) - struct idf *id; + struct node *id; { /* The identifier "id" is not declared. If it is not generated, give an error message */ - if (!is_anon_idf(id)) { - error("identifier \"%s\" not declared", id->id_text); + if (!is_anon_idf(id->nd_IDF)) { + node_error(id, + "identifier \"%s\" not declared", id->nd_IDF->id_text); } } diff --git a/lang/m2/comp/node.H b/lang/m2/comp/node.H index ac9921f0..8f0c451e 100644 --- a/lang/m2/comp/node.H +++ b/lang/m2/comp/node.H @@ -7,18 +7,28 @@ struct node { #define nd_left next struct node *nd_right; int nd_class; /* kind of node */ -#define Value 1 /* idf or constant */ +#define Value 1 /* constant */ #define Oper 2 /* binary operator */ #define Uoper 3 /* unary operator */ #define Call 4 /* cast or procedure - or function call */ -#define Link 5 +#define Name 5 /* a qualident */ +#define Set 6 /* a set constant */ +#define Xset 7 /* a set */ +#define Def 8 /* an identified name */ +#define Link 11 struct type *nd_type; /* type of this node */ union { - struct token ndu_token; - char *ndu_set; /* Pointer to a set constant */ + struct token ndu_token; /* (Value, Oper, Uoper, Call, Name, + Link) + */ + arith *ndu_set; /* pointer to a set constant (Set) */ + struct def *ndu_def; /* pointer to definition structure for + identified name (Def) + */ } nd_val; #define nd_token nd_val.ndu_token #define nd_set nd_val.ndu_set +#define nd_def nd_val.ndu_def #define nd_symb nd_token.tk_symb #define nd_lineno nd_token.tk_lineno #define nd_filename nd_token.tk_filename diff --git a/lang/m2/comp/node.c b/lang/m2/comp/node.c index b50e30d0..35cd416d 100644 --- a/lang/m2/comp/node.c +++ b/lang/m2/comp/node.c @@ -6,7 +6,6 @@ static char *RcsId = "$Header$"; #include #include #include -#include "main.h" #include "def.h" #include "type.h" #include "LLlex.h" diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 5e33d6f1..483232cb 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -6,8 +6,8 @@ static char *RcsId = "$Header$"; #include #include #include -#include "idf.h" #include "main.h" +#include "idf.h" #include "LLlex.h" #include "scope.h" #include "def.h" @@ -148,13 +148,12 @@ DefinitionModule definition { struct def *df; - struct type *tp; } : CONST [ ConstantDeclaration ';' ]* | TYPE [ IDENT { df = define(dot.TOK_IDF, CurrentScope, D_TYPE); } - [ '=' type(&tp) + [ '=' type(&(df->df_type)) | /* empty */ /* Here, the exported type has a hidden implementation. diff --git a/lang/m2/comp/scope.C b/lang/m2/comp/scope.C index 697e810c..5162923a 100644 --- a/lang/m2/comp/scope.C +++ b/lang/m2/comp/scope.C @@ -11,7 +11,7 @@ static char *RcsId = "$Header$"; #include "scope.h" #include "type.h" #include "def.h" -#include "main.h" +#include "node.h" #include "debug.h" static int maxscope; /* maximum assigned scope number */ @@ -34,7 +34,8 @@ open_scope(scopetype, scope) register struct scope *sc1; sc->sc_scope = scope == 0 ? ++maxscope : scope; - sc->sc_forw = 0; sc->sc_def = 0; + sc->sc_forw = 0; + sc->sc_def = 0; assert(scopetype == OPENSCOPE || scopetype == CLOSEDSCOPE); DO_DEBUG(1, debug("Opening a %s scope", scopetype == OPENSCOPE ? "open" : "closed")); @@ -42,32 +43,14 @@ open_scope(scopetype, scope) if (scopetype == CLOSEDSCOPE) { sc1 = new_scope(); sc1->sc_scope = 0; /* Pervasive scope nr */ - sc1->sc_forw = 0; sc1->sc_def = 0; + sc1->sc_forw = 0; + sc1->sc_def = 0; sc1->next = CurrentScope; } sc->next = sc1; CurrentScope = sc; } -static rem_forwards(); - -close_scope() -{ - register struct scope *sc = CurrentScope; - - assert(sc != 0); - DO_DEBUG(1, debug("Closing a scope")); - if (sc->sc_forw) rem_forwards(sc->sc_forw); - if (sc->next && (sc->next->sc_scope == 0)) { - struct scope *sc1 = sc; - - sc = sc->next; - free_scope(sc1); - } - CurrentScope = sc->next; - free_scope(sc); -} - init_scope() { register struct scope *sc = new_scope(); @@ -86,7 +69,7 @@ uniq_scope() struct forwards { struct forwards *next; - struct token fo_tok; + struct node fo_tok; struct type **fo_ptyp; }; @@ -103,12 +86,29 @@ Forward(tk, ptp) */ register struct forwards *f = new_forwards(); - f->fo_tok = *tk; + f->fo_tok.nd_token = *tk; f->fo_ptyp = ptp; f->next = CurrentScope->sc_forw; CurrentScope->sc_forw = f; } +close_scope() +{ + register struct scope *sc = CurrentScope; + + assert(sc != 0); + DO_DEBUG(1, debug("Closing a scope")); + if (sc->sc_forw) rem_forwards(sc->sc_forw); + if (sc->next && (sc->next->sc_scope == 0)) { + struct scope *sc1 = sc; + + sc = sc->next; + free_scope(sc1); + } + CurrentScope = sc->next; + free_scope(sc); +} + static rem_forwards(fo) struct forwards *fo; @@ -116,21 +116,17 @@ rem_forwards(fo) /* When closing a scope, all forward references must be resolved */ register struct forwards *f; - struct token savetok; register struct def *df; struct def *lookfor(); - savetok = dot; while (f = fo) { - dot = f->fo_tok; - df = lookfor(dot.TOK_IDF, CurrentScope, 1); + df = lookfor(&(f->fo_tok), CurrentScope, 1); if (!(df->df_kind & (D_TYPE | D_HTYPE | D_ERROR))) { - error("identifier \"%s\" not a type", + node_error(&(f->fo_tok), "identifier \"%s\" not a type", df->df_idf->id_text); } *(f->fo_ptyp) = df->df_type; fo = f->next; free_forwards(f); } - dot = savetok; } diff --git a/lang/m2/comp/typequiv.c b/lang/m2/comp/typequiv.c index b1bf08af..9331f036 100644 --- a/lang/m2/comp/typequiv.c +++ b/lang/m2/comp/typequiv.c @@ -79,5 +79,6 @@ TstCompat(tp1, tp2) || tp1 == intorcard_type || tp1->tp_fund == POINTER ) - ); + ) + ; } From 88370d543313c748ae53d906690ac2f6da5de6be Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 8 Apr 1986 23:34:10 +0000 Subject: [PATCH 0172/1625] newer version --- lang/m2/comp/chk_expr.c | 82 ++++++++++++++++++++++++++++++++++++++- lang/m2/comp/const.h | 3 +- lang/m2/comp/cstoper.c | 4 +- lang/m2/comp/declar.g | 21 +++------- lang/m2/comp/defmodule.c | 1 + lang/m2/comp/expression.g | 1 + lang/m2/comp/type.c | 82 +++++++++++++++++++++++++++++++++++++++ lang/m2/comp/typequiv.c | 18 ++++++++- 8 files changed, 190 insertions(+), 22 deletions(-) diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index a4e5fa51..49179616 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -50,6 +50,8 @@ chk_expr(expp, const) return chk_call(expp, const); case Link: return chk_name(expp, const); + default: + assert(0); } /*NOTREACHED*/ } @@ -58,7 +60,85 @@ int chk_set(expp, const) register struct node *expp; { - /* ??? */ + struct type *tp; + struct def *df; + register struct node *nd; + extern struct def *findname(); + + assert(expp->nd_symb == SET); + + /* First determine the type of the set + */ + if (expp->nd_left) { + /* A type was given. Check it out + */ + df = findname(expp->nd_left); + if ((df->df_kind != D_TYPE && df->df_kind != D_ERROR) || + (df->df_type->tp_fund != SET)) { + node_error(expp, "Illegal set type"); + return 0; + } + tp = df->df_type; + } + else tp = bitset_type; + + /* Now check the elements given + */ + nd = expp->nd_right; + while (nd) { + assert(nd->nd_class == Link && nd->nd_symb == ','); + if (!chk_el(nd->nd_left, const, tp->next, 0)) return 0; + nd = nd->nd_right; + } + return 1; +} + +int +chk_el(expp, const, tp, level) + struct node *expp; + struct type *tp; +{ + /* Check elements of a set. This routine may call itself + recursively, but only once. + */ + if (expp->nd_class == Link && expp->nd_symb == UPTO) { + /* { ... , expr1 .. expr2, ... } */ + if (level) { + node_error(expp, "Illegal set element"); + return 0; + } + if (!chk_el(expp->nd_left, const, tp, 1) || + !chk_el(expp->nd_right, const, tp, 1)) { + return 0; + } + if (expp->nd_left->nd_class == Value && + expp->nd_right->nd_class == Value) { + if (expp->nd_left->nd_INT > expp->nd_right->nd_INT) { +node_error(expp, "Lower bound exceeds upper bound in range"); + return 0; + } + } + return 1; + } + if (!chk_expr(expp, const)) return 0; + if (!TstCompat(tp, expp->nd_type)) { + node_error(expp, "Set element has incompatible type"); + return 0; + } + if (expp->nd_class == Value) { + if ((tp->tp_fund != ENUMERATION && + (expp->nd_INT < tp->sub_lb || expp->nd_INT > tp->sub_ub)) + || + (tp->tp_fund == ENUMERATION && + (expp->nd_INT < 0 || expp->nd_INT > tp->enm_ncst)) + ) { + node_error(expp, "Set element out of range"); +#ifdef DEBUG + debug("%d (%d, %d)", (int) expp->nd_INT, (int) tp->sub_lb, (int) tp->sub_ub); +#endif + return 0; + } + } return 1; } diff --git a/lang/m2/comp/const.h b/lang/m2/comp/const.h index 02f7e28f..65330a70 100644 --- a/lang/m2/comp/const.h +++ b/lang/m2/comp/const.h @@ -8,5 +8,4 @@ extern int mach_long_size; /* size of long on this machine == sizeof(long) */ extern arith max_int, /* maximum integer on target machine */ - max_unsigned, /* maximum unsigned on target machine */ - max_longint; /* maximum longint on target machine */ + max_unsigned; /* maximum unsigned on target machine */ diff --git a/lang/m2/comp/cstoper.c b/lang/m2/comp/cstoper.c index c276cf5a..42948f02 100644 --- a/lang/m2/comp/cstoper.c +++ b/lang/m2/comp/cstoper.c @@ -267,10 +267,10 @@ init_cst() } mach_long_size = i; mach_long_sign = 1 << (mach_long_size * 8 - 1); - if (sizeof(long) < mach_long_size) + if (int_size > mach_long_size) { fatal("sizeof (long) insufficient on this machine"); + } max_int = full_mask[int_size] & ~(1 << (int_size * 8 - 1)); - max_longint = full_mask[lint_size] & ~(1 << (lint_size * 8 - 1)); max_unsigned = full_mask[int_size]; } diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index a67df311..b2bfe9b4 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -233,8 +233,8 @@ IdentList(struct node **p;) SubrangeType(struct type **ptp;) { - struct type *tp; - struct node *nd1 = 0, *nd2 = 0; + struct node *nd1, *nd2; + extern struct type *subr_type(); }: /* This is not exactly the rule in the new report, but see @@ -243,17 +243,7 @@ SubrangeType(struct type **ptp;) '[' ConstExpression(&nd1) UPTO ConstExpression(&nd2) ']' - /* - Evaluate the expressions. Check that they are indeed constant. - ??? - Leave the basetype of the subrange in tp; - */ - { - /* For the time being: */ - tp = int_type; - tp = construct_type(SUBRANGE, tp); - *ptp = tp; - } + { *ptp = subr_type(nd1, nd2); } ; ArrayType(struct type **ptp;) @@ -350,10 +340,11 @@ CaseLabels SetType(struct type **ptp;) { struct type *tp; + struct type *set_type(); } : SET OF SimpleType(&tp) - { - *ptp = construct_type(SET, tp); + { + *ptp = set_type(tp); } ; diff --git a/lang/m2/comp/defmodule.c b/lang/m2/comp/defmodule.c index 3b4e2092..8dd739a0 100644 --- a/lang/m2/comp/defmodule.c +++ b/lang/m2/comp/defmodule.c @@ -25,6 +25,7 @@ GetFile(name) */ extern char *DEFPATH[]; char buf[256]; + char *strcpy(), *strcat(); (void) strcpy(buf, name); if (strlen(buf) > 10) { diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index c3db7e18..93bf3ec1 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -91,6 +91,7 @@ ConstExpression(struct node **pnd;): ( debug("Constant expression:"), PrNode(*pnd))); (void) chk_expr(*pnd, 1); + DO_DEBUG(3, PrNode(*pnd)); } ; diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index c5648613..972dede9 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -13,6 +13,8 @@ static char *RcsId = "$Header$"; #include "idf.h" #include "LLlex.h" #include "node.h" +#include "const.h" +#include "debug.h" /* To be created dynamically in main() from defaults or from command line parameters. @@ -129,6 +131,7 @@ init_types() register struct type *tp; char_type = standard_type(CHAR, 1, (arith) 1); + char_type->enm_ncst = 256; bool_type = standard_type(BOOLEAN, 1, (arith) 1); int_type = standard_type(INTEGER, int_align, int_size); longint_type = standard_type(LONGINT, lint_align, lint_size); @@ -217,8 +220,87 @@ chk_basesubrange(tp, base) else if (base != card_type && base != int_type) { error("Illegal base for a subrange"); } + else if (base == int_type && tp->next == card_type && + (tp->sub_ub > max_int || tp->sub_ub)) { + error("Upperbound to large for type INTEGER"); + } else if (base != tp->next && base != int_type) { error("Specified base does not conform"); } tp->next = base; } + +struct type * +subr_type(lb, ub) + struct node *lb, *ub; +{ + /* Construct a subrange type from the constant expressions + indicated by "lb" and "ub", but first perform some + checks + */ + register struct type *tp = lb->nd_type; + + if (!TstCompat(lb->nd_type, ub->nd_type)) { + node_error(ub, "Types of subrange bounds not compatible"); + return error_type; + } + + if (tp->tp_fund == SUBRANGE) tp = tp->next; + if (tp == intorcard_type) tp = card_type; /* lower bound > 0 */ + + /* Check base type + */ + if (tp != int_type && tp != card_type && tp != char_type && + tp->tp_fund != ENUMERATION) { + /* BOOLEAN is also an ENUMERATION type + */ + node_error(ub, "Illegal base type for subrange"); + return error_type; + } + + /* Check bounds + */ + if (lb->nd_INT > ub->nd_INT) { + node_error(ub, "Lower bound exceeds upper bound"); + } + + /* Now construct resulting type + */ + tp = construct_type(SUBRANGE, tp); + tp->sub_lb = lb->nd_INT; + tp->sub_ub = ub->nd_INT; + DO_DEBUG(2,debug("Creating subrange type %ld-%ld", (long)lb->nd_INT,(long)ub->nd_INT)); + return tp; +} +#define MAX_SET 1024 /* ??? Maximum number of elements in a set */ + +struct type * +set_type(tp) + struct type *tp; +{ + /* Construct a set type with base type "tp", but first + perform some checks + */ + int lb, ub; + + if (tp->tp_fund == SUBRANGE) { + if ((lb = tp->sub_lb) < 0 || (ub = tp->sub_ub) > MAX_SET - 1) { + error("Set type limits exceeded"); + return error_type; + } + } + else if (tp->tp_fund == ENUMERATION || tp == char_type) { + lb = 0; + if ((ub = tp->enm_ncst - 1) > MAX_SET - 1) { + error("Set type limits exceeded"); + return error_type; + } + } + else { + error("illegal base type for set"); + return error_type; + } + tp = construct_type(SET, tp); + tp->tp_size = align(((ub - lb) + 7)/8, wrd_align); + return tp; +} diff --git a/lang/m2/comp/typequiv.c b/lang/m2/comp/typequiv.c index 9331f036..02f184cd 100644 --- a/lang/m2/comp/typequiv.c +++ b/lang/m2/comp/typequiv.c @@ -19,6 +19,10 @@ TstTypeEquiv(tp1, tp2) */ return tp1 == tp2 + || + tp1 == error_type + || + tp2 == error_type || ( tp1 && tp1->tp_fund == PROCEDURE @@ -61,9 +65,19 @@ TstCompat(tp1, tp2) Modula-2 Report for a definition of "compatible". */ if (TstTypeEquiv(tp1, tp2)) return 1; - if (tp2->tp_fund == SUBRANGE) tp1 = tp1->next; - if (tp2->tp_fund == SUBRANGE) tp1 = tp1->next; + if (tp1->tp_fund == SUBRANGE) tp1 = tp1->next; + if (tp2->tp_fund == SUBRANGE) tp2 = tp2->next; return tp1 == tp2 + || + ( tp1 == intorcard_type + && + (tp2 == int_type || tp2 == card_type) + ) + || + ( tp2 == intorcard_type + && + (tp1 == int_type || tp1 == card_type) + ) || ( tp1 == address_type && From 6ef38e34837ca2f38a438a8391c48024daf7a97d Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 8 Apr 1986 23:51:11 +0000 Subject: [PATCH 0173/1625] newer version --- lang/m2/comp/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index 4175c01b..2dee7e1a 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -82,7 +82,7 @@ symbol2str.o: Lpars.h tokenname.o: Lpars.h idf.h tokenname.h idf.o: idf.h input.o: f_info.h input.h -type.o: LLlex.h Lpars.h def.h def_sizes.h idf.h node.h type.h +type.o: LLlex.h Lpars.h const.h debug.h def.h def_sizes.h idf.h node.h type.h def.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h type.h scope.o: LLlex.h debug.h def.h idf.h node.h scope.h type.h misc.o: LLlex.h f_info.h idf.h misc.h node.h From 6ca5eb658de82e798c03c671f0510b802fe801d2 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 9 Apr 1986 18:14:49 +0000 Subject: [PATCH 0174/1625] safety commit --- lang/m2/comp/LLlex.h | 2 + lang/m2/comp/Makefile | 2 +- lang/m2/comp/chk_expr.c | 273 ++++++++++++++++++++++++++++++-------- lang/m2/comp/const.h | 3 +- lang/m2/comp/cstoper.c | 94 +++++++++++-- lang/m2/comp/declar.g | 2 - lang/m2/comp/expression.g | 37 +++--- lang/m2/comp/main.c | 38 +++--- lang/m2/comp/node.H | 18 +-- lang/m2/comp/program.g | 5 + lang/m2/comp/statement.g | 8 +- lang/m2/comp/type.H | 5 +- lang/m2/comp/type.c | 8 +- 13 files changed, 365 insertions(+), 130 deletions(-) diff --git a/lang/m2/comp/LLlex.h b/lang/m2/comp/LLlex.h index 92bc5979..db49e6b9 100644 --- a/lang/m2/comp/LLlex.h +++ b/lang/m2/comp/LLlex.h @@ -16,6 +16,8 @@ struct token { struct string tk_str; /* STRING */ arith tk_int; /* INTEGER */ char *tk_real; /* REAL */ + arith *tk_set; /* only used in parse tree node */ + struct def *tk_def; /* only used in parse tree node */ } tk_data; }; diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index 2dee7e1a..74969ac1 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -91,7 +91,7 @@ defmodule.o: LLlex.h debug.h def.h f_info.h idf.h input.h scope.h typequiv.o: Lpars.h def.h type.h node.o: LLlex.h debug.h def.h node.h type.h cstoper.o: LLlex.h Lpars.h def_sizes.h idf.h node.h type.h -chk_expr.o: LLlex.h Lpars.h def.h idf.h node.h scope.h type.h +chk_expr.o: LLlex.h Lpars.h const.h def.h idf.h node.h scope.h standards.h type.h tokenfile.o: Lpars.h program.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h type.h declar.o: LLlex.h Lpars.h def.h idf.h misc.h node.h scope.h type.h diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index 49179616..3b0cd8ba 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -7,6 +7,7 @@ static char *RcsId = "$Header$"; #include #include #include +#include #include "idf.h" #include "type.h" #include "def.h" @@ -14,6 +15,8 @@ static char *RcsId = "$Header$"; #include "node.h" #include "Lpars.h" #include "scope.h" +#include "const.h" +#include "standards.h" int chk_expr(expp, const) @@ -60,10 +63,13 @@ int chk_set(expp, const) register struct node *expp; { + /* Check the legality of a SET aggregate, and try to evaluate it + compile time. Unfortunately this is all rather complicated. + */ struct type *tp; struct def *df; register struct node *nd; - extern struct def *findname(); + arith *set; assert(expp->nd_symb == SET); @@ -72,7 +78,9 @@ chk_set(expp, const) if (expp->nd_left) { /* A type was given. Check it out */ - df = findname(expp->nd_left); + (void) findname(expp->nd_left); + assert(expp->nd_left->nd_class == Def); + df = expp->nd_left->nd_def; if ((df->df_kind != D_TYPE && df->df_kind != D_ERROR) || (df->df_type->tp_fund != SET)) { node_error(expp, "Illegal set type"); @@ -82,48 +90,79 @@ chk_set(expp, const) } else tp = bitset_type; - /* Now check the elements given + /* Now check the elements given, and try to compute a constant set. */ + set = (arith *) Malloc(tp->tp_size * sizeof(arith) / wrd_size); nd = expp->nd_right; while (nd) { assert(nd->nd_class == Link && nd->nd_symb == ','); - if (!chk_el(nd->nd_left, const, tp->next, 0)) return 0; + if (!chk_el(nd->nd_left, const, tp->next, &set)) return 0; nd = nd->nd_right; } + expp->nd_type = tp; + assert(!const || set); + if (set) { + /* Yes, in was a constant set, and we managed to compute it! + */ + expp->nd_class = Set; + expp->nd_set = set; + FreeNode(expp->nd_left); + FreeNode(expp->nd_right); + expp->nd_left = expp->nd_right = 0; + } return 1; } int -chk_el(expp, const, tp, level) - struct node *expp; +chk_el(expp, const, tp, set) + register struct node *expp; struct type *tp; + arith **set; { /* Check elements of a set. This routine may call itself - recursively, but only once. + recursively. + Also try to compute the set! */ if (expp->nd_class == Link && expp->nd_symb == UPTO) { - /* { ... , expr1 .. expr2, ... } */ - if (level) { - node_error(expp, "Illegal set element"); - return 0; - } - if (!chk_el(expp->nd_left, const, tp, 1) || - !chk_el(expp->nd_right, const, tp, 1)) { + /* { ... , expr1 .. expr2, ... } + First check expr1 and expr2, and try to compute them. + */ + if (!chk_el(expp->nd_left, const, tp, set) || + !chk_el(expp->nd_right, const, tp, set)) { return 0; } if (expp->nd_left->nd_class == Value && expp->nd_right->nd_class == Value) { + /* We have a constant range. Put all elements in the + set + */ + register int i; + if (expp->nd_left->nd_INT > expp->nd_right->nd_INT) { node_error(expp, "Lower bound exceeds upper bound in range"); - return 0; + return rem_set(set); } + + if (*set) for (i = expp->nd_left->nd_INT + 1; + i < expp->nd_right->nd_INT; i++) { + (*set)[i/wrd_bits] |= (1 << (i % wrd_bits)); + } + } + else if (*set) { + free(*set); + *set = 0; } return 1; } - if (!chk_expr(expp, const)) return 0; + + /* Here, a single element is checked + */ + if (!chk_expr(expp, const)) { + return rem_set(set); + } if (!TstCompat(tp, expp->nd_type)) { node_error(expp, "Set element has incompatible type"); - return 0; + return rem_set(set); } if (expp->nd_class == Value) { if ((tp->tp_fund != ENUMERATION && @@ -133,24 +172,104 @@ node_error(expp, "Lower bound exceeds upper bound in range"); (expp->nd_INT < 0 || expp->nd_INT > tp->enm_ncst)) ) { node_error(expp, "Set element out of range"); -#ifdef DEBUG - debug("%d (%d, %d)", (int) expp->nd_INT, (int) tp->sub_lb, (int) tp->sub_ub); -#endif - return 0; + return rem_set(set); } + if (*set) (*set)[expp->nd_INT/wrd_bits] |= (1 << (expp->nd_INT%wrd_bits)); } return 1; } +int +rem_set(set) + arith **set; +{ + /* This routine is only used for error exits of chk_el. + It frees the set indicated by "set", and returns 0. + */ + if (*set) { + free((char *) *set); + *set = 0; + } + return 0; +} + int chk_call(expp, const) register struct node *expp; { - /* ??? */ - return 1; + register struct type *tp; + register struct node *left; + + expp->nd_type = error_type; + (void) findname(expp->nd_left); + left = expp->nd_left; + tp = left->nd_type; + + if (tp == error_type) return 0; + if (left->nd_class == Def && + (left->nd_def->df_kind & (D_HTYPE|D_TYPE|D_HIDDEN))) { + /* A type cast. This is of course not portable. + No runtime action. Remove it. + */ + if (!expp->nd_right || + (expp->nd_right->nd_symb == ',')) { +node_error(expp, "Only one parameter expected in type cast"); + return 0; + } + if (! chk_expr(expp->nd_right, const)) return 0; + if (expp->nd_right->nd_type->tp_size != + left->nd_type->tp_size) { +node_error(expp, "Size of type in type cast does not match size of operand"); + return 0; + } + expp->nd_right->nd_type = left->nd_type; + left = expp->nd_right; + FreeNode(expp->nd_left); + *expp = *(expp->nd_right); + left->nd_left = left->nd_right = 0; + FreeNode(left); + return 1; + } + + if ((left->nd_class == Def && left->nd_def->df_kind == D_PROCEDURE) || + tp->tp_fund == PROCVAR) { + /* A procedure call. it may also be a call to a + standard procedure + */ + if (tp == std_type) { + assert(left->nd_class == Def); + switch(left->nd_def->df_value.df_stdname) { + case S_ABS: + case S_CAP: + case S_CHR: + case S_FLOAT: + case S_HIGH: + case S_MAX: + case S_MIN: + case S_ODD: + case S_ORD: + case S_SIZE: + case S_TRUNC: + case S_VAL: + break; + case S_DEC: + case S_INC: + case S_HALT: + case S_EXCL: + case S_INCL: + expp->nd_type = 0; + break; + default: + assert(0); + } + return 1; + } + return 1; + } + node_error(expp->nd_left, "procedure, type, or function expected"); + return 0; } -struct def * findname(expp) register struct node *expp; { @@ -159,41 +278,66 @@ findname(expp) */ register struct def *df; struct def *lookfor(); - register struct node *nd; + register struct type *tp; int scope; int module; + expp->nd_type = error_type; if (expp->nd_class == Name) { - return lookfor(expp, CurrentScope, 1); + expp->nd_def = lookfor(expp, CurrentScope, 1); + expp->nd_class = Def; + expp->nd_type = expp->nd_def->df_type; + return; } - assert(expp->nd_class == Link && expp->nd_symb == '.'); - assert(expp->nd_left->nd_class == Name); - df = lookfor(expp->nd_left, CurrentScope, 1); - if (df->df_kind == D_ERROR) return df; - nd = expp; - while (nd->nd_class == Link) { - struct node *nd1; - - if (!(scope = has_selectors(df))) { - node_error(nd, "identifier \"%s\" has no selectors", - df->df_idf->id_text); - return ill_df; + if (expp->nd_class == Link) { + assert(expp->nd_symb == '.'); + assert(expp->nd_right->nd_class == Name); + findname(expp->nd_left); + tp = expp->nd_left->nd_type; + if (tp == error_type) { + df = ill_df; } - nd = nd->nd_right; - if (nd->nd_class == Name) nd1 = nd; - else nd1 = nd->nd_left; - module = (df->df_kind == D_MODULE); - df = lookup(nd1->nd_IDF, scope); + else if (tp->tp_fund != RECORD) { + /* This is also true for modules */ + node_error(expp,"Illegal selection"); + df = ill_df; + } + else df = lookup(expp->nd_right->nd_IDF, tp->rec_scope); if (!df) { - id_not_declared(nd1); - return ill_df; + df = ill_df; + id_not_declared(expp->nd_right); } - if (module && !(df->df_flags&(D_EXPORTED|D_QEXPORTED))) { -node_error(nd1, "identifier \"%s\" not exprted from qualifying module", + else if (df != ill_df) { + expp->nd_type = df->df_type; + if (!(df->df_flags & (D_EXPORTED|D_QEXPORTED))) { +node_error(expp->nd_right, +"identifier \"%s\" not exprted from qualifying module", df->df_idf->id_text); + } } + if (expp->nd_left->nd_class == Def) { + expp->nd_class = Def; + expp->nd_def = df; + FreeNode(expp->nd_left); + FreeNode(expp->nd_right); + expp->nd_left = expp->nd_right = 0; + } + return; } - return df; + if (expp->nd_class == Oper) { + assert(expp->nd_symb == '['); + (void) findname(expp->nd_left); + if (chk_expr(expp->nd_right, 0) && + expp->nd_left->nd_type != error_type && + chk_oper(expp)) /* ??? */ ; + return 1; + } + if (expp->nd_class == Uoper && expp->nd_symb == '^') { + (void) findname(expp->nd_right); + if (expp->nd_right->nd_type != error_type && + chk_uoper(expp)) /* ??? */ ; + } + return 0; } int @@ -203,16 +347,14 @@ chk_name(expp, const) register struct def *df; int retval = 1; - df = findname(expp); + (void) findname(expp); + assert(expp->nd_class == Def); + df = expp->nd_def; if (df->df_kind == D_ERROR) { retval = 0; } - expp->nd_type = df->df_type; - if (df->df_kind == D_ENUM || df->df_kind == D_CONST) { - if (expp->nd_left) FreeNode(expp->nd_left); - if (expp->nd_right) FreeNode(expp->nd_right); + if (df->df_kind & (D_ENUM | D_CONST)) { if (df->df_kind == D_ENUM) { - expp->nd_left = expp->nd_right = 0; expp->nd_class = Value; expp->nd_INT = df->enm_val; expp->nd_symb = INTEGER; @@ -251,10 +393,11 @@ chk_oper(expp, const) expp->nd_right->nd_type = tpr = tpl; } } + expp->nd_type = error_type; if (expp->nd_symb == IN) { /* Handle this one specially */ - expp->nd_type == bool_type; + expp->nd_type = bool_type; if (tpr->tp_fund != SET) { node_error(expp, "RHS of IN operator not a SET type"); return 0; @@ -266,6 +409,21 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R return 1; } + if (expp->nd_symb == '[') { + /* Handle ARRAY selection specially too! */ + if (tpl->tp_fund != ARRAY) { +node_error(expp, "array index not belonging to an ARRAY"); + return 0; + } + if (!TstCompat(tpl->next, tpr)) { +node_error(expp, "incompatible index type"); + return 0; + } + expp->nd_type = tpl->arr_elem; + if (const) return 0; + return 1; + } + if (tpl->tp_fund == SUBRANGE) tpl = tpl->next; expp->nd_type = tpl; @@ -450,6 +608,11 @@ chk_uoper(expp, const) return 1; } break; + case '^': + if (tpr->tp_fund != POINTER) break; + expp->nd_type = tpr->next; + if (const) return 0; + return 1; default: assert(0); } diff --git a/lang/m2/comp/const.h b/lang/m2/comp/const.h index 65330a70..41f44cf9 100644 --- a/lang/m2/comp/const.h +++ b/lang/m2/comp/const.h @@ -8,4 +8,5 @@ extern int mach_long_size; /* size of long on this machine == sizeof(long) */ extern arith max_int, /* maximum integer on target machine */ - max_unsigned; /* maximum unsigned on target machine */ + max_unsigned, /* maximum unsigned on target machine */ + wrd_bits; /* Number of bits in a word */ diff --git a/lang/m2/comp/cstoper.c b/lang/m2/comp/cstoper.c index 42948f02..cb9e1431 100644 --- a/lang/m2/comp/cstoper.c +++ b/lang/m2/comp/cstoper.c @@ -18,6 +18,7 @@ long full_mask[MAXSIZE];/* full_mask[1] == 0xFF, full_mask[2] == 0xFFFF, .. */ arith max_int; /* maximum integer on target machine */ arith max_unsigned; /* maximum unsigned on target machine */ arith max_longint; /* maximum longint on target machine */ +arith wrd_bits; /* number of bits in a word */ cstunary(expp) register struct node *expp; @@ -206,21 +207,85 @@ cstbin(expp) cstset(expp) register struct node *expp; { - switch(expp->nd_symb) { - case IN: - case '+': - case '-': - case '*': - case '/': - case GREATEREQUAL: - case LESSEQUAL: - case '=': - case '#': - /* ??? */ - break; - default: - assert(0); + register arith *set1 = 0, *set2; + register int setsize, j; + + assert(expp->nd_right->nd_class == Set); + assert(expp->nd_symb == IN || expp->nd_left->nd_class == Set); + set2 = expp->nd_right->nd_set; + setsize = expp->nd_right->nd_type->tp_size / wrd_size; + + if (expp->nd_symb == IN) { + arith i; + + assert(expp->nd_left->nd_class == Value); + i = expp->nd_left->nd_INT; + expp->nd_INT = (i >= 0 && + i < setsize * wrd_bits && + (set2[i / wrd_bits] & (1 << (i % wrd_bits)))); + free((char *) set2); } + else { + set1 = expp->nd_left->nd_set; + switch(expp->nd_symb) { + case '+': + for (j = 0; j < setsize; j++) { + *set1++ |= *set2++; + } + break; + case '-': + for (j = 0; j < setsize; j++) { + *set1++ &= ~*set2++; + } + break; + case '*': + for (j = 0; j < setsize; j++) { + *set1++ &= *set2++; + } + break; + case '/': + for (j = 0; j < setsize; j++) { + *set1++ ^= *set2++; + } + break; + case GREATEREQUAL: + case LESSEQUAL: + case '=': + case '#': + /* Clumsy, but who cares? Nobody writes these things! */ + for (j = 0; j < setsize; j++) { + switch(expp->nd_symb) { + case GREATEREQUAL: + if ((*set1 | *set2++) != *set1) break; + set1++; + continue; + case LESSEQUAL: + if ((*set2 | *set1++) != *set2) break; + set2++; + continue; + case '=': + case '#': + if (*set1++ != *set2++) break; + continue; + } + expp->nd_INT = expp->nd_symb == '#'; + break; + } + if (j == setsize) expp->nd_INT = expp->nd_symb != '#'; + expp->nd_class = Value; + free((char *) expp->nd_left->nd_set); + free((char *) expp->nd_right->nd_set); + break; + default: + assert(0); + } + free((char *) expp->nd_right->nd_set); + expp->nd_class = Set; + expp->nd_set = expp->nd_left->nd_set; + } + FreeNode(expp->nd_left); + FreeNode(expp->nd_right); + expp->nd_left = expp->nd_right = 0; } cut_size(expr) @@ -273,4 +338,5 @@ init_cst() max_int = full_mask[int_size] & ~(1 << (int_size * 8 - 1)); max_unsigned = full_mask[int_size]; + wrd_bits = 8 * wrd_size; } diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index b2bfe9b4..65dcc05c 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -234,7 +234,6 @@ IdentList(struct node **p;) SubrangeType(struct type **ptp;) { struct node *nd1, *nd2; - extern struct type *subr_type(); }: /* This is not exactly the rule in the new report, but see @@ -340,7 +339,6 @@ CaseLabels SetType(struct type **ptp;) { struct type *tp; - struct type *set_type(); } : SET OF SimpleType(&tp) { diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index 93bf3ec1..2abfb97f 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -6,6 +6,7 @@ static char *RcsId = "$Header$"; #include #include #include +#include #include "LLlex.h" #include "idf.h" #include "def.h" @@ -36,21 +37,17 @@ qualident(int types; struct def **pdf; char *str; struct node **p;) register struct def *df; register struct node **pnd; struct node *nd; - struct def *findname(); } : IDENT { nd = MkNode(Name, NULLNODE, NULLNODE, &dot); pnd = &nd; } [ - /* selector */ - '.' { *pnd = MkNode(Link,*pnd,NULLNODE,&dot); - pnd = &(*pnd)->nd_right; - } - IDENT - { *pnd = MkNode(Name,NULLNODE,NULLNODE,&dot); } + selector(pnd) ]* { if (types) { - *pdf = df = findname(nd); + findname(nd); + assert(nd->nd_class == Def); + *pdf = df = nd->nd_def; if (df->df_kind != D_ERROR && !(types & df->df_kind)) { error("identifier \"%s\" is not a %s", @@ -62,11 +59,10 @@ qualident(int types; struct def **pdf; char *str; struct node **p;) } ; -/* Inline substituted wherever it occurred -selector: - '.' IDENT +selector(struct node **pnd;): + '.' { *pnd = MkNode(Link,*pnd,NULLNODE,&dot); } + IDENT { (*pnd)->nd_right = MkNode(Name,NULLNODE,NULLNODE,&dot); } ; -*/ ExpList(struct node **pnd;) { @@ -238,11 +234,7 @@ designator(struct node **pnd;) designator_tail(struct node **pnd;): visible_designator_tail(pnd) [ - /* selector */ - '.' { *pnd = MkNode(Link, *pnd, NULLNODE, &dot); } - IDENT { (*pnd)->nd_right = - MkNode(Name, NULLNODE, NULLNODE, &dot); - } + selector(pnd) | visible_designator_tail(pnd) ]* @@ -250,8 +242,15 @@ designator_tail(struct node **pnd;): visible_designator_tail(struct node **pnd;): '[' { *pnd = MkNode(Oper, *pnd, NULLNODE, &dot); } - ExpList(&((*pnd)->nd_right)) + expression(&((*pnd)->nd_right)) + [ + ',' + { *pnd = MkNode(Oper, *pnd, NULLNODE, &dot); + (*pnd)->nd_symb = '['; + } + expression(&((*pnd)->nd_right)) + ]* ']' | - '^' { *pnd = MkNode(Oper, *pnd, NULLNODE, &dot); } + '^' { *pnd = MkNode(Oper, NULLNODE, *pnd, &dot); } ; diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index c20c43f4..5019dce9 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -128,23 +128,23 @@ add_standards() register struct def *df; struct def *Enter(); - (void) Enter("ABS", D_STDFUNC, NULLTYPE, S_ABS); - (void) Enter("CAP", D_STDFUNC, NULLTYPE, S_CAP); - (void) Enter("CHR", D_STDFUNC, NULLTYPE, S_CHR); - (void) Enter("FLOAT", D_STDFUNC, NULLTYPE, S_FLOAT); - (void) Enter("HIGH", D_STDFUNC, NULLTYPE, S_HIGH); - (void) Enter("HALT", D_STDPROC, NULLTYPE, S_HALT); - (void) Enter("EXCL", D_STDPROC, NULLTYPE, S_EXCL); - (void) Enter("DEC", D_STDPROC, NULLTYPE, S_DEC); - (void) Enter("INC", D_STDPROC, NULLTYPE, S_INC); - (void) Enter("VAL", D_STDFUNC, NULLTYPE, S_VAL); - (void) Enter("TRUNC", D_STDFUNC, NULLTYPE, S_TRUNC); - (void) Enter("SIZE", D_STDFUNC, NULLTYPE, S_SIZE); - (void) Enter("ORD", D_STDFUNC, NULLTYPE, S_ORD); - (void) Enter("ODD", D_STDFUNC, NULLTYPE, S_ODD); - (void) Enter("MAX", D_STDFUNC, NULLTYPE, S_MAX); - (void) Enter("MIN", D_STDFUNC, NULLTYPE, S_MIN); - (void) Enter("INCL", D_STDPROC, NULLTYPE, S_INCL); + (void) Enter("ABS", D_PROCEDURE, std_type, S_ABS); + (void) Enter("CAP", D_PROCEDURE, std_type, S_CAP); + (void) Enter("CHR", D_PROCEDURE, std_type, S_CHR); + (void) Enter("FLOAT", D_PROCEDURE, std_type, S_FLOAT); + (void) Enter("HIGH", D_PROCEDURE, std_type, S_HIGH); + (void) Enter("HALT", D_PROCEDURE, std_type, S_HALT); + (void) Enter("EXCL", D_PROCEDURE, std_type, S_EXCL); + (void) Enter("DEC", D_PROCEDURE, std_type, S_DEC); + (void) Enter("INC", D_PROCEDURE, std_type, S_INC); + (void) Enter("VAL", D_PROCEDURE, std_type, S_VAL); + (void) Enter("TRUNC", D_PROCEDURE, std_type, S_TRUNC); + (void) Enter("SIZE", D_PROCEDURE, std_type, S_SIZE); + (void) Enter("ORD", D_PROCEDURE, std_type, S_ORD); + (void) Enter("ODD", D_PROCEDURE, std_type, S_ODD); + (void) Enter("MAX", D_PROCEDURE, std_type, S_MAX); + (void) Enter("MIN", D_PROCEDURE, std_type, S_MIN); + (void) Enter("INCL", D_PROCEDURE, std_type, S_INCL); (void) Enter("CHAR", D_TYPE, char_type, 0); (void) Enter("INTEGER", D_TYPE, int_type, 0); @@ -195,8 +195,8 @@ END SYSTEM.\n"; open_scope(CLOSEDSCOPE, 0); (void) Enter("WORD", D_TYPE, word_type, 0); (void) Enter("ADDRESS", D_TYPE, address_type, 0); - (void) Enter("ADR", D_STDFUNC, NULLTYPE, S_ADR); - (void) Enter("TSIZE", D_STDFUNC, NULLTYPE, S_TSIZE); + (void) Enter("ADR", D_PROCEDURE, std_type, S_ADR); + (void) Enter("TSIZE", D_PROCEDURE, std_type, S_TSIZE); if (!InsertText(SYSTEM, strlen(SYSTEM))) { fatal("Could not insert text"); } diff --git a/lang/m2/comp/node.H b/lang/m2/comp/node.H index 8f0c451e..eb70a229 100644 --- a/lang/m2/comp/node.H +++ b/lang/m2/comp/node.H @@ -11,24 +11,16 @@ struct node { #define Oper 2 /* binary operator */ #define Uoper 3 /* unary operator */ #define Call 4 /* cast or procedure - or function call */ -#define Name 5 /* a qualident */ +#define Name 5 /* an identifier */ #define Set 6 /* a set constant */ #define Xset 7 /* a set */ #define Def 8 /* an identified name */ +#define Stat 9 /* a statement */ #define Link 11 struct type *nd_type; /* type of this node */ - union { - struct token ndu_token; /* (Value, Oper, Uoper, Call, Name, - Link) - */ - arith *ndu_set; /* pointer to a set constant (Set) */ - struct def *ndu_def; /* pointer to definition structure for - identified name (Def) - */ - } nd_val; -#define nd_token nd_val.ndu_token -#define nd_set nd_val.ndu_set -#define nd_def nd_val.ndu_def + struct token nd_token; +#define nd_set nd_token.tk_data.tk_set +#define nd_def nd_token.tk_data.tk_def #define nd_symb nd_token.tk_symb #define nd_lineno nd_token.tk_lineno #define nd_filename nd_token.tk_filename diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 483232cb..f7674246 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -47,6 +47,9 @@ ModuleDeclaration df = define(id, CurrentScope, D_MODULE); open_scope(CLOSEDSCOPE, 0); df->mod_scope = CurrentScope->sc_scope; + df->df_type = + standard_type(RECORD, 0, (arith) 0); + df->df_type->rec_scope = df->mod_scope; } priority? ';' import(1)* @@ -113,6 +116,8 @@ DefinitionModule df = define(id, GlobalScope, D_MODULE); if (!SYSTEMModule) open_scope(CLOSEDSCOPE, 0); df->mod_scope = CurrentScope->sc_scope; + df->df_type = standard_type(RECORD, 0, (arith) 0); + df->df_type->rec_scope = df->mod_scope; DefinitionModule = 1; DO_DEBUG(1, debug("Definition module \"%s\"", id->id_text)); } diff --git a/lang/m2/comp/statement.g b/lang/m2/comp/statement.g index 6f675a26..d9eb42cd 100644 --- a/lang/m2/comp/statement.g +++ b/lang/m2/comp/statement.g @@ -10,7 +10,7 @@ static char *RcsId = "$Header$"; statement { - struct node *nd1, *nd2; + struct node *nd1, *nd2 = 0; } : [ /* @@ -21,8 +21,12 @@ statement designator(&nd1) [ ActualParameters(&nd2)? + { nd1 = MkNode(Call, nd1, nd2, &dot); + nd1->nd_symb = '('; + } | - BECOMES expression(&nd2) + BECOMES { nd1 = MkNode(Stat, nd1, NULLNODE, &dot); } + expression(&(nd1->nd_right)) ] /* * end of changed part diff --git a/lang/m2/comp/type.H b/lang/m2/comp/type.H index c67a8367..bba1f4af 100644 --- a/lang/m2/comp/type.H +++ b/lang/m2/comp/type.H @@ -80,6 +80,7 @@ extern struct type *intorcard_type, *string_type, *bitset_type, + *std_type, *error_type; /* All from type.c */ extern int @@ -105,6 +106,8 @@ extern arith struct type *create_type(), *construct_type(), - *standard_type(); /* All from type.c */ + *standard_type(), + *set_type(), + *subr_type(); /* All from type.c */ #define NULLTYPE ((struct type *) 0) diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index 972dede9..36083a1d 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -49,6 +49,7 @@ struct type *intorcard_type, *string_type, *bitset_type, + *std_type, *error_type; struct paramlist *h_paramlist; @@ -132,7 +133,8 @@ init_types() char_type = standard_type(CHAR, 1, (arith) 1); char_type->enm_ncst = 256; - bool_type = standard_type(BOOLEAN, 1, (arith) 1); + bool_type = standard_type(ENUMERATION, 1, (arith) 1); + bool_type->enm_ncst = 2; int_type = standard_type(INTEGER, int_align, int_size); longint_type = standard_type(LONGINT, lint_align, lint_size); card_type = standard_type(CARDINAL, int_align, int_size); @@ -145,8 +147,8 @@ init_types() tp = construct_type(SUBRANGE, int_type); tp->sub_lb = 0; tp->sub_ub = wrd_size * 8 - 1; - bitset_type = construct_type(SET, tp); - bitset_type->tp_size = wrd_size; + bitset_type = set_type(tp); + std_type = construct_type(PROCEDURE, NULLTYPE); error_type = standard_type(ERRONEOUS, 1, (arith) 1); } From bf43df896b76236fe216620b88667072aa0efc2b Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 10 Apr 1986 01:08:49 +0000 Subject: [PATCH 0175/1625] newer version --- lang/m2/comp/chk_expr.c | 309 +++++++++++++++++++++++++------------- lang/m2/comp/cstoper.c | 2 +- lang/m2/comp/declar.g | 34 ++--- lang/m2/comp/def.c | 2 +- lang/m2/comp/expression.g | 18 ++- lang/m2/comp/main.c | 2 +- lang/m2/comp/program.g | 4 +- lang/m2/comp/tokenname.c | 12 -- lang/m2/comp/type.H | 16 +- lang/m2/comp/type.c | 63 ++++---- lang/m2/comp/typequiv.c | 12 +- 11 files changed, 287 insertions(+), 187 deletions(-) diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index 3b0cd8ba..21ba93bb 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -8,18 +8,18 @@ static char *RcsId = "$Header$"; #include #include #include +#include "Lpars.h" #include "idf.h" #include "type.h" #include "def.h" #include "LLlex.h" #include "node.h" -#include "Lpars.h" #include "scope.h" #include "const.h" #include "standards.h" int -chk_expr(expp, const) +chk_expr(expp) register struct node *expp; { /* Check the expression indicated by expp for semantic errors, @@ -29,12 +29,12 @@ chk_expr(expp, const) switch(expp->nd_class) { case Oper: - return chk_expr(expp->nd_left, const) && - chk_expr(expp->nd_right, const) && - chk_oper(expp, const); + return chk_expr(expp->nd_left) && + chk_expr(expp->nd_right) && + chk_oper(expp); case Uoper: - return chk_expr(expp->nd_right, const) && - chk_uoper(expp, const); + return chk_expr(expp->nd_right) && + chk_uoper(expp); case Value: switch(expp->nd_symb) { case REAL: @@ -46,13 +46,13 @@ chk_expr(expp, const) } break; case Xset: - return chk_set(expp, const); + return chk_set(expp); case Name: - return chk_name(expp, const); + return chk_name(expp); case Call: - return chk_call(expp, const); + return chk_call(expp); case Link: - return chk_name(expp, const); + return chk_name(expp); default: assert(0); } @@ -60,7 +60,7 @@ chk_expr(expp, const) } int -chk_set(expp, const) +chk_set(expp) register struct node *expp; { /* Check the legality of a SET aggregate, and try to evaluate it @@ -82,7 +82,7 @@ chk_set(expp, const) assert(expp->nd_left->nd_class == Def); df = expp->nd_left->nd_def; if ((df->df_kind != D_TYPE && df->df_kind != D_ERROR) || - (df->df_type->tp_fund != SET)) { + (df->df_type->tp_fund != T_SET)) { node_error(expp, "Illegal set type"); return 0; } @@ -96,11 +96,10 @@ chk_set(expp, const) nd = expp->nd_right; while (nd) { assert(nd->nd_class == Link && nd->nd_symb == ','); - if (!chk_el(nd->nd_left, const, tp->next, &set)) return 0; + if (!chk_el(nd->nd_left, tp->next, &set)) return 0; nd = nd->nd_right; } expp->nd_type = tp; - assert(!const || set); if (set) { /* Yes, in was a constant set, and we managed to compute it! */ @@ -114,7 +113,7 @@ chk_set(expp, const) } int -chk_el(expp, const, tp, set) +chk_el(expp, tp, set) register struct node *expp; struct type *tp; arith **set; @@ -127,8 +126,8 @@ chk_el(expp, const, tp, set) /* { ... , expr1 .. expr2, ... } First check expr1 and expr2, and try to compute them. */ - if (!chk_el(expp->nd_left, const, tp, set) || - !chk_el(expp->nd_right, const, tp, set)) { + if (!chk_el(expp->nd_left, tp, set) || + !chk_el(expp->nd_right, tp, set)) { return 0; } if (expp->nd_left->nd_class == Value && @@ -157,7 +156,7 @@ node_error(expp, "Lower bound exceeds upper bound in range"); /* Here, a single element is checked */ - if (!chk_expr(expp, const)) { + if (!chk_expr(expp)) { return rem_set(set); } if (!TstCompat(tp, expp->nd_type)) { @@ -165,10 +164,10 @@ node_error(expp, "Lower bound exceeds upper bound in range"); return rem_set(set); } if (expp->nd_class == Value) { - if ((tp->tp_fund != ENUMERATION && + if ((tp->tp_fund != T_ENUMERATION && (expp->nd_INT < tp->sub_lb || expp->nd_INT > tp->sub_ub)) || - (tp->tp_fund == ENUMERATION && + (tp->tp_fund == T_ENUMERATION && (expp->nd_INT < 0 || expp->nd_INT > tp->enm_ncst)) ) { node_error(expp, "Set element out of range"); @@ -193,12 +192,52 @@ rem_set(set) return 0; } +struct node * +getarg(argp, bases) + struct node *argp; +{ + struct type *tp; + + if (!argp->nd_right) { + node_error(argp, "Too few arguments supplied"); + return 0; + } + argp = argp->nd_right; + if (!chk_expr(argp->nd_left)) return 0; + tp = argp->nd_left->nd_type; + if (tp->tp_fund == T_SUBRANGE) tp = tp->next; + if (!(tp->tp_fund & bases)) { + node_error(argp, "Unexpected type"); + return 0; + } + return argp; +} + +struct node * +getname(argp, kinds) + struct node *argp; +{ + if (!argp->nd_right) { + node_error(argp, "Too few arguments supplied"); + return 0; + } + argp = argp->nd_right; + if (!findname(argp->nd_left)) return 0; + assert(argp->nd_left->nd_class == Def); + if (!(argp->nd_left->nd_def->df_kind & kinds)) { + node_error(argp, "Unexpected type"); + return 0; + } + return argp; +} + int -chk_call(expp, const) +chk_call(expp) register struct node *expp; { register struct type *tp; register struct node *left; + register struct node *arg; expp->nd_type = error_type; (void) findname(expp->nd_left); @@ -211,57 +250,148 @@ chk_call(expp, const) /* A type cast. This is of course not portable. No runtime action. Remove it. */ - if (!expp->nd_right || - (expp->nd_right->nd_symb == ',')) { + arg = expp->nd_right; + if (!arg || arg->nd_right) { node_error(expp, "Only one parameter expected in type cast"); return 0; } - if (! chk_expr(expp->nd_right, const)) return 0; - if (expp->nd_right->nd_type->tp_size != + if (! chk_expr(arg->nd_left)) return 0; + if (arg->nd_left->nd_type->tp_size != left->nd_type->tp_size) { node_error(expp, "Size of type in type cast does not match size of operand"); return 0; } - expp->nd_right->nd_type = left->nd_type; - left = expp->nd_right; + arg->nd_left->nd_type = left->nd_type; FreeNode(expp->nd_left); - *expp = *(expp->nd_right); - left->nd_left = left->nd_right = 0; - FreeNode(left); + *expp = *(arg->nd_left); + arg->nd_left->nd_left = 0; + arg->nd_left->nd_right = 0; + FreeNode(arg); return 1; } if ((left->nd_class == Def && left->nd_def->df_kind == D_PROCEDURE) || - tp->tp_fund == PROCVAR) { + tp->tp_fund == T_PROCEDURE) { /* A procedure call. it may also be a call to a standard procedure */ + arg = expp; if (tp == std_type) { assert(left->nd_class == Def); switch(left->nd_def->df_value.df_stdname) { case S_ABS: + arg = getarg(arg, T_INTEGER|T_CARDINAL|T_REAL); + if (! arg) return 0; + expp->nd_type = arg->nd_left->nd_type; + break; case S_CAP: + arg = getarg(arg, T_CHAR); + expp->nd_type = char_type; + if (!arg) return 0; + break; case S_CHR: + arg = getarg(arg, T_INTEGER|T_CARDINAL); + expp->nd_type = char_type; + if (!arg) return 0; + break; case S_FLOAT: + arg = getarg(arg, T_CARDINAL|T_INTEGER); + expp->nd_type = real_type; + if (!arg) return 0; + break; case S_HIGH: + arg = getarg(arg, T_ARRAY); + if (!arg) return 0; + expp->nd_type = arg->nd_left->nd_type->next; + if (!expp->nd_type) expp->nd_type = int_type; + break; case S_MAX: case S_MIN: + arg = getarg(arg, T_ENUMERATION|T_CHAR|T_INTEGER|T_CARDINAL); + if (!arg) return 0; + expp->nd_type = arg->nd_left->nd_type; + break; case S_ODD: + arg = getarg(arg, T_INTEGER|T_CARDINAL); + if (!arg) return 0; + expp->nd_type = bool_type; + break; case S_ORD: + arg = getarg(arg, T_ENUMERATION|T_CHAR|T_INTEGER|T_CARDINAL); + if (!arg) return 0; + expp->nd_type = card_type; + break; + case S_TSIZE: /* ??? */ case S_SIZE: + arg = getname(arg, D_FIELD|D_VARIABLE|D_TYPE|D_HIDDEN|D_HTYPE); + expp->nd_type = intorcard_type; + if (!arg) return 0; + break; case S_TRUNC: + arg = getarg(arg, T_REAL); + if (!arg) return 0; + expp->nd_type = card_type; + break; case S_VAL: + arg = getname(arg, D_HIDDEN|D_HTYPE|D_TYPE); + if (!arg) return 0; + tp = arg->nd_left->nd_def->df_type; + if (tp->tp_fund == T_SUBRANGE) tp = tp->next; + if (!(tp->tp_fund & (T_ENUMERATION|T_CHAR|T_INTEGER|T_CARDINAL))) { + node_error(arg, "unexpected type"); + return 0; + } + expp->nd_type = arg->nd_left->nd_def->df_type; + FreeNode(arg->nd_left); + arg->nd_left = 0; + arg = getarg(arg, T_INTEGER|T_CARDINAL); + if (!arg) return 0; + break; + case S_ADR: + arg = getname(arg, D_VARIABLE|D_FIELD|D_PROCEDURE); + expp->nd_type = address_type; + if (!arg) return 0; break; case S_DEC: case S_INC: + expp->nd_type = 0; + arg = getname(arg, D_VARIABLE|D_FIELD); + if (!arg) return 0; + if (arg->nd_right) { + arg = getarg(arg, T_INTEGER|T_CARDINAL); + if (!arg) return 0; + } + break; case S_HALT: + expp->nd_type = 0; + break; case S_EXCL: case S_INCL: expp->nd_type = 0; + arg = getname(arg, D_VARIABLE|D_FIELD); + if (!arg) return 0; + tp = arg->nd_left->nd_type; + if (tp->tp_fund != T_SET) { +node_error(arg, "EXCL and INCL expect a SET parameter"); + return 0; + } + arg = getarg(arg, T_INTEGER|T_CARDINAL|T_CHAR|T_ENUMERATION); + if (!arg) return 0; + if (!TstCompat(tp->next, arg->nd_left->nd_type)) { + node_error(arg, "Unexpected type"); + return 0; + } break; default: assert(0); } + if (arg->nd_right) { + node_error(arg->nd_right, + "Too many parameters supplied"); + return 0; + } + FreeNode(expp->nd_left); + expp->nd_left = 0; return 1; } return 1; @@ -297,7 +427,7 @@ findname(expp) if (tp == error_type) { df = ill_df; } - else if (tp->tp_fund != RECORD) { + else if (tp->tp_fund != T_RECORD) { /* This is also true for modules */ node_error(expp,"Illegal selection"); df = ill_df; @@ -341,18 +471,15 @@ df->df_idf->id_text); } int -chk_name(expp, const) +chk_name(expp) register struct node *expp; { register struct def *df; - int retval = 1; (void) findname(expp); assert(expp->nd_class == Def); df = expp->nd_def; - if (df->df_kind == D_ERROR) { - retval = 0; - } + if (df->df_kind == D_ERROR) return 0; if (df->df_kind & (D_ENUM | D_CONST)) { if (df->df_kind == D_ENUM) { expp->nd_class = Value; @@ -363,20 +490,14 @@ chk_name(expp, const) *expp = *(df->con_const); } } - else if (const) { - node_error(expp, "constant expected"); - retval = 0; - } - return retval; + return 1; } int -chk_oper(expp, const) +chk_oper(expp) register struct node *expp; { - /* Check a binary operation. If "const" is set, also check - that it is constant. - The code is ugly ! + /* Check a binary operation. */ register struct type *tpl = expp->nd_left->nd_type; register struct type *tpr = expp->nd_right->nd_type; @@ -398,7 +519,7 @@ chk_oper(expp, const) if (expp->nd_symb == IN) { /* Handle this one specially */ expp->nd_type = bool_type; - if (tpr->tp_fund != SET) { + if (tpr->tp_fund != T_SET) { node_error(expp, "RHS of IN operator not a SET type"); return 0; } @@ -411,7 +532,7 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R if (expp->nd_symb == '[') { /* Handle ARRAY selection specially too! */ - if (tpl->tp_fund != ARRAY) { + if (tpl->tp_fund != T_ARRAY) { node_error(expp, "array index not belonging to an ARRAY"); return 0; } @@ -420,11 +541,10 @@ node_error(expp, "incompatible index type"); return 0; } expp->nd_type = tpl->arr_elem; - if (const) return 0; return 1; } - if (tpl->tp_fund == SUBRANGE) tpl = tpl->next; + if (tpl->tp_fund == T_SUBRANGE) tpl = tpl->next; expp->nd_type = tpl; if (!TstCompat(tpl, tpr)) { @@ -437,49 +557,35 @@ node_error(expp, "Incompatible types for operator \"%s\"", symbol2str(expp->nd_s case '-': case '*': switch(tpl->tp_fund) { - case INTEGER: - case INTORCARD: - case CARDINAL: - case LONGINT: - case SET: + case T_INTEGER: + case T_CARDINAL: + case T_SET: if (expp->nd_left->nd_class == Value && expp->nd_right->nd_class == Value) { cstbin(expp); } return 1; - case REAL: - case LONGREAL: - if (const) { - errval = 2; - break; - } + case T_REAL: return 1; } break; case '/': switch(tpl->tp_fund) { - case SET: + case T_SET: if (expp->nd_left->nd_class == Value && expp->nd_right->nd_class == Value) { cstbin(expp); } return 1; - case REAL: - case LONGREAL: - if (const) { - errval = 2; - break; - } + case T_REAL: return 1; } break; case DIV: case MOD: switch(tpl->tp_fund) { - case INTEGER: - case INTORCARD: - case CARDINAL: - case LONGINT: + case T_INTEGER: + case T_CARDINAL: if (expp->nd_left->nd_class == Value && expp->nd_right->nd_class == Value) { cstbin(expp); @@ -505,32 +611,30 @@ node_error(expp, "Incompatible types for operator \"%s\"", symbol2str(expp->nd_s case '<': case '>': switch(tpl->tp_fund) { - case SET: + case T_SET: if (expp->nd_symb == '<' || expp->nd_symb == '>') { break; } - case INTEGER: - case INTORCARD: - case LONGINT: - case CARDINAL: - case ENUMERATION: /* includes boolean */ - case CHAR: + if (expp->nd_left->nd_class == Set && + expp->nd_right->nd_class == Set) { + cstbin(expp); + } + return 1; + case T_INTEGER: + case T_CARDINAL: + case T_ENUMERATION: /* includes boolean */ + case T_CHAR: if (expp->nd_left->nd_class == Value && expp->nd_right->nd_class == Value) { cstbin(expp); } return 1; - case POINTER: + case T_POINTER: if (!(expp->nd_symb == '=' || expp->nd_symb == '#')) { break; } /* Fall through */ - case REAL: - case LONGREAL: - if (const) { - errval = 2; - break; - } + case T_REAL: return 1; } default: @@ -540,37 +644,32 @@ node_error(expp, "Incompatible types for operator \"%s\"", symbol2str(expp->nd_s case 1: node_error(expp,"Operator \"%s\": illegal operand type(s)", symbol2str(expp->nd_symb)); break; - case 2: - node_error(expp, "Expression not constant"); - break; case 3: node_error(expp, "BOOLEAN type(s) expected"); break; + default: + assert(0); } return 0; } int -chk_uoper(expp, const) +chk_uoper(expp) register struct node *expp; { - /* Check an unary operation. If "const" is set, also check that - it can be evaluated compile-time. + /* Check an unary operation. */ register struct type *tpr = expp->nd_right->nd_type; - if (tpr->tp_fund == SUBRANGE) tpr = tpr->next; + if (tpr->tp_fund == T_SUBRANGE) tpr = tpr->next; expp->nd_type = tpr; switch(expp->nd_symb) { case '+': switch(tpr->tp_fund) { - case INTEGER: - case LONGINT: - case REAL: - case LONGREAL: - case CARDINAL: - case INTORCARD: + case T_INTEGER: + case T_REAL: + case T_CARDINAL: expp->nd_token = expp->nd_right->nd_token; FreeNode(expp->nd_right); expp->nd_right = 0; @@ -579,15 +678,12 @@ chk_uoper(expp, const) break; case '-': switch(tpr->tp_fund) { - case INTEGER: - case LONGINT: - case INTORCARD: + case T_INTEGER: if (expp->nd_right->nd_class == Value) { cstunary(expp); } return 1; - case REAL: - case LONGREAL: + case T_REAL: if (expp->nd_right->nd_class == Value) { expp->nd_token = expp->nd_right->nd_token; if (*(expp->nd_REL) == '-') { @@ -609,9 +705,8 @@ chk_uoper(expp, const) } break; case '^': - if (tpr->tp_fund != POINTER) break; + if (tpr->tp_fund != T_POINTER) break; expp->nd_type = tpr->next; - if (const) return 0; return 1; default: assert(0); diff --git a/lang/m2/comp/cstoper.c b/lang/m2/comp/cstoper.c index cb9e1431..a6182bd8 100644 --- a/lang/m2/comp/cstoper.c +++ b/lang/m2/comp/cstoper.c @@ -60,7 +60,7 @@ cstbin(expp) int uns = expp->nd_type != int_type; assert(expp->nd_class == Oper); - if (expp->nd_right->nd_type->tp_fund == SET) { + if (expp->nd_right->nd_type->tp_fund == T_SET) { cstset(expp); return; } diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 65dcc05c..79bc4dc0 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -56,7 +56,7 @@ ProcedureHeading(struct def **pdf; int type;) } FormalParameters(type == D_PROCEDURE, ¶ms, &tp)? { - df->df_type = tp = construct_type(PROCEDURE, tp); + df->df_type = tp = construct_type(T_PROCEDURE, tp); tp->prc_params = params; if (tp1 && !TstTypeEquiv(tp, tp1)) { error("inconsistent procedure declaration for \"%s\"", df->df_idf->id_text); @@ -137,7 +137,7 @@ FormalType(struct type **tp;) ]? qualident(D_TYPE | D_HTYPE, &df, "type", (struct node **) 0) { if (ARRAYflag) { - *tp = construct_type(ARRAY, NULLTYPE); + *tp = construct_type(T_ARRAY, NULLTYPE); (*tp)->arr_elem = df->df_type; } else *tp = df->df_type; @@ -153,12 +153,12 @@ TypeDeclaration '=' type(&tp) { df->df_type = tp; if ((df->df_flags&D_EXPORTED) && - tp->tp_fund == ENUMERATION) { + tp->tp_fund == T_ENUMERATION) { exprt_literals(tp->enm_enums, enclosing(CurrentScope)); } if (df->df_kind == D_HTYPE && - tp->tp_fund != POINTER) { + tp->tp_fund != T_POINTER) { error("Opaque type \"%s\" is not a pointer type", df->df_idf->id_text); } @@ -207,11 +207,11 @@ enumeration(struct type **ptp;) struct node *EnumList; } : '(' IdentList(&EnumList) ')' - { - *ptp = standard_type(ENUMERATION,int_align,int_size); - EnterIdList(EnumList, D_ENUM, 0, *ptp, CurrentScope); - FreeNode(EnumList); - } + { + *ptp = standard_type(T_ENUMERATION,int_align,int_size); + EnterIdList(EnumList, D_ENUM, 0, *ptp, CurrentScope); + FreeNode(EnumList); + } ; @@ -252,12 +252,12 @@ ArrayType(struct type **ptp;) } : ARRAY SimpleType(&tp) { - *ptp = tp2 = construct_type(ARRAY, tp); + *ptp = tp2 = construct_type(T_ARRAY, tp); } [ ',' SimpleType(&tp) { tp2 = tp2->arr_elem = - construct_type(ARRAY, tp); + construct_type(T_ARRAY, tp); } ]* OF type(&tp) { tp2->arr_elem = tp; } @@ -273,10 +273,10 @@ RecordType(struct type **ptp;) scope.next = CurrentScope; } FieldListSequence(&scope) - { - *ptp = standard_type(RECORD, record_align, (arith) 0 /* ???? */); - (*ptp)->rec_scope = scope.sc_scope; - } + { + *ptp = standard_type(T_RECORD, record_align, (arith) 0 /* ???? */); + (*ptp)->rec_scope = scope.sc_scope; + } END ; @@ -380,7 +380,7 @@ PointerType(struct type **ptp;) { tp = NULLTYPE; } ] { - *ptp = construct_type(POINTER, tp); + *ptp = construct_type(T_POINTER, tp); if (!tp) Forward(&dot, &((*ptp)->next)); } ; @@ -391,7 +391,7 @@ ProcedureType(struct type **ptp;) struct type *tp = 0; } : PROCEDURE FormalTypeList(&pr, &tp)? - { *ptp = construct_type(PROCVAR, tp); + { *ptp = construct_type(T_PROCEDURE, tp); (*ptp)->prc_params = pr; } ; diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index 55df98c8..b0f44480 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -204,7 +204,7 @@ ids->nd_IDF->id_text); DO_DEBUG(2, debug("importing \"%s\", kind %d", ids->nd_IDF->id_text, df->df_kind)); define(ids->nd_IDF, CurrentScope, kind)->imp_def = df; if (df->df_kind == D_TYPE && - df->df_type->tp_fund == ENUMERATION) { + df->df_type->tp_fund == T_ENUMERATION) { /* Also import all enumeration literals */ exprt_literals(df->df_type->enm_enums, CurrentScope); diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index 2abfb97f..6a9e1556 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -68,12 +68,15 @@ ExpList(struct node **pnd;) { struct node **nd; } : - expression(pnd) { nd = pnd; } - [ - ',' { *nd = MkNode(Link, *nd, NULLNODE, &dot); - nd = &(*nd)->nd_right; + expression(pnd) { *pnd = MkNode(Link, *pnd, NULLNODE, &dot); + (*pnd)->nd_symb = ','; + nd = &((*pnd)->nd_right); } - expression(nd) + [ + ',' { *nd = MkNode(Link, NULLNODE, NULLNODE, &dot); + } + expression(&(*nd)->nd_left) + { nd = &((*pnd)->nd_right); } ]* ; @@ -86,7 +89,10 @@ ConstExpression(struct node **pnd;): { DO_DEBUG(3, ( debug("Constant expression:"), PrNode(*pnd))); - (void) chk_expr(*pnd, 1); + if (chk_expr(*pnd) && + ((*pnd)->nd_class != Set && (*pnd)->nd_class != Value)) { + error("Constant expression expected"); + } DO_DEBUG(3, PrNode(*pnd)); } ; diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index 5019dce9..08632c06 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -156,7 +156,7 @@ add_standards() (void) Enter("NIL", D_CONST, address_type, 0); (void) Enter("PROC", D_TYPE, - construct_type(PROCEDURE, NULLTYPE), + construct_type(T_PROCEDURE, NULLTYPE), 0); df = Enter("BITSET", D_TYPE, bitset_type, 0); df = Enter("FALSE", D_ENUM, bool_type, 0); diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index f7674246..0cca0902 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -48,7 +48,7 @@ ModuleDeclaration open_scope(CLOSEDSCOPE, 0); df->mod_scope = CurrentScope->sc_scope; df->df_type = - standard_type(RECORD, 0, (arith) 0); + standard_type(T_RECORD, 0, (arith) 0); df->df_type->rec_scope = df->mod_scope; } priority? ';' @@ -116,7 +116,7 @@ DefinitionModule df = define(id, GlobalScope, D_MODULE); if (!SYSTEMModule) open_scope(CLOSEDSCOPE, 0); df->mod_scope = CurrentScope->sc_scope; - df->df_type = standard_type(RECORD, 0, (arith) 0); + df->df_type = standard_type(T_RECORD, 0, (arith) 0); df->df_type->rec_scope = df->mod_scope; DefinitionModule = 1; DO_DEBUG(1, debug("Definition module \"%s\"", id->id_text)); diff --git a/lang/m2/comp/tokenname.c b/lang/m2/comp/tokenname.c index 9e0ca1cb..a9b9920c 100644 --- a/lang/m2/comp/tokenname.c +++ b/lang/m2/comp/tokenname.c @@ -76,22 +76,10 @@ struct tokenname tkidf[] = { /* names of the identifier tokens */ struct tokenname tkinternal[] = { /* internal keywords */ {PROGRAM, ""}, - {SUBRANGE, ""}, - {ENUMERATION, ""}, - {ERRONEOUS, ""}, - {PROCVAR, ""}, - {INTORCARD, ""}, {0, "0"} }; struct tokenname tkstandard[] = { /* standard identifiers */ - {CHAR, ""}, - {BOOLEAN, ""}, - {LONGINT, ""}, - {CARDINAL, ""}, - {LONGREAL, ""}, - {WORD, ""}, - {ADDRESS, ""}, {0, ""} }; diff --git a/lang/m2/comp/type.H b/lang/m2/comp/type.H index bba1f4af..d144e445 100644 --- a/lang/m2/comp/type.H +++ b/lang/m2/comp/type.H @@ -53,9 +53,23 @@ struct type { SUBRANGE */ int tp_fund; /* fundamental type or constructor */ +#define T_RECORD 0x0001 +#define T_ENUMERATION 0x0002 +#define T_INTEGER 0x0004 +#define T_CARDINAL 0x0008 +/* #define T_LONGINT 0x0010 */ +#define T_REAL 0x0020 +/* #define T_LONGREAL 0x0040 */ +#define T_POINTER 0x0080 +#define T_CHAR 0x0100 +#define T_WORD 0x0200 +#define T_SET 0x0400 +#define T_SUBRANGE 0x0800 +#define T_PROCEDURE 0x1000 +#define T_ARRAY 0x2000 +#define T_STRING 0x4000 int tp_align; /* alignment requirement of this type */ arith tp_size; /* size of this type */ -/* struct idf *tp_idf; /* name of this type */ union { struct enume tp_enum; struct subrange tp_subrange; diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index 36083a1d..f509f0d0 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -82,21 +82,21 @@ construct_type(fund, tp) struct type *dtp = create_type(fund); switch (fund) { - case PROCEDURE: - case POINTER: + case T_PROCEDURE: + case T_POINTER: dtp->tp_align = ptr_align; dtp->tp_size = ptr_size; dtp->next = tp; break; - case SET: + case T_SET: dtp->tp_align = wrd_align; dtp->next = tp; break; - case ARRAY: + case T_ARRAY: dtp->tp_align = tp->tp_align; dtp->next = tp; break; - case SUBRANGE: + case T_SUBRANGE: dtp->tp_align = tp->tp_align; dtp->tp_size = tp->tp_size; dtp->next = tp; @@ -131,25 +131,25 @@ init_types() { register struct type *tp; - char_type = standard_type(CHAR, 1, (arith) 1); + char_type = standard_type(T_CHAR, 1, (arith) 1); char_type->enm_ncst = 256; - bool_type = standard_type(ENUMERATION, 1, (arith) 1); + bool_type = standard_type(T_ENUMERATION, 1, (arith) 1); bool_type->enm_ncst = 2; - int_type = standard_type(INTEGER, int_align, int_size); - longint_type = standard_type(LONGINT, lint_align, lint_size); - card_type = standard_type(CARDINAL, int_align, int_size); - real_type = standard_type(REAL, real_align, real_size); - longreal_type = standard_type(LONGREAL, lreal_align, lreal_size); - word_type = standard_type(WORD, wrd_align, wrd_size); - intorcard_type = standard_type(INTORCARD, int_align, int_size); - string_type = standard_type(STRING, 1, (arith) -1); - address_type = construct_type(POINTER, word_type); - tp = construct_type(SUBRANGE, int_type); + int_type = standard_type(T_INTEGER, int_align, int_size); + longint_type = standard_type(T_INTEGER, lint_align, lint_size); + card_type = standard_type(T_CARDINAL, int_align, int_size); + real_type = standard_type(T_REAL, real_align, real_size); + longreal_type = standard_type(T_REAL, lreal_align, lreal_size); + word_type = standard_type(T_WORD, wrd_align, wrd_size); + intorcard_type = standard_type(T_INTEGER, int_align, int_size); + string_type = standard_type(T_STRING, 1, (arith) -1); + address_type = construct_type(T_POINTER, word_type); + tp = construct_type(T_SUBRANGE, int_type); tp->sub_lb = 0; tp->sub_ub = wrd_size * 8 - 1; bitset_type = set_type(tp); - std_type = construct_type(PROCEDURE, NULLTYPE); - error_type = standard_type(ERRONEOUS, 1, (arith) 1); + std_type = construct_type(T_PROCEDURE, NULLTYPE); + error_type = standard_type(T_CHAR, 1, (arith) 1); } int @@ -160,14 +160,11 @@ has_selectors(df) switch(df->df_kind) { case D_MODULE: return df->df_value.df_module.mo_scope; - case D_VARIABLE: { - register struct type *tp = df->df_type; - - if (tp->tp_fund == RECORD) { - return tp->rec_scope; + case D_VARIABLE: + if (df->df_type->tp_fund == T_RECORD) { + return df->df_type->rec_scope; } break; - } } error("no selectors for \"%s\"", df->df_idf->id_text); return 0; @@ -205,7 +202,7 @@ ParamList(ids, tp, VARp) chk_basesubrange(tp, base) register struct type *tp, *base; { - if (base->tp_fund == SUBRANGE) { + if (base->tp_fund == T_SUBRANGE) { /* Check that the bounds of "tp" fall within the range of "base" */ @@ -214,7 +211,7 @@ chk_basesubrange(tp, base) } base = base->next; } - if (base->tp_fund == ENUMERATION || base->tp_fund == CHAR) { + if (base->tp_fund == T_ENUMERATION || base->tp_fund == T_CHAR) { if (tp->next != base) { error("Specified base does not conform"); } @@ -247,13 +244,13 @@ subr_type(lb, ub) return error_type; } - if (tp->tp_fund == SUBRANGE) tp = tp->next; + if (tp->tp_fund == T_SUBRANGE) tp = tp->next; if (tp == intorcard_type) tp = card_type; /* lower bound > 0 */ /* Check base type */ if (tp != int_type && tp != card_type && tp != char_type && - tp->tp_fund != ENUMERATION) { + tp->tp_fund != T_ENUMERATION) { /* BOOLEAN is also an ENUMERATION type */ node_error(ub, "Illegal base type for subrange"); @@ -268,7 +265,7 @@ subr_type(lb, ub) /* Now construct resulting type */ - tp = construct_type(SUBRANGE, tp); + tp = construct_type(T_SUBRANGE, tp); tp->sub_lb = lb->nd_INT; tp->sub_ub = ub->nd_INT; DO_DEBUG(2,debug("Creating subrange type %ld-%ld", (long)lb->nd_INT,(long)ub->nd_INT)); @@ -285,13 +282,13 @@ set_type(tp) */ int lb, ub; - if (tp->tp_fund == SUBRANGE) { + if (tp->tp_fund == T_SUBRANGE) { if ((lb = tp->sub_lb) < 0 || (ub = tp->sub_ub) > MAX_SET - 1) { error("Set type limits exceeded"); return error_type; } } - else if (tp->tp_fund == ENUMERATION || tp == char_type) { + else if (tp->tp_fund == T_ENUMERATION || tp == char_type) { lb = 0; if ((ub = tp->enm_ncst - 1) > MAX_SET - 1) { error("Set type limits exceeded"); @@ -302,7 +299,7 @@ set_type(tp) error("illegal base type for set"); return error_type; } - tp = construct_type(SET, tp); + tp = construct_type(T_SET, tp); tp->tp_size = align(((ub - lb) + 7)/8, wrd_align); return tp; } diff --git a/lang/m2/comp/typequiv.c b/lang/m2/comp/typequiv.c index 02f184cd..9cf8621f 100644 --- a/lang/m2/comp/typequiv.c +++ b/lang/m2/comp/typequiv.c @@ -25,9 +25,9 @@ TstTypeEquiv(tp1, tp2) tp2 == error_type || ( - tp1 && tp1->tp_fund == PROCEDURE + tp1 && tp1->tp_fund == T_PROCEDURE && - tp2 && tp2->tp_fund == PROCEDURE + tp2 && tp2->tp_fund == T_PROCEDURE && TstProcEquiv(tp1, tp2) ); @@ -65,8 +65,8 @@ TstCompat(tp1, tp2) Modula-2 Report for a definition of "compatible". */ if (TstTypeEquiv(tp1, tp2)) return 1; - if (tp1->tp_fund == SUBRANGE) tp1 = tp1->next; - if (tp2->tp_fund == SUBRANGE) tp2 = tp2->next; + if (tp1->tp_fund == T_SUBRANGE) tp1 = tp1->next; + if (tp2->tp_fund == T_SUBRANGE) tp2 = tp2->next; return tp1 == tp2 || ( tp1 == intorcard_type @@ -83,7 +83,7 @@ TstCompat(tp1, tp2) && ( tp2 == card_type || tp2 == intorcard_type - || tp2->tp_fund == POINTER + || tp2->tp_fund == T_POINTER ) ) || @@ -91,7 +91,7 @@ TstCompat(tp1, tp2) && ( tp1 == card_type || tp1 == intorcard_type - || tp1->tp_fund == POINTER + || tp1->tp_fund == T_POINTER ) ) ; From 01eb8d8637fbfabf882577d3c6c08b21aaf5b8cc Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 11 Apr 1986 11:57:19 +0000 Subject: [PATCH 0176/1625] newer version --- lang/m2/comp/Makefile | 10 +-- lang/m2/comp/chk_expr.c | 159 +++++++++++++++++++++++++------------- lang/m2/comp/const.h | 1 + lang/m2/comp/cstoper.c | 118 ++++++++++++++++++++++++++-- lang/m2/comp/declar.g | 63 ++++++++++++--- lang/m2/comp/def.H | 16 ++-- lang/m2/comp/def.c | 83 ++++++++++++++++---- lang/m2/comp/enter.c | 4 +- lang/m2/comp/expression.g | 9 ++- lang/m2/comp/type.H | 3 + lang/m2/comp/type.c | 3 +- lang/m2/comp/typequiv.c | 17 +++- 12 files changed, 379 insertions(+), 107 deletions(-) diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index 74969ac1..7cb39541 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -82,16 +82,16 @@ symbol2str.o: Lpars.h tokenname.o: Lpars.h idf.h tokenname.h idf.o: idf.h input.o: f_info.h input.h -type.o: LLlex.h Lpars.h const.h debug.h def.h def_sizes.h idf.h node.h type.h -def.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h type.h +type.o: LLlex.h const.h debug.h def.h def_sizes.h idf.h node.h type.h +def.o: LLlex.h debug.h def.h idf.h main.h node.h scope.h type.h scope.o: LLlex.h debug.h def.h idf.h node.h scope.h type.h misc.o: LLlex.h f_info.h idf.h misc.h node.h enter.o: LLlex.h def.h idf.h node.h scope.h type.h defmodule.o: LLlex.h debug.h def.h f_info.h idf.h input.h scope.h -typequiv.o: Lpars.h def.h type.h +typequiv.o: def.h type.h node.o: LLlex.h debug.h def.h node.h type.h -cstoper.o: LLlex.h Lpars.h def_sizes.h idf.h node.h type.h -chk_expr.o: LLlex.h Lpars.h const.h def.h idf.h node.h scope.h standards.h type.h +cstoper.o: LLlex.h Lpars.h def_sizes.h idf.h node.h standards.h type.h +chk_expr.o: LLlex.h Lpars.h const.h debug.h def.h idf.h node.h scope.h standards.h type.h tokenfile.o: Lpars.h program.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h type.h declar.o: LLlex.h Lpars.h def.h idf.h misc.h node.h scope.h type.h diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index 21ba93bb..67075d10 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -17,6 +17,7 @@ static char *RcsId = "$Header$"; #include "scope.h" #include "const.h" #include "standards.h" +#include "debug.h" int chk_expr(expp) @@ -199,7 +200,7 @@ getarg(argp, bases) struct type *tp; if (!argp->nd_right) { - node_error(argp, "Too few arguments supplied"); + node_error(argp, "too few arguments supplied"); return 0; } argp = argp->nd_right; @@ -218,7 +219,7 @@ getname(argp, kinds) struct node *argp; { if (!argp->nd_right) { - node_error(argp, "Too few arguments supplied"); + node_error(argp, "too few arguments supplied"); return 0; } argp = argp->nd_right; @@ -235,67 +236,84 @@ int chk_call(expp) register struct node *expp; { - register struct type *tp; + /* Check something that looks like a procedure or function call. + Of course this does not have to be a call at all. + it may also be a cast or a standard procedure call. + */ register struct node *left; register struct node *arg; expp->nd_type = error_type; - (void) findname(expp->nd_left); + (void) findname(expp->nd_left); /* parser made sure it is a name */ left = expp->nd_left; - tp = left->nd_type; - if (tp == error_type) return 0; + if (left->nd_type == error_type) return 0; if (left->nd_class == Def && (left->nd_def->df_kind & (D_HTYPE|D_TYPE|D_HIDDEN))) { /* A type cast. This is of course not portable. No runtime action. Remove it. */ arg = expp->nd_right; - if (!arg || arg->nd_right) { + if ((! arg) || arg->nd_right) { node_error(expp, "Only one parameter expected in type cast"); return 0; } - if (! chk_expr(arg->nd_left)) return 0; - if (arg->nd_left->nd_type->tp_size != - left->nd_type->tp_size) { + arg = arg->nd_left; + if (! chk_expr(arg)) return 0; + if (arg->nd_type->tp_size != left->nd_type->tp_size) { node_error(expp, "Size of type in type cast does not match size of operand"); return 0; } - arg->nd_left->nd_type = left->nd_type; + arg->nd_type = left->nd_type; FreeNode(expp->nd_left); *expp = *(arg->nd_left); - arg->nd_left->nd_left = 0; - arg->nd_left->nd_right = 0; + arg->nd_left = 0; + arg->nd_right = 0; FreeNode(arg); return 1; } if ((left->nd_class == Def && left->nd_def->df_kind == D_PROCEDURE) || - tp->tp_fund == T_PROCEDURE) { + left->nd_type->tp_fund == T_PROCEDURE) { /* A procedure call. it may also be a call to a standard procedure */ arg = expp; - if (tp == std_type) { + if (left->nd_type == std_type) { + /* A standard procedure + */ assert(left->nd_class == Def); +DO_DEBUG(3, debug("Standard name \"%s\", %d", +left->nd_def->df_idf->id_text, left->nd_def->df_value.df_stdname)); switch(left->nd_def->df_value.df_stdname) { case S_ABS: - arg = getarg(arg, T_INTEGER|T_CARDINAL|T_REAL); + arg = getarg(arg, T_NUMERIC); if (! arg) return 0; - expp->nd_type = arg->nd_left->nd_type; + left = arg->nd_left; + expp->nd_type = left->nd_type; + if (left->nd_class == Value) { + cstcall(expp, S_ABS); + } break; case S_CAP: arg = getarg(arg, T_CHAR); expp->nd_type = char_type; if (!arg) return 0; + left = arg->nd_left; + if (left->nd_class == Value) { + cstcall(expp, S_CAP); + } break; case S_CHR: - arg = getarg(arg, T_INTEGER|T_CARDINAL); + arg = getarg(arg, T_INTORCARD); expp->nd_type = char_type; if (!arg) return 0; + if (arg->nd_left->nd_class == Value) { + cstcall(expp, S_CHR); + } break; case S_FLOAT: - arg = getarg(arg, T_CARDINAL|T_INTEGER); + arg = getarg(arg, T_INTORCARD); expp->nd_type = real_type; if (!arg) return 0; break; @@ -303,50 +321,71 @@ node_error(expp, "Size of type in type cast does not match size of operand"); arg = getarg(arg, T_ARRAY); if (!arg) return 0; expp->nd_type = arg->nd_left->nd_type->next; - if (!expp->nd_type) expp->nd_type = int_type; + if (!expp->nd_type) { + /* A dynamic array has no explicit + index type + */ + expp->nd_type = int_type; + } + else cstcall(expp, S_MAX); break; case S_MAX: case S_MIN: - arg = getarg(arg, T_ENUMERATION|T_CHAR|T_INTEGER|T_CARDINAL); + arg = getarg(arg, T_DISCRETE); if (!arg) return 0; expp->nd_type = arg->nd_left->nd_type; + cstcall(expp,left->nd_def->df_value.df_stdname); break; case S_ODD: - arg = getarg(arg, T_INTEGER|T_CARDINAL); + arg = getarg(arg, T_INTORCARD); if (!arg) return 0; expp->nd_type = bool_type; + if (arg->nd_left->nd_class == Value) { + cstcall(expp, S_ODD); + } break; case S_ORD: - arg = getarg(arg, T_ENUMERATION|T_CHAR|T_INTEGER|T_CARDINAL); + arg = getarg(arg, T_DISCRETE); if (!arg) return 0; expp->nd_type = card_type; + if (arg->nd_left->nd_class == Value) { + cstcall(expp, S_ORD); + } break; case S_TSIZE: /* ??? */ case S_SIZE: arg = getname(arg, D_FIELD|D_VARIABLE|D_TYPE|D_HIDDEN|D_HTYPE); expp->nd_type = intorcard_type; if (!arg) return 0; + cstcall(expp, S_SIZE); break; case S_TRUNC: arg = getarg(arg, T_REAL); if (!arg) return 0; expp->nd_type = card_type; break; - case S_VAL: + case S_VAL: { + struct type *tp; + arg = getname(arg, D_HIDDEN|D_HTYPE|D_TYPE); if (!arg) return 0; tp = arg->nd_left->nd_def->df_type; if (tp->tp_fund == T_SUBRANGE) tp = tp->next; - if (!(tp->tp_fund & (T_ENUMERATION|T_CHAR|T_INTEGER|T_CARDINAL))) { + if (!(tp->tp_fund & T_DISCRETE)) { node_error(arg, "unexpected type"); return 0; } expp->nd_type = arg->nd_left->nd_def->df_type; - FreeNode(arg->nd_left); - arg->nd_left = 0; - arg = getarg(arg, T_INTEGER|T_CARDINAL); + expp->nd_right = arg->nd_right; + arg->nd_right = 0; + FreeNode(arg); + arg = getarg(expp, T_INTORCARD); if (!arg) return 0; + if (arg->nd_left->nd_class == Value) { + cstcall(expp, S_VAL); + } break; + } case S_ADR: arg = getname(arg, D_VARIABLE|D_FIELD|D_PROCEDURE); expp->nd_type = address_type; @@ -358,7 +397,7 @@ node_error(expp, "Size of type in type cast does not match size of operand"); arg = getname(arg, D_VARIABLE|D_FIELD); if (!arg) return 0; if (arg->nd_right) { - arg = getarg(arg, T_INTEGER|T_CARDINAL); + arg = getarg(arg, T_INTORCARD); if (!arg) return 0; } break; @@ -366,7 +405,9 @@ node_error(expp, "Size of type in type cast does not match size of operand"); expp->nd_type = 0; break; case S_EXCL: - case S_INCL: + case S_INCL: { + struct type *tp; + expp->nd_type = 0; arg = getname(arg, D_VARIABLE|D_FIELD); if (!arg) return 0; @@ -375,25 +416,26 @@ node_error(expp, "Size of type in type cast does not match size of operand"); node_error(arg, "EXCL and INCL expect a SET parameter"); return 0; } - arg = getarg(arg, T_INTEGER|T_CARDINAL|T_CHAR|T_ENUMERATION); + arg = getarg(arg, T_DISCRETE); if (!arg) return 0; if (!TstCompat(tp->next, arg->nd_left->nd_type)) { node_error(arg, "Unexpected type"); return 0; } break; + } default: assert(0); } if (arg->nd_right) { node_error(arg->nd_right, - "Too many parameters supplied"); + "too many parameters supplied"); return 0; } - FreeNode(expp->nd_left); - expp->nd_left = 0; return 1; } + /* Here, we have found a real procedure call + */ return 1; } node_error(expp->nd_left, "procedure, type, or function expected"); @@ -527,17 +569,22 @@ node_error(expp, "RHS of IN operator not a SET type"); node_error(expp, "IN operator: type of LHS not compatible with element type of RHS"); return 0; } + if (expp->nd_left->nd_class == Value && + expp->nd_right->nd_class == Set) { + cstset(expp); + } return 1; } if (expp->nd_symb == '[') { /* Handle ARRAY selection specially too! */ if (tpl->tp_fund != T_ARRAY) { -node_error(expp, "array index not belonging to an ARRAY"); + node_error(expp, + "array index not belonging to an ARRAY"); return 0; } if (!TstCompat(tpl->next, tpr)) { -node_error(expp, "incompatible index type"); + node_error(expp, "incompatible index type"); return 0; } expp->nd_type = tpl->arr_elem; @@ -548,7 +595,9 @@ node_error(expp, "incompatible index type"); expp->nd_type = tpl; if (!TstCompat(tpl, tpr)) { -node_error(expp, "Incompatible types for operator \"%s\"", symbol2str(expp->nd_symb)); + node_error(expp, + "Incompatible types for operator \"%s\"", + symbol2str(expp->nd_symb)); return 0; } @@ -559,12 +608,18 @@ node_error(expp, "Incompatible types for operator \"%s\"", symbol2str(expp->nd_s switch(tpl->tp_fund) { case T_INTEGER: case T_CARDINAL: - case T_SET: + case T_INTORCARD: if (expp->nd_left->nd_class == Value && expp->nd_right->nd_class == Value) { cstbin(expp); } return 1; + case T_SET: + if (expp->nd_left->nd_class == Set && + expp->nd_right->nd_class == Set) { + cstset(expp); + } + /* Fall through */ case T_REAL: return 1; } @@ -572,20 +627,18 @@ node_error(expp, "Incompatible types for operator \"%s\"", symbol2str(expp->nd_s case '/': switch(tpl->tp_fund) { case T_SET: - if (expp->nd_left->nd_class == Value && - expp->nd_right->nd_class == Value) { - cstbin(expp); + if (expp->nd_left->nd_class == Set && + expp->nd_right->nd_class == Set) { + cstset(expp); } - return 1; + /* Fall through */ case T_REAL: return 1; } break; case DIV: case MOD: - switch(tpl->tp_fund) { - case T_INTEGER: - case T_CARDINAL: + if (tpl->tp_fund & T_INTORCARD) { if (expp->nd_left->nd_class == Value && expp->nd_right->nd_class == Value) { cstbin(expp); @@ -617,13 +670,14 @@ node_error(expp, "Incompatible types for operator \"%s\"", symbol2str(expp->nd_s } if (expp->nd_left->nd_class == Set && expp->nd_right->nd_class == Set) { - cstbin(expp); + cstset(expp); } return 1; case T_INTEGER: case T_CARDINAL: case T_ENUMERATION: /* includes boolean */ case T_CHAR: + case T_INTORCARD: if (expp->nd_left->nd_class == Value && expp->nd_right->nd_class == Value) { cstbin(expp); @@ -666,10 +720,7 @@ chk_uoper(expp) switch(expp->nd_symb) { case '+': - switch(tpr->tp_fund) { - case T_INTEGER: - case T_REAL: - case T_CARDINAL: + if (tpr->tp_fund & T_NUMERIC) { expp->nd_token = expp->nd_right->nd_token; FreeNode(expp->nd_right); expp->nd_right = 0; @@ -677,13 +728,13 @@ chk_uoper(expp) } break; case '-': - switch(tpr->tp_fund) { - case T_INTEGER: + if (tpr->tp_fund & T_INTORCARD) { if (expp->nd_right->nd_class == Value) { cstunary(expp); } return 1; - case T_REAL: + } + else if (tpr->tp_fund == T_REAL) { if (expp->nd_right->nd_class == Value) { expp->nd_token = expp->nd_right->nd_token; if (*(expp->nd_REL) == '-') { @@ -711,7 +762,7 @@ chk_uoper(expp) default: assert(0); } - node_error(expp, "Illegal operand for unary operator \"%s\"", + node_error(expp, "illegal operand for unary operator \"%s\"", symbol2str(expp->nd_symb)); return 0; } diff --git a/lang/m2/comp/const.h b/lang/m2/comp/const.h index 41f44cf9..28cf5c99 100644 --- a/lang/m2/comp/const.h +++ b/lang/m2/comp/const.h @@ -9,4 +9,5 @@ extern int extern arith max_int, /* maximum integer on target machine */ max_unsigned, /* maximum unsigned on target machine */ + max_longint, /* maximum longint on target machine */ wrd_bits; /* Number of bits in a word */ diff --git a/lang/m2/comp/cstoper.c b/lang/m2/comp/cstoper.c index a6182bd8..81411b29 100644 --- a/lang/m2/comp/cstoper.c +++ b/lang/m2/comp/cstoper.c @@ -11,6 +11,7 @@ static char *RcsId = "$Header$"; #include "LLlex.h" #include "node.h" #include "Lpars.h" +#include "standards.h" long mach_long_sign; /* sign bit of the machine long */ int mach_long_size; /* size of long on this machine == sizeof(long) */ @@ -60,10 +61,7 @@ cstbin(expp) int uns = expp->nd_type != int_type; assert(expp->nd_class == Oper); - if (expp->nd_right->nd_type->tp_fund == T_SET) { - cstset(expp); - return; - } + assert(expp->nd_left->nd_class == Value && expp->nd_right->nd_class == Value); switch (expp->nd_symb) { case '*': o1 *= o2; @@ -288,6 +286,108 @@ cstset(expp) expp->nd_left = expp->nd_right = 0; } +cstcall(expp, call) + register struct node *expp; +{ + /* a standard procedure call is found that can be evaluated + compile time, so do so. + */ + register struct node *expr = 0; + + assert(expp->nd_class == Call); + if (expp->nd_right) { + expr = expp->nd_right->nd_left; + expp->nd_right->nd_left = 0; + FreeNode(expp->nd_right); + } + expp->nd_class = Value; + switch(call) { + case S_ABS: + if (expr->nd_type->tp_fund == T_REAL) { + expp->nd_symb = REAL; + expp->nd_REL = expr->nd_REL; + if (*(expr->nd_REL) == '-') (expp->nd_REL)++; + break; + } + if (expr->nd_INT < 0) expp->nd_INT = - expr->nd_INT; + else expp->nd_INT = expr->nd_INT; + cut_size(expp); + break; + case S_CAP: + if (expr->nd_INT >= 'a' && expr->nd_INT <= 'z') { + expp->nd_INT = expr->nd_INT + ('A' - 'a'); + } + else expp->nd_INT = expr->nd_INT; + cut_size(expp); + break; + case S_CHR: + expp->nd_INT = expr->nd_INT; + cut_size(expp); + break; + case S_MAX: + if (expp->nd_type == int_type) { + expp->nd_INT = max_int; + } + else if (expp->nd_type == longint_type) { + expp->nd_INT = max_longint; + } + else if (expp->nd_type == card_type) { + expp->nd_INT = max_unsigned; + } + else if (expp->nd_type->tp_fund == T_SUBRANGE) { + expp->nd_INT = expp->nd_type->sub_ub; + } + else expp->nd_INT = expp->nd_type->enm_ncst - 1; + break; + case S_MIN: + if (expp->nd_type == int_type) { + expp->nd_INT = (-max_int) - 1; + } + else if (expp->nd_type == longint_type) { + expp->nd_INT = (-max_longint) - 1; + } + else if (expp->nd_type->tp_fund == T_SUBRANGE) { + expp->nd_INT = expp->nd_type->sub_lb; + } + else expp->nd_INT = 0; + break; + case S_ODD: + expp->nd_INT = (expr->nd_INT & 1); + break; + case S_ORD: + expp->nd_INT = expr->nd_INT; + cut_size(expp); + break; + case S_SIZE: + expp->nd_INT = align(expr->nd_type->tp_size, wrd_size)/wrd_size; + break; + case S_VAL: + expp->nd_INT = expr->nd_INT; + if ( /* Check overflow of subranges or enumerations */ + ( expp->nd_type->tp_fund == T_SUBRANGE + && + ( expp->nd_INT < expp->nd_type->sub_lb + || expp->nd_INT > expp->nd_type->sub_ub + ) + ) + || + ( expp->nd_type->tp_fund == T_ENUMERATION + && + ( expp->nd_INT < 0 + || expp->nd_INT >= expp->nd_type->enm_ncst + ) + ) + ) node_warning(expp,"overflow in constant expression"); + else cut_size(expp); + break; + default: + assert(0); + } + FreeNode(expr); + FreeNode(expp->nd_left); + expp->nd_right = expp->nd_left = 0; +} + cut_size(expr) register struct node *expr; { @@ -295,10 +395,13 @@ cut_size(expr) conform to the size of the type of the expression. */ arith o1 = expr->nd_INT; - int uns = expr->nd_type == card_type || expr->nd_type == intorcard_type; - int size = expr->nd_type->tp_size; + struct type *tp = expr->nd_type; + int uns; + int size = tp->tp_size; assert(expr->nd_class == Value); + if (tp->tp_fund == T_SUBRANGE) tp = tp->next; + uns = (tp->tp_fund & (T_CARDINAL|T_CHAR)); if (uns) { if (o1 & ~full_mask[size]) { node_warning(expr, @@ -332,11 +435,12 @@ init_cst() } mach_long_size = i; mach_long_sign = 1 << (mach_long_size * 8 - 1); - if (int_size > mach_long_size) { + if (lint_size > mach_long_size) { fatal("sizeof (long) insufficient on this machine"); } max_int = full_mask[int_size] & ~(1 << (int_size * 8 - 1)); max_unsigned = full_mask[int_size]; + max_longint = full_mask[lint_size] & ~(1 << (lint_size * 8 - 1)); wrd_bits = 8 * wrd_size; } diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 79bc4dc0..857f35c0 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -30,7 +30,7 @@ ProcedureDeclaration ProcedureHeading(struct def **pdf; int type;) { - struct type *tp; + struct type *tp = 0; struct type *tp1 = 0; struct paramlist *params = 0; register struct def *df; @@ -97,7 +97,7 @@ FormalParameters(int doparams; struct paramlist **pr; struct type **tp;) ]? ')' { *tp = 0; } - [ ':' qualident(D_TYPE | D_HTYPE, &df, "type", (struct node **) 0) + [ ':' qualident(D_TYPE|D_HTYPE|D_HIDDEN, &df, "type", (struct node **) 0) { *tp = df->df_type; } ]? ; @@ -135,7 +135,7 @@ FormalType(struct type **tp;) } : [ ARRAY OF { ARRAYflag = 1; } ]? - qualident(D_TYPE | D_HTYPE, &df, "type", (struct node **) 0) + qualident(D_TYPE|D_HTYPE|D_HIDDEN, &df, "type", (struct node **) 0) { if (ARRAYflag) { *tp = construct_type(T_ARRAY, NULLTYPE); (*tp)->arr_elem = df->df_type; @@ -183,7 +183,7 @@ SimpleType(struct type **ptp;) { struct def *df; } : - qualident(D_TYPE | D_HTYPE, &df, "type", (struct node **) 0) + qualident(D_TYPE|D_HTYPE|D_HIDDEN, &df, "type", (struct node **) 0) [ /* nothing */ { *ptp = df->df_type; } @@ -293,6 +293,7 @@ FieldList(struct scope *scope;) struct idf *id; struct def *df, *df1; struct type *tp; + struct node *nd; } : [ IdentList(&FldList) ':' type(&tp) @@ -301,13 +302,51 @@ FieldList(struct scope *scope;) } | CASE - [ - IDENT { id = dot.TOK_IDF; } + /* Also accept old fashioned Modula-2 syntax, but give a warning + */ + [ qualident(0, &df, (char *) 0, &nd) + [ /* This is good, in both kinds of Modula-2, if + the first qualident is a single identifier. + */ + { + if (nd->nd_class != Name) { + error("illegal variant tag"); + id = gen_anon_idf(); + } + else id = nd->nd_IDF; + } + ':' qualident(D_TYPE|D_HTYPE|D_HIDDEN, + &df, "type", (struct node **) 0) + | + /* Old fashioned! the first qualident now represents + the type + */ + { + warning("Old fashioned Modula-2 syntax!"); + id = gen_anon_idf(); + findname(nd); + assert(nd->nd_class == Def); + df = nd->nd_def; + if (!(df->df_kind & + (D_ERROR|D_TYPE|D_HTYPE|D_HIDDEN))) { + error("identifier \"%s\" is not a type", + df->df_idf->id_text); + } + FreeNode(nd); + } + ] | - { id = gen_anon_idf(); } - ] /* Changed rule in new modula-2 */ - ':' qualident(D_TYPE|D_HTYPE, &df, "type", (struct node **) 0) - { df1 = define(id, scope, D_FIELD); + /* Aha, third edition? */ + ':' qualident(D_TYPE|D_HTYPE|D_HIDDEN, + &df, + "type", + (struct node **) 0) + { + id = gen_anon_idf(); + } + ] + { + df1 = define(id, scope, D_FIELD); df1->df_type = df->df_type; } OF variant(scope) @@ -362,7 +401,7 @@ PointerType(struct type **ptp;) /* Either a Module or a Type, but in both cases defined in this scope, so this is the correct identification */ - qualident(D_TYPE|D_HTYPE, &df, "type", (struct node **) 0) + qualident(D_TYPE|D_HTYPE|D_HIDDEN, &df, "type", (struct node **) 0) { if (!df->df_type) { error("type \"%s\" not declared", @@ -428,7 +467,7 @@ FormalTypeList(struct paramlist **ppr; struct type **ptp;) { p->next = 0; } ]? ')' - [ ':' qualident(D_TYPE|D_HTYPE, &df, "type", (struct node **) 0) + [ ':' qualident(D_TYPE|D_HTYPE|D_HIDDEN, &df, "type", (struct node **) 0) { *ptp = df->df_type; } ]? ; diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H index 274f9290..30fc1b49 100644 --- a/lang/m2/comp/def.H +++ b/lang/m2/comp/def.H @@ -43,8 +43,12 @@ struct dfproc { }; struct import { - struct def *im_def; /* imported definition */ -#define imp_def df_value.df_import.im_def + union { + struct def *im_def; /* imported definition */ + struct node *im_nodef; /* imported from undefined name */ + } im_u; +#define imp_def df_value.df_import.im_u.im_def +#define imp_nodef df_value.df_import.im_u.im_nodef }; struct def { /* list of definitions for a name */ @@ -65,12 +69,12 @@ struct def { /* list of definitions for a name */ #define D_PROCHEAD 0x0100 /* a procedure heading in a definition module */ #define D_HIDDEN 0x0200 /* a hidden type */ #define D_HTYPE 0x0400 /* definition of a hidden type seen */ -#define D_STDPROC 0x0800 /* a standard procedure */ -#define D_STDFUNC 0x1000 /* a standard function */ -#define D_ERROR 0x2000 /* a compiler generated definition for an +#define D_FORWARD 0x0800 /* not yet defined */ +#define D_UNDEF_IMPORT 0x1000 /* imported from an undefined name */ +#define D_FORWMODULE 0x2000 /* module must be declared later */ +#define D_ERROR 0x4000 /* a compiler generated definition for an undefined variable */ -#define D_ISEXPORTED 0x4000 /* not yet defined */ char df_flags; #define D_ADDRESS 0x01 /* set if address was taken */ #define D_USED 0x02 /* set if used */ diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index b0f44480..d8888c66 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -7,7 +7,6 @@ static char *RcsId = "$Header$"; #include #include #include "main.h" -#include "Lpars.h" #include "def.h" #include "type.h" #include "idf.h" @@ -33,7 +32,8 @@ define(id, scope, kind) */ register struct def *df; - DO_DEBUG(5, debug("Defining identifier \"%s\" in scope %d", id->id_text, scope->sc_scope)); + DO_DEBUG(5, debug("Defining identifier \"%s\" in scope %d, kind = %d", + id->id_text, scope->sc_scope, kind)); df = lookup(id, scope->sc_scope); if ( /* Already in this scope */ df @@ -47,7 +47,10 @@ define(id, scope, kind) switch(df->df_kind) { case D_PROCHEAD: if (kind == D_PROCEDURE) { - df->df_kind = D_PROCEDURE; + /* Definition of which the heading was + already seen in a definition module + */ + df->df_kind = kind; return df; } break; @@ -57,8 +60,14 @@ define(id, scope, kind) return df; } break; + case D_FORWMODULE: + if (kind & (D_FORWMODULE|D_MODULE)) { + df->df_kind = kind; + return df; + } + break; case D_ERROR: - case D_ISEXPORTED: + case D_FORWARD: df->df_kind = kind; return df; } @@ -72,6 +81,7 @@ error("identifier \"%s\" already declared", id->id_text); df->df_scope = scope->sc_scope; df->df_kind = kind; df->next = id->id_def; + df->df_flags = 0; id->id_def = df; /* enter the definition in the list of definitions in this scope */ @@ -101,6 +111,21 @@ lookup(id, scope) assert(df != 0); return df; } + + if (df->df_kind == D_UNDEF_IMPORT) { + df1 = df->imp_def; + assert(df1 != 0); + if (df1->df_kind == D_MODULE) { + df1 = lookup(id, df1->mod_scope); + if (df1) { + df->df_kind = D_IMPORT; + df->imp_def = df1; + } + return df1; + } + return df; + } + if (df1) { df1->next = df->next; df->next = id->id_def; @@ -122,17 +147,31 @@ Export(ids, qualified) all the "ids" visible in the enclosing scope by defining them in this scope as "imported". */ - register struct def *df; + register struct def *df, *df1; while (ids) { - df = define(ids->nd_IDF, CurrentScope, D_ISEXPORTED); + df = define(ids->nd_IDF, CurrentScope, D_FORWARD); if (qualified) { df->df_flags |= D_QEXPORTED; } else { df->df_flags |= D_EXPORTED; - df = define(ids->nd_IDF, enclosing(CurrentScope), - D_IMPORT); + df1 = lookup(ids->nd_IDF, + enclosing(CurrentScope)->sc_scope); + if (! df1 || !(df1->df_kind & (D_PROCHEAD|D_HIDDEN))) { + df1 = define(ids->nd_IDF, + enclosing(CurrentScope), + D_IMPORT); + } + else { + /* A hidden type or a procedure of which only + the head is seen. Apparently, they are + exported from a local module! + */ + df->df_kind = df1->df_kind; + df1->df_kind = D_IMPORT; + } + df1->imp_def = df; } ids = ids->next; } @@ -168,9 +207,24 @@ Import(ids, idn, local) if (!idn) imp_kind = FROM_ENCLOSING; else { imp_kind = FROM_MODULE; - if (local) df = lookfor(idn, enclosing(CurrentScope), 1); - else df = GetDefinitionModule(idn->nd_IDF); - if (df->df_kind != D_MODULE) { + if (local) { + df = lookfor(idn, enclosing(CurrentScope), 0); + if (df->df_kind == D_ERROR) { + /* The module from which the import was done + is not yet declared. I'm not sure if I must + accept this, but for the time being I will. + ??? + */ + df->df_scope = scope; + df->df_kind = D_FORWMODULE; + df->mod_scope = -1; + kind = D_UNDEF_IMPORT; + } + } + else { + df = GetDefinitionModule(idn->nd_IDF); + } + if (!(df->df_kind & (D_MODULE|D_FORWMODULE))) { /* enter all "ids" with type D_ERROR */ kind = D_ERROR; if (df->df_kind != D_ERROR) { @@ -181,13 +235,14 @@ node_error(idn, "identifier \"%s\" does not represent a module", idn->nd_IDF->id } while (ids) { if (imp_kind == FROM_MODULE) { - if (!(df = lookup(ids->nd_IDF, scope))) { + if (scope == -1) { + } + else if (!(df = lookup(ids->nd_IDF, scope))) { node_error(ids, "identifier \"%s\" not declared in qualifying module", ids->nd_IDF->id_text); df = ill_df; } - else - if (!(df->df_flags&(D_EXPORTED|D_QEXPORTED))) { + else if (!(df->df_flags&(D_EXPORTED|D_QEXPORTED))) { node_error(ids,"identifier \"%s\" not exported from qualifying module", ids->nd_IDF->id_text); } diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index 8ae0e285..52380bc3 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -29,7 +29,7 @@ Enter(name, kind, type, pnam) if (!id) fatal("Out of core"); df = define(id, CurrentScope, kind); df->df_type = type; - if (kind == D_STDPROC || kind == D_STDFUNC) { + if (type = std_type) { df->df_value.df_stdname = pnam; } return df; @@ -54,7 +54,7 @@ EnterIdList(idlist, kind, flags, type, scope) while (idlist) { df = define(idlist->nd_IDF, scope, kind); df->df_type = type; - df->df_flags = flags; + df->df_flags |= flags; if (kind == D_ENUM) { if (!first) first = df; df->enm_val = assval++; diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index 6a9e1556..60c33ca2 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -48,8 +48,7 @@ qualident(int types; struct def **pdf; char *str; struct node **p;) findname(nd); assert(nd->nd_class == Def); *pdf = df = nd->nd_def; - if (df->df_kind != D_ERROR && - !(types & df->df_kind)) { + if ( !((types|D_ERROR) & df->df_kind)) { error("identifier \"%s\" is not a %s", df->df_idf->id_text, str); } @@ -183,7 +182,11 @@ factor(struct node **p;) number(p) | STRING { *p = MkNode(Value, NULLNODE, NULLNODE, &dot); - (*p)->nd_type = string_type; + if (dot.TOK_SLE == 1) { + dot.TOK_INT = *(dot.TOK_STR); + (*p)->nd_type = char_type; + } + else (*p)->nd_type = string_type; } | '(' expression(p) ')' diff --git a/lang/m2/comp/type.H b/lang/m2/comp/type.H index d144e445..8abf6981 100644 --- a/lang/m2/comp/type.H +++ b/lang/m2/comp/type.H @@ -68,6 +68,9 @@ struct type { #define T_PROCEDURE 0x1000 #define T_ARRAY 0x2000 #define T_STRING 0x4000 +#define T_INTORCARD (T_INTEGER|T_CARDINAL) +#define T_DISCRETE (T_ENUMERATION|T_INTORCARD|T_CHAR) +#define T_NUMERIC (T_INTORCARD|T_REAL) int tp_align; /* alignment requirement of this type */ arith tp_size; /* size of this type */ union { diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index f509f0d0..7efa40a4 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -7,7 +7,6 @@ static char *RcsId = "$Header$"; #include #include #include "def_sizes.h" -#include "Lpars.h" #include "def.h" #include "type.h" #include "idf.h" @@ -141,7 +140,7 @@ init_types() real_type = standard_type(T_REAL, real_align, real_size); longreal_type = standard_type(T_REAL, lreal_align, lreal_size); word_type = standard_type(T_WORD, wrd_align, wrd_size); - intorcard_type = standard_type(T_INTEGER, int_align, int_size); + intorcard_type = standard_type(T_INTORCARD, int_align, int_size); string_type = standard_type(T_STRING, 1, (arith) -1); address_type = construct_type(T_POINTER, word_type); tp = construct_type(T_SUBRANGE, int_type); diff --git a/lang/m2/comp/typequiv.c b/lang/m2/comp/typequiv.c index 9cf8621f..9c97fdd2 100644 --- a/lang/m2/comp/typequiv.c +++ b/lang/m2/comp/typequiv.c @@ -6,16 +6,17 @@ static char *RcsId = "$Header$"; #include #include "type.h" #include "def.h" -#include "Lpars.h" int TstTypeEquiv(tp1, tp2) register struct type *tp1, *tp2; { - /* test if two types are equivalent. The only complication comes + /* test if two types are equivalent. A complication comes from the fact that for some procedures two declarations may be given: one in the specification module and one in the definition module. + A related problem is that two dynamic arrays with the + same base type are also equivalent. */ return tp1 == tp2 @@ -23,6 +24,18 @@ TstTypeEquiv(tp1, tp2) tp1 == error_type || tp2 == error_type + || + ( + tp1->tp_fund == T_ARRAY + && + tp1->next == 0 + && + tp2->tp_fund == T_ARRAY + && + tp2->next == 0 + && + TstTypeEquiv(tp1->arr_elem, tp2->arr_elem) + ) || ( tp1 && tp1->tp_fund == T_PROCEDURE From 892b48787bbf068ce6472ecda8f63f0f1e0eeade Mon Sep 17 00:00:00 2001 From: ceriel Date: Sat, 12 Apr 1986 02:21:24 +0000 Subject: [PATCH 0177/1625] newer version --- lang/m2/comp/declar.g | 3 +- lang/m2/comp/def.H | 16 ++++-- lang/m2/comp/def.c | 116 +++++++++++++++++++++++--------------- lang/m2/comp/expression.g | 8 ++- lang/m2/comp/node.c | 1 + lang/m2/comp/program.g | 36 +++++++----- lang/m2/comp/scope.C | 66 +++++++++++++++++++--- lang/m2/comp/scope.h | 7 +++ 8 files changed, 177 insertions(+), 76 deletions(-) diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 857f35c0..06244583 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -24,7 +24,7 @@ ProcedureDeclaration ';' block IDENT { match_id(dot.TOK_IDF, df->df_idf); df->prc_scope = CurrentScope->sc_scope; - close_scope(); + close_scope(SC_CHKFORW); } ; @@ -39,6 +39,7 @@ ProcedureHeading(struct def **pdf; int type;) { assert(type & (D_PROCEDURE | D_PROCHEAD)); if (type == D_PROCHEAD) { df = define(dot.TOK_IDF, CurrentScope, type); + df->for_node = MkNode(Name, NULLNODE, NULLNODE, &dot); } else { df = lookup(dot.TOK_IDF, diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H index 30fc1b49..35f75794 100644 --- a/lang/m2/comp/def.H +++ b/lang/m2/comp/def.H @@ -43,12 +43,15 @@ struct dfproc { }; struct import { - union { - struct def *im_def; /* imported definition */ - struct node *im_nodef; /* imported from undefined name */ - } im_u; -#define imp_def df_value.df_import.im_u.im_def -#define imp_nodef df_value.df_import.im_u.im_nodef + struct def *im_def; /* imported definition */ +#define imp_def df_value.df_import.im_def +}; + +struct dforward { + int fo_scope; + struct node *fo_node; +#define for_node df_value.df_forward.fo_node +#define for_scope df_value.df_forward.fo_scope }; struct def { /* list of definitions for a name */ @@ -92,6 +95,7 @@ struct def { /* list of definitions for a name */ struct field df_field; struct import df_import; struct dfproc df_proc; + struct dforward df_forward; int df_stdname; /* define for standard name */ } df_value; }; diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index d8888c66..c47b3218 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -61,13 +61,23 @@ define(id, scope, kind) } break; case D_FORWMODULE: - if (kind & (D_FORWMODULE|D_MODULE)) { + if (kind == D_FORWMODULE) { + df->df_kind = kind; + return df; + } + if (kind == D_MODULE) { + FreeNode(df->for_node); + df->mod_scope = df->for_scope; df->df_kind = kind; return df; } break; - case D_ERROR: case D_FORWARD: + if (kind != D_FORWARD) { + FreeNode(df->for_node); + } + /* Fall Through */ + case D_ERROR: df->df_kind = kind; return df; } @@ -77,11 +87,11 @@ error("identifier \"%s\" already declared", id->id_text); return df; } df = new_def(); + df->df_flags = 0; df->df_idf = id; df->df_scope = scope->sc_scope; df->df_kind = kind; df->next = id->id_def; - df->df_flags = 0; id->id_def = df; /* enter the definition in the list of definitions in this scope */ @@ -100,30 +110,17 @@ lookup(id, scope) otherwise return 0. */ register struct def *df, *df1; + struct def *retval; df1 = 0; df = id->id_def; DO_DEBUG(5, debug("Looking for identifier \"%s\" in scope %d", id->id_text, scope)); while (df) { if (df->df_scope == scope) { + retval = df; if (df->df_kind == D_IMPORT) { - df = df->imp_def; - assert(df != 0); - return df; - } - - if (df->df_kind == D_UNDEF_IMPORT) { - df1 = df->imp_def; - assert(df1 != 0); - if (df1->df_kind == D_MODULE) { - df1 = lookup(id, df1->mod_scope); - if (df1) { - df->df_kind = D_IMPORT; - df->imp_def = df1; - } - return df1; - } - return df; + retval = df->imp_def; + assert(retval != 0); } if (df1) { @@ -131,7 +128,7 @@ lookup(id, scope) df->next = id->id_def; id->id_def = df; } - return df; + return retval; } df1 = df; df = df->next; @@ -148,9 +145,19 @@ Export(ids, qualified) in this scope as "imported". */ register struct def *df, *df1; + struct node *nd = ids; while (ids) { - df = define(ids->nd_IDF, CurrentScope, D_FORWARD); + df = lookup(ids->nd_IDF, CurrentScope->sc_scope); + if (df && (df->df_flags & (D_EXPORTED|D_QEXPORTED))) { +node_error(ids, "Identifier \"%s\" occurs more than once in export list", +df->df_idf->id_text); + } + else if (!df) { + df = define(ids->nd_IDF, CurrentScope, D_FORWARD); + df->for_node = MkNode(Name,NULLNODE,NULLNODE, + &(ids->nd_token)); + } if (qualified) { df->df_flags |= D_QEXPORTED; } @@ -175,6 +182,7 @@ Export(ids, qualified) } ids = ids->next; } + FreeNode(nd); } Import(ids, idn, local) @@ -195,6 +203,7 @@ Import(ids, idn, local) identifiers defined in this module. */ register struct def *df; + struct def *df1 = 0; int scope; int kind; int imp_kind; @@ -204,7 +213,8 @@ Import(ids, idn, local) kind = D_IMPORT; scope = enclosing(CurrentScope)->sc_scope; - if (!idn) imp_kind = FROM_ENCLOSING; + + if (! idn) imp_kind = FROM_ENCLOSING; else { imp_kind = FROM_MODULE; if (local) { @@ -217,25 +227,39 @@ Import(ids, idn, local) */ df->df_scope = scope; df->df_kind = D_FORWMODULE; - df->mod_scope = -1; - kind = D_UNDEF_IMPORT; + open_scope(CLOSEDSCOPE, 0); + df->for_scope = CurrentScope->sc_scope; + df->for_node = MkNode(Name, NULLNODE, + NULLNODE, &(idn->nd_token)); + close_scope(); + df1 = df; } } - else { - df = GetDefinitionModule(idn->nd_IDF); - } + else df = GetDefinitionModule(idn->nd_IDF); + if (!(df->df_kind & (D_MODULE|D_FORWMODULE))) { /* enter all "ids" with type D_ERROR */ kind = D_ERROR; if (df->df_kind != D_ERROR) { -node_error(idn, "identifier \"%s\" does not represent a module", idn->nd_IDF->id_text); +node_error(idn, "identifier \"%s\" does not represent a module", +idn->nd_IDF->id_text); } } else scope = df->mod_scope; + FreeNode(idn); } + + idn = ids; while (ids) { if (imp_kind == FROM_MODULE) { - if (scope == -1) { + if (df1 != 0) { + open_scope(CLOSEDSCOPE, df1->mod_scope); + df = define(ids->nd_IDF, + CurrentScope, + D_FORWARD); + df->for_node = MkNode(Name, NULLNODE, + NULLNODE, &(ids->nd_token)); + close_scope(0); } else if (!(df = lookup(ids->nd_IDF, scope))) { node_error(ids, "identifier \"%s\" not declared in qualifying module", @@ -250,13 +274,18 @@ ids->nd_IDF->id_text); else { if (local) { df = lookfor(ids, enclosing(CurrentScope), 0); - } else df = GetDefinitionModule(ids->nd_IDF); + } else df = GetDefinitionModule(ids->nd_IDF); if (df->df_kind == D_ERROR) { -node_error(ids, "identifier \"%s\" not visible in enclosing scope", -ids->nd_IDF->id_text); + /* It was not yet defined in the enclosing + scope. + */ + df->df_kind = D_FORWARD; + df->for_node = MkNode(Name, NULLNODE, NULLNODE, + &(ids->nd_token)); } } - DO_DEBUG(2, debug("importing \"%s\", kind %d", ids->nd_IDF->id_text, df->df_kind)); +DO_DEBUG(2, debug("importing \"%s\", kind %d", ids->nd_IDF->id_text, +df->df_kind)); define(ids->nd_IDF, CurrentScope, kind)->imp_def = df; if (df->df_kind == D_TYPE && df->df_type->tp_fund == T_ENUMERATION) { @@ -266,6 +295,7 @@ ids->nd_IDF->id_text); } ids = ids->next; } + FreeNode(idn); } exprt_literals(df, toscope) @@ -290,26 +320,18 @@ RemImports(pdf) neccesary because the implementation module might import them again. */ - register struct def *df = *pdf, *df1 = 0; + register struct def *df = *pdf; while (df) { if (df->df_kind == D_IMPORT) { RemFromId(df); - if (df1) { - df1->df_nextinscope = df->df_nextinscope; - free_def(df); - df = df1->df_nextinscope; - } - else { - *pdf = df->df_nextinscope; - free_def(df); - df = *pdf; - } + *pdf = df->df_nextinscope; + free_def(df); } else { - df1 = df; - df = df->df_nextinscope; + pdf = &(df->df_nextinscope); } + df = *pdf; } } diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index 60c33ca2..dfe210ba 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -49,8 +49,12 @@ qualident(int types; struct def **pdf; char *str; struct node **p;) assert(nd->nd_class == Def); *pdf = df = nd->nd_def; if ( !((types|D_ERROR) & df->df_kind)) { - error("identifier \"%s\" is not a %s", - df->df_idf->id_text, str); + if (df->df_kind == D_FORWARD) { +node_error(*pnd,"%s \"%s\" not declared", str, df->df_idf->id_text); + } + else { +node_error(*pnd,"identifier \"%s\" is not a %s", df->df_idf->id_text, str); + } } } if (!p) FreeNode(nd); diff --git a/lang/m2/comp/node.c b/lang/m2/comp/node.c index 35cd416d..e852541e 100644 --- a/lang/m2/comp/node.c +++ b/lang/m2/comp/node.c @@ -38,6 +38,7 @@ FreeNode(nd) /* Put nodes that are no longer needed back onto the free list */ + if (!nd) return; if (nd->nd_left) FreeNode(nd->nd_left); if (nd->nd_right) FreeNode(nd->nd_right); free_node(nd); diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 0cca0902..3ff352b2 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -15,7 +15,11 @@ static char *RcsId = "$Header$"; #include "node.h" #include "debug.h" -static struct idf *impl_name = 0; +static int DEFofIMPL = 0; /* Flag indicating that we are currently + parsing the definition module of the + implementation module currently being + compiled + */ static struct def *impl_df; } /* @@ -45,8 +49,11 @@ ModuleDeclaration MODULE IDENT { id = dot.TOK_IDF; df = define(id, CurrentScope, D_MODULE); - open_scope(CLOSEDSCOPE, 0); - df->mod_scope = CurrentScope->sc_scope; + if (!df->mod_scope) { + open_scope(CLOSEDSCOPE, 0); + df->mod_scope = CurrentScope->sc_scope; + } + else open_scope(CLOSEDSCOPE, df->mod_scope); df->df_type = standard_type(T_RECORD, 0, (arith) 0); df->df_type->rec_scope = df->mod_scope; @@ -55,7 +62,7 @@ ModuleDeclaration import(1)* export(0)? block - IDENT { close_scope(); + IDENT { close_scope(SC_CHKFORW|SC_CHKPROC); match_id(id, dot.TOK_IDF); } ; @@ -78,9 +85,13 @@ export(int def;) ]? IdentList(&ExportList) ';' { - if (!def) Export(ExportList, QUALflag); - else warning("export list in definition module ignored"); - FreeNode(ExportList); + if (!def) { + Export(ExportList, QUALflag); + } + else { + warning("export list in definition module ignored"); + FreeNode(ExportList); + } } ; @@ -101,8 +112,6 @@ import(int local;) */ { Import(ImportList, id, local); - FreeNode(ImportList); - if (id) FreeNode(id); } ; @@ -130,7 +139,7 @@ DefinitionModule */ definition* END IDENT { - if (id == impl_name) { + if (DEFofIMPL) { /* Just read the definition module of the implementation module being compiled */ @@ -143,7 +152,7 @@ DefinitionModule df->df_flags |= D_QEXPORTED; df = df->df_nextinscope; } - if (!SYSTEMModule) close_scope(); + if (!SYSTEMModule) close_scope(SC_CHKFORW); DefinitionModule = 0; match_id(id, dot.TOK_IDF); } @@ -185,9 +194,10 @@ ProgramModule(int state;) IDENT { id = dot.TOK_IDF; if (state == IMPLEMENTATION) { - impl_name = id; + DEFofIMPL = 1; df = GetDefinitionModule(id); scope = df->mod_scope; + DEFofIMPL = 0; } DefinitionModule = 0; open_scope(CLOSEDSCOPE, scope); @@ -196,7 +206,7 @@ ProgramModule(int state;) priority? ';' import(0)* block IDENT - { close_scope(); + { close_scope(SC_CHKFORW|SC_CHKPROC); match_id(id, dot.TOK_IDF); } '.' diff --git a/lang/m2/comp/scope.C b/lang/m2/comp/scope.C index 5162923a..e7a0fcf7 100644 --- a/lang/m2/comp/scope.C +++ b/lang/m2/comp/scope.C @@ -92,21 +92,73 @@ Forward(tk, ptp) CurrentScope->sc_forw = f; } -close_scope() +close_scope(flag) { + /* Close a scope. If "flag" is set, check for forward declarations, + either POINTER declarations, or EXPORTs, or forward references + to MODULES + */ register struct scope *sc = CurrentScope; + register struct def *df, *dfback = 0; assert(sc != 0); DO_DEBUG(1, debug("Closing a scope")); - if (sc->sc_forw) rem_forwards(sc->sc_forw); - if (sc->next && (sc->next->sc_scope == 0)) { - struct scope *sc1 = sc; + if (flag) { + if (sc->sc_forw) rem_forwards(sc->sc_forw); + df = sc->sc_def; + while(df) { + if (flag & SC_CHKPROC) { + if (df->df_kind == D_PROCHEAD) { + /* A not defined procedure + */ +node_error(df->for_node, "procedure \"%s\" not defined", df->df_idf->id_text); + FreeNode(df->for_node); + } + } + if ((flag & SC_CHKFORW) && + df->df_kind & (D_FORWARD|D_FORWMODULE)) { + /* These definitions must be found in + the enclosing closed scope, which of course + may be the scope that is now closed! + */ + struct def *df1 = df->df_nextinscope; + + if (scopeclosed(CurrentScope)) { + /* Indeed, the scope was a closed + scope, so give error message + */ +node_error(df->for_node, "identifier \"%s\" not declared", df->df_idf->id_text); + FreeNode(df->for_node); + dfback = df; + } + else { + /* This scope was an open scope. + Maybe the definitions are in the + enclosing scope? + */ + struct scope *sc; + + sc = enclosing(CurrentScope); + df->df_nextinscope = sc->sc_def; + sc->sc_def = df; + df->df_scope = sc->sc_scope; + if (dfback) dfback->df_nextinscope = df1; + else sc->sc_def = df1; + } + df = df1; + } + else { + dfback = df; + df = df->df_nextinscope; + } + } + } + + if (sc->next && (sc->next->sc_scope == 0)) { sc = sc->next; - free_scope(sc1); } CurrentScope = sc->next; - free_scope(sc); } static @@ -121,7 +173,7 @@ rem_forwards(fo) while (f = fo) { df = lookfor(&(f->fo_tok), CurrentScope, 1); - if (!(df->df_kind & (D_TYPE | D_HTYPE | D_ERROR))) { + if (!(df->df_kind & (D_TYPE|D_HTYPE|D_ERROR))) { node_error(&(f->fo_tok), "identifier \"%s\" not a type", df->df_idf->id_text); } diff --git a/lang/m2/comp/scope.h b/lang/m2/comp/scope.h index c8e6d9c9..e009ccf7 100644 --- a/lang/m2/comp/scope.h +++ b/lang/m2/comp/scope.h @@ -5,6 +5,13 @@ #define OPENSCOPE 0 /* Indicating an open scope */ #define CLOSEDSCOPE 1 /* Indicating a closed scope (module) */ +#define SC_CHKFORW 1 /* Check for forward definitions when closing + a scope + */ +#define SC_CHKPROC 2 /* Check for forward procedure definitions + when closing a scope + */ + struct scope { struct scope *next; struct forwards *sc_forw; From 5cb0474789bf4a232cf5a57933049b8138c43a2a Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 15 Apr 1986 17:51:53 +0000 Subject: [PATCH 0178/1625] newer version --- lang/m2/comp/LLlex.c | 20 ++-- lang/m2/comp/LLlex.h | 1 + lang/m2/comp/chk_expr.c | 8 +- lang/m2/comp/declar.g | 215 ++++++++++++++++++++++++-------------- lang/m2/comp/def.H | 14 ++- lang/m2/comp/def.c | 159 ++++++++++++++++------------ lang/m2/comp/defmodule.c | 4 +- lang/m2/comp/enter.c | 62 ++++++++++- lang/m2/comp/expression.g | 4 +- lang/m2/comp/main.c | 6 +- lang/m2/comp/program.g | 30 +++--- lang/m2/comp/scope.C | 182 +++++++++++++++++--------------- lang/m2/comp/scope.h | 13 ++- lang/m2/comp/statement.g | 166 +++++++++++++++++++++-------- lang/m2/comp/type.H | 5 +- lang/m2/comp/type.c | 100 ++++++++++++++---- lang/m2/comp/typequiv.c | 10 +- 17 files changed, 648 insertions(+), 351 deletions(-) diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index b0eb90e1..db080a5f 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -4,13 +4,16 @@ static char *RcsId = "$Header$"; #include #include +#include #include #include "input.h" #include "f_info.h" #include "Lpars.h" #include "class.h" #include "idf.h" +#include "type.h" #include "LLlex.h" +#include "const.h" #define IDFSIZE 256 /* Number of significant characters in an identifier */ #define NUMSIZE 256 /* maximum number of characters in a number */ @@ -18,6 +21,7 @@ static char *RcsId = "$Header$"; long str2long(); struct token dot, aside; +struct type *numtype; struct string string; static @@ -102,6 +106,7 @@ LLlex() char buf[(IDFSIZE > NUMSIZE ? IDFSIZE : NUMSIZE) + 1]; register int ch, nch; + numtype = error_type; if (ASIDE) { /* a token is put aside */ *tk = aside; ASIDE = 0; @@ -236,7 +241,7 @@ again: switch (ch) { case 'H': Shex: *np++ = '\0'; - /* Type is integer */ + numtype = card_type; tk->TOK_INT = str2long(&buf[1], 16); return tk->tk_symb = INTEGER; @@ -271,10 +276,10 @@ Shex: *np++ = '\0'; PushBack(ch); ch = *--np; *np++ = '\0'; - /* - * If (ch == 'C') type is a CHAR - * else type is an INTEGER - */ + if (ch == 'C') { + numtype = char_type; + } + else numtype = card_type; tk->TOK_INT = str2long(&buf[1], 8); return tk->tk_symb = INTEGER; @@ -369,8 +374,11 @@ Sreal: PushBack(ch); Sdec: *np++ = '\0'; - /* Type is an integer */ tk->TOK_INT = str2long(&buf[1], 10); + if (tk->TOK_INT < 0 || tk->TOK_INT > max_int) { + numtype = card_type; + } + else numtype = intorcard_type; return tk->tk_symb = INTEGER; } /*NOTREACHED*/ diff --git a/lang/m2/comp/LLlex.h b/lang/m2/comp/LLlex.h index db49e6b9..31ddcd46 100644 --- a/lang/m2/comp/LLlex.h +++ b/lang/m2/comp/LLlex.h @@ -28,6 +28,7 @@ struct token { #define TOK_REL tk_data.tk_real extern struct token dot, aside; +extern struct type *numtype; #define DOT dot.tk_symb #define ASIDE aside.tk_symb diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index 67075d10..fdd55cb4 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -266,7 +266,9 @@ node_error(expp, "Size of type in type cast does not match size of operand"); } arg->nd_type = left->nd_type; FreeNode(expp->nd_left); - *expp = *(arg->nd_left); + expp->nd_right->nd_left = 0; + FreeNode(expp->nd_right); + *expp = *arg; arg->nd_left = 0; arg->nd_right = 0; FreeNode(arg); @@ -451,8 +453,6 @@ findname(expp) register struct def *df; struct def *lookfor(); register struct type *tp; - int scope; - int module; expp->nd_type = error_type; if (expp->nd_class == Name) { @@ -596,7 +596,7 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R if (!TstCompat(tpl, tpr)) { node_error(expp, - "Incompatible types for operator \"%s\"", + "incompatible types for operator \"%s\"", symbol2str(expp->nd_symb)); return 0; } diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 06244583..afedfbbe 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -14,6 +14,8 @@ static char *RcsId = "$Header$"; #include "scope.h" #include "node.h" #include "misc.h" + +static int proclevel = 0; /* nesting level of procedures */ } ProcedureDeclaration @@ -21,10 +23,13 @@ ProcedureDeclaration struct def *df; } : ProcedureHeading(&df, D_PROCEDURE) + { df->prc_level = proclevel++; + } ';' block IDENT { match_id(dot.TOK_IDF, df->df_idf); - df->prc_scope = CurrentScope->sc_scope; + df->prc_scope = CurrentScope; close_scope(SC_CHKFORW); + proclevel--; } ; @@ -36,38 +41,38 @@ ProcedureHeading(struct def **pdf; int type;) register struct def *df; } : PROCEDURE IDENT - { assert(type & (D_PROCEDURE | D_PROCHEAD)); - if (type == D_PROCHEAD) { - df = define(dot.TOK_IDF, CurrentScope, type); - df->for_node = MkNode(Name, NULLNODE, NULLNODE, &dot); - } - else { - df = lookup(dot.TOK_IDF, - CurrentScope->sc_scope); - if (df && df->df_kind == D_PROCHEAD) { - df->df_kind = type; - tp1 = df->df_type; - } - else { - df = define(dot.TOK_IDF, - CurrentScope, type); - } - open_scope(OPENSCOPE, 0); - } + { assert(type & (D_PROCEDURE | D_PROCHEAD)); + if (type == D_PROCHEAD) { + df = define(dot.TOK_IDF, CurrentScope, type); + df->for_node = MkNode(Name, NULLNODE, NULLNODE, &dot); + } + else { + df = lookup(dot.TOK_IDF, CurrentScope); + if (df && df->df_kind == D_PROCHEAD) { + df->df_kind = type; + tp1 = df->df_type; } - FormalParameters(type == D_PROCEDURE, ¶ms, &tp)? - { - df->df_type = tp = construct_type(T_PROCEDURE, tp); - tp->prc_params = params; - if (tp1 && !TstTypeEquiv(tp, tp1)) { + else df = define(dot.TOK_IDF, CurrentScope, type); + df->prc_nbpar = 0; + open_scope(OPENSCOPE); + } + } + FormalParameters(type == D_PROCEDURE, ¶ms, &tp, &(df->prc_nbpar))? + { + df->df_type = tp = construct_type(T_PROCEDURE, tp); + tp->prc_params = params; + if (tp1 && !TstTypeEquiv(tp, tp1)) { error("inconsistent procedure declaration for \"%s\"", df->df_idf->id_text); - } - *pdf = df; - } + } + *pdf = df; + } ; -block: - declaration* [ BEGIN StatementSequence ]? END +block +{ + struct node *nd; +}: + declaration* [ BEGIN StatementSequence(&nd) ]? END ; declaration: @@ -82,18 +87,21 @@ declaration: ModuleDeclaration ';' ; -FormalParameters(int doparams; struct paramlist **pr; struct type **tp;) +FormalParameters(int doparams; + struct paramlist **pr; + struct type **tp; + arith *parmaddr;) { struct def *df; register struct paramlist *pr1; } : '(' [ - FPSection(doparams, pr) + FPSection(doparams, pr, parmaddr) { pr1 = *pr; } [ { for (; pr1->next; pr1 = pr1->next) ; } - ';' FPSection(doparams, &(pr1->next)) + ';' FPSection(doparams, &(pr1->next), &parmaddr) ]* ]? ')' @@ -109,7 +117,7 @@ FormalParameters(int doparams; struct paramlist **pr; struct type **tp;) because in this case we only read the header. The Implementation might contain different identifiers representing the same paramters. */ -FPSection(int doparams; struct paramlist **ppr;) +FPSection(int doparams; struct paramlist **ppr; arith *addr;) { struct node *FPList; struct paramlist *ParamList(); @@ -122,7 +130,8 @@ FPSection(int doparams; struct paramlist **ppr;) IdentList(&FPList) ':' FormalType(&tp) { if (doparams) { - EnterIdList(FPList, D_VARIABLE, VARp, tp, CurrentScope); + EnterIdList(FPList, D_VARIABLE, VARp, + tp, CurrentScope, addr); } *ppr = ParamList(FPList, tp, VARp); FreeNode(FPList); @@ -140,6 +149,9 @@ FormalType(struct type **tp;) { if (ARRAYflag) { *tp = construct_type(T_ARRAY, NULLTYPE); (*tp)->arr_elem = df->df_type; + (*tp)->tp_align = lcm(wrd_align, ptr_align); + (*tp)->tp_size = align(ptr_size + 3*wrd_size, + (*tp)->tp_align); } else *tp = df->df_type; } @@ -209,11 +221,20 @@ enumeration(struct type **ptp;) } : '(' IdentList(&EnumList) ')' { - *ptp = standard_type(T_ENUMERATION,int_align,int_size); - EnterIdList(EnumList, D_ENUM, 0, *ptp, CurrentScope); + *ptp = standard_type(T_ENUMERATION,1,1); + EnterIdList(EnumList, D_ENUM, 0, *ptp, + CurrentScope, (arith *) 0); FreeNode(EnumList); + if ((*ptp)->enm_ncst > 256) { + if (wrd_size == 1) { + error("Too many enumeration literals"); + } + else { + (*ptp)->tp_size = wrd_size; + (*ptp)->tp_align = wrd_align; + } + } } - ; IdentList(struct node **p;) @@ -261,44 +282,52 @@ ArrayType(struct type **ptp;) construct_type(T_ARRAY, tp); } ]* OF type(&tp) - { tp2->arr_elem = tp; } + { tp2->arr_elem = tp; + ArraySizes(*ptp); + } ; RecordType(struct type **ptp;) { - struct scope scope; + struct scope *scope; + arith count; + int xalign = record_align; } : RECORD - { scope.sc_scope = uniq_scope(); - scope.next = CurrentScope; + { open_scope(OPENSCOPE); + scope = CurrentScope; + close_scope(0); + count = 0; } - FieldListSequence(&scope) + FieldListSequence(scope, &count, &xalign) { - *ptp = standard_type(T_RECORD, record_align, (arith) 0 /* ???? */); - (*ptp)->rec_scope = scope.sc_scope; + *ptp = standard_type(T_RECORD, xalign, count); + (*ptp)->rec_scope = scope; } END ; -FieldListSequence(struct scope *scope;): - FieldList(scope) +FieldListSequence(struct scope *scope; arith *cnt; int *palign;): + FieldList(scope, cnt, palign) [ - ';' FieldList(scope) + ';' FieldList(scope, cnt, palign) ]* ; -FieldList(struct scope *scope;) +FieldList(struct scope *scope; arith *cnt; int *palign;) { struct node *FldList; struct idf *id; - struct def *df, *df1; + struct def *df; struct type *tp; struct node *nd; + arith tcnt, max; } : [ IdentList(&FldList) ':' type(&tp) - { EnterIdList(FldList, D_FIELD, 0, tp, scope); + { *palign = lcm(*palign, tp->tp_align); + EnterIdList(FldList, D_FIELD, 0, tp, scope, cnt); FreeNode(FldList); } | @@ -309,8 +338,7 @@ FieldList(struct scope *scope;) [ /* This is good, in both kinds of Modula-2, if the first qualident is a single identifier. */ - { - if (nd->nd_class != Name) { + { if (nd->nd_class != Name) { error("illegal variant tag"); id = gen_anon_idf(); } @@ -322,8 +350,7 @@ FieldList(struct scope *scope;) /* Old fashioned! the first qualident now represents the type */ - { - warning("Old fashioned Modula-2 syntax!"); + { warning("Old fashioned Modula-2 syntax!"); id = gen_anon_idf(); findname(nd); assert(nd->nd_class == Def); @@ -338,42 +365,62 @@ FieldList(struct scope *scope;) ] | /* Aha, third edition? */ - ':' qualident(D_TYPE|D_HTYPE|D_HIDDEN, - &df, - "type", - (struct node **) 0) - { - id = gen_anon_idf(); - } + ':' qualident(D_TYPE|D_HTYPE|D_HIDDEN, &df, "type", (struct node **) 0) + { id = gen_anon_idf(); } ] - { - df1 = define(id, scope, D_FIELD); - df1->df_type = df->df_type; + { tp = df->df_type; + df = define(id, scope, D_FIELD); + df->df_type = tp; + df->fld_off = align(*cnt, tp->tp_align); + *cnt = tcnt = df->fld_off + tp->tp_size; } - OF variant(scope) + OF variant(scope, &tcnt, tp, palign) + { max = tcnt; tcnt = *cnt; } [ - '|' variant(scope) + '|' variant(scope, &tcnt, tp, palign) + { if (tcnt > max) max = tcnt; } ]* - [ ELSE FieldListSequence(scope) + [ ELSE FieldListSequence(scope, &tcnt, palign) + { if (tcnt > max) max = tcnt; } ]? END + { *cnt = max; } ]? ; -variant(struct scope *scope;): - [ CaseLabelList ':' FieldListSequence(scope) ]? +variant(struct scope *scope; arith *cnt; struct type *tp; int *palign;) +{ + struct type *tp1 = tp; +} : + [ + CaseLabelList(&tp1) ':' FieldListSequence(scope, cnt, palign) + ]? /* Changed rule in new modula-2 */ ; -CaseLabelList: - CaseLabels [ ',' CaseLabels ]* +CaseLabelList(struct type **ptp;): + CaseLabels(ptp) [ ',' CaseLabels(ptp) ]* ; -CaseLabels +CaseLabels(struct type **ptp;) { struct node *nd1, *nd2 = 0; }: - ConstExpression(&nd1) [ UPTO ConstExpression(&nd2) ]? + ConstExpression(&nd1) + [ + UPTO ConstExpression(&nd2) + { if (!TstCompat(nd1->nd_type, nd2->nd_type)) { +node_error(nd2,"type incompatibility in case label"); + } + nd1->nd_type = error_type; + } + ]? + { if (*ptp != 0 && + !TstCompat(*ptp, nd1->nd_type)) { +node_error(nd1,"type incompatibility in case label"); + } + *ptp = nd1->nd_type; + } ; SetType(struct type **ptp;) @@ -398,7 +445,7 @@ PointerType(struct type **ptp;) struct node *nd; } : POINTER TO - [ %if ( (df = lookup(dot.TOK_IDF, CurrentScope->sc_scope))) + [ %if ( (df = lookup(dot.TOK_IDF, CurrentScope))) /* Either a Module or a Type, but in both cases defined in this scope, so this is the correct identification */ @@ -489,14 +536,22 @@ VariableDeclaration { struct node *VarList; struct type *tp; - struct node *nd = 0; } : - IdentList(&VarList) - [ - ConstExpression(&nd) - ]? + IdentAddrList(&VarList) ':' type(&tp) - { EnterIdList(VarList, D_VARIABLE, 0, tp, CurrentScope); + { EnterVarList(VarList, tp, proclevel > 0); FreeNode(VarList); } ; + +IdentAddrList(struct node **pnd;) +{ +} : + IDENT { *pnd = MkNode(Name, NULLNODE, NULLNODE, &dot); } + ConstExpression(&(*pnd)->nd_left)? + [ { pnd = &((*pnd)->nd_right); } + ',' IDENT + { *pnd = MkNode(Name, NULLNODE, NULLNODE, &dot); } + ConstExpression(&(*pnd)->nd_left)? + ]* +; diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H index 35f75794..6a762937 100644 --- a/lang/m2/comp/def.H +++ b/lang/m2/comp/def.H @@ -4,14 +4,16 @@ struct module { int mo_priority; /* priority of a module */ - int mo_scope; /* scope of this module */ + struct scope *mo_scope; /* scope of this module */ #define mod_priority df_value.df_module.mo_priority #define mod_scope df_value.df_module.mo_scope }; struct variable { arith va_off; /* address or offset of variable */ + char va_addrgiven; /* an address was given in the program */ #define var_off df_value.df_variable.va_off +#define var_addrgiven df_value.df_variable.va_addrgiven }; struct constant { @@ -38,8 +40,12 @@ struct field { }; struct dfproc { - int pr_scope; /* scope number of procedure */ + struct scope *pr_scope; /* scope of procedure */ + int pr_level; /* depth level of this procedure */ + arith pr_nbpar; /* Number of bytes parameters */ #define prc_scope df_value.df_proc.pr_scope +#define prc_level df_value.df_proc.pr_level +#define prc_nbpar df_value.df_proc.pr_nbpar }; struct import { @@ -48,7 +54,7 @@ struct import { }; struct dforward { - int fo_scope; + struct scope *fo_scope; struct node *fo_node; #define for_node df_value.df_forward.fo_node #define for_scope df_value.df_forward.fo_scope @@ -59,7 +65,7 @@ struct def { /* list of definitions for a name */ struct def *df_nextinscope; /* link all definitions in a scope */ struct idf *df_idf; /* link back to the name */ - int df_scope; /* scope in which this definition resides */ + struct scope *df_scope; /* scope in which this definition resides */ short df_kind; /* the kind of this definition: */ #define D_MODULE 0x0001 /* a module */ #define D_PROCEDURE 0x0002 /* procedure of function */ diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index c47b3218..4ebdef06 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -18,7 +18,7 @@ static char *RcsId = "$Header$"; struct def *h_def; /* Pointer to free list of def structures */ static struct def illegal_def = - {0, 0, 0, -20 /* Illegal scope */, D_ERROR}; + {0, 0, 0, 0, D_ERROR}; struct def *ill_df = &illegal_def; @@ -32,17 +32,17 @@ define(id, scope, kind) */ register struct def *df; - DO_DEBUG(5, debug("Defining identifier \"%s\" in scope %d, kind = %d", - id->id_text, scope->sc_scope, kind)); - df = lookup(id, scope->sc_scope); + DO_DEBUG(5, debug("Defining identifier \"%s\", kind = %d", + id->id_text, kind)); + df = lookup(id, scope); if ( /* Already in this scope */ df || /* A closed scope, and id defined in the pervasive scope */ ( CurrentScope == scope && - scopeclosed(CurrentScope) + scopeclosed(scope) && - (df = lookup(id, 0))) + (df = lookup(id, PervasiveScope))) ) { switch(df->df_kind) { case D_PROCHEAD: @@ -62,7 +62,6 @@ define(id, scope, kind) break; case D_FORWMODULE: if (kind == D_FORWMODULE) { - df->df_kind = kind; return df; } if (kind == D_MODULE) { @@ -89,8 +88,9 @@ error("identifier \"%s\" already declared", id->id_text); df = new_def(); df->df_flags = 0; df->df_idf = id; - df->df_scope = scope->sc_scope; + df->df_scope = scope; df->df_kind = kind; + df->df_type = 0; df->next = id->id_def; id->id_def = df; @@ -103,6 +103,7 @@ error("identifier \"%s\" already declared", id->id_text); struct def * lookup(id, scope) register struct idf *id; + struct scope *scope; { /* Look up a definition of an identifier in scope "scope". Make the "def" list self-organizing. @@ -114,7 +115,6 @@ lookup(id, scope) df1 = 0; df = id->id_def; - DO_DEBUG(5, debug("Looking for identifier \"%s\" in scope %d", id->id_text, scope)); while (df) { if (df->df_scope == scope) { retval = df; @@ -148,7 +148,7 @@ Export(ids, qualified) struct node *nd = ids; while (ids) { - df = lookup(ids->nd_IDF, CurrentScope->sc_scope); + df = lookup(ids->nd_IDF, CurrentScope); if (df && (df->df_flags & (D_EXPORTED|D_QEXPORTED))) { node_error(ids, "Identifier \"%s\" occurs more than once in export list", df->df_idf->id_text); @@ -163,8 +163,7 @@ df->df_idf->id_text); } else { df->df_flags |= D_EXPORTED; - df1 = lookup(ids->nd_IDF, - enclosing(CurrentScope)->sc_scope); + df1 = lookup(ids->nd_IDF, enclosing(CurrentScope)); if (! df1 || !(df1->df_kind & (D_PROCHEAD|D_HIDDEN))) { df1 = define(ids->nd_IDF, enclosing(CurrentScope), @@ -185,6 +184,49 @@ df->df_idf->id_text); FreeNode(nd); } +static struct scope * +ForwModule(df, idn) + register struct def *df; + struct node *idn; +{ + /* An import is done from a not yet defined module "idn". + Create a declaration and a scope for this module. + */ + struct scope *scope; + + df->df_scope = enclosing(CurrentScope); + df->df_kind = D_FORWMODULE; + open_scope(CLOSEDSCOPE); + scope = CurrentScope; /* The new scope, but watch out, it's "next" + field is not set right. It must indicate the + enclosing scope, but this must be done AFTER + closing this one + */ + df->for_scope = scope; + df->for_node = MkNode(Name, NULLNODE, NULLNODE, &(idn->nd_token)); + close_scope(0); + scope->next = df->df_scope; + /* Here ! */ + return scope; +} + +static struct def * +ForwDef(ids, scope) + register struct node *ids; + struct scope *scope; +{ + /* Enter a forward definition of "ids" in scope "scope", + if it is not already defined. + */ + register struct def *df; + + if (!(df = lookup(ids->nd_IDF, scope))) { + df = define(ids->nd_IDF, scope, D_FORWARD); + df->for_node = MkNode(Name,NULLNODE,NULLNODE,&(ids->nd_token)); + } + return df; +} + Import(ids, idn, local) register struct node *ids; struct node *idn; @@ -203,63 +245,51 @@ Import(ids, idn, local) identifiers defined in this module. */ register struct def *df; - struct def *df1 = 0; - int scope; - int kind; - int imp_kind; + struct scope *scope = enclosing(CurrentScope); + int kind = D_IMPORT; + int forwflag = 0; #define FROM_MODULE 0 #define FROM_ENCLOSING 1 + int imp_kind = FROM_ENCLOSING; struct def *lookfor(), *GetDefinitionModule(); - kind = D_IMPORT; - scope = enclosing(CurrentScope)->sc_scope; - - if (! idn) imp_kind = FROM_ENCLOSING; - else { + if (idn) { imp_kind = FROM_MODULE; if (local) { - df = lookfor(idn, enclosing(CurrentScope), 0); - if (df->df_kind == D_ERROR) { + df = lookfor(idn, scope, 0); + switch(df->df_kind) { + case D_ERROR: /* The module from which the import was done is not yet declared. I'm not sure if I must accept this, but for the time being I will. ??? */ - df->df_scope = scope; - df->df_kind = D_FORWMODULE; - open_scope(CLOSEDSCOPE, 0); - df->for_scope = CurrentScope->sc_scope; - df->for_node = MkNode(Name, NULLNODE, - NULLNODE, &(idn->nd_token)); - close_scope(); - df1 = df; - } - } - else df = GetDefinitionModule(idn->nd_IDF); - - if (!(df->df_kind & (D_MODULE|D_FORWMODULE))) { - /* enter all "ids" with type D_ERROR */ - kind = D_ERROR; - if (df->df_kind != D_ERROR) { + scope = ForwModule(df, idn); + forwflag = 1; + break; + case D_FORWMODULE: + scope = df->for_scope; + break; + case D_MODULE: + scope = df->mod_scope; + break; + default: + kind = D_ERROR; node_error(idn, "identifier \"%s\" does not represent a module", idn->nd_IDF->id_text); + break; } } - else scope = df->mod_scope; + else scope = GetDefinitionModule(idn->nd_IDF)->mod_scope; + FreeNode(idn); } idn = ids; while (ids) { if (imp_kind == FROM_MODULE) { - if (df1 != 0) { - open_scope(CLOSEDSCOPE, df1->mod_scope); - df = define(ids->nd_IDF, - CurrentScope, - D_FORWARD); - df->for_node = MkNode(Name, NULLNODE, - NULLNODE, &(ids->nd_token)); - close_scope(0); + if (forwflag) { + df = ForwDef(ids, scope); } else if (!(df = lookup(ids->nd_IDF, scope))) { node_error(ids, "identifier \"%s\" not declared in qualifying module", @@ -272,29 +302,22 @@ ids->nd_IDF->id_text); } } else { - if (local) { - df = lookfor(ids, enclosing(CurrentScope), 0); - } else df = GetDefinitionModule(ids->nd_IDF); - if (df->df_kind == D_ERROR) { - /* It was not yet defined in the enclosing - scope. - */ - df->df_kind = D_FORWARD; - df->for_node = MkNode(Name, NULLNODE, NULLNODE, - &(ids->nd_token)); - } + if (local) df = ForwDef(ids, scope); + else df = GetDefinitionModule(ids->nd_IDF); } + DO_DEBUG(2, debug("importing \"%s\", kind %d", ids->nd_IDF->id_text, df->df_kind)); define(ids->nd_IDF, CurrentScope, kind)->imp_def = df; if (df->df_kind == D_TYPE && df->df_type->tp_fund == T_ENUMERATION) { - /* Also import all enumeration literals */ - exprt_literals(df->df_type->enm_enums, - CurrentScope); + /* Also import all enumeration literals + */ + exprt_literals(df->df_type->enm_enums, CurrentScope); } ids = ids->next; } + FreeNode(idn); } @@ -305,9 +328,9 @@ exprt_literals(df, toscope) /* A list of enumeration literals is exported. This is implemented as an import from the scope "toscope". */ - DO_DEBUG(2, debug("enumeration import:")); + DO_DEBUG(3, debug("enumeration import:")); while (df) { - DO_DEBUG(2, debug(df->df_idf->id_text)); + DO_DEBUG(3, debug(df->df_idf->id_text)); define(df->df_idf, toscope, D_IMPORT)->imp_def = df; df = df->enm_next; } @@ -353,3 +376,11 @@ RemFromId(df) df1->next = df->next; } } + +#ifdef DEBUG +PrDef(df) + register struct def *df; +{ + debug("name: %s, kind: %d", df->df_idf->id_text, df->df_kind); +} +#endif DEBUG diff --git a/lang/m2/comp/defmodule.c b/lang/m2/comp/defmodule.c index 8dd739a0..7a261113 100644 --- a/lang/m2/comp/defmodule.c +++ b/lang/m2/comp/defmodule.c @@ -49,7 +49,7 @@ GetDefinitionModule(id) */ struct def *df; - df = lookup(id, GlobalScope->sc_scope); + df = lookup(id, GlobalScope); if (!df) { /* Read definition module. Make an exception for SYSTEM. */ @@ -60,7 +60,7 @@ GetDefinitionModule(id) GetFile(id->id_text); DefModule(); } - df = lookup(id, GlobalScope->sc_scope); + df = lookup(id, GlobalScope); } assert(df != 0 && df->df_kind == D_MODULE); return df; diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index 52380bc3..4c9e14b7 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -35,10 +35,11 @@ Enter(name, kind, type, pnam) return df; } -EnterIdList(idlist, kind, flags, type, scope) +EnterIdList(idlist, kind, flags, type, scope, addr) register struct node *idlist; struct type *type; struct scope *scope; + arith *addr; { /* Put a list of identifiers in the symbol table. They all have kind "kind", and type "type", and are put @@ -50,11 +51,29 @@ EnterIdList(idlist, kind, flags, type, scope) register struct def *df; struct def *first = 0, *last = 0; int assval = 0; + arith off; while (idlist) { df = define(idlist->nd_IDF, scope, kind); df->df_type = type; df->df_flags |= flags; + if (addr) { + if (*addr >= 0) { + off = align(*addr, type->tp_align); + *addr = off + type->tp_size; + } + else { + off = -align(-*addr, type->tp_align); + *addr = off - type->tp_size; + } + if (kind == D_VARIABLE) { + df->var_off = off; + } + else { + assert(kind == D_FIELD); + df->fld_off = off; + } + } if (kind == D_ENUM) { if (!first) first = df; df->enm_val = assval++; @@ -72,6 +91,45 @@ EnterIdList(idlist, kind, flags, type, scope) } } +EnterVarList(IdList, type, local) + register struct node *IdList; + struct type *type; +{ + register struct def *df; + struct scope *scope; + + if (local) { + /* Find the closest enclosing open scope. This + is the procedure that we are dealing with + */ + scope = CurrentScope; + while (scope->sc_scopeclosed) scope = scope->next; + } + + while (IdList) { + df = define(IdList->nd_IDF, CurrentScope, D_VARIABLE); + df->df_type = type; + if (IdList->nd_left) { + df->var_addrgiven = 1; + if (IdList->nd_left->nd_type != card_type) { +node_error(IdList->nd_left,"Illegal type for address"); + } + df->var_off = IdList->nd_left->nd_INT; + } + else if (local) { + arith off; + + /* add aligned size of variable to the offset + */ + off = scope->sc_off - type->tp_size; + off = -align(-off, type->tp_align); + df->var_off = off; + scope->sc_off = off; + } + IdList = IdList->nd_right; + } +} + struct def * lookfor(id, scope, give_error) struct node *id; @@ -86,7 +144,7 @@ lookfor(id, scope, give_error) register struct scope *sc = scope; while (sc) { - df = lookup(id->nd_IDF, sc->sc_scope); + df = lookup(id->nd_IDF, sc); if (df) return df; sc = nextvisible(sc); } diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index dfe210ba..75655c90 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -22,9 +22,7 @@ number(struct node **p;) struct type *tp; } : [ - INTEGER { tp = dot.TOK_INT <= max_int ? - intorcard_type : card_type; - } + INTEGER { tp = numtype; } | REAL { tp = real_type; } ] { *p = MkNode(Value, NULLNODE, NULLNODE, &dot); diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index 08632c06..a66d0aa8 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -74,7 +74,7 @@ Compile(src) if (options['L']) LexScan(); else { #endif DEBUG - (void) open_scope(CLOSEDSCOPE, 0); + (void) open_scope(CLOSEDSCOPE); GlobalScope = CurrentScope; CompUnit(); #ifdef DEBUG @@ -192,7 +192,7 @@ PROCEDURE NEWPROCESS(P:PROC; A:ADDRESS; n:CARDINAL; VAR p1:ADDRESS);\n\ PROCEDURE TRANSFER(VAR p1,p2:ADDRESS);\n\ END SYSTEM.\n"; - open_scope(CLOSEDSCOPE, 0); + open_scope(CLOSEDSCOPE); (void) Enter("WORD", D_TYPE, word_type, 0); (void) Enter("ADDRESS", D_TYPE, address_type, 0); (void) Enter("ADR", D_PROCEDURE, std_type, S_ADR); @@ -202,7 +202,7 @@ END SYSTEM.\n"; } SYSTEMModule = 1; DefModule(); - close_scope(); + close_scope(0); SYSTEMModule = 0; } diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 3ff352b2..e3c6bb78 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -20,7 +20,6 @@ static int DEFofIMPL = 0; /* Flag indicating that we are currently implementation module currently being compiled */ -static struct def *impl_df; } /* The grammar as given by Wirth is already almost LL(1); the @@ -50,10 +49,10 @@ ModuleDeclaration id = dot.TOK_IDF; df = define(id, CurrentScope, D_MODULE); if (!df->mod_scope) { - open_scope(CLOSEDSCOPE, 0); - df->mod_scope = CurrentScope->sc_scope; + open_scope(CLOSEDSCOPE); + df->mod_scope = CurrentScope; } - else open_scope(CLOSEDSCOPE, df->mod_scope); + else CurrentScope = df->mod_scope; df->df_type = standard_type(T_RECORD, 0, (arith) 0); df->df_type->rec_scope = df->mod_scope; @@ -123,8 +122,8 @@ DefinitionModule DEFINITION MODULE IDENT { id = dot.TOK_IDF; df = define(id, GlobalScope, D_MODULE); - if (!SYSTEMModule) open_scope(CLOSEDSCOPE, 0); - df->mod_scope = CurrentScope->sc_scope; + if (!SYSTEMModule) open_scope(CLOSEDSCOPE); + df->mod_scope = CurrentScope; df->df_type = standard_type(T_RECORD, 0, (arith) 0); df->df_type->rec_scope = df->mod_scope; DefinitionModule = 1; @@ -144,7 +143,6 @@ DefinitionModule implementation module being compiled */ RemImports(&(CurrentScope->sc_def)); - impl_df = CurrentScope->sc_def; } df = CurrentScope->sc_def; while (df) { @@ -174,7 +172,8 @@ definition The export is said to be opaque. It is restricted to pointer types. */ - { df->df_kind = D_HIDDEN; } + { df->df_kind = D_HIDDEN; + } ] ';' ]* @@ -188,20 +187,19 @@ ProgramModule(int state;) { struct idf *id; struct def *df, *GetDefinitionModule(); - int scope = 0; + struct scope *scope = 0; } : MODULE IDENT { id = dot.TOK_IDF; if (state == IMPLEMENTATION) { - DEFofIMPL = 1; - df = GetDefinitionModule(id); - scope = df->mod_scope; - DEFofIMPL = 0; + DEFofIMPL = 1; + df = GetDefinitionModule(id); + CurrentScope = df->mod_scope; + DEFofIMPL = 0; + DefinitionModule = 0; } - DefinitionModule = 0; - open_scope(CLOSEDSCOPE, scope); - CurrentScope->sc_def = impl_df; + else open_scope(CLOSEDSCOPE); } priority? ';' import(0)* diff --git a/lang/m2/comp/scope.C b/lang/m2/comp/scope.C index e7a0fcf7..ca608682 100644 --- a/lang/m2/comp/scope.C +++ b/lang/m2/comp/scope.C @@ -14,40 +14,28 @@ static char *RcsId = "$Header$"; #include "node.h" #include "debug.h" -static int maxscope; /* maximum assigned scope number */ - -struct scope *CurrentScope, *GlobalScope; +struct scope *CurrentScope, *PervasiveScope, *GlobalScope; /* STATICALLOCDEF "scope" */ -open_scope(scopetype, scope) +open_scope(scopetype) { /* Open a scope that is either open (automatic imports) or closed. - A closed scope is handled by adding an extra entry to the list - with scope number 0. This has two purposes: it makes scope 0 - visible, and it marks the end of a visibility list. - Scope 0 is the pervasive scope, the one that is always visible. - A disadvantage of this method is that we cannot open scope 0 - explicitly. */ register struct scope *sc = new_scope(); register struct scope *sc1; - sc->sc_scope = scope == 0 ? ++maxscope : scope; + assert(scopetype == OPENSCOPE || scopetype == CLOSEDSCOPE); + sc->sc_scopeclosed = scopetype == CLOSEDSCOPE; sc->sc_forw = 0; sc->sc_def = 0; - assert(scopetype == OPENSCOPE || scopetype == CLOSEDSCOPE); + sc->sc_off = 0; + sc->next = 0; DO_DEBUG(1, debug("Opening a %s scope", scopetype == OPENSCOPE ? "open" : "closed")); - sc1 = CurrentScope; - if (scopetype == CLOSEDSCOPE) { - sc1 = new_scope(); - sc1->sc_scope = 0; /* Pervasive scope nr */ - sc1->sc_forw = 0; - sc1->sc_def = 0; - sc1->next = CurrentScope; + if (CurrentScope != PervasiveScope) { + sc->next = CurrentScope; } - sc->next = sc1; CurrentScope = sc; } @@ -55,18 +43,14 @@ init_scope() { register struct scope *sc = new_scope(); - sc->sc_scope = 0; + sc->sc_scopeclosed = 0; sc->sc_forw = 0; sc->sc_def = 0; + sc->next = 0; + PervasiveScope = sc; CurrentScope = sc; } -int -uniq_scope() -{ - return ++maxscope; -} - struct forwards { struct forwards *next; struct node fo_tok; @@ -92,73 +76,67 @@ Forward(tk, ptp) CurrentScope->sc_forw = f; } -close_scope(flag) +static +chk_proc(df) + register struct def *df; { - /* Close a scope. If "flag" is set, check for forward declarations, - either POINTER declarations, or EXPORTs, or forward references - to MODULES + /* Called at scope closing. Check all definitions, and if one + is a D_PROCHEAD, the procedure was not defined */ - register struct scope *sc = CurrentScope; - register struct def *df, *dfback = 0; - - assert(sc != 0); - DO_DEBUG(1, debug("Closing a scope")); - - if (flag) { - if (sc->sc_forw) rem_forwards(sc->sc_forw); - df = sc->sc_def; - while(df) { - if (flag & SC_CHKPROC) { - if (df->df_kind == D_PROCHEAD) { - /* A not defined procedure - */ + while (df) { + if (df->df_kind == D_PROCHEAD) { + /* A not defined procedure + */ node_error(df->for_node, "procedure \"%s\" not defined", df->df_idf->id_text); - FreeNode(df->for_node); - } - } - if ((flag & SC_CHKFORW) && - df->df_kind & (D_FORWARD|D_FORWMODULE)) { - /* These definitions must be found in - the enclosing closed scope, which of course - may be the scope that is now closed! + FreeNode(df->for_node); + } + df = df->df_nextinscope; + } +} + +static +chk_forw(pdf) + register struct def **pdf; +{ + /* Called at scope close. Look for all forward definitions and + if the scope was a closed scope, give an error message for + them, and otherwise move them to the enclosing scope. + */ + while (*pdf) { + if ((*pdf)->df_kind & (D_FORWARD|D_FORWMODULE)) { + /* These definitions must be found in + the enclosing closed scope, which of course + may be the scope that is now closed! + */ + struct def *df1 = (*pdf)->df_nextinscope; + + if (scopeclosed(CurrentScope)) { + /* Indeed, the scope was a closed + scope, so give error message */ - struct def *df1 = df->df_nextinscope; - - if (scopeclosed(CurrentScope)) { - /* Indeed, the scope was a closed - scope, so give error message - */ -node_error(df->for_node, "identifier \"%s\" not declared", df->df_idf->id_text); - FreeNode(df->for_node); - dfback = df; - } - else { - /* This scope was an open scope. - Maybe the definitions are in the - enclosing scope? - */ - struct scope *sc; - - sc = enclosing(CurrentScope); - df->df_nextinscope = sc->sc_def; - sc->sc_def = df; - df->df_scope = sc->sc_scope; - if (dfback) dfback->df_nextinscope = df1; - else sc->sc_def = df1; - } - df = df1; +node_error((*pdf)->for_node, "identifier \"%s\" has not been declared", +(*pdf)->df_idf->id_text); + FreeNode((*pdf)->for_node); + pdf = &(*pdf)->df_nextinscope; } - else { - dfback = df; - df = df->df_nextinscope; + else { /* This scope was an open scope. + Maybe the definitions are in the + enclosing scope? + */ + struct scope *sc; + + sc = enclosing(CurrentScope); + if ((*pdf)->df_kind == D_FORWMODULE) { + (*pdf)->for_scope->next = sc; + } + (*pdf)->df_nextinscope = sc->sc_def; + sc->sc_def = *pdf; + (*pdf)->df_scope = sc; + *pdf = df1; } } + else pdf = &(*pdf)->df_nextinscope; } - - if (sc->next && (sc->next->sc_scope == 0)) { - sc = sc->next; - } - CurrentScope = sc->next; } static @@ -182,3 +160,35 @@ rem_forwards(fo) free_forwards(f); } } + +close_scope(flag) +{ + /* Close a scope. If "flag" is set, check for forward declarations, + either POINTER declarations, or EXPORTs, or forward references + to MODULES + */ + register struct scope *sc = CurrentScope; + + assert(sc != 0); + DO_DEBUG(1, debug("Closing a scope")); + + if (flag) { + if (sc->sc_forw) rem_forwards(sc->sc_forw); + DO_DEBUG(2, PrScopeDef(sc->sc_def)); + if (flag & SC_CHKPROC) chk_proc(sc->sc_def); + if (flag & SC_CHKFORW) chk_forw(&(sc->sc_def)); + } + CurrentScope = sc->next; +} + +#ifdef DEBUG +PrScopeDef(df) + register struct def *df; +{ + debug("List of definitions in currently ended scope:"); + while (df) { + PrDef(df); + df = df->df_nextinscope; + } +} +#endif diff --git a/lang/m2/comp/scope.h b/lang/m2/comp/scope.h index e009ccf7..3dc7b441 100644 --- a/lang/m2/comp/scope.h +++ b/lang/m2/comp/scope.h @@ -16,16 +16,15 @@ struct scope { struct scope *next; struct forwards *sc_forw; struct def *sc_def; /* list of definitions in this scope */ - int sc_scope; /* The scope number. Scope number 0 indicates - both the pervasive scope and the end of a - visibility range - */ + arith sc_off; /* offsets of variables in this scope */ + char sc_scopeclosed; /* flag indicating closed or open scope */ }; extern struct scope *CurrentScope, + *PervasiveScope, *GlobalScope; -#define nextvisible(x) ((x)->sc_scope ? (x)->next : (struct scope *) 0) -#define scopeclosed(x) ((x)->next->sc_scope == 0) -#define enclosing(x) (scopeclosed(x) ? (x)->next->next : (x)->next) +#define enclosing(x) ((x)->next) +#define scopeclosed(x) ((x)->sc_scopeclosed) +#define nextvisible(x) (scopeclosed(x) ? PervasiveScope : enclosing(x)) diff --git a/lang/m2/comp/statement.g b/lang/m2/comp/statement.g index d9eb42cd..36596be0 100644 --- a/lang/m2/comp/statement.g +++ b/lang/m2/comp/statement.g @@ -6,12 +6,15 @@ static char *RcsId = "$Header$"; #include #include "LLlex.h" #include "node.h" + +static int loopcount = 0; /* Count nested loops */ } -statement +statement(struct node **pnd;) { - struct node *nd1, *nd2 = 0; + struct node *nd1; } : + { *pnd = 0; } [ /* * This part is not in the reference grammar. The reference grammar @@ -19,38 +22,45 @@ statement * but this gives LL(1) conflicts */ designator(&nd1) - [ - ActualParameters(&nd2)? - { nd1 = MkNode(Call, nd1, nd2, &dot); + [ { nd1 = MkNode(Call, nd1, NULLNODE, &dot); nd1->nd_symb = '('; } + ActualParameters(&(nd1->nd_right))? | BECOMES { nd1 = MkNode(Stat, nd1, NULLNODE, &dot); } expression(&(nd1->nd_right)) ] + { *pnd = nd1; } /* * end of changed part */ | - IfStatement + IfStatement(pnd) | - CaseStatement + CaseStatement(pnd) | - WhileStatement + WhileStatement(pnd) | - RepeatStatement + RepeatStatement(pnd) | - LoopStatement + { loopcount++; } + LoopStatement(pnd) + { loopcount--; } | - ForStatement + ForStatement(pnd) | - WithStatement + WithStatement(pnd) | EXIT + { if (!loopcount) { + error("EXIT not in a LOOP"); + } + *pnd = MkNode(Stat, NULLNODE, NULLNODE, &dot); + } | - RETURN + RETURN { *pnd = MkNode(Stat, NULLNODE, NULLNODE, &dot); } [ - expression(&nd1) + expression(&((*pnd)->nd_right)) ]? ]? ; @@ -67,66 +77,132 @@ ProcedureCall: ; */ -StatementSequence: - statement [ ';' statement ]* +StatementSequence(struct node **pnd;): + statement(pnd) + [ + ';' { *pnd = MkNode(Link, *pnd, NULLNODE, &dot); + pnd = &((*pnd)->nd_right); + } + statement(pnd) + ]* ; -IfStatement +IfStatement(struct node **pnd;) { - struct node *nd1; + register struct node *nd; } : - IF expression(&nd1) THEN StatementSequence - [ ELSIF expression(&nd1) THEN StatementSequence ]* - [ ELSE StatementSequence ]? + IF { nd = MkNode(Stat, NULLNODE, NULLNODE, &dot); + *pnd = nd; + } + expression(&(nd->nd_left)) + THEN { nd = MkNode(Link, NULLNODE, NULLNODE, &dot); + (*pnd)->nd_right = nd; + } + StatementSequence(&(nd->nd_left)) + [ + ELSIF { nd->nd_right = MkNode(Stat,NULLNODE,NULLNODE,&dot); + nd = nd->nd_right; + nd->nd_symb = IF; + } + expression(&(nd->nd_left)) + THEN { nd->nd_right = MkNode(Link,NULLNODE,NULLNODE,&dot); + nd = nd->nd_right; + } + StatementSequence(&(nd->nd_left)) + ]* + [ + ELSE + StatementSequence(&(nd->nd_right)) + ]? END ; -CaseStatement +CaseStatement(struct node **pnd;) { - struct node *nd; + register struct node *nd; + struct type *tp = 0; } : - CASE expression(&nd) OF case [ '|' case ]* - [ ELSE StatementSequence ]? + CASE { *pnd = nd = MkNode(Stat, NULLNODE, NULLNODE, &dot); } + expression(&(nd->nd_left)) + OF + case(&(nd->nd_right), &tp) + { nd = nd->nd_right; } + [ + '|' + case(&(nd->nd_right), &tp) + { nd = nd->nd_right; } + ]* + [ ELSE StatementSequence(&(nd->nd_right)) ]? END ; -case: - [ CaseLabelList ':' StatementSequence ]? +case(struct node **pnd; struct type **ptp;) : + { *pnd = 0; } + [ CaseLabelList(ptp/*,pnd*/) + ':' { *pnd = MkNode(Link, *pnd, NULLNODE, &dot); } + StatementSequence(&((*pnd)->nd_right)) + ]? /* This rule is changed in new modula-2 */ + { *pnd = MkNode(Link, *pnd, NULLNODE, &dot); + (*pnd)->nd_symb = '|'; + } ; -WhileStatement +WhileStatement(struct node **pnd;) { - struct node *nd; + register struct node *nd; }: - WHILE expression(&nd) DO StatementSequence END + WHILE { *pnd = nd = MkNode(Stat, NULLNODE, NULLNODE, &dot); } + expression(&(nd->nd_left)) + DO + StatementSequence(&(nd->nd_right)) + END ; -RepeatStatement +RepeatStatement(struct node **pnd;) { - struct node *nd; + register struct node *nd; }: - REPEAT StatementSequence UNTIL expression(&nd) + REPEAT { *pnd = nd = MkNode(Stat, NULLNODE, NULLNODE, &dot); } + StatementSequence(&(nd->nd_left)) + UNTIL + expression(&(nd->nd_right)) ; -ForStatement +ForStatement(struct node **pnd;) { - struct node *nd1, *nd2, *nd3; + register struct node *nd; }: - FOR IDENT - BECOMES expression(&nd1) - TO expression(&nd2) - [ BY ConstExpression(&nd3) ]? - DO StatementSequence END + FOR { *pnd = MkNode(Stat, NULLNODE, NULLNODE, &dot); } + IDENT { nd = MkNode(Name, NULLNODE, NULLNODE, &dot); } + BECOMES { nd = MkNode(BECOMES, nd, NULLNODE, &dot); } + expression(&(nd->nd_right)) + TO { (*pnd)->nd_left=nd=MkNode(Link,nd,NULLNODE,&dot); } + expression(&(nd->nd_right)) + [ + BY { nd->nd_right=MkNode(Link,NULLNODE,nd->nd_right,&dot); + } + ConstExpression(&(nd->nd_right->nd_left)) + | + ] + DO + StatementSequence(&((*pnd)->nd_right)) + END ; -LoopStatement: - LOOP StatementSequence END +LoopStatement(struct node **pnd;): + LOOP { *pnd = MkNode(Stat, NULLNODE, NULLNODE, &dot); } + StatementSequence(&((*pnd)->nd_right)) + END ; -WithStatement +WithStatement(struct node **pnd;) { - struct node *nd; + register struct node *nd; }: - WITH designator(&nd) DO StatementSequence END + WITH { *pnd = nd = MkNode(Stat, NULLNODE, NULLNODE, &dot); } + designator(&(nd->nd_left)) + DO + StatementSequence(&(nd->nd_right)) + END ; diff --git a/lang/m2/comp/type.H b/lang/m2/comp/type.H index 8abf6981..38c8a96c 100644 --- a/lang/m2/comp/type.H +++ b/lang/m2/comp/type.H @@ -38,8 +38,8 @@ struct array { }; struct record { - int rc_scope; /* Scope number of this record */ - /* Members are in the symbol table */ + struct scope *rc_scope; /* scope of this record */ + /* members are in the symbol table */ #define rec_scope tp_value.tp_record.rc_scope }; @@ -71,6 +71,7 @@ struct type { #define T_INTORCARD (T_INTEGER|T_CARDINAL) #define T_DISCRETE (T_ENUMERATION|T_INTORCARD|T_CHAR) #define T_NUMERIC (T_INTORCARD|T_REAL) +#define T_INDEX (T_ENUMERATION|T_CHAR|T_SUBRANGE) int tp_align; /* alignment requirement of this type */ arith tp_size; /* size of this type */ union { diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index 7efa40a4..5792379e 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -151,24 +151,6 @@ init_types() error_type = standard_type(T_CHAR, 1, (arith) 1); } -int -has_selectors(df) - register struct def *df; -{ - - switch(df->df_kind) { - case D_MODULE: - return df->df_value.df_module.mo_scope; - case D_VARIABLE: - if (df->df_type->tp_fund == T_RECORD) { - return df->df_type->rec_scope; - } - break; - } - error("no selectors for \"%s\"", df->df_idf->id_text); - return 0; -} - /* Create a parameterlist of a procedure and return a pointer to it. "ids" indicates the list of identifiers, "tp" their type, and "VARp" is set when the parameters are VAR-parameters. @@ -226,6 +208,8 @@ chk_basesubrange(tp, base) error("Specified base does not conform"); } tp->next = base; + tp->tp_size = base->tp_size; + tp->tp_align = base->tp_align; } struct type * @@ -236,7 +220,7 @@ subr_type(lb, ub) indicated by "lb" and "ub", but first perform some checks */ - register struct type *tp = lb->nd_type; + register struct type *tp = lb->nd_type, *res; if (!TstCompat(lb->nd_type, ub->nd_type)) { node_error(ub, "Types of subrange bounds not compatible"); @@ -264,11 +248,13 @@ subr_type(lb, ub) /* Now construct resulting type */ - tp = construct_type(T_SUBRANGE, tp); - tp->sub_lb = lb->nd_INT; - tp->sub_ub = ub->nd_INT; + res = construct_type(T_SUBRANGE, tp); + res->sub_lb = lb->nd_INT; + res->sub_ub = ub->nd_INT; + res->tp_size = tp->tp_size; + res->tp_align = tp->tp_align; DO_DEBUG(2,debug("Creating subrange type %ld-%ld", (long)lb->nd_INT,(long)ub->nd_INT)); - return tp; + return res; } #define MAX_SET 1024 /* ??? Maximum number of elements in a set */ @@ -302,3 +288,71 @@ set_type(tp) tp->tp_size = align(((ub - lb) + 7)/8, wrd_align); return tp; } + +ArraySizes(tp) + register struct type *tp; +{ + /* Assign sizes to an array type + */ + arith elem_size; + register struct type *itype = tp->next; /* the index type */ + + if (tp->arr_elem->tp_fund == T_ARRAY) { + ArraySizes(tp->arr_elem); + } + + elem_size = align(tp->arr_elem->tp_size, tp->arr_elem->tp_align); + tp->tp_align = tp->arr_elem->tp_align; + + if (! (itype->tp_fund & T_INDEX)) { + error("Illegal index type"); + tp->tp_size = 0; + return; + } + + switch(itype->tp_fund) { + case T_SUBRANGE: + tp->arr_lb = itype->sub_lb; + tp->arr_ub = itype->sub_ub; + tp->tp_size = elem_size * (itype->sub_ub - itype->sub_lb + 1); + break; + case T_CHAR: + case T_ENUMERATION: + tp->arr_lb = 0; + tp->arr_ub = itype->enm_ncst - 1; + tp->tp_size = elem_size * itype->enm_ncst; + break; + default: + assert(0); + } + /* ??? overflow checking ??? */ +} + +int +gcd(m, n) + register int m, n; +{ + /* Greatest Common Divisor + */ + register int r; + + while (n) { + r = m % n; + m = n; + n = r; + } + return m; +} + +int +lcm(m, n) + register int m, n; +{ + /* Least Common Multiple + */ + while (m != n) { + if (m < n) m = m + m; + else n = n + n; + } + return n; /* or m */ +} diff --git a/lang/m2/comp/typequiv.c b/lang/m2/comp/typequiv.c index 9c97fdd2..7fef0927 100644 --- a/lang/m2/comp/typequiv.c +++ b/lang/m2/comp/typequiv.c @@ -2,6 +2,9 @@ static char *RcsId = "$Header$"; +/* Routines for testing type equivalence, type compatibility, and + assignment compatibility +*/ #include #include #include "type.h" @@ -15,8 +18,8 @@ TstTypeEquiv(tp1, tp2) from the fact that for some procedures two declarations may be given: one in the specification module and one in the definition module. - A related problem is that two dynamic arrays with the - same base type are also equivalent. + A related problem is that two dynamic arrays with + equivalent base types are also equivalent. */ return tp1 == tp2 @@ -66,8 +69,7 @@ TstProcEquiv(tp1, tp2) p1 = p1->next; p2 = p2->next; } - if (p1 != p2) return 0; - return 1; + return p1 == p2; } int From f5334707b5a0ae88ac7e7618bb5056a53e3eddc6 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 17 Apr 1986 09:28:09 +0000 Subject: [PATCH 0179/1625] newer version --- lang/m2/comp/LLlex.c | 21 +++++--- lang/m2/comp/LLlex.h | 2 +- lang/m2/comp/Makefile | 25 +++++---- lang/m2/comp/Parameters | 60 +++++++++++++++++++++ lang/m2/comp/chk_expr.c | 24 ++++----- lang/m2/comp/cstoper.c | 15 +++--- lang/m2/comp/declar.g | 57 +++++++++++++------- lang/m2/comp/def.H | 6 ++- lang/m2/comp/error.c | 6 +-- lang/m2/comp/input.h | 2 + lang/m2/comp/main.c | 18 ++----- lang/m2/comp/make.hfiles | 35 ++++++++++++ lang/m2/comp/options.c | 114 +++++++++++++++++++++++++++++++++++++++ lang/m2/comp/program.g | 71 ++++++++++++++---------- lang/m2/comp/scope.C | 20 ++++++- lang/m2/comp/statement.g | 24 +++++---- lang/m2/comp/type.H | 22 ++++---- lang/m2/comp/type.c | 56 ++++++++++--------- 18 files changed, 427 insertions(+), 151 deletions(-) create mode 100644 lang/m2/comp/Parameters create mode 100755 lang/m2/comp/make.hfiles create mode 100644 lang/m2/comp/options.c diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index db080a5f..c53e3159 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -6,6 +6,11 @@ static char *RcsId = "$Header$"; #include #include #include + +#include "idfsize.h" +#include "numsize.h" +#include "strsize.h" + #include "input.h" #include "f_info.h" #include "Lpars.h" @@ -15,14 +20,12 @@ static char *RcsId = "$Header$"; #include "LLlex.h" #include "const.h" -#define IDFSIZE 256 /* Number of significant characters in an identifier */ -#define NUMSIZE 256 /* maximum number of characters in a number */ - long str2long(); struct token dot, aside; struct type *numtype; struct string string; +int idfsize = IDFSIZE; static SkipComment() @@ -73,7 +76,7 @@ GetString(upto) register struct string *str = &string; register char *p; - str->s_str = p = Malloc(str->s_length = 32); + str->s_str = p = Malloc((unsigned) (str->s_length = ISTRSIZE)); LoadChar(ch); while (ch != upto) { if (class(ch) == STNL) { @@ -87,8 +90,10 @@ GetString(upto) } *p++ = ch; if (p - str->s_str == str->s_length) { - str->s_str = Srealloc(str->s_str, str->s_length += 8); - p = str->s_str + (str->s_length - 8); + str->s_str = Srealloc(str->s_str, + str->s_length + RSTRSIZE); + p = str->s_str + str->s_length; + str->s_length += RSTRSIZE; } LoadChar(ch); } @@ -99,7 +104,7 @@ GetString(upto) int LLlex() { - /* LLlex() plays the role of Lexical Analyzer for the parser. + /* LLlex() is the Lexical Analyzer. The putting aside of tokens is taken into account. */ register struct token *tk = ˙ @@ -199,7 +204,7 @@ again: register struct idf *id; do { - if (tg - buf < IDFSIZE) *tg++ = ch; + if (tg - buf < idfsize) *tg++ = ch; LoadChar(ch); } while(in_idf(ch)); diff --git a/lang/m2/comp/LLlex.h b/lang/m2/comp/LLlex.h index 31ddcd46..16ea9e01 100644 --- a/lang/m2/comp/LLlex.h +++ b/lang/m2/comp/LLlex.h @@ -3,7 +3,7 @@ /* $Header$ */ struct string { - int s_length; /* length of a string */ + unsigned int s_length; /* length of a string */ char *s_str; /* the string itself */ }; diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index 7cb39541..8ce1097f 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -12,19 +12,20 @@ CC = cc GEN = LLgen GENOPTIONS = PROFILE = -CFLAGS = -DDEBUG $(PROFILE) $(INCLUDES) +CFLAGS = $(PROFILE) $(INCLUDES) LFLAGS = $(PROFILE) LOBJ = tokenfile.o program.o declar.o expression.o statement.o COBJ = LLlex.o LLmessage.o char.o error.o main.o \ symbol2str.o tokenname.o idf.o input.o type.o def.o \ scope.o misc.o enter.o defmodule.o typequiv.o node.o \ - cstoper.o chk_expr.o + cstoper.o chk_expr.o options.o OBJ = $(COBJ) $(LOBJ) Lpars.o GENFILES= tokenfile.c \ program.c declar.c expression.c statement.c \ tokenfile.g symbol2str.c char.c Lpars.c Lpars.h all: + make hfiles make LLfiles make main @@ -32,6 +33,10 @@ LLfiles: $(LSRC) $(GEN) $(GENOPTIONS) $(LSRC) @touch LLfiles +hfiles: Parameters make.hfiles + make.hfiles Parameters + touch hfiles + main: $(OBJ) Makefile $(CC) $(LFLAGS) $(OBJ) $(LIBDIR)/libcomp.a $(LIBDIR)/malloc.o /user1/erikb/em/lib/libprint.a /user1/erikb/em/lib/libstr.a /user1/erikb/em/lib/libsystem.a -o main size main @@ -73,28 +78,28 @@ depend: make.allocd < $< > $@ #AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO -LLlex.o: LLlex.h Lpars.h class.h f_info.h idf.h input.h +LLlex.o: LLlex.h Lpars.h class.h const.h f_info.h idf.h idfsize.h input.h inputtype.h numsize.h strsize.h type.h LLmessage.o: LLlex.h Lpars.h idf.h char.o: class.h -error.o: LLlex.h f_info.h input.h main.h node.h -main.o: LLlex.h Lpars.h debug.h def.h f_info.h idf.h input.h scope.h standards.h tokenname.h type.h +error.o: LLlex.h errout.h f_info.h input.h inputtype.h main.h node.h +main.o: LLlex.h Lpars.h debug.h def.h f_info.h idf.h input.h inputtype.h scope.h standards.h tokenname.h type.h symbol2str.o: Lpars.h tokenname.o: Lpars.h idf.h tokenname.h idf.o: idf.h -input.o: f_info.h input.h -type.o: LLlex.h const.h debug.h def.h def_sizes.h idf.h node.h type.h +input.o: f_info.h input.h inputtype.h +type.o: LLlex.h const.h debug.h def.h idf.h node.h target_sizes.h type.h def.o: LLlex.h debug.h def.h idf.h main.h node.h scope.h type.h scope.o: LLlex.h debug.h def.h idf.h node.h scope.h type.h misc.o: LLlex.h f_info.h idf.h misc.h node.h enter.o: LLlex.h def.h idf.h node.h scope.h type.h -defmodule.o: LLlex.h debug.h def.h f_info.h idf.h input.h scope.h +defmodule.o: LLlex.h debug.h def.h f_info.h idf.h input.h inputtype.h scope.h typequiv.o: def.h type.h node.o: LLlex.h debug.h def.h node.h type.h -cstoper.o: LLlex.h Lpars.h def_sizes.h idf.h node.h standards.h type.h +cstoper.o: LLlex.h Lpars.h idf.h node.h standards.h target_sizes.h type.h chk_expr.o: LLlex.h Lpars.h const.h debug.h def.h idf.h node.h scope.h standards.h type.h tokenfile.o: Lpars.h program.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h type.h declar.o: LLlex.h Lpars.h def.h idf.h misc.h node.h scope.h type.h expression.o: LLlex.h Lpars.h const.h debug.h def.h idf.h node.h scope.h type.h -statement.o: LLlex.h Lpars.h node.h +statement.o: LLlex.h Lpars.h node.h type.h Lpars.o: Lpars.h diff --git a/lang/m2/comp/Parameters b/lang/m2/comp/Parameters new file mode 100644 index 00000000..f49d2aad --- /dev/null +++ b/lang/m2/comp/Parameters @@ -0,0 +1,60 @@ +!File: errout.h +#define ERROUT STDERR /* file pointer for writing messages */ +#define MAXERR_LINE 5 /* maximum number of error messages given + on the same input line. */ + + +!File: idfsize.h +#define IDFSIZE 30 /* maximum significant length of an identifier */ + + +!File: numsize.h +#define NUMSIZE 256 /* maximum length of a numeric constant */ + + +!File: strsize.h +#define ISTRSIZE 32 /* minimum number of bytes allocated for + storing a string */ +#define RSTRSIZE 8 /* step size in enlarging the memory for + the storage of a string */ + + +!File: target_sizes.h +#define MAXSIZE 8 /* the maximum of the SZ_* constants */ + +/* target machine sizes */ +#define SZ_CHAR (arith)1 +#define SZ_SHORT (arith)2 +#define SZ_WORD (arith)4 +#define SZ_INT (arith)4 +#define SZ_LONG (arith)4 +#define SZ_FLOAT (arith)4 +#define SZ_DOUBLE (arith)8 +#define SZ_POINTER (arith)4 + +/* target machine alignment requirements */ +#define AL_CHAR 1 +#define AL_SHORT SZ_SHORT +#define AL_WORD SZ_WORD +#define AL_INT SZ_WORD +#define AL_LONG SZ_WORD +#define AL_FLOAT SZ_WORD +#define AL_DOUBLE SZ_WORD +#define AL_POINTER SZ_WORD +#define AL_STRUCT 1 +#define AL_UNION 1 + + +!File: debug.h +#define DEBUG 1 /* perform various self-tests */ +extern char options[]; +#ifdef DEBUG +#define DO_DEBUG(n, x) ((n) <= options['D'] && (x)) +#else +#define DO_DEBUG(n, x) +#endif DEBUG + +!File: inputtype.h +#undef INP_READ_IN_ONE 1 /* read input file in one */ + + diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index fdd55cb4..95ecf20b 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -79,7 +79,7 @@ chk_set(expp) if (expp->nd_left) { /* A type was given. Check it out */ - (void) findname(expp->nd_left); + findname(expp->nd_left); assert(expp->nd_left->nd_class == Def); df = expp->nd_left->nd_def; if ((df->df_kind != D_TYPE && df->df_kind != D_ERROR) || @@ -93,7 +93,7 @@ chk_set(expp) /* Now check the elements given, and try to compute a constant set. */ - set = (arith *) Malloc(tp->tp_size * sizeof(arith) / wrd_size); + set = (arith *) Malloc(tp->tp_size * sizeof(arith) / word_size); nd = expp->nd_right; while (nd) { assert(nd->nd_class == Link && nd->nd_symb == ','); @@ -149,7 +149,7 @@ node_error(expp, "Lower bound exceeds upper bound in range"); } } else if (*set) { - free(*set); + free((char *) *set); *set = 0; } return 1; @@ -223,7 +223,7 @@ getname(argp, kinds) return 0; } argp = argp->nd_right; - if (!findname(argp->nd_left)) return 0; + findname(argp->nd_left); assert(argp->nd_left->nd_class == Def); if (!(argp->nd_left->nd_def->df_kind & kinds)) { node_error(argp, "Unexpected type"); @@ -244,8 +244,8 @@ chk_call(expp) register struct node *arg; expp->nd_type = error_type; - (void) findname(expp->nd_left); /* parser made sure it is a name */ left = expp->nd_left; + findname(left); if (left->nd_type == error_type) return 0; if (left->nd_class == Def && @@ -451,8 +451,8 @@ findname(expp) scope. */ register struct def *df; - struct def *lookfor(); register struct type *tp; + struct def *lookfor(); expp->nd_type = error_type; if (expp->nd_class == Name) { @@ -498,18 +498,18 @@ df->df_idf->id_text); } if (expp->nd_class == Oper) { assert(expp->nd_symb == '['); - (void) findname(expp->nd_left); - if (chk_expr(expp->nd_right, 0) && + findname(expp->nd_left); + if (chk_expr(expp->nd_right) && expp->nd_left->nd_type != error_type && chk_oper(expp)) /* ??? */ ; - return 1; + return; } if (expp->nd_class == Uoper && expp->nd_symb == '^') { - (void) findname(expp->nd_right); + findname(expp->nd_right); if (expp->nd_right->nd_type != error_type && chk_uoper(expp)) /* ??? */ ; } - return 0; + return; } int @@ -518,7 +518,7 @@ chk_name(expp) { register struct def *df; - (void) findname(expp); + findname(expp); assert(expp->nd_class == Def); df = expp->nd_def; if (df->df_kind == D_ERROR) return 0; diff --git a/lang/m2/comp/cstoper.c b/lang/m2/comp/cstoper.c index 81411b29..be2ba576 100644 --- a/lang/m2/comp/cstoper.c +++ b/lang/m2/comp/cstoper.c @@ -5,7 +5,9 @@ static char *RcsId = "$Header$"; #include #include #include -#include "def_sizes.h" + +#include "target_sizes.h" + #include "idf.h" #include "type.h" #include "LLlex.h" @@ -211,7 +213,7 @@ cstset(expp) assert(expp->nd_right->nd_class == Set); assert(expp->nd_symb == IN || expp->nd_left->nd_class == Set); set2 = expp->nd_right->nd_set; - setsize = expp->nd_right->nd_type->tp_size / wrd_size; + setsize = expp->nd_right->nd_type->tp_size / word_size; if (expp->nd_symb == IN) { arith i; @@ -359,7 +361,8 @@ cstcall(expp, call) cut_size(expp); break; case S_SIZE: - expp->nd_INT = align(expr->nd_type->tp_size, wrd_size)/wrd_size; + expp->nd_INT = align(expr->nd_type->tp_size, (int) word_size) / + word_size; break; case S_VAL: expp->nd_INT = expr->nd_INT; @@ -435,12 +438,12 @@ init_cst() } mach_long_size = i; mach_long_sign = 1 << (mach_long_size * 8 - 1); - if (lint_size > mach_long_size) { + if (long_size > mach_long_size) { fatal("sizeof (long) insufficient on this machine"); } max_int = full_mask[int_size] & ~(1 << (int_size * 8 - 1)); max_unsigned = full_mask[int_size]; - max_longint = full_mask[lint_size] & ~(1 << (lint_size * 8 - 1)); - wrd_bits = 8 * wrd_size; + max_longint = full_mask[long_size] & ~(1 << (long_size * 8 - 1)); + wrd_bits = 8 * word_size; } diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index afedfbbe..8e5dbcd5 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -25,7 +25,7 @@ ProcedureDeclaration ProcedureHeading(&df, D_PROCEDURE) { df->prc_level = proclevel++; } - ';' block IDENT + ';' block(&(df->prc_body)) IDENT { match_id(dot.TOK_IDF, df->df_idf); df->prc_scope = CurrentScope; close_scope(SC_CHKFORW); @@ -68,11 +68,17 @@ error("inconsistent procedure declaration for \"%s\"", df->df_idf->id_text); } ; -block +block(struct node **pnd;) { - struct node *nd; }: - declaration* [ BEGIN StatementSequence(&nd) ]? END + declaration* + [ + BEGIN + StatementSequence(pnd) + | + { *pnd = 0; } + ] + END ; declaration: @@ -101,7 +107,7 @@ FormalParameters(int doparams; { pr1 = *pr; } [ { for (; pr1->next; pr1 = pr1->next) ; } - ';' FPSection(doparams, &(pr1->next), &parmaddr) + ';' FPSection(doparams, &(pr1->next), parmaddr) ]* ]? ')' @@ -149,8 +155,8 @@ FormalType(struct type **tp;) { if (ARRAYflag) { *tp = construct_type(T_ARRAY, NULLTYPE); (*tp)->arr_elem = df->df_type; - (*tp)->tp_align = lcm(wrd_align, ptr_align); - (*tp)->tp_size = align(ptr_size + 3*wrd_size, + (*tp)->tp_align = lcm(word_align, pointer_align); + (*tp)->tp_size = align(pointer_size + 3*word_size, (*tp)->tp_align); } else *tp = df->df_type; @@ -221,17 +227,17 @@ enumeration(struct type **ptp;) } : '(' IdentList(&EnumList) ')' { - *ptp = standard_type(T_ENUMERATION,1,1); + *ptp = standard_type(T_ENUMERATION, 1, (arith) 1); EnterIdList(EnumList, D_ENUM, 0, *ptp, CurrentScope, (arith *) 0); FreeNode(EnumList); if ((*ptp)->enm_ncst > 256) { - if (wrd_size == 1) { + if (word_size == 1) { error("Too many enumeration literals"); } else { - (*ptp)->tp_size = wrd_size; - (*ptp)->tp_align = wrd_align; + (*ptp)->tp_size = word_size; + (*ptp)->tp_align = word_align; } } } @@ -291,7 +297,7 @@ RecordType(struct type **ptp;) { struct scope *scope; arith count; - int xalign = record_align; + int xalign = struct_align; } : RECORD @@ -391,28 +397,43 @@ FieldList(struct scope *scope; arith *cnt; int *palign;) variant(struct scope *scope; arith *cnt; struct type *tp; int *palign;) { struct type *tp1 = tp; + struct node *nd; } : [ - CaseLabelList(&tp1) ':' FieldListSequence(scope, cnt, palign) + CaseLabelList(&tp1, &nd) + { /* Ignore the cases for the time being. + Maybe a checking version will be supplied + later ??? + */ + FreeNode(nd); + } + ':' FieldListSequence(scope, cnt, palign) ]? /* Changed rule in new modula-2 */ ; -CaseLabelList(struct type **ptp;): - CaseLabels(ptp) [ ',' CaseLabels(ptp) ]* +CaseLabelList(struct type **ptp; struct node **pnd;): + CaseLabels(ptp, pnd) + [ + { *pnd = MkNode(Link, *pnd, NULLNODE, &dot); } + ',' CaseLabels(ptp, &((*pnd)->nd_right)) + { pnd = &((*pnd)->nd_right); } + ]* ; -CaseLabels(struct type **ptp;) +CaseLabels(struct type **ptp; struct node **pnd;) { struct node *nd1, *nd2 = 0; }: - ConstExpression(&nd1) + ConstExpression(&nd1) { *pnd = nd1; } [ - UPTO ConstExpression(&nd2) + UPTO { *pnd = MkNode(Link,nd1,NULLNODE,&dot); } + ConstExpression(&nd2) { if (!TstCompat(nd1->nd_type, nd2->nd_type)) { node_error(nd2,"type incompatibility in case label"); } nd1->nd_type = error_type; + (*pnd)->nd_right = nd2; } ]? { if (*ptp != 0 && diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H index 6a762937..f2705a94 100644 --- a/lang/m2/comp/def.H +++ b/lang/m2/comp/def.H @@ -3,10 +3,12 @@ /* $Header$ */ struct module { - int mo_priority; /* priority of a module */ + arith mo_priority; /* priority of a module */ struct scope *mo_scope; /* scope of this module */ + struct node *mo_body; /* body of this module */ #define mod_priority df_value.df_module.mo_priority #define mod_scope df_value.df_module.mo_scope +#define mod_body df_value.df_module.mo_body }; struct variable { @@ -43,9 +45,11 @@ struct dfproc { struct scope *pr_scope; /* scope of procedure */ int pr_level; /* depth level of this procedure */ arith pr_nbpar; /* Number of bytes parameters */ + struct node *pr_body; /* body of this procedure */ #define prc_scope df_value.df_proc.pr_scope #define prc_level df_value.df_proc.pr_level #define prc_nbpar df_value.df_proc.pr_nbpar +#define prc_body df_value.df_proc.pr_body }; struct import { diff --git a/lang/m2/comp/error.c b/lang/m2/comp/error.c index e72269c4..13eae686 100644 --- a/lang/m2/comp/error.c +++ b/lang/m2/comp/error.c @@ -9,15 +9,15 @@ static char *RcsId = "$Header$"; #include #include + +#include "errout.h" + #include "input.h" #include "f_info.h" #include "LLlex.h" #include "main.h" #include "node.h" -#define MAXERR_LINE 5 /* Number of error messages on one line ... */ -#define ERROUT STDERR - /* error classes */ #define ERROR 1 #define WARNING 2 diff --git a/lang/m2/comp/input.h b/lang/m2/comp/input.h index 550cdc50..abb111c6 100644 --- a/lang/m2/comp/input.h +++ b/lang/m2/comp/input.h @@ -2,6 +2,8 @@ /* $Header$ */ +#include "inputtype.h" + #define INP_NPUSHBACK 2 #define INP_TYPE struct f_info #define INP_VAR file_info diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index a66d0aa8..a135e668 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -28,14 +28,14 @@ char *getenv(); main(argc, argv) char *argv[]; { - register Nargc = 1; + register int Nargc = 1; register char **Nargv = &argv[0]; ProgName = *argv++; while (--argc > 0) { if (**argv == '-') - Option(*argv++); + do_option((*argv++) + 1); else Nargv[Nargc++] = *argv++; } @@ -71,16 +71,14 @@ Compile(src) init_types(); add_standards(); #ifdef DEBUG - if (options['L']) LexScan(); - else { + if (options['l']) LexScan(); + else #endif DEBUG + { (void) open_scope(CLOSEDSCOPE); GlobalScope = CurrentScope; CompUnit(); -#ifdef DEBUG } - if (options['h']) hash_stat(); -#endif DEBUG if (err_occurred) return 0; return 1; } @@ -117,12 +115,6 @@ LexScan() } #endif -Option(str) - char *str; -{ - options[str[1]]++; /* switch option on */ -} - add_standards() { register struct def *df; diff --git a/lang/m2/comp/make.hfiles b/lang/m2/comp/make.hfiles new file mode 100755 index 00000000..2132dd61 --- /dev/null +++ b/lang/m2/comp/make.hfiles @@ -0,0 +1,35 @@ +: Update Files from database + +PATH=/bin:/usr/bin + +case $# in +1) ;; +*) echo use: $0 file >&2 + exit 1 +esac + +( +IFCOMMAND="if (<\$FN) 2>/dev/null;\ + then if cmp -s \$FN \$TMP;\ + then rm \$TMP;\ + else mv \$TMP \$FN;\ + echo update \$FN;\ + fi;\ + else mv \$TMP \$FN;\ + echo create \$FN;\ + fi" +echo 'TMP=.uf$$' +echo 'FN=$TMP' +echo 'cat >$TMP <<\!EOF!' +sed -n '/^!File:/,${ +/^$/d +/^!File:[ ]*\(.*\)$/s@@!EOF!\ +'"$IFCOMMAND"'\ +FN=\1\ +cat >$TMP <<\\!EOF!@ +p +}' $1 +echo '!EOF!' +echo $IFCOMMAND +) | +sh diff --git a/lang/m2/comp/options.c b/lang/m2/comp/options.c new file mode 100644 index 00000000..f8bc4881 --- /dev/null +++ b/lang/m2/comp/options.c @@ -0,0 +1,114 @@ +/* U S E R O P T I O N - H A N D L I N G */ + +static char *RcsId = "$Header$"; + +#include +#include + +#include "idfsize.h" + +#include "type.h" + +extern char options[]; +extern int idfsize; + +do_option(text) + char *text; +{ + switch(*text++) { + + default: + options[text[-1]] = 1; /* flags, debug options etc. */ + break; + + case 'L' : + warning("-L: default no EM profiling; use -p for EM profiling"); + break; + + case 'M': /* maximum identifier length */ + idfsize = txt2int(&text); + if (*text || idfsize <= 0) + fatal("malformed -M option"); + if (idfsize > IDFSIZE) + fatal("maximum identifier length is %d", IDFSIZE); + break; + + case 'p' : /* generate profiling code (fil/lin) */ + options['p'] = 1; + break; + + case 'V' : /* set object sizes and alignment requirements */ + { + arith size; + int align; + char c; + + while (c = *text++) { + size = txt2int(&text); + align = 0; + if (*text == '.') { + text++; + align = txt2int(&text); + } + switch (c) { + + case 'w': /* word */ + if (size != (arith)0) word_size = size; + if (align != 0) word_align = align; + break; + case 'i': /* int */ + if (size != (arith)0) int_size = size; + if (align != 0) int_align = align; + break; + case 'l': /* longint */ + if (size != (arith)0) long_size = size; + if (align != 0) long_align = align; + break; + case 'f': /* real */ + if (size != (arith)0) float_size = size; + if (align != 0) float_align = align; + break; + case 'd': /* longreal */ + if (size != (arith)0) double_size = size; + if (align != 0) double_align = align; + break; + case 'p': /* pointer */ + if (size != (arith)0) pointer_size = size; + if (align != 0) pointer_align = align; + break; + case 'S': /* initial record alignment */ + if (align != (arith)0) struct_align = align; + break; + default: + error("-V: bad type indicator %c\n", c); + } + } + break; + } + + case 'n': + options['n'] = 1; /* use no registers */ + break; + + case 'w': + options['w'] = 1; /* no warnings will be given */ + break; + } +} + +int +txt2int(tp) + char **tp; +{ + /* the integer pointed to by *tp is read, while increasing + *tp; the resulting value is yielded. + */ + register int val = 0; + register int ch; + + while (ch = **tp, ch >= '0' && ch <= '9') { + val = val * 10 + ch - '0'; + (*tp)++; + } + return val; +} diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index e3c6bb78..07930f4a 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -43,7 +43,7 @@ static int DEFofIMPL = 0; /* Flag indicating that we are currently ModuleDeclaration { struct idf *id; - struct def *df; + register struct def *df; } : MODULE IDENT { id = dot.TOK_IDF; @@ -57,20 +57,27 @@ ModuleDeclaration standard_type(T_RECORD, 0, (arith) 0); df->df_type->rec_scope = df->mod_scope; } - priority? ';' + priority(&(df->mod_priority))? + ';' import(1)* export(0)? - block + block(&(df->mod_body)) IDENT { close_scope(SC_CHKFORW|SC_CHKPROC); match_id(id, dot.TOK_IDF); } ; -priority +priority(arith *pprio;) { struct node *nd; -}: +} : '[' ConstExpression(&nd) ']' + { if (!(nd->nd_type->tp_fund & T_INTORCARD)) { + node_error(nd, "Illegal priority"); + } + *pprio = nd->nd_INT; + FreeNode(nd); + } ; export(int def;) @@ -161,7 +168,7 @@ definition { struct def *df; } : - CONST [ ConstantDeclaration ';' ]* + CONST [ ConstantDeclaration Semicolon ]* | TYPE [ IDENT { df = define(dot.TOK_IDF, CurrentScope, D_TYPE); } @@ -175,38 +182,48 @@ definition { df->df_kind = D_HIDDEN; } ] - ';' + Semicolon ]* | - VAR [ VariableDeclaration ';' ]* + VAR [ VariableDeclaration Semicolon ]* | - ProcedureHeading(&df, D_PROCHEAD) ';' + ProcedureHeading(&df, D_PROCHEAD) Semicolon +; + +Semicolon: + ';' +| + { warning("; expected"); } ; ProgramModule(int state;) { struct idf *id; - struct def *df, *GetDefinitionModule(); - struct scope *scope = 0; + struct def *GetDefinitionModule(); + register struct def *df; } : MODULE - IDENT { - id = dot.TOK_IDF; - if (state == IMPLEMENTATION) { - DEFofIMPL = 1; - df = GetDefinitionModule(id); - CurrentScope = df->mod_scope; - DEFofIMPL = 0; - DefinitionModule = 0; - } - else open_scope(CLOSEDSCOPE); - } - priority? + IDENT { + id = dot.TOK_IDF; + if (state == IMPLEMENTATION) { + DEFofIMPL = 1; + df = GetDefinitionModule(id); + CurrentScope = df->mod_scope; + DEFofIMPL = 0; + DefinitionModule = 0; + } + else { + df = define(id, CurrentScope, D_MODULE); + open_scope(CLOSEDSCOPE); + df->mod_scope = CurrentScope; + } + } + priority(&(df->mod_priority))? ';' import(0)* - block IDENT - { close_scope(SC_CHKFORW|SC_CHKPROC); - match_id(id, dot.TOK_IDF); - } + block(&(df->mod_body)) IDENT + { close_scope(SC_CHKFORW|SC_CHKPROC); + match_id(id, dot.TOK_IDF); + } '.' ; diff --git a/lang/m2/comp/scope.C b/lang/m2/comp/scope.C index ca608682..79ebb5f8 100644 --- a/lang/m2/comp/scope.C +++ b/lang/m2/comp/scope.C @@ -23,7 +23,6 @@ open_scope(scopetype) /* Open a scope that is either open (automatic imports) or closed. */ register struct scope *sc = new_scope(); - register struct scope *sc1; assert(scopetype == OPENSCOPE || scopetype == CLOSEDSCOPE); sc->sc_scopeclosed = scopetype == CLOSEDSCOPE; @@ -161,6 +160,24 @@ rem_forwards(fo) } } +Reverse(pdf) + register struct def **pdf; +{ + /* Reverse the order in the list of definitions in a scope. + This is neccesary because this list is built in reverse. + */ + register struct def *df, *df1; + + df = 0; + df1 = *pdf; + while (df1) { + df1 = df1->df_nextinscope; + (*pdf)->df_nextinscope = df; + df = *pdf; + *pdf = df1; + } +} + close_scope(flag) { /* Close a scope. If "flag" is set, check for forward declarations, @@ -177,6 +194,7 @@ close_scope(flag) DO_DEBUG(2, PrScopeDef(sc->sc_def)); if (flag & SC_CHKPROC) chk_proc(sc->sc_def); if (flag & SC_CHKFORW) chk_forw(&(sc->sc_def)); + Reverse(&(sc->sc_def)); } CurrentScope = sc->next; } diff --git a/lang/m2/comp/statement.g b/lang/m2/comp/statement.g index 36596be0..c30e66b3 100644 --- a/lang/m2/comp/statement.g +++ b/lang/m2/comp/statement.g @@ -4,7 +4,9 @@ static char *RcsId = "$Header$"; #include +#include #include "LLlex.h" +#include "type.h" #include "node.h" static int loopcount = 0; /* Count nested loops */ @@ -12,7 +14,7 @@ static int loopcount = 0; /* Count nested loops */ statement(struct node **pnd;) { - struct node *nd1; + register struct node *nd; } : { *pnd = 0; } [ @@ -21,16 +23,16 @@ statement(struct node **pnd;) * states : assignment | ProcedureCall | ... * but this gives LL(1) conflicts */ - designator(&nd1) - [ { nd1 = MkNode(Call, nd1, NULLNODE, &dot); - nd1->nd_symb = '('; + designator(pnd) + [ { nd = MkNode(Call, *pnd, NULLNODE, &dot); + nd->nd_symb = '('; } - ActualParameters(&(nd1->nd_right))? + ActualParameters(&(nd->nd_right))? | - BECOMES { nd1 = MkNode(Stat, nd1, NULLNODE, &dot); } - expression(&(nd1->nd_right)) + BECOMES { nd = MkNode(Stat, *pnd, NULLNODE, &dot); } + expression(&(nd->nd_right)) ] - { *pnd = nd1; } + { *pnd = nd; } /* * end of changed part */ @@ -58,9 +60,9 @@ statement(struct node **pnd;) *pnd = MkNode(Stat, NULLNODE, NULLNODE, &dot); } | - RETURN { *pnd = MkNode(Stat, NULLNODE, NULLNODE, &dot); } + RETURN { *pnd = nd = MkNode(Stat, NULLNODE, NULLNODE, &dot); } [ - expression(&((*pnd)->nd_right)) + expression(&(nd->nd_right)) ]? ]? ; @@ -138,7 +140,7 @@ CaseStatement(struct node **pnd;) case(struct node **pnd; struct type **ptp;) : { *pnd = 0; } - [ CaseLabelList(ptp/*,pnd*/) + [ CaseLabelList(ptp, pnd) ':' { *pnd = MkNode(Link, *pnd, NULLNODE, &dot); } StatementSequence(&((*pnd)->nd_right)) ]? diff --git a/lang/m2/comp/type.H b/lang/m2/comp/type.H index 38c8a96c..c2824a84 100644 --- a/lang/m2/comp/type.H +++ b/lang/m2/comp/type.H @@ -102,21 +102,21 @@ extern struct type *error_type; /* All from type.c */ extern int - wrd_align, + word_align, int_align, - lint_align, - real_align, - lreal_align, - ptr_align, - record_align; /* All from type.c */ + long_align, + float_align, + double_align, + pointer_align, + struct_align; /* All from type.c */ extern arith - wrd_size, + word_size, int_size, - lint_size, - real_size, - lreal_size, - ptr_size; /* All from type.c */ + long_size, + float_size, + double_size, + pointer_size; /* All from type.c */ extern arith align(); /* type.c */ diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index 5792379e..58139999 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -6,34 +6,36 @@ static char *RcsId = "$Header$"; #include #include #include -#include "def_sizes.h" + +#include "target_sizes.h" +#include "debug.h" + #include "def.h" #include "type.h" #include "idf.h" #include "LLlex.h" #include "node.h" #include "const.h" -#include "debug.h" /* To be created dynamically in main() from defaults or from command line parameters. */ int - wrd_align = AL_WORD, + word_align = AL_WORD, int_align = AL_INT, - lint_align = AL_LONG, - real_align = AL_FLOAT, - lreal_align = AL_DOUBLE, - ptr_align = AL_POINTER, - record_align = AL_STRUCT; + long_align = AL_LONG, + float_align = AL_FLOAT, + double_align = AL_DOUBLE, + pointer_align = AL_POINTER, + struct_align = AL_STRUCT; arith - wrd_size = SZ_WORD, + word_size = SZ_WORD, int_size = SZ_INT, - lint_size = SZ_LONG, - real_size = SZ_FLOAT, - lreal_size = SZ_DOUBLE, - ptr_size = SZ_POINTER; + long_size = SZ_LONG, + float_size = SZ_FLOAT, + double_size = SZ_DOUBLE, + pointer_size = SZ_POINTER; struct type *bool_type, @@ -83,12 +85,12 @@ construct_type(fund, tp) switch (fund) { case T_PROCEDURE: case T_POINTER: - dtp->tp_align = ptr_align; - dtp->tp_size = ptr_size; + dtp->tp_align = pointer_align; + dtp->tp_size = pointer_size; dtp->next = tp; break; case T_SET: - dtp->tp_align = wrd_align; + dtp->tp_align = word_align; dtp->next = tp; break; case T_ARRAY: @@ -135,17 +137,17 @@ init_types() bool_type = standard_type(T_ENUMERATION, 1, (arith) 1); bool_type->enm_ncst = 2; int_type = standard_type(T_INTEGER, int_align, int_size); - longint_type = standard_type(T_INTEGER, lint_align, lint_size); + longint_type = standard_type(T_INTEGER, long_align, long_size); card_type = standard_type(T_CARDINAL, int_align, int_size); - real_type = standard_type(T_REAL, real_align, real_size); - longreal_type = standard_type(T_REAL, lreal_align, lreal_size); - word_type = standard_type(T_WORD, wrd_align, wrd_size); + real_type = standard_type(T_REAL, float_align, float_size); + longreal_type = standard_type(T_REAL, double_align, double_size); + word_type = standard_type(T_WORD, word_align, word_size); intorcard_type = standard_type(T_INTORCARD, int_align, int_size); string_type = standard_type(T_STRING, 1, (arith) -1); address_type = construct_type(T_POINTER, word_type); tp = construct_type(T_SUBRANGE, int_type); tp->sub_lb = 0; - tp->sub_ub = wrd_size * 8 - 1; + tp->sub_ub = word_size * 8 - 1; bitset_type = set_type(tp); std_type = construct_type(T_PROCEDURE, NULLTYPE); error_type = standard_type(T_CHAR, 1, (arith) 1); @@ -265,7 +267,7 @@ set_type(tp) /* Construct a set type with base type "tp", but first perform some checks */ - int lb, ub; + arith lb, ub; if (tp->tp_fund == T_SUBRANGE) { if ((lb = tp->sub_lb) < 0 || (ub = tp->sub_ub) > MAX_SET - 1) { @@ -285,7 +287,7 @@ set_type(tp) return error_type; } tp = construct_type(T_SET, tp); - tp->tp_size = align(((ub - lb) + 7)/8, wrd_align); + tp->tp_size = align(((ub - lb) + 7)/8, word_align); return tp; } @@ -346,13 +348,9 @@ gcd(m, n) int lcm(m, n) - register int m, n; + int m, n; { /* Least Common Multiple */ - while (m != n) { - if (m < n) m = m + m; - else n = n + n; - } - return n; /* or m */ + return m * (n / gcd(m, n)); } From 8b438fbca3a742a9fc9361cfb826053cbfee65fd Mon Sep 17 00:00:00 2001 From: erikb Date: Thu, 17 Apr 1986 14:42:54 +0000 Subject: [PATCH 0180/1625] various small corrections --- lang/cem/cemcom/domacro.c | 14 +++++++------- lang/cem/cemcom/dumpidf.c | 2 +- lang/cem/cemcom/stack.c | 5 ++++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lang/cem/cemcom/domacro.c b/lang/cem/cemcom/domacro.c index b0afb18d..ff742d83 100644 --- a/lang/cem/cemcom/domacro.c +++ b/lang/cem/cemcom/domacro.c @@ -352,11 +352,12 @@ do_ifdef(how) */ push_if(); if (id = GetIdentifier()) { - if ((how && !(id && id->id_macro)) || - (!how && id && id->id_macro)) - { /* this id is not defined */ + if ( + (how && !(id && id->id_macro)) + || + (!how && id && id->id_macro) + ) /* this id is not defined */ skip_block(); - } else SkipRestOfLine(); } @@ -390,9 +391,8 @@ do_line(l) { struct token tk; - LineNumber = l; - /* is there a filespecifier? */ - if (GetToken(&tk) == STRING) + LineNumber = l - 1; /* the number of the next input line */ + if (GetToken(&tk) == STRING) /* is there a filespecifier? */ FileName = tk.tk_bts; SkipRestOfLine(); } diff --git a/lang/cem/cemcom/dumpidf.c b/lang/cem/cemcom/dumpidf.c index 77c8f5ea..af6f3093 100644 --- a/lang/cem/cemcom/dumpidf.c +++ b/lang/cem/cemcom/dumpidf.c @@ -352,7 +352,7 @@ p1_expr(lvl, expr) break; case String: { - char bts2str(); + char *bts2str(); print( "%s\n", diff --git a/lang/cem/cemcom/stack.c b/lang/cem/cemcom/stack.c index 00b79081..26a849e2 100644 --- a/lang/cem/cemcom/stack.c +++ b/lang/cem/cemcom/stack.c @@ -210,12 +210,15 @@ unstack_world() #ifdef DEBUG if (options['a']) { - print("\"%s\", %s, %s, %s\n", + char *symbol2str(); + + print("\"%s\", %s, %s, %s, %s\n", idf->id_text, (def->df_alloc == 0) ? "no alloc" : (def->df_alloc == ALLOC_SEEN) ? "alloc seen" : (def->df_alloc == ALLOC_DONE) ? "alloc done" : "illegal alloc info", + symbol2str(def->df_sc), def->df_initialized ? "init" : "no init", def->df_used ? "used" : "not used"); } From ea9dcf01ec6dfe7021385256044d5527cafc6bdc Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 18 Apr 1986 17:53:47 +0000 Subject: [PATCH 0181/1625] newer version --- lang/m2/comp/LLlex.c | 2 +- lang/m2/comp/Makefile | 5 +- lang/m2/comp/char.tab | 2 +- lang/m2/comp/chk_expr.c | 134 +++++++++++++++++++++++++++++++------- lang/m2/comp/declar.g | 8 +++ lang/m2/comp/def.H | 12 +++- lang/m2/comp/def.c | 40 ++++++++---- lang/m2/comp/enter.c | 15 ++++- lang/m2/comp/error.c | 1 + lang/m2/comp/expression.g | 11 +++- lang/m2/comp/main.c | 25 +++++-- lang/m2/comp/program.g | 17 +++-- lang/m2/comp/scope.C | 4 ++ lang/m2/comp/scope.h | 2 + lang/m2/comp/type.H | 1 + lang/m2/comp/type.c | 3 + lang/m2/comp/typequiv.c | 24 +++++++ 17 files changed, 246 insertions(+), 60 deletions(-) diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index c53e3159..1cf3c387 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -76,7 +76,7 @@ GetString(upto) register struct string *str = &string; register char *p; - str->s_str = p = Malloc((unsigned) (str->s_length = ISTRSIZE)); + str->s_str = p = Malloc(str->s_length = ISTRSIZE); LoadChar(ch); while (ch != upto) { if (class(ch) == STNL) { diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index 8ce1097f..c342b5e0 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -38,7 +38,7 @@ hfiles: Parameters make.hfiles touch hfiles main: $(OBJ) Makefile - $(CC) $(LFLAGS) $(OBJ) $(LIBDIR)/libcomp.a $(LIBDIR)/malloc.o /user1/erikb/em/lib/libprint.a /user1/erikb/em/lib/libstr.a /user1/erikb/em/lib/libsystem.a -o main + $(CC) $(LFLAGS) $(OBJ) /user1/erikb/em/lib/libem_mes.a /user1/erikb/em/lib/libeme.a $(LIBDIR)/libcomp.a $(LIBDIR)/malloc.o /user1/erikb/em/lib/libprint.a /user1/erikb/em/lib/libstr.a /user1/erikb/em/lib/libsystem.a -o main size main clean: @@ -91,12 +91,13 @@ type.o: LLlex.h const.h debug.h def.h idf.h node.h target_sizes.h type.h def.o: LLlex.h debug.h def.h idf.h main.h node.h scope.h type.h scope.o: LLlex.h debug.h def.h idf.h node.h scope.h type.h misc.o: LLlex.h f_info.h idf.h misc.h node.h -enter.o: LLlex.h def.h idf.h node.h scope.h type.h +enter.o: LLlex.h def.h idf.h main.h node.h scope.h type.h defmodule.o: LLlex.h debug.h def.h f_info.h idf.h input.h inputtype.h scope.h typequiv.o: def.h type.h node.o: LLlex.h debug.h def.h node.h type.h cstoper.o: LLlex.h Lpars.h idf.h node.h standards.h target_sizes.h type.h chk_expr.o: LLlex.h Lpars.h const.h debug.h def.h idf.h node.h scope.h standards.h type.h +options.o: idfsize.h type.h tokenfile.o: Lpars.h program.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h type.h declar.o: LLlex.h Lpars.h def.h idf.h misc.h node.h scope.h type.h diff --git a/lang/m2/comp/char.tab b/lang/m2/comp/char.tab index 53b2d69d..e4f57402 100644 --- a/lang/m2/comp/char.tab +++ b/lang/m2/comp/char.tab @@ -23,7 +23,7 @@ STEOI:\200 % INIDF % %C -1:a-zA-Z_0-9 +1:a-zA-Z0-9 %Tchar inidf[] = { %F %s, %p diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index 95ecf20b..6c950e5b 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -8,6 +8,7 @@ static char *RcsId = "$Header$"; #include #include #include + #include "Lpars.h" #include "idf.h" #include "type.h" @@ -17,6 +18,7 @@ static char *RcsId = "$Header$"; #include "scope.h" #include "const.h" #include "standards.h" + #include "debug.h" int @@ -25,7 +27,7 @@ chk_expr(expp) { /* Check the expression indicated by expp for semantic errors, identify identifiers used in it, replace constants by - their value. + their value, and try to evaluate the expression. */ switch(expp->nd_class) { @@ -33,25 +35,32 @@ chk_expr(expp) return chk_expr(expp->nd_left) && chk_expr(expp->nd_right) && chk_oper(expp); + case Uoper: return chk_expr(expp->nd_right) && chk_uoper(expp); + case Value: switch(expp->nd_symb) { case REAL: case STRING: case INTEGER: return 1; + default: assert(0); } break; + case Xset: return chk_set(expp); + case Name: return chk_name(expp); + case Call: return chk_call(expp); + case Link: return chk_name(expp); default: @@ -82,9 +91,9 @@ chk_set(expp) findname(expp->nd_left); assert(expp->nd_left->nd_class == Def); df = expp->nd_left->nd_def; - if ((df->df_kind != D_TYPE && df->df_kind != D_ERROR) || + if (!(df->df_kind & (D_TYPE|D_ERROR)) || (df->df_type->tp_fund != T_SET)) { - node_error(expp, "Illegal set type"); + node_error(expp, "illegal set type"); return 0; } tp = df->df_type; @@ -93,7 +102,8 @@ chk_set(expp) /* Now check the elements given, and try to compute a constant set. */ - set = (arith *) Malloc(tp->tp_size * sizeof(arith) / word_size); + set = (arith *) + Malloc((unsigned) (tp->tp_size * sizeof(arith) / word_size)); nd = expp->nd_right; while (nd) { assert(nd->nd_class == Link && nd->nd_symb == ','); @@ -102,7 +112,10 @@ chk_set(expp) } expp->nd_type = tp; if (set) { - /* Yes, in was a constant set, and we managed to compute it! + /* Yes, it was a constant set, and we managed to compute it! + Notice that at the moment there is no such thing as + partial evaluation. Either we evaluate the set, or we + don't (at all). Improvement not neccesary. (???) */ expp->nd_class = Set; expp->nd_set = set; @@ -123,6 +136,8 @@ chk_el(expp, tp, set) recursively. Also try to compute the set! */ + register int i; + if (expp->nd_class == Link && expp->nd_symb == UPTO) { /* { ... , expr1 .. expr2, ... } First check expr1 and expr2, and try to compute them. @@ -136,10 +151,9 @@ chk_el(expp, tp, set) /* We have a constant range. Put all elements in the set */ - register int i; if (expp->nd_left->nd_INT > expp->nd_right->nd_INT) { -node_error(expp, "Lower bound exceeds upper bound in range"); +node_error(expp, "lower bound exceeds upper bound in range"); return rem_set(set); } @@ -161,20 +175,21 @@ node_error(expp, "Lower bound exceeds upper bound in range"); return rem_set(set); } if (!TstCompat(tp, expp->nd_type)) { - node_error(expp, "Set element has incompatible type"); + node_error(expp, "set element has incompatible type"); return rem_set(set); } if (expp->nd_class == Value) { + i = expp->nd_INT; if ((tp->tp_fund != T_ENUMERATION && - (expp->nd_INT < tp->sub_lb || expp->nd_INT > tp->sub_ub)) + (i < tp->sub_lb || i > tp->sub_ub)) || (tp->tp_fund == T_ENUMERATION && - (expp->nd_INT < 0 || expp->nd_INT > tp->enm_ncst)) + (i < 0 || i > tp->enm_ncst)) ) { - node_error(expp, "Set element out of range"); + node_error(expp, "set element out of range"); return rem_set(set); } - if (*set) (*set)[expp->nd_INT/wrd_bits] |= (1 << (expp->nd_INT%wrd_bits)); + if (*set) (*set)[i/wrd_bits] |= (1 << (i%wrd_bits)); } return 1; } @@ -207,8 +222,8 @@ getarg(argp, bases) if (!chk_expr(argp->nd_left)) return 0; tp = argp->nd_left->nd_type; if (tp->tp_fund == T_SUBRANGE) tp = tp->next; - if (!(tp->tp_fund & bases)) { - node_error(argp, "Unexpected type"); + if (bases && !(tp->tp_fund & bases)) { + node_error(argp, "unexpected type"); return 0; } return argp; @@ -226,7 +241,7 @@ getname(argp, kinds) findname(argp->nd_left); assert(argp->nd_left->nd_class == Def); if (!(argp->nd_left->nd_def->df_kind & kinds)) { - node_error(argp, "Unexpected type"); + node_error(argp, "unexpected type"); return 0; } return argp; @@ -243,6 +258,8 @@ chk_call(expp) register struct node *left; register struct node *arg; + /* First, get the name of the function or procedure + */ expp->nd_type = error_type; left = expp->nd_left; findname(left); @@ -250,18 +267,18 @@ chk_call(expp) if (left->nd_type == error_type) return 0; if (left->nd_class == Def && (left->nd_def->df_kind & (D_HTYPE|D_TYPE|D_HIDDEN))) { - /* A type cast. This is of course not portable. + /* It was a type cast. This is of course not portable. No runtime action. Remove it. */ arg = expp->nd_right; if ((! arg) || arg->nd_right) { -node_error(expp, "Only one parameter expected in type cast"); +node_error(expp, "only one parameter expected in type cast"); return 0; } arg = arg->nd_left; if (! chk_expr(arg)) return 0; if (arg->nd_type->tp_size != left->nd_type->tp_size) { -node_error(expp, "Size of type in type cast does not match size of operand"); +node_error(expp, "size of type in type cast does not match size of operand"); return 0; } arg->nd_type = left->nd_type; @@ -285,7 +302,7 @@ node_error(expp, "Size of type in type cast does not match size of operand"); /* A standard procedure */ assert(left->nd_class == Def); -DO_DEBUG(3, debug("Standard name \"%s\", %d", +DO_DEBUG(3, debug("standard name \"%s\", %d", left->nd_def->df_idf->id_text, left->nd_def->df_value.df_stdname)); switch(left->nd_def->df_value.df_stdname) { case S_ABS: @@ -297,6 +314,7 @@ left->nd_def->df_idf->id_text, left->nd_def->df_value.df_stdname)); cstcall(expp, S_ABS); } break; + case S_CAP: arg = getarg(arg, T_CHAR); expp->nd_type = char_type; @@ -306,6 +324,7 @@ left->nd_def->df_idf->id_text, left->nd_def->df_value.df_stdname)); cstcall(expp, S_CAP); } break; + case S_CHR: arg = getarg(arg, T_INTORCARD); expp->nd_type = char_type; @@ -314,11 +333,13 @@ left->nd_def->df_idf->id_text, left->nd_def->df_value.df_stdname)); cstcall(expp, S_CHR); } break; + case S_FLOAT: arg = getarg(arg, T_INTORCARD); expp->nd_type = real_type; if (!arg) return 0; break; + case S_HIGH: arg = getarg(arg, T_ARRAY); if (!arg) return 0; @@ -331,6 +352,7 @@ left->nd_def->df_idf->id_text, left->nd_def->df_value.df_stdname)); } else cstcall(expp, S_MAX); break; + case S_MAX: case S_MIN: arg = getarg(arg, T_DISCRETE); @@ -338,6 +360,7 @@ left->nd_def->df_idf->id_text, left->nd_def->df_value.df_stdname)); expp->nd_type = arg->nd_left->nd_type; cstcall(expp,left->nd_def->df_value.df_stdname); break; + case S_ODD: arg = getarg(arg, T_INTORCARD); if (!arg) return 0; @@ -346,6 +369,7 @@ left->nd_def->df_idf->id_text, left->nd_def->df_value.df_stdname)); cstcall(expp, S_ODD); } break; + case S_ORD: arg = getarg(arg, T_DISCRETE); if (!arg) return 0; @@ -354,6 +378,7 @@ left->nd_def->df_idf->id_text, left->nd_def->df_value.df_stdname)); cstcall(expp, S_ORD); } break; + case S_TSIZE: /* ??? */ case S_SIZE: arg = getname(arg, D_FIELD|D_VARIABLE|D_TYPE|D_HIDDEN|D_HTYPE); @@ -361,11 +386,13 @@ left->nd_def->df_idf->id_text, left->nd_def->df_value.df_stdname)); if (!arg) return 0; cstcall(expp, S_SIZE); break; + case S_TRUNC: arg = getarg(arg, T_REAL); if (!arg) return 0; expp->nd_type = card_type; break; + case S_VAL: { struct type *tp; @@ -388,11 +415,13 @@ left->nd_def->df_idf->id_text, left->nd_def->df_value.df_stdname)); } break; } + case S_ADR: arg = getname(arg, D_VARIABLE|D_FIELD|D_PROCEDURE); expp->nd_type = address_type; if (!arg) return 0; break; + case S_DEC: case S_INC: expp->nd_type = 0; @@ -403,9 +432,11 @@ left->nd_def->df_idf->id_text, left->nd_def->df_value.df_stdname)); if (!arg) return 0; } break; + case S_HALT: expp->nd_type = 0; break; + case S_EXCL: case S_INCL: { struct type *tp; @@ -421,11 +452,12 @@ node_error(arg, "EXCL and INCL expect a SET parameter"); arg = getarg(arg, T_DISCRETE); if (!arg) return 0; if (!TstCompat(tp->next, arg->nd_left->nd_type)) { - node_error(arg, "Unexpected type"); + node_error(arg, "unexpected type"); return 0; } break; } + default: assert(0); } @@ -436,14 +468,51 @@ node_error(arg, "EXCL and INCL expect a SET parameter"); } return 1; } - /* Here, we have found a real procedure call + /* Here, we have found a real procedure call. The left hand + side may also represent a procedure variable. */ - return 1; + return chk_proccall(expp); } node_error(expp->nd_left, "procedure, type, or function expected"); return 0; } +chk_proccall(expp) + struct node *expp; +{ + /* Check a procedure call + */ + register struct node *left = expp->nd_left; + register struct node *arg; + register struct paramlist *param; + + expp->nd_type = left->nd_type->next; + param = left->nd_type->prc_params; + arg = expp; + + while (param) { + arg = getarg(arg, 0); + if (!arg) return 0; + if (param->par_var && + ! TstCompat(param->par_type, arg->nd_left->nd_type)) { +node_error(arg->nd_left, "type incompatibility in var parameter"); + return 0; + } + else + if (!param->par_var && + !TstAssCompat(param->par_type, arg->nd_left->nd_type)) { +node_error(arg->nd_left, "type incompatibility in value parameter"); + return 0; + } + param = param->next; + } + if (arg->nd_right) { + node_error(arg->nd_right, "too many parameters supplied"); + return 0; + } + return 1; +} + findname(expp) register struct node *expp; { @@ -471,7 +540,7 @@ findname(expp) } else if (tp->tp_fund != T_RECORD) { /* This is also true for modules */ - node_error(expp,"Illegal selection"); + node_error(expp,"illegal selection"); df = ill_df; } else df = lookup(expp->nd_right->nd_IDF, tp->rec_scope); @@ -614,16 +683,19 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R cstbin(expp); } return 1; + case T_SET: if (expp->nd_left->nd_class == Set && expp->nd_right->nd_class == Set) { cstset(expp); } /* Fall through */ + case T_REAL: return 1; } break; + case '/': switch(tpl->tp_fund) { case T_SET: @@ -632,10 +704,12 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R cstset(expp); } /* Fall through */ + case T_REAL: return 1; } break; + case DIV: case MOD: if (tpl->tp_fund & T_INTORCARD) { @@ -646,6 +720,7 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R return 1; } break; + case OR: case AND: if (tpl == bool_type) { @@ -657,6 +732,7 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R } errval = 3; break; + case '=': case '#': case GREATEREQUAL: @@ -673,6 +749,7 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R cstset(expp); } return 1; + case T_INTEGER: case T_CARDINAL: case T_ENUMERATION: /* includes boolean */ @@ -683,24 +760,29 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R cstbin(expp); } return 1; + case T_POINTER: if (!(expp->nd_symb == '=' || expp->nd_symb == '#')) { break; } /* Fall through */ + case T_REAL: return 1; } + default: assert(0); } switch(errval) { case 1: - node_error(expp,"Operator \"%s\": illegal operand type(s)", symbol2str(expp->nd_symb)); + node_error(expp,"operator \"%s\": illegal operand type(s)", symbol2str(expp->nd_symb)); break; + case 3: node_error(expp, "BOOLEAN type(s) expected"); break; + default: assert(0); } @@ -727,6 +809,7 @@ chk_uoper(expp) return 1; } break; + case '-': if (tpr->tp_fund & T_INTORCARD) { if (expp->nd_right->nd_class == Value) { @@ -747,6 +830,7 @@ chk_uoper(expp) return 1; } break; + case NOT: if (tpr == bool_type) { if (expp->nd_right->nd_class == Value) { @@ -755,10 +839,12 @@ chk_uoper(expp) return 1; } break; + case '^': if (tpr->tp_fund != T_POINTER) break; expp->nd_type = tpr->next; return 1; + default: assert(0); } diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 8e5dbcd5..173104d2 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -14,16 +14,24 @@ static char *RcsId = "$Header$"; #include "scope.h" #include "node.h" #include "misc.h" +#include "main.h" static int proclevel = 0; /* nesting level of procedures */ +char * sprint(); } ProcedureDeclaration { struct def *df; + char buf[256]; } : ProcedureHeading(&df, D_PROCEDURE) { df->prc_level = proclevel++; + if (DefinitionModule) { + C_exp(sprint(buf, "%s_%s", + df->df_scope->sc_name, + df->df_idf->id_text)); + } } ';' block(&(df->prc_body)) IDENT { match_id(dot.TOK_IDF, df->df_idf); diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H index f2705a94..e208653c 100644 --- a/lang/m2/comp/def.H +++ b/lang/m2/comp/def.H @@ -14,8 +14,13 @@ struct module { struct variable { arith va_off; /* address or offset of variable */ char va_addrgiven; /* an address was given in the program */ + char va_noreg; /* may not be in a register */ + short va_number; /* number of this variable in definition module + */ #define var_off df_value.df_variable.va_off #define var_addrgiven df_value.df_variable.va_addrgiven +#define var_noreg df_value.df_variable.va_noreg +#define var_number df_value.df_variable.va_number }; struct constant { @@ -43,13 +48,16 @@ struct field { struct dfproc { struct scope *pr_scope; /* scope of procedure */ - int pr_level; /* depth level of this procedure */ - arith pr_nbpar; /* Number of bytes parameters */ + short pr_level; /* depth level of this procedure */ + short pr_number; /* number of this procedure in definition module + */ + arith pr_nbpar; /* number of bytes parameters */ struct node *pr_body; /* body of this procedure */ #define prc_scope df_value.df_proc.pr_scope #define prc_level df_value.df_proc.pr_level #define prc_nbpar df_value.df_proc.pr_nbpar #define prc_body df_value.df_proc.pr_body +#define prc_number df_value.df_proc.pr_number }; struct import { diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index 4ebdef06..809bb5ed 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -22,6 +22,32 @@ static struct def illegal_def = struct def *ill_df = &illegal_def; +struct def * +MkDef(id, scope, kind) + struct idf *id; + struct scope *scope; +{ + /* Create a new definition structure in scope "scope", with + id "id" and kind "kind". + */ + register struct def *df; + + df = new_def(); + df->df_flags = 0; + df->df_idf = id; + df->df_scope = scope; + df->df_kind = kind; + df->df_type = 0; + df->next = id->id_def; + id->id_def = df; + + /* enter the definition in the list of definitions in this scope + */ + df->df_nextinscope = scope->sc_def; + scope->sc_def = df; + return df; +} + struct def * define(id, scope, kind) register struct idf *id; @@ -85,19 +111,7 @@ error("identifier \"%s\" already declared", id->id_text); } return df; } - df = new_def(); - df->df_flags = 0; - df->df_idf = id; - df->df_scope = scope; - df->df_kind = kind; - df->df_type = 0; - df->next = id->id_def; - id->id_def = df; - - /* enter the definition in the list of definitions in this scope */ - df->df_nextinscope = scope->sc_def; - scope->sc_def = df; - return df; + return MkDef(id, scope, kind); } struct def * diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index 4c9e14b7..76fbc32a 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -12,6 +12,7 @@ static char *RcsId = "$Header$"; #include "scope.h" #include "LLlex.h" #include "node.h" +#include "main.h" struct def * Enter(name, kind, type, pnam) @@ -126,6 +127,13 @@ node_error(IdList->nd_left,"Illegal type for address"); df->var_off = off; scope->sc_off = off; } + else if (DefinitionModule) { + char buf[256]; + char *sprint(); + + C_exa_dnam(sprint(buf,"%s_%s",df->df_scope->sc_name, + df->df_idf->id_text)); + } IdList = IdList->nd_right; } } @@ -137,17 +145,20 @@ lookfor(id, scope, give_error) { /* Look for an identifier in the visibility range started by "scope". - If it is not defined, give an error message, and + If it is not defined, maybe give an error message, and create a dummy definition. */ struct def *df; register struct scope *sc = scope; + struct def *MkDef(); while (sc) { df = lookup(id->nd_IDF, sc); if (df) return df; sc = nextvisible(sc); } + if (give_error) id_not_declared(id); - return define(id->nd_IDF, scope, D_ERROR); + + return MkDef(id->nd_IDF, scope, D_ERROR); } diff --git a/lang/m2/comp/error.c b/lang/m2/comp/error.c index 13eae686..13280af6 100644 --- a/lang/m2/comp/error.c +++ b/lang/m2/comp/error.c @@ -11,6 +11,7 @@ static char *RcsId = "$Header$"; #include #include "errout.h" +#include "debug.h" #include "input.h" #include "f_info.h" diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index 75655c90..69a750c6 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -183,10 +183,15 @@ factor(struct node **p;) | %default number(p) | - STRING { *p = MkNode(Value, NULLNODE, NULLNODE, &dot); + STRING { + *p = MkNode(Value, NULLNODE, NULLNODE, &dot); if (dot.TOK_SLE == 1) { - dot.TOK_INT = *(dot.TOK_STR); - (*p)->nd_type = char_type; + int i; + + i = *(dot.TOK_STR) & 0377; + (*p)->nd_type = charc_type; + free(dot.TOK_STR); + dot.TOK_INT = i; } else (*p)->nd_type = string_type; } diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index a135e668..491d9f81 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -40,23 +40,24 @@ main(argc, argv) Nargv[Nargc++] = *argv++; } Nargv[Nargc] = 0; /* terminate the arg vector */ - if (Nargc != 2) { - fprint(STDERR, "%s: Use one file argument\n", ProgName); + if (Nargc < 2) { + fprint(STDERR, "%s: Use a file argument\n", ProgName); return 1; } #ifdef DEBUG - print("Mod2 compiler -- Debug version\n"); -#endif DEBUG + print("MODULA-2 compiler -- Debug version\n"); DO_DEBUG(1, debug("Debugging level: %d", options['D'])); - return !Compile(Nargv[1]); +#endif DEBUG + return !Compile(Nargv[1], Nargv[2]); } -Compile(src) - char *src; +Compile(src, dst) + char *src, *dst; { extern struct tokenname tkidf[]; DO_DEBUG(1, debug("Filename : %s", src)); + DO_DEBUG(1, (!dst || debug("Targetfile: %s", dst))); if (! InsertFile(src, (char **) 0, &src)) { fprint(STDERR,"%s: cannot open %s\n", ProgName, src); return 0; @@ -77,8 +78,15 @@ Compile(src) { (void) open_scope(CLOSEDSCOPE); GlobalScope = CurrentScope; + C_init(word_size, pointer_size); + if (! C_open(dst)) { + fatal("Could not open output file"); + } + C_magic(); + C_ms_emx(word_size, pointer_size); CompUnit(); } + C_close(); if (err_occurred) return 0; return 1; } @@ -87,6 +95,7 @@ Compile(src) LexScan() { register int symb; + char *symbol2str(); while ((symb = LLlex()) > 0) { print(">>> %s ", symbol2str(symb)); @@ -171,6 +180,8 @@ init_DEFPATH() if (*p) *p++ = '\0'; } } + else DEFPATH[i++] = ""; + DEFPATH[i] = 0; } diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 07930f4a..a2c066c9 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -20,6 +20,9 @@ static int DEFofIMPL = 0; /* Flag indicating that we are currently implementation module currently being compiled */ +short nmcount = 0; /* count names in definition modules in order + to create suitable names in the object code + */ } /* The grammar as given by Wirth is already almost LL(1); the @@ -95,7 +98,7 @@ export(int def;) Export(ExportList, QUALflag); } else { - warning("export list in definition module ignored"); +node_warning(ExportList, "export list in definition module ignored"); FreeNode(ExportList); } } @@ -125,16 +128,20 @@ DefinitionModule { register struct def *df; struct idf *id; + int savnmcount = nmcount; } : DEFINITION MODULE IDENT { id = dot.TOK_IDF; df = define(id, GlobalScope, D_MODULE); if (!SYSTEMModule) open_scope(CLOSEDSCOPE); df->mod_scope = CurrentScope; + CurrentScope->sc_name = id->id_text; df->df_type = standard_type(T_RECORD, 0, (arith) 0); df->df_type->rec_scope = df->mod_scope; - DefinitionModule = 1; - DO_DEBUG(1, debug("Definition module \"%s\"", id->id_text)); + DefinitionModule++; + nmcount = 0; + DO_DEBUG(1, debug("Definition module \"%s\" %d", + id->id_text, DefinitionModule)); } ';' import(0)* @@ -158,8 +165,9 @@ DefinitionModule df = df->df_nextinscope; } if (!SYSTEMModule) close_scope(SC_CHKFORW); - DefinitionModule = 0; + DefinitionModule--; match_id(id, dot.TOK_IDF); + nmcount = savnmcount; } '.' ; @@ -210,7 +218,6 @@ ProgramModule(int state;) df = GetDefinitionModule(id); CurrentScope = df->mod_scope; DEFofIMPL = 0; - DefinitionModule = 0; } else { df = define(id, CurrentScope, D_MODULE); diff --git a/lang/m2/comp/scope.C b/lang/m2/comp/scope.C index 79ebb5f8..8142ee41 100644 --- a/lang/m2/comp/scope.C +++ b/lang/m2/comp/scope.C @@ -15,6 +15,7 @@ static char *RcsId = "$Header$"; #include "debug.h" struct scope *CurrentScope, *PervasiveScope, *GlobalScope; +static int scp_level; /* STATICALLOCDEF "scope" */ @@ -26,6 +27,7 @@ open_scope(scopetype) assert(scopetype == OPENSCOPE || scopetype == CLOSEDSCOPE); sc->sc_scopeclosed = scopetype == CLOSEDSCOPE; + sc->sc_level = scp_level++; sc->sc_forw = 0; sc->sc_def = 0; sc->sc_off = 0; @@ -45,6 +47,7 @@ init_scope() sc->sc_scopeclosed = 0; sc->sc_forw = 0; sc->sc_def = 0; + sc->sc_level = scp_level++; sc->next = 0; PervasiveScope = sc; CurrentScope = sc; @@ -197,6 +200,7 @@ close_scope(flag) Reverse(&(sc->sc_def)); } CurrentScope = sc->next; + scp_level = CurrentScope->sc_level; } #ifdef DEBUG diff --git a/lang/m2/comp/scope.h b/lang/m2/comp/scope.h index 3dc7b441..e2611f3d 100644 --- a/lang/m2/comp/scope.h +++ b/lang/m2/comp/scope.h @@ -15,9 +15,11 @@ struct scope { struct scope *next; struct forwards *sc_forw; + char *sc_name; /* name of this scope */ struct def *sc_def; /* list of definitions in this scope */ arith sc_off; /* offsets of variables in this scope */ char sc_scopeclosed; /* flag indicating closed or open scope */ + int sc_level; /* level of this scope */ }; extern struct scope diff --git a/lang/m2/comp/type.H b/lang/m2/comp/type.H index c2824a84..f206e6cd 100644 --- a/lang/m2/comp/type.H +++ b/lang/m2/comp/type.H @@ -88,6 +88,7 @@ struct type { extern struct type *bool_type, *char_type, + *charc_type, *int_type, *card_type, *longint_type, diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index 58139999..21e4bb59 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -40,6 +40,7 @@ arith struct type *bool_type, *char_type, + *charc_type, *int_type, *card_type, *longint_type, @@ -134,6 +135,8 @@ init_types() char_type = standard_type(T_CHAR, 1, (arith) 1); char_type->enm_ncst = 256; + charc_type = standard_type(T_CHAR, 1, (arith) 1); + charc_type->enm_ncst = 256; bool_type = standard_type(T_ENUMERATION, 1, (arith) 1); bool_type->enm_ncst = 2; int_type = standard_type(T_INTEGER, int_align, int_size); diff --git a/lang/m2/comp/typequiv.c b/lang/m2/comp/typequiv.c index 7fef0927..603d35fe 100644 --- a/lang/m2/comp/typequiv.c +++ b/lang/m2/comp/typequiv.c @@ -111,3 +111,27 @@ TstCompat(tp1, tp2) ) ; } + +int TstAssCompat(tp1, tp2) + struct type *tp1, *tp2; +{ + /* Test if two types are assignment compatible. + */ + if (TstCompat(tp1, tp2)) return 1; + + if (tp1->tp_fund == T_SUBRANGE) tp1 = tp1->next; + if (tp2->tp_fund == T_SUBRANGE) tp2 = tp2->next; + if ((tp1->tp_fund & (T_INTEGER|T_CARDINAL)) && + (tp2->tp_fund & (T_INTEGER|T_CARDINAL))) return 1; + if (tp1 == char_type && tp2 == charc_type) return 1; + if (tp1->tp_fund == T_ARRAY && + (tp2 == charc_type || tp2 == string_type)) { + /* Unfortunately the length of the string is not + available here, so this must be tested somewhere else (???) + */ + tp1 = tp1->arr_elem; + if (tp1->tp_fund == T_SUBRANGE) tp1 = tp1->next; + return tp1 == char_type; + } + return 0; +} From 23532d6fb4462887003336c9ba4d5259e0cd6448 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 21 Apr 1986 17:27:06 +0000 Subject: [PATCH 0182/1625] newer version --- lang/m2/comp/Makefile | 9 +-- lang/m2/comp/declar.g | 66 +++++++----------- lang/m2/comp/def.H | 11 ++- lang/m2/comp/def.c | 53 +++++++++++++++ lang/m2/comp/defmodule.c | 3 + lang/m2/comp/enter.c | 36 +++++++--- lang/m2/comp/main.c | 37 +++++----- lang/m2/comp/main.h | 4 ++ lang/m2/comp/program.g | 70 +++++++++++-------- lang/m2/comp/scope.C | 17 ++++- lang/m2/comp/walk.c | 142 +++++++++++++++++++++++++++++++++++++++ 11 files changed, 348 insertions(+), 100 deletions(-) create mode 100644 lang/m2/comp/walk.c diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index c342b5e0..6b2a4d73 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -18,7 +18,7 @@ LOBJ = tokenfile.o program.o declar.o expression.o statement.o COBJ = LLlex.o LLmessage.o char.o error.o main.o \ symbol2str.o tokenname.o idf.o input.o type.o def.o \ scope.o misc.o enter.o defmodule.o typequiv.o node.o \ - cstoper.o chk_expr.o options.o + cstoper.o chk_expr.o options.o walk.o OBJ = $(COBJ) $(LOBJ) Lpars.o GENFILES= tokenfile.c \ program.c declar.c expression.c statement.c \ @@ -81,7 +81,7 @@ depend: LLlex.o: LLlex.h Lpars.h class.h const.h f_info.h idf.h idfsize.h input.h inputtype.h numsize.h strsize.h type.h LLmessage.o: LLlex.h Lpars.h idf.h char.o: class.h -error.o: LLlex.h errout.h f_info.h input.h inputtype.h main.h node.h +error.o: LLlex.h debug.h errout.h f_info.h input.h inputtype.h main.h node.h main.o: LLlex.h Lpars.h debug.h def.h f_info.h idf.h input.h inputtype.h scope.h standards.h tokenname.h type.h symbol2str.o: Lpars.h tokenname.o: Lpars.h idf.h tokenname.h @@ -92,15 +92,16 @@ def.o: LLlex.h debug.h def.h idf.h main.h node.h scope.h type.h scope.o: LLlex.h debug.h def.h idf.h node.h scope.h type.h misc.o: LLlex.h f_info.h idf.h misc.h node.h enter.o: LLlex.h def.h idf.h main.h node.h scope.h type.h -defmodule.o: LLlex.h debug.h def.h f_info.h idf.h input.h inputtype.h scope.h +defmodule.o: LLlex.h debug.h def.h f_info.h idf.h input.h inputtype.h main.h scope.h typequiv.o: def.h type.h node.o: LLlex.h debug.h def.h node.h type.h cstoper.o: LLlex.h Lpars.h idf.h node.h standards.h target_sizes.h type.h chk_expr.o: LLlex.h Lpars.h const.h debug.h def.h idf.h node.h scope.h standards.h type.h options.o: idfsize.h type.h +walk.o: debug.h def.h main.h scope.h type.h tokenfile.o: Lpars.h program.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h type.h -declar.o: LLlex.h Lpars.h def.h idf.h misc.h node.h scope.h type.h +declar.o: LLlex.h Lpars.h def.h idf.h main.h misc.h node.h scope.h type.h expression.o: LLlex.h Lpars.h const.h debug.h def.h idf.h node.h scope.h type.h statement.o: LLlex.h Lpars.h node.h type.h Lpars.o: Lpars.h diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 173104d2..e28df724 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -16,25 +16,22 @@ static char *RcsId = "$Header$"; #include "misc.h" #include "main.h" -static int proclevel = 0; /* nesting level of procedures */ -char * sprint(); +int proclevel = 0; /* nesting level of procedures */ +extern char *sprint(); } ProcedureDeclaration { struct def *df; - char buf[256]; } : ProcedureHeading(&df, D_PROCEDURE) - { df->prc_level = proclevel++; - if (DefinitionModule) { - C_exp(sprint(buf, "%s_%s", - df->df_scope->sc_name, - df->df_idf->id_text)); - } + { + df->prc_level = proclevel++; + } ';' block(&(df->prc_body)) IDENT - { match_id(dot.TOK_IDF, df->df_idf); + { + match_id(dot.TOK_IDF, df->df_idf); df->prc_scope = CurrentScope; close_scope(SC_CHKFORW); proclevel--; @@ -44,34 +41,22 @@ ProcedureDeclaration ProcedureHeading(struct def **pdf; int type;) { struct type *tp = 0; - struct type *tp1 = 0; struct paramlist *params = 0; register struct def *df; + struct def *DeclProc(); } : PROCEDURE IDENT - { assert(type & (D_PROCEDURE | D_PROCHEAD)); - if (type == D_PROCHEAD) { - df = define(dot.TOK_IDF, CurrentScope, type); - df->for_node = MkNode(Name, NULLNODE, NULLNODE, &dot); - } - else { - df = lookup(dot.TOK_IDF, CurrentScope); - if (df && df->df_kind == D_PROCHEAD) { - df->df_kind = type; - tp1 = df->df_type; - } - else df = define(dot.TOK_IDF, CurrentScope, type); - df->prc_nbpar = 0; - open_scope(OPENSCOPE); - } + { + df = DeclProc(type); } FormalParameters(type == D_PROCEDURE, ¶ms, &tp, &(df->prc_nbpar))? { - df->df_type = tp = construct_type(T_PROCEDURE, tp); + tp = construct_type(T_PROCEDURE, tp); tp->prc_params = params; - if (tp1 && !TstTypeEquiv(tp, tp1)) { + if (df->df_type && !TstTypeEquiv(tp, df->df_type)) { error("inconsistent procedure declaration for \"%s\"", df->df_idf->id_text); } + df->df_type = tp; *pdf = df; } ; @@ -120,7 +105,8 @@ FormalParameters(int doparams; ]? ')' { *tp = 0; } - [ ':' qualident(D_TYPE|D_HTYPE|D_HIDDEN, &df, "type", (struct node **) 0) + [ ':' qualident(D_TYPE|D_HTYPE|D_HIDDEN, &df, "type", + (struct node **) 0) { *tp = df->df_type; } ]? ; @@ -160,15 +146,15 @@ FormalType(struct type **tp;) [ ARRAY OF { ARRAYflag = 1; } ]? qualident(D_TYPE|D_HTYPE|D_HIDDEN, &df, "type", (struct node **) 0) - { if (ARRAYflag) { - *tp = construct_type(T_ARRAY, NULLTYPE); - (*tp)->arr_elem = df->df_type; - (*tp)->tp_align = lcm(word_align, pointer_align); - (*tp)->tp_size = align(pointer_size + 3*word_size, - (*tp)->tp_align); - } - else *tp = df->df_type; - } + { if (ARRAYflag) { + *tp = construct_type(T_ARRAY, NULLTYPE); + (*tp)->arr_elem = df->df_type; + (*tp)->tp_align = lcm(word_align, pointer_align); + (*tp)->tp_size = align(pointer_size + word_size, + (*tp)->tp_align); + } + else *tp = df->df_type; + } ; TypeDeclaration @@ -188,7 +174,6 @@ TypeDeclaration tp->tp_fund != T_POINTER) { error("Opaque type \"%s\" is not a pointer type", df->df_idf->id_text); } - } ; @@ -244,6 +229,7 @@ enumeration(struct type **ptp;) error("Too many enumeration literals"); } else { + /* ??? This is crummy */ (*ptp)->tp_size = word_size; (*ptp)->tp_align = word_align; } @@ -392,7 +378,7 @@ FieldList(struct scope *scope; arith *cnt; int *palign;) { max = tcnt; tcnt = *cnt; } [ '|' variant(scope, &tcnt, tp, palign) - { if (tcnt > max) max = tcnt; } + { if (tcnt > max) max = tcnt; tcnt = *cnt; } ]* [ ELSE FieldListSequence(scope, &tcnt, palign) { if (tcnt > max) max = tcnt; } diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H index e208653c..7ae10546 100644 --- a/lang/m2/comp/def.H +++ b/lang/m2/comp/def.H @@ -6,18 +6,22 @@ struct module { arith mo_priority; /* priority of a module */ struct scope *mo_scope; /* scope of this module */ struct node *mo_body; /* body of this module */ + int mo_number; /* number of this module */ #define mod_priority df_value.df_module.mo_priority #define mod_scope df_value.df_module.mo_scope #define mod_body df_value.df_module.mo_body +#define mod_number df_value.df_module.mo_number }; struct variable { arith va_off; /* address or offset of variable */ + char *va_name; /* name of variable if given */ char va_addrgiven; /* an address was given in the program */ char va_noreg; /* may not be in a register */ short va_number; /* number of this variable in definition module */ #define var_off df_value.df_variable.va_off +#define var_name df_value.df_variable.va_name #define var_addrgiven df_value.df_variable.va_addrgiven #define var_noreg df_value.df_variable.va_noreg #define var_number df_value.df_variable.va_number @@ -49,15 +53,14 @@ struct field { struct dfproc { struct scope *pr_scope; /* scope of procedure */ short pr_level; /* depth level of this procedure */ - short pr_number; /* number of this procedure in definition module - */ + char *pr_name; /* name of this procedure */ arith pr_nbpar; /* number of bytes parameters */ struct node *pr_body; /* body of this procedure */ #define prc_scope df_value.df_proc.pr_scope #define prc_level df_value.df_proc.pr_level #define prc_nbpar df_value.df_proc.pr_nbpar #define prc_body df_value.df_proc.pr_body -#define prc_number df_value.df_proc.pr_number +#define prc_name df_value.df_proc.pr_name }; struct import { @@ -68,8 +71,10 @@ struct import { struct dforward { struct scope *fo_scope; struct node *fo_node; + char *fo_name; #define for_node df_value.df_forward.fo_node #define for_scope df_value.df_forward.fo_scope +#define for_name df_value.df_forward.fo_name }; struct def { /* list of definitions for a name */ diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index 809bb5ed..c6f49f06 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -6,6 +6,7 @@ static char *RcsId = "$Header$"; #include #include #include + #include "main.h" #include "def.h" #include "type.h" @@ -13,6 +14,7 @@ static char *RcsId = "$Header$"; #include "scope.h" #include "LLlex.h" #include "node.h" + #include "debug.h" struct def *h_def; /* Pointer to free list of def structures */ @@ -77,6 +79,7 @@ define(id, scope, kind) already seen in a definition module */ df->df_kind = kind; + df->prc_name = df->for_name; return df; } break; @@ -391,6 +394,56 @@ RemFromId(df) } } +struct def * +DeclProc(type) +{ + /* A procedure is declared, either in a definition or a program + module. Create a def structure for it (if neccessary) + */ + register struct def *df; + extern char *sprint(), *Malloc(), *strcpy(); + static int nmcount = 0; + char buf[256]; + + assert(type & (D_PROCEDURE | D_PROCHEAD)); + + if (type == D_PROCHEAD) { + /* In a definition module + */ + df = define(dot.TOK_IDF, CurrentScope, type); + df->for_node = MkNode(Name, NULLNODE, NULLNODE, &dot); + sprint(buf,"%s_%s",CurrentScope->sc_name,df->df_idf->id_text); + df->for_name = Malloc((unsigned) (strlen(buf)+1)); + strcpy(df->for_name, buf); + C_exp(df->for_name); + } + else { + df = lookup(dot.TOK_IDF, CurrentScope); + if (df && df->df_kind == D_PROCHEAD) { + /* C_exp already generated when we saw the definition + in the definition module + */ + df->df_kind = type; + } + else { + df = define(dot.TOK_IDF, CurrentScope, type); + if (CurrentScope != Defined->mod_scope) { + sprint(buf, "_%d_%s", ++nmcount, + df->df_idf->id_text); + } + else (sprint(buf, "%s_%s",df->df_scope->sc_name, + df->df_idf->id_text)); + df->prc_name = Malloc((unsigned)(strlen(buf)+1)); + strcpy(df->prc_name, buf); + C_inp(buf); + } + df->prc_nbpar = 0; + open_scope(OPENSCOPE); + } + + return df; +} + #ifdef DEBUG PrDef(df) register struct def *df; diff --git a/lang/m2/comp/defmodule.c b/lang/m2/comp/defmodule.c index 7a261113..808ff845 100644 --- a/lang/m2/comp/defmodule.c +++ b/lang/m2/comp/defmodule.c @@ -5,12 +5,15 @@ static char *RcsId = "$Header$"; #include #include #include + #include "idf.h" #include "input.h" #include "scope.h" #include "def.h" #include "LLlex.h" #include "f_info.h" +#include "main.h" + #include "debug.h" #ifdef DEBUG diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index 76fbc32a..36e36320 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -96,14 +96,21 @@ EnterVarList(IdList, type, local) register struct node *IdList; struct type *type; { + /* Enter a list of identifiers representing variables into the + name list. "type" represents the type of the variables. + "local" is set if the variables are declared local to a + procedure + */ register struct def *df; - struct scope *scope; + register struct scope *scope; + char buf[256]; + extern char *sprint(), *Malloc(), *strcpy(); + scope = CurrentScope; if (local) { /* Find the closest enclosing open scope. This is the procedure that we are dealing with */ - scope = CurrentScope; while (scope->sc_scopeclosed) scope = scope->next; } @@ -111,6 +118,8 @@ EnterVarList(IdList, type, local) df = define(IdList->nd_IDF, CurrentScope, D_VARIABLE); df->df_type = type; if (IdList->nd_left) { + /* An address was supplied + */ df->var_addrgiven = 1; if (IdList->nd_left->nd_type != card_type) { node_error(IdList->nd_left,"Illegal type for address"); @@ -127,12 +136,23 @@ node_error(IdList->nd_left,"Illegal type for address"); df->var_off = off; scope->sc_off = off; } - else if (DefinitionModule) { - char buf[256]; - char *sprint(); - - C_exa_dnam(sprint(buf,"%s_%s",df->df_scope->sc_name, - df->df_idf->id_text)); + else if (!DefinitionModule && + CurrentScope != Defined->mod_scope) { + scope->sc_off = align(scope->sc_off, type->tp_align); + df->var_off = scope->sc_off; + scope->sc_off += type->tp_size; + } + else { + sprint(buf,"%s_%s", df->df_scope->sc_name, + df->df_idf->id_text); + df->var_name = Malloc((unsigned)(strlen(buf)+1)); + strcpy(df->var_name, buf); + if (DefinitionModule) { + C_exa_dnam(df->var_name); + } + else { + C_ina_dnam(df->var_name); + } } IdList = IdList->nd_right; } diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index 491d9f81..cc69c3ea 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -5,18 +5,20 @@ static char *RcsId = "$Header$"; #include #include #include + #include "input.h" #include "f_info.h" #include "idf.h" #include "LLlex.h" #include "Lpars.h" -#include "debug.h" #include "type.h" #include "def.h" #include "scope.h" #include "standards.h" #include "tokenname.h" +#include "debug.h" + char options[128]; int DefinitionModule; int SYSTEMModule = 0; @@ -24,6 +26,7 @@ char *ProgName; extern int err_occurred; char *DEFPATH[128]; char *getenv(); +struct def *Defined; main(argc, argv) char *argv[]; @@ -45,7 +48,6 @@ main(argc, argv) return 1; } #ifdef DEBUG - print("MODULA-2 compiler -- Debug version\n"); DO_DEBUG(1, debug("Debugging level: %d", options['D'])); #endif DEBUG return !Compile(Nargv[1], Nargv[2]); @@ -72,20 +74,25 @@ Compile(src, dst) init_types(); add_standards(); #ifdef DEBUG - if (options['l']) LexScan(); - else -#endif DEBUG - { - (void) open_scope(CLOSEDSCOPE); - GlobalScope = CurrentScope; - C_init(word_size, pointer_size); - if (! C_open(dst)) { - fatal("Could not open output file"); - } - C_magic(); - C_ms_emx(word_size, pointer_size); - CompUnit(); + if (options['l']) { + LexScan(); + return 1; } +#endif DEBUG + (void) open_scope(CLOSEDSCOPE); + GlobalScope = CurrentScope; + C_init(word_size, pointer_size); + if (! C_open(dst)) { + fatal("Could not open output file"); + } + C_magic(); + C_ms_emx(word_size, pointer_size); + CompUnit(); + if (err_occurred) { + C_close(); + return 0; + } + WalkModule(Defined); C_close(); if (err_occurred) return 0; return 1; diff --git a/lang/m2/comp/main.h b/lang/m2/comp/main.h index fd4502be..04ca4ed6 100644 --- a/lang/m2/comp/main.h +++ b/lang/m2/comp/main.h @@ -12,3 +12,7 @@ extern int DefinitionModule; extern int SYSTEMModule;/* Flag indicating that we are handling the SYSTEM module */ +extern struct def *Defined; + /* Definition structure of module defined in this + compilation + */ diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index a2c066c9..1e747084 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -6,6 +6,7 @@ static char *RcsId = "$Header$"; #include #include #include + #include "main.h" #include "idf.h" #include "LLlex.h" @@ -13,6 +14,7 @@ static char *RcsId = "$Header$"; #include "def.h" #include "type.h" #include "node.h" + #include "debug.h" static int DEFofIMPL = 0; /* Flag indicating that we are currently @@ -20,9 +22,6 @@ static int DEFofIMPL = 0; /* Flag indicating that we are currently implementation module currently being compiled */ -short nmcount = 0; /* count names in definition modules in order - to create suitable names in the object code - */ } /* The grammar as given by Wirth is already almost LL(1); the @@ -47,27 +46,37 @@ ModuleDeclaration { struct idf *id; register struct def *df; + extern int proclevel; + static int modulecount = 0; + char buf[256]; + extern char *sprint(), *Malloc(), *strcpy(); } : - MODULE IDENT { - id = dot.TOK_IDF; - df = define(id, CurrentScope, D_MODULE); - if (!df->mod_scope) { - open_scope(CLOSEDSCOPE); - df->mod_scope = CurrentScope; - } - else CurrentScope = df->mod_scope; - df->df_type = - standard_type(T_RECORD, 0, (arith) 0); - df->df_type->rec_scope = df->mod_scope; - } + MODULE IDENT { + id = dot.TOK_IDF; + df = define(id, CurrentScope, D_MODULE); + if (!df->mod_scope) { + open_scope(CLOSEDSCOPE); + df->mod_scope = CurrentScope; + } + else CurrentScope = df->mod_scope; + df->df_type = standard_type(T_RECORD, 0, (arith) 0); + df->df_type->rec_scope = df->mod_scope; + df->mod_number = ++modulecount; + sprint(buf, "__%d%s", df->mod_number, id->id_text); + CurrentScope->sc_name = + Malloc((unsigned) (strlen(buf) + 1)); + strcpy(CurrentScope->sc_name, buf); + C_ina_dnam(&buf[1]); + C_inp(buf); + } priority(&(df->mod_priority))? ';' import(1)* export(0)? block(&(df->mod_body)) - IDENT { close_scope(SC_CHKFORW|SC_CHKPROC); - match_id(id, dot.TOK_IDF); - } + IDENT { close_scope(SC_CHKFORW|SC_CHKPROC); + match_id(id, dot.TOK_IDF); + } ; priority(arith *pprio;) @@ -75,12 +84,12 @@ priority(arith *pprio;) struct node *nd; } : '[' ConstExpression(&nd) ']' - { if (!(nd->nd_type->tp_fund & T_INTORCARD)) { - node_error(nd, "Illegal priority"); - } - *pprio = nd->nd_INT; - FreeNode(nd); - } + { if (!(nd->nd_type->tp_fund & T_INTORCARD)) { + node_error(nd, "Illegal priority"); + } + *pprio = nd->nd_INT; + FreeNode(nd); + } ; export(int def;) @@ -90,7 +99,8 @@ export(int def;) } : EXPORT [ - QUALIFIED { QUALflag = 1; } + QUALIFIED + { QUALflag = 1; } ]? IdentList(&ExportList) ';' { @@ -128,18 +138,19 @@ DefinitionModule { register struct def *df; struct idf *id; - int savnmcount = nmcount; } : DEFINITION - MODULE IDENT { id = dot.TOK_IDF; + MODULE IDENT { + id = dot.TOK_IDF; df = define(id, GlobalScope, D_MODULE); if (!SYSTEMModule) open_scope(CLOSEDSCOPE); + if (!Defined) Defined = df; df->mod_scope = CurrentScope; + df->mod_number = 0; CurrentScope->sc_name = id->id_text; df->df_type = standard_type(T_RECORD, 0, (arith) 0); df->df_type->rec_scope = df->mod_scope; DefinitionModule++; - nmcount = 0; DO_DEBUG(1, debug("Definition module \"%s\" %d", id->id_text, DefinitionModule)); } @@ -167,7 +178,6 @@ DefinitionModule if (!SYSTEMModule) close_scope(SC_CHKFORW); DefinitionModule--; match_id(id, dot.TOK_IDF); - nmcount = savnmcount; } '.' ; @@ -221,8 +231,10 @@ ProgramModule(int state;) } else { df = define(id, CurrentScope, D_MODULE); + Defined = df; open_scope(CLOSEDSCOPE); df->mod_scope = CurrentScope; + df->mod_number = 0; } } priority(&(df->mod_priority))? diff --git a/lang/m2/comp/scope.C b/lang/m2/comp/scope.C index 8142ee41..4a448c7e 100644 --- a/lang/m2/comp/scope.C +++ b/lang/m2/comp/scope.C @@ -168,16 +168,31 @@ Reverse(pdf) { /* Reverse the order in the list of definitions in a scope. This is neccesary because this list is built in reverse. + Also, while we're at it, remove uninteresting definitions + from this list. The only interesting definitions are: + D_MODULE, D_PROCEDURE, and D_PROCHEAD. */ register struct def *df, *df1; +#define INTERESTING D_MODULE|D_PROCEDURE|D_PROCHEAD df = 0; df1 = *pdf; while (df1) { + if (df1->df_kind & INTERESTING) break; df1 = df1->df_nextinscope; + } + + if (!(*pdf = df1)) return; + + while (df1) { + *pdf = df1; + df1 = df1->df_nextinscope; + while (df1) { + if (df1->df_kind & INTERESTING) break; + df1 = df1->df_nextinscope; + } (*pdf)->df_nextinscope = df; df = *pdf; - *pdf = df1; } } diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c new file mode 100644 index 00000000..d23bbdf0 --- /dev/null +++ b/lang/m2/comp/walk.c @@ -0,0 +1,142 @@ +/* P A R S E T R E E W A L K E R */ + +static char *RcsId = "$Header$"; + +/* Routines to walk through parts of the parse tree, and generate + code for these parts. +*/ + +#include +#include +#include + +#include "def.h" +#include "type.h" +#include "scope.h" +#include "main.h" +#include "LLlex.h" +#include "node.h" + +#include "debug.h" + +extern arith align(); +static int prclev = 0; + +WalkModule(module) + register struct def *module; +{ + /* Walk through a module, and all its local definitions. + Also generate code for its body. + */ + register struct def *df = module->mod_scope->sc_def; + struct scope *scope; + + scope = CurrentScope; + CurrentScope = module->mod_scope; + if (!prclev && module->mod_number) { + /* This module is a local module, but not within a + procedure. Generate code to allocate storage for its + variables + */ + arith size = align(CurrentScope->sc_off, word_size); + + if (size == 0) size = word_size; + C_df_dnam(&(CurrentScope->sc_name[1])); + C_bss_cst(size, (arith) 0, 0); + } + else if (CurrentScope == Defined->mod_scope) { + /* This module is the module currently being compiled. + Again, generate code to allocate storage for its + variables, which all have an explicit name. + */ + while (df) { + if (df->df_kind == D_VARIABLE) { + C_df_dnam(df->var_name); + C_bss_cst(df->df_type->tp_size, (arith) 0, 0); + } + df = df->df_nextinscope; + } + } + + /* Now, walk through it's local definitions + */ + WalkDef(CurrentScope->sc_def); + + /* Now, generate initialization code for this module. + First call initialization routines for modules defined within + this module. + */ + CurrentScope->sc_off = 0; + C_pro_narg(CurrentScope->sc_name); + MkCalls(CurrentScope->sc_def); + WalkNode(module->mod_body); + C_end(align(-CurrentScope->sc_off, word_size)); + + CurrentScope = scope; +} + +WalkProcedure(procedure) + struct def *procedure; +{ + /* Walk through the definition of a procedure and all its + local definitions + */ + struct scope *scope = CurrentScope; + register struct def *df; + + prclev++; + CurrentScope = procedure->prc_scope; + + WalkDef(CurrentScope->sc_def); + + /* Generate code for this procedure + */ + C_pro_narg(procedure->prc_name); + /* generate calls to initialization routines of modules defined within + this procedure + */ + MkCalls(CurrentScope->sc_def); + WalkNode(procedure->prc_body); + C_end(align(-CurrentScope->sc_off, word_size)); + CurrentScope = scope; + prclev--; +} + +WalkDef(df) + register struct def *df; +{ + /* Walk through a list of definitions + */ + while (df) { + if (df->df_kind == D_MODULE) { + WalkModule(df); + } + else if (df->df_kind == D_PROCEDURE) { + WalkProcedure(df); + } + df = df->df_nextinscope; + } +} + +MkCalls(df) + register struct def *df; +{ + /* Generate calls to initialization routines of modules + */ + while (df) { + if (df->df_kind == D_MODULE) { + C_lxl((arith) 0); + C_cal(df->df_scope->sc_name); + } + df = df->df_nextinscope; + } +} + +WalkNode(nd) + struct node *nd; +{ + /* Node "nd" represents either a statement or a statement list. + Generate code for it. + */ + /* ??? */ +} From 4a2d866fb0e34288337cd2c7af5235fbcfaf2328 Mon Sep 17 00:00:00 2001 From: keie Date: Tue, 22 Apr 1986 10:40:29 +0000 Subject: [PATCH 0183/1625] Added EODDZ to the exported externals. It should have been there from the start. --- mach/i86/libsys/head_em.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/i86/libsys/head_em.s b/mach/i86/libsys/head_em.s index fd45fde9..d421e79b 100644 --- a/mach/i86/libsys/head_em.s +++ b/mach/i86/libsys/head_em.s @@ -1,6 +1,6 @@ .define begtext,begdata,begbss .define hol0,.reghp,.limhp,.trppc,.ignmask -.define ERANGE,ESET,EHEAP,ECASE,EILLINS +.define ERANGE,ESET,EHEAP,ECASE,EILLINS,EODDZ ERANGE = 1 ESET = 2 From a46f20bff7e3926fc776bbcd169f9ac185c4a6a7 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 22 Apr 1986 22:36:16 +0000 Subject: [PATCH 0184/1625] newer version --- lang/m2/comp/LLlex.c | 6 +- lang/m2/comp/LLlex.h | 6 +- lang/m2/comp/Makefile | 8 +- lang/m2/comp/Parameters | 6 ++ lang/m2/comp/chk_expr.c | 67 +++++++++++----- lang/m2/comp/cstoper.c | 9 ++- lang/m2/comp/declar.g | 23 ++++-- lang/m2/comp/def.H | 2 - lang/m2/comp/def.c | 23 +++--- lang/m2/comp/enter.c | 20 +++-- lang/m2/comp/expression.g | 2 +- lang/m2/comp/main.c | 8 +- lang/m2/comp/program.g | 12 ++- lang/m2/comp/scope.C | 4 +- lang/m2/comp/scope.h | 3 + lang/m2/comp/statement.g | 13 +++- lang/m2/comp/type.c | 122 ++++++++++++++++++++++------- lang/m2/comp/typequiv.c | 51 ++++++++----- lang/m2/comp/walk.c | 156 ++++++++++++++++++++++++++++++++++++-- 19 files changed, 420 insertions(+), 121 deletions(-) diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index 1cf3c387..a252b606 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -182,7 +182,7 @@ again: } else if (nch == '>') { - return tk->tk_symb = UNEQUAL; + return tk->tk_symb = '#'; } PushBack(nch); return tk->tk_symb = ch; @@ -219,7 +219,9 @@ again: case STSTR: GetString(ch); - tk->tk_data.tk_str = string; + tk->tk_data.tk_str = (struct string *) + Malloc(sizeof (struct string)); + *(tk->tk_data.tk_str) = string; return tk->tk_symb = STRING; case STNUM: diff --git a/lang/m2/comp/LLlex.h b/lang/m2/comp/LLlex.h index 16ea9e01..69573dd0 100644 --- a/lang/m2/comp/LLlex.h +++ b/lang/m2/comp/LLlex.h @@ -13,7 +13,7 @@ struct token { int tk_lineno; /* linenumber on which it occurred */ union { struct idf *tk_idf; /* IDENT */ - struct string tk_str; /* STRING */ + struct string *tk_str; /* STRING */ arith tk_int; /* INTEGER */ char *tk_real; /* REAL */ arith *tk_set; /* only used in parse tree node */ @@ -22,8 +22,8 @@ struct token { }; #define TOK_IDF tk_data.tk_idf -#define TOK_STR tk_data.tk_str.s_str -#define TOK_SLE tk_data.tk_str.s_length +#define TOK_STR tk_data.tk_str->s_str +#define TOK_SLE tk_data.tk_str->s_length #define TOK_INT tk_data.tk_int #define TOK_REL tk_data.tk_real diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index 6b2a4d73..70815858 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -82,12 +82,12 @@ LLlex.o: LLlex.h Lpars.h class.h const.h f_info.h idf.h idfsize.h input.h inputt LLmessage.o: LLlex.h Lpars.h idf.h char.o: class.h error.o: LLlex.h debug.h errout.h f_info.h input.h inputtype.h main.h node.h -main.o: LLlex.h Lpars.h debug.h def.h f_info.h idf.h input.h inputtype.h scope.h standards.h tokenname.h type.h +main.o: LLlex.h Lpars.h debug.h def.h f_info.h idf.h input.h inputtype.h node.h scope.h standards.h tokenname.h type.h symbol2str.o: Lpars.h tokenname.o: Lpars.h idf.h tokenname.h idf.o: idf.h input.o: f_info.h input.h inputtype.h -type.o: LLlex.h const.h debug.h def.h idf.h node.h target_sizes.h type.h +type.o: LLlex.h const.h debug.h def.h idf.h maxset.h node.h target_sizes.h type.h def.o: LLlex.h debug.h def.h idf.h main.h node.h scope.h type.h scope.o: LLlex.h debug.h def.h idf.h node.h scope.h type.h misc.o: LLlex.h f_info.h idf.h misc.h node.h @@ -98,10 +98,10 @@ node.o: LLlex.h debug.h def.h node.h type.h cstoper.o: LLlex.h Lpars.h idf.h node.h standards.h target_sizes.h type.h chk_expr.o: LLlex.h Lpars.h const.h debug.h def.h idf.h node.h scope.h standards.h type.h options.o: idfsize.h type.h -walk.o: debug.h def.h main.h scope.h type.h +walk.o: LLlex.h Lpars.h debug.h def.h main.h node.h scope.h type.h tokenfile.o: Lpars.h program.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h type.h declar.o: LLlex.h Lpars.h def.h idf.h main.h misc.h node.h scope.h type.h expression.o: LLlex.h Lpars.h const.h debug.h def.h idf.h node.h scope.h type.h -statement.o: LLlex.h Lpars.h node.h type.h +statement.o: LLlex.h Lpars.h def.h idf.h node.h scope.h type.h Lpars.o: Lpars.h diff --git a/lang/m2/comp/Parameters b/lang/m2/comp/Parameters index f49d2aad..fcdfc05c 100644 --- a/lang/m2/comp/Parameters +++ b/lang/m2/comp/Parameters @@ -58,3 +58,9 @@ extern char options[]; #undef INP_READ_IN_ONE 1 /* read input file in one */ +!File: maxset.h +#define MAXSET 1024 /* maximum number of elements in a set, + but what is a reasonable choice ??? + */ + + diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index 6c950e5b..bf9c58c3 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -63,6 +63,7 @@ chk_expr(expp) case Link: return chk_name(expp); + default: assert(0); } @@ -85,32 +86,42 @@ chk_set(expp) /* First determine the type of the set */ - if (expp->nd_left) { + if (nd = expp->nd_left) { /* A type was given. Check it out */ - findname(expp->nd_left); - assert(expp->nd_left->nd_class == Def); - df = expp->nd_left->nd_def; + findname(nd); + assert(nd->nd_class == Def); + df = nd->nd_def; + if (!(df->df_kind & (D_TYPE|D_ERROR)) || (df->df_type->tp_fund != T_SET)) { - node_error(expp, "illegal set type"); + node_error(expp, "specifier does not represent a set type"); return 0; } tp = df->df_type; + FreeNode(expp->nd_left); + expp->nd_left = 0; } else tp = bitset_type; /* Now check the elements given, and try to compute a constant set. + First allocate room for the set */ set = (arith *) Malloc((unsigned) (tp->tp_size * sizeof(arith) / word_size)); + + /* Now check the elements, one by one + */ nd = expp->nd_right; while (nd) { assert(nd->nd_class == Link && nd->nd_symb == ','); + if (!chk_el(nd->nd_left, tp->next, &set)) return 0; nd = nd->nd_right; } + expp->nd_type = tp; + if (set) { /* Yes, it was a constant set, and we managed to compute it! Notice that at the moment there is no such thing as @@ -119,10 +130,10 @@ chk_set(expp) */ expp->nd_class = Set; expp->nd_set = set; - FreeNode(expp->nd_left); FreeNode(expp->nd_right); - expp->nd_left = expp->nd_right = 0; + expp->nd_right = 0; } + return 1; } @@ -137,35 +148,38 @@ chk_el(expp, tp, set) Also try to compute the set! */ register int i; + register struct node *left = expp->nd_left; + register struct node *right = expp->nd_right; if (expp->nd_class == Link && expp->nd_symb == UPTO) { /* { ... , expr1 .. expr2, ... } First check expr1 and expr2, and try to compute them. */ - if (!chk_el(expp->nd_left, tp, set) || - !chk_el(expp->nd_right, tp, set)) { + if (!chk_el(left, tp, set) || !chk_el(right, tp, set)) { return 0; } - if (expp->nd_left->nd_class == Value && - expp->nd_right->nd_class == Value) { + + if (left->nd_class == Value && right->nd_class == Value) { /* We have a constant range. Put all elements in the set */ - if (expp->nd_left->nd_INT > expp->nd_right->nd_INT) { + if (left->nd_INT > right->nd_INT) { node_error(expp, "lower bound exceeds upper bound in range"); return rem_set(set); } - - if (*set) for (i = expp->nd_left->nd_INT + 1; - i < expp->nd_right->nd_INT; i++) { - (*set)[i/wrd_bits] |= (1 << (i % wrd_bits)); + + if (*set) { + for (i=left->nd_INT+1; ind_INT; i++) { + (*set)[i/wrd_bits] |= (1<<(i%wrd_bits)); + } } } else if (*set) { free((char *) *set); *set = 0; } + return 1; } @@ -174,12 +188,17 @@ node_error(expp, "lower bound exceeds upper bound in range"); if (!chk_expr(expp)) { return rem_set(set); } + if (!TstCompat(tp, expp->nd_type)) { node_error(expp, "set element has incompatible type"); return rem_set(set); } + if (expp->nd_class == Value) { + /* a constant element + */ i = expp->nd_INT; + if ((tp->tp_fund != T_ENUMERATION && (i < tp->sub_lb || i > tp->sub_ub)) || @@ -189,8 +208,10 @@ node_error(expp, "lower bound exceeds upper bound in range"); node_error(expp, "set element out of range"); return rem_set(set); } + if (*set) (*set)[i/wrd_bits] |= (1 << (i%wrd_bits)); } + return 1; } @@ -552,7 +573,7 @@ findname(expp) expp->nd_type = df->df_type; if (!(df->df_flags & (D_EXPORTED|D_QEXPORTED))) { node_error(expp->nd_right, -"identifier \"%s\" not exprted from qualifying module", +"identifier \"%s\" not exported from qualifying module", df->df_idf->id_text); } } @@ -723,6 +744,7 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R case OR: case AND: + case '&': if (tpl == bool_type) { if (expp->nd_left->nd_class == Value && expp->nd_right->nd_class == Value) { @@ -735,10 +757,12 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R case '=': case '#': + case UNEQUAL: case GREATEREQUAL: case LESSEQUAL: case '<': case '>': + expp->nd_type = bool_type; switch(tpl->tp_fund) { case T_SET: if (expp->nd_symb == '<' || expp->nd_symb == '>') { @@ -762,10 +786,10 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R return 1; case T_POINTER: - if (!(expp->nd_symb == '=' || expp->nd_symb == '#')) { - break; - } - /* Fall through */ + if (expp->nd_symb == '=' || + expp->nd_symb == UNEQUAL || + expp->nd_symb == '#') return 1; + break; case T_REAL: return 1; @@ -832,6 +856,7 @@ chk_uoper(expp) break; case NOT: + case '~': if (tpr == bool_type) { if (expp->nd_right->nd_class == Value) { cstunary(expp); diff --git a/lang/m2/comp/cstoper.c b/lang/m2/comp/cstoper.c index be2ba576..8a671aa0 100644 --- a/lang/m2/comp/cstoper.c +++ b/lang/m2/comp/cstoper.c @@ -38,6 +38,7 @@ cstunary(expp) o1 = -o1; break; case NOT: + case '~': o1 = !o1; break; default: @@ -184,9 +185,11 @@ cstbin(expp) o1 = o1 == o2; break; case '#': + case UNEQUAL: o1 = o1 != o2; break; case AND: + case '&': o1 = o1 && o2; break; case OR: @@ -252,6 +255,7 @@ cstset(expp) case LESSEQUAL: case '=': case '#': + case UNEQUAL: /* Clumsy, but who cares? Nobody writes these things! */ for (j = 0; j < setsize; j++) { switch(expp->nd_symb) { @@ -265,13 +269,14 @@ cstset(expp) continue; case '=': case '#': + case UNEQUAL: if (*set1++ != *set2++) break; continue; } - expp->nd_INT = expp->nd_symb == '#'; + expp->nd_INT = expp->nd_symb != '='; break; } - if (j == setsize) expp->nd_INT = expp->nd_symb != '#'; + if (j == setsize) expp->nd_INT = expp->nd_symb == '='; expp->nd_class = Value; free((char *) expp->nd_left->nd_set); free((char *) expp->nd_right->nd_set); diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index e28df724..b42921fe 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -7,6 +7,7 @@ static char *RcsId = "$Header$"; #include #include #include + #include "idf.h" #include "LLlex.h" #include "def.h" @@ -18,23 +19,26 @@ static char *RcsId = "$Header$"; int proclevel = 0; /* nesting level of procedures */ extern char *sprint(); +extern struct def *currentdef; } ProcedureDeclaration { struct def *df; + struct def *savecurr = currentdef; } : ProcedureHeading(&df, D_PROCEDURE) { df->prc_level = proclevel++; - + currentdef = df; } ';' block(&(df->prc_body)) IDENT { match_id(dot.TOK_IDF, df->df_idf); df->prc_scope = CurrentScope; - close_scope(SC_CHKFORW); + close_scope(SC_CHKFORW|SC_REVERSE); proclevel--; + currentdef = savecurr; } ; @@ -53,8 +57,14 @@ ProcedureHeading(struct def **pdf; int type;) { tp = construct_type(T_PROCEDURE, tp); tp->prc_params = params; - if (df->df_type && !TstTypeEquiv(tp, df->df_type)) { + if (df->df_type) { + /* We already saw a definition of this type + in the definition module. + */ + if (!TstTypeEquiv(tp, df->df_type)) { error("inconsistent procedure declaration for \"%s\"", df->df_idf->id_text); + } + FreeType(df->df_type); } df->df_type = tp; *pdf = df; @@ -164,7 +174,8 @@ TypeDeclaration }: IDENT { df = define(dot.TOK_IDF, CurrentScope, D_TYPE); } '=' type(&tp) - { df->df_type = tp; + { if (df->df_type) free_type(df->df_type); + df->df_type = tp; if ((df->df_flags&D_EXPORTED) && tp->tp_fund == T_ENUMERATION) { exprt_literals(tp->enm_enums, @@ -327,7 +338,8 @@ FieldList(struct scope *scope; arith *cnt; int *palign;) [ IdentList(&FldList) ':' type(&tp) { *palign = lcm(*palign, tp->tp_align); - EnterIdList(FldList, D_FIELD, 0, tp, scope, cnt); + EnterIdList(FldList, D_FIELD, D_QEXPORTED, + tp, scope, cnt); FreeNode(FldList); } | @@ -373,6 +385,7 @@ FieldList(struct scope *scope; arith *cnt; int *palign;) df->df_type = tp; df->fld_off = align(*cnt, tp->tp_align); *cnt = tcnt = df->fld_off + tp->tp_size; + df->df_flags |= D_QEXPORTED; } OF variant(scope, &tcnt, tp, palign) { max = tcnt; tcnt = *cnt; } diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H index 7ae10546..9810bd29 100644 --- a/lang/m2/comp/def.H +++ b/lang/m2/comp/def.H @@ -53,14 +53,12 @@ struct field { struct dfproc { struct scope *pr_scope; /* scope of procedure */ short pr_level; /* depth level of this procedure */ - char *pr_name; /* name of this procedure */ arith pr_nbpar; /* number of bytes parameters */ struct node *pr_body; /* body of this procedure */ #define prc_scope df_value.df_proc.pr_scope #define prc_level df_value.df_proc.pr_level #define prc_nbpar df_value.df_proc.pr_nbpar #define prc_body df_value.df_proc.pr_body -#define prc_name df_value.df_proc.pr_name }; struct import { diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index c6f49f06..460e5397 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -73,16 +73,6 @@ define(id, scope, kind) (df = lookup(id, PervasiveScope))) ) { switch(df->df_kind) { - case D_PROCHEAD: - if (kind == D_PROCEDURE) { - /* Definition of which the heading was - already seen in a definition module - */ - df->df_kind = kind; - df->prc_name = df->for_name; - return df; - } - break; case D_HIDDEN: if (kind == D_TYPE && !DefinitionModule) { df->df_kind = D_HTYPE; @@ -192,6 +182,7 @@ df->df_idf->id_text); exported from a local module! */ df->df_kind = df1->df_kind; + df->df_value.df_forward = df1->df_value.df_forward; df1->df_kind = D_IMPORT; } df1->imp_def = df; @@ -423,7 +414,10 @@ DeclProc(type) /* C_exp already generated when we saw the definition in the definition module */ - df->df_kind = type; + df->df_kind = D_PROCEDURE; + open_scope(OPENSCOPE); + CurrentScope->sc_name = df->for_name; + df->prc_scope = CurrentScope; } else { df = define(dot.TOK_IDF, CurrentScope, type); @@ -433,12 +427,13 @@ DeclProc(type) } else (sprint(buf, "%s_%s",df->df_scope->sc_name, df->df_idf->id_text)); - df->prc_name = Malloc((unsigned)(strlen(buf)+1)); - strcpy(df->prc_name, buf); + open_scope(OPENSCOPE); + df->prc_scope = CurrentScope; + CurrentScope->sc_name = Malloc((unsigned)(strlen(buf)+1)); + strcpy(CurrentScope->sc_name, buf); C_inp(buf); } df->prc_nbpar = 0; - open_scope(OPENSCOPE); } return df; diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index 36e36320..338b1270 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -72,6 +72,7 @@ EnterIdList(idlist, kind, flags, type, scope, addr) } else { assert(kind == D_FIELD); + df->fld_off = off; } } @@ -107,6 +108,7 @@ EnterVarList(IdList, type, local) extern char *sprint(), *Malloc(), *strcpy(); scope = CurrentScope; + if (local) { /* Find the closest enclosing open scope. This is the procedure that we are dealing with @@ -127,22 +129,26 @@ node_error(IdList->nd_left,"Illegal type for address"); df->var_off = IdList->nd_left->nd_INT; } else if (local) { - arith off; - - /* add aligned size of variable to the offset + /* subtract aligned size of variable to the offset, + as the variable list exists only local to a + procedure */ - off = scope->sc_off - type->tp_size; - off = -align(-off, type->tp_align); - df->var_off = off; - scope->sc_off = off; + scope->sc_off = -align(type->tp_size - scope->sc_off, + type->tp_align); + df->var_off = scope->sc_off; } else if (!DefinitionModule && CurrentScope != Defined->mod_scope) { + /* variable list belongs to an internal global + module. Align offset and add size + */ scope->sc_off = align(scope->sc_off, type->tp_align); df->var_off = scope->sc_off; scope->sc_off += type->tp_size; } else { + /* Global name, possibly external + */ sprint(buf,"%s_%s", df->df_scope->sc_name, df->df_idf->id_text); df->var_name = Malloc((unsigned)(strlen(buf)+1)); diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index 69a750c6..25d070c7 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -268,5 +268,5 @@ visible_designator_tail(struct node **pnd;): ]* ']' | - '^' { *pnd = MkNode(Oper, NULLNODE, *pnd, &dot); } + '^' { *pnd = MkNode(Uoper, NULLNODE, *pnd, &dot); } ; diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index cc69c3ea..0c453272 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -16,6 +16,7 @@ static char *RcsId = "$Header$"; #include "scope.h" #include "standards.h" #include "tokenname.h" +#include "node.h" #include "debug.h" @@ -135,6 +136,7 @@ add_standards() { register struct def *df; struct def *Enter(); + static struct node nilnode = { 0, 0, Value, 0, { INTEGER, 0, 0}}; (void) Enter("ABS", D_PROCEDURE, std_type, S_ABS); (void) Enter("CAP", D_PROCEDURE, std_type, S_CAP); @@ -161,7 +163,11 @@ add_standards() (void) Enter("LONGREAL", D_TYPE, longreal_type, 0); (void) Enter("BOOLEAN", D_TYPE, bool_type, 0); (void) Enter("CARDINAL", D_TYPE, card_type, 0); - (void) Enter("NIL", D_CONST, address_type, 0); + df = Enter("NIL", D_CONST, address_type, 0); + df->con_const = &nilnode; + nilnode.nd_INT = 0; + nilnode.nd_type = address_type; + (void) Enter("PROC", D_TYPE, construct_type(T_PROCEDURE, NULLTYPE), diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 1e747084..1d675310 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -22,6 +22,7 @@ static int DEFofIMPL = 0; /* Flag indicating that we are currently implementation module currently being compiled */ +struct def *currentdef; /* current definition of module or procedure */ } /* The grammar as given by Wirth is already almost LL(1); the @@ -46,6 +47,7 @@ ModuleDeclaration { struct idf *id; register struct def *df; + struct def *savecurr = currentdef; extern int proclevel; static int modulecount = 0; char buf[256]; @@ -54,11 +56,14 @@ ModuleDeclaration MODULE IDENT { id = dot.TOK_IDF; df = define(id, CurrentScope, D_MODULE); + currentdef = df; + if (!df->mod_scope) { open_scope(CLOSEDSCOPE); df->mod_scope = CurrentScope; } else CurrentScope = df->mod_scope; + df->df_type = standard_type(T_RECORD, 0, (arith) 0); df->df_type->rec_scope = df->mod_scope; df->mod_number = ++modulecount; @@ -74,8 +79,9 @@ ModuleDeclaration import(1)* export(0)? block(&(df->mod_body)) - IDENT { close_scope(SC_CHKFORW|SC_CHKPROC); + IDENT { close_scope(SC_CHKFORW|SC_CHKPROC|SC_REVERSE); match_id(id, dot.TOK_IDF); + currentdef = savecurr; } ; @@ -198,6 +204,7 @@ definition It is restricted to pointer types. */ { df->df_kind = D_HIDDEN; + df->df_type = construct_type(T_POINTER, NULLTYPE); } ] Semicolon @@ -226,6 +233,7 @@ ProgramModule(int state;) if (state == IMPLEMENTATION) { DEFofIMPL = 1; df = GetDefinitionModule(id); + currentdef = df; CurrentScope = df->mod_scope; DEFofIMPL = 0; } @@ -240,7 +248,7 @@ ProgramModule(int state;) priority(&(df->mod_priority))? ';' import(0)* block(&(df->mod_body)) IDENT - { close_scope(SC_CHKFORW|SC_CHKPROC); + { close_scope(SC_CHKFORW|SC_CHKPROC|SC_REVERSE); match_id(id, dot.TOK_IDF); } '.' diff --git a/lang/m2/comp/scope.C b/lang/m2/comp/scope.C index 4a448c7e..9aad947a 100644 --- a/lang/m2/comp/scope.C +++ b/lang/m2/comp/scope.C @@ -6,12 +6,14 @@ static char *RcsId = "$Header$"; #include #include #include + #include "LLlex.h" #include "idf.h" #include "scope.h" #include "type.h" #include "def.h" #include "node.h" + #include "debug.h" struct scope *CurrentScope, *PervasiveScope, *GlobalScope; @@ -212,7 +214,7 @@ close_scope(flag) DO_DEBUG(2, PrScopeDef(sc->sc_def)); if (flag & SC_CHKPROC) chk_proc(sc->sc_def); if (flag & SC_CHKFORW) chk_forw(&(sc->sc_def)); - Reverse(&(sc->sc_def)); + if (flag & SC_REVERSE) Reverse(&(sc->sc_def)); } CurrentScope = sc->next; scp_level = CurrentScope->sc_level; diff --git a/lang/m2/comp/scope.h b/lang/m2/comp/scope.h index e2611f3d..adddeef5 100644 --- a/lang/m2/comp/scope.h +++ b/lang/m2/comp/scope.h @@ -11,6 +11,9 @@ #define SC_CHKPROC 2 /* Check for forward procedure definitions when closing a scope */ +#define SC_REVERSE 4 /* Reverse list of definitions, to get it + back into original order + */ struct scope { struct scope *next; diff --git a/lang/m2/comp/statement.g b/lang/m2/comp/statement.g index c30e66b3..b80c8cb3 100644 --- a/lang/m2/comp/statement.g +++ b/lang/m2/comp/statement.g @@ -5,11 +5,15 @@ static char *RcsId = "$Header$"; #include #include +#include "idf.h" #include "LLlex.h" +#include "scope.h" +#include "def.h" #include "type.h" #include "node.h" static int loopcount = 0; /* Count nested loops */ +extern struct def *currentdef; } statement(struct node **pnd;) @@ -55,7 +59,7 @@ statement(struct node **pnd;) | EXIT { if (!loopcount) { - error("EXIT not in a LOOP"); +error("EXIT not in a LOOP"); } *pnd = MkNode(Stat, NULLNODE, NULLNODE, &dot); } @@ -63,6 +67,13 @@ statement(struct node **pnd;) RETURN { *pnd = nd = MkNode(Stat, NULLNODE, NULLNODE, &dot); } [ expression(&(nd->nd_right)) + { if (scopeclosed(CurrentScope)) { +error("a module body has no result value"); + } + else if (! currentdef->df_type->next) { +error("procedure \"%s\" has no result value", currentdef->df_idf->id_text); + } + } ]? ]? ; diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index 21e4bb59..1cc5cfbf 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -9,6 +9,7 @@ static char *RcsId = "$Header$"; #include "target_sizes.h" #include "debug.h" +#include "maxset.h" #include "def.h" #include "type.h" @@ -131,28 +132,61 @@ standard_type(fund, align, size) init_types() { + /* Initialize the predefined types + */ register struct type *tp; + /* character type + */ char_type = standard_type(T_CHAR, 1, (arith) 1); char_type->enm_ncst = 256; + + /* character constant, different from char because of compatibility + with ARRAY OF CHAR + */ charc_type = standard_type(T_CHAR, 1, (arith) 1); charc_type->enm_ncst = 256; + + /* boolean type + */ bool_type = standard_type(T_ENUMERATION, 1, (arith) 1); bool_type->enm_ncst = 2; + + /* integer types, also a "intorcard", for integer constants between + 0 and MAX(INTEGER) + */ int_type = standard_type(T_INTEGER, int_align, int_size); longint_type = standard_type(T_INTEGER, long_align, long_size); card_type = standard_type(T_CARDINAL, int_align, int_size); + intorcard_type = standard_type(T_INTORCARD, int_align, int_size); + + /* floating types + */ real_type = standard_type(T_REAL, float_align, float_size); longreal_type = standard_type(T_REAL, double_align, double_size); - word_type = standard_type(T_WORD, word_align, word_size); - intorcard_type = standard_type(T_INTORCARD, int_align, int_size); + + /* string constant type + */ string_type = standard_type(T_STRING, 1, (arith) -1); + + /* SYSTEM types + */ + word_type = standard_type(T_WORD, word_align, word_size); address_type = construct_type(T_POINTER, word_type); + + /* create BITSET type + */ tp = construct_type(T_SUBRANGE, int_type); tp->sub_lb = 0; tp->sub_ub = word_size * 8 - 1; bitset_type = set_type(tp); + + /* a unique type for standard procedures and functions + */ std_type = construct_type(T_PROCEDURE, NULLTYPE); + + /* a unique type indicating an error + */ error_type = standard_type(T_CHAR, 1, (arith) 1); } @@ -183,11 +217,12 @@ ParamList(ids, tp, VARp) return pstart; } -/* A subrange had a specified base. Check that the bases conform ... -*/ chk_basesubrange(tp, base) register struct type *tp, *base; { + /* A subrange had a specified base. Check that the bases conform. + */ + if (base->tp_fund == T_SUBRANGE) { /* Check that the bounds of "tp" fall within the range of "base" @@ -197,6 +232,7 @@ chk_basesubrange(tp, base) } base = base->next; } + if (base->tp_fund == T_ENUMERATION || base->tp_fund == T_CHAR) { if (tp->next != base) { error("Specified base does not conform"); @@ -212,6 +248,7 @@ chk_basesubrange(tp, base) else if (base != tp->next && base != int_type) { error("Specified base does not conform"); } + tp->next = base; tp->tp_size = base->tp_size; tp->tp_align = base->tp_align; @@ -233,14 +270,18 @@ subr_type(lb, ub) } if (tp->tp_fund == T_SUBRANGE) tp = tp->next; - if (tp == intorcard_type) tp = card_type; /* lower bound > 0 */ + + if (tp == intorcard_type) { + /* Lower bound >= 0; in this case, the base type is CARDINAL, + according to the language definition, par. 6.3 + */ + assert(lb->nd_INT >= 0); + tp = card_type; + } /* Check base type */ - if (tp != int_type && tp != card_type && tp != char_type && - tp->tp_fund != T_ENUMERATION) { - /* BOOLEAN is also an ENUMERATION type - */ + if (! (tp->tp_fund & T_DISCRETE)) { node_error(ub, "Illegal base type for subrange"); return error_type; } @@ -258,10 +299,8 @@ subr_type(lb, ub) res->sub_ub = ub->nd_INT; res->tp_size = tp->tp_size; res->tp_align = tp->tp_align; - DO_DEBUG(2,debug("Creating subrange type %ld-%ld", (long)lb->nd_INT,(long)ub->nd_INT)); return res; } -#define MAX_SET 1024 /* ??? Maximum number of elements in a set */ struct type * set_type(tp) @@ -273,14 +312,14 @@ set_type(tp) arith lb, ub; if (tp->tp_fund == T_SUBRANGE) { - if ((lb = tp->sub_lb) < 0 || (ub = tp->sub_ub) > MAX_SET - 1) { + if ((lb = tp->sub_lb) < 0 || (ub = tp->sub_ub) > MAXSET - 1) { error("Set type limits exceeded"); return error_type; } } else if (tp->tp_fund == T_ENUMERATION || tp == char_type) { lb = 0; - if ((ub = tp->enm_ncst - 1) > MAX_SET - 1) { + if ((ub = tp->enm_ncst - 1) > MAXSET - 1) { error("Set type limits exceeded"); return error_type; } @@ -289,6 +328,7 @@ set_type(tp) error("illegal base type for set"); return error_type; } + tp = construct_type(T_SET, tp); tp->tp_size = align(((ub - lb) + 7)/8, word_align); return tp; @@ -297,40 +337,68 @@ set_type(tp) ArraySizes(tp) register struct type *tp; { - /* Assign sizes to an array type + /* Assign sizes to an array type, and check index type */ arith elem_size; - register struct type *itype = tp->next; /* the index type */ + register struct type *index_type = tp->next; + register struct type *elem_type = tp->arr_elem; - if (tp->arr_elem->tp_fund == T_ARRAY) { - ArraySizes(tp->arr_elem); + if (elem_type->tp_fund == T_ARRAY) { + ArraySizes(elem_type); } - elem_size = align(tp->arr_elem->tp_size, tp->arr_elem->tp_align); - tp->tp_align = tp->arr_elem->tp_align; + /* align element size to alignment requirement of element type + */ + elem_size = align(elem_type->tp_size, elem_type->tp_align); + tp->tp_align = elem_type->tp_align; - if (! (itype->tp_fund & T_INDEX)) { + /* check index type + */ + if (! (index_type->tp_fund & T_INDEX)) { error("Illegal index type"); tp->tp_size = 0; return; } - switch(itype->tp_fund) { + /* find out HIGH, LOW and size of ARRAY + */ + switch(index_type->tp_fund) { case T_SUBRANGE: - tp->arr_lb = itype->sub_lb; - tp->arr_ub = itype->sub_ub; - tp->tp_size = elem_size * (itype->sub_ub - itype->sub_lb + 1); + tp->arr_lb = index_type->sub_lb; + tp->arr_ub = index_type->sub_ub; + tp->tp_size = elem_size * + (index_type->sub_ub - index_type->sub_lb + 1); break; case T_CHAR: case T_ENUMERATION: tp->arr_lb = 0; - tp->arr_ub = itype->enm_ncst - 1; - tp->tp_size = elem_size * itype->enm_ncst; + tp->arr_ub = index_type->enm_ncst - 1; + tp->tp_size = elem_size * index_type->enm_ncst; break; default: assert(0); } - /* ??? overflow checking ??? */ + /* ??? overflow checking ??? + */ +} + +FreeType(tp) + struct type *tp; +{ + /* Release type structures indicated by "tp" + */ + register struct paramlist *pr, *pr1; + + assert(tp->tp_fund == T_PROCEDURE); + + pr = tp->prc_params; + while (pr) { + pr1 = pr; + pr = pr->next; + free_paramlist(pr1); + } + + free_type(tp); } int diff --git a/lang/m2/comp/typequiv.c b/lang/m2/comp/typequiv.c index 603d35fe..3054afc3 100644 --- a/lang/m2/comp/typequiv.c +++ b/lang/m2/comp/typequiv.c @@ -12,21 +12,31 @@ static char *RcsId = "$Header$"; int TstTypeEquiv(tp1, tp2) - register struct type *tp1, *tp2; + struct type *tp1, *tp2; { - /* test if two types are equivalent. A complication comes - from the fact that for some procedures two declarations may - be given: one in the specification module and one in the - definition module. - A related problem is that two dynamic arrays with - equivalent base types are also equivalent. + /* test if two types are equivalent. */ return tp1 == tp2 || tp1 == error_type || - tp2 == error_type + tp2 == error_type; +} + +int +TstParEquiv(tp1, tp2) + register struct type *tp1, *tp2; +{ + /* test if two parameter types are equivalent. This routine + is used to check if two different procedure declarations + (one in the definition module, one in the implementation + module) are equivalent. A complication comes from dynamic + arrays. + */ + + return + TstTypeEquiv(tp1, tp2) || ( tp1->tp_fund == T_ARRAY @@ -38,16 +48,7 @@ TstTypeEquiv(tp1, tp2) tp2->next == 0 && TstTypeEquiv(tp1->arr_elem, tp2->arr_elem) - ) - || - ( - tp1 && tp1->tp_fund == T_PROCEDURE - && - tp2 && tp2->tp_fund == T_PROCEDURE - && - TstProcEquiv(tp1, tp2) ); - } int @@ -61,14 +62,17 @@ TstProcEquiv(tp1, tp2) register struct paramlist *p1, *p2; if (!TstTypeEquiv(tp1->next, tp2->next)) return 0; + p1 = tp1->prc_params; p2 = tp2->prc_params; + while (p1 && p2) { if (p1->par_var != p2->par_var || - !TstTypeEquiv(p1->par_type, p2->par_type)) return 0; + !TstParEquiv(p1->par_type, p2->par_type)) return 0; p1 = p1->next; p2 = p2->next; } + return p1 == p2; } @@ -79,9 +83,12 @@ TstCompat(tp1, tp2) /* test if two types are compatible. See section 6.3 of the Modula-2 Report for a definition of "compatible". */ + if (TstTypeEquiv(tp1, tp2)) return 1; + if (tp1->tp_fund == T_SUBRANGE) tp1 = tp1->next; if (tp2->tp_fund == T_SUBRANGE) tp2 = tp2->next; + return tp1 == tp2 || ( tp1 == intorcard_type @@ -117,12 +124,15 @@ int TstAssCompat(tp1, tp2) { /* Test if two types are assignment compatible. */ + if (TstCompat(tp1, tp2)) return 1; if (tp1->tp_fund == T_SUBRANGE) tp1 = tp1->next; if (tp2->tp_fund == T_SUBRANGE) tp2 = tp2->next; - if ((tp1->tp_fund & (T_INTEGER|T_CARDINAL)) && - (tp2->tp_fund & (T_INTEGER|T_CARDINAL))) return 1; + + if ((tp1->tp_fund & T_INTORCARD) && + (tp2->tp_fund & T_INTORCARD)) return 1; + if (tp1 == char_type && tp2 == charc_type) return 1; if (tp1->tp_fund == T_ARRAY && (tp2 == charc_type || tp2 == string_type)) { @@ -133,5 +143,6 @@ int TstAssCompat(tp1, tp2) if (tp1->tp_fund == T_SUBRANGE) tp1 = tp1->next; return tp1 == char_type; } + return 0; } diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index d23bbdf0..653b6db6 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -16,11 +16,14 @@ static char *RcsId = "$Header$"; #include "main.h" #include "LLlex.h" #include "node.h" +#include "Lpars.h" #include "debug.h" extern arith align(); static int prclev = 0; +static label instructionlabel = 0; +static label datalabel = 0; WalkModule(module) register struct def *module; @@ -33,10 +36,12 @@ WalkModule(module) scope = CurrentScope; CurrentScope = module->mod_scope; + if (!prclev && module->mod_number) { /* This module is a local module, but not within a procedure. Generate code to allocate storage for its - variables + variables. This is done by generating a "bss", + with label "_". */ arith size = align(CurrentScope->sc_off, word_size); @@ -69,7 +74,7 @@ WalkModule(module) CurrentScope->sc_off = 0; C_pro_narg(CurrentScope->sc_name); MkCalls(CurrentScope->sc_def); - WalkNode(module->mod_body); + WalkNode(module->mod_body, (label) 0); C_end(align(-CurrentScope->sc_off, word_size)); CurrentScope = scope; @@ -91,12 +96,13 @@ WalkProcedure(procedure) /* Generate code for this procedure */ - C_pro_narg(procedure->prc_name); + C_pro_narg(CurrentScope->sc_name); /* generate calls to initialization routines of modules defined within this procedure */ + instructionlabel = 1; MkCalls(CurrentScope->sc_def); - WalkNode(procedure->prc_body); + WalkNode(procedure->prc_body, (label) 0); C_end(align(-CurrentScope->sc_off, word_size)); CurrentScope = scope; prclev--; @@ -126,17 +132,151 @@ MkCalls(df) while (df) { if (df->df_kind == D_MODULE) { C_lxl((arith) 0); - C_cal(df->df_scope->sc_name); + C_cal(df->mod_scope->sc_name); } df = df->df_nextinscope; } } -WalkNode(nd) - struct node *nd; +WalkNode(nd, lab) + register struct node *nd; + label lab; { /* Node "nd" represents either a statement or a statement list. - Generate code for it. + Walk through it. + "lab" represents the label that must be jumped to on + encountering an EXIT statement. + */ + + while (nd->nd_class == Link) { /* statement list */ + WalkStat(nd->nd_left, lab); + nd = nd->nd_right; + } + + WalkStat(nd, lab); +} + +WalkStat(nd, lab) + register struct node *nd; + label lab; +{ + /* Walk through a statement, generating code for it. + "lab" represents the label that must be jumped to on + encountering an EXIT statement. + */ + register struct node *left = nd->nd_left; + register struct node *right = nd->nd_right; + + if (nd->nd_class == Call) { + /* ??? */ + return; + } + + assert(nd->nd_class == Stat); + + switch(nd->nd_symb) { + case BECOMES: + /* ??? */ + break; + + case IF: + { label l1, l2; + + l1 = instructionlabel++; + l2 = instructionlabel++; + ExpectBool(left); + assert(right->nd_symb == THEN); + C_zeq(l1); + WalkNode(right->nd_left, lab); + + if (right->nd_right) { /* ELSE part */ + C_bra(l2); + C_df_ilb(l1); + WalkNode(right->nd_right, lab); + C_df_ilb(l2); + } + else C_df_ilb(l1); + break; + } + + case CASE: + /* ??? */ + break; + + case WHILE: + { label l1, l2; + + l1 = instructionlabel++; + l2 = instructionlabel++; + C_df_ilb(l1); + ExpectBool(left); + C_zeq(l2); + WalkNode(right, lab); + C_bra(l1); + C_df_ilb(l2); + break; + } + + case REPEAT: + { label l1; + + l1 = instructionlabel++; + C_df_ilb(l1); + WalkNode(left, lab); + ExpectBool(right); + C_zeq(l1); + break; + } + + case LOOP: + { label l1, l2; + + l1 = instructionlabel++; + l2 = instructionlabel++; + C_df_ilb(l1); + WalkNode(left, l2); + C_bra(l1); + C_df_ilb(l2); + break; + } + + case FOR: + /* ??? */ + break; + + case WITH: + /* ??? */ + break; + + case EXIT: + assert(lab != 0); + + C_bra(lab); + break; + + case RETURN: + /* ??? */ + break; + + default: + assert(0); + } +} + +ExpectBool(nd) + struct node *nd; +{ + /* "nd" must indicate a boolean expression. Check this and + generate code to evaluate the expression. + */ + + chk_expr(nd); + + if (nd->nd_type != bool_type) { + node_error(nd, "boolean expression expected"); + } + + /* generate code */ /* ??? */ } From e8977ebb57701bb820d950e53411425654d63529 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 22 Apr 1986 23:22:19 +0000 Subject: [PATCH 0185/1625] newer version --- lang/m2/comp/chk_expr.c | 11 +++++++---- lang/m2/comp/declar.g | 2 +- lang/m2/comp/typequiv.c | 4 ++++ lang/m2/comp/walk.c | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index bf9c58c3..22d91ea7 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -369,7 +369,7 @@ left->nd_def->df_idf->id_text, left->nd_def->df_value.df_stdname)); /* A dynamic array has no explicit index type */ - expp->nd_type = int_type; + expp->nd_type = intorcard_type; } else cstcall(expp, S_MAX); break; @@ -667,16 +667,19 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R } if (expp->nd_symb == '[') { - /* Handle ARRAY selection specially too! */ + /* Handle ARRAY selection specially too! + */ if (tpl->tp_fund != T_ARRAY) { node_error(expp, "array index not belonging to an ARRAY"); return 0; } - if (!TstCompat(tpl->next, tpr)) { + + if ((tpl->next && !TstCompat(tpl->next, tpr)) || + (!tpl->next && !TstCompat(intorcard_type, tpr)) { node_error(expp, "incompatible index type"); - return 0; } + expp->nd_type = tpl->arr_elem; return 1; } diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index b42921fe..abd63d34 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -61,7 +61,7 @@ ProcedureHeading(struct def **pdf; int type;) /* We already saw a definition of this type in the definition module. */ - if (!TstTypeEquiv(tp, df->df_type)) { + if (!TstProcEquiv(tp, df->df_type)) { error("inconsistent procedure declaration for \"%s\"", df->df_idf->id_text); } FreeType(df->df_type); diff --git a/lang/m2/comp/typequiv.c b/lang/m2/comp/typequiv.c index 3054afc3..4c48a305 100644 --- a/lang/m2/comp/typequiv.c +++ b/lang/m2/comp/typequiv.c @@ -95,6 +95,10 @@ TstCompat(tp1, tp2) && (tp2 == int_type || tp2 == card_type) ) + || + (tp1 == char_type && tp2 == charc_type) + || + (tp2 == char_type && tp1 == charc_type) || ( tp2 == intorcard_type && diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index 653b6db6..6324b8be 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -272,7 +272,7 @@ ExpectBool(nd) chk_expr(nd); - if (nd->nd_type != bool_type) { + if (nd->nd_type != bool_type && nd->nd_type != error_type) { node_error(nd, "boolean expression expected"); } From c11efeb1fea4128396fa707e3934f82fd0d2d7fa Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 23 Apr 1986 22:12:22 +0000 Subject: [PATCH 0186/1625] newer version --- lang/m2/comp/chk_expr.c | 558 ++++++++++++++++++++------------------ lang/m2/comp/declar.g | 17 +- lang/m2/comp/def.c | 10 + lang/m2/comp/error.c | 5 +- lang/m2/comp/expression.g | 30 +- lang/m2/comp/node.H | 2 + lang/m2/comp/program.g | 13 +- lang/m2/comp/statement.g | 7 +- lang/m2/comp/type.c | 11 + lang/m2/comp/typequiv.c | 8 +- lang/m2/comp/walk.c | 75 ++++- 11 files changed, 437 insertions(+), 299 deletions(-) diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index 22d91ea7..81fc53c8 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -21,6 +21,8 @@ static char *RcsId = "$Header$"; #include "debug.h" +extern char *symbol2str(); + int chk_expr(expp) register struct node *expp; @@ -32,11 +34,19 @@ chk_expr(expp) switch(expp->nd_class) { case Oper: + if (expp->nd_symb == '[') { + return chk_designator(expp, DESIGNATOR); + } + return chk_expr(expp->nd_left) && chk_expr(expp->nd_right) && chk_oper(expp); case Uoper: + if (expp->nd_symb == '^') { + return chk_designator(expp, DESIGNATOR); + } + return chk_expr(expp->nd_right) && chk_uoper(expp); @@ -56,13 +66,13 @@ chk_expr(expp) return chk_set(expp); case Name: - return chk_name(expp); + return chk_designator(expp, DESIGNATOR); case Call: return chk_call(expp); case Link: - return chk_name(expp); + return chk_designator(expp, DESIGNATOR); default: assert(0); @@ -89,7 +99,8 @@ chk_set(expp) if (nd = expp->nd_left) { /* A type was given. Check it out */ - findname(nd); + if (! chk_designator(nd, QUALONLY)) return 0; + assert(nd->nd_class == Def); df = nd->nd_def; @@ -259,7 +270,7 @@ getname(argp, kinds) return 0; } argp = argp->nd_right; - findname(argp->nd_left); + if (! chk_designator(argp->nd_left, QUALONLY)) return 0; assert(argp->nd_left->nd_class == Def); if (!(argp->nd_left->nd_def->df_kind & kinds)) { node_error(argp, "unexpected type"); @@ -283,7 +294,7 @@ chk_call(expp) */ expp->nd_type = error_type; left = expp->nd_left; - findname(left); + if (! chk_designator(left, DESIGNATOR)) return 0; if (left->nd_type == error_type) return 0; if (left->nd_class == Def && @@ -300,7 +311,6 @@ node_error(expp, "only one parameter expected in type cast"); if (! chk_expr(arg)) return 0; if (arg->nd_type->tp_size != left->nd_type->tp_size) { node_error(expp, "size of type in type cast does not match size of operand"); - return 0; } arg->nd_type = left->nd_type; FreeNode(expp->nd_left); @@ -322,172 +332,7 @@ node_error(expp, "size of type in type cast does not match size of operand"); if (left->nd_type == std_type) { /* A standard procedure */ - assert(left->nd_class == Def); -DO_DEBUG(3, debug("standard name \"%s\", %d", -left->nd_def->df_idf->id_text, left->nd_def->df_value.df_stdname)); - switch(left->nd_def->df_value.df_stdname) { - case S_ABS: - arg = getarg(arg, T_NUMERIC); - if (! arg) return 0; - left = arg->nd_left; - expp->nd_type = left->nd_type; - if (left->nd_class == Value) { - cstcall(expp, S_ABS); - } - break; - - case S_CAP: - arg = getarg(arg, T_CHAR); - expp->nd_type = char_type; - if (!arg) return 0; - left = arg->nd_left; - if (left->nd_class == Value) { - cstcall(expp, S_CAP); - } - break; - - case S_CHR: - arg = getarg(arg, T_INTORCARD); - expp->nd_type = char_type; - if (!arg) return 0; - if (arg->nd_left->nd_class == Value) { - cstcall(expp, S_CHR); - } - break; - - case S_FLOAT: - arg = getarg(arg, T_INTORCARD); - expp->nd_type = real_type; - if (!arg) return 0; - break; - - case S_HIGH: - arg = getarg(arg, T_ARRAY); - if (!arg) return 0; - expp->nd_type = arg->nd_left->nd_type->next; - if (!expp->nd_type) { - /* A dynamic array has no explicit - index type - */ - expp->nd_type = intorcard_type; - } - else cstcall(expp, S_MAX); - break; - - case S_MAX: - case S_MIN: - arg = getarg(arg, T_DISCRETE); - if (!arg) return 0; - expp->nd_type = arg->nd_left->nd_type; - cstcall(expp,left->nd_def->df_value.df_stdname); - break; - - case S_ODD: - arg = getarg(arg, T_INTORCARD); - if (!arg) return 0; - expp->nd_type = bool_type; - if (arg->nd_left->nd_class == Value) { - cstcall(expp, S_ODD); - } - break; - - case S_ORD: - arg = getarg(arg, T_DISCRETE); - if (!arg) return 0; - expp->nd_type = card_type; - if (arg->nd_left->nd_class == Value) { - cstcall(expp, S_ORD); - } - break; - - case S_TSIZE: /* ??? */ - case S_SIZE: - arg = getname(arg, D_FIELD|D_VARIABLE|D_TYPE|D_HIDDEN|D_HTYPE); - expp->nd_type = intorcard_type; - if (!arg) return 0; - cstcall(expp, S_SIZE); - break; - - case S_TRUNC: - arg = getarg(arg, T_REAL); - if (!arg) return 0; - expp->nd_type = card_type; - break; - - case S_VAL: { - struct type *tp; - - arg = getname(arg, D_HIDDEN|D_HTYPE|D_TYPE); - if (!arg) return 0; - tp = arg->nd_left->nd_def->df_type; - if (tp->tp_fund == T_SUBRANGE) tp = tp->next; - if (!(tp->tp_fund & T_DISCRETE)) { - node_error(arg, "unexpected type"); - return 0; - } - expp->nd_type = arg->nd_left->nd_def->df_type; - expp->nd_right = arg->nd_right; - arg->nd_right = 0; - FreeNode(arg); - arg = getarg(expp, T_INTORCARD); - if (!arg) return 0; - if (arg->nd_left->nd_class == Value) { - cstcall(expp, S_VAL); - } - break; - } - - case S_ADR: - arg = getname(arg, D_VARIABLE|D_FIELD|D_PROCEDURE); - expp->nd_type = address_type; - if (!arg) return 0; - break; - - case S_DEC: - case S_INC: - expp->nd_type = 0; - arg = getname(arg, D_VARIABLE|D_FIELD); - if (!arg) return 0; - if (arg->nd_right) { - arg = getarg(arg, T_INTORCARD); - if (!arg) return 0; - } - break; - - case S_HALT: - expp->nd_type = 0; - break; - - case S_EXCL: - case S_INCL: { - struct type *tp; - - expp->nd_type = 0; - arg = getname(arg, D_VARIABLE|D_FIELD); - if (!arg) return 0; - tp = arg->nd_left->nd_type; - if (tp->tp_fund != T_SET) { -node_error(arg, "EXCL and INCL expect a SET parameter"); - return 0; - } - arg = getarg(arg, T_DISCRETE); - if (!arg) return 0; - if (!TstCompat(tp->next, arg->nd_left->nd_type)) { - node_error(arg, "unexpected type"); - return 0; - } - break; - } - - default: - assert(0); - } - if (arg->nd_right) { - node_error(arg->nd_right, - "too many parameters supplied"); - return 0; - } - return 1; + return chk_std(expp, left, arg); } /* Here, we have found a real procedure call. The left hand side may also represent a procedure variable. @@ -534,7 +379,8 @@ node_error(arg->nd_left, "type incompatibility in value parameter"); return 1; } -findname(expp) +int +chk_designator(expp, flag) register struct node *expp; { /* Find the name indicated by "expp", starting from the current @@ -545,29 +391,31 @@ findname(expp) struct def *lookfor(); expp->nd_type = error_type; + if (expp->nd_class == Name) { expp->nd_def = lookfor(expp, CurrentScope, 1); expp->nd_class = Def; expp->nd_type = expp->nd_def->df_type; - return; + if (expp->nd_type == error_type) return 0; } + if (expp->nd_class == Link) { assert(expp->nd_symb == '.'); assert(expp->nd_right->nd_class == Name); - findname(expp->nd_left); + + if (! chk_designator(expp->nd_left, flag)) return 0; tp = expp->nd_left->nd_type; - if (tp == error_type) { - df = ill_df; - } + if (tp == error_type) return 0; else if (tp->tp_fund != T_RECORD) { /* This is also true for modules */ node_error(expp,"illegal selection"); - df = ill_df; + return 0; } else df = lookup(expp->nd_right->nd_IDF, tp->rec_scope); + if (!df) { - df = ill_df; id_not_declared(expp->nd_right); + return 0; } else if (df != ill_df) { expp->nd_type = df->df_type; @@ -575,8 +423,10 @@ findname(expp) node_error(expp->nd_right, "identifier \"%s\" not exported from qualifying module", df->df_idf->id_text); + return 0; } } + if (expp->nd_left->nd_class == Def) { expp->nd_class = Def; expp->nd_def = df; @@ -584,45 +434,83 @@ df->df_idf->id_text); FreeNode(expp->nd_right); expp->nd_left = expp->nd_right = 0; } - return; + else return 1; } + + if (expp->nd_class == Def) { + df = expp->nd_def; + + if (df->df_kind & (D_ENUM | D_CONST)) { + if (df->df_kind == D_ENUM) { + expp->nd_class = Value; + expp->nd_INT = df->enm_val; + expp->nd_symb = INTEGER; + } + else { + assert(df->df_kind == D_CONST); + *expp = *(df->con_const); + } + } + + return 1; + } + + if (flag == QUALONLY) { + node_error(expp, "identifier expected"); + return 0; + } + if (expp->nd_class == Oper) { + struct type *tpl, *tpr; + assert(expp->nd_symb == '['); - findname(expp->nd_left); - if (chk_expr(expp->nd_right) && - expp->nd_left->nd_type != error_type && - chk_oper(expp)) /* ??? */ ; - return; - } - if (expp->nd_class == Uoper && expp->nd_symb == '^') { - findname(expp->nd_right); - if (expp->nd_right->nd_type != error_type && - chk_uoper(expp)) /* ??? */ ; - } - return; -} -int -chk_name(expp) - register struct node *expp; -{ - register struct def *df; + if ( + !chk_designator(expp->nd_left, DESIGNATOR) + || + !chk_expr(expp->nd_right) + || + expp->nd_left->nd_type == error_type + ) return 0; - findname(expp); - assert(expp->nd_class == Def); - df = expp->nd_def; - if (df->df_kind == D_ERROR) return 0; - if (df->df_kind & (D_ENUM | D_CONST)) { - if (df->df_kind == D_ENUM) { - expp->nd_class = Value; - expp->nd_INT = df->enm_val; - expp->nd_symb = INTEGER; + tpr = expp->nd_right->nd_type; + tpl = expp->nd_left->nd_type; + + if (tpl->tp_fund != T_ARRAY) { + node_error(expp, + "array index not belonging to an ARRAY"); + return 0; } - else if (df->df_kind == D_CONST) { - *expp = *(df->con_const); + + /* Type of the index must be assignment compatible with + the index type of the array (Def 8.1) + */ + if ((tpl->next && !TstAssCompat(tpl->next, tpr)) || + (!tpl->next && !TstAssCompat(intorcard_type, tpr))) { + node_error(expp, "incompatible index type"); + return 0; } + + expp->nd_type = tpl->arr_elem; + return 1; } - return 1; + + if (expp->nd_class == Uoper) { + assert(expp->nd_symb == '^'); + + if (! chk_designator(expp->nd_right, DESIGNATOR)) return 0; + if (expp->nd_right->nd_type->tp_fund != T_POINTER) { +node_error(expp, "illegal operand for unary operator \"%s\"", +symbol2str(expp->nd_symb)); + return 0; + } + + expp->nd_type = expp->nd_right->nd_type->next; + return 1; + } + + node_error(expp, "designator expected"); + return 0; } int @@ -631,19 +519,20 @@ chk_oper(expp) { /* Check a binary operation. */ - register struct type *tpl = expp->nd_left->nd_type; - register struct type *tpr = expp->nd_right->nd_type; - char *symbol2str(); + register struct node *left = expp->nd_left; + register struct node *right = expp->nd_right; + struct type *tpl = left->nd_type; + struct type *tpr = right->nd_type; int errval = 1; if (tpl == intorcard_type) { if (tpr == int_type || tpr == card_type) { - expp->nd_left->nd_type = tpl = tpr; + left->nd_type = tpl = tpr; } } if (tpr == intorcard_type) { if (tpl == int_type || tpl == card_type) { - expp->nd_right->nd_type = tpr = tpl; + right->nd_type = tpr = tpl; } } expp->nd_type = error_type; @@ -655,42 +544,29 @@ chk_oper(expp) node_error(expp, "RHS of IN operator not a SET type"); return 0; } - if (!TstCompat(tpl, tpr->next)) { + if (!TstAssCompat(tpl, tpr->next)) { + /* Assignment compatible ??? + I don't know! Should we be allowed th check + if a CARDINAL is a member of a BITSET??? + */ + node_error(expp, "IN operator: type of LHS not compatible with element type of RHS"); return 0; } - if (expp->nd_left->nd_class == Value && - expp->nd_right->nd_class == Set) { + if (left->nd_class == Value && right->nd_class == Set) { cstset(expp); } return 1; } - if (expp->nd_symb == '[') { - /* Handle ARRAY selection specially too! - */ - if (tpl->tp_fund != T_ARRAY) { - node_error(expp, - "array index not belonging to an ARRAY"); - return 0; - } - - if ((tpl->next && !TstCompat(tpl->next, tpr)) || - (!tpl->next && !TstCompat(intorcard_type, tpr)) { - node_error(expp, "incompatible index type"); - } - - expp->nd_type = tpl->arr_elem; - return 1; - } - if (tpl->tp_fund == T_SUBRANGE) tpl = tpl->next; expp->nd_type = tpl; + /* Operands must be compatible (distilled from Def 8.2) + */ if (!TstCompat(tpl, tpr)) { - node_error(expp, - "incompatible types for operator \"%s\"", - symbol2str(expp->nd_symb)); + node_error(expp, "incompatible types for operator \"%s\"", + symbol2str(expp->nd_symb)); return 0; } @@ -702,15 +578,13 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R case T_INTEGER: case T_CARDINAL: case T_INTORCARD: - if (expp->nd_left->nd_class == Value && - expp->nd_right->nd_class == Value) { + if (left->nd_class==Value && right->nd_class==Value) { cstbin(expp); } return 1; case T_SET: - if (expp->nd_left->nd_class == Set && - expp->nd_right->nd_class == Set) { + if (left->nd_class == Set && right->nd_class == Set) { cstset(expp); } /* Fall through */ @@ -723,8 +597,7 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R case '/': switch(tpl->tp_fund) { case T_SET: - if (expp->nd_left->nd_class == Set && - expp->nd_right->nd_class == Set) { + if (left->nd_class == Set && right->nd_class == Set) { cstset(expp); } /* Fall through */ @@ -737,8 +610,7 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R case DIV: case MOD: if (tpl->tp_fund & T_INTORCARD) { - if (expp->nd_left->nd_class == Value && - expp->nd_right->nd_class == Value) { + if (left->nd_class==Value && right->nd_class==Value) { cstbin(expp); } return 1; @@ -749,8 +621,7 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R case AND: case '&': if (tpl == bool_type) { - if (expp->nd_left->nd_class == Value && - expp->nd_right->nd_class == Value) { + if (left->nd_class==Value && right->nd_class==Value) { cstbin(expp); } return 1; @@ -771,8 +642,7 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R if (expp->nd_symb == '<' || expp->nd_symb == '>') { break; } - if (expp->nd_left->nd_class == Set && - expp->nd_right->nd_class == Set) { + if (left->nd_class == Set && right->nd_class == Set) { cstset(expp); } return 1; @@ -782,8 +652,7 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R case T_ENUMERATION: /* includes boolean */ case T_CHAR: case T_INTORCARD: - if (expp->nd_left->nd_class == Value && - expp->nd_right->nd_class == Value) { + if (left->nd_class==Value && right->nd_class==Value) { cstbin(expp); } return 1; @@ -868,11 +737,6 @@ chk_uoper(expp) } break; - case '^': - if (tpr->tp_fund != T_POINTER) break; - expp->nd_type = tpr->next; - return 1; - default: assert(0); } @@ -880,3 +744,179 @@ chk_uoper(expp) symbol2str(expp->nd_symb)); return 0; } + +struct node * +getvariable(arg) + register struct node *arg; +{ + arg = arg->nd_right; + if (!arg) { + node_error(arg, "too few parameters supplied"); + return 0; + } + + if (! chk_designator(arg->nd_left, DESIGNATOR)) return 0; + if (arg->nd_left->nd_class == Oper || arg->nd_left->nd_class == Uoper) { + return arg; + } + + if (arg->nd_left->nd_class != Def || + !(arg->nd_left->nd_def->df_kind & (D_VARIABLE|D_FIELD))) { + node_error(arg, "variable expected"); + return 0; + } + + return arg; +} + +int +chk_std(expp, left, arg) + register struct node *expp, *left, *arg; +{ + /* Check a call of a standard procedure or function + */ + + assert(left->nd_class == Def); +DO_DEBUG(3, debug("standard name \"%s\", %d", +left->nd_def->df_idf->id_text, left->nd_def->df_value.df_stdname)); + + switch(left->nd_def->df_value.df_stdname) { + case S_ABS: + if (!(arg = getarg(arg, T_NUMERIC))) return 0; + left = arg->nd_left; + expp->nd_type = left->nd_type; + if (left->nd_class == Value) cstcall(expp, S_ABS); + break; + + case S_CAP: + expp->nd_type = char_type; + if (!(arg = getarg(arg, T_CHAR))) return 0; + left = arg->nd_left; + if (left->nd_class == Value) cstcall(expp, S_CAP); + break; + + case S_CHR: + expp->nd_type = char_type; + if (!(arg = getarg(arg, T_INTORCARD))) return 0; + left = arg->nd_left; + if (left->nd_class == Value) cstcall(expp, S_CHR); + break; + + case S_FLOAT: + expp->nd_type = real_type; + if (!(arg = getarg(arg, T_INTORCARD))) return 0; + break; + + case S_HIGH: + if (!(arg = getarg(arg, T_ARRAY))) return 0; + expp->nd_type = arg->nd_left->nd_type->next; + if (!expp->nd_type) { + /* A dynamic array has no explicit index type + */ + expp->nd_type = intorcard_type; + } + else cstcall(expp, S_MAX); + break; + + case S_MAX: + case S_MIN: + if (!(arg = getarg(arg, T_DISCRETE))) return 0; + expp->nd_type = arg->nd_left->nd_type; + cstcall(expp,left->nd_def->df_value.df_stdname); + break; + + case S_ODD: + if (!(arg = getarg(arg, T_INTORCARD))) return 0; + expp->nd_type = bool_type; + if (arg->nd_left->nd_class == Value) cstcall(expp, S_ODD); + break; + + case S_ORD: + if (!(arg = getarg(arg, T_DISCRETE))) return 0; + expp->nd_type = card_type; + if (arg->nd_left->nd_class == Value) cstcall(expp, S_ORD); + break; + + case S_TSIZE: /* ??? */ + case S_SIZE: + expp->nd_type = intorcard_type; + arg = getname(arg, D_FIELD|D_VARIABLE|D_TYPE|D_HIDDEN|D_HTYPE); + if (!arg) return 0; + cstcall(expp, S_SIZE); + break; + + case S_TRUNC: + expp->nd_type = card_type; + if (!(arg = getarg(arg, T_REAL))) return 0; + break; + + case S_VAL: + { + struct type *tp; + + if (!(arg = getname(arg, D_HIDDEN|D_HTYPE|D_TYPE))) return 0; + tp = arg->nd_left->nd_def->df_type; + if (tp->tp_fund == T_SUBRANGE) tp = tp->next; + if (!(tp->tp_fund & T_DISCRETE)) { + node_error(arg, "unexpected type"); + return 0; + } + expp->nd_type = arg->nd_left->nd_def->df_type; + expp->nd_right = arg->nd_right; + arg->nd_right = 0; + FreeNode(arg); + arg = getarg(expp, T_INTORCARD); + if (!arg) return 0; + if (arg->nd_left->nd_class == Value) cstcall(expp, S_VAL); + break; + } + + case S_ADR: + expp->nd_type = address_type; + if (!(arg = getarg(arg, D_VARIABLE|D_FIELD))) return 0; + break; + + case S_DEC: + case S_INC: + expp->nd_type = 0; + if (!(arg = getvariable(arg))) return 0; + if (arg->nd_right) { + if (!(arg = getarg(arg, T_INTORCARD))) return 0; + } + break; + + case S_HALT: + expp->nd_type = 0; + break; + + case S_EXCL: + case S_INCL: + { + struct type *tp; + + expp->nd_type = 0; + if (!(arg = getvariable(arg))) return 0; + tp = arg->nd_left->nd_type; + if (tp->tp_fund != T_SET) { +node_error(arg, "EXCL and INCL expect a SET parameter"); + return 0; + } + if (!(arg = getarg(arg, T_DISCRETE))) return 0; + if (!TstCompat(tp->next, arg->nd_left->nd_type)) { + node_error(arg, "unexpected type"); + return 0; + } + break; + } + + default: + assert(0); + } + + if (arg->nd_right) { + node_error(arg->nd_right, "too many parameters supplied"); + return 0; + } + + return 1; +} diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index abd63d34..baca3d8f 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -117,7 +117,8 @@ FormalParameters(int doparams; { *tp = 0; } [ ':' qualident(D_TYPE|D_HTYPE|D_HIDDEN, &df, "type", (struct node **) 0) - { *tp = df->df_type; } + { *tp = df->df_type; + } ]? ; @@ -364,14 +365,14 @@ FieldList(struct scope *scope; arith *cnt; int *palign;) */ { warning("Old fashioned Modula-2 syntax!"); id = gen_anon_idf(); - findname(nd); - assert(nd->nd_class == Def); - df = nd->nd_def; - if (!(df->df_kind & - (D_ERROR|D_TYPE|D_HTYPE|D_HIDDEN))) { - error("identifier \"%s\" is not a type", - df->df_idf->id_text); + df = ill_df; + if (chk_designator(nd, QUALONLY) && + (nd->nd_class != Def || + !(nd->nd_def->df_kind & + (D_ERROR|D_TYPE|D_HTYPE|D_HIDDEN)))) { + node_error(nd, "type expected"); } + else df = nd->nd_def; FreeNode(nd); } ] diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index 460e5397..64e8adbf 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -439,6 +439,16 @@ DeclProc(type) return df; } +InitProc(nd, df) + struct node *nd; + struct def *df; +{ + /* Create an initialization procedure for a module. + */ + df->mod_body = nd; + /* Keep it this way, or really create a procedure out of it??? */ +} + #ifdef DEBUG PrDef(df) register struct def *df; diff --git a/lang/m2/comp/error.c b/lang/m2/comp/error.c index 13280af6..7c121072 100644 --- a/lang/m2/comp/error.c +++ b/lang/m2/comp/error.c @@ -134,10 +134,7 @@ _error(class, node, fmt, argv) case LEXERROR: case CRASH: case FATAL: - /* ???? - if (C_busy()) - C_ms_err(); - */ + if (C_busy()) C_ms_err(); err_occurred = 1; break; diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index 25d070c7..4348fceb 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -33,27 +33,33 @@ number(struct node **p;) qualident(int types; struct def **pdf; char *str; struct node **p;) { register struct def *df; - register struct node **pnd; struct node *nd; } : IDENT { nd = MkNode(Name, NULLNODE, NULLNODE, &dot); - pnd = &nd; } [ - selector(pnd) + selector(&nd) ]* { if (types) { - findname(nd); - assert(nd->nd_class == Def); - *pdf = df = nd->nd_def; - if ( !((types|D_ERROR) & df->df_kind)) { - if (df->df_kind == D_FORWARD) { -node_error(*pnd,"%s \"%s\" not declared", str, df->df_idf->id_text); - } - else { -node_error(*pnd,"identifier \"%s\" is not a %s", df->df_idf->id_text, str); + df = ill_df; + + if (chk_designator(nd, QUALONLY)) { + if (nd->nd_class != Def) { + node_error(nd, "%s expected", str); + } + else { + df = nd->nd_def; + if ( !((types|D_ERROR) & df->df_kind)) { + if (df->df_kind == D_FORWARD) { +node_error(nd,"%s \"%s\" not declared", str, df->df_idf->id_text); + } + else { +node_error(nd,"identifier \"%s\" is not a %s", df->df_idf->id_text, str); + } } + } } + *pdf = df; } if (!p) FreeNode(nd); else *p = nd; diff --git a/lang/m2/comp/node.H b/lang/m2/comp/node.H index eb70a229..f74fd3ab 100644 --- a/lang/m2/comp/node.H +++ b/lang/m2/comp/node.H @@ -36,3 +36,5 @@ struct node { extern struct node *MkNode(); #define NULLNODE ((struct node *) 0) +#define QUALONLY 0 +#define DESIGNATOR 1 diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 1d675310..298bd74e 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -51,6 +51,7 @@ ModuleDeclaration extern int proclevel; static int modulecount = 0; char buf[256]; + struct node *nd; extern char *sprint(), *Malloc(), *strcpy(); } : MODULE IDENT { @@ -78,8 +79,9 @@ ModuleDeclaration ';' import(1)* export(0)? - block(&(df->mod_body)) - IDENT { close_scope(SC_CHKFORW|SC_CHKPROC|SC_REVERSE); + block(&nd) + IDENT { InitProc(nd, df); + close_scope(SC_CHKFORW|SC_CHKPROC|SC_REVERSE); match_id(id, dot.TOK_IDF); currentdef = savecurr; } @@ -226,6 +228,7 @@ ProgramModule(int state;) struct idf *id; struct def *GetDefinitionModule(); register struct def *df; + struct node *nd; } : MODULE IDENT { @@ -243,12 +246,14 @@ ProgramModule(int state;) open_scope(CLOSEDSCOPE); df->mod_scope = CurrentScope; df->mod_number = 0; + CurrentScope->sc_name = id->id_text; } } priority(&(df->mod_priority))? ';' import(0)* - block(&(df->mod_body)) IDENT - { close_scope(SC_CHKFORW|SC_CHKPROC|SC_REVERSE); + block(&nd) IDENT + { InitProc(nd, df); + close_scope(SC_CHKFORW|SC_CHKPROC|SC_REVERSE); match_id(id, dot.TOK_IDF); } '.' diff --git a/lang/m2/comp/statement.g b/lang/m2/comp/statement.g index b80c8cb3..1b068826 100644 --- a/lang/m2/comp/statement.g +++ b/lang/m2/comp/statement.g @@ -74,7 +74,12 @@ error("a module body has no result value"); error("procedure \"%s\" has no result value", currentdef->df_idf->id_text); } } - ]? + | + { if (currentdef->df_type->next) { +error("procedure \"%s\" must return a value", currentdef->df_idf->id_text); + } + } + ] ]? ; diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index 1cc5cfbf..2d5b140a 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -90,23 +90,34 @@ construct_type(fund, tp) dtp->tp_align = pointer_align; dtp->tp_size = pointer_size; dtp->next = tp; + if (fund == T_PROCEDURE && tp) { + if (tp != bitset_type && + !(tp->tp_fund&(T_NUMERIC|T_INDEX|T_WORD|T_POINTER))) { + error("illegal procedure result type"); + } + } break; + case T_SET: dtp->tp_align = word_align; dtp->next = tp; break; + case T_ARRAY: dtp->tp_align = tp->tp_align; dtp->next = tp; break; + case T_SUBRANGE: dtp->tp_align = tp->tp_align; dtp->tp_size = tp->tp_size; dtp->next = tp; break; + default: assert(0); } + return dtp; } diff --git a/lang/m2/comp/typequiv.c b/lang/m2/comp/typequiv.c index 4c48a305..2a7c1a81 100644 --- a/lang/m2/comp/typequiv.c +++ b/lang/m2/comp/typequiv.c @@ -95,15 +95,15 @@ TstCompat(tp1, tp2) && (tp2 == int_type || tp2 == card_type) ) - || - (tp1 == char_type && tp2 == charc_type) - || - (tp2 == char_type && tp1 == charc_type) || ( tp2 == intorcard_type && (tp1 == int_type || tp1 == card_type) ) + || + (tp1 == char_type && tp2 == charc_type) + || + (tp2 == char_type && tp1 == charc_type) || ( tp1 == address_type && diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index 6324b8be..c8fffc56 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -24,6 +24,9 @@ extern arith align(); static int prclev = 0; static label instructionlabel = 0; static label datalabel = 0; +static label return_label; +static char return_expr_occurred; +static struct type *func_type; WalkModule(module) register struct def *module; @@ -72,9 +75,14 @@ WalkModule(module) this module. */ CurrentScope->sc_off = 0; + instructionlabel = 1; + return_label = instructionlabel++; + func_type = 0; C_pro_narg(CurrentScope->sc_name); MkCalls(CurrentScope->sc_def); WalkNode(module->mod_body, (label) 0); + C_df_ilb(return_label); + C_ret((label) 0); C_end(align(-CurrentScope->sc_off, word_size)); CurrentScope = scope; @@ -100,9 +108,14 @@ WalkProcedure(procedure) /* generate calls to initialization routines of modules defined within this procedure */ - instructionlabel = 1; + return_label = 1; + instructionlabel = 2; + func_type = procedure->df_type->next; MkCalls(CurrentScope->sc_def); WalkNode(procedure->prc_body, (label) 0); + C_df_ilb(return_label); + if (func_type) C_ret((arith) align(func_type->tp_size, word_align)); + else C_ret((arith) 0); C_end(align(-CurrentScope->sc_off, word_size)); CurrentScope = scope; prclev--; @@ -255,7 +268,13 @@ WalkStat(nd, lab) break; case RETURN: - /* ??? */ + if (right) { + WalkExpr(right); + if (!TstCompat(right->nd_type, func_type)) { +node_error(right, "type incompatibility in RETURN statement"); + } + } + C_bra(return_label); break; default: @@ -270,13 +289,55 @@ ExpectBool(nd) generate code to evaluate the expression. */ - chk_expr(nd); + WalkExpr(nd); if (nd->nd_type != bool_type && nd->nd_type != error_type) { node_error(nd, "boolean expression expected"); } - - /* generate code - */ - /* ??? */ } + +WalkExpr(nd) + struct node *nd; +{ + /* Check an expression and generate code for it + */ + + DO_DEBUG(1, (DumpTree(nd), print("\n"))); + + if (chk_expr(nd)) { + /* ??? */ + } +} + +#ifdef DEBUG +DumpTree(nd) + struct node *nd; +{ + char *s; + extern char *symbol2str(); + + if (!nd) { + print("()"); + return; + } + + print("("); + DumpTree(nd->nd_left); + switch(nd->nd_class) { + case Def: s = "Def"; break; + case Oper: s = "Oper"; break; + case Uoper: s = "Uoper"; break; + case Name: s = "Name"; break; + case Set: s = "Set"; break; + case Value: s = "Value"; break; + case Call: s = "Call"; break; + case Xset: s = "Xset"; break; + case Stat: s = "Stat"; break; + case Link: s = "Link"; break; + default: s = "ERROR"; break; + } + print("%s %s", s, symbol2str(nd->nd_symb)); + DumpTree(nd->nd_right); + print(")"); +} +#endif From f445033fab24929c1add93dba2f99e4f8afc23fd Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 25 Apr 1986 10:14:08 +0000 Subject: [PATCH 0187/1625] newer version --- lang/m2/comp/LLlex.c | 13 ++++- lang/m2/comp/Makefile | 4 +- lang/m2/comp/Parameters | 4 ++ lang/m2/comp/chk_expr.c | 117 ++++++++++++++++++++++++++------------ lang/m2/comp/declar.g | 11 +++- lang/m2/comp/defmodule.c | 1 - lang/m2/comp/expression.g | 4 +- lang/m2/comp/main.c | 24 ++------ lang/m2/comp/main.h | 9 +-- lang/m2/comp/node.H | 5 +- lang/m2/comp/options.c | 12 +++- lang/m2/comp/type.c | 67 ++++++++++++++++++++++ lang/m2/comp/typequiv.c | 18 ++++++ lang/m2/comp/walk.c | 19 ++++++- 14 files changed, 235 insertions(+), 73 deletions(-) diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index a252b606..a1ccd14a 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -248,8 +248,11 @@ again: switch (ch) { case 'H': Shex: *np++ = '\0'; - numtype = card_type; tk->TOK_INT = str2long(&buf[1], 16); + if (tk->TOK_INT >= 0 && tk->TOK_INT <= max_int) { + numtype = intorcard_type; + } + else numtype = card_type; return tk->tk_symb = INTEGER; case '8': @@ -283,11 +286,17 @@ Shex: *np++ = '\0'; PushBack(ch); ch = *--np; *np++ = '\0'; + tk->TOK_INT = str2long(&buf[1], 8); if (ch == 'C') { numtype = char_type; + if (tk->TOK_INT < 0 || tk->TOK_INT > 255) { +lexwarning("Character constant out of range"); + } + } + else if (tk->TOK_INT >= 0 && tk->TOK_INT <= max_int) { + numtype = intorcard_type; } else numtype = card_type; - tk->TOK_INT = str2long(&buf[1], 8); return tk->tk_symb = INTEGER; case 'A': diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index 70815858..7d893277 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -82,7 +82,7 @@ LLlex.o: LLlex.h Lpars.h class.h const.h f_info.h idf.h idfsize.h input.h inputt LLmessage.o: LLlex.h Lpars.h idf.h char.o: class.h error.o: LLlex.h debug.h errout.h f_info.h input.h inputtype.h main.h node.h -main.o: LLlex.h Lpars.h debug.h def.h f_info.h idf.h input.h inputtype.h node.h scope.h standards.h tokenname.h type.h +main.o: LLlex.h Lpars.h debug.h def.h f_info.h idf.h input.h inputtype.h ndirs.h node.h scope.h standards.h tokenname.h type.h symbol2str.o: Lpars.h tokenname.o: Lpars.h idf.h tokenname.h idf.o: idf.h @@ -97,7 +97,7 @@ typequiv.o: def.h type.h node.o: LLlex.h debug.h def.h node.h type.h cstoper.o: LLlex.h Lpars.h idf.h node.h standards.h target_sizes.h type.h chk_expr.o: LLlex.h Lpars.h const.h debug.h def.h idf.h node.h scope.h standards.h type.h -options.o: idfsize.h type.h +options.o: idfsize.h main.h ndir.h type.h walk.o: LLlex.h Lpars.h debug.h def.h main.h node.h scope.h type.h tokenfile.o: Lpars.h program.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h type.h diff --git a/lang/m2/comp/Parameters b/lang/m2/comp/Parameters index fcdfc05c..7604bdf9 100644 --- a/lang/m2/comp/Parameters +++ b/lang/m2/comp/Parameters @@ -63,4 +63,8 @@ extern char options[]; but what is a reasonable choice ??? */ +!File: ndir.h +#define NDIRS 16 /* maximum number of directories searched */ + + diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index 81fc53c8..938fc6f0 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -35,7 +35,7 @@ chk_expr(expp) switch(expp->nd_class) { case Oper: if (expp->nd_symb == '[') { - return chk_designator(expp, DESIGNATOR); + return chk_designator(expp, DESIGNATOR|VARIABLE); } return chk_expr(expp->nd_left) && @@ -44,7 +44,7 @@ chk_expr(expp) case Uoper: if (expp->nd_symb == '^') { - return chk_designator(expp, DESIGNATOR); + return chk_designator(expp, DESIGNATOR|VARIABLE); } return chk_expr(expp->nd_right) && @@ -66,13 +66,13 @@ chk_expr(expp) return chk_set(expp); case Name: - return chk_designator(expp, DESIGNATOR); + return chk_designator(expp, VALUE); case Call: return chk_call(expp); case Link: - return chk_designator(expp, DESIGNATOR); + return chk_designator(expp, DESIGNATOR|VALUE); default: assert(0); @@ -99,7 +99,7 @@ chk_set(expp) if (nd = expp->nd_left) { /* A type was given. Check it out */ - if (! chk_designator(nd, QUALONLY)) return 0; + if (! chk_designator(nd, 0)) return 0; assert(nd->nd_class == Def); df = nd->nd_def; @@ -270,12 +270,15 @@ getname(argp, kinds) return 0; } argp = argp->nd_right; - if (! chk_designator(argp->nd_left, QUALONLY)) return 0; + if (! chk_designator(argp->nd_left, 0)) return 0; + assert(argp->nd_left->nd_class == Def); + if (!(argp->nd_left->nd_def->df_kind & kinds)) { node_error(argp, "unexpected type"); return 0; } + return argp; } @@ -294,9 +297,8 @@ chk_call(expp) */ expp->nd_type = error_type; left = expp->nd_left; - if (! chk_designator(left, DESIGNATOR)) return 0; + if (! chk_designator(left, 0)) return 0; - if (left->nd_type == error_type) return 0; if (left->nd_class == Def && (left->nd_def->df_kind & (D_HTYPE|D_TYPE|D_HIDDEN))) { /* It was a type cast. This is of course not portable. @@ -310,7 +312,7 @@ node_error(expp, "only one parameter expected in type cast"); arg = arg->nd_left; if (! chk_expr(arg)) return 0; if (arg->nd_type->tp_size != left->nd_type->tp_size) { -node_error(expp, "size of type in type cast does not match size of operand"); +node_error(expp, "unequal sizes in type cast"); } arg->nd_type = left->nd_type; FreeNode(expp->nd_left); @@ -352,30 +354,59 @@ chk_proccall(expp) register struct node *arg; register struct paramlist *param; - expp->nd_type = left->nd_type->next; - param = left->nd_type->prc_params; arg = expp; + arg->nd_type = left->nd_type->next; + param = left->nd_type->prc_params; while (param) { - arg = getarg(arg, 0); - if (!arg) return 0; - if (param->par_var && - ! TstCompat(param->par_type, arg->nd_left->nd_type)) { -node_error(arg->nd_left, "type incompatibility in var parameter"); - return 0; - } - else - if (!param->par_var && - !TstAssCompat(param->par_type, arg->nd_left->nd_type)) { -node_error(arg->nd_left, "type incompatibility in value parameter"); + if (!(arg = getarg(arg, 0))) return 0; + + if (! TstParCompat(param->par_type, + arg->nd_left->nd_type, + param->par_var)) { +node_error(arg->nd_left, "type incompatibility in parameter"); return 0; } + param = param->next; } + if (arg->nd_right) { node_error(arg->nd_right, "too many parameters supplied"); return 0; } + + return 1; +} + +static int +FlagCheck(expp, df, flag) + struct node *expp; + struct def *df; +{ + /* See the routine "chk_designator" for an explanation of + "flag". Here, a definition "df" is checked against it. + */ + + if ((flag & VARIABLE) && + !(df->df_kind & (D_FIELD|D_VARIABLE))) { + node_error(expp, "variable expected"); + return 0; + } + + if ((flag & HASSELECTORS) && + ( !(df->df_kind & (D_VARIABLE|D_FIELD|D_MODULE)) || + df->df_type->tp_fund != T_RECORD)) { + node_error(expp, "illegal selection"); + return 0; + } + + if ((flag & VALUE) && + ( !(df->df_kind & (D_VARIABLE|D_FIELD|D_CONST|D_ENUM)))) { + node_error(expp, "value expected"); + return 0; + } + return 1; } @@ -384,7 +415,15 @@ chk_designator(expp, flag) register struct node *expp; { /* Find the name indicated by "expp", starting from the current - scope. + scope. "flag" indicates the kind of designator we expect: + It contains the flags VARIABLE, indicating that the result must + be something that can be assigned to. + It may also contain the flag VALUE, indicating that a + value is expected. In this case, VARIABLE may not be set. + It also contains the flag DESIGNATOR, indicating that '[' + and '^' are allowed for this designator. + Also contained may be the flag HASSELECTORS, indicating that + the result must have selectors. */ register struct def *df; register struct type *tp; @@ -403,21 +442,20 @@ chk_designator(expp, flag) assert(expp->nd_symb == '.'); assert(expp->nd_right->nd_class == Name); - if (! chk_designator(expp->nd_left, flag)) return 0; + if (! chk_designator(expp->nd_left, + (flag|HASSELECTORS)&DESIGNATOR)) return 0; + tp = expp->nd_left->nd_type; - if (tp == error_type) return 0; - else if (tp->tp_fund != T_RECORD) { - /* This is also true for modules */ - node_error(expp,"illegal selection"); - return 0; - } - else df = lookup(expp->nd_right->nd_IDF, tp->rec_scope); + + assert(tp->tp_fund == T_RECORD); + + df = lookup(expp->nd_right->nd_IDF, tp->rec_scope); if (!df) { id_not_declared(expp->nd_right); return 0; } - else if (df != ill_df) { + else { expp->nd_type = df->df_type; if (!(df->df_flags & (D_EXPORTED|D_QEXPORTED))) { node_error(expp->nd_right, @@ -434,12 +472,16 @@ df->df_idf->id_text); FreeNode(expp->nd_right); expp->nd_left = expp->nd_right = 0; } - else return 1; + else { + return FlagCheck(expp->nd_right, df, flag); + } } if (expp->nd_class == Def) { df = expp->nd_def; + if (! FlagCheck(expp, df, flag)) return 0; + if (df->df_kind & (D_ENUM | D_CONST)) { if (df->df_kind == D_ENUM) { expp->nd_class = Value; @@ -455,7 +497,7 @@ df->df_idf->id_text); return 1; } - if (flag == QUALONLY) { + if (! (flag & DESIGNATOR)) { node_error(expp, "identifier expected"); return 0; } @@ -466,7 +508,7 @@ df->df_idf->id_text); assert(expp->nd_symb == '['); if ( - !chk_designator(expp->nd_left, DESIGNATOR) + !chk_designator(expp->nd_left, DESIGNATOR|VARIABLE) || !chk_expr(expp->nd_right) || @@ -498,7 +540,10 @@ df->df_idf->id_text); if (expp->nd_class == Uoper) { assert(expp->nd_symb == '^'); - if (! chk_designator(expp->nd_right, DESIGNATOR)) return 0; + if (! chk_designator(expp->nd_right, DESIGNATOR|VARIABLE)) { + return 0; + } + if (expp->nd_right->nd_type->tp_fund != T_POINTER) { node_error(expp, "illegal operand for unary operator \"%s\"", symbol2str(expp->nd_symb)); diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index baca3d8f..ad2bcd17 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -17,6 +17,8 @@ static char *RcsId = "$Header$"; #include "misc.h" #include "main.h" +#include "debug.h" + int proclevel = 0; /* nesting level of procedures */ extern char *sprint(); extern struct def *currentdef; @@ -68,6 +70,10 @@ error("inconsistent procedure declaration for \"%s\"", df->df_idf->id_text); } df->df_type = tp; *pdf = df; + + DO_DEBUG(1, type == D_PROCEDURE && + (print("proc %s:", df->df_idf->id_text), + DumpType(tp), print("\n"))); } ; @@ -107,9 +113,8 @@ FormalParameters(int doparams; '(' [ FPSection(doparams, pr, parmaddr) - { pr1 = *pr; } [ - { for (; pr1->next; pr1 = pr1->next) ; } + { for (pr1 = *pr; pr1->next; pr1 = pr1->next) ; } ';' FPSection(doparams, &(pr1->next), parmaddr) ]* ]? @@ -366,7 +371,7 @@ FieldList(struct scope *scope; arith *cnt; int *palign;) { warning("Old fashioned Modula-2 syntax!"); id = gen_anon_idf(); df = ill_df; - if (chk_designator(nd, QUALONLY) && + if (chk_designator(nd, 0) && (nd->nd_class != Def || !(nd->nd_def->df_kind & (D_ERROR|D_TYPE|D_HTYPE|D_HIDDEN)))) { diff --git a/lang/m2/comp/defmodule.c b/lang/m2/comp/defmodule.c index 808ff845..faf3b629 100644 --- a/lang/m2/comp/defmodule.c +++ b/lang/m2/comp/defmodule.c @@ -26,7 +26,6 @@ GetFile(name) /* Try to find a file with basename "name" and extension ".def", in the directories mentioned in "DEFPATH". */ - extern char *DEFPATH[]; char buf[256]; char *strcpy(), *strcat(); diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index 4348fceb..a3b122ec 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -43,7 +43,7 @@ qualident(int types; struct def **pdf; char *str; struct node **p;) { if (types) { df = ill_df; - if (chk_designator(nd, QUALONLY)) { + if (chk_designator(nd, 0)) { if (nd->nd_class != Def) { node_error(nd, "%s expected", str); } @@ -83,7 +83,7 @@ ExpList(struct node **pnd;) ',' { *nd = MkNode(Link, NULLNODE, NULLNODE, &dot); } expression(&(*nd)->nd_left) - { nd = &((*pnd)->nd_right); } + { nd = &((*nd)->nd_right); } ]* ; diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index 0c453272..afd2b135 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -19,14 +19,14 @@ static char *RcsId = "$Header$"; #include "node.h" #include "debug.h" +#include "ndir.h" char options[128]; int DefinitionModule; int SYSTEMModule = 0; char *ProgName; extern int err_occurred; -char *DEFPATH[128]; -char *getenv(); +char *DEFPATH[NDIRS+1]; struct def *Defined; main(argc, argv) @@ -67,7 +67,8 @@ Compile(src, dst) } LineNumber = 1; FileName = src; - init_DEFPATH(); + DEFPATH[0] = ""; + DEFPATH[NDIRS] = 0; init_idf(); init_cst(); reserve(tkidf); @@ -181,23 +182,6 @@ add_standards() df->enm_next = 0; } -init_DEFPATH() -{ - register char *p = getenv("M2path"); - register int i = 0; - - if (p) { - while (*p) { - DEFPATH[i++] = p; - while (*p && *p != ':') p++; - if (*p) *p++ = '\0'; - } - } - else DEFPATH[i++] = ""; - - DEFPATH[i] = 0; -} - do_SYSTEM() { /* Simulate the reading of the SYSTEM definition module diff --git a/lang/m2/comp/main.h b/lang/m2/comp/main.h index 04ca4ed6..35a0f9ad 100644 --- a/lang/m2/comp/main.h +++ b/lang/m2/comp/main.h @@ -2,17 +2,18 @@ /* $Header$ */ -extern char options[]; /* Indicating which options were given */ +extern char options[]; /* indicating which options were given */ extern int DefinitionModule; - /* Flag indicating that we are reading a definition + /* flag indicating that we are reading a definition module */ -extern int SYSTEMModule;/* Flag indicating that we are handling the SYSTEM +extern int SYSTEMModule;/* flag indicating that we are handling the SYSTEM module */ extern struct def *Defined; - /* Definition structure of module defined in this + /* definition structure of module defined in this compilation */ +extern char *DEFPATH[]; /* search path for DEFINITION MODULE's */ diff --git a/lang/m2/comp/node.H b/lang/m2/comp/node.H index f74fd3ab..f4a30952 100644 --- a/lang/m2/comp/node.H +++ b/lang/m2/comp/node.H @@ -36,5 +36,8 @@ struct node { extern struct node *MkNode(); #define NULLNODE ((struct node *) 0) -#define QUALONLY 0 + #define DESIGNATOR 1 +#define HASSELECTORS 2 +#define VARIABLE 4 +#define VALUE 8 diff --git a/lang/m2/comp/options.c b/lang/m2/comp/options.c index f8bc4881..f372a628 100644 --- a/lang/m2/comp/options.c +++ b/lang/m2/comp/options.c @@ -6,12 +6,15 @@ static char *RcsId = "$Header$"; #include #include "idfsize.h" +#include "ndir.h" #include "type.h" +#include "main.h" -extern char options[]; extern int idfsize; +static int ndirs; + do_option(text) char *text; { @@ -37,6 +40,13 @@ do_option(text) options['p'] = 1; break; + case 'I' : + if (++ndirs >= NDIRS) { + fatal("Too many -I options"); + } + DEFPATH[ndirs] = text; + break; + case 'V' : /* set object sizes and alignment requirements */ { arith size; diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index 2d5b140a..41d1e255 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -436,3 +436,70 @@ lcm(m, n) */ return m * (n / gcd(m, n)); } + +#ifdef DEBUG +DumpType(tp) + register struct type *tp; +{ + print(" a:%d; s:%ld;", tp->tp_align, (long) tp->tp_size); + if (tp->next && tp->tp_fund != T_POINTER) { + /* Avoid printing recursive types! + */ + print(" n:("); + DumpType(tp->next); + print(")"); + } + + print(" f:"); + switch(tp->tp_fund) { + case T_RECORD: + print("RECORD"); break; + case T_ENUMERATION: + print("ENUMERATION; n:%d", tp->enm_ncst); break; + case T_INTEGER: + print("INTEGER"); break; + case T_CARDINAL: + print("CARDINAL"); break; + case T_REAL: + print("REAL"); break; + case T_POINTER: + print("POINTER"); break; + case T_CHAR: + print("CHAR"); break; + case T_WORD: + print("WORD"); break; + case T_SET: + print("SET"); break; + case T_SUBRANGE: + print("SUBRANGE %ld-%ld", (long) tp->sub_lb, (long) tp->sub_ub); + break; + case T_PROCEDURE: + { + register struct paramlist *par = tp->prc_params; + + print("PROCEDURE"); + if (par) { + print("; p:"); + while(par) { + if (par->par_var) print("VAR "); + DumpType(par->par_type); + par = par->next; + } + } + break; + } + case T_ARRAY: + print("ARRAY %ld-%ld", (long) tp->arr_lb, (long) tp->arr_ub); + print("; el:"); + DumpType(tp->arr_elem); + break; + case T_STRING: + print("STRING"); break; + case T_INTORCARD: + print("INTORCARD"); break; + default: + assert(0); + } + print(";"); +} +#endif diff --git a/lang/m2/comp/typequiv.c b/lang/m2/comp/typequiv.c index 2a7c1a81..80c23318 100644 --- a/lang/m2/comp/typequiv.c +++ b/lang/m2/comp/typequiv.c @@ -150,3 +150,21 @@ int TstAssCompat(tp1, tp2) return 0; } + +int TstParCompat(formaltype, actualtype, VARflag) + struct type *formaltype, *actualtype; +{ + /* Check type compatibility for a parameter in a procedure + call + */ + + return + TstCompat(formaltype, actualtype) + || + ( !VARflag && TstAssCompat(formaltype, actualtype)) + || + ( formaltype->tp_fund == T_ARRAY + && formaltype->next == 0 + && actualtype->tp_fund == T_ARRAY + && TstTypeEquiv(formaltype->arr_elem, actualtype->arr_elem)); +} diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index c8fffc56..9e7c2e73 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -181,7 +181,9 @@ WalkStat(nd, lab) register struct node *right = nd->nd_right; if (nd->nd_class == Call) { - /* ??? */ + if (chk_call(nd)) { + /* ??? */ + } return; } @@ -189,6 +191,8 @@ WalkStat(nd, lab) switch(nd->nd_symb) { case BECOMES: + WalkExpr(nd->nd_right); + WalkDesignator(nd->nd_left); /* ??? */ break; @@ -309,6 +313,19 @@ WalkExpr(nd) } } +WalkDesignator(nd) + struct node *nd; +{ + /* Check designator and generate code for it + */ + + DO_DEBUG(1, (DumpTree(nd), print("\n"))); + + if (chk_designator(nd, DESIGNATOR|VARIABLE)) { + /* ??? */ + } +} + #ifdef DEBUG DumpTree(nd) struct node *nd; From 5b9a3d373e99f927b198f21a2e46231360404921 Mon Sep 17 00:00:00 2001 From: erikb Date: Mon, 28 Apr 1986 09:56:33 +0000 Subject: [PATCH 0188/1625] various small layout corrections --- lang/cem/cemcom/declarator.c | 5 +++++ lang/cem/cemcom/error.c | 2 +- lang/cem/cemcom/main.c | 5 +++-- lang/cem/cemcom/stack.c | 38 ++++++++++++++++++------------------ 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/lang/cem/cemcom/declarator.c b/lang/cem/cemcom/declarator.c index 27a9d88c..4eb1a32f 100644 --- a/lang/cem/cemcom/declarator.c +++ b/lang/cem/cemcom/declarator.c @@ -99,6 +99,11 @@ array_subscript(expr) expr->VL_VALUE = (arith)1; } else + if (size == 0) { + warning("empty array declaration"); + expr->VL_VALUE = (arith)-1; + } + else if (size & ~max_unsigned) { /* absolute ridiculous */ expr_error(expr, "overflow in array size"); expr->VL_VALUE = (arith)1; diff --git a/lang/cem/cemcom/error.c b/lang/cem/cemcom/error.c index 054ee73b..6ada030e 100644 --- a/lang/cem/cemcom/error.c +++ b/lang/cem/cemcom/error.c @@ -28,7 +28,7 @@ #define CRASH 5 #define FATAL 6 -int err_occurred; +int err_occurred = 0; extern char *symbol2str(); extern char options[]; diff --git a/lang/cem/cemcom/main.c b/lang/cem/cemcom/main.c index 0cf9425d..feb46491 100644 --- a/lang/cem/cemcom/main.c +++ b/lang/cem/cemcom/main.c @@ -89,10 +89,11 @@ main(argc, argv) not defined! */ #ifdef READ_IN_ONE - while (argc > 1 && *argv[1] == '-') { + while (argc > 1 && *argv[1] == '-') #else READ_IN_ONE - while (argc > 1 && *argv[1] == '-' && argv[1][1] != '\0') { + while (argc > 1 && *argv[1] == '-' && argv[1][1] != '\0') #endif READ_IN_ONE + { char *par = &argv[1][1]; if (*par == '-') diff --git a/lang/cem/cemcom/stack.c b/lang/cem/cemcom/stack.c index 26a849e2..8f939230 100644 --- a/lang/cem/cemcom/stack.c +++ b/lang/cem/cemcom/stack.c @@ -194,7 +194,7 @@ unstack_world() have already been encoded while the uninitialised ones are not and have to be encoded at this moment. */ - struct stack_entry *se = local_level->sl_entry; + register struct stack_entry *se = local_level->sl_entry; open_name_list(); @@ -223,11 +223,12 @@ unstack_world() def->df_used ? "used" : "not used"); } #endif DEBUG - /* find final storage class */ - if (def->df_sc == GLOBAL || def->df_sc == IMPLICIT) { - /* even now we still don't know */ + /* + /_* find final storage class *_/ + if (def->df_sc == GLOBAL || def->df_sc == IMPLICIT) + /_* even now we still don't know *_/ def->df_sc = EXTERN; - } + */ if ( def->df_sc == STATIC && def->df_type->tp_fund == FUNCTION @@ -242,28 +243,27 @@ unstack_world() def->df_sc = EXTERN; } - if ( def->df_alloc == ALLOC_SEEN && + if ( + def->df_alloc == ALLOC_SEEN && !def->df_initialized ) { /* space must be allocated */ bss(idf); namelist(idf->id_text); /* may be common */ - def->df_alloc = ALLOC_DONE; - /* df_alloc must be set to ALLOC_DONE because - the idf entry may occur several times in - the list. - The reason is that the same name may be used - for different purposes on the same level, e.g - struct s {int s;} s; - is a legal definition and contains 3 defining - occurrences of s. Each definition has been - entered into the idfstack. Although only - one of them concerns a variable, we meet the - s 3 times when scanning the idfstack. - */ + def->df_alloc = ALLOC_DONE; /* *) */ } se = se->next; } + /* *) df_alloc must be set to ALLOC_DONE because the idf entry + may occur several times in the list. + The reason for this is that the same name may be used + for different purposes on the same level, e.g + struct s {int s;} s; + is a legal definition and contains 3 defining occurrences of s. + Each definition has been entered into the idfstack. + Although only one of them concerns a variable, we meet the + s 3 times when scanning the idfstack. + */ } /* A list of potential common names is kept, to be fed to From 8b07933e3d36716748063a20fce90219baa7b73f Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 28 Apr 1986 18:06:58 +0000 Subject: [PATCH 0189/1625] newer version --- lang/m2/comp/LLlex.c | 4 +- lang/m2/comp/LLlex.h | 2 +- lang/m2/comp/chk_expr.c | 56 +++++++---- lang/m2/comp/declar.g | 11 +-- lang/m2/comp/def.H | 13 +-- lang/m2/comp/def.c | 190 +++++++++++++++++++++++--------------- lang/m2/comp/enter.c | 34 +++---- lang/m2/comp/expression.g | 26 +++--- lang/m2/comp/program.g | 50 +++++----- lang/m2/comp/scope.C | 43 +++++---- lang/m2/comp/scope.h | 15 ++- lang/m2/comp/statement.g | 1 + lang/m2/comp/type.H | 3 +- lang/m2/comp/type.c | 9 +- lang/m2/comp/typequiv.c | 68 ++++++++++---- lang/m2/comp/walk.c | 82 +++++++++++----- 16 files changed, 379 insertions(+), 228 deletions(-) diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index a1ccd14a..8ebb1d8b 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -76,7 +76,7 @@ GetString(upto) register struct string *str = &string; register char *p; - str->s_str = p = Malloc(str->s_length = ISTRSIZE); + str->s_str = p = Malloc((unsigned int) (str->s_length = ISTRSIZE)); LoadChar(ch); while (ch != upto) { if (class(ch) == STNL) { @@ -91,7 +91,7 @@ GetString(upto) *p++ = ch; if (p - str->s_str == str->s_length) { str->s_str = Srealloc(str->s_str, - str->s_length + RSTRSIZE); + (unsigned int) str->s_length + RSTRSIZE); p = str->s_str + str->s_length; str->s_length += RSTRSIZE; } diff --git a/lang/m2/comp/LLlex.h b/lang/m2/comp/LLlex.h index 69573dd0..0fcddecc 100644 --- a/lang/m2/comp/LLlex.h +++ b/lang/m2/comp/LLlex.h @@ -3,7 +3,7 @@ /* $Header$ */ struct string { - unsigned int s_length; /* length of a string */ + arith s_length; /* length of a string */ char *s_str; /* the string itself */ }; diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index 938fc6f0..95f33384 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -388,6 +388,8 @@ FlagCheck(expp, df, flag) "flag". Here, a definition "df" is checked against it. */ + if (df->df_kind == D_ERROR) return 0; + if ((flag & VARIABLE) && !(df->df_kind & (D_FIELD|D_VARIABLE))) { node_error(expp, "variable expected"); @@ -432,7 +434,7 @@ chk_designator(expp, flag) expp->nd_type = error_type; if (expp->nd_class == Name) { - expp->nd_def = lookfor(expp, CurrentScope, 1); + expp->nd_def = lookfor(expp, CurrVis, 1); expp->nd_class = Def; expp->nd_type = expp->nd_def->df_type; if (expp->nd_type == error_type) return 0; @@ -489,8 +491,15 @@ df->df_idf->id_text); expp->nd_symb = INTEGER; } else { + char *fn; + int ln; + assert(df->df_kind == D_CONST); + ln = expp->nd_lineno; + fn = expp->nd_filename; *expp = *(df->con_const); + expp->nd_lineno = ln; + expp->nd_filename = fn; } } @@ -591,7 +600,7 @@ node_error(expp, "RHS of IN operator not a SET type"); } if (!TstAssCompat(tpl, tpr->next)) { /* Assignment compatible ??? - I don't know! Should we be allowed th check + I don't know! Should we be allowed to check if a CARDINAL is a member of a BITSET??? */ @@ -620,6 +629,9 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R case '-': case '*': switch(tpl->tp_fund) { + case T_POINTER: + if (tpl != address_type) break; + /* Fall through */ case T_INTEGER: case T_CARDINAL: case T_INTORCARD: @@ -654,7 +666,7 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R case DIV: case MOD: - if (tpl->tp_fund & T_INTORCARD) { + if ((tpl->tp_fund & T_INTORCARD) || tpl == address_type) { if (left->nd_class==Value && right->nd_class==Value) { cstbin(expp); } @@ -736,7 +748,8 @@ chk_uoper(expp) { /* Check an unary operation. */ - register struct type *tpr = expp->nd_right->nd_type; + register struct node *right = expp->nd_right; + register struct type *tpr = right->nd_type; if (tpr->tp_fund == T_SUBRANGE) tpr = tpr->next; expp->nd_type = tpr; @@ -744,8 +757,8 @@ chk_uoper(expp) switch(expp->nd_symb) { case '+': if (tpr->tp_fund & T_NUMERIC) { - expp->nd_token = expp->nd_right->nd_token; - FreeNode(expp->nd_right); + expp->nd_token = right->nd_token; + FreeNode(right); expp->nd_right = 0; return 1; } @@ -753,19 +766,19 @@ chk_uoper(expp) case '-': if (tpr->tp_fund & T_INTORCARD) { - if (expp->nd_right->nd_class == Value) { + if (right->nd_class == Value) { cstunary(expp); } return 1; } else if (tpr->tp_fund == T_REAL) { - if (expp->nd_right->nd_class == Value) { - expp->nd_token = expp->nd_right->nd_token; + if (right->nd_class == Value) { + expp->nd_token = right->nd_token; if (*(expp->nd_REL) == '-') { expp->nd_REL++; } else expp->nd_REL--; - FreeNode(expp->nd_right); + FreeNode(right); expp->nd_right = 0; } return 1; @@ -775,7 +788,7 @@ chk_uoper(expp) case NOT: case '~': if (tpr == bool_type) { - if (expp->nd_right->nd_class == Value) { + if (right->nd_class == Value) { cstunary(expp); } return 1; @@ -794,19 +807,27 @@ struct node * getvariable(arg) register struct node *arg; { + struct def *df; + register struct node *left; + arg = arg->nd_right; if (!arg) { node_error(arg, "too few parameters supplied"); return 0; } - if (! chk_designator(arg->nd_left, DESIGNATOR)) return 0; - if (arg->nd_left->nd_class == Oper || arg->nd_left->nd_class == Uoper) { + left = arg->nd_left; + + if (! chk_designator(left, DESIGNATOR)) return 0; + if (left->nd_class == Oper || left->nd_class == Uoper) { return arg; } - if (arg->nd_left->nd_class != Def || - !(arg->nd_left->nd_def->df_kind & (D_VARIABLE|D_FIELD))) { + df = 0; + if (left->nd_class == Link) df = left->nd_right->nd_def; + else if (left->nd_class == Def) df = left->nd_def; + + if (!df || !(df->df_kind & (D_VARIABLE|D_FIELD))) { node_error(arg, "variable expected"); return 0; } @@ -947,7 +968,10 @@ node_error(arg, "EXCL and INCL expect a SET parameter"); return 0; } if (!(arg = getarg(arg, T_DISCRETE))) return 0; - if (!TstCompat(tp->next, arg->nd_left->nd_type)) { + if (!TstAssCompat(tp->next, arg->nd_left->nd_type)) { + /* What type of compatibility do we want here? + apparently assignment compatibility! ??? ??? + */ node_error(arg, "unexpected type"); return 0; } diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index ad2bcd17..924f63e2 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -37,7 +37,7 @@ ProcedureDeclaration ';' block(&(df->prc_body)) IDENT { match_id(dot.TOK_IDF, df->df_idf); - df->prc_scope = CurrentScope; + df->prc_vis = CurrVis; close_scope(SC_CHKFORW|SC_REVERSE); proclevel--; currentdef = savecurr; @@ -182,14 +182,9 @@ TypeDeclaration '=' type(&tp) { if (df->df_type) free_type(df->df_type); df->df_type = tp; - if ((df->df_flags&D_EXPORTED) && - tp->tp_fund == T_ENUMERATION) { - exprt_literals(tp->enm_enums, - enclosing(CurrentScope)); - } if (df->df_kind == D_HTYPE && tp->tp_fund != T_POINTER) { -error("Opaque type \"%s\" is not a pointer type", df->df_idf->id_text); +error("opaque type \"%s\" is not a pointer type", df->df_idf->id_text); } } ; @@ -493,7 +488,7 @@ PointerType(struct type **ptp;) else tp = df->df_type; } | %if ( nd = new_node(), nd->nd_token = dot, - df = lookfor(nd, CurrentScope, 0), free_node(nd), + df = lookfor(nd, CurrVis, 0), free_node(nd), df->df_kind == D_MODULE) type(&tp) | diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H index 9810bd29..131f67f1 100644 --- a/lang/m2/comp/def.H +++ b/lang/m2/comp/def.H @@ -4,11 +4,11 @@ struct module { arith mo_priority; /* priority of a module */ - struct scope *mo_scope; /* scope of this module */ + struct scopelist *mo_vis;/* scope of this module */ struct node *mo_body; /* body of this module */ int mo_number; /* number of this module */ #define mod_priority df_value.df_module.mo_priority -#define mod_scope df_value.df_module.mo_scope +#define mod_vis df_value.df_module.mo_vis #define mod_body df_value.df_module.mo_body #define mod_number df_value.df_module.mo_number }; @@ -51,11 +51,11 @@ struct field { }; struct dfproc { - struct scope *pr_scope; /* scope of procedure */ + struct scopelist *pr_vis; /* scope of procedure */ short pr_level; /* depth level of this procedure */ arith pr_nbpar; /* number of bytes parameters */ struct node *pr_body; /* body of this procedure */ -#define prc_scope df_value.df_proc.pr_scope +#define prc_vis df_value.df_proc.pr_vis #define prc_level df_value.df_proc.pr_level #define prc_nbpar df_value.df_proc.pr_nbpar #define prc_body df_value.df_proc.pr_body @@ -67,11 +67,12 @@ struct import { }; struct dforward { - struct scope *fo_scope; + struct scopelist *fo_vis; struct node *fo_node; char *fo_name; #define for_node df_value.df_forward.fo_node -#define for_scope df_value.df_forward.fo_scope +#define for_vis df_value.df_forward.fo_vis +#define for_scopes df_value.df_forward.fo_scopes #define for_name df_value.df_forward.fo_name }; diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index 64e8adbf..295e5c4a 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -35,11 +35,10 @@ MkDef(id, scope, kind) register struct def *df; df = new_def(); - df->df_flags = 0; + clear((char *) df, sizeof (*df)); df->df_idf = id; df->df_scope = scope; df->df_kind = kind; - df->df_type = 0; df->next = id->id_def; id->id_def = df; @@ -66,8 +65,7 @@ define(id, scope, kind) if ( /* Already in this scope */ df || /* A closed scope, and id defined in the pervasive scope */ - ( CurrentScope == scope - && + ( scopeclosed(scope) && (df = lookup(id, PervasiveScope))) @@ -79,31 +77,40 @@ define(id, scope, kind) return df; } break; + case D_FORWMODULE: if (kind == D_FORWMODULE) { return df; } + if (kind == D_MODULE) { FreeNode(df->for_node); - df->mod_scope = df->for_scope; + df->mod_vis = df->for_vis; df->df_kind = kind; return df; } break; + case D_FORWARD: if (kind != D_FORWARD) { FreeNode(df->for_node); } - /* Fall Through */ + + df->df_kind = kind; + return df; + case D_ERROR: df->df_kind = kind; return df; } + if (kind != D_ERROR) { error("identifier \"%s\" already declared", id->id_text); } + return df; } + return MkDef(id, scope, kind); } @@ -129,7 +136,6 @@ lookup(id, scope) retval = df->imp_def; assert(retval != 0); } - if (df1) { df1->next = df->next; df->next = id->id_def; @@ -143,8 +149,38 @@ lookup(id, scope) return 0; } -Export(ids, qualified) +DoImport(df, scope) + struct def *df; + struct scope *scope; +{ + register struct def *df1; + + if (df->df_kind == D_TYPE && df->df_type->tp_fund == T_ENUMERATION) { + /* Also import all enumeration literals + */ + df1 = df->df_type->enm_enums; + while (df1) { + define(df1->df_idf, scope, D_IMPORT)->imp_def = df1; + df1 = df1->enm_next; + } + } + else if (df->df_kind == D_MODULE) { + /* Also import all definitions that are exported from this + module + */ + df1 = df->mod_vis->sc_scope->sc_def; + while (df1) { + if (df1->df_flags & D_EXPORTED) { + define(df1->df_idf, scope, D_IMPORT)->imp_def = df1; + } + df1 = df1->df_nextinscope; + } + } +} + +Export(ids, qualified, moddef) register struct node *ids; + struct def *moddef; { /* From the current scope, the list of identifiers "ids" is exported. Note this fact. If the export is not qualified, make @@ -152,47 +188,71 @@ Export(ids, qualified) in this scope as "imported". */ register struct def *df, *df1; - struct node *nd = ids; + register struct def *impmod; - while (ids) { + for (;ids; ids = ids->next) { df = lookup(ids->nd_IDF, CurrentScope); - if (df && (df->df_flags & (D_EXPORTED|D_QEXPORTED))) { + + if (!df) { + /* undefined item in export list + */ +node_error(ids, "identifier \"%s\" not defined", ids->nd_IDF->id_text); + continue; + } + + if (df->df_flags & (D_EXPORTED|D_QEXPORTED)) { node_error(ids, "Identifier \"%s\" occurs more than once in export list", df->df_idf->id_text); } - else if (!df) { - df = define(ids->nd_IDF, CurrentScope, D_FORWARD); - df->for_node = MkNode(Name,NULLNODE,NULLNODE, - &(ids->nd_token)); - } + if (qualified) { df->df_flags |= D_QEXPORTED; } else { + /* Export, but not qualified. + Find all imports of the module in which this export + occurs, and export the current definition to it + */ + impmod = moddef->df_idf->id_def; + while (impmod) { + if (impmod->df_kind == D_IMPORT && + impmod->imp_def == moddef) { + DoImport(df, impmod->df_scope); + } + impmod = impmod->next; + } + df->df_flags |= D_EXPORTED; - df1 = lookup(ids->nd_IDF, enclosing(CurrentScope)); - if (! df1 || !(df1->df_kind & (D_PROCHEAD|D_HIDDEN))) { - df1 = define(ids->nd_IDF, - enclosing(CurrentScope), + df1 = lookup(ids->nd_IDF, enclosing(CurrVis)->sc_scope); + if (df1 && df1->df_kind == D_PROCHEAD) { + if (df->df_kind == D_PROCEDURE) { + df1->df_kind = D_IMPORT; + df1->imp_def = df; + continue; + } + } + else if (df1 && df1->df_kind == D_HIDDEN) { + if (df->df_kind == D_TYPE) { + if (df->df_type->tp_fund != T_POINTER) { +error("Opaque type \"%s\" is not a pointer type", df->df_idf->id_text); + } + df->df_kind = D_HTYPE; + df1->df_kind = D_IMPORT; + df1->imp_def = df; + continue; + } + } + + df1 = define(ids->nd_IDF, + enclosing(CurrVis)->sc_scope, D_IMPORT); - } - else { - /* A hidden type or a procedure of which only - the head is seen. Apparently, they are - exported from a local module! - */ - df->df_kind = df1->df_kind; - df->df_value.df_forward = df1->df_value.df_forward; - df1->df_kind = D_IMPORT; - } df1->imp_def = df; + DoImport(df, enclosing(CurrVis)->sc_scope); } - ids = ids->next; } - FreeNode(nd); } -static struct scope * +static struct scopelist * ForwModule(df, idn) register struct def *df; struct node *idn; @@ -200,22 +260,22 @@ ForwModule(df, idn) /* An import is done from a not yet defined module "idn". Create a declaration and a scope for this module. */ - struct scope *scope; + struct scopelist *vis; - df->df_scope = enclosing(CurrentScope); + df->df_scope = enclosing(CurrVis)->sc_scope; df->df_kind = D_FORWMODULE; open_scope(CLOSEDSCOPE); - scope = CurrentScope; /* The new scope, but watch out, it's "next" + vis = CurrVis; /* The new scope, but watch out, it's "sc_encl" field is not set right. It must indicate the enclosing scope, but this must be done AFTER closing this one */ - df->for_scope = scope; + df->for_vis = vis; df->for_node = MkNode(Name, NULLNODE, NULLNODE, &(idn->nd_token)); close_scope(0); - scope->next = df->df_scope; + vis->sc_encl = enclosing(CurrVis); /* Here ! */ - return scope; + return vis; } static struct def * @@ -253,8 +313,7 @@ Import(ids, idn, local) identifiers defined in this module. */ register struct def *df; - struct scope *scope = enclosing(CurrentScope); - int kind = D_IMPORT; + struct scopelist *vis = enclosing(CurrVis); int forwflag = 0; #define FROM_MODULE 0 #define FROM_ENCLOSING 1 @@ -264,7 +323,7 @@ Import(ids, idn, local) if (idn) { imp_kind = FROM_MODULE; if (local) { - df = lookfor(idn, scope, 0); + df = lookfor(idn, vis, 0); switch(df->df_kind) { case D_ERROR: /* The module from which the import was done @@ -272,23 +331,22 @@ Import(ids, idn, local) accept this, but for the time being I will. ??? */ - scope = ForwModule(df, idn); + vis = ForwModule(df, idn); forwflag = 1; break; case D_FORWMODULE: - scope = df->for_scope; + vis = df->for_vis; break; case D_MODULE: - scope = df->mod_scope; + vis = df->mod_vis; break; default: - kind = D_ERROR; node_error(idn, "identifier \"%s\" does not represent a module", idn->nd_IDF->id_text); break; } } - else scope = GetDefinitionModule(idn->nd_IDF)->mod_scope; + else vis = GetDefinitionModule(idn->nd_IDF)->mod_vis; FreeNode(idn); } @@ -297,9 +355,9 @@ idn->nd_IDF->id_text); while (ids) { if (imp_kind == FROM_MODULE) { if (forwflag) { - df = ForwDef(ids, scope); + df = ForwDef(ids, vis->sc_scope); } - else if (!(df = lookup(ids->nd_IDF, scope))) { + else if (!(df = lookup(ids->nd_IDF, vis->sc_scope))) { node_error(ids, "identifier \"%s\" not declared in qualifying module", ids->nd_IDF->id_text); df = ill_df; @@ -310,40 +368,20 @@ ids->nd_IDF->id_text); } } else { - if (local) df = ForwDef(ids, scope); + if (local) df = ForwDef(ids, vis->sc_scope); else df = GetDefinitionModule(ids->nd_IDF); } DO_DEBUG(2, debug("importing \"%s\", kind %d", ids->nd_IDF->id_text, df->df_kind)); - define(ids->nd_IDF, CurrentScope, kind)->imp_def = df; - if (df->df_kind == D_TYPE && - df->df_type->tp_fund == T_ENUMERATION) { - /* Also import all enumeration literals - */ - exprt_literals(df->df_type->enm_enums, CurrentScope); - } + define(df->df_idf, CurrentScope, D_IMPORT)->imp_def = df; + DoImport(df, CurrentScope); ids = ids->next; } FreeNode(idn); } -exprt_literals(df, toscope) - register struct def *df; - struct scope *toscope; -{ - /* A list of enumeration literals is exported. This is implemented - as an import from the scope "toscope". - */ - DO_DEBUG(3, debug("enumeration import:")); - while (df) { - DO_DEBUG(3, debug(df->df_idf->id_text)); - define(df->df_idf, toscope, D_IMPORT)->imp_def = df; - df = df->enm_next; - } -} - RemImports(pdf) struct def **pdf; { @@ -417,18 +455,18 @@ DeclProc(type) df->df_kind = D_PROCEDURE; open_scope(OPENSCOPE); CurrentScope->sc_name = df->for_name; - df->prc_scope = CurrentScope; + df->prc_vis = CurrVis; } else { df = define(dot.TOK_IDF, CurrentScope, type); - if (CurrentScope != Defined->mod_scope) { + if (CurrVis != Defined->mod_vis) { sprint(buf, "_%d_%s", ++nmcount, df->df_idf->id_text); } - else (sprint(buf, "%s_%s",df->df_scope->sc_name, + else (sprint(buf, "%s_%s",CurrentScope->sc_name, df->df_idf->id_text)); open_scope(OPENSCOPE); - df->prc_scope = CurrentScope; + df->prc_vis = CurrVis; CurrentScope->sc_name = Malloc((unsigned)(strlen(buf)+1)); strcpy(CurrentScope->sc_name, buf); C_inp(buf); diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index 338b1270..b96d7a17 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -103,17 +103,17 @@ EnterVarList(IdList, type, local) procedure */ register struct def *df; - register struct scope *scope; + register struct scopelist *sc; char buf[256]; extern char *sprint(), *Malloc(), *strcpy(); - scope = CurrentScope; + sc = CurrVis; if (local) { /* Find the closest enclosing open scope. This is the procedure that we are dealing with */ - while (scope->sc_scopeclosed) scope = scope->next; + while (sc->sc_scope->sc_scopeclosed) sc = enclosing(sc); } while (IdList) { @@ -133,23 +133,25 @@ node_error(IdList->nd_left,"Illegal type for address"); as the variable list exists only local to a procedure */ - scope->sc_off = -align(type->tp_size - scope->sc_off, + sc->sc_scope->sc_off = + -align(type->tp_size - sc->sc_scope->sc_off, type->tp_align); - df->var_off = scope->sc_off; + df->var_off = sc->sc_scope->sc_off; } else if (!DefinitionModule && - CurrentScope != Defined->mod_scope) { + CurrVis != Defined->mod_vis) { /* variable list belongs to an internal global module. Align offset and add size */ - scope->sc_off = align(scope->sc_off, type->tp_align); - df->var_off = scope->sc_off; - scope->sc_off += type->tp_size; + sc->sc_scope->sc_off = + align(sc->sc_scope->sc_off, type->tp_align); + df->var_off = sc->sc_scope->sc_off; + sc->sc_scope->sc_off += type->tp_size; } else { /* Global name, possibly external */ - sprint(buf,"%s_%s", df->df_scope->sc_name, + sprint(buf,"%s_%s", sc->sc_scope->sc_name, df->df_idf->id_text); df->var_name = Malloc((unsigned)(strlen(buf)+1)); strcpy(df->var_name, buf); @@ -165,26 +167,26 @@ node_error(IdList->nd_left,"Illegal type for address"); } struct def * -lookfor(id, scope, give_error) +lookfor(id, vis, give_error) struct node *id; - struct scope *scope; + struct scopelist *vis; { /* Look for an identifier in the visibility range started by - "scope". + "vis". If it is not defined, maybe give an error message, and create a dummy definition. */ struct def *df; - register struct scope *sc = scope; + register struct scopelist *sc = vis; struct def *MkDef(); while (sc) { - df = lookup(id->nd_IDF, sc); + df = lookup(id->nd_IDF, sc->sc_scope); if (df) return df; sc = nextvisible(sc); } if (give_error) id_not_declared(id); - return MkDef(id->nd_IDF, scope, D_ERROR); + return MkDef(id->nd_IDF, vis->sc_scope, D_ERROR); } diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index a3b122ec..1509eb94 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -10,7 +10,6 @@ static char *RcsId = "$Header$"; #include "LLlex.h" #include "idf.h" #include "def.h" -#include "scope.h" #include "node.h" #include "const.h" #include "type.h" @@ -170,6 +169,7 @@ factor(struct node **p;) { struct def *df; struct node *nd; + register struct type *tp; } : qualident(0, &df, (char *) 0, p) [ @@ -189,18 +189,20 @@ factor(struct node **p;) | %default number(p) | - STRING { - *p = MkNode(Value, NULLNODE, NULLNODE, &dot); - if (dot.TOK_SLE == 1) { - int i; + STRING { + *p = MkNode(Value, NULLNODE, NULLNODE, &dot); + if (dot.TOK_SLE == 1) { + int i; - i = *(dot.TOK_STR) & 0377; - (*p)->nd_type = charc_type; - free(dot.TOK_STR); - dot.TOK_INT = i; - } - else (*p)->nd_type = string_type; - } + tp = charc_type; + i = *(dot.TOK_STR) & 0377; + free(dot.TOK_STR); + free((char *) dot.tk_data.tk_str); + dot.TOK_INT = i; + } + else tp = standard_type(T_STRING, 1, dot.TOK_SLE); + (*p)->nd_type = tp; + } | '(' expression(p) ')' | diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 298bd74e..3a54619e 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -52,6 +52,8 @@ ModuleDeclaration static int modulecount = 0; char buf[256]; struct node *nd; + struct node *exportlist = 0; + int qualified; extern char *sprint(), *Malloc(), *strcpy(); } : MODULE IDENT { @@ -59,14 +61,14 @@ ModuleDeclaration df = define(id, CurrentScope, D_MODULE); currentdef = df; - if (!df->mod_scope) { + if (!df->mod_vis) { open_scope(CLOSEDSCOPE); - df->mod_scope = CurrentScope; + df->mod_vis = CurrVis; } - else CurrentScope = df->mod_scope; + else CurrVis = df->mod_vis; df->df_type = standard_type(T_RECORD, 0, (arith) 0); - df->df_type->rec_scope = df->mod_scope; + df->df_type->rec_scope = df->mod_vis->sc_scope; df->mod_number = ++modulecount; sprint(buf, "__%d%s", df->mod_number, id->id_text); CurrentScope->sc_name = @@ -78,9 +80,13 @@ ModuleDeclaration priority(&(df->mod_priority))? ';' import(1)* - export(0)? + export(&qualified, &exportlist, 0)? block(&nd) IDENT { InitProc(nd, df); + if (exportlist) { + Export(exportlist, qualified, df); + FreeNode(exportlist); + } close_scope(SC_CHKFORW|SC_CHKPROC|SC_REVERSE); match_id(id, dot.TOK_IDF); currentdef = savecurr; @@ -100,24 +106,21 @@ priority(arith *pprio;) } ; -export(int def;) +export(int *QUALflag; struct node **ExportList; int def;) { - struct node *ExportList; - int QUALflag = 0; } : EXPORT [ QUALIFIED - { QUALflag = 1; } - ]? - IdentList(&ExportList) ';' + { *QUALflag = 1; } + | + { *QUALflag = 0; } + ] + IdentList(ExportList) ';' { - if (!def) { - Export(ExportList, QUALflag); - } - else { -node_warning(ExportList, "export list in definition module ignored"); - FreeNode(ExportList); + if (def) { +node_warning(*ExportList, "export list in definition module ignored"); + FreeNode(*ExportList); } } ; @@ -146,6 +149,8 @@ DefinitionModule { register struct def *df; struct idf *id; + struct node *exportlist; + int dummy; } : DEFINITION MODULE IDENT { @@ -153,18 +158,18 @@ DefinitionModule df = define(id, GlobalScope, D_MODULE); if (!SYSTEMModule) open_scope(CLOSEDSCOPE); if (!Defined) Defined = df; - df->mod_scope = CurrentScope; + df->mod_vis = CurrVis; df->mod_number = 0; CurrentScope->sc_name = id->id_text; df->df_type = standard_type(T_RECORD, 0, (arith) 0); - df->df_type->rec_scope = df->mod_scope; + df->df_type->rec_scope = df->mod_vis->sc_scope; DefinitionModule++; DO_DEBUG(1, debug("Definition module \"%s\" %d", id->id_text, DefinitionModule)); } ';' import(0)* - export(1)? + export(&dummy, &exportlist, 1)? /* New Modula-2 does not have export lists in definition modules. For the time being, we ignore export lists here, and a warning is issued. @@ -237,14 +242,15 @@ ProgramModule(int state;) DEFofIMPL = 1; df = GetDefinitionModule(id); currentdef = df; - CurrentScope = df->mod_scope; + CurrVis = df->mod_vis; + CurrentScope = CurrVis->sc_scope; DEFofIMPL = 0; } else { df = define(id, CurrentScope, D_MODULE); Defined = df; open_scope(CLOSEDSCOPE); - df->mod_scope = CurrentScope; + df->mod_vis = CurrVis; df->mod_number = 0; CurrentScope->sc_name = id->id_text; } diff --git a/lang/m2/comp/scope.C b/lang/m2/comp/scope.C index 9aad947a..fbb6f6c4 100644 --- a/lang/m2/comp/scope.C +++ b/lang/m2/comp/scope.C @@ -16,16 +16,21 @@ static char *RcsId = "$Header$"; #include "debug.h" -struct scope *CurrentScope, *PervasiveScope, *GlobalScope; +struct scope *PervasiveScope, *GlobalScope; +struct scopelist *CurrVis; static int scp_level; +static struct scopelist *PervVis; /* STATICALLOCDEF "scope" */ +/* STATICALLOCDEF "scopelist" */ + open_scope(scopetype) { /* Open a scope that is either open (automatic imports) or closed. */ register struct scope *sc = new_scope(); + register struct scopelist *ls = new_scopelist(); assert(scopetype == OPENSCOPE || scopetype == CLOSEDSCOPE); sc->sc_scopeclosed = scopetype == CLOSEDSCOPE; @@ -33,26 +38,30 @@ open_scope(scopetype) sc->sc_forw = 0; sc->sc_def = 0; sc->sc_off = 0; - sc->next = 0; - DO_DEBUG(1, debug("Opening a %s scope", - scopetype == OPENSCOPE ? "open" : "closed")); - if (CurrentScope != PervasiveScope) { - sc->next = CurrentScope; + if (scopetype == OPENSCOPE) { + ls->next = CurrVis; } - CurrentScope = sc; + else ls->next = PervVis; + ls->sc_scope = sc; + ls->sc_encl = CurrVis; + CurrVis = ls; } init_scope() { register struct scope *sc = new_scope(); + register struct scopelist *ls = new_scopelist(); sc->sc_scopeclosed = 0; sc->sc_forw = 0; sc->sc_def = 0; sc->sc_level = scp_level++; - sc->next = 0; PervasiveScope = sc; - CurrentScope = sc; + ls->next = 0; + ls->sc_encl = 0; + ls->sc_scope = PervasiveScope; + PervVis = ls; + CurrVis = ls; } struct forwards { @@ -127,15 +136,15 @@ node_error((*pdf)->for_node, "identifier \"%s\" has not been declared", Maybe the definitions are in the enclosing scope? */ - struct scope *sc; + struct scopelist *ls; - sc = enclosing(CurrentScope); + ls = nextvisible(CurrVis); if ((*pdf)->df_kind == D_FORWMODULE) { - (*pdf)->for_scope->next = sc; + (*pdf)->for_vis->next = ls; } - (*pdf)->df_nextinscope = sc->sc_def; - sc->sc_def = *pdf; - (*pdf)->df_scope = sc; + (*pdf)->df_nextinscope = ls->sc_scope->sc_def; + ls->sc_scope->sc_def = *pdf; + (*pdf)->df_scope = ls->sc_scope; *pdf = df1; } } @@ -154,7 +163,7 @@ rem_forwards(fo) struct def *lookfor(); while (f = fo) { - df = lookfor(&(f->fo_tok), CurrentScope, 1); + df = lookfor(&(f->fo_tok), CurrVis, 1); if (!(df->df_kind & (D_TYPE|D_HTYPE|D_ERROR))) { node_error(&(f->fo_tok), "identifier \"%s\" not a type", df->df_idf->id_text); @@ -216,7 +225,7 @@ close_scope(flag) if (flag & SC_CHKFORW) chk_forw(&(sc->sc_def)); if (flag & SC_REVERSE) Reverse(&(sc->sc_def)); } - CurrentScope = sc->next; + CurrVis = enclosing(CurrVis); scp_level = CurrentScope->sc_level; } diff --git a/lang/m2/comp/scope.h b/lang/m2/comp/scope.h index adddeef5..4bee7e82 100644 --- a/lang/m2/comp/scope.h +++ b/lang/m2/comp/scope.h @@ -25,11 +25,20 @@ struct scope { int sc_level; /* level of this scope */ }; +struct scopelist { + struct scopelist *next; + struct scopelist *sc_encl; + struct scope *sc_scope; +}; + extern struct scope - *CurrentScope, *PervasiveScope, *GlobalScope; -#define enclosing(x) ((x)->next) +extern struct scopelist + *CurrVis; + +#define CurrentScope (CurrVis->sc_scope) +#define enclosing(x) ((x)->sc_encl) #define scopeclosed(x) ((x)->sc_scopeclosed) -#define nextvisible(x) (scopeclosed(x) ? PervasiveScope : enclosing(x)) +#define nextvisible(x) ((x)->next) /* use with scopelists */ diff --git a/lang/m2/comp/statement.g b/lang/m2/comp/statement.g index 1b068826..c6010473 100644 --- a/lang/m2/comp/statement.g +++ b/lang/m2/comp/statement.g @@ -5,6 +5,7 @@ static char *RcsId = "$Header$"; #include #include + #include "idf.h" #include "LLlex.h" #include "scope.h" diff --git a/lang/m2/comp/type.H b/lang/m2/comp/type.H index f206e6cd..e1595d4f 100644 --- a/lang/m2/comp/type.H +++ b/lang/m2/comp/type.H @@ -97,7 +97,6 @@ extern struct type *word_type, *address_type, *intorcard_type, - *string_type, *bitset_type, *std_type, *error_type; /* All from type.c */ @@ -130,3 +129,5 @@ struct type *subr_type(); /* All from type.c */ #define NULLTYPE ((struct type *) 0) + +#define IsConformantArray(tpx) ((tpx)->tp_fund == T_ARRAY && (tpx)->next == 0) diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index 41d1e255..f5424023 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -50,7 +50,6 @@ struct type *word_type, *address_type, *intorcard_type, - *string_type, *bitset_type, *std_type, *error_type; @@ -152,8 +151,8 @@ init_types() char_type = standard_type(T_CHAR, 1, (arith) 1); char_type->enm_ncst = 256; - /* character constant, different from char because of compatibility - with ARRAY OF CHAR + /* character constant type, different from character type because + of compatibility with character array's */ charc_type = standard_type(T_CHAR, 1, (arith) 1); charc_type->enm_ncst = 256; @@ -176,10 +175,6 @@ init_types() real_type = standard_type(T_REAL, float_align, float_size); longreal_type = standard_type(T_REAL, double_align, double_size); - /* string constant type - */ - string_type = standard_type(T_STRING, 1, (arith) -1); - /* SYSTEM types */ word_type = standard_type(T_WORD, word_align, word_size); diff --git a/lang/m2/comp/typequiv.c b/lang/m2/comp/typequiv.c index 80c23318..6ccd9aa7 100644 --- a/lang/m2/comp/typequiv.c +++ b/lang/m2/comp/typequiv.c @@ -39,13 +39,9 @@ TstParEquiv(tp1, tp2) TstTypeEquiv(tp1, tp2) || ( - tp1->tp_fund == T_ARRAY + IsConformantArray(tp1) && - tp1->next == 0 - && - tp2->tp_fund == T_ARRAY - && - tp2->next == 0 + IsConformantArray(tp2) && TstTypeEquiv(tp1->arr_elem, tp2->arr_elem) ); @@ -61,11 +57,15 @@ TstProcEquiv(tp1, tp2) */ register struct paramlist *p1, *p2; - if (!TstTypeEquiv(tp1->next, tp2->next)) return 0; + /* First check if the result types are equivalent + */ + if (! TstTypeEquiv(tp1->next, tp2->next)) return 0; p1 = tp1->prc_params; p2 = tp2->prc_params; + /* Now check the parameters + */ while (p1 && p2) { if (p1->par_var != p2->par_var || !TstParEquiv(p1->par_type, p2->par_type)) return 0; @@ -123,10 +123,12 @@ TstCompat(tp1, tp2) ; } -int TstAssCompat(tp1, tp2) +int +TstAssCompat(tp1, tp2) struct type *tp1, *tp2; { /* Test if two types are assignment compatible. + See Def 9.1. */ if (TstCompat(tp1, tp2)) return 1; @@ -138,24 +140,39 @@ int TstAssCompat(tp1, tp2) (tp2->tp_fund & T_INTORCARD)) return 1; if (tp1 == char_type && tp2 == charc_type) return 1; - if (tp1->tp_fund == T_ARRAY && - (tp2 == charc_type || tp2 == string_type)) { - /* Unfortunately the length of the string is not - available here, so this must be tested somewhere else (???) - */ + + if (tp1->tp_fund == T_ARRAY) { + arith size; + + if (! tp1->next) return 0; + + size = tp1->arr_ub - tp1->arr_lb + 1; tp1 = tp1->arr_elem; if (tp1->tp_fund == T_SUBRANGE) tp1 = tp1->next; - return tp1 == char_type; + return + tp1 == char_type + && + ( + tp2 == charc_type + || + (tp2->tp_fund == T_STRING && size >= tp2->tp_size) + ); } return 0; } -int TstParCompat(formaltype, actualtype, VARflag) +int +TstParCompat(formaltype, actualtype, VARflag) struct type *formaltype, *actualtype; { /* Check type compatibility for a parameter in a procedure - call + call. Ordinary type compatibility is sufficient in any case. + Assignment compatibility may do if the parameter is + a value parameter. + Otherwise, a conformant array may do, or an ARRAY OF WORD + may do too. + Or: a WORD may do. */ return @@ -163,8 +180,19 @@ int TstParCompat(formaltype, actualtype, VARflag) || ( !VARflag && TstAssCompat(formaltype, actualtype)) || - ( formaltype->tp_fund == T_ARRAY - && formaltype->next == 0 - && actualtype->tp_fund == T_ARRAY - && TstTypeEquiv(formaltype->arr_elem, actualtype->arr_elem)); + ( formaltype == word_type && actualtype->tp_size == word_size) + || + ( IsConformantArray(formaltype) + && + ( formaltype->arr_elem == word_type + || + ( actualtype->tp_fund == T_ARRAY + && TstTypeEquiv(formaltype->arr_elem,actualtype->arr_elem) + ) + || + ( actualtype->tp_fund == T_STRING + && TstTypeEquiv(formaltype->arr_elem, char_type) + ) + ) + ); } diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index 9e7c2e73..dfd8d643 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -34,11 +34,11 @@ WalkModule(module) /* Walk through a module, and all its local definitions. Also generate code for its body. */ - register struct def *df = module->mod_scope->sc_def; - struct scope *scope; + register struct def *df = module->mod_vis->sc_scope->sc_def; + struct scopelist *vis; - scope = CurrentScope; - CurrentScope = module->mod_scope; + vis = CurrVis; + CurrVis = module->mod_vis; if (!prclev && module->mod_number) { /* This module is a local module, but not within a @@ -46,13 +46,13 @@ WalkModule(module) variables. This is done by generating a "bss", with label "_". */ - arith size = align(CurrentScope->sc_off, word_size); + arith size = align(CurrentScope->sc_off, word_align); if (size == 0) size = word_size; C_df_dnam(&(CurrentScope->sc_name[1])); C_bss_cst(size, (arith) 0, 0); } - else if (CurrentScope == Defined->mod_scope) { + else if (CurrVis == Defined->mod_vis) { /* This module is the module currently being compiled. Again, generate code to allocate storage for its variables, which all have an explicit name. @@ -83,9 +83,9 @@ WalkModule(module) WalkNode(module->mod_body, (label) 0); C_df_ilb(return_label); C_ret((label) 0); - C_end(align(-CurrentScope->sc_off, word_size)); + C_end(align(-CurrentScope->sc_off, word_align)); - CurrentScope = scope; + CurrVis = vis; } WalkProcedure(procedure) @@ -94,11 +94,10 @@ WalkProcedure(procedure) /* Walk through the definition of a procedure and all its local definitions */ - struct scope *scope = CurrentScope; - register struct def *df; + struct scopelist *vis = CurrVis; prclev++; - CurrentScope = procedure->prc_scope; + CurrVis = procedure->prc_vis; WalkDef(CurrentScope->sc_def); @@ -117,7 +116,7 @@ WalkProcedure(procedure) if (func_type) C_ret((arith) align(func_type->tp_size, word_align)); else C_ret((arith) 0); C_end(align(-CurrentScope->sc_off, word_size)); - CurrentScope = scope; + CurrVis = vis; prclev--; } @@ -126,6 +125,7 @@ WalkDef(df) { /* Walk through a list of definitions */ + while (df) { if (df->df_kind == D_MODULE) { WalkModule(df); @@ -142,10 +142,11 @@ MkCalls(df) { /* Generate calls to initialization routines of modules */ + while (df) { if (df->df_kind == D_MODULE) { C_lxl((arith) 0); - C_cal(df->mod_scope->sc_name); + C_cal(df->mod_vis->sc_scope->sc_name); } df = df->df_nextinscope; } @@ -160,7 +161,7 @@ WalkNode(nd, lab) "lab" represents the label that must be jumped to on encountering an EXIT statement. */ - + while (nd->nd_class == Link) { /* statement list */ WalkStat(nd->nd_left, lab); nd = nd->nd_right; @@ -191,8 +192,13 @@ WalkStat(nd, lab) switch(nd->nd_symb) { case BECOMES: - WalkExpr(nd->nd_right); - WalkDesignator(nd->nd_left); + WalkDesignator(left); + WalkExpr(right); + + if (! TstAssCompat(left->nd_type, right->nd_type)) { + node_error(nd, "type incompatibility in assignment"); + break; + } /* ??? */ break; @@ -217,8 +223,23 @@ WalkStat(nd, lab) } case CASE: - /* ??? */ - break; + { + WalkExpr(left); + + while (right) { + if (right->nd_class == Link && right->nd_symb == '|') { + WalkNode(right->nd_left->nd_right, lab); + right = right->nd_right; + } + else { + WalkNode(right, lab); + right = 0; + } + } + + /* ??? */ + break; + } case WHILE: { label l1, l2; @@ -259,11 +280,27 @@ WalkStat(nd, lab) case FOR: /* ??? */ + WalkNode(right, lab); break; case WITH: - /* ??? */ - break; + { + struct scopelist link; + + WalkDesignator(left); + if (left->nd_type->tp_fund != T_RECORD) { + node_error(left, "record variable expected"); + break; + } + + link.sc_scope = left->nd_type->rec_scope; + link.next = CurrVis; + CurrVis = &link; + WalkNode(right, lab); + CurrVis = link.next; + /* ??? */ + break; + } case EXIT: assert(lab != 0); @@ -274,7 +311,10 @@ WalkStat(nd, lab) case RETURN: if (right) { WalkExpr(right); - if (!TstCompat(right->nd_type, func_type)) { + /* What kind of compatibility do we need here ??? + assignment compatibility? + */ + if (!TstAssCompat(func_type, right->nd_type)) { node_error(right, "type incompatibility in RETURN statement"); } } From 07e226dac3eacd153c77a2b71a760c8b56301a4f Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 1 May 1986 19:06:53 +0000 Subject: [PATCH 0190/1625] newer version --- lang/m2/comp/LLlex.c | 11 +- lang/m2/comp/LLlex.h | 1 + lang/m2/comp/LLmessage.c | 4 + lang/m2/comp/Makefile | 3 +- lang/m2/comp/Parameters | 3 +- lang/m2/comp/casestat.C | 279 ++++++++++++++++++++++++++++++++++++++ lang/m2/comp/chk_expr.c | 7 +- lang/m2/comp/cstoper.c | 35 +++-- lang/m2/comp/declar.g | 11 +- lang/m2/comp/def.c | 34 +++-- lang/m2/comp/defmodule.c | 6 +- lang/m2/comp/enter.c | 5 + lang/m2/comp/error.c | 9 +- lang/m2/comp/expression.g | 6 +- lang/m2/comp/main.c | 17 ++- lang/m2/comp/misc.c | 4 + lang/m2/comp/node.H | 1 + lang/m2/comp/node.c | 6 +- lang/m2/comp/options.c | 11 +- lang/m2/comp/program.g | 6 +- lang/m2/comp/scope.C | 8 +- lang/m2/comp/statement.g | 2 + lang/m2/comp/tokenname.c | 2 + lang/m2/comp/type.c | 10 +- lang/m2/comp/typequiv.c | 3 + lang/m2/comp/walk.c | 80 ++++++----- 26 files changed, 468 insertions(+), 96 deletions(-) create mode 100644 lang/m2/comp/casestat.C diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index 8ebb1d8b..9edc42d6 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -1,16 +1,19 @@ /* L E X I C A L A N A L Y S E R F O R M O D U L A - 2 */ +#ifndef NORCSID static char *RcsId = "$Header$"; +#endif + +#include "debug.h" +#include "idfsize.h" +#include "numsize.h" +#include "strsize.h" #include #include #include #include -#include "idfsize.h" -#include "numsize.h" -#include "strsize.h" - #include "input.h" #include "f_info.h" #include "Lpars.h" diff --git a/lang/m2/comp/LLlex.h b/lang/m2/comp/LLlex.h index 0fcddecc..bf207ad9 100644 --- a/lang/m2/comp/LLlex.h +++ b/lang/m2/comp/LLlex.h @@ -18,6 +18,7 @@ struct token { char *tk_real; /* REAL */ arith *tk_set; /* only used in parse tree node */ struct def *tk_def; /* only used in parse tree node */ + label tk_lab; /* only used in parse tree node */ } tk_data; }; diff --git a/lang/m2/comp/LLmessage.c b/lang/m2/comp/LLmessage.c index ad6cd5be..0ea6e86a 100644 --- a/lang/m2/comp/LLmessage.c +++ b/lang/m2/comp/LLmessage.c @@ -1,9 +1,13 @@ /* S Y N T A X E R R O R R E P O R T I N G */ +#ifndef NORCSID static char *RcsId = "$Header$"; +#endif #include #include +#include + #include "idf.h" #include "LLlex.h" #include "Lpars.h" diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index 7d893277..f4d00d07 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -18,7 +18,7 @@ LOBJ = tokenfile.o program.o declar.o expression.o statement.o COBJ = LLlex.o LLmessage.o char.o error.o main.o \ symbol2str.o tokenname.o idf.o input.o type.o def.o \ scope.o misc.o enter.o defmodule.o typequiv.o node.o \ - cstoper.o chk_expr.o options.o walk.o + cstoper.o chk_expr.o options.o walk.o casestat.o OBJ = $(COBJ) $(LOBJ) Lpars.o GENFILES= tokenfile.c \ program.c declar.c expression.c statement.c \ @@ -58,6 +58,7 @@ def.h: def.H make.allocd type.h: type.H make.allocd node.h: node.H make.allocd scope.c: scope.C make.allocd +casestat.c: casestat.C make.allocd char.c: char.tab tab ./tab -fchar.tab >char.c diff --git a/lang/m2/comp/Parameters b/lang/m2/comp/Parameters index 7604bdf9..82e019a8 100644 --- a/lang/m2/comp/Parameters +++ b/lang/m2/comp/Parameters @@ -67,4 +67,5 @@ extern char options[]; #define NDIRS 16 /* maximum number of directories searched */ - +!File: density.h +#define DENSITY 3 /* see casestat.C for an explanation */ diff --git a/lang/m2/comp/casestat.C b/lang/m2/comp/casestat.C new file mode 100644 index 00000000..babfd8b3 --- /dev/null +++ b/lang/m2/comp/casestat.C @@ -0,0 +1,279 @@ +/* C A S E S T A T E M E N T C O D E G E N E R A T I O N */ + +#ifndef NORCSID +static char *RcsId = "$Header$"; +#endif + +#include "debug.h" + +#include +#include +#include +#include + +#include "Lpars.h" +#include "type.h" +#include "LLlex.h" +#include "node.h" + +#include "density.h" + +/* STATICALLOCDEF "caselist" */ + +struct switch_hdr { + struct switch_hdr *next; + label sh_break; + label sh_default; + int sh_nrofentries; + struct type *sh_type; + arith sh_lowerbd; + arith sh_upperbd; + struct case_entry *sh_entries; +}; + +/* STATICALLOCDEF "switch_hdr" */ + +struct case_entry { + struct case_entry *next; + label ce_label; + arith ce_value; +}; + +/* STATICALLOCDEF "case_entry" */ + +/* The constant DENSITY determines when CSA and when CSB instructions + are generated. Reasonable values are: 2, 3, 4. + On machines that have lots of address space and memory, higher values + are also reasonable. On these machines the density of jump tables + may be lower. +*/ +#define compact(nr, low, up) (nr != 0 && (up - low) / nr <= DENSITY) + +extern label text_label(), data_label(); + +CaseCode(nd, exitlabel) + struct node *nd; + label exitlabel; +{ + /* Check the expression, stack a new case header and + fill in the necessary fields. + */ + register struct switch_hdr *sh = new_switch_hdr(); + register struct node *pnode = nd; + register struct case_entry *ce; + register arith val; + label tablabel; + + assert(nd->nd_class == Stat && nd->nd_symb == CASE); + + WalkExpr(nd->nd_left); + sh->sh_type = nd->nd_left->nd_type; + sh->sh_break = text_label(); + sh->sh_default = 0; + sh->sh_nrofentries = 0; + sh->sh_lowerbd = sh->sh_upperbd = (arith)0; /* immaterial ??? */ + sh->sh_entries = (struct case_entry *) 0; /* case-entry list */ + + /* Now, create case label list + */ + while (pnode && pnode->nd_right) { + pnode = pnode->nd_right; + if (pnode->nd_class == Link && pnode->nd_symb == '|') { + if (pnode->nd_left) { + pnode->nd_lab = text_label(); + if (! AddCases(sh, + pnode->nd_left->nd_left, + pnode->nd_lab)) { + FreeSh(sh); + return; + } + } + } + else { + /* Else part + */ + pnode = 0; + sh->sh_default = text_label(); + } + } + + /* Now generate code for the switch itself + */ + tablabel = data_label(); /* the rom must have a label */ + C_df_dlb(tablabel); + if (sh->sh_default) C_rom_ilb(sh->sh_default); + else C_rom_ucon((arith) 0, pointer_size); + if (compact(sh->sh_nrofentries, sh->sh_lowerbd, sh->sh_upperbd)) { + /* CSA */ + + C_rom_cst(sh->sh_lowerbd); + C_rom_cst(sh->sh_upperbd - sh->sh_lowerbd); + ce = sh->sh_entries; + for (val = sh->sh_lowerbd; val <= sh->sh_upperbd; val++) { + assert(ce); + if (val == ce->ce_value) { + C_rom_ilb(ce->ce_label); + ce = ce->next; + } + else if (sh->sh_default) C_rom_ilb(sh->sh_default); + else C_rom_ucon("0", pointer_size); + } + C_lae_dlb(tablabel, (arith)0); /* perform the switch */ + C_csa(word_size); + } + else { /* CSB */ + C_rom_cst((arith)sh->sh_nrofentries); + for (ce = sh->sh_entries; ce; ce = ce->next) { + /* generate the entries: value + prog.label */ + C_rom_cst(ce->ce_value); + C_rom_ilb(ce->ce_label); + } + C_lae_dlb(tablabel, (arith)0); /* perform the switch */ + C_csb(word_size); + } + + /* Now generate code for the cases + */ + pnode = nd; + while (pnode && pnode->nd_right) { + pnode = pnode->nd_right; + if (pnode->nd_class == Link && pnode->nd_symb == '|') { + if (pnode->nd_left) { + C_df_ilb(pnode->nd_lab); + WalkNode(pnode->nd_left->nd_right, exitlabel); + C_bra(sh->sh_break); + } + } + else { + /* Else part + */ + assert(sh->sh_default != 0); + + C_df_ilb(sh->sh_default); + WalkNode(pnode, exitlabel); + pnode = 0; + } + } + + C_df_ilb(sh->sh_break); + FreeSh(sh); +} + +FreeSh(sh) + struct switch_hdr *sh; +{ + /* free the allocated switch structure + */ + register struct case_entry *ce; + + ce = sh->sh_entries; + while (ce) { + struct case_entry *tmp = ce->next; + + free_case_entry(ce); + ce = tmp; + } + + free_switch_hdr(sh); +} + +AddCases(sh, node, lbl) + struct switch_hdr *sh; + struct node *node; + label lbl; +{ + /* Add case labels to the case label list + */ + register arith v1, v2; + + if (node->nd_class == Link) { + if (node->nd_symb == UPTO) { + assert(node->nd_left->nd_class == Value); + assert(node->nd_right->nd_class == Value); + v2 = node->nd_right->nd_INT; + node->nd_type = node->nd_left->nd_type; + for (v1 = node->nd_left->nd_INT; v1 <= v2; v1++) { + node->nd_INT = v1; + if (! AddOneCase(sh, node, lbl)) return 0; + } + return 1; + } + + assert(node->nd_symb == ','); + return AddCases(sh, node->nd_left, lbl) && + AddCases(sh, node->nd_right, lbl); + } + + assert(node->nd_class == Value); + return AddOneCase(sh, node, lbl); +} + +AddOneCase(sh, node, lbl) + register struct switch_hdr *sh; + struct node *node; + label lbl; +{ + register struct case_entry *ce = new_case_entry(); + register struct case_entry *c1 = sh->sh_entries, *c2 = 0; + + ce->ce_label = lbl; + ce->ce_value = node->nd_INT; + if (! TstCompat(sh->sh_type, node->nd_type)) { + node_error(node, "Type incompatibility in case"); + free_case_entry(ce); + return 0; + } + if (sh->sh_entries == 0) { + /* first case entry */ + ce->next = (struct case_entry *) 0; + sh->sh_entries = ce; + sh->sh_lowerbd = sh->sh_upperbd = ce->ce_value; + sh->sh_nrofentries = 1; + } + else { + /* second etc. case entry */ + /* find the proper place to put ce into the list */ + + if (ce->ce_value < sh->sh_lowerbd) sh->sh_lowerbd = ce->ce_value; + else + if (ce->ce_value > sh->sh_upperbd) sh->sh_upperbd = ce->ce_value; + while (c1 && c1->ce_value < ce->ce_value) { + c2 = c1; + c1 = c1->next; + } + /* At this point three cases are possible: + 1: c1 != 0 && c2 != 0: + insert ce somewhere in the middle + 2: c1 != 0 && c2 == 0: + insert ce right after the head + 3: c1 == 0 && c2 != 0: + append ce to last element + The case c1 == 0 && c2 == 0 cannot occur, since + the list is guaranteed not to be empty. + */ + if (c1) { + if (c1->ce_value == ce->ce_value) { + node_error("multiple case entry for value %ld", + ce->ce_value); + free_case_entry(ce); + return 0; + } + if (c2) { + ce->next = c2->next; + c2->next = ce; + } + else { + ce->next = sh->sh_entries; + sh->sh_entries = ce; + } + } + else { + assert(c2); + + ce->next = (struct case_entry *) 0; + c2->next = ce; + } + (sh->sh_nrofentries)++; + } + return 1; +} diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index 95f33384..ad59c7fe 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -1,9 +1,14 @@ /* E X P R E S S I O N C H E C K I N G */ +#ifndef NORCSID static char *RcsId = "$Header$"; +#endif /* Check expressions, and try to evaluate them as far as possible. */ + +#include "debug.h" + #include #include #include @@ -19,8 +24,6 @@ static char *RcsId = "$Header$"; #include "const.h" #include "standards.h" -#include "debug.h" - extern char *symbol2str(); int diff --git a/lang/m2/comp/cstoper.c b/lang/m2/comp/cstoper.c index 8a671aa0..aba69405 100644 --- a/lang/m2/comp/cstoper.c +++ b/lang/m2/comp/cstoper.c @@ -1,13 +1,16 @@ /* C O N S T A N T E X P R E S S I O N H A N D L I N G */ +#ifndef NORCSID static char *RcsId = "$Header$"; +#endif + +#include "debug.h" +#include "target_sizes.h" #include #include #include -#include "target_sizes.h" - #include "idf.h" #include "type.h" #include "LLlex.h" @@ -47,7 +50,7 @@ cstunary(expp) expp->nd_class = Value; expp->nd_token = expp->nd_right->nd_token; expp->nd_INT = o1; - cut_size(expp); + CutSize(expp); FreeNode(expp->nd_right); expp->nd_right = 0; } @@ -64,11 +67,14 @@ cstbin(expp) int uns = expp->nd_type != int_type; assert(expp->nd_class == Oper); - assert(expp->nd_left->nd_class == Value && expp->nd_right->nd_class == Value); + assert(expp->nd_left->nd_class == Value); + assert(expp->nd_right->nd_class == Value); + switch (expp->nd_symb) { case '*': o1 *= o2; break; + case DIV: if (o2 == 0) { node_error(expp, "division by 0"); @@ -106,6 +112,7 @@ cstbin(expp) else o1 /= o2; break; + case MOD: if (o2 == 0) { node_error(expp, "modulo by 0"); @@ -135,12 +142,15 @@ cstbin(expp) else o1 %= o2; break; + case '+': o1 += o2; break; + case '-': o1 -= o2; break; + case '<': if (uns) { o1 = (o1 & mach_long_sign ? @@ -151,6 +161,7 @@ cstbin(expp) else o1 = o1 < o2; break; + case '>': if (uns) { o1 = (o1 & mach_long_sign ? @@ -201,7 +212,7 @@ cstbin(expp) expp->nd_class = Value; expp->nd_token = expp->nd_right->nd_token; expp->nd_INT = o1; - cut_size(expp); + CutSize(expp); FreeNode(expp->nd_left); FreeNode(expp->nd_right); expp->nd_left = expp->nd_right = 0; @@ -318,18 +329,18 @@ cstcall(expp, call) } if (expr->nd_INT < 0) expp->nd_INT = - expr->nd_INT; else expp->nd_INT = expr->nd_INT; - cut_size(expp); + CutSize(expp); break; case S_CAP: if (expr->nd_INT >= 'a' && expr->nd_INT <= 'z') { expp->nd_INT = expr->nd_INT + ('A' - 'a'); } else expp->nd_INT = expr->nd_INT; - cut_size(expp); + CutSize(expp); break; case S_CHR: expp->nd_INT = expr->nd_INT; - cut_size(expp); + CutSize(expp); break; case S_MAX: if (expp->nd_type == int_type) { @@ -363,7 +374,7 @@ cstcall(expp, call) break; case S_ORD: expp->nd_INT = expr->nd_INT; - cut_size(expp); + CutSize(expp); break; case S_SIZE: expp->nd_INT = align(expr->nd_type->tp_size, (int) word_size) / @@ -386,7 +397,7 @@ cstcall(expp, call) ) ) ) node_warning(expp,"overflow in constant expression"); - else cut_size(expp); + else CutSize(expp); break; default: assert(0); @@ -396,7 +407,7 @@ cstcall(expp, call) expp->nd_right = expp->nd_left = 0; } -cut_size(expr) +CutSize(expr) register struct node *expr; { /* The constant value of the expression expr is made to @@ -430,7 +441,7 @@ cut_size(expr) expr->nd_INT = o1; } -init_cst() +InitCst() { int i = 0; arith bt = (arith)0; diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 924f63e2..909e4339 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -1,7 +1,11 @@ /* D E C L A R A T I O N S */ { +#ifndef NORCSID static char *RcsId = "$Header$"; +#endif + +#include "debug.h" #include #include @@ -17,8 +21,6 @@ static char *RcsId = "$Header$"; #include "misc.h" #include "main.h" -#include "debug.h" - int proclevel = 0; /* nesting level of procedures */ extern char *sprint(); extern struct def *currentdef; @@ -382,6 +384,9 @@ FieldList(struct scope *scope; arith *cnt; int *palign;) { id = gen_anon_idf(); } ] { tp = df->df_type; + if (!(tp->tp_fund & T_DISCRETE)) { + error("Illegal type in variant"); + } df = define(id, scope, D_FIELD); df->df_type = tp; df->fld_off = align(*cnt, tp->tp_align); @@ -439,8 +444,8 @@ CaseLabels(struct type **ptp; struct node **pnd;) ConstExpression(&nd2) { if (!TstCompat(nd1->nd_type, nd2->nd_type)) { node_error(nd2,"type incompatibility in case label"); + nd1->nd_type = error_type; } - nd1->nd_type = error_type; (*pnd)->nd_right = nd2; } ]? diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index 295e5c4a..a5781cbe 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -1,6 +1,10 @@ /* D E F I N I T I O N M E C H A N I S M */ +#ifndef NORCSID static char *RcsId = "$Header$"; +#endif + +#include "debug.h" #include #include @@ -15,14 +19,9 @@ static char *RcsId = "$Header$"; #include "LLlex.h" #include "node.h" -#include "debug.h" - struct def *h_def; /* Pointer to free list of def structures */ -static struct def illegal_def = - {0, 0, 0, 0, D_ERROR}; - -struct def *ill_df = &illegal_def; +struct def *ill_df; struct def * MkDef(id, scope, kind) @@ -49,6 +48,16 @@ MkDef(id, scope, kind) return df; } +InitDef() +{ + /* Initialize this module. Easy, the only thing to be initialized + is "illegal_def". + */ + struct idf *gen_anon_idf(); + + ill_df = MkDef(gen_anon_idf(), CurrentScope, D_ERROR); +} + struct def * define(id, scope, kind) register struct idf *id; @@ -59,8 +68,6 @@ define(id, scope, kind) */ register struct def *df; - DO_DEBUG(5, debug("Defining identifier \"%s\", kind = %d", - id->id_text, kind)); df = lookup(id, scope); if ( /* Already in this scope */ df @@ -372,10 +379,9 @@ ids->nd_IDF->id_text); else df = GetDefinitionModule(ids->nd_IDF); } -DO_DEBUG(2, debug("importing \"%s\", kind %d", ids->nd_IDF->id_text, -df->df_kind)); - define(df->df_idf, CurrentScope, D_IMPORT)->imp_def = df; + define(ids->nd_IDF,CurrentScope,D_IMPORT)->imp_def = df; DoImport(df, CurrentScope); + ids = ids->next; } @@ -463,8 +469,8 @@ DeclProc(type) sprint(buf, "_%d_%s", ++nmcount, df->df_idf->id_text); } - else (sprint(buf, "%s_%s",CurrentScope->sc_name, - df->df_idf->id_text)); + else sprint(buf, "%s_%s",CurrentScope->sc_name, + df->df_idf->id_text); open_scope(OPENSCOPE); df->prc_vis = CurrVis; CurrentScope->sc_name = Malloc((unsigned)(strlen(buf)+1)); @@ -491,6 +497,6 @@ InitProc(nd, df) PrDef(df) register struct def *df; { - debug("name: %s, kind: %d", df->df_idf->id_text, df->df_kind); + print("n: %s, k: %d\n", df->df_idf->id_text, df->df_kind); } #endif DEBUG diff --git a/lang/m2/comp/defmodule.c b/lang/m2/comp/defmodule.c index faf3b629..cad40b37 100644 --- a/lang/m2/comp/defmodule.c +++ b/lang/m2/comp/defmodule.c @@ -1,6 +1,10 @@ /* D E F I N I T I O N M O D U L E S */ +#ifndef NORCSID static char *RcsId = "$Header$"; +#endif + +#include "debug.h" #include #include @@ -14,8 +18,6 @@ static char *RcsId = "$Header$"; #include "f_info.h" #include "main.h" -#include "debug.h" - #ifdef DEBUG long sys_filesize(); #endif diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index b96d7a17..336a2e0a 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -1,11 +1,16 @@ /* H I G H L E V E L S Y M B O L E N T R Y A N D L O O K U P */ +#ifndef NORCSID static char *RcsId = "$Header$"; +#endif + +#include "debug.h" #include #include #include #include + #include "idf.h" #include "def.h" #include "type.h" diff --git a/lang/m2/comp/error.c b/lang/m2/comp/error.c index 7c121072..81588868 100644 --- a/lang/m2/comp/error.c +++ b/lang/m2/comp/error.c @@ -5,14 +5,17 @@ number of arguments! */ +#ifndef NORCSID static char *RcsId = "$Header$"; - -#include -#include +#endif #include "errout.h" #include "debug.h" +#include +#include +#include + #include "input.h" #include "f_info.h" #include "LLlex.h" diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index 1509eb94..6825795f 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -1,19 +1,23 @@ /* E X P R E S S I O N S */ { +#ifndef NORCSID static char *RcsId = "$Header$"; +#endif + +#include "debug.h" #include #include #include #include + #include "LLlex.h" #include "idf.h" #include "def.h" #include "node.h" #include "const.h" #include "type.h" -#include "debug.h" } number(struct node **p;) diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index afd2b135..c81078f3 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -1,6 +1,11 @@ /* M A I N P R O G R A M */ +#ifndef NORCSID static char *RcsId = "$Header$"; +#endif + +#include "debug.h" +#include "ndir.h" #include #include @@ -18,9 +23,6 @@ static char *RcsId = "$Header$"; #include "tokenname.h" #include "node.h" -#include "debug.h" -#include "ndir.h" - char options[128]; int DefinitionModule; int SYSTEMModule = 0; @@ -39,7 +41,7 @@ main(argc, argv) while (--argc > 0) { if (**argv == '-') - do_option((*argv++) + 1); + DoOption((*argv++) + 1); else Nargv[Nargc++] = *argv++; } @@ -70,11 +72,12 @@ Compile(src, dst) DEFPATH[0] = ""; DEFPATH[NDIRS] = 0; init_idf(); - init_cst(); + InitCst(); reserve(tkidf); init_scope(); init_types(); - add_standards(); + InitDef(); + AddStandards(); #ifdef DEBUG if (options['l']) { LexScan(); @@ -133,7 +136,7 @@ LexScan() } #endif -add_standards() +AddStandards() { register struct def *df; struct def *Enter(); diff --git a/lang/m2/comp/misc.c b/lang/m2/comp/misc.c index 70c4f824..d28f4efc 100644 --- a/lang/m2/comp/misc.c +++ b/lang/m2/comp/misc.c @@ -1,9 +1,13 @@ /* M I S C E L L A N E O U S R O U T I N E S */ +#ifndef NORCSID static char *RcsId = "$Header$"; +#endif #include #include +#include + #include "f_info.h" #include "misc.h" #include "LLlex.h" diff --git a/lang/m2/comp/node.H b/lang/m2/comp/node.H index f4a30952..c8c29216 100644 --- a/lang/m2/comp/node.H +++ b/lang/m2/comp/node.H @@ -21,6 +21,7 @@ struct node { struct token nd_token; #define nd_set nd_token.tk_data.tk_set #define nd_def nd_token.tk_data.tk_def +#define nd_lab nd_token.tk_data.tk_lab #define nd_symb nd_token.tk_symb #define nd_lineno nd_token.tk_lineno #define nd_filename nd_token.tk_filename diff --git a/lang/m2/comp/node.c b/lang/m2/comp/node.c index e852541e..d0c982c3 100644 --- a/lang/m2/comp/node.c +++ b/lang/m2/comp/node.c @@ -1,16 +1,20 @@ /* N O D E O F A N A B S T R A C T P A R S E T R E E */ +#ifndef NORCSID static char *RcsId = "$Header$"; +#endif + +#include "debug.h" #include #include #include #include + #include "def.h" #include "type.h" #include "LLlex.h" #include "node.h" -#include "debug.h" struct node *h_node; /* header of free list */ diff --git a/lang/m2/comp/options.c b/lang/m2/comp/options.c index f372a628..5206d422 100644 --- a/lang/m2/comp/options.c +++ b/lang/m2/comp/options.c @@ -1,21 +1,22 @@ /* U S E R O P T I O N - H A N D L I N G */ +#ifndef NORCSID static char *RcsId = "$Header$"; - -#include -#include +#endif #include "idfsize.h" #include "ndir.h" +#include +#include + #include "type.h" #include "main.h" extern int idfsize; - static int ndirs; -do_option(text) +DoOption(text) char *text; { switch(*text++) { diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 3a54619e..81444fc5 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -1,7 +1,11 @@ /* O V E R A L L S T R U C T U R E */ { +#ifndef NORCSID static char *RcsId = "$Header$"; +#endif + +#include "debug.h" #include #include @@ -15,8 +19,6 @@ static char *RcsId = "$Header$"; #include "type.h" #include "node.h" -#include "debug.h" - static int DEFofIMPL = 0; /* Flag indicating that we are currently parsing the definition module of the implementation module currently being diff --git a/lang/m2/comp/scope.C b/lang/m2/comp/scope.C index fbb6f6c4..f416ceb6 100644 --- a/lang/m2/comp/scope.C +++ b/lang/m2/comp/scope.C @@ -1,6 +1,10 @@ /* S C O P E M E C H A N I S M */ +#ifndef NORCSID static char *RcsId = "$Header$"; +#endif + +#include "debug.h" #include #include @@ -14,8 +18,6 @@ static char *RcsId = "$Header$"; #include "def.h" #include "node.h" -#include "debug.h" - struct scope *PervasiveScope, *GlobalScope; struct scopelist *CurrVis; static int scp_level; @@ -233,7 +235,7 @@ close_scope(flag) PrScopeDef(df) register struct def *df; { - debug("List of definitions in currently ended scope:"); + print("List of definitions in currently ended scope:\n"); while (df) { PrDef(df); df = df->df_nextinscope; diff --git a/lang/m2/comp/statement.g b/lang/m2/comp/statement.g index c6010473..434de4d8 100644 --- a/lang/m2/comp/statement.g +++ b/lang/m2/comp/statement.g @@ -1,7 +1,9 @@ /* S T A T E M E N T S */ { +#ifndef NORCSID static char *RcsId = "$Header$"; +#endif #include #include diff --git a/lang/m2/comp/tokenname.c b/lang/m2/comp/tokenname.c index a9b9920c..bb248137 100644 --- a/lang/m2/comp/tokenname.c +++ b/lang/m2/comp/tokenname.c @@ -1,6 +1,8 @@ /* T O K E N D E F I N I T I O N S */ +#ifndef NORCSID static char *RcsId = "$Header$"; +#endif #include "tokenname.h" #include "Lpars.h" diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index f5424023..e9f19f97 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -1,16 +1,18 @@ /* T Y P E D E F I N I T I O N M E C H A N I S M */ +#ifndef NORCSID static char *RcsId = "$Header$"; +#endif + +#include "target_sizes.h" +#include "debug.h" +#include "maxset.h" #include #include #include #include -#include "target_sizes.h" -#include "debug.h" -#include "maxset.h" - #include "def.h" #include "type.h" #include "idf.h" diff --git a/lang/m2/comp/typequiv.c b/lang/m2/comp/typequiv.c index 6ccd9aa7..2ddd5cf9 100644 --- a/lang/m2/comp/typequiv.c +++ b/lang/m2/comp/typequiv.c @@ -1,12 +1,15 @@ /* T Y P E E Q U I V A L E N C E */ +#ifndef NORCSID static char *RcsId = "$Header$"; +#endif /* Routines for testing type equivalence, type compatibility, and assignment compatibility */ #include #include + #include "type.h" #include "def.h" diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index dfd8d643..812b48cf 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -1,11 +1,15 @@ /* P A R S E T R E E W A L K E R */ +#ifndef NORCSID static char *RcsId = "$Header$"; +#endif /* Routines to walk through parts of the parse tree, and generate code for these parts. */ +#include "debug.h" + #include #include #include @@ -18,16 +22,26 @@ static char *RcsId = "$Header$"; #include "node.h" #include "Lpars.h" -#include "debug.h" - extern arith align(); static int prclev = 0; -static label instructionlabel = 0; -static label datalabel = 0; +static label instructionlabel; +static label datalabel = 1; static label return_label; static char return_expr_occurred; static struct type *func_type; +label +text_label() +{ + return instructionlabel++; +} + +label +data_label() +{ + return datalabel++; +} + WalkModule(module) register struct def *module; { @@ -182,9 +196,7 @@ WalkStat(nd, lab) register struct node *right = nd->nd_right; if (nd->nd_class == Call) { - if (chk_call(nd)) { - /* ??? */ - } + if (chk_call(nd)) CodeCall(nd); return; } @@ -199,7 +211,9 @@ WalkStat(nd, lab) node_error(nd, "type incompatibility in assignment"); break; } - /* ??? */ + + CodeAssign(nd); + break; case IF: @@ -223,23 +237,8 @@ WalkStat(nd, lab) } case CASE: - { - WalkExpr(left); - - while (right) { - if (right->nd_class == Link && right->nd_symb == '|') { - WalkNode(right->nd_left->nd_right, lab); - right = right->nd_right; - } - else { - WalkNode(right, lab); - right = 0; - } - } - - /* ??? */ - break; - } + CaseCode(nd, lab); + break; case WHILE: { label l1, l2; @@ -317,6 +316,7 @@ WalkStat(nd, lab) if (!TstAssCompat(func_type, right->nd_type)) { node_error(right, "type incompatibility in RETURN statement"); } + return_expr_occurred = 1; } C_bra(return_label); break; @@ -348,9 +348,9 @@ WalkExpr(nd) DO_DEBUG(1, (DumpTree(nd), print("\n"))); - if (chk_expr(nd)) { - /* ??? */ - } + if (! chk_expr(nd)) return; + + /* ??? */ } WalkDesignator(nd) @@ -361,9 +361,27 @@ WalkDesignator(nd) DO_DEBUG(1, (DumpTree(nd), print("\n"))); - if (chk_designator(nd, DESIGNATOR|VARIABLE)) { - /* ??? */ - } + if (! chk_designator(nd, DESIGNATOR|VARIABLE)) return; + + /* ??? */ +} + +CodeCall(nd) + struct node *nd; +{ + /* Generate code for a procedure call. Checking of parameters + and result is already done. + */ + /* ??? */ +} + +CodeAssign(nd) + struct node *nd; +{ + /* Generate code for an assignment. Testing of type + compatibility and the like is already done. + */ + /* ??? */ } #ifdef DEBUG From f57a4849065bdb5179755e92f3b5cc24c2cb4ce7 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 14 May 1986 09:03:51 +0000 Subject: [PATCH 0191/1625] newer version --- lang/m2/comp/Makefile | 17 +++++++++-------- lang/m2/comp/casestat.C | 7 ++----- lang/m2/comp/chk_expr.c | 34 ++++++++++++++++++++++++++++++---- lang/m2/comp/declar.g | 6 ++++++ lang/m2/comp/def.c | 1 - lang/m2/comp/walk.c | 40 +++++++++++++++++++++++++--------------- 6 files changed, 72 insertions(+), 33 deletions(-) diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index f4d00d07..c0b90a47 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -44,8 +44,8 @@ main: $(OBJ) Makefile clean: rm -f $(OBJ) $(GENFILES) LLfiles -lint: LLfiles lintlist - lint $(INCLUDES) `cat lintlist` +lint: LLfiles hfiles + lint $(INCLUDES) -DNORCSID `sources $(OBJ)` tokenfile.g: tokenname.c make.tokfile make.tokfile tokenfile.g @@ -79,11 +79,11 @@ depend: make.allocd < $< > $@ #AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO -LLlex.o: LLlex.h Lpars.h class.h const.h f_info.h idf.h idfsize.h input.h inputtype.h numsize.h strsize.h type.h +LLlex.o: LLlex.h Lpars.h class.h const.h debug.h f_info.h idf.h idfsize.h input.h inputtype.h numsize.h strsize.h type.h LLmessage.o: LLlex.h Lpars.h idf.h char.o: class.h error.o: LLlex.h debug.h errout.h f_info.h input.h inputtype.h main.h node.h -main.o: LLlex.h Lpars.h debug.h def.h f_info.h idf.h input.h inputtype.h ndirs.h node.h scope.h standards.h tokenname.h type.h +main.o: LLlex.h Lpars.h debug.h def.h f_info.h idf.h input.h inputtype.h ndir.h node.h scope.h standards.h tokenname.h type.h symbol2str.o: Lpars.h tokenname.o: Lpars.h idf.h tokenname.h idf.o: idf.h @@ -92,17 +92,18 @@ type.o: LLlex.h const.h debug.h def.h idf.h maxset.h node.h target_sizes.h type. def.o: LLlex.h debug.h def.h idf.h main.h node.h scope.h type.h scope.o: LLlex.h debug.h def.h idf.h node.h scope.h type.h misc.o: LLlex.h f_info.h idf.h misc.h node.h -enter.o: LLlex.h def.h idf.h main.h node.h scope.h type.h +enter.o: LLlex.h debug.h def.h idf.h main.h node.h scope.h type.h defmodule.o: LLlex.h debug.h def.h f_info.h idf.h input.h inputtype.h main.h scope.h typequiv.o: def.h type.h node.o: LLlex.h debug.h def.h node.h type.h -cstoper.o: LLlex.h Lpars.h idf.h node.h standards.h target_sizes.h type.h +cstoper.o: LLlex.h Lpars.h debug.h idf.h node.h standards.h target_sizes.h type.h chk_expr.o: LLlex.h Lpars.h const.h debug.h def.h idf.h node.h scope.h standards.h type.h options.o: idfsize.h main.h ndir.h type.h walk.o: LLlex.h Lpars.h debug.h def.h main.h node.h scope.h type.h +casestat.o: LLlex.h Lpars.h debug.h density.h node.h type.h tokenfile.o: Lpars.h program.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h type.h -declar.o: LLlex.h Lpars.h def.h idf.h main.h misc.h node.h scope.h type.h -expression.o: LLlex.h Lpars.h const.h debug.h def.h idf.h node.h scope.h type.h +declar.o: LLlex.h Lpars.h debug.h def.h idf.h main.h misc.h node.h scope.h type.h +expression.o: LLlex.h Lpars.h const.h debug.h def.h idf.h node.h type.h statement.o: LLlex.h Lpars.h def.h idf.h node.h scope.h type.h Lpars.o: Lpars.h diff --git a/lang/m2/comp/casestat.C b/lang/m2/comp/casestat.C index babfd8b3..b3ef54b3 100644 --- a/lang/m2/comp/casestat.C +++ b/lang/m2/comp/casestat.C @@ -18,8 +18,6 @@ static char *RcsId = "$Header$"; #include "density.h" -/* STATICALLOCDEF "caselist" */ - struct switch_hdr { struct switch_hdr *next; label sh_break; @@ -102,7 +100,7 @@ CaseCode(nd, exitlabel) tablabel = data_label(); /* the rom must have a label */ C_df_dlb(tablabel); if (sh->sh_default) C_rom_ilb(sh->sh_default); - else C_rom_ucon((arith) 0, pointer_size); + else C_rom_ucon("0", pointer_size); if (compact(sh->sh_nrofentries, sh->sh_lowerbd, sh->sh_upperbd)) { /* CSA */ @@ -253,8 +251,7 @@ AddOneCase(sh, node, lbl) */ if (c1) { if (c1->ce_value == ce->ce_value) { - node_error("multiple case entry for value %ld", - ce->ce_value); +node_error(node, "multiple case entry for value %ld", ce->ce_value); free_case_entry(ce); return 0; } diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index ad59c7fe..a0bc2050 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -448,7 +448,7 @@ chk_designator(expp, flag) assert(expp->nd_right->nd_class == Name); if (! chk_designator(expp->nd_left, - (flag|HASSELECTORS)&DESIGNATOR)) return 0; + (flag|HASSELECTORS))) return 0; tp = expp->nd_left->nd_type; @@ -633,7 +633,7 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R case '*': switch(tpl->tp_fund) { case T_POINTER: - if (tpl != address_type) break; + if (! chk_address(tpl, tpr)) break; /* Fall through */ case T_INTEGER: case T_CARDINAL: @@ -669,7 +669,13 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R case DIV: case MOD: - if ((tpl->tp_fund & T_INTORCARD) || tpl == address_type) { + switch(tpl->tp_fund) { + case T_POINTER: + if (! chk_address(tpl, tpr)) break; + /* Fall through */ + case T_INTEGER: + case T_CARDINAL: + case T_INTORCARD: if (left->nd_class==Value && right->nd_class==Value) { cstbin(expp); } @@ -718,7 +724,8 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R return 1; case T_POINTER: - if (expp->nd_symb == '=' || + if (chk_address(tpl, tpr) || + expp->nd_symb == '=' || expp->nd_symb == UNEQUAL || expp->nd_symb == '#') return 1; break; @@ -745,6 +752,22 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R return 0; } +int +chk_address(tpl, tpr) + register struct type *tpl, *tpr; +{ + + if (tpl == address_type) { + return tpr == address_type || tpr->tp_fund != T_POINTER; + } + + if (tpr == address_type) { + return tpl->tp_fund != T_POINTER; + } + + return 0; +} + int chk_uoper(expp) register struct node *expp; @@ -769,6 +792,9 @@ chk_uoper(expp) case '-': if (tpr->tp_fund & T_INTORCARD) { + if (tpr == intorcard_type) { + expp->nd_type = int_type; + } if (right->nd_class == Value) { cstunary(expp); } diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 909e4339..1adbccd7 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -56,6 +56,12 @@ ProcedureHeading(struct def **pdf; int type;) PROCEDURE IDENT { df = DeclProc(type); + if (proclevel) { + /* Room for static link + */ + df->prc_nbpar = pointer_size; + } + else df->prc_nbpar = 0; } FormalParameters(type == D_PROCEDURE, ¶ms, &tp, &(df->prc_nbpar))? { diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index a5781cbe..8006d58a 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -477,7 +477,6 @@ DeclProc(type) strcpy(CurrentScope->sc_name, buf); C_inp(buf); } - df->prc_nbpar = 0; } return df; diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index 812b48cf..6e56b658 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -25,8 +25,6 @@ static char *RcsId = "$Header$"; extern arith align(); static int prclev = 0; static label instructionlabel; -static label datalabel = 1; -static label return_label; static char return_expr_occurred; static struct type *func_type; @@ -39,7 +37,9 @@ text_label() label data_label() { - return datalabel++; + static label datalabel = 0; + + return ++datalabel; } WalkModule(module) @@ -89,14 +89,13 @@ WalkModule(module) this module. */ CurrentScope->sc_off = 0; - instructionlabel = 1; - return_label = instructionlabel++; + instructionlabel = 2; func_type = 0; C_pro_narg(CurrentScope->sc_name); MkCalls(CurrentScope->sc_def); WalkNode(module->mod_body, (label) 0); - C_df_ilb(return_label); - C_ret((label) 0); + C_df_ilb((label) 1); + C_ret(0); C_end(align(-CurrentScope->sc_off, word_align)); CurrVis = vis; @@ -121,15 +120,20 @@ WalkProcedure(procedure) /* generate calls to initialization routines of modules defined within this procedure */ - return_label = 1; + MkCalls(CurrentScope->sc_def); + return_expr_occurred = 0; instructionlabel = 2; func_type = procedure->df_type->next; - MkCalls(CurrentScope->sc_def); WalkNode(procedure->prc_body, (label) 0); - C_df_ilb(return_label); - if (func_type) C_ret((arith) align(func_type->tp_size, word_align)); - else C_ret((arith) 0); - C_end(align(-CurrentScope->sc_off, word_size)); + C_df_ilb((label) 1); + if (func_type) { + if (! return_expr_occurred) { +node_error(procedure->prc_body,"function procedure does not return a value"); + } + C_ret((int) align(func_type->tp_size, word_align)); + } + else C_ret(0); + C_end((int) align(-CurrentScope->sc_off, word_align)); CurrVis = vis; prclev--; } @@ -195,6 +199,12 @@ WalkStat(nd, lab) register struct node *left = nd->nd_left; register struct node *right = nd->nd_right; + if (!nd) { + /* Empty statement + */ + return; + } + if (nd->nd_class == Call) { if (chk_call(nd)) CodeCall(nd); return; @@ -204,8 +214,8 @@ WalkStat(nd, lab) switch(nd->nd_symb) { case BECOMES: - WalkDesignator(left); WalkExpr(right); + WalkDesignator(left); /* May we do it in this order??? */ if (! TstAssCompat(left->nd_type, right->nd_type)) { node_error(nd, "type incompatibility in assignment"); @@ -318,7 +328,7 @@ node_error(right, "type incompatibility in RETURN statement"); } return_expr_occurred = 1; } - C_bra(return_label); + C_bra((label) 1); break; default: From 72fac35781dd4ec381523950c2daaaea6496c3a2 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 16 May 1986 17:15:36 +0000 Subject: [PATCH 0192/1625] newer version --- lang/m2/comp/Makefile | 2 +- lang/m2/comp/chk_expr.c | 2 + lang/m2/comp/declar.g | 6 +- lang/m2/comp/def.H | 9 --- lang/m2/comp/desig.c | 164 ++++++++++++++++++++++++++++++++++++++++ lang/m2/comp/desig.h | 53 +++++++++++++ lang/m2/comp/enter.c | 11 ++- lang/m2/comp/main.c | 2 +- lang/m2/comp/options.c | 5 +- lang/m2/comp/program.g | 12 +-- lang/m2/comp/scope.C | 7 +- lang/m2/comp/scope.h | 2 +- lang/m2/comp/type.H | 1 + lang/m2/comp/type.c | 1 + lang/m2/comp/walk.c | 30 ++++++-- 15 files changed, 270 insertions(+), 37 deletions(-) create mode 100644 lang/m2/comp/desig.c create mode 100644 lang/m2/comp/desig.h diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index c0b90a47..3f233ffe 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -99,7 +99,7 @@ node.o: LLlex.h debug.h def.h node.h type.h cstoper.o: LLlex.h Lpars.h debug.h idf.h node.h standards.h target_sizes.h type.h chk_expr.o: LLlex.h Lpars.h const.h debug.h def.h idf.h node.h scope.h standards.h type.h options.o: idfsize.h main.h ndir.h type.h -walk.o: LLlex.h Lpars.h debug.h def.h main.h node.h scope.h type.h +walk.o: LLlex.h Lpars.h debug.h def.h desig.h main.h node.h scope.h type.h casestat.o: LLlex.h Lpars.h debug.h density.h node.h type.h tokenfile.o: Lpars.h program.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h type.h diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index a0bc2050..a4f55fd0 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -461,6 +461,8 @@ chk_designator(expp, flag) return 0; } else { + expp->nd_right->nd_class = Def; + expp->nd_right->nd_def = df; expp->nd_type = df->df_type; if (!(df->df_flags & (D_EXPORTED|D_QEXPORTED))) { node_error(expp->nd_right, diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 1adbccd7..36c160b3 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -33,7 +33,6 @@ ProcedureDeclaration } : ProcedureHeading(&df, D_PROCEDURE) { - df->prc_level = proclevel++; currentdef = df; } ';' block(&(df->prc_body)) IDENT @@ -55,8 +54,9 @@ ProcedureHeading(struct def **pdf; int type;) } : PROCEDURE IDENT { + if (type == D_PROCEDURE) proclevel++; df = DeclProc(type); - if (proclevel) { + if (proclevel > 1) { /* Room for static link */ df->prc_nbpar = pointer_size; @@ -242,7 +242,7 @@ enumeration(struct type **ptp;) { *ptp = standard_type(T_ENUMERATION, 1, (arith) 1); EnterIdList(EnumList, D_ENUM, 0, *ptp, - CurrentScope, (arith *) 0); + CurrentScope, (arith *) 0); FreeNode(EnumList); if ((*ptp)->enm_ncst > 256) { if (word_size == 1) { diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H index 131f67f1..82a5cda7 100644 --- a/lang/m2/comp/def.H +++ b/lang/m2/comp/def.H @@ -6,25 +6,18 @@ struct module { arith mo_priority; /* priority of a module */ struct scopelist *mo_vis;/* scope of this module */ struct node *mo_body; /* body of this module */ - int mo_number; /* number of this module */ #define mod_priority df_value.df_module.mo_priority #define mod_vis df_value.df_module.mo_vis #define mod_body df_value.df_module.mo_body -#define mod_number df_value.df_module.mo_number }; struct variable { arith va_off; /* address or offset of variable */ char *va_name; /* name of variable if given */ char va_addrgiven; /* an address was given in the program */ - char va_noreg; /* may not be in a register */ - short va_number; /* number of this variable in definition module - */ #define var_off df_value.df_variable.va_off #define var_name df_value.df_variable.va_name #define var_addrgiven df_value.df_variable.va_addrgiven -#define var_noreg df_value.df_variable.va_noreg -#define var_number df_value.df_variable.va_number }; struct constant { @@ -52,11 +45,9 @@ struct field { struct dfproc { struct scopelist *pr_vis; /* scope of procedure */ - short pr_level; /* depth level of this procedure */ arith pr_nbpar; /* number of bytes parameters */ struct node *pr_body; /* body of this procedure */ #define prc_vis df_value.df_proc.pr_vis -#define prc_level df_value.df_proc.pr_level #define prc_nbpar df_value.df_proc.pr_nbpar #define prc_body df_value.df_proc.pr_body }; diff --git a/lang/m2/comp/desig.c b/lang/m2/comp/desig.c new file mode 100644 index 00000000..e52b69f2 --- /dev/null +++ b/lang/m2/comp/desig.c @@ -0,0 +1,164 @@ +/* D E S I G N A T O R E V A L U A T I O N */ + +#ifndef NORCSID +static char *RcsId = "$Header$"; +#endif + +/* Code generation for designators. + This file contains some routines that generate code common to address + as well as value computations, and leave a description in a "desig" + structure. It also contains routines to load an address, load a value + or perform a store. +*/ + +#include "debug.h" + +#include +#include +#include + +#include "type.h" +#include "def.h" +#include "scope.h" +#include "desig.h" +#include "LLlex.h" +#include "node.h" + +CodeValue(ds, size) + register struct desig *ds; +{ + /* Generate code to load the value of the designator described + in "ds" + */ + + switch(ds->dsg_kind) { + case DSG_LOADED: + break; + + case DSG_FIXED: + if (size == word_size) { + if (ds->dsg_name) { + C_loe_dnam(ds->dsg_name, ds->dsg_offset); + } + else C_lol(ds->dsg_offset); + break; + } + + if (size == dwird_size) { + if (ds->dsg_name) { + C_lde_dnam(ds->dsg_name, ds->dsg_offset); + } + else C_ldl(ds->dsg_offset); + break; + } + /* Fall through */ + case DSG_PLOADED: + case DSG_PFIXED: + CodeAddress(ds); + C_loi(size); + break; + + case DSG_INDEXED: + C_lar(word_size); + break; + + default: + assert(0); + } + + ds->dsg_kind = DSG_LOADED; +} + +CodeAddress(ds) + register struct desig *ds; +{ + /* Generate code to load the address of the designator described + in "ds" + */ + + switch(ds->dsg_kind) { + case DSG_PLOADED: + if (ds->dsg_offset) { + C_adp(ds->dsg_offset); + } + break; + + case DSG_FIXED: + if (ds->dsg_name) { + C_lae_dnam(ds->dsg_name, ds->dsg_offset); + break; + } + C_lal(ds->dsg_offset); + break; + + case DSG_PFIXED: + ds->dsg_kind = DSG_FIXED; + CodeValue(ds, pointer_size); + break; + + case DSG_INDEXED: + C_aar(word_size); + break; + + default: + assert(0); + break; + } + + ds->dsg_offset = 0; + ds->dsg_kind = DSG_PLOADED; +} + +CodeFieldDesig(df, ds) + register struct def *df; + register struct desig *ds; +{ + /* Generate code for a field designator. Only the code common for + address as well as value computation is generated, and the + resulting information on where to find the designator is placed + in "ds". "df" indicates the definition of the field. + */ + + register struct withdesig *wds; + + if (ds->dsg_kind == DSG_INIT) { + /* In a WITH statement. We must find the designator in the + WITH statement, and act as if the field is a selection + of this designator. + So, first find the right WITH statement, which is the + first one of the proper record type. + Notice that the proper record type is recognized by its + scope indication. + */ + wds = WithDesigs; + assert(wds != 0); + + while (wds->w_scope != df->df_scope) { + wds = wds->w_next; + assert(wds != 0); + } + + /* Found it. Now, act like it was a selection. + */ + *ds = wds->w_desig; + } + + switch(ds->dsg_kind) { + case DSG_PLOADED: + case DSG_FIXED: + ds->dsg_offset += df->fld_off; + break; + + case DSG_PFIXED: + case DSG_INDEXED: + CodeAddress(ds); + ds->dsg_kind = PLOADED; + ds->dsg_offset = df->fld_off; + break; + + default: + assert(0); + break; + } +} + diff --git a/lang/m2/comp/desig.h b/lang/m2/comp/desig.h new file mode 100644 index 00000000..ffbbb65b --- /dev/null +++ b/lang/m2/comp/desig.h @@ -0,0 +1,53 @@ +/* D E S I G N A T O R D E S C R I P T I O N S */ + +/* $Header$ */ + +/* Generating code for designators is not particularly easy, especially if + you don't know wether you want the address or the value. + The next structure is used to generate code for designators. + It contains information on how to find the designator, after generation + of the code that is common to both address and value computations. +*/ + +struct desig { + int dsg_kind; +#define DSG_INIT 0 /* don't know anything yet */ +#define DSG_LOADED 1 /* designator loaded on top of the stack */ +#define DSG_PLOADED 2 /* designator accessible through pointer on + stack, possibly with an offset + */ +#define DSG_FIXED 3 /* designator directly accessible */ +#define DSG_PFIXED 4 /* designator accessible through directly + accessible pointer + */ +#define DSG_INDEXED 5 /* designator accessible through array + operation. Address of array descriptor on + top of the stack, index beneath that, and + base address beneath that + */ + arith dsg_offset; /* contains an offset for PLOADED, + or for FIXED or PFIXED it contains an + offset from dsg_name, if it exists, + or from the current Local Base + */ + char *dsg_name; /* name of global variable, used for + FIXED and PFIXED + */ +}; + +/* The next structure describes the designator in a with-statement. + We have a linked list of them, as with-statements may be nested. +*/ + +struct withdesig { + struct withdesig *w_next; + struct scope *w_scope; /* scope in which fields of this record + reside + */ + struct desig *w_desig; /* a desig structure for this particular + designator + */ +}; + +extern struct withdesig *WithDesigs; +extern struct desig Desig; diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index 336a2e0a..17fe39c5 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -105,7 +105,7 @@ EnterVarList(IdList, type, local) /* Enter a list of identifiers representing variables into the name list. "type" represents the type of the variables. "local" is set if the variables are declared local to a - procedure + procedure. */ register struct def *df; register struct scopelist *sc; @@ -143,14 +143,15 @@ node_error(IdList->nd_left,"Illegal type for address"); type->tp_align); df->var_off = sc->sc_scope->sc_off; } - else if (!DefinitionModule && - CurrVis != Defined->mod_vis) { + else if (!DefinitionModule && CurrVis != Defined->mod_vis) { /* variable list belongs to an internal global - module. Align offset and add size + module. + Align offset and add size */ sc->sc_scope->sc_off = align(sc->sc_scope->sc_off, type->tp_align); df->var_off = sc->sc_scope->sc_off; + df->var_name = 0; sc->sc_scope->sc_off += type->tp_size; } else { @@ -160,6 +161,7 @@ node_error(IdList->nd_left,"Illegal type for address"); df->df_idf->id_text); df->var_name = Malloc((unsigned)(strlen(buf)+1)); strcpy(df->var_name, buf); + if (DefinitionModule) { C_exa_dnam(df->var_name); } @@ -167,6 +169,7 @@ node_error(IdList->nd_left,"Illegal type for address"); C_ina_dnam(df->var_name); } } + IdList = IdList->nd_right; } } diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index c81078f3..62b780de 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -84,7 +84,7 @@ Compile(src, dst) return 1; } #endif DEBUG - (void) open_scope(CLOSEDSCOPE); + open_scope(CLOSEDSCOPE); GlobalScope = CurrentScope; C_init(word_size, pointer_size); if (! C_open(dst)) { diff --git a/lang/m2/comp/options.c b/lang/m2/comp/options.c index 5206d422..8e3214d0 100644 --- a/lang/m2/comp/options.c +++ b/lang/m2/comp/options.c @@ -64,7 +64,10 @@ DoOption(text) switch (c) { case 'w': /* word */ - if (size != (arith)0) word_size = size; + if (size != (arith)0) { + word_size = size; + dword_size = 2 * size; + } if (align != 0) word_align = align; break; case 'i': /* int */ diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 81444fc5..3fb43e3a 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -67,16 +67,18 @@ ModuleDeclaration open_scope(CLOSEDSCOPE); df->mod_vis = CurrVis; } - else CurrVis = df->mod_vis; + else { + CurrVis = df->mod_vis; + CurrentScope->sc_level = proclevel; + } df->df_type = standard_type(T_RECORD, 0, (arith) 0); df->df_type->rec_scope = df->mod_vis->sc_scope; - df->mod_number = ++modulecount; - sprint(buf, "__%d%s", df->mod_number, id->id_text); + sprint(buf, "__%d%s", ++modulecount, id->id_text); CurrentScope->sc_name = Malloc((unsigned) (strlen(buf) + 1)); strcpy(CurrentScope->sc_name, buf); - C_ina_dnam(&buf[1]); + if (! proclevel) C_ina_dnam(&buf[1]); C_inp(buf); } priority(&(df->mod_priority))? @@ -161,7 +163,6 @@ DefinitionModule if (!SYSTEMModule) open_scope(CLOSEDSCOPE); if (!Defined) Defined = df; df->mod_vis = CurrVis; - df->mod_number = 0; CurrentScope->sc_name = id->id_text; df->df_type = standard_type(T_RECORD, 0, (arith) 0); df->df_type->rec_scope = df->mod_vis->sc_scope; @@ -253,7 +254,6 @@ ProgramModule(int state;) Defined = df; open_scope(CLOSEDSCOPE); df->mod_vis = CurrVis; - df->mod_number = 0; CurrentScope->sc_name = id->id_text; } } diff --git a/lang/m2/comp/scope.C b/lang/m2/comp/scope.C index f416ceb6..f9899872 100644 --- a/lang/m2/comp/scope.C +++ b/lang/m2/comp/scope.C @@ -20,7 +20,7 @@ static char *RcsId = "$Header$"; struct scope *PervasiveScope, *GlobalScope; struct scopelist *CurrVis; -static int scp_level; +extern int proclevel; static struct scopelist *PervVis; /* STATICALLOCDEF "scope" */ @@ -36,7 +36,7 @@ open_scope(scopetype) assert(scopetype == OPENSCOPE || scopetype == CLOSEDSCOPE); sc->sc_scopeclosed = scopetype == CLOSEDSCOPE; - sc->sc_level = scp_level++; + sc->sc_level = proclevel; sc->sc_forw = 0; sc->sc_def = 0; sc->sc_off = 0; @@ -57,7 +57,7 @@ init_scope() sc->sc_scopeclosed = 0; sc->sc_forw = 0; sc->sc_def = 0; - sc->sc_level = scp_level++; + sc->sc_level = proclevel; PervasiveScope = sc; ls->next = 0; ls->sc_encl = 0; @@ -228,7 +228,6 @@ close_scope(flag) if (flag & SC_REVERSE) Reverse(&(sc->sc_def)); } CurrVis = enclosing(CurrVis); - scp_level = CurrentScope->sc_level; } #ifdef DEBUG diff --git a/lang/m2/comp/scope.h b/lang/m2/comp/scope.h index 4bee7e82..a80a1dbc 100644 --- a/lang/m2/comp/scope.h +++ b/lang/m2/comp/scope.h @@ -27,8 +27,8 @@ struct scope { struct scopelist { struct scopelist *next; - struct scopelist *sc_encl; struct scope *sc_scope; + struct scopelist *sc_encl; }; extern struct scope diff --git a/lang/m2/comp/type.H b/lang/m2/comp/type.H index e1595d4f..ef74b993 100644 --- a/lang/m2/comp/type.H +++ b/lang/m2/comp/type.H @@ -112,6 +112,7 @@ extern int extern arith word_size, + dword_size, int_size, long_size, float_size, diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index e9f19f97..a15405cf 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -34,6 +34,7 @@ int arith word_size = SZ_WORD, + dword_size = 2 * SZ_WORD, int_size = SZ_INT, long_size = SZ_LONG, float_size = SZ_FLOAT, diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index 6e56b658..9c4ba1cf 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -21,12 +21,14 @@ static char *RcsId = "$Header$"; #include "LLlex.h" #include "node.h" #include "Lpars.h" +#include "desig.h" extern arith align(); -static int prclev = 0; +extern int proclevel; static label instructionlabel; static char return_expr_occurred; static struct type *func_type; +struct withdesig *WithDesigs; label text_label() @@ -54,7 +56,7 @@ WalkModule(module) vis = CurrVis; CurrVis = module->mod_vis; - if (!prclev && module->mod_number) { + if (!proclevel && module != Defined) { /* This module is a local module, but not within a procedure. Generate code to allocate storage for its variables. This is done by generating a "bss", @@ -63,6 +65,8 @@ WalkModule(module) arith size = align(CurrentScope->sc_off, word_align); if (size == 0) size = word_size; + /* WHY ??? because we generated an INA for it ??? */ + C_df_dnam(&(CurrentScope->sc_name[1])); C_bss_cst(size, (arith) 0, 0); } @@ -109,7 +113,7 @@ WalkProcedure(procedure) */ struct scopelist *vis = CurrVis; - prclev++; + proclevel++; CurrVis = procedure->prc_vis; WalkDef(CurrentScope->sc_def); @@ -133,9 +137,9 @@ node_error(procedure->prc_body,"function procedure does not return a value"); C_ret((int) align(func_type->tp_size, word_align)); } else C_ret(0); - C_end((int) align(-CurrentScope->sc_off, word_align)); + C_end(align(-CurrentScope->sc_off, word_align)); CurrVis = vis; - prclev--; + proclevel--; } WalkDef(df) @@ -295,6 +299,7 @@ WalkStat(nd, lab) case WITH: { struct scopelist link; + struct withdesig wds; WalkDesignator(left); if (left->nd_type->tp_fund != T_RECORD) { @@ -302,12 +307,23 @@ WalkStat(nd, lab) break; } - link.sc_scope = left->nd_type->rec_scope; + wds.w_next = WithDesigs; + WithDesigs = &wds; + wds.w_scope = left->nd_type->rec_scope; + /* + Decide here wether to use a temporary variable or + not, depending on the value of Desig. + Suggestion: temporary if Desig != DSG_FIXED + + And then: + wds.w_desig = Desig; ??? + */ + link.sc_scope = wds.w_scope; link.next = CurrVis; CurrVis = &link; WalkNode(right, lab); CurrVis = link.next; - /* ??? */ + WithDesigs = wds.w_next; break; } From 0d93c572bc11f99e9e73d9c31b9f08c92a6771fd Mon Sep 17 00:00:00 2001 From: sater Date: Wed, 21 May 1986 15:08:57 +0000 Subject: [PATCH 0193/1625] Non existing token fields in the format string caused memfaults because fields were checked beyond the end of the tokeninfo. Fixed. --- util/ncgg/subr.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/util/ncgg/subr.c b/util/ncgg/subr.c index fff05680..3693104b 100644 --- a/util/ncgg/subr.c +++ b/util/ncgg/subr.c @@ -90,6 +90,7 @@ struct varinfo *atts,*cost,*format; register struct varinfo *vip; int i; int tokno; + int thistokensize; char formstr[50],smallstr[2]; sy_p = lookup(name,symtok,newsymbol); @@ -111,6 +112,7 @@ struct varinfo *atts,*cost,*format; tp->tk_att[i].ta_name = vip->vi_str[0]; vip->vi_str[0]=0; } + thistokensize=i; if (i>maxtokensize) maxtokensize=i; if (vip!=0) @@ -123,7 +125,7 @@ struct varinfo *atts,*cost,*format; if (vip->vi_int[0]==0) strcat(formstr,vip->vi_str[0]); else { - for(i=0;ivi_str[0],tp->tk_att[i].ta_name)==0) { smallstr[0] = i+1; smallstr[1] = 0; @@ -131,7 +133,7 @@ struct varinfo *atts,*cost,*format; break; } } - if (i==MAXATT) + if (i==thistokensize) error("%s not a known attribute", vip->vi_str[0]); } From 8aaaa488406fcd65585a2f97935b5a2c8150e065 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 21 May 1986 18:32:20 +0000 Subject: [PATCH 0194/1625] newer version --- lang/m2/comp/Makefile | 2 +- lang/m2/comp/casestat.C | 3 +- lang/m2/comp/chk_expr.c | 19 +- lang/m2/comp/code.c | 584 ++++++++++++++++++++++++++++++++++++++++ lang/m2/comp/declar.g | 8 +- lang/m2/comp/def.H | 2 - lang/m2/comp/desig.c | 180 ++++++++++++- lang/m2/comp/desig.h | 6 +- lang/m2/comp/enter.c | 29 +- lang/m2/comp/error.c | 14 + lang/m2/comp/type.H | 2 + lang/m2/comp/type.c | 14 + lang/m2/comp/walk.c | 71 +++-- 13 files changed, 870 insertions(+), 64 deletions(-) create mode 100644 lang/m2/comp/code.c diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index 3f233ffe..ee5c819f 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -18,7 +18,7 @@ LOBJ = tokenfile.o program.o declar.o expression.o statement.o COBJ = LLlex.o LLmessage.o char.o error.o main.o \ symbol2str.o tokenname.o idf.o input.o type.o def.o \ scope.o misc.o enter.o defmodule.o typequiv.o node.o \ - cstoper.o chk_expr.o options.o walk.o casestat.o + cstoper.o chk_expr.o options.o walk.o casestat.o desig.o code.o OBJ = $(COBJ) $(LOBJ) Lpars.o GENFILES= tokenfile.c \ program.c declar.c expression.c statement.c \ diff --git a/lang/m2/comp/casestat.C b/lang/m2/comp/casestat.C index b3ef54b3..9ba52fb2 100644 --- a/lang/m2/comp/casestat.C +++ b/lang/m2/comp/casestat.C @@ -15,6 +15,7 @@ static char *RcsId = "$Header$"; #include "type.h" #include "LLlex.h" #include "node.h" +#include "desig.h" #include "density.h" @@ -64,7 +65,7 @@ CaseCode(nd, exitlabel) assert(nd->nd_class == Stat && nd->nd_symb == CASE); - WalkExpr(nd->nd_left); + WalkExpr(nd->nd_left, NO_LABEL, NO_LABEL); sh->sh_type = nd->nd_left->nd_type; sh->sh_break = text_label(); sh->sh_default = 0; diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index a4f55fd0..5934c406 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -371,6 +371,12 @@ node_error(arg->nd_left, "type incompatibility in parameter"); return 0; } + if (param->par_var && + !chk_designator(arg->nd_left, VARIABLE|DESIGNATOR)) { + node_error(arg->nd_left,"VAR parameter expected"); + return 0; + } + param = param->next; } @@ -445,14 +451,20 @@ chk_designator(expp, flag) if (expp->nd_class == Link) { assert(expp->nd_symb == '.'); - assert(expp->nd_right->nd_class == Name); if (! chk_designator(expp->nd_left, (flag|HASSELECTORS))) return 0; tp = expp->nd_left->nd_type; + if (expp->nd_right->nd_class == Def) { + /* We were here already! + */ + return 1; + } + assert(tp->tp_fund == T_RECORD); + assert(expp->nd_right->nd_class == Name); df = lookup(expp->nd_right->nd_IDF, tp->rec_scope); @@ -472,7 +484,8 @@ df->df_idf->id_text); } } - if (expp->nd_left->nd_class == Def) { + if (expp->nd_left->nd_class == Def && + expp->nd_left->nd_def->df_kind == D_MODULE) { expp->nd_class = Def; expp->nd_def = df; FreeNode(expp->nd_left); @@ -628,7 +641,7 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R symbol2str(expp->nd_symb)); return 0; } - + switch(expp->nd_symb) { case '+': case '-': diff --git a/lang/m2/comp/code.c b/lang/m2/comp/code.c new file mode 100644 index 00000000..f47349e1 --- /dev/null +++ b/lang/m2/comp/code.c @@ -0,0 +1,584 @@ +/* C O D E G E N E R A T I O N R O U T I N E S */ + +#ifndef NORCSID +static char *RcsId = "$Header$"; +#endif + +/* Code generation for expressions and coercions +*/ + +#include "debug.h" + +#include +#include +#include + +#include "type.h" +#include "def.h" +#include "scope.h" +#include "desig.h" +#include "LLlex.h" +#include "node.h" +#include "Lpars.h" + +extern label data_label(); +extern char *long2str(); +extern char *symbol2str(); +extern int proclevel; + +CodeConst(cst, size) + arith cst, size; +{ + /* Generate code to push constant "cst" with size "size" + */ + label dlab; + + if (size <= word_size) { + C_loc(cst); + } + else if (size == dword_size) { + C_ldc(cst); + } + else { + C_df_dlb(dlab = data_label()); + C_rom_icon(long2str((long) cst), 10); + C_lae_dlb(dlab); + C_loi(size); + } +} + +CodeString(nd) + struct node *nd; +{ + + label lab; + + C_df_dlb(lab = data_label()); + C_rom_scon(nd->nd_STR, nd->nd_SLE); + C_lae_dlb(lab); +} + +CodeReal(nd) + struct node *nd; +{ + label lab; + + C_df_dlb(lab = data_label()); + C_rom_fcon(nd->nd_REL, nd->nd_type->tp_size); + C_lae_dlb(lab); + C_loi(nd->nd_type->tp_size); +} + +CodeExpr(nd, ds, true_label, false_label) + struct node *nd; + struct desig *ds; + label true_label, false_label; +{ + struct desig ds1, ds2; + + switch(nd->nd_class) { + case Def: + CodeDesig(nd, ds); + break; + + case Oper: + if (nd->nd_symb == '[') { + CodeDesig(nd, ds); + break; + } + CodeOper(nd, true_label, false_label); + if (true_label == 0) ds->dsg_kind = DSG_LOADED; + else { + *ds = InitDesig; + true_label = 0; + } + break; + + case Uoper: + if (nd->nd_symb == '^') { + CodeDesig(nd, ds); + break; + } + CodeExpr(nd->nd_right, ds, NO_LABEL, NO_LABEL); + CodeValue(ds, nd->nd_right->nd_type->tp_size); + CodeUoper(nd); + ds->dsg_kind = DSG_LOADED; + break; + + case Value: + switch(nd->nd_symb) { + case REAL: + CodeReal(nd); + break; + case STRING: + CodeString(nd); + break; + case INTEGER: + CodeConst(nd->nd_INT, nd->nd_type->tp_size); + break; + default: + crash("Value error"); + } + ds->dsg_kind = DSG_LOADED; + break; + + case Link: + CodeDesig(nd, ds); + break; + + case Call: + CodeCall(nd); + ds->dsg_kind = DSG_LOADED; + break; + + case Xset: + case Set: + /* ??? */ + ds->dsg_kind = DSG_LOADED; + break; + + default: + crash("(CodeExpr) bad node type"); + } + + if (true_label != 0) { + CodeValue(ds, nd->nd_type->tp_size); + *ds = InitDesig; + C_zne(true_label); + C_bra(false_label); + } +} + +CodeCoercion(t1, t2) + struct type *t1, *t2; +{ + /* ??? */ +} + +CodeCall(nd) + struct node *nd; +{ + /* Generate code for a procedure call. Checking of parameters + and result is already done. + */ + register struct node *left = nd->nd_left; + register struct node *arg = nd; + register struct paramlist *param; + struct type *tp; + arith pushed = 0; + struct desig Des; + + if (left->nd_type == std_type) { + CodeStd(nd); + return; + } + tp = left->nd_type; + + assert(tp->tp_fund == T_PROCEDURE); + + for (param = left->nd_type->prc_params; param; param = param->next) { + Des = InitDesig; + arg = arg->nd_right; + assert(arg != 0); + if (param->par_var) { + CodeDesig(arg->nd_left, &Des); + CodeAddress(&Des); + pushed += pointer_size; + } + else { + CodeExpr(arg->nd_left, &Des, NO_LABEL, NO_LABEL); + CodeValue(&Des, arg->nd_left->nd_type->tp_size); + pushed += align(arg->nd_left->nd_type->tp_size, word_align); + } + /* ??? Conformant arrays */ + } + + if (left->nd_class == Def && left->nd_def->df_kind == D_PROCEDURE) { + if (left->nd_def->df_scope->sc_level > 0) { + C_lxl((arith) proclevel - left->nd_def->df_scope->sc_level); + pushed += pointer_size; + } + C_cal(left->nd_def->prc_vis->sc_scope->sc_name); + } + else if (left->nd_class == Def && left->nd_def->df_kind == D_PROCHEAD) { + C_cal(left->nd_def->for_name); + } + else { + Des = InitDesig; + CodeDesig(left, &Des); + CodeAddress(&Des); + C_cai(); + } + C_asp(pushed); + if (tp->next) { + C_lfr(align(tp->next->tp_size, word_align)); + } +} + +CodeStd(nd) + struct node *nd; +{ + /* ??? */ +} + +CodeAssign(nd, dst, dss) + struct node *nd; + struct desig *dst, dss; +{ + /* Generate code for an assignment. Testing of type + compatibility and the like is already done. + */ + + CodeCoercion(nd->nd_right->nd_type, nd->nd_left->nd_type); + /* ??? */ +} + +Operands(leftop, rightop) + struct node *leftop, *rightop; +{ + struct desig Des; + + Des = InitDesig; + CodeExpr(leftop, &Des, NO_LABEL, NO_LABEL); + CodeValue(&Des, leftop->nd_type->tp_size); + Des = InitDesig; + + if (rightop->nd_type->tp_fund == T_POINTER && + leftop->nd_type->tp_size != pointer_size) { + CodeCoercion(leftop->nd_type, rightop->nd_type); + leftop->nd_type = rightop->nd_type; + } + + CodeExpr(rightop, &Des, NO_LABEL, NO_LABEL); + CodeValue(&Des, rightop->nd_type->tp_size); +} + +CodeOper(expr, true_label, false_label) + struct node *expr; /* the expression tree itself */ + label true_label; + label false_label; /* labels to jump to in logical expr's */ +{ + register int oper = expr->nd_symb; + register struct node *leftop = expr->nd_left; + register struct node *rightop = expr->nd_right; + register struct type *tp = expr->nd_type; + struct desig Des; + register struct desig *ds = &Des; + + switch (oper) { + case '+': + Operands(leftop, rightop); + switch (tp->tp_fund) { + case T_INTEGER: + C_adi(tp->tp_size); + break; + case T_POINTER: + C_ads(rightop->nd_type->tp_size); + break; + case T_REAL: + C_adf(tp->tp_size); + break; + case T_CARDINAL: + C_adu(tp->tp_size); + break; + case T_SET: + C_ior(tp->tp_size); + break; + default: + crash("bad type +"); + } + break; + case '-': + Operands(leftop, rightop); + switch (tp->tp_fund) { + case T_INTEGER: + C_sbi(tp->tp_size); + break; + case T_POINTER: + if (rightop->nd_type->tp_fund == T_POINTER) { + C_sbs(pointer_size); + } + else { + C_ngi(rightop->nd_type->tp_size); + C_ads(rightop->nd_type->tp_size); + } + break; + case T_REAL: + C_sbf(tp->tp_size); + break; + case T_CARDINAL: + C_sbu(tp->tp_size); + break; + case T_SET: + C_com(tp->tp_size); + C_and(tp->tp_size); + break; + default: + crash("bad type -"); + } + break; + case '*': + Operands(leftop, rightop); + switch (tp->tp_fund) { + case T_INTEGER: + C_mli(tp->tp_size); + break; + case T_POINTER: + CodeCoercion(rightop->nd_type, tp); + /* Fall through */ + case T_CARDINAL: + C_mlu(tp->tp_size); + break; + case T_REAL: + C_mlf(tp->tp_size); + break; + case T_SET: + C_and(tp->tp_size); + break; + default: + crash("bad type *"); + } + break; + case '/': + Operands(leftop, rightop); + switch (tp->tp_fund) { + case T_REAL: + C_dvf(tp->tp_size); + break; + case T_SET: + C_xor(tp->tp_size); + break; + default: + crash("bad type /"); + } + break; + case DIV: + Operands(leftop, rightop); + switch(tp->tp_fund) { + case T_INTEGER: + C_dvi(tp->tp_size); + break; + case T_POINTER: + CodeCoercion(rightop->nd_type, tp); + /* Fall through */ + case T_CARDINAL: + C_dvu(tp->tp_size); + break; + default: + crash("bad type DIV"); + } + break; + case MOD: + Operands(leftop, rightop); + switch(tp->tp_fund) { + case T_INTEGER: + C_rmi(tp->tp_size); + break; + case T_POINTER: + CodeCoercion(rightop->nd_type, tp); + /* Fall through */ + case T_CARDINAL: + C_rmu(tp->tp_size); + break; + default: + crash("bad type MOD"); + } + break; + case '<': + case LESSEQUAL: + case '>': + case GREATEREQUAL: + case '=': + case UNEQUAL: + case '#': + Operands(leftop, rightop); + CodeCoercion(rightop->nd_type, leftop->nd_type); + switch (tp->tp_fund) { + case T_INTEGER: + C_cmi(leftop->nd_type->tp_size); + break; + case T_POINTER: + C_cmp(); + break; + case T_CARDINAL: + C_cmu(leftop->nd_type->tp_size); + break; + case T_ENUMERATION: + case T_CHAR: + C_cmu(word_size); + break; + case T_REAL: + C_cmf(leftop->nd_type->tp_size); + break; + case T_SET: + C_cms(leftop->nd_type->tp_size); + break; + default: + crash("bad type COMPARE"); + } + if (true_label != 0) { + compare(oper, true_label); + C_bra(false_label); + } + else { + truthvalue(oper); + } + break; + case IN: + Operands(leftop, rightop); + CodeCoercion(rightop->nd_type, word_type); + C_inn(leftop->nd_type->tp_size); + break; + case AND: + case '&': + if (true_label == 0) { + label l_true = text_label(); + label l_false = text_label(); + label l_maybe = text_label(); + label l_end = text_label(); + struct desig Des; + + Des = InitDesig; + CodeExpr(leftop, &Des, l_maybe, l_false); + C_df_ilb(l_maybe); + Des = InitDesig; + CodeExpr(rightop, &Des, l_true, l_false); + C_df_ilb(l_true); + C_loc((arith)1); + C_bra(l_end); + C_df_ilb(l_false); + C_loc((arith)0); + C_df_ilb(l_end); + } + else { + label l_maybe = text_label(); + struct desig Des; + + Des = InitDesig; + CodeExpr(leftop, &Des, l_maybe, false_label); + Des = InitDesig; + C_df_ilb(l_maybe); + CodeExpr(rightop, &Des, true_label, false_label); + } + break; + case OR: + if (true_label == 0) { + label l_true = text_label(); + label l_false = text_label(); + label l_maybe = text_label(); + label l_end = text_label(); + struct desig Des; + + Des = InitDesig; + CodeExpr(leftop, &Des, l_true, l_maybe); + C_df_ilb(l_maybe); + Des = InitDesig; + CodeExpr(rightop, &Des, l_true, l_false); + C_df_ilb(l_false); + C_loc((arith)0); + C_bra(l_end); + C_df_ilb(l_true); + C_loc((arith)1); + C_df_ilb(l_end); + } + else { + label l_maybe = text_label(); + struct desig Des; + + Des = InitDesig; + CodeExpr(leftop, &Des, true_label, l_maybe); + C_df_ilb(l_maybe); + Des = InitDesig; + CodeExpr(rightop, &Des, true_label, false_label); + } + break; + default: + crash("(CodeOper) Bad operator %s\n", symbol2str(oper)); + } +} + +/* compare() serves as an auxiliary function of CodeOper */ +compare(relop, lbl) + int relop; + label lbl; +{ + switch (relop) { + case '<': + C_zlt(lbl); + break; + case LESSEQUAL: + C_zle(lbl); + break; + case '>': + C_zgt(lbl); + break; + case GREATEREQUAL: + C_zge(lbl); + break; + case '=': + C_zeq(lbl); + break; + case UNEQUAL: + case '#': + C_zne(lbl); + break; + default: + crash("(compare)"); + } +} + +/* truthvalue() serves as an auxiliary function of CodeOper */ +truthvalue(relop) + int relop; +{ + switch (relop) { + case '<': + C_tlt(); + break; + case LESSEQUAL: + C_tle(); + break; + case '>': + C_tgt(); + break; + case GREATEREQUAL: + C_tge(); + break; + case '=': + C_teq(); + break; + case UNEQUAL: + case '#': + C_tne(); + break; + default: + crash("(truthvalue)"); + } +} + +CodeUoper(nd) + register struct node *nd; +{ + register struct type *tp = nd->nd_type; + + switch(nd->nd_symb) { + case '~': + case NOT: + C_teq(); + break; + case '-': + switch(tp->tp_fund) { + case T_INTEGER: + C_ngi(tp->tp_size); + break; + case T_REAL: + C_ngf(tp->tp_size); + break; + default: + crash("Bad operand to unary -"); + } + break; + default: + crash("Bad unary operator"); + } +} diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 36c160b3..05acf894 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -56,16 +56,16 @@ ProcedureHeading(struct def **pdf; int type;) { if (type == D_PROCEDURE) proclevel++; df = DeclProc(type); + tp = construct_type(T_PROCEDURE, tp); if (proclevel > 1) { /* Room for static link */ - df->prc_nbpar = pointer_size; + tp->prc_nbpar = pointer_size; } - else df->prc_nbpar = 0; + else tp->prc_nbpar = 0; } - FormalParameters(type == D_PROCEDURE, ¶ms, &tp, &(df->prc_nbpar))? + FormalParameters(type == D_PROCEDURE, ¶ms, &(tp->next), &(tp->prc_nbpar))? { - tp = construct_type(T_PROCEDURE, tp); tp->prc_params = params; if (df->df_type) { /* We already saw a definition of this type diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H index 82a5cda7..95037b6f 100644 --- a/lang/m2/comp/def.H +++ b/lang/m2/comp/def.H @@ -45,10 +45,8 @@ struct field { struct dfproc { struct scopelist *pr_vis; /* scope of procedure */ - arith pr_nbpar; /* number of bytes parameters */ struct node *pr_body; /* body of this procedure */ #define prc_vis df_value.df_proc.pr_vis -#define prc_nbpar df_value.df_proc.pr_nbpar #define prc_body df_value.df_proc.pr_body }; diff --git a/lang/m2/comp/desig.c b/lang/m2/comp/desig.c index e52b69f2..7f09be6c 100644 --- a/lang/m2/comp/desig.c +++ b/lang/m2/comp/desig.c @@ -24,6 +24,10 @@ static char *RcsId = "$Header$"; #include "LLlex.h" #include "node.h" +extern int proclevel; +struct desig Desig; +struct desig InitDesig = {DSG_INIT, 0, 0}; + CodeValue(ds, size) register struct desig *ds; { @@ -44,7 +48,7 @@ CodeValue(ds, size) break; } - if (size == dwird_size) { + if (size == dword_size) { if (ds->dsg_name) { C_lde_dnam(ds->dsg_name, ds->dsg_offset); } @@ -63,7 +67,7 @@ CodeValue(ds, size) break; default: - assert(0); + crash("(CodeValue)"); } ds->dsg_kind = DSG_LOADED; @@ -101,8 +105,7 @@ CodeAddress(ds) break; default: - assert(0); - break; + crash("(CodeAddress)"); } ds->dsg_offset = 0; @@ -152,13 +155,176 @@ CodeFieldDesig(df, ds) case DSG_PFIXED: case DSG_INDEXED: CodeAddress(ds); - ds->dsg_kind = PLOADED; + ds->dsg_kind = DSG_PLOADED; ds->dsg_offset = df->fld_off; break; default: - assert(0); - break; + crash("(CodeFieldDesig)"); } } +CodeVarDesig(df, ds) + register struct def *df; + register struct desig *ds; +{ + /* Generate code for a variable represented by a "def" structure. + Of course, there are numerous cases: the variable is local, + it is a value parameter, it is a var parameter, it is one of + those of an enclosing procedure, or it is global. + */ + register struct scope *sc = df->df_scope; + + /* Selections from a module are handled earlier, when identifying + the variable, so ... + */ + assert(ds->dsg_kind == DSG_INIT); + + if (df->var_addrgiven) { + /* the programmer specified an address in the declaration of + the variable. Generate code to push the address. + */ + CodeConst(df->var_off, pointer_size); + ds->dsg_kind = DSG_PLOADED; + ds->dsg_offset = 0; + return; + } + + if (df->var_name) { + /* this variable has been given a name, so it is global. + It is directly accessible. + */ + ds->dsg_name = df->var_name; + ds->dsg_offset = 0; + ds->dsg_kind = DSG_FIXED; + return; + } + + if (sc->sc_level == 0) { + /* the variable is global, but declared in a module local + to the implementation or program module. + Such variables can be accessed through an offset from + the name of the module. + */ + ds->dsg_name = &(sc->sc_name[1]); + ds->dsg_offset = df->var_off; + ds->dsg_kind = DSG_FIXED; + return; + } + + if (sc->sc_level != proclevel) { + /* the variable is local to a statically enclosing procedure. + */ + assert(proclevel > sc->sc_level); + if (df->df_flags & (D_VARPAR|D_VALPAR)) { + /* value or var parameter + */ + C_lxa((arith) (proclevel - sc->sc_level)); + if (df->df_flags & D_VARPAR) { + /* var parameter + */ + C_adp(df->var_off); + C_loi(pointer_size); + ds->dsg_offset = 0; + ds->dsg_kind = DSG_PLOADED; + return; + } + } + else C_lxl((arith) (proclevel - sc->sc_level)); + ds->dsg_kind = DSG_PLOADED; + ds->dsg_offset = df->var_off; + return; + } + + /* Now, finally, we have a local variable or a local parameter + */ + if (df->df_flags & D_VARPAR) { + /* a var parameter; address directly accessible. + */ + ds->dsg_kind = DSG_PFIXED; + } + else ds->dsg_kind = DSG_FIXED; + ds->dsg_offset =df->var_off; +} + +CodeDesig(nd, ds) + register struct node *nd; + register struct desig *ds; +{ + /* Generate code for a designator. Use divide and conquer + principle + */ + + switch(nd->nd_class) { /* Divide */ + case Def: { + register struct def *df = nd->nd_def; + + switch(df->df_kind) { + case D_FIELD: + CodeFieldDesig(df, ds); + break; + + case D_VARIABLE: + CodeVarDesig(df, ds); + break; + + default: + crash("(CodeDesig) Def"); + } + } + break; + + case Link: + assert(nd->nd_symb == '.'); + assert(nd->nd_right->nd_class == Def); + CodeDesig(nd->nd_left, ds); + CodeFieldDesig(nd->nd_right->nd_def, ds); + break; + + case Oper: + assert(nd->nd_symb == '['); + CodeDesig(nd->nd_left, ds); + CodeAddress(ds); + *ds = InitDesig; + CodeExpr(nd->nd_right, ds, NO_LABEL, NO_LABEL); + CodeValue(ds, nd->nd_right->nd_type->tp_size); + CodeCoercion(nd->nd_right->nd_type, int_type); + if (IsConformantArray(nd->nd_left->nd_type)) { + /* ??? */ + } + else { + /* load address of descriptor + */ + /* ??? */ + } + break; + + case Uoper: + assert(nd->nd_symb == '^'); + CodeDesig(nd->nd_right, ds); + switch(ds->dsg_kind) { + case DSG_LOADED: + ds->dsg_kind = DSG_PLOADED; + break; + + case DSG_INDEXED: + case DSG_PLOADED: + case DSG_PFIXED: + CodeValue(ds, pointer_size); + ds->dsg_kind = DSG_PLOADED; + ds->dsg_offset = 0; + break; + + case DSG_FIXED: + ds->dsg_kind = DSG_PFIXED; + break; + + default: + crash("(CodeDesig) Uoper"); + } + break; + + default: + crash("(CodeDesig) class"); + } +} diff --git a/lang/m2/comp/desig.h b/lang/m2/comp/desig.h index ffbbb65b..ac2f3760 100644 --- a/lang/m2/comp/desig.h +++ b/lang/m2/comp/desig.h @@ -44,10 +44,12 @@ struct withdesig { struct scope *w_scope; /* scope in which fields of this record reside */ - struct desig *w_desig; /* a desig structure for this particular + struct desig w_desig; /* a desig structure for this particular designator */ }; extern struct withdesig *WithDesigs; -extern struct desig Desig; +extern struct desig Desig, InitDesig; + +#define NO_LABEL ((label) 0) diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index 17fe39c5..782ad9b1 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -64,13 +64,34 @@ EnterIdList(idlist, kind, flags, type, scope, addr) df->df_type = type; df->df_flags |= flags; if (addr) { + int xalign = type->tp_align; + + if (xalign < word_align && kind != D_FIELD) { + xalign = word_align; + } + if (*addr >= 0) { - off = align(*addr, type->tp_align); - *addr = off + type->tp_size; + if (scope->sc_level) { + /* alignment of parameters is on + word boundaries. We cannot do any + better, because we don't know the + alignment of the stack pointer when + starting to push parameters + */ + off = *addr; + *addr = align(off, word_align); + } + else { + /* for global variables we can honour + the alignment requirements totally. + */ + off = align(*addr, xalign); + *addr = off + type->tp_size; + } } else { - off = -align(-*addr, type->tp_align); - *addr = off - type->tp_size; + off = -align(-*addr-type->tp_size, xalign); + *addr = off; } if (kind == D_VARIABLE) { df->var_off = off; diff --git a/lang/m2/comp/error.c b/lang/m2/comp/error.c index 81588868..38a29fff 100644 --- a/lang/m2/comp/error.c +++ b/lang/m2/comp/error.c @@ -111,6 +111,20 @@ fatal(fmt, args) sys_stop(S_EXIT); } +/*VARARGS1*/ +crash(fmt, args) + char *fmt; + int args; +{ + + _error(CRASH, NULLNODE, fmt, &args); +#ifdef DEBUG + sys_stop(S_ABORT); +#else + sys_stop(S_EXIT); +#endif +} + _error(class, node, fmt, argv) int class; struct node *node; diff --git a/lang/m2/comp/type.H b/lang/m2/comp/type.H index ef74b993..b9c0eaf0 100644 --- a/lang/m2/comp/type.H +++ b/lang/m2/comp/type.H @@ -45,7 +45,9 @@ struct record { struct proc { struct paramlist *pr_params; + arith pr_nbpar; #define prc_params tp_value.tp_proc.pr_params +#define prc_nbpar tp_value.tp_proc.pr_nbpar }; struct type { diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index a15405cf..5898569b 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -149,6 +149,20 @@ init_types() */ register struct type *tp; + /* first, do some checking + */ + if (int_size != word_size) { + fatal("Integer size not equal to word size"); + } + + if (long_size < int_size) { + fatal("Long integer size smaller than integer size"); + } + + if (double_size < float_size) { + fatal("Long real size smaller than real size"); + } + /* character type */ char_type = standard_type(T_CHAR, 1, (arith) 1); diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index 9c4ba1cf..1ea53dd6 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -217,8 +217,11 @@ WalkStat(nd, lab) assert(nd->nd_class == Stat); switch(nd->nd_symb) { - case BECOMES: - WalkExpr(right); + case BECOMES: { + struct desig ds; + + WalkExpr(right, NO_LABEL, NO_LABEL); + ds = Desig; WalkDesignator(left); /* May we do it in this order??? */ if (! TstAssCompat(left->nd_type, right->nd_type)) { @@ -226,18 +229,19 @@ WalkStat(nd, lab) break; } - CodeAssign(nd); - + CodeAssign(nd, &ds, &Desig); + } break; case IF: - { label l1, l2; + { label l1, l2, l3; l1 = instructionlabel++; l2 = instructionlabel++; - ExpectBool(left); + l3 = instructionlabel++; + ExpectBool(left, l3, l1); assert(right->nd_symb == THEN); - C_zeq(l1); + C_df_ilb(l3); WalkNode(right->nd_left, lab); if (right->nd_right) { /* ELSE part */ @@ -255,13 +259,14 @@ WalkStat(nd, lab) break; case WHILE: - { label l1, l2; + { label l1, l2, l3; l1 = instructionlabel++; l2 = instructionlabel++; + l3 = instructionlabel++; C_df_ilb(l1); - ExpectBool(left); - C_zeq(l2); + ExpectBool(left, l3, l2); + C_df_ilb(l3); WalkNode(right, lab); C_bra(l1); C_df_ilb(l2); @@ -269,13 +274,14 @@ WalkStat(nd, lab) } case REPEAT: - { label l1; + { label l1, l2; l1 = instructionlabel++; + l2 = instructionlabel++; C_df_ilb(l1); WalkNode(left, lab); - ExpectBool(right); - C_zeq(l1); + ExpectBool(right, l2, l1); + C_df_ilb(l2); break; } @@ -314,10 +320,9 @@ WalkStat(nd, lab) Decide here wether to use a temporary variable or not, depending on the value of Desig. Suggestion: temporary if Desig != DSG_FIXED - - And then: - wds.w_desig = Desig; ??? + ??? */ + wds.w_desig = Desig; link.sc_scope = wds.w_scope; link.next = CurrVis; CurrVis = &link; @@ -335,7 +340,7 @@ WalkStat(nd, lab) case RETURN: if (right) { - WalkExpr(right); + WalkExpr(right, NO_LABEL, NO_LABEL); /* What kind of compatibility do we need here ??? assignment compatibility? */ @@ -352,22 +357,24 @@ node_error(right, "type incompatibility in RETURN statement"); } } -ExpectBool(nd) +ExpectBool(nd, true_label, false_label) struct node *nd; + label true_label, false_label; { /* "nd" must indicate a boolean expression. Check this and generate code to evaluate the expression. */ - WalkExpr(nd); + WalkExpr(nd, true_label, false_label); if (nd->nd_type != bool_type && nd->nd_type != error_type) { node_error(nd, "boolean expression expected"); } } -WalkExpr(nd) +WalkExpr(nd, true_label, false_label) struct node *nd; + label true_label, false_label; { /* Check an expression and generate code for it */ @@ -376,7 +383,8 @@ WalkExpr(nd) if (! chk_expr(nd)) return; - /* ??? */ + Desig = InitDesig; + CodeExpr(nd, &Desig, true_label, false_label); } WalkDesignator(nd) @@ -389,25 +397,8 @@ WalkDesignator(nd) if (! chk_designator(nd, DESIGNATOR|VARIABLE)) return; - /* ??? */ -} - -CodeCall(nd) - struct node *nd; -{ - /* Generate code for a procedure call. Checking of parameters - and result is already done. - */ - /* ??? */ -} - -CodeAssign(nd) - struct node *nd; -{ - /* Generate code for an assignment. Testing of type - compatibility and the like is already done. - */ - /* ??? */ + Desig = InitDesig; + CodeDesig(nd, &Desig); } #ifdef DEBUG From deb9ab046149c414034f5e4caaeee114027c6869 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 23 May 1986 09:46:31 +0000 Subject: [PATCH 0195/1625] newer version --- lang/m2/comp/Makefile | 10 +++- lang/m2/comp/chk_expr.c | 70 +++++++++++------------ lang/m2/comp/code.c | 24 ++++++-- lang/m2/comp/cstoper.c | 7 ++- lang/m2/comp/desig.c | 47 ++++++++++++++++ lang/m2/comp/error.c | 2 +- lang/m2/comp/expression.g | 2 +- lang/m2/comp/tmpvar.C | 114 ++++++++++++++++++++++++++++++++++++++ lang/m2/comp/walk.c | 48 +++++++++++++--- 9 files changed, 267 insertions(+), 57 deletions(-) create mode 100644 lang/m2/comp/tmpvar.C diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index ee5c819f..42805283 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -5,7 +5,7 @@ HDIR = ../../em/h PKGDIR = ../../em/pkg LIBDIR = ../../em/lib -INCLUDES = -I$(HDIR) -I$(PKGDIR) -I/user1/erikb/em/h +INCLUDES = -I$(HDIR) -I/usr/em/h -I$(PKGDIR) -I/user1/erikb/em/h LSRC = tokenfile.g program.g declar.g expression.g statement.g CC = cc @@ -18,7 +18,8 @@ LOBJ = tokenfile.o program.o declar.o expression.o statement.o COBJ = LLlex.o LLmessage.o char.o error.o main.o \ symbol2str.o tokenname.o idf.o input.o type.o def.o \ scope.o misc.o enter.o defmodule.o typequiv.o node.o \ - cstoper.o chk_expr.o options.o walk.o casestat.o desig.o code.o + cstoper.o chk_expr.o options.o walk.o casestat.o desig.o \ + code.o tmpvar.o OBJ = $(COBJ) $(LOBJ) Lpars.o GENFILES= tokenfile.c \ program.c declar.c expression.c statement.c \ @@ -58,6 +59,7 @@ def.h: def.H make.allocd type.h: type.H make.allocd node.h: node.H make.allocd scope.c: scope.C make.allocd +tmpvar.c: tmpvar.C make.allocd casestat.c: casestat.C make.allocd char.c: char.tab tab @@ -100,7 +102,9 @@ cstoper.o: LLlex.h Lpars.h debug.h idf.h node.h standards.h target_sizes.h type. chk_expr.o: LLlex.h Lpars.h const.h debug.h def.h idf.h node.h scope.h standards.h type.h options.o: idfsize.h main.h ndir.h type.h walk.o: LLlex.h Lpars.h debug.h def.h desig.h main.h node.h scope.h type.h -casestat.o: LLlex.h Lpars.h debug.h density.h node.h type.h +casestat.o: LLlex.h Lpars.h debug.h density.h desig.h node.h type.h +desig.o: LLlex.h debug.h def.h desig.h node.h scope.h type.h +code.o: LLlex.h Lpars.h debug.h def.h desig.h node.h scope.h type.h tokenfile.o: Lpars.h program.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h type.h declar.o: LLlex.h Lpars.h debug.h def.h idf.h main.h misc.h node.h scope.h type.h diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index 5934c406..31e505de 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -244,7 +244,7 @@ rem_set(set) } struct node * -getarg(argp, bases) +getarg(argp, bases, designator) struct node *argp; { struct type *tp; @@ -254,7 +254,10 @@ getarg(argp, bases) return 0; } argp = argp->nd_right; - if (!chk_expr(argp->nd_left)) return 0; + if ((!designator && !chk_expr(argp->nd_left)) || + (designator && !chk_designator(argp->nd_left, DESIGNATOR))) { + return 0; + } tp = argp->nd_left->nd_type; if (tp->tp_fund == T_SUBRANGE) tp = tp->next; if (bases && !(tp->tp_fund & bases)) { @@ -305,7 +308,6 @@ chk_call(expp) if (left->nd_class == Def && (left->nd_def->df_kind & (D_HTYPE|D_TYPE|D_HIDDEN))) { /* It was a type cast. This is of course not portable. - No runtime action. Remove it. */ arg = expp->nd_right; if ((! arg) || arg->nd_right) { @@ -317,14 +319,18 @@ node_error(expp, "only one parameter expected in type cast"); if (arg->nd_type->tp_size != left->nd_type->tp_size) { node_error(expp, "unequal sizes in type cast"); } - arg->nd_type = left->nd_type; - FreeNode(expp->nd_left); - expp->nd_right->nd_left = 0; - FreeNode(expp->nd_right); - *expp = *arg; - arg->nd_left = 0; - arg->nd_right = 0; - FreeNode(arg); + if (arg->nd_class == Value) { + struct type *tp = left->nd_type; + + FreeNode(expp->nd_left); + expp->nd_right->nd_left = 0; + FreeNode(expp->nd_right); + expp->nd_left = expp->nd_right = 0; + *expp = *arg; + expp->nd_type = tp; + } + else expp->nd_type = left->nd_type; + return 1; } @@ -362,7 +368,7 @@ chk_proccall(expp) param = left->nd_type->prc_params; while (param) { - if (!(arg = getarg(arg, 0))) return 0; + if (!(arg = getarg(arg, 0, param->par_var))) return 0; if (! TstParCompat(param->par_type, arg->nd_left->nd_type, @@ -371,12 +377,6 @@ node_error(arg->nd_left, "type incompatibility in parameter"); return 0; } - if (param->par_var && - !chk_designator(arg->nd_left, VARIABLE|DESIGNATOR)) { - node_error(arg->nd_left,"VAR parameter expected"); - return 0; - } - param = param->next; } @@ -451,20 +451,14 @@ chk_designator(expp, flag) if (expp->nd_class == Link) { assert(expp->nd_symb == '.'); + assert(expp->nd_right->nd_class == Name); if (! chk_designator(expp->nd_left, (flag|HASSELECTORS))) return 0; tp = expp->nd_left->nd_type; - if (expp->nd_right->nd_class == Def) { - /* We were here already! - */ - return 1; - } - assert(tp->tp_fund == T_RECORD); - assert(expp->nd_right->nd_class == Name); df = lookup(expp->nd_right->nd_IDF, tp->rec_scope); @@ -892,7 +886,7 @@ left->nd_def->df_idf->id_text, left->nd_def->df_value.df_stdname)); switch(left->nd_def->df_value.df_stdname) { case S_ABS: - if (!(arg = getarg(arg, T_NUMERIC))) return 0; + if (!(arg = getarg(arg, T_NUMERIC, 0))) return 0; left = arg->nd_left; expp->nd_type = left->nd_type; if (left->nd_class == Value) cstcall(expp, S_ABS); @@ -900,25 +894,25 @@ left->nd_def->df_idf->id_text, left->nd_def->df_value.df_stdname)); case S_CAP: expp->nd_type = char_type; - if (!(arg = getarg(arg, T_CHAR))) return 0; + if (!(arg = getarg(arg, T_CHAR, 0))) return 0; left = arg->nd_left; if (left->nd_class == Value) cstcall(expp, S_CAP); break; case S_CHR: expp->nd_type = char_type; - if (!(arg = getarg(arg, T_INTORCARD))) return 0; + if (!(arg = getarg(arg, T_INTORCARD, 0))) return 0; left = arg->nd_left; if (left->nd_class == Value) cstcall(expp, S_CHR); break; case S_FLOAT: expp->nd_type = real_type; - if (!(arg = getarg(arg, T_INTORCARD))) return 0; + if (!(arg = getarg(arg, T_INTORCARD, 0))) return 0; break; case S_HIGH: - if (!(arg = getarg(arg, T_ARRAY))) return 0; + if (!(arg = getarg(arg, T_ARRAY, 0))) return 0; expp->nd_type = arg->nd_left->nd_type->next; if (!expp->nd_type) { /* A dynamic array has no explicit index type @@ -930,19 +924,19 @@ left->nd_def->df_idf->id_text, left->nd_def->df_value.df_stdname)); case S_MAX: case S_MIN: - if (!(arg = getarg(arg, T_DISCRETE))) return 0; + if (!(arg = getarg(arg, T_DISCRETE, 0))) return 0; expp->nd_type = arg->nd_left->nd_type; cstcall(expp,left->nd_def->df_value.df_stdname); break; case S_ODD: - if (!(arg = getarg(arg, T_INTORCARD))) return 0; + if (!(arg = getarg(arg, T_INTORCARD, 0))) return 0; expp->nd_type = bool_type; if (arg->nd_left->nd_class == Value) cstcall(expp, S_ODD); break; case S_ORD: - if (!(arg = getarg(arg, T_DISCRETE))) return 0; + if (!(arg = getarg(arg, T_DISCRETE, 0))) return 0; expp->nd_type = card_type; if (arg->nd_left->nd_class == Value) cstcall(expp, S_ORD); break; @@ -957,7 +951,7 @@ left->nd_def->df_idf->id_text, left->nd_def->df_value.df_stdname)); case S_TRUNC: expp->nd_type = card_type; - if (!(arg = getarg(arg, T_REAL))) return 0; + if (!(arg = getarg(arg, T_REAL, 0))) return 0; break; case S_VAL: @@ -975,7 +969,7 @@ left->nd_def->df_idf->id_text, left->nd_def->df_value.df_stdname)); expp->nd_right = arg->nd_right; arg->nd_right = 0; FreeNode(arg); - arg = getarg(expp, T_INTORCARD); + arg = getarg(expp, T_INTORCARD, 0); if (!arg) return 0; if (arg->nd_left->nd_class == Value) cstcall(expp, S_VAL); break; @@ -983,7 +977,7 @@ left->nd_def->df_idf->id_text, left->nd_def->df_value.df_stdname)); case S_ADR: expp->nd_type = address_type; - if (!(arg = getarg(arg, D_VARIABLE|D_FIELD))) return 0; + if (!(arg = getarg(arg, 0, 1))) return 0; break; case S_DEC: @@ -991,7 +985,7 @@ left->nd_def->df_idf->id_text, left->nd_def->df_value.df_stdname)); expp->nd_type = 0; if (!(arg = getvariable(arg))) return 0; if (arg->nd_right) { - if (!(arg = getarg(arg, T_INTORCARD))) return 0; + if (!(arg = getarg(arg, T_INTORCARD, 0))) return 0; } break; @@ -1011,7 +1005,7 @@ left->nd_def->df_idf->id_text, left->nd_def->df_value.df_stdname)); node_error(arg, "EXCL and INCL expect a SET parameter"); return 0; } - if (!(arg = getarg(arg, T_DISCRETE))) return 0; + if (!(arg = getarg(arg, T_DISCRETE, 0))) return 0; if (!TstAssCompat(tp->next, arg->nd_left->nd_type)) { /* What type of compatibility do we want here? apparently assignment compatibility! ??? ??? diff --git a/lang/m2/comp/code.c b/lang/m2/comp/code.c index f47349e1..668d527b 100644 --- a/lang/m2/comp/code.c +++ b/lang/m2/comp/code.c @@ -22,6 +22,7 @@ static char *RcsId = "$Header$"; #include "Lpars.h" extern label data_label(); +extern label text_label(); extern char *long2str(); extern char *symbol2str(); extern int proclevel; @@ -42,7 +43,7 @@ CodeConst(cst, size) else { C_df_dlb(dlab = data_label()); C_rom_icon(long2str((long) cst), 10); - C_lae_dlb(dlab); + C_lae_dlb(dlab, (arith) 0); C_loi(size); } } @@ -53,6 +54,10 @@ CodeString(nd) label lab; + if (nd->nd_type == charc_type) { + C_loc(nd->nd_INT); + return; + } C_df_dlb(lab = data_label()); C_rom_scon(nd->nd_STR, nd->nd_SLE); C_lae_dlb(lab); @@ -74,7 +79,6 @@ CodeExpr(nd, ds, true_label, false_label) struct desig *ds; label true_label, false_label; { - struct desig ds1, ds2; switch(nd->nd_class) { case Def: @@ -174,6 +178,18 @@ CodeCall(nd) } tp = left->nd_type; + if (left->nd_class == Def && + (left->nd_def->df_kind & (D_TYPE|D_HTYPE|D_HIDDEN))) { + /* it was just a cast. Simply ignore it + */ + Des = InitDesig; + CodeExpr(nd->nd_right->nd_left, &Des, NO_LABEL, NO_LABEL); + CodeValue(&Des); + *nd = *(nd->nd_right->nd_left); + nd->nd_type = left->nd_def->df_type; + return; + } + assert(tp->tp_fund == T_PROCEDURE); for (param = left->nd_type->prc_params; param; param = param->next) { @@ -223,7 +239,7 @@ CodeStd(nd) CodeAssign(nd, dst, dss) struct node *nd; - struct desig *dst, dss; + struct desig *dst, *dss; { /* Generate code for an assignment. Testing of type compatibility and the like is already done. @@ -262,8 +278,6 @@ CodeOper(expr, true_label, false_label) register struct node *leftop = expr->nd_left; register struct node *rightop = expr->nd_right; register struct type *tp = expr->nd_type; - struct desig Des; - register struct desig *ds = &Des; switch (oper) { case '+': diff --git a/lang/m2/comp/cstoper.c b/lang/m2/comp/cstoper.c index aba69405..b298221a 100644 --- a/lang/m2/comp/cstoper.c +++ b/lang/m2/comp/cstoper.c @@ -289,9 +289,13 @@ cstset(expp) } if (j == setsize) expp->nd_INT = expp->nd_symb == '='; expp->nd_class = Value; + expp->nd_symb = INTEGER; free((char *) expp->nd_left->nd_set); free((char *) expp->nd_right->nd_set); - break; + FreeNode(expp->nd_left); + FreeNode(expp->nd_right); + expp->nd_left = expp->nd_right = 0; + return; default: assert(0); } @@ -319,6 +323,7 @@ cstcall(expp, call) FreeNode(expp->nd_right); } expp->nd_class = Value; + expp->nd_symb = INTEGER; switch(call) { case S_ABS: if (expr->nd_type->tp_fund == T_REAL) { diff --git a/lang/m2/comp/desig.c b/lang/m2/comp/desig.c index 7f09be6c..79d0f600 100644 --- a/lang/m2/comp/desig.c +++ b/lang/m2/comp/desig.c @@ -30,6 +30,7 @@ struct desig InitDesig = {DSG_INIT, 0, 0}; CodeValue(ds, size) register struct desig *ds; + arith size; { /* Generate code to load the value of the designator described in "ds" @@ -73,6 +74,49 @@ CodeValue(ds, size) ds->dsg_kind = DSG_LOADED; } +CodeStore(ds, size) + register struct desig *ds; + arith size; +{ + /* Generate code to store the value on the stack in the designator + described in "ds" + */ + + switch(ds->dsg_kind) { + case DSG_FIXED: + if (size == word_size) { + if (ds->dsg_name) { + C_ste_dnam(ds->dsg_name, ds->dsg_offset); + } + else C_stl(ds->dsg_offset); + break; + } + + if (size == dword_size) { + if (ds->dsg_name) { + C_sde_dnam(ds->dsg_name, ds->dsg_offset); + } + else C_sdl(ds->dsg_offset); + break; + } + /* Fall through */ + case DSG_PLOADED: + case DSG_PFIXED: + CodeAddress(ds); + C_sti(size); + break; + + case DSG_INDEXED: + C_sar(word_size); + break; + + default: + crash("(CodeStore)"); + } + + ds->dsg_kind = DSG_INIT; +} + CodeAddress(ds) register struct desig *ds; { @@ -144,6 +188,7 @@ CodeFieldDesig(df, ds) /* Found it. Now, act like it was a selection. */ *ds = wds->w_desig; + assert(ds->dsg_kind == DSG_PFIXED); } switch(ds->dsg_kind) { @@ -277,6 +322,7 @@ CodeDesig(nd, ds) case Link: assert(nd->nd_symb == '.'); assert(nd->nd_right->nd_class == Def); + CodeDesig(nd->nd_left, ds); CodeFieldDesig(nd->nd_right->nd_def, ds); break; @@ -297,6 +343,7 @@ CodeDesig(nd, ds) */ /* ??? */ } + ds->dsg_kind = DSG_INDEXED; break; case Uoper: diff --git a/lang/m2/comp/error.c b/lang/m2/comp/error.c index 38a29fff..a430f70b 100644 --- a/lang/m2/comp/error.c +++ b/lang/m2/comp/error.c @@ -49,7 +49,7 @@ extern char *symbol2str(); */ #ifdef DEBUG -/*VARARGS2*/ +/*VARARGS1*/ debug(fmt, args) char *fmt; { diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index 6825795f..8f306e29 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -200,8 +200,8 @@ factor(struct node **p;) tp = charc_type; i = *(dot.TOK_STR) & 0377; - free(dot.TOK_STR); free((char *) dot.tk_data.tk_str); + free(dot.TOK_STR); dot.TOK_INT = i; } else tp = standard_type(T_STRING, 1, dot.TOK_SLE); diff --git a/lang/m2/comp/tmpvar.C b/lang/m2/comp/tmpvar.C new file mode 100644 index 00000000..c4778bf2 --- /dev/null +++ b/lang/m2/comp/tmpvar.C @@ -0,0 +1,114 @@ +/* T E M P O R A R Y V A R I A B L E S */ + +#ifndef NORCSID +static char *RcsId = "$Header$"; +#endif + +/* Code for the allocation and de-allocation of temporary variables, + allowing re-use. +*/ + +#include "debug.h" + +#include +#include +#include +#include +#include + +#include "def.h" +#include "type.h" +#include "scope.h" + +struct tmpvar { + struct tmpvar *next; + arith t_offset; /* offset from LocalBase */ +}; + +/* STATICALLOCDEF "tmpvar" */ + +static struct tmpvar *TmpInts, /* for integer temporaries */ + *TmpPtrs; /* for pointer temporaries */ + +extern arith align(); + +arith +NewInt() +{ + arith offset; + register struct tmpvar *tmp; + + if (!TmpInts) { + offset = - align(int_size - CurrentScope->sc_off, int_align); + CurrentScope->sc_off = offset; + C_ms_reg(offset, int_size, reg_any, 0); + } + else { + tmp = TmpInts; + offset = tmp->t_offset; + TmpInts = tmp->next; + free_tmpvar(tmp); + } + return offset; +} + +arith +NewPtr() +{ + arith offset; + register struct tmpvar *tmp; + + if (!TmpPtrs) { + offset = - align(pointer_size - CurrentScope->sc_off, pointer_align); + CurrentScope->sc_off = offset; + C_ms_reg(offset, pointer_size, reg_pointer, 0); + } + else { + tmp = TmpPtrs; + offset = tmp->t_offset; + TmpPtrs = tmp->next; + free_tmpvar(tmp); + } + return offset; +} + +FreeInt(off) + arith off; +{ + register struct tmpvar *tmp; + + tmp = new_tmpvar(); + tmp->next = TmpInts; + tmp->t_offset = off; + TmpInts = tmp; +} + +FreePtr(off) + arith off; +{ + register struct tmpvar *tmp; + + tmp = new_tmpvar(); + tmp->next = TmpPtrs; + tmp->t_offset = off; + TmpPtrs = tmp; +} + +TmpClose() +{ + register struct tmpvar *tmp, *tmp1; + + tmp = TmpInts; + while (tmp) { + tmp1 = tmp; + tmp = tmp->next; + free_tmpvar(tmp1); + } + tmp = TmpPtrs; + while (tmp) { + tmp1 = tmp; + tmp = tmp->next; + free_tmpvar(tmp1); + } + TmpInts = TmpPtrs = 0; +} diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index 1ea53dd6..f71cd5ed 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -22,8 +22,10 @@ static char *RcsId = "$Header$"; #include "node.h" #include "Lpars.h" #include "desig.h" +#include "f_info.h" extern arith align(); +extern arith NewPtr(); extern int proclevel; static label instructionlabel; static char return_expr_occurred; @@ -44,6 +46,22 @@ data_label() return ++datalabel; } +static +DoProfil() +{ + static label filename_label = 0; + + if (options['p']) { + if (!filename_label) { + filename_label = data_label(); + C_df_dlb(filename_label); + C_rom_scon(FileName, (arith) strlen(FileName)); + } + + C_fil_dlb(filename_label, (arith) 0); + } +} + WalkModule(module) register struct def *module; { @@ -96,11 +114,13 @@ WalkModule(module) instructionlabel = 2; func_type = 0; C_pro_narg(CurrentScope->sc_name); + DoProfil(); MkCalls(CurrentScope->sc_def); WalkNode(module->mod_body, (label) 0); C_df_ilb((label) 1); C_ret(0); - C_end(align(-CurrentScope->sc_off, word_align)); + C_end(-CurrentScope->sc_off); + TmpClose(); CurrVis = vis; } @@ -121,6 +141,7 @@ WalkProcedure(procedure) /* Generate code for this procedure */ C_pro_narg(CurrentScope->sc_name); + DoProfil(); /* generate calls to initialization routines of modules defined within this procedure */ @@ -137,7 +158,8 @@ node_error(procedure->prc_body,"function procedure does not return a value"); C_ret((int) align(func_type->tp_size, word_align)); } else C_ret(0); - C_end(align(-CurrentScope->sc_off, word_align)); + C_end(-CurrentScope->sc_off); + TmpClose(); CurrVis = vis; proclevel--; } @@ -203,6 +225,8 @@ WalkStat(nd, lab) register struct node *left = nd->nd_left; register struct node *right = nd->nd_right; + if (options['p']) C_lin((arith) nd->nd_lineno); + if (!nd) { /* Empty statement */ @@ -306,6 +330,7 @@ WalkStat(nd, lab) { struct scopelist link; struct withdesig wds; + arith tmp = 0; WalkDesignator(left); if (left->nd_type->tp_fund != T_RECORD) { @@ -316,12 +341,18 @@ WalkStat(nd, lab) wds.w_next = WithDesigs; WithDesigs = &wds; wds.w_scope = left->nd_type->rec_scope; - /* - Decide here wether to use a temporary variable or - not, depending on the value of Desig. - Suggestion: temporary if Desig != DSG_FIXED - ??? - */ + if (Desig.dsg_kind != DSG_PFIXED) { + /* In this case, we use a temporary variable + */ + CodeAddress(&Desig); + Desig.dsg_kind = DSG_FIXED; + /* Only for the store ... */ + Desig.dsg_offset = tmp = NewPtr(); + Desig.dsg_name = 0; + CodeStore(&Desig, pointer_size); + Desig.dsg_kind = DSG_PFIXED; + /* the record is indirectly available */ + } wds.w_desig = Desig; link.sc_scope = wds.w_scope; link.next = CurrVis; @@ -329,6 +360,7 @@ WalkStat(nd, lab) WalkNode(right, lab); CurrVis = link.next; WithDesigs = wds.w_next; + if (tmp) FreePtr(tmp); break; } From e08808d5bcba42edc217c028365faabb59def590 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 23 May 1986 19:25:21 +0000 Subject: [PATCH 0196/1625] newer version --- lang/m2/comp/LLlex.c | 1 - lang/m2/comp/LLlex.h | 5 ++- lang/m2/comp/chk_expr.c | 5 +-- lang/m2/comp/code.c | 67 ++++++++++++++++++++++++++++++++++++----- lang/m2/comp/def.H | 1 - lang/m2/comp/desig.c | 2 ++ lang/m2/comp/error.c | 11 +++---- lang/m2/comp/f_info.h | 2 +- lang/m2/comp/main.c | 2 +- lang/m2/comp/node.H | 1 - lang/m2/comp/node.c | 4 +-- lang/m2/comp/type.H | 3 -- lang/m2/comp/type.c | 10 +++--- lang/m2/comp/typequiv.c | 12 ++++++-- lang/m2/comp/walk.c | 51 +++++++++++++++++-------------- 15 files changed, 114 insertions(+), 63 deletions(-) diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index 9edc42d6..c7738c64 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -121,7 +121,6 @@ LLlex() return tk->tk_symb; } tk->tk_lineno = LineNumber; - tk->tk_filename = FileName; again: LoadChar(ch); diff --git a/lang/m2/comp/LLlex.h b/lang/m2/comp/LLlex.h index bf207ad9..dae0151a 100644 --- a/lang/m2/comp/LLlex.h +++ b/lang/m2/comp/LLlex.h @@ -8,9 +8,8 @@ struct string { }; struct token { - int tk_symb; /* token itself */ - char *tk_filename; /* filename in which it occurred */ - int tk_lineno; /* linenumber on which it occurred */ + short tk_symb; /* token itself */ + unsigned short tk_lineno; /* linenumber on which it occurred */ union { struct idf *tk_idf; /* IDENT */ struct string *tk_str; /* STRING */ diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index 31e505de..daf2befb 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -503,15 +503,12 @@ df->df_idf->id_text); expp->nd_symb = INTEGER; } else { - char *fn; - int ln; + unsigned int ln; assert(df->df_kind == D_CONST); ln = expp->nd_lineno; - fn = expp->nd_filename; *expp = *(df->con_const); expp->nd_lineno = ln; - expp->nd_filename = fn; } } diff --git a/lang/m2/comp/code.c b/lang/m2/comp/code.c index 668d527b..cd2101fa 100644 --- a/lang/m2/comp/code.c +++ b/lang/m2/comp/code.c @@ -51,7 +51,6 @@ CodeConst(cst, size) CodeString(nd) struct node *nd; { - label lab; if (nd->nd_type == charc_type) { @@ -75,8 +74,8 @@ CodeReal(nd) } CodeExpr(nd, ds, true_label, false_label) - struct node *nd; - struct desig *ds; + register struct node *nd; + register struct desig *ds; label true_label, false_label; { @@ -135,9 +134,22 @@ CodeExpr(nd, ds, true_label, false_label) ds->dsg_kind = DSG_LOADED; break; + case Set: { + arith *st; + int i; + + st = nd->nd_set; + for (i = nd->nd_type->tp_size / word_size, st = nd->nd_set + i; + i > 0; + i--) { + C_loc(*--st); + } + ds->dsg_kind = DSG_LOADED; + } + break; + case Xset: - case Set: - /* ??? */ + CodeSet(nd); ds->dsg_kind = DSG_LOADED; break; @@ -160,7 +172,7 @@ CodeCoercion(t1, t2) } CodeCall(nd) - struct node *nd; + register struct node *nd; { /* Generate code for a procedure call. Checking of parameters and result is already done. @@ -250,7 +262,7 @@ CodeAssign(nd, dst, dss) } Operands(leftop, rightop) - struct node *leftop, *rightop; + register struct node *leftop, *rightop; { struct desig Des; @@ -514,7 +526,7 @@ CodeOper(expr, true_label, false_label) /* compare() serves as an auxiliary function of CodeOper */ compare(relop, lbl) int relop; - label lbl; + register label lbl; { switch (relop) { case '<': @@ -596,3 +608,42 @@ CodeUoper(nd) crash("Bad unary operator"); } } + +CodeSet(nd) + register struct node *nd; +{ + struct type *tp = nd->nd_type; + + nd = nd->nd_right; + while (nd) { + assert(nd->nd_class == Link && nd->nd_symb == ','); + + CodeEl(nd->nd_left, tp); + nd = nd->nd_right; + if (nd) { + C_ior(tp->tp_size); + } + } +} + +CodeEl(nd, tp) + register struct node *nd; + struct type *tp; +{ + + if (nd->nd_class == Link && nd->nd_symb == UPTO) { + C_zer(tp->tp_size); /* empty set */ + C_lor((arith) 1); /* SP: address of set */ + Operands(nd->nd_left, nd->nd_right); + C_cal("_LtoUset"); /* library routine to fill set */ + C_asp(2 * word_size + pointer_size); + } + else { + struct desig Des; + + Des = InitDesig; + CodeExpr(nd, &Des, NO_LABEL, NO_LABEL); + CodeValue(nd, word_size); + C_set(tp->tp_size); + } +} diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H index 95037b6f..176452c3 100644 --- a/lang/m2/comp/def.H +++ b/lang/m2/comp/def.H @@ -61,7 +61,6 @@ struct dforward { char *fo_name; #define for_node df_value.df_forward.fo_node #define for_vis df_value.df_forward.fo_vis -#define for_scopes df_value.df_forward.fo_scopes #define for_name df_value.df_forward.fo_name }; diff --git a/lang/m2/comp/desig.c b/lang/m2/comp/desig.c index 79d0f600..fd7949bb 100644 --- a/lang/m2/comp/desig.c +++ b/lang/m2/comp/desig.c @@ -329,6 +329,7 @@ CodeDesig(nd, ds) case Oper: assert(nd->nd_symb == '['); + CodeDesig(nd->nd_left, ds); CodeAddress(ds); *ds = InitDesig; @@ -348,6 +349,7 @@ CodeDesig(nd, ds) case Uoper: assert(nd->nd_symb == '^'); + CodeDesig(nd->nd_right, ds); switch(ds->dsg_kind) { case DSG_LOADED: diff --git a/lang/m2/comp/error.c b/lang/m2/comp/error.c index a430f70b..3c612e16 100644 --- a/lang/m2/comp/error.c +++ b/lang/m2/comp/error.c @@ -137,9 +137,8 @@ _error(class, node, fmt, argv) static unsigned int last_ln = 0; unsigned int ln = 0; static char * last_fn = 0; - char *fn = 0; static int e_seen = 0; - char *remark = 0; + register char *remark = 0; /* Since name and number are gathered from different places depending on the class, we first collect the relevant @@ -185,7 +184,6 @@ _error(class, node, fmt, argv) switch (class) { case WARNING: case ERROR: - fn = node ? node->nd_filename : dot.tk_filename; ln = node ? node->nd_lineno : dot.tk_lineno; break; case LEXWARNING: @@ -196,14 +194,13 @@ _error(class, node, fmt, argv) case VDEBUG: #endif DEBUG ln = LineNumber; - fn = FileName; break; } #ifdef DEBUG if (class != VDEBUG) { #endif - if (fn == last_fn && ln == last_ln) { + if (FileName == last_fn && ln == last_ln) { /* we've seen this place before */ e_seen++; if (e_seen == MAXERR_LINE) fmt = "etc ..."; @@ -215,14 +212,14 @@ _error(class, node, fmt, argv) else { /* brand new place */ last_ln = ln; - last_fn = fn; + last_fn = FileName; e_seen = 0; } #ifdef DEBUG } #endif DEBUG - if (fn) fprint(ERROUT, "\"%s\", line %u: ", fn, ln); + if (FileName) fprint(ERROUT, "\"%s\", line %u: ", FileName, ln); if (remark) fprint(ERROUT, "%s ", remark); diff --git a/lang/m2/comp/f_info.h b/lang/m2/comp/f_info.h index 92b1710a..edee620d 100644 --- a/lang/m2/comp/f_info.h +++ b/lang/m2/comp/f_info.h @@ -3,7 +3,7 @@ /* $Header$ */ struct f_info { - unsigned int f_lineno; + unsigned short f_lineno; char *f_filename; char *f_workingdir; }; diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index 62b780de..d4e112d5 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -140,7 +140,7 @@ AddStandards() { register struct def *df; struct def *Enter(); - static struct node nilnode = { 0, 0, Value, 0, { INTEGER, 0, 0}}; + static struct node nilnode = { 0, 0, Value, 0, { INTEGER, 0}}; (void) Enter("ABS", D_PROCEDURE, std_type, S_ABS); (void) Enter("CAP", D_PROCEDURE, std_type, S_CAP); diff --git a/lang/m2/comp/node.H b/lang/m2/comp/node.H index c8c29216..859e4bbc 100644 --- a/lang/m2/comp/node.H +++ b/lang/m2/comp/node.H @@ -24,7 +24,6 @@ struct node { #define nd_lab nd_token.tk_data.tk_lab #define nd_symb nd_token.tk_symb #define nd_lineno nd_token.tk_lineno -#define nd_filename nd_token.tk_filename #define nd_IDF nd_token.TOK_IDF #define nd_STR nd_token.TOK_STR #define nd_SLE nd_token.TOK_SLE diff --git a/lang/m2/comp/node.c b/lang/m2/comp/node.c index d0c982c3..352347c4 100644 --- a/lang/m2/comp/node.c +++ b/lang/m2/comp/node.c @@ -43,8 +43,8 @@ FreeNode(nd) list */ if (!nd) return; - if (nd->nd_left) FreeNode(nd->nd_left); - if (nd->nd_right) FreeNode(nd->nd_right); + FreeNode(nd->nd_left); + FreeNode(nd->nd_right); free_node(nd); } diff --git a/lang/m2/comp/type.H b/lang/m2/comp/type.H index b9c0eaf0..b0cbd564 100644 --- a/lang/m2/comp/type.H +++ b/lang/m2/comp/type.H @@ -29,11 +29,8 @@ struct subrange { struct array { struct type *ar_elem; /* Type of elements */ - arith ar_lb, ar_ub; /* Lower bound and upper bound */ label ar_descr; /* Label of array descriptor */ #define arr_elem tp_value.tp_arr.ar_elem -#define arr_lb tp_value.tp_arr.ar_lb -#define arr_ub tp_value.tp_arr.ar_ub #define arr_descr tp_value.tp_arr.ar_descr }; diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index 5898569b..cdea3b4e 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -387,15 +387,11 @@ ArraySizes(tp) */ switch(index_type->tp_fund) { case T_SUBRANGE: - tp->arr_lb = index_type->sub_lb; - tp->arr_ub = index_type->sub_ub; tp->tp_size = elem_size * (index_type->sub_ub - index_type->sub_lb + 1); break; case T_CHAR: case T_ENUMERATION: - tp->arr_lb = 0; - tp->arr_ub = index_type->enm_ncst - 1; tp->tp_size = elem_size * index_type->enm_ncst; break; default: @@ -453,6 +449,8 @@ lcm(m, n) DumpType(tp) register struct type *tp; { + if (!tp) return; + print(" a:%d; s:%ld;", tp->tp_align, (long) tp->tp_size); if (tp->next && tp->tp_fund != T_POINTER) { /* Avoid printing recursive types! @@ -501,9 +499,11 @@ DumpType(tp) break; } case T_ARRAY: - print("ARRAY %ld-%ld", (long) tp->arr_lb, (long) tp->arr_ub); + print("ARRAY"); print("; el:"); DumpType(tp->arr_elem); + print("; index:"); + DumpType(tp->next); break; case T_STRING: print("STRING"); break; diff --git a/lang/m2/comp/typequiv.c b/lang/m2/comp/typequiv.c index 2ddd5cf9..266a06a5 100644 --- a/lang/m2/comp/typequiv.c +++ b/lang/m2/comp/typequiv.c @@ -128,11 +128,12 @@ TstCompat(tp1, tp2) int TstAssCompat(tp1, tp2) - struct type *tp1, *tp2; + register struct type *tp1, *tp2; { /* Test if two types are assignment compatible. See Def 9.1. */ + register struct type *tp; if (TstCompat(tp1, tp2)) return 1; @@ -145,11 +146,16 @@ TstAssCompat(tp1, tp2) if (tp1 == char_type && tp2 == charc_type) return 1; if (tp1->tp_fund == T_ARRAY) { + /* check for string + */ arith size; - if (! tp1->next) return 0; + if (!(tp = tp1->next)) return 0; - size = tp1->arr_ub - tp1->arr_lb + 1; + if (tp->tp_fund == T_SUBRANGE) { + size = tp->sub_ub - tp->sub_lb + 1; + } + else size = tp->enm_ncst; tp1 = tp1->arr_elem; if (tp1->tp_fund == T_SUBRANGE) tp1 = tp1->next; return diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index f71cd5ed..111ea180 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -69,10 +69,12 @@ WalkModule(module) Also generate code for its body. */ register struct def *df = module->mod_vis->sc_scope->sc_def; + register struct scope *sc; struct scopelist *vis; vis = CurrVis; CurrVis = module->mod_vis; + sc = CurrentScope; if (!proclevel && module != Defined) { /* This module is a local module, but not within a @@ -80,12 +82,12 @@ WalkModule(module) variables. This is done by generating a "bss", with label "_". */ - arith size = align(CurrentScope->sc_off, word_align); + arith size = align(sc->sc_off, word_align); if (size == 0) size = word_size; /* WHY ??? because we generated an INA for it ??? */ - C_df_dnam(&(CurrentScope->sc_name[1])); + C_df_dnam(&(sc->sc_name[1])); C_bss_cst(size, (arith) 0, 0); } else if (CurrVis == Defined->mod_vis) { @@ -104,22 +106,22 @@ WalkModule(module) /* Now, walk through it's local definitions */ - WalkDef(CurrentScope->sc_def); + WalkDef(sc->sc_def); /* Now, generate initialization code for this module. First call initialization routines for modules defined within this module. */ - CurrentScope->sc_off = 0; + sc->sc_off = 0; instructionlabel = 2; func_type = 0; - C_pro_narg(CurrentScope->sc_name); + C_pro_narg(sc->sc_name); DoProfil(); - MkCalls(CurrentScope->sc_def); + MkCalls(sc->sc_def); WalkNode(module->mod_body, (label) 0); C_df_ilb((label) 1); C_ret(0); - C_end(-CurrentScope->sc_off); + C_end(-sc->sc_off); TmpClose(); CurrVis = vis; @@ -132,20 +134,22 @@ WalkProcedure(procedure) local definitions */ struct scopelist *vis = CurrVis; + register struct scope *sc; proclevel++; CurrVis = procedure->prc_vis; + sc = CurrentScope; - WalkDef(CurrentScope->sc_def); + WalkDef(sc->sc_def); /* Generate code for this procedure */ - C_pro_narg(CurrentScope->sc_name); + C_pro_narg(sc->sc_name); DoProfil(); /* generate calls to initialization routines of modules defined within this procedure */ - MkCalls(CurrentScope->sc_def); + MkCalls(sc->sc_def); return_expr_occurred = 0; instructionlabel = 2; func_type = procedure->df_type->next; @@ -158,7 +162,7 @@ node_error(procedure->prc_body,"function procedure does not return a value"); C_ret((int) align(func_type->tp_size, word_align)); } else C_ret(0); - C_end(-CurrentScope->sc_off); + C_end(-sc->sc_off); TmpClose(); CurrVis = vis; proclevel--; @@ -215,7 +219,7 @@ WalkNode(nd, lab) } WalkStat(nd, lab) - register struct node *nd; + struct node *nd; label lab; { /* Walk through a statement, generating code for it. @@ -224,8 +228,7 @@ WalkStat(nd, lab) */ register struct node *left = nd->nd_left; register struct node *right = nd->nd_right; - - if (options['p']) C_lin((arith) nd->nd_lineno); + register struct desig *pds = &Desig; if (!nd) { /* Empty statement @@ -233,6 +236,8 @@ WalkStat(nd, lab) return; } + if (options['p']) C_lin((arith) nd->nd_lineno); + if (nd->nd_class == Call) { if (chk_call(nd)) CodeCall(nd); return; @@ -253,7 +258,7 @@ WalkStat(nd, lab) break; } - CodeAssign(nd, &ds, &Desig); + CodeAssign(nd, &ds, pds); } break; @@ -341,16 +346,16 @@ WalkStat(nd, lab) wds.w_next = WithDesigs; WithDesigs = &wds; wds.w_scope = left->nd_type->rec_scope; - if (Desig.dsg_kind != DSG_PFIXED) { + if (pds->dsg_kind != DSG_PFIXED) { /* In this case, we use a temporary variable */ - CodeAddress(&Desig); - Desig.dsg_kind = DSG_FIXED; + CodeAddress(pds); + pds->dsg_kind = DSG_FIXED; /* Only for the store ... */ - Desig.dsg_offset = tmp = NewPtr(); - Desig.dsg_name = 0; - CodeStore(&Desig, pointer_size); - Desig.dsg_kind = DSG_PFIXED; + pds->dsg_offset = tmp = NewPtr(); + pds->dsg_name = 0; + CodeStore(pds, pointer_size); + pds->dsg_kind = DSG_PFIXED; /* the record is indirectly available */ } wds.w_desig = Desig; @@ -390,7 +395,7 @@ node_error(right, "type incompatibility in RETURN statement"); } ExpectBool(nd, true_label, false_label) - struct node *nd; + register struct node *nd; label true_label, false_label; { /* "nd" must indicate a boolean expression. Check this and From a504ee7e0965d863ad1632ae0a7b308f2be0548f Mon Sep 17 00:00:00 2001 From: erikb Date: Wed, 28 May 1986 08:40:06 +0000 Subject: [PATCH 0197/1625] revised the type checking of expr in "switch (expr)" --- lang/cem/cemcom/main.c | 3 +++ lang/cem/cemcom/switch.c | 15 +++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lang/cem/cemcom/main.c b/lang/cem/cemcom/main.c index feb46491..79bc29c7 100644 --- a/lang/cem/cemcom/main.c +++ b/lang/cem/cemcom/main.c @@ -252,6 +252,9 @@ init() pa_type = long_type; else fatal("pointer size incompatible with any integral size"); + + if (int_size != word_size) + fatal("int_size and word_size are not equal"); if (short_size > int_size || int_size > long_size) fatal("sizes of short/int/long decreasing"); diff --git a/lang/cem/cemcom/switch.c b/lang/cem/cemcom/switch.c index 3999206f..acc44e89 100644 --- a/lang/cem/cemcom/switch.c +++ b/lang/cem/cemcom/switch.c @@ -24,6 +24,14 @@ extern char options[]; static struct switch_hdr *switch_stack = 0; +/* (EB 86.05.20) The following rules hold for switch statements: + - the expression E in "switch(E)" is cast to 'int' (RM 9.7) + - the expression E in "case E:" must be 'int' (RM 9.7) + - the values in the CSA/CSB tables are words (EM 7.4) + + For simplicity, we suppose int_size == word_size. +*/ + code_startswitch(expr) struct expr *expr; { @@ -38,7 +46,8 @@ code_startswitch(expr) switch (fund) { case LONG: if (options['R']) - warning("long in switch"); + warning("long in switch (cast to int)"); + int2int(&expr, int_type); break; case DOUBLE: error("float/double in switch"); @@ -129,13 +138,11 @@ code_case(expr) error("case statement not in switch"); return; } - if (expr->ex_flags & EX_ERROR) { /* is probably 0 anyway */ return; } - expr->ex_type = sh->sh_type; - cut_size(expr); + ch7cast(&expr, SWITCH, sh->sh_type); ce = new_case_entry(); C_df_ilb(ce->ce_label = text_label()); ce->ce_value = val = expr->VL_VALUE; From cb9213bf8ccc38a0b8647d56a5559d2000ca1167 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 May 1986 18:36:51 +0000 Subject: [PATCH 0198/1625] newer version --- lang/m2/comp/LLlex.c | 4 - lang/m2/comp/LLmessage.c | 15 ++- lang/m2/comp/Makefile | 7 +- lang/m2/comp/casestat.C | 21 ++-- lang/m2/comp/chk_expr.c | 84 ++++++++++------ lang/m2/comp/code.c | 198 +++++++++++++++++++++++++++++++++----- lang/m2/comp/cstoper.c | 98 ++++++++++++++----- lang/m2/comp/declar.g | 54 +++++------ lang/m2/comp/def.H | 10 +- lang/m2/comp/def.c | 53 +++++++++- lang/m2/comp/defmodule.c | 11 +++ lang/m2/comp/desig.c | 11 ++- lang/m2/comp/enter.c | 16 ++- lang/m2/comp/expression.g | 17 ++-- lang/m2/comp/main.c | 4 +- lang/m2/comp/main.h | 1 + lang/m2/comp/node.c | 2 +- lang/m2/comp/program.g | 13 ++- lang/m2/comp/scope.C | 2 +- lang/m2/comp/tokenname.c | 1 - lang/m2/comp/type.H | 9 +- lang/m2/comp/type.c | 64 +++++++++++- lang/m2/comp/walk.c | 172 ++++++++++++++++++++++++++++----- 23 files changed, 671 insertions(+), 196 deletions(-) diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index c7738c64..08a27624 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -182,10 +182,6 @@ again: if (nch == '=') { return tk->tk_symb = LESSEQUAL; } - else - if (nch == '>') { - return tk->tk_symb = '#'; - } PushBack(nch); return tk->tk_symb = ch; diff --git a/lang/m2/comp/LLmessage.c b/lang/m2/comp/LLmessage.c index 0ea6e86a..ffb3d80b 100644 --- a/lang/m2/comp/LLmessage.c +++ b/lang/m2/comp/LLmessage.c @@ -4,6 +4,12 @@ static char *RcsId = "$Header$"; #endif +/* Defines the LLmessage routine. LLgen-generated parsers require the + existence of a routine of that name. + The routine must do syntax-error reporting and must be able to + insert tokens in the token stream. +*/ + #include #include #include @@ -12,15 +18,18 @@ static char *RcsId = "$Header$"; #include "LLlex.h" #include "Lpars.h" -extern char *symbol2str(); -extern struct idf *gen_anon_idf(); -int err_occurred = 0; +extern char *symbol2str(); +extern struct idf *gen_anon_idf(); +int err_occurred = 0; LLmessage(tk) int tk; { ++err_occurred; if (tk) { + /* if (tk != 0), it represents the token to be inserted. + otherwize, the current token is deleted + */ error("%s missing", symbol2str(tk)); insert_token(tk); } diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index 42805283..1e00f28a 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -11,7 +11,7 @@ LSRC = tokenfile.g program.g declar.g expression.g statement.g CC = cc GEN = LLgen GENOPTIONS = -PROFILE = +PROFILE = CFLAGS = $(PROFILE) $(INCLUDES) LFLAGS = $(PROFILE) LOBJ = tokenfile.o program.o declar.o expression.o statement.o @@ -91,7 +91,7 @@ tokenname.o: Lpars.h idf.h tokenname.h idf.o: idf.h input.o: f_info.h input.h inputtype.h type.o: LLlex.h const.h debug.h def.h idf.h maxset.h node.h target_sizes.h type.h -def.o: LLlex.h debug.h def.h idf.h main.h node.h scope.h type.h +def.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h type.h scope.o: LLlex.h debug.h def.h idf.h node.h scope.h type.h misc.o: LLlex.h f_info.h idf.h misc.h node.h enter.o: LLlex.h debug.h def.h idf.h main.h node.h scope.h type.h @@ -101,10 +101,11 @@ node.o: LLlex.h debug.h def.h node.h type.h cstoper.o: LLlex.h Lpars.h debug.h idf.h node.h standards.h target_sizes.h type.h chk_expr.o: LLlex.h Lpars.h const.h debug.h def.h idf.h node.h scope.h standards.h type.h options.o: idfsize.h main.h ndir.h type.h -walk.o: LLlex.h Lpars.h debug.h def.h desig.h main.h node.h scope.h type.h +walk.o: LLlex.h Lpars.h debug.h def.h desig.h f_info.h idf.h main.h node.h scope.h type.h casestat.o: LLlex.h Lpars.h debug.h density.h desig.h node.h type.h desig.o: LLlex.h debug.h def.h desig.h node.h scope.h type.h code.o: LLlex.h Lpars.h debug.h def.h desig.h node.h scope.h type.h +tmpvar.o: debug.h def.h scope.h type.h tokenfile.o: Lpars.h program.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h type.h declar.o: LLlex.h Lpars.h debug.h def.h idf.h main.h misc.h node.h scope.h type.h diff --git a/lang/m2/comp/casestat.C b/lang/m2/comp/casestat.C index 9ba52fb2..7fbfeffe 100644 --- a/lang/m2/comp/casestat.C +++ b/lang/m2/comp/casestat.C @@ -63,15 +63,12 @@ CaseCode(nd, exitlabel) register arith val; label tablabel; - assert(nd->nd_class == Stat && nd->nd_symb == CASE); + assert(pnode->nd_class == Stat && pnode->nd_symb == CASE); - WalkExpr(nd->nd_left, NO_LABEL, NO_LABEL); - sh->sh_type = nd->nd_left->nd_type; + clear((char *) sh, sizeof(*sh)); + WalkExpr(pnode->nd_left, NO_LABEL, NO_LABEL); + sh->sh_type = pnode->nd_left->nd_type; sh->sh_break = text_label(); - sh->sh_default = 0; - sh->sh_nrofentries = 0; - sh->sh_lowerbd = sh->sh_upperbd = (arith)0; /* immaterial ??? */ - sh->sh_entries = (struct case_entry *) 0; /* case-entry list */ /* Now, create case label list */ @@ -189,6 +186,7 @@ AddCases(sh, node, lbl) if (node->nd_symb == UPTO) { assert(node->nd_left->nd_class == Value); assert(node->nd_right->nd_class == Value); + v2 = node->nd_right->nd_INT; node->nd_type = node->nd_left->nd_type; for (v1 = node->nd_left->nd_INT; v1 <= v2; v1++) { @@ -233,9 +231,12 @@ AddOneCase(sh, node, lbl) /* second etc. case entry */ /* find the proper place to put ce into the list */ - if (ce->ce_value < sh->sh_lowerbd) sh->sh_lowerbd = ce->ce_value; - else - if (ce->ce_value > sh->sh_upperbd) sh->sh_upperbd = ce->ce_value; + if (ce->ce_value < sh->sh_lowerbd) { + sh->sh_lowerbd = ce->ce_value; + } + else if (ce->ce_value > sh->sh_upperbd) { + sh->sh_upperbd = ce->ce_value; + } while (c1 && c1->ce_value < ce->ce_value) { c2 = c1; c1 = c1->next; diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index daf2befb..36db56bf 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -38,7 +38,7 @@ chk_expr(expp) switch(expp->nd_class) { case Oper: if (expp->nd_symb == '[') { - return chk_designator(expp, DESIGNATOR|VARIABLE); + return chk_designator(expp, DESIGNATOR|VARIABLE, D_NOREG|D_USED); } return chk_expr(expp->nd_left) && @@ -47,7 +47,7 @@ chk_expr(expp) case Uoper: if (expp->nd_symb == '^') { - return chk_designator(expp, DESIGNATOR|VARIABLE); + return chk_designator(expp, DESIGNATOR|VARIABLE, D_USED); } return chk_expr(expp->nd_right) && @@ -69,13 +69,13 @@ chk_expr(expp) return chk_set(expp); case Name: - return chk_designator(expp, VALUE); + return chk_designator(expp, VALUE, D_USED); case Call: return chk_call(expp); case Link: - return chk_designator(expp, DESIGNATOR|VALUE); + return chk_designator(expp, DESIGNATOR|VALUE, D_USED|D_NOREG); default: assert(0); @@ -94,6 +94,7 @@ chk_set(expp) struct def *df; register struct node *nd; arith *set; + unsigned size; assert(expp->nd_symb == SET); @@ -102,7 +103,7 @@ chk_set(expp) if (nd = expp->nd_left) { /* A type was given. Check it out */ - if (! chk_designator(nd, 0)) return 0; + if (! chk_designator(nd, 0, D_USED)) return 0; assert(nd->nd_class == Def); df = nd->nd_def; @@ -117,16 +118,26 @@ chk_set(expp) expp->nd_left = 0; } else tp = bitset_type; + expp->nd_type = tp; + + nd = expp->nd_right; /* Now check the elements given, and try to compute a constant set. - First allocate room for the set + First allocate room for the set, but only if it is'nt empty. */ - set = (arith *) - Malloc((unsigned) (tp->tp_size * sizeof(arith) / word_size)); + if (! nd) { + /* The resulting set IS empty, so we just return + */ + expp->nd_class = Set; + expp->nd_set = 0; + return 1; + } + size = tp->tp_size * (sizeof(arith) / word_size); + set = (arith *) Malloc(size); + clear((char *) set, size); /* Now check the elements, one by one */ - nd = expp->nd_right; while (nd) { assert(nd->nd_class == Link && nd->nd_symb == ','); @@ -134,8 +145,6 @@ chk_set(expp) nd = nd->nd_right; } - expp->nd_type = tp; - if (set) { /* Yes, it was a constant set, and we managed to compute it! Notice that at the moment there is no such thing as @@ -255,7 +264,7 @@ getarg(argp, bases, designator) } argp = argp->nd_right; if ((!designator && !chk_expr(argp->nd_left)) || - (designator && !chk_designator(argp->nd_left, DESIGNATOR))) { + (designator && !chk_designator(argp->nd_left, DESIGNATOR, D_REFERRED))) { return 0; } tp = argp->nd_left->nd_type; @@ -276,7 +285,7 @@ getname(argp, kinds) return 0; } argp = argp->nd_right; - if (! chk_designator(argp->nd_left, 0)) return 0; + if (! chk_designator(argp->nd_left, 0, D_REFERRED)) return 0; assert(argp->nd_left->nd_class == Def); @@ -303,10 +312,9 @@ chk_call(expp) */ expp->nd_type = error_type; left = expp->nd_left; - if (! chk_designator(left, 0)) return 0; + if (! chk_designator(left, 0, D_USED)) return 0; - if (left->nd_class == Def && - (left->nd_def->df_kind & (D_HTYPE|D_TYPE|D_HIDDEN))) { + if (left->nd_class == Def && is_type(left->nd_def)) { /* It was a type cast. This is of course not portable. */ arg = expp->nd_right; @@ -359,10 +367,21 @@ chk_proccall(expp) { /* Check a procedure call */ - register struct node *left = expp->nd_left; + register struct node *left; register struct node *arg; register struct paramlist *param; + left = 0; + arg = expp->nd_right; + /* First, reverse the order in the argument list */ + while (arg) { + expp->nd_right = arg; + arg = arg->nd_right; + expp->nd_right->nd_right = left; + left = expp->nd_right; + } + + left = expp->nd_left; arg = expp; arg->nd_type = left->nd_type->next; param = left->nd_type->prc_params; @@ -376,6 +395,9 @@ chk_proccall(expp) node_error(arg->nd_left, "type incompatibility in parameter"); return 0; } + if (param->par_var && arg->nd_left->nd_class == Def) { + arg->nd_left->nd_def->df_flags |= D_NOREG; + } param = param->next; } @@ -422,7 +444,7 @@ FlagCheck(expp, df, flag) } int -chk_designator(expp, flag) +chk_designator(expp, flag, dflags) register struct node *expp; { /* Find the name indicated by "expp", starting from the current @@ -435,6 +457,8 @@ chk_designator(expp, flag) and '^' are allowed for this designator. Also contained may be the flag HASSELECTORS, indicating that the result must have selectors. + "dflags" contains some flags that must be set at the definition + found. */ register struct def *df; register struct type *tp; @@ -454,7 +478,8 @@ chk_designator(expp, flag) assert(expp->nd_right->nd_class == Name); if (! chk_designator(expp->nd_left, - (flag|HASSELECTORS))) return 0; + flag|HASSELECTORS, + dflags|D_NOREG)) return 0; tp = expp->nd_left->nd_type; @@ -512,6 +537,8 @@ df->df_idf->id_text); } } + df->df_flags |= dflags; + return 1; } @@ -526,7 +553,7 @@ df->df_idf->id_text); assert(expp->nd_symb == '['); if ( - !chk_designator(expp->nd_left, DESIGNATOR|VARIABLE) + !chk_designator(expp->nd_left, DESIGNATOR|VARIABLE, dflags|D_NOREG) || !chk_expr(expp->nd_right) || @@ -558,7 +585,7 @@ df->df_idf->id_text); if (expp->nd_class == Uoper) { assert(expp->nd_symb == '^'); - if (! chk_designator(expp->nd_right, DESIGNATOR|VARIABLE)) { + if (! chk_designator(expp->nd_right, DESIGNATOR|VARIABLE, dflags)) { return 0; } @@ -703,7 +730,6 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R case '=': case '#': - case UNEQUAL: case GREATEREQUAL: case LESSEQUAL: case '<': @@ -732,7 +758,6 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R case T_POINTER: if (chk_address(tpl, tpr) || expp->nd_symb == '=' || - expp->nd_symb == UNEQUAL || expp->nd_symb == '#') return 1; break; @@ -790,6 +815,7 @@ chk_uoper(expp) case '+': if (tpr->tp_fund & T_NUMERIC) { expp->nd_token = right->nd_token; + expp->nd_class = right->nd_class; FreeNode(right); expp->nd_right = 0; return 1; @@ -809,10 +835,14 @@ chk_uoper(expp) else if (tpr->tp_fund == T_REAL) { if (right->nd_class == Value) { expp->nd_token = right->nd_token; + expp->nd_class = Value; if (*(expp->nd_REL) == '-') { expp->nd_REL++; } - else expp->nd_REL--; + else { + expp->nd_REL--; + *(expp->nd_REL) = '-'; + } FreeNode(right); expp->nd_right = 0; } @@ -853,7 +883,7 @@ getvariable(arg) left = arg->nd_left; - if (! chk_designator(left, DESIGNATOR)) return 0; + if (! chk_designator(left, DESIGNATOR, D_REFERRED)) return 0; if (left->nd_class == Oper || left->nd_class == Uoper) { return arg; } @@ -941,7 +971,7 @@ left->nd_def->df_idf->id_text, left->nd_def->df_value.df_stdname)); case S_TSIZE: /* ??? */ case S_SIZE: expp->nd_type = intorcard_type; - arg = getname(arg, D_FIELD|D_VARIABLE|D_TYPE|D_HIDDEN|D_HTYPE); + arg = getname(arg, D_FIELD|D_VARIABLE|D_ISTYPE); if (!arg) return 0; cstcall(expp, S_SIZE); break; @@ -955,7 +985,7 @@ left->nd_def->df_idf->id_text, left->nd_def->df_value.df_stdname)); { struct type *tp; - if (!(arg = getname(arg, D_HIDDEN|D_HTYPE|D_TYPE))) return 0; + if (!(arg = getname(arg, D_ISTYPE))) return 0; tp = arg->nd_left->nd_def->df_type; if (tp->tp_fund == T_SUBRANGE) tp = tp->next; if (!(tp->tp_fund & T_DISCRETE)) { diff --git a/lang/m2/comp/code.c b/lang/m2/comp/code.c index cd2101fa..54e9bf1b 100644 --- a/lang/m2/comp/code.c +++ b/lang/m2/comp/code.c @@ -52,14 +52,14 @@ CodeString(nd) struct node *nd; { label lab; - + if (nd->nd_type == charc_type) { C_loc(nd->nd_INT); return; } C_df_dlb(lab = data_label()); C_rom_scon(nd->nd_STR, nd->nd_SLE); - C_lae_dlb(lab); + C_lae_dlb(lab, (arith) 0); } CodeReal(nd) @@ -69,7 +69,7 @@ CodeReal(nd) C_df_dlb(lab = data_label()); C_rom_fcon(nd->nd_REL, nd->nd_type->tp_size); - C_lae_dlb(lab); + C_lae_dlb(lab, (arith) 0); C_loi(nd->nd_type->tp_size); } @@ -139,12 +139,16 @@ CodeExpr(nd, ds, true_label, false_label) int i; st = nd->nd_set; - for (i = nd->nd_type->tp_size / word_size, st = nd->nd_set + i; + ds->dsg_kind = DSG_LOADED; + if (!st) { + C_zer(nd->nd_type->tp_size); + break; + } + for (i = nd->nd_type->tp_size / word_size, st += i; i > 0; i--) { C_loc(*--st); } - ds->dsg_kind = DSG_LOADED; } break; @@ -166,9 +170,97 @@ CodeExpr(nd, ds, true_label, false_label) } CodeCoercion(t1, t2) - struct type *t1, *t2; + register struct type *t1, *t2; { - /* ??? */ + int fund1, fund2; + + if (t1 == t2) return; + if (t1->tp_fund == T_SUBRANGE) t1 = t1->next; + if (t2->tp_fund == T_SUBRANGE) t2 = t2->next; + if ((fund1 = t1->tp_fund) == T_WORD) fund1 = T_INTEGER; + if ((fund2 = t2->tp_fund) == T_WORD) fund2 = T_INTEGER; + switch(fund1) { + case T_INTEGER: + switch(fund2) { + case T_INTEGER: + if (t2->tp_size != t1->tp_size) { + C_loc(t1->tp_size); + C_loc(t2->tp_size); + C_cii(); + } + break; + case T_ENUMERATION: + case T_CHAR: + case T_CARDINAL: + if (t1->tp_size != word_size) { + C_loc(t1->tp_size); + C_loc(word_size); + C_ciu(); + } + break; + case T_REAL: + C_loc(t1->tp_size); + C_loc(t2->tp_size); + C_cif(); + break; + default: + crash("Funny integer conversion"); + } + break; + + case T_CHAR: + case T_ENUMERATION: + case T_CARDINAL: + switch(fund2) { + case T_ENUMERATION: + case T_CHAR: + case T_CARDINAL: + case T_POINTER: + if (t2->tp_size > word_size) { + C_loc(word_size); + C_loc(t2->tp_size); + C_cuu(); + } + break; + case T_INTEGER: + C_loc(t1->tp_size); + C_loc(t2->tp_size); + C_cui(); + break; + case T_REAL: + C_loc(t1->tp_size); + C_loc(t2->tp_size); + C_cuf(); + break; + default: + crash("Funny cardinal conversion"); + } + break; + + case T_REAL: + switch(fund2) { + case T_REAL: + if (t2->tp_size != t1->tp_size) { + C_loc(t1->tp_size); + C_loc(t2->tp_size); + C_cff(); + } + break; + case T_INTEGER: + C_loc(t1->tp_size); + C_loc(t2->tp_size); + C_cfi(); + break; + case T_CARDINAL: + C_loc(t1->tp_size); + C_loc(t2->tp_size); + C_cfu(); + break; + default: + crash("Funny REAL conversion"); + } + break; + } } CodeCall(nd) @@ -190,13 +282,12 @@ CodeCall(nd) } tp = left->nd_type; - if (left->nd_class == Def && - (left->nd_def->df_kind & (D_TYPE|D_HTYPE|D_HIDDEN))) { + if (left->nd_class == Def && is_type(left->nd_def)) { /* it was just a cast. Simply ignore it */ Des = InitDesig; CodeExpr(nd->nd_right->nd_left, &Des, NO_LABEL, NO_LABEL); - CodeValue(&Des); + CodeValue(&Des, tp->tp_size); *nd = *(nd->nd_right->nd_left); nd->nd_type = left->nd_def->df_type; return; @@ -216,6 +307,7 @@ CodeCall(nd) else { CodeExpr(arg->nd_left, &Des, NO_LABEL, NO_LABEL); CodeValue(&Des, arg->nd_left->nd_type->tp_size); + CheckAssign(arg->nd_left->nd_type, param->par_type); pushed += align(arg->nd_left->nd_type->tp_size, word_align); } /* ??? Conformant arrays */ @@ -249,16 +341,55 @@ CodeStd(nd) /* ??? */ } -CodeAssign(nd, dst, dss) +CodeAssign(nd, dss, dst) struct node *nd; struct desig *dst, *dss; { /* Generate code for an assignment. Testing of type compatibility and the like is already done. */ - - CodeCoercion(nd->nd_right->nd_type, nd->nd_left->nd_type); - /* ??? */ + + if (dss->dsg_kind == DSG_LOADED) { + CodeStore(dst, nd->nd_left->nd_type->tp_size); + } + else { + CodeAddress(dst); + C_blm(nd->nd_left->nd_type->tp_size); + } +} + +CheckAssign(tpl, tpr) + register struct type *tpl, *tpr; +{ + /* Generate a range check if neccessary + */ + + arith llo, lhi, rlo, rhi; + label l = 0; + extern label getrck(); + + if (bounded(tpl)) { + /* in this case we might need a range check */ + if (!bounded(tpr)) { + /* yes, we need one */ + l = getrck(tpl); + } + else { + /* both types are restricted. check the bounds + to see wether we need a range check + */ + getbounds(tpl, &llo, &lhi); + getbounds(tpr, &rlo, &rhi); + if (llo > rlo || lhi < rhi) { + l = getrck(tpl); + } + } + + if (l) { + C_lae_dlb(l, (arith) 0); + C_rck(word_size); + } + } } Operands(leftop, rightop) @@ -415,29 +546,44 @@ CodeOper(expr, true_label, false_label) case '>': case GREATEREQUAL: case '=': - case UNEQUAL: case '#': Operands(leftop, rightop); CodeCoercion(rightop->nd_type, leftop->nd_type); + tp = leftop->nd_type; /* Not the result type! */ + if (tp->tp_fund == T_SUBRANGE) tp = tp->next; switch (tp->tp_fund) { case T_INTEGER: - C_cmi(leftop->nd_type->tp_size); + C_cmi(tp->tp_size); break; case T_POINTER: C_cmp(); break; case T_CARDINAL: - C_cmu(leftop->nd_type->tp_size); + C_cmu(tp->tp_size); break; case T_ENUMERATION: case T_CHAR: C_cmu(word_size); break; case T_REAL: - C_cmf(leftop->nd_type->tp_size); + C_cmf(tp->tp_size); break; case T_SET: - C_cms(leftop->nd_type->tp_size); + if (oper == GREATEREQUAL) { + /* A >= B is the same as A equals A + B + */ + C_dup(2*tp->tp_size); + C_asp(tp->tp_size); + C_zer(tp->tp_size); + } + else if (oper == LESSEQUAL) { + /* A <= B is the same as A - B = {} + */ + C_com(tp->tp_size); + C_and(tp->tp_size); + C_ior(tp->tp_size); + } + C_cms(tp->tp_size); break; default: crash("bad type COMPARE"); @@ -451,9 +597,13 @@ CodeOper(expr, true_label, false_label) } break; case IN: - Operands(leftop, rightop); - CodeCoercion(rightop->nd_type, word_type); - C_inn(leftop->nd_type->tp_size); + /* In this case, evaluate right hand side first! The + INN instruction expects the bit number on top of the + stack + */ + Operands(rightop, leftop); + CodeCoercion(leftop->nd_type, word_type); + C_inn(rightop->nd_type->tp_size); break; case AND: case '&': @@ -544,7 +694,6 @@ compare(relop, lbl) case '=': C_zeq(lbl); break; - case UNEQUAL: case '#': C_zne(lbl); break; @@ -573,7 +722,6 @@ truthvalue(relop) case '=': C_teq(); break; - case UNEQUAL: case '#': C_tne(); break; @@ -643,7 +791,7 @@ CodeEl(nd, tp) Des = InitDesig; CodeExpr(nd, &Des, NO_LABEL, NO_LABEL); - CodeValue(nd, word_size); + CodeValue(&Des, word_size); C_set(tp->tp_size); } } diff --git a/lang/m2/comp/cstoper.c b/lang/m2/comp/cstoper.c index b298221a..20d91a50 100644 --- a/lang/m2/comp/cstoper.c +++ b/lang/m2/comp/cstoper.c @@ -45,7 +45,7 @@ cstunary(expp) o1 = !o1; break; default: - assert(0); + crash("(cstunary)"); } expp->nd_class = Value; expp->nd_token = expp->nd_right->nd_token; @@ -159,7 +159,7 @@ cstbin(expp) ); } else - o1 = o1 < o2; + o1 = (o1 < o2); break; case '>': @@ -170,7 +170,7 @@ cstbin(expp) ); } else - o1 = o1 > o2; + o1 = (o1 > o2); break; case LESSEQUAL: if (uns) { @@ -180,7 +180,7 @@ cstbin(expp) ); } else - o1 = o1 <= o2; + o1 = (o1 <= o2); break; case GREATEREQUAL: if (uns) { @@ -190,27 +190,27 @@ cstbin(expp) ); } else - o1 = o1 >= o2; + o1 = (o1 >= o2); break; case '=': - o1 = o1 == o2; + o1 = (o1 == o2); break; case '#': - case UNEQUAL: - o1 = o1 != o2; + o1 = (o1 != o2); break; case AND: case '&': - o1 = o1 && o2; + o1 = (o1 && o2); break; case OR: - o1 = o1 || o2; + o1 = (o1 || o2); break; default: - assert(0); + crash("(cstbin)"); } expp->nd_class = Value; expp->nd_token = expp->nd_right->nd_token; + if (expp->nd_type == bool_type) expp->nd_symb = INTEGER; expp->nd_INT = o1; CutSize(expp); FreeNode(expp->nd_left); @@ -222,6 +222,7 @@ cstset(expp) register struct node *expp; { register arith *set1 = 0, *set2; + arith *resultset = 0; register int setsize, j; assert(expp->nd_right->nd_class == Set); @@ -233,32 +234,59 @@ cstset(expp) arith i; assert(expp->nd_left->nd_class == Value); + i = expp->nd_left->nd_INT; - expp->nd_INT = (i >= 0 && + expp->nd_INT = (i >= 0 && set2 != 0 && i < setsize * wrd_bits && (set2[i / wrd_bits] & (1 << (i % wrd_bits)))); - free((char *) set2); + if (set2) free((char *) set2); } else { set1 = expp->nd_left->nd_set; + resultset = set1; + expp->nd_left->nd_set = 0; switch(expp->nd_symb) { case '+': - for (j = 0; j < setsize; j++) { + if (!set1) { + resultset = set2; + expp->nd_right->nd_set = 0; + break; + } + if (set2) for (j = 0; j < setsize; j++) { *set1++ |= *set2++; } break; case '-': + if (!set1 || !set2) { + /* The set from which something is substracted + is already empty, or the set that is + substracted is empty + */ + break; + } for (j = 0; j < setsize; j++) { *set1++ &= ~*set2++; } break; case '*': + if (!set1) break; + if (!set2) { + resultset = set2; + expp->nd_right->nd_set = 0; + break; + } + for (j = 0; j < setsize; j++) { *set1++ &= *set2++; } break; case '/': - for (j = 0; j < setsize; j++) { + if (!set1) { + resultset = set2; + expp->nd_right->nd_set = 0; + break; + } + if (set2) for (j = 0; j < setsize; j++) { *set1++ ^= *set2++; } break; @@ -266,42 +294,62 @@ cstset(expp) case LESSEQUAL: case '=': case '#': - case UNEQUAL: /* Clumsy, but who cares? Nobody writes these things! */ + expp->nd_left->nd_set = set1; for (j = 0; j < setsize; j++) { switch(expp->nd_symb) { case GREATEREQUAL: + if (!set2) {j = setsize; break; } + if (!set1) break; if ((*set1 | *set2++) != *set1) break; set1++; continue; case LESSEQUAL: + if (!set1) {j = setsize; break; } + if (!set2) break; if ((*set2 | *set1++) != *set2) break; set2++; continue; case '=': case '#': - case UNEQUAL: + if (!set1 && !set2) { + j = setsize; break; + } + if (!set1 || !set2) break; if (*set1++ != *set2++) break; continue; } - expp->nd_INT = expp->nd_symb != '='; + if (j < setsize) { + expp->nd_INT = expp->nd_symb == '#'; + } + else { + expp->nd_INT = expp->nd_symb != '#'; + } break; } - if (j == setsize) expp->nd_INT = expp->nd_symb == '='; expp->nd_class = Value; expp->nd_symb = INTEGER; - free((char *) expp->nd_left->nd_set); - free((char *) expp->nd_right->nd_set); + if (expp->nd_left->nd_set) { + free((char *) expp->nd_left->nd_set); + } + if (expp->nd_right->nd_set) { + free((char *) expp->nd_right->nd_set); + } FreeNode(expp->nd_left); FreeNode(expp->nd_right); expp->nd_left = expp->nd_right = 0; return; default: - assert(0); + crash("(cstset)"); + } + if (expp->nd_right->nd_set) { + free((char *) expp->nd_right->nd_set); + } + if (expp->nd_left->nd_set) { + free((char *) expp->nd_left->nd_set); } - free((char *) expp->nd_right->nd_set); expp->nd_class = Set; - expp->nd_set = expp->nd_left->nd_set; + expp->nd_set = resultset; } FreeNode(expp->nd_left); FreeNode(expp->nd_right); @@ -405,7 +453,7 @@ cstcall(expp, call) else CutSize(expp); break; default: - assert(0); + crash("(cstcall)"); } FreeNode(expr); FreeNode(expp->nd_left); diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 05acf894..82b35060 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -128,8 +128,7 @@ FormalParameters(int doparams; ]? ')' { *tp = 0; } - [ ':' qualident(D_TYPE|D_HTYPE|D_HIDDEN, &df, "type", - (struct node **) 0) + [ ':' qualident(D_ISTYPE, &df, "type", (struct node **) 0) { *tp = df->df_type; } ]? @@ -169,7 +168,7 @@ FormalType(struct type **tp;) } : [ ARRAY OF { ARRAYflag = 1; } ]? - qualident(D_TYPE|D_HTYPE|D_HIDDEN, &df, "type", (struct node **) 0) + qualident(D_ISTYPE, &df, "type", (struct node **) 0) { if (ARRAYflag) { *tp = construct_type(T_ARRAY, NULLTYPE); (*tp)->arr_elem = df->df_type; @@ -186,14 +185,19 @@ TypeDeclaration struct def *df; struct type *tp; }: - IDENT { df = define(dot.TOK_IDF, CurrentScope, D_TYPE); } + IDENT { df = lookup(dot.TOK_IDF, CurrentScope); + if (!df) df = define( dot.TOK_IDF, + CurrentScope, + D_TYPE); + } '=' type(&tp) - { if (df->df_type) free_type(df->df_type); + { if (df->df_type) free_type(df->df_type); /* ??? */ df->df_type = tp; - if (df->df_kind == D_HTYPE && + if (df->df_kind == D_HIDDEN && tp->tp_fund != T_POINTER) { error("opaque type \"%s\" is not a pointer type", df->df_idf->id_text); } + df->df_kind = D_TYPE; } ; @@ -215,7 +219,7 @@ SimpleType(struct type **ptp;) { struct def *df; } : - qualident(D_TYPE|D_HTYPE|D_HIDDEN, &df, "type", (struct node **) 0) + qualident(D_ISTYPE, &df, "type", (struct node **) 0) [ /* nothing */ { *ptp = df->df_type; } @@ -237,22 +241,16 @@ SimpleType(struct type **ptp;) enumeration(struct type **ptp;) { struct node *EnumList; + register struct type *tp; } : '(' IdentList(&EnumList) ')' { - *ptp = standard_type(T_ENUMERATION, 1, (arith) 1); - EnterIdList(EnumList, D_ENUM, 0, *ptp, + *ptp = tp = standard_type(T_ENUMERATION, 1, (arith) 1); + EnterIdList(EnumList, D_ENUM, 0, tp, CurrentScope, (arith *) 0); FreeNode(EnumList); - if ((*ptp)->enm_ncst > 256) { - if (word_size == 1) { - error("Too many enumeration literals"); - } - else { - /* ??? This is crummy */ - (*ptp)->tp_size = word_size; - (*ptp)->tp_align = word_align; - } + if (tp->enm_ncst > 256) { + error("Too many enumeration literals"); } } ; @@ -284,7 +282,8 @@ SubrangeType(struct type **ptp;) '[' ConstExpression(&nd1) UPTO ConstExpression(&nd2) ']' - { *ptp = subr_type(nd1, nd2); } + { *ptp = subr_type(nd1, nd2); + } ; ArrayType(struct type **ptp;) @@ -298,8 +297,8 @@ ArrayType(struct type **ptp;) } [ ',' SimpleType(&tp) - { tp2 = tp2->arr_elem = - construct_type(T_ARRAY, tp); + { tp2->arr_elem = construct_type(T_ARRAY, tp); + tp2 = tp2->arr_elem; } ]* OF type(&tp) { tp2->arr_elem = tp; @@ -365,8 +364,7 @@ FieldList(struct scope *scope; arith *cnt; int *palign;) } else id = nd->nd_IDF; } - ':' qualident(D_TYPE|D_HTYPE|D_HIDDEN, - &df, "type", (struct node **) 0) + ':' qualident(D_ISTYPE, &df, "type", (struct node **) 0) | /* Old fashioned! the first qualident now represents the type @@ -374,10 +372,10 @@ FieldList(struct scope *scope; arith *cnt; int *palign;) { warning("Old fashioned Modula-2 syntax!"); id = gen_anon_idf(); df = ill_df; - if (chk_designator(nd, 0) && + if (chk_designator(nd, 0, D_REFERRED) && (nd->nd_class != Def || !(nd->nd_def->df_kind & - (D_ERROR|D_TYPE|D_HTYPE|D_HIDDEN)))) { + (D_ERROR|D_ISTYPE)))) { node_error(nd, "type expected"); } else df = nd->nd_def; @@ -386,7 +384,7 @@ FieldList(struct scope *scope; arith *cnt; int *palign;) ] | /* Aha, third edition? */ - ':' qualident(D_TYPE|D_HTYPE|D_HIDDEN, &df, "type", (struct node **) 0) + ':' qualident(D_ISTYPE, &df, "type", (struct node **) 0) { id = gen_anon_idf(); } ] { tp = df->df_type; @@ -489,7 +487,7 @@ PointerType(struct type **ptp;) /* Either a Module or a Type, but in both cases defined in this scope, so this is the correct identification */ - qualident(D_TYPE|D_HTYPE|D_HIDDEN, &df, "type", (struct node **) 0) + qualident(D_ISTYPE, &df, "type", (struct node **) 0) { if (!df->df_type) { error("type \"%s\" not declared", @@ -555,7 +553,7 @@ FormalTypeList(struct paramlist **ppr; struct type **ptp;) { p->next = 0; } ]? ')' - [ ':' qualident(D_TYPE|D_HTYPE|D_HIDDEN, &df, "type", (struct node **) 0) + [ ':' qualident(D_TYPE, &df, "type", (struct node **) 0) { *ptp = df->df_type; } ]? ; diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H index 176452c3..df4517a9 100644 --- a/lang/m2/comp/def.H +++ b/lang/m2/comp/def.H @@ -81,19 +81,21 @@ struct def { /* list of definitions for a name */ #define D_IMPORT 0x0080 /* an imported definition */ #define D_PROCHEAD 0x0100 /* a procedure heading in a definition module */ #define D_HIDDEN 0x0200 /* a hidden type */ -#define D_HTYPE 0x0400 /* definition of a hidden type seen */ #define D_FORWARD 0x0800 /* not yet defined */ #define D_UNDEF_IMPORT 0x1000 /* imported from an undefined name */ #define D_FORWMODULE 0x2000 /* module must be declared later */ #define D_ERROR 0x4000 /* a compiler generated definition for an undefined variable */ +#define D_ISTYPE (D_HIDDEN|D_TYPE) +#define is_type(dfx) ((dfx)->df_kind & D_ISTYPE) char df_flags; -#define D_ADDRESS 0x01 /* set if address was taken */ +#define D_NOREG 0x01 /* set if it may not reside in a register */ #define D_USED 0x02 /* set if used */ #define D_DEFINED 0x04 /* set if it is assigned a value */ -#define D_VARPAR 0x08 /* set if it is a VAR parameter */ -#define D_VALPAR 0x10 /* set if it is a value parameter */ +#define D_REFERRED 0x08 /* set if it is referred to */ +#define D_VARPAR 0x10 /* set if it is a VAR parameter */ +#define D_VALPAR 0x20 /* set if it is a value parameter */ #define D_EXPORTED 0x40 /* set if exported */ #define D_QEXPORTED 0x80 /* set if qualified exported */ struct type *df_type; diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index 8006d58a..3f811aeb 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -18,6 +18,7 @@ static char *RcsId = "$Header$"; #include "scope.h" #include "LLlex.h" #include "node.h" +#include "Lpars.h" struct def *h_def; /* Pointer to free list of def structures */ @@ -80,7 +81,7 @@ define(id, scope, kind) switch(df->df_kind) { case D_HIDDEN: if (kind == D_TYPE && !DefinitionModule) { - df->df_kind = D_HTYPE; + df->df_kind = D_TYPE; return df; } break; @@ -94,6 +95,7 @@ define(id, scope, kind) FreeNode(df->for_node); df->mod_vis = df->for_vis; df->df_kind = kind; + DefInFront(df); return df; } break; @@ -241,9 +243,9 @@ df->df_idf->id_text); else if (df1 && df1->df_kind == D_HIDDEN) { if (df->df_kind == D_TYPE) { if (df->df_type->tp_fund != T_POINTER) { -error("Opaque type \"%s\" is not a pointer type", df->df_idf->id_text); +error("opaque type \"%s\" is not a pointer type", df->df_idf->id_text); } - df->df_kind = D_HTYPE; + df->df_kind = D_TYPE; df1->df_kind = D_IMPORT; df1->imp_def = df; continue; @@ -436,8 +438,10 @@ DeclProc(type) module. Create a def structure for it (if neccessary) */ register struct def *df; - extern char *sprint(), *Malloc(), *strcpy(); static int nmcount = 0; + extern char *Malloc(); + extern char *strcpy(); + extern char *sprint(); char buf[256]; assert(type & (D_PROCEDURE | D_PROCHEAD)); @@ -462,6 +466,7 @@ DeclProc(type) open_scope(OPENSCOPE); CurrentScope->sc_name = df->for_name; df->prc_vis = CurrVis; + DefInFront(df); } else { df = define(dot.TOK_IDF, CurrentScope, type); @@ -492,6 +497,46 @@ InitProc(nd, df) /* Keep it this way, or really create a procedure out of it??? */ } +AddModule(id) + struct idf *id; +{ + /* Add the name of a module to the Module list. This list is + maintained to create the initialization routine of the + program/implementation module currently defined. + */ + static struct node *nd_end; /* to remember end of list */ + register struct node *n; + extern struct node *Modules; + + n = MkNode(Name, NULLNODE, NULLNODE, &dot); + n->nd_IDF = id; + n->nd_symb = IDENT; + if (nd_end) nd_end->next = n; + nd_end = n; + if (!Modules) Modules = n; +} + +DefInFront(df) + register struct def *df; +{ + /* Put definition "df" in front of the list of definitions + in its scope. + This is neccessary because in some cases the order in this + list is important. + */ + register struct def *df1; + + if (df->df_scope->sc_def != df) { + df1 = df->df_scope->sc_def; + while (df1 && df1->df_nextinscope != df) { + df1 = df1->df_nextinscope; + } + if (df1) df1->df_nextinscope = df->df_nextinscope; + df->df_nextinscope = df->df_scope->sc_def; + df->df_scope->sc_def = df; + } +} + #ifdef DEBUG PrDef(df) register struct def *df; diff --git a/lang/m2/comp/defmodule.c b/lang/m2/comp/defmodule.c index cad40b37..fe6d63c1 100644 --- a/lang/m2/comp/defmodule.c +++ b/lang/m2/comp/defmodule.c @@ -52,7 +52,9 @@ GetDefinitionModule(id) We may have to read the definition module itself. */ struct def *df; + static int level; + level++; df = lookup(id, GlobalScope); if (!df) { /* Read definition module. Make an exception for SYSTEM. @@ -63,10 +65,19 @@ GetDefinitionModule(id) else { GetFile(id->id_text); DefModule(); + if (level == 1) { + /* The module is directly imported by the + currently defined module, so we have to + remember its name because we have to call + its initialization routine + */ + AddModule(id); + } } df = lookup(id, GlobalScope); } assert(df != 0 && df->df_kind == D_MODULE); + level--; return df; } diff --git a/lang/m2/comp/desig.c b/lang/m2/comp/desig.c index fd7949bb..c4bc9eb1 100644 --- a/lang/m2/comp/desig.c +++ b/lang/m2/comp/desig.c @@ -232,6 +232,7 @@ CodeVarDesig(df, ds) CodeConst(df->var_off, pointer_size); ds->dsg_kind = DSG_PLOADED; ds->dsg_offset = 0; + df->df_flags |= D_NOREG; return; } @@ -242,6 +243,7 @@ CodeVarDesig(df, ds) ds->dsg_name = df->var_name; ds->dsg_offset = 0; ds->dsg_kind = DSG_FIXED; + df->df_flags |= D_NOREG; return; } @@ -254,6 +256,7 @@ CodeVarDesig(df, ds) ds->dsg_name = &(sc->sc_name[1]); ds->dsg_offset = df->var_off; ds->dsg_kind = DSG_FIXED; + df->df_flags |= D_NOREG; return; } @@ -278,6 +281,7 @@ CodeVarDesig(df, ds) else C_lxl((arith) (proclevel - sc->sc_level)); ds->dsg_kind = DSG_PLOADED; ds->dsg_offset = df->var_off; + df->df_flags |= D_NOREG; return; } @@ -304,6 +308,7 @@ CodeDesig(nd, ds) case Def: { register struct def *df = nd->nd_def; + df->df_flags |= D_USED; switch(df->df_kind) { case D_FIELD: CodeFieldDesig(df, ds); @@ -335,14 +340,16 @@ CodeDesig(nd, ds) *ds = InitDesig; CodeExpr(nd->nd_right, ds, NO_LABEL, NO_LABEL); CodeValue(ds, nd->nd_right->nd_type->tp_size); - CodeCoercion(nd->nd_right->nd_type, int_type); + if (nd->nd_right->nd_type->tp_size > word_size) { + CodeCoercion(nd->nd_right->nd_type, int_type); + } if (IsConformantArray(nd->nd_left->nd_type)) { /* ??? */ } else { /* load address of descriptor */ - /* ??? */ + C_lae_dlb(nd->nd_left->nd_type->arr_descr, (arith) 0); } ds->dsg_kind = DSG_INDEXED; break; diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index 782ad9b1..b88dd68d 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -67,27 +67,23 @@ EnterIdList(idlist, kind, flags, type, scope, addr) int xalign = type->tp_align; if (xalign < word_align && kind != D_FIELD) { + /* variables are at least word aligned + */ xalign = word_align; } if (*addr >= 0) { - if (scope->sc_level) { + if (scope->sc_level && kind != D_FIELD) { /* alignment of parameters is on word boundaries. We cannot do any better, because we don't know the alignment of the stack pointer when starting to push parameters */ - off = *addr; - *addr = align(off, word_align); - } - else { - /* for global variables we can honour - the alignment requirements totally. - */ - off = align(*addr, xalign); - *addr = off + type->tp_size; + xalign = word_align; } + off = align(*addr, xalign); + *addr = off + type->tp_size; } else { off = -align(-*addr-type->tp_size, xalign); diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index 8f306e29..071b306a 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -25,6 +25,7 @@ number(struct node **p;) struct type *tp; } : [ + %default INTEGER { tp = numtype; } | REAL { tp = real_type; } @@ -46,7 +47,7 @@ qualident(int types; struct def **pdf; char *str; struct node **p;) { if (types) { df = ill_df; - if (chk_designator(nd, 0)) { + if (chk_designator(nd, 0, D_REFERRED)) { if (nd->nd_class != Def) { node_error(nd, "%s expected", str); } @@ -113,9 +114,7 @@ expression(struct node **pnd;) SimpleExpression(pnd) [ /* relation */ - [ '=' | '#' | UNEQUAL | '<' | LESSEQUAL | '>' | - GREATEREQUAL | IN - ] + [ '=' | '#' | '<' | LESSEQUAL | '>' | GREATEREQUAL | IN ] { *pnd = MkNode(Oper, *pnd, NULLNODE, &dot); } SimpleExpression(&((*pnd)->nd_right)) ]? @@ -123,7 +122,7 @@ expression(struct node **pnd;) /* Inline in expression relation: - '=' | '#' | UNEQUAL | '<' | LESSEQUAL | '>' | GREATEREQUAL | IN + '=' | '#' | '<' | LESSEQUAL | '>' | GREATEREQUAL | IN ; */ @@ -184,9 +183,7 @@ factor(struct node **p;) ]? | bare_set(&nd) - { nd->nd_left = *p; - *p = nd; - } + { nd->nd_left = *p; *p = nd; } ] | bare_set(p) @@ -200,9 +197,9 @@ factor(struct node **p;) tp = charc_type; i = *(dot.TOK_STR) & 0377; - free((char *) dot.tk_data.tk_str); free(dot.TOK_STR); - dot.TOK_INT = i; + free((char *) dot.tk_data.tk_str); + (*p)->nd_INT = i; } else tp = standard_type(T_STRING, 1, dot.TOK_SLE); (*p)->nd_type = tp; diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index d4e112d5..c9b6a323 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -23,13 +23,14 @@ static char *RcsId = "$Header$"; #include "tokenname.h" #include "node.h" +int state; /* either IMPLEMENTATION or PROGRAM */ char options[128]; int DefinitionModule; int SYSTEMModule = 0; char *ProgName; -extern int err_occurred; char *DEFPATH[NDIRS+1]; struct def *Defined; +extern int err_occurred; main(argc, argv) char *argv[]; @@ -93,6 +94,7 @@ Compile(src, dst) C_magic(); C_ms_emx(word_size, pointer_size); CompUnit(); + close_scope(SC_REVERSE); if (err_occurred) { C_close(); return 0; diff --git a/lang/m2/comp/main.h b/lang/m2/comp/main.h index 35a0f9ad..642f7f5e 100644 --- a/lang/m2/comp/main.h +++ b/lang/m2/comp/main.h @@ -17,3 +17,4 @@ extern struct def *Defined; compilation */ extern char *DEFPATH[]; /* search path for DEFINITION MODULE's */ +extern int state; /* either IMPLEMENTATION or PROGRAM */ diff --git a/lang/m2/comp/node.c b/lang/m2/comp/node.c index 352347c4..c2270aa0 100644 --- a/lang/m2/comp/node.c +++ b/lang/m2/comp/node.c @@ -31,7 +31,7 @@ MkNode(class, left, right, token) nd->nd_right = right; nd->nd_token = *token; nd->nd_class = class; - nd->nd_type = NULLTYPE; + nd->nd_type = error_type; DO_DEBUG(4,(debug("Create node:"), PrNode(nd))); return nd; } diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 3fb43e3a..e3395260 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -231,7 +231,7 @@ Semicolon: { warning("; expected"); } ; -ProgramModule(int state;) +ProgramModule { struct idf *id; struct def *GetDefinitionModule(); @@ -267,16 +267,15 @@ ProgramModule(int state;) '.' ; -Module -{ - int state = PROGRAM; -} : +Module: DefinitionModule | [ IMPLEMENTATION { state = IMPLEMENTATION; } - ]? - ProgramModule(state) + | + { state = PROGRAM; } + ] + ProgramModule ; CompilationUnit: diff --git a/lang/m2/comp/scope.C b/lang/m2/comp/scope.C index f9899872..a4c5bb3a 100644 --- a/lang/m2/comp/scope.C +++ b/lang/m2/comp/scope.C @@ -166,7 +166,7 @@ rem_forwards(fo) while (f = fo) { df = lookfor(&(f->fo_tok), CurrVis, 1); - if (!(df->df_kind & (D_TYPE|D_HTYPE|D_ERROR))) { + if (!(df->df_kind & (D_TYPE|D_ERROR))) { node_error(&(f->fo_tok), "identifier \"%s\" not a type", df->df_idf->id_text); } diff --git a/lang/m2/comp/tokenname.c b/lang/m2/comp/tokenname.c index bb248137..e6add612 100644 --- a/lang/m2/comp/tokenname.c +++ b/lang/m2/comp/tokenname.c @@ -24,7 +24,6 @@ struct tokenname tkspec[] = { /* the names of the special tokens */ }; struct tokenname tkcomp[] = { /* names of the composite tokens */ - {UNEQUAL, "<>"}, {LESSEQUAL, "<="}, {GREATEREQUAL, ">="}, {UPTO, ".."}, diff --git a/lang/m2/comp/type.H b/lang/m2/comp/type.H index b0cbd564..13533ef0 100644 --- a/lang/m2/comp/type.H +++ b/lang/m2/comp/type.H @@ -16,7 +16,7 @@ struct enume { label en_rck; /* Label of range check descriptor */ #define enm_enums tp_value.tp_enum.en_enums #define enm_ncst tp_value.tp_enum.en_ncst -#define enm_rck tp_value.tp_enum.enm_rck +#define enm_rck tp_value.tp_enum.en_rck }; struct subrange { @@ -68,9 +68,10 @@ struct type { #define T_ARRAY 0x2000 #define T_STRING 0x4000 #define T_INTORCARD (T_INTEGER|T_CARDINAL) -#define T_DISCRETE (T_ENUMERATION|T_INTORCARD|T_CHAR) #define T_NUMERIC (T_INTORCARD|T_REAL) #define T_INDEX (T_ENUMERATION|T_CHAR|T_SUBRANGE) +#define T_DISCRETE (T_INDEX|T_INTORCARD) +#define T_PRCRESULT (T_DISCRETE|T_REAL|T_POINTER|T_WORD) int tp_align; /* alignment requirement of this type */ arith tp_size; /* size of this type */ union { @@ -131,3 +132,7 @@ struct type #define NULLTYPE ((struct type *) 0) #define IsConformantArray(tpx) ((tpx)->tp_fund == T_ARRAY && (tpx)->next == 0) +#define bounded(tpx) ((tpx)->tp_fund & T_INDEX) +#define complex(tpx) ((tpx)->tp_fund & (T_RECORD|T_ARRAY)) +#define returntype(tpx) (((tpx)->tp_fund & T_PRCRESULT) ||\ + ((tpx)->tp_fund == T_SET && (tpx)->tp_size <= dword_size)) diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index cdea3b4e..1ac5eb5c 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -61,6 +61,8 @@ struct paramlist *h_paramlist; struct type *h_type; +extern label data_label(); + struct type * create_type(fund) register int fund; @@ -117,7 +119,7 @@ construct_type(fund, tp) break; default: - assert(0); + crash("funny type constructor"); } return dtp; @@ -325,6 +327,52 @@ subr_type(lb, ub) return res; } +label +getrck(tp) + register struct type *tp; +{ + /* generate a range check descriptor for type "tp" when + neccessary. Return its label + */ + + assert(bounded(tp)); + + if (tp->tp_fund == T_SUBRANGE) { + if (tp->sub_rck == (label) 0) { + tp->sub_rck = data_label(); + C_df_dlb(tp->sub_rck); + C_rom_cst(tp->sub_lb); + C_rom_cst(tp->sub_ub); + } + return tp->sub_rck; + } + if (tp->enm_rck == (label) 0) { + tp->enm_rck = data_label(); + C_df_dlb(tp->enm_rck); + C_rom_cst((arith) 0); + C_rom_cst((arith) (tp->enm_ncst - 1)); + } + return tp->enm_rck; +} + +getbounds(tp, plo, phi) + register struct type *tp; + arith *plo, *phi; +{ + /* Get the bounds of a bounded type + */ + + assert(bounded(tp)); + + if (tp->tp_fund == T_SUBRANGE) { + *plo = tp->sub_lb; + *phi = tp->sub_ub; + } + else { + *plo = 0; + *phi = tp->enm_ncst - 1; + } +} struct type * set_type(tp) struct type *tp; @@ -385,18 +433,30 @@ ArraySizes(tp) /* find out HIGH, LOW and size of ARRAY */ + tp->arr_descr = data_label(); + C_df_dlb(tp->arr_descr); + switch(index_type->tp_fund) { case T_SUBRANGE: tp->tp_size = elem_size * (index_type->sub_ub - index_type->sub_lb + 1); + C_rom_cst(index_type->sub_lb); + C_rom_cst(index_type->sub_ub - index_type->sub_lb); break; + case T_CHAR: case T_ENUMERATION: tp->tp_size = elem_size * index_type->enm_ncst; + C_rom_cst((arith) 0); + C_rom_cst((arith) (index_type->enm_ncst - 1)); break; + default: - assert(0); + crash("Funny index type"); } + + C_rom_cst(elem_size); + /* ??? overflow checking ??? */ } diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index 111ea180..b24bcacd 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -23,14 +23,17 @@ static char *RcsId = "$Header$"; #include "Lpars.h" #include "desig.h" #include "f_info.h" +#include "idf.h" extern arith align(); extern arith NewPtr(); +extern arith NewInt(); extern int proclevel; static label instructionlabel; static char return_expr_occurred; static struct type *func_type; struct withdesig *WithDesigs; +struct node *Modules; label text_label() @@ -88,7 +91,9 @@ WalkModule(module) /* WHY ??? because we generated an INA for it ??? */ C_df_dnam(&(sc->sc_name[1])); + size = align(size, word_align); C_bss_cst(size, (arith) 0, 0); + C_exp(sc->sc_name); } else if (CurrVis == Defined->mod_vis) { /* This module is the module currently being compiled. @@ -98,10 +103,14 @@ WalkModule(module) while (df) { if (df->df_kind == D_VARIABLE) { C_df_dnam(df->var_name); - C_bss_cst(df->df_type->tp_size, (arith) 0, 0); + C_bss_cst( + align(df->df_type->tp_size, word_align), + (arith) 0, 0); } df = df->df_nextinscope; } + if (state == PROGRAM) C_exp("main"); + else C_exp(sc->sc_name); } /* Now, walk through it's local definitions @@ -115,26 +124,55 @@ WalkModule(module) sc->sc_off = 0; instructionlabel = 2; func_type = 0; - C_pro_narg(sc->sc_name); + C_pro_narg(state == PROGRAM ? "main" : sc->sc_name); DoProfil(); + if (CurrVis == Defined->mod_vis) { + /* Body of implementation or program module. + Call initialization routines of imported modules. + Also prevent recursive calls of this one. + */ + label l1 = data_label(), l2 = text_label(); + struct node *nd; + + /* we don't actually prevent recursive calls, but do nothing + if called recursively + */ + C_df_dlb(l1); + C_bss_cst(word_size, (arith) 0, 1); + C_loe_dlb(l1, (arith) 0); + C_zeq(l2); + C_ret((arith) 0); + C_df_ilb(l2); + C_loc((arith) 1); + C_ste_dlb(l1, (arith) 0); + + nd = Modules; + while (nd) { + C_cal(nd->nd_IDF->id_text); + nd = nd->next; + } + } MkCalls(sc->sc_def); + proclevel++; WalkNode(module->mod_body, (label) 0); C_df_ilb((label) 1); - C_ret(0); + C_ret((arith) 0); C_end(-sc->sc_off); + proclevel--; TmpClose(); CurrVis = vis; } WalkProcedure(procedure) - struct def *procedure; + register struct def *procedure; { /* Walk through the definition of a procedure and all its local definitions */ struct scopelist *vis = CurrVis; register struct scope *sc; + register struct type *res_type; proclevel++; CurrVis = procedure->prc_vis; @@ -152,16 +190,19 @@ WalkProcedure(procedure) MkCalls(sc->sc_def); return_expr_occurred = 0; instructionlabel = 2; - func_type = procedure->df_type->next; + func_type = res_type = procedure->df_type->next; + if (! returntype(res_type)) { + node_error(procedure->prc_body, "illegal result type"); + } WalkNode(procedure->prc_body, (label) 0); C_df_ilb((label) 1); - if (func_type) { + if (res_type) { if (! return_expr_occurred) { node_error(procedure->prc_body,"function procedure does not return a value"); } - C_ret((int) align(func_type->tp_size, word_align)); + C_ret(align(res_type->tp_size, word_align)); } - else C_ret(0); + else C_ret((arith) 0); C_end(-sc->sc_off); TmpClose(); CurrVis = vis; @@ -195,6 +236,7 @@ MkCalls(df) if (df->df_kind == D_MODULE) { C_lxl((arith) 0); C_cal(df->mod_vis->sc_scope->sc_name); + C_asp(pointer_size); } df = df->df_nextinscope; } @@ -246,20 +288,8 @@ WalkStat(nd, lab) assert(nd->nd_class == Stat); switch(nd->nd_symb) { - case BECOMES: { - struct desig ds; - - WalkExpr(right, NO_LABEL, NO_LABEL); - ds = Desig; - WalkDesignator(left); /* May we do it in this order??? */ - - if (! TstAssCompat(left->nd_type, right->nd_type)) { - node_error(nd, "type incompatibility in assignment"); - break; - } - - CodeAssign(nd, &ds, pds); - } + case BECOMES: + DoAssign(nd, left, right, 0); break; case IF: @@ -327,8 +357,61 @@ WalkStat(nd, lab) } case FOR: - /* ??? */ - WalkNode(right, lab); + { + arith tmp = 0; + struct node *fnd; + label l1 = instructionlabel++; + label l2 = instructionlabel++; + arith incr = 1; + arith size; + + assert(left->nd_symb == TO); + assert(left->nd_left->nd_symb == BECOMES); + + DoAssign(left->nd_left, + left->nd_left->nd_left, + left->nd_left->nd_right, 1); + fnd = left->nd_right; + if (fnd->nd_symb == BY) { + incr = fnd->nd_left->nd_INT; + fnd = fnd->nd_right; + } + if (! chk_expr(fnd)) return; + size = fnd->nd_type->tp_size; + if (fnd->nd_class != Value) { + *pds = InitDesig; + CodeExpr(fnd, pds, NO_LABEL, NO_LABEL); + CodeValue(pds, size); + tmp = NewInt(); + C_stl(tmp); + } + if (!TstCompat(left->nd_left->nd_left->nd_type, + fnd->nd_type)) { +node_error(fnd, "type incompatibility in limit of FOR loop"); + break; + } + C_bra(l1); + C_df_ilb(l2); + WalkNode(right, lab); + *pds = InitDesig; + C_loc(incr); + CodeDesig(left->nd_left->nd_left, pds); + CodeValue(pds, size); + C_adi(int_size); + *pds = InitDesig; + CodeDesig(left->nd_left->nd_left, pds); + CodeStore(pds, size); + C_df_ilb(l1); + *pds = InitDesig; + CodeDesig(left->nd_left->nd_left, pds); + CodeValue(pds, size); + if (tmp) C_lol(tmp); else C_loc(fnd->nd_INT); + if (incr > 0) { + C_ble(l2); + } + else C_bge(l2); + if (tmp) FreeInt(tmp); + } break; case WITH: @@ -358,7 +441,7 @@ WalkStat(nd, lab) pds->dsg_kind = DSG_PFIXED; /* the record is indirectly available */ } - wds.w_desig = Desig; + wds.w_desig = *pds; link.sc_scope = wds.w_scope; link.next = CurrVis; CurrVis = &link; @@ -432,10 +515,47 @@ WalkDesignator(nd) DO_DEBUG(1, (DumpTree(nd), print("\n"))); - if (! chk_designator(nd, DESIGNATOR|VARIABLE)) return; + if (! chk_designator(nd, DESIGNATOR|VARIABLE, D_DEFINED)) return; Desig = InitDesig; CodeDesig(nd, &Desig); + +} + +DoAssign(nd, left, right, forloopass) + struct node *nd; + register struct node *left, *right; +{ + /* May we do it in this order (expression first) ??? */ + struct desig ds; + + WalkExpr(right, NO_LABEL, NO_LABEL); + if (! chk_designator(left, DESIGNATOR|VARIABLE, D_DEFINED)) return; + + if (forloopass) { + if (! TstCompat(left->nd_type, right->nd_type)) { + node_error(nd, "type incompatibility in FOR loop"); + return; + } + /* Test if the left hand side may be a for loop variable ??? */ + } + else if (! TstAssCompat(left->nd_type, right->nd_type)) { + node_error(nd, "type incompatibility in assignment"); + return; + } + + if (complex(right->nd_type)) { + CodeAddress(&Desig); + } + else { + CodeValue(&Desig, right->nd_type->tp_size); + CheckAssign(left->nd_type, right->nd_type); + } + ds = Desig; + Desig = InitDesig; + CodeDesig(left, &Desig); + + CodeAssign(nd, &ds, &Desig); } #ifdef DEBUG From 1fcd61aa360d7047cf1d84a528a8bb29fde5f221 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 30 May 1986 18:48:00 +0000 Subject: [PATCH 0199/1625] newer version --- lang/m2/comp/LLlex.c | 4 + lang/m2/comp/Makefile | 7 +- lang/m2/comp/chk_expr.c | 253 +++++++++++++++++++++----------------- lang/m2/comp/code.c | 227 +++++++++++++++++++++++++++++----- lang/m2/comp/declar.g | 63 ++++------ lang/m2/comp/def.c | 6 +- lang/m2/comp/desig.c | 3 +- lang/m2/comp/enter.c | 9 -- lang/m2/comp/expression.g | 2 +- lang/m2/comp/main.c | 19 +++ lang/m2/comp/make.allocd | 18 ++- lang/m2/comp/misc.H | 2 - lang/m2/comp/node.H | 3 + lang/m2/comp/node.c | 3 + lang/m2/comp/options.c | 6 +- lang/m2/comp/program.g | 7 +- lang/m2/comp/scope.C | 7 +- lang/m2/comp/scope.h | 1 + lang/m2/comp/statement.g | 68 ++++++---- lang/m2/comp/type.H | 5 +- lang/m2/comp/type.c | 49 +++++--- lang/m2/comp/typequiv.c | 43 +++++-- lang/m2/comp/walk.c | 101 +++++++-------- 23 files changed, 586 insertions(+), 320 deletions(-) diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index 08a27624..19ffd0c1 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -182,6 +182,10 @@ again: if (nch == '=') { return tk->tk_symb = LESSEQUAL; } + if (nch == '>') { + lexwarning("'<>' is old-fashioned; use '#'"); + return tk->tk_symb = '#'; + } PushBack(nch); return tk->tk_symb = ch; diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index 1e00f28a..abeb35a6 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -54,7 +54,6 @@ tokenfile.g: tokenname.c make.tokfile symbol2str.c: tokenname.c make.tokcase make.tokcase symbol2str.c -misc.h: misc.H make.allocd def.h: def.H make.allocd type.h: type.H make.allocd node.h: node.H make.allocd @@ -90,13 +89,13 @@ symbol2str.o: Lpars.h tokenname.o: Lpars.h idf.h tokenname.h idf.o: idf.h input.o: f_info.h input.h inputtype.h -type.o: LLlex.h const.h debug.h def.h idf.h maxset.h node.h target_sizes.h type.h +type.o: LLlex.h const.h debug.h def.h idf.h maxset.h node.h scope.h target_sizes.h type.h def.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h type.h scope.o: LLlex.h debug.h def.h idf.h node.h scope.h type.h misc.o: LLlex.h f_info.h idf.h misc.h node.h enter.o: LLlex.h debug.h def.h idf.h main.h node.h scope.h type.h defmodule.o: LLlex.h debug.h def.h f_info.h idf.h input.h inputtype.h main.h scope.h -typequiv.o: def.h type.h +typequiv.o: LLlex.h def.h node.h type.h node.o: LLlex.h debug.h def.h node.h type.h cstoper.o: LLlex.h Lpars.h debug.h idf.h node.h standards.h target_sizes.h type.h chk_expr.o: LLlex.h Lpars.h const.h debug.h def.h idf.h node.h scope.h standards.h type.h @@ -104,7 +103,7 @@ options.o: idfsize.h main.h ndir.h type.h walk.o: LLlex.h Lpars.h debug.h def.h desig.h f_info.h idf.h main.h node.h scope.h type.h casestat.o: LLlex.h Lpars.h debug.h density.h desig.h node.h type.h desig.o: LLlex.h debug.h def.h desig.h node.h scope.h type.h -code.o: LLlex.h Lpars.h debug.h def.h desig.h node.h scope.h type.h +code.o: LLlex.h Lpars.h debug.h def.h desig.h node.h scope.h standards.h type.h tmpvar.o: debug.h def.h scope.h type.h tokenfile.o: Lpars.h program.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h type.h diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index 36db56bf..4e69cad6 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -254,47 +254,53 @@ rem_set(set) struct node * getarg(argp, bases, designator) - struct node *argp; + struct node **argp; { struct type *tp; + register struct node *arg = *argp; - if (!argp->nd_right) { - node_error(argp, "too few arguments supplied"); + if (!arg->nd_right) { + node_error(arg, "too few arguments supplied"); return 0; } - argp = argp->nd_right; - if ((!designator && !chk_expr(argp->nd_left)) || - (designator && !chk_designator(argp->nd_left, DESIGNATOR, D_REFERRED))) { + arg = arg->nd_right; + if ((!designator && !chk_expr(arg->nd_left)) || + (designator && !chk_designator(arg->nd_left, DESIGNATOR, D_REFERRED))) { return 0; } - tp = argp->nd_left->nd_type; + tp = arg->nd_left->nd_type; if (tp->tp_fund == T_SUBRANGE) tp = tp->next; if (bases && !(tp->tp_fund & bases)) { - node_error(argp, "unexpected type"); + node_error(arg, "unexpected type"); return 0; } - return argp; + + *argp = arg; + return arg->nd_left; } struct node * getname(argp, kinds) - struct node *argp; + struct node **argp; { - if (!argp->nd_right) { - node_error(argp, "too few arguments supplied"); + register struct node *arg = *argp; + + if (!arg->nd_right) { + node_error(arg, "too few arguments supplied"); return 0; } - argp = argp->nd_right; - if (! chk_designator(argp->nd_left, 0, D_REFERRED)) return 0; + arg = arg->nd_right; + if (! chk_designator(arg->nd_left, 0, D_REFERRED)) return 0; - assert(argp->nd_left->nd_class == Def); + assert(arg->nd_left->nd_class == Def); - if (!(argp->nd_left->nd_def->df_kind & kinds)) { - node_error(argp, "unexpected type"); + if (!(arg->nd_left->nd_def->df_kind & kinds)) { + node_error(arg, "unexpected type"); return 0; } - return argp; + *argp = arg; + return arg->nd_left; } int @@ -314,44 +320,20 @@ chk_call(expp) left = expp->nd_left; if (! chk_designator(left, 0, D_USED)) return 0; - if (left->nd_class == Def && is_type(left->nd_def)) { + if (IsCast(left)) { /* It was a type cast. This is of course not portable. */ - arg = expp->nd_right; - if ((! arg) || arg->nd_right) { -node_error(expp, "only one parameter expected in type cast"); - return 0; - } - arg = arg->nd_left; - if (! chk_expr(arg)) return 0; - if (arg->nd_type->tp_size != left->nd_type->tp_size) { -node_error(expp, "unequal sizes in type cast"); - } - if (arg->nd_class == Value) { - struct type *tp = left->nd_type; - - FreeNode(expp->nd_left); - expp->nd_right->nd_left = 0; - FreeNode(expp->nd_right); - expp->nd_left = expp->nd_right = 0; - *expp = *arg; - expp->nd_type = tp; - } - else expp->nd_type = left->nd_type; - - return 1; + return chk_cast(expp, left); } - if ((left->nd_class == Def && left->nd_def->df_kind == D_PROCEDURE) || - left->nd_type->tp_fund == T_PROCEDURE) { + if (IsProcCall(left)) { /* A procedure call. it may also be a call to a standard procedure */ - arg = expp; if (left->nd_type == std_type) { /* A standard procedure */ - return chk_std(expp, left, arg); + return chk_std(expp, left); } /* Here, we have found a real procedure call. The left hand side may also represent a procedure variable. @@ -363,12 +345,12 @@ node_error(expp, "unequal sizes in type cast"); } chk_proccall(expp) - struct node *expp; + register struct node *expp; { /* Check a procedure call */ register struct node *left; - register struct node *arg; + struct node *arg; register struct paramlist *param; left = 0; @@ -383,20 +365,21 @@ chk_proccall(expp) left = expp->nd_left; arg = expp; - arg->nd_type = left->nd_type->next; + expp->nd_type = left->nd_type->next; param = left->nd_type->prc_params; while (param) { - if (!(arg = getarg(arg, 0, param->par_var))) return 0; + if (!(left = getarg(&arg, 0, IsVarParam(param)))) return 0; - if (! TstParCompat(param->par_type, - arg->nd_left->nd_type, - param->par_var)) { -node_error(arg->nd_left, "type incompatibility in parameter"); + if (! TstParCompat(TypeOfParam(param), + left->nd_type, + IsVarParam(param), + left)) { +node_error(left, "type incompatibility in parameter"); return 0; } - if (param->par_var && arg->nd_left->nd_class == Def) { - arg->nd_left->nd_def->df_flags |= D_NOREG; + if (IsVarParam(param) && left->nd_class == Def) { + left->nd_def->df_flags |= D_NOREG; } param = param->next; @@ -475,7 +458,6 @@ chk_designator(expp, flag, dflags) if (expp->nd_class == Link) { assert(expp->nd_symb == '.'); - assert(expp->nd_right->nd_class == Name); if (! chk_designator(expp->nd_left, flag|HASSELECTORS, @@ -485,19 +467,17 @@ chk_designator(expp, flag, dflags) assert(tp->tp_fund == T_RECORD); - df = lookup(expp->nd_right->nd_IDF, tp->rec_scope); + df = lookup(expp->nd_IDF, tp->rec_scope); if (!df) { - id_not_declared(expp->nd_right); + id_not_declared(expp); return 0; } else { - expp->nd_right->nd_class = Def; - expp->nd_right->nd_def = df; + expp->nd_def = df; expp->nd_type = df->df_type; if (!(df->df_flags & (D_EXPORTED|D_QEXPORTED))) { -node_error(expp->nd_right, -"identifier \"%s\" not exported from qualifying module", +node_error(expp, "identifier \"%s\" not exported from qualifying module", df->df_idf->id_text); return 0; } @@ -508,11 +488,10 @@ df->df_idf->id_text); expp->nd_class = Def; expp->nd_def = df; FreeNode(expp->nd_left); - FreeNode(expp->nd_right); - expp->nd_left = expp->nd_right = 0; + expp->nd_left = 0; } else { - return FlagCheck(expp->nd_right, df, flag); + return FlagCheck(expp, df, flag); } } @@ -869,10 +848,11 @@ chk_uoper(expp) } struct node * -getvariable(arg) - register struct node *arg; +getvariable(argp) + struct node **argp; { - struct def *df; + register struct node *arg = *argp; + register struct def *df; register struct node *left; arg = arg->nd_right; @@ -885,62 +865,65 @@ getvariable(arg) if (! chk_designator(left, DESIGNATOR, D_REFERRED)) return 0; if (left->nd_class == Oper || left->nd_class == Uoper) { - return arg; + *argp = arg; + return left; } df = 0; - if (left->nd_class == Link) df = left->nd_right->nd_def; - else if (left->nd_class == Def) df = left->nd_def; + if (left->nd_class == Link || left->nd_class == Def) { + df = left->nd_def; + } if (!df || !(df->df_kind & (D_VARIABLE|D_FIELD))) { node_error(arg, "variable expected"); return 0; } - return arg; + *argp = arg; + return left; } int -chk_std(expp, left, arg) - register struct node *expp, *left, *arg; +chk_std(expp, left) + register struct node *expp, *left; { /* Check a call of a standard procedure or function */ + struct node *arg = expp; + int std; assert(left->nd_class == Def); -DO_DEBUG(3, debug("standard name \"%s\", %d", -left->nd_def->df_idf->id_text, left->nd_def->df_value.df_stdname)); + std = left->nd_def->df_value.df_stdname; - switch(left->nd_def->df_value.df_stdname) { +DO_DEBUG(3,debug("standard name \"%s\", %d",left->nd_def->df_idf->id_text,std)); + + switch(std) { case S_ABS: - if (!(arg = getarg(arg, T_NUMERIC, 0))) return 0; - left = arg->nd_left; + if (!(left = getarg(&arg, T_NUMERIC, 0))) return 0; expp->nd_type = left->nd_type; if (left->nd_class == Value) cstcall(expp, S_ABS); break; case S_CAP: expp->nd_type = char_type; - if (!(arg = getarg(arg, T_CHAR, 0))) return 0; - left = arg->nd_left; + if (!(left = getarg(&arg, T_CHAR, 0))) return 0; if (left->nd_class == Value) cstcall(expp, S_CAP); break; case S_CHR: expp->nd_type = char_type; - if (!(arg = getarg(arg, T_INTORCARD, 0))) return 0; - left = arg->nd_left; + if (!(left = getarg(&arg, T_INTORCARD, 0))) return 0; if (left->nd_class == Value) cstcall(expp, S_CHR); break; case S_FLOAT: expp->nd_type = real_type; - if (!(arg = getarg(arg, T_INTORCARD, 0))) return 0; + if (!(left = getarg(&arg, T_INTORCARD, 0))) return 0; break; case S_HIGH: - if (!(arg = getarg(arg, T_ARRAY, 0))) return 0; - expp->nd_type = arg->nd_left->nd_type->next; + if (!(left = getarg(&arg, T_ARRAY, 0))) return 0; + expp->nd_type = left->nd_type->next; if (!expp->nd_type) { /* A dynamic array has no explicit index type */ @@ -951,68 +934,75 @@ left->nd_def->df_idf->id_text, left->nd_def->df_value.df_stdname)); case S_MAX: case S_MIN: - if (!(arg = getarg(arg, T_DISCRETE, 0))) return 0; - expp->nd_type = arg->nd_left->nd_type; - cstcall(expp,left->nd_def->df_value.df_stdname); + if (!(left = getarg(&arg, T_DISCRETE, 0))) return 0; + expp->nd_type = left->nd_type; + cstcall(expp,std); break; case S_ODD: - if (!(arg = getarg(arg, T_INTORCARD, 0))) return 0; + if (!(left = getarg(&arg, T_INTORCARD, 0))) return 0; expp->nd_type = bool_type; - if (arg->nd_left->nd_class == Value) cstcall(expp, S_ODD); + if (left->nd_class == Value) cstcall(expp, S_ODD); break; case S_ORD: - if (!(arg = getarg(arg, T_DISCRETE, 0))) return 0; + if (!(left = getarg(&arg, T_DISCRETE, 0))) return 0; + if (left->nd_type->tp_size > word_size) { + node_error(left, "illegal type in argument of ORD"); + return 0; + } expp->nd_type = card_type; - if (arg->nd_left->nd_class == Value) cstcall(expp, S_ORD); + if (left->nd_class == Value) cstcall(expp, S_ORD); break; case S_TSIZE: /* ??? */ case S_SIZE: expp->nd_type = intorcard_type; - arg = getname(arg, D_FIELD|D_VARIABLE|D_ISTYPE); - if (!arg) return 0; + if (! getname(&arg, D_FIELD|D_VARIABLE|D_ISTYPE)) return 0; cstcall(expp, S_SIZE); break; case S_TRUNC: expp->nd_type = card_type; - if (!(arg = getarg(arg, T_REAL, 0))) return 0; + if (!(left = getarg(&arg, T_REAL, 0))) return 0; break; case S_VAL: { struct type *tp; - if (!(arg = getname(arg, D_ISTYPE))) return 0; - tp = arg->nd_left->nd_def->df_type; + if (!(left = getname(&arg, D_ISTYPE))) return 0; + tp = left->nd_def->df_type; if (tp->tp_fund == T_SUBRANGE) tp = tp->next; if (!(tp->tp_fund & T_DISCRETE)) { node_error(arg, "unexpected type"); return 0; } - expp->nd_type = arg->nd_left->nd_def->df_type; + expp->nd_type = left->nd_def->df_type; expp->nd_right = arg->nd_right; arg->nd_right = 0; FreeNode(arg); - arg = getarg(expp, T_INTORCARD, 0); - if (!arg) return 0; - if (arg->nd_left->nd_class == Value) cstcall(expp, S_VAL); + arg = expp; + if (!(left = getarg(&arg, T_INTORCARD, 0))) return 0; + if (left->nd_class == Value) cstcall(expp, S_VAL); break; } case S_ADR: expp->nd_type = address_type; - if (!(arg = getarg(arg, 0, 1))) return 0; + if (!(left = getarg(&arg, 0, 1))) return 0; break; case S_DEC: case S_INC: expp->nd_type = 0; - if (!(arg = getvariable(arg))) return 0; + if (! (left = getvariable(&arg))) return 0; + if (! (left->nd_type->tp_fund & T_DISCRETE)) { +node_error(left, "illegal type in argument of INC or DEC"); + return 0; + } if (arg->nd_right) { - if (!(arg = getarg(arg, T_INTORCARD, 0))) return 0; + if (! getarg(&arg, T_INTORCARD, 0)) return 0; } break; @@ -1026,14 +1016,14 @@ left->nd_def->df_idf->id_text, left->nd_def->df_value.df_stdname)); struct type *tp; expp->nd_type = 0; - if (!(arg = getvariable(arg))) return 0; - tp = arg->nd_left->nd_type; + if (!(left = getvariable(&arg))) return 0; + tp = left->nd_type; if (tp->tp_fund != T_SET) { node_error(arg, "EXCL and INCL expect a SET parameter"); return 0; } - if (!(arg = getarg(arg, T_DISCRETE, 0))) return 0; - if (!TstAssCompat(tp->next, arg->nd_left->nd_type)) { + if (!(left = getarg(&arg, T_DISCRETE, 0))) return 0; + if (!TstAssCompat(tp->next, left->nd_type)) { /* What type of compatibility do we want here? apparently assignment compatibility! ??? ??? */ @@ -1044,7 +1034,7 @@ node_error(arg, "EXCL and INCL expect a SET parameter"); } default: - assert(0); + crash("(chk_std)"); } if (arg->nd_right) { @@ -1054,3 +1044,44 @@ node_error(arg, "EXCL and INCL expect a SET parameter"); return 1; } + +chk_cast(expp, left) + register struct node *expp, *left; +{ + /* Check a cast and perform it if the argument is constant. + If the sizes don't match, only complain if at least one of them + has a size larger than the word size. + If both sizes are equal to or smaller than the word size, there + is no problem as such values take a word on the EM stack + anyway. + */ + register struct node *arg = expp->nd_right; + + if ((! arg) || arg->nd_right) { +node_error(expp, "only one parameter expected in type cast"); + return 0; + } + + arg = arg->nd_left; + if (! chk_expr(arg)) return 0; + + if (arg->nd_type->tp_size != left->nd_type->tp_size && + (arg->nd_type->tp_size > word_size || + left->nd_type->tp_size > word_size)) { + node_error(expp, "unequal sizes in type cast"); + } + + if (arg->nd_class == Value) { + struct type *tp = left->nd_type; + + FreeNode(left); + expp->nd_right->nd_left = 0; + FreeNode(expp->nd_right); + expp->nd_left = expp->nd_right = 0; + *expp = *arg; + expp->nd_type = tp; + } + else expp->nd_type = left->nd_type; + + return 1; +} diff --git a/lang/m2/comp/code.c b/lang/m2/comp/code.c index 54e9bf1b..f59ef69d 100644 --- a/lang/m2/comp/code.c +++ b/lang/m2/comp/code.c @@ -20,6 +20,7 @@ static char *RcsId = "$Header$"; #include "LLlex.h" #include "node.h" #include "Lpars.h" +#include "standards.h" extern label data_label(); extern label text_label(); @@ -81,6 +82,11 @@ CodeExpr(nd, ds, true_label, false_label) switch(nd->nd_class) { case Def: + if (nd->nd_def->df_kind == D_PROCEDURE) { + C_lpi(nd->nd_def->prc_vis->sc_scope->sc_name); + ds->dsg_kind = DSG_LOADED; + break; + } CodeDesig(nd, ds); break; @@ -102,8 +108,7 @@ CodeExpr(nd, ds, true_label, false_label) CodeDesig(nd, ds); break; } - CodeExpr(nd->nd_right, ds, NO_LABEL, NO_LABEL); - CodeValue(ds, nd->nd_right->nd_type->tp_size); + CodePExpr(nd->nd_right); CodeUoper(nd); ds->dsg_kind = DSG_LOADED; break; @@ -181,6 +186,7 @@ CodeCoercion(t1, t2) if ((fund2 = t2->tp_fund) == T_WORD) fund2 = T_INTEGER; switch(fund1) { case T_INTEGER: + case T_INTORCARD: switch(fund2) { case T_INTEGER: if (t2->tp_size != t1->tp_size) { @@ -274,7 +280,6 @@ CodeCall(nd) register struct paramlist *param; struct type *tp; arith pushed = 0; - struct desig Des; if (left->nd_type == std_type) { CodeStd(nd); @@ -282,32 +287,27 @@ CodeCall(nd) } tp = left->nd_type; - if (left->nd_class == Def && is_type(left->nd_def)) { + if (IsCast(left)) { /* it was just a cast. Simply ignore it */ - Des = InitDesig; - CodeExpr(nd->nd_right->nd_left, &Des, NO_LABEL, NO_LABEL); - CodeValue(&Des, tp->tp_size); + CodePExpr(nd->nd_right->nd_left); *nd = *(nd->nd_right->nd_left); nd->nd_type = left->nd_def->df_type; return; } - assert(tp->tp_fund == T_PROCEDURE); + assert(IsProcCall(left)); for (param = left->nd_type->prc_params; param; param = param->next) { - Des = InitDesig; arg = arg->nd_right; assert(arg != 0); - if (param->par_var) { - CodeDesig(arg->nd_left, &Des); - CodeAddress(&Des); + if (IsVarParam(param)) { + CodeDAddress(arg->nd_left); pushed += pointer_size; } else { - CodeExpr(arg->nd_left, &Des, NO_LABEL, NO_LABEL); - CodeValue(&Des, arg->nd_left->nd_type->tp_size); - CheckAssign(arg->nd_left->nd_type, param->par_type); + CodePExpr(arg->nd_left); + CheckAssign(arg->nd_left->nd_type, TypeOfParam(param)); pushed += align(arg->nd_left->nd_type->tp_size, word_align); } /* ??? Conformant arrays */ @@ -324,9 +324,7 @@ CodeCall(nd) C_cal(left->nd_def->for_name); } else { - Des = InitDesig; - CodeDesig(left, &Des); - CodeAddress(&Des); + CodePExpr(left); C_cai(); } C_asp(pushed); @@ -338,7 +336,141 @@ CodeCall(nd) CodeStd(nd) struct node *nd; { - /* ??? */ + register struct node *arg = nd->nd_right; + register struct node *left = 0; + register struct type *tp = 0; + int std; + + if (arg) { + left = arg->nd_left; + tp = left->nd_type; + if (tp->tp_fund == T_SUBRANGE) tp = tp->next; + arg = arg->nd_right; + } + Desig = InitDesig; + + switch(std = nd->nd_left->nd_def->df_value.df_stdname) { + case S_ABS: + CodePExpr(left); + if (tp->tp_fund == T_INTEGER) { + if (tp->tp_size == int_size) { + C_cal("_absi"); + } + else C_cal("_absl"); + } + else if (tp->tp_fund == T_REAL) { + if (tp->tp_size == float_size) { + C_cal("_absf"); + } + else C_cal("_absd"); + } + C_lfr(tp->tp_size); + break; + + case S_CAP: + CodePExpr(left); + C_loc((arith) 0137); + C_and(word_size); + break; + + case S_CHR: + CodePExpr(left); + CheckAssign(char_type, tp); + break; + + case S_FLOAT: + CodePExpr(left); + CodeCoercion(tp, real_type); + break; + + case S_HIGH: + assert(IsConformantArray(tp)); + /* ??? */ + break; + + case S_ODD: + if (tp->tp_size == word_size) { + C_loc((arith) 1); + C_and(word_size); + } + else { + assert(tp->tp_size == dword_size); + C_ldc((arith) 1); + C_and(dword_size); + C_ior(word_size); + } + break; + + case S_ORD: + CodePExpr(left); + break; + + case S_TRUNC: + CodePExpr(left); + CodeCoercion(tp, card_type); + break; + + case S_VAL: + CodePExpr(left); + CheckAssign(nd->nd_type, tp); + break; + + case S_ADR: + CodeDAddress(left); + break; + + case S_DEC: + case S_INC: + CodePExpr(left); + if (arg) CodePExpr(arg->nd_left); + else C_loc((arith) 1); + if (tp->tp_size <= word_size) { + if (std == S_DEC) { + if (tp->tp_fund == T_INTEGER) C_sbi(word_size); + else C_sbu(word_size); + } + else { + if (tp->tp_fund == T_INTEGER) C_adi(word_size); + else C_adu(word_size); + } + CheckAssign(tp, int_type); + } + else { + CodeCoercion(int_type, tp); + if (std == S_DEC) { + if (tp->tp_fund==T_INTEGER) C_sbi(tp->tp_size); + else C_sbu(tp->tp_size); + } + else { + if (tp->tp_fund==T_INTEGER) C_adi(tp->tp_size); + else C_adu(tp->tp_size); + } + } + CodeDStore(left); + break; + + case S_HALT: + C_cal("_halt"); + break; + + case S_INCL: + case S_EXCL: + CodePExpr(left); + CodePExpr(arg->nd_left); + C_set(tp->tp_size); + if (std == S_INCL) { + C_ior(tp->tp_size); + } + else { + C_com(tp->tp_size); + C_and(tp->tp_size); + } + CodeDStore(left); + break; + + default: + crash("(CodeStd)"); + } } CodeAssign(nd, dss, dst) @@ -353,6 +485,7 @@ CodeAssign(nd, dss, dst) CodeStore(dst, nd->nd_left->nd_type->tp_size); } else { + CodeAddress(dss); CodeAddress(dst); C_blm(nd->nd_left->nd_type->tp_size); } @@ -395,12 +528,8 @@ CheckAssign(tpl, tpr) Operands(leftop, rightop) register struct node *leftop, *rightop; { - struct desig Des; - Des = InitDesig; - CodeExpr(leftop, &Des, NO_LABEL, NO_LABEL); - CodeValue(&Des, leftop->nd_type->tp_size); - Des = InitDesig; + CodePExpr(leftop); if (rightop->nd_type->tp_fund == T_POINTER && leftop->nd_type->tp_size != pointer_size) { @@ -408,8 +537,7 @@ Operands(leftop, rightop) leftop->nd_type = rightop->nd_type; } - CodeExpr(rightop, &Des, NO_LABEL, NO_LABEL); - CodeValue(&Des, rightop->nd_type->tp_size); + CodePExpr(rightop); } CodeOper(expr, true_label, false_label) @@ -787,11 +915,48 @@ CodeEl(nd, tp) C_asp(2 * word_size + pointer_size); } else { - struct desig Des; - - Des = InitDesig; - CodeExpr(nd, &Des, NO_LABEL, NO_LABEL); - CodeValue(&Des, word_size); + CodePExpr(nd); C_set(tp->tp_size); } } + +CodePExpr(nd) + struct node *nd; +{ + /* Generate code to push the value of the expression "nd" + on the stack. + */ + struct desig designator; + + designator = InitDesig; + CodeExpr(nd, &designator, NO_LABEL, NO_LABEL); + CodeValue(&designator, nd->nd_type->tp_size); +} + +CodeDAddress(nd) + struct node *nd; +{ + /* Generate code to push the address of the designator "nd" + on the stack. + */ + + struct desig designator; + + designator = InitDesig; + CodeDesig(nd, &designator); + CodeAddress(&designator); +} + +CodeDStore(nd) + register struct node *nd; +{ + /* Generate code to store the expression on the stack into the + designator "nd". + */ + + struct desig designator; + + designator = InitDesig; + CodeDesig(nd, &designator); + CodeStore(&designator, nd->nd_type->tp_size); +} diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 82b35060..b605456a 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -23,25 +23,23 @@ static char *RcsId = "$Header$"; int proclevel = 0; /* nesting level of procedures */ extern char *sprint(); -extern struct def *currentdef; } ProcedureDeclaration { struct def *df; - struct def *savecurr = currentdef; } : + { proclevel++; } ProcedureHeading(&df, D_PROCEDURE) { - currentdef = df; + CurrentScope->sc_definedby = df; + df->prc_vis = CurrVis; } ';' block(&(df->prc_body)) IDENT { match_id(dot.TOK_IDF, df->df_idf); - df->prc_vis = CurrVis; close_scope(SC_CHKFORW|SC_REVERSE); proclevel--; - currentdef = savecurr; } ; @@ -54,17 +52,16 @@ ProcedureHeading(struct def **pdf; int type;) } : PROCEDURE IDENT { - if (type == D_PROCEDURE) proclevel++; df = DeclProc(type); tp = construct_type(T_PROCEDURE, tp); - if (proclevel > 1) { + if (proclevel) { /* Room for static link */ tp->prc_nbpar = pointer_size; } else tp->prc_nbpar = 0; } - FormalParameters(type == D_PROCEDURE, ¶ms, &(tp->next), &(tp->prc_nbpar))? + FormalParameters(¶ms, &(tp->next), &(tp->prc_nbpar))? { tp->prc_params = params; if (df->df_type) { @@ -79,6 +76,8 @@ error("inconsistent procedure declaration for \"%s\"", df->df_idf->id_text); df->df_type = tp; *pdf = df; + if (type == D_PROCHEAD) close_scope(0); + DO_DEBUG(1, type == D_PROCEDURE && (print("proc %s:", df->df_idf->id_text), DumpType(tp), print("\n"))); @@ -110,20 +109,17 @@ declaration: ModuleDeclaration ';' ; -FormalParameters(int doparams; - struct paramlist **pr; +FormalParameters(struct paramlist **pr; struct type **tp; arith *parmaddr;) { struct def *df; - register struct paramlist *pr1; } : '(' [ - FPSection(doparams, pr, parmaddr) + FPSection(pr, parmaddr) [ - { for (pr1 = *pr; pr1->next; pr1 = pr1->next) ; } - ';' FPSection(doparams, &(pr1->next), parmaddr) + ';' FPSection(pr, parmaddr) ]* ]? ')' @@ -134,16 +130,9 @@ FormalParameters(int doparams; ]? ; -/* In the next nonterminal, "doparams" is a flag indicating whether - the identifiers representing the parameters must be added to the - symbol table. We must not do so when reading a Definition Module, - because in this case we only read the header. The Implementation - might contain different identifiers representing the same paramters. -*/ -FPSection(int doparams; struct paramlist **ppr; arith *addr;) +FPSection(struct paramlist **ppr; arith *parmaddr;) { struct node *FPList; - struct paramlist *ParamList(); struct type *tp; int VARp = 0; } : @@ -152,11 +141,7 @@ FPSection(int doparams; struct paramlist **ppr; arith *addr;) ]? IdentList(&FPList) ':' FormalType(&tp) { - if (doparams) { - EnterIdList(FPList, D_VARIABLE, VARp, - tp, CurrentScope, addr); - } - *ppr = ParamList(FPList, tp, VARp); + ParamList(ppr, FPList, tp, VARp, parmaddr); FreeNode(FPList); } ; @@ -530,27 +515,29 @@ FormalTypeList(struct paramlist **ppr; struct type **ptp;) } : '(' { *ppr = 0; } [ - [ VAR { VARp = 1; } - | { VARp = 0; } + [ VAR { VARp = D_VARPAR; } + | { VARp = D_VALPAR; } ] FormalType(&tp) { *ppr = p = new_paramlist(); - p->par_type = tp; - p->par_var = VARp; + p->next = 0; + p->par_def = df = new_def(); + df->df_type = tp; + df->df_flags = VARp; } [ ',' - [ VAR {VARp = 1; } - | {VARp = 0; } + [ VAR {VARp = D_VARPAR; } + | {VARp = D_VALPAR; } ] FormalType(&tp) - { p->next = new_paramlist(); - p = p->next; - p->par_type = tp; - p->par_var = VARp; + { p = new_paramlist(); + p->next = *ppr; *ppr = p; + p->par_def = df = new_def(); + df->df_type = tp; + df->df_flags = VARp; } ]* - { p->next = 0; } ]? ')' [ ':' qualident(D_TYPE, &df, "type", (struct node **) 0) diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index 3f811aeb..c3a98030 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -20,7 +20,10 @@ static char *RcsId = "$Header$"; #include "node.h" #include "Lpars.h" -struct def *h_def; /* Pointer to free list of def structures */ +struct def *h_def; /* pointer to free list of def structures */ +#ifdef DEBUG +int cnt_def; /* count number of allocated ones */ +#endif struct def *ill_df; @@ -455,6 +458,7 @@ DeclProc(type) df->for_name = Malloc((unsigned) (strlen(buf)+1)); strcpy(df->for_name, buf); C_exp(df->for_name); + open_scope(OPENSCOPE); } else { df = lookup(dot.TOK_IDF, CurrentScope); diff --git a/lang/m2/comp/desig.c b/lang/m2/comp/desig.c index c4bc9eb1..04f2fd8b 100644 --- a/lang/m2/comp/desig.c +++ b/lang/m2/comp/desig.c @@ -326,10 +326,9 @@ CodeDesig(nd, ds) case Link: assert(nd->nd_symb == '.'); - assert(nd->nd_right->nd_class == Def); CodeDesig(nd->nd_left, ds); - CodeFieldDesig(nd->nd_right->nd_def, ds); + CodeFieldDesig(nd->nd_def, ds); break; case Oper: diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index b88dd68d..b2bb3bf5 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -73,15 +73,6 @@ EnterIdList(idlist, kind, flags, type, scope, addr) } if (*addr >= 0) { - if (scope->sc_level && kind != D_FIELD) { - /* alignment of parameters is on - word boundaries. We cannot do any - better, because we don't know the - alignment of the stack pointer when - starting to push parameters - */ - xalign = word_align; - } off = align(*addr, xalign); *addr = off + type->tp_size; } diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index 071b306a..f0c144e6 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -72,7 +72,7 @@ node_error(nd,"identifier \"%s\" is not a %s", df->df_idf->id_text, str); selector(struct node **pnd;): '.' { *pnd = MkNode(Link,*pnd,NULLNODE,&dot); } - IDENT { (*pnd)->nd_right = MkNode(Name,NULLNODE,NULLNODE,&dot); } + IDENT { (*pnd)->nd_IDF = dot.TOK_IDF; } ; ExpList(struct node **pnd;) diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index c9b6a323..53d0a92e 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -101,6 +101,9 @@ Compile(src, dst) } WalkModule(Defined); C_close(); +#ifdef DEBUG + if (options['m']) MemUse(); +#endif if (err_occurred) return 0; return 1; } @@ -217,3 +220,19 @@ AtEoIT() */ return 1; } + +#ifdef DEBUG +MemUse() +{ + extern int cnt_def, cnt_node, cnt_paramlist, cnt_type, + cnt_switch_hdr, cnt_case_entry, + cnt_scope, cnt_scopelist, cnt_forwards, cnt_tmpvar; + + print("\ +%6d def\n%6d node\n%6d paramlist\n%6d type\n%6d switch_hdr\n\ +%6d case_entry\n%6d scope\n%6d scopelist\n%6d forwards\n%6d tmpvar\n", +cnt_def, cnt_node, cnt_paramlist, cnt_type, +cnt_switch_hdr, cnt_case_entry, +cnt_scope, cnt_scopelist, cnt_forwards, cnt_tmpvar); +} +#endif diff --git a/lang/m2/comp/make.allocd b/lang/m2/comp/make.allocd index 450584aa..364ff9d3 100755 --- a/lang/m2/comp/make.allocd +++ b/lang/m2/comp/make.allocd @@ -3,15 +3,23 @@ s:^.*[ ]ALLOCDEF[ ].*"\(.*\)".*$:\ /* allocation definitions of struct \1 */\ extern char *st_alloc();\ extern struct \1 *h_\1;\ -#define new_\1() ((struct \1 *) \\\ - st_alloc((char **)\&h_\1, sizeof(struct \1)))\ +#ifdef DEBUG\ +extern int cnt_\1;\ +#define new_\1() ((struct \1 *) std_alloc((char **)\&h_\1, sizeof(struct \1), \&cnt_\1))\ +#else\ +#define new_\1() ((struct \1 *) st_alloc((char **)\&h_\1, sizeof(struct \1)))\ +#endif\ #define free_\1(p) st_free(p, h_\1, sizeof(struct \1))\ :' -e ' s:^.*[ ]STATICALLOCDEF[ ].*"\(.*\)".*$:\ /* allocation definitions of struct \1 */\ extern char *st_alloc();\ -static struct \1 *h_\1;\ -#define new_\1() ((struct \1 *) \\\ - st_alloc((char **)\&h_\1, sizeof(struct \1)))\ +struct \1 *h_\1;\ +#ifdef DEBUG\ +int cnt_\1;\ +#define new_\1() ((struct \1 *) std_alloc((char **)\&h_\1, sizeof(struct \1), \&cnt_\1))\ +#else\ +#define new_\1() ((struct \1 *) st_alloc((char **)\&h_\1, sizeof(struct \1)))\ +#endif\ #define free_\1(p) st_free(p, h_\1, sizeof(struct \1))\ :' diff --git a/lang/m2/comp/misc.H b/lang/m2/comp/misc.H index 4f2ae65e..82a8ed5e 100644 --- a/lang/m2/comp/misc.H +++ b/lang/m2/comp/misc.H @@ -2,8 +2,6 @@ /* $Header$ */ -/* ALLOCDEF "id_list" */ - #define is_anon_idf(x) ((x)->id_text[0] == '#') extern struct idf diff --git a/lang/m2/comp/node.H b/lang/m2/comp/node.H index 859e4bbc..db0467a8 100644 --- a/lang/m2/comp/node.H +++ b/lang/m2/comp/node.H @@ -41,3 +41,6 @@ extern struct node *MkNode(); #define HASSELECTORS 2 #define VARIABLE 4 #define VALUE 8 + +#define IsCast(lnd) ((lnd)->nd_class == Def && is_type((lnd)->nd_def)) +#define IsProcCall(lnd) ((lnd)->nd_type->tp_fund == T_PROCEDURE) diff --git a/lang/m2/comp/node.c b/lang/m2/comp/node.c index c2270aa0..b1556d14 100644 --- a/lang/m2/comp/node.c +++ b/lang/m2/comp/node.c @@ -17,6 +17,9 @@ static char *RcsId = "$Header$"; #include "node.h" struct node *h_node; /* header of free list */ +#ifdef DEBUG +int cnt_node; /* count number of allocated ones */ +#endif struct node * MkNode(class, left, right, token) diff --git a/lang/m2/comp/options.c b/lang/m2/comp/options.c index 8e3214d0..6da42772 100644 --- a/lang/m2/comp/options.c +++ b/lang/m2/comp/options.c @@ -25,8 +25,8 @@ DoOption(text) options[text[-1]] = 1; /* flags, debug options etc. */ break; - case 'L' : - warning("-L: default no EM profiling; use -p for EM profiling"); + case 'L' : /* don't generate fil/lin */ + options['L'] = 1; break; case 'M': /* maximum identifier length */ @@ -37,7 +37,7 @@ DoOption(text) fatal("maximum identifier length is %d", IDFSIZE); break; - case 'p' : /* generate profiling code (fil/lin) */ + case 'p' : /* generate profiling code procentry/procexit ???? */ options['p'] = 1; break; diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index e3395260..ac0d4854 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -24,7 +24,6 @@ static int DEFofIMPL = 0; /* Flag indicating that we are currently implementation module currently being compiled */ -struct def *currentdef; /* current definition of module or procedure */ } /* The grammar as given by Wirth is already almost LL(1); the @@ -49,7 +48,6 @@ ModuleDeclaration { struct idf *id; register struct def *df; - struct def *savecurr = currentdef; extern int proclevel; static int modulecount = 0; char buf[256]; @@ -61,7 +59,6 @@ ModuleDeclaration MODULE IDENT { id = dot.TOK_IDF; df = define(id, CurrentScope, D_MODULE); - currentdef = df; if (!df->mod_vis) { open_scope(CLOSEDSCOPE); @@ -71,6 +68,7 @@ ModuleDeclaration CurrVis = df->mod_vis; CurrentScope->sc_level = proclevel; } + CurrentScope->sc_definedby = df; df->df_type = standard_type(T_RECORD, 0, (arith) 0); df->df_type->rec_scope = df->mod_vis->sc_scope; @@ -93,7 +91,6 @@ ModuleDeclaration } close_scope(SC_CHKFORW|SC_CHKPROC|SC_REVERSE); match_id(id, dot.TOK_IDF); - currentdef = savecurr; } ; @@ -244,7 +241,6 @@ ProgramModule if (state == IMPLEMENTATION) { DEFofIMPL = 1; df = GetDefinitionModule(id); - currentdef = df; CurrVis = df->mod_vis; CurrentScope = CurrVis->sc_scope; DEFofIMPL = 0; @@ -256,6 +252,7 @@ ProgramModule df->mod_vis = CurrVis; CurrentScope->sc_name = id->id_text; } + CurrentScope->sc_definedby = df; } priority(&(df->mod_priority))? ';' import(0)* diff --git a/lang/m2/comp/scope.C b/lang/m2/comp/scope.C index a4c5bb3a..c359cfc5 100644 --- a/lang/m2/comp/scope.C +++ b/lang/m2/comp/scope.C @@ -33,13 +33,12 @@ open_scope(scopetype) */ register struct scope *sc = new_scope(); register struct scopelist *ls = new_scopelist(); - + assert(scopetype == OPENSCOPE || scopetype == CLOSEDSCOPE); + + clear((char *) sc, sizeof (*sc)); sc->sc_scopeclosed = scopetype == CLOSEDSCOPE; sc->sc_level = proclevel; - sc->sc_forw = 0; - sc->sc_def = 0; - sc->sc_off = 0; if (scopetype == OPENSCOPE) { ls->next = CurrVis; } diff --git a/lang/m2/comp/scope.h b/lang/m2/comp/scope.h index a80a1dbc..9657870e 100644 --- a/lang/m2/comp/scope.h +++ b/lang/m2/comp/scope.h @@ -23,6 +23,7 @@ struct scope { arith sc_off; /* offsets of variables in this scope */ char sc_scopeclosed; /* flag indicating closed or open scope */ int sc_level; /* level of this scope */ + struct def *sc_definedby; /* The def structure defining this scope */ }; struct scopelist { diff --git a/lang/m2/comp/statement.g b/lang/m2/comp/statement.g index 434de4d8..b0a05b20 100644 --- a/lang/m2/comp/statement.g +++ b/lang/m2/comp/statement.g @@ -16,7 +16,6 @@ static char *RcsId = "$Header$"; #include "node.h" static int loopcount = 0; /* Count nested loops */ -extern struct def *currentdef; } statement(struct node **pnd;) @@ -61,28 +60,11 @@ statement(struct node **pnd;) WithStatement(pnd) | EXIT - { if (!loopcount) { -error("EXIT not in a LOOP"); - } + { if (!loopcount) error("EXIT not in a LOOP"); *pnd = MkNode(Stat, NULLNODE, NULLNODE, &dot); } | - RETURN { *pnd = nd = MkNode(Stat, NULLNODE, NULLNODE, &dot); } - [ - expression(&(nd->nd_right)) - { if (scopeclosed(CurrentScope)) { -error("a module body has no result value"); - } - else if (! currentdef->df_type->next) { -error("procedure \"%s\" has no result value", currentdef->df_idf->id_text); - } - } - | - { if (currentdef->df_type->next) { -error("procedure \"%s\" must return a value", currentdef->df_idf->id_text); - } - } - ] + ReturnStatement(pnd) ]? ; @@ -193,18 +175,28 @@ RepeatStatement(struct node **pnd;) ForStatement(struct node **pnd;) { register struct node *nd; + struct node *dummy; }: FOR { *pnd = MkNode(Stat, NULLNODE, NULLNODE, &dot); } - IDENT { nd = MkNode(Name, NULLNODE, NULLNODE, &dot); } - BECOMES { nd = MkNode(BECOMES, nd, NULLNODE, &dot); } - expression(&(nd->nd_right)) - TO { (*pnd)->nd_left=nd=MkNode(Link,nd,NULLNODE,&dot); } + IDENT { (*pnd)->nd_IDF = dot.TOK_IDF; } + BECOMES { nd = MkNode(Stat, NULLNODE, NULLNODE, &dot); + (*pnd)->nd_left = nd; + } + expression(&(nd->nd_left)) + TO expression(&(nd->nd_right)) [ - BY { nd->nd_right=MkNode(Link,NULLNODE,nd->nd_right,&dot); + BY + ConstExpression(&dummy) + { + if (!(dummy->nd_type->tp_fund & T_INTORCARD)) { + error("illegal type in BY clause"); + } + nd->nd_INT = dummy->nd_INT; + FreeNode(dummy); } - ConstExpression(&(nd->nd_right->nd_left)) | + { nd->nd_INT = 1; } ] DO StatementSequence(&((*pnd)->nd_right)) @@ -227,3 +219,27 @@ WithStatement(struct node **pnd;) StatementSequence(&(nd->nd_right)) END ; + +ReturnStatement(struct node **pnd;) +{ + register struct def *df = CurrentScope->sc_definedby; + register struct node *nd; +} : + + RETURN { *pnd = nd = MkNode(Stat, NULLNODE, NULLNODE, &dot); } + [ + expression(&(nd->nd_right)) + { if (scopeclosed(CurrentScope)) { +error("a module body has no result value"); + } + else if (! df->df_type->next) { +error("procedure \"%s\" has no result value", df->df_idf->id_text); + } + } + | + { if (df->df_type->next) { +error("procedure \"%s\" must return a value", df->df_idf->id_text); + } + } + ] +; diff --git a/lang/m2/comp/type.H b/lang/m2/comp/type.H index 13533ef0..958a76e7 100644 --- a/lang/m2/comp/type.H +++ b/lang/m2/comp/type.H @@ -4,8 +4,9 @@ struct paramlist { /* structure for parameterlist of a PROCEDURE */ struct paramlist *next; - struct type *par_type; /* Parameter type */ - int par_var; /* flag, set if VAR parameter */ + struct def *par_def; /* "df" of parameter */ +#define IsVarParam(xpar) ((xpar)->par_def->df_flags & D_VARPAR) +#define TypeOfParam(xpar) ((xpar)->par_def->df_type) }; /* ALLOCDEF "paramlist" */ diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index 1ac5eb5c..9319f9d9 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -19,6 +19,7 @@ static char *RcsId = "$Header$"; #include "LLlex.h" #include "node.h" #include "const.h" +#include "scope.h" /* To be created dynamically in main() from defaults or from command line parameters. @@ -58,8 +59,14 @@ struct type *error_type; struct paramlist *h_paramlist; +#ifdef DEBUG +int cnt_paramlist; +#endif struct type *h_type; +#ifdef DEBUG +int cnt_type; +#endif extern label data_label(); @@ -215,31 +222,33 @@ init_types() error_type = standard_type(T_CHAR, 1, (arith) 1); } -/* Create a parameterlist of a procedure and return a pointer to it. - "ids" indicates the list of identifiers, "tp" their type, and - "VARp" is set when the parameters are VAR-parameters. - Actually, "ids" is only used because it tells us how many parameters - there were with this type. -*/ -struct paramlist * -ParamList(ids, tp, VARp) +ParamList(ppr, ids, tp, VARp, off) register struct node *ids; + struct paramlist **ppr; struct type *tp; + arith *off; { + /* Create (part of) a parameterlist of a procedure. + "ids" indicates the list of identifiers, "tp" their type, and + "VARp" is set when the parameters are VAR-parameters. +*/ register struct paramlist *pr; + register struct def *df; struct paramlist *pstart; - pstart = pr = new_paramlist(); - pr->par_type = tp; - pr->par_var = VARp; - for (ids = ids->next; ids; ids = ids->next) { - pr->next = new_paramlist(); - pr = pr->next; - pr->par_type = tp; - pr->par_var = VARp; + while (ids) { + pr = new_paramlist(); + pr->next = *ppr; + *ppr = pr; + df = define(ids->nd_IDF, CurrentScope, D_VARIABLE); + pr->par_def = df; + df->df_type = tp; + if (VARp) df->df_flags = D_VARPAR; + else df->df_flags = D_VALPAR; + df->var_off = align(*off, word_align); + *off = df->var_off + tp->tp_size; + ids = ids->next; } - pr->next = 0; - return pstart; } chk_basesubrange(tp, base) @@ -551,8 +560,8 @@ DumpType(tp) if (par) { print("; p:"); while(par) { - if (par->par_var) print("VAR "); - DumpType(par->par_type); + if (IsVarParam(par)) print("VAR "); + DumpType(TypeOfParam(par)); par = par->next; } } diff --git a/lang/m2/comp/typequiv.c b/lang/m2/comp/typequiv.c index 266a06a5..b46971bc 100644 --- a/lang/m2/comp/typequiv.c +++ b/lang/m2/comp/typequiv.c @@ -12,6 +12,8 @@ static char *RcsId = "$Header$"; #include "type.h" #include "def.h" +#include "LLlex.h" +#include "node.h" int TstTypeEquiv(tp1, tp2) @@ -70,8 +72,8 @@ TstProcEquiv(tp1, tp2) /* Now check the parameters */ while (p1 && p2) { - if (p1->par_var != p2->par_var || - !TstParEquiv(p1->par_type, p2->par_type)) return 0; + if (IsVarParam(p1) != IsVarParam(p2) || + !TstParEquiv(TypeOfParam(p1), TypeOfParam(p2))) return 0; p1 = p1->next; p2 = p2->next; } @@ -172,11 +174,11 @@ TstAssCompat(tp1, tp2) } int -TstParCompat(formaltype, actualtype, VARflag) +TstParCompat(formaltype, actualtype, VARflag, nd) struct type *formaltype, *actualtype; + struct node *nd; { - /* Check type compatibility for a parameter in a procedure - call. Ordinary type compatibility is sufficient in any case. + /* Check type compatibility for a parameter in a procedure call. Assignment compatibility may do if the parameter is a value parameter. Otherwise, a conformant array may do, or an ARRAY OF WORD @@ -185,11 +187,20 @@ TstParCompat(formaltype, actualtype, VARflag) */ return - TstCompat(formaltype, actualtype) + TstTypeEquiv(formaltype, actualtype) || ( !VARflag && TstAssCompat(formaltype, actualtype)) || - ( formaltype == word_type && actualtype->tp_size == word_size) + ( formaltype == word_type + && + ( actualtype->tp_size == word_size + || + ( !VARflag + && + actualtype->tp_size <= word_size + ) + ) + ) || ( IsConformantArray(formaltype) && @@ -203,5 +214,21 @@ TstParCompat(formaltype, actualtype, VARflag) && TstTypeEquiv(formaltype->arr_elem, char_type) ) ) - ); + ) + || + ( VARflag && OldCompat(formaltype, actualtype, nd)) + ; +} + +int +OldCompat(ft, at, nd) + struct type *ft, *at; + struct node *nd; +{ + if (TstCompat(ft, at)) { +node_warning(nd, "oldfashioned! types of formal and actual must be identical"); + return 1; + } + + return 0; } diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index b24bcacd..578cc67c 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -54,7 +54,7 @@ DoProfil() { static label filename_label = 0; - if (options['p']) { + if (! options['L']) { if (!filename_label) { filename_label = data_label(); C_df_dlb(filename_label); @@ -278,10 +278,16 @@ WalkStat(nd, lab) return; } - if (options['p']) C_lin((arith) nd->nd_lineno); + if (options['L']) C_lin((arith) nd->nd_lineno); if (nd->nd_class == Call) { - if (chk_call(nd)) CodeCall(nd); + if (chk_call(nd)) { + if (nd->nd_type != 0) { + node_error(nd, "procedure call expected"); + return; + } + CodeCall(nd); + } return; } @@ -289,7 +295,7 @@ WalkStat(nd, lab) switch(nd->nd_symb) { case BECOMES: - DoAssign(nd, left, right, 0); + DoAssign(nd, left, right); break; case IF: @@ -362,51 +368,27 @@ WalkStat(nd, lab) struct node *fnd; label l1 = instructionlabel++; label l2 = instructionlabel++; - arith incr = 1; arith size; - assert(left->nd_symb == TO); - assert(left->nd_left->nd_symb == BECOMES); - - DoAssign(left->nd_left, - left->nd_left->nd_left, - left->nd_left->nd_right, 1); + if (! DoForInit(nd, left)) break; fnd = left->nd_right; - if (fnd->nd_symb == BY) { - incr = fnd->nd_left->nd_INT; - fnd = fnd->nd_right; - } - if (! chk_expr(fnd)) return; size = fnd->nd_type->tp_size; if (fnd->nd_class != Value) { - *pds = InitDesig; - CodeExpr(fnd, pds, NO_LABEL, NO_LABEL); - CodeValue(pds, size); + CodePExpr(fnd); tmp = NewInt(); C_stl(tmp); } - if (!TstCompat(left->nd_left->nd_left->nd_type, - fnd->nd_type)) { -node_error(fnd, "type incompatibility in limit of FOR loop"); - break; - } C_bra(l1); C_df_ilb(l2); WalkNode(right, lab); - *pds = InitDesig; - C_loc(incr); - CodeDesig(left->nd_left->nd_left, pds); - CodeValue(pds, size); + C_loc(left->nd_INT); + CodePExpr(nd); C_adi(int_size); - *pds = InitDesig; - CodeDesig(left->nd_left->nd_left, pds); - CodeStore(pds, size); + CodeDStore(nd); C_df_ilb(l1); - *pds = InitDesig; - CodeDesig(left->nd_left->nd_left, pds); - CodeValue(pds, size); + CodePExpr(nd); if (tmp) C_lol(tmp); else C_loc(fnd->nd_INT); - if (incr > 0) { + if (left->nd_INT > 0) { C_ble(l2); } else C_bge(l2); @@ -461,8 +443,7 @@ node_error(fnd, "type incompatibility in limit of FOR loop"); case RETURN: if (right) { WalkExpr(right, NO_LABEL, NO_LABEL); - /* What kind of compatibility do we need here ??? - assignment compatibility? + /* Assignment compatibility? Yes, see Rep. 9.11 */ if (!TstAssCompat(func_type, right->nd_type)) { node_error(right, "type incompatibility in RETURN statement"); @@ -519,27 +500,51 @@ WalkDesignator(nd) Desig = InitDesig; CodeDesig(nd, &Desig); - } -DoAssign(nd, left, right, forloopass) +DoForInit(nd, left) + register struct node *nd, *left; +{ + + nd->nd_left = nd->nd_right = 0; + nd->nd_class = Name; + nd->nd_symb = IDENT; + + if (! chk_designator(nd, VARIABLE, D_DEFINED) || + ! chk_expr(left->nd_left) || + ! chk_expr(left->nd_right)) return; + + if (nd->nd_type->tp_size > word_size || + !(nd->nd_type->tp_fund & T_DISCRETE)) { + node_error(nd, "illegal type of FOR loop variable"); + return 0; + } + + if (!TstCompat(nd->nd_type, left->nd_left->nd_type) || + !TstCompat(nd->nd_type, left->nd_right->nd_type)) { + if (!TstAssCompat(nd->nd_type, left->nd_left->nd_type) || + !TstAssCompat(nd->nd_type, left->nd_right->nd_type)) { + node_error(nd, "type incompatibility in FOR statement"); + return 0; + } +node_warning(nd, "old-fashioned! compatibility required in FOR statement"); + } + + CodePExpr(left->nd_left); + CodeDStore(nd); +} + +DoAssign(nd, left, right) struct node *nd; register struct node *left, *right; { - /* May we do it in this order (expression first) ??? */ + /* May we do it in this order (expression first) ??? */ struct desig ds; WalkExpr(right, NO_LABEL, NO_LABEL); if (! chk_designator(left, DESIGNATOR|VARIABLE, D_DEFINED)) return; - if (forloopass) { - if (! TstCompat(left->nd_type, right->nd_type)) { - node_error(nd, "type incompatibility in FOR loop"); - return; - } - /* Test if the left hand side may be a for loop variable ??? */ - } - else if (! TstAssCompat(left->nd_type, right->nd_type)) { + if (! TstAssCompat(left->nd_type, right->nd_type)) { node_error(nd, "type incompatibility in assignment"); return; } From c479ca00580afb3b503d94b9bae8f9f33a15855a Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 4 Jun 1986 09:01:48 +0000 Subject: [PATCH 0200/1625] first, almost complete, version --- lang/m2/comp/LLlex.c | 38 ++++++---- lang/m2/comp/LLlex.h | 4 +- lang/m2/comp/chk_expr.c | 54 +++++++++----- lang/m2/comp/code.c | 152 ++++++++++++++++++++++++++++---------- lang/m2/comp/cstoper.c | 6 -- lang/m2/comp/declar.g | 52 +++++++------ lang/m2/comp/def.H | 1 + lang/m2/comp/def.c | 99 ++++++++++++++++--------- lang/m2/comp/desig.c | 29 +++++--- lang/m2/comp/expression.g | 69 ++++++++--------- lang/m2/comp/main.c | 20 ++--- lang/m2/comp/node.H | 2 +- lang/m2/comp/node.c | 13 ++++ lang/m2/comp/program.g | 18 +---- lang/m2/comp/statement.g | 45 +++++------ lang/m2/comp/type.H | 15 ++-- lang/m2/comp/type.c | 100 +++++++++++++++---------- lang/m2/comp/typequiv.c | 14 +--- lang/m2/comp/walk.c | 36 +++++---- 19 files changed, 458 insertions(+), 309 deletions(-) diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index 19ffd0c1..e4a15ab9 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -26,9 +26,10 @@ static char *RcsId = "$Header$"; long str2long(); struct token dot, aside; -struct type *numtype; +struct type *toktype; struct string string; int idfsize = IDFSIZE; +extern label data_label(); static SkipComment() @@ -111,10 +112,10 @@ LLlex() The putting aside of tokens is taken into account. */ register struct token *tk = ˙ - char buf[(IDFSIZE > NUMSIZE ? IDFSIZE : NUMSIZE) + 1]; + char buf[(IDFSIZE > NUMSIZE ? IDFSIZE : NUMSIZE) + 2]; register int ch, nch; - numtype = error_type; + toktype = error_type; if (ASIDE) { /* a token is put aside */ *tk = aside; ASIDE = 0; @@ -221,9 +222,16 @@ again: case STSTR: GetString(ch); - tk->tk_data.tk_str = (struct string *) + if (string.s_length == 1) { + tk->TOK_INT = *(string.s_str) & 0377; + toktype = char_type; + } + else { + tk->tk_data.tk_str = (struct string *) Malloc(sizeof (struct string)); - *(tk->tk_data.tk_str) = string; + *(tk->tk_data.tk_str) = string; + toktype = standard_type(T_STRING, 1, string.s_length); + } return tk->tk_symb = STRING; case STNUM: @@ -252,9 +260,9 @@ again: Shex: *np++ = '\0'; tk->TOK_INT = str2long(&buf[1], 16); if (tk->TOK_INT >= 0 && tk->TOK_INT <= max_int) { - numtype = intorcard_type; + toktype = intorcard_type; } - else numtype = card_type; + else toktype = card_type; return tk->tk_symb = INTEGER; case '8': @@ -290,15 +298,15 @@ Shex: *np++ = '\0'; *np++ = '\0'; tk->TOK_INT = str2long(&buf[1], 8); if (ch == 'C') { - numtype = char_type; + toktype = char_type; if (tk->TOK_INT < 0 || tk->TOK_INT > 255) { lexwarning("Character constant out of range"); } } else if (tk->TOK_INT >= 0 && tk->TOK_INT <= max_int) { - numtype = intorcard_type; + toktype = intorcard_type; } - else numtype = card_type; + else toktype = card_type; return tk->tk_symb = INTEGER; case 'A': @@ -380,12 +388,10 @@ Sreal: PushBack(ch); if (np == &buf[NUMSIZE + 1]) { - lexerror("floating constant too long"); tk->TOK_REL = Salloc("0.0", 5); + lexerror("floating constant too long"); } - else { - tk->TOK_REL = Salloc(buf, np - buf) + 1; - } + else tk->TOK_REL = Salloc(buf, np - buf) + 1; return tk->tk_symb = REAL; default: @@ -394,9 +400,9 @@ Sdec: *np++ = '\0'; tk->TOK_INT = str2long(&buf[1], 10); if (tk->TOK_INT < 0 || tk->TOK_INT > max_int) { - numtype = card_type; + toktype = card_type; } - else numtype = intorcard_type; + else toktype = intorcard_type; return tk->tk_symb = INTEGER; } /*NOTREACHED*/ diff --git a/lang/m2/comp/LLlex.h b/lang/m2/comp/LLlex.h index dae0151a..8ba0bd94 100644 --- a/lang/m2/comp/LLlex.h +++ b/lang/m2/comp/LLlex.h @@ -25,10 +25,10 @@ struct token { #define TOK_STR tk_data.tk_str->s_str #define TOK_SLE tk_data.tk_str->s_length #define TOK_INT tk_data.tk_int -#define TOK_REL tk_data.tk_real +#define TOK_REL tk_data.tk_real extern struct token dot, aside; -extern struct type *numtype; +extern struct type *toktype; #define DOT dot.tk_symb #define ASIDE aside.tk_symb diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index 4e69cad6..49163d6a 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -61,7 +61,7 @@ chk_expr(expp) return 1; default: - assert(0); + crash("(chk_expr(Value))"); } break; @@ -78,7 +78,7 @@ chk_expr(expp) return chk_designator(expp, DESIGNATOR|VALUE, D_USED|D_NOREG); default: - assert(0); + crash("(chk_expr)"); } /*NOTREACHED*/ } @@ -90,9 +90,9 @@ chk_set(expp) /* Check the legality of a SET aggregate, and try to evaluate it compile time. Unfortunately this is all rather complicated. */ - struct type *tp; - struct def *df; + register struct type *tp; register struct node *nd; + register struct def *df; arith *set; unsigned size; @@ -110,7 +110,7 @@ chk_set(expp) if (!(df->df_kind & (D_TYPE|D_ERROR)) || (df->df_type->tp_fund != T_SET)) { - node_error(expp, "specifier does not represent a set type"); +node_error(expp, "specifier does not represent a set type"); return 0; } tp = df->df_type; @@ -163,16 +163,16 @@ chk_set(expp) int chk_el(expp, tp, set) register struct node *expp; - struct type *tp; + register struct type *tp; arith **set; { /* Check elements of a set. This routine may call itself recursively. Also try to compute the set! */ - register int i; register struct node *left = expp->nd_left; register struct node *right = expp->nd_right; + register int i; if (expp->nd_class == Link && expp->nd_symb == UPTO) { /* { ... , expr1 .. expr2, ... } @@ -370,7 +370,9 @@ chk_proccall(expp) while (param) { if (!(left = getarg(&arg, 0, IsVarParam(param)))) return 0; - + if (left->nd_symb == STRING) { + TryToString(left, TypeOfParam(param)); + } if (! TstParCompat(TypeOfParam(param), left->nd_type, IsVarParam(param), @@ -734,6 +736,7 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R } return 1; + case T_HIDDEN: case T_POINTER: if (chk_address(tpl, tpr) || expp->nd_symb == '=' || @@ -812,16 +815,13 @@ chk_uoper(expp) return 1; } else if (tpr->tp_fund == T_REAL) { + expp->nd_type = tpr; if (right->nd_class == Value) { - expp->nd_token = right->nd_token; + if (*(right->nd_REL) == '-') (right->nd_REL)++; + else (right->nd_REL)--; expp->nd_class = Value; - if (*(expp->nd_REL) == '-') { - expp->nd_REL++; - } - else { - expp->nd_REL--; - *(expp->nd_REL) = '-'; - } + expp->nd_symb = REAL; + expp->nd_REL = right->nd_REL; FreeNode(right); expp->nd_right = 0; } @@ -901,7 +901,10 @@ DO_DEBUG(3,debug("standard name \"%s\", %d",left->nd_def->df_idf->id_text,std)); case S_ABS: if (!(left = getarg(&arg, T_NUMERIC, 0))) return 0; expp->nd_type = left->nd_type; - if (left->nd_class == Value) cstcall(expp, S_ABS); + if (left->nd_class == Value && + expp->nd_type->tp_fund != T_REAL) { + cstcall(expp, S_ABS); + } break; case S_CAP: @@ -1085,3 +1088,20 @@ node_error(expp, "only one parameter expected in type cast"); return 1; } + +TryToString(nd, tp) + struct node *nd; + struct type *tp; +{ + /* Try a coercion from character constant to string */ + if (tp->tp_fund == T_ARRAY && nd->nd_type == char_type) { + int ch = nd->nd_INT; + + nd->nd_type = standard_type(T_STRING, 1, (arith) 2); + nd->nd_token.tk_data.tk_str = + (struct string *) Malloc(sizeof(struct string)); + nd->nd_STR = Salloc("X", 2); + *(nd->nd_STR) = ch; + nd->nd_SLE = 1; + } +} diff --git a/lang/m2/comp/code.c b/lang/m2/comp/code.c index f59ef69d..ca720318 100644 --- a/lang/m2/comp/code.c +++ b/lang/m2/comp/code.c @@ -50,25 +50,49 @@ CodeConst(cst, size) } CodeString(nd) - struct node *nd; + register struct node *nd; { label lab; - if (nd->nd_type == charc_type) { + if (nd->nd_type == char_type) { C_loc(nd->nd_INT); - return; } - C_df_dlb(lab = data_label()); - C_rom_scon(nd->nd_STR, nd->nd_SLE); - C_lae_dlb(lab, (arith) 0); + else { + C_df_dlb(lab = data_label()); + C_rom_scon(nd->nd_STR, align(nd->nd_SLE + 1, word_size)); + C_lae_dlb(lab, (arith) 0); + } +} + +CodePadString(nd, sz) + register struct node *nd; + arith sz; +{ + /* Generate code to push the string indicated by "nd". + Make it null-padded to "sz" bytes + */ + register arith sizearg = align(nd->nd_type->tp_size, word_align); + + assert(nd->nd_type->tp_fund == T_STRING); + + if (sizearg != sz) { + /* null padding required */ + assert(sizearg < sz); + C_zer(sz - sizearg); + } + C_asp(-sizearg); /* room for string */ + CodeString(nd); /* push address of string */ + C_lor((arith) 1); /* load stack pointer */ + C_adp(pointer_size); /* and compute target address from it */ + C_blm(sizearg); /* and copy */ } CodeReal(nd) - struct node *nd; + register struct node *nd; { - label lab; - - C_df_dlb(lab = data_label()); + label lab = data_label(); + + C_df_dlb(lab); C_rom_fcon(nd->nd_REL, nd->nd_type->tp_size); C_lae_dlb(lab, (arith) 0); C_loi(nd->nd_type->tp_size); @@ -83,10 +107,13 @@ CodeExpr(nd, ds, true_label, false_label) switch(nd->nd_class) { case Def: if (nd->nd_def->df_kind == D_PROCEDURE) { - C_lpi(nd->nd_def->prc_vis->sc_scope->sc_name); + C_lpi(NameOfProc(nd->nd_def)); ds->dsg_kind = DSG_LOADED; break; } + /* Fall through */ + + case Link: CodeDesig(nd, ds); break; @@ -97,10 +124,8 @@ CodeExpr(nd, ds, true_label, false_label) } CodeOper(nd, true_label, false_label); if (true_label == 0) ds->dsg_kind = DSG_LOADED; - else { - *ds = InitDesig; - true_label = 0; - } + else ds->dsg_kind = DSG_INIT; + true_label = 0; break; case Uoper: @@ -130,10 +155,6 @@ CodeExpr(nd, ds, true_label, false_label) ds->dsg_kind = DSG_LOADED; break; - case Link: - CodeDesig(nd, ds); - break; - case Call: CodeCall(nd); ds->dsg_kind = DSG_LOADED; @@ -177,7 +198,7 @@ CodeExpr(nd, ds, true_label, false_label) CodeCoercion(t1, t2) register struct type *t1, *t2; { - int fund1, fund2; + register int fund1, fund2; if (t1 == t2) return; if (t1->tp_fund == T_SUBRANGE) t1 = t1->next; @@ -285,7 +306,6 @@ CodeCall(nd) CodeStd(nd); return; } - tp = left->nd_type; if (IsCast(left)) { /* it was just a cast. Simply ignore it @@ -299,18 +319,42 @@ CodeCall(nd) assert(IsProcCall(left)); for (param = left->nd_type->prc_params; param; param = param->next) { + tp = TypeOfParam(param); arg = arg->nd_right; assert(arg != 0); - if (IsVarParam(param)) { + if (IsConformantArray(tp)) { + C_loc(tp->arr_elsize); + if (IsConformantArray(arg->nd_left->nd_type)) { + DoHIGH(arg->nd_left); + } + else if (arg->nd_left->nd_symb == STRING) { + C_loc(arg->nd_left->nd_SLE); + } + else if (tp->arr_elem == word_type) { + C_loc(arg->nd_left->nd_type->tp_size / word_size - 1); + } + else C_loc(arg->nd_left->nd_type->tp_size / + tp->arr_elsize - 1); + C_loc(0); + if (arg->nd_left->nd_symb == STRING) { + CodeString(arg->nd_left); + } + else CodeDAddress(arg->nd_left); + pushed += pointer_size + 3 * word_size; + } + else if (IsVarParam(param)) { CodeDAddress(arg->nd_left); pushed += pointer_size; } else { - CodePExpr(arg->nd_left); - CheckAssign(arg->nd_left->nd_type, TypeOfParam(param)); - pushed += align(arg->nd_left->nd_type->tp_size, word_align); + if (arg->nd_left->nd_type->tp_fund == T_STRING) { + CodePadString(arg->nd_left, + align(tp->tp_size, word_align)); + } + else CodePExpr(arg->nd_left); + CheckAssign(arg->nd_left->nd_type, tp); + pushed += align(tp->tp_size, word_align); } - /* ??? Conformant arrays */ } if (left->nd_class == Def && left->nd_def->df_kind == D_PROCEDURE) { @@ -318,7 +362,7 @@ CodeCall(nd) C_lxl((arith) proclevel - left->nd_def->df_scope->sc_level); pushed += pointer_size; } - C_cal(left->nd_def->prc_vis->sc_scope->sc_name); + C_cal(NameOfProc(left->nd_def)); } else if (left->nd_class == Def && left->nd_def->df_kind == D_PROCHEAD) { C_cal(left->nd_def->for_name); @@ -327,9 +371,9 @@ CodeCall(nd) CodePExpr(left); C_cai(); } - C_asp(pushed); - if (tp->next) { - C_lfr(align(tp->next->tp_size, word_align)); + if (pushed) C_asp(pushed); + if (left->nd_type->next) { + C_lfr(align(left->nd_type->next->tp_size, word_align)); } } @@ -385,7 +429,7 @@ CodeStd(nd) case S_HIGH: assert(IsConformantArray(tp)); - /* ??? */ + DoHIGH(left); break; case S_ODD: @@ -480,15 +524,24 @@ CodeAssign(nd, dss, dst) /* Generate code for an assignment. Testing of type compatibility and the like is already done. */ + register struct type *tp = nd->nd_right->nd_type; + extern arith align(); if (dss->dsg_kind == DSG_LOADED) { + if (tp->tp_fund == T_STRING) { + CodeAddress(dst); + C_loc(tp->tp_size); + C_loc(nd->nd_left->nd_type->tp_size); + C_cal("_StringAssign"); + C_asp((int_size << 1) + (pointer_size << 1)); + return; + } CodeStore(dst, nd->nd_left->nd_type->tp_size); + return; } - else { - CodeAddress(dss); - CodeAddress(dst); - C_blm(nd->nd_left->nd_type->tp_size); - } + CodeAddress(dss); + CodeAddress(dst); + C_blm(nd->nd_left->nd_type->tp_size); } CheckAssign(tpl, tpr) @@ -683,6 +736,7 @@ CodeOper(expr, true_label, false_label) case T_INTEGER: C_cmi(tp->tp_size); break; + case T_HIDDEN: case T_POINTER: C_cmp(); break; @@ -904,12 +958,16 @@ CodeSet(nd) CodeEl(nd, tp) register struct node *nd; - struct type *tp; + register struct type *tp; { if (nd->nd_class == Link && nd->nd_symb == UPTO) { C_zer(tp->tp_size); /* empty set */ C_lor((arith) 1); /* SP: address of set */ + if (tp->next->tp_fund == T_SUBRANGE) { + C_loc(tp->next->sub_ub); + } + else C_loc(tp->next->enm_ncst - 1); Operands(nd->nd_left, nd->nd_right); C_cal("_LtoUset"); /* library routine to fill set */ C_asp(2 * word_size + pointer_size); @@ -960,3 +1018,23 @@ CodeDStore(nd) CodeDesig(nd, &designator); CodeStore(&designator, nd->nd_type->tp_size); } + +DoHIGH(nd) + struct node *nd; +{ + register struct def *df; + arith highoff; + + assert(nd->nd_class == Def); + + df = nd->nd_def; + + assert(df->df_kind == D_VARIABLE); + + highoff = df->var_off + pointer_size + word_size; + if (df->df_scope->sc_level < proclevel) { + C_lxa(proclevel - df->df_scope->sc_level); + C_lof(highoff); + } + else C_lol(highoff); +} diff --git a/lang/m2/comp/cstoper.c b/lang/m2/comp/cstoper.c index 20d91a50..7c0453a5 100644 --- a/lang/m2/comp/cstoper.c +++ b/lang/m2/comp/cstoper.c @@ -374,12 +374,6 @@ cstcall(expp, call) expp->nd_symb = INTEGER; switch(call) { case S_ABS: - if (expr->nd_type->tp_fund == T_REAL) { - expp->nd_symb = REAL; - expp->nd_REL = expr->nd_REL; - if (*(expr->nd_REL) == '-') (expp->nd_REL)++; - break; - } if (expr->nd_INT < 0) expp->nd_INT = - expr->nd_INT; else expp->nd_INT = expr->nd_INT; CutSize(expp); diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index b605456a..84174ed8 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -54,7 +54,7 @@ ProcedureHeading(struct def **pdf; int type;) { df = DeclProc(type); tp = construct_type(T_PROCEDURE, tp); - if (proclevel) { + if (proclevel > 1) { /* Room for static link */ tp->prc_nbpar = pointer_size; @@ -134,10 +134,10 @@ FPSection(struct paramlist **ppr; arith *parmaddr;) { struct node *FPList; struct type *tp; - int VARp = 0; + int VARp = D_VALPAR; } : [ - VAR { VARp = 1; } + VAR { VARp = D_VARPAR; } ]? IdentList(&FPList) ':' FormalType(&tp) { @@ -146,43 +146,48 @@ FPSection(struct paramlist **ppr; arith *parmaddr;) } ; -FormalType(struct type **tp;) +FormalType(struct type **ptp;) { struct def *df; int ARRAYflag = 0; + register struct type *tp; + extern arith ArrayElSize(); } : [ ARRAY OF { ARRAYflag = 1; } ]? qualident(D_ISTYPE, &df, "type", (struct node **) 0) { if (ARRAYflag) { - *tp = construct_type(T_ARRAY, NULLTYPE); - (*tp)->arr_elem = df->df_type; - (*tp)->tp_align = lcm(word_align, pointer_align); - (*tp)->tp_size = align(pointer_size + word_size, - (*tp)->tp_align); + *ptp = tp = construct_type(T_ARRAY, NULLTYPE); + tp->arr_elem = df->df_type; + tp->arr_elsize = ArrayElSize(df->df_type); + tp->tp_align = lcm(word_align, pointer_align); } - else *tp = df->df_type; + else *ptp = df->df_type; } ; TypeDeclaration { - struct def *df; + register struct def *df; struct type *tp; }: IDENT { df = lookup(dot.TOK_IDF, CurrentScope); - if (!df) df = define( dot.TOK_IDF, - CurrentScope, - D_TYPE); + if (!df) df = define(dot.TOK_IDF,CurrentScope,D_TYPE); } '=' type(&tp) - { if (df->df_type) free_type(df->df_type); /* ??? */ - df->df_type = tp; - if (df->df_kind == D_HIDDEN && - tp->tp_fund != T_POINTER) { + { + if (df->df_kind == D_HIDDEN) { + if (tp->tp_fund != T_POINTER) { error("opaque type \"%s\" is not a pointer type", df->df_idf->id_text); + } + df->df_kind = D_TYPE; + *(df->df_type) = *tp; + free_type(tp); + } + else { + df->df_type = tp; + df->df_kind = D_TYPE; } - df->df_kind = D_TYPE; } ; @@ -235,6 +240,7 @@ enumeration(struct type **ptp;) CurrentScope, (arith *) 0); FreeNode(EnumList); if (tp->enm_ncst > 256) { + /* ??? is this reasonable ??? */ error("Too many enumeration literals"); } } @@ -244,12 +250,12 @@ IdentList(struct node **p;) { register struct node *q; } : - IDENT { q = MkNode(Value, NULLNODE, NULLNODE, &dot); + IDENT { q = MkLeaf(Value, &dot); *p = q; } [ ',' IDENT - { q->next = MkNode(Value,NULLNODE,NULLNODE,&dot); + { q->next = MkLeaf(Value, &dot); q = q->next; } ]* @@ -572,11 +578,11 @@ VariableDeclaration IdentAddrList(struct node **pnd;) { } : - IDENT { *pnd = MkNode(Name, NULLNODE, NULLNODE, &dot); } + IDENT { *pnd = MkLeaf(Name, &dot); } ConstExpression(&(*pnd)->nd_left)? [ { pnd = &((*pnd)->nd_right); } ',' IDENT - { *pnd = MkNode(Name, NULLNODE, NULLNODE, &dot); } + { *pnd = MkLeaf(Name, &dot); } ConstExpression(&(*pnd)->nd_left)? ]* ; diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H index df4517a9..bdf90881 100644 --- a/lang/m2/comp/def.H +++ b/lang/m2/comp/def.H @@ -48,6 +48,7 @@ struct dfproc { struct node *pr_body; /* body of this procedure */ #define prc_vis df_value.df_proc.pr_vis #define prc_body df_value.df_proc.pr_body +#define NameOfProc(xdf) ((xdf)->prc_vis->sc_scope->sc_name) }; struct import { diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index c3a98030..80bc6ea2 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -30,7 +30,7 @@ struct def *ill_df; struct def * MkDef(id, scope, kind) struct idf *id; - struct scope *scope; + register struct scope *scope; { /* Create a new definition structure in scope "scope", with id "id" and kind "kind". @@ -55,7 +55,7 @@ MkDef(id, scope, kind) InitDef() { /* Initialize this module. Easy, the only thing to be initialized - is "illegal_def". + is "ill_df". */ struct idf *gen_anon_idf(); @@ -83,6 +83,9 @@ define(id, scope, kind) ) { switch(df->df_kind) { case D_HIDDEN: + /* An opaque type. We may now have found the + definition of this type. + */ if (kind == D_TYPE && !DefinitionModule) { df->df_kind = D_TYPE; return df; @@ -90,6 +93,10 @@ define(id, scope, kind) break; case D_FORWMODULE: + /* A forward reference to a module. We may have found + another one, or we may have found the definition + for this module. + */ if (kind == D_FORWMODULE) { return df; } @@ -104,19 +111,27 @@ define(id, scope, kind) break; case D_FORWARD: + /* A forward reference, for which we may now have + found a definition. + */ if (kind != D_FORWARD) { FreeNode(df->for_node); } - df->df_kind = kind; - return df; + /* Fall through */ case D_ERROR: + /* A definition generated by the compiler, because + it found an error. Maybe, the user gives a + definition after all. + */ df->df_kind = kind; return df; } if (kind != D_ERROR) { + /* Avoid spurious error messages + */ error("identifier \"%s\" already declared", id->id_text); } @@ -149,6 +164,8 @@ lookup(id, scope) assert(retval != 0); } if (df1) { + /* Put the definition now found in front + */ df1->next = df->next; df->next = id->id_def; id->id_def = df; @@ -162,30 +179,34 @@ lookup(id, scope) } DoImport(df, scope) - struct def *df; + register struct def *df; struct scope *scope; { - register struct def *df1; + /* Definition "df" is imported to scope "scope". + Handle the case that it is an enumeration type or a module. + */ + + define(df->df_idf, scope, D_IMPORT)->imp_def = df; if (df->df_kind == D_TYPE && df->df_type->tp_fund == T_ENUMERATION) { /* Also import all enumeration literals */ - df1 = df->df_type->enm_enums; - while (df1) { - define(df1->df_idf, scope, D_IMPORT)->imp_def = df1; - df1 = df1->enm_next; + df = df->df_type->enm_enums; + while (df) { + define(df->df_idf, scope, D_IMPORT)->imp_def = df; + df = df->enm_next; } } else if (df->df_kind == D_MODULE) { /* Also import all definitions that are exported from this module */ - df1 = df->mod_vis->sc_scope->sc_def; - while (df1) { - if (df1->df_flags & D_EXPORTED) { - define(df1->df_idf, scope, D_IMPORT)->imp_def = df1; + df = df->mod_vis->sc_scope->sc_def; + while (df) { + if (df->df_flags & D_EXPORTED) { + define(df->df_idf,scope,D_IMPORT)->imp_def = df; } - df1 = df1->df_nextinscope; + df = df->df_nextinscope; } } } @@ -213,7 +234,7 @@ node_error(ids, "identifier \"%s\" not defined", ids->nd_IDF->id_text); } if (df->df_flags & (D_EXPORTED|D_QEXPORTED)) { -node_error(ids, "Identifier \"%s\" occurs more than once in export list", +node_error(ids, "identifier \"%s\" occurs more than once in export list", df->df_idf->id_text); } @@ -225,6 +246,8 @@ df->df_idf->id_text); Find all imports of the module in which this export occurs, and export the current definition to it */ + df->df_flags |= D_EXPORTED; + impmod = moddef->df_idf->id_def; while (impmod) { if (impmod->df_kind == D_IMPORT && @@ -234,7 +257,6 @@ df->df_idf->id_text); impmod = impmod->next; } - df->df_flags |= D_EXPORTED; df1 = lookup(ids->nd_IDF, enclosing(CurrVis)->sc_scope); if (df1 && df1->df_kind == D_PROCHEAD) { if (df->df_kind == D_PROCEDURE) { @@ -255,10 +277,6 @@ error("opaque type \"%s\" is not a pointer type", df->df_idf->id_text); } } - df1 = define(ids->nd_IDF, - enclosing(CurrVis)->sc_scope, - D_IMPORT); - df1->imp_def = df; DoImport(df, enclosing(CurrVis)->sc_scope); } } @@ -283,7 +301,7 @@ ForwModule(df, idn) closing this one */ df->for_vis = vis; - df->for_node = MkNode(Name, NULLNODE, NULLNODE, &(idn->nd_token)); + df->for_node = MkLeaf(Name, &(idn->nd_token)); close_scope(0); vis->sc_encl = enclosing(CurrVis); /* Here ! */ @@ -302,7 +320,7 @@ ForwDef(ids, scope) if (!(df = lookup(ids->nd_IDF, scope))) { df = define(ids->nd_IDF, scope, D_FORWARD); - df->for_node = MkNode(Name,NULLNODE,NULLNODE,&(ids->nd_token)); + df->for_node = MkLeaf(Name, &(ids->nd_token)); } return df; } @@ -384,7 +402,6 @@ ids->nd_IDF->id_text); else df = GetDefinitionModule(ids->nd_IDF); } - define(ids->nd_IDF,CurrentScope,D_IMPORT)->imp_def = df; DoImport(df, CurrentScope); ids = ids->next; @@ -393,7 +410,7 @@ ids->nd_IDF->id_text); FreeNode(idn); } -RemImports(pdf) +RemoveImports(pdf) struct def **pdf; { /* Remove all imports from a definition module. This is @@ -404,7 +421,7 @@ RemImports(pdf) while (df) { if (df->df_kind == D_IMPORT) { - RemFromId(df); + RemoveFromIdList(df); *pdf = df->df_nextinscope; free_def(df); } @@ -415,7 +432,7 @@ RemImports(pdf) } } -RemFromId(df) +RemoveFromIdList(df) struct def *df; { /* Remove definition "df" from the definition list @@ -438,11 +455,11 @@ struct def * DeclProc(type) { /* A procedure is declared, either in a definition or a program - module. Create a def structure for it (if neccessary) + module. Create a def structure for it (if neccessary). + Also create a name for it. */ register struct def *df; static int nmcount = 0; - extern char *Malloc(); extern char *strcpy(); extern char *sprint(); char buf[256]; @@ -453,7 +470,7 @@ DeclProc(type) /* In a definition module */ df = define(dot.TOK_IDF, CurrentScope, type); - df->for_node = MkNode(Name, NULLNODE, NULLNODE, &dot); + df->for_node = MkLeaf(Name, &dot); sprint(buf,"%s_%s",CurrentScope->sc_name,df->df_idf->id_text); df->for_name = Malloc((unsigned) (strlen(buf)+1)); strcpy(df->for_name, buf); @@ -512,12 +529,12 @@ AddModule(id) register struct node *n; extern struct node *Modules; - n = MkNode(Name, NULLNODE, NULLNODE, &dot); + n = MkLeaf(Name, &dot); n->nd_IDF = id; n->nd_symb = IDENT; if (nd_end) nd_end->next = n; + else Modules = n; nd_end = n; - if (!Modules) Modules = n; } DefInFront(df) @@ -528,14 +545,24 @@ DefInFront(df) This is neccessary because in some cases the order in this list is important. */ - register struct def *df1; + register struct def *df1 = df->df_scope->sc_def; - if (df->df_scope->sc_def != df) { - df1 = df->df_scope->sc_def; + if (df1 != df) { + /* Definition "df" is not in front of the list + */ while (df1 && df1->df_nextinscope != df) { + /* Find definition "df" + */ df1 = df1->df_nextinscope; } - if (df1) df1->df_nextinscope = df->df_nextinscope; + if (df1) { + /* It already was in the list. Remove it + */ + df1->df_nextinscope = df->df_nextinscope; + } + + /* Now put it in front + */ df->df_nextinscope = df->df_scope->sc_def; df->df_scope->sc_def = df; } diff --git a/lang/m2/comp/desig.c b/lang/m2/comp/desig.c index 04f2fd8b..47780bfc 100644 --- a/lang/m2/comp/desig.c +++ b/lang/m2/comp/desig.c @@ -268,7 +268,8 @@ CodeVarDesig(df, ds) /* value or var parameter */ C_lxa((arith) (proclevel - sc->sc_level)); - if (df->df_flags & D_VARPAR) { + if ((df->df_flags & D_VARPAR) || + IsConformantArray(df->df_type)) { /* var parameter */ C_adp(df->var_off); @@ -287,7 +288,7 @@ CodeVarDesig(df, ds) /* Now, finally, we have a local variable or a local parameter */ - if (df->df_flags & D_VARPAR) { + if ((df->df_flags & D_VARPAR) || IsConformantArray(df->df_type)) { /* a var parameter; address directly accessible. */ ds->dsg_kind = DSG_PFIXED; @@ -303,10 +304,11 @@ CodeDesig(nd, ds) /* Generate code for a designator. Use divide and conquer principle */ + register struct def *df; switch(nd->nd_class) { /* Divide */ - case Def: { - register struct def *df = nd->nd_def; + case Def: + df = nd->nd_def; df->df_flags |= D_USED; switch(df->df_kind) { @@ -321,7 +323,6 @@ CodeDesig(nd, ds) default: crash("(CodeDesig) Def"); } - } break; case Link: @@ -336,18 +337,24 @@ CodeDesig(nd, ds) CodeDesig(nd->nd_left, ds); CodeAddress(ds); - *ds = InitDesig; - CodeExpr(nd->nd_right, ds, NO_LABEL, NO_LABEL); - CodeValue(ds, nd->nd_right->nd_type->tp_size); + CodePExpr(nd->nd_right); if (nd->nd_right->nd_type->tp_size > word_size) { CodeCoercion(nd->nd_right->nd_type, int_type); } + + /* Now load address of descriptor + */ if (IsConformantArray(nd->nd_left->nd_type)) { - /* ??? */ + assert(nd->nd_left->nd_class == Def); + + df = nd->nd_left->nd_def; + if (proclevel > df->df_scope->sc_level) { + C_lxa(proclevel - df->df_scope->sc_level); + C_adp(df->var_off + pointer_size); + } + else C_lal(df->var_off + pointer_size); } else { - /* load address of descriptor - */ C_lae_dlb(nd->nd_left->nd_type->arr_descr, (arith) 0); } ds->dsg_kind = DSG_INDEXED; diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index f0c144e6..80a75780 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -26,48 +26,51 @@ number(struct node **p;) } : [ %default - INTEGER { tp = numtype; } + INTEGER { tp = toktype; } | REAL { tp = real_type; } -] { *p = MkNode(Value, NULLNODE, NULLNODE, &dot); +] { *p = MkLeaf(Value, &dot); (*p)->nd_type = tp; } ; -qualident(int types; struct def **pdf; char *str; struct node **p;) +qualident(int types; + struct def **pdf; + char *str; + struct node **p; + ) { register struct def *df; struct node *nd; } : - IDENT { nd = MkNode(Name, NULLNODE, NULLNODE, &dot); - } + IDENT { nd = MkLeaf(Name, &dot); } [ selector(&nd) ]* - { if (types) { - df = ill_df; + { if (types) { + df = ill_df; - if (chk_designator(nd, 0, D_REFERRED)) { - if (nd->nd_class != Def) { - node_error(nd, "%s expected", str); + if (chk_designator(nd, 0, D_REFERRED)) { + if (nd->nd_class != Def) { + node_error(nd, "%s expected", str); + } + else { + df = nd->nd_def; + if ( !((types|D_ERROR) & df->df_kind)) { + if (df->df_kind == D_FORWARD) { +node_error(nd,"%s \"%s\" not declared", str, df->df_idf->id_text); } else { - df = nd->nd_def; - if ( !((types|D_ERROR) & df->df_kind)) { - if (df->df_kind == D_FORWARD) { -node_error(nd,"%s \"%s\" not declared", str, df->df_idf->id_text); - } - else { node_error(nd,"identifier \"%s\" is not a %s", df->df_idf->id_text, str); - } - } } } - *pdf = df; - } - if (!p) FreeNode(nd); - else *p = nd; + } } + *pdf = df; + } + if (!p) FreeNode(nd); + else *p = nd; + } ; selector(struct node **pnd;): @@ -84,7 +87,7 @@ ExpList(struct node **pnd;) nd = &((*pnd)->nd_right); } [ - ',' { *nd = MkNode(Link, NULLNODE, NULLNODE, &dot); + ',' { *nd = MkLeaf(Link, &dot); } expression(&(*nd)->nd_left) { nd = &((*nd)->nd_right); } @@ -131,7 +134,7 @@ SimpleExpression(struct node **pnd;) } : [ [ '+' | '-' ] - { *pnd = MkNode(Uoper, NULLNODE, NULLNODE, &dot); + { *pnd = MkLeaf(Uoper, &dot); pnd = &((*pnd)->nd_right); } ]? @@ -191,23 +194,13 @@ factor(struct node **p;) number(p) | STRING { - *p = MkNode(Value, NULLNODE, NULLNODE, &dot); - if (dot.TOK_SLE == 1) { - int i; - - tp = charc_type; - i = *(dot.TOK_STR) & 0377; - free(dot.TOK_STR); - free((char *) dot.tk_data.tk_str); - (*p)->nd_INT = i; - } - else tp = standard_type(T_STRING, 1, dot.TOK_SLE); - (*p)->nd_type = tp; + *p = MkLeaf(Value, &dot); + (*p)->nd_type = toktype; } | '(' expression(p) ')' | - NOT { *p = MkNode(Uoper, NULLNODE, NULLNODE, &dot); } + NOT { *p = MkLeaf(Uoper, &dot); } factor(&((*p)->nd_right)) ; @@ -217,7 +210,7 @@ bare_set(struct node **pnd;) } : '{' { dot.tk_symb = SET; - *pnd = nd = MkNode(Xset, NULLNODE, NULLNODE, &dot); + *pnd = nd = MkLeaf(Xset, &dot); nd->nd_type = bitset_type; } [ diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index 53d0a92e..1372165b 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -111,27 +111,27 @@ Compile(src, dst) #ifdef DEBUG LexScan() { - register int symb; - char *symbol2str(); + register struct token *tkp = ˙ + extern char *symbol2str(); - while ((symb = LLlex()) > 0) { - print(">>> %s ", symbol2str(symb)); - switch(symb) { + while (LLlex() > 0) { + print(">>> %s ", symbol2str(tkp->tk_symb)); + switch(tkp->tk_symb) { case IDENT: - print("%s\n", dot.TOK_IDF->id_text); + print("%s\n", tkp->TOK_IDF->id_text); break; case INTEGER: - print("%ld\n", dot.TOK_INT); + print("%ld\n", tkp->TOK_INT); break; case REAL: - print("%s\n", dot.TOK_REL); + print("%s\n", tkp->TOK_REL); break; - + case STRING: - print("\"%s\"\n", dot.TOK_STR); + print("\"%s\"\n", tkp->TOK_STR); break; default: diff --git a/lang/m2/comp/node.H b/lang/m2/comp/node.H index db0467a8..dfbe94fe 100644 --- a/lang/m2/comp/node.H +++ b/lang/m2/comp/node.H @@ -33,7 +33,7 @@ struct node { /* ALLOCDEF "node" */ -extern struct node *MkNode(); +extern struct node *MkNode(), *MkLeaf(); #define NULLNODE ((struct node *) 0) diff --git a/lang/m2/comp/node.c b/lang/m2/comp/node.c index b1556d14..c940e427 100644 --- a/lang/m2/comp/node.c +++ b/lang/m2/comp/node.c @@ -39,6 +39,19 @@ MkNode(class, left, right, token) return nd; } +struct node * +MkLeaf(class, token) + struct token *token; +{ + register struct node *nd = new_node(); + + nd->nd_left = nd->nd_right = 0; + nd->nd_token = *token; + nd->nd_type = error_type; + nd->nd_class = class; + return nd; +} + FreeNode(nd) register struct node *nd; { diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index ac0d4854..cbf86b8a 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -19,11 +19,6 @@ static char *RcsId = "$Header$"; #include "type.h" #include "node.h" -static int DEFofIMPL = 0; /* Flag indicating that we are currently - parsing the definition module of the - implementation module currently being - compiled - */ } /* The grammar as given by Wirth is already almost LL(1); the @@ -132,7 +127,7 @@ import(int local;) struct node *id = 0; } : [ FROM - IDENT { id = MkNode(Value, NULLNODE, NULLNODE, &dot); } + IDENT { id = MkLeaf(Value, &dot); } ]? IMPORT IdentList(&ImportList) ';' /* @@ -176,12 +171,6 @@ DefinitionModule */ definition* END IDENT { - if (DEFofIMPL) { - /* Just read the definition module of the - implementation module being compiled - */ - RemImports(&(CurrentScope->sc_def)); - } df = CurrentScope->sc_def; while (df) { /* Make all definitions "QUALIFIED EXPORT" */ @@ -211,7 +200,7 @@ definition It is restricted to pointer types. */ { df->df_kind = D_HIDDEN; - df->df_type = construct_type(T_POINTER, NULLTYPE); + df->df_type = construct_type(T_HIDDEN, NULLTYPE); } ] Semicolon @@ -239,11 +228,10 @@ ProgramModule IDENT { id = dot.TOK_IDF; if (state == IMPLEMENTATION) { - DEFofIMPL = 1; df = GetDefinitionModule(id); CurrVis = df->mod_vis; CurrentScope = CurrVis->sc_scope; - DEFofIMPL = 0; + RemoveImports(&(CurrentScope->sc_def)); } else { df = define(id, CurrentScope, D_MODULE); diff --git a/lang/m2/comp/statement.g b/lang/m2/comp/statement.g index b0a05b20..aef6e22c 100644 --- a/lang/m2/comp/statement.g +++ b/lang/m2/comp/statement.g @@ -18,11 +18,10 @@ static char *RcsId = "$Header$"; static int loopcount = 0; /* Count nested loops */ } -statement(struct node **pnd;) +statement(register struct node **pnd;) { register struct node *nd; } : - { *pnd = 0; } [ /* * This part is not in the reference grammar. The reference grammar @@ -61,11 +60,13 @@ statement(struct node **pnd;) | EXIT { if (!loopcount) error("EXIT not in a LOOP"); - *pnd = MkNode(Stat, NULLNODE, NULLNODE, &dot); + *pnd = MkLeaf(Stat, &dot); } | ReturnStatement(pnd) -]? +| + /* empty */ { *pnd = 0; } +] ; /* @@ -80,7 +81,9 @@ ProcedureCall: ; */ -StatementSequence(struct node **pnd;): +StatementSequence(register struct node **pnd;) +{ +} : statement(pnd) [ ';' { *pnd = MkNode(Link, *pnd, NULLNODE, &dot); @@ -94,21 +97,21 @@ IfStatement(struct node **pnd;) { register struct node *nd; } : - IF { nd = MkNode(Stat, NULLNODE, NULLNODE, &dot); + IF { nd = MkLeaf(Stat, &dot); *pnd = nd; } expression(&(nd->nd_left)) - THEN { nd = MkNode(Link, NULLNODE, NULLNODE, &dot); - (*pnd)->nd_right = nd; + THEN { nd->nd_right = MkLeaf(Link, &dot); + nd = nd->nd_right; } StatementSequence(&(nd->nd_left)) [ - ELSIF { nd->nd_right = MkNode(Stat,NULLNODE,NULLNODE,&dot); + ELSIF { nd->nd_right = MkLeaf(Stat, &dot); nd = nd->nd_right; nd->nd_symb = IF; } expression(&(nd->nd_left)) - THEN { nd->nd_right = MkNode(Link,NULLNODE,NULLNODE,&dot); + THEN { nd->nd_right = MkLeaf(Link, &dot); nd = nd->nd_right; } StatementSequence(&(nd->nd_left)) @@ -125,7 +128,7 @@ CaseStatement(struct node **pnd;) register struct node *nd; struct type *tp = 0; } : - CASE { *pnd = nd = MkNode(Stat, NULLNODE, NULLNODE, &dot); } + CASE { *pnd = nd = MkLeaf(Stat, &dot); } expression(&(nd->nd_left)) OF case(&(nd->nd_right), &tp) @@ -140,12 +143,10 @@ CaseStatement(struct node **pnd;) ; case(struct node **pnd; struct type **ptp;) : - { *pnd = 0; } [ CaseLabelList(ptp, pnd) ':' { *pnd = MkNode(Link, *pnd, NULLNODE, &dot); } StatementSequence(&((*pnd)->nd_right)) ]? - /* This rule is changed in new modula-2 */ { *pnd = MkNode(Link, *pnd, NULLNODE, &dot); (*pnd)->nd_symb = '|'; } @@ -155,7 +156,7 @@ WhileStatement(struct node **pnd;) { register struct node *nd; }: - WHILE { *pnd = nd = MkNode(Stat, NULLNODE, NULLNODE, &dot); } + WHILE { *pnd = nd = MkLeaf(Stat, &dot); } expression(&(nd->nd_left)) DO StatementSequence(&(nd->nd_right)) @@ -166,7 +167,7 @@ RepeatStatement(struct node **pnd;) { register struct node *nd; }: - REPEAT { *pnd = nd = MkNode(Stat, NULLNODE, NULLNODE, &dot); } + REPEAT { *pnd = nd = MkLeaf(Stat, &dot); } StatementSequence(&(nd->nd_left)) UNTIL expression(&(nd->nd_right)) @@ -177,10 +178,10 @@ ForStatement(struct node **pnd;) register struct node *nd; struct node *dummy; }: - FOR { *pnd = MkNode(Stat, NULLNODE, NULLNODE, &dot); } - IDENT { (*pnd)->nd_IDF = dot.TOK_IDF; } - BECOMES { nd = MkNode(Stat, NULLNODE, NULLNODE, &dot); - (*pnd)->nd_left = nd; + FOR { *pnd = nd = MkLeaf(Stat, &dot); } + IDENT { nd->nd_IDF = dot.TOK_IDF; } + BECOMES { nd->nd_left = MkLeaf(Stat, &dot); + nd = nd->nd_left; } expression(&(nd->nd_left)) TO @@ -204,7 +205,7 @@ ForStatement(struct node **pnd;) ; LoopStatement(struct node **pnd;): - LOOP { *pnd = MkNode(Stat, NULLNODE, NULLNODE, &dot); } + LOOP { *pnd = MkLeaf(Stat, &dot); } StatementSequence(&((*pnd)->nd_right)) END ; @@ -213,7 +214,7 @@ WithStatement(struct node **pnd;) { register struct node *nd; }: - WITH { *pnd = nd = MkNode(Stat, NULLNODE, NULLNODE, &dot); } + WITH { *pnd = nd = MkLeaf(Stat, &dot); } designator(&(nd->nd_left)) DO StatementSequence(&(nd->nd_right)) @@ -226,7 +227,7 @@ ReturnStatement(struct node **pnd;) register struct node *nd; } : - RETURN { *pnd = nd = MkNode(Stat, NULLNODE, NULLNODE, &dot); } + RETURN { *pnd = nd = MkLeaf(Stat, &dot); } [ expression(&(nd->nd_right)) { if (scopeclosed(CurrentScope)) { diff --git a/lang/m2/comp/type.H b/lang/m2/comp/type.H index 958a76e7..010b9e04 100644 --- a/lang/m2/comp/type.H +++ b/lang/m2/comp/type.H @@ -21,18 +21,20 @@ struct enume { }; struct subrange { - arith su_lb, su_ub; /* Lower bound and upper bound */ - label su_rck; /* Label of range check descriptor */ + arith su_lb, su_ub; /* lower bound and upper bound */ + label su_rck; /* label of range check descriptor */ #define sub_lb tp_value.tp_subrange.su_lb #define sub_ub tp_value.tp_subrange.su_ub #define sub_rck tp_value.tp_subrange.su_rck }; struct array { - struct type *ar_elem; /* Type of elements */ - label ar_descr; /* Label of array descriptor */ + struct type *ar_elem; /* type of elements */ + label ar_descr; /* label of array descriptor */ + arith ar_elsize; /* size of elements */ #define arr_elem tp_value.tp_arr.ar_elem #define arr_descr tp_value.tp_arr.ar_descr +#define arr_elsize tp_value.tp_arr.ar_elsize }; struct record { @@ -59,7 +61,7 @@ struct type { #define T_CARDINAL 0x0008 /* #define T_LONGINT 0x0010 */ #define T_REAL 0x0020 -/* #define T_LONGREAL 0x0040 */ +#define T_HIDDEN 0x0040 #define T_POINTER 0x0080 #define T_CHAR 0x0100 #define T_WORD 0x0200 @@ -89,7 +91,6 @@ struct type { extern struct type *bool_type, *char_type, - *charc_type, *int_type, *card_type, *longint_type, @@ -132,7 +133,7 @@ struct type #define NULLTYPE ((struct type *) 0) -#define IsConformantArray(tpx) ((tpx)->tp_fund == T_ARRAY && (tpx)->next == 0) +#define IsConformantArray(tpx) ((tpx)->tp_fund==T_ARRAY && (tpx)->next==0) #define bounded(tpx) ((tpx)->tp_fund & T_INDEX) #define complex(tpx) ((tpx)->tp_fund & (T_RECORD|T_ARRAY)) #define returntype(tpx) (((tpx)->tp_fund & T_PRCRESULT) ||\ diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index 9319f9d9..974c8669 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -45,7 +45,6 @@ arith struct type *bool_type, *char_type, - *charc_type, *int_type, *card_type, *longint_type, @@ -72,7 +71,7 @@ extern label data_label(); struct type * create_type(fund) - register int fund; + int fund; { /* A brand new struct type is created, and its tp_fund set to fund. @@ -81,29 +80,29 @@ create_type(fund) clear((char *)ntp, sizeof(struct type)); ntp->tp_fund = fund; - ntp->tp_size = (arith)-1; return ntp; } struct type * construct_type(fund, tp) - struct type *tp; + int fund; + register struct type *tp; { /* fund must be a type constructor. The pointer to the constructed type is returned. */ - struct type *dtp = create_type(fund); + register struct type *dtp = create_type(fund); switch (fund) { case T_PROCEDURE: case T_POINTER: + case T_HIDDEN: dtp->tp_align = pointer_align; dtp->tp_size = pointer_size; dtp->next = tp; if (fund == T_PROCEDURE && tp) { - if (tp != bitset_type && - !(tp->tp_fund&(T_NUMERIC|T_INDEX|T_WORD|T_POINTER))) { + if (! returntype(tp)) { error("illegal procedure result type"); } } @@ -142,7 +141,9 @@ align(pos, al) struct type * standard_type(fund, align, size) - int align; arith size; + int fund; + int align; + arith size; { register struct type *tp = create_type(fund); @@ -161,15 +162,19 @@ init_types() /* first, do some checking */ if (int_size != word_size) { - fatal("Integer size not equal to word size"); + fatal("integer size not equal to word size"); } - if (long_size < int_size) { - fatal("Long integer size smaller than integer size"); + if (long_size < int_size || long_size % word_size != 0) { + fatal("illegal long integer size"); } if (double_size < float_size) { - fatal("Long real size smaller than real size"); + fatal("long real size smaller than real size"); + } + + if (!pointer_size || pointer_size % word_size != 0) { + fatal("illegal pointer size"); } /* character type @@ -177,12 +182,6 @@ init_types() char_type = standard_type(T_CHAR, 1, (arith) 1); char_type->enm_ncst = 256; - /* character constant type, different from character type because - of compatibility with character array's - */ - charc_type = standard_type(T_CHAR, 1, (arith) 1); - charc_type->enm_ncst = 256; - /* boolean type */ bool_type = standard_type(T_ENUMERATION, 1, (arith) 1); @@ -226,28 +225,36 @@ ParamList(ppr, ids, tp, VARp, off) register struct node *ids; struct paramlist **ppr; struct type *tp; + int VARp; arith *off; { /* Create (part of) a parameterlist of a procedure. "ids" indicates the list of identifiers, "tp" their type, and - "VARp" is set when the parameters are VAR-parameters. -*/ + "VARp" indicates D_VARPAR or D_VALPAR. + */ register struct paramlist *pr; register struct def *df; - struct paramlist *pstart; - while (ids) { + for ( ; ids; ids = ids->next) { pr = new_paramlist(); pr->next = *ppr; *ppr = pr; df = define(ids->nd_IDF, CurrentScope, D_VARIABLE); pr->par_def = df; df->df_type = tp; - if (VARp) df->df_flags = D_VARPAR; - else df->df_flags = D_VALPAR; df->var_off = align(*off, word_align); - *off = df->var_off + tp->tp_size; - ids = ids->next; + df->df_flags = VARp; + if (IsConformantArray(tp)) { + /* we need room for the base address and a descriptor + */ + *off = df->var_off + pointer_size + 3 * word_size; + } + else if (VARp == D_VARPAR) { + *off = df->var_off + pointer_size; + } + else { + *off = df->var_off + tp->tp_size; + } } } @@ -267,7 +274,7 @@ chk_basesubrange(tp, base) base = base->next; } - if (base->tp_fund == T_ENUMERATION || base->tp_fund == T_CHAR) { + if (base->tp_fund & (T_ENUMERATION|T_CHAR)) { if (tp->next != base) { error("Specified base does not conform"); } @@ -384,7 +391,7 @@ getbounds(tp, plo, phi) } struct type * set_type(tp) - struct type *tp; + register struct type *tp; { /* Construct a set type with base type "tp", but first perform some checks @@ -414,22 +421,33 @@ set_type(tp) return tp; } +arith +ArrayElSize(tp) + register struct type *tp; +{ + /* Align element size to alignment requirement of element type. + Also make sure that its size is either a dividor of the word_size, + or a multiple of it. + */ + arith algn; + + if (tp->tp_fund == T_ARRAY) ArraySizes(tp); + algn = align(tp->tp_size, tp->tp_align); + if (!(algn % word_size == 0 || word_size % algn == 0)) { + algn = align(algn, word_size); + } + return algn; +} + ArraySizes(tp) register struct type *tp; { /* Assign sizes to an array type, and check index type */ - arith elem_size; register struct type *index_type = tp->next; register struct type *elem_type = tp->arr_elem; - if (elem_type->tp_fund == T_ARRAY) { - ArraySizes(elem_type); - } - - /* align element size to alignment requirement of element type - */ - elem_size = align(elem_type->tp_size, elem_type->tp_align); + tp->arr_elsize = ArrayElSize(elem_type); tp->tp_align = elem_type->tp_align; /* check index type @@ -447,7 +465,7 @@ ArraySizes(tp) switch(index_type->tp_fund) { case T_SUBRANGE: - tp->tp_size = elem_size * + tp->tp_size = tp->arr_elsize * (index_type->sub_ub - index_type->sub_lb + 1); C_rom_cst(index_type->sub_lb); C_rom_cst(index_type->sub_ub - index_type->sub_lb); @@ -455,7 +473,7 @@ ArraySizes(tp) case T_CHAR: case T_ENUMERATION: - tp->tp_size = elem_size * index_type->enm_ncst; + tp->tp_size = tp->arr_elsize * index_type->enm_ncst; C_rom_cst((arith) 0); C_rom_cst((arith) (index_type->enm_ncst - 1)); break; @@ -464,7 +482,7 @@ ArraySizes(tp) crash("Funny index type"); } - C_rom_cst(elem_size); + C_rom_cst(tp->arr_elsize); /* ??? overflow checking ??? */ @@ -473,7 +491,9 @@ ArraySizes(tp) FreeType(tp) struct type *tp; { - /* Release type structures indicated by "tp" + /* Release type structures indicated by "tp". + This procedure is only called for types, constructed with + T_PROCEDURE. */ register struct paramlist *pr, *pr1; diff --git a/lang/m2/comp/typequiv.c b/lang/m2/comp/typequiv.c index b46971bc..aa223409 100644 --- a/lang/m2/comp/typequiv.c +++ b/lang/m2/comp/typequiv.c @@ -105,10 +105,6 @@ TstCompat(tp1, tp2) && (tp1 == int_type || tp1 == card_type) ) - || - (tp1 == char_type && tp2 == charc_type) - || - (tp2 == char_type && tp1 == charc_type) || ( tp1 == address_type && @@ -145,8 +141,6 @@ TstAssCompat(tp1, tp2) if ((tp1->tp_fund & T_INTORCARD) && (tp2->tp_fund & T_INTORCARD)) return 1; - if (tp1 == char_type && tp2 == charc_type) return 1; - if (tp1->tp_fund == T_ARRAY) { /* check for string */ @@ -162,12 +156,8 @@ TstAssCompat(tp1, tp2) if (tp1->tp_fund == T_SUBRANGE) tp1 = tp1->next; return tp1 == char_type - && - ( - tp2 == charc_type - || - (tp2->tp_fund == T_STRING && size >= tp2->tp_size) - ); + && (tp2->tp_fund == T_STRING && size >= tp2->tp_size) + ; } return 0; diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index 578cc67c..eb655e67 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -25,7 +25,6 @@ static char *RcsId = "$Header$"; #include "f_info.h" #include "idf.h" -extern arith align(); extern arith NewPtr(); extern arith NewInt(); extern int proclevel; @@ -58,7 +57,7 @@ DoProfil() if (!filename_label) { filename_label = data_label(); C_df_dlb(filename_label); - C_rom_scon(FileName, (arith) strlen(FileName)); + C_rom_scon(FileName, (arith) (strlen(FileName) + 1)); } C_fil_dlb(filename_label, (arith) 0); @@ -131,20 +130,22 @@ WalkModule(module) Call initialization routines of imported modules. Also prevent recursive calls of this one. */ - label l1 = data_label(), l2 = text_label(); struct node *nd; - /* we don't actually prevent recursive calls, but do nothing - if called recursively - */ - C_df_dlb(l1); - C_bss_cst(word_size, (arith) 0, 1); - C_loe_dlb(l1, (arith) 0); - C_zeq(l2); - C_ret((arith) 0); - C_df_ilb(l2); - C_loc((arith) 1); - C_ste_dlb(l1, (arith) 0); + if (state == IMPLEMENTATION) { + label l1 = data_label(), l2 = text_label(); + /* we don't actually prevent recursive calls, + but do nothing if called recursively + */ + C_df_dlb(l1); + C_bss_cst(word_size, (arith) 0, 1); + C_loe_dlb(l1, (arith) 0); + C_zeq(l2); + C_ret((arith) 0); + C_df_ilb(l2); + C_loc((arith) 1); + C_ste_dlb(l1, (arith) 0); + } nd = Modules; while (nd) { @@ -278,7 +279,7 @@ WalkStat(nd, lab) return; } - if (options['L']) C_lin((arith) nd->nd_lineno); + if (! options['L']) C_lin((arith) nd->nd_lineno); if (nd->nd_class == Call) { if (chk_call(nd)) { @@ -541,8 +542,11 @@ DoAssign(nd, left, right) /* May we do it in this order (expression first) ??? */ struct desig ds; - WalkExpr(right, NO_LABEL, NO_LABEL); + if (!chk_expr(right)) return; if (! chk_designator(left, DESIGNATOR|VARIABLE, D_DEFINED)) return; + TryToString(right, left->nd_type); + Desig = InitDesig; + CodeExpr(right, &Desig, NO_LABEL, NO_LABEL); if (! TstAssCompat(left->nd_type, right->nd_type)) { node_error(nd, "type incompatibility in assignment"); From 72a234b9bd055294b1cd4256f49f94b3dbf45a81 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 5 Jun 1986 12:43:56 +0000 Subject: [PATCH 0201/1625] Rediscovered a bug in the VAX 4.1 UNIX assembler. It handles $0f0.0 wrong! The changes is the table insure that $0f0.0 is never generated. --- mach/vax4/cg/table | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/mach/vax4/cg/table b/mach/vax4/cg/table index 85254053..941cf0cf 100644 --- a/mach/vax4/cg/table +++ b/mach/vax4/cg/table @@ -77,6 +77,7 @@ CONST1 = {INT num;} 4 cost=(4,3) "$%[num]" CONST2 = {INT num;} 4 cost=(4,3) "$%[num]" CONST4 = {INT num;} 4 cost=(4,3) "$%[num]" CONST8 = {STRING ind;} 8 cost=(8,6) "$%[ind]" +FCONST4 = {INT num;} 4 cost=(4,3) "$0f%[num].0" FCONST8 = {INT num;} 8 cost=(8,6) "$0f%[num].0" LOCAL1 = {REGISTER reg; INT num,size;} 4 cost=(2,6) "%[num](%[reg])" LOCAL2 = {REGISTER reg; INT num,size;} 4 cost=(2,6) "%[num](%[reg])" @@ -182,7 +183,7 @@ source2 = regdef2 + displ2 + displdef2 + + reginc2 + regdec2 #endif REGVARS source4 = REG + regdef4 + displ4 + displdef4 + LocaLBase + - EXTERNAL4 + reldef4 + CONST + DOUBLE + LOCAL4 + EXTERNAL4 + reldef4 + CONST + DOUBLE + LOCAL4 + FCONST4 + extind4 + displind4 + extdefind4 + displdefind4 #ifdef REGVARS + RREG + reginc4 + regdec4 @@ -191,7 +192,7 @@ dups4 = CONST + regdef1 + displ1 + LOCAL1 + REG + regdef2 + displ2 + LOCAL2 + RREG + regdef4 + displ4 + LOCAL4 + DOUBLE source8 = QREG + regdef8 + displ8 + displdef8 + - EXTERNAL8 + reldef8 + CONST8 + LOCAL8 + EXTERNAL8 + reldef8 + CONST8 + LOCAL8 + FCONST8 + extind8 + displind8 + extdefind8 + displdefind8 #ifdef REGVARS + reginc8 + regdec8 @@ -244,7 +245,7 @@ reg8 = QREG sreg4 = REG * SCRATCH sreg8 = QREG * SCRATCH bigsource4 = source1or2or4 + nonexist -bigsource8 = source8 + FCONST8 +bigsource8 = source8 all = bigsource4 + bigsource8 scr = ALL - (EXTERNALS + LOCALS + ADDR_LOCAL + ADDR_EXTERNAL + CONST + DOUBLE) @@ -264,7 +265,6 @@ CODE: loc $1>=0 && $1<256 | | | {CONST1,$1} | | loc $1>=256 && $1<65536 | | | {CONST2,$1} | | loc | | | {CONST4,$1} | | -loc loc $1==0 && $2==0 | | | {FCONST8,0} | | ldc | | | {CONST8,$1} | | #ifdef REGVARS lol inreg($1)==2 | | | regvar($1) | | @@ -1986,9 +1986,14 @@ zrl zrl $1==$2-4 | | | | zrl $2 zrl $1 | zre | | remove(externals) "clrl\t$1" setcc({EXTERNAL4,$1}) | | | -zrf $1==4 | | | {CONST4,0} | | -zrf $1==8 | | | {FCONST8,0} | | -zer $1==4 | | | {CONST4,0} | | +/* Avoid a bug in the VAX assembler, that handles $0f0.0 wrong. + So, do NOT create {FCONST[4|8], 0}! +*/ +zrf $1==4 | | allocate(REG) + "clrl\t%[a]" | %[a] | | +zrf $1==8 | | allocate(QREG) + "clrq\t%[a]" | %[a] | | +zer $1==4 | | | {CONST4,0} | | zer $1==8 | | allocate(QREG) "clrq\t%[a]" | %[a] | | zer $1<=32 | STACK | @@ -2183,6 +2188,8 @@ loc loc cif stl $1==4 && $2==4 && $4>=0 loc loc cif ste $1==4 && $2==4 | source4 | remove(externals) "cvtlf\t%[1],$4" | | | +loc loc loc cif $1!=0 && $2==4 && $3==4 | | | {FCONST4, $1} | | +/* $1 != 0: kludge to avoid bug in VAX assembler */ #endif FLOAT4 loc loc cif $1==4 && $2==4 | source4 | allocate(%[1],REG) @@ -4520,6 +4527,10 @@ MOVES: setcc(%[2]), (2,4)+%[2]) (CONST8 %[ind]=="0",source8, "clrq\t%[2]" setcc(%[2]), (2,4)+%[2]) +(FCONST4 %[num]==0,source4, "clrl\t%[2]" + setcc(%[2]), (2,4)+%[2]) +(FCONST4,source4, "movl\t%[1],%[2]" + setcc(%[2]), (3,4)+%[1]+%[2]) (FCONST8 %[num]==0,source8, "clrq\t%[2]" setcc(%[2]), (2,4)+%[2]) (FCONST8,source8, "movd\t%[1],%[2]" @@ -4592,6 +4603,7 @@ STACKS: (source8,, "movq\t%[1],-(sp)" setcc(%[1]), (3,10)+ %[1]) (nonexist1,, "pushal\t%[1]", (2,7) + %[1]) +(FCONST4,, "pushl\t%[1]", (2,7) + %[1]) (FCONST8 %[num]==0,, "clrq\t-(sp)", (2,10)) (FCONST8,, "movd\t%[1],-(sp)", (3,10) + %[1]) From 49287324b3014e056bc18dbd85ce56aba227954d Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 5 Jun 1986 13:56:31 +0000 Subject: [PATCH 0202/1625] Increased the size of the expression node table. --- util/cgg/bootgram.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/cgg/bootgram.y b/util/cgg/bootgram.y index d2f72018..4e9bff12 100644 --- a/util/cgg/bootgram.y +++ b/util/cgg/bootgram.y @@ -44,7 +44,7 @@ static char rcsid[]="$Header$"; #define MAXINSTANCE BORS(250,120) /* Maximum number of different tokeninstances */ #define MAXSTRINGS BORS(800,400)/* Maximum number of different codestrings */ #define MAXPATTERN BORS(8000,6000) /* Maximum number of bytes in pattern[] */ -#define MAXNODES BORS(450,400) /* Maximum number of expression nodes */ +#define MAXNODES BORS(500,400) /* Maximum number of expression nodes */ #define MAXMEMBERS 2 /* Maximum number of subregisters per reg */ #define NMOVES BORS(50,30) /* Maximum number of move definitions */ #define MAXC1 20 /* Maximum of coercions type 1 */ From 702c0bd19ad02b83efe5df09d27f094f5e7ee9f1 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 6 Jun 1986 02:22:09 +0000 Subject: [PATCH 0203/1625] newer version --- lang/m2/comp/LLlex.c | 18 +-- lang/m2/comp/chk_expr.c | 239 +++++++++++++++++--------------------- lang/m2/comp/code.c | 71 ++++++----- lang/m2/comp/cstoper.c | 6 + lang/m2/comp/declar.g | 20 ++-- lang/m2/comp/def.c | 20 ++-- lang/m2/comp/defmodule.c | 16 +-- lang/m2/comp/desig.c | 15 +-- lang/m2/comp/enter.c | 16 +-- lang/m2/comp/expression.g | 1 - lang/m2/comp/input.c | 15 +++ lang/m2/comp/main.c | 33 +++--- lang/m2/comp/program.g | 9 +- lang/m2/comp/scope.C | 4 +- lang/m2/comp/standards.h | 8 +- lang/m2/comp/type.c | 4 +- lang/m2/comp/walk.c | 30 ++--- 17 files changed, 224 insertions(+), 301 deletions(-) diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index e4a15ab9..1f87f78b 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -29,7 +29,6 @@ struct token dot, aside; struct type *toktype; struct string string; int idfsize = IDFSIZE; -extern label data_label(); static SkipComment() @@ -51,21 +50,15 @@ SkipComment() if (ch == '*') { ++NestLevel; } - else { - continue; - } + else continue; } else if (ch == '*') { LoadChar(ch); if (ch == ')') { - if (NestLevel-- == 0) { - return; - } - } - else { - continue; + if (NestLevel-- == 0) return; } + else continue; } LoadChar(ch); } @@ -198,7 +191,7 @@ again: return tk->tk_symb = ch; default : - assert(0); + crash("(LLlex, STCOMP)"); } case STIDF: @@ -216,7 +209,6 @@ again: *tg++ = '\0'; tk->TOK_IDF = id = str2idf(buf, 1); - if (!id) fatal("Out of memory"); return tk->tk_symb = id->id_reserved ? id->id_reserved : IDENT; } @@ -413,7 +405,7 @@ Sdec: case STCHAR: default: - assert(0); + crash("(LLlex) Impossible character class"); } /*NOTREACHED*/ } diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index 49163d6a..6fed1777 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -68,15 +68,34 @@ chk_expr(expp) case Xset: return chk_set(expp); + case Link: case Name: - return chk_designator(expp, VALUE, D_USED); + if (chk_designator(expp, VALUE|DESIGNATOR, D_USED)) { + if (expp->nd_class == Def && + expp->nd_def->df_kind == D_PROCEDURE) { + /* Check that this procedure is one that we + may take the address from. + */ + if (expp->nd_def->df_type == std_type) { + /* Standard procedure. Illegal */ +node_error(expp, "address of standard procedure taken"); + return 0; + } + if (expp->nd_def->df_scope->sc_level > 0) { + /* Address of nested procedure taken. + Illegal. + */ +node_error(expp, "address of a procedure local to another one taken"); + return 0; + } + } + return 1; + } + return 0; case Call: return chk_call(expp); - case Link: - return chk_designator(expp, DESIGNATOR|VALUE, D_USED|D_NOREG); - default: crash("(chk_expr)"); } @@ -312,7 +331,6 @@ chk_call(expp) it may also be a cast or a standard procedure call. */ register struct node *left; - register struct node *arg; /* First, get the name of the function or procedure */ @@ -340,7 +358,8 @@ chk_call(expp) */ return chk_proccall(expp); } - node_error(expp->nd_left, "procedure, type, or function expected"); + + node_error(left, "procedure, type, or function expected"); return 0; } @@ -420,7 +439,7 @@ FlagCheck(expp, df, flag) } if ((flag & VALUE) && - ( !(df->df_kind & (D_VARIABLE|D_FIELD|D_CONST|D_ENUM)))) { + ( !(df->df_kind & (D_VARIABLE|D_FIELD|D_CONST|D_ENUM|D_PROCEDURE)))) { node_error(expp, "value expected"); return 0; } @@ -584,6 +603,62 @@ symbol2str(expp->nd_symb)); return 0; } +struct type * +ResultOfOperation(operator, tp) + struct type *tp; +{ + switch(operator) { + case '=': + case '#': + case GREATEREQUAL: + case LESSEQUAL: + case '<': + case '>': + case IN: + return bool_type; + } + + return tp; +} + +int +Boolean(operator) +{ + return operator == OR || operator == AND || operator == '&'; +} + +int +AllowedTypes(operator) +{ + switch(operator) { + case '+': + case '-': + case '*': + return T_NUMERIC|T_SET; + case '/': + return T_REAL|T_SET; + case DIV: + case MOD: + return T_INTORCARD; + case OR: + case AND: + case '&': + return T_ENUMERATION; + case '=': + case '#': + return T_POINTER|T_HIDDEN|T_SET|T_NUMERIC|T_ENUMERATION|T_CHAR; + case GREATEREQUAL: + case LESSEQUAL: + return T_SET|T_NUMERIC|T_CHAR|T_ENUMERATION; + case '<': + case '>': + return T_NUMERIC|T_CHAR|T_ENUMERATION; + default: + crash("(AllowedTypes)"); + } + /*NOTREACHED*/ +} + int chk_oper(expp) register struct node *expp; @@ -594,8 +669,11 @@ chk_oper(expp) register struct node *right = expp->nd_right; struct type *tpl = left->nd_type; struct type *tpr = right->nd_type; - int errval = 1; - + int allowed; + + if (tpl->tp_fund == T_SUBRANGE) tpl = tpl->next; + if (tpr->tp_fund == T_SUBRANGE) tpr = tpr->next; + if (tpl == intorcard_type) { if (tpr == int_type || tpr == card_type) { left->nd_type = tpl = tpr; @@ -606,11 +684,11 @@ chk_oper(expp) right->nd_type = tpr = tpl; } } - expp->nd_type = error_type; + + expp->nd_type = ResultOfOperation(expp->nd_symb, tpl); if (expp->nd_symb == IN) { /* Handle this one specially */ - expp->nd_type = bool_type; if (tpr->tp_fund != T_SET) { node_error(expp, "RHS of IN operator not a SET type"); return 0; @@ -630,9 +708,6 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R return 1; } - if (tpl->tp_fund == T_SUBRANGE) tpl = tpl->next; - expp->nd_type = tpl; - /* Operands must be compatible (distilled from Def 8.2) */ if (!TstCompat(tpl, tpr)) { @@ -641,128 +716,28 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R return 0; } - switch(expp->nd_symb) { - case '+': - case '-': - case '*': - switch(tpl->tp_fund) { - case T_POINTER: - if (! chk_address(tpl, tpr)) break; - /* Fall through */ - case T_INTEGER: - case T_CARDINAL: - case T_INTORCARD: - if (left->nd_class==Value && right->nd_class==Value) { - cstbin(expp); - } - return 1; - - case T_SET: - if (left->nd_class == Set && right->nd_class == Set) { - cstset(expp); - } - /* Fall through */ - - case T_REAL: - return 1; + allowed = AllowedTypes(expp->nd_symb); + if (!(tpl->tp_fund & allowed) || + (tpl != bool_type && Boolean(expp->nd_symb))) { + if (!(tpl->tp_fund == T_POINTER && + (T_CARDINAL & allowed) && + chk_address(tpl, tpr))) { +node_error(expp,"operator \"%s\": illegal operand type(s)", symbol2str(expp->nd_symb)); + return 0; } - break; - - case '/': - switch(tpl->tp_fund) { - case T_SET: - if (left->nd_class == Set && right->nd_class == Set) { - cstset(expp); - } - /* Fall through */ - - case T_REAL: - return 1; - } - break; - - case DIV: - case MOD: - switch(tpl->tp_fund) { - case T_POINTER: - if (! chk_address(tpl, tpr)) break; - /* Fall through */ - case T_INTEGER: - case T_CARDINAL: - case T_INTORCARD: - if (left->nd_class==Value && right->nd_class==Value) { - cstbin(expp); - } - return 1; - } - break; - - case OR: - case AND: - case '&': - if (tpl == bool_type) { - if (left->nd_class==Value && right->nd_class==Value) { - cstbin(expp); - } - return 1; - } - errval = 3; - break; - - case '=': - case '#': - case GREATEREQUAL: - case LESSEQUAL: - case '<': - case '>': - expp->nd_type = bool_type; - switch(tpl->tp_fund) { - case T_SET: - if (expp->nd_symb == '<' || expp->nd_symb == '>') { - break; - } - if (left->nd_class == Set && right->nd_class == Set) { - cstset(expp); - } - return 1; - - case T_INTEGER: - case T_CARDINAL: - case T_ENUMERATION: /* includes boolean */ - case T_CHAR: - case T_INTORCARD: - if (left->nd_class==Value && right->nd_class==Value) { - cstbin(expp); - } - return 1; - - case T_HIDDEN: - case T_POINTER: - if (chk_address(tpl, tpr) || - expp->nd_symb == '=' || - expp->nd_symb == '#') return 1; - break; - - case T_REAL: - return 1; - } - - default: - assert(0); } - switch(errval) { - case 1: - node_error(expp,"operator \"%s\": illegal operand type(s)", symbol2str(expp->nd_symb)); - break; - case 3: - node_error(expp, "BOOLEAN type(s) expected"); - break; - - default: - assert(0); + if (tpl->tp_fund == T_SET) { + if (left->nd_class == Set && right->nd_class == Set) { + cstset(expp); + } } - return 0; + else if ( tpl->tp_fund != T_REAL && + left->nd_class == Value && right->nd_class == Value) { + cstbin(expp); + } + + return 1; } int diff --git a/lang/m2/comp/code.c b/lang/m2/comp/code.c index ca720318..4566bc3a 100644 --- a/lang/m2/comp/code.c +++ b/lang/m2/comp/code.c @@ -27,6 +27,7 @@ extern label text_label(); extern char *long2str(); extern char *symbol2str(); extern int proclevel; +int fp_used; CodeConst(cst, size) arith cst, size; @@ -43,7 +44,7 @@ CodeConst(cst, size) } else { C_df_dlb(dlab = data_label()); - C_rom_icon(long2str((long) cst), 10); + C_rom_icon(long2str((long) cst), size); C_lae_dlb(dlab, (arith) 0); C_loi(size); } @@ -59,7 +60,7 @@ CodeString(nd) } else { C_df_dlb(lab = data_label()); - C_rom_scon(nd->nd_STR, align(nd->nd_SLE + 1, word_size)); + C_rom_scon(nd->nd_STR, align(nd->nd_SLE + 1, (int) word_size)); C_lae_dlb(lab, (arith) 0); } } @@ -80,11 +81,8 @@ CodePadString(nd, sz) assert(sizearg < sz); C_zer(sz - sizearg); } - C_asp(-sizearg); /* room for string */ CodeString(nd); /* push address of string */ - C_lor((arith) 1); /* load stack pointer */ - C_adp(pointer_size); /* and compute target address from it */ - C_blm(sizearg); /* and copy */ + C_loi(sizearg); } CodeReal(nd) @@ -103,7 +101,9 @@ CodeExpr(nd, ds, true_label, false_label) register struct desig *ds; label true_label, false_label; { + register struct type *tp = nd->nd_type; + if (tp->tp_fund == T_REAL) fp_used = 1; switch(nd->nd_class) { case Def: if (nd->nd_def->df_kind == D_PROCEDURE) { @@ -147,7 +147,7 @@ CodeExpr(nd, ds, true_label, false_label) CodeString(nd); break; case INTEGER: - CodeConst(nd->nd_INT, nd->nd_type->tp_size); + CodeConst(nd->nd_INT, tp->tp_size); break; default: crash("Value error"); @@ -167,12 +167,10 @@ CodeExpr(nd, ds, true_label, false_label) st = nd->nd_set; ds->dsg_kind = DSG_LOADED; if (!st) { - C_zer(nd->nd_type->tp_size); + C_zer(tp->tp_size); break; } - for (i = nd->nd_type->tp_size / word_size, st += i; - i > 0; - i--) { + for (i = tp->tp_size / word_size, st += i; i > 0; i--) { C_loc(*--st); } } @@ -188,7 +186,7 @@ CodeExpr(nd, ds, true_label, false_label) } if (true_label != 0) { - CodeValue(ds, nd->nd_type->tp_size); + CodeValue(ds, tp->tp_size); *ds = InitDesig; C_zne(true_label); C_bra(false_label); @@ -250,12 +248,12 @@ CodeCoercion(t1, t2) } break; case T_INTEGER: - C_loc(t1->tp_size); + C_loc(word_size); C_loc(t2->tp_size); C_cui(); break; case T_REAL: - C_loc(t1->tp_size); + C_loc(word_size); C_loc(t2->tp_size); C_cuf(); break; @@ -322,41 +320,44 @@ CodeCall(nd) tp = TypeOfParam(param); arg = arg->nd_right; assert(arg != 0); + left = arg->nd_left; if (IsConformantArray(tp)) { C_loc(tp->arr_elsize); - if (IsConformantArray(arg->nd_left->nd_type)) { - DoHIGH(arg->nd_left); + if (IsConformantArray(left->nd_type)) { + DoHIGH(left); } - else if (arg->nd_left->nd_symb == STRING) { - C_loc(arg->nd_left->nd_SLE); + else if (left->nd_symb == STRING) { + C_loc(left->nd_SLE); } else if (tp->arr_elem == word_type) { - C_loc(arg->nd_left->nd_type->tp_size / word_size - 1); + C_loc(left->nd_type->tp_size / word_size - 1); } - else C_loc(arg->nd_left->nd_type->tp_size / + else C_loc(left->nd_type->tp_size / tp->arr_elsize - 1); - C_loc(0); - if (arg->nd_left->nd_symb == STRING) { - CodeString(arg->nd_left); + C_loc((arith) 0); + if (left->nd_symb == STRING) { + CodeString(left); } - else CodeDAddress(arg->nd_left); + else CodeDAddress(left); pushed += pointer_size + 3 * word_size; } else if (IsVarParam(param)) { - CodeDAddress(arg->nd_left); + CodeDAddress(left); pushed += pointer_size; } else { - if (arg->nd_left->nd_type->tp_fund == T_STRING) { - CodePadString(arg->nd_left, + if (left->nd_type->tp_fund == T_STRING) { + CodePadString(left, align(tp->tp_size, word_align)); } - else CodePExpr(arg->nd_left); - CheckAssign(arg->nd_left->nd_type, tp); + else CodePExpr(left); + CheckAssign(left->nd_type, tp); pushed += align(tp->tp_size, word_align); } } + left = nd->nd_left; + if (left->nd_class == Def && left->nd_def->df_kind == D_PROCEDURE) { if (left->nd_def->df_scope->sc_level > 0) { C_lxl((arith) proclevel - left->nd_def->df_scope->sc_level); @@ -944,15 +945,13 @@ CodeSet(nd) { struct type *tp = nd->nd_type; + C_zer(nd->nd_type->tp_size); /* empty set */ nd = nd->nd_right; while (nd) { assert(nd->nd_class == Link && nd->nd_symb == ','); CodeEl(nd->nd_left, tp); nd = nd->nd_right; - if (nd) { - C_ior(tp->tp_size); - } } } @@ -962,19 +961,19 @@ CodeEl(nd, tp) { if (nd->nd_class == Link && nd->nd_symb == UPTO) { - C_zer(tp->tp_size); /* empty set */ - C_lor((arith) 1); /* SP: address of set */ + C_loc(tp->tp_size); /* push size */ if (tp->next->tp_fund == T_SUBRANGE) { C_loc(tp->next->sub_ub); } - else C_loc(tp->next->enm_ncst - 1); + else C_loc((arith) (tp->next->enm_ncst - 1)); Operands(nd->nd_left, nd->nd_right); C_cal("_LtoUset"); /* library routine to fill set */ - C_asp(2 * word_size + pointer_size); + C_asp(4 * word_size); } else { CodePExpr(nd); C_set(tp->tp_size); + C_ior(tp->tp_size); } } diff --git a/lang/m2/comp/cstoper.c b/lang/m2/comp/cstoper.c index 7c0453a5..617ef95d 100644 --- a/lang/m2/comp/cstoper.c +++ b/lang/m2/comp/cstoper.c @@ -39,6 +39,9 @@ cstunary(expp) break; case '-': o1 = -o1; + if (expp->nd_type->tp_fund == T_INTORCARD) { + expp->nd_type = int_type; + } break; case NOT: case '~': @@ -149,6 +152,9 @@ cstbin(expp) case '-': o1 -= o2; + if (expp->nd_type->tp_fund == T_INTORCARD) { + if (o1 < 0) expp->nd_type = int_type; + } break; case '<': diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 84174ed8..a0f87104 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -22,7 +22,6 @@ static char *RcsId = "$Header$"; #include "main.h" int proclevel = 0; /* nesting level of procedures */ -extern char *sprint(); } ProcedureDeclaration @@ -566,23 +565,22 @@ ConstantDeclaration VariableDeclaration { struct node *VarList; + register struct node *nd; struct type *tp; } : - IdentAddrList(&VarList) + IdentAddr(&VarList) + { nd = VarList; } + [ + ',' IdentAddr(&(nd->nd_right)) + { nd = nd->nd_right; } + ]* ':' type(&tp) { EnterVarList(VarList, tp, proclevel > 0); FreeNode(VarList); } ; -IdentAddrList(struct node **pnd;) -{ -} : +IdentAddr(struct node **pnd;) : IDENT { *pnd = MkLeaf(Name, &dot); } - ConstExpression(&(*pnd)->nd_left)? - [ { pnd = &((*pnd)->nd_right); } - ',' IDENT - { *pnd = MkLeaf(Name, &dot); } - ConstExpression(&(*pnd)->nd_left)? - ]* + ConstExpression(&((*pnd)->nd_left))? ; diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index 80bc6ea2..6f3344ec 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -390,11 +390,12 @@ idn->nd_IDF->id_text); else if (!(df = lookup(ids->nd_IDF, vis->sc_scope))) { node_error(ids, "identifier \"%s\" not declared in qualifying module", ids->nd_IDF->id_text); - df = ill_df; + df = define(ids->nd_IDF,vis->sc_scope,D_ERROR); } else if (!(df->df_flags&(D_EXPORTED|D_QEXPORTED))) { node_error(ids,"identifier \"%s\" not exported from qualifying module", ids->nd_IDF->id_text); + df->df_flags |= D_QEXPORTED; } } else { @@ -459,9 +460,8 @@ DeclProc(type) Also create a name for it. */ register struct def *df; - static int nmcount = 0; - extern char *strcpy(); extern char *sprint(); + static int nmcount; char buf[256]; assert(type & (D_PROCEDURE | D_PROCHEAD)); @@ -472,8 +472,7 @@ DeclProc(type) df = define(dot.TOK_IDF, CurrentScope, type); df->for_node = MkLeaf(Name, &dot); sprint(buf,"%s_%s",CurrentScope->sc_name,df->df_idf->id_text); - df->for_name = Malloc((unsigned) (strlen(buf)+1)); - strcpy(df->for_name, buf); + df->for_name = Salloc(buf, (unsigned) (strlen(buf)+1)); C_exp(df->for_name); open_scope(OPENSCOPE); } @@ -491,16 +490,11 @@ DeclProc(type) } else { df = define(dot.TOK_IDF, CurrentScope, type); - if (CurrVis != Defined->mod_vis) { - sprint(buf, "_%d_%s", ++nmcount, - df->df_idf->id_text); - } - else sprint(buf, "%s_%s",CurrentScope->sc_name, - df->df_idf->id_text); open_scope(OPENSCOPE); df->prc_vis = CurrVis; - CurrentScope->sc_name = Malloc((unsigned)(strlen(buf)+1)); - strcpy(CurrentScope->sc_name, buf); + sprint(buf,"_%d_%s",++nmcount,df->df_idf->id_text); + CurrentScope->sc_name = + Salloc(buf, (unsigned)(strlen(buf)+1)); C_inp(buf); } } diff --git a/lang/m2/comp/defmodule.c b/lang/m2/comp/defmodule.c index fe6d63c1..1696facd 100644 --- a/lang/m2/comp/defmodule.c +++ b/lang/m2/comp/defmodule.c @@ -31,11 +31,9 @@ GetFile(name) char buf[256]; char *strcpy(), *strcat(); - (void) strcpy(buf, name); - if (strlen(buf) > 10) { - (void) strcpy(&buf[10], ".def"); - } - else (void) strcat(buf, ".def"); + strcpy(buf, name); + buf[10] = '\0'; /* maximum length */ + strcat(buf, ".def"); if (! InsertFile(buf, DEFPATH, &(FileName))) { fatal("Could'nt find a DEFINITION MODULE for \"%s\"", name); } @@ -80,11 +78,3 @@ GetDefinitionModule(id) level--; return df; } - -AtEoIF() -{ - /* Make the unstacking of input streams noticable by the - lexical analyzer - */ - return 1; -} diff --git a/lang/m2/comp/desig.c b/lang/m2/comp/desig.c index 47780bfc..69eb62b8 100644 --- a/lang/m2/comp/desig.c +++ b/lang/m2/comp/desig.c @@ -246,19 +246,6 @@ CodeVarDesig(df, ds) df->df_flags |= D_NOREG; return; } - - if (sc->sc_level == 0) { - /* the variable is global, but declared in a module local - to the implementation or program module. - Such variables can be accessed through an offset from - the name of the module. - */ - ds->dsg_name = &(sc->sc_name[1]); - ds->dsg_offset = df->var_off; - ds->dsg_kind = DSG_FIXED; - df->df_flags |= D_NOREG; - return; - } if (sc->sc_level != proclevel) { /* the variable is local to a statically enclosing procedure. @@ -349,7 +336,7 @@ CodeDesig(nd, ds) df = nd->nd_left->nd_def; if (proclevel > df->df_scope->sc_level) { - C_lxa(proclevel - df->df_scope->sc_level); + C_lxa((arith) (proclevel - df->df_scope->sc_level)); C_adp(df->var_off + pointer_size); } else C_lal(df->var_off + pointer_size); diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index b2bb3bf5..424c423b 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -118,7 +118,7 @@ EnterVarList(IdList, type, local) register struct def *df; register struct scopelist *sc; char buf[256]; - extern char *sprint(), *Malloc(), *strcpy(); + extern char *sprint(); sc = CurrVis; @@ -151,24 +151,12 @@ node_error(IdList->nd_left,"Illegal type for address"); type->tp_align); df->var_off = sc->sc_scope->sc_off; } - else if (!DefinitionModule && CurrVis != Defined->mod_vis) { - /* variable list belongs to an internal global - module. - Align offset and add size - */ - sc->sc_scope->sc_off = - align(sc->sc_scope->sc_off, type->tp_align); - df->var_off = sc->sc_scope->sc_off; - df->var_name = 0; - sc->sc_scope->sc_off += type->tp_size; - } else { /* Global name, possibly external */ sprint(buf,"%s_%s", sc->sc_scope->sc_name, df->df_idf->id_text); - df->var_name = Malloc((unsigned)(strlen(buf)+1)); - strcpy(df->var_name, buf); + df->var_name = Salloc(buf, (unsigned)(strlen(buf)+1)); if (DefinitionModule) { C_exa_dnam(df->var_name); diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index 80a75780..983042cd 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -175,7 +175,6 @@ factor(struct node **p;) { struct def *df; struct node *nd; - register struct type *tp; } : qualident(0, &df, (char *) 0, p) [ diff --git a/lang/m2/comp/input.c b/lang/m2/comp/input.c index bc608885..7dd53d9b 100644 --- a/lang/m2/comp/input.c +++ b/lang/m2/comp/input.c @@ -6,3 +6,18 @@ struct f_info file_info; #include "input.h" #include + +AtEoIF() +{ + /* Make the unstacking of input streams noticable to the + lexical analyzer + */ + return 1; +} + +AtEoIT() +{ + /* Make the end of the text noticable + */ + return 1; +} diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index 1372165b..54857ddd 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -23,14 +23,15 @@ static char *RcsId = "$Header$"; #include "tokenname.h" #include "node.h" -int state; /* either IMPLEMENTATION or PROGRAM */ -char options[128]; -int DefinitionModule; -int SYSTEMModule = 0; -char *ProgName; -char *DEFPATH[NDIRS+1]; -struct def *Defined; -extern int err_occurred; +int state; /* either IMPLEMENTATION or PROGRAM */ +char options[128]; +int DefinitionModule; +int SYSTEMModule = 0; +char *ProgName; +char *DEFPATH[NDIRS+1]; +struct def *Defined; +extern int err_occurred; +extern int fp_used; /* set if floating point used */ main(argc, argv) char *argv[]; @@ -75,8 +76,8 @@ Compile(src, dst) init_idf(); InitCst(); reserve(tkidf); - init_scope(); - init_types(); + InitScope(); + InitTypes(); InitDef(); AddStandards(); #ifdef DEBUG @@ -94,12 +95,16 @@ Compile(src, dst) C_magic(); C_ms_emx(word_size, pointer_size); CompUnit(); + C_ms_src((arith) (LineNumber - 1), FileName); close_scope(SC_REVERSE); if (err_occurred) { C_close(); return 0; } WalkModule(Defined); + if (fp_used) { + C_ms_flt(); + } C_close(); #ifdef DEBUG if (options['m']) MemUse(); @@ -210,17 +215,9 @@ END SYSTEM.\n"; } SYSTEMModule = 1; DefModule(); - close_scope(0); SYSTEMModule = 0; } -AtEoIT() -{ - /* Make the end of the text noticable - */ - return 1; -} - #ifdef DEBUG MemUse() { diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index cbf86b8a..cf8aed10 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -49,7 +49,7 @@ ModuleDeclaration struct node *nd; struct node *exportlist = 0; int qualified; - extern char *sprint(), *Malloc(), *strcpy(); + extern char *sprint(); } : MODULE IDENT { id = dot.TOK_IDF; @@ -67,10 +67,9 @@ ModuleDeclaration df->df_type = standard_type(T_RECORD, 0, (arith) 0); df->df_type->rec_scope = df->mod_vis->sc_scope; - sprint(buf, "__%d%s", ++modulecount, id->id_text); + sprint(buf, "_%d%s", ++modulecount, id->id_text); CurrentScope->sc_name = - Malloc((unsigned) (strlen(buf) + 1)); - strcpy(CurrentScope->sc_name, buf); + Salloc(buf, (unsigned) (strlen(buf) + 1)); if (! proclevel) C_ina_dnam(&buf[1]); C_inp(buf); } @@ -177,7 +176,7 @@ DefinitionModule df->df_flags |= D_QEXPORTED; df = df->df_nextinscope; } - if (!SYSTEMModule) close_scope(SC_CHKFORW); + close_scope(SC_CHKFORW); DefinitionModule--; match_id(id, dot.TOK_IDF); } diff --git a/lang/m2/comp/scope.C b/lang/m2/comp/scope.C index c359cfc5..f1731fb3 100644 --- a/lang/m2/comp/scope.C +++ b/lang/m2/comp/scope.C @@ -36,7 +36,7 @@ open_scope(scopetype) assert(scopetype == OPENSCOPE || scopetype == CLOSEDSCOPE); - clear((char *) sc, sizeof (*sc)); + clear((char *) sc, sizeof (struct scope)); sc->sc_scopeclosed = scopetype == CLOSEDSCOPE; sc->sc_level = proclevel; if (scopetype == OPENSCOPE) { @@ -48,7 +48,7 @@ open_scope(scopetype) CurrVis = ls; } -init_scope() +InitScope() { register struct scope *sc = new_scope(); register struct scopelist *ls = new_scopelist(); diff --git a/lang/m2/comp/standards.h b/lang/m2/comp/standards.h index c7841b0b..983b13e3 100644 --- a/lang/m2/comp/standards.h +++ b/lang/m2/comp/standards.h @@ -22,7 +22,7 @@ /* Standard procedures and functions defined in the SYSTEM module ... */ -#define S_ADR 20 -#define S_TSIZE 21 -#define S_NEWPROCESS 22 -#define S_TRANSFER 23 +#define S_ADR 50 +#define S_TSIZE 51 +#define S_NEWPROCESS 52 +#define S_TRANSFER 53 diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index 974c8669..89360b85 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -153,7 +153,7 @@ standard_type(fund, align, size) return tp; } -init_types() +InitTypes() { /* Initialize the predefined types */ @@ -434,7 +434,7 @@ ArrayElSize(tp) if (tp->tp_fund == T_ARRAY) ArraySizes(tp); algn = align(tp->tp_size, tp->tp_align); if (!(algn % word_size == 0 || word_size % algn == 0)) { - algn = align(algn, word_size); + algn = align(algn, (int) word_size); } return algn; } diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index eb655e67..cc48c91c 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -78,26 +78,10 @@ WalkModule(module) CurrVis = module->mod_vis; sc = CurrentScope; - if (!proclevel && module != Defined) { - /* This module is a local module, but not within a - procedure. Generate code to allocate storage for its - variables. This is done by generating a "bss", - with label "_". - */ - arith size = align(sc->sc_off, word_align); - - if (size == 0) size = word_size; - /* WHY ??? because we generated an INA for it ??? */ - - C_df_dnam(&(sc->sc_name[1])); - size = align(size, word_align); - C_bss_cst(size, (arith) 0, 0); - C_exp(sc->sc_name); - } - else if (CurrVis == Defined->mod_vis) { - /* This module is the module currently being compiled. - Again, generate code to allocate storage for its - variables, which all have an explicit name. + if (!proclevel) { + /* This module is a glocal module. + Generate code to allocate storage for its variables. + They all have an explicit name. */ while (df) { if (df->df_kind == D_VARIABLE) { @@ -369,11 +353,9 @@ WalkStat(nd, lab) struct node *fnd; label l1 = instructionlabel++; label l2 = instructionlabel++; - arith size; if (! DoForInit(nd, left)) break; fnd = left->nd_right; - size = fnd->nd_type->tp_size; if (fnd->nd_class != Value) { CodePExpr(fnd); tmp = NewInt(); @@ -513,7 +495,7 @@ DoForInit(nd, left) if (! chk_designator(nd, VARIABLE, D_DEFINED) || ! chk_expr(left->nd_left) || - ! chk_expr(left->nd_right)) return; + ! chk_expr(left->nd_right)) return 0; if (nd->nd_type->tp_size > word_size || !(nd->nd_type->tp_fund & T_DISCRETE)) { @@ -533,6 +515,8 @@ node_warning(nd, "old-fashioned! compatibility required in FOR statement"); CodePExpr(left->nd_left); CodeDStore(nd); + + return 1; } DoAssign(nd, left, right) From ddba03d53bc4233fcd3b1e4a1cc5e8d8e6052b30 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 6 Jun 1986 09:35:11 +0000 Subject: [PATCH 0204/1625] newer version --- lang/m2/comp/LLlex.c | 12 ++++++++++++ lang/m2/comp/main.c | 23 ++++++++++++----------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index 1f87f78b..5f4c8b43 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -29,6 +29,9 @@ struct token dot, aside; struct type *toktype; struct string string; int idfsize = IDFSIZE; +#ifdef DEBUG +extern int cntlines; +#endif static SkipComment() @@ -43,6 +46,9 @@ SkipComment() for (;;) { if (class(ch) == STNL) { LineNumber++; +#ifdef DEBUG + cntlines++; +#endif } else if (ch == '(') { @@ -79,6 +85,9 @@ GetString(upto) if (class(ch) == STNL) { lexerror("newline in string"); LineNumber++; +#ifdef DEBUG + cntlines++; +#endif break; } if (ch == EOI) { @@ -129,6 +138,9 @@ again: case STNL: LineNumber++; +#ifdef DEBUG + cntlines++; +#endif tk->tk_lineno++; goto again; diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index 54857ddd..79dc43e1 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -97,20 +97,17 @@ Compile(src, dst) CompUnit(); C_ms_src((arith) (LineNumber - 1), FileName); close_scope(SC_REVERSE); - if (err_occurred) { - C_close(); - return 0; - } - WalkModule(Defined); - if (fp_used) { - C_ms_flt(); + if (!err_occurred) { + WalkModule(Defined); + if (fp_used) { + C_ms_flt(); + } } C_close(); #ifdef DEBUG - if (options['m']) MemUse(); + if (options['i']) Info(); #endif - if (err_occurred) return 0; - return 1; + return ! err_occurred; } #ifdef DEBUG @@ -219,7 +216,10 @@ END SYSTEM.\n"; } #ifdef DEBUG -MemUse() + +int cntlines; + +Info() { extern int cnt_def, cnt_node, cnt_paramlist, cnt_type, cnt_switch_hdr, cnt_case_entry, @@ -231,5 +231,6 @@ MemUse() cnt_def, cnt_node, cnt_paramlist, cnt_type, cnt_switch_hdr, cnt_case_entry, cnt_scope, cnt_scopelist, cnt_forwards, cnt_tmpvar); +print("\nNumber of lines read: %d\n", cntlines); } #endif From 933448ad6e932d90c040c04f9a9fc9e92368fe15 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 6 Jun 1986 23:35:42 +0000 Subject: [PATCH 0205/1625] There was a bug in the printing of the trap number. This is corrected. --- mach/vax4/libem/trp.s | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mach/vax4/libem/trp.s b/mach/vax4/libem/trp.s index 0e3a5a68..e6779037 100644 --- a/mach/vax4/libem/trp.s +++ b/mach/vax4/libem/trp.s @@ -31,8 +31,8 @@ L2: movl $5,r2 # Max number of digits. movl (sp),r0 # Trap number in r0. L3: - bicw2 $0177770,r0 # Lower 3 bits form lower octal digit. - bisb2 r0,-(r1) # Put them in the '0'. + bicw3 $0177770,r0,r3 # Lower 3 bits form lower octal digit. + bisb2 r3,-(r1) # Put them in the '0'. ashl $-3,r0,r0 # Shift the 3 bits off. sobgtr r2,L3 movl ap,r2 From 2df2dde564c6b187d00d50ac3b6c3dcf819fcc9b Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 10 Jun 1986 13:18:52 +0000 Subject: [PATCH 0206/1625] newer version --- lang/m2/comp/Makefile | 2 +- lang/m2/comp/casestat.C | 9 +- lang/m2/comp/chk_expr.c | 46 +++-- lang/m2/comp/code.c | 48 +++-- lang/m2/comp/cstoper.c | 3 +- lang/m2/comp/declar.g | 22 +- lang/m2/comp/def.c | 270 ------------------------- lang/m2/comp/desig.c | 4 +- lang/m2/comp/enter.c | 415 +++++++++++++++++++++++++++++--------- lang/m2/comp/expression.g | 6 +- lang/m2/comp/lookup.c | 74 +++++++ lang/m2/comp/main.c | 10 +- lang/m2/comp/node.H | 16 +- lang/m2/comp/options.c | 2 +- lang/m2/comp/program.g | 30 ++- lang/m2/comp/tmpvar.C | 16 +- lang/m2/comp/type.H | 1 + lang/m2/comp/type.c | 49 +---- lang/m2/comp/walk.c | 25 ++- 19 files changed, 524 insertions(+), 524 deletions(-) create mode 100644 lang/m2/comp/lookup.c diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index abeb35a6..a295f17f 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -19,7 +19,7 @@ COBJ = LLlex.o LLmessage.o char.o error.o main.o \ symbol2str.o tokenname.o idf.o input.o type.o def.o \ scope.o misc.o enter.o defmodule.o typequiv.o node.o \ cstoper.o chk_expr.o options.o walk.o casestat.o desig.o \ - code.o tmpvar.o + code.o tmpvar.o lookup.o OBJ = $(COBJ) $(LOBJ) Lpars.o GENFILES= tokenfile.c \ program.c declar.c expression.c statement.c \ diff --git a/lang/m2/comp/casestat.C b/lang/m2/comp/casestat.C index 7fbfeffe..c9c728dd 100644 --- a/lang/m2/comp/casestat.C +++ b/lang/m2/comp/casestat.C @@ -66,7 +66,7 @@ CaseCode(nd, exitlabel) assert(pnode->nd_class == Stat && pnode->nd_symb == CASE); clear((char *) sh, sizeof(*sh)); - WalkExpr(pnode->nd_left, NO_LABEL, NO_LABEL); + WalkExpr(pnode->nd_left); sh->sh_type = pnode->nd_left->nd_type; sh->sh_break = text_label(); @@ -88,8 +88,9 @@ CaseCode(nd, exitlabel) else { /* Else part */ - pnode = 0; + sh->sh_default = text_label(); + pnode = 0; } } @@ -98,7 +99,7 @@ CaseCode(nd, exitlabel) tablabel = data_label(); /* the rom must have a label */ C_df_dlb(tablabel); if (sh->sh_default) C_rom_ilb(sh->sh_default); - else C_rom_ucon("0", pointer_size); + else C_rom_ilb(sh->sh_break); if (compact(sh->sh_nrofentries, sh->sh_lowerbd, sh->sh_upperbd)) { /* CSA */ @@ -112,7 +113,7 @@ CaseCode(nd, exitlabel) ce = ce->next; } else if (sh->sh_default) C_rom_ilb(sh->sh_default); - else C_rom_ucon("0", pointer_size); + else C_rom_ilb(sh->sh_break); } C_lae_dlb(tablabel, (arith)0); /* perform the switch */ C_csa(word_size); diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index 6fed1777..82f32881 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -36,22 +36,17 @@ chk_expr(expp) */ switch(expp->nd_class) { - case Oper: - if (expp->nd_symb == '[') { - return chk_designator(expp, DESIGNATOR|VARIABLE, D_NOREG|D_USED); - } + case Arrsel: + return chk_designator(expp, DESIGNATOR|VARIABLE, D_USED); - return chk_expr(expp->nd_left) && - chk_expr(expp->nd_right) && - chk_oper(expp); + case Oper: + return chk_oper(expp); + + case Arrow: + return chk_designator(expp, DESIGNATOR|VARIABLE, D_USED); case Uoper: - if (expp->nd_symb == '^') { - return chk_designator(expp, DESIGNATOR|VARIABLE, D_USED); - } - - return chk_expr(expp->nd_right) && - chk_uoper(expp); + return chk_uoper(expp); case Value: switch(expp->nd_symb) { @@ -547,7 +542,7 @@ df->df_idf->id_text); return 0; } - if (expp->nd_class == Oper) { + if (expp->nd_class == Arrsel) { struct type *tpl, *tpr; assert(expp->nd_symb == '['); @@ -582,7 +577,7 @@ df->df_idf->id_text); return 1; } - if (expp->nd_class == Uoper) { + if (expp->nd_class == Arrow) { assert(expp->nd_symb == '^'); if (! chk_designator(expp->nd_right, DESIGNATOR|VARIABLE, dflags)) { @@ -665,12 +660,18 @@ chk_oper(expp) { /* Check a binary operation. */ - register struct node *left = expp->nd_left; - register struct node *right = expp->nd_right; - struct type *tpl = left->nd_type; - struct type *tpr = right->nd_type; + register struct node *left, *right; + struct type *tpl, *tpr; int allowed; + left = expp->nd_left; + right = expp->nd_right; + + if (!chk_expr(left) || !chk_expr(right)) return 0; + + tpl = left->nd_type; + tpr = right->nd_type; + if (tpl->tp_fund == T_SUBRANGE) tpl = tpl->next; if (tpr->tp_fund == T_SUBRANGE) tpr = tpr->next; @@ -763,8 +764,11 @@ chk_uoper(expp) /* Check an unary operation. */ register struct node *right = expp->nd_right; - register struct type *tpr = right->nd_type; + register struct type *tpr; + if (! chk_expr(right)) return 0; + + tpr = right->nd_type; if (tpr->tp_fund == T_SUBRANGE) tpr = tpr->next; expp->nd_type = tpr; @@ -839,7 +843,7 @@ getvariable(argp) left = arg->nd_left; if (! chk_designator(left, DESIGNATOR, D_REFERRED)) return 0; - if (left->nd_class == Oper || left->nd_class == Uoper) { + if (left->nd_class == Arrsel || left->nd_class == Arrow) { *argp = arg; return left; } diff --git a/lang/m2/comp/code.c b/lang/m2/comp/code.c index 4566bc3a..48c55d28 100644 --- a/lang/m2/comp/code.c +++ b/lang/m2/comp/code.c @@ -60,7 +60,7 @@ CodeString(nd) } else { C_df_dlb(lab = data_label()); - C_rom_scon(nd->nd_STR, align(nd->nd_SLE + 1, (int) word_size)); + C_rom_scon(nd->nd_STR, WA(nd->nd_SLE + 1)); C_lae_dlb(lab, (arith) 0); } } @@ -72,7 +72,7 @@ CodePadString(nd, sz) /* Generate code to push the string indicated by "nd". Make it null-padded to "sz" bytes */ - register arith sizearg = align(nd->nd_type->tp_size, word_align); + register arith sizearg = WA(nd->nd_type->tp_size); assert(nd->nd_type->tp_fund == T_STRING); @@ -114,25 +114,21 @@ CodeExpr(nd, ds, true_label, false_label) /* Fall through */ case Link: + case Arrsel: + case Arrow: CodeDesig(nd, ds); break; case Oper: - if (nd->nd_symb == '[') { - CodeDesig(nd, ds); - break; - } CodeOper(nd, true_label, false_label); if (true_label == 0) ds->dsg_kind = DSG_LOADED; - else ds->dsg_kind = DSG_INIT; - true_label = 0; + else { + ds->dsg_kind = DSG_INIT; + true_label = 0; + } break; case Uoper: - if (nd->nd_symb == '^') { - CodeDesig(nd, ds); - break; - } CodePExpr(nd->nd_right); CodeUoper(nd); ds->dsg_kind = DSG_LOADED; @@ -298,7 +294,6 @@ CodeCall(nd) register struct node *arg = nd; register struct paramlist *param; struct type *tp; - arith pushed = 0; if (left->nd_type == std_type) { CodeStd(nd); @@ -332,27 +327,28 @@ CodeCall(nd) else if (tp->arr_elem == word_type) { C_loc(left->nd_type->tp_size / word_size - 1); } - else C_loc(left->nd_type->tp_size / - tp->arr_elsize - 1); + else { + tp = left->nd_type->next; + if (tp->tp_fund == T_SUBRANGE) { + C_loc(tp->sub_ub - tp->sub_lb); + } + else C_loc((arith) (tp->enm_ncst - 1)); + } C_loc((arith) 0); if (left->nd_symb == STRING) { CodeString(left); } else CodeDAddress(left); - pushed += pointer_size + 3 * word_size; } else if (IsVarParam(param)) { CodeDAddress(left); - pushed += pointer_size; } else { if (left->nd_type->tp_fund == T_STRING) { - CodePadString(left, - align(tp->tp_size, word_align)); + CodePadString(left, tp->tp_size); } else CodePExpr(left); CheckAssign(left->nd_type, tp); - pushed += align(tp->tp_size, word_align); } } @@ -361,7 +357,6 @@ CodeCall(nd) if (left->nd_class == Def && left->nd_def->df_kind == D_PROCEDURE) { if (left->nd_def->df_scope->sc_level > 0) { C_lxl((arith) proclevel - left->nd_def->df_scope->sc_level); - pushed += pointer_size; } C_cal(NameOfProc(left->nd_def)); } @@ -372,9 +367,9 @@ CodeCall(nd) CodePExpr(left); C_cai(); } - if (pushed) C_asp(pushed); + if (left->nd_type->prc_nbpar) C_asp(left->nd_type->prc_nbpar); if (left->nd_type->next) { - C_lfr(align(left->nd_type->next->tp_size, word_align)); + C_lfr(WA(left->nd_type->next->tp_size)); } } @@ -526,7 +521,6 @@ CodeAssign(nd, dss, dst) compatibility and the like is already done. */ register struct type *tp = nd->nd_right->nd_type; - extern arith align(); if (dss->dsg_kind == DSG_LOADED) { if (tp->tp_fund == T_STRING) { @@ -787,6 +781,10 @@ CodeOper(expr, true_label, false_label) Operands(rightop, leftop); CodeCoercion(leftop->nd_type, word_type); C_inn(rightop->nd_type->tp_size); + if (true_label != 0) { + C_zne(true_label); + C_bra(false_label); + } break; case AND: case '&': @@ -1032,7 +1030,7 @@ DoHIGH(nd) highoff = df->var_off + pointer_size + word_size; if (df->df_scope->sc_level < proclevel) { - C_lxa(proclevel - df->df_scope->sc_level); + C_lxa((arith) (proclevel - df->df_scope->sc_level)); C_lof(highoff); } else C_lol(highoff); diff --git a/lang/m2/comp/cstoper.c b/lang/m2/comp/cstoper.c index 617ef95d..120793c3 100644 --- a/lang/m2/comp/cstoper.c +++ b/lang/m2/comp/cstoper.c @@ -430,8 +430,7 @@ cstcall(expp, call) CutSize(expp); break; case S_SIZE: - expp->nd_INT = align(expr->nd_type->tp_size, (int) word_size) / - word_size; + expp->nd_INT = WA(expr->nd_type->tp_size) / word_size; break; case S_VAL: expp->nd_INT = expr->nd_INT; diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index a0f87104..9bad30c1 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -139,10 +139,7 @@ FPSection(struct paramlist **ppr; arith *parmaddr;) VAR { VARp = D_VARPAR; } ]? IdentList(&FPList) ':' FormalType(&tp) - { - ParamList(ppr, FPList, tp, VARp, parmaddr); - FreeNode(FPList); - } + { EnterParamList(ppr, FPList, tp, VARp, parmaddr); } ; FormalType(struct type **ptp;) @@ -235,11 +232,8 @@ enumeration(struct type **ptp;) '(' IdentList(&EnumList) ')' { *ptp = tp = standard_type(T_ENUMERATION, 1, (arith) 1); - EnterIdList(EnumList, D_ENUM, 0, tp, - CurrentScope, (arith *) 0); - FreeNode(EnumList); - if (tp->enm_ncst > 256) { - /* ??? is this reasonable ??? */ + EnterEnumList(EnumList, tp); + if (tp->enm_ncst > 256) { /* ??? is this reasonable ??? */ error("Too many enumeration literals"); } } @@ -311,7 +305,7 @@ RecordType(struct type **ptp;) } FieldListSequence(scope, &count, &xalign) { - *ptp = standard_type(T_RECORD, xalign, count); + *ptp = standard_type(T_RECORD, xalign, WA(count)); (*ptp)->rec_scope = scope; } END @@ -336,9 +330,7 @@ FieldList(struct scope *scope; arith *cnt; int *palign;) [ IdentList(&FldList) ':' type(&tp) { *palign = lcm(*palign, tp->tp_align); - EnterIdList(FldList, D_FIELD, D_QEXPORTED, - tp, scope, cnt); - FreeNode(FldList); + EnterFieldList(FldList, tp, scope, cnt); } | CASE @@ -575,9 +567,7 @@ VariableDeclaration { nd = nd->nd_right; } ]* ':' type(&tp) - { EnterVarList(VarList, tp, proclevel > 0); - FreeNode(VarList); - } + { EnterVarList(VarList, tp, proclevel > 0); } ; IdentAddr(struct node **pnd;) : diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index 6f3344ec..1b703ff6 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -141,276 +141,6 @@ error("identifier \"%s\" already declared", id->id_text); return MkDef(id, scope, kind); } -struct def * -lookup(id, scope) - register struct idf *id; - struct scope *scope; -{ - /* Look up a definition of an identifier in scope "scope". - Make the "def" list self-organizing. - Return a pointer to its "def" structure if it exists, - otherwise return 0. - */ - register struct def *df, *df1; - struct def *retval; - - df1 = 0; - df = id->id_def; - while (df) { - if (df->df_scope == scope) { - retval = df; - if (df->df_kind == D_IMPORT) { - retval = df->imp_def; - assert(retval != 0); - } - if (df1) { - /* Put the definition now found in front - */ - df1->next = df->next; - df->next = id->id_def; - id->id_def = df; - } - return retval; - } - df1 = df; - df = df->next; - } - return 0; -} - -DoImport(df, scope) - register struct def *df; - struct scope *scope; -{ - /* Definition "df" is imported to scope "scope". - Handle the case that it is an enumeration type or a module. - */ - - define(df->df_idf, scope, D_IMPORT)->imp_def = df; - - if (df->df_kind == D_TYPE && df->df_type->tp_fund == T_ENUMERATION) { - /* Also import all enumeration literals - */ - df = df->df_type->enm_enums; - while (df) { - define(df->df_idf, scope, D_IMPORT)->imp_def = df; - df = df->enm_next; - } - } - else if (df->df_kind == D_MODULE) { - /* Also import all definitions that are exported from this - module - */ - df = df->mod_vis->sc_scope->sc_def; - while (df) { - if (df->df_flags & D_EXPORTED) { - define(df->df_idf,scope,D_IMPORT)->imp_def = df; - } - df = df->df_nextinscope; - } - } -} - -Export(ids, qualified, moddef) - register struct node *ids; - struct def *moddef; -{ - /* From the current scope, the list of identifiers "ids" is - exported. Note this fact. If the export is not qualified, make - all the "ids" visible in the enclosing scope by defining them - in this scope as "imported". - */ - register struct def *df, *df1; - register struct def *impmod; - - for (;ids; ids = ids->next) { - df = lookup(ids->nd_IDF, CurrentScope); - - if (!df) { - /* undefined item in export list - */ -node_error(ids, "identifier \"%s\" not defined", ids->nd_IDF->id_text); - continue; - } - - if (df->df_flags & (D_EXPORTED|D_QEXPORTED)) { -node_error(ids, "identifier \"%s\" occurs more than once in export list", -df->df_idf->id_text); - } - - if (qualified) { - df->df_flags |= D_QEXPORTED; - } - else { - /* Export, but not qualified. - Find all imports of the module in which this export - occurs, and export the current definition to it - */ - df->df_flags |= D_EXPORTED; - - impmod = moddef->df_idf->id_def; - while (impmod) { - if (impmod->df_kind == D_IMPORT && - impmod->imp_def == moddef) { - DoImport(df, impmod->df_scope); - } - impmod = impmod->next; - } - - df1 = lookup(ids->nd_IDF, enclosing(CurrVis)->sc_scope); - if (df1 && df1->df_kind == D_PROCHEAD) { - if (df->df_kind == D_PROCEDURE) { - df1->df_kind = D_IMPORT; - df1->imp_def = df; - continue; - } - } - else if (df1 && df1->df_kind == D_HIDDEN) { - if (df->df_kind == D_TYPE) { - if (df->df_type->tp_fund != T_POINTER) { -error("opaque type \"%s\" is not a pointer type", df->df_idf->id_text); - } - df->df_kind = D_TYPE; - df1->df_kind = D_IMPORT; - df1->imp_def = df; - continue; - } - } - - DoImport(df, enclosing(CurrVis)->sc_scope); - } - } -} - -static struct scopelist * -ForwModule(df, idn) - register struct def *df; - struct node *idn; -{ - /* An import is done from a not yet defined module "idn". - Create a declaration and a scope for this module. - */ - struct scopelist *vis; - - df->df_scope = enclosing(CurrVis)->sc_scope; - df->df_kind = D_FORWMODULE; - open_scope(CLOSEDSCOPE); - vis = CurrVis; /* The new scope, but watch out, it's "sc_encl" - field is not set right. It must indicate the - enclosing scope, but this must be done AFTER - closing this one - */ - df->for_vis = vis; - df->for_node = MkLeaf(Name, &(idn->nd_token)); - close_scope(0); - vis->sc_encl = enclosing(CurrVis); - /* Here ! */ - return vis; -} - -static struct def * -ForwDef(ids, scope) - register struct node *ids; - struct scope *scope; -{ - /* Enter a forward definition of "ids" in scope "scope", - if it is not already defined. - */ - register struct def *df; - - if (!(df = lookup(ids->nd_IDF, scope))) { - df = define(ids->nd_IDF, scope, D_FORWARD); - df->for_node = MkLeaf(Name, &(ids->nd_token)); - } - return df; -} - -Import(ids, idn, local) - register struct node *ids; - struct node *idn; -{ - /* "ids" is a list of imported identifiers. - If "idn" is a null-pointer, the identifiers are imported from - the enclosing scope. Otherwise they are imported from the module - indicated by "idn", which must be visible in the enclosing - scope. An exception must be made for imports of the - Compilation Unit. - This case is indicated by the value 0 of the flag "local". - In this case, if "idn" is a null pointer, the "ids" identifiers - are all module identifiers. Their Definition Modules must be - read. Otherwise "idn" is a module identifier whose Definition - Module must be read. "ids" then represents a list of - identifiers defined in this module. - */ - register struct def *df; - struct scopelist *vis = enclosing(CurrVis); - int forwflag = 0; -#define FROM_MODULE 0 -#define FROM_ENCLOSING 1 - int imp_kind = FROM_ENCLOSING; - struct def *lookfor(), *GetDefinitionModule(); - - if (idn) { - imp_kind = FROM_MODULE; - if (local) { - df = lookfor(idn, vis, 0); - switch(df->df_kind) { - case D_ERROR: - /* The module from which the import was done - is not yet declared. I'm not sure if I must - accept this, but for the time being I will. - ??? - */ - vis = ForwModule(df, idn); - forwflag = 1; - break; - case D_FORWMODULE: - vis = df->for_vis; - break; - case D_MODULE: - vis = df->mod_vis; - break; - default: -node_error(idn, "identifier \"%s\" does not represent a module", -idn->nd_IDF->id_text); - break; - } - } - else vis = GetDefinitionModule(idn->nd_IDF)->mod_vis; - - FreeNode(idn); - } - - idn = ids; - while (ids) { - if (imp_kind == FROM_MODULE) { - if (forwflag) { - df = ForwDef(ids, vis->sc_scope); - } - else if (!(df = lookup(ids->nd_IDF, vis->sc_scope))) { -node_error(ids, "identifier \"%s\" not declared in qualifying module", -ids->nd_IDF->id_text); - df = define(ids->nd_IDF,vis->sc_scope,D_ERROR); - } - else if (!(df->df_flags&(D_EXPORTED|D_QEXPORTED))) { -node_error(ids,"identifier \"%s\" not exported from qualifying module", -ids->nd_IDF->id_text); - df->df_flags |= D_QEXPORTED; - } - } - else { - if (local) df = ForwDef(ids, vis->sc_scope); - else df = GetDefinitionModule(ids->nd_IDF); - } - - DoImport(df, CurrentScope); - - ids = ids->next; - } - - FreeNode(idn); -} - RemoveImports(pdf) struct def **pdf; { diff --git a/lang/m2/comp/desig.c b/lang/m2/comp/desig.c index 69eb62b8..3cde10de 100644 --- a/lang/m2/comp/desig.c +++ b/lang/m2/comp/desig.c @@ -319,7 +319,7 @@ CodeDesig(nd, ds) CodeFieldDesig(nd->nd_def, ds); break; - case Oper: + case Arrsel: assert(nd->nd_symb == '['); CodeDesig(nd->nd_left, ds); @@ -347,7 +347,7 @@ CodeDesig(nd, ds) ds->dsg_kind = DSG_INDEXED; break; - case Uoper: + case Arrow: assert(nd->nd_symb == '^'); CodeDesig(nd->nd_right, ds); diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index 424c423b..6184d23d 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -1,4 +1,4 @@ -/* H I G H L E V E L S Y M B O L E N T R Y A N D L O O K U P */ +/* H I G H L E V E L S Y M B O L E N T R Y */ #ifndef NORCSID static char *RcsId = "$Header$"; @@ -28,86 +28,65 @@ Enter(name, kind, type, pnam) "type" in the Current Scope. If it is a standard name, also put its number in the definition structure. */ - struct idf *id; - struct def *df; + register struct def *df; - id = str2idf(name, 0); - if (!id) fatal("Out of core"); - df = define(id, CurrentScope, kind); + df = define(str2idf(name, 0), CurrentScope, kind); df->df_type = type; - if (type = std_type) { - df->df_value.df_stdname = pnam; - } + if (pnam) df->df_value.df_stdname = pnam; return df; } -EnterIdList(idlist, kind, flags, type, scope, addr) - register struct node *idlist; - struct type *type; +EnterEnumList(Idlist, type) + struct node *Idlist; + register struct type *type; +{ + /* Put a list of enumeration literals in the symbol table. + They all have type "type". + Also assign numbers to them, and link them together. + We must link them together because an enumeration type may + be exported, in which case its literals must also be exported. + Thus, we need an easy way to get to them. + */ + register struct def *df; + register struct node *idlist = Idlist; + + type->enm_ncst = 0; + for (; idlist; idlist = idlist->next) { + df = define(idlist->nd_IDF, CurrentScope, D_ENUM); + df->df_type = type; + df->enm_val = (type->enm_ncst)++; + df->enm_next = type->enm_enums; + type->enm_enums = df; + } + FreeNode(Idlist); +} + +EnterFieldList(Idlist, type, scope, addr) + struct node *Idlist; + register struct type *type; struct scope *scope; arith *addr; { - /* Put a list of identifiers in the symbol table. - They all have kind "kind", and type "type", and are put - in scope "scope". "flags" initializes the "df_flags" field - of the definition structure. - Also assign numbers to enumeration literals, and link - them together. + /* Put a list of fields in the symbol table. + They all have type "type", and are put in scope "scope". + Mark them as QUALIFIED EXPORT, because that's exactly what + fields are, you can get to them by qualifying them. */ register struct def *df; - struct def *first = 0, *last = 0; - int assval = 0; - arith off; + register struct node *idlist = Idlist; - while (idlist) { - df = define(idlist->nd_IDF, scope, kind); + for (; idlist; idlist = idlist->next) { + df = define(idlist->nd_IDF, scope, D_FIELD); df->df_type = type; - df->df_flags |= flags; - if (addr) { - int xalign = type->tp_align; - - if (xalign < word_align && kind != D_FIELD) { - /* variables are at least word aligned - */ - xalign = word_align; - } - - if (*addr >= 0) { - off = align(*addr, xalign); - *addr = off + type->tp_size; - } - else { - off = -align(-*addr-type->tp_size, xalign); - *addr = off; - } - if (kind == D_VARIABLE) { - df->var_off = off; - } - else { - assert(kind == D_FIELD); - - df->fld_off = off; - } - } - if (kind == D_ENUM) { - if (!first) first = df; - df->enm_val = assval++; - if (last) last->enm_next = df; - last = df; - } - idlist = idlist->next; - } - if (last) { - /* Also meaning : kind == D_ENUM */ - assert(kind == D_ENUM); - last->enm_next = 0; - type->enm_enums = first; - type->enm_ncst = assval; + df->df_flags |= D_QEXPORTED; + df->fld_off = align(*addr, type->tp_align); + *addr = df->fld_off + type->tp_size; } + FreeNode(Idlist); } -EnterVarList(IdList, type, local) - register struct node *IdList; +EnterVarList(Idlist, type, local) + struct node *Idlist; struct type *type; { /* Enter a list of identifiers representing variables into the @@ -116,6 +95,7 @@ EnterVarList(IdList, type, local) procedure. */ register struct def *df; + register struct node *idlist = Idlist; register struct scopelist *sc; char buf[256]; extern char *sprint(); @@ -129,17 +109,17 @@ EnterVarList(IdList, type, local) while (sc->sc_scope->sc_scopeclosed) sc = enclosing(sc); } - while (IdList) { - df = define(IdList->nd_IDF, CurrentScope, D_VARIABLE); + for (; idlist; idlist = idlist->nd_right) { + df = define(idlist->nd_IDF, CurrentScope, D_VARIABLE); df->df_type = type; - if (IdList->nd_left) { + if (idlist->nd_left) { /* An address was supplied */ df->var_addrgiven = 1; - if (IdList->nd_left->nd_type != card_type) { -node_error(IdList->nd_left,"Illegal type for address"); + if (idlist->nd_left->nd_type != card_type) { +node_error(idlist->nd_left,"Illegal type for address"); } - df->var_off = IdList->nd_left->nd_INT; + df->var_off = idlist->nd_left->nd_INT; } else if (local) { /* subtract aligned size of variable to the offset, @@ -147,8 +127,8 @@ node_error(IdList->nd_left,"Illegal type for address"); procedure */ sc->sc_scope->sc_off = - -align(type->tp_size - sc->sc_scope->sc_off, - type->tp_align); + -WA(align(type->tp_size - sc->sc_scope->sc_off, + type->tp_align)); df->var_off = sc->sc_scope->sc_off; } else { @@ -165,32 +145,279 @@ node_error(IdList->nd_left,"Illegal type for address"); C_ina_dnam(df->var_name); } } - - IdList = IdList->nd_right; } + FreeNode(Idlist); } -struct def * -lookfor(id, vis, give_error) - struct node *id; - struct scopelist *vis; +EnterParamList(ppr, Idlist, type, VARp, off) + struct node *Idlist; + struct paramlist **ppr; + struct type *type; + int VARp; + arith *off; { - /* Look for an identifier in the visibility range started by - "vis". - If it is not defined, maybe give an error message, and - create a dummy definition. + /* Create (part of) a parameterlist of a procedure. + "ids" indicates the list of identifiers, "tp" their type, and + "VARp" indicates D_VARPAR or D_VALPAR. */ - struct def *df; - register struct scopelist *sc = vis; - struct def *MkDef(); + register struct paramlist *pr; + register struct def *df; + register struct node *idlist = Idlist; - while (sc) { - df = lookup(id->nd_IDF, sc->sc_scope); - if (df) return df; - sc = nextvisible(sc); + for ( ; idlist; idlist = idlist->next) { + pr = new_paramlist(); + pr->next = *ppr; + *ppr = pr; + df = define(idlist->nd_IDF, CurrentScope, D_VARIABLE); + pr->par_def = df; + df->df_type = type; + df->var_off = *off; + df->df_flags = VARp; + if (IsConformantArray(type)) { + /* we need room for the base address and a descriptor + */ + *off += pointer_size + 3 * word_size; + } + else if (VARp == D_VARPAR) { + *off += pointer_size; + } + else { + *off += WA(type->tp_size); + } + } + FreeNode(Idlist); +} + +static +DoImport(df, scope) + register struct def *df; + struct scope *scope; +{ + /* Definition "df" is imported to scope "scope". + Handle the case that it is an enumeration type or a module. + */ + + define(df->df_idf, scope, D_IMPORT)->imp_def = df; + + if (df->df_kind == D_TYPE && df->df_type->tp_fund == T_ENUMERATION) { + /* Also import all enumeration literals + */ + df = df->df_type->enm_enums; + while (df) { + define(df->df_idf, scope, D_IMPORT)->imp_def = df; + df = df->enm_next; + } + } + else if (df->df_kind == D_MODULE) { + /* Also import all definitions that are exported from this + module + */ + df = df->mod_vis->sc_scope->sc_def; + while (df) { + if (df->df_flags & D_EXPORTED) { + define(df->df_idf,scope,D_IMPORT)->imp_def = df; + } + df = df->df_nextinscope; + } + } +} + +static struct scopelist * +ForwModule(df, idn) + register struct def *df; + struct node *idn; +{ + /* An import is done from a not yet defined module "idn". + Create a declaration and a scope for this module. + */ + struct scopelist *vis; + + df->df_scope = enclosing(CurrVis)->sc_scope; + df->df_kind = D_FORWMODULE; + open_scope(CLOSEDSCOPE); + vis = CurrVis; /* The new scope, but watch out, it's "sc_encl" + field is not set right. It must indicate the + enclosing scope, but this must be done AFTER + closing this one + */ + df->for_vis = vis; + df->for_node = MkLeaf(Name, &(idn->nd_token)); + close_scope(0); + vis->sc_encl = enclosing(CurrVis); + /* Here ! */ + return vis; +} + +static struct def * +ForwDef(ids, scope) + register struct node *ids; + struct scope *scope; +{ + /* Enter a forward definition of "ids" in scope "scope", + if it is not already defined. + */ + register struct def *df; + + if (!(df = lookup(ids->nd_IDF, scope))) { + df = define(ids->nd_IDF, scope, D_FORWARD); + df->for_node = MkLeaf(Name, &(ids->nd_token)); + } + return df; +} + +EnterExportList(Idlist, qualified) + struct node *Idlist; +{ + /* From the current scope, the list of identifiers "ids" is + exported. Note this fact. If the export is not qualified, make + all the "ids" visible in the enclosing scope by defining them + in this scope as "imported". + */ + register struct node *idlist = Idlist; + register struct def *df, *df1; + register struct def *impmod; + + for (;idlist; idlist = idlist->next) { + df = lookup(idlist->nd_IDF, CurrentScope); + + if (!df) { + /* undefined item in export list + */ +node_error(idlist, "identifier \"%s\" not defined", idlist->nd_IDF->id_text); + continue; + } + + if (df->df_flags & (D_EXPORTED|D_QEXPORTED)) { +node_error(idlist, "identifier \"%s\" occurs more than once in export list", +idlist->nd_IDF->id_text); + } + + df->df_flags |= qualified; + if (qualified == D_EXPORTED) { + /* Export, but not qualified. + Find all imports of the module in which this export + occurs, and export the current definition to it + */ + impmod = CurrentScope->sc_definedby->df_idf->id_def; + while (impmod) { + if (impmod->df_kind == D_IMPORT && + impmod->imp_def == CurrentScope->sc_definedby) { + DoImport(df, impmod->df_scope); + } + impmod = impmod->next; + } + + /* Also handle the definition as if the enclosing + scope imports it. + */ + df1 = lookup(idlist->nd_IDF, + enclosing(CurrVis)->sc_scope); + if (df1) { + /* It was already defined in the enclosing + scope. There are two legal possibilities, + which are examined below. + */ + if ((df1->df_kind == D_PROCHEAD && + df->df_kind == D_PROCEDURE) || + (df1->df_kind == D_HIDDEN && + df->df_kind == D_TYPE)) { + if (df->df_kind == D_TYPE && + df->df_type->tp_fund != T_POINTER) { +node_error(idlist, "opaque type \"%s\" is not a pointer type", df->df_idf->id_text); + } + df1->df_kind = D_IMPORT; + df1->imp_def = df; + continue; + } + } + + DoImport(df, enclosing(CurrVis)->sc_scope); + } + } + FreeNode(Idlist); +} + +EnterFromImportList(Idlist, Fromid, local) + struct node *Idlist; + register struct node *Fromid; +{ + /* Import the list Idlist from the module indicated by Fromid. + An exception must be made for imports of the Compilation Unit, + because in this case the definition module for Fromid must + be read. + This case is indicated by the value 0 of the flag "local". + */ + register struct node *idlist = Idlist; + register struct def *df; + struct scopelist *vis = enclosing(CurrVis); + int forwflag = 0; + extern struct def *lookfor(), *GetDefinitionModule(); + + if (local) { + df = lookfor(Fromid, vis, 0); + switch(df->df_kind) { + case D_ERROR: + /* The module from which the import was done + is not yet declared. I'm not sure if I must + accept this, but for the time being I will. + ??? + */ + vis = ForwModule(df, Fromid); + forwflag = 1; + break; + case D_FORWMODULE: + vis = df->for_vis; + break; + case D_MODULE: + vis = df->mod_vis; + break; + default: +node_error(Fromid, "identifier \"%s\" does not represent a module", +Fromid->nd_IDF->id_text); + break; + } + } + else vis = GetDefinitionModule(Fromid->nd_IDF)->mod_vis; + + FreeNode(Fromid); + + for (; idlist; idlist = idlist->next) { + if (forwflag) { + df = ForwDef(idlist, vis->sc_scope); + } + else if (!(df = lookup(idlist->nd_IDF, vis->sc_scope))) { +node_error(idlist, "identifier \"%s\" not declared in qualifying module", +idlist->nd_IDF->id_text); + df = define(idlist->nd_IDF,vis->sc_scope,D_ERROR); + } + else if (!(df->df_flags&(D_EXPORTED|D_QEXPORTED))) { +node_error(idlist,"identifier \"%s\" not exported from qualifying module", +idlist->nd_IDF->id_text); + df->df_flags |= D_QEXPORTED; + } + DoImport(df, CurrentScope); } - if (give_error) id_not_declared(id); - - return MkDef(id->nd_IDF, vis->sc_scope, D_ERROR); + FreeNode(Idlist); +} + +EnterImportList(Idlist, local) + struct node *Idlist; +{ + /* Import "Idlist" from the enclosing scope. + An exception must be made for imports of the compilation unit. + In this case, definition modules must be read for "Idlist". + This case is indicated by the value 0 of the "local" flag. + */ + register struct node *idlist = Idlist; + register struct def *df; + struct scopelist *vis = enclosing(CurrVis); + extern struct def *lookfor(), *GetDefinitionModule(); + + for (; idlist; idlist = idlist->next) { + if (local) df = ForwDef(idlist, vis->sc_scope); + else df = GetDefinitionModule(idlist->nd_IDF); + DoImport(df, CurrentScope); + } + FreeNode(Idlist); } diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index 983042cd..bfdfe427 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -258,16 +258,16 @@ designator_tail(struct node **pnd;): ; visible_designator_tail(struct node **pnd;): - '[' { *pnd = MkNode(Oper, *pnd, NULLNODE, &dot); } + '[' { *pnd = MkNode(Arrsel, *pnd, NULLNODE, &dot); } expression(&((*pnd)->nd_right)) [ ',' - { *pnd = MkNode(Oper, *pnd, NULLNODE, &dot); + { *pnd = MkNode(Arrsel, *pnd, NULLNODE, &dot); (*pnd)->nd_symb = '['; } expression(&((*pnd)->nd_right)) ]* ']' | - '^' { *pnd = MkNode(Uoper, NULLNODE, *pnd, &dot); } + '^' { *pnd = MkNode(Arrow, NULLNODE, *pnd, &dot); } ; diff --git a/lang/m2/comp/lookup.c b/lang/m2/comp/lookup.c new file mode 100644 index 00000000..a150d79a --- /dev/null +++ b/lang/m2/comp/lookup.c @@ -0,0 +1,74 @@ +/* L O O K U P R O U T I N E S */ + +#ifndef NORCSID +static char *RcsId = "$Header$"; +#endif + +#include "debug.h" + +#include +#include +#include + +#include "def.h" +#include "idf.h" +#include "scope.h" +#include "LLlex.h" +#include "node.h" + +extern struct def *MkDef(); + +struct def * +lookup(id, scope) + register struct idf *id; + struct scope *scope; +{ + /* Look up a definition of an identifier in scope "scope". + Make the "def" list self-organizing. + Return a pointer to its "def" structure if it exists, + otherwise return 0. + */ + register struct def *df; + struct def *df1; + + for (df = id->id_def, df1 = 0; df; df1 = df, df = df->next) { + if (df->df_scope == scope) { + if (df1) { + /* Put the definition in front + */ + df1->next = df->next; + df->next = id->id_def; + id->id_def = df; + } + if (df->df_kind == D_IMPORT) { + assert(df->imp_def != 0); + return df->imp_def; + } + return df; + } + } + return 0; +} + +struct def * +lookfor(id, vis, give_error) + register struct node *id; + struct scopelist *vis; +{ + /* Look for an identifier in the visibility range started by "vis". + If it is not defined create a dummy definition and, + if "give_error" is set, give an error message. + */ + struct def *df; + register struct scopelist *sc = vis; + + while (sc) { + df = lookup(id->nd_IDF, sc->sc_scope); + if (df) return df; + sc = nextvisible(sc); + } + + if (give_error) id_not_declared(id); + + return MkDef(id->nd_IDF, vis->sc_scope, D_ERROR); +} diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index 79dc43e1..4a43718c 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -146,7 +146,7 @@ LexScan() AddStandards() { register struct def *df; - struct def *Enter(); + extern struct def *Enter(); static struct node nilnode = { 0, 0, Value, 0, { INTEGER, 0}}; (void) Enter("ABS", D_PROCEDURE, std_type, S_ABS); @@ -184,11 +184,11 @@ AddStandards() construct_type(T_PROCEDURE, NULLTYPE), 0); df = Enter("BITSET", D_TYPE, bitset_type, 0); - df = Enter("FALSE", D_ENUM, bool_type, 0); - df->enm_val = 0; - df->enm_next = Enter("TRUE", D_ENUM, bool_type, 0); - df = df->enm_next; + df = Enter("TRUE", D_ENUM, bool_type, 0); df->enm_val = 1; + df->enm_next = Enter("FALSE", D_ENUM, bool_type, 0); + df = df->enm_next; + df->enm_val = 0; df->enm_next = 0; } diff --git a/lang/m2/comp/node.H b/lang/m2/comp/node.H index dfbe94fe..ca2bf228 100644 --- a/lang/m2/comp/node.H +++ b/lang/m2/comp/node.H @@ -7,15 +7,17 @@ struct node { #define nd_left next struct node *nd_right; int nd_class; /* kind of node */ -#define Value 1 /* constant */ +#define Value 0 /* constant */ +#define Arrsel 1 /* array selection */ #define Oper 2 /* binary operator */ #define Uoper 3 /* unary operator */ -#define Call 4 /* cast or procedure - or function call */ -#define Name 5 /* an identifier */ -#define Set 6 /* a set constant */ -#define Xset 7 /* a set */ -#define Def 8 /* an identified name */ -#define Stat 9 /* a statement */ +#define Arrow 4 /* ^ construction */ +#define Call 5 /* cast or procedure - or function call */ +#define Name 6 /* an identifier */ +#define Set 7 /* a set constant */ +#define Xset 8 /* a set */ +#define Def 9 /* an identified name */ +#define Stat 10 /* a statement */ #define Link 11 struct type *nd_type; /* type of this node */ struct token nd_token; diff --git a/lang/m2/comp/options.c b/lang/m2/comp/options.c index 6da42772..25f16c90 100644 --- a/lang/m2/comp/options.c +++ b/lang/m2/comp/options.c @@ -22,7 +22,7 @@ DoOption(text) switch(*text++) { default: - options[text[-1]] = 1; /* flags, debug options etc. */ + options[text[-1]]++; /* flags, debug options etc. */ break; case 'L' : /* don't generate fil/lin */ diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index cf8aed10..32cba66b 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -76,12 +76,11 @@ ModuleDeclaration priority(&(df->mod_priority))? ';' import(1)* - export(&qualified, &exportlist, 0)? + export(&qualified, &exportlist)? block(&nd) IDENT { InitProc(nd, df); if (exportlist) { - Export(exportlist, qualified, df); - FreeNode(exportlist); + EnterExportList(exportlist, qualified); } close_scope(SC_CHKFORW|SC_CHKPROC|SC_REVERSE); match_id(id, dot.TOK_IDF); @@ -101,23 +100,17 @@ priority(arith *pprio;) } ; -export(int *QUALflag; struct node **ExportList; int def;) +export(int *QUALflag; struct node **ExportList;) { } : EXPORT [ QUALIFIED - { *QUALflag = 1; } + { *QUALflag = D_QEXPORTED; } | - { *QUALflag = 0; } + { *QUALflag = D_EXPORTED; } ] IdentList(ExportList) ';' - { - if (def) { -node_warning(*ExportList, "export list in definition module ignored"); - FreeNode(*ExportList); - } - } ; import(int local;) @@ -135,8 +128,8 @@ import(int local;) If the FROM clause is present, the identifier in it is a module name, otherwise the names in the import list are module names. */ - { - Import(ImportList, id, local); + { if (id) EnterFromImportList(ImportList, id, local); + else EnterImportList(ImportList, local); } ; @@ -144,7 +137,7 @@ DefinitionModule { register struct def *df; struct idf *id; - struct node *exportlist; + struct node *exportlist = 0; int dummy; } : DEFINITION @@ -163,11 +156,16 @@ DefinitionModule } ';' import(0)* - export(&dummy, &exportlist, 1)? + export(&dummy, &exportlist)? /* New Modula-2 does not have export lists in definition modules. For the time being, we ignore export lists here, and a warning is issued. */ + { if (exportlist) { +node_warning(exportlist, "export list in definition module ignored"); + FreeNode(exportlist); + } + } definition* END IDENT { df = CurrentScope->sc_def; diff --git a/lang/m2/comp/tmpvar.C b/lang/m2/comp/tmpvar.C index c4778bf2..f6362705 100644 --- a/lang/m2/comp/tmpvar.C +++ b/lang/m2/comp/tmpvar.C @@ -6,6 +6,9 @@ static char *RcsId = "$Header$"; /* Code for the allocation and de-allocation of temporary variables, allowing re-use. + The routines use "ProcScope" instead of "CurrentScope", because + "CurrentScope" also reflects WITH statements, and these scopes do not + have local variabes. */ #include "debug.h" @@ -29,8 +32,9 @@ struct tmpvar { static struct tmpvar *TmpInts, /* for integer temporaries */ *TmpPtrs; /* for pointer temporaries */ - -extern arith align(); +extern struct scope *ProcScope; /* scope of procedure in which the + temporaries are allocated + */ arith NewInt() @@ -39,8 +43,8 @@ NewInt() register struct tmpvar *tmp; if (!TmpInts) { - offset = - align(int_size - CurrentScope->sc_off, int_align); - CurrentScope->sc_off = offset; + offset = - WA(align(int_size - ProcScope->sc_off, int_align)); + ProcScope->sc_off = offset; C_ms_reg(offset, int_size, reg_any, 0); } else { @@ -59,8 +63,8 @@ NewPtr() register struct tmpvar *tmp; if (!TmpPtrs) { - offset = - align(pointer_size - CurrentScope->sc_off, pointer_align); - CurrentScope->sc_off = offset; + offset = - WA(align(pointer_size - ProcScope->sc_off, pointer_align)); + ProcScope->sc_off = offset; C_ms_reg(offset, pointer_size, reg_pointer, 0); } else { diff --git a/lang/m2/comp/type.H b/lang/m2/comp/type.H index 010b9e04..90b56e35 100644 --- a/lang/m2/comp/type.H +++ b/lang/m2/comp/type.H @@ -138,3 +138,4 @@ struct type #define complex(tpx) ((tpx)->tp_fund & (T_RECORD|T_ARRAY)) #define returntype(tpx) (((tpx)->tp_fund & T_PRCRESULT) ||\ ((tpx)->tp_fund == T_SET && (tpx)->tp_size <= dword_size)) +#define WA(sz) (align(sz, (int) word_size)) diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index 89360b85..ae272a6f 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -221,43 +221,6 @@ InitTypes() error_type = standard_type(T_CHAR, 1, (arith) 1); } -ParamList(ppr, ids, tp, VARp, off) - register struct node *ids; - struct paramlist **ppr; - struct type *tp; - int VARp; - arith *off; -{ - /* Create (part of) a parameterlist of a procedure. - "ids" indicates the list of identifiers, "tp" their type, and - "VARp" indicates D_VARPAR or D_VALPAR. - */ - register struct paramlist *pr; - register struct def *df; - - for ( ; ids; ids = ids->next) { - pr = new_paramlist(); - pr->next = *ppr; - *ppr = pr; - df = define(ids->nd_IDF, CurrentScope, D_VARIABLE); - pr->par_def = df; - df->df_type = tp; - df->var_off = align(*off, word_align); - df->df_flags = VARp; - if (IsConformantArray(tp)) { - /* we need room for the base address and a descriptor - */ - *off = df->var_off + pointer_size + 3 * word_size; - } - else if (VARp == D_VARPAR) { - *off = df->var_off + pointer_size; - } - else { - *off = df->var_off + tp->tp_size; - } - } -} - chk_basesubrange(tp, base) register struct type *tp, *base; { @@ -417,7 +380,7 @@ set_type(tp) } tp = construct_type(T_SET, tp); - tp->tp_size = align(((ub - lb) + 7)/8, word_align); + tp->tp_size = WA(((ub - lb) + 7)/8); return tp; } @@ -433,8 +396,11 @@ ArrayElSize(tp) if (tp->tp_fund == T_ARRAY) ArraySizes(tp); algn = align(tp->tp_size, tp->tp_align); - if (!(algn % word_size == 0 || word_size % algn == 0)) { - algn = align(algn, (int) word_size); + if (word_size % algn != 0) { + /* algn is not a dividor of the word size, so make sure it + is a multiple + */ + algn = WA(algn); } return algn; } @@ -481,8 +447,9 @@ ArraySizes(tp) default: crash("Funny index type"); } - + C_rom_cst(tp->arr_elsize); + tp->tp_size = WA(tp->tp_size); /* ??? overflow checking ??? */ diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index cc48c91c..a68f48f6 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -33,6 +33,7 @@ static char return_expr_occurred; static struct type *func_type; struct withdesig *WithDesigs; struct node *Modules; +struct scope *ProcScope; label text_label() @@ -87,7 +88,7 @@ WalkModule(module) if (df->df_kind == D_VARIABLE) { C_df_dnam(df->var_name); C_bss_cst( - align(df->df_type->tp_size, word_align), + WA(df->df_type->tp_size), (arith) 0, 0); } df = df->df_nextinscope; @@ -107,6 +108,7 @@ WalkModule(module) sc->sc_off = 0; instructionlabel = 2; func_type = 0; + ProcScope = CurrentScope; C_pro_narg(state == PROGRAM ? "main" : sc->sc_name); DoProfil(); if (CurrVis == Defined->mod_vis) { @@ -161,7 +163,7 @@ WalkProcedure(procedure) proclevel++; CurrVis = procedure->prc_vis; - sc = CurrentScope; + ProcScope = sc = CurrentScope; WalkDef(sc->sc_def); @@ -185,7 +187,7 @@ WalkProcedure(procedure) if (! return_expr_occurred) { node_error(procedure->prc_body,"function procedure does not return a value"); } - C_ret(align(res_type->tp_size, word_align)); + C_ret(WA(res_type->tp_size)); } else C_ret((arith) 0); C_end(-sc->sc_off); @@ -341,7 +343,7 @@ WalkStat(nd, lab) l1 = instructionlabel++; l2 = instructionlabel++; C_df_ilb(l1); - WalkNode(left, l2); + WalkNode(right, l2); C_bra(l1); C_df_ilb(l2); break; @@ -425,7 +427,7 @@ WalkStat(nd, lab) case RETURN: if (right) { - WalkExpr(right, NO_LABEL, NO_LABEL); + WalkExpr(right); /* Assignment compatibility? Yes, see Rep. 9.11 */ if (!TstAssCompat(func_type, right->nd_type)) { @@ -449,16 +451,18 @@ ExpectBool(nd, true_label, false_label) generate code to evaluate the expression. */ - WalkExpr(nd, true_label, false_label); + if (!chk_expr(nd)) return; if (nd->nd_type != bool_type && nd->nd_type != error_type) { node_error(nd, "boolean expression expected"); } + + Desig = InitDesig; + CodeExpr(nd, &Desig, true_label, false_label); } -WalkExpr(nd, true_label, false_label) +WalkExpr(nd) struct node *nd; - label true_label, false_label; { /* Check an expression and generate code for it */ @@ -467,8 +471,7 @@ WalkExpr(nd, true_label, false_label) if (! chk_expr(nd)) return; - Desig = InitDesig; - CodeExpr(nd, &Desig, true_label, false_label); + CodePExpr(nd); } WalkDesignator(nd) @@ -568,6 +571,8 @@ DumpTree(nd) switch(nd->nd_class) { case Def: s = "Def"; break; case Oper: s = "Oper"; break; + case Arrsel: s = "Arrsel"; break; + case Arrow: s = "Arrow"; break; case Uoper: s = "Uoper"; break; case Name: s = "Name"; break; case Set: s = "Set"; break; From a01826972486deee9f57d2fad46367e83d1f2e18 Mon Sep 17 00:00:00 2001 From: sater Date: Mon, 16 Jun 1986 11:35:12 +0000 Subject: [PATCH 0207/1625] Conversions from 1 byte integers were wrong. Only discovered after new C-frontend. --- mach/i86/cg/table | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/mach/i86/cg/table b/mach/i86/cg/table index d2440d0e..b444751c 100644 --- a/mach/i86/cg/table +++ b/mach/i86/cg/table @@ -1126,12 +1126,11 @@ cfu | CXREG DXREG | cff | CXREG DXREG | remove(ALL) "call .cff" | | | -loc loc cii $1==1 && $2==2 | ACC1 | - allocate(%[1],ACC) +loc loc cii $1==1 && $2==2 | ACC | "cbw" - samecc | %[a] | |(1,2) -loc loc cii $1==1 && $2==4 | ACC1 | - allocate(%[1],ACC,DXREG) + samecc | ax | |(1,2) +loc loc cii $1==1 && $2==4 | ACC | + allocate(DXREG) "cbw" "cwd" samecc | dx ax | |(2,7) From 60a59064562dfe1766f2e77ae3447c0b79a27bd7 Mon Sep 17 00:00:00 2001 From: sater Date: Tue, 17 Jun 1986 09:13:11 +0000 Subject: [PATCH 0208/1625] removed sanity checking on result from sprintf System IIIish systems seem to have their own idea. --- util/opt/getline.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/util/opt/getline.c b/util/opt/getline.c index d1080f9c..e85bfd33 100644 --- a/util/opt/getline.c +++ b/util/opt/getline.c @@ -5,7 +5,6 @@ static char rcsid[] = "$Header$"; #include #include "param.h" #include "types.h" -#include "assert.h" #include "line.h" #include "lookup.h" #include "alloc.h" @@ -123,11 +122,8 @@ offset getoff() { } make_string(n) int n; { - register char *s; - extern char *sprintf(); - s=sprintf(string,".%u",n); - assert(s == string); + sprintf(string,".%u",n); } inident() { From f0d88d3de32b9f82511de638f80c7fb98b5028db Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 17 Jun 1986 12:04:05 +0000 Subject: [PATCH 0209/1625] newer version --- lang/m2/comp/LLlex.c | 20 +- lang/m2/comp/Makefile | 18 +- lang/m2/comp/chk_expr.c | 516 +++++++++++++++++++------------------- lang/m2/comp/chk_expr.h | 9 + lang/m2/comp/code.c | 119 ++++----- lang/m2/comp/declar.g | 1 - lang/m2/comp/def.H | 6 +- lang/m2/comp/def.c | 47 +++- lang/m2/comp/desig.c | 7 +- lang/m2/comp/desig.h | 2 +- lang/m2/comp/enter.c | 25 +- lang/m2/comp/expression.g | 12 +- lang/m2/comp/lookup.c | 2 - lang/m2/comp/misc.c | 4 +- lang/m2/comp/node.H | 1 + lang/m2/comp/node.c | 8 +- lang/m2/comp/program.g | 43 +--- lang/m2/comp/scope.C | 13 +- lang/m2/comp/statement.g | 10 +- lang/m2/comp/type.c | 121 ++++----- lang/m2/comp/walk.c | 105 +++++--- 21 files changed, 573 insertions(+), 516 deletions(-) create mode 100644 lang/m2/comp/chk_expr.h diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index 5f4c8b43..20d08b3b 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -33,7 +33,7 @@ int idfsize = IDFSIZE; extern int cntlines; #endif -static +STATIC SkipComment() { /* Skip Modula-2 comments (* ... *). @@ -50,16 +50,12 @@ SkipComment() cntlines++; #endif } - else - if (ch == '(') { + else if (ch == '(') { LoadChar(ch); - if (ch == '*') { - ++NestLevel; - } + if (ch == '*') ++NestLevel; else continue; } - else - if (ch == '*') { + else if (ch == '*') { LoadChar(ch); if (ch == ')') { if (NestLevel-- == 0) return; @@ -70,7 +66,7 @@ SkipComment() } } -static +STATIC GetString(upto) { /* Read a Modula-2 string, delimited by the character "upto". @@ -118,11 +114,13 @@ LLlex() register int ch, nch; toktype = error_type; + if (ASIDE) { /* a token is put aside */ *tk = aside; ASIDE = 0; return tk->tk_symb; } + tk->tk_lineno = LineNumber; again: @@ -216,8 +214,7 @@ again: LoadChar(ch); } while(in_idf(ch)); - if (ch != EOI) - PushBack(ch); + if (ch != EOI) PushBack(ch); *tg++ = '\0'; tk->TOK_IDF = id = str2idf(buf, 1); @@ -396,6 +393,7 @@ Sreal: lexerror("floating constant too long"); } else tk->TOK_REL = Salloc(buf, np - buf) + 1; + toktype = real_type; return tk->tk_symb = REAL; default: diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index a295f17f..48df7b4c 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -9,10 +9,11 @@ INCLUDES = -I$(HDIR) -I/usr/em/h -I$(PKGDIR) -I/user1/erikb/em/h LSRC = tokenfile.g program.g declar.g expression.g statement.g CC = cc -GEN = LLgen -GENOPTIONS = -PROFILE = -CFLAGS = $(PROFILE) $(INCLUDES) +GEN = /usr/em/util/LLgen/src/LLgen +GENOPTIONS = -d +PROFILE = -p +CFLAGS = $(PROFILE) $(INCLUDES) -DSTATIC= +LINTFLAGS = -DSTATIC= -DNORCSID LFLAGS = $(PROFILE) LOBJ = tokenfile.o program.o declar.o expression.o statement.o COBJ = LLlex.o LLmessage.o char.o error.o main.o \ @@ -46,7 +47,7 @@ clean: rm -f $(OBJ) $(GENFILES) LLfiles lint: LLfiles hfiles - lint $(INCLUDES) -DNORCSID `sources $(OBJ)` + lint $(INCLUDES) $(LINTFLAGS) `sources $(OBJ)` tokenfile.g: tokenname.c make.tokfile make.tokfile tokenfile.g @@ -98,16 +99,17 @@ defmodule.o: LLlex.h debug.h def.h f_info.h idf.h input.h inputtype.h main.h sco typequiv.o: LLlex.h def.h node.h type.h node.o: LLlex.h debug.h def.h node.h type.h cstoper.o: LLlex.h Lpars.h debug.h idf.h node.h standards.h target_sizes.h type.h -chk_expr.o: LLlex.h Lpars.h const.h debug.h def.h idf.h node.h scope.h standards.h type.h +chk_expr.o: LLlex.h Lpars.h chk_expr.h const.h debug.h def.h idf.h node.h scope.h standards.h type.h options.o: idfsize.h main.h ndir.h type.h -walk.o: LLlex.h Lpars.h debug.h def.h desig.h f_info.h idf.h main.h node.h scope.h type.h +walk.o: LLlex.h Lpars.h chk_expr.h debug.h def.h desig.h f_info.h idf.h main.h node.h scope.h type.h casestat.o: LLlex.h Lpars.h debug.h density.h desig.h node.h type.h desig.o: LLlex.h debug.h def.h desig.h node.h scope.h type.h code.o: LLlex.h Lpars.h debug.h def.h desig.h node.h scope.h standards.h type.h tmpvar.o: debug.h def.h scope.h type.h +lookup.o: LLlex.h debug.h def.h idf.h node.h scope.h tokenfile.o: Lpars.h program.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h type.h declar.o: LLlex.h Lpars.h debug.h def.h idf.h main.h misc.h node.h scope.h type.h -expression.o: LLlex.h Lpars.h const.h debug.h def.h idf.h node.h type.h +expression.o: LLlex.h Lpars.h chk_expr.h const.h debug.h def.h idf.h node.h type.h statement.o: LLlex.h Lpars.h def.h idf.h node.h scope.h type.h Lpars.o: Lpars.h diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index 82f32881..ea1b0a2c 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -23,81 +23,150 @@ static char *RcsId = "$Header$"; #include "scope.h" #include "const.h" #include "standards.h" +#include "chk_expr.h" extern char *symbol2str(); -int -chk_expr(expp) - register struct node *expp; +STATIC int +chk_arr(expp) + struct node *expp; { - /* Check the expression indicated by expp for semantic errors, - identify identifiers used in it, replace constants by - their value, and try to evaluate the expression. - */ + return chk_designator(expp, DESIGNATOR|VARIABLE, D_USED); +} - switch(expp->nd_class) { - case Arrsel: - return chk_designator(expp, DESIGNATOR|VARIABLE, D_USED); - - case Oper: - return chk_oper(expp); - - case Arrow: - return chk_designator(expp, DESIGNATOR|VARIABLE, D_USED); - - case Uoper: - return chk_uoper(expp); - - case Value: - switch(expp->nd_symb) { - case REAL: - case STRING: - case INTEGER: - return 1; - - default: - crash("(chk_expr(Value))"); - } - break; - - case Xset: - return chk_set(expp); - - case Link: - case Name: - if (chk_designator(expp, VALUE|DESIGNATOR, D_USED)) { - if (expp->nd_class == Def && - expp->nd_def->df_kind == D_PROCEDURE) { - /* Check that this procedure is one that we - may take the address from. - */ - if (expp->nd_def->df_type == std_type) { - /* Standard procedure. Illegal */ -node_error(expp, "address of standard procedure taken"); - return 0; - } - if (expp->nd_def->df_scope->sc_level > 0) { - /* Address of nested procedure taken. - Illegal. - */ -node_error(expp, "address of a procedure local to another one taken"); - return 0; - } - } - return 1; - } - return 0; - - case Call: - return chk_call(expp); +STATIC int +chk_value(expp) + struct node *expp; +{ + switch(expp->nd_symb) { + case REAL: + case STRING: + case INTEGER: + return 1; default: - crash("(chk_expr)"); + crash("(chk_value)"); } /*NOTREACHED*/ } -int +STATIC int +chk_linkorname(expp) + register struct node *expp; +{ + if (chk_designator(expp, VALUE|DESIGNATOR, D_USED)) { + if (expp->nd_class == Def && + expp->nd_def->df_kind == D_PROCEDURE) { + /* Check that this procedure is one that we + may take the address from. + */ + if (expp->nd_def->df_type == std_type || + expp->nd_def->df_scope->sc_level > 0) { + /* Address of standard or nested procedure + taken. + */ +node_error(expp, "it is illegal to take the address of a standard or local procedure"); + return 0; + } + } + return 1; + } + return 0; +} + +STATIC int +RemoveSet(set) + arith **set; +{ + /* This routine is only used for error exits of chk_el. + It frees the set indicated by "set", and returns 0. + */ + if (*set) { + free((char *) *set); + *set = 0; + } + return 0; +} + +STATIC int +chk_el(expp, tp, set) + register struct node *expp; + register struct type *tp; + arith **set; +{ + /* Check elements of a set. This routine may call itself + recursively. + Also try to compute the set! + */ + register struct node *left = expp->nd_left; + register struct node *right = expp->nd_right; + register int i; + + if (expp->nd_class == Link && expp->nd_symb == UPTO) { + /* { ... , expr1 .. expr2, ... } + First check expr1 and expr2, and try to compute them. + */ + if (!chk_el(left, tp, set) || !chk_el(right, tp, set)) { + return 0; + } + + if (left->nd_class == Value && right->nd_class == Value) { + /* We have a constant range. Put all elements in the + set + */ + + if (left->nd_INT > right->nd_INT) { +node_error(expp, "lower bound exceeds upper bound in range"); + return RemoveSet(set); + } + + if (*set) { + for (i=left->nd_INT+1; ind_INT; i++) { + (*set)[i/wrd_bits] |= (1<<(i%wrd_bits)); + } + } + } + else if (*set) { + free((char *) *set); + *set = 0; + } + + return 1; + } + + /* Here, a single element is checked + */ + if (!chk_expr(expp)) { + return RemoveSet(set); + } + + if (!TstCompat(tp, expp->nd_type)) { + node_error(expp, "set element has incompatible type"); + return RemoveSet(set); + } + + if (expp->nd_class == Value) { + /* a constant element + */ + i = expp->nd_INT; + + if ((tp->tp_fund != T_ENUMERATION && + (i < tp->sub_lb || i > tp->sub_ub)) + || + (tp->tp_fund == T_ENUMERATION && + (i < 0 || i > tp->enm_ncst)) + ) { + node_error(expp, "set element out of range"); + return RemoveSet(set); + } + + if (*set) (*set)[i/wrd_bits] |= (1 << (i%wrd_bits)); + } + + return 1; +} + +STATIC int chk_set(expp) register struct node *expp; { @@ -174,126 +243,49 @@ node_error(expp, "specifier does not represent a set type"); return 1; } -int -chk_el(expp, tp, set) - register struct node *expp; - register struct type *tp; - arith **set; -{ - /* Check elements of a set. This routine may call itself - recursively. - Also try to compute the set! - */ - register struct node *left = expp->nd_left; - register struct node *right = expp->nd_right; - register int i; - - if (expp->nd_class == Link && expp->nd_symb == UPTO) { - /* { ... , expr1 .. expr2, ... } - First check expr1 and expr2, and try to compute them. - */ - if (!chk_el(left, tp, set) || !chk_el(right, tp, set)) { - return 0; - } - - if (left->nd_class == Value && right->nd_class == Value) { - /* We have a constant range. Put all elements in the - set - */ - - if (left->nd_INT > right->nd_INT) { -node_error(expp, "lower bound exceeds upper bound in range"); - return rem_set(set); - } - - if (*set) { - for (i=left->nd_INT+1; ind_INT; i++) { - (*set)[i/wrd_bits] |= (1<<(i%wrd_bits)); - } - } - } - else if (*set) { - free((char *) *set); - *set = 0; - } - - return 1; - } - - /* Here, a single element is checked - */ - if (!chk_expr(expp)) { - return rem_set(set); - } - - if (!TstCompat(tp, expp->nd_type)) { - node_error(expp, "set element has incompatible type"); - return rem_set(set); - } - - if (expp->nd_class == Value) { - /* a constant element - */ - i = expp->nd_INT; - - if ((tp->tp_fund != T_ENUMERATION && - (i < tp->sub_lb || i > tp->sub_ub)) - || - (tp->tp_fund == T_ENUMERATION && - (i < 0 || i > tp->enm_ncst)) - ) { - node_error(expp, "set element out of range"); - return rem_set(set); - } - - if (*set) (*set)[i/wrd_bits] |= (1 << (i%wrd_bits)); - } - - return 1; -} - -int -rem_set(set) - arith **set; -{ - /* This routine is only used for error exits of chk_el. - It frees the set indicated by "set", and returns 0. - */ - if (*set) { - free((char *) *set); - *set = 0; - } - return 0; -} - -struct node * +STATIC struct node * getarg(argp, bases, designator) struct node **argp; { + /* This routine is used to fetch the next argument from an + argument list. The argument list is indicated by "argp". + The parameter "bases" is a bitset indicating which types + are allowed at this point, and "designator" is a flag + indicating that the address from this argument is taken, so + that it must be a designator and may not be a register + variable. + */ struct type *tp; register struct node *arg = *argp; + register struct node *left; - if (!arg->nd_right) { + if (! arg->nd_right) { node_error(arg, "too few arguments supplied"); return 0; } + arg = arg->nd_right; - if ((!designator && !chk_expr(arg->nd_left)) || - (designator && !chk_designator(arg->nd_left, DESIGNATOR, D_REFERRED))) { + left = arg->nd_left; + + if ((!designator && !chk_expr(left)) || + (designator && + !chk_designator(left, DESIGNATOR|VARIABLE, D_USED|D_NOREG))) { return 0; } - tp = arg->nd_left->nd_type; + + tp = left->nd_type; if (tp->tp_fund == T_SUBRANGE) tp = tp->next; + if (bases && !(tp->tp_fund & bases)) { node_error(arg, "unexpected type"); return 0; } *argp = arg; - return arg->nd_left; + return left; } -struct node * +STATIC struct node * getname(argp, kinds) struct node **argp; { @@ -303,10 +295,11 @@ getname(argp, kinds) node_error(arg, "too few arguments supplied"); return 0; } + arg = arg->nd_right; if (! chk_designator(arg->nd_left, 0, D_REFERRED)) return 0; - assert(arg->nd_left->nd_class == Def); + if (arg->nd_left->nd_class != Def); if (!(arg->nd_left->nd_def->df_kind & kinds)) { node_error(arg, "unexpected type"); @@ -317,6 +310,42 @@ getname(argp, kinds) return arg->nd_left; } +STATIC int +chk_proccall(expp) + register struct node *expp; +{ + /* Check a procedure call + */ + register struct node *left; + struct node *arg; + register struct paramlist *param; + + left = expp->nd_left; + arg = expp; + expp->nd_type = left->nd_type->next; + + for (param = left->nd_type->prc_params; param; param = param->next) { + if (!(left = getarg(&arg, 0, IsVarParam(param)))) return 0; + if (left->nd_symb == STRING) { + TryToString(left, TypeOfParam(param)); + } + if (! TstParCompat(TypeOfParam(param), + left->nd_type, + IsVarParam(param), + left)) { +node_error(left, "type incompatibility in parameter"); + return 0; + } + } + + if (arg->nd_right) { + node_error(arg->nd_right, "too many parameters supplied"); + return 0; + } + + return 1; +} + int chk_call(expp) register struct node *expp; @@ -358,58 +387,7 @@ chk_call(expp) return 0; } -chk_proccall(expp) - register struct node *expp; -{ - /* Check a procedure call - */ - register struct node *left; - struct node *arg; - register struct paramlist *param; - - left = 0; - arg = expp->nd_right; - /* First, reverse the order in the argument list */ - while (arg) { - expp->nd_right = arg; - arg = arg->nd_right; - expp->nd_right->nd_right = left; - left = expp->nd_right; - } - - left = expp->nd_left; - arg = expp; - expp->nd_type = left->nd_type->next; - param = left->nd_type->prc_params; - - while (param) { - if (!(left = getarg(&arg, 0, IsVarParam(param)))) return 0; - if (left->nd_symb == STRING) { - TryToString(left, TypeOfParam(param)); - } - if (! TstParCompat(TypeOfParam(param), - left->nd_type, - IsVarParam(param), - left)) { -node_error(left, "type incompatibility in parameter"); - return 0; - } - if (IsVarParam(param) && left->nd_class == Def) { - left->nd_def->df_flags |= D_NOREG; - } - - param = param->next; - } - - if (arg->nd_right) { - node_error(arg->nd_right, "too many parameters supplied"); - return 0; - } - - return 1; -} - -static int +STATIC int FlagCheck(expp, df, flag) struct node *expp; struct def *df; @@ -461,7 +439,6 @@ chk_designator(expp, flag, dflags) */ register struct def *df; register struct type *tp; - struct def *lookfor(); expp->nd_type = error_type; @@ -469,23 +446,20 @@ chk_designator(expp, flag, dflags) expp->nd_def = lookfor(expp, CurrVis, 1); expp->nd_class = Def; expp->nd_type = expp->nd_def->df_type; - if (expp->nd_type == error_type) return 0; } + else if (expp->nd_class == Link) { + register struct node *left = expp->nd_left; - if (expp->nd_class == Link) { assert(expp->nd_symb == '.'); - if (! chk_designator(expp->nd_left, - flag|HASSELECTORS, - dflags|D_NOREG)) return 0; - - tp = expp->nd_left->nd_type; + if (! chk_designator(left, + (flag&DESIGNATOR)|HASSELECTORS, + dflags)) return 0; + tp = left->nd_type; assert(tp->tp_fund == T_RECORD); - df = lookup(expp->nd_IDF, tp->rec_scope); - - if (!df) { + if (!(df = lookup(expp->nd_IDF, tp->rec_scope))) { id_not_declared(expp); return 0; } @@ -493,17 +467,19 @@ chk_designator(expp, flag, dflags) expp->nd_def = df; expp->nd_type = df->df_type; if (!(df->df_flags & (D_EXPORTED|D_QEXPORTED))) { + /* Fields of a record are always D_QEXPORTED, + so ... + */ node_error(expp, "identifier \"%s\" not exported from qualifying module", df->df_idf->id_text); return 0; } } - if (expp->nd_left->nd_class == Def && - expp->nd_left->nd_def->df_kind == D_MODULE) { + if (left->nd_class == Def && + left->nd_def->df_kind == D_MODULE) { expp->nd_class = Def; - expp->nd_def = df; - FreeNode(expp->nd_left); + FreeNode(left); expp->nd_left = 0; } else { @@ -548,12 +524,12 @@ df->df_idf->id_text); assert(expp->nd_symb == '['); if ( - !chk_designator(expp->nd_left, DESIGNATOR|VARIABLE, dflags|D_NOREG) + !chk_designator(expp->nd_left, DESIGNATOR|VARIABLE, dflags) || - !chk_expr(expp->nd_right) + !chk_expr(expp->nd_right) || - expp->nd_left->nd_type == error_type - ) return 0; + expp->nd_left->nd_type == error_type + ) return 0; tpr = expp->nd_right->nd_type; tpl = expp->nd_left->nd_type; @@ -598,7 +574,7 @@ symbol2str(expp->nd_symb)); return 0; } -struct type * +STATIC struct type * ResultOfOperation(operator, tp) struct type *tp; { @@ -616,13 +592,13 @@ ResultOfOperation(operator, tp) return tp; } -int +STATIC int Boolean(operator) { return operator == OR || operator == AND || operator == '&'; } -int +STATIC int AllowedTypes(operator) { switch(operator) { @@ -654,7 +630,23 @@ AllowedTypes(operator) /*NOTREACHED*/ } -int +STATIC int +chk_address(tpl, tpr) + register struct type *tpl, *tpr; +{ + + if (tpl == address_type) { + return tpr == address_type || tpr->tp_fund != T_POINTER; + } + + if (tpr == address_type) { + return tpl->tp_fund != T_POINTER; + } + + return 0; +} + +STATIC int chk_oper(expp) register struct node *expp; { @@ -741,23 +733,7 @@ node_error(expp,"operator \"%s\": illegal operand type(s)", symbol2str(expp->nd_ return 1; } -int -chk_address(tpl, tpr) - register struct type *tpl, *tpr; -{ - - if (tpl == address_type) { - return tpr == address_type || tpr->tp_fund != T_POINTER; - } - - if (tpr == address_type) { - return tpl->tp_fund != T_POINTER; - } - - return 0; -} - -int +STATIC int chk_uoper(expp) register struct node *expp; { @@ -826,7 +802,7 @@ chk_uoper(expp) return 0; } -struct node * +STATIC struct node * getvariable(argp) struct node **argp; { @@ -916,7 +892,11 @@ DO_DEBUG(3,debug("standard name \"%s\", %d",left->nd_def->df_idf->id_text,std)); case S_MAX: case S_MIN: - if (!(left = getarg(&arg, T_DISCRETE, 0))) return 0; + if (!(left = getname(&arg, D_ISTYPE))) return 0; + if (!(left->nd_type->tp_fund & (T_DISCRETE))) { + node_error(left, "illegal type in MIN or MAX"); + return 0; + } expp->nd_type = left->nd_type; cstcall(expp,std); break; @@ -1072,7 +1052,8 @@ TryToString(nd, tp) struct node *nd; struct type *tp; { - /* Try a coercion from character constant to string */ + /* Try a coercion from character constant to string. + */ if (tp->tp_fund == T_ARRAY && nd->nd_type == char_type) { int ch = nd->nd_INT; @@ -1084,3 +1065,20 @@ TryToString(nd, tp) nd->nd_SLE = 1; } } + +extern int NodeCrash(); + +int (*ChkTable[])() = { + chk_value, + chk_arr, + chk_oper, + chk_uoper, + chk_arr, + chk_call, + chk_linkorname, + NodeCrash, + chk_set, + NodeCrash, + NodeCrash, + chk_linkorname +}; diff --git a/lang/m2/comp/chk_expr.h b/lang/m2/comp/chk_expr.h new file mode 100644 index 00000000..6b4422b3 --- /dev/null +++ b/lang/m2/comp/chk_expr.h @@ -0,0 +1,9 @@ +/* E X P R E S S I O N C H E C K I N G */ + +/* $Header$ */ + +extern int (*ChkTable[])(); /* table of expression checking + functions, indexed by node class + */ + +#define chk_expr(expp) ((*ChkTable[(expp)->nd_class])(expp)) diff --git a/lang/m2/comp/code.c b/lang/m2/comp/code.c index 48c55d28..9c81eb76 100644 --- a/lang/m2/comp/code.c +++ b/lang/m2/comp/code.c @@ -129,7 +129,6 @@ CodeExpr(nd, ds, true_label, false_label) break; case Uoper: - CodePExpr(nd->nd_right); CodeUoper(nd); ds->dsg_kind = DSG_LOADED; break; @@ -194,9 +193,9 @@ CodeCoercion(t1, t2) { register int fund1, fund2; - if (t1 == t2) return; if (t1->tp_fund == T_SUBRANGE) t1 = t1->next; if (t2->tp_fund == T_SUBRANGE) t2 = t2->next; + if (t1 == t2) return; if ((fund1 = t1->tp_fund) == T_WORD) fund1 = T_INTEGER; if ((fund2 = t2->tp_fund) == T_WORD) fund2 = T_INTEGER; switch(fund1) { @@ -291,9 +290,6 @@ CodeCall(nd) and result is already done. */ register struct node *left = nd->nd_left; - register struct node *arg = nd; - register struct paramlist *param; - struct type *tp; if (left->nd_type == std_type) { CodeStd(nd); @@ -311,49 +307,10 @@ CodeCall(nd) assert(IsProcCall(left)); - for (param = left->nd_type->prc_params; param; param = param->next) { - tp = TypeOfParam(param); - arg = arg->nd_right; - assert(arg != 0); - left = arg->nd_left; - if (IsConformantArray(tp)) { - C_loc(tp->arr_elsize); - if (IsConformantArray(left->nd_type)) { - DoHIGH(left); - } - else if (left->nd_symb == STRING) { - C_loc(left->nd_SLE); - } - else if (tp->arr_elem == word_type) { - C_loc(left->nd_type->tp_size / word_size - 1); - } - else { - tp = left->nd_type->next; - if (tp->tp_fund == T_SUBRANGE) { - C_loc(tp->sub_ub - tp->sub_lb); - } - else C_loc((arith) (tp->enm_ncst - 1)); - } - C_loc((arith) 0); - if (left->nd_symb == STRING) { - CodeString(left); - } - else CodeDAddress(left); - } - else if (IsVarParam(param)) { - CodeDAddress(left); - } - else { - if (left->nd_type->tp_fund == T_STRING) { - CodePadString(left, tp->tp_size); - } - else CodePExpr(left); - CheckAssign(left->nd_type, tp); - } + if (nd->nd_right) { + CodeParameters(left->nd_type->prc_params, nd->nd_right); } - left = nd->nd_left; - if (left->nd_class == Def && left->nd_def->df_kind == D_PROCEDURE) { if (left->nd_def->df_scope->sc_level > 0) { C_lxl((arith) proclevel - left->nd_def->df_scope->sc_level); @@ -373,6 +330,63 @@ CodeCall(nd) } } +CodeParameters(param, arg) + struct paramlist *param; + struct node *arg; +{ + register struct type *tp; + register struct node *left; + + assert(param != 0 && arg != 0); + + if (param->next) { + CodeParameters(param->next, arg->nd_right); + } + + tp = TypeOfParam(param); + left = arg->nd_left; + if (IsConformantArray(tp)) { + C_loc(tp->arr_elsize); + if (IsConformantArray(left->nd_type)) { + DoHIGH(left); + if (tp->arr_elem->tp_size != left->nd_type->arr_elem->tp_size) { + /* This can only happen if the formal type is + ARRAY OF WORD + */ + /* ??? */ + } + } + else if (left->nd_symb == STRING) { + C_loc(left->nd_SLE); + } + else if (tp->arr_elem == word_type) { + C_loc(left->nd_type->tp_size / word_size - 1); + } + else { + tp = left->nd_type->next; + if (tp->tp_fund == T_SUBRANGE) { + C_loc(tp->sub_ub - tp->sub_lb); + } + else C_loc((arith) (tp->enm_ncst - 1)); + } + C_loc((arith) 0); + if (left->nd_symb == STRING) { + CodeString(left); + } + else CodeDAddress(left); + } + else if (IsVarParam(param)) { + CodeDAddress(left); + } + else { + if (left->nd_type->tp_fund == T_STRING) { + CodePadString(left, tp->tp_size); + } + else CodePExpr(left); + CheckAssign(left->nd_type, tp); + } +} + CodeStd(nd) struct node *nd; { @@ -387,7 +401,6 @@ CodeStd(nd) if (tp->tp_fund == T_SUBRANGE) tp = tp->next; arg = arg->nd_right; } - Desig = InitDesig; switch(std = nd->nd_left->nd_def->df_value.df_stdname) { case S_ABS: @@ -546,14 +559,12 @@ CheckAssign(tpl, tpr) */ arith llo, lhi, rlo, rhi; - label l = 0; - extern label getrck(); if (bounded(tpl)) { /* in this case we might need a range check */ if (!bounded(tpr)) { /* yes, we need one */ - l = getrck(tpl); + genrck(tpl); } else { /* both types are restricted. check the bounds @@ -562,14 +573,9 @@ CheckAssign(tpl, tpr) getbounds(tpl, &llo, &lhi); getbounds(tpr, &rlo, &rhi); if (llo > rlo || lhi < rhi) { - l = getrck(tpl); + genrck(tpl); } } - - if (l) { - C_lae_dlb(l, (arith) 0); - C_rck(word_size); - } } } @@ -916,6 +922,7 @@ CodeUoper(nd) { register struct type *tp = nd->nd_type; + CodePExpr(nd->nd_right); switch(nd->nd_symb) { case '~': case NOT: diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 9bad30c1..63c0e3c9 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -461,7 +461,6 @@ PointerType(struct type **ptp;) { struct type *tp; struct def *df; - struct def *lookfor(); struct node *nd; } : POINTER TO diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H index bdf90881..e87d3ac0 100644 --- a/lang/m2/comp/def.H +++ b/lang/m2/comp/def.H @@ -117,7 +117,11 @@ struct def { /* list of definitions for a name */ extern struct def *define(), - *lookup(), + *DefineLocalModule(), + *MkDef(), *ill_df; +extern struct def + *lookup(), + *lookfor(); #define NULLDEF ((struct def *) 0) diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index 1b703ff6..91f4402a 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -203,7 +203,7 @@ DeclProc(type) df->for_node = MkLeaf(Name, &dot); sprint(buf,"%s_%s",CurrentScope->sc_name,df->df_idf->id_text); df->for_name = Salloc(buf, (unsigned) (strlen(buf)+1)); - C_exp(df->for_name); + if (CurrVis == Defined->mod_vis) C_exp(df->for_name); open_scope(OPENSCOPE); } else { @@ -292,6 +292,51 @@ DefInFront(df) } } +struct def * +DefineLocalModule(id) + struct idf *id; +{ + /* Create a definition for a local module. Also give it + a name to be used for code generation. + */ + register struct def *df = define(id, CurrentScope, D_MODULE); + register struct type *tp; + register struct scope *sc; + static int modulecount = 0; + char buf[256]; + extern char *sprint(); + extern int proclevel; + + sprint(buf, "_%d%s", ++modulecount, id->id_text); + + if (!df->mod_vis) { + /* We never saw the name of this module before. Create a + scope for it. + */ + open_scope(CLOSEDSCOPE); + df->mod_vis = CurrVis; + } + + CurrVis = df->mod_vis; + + sc = CurrentScope; + sc->sc_level = proclevel; + sc->sc_definedby = df; + sc->sc_name = Salloc(buf, (unsigned) (strlen(buf) + 1)); + + /* Create a type for it + */ + df->df_type = tp = standard_type(T_RECORD, 0, (arith) 0); + tp->rec_scope = sc; + + /* Generate code that indicates that the initialization procedure + for this module is local. + */ + C_inp(buf); + + return df; +} + #ifdef DEBUG PrDef(df) register struct def *df; diff --git a/lang/m2/comp/desig.c b/lang/m2/comp/desig.c index 3cde10de..1a325fb2 100644 --- a/lang/m2/comp/desig.c +++ b/lang/m2/comp/desig.c @@ -25,7 +25,6 @@ static char *RcsId = "$Header$"; #include "node.h" extern int proclevel; -struct desig Desig; struct desig InitDesig = {DSG_INIT, 0, 0}; CodeValue(ds, size) @@ -225,6 +224,7 @@ CodeVarDesig(df, ds) */ assert(ds->dsg_kind == DSG_INIT); + df->df_flags |= D_USED; if (df->var_addrgiven) { /* the programmer specified an address in the declaration of the variable. Generate code to push the address. @@ -232,7 +232,6 @@ CodeVarDesig(df, ds) CodeConst(df->var_off, pointer_size); ds->dsg_kind = DSG_PLOADED; ds->dsg_offset = 0; - df->df_flags |= D_NOREG; return; } @@ -243,7 +242,6 @@ CodeVarDesig(df, ds) ds->dsg_name = df->var_name; ds->dsg_offset = 0; ds->dsg_kind = DSG_FIXED; - df->df_flags |= D_NOREG; return; } @@ -251,6 +249,8 @@ CodeVarDesig(df, ds) /* the variable is local to a statically enclosing procedure. */ assert(proclevel > sc->sc_level); + + df->df_flags |= D_NOREG; if (df->df_flags & (D_VARPAR|D_VALPAR)) { /* value or var parameter */ @@ -269,7 +269,6 @@ CodeVarDesig(df, ds) else C_lxl((arith) (proclevel - sc->sc_level)); ds->dsg_kind = DSG_PLOADED; ds->dsg_offset = df->var_off; - df->df_flags |= D_NOREG; return; } diff --git a/lang/m2/comp/desig.h b/lang/m2/comp/desig.h index ac2f3760..a7c1c736 100644 --- a/lang/m2/comp/desig.h +++ b/lang/m2/comp/desig.h @@ -50,6 +50,6 @@ struct withdesig { }; extern struct withdesig *WithDesigs; -extern struct desig Desig, InitDesig; +extern struct desig InitDesig; #define NO_LABEL ((label) 0) diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index 6184d23d..04d4dda7 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -116,6 +116,7 @@ EnterVarList(Idlist, type, local) /* An address was supplied */ df->var_addrgiven = 1; + df->df_flags |= D_NOREG; if (idlist->nd_left->nd_type != card_type) { node_error(idlist->nd_left,"Illegal type for address"); } @@ -137,9 +138,12 @@ node_error(idlist->nd_left,"Illegal type for address"); sprint(buf,"%s_%s", sc->sc_scope->sc_name, df->df_idf->id_text); df->var_name = Salloc(buf, (unsigned)(strlen(buf)+1)); + df->df_flags |= D_NOREG; if (DefinitionModule) { - C_exa_dnam(df->var_name); + if (sc == Defined->mod_vis) { + C_exa_dnam(df->var_name); + } } else { C_ina_dnam(df->var_name); @@ -163,11 +167,16 @@ EnterParamList(ppr, Idlist, type, VARp, off) register struct paramlist *pr; register struct def *df; register struct node *idlist = Idlist; + static struct paramlist *last; for ( ; idlist; idlist = idlist->next) { pr = new_paramlist(); - pr->next = *ppr; - *ppr = pr; + pr->next = 0; + if (!*ppr) { + *ppr = pr; + } + else last->next = pr; + last = pr; df = define(idlist->nd_IDF, CurrentScope, D_VARIABLE); pr->par_def = df; df->df_type = type; @@ -188,7 +197,7 @@ EnterParamList(ppr, Idlist, type, VARp, off) FreeNode(Idlist); } -static +STATIC DoImport(df, scope) register struct def *df; struct scope *scope; @@ -222,7 +231,7 @@ DoImport(df, scope) } } -static struct scopelist * +STATIC struct scopelist * ForwModule(df, idn) register struct def *df; struct node *idn; @@ -248,7 +257,7 @@ ForwModule(df, idn) return vis; } -static struct def * +STATIC struct def * ForwDef(ids, scope) register struct node *ids; struct scope *scope; @@ -351,7 +360,7 @@ EnterFromImportList(Idlist, Fromid, local) register struct def *df; struct scopelist *vis = enclosing(CurrVis); int forwflag = 0; - extern struct def *lookfor(), *GetDefinitionModule(); + extern struct def *GetDefinitionModule(); if (local) { df = lookfor(Fromid, vis, 0); @@ -412,7 +421,7 @@ EnterImportList(Idlist, local) register struct node *idlist = Idlist; register struct def *df; struct scopelist *vis = enclosing(CurrVis); - extern struct def *lookfor(), *GetDefinitionModule(); + extern struct def *GetDefinitionModule(); for (; idlist; idlist = idlist->next) { if (local) df = ForwDef(idlist, vis->sc_scope); diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index bfdfe427..3adfc160 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -18,19 +18,17 @@ static char *RcsId = "$Header$"; #include "node.h" #include "const.h" #include "type.h" +#include "chk_expr.h" } -number(struct node **p;) -{ - struct type *tp; -} : +number(struct node **p;) : [ %default - INTEGER { tp = toktype; } + INTEGER | - REAL { tp = real_type; } + REAL ] { *p = MkLeaf(Value, &dot); - (*p)->nd_type = tp; + (*p)->nd_type = toktype; } ; diff --git a/lang/m2/comp/lookup.c b/lang/m2/comp/lookup.c index a150d79a..12775cbe 100644 --- a/lang/m2/comp/lookup.c +++ b/lang/m2/comp/lookup.c @@ -16,8 +16,6 @@ static char *RcsId = "$Header$"; #include "LLlex.h" #include "node.h" -extern struct def *MkDef(); - struct def * lookup(id, scope) register struct idf *id; diff --git a/lang/m2/comp/misc.c b/lang/m2/comp/misc.c index d28f4efc..d3f00bad 100644 --- a/lang/m2/comp/misc.c +++ b/lang/m2/comp/misc.c @@ -15,7 +15,7 @@ static char *RcsId = "$Header$"; #include "node.h" match_id(id1, id2) - struct idf *id1, *id2; + register struct idf *id1, *id2; { /* Check that identifiers id1 and id2 are equal. If they are not, check that we did'nt generate them in the @@ -45,7 +45,7 @@ gen_anon_idf() } id_not_declared(id) - struct node *id; + register struct node *id; { /* The identifier "id" is not declared. If it is not generated, give an error message diff --git a/lang/m2/comp/node.H b/lang/m2/comp/node.H index ca2bf228..a5e83862 100644 --- a/lang/m2/comp/node.H +++ b/lang/m2/comp/node.H @@ -19,6 +19,7 @@ struct node { #define Def 9 /* an identified name */ #define Stat 10 /* a statement */ #define Link 11 + /* do NOT change the order or the numbers!!! */ struct type *nd_type; /* type of this node */ struct token nd_token; #define nd_set nd_token.tk_data.tk_set diff --git a/lang/m2/comp/node.c b/lang/m2/comp/node.c index c940e427..f8ea57b1 100644 --- a/lang/m2/comp/node.c +++ b/lang/m2/comp/node.c @@ -64,11 +64,17 @@ FreeNode(nd) free_node(nd); } +NodeCrash(expp) + struct node *expp; +{ + crash("Illegal node %d", expp->nd_class); +} + #ifdef DEBUG extern char *symbol2str(); -static +STATIC printnode(nd) register struct node *nd; { diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 32cba66b..9ee7cec4 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -42,36 +42,13 @@ static char *RcsId = "$Header$"; ModuleDeclaration { struct idf *id; - register struct def *df; - extern int proclevel; - static int modulecount = 0; - char buf[256]; + struct def *df; struct node *nd; struct node *exportlist = 0; int qualified; - extern char *sprint(); } : - MODULE IDENT { - id = dot.TOK_IDF; - df = define(id, CurrentScope, D_MODULE); - - if (!df->mod_vis) { - open_scope(CLOSEDSCOPE); - df->mod_vis = CurrVis; - } - else { - CurrVis = df->mod_vis; - CurrentScope->sc_level = proclevel; - } - CurrentScope->sc_definedby = df; - - df->df_type = standard_type(T_RECORD, 0, (arith) 0); - df->df_type->rec_scope = df->mod_vis->sc_scope; - sprint(buf, "_%d%s", ++modulecount, id->id_text); - CurrentScope->sc_name = - Salloc(buf, (unsigned) (strlen(buf) + 1)); - if (! proclevel) C_ina_dnam(&buf[1]); - C_inp(buf); + MODULE IDENT { id = dot.TOK_IDF; + df = DefineLocalModule(id); } priority(&(df->mod_priority))? ';' @@ -92,7 +69,7 @@ priority(arith *pprio;) struct node *nd; } : '[' ConstExpression(&nd) ']' - { if (!(nd->nd_type->tp_fund & T_INTORCARD)) { + { if (!(nd->nd_type->tp_fund & T_CARDINAL)) { node_error(nd, "Illegal priority"); } *pprio = nd->nd_INT; @@ -141,13 +118,12 @@ DefinitionModule int dummy; } : DEFINITION - MODULE IDENT { - id = dot.TOK_IDF; + MODULE IDENT { id = dot.TOK_IDF; df = define(id, GlobalScope, D_MODULE); - if (!SYSTEMModule) open_scope(CLOSEDSCOPE); if (!Defined) Defined = df; - df->mod_vis = CurrVis; + if (!SYSTEMModule) open_scope(CLOSEDSCOPE); CurrentScope->sc_name = id->id_text; + df->mod_vis = CurrVis; df->df_type = standard_type(T_RECORD, 0, (arith) 0); df->df_type->rec_scope = df->mod_vis->sc_scope; DefinitionModule++; @@ -222,8 +198,7 @@ ProgramModule struct node *nd; } : MODULE - IDENT { - id = dot.TOK_IDF; + IDENT { id = dot.TOK_IDF; if (state == IMPLEMENTATION) { df = GetDefinitionModule(id); CurrVis = df->mod_vis; @@ -232,11 +207,11 @@ ProgramModule } else { df = define(id, CurrentScope, D_MODULE); - Defined = df; open_scope(CLOSEDSCOPE); df->mod_vis = CurrVis; CurrentScope->sc_name = id->id_text; } + Defined = df; CurrentScope->sc_definedby = df; } priority(&(df->mod_priority))? diff --git a/lang/m2/comp/scope.C b/lang/m2/comp/scope.C index f1731fb3..2cd6d34a 100644 --- a/lang/m2/comp/scope.C +++ b/lang/m2/comp/scope.C @@ -90,7 +90,7 @@ Forward(tk, ptp) CurrentScope->sc_forw = f; } -static +STATIC chk_proc(df) register struct def *df; { @@ -108,7 +108,7 @@ node_error(df->for_node, "procedure \"%s\" not defined", df->df_idf->id_text); } } -static +STATIC chk_forw(pdf) register struct def **pdf; { @@ -153,7 +153,7 @@ node_error((*pdf)->for_node, "identifier \"%s\" has not been declared", } } -static +STATIC rem_forwards(fo) struct forwards *fo; { @@ -161,7 +161,6 @@ rem_forwards(fo) */ register struct forwards *f; register struct def *df; - struct def *lookfor(); while (f = fo) { df = lookfor(&(f->fo_tok), CurrVis, 1); @@ -181,11 +180,10 @@ Reverse(pdf) /* Reverse the order in the list of definitions in a scope. This is neccesary because this list is built in reverse. Also, while we're at it, remove uninteresting definitions - from this list. The only interesting definitions are: - D_MODULE, D_PROCEDURE, and D_PROCHEAD. + from this list. */ register struct def *df, *df1; -#define INTERESTING D_MODULE|D_PROCEDURE|D_PROCHEAD +#define INTERESTING D_MODULE|D_PROCEDURE|D_PROCHEAD|D_VARIABLE df = 0; df1 = *pdf; @@ -217,7 +215,6 @@ close_scope(flag) register struct scope *sc = CurrentScope; assert(sc != 0); - DO_DEBUG(1, debug("Closing a scope")); if (flag) { if (sc->sc_forw) rem_forwards(sc->sc_forw); diff --git a/lang/m2/comp/statement.g b/lang/m2/comp/statement.g index aef6e22c..62fd0a91 100644 --- a/lang/m2/comp/statement.g +++ b/lang/m2/comp/statement.g @@ -83,13 +83,17 @@ ProcedureCall: StatementSequence(register struct node **pnd;) { + struct node *nd; } : statement(pnd) [ - ';' { *pnd = MkNode(Link, *pnd, NULLNODE, &dot); - pnd = &((*pnd)->nd_right); + ';' statement(&nd) + { if (nd) { + *pnd = MkNode(Link, *pnd, nd, &dot); + (*pnd)->nd_symb = ';'; + pnd = &((*pnd)->nd_right); + } } - statement(pnd) ]* ; diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index ae272a6f..98595b18 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -21,9 +21,6 @@ static char *RcsId = "$Header$"; #include "const.h" #include "scope.h" -/* To be created dynamically in main() from defaults or from command - line parameters. -*/ int word_align = AL_WORD, int_align = AL_INT, @@ -96,38 +93,34 @@ construct_type(fund, tp) switch (fund) { case T_PROCEDURE: + if (tp && !returntype(tp)) { + error("illegal procedure result type"); + } + /* Fall through */ case T_POINTER: case T_HIDDEN: dtp->tp_align = pointer_align; dtp->tp_size = pointer_size; - dtp->next = tp; - if (fund == T_PROCEDURE && tp) { - if (! returntype(tp)) { - error("illegal procedure result type"); - } - } break; case T_SET: dtp->tp_align = word_align; - dtp->next = tp; break; case T_ARRAY: dtp->tp_align = tp->tp_align; - dtp->next = tp; break; case T_SUBRANGE: dtp->tp_align = tp->tp_align; dtp->tp_size = tp->tp_size; - dtp->next = tp; break; default: crash("funny type constructor"); } + dtp->next = tp; return dtp; } @@ -206,8 +199,11 @@ InitTypes() address_type = construct_type(T_POINTER, word_type); /* create BITSET type + TYPE BITSET = SET OF [0..W-1]; + The subrange is a subrange of type cardinal, because the lower bound + is a non-negative integer (See Rep. 6.3) */ - tp = construct_type(T_SUBRANGE, int_type); + tp = construct_type(T_SUBRANGE, card_type); tp->sub_lb = 0; tp->sub_ub = word_size * 8 - 1; bitset_type = set_type(tp); @@ -229,7 +225,7 @@ chk_basesubrange(tp, base) if (base->tp_fund == T_SUBRANGE) { /* Check that the bounds of "tp" fall within the range - of "base" + of "base". */ if (base->sub_lb > tp->sub_lb || base->sub_ub < tp->sub_ub) { error("Base type has insufficient range"); @@ -246,7 +242,7 @@ chk_basesubrange(tp, base) error("Illegal base for a subrange"); } else if (base == int_type && tp->next == card_type && - (tp->sub_ub > max_int || tp->sub_ub)) { + (tp->sub_ub > max_int || tp->sub_ub < 0)) { error("Upperbound to large for type INTEGER"); } else if (base != tp->next && base != int_type) { @@ -269,7 +265,7 @@ subr_type(lb, ub) register struct type *tp = lb->nd_type, *res; if (!TstCompat(lb->nd_type, ub->nd_type)) { - node_error(ub, "Types of subrange bounds not compatible"); + node_error(ub, "Types of subrange bounds not equal"); return error_type; } @@ -306,32 +302,33 @@ subr_type(lb, ub) return res; } -label -getrck(tp) +genrck(tp) register struct type *tp; { /* generate a range check descriptor for type "tp" when - neccessary. Return its label + neccessary. Return its label. */ + arith lb, ub; + label ol, l; - assert(bounded(tp)); + getbounds(tp, &lb, &ub); if (tp->tp_fund == T_SUBRANGE) { - if (tp->sub_rck == (label) 0) { - tp->sub_rck = data_label(); - C_df_dlb(tp->sub_rck); - C_rom_cst(tp->sub_lb); - C_rom_cst(tp->sub_ub); + if (!(ol = tp->sub_rck)) { + tp->sub_rck = l = data_label(); } - return tp->sub_rck; } - if (tp->enm_rck == (label) 0) { - tp->enm_rck = data_label(); - C_df_dlb(tp->enm_rck); - C_rom_cst((arith) 0); - C_rom_cst((arith) (tp->enm_ncst - 1)); + else if (!(ol = tp->enm_rck)) { + tp->enm_rck = l = data_label(); } - return tp->enm_rck; + if (!ol) { + ol = l; + C_df_dlb(ol); + C_rom_cst(lb); + C_rom_cst(ub); + } + C_lae_dlb(ol, (arith) 0); + C_rck(word_size); } getbounds(tp, plo, phi) @@ -352,6 +349,7 @@ getbounds(tp, plo, phi) *phi = tp->enm_ncst - 1; } } + struct type * set_type(tp) register struct type *tp; @@ -361,26 +359,20 @@ set_type(tp) */ arith lb, ub; - if (tp->tp_fund == T_SUBRANGE) { - if ((lb = tp->sub_lb) < 0 || (ub = tp->sub_ub) > MAXSET - 1) { - error("Set type limits exceeded"); - return error_type; - } - } - else if (tp->tp_fund == T_ENUMERATION || tp == char_type) { - lb = 0; - if ((ub = tp->enm_ncst - 1) > MAXSET - 1) { - error("Set type limits exceeded"); - return error_type; - } - } - else { + if (! bounded(tp)) { error("illegal base type for set"); return error_type; } + getbounds(tp, &lb, &ub); + + if (lb < 0 || ub > MAXSET-1) { + error("Set type limits exceeded"); + return error_type; + } + tp = construct_type(T_SET, tp); - tp->tp_size = WA(((ub - lb) + 7)/8); + tp->tp_size = WA(((ub - lb) + 8)/8); return tp; } @@ -412,47 +404,30 @@ ArraySizes(tp) */ register struct type *index_type = tp->next; register struct type *elem_type = tp->arr_elem; + arith lo, hi; tp->arr_elsize = ArrayElSize(elem_type); tp->tp_align = elem_type->tp_align; /* check index type */ - if (! (index_type->tp_fund & T_INDEX)) { + if (! bounded(index_type)) { error("Illegal index type"); tp->tp_size = 0; return; } - /* find out HIGH, LOW and size of ARRAY + getbounds(index_type, &lo, &hi); + + tp->tp_size = WA((hi - lo + 1) * tp->arr_elsize); + + /* generate descriptor and remember label. */ tp->arr_descr = data_label(); C_df_dlb(tp->arr_descr); - - switch(index_type->tp_fund) { - case T_SUBRANGE: - tp->tp_size = tp->arr_elsize * - (index_type->sub_ub - index_type->sub_lb + 1); - C_rom_cst(index_type->sub_lb); - C_rom_cst(index_type->sub_ub - index_type->sub_lb); - break; - - case T_CHAR: - case T_ENUMERATION: - tp->tp_size = tp->arr_elsize * index_type->enm_ncst; - C_rom_cst((arith) 0); - C_rom_cst((arith) (index_type->enm_ncst - 1)); - break; - - default: - crash("Funny index type"); - } - + C_rom_cst(lo); + C_rom_cst(hi - lo); C_rom_cst(tp->arr_elsize); - tp->tp_size = WA(tp->tp_size); - - /* ??? overflow checking ??? - */ } FreeType(tp) diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index a68f48f6..ae214d50 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -12,6 +12,7 @@ static char *RcsId = "$Header$"; #include #include +#include #include #include "def.h" @@ -24,6 +25,7 @@ static char *RcsId = "$Header$"; #include "desig.h" #include "f_info.h" #include "idf.h" +#include "chk_expr.h" extern arith NewPtr(); extern arith NewInt(); @@ -49,7 +51,7 @@ data_label() return ++datalabel; } -static +STATIC DoProfil() { static label filename_label = 0; @@ -119,16 +121,14 @@ WalkModule(module) struct node *nd; if (state == IMPLEMENTATION) { - label l1 = data_label(), l2 = text_label(); + label l1 = data_label(); /* we don't actually prevent recursive calls, but do nothing if called recursively */ C_df_dlb(l1); C_bss_cst(word_size, (arith) 0, 1); C_loe_dlb(l1, (arith) 0); - C_zeq(l2); - C_ret((arith) 0); - C_df_ilb(l2); + C_zne((label) 1); C_loc((arith) 1); C_ste_dlb(l1, (arith) 0); } @@ -159,7 +159,8 @@ WalkProcedure(procedure) */ struct scopelist *vis = CurrVis; register struct scope *sc; - register struct type *res_type; + register struct type *tp; + register struct paramlist *param; proclevel++; CurrVis = procedure->prc_vis; @@ -177,19 +178,20 @@ WalkProcedure(procedure) MkCalls(sc->sc_def); return_expr_occurred = 0; instructionlabel = 2; - func_type = res_type = procedure->df_type->next; - if (! returntype(res_type)) { + func_type = tp = procedure->df_type->next; + if (! returntype(tp)) { node_error(procedure->prc_body, "illegal result type"); } WalkNode(procedure->prc_body, (label) 0); C_df_ilb((label) 1); - if (res_type) { + if (tp) { if (! return_expr_occurred) { node_error(procedure->prc_body,"function procedure does not return a value"); } - C_ret(WA(res_type->tp_size)); + C_ret(WA(tp->tp_size)); } else C_ret((arith) 0); + RegisterMessages(sc->sc_def); C_end(-sc->sc_off); TmpClose(); CurrVis = vis; @@ -257,7 +259,6 @@ WalkStat(nd, lab) */ register struct node *left = nd->nd_left; register struct node *right = nd->nd_right; - register struct desig *pds = &Desig; if (!nd) { /* Empty statement @@ -385,9 +386,10 @@ WalkStat(nd, lab) { struct scopelist link; struct withdesig wds; + struct desig ds; arith tmp = 0; - WalkDesignator(left); + WalkDesignator(left, &ds); if (left->nd_type->tp_fund != T_RECORD) { node_error(left, "record variable expected"); break; @@ -396,19 +398,21 @@ WalkStat(nd, lab) wds.w_next = WithDesigs; WithDesigs = &wds; wds.w_scope = left->nd_type->rec_scope; - if (pds->dsg_kind != DSG_PFIXED) { + if (ds.dsg_kind != DSG_PFIXED) { /* In this case, we use a temporary variable */ - CodeAddress(pds); - pds->dsg_kind = DSG_FIXED; - /* Only for the store ... */ - pds->dsg_offset = tmp = NewPtr(); - pds->dsg_name = 0; - CodeStore(pds, pointer_size); - pds->dsg_kind = DSG_PFIXED; + CodeAddress(&ds); + ds.dsg_kind = DSG_FIXED; + /* Create a designator structure for the + temporary. + */ + ds.dsg_offset = tmp = NewPtr(); + ds.dsg_name = 0; + CodeStore(&ds, pointer_size); + ds.dsg_kind = DSG_PFIXED; /* the record is indirectly available */ } - wds.w_desig = *pds; + wds.w_desig = ds; link.sc_scope = wds.w_scope; link.next = CurrVis; CurrVis = &link; @@ -439,7 +443,7 @@ node_error(right, "type incompatibility in RETURN statement"); break; default: - assert(0); + crash("(WalkStat)"); } } @@ -450,6 +454,7 @@ ExpectBool(nd, true_label, false_label) /* "nd" must indicate a boolean expression. Check this and generate code to evaluate the expression. */ + struct desig ds; if (!chk_expr(nd)) return; @@ -457,8 +462,8 @@ ExpectBool(nd, true_label, false_label) node_error(nd, "boolean expression expected"); } - Desig = InitDesig; - CodeExpr(nd, &Desig, true_label, false_label); + ds = InitDesig; + CodeExpr(nd, &ds, true_label, false_label); } WalkExpr(nd) @@ -474,8 +479,9 @@ WalkExpr(nd) CodePExpr(nd); } -WalkDesignator(nd) +WalkDesignator(nd, ds) struct node *nd; + struct desig *ds; { /* Check designator and generate code for it */ @@ -484,8 +490,8 @@ WalkDesignator(nd) if (! chk_designator(nd, DESIGNATOR|VARIABLE, D_DEFINED)) return; - Desig = InitDesig; - CodeDesig(nd, &Desig); + *ds = InitDesig; + CodeDesig(nd, ds); } DoForInit(nd, left) @@ -527,13 +533,13 @@ DoAssign(nd, left, right) register struct node *left, *right; { /* May we do it in this order (expression first) ??? */ - struct desig ds; + struct desig dsl, dsr; if (!chk_expr(right)) return; if (! chk_designator(left, DESIGNATOR|VARIABLE, D_DEFINED)) return; TryToString(right, left->nd_type); - Desig = InitDesig; - CodeExpr(right, &Desig, NO_LABEL, NO_LABEL); + dsr = InitDesig; + CodeExpr(right, &dsr, NO_LABEL, NO_LABEL); if (! TstAssCompat(left->nd_type, right->nd_type)) { node_error(nd, "type incompatibility in assignment"); @@ -541,17 +547,44 @@ DoAssign(nd, left, right) } if (complex(right->nd_type)) { - CodeAddress(&Desig); + CodeAddress(&dsr); } else { - CodeValue(&Desig, right->nd_type->tp_size); + CodeValue(&dsr, right->nd_type->tp_size); CheckAssign(left->nd_type, right->nd_type); } - ds = Desig; - Desig = InitDesig; - CodeDesig(left, &Desig); + dsl = InitDesig; + CodeDesig(left, &dsl); - CodeAssign(nd, &ds, &Desig); + CodeAssign(nd, &dsr, &dsl); +} + +RegisterMessages(df) + register struct def *df; +{ + struct type *tp; + + for (; df; df = df->df_nextinscope) { + if (df->df_kind == D_VARIABLE && !(df->df_flags & D_NOREG)) { + /* Examine type and size + */ + tp = df->df_type; + if (tp->tp_fund == T_SUBRANGE) tp = tp->next; + if ((tp->tp_fund & T_NUMERIC) && + tp->tp_size <= dword_size) { + C_ms_reg(df->var_off, + tp->tp_size, + tp->tp_fund == T_REAL ? + reg_float : reg_any, + 0); + } + else if ((df->df_flags & D_VARPAR) || + tp->tp_fund == T_POINTER) { + C_ms_reg(df->var_off, pointer_size, + reg_pointer, 0); + } + } + } } #ifdef DEBUG From 07297eeb2af7a1e9aa6ef3fa089120315db8475d Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 20 Jun 1986 14:36:49 +0000 Subject: [PATCH 0210/1625] newer version --- lang/m2/comp/Makefile | 19 +++- lang/m2/comp/casestat.C | 15 ++- lang/m2/comp/chk_expr.c | 82 ++++++++++---- lang/m2/comp/code.c | 49 ++++---- lang/m2/comp/declar.g | 16 ++- lang/m2/comp/desig.c | 2 +- lang/m2/comp/lookup.c | 41 ++++--- lang/m2/comp/main.c | 2 + lang/m2/comp/node.H | 10 +- lang/m2/comp/standards.h | 2 + lang/m2/comp/statement.g | 5 +- lang/m2/comp/type.H | 8 +- lang/m2/comp/type.c | 19 ++-- lang/m2/comp/typequiv.c | 11 +- lang/m2/comp/walk.c | 239 ++++++++++++++++++++++++--------------- lang/m2/comp/walk.h | 13 +++ 16 files changed, 337 insertions(+), 196 deletions(-) create mode 100644 lang/m2/comp/walk.h diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index 48df7b4c..e6d968bf 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -11,7 +11,7 @@ LSRC = tokenfile.g program.g declar.g expression.g statement.g CC = cc GEN = /usr/em/util/LLgen/src/LLgen GENOPTIONS = -d -PROFILE = -p +PROFILE = CFLAGS = $(PROFILE) $(INCLUDES) -DSTATIC= LINTFLAGS = -DSTATIC= -DNORCSID LFLAGS = $(PROFILE) @@ -22,10 +22,17 @@ COBJ = LLlex.o LLmessage.o char.o error.o main.o \ cstoper.o chk_expr.o options.o walk.o casestat.o desig.o \ code.o tmpvar.o lookup.o OBJ = $(COBJ) $(LOBJ) Lpars.o -GENFILES= tokenfile.c \ - program.c declar.c expression.c statement.c \ - tokenfile.g symbol2str.c char.c Lpars.c Lpars.h +# Keep the next three entries up to date! +GENCFILES= tokenfile.c \ + program.c declar.c expression.c statement.c \ + symbol2str.c char.c Lpars.c casestat.c tmpvar.c scope.c +GENGFILES= tokenfile.g +GENHFILES= errout.h\ + idfsize.h numsize.h strsize.h target_sizes.h debug.h\ + inputtype.h maxset.h ndir.h density.h +# +GENFILES = $(GENGFILES) $(GENCFILES) $(GENHFILES) all: make hfiles make LLfiles @@ -44,7 +51,7 @@ main: $(OBJ) Makefile size main clean: - rm -f $(OBJ) $(GENFILES) LLfiles + rm -f $(OBJ) $(GENFILES) LLfiles hfiles lint: LLfiles hfiles lint $(INCLUDES) $(LINTFLAGS) `sources $(OBJ)` @@ -101,7 +108,7 @@ node.o: LLlex.h debug.h def.h node.h type.h cstoper.o: LLlex.h Lpars.h debug.h idf.h node.h standards.h target_sizes.h type.h chk_expr.o: LLlex.h Lpars.h chk_expr.h const.h debug.h def.h idf.h node.h scope.h standards.h type.h options.o: idfsize.h main.h ndir.h type.h -walk.o: LLlex.h Lpars.h chk_expr.h debug.h def.h desig.h f_info.h idf.h main.h node.h scope.h type.h +walk.o: LLlex.h Lpars.h chk_expr.h debug.h def.h desig.h f_info.h idf.h main.h node.h scope.h type.h walk.h casestat.o: LLlex.h Lpars.h debug.h density.h desig.h node.h type.h desig.o: LLlex.h debug.h def.h desig.h node.h scope.h type.h code.o: LLlex.h Lpars.h debug.h def.h desig.h node.h scope.h standards.h type.h diff --git a/lang/m2/comp/casestat.C b/lang/m2/comp/casestat.C index c9c728dd..7c429444 100644 --- a/lang/m2/comp/casestat.C +++ b/lang/m2/comp/casestat.C @@ -16,6 +16,7 @@ static char *RcsId = "$Header$"; #include "LLlex.h" #include "node.h" #include "desig.h" +#include "walk.h" #include "density.h" @@ -48,8 +49,6 @@ struct case_entry { */ #define compact(nr, low, up) (nr != 0 && (up - low) / nr <= DENSITY) -extern label text_label(), data_label(); - CaseCode(nd, exitlabel) struct node *nd; label exitlabel; @@ -68,7 +67,7 @@ CaseCode(nd, exitlabel) clear((char *) sh, sizeof(*sh)); WalkExpr(pnode->nd_left); sh->sh_type = pnode->nd_left->nd_type; - sh->sh_break = text_label(); + sh->sh_break = ++text_label; /* Now, create case label list */ @@ -76,7 +75,7 @@ CaseCode(nd, exitlabel) pnode = pnode->nd_right; if (pnode->nd_class == Link && pnode->nd_symb == '|') { if (pnode->nd_left) { - pnode->nd_lab = text_label(); + pnode->nd_lab = ++text_label; if (! AddCases(sh, pnode->nd_left->nd_left, pnode->nd_lab)) { @@ -89,17 +88,17 @@ CaseCode(nd, exitlabel) /* Else part */ - sh->sh_default = text_label(); + sh->sh_default = ++text_label; pnode = 0; } } /* Now generate code for the switch itself */ - tablabel = data_label(); /* the rom must have a label */ + tablabel = ++data_label; /* the rom must have a label */ C_df_dlb(tablabel); if (sh->sh_default) C_rom_ilb(sh->sh_default); - else C_rom_ilb(sh->sh_break); + else C_rom_ucon("0", pointer_size); if (compact(sh->sh_nrofentries, sh->sh_lowerbd, sh->sh_upperbd)) { /* CSA */ @@ -113,7 +112,7 @@ CaseCode(nd, exitlabel) ce = ce->next; } else if (sh->sh_default) C_rom_ilb(sh->sh_default); - else C_rom_ilb(sh->sh_break); + else C_rom_ucon("0", pointer_size); } C_lae_dlb(tablabel, (arith)0); /* perform the switch */ C_csa(word_size); diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index ea1b0a2c..e5db28b9 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -31,7 +31,7 @@ STATIC int chk_arr(expp) struct node *expp; { - return chk_designator(expp, DESIGNATOR|VARIABLE, D_USED); + return chk_designator(expp, VARIABLE, D_USED); } STATIC int @@ -54,7 +54,7 @@ STATIC int chk_linkorname(expp) register struct node *expp; { - if (chk_designator(expp, VALUE|DESIGNATOR, D_USED)) { + if (chk_designator(expp, VALUE, D_USED)) { if (expp->nd_class == Def && expp->nd_def->df_kind == D_PROCEDURE) { /* Check that this procedure is one that we @@ -269,7 +269,7 @@ getarg(argp, bases, designator) if ((!designator && !chk_expr(left)) || (designator && - !chk_designator(left, DESIGNATOR|VARIABLE, D_USED|D_NOREG))) { + !chk_designator(left, VARIABLE, D_USED|D_NOREG))) { return 0; } @@ -299,7 +299,10 @@ getname(argp, kinds) arg = arg->nd_right; if (! chk_designator(arg->nd_left, 0, D_REFERRED)) return 0; - if (arg->nd_left->nd_class != Def); + if (arg->nd_left->nd_class != Def && arg->nd_left->nd_class != LinkDef) { + node_error(arg, "identifier expected"); + return 0; + } if (!(arg->nd_left->nd_def->df_kind & kinds)) { node_error(arg, "unexpected type"); @@ -324,7 +327,7 @@ chk_proccall(expp) arg = expp; expp->nd_type = left->nd_type->next; - for (param = left->nd_type->prc_params; param; param = param->next) { + for (param = ParamList(left->nd_type); param; param = param->next) { if (!(left = getarg(&arg, 0, IsVarParam(param)))) return 0; if (left->nd_symb == STRING) { TryToString(left, TypeOfParam(param)); @@ -430,8 +433,6 @@ chk_designator(expp, flag, dflags) be something that can be assigned to. It may also contain the flag VALUE, indicating that a value is expected. In this case, VARIABLE may not be set. - It also contains the flag DESIGNATOR, indicating that '[' - and '^' are allowed for this designator. Also contained may be the flag HASSELECTORS, indicating that the result must have selectors. "dflags" contains some flags that must be set at the definition @@ -440,6 +441,11 @@ chk_designator(expp, flag, dflags) register struct def *df; register struct type *tp; + if (expp->nd_class == Def || expp->nd_class == LinkDef) { + expp->nd_def->df_flags |= dflags; + return 1; + } + expp->nd_type = error_type; if (expp->nd_class == Name) { @@ -453,7 +459,7 @@ chk_designator(expp, flag, dflags) assert(expp->nd_symb == '.'); if (! chk_designator(left, - (flag&DESIGNATOR)|HASSELECTORS, + HASSELECTORS, dflags)) return 0; tp = left->nd_type; @@ -466,6 +472,7 @@ chk_designator(expp, flag, dflags) else { expp->nd_def = df; expp->nd_type = df->df_type; + expp->nd_class = LinkDef; if (!(df->df_flags & (D_EXPORTED|D_QEXPORTED))) { /* Fields of a record are always D_QEXPORTED, so ... @@ -513,18 +520,13 @@ df->df_idf->id_text); return 1; } - if (! (flag & DESIGNATOR)) { - node_error(expp, "identifier expected"); - return 0; - } - if (expp->nd_class == Arrsel) { struct type *tpl, *tpr; assert(expp->nd_symb == '['); if ( - !chk_designator(expp->nd_left, DESIGNATOR|VARIABLE, dflags) + !chk_designator(expp->nd_left, VARIABLE, dflags) || !chk_expr(expp->nd_right) || @@ -556,7 +558,7 @@ df->df_idf->id_text); if (expp->nd_class == Arrow) { assert(expp->nd_symb == '^'); - if (! chk_designator(expp->nd_right, DESIGNATOR|VARIABLE, dflags)) { + if (! chk_designator(expp->nd_right, VARIABLE, dflags)) { return 0; } @@ -795,7 +797,7 @@ chk_uoper(expp) break; default: - assert(0); + crash("chk_uoper"); } node_error(expp, "illegal operand for unary operator \"%s\"", symbol2str(expp->nd_symb)); @@ -818,14 +820,14 @@ getvariable(argp) left = arg->nd_left; - if (! chk_designator(left, DESIGNATOR, D_REFERRED)) return 0; + if (! chk_designator(left, 0, D_REFERRED)) return 0; if (left->nd_class == Arrsel || left->nd_class == Arrow) { *argp = arg; return left; } df = 0; - if (left->nd_class == Link || left->nd_class == Def) { + if (left->nd_class == LinkDef || left->nd_class == Def) { df = left->nd_def; } @@ -917,6 +919,47 @@ DO_DEBUG(3,debug("standard name \"%s\", %d",left->nd_def->df_idf->id_text,std)); if (left->nd_class == Value) cstcall(expp, S_ORD); break; + case S_NEW: + case S_DISPOSE: + { + static int warning_given = 0; + + if (!warning_given) { + warning_given = 1; + node_warning(expp, "NEW and DISPOSE are old-fashioned"); + } + } + if (! (left = getvariable(&arg))) return 0; + if (! (left->nd_type->tp_fund == T_POINTER)) { + node_error(left, "pointer variable expected"); + return 0; + } + if (left->nd_class == Def) { + left->nd_def->df_flags |= D_NOREG; + } + /* Now, make it look like a call to ALLOCATE or DEALLOCATE */ + { + struct token dt; + struct node *nd; + + dt.TOK_INT = left->nd_type->next->tp_size; + dt.tk_symb = INTEGER; + dt.tk_lineno = left->nd_lineno; + nd = MkLeaf(Value, &dt); + nd->nd_type = card_type; + dt.tk_symb = ','; + arg->nd_right = MkNode(Link, nd, NULLNODE, &dt); + /* Ignore other arguments to NEW and/or DISPOSE ??? */ + + FreeNode(expp->nd_left); + dt.tk_symb = IDENT; + dt.tk_lineno = expp->nd_left->nd_lineno; + dt.TOK_IDF = str2idf(std == S_NEW ? + "ALLOCATE" : "DEALLOCATE", 0); + expp->nd_left = MkLeaf(Name, &dt); + } + return chk_call(expp); + case S_TSIZE: /* ??? */ case S_SIZE: expp->nd_type = intorcard_type; @@ -1080,5 +1123,6 @@ int (*ChkTable[])() = { chk_set, NodeCrash, NodeCrash, - chk_linkorname + chk_linkorname, + NodeCrash }; diff --git a/lang/m2/comp/code.c b/lang/m2/comp/code.c index 9c81eb76..5d3c66a4 100644 --- a/lang/m2/comp/code.c +++ b/lang/m2/comp/code.c @@ -21,9 +21,8 @@ static char *RcsId = "$Header$"; #include "node.h" #include "Lpars.h" #include "standards.h" +#include "walk.h" -extern label data_label(); -extern label text_label(); extern char *long2str(); extern char *symbol2str(); extern int proclevel; @@ -43,7 +42,7 @@ CodeConst(cst, size) C_ldc(cst); } else { - C_df_dlb(dlab = data_label()); + C_df_dlb(dlab = ++data_label); C_rom_icon(long2str((long) cst), size); C_lae_dlb(dlab, (arith) 0); C_loi(size); @@ -59,7 +58,7 @@ CodeString(nd) C_loc(nd->nd_INT); } else { - C_df_dlb(lab = data_label()); + C_df_dlb(lab = ++data_label); C_rom_scon(nd->nd_STR, WA(nd->nd_SLE + 1)); C_lae_dlb(lab, (arith) 0); } @@ -88,7 +87,7 @@ CodePadString(nd, sz) CodeReal(nd) register struct node *nd; { - label lab = data_label(); + label lab = ++data_label; C_df_dlb(lab); C_rom_fcon(nd->nd_REL, nd->nd_type->tp_size); @@ -114,6 +113,7 @@ CodeExpr(nd, ds, true_label, false_label) /* Fall through */ case Link: + case LinkDef: case Arrsel: case Arrow: CodeDesig(nd, ds); @@ -290,6 +290,7 @@ CodeCall(nd) and result is already done. */ register struct node *left = nd->nd_left; + register struct type *result_tp; if (left->nd_type == std_type) { CodeStd(nd); @@ -308,7 +309,7 @@ CodeCall(nd) assert(IsProcCall(left)); if (nd->nd_right) { - CodeParameters(left->nd_type->prc_params, nd->nd_right); + CodeParameters(ParamList(left->nd_type), nd->nd_right); } if (left->nd_class == Def && left->nd_def->df_kind == D_PROCEDURE) { @@ -325,8 +326,12 @@ CodeCall(nd) C_cai(); } if (left->nd_type->prc_nbpar) C_asp(left->nd_type->prc_nbpar); - if (left->nd_type->next) { - C_lfr(WA(left->nd_type->next->tp_size)); + if (result_tp = ResultType(left->nd_type)) { + if (IsConstructed(result_tp)) { + C_lfr(pointer_size); + C_loi(result_tp->tp_size); + } + else C_lfr(WA(result_tp->tp_size)); } } @@ -765,6 +770,7 @@ CodeOper(expr, true_label, false_label) C_com(tp->tp_size); C_and(tp->tp_size); C_ior(tp->tp_size); + C_zer(tp->tp_size); } C_cms(tp->tp_size); break; @@ -795,10 +801,10 @@ CodeOper(expr, true_label, false_label) case AND: case '&': if (true_label == 0) { - label l_true = text_label(); - label l_false = text_label(); - label l_maybe = text_label(); - label l_end = text_label(); + label l_true = ++text_label; + label l_false = ++text_label; + label l_maybe = ++text_label; + label l_end = ++text_label; struct desig Des; Des = InitDesig; @@ -814,7 +820,7 @@ CodeOper(expr, true_label, false_label) C_df_ilb(l_end); } else { - label l_maybe = text_label(); + label l_maybe = ++text_label; struct desig Des; Des = InitDesig; @@ -826,10 +832,10 @@ CodeOper(expr, true_label, false_label) break; case OR: if (true_label == 0) { - label l_true = text_label(); - label l_false = text_label(); - label l_maybe = text_label(); - label l_end = text_label(); + label l_true = ++text_label; + label l_false = ++text_label; + label l_maybe = ++text_label; + label l_end = ++text_label; struct desig Des; Des = InitDesig; @@ -845,7 +851,7 @@ CodeOper(expr, true_label, false_label) C_df_ilb(l_end); } else { - label l_maybe = text_label(); + label l_maybe = ++text_label; struct desig Des; Des = InitDesig; @@ -1026,13 +1032,10 @@ CodeDStore(nd) DoHIGH(nd) struct node *nd; { - register struct def *df; - arith highoff; + register struct def *df = nd->nd_def; + register arith highoff; assert(nd->nd_class == Def); - - df = nd->nd_def; - assert(df->df_kind == D_VARIABLE); highoff = df->var_off + pointer_size + word_size; diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 63c0e3c9..e6381115 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -21,23 +21,31 @@ static char *RcsId = "$Header$"; #include "misc.h" #include "main.h" -int proclevel = 0; /* nesting level of procedures */ +int proclevel = 0; /* nesting level of procedures */ +int return_occurred; /* set if a return occurred in a + procedure or function + */ } ProcedureDeclaration { - struct def *df; + register struct def *df; + struct def *df1; } : { proclevel++; } - ProcedureHeading(&df, D_PROCEDURE) + ProcedureHeading(&df1, D_PROCEDURE) { - CurrentScope->sc_definedby = df; + CurrentScope->sc_definedby = df = df1; df->prc_vis = CurrVis; + return_occurred = 0; } ';' block(&(df->prc_body)) IDENT { match_id(dot.TOK_IDF, df->df_idf); close_scope(SC_CHKFORW|SC_REVERSE); + if (! return_occurred && ResultType(df->df_type)) { +error("function procedure does not return a value", df->df_idf->id_text); + } proclevel--; } ; diff --git a/lang/m2/comp/desig.c b/lang/m2/comp/desig.c index 1a325fb2..68bebc39 100644 --- a/lang/m2/comp/desig.c +++ b/lang/m2/comp/desig.c @@ -311,7 +311,7 @@ CodeDesig(nd, ds) } break; - case Link: + case LinkDef: assert(nd->nd_symb == '.'); CodeDesig(nd->nd_left, ds); diff --git a/lang/m2/comp/lookup.c b/lang/m2/comp/lookup.c index 12775cbe..d8b89ef6 100644 --- a/lang/m2/comp/lookup.c +++ b/lang/m2/comp/lookup.c @@ -26,26 +26,31 @@ lookup(id, scope) Return a pointer to its "def" structure if it exists, otherwise return 0. */ - register struct def *df; - struct def *df1; + register struct def *df, *df1; - for (df = id->id_def, df1 = 0; df; df1 = df, df = df->next) { - if (df->df_scope == scope) { - if (df1) { - /* Put the definition in front - */ - df1->next = df->next; - df->next = id->id_def; - id->id_def = df; - } - if (df->df_kind == D_IMPORT) { - assert(df->imp_def != 0); - return df->imp_def; - } - return df; + /* Look in the chain of definitions of this "id" for one with scope + "scope". + */ + for (df = id->id_def, df1 = 0; + df && df->df_scope != scope; + df1 = df, df = df->next) { /* nothing */ } + + if (df) { + /* Found it + */ + if (df1) { + /* Put the definition in front + */ + df1->next = df->next; + df->next = id->id_def; + id->id_def = df; + } + if (df->df_kind == D_IMPORT) { + assert(df->imp_def != 0); + return df->imp_def; } } - return 0; + return df; } struct def * @@ -57,7 +62,7 @@ lookfor(id, vis, give_error) If it is not defined create a dummy definition and, if "give_error" is set, give an error message. */ - struct def *df; + register struct def *df; register struct scopelist *sc = vis; while (sc) { diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index 4a43718c..5ca3138e 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -159,6 +159,8 @@ AddStandards() (void) Enter("DEC", D_PROCEDURE, std_type, S_DEC); (void) Enter("INC", D_PROCEDURE, std_type, S_INC); (void) Enter("VAL", D_PROCEDURE, std_type, S_VAL); + (void) Enter("NEW", D_PROCEDURE, std_type, S_NEW); + (void) Enter("DISPOSE", D_PROCEDURE, std_type, S_DISPOSE); (void) Enter("TRUNC", D_PROCEDURE, std_type, S_TRUNC); (void) Enter("SIZE", D_PROCEDURE, std_type, S_SIZE); (void) Enter("ORD", D_PROCEDURE, std_type, S_ORD); diff --git a/lang/m2/comp/node.H b/lang/m2/comp/node.H index a5e83862..80006975 100644 --- a/lang/m2/comp/node.H +++ b/lang/m2/comp/node.H @@ -19,6 +19,7 @@ struct node { #define Def 9 /* an identified name */ #define Stat 10 /* a statement */ #define Link 11 +#define LinkDef 12 /* do NOT change the order or the numbers!!! */ struct type *nd_type; /* type of this node */ struct token nd_token; @@ -40,10 +41,9 @@ extern struct node *MkNode(), *MkLeaf(); #define NULLNODE ((struct node *) 0) -#define DESIGNATOR 1 -#define HASSELECTORS 2 -#define VARIABLE 4 -#define VALUE 8 +#define HASSELECTORS 002 +#define VARIABLE 004 +#define VALUE 010 -#define IsCast(lnd) ((lnd)->nd_class == Def && is_type((lnd)->nd_def)) +#define IsCast(lnd) (((lnd)->nd_class == Def || (lnd)->nd_class == LinkDef) && is_type((lnd)->nd_def)) #define IsProcCall(lnd) ((lnd)->nd_type->tp_fund == T_PROCEDURE) diff --git a/lang/m2/comp/standards.h b/lang/m2/comp/standards.h index 983b13e3..4c445b97 100644 --- a/lang/m2/comp/standards.h +++ b/lang/m2/comp/standards.h @@ -19,6 +19,8 @@ #define S_SIZE 15 #define S_TRUNC 16 #define S_VAL 17 +#define S_NEW 18 +#define S_DISPOSE 19 /* Standard procedures and functions defined in the SYSTEM module ... */ diff --git a/lang/m2/comp/statement.g b/lang/m2/comp/statement.g index 62fd0a91..fadb5e05 100644 --- a/lang/m2/comp/statement.g +++ b/lang/m2/comp/statement.g @@ -229,9 +229,12 @@ ReturnStatement(struct node **pnd;) { register struct def *df = CurrentScope->sc_definedby; register struct node *nd; + extern int return_occurred; } : - RETURN { *pnd = nd = MkLeaf(Stat, &dot); } + RETURN { *pnd = nd = MkLeaf(Stat, &dot); + return_occurred = 1; + } [ expression(&(nd->nd_right)) { if (scopeclosed(CurrentScope)) { diff --git a/lang/m2/comp/type.H b/lang/m2/comp/type.H index 90b56e35..129b8def 100644 --- a/lang/m2/comp/type.H +++ b/lang/m2/comp/type.H @@ -74,7 +74,7 @@ struct type { #define T_NUMERIC (T_INTORCARD|T_REAL) #define T_INDEX (T_ENUMERATION|T_CHAR|T_SUBRANGE) #define T_DISCRETE (T_INDEX|T_INTORCARD) -#define T_PRCRESULT (T_DISCRETE|T_REAL|T_POINTER|T_WORD) +#define T_CONSTRUCTED (T_ARRAY|T_SET|T_RECORD) int tp_align; /* alignment requirement of this type */ arith tp_size; /* size of this type */ union { @@ -136,6 +136,8 @@ struct type #define IsConformantArray(tpx) ((tpx)->tp_fund==T_ARRAY && (tpx)->next==0) #define bounded(tpx) ((tpx)->tp_fund & T_INDEX) #define complex(tpx) ((tpx)->tp_fund & (T_RECORD|T_ARRAY)) -#define returntype(tpx) (((tpx)->tp_fund & T_PRCRESULT) ||\ - ((tpx)->tp_fund == T_SET && (tpx)->tp_size <= dword_size)) #define WA(sz) (align(sz, (int) word_size)) +#define ResultType(tpx) (assert((tpx)->tp_fund == T_PROCEDURE), (tpx)->next) +#define ParamList(tpx) (assert((tpx)->tp_fund == T_PROCEDURE),\ + (tpx)->prc_params) +#define IsConstructed(tpx) ((tpx)->tp_fund & T_CONSTRUCTED) diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index 98595b18..ff0b4850 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -20,6 +20,7 @@ static char *RcsId = "$Header$"; #include "node.h" #include "const.h" #include "scope.h" +#include "walk.h" int word_align = AL_WORD, @@ -64,8 +65,6 @@ struct type *h_type; int cnt_type; #endif -extern label data_label(); - struct type * create_type(fund) int fund; @@ -93,10 +92,6 @@ construct_type(fund, tp) switch (fund) { case T_PROCEDURE: - if (tp && !returntype(tp)) { - error("illegal procedure result type"); - } - /* Fall through */ case T_POINTER: case T_HIDDEN: dtp->tp_align = pointer_align; @@ -315,11 +310,11 @@ genrck(tp) if (tp->tp_fund == T_SUBRANGE) { if (!(ol = tp->sub_rck)) { - tp->sub_rck = l = data_label(); + tp->sub_rck = l = ++data_label; } } else if (!(ol = tp->enm_rck)) { - tp->enm_rck = l = data_label(); + tp->enm_rck = l = ++data_label; } if (!ol) { ol = l; @@ -423,7 +418,7 @@ ArraySizes(tp) /* generate descriptor and remember label. */ - tp->arr_descr = data_label(); + tp->arr_descr = ++data_label; C_df_dlb(tp->arr_descr); C_rom_cst(lo); C_rom_cst(hi - lo); @@ -441,7 +436,7 @@ FreeType(tp) assert(tp->tp_fund == T_PROCEDURE); - pr = tp->prc_params; + pr = ParamList(tp); while (pr) { pr1 = pr; pr = pr->next; @@ -516,7 +511,7 @@ DumpType(tp) break; case T_PROCEDURE: { - register struct paramlist *par = tp->prc_params; + register struct paramlist *par = ParamList(tp); print("PROCEDURE"); if (par) { @@ -541,7 +536,7 @@ DumpType(tp) case T_INTORCARD: print("INTORCARD"); break; default: - assert(0); + crash("DumpType"); } print(";"); } diff --git a/lang/m2/comp/typequiv.c b/lang/m2/comp/typequiv.c index aa223409..76a66ce1 100644 --- a/lang/m2/comp/typequiv.c +++ b/lang/m2/comp/typequiv.c @@ -7,8 +7,11 @@ static char *RcsId = "$Header$"; /* Routines for testing type equivalence, type compatibility, and assignment compatibility */ +#include "debug.h" + #include #include +#include #include "type.h" #include "def.h" @@ -66,8 +69,8 @@ TstProcEquiv(tp1, tp2) */ if (! TstTypeEquiv(tp1->next, tp2->next)) return 0; - p1 = tp1->prc_params; - p2 = tp2->prc_params; + p1 = ParamList(tp1); + p2 = ParamList(tp2); /* Now check the parameters */ @@ -180,6 +183,10 @@ TstParCompat(formaltype, actualtype, VARflag, nd) TstTypeEquiv(formaltype, actualtype) || ( !VARflag && TstAssCompat(formaltype, actualtype)) + || + ( formaltype == address_type + && actualtype->tp_fund == T_POINTER + ) || ( formaltype == word_type && diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index ae214d50..c314c157 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -26,31 +26,18 @@ static char *RcsId = "$Header$"; #include "f_info.h" #include "idf.h" #include "chk_expr.h" +#include "walk.h" extern arith NewPtr(); extern arith NewInt(); extern int proclevel; -static label instructionlabel; -static char return_expr_occurred; +label text_label; +label data_label; static struct type *func_type; struct withdesig *WithDesigs; struct node *Modules; struct scope *ProcScope; -label -text_label() -{ - return instructionlabel++; -} - -label -data_label() -{ - static label datalabel = 0; - - return ++datalabel; -} - STATIC DoProfil() { @@ -58,7 +45,7 @@ DoProfil() if (! options['L']) { if (!filename_label) { - filename_label = data_label(); + filename_label = ++data_label; C_df_dlb(filename_label); C_rom_scon(FileName, (arith) (strlen(FileName) + 1)); } @@ -73,7 +60,6 @@ WalkModule(module) /* Walk through a module, and all its local definitions. Also generate code for its body. */ - register struct def *df = module->mod_vis->sc_scope->sc_def; register struct scope *sc; struct scopelist *vis; @@ -81,20 +67,10 @@ WalkModule(module) CurrVis = module->mod_vis; sc = CurrentScope; - if (!proclevel) { - /* This module is a glocal module. - Generate code to allocate storage for its variables. - They all have an explicit name. + if (!proclevel && module == Defined) { + /* This module is a global module. Export the name of its + initialization routine */ - while (df) { - if (df->df_kind == D_VARIABLE) { - C_df_dnam(df->var_name); - C_bss_cst( - WA(df->df_type->tp_size), - (arith) 0, 0); - } - df = df->df_nextinscope; - } if (state == PROGRAM) C_exp("main"); else C_exp(sc->sc_name); } @@ -108,12 +84,11 @@ WalkModule(module) this module. */ sc->sc_off = 0; - instructionlabel = 2; - func_type = 0; + text_label = 1; ProcScope = CurrentScope; - C_pro_narg(state == PROGRAM ? "main" : sc->sc_name); + C_pro_narg(state==PROGRAM && module==Defined ? "main" : sc->sc_name); DoProfil(); - if (CurrVis == Defined->mod_vis) { + if (module == Defined) { /* Body of implementation or program module. Call initialization routines of imported modules. Also prevent recursive calls of this one. @@ -121,7 +96,7 @@ WalkModule(module) struct node *nd; if (state == IMPLEMENTATION) { - label l1 = data_label(); + label l1 = ++data_label; /* we don't actually prevent recursive calls, but do nothing if called recursively */ @@ -157,44 +132,73 @@ WalkProcedure(procedure) /* Walk through the definition of a procedure and all its local definitions */ - struct scopelist *vis = CurrVis; + struct scopelist *savevis = CurrVis; register struct scope *sc; register struct type *tp; register struct paramlist *param; + label func_res_label = 0; proclevel++; CurrVis = procedure->prc_vis; ProcScope = sc = CurrentScope; + /* Generate code for all local modules and procedures + */ WalkDef(sc->sc_def); /* Generate code for this procedure */ C_pro_narg(sc->sc_name); DoProfil(); - /* generate calls to initialization routines of modules defined within + + /* Generate calls to initialization routines of modules defined within this procedure */ MkCalls(sc->sc_def); - return_expr_occurred = 0; - instructionlabel = 2; - func_type = tp = procedure->df_type->next; - if (! returntype(tp)) { - node_error(procedure->prc_body, "illegal result type"); - } - WalkNode(procedure->prc_body, (label) 0); - C_df_ilb((label) 1); - if (tp) { - if (! return_expr_occurred) { -node_error(procedure->prc_body,"function procedure does not return a value"); + + /* Make sure that arguments of size < word_size are on a + fixed place. + */ + for (param = ParamList(procedure->df_type); + param; + param = param->next) { + if (! IsVarParam(param)) { + tp = TypeOfParam(param); + + if (!IsConformantArray(tp) && tp->tp_size < word_size) { + C_lol(param->par_def->var_off); + C_lal(param->par_def->var_off); + C_sti(tp->tp_size); + } } - C_ret(WA(tp->tp_size)); } - else C_ret((arith) 0); + + text_label = 1; + func_type = tp = ResultType(procedure->df_type); + + if (IsConstructed(tp)) { + func_res_label = ++data_label; + C_df_dlb(func_res_label); + C_bss_cst(tp->tp_size, (arith) 0, 0); + } + + WalkNode(procedure->prc_body, (label) 0); + C_ret((arith) 0); + if (tp) { + C_df_ilb((label) 1); + if (func_res_label) { + C_lae_dlb(func_res_label, (arith) 0); + C_sti(tp->tp_size); + C_lae_dlb(func_res_label, (arith) 0); + C_ret(pointer_size); + } + else C_ret(WA(tp->tp_size)); + } + RegisterMessages(sc->sc_def); C_end(-sc->sc_off); TmpClose(); - CurrVis = vis; + CurrVis = savevis; proclevel--; } @@ -211,6 +215,12 @@ WalkDef(df) else if (df->df_kind == D_PROCEDURE) { WalkProcedure(df); } + else if (!proclevel && df->df_kind == D_VARIABLE) { + C_df_dnam(df->var_name); + C_bss_cst( + WA(df->df_type->tp_size), + (arith) 0, 0); + } df = df->df_nextinscope; } } @@ -231,22 +241,36 @@ MkCalls(df) } } -WalkNode(nd, lab) +WalkLink(nd, lab) register struct node *nd; label lab; { - /* Node "nd" represents either a statement or a statement list. - Walk through it. + /* Walk node "nd", which is a link. "lab" represents the label that must be jumped to on encountering an EXIT statement. */ - while (nd->nd_class == Link) { /* statement list */ - WalkStat(nd->nd_left, lab); + while (nd && nd->nd_class == Link) { /* statement list */ + WalkNode(nd->nd_left, lab); nd = nd->nd_right; } - WalkStat(nd, lab); + WalkNode(nd, lab); +} + +WalkCall(nd) + register struct node *nd; +{ + assert(nd->nd_class == Call); + + if (! options['L']) C_lin((arith) nd->nd_lineno); + if (chk_call(nd)) { + if (nd->nd_type != 0) { + node_error(nd, "procedure call expected"); + return; + } + CodeCall(nd); + } } WalkStat(nd, lab) @@ -260,27 +284,9 @@ WalkStat(nd, lab) register struct node *left = nd->nd_left; register struct node *right = nd->nd_right; - if (!nd) { - /* Empty statement - */ - return; - } - - if (! options['L']) C_lin((arith) nd->nd_lineno); - - if (nd->nd_class == Call) { - if (chk_call(nd)) { - if (nd->nd_type != 0) { - node_error(nd, "procedure call expected"); - return; - } - CodeCall(nd); - } - return; - } - assert(nd->nd_class == Stat); + if (! options['L']) C_lin((arith) nd->nd_lineno); switch(nd->nd_symb) { case BECOMES: DoAssign(nd, left, right); @@ -289,9 +295,9 @@ WalkStat(nd, lab) case IF: { label l1, l2, l3; - l1 = instructionlabel++; - l2 = instructionlabel++; - l3 = instructionlabel++; + l1 = ++text_label; + l2 = ++text_label; + l3 = ++text_label; ExpectBool(left, l3, l1); assert(right->nd_symb == THEN); C_df_ilb(l3); @@ -314,9 +320,9 @@ WalkStat(nd, lab) case WHILE: { label l1, l2, l3; - l1 = instructionlabel++; - l2 = instructionlabel++; - l3 = instructionlabel++; + l1 = ++text_label; + l2 = ++text_label; + l3 = ++text_label; C_df_ilb(l1); ExpectBool(left, l3, l2); C_df_ilb(l3); @@ -329,8 +335,8 @@ WalkStat(nd, lab) case REPEAT: { label l1, l2; - l1 = instructionlabel++; - l2 = instructionlabel++; + l1 = ++text_label; + l2 = ++text_label; C_df_ilb(l1); WalkNode(left, lab); ExpectBool(right, l2, l1); @@ -341,8 +347,8 @@ WalkStat(nd, lab) case LOOP: { label l1, l2; - l1 = instructionlabel++; - l2 = instructionlabel++; + l1 = ++text_label; + l2 = ++text_label; C_df_ilb(l1); WalkNode(right, l2); C_bra(l1); @@ -354,8 +360,8 @@ WalkStat(nd, lab) { arith tmp = 0; struct node *fnd; - label l1 = instructionlabel++; - label l2 = instructionlabel++; + label l1 = ++text_label; + label l2 = ++text_label; if (! DoForInit(nd, left)) break; fnd = left->nd_right; @@ -432,14 +438,16 @@ WalkStat(nd, lab) case RETURN: if (right) { WalkExpr(right); - /* Assignment compatibility? Yes, see Rep. 9.11 + /* The type of the return-expression must be + assignment compatible with the result type of the + function procedure (See Rep. 9.11). */ if (!TstAssCompat(func_type, right->nd_type)) { node_error(right, "type incompatibility in RETURN statement"); } - return_expr_occurred = 1; + C_bra((label) 1); } - C_bra((label) 1); + else C_ret((arith) 0); break; default: @@ -447,6 +455,24 @@ node_error(right, "type incompatibility in RETURN statement"); } } +extern int NodeCrash(); + +int (*WalkTable[])() = { + NodeCrash, + NodeCrash, + NodeCrash, + NodeCrash, + NodeCrash, + WalkCall, + NodeCrash, + NodeCrash, + NodeCrash, + NodeCrash, + WalkStat, + WalkLink, + NodeCrash +}; + ExpectBool(nd, true_label, false_label) register struct node *nd; label true_label, false_label; @@ -488,7 +514,7 @@ WalkDesignator(nd, ds) DO_DEBUG(1, (DumpTree(nd), print("\n"))); - if (! chk_designator(nd, DESIGNATOR|VARIABLE, D_DEFINED)) return; + if (! chk_designator(nd, VARIABLE, D_DEFINED)) return; *ds = InitDesig; CodeDesig(nd, ds); @@ -497,6 +523,7 @@ WalkDesignator(nd, ds) DoForInit(nd, left) register struct node *nd, *left; { + register struct def *df; nd->nd_left = nd->nd_right = 0; nd->nd_class = Name; @@ -506,6 +533,30 @@ DoForInit(nd, left) ! chk_expr(left->nd_left) || ! chk_expr(left->nd_right)) return 0; + df = nd->nd_def; + if (df->df_kind == D_FIELD) { + node_error(nd, "FOR-loop variable may not be a field of a record"); + return 0; + } + + if (!df->var_name && df->var_off >= 0) { + node_error(nd, "FOR-loop variable may not be a parameter"); + return 0; + } + + if (df->df_scope != CurrentScope) { + register struct scopelist *sc = CurrVis; + + while (sc && sc->sc_scope != df->df_scope) { + sc = nextvisible(sc); + } + + if (!sc) { + node_error(nd, "FOR-loop variable may not be imported"); + return 0; + } + } + if (nd->nd_type->tp_size > word_size || !(nd->nd_type->tp_fund & T_DISCRETE)) { node_error(nd, "illegal type of FOR loop variable"); @@ -536,7 +587,7 @@ DoAssign(nd, left, right) struct desig dsl, dsr; if (!chk_expr(right)) return; - if (! chk_designator(left, DESIGNATOR|VARIABLE, D_DEFINED)) return; + if (! chk_designator(left, VARIABLE, D_DEFINED)) return; TryToString(right, left->nd_type); dsr = InitDesig; CodeExpr(right, &dsr, NO_LABEL, NO_LABEL); diff --git a/lang/m2/comp/walk.h b/lang/m2/comp/walk.h new file mode 100644 index 00000000..439f2c2a --- /dev/null +++ b/lang/m2/comp/walk.h @@ -0,0 +1,13 @@ +/* P A R S E T R E E W A L K E R */ + +/* $Header$ */ + +/* Definition of WalkNode macro +*/ + +extern int (*WalkTable[])(); + +#define WalkNode(xnd, xlab) ((xnd) && (*WalkTable[(xnd)->nd_class])((xnd), (xlab))) + +extern label text_label; +extern label data_label; From d46c6d1cae12e79c28baeb9e11da78ad02965a1e Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 26 Jun 1986 09:39:36 +0000 Subject: [PATCH 0211/1625] newer version --- lang/m2/comp/Makefile | 12 +- lang/m2/comp/Parameters | 4 +- lang/m2/comp/chk_expr.c | 488 ++++++++++++++++++-------------------- lang/m2/comp/chk_expr.h | 8 +- lang/m2/comp/code.c | 19 +- lang/m2/comp/cstoper.c | 3 +- lang/m2/comp/declar.g | 75 +++--- lang/m2/comp/defmodule.c | 2 +- lang/m2/comp/expression.g | 10 +- lang/m2/comp/main.c | 6 +- lang/m2/comp/node.c | 33 +-- lang/m2/comp/program.g | 4 +- lang/m2/comp/scope.C | 2 +- lang/m2/comp/statement.g | 5 +- lang/m2/comp/tmpvar.C | 5 +- lang/m2/comp/type.H | 19 +- lang/m2/comp/type.c | 14 +- lang/m2/comp/typequiv.c | 16 +- lang/m2/comp/walk.c | 108 +++------ 19 files changed, 387 insertions(+), 446 deletions(-) diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index e6d968bf..f4caf84b 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -97,26 +97,26 @@ symbol2str.o: Lpars.h tokenname.o: Lpars.h idf.h tokenname.h idf.o: idf.h input.o: f_info.h input.h inputtype.h -type.o: LLlex.h const.h debug.h def.h idf.h maxset.h node.h scope.h target_sizes.h type.h +type.o: LLlex.h const.h debug.h def.h idf.h maxset.h node.h scope.h target_sizes.h type.h walk.h def.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h type.h scope.o: LLlex.h debug.h def.h idf.h node.h scope.h type.h misc.o: LLlex.h f_info.h idf.h misc.h node.h enter.o: LLlex.h debug.h def.h idf.h main.h node.h scope.h type.h defmodule.o: LLlex.h debug.h def.h f_info.h idf.h input.h inputtype.h main.h scope.h -typequiv.o: LLlex.h def.h node.h type.h +typequiv.o: LLlex.h debug.h def.h node.h type.h node.o: LLlex.h debug.h def.h node.h type.h cstoper.o: LLlex.h Lpars.h debug.h idf.h node.h standards.h target_sizes.h type.h chk_expr.o: LLlex.h Lpars.h chk_expr.h const.h debug.h def.h idf.h node.h scope.h standards.h type.h options.o: idfsize.h main.h ndir.h type.h walk.o: LLlex.h Lpars.h chk_expr.h debug.h def.h desig.h f_info.h idf.h main.h node.h scope.h type.h walk.h -casestat.o: LLlex.h Lpars.h debug.h density.h desig.h node.h type.h +casestat.o: LLlex.h Lpars.h debug.h density.h desig.h node.h type.h walk.h desig.o: LLlex.h debug.h def.h desig.h node.h scope.h type.h -code.o: LLlex.h Lpars.h debug.h def.h desig.h node.h scope.h standards.h type.h -tmpvar.o: debug.h def.h scope.h type.h +code.o: LLlex.h Lpars.h debug.h def.h desig.h node.h scope.h standards.h type.h walk.h +tmpvar.o: debug.h def.h main.h scope.h type.h lookup.o: LLlex.h debug.h def.h idf.h node.h scope.h tokenfile.o: Lpars.h program.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h type.h -declar.o: LLlex.h Lpars.h debug.h def.h idf.h main.h misc.h node.h scope.h type.h +declar.o: LLlex.h Lpars.h chk_expr.h debug.h def.h idf.h main.h misc.h node.h scope.h type.h expression.o: LLlex.h Lpars.h chk_expr.h const.h debug.h def.h idf.h node.h type.h statement.o: LLlex.h Lpars.h def.h idf.h node.h scope.h type.h Lpars.o: Lpars.h diff --git a/lang/m2/comp/Parameters b/lang/m2/comp/Parameters index 82e019a8..acda8568 100644 --- a/lang/m2/comp/Parameters +++ b/lang/m2/comp/Parameters @@ -49,9 +49,9 @@ #define DEBUG 1 /* perform various self-tests */ extern char options[]; #ifdef DEBUG -#define DO_DEBUG(n, x) ((n) <= options['D'] && (x)) +#define DO_DEBUG(y, x) ((y) && (x)) #else -#define DO_DEBUG(n, x) +#define DO_DEBUG(y, x) #endif DEBUG !File: inputtype.h diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index e5db28b9..1d8b93d0 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -27,11 +27,87 @@ static char *RcsId = "$Header$"; extern char *symbol2str(); +int +chk_variable(expp) + register struct node *expp; +{ + + if (! chk_designator(expp)) return 0; + + if (expp->nd_class == Def && + !(expp->nd_def->df_kind & (D_FIELD|D_VARIABLE))) { + node_error(expp, "variable expected"); + return 0; + } + + return 1; +} + +STATIC int +chk_arrow(expp) + register struct node *expp; +{ + register struct type *tp; + + assert(expp->nd_class == Arrow); + assert(expp->nd_symb == '^'); + + expp->nd_type = error_type; + + if (! chk_variable(expp->nd_right)) return 0; + + tp = expp->nd_right->nd_type; + + if (tp->tp_fund != T_POINTER) { + node_error(expp, "illegal operand for unary operator \"%s\"", + symbol2str(expp->nd_symb)); + return 0; + } + + expp->nd_type = PointedtoType(tp); + return 1; +} + STATIC int chk_arr(expp) - struct node *expp; + register struct node *expp; { - return chk_designator(expp, VARIABLE, D_USED); + register struct type *tpl, *tpr; + + assert(expp->nd_class == Arrsel); + assert(expp->nd_symb == '['); + + expp->nd_type = error_type; + + if ( + !chk_variable(expp->nd_left) + || + !chk_expr(expp->nd_right) + || + expp->nd_left->nd_type == error_type + ) return 0; + + tpl = expp->nd_left->nd_type; + tpr = expp->nd_right->nd_type; + + if (tpl->tp_fund != T_ARRAY) { + node_error(expp, "array index not belonging to an ARRAY"); + return 0; + } + + /* Type of the index must be assignment compatible with + the index type of the array (Def 8.1). + However, the index type of a conformant array is not specified. + Either INTEGER or CARDINAL seems reasonable. + */ + if (IsConformantArray(tpl) ? !TstAssCompat(card_type, tpr) + : !TstAssCompat(IndexType(tpl), tpr)) { + node_error(expp, "incompatible index type"); + return 0; + } + + expp->nd_type = tpl->arr_elem; + return 1; } STATIC int @@ -54,24 +130,107 @@ STATIC int chk_linkorname(expp) register struct node *expp; { - if (chk_designator(expp, VALUE, D_USED)) { - if (expp->nd_class == Def && - expp->nd_def->df_kind == D_PROCEDURE) { - /* Check that this procedure is one that we - may take the address from. - */ - if (expp->nd_def->df_type == std_type || - expp->nd_def->df_scope->sc_level > 0) { - /* Address of standard or nested procedure - taken. + register struct def *df; + + if (expp->nd_class == Name) { + expp->nd_def = lookfor(expp, CurrVis, 1); + expp->nd_class = Def; + expp->nd_type = expp->nd_def->df_type; + } + else if (expp->nd_class == Link) { + register struct node *left = expp->nd_left; + + assert(expp->nd_symb == '.'); + + if (! chk_designator(left)) return 0; + + if (left->nd_type->tp_fund != T_RECORD || + (left->nd_class == Def && + !(left->nd_def->df_kind & (D_MODULE|D_VARIABLE|D_FIELD)) + ) + ) { + node_error(left, "illegal selection"); + return 0; + } + + if (!(df = lookup(expp->nd_IDF, left->nd_type->rec_scope))) { + id_not_declared(expp); + return 0; + } + else { + expp->nd_def = df; + expp->nd_type = df->df_type; + expp->nd_class = LinkDef; + if (!(df->df_flags & (D_EXPORTED|D_QEXPORTED))) { + /* Fields of a record are always D_QEXPORTED, + so ... */ -node_error(expp, "it is illegal to take the address of a standard or local procedure"); +node_error(expp, "identifier \"%s\" not exported from qualifying module", +df->df_idf->id_text); return 0; } } - return 1; + + if (left->nd_class == Def && + left->nd_def->df_kind == D_MODULE) { + expp->nd_class = Def; + FreeNode(left); + expp->nd_left = 0; + } + else return 1; } - return 0; + + assert(expp->nd_class == Def); + + df = expp->nd_def; + + if (df->df_kind & (D_ENUM | D_CONST)) { + if (df->df_kind == D_ENUM) { + expp->nd_class = Value; + expp->nd_INT = df->enm_val; + expp->nd_symb = INTEGER; + } + else { + unsigned int ln; + + assert(df->df_kind == D_CONST); + ln = expp->nd_lineno; + *expp = *(df->con_const); + expp->nd_lineno = ln; + } + } + + return 1; +} + +STATIC int +chk_ex_linkorname(expp) + register struct node *expp; +{ + register struct def *df; + + if (! chk_linkorname(expp)) return 0; + if (expp->nd_class != Def) return 1; + df = expp->nd_def; + + if (!(df->df_kind & (D_ENUM|D_CONST|D_PROCEDURE|D_FIELD|D_VARIABLE|D_PROCHEAD))) { + node_error(expp, "value expected"); + } + + if (df->df_kind == D_PROCEDURE) { + /* Check that this procedure is one that we + may take the address from. + */ + if (df->df_type == std_type || df->df_scope->sc_level > 0) { + /* Address of standard or nested procedure + taken. + */ +node_error(expp, "it is illegal to take the address of a standard or local procedure"); + return 0; + } + } + + return 1; } STATIC int @@ -186,7 +345,7 @@ chk_set(expp) if (nd = expp->nd_left) { /* A type was given. Check it out */ - if (! chk_designator(nd, 0, D_USED)) return 0; + if (! chk_designator(nd)) return 0; assert(nd->nd_class == Def); df = nd->nd_def; @@ -224,7 +383,7 @@ node_error(expp, "specifier does not represent a set type"); while (nd) { assert(nd->nd_class == Link && nd->nd_symb == ','); - if (!chk_el(nd->nd_left, tp->next, &set)) return 0; + if (!chk_el(nd->nd_left, ElementType(tp), &set)) return 0; nd = nd->nd_right; } @@ -268,13 +427,11 @@ getarg(argp, bases, designator) left = arg->nd_left; if ((!designator && !chk_expr(left)) || - (designator && - !chk_designator(left, VARIABLE, D_USED|D_NOREG))) { + (designator && !chk_variable(left))) { return 0; } - tp = left->nd_type; - if (tp->tp_fund == T_SUBRANGE) tp = tp->next; + tp = BaseType(left->nd_type); if (bases && !(tp->tp_fund & bases)) { node_error(arg, "unexpected type"); @@ -297,7 +454,7 @@ getname(argp, kinds) } arg = arg->nd_right; - if (! chk_designator(arg->nd_left, 0, D_REFERRED)) return 0; + if (! chk_designator(arg->nd_left)) return 0; if (arg->nd_left->nd_class != Def && arg->nd_left->nd_class != LinkDef) { node_error(arg, "identifier expected"); @@ -325,7 +482,7 @@ chk_proccall(expp) left = expp->nd_left; arg = expp; - expp->nd_type = left->nd_type->next; + expp->nd_type = ResultType(left->nd_type); for (param = ParamList(left->nd_type); param; param = param->next) { if (!(left = getarg(&arg, 0, IsVarParam(param)))) return 0; @@ -358,12 +515,14 @@ chk_call(expp) it may also be a cast or a standard procedure call. */ register struct node *left; + STATIC int chk_std(); + STATIC int chk_cast(); /* First, get the name of the function or procedure */ expp->nd_type = error_type; left = expp->nd_left; - if (! chk_designator(left, 0, D_USED)) return 0; + if (! chk_designator(left)) return 0; if (IsCast(left)) { /* It was a type cast. This is of course not portable. @@ -390,192 +549,6 @@ chk_call(expp) return 0; } -STATIC int -FlagCheck(expp, df, flag) - struct node *expp; - struct def *df; -{ - /* See the routine "chk_designator" for an explanation of - "flag". Here, a definition "df" is checked against it. - */ - - if (df->df_kind == D_ERROR) return 0; - - if ((flag & VARIABLE) && - !(df->df_kind & (D_FIELD|D_VARIABLE))) { - node_error(expp, "variable expected"); - return 0; - } - - if ((flag & HASSELECTORS) && - ( !(df->df_kind & (D_VARIABLE|D_FIELD|D_MODULE)) || - df->df_type->tp_fund != T_RECORD)) { - node_error(expp, "illegal selection"); - return 0; - } - - if ((flag & VALUE) && - ( !(df->df_kind & (D_VARIABLE|D_FIELD|D_CONST|D_ENUM|D_PROCEDURE)))) { - node_error(expp, "value expected"); - return 0; - } - - return 1; -} - -int -chk_designator(expp, flag, dflags) - register struct node *expp; -{ - /* Find the name indicated by "expp", starting from the current - scope. "flag" indicates the kind of designator we expect: - It contains the flags VARIABLE, indicating that the result must - be something that can be assigned to. - It may also contain the flag VALUE, indicating that a - value is expected. In this case, VARIABLE may not be set. - Also contained may be the flag HASSELECTORS, indicating that - the result must have selectors. - "dflags" contains some flags that must be set at the definition - found. - */ - register struct def *df; - register struct type *tp; - - if (expp->nd_class == Def || expp->nd_class == LinkDef) { - expp->nd_def->df_flags |= dflags; - return 1; - } - - expp->nd_type = error_type; - - if (expp->nd_class == Name) { - expp->nd_def = lookfor(expp, CurrVis, 1); - expp->nd_class = Def; - expp->nd_type = expp->nd_def->df_type; - } - else if (expp->nd_class == Link) { - register struct node *left = expp->nd_left; - - assert(expp->nd_symb == '.'); - - if (! chk_designator(left, - HASSELECTORS, - dflags)) return 0; - - tp = left->nd_type; - assert(tp->tp_fund == T_RECORD); - - if (!(df = lookup(expp->nd_IDF, tp->rec_scope))) { - id_not_declared(expp); - return 0; - } - else { - expp->nd_def = df; - expp->nd_type = df->df_type; - expp->nd_class = LinkDef; - if (!(df->df_flags & (D_EXPORTED|D_QEXPORTED))) { - /* Fields of a record are always D_QEXPORTED, - so ... - */ -node_error(expp, "identifier \"%s\" not exported from qualifying module", -df->df_idf->id_text); - return 0; - } - } - - if (left->nd_class == Def && - left->nd_def->df_kind == D_MODULE) { - expp->nd_class = Def; - FreeNode(left); - expp->nd_left = 0; - } - else { - return FlagCheck(expp, df, flag); - } - } - - if (expp->nd_class == Def) { - df = expp->nd_def; - - if (! FlagCheck(expp, df, flag)) return 0; - - if (df->df_kind & (D_ENUM | D_CONST)) { - if (df->df_kind == D_ENUM) { - expp->nd_class = Value; - expp->nd_INT = df->enm_val; - expp->nd_symb = INTEGER; - } - else { - unsigned int ln; - - assert(df->df_kind == D_CONST); - ln = expp->nd_lineno; - *expp = *(df->con_const); - expp->nd_lineno = ln; - } - } - - df->df_flags |= dflags; - - return 1; - } - - if (expp->nd_class == Arrsel) { - struct type *tpl, *tpr; - - assert(expp->nd_symb == '['); - - if ( - !chk_designator(expp->nd_left, VARIABLE, dflags) - || - !chk_expr(expp->nd_right) - || - expp->nd_left->nd_type == error_type - ) return 0; - - tpr = expp->nd_right->nd_type; - tpl = expp->nd_left->nd_type; - - if (tpl->tp_fund != T_ARRAY) { - node_error(expp, - "array index not belonging to an ARRAY"); - return 0; - } - - /* Type of the index must be assignment compatible with - the index type of the array (Def 8.1) - */ - if ((tpl->next && !TstAssCompat(tpl->next, tpr)) || - (!tpl->next && !TstAssCompat(intorcard_type, tpr))) { - node_error(expp, "incompatible index type"); - return 0; - } - - expp->nd_type = tpl->arr_elem; - return 1; - } - - if (expp->nd_class == Arrow) { - assert(expp->nd_symb == '^'); - - if (! chk_designator(expp->nd_right, VARIABLE, dflags)) { - return 0; - } - - if (expp->nd_right->nd_type->tp_fund != T_POINTER) { -node_error(expp, "illegal operand for unary operator \"%s\"", -symbol2str(expp->nd_symb)); - return 0; - } - - expp->nd_type = expp->nd_right->nd_type->next; - return 1; - } - - node_error(expp, "designator expected"); - return 0; -} - STATIC struct type * ResultOfOperation(operator, tp) struct type *tp; @@ -663,11 +636,8 @@ chk_oper(expp) if (!chk_expr(left) || !chk_expr(right)) return 0; - tpl = left->nd_type; - tpr = right->nd_type; - - if (tpl->tp_fund == T_SUBRANGE) tpl = tpl->next; - if (tpr->tp_fund == T_SUBRANGE) tpr = tpr->next; + tpl = BaseType(left->nd_type); + tpr = BaseType(right->nd_type); if (tpl == intorcard_type) { if (tpr == int_type || tpr == card_type) { @@ -688,7 +658,7 @@ chk_oper(expp) node_error(expp, "RHS of IN operator not a SET type"); return 0; } - if (!TstAssCompat(tpl, tpr->next)) { + if (!TstAssCompat(tpl, ElementType(tpr))) { /* Assignment compatible ??? I don't know! Should we be allowed to check if a CARDINAL is a member of a BITSET??? @@ -746,8 +716,7 @@ chk_uoper(expp) if (! chk_expr(right)) return 0; - tpr = right->nd_type; - if (tpr->tp_fund == T_SUBRANGE) tpr = tpr->next; + tpr = BaseType(right->nd_type); expp->nd_type = tpr; switch(expp->nd_symb) { @@ -809,8 +778,6 @@ getvariable(argp) struct node **argp; { register struct node *arg = *argp; - register struct def *df; - register struct node *left; arg = arg->nd_right; if (!arg) { @@ -818,29 +785,13 @@ getvariable(argp) return 0; } - left = arg->nd_left; - - if (! chk_designator(left, 0, D_REFERRED)) return 0; - if (left->nd_class == Arrsel || left->nd_class == Arrow) { - *argp = arg; - return left; - } - - df = 0; - if (left->nd_class == LinkDef || left->nd_class == Def) { - df = left->nd_def; - } - - if (!df || !(df->df_kind & (D_VARIABLE|D_FIELD))) { - node_error(arg, "variable expected"); - return 0; - } + if (! chk_variable(arg->nd_left)) return 0; *argp = arg; - return left; + return arg->nd_left; } -int +STATIC int chk_std(expp, left) register struct node *expp, *left; { @@ -852,8 +803,6 @@ chk_std(expp, left) assert(left->nd_class == Def); std = left->nd_def->df_value.df_stdname; -DO_DEBUG(3,debug("standard name \"%s\", %d",left->nd_def->df_idf->id_text,std)); - switch(std) { case S_ABS: if (!(left = getarg(&arg, T_NUMERIC, 0))) return 0; @@ -883,13 +832,15 @@ DO_DEBUG(3,debug("standard name \"%s\", %d",left->nd_def->df_idf->id_text,std)); case S_HIGH: if (!(left = getarg(&arg, T_ARRAY, 0))) return 0; - expp->nd_type = left->nd_type->next; - if (!expp->nd_type) { - /* A dynamic array has no explicit index type + if (IsConformantArray(left->nd_type)) { + /* A conformant array has no explicit index type */ - expp->nd_type = intorcard_type; + expp->nd_type = card_type; + } + else { + expp->nd_type = IndexType(left->nd_type); + cstcall(expp, S_MAX); } - else cstcall(expp, S_MAX); break; case S_MAX: @@ -942,7 +893,7 @@ DO_DEBUG(3,debug("standard name \"%s\", %d",left->nd_def->df_idf->id_text,std)); struct token dt; struct node *nd; - dt.TOK_INT = left->nd_type->next->tp_size; + dt.TOK_INT = PointedtoType(left->nd_type)->tp_size; dt.tk_symb = INTEGER; dt.tk_lineno = left->nd_lineno; nd = MkLeaf(Value, &dt); @@ -978,7 +929,6 @@ DO_DEBUG(3,debug("standard name \"%s\", %d",left->nd_def->df_idf->id_text,std)); if (!(left = getname(&arg, D_ISTYPE))) return 0; tp = left->nd_def->df_type; - if (tp->tp_fund == T_SUBRANGE) tp = tp->next; if (!(tp->tp_fund & T_DISCRETE)) { node_error(arg, "unexpected type"); return 0; @@ -1028,7 +978,7 @@ node_error(arg, "EXCL and INCL expect a SET parameter"); return 0; } if (!(left = getarg(&arg, T_DISCRETE, 0))) return 0; - if (!TstAssCompat(tp->next, left->nd_type)) { + if (!TstAssCompat(ElementType(tp), left->nd_type)) { /* What type of compatibility do we want here? apparently assignment compatibility! ??? ??? */ @@ -1050,6 +1000,7 @@ node_error(arg, "EXCL and INCL expect a SET parameter"); return 1; } +STATIC int chk_cast(expp, left) register struct node *expp, *left; { @@ -1109,20 +1060,51 @@ TryToString(nd, tp) } } +STATIC int +no_desig(expp) + struct node *expp; +{ + node_error(expp, "designator expected"); + return 0; +} + +STATIC int +done_before(expp) + struct node *expp; +{ + return 1; +} + extern int NodeCrash(); -int (*ChkTable[])() = { +int (*ExprChkTable[])() = { chk_value, chk_arr, chk_oper, chk_uoper, - chk_arr, + chk_arrow, chk_call, - chk_linkorname, + chk_ex_linkorname, NodeCrash, chk_set, NodeCrash, NodeCrash, - chk_linkorname, + chk_ex_linkorname, NodeCrash }; + +int (*DesigChkTable[])() = { + chk_value, + chk_arr, + no_desig, + no_desig, + chk_arrow, + no_desig, + chk_linkorname, + NodeCrash, + no_desig, + done_before, + NodeCrash, + chk_linkorname, + done_before +}; diff --git a/lang/m2/comp/chk_expr.h b/lang/m2/comp/chk_expr.h index 6b4422b3..d24ed645 100644 --- a/lang/m2/comp/chk_expr.h +++ b/lang/m2/comp/chk_expr.h @@ -2,8 +2,12 @@ /* $Header$ */ -extern int (*ChkTable[])(); /* table of expression checking +extern int (*ExprChkTable[])(); /* table of expression checking + functions, indexed by node class + */ +extern int (*DesigChkTable[])(); /* table of designator checking functions, indexed by node class */ -#define chk_expr(expp) ((*ChkTable[(expp)->nd_class])(expp)) +#define chk_expr(expp) ((*ExprChkTable[(expp)->nd_class])(expp)) +#define chk_designator(expp) ((*DesigChkTable[(expp)->nd_class])(expp)) diff --git a/lang/m2/comp/code.c b/lang/m2/comp/code.c index 5d3c66a4..60b6c6a4 100644 --- a/lang/m2/comp/code.c +++ b/lang/m2/comp/code.c @@ -193,8 +193,8 @@ CodeCoercion(t1, t2) { register int fund1, fund2; - if (t1->tp_fund == T_SUBRANGE) t1 = t1->next; - if (t2->tp_fund == T_SUBRANGE) t2 = t2->next; + t1 = BaseType(t1); + t2 = BaseType(t2); if (t1 == t2) return; if ((fund1 = t1->tp_fund) == T_WORD) fund1 = T_INTEGER; if ((fund2 = t2->tp_fund) == T_WORD) fund2 = T_INTEGER; @@ -368,7 +368,7 @@ CodeParameters(param, arg) C_loc(left->nd_type->tp_size / word_size - 1); } else { - tp = left->nd_type->next; + tp = IndexType(left->nd_type); if (tp->tp_fund == T_SUBRANGE) { C_loc(tp->sub_ub - tp->sub_lb); } @@ -402,8 +402,7 @@ CodeStd(nd) if (arg) { left = arg->nd_left; - tp = left->nd_type; - if (tp->tp_fund == T_SUBRANGE) tp = tp->next; + tp = BaseType(left->nd_type); arg = arg->nd_right; } @@ -736,8 +735,7 @@ CodeOper(expr, true_label, false_label) case '#': Operands(leftop, rightop); CodeCoercion(rightop->nd_type, leftop->nd_type); - tp = leftop->nd_type; /* Not the result type! */ - if (tp->tp_fund == T_SUBRANGE) tp = tp->next; + tp = BaseType(leftop->nd_type); /* Not the result type! */ switch (tp->tp_fund) { case T_INTEGER: C_cmi(tp->tp_size); @@ -970,13 +968,14 @@ CodeEl(nd, tp) register struct node *nd; register struct type *tp; { + register struct type *eltype = ElementType(tp); if (nd->nd_class == Link && nd->nd_symb == UPTO) { C_loc(tp->tp_size); /* push size */ - if (tp->next->tp_fund == T_SUBRANGE) { - C_loc(tp->next->sub_ub); + if (eltype->tp_fund == T_SUBRANGE) { + C_loc(eltype->sub_ub); } - else C_loc((arith) (tp->next->enm_ncst - 1)); + else C_loc((arith) (eltype->enm_ncst - 1)); Operands(nd->nd_left, nd->nd_right); C_cal("_LtoUset"); /* library routine to fill set */ C_asp(4 * word_size); diff --git a/lang/m2/comp/cstoper.c b/lang/m2/comp/cstoper.c index 120793c3..30ac8c7a 100644 --- a/lang/m2/comp/cstoper.c +++ b/lang/m2/comp/cstoper.c @@ -466,12 +466,11 @@ CutSize(expr) conform to the size of the type of the expression. */ arith o1 = expr->nd_INT; - struct type *tp = expr->nd_type; + struct type *tp = BaseType(expr->nd_type); int uns; int size = tp->tp_size; assert(expr->nd_class == Value); - if (tp->tp_fund == T_SUBRANGE) tp = tp->next; uns = (tp->tp_fund & (T_CARDINAL|T_CHAR)); if (uns) { if (o1 & ~full_mask[size]) { diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index e6381115..3b1bc590 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -20,6 +20,7 @@ static char *RcsId = "$Header$"; #include "node.h" #include "misc.h" #include "main.h" +#include "chk_expr.h" int proclevel = 0; /* nesting level of procedures */ int return_occurred; /* set if a return occurred in a @@ -52,25 +53,27 @@ error("function procedure does not return a value", df->df_idf->id_text); ProcedureHeading(struct def **pdf; int type;) { - struct type *tp = 0; struct paramlist *params = 0; + struct type *tp = 0; register struct def *df; struct def *DeclProc(); + arith NBytesParams; } : PROCEDURE IDENT { df = DeclProc(type); - tp = construct_type(T_PROCEDURE, tp); if (proclevel > 1) { /* Room for static link */ - tp->prc_nbpar = pointer_size; + NBytesParams = pointer_size; } - else tp->prc_nbpar = 0; + else NBytesParams = 0; } - FormalParameters(¶ms, &(tp->next), &(tp->prc_nbpar))? + FormalParameters(¶ms, &tp, &NBytesParams)? { + tp = construct_type(T_PROCEDURE, tp); tp->prc_params = params; + tp->prc_nbpar = NBytesParams; if (df->df_type) { /* We already saw a definition of this type in the definition module. @@ -85,15 +88,10 @@ error("inconsistent procedure declaration for \"%s\"", df->df_idf->id_text); if (type == D_PROCHEAD) close_scope(0); - DO_DEBUG(1, type == D_PROCEDURE && - (print("proc %s:", df->df_idf->id_text), - DumpType(tp), print("\n"))); } ; -block(struct node **pnd;) -{ -}: +block(struct node **pnd;) : declaration* [ BEGIN @@ -130,7 +128,6 @@ FormalParameters(struct paramlist **pr; ]* ]? ')' - { *tp = 0; } [ ':' qualident(D_ISTYPE, &df, "type", (struct node **) 0) { *tp = df->df_type; } @@ -142,31 +139,45 @@ FPSection(struct paramlist **ppr; arith *parmaddr;) struct node *FPList; struct type *tp; int VARp = D_VALPAR; + struct paramlist *p = 0; } : [ VAR { VARp = D_VARPAR; } ]? - IdentList(&FPList) ':' FormalType(&tp) - { EnterParamList(ppr, FPList, tp, VARp, parmaddr); } + IdentList(&FPList) ':' FormalType(&p, 0) + { EnterParamList(ppr, FPList, p->par_def->df_type, + VARp, parmaddr); + free_def(p->par_def); + free_paramlist(p); + } ; -FormalType(struct type **ptp;) +FormalType(struct paramlist **ppr; int VARp;) { - struct def *df; - int ARRAYflag = 0; + struct def *df1; + register struct def *df; + int ARRAYflag; register struct type *tp; + register struct paramlist *p = new_paramlist(); extern arith ArrayElSize(); } : [ ARRAY OF { ARRAYflag = 1; } - ]? - qualident(D_ISTYPE, &df, "type", (struct node **) 0) - { if (ARRAYflag) { - *ptp = tp = construct_type(T_ARRAY, NULLTYPE); + | { ARRAYflag = 0; } + ] + qualident(D_ISTYPE, &df1, "type", (struct node **) 0) + { df = df1; + if (ARRAYflag) { + tp = construct_type(T_ARRAY, NULLTYPE); tp->arr_elem = df->df_type; tp->arr_elsize = ArrayElSize(df->df_type); tp->tp_align = lcm(word_align, pointer_align); } - else *ptp = df->df_type; + else tp = df->df_type; + p->next = *ppr; + *ppr = p; + p->par_def = df = new_def(); + df->df_type = tp; + df->df_flags = VARp; } ; @@ -362,7 +373,7 @@ FieldList(struct scope *scope; arith *cnt; int *palign;) { warning("Old fashioned Modula-2 syntax!"); id = gen_anon_idf(); df = ill_df; - if (chk_designator(nd, 0, D_REFERRED) && + if (chk_designator(nd) && (nd->nd_class != Def || !(nd->nd_def->df_kind & (D_ERROR|D_ISTYPE)))) { @@ -513,8 +524,6 @@ ProcedureType(struct type **ptp;) FormalTypeList(struct paramlist **ppr; struct type **ptp;) { struct def *df; - struct type *tp; - struct paramlist *p; int VARp; } : '(' { *ppr = 0; } @@ -522,25 +531,13 @@ FormalTypeList(struct paramlist **ppr; struct type **ptp;) [ VAR { VARp = D_VARPAR; } | { VARp = D_VALPAR; } ] - FormalType(&tp) - { *ppr = p = new_paramlist(); - p->next = 0; - p->par_def = df = new_def(); - df->df_type = tp; - df->df_flags = VARp; - } + FormalType(ppr, VARp) [ ',' [ VAR {VARp = D_VARPAR; } | {VARp = D_VALPAR; } ] - FormalType(&tp) - { p = new_paramlist(); - p->next = *ppr; *ppr = p; - p->par_def = df = new_def(); - df->df_type = tp; - df->df_flags = VARp; - } + FormalType(ppr, VARp) ]* ]? ')' diff --git a/lang/m2/comp/defmodule.c b/lang/m2/comp/defmodule.c index 1696facd..99013dbd 100644 --- a/lang/m2/comp/defmodule.c +++ b/lang/m2/comp/defmodule.c @@ -38,7 +38,7 @@ GetFile(name) fatal("Could'nt find a DEFINITION MODULE for \"%s\"", name); } LineNumber = 1; - DO_DEBUG(1, debug("File %s : %ld characters", FileName, sys_filesize(FileName))); + DO_DEBUG(options['F'], debug("File %s : %ld characters", FileName, sys_filesize(FileName))); } struct def * diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index 3adfc160..53673a47 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -48,7 +48,7 @@ qualident(int types; { if (types) { df = ill_df; - if (chk_designator(nd, 0, D_REFERRED)) { + if (chk_designator(nd)) { if (nd->nd_class != Def) { node_error(nd, "%s expected", str); } @@ -98,14 +98,14 @@ ConstExpression(struct node **pnd;): * Changed rule in new Modula-2. * Check that the expression is a constant expression and evaluate! */ - { DO_DEBUG(3, - ( debug("Constant expression:"), - PrNode(*pnd))); + { DO_DEBUG(options['X'], print("CONSTANT EXPRESSION\n")); + DO_DEBUG(options['X'], PrNode(*pnd, 0)); if (chk_expr(*pnd) && ((*pnd)->nd_class != Set && (*pnd)->nd_class != Value)) { error("Constant expression expected"); } - DO_DEBUG(3, PrNode(*pnd)); + DO_DEBUG(options['X'], print("RESULTS IN\n")); + DO_DEBUG(options['X'], PrNode(*pnd, 0)); } ; diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index 5ca3138e..40573718 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -52,9 +52,6 @@ main(argc, argv) fprint(STDERR, "%s: Use a file argument\n", ProgName); return 1; } -#ifdef DEBUG - DO_DEBUG(1, debug("Debugging level: %d", options['D'])); -#endif DEBUG return !Compile(Nargv[1], Nargv[2]); } @@ -63,8 +60,6 @@ Compile(src, dst) { extern struct tokenname tkidf[]; - DO_DEBUG(1, debug("Filename : %s", src)); - DO_DEBUG(1, (!dst || debug("Targetfile: %s", dst))); if (! InsertFile(src, (char **) 0, &src)) { fprint(STDERR,"%s: cannot open %s\n", ProgName, src); return 0; @@ -98,6 +93,7 @@ Compile(src, dst) C_ms_src((arith) (LineNumber - 1), FileName); close_scope(SC_REVERSE); if (!err_occurred) { + C_exp(Defined->mod_vis->sc_scope->sc_name); WalkModule(Defined); if (fp_used) { C_ms_flt(); diff --git a/lang/m2/comp/node.c b/lang/m2/comp/node.c index f8ea57b1..6f16617c 100644 --- a/lang/m2/comp/node.c +++ b/lang/m2/comp/node.c @@ -35,7 +35,6 @@ MkNode(class, left, right, token) nd->nd_token = *token; nd->nd_class = class; nd->nd_type = error_type; - DO_DEBUG(4,(debug("Create node:"), PrNode(nd))); return nd; } @@ -74,23 +73,29 @@ NodeCrash(expp) extern char *symbol2str(); -STATIC -printnode(nd) - register struct node *nd; +indnt(lvl) { - fprint(STDERR, "("); - if (nd) { - printnode(nd->nd_left); - fprint(STDERR, " %s ", symbol2str(nd->nd_symb)); - printnode(nd->nd_right); + while (lvl--) { + print(" "); } - fprint(STDERR, ")"); } -PrNode(nd) - struct node *nd; +printnode(nd, lvl) + register struct node *nd; { - printnode(nd); - fprint(STDERR, "\n"); + indnt(lvl); + print("C: %d; T: %s\n", nd->nd_class, symbol2str(nd->nd_symb)); +} + +PrNode(nd, lvl) + register struct node *nd; +{ + if (! nd) { + indnt(lvl); print("\n"); + return; + } + PrNode(nd->nd_left, lvl + 1); + printnode(nd, lvl); + PrNode(nd->nd_right, lvl + 1); } #endif DEBUG diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 9ee7cec4..60ffc705 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -127,8 +127,6 @@ DefinitionModule df->df_type = standard_type(T_RECORD, 0, (arith) 0); df->df_type->rec_scope = df->mod_vis->sc_scope; DefinitionModule++; - DO_DEBUG(1, debug("Definition module \"%s\" %d", - id->id_text, DefinitionModule)); } ';' import(0)* @@ -209,7 +207,7 @@ ProgramModule df = define(id, CurrentScope, D_MODULE); open_scope(CLOSEDSCOPE); df->mod_vis = CurrVis; - CurrentScope->sc_name = id->id_text; + CurrentScope->sc_name = "_M2M"; } Defined = df; CurrentScope->sc_definedby = df; diff --git a/lang/m2/comp/scope.C b/lang/m2/comp/scope.C index 2cd6d34a..737cbd40 100644 --- a/lang/m2/comp/scope.C +++ b/lang/m2/comp/scope.C @@ -218,7 +218,7 @@ close_scope(flag) if (flag) { if (sc->sc_forw) rem_forwards(sc->sc_forw); - DO_DEBUG(2, PrScopeDef(sc->sc_def)); + DO_DEBUG(options['S'], PrScopeDef(sc->sc_def)); if (flag & SC_CHKPROC) chk_proc(sc->sc_def); if (flag & SC_CHKFORW) chk_forw(&(sc->sc_def)); if (flag & SC_REVERSE) Reverse(&(sc->sc_def)); diff --git a/lang/m2/comp/statement.g b/lang/m2/comp/statement.g index fadb5e05..7728d2de 100644 --- a/lang/m2/comp/statement.g +++ b/lang/m2/comp/statement.g @@ -5,6 +5,7 @@ static char *RcsId = "$Header$"; #endif +#include #include #include @@ -240,12 +241,12 @@ ReturnStatement(struct node **pnd;) { if (scopeclosed(CurrentScope)) { error("a module body has no result value"); } - else if (! df->df_type->next) { + else if (! ResultType(df->df_type)) { error("procedure \"%s\" has no result value", df->df_idf->id_text); } } | - { if (df->df_type->next) { + { if (ResultType(df->df_type)) { error("procedure \"%s\" must return a value", df->df_idf->id_text); } } diff --git a/lang/m2/comp/tmpvar.C b/lang/m2/comp/tmpvar.C index f6362705..10338d11 100644 --- a/lang/m2/comp/tmpvar.C +++ b/lang/m2/comp/tmpvar.C @@ -22,6 +22,7 @@ static char *RcsId = "$Header$"; #include "def.h" #include "type.h" #include "scope.h" +#include "main.h" struct tmpvar { struct tmpvar *next; @@ -45,7 +46,7 @@ NewInt() if (!TmpInts) { offset = - WA(align(int_size - ProcScope->sc_off, int_align)); ProcScope->sc_off = offset; - C_ms_reg(offset, int_size, reg_any, 0); + if (! options['n']) C_ms_reg(offset, int_size, reg_any, 0); } else { tmp = TmpInts; @@ -65,7 +66,7 @@ NewPtr() if (!TmpPtrs) { offset = - WA(align(pointer_size - ProcScope->sc_off, pointer_align)); ProcScope->sc_off = offset; - C_ms_reg(offset, pointer_size, reg_pointer, 0); + if (! options['n']) C_ms_reg(offset, pointer_size, reg_pointer, 0); } else { tmp = TmpPtrs; diff --git a/lang/m2/comp/type.H b/lang/m2/comp/type.H index 129b8def..c20e7a15 100644 --- a/lang/m2/comp/type.H +++ b/lang/m2/comp/type.H @@ -134,10 +134,19 @@ struct type #define NULLTYPE ((struct type *) 0) #define IsConformantArray(tpx) ((tpx)->tp_fund==T_ARRAY && (tpx)->next==0) -#define bounded(tpx) ((tpx)->tp_fund & T_INDEX) -#define complex(tpx) ((tpx)->tp_fund & (T_RECORD|T_ARRAY)) -#define WA(sz) (align(sz, (int) word_size)) -#define ResultType(tpx) (assert((tpx)->tp_fund == T_PROCEDURE), (tpx)->next) -#define ParamList(tpx) (assert((tpx)->tp_fund == T_PROCEDURE),\ +#define bounded(tpx) ((tpx)->tp_fund & T_INDEX) +#define complex(tpx) ((tpx)->tp_fund & (T_RECORD|T_ARRAY)) +#define WA(sz) (align(sz, (int) word_size)) +#define ResultType(tpx) (assert((tpx)->tp_fund == T_PROCEDURE),\ + (tpx)->next) +#define ParamList(tpx) (assert((tpx)->tp_fund == T_PROCEDURE),\ (tpx)->prc_params) +#define IndexType(tpx) (assert((tpx)->tp_fund == T_ARRAY),\ + (tpx)->next) +#define ElementType(tpx) (assert((tpx)->tp_fund == T_SET),\ + (tpx)->next) +#define PointedtoType(tpx) (assert((tpx)->tp_fund == T_POINTER),\ + (tpx)->next) +#define BaseType(tpx) ((tpx)->tp_fund == T_SUBRANGE ? (tpx)->next\ + : (tpx)) #define IsConstructed(tpx) ((tpx)->tp_fund & T_CONSTRUCTED) diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index ff0b4850..13584d02 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -225,22 +225,22 @@ chk_basesubrange(tp, base) if (base->sub_lb > tp->sub_lb || base->sub_ub < tp->sub_ub) { error("Base type has insufficient range"); } - base = base->next; + base = BaseType(base); } if (base->tp_fund & (T_ENUMERATION|T_CHAR)) { - if (tp->next != base) { + if (BaseType(tp) != base) { error("Specified base does not conform"); } } else if (base != card_type && base != int_type) { error("Illegal base for a subrange"); } - else if (base == int_type && tp->next == card_type && + else if (base == int_type && BaseType(tp) == card_type && (tp->sub_ub > max_int || tp->sub_ub < 0)) { error("Upperbound to large for type INTEGER"); } - else if (base != tp->next && base != int_type) { + else if (base != BaseType(tp) && base != int_type) { error("Specified base does not conform"); } @@ -257,15 +257,13 @@ subr_type(lb, ub) indicated by "lb" and "ub", but first perform some checks */ - register struct type *tp = lb->nd_type, *res; + register struct type *tp = BaseType(lb->nd_type), *res; if (!TstCompat(lb->nd_type, ub->nd_type)) { node_error(ub, "Types of subrange bounds not equal"); return error_type; } - if (tp->tp_fund == T_SUBRANGE) tp = tp->next; - if (tp == intorcard_type) { /* Lower bound >= 0; in this case, the base type is CARDINAL, according to the language definition, par. 6.3 @@ -397,7 +395,7 @@ ArraySizes(tp) { /* Assign sizes to an array type, and check index type */ - register struct type *index_type = tp->next; + register struct type *index_type = IndexType(tp); register struct type *elem_type = tp->arr_elem; arith lo, hi; diff --git a/lang/m2/comp/typequiv.c b/lang/m2/comp/typequiv.c index 76a66ce1..0e1d4ce7 100644 --- a/lang/m2/comp/typequiv.c +++ b/lang/m2/comp/typequiv.c @@ -67,7 +67,7 @@ TstProcEquiv(tp1, tp2) /* First check if the result types are equivalent */ - if (! TstTypeEquiv(tp1->next, tp2->next)) return 0; + if (! TstTypeEquiv(ResultType(tp1), ResultType(tp2))) return 0; p1 = ParamList(tp1); p2 = ParamList(tp2); @@ -94,8 +94,8 @@ TstCompat(tp1, tp2) if (TstTypeEquiv(tp1, tp2)) return 1; - if (tp1->tp_fund == T_SUBRANGE) tp1 = tp1->next; - if (tp2->tp_fund == T_SUBRANGE) tp2 = tp2->next; + tp1 = BaseType(tp1); + tp2 = BaseType(tp2); return tp1 == tp2 || @@ -138,8 +138,8 @@ TstAssCompat(tp1, tp2) if (TstCompat(tp1, tp2)) return 1; - if (tp1->tp_fund == T_SUBRANGE) tp1 = tp1->next; - if (tp2->tp_fund == T_SUBRANGE) tp2 = tp2->next; + tp1 = BaseType(tp1); + tp2 = BaseType(tp2); if ((tp1->tp_fund & T_INTORCARD) && (tp2->tp_fund & T_INTORCARD)) return 1; @@ -149,14 +149,14 @@ TstAssCompat(tp1, tp2) */ arith size; - if (!(tp = tp1->next)) return 0; + if (IsConformantArray(tp1)) return 0; + tp = IndexType(tp1); if (tp->tp_fund == T_SUBRANGE) { size = tp->sub_ub - tp->sub_lb + 1; } else size = tp->enm_ncst; - tp1 = tp1->arr_elem; - if (tp1->tp_fund == T_SUBRANGE) tp1 = tp1->next; + tp1 = BaseType(tp1->arr_elem); return tp1 == char_type && (tp2->tp_fund == T_STRING && size >= tp2->tp_size) diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index c314c157..7a5b9bc2 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -61,21 +61,12 @@ WalkModule(module) Also generate code for its body. */ register struct scope *sc; - struct scopelist *vis; + struct scopelist *savevis = CurrVis; - vis = CurrVis; CurrVis = module->mod_vis; sc = CurrentScope; - if (!proclevel && module == Defined) { - /* This module is a global module. Export the name of its - initialization routine - */ - if (state == PROGRAM) C_exp("main"); - else C_exp(sc->sc_name); - } - - /* Now, walk through it's local definitions + /* Walk through it's local definitions */ WalkDef(sc->sc_def); @@ -85,15 +76,15 @@ WalkModule(module) */ sc->sc_off = 0; text_label = 1; - ProcScope = CurrentScope; - C_pro_narg(state==PROGRAM && module==Defined ? "main" : sc->sc_name); + ProcScope = sc; + C_pro_narg(sc->sc_name); DoProfil(); if (module == Defined) { /* Body of implementation or program module. Call initialization routines of imported modules. Also prevent recursive calls of this one. */ - struct node *nd; + register struct node *nd; if (state == IMPLEMENTATION) { label l1 = ++data_label; @@ -108,14 +99,13 @@ WalkModule(module) C_ste_dlb(l1, (arith) 0); } - nd = Modules; - while (nd) { + for (nd = Modules; nd; nd = nd->next) { C_cal(nd->nd_IDF->id_text); - nd = nd->next; } } MkCalls(sc->sc_def); proclevel++; + DO_DEBUG(options['X'], PrNode(module->mod_body, 0)); WalkNode(module->mod_body, (label) 0); C_df_ilb((label) 1); C_ret((arith) 0); @@ -123,14 +113,14 @@ WalkModule(module) proclevel--; TmpClose(); - CurrVis = vis; + CurrVis = savevis; } WalkProcedure(procedure) register struct def *procedure; { /* Walk through the definition of a procedure and all its - local definitions + local definitions, checking and generating code. */ struct scopelist *savevis = CurrVis; register struct scope *sc; @@ -141,7 +131,7 @@ WalkProcedure(procedure) proclevel++; CurrVis = procedure->prc_vis; ProcScope = sc = CurrentScope; - + /* Generate code for all local modules and procedures */ WalkDef(sc->sc_def); @@ -182,6 +172,7 @@ WalkProcedure(procedure) C_bss_cst(tp->tp_size, (arith) 0, 0); } + DO_DEBUG(options['X'], PrNode(procedure->prc_body, 0)); WalkNode(procedure->prc_body, (label) 0); C_ret((arith) 0); if (tp) { @@ -195,7 +186,7 @@ WalkProcedure(procedure) else C_ret(WA(tp->tp_size)); } - RegisterMessages(sc->sc_def); + if (! options['n']) RegisterMessages(sc->sc_def); C_end(-sc->sc_off); TmpClose(); CurrVis = savevis; @@ -372,18 +363,20 @@ WalkStat(nd, lab) } C_bra(l1); C_df_ilb(l2); - WalkNode(right, lab); - C_loc(left->nd_INT); - CodePExpr(nd); - C_adi(int_size); + CheckAssign(nd->nd_type, int_type); CodeDStore(nd); - C_df_ilb(l1); + WalkNode(right, lab); CodePExpr(nd); + C_loc(left->nd_INT); + C_adi(int_size); + C_df_ilb(l1); + C_dup(int_size); if (tmp) C_lol(tmp); else C_loc(fnd->nd_INT); if (left->nd_INT > 0) { C_ble(l2); } else C_bge(l2); + C_asp(int_size); if (tmp) FreeInt(tmp); } break; @@ -498,8 +491,6 @@ WalkExpr(nd) /* Check an expression and generate code for it */ - DO_DEBUG(1, (DumpTree(nd), print("\n"))); - if (! chk_expr(nd)) return; CodePExpr(nd); @@ -512,9 +503,7 @@ WalkDesignator(nd, ds) /* Check designator and generate code for it */ - DO_DEBUG(1, (DumpTree(nd), print("\n"))); - - if (! chk_designator(nd, VARIABLE, D_DEFINED)) return; + if (! chk_variable(nd)) return; *ds = InitDesig; CodeDesig(nd, ds); @@ -529,7 +518,7 @@ DoForInit(nd, left) nd->nd_class = Name; nd->nd_symb = IDENT; - if (! chk_designator(nd, VARIABLE, D_DEFINED) || + if (! chk_variable(nd) || ! chk_expr(left->nd_left) || ! chk_expr(left->nd_right)) return 0; @@ -574,7 +563,6 @@ node_warning(nd, "old-fashioned! compatibility required in FOR statement"); } CodePExpr(left->nd_left); - CodeDStore(nd); return 1; } @@ -587,7 +575,7 @@ DoAssign(nd, left, right) struct desig dsl, dsr; if (!chk_expr(right)) return; - if (! chk_designator(left, VARIABLE, D_DEFINED)) return; + if (! chk_variable(left)) return; TryToString(right, left->nd_type); dsr = InitDesig; CodeExpr(right, &dsr, NO_LABEL, NO_LABEL); @@ -613,15 +601,19 @@ DoAssign(nd, left, right) RegisterMessages(df) register struct def *df; { - struct type *tp; + register struct type *tp; for (; df; df = df->df_nextinscope) { if (df->df_kind == D_VARIABLE && !(df->df_flags & D_NOREG)) { /* Examine type and size */ - tp = df->df_type; - if (tp->tp_fund == T_SUBRANGE) tp = tp->next; - if ((tp->tp_fund & T_NUMERIC) && + tp = BaseType(df->df_type); + if ((df->df_flags & D_VARPAR) || + tp->tp_fund == T_POINTER) { + C_ms_reg(df->var_off, pointer_size, + reg_pointer, 0); + } + else if ((tp->tp_fund & T_NUMERIC) && tp->tp_size <= dword_size) { C_ms_reg(df->var_off, tp->tp_size, @@ -629,46 +621,6 @@ RegisterMessages(df) reg_float : reg_any, 0); } - else if ((df->df_flags & D_VARPAR) || - tp->tp_fund == T_POINTER) { - C_ms_reg(df->var_off, pointer_size, - reg_pointer, 0); - } } } } - -#ifdef DEBUG -DumpTree(nd) - struct node *nd; -{ - char *s; - extern char *symbol2str(); - - if (!nd) { - print("()"); - return; - } - - print("("); - DumpTree(nd->nd_left); - switch(nd->nd_class) { - case Def: s = "Def"; break; - case Oper: s = "Oper"; break; - case Arrsel: s = "Arrsel"; break; - case Arrow: s = "Arrow"; break; - case Uoper: s = "Uoper"; break; - case Name: s = "Name"; break; - case Set: s = "Set"; break; - case Value: s = "Value"; break; - case Call: s = "Call"; break; - case Xset: s = "Xset"; break; - case Stat: s = "Stat"; break; - case Link: s = "Link"; break; - default: s = "ERROR"; break; - } - print("%s %s", s, symbol2str(nd->nd_symb)); - DumpTree(nd->nd_right); - print(")"); -} -#endif From 250729d4415f8497e485b55debab309c00cd7578 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 8 Jul 1986 14:59:02 +0000 Subject: [PATCH 0212/1625] newer version --- lang/m2/comp/Makefile | 21 ++-- lang/m2/comp/casestat.C | 1 + lang/m2/comp/code.c | 1 + lang/m2/comp/cstoper.c | 107 +++++++++++------ lang/m2/comp/declar.g | 236 ++++++++++++++++---------------------- lang/m2/comp/def.H | 1 + lang/m2/comp/def.c | 10 -- lang/m2/comp/desig.c | 1 + lang/m2/comp/enter.c | 1 + lang/m2/comp/expression.g | 21 ++-- lang/m2/comp/main.c | 12 +- lang/m2/comp/program.g | 62 +++++----- lang/m2/comp/statement.g | 5 +- lang/m2/comp/tmpvar.C | 9 +- lang/m2/comp/type.c | 1 + lang/m2/comp/walk.c | 35 +++--- 16 files changed, 259 insertions(+), 265 deletions(-) diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index f4caf84b..dda87c51 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -1,16 +1,16 @@ # make modula-2 "compiler" # $Header$ +EMDIR = /usr/em +MHDIR = $(EMDIR)/modules/h +PKGDIR = $(EMDIR)/modules/pkg +LIBDIR = $(EMDIR)/modules/lib +LLGEN = $(EMDIR)/util/LLgen/src/LLgen -HDIR = ../../em/h -PKGDIR = ../../em/pkg -LIBDIR = ../../em/lib - -INCLUDES = -I$(HDIR) -I/usr/em/h -I$(PKGDIR) -I/user1/erikb/em/h +INCLUDES = -I$(MHDIR) -I$(EMDIR)/h -I$(PKGDIR) LSRC = tokenfile.g program.g declar.g expression.g statement.g CC = cc -GEN = /usr/em/util/LLgen/src/LLgen -GENOPTIONS = -d +LLGENOPTIONS = -d PROFILE = CFLAGS = $(PROFILE) $(INCLUDES) -DSTATIC= LINTFLAGS = -DSTATIC= -DNORCSID @@ -30,7 +30,8 @@ GENCFILES= tokenfile.c \ GENGFILES= tokenfile.g GENHFILES= errout.h\ idfsize.h numsize.h strsize.h target_sizes.h debug.h\ - inputtype.h maxset.h ndir.h density.h + inputtype.h maxset.h ndir.h density.h\ + def.h type.h Lpars.h node.h # GENFILES = $(GENGFILES) $(GENCFILES) $(GENHFILES) all: @@ -39,7 +40,7 @@ all: make main LLfiles: $(LSRC) - $(GEN) $(GENOPTIONS) $(LSRC) + $(LLGEN) $(LLGENOPTIONS) $(LSRC) @touch LLfiles hfiles: Parameters make.hfiles @@ -47,7 +48,7 @@ hfiles: Parameters make.hfiles touch hfiles main: $(OBJ) Makefile - $(CC) $(LFLAGS) $(OBJ) /user1/erikb/em/lib/libem_mes.a /user1/erikb/em/lib/libeme.a $(LIBDIR)/libcomp.a $(LIBDIR)/malloc.o /user1/erikb/em/lib/libprint.a /user1/erikb/em/lib/libstr.a /user1/erikb/em/lib/libsystem.a -o main + $(CC) $(LFLAGS) $(OBJ) $(LIBDIR)/libem_mes.a $(LIBDIR)/libeme.a $(LIBDIR)/input.a $(LIBDIR)/assert.a $(LIBDIR)/alloc.a $(LIBDIR)/malloc.o $(LIBDIR)/libprint.a $(LIBDIR)/libstr.a $(LIBDIR)/libsystem.a -o main size main clean: diff --git a/lang/m2/comp/casestat.C b/lang/m2/comp/casestat.C index 7c429444..eeb9162a 100644 --- a/lang/m2/comp/casestat.C +++ b/lang/m2/comp/casestat.C @@ -8,6 +8,7 @@ static char *RcsId = "$Header$"; #include #include +#include #include #include diff --git a/lang/m2/comp/code.c b/lang/m2/comp/code.c index 60b6c6a4..2e625273 100644 --- a/lang/m2/comp/code.c +++ b/lang/m2/comp/code.c @@ -11,6 +11,7 @@ static char *RcsId = "$Header$"; #include #include +#include #include #include "type.h" diff --git a/lang/m2/comp/cstoper.c b/lang/m2/comp/cstoper.c index 30ac8c7a..65c9924e 100644 --- a/lang/m2/comp/cstoper.c +++ b/lang/m2/comp/cstoper.c @@ -32,24 +32,28 @@ cstunary(expp) /* The unary operation in "expp" is performed on the constant expression below it, and the result restored in expp. */ - arith o1 = expp->nd_right->nd_INT; + register arith o1 = expp->nd_right->nd_INT; switch(expp->nd_symb) { case '+': break; + case '-': o1 = -o1; if (expp->nd_type->tp_fund == T_INTORCARD) { expp->nd_type = int_type; } break; + case NOT: case '~': o1 = !o1; break; + default: crash("(cstunary)"); } + expp->nd_class = Value; expp->nd_token = expp->nd_right->nd_token; expp->nd_INT = o1; @@ -65,8 +69,8 @@ cstbin(expp) expressions below it, and the result restored in expp. */ - arith o1 = expp->nd_left->nd_INT; - arith o2 = expp->nd_right->nd_INT; + register arith o1 = expp->nd_left->nd_INT; + register arith o2 = expp->nd_right->nd_INT; int uns = expp->nd_type != int_type; assert(expp->nd_class == Oper); @@ -158,15 +162,12 @@ cstbin(expp) break; case '<': - if (uns) { - o1 = (o1 & mach_long_sign ? - (o2 & mach_long_sign ? o1 < o2 : 0) : - (o2 & mach_long_sign ? 1 : o1 < o2) - ); + { arith tmp = o1; + + o1 = o2; + o2 = tmp; } - else - o1 = (o1 < o2); - break; + /* Fall through */ case '>': if (uns) { @@ -178,16 +179,15 @@ cstbin(expp) else o1 = (o1 > o2); break; + case LESSEQUAL: - if (uns) { - o1 = (o1 & mach_long_sign ? - (o2 & mach_long_sign ? o1 <= o2 : 0) : - (o2 & mach_long_sign ? 1 : o1 <= o2) - ); + { arith tmp = o1; + + o1 = o2; + o2 = tmp; } - else - o1 = (o1 <= o2); - break; + /* Fall through */ + case GREATEREQUAL: if (uns) { o1 = (o1 & mach_long_sign ? @@ -198,22 +198,28 @@ cstbin(expp) else o1 = (o1 >= o2); break; + case '=': o1 = (o1 == o2); break; + case '#': o1 = (o1 != o2); break; + case AND: case '&': o1 = (o1 && o2); break; + case OR: o1 = (o1 || o2); break; + default: crash("(cstbin)"); } + expp->nd_class = Value; expp->nd_token = expp->nd_right->nd_token; if (expp->nd_type == bool_type) expp->nd_symb = INTEGER; @@ -227,7 +233,7 @@ cstbin(expp) cstset(expp) register struct node *expp; { - register arith *set1 = 0, *set2; + register arith *set1, *set2; arith *resultset = 0; register int setsize, j; @@ -253,6 +259,8 @@ cstset(expp) expp->nd_left->nd_set = 0; switch(expp->nd_symb) { case '+': + /* Set union + */ if (!set1) { resultset = set2; expp->nd_right->nd_set = 0; @@ -262,11 +270,15 @@ cstset(expp) *set1++ |= *set2++; } break; + case '-': + /* Set difference + */ if (!set1 || !set2) { /* The set from which something is substracted is already empty, or the set that is - substracted is empty + substracted is empty. In either case, the + result set is set1. */ break; } @@ -274,34 +286,50 @@ cstset(expp) *set1++ &= ~*set2++; } break; + case '*': - if (!set1) break; + /* Set intersection + */ + if (!set1) { + /* set1 is empty, and so is the result set + */ + break; + } if (!set2) { + /* set 2 is empty, so the result set must be + empty too. + */ resultset = set2; expp->nd_right->nd_set = 0; break; } - for (j = 0; j < setsize; j++) { *set1++ &= *set2++; } break; + case '/': + /* Symmetric set difference + */ if (!set1) { resultset = set2; expp->nd_right->nd_set = 0; break; } - if (set2) for (j = 0; j < setsize; j++) { - *set1++ ^= *set2++; + if (set2) { + for (j = 0; j < setsize; j++) { + *set1++ ^= *set2++; + } } break; + case GREATEREQUAL: case LESSEQUAL: case '=': case '#': - /* Clumsy, but who cares? Nobody writes these things! */ - expp->nd_left->nd_set = set1; + /* Constant set comparisons + */ + expp->nd_left->nd_set = set1; /* may be disposed of */ for (j = 0; j < setsize; j++) { switch(expp->nd_symb) { case GREATEREQUAL: @@ -371,11 +399,13 @@ cstcall(expp, call) register struct node *expr = 0; assert(expp->nd_class == Call); + if (expp->nd_right) { expr = expp->nd_right->nd_left; expp->nd_right->nd_left = 0; FreeNode(expp->nd_right); } + expp->nd_class = Value; expp->nd_symb = INTEGER; switch(call) { @@ -384,6 +414,7 @@ cstcall(expp, call) else expp->nd_INT = expr->nd_INT; CutSize(expp); break; + case S_CAP: if (expr->nd_INT >= 'a' && expr->nd_INT <= 'z') { expp->nd_INT = expr->nd_INT + ('A' - 'a'); @@ -391,10 +422,12 @@ cstcall(expp, call) else expp->nd_INT = expr->nd_INT; CutSize(expp); break; + case S_CHR: expp->nd_INT = expr->nd_INT; CutSize(expp); break; + case S_MAX: if (expp->nd_type == int_type) { expp->nd_INT = max_int; @@ -410,6 +443,7 @@ cstcall(expp, call) } else expp->nd_INT = expp->nd_type->enm_ncst - 1; break; + case S_MIN: if (expp->nd_type == int_type) { expp->nd_INT = (-max_int) - 1; @@ -422,16 +456,20 @@ cstcall(expp, call) } else expp->nd_INT = 0; break; + case S_ODD: expp->nd_INT = (expr->nd_INT & 1); break; + case S_ORD: expp->nd_INT = expr->nd_INT; CutSize(expp); break; + case S_SIZE: expp->nd_INT = WA(expr->nd_type->tp_size) / word_size; break; + case S_VAL: expp->nd_INT = expr->nd_INT; if ( /* Check overflow of subranges or enumerations */ @@ -451,6 +489,7 @@ cstcall(expp, call) ) node_warning(expp,"overflow in constant expression"); else CutSize(expp); break; + default: crash("(cstcall)"); } @@ -465,8 +504,8 @@ CutSize(expr) /* The constant value of the expression expr is made to conform to the size of the type of the expression. */ - arith o1 = expr->nd_INT; - struct type *tp = BaseType(expr->nd_type); + register arith o1 = expr->nd_INT; + register struct type *tp = BaseType(expr->nd_type); int uns; int size = tp->tp_size; @@ -476,8 +515,8 @@ CutSize(expr) if (o1 & ~full_mask[size]) { node_warning(expr, "overflow in constant expression"); + o1 &= full_mask[size]; } - o1 &= full_mask[size]; } else { int nbits = (int) (mach_long_size - size) * 8; @@ -485,17 +524,17 @@ CutSize(expr) if (remainder != 0 && remainder != ~full_mask[size]) { node_warning(expr, "overflow in constant expression"); + o1 <<= nbits; + o1 >>= nbits; } - o1 <<= nbits; - o1 >>= nbits; } expr->nd_INT = o1; } InitCst() { - int i = 0; - arith bt = (arith)0; + register int i = 0; + register arith bt = (arith)0; while (!(bt < 0)) { bt = (bt << 8) + 0377, i++; diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 3b1bc590..53fb4665 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -33,21 +33,20 @@ ProcedureDeclaration register struct def *df; struct def *df1; } : - { proclevel++; } - ProcedureHeading(&df1, D_PROCEDURE) - { - CurrentScope->sc_definedby = df = df1; - df->prc_vis = CurrVis; + { ++proclevel; return_occurred = 0; } + ProcedureHeading(&df1, D_PROCEDURE) + { CurrentScope->sc_definedby = df = df1; + df->prc_vis = CurrVis; + } ';' block(&(df->prc_body)) IDENT - { - match_id(dot.TOK_IDF, df->df_idf); + { match_id(dot.TOK_IDF, df->df_idf); close_scope(SC_CHKFORW|SC_REVERSE); if (! return_occurred && ResultType(df->df_type)) { -error("function procedure does not return a value", df->df_idf->id_text); +error("function procedure %s does not return a value", df->df_idf->id_text); } - proclevel--; + --proclevel; } ; @@ -56,22 +55,17 @@ ProcedureHeading(struct def **pdf; int type;) struct paramlist *params = 0; struct type *tp = 0; register struct def *df; - struct def *DeclProc(); arith NBytesParams; } : PROCEDURE IDENT - { - df = DeclProc(type); - if (proclevel > 1) { - /* Room for static link - */ + { df = DeclProc(type); + if (proclevel > 1) { /* need room for static link */ NBytesParams = pointer_size; } else NBytesParams = 0; } FormalParameters(¶ms, &tp, &NBytesParams)? - { - tp = construct_type(T_PROCEDURE, tp); + { tp = construct_type(T_PROCEDURE, tp); tp->prc_params = params; tp->prc_nbpar = NBytesParams; if (df->df_type) { @@ -85,9 +79,6 @@ error("inconsistent procedure declaration for \"%s\"", df->df_idf->id_text); } df->df_type = tp; *pdf = df; - - if (type == D_PROCHEAD) close_scope(0); - } ; @@ -115,7 +106,7 @@ declaration: ; FormalParameters(struct paramlist **pr; - struct type **tp; + struct type **ptp; arith *parmaddr;) { struct def *df; @@ -128,9 +119,7 @@ FormalParameters(struct paramlist **pr; ]* ]? ')' - [ ':' qualident(D_ISTYPE, &df, "type", (struct node **) 0) - { *tp = df->df_type; - } + [ ':' qualtype(ptp) ]? ; @@ -138,13 +127,10 @@ FPSection(struct paramlist **ppr; arith *parmaddr;) { struct node *FPList; struct type *tp; - int VARp = D_VALPAR; + int VARp; struct paramlist *p = 0; } : - [ - VAR { VARp = D_VARPAR; } - ]? - IdentList(&FPList) ':' FormalType(&p, 0) + var(&VARp) IdentList(&FPList) ':' FormalType(&p, 0) { EnterParamList(ppr, FPList, p->par_def->df_type, VARp, parmaddr); free_def(p->par_def); @@ -154,25 +140,24 @@ FPSection(struct paramlist **ppr; arith *parmaddr;) FormalType(struct paramlist **ppr; int VARp;) { - struct def *df1; register struct def *df; int ARRAYflag; register struct type *tp; + struct type *tp1; register struct paramlist *p = new_paramlist(); extern arith ArrayElSize(); } : [ ARRAY OF { ARRAYflag = 1; } | { ARRAYflag = 0; } ] - qualident(D_ISTYPE, &df1, "type", (struct node **) 0) - { df = df1; - if (ARRAYflag) { + qualtype(&tp1) + { if (ARRAYflag) { tp = construct_type(T_ARRAY, NULLTYPE); - tp->arr_elem = df->df_type; - tp->arr_elsize = ArrayElSize(df->df_type); + tp->arr_elem = tp1; + tp->arr_elsize = ArrayElSize(tp1); tp->tp_align = lcm(word_align, pointer_align); } - else tp = df->df_type; + else tp = tp1; p->next = *ppr; *ppr = p; p->par_def = df = new_def(); @@ -186,23 +171,19 @@ TypeDeclaration register struct def *df; struct type *tp; }: - IDENT { df = lookup(dot.TOK_IDF, CurrentScope); - if (!df) df = define(dot.TOK_IDF,CurrentScope,D_TYPE); - } + IDENT { df = define(dot.TOK_IDF,CurrentScope,D_TYPE); } '=' type(&tp) - { - if (df->df_kind == D_HIDDEN) { + { if (df->df_type && df->df_type->tp_fund == T_HIDDEN) { if (tp->tp_fund != T_POINTER) { error("opaque type \"%s\" is not a pointer type", df->df_idf->id_text); } - df->df_kind = D_TYPE; + /* Careful now ... we might have declarations + referring to the hidden type. + */ *(df->df_type) = *tp; free_type(tp); } - else { - df->df_type = tp; - df->df_kind = D_TYPE; - } + else df->df_type = tp; } ; @@ -222,20 +203,17 @@ type(struct type **ptp;): SimpleType(struct type **ptp;) { - struct def *df; + struct type *tp; } : - qualident(D_ISTYPE, &df, "type", (struct node **) 0) + qualtype(ptp) [ /* nothing */ - { *ptp = df->df_type; } | - SubrangeType(ptp) + SubrangeType(&tp) /* The subrange type is given a base type by the qualident (this is new modula-2). */ - { - chk_basesubrange(*ptp, df->df_type); - } + { chk_basesubrange(tp, *ptp); } ] | enumeration(ptp) @@ -249,8 +227,7 @@ enumeration(struct type **ptp;) register struct type *tp; } : '(' IdentList(&EnumList) ')' - { - *ptp = tp = standard_type(T_ENUMERATION, 1, (arith) 1); + { *ptp = tp = standard_type(T_ENUMERATION, 1, (arith) 1); EnterEnumList(EnumList, tp); if (tp->enm_ncst > 256) { /* ??? is this reasonable ??? */ error("Too many enumeration literals"); @@ -262,9 +239,7 @@ IdentList(struct node **p;) { register struct node *q; } : - IDENT { q = MkLeaf(Value, &dot); - *p = q; - } + IDENT { *p = q = MkLeaf(Value, &dot); } [ ',' IDENT { q->next = MkLeaf(Value, &dot); @@ -285,8 +260,7 @@ SubrangeType(struct type **ptp;) '[' ConstExpression(&nd1) UPTO ConstExpression(&nd2) ']' - { *ptp = subr_type(nd1, nd2); - } + { *ptp = subr_type(nd1, nd2); } ; ArrayType(struct type **ptp;) @@ -295,9 +269,7 @@ ArrayType(struct type **ptp;) register struct type *tp2; } : ARRAY SimpleType(&tp) - { - *ptp = tp2 = construct_type(T_ARRAY, tp); - } + { *ptp = tp2 = construct_type(T_ARRAY, tp); } [ ',' SimpleType(&tp) { tp2->arr_elem = construct_type(T_ARRAY, tp); @@ -311,20 +283,19 @@ ArrayType(struct type **ptp;) RecordType(struct type **ptp;) { - struct scope *scope; + register struct scope *scope; arith count; int xalign = struct_align; } : RECORD - { open_scope(OPENSCOPE); - scope = CurrentScope; - close_scope(0); - count = 0; - } + { open_scope(OPENSCOPE); + scope = CurrentScope; + close_scope(0); + count = 0; + } FieldListSequence(scope, &count, &xalign) - { - *ptp = standard_type(T_RECORD, xalign, WA(count)); + { *ptp = standard_type(T_RECORD, xalign, WA(count)); (*ptp)->rec_scope = scope; } END @@ -340,8 +311,8 @@ FieldListSequence(struct scope *scope; arith *cnt; int *palign;): FieldList(struct scope *scope; arith *cnt; int *palign;) { struct node *FldList; - struct idf *id; - struct def *df; + register struct idf *id = gen_anon_idf(); + register struct def *df; struct type *tp; struct node *nd; arith tcnt, max; @@ -355,41 +326,37 @@ FieldList(struct scope *scope; arith *cnt; int *palign;) CASE /* Also accept old fashioned Modula-2 syntax, but give a warning */ - [ qualident(0, &df, (char *) 0, &nd) - [ /* This is good, in both kinds of Modula-2, if + [ qualident(0, (struct def **) 0, (char *) 0, &nd) + [ ':' qualtype(&tp) + /* This is correct, in both kinds of Modula-2, if the first qualident is a single identifier. */ - { if (nd->nd_class != Name) { - error("illegal variant tag"); - id = gen_anon_idf(); - } - else id = nd->nd_IDF; - } - ':' qualident(D_ISTYPE, &df, "type", (struct node **) 0) + { if (nd->nd_class != Name) { + error("illegal variant tag"); + } + else id = nd->nd_IDF; + } | /* Old fashioned! the first qualident now represents the type */ { warning("Old fashioned Modula-2 syntax!"); - id = gen_anon_idf(); - df = ill_df; if (chk_designator(nd) && (nd->nd_class != Def || - !(nd->nd_def->df_kind & - (D_ERROR|D_ISTYPE)))) { + !(nd->nd_def->df_kind&(D_ERROR|D_ISTYPE)) || + !nd->nd_def->df_type)) { node_error(nd, "type expected"); + tp = error_type; } - else df = nd->nd_def; + else tp = nd->nd_def->df_type; FreeNode(nd); } ] | - /* Aha, third edition? */ - ':' qualident(D_ISTYPE, &df, "type", (struct node **) 0) - { id = gen_anon_idf(); } + /* Aha, third edition. Well done! */ + ':' qualtype(&tp) ] - { tp = df->df_type; - if (!(tp->tp_fund & T_DISCRETE)) { + { if (!(tp->tp_fund & T_DISCRETE)) { error("Illegal type in variant"); } df = define(id, scope, D_FIELD); @@ -464,12 +431,9 @@ node_error(nd1,"type incompatibility in case label"); SetType(struct type **ptp;) { - struct type *tp; } : - SET OF SimpleType(&tp) - { - *ptp = set_type(tp); - } + SET OF SimpleType(ptp) + { *ptp = set_type(*ptp); } ; /* In a pointer type definition, the type pointed at does not @@ -478,46 +442,48 @@ SetType(struct type **ptp;) */ PointerType(struct type **ptp;) { - struct type *tp; - struct def *df; - struct node *nd; + register struct def *df; + register struct node *nd; } : POINTER TO - [ %if ( (df = lookup(dot.TOK_IDF, CurrentScope))) + { *ptp = construct_type(T_POINTER, NULLTYPE); } + [ %if ( lookup(dot.TOK_IDF, CurrentScope)) /* Either a Module or a Type, but in both cases defined in this scope, so this is the correct identification */ - qualident(D_ISTYPE, &df, "type", (struct node **) 0) - { - if (!df->df_type) { - error("type \"%s\" not declared", - df->df_idf->id_text); - tp = error_type; - } - else tp = df->df_type; - } + qualtype(&((*ptp)->next)) | %if ( nd = new_node(), nd->nd_token = dot, df = lookfor(nd, CurrVis, 0), free_node(nd), df->df_kind == D_MODULE) - type(&tp) + type(&((*ptp)->next)) | - IDENT - { tp = NULLTYPE; } + IDENT { Forward(&dot, &((*ptp)->next)); } ] - { - *ptp = construct_type(T_POINTER, tp); - if (!tp) Forward(&dot, &((*ptp)->next)); - } ; +qualtype(struct type **ptp;) +{ + struct def *df; +} : + qualident(D_ISTYPE, &df, "type", (struct node **) 0) + { if (!df->df_type) { + error("type \"%s\" not declared", df->df_idf->id_text); + *ptp = error_type; + } + else *ptp = df->df_type; + } +; + + ProcedureType(struct type **ptp;) { struct paramlist *pr = 0; - struct type *tp = 0; + register struct type *tp; } : - PROCEDURE FormalTypeList(&pr, &tp)? - { *ptp = construct_type(T_PROCEDURE, tp); - (*ptp)->prc_params = pr; + { *ptp = 0; } + PROCEDURE FormalTypeList(&pr, ptp)? + { *ptp = tp = construct_type(T_PROCEDURE, *ptp); + tp->prc_params = pr; } ; @@ -528,34 +494,30 @@ FormalTypeList(struct paramlist **ppr; struct type **ptp;) } : '(' { *ppr = 0; } [ - [ VAR { VARp = D_VARPAR; } - | { VARp = D_VALPAR; } - ] - FormalType(ppr, VARp) + var(&VARp) FormalType(ppr, VARp) [ - ',' - [ VAR {VARp = D_VARPAR; } - | {VARp = D_VALPAR; } - ] - FormalType(ppr, VARp) + ',' var(&VARp) FormalType(ppr, VARp) ]* ]? ')' - [ ':' qualident(D_TYPE, &df, "type", (struct node **) 0) - { *ptp = df->df_type; } + [ ':' qualtype(ptp) ]? ; +var(int *VARp;): + VAR { *VARp = D_VARPAR; } +| + /* empty */ { *VARp = D_VALPAR; } +; + ConstantDeclaration { - struct def *df; struct idf *id; struct node *nd; }: - IDENT { id = dot.TOK_IDF; } - '=' ConstExpression(&nd){ df = define(id, CurrentScope, D_CONST); - df->con_const = nd; - } + IDENT { id = dot.TOK_IDF; } + '=' ConstExpression(&nd) + { define(id,CurrentScope,D_CONST)->con_const = nd; } ; VariableDeclaration diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H index e87d3ac0..774fd798 100644 --- a/lang/m2/comp/def.H +++ b/lang/m2/comp/def.H @@ -119,6 +119,7 @@ extern struct def *define(), *DefineLocalModule(), *MkDef(), + *DeclProc(), *ill_df; extern struct def diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index 91f4402a..037e9bfe 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -232,16 +232,6 @@ DeclProc(type) return df; } -InitProc(nd, df) - struct node *nd; - struct def *df; -{ - /* Create an initialization procedure for a module. - */ - df->mod_body = nd; - /* Keep it this way, or really create a procedure out of it??? */ -} - AddModule(id) struct idf *id; { diff --git a/lang/m2/comp/desig.c b/lang/m2/comp/desig.c index 68bebc39..f33a589d 100644 --- a/lang/m2/comp/desig.c +++ b/lang/m2/comp/desig.c @@ -15,6 +15,7 @@ static char *RcsId = "$Header$"; #include #include +#include #include #include "type.h" diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index 04d4dda7..0d3bf367 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -9,6 +9,7 @@ static char *RcsId = "$Header$"; #include #include #include +#include #include #include "idf.h" diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index 53673a47..ca3961f4 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -78,17 +78,16 @@ selector(struct node **pnd;): ExpList(struct node **pnd;) { - struct node **nd; + register struct node *nd; } : - expression(pnd) { *pnd = MkNode(Link, *pnd, NULLNODE, &dot); + expression(pnd) { *pnd = nd = MkNode(Link,*pnd,NULLNODE,&dot); (*pnd)->nd_symb = ','; - nd = &((*pnd)->nd_right); } [ - ',' { *nd = MkLeaf(Link, &dot); + ',' { nd->nd_right = MkLeaf(Link, &dot); + nd = nd->nd_right; } - expression(&(*nd)->nd_left) - { nd = &((*nd)->nd_right); } + expression(&(nd->nd_left)) ]* ; @@ -169,7 +168,7 @@ MulOperator: ; */ -factor(struct node **p;) +factor(register struct node **p;) { struct def *df; struct node *nd; @@ -190,8 +189,7 @@ factor(struct node **p;) | %default number(p) | - STRING { - *p = MkLeaf(Value, &dot); + STRING { *p = MkLeaf(Value, &dot); (*p)->nd_type = toktype; } | @@ -205,8 +203,7 @@ bare_set(struct node **pnd;) { register struct node *nd; } : - '{' { - dot.tk_symb = SET; + '{' { dot.tk_symb = SET; *pnd = nd = MkLeaf(Xset, &dot); nd->nd_type = bitset_type; } @@ -255,7 +252,7 @@ designator_tail(struct node **pnd;): ]* ; -visible_designator_tail(struct node **pnd;): +visible_designator_tail(register struct node **pnd;): '[' { *pnd = MkNode(Arrsel, *pnd, NULLNODE, &dot); } expression(&((*pnd)->nd_right)) [ diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index 40573718..18d1ad6d 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -26,7 +26,7 @@ static char *RcsId = "$Header$"; int state; /* either IMPLEMENTATION or PROGRAM */ char options[128]; int DefinitionModule; -int SYSTEMModule = 0; +int SYSTEMModule; char *ProgName; char *DEFPATH[NDIRS+1]; struct def *Defined; @@ -34,7 +34,7 @@ extern int err_occurred; extern int fp_used; /* set if floating point used */ main(argc, argv) - char *argv[]; + register char **argv; { register int Nargc = 1; register char **Nargv = &argv[0]; @@ -84,9 +84,7 @@ Compile(src, dst) open_scope(CLOSEDSCOPE); GlobalScope = CurrentScope; C_init(word_size, pointer_size); - if (! C_open(dst)) { - fatal("Could not open output file"); - } + if (! C_open(dst)) fatal("Could not open output file"); C_magic(); C_ms_emx(word_size, pointer_size); CompUnit(); @@ -95,9 +93,7 @@ Compile(src, dst) if (!err_occurred) { C_exp(Defined->mod_vis->sc_scope->sc_name); WalkModule(Defined); - if (fp_used) { - C_ms_flt(); - } + if (fp_used) C_ms_flt(); } C_close(); #ifdef DEBUG diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 60ffc705..36c2bf35 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -41,9 +41,8 @@ static char *RcsId = "$Header$"; ModuleDeclaration { - struct idf *id; - struct def *df; - struct node *nd; + struct idf *id; /* save module identifier */ + register struct def *df; struct node *exportlist = 0; int qualified; } : @@ -54,9 +53,8 @@ ModuleDeclaration ';' import(1)* export(&qualified, &exportlist)? - block(&nd) - IDENT { InitProc(nd, df); - if (exportlist) { + block(&(df->mod_body)) + IDENT { if (exportlist) { EnterExportList(exportlist, qualified); } close_scope(SC_CHKFORW|SC_CHKPROC|SC_REVERSE); @@ -93,11 +91,13 @@ export(int *QUALflag; struct node **ExportList;) import(int local;) { struct node *ImportList; - struct node *id = 0; + register struct node *id; } : [ FROM IDENT { id = MkLeaf(Value, &dot); } - ]? + | + { id = 0; } + ] IMPORT IdentList(&ImportList) ';' /* When parsing a global module, this is the place where we must @@ -113,8 +113,8 @@ import(int local;) DefinitionModule { register struct def *df; - struct idf *id; - struct node *exportlist = 0; + struct idf *id; /* save module identifier */ + struct node *exportlist; int dummy; } : DEFINITION @@ -130,19 +130,20 @@ DefinitionModule } ';' import(0)* - export(&dummy, &exportlist)? - /* New Modula-2 does not have export lists in definition modules. - For the time being, we ignore export lists here, and a - warning is issued. - */ - { if (exportlist) { + [ + export(&dummy, &exportlist) + /* New Modula-2 does not have export lists in definition + modules. Issue a warning. + */ + { node_warning(exportlist, "export list in definition module ignored"); FreeNode(exportlist); - } } + | + /* empty */ + ] definition* END IDENT - { - df = CurrentScope->sc_def; + { df = CurrentScope->sc_def; while (df) { /* Make all definitions "QUALIFIED EXPORT" */ df->df_flags |= D_QEXPORTED; @@ -157,7 +158,8 @@ node_warning(exportlist, "export list in definition module ignored"); definition { - struct def *df; + register struct def *df; + struct def *dummy; } : CONST [ ConstantDeclaration Semicolon ]* | @@ -179,13 +181,17 @@ definition | VAR [ VariableDeclaration Semicolon ]* | - ProcedureHeading(&df, D_PROCHEAD) Semicolon + ProcedureHeading(&dummy, D_PROCHEAD) + { close_scope(0); } + Semicolon ; +/* The next nonterminal is used to relax the grammar a little. +*/ Semicolon: ';' | - { warning("; expected"); } + /* empty */ { warning("; expected"); } ; ProgramModule @@ -193,30 +199,26 @@ ProgramModule struct idf *id; struct def *GetDefinitionModule(); register struct def *df; - struct node *nd; } : MODULE IDENT { id = dot.TOK_IDF; if (state == IMPLEMENTATION) { df = GetDefinitionModule(id); CurrVis = df->mod_vis; - CurrentScope = CurrVis->sc_scope; RemoveImports(&(CurrentScope->sc_def)); } else { - df = define(id, CurrentScope, D_MODULE); + Defined = df = define(id, CurrentScope, D_MODULE); open_scope(CLOSEDSCOPE); df->mod_vis = CurrVis; CurrentScope->sc_name = "_M2M"; } - Defined = df; CurrentScope->sc_definedby = df; } priority(&(df->mod_priority))? ';' import(0)* - block(&nd) IDENT - { InitProc(nd, df); - close_scope(SC_CHKFORW|SC_CHKPROC|SC_REVERSE); + block(&(df->mod_body)) IDENT + { close_scope(SC_CHKFORW|SC_CHKPROC|SC_REVERSE); match_id(id, dot.TOK_IDF); } '.' @@ -228,7 +230,7 @@ Module: [ IMPLEMENTATION { state = IMPLEMENTATION; } | - { state = PROGRAM; } + /* empty */ { state = PROGRAM; } ] ProgramModule ; diff --git a/lang/m2/comp/statement.g b/lang/m2/comp/statement.g index 7728d2de..6c45f898 100644 --- a/lang/m2/comp/statement.g +++ b/lang/m2/comp/statement.g @@ -23,7 +23,6 @@ statement(register struct node **pnd;) { register struct node *nd; } : -[ /* * This part is not in the reference grammar. The reference grammar * states : assignment | ProcedureCall | ... @@ -67,7 +66,6 @@ statement(register struct node **pnd;) ReturnStatement(pnd) | /* empty */ { *pnd = 0; } -] ; /* @@ -194,8 +192,7 @@ ForStatement(struct node **pnd;) [ BY ConstExpression(&dummy) - { - if (!(dummy->nd_type->tp_fund & T_INTORCARD)) { + { if (!(dummy->nd_type->tp_fund & T_INTORCARD)) { error("illegal type in BY clause"); } nd->nd_INT = dummy->nd_INT; diff --git a/lang/m2/comp/tmpvar.C b/lang/m2/comp/tmpvar.C index 10338d11..0c5ade1c 100644 --- a/lang/m2/comp/tmpvar.C +++ b/lang/m2/comp/tmpvar.C @@ -33,10 +33,17 @@ struct tmpvar { static struct tmpvar *TmpInts, /* for integer temporaries */ *TmpPtrs; /* for pointer temporaries */ -extern struct scope *ProcScope; /* scope of procedure in which the +static struct scope *ProcScope; /* scope of procedure in which the temporaries are allocated */ +TmpOpen(sc) struct scope *sc; +{ + /* Initialize for temporaries in scope "sc". + */ + ProcScope = sc; +} + arith NewInt() { diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index 13584d02..434c0c23 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -12,6 +12,7 @@ static char *RcsId = "$Header$"; #include #include #include +#include #include "def.h" #include "type.h" diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index 7a5b9bc2..68e60c22 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -13,6 +13,7 @@ static char *RcsId = "$Header$"; #include #include #include +#include #include #include "def.h" @@ -36,7 +37,6 @@ label data_label; static struct type *func_type; struct withdesig *WithDesigs; struct node *Modules; -struct scope *ProcScope; STATIC DoProfil() @@ -74,9 +74,9 @@ WalkModule(module) First call initialization routines for modules defined within this module. */ - sc->sc_off = 0; + sc->sc_off = 0; /* no locals (yet) */ text_label = 1; - ProcScope = sc; + TmpOpen(sc); /* Initialize for temporaries */ C_pro_narg(sc->sc_name); DoProfil(); if (module == Defined) { @@ -130,7 +130,7 @@ WalkProcedure(procedure) proclevel++; CurrVis = procedure->prc_vis; - ProcScope = sc = CurrentScope; + sc = CurrentScope; /* Generate code for all local modules and procedures */ @@ -140,6 +140,7 @@ WalkProcedure(procedure) */ C_pro_narg(sc->sc_name); DoProfil(); + TmpOpen(sc); /* Generate calls to initialization routines of modules defined within this procedure @@ -397,20 +398,16 @@ WalkStat(nd, lab) wds.w_next = WithDesigs; WithDesigs = &wds; wds.w_scope = left->nd_type->rec_scope; - if (ds.dsg_kind != DSG_PFIXED) { - /* In this case, we use a temporary variable - */ - CodeAddress(&ds); - ds.dsg_kind = DSG_FIXED; - /* Create a designator structure for the - temporary. - */ - ds.dsg_offset = tmp = NewPtr(); - ds.dsg_name = 0; - CodeStore(&ds, pointer_size); - ds.dsg_kind = DSG_PFIXED; - /* the record is indirectly available */ - } + CodeAddress(&ds); + ds.dsg_kind = DSG_FIXED; + /* Create a designator structure for the + temporary. + */ + ds.dsg_offset = tmp = NewPtr(); + ds.dsg_name = 0; + CodeStore(&ds, pointer_size); + ds.dsg_kind = DSG_PFIXED; + /* the record is indirectly available */ wds.w_desig = ds; link.sc_scope = wds.w_scope; link.next = CurrVis; @@ -418,7 +415,7 @@ WalkStat(nd, lab) WalkNode(right, lab); CurrVis = link.next; WithDesigs = wds.w_next; - if (tmp) FreePtr(tmp); + FreePtr(tmp); break; } From ee32bf5126201dca1712199702ff96ac81ddbee4 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 10 Jul 1986 16:27:26 +0000 Subject: [PATCH 0213/1625] better compatibility between CARDINAL and ADDRESS --- lang/m2/comp/chk_expr.c | 118 +++++++++++++++++++------------------- lang/m2/comp/chk_expr.h | 4 +- lang/m2/comp/declar.g | 2 +- lang/m2/comp/expression.g | 4 +- lang/m2/comp/type.c | 4 ++ lang/m2/comp/walk.c | 30 +++++----- 6 files changed, 84 insertions(+), 78 deletions(-) diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index 1d8b93d0..eaf8f032 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -28,11 +28,11 @@ static char *RcsId = "$Header$"; extern char *symbol2str(); int -chk_variable(expp) +ChkVariable(expp) register struct node *expp; { - if (! chk_designator(expp)) return 0; + if (! ChkDesignator(expp)) return 0; if (expp->nd_class == Def && !(expp->nd_def->df_kind & (D_FIELD|D_VARIABLE))) { @@ -44,7 +44,7 @@ chk_variable(expp) } STATIC int -chk_arrow(expp) +ChkArrow(expp) register struct node *expp; { register struct type *tp; @@ -54,7 +54,7 @@ chk_arrow(expp) expp->nd_type = error_type; - if (! chk_variable(expp->nd_right)) return 0; + if (! ChkVariable(expp->nd_right)) return 0; tp = expp->nd_right->nd_type; @@ -69,7 +69,7 @@ chk_arrow(expp) } STATIC int -chk_arr(expp) +ChkArr(expp) register struct node *expp; { register struct type *tpl, *tpr; @@ -80,9 +80,9 @@ chk_arr(expp) expp->nd_type = error_type; if ( - !chk_variable(expp->nd_left) + !ChkVariable(expp->nd_left) || - !chk_expr(expp->nd_right) + !ChkExpression(expp->nd_right) || expp->nd_left->nd_type == error_type ) return 0; @@ -111,7 +111,7 @@ chk_arr(expp) } STATIC int -chk_value(expp) +ChkValue(expp) struct node *expp; { switch(expp->nd_symb) { @@ -121,13 +121,13 @@ chk_value(expp) return 1; default: - crash("(chk_value)"); + crash("(ChkValue)"); } /*NOTREACHED*/ } STATIC int -chk_linkorname(expp) +ChkLinkOrName(expp) register struct node *expp; { register struct def *df; @@ -142,7 +142,7 @@ chk_linkorname(expp) assert(expp->nd_symb == '.'); - if (! chk_designator(left)) return 0; + if (! ChkDesignator(left)) return 0; if (left->nd_type->tp_fund != T_RECORD || (left->nd_class == Def && @@ -204,12 +204,12 @@ df->df_idf->id_text); } STATIC int -chk_ex_linkorname(expp) +ChkExLinkOrName(expp) register struct node *expp; { register struct def *df; - if (! chk_linkorname(expp)) return 0; + if (! ChkLinkOrName(expp)) return 0; if (expp->nd_class != Def) return 1; df = expp->nd_def; @@ -237,7 +237,7 @@ STATIC int RemoveSet(set) arith **set; { - /* This routine is only used for error exits of chk_el. + /* This routine is only used for error exits of ChkElement. It frees the set indicated by "set", and returns 0. */ if (*set) { @@ -248,7 +248,7 @@ RemoveSet(set) } STATIC int -chk_el(expp, tp, set) +ChkElement(expp, tp, set) register struct node *expp; register struct type *tp; arith **set; @@ -265,7 +265,7 @@ chk_el(expp, tp, set) /* { ... , expr1 .. expr2, ... } First check expr1 and expr2, and try to compute them. */ - if (!chk_el(left, tp, set) || !chk_el(right, tp, set)) { + if (!ChkElement(left, tp, set) || !ChkElement(right, tp, set)) { return 0; } @@ -295,7 +295,7 @@ node_error(expp, "lower bound exceeds upper bound in range"); /* Here, a single element is checked */ - if (!chk_expr(expp)) { + if (!ChkExpression(expp)) { return RemoveSet(set); } @@ -326,7 +326,7 @@ node_error(expp, "lower bound exceeds upper bound in range"); } STATIC int -chk_set(expp) +ChkSet(expp) register struct node *expp; { /* Check the legality of a SET aggregate, and try to evaluate it @@ -345,7 +345,7 @@ chk_set(expp) if (nd = expp->nd_left) { /* A type was given. Check it out */ - if (! chk_designator(nd)) return 0; + if (! ChkDesignator(nd)) return 0; assert(nd->nd_class == Def); df = nd->nd_def; @@ -383,7 +383,7 @@ node_error(expp, "specifier does not represent a set type"); while (nd) { assert(nd->nd_class == Link && nd->nd_symb == ','); - if (!chk_el(nd->nd_left, ElementType(tp), &set)) return 0; + if (!ChkElement(nd->nd_left, ElementType(tp), &set)) return 0; nd = nd->nd_right; } @@ -426,8 +426,8 @@ getarg(argp, bases, designator) arg = arg->nd_right; left = arg->nd_left; - if ((!designator && !chk_expr(left)) || - (designator && !chk_variable(left))) { + if ((!designator && !ChkExpression(left)) || + (designator && !ChkVariable(left))) { return 0; } @@ -454,7 +454,7 @@ getname(argp, kinds) } arg = arg->nd_right; - if (! chk_designator(arg->nd_left)) return 0; + if (! ChkDesignator(arg->nd_left)) return 0; if (arg->nd_left->nd_class != Def && arg->nd_left->nd_class != LinkDef) { node_error(arg, "identifier expected"); @@ -471,7 +471,7 @@ getname(argp, kinds) } STATIC int -chk_proccall(expp) +ChkProcCall(expp) register struct node *expp; { /* Check a procedure call @@ -507,7 +507,7 @@ node_error(left, "type incompatibility in parameter"); } int -chk_call(expp) +ChkCall(expp) register struct node *expp; { /* Check something that looks like a procedure or function call. @@ -515,19 +515,19 @@ chk_call(expp) it may also be a cast or a standard procedure call. */ register struct node *left; - STATIC int chk_std(); - STATIC int chk_cast(); + STATIC int ChkStandard(); + STATIC int ChkCast(); /* First, get the name of the function or procedure */ expp->nd_type = error_type; left = expp->nd_left; - if (! chk_designator(left)) return 0; + if (! ChkDesignator(left)) return 0; if (IsCast(left)) { /* It was a type cast. This is of course not portable. */ - return chk_cast(expp, left); + return ChkCast(expp, left); } if (IsProcCall(left)) { @@ -537,12 +537,12 @@ chk_call(expp) if (left->nd_type == std_type) { /* A standard procedure */ - return chk_std(expp, left); + return ChkStandard(expp, left); } /* Here, we have found a real procedure call. The left hand side may also represent a procedure variable. */ - return chk_proccall(expp); + return ChkProcCall(expp); } node_error(left, "procedure, type, or function expected"); @@ -606,7 +606,7 @@ AllowedTypes(operator) } STATIC int -chk_address(tpl, tpr) +ChkAddress(tpl, tpr) register struct type *tpl, *tpr; { @@ -622,7 +622,7 @@ chk_address(tpl, tpr) } STATIC int -chk_oper(expp) +ChkBinOper(expp) register struct node *expp; { /* Check a binary operation. @@ -634,7 +634,7 @@ chk_oper(expp) left = expp->nd_left; right = expp->nd_right; - if (!chk_expr(left) || !chk_expr(right)) return 0; + if (!ChkExpression(left) || !ChkExpression(right)) return 0; tpl = BaseType(left->nd_type); tpr = BaseType(right->nd_type); @@ -686,10 +686,11 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R (tpl != bool_type && Boolean(expp->nd_symb))) { if (!(tpl->tp_fund == T_POINTER && (T_CARDINAL & allowed) && - chk_address(tpl, tpr))) { + ChkAddress(tpl, tpr))) { node_error(expp,"operator \"%s\": illegal operand type(s)", symbol2str(expp->nd_symb)); return 0; } + expp->nd_type = card_type; } if (tpl->tp_fund == T_SET) { @@ -706,7 +707,7 @@ node_error(expp,"operator \"%s\": illegal operand type(s)", symbol2str(expp->nd_ } STATIC int -chk_uoper(expp) +ChkUnOper(expp) register struct node *expp; { /* Check an unary operation. @@ -714,9 +715,10 @@ chk_uoper(expp) register struct node *right = expp->nd_right; register struct type *tpr; - if (! chk_expr(right)) return 0; + if (! ChkExpression(right)) return 0; tpr = BaseType(right->nd_type); + if (tpr == address_type) tpr = card_type; expp->nd_type = tpr; switch(expp->nd_symb) { @@ -766,7 +768,7 @@ chk_uoper(expp) break; default: - crash("chk_uoper"); + crash("ChkUnOper"); } node_error(expp, "illegal operand for unary operator \"%s\"", symbol2str(expp->nd_symb)); @@ -785,14 +787,14 @@ getvariable(argp) return 0; } - if (! chk_variable(arg->nd_left)) return 0; + if (! ChkVariable(arg->nd_left)) return 0; *argp = arg; return arg->nd_left; } STATIC int -chk_std(expp, left) +ChkStandard(expp, left) register struct node *expp, *left; { /* Check a call of a standard procedure or function @@ -909,7 +911,7 @@ chk_std(expp, left) "ALLOCATE" : "DEALLOCATE", 0); expp->nd_left = MkLeaf(Name, &dt); } - return chk_call(expp); + return ChkCall(expp); case S_TSIZE: /* ??? */ case S_SIZE: @@ -989,7 +991,7 @@ node_error(arg, "EXCL and INCL expect a SET parameter"); } default: - crash("(chk_std)"); + crash("(ChkStandard)"); } if (arg->nd_right) { @@ -1001,7 +1003,7 @@ node_error(arg, "EXCL and INCL expect a SET parameter"); } STATIC int -chk_cast(expp, left) +ChkCast(expp, left) register struct node *expp, *left; { /* Check a cast and perform it if the argument is constant. @@ -1019,7 +1021,7 @@ node_error(expp, "only one parameter expected in type cast"); } arg = arg->nd_left; - if (! chk_expr(arg)) return 0; + if (! ChkExpression(arg)) return 0; if (arg->nd_type->tp_size != left->nd_type->tp_size && (arg->nd_type->tp_size > word_size || @@ -1078,33 +1080,33 @@ done_before(expp) extern int NodeCrash(); int (*ExprChkTable[])() = { - chk_value, - chk_arr, - chk_oper, - chk_uoper, - chk_arrow, - chk_call, - chk_ex_linkorname, + ChkValue, + ChkArr, + ChkBinOper, + ChkUnOper, + ChkArrow, + ChkCall, + ChkExLinkOrName, NodeCrash, - chk_set, + ChkSet, NodeCrash, NodeCrash, - chk_ex_linkorname, + ChkExLinkOrName, NodeCrash }; int (*DesigChkTable[])() = { - chk_value, - chk_arr, + ChkValue, + ChkArr, no_desig, no_desig, - chk_arrow, + ChkArrow, no_desig, - chk_linkorname, + ChkLinkOrName, NodeCrash, no_desig, done_before, NodeCrash, - chk_linkorname, + ChkLinkOrName, done_before }; diff --git a/lang/m2/comp/chk_expr.h b/lang/m2/comp/chk_expr.h index d24ed645..288bb719 100644 --- a/lang/m2/comp/chk_expr.h +++ b/lang/m2/comp/chk_expr.h @@ -9,5 +9,5 @@ extern int (*DesigChkTable[])(); /* table of designator checking functions, indexed by node class */ -#define chk_expr(expp) ((*ExprChkTable[(expp)->nd_class])(expp)) -#define chk_designator(expp) ((*DesigChkTable[(expp)->nd_class])(expp)) +#define ChkExpression(expp) ((*ExprChkTable[(expp)->nd_class])(expp)) +#define ChkDesignator(expp) ((*DesigChkTable[(expp)->nd_class])(expp)) diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 53fb4665..408fd91e 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -341,7 +341,7 @@ FieldList(struct scope *scope; arith *cnt; int *palign;) the type */ { warning("Old fashioned Modula-2 syntax!"); - if (chk_designator(nd) && + if (ChkDesignator(nd) && (nd->nd_class != Def || !(nd->nd_def->df_kind&(D_ERROR|D_ISTYPE)) || !nd->nd_def->df_type)) { diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index ca3961f4..18a04cba 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -48,7 +48,7 @@ qualident(int types; { if (types) { df = ill_df; - if (chk_designator(nd)) { + if (ChkDesignator(nd)) { if (nd->nd_class != Def) { node_error(nd, "%s expected", str); } @@ -99,7 +99,7 @@ ConstExpression(struct node **pnd;): */ { DO_DEBUG(options['X'], print("CONSTANT EXPRESSION\n")); DO_DEBUG(options['X'], PrNode(*pnd, 0)); - if (chk_expr(*pnd) && + if (ChkExpression(*pnd) && ((*pnd)->nd_class != Set && (*pnd)->nd_class != Value)) { error("Constant expression expected"); } diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index 434c0c23..610bc9fc 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -154,6 +154,10 @@ InitTypes() fatal("integer size not equal to word size"); } + if (int_size != pointer_size) { + fatal("cardinal size not equal to pointer size"); + } + if (long_size < int_size || long_size % word_size != 0) { fatal("illegal long integer size"); } diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index 68e60c22..d7257424 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -256,7 +256,7 @@ WalkCall(nd) assert(nd->nd_class == Call); if (! options['L']) C_lin((arith) nd->nd_lineno); - if (chk_call(nd)) { + if (ChkCall(nd)) { if (nd->nd_type != 0) { node_error(nd, "procedure call expected"); return; @@ -472,7 +472,7 @@ ExpectBool(nd, true_label, false_label) */ struct desig ds; - if (!chk_expr(nd)) return; + if (!ChkExpression(nd)) return; if (nd->nd_type != bool_type && nd->nd_type != error_type) { node_error(nd, "boolean expression expected"); @@ -488,7 +488,7 @@ WalkExpr(nd) /* Check an expression and generate code for it */ - if (! chk_expr(nd)) return; + if (! ChkExpression(nd)) return; CodePExpr(nd); } @@ -500,7 +500,7 @@ WalkDesignator(nd, ds) /* Check designator and generate code for it */ - if (! chk_variable(nd)) return; + if (! ChkVariable(nd)) return; *ds = InitDesig; CodeDesig(nd, ds); @@ -515,9 +515,9 @@ DoForInit(nd, left) nd->nd_class = Name; nd->nd_symb = IDENT; - if (! chk_variable(nd) || - ! chk_expr(left->nd_left) || - ! chk_expr(left->nd_right)) return 0; + if (! ChkVariable(nd) || + ! ChkExpression(left->nd_left) || + ! ChkExpression(left->nd_right)) return 0; df = nd->nd_def; if (df->df_kind == D_FIELD) { @@ -543,16 +543,16 @@ DoForInit(nd, left) } } - if (nd->nd_type->tp_size > word_size || - !(nd->nd_type->tp_fund & T_DISCRETE)) { + if (df->df_type->tp_size > word_size || + !(df->df_type->tp_fund & T_DISCRETE)) { node_error(nd, "illegal type of FOR loop variable"); return 0; } - if (!TstCompat(nd->nd_type, left->nd_left->nd_type) || - !TstCompat(nd->nd_type, left->nd_right->nd_type)) { - if (!TstAssCompat(nd->nd_type, left->nd_left->nd_type) || - !TstAssCompat(nd->nd_type, left->nd_right->nd_type)) { + if (!TstCompat(df->df_type, left->nd_left->nd_type) || + !TstCompat(df->df_type, left->nd_right->nd_type)) { + if (!TstAssCompat(df->df_type, left->nd_left->nd_type) || + !TstAssCompat(df->df_type, left->nd_right->nd_type)) { node_error(nd, "type incompatibility in FOR statement"); return 0; } @@ -571,8 +571,8 @@ DoAssign(nd, left, right) /* May we do it in this order (expression first) ??? */ struct desig dsl, dsr; - if (!chk_expr(right)) return; - if (! chk_variable(left)) return; + if (!ChkExpression(right)) return; + if (! ChkVariable(left)) return; TryToString(right, left->nd_type); dsr = InitDesig; CodeExpr(right, &dsr, NO_LABEL, NO_LABEL); From ca77c2b86b5e669c6851608c4a1a03a49aa3dfb9 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 14 Jul 1986 15:00:08 +0000 Subject: [PATCH 0214/1625] Some bug fixes --- lang/m2/comp/chk_expr.c | 8 +++++++- lang/m2/comp/cstoper.c | 2 +- lang/m2/comp/declar.g | 9 ++++++++- lang/m2/comp/scope.C | 19 ++++++++++++++++--- lang/m2/comp/typequiv.c | 5 +++++ lang/m2/comp/walk.c | 11 ++++++++--- 6 files changed, 45 insertions(+), 9 deletions(-) diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index eaf8f032..0137ec52 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -183,6 +183,7 @@ df->df_idf->id_text); assert(expp->nd_class == Def); df = expp->nd_def; + if (df == ill_df) return 0; if (df->df_kind & (D_ENUM | D_CONST)) { if (df->df_kind == D_ENUM) { @@ -431,6 +432,10 @@ getarg(argp, bases, designator) return 0; } + if (designator && left->nd_class == Def) { + left->nd_def->df_flags |= D_NOREG; + } + tp = BaseType(left->nd_type); if (bases && !(tp->tp_fund & bases)) { @@ -836,8 +841,9 @@ ChkStandard(expp, left) if (!(left = getarg(&arg, T_ARRAY, 0))) return 0; if (IsConformantArray(left->nd_type)) { /* A conformant array has no explicit index type + ??? So, what can we use as index-type ??? */ - expp->nd_type = card_type; + expp->nd_type = intorcard_type; } else { expp->nd_type = IndexType(left->nd_type); diff --git a/lang/m2/comp/cstoper.c b/lang/m2/comp/cstoper.c index 65c9924e..494a7bc9 100644 --- a/lang/m2/comp/cstoper.c +++ b/lang/m2/comp/cstoper.c @@ -467,7 +467,7 @@ cstcall(expp, call) break; case S_SIZE: - expp->nd_INT = WA(expr->nd_type->tp_size) / word_size; + expp->nd_INT = WA(expr->nd_type->tp_size); break; case S_VAL: diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 408fd91e..a634808d 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -181,6 +181,13 @@ error("opaque type \"%s\" is not a pointer type", df->df_idf->id_text); referring to the hidden type. */ *(df->df_type) = *tp; + if (! tp->next) { + /* It also contains a forward + reference, so update the forward- + list + */ + ChForward(tp, df->df_type); + } free_type(tp); } else df->df_type = tp; @@ -457,7 +464,7 @@ PointerType(struct type **ptp;) df->df_kind == D_MODULE) type(&((*ptp)->next)) | - IDENT { Forward(&dot, &((*ptp)->next)); } + IDENT { Forward(&dot, (*ptp)); } ] ; diff --git a/lang/m2/comp/scope.C b/lang/m2/comp/scope.C index 737cbd40..5333f37f 100644 --- a/lang/m2/comp/scope.C +++ b/lang/m2/comp/scope.C @@ -68,14 +68,14 @@ InitScope() struct forwards { struct forwards *next; struct node fo_tok; - struct type **fo_ptyp; + struct type *fo_ptyp; }; /* STATICALLOCDEF "forwards" */ Forward(tk, ptp) struct token *tk; - struct type **ptp; + struct type *ptp; { /* Enter a forward reference into a list belonging to the current scope. This is used for POINTER declarations, which @@ -90,6 +90,19 @@ Forward(tk, ptp) CurrentScope->sc_forw = f; } +ChForward(was, becomes) + struct type *was, *becomes; +{ + /* The declaration of a hidden type had a forward reference. + In this case, the "forwards" list must be adapted. + */ + register struct forwards *f = CurrentScope->sc_forw; + + while (f && f->fo_ptyp != was) f = f->next; + assert(f != 0); + f->fo_ptyp = becomes; +} + STATIC chk_proc(df) register struct def *df; @@ -168,7 +181,7 @@ rem_forwards(fo) node_error(&(f->fo_tok), "identifier \"%s\" not a type", df->df_idf->id_text); } - *(f->fo_ptyp) = df->df_type; + f->fo_ptyp->next = df->df_type; fo = f->next; free_forwards(f); } diff --git a/lang/m2/comp/typequiv.c b/lang/m2/comp/typequiv.c index 0e1d4ce7..0b0b9953 100644 --- a/lang/m2/comp/typequiv.c +++ b/lang/m2/comp/typequiv.c @@ -144,6 +144,11 @@ TstAssCompat(tp1, tp2) if ((tp1->tp_fund & T_INTORCARD) && (tp2->tp_fund & T_INTORCARD)) return 1; + if (tp1->tp_fund == T_PROCEDURE && + tp2->tp_fund == T_PROCEDURE) { + return TstProcEquiv(tp1, tp2); + } + if (tp1->tp_fund == T_ARRAY) { /* check for string */ diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index d7257424..7454ed96 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -84,7 +84,7 @@ WalkModule(module) Call initialization routines of imported modules. Also prevent recursive calls of this one. */ - register struct node *nd; + register struct node *nd = Modules; if (state == IMPLEMENTATION) { label l1 = ++data_label; @@ -97,9 +97,14 @@ WalkModule(module) C_zne((label) 1); C_loc((arith) 1); C_ste_dlb(l1, (arith) 0); + /* Prevent this module from calling its own + initialization routine + */ + assert(nd->nd_IDF == module->df_idf); + nd = nd->next; } - for (nd = Modules; nd; nd = nd->next) { + for (; nd; nd = nd->next) { C_cal(nd->nd_IDF->id_text); } } @@ -571,7 +576,7 @@ DoAssign(nd, left, right) /* May we do it in this order (expression first) ??? */ struct desig dsl, dsr; - if (!ChkExpression(right)) return; + if (! ChkExpression(right)) return; if (! ChkVariable(left)) return; TryToString(right, left->nd_type); dsr = InitDesig; From 7f5bcdf11690bcb96e34b55e9125c86f4da58929 Mon Sep 17 00:00:00 2001 From: dick Date: Thu, 17 Jul 1986 22:17:59 +0000 Subject: [PATCH 0215/1625] option NORCSID for lint in Makefile is nonsense --- lang/cem/cemcom/Makefile.erik | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/cem/cemcom/Makefile.erik b/lang/cem/cemcom/Makefile.erik index ca62a8f1..9b1e4d1b 100644 --- a/lang/cem/cemcom/Makefile.erik +++ b/lang/cem/cemcom/Makefile.erik @@ -173,7 +173,7 @@ lxref: lint: lint.main lint.cem lint.tab lint.main: cfiles - lint -DNORCSID -bx $(CDEFS) `sources $(OBJ)` >lint.out + lint -bx $(CDEFS) `sources $(OBJ)` >lint.out cchk: cchk `sources $(COBJ)` From fa9f4ab0ab660a416672006f220eaee8f1e49abb Mon Sep 17 00:00:00 2001 From: dick Date: Fri, 18 Jul 1986 21:10:42 +0000 Subject: [PATCH 0216/1625] some leaks plugged (as detected by the leak detector) --- lang/cem/cemcom/Makefile.erik | 13 +-- lang/cem/cemcom/Parameters | 2 +- lang/cem/cemcom/code.c | 146 ++++++++++++++++++---------------- lang/cem/cemcom/code.str | 8 -- lang/cem/cemcom/cstoper.c | 1 + lang/cem/cemcom/declar.g | 24 +++--- lang/cem/cemcom/declar.str | 12 ++- lang/cem/cemcom/declarator.c | 14 ++-- lang/cem/cemcom/expr.c | 47 +++++++---- lang/cem/cemcom/idf.c | 24 +++--- lang/cem/cemcom/idf.str | 7 -- lang/cem/cemcom/main.c | 7 +- lang/cem/cemcom/make.allocd | 1 - lang/cem/cemcom/program.g | 7 +- lang/cem/cemcom/stack.c | 16 ++-- lang/cem/cemcom/statement.g | 22 ++--- lang/cem/cemcom/storage.c | 2 +- lang/cem/cemcom/storage.h | 20 ++++- lang/cem/cemcom/struct.str | 2 - lang/cem/cemcom/switch.c | 4 +- lang/cem/cemcom/type.c | 1 + 21 files changed, 204 insertions(+), 176 deletions(-) diff --git a/lang/cem/cemcom/Makefile.erik b/lang/cem/cemcom/Makefile.erik index 9b1e4d1b..0304e641 100644 --- a/lang/cem/cemcom/Makefile.erik +++ b/lang/cem/cemcom/Makefile.erik @@ -56,7 +56,7 @@ GOBJ = char.o symbol2str.o next.o # generated source files GSRC = char.c symbol2str.c next.c \ code.h declar.h decspecs.h def.h expr.h field.h \ - idf.h macro.h stack.h struct.h switch.h type.h + idf.h macro.h stack.h stmt.h struct.h switch.h type.h # .h files generated by `make hfiles'; PLEASE KEEP THIS UP-TO-DATE! GHSRC = botch_free.h dataflow.h debug.h density.h errout.h \ @@ -71,7 +71,7 @@ GENERATED = tab tokenfile.g Lpars.h LLfiles LL.output lint.out \ # include files containing ALLOCDEF specifications NEXTFILES = code.str declar.str decspecs.str def.str expr.str field.str \ - idf.str macro.str stack.str struct.str switch.str type.str + idf.str macro.str stack.str stmt.str struct.str switch.str type.str .SUFFIXES: .str .h .str.h: @@ -90,7 +90,7 @@ cem: cem.c lint.cem: cem.c lint -abx cem.c -hfiles: Parameters +hfiles: ./make.hfiles Parameters ./make.hfiles Parameters @touch hfiles @@ -119,6 +119,7 @@ field.h: make.allocd idf.h: make.allocd macro.h: make.allocd stack.h: make.allocd +stmt.h: make.allocd struct.h: make.allocd switch.h: make.allocd type.h: make.allocd @@ -202,7 +203,7 @@ ch7bin.o: Lpars.h arith.h botch_free.h expr.h idf.h label.h nobitfield.h nopp.h cstoper.o: Lpars.h arith.h assert.h debug.h expr.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h target_sizes.h type.h arith.o: Lpars.h alloc.h arith.h botch_free.h expr.h field.h idf.h label.h mes.h nobitfield.h nopp.h spec_arith.h storage.h type.h alloc.o: alloc.h assert.h debug.h myalloc.h -code.o: LLlex.h Lpars.h alloc.h arith.h assert.h atw.h botch_free.h code.h dataflow.h debug.h declar.h decspecs.h def.h expr.h idf.h label.h level.h mes.h nobitfield.h nopp.h sizes.h spec_arith.h specials.h stack.h storage.h type.h use_tmp.h +code.o: LLlex.h Lpars.h alloc.h arith.h assert.h atw.h botch_free.h code.h dataflow.h debug.h declar.h decspecs.h def.h expr.h idf.h label.h level.h mes.h nobitfield.h nopp.h sizes.h spec_arith.h specials.h stack.h stmt.h storage.h type.h use_tmp.h dumpidf.o: Lpars.h arith.h debug.h def.h expr.h field.h idf.h label.h nobitfield.h nopp.h spec_arith.h stack.h struct.h type.h error.o: LLlex.h arith.h debug.h errout.h expr.h label.h nopp.h spec_arith.h tokenname.h use_tmp.h field.o: Lpars.h arith.h assert.h code.h debug.h expr.h field.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h type.h @@ -217,7 +218,7 @@ options.o: align.h arith.h class.h idf.h idfsize.h macro.h maxincl.h nobitfield. scan.o: class.h idf.h input.h interface.h lapbuf.h macro.h nopp.h nparams.h skip.o: LLlex.h arith.h class.h input.h interface.h nopp.h spec_arith.h stack.o: Lpars.h alloc.h arith.h botch_free.h debug.h def.h idf.h level.h mes.h nobitfield.h nopp.h spec_arith.h stack.h storage.h struct.h type.h use_tmp.h -type.o: Lpars.h align.h alloc.h arith.h def.h idf.h nobitfield.h nopp.h sizes.h spec_arith.h type.h +type.o: Lpars.h align.h alloc.h arith.h def.h idf.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h type.h ch7mon.o: Lpars.h arith.h botch_free.h def.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h storage.h type.h label.o: Lpars.h arith.h def.h idf.h label.h level.h nobitfield.h nopp.h spec_arith.h type.h eval.o: Lpars.h align.h arith.h assert.h atw.h code.h dataflow.h debug.h def.h expr.h idf.h label.h level.h mes.h nobitfield.h nopp.h sizes.h spec_arith.h stack.h type.h @@ -228,7 +229,7 @@ conversion.o: Lpars.h arith.h nobitfield.h sizes.h spec_arith.h type.h blocks.o: arith.h atw.h sizes.h spec_arith.h dataflow.o: dataflow.h tokenfile.o: Lpars.h -declar.o: LLlex.h Lpars.h arith.h debug.h declar.h decspecs.h def.h expr.h field.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h struct.h type.h +declar.o: LLlex.h Lpars.h arith.h debug.h declar.h decspecs.h def.h expr.h field.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h struct.h type.h statement.o: LLlex.h Lpars.h arith.h botch_free.h code.h debug.h def.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h stack.h storage.h type.h expression.o: LLlex.h Lpars.h arith.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h type.h program.o: LLlex.h Lpars.h alloc.h arith.h code.h declar.h decspecs.h def.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h type.h diff --git a/lang/cem/cemcom/Parameters b/lang/cem/cemcom/Parameters index 3744c69b..c3b9bef7 100644 --- a/lang/cem/cemcom/Parameters +++ b/lang/cem/cemcom/Parameters @@ -1,5 +1,5 @@ !File: myalloc.h -#define OWNALLOC 1 /* use own superfast allocation */ +#define OWNALLOC 1 /* use own superfast allocation */ #define ALLOCSIZ 4096 /* allocate pieces of 4K */ #define ALIGNSIZE 8 /* needed for alloc.c */ diff --git a/lang/cem/cemcom/code.c b/lang/cem/cemcom/code.c index 098924f7..0dd0c6f5 100644 --- a/lang/cem/cemcom/code.c +++ b/lang/cem/cemcom/code.c @@ -12,6 +12,7 @@ #include "idf.h" #include "label.h" #include "code.h" +#include "stmt.h" #include "alloc.h" #include "def.h" #include "expr.h" @@ -28,7 +29,7 @@ #include "atw.h" #include "assert.h" -static struct stat_block *stat_sp, *stat_head; +static struct stmt_block *stmt_stack; char *symbol2str(); int fp_used; @@ -37,20 +38,18 @@ label datlab_count = 1; extern char options[]; -/* init_code() initialises the output file on which the compact - EM code is written -*/ init_code(dst_file) char *dst_file; { + /* init_code() initialises the output file on which the + compact EM code is written + */ C_init(word_size, pointer_size); /* initialise EM module */ if (C_open(dst_file) == 0) fatal("cannot write to %s\n", dst_file); #ifndef USE_TMP famous_first_words(); #endif USE_TMP - stat_sp = stat_head = new_stat_block(); - clear((char *)stat_sp, sizeof(struct stat_block)); } famous_first_words() @@ -162,18 +161,18 @@ static label func_res_label; static char *last_fn_given = ""; static label file_name_label; -/* begin_proc() is called at the entrance of a new function - and performs the necessary code generation: - - a scope indicator (if needed) exp/inp - - the procedure entry pro $name - - reserves some space if the result of the function - does not fit in the return area - - a fil pseudo instruction -*/ begin_proc(name, def) /* to be called when entering a procedure */ char *name; struct def *def; { + /* begin_proc() is called at the entrance of a new function + and performs the necessary code generation: + - a scope indicator (if needed) exp/inp + - the procedure entry pro $name + - reserves some space if the result of the function + does not fit in the return area + - a fil pseudo instruction + */ arith size; #ifndef USE_TMP @@ -217,20 +216,21 @@ begin_proc(name, def) /* to be called when entering a procedure */ } } -/* end_proc() deals with the code to be generated at the end of - a function, as there is: - - the EM ret instruction: "ret 0" - - loading of the function result in the function result area - if there has been a return in the function body - (see do_return_expr()) - - indication of the use of floating points - - indication of the number of bytes used for formal parameters - - use of special identifiers such as "setjmp" - - "end" + number of bytes used for local variables -*/ end_proc(fbytes, nbytes) arith fbytes, nbytes; { + /* end_proc() deals with the code to be generated at the end of + a function, as there is: + - the EM ret instruction: "ret 0" + - loading of the function result in the function + result area if there has been a return + in the function body (see do_return_expr()) + - indication of the use of floating points + - indication of the number of bytes used for + formal parameters + - use of special identifiers such as "setjmp" + - "end" + number of bytes used for local variables + */ static int mes_flt_given = 0; /* once for the whole program */ #ifdef DATAFLOW @@ -296,6 +296,10 @@ code_declaration(idf, expr, lvl, sc) - global variables, coded only if initialized; - local static variables; - local automatic variables; + Since the expression may be modified in the process, + code_declaration() frees it after use, as the caller can + no longer do so. + If there is a storage class indication (EXTERN/STATIC), code_declaration() will generate an exa or ina. The sc is the actual storage class, as given in the @@ -328,6 +332,7 @@ code_declaration(idf, expr, lvl, sc) def->df_alloc = ALLOC_DONE; C_df_dnam(text); do_ival(&(def->df_type), expr); + free_expression(expr); } } else @@ -341,8 +346,11 @@ code_declaration(idf, expr, lvl, sc) integer label in EM. */ C_df_dlb((label)def->df_address); - if (expr) /* there is an initialisation */ + if (expr) { + /* there is an initialisation */ do_ival(&(def->df_type), expr); + free_expression(expr); + } else { /* produce blank space */ if (size <= 0) { error("size of %s unknown", text); @@ -378,6 +386,7 @@ loc_init(expr, id) { /* loc_init() generates code for the assignment of expression expr to the local variable described by id. + It frees the expression afterwards. */ register struct type *tp = id->id_def->df_type; @@ -388,6 +397,7 @@ loc_init(expr, id) case STRUCT: case UNION: error("no automatic aggregate initialisation"); + free_expression(expr); return; } @@ -407,8 +417,9 @@ loc_init(expr, id) else { /* not embraced */ struct value vl; - ch7cast(&expr, '=', tp); + ch7cast(&expr, '=', tp); /* may modify expr */ EVAL(expr, RVAL, TRUE, NO_LABEL, NO_LABEL); + free_expression(expr); vl.vl_class = Name; vl.vl_data.vl_idf = id; vl.vl_value = (arith)0; @@ -416,11 +427,11 @@ loc_init(expr, id) } } -/* bss() allocates bss space for the global idf. -*/ bss(idf) struct idf *idf; { + /* bss() allocates bss space for the global idf. + */ register struct def *def = idf->id_def; arith size = def->df_type->tp_size; @@ -454,85 +465,80 @@ formal_cvt(def) } } -/* code_expr() is the parser's interface to the expression code - generator. - If line number trace is wanted, it generates a lin instruction. - EVAL() is called directly. -*/ code_expr(expr, val, code, tlbl, flbl) struct expr *expr; label tlbl, flbl; { + /* code_expr() is the parser's interface to the expression code + generator. + If line number trace is wanted, it generates a + lin instruction. EVAL() is called directly. + */ if (options['p']) /* profiling */ C_lin((arith)LineNumber); EVAL(expr, val, code, tlbl, flbl); } /* The FOR/WHILE/DO/SWITCH stacking mechanism: - stat_stack() has to be called at the entrance of a + stack_stmt() has to be called at the entrance of a for, while, do or switch statement to indicate the EM labels where a subsequent break or continue causes the program to jump to. */ -/* do_break() generates EM code needed at the occurrence of "break": +/* code_break() generates EM code needed at the occurrence of "break": it generates a branch instruction to the break label of the innermost statement in which break has a meaning. As "break" is legal in any of 'while', 'do', 'for' or 'switch', which are the only ones that are stacked, only the top of the stack is interesting. - 0 is returned if the break cannot be bound to any enclosing - statement. */ -int -do_break() +code_break() { - register struct stat_block *stat_ptr = stat_sp; + register struct stmt_block *stmt_block = stmt_stack; - if (stat_ptr) { - C_bra(stat_ptr->st_break); - return 1; + if (stmt_block) { + C_bra(stmt_block->st_break); + return; } - return 0; /* break is illegal */ + error("break not inside for, while, do or switch"); } -/* do_continue() generates EM code needed at the occurrence of "continue": +/* code_continue() generates EM code needed at the occurrence of + "continue": it generates a branch instruction to the continue label of the innermost statement in which continue has a meaning. - 0 is returned if the continue cannot be bound to any enclosing - statement. */ -int -do_continue() +code_continue() { - register struct stat_block *stat_ptr = stat_sp; + register struct stmt_block *stmt_block = stmt_stack; - while (stat_ptr) { - if (stat_ptr->st_continue) { - C_bra(stat_ptr->st_continue); - return 1; + while (stmt_block) { + if (stmt_block->st_continue) { + C_bra(stmt_block->st_continue); + return; } - stat_ptr = stat_ptr->next; + stmt_block = stmt_block->next; } - return 0; + error("continue not inside for, while or do"); } -stat_stack(break_label, cont_label) +stack_stmt(break_label, cont_label) label break_label, cont_label; { - register struct stat_block *newb = new_stat_block(); + register struct stmt_block *stmt_block = new_stmt_block(); - newb->next = stat_sp; - newb->st_break = break_label; - newb->st_continue = cont_label; - stat_sp = newb; + stmt_block->next = stmt_stack; + stmt_block->st_break = break_label; + stmt_block->st_continue = cont_label; + stmt_stack = stmt_block; } -/* stat_unstack() unstacks the data of a statement - which may contain break or continue -*/ -stat_unstack() +unstack_stmt() { - register struct stat_block *sbp = stat_sp; - stat_sp = stat_sp->next; - free_stat_block(sbp); + /* unstack_stmt() unstacks the data of a statement + which may contain break or continue + */ + register struct stmt_block *sbp = stmt_stack; + stmt_stack = stmt_stack->next; + free_stmt_block(sbp); } diff --git a/lang/cem/cemcom/code.str b/lang/cem/cemcom/code.str index 2f2399ce..b2ca234d 100644 --- a/lang/cem/cemcom/code.str +++ b/lang/cem/cemcom/code.str @@ -1,14 +1,6 @@ /* $Header$ */ /* C O D E - G E N E R A T O R D E F I N I T I O N S */ -struct stat_block { - struct stat_block *next; - label st_break; - label st_continue; -}; - -/* ALLOCDEF "stat_block" */ - struct string_cst { /* storing string constants */ struct string_cst *next; char *sc_value; diff --git a/lang/cem/cemcom/cstoper.c b/lang/cem/cemcom/cstoper.c index 1d31a1b2..e9ce5349 100644 --- a/lang/cem/cemcom/cstoper.c +++ b/lang/cem/cemcom/cstoper.c @@ -180,6 +180,7 @@ cstbin(expp, oper, expr) cut_size(*expp); (*expp)->ex_flags |= expr->ex_flags; (*expp)->ex_flags &= ~EX_PARENS; + free_expression(expr); } cut_size(expr) diff --git a/lang/cem/cemcom/declar.g b/lang/cem/cemcom/declar.g index c211724f..ac6535c9 100644 --- a/lang/cem/cemcom/declar.g +++ b/lang/cem/cemcom/declar.g @@ -16,6 +16,7 @@ #include "label.h" #include "expr.h" #include "sizes.h" +#include "storage.h" extern char options[]; } @@ -151,7 +152,6 @@ init_declarator(struct decspecs *ds;) initializer(Dc.dc_idf, &expr)? { code_declaration(Dc.dc_idf, expr, level, ds->ds_sc); - free_expression(expr); } ] {remove_declarator(&Dc);} @@ -167,7 +167,7 @@ init_declarator(struct decspecs *ds;) declarator(struct declarator *dc;) { arith count; - struct idstack_item *is = 0; + struct formal *fm = 0; } : [ @@ -177,11 +177,11 @@ declarator(struct declarator *dc;) old-fashioned initialization. */ '(' - formal_list(&is) ? /* semantic check later... */ + formal_list(&fm) ? /* semantic check later... */ ')' { - add_decl_unary(dc, FUNCTION, (arith)0, is); - is = 0; + add_decl_unary(dc, FUNCTION, (arith)0, fm); + fm = 0; } | arrayer(&count) @@ -219,21 +219,21 @@ arrayer(arith *sizep;) ']' ; -formal_list (struct idstack_item **is;) +formal_list (struct formal **fmp;) : - formal(is) [ ',' formal(is) ]* + formal(fmp) [ ',' formal(fmp) ]* ; -formal(struct idstack_item **is;) +formal(struct formal **fmp;) {struct idf *idf; } : identifier(&idf) { - struct idstack_item *new = new_idstack_item(); + struct formal *new = new_formal(); - new->is_idf = idf; - new->next = *is; - *is = new; + new->fm_idf = idf; + new->next = *fmp; + *fmp = new; } ; diff --git a/lang/cem/cemcom/declar.str b/lang/cem/cemcom/declar.str index 9a25c58a..c9c197ac 100644 --- a/lang/cem/cemcom/declar.str +++ b/lang/cem/cemcom/declar.str @@ -10,12 +10,20 @@ struct declarator { struct declarator *next; struct idf *dc_idf; struct decl_unary *dc_decl_unary; - struct idstack_item *dc_fparams; /* params for function */ + struct formal *dc_formal; /* params for function */ }; /* ALLOCDEF "declarator" */ -#define NO_PARAMS ((struct idstack_item *) 0) + +struct formal { /* list of formals */ + struct formal *next; + struct idf *fm_idf; +}; + +/* ALLOCDEF "formal" */ + +#define NO_PARAMS ((struct formal *) 0) struct decl_unary { struct decl_unary *next; diff --git a/lang/cem/cemcom/declarator.c b/lang/cem/cemcom/declarator.c index 4eb1a32f..dba30694 100644 --- a/lang/cem/cemcom/declarator.c +++ b/lang/cem/cemcom/declarator.c @@ -32,10 +32,10 @@ declare_type(tp, dc) return tp; } -add_decl_unary(dc, fund, count, is) +add_decl_unary(dc, fund, count, fm) struct declarator *dc; arith count; - struct idstack_item *is; + struct formal *fm; { /* A decl_unary describing a constructor with fundamental type fund and with size count is inserted in front of the @@ -47,14 +47,14 @@ add_decl_unary(dc, fund, count, is) new->next = dc->dc_decl_unary; new->du_fund = fund; new->du_count = count; - if (is) { + if (fm) { if (dc->dc_decl_unary) { /* paramlist only allowed at first decl_unary */ error("formal parameter list discarded"); } else { /* register the parameters */ - dc->dc_fparams = is; + dc->dc_formal = fm; } } dc->dc_decl_unary = new; @@ -82,10 +82,10 @@ reject_params(dc) /* The declarator is checked to have no parameters, if it is a function. */ - if (dc->dc_fparams) { + if (dc->dc_formal) { error("non_empty formal parameter pack"); - del_idfstack(dc->dc_fparams); - dc->dc_fparams = 0; + free_formals(dc->dc_formal); + dc->dc_formal = 0; } } diff --git a/lang/cem/cemcom/expr.c b/lang/cem/cemcom/expr.c index 0a8629e9..3549c840 100644 --- a/lang/cem/cemcom/expr.c +++ b/lang/cem/cemcom/expr.c @@ -132,7 +132,7 @@ dot2expr(expp) string2expr(*expp); break; case INTEGER: - *expp = intexpr(dot.tk_ival, dot.tk_fund); + int2expr(*expp); break; case FLOATING: float2expr(*expp); @@ -214,6 +214,27 @@ string2expr(expr) expr->SG_DATLAB = 0; } +int2expr(expr) + struct expr *expr; +{ + /* Dot contains an integer constant which is turned + into an expression. + */ + fill_int_expr(expr, dot.tk_ival, dot.tk_fund); +} + +float2expr(expr) + struct expr *expr; +{ + /* Dot contains a floating point constant which is turned + into an expression. + */ + expr->ex_type = double_type; + expr->ex_class = Float; + expr->FL_VALUE = dot.tk_fval; + expr->FL_DATLAB = 0; +} + struct expr* intexpr(ivalue, fund) arith ivalue; @@ -227,6 +248,17 @@ intexpr(ivalue, fund) expr->ex_file = dot.tk_file; expr->ex_line = dot.tk_line; + fill_int_expr(expr, ivalue, fund); + return expr; +} + +fill_int_expr(expr, ivalue, fund) + struct expr *expr; + arith ivalue; +{ + /* Details derived from ivalue and fund are put into the + constant integer expression expr. + */ switch (fund) { case INT: expr->ex_type = int_type; @@ -258,19 +290,6 @@ intexpr(ivalue, fund) expr->VL_VALUE = ivalue; cut_size(expr); - return expr; -} - -float2expr(expr) - struct expr *expr; -{ - /* Dot contains a floating point constant which is turned - into an expression. - */ - expr->ex_type = double_type; - expr->ex_class = Float; - expr->FL_VALUE = dot.tk_fval; - expr->FL_DATLAB = 0; } struct expr * diff --git a/lang/cem/cemcom/idf.c b/lang/cem/cemcom/idf.c index b948e206..0209567c 100644 --- a/lang/cem/cemcom/idf.c +++ b/lang/cem/cemcom/idf.c @@ -552,14 +552,14 @@ declare_params(dc) { /* Declares the formal parameters if they exist. */ - register struct idstack_item *is = dc->dc_fparams; + register struct formal *fm = dc->dc_formal; - while (is) { - declare_parameter(is->is_idf); - is = is->next; + while (fm) { + declare_parameter(fm->fm_idf); + fm = fm->next; } - del_idfstack(dc->dc_fparams); - dc->dc_fparams = 0; + free_formals(dc->dc_formal); + dc->dc_formal = 0; } init_idf(idf) @@ -672,13 +672,13 @@ update_ahead(idf) TYPE_IDENTIFIER : IDENTIFIER; } -del_idfstack(is) - struct idstack_item *is; +free_formals(fm) + struct formal *fm; { - while (is) { - register struct idstack_item *tmp = is->next; - free_idstack_item(is); - is = tmp; + while (fm) { + register struct formal *tmp = fm->next; + free_formal(fm); + fm = tmp; } } diff --git a/lang/cem/cemcom/idf.str b/lang/cem/cemcom/idf.str index 3b6f7021..abba9f6b 100644 --- a/lang/cem/cemcom/idf.str +++ b/lang/cem/cemcom/idf.str @@ -22,13 +22,6 @@ extern char hmask[]; /* the random masks */ #define ENHASH(hs,ch,ps) (hs + (ch ^ hmask[ps])) #define STOPHASH(hs) (hs & HASHMASK) -struct idstack_item { /* stack of identifiers */ - struct idstack_item *next; - struct idf *is_idf; -}; - -/* ALLOCDEF "idstack_item" */ - struct idf { struct idf *next; char *id_text; diff --git a/lang/cem/cemcom/main.c b/lang/cem/cemcom/main.c index 79bc29c7..0c95935f 100644 --- a/lang/cem/cemcom/main.c +++ b/lang/cem/cemcom/main.c @@ -189,14 +189,15 @@ compile(argc, argv) #endif USE_TMP #ifdef DEBUG - if (options['u']) /* unstack L_UNIVERSAL */ - unstack_level(); + if (options['u']) { + unstack_level(); /* unstack L_GLOBAL */ + } if (options['f'] || options['t']) dumpidftab("end of main", options['f'] ? 0 : 0); #endif DEBUG #ifndef NOPP } -#endif NOPP +#endif NOPP PopLex(); } diff --git a/lang/cem/cemcom/make.allocd b/lang/cem/cemcom/make.allocd index 1c2469d8..d692801e 100755 --- a/lang/cem/cemcom/make.allocd +++ b/lang/cem/cemcom/make.allocd @@ -1,7 +1,6 @@ sed ' s:^.*ALLOCDEF.*"\(.*\)".*$:\ /* allocation definitions of struct \1 */\ -extern char *st_alloc();\ extern struct \1 *h_\1;\ #define new_\1() ((struct \1 *) \\\ st_alloc((char **)\&h_\1, sizeof(struct \1)))\ diff --git a/lang/cem/cemcom/program.g b/lang/cem/cemcom/program.g index 36da56e5..c44b44e5 100644 --- a/lang/cem/cemcom/program.g +++ b/lang/cem/cemcom/program.g @@ -153,10 +153,9 @@ non_function(struct decspecs *ds; struct declarator *dc;) : {reject_params(dc);} initializer(dc->dc_idf, &expr)? - { - code_declaration(dc->dc_idf, expr, level, ds->ds_sc); - free_expression(expr); - } + { + code_declaration(dc->dc_idf, expr, level, ds->ds_sc); + } [ ',' init_declarator(ds) diff --git a/lang/cem/cemcom/stack.c b/lang/cem/cemcom/stack.c index 8f939230..5e27af24 100644 --- a/lang/cem/cemcom/stack.c +++ b/lang/cem/cemcom/stack.c @@ -1,4 +1,4 @@ -/* DERIVED FROM $Header$ */ +/* $Header$ */ /* S T A C K / U N S T A C K R O U T I N E S */ #include @@ -250,19 +250,21 @@ unstack_world() /* space must be allocated */ bss(idf); namelist(idf->id_text); /* may be common */ - def->df_alloc = ALLOC_DONE; /* *) */ + def->df_alloc = ALLOC_DONE; /* see Note below */ } se = se->next; } - /* *) df_alloc must be set to ALLOC_DONE because the idf entry + /* Note: + df_alloc must be set to ALLOC_DONE because the idf entry may occur several times in the list. The reason for this is that the same name may be used - for different purposes on the same level, e.g + for different purposes on the same level, e.g. struct s {int s;} s; - is a legal definition and contains 3 defining occurrences of s. - Each definition has been entered into the idfstack. + is a legal definition and contains 3 defining occurrences + of s. + Each definition has been entered into the identifier stack. Although only one of them concerns a variable, we meet the - s 3 times when scanning the idfstack. + s 3 times when scanning the identifier stack. */ } diff --git a/lang/cem/cemcom/statement.g b/lang/cem/cemcom/statement.g index c2eb806f..62ce1b3a 100644 --- a/lang/cem/cemcom/statement.g +++ b/lang/cem/cemcom/statement.g @@ -153,7 +153,7 @@ while_statement : WHILE { - stat_stack(l_break, l_continue); + stack_stmt(l_break, l_continue); C_df_ilb(l_continue); } '(' @@ -175,7 +175,7 @@ while_statement { C_bra(l_continue); C_df_ilb(l_break); - stat_unstack(); + unstack_stmt(); free_expression(expr); } ; @@ -189,7 +189,7 @@ do_statement : DO { C_df_ilb(l_body); - stat_stack(l_break, l_continue); + stack_stmt(l_break, l_continue); } statement WHILE @@ -212,7 +212,7 @@ do_statement ')' ';' { - stat_unstack(); + unstack_stmt(); free_expression(expr); } ; @@ -226,7 +226,7 @@ for_statement } : FOR - { stat_stack(l_break, l_continue); + { stack_stmt(l_break, l_continue); } '(' [ @@ -263,7 +263,7 @@ for_statement NO_LABEL, NO_LABEL); C_bra(l_test); C_df_ilb(l_break); - stat_unstack(); + unstack_stmt(); free_expression(e_init); free_expression(e_test); free_expression(e_incr); @@ -317,20 +317,14 @@ default_statement break_statement : BREAK - { - if (!do_break()) - error("invalid break"); - } + {code_break();} ';' ; continue_statement : CONTINUE - { - if (!do_continue()) - error("invalid continue"); - } + {code_continue();} ';' ; diff --git a/lang/cem/cemcom/storage.c b/lang/cem/cemcom/storage.c index 3bae164b..1477f712 100644 --- a/lang/cem/cemcom/storage.c +++ b/lang/cem/cemcom/storage.c @@ -21,7 +21,7 @@ struct xxx { }; char * -st_alloc(phead, size) +head_alloc(phead, size) char **phead; int size; { diff --git a/lang/cem/cemcom/storage.h b/lang/cem/cemcom/storage.h index 73b024b4..8eec8214 100644 --- a/lang/cem/cemcom/storage.h +++ b/lang/cem/cemcom/storage.h @@ -1,9 +1,23 @@ /* $Header$ */ /* S T R U C T U R E - S T O R A G E D E F I N I T I O N S */ +/* Storage allocation is one of the most expensive operations in + the compiler and consequently much thought and experimentation + has gone into it. To simplify the hooking in of new super-fancy + algorithms, all allocating and freeing of storage for structs + goes through the macros + st_alloc(&head, size) + st_free(ptr, head, size) + which, hopefully, convey enough information. +*/ + +extern char *head_alloc(); + +#define st_alloc(headp, size) head_alloc((char **)headp, size) + #ifndef BOTCH_FREE -#define st_free(ptr, head, size) {ptr->next = head; head = ptr;} +#define st_free(ptr, head, size) (ptr->next = head, head = ptr) #else def BOTCH_FREE -#define st_free(ptr, head, size) {botch((char *)(ptr), size); \ - ptr->next = head; head = ptr;} +#define st_free(ptr, head, size) (botch((char *)(ptr), size), \ + ptr->next = head, head = ptr) #endif BOTCH_FREE diff --git a/lang/cem/cemcom/struct.str b/lang/cem/cemcom/struct.str index ccd3eaa7..9c3c51f1 100644 --- a/lang/cem/cemcom/struct.str +++ b/lang/cem/cemcom/struct.str @@ -11,8 +11,6 @@ struct sdef { /* for selectors */ arith sd_offset; }; -extern char *st_alloc(); - /* ALLOCDEF "sdef" */ struct tag { /* for struct-, union- and enum tags */ diff --git a/lang/cem/cemcom/switch.c b/lang/cem/cemcom/switch.c index acc44e89..30fd0abe 100644 --- a/lang/cem/cemcom/switch.c +++ b/lang/cem/cemcom/switch.c @@ -55,7 +55,7 @@ code_startswitch(expr) break; } - stat_stack(l_break, NO_LABEL); + stack_stmt(l_break, NO_LABEL); sh->sh_break = l_break; sh->sh_default = 0; sh->sh_table = l_table; @@ -123,7 +123,7 @@ code_endswitch() ce = tmp; } free_switch_hdr(sh); - stat_unstack(); + unstack_stmt(); } code_case(expr) diff --git a/lang/cem/cemcom/type.c b/lang/cem/cemcom/type.c index 7ca93399..c68c6687 100644 --- a/lang/cem/cemcom/type.c +++ b/lang/cem/cemcom/type.c @@ -10,6 +10,7 @@ #include "def.h" #include "sizes.h" #include "align.h" +#include "storage.h" struct type *function_of(), *array_of(); #ifndef NOBITFIELD From 21669f85edfd016ec2e42a99eb7c638193bf5dd6 Mon Sep 17 00:00:00 2001 From: dick Date: Fri, 18 Jul 1986 22:23:23 +0000 Subject: [PATCH 0217/1625] some leaks plugged (as detected by the leak detector) --- lang/cem/cemcom/stmt.str | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 lang/cem/cemcom/stmt.str diff --git a/lang/cem/cemcom/stmt.str b/lang/cem/cemcom/stmt.str new file mode 100644 index 00000000..7a79df97 --- /dev/null +++ b/lang/cem/cemcom/stmt.str @@ -0,0 +1,10 @@ +/* $Header$ */ +/* S T A T E M E N T - B L O C K D E F I N I T I O N S */ + +struct stmt_block { + struct stmt_block *next; + label st_break; + label st_continue; +}; + +/* ALLOCDEF "stmt_block" */ From de31476ed6da259cc080d5ab2db8980f8362707f Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 21 Jul 1986 09:23:39 +0000 Subject: [PATCH 0218/1625] Temporary variables are no longer overlapping. The operlapping caused problems with register variables. Also, code is added to prevent the generation of static exchanges. only included if the preprocessor-constant NO_EXC is defined. --- lang/pc/pem/pem.p | 230 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 186 insertions(+), 44 deletions(-) diff --git a/lang/pc/pem/pem.p b/lang/pc/pem/pem.p index 9c4472fd..c03bf413 100644 --- a/lang/pc/pem/pem.p +++ b/lang/pc/pem/pem.p @@ -25,6 +25,9 @@ {if next line is included the compiler itself is written in standard pascal} {#define STANDARD 1} +{if next line is included, the compiler won't generate static exchanges} +#define NO_EXC 1 + {Author: Johan Stevenson Version: 32} {$l- : no source line numbers} {$r- : no subrange checking} @@ -33,7 +36,7 @@ {$s+ : test conformancy to standard} #endif -program pem(input,em,errors); +program pem(input,output,em,errors); {/* This Pascal compiler produces EM code as described in - A.S.Tanenbaum, J.W.Stevenson & H. van Staveren, @@ -165,6 +168,10 @@ type lp= ^labl; bp= ^blockinfo; np= ^nameinfo; +#ifdef NO_EXC + mp= ^mmark; + op= ^outrec; +#endif NO_EXC {set types} sos= set of symbol; @@ -293,6 +300,18 @@ type otherwise dlbno of label information} end; +#ifdef NO_EXC + outrec=record + next:op; {chain of records} + bytes:array[1..16] of byte; + cnt:0..16; + end; + + mmark=record + next:mp; {chain of marks} + count,where:integer; + end; +#endif NO_EXC {-------------------------------------------------------------------} var {the most frequent used externals are declared first} sy:symbol; {last symbol} @@ -369,6 +388,16 @@ var {the most frequent used externals are declared first} em:file of byte; {the EM code} errors:text; {the compilation errors} source:fnarr; +#ifdef NO_EXC + ohead: op; {head of outrec list} + mhead: mp; {head of marks list} + bcnt: integer; +#define newmark setmark +#define relmark(xx) freemark(xx) +#else not NO_EXC +#define newmark lino +#define relmark(xx) +#endif NO_EXC {===================================================================} @@ -443,8 +472,29 @@ begin if fsp=nil then formof:=false else formof:=fsp^.form in forms end; {===================================================================} +#ifdef NO_EXC +procedure newoutrec; +var p:op; +begin + new(p); + bcnt := bcnt+1; + with p^ do begin cnt := 0; next := ohead end; + ohead := p +end; + +procedure put1(b:byte); +begin + if mhead = nil then write(em,b) + else begin + if ohead^.cnt = 16 then newoutrec; + with ohead^ do + begin cnt := cnt + 1; bytes[cnt] := b end + end +end; +#else not NO_EXC procedure put1(b:byte); begin write(em,b) end; +#endif NO_EXC procedure put2(i:integer); var i1,i2:byte; @@ -534,12 +584,81 @@ end; procedure laedlb(d:integer); begin genop(op_lae); argdlb(d) end; +#ifdef NO_EXC +procedure reloutrec; +var i,j,k:integer; + q, r, p:op; + m : mp; +begin p := ohead; q := p; + if mhead <> nil then + begin + m := mhead; while m^.next <> nil do m := m^.next; + k := (bcnt - m^.where) + 1 + end + else begin k := 0; ohead := nil; bcnt := 0 end; + for i := 1 to k do begin q := p; p := p^.next end; + if q <> p then q^.next := nil; + if p <> nil then + begin r := nil; + while p <> nil do + begin q := p^.next; p^.next := r; r := p; p := q end; + while r <> nil do with r^ do + begin + for j := 1 to cnt do write(em, bytes[j]); + r := next + end + end +end; + +function setmark:integer; +var p:mp; nm:boolean; +begin nm := false; + if mhead <> nil then with mhead^ do + if (where = bcnt) and (ohead^.cnt = 0) then + begin count := count + 1; nm := true end; + if not nm then + begin new(p); newoutrec; + with p^ do + begin where := bcnt; count := 1; next := mhead end; + mhead := p; + end; + setmark := bcnt +end; + +procedure freemark(m : integer); +var p, q : mp; +begin assert(mhead <> nil); p := mhead; q := p; + while p^.where <> m do + begin q := p; p := p^.next; assert(p <> nil) end; + with p^ do + begin assert(count > 0); count := count - 1; if count = 0 then + begin + if p = mhead then begin mhead := next; reloutrec end + else q^.next := next + end +end end; + +procedure exchange(n,m:integer); +var i:integer; + p,q,r:op; +begin assert(m >= n); + if n <> m then + begin + p := ohead; + for i := bcnt downto m+1 do p := p^.next; + q := p; + for i := m downto n+1 do q := q^.next; + r := ohead; ohead := p^.next; p^.next := q^.next; q^.next := r + end +end; +#else not NO_EXC procedure exchange(l1,l2:integer); var d1,d2:integer; begin d1:=l2-l1; d2:=lino-l2; if (d1<>0) and (d2<>0) then begin gencst(ps_exc,d1); argcst(d2) end end; +#endif NO_EXC procedure newilb(i:integer); begin lino:=lino+1; @@ -1881,7 +2000,7 @@ end; procedure callnonstandard(fsys:sos; moreargs:boolean; fip:ip); var nxt,lip:ip; l0,l1,l2,l3,sz:integer; lsp,savasp:sp; begin with a do begin - l0:=lino; l1:=l0; sz:=0; nxt:=fip^.parhead; + l0:=newmark; l1:=newmark; sz:=0; nxt:=fip^.parhead; while moreargs do begin if nxt=nil then @@ -1914,22 +2033,27 @@ begin with a do begin else {call by reference} begin variable(fsys); loadaddr; sz:=sz+sz_addr; if samesect in nxt^.iflag then lsp:=savasp else - begin savasp:=asp; l2:=lino; + begin savasp:=asp; l2:=newmark; while formof(lsp,[carray]) and formof(asp,[arrays,carray]) do if (compat(lsp^.inxtype,asp^.inxtype) > subeq) or (lsp^.sflag<>asp^.sflag) then errasp(+0142) else - begin l3:=lino; descraddr(asp^.arpos); exchange(l2,l3); + begin l3:=newmark; descraddr(asp^.arpos); exchange(l2,l3); + relmark(l3); sz:=sz+sz_addr; asp:=asp^.aeltype; lsp:=lsp^.aeltype - end + end; + relmark(l2) end; if not eqstruct(asp,lsp) then errasp(+0143); if packbit then errasp(+0144); end; nxt:=nxt^.next end; - exchange(l0,l1); l1:=lino; moreargs:=find3(comma,fsys,+0145) + exchange(l0,l1); + relmark(l1); + l1:=newmark; moreargs:=find3(comma,fsys,+0145) end; + relmark(l0); relmark(l1); if nxt<>nil then error(+0146); inita(procptr,0); pos:=fip^.pfpos; if fip^.pfkind=formal then @@ -2004,12 +2128,12 @@ begin with a do begin end end; procedure callrw(fsys:sos; lpar,w,ln:boolean); -var l1,l2,errno:integer; ftype,lsp,fsp:sp; savlb:integer; m:libmnem; -begin with b do begin savlb:=reglb; ftype:=textptr; +var l1,l2,errno:integer; ftype,lsp,fsp:sp; (* savlb:integer;*) m:libmnem; +begin with b do begin (* savlb:=reglb; *) ftype:=textptr; inita(textptr,argv[ord(w)].ad); a.pos.lv:=0; fa:=a; if lpar then - begin l1:=lino; if w then expression(fsys+[colon1]) else variable(fsys); - l2:=lino; + begin l1:=newmark; if w then expression(fsys+[colon1]) else variable(fsys); + l2:=newmark; if formof(a.asp,[files]) then begin ftype:=a.asp; if (a.ak<>fixed) and (a.ak<>pfixed) then @@ -2023,22 +2147,24 @@ begin with b do begin savlb:=reglb; ftype:=textptr; begin if iop[w]=nil then error(+0155); if w then callw(fsys,l1,l2) else callr(l1,l2) end; + relmark(l1); relmark(l2); while find3(comma,fsys,+0156) do with a do - begin l1:=lino; + begin l1:=newmark; if w then expression(fsys+[colon1]) else variable(fsys); - l2:=lino; + l2:=newmark; if ftype=textptr then if w then callw(fsys,l1,l2) else callr(l1,l2) else begin errno:=+0157; fsp:=ftype^.filtype; if w then force(fsp,errno) else - begin store; lsp:=asp; l2:=lino end; + begin store; lsp:=asp; relmark(l2); l2 := newmark end; fileaddr; gensp(WDW,sz_addr); gencst(op_lfr,sz_addr); ak:=ploaded; packbit:=true; asp:=fsp; if w then store else begin force(lsp,errno); exchange(l1,l2) end; fileaddr; if w then m:=PUTX else m:=GETX; gensp(m,sz_addr) - end + end; + relmark(l1); relmark(l2); end; end else @@ -2048,7 +2174,7 @@ begin with b do begin savlb:=reglb; ftype:=textptr; begin if ftype<>textptr then error(+0160); fileaddr; if w then m:=WLN else m:=RLN; gensp(m,sz_addr) end; - reglb:=savlb + (* reglb:=savlb *) end end; procedure callnd(fsys:sos); @@ -2221,8 +2347,8 @@ begin with a do begin asp:=desub(asp); es: expandnullset(fsp); li,ri,rl,se: - begin l2:=lino; lsp:=asp; asp:=fsp; - convert(lsp,l1); exchange(l1,l2); asp:=lsp + begin l2:=newmark; lsp:=asp; asp:=fsp; + convert(lsp,l1); exchange(l1,l2); relmark(l2); asp:=lsp end; noteq: errasp(+0184); @@ -2279,7 +2405,7 @@ begin with a do begin {buildset} varpart:=false; ncst:=0; asp:=nullset; for i:=1 to ncsw do cstpart[i]:=[]; if find2([notsy..lparent],fsys,+0189) then - repeat l1:=lino; + repeat l1:=newmark; setexpr(fsys+[colon2,comma],cst1,val1); cst12:=cst1; if find3(colon2,fsys+[comma,notsy..lparent],+0190) then begin setexpr(fsys+[comma,notsy..lparent],cst2,val2); @@ -2288,8 +2414,11 @@ begin with a do begin {buildset} begin if cst2 then gencst(op_loc,val2); if cst1 then - begin l2:=lino; gencst(op_loc,val1); exchange(l1,l2) end; - l2:=lino; genasp(op_zer); exchange(l1,l2); + begin l2:=newmark; gencst(op_loc,val1); exchange(l1,l2); + relmark(l2); + end; + l2:=newmark; genasp(op_zer); exchange(l1,l2); + relmark(l2); genasp(op_loc); gensp(BTS,3*sz_word) end; end @@ -2302,6 +2431,7 @@ begin with a do begin {buildset} end else if varpart then genasp(op_ior) else varpart:=true; + relmark(l1); until endofloop(fsys,[notsy..lparent],comma,+0191); {+0192} ak:=loaded; if ncst>0 then @@ -2375,11 +2505,11 @@ end end; procedure term(fsys:sos); var lsy:symbol; lsp:sp; l1:integer; first:boolean; -begin with a,b do begin first:=true; l1:=lino; +begin with a,b do begin first:=true; factor(fsys+[starsy..andsy]); while find2([starsy..andsy],fsys,+0197) do begin if first then begin load; first:=false end; - lsy:=sy; insym; l1:=lino; lsp:=asp; + lsy:=sy; insym; l1:=newmark; lsp:=asp; factor(fsys+[starsy..andsy]); load; convert(lsp,l1); if asp<>nil then case lsy of @@ -2407,13 +2537,14 @@ begin with a,b do begin first:=true; l1:=lino; end; andsy: if asp=boolptr then genasp(op_and) else errasp(+0202); - end {case} + end; {case} + relmark(l1) end {while} end end; procedure simpleexpression(fsys:sos); var lsy:symbol; lsp:sp; l1:integer; signed,min,first:boolean; -begin with a do begin l1:=lino; first:=true; +begin with a do begin first:=true; signed:=(sy=plussy) or (sy=minsy); if signed then begin min:=sy=minsy; insym end else min:=false; term(fsys + [minsy,plussy,orsy]); lsp:=desub(asp); @@ -2424,7 +2555,7 @@ begin with a do begin l1:=lino; first:=true; begin load; first:=false; asp:=lsp; negate end; while find2([plussy,minsy,orsy],fsys,+0204) do begin if first then begin load; first:=false end; - lsy:=sy; insym; l1:=lino; lsp:=asp; + lsy:=sy; insym; l1:=newmark; lsp:=asp; term(fsys+[minsy,plussy,orsy]); load; convert(lsp,l1); if asp<>nil then case lsy of @@ -2439,16 +2570,17 @@ begin with a do begin l1:=lino; first:=true; else errasp(+0206); orsy: if asp=boolptr then genasp(op_ior) else errasp(+0207); - end {case} + end; {case} + relmark(l1) end {while} end end; procedure expression; { fsys:sos } var lsy:symbol; lsp:sp; l1,l2:integer; -begin with a do begin l1:=lino; +begin with a do begin l1:=newmark; simpleexpression(fsys+[eqsy..insy]); if find2([eqsy..insy],fsys,+0208) then - begin lsy:=sy; insym; lsp:=asp; loadcheap; l2:=lino; + begin lsy:=sy; insym; lsp:=asp; loadcheap; l2:=newmark; simpleexpression(fsys); loadcheap; if lsy=insy then begin @@ -2501,8 +2633,10 @@ begin with a do begin l1:=lino; eqsy: genop(op_teq) end end; + relmark(l2); asp:=boolptr; ak:=loaded end; + relmark(l1) end end; {===================================================================} @@ -2513,10 +2647,11 @@ procedure statement(fsys:sos); forward; procedure assignment(fsys:sos; fip:ip); var la:attr; l1,l2:integer; begin - l1:=lino; selector(fsys+[becomes],fip,[assigned]); l2:=lino; + l1:=newmark; selector(fsys+[becomes],fip,[assigned]); l2:=newmark; la:=a; nextif(becomes,+0216); expression(fsys); loadcheap; checkasp(la.asp,+0217); exchange(l1,l2); a:=la; + relmark(l1); relmark(l2); if not formof(la.asp,[arrays..records]) then store else begin loadaddr; if la.asp^.form<>carray then genasp(op_blm) else @@ -2588,7 +2723,7 @@ var lsp:sp; head,p,q,r:cip; l0,l1:integer; begin with b do begin expression(fsys+[ofsy,semicolon,ident..plussy]); lsp:=a.asp; load; if not nicescalar(desub(lsp)) then begin error(+0223); lsp:=nil end; - l0:=lino; ilbno:=ilbno+1; ilb1:=ilbno; + l0:=newmark; ilbno:=ilbno+1; ilb1:=ilbno; nextif(ofsy,+0224); head:=nil; max:=-MI2; min:=MI2; n:=0; repeat ilbno:=ilbno+1; ilb2:=ilbno; {label of current case} repeat i:=cstinteger(fsys+[comma,colon1,semicolon],lsp,+0225); @@ -2607,7 +2742,7 @@ begin with b do begin nextif(colon1,+0229); newilb(ilb2); statement(fsys+[semicolon]); gencst(op_bra,ilb1); until lastsemicolon(fsys,[ident..plussy],+0230); {+0231 +0232} - assert n<>0; newilb(ilb1); l1:=lino; + assert n<>0; newilb(ilb1); l1:=newmark; dlb:=newdlb; genop(ps_rom); argnil; if (max div 3) - (min div 3) < n then begin argcst(min); argcst(max-min); @@ -2624,7 +2759,8 @@ begin with b do begin while head<>nil do begin argcst(head^.cslab);argilb(head^.csstart);head:=head^.next end; end; - argend; laedlb(dlb); gencst(m,sz_word); exchange(l0,l1) + argend; laedlb(dlb); gencst(m,sz_word); exchange(l0,l1); + relmark(l0); relmark(l1) end end; procedure repeatstatement(fsys:sos); @@ -2648,7 +2784,7 @@ begin with b do begin end end; procedure forstatement(fsys:sos); -var lip:ip; tosym:boolean; endlab,looplab,savlb:integer; +var lip:ip; tosym:boolean; endlab,looplab(* ,savlb *):integer; av,at1,at2:attr; lsp:sp; procedure forbound(fsys:sos; var fa:attr; fsp:sp); @@ -2660,7 +2796,7 @@ begin end end; -begin with b do begin savlb:=reglb; tosym:=false; +begin with b do begin (* savlb:=reglb; *) tosym:=false; ilbno:=ilbno+1; looplab:=ilbno; ilbno:=ilbno+1; endlab:=ilbno; inita(nil,0); if sy<>ident then error(+0240) else @@ -2685,13 +2821,13 @@ begin with b do begin savlb:=reglb; tosym:=false; a:=av; load; if tosym then genop(op_inc) else genop(op_dec); a.asp:=lsp; checkbnds(av.asp); a:=av; store; gencst(op_bra,looplab); newilb(endlab); - reglb:=savlb + (* reglb:=savlb *) end end; procedure withstatement(fsys:sos); -var lnp,savtop:np; savlb:integer; pbit:boolean; +var lnp,savtop:np; (* savlb:integer; *) pbit:boolean; begin with b do begin - savlb:=reglb; savtop:=top; + (* savlb:=reglb;*) savtop:=top; repeat variable(fsys+[comma,dosy]); if not formof(a.asp,[records]) then errasp(+0247) else begin pbit:=spack in a.asp^.sflag; @@ -2704,7 +2840,7 @@ begin with b do begin end; until endofloop(fsys+[dosy],[ident],comma,+0248); {+0249} nextif(dosy,+0250); statement(fsys); - top:=savtop; reglb:=savlb; + top:=savtop; (* reglb:=savlb; *) end end; procedure assertion(fsys:sos); @@ -2773,7 +2909,7 @@ begin with b do begin {produce PRO} genpnam(ps_pro,fip); argend; gencst(ps_mes,ms_par);argcst(fip^.maxlb); argend; - l0:=lino; dlb:=0; trace('procentr',fip,dlb); + l0:=newmark; dlb:=0; trace('procentr',fip,dlb); {global labels} llp:=lchain; spset:=false; while llp<>nil do @@ -2804,7 +2940,7 @@ begin with b do begin {finish and close files} treewalk(top^.fname); if level=1 then - begin l1:=lino; + begin l1:=newmark; genop(op_fil); argdlb(fildlb); {temporarily} dlb:=newdlb; gencst(ps_con,argc+1); for i:=0 to argc do with argv[i] do @@ -2813,18 +2949,19 @@ begin with b do begin end; argend; gencst(op_lxl,0); laedlb(dlb); gencst(op_lae,0); gencst(op_lxa,0); gensp(INI,4*sz_addr); - exchange(l0,l1); gencst(op_loc,0); gensp(HLT,0) + exchange(l0,l1); relmark(l1); gencst(op_loc,0); gensp(HLT,0) end else begin inita(fip^.idtype,fip^.pfpos.ad); if fip^.klass=func then begin load; if not (assigned in fip^.iflag) then - errid(-(+0265),fip^.name); + errid(-(+0265),fip^.name) end; - genasp(op_ret); + genasp(op_ret) end; - gencst(ps_end,-minlb); + relmark(l0); + gencst(ps_end,-minlb) end end; {===================================================================} @@ -3014,6 +3151,11 @@ begin iop[true]:=nil; argv[0].ad:=-1; argv[1].ad:=-1; +#ifdef NO_EXC + ohead := nil; + bcnt := 0; + mhead := nil; +#endif NO_EXC end; procedure init2; From 1475b0fce3118dcd69005ee3e26d9e86e5fa5235 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 21 Jul 1986 09:30:11 +0000 Subject: [PATCH 0219/1625] This is the result of the merging of 2.5 with 2.4.1.1, with some minor fixes. --- lang/pc/pem/pem.p | 178 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 131 insertions(+), 47 deletions(-) diff --git a/lang/pc/pem/pem.p b/lang/pc/pem/pem.p index c03bf413..cf06c724 100644 --- a/lang/pc/pem/pem.p +++ b/lang/pc/pem/pem.p @@ -1,9 +1,9 @@ #include #include -#include -#include +#include +#include #include -#include +#include { (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. @@ -26,7 +26,7 @@ {#define STANDARD 1} {if next line is included, the compiler won't generate static exchanges} -#define NO_EXC 1 +{#define NO_EXC 1} {Author: Johan Stevenson Version: 32} {$l- : no source line numbers} @@ -43,8 +43,17 @@ program pem(input,output,em,errors); "Description of a machine architecture for use with block structured languages" Informatika rapport 81. NOTE: this version is modified to produce the modified EM code of - januari 1981. it is not possible, using this compiler, to generate - code for machines with 1 or 4 byte wordsize. + januari 1981. it is not possible, using this compiler, to + generate code for machines with 1 byte wordsize. + NOTE: this version is modified by Kees Visser in such a way that + the compiler can now run on 2 and 4 byte machines. It is also + able to generate em-code for a 2 bytes machine while running + on a 4-bytes machine. Cross-compilation from a 2 bytes to a + four bytes machine is also possible with the following + exception: large integers that don't fit in an integer of + the compiler are treated like longs and are thus not allowed + in types. + A description of Pascal is given in - K.Jensen & N.Wirth, "PASCAL user manual and report", Springer-Verlag. Several options may be given in the normal pascal way. Moreover, @@ -52,7 +61,8 @@ program pem(input,output,em,errors); a: interpret assertions (+) c: C-type strings allowed (-) d: type long may be used (-) - i: controls the number of bits in integer sets (16) + i: controls the number of elements in integer sets + default: (wordsize in bits) l: insert code to keep track of source lines (+) o: optimize (+) r: check subranges (+) @@ -67,14 +77,38 @@ label 9999; const {fundamental constants} - MB1 = 7; MB2 = 15; {MB4 = 31} - NB1 = 8; NB2 = 16; {NB4 = 32} + MB1 = 7; + NB1 = 8; + MI2 = 32767; + MU1 = 255; + NU1 = 256; - MI1 = 127; MI2 = 32767; {MI4 = 2147483647} - NI1 = 128; {NI2 = 32768} {NI4 = 2147483648} +{string constants} + imax = 10; + max2bytes = '0000032767'; + max4bytes = '2147483647'; + wordsize = EM_WSIZE; - MU1 = 255; {MU2 = 65535} {MU4 = 4294967295} - NU1 = 256; {NU2 = 65536} {NU4 = 4294967296} +#if EM_WSIZE == 4 + {this can only be compiled with a compiler that has integer size 4} + MU2 = 65535; + NU2 = 65536; + + {characteristics of the machine on which the compiler will run} + {wordsize and integer size are 4} + MI = 2147483647; + maxcompintstring = max4bytes; +#endif +#if EM_WSIZE == 2 + MU2 = 0; {not used} + NU2 = 0; {not used} + + MI = MI2; + maxcompintstring = max2bytes; +#endif +#if EM_WSIZE != 2 && EM_WSIZE != 4 +Something wrong here! +#endif {maximal indices} idmax = 8; @@ -361,6 +395,7 @@ var {the most frequent used externals are declared first} fa:attr; {attr for current file name} {arrays} sizes:array[0 .. sz_last] of integer; + maxintstring,maxlongstring:packed array[1..imax] of char; strbuf:array[1..smax] of char; rw:array[rwrange] of idarr; {reserved words} @@ -506,15 +541,27 @@ begin put1(i1); put1(i2) end; +procedure put4(i:integer); +var i1,i2:integer; +begin + if i<0 then + begin i:=-(i+1); i1:=MU2 - i mod NU2; i2:=MU2 - i div NU2 end + else + begin i1:=i mod NU2; i2:=i div NU2 end; + put1(i1 mod NU1); put1(i1 div NU1); + put1(i2 mod NU1); put1(i2 div NU1) +end; + procedure argend; begin put1(sp_cend) end; procedure argcst(i:integer); begin if (i >= -sp_zcst0) and (i < sp_ncst0-sp_zcst0) then - put1(i + sp_zcst0 + sp_fcst0) - else - begin put1(sp_cst2); put2(i) end + put1(i + sp_zcst0 + sp_fcst0) + else if (i >= -MI2-1) and (i <= MI2) then + begin put1(sp_cst2); put2(i) end + else begin put1(sp_cst4); put4(i) end end; procedure argnil; @@ -850,7 +897,8 @@ begin if formof(a.asp,[arrays..records]) then loadaddr else load end; procedure nextch; begin - eol:=eoln(input); read(input,ch); srcchno:=srcchno+1; chsy:=cs[ch]; + eol:=eoln(input); read(input,ch); chsy:=cs[ch]; + if chsy <> tabch then srcchno:=srcchno+1 end; procedure nextln; @@ -934,9 +982,6 @@ end; procedure innumber; label 1; -const imax = 10; - maxintstring = '0000032767'; - maxlongstring = '2147483647'; var i,j:integer; is:packed array[1..imax] of char; begin ix:=0; sy:=intcst; val:=0; @@ -964,7 +1009,7 @@ begin ix:=0; sy:=intcst; val:=0; if ix>imax then error(+08) else begin is:='0000000000'; i:=ix; j:=imax; repeat is[j]:=strbuf[i]; j:=j-1; i:=i-1 until i=0; - if is<=maxintstring then + if (is<=maxintstring) and (is<=maxcompintstring) then repeat j:=j+1; val:=val*10 - ord('0') + ord(is[j]) until j=imax else if (is<=maxlongstring) and (dopt<>off) then begin sy:=longcst; val:=romstr(sp_icon,sz_long) end @@ -1307,7 +1352,8 @@ end; function posaddr(var lb:integer; fsp:sp; partword:boolean):integer; var sz:integer; begin sz:=sizeof(fsp,partword); - if lb >= MI2-sz then begin error(+016); lb:=0 end; + if sz_int = 2 then + if lb >= MI2-sz-sz_word then begin error(+016); lb:=0 end; if not partword or (sz>=sz_word) then while lb mod sz_word <> 0 do lb:=lb+1; posaddr:=lb; @@ -1318,7 +1364,8 @@ function negaddr(fsp:sp):integer; var sz:integer; begin with b do begin sz:=sizeof(fsp,wordmult); - if reglb <= -MI2+sz then begin error(+017); reglb:=0 end; + if sz_int = 2 then + if reglb <= -MI2+sz+sz_word then begin error(+017); reglb:=0 end; reglb:=reglb-sz; while reglb mod sz_word <> 0 do reglb:=reglb-1; if reglb < minlb then minlb:=reglb; @@ -1332,7 +1379,10 @@ end; procedure genhol; begin gencst(ps_hol,posaddr(holeb,nil,false)); - argcst(-MI2-1); argcst(0); level:=1 + if sz_word = 4 then begin put1(sp_cst4); put1(0); put1(0); end + else put1(sp_cst2); + put1(0); put1(128); { 1000000000000000 pattern} + argcst(0); level:=1 end; function arraysize(fsp:sp; pack:boolean):integer; @@ -1715,8 +1765,9 @@ begin fwptr:=nil; intypedec:=true; nextif(semicolon,+093); enterid(lip); end; until not find2([ident],fsys,+094); + assert sy<>ident; while fwptr<>nil do - begin assert sy<>ident; + begin id:=fwptr^.name; lip:=searchid([types]); fwptr^.idtype^.eltype:=lip^.idtype; fwptr:=fwptr^.next end; @@ -1725,7 +1776,7 @@ end; procedure vardeclaration(fsys:sos); var lip,hip,vip:ip; lsp:sp; -begin with b do begin +begin repeat hip:=nil; lip:=nil; repeat vip:=newident(vars,nil,nil,+095); if vip<>nil then @@ -1745,7 +1796,7 @@ begin with b do begin end; nextif(semicolon,+099); until not find2([ident],fsys,+0100); -end end; +end; procedure pfhead(fsys:sos;var fip:ip;var again:boolean;param:boolean); forward; @@ -2361,21 +2412,41 @@ procedure buildset(fsys:sos); - expr..expr very difficult to implement on most machines - this construct makes it hard to implement sets of different size } -const ncsw = 16; {tunable} -type wordset = set of 0..MB2; +const ncsb = 32; {tunable} +type byteset = set of 0..MB1; var i,j,val1,val2,ncst,l1,l2,sz:integer; cst1,cst2,cst12,varpart:boolean; - cstpart:array[1..ncsw] of wordset; + cstpart:array[1..ncsb] of byteset; -procedure genwordset(s:wordset); +procedure genconstset(sz:integer); {level 2: << buildset} -var b,i,w:integer; -begin i:=0; w:=0; b:=-1; +var i,j:integer; + +function setcode(s:byteset):byte; + {level 3: << buildset} +var b,i,w:byte; +begin i:=0; w:=0; b:=1; + for i:=0 to MB1 do + begin if i in s then w:=w+b; b:=b+b end; + setcode := w; +end; + +begin + i:=sz; repeat - if i in s then w:=w-b; b:=b+b; i:=i+1 - until i=MB2; - if i in s then w:=w+b; - gencst(op_loc,w) + genop(op_loc); j:=i; i:=i-sz_word; + + {the bytes of the next word to be loaded on the stack} + {are in cstpart[i+1] .. cstpart[j]} + while (cstpart[j] = []) and (j > i+1) do j:=j-1; + if j = i+1 then argcst(setcode(cstpart[j])) + else + begin + if j = i+2 then put1(sp_cst2) + else begin j:=i+4; put1(sp_cst4) end; + for j:=i+1 to j do put1(setcode(cstpart[j])) + end; + until i = 0; end; procedure setexpr(fsys:sos; var c:boolean; var v:integer); @@ -2396,14 +2467,14 @@ begin with a do begin c:=false; v:=0; lsp:=asp; if asp<>nil then if ak=cst then if (pos.ad<0) or (pos.ad div NB1>=sizeof(lsp,wordmult)) then error(+0188) - else if sz<=ncsw*sz_word then + else if sz<=ncsb*sz_byte then begin c:=true; v:=pos.ad end; if not c then load; asp:=lsp end end; begin with a do begin {buildset} varpart:=false; ncst:=0; asp:=nullset; - for i:=1 to ncsw do cstpart[i]:=[]; + for i:=1 to ncsb do cstpart[i]:=[]; if find2([notsy..lparent],fsys,+0189) then repeat l1:=newmark; setexpr(fsys+[colon2,comma],cst1,val1); cst12:=cst1; @@ -2426,8 +2497,8 @@ begin with a do begin {buildset} if cst12 then val2:=val1 else genasp(op_set); if cst12 then for i:=val1 to val2 do - begin j:=i div NB2 + 1; ncst:=ncst+1; - cstpart[j]:=cstpart[j] + [i mod NB2] + begin j:=i div NB1 + 1; ncst:=ncst+1; + cstpart[j]:=cstpart[j] + [i mod NB1] end else if varpart then genasp(op_ior) else varpart:=true; @@ -2436,8 +2507,7 @@ begin with a do begin {buildset} ak:=loaded; if ncst>0 then begin - for i:=sizeof(asp,wordmult) div sz_word downto 1 do - genwordset(cstpart[i]); + genconstset(sizeof(asp,wordmult)); if varpart then genasp(op_ior); end else @@ -2655,7 +2725,7 @@ begin if not formof(la.asp,[arrays..records]) then store else begin loadaddr; if la.asp^.form<>carray then genasp(op_blm) else - begin descraddr(la.asp^.arpos); gensp(ASZ,2*sz_addr); + begin descraddr(la.asp^.arpos); gensp(ASZ,sz_addr); gencst(op_lfr,sz_word); gencst(op_bls,sz_word) end; end; @@ -2724,7 +2794,7 @@ begin with b do begin expression(fsys+[ofsy,semicolon,ident..plussy]); lsp:=a.asp; load; if not nicescalar(desub(lsp)) then begin error(+0223); lsp:=nil end; l0:=newmark; ilbno:=ilbno+1; ilb1:=ilbno; - nextif(ofsy,+0224); head:=nil; max:=-MI2; min:=MI2; n:=0; + nextif(ofsy,+0224); head:=nil; max:=-MI; min:=MI; n:=0; repeat ilbno:=ilbno+1; ilb2:=ilbno; {label of current case} repeat i:=cstinteger(fsys+[comma,colon1,semicolon],lsp,+0225); if i>max then max:=i; if ioff then begin copt:=off; dopt:=off end From 3d0bf5c9a42d0c85a4fe359fb5f5291a8dd66d0c Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 21 Jul 1986 09:40:20 +0000 Subject: [PATCH 0220/1625] Added instructions to make pem44.m --- lang/pc/pem/Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lang/pc/pem/Makefile b/lang/pc/pem/Makefile index 9fde59b4..89953c4a 100644 --- a/lang/pc/pem/Makefile +++ b/lang/pc/pem/Makefile @@ -40,6 +40,9 @@ distr: apc -mpdp -c.m -I$h pem22.p ; rm -f pem22.p rm -f pem24.p ; ln pem.p pem24.p apc -mvax2 -c.m -I$h pem24.p ; rm -f pem24.p + rm -f pem44.p ; ln pem.p pem44.p + apc -mvax4 -c.m -I$h pem44.p ; rm -f pem44.p + clean: -rm -f pem pem.out *.[os] *.old From e706b3cdba5240a41723cfaf0231db8cf449a440 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 21 Jul 1986 09:53:44 +0000 Subject: [PATCH 0221/1625] Some changes needed for the new 4-4 Pascal compiler. --- util/ack/pc/em_pc.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/util/ack/pc/em_pc.c b/util/ack/pc/em_pc.c index 921e7472..ffda726d 100644 --- a/util/ack/pc/em_pc.c +++ b/util/ack/pc/em_pc.c @@ -49,12 +49,15 @@ char *eflag; char *wflag; int sizes[sz_last+1] = { - 2, /* sz_addr */ + 4, /* sz_addr */ 8, /* sz_real */ 0, /* sz_head */ 512, /* sz_buff */ 4096, /* sz_mset */ - 2, /* sz_iset */ + 4, /* sz_iset */ + 4, /* sz_word */ + 4, /* sz_int */ + 4, /* sz_long */ }; #define CALLSIZE 60 @@ -193,12 +196,17 @@ initsizes(f) FILE *f; { case 'b': sz_buff = i; continue; case 'm': sz_mset = i; continue; case 'j': sz_iset = i; continue; - case 'w': - case 'i': if (i == 2) continue; break; - case 'l': if (i == 4) continue; break; + case 'w': sz_word = i; continue; + case 'i': sz_int = i; continue; + case 'l': sz_long = i; continue; } fatal("bad V-flag %s",vvflag); } + if (sz_word != sz_int || + (sz_int != 2 && sz_int != 4) || + (sz_long != 4)) { + fatal("bad V-flag %s",vvflag); + } if (sz_head == 0) sz_head = 6*sz_word + 2*sz_addr; for (i = 0; i <= sz_last; i++) From f2d12c347f1782df6385b49e0122d37fcadeb1bf Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 21 Jul 1986 09:58:19 +0000 Subject: [PATCH 0222/1625] Added -Vi... flag to Pascal compiler options. --- lib/descr/fe.src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/descr/fe.src b/lib/descr/fe.src index d1d0a1cc..0713481f 100644 --- a/lib/descr/fe.src +++ b/lib/descr/fe.src @@ -42,7 +42,7 @@ name pc mapflag -L PC_F={PC_F?} -\{l-} mapflag -Pr* PC_ERRPATH=* mapflag -PR* PC_PCPATH=* - args -Vw{w}p{p}f{d}l{l} -R{PC_PCPATH} -r{PC_ERRPATH} {PC_F?} < > {SOURCE} + args -Vw{w}i{w}p{p}f{d}l{l} -R{PC_PCPATH} -r{PC_ERRPATH} {PC_F?} < > {SOURCE} prep cond rts .p need .p From 6bff676201fc7403312ce993983fa2f47e0db232 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 21 Jul 1986 12:26:38 +0000 Subject: [PATCH 0223/1625] Added code to use different integer constants when compiled with word_size >= 4. --- lang/pc/test/t1.p | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/lang/pc/test/t1.p b/lang/pc/test/t1.p index 2a911615..f9fe87ee 100644 --- a/lang/pc/test/t1.p +++ b/lang/pc/test/t1.p @@ -34,7 +34,11 @@ const type wavelength = (red,blue,yellow,purple,white,gray,pink,black,fuchia,maple, violet,darkred,darkblue,darkyellow,darkwhite,darkpink,darkblack); +#if EM_WSIZE < 4 ww2= 1939..1945; +#else + ww2= 1000939..1000945; +#endif #ifndef NOFLOAT tp2= record c1:char; i,j:integer; p:boolean; x:real end; #else @@ -52,7 +56,11 @@ var t,pct,ect:integer; #endif p,q,r:boolean; c1,c2,c3:char; +#if EM_WSIZE < 4 sr1,sr2,sr3: 1939..1945; +#else + sr1,sr2,sr3: 1000939..1000945; +#endif bar: packed array[0..3] of 0..255; color,hue,tint: wavelength; grat:spectrum; @@ -115,7 +123,11 @@ begin t:=1; pct := pct + 1; if -3 div 2 <> -1 then e(15); if ((1+2+3) * (2+3+4) * (3+5+5)) div 2 <> ((3 * ((5+3+2)*10)+51)*6) div 6 then e(16); +#if EM_WSIZE < 4 if (1000*2 + 5*7 + 13) div 8 <> 2*2*2*2*4*4 then e(17); +#else + if (1000*2 + 5*7 + 13) * 128 div 8 <> 2*2*2*2*4*4*128 then e(17); +#endif if (1 * 2 * 3 * 4 * 5 * 6 * 7) div 5040 <> 5040 div 7 div 6 div 5 div 4 div 3 div 2 then e(18); if -(-(-(-(-(-(-(-(-(1))))))))) <> -1 then e(19); @@ -232,7 +244,11 @@ begin t:=5; pct := pct + 1; if c1 = c2 then e(2); if c1 <> c3 then e(3); +#if EM_WSIZE < 4 sr1:=1939; sr2:=1945; sr3:=1939; +#else + sr1:=1000939; sr2:=1000945; sr3:=1000939; +#endif if sr1=sr2 then e(4); if sr1<>sr3 then e(5); @@ -251,8 +267,13 @@ begin t:=6; pct := pct + 1; if (a1[-10]<>100) or (a1[9]<>81) then e(1); #ifndef NOFLOAT +#if EM_WSIZE < 4 for i:=1939 to 1945 do a2[i]:=i-1938.5; if (abs(a2[1939]-0.5) > eps) or (abs(a2[1945]-6.5) > eps) then e(2); +#else + for i:=1000939 to 1000945 do a2[i]:=i-1000938.5; + if (abs(a2[1000939]-0.5) > eps) or (abs(a2[1000945]-6.5) > eps) then e(2); +#endif #endif color := yellow; @@ -264,10 +285,17 @@ begin t:=6; pct := pct + 1; a4[mouse]:='m'; a4[house]:='h'; if (a4[mouse] <> 'm') or (a4[house]<>'h' ) then e(5); +#if EM_WSIZE < 4 for i:=1939 to 1945 do a5[51,bat,false,i]:=300+i; if a5[51,bat,false,1940] <> 2240 then e(6); for i:=50 to 52 do a5[i,cat,true,1943]:=200+i; if (a5[50,cat,true,1943] <> 250) or (a5[52,cat,true,1943] <> 252) then e(7); +#else + for i:=1000939 to 1000945 do a5[51,bat,false,i]:=300+i; + if a5[51,bat,false,1000940] <> 1001240 then e(6); + for i:=50 to 52 do a5[i,cat,true,1000943]:=200+i; + if (a5[50,cat,true,1000943] <> 250) or (a5[52,cat,true,1000943] <> 252) then e(7); +#endif for i:= -10 to 10 do a1[i]:= 0; for i:= 0 to 10 do a1[i div 2 + i div 2]:= i+1; @@ -360,8 +388,13 @@ procedure tst9; { Global pointers } begin t:=9; pct := pct + 1; new(p1); new(p2); new(p3); new(p4); +#if EM_WSIZE < 4 p1^ := 1066; if p1^ <> 1066 then e(1); +#else + p1^ := 1000066; + if p1^ <> 1000066 then e(1); +#endif p2^.i := 1215; if p2^.i <> 1215 then e(2); p3^[0]:= 1566; @@ -460,7 +493,11 @@ end; procedure tst14; { Characters, Subranges, Enumerated types using locals } var cc1,cc2,cc3:char; +#if EM_WSIZE < 4 sr1,sr2,sr3: 1939..1945; +#else + sr1,sr2,sr3: 1000939..1000945; +#endif color,hue,tint: (ochre,magenta); begin t:=14; pct := pct + 1; if 'q' <> kew then e(1); @@ -468,7 +505,11 @@ end; if cc1 = cc2 then e(2); if cc1 <> cc3 then e(3); +#if EM_WSIZE < 4 sr1:=1939; sr2:=1945; sr3:=1939; +#else + sr1:=1000939; sr2:=1000945; sr3:=1000939; +#endif if sr1=sr2 then e(4); if sr1<>sr3 then e(5); bar[0]:=200; bar[1]:=255; bar[2]:=255; bar[3]:=203; @@ -498,8 +539,13 @@ end; if (aa1[-10]<>100) or (aa1[9]<>81) then e(1); #ifndef NOFLOAT +#if EM_WSIZE < 4 for i:=1939 to 1945 do aa2[i]:=i-1938.5; if (abs(aa2[1939]-0.5) > eps) or (abs(aa2[1945]-6.5) > eps) then e(2); +#else + for i:=1000939 to 1000945 do aa2[i]:=i-1000938.5; + if (abs(aa2[1000939]-0.5) > eps) or (abs(aa2[1000945]-6.5) > eps) then e(2); +#endif #endif aa3[magenta] := true; aa3[ochre] := true; @@ -510,10 +556,17 @@ end; aa4[mouse]:='m'; aa4[house]:='h'; aa4[louse]:='l'; if (aa4[mouse] <> 'm') or (aa4[house]<>'h' ) or (aa4[louse]<>'l') then e(5); +#if EM_WSIZE < 4 for i:=1939 to 1945 do aa5[51,bat,false,i]:=300+i; if aa5[51,bat,false,1940] <> 2240 then e(6); for i:=50 to 52 do aa5[i,cat,true,1943]:=200+i; if (aa5[50,cat,true,1943] <> 250) or (aa5[52,cat,true,1943] <> 252) then e(7); +#else + for i:=1000939 to 1000945 do aa5[51,bat,false,i]:=300+i; + if aa5[51,bat,false,1000940] <> 1001240 then e(6); + for i:=50 to 52 do aa5[i,cat,true,1000943]:=200+i; + if (aa5[50,cat,true,1000943] <> 250) or (aa5[52,cat,true,1000943] <> 252) then e(7); +#endif for i:= -10 to 10 do aa1[i]:= 0; for i:= 0 to 10 do aa1[i div 2 + i div 2]:= i+1; From 36a255a5cf17b414e55f363b8339c2db243b0415 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 22 Jul 1986 10:36:04 +0000 Subject: [PATCH 0224/1625] Changed default machine to "vax4". --- first/local.h.src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/first/local.h.src b/first/local.h.src index 439d62dc..37ec5d75 100644 --- a/first/local.h.src +++ b/first/local.h.src @@ -4,4 +4,4 @@ # define VERSION 3 /* 16 bits number */ /* The default machine used by ack, acc, apc */ -# define ACKM "vax2" +# define ACKM "vax4" From 7e94756b303a82425c76d799e32312e4b450d85c Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 22 Jul 1986 10:47:51 +0000 Subject: [PATCH 0225/1625] Adapted so that anybody can do "make install". --- util/ack/Makefile | 3 ++- util/ack/pc/Makefile | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/util/ack/Makefile b/util/ack/Makefile index 8d655401..b33790fd 100644 --- a/util/ack/Makefile +++ b/util/ack/Makefile @@ -16,9 +16,10 @@ BINDIR=../../bin head: ack install: ack + rm -f $(BINDIR)/ack cp ack $(BINDIR)/ack -cd $(BINDIR) ; \ - for i in $(INTABLES) $(LNTABLES) ; do ln ack $$i ; done + for i in $(INTABLES) $(LNTABLES) ; do rm -f $$i ; ln ack $$i ; done (cd pc ; make install ) cmp: ack diff --git a/util/ack/pc/Makefile b/util/ack/pc/Makefile index 4d4f340f..3d55256b 100644 --- a/util/ack/pc/Makefile +++ b/util/ack/pc/Makefile @@ -10,6 +10,7 @@ cmp: em_pc cmp em_pc $(PC_PATH) install: em_pc + rm -f $(PC_PATH) cp em_pc $(PC_PATH) lint: From 064ea695d5f4f1d5e9872f4af439584bc0474884 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 22 Jul 1986 11:01:54 +0000 Subject: [PATCH 0226/1625] replaced all occurrences of "cc" by "$(CC)". --- mach/6500/cg/Makefile | 34 +++++++++++++++++----------------- mach/pdp/cg/Makefile | 34 +++++++++++++++++----------------- mach/proto/cg/Makefile | 34 +++++++++++++++++----------------- mach/vax4/cg/Makefile | 34 +++++++++++++++++----------------- mach/z80/cg/Makefile | 34 +++++++++++++++++----------------- mach/z8000/cg/Makefile | 34 +++++++++++++++++----------------- 6 files changed, 102 insertions(+), 102 deletions(-) diff --git a/mach/6500/cg/Makefile b/mach/6500/cg/Makefile index bb54f712..93f97b75 100644 --- a/mach/6500/cg/Makefile +++ b/mach/6500/cg/Makefile @@ -19,41 +19,41 @@ all: make cg cg: tables.o $(OFILES) - cc $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg + $(CC) $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg tables.o: tables.c - cc -c $(PREFLAGS) -I$(CDIR) tables.c + $(CC) -c $(PREFLAGS) -I$(CDIR) tables.c codegen.o: $(CDIR)/codegen.c - cc -c $(CFLAGS) $(CDIR)/codegen.c + $(CC) -c $(CFLAGS) $(CDIR)/codegen.c compute.o: $(CDIR)/compute.c - cc -c $(CFLAGS) $(CDIR)/compute.c + $(CC) -c $(CFLAGS) $(CDIR)/compute.c equiv.o: $(CDIR)/equiv.c - cc -c $(CFLAGS) $(CDIR)/equiv.c + $(CC) -c $(CFLAGS) $(CDIR)/equiv.c fillem.o: $(CDIR)/fillem.c - cc -c $(CFLAGS) $(CDIR)/fillem.c + $(CC) -c $(CFLAGS) $(CDIR)/fillem.c gencode.o: $(CDIR)/gencode.c - cc -c $(CFLAGS) $(CDIR)/gencode.c + $(CC) -c $(CFLAGS) $(CDIR)/gencode.c glosym.o: $(CDIR)/glosym.c - cc -c $(CFLAGS) $(CDIR)/glosym.c + $(CC) -c $(CFLAGS) $(CDIR)/glosym.c main.o: $(CDIR)/main.c - cc -c $(CFLAGS) $(CDIR)/main.c + $(CC) -c $(CFLAGS) $(CDIR)/main.c move.o: $(CDIR)/move.c - cc -c $(CFLAGS) $(CDIR)/move.c + $(CC) -c $(CFLAGS) $(CDIR)/move.c nextem.o: $(CDIR)/nextem.c - cc -c $(CFLAGS) $(CDIR)/nextem.c + $(CC) -c $(CFLAGS) $(CDIR)/nextem.c reg.o: $(CDIR)/reg.c - cc -c $(CFLAGS) $(CDIR)/reg.c + $(CC) -c $(CFLAGS) $(CDIR)/reg.c regvar.o: $(CDIR)/regvar.c - cc -c $(CFLAGS) $(CDIR)/regvar.c + $(CC) -c $(CFLAGS) $(CDIR)/regvar.c salloc.o: $(CDIR)/salloc.c - cc -c $(CFLAGS) $(CDIR)/salloc.c + $(CC) -c $(CFLAGS) $(CDIR)/salloc.c state.o: $(CDIR)/state.c - cc -c $(CFLAGS) $(CDIR)/state.c + $(CC) -c $(CFLAGS) $(CDIR)/state.c subr.o: $(CDIR)/subr.c - cc -c $(CFLAGS) $(CDIR)/subr.c + $(CC) -c $(CFLAGS) $(CDIR)/subr.c var.o: $(CDIR)/var.c - cc -c $(CFLAGS) $(CDIR)/var.c + $(CC) -c $(CFLAGS) $(CDIR)/var.c install: all ../../install cg diff --git a/mach/pdp/cg/Makefile b/mach/pdp/cg/Makefile index bb54f712..93f97b75 100644 --- a/mach/pdp/cg/Makefile +++ b/mach/pdp/cg/Makefile @@ -19,41 +19,41 @@ all: make cg cg: tables.o $(OFILES) - cc $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg + $(CC) $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg tables.o: tables.c - cc -c $(PREFLAGS) -I$(CDIR) tables.c + $(CC) -c $(PREFLAGS) -I$(CDIR) tables.c codegen.o: $(CDIR)/codegen.c - cc -c $(CFLAGS) $(CDIR)/codegen.c + $(CC) -c $(CFLAGS) $(CDIR)/codegen.c compute.o: $(CDIR)/compute.c - cc -c $(CFLAGS) $(CDIR)/compute.c + $(CC) -c $(CFLAGS) $(CDIR)/compute.c equiv.o: $(CDIR)/equiv.c - cc -c $(CFLAGS) $(CDIR)/equiv.c + $(CC) -c $(CFLAGS) $(CDIR)/equiv.c fillem.o: $(CDIR)/fillem.c - cc -c $(CFLAGS) $(CDIR)/fillem.c + $(CC) -c $(CFLAGS) $(CDIR)/fillem.c gencode.o: $(CDIR)/gencode.c - cc -c $(CFLAGS) $(CDIR)/gencode.c + $(CC) -c $(CFLAGS) $(CDIR)/gencode.c glosym.o: $(CDIR)/glosym.c - cc -c $(CFLAGS) $(CDIR)/glosym.c + $(CC) -c $(CFLAGS) $(CDIR)/glosym.c main.o: $(CDIR)/main.c - cc -c $(CFLAGS) $(CDIR)/main.c + $(CC) -c $(CFLAGS) $(CDIR)/main.c move.o: $(CDIR)/move.c - cc -c $(CFLAGS) $(CDIR)/move.c + $(CC) -c $(CFLAGS) $(CDIR)/move.c nextem.o: $(CDIR)/nextem.c - cc -c $(CFLAGS) $(CDIR)/nextem.c + $(CC) -c $(CFLAGS) $(CDIR)/nextem.c reg.o: $(CDIR)/reg.c - cc -c $(CFLAGS) $(CDIR)/reg.c + $(CC) -c $(CFLAGS) $(CDIR)/reg.c regvar.o: $(CDIR)/regvar.c - cc -c $(CFLAGS) $(CDIR)/regvar.c + $(CC) -c $(CFLAGS) $(CDIR)/regvar.c salloc.o: $(CDIR)/salloc.c - cc -c $(CFLAGS) $(CDIR)/salloc.c + $(CC) -c $(CFLAGS) $(CDIR)/salloc.c state.o: $(CDIR)/state.c - cc -c $(CFLAGS) $(CDIR)/state.c + $(CC) -c $(CFLAGS) $(CDIR)/state.c subr.o: $(CDIR)/subr.c - cc -c $(CFLAGS) $(CDIR)/subr.c + $(CC) -c $(CFLAGS) $(CDIR)/subr.c var.o: $(CDIR)/var.c - cc -c $(CFLAGS) $(CDIR)/var.c + $(CC) -c $(CFLAGS) $(CDIR)/var.c install: all ../../install cg diff --git a/mach/proto/cg/Makefile b/mach/proto/cg/Makefile index bb54f712..93f97b75 100644 --- a/mach/proto/cg/Makefile +++ b/mach/proto/cg/Makefile @@ -19,41 +19,41 @@ all: make cg cg: tables.o $(OFILES) - cc $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg + $(CC) $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg tables.o: tables.c - cc -c $(PREFLAGS) -I$(CDIR) tables.c + $(CC) -c $(PREFLAGS) -I$(CDIR) tables.c codegen.o: $(CDIR)/codegen.c - cc -c $(CFLAGS) $(CDIR)/codegen.c + $(CC) -c $(CFLAGS) $(CDIR)/codegen.c compute.o: $(CDIR)/compute.c - cc -c $(CFLAGS) $(CDIR)/compute.c + $(CC) -c $(CFLAGS) $(CDIR)/compute.c equiv.o: $(CDIR)/equiv.c - cc -c $(CFLAGS) $(CDIR)/equiv.c + $(CC) -c $(CFLAGS) $(CDIR)/equiv.c fillem.o: $(CDIR)/fillem.c - cc -c $(CFLAGS) $(CDIR)/fillem.c + $(CC) -c $(CFLAGS) $(CDIR)/fillem.c gencode.o: $(CDIR)/gencode.c - cc -c $(CFLAGS) $(CDIR)/gencode.c + $(CC) -c $(CFLAGS) $(CDIR)/gencode.c glosym.o: $(CDIR)/glosym.c - cc -c $(CFLAGS) $(CDIR)/glosym.c + $(CC) -c $(CFLAGS) $(CDIR)/glosym.c main.o: $(CDIR)/main.c - cc -c $(CFLAGS) $(CDIR)/main.c + $(CC) -c $(CFLAGS) $(CDIR)/main.c move.o: $(CDIR)/move.c - cc -c $(CFLAGS) $(CDIR)/move.c + $(CC) -c $(CFLAGS) $(CDIR)/move.c nextem.o: $(CDIR)/nextem.c - cc -c $(CFLAGS) $(CDIR)/nextem.c + $(CC) -c $(CFLAGS) $(CDIR)/nextem.c reg.o: $(CDIR)/reg.c - cc -c $(CFLAGS) $(CDIR)/reg.c + $(CC) -c $(CFLAGS) $(CDIR)/reg.c regvar.o: $(CDIR)/regvar.c - cc -c $(CFLAGS) $(CDIR)/regvar.c + $(CC) -c $(CFLAGS) $(CDIR)/regvar.c salloc.o: $(CDIR)/salloc.c - cc -c $(CFLAGS) $(CDIR)/salloc.c + $(CC) -c $(CFLAGS) $(CDIR)/salloc.c state.o: $(CDIR)/state.c - cc -c $(CFLAGS) $(CDIR)/state.c + $(CC) -c $(CFLAGS) $(CDIR)/state.c subr.o: $(CDIR)/subr.c - cc -c $(CFLAGS) $(CDIR)/subr.c + $(CC) -c $(CFLAGS) $(CDIR)/subr.c var.o: $(CDIR)/var.c - cc -c $(CFLAGS) $(CDIR)/var.c + $(CC) -c $(CFLAGS) $(CDIR)/var.c install: all ../../install cg diff --git a/mach/vax4/cg/Makefile b/mach/vax4/cg/Makefile index bb54f712..93f97b75 100644 --- a/mach/vax4/cg/Makefile +++ b/mach/vax4/cg/Makefile @@ -19,41 +19,41 @@ all: make cg cg: tables.o $(OFILES) - cc $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg + $(CC) $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg tables.o: tables.c - cc -c $(PREFLAGS) -I$(CDIR) tables.c + $(CC) -c $(PREFLAGS) -I$(CDIR) tables.c codegen.o: $(CDIR)/codegen.c - cc -c $(CFLAGS) $(CDIR)/codegen.c + $(CC) -c $(CFLAGS) $(CDIR)/codegen.c compute.o: $(CDIR)/compute.c - cc -c $(CFLAGS) $(CDIR)/compute.c + $(CC) -c $(CFLAGS) $(CDIR)/compute.c equiv.o: $(CDIR)/equiv.c - cc -c $(CFLAGS) $(CDIR)/equiv.c + $(CC) -c $(CFLAGS) $(CDIR)/equiv.c fillem.o: $(CDIR)/fillem.c - cc -c $(CFLAGS) $(CDIR)/fillem.c + $(CC) -c $(CFLAGS) $(CDIR)/fillem.c gencode.o: $(CDIR)/gencode.c - cc -c $(CFLAGS) $(CDIR)/gencode.c + $(CC) -c $(CFLAGS) $(CDIR)/gencode.c glosym.o: $(CDIR)/glosym.c - cc -c $(CFLAGS) $(CDIR)/glosym.c + $(CC) -c $(CFLAGS) $(CDIR)/glosym.c main.o: $(CDIR)/main.c - cc -c $(CFLAGS) $(CDIR)/main.c + $(CC) -c $(CFLAGS) $(CDIR)/main.c move.o: $(CDIR)/move.c - cc -c $(CFLAGS) $(CDIR)/move.c + $(CC) -c $(CFLAGS) $(CDIR)/move.c nextem.o: $(CDIR)/nextem.c - cc -c $(CFLAGS) $(CDIR)/nextem.c + $(CC) -c $(CFLAGS) $(CDIR)/nextem.c reg.o: $(CDIR)/reg.c - cc -c $(CFLAGS) $(CDIR)/reg.c + $(CC) -c $(CFLAGS) $(CDIR)/reg.c regvar.o: $(CDIR)/regvar.c - cc -c $(CFLAGS) $(CDIR)/regvar.c + $(CC) -c $(CFLAGS) $(CDIR)/regvar.c salloc.o: $(CDIR)/salloc.c - cc -c $(CFLAGS) $(CDIR)/salloc.c + $(CC) -c $(CFLAGS) $(CDIR)/salloc.c state.o: $(CDIR)/state.c - cc -c $(CFLAGS) $(CDIR)/state.c + $(CC) -c $(CFLAGS) $(CDIR)/state.c subr.o: $(CDIR)/subr.c - cc -c $(CFLAGS) $(CDIR)/subr.c + $(CC) -c $(CFLAGS) $(CDIR)/subr.c var.o: $(CDIR)/var.c - cc -c $(CFLAGS) $(CDIR)/var.c + $(CC) -c $(CFLAGS) $(CDIR)/var.c install: all ../../install cg diff --git a/mach/z80/cg/Makefile b/mach/z80/cg/Makefile index bb54f712..93f97b75 100644 --- a/mach/z80/cg/Makefile +++ b/mach/z80/cg/Makefile @@ -19,41 +19,41 @@ all: make cg cg: tables.o $(OFILES) - cc $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg + $(CC) $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg tables.o: tables.c - cc -c $(PREFLAGS) -I$(CDIR) tables.c + $(CC) -c $(PREFLAGS) -I$(CDIR) tables.c codegen.o: $(CDIR)/codegen.c - cc -c $(CFLAGS) $(CDIR)/codegen.c + $(CC) -c $(CFLAGS) $(CDIR)/codegen.c compute.o: $(CDIR)/compute.c - cc -c $(CFLAGS) $(CDIR)/compute.c + $(CC) -c $(CFLAGS) $(CDIR)/compute.c equiv.o: $(CDIR)/equiv.c - cc -c $(CFLAGS) $(CDIR)/equiv.c + $(CC) -c $(CFLAGS) $(CDIR)/equiv.c fillem.o: $(CDIR)/fillem.c - cc -c $(CFLAGS) $(CDIR)/fillem.c + $(CC) -c $(CFLAGS) $(CDIR)/fillem.c gencode.o: $(CDIR)/gencode.c - cc -c $(CFLAGS) $(CDIR)/gencode.c + $(CC) -c $(CFLAGS) $(CDIR)/gencode.c glosym.o: $(CDIR)/glosym.c - cc -c $(CFLAGS) $(CDIR)/glosym.c + $(CC) -c $(CFLAGS) $(CDIR)/glosym.c main.o: $(CDIR)/main.c - cc -c $(CFLAGS) $(CDIR)/main.c + $(CC) -c $(CFLAGS) $(CDIR)/main.c move.o: $(CDIR)/move.c - cc -c $(CFLAGS) $(CDIR)/move.c + $(CC) -c $(CFLAGS) $(CDIR)/move.c nextem.o: $(CDIR)/nextem.c - cc -c $(CFLAGS) $(CDIR)/nextem.c + $(CC) -c $(CFLAGS) $(CDIR)/nextem.c reg.o: $(CDIR)/reg.c - cc -c $(CFLAGS) $(CDIR)/reg.c + $(CC) -c $(CFLAGS) $(CDIR)/reg.c regvar.o: $(CDIR)/regvar.c - cc -c $(CFLAGS) $(CDIR)/regvar.c + $(CC) -c $(CFLAGS) $(CDIR)/regvar.c salloc.o: $(CDIR)/salloc.c - cc -c $(CFLAGS) $(CDIR)/salloc.c + $(CC) -c $(CFLAGS) $(CDIR)/salloc.c state.o: $(CDIR)/state.c - cc -c $(CFLAGS) $(CDIR)/state.c + $(CC) -c $(CFLAGS) $(CDIR)/state.c subr.o: $(CDIR)/subr.c - cc -c $(CFLAGS) $(CDIR)/subr.c + $(CC) -c $(CFLAGS) $(CDIR)/subr.c var.o: $(CDIR)/var.c - cc -c $(CFLAGS) $(CDIR)/var.c + $(CC) -c $(CFLAGS) $(CDIR)/var.c install: all ../../install cg diff --git a/mach/z8000/cg/Makefile b/mach/z8000/cg/Makefile index bb54f712..93f97b75 100644 --- a/mach/z8000/cg/Makefile +++ b/mach/z8000/cg/Makefile @@ -19,41 +19,41 @@ all: make cg cg: tables.o $(OFILES) - cc $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg + $(CC) $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg tables.o: tables.c - cc -c $(PREFLAGS) -I$(CDIR) tables.c + $(CC) -c $(PREFLAGS) -I$(CDIR) tables.c codegen.o: $(CDIR)/codegen.c - cc -c $(CFLAGS) $(CDIR)/codegen.c + $(CC) -c $(CFLAGS) $(CDIR)/codegen.c compute.o: $(CDIR)/compute.c - cc -c $(CFLAGS) $(CDIR)/compute.c + $(CC) -c $(CFLAGS) $(CDIR)/compute.c equiv.o: $(CDIR)/equiv.c - cc -c $(CFLAGS) $(CDIR)/equiv.c + $(CC) -c $(CFLAGS) $(CDIR)/equiv.c fillem.o: $(CDIR)/fillem.c - cc -c $(CFLAGS) $(CDIR)/fillem.c + $(CC) -c $(CFLAGS) $(CDIR)/fillem.c gencode.o: $(CDIR)/gencode.c - cc -c $(CFLAGS) $(CDIR)/gencode.c + $(CC) -c $(CFLAGS) $(CDIR)/gencode.c glosym.o: $(CDIR)/glosym.c - cc -c $(CFLAGS) $(CDIR)/glosym.c + $(CC) -c $(CFLAGS) $(CDIR)/glosym.c main.o: $(CDIR)/main.c - cc -c $(CFLAGS) $(CDIR)/main.c + $(CC) -c $(CFLAGS) $(CDIR)/main.c move.o: $(CDIR)/move.c - cc -c $(CFLAGS) $(CDIR)/move.c + $(CC) -c $(CFLAGS) $(CDIR)/move.c nextem.o: $(CDIR)/nextem.c - cc -c $(CFLAGS) $(CDIR)/nextem.c + $(CC) -c $(CFLAGS) $(CDIR)/nextem.c reg.o: $(CDIR)/reg.c - cc -c $(CFLAGS) $(CDIR)/reg.c + $(CC) -c $(CFLAGS) $(CDIR)/reg.c regvar.o: $(CDIR)/regvar.c - cc -c $(CFLAGS) $(CDIR)/regvar.c + $(CC) -c $(CFLAGS) $(CDIR)/regvar.c salloc.o: $(CDIR)/salloc.c - cc -c $(CFLAGS) $(CDIR)/salloc.c + $(CC) -c $(CFLAGS) $(CDIR)/salloc.c state.o: $(CDIR)/state.c - cc -c $(CFLAGS) $(CDIR)/state.c + $(CC) -c $(CFLAGS) $(CDIR)/state.c subr.o: $(CDIR)/subr.c - cc -c $(CFLAGS) $(CDIR)/subr.c + $(CC) -c $(CFLAGS) $(CDIR)/subr.c var.o: $(CDIR)/var.c - cc -c $(CFLAGS) $(CDIR)/var.c + $(CC) -c $(CFLAGS) $(CDIR)/var.c install: all ../../install cg From 3a13b60c06ee3b6385ae9adee57d7ce5dddf6aa8 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 22 Jul 1986 11:07:48 +0000 Subject: [PATCH 0227/1625] Initial revision --- mach/m68k4/libem/compmodule | 4 ++++ 1 file changed, 4 insertions(+) create mode 100755 mach/m68k4/libem/compmodule diff --git a/mach/m68k4/libem/compmodule b/mach/m68k4/libem/compmodule new file mode 100755 index 00000000..80f42aab --- /dev/null +++ b/mach/m68k4/libem/compmodule @@ -0,0 +1,4 @@ +if m68k4 -c $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 +fi From 6cd49ed46c129bdba707e69b2418675d367cc2dd Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 22 Jul 1986 13:23:14 +0000 Subject: [PATCH 0228/1625] Adapted to use of new assembler. --- mach/m68k4/libsys/Makefile | 24 ++++++++++++++---------- mach/m68k4/libsys/_exit.s | 6 +++++- mach/m68k4/libsys/access.s | 6 +++++- mach/m68k4/libsys/acct.s | 6 +++++- mach/m68k4/libsys/alarm.s | 6 +++++- mach/m68k4/libsys/brk.s | 6 +++++- mach/m68k4/libsys/call.s | 6 +++++- mach/m68k4/libsys/chdir.s | 6 +++++- mach/m68k4/libsys/chmod.s | 6 +++++- mach/m68k4/libsys/chown.s | 6 +++++- mach/m68k4/libsys/chroot.s | 6 +++++- mach/m68k4/libsys/cleanup.s | 6 +++++- mach/m68k4/libsys/close.s | 6 +++++- mach/m68k4/libsys/creat.s | 6 +++++- mach/m68k4/libsys/dup.s | 6 +++++- mach/m68k4/libsys/dup2.s | 6 +++++- mach/m68k4/libsys/errno.s | 8 ++++++-- mach/m68k4/libsys/execl.s | 5 +++++ mach/m68k4/libsys/execve.s | 6 +++++- mach/m68k4/libsys/exit.s | 6 +++++- mach/m68k4/libsys/fork.s | 6 +++++- mach/m68k4/libsys/fstat.s | 5 +++++ mach/m68k4/libsys/ftime.s | 6 +++++- mach/m68k4/libsys/getegid.s | 6 +++++- mach/m68k4/libsys/getgid.s | 6 +++++- mach/m68k4/libsys/getpid.s | 6 +++++- mach/m68k4/libsys/getuid.s | 6 +++++- mach/m68k4/libsys/gtty.s | 6 +++++- mach/m68k4/libsys/ioctl.s | 6 +++++- mach/m68k4/libsys/kill.s | 6 +++++- mach/m68k4/libsys/link.s | 6 +++++- mach/m68k4/libsys/lock.s | 6 +++++- mach/m68k4/libsys/lseek.s | 6 +++++- mach/m68k4/libsys/mknod.s | 6 +++++- mach/m68k4/libsys/mount.s | 7 +++++-- mach/m68k4/libsys/nice.s | 6 +++++- mach/m68k4/libsys/open.s | 6 +++++- mach/m68k4/libsys/pause.s | 6 +++++- mach/m68k4/libsys/pipe.s | 5 +++++ mach/m68k4/libsys/profil.s | 6 +++++- mach/m68k4/libsys/ptrace.s | 6 +++++- mach/m68k4/libsys/read.s | 6 +++++- mach/m68k4/libsys/setgid.s | 6 +++++- mach/m68k4/libsys/setuid.s | 6 +++++- mach/m68k4/libsys/signal.s | 7 ++++++- mach/m68k4/libsys/stat.s | 6 +++++- mach/m68k4/libsys/stime.s | 5 ++++- mach/m68k4/libsys/stty.s | 5 ++++- mach/m68k4/libsys/sync.s | 5 ++++- mach/m68k4/libsys/time.s | 6 +++++- mach/m68k4/libsys/times.s | 6 +++++- mach/m68k4/libsys/umask.s | 6 +++++- mach/m68k4/libsys/umount.s | 6 +++++- mach/m68k4/libsys/unlink.s | 6 +++++- mach/m68k4/libsys/utime.s | 6 +++++- mach/m68k4/libsys/wait.s | 5 +++++ mach/m68k4/libsys/write.s | 6 +++++- 57 files changed, 293 insertions(+), 64 deletions(-) diff --git a/mach/m68k4/libsys/Makefile b/mach/m68k4/libsys/Makefile index 91f2cc35..37bd1e20 100644 --- a/mach/m68k4/libsys/Makefile +++ b/mach/m68k4/libsys/Makefile @@ -1,17 +1,21 @@ # $Header$ -install: - ../../install head_em.s head_em - ../../install tail_mon.a tail_mon +MACH=m68k4 +all: tail_mon +install: all + ../../install tail_mon -compare: - -../../compare head_em.s head_em - -../../compare tail_mon.a tail_mon +cmp: all + -../../compare tail_mon -clean : +tail_mon: + ASAR=aal ; export ASAR ;\ + march . tail_mon + +clean: + rm -f *.o opr : - make pr | opr + make pr | opr pr: - @pr -h `pwd`/head_em.s head_em.s - @ar pv tail_mon.a | pr -h `pwd`/tail_mon.a + @ar pv tail_mon.a diff --git a/mach/m68k4/libsys/_exit.s b/mach/m68k4/libsys/_exit.s index 6f0d4e3a..533c8166 100644 --- a/mach/m68k4/libsys/_exit.s +++ b/mach/m68k4/libsys/_exit.s @@ -1,6 +1,10 @@ .define __exit .extern __exit -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text __exit: move.w #0x1,d0 move.l 4(sp),a0 trap #0 diff --git a/mach/m68k4/libsys/access.s b/mach/m68k4/libsys/access.s index f2a0c2c5..fb8f690e 100644 --- a/mach/m68k4/libsys/access.s +++ b/mach/m68k4/libsys/access.s @@ -1,6 +1,10 @@ .define _access .extern _access -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _access: move.w #0x21,d0 move.l 4(sp),a0 move.l 8(sp),d1 diff --git a/mach/m68k4/libsys/acct.s b/mach/m68k4/libsys/acct.s index b4ba8b61..dd3466ba 100644 --- a/mach/m68k4/libsys/acct.s +++ b/mach/m68k4/libsys/acct.s @@ -1,6 +1,10 @@ .define _acct .extern _acct -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _acct: move.w #0x33,d0 move.l 4(sp),a0 jmp callc diff --git a/mach/m68k4/libsys/alarm.s b/mach/m68k4/libsys/alarm.s index d3b4220f..954ef29a 100644 --- a/mach/m68k4/libsys/alarm.s +++ b/mach/m68k4/libsys/alarm.s @@ -1,6 +1,10 @@ .define _alarm .extern _alarm -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _alarm: clr.l d0 move.l 4(sp),a0 move.w #0x1B,d0 diff --git a/mach/m68k4/libsys/brk.s b/mach/m68k4/libsys/brk.s index ec574c05..68636bf2 100644 --- a/mach/m68k4/libsys/brk.s +++ b/mach/m68k4/libsys/brk.s @@ -2,7 +2,11 @@ .define _sbrk .extern _brk .extern _sbrk -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _sbrk: move.l .reghp,a0 add.l 4(sp),a0 move.w #0x11,d0 diff --git a/mach/m68k4/libsys/call.s b/mach/m68k4/libsys/call.s index fa343cae..de682c1f 100644 --- a/mach/m68k4/libsys/call.s +++ b/mach/m68k4/libsys/call.s @@ -7,7 +7,11 @@ .extern calle .extern cerror .extern _errno -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text call: trap #0 bcs cerror rts diff --git a/mach/m68k4/libsys/chdir.s b/mach/m68k4/libsys/chdir.s index d03224ae..ac420e2e 100644 --- a/mach/m68k4/libsys/chdir.s +++ b/mach/m68k4/libsys/chdir.s @@ -1,6 +1,10 @@ .define _chdir .extern _chdir -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _chdir: move.w #0xC,d0 move.l 4(sp),a0 jmp callc diff --git a/mach/m68k4/libsys/chmod.s b/mach/m68k4/libsys/chmod.s index 171b16eb..82ed795e 100644 --- a/mach/m68k4/libsys/chmod.s +++ b/mach/m68k4/libsys/chmod.s @@ -1,6 +1,10 @@ .define _chmod .extern _chmod -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _chmod: move.w #0xF,d0 move.l 4(sp),a0 move.l 8(sp),d1 diff --git a/mach/m68k4/libsys/chown.s b/mach/m68k4/libsys/chown.s index d0f71f2a..26ae588e 100644 --- a/mach/m68k4/libsys/chown.s +++ b/mach/m68k4/libsys/chown.s @@ -1,6 +1,10 @@ .define _chown .extern _chown -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _chown: move.w #0x10,d0 move.l 4(sp),a0 move.l 8(sp),d1 diff --git a/mach/m68k4/libsys/chroot.s b/mach/m68k4/libsys/chroot.s index ebf9f6a4..3f50ea19 100644 --- a/mach/m68k4/libsys/chroot.s +++ b/mach/m68k4/libsys/chroot.s @@ -1,6 +1,10 @@ .define _chroot .extern _chroot -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _chroot: move.w #0x3D,d0 move.l 4(sp),a0 jmp callc diff --git a/mach/m68k4/libsys/cleanup.s b/mach/m68k4/libsys/cleanup.s index 7df1860b..28bab043 100644 --- a/mach/m68k4/libsys/cleanup.s +++ b/mach/m68k4/libsys/cleanup.s @@ -1,6 +1,10 @@ .define __cleanup .extern __cleanup -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text __cleanup: tst.b -40(sp) link a6,#-0 diff --git a/mach/m68k4/libsys/close.s b/mach/m68k4/libsys/close.s index 6ad17f1b..ce9ef46e 100644 --- a/mach/m68k4/libsys/close.s +++ b/mach/m68k4/libsys/close.s @@ -1,6 +1,10 @@ .define _close .extern _close -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _close: move.w #0x6,d0 move.l 4(sp),a0 jmp callc diff --git a/mach/m68k4/libsys/creat.s b/mach/m68k4/libsys/creat.s index 368b2e36..6bcced8a 100644 --- a/mach/m68k4/libsys/creat.s +++ b/mach/m68k4/libsys/creat.s @@ -1,6 +1,10 @@ .define _creat .extern _creat -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _creat: move.w #0x8,d0 move.l 4(sp),a0 move.l 8(sp),d1 diff --git a/mach/m68k4/libsys/dup.s b/mach/m68k4/libsys/dup.s index 20e7dbe8..b68626da 100644 --- a/mach/m68k4/libsys/dup.s +++ b/mach/m68k4/libsys/dup.s @@ -1,6 +1,10 @@ .define _dup .extern _dup -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _dup: move.w #0x29,d0 move.l 4(sp),a0 jmp call diff --git a/mach/m68k4/libsys/dup2.s b/mach/m68k4/libsys/dup2.s index 2924bc82..10f49418 100644 --- a/mach/m68k4/libsys/dup2.s +++ b/mach/m68k4/libsys/dup2.s @@ -1,6 +1,10 @@ .define _dup2 .extern _dup2 -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _dup2: move.w #0x29,d0 move.l 4(sp),a0 move.l 8(sp),d1 diff --git a/mach/m68k4/libsys/errno.s b/mach/m68k4/libsys/errno.s index e7ce8bb8..adc08301 100644 --- a/mach/m68k4/libsys/errno.s +++ b/mach/m68k4/libsys/errno.s @@ -1,5 +1,9 @@ .define _errno .extern _errno -.bss +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .bss _errno: .space 4 -.text +.sect .text diff --git a/mach/m68k4/libsys/execl.s b/mach/m68k4/libsys/execl.s index 21e03dc9..67c4c63c 100644 --- a/mach/m68k4/libsys/execl.s +++ b/mach/m68k4/libsys/execl.s @@ -1,5 +1,10 @@ .define _execl .extern _execl +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _execl: link a6,#0 tst.b -132(sp) move.l _environ,-(sp) diff --git a/mach/m68k4/libsys/execve.s b/mach/m68k4/libsys/execve.s index 2b2de5f8..40dbc0f1 100644 --- a/mach/m68k4/libsys/execve.s +++ b/mach/m68k4/libsys/execve.s @@ -1,6 +1,10 @@ .define _execve .extern _execve -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _execve: move.w #0x3B,d0 move.l 4(sp),a0 move.l 8(sp),d1 diff --git a/mach/m68k4/libsys/exit.s b/mach/m68k4/libsys/exit.s index 3824a590..33e3d650 100644 --- a/mach/m68k4/libsys/exit.s +++ b/mach/m68k4/libsys/exit.s @@ -1,6 +1,10 @@ .define _exit .extern _exit -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _exit: tst.b -40(sp) link a6,#-0 diff --git a/mach/m68k4/libsys/fork.s b/mach/m68k4/libsys/fork.s index 0401e631..f2c5115a 100644 --- a/mach/m68k4/libsys/fork.s +++ b/mach/m68k4/libsys/fork.s @@ -1,6 +1,10 @@ .define _fork .extern _fork -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _fork: move.w #0x2,d0 trap #0 bra 1f diff --git a/mach/m68k4/libsys/fstat.s b/mach/m68k4/libsys/fstat.s index 1d3b9894..e06060fa 100644 --- a/mach/m68k4/libsys/fstat.s +++ b/mach/m68k4/libsys/fstat.s @@ -1,5 +1,10 @@ .define _fstat .extern _fstat +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _fstat: move.w #0x1C,d0 move.l 4(sp),a0 move.l 8(sp),d1 diff --git a/mach/m68k4/libsys/ftime.s b/mach/m68k4/libsys/ftime.s index 432ed3f0..3826bbcf 100644 --- a/mach/m68k4/libsys/ftime.s +++ b/mach/m68k4/libsys/ftime.s @@ -1,6 +1,10 @@ .define _ftime .extern _ftime -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _ftime: move.w #0x23,d0 move.l 4(sp),a0 jmp callc diff --git a/mach/m68k4/libsys/getegid.s b/mach/m68k4/libsys/getegid.s index b4da40c1..49750e60 100644 --- a/mach/m68k4/libsys/getegid.s +++ b/mach/m68k4/libsys/getegid.s @@ -1,6 +1,10 @@ .define _getegid .extern _getegid -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _getegid: move.w #0x2F,d0 trap #0 move.l d1,d0 diff --git a/mach/m68k4/libsys/getgid.s b/mach/m68k4/libsys/getgid.s index 3ef4def3..b281bc40 100644 --- a/mach/m68k4/libsys/getgid.s +++ b/mach/m68k4/libsys/getgid.s @@ -1,6 +1,10 @@ .define _getgid .extern _getgid -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _getgid: move.w #0x2F,d0 trap #0 rts diff --git a/mach/m68k4/libsys/getpid.s b/mach/m68k4/libsys/getpid.s index 1bf2aba7..ab4fc03a 100644 --- a/mach/m68k4/libsys/getpid.s +++ b/mach/m68k4/libsys/getpid.s @@ -1,6 +1,10 @@ .define _getpid .extern _getpid -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _getpid: move.w #0x14,d0 trap #0 rts diff --git a/mach/m68k4/libsys/getuid.s b/mach/m68k4/libsys/getuid.s index d0e15a1b..8100b0cd 100644 --- a/mach/m68k4/libsys/getuid.s +++ b/mach/m68k4/libsys/getuid.s @@ -1,6 +1,10 @@ .define _getuid .extern _getuid -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _getuid: move.w #0x18,d0 trap #0 rts diff --git a/mach/m68k4/libsys/gtty.s b/mach/m68k4/libsys/gtty.s index 4de35e43..8b90d861 100644 --- a/mach/m68k4/libsys/gtty.s +++ b/mach/m68k4/libsys/gtty.s @@ -1,6 +1,10 @@ .define _gtty .extern _gtty -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _gtty: tst.b -40(sp) link a6,#-0 diff --git a/mach/m68k4/libsys/ioctl.s b/mach/m68k4/libsys/ioctl.s index 8dcdd294..5a354fc7 100644 --- a/mach/m68k4/libsys/ioctl.s +++ b/mach/m68k4/libsys/ioctl.s @@ -1,6 +1,10 @@ .define _ioctl .extern _ioctl -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _ioctl: move.w #0x36,d0 move.l 4(sp),a0 move.l 8(sp),d1 diff --git a/mach/m68k4/libsys/kill.s b/mach/m68k4/libsys/kill.s index 2f1303a8..71c032e3 100644 --- a/mach/m68k4/libsys/kill.s +++ b/mach/m68k4/libsys/kill.s @@ -1,6 +1,10 @@ .define _kill .extern _kill -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _kill: move.w #0x25,d0 move.l 4(sp),a0 move.l 6(sp),d1 diff --git a/mach/m68k4/libsys/link.s b/mach/m68k4/libsys/link.s index e0e7417e..1dc5c599 100644 --- a/mach/m68k4/libsys/link.s +++ b/mach/m68k4/libsys/link.s @@ -1,6 +1,10 @@ .define _link .extern _link -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _link: move.w #0x9,d0 move.l 4(sp),a0 move.l 8(sp),d1 diff --git a/mach/m68k4/libsys/lock.s b/mach/m68k4/libsys/lock.s index 408371a6..8e1f53b7 100644 --- a/mach/m68k4/libsys/lock.s +++ b/mach/m68k4/libsys/lock.s @@ -1,6 +1,10 @@ .define _lock .extern _lock -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _lock: move.w #0x35,d0 move.l 4(sp),a0 jmp callc diff --git a/mach/m68k4/libsys/lseek.s b/mach/m68k4/libsys/lseek.s index 56e66105..132458d6 100644 --- a/mach/m68k4/libsys/lseek.s +++ b/mach/m68k4/libsys/lseek.s @@ -1,6 +1,10 @@ .define _lseek .extern _lseek -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _lseek: move.w #0x13,d0 move.l 4(sp),a0 move.l 8(sp),d1 diff --git a/mach/m68k4/libsys/mknod.s b/mach/m68k4/libsys/mknod.s index bdc84aca..68c60b2b 100644 --- a/mach/m68k4/libsys/mknod.s +++ b/mach/m68k4/libsys/mknod.s @@ -1,6 +1,10 @@ .define _mknod .extern _mknod -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _mknod: move.w #0xE,d0 move.l 4(sp),a0 move.l 8(sp),d1 diff --git a/mach/m68k4/libsys/mount.s b/mach/m68k4/libsys/mount.s index b7d37737..bdf8430d 100644 --- a/mach/m68k4/libsys/mount.s +++ b/mach/m68k4/libsys/mount.s @@ -1,7 +1,10 @@ - .define _mount .extern _mount -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _mount: move.w #0x15,d0 move.l 4(sp),a0 move.l 8(sp),d1 diff --git a/mach/m68k4/libsys/nice.s b/mach/m68k4/libsys/nice.s index 2a34667d..942d3b57 100644 --- a/mach/m68k4/libsys/nice.s +++ b/mach/m68k4/libsys/nice.s @@ -1,6 +1,10 @@ .define _nice .extern _nice -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _nice: move.w #0x22,d0 move.l 4(sp),a0 jmp callc diff --git a/mach/m68k4/libsys/open.s b/mach/m68k4/libsys/open.s index 0746c613..d93a797b 100644 --- a/mach/m68k4/libsys/open.s +++ b/mach/m68k4/libsys/open.s @@ -1,6 +1,10 @@ .define _open .extern _open -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _open: move.w #0x5,d0 move.l 4(sp),a0 move.l 8(sp),d1 diff --git a/mach/m68k4/libsys/pause.s b/mach/m68k4/libsys/pause.s index 53b99d73..e60fcc46 100644 --- a/mach/m68k4/libsys/pause.s +++ b/mach/m68k4/libsys/pause.s @@ -1,6 +1,10 @@ .define _pause .extern _pause -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _pause: move.w #0x1D,d0 trap #0 rts diff --git a/mach/m68k4/libsys/pipe.s b/mach/m68k4/libsys/pipe.s index 8d5edc60..3c09f7f5 100644 --- a/mach/m68k4/libsys/pipe.s +++ b/mach/m68k4/libsys/pipe.s @@ -1,5 +1,10 @@ .define _pipe .extern _pipe +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _pipe: move.w #0x2A,d0 trap #0 diff --git a/mach/m68k4/libsys/profil.s b/mach/m68k4/libsys/profil.s index 8a55cbb8..55ddc55a 100644 --- a/mach/m68k4/libsys/profil.s +++ b/mach/m68k4/libsys/profil.s @@ -1,6 +1,10 @@ .define _profil .extern _profil -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _profil: move.w #0x2C,d0 move.l 4(sp),a0 move.l 8(sp),d1 diff --git a/mach/m68k4/libsys/ptrace.s b/mach/m68k4/libsys/ptrace.s index b0f59738..080a0697 100644 --- a/mach/m68k4/libsys/ptrace.s +++ b/mach/m68k4/libsys/ptrace.s @@ -1,7 +1,11 @@ .define _ptrace .extern _ptrace .extern _errno -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _ptrace: move.w #0x1A,d0 move.l 16(sp),a0 move.l 12(sp),d1 diff --git a/mach/m68k4/libsys/read.s b/mach/m68k4/libsys/read.s index 368c9b2b..242b9426 100644 --- a/mach/m68k4/libsys/read.s +++ b/mach/m68k4/libsys/read.s @@ -1,6 +1,10 @@ .define _read .extern _read -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _read: move.w #0x3,d0 move.l 4(sp),a0 move.l 8(sp),d1 diff --git a/mach/m68k4/libsys/setgid.s b/mach/m68k4/libsys/setgid.s index 618129fe..c8ccc97c 100644 --- a/mach/m68k4/libsys/setgid.s +++ b/mach/m68k4/libsys/setgid.s @@ -1,6 +1,10 @@ .define _setgid .extern _setgid -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _setgid: move.w #0x2E,d0 move.l 4(sp),a0 jmp callc diff --git a/mach/m68k4/libsys/setuid.s b/mach/m68k4/libsys/setuid.s index 2441afe1..07a7bee6 100644 --- a/mach/m68k4/libsys/setuid.s +++ b/mach/m68k4/libsys/setuid.s @@ -1,6 +1,10 @@ .define _setuid .extern _setuid -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _setuid: move.w #0x17,d0 move.l 4(sp),a0 jmp callc diff --git a/mach/m68k4/libsys/signal.s b/mach/m68k4/libsys/signal.s index 0553917c..40f4e2f0 100644 --- a/mach/m68k4/libsys/signal.s +++ b/mach/m68k4/libsys/signal.s @@ -1,5 +1,10 @@ .define _signal .extern _signal +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text NSIG=32 _signal: move.l 4(sp), d0 @@ -82,5 +87,5 @@ enter: movem.l (sp)+,d0/d1/a0/a1 add.l #4,sp rtr -.bss +.sect .bss dvect: .space 4*NSIG diff --git a/mach/m68k4/libsys/stat.s b/mach/m68k4/libsys/stat.s index dd43a18f..8b41b7ff 100644 --- a/mach/m68k4/libsys/stat.s +++ b/mach/m68k4/libsys/stat.s @@ -1,6 +1,10 @@ .define _stat .extern _stat -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _stat: move.w #0x12,d0 move.l 4(sp),a0 move.l 8(sp),d1 diff --git a/mach/m68k4/libsys/stime.s b/mach/m68k4/libsys/stime.s index bac6386d..f1a7a560 100644 --- a/mach/m68k4/libsys/stime.s +++ b/mach/m68k4/libsys/stime.s @@ -1,6 +1,9 @@ .define _stime .extern _stime -.text +.sect .rom +.sect .data +.sect .bss +.sect .text _stime: move.w #0x19,d0 move.l 4(sp),a0 move.l (a0),a0 diff --git a/mach/m68k4/libsys/stty.s b/mach/m68k4/libsys/stty.s index 7c8514a2..47a75b34 100644 --- a/mach/m68k4/libsys/stty.s +++ b/mach/m68k4/libsys/stty.s @@ -1,6 +1,9 @@ .define _stty .extern _stty -.text +.sect .rom +.sect .data +.sect .bss +.sect .text _stty: tst.b -40(sp) link a6,#-0 diff --git a/mach/m68k4/libsys/sync.s b/mach/m68k4/libsys/sync.s index 3c38a8ad..179c70e3 100644 --- a/mach/m68k4/libsys/sync.s +++ b/mach/m68k4/libsys/sync.s @@ -1,6 +1,9 @@ .define _sync .extern _sync -.text +.sect .rom +.sect .data +.sect .bss +.sect .text _sync: move.w #0x24,d0 trap #0 rts diff --git a/mach/m68k4/libsys/time.s b/mach/m68k4/libsys/time.s index 87b9d8bd..7b2d5900 100644 --- a/mach/m68k4/libsys/time.s +++ b/mach/m68k4/libsys/time.s @@ -1,6 +1,10 @@ .define _time .extern _time -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _time: move.w #0xD,d0 trap #0 tst.l 4(sp) diff --git a/mach/m68k4/libsys/times.s b/mach/m68k4/libsys/times.s index 6e74fe9a..bf6632d2 100644 --- a/mach/m68k4/libsys/times.s +++ b/mach/m68k4/libsys/times.s @@ -1,6 +1,10 @@ .define _times .extern _times -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _times: move.w #0x2B,d0 move.l 4(sp),a0 trap #0 diff --git a/mach/m68k4/libsys/umask.s b/mach/m68k4/libsys/umask.s index ff7ec060..d911d952 100644 --- a/mach/m68k4/libsys/umask.s +++ b/mach/m68k4/libsys/umask.s @@ -1,6 +1,10 @@ .define _umask .extern _umask -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _umask: move.w #0x3C,d0 move.l 4(sp),a0 jmp call diff --git a/mach/m68k4/libsys/umount.s b/mach/m68k4/libsys/umount.s index 59354ee9..bed0f260 100644 --- a/mach/m68k4/libsys/umount.s +++ b/mach/m68k4/libsys/umount.s @@ -1,6 +1,10 @@ .define _umount .extern _umount -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _umount: move.w #0x16,d0 move.l 4(sp),a0 jmp callc diff --git a/mach/m68k4/libsys/unlink.s b/mach/m68k4/libsys/unlink.s index 99e856a5..cfeba7ec 100644 --- a/mach/m68k4/libsys/unlink.s +++ b/mach/m68k4/libsys/unlink.s @@ -1,6 +1,10 @@ .define _unlink .extern _unlink -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _unlink: move.w #0xA,d0 move.l 4(sp),a0 jmp callc diff --git a/mach/m68k4/libsys/utime.s b/mach/m68k4/libsys/utime.s index 0e0b6dd9..79be2a59 100644 --- a/mach/m68k4/libsys/utime.s +++ b/mach/m68k4/libsys/utime.s @@ -1,6 +1,10 @@ .define _utime .extern _utime -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _utime: move.w #0x1E,d0 move.l 4(sp),a0 move.l 8(sp),d1 diff --git a/mach/m68k4/libsys/wait.s b/mach/m68k4/libsys/wait.s index f6aa587e..469192f5 100644 --- a/mach/m68k4/libsys/wait.s +++ b/mach/m68k4/libsys/wait.s @@ -1,5 +1,10 @@ .define _wait .extern _wait +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _wait: move.w #0x7,d0 move.l 4(sp),a0 trap #0 diff --git a/mach/m68k4/libsys/write.s b/mach/m68k4/libsys/write.s index ce23b2b2..ede0da00 100644 --- a/mach/m68k4/libsys/write.s +++ b/mach/m68k4/libsys/write.s @@ -1,6 +1,10 @@ .define _write .extern _write -.text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _write: move.w #0x4,d0 move.l 4(sp),a0 move.l 8(sp),d1 From 4310641b88ee135f4fe04027fa69dd9589ac99fc Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 22 Jul 1986 13:37:16 +0000 Subject: [PATCH 0229/1625] Adapted to new assembler and made re-entrant. --- mach/m68k4/libem/LIST | 3 +- mach/m68k4/libem/Makefile | 36 +++++-- mach/m68k4/libem/aciaio.s | 13 ++- mach/m68k4/libem/ara.s | 55 +++++------ mach/m68k4/libem/ari.s | 30 +++--- mach/m68k4/libem/cii.s | 9 +- mach/m68k4/libem/cmi.s | 13 ++- mach/m68k4/libem/cmp.s | 13 ++- mach/m68k4/libem/cms.s | 6 +- mach/m68k4/libem/cmu.s | 17 ++-- mach/m68k4/libem/csa.s | 9 +- mach/m68k4/libem/csb.s | 8 +- mach/m68k4/libem/cuu.s | 7 +- mach/m68k4/libem/cvf.s | 7 +- mach/m68k4/libem/dia.s | 10 +- mach/m68k4/libem/dvi.s | 24 ++--- mach/m68k4/libem/dvu.s | 20 ++-- mach/m68k4/libem/end.s | 19 ++-- mach/m68k4/libem/exg.s | 12 ++- mach/m68k4/libem/fat.s | 6 +- mach/m68k4/libem/inn.s | 19 ++-- mach/m68k4/libem/lfr.s | 6 +- mach/m68k4/libem/los.s | 13 +-- mach/m68k4/libem/mli.s | 25 ++--- mach/m68k4/libem/mlu.s | 27 +++--- mach/m68k4/libem/mon.s | 11 ++- mach/m68k4/libem/nop.s | 8 +- mach/m68k4/libem/printf.s | 199 +++++++++++++++++++++++--------------- mach/m68k4/libem/rck.s | 14 +-- mach/m68k4/libem/ret.s | 6 +- mach/m68k4/libem/set.s | 16 +-- mach/m68k4/libem/shp.s | 13 +-- mach/m68k4/libem/sig.s | 13 +-- mach/m68k4/libem/sts.s | 13 +-- mach/m68k4/libem/sys1.s | 12 ++- mach/m68k4/libem/sys2.s | 6 +- mach/m68k4/libem/trp.s | 26 +++-- 37 files changed, 452 insertions(+), 292 deletions(-) diff --git a/mach/m68k4/libem/LIST b/mach/m68k4/libem/LIST index 1cbe1413..66c59fe4 100644 --- a/mach/m68k4/libem/LIST +++ b/mach/m68k4/libem/LIST @@ -1,4 +1,4 @@ -tail_em.a +libem_s.a ari.s ara.s cvf.s @@ -30,4 +30,3 @@ trp.s dia.s printf.s dvu.s -sav.s diff --git a/mach/m68k4/libem/Makefile b/mach/m68k4/libem/Makefile index e740e504..72404fbd 100644 --- a/mach/m68k4/libem/Makefile +++ b/mach/m68k4/libem/Makefile @@ -1,17 +1,33 @@ # $Header$ -install: - ../../install tail_em.a tail_em - ../../install end.s end_em +MACH=m68k4 +install: all + ../../install head_em.o head_em + ../../install libem_o.a tail_em.rt + ../../install end.o end_em -cmp: - -../../compare tail_em.a tail_em - -../../compare end.s end_em +cmp: all + -../../compare head_em.o head_em + -../../compare libem_o.a tail_em.rt + -../../compare end.o end_em -clean : +all: head_em.o libem_o.a end.o +end.o: end.s + $(MACH) -I../../../h -c end.s + +head_em.o: head_em.s + $(MACH) -I../../../h -c head_em.s + +libem_o.a: libem_s.a + ASAR=aal ; export ASAR ;\ + march . libem_o.a + +clean: + rm -f *.o opr : - make pr | opr + make pr | opr pr: - @arch pv tail_em.a | pr -h `pwd`/tail_em.a - @pr `pwd`/end.s + @pr `pwd`/head_em.s + @arch pv libem_s.a | pr -h `pwd`/libem_s.a + @pr `pwd`/end.s diff --git a/mach/m68k4/libem/aciaio.s b/mach/m68k4/libem/aciaio.s index eabc9a63..09577e1f 100644 --- a/mach/m68k4/libem/aciaio.s +++ b/mach/m68k4/libem/aciaio.s @@ -1,9 +1,13 @@ .define .outch1,.outch2,.inch1,.inch2 +.sect .text +.sect .rom +.sect .data +.sect .bss - ! a0,d4 used + ! a0,d0 used ! character in d1 - .text + .sect .text .inch1: move.l #acia1,a0 bra .inch @@ -23,11 +27,10 @@ .outch2: move.l #acia2,a0 .outch: - move.b (a0),d4 - asr #2,d4 + move.b (a0),d0 + asr #2,d0 bcc .outch move.b d1,2(a0) rts - .align 2 diff --git a/mach/m68k4/libem/ara.s b/mach/m68k4/libem/ara.s index 24869056..2f391a2a 100644 --- a/mach/m68k4/libem/ara.s +++ b/mach/m68k4/libem/ara.s @@ -1,15 +1,18 @@ .define .sar .define .lar .define .aar +.sect .text +.sect .rom +.sect .data +.sect .bss !register usage: ! a0 : descriptor address ! d0 : index ! a1 : base address - .text + .sect .text .aar: - movem.l d0/d1/a0/a1,.savreg - move.l (sp)+,.retara ! return address + move.l (sp)+,d2 ! return address move.l (sp)+,a0 ! descriptor address move.l (sp)+,d0 ! index move.l (sp)+,a1 ! base address @@ -19,85 +22,77 @@ jsr .mlu add.l d1,a1 ! address of element move.l a1,-(sp) ! returned on stack - move.l .retara,-(sp) - movem.l d0/d1/a0/a1,.savreg + move.l d2,-(sp) rts - .lar: ! register usage: like .aar - ! d2 : # bytes / element - movem.l d0/d1/d2/a0/a1,.savreg - move.l (sp)+,.retara ! return address + move.l (sp)+,d2 ! return address move.l (sp)+,a0 move.l (sp)+,d0 move.l (sp)+,a1 sub.l (a0),d0 - move.l 8(a0),d2 ! # bytes / element move.l d0,-(sp) - move.l d2,-(sp) + move.l 8(a0),d0 + move.l d0,-(sp) jsr .mlu add.l d1,a1 ! address of element - add.l d2,a1 ! a1++ because of predecrement + add.l 8(a0),a1 ! a1++ because of predecrement clr.l d1 !?nodig? - asr #1,d2 + asr #1,d0 bne 3f move.b -(a1),d1 ! 1 byte element move.l d1,-(sp) bra 5f 3: - asr #1,d2 + asr #1,d0 bne 4f move.w -(a1),d1 ! 2 byte element move.l d1,-(sp) bra 5f 4: - sub.l #1,d2 + sub.l #1,d0 1: move.l -(a1),-(sp) ! 4n byte element (n = 1,2,...) - dbf d2,1b + dbf d0,1b 5: - move.l .retara,-(sp) - movem.l .savreg,d0/d1/d2/a0/a1 + move.l d2,-(sp) rts .sar: !register usage: same as lar - movem.l d0/d1/a0/a1,.savreg - move.l (sp)+,.retara + move.l (sp)+,d2 move.l (sp)+,a0 move.l (sp)+,d0 move.l (sp)+,a1 sub.l (a0),d0 - move.l 8(a0),d2 ! # bytes / element move.l d0,-(sp) - move.l d2,-(sp) + move.l 8(a0),d0 ! # bytes / element + move.l d0,-(sp) jsr .mlu add.l d1,a1 clr.l d1 !?nodig? - asr #1,d2 + asr #1,d0 bne 3f move.l (sp)+,d1 move.b d1,(a1) ! 1 byte element bra 4f 3: - asr #1,d2 + asr #1,d0 bne 5f move.l (sp)+,d1 move.w d1,(a1) ! 2 byte element bra 4f 5: - sub.l #1,d2 + sub.l #1,d0 1: move.l (sp)+,(a1)+ ! 4n byte element (n = 1,2,...) - dbf d2,1b + dbf d0,1b 4: - move.l .retara,-(sp) - movem.l .savreg,d0/d1/a0/a1 + move.l d2,-(sp) rts -.data -.retara: .long 0 + .align 2 diff --git a/mach/m68k4/libem/ari.s b/mach/m68k4/libem/ari.s index 19d64260..cefb0f66 100644 --- a/mach/m68k4/libem/ari.s +++ b/mach/m68k4/libem/ari.s @@ -1,36 +1,36 @@ .define .sari .define .lari .define .aari +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text .aari: - move.l (sp)+,.retari ! return address + move.l (sp)+,d0 ! return address cmp.l #4, (sp)+ ! size of descriptor elements bne 9f - jsr .aar - move.l .retari,-(sp) - rts + move.l d0,-(sp) + jmp .aar .lari: - move.l (sp)+,.retari ! return address + move.l (sp)+,d0 ! return address cmp.l #4, (sp)+ ! size of descriptor elements bne 9f - jsr .lar - move.l .retari,-(sp) - rts + move.l d0,-(sp) + jmp .lar 9: move.w #EILLINS,-(sp) jmp .fat .sari: - move.l (sp)+,.retari ! return address + move.l (sp)+,d0 ! return address cmp.l #4, (sp)+ ! size of descriptor elements bne 9b - jsr .sar - move.l .retari,-(sp) - rts -.data -.retari: .long 0 + move.l d0,-(sp) + jmp .sar + .align 2 diff --git a/mach/m68k4/libem/cii.s b/mach/m68k4/libem/cii.s index fc827aa5..8523a706 100644 --- a/mach/m68k4/libem/cii.s +++ b/mach/m68k4/libem/cii.s @@ -1,8 +1,11 @@ .define .cii +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text .cii: - movem.l a0/d0/d1,.savreg move.l (sp)+,a0 ! return address move (sp)+,d0 ! destination size sub (sp)+,d0 ! destination - source size @@ -19,6 +22,6 @@ dbf d0,2b 3: move.l a0,-(sp) - movem.l .savreg,a0/d0/d1 rts + .align 2 diff --git a/mach/m68k4/libem/cmi.s b/mach/m68k4/libem/cmi.s index 79616ba5..37830b93 100644 --- a/mach/m68k4/libem/cmi.s +++ b/mach/m68k4/libem/cmi.s @@ -1,12 +1,15 @@ .define .cmi, .cmi_ +.sect .text +.sect .rom +.sect .data +.sect .bss ! NUM == 4 ! result in d1 - .text + .sect .text .cmi: .cmi_: - move.l (sp)+,.savret - move.l d0,.savd0 + move.l (sp)+,d2 move.l #1,d1 move.l (sp)+,d0 cmp.l (sp)+,d0 @@ -16,7 +19,7 @@ ble 2f neg.l d1 2: - move.l .savd0,d0 - move.l .savret,-(sp) + move.l d2,-(sp) rts + .align 2 diff --git a/mach/m68k4/libem/cmp.s b/mach/m68k4/libem/cmp.s index 61bdabba..d3a36245 100644 --- a/mach/m68k4/libem/cmp.s +++ b/mach/m68k4/libem/cmp.s @@ -1,9 +1,12 @@ .define .cmp +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text .cmp: - move.l (sp)+,.savret ! return address - move.l d0,.savd0 + move.l (sp)+,d2 ! return address move.l #1,d1 move.l (sp)+,d0 cmp.l (sp)+,d0 @@ -13,7 +16,7 @@ bcs 2f neg.l d1 2: - move.l .savd0,d0 - move.l .savret,-(sp) + move.l d2,-(sp) rts + .align 2 diff --git a/mach/m68k4/libem/cms.s b/mach/m68k4/libem/cms.s index 7f134b8c..b6f4a510 100644 --- a/mach/m68k4/libem/cms.s +++ b/mach/m68k4/libem/cms.s @@ -1,8 +1,12 @@ .define .cms +.sect .text +.sect .rom +.sect .data +.sect .bss ! d0 contains set size - .text + .sect .text .cms: move.l (sp)+,a2 ! return address move.l sp,a0 diff --git a/mach/m68k4/libem/cmu.s b/mach/m68k4/libem/cmu.s index b69ef89c..9f205159 100644 --- a/mach/m68k4/libem/cmu.s +++ b/mach/m68k4/libem/cmu.s @@ -1,12 +1,15 @@ .define .cmu +.sect .text +.sect .rom +.sect .data +.sect .bss ! d0 : # bytes of 1 block - .text + .sect .text .cmu: - movem.l d2/a0/a1/a2,.savreg - move.l (sp)+,a2 ! reta move.l sp,a0 ! top block - move.l sp,a1 + add.l #4,a0 + move.l a0,a1 add.l d0,a1 ! lower block move.l d0,d2 asr.l #2,d0 @@ -22,8 +25,8 @@ neg.l d1 ! less 3: asl.l #1,d2 + move.l (sp)+,a0 add.l d2,sp ! new sp - move.l a2,-(sp) - movem.l .savreg,d2/a0/a1/a2 - rts + jmp (a0) + .align 2 diff --git a/mach/m68k4/libem/csa.s b/mach/m68k4/libem/csa.s index 3f81ce1c..b81acb34 100644 --- a/mach/m68k4/libem/csa.s +++ b/mach/m68k4/libem/csa.s @@ -1,8 +1,11 @@ .define .csa +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text .csa: - movem.l d0/a0/a1/a2,.savreg move.l (sp)+,a0 ! case descriptor move.l (sp)+,d0 ! index move.l (a0)+,a1 ! default address @@ -21,9 +24,9 @@ beq 2f move.l a1,-(sp) ! jump address 3: - movem.l .savreg,d0/a0/a1/a2 rts ! not a real rts 2: move.w #ECASE,-(sp) jmp .fat + .align 2 diff --git a/mach/m68k4/libem/csb.s b/mach/m68k4/libem/csb.s index 88ed8043..a5376b18 100644 --- a/mach/m68k4/libem/csb.s +++ b/mach/m68k4/libem/csb.s @@ -1,8 +1,11 @@ .define .csb +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text .csb: - movem.l d0/d1/a0/a1,.savreg move.l (sp)+,a0 ! case descriptor move.l (sp)+,d0 ! index move.l (a0)+,a1 ! default jump address @@ -23,6 +26,5 @@ move.l (a0)+,a1 ! get jump address 4: move.l a1,-(sp) - movem.l .savreg,d0/d1/a0/a1 rts .align 2 diff --git a/mach/m68k4/libem/cuu.s b/mach/m68k4/libem/cuu.s index 3e56221e..f6587e77 100644 --- a/mach/m68k4/libem/cuu.s +++ b/mach/m68k4/libem/cuu.s @@ -1,8 +1,12 @@ .define .ciu .define .cui .define .cuu +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text .ciu: .cui: .cuu: @@ -18,4 +22,5 @@ clr -(sp) dbf d0,2b jmp (a0) + .align 2 diff --git a/mach/m68k4/libem/cvf.s b/mach/m68k4/libem/cvf.s index 59cc742b..74dcc928 100644 --- a/mach/m68k4/libem/cvf.s +++ b/mach/m68k4/libem/cvf.s @@ -1,6 +1,10 @@ .define .cfi,.cif,.cfu,.cuf,.cff +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text ! this is a dummy float conversion routine .cfi: @@ -13,4 +17,5 @@ sub (sp)+,d0 ! diff. in sizes sub d0,sp jmp (a0) + .align 2 diff --git a/mach/m68k4/libem/dia.s b/mach/m68k4/libem/dia.s index a9d7a0bd..fd06f9c6 100644 --- a/mach/m68k4/libem/dia.s +++ b/mach/m68k4/libem/dia.s @@ -1,12 +1,16 @@ .define .diagnos +.sect .text +.sect .rom +.sect .data +.sect .bss space = 040 del = 0177 - .text + .sect .text .diagnos: move.l hol0,-(sp) - move.l hol0+FILN_AD,d2 + move.l hol0+4,d2 beq 1f move.l d2,a0 move.l #40,d0 @@ -31,7 +35,7 @@ del = 0177 move.l #unknwn,d2 bra 2b - .data + .sect .data fmt: .asciz "%s, line %d: " unknwn: .asciz "unknown file" .align 2 diff --git a/mach/m68k4/libem/dvi.s b/mach/m68k4/libem/dvi.s index fc74fb4d..b1d5ed93 100644 --- a/mach/m68k4/libem/dvi.s +++ b/mach/m68k4/libem/dvi.s @@ -1,12 +1,15 @@ .define .dvi +.sect .text +.sect .rom +.sect .data +.sect .bss ! signed long divide - .text + .sect .text .dvi: - movem.l d0/d4,.savdvi - move.l (sp)+,.retdvi - move.l (sp)+,d0 - move.l (sp)+,d1 + move.l 4(sp),d0 + move.l 8(sp),d1 + move.l d4,-(sp) clr.l d4 tst.l d0 ! divisor bpl 1f @@ -32,11 +35,10 @@ bpl 6f neg.l d2 ! remainder 6: - movem.l .savdvi,d0/d4 - move.l .retdvi,-(sp) + move.l (sp)+,d4 + move.l (sp)+,a0 + add.l #8,sp + move.l a0,-(sp) rts -.data -.savdvi: .space 12 -.retdvi: .long 0 -.text + .align 2 diff --git a/mach/m68k4/libem/dvu.s b/mach/m68k4/libem/dvu.s index 9f595d6f..87b0e911 100644 --- a/mach/m68k4/libem/dvu.s +++ b/mach/m68k4/libem/dvu.s @@ -1,4 +1,8 @@ .define .dvu +.sect .text +.sect .rom +.sect .data +.sect .bss ! unsigned long divide ! register usage: @@ -6,12 +10,11 @@ ! d1 dividend ! exit : d1 quotient ! d2 remainder - .text + .sect .text .dvu: - movem.l d0/d3,.savreg - move.l (sp)+,.savret - move.l (sp)+,d0 - move.l (sp)+,d1 + move.l 4(sp),d0 + move.l 8(sp),d1 + move.l d3,-(sp) tst.l d0 bne 0f move.w #EIDIVZ,-(sp) @@ -28,7 +31,10 @@ add #1,d1 4: dbf d3,3b - movem.l .savreg,d0/d3 - move.l .savret,-(sp) + move.l (sp)+,d3 + move.l (sp)+,a0 + add.l #8,sp + move.l a0,-(sp) rts + .align 2 diff --git a/mach/m68k4/libem/end.s b/mach/m68k4/libem/end.s index 9225bd8c..37e1cef2 100644 --- a/mach/m68k4/libem/end.s +++ b/mach/m68k4/libem/end.s @@ -1,15 +1,16 @@ -.define endtext,enddata,endbss -.define _end, _etext, _edata +.define endtext,enddata,endbss,_etext,_edata,_end +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .end ! only for declaration of _end and endbss. - .text + .sect .text endtext: _etext: - .align 4 - .data + .sect .data enddata: _edata: - .align 4 - .bss - .align 4 -endbss: + .sect .end _end: +endbss: diff --git a/mach/m68k4/libem/exg.s b/mach/m68k4/libem/exg.s index 0107f799..396893b6 100644 --- a/mach/m68k4/libem/exg.s +++ b/mach/m68k4/libem/exg.s @@ -1,10 +1,13 @@ .define .exg +.sect .text +.sect .rom +.sect .data +.sect .bss ! d0 : exchange size in bytes - .text + .sect .text .exg: - move.l (sp)+,.savret - movem.l d1/a1/a2,.savreg + move.l (sp)+,d2 move.l sp,a1 sub.l d0,sp move.l sp,a2 @@ -21,6 +24,5 @@ sub #1,d1 bgt 1b move.l a1,sp - movem.l .savreg,d1/a1/a2 - move.l .savret,-(sp) + move.l d2,-(sp) rts diff --git a/mach/m68k4/libem/fat.s b/mach/m68k4/libem/fat.s index e6fbbb03..670a3cf6 100644 --- a/mach/m68k4/libem/fat.s +++ b/mach/m68k4/libem/fat.s @@ -1,6 +1,10 @@ .define .fat +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text .fat: jsr .trp jmp EXIT diff --git a/mach/m68k4/libem/inn.s b/mach/m68k4/libem/inn.s index 83e1c925..2e745287 100644 --- a/mach/m68k4/libem/inn.s +++ b/mach/m68k4/libem/inn.s @@ -1,16 +1,19 @@ .define .inn +.sect .text +.sect .rom +.sect .data +.sect .bss ! d0 : set size in bytes ! d1 : bitnumber - .text + .sect .text .inn: - movem.l d1/d2/a0/a1,.savreg - move.l (sp)+,.savret + move.l (sp)+,a1 move.l (sp)+,d1 - move.l sp,a1 - add.l d0,a1 + move.l d0,-(sp) move.l sp,a0 + add.l #4,a0 move.l d1,d2 asr.l #4,d2 !bchg.l #0,d2 @@ -25,7 +28,7 @@ 1: clr.l d0 2: - move.l a1,sp - movem.l .savreg,d1/d2/a0/a1 - move.l .savret,-(sp) + move.l (sp)+,d1 + add.l d1,sp + move.l a1,-(sp) rts diff --git a/mach/m68k4/libem/lfr.s b/mach/m68k4/libem/lfr.s index 51c06697..82e9d815 100644 --- a/mach/m68k4/libem/lfr.s +++ b/mach/m68k4/libem/lfr.s @@ -1,6 +1,10 @@ .define .lfr +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text .lfr: move.l (sp)+,a0 cmp #2,d7 diff --git a/mach/m68k4/libem/los.s b/mach/m68k4/libem/los.s index c15dc814..8ae239a2 100644 --- a/mach/m68k4/libem/los.s +++ b/mach/m68k4/libem/los.s @@ -1,11 +1,14 @@ .define .los +.sect .text +.sect .rom +.sect .data +.sect .bss ! d0 : # bytes ! a0 : source address - .text + .sect .text .los: - movem.l d0/a0,.savreg - move.l (sp)+,.savret + move.l (sp)+,a1 move.l (sp)+,d0 move.l (sp)+,a0 cmp.l #1,d0 @@ -30,7 +33,5 @@ sub.l #1,d0 bgt 4b 3: - movem.l .savreg,d0/a0 - move.l .savret,-(sp) - rts + jmp (a1) .align 2 diff --git a/mach/m68k4/libem/mli.s b/mach/m68k4/libem/mli.s index fe2e0ddc..27ed589b 100644 --- a/mach/m68k4/libem/mli.s +++ b/mach/m68k4/libem/mli.s @@ -1,12 +1,15 @@ .define .mli +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text .mli: - move.l d5,.savmli - move.l (sp)+,.retmli - move.l (sp)+,d1 - move.l (sp)+,d0 + move.l 4(sp),d1 + move.l 8(sp),d0 + move.l d5,-(sp) clr d5 tst.l d0 bpl 1f @@ -26,11 +29,9 @@ neg.l d1 negx.l d0 3: - move.l .savmli,d5 - move.l .retmli,-(sp) - rts -.data -.savmli: .long 0 -.retmli: .long 0 -.text + move.l (sp)+,d5 + move.l (sp)+,a0 + add.l #8,sp + jmp (a0) + .align 2 diff --git a/mach/m68k4/libem/mlu.s b/mach/m68k4/libem/mlu.s index 0235ec26..5c0a4f60 100644 --- a/mach/m68k4/libem/mlu.s +++ b/mach/m68k4/libem/mlu.s @@ -1,20 +1,24 @@ .define .mlu +.sect .text +.sect .rom +.sect .data +.sect .bss ! entry : d0 multiplicand ! d1 multiplier ! exit : d0 high order result ! d1 low order result - .text + .sect .text .mlu: - move.l (sp)+,.savret - move.l (sp)+,d1 - move.l (sp)+,d0 + movem.l d3/d4/d6,-(sp) + move.l 16(sp),d1 + move.l 20(sp),d0 cmp.l #32768,d0 bgt 1f cmp.l #32768,d1 bls 2f -1: movem.l d2/d3/d4/d6,.savreg +1: move.l d1,d3 move.l d1,d2 swap d2 @@ -36,12 +40,13 @@ swap d2 swap d3 add.l d2,d0 - add.l d3,d0 - movem.l .savreg,d2/d3/d4/d6 - move.l .savret,-(sp) - rts + add.l d3,a0 + bra 3f 2: mulu d0,d1 clr d0 - move.l .savret,-(sp) - rts +3: + movem.l (sp)+,d3/d4/d6 + move.l (sp)+,a0 + add #8,sp + jmp (a0) .align 2 diff --git a/mach/m68k4/libem/mon.s b/mach/m68k4/libem/mon.s index dabe65a9..38114a75 100644 --- a/mach/m68k4/libem/mon.s +++ b/mach/m68k4/libem/mon.s @@ -1,12 +1,17 @@ .define .mon - .text +.sect .text +.sect .rom +.sect .data +.sect .bss + + .sect .text .mon: move.l (sp)+,a0 pea fmt jsr .diagnos - add #6,sp + add #8,sp jmp EXIT - .data + .sect .data fmt: .asciz "system call %d not implemented" .align 2 diff --git a/mach/m68k4/libem/nop.s b/mach/m68k4/libem/nop.s index ed7720d1..d701c49f 100644 --- a/mach/m68k4/libem/nop.s +++ b/mach/m68k4/libem/nop.s @@ -1,6 +1,10 @@ .define .nop +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text .nop: pea 4(sp) move.l hol0,-(sp) @@ -9,6 +13,6 @@ add.l #12,sp rts - .data + .sect .data fmt: .asciz "test %d, sp %d\n" .align 2 diff --git a/mach/m68k4/libem/printf.s b/mach/m68k4/libem/printf.s index 6a500944..9de6290a 100644 --- a/mach/m68k4/libem/printf.s +++ b/mach/m68k4/libem/printf.s @@ -1,78 +1,125 @@ +.sect .text;.sect .rom;.sect .data;.sect .bss +.define _printn .define _printf -.define _putchar -.define _getal -.define _char -.bss -_getal: - .space 12 -_char: - .space 1 - .align 2 -.data -sav: - .long 0 -.text -_printf: - movem.l d0/d1/d2/a0/a1/a2/a3/a4/a5/a6,.savreg - move.l (sp)+,sav !return address - move.l sp,a6 !a6 <- address of arguments - move.l (a6)+,a5 !a5 <- address of format - clr.l d0 !d0 <- char to be printed -next: move.b (a5)+,d0 - beq out - cmp.b #'%',d0 - beq procnt -put: move.l d0,-(sp) - jsr _putchar !argument is long en op de stack - tst.l (sp)+ - jmp next - -procnt: move.b (a5)+,d0 - cmp.b #'d',d0 !NOTE: %d means unsigned. - beq digit - cmp.b #'s',d0 - beq string - cmp.b #'%',d0 !second % has to be printed. - beq put - tst.b -(a5) !normal char should be printed - jmp next - -string: move.l (a6)+,a2 !a2 <- address of string -sloop: move.b (a2)+,d0 - beq next - move.l d0,-(sp) - jsr _putchar !argument is long en op de stack - tst.l (sp)+ - jmp sloop - -digit: move.l (a6)+,d1 !d1 <- integer - move.l #_getal+12,a3 !a3 <- ptr to last part of buf - move.b #0,-(a3) !stringterminator -dloop: move.l d1,-(sp) - move.l #10,-(sp) - jsr .dvu !d1 <- quotient d2 <- remainder - add.l #'0',d2 - move.b d2,-(a3) - tst.l d1 !if quotient = 0 then ready - bne dloop - move.l a3,a2 - jmp sloop !print digitstring. - -out: - move.l sav,-(sp) - movem.l .savreg,d0/d1/d2/a0/a1/a2/a3/a4/a5/a6 - rts - - +.extern _printf +.sect .text _putchar: - movem.l d0,.savreg - move.l 4(sp),d0 - move.b d0,_char - move.l #1,-(sp) - move.l #_char,-(sp) - move.l #1,-(sp) - jsr _write - add.l #12,sp - movem.l .savreg,d0 - rts -.align 2 +move.l #1,-(sp) +pea 9(sp) +move.l #1,-(sp) +jsr _write +add.l #12,sp +rts +_printf: +tst.b -56(sp) +link a6,#-16 +!Local -4 into d7 +!Local -12 into d6 +!Local -8 into a5 +!Local 8 into a4 +!Local -16 into a3 +movem.l d7/d6/a5/a4/a3,-(sp) +move.l 8(a6),a4 +lea 12(a6),a1 +move.l a1, a5 +I0014: +move.l a4, a0 +add.l #1,a4 +clr.l d0 +move.b (a0),d0 +move.l d0, d7 +cmp.l #37,d7 +beq I0015 +tst.l d7 +beq I0012 +move.l d7,-(sp) +jsr _putchar +add #4,sp +jmp I0014 +I0015: +move.l a4, a0 +add.l #1,a4 +clr.l d0 +move.b (a0),d0 +move.l d0, d7 +cmp.l #100,d7 +beq I0018 +cmp.l #117,d7 +bne I0017 +I0018: +move.l a5, a0 +add.l #4,a5 +move.l (a0), d6 +cmp.l #100,d7 +bne I0019 +tst.l d6 +bge I0019 +clr.l d2 +sub.l d6,d2 +move.l d2, d6 +pea 45 +jsr _putchar +add #4,sp +I0019: +move.l d6,-(sp) +jsr _printn +add #4,sp +jmp I0014 +I0017: +cmp.l #115,d7 +bne I0014 +move.l a5, a0 +add.l #4,a5 +move.l (a0), a3 +I001c: +move.l a3, a0 +add.l #1,a3 +clr.l d0 +move.b (a0),d0 +move.l d0, d7 +tst.l d7 +beq I0014 +move.l d7,-(sp) +jsr _putchar +add #4,sp +jmp I001c +I0012: +movem.l (sp)+,d7/d6/a5/a4/a3 +unlk a6 +rts +.extern _printn +_printn: +tst.b -44(sp) +link a6,#-4 +!Local -4 into d7 +move.l d7,-(sp) +.sect .data +_14: +.data4 808530483 +.data4 875902519 +.data4 943259648 +.sect .text +move.l 8(a6),-(sp) +pea 10 +jsr .dvu +move.l d1, d7 +tst.l d7 +beq I0023 +move.l d7,-(sp) +jsr _printn +add #4,sp +I0023: +pea _14 +move.l 8(a6),-(sp) +pea 10 +jsr .dvu +move.l (sp)+,a1 +add.l d2,a1 +clr.l d0 +move.b (a1),d0 +move.l d0,-(sp) +jsr _putchar +add #4,sp +move.l (sp)+,d7 +unlk a6 +rts diff --git a/mach/m68k4/libem/rck.s b/mach/m68k4/libem/rck.s index 6d935e86..5b55a91c 100644 --- a/mach/m68k4/libem/rck.s +++ b/mach/m68k4/libem/rck.s @@ -1,9 +1,12 @@ .define .rck +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text .rck: - movem.l d0/a0,.savreg - move.l (sp)+,.savret + move.l (sp)+,a1 move.l (sp)+,a0 ! descriptor address move.l (sp),d0 cmp.l (a0),d0 @@ -14,7 +17,6 @@ move.l #ERANGE,-(sp) jsr .trp 2: - movem.l .savreg,d0/a0 - move.l .savret,-(sp) - rts + jmp (a1) + .align 2 diff --git a/mach/m68k4/libem/ret.s b/mach/m68k4/libem/ret.s index ba5c2f03..2e5bd189 100644 --- a/mach/m68k4/libem/ret.s +++ b/mach/m68k4/libem/ret.s @@ -1,6 +1,10 @@ .define .ret +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text .ret: beq 3f cmp #2,d0 diff --git a/mach/m68k4/libem/set.s b/mach/m68k4/libem/set.s index c5c6038b..4091243a 100644 --- a/mach/m68k4/libem/set.s +++ b/mach/m68k4/libem/set.s @@ -1,11 +1,14 @@ .define .set +.sect .text +.sect .rom +.sect .data +.sect .bss ! d0 : setsize in bytes ! d1 : bitnumber - .text + .sect .text .set: - movem.l d1/d2/a1,.savreg - move.l (sp)+,.savret + move.l (sp)+,a0 move.l (sp)+,d1 move.l d0,d2 asr.l #2,d2 @@ -20,13 +23,10 @@ cmp.l d0,d2 bcs 1f move.w #ESET,-(sp) - move.l .savret,-(sp) - jmp .trp + jsr .trp 1: add.l d2,a1 move.l (a1),d2 bset d1,d2 move.l d2,(a1) - movem.l .savreg,d1/d2/a1 - move.l .savret,-(sp) - rts + jmp (a0) diff --git a/mach/m68k4/libem/shp.s b/mach/m68k4/libem/shp.s index 2e60f1b0..a4be6733 100644 --- a/mach/m68k4/libem/shp.s +++ b/mach/m68k4/libem/shp.s @@ -1,9 +1,12 @@ .define .strhp +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text .strhp: - move.l d0,.savreg - move.l (sp)+,.savret + move.l (sp)+,a0 move.l (sp)+,d0 ! heap pointer move.l d0,.reghp cmp.l .limhp,d0 @@ -14,9 +17,7 @@ cmp.l d0,sp ble 2f 1: - move.l .savreg,d0 - move.l .savret,-(sp) - rts + jmp (a0) 2: move.w #EHEAP,-(sp) jmp .fat diff --git a/mach/m68k4/libem/sig.s b/mach/m68k4/libem/sig.s index 491d0cf5..2d5afad5 100644 --- a/mach/m68k4/libem/sig.s +++ b/mach/m68k4/libem/sig.s @@ -1,13 +1,14 @@ .define .sig +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text .sig: - movem.l a1/a2,.savreg - move.l (sp)+,.savret + move.l (sp)+,a0 move.l (sp)+,a1 ! trap pc move.l .trppc,-(sp) move.l a1,.trppc - movem.l .savreg,a1/a2 - move.l .savret,-(sp) - rts + jmp (a0) .align 2 diff --git a/mach/m68k4/libem/sts.s b/mach/m68k4/libem/sts.s index 17d78807..fe63e2b0 100644 --- a/mach/m68k4/libem/sts.s +++ b/mach/m68k4/libem/sts.s @@ -1,11 +1,14 @@ .define .sts +.sect .text +.sect .rom +.sect .data +.sect .bss ! d0 : # bytes ! a0 : destination address - .text + .sect .text .sts: - movem.l d0/a0,.savreg - move.l (sp)+,.savret + move.l (sp)+,a1 move.l (sp)+,d0 move.l (sp)+,a0 cmp #1,d0 @@ -27,7 +30,5 @@ move.l (sp)+,(a0)+ dbf d0,3b 4: - movem.l .savreg,d0/a0 - move.l .savret,-(sp) - rts + jmp (a1) .align 2 diff --git a/mach/m68k4/libem/sys1.s b/mach/m68k4/libem/sys1.s index 99cd6304..49a3d759 100644 --- a/mach/m68k4/libem/sys1.s +++ b/mach/m68k4/libem/sys1.s @@ -1,18 +1,22 @@ .extern _errno -.data +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .data _errno: .extern _lseek .short 0 -.text +.sect .text _lseek: link a6,#-0 -.data +.sect .data _13: .short 29561 .short 29489 .short 11875 .short 0 -.text +.sect .text move.l #_13,.filn move.w #8,.lino move.w #0,-(sp) diff --git a/mach/m68k4/libem/sys2.s b/mach/m68k4/libem/sys2.s index fce0ee6e..661f2fb5 100644 --- a/mach/m68k4/libem/sys2.s +++ b/mach/m68k4/libem/sys2.s @@ -1,7 +1,11 @@ .extern _exit +.sect .text +.sect .rom +.sect .data +.sect .bss ! Fake system call for 68000 running MACSBUG -.text +.sect .text _exit: jmp 0x0200f6 diff --git a/mach/m68k4/libem/trp.s b/mach/m68k4/libem/trp.s index 6afacad1..0978c898 100644 --- a/mach/m68k4/libem/trp.s +++ b/mach/m68k4/libem/trp.s @@ -1,31 +1,41 @@ .define .trp +.sect .text +.sect .rom +.sect .data +.sect .bss - .text + .sect .text .trp: - move.l (sp)+,a2 ! return address - move.l (sp)+,d0 ! error number - move.l a2,-(sp) - move.l d0,-(sp) - cmp.l #16,d0 + cmp.l #16,4(sp) bcc 1f + move.l d0,-(sp) + move.l 8(sp),d0 btst d0,.trpim bne 3f 1: + move.l a0,-(sp) move.l .trppc,a0 move.l a0,d0 beq 9f clr.l .trppc + move.l 12(sp),-(sp) jsr (a0) + add.l #4,sp + move.l (sp)+,a0 3: - add #4,sp + move.l (sp)+,d0 + move.l (sp)+,(sp) rts 9: + move.l (sp)+,a0 + move.l (sp)+,d0 + move.l 4(sp),-(sp) pea fmt jsr .diagnos add #4,sp jsr __cleanup jmp EXIT - .data + .sect .data fmt: .asciz "trap %d called\n" .align 2 From b72b2e98f1a20692ed5bc2936a0826601e36a42d Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 22 Jul 1986 13:42:21 +0000 Subject: [PATCH 0230/1625] Adapted to the use of the new assembler. --- mach/m68k4/libbc/Makefile | 4 ++-- mach/m68k4/libbc/compmodule | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/mach/m68k4/libbc/Makefile b/mach/m68k4/libbc/Makefile index 9745cc47..a4a75655 100644 --- a/mach/m68k4/libbc/Makefile +++ b/mach/m68k4/libbc/Makefile @@ -1,5 +1,5 @@ MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=m68k4" "SUF=o" +MACHDEF="MACH=m68k4" "SUF=o" "ASAR=aal" BCDEF="PREF=bc" "SUB=" "SRC=lang/basic/lib" install: @@ -11,7 +11,7 @@ cmp: -../../compare tail_bc clean: - -rm -f *.old *.[ce$(SUF)] tail* head* + -rm -f *.old *.[ceo] tail* head* opr: make pr | opr diff --git a/mach/m68k4/libbc/compmodule b/mach/m68k4/libbc/compmodule index 491f6d25..6327cb99 100755 --- a/mach/m68k4/libbc/compmodule +++ b/mach/m68k4/libbc/compmodule @@ -1,2 +1,6 @@ -${MACH?} -I../../../h ${MACHFL?} $1 1>&2 -echo `basename $1 $2`.o +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then + echo `basename $1 $2`.o +else + exit 1 +fi From 10fa57ef52c10be7503b9f462dfafc988e7c0690 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 22 Jul 1986 14:49:46 +0000 Subject: [PATCH 0231/1625] *** empty log message *** --- mach/m68k4/libem/ara.s | 37 ++++++++++++++++++------------------- mach/m68k4/libem/printf.s | 7 +++++-- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/mach/m68k4/libem/ara.s b/mach/m68k4/libem/ara.s index 2f391a2a..bc90ea2a 100644 --- a/mach/m68k4/libem/ara.s +++ b/mach/m68k4/libem/ara.s @@ -12,26 +12,25 @@ ! a1 : base address .sect .text .aar: - move.l (sp)+,d2 ! return address - move.l (sp)+,a0 ! descriptor address - move.l (sp)+,d0 ! index - move.l (sp)+,a1 ! base address + move.l 4(sp),a0 ! descriptor address + move.l 8(sp),d0 ! index + move.l 12(sp),a1 ! base address sub.l (a0),d0 ! index - lower bound : relative index move.l 8(a0),-(sp) ! # bytes / element move.l d0,-(sp) jsr .mlu add.l d1,a1 ! address of element + move.l (sp)+,a0 ! return address + add.l #12,sp ! pop arguments move.l a1,-(sp) ! returned on stack - move.l d2,-(sp) - rts + jmp (a0) .lar: ! register usage: like .aar - move.l (sp)+,d2 ! return address - move.l (sp)+,a0 - move.l (sp)+,d0 - move.l (sp)+,a1 + move.l 4(sp),a0 + move.l 8(sp),d0 + move.l 12(sp),a1 sub.l (a0),d0 move.l d0,-(sp) move.l 8(a0),d0 @@ -39,6 +38,8 @@ jsr .mlu add.l d1,a1 ! address of element add.l 8(a0),a1 ! a1++ because of predecrement + move.l (sp)+,a0 ! return address + add.l #12,sp ! pop parameters clr.l d1 !?nodig? asr #1,d0 bne 3f @@ -57,23 +58,22 @@ move.l -(a1),-(sp) ! 4n byte element (n = 1,2,...) dbf d0,1b 5: - move.l d2,-(sp) - rts - + jmp (a0) .sar: !register usage: same as lar - move.l (sp)+,d2 - move.l (sp)+,a0 - move.l (sp)+,d0 - move.l (sp)+,a1 + move.l 4(sp),a0 + move.l 8(sp),d0 + move.l 12(sp),a1 sub.l (a0),d0 move.l d0,-(sp) move.l 8(a0),d0 ! # bytes / element move.l d0,-(sp) jsr .mlu add.l d1,a1 + move.l (sp)+,a0 ! return address + add.l #12,sp ! pop parameters clr.l d1 !?nodig? asr #1,d0 bne 3f @@ -92,7 +92,6 @@ move.l (sp)+,(a1)+ ! 4n byte element (n = 1,2,...) dbf d0,1b 4: - move.l d2,-(sp) - rts + jmp (a0) .align 2 diff --git a/mach/m68k4/libem/printf.s b/mach/m68k4/libem/printf.s index 9de6290a..16826c04 100644 --- a/mach/m68k4/libem/printf.s +++ b/mach/m68k4/libem/printf.s @@ -1,11 +1,14 @@ -.sect .text;.sect .rom;.sect .data;.sect .bss .define _printn .define _printf .extern _printf +.sect .text;.sect .rom;.sect .data;.sect .bss .sect .text _putchar: move.l #1,-(sp) -pea 9(sp) +lea 8(sp),a0 +move.l 8(sp),d0 +move.b d0,(a0) +move.l a0,-(sp) move.l #1,-(sp) jsr _write add.l #12,sp From 9d4acc9c3ac8e27d3d53dbaf37cd450a195fb933 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 22 Jul 1986 15:11:09 +0000 Subject: [PATCH 0232/1625] Bug fix. It just did'nt work. --- mach/m68k4/libem/ara.s | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/mach/m68k4/libem/ara.s b/mach/m68k4/libem/ara.s index bc90ea2a..929ada9e 100644 --- a/mach/m68k4/libem/ara.s +++ b/mach/m68k4/libem/ara.s @@ -14,15 +14,15 @@ .aar: move.l 4(sp),a0 ! descriptor address move.l 8(sp),d0 ! index - move.l 12(sp),a1 ! base address sub.l (a0),d0 ! index - lower bound : relative index move.l 8(a0),-(sp) ! # bytes / element move.l d0,-(sp) jsr .mlu + move.l 12(sp),a1 ! base address add.l d1,a1 ! address of element move.l (sp)+,a0 ! return address - add.l #12,sp ! pop arguments - move.l a1,-(sp) ! returned on stack + add.l #8,sp ! pop arguments + move.l a1,(sp) ! returned on stack jmp (a0) .lar: @@ -33,14 +33,16 @@ move.l 12(sp),a1 sub.l (a0),d0 move.l d0,-(sp) - move.l 8(a0),d0 - move.l d0,-(sp) + move.l 8(a0),-(sp) jsr .mlu + move.l 12(sp),a1 + move.l 4(sp),a0 add.l d1,a1 ! address of element add.l 8(a0),a1 ! a1++ because of predecrement move.l (sp)+,a0 ! return address add.l #12,sp ! pop parameters clr.l d1 !?nodig? + move.l 8(a0),d0 asr #1,d0 bne 3f move.b -(a1),d1 ! 1 byte element @@ -68,10 +70,12 @@ move.l 12(sp),a1 sub.l (a0),d0 move.l d0,-(sp) - move.l 8(a0),d0 ! # bytes / element - move.l d0,-(sp) + move.l 8(a0),-(sp) jsr .mlu + move.l 12(sp),a1 + move.l 4(sp),a0 add.l d1,a1 + move.l 8(a0),d0 ! # bytes / element move.l (sp)+,a0 ! return address add.l #12,sp ! pop parameters clr.l d1 !?nodig? From 41de09df241651dcbbd7814eb60fe97a77cdd2fa Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 23 Jul 1986 11:04:40 +0000 Subject: [PATCH 0233/1625] Added a ".sect .text". The text "landed" in the bss segment. --- mach/m68k4/libsys/stime.s | 1 + mach/m68k4/libsys/stty.s | 1 + mach/m68k4/libsys/sync.s | 1 + 3 files changed, 3 insertions(+) diff --git a/mach/m68k4/libsys/stime.s b/mach/m68k4/libsys/stime.s index f1a7a560..57ecbb69 100644 --- a/mach/m68k4/libsys/stime.s +++ b/mach/m68k4/libsys/stime.s @@ -1,5 +1,6 @@ .define _stime .extern _stime +.sect .text .sect .rom .sect .data .sect .bss diff --git a/mach/m68k4/libsys/stty.s b/mach/m68k4/libsys/stty.s index 47a75b34..0de8f974 100644 --- a/mach/m68k4/libsys/stty.s +++ b/mach/m68k4/libsys/stty.s @@ -1,5 +1,6 @@ .define _stty .extern _stty +.sect .text .sect .rom .sect .data .sect .bss diff --git a/mach/m68k4/libsys/sync.s b/mach/m68k4/libsys/sync.s index 179c70e3..a33454b7 100644 --- a/mach/m68k4/libsys/sync.s +++ b/mach/m68k4/libsys/sync.s @@ -1,5 +1,6 @@ .define _sync .extern _sync +.sect .text .sect .rom .sect .data .sect .bss From 829243f8b1ec9c4c1b5d394330d7d3e2228fa468 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 23 Jul 1986 11:06:29 +0000 Subject: [PATCH 0234/1625] Made tail_mon dependant on tail_mon.a --- mach/m68k4/libsys/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/m68k4/libsys/Makefile b/mach/m68k4/libsys/Makefile index 37bd1e20..8908c873 100644 --- a/mach/m68k4/libsys/Makefile +++ b/mach/m68k4/libsys/Makefile @@ -7,7 +7,7 @@ install: all cmp: all -../../compare tail_mon -tail_mon: +tail_mon: tail_mon.a ASAR=aal ; export ASAR ;\ march . tail_mon From 686c0aee932e378841febbc14fdc134a2ee38940 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 25 Jul 1986 13:19:51 +0000 Subject: [PATCH 0235/1625] Bug fix --- mach/m68k4/libem/ara.s | 4 ++-- mach/m68k4/libem/rck.s | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mach/m68k4/libem/ara.s b/mach/m68k4/libem/ara.s index 929ada9e..e4e9ab19 100644 --- a/mach/m68k4/libem/ara.s +++ b/mach/m68k4/libem/ara.s @@ -38,11 +38,11 @@ move.l 12(sp),a1 move.l 4(sp),a0 add.l d1,a1 ! address of element - add.l 8(a0),a1 ! a1++ because of predecrement + move.l 8(a0),d0 + add.l d0,a1 ! a1++ because of predecrement move.l (sp)+,a0 ! return address add.l #12,sp ! pop parameters clr.l d1 !?nodig? - move.l 8(a0),d0 asr #1,d0 bne 3f move.b -(a1),d1 ! 1 byte element diff --git a/mach/m68k4/libem/rck.s b/mach/m68k4/libem/rck.s index 5b55a91c..bb214893 100644 --- a/mach/m68k4/libem/rck.s +++ b/mach/m68k4/libem/rck.s @@ -11,7 +11,7 @@ move.l (sp),d0 cmp.l (a0),d0 blt 1f - cmp.l 2(a0),d0 + cmp.l 4(a0),d0 ble 2f 1: move.l #ERANGE,-(sp) From 3e5c4dbe94a8193f33628b711e55546651d6b827 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 25 Jul 1986 14:17:23 +0000 Subject: [PATCH 0236/1625] Bug fix --- mach/m68k4/libem/inn.s | 9 +++------ mach/m68k4/libem/set.s | 7 ++----- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/mach/m68k4/libem/inn.s b/mach/m68k4/libem/inn.s index 2e745287..2bc4c6e0 100644 --- a/mach/m68k4/libem/inn.s +++ b/mach/m68k4/libem/inn.s @@ -15,13 +15,11 @@ move.l sp,a0 add.l #4,a0 move.l d1,d2 - asr.l #4,d2 - !bchg.l #0,d2 + asr.l #3,d2 cmp.l d0,d2 bcc 1f add.l d2,a0 - move.l (a0),d2 - btst d1,d2 !eigenlijk .l + btst d1,(a0) beq 1f move.l #1,d0 bra 2f @@ -30,5 +28,4 @@ 2: move.l (sp)+,d1 add.l d1,sp - move.l a1,-(sp) - rts + jmp (a1) diff --git a/mach/m68k4/libem/set.s b/mach/m68k4/libem/set.s index 4091243a..7a928772 100644 --- a/mach/m68k4/libem/set.s +++ b/mach/m68k4/libem/set.s @@ -18,15 +18,12 @@ bgt 1b move.l sp,a1 ! set base move.l d1,d2 - asr.l #4,d2 - !bchg #0,d2 + asr.l #3,d2 cmp.l d0,d2 bcs 1f move.w #ESET,-(sp) jsr .trp 1: add.l d2,a1 - move.l (a1),d2 - bset d1,d2 - move.l d2,(a1) + bset d1,(a1) jmp (a0) From 8c8fb9a5b7713ac4f94a5715378224d7554d61d8 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 25 Jul 1986 15:01:15 +0000 Subject: [PATCH 0237/1625] inn and set must be word-orientated, not byte-orientated. --- mach/m68k4/libem/inn.s | 5 ++++- mach/m68k4/libem/set.s | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/mach/m68k4/libem/inn.s b/mach/m68k4/libem/inn.s index 2bc4c6e0..ef017627 100644 --- a/mach/m68k4/libem/inn.s +++ b/mach/m68k4/libem/inn.s @@ -18,8 +18,11 @@ asr.l #3,d2 cmp.l d0,d2 bcc 1f + bclr #0,d2 + bclr #1,d2 add.l d2,a0 - btst d1,(a0) + move.l (a0),d2 + btst d1,d2 beq 1f move.l #1,d0 bra 2f diff --git a/mach/m68k4/libem/set.s b/mach/m68k4/libem/set.s index 7a928772..f413311b 100644 --- a/mach/m68k4/libem/set.s +++ b/mach/m68k4/libem/set.s @@ -24,6 +24,10 @@ move.w #ESET,-(sp) jsr .trp 1: + bclr #0,d2 + bclr #1,d2 add.l d2,a1 - bset d1,(a1) + clr.l d2 + bset d1,d2 + move.l d2,(a1) jmp (a0) From 6faf0887c3ce15991d1198ba2bd20a1d32e493dc Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 25 Jul 1986 15:57:03 +0000 Subject: [PATCH 0238/1625] Bug fix: the BLS instruction did'nt work with block moves of one word. --- mach/m68k2/cg/table | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mach/m68k2/cg/table b/mach/m68k2/cg/table index 17136980..62f8dcb3 100644 --- a/mach/m68k2/cg/table +++ b/mach/m68k2/cg/table @@ -2725,9 +2725,9 @@ blm $1 > 12 | ADDSCR ADDSCR | remove(MEM_ALL) /* Wait for restriction nregneeded<2 to be removed bls $1 == 2 | DATASCR ADDSCR ADDSCR | remove(MEM_ALL) - "sub.w #1,%[1]" "asr #1,%[1]" - "beq 2f" + "sub.w #1,%[1]" + "blt 2f" "1:" "move.w (%[3])+,(%[2])+" "dbf %[1],1b" @@ -2741,9 +2741,9 @@ bls $1 == 2 | STACK | "move.w (sp)+,%[c]" "move.l (sp)+,%[b]" "move.l (sp)+,%[a]" - "sub.w #1,%[c]" "asr #1,%[c]" - "beq 2f" + "sub.w #1,%[c]" + "blt 2f" "1:" "move.w (%[a])+,(%[b])+" "dbf %[c],1b" From 9f2c3e618686ed695af65243b6bbb1b5affca07b Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 25 Jul 1986 16:08:56 +0000 Subject: [PATCH 0239/1625] Added a test for BLS with a blockmove of wordsize bytes. --- emtest/tests | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/emtest/tests b/emtest/tests index 0479430f..25220012 100644 --- a/emtest/tests +++ b/emtest/tests @@ -1871,6 +1871,16 @@ OK TEST 084: test bls WS HOL 40 MAIN 32 + loc 20 + stl -8 + lal -8 + lae 20 + loc WS + bls WS + loe 20 + loc 20 + bne *1 +OK loc 55 stl -8+WS loc 56 From 1d5a5e0a6d79ee4ccfa84416d4f791aef57c8fe4 Mon Sep 17 00:00:00 2001 From: erikb Date: Tue, 29 Jul 1986 11:46:00 +0000 Subject: [PATCH 0240/1625] added -T option: create temporary file(s) in directory --- lang/cem/cemcom/main.c | 12 ++++++++++-- lang/cem/cemcom/options | 1 + lang/cem/cemcom/options.c | 13 +++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lang/cem/cemcom/main.c b/lang/cem/cemcom/main.c index 0c95935f..614eb5cc 100644 --- a/lang/cem/cemcom/main.c +++ b/lang/cem/cemcom/main.c @@ -123,13 +123,18 @@ char *nmlist = 0; #ifdef USE_TMP extern char *mktemp(); /* library routine */ -static char tmpname[] = "/tmp/Cem.XXXXXX"; +char *tmpfdir = "/tmp"; /* where to keep the temporary file */ +static char *tmpfname = "/Cem.XXXXXX"; char *tmpfile = 0; #endif USE_TMP compile(argc, argv) char *argv[]; { +#ifdef USE_TMP + char tmpf[256]; +#endif + #ifndef NOPP int pp_only = options['E'] || options['P']; #endif NOPP @@ -155,8 +160,11 @@ compile(argc, argv) } #ifdef USE_TMP - tmpfile = mktemp(tmpname); + strcpy(tmpf, tmpfdir); + strcat(tmpf, tmpfname); + tmpfile = mktemp(tmpf); #endif USE_TMP + if (strcmp(destination, "-") == 0) destination = 0; if (!InsertFile(source, (char **) 0)) /* read the source file */ diff --git a/lang/cem/cemcom/options b/lang/cem/cemcom/options index dc432c55..d1faf7cf 100644 --- a/lang/cem/cemcom/options +++ b/lang/cem/cemcom/options @@ -9,6 +9,7 @@ p generate linenumbers and filename indications while generating compact EM code P in running the preprocessor do not output '# line' lines R restricted C +T take path following as directory for storing temporary file(s) U undefine predefined name V set objectsize and alignment requirements w suppress warning diagnostics diff --git a/lang/cem/cemcom/options.c b/lang/cem/cemcom/options.c index a21456ea..79416b40 100644 --- a/lang/cem/cemcom/options.c +++ b/lang/cem/cemcom/options.c @@ -12,6 +12,7 @@ #include "sizes.h" #include "align.h" #include "storage.h" +#include "use_tmp.h" #ifndef NOPP extern char *inctable[MAXINCL]; @@ -20,6 +21,7 @@ extern int inc_pos; extern char options[]; extern int idfsize; +extern char *tmpfdir; /* main.c */ int txt2int(); @@ -130,6 +132,17 @@ do_option(text) #endif NOPP break; +#ifdef USE_TMP + case 'T' : + if (*text) + tmpfdir = text; + else + tmpfdir = "."; +#else USE_TMP + warning("-T option ignored"); +#endif USE_TMP + break; + case 'U' : { /* -Uname : undefine predefined */ #ifndef NOPP struct idf *idef; From 1b7821a87ed410abe5208cb853a759bcd44f109e Mon Sep 17 00:00:00 2001 From: erikb Date: Tue, 29 Jul 1986 12:49:38 +0000 Subject: [PATCH 0241/1625] added some #ifdef USE_TMP lines --- lang/cem/cemcom/options.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lang/cem/cemcom/options.c b/lang/cem/cemcom/options.c index 79416b40..7569fc49 100644 --- a/lang/cem/cemcom/options.c +++ b/lang/cem/cemcom/options.c @@ -21,7 +21,9 @@ extern int inc_pos; extern char options[]; extern int idfsize; +#ifdef USE_TMP extern char *tmpfdir; /* main.c */ +#endif USE_TMP int txt2int(); From 736a5ff99b8bc44db133f89699c69dc27d8624fb Mon Sep 17 00:00:00 2001 From: erikb Date: Wed, 13 Aug 1986 10:05:39 +0000 Subject: [PATCH 0242/1625] revised the treatment of "e op= f" expression --- lang/cem/cemcom/Files | 1 + lang/cem/cemcom/ch7.c | 104 +++++++++++++---------------------- lang/cem/cemcom/ch7bin.c | 36 +++++++++++- lang/cem/cemcom/conversion.c | 1 + lang/cem/cemcom/dumpidf.c | 8 ++- lang/cem/cemcom/eval.c | 14 +++-- lang/cem/cemcom/field.c | 34 ++++++------ 7 files changed, 106 insertions(+), 92 deletions(-) diff --git a/lang/cem/cemcom/Files b/lang/cem/cemcom/Files index 9b7abae1..26fb953f 100644 --- a/lang/cem/cemcom/Files +++ b/lang/cem/cemcom/Files @@ -75,6 +75,7 @@ statement.g stb.c storage.c storage.h +stmt.str struct.c struct.str switch.c diff --git a/lang/cem/cemcom/ch7.c b/lang/cem/cemcom/ch7.c index ab173731..9c5819ed 100644 --- a/lang/cem/cemcom/ch7.c +++ b/lang/cem/cemcom/ch7.c @@ -192,9 +192,6 @@ ch7cast(expp, oper, tp) if ((*expp)->ex_class == String) string2pointer(expp); oldtp = (*expp)->ex_type; - if (oldtp == tp) - {} /* life is easy */ - else #ifndef NOBITFIELD if (oldtp->tp_fund == FIELD) { field2arith(expp); @@ -205,6 +202,9 @@ ch7cast(expp, oper, tp) ch7cast(expp, oper, tp->tp_up); else #endif NOBITFIELD + if (oldtp == tp) + {} /* life is easy */ + else if (tp->tp_fund == VOID) /* Easy again */ (*expp)->ex_type = void_type; else @@ -311,6 +311,17 @@ ch7asgn(expp, oper, expr) struct expr *expr; { /* The assignment operators. + "f op= e" should be interpreted as + "f = (typeof f)((typeof (f op e))f op (typeof (f op e))e)" + and not as "f = f op (typeof f)e". + Consider, for example, (i == 10) i *= 0.9; (i == 9), where + typeof i == int. + The resulting expression tree becomes: + op= + / \ + / \ + f (typeof (f op e))e + EVAL should however take care of evaluating (typeof (f op e))f */ int fund = (*expp)->ex_type->tp_fund; @@ -320,48 +331,30 @@ ch7asgn(expp, oper, expr) (*expp)->ex_depth = 99; /* no direct store/load at EVAL() */ /* what is 99 ??? DG */ } - switch (oper) { - case '=': + if (oper == '=') { ch7cast(&expr, oper, (*expp)->ex_type); - break; - case TIMESAB: - case DIVAB: - case MODAB: - check_arith_type(expp, oper); - any2arith(&expr, oper); - ch7cast(&expr, CAST, (*expp)->ex_type); - break; - case PLUSAB: - case MINAB: - any2arith(&expr, oper); - if (fund == POINTER) { - check_integral_type(&expr, oper); - ch7bin(&expr, '*', - intexpr( - size_of_type( - (*expp)->ex_type->tp_up, - "object" - ), - pa_type->tp_fund - ) - ); + } + else { /* turn e into e' where typeof(e') = typeof (f op e) */ + struct expr *extmp = intexpr(0, INT); + + /* this is really $#@&*%$# ! */ + extmp->ex_lvalue = 1; + extmp->ex_type = (*expp)->ex_type; + ch7bin(&extmp, oper, expr); + /* note that ch7bin creates a tree of the expression + ((typeof (f op e))f op (typeof (f op e))e), + where f ~ extmp and e ~ expr; + we have to use (typeof (f op e))e + Ch7bin does not create a tree if both operands + were illegal or constants! + */ + if (extmp->ex_class == Oper) { + expr = extmp->OP_RIGHT; + extmp->OP_RIGHT = NILEXPR; + free_expression(extmp); } - else { - check_arith_type(expp, oper); - ch7cast(&expr, CAST, (*expp)->ex_type); - } - break; - case LEFTAB: - case RIGHTAB: - check_integral_type(expp, oper); - ch7cast(&expr, oper, int_type); - break; - case ANDAB: - case XORAB: - case ORAB: - check_integral_type(expp, oper); - ch7cast(&expr, oper, (*expp)->ex_type); - break; + else + expr = extmp; } #ifndef NOBITFIELD if (fund == FIELD) @@ -369,6 +362,7 @@ ch7asgn(expp, oper, expr) else #endif NOBITFIELD *expp = new_oper((*expp)->ex_type, *expp, oper, expr); + (*expp)->OP_TYPE = expr->ex_type; /* for EVAL() */ } /* Some interesting (?) questions answered. @@ -393,18 +387,6 @@ is_integral_type(tp) } } -check_integral_type(expp, oper) - struct expr **expp; -{ - register struct expr *expr = *expp; - - if (!is_integral_type(expr->ex_type)) { - expr_error(expr, "%s on non-integral type (%s)", - symbol2str(oper), symbol2str(expr->ex_type->tp_fund)); - erroneous2int(expp); - } -} - int is_arith_type(tp) struct type *tp; @@ -426,15 +408,3 @@ is_arith_type(tp) return 0; } } - -check_arith_type(expp, oper) - struct expr **expp; -{ - register struct expr *expr = *expp; - - if (!is_arith_type(expr->ex_type)) { - expr_error(expr, "%s on non-arithmetical type (%s)", - symbol2str(oper), symbol2str(expr->ex_type->tp_fund)); - erroneous2int(expp); - } -} diff --git a/lang/cem/cemcom/ch7bin.c b/lang/cem/cemcom/ch7bin.c index 217eecb5..970e8b76 100644 --- a/lang/cem/cemcom/ch7bin.c +++ b/lang/cem/cemcom/ch7bin.c @@ -24,6 +24,7 @@ ch7bin(expp, oper, expr) struct expr *expr; { /* apply binary operator oper between *expp and expr. + NB: don't swap operands if op is one of the op= operators!!! */ any2opnd(expp, oper); any2opnd(&expr, oper); @@ -79,15 +80,24 @@ ch7bin(expp, oper, expr) *expp = new_oper(expr->ex_type, *expp, PARCOMMA, expr); break; case '%': + case MODAB: +/*** NB "not float" means "integral" !!! fund = arithbalance(expp, oper, &expr); if (fund == DOUBLE) { - expr_error(*expp, "floating operand to %%"); + expr_error(*expp, "floating operand to %s", + symbol2str(oper)); erroneous2int(expp); } else non_commutative_binop(expp, oper, expr); +***/ + opnd2integral(expp, oper); + opnd2integral(&expr, oper); + fund = arithbalance(expp, oper, &expr); + non_commutative_binop(expp, oper, expr); break; case '/': + case DIVAB: fund = arithbalance(expp, oper, &expr); non_commutative_binop(expp, oper, expr); break; @@ -95,6 +105,10 @@ ch7bin(expp, oper, expr) fund = arithbalance(expp, oper, &expr); commutative_binop(expp, oper, expr); break; + case TIMESAB: + fund = arithbalance(expp, oper, &expr); + non_commutative_binop(expp, oper, expr); + break; case '+': if (expr->ex_type->tp_fund == POINTER) { /* swap operands */ @@ -102,6 +116,8 @@ ch7bin(expp, oper, expr) expr = *expp; *expp = etmp; } + /*FALLTHROUGH*/ + case PLUSAB: if ((*expp)->ex_type->tp_fund == POINTER) { pointer_arithmetic(expp, oper, &expr); if ( expr->ex_type->tp_size != @@ -113,10 +129,14 @@ ch7bin(expp, oper, expr) } else { fund = arithbalance(expp, oper, &expr); - commutative_binop(expp, oper, expr); + if (oper == '+') + commutative_binop(expp, oper, expr); + else + non_commutative_binop(expp, oper, expr); } break; case '-': + case MINAB: if ((*expp)->ex_type->tp_fund == POINTER) { if (expr->ex_type->tp_fund == POINTER) pntminuspnt(expp, oper, expr); @@ -131,7 +151,9 @@ ch7bin(expp, oper, expr) } break; case LEFT: + case LEFTAB: case RIGHT: + case RIGHTAB: opnd2integral(expp, oper); opnd2integral(&expr, oper); ch7cast(&expr, oper, int_type); /* leftop should be int */ @@ -152,9 +174,17 @@ ch7bin(expp, oper, expr) case '|': opnd2integral(expp, oper); opnd2integral(&expr, oper); - fund = arithbalance(expp, oper, &expr); /* <=== */ + fund = arithbalance(expp, oper, &expr); commutative_binop(expp, oper, expr); break; + case ANDAB: + case XORAB: + case ORAB: + opnd2integral(expp, oper); + opnd2integral(&expr, oper); + fund = arithbalance(expp, oper, &expr); + non_commutative_binop(expp, oper, expr); + break; case AND: case OR: opnd2test(expp, oper); diff --git a/lang/cem/cemcom/conversion.c b/lang/cem/cemcom/conversion.c index b74f779b..7d6d4729 100644 --- a/lang/cem/cemcom/conversion.c +++ b/lang/cem/cemcom/conversion.c @@ -115,6 +115,7 @@ fundamental(tp) case CHAR: case SHORT: case INT: + case ERRONEOUS: case LONG: case ENUM: return tp->tp_unsigned ? T_UNSIGNED : T_SIGNED; diff --git a/lang/cem/cemcom/dumpidf.c b/lang/cem/cemcom/dumpidf.c index af6f3093..361aa89a 100644 --- a/lang/cem/cemcom/dumpidf.c +++ b/lang/cem/cemcom/dumpidf.c @@ -271,9 +271,10 @@ type2str(tp) if (tp->tp_field) { struct field *fd = tp->tp_field; - sprint(buf, "%s [s=%ld,w=%ld]", buf, + sprint(buf, "%s [s=%ld,w=%ld] of ", buf, fd->fd_shift, fd->fd_width); } + else #endif NOBITFIELD ops = 0; break; @@ -367,7 +368,10 @@ p1_expr(lvl, expr) o = &expr->ex_object.ex_oper; print("\n"); p1_expr(lvl+1, o->op_left); - p1_indent(lvl); print("%s\n", symbol2str(o->op_oper)); + p1_indent(lvl); + print("%s <%s>\n", symbol2str(o->op_oper), + type2str(o->op_type) + ); p1_expr(lvl+1, o->op_right); break; case Type: diff --git a/lang/cem/cemcom/eval.c b/lang/cem/cemcom/eval.c index b0f5f40c..2ce3f825 100644 --- a/lang/cem/cemcom/eval.c +++ b/lang/cem/cemcom/eval.c @@ -389,27 +389,33 @@ EVAL(expr, val, code, true_label, false_label) C_sti(pointer_size); C_lal(tmpvar); C_loi(pointer_size); - C_loi(tp->tp_size); + C_loi(leftop->ex_type->tp_size); + conversion(leftop->ex_type, tp); EVAL(rightop, RVAL, TRUE, NO_LABEL, NO_LABEL); assop(tp, oper); + conversion(tp, leftop->ex_type); if (gencode) - C_dup(roundup(tp->tp_size)); + C_dup(roundup(leftop->ex_type->tp_size)); C_lal(tmpvar); C_loi(pointer_size); - C_sti(tp->tp_size); + C_sti(leftop->ex_type->tp_size); free_tmp_var(old_offset); } else { load_val(leftop, RVAL); + conversion(leftop->ex_type, tp); EVAL(rightop, RVAL, TRUE, NO_LABEL, NO_LABEL); assop(tp, oper); + conversion(tp, leftop->ex_type); if (gencode) - C_dup(roundup(tp->tp_size)); + C_dup(roundup(leftop->ex_type->tp_size)); store_val( &(leftop->ex_object.ex_value), leftop->ex_type ); } + if (gencode) + conversion(leftop->ex_type, expr->ex_type); break; case '(': { diff --git a/lang/cem/cemcom/field.c b/lang/cem/cemcom/field.c index 6245ac86..747656ad 100644 --- a/lang/cem/cemcom/field.c +++ b/lang/cem/cemcom/field.c @@ -40,13 +40,16 @@ eval_field(expr, code) struct type *tp = leftop->ex_type->tp_up; arith old_offset, tmpvar; - /* The type in which the bitfield arithmetic is done: + /* The type in which the bitfield arithmetic is done; + AND IN WHICH BITFIELDS ARE STORED! */ struct type *atype = tp->tp_unsigned ? uword_type : word_type; arith asize = atype->tp_size; - ASSERT(leftop->ex_type->tp_fund == FIELD); + /* First some assertions to be sure that the rest is legal */ ASSERT(asize == word_size); /* make sure that C_loc() is legal */ + ASSERT(leftop->ex_type->tp_fund == FIELD); + leftop->ex_type = atype; /* this is cheating but it works... */ /* Note that op is either an assignment operator or an increment/ @@ -55,6 +58,8 @@ eval_field(expr, code) if (op == '=') { /* F = E: f = ((E & mask)<ex_type); + EVAL(rightop, RVAL, TRUE, NO_LABEL, NO_LABEL); conversion(tp, atype); C_loc(fd->fd_mask); @@ -71,10 +76,7 @@ eval_field(expr, code) load_val(leftop, RVAL); C_and(asize); C_ior(asize); - store_val( - &(leftop->ex_object.ex_value), - leftop->ex_type - ); + store_val(&(leftop->ex_object.ex_value), atype); } else { /* complex case */ tmpvar = tmp_pointer_var(&old_offset); @@ -114,16 +116,19 @@ eval_field(expr, code) C_and(asize); if (code == TRUE && (op == POSTINCR || op == POSTDECR)) C_dup(asize); + + /* the 'op' operation: */ + conversion(atype, rightop->ex_type); EVAL(rightop, RVAL, TRUE, NO_LABEL, NO_LABEL); - conversion(tp, atype); - /* generate code for the operator */ if (op == PLUSPLUS || op == POSTINCR) - assop(atype, PLUSAB); + assop(rightop->ex_type, PLUSAB); else if (op == MINMIN || op == POSTDECR) - assop(atype, MINAB); + assop(rightop->ex_type, MINAB); else - assop(atype, op); + assop(rightop->ex_type, op); + conversion(rightop->ex_type, atype); + C_loc(fd->fd_mask); C_and(asize); if (code == TRUE && op != POSTINCR && op != POSTDECR) @@ -138,10 +143,7 @@ eval_field(expr, code) load_val(leftop, RVAL); C_and(asize); C_ior(asize); - store_val( - &(leftop->ex_object.ex_value), - leftop->ex_type - ); + store_val(&(leftop->ex_object.ex_value), atype); } else { C_lal(tmpvar); @@ -168,7 +170,7 @@ eval_field(expr, code) C_loc(shift); C_sri(asize); } - conversion(atype, tp); + conversion(atype, expr->ex_type); } } #endif NOBITFIELD From de1efda513f7b0044c8b174bdc4ba947b28be70b Mon Sep 17 00:00:00 2001 From: erikb Date: Fri, 22 Aug 1986 09:10:12 +0000 Subject: [PATCH 0243/1625] made less environ and machine dependent --- lang/cem/cemcom/Makefile.erik | 58 ++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/lang/cem/cemcom/Makefile.erik b/lang/cem/cemcom/Makefile.erik index 0304e641..8e6305d8 100644 --- a/lang/cem/cemcom/Makefile.erik +++ b/lang/cem/cemcom/Makefile.erik @@ -1,35 +1,38 @@ # $Header$ # M A K E F I L E F O R A C K C - C O M P I L E R -# Some paths -BIN =/user1/$$USER/bin# # provisional ??? -EM = /usr/em# # where to find the ACK tree -ACK = $(EM)/bin/ack# # old ACK C compiler -EM_INCLUDES =$(EM)/h# # directory containing EM interface definition +# Machine and environ dependent definitions +EM = /user1/erikb/em# # ACK tree on this machine +DESTINATION = /user1/$$USER/bin# # where to put the stuff +MKDEP = /user1/erikb/bin/mkdep# # dependency generator +MAP = -DInsertFile=ins_file -DInsertText=ins_text# # bug in m68k2 back end +SIM = /user1/dick/bin/sim# # Dicks sim program -# Libraries -SYSLIB = /user1/erikb/em/lib/libsystem.a -EMKLIB = /user1/erikb/em/lib/libemk.a -EMELIB = /user1/erikb/em/lib/libeme.a -STRLIB = /user1/erikb/em/lib/libstr.a -PRTLIB = /user1/erikb/em/lib/libprint.a -EMMESLIB = /user1/erikb/em/lib/libem_mes.a -LIBS = $(EMMESLIB) $(EMKLIB) $(PRTLIB) $(STRLIB) $(SYSLIB) -ELIBS = $(EMMESLIB) $(EMELIB) $(PRTLIB) $(STRLIB) $(SYSLIB) -LIB_INCLUDES = /user1/erikb/em/h +# Libraries and EM interface definitions +SYSLIB = $(EM)/modules/lib/libsystem.a +EMKLIB = $(EM)/modules/lib/libemk.a +EMELIB = $(EM)/modules/lib/libeme.a +STRLIB = $(EM)/modules/lib/libstr.a +PRTLIB = $(EM)/modules/lib/libprint.a +EMMESLIB = $(EM)/modules/lib/libem_mes.a +CH3LIB = $(EM)/modules/lib/libch3.a +LIBS = $(CH3LIB) $(EMMESLIB) $(EMKLIB) $(PRTLIB) $(STRLIB) $(SYSLIB) +ELIBS = $(CH3LIB) $(EMMESLIB) $(EMELIB) $(PRTLIB) $(STRLIB) $(SYSLIB) +LIB_INCLUDES = $(EM)/modules/h +EM_INCLUDES = $(EM)/h # Where to install the compiler and its driver -CEMCOM = $(BIN)/cemcom -DRIVER = $(BIN)/cem +CEMCOM = $(DESTINATION)/cemcom +DRIVER = $(DESTINATION)/cem # What C compiler to use and how -CC = $(ACK) -.c -CC = CC -CC = /bin/cc +# CC = $(ACK) -.c +# CC = CC +# CC = /bin/cc COPTIONS = # What parser generator to use and how -GEN = /user0/ceriel/bin/LLgen +GEN = $(EM)/bin/LLgen GENOPTIONS = -vv # Special #defines during compilation @@ -79,10 +82,10 @@ NEXTFILES = code.str declar.str decspecs.str def.str expr.str field.str \ all: cc -cc: - make hfiles - make LLfiles - make main +cc: + make "CC=$(CC)" hfiles + make "CC=$(CC)" LLfiles + make "CC=$(CC)" main cem: cem.c $(CC) -O cem.c $(SYSLIB) -o cem @@ -160,8 +163,7 @@ listobjects: depend: cfiles sed '/^#AUTOAUTO/,$$d' Makefile >Makefile.new echo '#AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO' >>Makefile.new - /user1/erikb/bin/mkdep `sources $(OBJ)` | \ - sed 's/\.c:/.o:/' >>Makefile.new + $(MKDEP) `sources $(OBJ)` | sed 's/\.c:/.o:/' >>Makefile.new mv Makefile Makefile.old mv Makefile.new Makefile @@ -214,7 +216,7 @@ input.o: LLlex.h alloc.h arith.h assert.h debug.h idepth.h input.h inputtype.h i domacro.o: LLlex.h Lpars.h alloc.h arith.h assert.h botch_free.h class.h debug.h idf.h idfsize.h ifdepth.h input.h interface.h macro.h nopp.h nparams.h parbufsize.h spec_arith.h storage.h textsize.h replace.o: LLlex.h alloc.h arith.h assert.h class.h debug.h idf.h input.h interface.h macro.h nopp.h pathlength.h spec_arith.h strsize.h init.o: alloc.h class.h idf.h interface.h macro.h nopp.h predefine.h -options.o: align.h arith.h class.h idf.h idfsize.h macro.h maxincl.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h +options.o: align.h arith.h class.h idf.h idfsize.h macro.h maxincl.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h use_tmp.h scan.o: class.h idf.h input.h interface.h lapbuf.h macro.h nopp.h nparams.h skip.o: LLlex.h arith.h class.h input.h interface.h nopp.h spec_arith.h stack.o: Lpars.h alloc.h arith.h botch_free.h debug.h def.h idf.h level.h mes.h nobitfield.h nopp.h spec_arith.h stack.h storage.h struct.h type.h use_tmp.h From c3ef25a7a97c8f374f50a431cd5d445fe732bfa0 Mon Sep 17 00:00:00 2001 From: erikb Date: Fri, 22 Aug 1986 09:20:13 +0000 Subject: [PATCH 0244/1625] some minor bugs --- lang/cem/cemcom/code.c | 2 +- lang/cem/cemcom/init.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lang/cem/cemcom/code.c b/lang/cem/cemcom/code.c index 0dd0c6f5..b9ba88f8 100644 --- a/lang/cem/cemcom/code.c +++ b/lang/cem/cemcom/code.c @@ -93,7 +93,7 @@ end_code() */ def_strings(str_list); str_list = 0; - C_ms_src((arith)(LineNumber - 2), FileName); + C_ms_src((int)(LineNumber - 2), FileName); C_close(); } diff --git a/lang/cem/cemcom/init.c b/lang/cem/cemcom/init.c index c5cf19cd..dcdf1bfc 100644 --- a/lang/cem/cemcom/init.c +++ b/lang/cem/cemcom/init.c @@ -34,7 +34,7 @@ char *strcpy(); EXPORT init_pp() { - long clock; + long clock, sys_time(); static char date[30]; char *ctime(); From 196cc676d9908030b2f5583d5f50d00d224db502 Mon Sep 17 00:00:00 2001 From: erikb Date: Mon, 25 Aug 1986 08:47:07 +0000 Subject: [PATCH 0245/1625] generate a con instruction for each character in a string constant --- lang/cem/cemcom/code.c | 2 +- lang/cem/cemcom/ival.c | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lang/cem/cemcom/code.c b/lang/cem/cemcom/code.c index b9ba88f8..b56e16e3 100644 --- a/lang/cem/cemcom/code.c +++ b/lang/cem/cemcom/code.c @@ -81,7 +81,7 @@ def_strings(sc) if (sc) { def_strings(sc->next); C_df_dlb(sc->sc_dlb); - C_con_scon(sc->sc_value, sc->sc_len); + str_cst(sc->sc_value, sc->sc_len); free_string_cst(sc); } } diff --git a/lang/cem/cemcom/ival.c b/lang/cem/cemcom/ival.c index b47cd0ad..95e8d3fa 100644 --- a/lang/cem/cemcom/ival.c +++ b/lang/cem/cemcom/ival.c @@ -67,7 +67,7 @@ IVAL(tpp, ex) return do_array(ex, tpp); /* catch initialisations like char s[] = "I am a string" */ if (tp->tp_up->tp_fund == CHAR && ex->ex_class == String) - init_string(tpp, ex); + ch_array(tpp, ex); else /* " int i[24] = 12;" */ check_and_pad(ex, tpp); break; @@ -140,7 +140,7 @@ do_array(ex, tpp) f = f->OP_LEFT; } if (f->ex_class == String) { /* hallelujah, it's a string! */ - init_string(tpp, f); + ch_array(tpp, f); return g ? g->OP_RIGHT : ex->OP_RIGHT; } /* else: just go on with the next part of this function */ @@ -492,11 +492,11 @@ check_ival(ex, tp) } } -/* init_string() initialises an array of characters by specifying +/* ch_array() initialises an array of characters when given a string constant. Alignment is taken care of. */ -init_string(tpp, ex) +ch_array(tpp, ex) struct type **tpp; /* type tp = array of characters */ struct expr *ex; { @@ -536,6 +536,14 @@ init_string(tpp, ex) con_nullbyte(); } +str_cst(str, len) + register char *str; + register int len; +{ + while (len-- > 0) + C_con_ucon(long2str((long)*str++ & 0xFF, 10), (arith)1); +} + #ifndef NOBITFIELD /* put_bf() takes care of the initialisation of (bit-)field selectors of a struct: each time such an initialisation takes place, From a601e0a5422a4932f8ced759d934dc8aa683efad Mon Sep 17 00:00:00 2001 From: erikb Date: Tue, 26 Aug 1986 10:30:39 +0000 Subject: [PATCH 0246/1625] unknown-sized locals retain their type --- lang/cem/cemcom/idf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/cem/cemcom/idf.c b/lang/cem/cemcom/idf.c index 0209567c..05e74f8b 100644 --- a/lang/cem/cemcom/idf.c +++ b/lang/cem/cemcom/idf.c @@ -335,7 +335,7 @@ declare_idf(ds, dc, lvl) if (type->tp_size == (arith)-1) { error("size of local %s unknown", idf->id_text); - type = idf->id_def->df_type = int_type; + /** type = idf->id_def->df_type = int_type; **/ } idf->id_def->df_register = (sc == REGISTER) From aacc4053dbd36d89dbef360df008846c99d46ccc Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 26 Aug 1986 14:33:24 +0000 Subject: [PATCH 0247/1625] newer version with bug fixes --- lang/m2/comp/Makefile | 103 +++++++++++------- lang/m2/comp/Parameters | 2 +- lang/m2/comp/chk_expr.c | 10 +- lang/m2/comp/code.c | 227 ++++++++++++++++++++------------------- lang/m2/comp/cstoper.c | 1 + lang/m2/comp/declar.g | 91 +++++----------- lang/m2/comp/def.c | 5 +- lang/m2/comp/defmodule.c | 2 +- lang/m2/comp/enter.c | 73 +++++++------ lang/m2/comp/program.g | 19 +++- lang/m2/comp/scope.C | 29 ++--- lang/m2/comp/type.c | 35 +++++- lang/m2/comp/typequiv.c | 32 +++--- lang/m2/comp/walk.c | 143 +++++++++++++++++++----- 14 files changed, 452 insertions(+), 320 deletions(-) diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index dda87c51..25407363 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -1,16 +1,16 @@ # make modula-2 "compiler" # $Header$ -EMDIR = /usr/em +EMDIR = /usr/ceriel/em MHDIR = $(EMDIR)/modules/h PKGDIR = $(EMDIR)/modules/pkg LIBDIR = $(EMDIR)/modules/lib -LLGEN = $(EMDIR)/util/LLgen/src/LLgen +LLGEN = $(EMDIR)/bin/LLgen INCLUDES = -I$(MHDIR) -I$(EMDIR)/h -I$(PKGDIR) LSRC = tokenfile.g program.g declar.g expression.g statement.g CC = cc -LLGENOPTIONS = -d +LLGENOPTIONS = PROFILE = CFLAGS = $(PROFILE) $(INCLUDES) -DSTATIC= LINTFLAGS = -DSTATIC= -DNORCSID @@ -23,7 +23,7 @@ COBJ = LLlex.o LLmessage.o char.o error.o main.o \ code.o tmpvar.o lookup.o OBJ = $(COBJ) $(LOBJ) Lpars.o -# Keep the next three entries up to date! +# Keep the next entries up to date! GENCFILES= tokenfile.c \ program.c declar.c expression.c statement.c \ symbol2str.c char.c Lpars.c casestat.c tmpvar.c scope.c @@ -32,12 +32,42 @@ GENHFILES= errout.h\ idfsize.h numsize.h strsize.h target_sizes.h debug.h\ inputtype.h maxset.h ndir.h density.h\ def.h type.h Lpars.h node.h +HFILES= LLlex.h\ + chk_expr.h class.h const.h desig.h f_info.h idf.h\ + input.h main.h misc.h scope.h standards.h tokenname.h\ + walk.h $(GENHFILES) # GENFILES = $(GENGFILES) $(GENCFILES) $(GENHFILES) -all: - make hfiles - make LLfiles - make main + +all: Cfiles + sh -c 'if $(CC) nmclash.c > /dev/null 2>&1 ; then make main ; else sh Resolve main ; fi' + @rm -f nmclash.o a.out + +clean: + rm -f $(OBJ) $(GENFILES) LLfiles hfiles Cfiles tab cclash.o cid.o cclash cid + (cd .. ; rm -rf Xsrc) + +lint: Cfiles + sh -c `if $(CC) nmclash.c > /dev/null 2>&1 ; then make Xlint ; else sh Resolve Xlint ; fi' + @rm -f nmclash.o a.out + +mkdep: mkdep.o + $(CC) -o mkdep mkdep.o + +cclash: cclash.o + $(CC) -o cclash cclash.o + +cid: cid.o + $(CC) -o cid cid.o + +# entry points not to be used directly + +Xlint: + lint $(INCLUDES) $(LINTFLAGS) `./sources $(OBJ)` + +Cfiles: hfiles LLfiles $(GENHFILES) $(GENCFILES) + ./sources $(OBJ) > Cfiles + sh -c 'for i in $(HFILES) ; do echo $$i ; done >> Cfiles' LLfiles: $(LSRC) $(LLGEN) $(LLGENOPTIONS) $(LSRC) @@ -47,47 +77,48 @@ hfiles: Parameters make.hfiles make.hfiles Parameters touch hfiles -main: $(OBJ) Makefile - $(CC) $(LFLAGS) $(OBJ) $(LIBDIR)/libem_mes.a $(LIBDIR)/libeme.a $(LIBDIR)/input.a $(LIBDIR)/assert.a $(LIBDIR)/alloc.a $(LIBDIR)/malloc.o $(LIBDIR)/libprint.a $(LIBDIR)/libstr.a $(LIBDIR)/libsystem.a -o main - size main - -clean: - rm -f $(OBJ) $(GENFILES) LLfiles hfiles - -lint: LLfiles hfiles - lint $(INCLUDES) $(LINTFLAGS) `sources $(OBJ)` +main: $(OBJ) ../src/Makefile + $(CC) $(LFLAGS) $(OBJ) $(LIBDIR)/libem_mes.a $(LIBDIR)/libemk.a $(LIBDIR)/input.a $(LIBDIR)/assert.a $(LIBDIR)/alloc.a $(LIBDIR)/malloc.o $(LIBDIR)/libprint.a $(LIBDIR)/libstr.a $(LIBDIR)/libsystem.a -o ../src/main + size ../src/main tokenfile.g: tokenname.c make.tokfile make.tokfile tokenfile.g -symbol2str.c: tokenname.c make.tokcase - make.tokcase symbol2str.c +symbol2str.c: ../src/tokenname.c ../src/make.tokcase + ../src/make.tokcase <../src/tokenname.c >symbol2str.c -def.h: def.H make.allocd -type.h: type.H make.allocd -node.h: node.H make.allocd -scope.c: scope.C make.allocd -tmpvar.c: tmpvar.C make.allocd -casestat.c: casestat.C make.allocd +def.h: ../src/def.H ../src/make.allocd + ../src/make.allocd < ../src/def.H > def.h -char.c: char.tab tab - ./tab -fchar.tab >char.c +type.h: ../src/type.H ../src/make.allocd + ../src/make.allocd < ../src/type.H > type.h -tab: - $(CC) tab.c -o tab +node.h: ../src/node.H ../src/make.allocd + ../src/make.allocd < ../src/node.H > node.h -depend: +scope.c: ../src/scope.C ../src/make.allocd + ../src/make.allocd < ../src/scope.C > scope.c + +tmpvar.c: ../src/tmpvar.C ../src/make.allocd + ../src/make.allocd < ../src/tmpvar.C > tmpvar.c + +casestat.c: ../src/casestat.C ../src/make.allocd + ../src/make.allocd < ../src/casestat.C > casestat.c + +char.c: ../src/char.tab ../src/tab + ../src/tab -fchar.tab >char.c + +../src/tab: + $(CC) ../src/tab.c -o ../src/tab + +depend: mkdep sed '/^#AUTOAUTO/,$$d' Makefile > Makefile.new echo '#AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO' >> Makefile.new - /user1/erikb/bin/mkdep `sources $(OBJ)` |\ + ./mkdep `./sources $(OBJ)` |\ sed 's/\.c:/\.o:/' >> Makefile.new mv Makefile Makefile.old mv Makefile.new Makefile -.SUFFIXES: .H .h .C -.H.h .C.c : - make.allocd < $< > $@ - #AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO LLlex.o: LLlex.h Lpars.h class.h const.h debug.h f_info.h idf.h idfsize.h input.h inputtype.h numsize.h strsize.h type.h LLmessage.o: LLlex.h Lpars.h idf.h @@ -116,7 +147,7 @@ code.o: LLlex.h Lpars.h debug.h def.h desig.h node.h scope.h standards.h type.h tmpvar.o: debug.h def.h main.h scope.h type.h lookup.o: LLlex.h debug.h def.h idf.h node.h scope.h tokenfile.o: Lpars.h -program.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h type.h +program.o: LLlex.h Lpars.h debug.h def.h f_info.h idf.h main.h node.h scope.h type.h declar.o: LLlex.h Lpars.h chk_expr.h debug.h def.h idf.h main.h misc.h node.h scope.h type.h expression.o: LLlex.h Lpars.h chk_expr.h const.h debug.h def.h idf.h node.h type.h statement.o: LLlex.h Lpars.h def.h idf.h node.h scope.h type.h diff --git a/lang/m2/comp/Parameters b/lang/m2/comp/Parameters index acda8568..a1d3ff8c 100644 --- a/lang/m2/comp/Parameters +++ b/lang/m2/comp/Parameters @@ -5,7 +5,7 @@ !File: idfsize.h -#define IDFSIZE 30 /* maximum significant length of an identifier */ +#define IDFSIZE 128 /* maximum significant length of an identifier */ !File: numsize.h diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index 0137ec52..ae2571eb 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -132,6 +132,8 @@ ChkLinkOrName(expp) { register struct def *df; + expp->nd_type = error_type; + if (expp->nd_class == Name) { expp->nd_def = lookfor(expp, CurrVis, 1); expp->nd_class = Def; @@ -183,7 +185,7 @@ df->df_idf->id_text); assert(expp->nd_class == Def); df = expp->nd_def; - if (df == ill_df) return 0; + if (df->df_kind == D_ERROR) return 0; if (df->df_kind & (D_ENUM | D_CONST)) { if (df->df_kind == D_ENUM) { @@ -855,7 +857,7 @@ ChkStandard(expp, left) case S_MIN: if (!(left = getname(&arg, D_ISTYPE))) return 0; if (!(left->nd_type->tp_fund & (T_DISCRETE))) { - node_error(left, "illegal type in MIN or MAX"); +node_error(left, "illegal type in %s", std == S_MAX ? "MAX" : "MIN"); return 0; } expp->nd_type = left->nd_type; @@ -961,7 +963,7 @@ ChkStandard(expp, left) expp->nd_type = 0; if (! (left = getvariable(&arg))) return 0; if (! (left->nd_type->tp_fund & T_DISCRETE)) { -node_error(left, "illegal type in argument of INC or DEC"); +node_error(left,"illegal type in argument of %s",std == S_INC ? "INC" : "DEC"); return 0; } if (arg->nd_right) { @@ -982,7 +984,7 @@ node_error(left, "illegal type in argument of INC or DEC"); if (!(left = getvariable(&arg))) return 0; tp = left->nd_type; if (tp->tp_fund != T_SET) { -node_error(arg, "EXCL and INCL expect a SET parameter"); +node_error(arg, "%s expects a SET parameter", std == S_EXCL ? "EXCL" : "INCL"); return 0; } if (!(left = getarg(&arg, T_DISCRETE, 0))) return 0; diff --git a/lang/m2/comp/code.c b/lang/m2/comp/code.c index 2e625273..acfeda5e 100644 --- a/lang/m2/comp/code.c +++ b/lang/m2/comp/code.c @@ -201,7 +201,6 @@ CodeCoercion(t1, t2) if ((fund2 = t2->tp_fund) == T_WORD) fund2 = T_INTEGER; switch(fund1) { case T_INTEGER: - case T_INTORCARD: switch(fund2) { case T_INTEGER: if (t2->tp_size != t1->tp_size) { @@ -232,11 +231,13 @@ CodeCoercion(t1, t2) case T_CHAR: case T_ENUMERATION: case T_CARDINAL: + case T_INTORCARD: switch(fund2) { case T_ENUMERATION: case T_CHAR: case T_CARDINAL: case T_POINTER: + case T_INTORCARD: if (t2->tp_size > word_size) { C_loc(word_size); C_loc(t2->tp_size); @@ -313,16 +314,25 @@ CodeCall(nd) CodeParameters(ParamList(left->nd_type), nd->nd_right); } - if (left->nd_class == Def && left->nd_def->df_kind == D_PROCEDURE) { - if (left->nd_def->df_scope->sc_level > 0) { - C_lxl((arith) proclevel - left->nd_def->df_scope->sc_level); + switch(left->nd_class) { + case Def: { + register struct def *df = left->nd_def; + + if (df->df_kind == D_PROCEDURE) { + arith level = df->df_scope->sc_level; + + if (level > 0) { + C_lxl((arith) proclevel - level); + } + C_cal(NameOfProc(df)); + break; } - C_cal(NameOfProc(left->nd_def)); - } - else if (left->nd_class == Def && left->nd_def->df_kind == D_PROCHEAD) { - C_cal(left->nd_def->for_name); - } - else { + else if (df->df_kind == D_PROCHEAD) { + C_cal(df->for_name); + break; + }} + /* Fall through */ + default: CodePExpr(left); C_cai(); } @@ -342,6 +352,7 @@ CodeParameters(param, arg) { register struct type *tp; register struct node *left; + register struct type *left_type; assert(param != 0 && arg != 0); @@ -351,25 +362,31 @@ CodeParameters(param, arg) tp = TypeOfParam(param); left = arg->nd_left; + left_type = left->nd_type; if (IsConformantArray(tp)) { C_loc(tp->arr_elsize); - if (IsConformantArray(left->nd_type)) { + if (IsConformantArray(left_type)) { DoHIGH(left); - if (tp->arr_elem->tp_size != left->nd_type->arr_elem->tp_size) { + if (tp->arr_elem->tp_size != + left_type->arr_elem->tp_size) { /* This can only happen if the formal type is ARRAY OF WORD */ - /* ??? */ + assert(tp->arr_elem == word_type); + C_loc(left_type->arr_elem->tp_size); + C_cal("_wa"); + C_asp(dword_size); + C_lfr(word_size); } } else if (left->nd_symb == STRING) { C_loc(left->nd_SLE); } else if (tp->arr_elem == word_type) { - C_loc(left->nd_type->tp_size / word_size - 1); + C_loc((left_type->tp_size+word_size-1) / word_size - 1); } else { - tp = IndexType(left->nd_type); + tp = IndexType(left_type); if (tp->tp_fund == T_SUBRANGE) { C_loc(tp->sub_ub - tp->sub_lb); } @@ -385,11 +402,11 @@ CodeParameters(param, arg) CodeDAddress(left); } else { - if (left->nd_type->tp_fund == T_STRING) { + if (left_type->tp_fund == T_STRING) { CodePadString(left, tp->tp_size); } else CodePExpr(left); - CheckAssign(left->nd_type, tp); + CheckAssign(left_type, tp); } } @@ -422,6 +439,7 @@ CodeStd(nd) } else C_cal("_absd"); } + C_asp(tp->tp_size); C_lfr(tp->tp_size); break; @@ -447,6 +465,7 @@ CodeStd(nd) break; case S_ODD: + CodePExpr(left); if (tp->tp_size == word_size) { C_loc((arith) 1); C_and(word_size); @@ -584,45 +603,39 @@ CheckAssign(tpl, tpr) } } -Operands(leftop, rightop) +Operands(leftop, rightop, tp) register struct node *leftop, *rightop; + struct type *tp; { CodePExpr(leftop); - - if (rightop->nd_type->tp_fund == T_POINTER && - leftop->nd_type->tp_size != pointer_size) { - CodeCoercion(leftop->nd_type, rightop->nd_type); - leftop->nd_type = rightop->nd_type; - } - + CodeCoercion(leftop->nd_type, tp); CodePExpr(rightop); + CodeCoercion(rightop->nd_type, tp); } CodeOper(expr, true_label, false_label) - struct node *expr; /* the expression tree itself */ + register struct node *expr; /* the expression tree itself */ label true_label; label false_label; /* labels to jump to in logical expr's */ { - register int oper = expr->nd_symb; register struct node *leftop = expr->nd_left; register struct node *rightop = expr->nd_right; register struct type *tp = expr->nd_type; - switch (oper) { + switch (expr->nd_symb) { case '+': - Operands(leftop, rightop); + Operands(leftop, rightop, tp); switch (tp->tp_fund) { case T_INTEGER: C_adi(tp->tp_size); break; - case T_POINTER: - C_ads(rightop->nd_type->tp_size); - break; case T_REAL: C_adf(tp->tp_size); break; + case T_POINTER: case T_CARDINAL: + case T_INTORCARD: C_adu(tp->tp_size); break; case T_SET: @@ -633,24 +646,17 @@ CodeOper(expr, true_label, false_label) } break; case '-': - Operands(leftop, rightop); + Operands(leftop, rightop, tp); switch (tp->tp_fund) { case T_INTEGER: C_sbi(tp->tp_size); break; - case T_POINTER: - if (rightop->nd_type->tp_fund == T_POINTER) { - C_sbs(pointer_size); - } - else { - C_ngi(rightop->nd_type->tp_size); - C_ads(rightop->nd_type->tp_size); - } - break; case T_REAL: C_sbf(tp->tp_size); break; + case T_POINTER: case T_CARDINAL: + case T_INTORCARD: C_sbu(tp->tp_size); break; case T_SET: @@ -662,15 +668,14 @@ CodeOper(expr, true_label, false_label) } break; case '*': - Operands(leftop, rightop); + Operands(leftop, rightop, tp); switch (tp->tp_fund) { case T_INTEGER: C_mli(tp->tp_size); break; case T_POINTER: - CodeCoercion(rightop->nd_type, tp); - /* Fall through */ case T_CARDINAL: + case T_INTORCARD: C_mlu(tp->tp_size); break; case T_REAL: @@ -684,7 +689,7 @@ CodeOper(expr, true_label, false_label) } break; case '/': - Operands(leftop, rightop); + Operands(leftop, rightop, tp); switch (tp->tp_fund) { case T_REAL: C_dvf(tp->tp_size); @@ -697,15 +702,14 @@ CodeOper(expr, true_label, false_label) } break; case DIV: - Operands(leftop, rightop); + Operands(leftop, rightop, tp); switch(tp->tp_fund) { case T_INTEGER: C_dvi(tp->tp_size); break; case T_POINTER: - CodeCoercion(rightop->nd_type, tp); - /* Fall through */ case T_CARDINAL: + case T_INTORCARD: C_dvu(tp->tp_size); break; default: @@ -713,15 +717,14 @@ CodeOper(expr, true_label, false_label) } break; case MOD: - Operands(leftop, rightop); + Operands(leftop, rightop, tp); switch(tp->tp_fund) { case T_INTEGER: C_rmi(tp->tp_size); break; case T_POINTER: - CodeCoercion(rightop->nd_type, tp); - /* Fall through */ case T_CARDINAL: + case T_INTORCARD: C_rmu(tp->tp_size); break; default: @@ -734,18 +737,17 @@ CodeOper(expr, true_label, false_label) case GREATEREQUAL: case '=': case '#': - Operands(leftop, rightop); - CodeCoercion(rightop->nd_type, leftop->nd_type); - tp = BaseType(leftop->nd_type); /* Not the result type! */ + tp = BaseType(leftop->nd_type); + if (tp == intorcard_type) tp = BaseType(rightop->nd_type); + Operands(leftop, rightop, tp); switch (tp->tp_fund) { case T_INTEGER: C_cmi(tp->tp_size); break; case T_HIDDEN: case T_POINTER: - C_cmp(); - break; case T_CARDINAL: + case T_INTORCARD: C_cmu(tp->tp_size); break; case T_ENUMERATION: @@ -756,19 +758,18 @@ CodeOper(expr, true_label, false_label) C_cmf(tp->tp_size); break; case T_SET: - if (oper == GREATEREQUAL) { + if (expr->nd_symb == GREATEREQUAL) { /* A >= B is the same as A equals A + B */ C_dup(2*tp->tp_size); C_asp(tp->tp_size); - C_zer(tp->tp_size); + C_ior(tp->tp_size); } - else if (oper == LESSEQUAL) { + else if (expr->nd_symb == LESSEQUAL) { /* A <= B is the same as A - B = {} */ C_com(tp->tp_size); C_and(tp->tp_size); - C_ior(tp->tp_size); C_zer(tp->tp_size); } C_cms(tp->tp_size); @@ -777,11 +778,11 @@ CodeOper(expr, true_label, false_label) crash("bad type COMPARE"); } if (true_label != 0) { - compare(oper, true_label); + compare(expr->nd_symb, true_label); C_bra(false_label); } else { - truthvalue(oper); + truthvalue(expr->nd_symb); } break; case IN: @@ -789,7 +790,8 @@ CodeOper(expr, true_label, false_label) INN instruction expects the bit number on top of the stack */ - Operands(rightop, leftop); + CodePExpr(rightop); + CodePExpr(leftop); CodeCoercion(leftop->nd_type, word_type); C_inn(rightop->nd_type->tp_size); if (true_label != 0) { @@ -798,19 +800,26 @@ CodeOper(expr, true_label, false_label) } break; case AND: - case '&': - if (true_label == 0) { - label l_true = ++text_label; - label l_false = ++text_label; - label l_maybe = ++text_label; - label l_end = ++text_label; - struct desig Des; + case '&': { + label l_true, l_false, l_maybe = ++text_label, l_end; + struct desig Des; - Des = InitDesig; - CodeExpr(leftop, &Des, l_maybe, l_false); - C_df_ilb(l_maybe); - Des = InitDesig; - CodeExpr(rightop, &Des, l_true, l_false); + if (true_label == 0) { + l_true = ++text_label; + l_false = ++text_label; + l_end = ++text_label; + } + else { + l_true = true_label; + l_false = false_label; + } + + Des = InitDesig; + CodeExpr(leftop, &Des, l_maybe, l_false); + C_df_ilb(l_maybe); + Des = InitDesig; + CodeExpr(rightop, &Des, l_true, l_false); + if (true_label == 0) { C_df_ilb(l_true); C_loc((arith)1); C_bra(l_end); @@ -818,30 +827,27 @@ CodeOper(expr, true_label, false_label) C_loc((arith)0); C_df_ilb(l_end); } - else { - label l_maybe = ++text_label; - struct desig Des; - - Des = InitDesig; - CodeExpr(leftop, &Des, l_maybe, false_label); - Des = InitDesig; - C_df_ilb(l_maybe); - CodeExpr(rightop, &Des, true_label, false_label); - } break; - case OR: - if (true_label == 0) { - label l_true = ++text_label; - label l_false = ++text_label; - label l_maybe = ++text_label; - label l_end = ++text_label; - struct desig Des; + } + case OR: { + label l_true, l_false, l_maybe = ++text_label, l_end; + struct desig Des; - Des = InitDesig; - CodeExpr(leftop, &Des, l_true, l_maybe); - C_df_ilb(l_maybe); - Des = InitDesig; - CodeExpr(rightop, &Des, l_true, l_false); + if (true_label == 0) { + l_true = ++text_label; + l_false = ++text_label; + l_end = ++text_label; + } + else { + l_true = true_label; + l_false = false_label; + } + Des = InitDesig; + CodeExpr(leftop, &Des, l_true, l_maybe); + C_df_ilb(l_maybe); + Des = InitDesig; + CodeExpr(rightop, &Des, l_true, l_false); + if (true_label == 0) { C_df_ilb(l_false); C_loc((arith)0); C_bra(l_end); @@ -849,19 +855,10 @@ CodeOper(expr, true_label, false_label) C_loc((arith)1); C_df_ilb(l_end); } - else { - label l_maybe = ++text_label; - struct desig Des; - - Des = InitDesig; - CodeExpr(leftop, &Des, true_label, l_maybe); - C_df_ilb(l_maybe); - Des = InitDesig; - CodeExpr(rightop, &Des, true_label, false_label); - } break; + } default: - crash("(CodeOper) Bad operator %s\n", symbol2str(oper)); + crash("(CodeOper) Bad operator %s\n",symbol2str(expr->nd_symb)); } } @@ -936,6 +933,7 @@ CodeUoper(nd) case '-': switch(tp->tp_fund) { case T_INTEGER: + case T_INTORCARD: C_ngi(tp->tp_size); break; case T_REAL: @@ -977,7 +975,7 @@ CodeEl(nd, tp) C_loc(eltype->sub_ub); } else C_loc((arith) (eltype->enm_ncst - 1)); - Operands(nd->nd_left, nd->nd_right); + Operands(nd->nd_left, nd->nd_right, word_type); C_cal("_LtoUset"); /* library routine to fill set */ C_asp(4 * word_size); } @@ -1032,13 +1030,20 @@ CodeDStore(nd) DoHIGH(nd) struct node *nd; { + /* Get the high index of a conformant array, indicated by "nd". + The high index is the second field in the descriptor of + the array, so it is easily found. + */ register struct def *df = nd->nd_def; register arith highoff; assert(nd->nd_class == Def); assert(df->df_kind == D_VARIABLE); + assert(IsConformantArray(df->df_type)); - highoff = df->var_off + pointer_size + word_size; + highoff = df->var_off /* base address and descriptor */ + + pointer_size /* skip base address */ + + word_size; /* skip first field of descriptor */ if (df->df_scope->sc_level < proclevel) { C_lxa((arith) (proclevel - df->df_scope->sc_level)); C_lof(highoff); diff --git a/lang/m2/comp/cstoper.c b/lang/m2/comp/cstoper.c index 494a7bc9..6620b985 100644 --- a/lang/m2/comp/cstoper.c +++ b/lang/m2/comp/cstoper.c @@ -248,6 +248,7 @@ cstset(expp) assert(expp->nd_left->nd_class == Value); i = expp->nd_left->nd_INT; + expp->nd_class = Value; expp->nd_INT = (i >= 0 && set2 != 0 && i < setsize * wrd_bits && (set2[i / wrd_bits] & (1 << (i % wrd_bits)))); diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index a634808d..a9fdac97 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -108,9 +108,7 @@ declaration: FormalParameters(struct paramlist **pr; struct type **ptp; arith *parmaddr;) -{ - struct def *df; -} : +: '(' [ FPSection(pr, parmaddr) @@ -128,74 +126,38 @@ FPSection(struct paramlist **ppr; arith *parmaddr;) struct node *FPList; struct type *tp; int VARp; - struct paramlist *p = 0; } : - var(&VARp) IdentList(&FPList) ':' FormalType(&p, 0) - { EnterParamList(ppr, FPList, p->par_def->df_type, - VARp, parmaddr); - free_def(p->par_def); - free_paramlist(p); - } + var(&VARp) IdentList(&FPList) ':' FormalType(&tp) + { EnterParamList(ppr, FPList, tp, VARp, parmaddr); } ; -FormalType(struct paramlist **ppr; int VARp;) +FormalType(struct type **ptp;) { - register struct def *df; - int ARRAYflag; register struct type *tp; - struct type *tp1; - register struct paramlist *p = new_paramlist(); extern arith ArrayElSize(); } : - [ ARRAY OF { ARRAYflag = 1; } - | { ARRAYflag = 0; } - ] - qualtype(&tp1) - { if (ARRAYflag) { - tp = construct_type(T_ARRAY, NULLTYPE); - tp->arr_elem = tp1; - tp->arr_elsize = ArrayElSize(tp1); - tp->tp_align = lcm(word_align, pointer_align); - } - else tp = tp1; - p->next = *ppr; - *ppr = p; - p->par_def = df = new_def(); - df->df_type = tp; - df->df_flags = VARp; + ARRAY OF qualtype(ptp) + { tp = construct_type(T_ARRAY, NULLTYPE); + tp->arr_elem = *ptp; *ptp = tp; + tp->arr_elsize = ArrayElSize(tp->arr_elem); + tp->tp_align = lcm(word_align, pointer_align); } +| + qualtype(ptp) ; TypeDeclaration { - register struct def *df; + struct def *df; struct type *tp; }: IDENT { df = define(dot.TOK_IDF,CurrentScope,D_TYPE); } '=' type(&tp) - { if (df->df_type && df->df_type->tp_fund == T_HIDDEN) { - if (tp->tp_fund != T_POINTER) { -error("opaque type \"%s\" is not a pointer type", df->df_idf->id_text); - } - /* Careful now ... we might have declarations - referring to the hidden type. - */ - *(df->df_type) = *tp; - if (! tp->next) { - /* It also contains a forward - reference, so update the forward- - list - */ - ChForward(tp, df->df_type); - } - free_type(tp); - } - else df->df_type = tp; - } + { DeclareType(df, tp); } ; type(struct type **ptp;): - SimpleType(ptp) + %default SimpleType(ptp) | ArrayType(ptp) | @@ -247,7 +209,7 @@ IdentList(struct node **p;) register struct node *q; } : IDENT { *p = q = MkLeaf(Value, &dot); } - [ + [ %persistent ',' IDENT { q->next = MkLeaf(Value, &dot); q = q->next; @@ -460,11 +422,12 @@ PointerType(struct type **ptp;) */ qualtype(&((*ptp)->next)) | %if ( nd = new_node(), nd->nd_token = dot, - df = lookfor(nd, CurrVis, 0), free_node(nd), + df = lookfor(nd, CurrVis, 0), df->df_kind == D_MODULE) - type(&((*ptp)->next)) + type(&((*ptp)->next)) + { free_node(nd); } | - IDENT { Forward(&dot, (*ptp)); } + IDENT { Forward(nd, (*ptp)); } ] ; @@ -486,24 +449,28 @@ ProcedureType(struct type **ptp;) { struct paramlist *pr = 0; register struct type *tp; + arith nbytes = 0; } : { *ptp = 0; } - PROCEDURE FormalTypeList(&pr, ptp)? + PROCEDURE FormalTypeList(&pr, ptp, &nbytes)? { *ptp = tp = construct_type(T_PROCEDURE, *ptp); tp->prc_params = pr; + tp->prc_nbpar = nbytes; } ; -FormalTypeList(struct paramlist **ppr; struct type **ptp;) +FormalTypeList(struct paramlist **ppr; struct type **ptp; arith *parmaddr;) { - struct def *df; int VARp; + struct type *tp; } : '(' { *ppr = 0; } [ - var(&VARp) FormalType(ppr, VARp) + var(&VARp) FormalType(&tp) + { EnterParamList(ppr,NULLNODE,tp,VARp,parmaddr); } [ - ',' var(&VARp) FormalType(ppr, VARp) + ',' var(&VARp) FormalType(&tp) + { EnterParamList(ppr,NULLNODE,tp,VARp,parmaddr); } ]* ]? ')' @@ -535,7 +502,7 @@ VariableDeclaration } : IdentAddr(&VarList) { nd = VarList; } - [ + [ %persistent ',' IdentAddr(&(nd->nd_right)) { nd = nd->nd_right; } ]* diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index 037e9bfe..8c189150 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -290,7 +290,6 @@ DefineLocalModule(id) a name to be used for code generation. */ register struct def *df = define(id, CurrentScope, D_MODULE); - register struct type *tp; register struct scope *sc; static int modulecount = 0; char buf[256]; @@ -316,8 +315,8 @@ DefineLocalModule(id) /* Create a type for it */ - df->df_type = tp = standard_type(T_RECORD, 0, (arith) 0); - tp->rec_scope = sc; + df->df_type = standard_type(T_RECORD, 0, (arith) 0); + df->df_type->rec_scope = sc; /* Generate code that indicates that the initialization procedure for this module is local. diff --git a/lang/m2/comp/defmodule.c b/lang/m2/comp/defmodule.c index 99013dbd..94881826 100644 --- a/lang/m2/comp/defmodule.c +++ b/lang/m2/comp/defmodule.c @@ -74,7 +74,7 @@ GetDefinitionModule(id) } df = lookup(id, GlobalScope); } - assert(df != 0 && df->df_kind == D_MODULE); + assert(df && df->df_kind == D_MODULE); level--; return df; } diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index 0d3bf367..2c9f8743 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -168,8 +168,12 @@ EnterParamList(ppr, Idlist, type, VARp, off) register struct paramlist *pr; register struct def *df; register struct node *idlist = Idlist; + struct node *dummy = 0; static struct paramlist *last; + if (! idlist) { + dummy = Idlist = idlist = MkLeaf(Name, &dot); + } for ( ; idlist; idlist = idlist->next) { pr = new_paramlist(); pr->next = 0; @@ -178,11 +182,17 @@ EnterParamList(ppr, Idlist, type, VARp, off) } else last->next = pr; last = pr; - df = define(idlist->nd_IDF, CurrentScope, D_VARIABLE); + if (idlist != dummy) { + df = define(idlist->nd_IDF, CurrentScope, D_VARIABLE); + df->var_off = *off; + } + else { + df = new_def(); + } pr->par_def = df; df->df_type = type; - df->var_off = *off; df->df_flags = VARp; + if (IsConformantArray(type)) { /* we need room for the base address and a descriptor */ @@ -347,49 +357,38 @@ node_error(idlist, "opaque type \"%s\" is not a pointer type", df->df_idf->id_te FreeNode(Idlist); } -EnterFromImportList(Idlist, Fromid, local) +EnterFromImportList(Idlist, FromDef) struct node *Idlist; - register struct node *Fromid; + register struct def *FromDef; { - /* Import the list Idlist from the module indicated by Fromid. - An exception must be made for imports of the Compilation Unit, - because in this case the definition module for Fromid must - be read. - This case is indicated by the value 0 of the flag "local". + /* Import the list Idlist from the module indicated by Fromdef. */ register struct node *idlist = Idlist; + register struct scopelist *vis; register struct def *df; - struct scopelist *vis = enclosing(CurrVis); int forwflag = 0; - extern struct def *GetDefinitionModule(); - if (local) { - df = lookfor(Fromid, vis, 0); - switch(df->df_kind) { - case D_ERROR: - /* The module from which the import was done - is not yet declared. I'm not sure if I must - accept this, but for the time being I will. - ??? - */ - vis = ForwModule(df, Fromid); - forwflag = 1; - break; - case D_FORWMODULE: - vis = df->for_vis; - break; - case D_MODULE: - vis = df->mod_vis; - break; - default: -node_error(Fromid, "identifier \"%s\" does not represent a module", -Fromid->nd_IDF->id_text); - break; - } + switch(FromDef->df_kind) { + case D_ERROR: + /* The module from which the import was done + is not yet declared. I'm not sure if I must + accept this, but for the time being I will. + ??? + */ + vis = ForwModule(FromDef, FromDef->df_idf); + forwflag = 1; + break; + case D_FORWMODULE: + vis = FromDef->for_vis; + break; + case D_MODULE: + vis = FromDef->mod_vis; + break; + default: +error("identifier \"%s\" does not represent a module", +FromDef->df_idf->id_text); + break; } - else vis = GetDefinitionModule(Fromid->nd_IDF)->mod_vis; - - FreeNode(Fromid); for (; idlist; idlist = idlist->next) { if (forwflag) { diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 36c2bf35..0573fde3 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -18,6 +18,7 @@ static char *RcsId = "$Header$"; #include "def.h" #include "type.h" #include "node.h" +#include "f_info.h" } /* @@ -91,12 +92,22 @@ export(int *QUALflag; struct node **ExportList;) import(int local;) { struct node *ImportList; - register struct node *id; + register struct def *df; + int fromid; + extern struct def *GetDefinitionModule(); } : [ FROM - IDENT { id = MkLeaf(Value, &dot); } + IDENT { fromid = 1; + if (local) { + struct node *nd = MkLeaf(Name, &dot); + + df = lookfor(nd,enclosing(CurrVis),0); + FreeNode(nd); + } + else df = GetDefinitionModule(dot.TOK_IDF); + } | - { id = 0; } + { fromid = 0; } ] IMPORT IdentList(&ImportList) ';' /* @@ -105,7 +116,7 @@ import(int local;) If the FROM clause is present, the identifier in it is a module name, otherwise the names in the import list are module names. */ - { if (id) EnterFromImportList(ImportList, id, local); + { if (fromid) EnterFromImportList(ImportList, df); else EnterImportList(ImportList, local); } ; diff --git a/lang/m2/comp/scope.C b/lang/m2/comp/scope.C index 5333f37f..9962b67c 100644 --- a/lang/m2/comp/scope.C +++ b/lang/m2/comp/scope.C @@ -67,14 +67,14 @@ InitScope() struct forwards { struct forwards *next; - struct node fo_tok; + struct node *fo_tok; struct type *fo_ptyp; }; /* STATICALLOCDEF "forwards" */ Forward(tk, ptp) - struct token *tk; + struct node *tk; struct type *ptp; { /* Enter a forward reference into a list belonging to the @@ -84,7 +84,7 @@ Forward(tk, ptp) */ register struct forwards *f = new_forwards(); - f->fo_tok.nd_token = *tk; + f->fo_tok = tk; f->fo_ptyp = ptp; f->next = CurrentScope->sc_forw; CurrentScope->sc_forw = f; @@ -168,23 +168,24 @@ node_error((*pdf)->for_node, "identifier \"%s\" has not been declared", STATIC rem_forwards(fo) - struct forwards *fo; + register struct forwards *fo; { /* When closing a scope, all forward references must be resolved */ - register struct forwards *f; register struct def *df; - while (f = fo) { - df = lookfor(&(f->fo_tok), CurrVis, 1); - if (!(df->df_kind & (D_TYPE|D_ERROR))) { - node_error(&(f->fo_tok), "identifier \"%s\" not a type", - df->df_idf->id_text); - } - f->fo_ptyp->next = df->df_type; - fo = f->next; - free_forwards(f); + if (fo->next) rem_forwards(fo->next); + df = lookfor(fo->fo_tok, CurrVis, 0); + if (df->df_kind == D_ERROR) { + node_error(fo->fo_tok, "identifier \"%s\" not declared", + df->df_idf->id_text); } + else if (df->df_kind != D_TYPE) { + node_error(fo->fo_tok, "identifier \"%s\" not a type", + df->df_idf->id_text); + } + fo->fo_ptyp->next = df->df_type; + free_forwards(fo); } Reverse(pdf) diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index 610bc9fc..c04f1931 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -104,10 +104,11 @@ construct_type(fund, tp) break; case T_ARRAY: - dtp->tp_align = tp->tp_align; + if (tp) dtp->tp_align = tp->tp_align; break; case T_SUBRANGE: + assert(tp != 0); dtp->tp_align = tp->tp_align; dtp->tp_size = tp->tp_size; break; @@ -386,7 +387,7 @@ ArrayElSize(tp) if (tp->tp_fund == T_ARRAY) ArraySizes(tp); algn = align(tp->tp_size, tp->tp_align); - if (word_size % algn != 0) { + if (algn && word_size % algn != 0) { /* algn is not a dividor of the word size, so make sure it is a multiple */ @@ -449,6 +450,36 @@ FreeType(tp) free_type(tp); } +DeclareType(df, tp) + register struct def *df; + register struct type *tp; +{ + /* A type with type-description "tp" is declared and must + be bound to definition "df". + This routine also handles the case that the type-field of + "df" is already bound. In that case, it is either an opaque + type, or an error message was given when "df" was created. + */ + + if (df->df_type && df->df_type->tp_fund == T_HIDDEN) { + if (tp->tp_fund != T_POINTER) { +error("opaque type \"%s\" is not a pointer type", df->df_idf->id_text); + } + /* Careful now ... we might have declarations + referring to the hidden type. + */ + *(df->df_type) = *tp; + if (! tp->next) { + /* It also contains a forward reference, + so update the forwardlist + */ + ChForward(tp, df->df_type); + } + free_type(tp); + } + else df->df_type = tp; +} + int gcd(m, n) register int m, n; diff --git a/lang/m2/comp/typequiv.c b/lang/m2/comp/typequiv.c index 0b0b9953..422638c8 100644 --- a/lang/m2/comp/typequiv.c +++ b/lang/m2/comp/typequiv.c @@ -81,6 +81,9 @@ TstProcEquiv(tp1, tp2) p2 = p2->next; } + /* Here, at least one of the parameterlists is exhausted. + Check that they are both. + */ return p1 == p2; } @@ -101,18 +104,17 @@ TstCompat(tp1, tp2) || ( tp1 == intorcard_type && - (tp2 == int_type || tp2 == card_type) + (tp2 == int_type || tp2 == card_type || tp2 == address_type) ) || ( tp2 == intorcard_type && - (tp1 == int_type || tp1 == card_type) + (tp1 == int_type || tp1 == card_type || tp1 == address_type) ) || ( tp1 == address_type && ( tp2 == card_type - || tp2 == intorcard_type || tp2->tp_fund == T_POINTER ) ) @@ -120,7 +122,6 @@ TstCompat(tp1, tp2) ( tp2 == address_type && ( tp1 == card_type - || tp1 == intorcard_type || tp1->tp_fund == T_POINTER ) ) @@ -173,7 +174,7 @@ TstAssCompat(tp1, tp2) int TstParCompat(formaltype, actualtype, VARflag, nd) - struct type *formaltype, *actualtype; + register struct type *formaltype, *actualtype; struct node *nd; { /* Check type compatibility for a parameter in a procedure call. @@ -218,19 +219,12 @@ TstParCompat(formaltype, actualtype, VARflag, nd) ) ) || - ( VARflag && OldCompat(formaltype, actualtype, nd)) + ( VARflag + && ( TstCompat(formaltype, actualtype) + && +(node_warning(nd, "oldfashioned! types of formal and actual must be identical"), + 1) + ) + ) ; } - -int -OldCompat(ft, at, nd) - struct type *ft, *at; - struct node *nd; -{ - if (TstCompat(ft, at)) { -node_warning(nd, "oldfashioned! types of formal and actual must be identical"); - return 1; - } - - return 0; -} diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index 7454ed96..c6324938 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -132,6 +132,8 @@ WalkProcedure(procedure) register struct type *tp; register struct paramlist *param; label func_res_label = 0; + arith tmpvar1 = 0; + arith retsav = 0; proclevel++; CurrVis = procedure->prc_vis; @@ -147,6 +149,14 @@ WalkProcedure(procedure) DoProfil(); TmpOpen(sc); + func_type = tp = ResultType(procedure->df_type); + + if (tp && IsConstructed(tp)) { + func_res_label = ++data_label; + C_df_dlb(func_res_label); + C_bss_cst(tp->tp_size, (arith) 0, 0); + } + /* Generate calls to initialization routines of modules defined within this procedure */ @@ -154,6 +164,7 @@ WalkProcedure(procedure) /* Make sure that arguments of size < word_size are on a fixed place. + Also make copies of conformant arrays when neccessary. */ for (param = ParamList(procedure->df_type); param; @@ -161,37 +172,114 @@ WalkProcedure(procedure) if (! IsVarParam(param)) { tp = TypeOfParam(param); - if (!IsConformantArray(tp) && tp->tp_size < word_size) { - C_lol(param->par_def->var_off); + if (! IsConformantArray(tp)) { + if (tp->tp_size < word_size) { + C_lol(param->par_def->var_off); + C_lal(param->par_def->var_off); + C_sti(tp->tp_size); + } + } + else { + /* Here, we have to make a copy of the + array. We must also remember how much + room is reserved for copies, because + we have to adjust the stack pointer before + a RET is done. This is even more complicated + when the procedure returns a value. + Then, the value must be saved (in retval), + the stack adjusted, the return value pushed + again, and then RET + */ + arith tmpvar = NewInt(); + + if (! tmpvar1) { + if (tp && !func_res_label) { + /* Some local space, only + needed if the value itself + is returned + */ + sc->sc_off -= WA(tp->tp_size); + retsav = sc->sc_off; + } + tmpvar1 = NewInt(); + C_loc((arith) 0); + C_stl(tmpvar1); + } + /* First compute the size */ + C_lol(param->par_def->var_off + + pointer_size + word_size); + C_inc(); /* gives number of elements */ + C_loc(tp->arr_elem->tp_size); + C_cal("_wa"); + C_asp(dword_size); + C_lfr(word_size); + /* size in words */ + C_loc(word_size); + C_mli(word_size); + /* size in bytes */ + C_stl(tmpvar); + C_lol(tmpvar); + C_dup(word_size); + C_lol(tmpvar1); + C_adi(word_size); + C_stl(tmpvar1); /* remember all stack adjustments */ + C_ngi(word_size); + C_ass(word_size); + /* adjusted stack pointer */ + C_lor((arith) 1); + /* destination address */ C_lal(param->par_def->var_off); - C_sti(tp->tp_size); + C_loi(pointer_size); + /* push source address */ + C_exg(pointer_size); + /* exchange them */ + C_lol(tmpvar); /* push size */ + C_bls(word_size); + /* copy */ + C_lor((arith) 1); + /* push new address of array */ + C_lal(param->par_def->var_off); + C_sti(pointer_size); + FreeInt(tmpvar); } } } text_label = 1; - func_type = tp = ResultType(procedure->df_type); - - if (IsConstructed(tp)) { - func_res_label = ++data_label; - C_df_dlb(func_res_label); - C_bss_cst(tp->tp_size, (arith) 0, 0); - } DO_DEBUG(options['X'], PrNode(procedure->prc_body, 0)); WalkNode(procedure->prc_body, (label) 0); - C_ret((arith) 0); - if (tp) { - C_df_ilb((label) 1); - if (func_res_label) { - C_lae_dlb(func_res_label, (arith) 0); - C_sti(tp->tp_size); - C_lae_dlb(func_res_label, (arith) 0); - C_ret(pointer_size); + C_df_ilb((label) 1); + tp = func_type; + if (func_res_label) { + C_lae_dlb(func_res_label, (arith) 0); + C_sti(tp->tp_size); + if (tmpvar1) { + C_lol(tmpvar1); + C_ass(word_size); } - else C_ret(WA(tp->tp_size)); + C_lae_dlb(func_res_label, (arith) 0); + C_ret(pointer_size); } - + else if (tp) { + if (tmpvar1) { + C_lal(retsav); + C_sti(WA(tp->tp_size)); + C_lol(tmpvar1); + C_ass(word_size); + C_lal(retsav); + C_loi(WA(tp->tp_size)); + } + C_ret(WA(tp->tp_size)); + } + else { + if (tmpvar1) { + C_lol(tmpvar1); + C_ass(word_size); + } + C_ret((arith) 0); + } + if (tmpvar1) FreeInt(tmpvar1); if (! options['n']) RegisterMessages(sc->sc_def); C_end(-sc->sc_off); TmpClose(); @@ -394,7 +482,7 @@ WalkStat(nd, lab) struct desig ds; arith tmp = 0; - WalkDesignator(left, &ds); + if (! WalkDesignator(left, &ds)) break; if (left->nd_type->tp_fund != T_RECORD) { node_error(left, "record variable expected"); break; @@ -432,7 +520,7 @@ WalkStat(nd, lab) case RETURN: if (right) { - WalkExpr(right); + if (! WalkExpr(right)) break; /* The type of the return-expression must be assignment compatible with the result type of the function procedure (See Rep. 9.11). @@ -440,9 +528,8 @@ WalkStat(nd, lab) if (!TstAssCompat(func_type, right->nd_type)) { node_error(right, "type incompatibility in RETURN statement"); } - C_bra((label) 1); } - else C_ret((arith) 0); + C_bra((label) 1); break; default: @@ -487,17 +574,20 @@ ExpectBool(nd, true_label, false_label) CodeExpr(nd, &ds, true_label, false_label); } +int WalkExpr(nd) struct node *nd; { /* Check an expression and generate code for it */ - if (! ChkExpression(nd)) return; + if (! ChkExpression(nd)) return 0; CodePExpr(nd); + return 1; } +int WalkDesignator(nd, ds) struct node *nd; struct desig *ds; @@ -505,10 +595,11 @@ WalkDesignator(nd, ds) /* Check designator and generate code for it */ - if (! ChkVariable(nd)) return; + if (! ChkVariable(nd)) return 0; *ds = InitDesig; CodeDesig(nd, ds); + return 1; } DoForInit(nd, left) From 01171cbc52ac597bde41b7f0a071e9012ac131dc Mon Sep 17 00:00:00 2001 From: erikb Date: Tue, 26 Aug 1986 14:59:36 +0000 Subject: [PATCH 0248/1625] first operand to intexpr is arith typed --- lang/cem/cemcom/ch7.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/cem/cemcom/ch7.c b/lang/cem/cemcom/ch7.c index 9c5819ed..d73052fc 100644 --- a/lang/cem/cemcom/ch7.c +++ b/lang/cem/cemcom/ch7.c @@ -335,7 +335,7 @@ ch7asgn(expp, oper, expr) ch7cast(&expr, oper, (*expp)->ex_type); } else { /* turn e into e' where typeof(e') = typeof (f op e) */ - struct expr *extmp = intexpr(0, INT); + struct expr *extmp = intexpr((arith)0, INT); /* this is really $#@&*%$# ! */ extmp->ex_lvalue = 1; From 2c23adf9737a1789b1cdc1c56d329045b731e26e Mon Sep 17 00:00:00 2001 From: sater Date: Thu, 28 Aug 1986 10:28:42 +0000 Subject: [PATCH 0249/1625] Error fixed where w==2 was assumed --- util/opt/patterns | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/opt/patterns b/util/opt/patterns index d1c607b2..1b58cf03 100644 --- a/util/opt/patterns +++ b/util/opt/patterns @@ -363,7 +363,7 @@ tne tne : tne tne zeq : zeq $2 tne zne : zne $2 #ifdef INT -loc loc loc $1==0 && $2==0 && $3==0 : zer 6 +loc loc loc $1==0 && $2==0 && $3==0 : zer 3*w zer loc defined($1) && $2==0: zer $1+w #endif loi loc and $1==1 && $3==w && ($2&255)==255: loi 1 From b18ced777efd4a2dcd4d3a7f0339b62f5bc6dcff Mon Sep 17 00:00:00 2001 From: erikb Date: Tue, 2 Sep 1986 15:00:50 +0000 Subject: [PATCH 0250/1625] added some LINT facilities --- lang/cem/cemcom/Makefile.erik | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lang/cem/cemcom/Makefile.erik b/lang/cem/cemcom/Makefile.erik index 8e6305d8..73d412c7 100644 --- a/lang/cem/cemcom/Makefile.erik +++ b/lang/cem/cemcom/Makefile.erik @@ -5,8 +5,10 @@ EM = /user1/erikb/em# # ACK tree on this machine DESTINATION = /user1/$$USER/bin# # where to put the stuff MKDEP = /user1/erikb/bin/mkdep# # dependency generator -MAP = -DInsertFile=ins_file -DInsertText=ins_text# # bug in m68k2 back end +MAP = +#MAP = -DInsertFile=ins_file -DInsertText=ins_text# # bug in m68k2 back end SIM = /user1/dick/bin/sim# # Dicks sim program +LINT = /usr/new/lint # Libraries and EM interface definitions SYSLIB = $(EM)/modules/lib/libsystem.a @@ -20,6 +22,15 @@ LIBS = $(CH3LIB) $(EMMESLIB) $(EMKLIB) $(PRTLIB) $(STRLIB) $(SYSLIB) ELIBS = $(CH3LIB) $(EMMESLIB) $(EMELIB) $(PRTLIB) $(STRLIB) $(SYSLIB) LIB_INCLUDES = $(EM)/modules/h EM_INCLUDES = $(EM)/h +SYSLLIB = $(EM)/modules/lib/llib-lsys.ln +EMKLLIB = $(EM)/modules/lib/llib-lemk.ln +EMELLIB = $(EM)/modules/lib/llib-leme.ln +STRLLIB = $(EM)/modules/lib/llib-lstr.ln +PRTLLIB = $(EM)/modules/lib/llib-lprint.ln +EMMESLLIB = $(EM)/modules/lib/llib-lmes.ln +CH3LLIB = $(EM)/modules/lib/llib-lch3.ln +LINTLIBS = +#LINTLIBS = $(CH3LLIB) $(EMMESLLIB) $(EMKLLIB) $(PRTLLIB) $(STRLLIB) $(SYSLLIB) # Where to install the compiler and its driver CEMCOM = $(DESTINATION)/cemcom @@ -91,7 +102,7 @@ cem: cem.c $(CC) -O cem.c $(SYSLIB) -o cem lint.cem: cem.c - lint -abx cem.c + $(LINT) -bx cem.c hfiles: ./make.hfiles Parameters ./make.hfiles Parameters @@ -176,7 +187,7 @@ lxref: lint: lint.main lint.cem lint.tab lint.main: cfiles - lint -bx $(CDEFS) `sources $(OBJ)` >lint.out + $(LINT) -bx $(CDEFS) `sources $(OBJ)` $(LINTLIBS) >lint.out cchk: cchk `sources $(COBJ)` @@ -188,7 +199,7 @@ tab: $(CC) tab.c -o tab lint.tab: - lint -abx tab.c + $(LINT) -abx tab.c sim: cfiles $(SIM) $(SIMFLAGS) `sources $(COBJ)` $(GSRC) $(LSRC) From c2a10ef9bc636db8d860d01b17eda4765bd4c537 Mon Sep 17 00:00:00 2001 From: erikb Date: Tue, 2 Sep 1986 15:22:54 +0000 Subject: [PATCH 0251/1625] various null-dereference problems fixed --- lang/cem/cemcom/code.c | 7 ++++++- lang/cem/cemcom/expr.c | 1 + lang/cem/cemcom/idf.c | 6 ++---- lang/cem/cemcom/statement.g | 2 +- lang/cem/cemcom/struct.c | 2 +- lang/cem/cemcom/switch.c | 14 +++++++------- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/lang/cem/cemcom/code.c b/lang/cem/cemcom/code.c index b56e16e3..c273ba35 100644 --- a/lang/cem/cemcom/code.c +++ b/lang/cem/cemcom/code.c @@ -183,7 +183,12 @@ begin_proc(name, def) /* to be called when entering a procedure */ DfaStartFunction(name); #endif DATAFLOW - func_tp = def->df_type->tp_up; + if (def->df_type->tp_fund != FUNCTION) { + error("making function body for non-function"); + func_tp = error_type; + } + else + func_tp = def->df_type->tp_up; size = ATW(func_tp->tp_size); C_pro_narg(name); if (is_struct_or_union(func_tp->tp_fund)) { diff --git a/lang/cem/cemcom/expr.c b/lang/cem/cemcom/expr.c index 3549c840..4fa8cf7e 100644 --- a/lang/cem/cemcom/expr.c +++ b/lang/cem/cemcom/expr.c @@ -171,6 +171,7 @@ idf2expr(expr) /* now def != 0 */ if (def->df_type->tp_fund == LABEL) { expr_error(expr, "illegal use of label %s", idf->id_text); + expr->ex_type = error_type; } else { def->df_used = 1; diff --git a/lang/cem/cemcom/idf.c b/lang/cem/cemcom/idf.c index 05e74f8b..aa6c48f1 100644 --- a/lang/cem/cemcom/idf.c +++ b/lang/cem/cemcom/idf.c @@ -181,7 +181,7 @@ declare_idf(ds, dc, lvl) /* at the L_FORMAL1 level there is no type specified yet */ ASSERT(lvl == L_FORMAL1); - type = 0; + type = int_type; /* may change at L_FORMAL2 */ } else { /* combine the decspecs and the declarator into one type */ @@ -583,7 +583,7 @@ declare_parameter(idf) { /* idf is declared as a formal. */ - add_def(idf, FORMAL, (struct type *)0, level); + add_def(idf, FORMAL, int_type, level); } declare_enum(tp, idf, l) @@ -616,8 +616,6 @@ declare_formals(fp) struct idf *idf = se->se_idf; struct def *def = idf->id_def; - if (def->df_type == 0) - def->df_type = int_type; /* default type */ def->df_address = f_offset; /* the alignment convention for parameters is: align on diff --git a/lang/cem/cemcom/statement.g b/lang/cem/cemcom/statement.g index 62ce1b3a..4109ba07 100644 --- a/lang/cem/cemcom/statement.g +++ b/lang/cem/cemcom/statement.g @@ -279,7 +279,7 @@ switch_statement '(' expression(&expr) { - code_startswitch(expr); + code_startswitch(&expr); } ')' statement diff --git a/lang/cem/cemcom/struct.c b/lang/cem/cemcom/struct.c index b7e266e6..b5af15c0 100644 --- a/lang/cem/cemcom/struct.c +++ b/lang/cem/cemcom/struct.c @@ -310,7 +310,7 @@ idf2sdef(idf, tp) *sdefp = sdef = new_sdef(); clear((char *)sdef, sizeof(struct sdef)); sdef->sd_idf = idf; - sdef->sd_type = error_type; + sdef->sd_stype = sdef->sd_type = error_type; return sdef; } diff --git a/lang/cem/cemcom/switch.c b/lang/cem/cemcom/switch.c index 30fd0abe..4a73673c 100644 --- a/lang/cem/cemcom/switch.c +++ b/lang/cem/cemcom/switch.c @@ -32,8 +32,8 @@ static struct switch_hdr *switch_stack = 0; For simplicity, we suppose int_size == word_size. */ -code_startswitch(expr) - struct expr *expr; +code_startswitch(expp) + struct expr **expp; { /* Check the expression, stack a new case header and fill in the necessary fields. @@ -41,17 +41,17 @@ code_startswitch(expr) register label l_table = text_label(); register label l_break = text_label(); register struct switch_hdr *sh = new_switch_hdr(); - int fund = any2arith(&expr, SWITCH); /* INT, LONG or DOUBLE */ + int fund = any2arith(expp, SWITCH); /* INT, LONG or DOUBLE */ switch (fund) { case LONG: if (options['R']) warning("long in switch (cast to int)"); - int2int(&expr, int_type); + int2int(expp, int_type); break; case DOUBLE: error("float/double in switch"); - erroneous2int(&expr); + erroneous2int(expp); break; } @@ -60,12 +60,12 @@ code_startswitch(expr) sh->sh_default = 0; sh->sh_table = l_table; sh->sh_nrofentries = 0; - sh->sh_type = expr->ex_type; /* the expression switched */ + sh->sh_type = (*expp)->ex_type; /* the expression switched */ sh->sh_lowerbd = sh->sh_upperbd = (arith)0; /* immaterial ??? */ sh->sh_entries = (struct case_entry *) 0; /* case-entry list */ sh->next = switch_stack; /* push onto switch-stack */ switch_stack = sh; - code_expr(expr, RVAL, TRUE, NO_LABEL, NO_LABEL); + code_expr(*expp, RVAL, TRUE, NO_LABEL, NO_LABEL); /* evaluate the switch expr. */ C_bra(l_table); /* goto start of switch_table */ } From 004a1d541466d7f8042695d0da4938dbec77d49e Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 5 Sep 1986 16:35:12 +0000 Subject: [PATCH 0252/1625] An improvement to prevent calls to the .cuu routine. --- mach/i86/cg/table | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/mach/i86/cg/table b/mach/i86/cg/table index b444751c..82049d18 100644 --- a/mach/i86/cg/table +++ b/mach/i86/cg/table @@ -1139,15 +1139,12 @@ loc loc cii $1==2 && $2==4 | ACC | "cwd" samecc | dx ax | |(1,5) loc loc cii $1==4 && $2==2 | a_word a_word | | %[1] | | +loc loc ciu | | | | loc $1 loc $2 cuu | +loc loc cui | | | | loc $1 loc $2 cuu | +loc loc cuu $1==$2 | | | | | loc loc cuu $1==2 && $2==4 | a_word | allocate(REG={ANYCON,0})| %[a] %[1] | | loc loc cuu $1==4 && $2==2 | a_word a_word | | %[1] | | -loc loc ciu $1==2 && $2==4 | a_word | - allocate(REG={ANYCON,0})| %[a] %[1] | | -loc loc ciu $1==4 && $2==2 | a_word a_word | | %[1] | | -loc loc cui $1==2 && $2==4 | a_word | - allocate(REG={ANYCON,0})| %[a] %[1] | | -loc loc cui $1==4 && $2==2 | a_word a_word | | %[1] | | /**************************************** * Group 9 : Logical instructions * From 1939e147a4f921d84b12f3593efca2138b6c68b6 Mon Sep 17 00:00:00 2001 From: erikb Date: Tue, 9 Sep 1986 09:47:43 +0000 Subject: [PATCH 0253/1625] corrected the compile-time evaluation of ~ --- lang/cem/cemcom/ch7mon.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lang/cem/cemcom/ch7mon.c b/lang/cem/cemcom/ch7mon.c index 64b3170e..2d633246 100644 --- a/lang/cem/cemcom/ch7mon.c +++ b/lang/cem/cemcom/ch7mon.c @@ -13,6 +13,7 @@ #include "def.h" extern char options[]; +extern long full_mask[/*MAXSIZE*/]; /* cstoper.c */ char *symbol2str(); ch7mon(oper, expp) @@ -99,13 +100,18 @@ ch7mon(oper, expp) erroneous2int(expp); break; } - /* FALL THROUGH */ + /* FALLTHROUGH */ } case '-': any2arith(expp, oper); if (is_cp_cst(*expp)) { arith o1 = (*expp)->VL_VALUE; - (*expp)->VL_VALUE = (oper == '-') ? -o1 : ~o1; + + (*expp)->VL_VALUE = (oper == '-') ? -o1 : + ((*expp)->ex_type->tp_unsigned ? + (~o1) & full_mask[(*expp)->ex_type->tp_size] : + ~o1 + ); } else if (is_fp_cst(*expp)) From af1c3f29a826da9bbdf0f5eaf0e9e4eab8356123 Mon Sep 17 00:00:00 2001 From: em Date: Tue, 9 Sep 1986 13:10:15 +0000 Subject: [PATCH 0254/1625] set limit on optimization passes to prevent loop in optimizer in case of bad table. --- util/opt/peephole.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/util/opt/peephole.c b/util/opt/peephole.c index 1a52beea..3b013cb4 100644 --- a/util/opt/peephole.c +++ b/util/opt/peephole.c @@ -609,7 +609,9 @@ basicblock(alpp) line_p *alpp; { register byte *bp; int i; short index; + int npasses; + npasses = 0; do { /* make pass over basicblock */ lpp = alpp; madeopt = FALSE; while ((*lpp) != (line_p) 0 && ((*lpp)->l_instr&BMASK) != op_lab) { @@ -648,5 +650,6 @@ basicblock(alpp) line_p *alpp; { } lpp = next; } - } while(madeopt); /* as long as there is progress */ + } while(madeopt && ++npasses<5000); /* as long as there is progress */ + assert(!madeopt); } From c489f7f608df1739db0992a9db7d9e19e64d3982 Mon Sep 17 00:00:00 2001 From: erikb Date: Tue, 9 Sep 1986 13:49:46 +0000 Subject: [PATCH 0255/1625] simplified the return expression in loadbuf() --- lang/cem/cemcom/input.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/lang/cem/cemcom/input.c b/lang/cem/cemcom/input.c index 850f7f08..adae8d9f 100644 --- a/lang/cem/cemcom/input.c +++ b/lang/cem/cemcom/input.c @@ -317,6 +317,8 @@ InsertFile(filnam, table) } #else NOPP { + LineNumber = 0; + FileName = filnam; #ifdef READ_IN_ONE isize = size; ipp = text; @@ -361,10 +363,8 @@ EXPORT int loadbuf() { #ifndef NOPP - if (!head) { - /* stack exhausted, EOF on sourcefile */ + if (!head) /* stack exhausted, EOF on sourcefile */ return EOI; - } #endif NOPP #ifndef NOPP @@ -372,23 +372,18 @@ loadbuf() #else NOPP if (ipp < &ibuf[isize]) #endif NOPP - { - /* a genuine '\0' character has been seen */ - return '\0'; - } + return '\0'; /* a genuine '\0' character has been seen */ #ifndef READ_IN_ONE #ifndef NOPP if ( FilDes != 0 && (head->bh_size = readblock(FilDes, head->bh_text)) > 0 - ) { + ) return ipp = &(head->bh_text[1]), *ipp++; - } #else NOPP if (FilDes != 0 && (isize = readblock(FilDes, &ibuf[0])) > 0) return ipp = &ibuf[1], *ipp++; #endif NOPP - #endif READ_IN_ONE #ifdef NOPP @@ -399,11 +394,12 @@ loadbuf() #endif READ_IN_ONE #endif NOPP - return #ifndef NOPP - pop_bh() ? (*ipp ? *ipp++ : loadbuf()) : + if (pop_bh()) + return *ipp ? *ipp++ : loadbuf(); #endif NOPP - (ipp = &"\0\0"[1], EOI); + ipp = &"\0\0"[1]; + return EOI; } /* Some miscellaneous routines : setwdir() and mk_filename() From 7bc71298bef52fd30deabddbfdb4abe54b1c9057 Mon Sep 17 00:00:00 2001 From: erikb Date: Wed, 10 Sep 1986 10:23:26 +0000 Subject: [PATCH 0256/1625] corrected the treatment of the <<= and >>= operators --- lang/cem/cemcom/ch7.c | 17 ++++++++++++----- lang/cem/cemcom/ch7bin.c | 3 ++- lang/cem/cemcom/eval.c | 36 ++++++++++++++++++------------------ 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/lang/cem/cemcom/ch7.c b/lang/cem/cemcom/ch7.c index d73052fc..0cb13fb5 100644 --- a/lang/cem/cemcom/ch7.c +++ b/lang/cem/cemcom/ch7.c @@ -324,6 +324,7 @@ ch7asgn(expp, oper, expr) EVAL should however take care of evaluating (typeof (f op e))f */ int fund = (*expp)->ex_type->tp_fund; + struct type *tp; /* We expect an lvalue */ if (!(*expp)->ex_lvalue) { @@ -333,6 +334,7 @@ ch7asgn(expp, oper, expr) } if (oper == '=') { ch7cast(&expr, oper, (*expp)->ex_type); + tp = expr->ex_type; } else { /* turn e into e' where typeof(e') = typeof (f op e) */ struct expr *extmp = intexpr((arith)0, INT); @@ -341,13 +343,14 @@ ch7asgn(expp, oper, expr) extmp->ex_lvalue = 1; extmp->ex_type = (*expp)->ex_type; ch7bin(&extmp, oper, expr); - /* note that ch7bin creates a tree of the expression + /* Note that ch7bin creates a tree of the expression ((typeof (f op e))f op (typeof (f op e))e), - where f ~ extmp and e ~ expr; - we have to use (typeof (f op e))e + where f ~ extmp and e ~ expr. + We want to use (typeof (f op e))e. Ch7bin does not create a tree if both operands were illegal or constants! */ + tp = extmp->ex_type; /* perform the arithmetic in type tp */ if (extmp->ex_class == Oper) { expr = extmp->OP_RIGHT; extmp->OP_RIGHT = NILEXPR; @@ -356,13 +359,17 @@ ch7asgn(expp, oper, expr) else expr = extmp; } + #ifndef NOBITFIELD if (fund == FIELD) *expp = new_oper((*expp)->ex_type->tp_up, *expp, oper, expr); else -#endif NOBITFIELD *expp = new_oper((*expp)->ex_type, *expp, oper, expr); - (*expp)->OP_TYPE = expr->ex_type; /* for EVAL() */ +#else NOBITFIELD + *expp = new_oper((*expp)->ex_type, *expp, oper, expr); +#endif NOBITFIELD + + (*expp)->OP_TYPE = tp; /* for EVAL() */ } /* Some interesting (?) questions answered. diff --git a/lang/cem/cemcom/ch7bin.c b/lang/cem/cemcom/ch7bin.c index 970e8b76..c34e1c21 100644 --- a/lang/cem/cemcom/ch7bin.c +++ b/lang/cem/cemcom/ch7bin.c @@ -156,7 +156,8 @@ ch7bin(expp, oper, expr) case RIGHTAB: opnd2integral(expp, oper); opnd2integral(&expr, oper); - ch7cast(&expr, oper, int_type); /* leftop should be int */ + fund = arithbalance(expp, oper, &expr); /* ch. 7.5 */ + ch7cast(&expr, oper, int_type); /* cvt. rightop to int */ non_commutative_binop(expp, oper, expr); break; case '<': diff --git a/lang/cem/cemcom/eval.c b/lang/cem/cemcom/eval.c index 2ce3f825..ac14d2d2 100644 --- a/lang/cem/cemcom/eval.c +++ b/lang/cem/cemcom/eval.c @@ -35,7 +35,7 @@ #include "atw.h" #define CRASH() crash("EVAL: CRASH at line %u", __LINE__) -#define roundup(n) ((n) < word_size ? word_size : (n)) +#define toword(n) ((n) < word_size ? word_size : (n)) char *symbol2str(); char *long2str(); @@ -374,6 +374,10 @@ EVAL(expr, val, code, true_label, false_label) case ANDAB: case XORAB: case ORAB: + { + arith old_offset; + arith tmpvar = tmp_pointer_var(&old_offset); + #ifndef NOBITFIELD if (leftop->ex_type->tp_fund == FIELD) { eval_field(expr, code); @@ -381,34 +385,29 @@ EVAL(expr, val, code, true_label, false_label) } #endif NOBITFIELD if (leftop->ex_class != Value) { - arith old_offset; - arith tmpvar = tmp_pointer_var(&old_offset); - EVAL(leftop, LVAL, TRUE, NO_LABEL, NO_LABEL); C_lal(tmpvar); C_sti(pointer_size); C_lal(tmpvar); C_loi(pointer_size); C_loi(leftop->ex_type->tp_size); - conversion(leftop->ex_type, tp); - EVAL(rightop, RVAL, TRUE, NO_LABEL, NO_LABEL); - assop(tp, oper); - conversion(tp, leftop->ex_type); - if (gencode) - C_dup(roundup(leftop->ex_type->tp_size)); + } + else { + load_val(leftop, RVAL); + } + conversion(leftop->ex_type, tp); + EVAL(rightop, RVAL, TRUE, NO_LABEL, NO_LABEL); + assop(tp, oper); + conversion(tp, leftop->ex_type); + if (gencode) + C_dup(toword(leftop->ex_type->tp_size)); + if (leftop->ex_class != Value) { C_lal(tmpvar); C_loi(pointer_size); C_sti(leftop->ex_type->tp_size); free_tmp_var(old_offset); } - else { - load_val(leftop, RVAL); - conversion(leftop->ex_type, tp); - EVAL(rightop, RVAL, TRUE, NO_LABEL, NO_LABEL); - assop(tp, oper); - conversion(tp, leftop->ex_type); - if (gencode) - C_dup(roundup(leftop->ex_type->tp_size)); + else { store_val( &(leftop->ex_object.ex_value), leftop->ex_type @@ -417,6 +416,7 @@ EVAL(expr, val, code, true_label, false_label) if (gencode) conversion(leftop->ex_type, expr->ex_type); break; + } case '(': { register struct expr *expr; From 106c9e2293d3546f4a025fa924503068086256a4 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 10 Sep 1986 16:03:11 +0000 Subject: [PATCH 0257/1625] Bug fix: The "cmp.l" instruction was sometimes used in an illegal way. --- mach/m68k2/cg/table | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/mach/m68k2/cg/table b/mach/m68k2/cg/table index 62f8dcb3..c9c2abf5 100644 --- a/mach/m68k2/cg/table +++ b/mach/m68k2/cg/table @@ -2319,7 +2319,7 @@ cmp tlt | ANY4 ADDREG | allocate(DATAREG={IMMEDIATE,1}) "clr.w %[a]" "1:" erase(%[a]) | %[a] | | -... | nocoercions: EXTERNAL_ADDR ANY4 | allocate(DATAREG={IMMEDIATE,1}) +... | nocoercions: EXTERNAL_ADDR DATA_ALT4 | allocate(DATAREG={IMMEDIATE,1}) "cmp.l %[1],%[2]" "bcs 1f" "clr.w %[a]" @@ -2331,7 +2331,7 @@ cmp tle | ANY4 ADDREG | allocate(DATAREG={IMMEDIATE,1}) "clr.w %[a]" "1:" erase(%[a]) | %[a] | | -... | nocoercions: EXTERNAL_ADDR ANY4 | allocate(DATAREG={IMMEDIATE,1}) +... | nocoercions: EXTERNAL_ADDR DATA_ALT4 | allocate(DATAREG={IMMEDIATE,1}) "cmp.l %[1],%[2]" "bls 1f" "clr.w %[a]" @@ -2343,7 +2343,7 @@ cmp teq | ANY4 ADDREG | allocate(DATAREG={IMMEDIATE,1}) "clr.w %[a]" "1:" erase(%[a]) | %[a] | | -... | nocoercions: EXTERNAL_ADDR ANY4 | allocate(DATAREG={IMMEDIATE,1}) +... | nocoercions: EXTERNAL_ADDR DATA_ALT4 | allocate(DATAREG={IMMEDIATE,1}) "cmp.l %[1],%[2]" "beq 1f" "clr.w %[a]" @@ -2355,7 +2355,7 @@ cmp bne | ANY4 ADDREG | allocate(DATAREG={IMMEDIATE,1}) "clr.w %[a]" "1:" erase(%[a]) | %[a] | | -... | nocoercions: EXTERNAL_ADDR ANY4 | allocate(DATAREG={IMMEDIATE,1}) +... | nocoercions: EXTERNAL_ADDR DATA_ALT4 | allocate(DATAREG={IMMEDIATE,1}) "cmp.l %[1],%[2]" "bne 1f" "clr.w %[a]" @@ -2367,7 +2367,7 @@ cmp tge | ANY4 ADDREG | allocate(DATAREG={IMMEDIATE,1}) "clr.w %[a]" "1:" erase(%[a]) | %[a] | | -... | nocoercions: EXTERNAL_ADDR ANY4 | allocate(DATAREG={IMMEDIATE,1}) +... | nocoercions: EXTERNAL_ADDR DATA_ALT4 | allocate(DATAREG={IMMEDIATE,1}) "cmp.l %[1],%[2]" "bcc 1f" "clr.w %[a]" @@ -2379,7 +2379,7 @@ cmp tgt | ANY4 ADDREG | allocate(DATAREG={IMMEDIATE,1}) "clr.w %[a]" "1:" erase(%[a]) | %[a] | | -... | nocoercions: EXTERNAL_ADDR ANY4 | allocate(DATAREG={IMMEDIATE,1}) +... | nocoercions: EXTERNAL_ADDR DATA_ALT4 | allocate(DATAREG={IMMEDIATE,1}) "cmp.l %[1],%[2]" "bhi 1f" "clr.w %[a]" @@ -2389,37 +2389,37 @@ cmp tgt | ANY4 ADDREG | allocate(DATAREG={IMMEDIATE,1}) cmp zlt | ANY4 ADDREG | remove(ALL) "cmp.l %[1],%[2]" "bcs $2" | | | -... | nocoercions: EXTERNAL_ADDR ANY4 | remove(ALL) +... | nocoercions: EXTERNAL_ADDR DATA_ALT4 | remove(ALL) "cmp.l %[1],%[2]" "bcs $2" | | | cmp zle | ANY4 ADDREG | remove(ALL) "cmp.l %[1],%[2]" "bls $2" | | | -... | nocoercions: EXTERNAL_ADDR ANY4 | remove(ALL) +... | nocoercions: EXTERNAL_ADDR DATA_ALT4 | remove(ALL) "cmp.l %[1],%[2]" "bls $2" | | | cmp zeq | ANY4 ADDREG | remove(ALL) "cmp.l %[1],%[2]" "beq $2" | | | -... | nocoercions: EXTERNAL_ADDR ANY4 | remove(ALL) +... | nocoercions: EXTERNAL_ADDR DATA_ALT4 | remove(ALL) "cmp.l %[1],%[2]" "beq $2" | | | cmp zne | ANY4 ADDREG | remove(ALL) "cmp.l %[1],%[2]" "bne $2" | | | -... | nocoercions: EXTERNAL_ADDR ANY4 | remove(ALL) +... | nocoercions: EXTERNAL_ADDR DATA_ALT4 | remove(ALL) "cmp.l %[1],%[2]" "bne $2" | | | cmp zge | ANY4 ADDREG | remove(ALL) "cmp.l %[1],%[2]" "bcc $2" | | | -... | nocoercions: EXTERNAL_ADDR ANY4 | remove(ALL) +... | nocoercions: EXTERNAL_ADDR DATA_ALT4 | remove(ALL) "cmp.l %[1],%[2]" "bcc $2" | | | cmp zgt | ANY4 ADDREG | remove(ALL) "cmp.l %[1],%[2]" "bhi $2" | | | -... | nocoercions: EXTERNAL_ADDR ANY4 | remove(ALL) +... | nocoercions: EXTERNAL_ADDR DATA_ALT4 | remove(ALL) "cmp.l %[1],%[2]" "bhi $2" | | | tlt and $2==2 | DATA_ALT DATASCR | From f27be37970a41127fde81a6c217cec543eec864e Mon Sep 17 00:00:00 2001 From: erikb Date: Fri, 12 Sep 1986 09:16:07 +0000 Subject: [PATCH 0258/1625] built in the compile time flag NOFLOAT to get rid of the float stuff --- lang/cem/cemcom/LLlex.c | 11 ++++++++- lang/cem/cemcom/LLlex.h | 4 +++ lang/cem/cemcom/LLmessage.c | 2 ++ lang/cem/cemcom/Parameters | 4 +++ lang/cem/cemcom/align.h | 5 +++- lang/cem/cemcom/arith.c | 12 +++++++++ lang/cem/cemcom/ch7.c | 7 ++++++ lang/cem/cemcom/ch7bin.c | 2 ++ lang/cem/cemcom/ch7mon.c | 4 +++ lang/cem/cemcom/code.c | 4 +++ lang/cem/cemcom/conversion.c | 10 ++++++++ lang/cem/cemcom/decspecs.c | 8 ++++-- lang/cem/cemcom/dumpidf.c | 4 +++ lang/cem/cemcom/eval.c | 48 ++++++++++++++++++++++-------------- lang/cem/cemcom/expr.c | 10 +++++--- lang/cem/cemcom/expr.str | 8 ++++++ lang/cem/cemcom/idf.c | 2 ++ lang/cem/cemcom/ival.c | 4 +++ lang/cem/cemcom/main.c | 10 ++++++++ lang/cem/cemcom/options.c | 4 +++ lang/cem/cemcom/sizes.h | 5 +++- lang/cem/cemcom/stack.c | 2 ++ lang/cem/cemcom/switch.c | 2 ++ lang/cem/cemcom/type.c | 2 ++ lang/cem/cemcom/type.str | 2 ++ 25 files changed, 150 insertions(+), 26 deletions(-) diff --git a/lang/cem/cemcom/LLlex.c b/lang/cem/cemcom/LLlex.c index a1182d91..b49dcaf6 100644 --- a/lang/cem/cemcom/LLlex.c +++ b/lang/cem/cemcom/LLlex.c @@ -337,6 +337,7 @@ go_on: /* rescan, the following character has been read */ register arith val = 0; if (ch == '.') { /* an embarrassing ambiguity */ +#ifndef NOFLOAT LoadChar(vch); PushBack(); if (!is_dig(vch)) /* just a `.' */ @@ -345,6 +346,9 @@ go_on: /* rescan, the following character has been read */ /* in the rest of the compiler, all floats have to start with a digit. */ +#else NOFLOAT + return ptok->tk_symb = ch; +#endif NOFLOAT } if (ch == '0') { *np++ = ch; @@ -367,7 +371,10 @@ go_on: /* rescan, the following character has been read */ ptok->tk_fund = LONG; return ptok->tk_symb = INTEGER; } - if (base == 16 || !(ch == '.' || ch == 'e' || ch == 'E')) { +#ifndef NOFLOAT + if (base == 16 || !(ch == '.' || ch == 'e' || ch == 'E')) +#endif NOFLOAT + { PushBack(); ptok->tk_ival = val; /* The semantic analyser must know if the @@ -383,6 +390,7 @@ go_on: /* rescan, the following character has been read */ return ptok->tk_symb = INTEGER; } /* where's the test for the length of the integral ??? */ +#ifndef NOFLOAT if (ch == '.'){ if (np < &buf[NUMSIZE]) *np++ = ch; @@ -423,6 +431,7 @@ go_on: /* rescan, the following character has been read */ else ptok->tk_fval = Salloc(buf, np - buf) + 1; return ptok->tk_symb = FLOATING; +#endif NOFLOAT } case STEOI: /* end of text on source file */ return ptok->tk_symb = EOI; diff --git a/lang/cem/cemcom/LLlex.h b/lang/cem/cemcom/LLlex.h index 392f6664..572160c5 100644 --- a/lang/cem/cemcom/LLlex.h +++ b/lang/cem/cemcom/LLlex.h @@ -21,7 +21,9 @@ struct token { int tok_fund; /* INT or LONG */ arith tok_ival; } tok_integer; +#ifndef NOFLOAT char *tok_fval; +#endif NOFLOAT } tok_data; }; @@ -33,7 +35,9 @@ struct token { #define tk_len tok_data.tok_string.tok_len #define tk_fund tok_data.tok_integer.tok_fund #define tk_ival tok_data.tok_integer.tok_ival +#ifndef NOFLOAT #define tk_fval tok_data.tok_fval +#endif NOFLOAT extern struct token dot, ahead, aside; extern unsigned int LineNumber; /* "LLlex.c" */ diff --git a/lang/cem/cemcom/LLmessage.c b/lang/cem/cemcom/LLmessage.c index 78ca57d0..887a15d9 100644 --- a/lang/cem/cemcom/LLmessage.c +++ b/lang/cem/cemcom/LLmessage.c @@ -44,8 +44,10 @@ insert_token(tk) dot.tk_fund = INT; dot.tk_ival = 1; break; +#ifndef NOFLOAT case FLOATING: dot.tk_fval = Salloc("0.0", 4); break; +#endif NOFLOAT } } diff --git a/lang/cem/cemcom/Parameters b/lang/cem/cemcom/Parameters index c3b9bef7..dab11db3 100644 --- a/lang/cem/cemcom/Parameters +++ b/lang/cem/cemcom/Parameters @@ -66,8 +66,10 @@ #define SZ_WORD (arith)4 #define SZ_INT (arith)4 #define SZ_LONG (arith)4 +#ifndef NOFLOAT #define SZ_FLOAT (arith)4 #define SZ_DOUBLE (arith)8 +#endif NOFLOAT #define SZ_POINTER (arith)4 /* target machine alignment requirements */ @@ -76,8 +78,10 @@ #define AL_WORD SZ_WORD #define AL_INT SZ_WORD #define AL_LONG SZ_WORD +#ifndef NOFLOAT #define AL_FLOAT SZ_WORD #define AL_DOUBLE SZ_WORD +#endif NOFLOAT #define AL_POINTER SZ_WORD #define AL_STRUCT 1 #define AL_UNION 1 diff --git a/lang/cem/cemcom/align.h b/lang/cem/cemcom/align.h index b0be9d44..ae162f1b 100644 --- a/lang/cem/cemcom/align.h +++ b/lang/cem/cemcom/align.h @@ -3,7 +3,10 @@ extern int short_align, word_align, int_align, long_align, - float_align, double_align, pointer_align, +#ifndef NOFLOAT + float_align, double_align, +#endif NOFLOAT + pointer_align, struct_align, union_align; extern arith align(); diff --git a/lang/cem/cemcom/arith.c b/lang/cem/cemcom/arith.c index 61bdb6ef..9379244a 100644 --- a/lang/cem/cemcom/arith.c +++ b/lang/cem/cemcom/arith.c @@ -36,6 +36,7 @@ arithbalance(e1p, oper, e2p) /* RM 6.6 */ t2 = any2arith(e2p, oper); /* Now t1 and t2 are either INT or LONG or DOUBLE */ +#ifndef NOFLOAT if (t1 == DOUBLE && t2 != DOUBLE) t2 = int2float(e2p, double_type); else @@ -44,6 +45,7 @@ arithbalance(e1p, oper, e2p) /* RM 6.6 */ else if (t1 == DOUBLE) return DOUBLE; +#endif NOFLOAT /* Now they are INT or LONG */ u1 = (*e1p)->ex_type->tp_unsigned; @@ -148,11 +150,13 @@ any2arith(expp, oper) expr_warning(*expp, "%s on enum", symbol2str(oper)); int2int(expp, int_type); break; +#ifndef NOFLOAT case FLOAT: float2float(expp, double_type); break; case DOUBLE: break; +#endif NOFLOAT #ifndef NOBITFIELD case FIELD: field2arith(expp); @@ -220,6 +224,7 @@ int2int(expp, tp) return (*expp)->ex_type->tp_fund; } +#ifndef NOFLOAT int int2float(expp, tp) struct expr **expp; @@ -262,6 +267,7 @@ float2float(expp, tp) else *expp = arith2arith(tp, FLOAT2FLOAT, *expp); } +#endif NOFLOAT array2pointer(expp) struct expr **expp; @@ -337,8 +343,10 @@ opnd2logical(expp, oper) case LONG: case ENUM: case POINTER: +#ifndef NOFLOAT case FLOAT: case DOUBLE: +#endif NOFLOAT break; default: expr_error(*expp, "%s operand to %s", @@ -429,7 +437,9 @@ any2opnd(expp, oper) case CHAR: case SHORT: case ENUM: +#ifndef NOFLOAT case FLOAT: +#endif NOFLOAT any2arith(expp, oper); break; case ARRAY: @@ -477,6 +487,7 @@ field2arith(expp) } #endif NOBITFIELD +#ifndef NOFLOAT /* switch_sign_fp() negates the given floating constant expression The lexical analyser has reserved an extra byte of space in front of the string containing the representation of the floating @@ -491,3 +502,4 @@ switch_sign_fp(expr) else --(expr->FL_VALUE); } +#endif NOFLOAT diff --git a/lang/cem/cemcom/ch7.c b/lang/cem/cemcom/ch7.c index 0cb13fb5..b95922fe 100644 --- a/lang/cem/cemcom/ch7.c +++ b/lang/cem/cemcom/ch7.c @@ -222,6 +222,7 @@ ch7cast(expp, oper, tp) symbol2str(oper)); int2int(expp, tp); } +#ifndef NOFLOAT else if (oldi && !i) { if (oldtp->tp_fund == ENUM && oper != CAST) @@ -235,6 +236,10 @@ ch7cast(expp, oper, tp) float2int(expp, tp); else /* !oldi && !i */ float2float(expp, tp); +#else NOFLOAT + else + crash("(ch7cast) floats not implemented\n"); +#endif NOFLOAT } else if (oldtp->tp_fund == POINTER && tp->tp_fund == POINTER) { @@ -404,8 +409,10 @@ is_arith_type(tp) case INT: case LONG: case ENUM: +#ifndef NOFLOAT case FLOAT: case DOUBLE: +#endif NOFLOAT return 1; #ifndef NOBITFIELD case FIELD: diff --git a/lang/cem/cemcom/ch7bin.c b/lang/cem/cemcom/ch7bin.c index c34e1c21..b8e1e182 100644 --- a/lang/cem/cemcom/ch7bin.c +++ b/lang/cem/cemcom/ch7bin.c @@ -314,11 +314,13 @@ pointer_arithmetic(expp1, oper, expp2) /* prepares the integral expression expp2 in order to apply it to the pointer expression expp1 */ +#ifndef NOFLOAT if (any2arith(expp2, oper) == DOUBLE) { expr_error(*expp2, "illegal combination of float and pointer"); erroneous2int(expp2); } +#endif NOFLOAT ch7bin( expp2, '*', intexpr(size_of_type((*expp1)->ex_type->tp_up, "object"), pa_type->tp_fund) diff --git a/lang/cem/cemcom/ch7mon.c b/lang/cem/cemcom/ch7mon.c index 2d633246..21ca76bd 100644 --- a/lang/cem/cemcom/ch7mon.c +++ b/lang/cem/cemcom/ch7mon.c @@ -88,6 +88,7 @@ ch7mon(oper, expp) } break; case '~': +#ifndef NOFLOAT { int fund = (*expp)->ex_type->tp_fund; @@ -102,6 +103,7 @@ ch7mon(oper, expp) } /* FALLTHROUGH */ } +#endif NOFLOAT case '-': any2arith(expp, oper); if (is_cp_cst(*expp)) { @@ -114,9 +116,11 @@ ch7mon(oper, expp) ); } else +#ifndef NOFLOAT if (is_fp_cst(*expp)) switch_sign_fp(*expp); else +#endif NOFLOAT *expp = new_oper((*expp)->ex_type, NILEXPR, oper, *expp); break; diff --git a/lang/cem/cemcom/code.c b/lang/cem/cemcom/code.c index c273ba35..dfd952b5 100644 --- a/lang/cem/cemcom/code.c +++ b/lang/cem/cemcom/code.c @@ -32,7 +32,9 @@ static struct stmt_block *stmt_stack; char *symbol2str(); +#ifndef NOFLOAT int fp_used; +#endif NOFLOAT label lab_count = 1; label datlab_count = 1; @@ -254,11 +256,13 @@ end_proc(fbytes, nbytes) else C_ret(ATW(func_tp->tp_size)); } +#ifndef NOFLOAT if (fp_used && mes_flt_given == 0) { /* floating point used */ C_ms_flt(); mes_flt_given++; } +#endif NOFLOAT C_ms_par(fbytes); /* # bytes for formals */ if (sp_occurred[SP_SETJMP]) { /* indicate use of "setjmp" */ C_ms_gto(); diff --git a/lang/cem/cemcom/conversion.c b/lang/cem/cemcom/conversion.c index 7d6d4729..e62cb264 100644 --- a/lang/cem/cemcom/conversion.c +++ b/lang/cem/cemcom/conversion.c @@ -9,7 +9,9 @@ #define T_SIGNED 1 #define T_UNSIGNED 2 +#ifndef NOFLOAT #define T_FLOATING 3 +#endif NOFLOAT /* conversion() generates the EM code for a conversion between the types char, short, int, long, float, double and pointer. @@ -51,11 +53,13 @@ conversion(from_type, to_type) C_ciu(); break; +#ifndef NOFLOAT case T_FLOATING: C_loc(from_size < word_size ? word_size : from_size); C_loc(to_size < word_size ? word_size : to_size); C_cif(); break; +#endif NOFLOAT } break; @@ -73,12 +77,15 @@ conversion(from_type, to_type) C_cuu(); break; +#ifndef NOFLOAT case T_FLOATING: C_cuf(); break; +#endif NOFLOAT } break; +#ifndef NOFLOAT case T_FLOATING: C_loc(from_size < word_size ? word_size : from_size); C_loc(to_size < word_size ? word_size : to_size); @@ -98,6 +105,7 @@ conversion(from_type, to_type) break; } break; +#endif NOFLOAT default: crash("(conversion) illegal type conversion"); } @@ -120,9 +128,11 @@ fundamental(tp) case ENUM: return tp->tp_unsigned ? T_UNSIGNED : T_SIGNED; +#ifndef NOFLOAT case FLOAT: case DOUBLE: return T_FLOATING; +#endif NOFLOAT case POINTER: /* pointer : signed / unsigned ??? */ return T_SIGNED; diff --git a/lang/cem/cemcom/decspecs.c b/lang/cem/cemcom/decspecs.c index 7cc5a211..564b8d0b 100644 --- a/lang/cem/cemcom/decspecs.c +++ b/lang/cem/cemcom/decspecs.c @@ -52,15 +52,19 @@ do_decspecs(ds) case SHORT: if (tp == int_type) tp = short_type; - else error("short with illegal type"); + else + error("short with illegal type"); break; case LONG: if (tp == int_type) tp = long_type; else +#ifndef NOFLOAT if (tp == float_type) tp = double_type; - else error("long with illegal type"); + else +#endif NOFLOAT + error("long with illegal type"); break; } if (ds->ds_unsigned) { diff --git a/lang/cem/cemcom/dumpidf.c b/lang/cem/cemcom/dumpidf.c index 361aa89a..a7bf5ac7 100644 --- a/lang/cem/cemcom/dumpidf.c +++ b/lang/cem/cemcom/dumpidf.c @@ -327,7 +327,9 @@ p1_expr(lvl, expr) expr->ex_depth, expr->ex_class == Value ? "Value" : expr->ex_class == String ? "String" : +#ifndef NOFLOAT expr->ex_class == Float ? "Float" : +#endif NOFLOAT expr->ex_class == Oper ? "Oper" : expr->ex_class == Type ? "Type" : "UNKNOWN CLASS" ); @@ -361,9 +363,11 @@ p1_expr(lvl, expr) ); break; } +#ifndef NOFLOAT case Float: print("%s\n", expr->FL_VALUE); break; +#endif NOFLOAT case Oper: o = &expr->ex_object.ex_oper; print("\n"); diff --git a/lang/cem/cemcom/eval.c b/lang/cem/cemcom/eval.c index ac14d2d2..5374ef46 100644 --- a/lang/cem/cemcom/eval.c +++ b/lang/cem/cemcom/eval.c @@ -91,6 +91,7 @@ EVAL(expr, val, code, true_label, false_label) C_lae_dlb(expr->VL_LBL, expr->VL_VALUE); } break; +#ifndef NOFLOAT case Float: /* a floating constant */ if (gencode) { label datlab = data_label(); @@ -101,6 +102,7 @@ EVAL(expr, val, code, true_label, false_label) C_loi(expr->ex_type->tp_size); } break; +#endif NOFLOAT case Oper: /* compound expression */ { register int oper = expr->OP_OPER; @@ -131,9 +133,11 @@ EVAL(expr, val, code, true_label, false_label) case POINTER: C_ads(rightop->ex_type->tp_size); break; +#ifndef NOFLOAT case DOUBLE: C_adf(tp->tp_size); break; +#endif NOFLOAT default: crash("bad type +"); } @@ -144,14 +148,16 @@ EVAL(expr, val, code, true_label, false_label) EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); if (gencode) { switch (tp->tp_fund) { - case DOUBLE: - C_ngf(tp->tp_size); - break; case INT: case LONG: case POINTER: C_ngi(tp->tp_size); break; +#ifndef NOFLOAT + case DOUBLE: + C_ngf(tp->tp_size); + break; +#endif NOFLOAT default: CRASH(); } @@ -183,9 +189,11 @@ EVAL(expr, val, code, true_label, false_label) C_ads(rightop->ex_type->tp_size); } break; +#ifndef NOFLOAT case DOUBLE: C_sbf(tp->tp_size); break; +#endif NOFLOAT default: crash("bad type -"); } @@ -206,9 +214,11 @@ EVAL(expr, val, code, true_label, false_label) else C_mli(tp->tp_size); break; +#ifndef NOFLOAT case DOUBLE: C_mlf(double_size); break; +#endif NOFLOAT default: crash("bad type *"); } @@ -227,9 +237,11 @@ EVAL(expr, val, code, true_label, false_label) else C_dvi(tp->tp_size); break; +#ifndef NOFLOAT case DOUBLE: C_dvf(double_size); break; +#endif NOFLOAT default: crash("bad type /"); } @@ -237,17 +249,13 @@ EVAL(expr, val, code, true_label, false_label) case '%': EVAL(leftop, RVAL, code, NO_LABEL, NO_LABEL); EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); - if (gencode) - if ( tp->tp_fund == INT - || tp->tp_fund == LONG - ) { - if (tp->tp_unsigned) - C_rmu(tp->tp_size); - else - C_rmi(tp->tp_size); - } + ASSERT(tp->tp_fund==INT || tp->tp_fund==LONG); + if (gencode) { + if (tp->tp_unsigned) + C_rmu(tp->tp_size); else - crash("bad type %%"); + C_rmi(tp->tp_size); + } break; case LEFT: EVAL(leftop, RVAL, code, NO_LABEL, NO_LABEL); @@ -287,10 +295,12 @@ EVAL(expr, val, code, true_label, false_label) else C_cmi(size); break; - case FLOAT: +#ifndef NOFLOAT + case FLOAT: /* thought they were converted??? */ case DOUBLE: C_cmf(size); break; +#endif NOFLOAT case POINTER: C_cmp(); break; @@ -553,12 +563,10 @@ EVAL(expr, val, code, true_label, false_label) EVAL(leftop, RVAL, TRUE, l_true, l_false); C_df_ilb(l_true); - EVAL(rightop->OP_LEFT, RVAL, code, - NO_LABEL, NO_LABEL); + EVAL(rightop->OP_LEFT, RVAL, code, NO_LABEL, NO_LABEL); C_bra(l_end); C_df_ilb(l_false); - EVAL(rightop->OP_RIGHT, RVAL, code, - NO_LABEL, NO_LABEL); + EVAL(rightop->OP_RIGHT, RVAL, code, NO_LABEL, NO_LABEL); C_df_ilb(l_end); break; } @@ -655,9 +663,11 @@ EVAL(expr, val, code, true_label, false_label) true_label); break; case INT2INT: +#ifndef NOFLOAT case INT2FLOAT: case FLOAT2INT: case FLOAT2FLOAT: +#endif NOFLOAT EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); if (gencode) conversion(rightop->ex_type, leftop->ex_type); @@ -784,6 +794,7 @@ assop(type, oper) break; } break; +#ifndef NOFLOAT case FLOAT: case DOUBLE: switch (oper) { @@ -805,6 +816,7 @@ assop(type, oper) break; } break; +#endif NOFLOAT case POINTER: if (oper == MINAB || oper == MINMIN || oper == POSTDECR) C_ngi(size); diff --git a/lang/cem/cemcom/expr.c b/lang/cem/cemcom/expr.c index 4fa8cf7e..6426ec5b 100644 --- a/lang/cem/cemcom/expr.c +++ b/lang/cem/cemcom/expr.c @@ -134,9 +134,11 @@ dot2expr(expp) case INTEGER: int2expr(*expp); break; +#ifndef NOFLOAT case FLOATING: float2expr(*expp); break; +#endif NOFLOAT default: crash("bad conversion to expression"); break; @@ -224,6 +226,7 @@ int2expr(expr) fill_int_expr(expr, dot.tk_ival, dot.tk_fund); } +#ifndef NOFLOAT float2expr(expr) struct expr *expr; { @@ -235,6 +238,7 @@ float2expr(expr) expr->FL_VALUE = dot.tk_fval; expr->FL_DATLAB = 0; } +#endif NOFLOAT struct expr* intexpr(ivalue, fund) @@ -408,10 +412,8 @@ chk_cst_expr(expp) expr_warning(expr, "expression comma in constant expression"); } - - if (err) { + if (err) erroneous2int(expp); - } } init_expression(eppp, expr) @@ -453,6 +455,7 @@ is_cp_cst(expr) return is_ld_cst(expr) && expr->VL_CLASS == Const; } +#ifndef NOFLOAT int is_fp_cst(expr) register struct expr *expr; @@ -462,6 +465,7 @@ is_fp_cst(expr) */ return expr->ex_class == Float; } +#endif NOFLOAT free_expression(expr) struct expr *expr; diff --git a/lang/cem/cemcom/expr.str b/lang/cem/cemcom/expr.str index 1d627586..cf74c7e9 100644 --- a/lang/cem/cemcom/expr.str +++ b/lang/cem/cemcom/expr.str @@ -25,10 +25,12 @@ struct string { label sg_datlab; /* global data-label */ }; +#ifndef NOFLOAT struct floating { char *fl_value; /* pointer to string repr. the fp const. */ label fl_datlab; /* global data_label */ }; +#endif NOFLOAT struct oper { struct type *op_type; /* resulting type of the operation */ @@ -40,7 +42,9 @@ struct oper { /* The following constants indicate the class of the expression: */ #define Value 0 /* it is a value known at load time */ #define String 1 /* it is a string constant */ +#ifndef NOFLOAT #define Float 2 /* it is a floating point constant */ +#endif NOFLOAT #define Oper 3 /* it is a run-time expression */ #define Type 4 /* only its type is relevant */ @@ -56,7 +60,9 @@ struct expr { union { struct value ex_value; struct string ex_string; +#ifndef NOFLOAT struct floating ex_float; +#endif NOFLOAT struct oper ex_oper; } ex_object; }; @@ -69,8 +75,10 @@ struct expr { #define SG_VALUE ex_object.ex_string.sg_value #define SG_LEN ex_object.ex_string.sg_len #define SG_DATLAB ex_object.ex_string.sg_datlab +#ifndef NOFLOAT #define FL_VALUE ex_object.ex_float.fl_value #define FL_DATLAB ex_object.ex_float.fl_datlab +#endif NOFLOAT #define OP_TYPE ex_object.ex_oper.op_type #define OP_LEFT ex_object.ex_oper.op_left #define OP_OPER ex_object.ex_oper.op_oper diff --git a/lang/cem/cemcom/idf.c b/lang/cem/cemcom/idf.c index aa6c48f1..2cda12a9 100644 --- a/lang/cem/cemcom/idf.c +++ b/lang/cem/cemcom/idf.c @@ -210,9 +210,11 @@ declare_idf(ds, dc, lvl) type = construct_type(POINTER, type->tp_up, (arith)0); formal_array = 1; break; +#ifndef NOFLOAT case FLOAT: /* RM 10.1 */ type = double_type; break; +#endif NOFLOAT case CHAR: case SHORT: /* The RM is not clear about this: we must diff --git a/lang/cem/cemcom/ival.c b/lang/cem/cemcom/ival.c index 95e8d3fa..61ce90f2 100644 --- a/lang/cem/cemcom/ival.c +++ b/lang/cem/cemcom/ival.c @@ -383,10 +383,12 @@ pad(tp) case POINTER: C_con_ucon("0", tp->tp_size); break; +#ifndef NOFLOAT case FLOAT: case DOUBLE: C_con_fcon("0", tp->tp_size); break; +#endif NOFLOAT case UNION: error("initialisation of unions not allowed"); break; @@ -448,6 +450,7 @@ check_ival(ex, tp) C_con_dlb(ex->VL_LBL, ex->VL_VALUE); } break; +#ifndef NOFLOAT case FLOAT: case DOUBLE: ch7cast(&ex, '=', tp); @@ -471,6 +474,7 @@ check_ival(ex, tp) else illegal_init_cst(ex); break; +#endif NOFLOAT #ifndef NOBITFIELD case FIELD: diff --git a/lang/cem/cemcom/main.c b/lang/cem/cemcom/main.c index 614eb5cc..e6240077 100644 --- a/lang/cem/cemcom/main.c +++ b/lang/cem/cemcom/main.c @@ -48,8 +48,10 @@ arith dword_size = (2 * SZ_WORD), int_size = SZ_INT, long_size = SZ_LONG, +#ifndef NOFLOAT float_size = SZ_FLOAT, double_size = SZ_DOUBLE, +#endif NOFLOAT pointer_size = SZ_POINTER; int @@ -57,8 +59,10 @@ int word_align = AL_WORD, int_align = AL_INT, long_align = AL_LONG, +#ifndef NOFLOAT float_align = AL_FLOAT, double_align = AL_DOUBLE, +#endif NOFLOAT pointer_align = AL_POINTER, struct_align = AL_STRUCT, union_align = AL_UNION; @@ -237,8 +241,10 @@ init() long_type = standard_type(LONG, 0, long_align, long_size); ulong_type = standard_type(LONG, UNSIGNED, long_align, long_size); +#ifndef NOFLOAT float_type = standard_type(FLOAT, 0, float_align, float_size); double_type = standard_type(DOUBLE, 0, double_align, double_size); +#endif NOFLOAT void_type = standard_type(VOID, 0, 0, (arith)0); label_type = standard_type(LABEL, 0, 0, (arith)0); error_type = standard_type(ERRONEOUS, 0, 1, (arith)1); @@ -274,8 +280,10 @@ init() /* Define the standard type identifiers. */ add_def(str2idf("char"), TYPEDEF, char_type, L_UNIVERSAL); add_def(str2idf("int"), TYPEDEF, int_type, L_UNIVERSAL); +#ifndef NOFLOAT add_def(str2idf("float"), TYPEDEF, float_type, L_UNIVERSAL); add_def(str2idf("double"), TYPEDEF, double_type, L_UNIVERSAL); +#endif NOFLOAT add_def(str2idf("void"), TYPEDEF, void_type, L_UNIVERSAL); stack_level(); } @@ -350,9 +358,11 @@ preprocess() case INTEGER: print("%ld ", dot.tk_ival); break; +#ifndef NOFLOAT case FLOATING: print("%s ", dot.tk_fval); break; +#endif NOFLOAT case EOI: case EOF: return; diff --git a/lang/cem/cemcom/options.c b/lang/cem/cemcom/options.c index 7569fc49..90a94f16 100644 --- a/lang/cem/cemcom/options.c +++ b/lang/cem/cemcom/options.c @@ -200,16 +200,20 @@ do_option(text) long_align = align; break; case 'f': /* float */ +#ifndef NOFLOAT if (size != (arith)0) float_size = size; if (align != 0) float_align = align; +#endif NOFLOAT break; case 'd': /* double */ +#ifndef NOFLOAT if (size != (arith)0) double_size = size; if (align != 0) double_align = align; +#endif NOFLOAT break; case 'p': /* pointer */ if (size != (arith)0) diff --git a/lang/cem/cemcom/sizes.h b/lang/cem/cemcom/sizes.h index d0ae01e2..a4af4f2e 100644 --- a/lang/cem/cemcom/sizes.h +++ b/lang/cem/cemcom/sizes.h @@ -3,6 +3,9 @@ extern arith short_size, word_size, dword_size, int_size, long_size, - float_size, double_size, pointer_size; +#ifndef NOFLOAT + float_size, double_size, +#endif NOFLOAT + pointer_size; extern arith max_int, max_unsigned; /* cstoper.c */ diff --git a/lang/cem/cemcom/stack.c b/lang/cem/cemcom/stack.c index 5e27af24..adb71aa6 100644 --- a/lang/cem/cemcom/stack.c +++ b/lang/cem/cemcom/stack.c @@ -128,10 +128,12 @@ unstack_level() case POINTER: reg = reg_pointer; break; +#ifndef NOFLOAT case FLOAT: case DOUBLE: reg = reg_float; break; +#endif NOFLOAT default: reg = reg_any; break; diff --git a/lang/cem/cemcom/switch.c b/lang/cem/cemcom/switch.c index 4a73673c..35d131ba 100644 --- a/lang/cem/cemcom/switch.c +++ b/lang/cem/cemcom/switch.c @@ -49,10 +49,12 @@ code_startswitch(expp) warning("long in switch (cast to int)"); int2int(expp, int_type); break; +#ifndef NOFLOAT case DOUBLE: error("float/double in switch"); erroneous2int(expp); break; +#endif NOFLOAT } stack_stmt(l_break, NO_LABEL); diff --git a/lang/cem/cemcom/type.c b/lang/cem/cemcom/type.c index c68c6687..52021832 100644 --- a/lang/cem/cemcom/type.c +++ b/lang/cem/cemcom/type.c @@ -26,7 +26,9 @@ struct type *word_type, *uword_type, *int_type, *uint_type, *long_type, *ulong_type, +#ifndef NOFLOAT *float_type, *double_type, +#endif NOFLOAT *void_type, *label_type, *string_type, *funint_type, *error_type; diff --git a/lang/cem/cemcom/type.str b/lang/cem/cemcom/type.str index 9524ef16..837ebc85 100644 --- a/lang/cem/cemcom/type.str +++ b/lang/cem/cemcom/type.str @@ -33,7 +33,9 @@ extern struct type *word_type, *uword_type, *int_type, *uint_type, *long_type, *ulong_type, +#ifndef NOFLOAT *float_type, *double_type, +#endif NOFLOAT *void_type, *label_type, *string_type, *funint_type, *error_type; From d89580fd2214a9dff32a684381ed16f722ce125e Mon Sep 17 00:00:00 2001 From: erikb Date: Fri, 12 Sep 1986 12:58:22 +0000 Subject: [PATCH 0259/1625] added one byte to ibuf --- lang/cem/cemcom/input.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/cem/cemcom/input.c b/lang/cem/cemcom/input.c index adae8d9f..daa4e96f 100644 --- a/lang/cem/cemcom/input.c +++ b/lang/cem/cemcom/input.c @@ -71,7 +71,7 @@ PRIVATE struct buffer_header *head = 0; /* current input buffer */ IMPORT char **WorkingDir; /* name of current working directory */ #else NOPP long isize; -char ibuf[BUFSIZ]; +char ibuf[BUFSIZ + 1]; #endif NOPP #ifdef READ_IN_ONE From 7dfa6a955af0cbcbac33f4fc6f1f8a2ac6d6690c Mon Sep 17 00:00:00 2001 From: erikb Date: Mon, 15 Sep 1986 08:47:53 +0000 Subject: [PATCH 0260/1625] changed some large static data structures into STATIC --- lang/cem/cemcom/Makefile.erik | 8 ++++---- lang/cem/cemcom/Parameters | 3 +++ lang/cem/cemcom/dumpidf.c | 6 ++++-- lang/cem/cemcom/input.c | 16 +++++++++------- lang/cem/cemcom/replace.c | 5 +++-- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/lang/cem/cemcom/Makefile.erik b/lang/cem/cemcom/Makefile.erik index 73d412c7..7f8ea21f 100644 --- a/lang/cem/cemcom/Makefile.erik +++ b/lang/cem/cemcom/Makefile.erik @@ -77,7 +77,7 @@ GHSRC = botch_free.h dataflow.h debug.h density.h errout.h \ idepth.h idfsize.h ifdepth.h inputtype.h inumlength.h lapbuf.h \ maxincl.h myalloc.h nobitfield.h nopp.h \ nparams.h numsize.h parbufsize.h pathlength.h predefine.h \ - strsize.h target_sizes.h textsize.h use_tmp.h spec_arith.h + strsize.h target_sizes.h textsize.h use_tmp.h spec_arith.h static.h # Other generated files, for 'make clean' only GENERATED = tab tokenfile.g Lpars.h LLfiles LL.output lint.out \ @@ -217,15 +217,15 @@ cstoper.o: Lpars.h arith.h assert.h debug.h expr.h idf.h label.h nobitfield.h no arith.o: Lpars.h alloc.h arith.h botch_free.h expr.h field.h idf.h label.h mes.h nobitfield.h nopp.h spec_arith.h storage.h type.h alloc.o: alloc.h assert.h debug.h myalloc.h code.o: LLlex.h Lpars.h alloc.h arith.h assert.h atw.h botch_free.h code.h dataflow.h debug.h declar.h decspecs.h def.h expr.h idf.h label.h level.h mes.h nobitfield.h nopp.h sizes.h spec_arith.h specials.h stack.h stmt.h storage.h type.h use_tmp.h -dumpidf.o: Lpars.h arith.h debug.h def.h expr.h field.h idf.h label.h nobitfield.h nopp.h spec_arith.h stack.h struct.h type.h +dumpidf.o: Lpars.h arith.h debug.h def.h expr.h field.h idf.h label.h nobitfield.h nopp.h spec_arith.h stack.h static.h struct.h type.h error.o: LLlex.h arith.h debug.h errout.h expr.h label.h nopp.h spec_arith.h tokenname.h use_tmp.h field.o: Lpars.h arith.h assert.h code.h debug.h expr.h field.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h type.h tokenname.o: LLlex.h Lpars.h arith.h idf.h nopp.h spec_arith.h tokenname.h LLlex.o: LLlex.h Lpars.h alloc.h arith.h assert.h class.h debug.h def.h idf.h idfsize.h input.h nopp.h numsize.h sizes.h spec_arith.h strsize.h LLmessage.o: LLlex.h Lpars.h alloc.h arith.h idf.h nopp.h spec_arith.h -input.o: LLlex.h alloc.h arith.h assert.h debug.h idepth.h input.h inputtype.h interface.h nopp.h pathlength.h spec_arith.h +input.o: LLlex.h alloc.h arith.h assert.h debug.h idepth.h input.h inputtype.h interface.h nopp.h pathlength.h spec_arith.h static.h domacro.o: LLlex.h Lpars.h alloc.h arith.h assert.h botch_free.h class.h debug.h idf.h idfsize.h ifdepth.h input.h interface.h macro.h nopp.h nparams.h parbufsize.h spec_arith.h storage.h textsize.h -replace.o: LLlex.h alloc.h arith.h assert.h class.h debug.h idf.h input.h interface.h macro.h nopp.h pathlength.h spec_arith.h strsize.h +replace.o: LLlex.h alloc.h arith.h assert.h class.h debug.h idf.h input.h interface.h macro.h nopp.h pathlength.h spec_arith.h static.h strsize.h init.o: alloc.h class.h idf.h interface.h macro.h nopp.h predefine.h options.o: align.h arith.h class.h idf.h idfsize.h macro.h maxincl.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h use_tmp.h scan.o: class.h idf.h input.h interface.h lapbuf.h macro.h nopp.h nparams.h diff --git a/lang/cem/cemcom/Parameters b/lang/cem/cemcom/Parameters index dab11db3..5fff54b3 100644 --- a/lang/cem/cemcom/Parameters +++ b/lang/cem/cemcom/Parameters @@ -130,3 +130,6 @@ /* describes internal compiler arithmetics */ #undef SPECIAL_ARITHMETICS /* something different from native long */ + +!File: static.h +#define STATIC /* decl. spec. for large "static" arrays */ diff --git a/lang/cem/cemcom/dumpidf.c b/lang/cem/cemcom/dumpidf.c index a7bf5ac7..e6a67c14 100644 --- a/lang/cem/cemcom/dumpidf.c +++ b/lang/cem/cemcom/dumpidf.c @@ -16,6 +16,7 @@ #include "Lpars.h" #include "label.h" #include "expr.h" +#include "static.h" /* Some routines (symbol2str, token2str, type2str) which should have * yielded strings are written to yield a pointer to a transient piece @@ -284,15 +285,16 @@ type2str(tp) return buf; } +STATIC char trans_buf[MAXTRANS][300]; + char * /* the ultimate transient buffer supplier */ next_transient() { static int bnum; - static char buf[MAXTRANS][300]; if (++bnum == MAXTRANS) bnum = 0; - return buf[bnum]; + return trans_buf[bnum]; } print_expr(msg, expr) diff --git a/lang/cem/cemcom/input.c b/lang/cem/cemcom/input.c index daa4e96f..0fa38e2d 100644 --- a/lang/cem/cemcom/input.c +++ b/lang/cem/cemcom/input.c @@ -32,7 +32,7 @@ #include #include "nopp.h" -#include "inputtype.h" /* UF */ +#include "inputtype.h" #include "interface.h" #include "arith.h" #include "LLlex.h" @@ -40,10 +40,11 @@ #include "alloc.h" #ifndef NOPP -#include "idepth.h" /* UF */ -#include "debug.h" /* UF */ -#include "pathlength.h" /* UF */ +#include "idepth.h" +#include "debug.h" +#include "pathlength.h" #include "assert.h" +#include "static.h" #endif NOPP EXPORT char *ipp = 0; /* input pointer */ @@ -445,18 +446,19 @@ setwdir(wdir, fn) #ifndef NOPP /* mk_filename() concatenates a dir and filename. */ +STATIC char path[PATHLENGTH]; + PRIVATE char * mk_filename(dir, file) register char *dir, *file; { - static char newfn[PATHLENGTH]; - register char *dst = &newfn[0]; + register char *dst = &path[0]; if (!(dir[0] == '.' && dir[1] == '\0')) { while (*dst++ = *dir++); *(dst - 1) = '/'; } while (*dst++ = *file++); - return &newfn[0]; + return &path[0]; } #endif NOPP diff --git a/lang/cem/cemcom/replace.c b/lang/cem/cemcom/replace.c index 8738fa0e..b19d41ba 100644 --- a/lang/cem/cemcom/replace.c +++ b/lang/cem/cemcom/replace.c @@ -17,6 +17,7 @@ #include "class.h" #include "assert.h" #include "interface.h" +#include "static.h" char *strcpy(), *strcat(); char *long2str(); @@ -62,6 +63,8 @@ replace(idef) return 1; } +STATIC char FilNamBuf[PATHLENGTH]; + PRIVATE macro_func(idef) struct idf *idef; @@ -71,8 +74,6 @@ macro_func(idef) replacement texts must be evaluated at the time they are used. */ - static char FilNamBuf[PATHLENGTH]; - /* This switch is very blunt... */ switch (idef->id_text[2]) { case 'F' : /* __FILE__ */ From 1384666eb985b692b6040c4330457566b60a5336 Mon Sep 17 00:00:00 2001 From: erikb Date: Wed, 17 Sep 1986 12:31:45 +0000 Subject: [PATCH 0261/1625] some minor fixes --- lang/cem/cemcom/Parameters | 2 +- lang/cem/cemcom/dumpidf.c | 2 +- lang/cem/cemcom/input.c | 2 +- lang/cem/cemcom/main.c | 2 +- lang/cem/cemcom/replace.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lang/cem/cemcom/Parameters b/lang/cem/cemcom/Parameters index 5fff54b3..17babb55 100644 --- a/lang/cem/cemcom/Parameters +++ b/lang/cem/cemcom/Parameters @@ -132,4 +132,4 @@ !File: static.h -#define STATIC /* decl. spec. for large "static" arrays */ +#define GSTATIC /* for large global "static" arrays */ diff --git a/lang/cem/cemcom/dumpidf.c b/lang/cem/cemcom/dumpidf.c index e6a67c14..c027c646 100644 --- a/lang/cem/cemcom/dumpidf.c +++ b/lang/cem/cemcom/dumpidf.c @@ -285,7 +285,7 @@ type2str(tp) return buf; } -STATIC char trans_buf[MAXTRANS][300]; +GSTATIC char trans_buf[MAXTRANS][300]; char * /* the ultimate transient buffer supplier */ next_transient() diff --git a/lang/cem/cemcom/input.c b/lang/cem/cemcom/input.c index 0fa38e2d..fd6de239 100644 --- a/lang/cem/cemcom/input.c +++ b/lang/cem/cemcom/input.c @@ -446,7 +446,7 @@ setwdir(wdir, fn) #ifndef NOPP /* mk_filename() concatenates a dir and filename. */ -STATIC char path[PATHLENGTH]; +GSTATIC char path[PATHLENGTH]; PRIVATE char * mk_filename(dir, file) diff --git a/lang/cem/cemcom/main.c b/lang/cem/cemcom/main.c index e6240077..f3a3cd6c 100644 --- a/lang/cem/cemcom/main.c +++ b/lang/cem/cemcom/main.c @@ -143,7 +143,6 @@ compile(argc, argv) int pp_only = options['E'] || options['P']; #endif NOPP - source = strcmp(argv[0], "-") ? argv[0] : 0; switch (argc) { case 1: #ifndef NOPP @@ -162,6 +161,7 @@ compile(argc, argv) fatal("use: %s source destination [namelist]", prog_name); break; } + source = strcmp(argv[0], "-") ? argv[0] : 0; #ifdef USE_TMP strcpy(tmpf, tmpfdir); diff --git a/lang/cem/cemcom/replace.c b/lang/cem/cemcom/replace.c index b19d41ba..675d37d2 100644 --- a/lang/cem/cemcom/replace.c +++ b/lang/cem/cemcom/replace.c @@ -63,7 +63,7 @@ replace(idef) return 1; } -STATIC char FilNamBuf[PATHLENGTH]; +GSTATIC char FilNamBuf[PATHLENGTH]; PRIVATE macro_func(idef) From 2e7633971a66f30e607401188181ece126e8ebba Mon Sep 17 00:00:00 2001 From: erikb Date: Mon, 22 Sep 1986 13:04:04 +0000 Subject: [PATCH 0262/1625] if NOPP: made #line directives treated correctly --- lang/cem/cemcom/domacro.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/cem/cemcom/domacro.c b/lang/cem/cemcom/domacro.c index ff742d83..f215b5bb 100644 --- a/lang/cem/cemcom/domacro.c +++ b/lang/cem/cemcom/domacro.c @@ -650,7 +650,7 @@ domacro() SkipRestOfLine(); return; } - LineNumber = tk.tk_ival; + LineNumber = tk.tk_ival - 1; /* number of the next line */ if ((tok = GetToken(&tk)) == STRING) FileName = tk.tk_bts; else From 9bc53f63a9e8b63ec877208dc393531489673d27 Mon Sep 17 00:00:00 2001 From: sater Date: Mon, 22 Sep 1986 13:14:54 +0000 Subject: [PATCH 0263/1625] made debiug output better --- mach/proto/ncg/nextem.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mach/proto/ncg/nextem.c b/mach/proto/ncg/nextem.c index 4b74b440..a9616efd 100644 --- a/mach/proto/ncg/nextem.c +++ b/mach/proto/ncg/nextem.c @@ -69,8 +69,11 @@ byte *trypat(bp,len) register byte *bp; { #ifndef NDEBUG if (Debug) { fprintf(stderr,"Matched:"); - for (i=0;i Date: Mon, 22 Sep 1986 13:15:15 +0000 Subject: [PATCH 0264/1625] changed ad2str function not to add +0 at labels --- mach/proto/ncg/gencode.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mach/proto/ncg/gencode.c b/mach/proto/ncg/gencode.c index d2ee010a..1f84faf2 100644 --- a/mach/proto/ncg/gencode.c +++ b/mach/proto/ncg/gencode.c @@ -84,6 +84,8 @@ string ad2str(ad) addr_t ad; { if (ad.ea_str==0) ad.ea_str=""; + if (ad.ea_off==0) + return(mystrcpy(ad.ea_str)); sprintf(buf,"%s%c%ld",ad.ea_str,ad.ea_off>=0 ? '+' : ' ',(long)ad.ea_off); return(mystrcpy(buf)); } From a05325ba7f7f5849ad2b190bda16ac9c9589c33a Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 23 Sep 1986 09:41:47 +0000 Subject: [PATCH 0265/1625] Addition of new patterns. --- util/opt/patterns | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/util/opt/patterns b/util/opt/patterns index 1b58cf03..0abe5f84 100644 --- a/util/opt/patterns +++ b/util/opt/patterns @@ -1,5 +1,10 @@ "$Header$" loc adi loc sbi $2==w && $4==w: loc $1-$3 adi w +inc dec: +inc loc adi $3==w: loc $1+1 adi w +inc loc sbi $3==w: loc $1-1 sbi w +dec loc adi $3==w: loc $1-1 adi w +dec loc sbi $3==w: loc $1+1 sbi w ldc adi ldc sbi $2==2*w && $4==2*w: ldc $1-$3 adi 2*w loc adi loc adi $2==w && $4==w: loc $1+$3 adi w ldc adi ldc adi $2==2*w && $4==2*w: ldc $1+$3 adi 2*w @@ -24,6 +29,8 @@ cmi zgt $1==w: bgt $2 cmi zle $1==w: ble $2 cmi zlt $1==w: blt $2 cmi zne $1==w: bne $2 +cmu zeq $1==w: beq $2 +cmu zne $1==w: bne $2 dvi ngi $1==$2: ngi $1 dvi $1 lae adp : lae $1+$2 lae blm $2==w: loi w ste $1 @@ -168,7 +175,13 @@ loc mlu $1==1 && $2==w: ldc mlu $1==1 && $2==2*w: loc sbi $1==1 && $2==w: dec loc loe mli $3==w: loe $2 loc $1 mli w +loc loe adi loc $3==w: loe $2 loc $1 adi w loc $4 +loc loe adi inc $3==w: loe $2 loc $1 adi w inc +loc loe adi dec $3==w: loe $2 loc $1 adi w dec loc lol mli $3==w: lol $2 loc $1 mli w +loc lol adi loc $3==w: lol $2 loc $1 adi w loc $4 +loc lol adi inc $3==w: lol $2 loc $1 adi w dec +loc lol adi dec $3==w: lol $2 loc $1 adi w dec ldc lde mli $3==2*w: lde $2 ldc $1 mli 2*w ldc lde adi $3==2*w: lde $2 ldc $1 adi 2*w ldc ldl mli $3==2*w: ldl $2 ldc $1 mli 2*w @@ -368,6 +381,10 @@ zer loc defined($1) && $2==0: zer $1+w #endif loi loc and $1==1 && $3==w && ($2&255)==255: loi 1 loi loc loc cii $1=0 && $5<128 && $6==w: loi 1 loc $5 cmi w zeq $7 +loi loc loc cii loc cmi zne $1==1 && $2==1 && $3==w && $5>=0 && $5<128 && $6==w: loi 1 loc $5 cmi w zne $7 +loi loc loc cii loc loc ciu loc and $1==1 && $2==1 && $3==w && $5==w && $6==w && $8==255 && $9==w: loi 1 cmp teq : cms p teq cmp tne : cms p tne cmu teq defined($1): cms $1 teq From ccb47897ea80c1dff3f553ea74c9f2aafb19f229 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 24 Sep 1986 11:24:37 +0000 Subject: [PATCH 0266/1625] Initial revision --- mach/m68k4/libsys/compmodule | 4 ++++ 1 file changed, 4 insertions(+) create mode 100755 mach/m68k4/libsys/compmodule diff --git a/mach/m68k4/libsys/compmodule b/mach/m68k4/libsys/compmodule new file mode 100755 index 00000000..80f42aab --- /dev/null +++ b/mach/m68k4/libsys/compmodule @@ -0,0 +1,4 @@ +if m68k4 -c $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 +fi From 6df30b45d7f5866285c40daa372d9f281d5aa0fe Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 24 Sep 1986 12:17:25 +0000 Subject: [PATCH 0267/1625] Added a pattern for "ldc ads". --- util/opt/patterns | 1 + 1 file changed, 1 insertion(+) diff --git a/util/opt/patterns b/util/opt/patterns index 0abe5f84..03db7f93 100644 --- a/util/opt/patterns +++ b/util/opt/patterns @@ -229,6 +229,7 @@ loc zrf !defined($2): zrf $1 loc los $2==w: loi $1 loc sts $2==w: sti $1 loc ads $2==w: adp $1 +ldc ads $2==2*w && sfit($1,8*w): adp $1 loc ass $2==w: asp $1 loc bls $2==w: blm $1 loc dus $2==w: dup $1 From b1eed62b5c649bd09374fca17d39775f043eaf29 Mon Sep 17 00:00:00 2001 From: erikb Date: Wed, 24 Sep 1986 13:53:16 +0000 Subject: [PATCH 0268/1625] put heavily used pointer variables in registers --- lang/cem/cemcom/LLlex.c | 2 +- lang/cem/cemcom/LLlex.h | 2 + lang/cem/cemcom/LLmessage.c | 1 + lang/cem/cemcom/Makefile.erik | 84 +++++++++++++------------- lang/cem/cemcom/Parameters | 5 ++ lang/cem/cemcom/align.h | 2 + lang/cem/cemcom/arith.c | 30 +++++----- lang/cem/cemcom/ch7.c | 1 + lang/cem/cemcom/ch7bin.c | 3 +- lang/cem/cemcom/ch7mon.c | 1 + lang/cem/cemcom/code.c | 35 ++++++----- lang/cem/cemcom/conversion.c | 25 +------- lang/cem/cemcom/cstoper.c | 17 +++--- lang/cem/cemcom/declarator.c | 6 +- lang/cem/cemcom/decspecs.c | 5 +- lang/cem/cemcom/dumpidf.c | 26 ++++---- lang/cem/cemcom/eval.c | 108 +++++++++++++++++++--------------- lang/cem/cemcom/expr.c | 33 ++++++----- lang/cem/cemcom/expr.str | 2 + lang/cem/cemcom/idf.c | 37 +++++------- lang/cem/cemcom/ival.c | 32 +++++----- lang/cem/cemcom/main.c | 5 +- lang/cem/cemcom/options.c | 7 +-- lang/cem/cemcom/sizes.h | 2 + lang/cem/cemcom/stack.c | 7 +-- lang/cem/cemcom/struct.c | 48 +++++++-------- lang/cem/cemcom/switch.c | 3 +- lang/cem/cemcom/type.c | 23 ++++---- lang/cem/cemcom/type.str | 3 +- 29 files changed, 275 insertions(+), 280 deletions(-) diff --git a/lang/cem/cemcom/LLlex.c b/lang/cem/cemcom/LLlex.c index b49dcaf6..10780846 100644 --- a/lang/cem/cemcom/LLlex.c +++ b/lang/cem/cemcom/LLlex.c @@ -1,12 +1,12 @@ /* $Header$ */ /* L E X I C A L A N A L Y Z E R */ +#include "nofloat.h" #include "idfsize.h" #include "numsize.h" #include "debug.h" #include "strsize.h" #include "nopp.h" - #include "input.h" #include "alloc.h" #include "arith.h" diff --git a/lang/cem/cemcom/LLlex.h b/lang/cem/cemcom/LLlex.h index 572160c5..569a2e90 100644 --- a/lang/cem/cemcom/LLlex.h +++ b/lang/cem/cemcom/LLlex.h @@ -6,6 +6,8 @@ to it. */ +#include "nofloat.h" + /* the structure of a token: */ struct token { int tok_symb; /* the token itself */ diff --git a/lang/cem/cemcom/LLmessage.c b/lang/cem/cemcom/LLmessage.c index 887a15d9..2d4ac43b 100644 --- a/lang/cem/cemcom/LLmessage.c +++ b/lang/cem/cemcom/LLmessage.c @@ -1,6 +1,7 @@ /* $Header$ */ /* PARSER ERROR ADMINISTRATION */ +#include "nofloat.h" #include "idf.h" #include "alloc.h" #include "arith.h" diff --git a/lang/cem/cemcom/Makefile.erik b/lang/cem/cemcom/Makefile.erik index 7f8ea21f..8e7b76aa 100644 --- a/lang/cem/cemcom/Makefile.erik +++ b/lang/cem/cemcom/Makefile.erik @@ -75,7 +75,7 @@ GSRC = char.c symbol2str.c next.c \ # .h files generated by `make hfiles'; PLEASE KEEP THIS UP-TO-DATE! GHSRC = botch_free.h dataflow.h debug.h density.h errout.h \ idepth.h idfsize.h ifdepth.h inputtype.h inumlength.h lapbuf.h \ - maxincl.h myalloc.h nobitfield.h nopp.h \ + maxincl.h myalloc.h nobitfield.h nofloat.h nopp.h \ nparams.h numsize.h parbufsize.h pathlength.h predefine.h \ strsize.h target_sizes.h textsize.h use_tmp.h spec_arith.h static.h @@ -205,47 +205,47 @@ sim: cfiles $(SIM) $(SIMFLAGS) `sources $(COBJ)` $(GSRC) $(LSRC) #AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO -main.o: LLlex.h Lpars.h alloc.h arith.h debug.h declar.h idf.h input.h inputtype.h level.h maxincl.h myalloc.h nobitfield.h nopp.h spec_arith.h specials.h target_sizes.h tokenname.h type.h use_tmp.h -idf.o: LLlex.h Lpars.h align.h alloc.h arith.h assert.h botch_free.h debug.h declar.h decspecs.h def.h idf.h idfsize.h label.h level.h nobitfield.h nopp.h sizes.h spec_arith.h specials.h stack.h storage.h struct.h type.h -declarator.o: Lpars.h alloc.h arith.h botch_free.h declar.h expr.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h type.h -decspecs.o: Lpars.h arith.h decspecs.h def.h level.h nobitfield.h spec_arith.h type.h -struct.o: LLlex.h Lpars.h align.h arith.h assert.h botch_free.h debug.h def.h field.h idf.h level.h nobitfield.h nopp.h sizes.h spec_arith.h stack.h storage.h struct.h type.h -expr.o: LLlex.h Lpars.h alloc.h arith.h botch_free.h declar.h decspecs.h def.h expr.h idf.h label.h level.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h type.h -ch7.o: Lpars.h arith.h assert.h debug.h def.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h struct.h type.h -ch7bin.o: Lpars.h arith.h botch_free.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h storage.h struct.h type.h -cstoper.o: Lpars.h arith.h assert.h debug.h expr.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h target_sizes.h type.h -arith.o: Lpars.h alloc.h arith.h botch_free.h expr.h field.h idf.h label.h mes.h nobitfield.h nopp.h spec_arith.h storage.h type.h -alloc.o: alloc.h assert.h debug.h myalloc.h -code.o: LLlex.h Lpars.h alloc.h arith.h assert.h atw.h botch_free.h code.h dataflow.h debug.h declar.h decspecs.h def.h expr.h idf.h label.h level.h mes.h nobitfield.h nopp.h sizes.h spec_arith.h specials.h stack.h stmt.h storage.h type.h use_tmp.h -dumpidf.o: Lpars.h arith.h debug.h def.h expr.h field.h idf.h label.h nobitfield.h nopp.h spec_arith.h stack.h static.h struct.h type.h -error.o: LLlex.h arith.h debug.h errout.h expr.h label.h nopp.h spec_arith.h tokenname.h use_tmp.h -field.o: Lpars.h arith.h assert.h code.h debug.h expr.h field.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h type.h -tokenname.o: LLlex.h Lpars.h arith.h idf.h nopp.h spec_arith.h tokenname.h -LLlex.o: LLlex.h Lpars.h alloc.h arith.h assert.h class.h debug.h def.h idf.h idfsize.h input.h nopp.h numsize.h sizes.h spec_arith.h strsize.h -LLmessage.o: LLlex.h Lpars.h alloc.h arith.h idf.h nopp.h spec_arith.h -input.o: LLlex.h alloc.h arith.h assert.h debug.h idepth.h input.h inputtype.h interface.h nopp.h pathlength.h spec_arith.h static.h -domacro.o: LLlex.h Lpars.h alloc.h arith.h assert.h botch_free.h class.h debug.h idf.h idfsize.h ifdepth.h input.h interface.h macro.h nopp.h nparams.h parbufsize.h spec_arith.h storage.h textsize.h -replace.o: LLlex.h alloc.h arith.h assert.h class.h debug.h idf.h input.h interface.h macro.h nopp.h pathlength.h spec_arith.h static.h strsize.h -init.o: alloc.h class.h idf.h interface.h macro.h nopp.h predefine.h -options.o: align.h arith.h class.h idf.h idfsize.h macro.h maxincl.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h use_tmp.h -scan.o: class.h idf.h input.h interface.h lapbuf.h macro.h nopp.h nparams.h -skip.o: LLlex.h arith.h class.h input.h interface.h nopp.h spec_arith.h -stack.o: Lpars.h alloc.h arith.h botch_free.h debug.h def.h idf.h level.h mes.h nobitfield.h nopp.h spec_arith.h stack.h storage.h struct.h type.h use_tmp.h -type.o: Lpars.h align.h alloc.h arith.h def.h idf.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h type.h -ch7mon.o: Lpars.h arith.h botch_free.h def.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h storage.h type.h -label.o: Lpars.h arith.h def.h idf.h label.h level.h nobitfield.h nopp.h spec_arith.h type.h -eval.o: Lpars.h align.h arith.h assert.h atw.h code.h dataflow.h debug.h def.h expr.h idf.h label.h level.h mes.h nobitfield.h nopp.h sizes.h spec_arith.h stack.h type.h -switch.o: Lpars.h arith.h assert.h botch_free.h code.h debug.h density.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h storage.h switch.h type.h -storage.o: alloc.h assert.h botch_free.h debug.h storage.h -ival.o: Lpars.h align.h arith.h assert.h class.h debug.h def.h expr.h field.h idf.h label.h level.h nobitfield.h nopp.h sizes.h spec_arith.h struct.h type.h -conversion.o: Lpars.h arith.h nobitfield.h sizes.h spec_arith.h type.h -blocks.o: arith.h atw.h sizes.h spec_arith.h -dataflow.o: dataflow.h -tokenfile.o: Lpars.h -declar.o: LLlex.h Lpars.h arith.h debug.h declar.h decspecs.h def.h expr.h field.h idf.h label.h nobitfield.h nopp.h sizes.h spec_arith.h storage.h struct.h type.h -statement.o: LLlex.h Lpars.h arith.h botch_free.h code.h debug.h def.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h stack.h storage.h type.h -expression.o: LLlex.h Lpars.h arith.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h type.h -program.o: LLlex.h Lpars.h alloc.h arith.h code.h declar.h decspecs.h def.h expr.h idf.h label.h nobitfield.h nopp.h spec_arith.h type.h +LLlex.o: LLlex.h Lpars.h alloc.h arith.h assert.h class.h debug.h def.h idf.h idfsize.h input.h nofloat.h nopp.h numsize.h sizes.h spec_arith.h strsize.h +LLmessage.o: LLlex.h Lpars.h alloc.h arith.h idf.h nofloat.h nopp.h spec_arith.h Lpars.o: Lpars.h +alloc.o: alloc.h assert.h debug.h myalloc.h +arith.o: Lpars.h alloc.h arith.h botch_free.h expr.h field.h idf.h label.h mes.h nobitfield.h nofloat.h nopp.h spec_arith.h storage.h type.h +blocks.o: arith.h atw.h nofloat.h sizes.h spec_arith.h +ch7.o: Lpars.h arith.h assert.h debug.h def.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h struct.h type.h +ch7bin.o: Lpars.h arith.h botch_free.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h storage.h struct.h type.h +ch7mon.o: Lpars.h arith.h botch_free.h def.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h storage.h type.h char.o: class.h +code.o: LLlex.h Lpars.h alloc.h arith.h assert.h atw.h botch_free.h code.h dataflow.h debug.h declar.h decspecs.h def.h expr.h idf.h label.h level.h mes.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h specials.h stack.h stmt.h storage.h type.h use_tmp.h +conversion.o: Lpars.h arith.h nobitfield.h nofloat.h sizes.h spec_arith.h type.h +cstoper.o: Lpars.h arith.h assert.h debug.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h target_sizes.h type.h +dataflow.o: dataflow.h +declar.o: LLlex.h Lpars.h arith.h debug.h declar.h decspecs.h def.h expr.h field.h idf.h label.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h storage.h struct.h type.h +declarator.o: Lpars.h alloc.h arith.h botch_free.h declar.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h storage.h type.h +decspecs.o: Lpars.h arith.h decspecs.h def.h level.h nobitfield.h nofloat.h spec_arith.h type.h +domacro.o: LLlex.h Lpars.h alloc.h arith.h assert.h botch_free.h class.h debug.h idf.h idfsize.h ifdepth.h input.h interface.h macro.h nofloat.h nopp.h nparams.h parbufsize.h spec_arith.h storage.h textsize.h +dumpidf.o: Lpars.h arith.h debug.h def.h expr.h field.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h stack.h static.h struct.h type.h +error.o: LLlex.h arith.h debug.h errout.h expr.h label.h nofloat.h nopp.h spec_arith.h tokenname.h use_tmp.h +eval.o: Lpars.h align.h arith.h assert.h atw.h code.h dataflow.h debug.h def.h expr.h idf.h label.h level.h mes.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h stack.h type.h +expr.o: LLlex.h Lpars.h alloc.h arith.h botch_free.h declar.h decspecs.h def.h expr.h idf.h label.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h storage.h type.h +expression.o: LLlex.h Lpars.h arith.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h +field.o: Lpars.h arith.h assert.h code.h debug.h expr.h field.h idf.h label.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h type.h +idf.o: LLlex.h Lpars.h align.h alloc.h arith.h assert.h botch_free.h debug.h declar.h decspecs.h def.h idf.h idfsize.h label.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h specials.h stack.h storage.h struct.h type.h +init.o: alloc.h class.h idf.h interface.h macro.h nopp.h predefine.h +input.o: LLlex.h alloc.h arith.h assert.h debug.h idepth.h input.h inputtype.h interface.h nofloat.h nopp.h pathlength.h spec_arith.h static.h +ival.o: Lpars.h align.h arith.h assert.h class.h debug.h def.h expr.h field.h idf.h label.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h struct.h type.h +label.o: Lpars.h arith.h def.h idf.h label.h level.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h +main.o: LLlex.h Lpars.h alloc.h arith.h debug.h declar.h idf.h input.h inputtype.h level.h maxincl.h myalloc.h nobitfield.h nofloat.h nopp.h spec_arith.h specials.h target_sizes.h tokenname.h type.h use_tmp.h +options.o: align.h arith.h class.h idf.h idfsize.h macro.h maxincl.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h storage.h use_tmp.h +program.o: LLlex.h Lpars.h alloc.h arith.h code.h declar.h decspecs.h def.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h +replace.o: LLlex.h alloc.h arith.h assert.h class.h debug.h idf.h input.h interface.h macro.h nofloat.h nopp.h pathlength.h spec_arith.h static.h strsize.h +scan.o: class.h idf.h input.h interface.h lapbuf.h macro.h nopp.h nparams.h +skip.o: LLlex.h arith.h class.h input.h interface.h nofloat.h nopp.h spec_arith.h +stack.o: Lpars.h alloc.h arith.h botch_free.h debug.h def.h idf.h level.h mes.h nobitfield.h nofloat.h nopp.h spec_arith.h stack.h storage.h struct.h type.h use_tmp.h +statement.o: LLlex.h Lpars.h arith.h botch_free.h code.h debug.h def.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h stack.h storage.h type.h +storage.o: alloc.h assert.h botch_free.h debug.h storage.h +struct.o: LLlex.h Lpars.h align.h arith.h assert.h botch_free.h debug.h def.h field.h idf.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h stack.h storage.h struct.h type.h +switch.o: Lpars.h arith.h assert.h botch_free.h code.h debug.h density.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h storage.h switch.h type.h symbol2str.o: Lpars.h +tokenfile.o: Lpars.h +tokenname.o: LLlex.h Lpars.h arith.h idf.h nofloat.h nopp.h spec_arith.h tokenname.h +type.o: Lpars.h align.h alloc.h arith.h def.h idf.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h storage.h type.h diff --git a/lang/cem/cemcom/Parameters b/lang/cem/cemcom/Parameters index 17babb55..a1d0d240 100644 --- a/lang/cem/cemcom/Parameters +++ b/lang/cem/cemcom/Parameters @@ -133,3 +133,8 @@ !File: static.h #define GSTATIC /* for large global "static" arrays */ + + +!File: nofloat.h +#undef NOFLOAT /* floats implemented by default */ + diff --git a/lang/cem/cemcom/align.h b/lang/cem/cemcom/align.h index ae162f1b..a49ad946 100644 --- a/lang/cem/cemcom/align.h +++ b/lang/cem/cemcom/align.h @@ -1,6 +1,8 @@ /* $Header$ */ /* A L I G N M E N T D E F I N I T I O N S */ +#include "nofloat.h" + extern int short_align, word_align, int_align, long_align, #ifndef NOFLOAT diff --git a/lang/cem/cemcom/arith.c b/lang/cem/cemcom/arith.c index 9379244a..51382e41 100644 --- a/lang/cem/cemcom/arith.c +++ b/lang/cem/cemcom/arith.c @@ -7,6 +7,7 @@ semantics of C is a mess. */ +#include "nofloat.h" #include "botch_free.h" #include "nobitfield.h" #include "alloc.h" @@ -25,7 +26,8 @@ extern char options[]; int arithbalance(e1p, oper, e2p) /* RM 6.6 */ - struct expr **e1p, **e2p; + register struct expr **e1p, **e2p; + int oper; { /* The expressions *e1p and *e2p are balanced to be operands of the arithmetic operator oper. @@ -127,9 +129,9 @@ any2arith(expp, oper) /* Turns any expression into int_type, long_type or double_type. */ - int fund = (*expp)->ex_type->tp_fund; + int fund; - switch (fund) { + switch (fund = (*expp)->ex_type->tp_fund) { case CHAR: case SHORT: int2int(expp, @@ -174,7 +176,7 @@ any2arith(expp, oper) } erroneous2int(expp) - struct expr **expp; + register struct expr **expp; { /* the (erroneous) expression *expp is replaced by an int expression @@ -190,7 +192,7 @@ struct expr * arith2arith(tp, oper, expr) struct type *tp; int oper; - struct expr *expr; + register struct expr *expr; { /* arith2arith constructs a new expression containing a run-time conversion between some arithmetic types. @@ -280,7 +282,7 @@ array2pointer(expp) } function2pointer(expp) - struct expr **expp; + register struct expr **expp; { /* The expression, which must be a function, is converted to a pointer to the function. @@ -295,7 +297,7 @@ string2pointer(expp) /* The expression, which must be a string constant, is converted to a pointer to the string-containing area. */ - struct expr *ex = *expp; + register struct expr *ex = *expp; label lbl = data_label(); code_string(ex->SG_VALUE, ex->SG_LEN, lbl); @@ -306,7 +308,7 @@ string2pointer(expp) } opnd2integral(expp, oper) - struct expr **expp; + register struct expr **expp; int oper; { register int fund = (*expp)->ex_type->tp_fund; @@ -320,7 +322,7 @@ opnd2integral(expp, oper) } opnd2logical(expp, oper) - struct expr **expp; + register struct expr **expp; int oper; { register int fund; @@ -332,11 +334,7 @@ opnd2logical(expp, oper) if ((*expp)->ex_type->tp_fund == FIELD) field2arith(expp); #endif NOBITFIELD - - fund = (*expp)->ex_type->tp_fund; - - switch (fund) { - + switch (fund = (*expp)->ex_type->tp_fund) { case CHAR: case SHORT: case INT: @@ -358,7 +356,7 @@ opnd2logical(expp, oper) } opnd2test(expp, oper) - struct expr **expp; + register struct expr **expp; { opnd2logical(expp, oper); if ((*expp)->ex_class == Oper && is_test_op((*expp)->OP_OPER)) @@ -429,7 +427,7 @@ is_asgn_op(oper) } any2opnd(expp, oper) - struct expr **expp; + register struct expr **expp; { if (!*expp) return; diff --git a/lang/cem/cemcom/ch7.c b/lang/cem/cemcom/ch7.c index b95922fe..1317571c 100644 --- a/lang/cem/cemcom/ch7.c +++ b/lang/cem/cemcom/ch7.c @@ -1,6 +1,7 @@ /* $Header$ */ /* S E M A N T I C A N A L Y S I S -- C H A P T E R 7 RM */ +#include "nofloat.h" #include "debug.h" #include "nobitfield.h" #include "idf.h" diff --git a/lang/cem/cemcom/ch7bin.c b/lang/cem/cemcom/ch7bin.c index b8e1e182..848f14cf 100644 --- a/lang/cem/cemcom/ch7bin.c +++ b/lang/cem/cemcom/ch7bin.c @@ -1,7 +1,8 @@ /* $Header$ */ /* SEMANTIC ANALYSIS (CHAPTER 7RM) -- BINARY OPERATORS */ -#include "botch_free.h" /* UF */ +#include "nofloat.h" +#include "botch_free.h" #include "idf.h" #include "arith.h" #include "type.h" diff --git a/lang/cem/cemcom/ch7mon.c b/lang/cem/cemcom/ch7mon.c index 21ca76bd..23c3f5c3 100644 --- a/lang/cem/cemcom/ch7mon.c +++ b/lang/cem/cemcom/ch7mon.c @@ -1,6 +1,7 @@ /* $Header$ */ /* SEMANTIC ANALYSIS (CHAPTER 7RM) -- MONADIC OPERATORS */ +#include "nofloat.h" #include "nobitfield.h" #include "botch_free.h" #include "Lpars.h" diff --git a/lang/cem/cemcom/code.c b/lang/cem/cemcom/code.c index dfd952b5..a5c245de 100644 --- a/lang/cem/cemcom/code.c +++ b/lang/cem/cemcom/code.c @@ -1,12 +1,11 @@ /* $Header$ */ /* C O D E - G E N E R A T I N G R O U T I N E S */ +#include "nofloat.h" #include - #include "dataflow.h" #include "use_tmp.h" #include "botch_free.h" - #include "arith.h" #include "type.h" #include "idf.h" @@ -67,7 +66,7 @@ code_string(val, len, dlb) int len; label dlb; { - struct string_cst *sc = new_string_cst(); + register struct string_cst *sc = new_string_cst(); C_ina_dlb(dlb); sc->next = str_list; @@ -107,14 +106,14 @@ prepend_scopes(dst_file) and generates those exa's, exp's, ina's and inp's that superior hindsight has provided, on the file dst_file. */ - struct stack_entry *se = local_level->sl_entry; + register struct stack_entry *se = local_level->sl_entry; if (C_open(dst_file) == 0) fatal("cannot create %s", dst_file ? dst_file : "stdout"); famous_first_words(); while (se != 0) { - struct idf *idf = se->se_idf; - struct def *def = idf->id_def; + register struct idf *idf = se->se_idf; + register struct def *def = idf->id_def; if (def && ( def->df_initialized || @@ -131,7 +130,7 @@ prepend_scopes(dst_file) code_scope(text, def) char *text; - struct def *def; + register struct def *def; { /* generates code for one name, text, of the storage class as given by def, if meaningful. @@ -165,7 +164,7 @@ static label file_name_label; begin_proc(name, def) /* to be called when entering a procedure */ char *name; - struct def *def; + register struct def *def; { /* begin_proc() is called at the entrance of a new function and performs the necessary code generation: @@ -291,7 +290,7 @@ do_return_expr(expr) } code_declaration(idf, expr, lvl, sc) - struct idf *idf; /* idf to be declared */ + register struct idf *idf; /* idf to be declared */ struct expr *expr; /* initialisation; NULL if absent */ int lvl; /* declaration level */ int sc; /* storage class, as in the declaration */ @@ -319,7 +318,7 @@ code_declaration(idf, expr, lvl, sc) extern int a = 5; */ char *text = idf->id_text; - struct def *def = idf->id_def; + register struct def *def = idf->id_def; arith size = def->df_type->tp_size; int def_sc = def->df_sc; @@ -437,7 +436,7 @@ loc_init(expr, id) } bss(idf) - struct idf *idf; + register struct idf *idf; { /* bss() allocates bss space for the global idf. */ @@ -456,21 +455,21 @@ bss(idf) C_bss_cst(align(size, word_align), (arith)0, 1); } -formal_cvt(def) - struct def *def; +formal_cvt(df) + register struct def *df; { /* formal_cvt() converts a formal parameter of type char or short from int to that type. */ - register struct type* tp = def->df_type; + register struct type *tp = df->df_type; if (tp->tp_size != int_size) if (tp->tp_fund == CHAR || tp->tp_fund == SHORT) { - C_lol(def->df_address); - conversion(int_type, def->df_type); - C_lal(def->df_address); + C_lol(df->df_address); + conversion(int_type, df->df_type); + C_lal(df->df_address); C_sti(tp->tp_size); - def->df_register = REG_NONE; + df->df_register = REG_NONE; } } diff --git a/lang/cem/cemcom/conversion.c b/lang/cem/cemcom/conversion.c index e62cb264..bbb8914b 100644 --- a/lang/cem/cemcom/conversion.c +++ b/lang/cem/cemcom/conversion.c @@ -1,6 +1,7 @@ /* $Header$ */ /* C O N V E R S I O N - C O D E G E N E R A T O R */ +#include "nofloat.h" #include #include "arith.h" #include "type.h" @@ -29,30 +30,23 @@ conversion(from_type, to_type) arith from_size; arith to_size; - if (from_type == to_type) { /* a little optimisation */ + if (from_type == to_type) /* a little optimisation */ return; - } - from_size = from_type->tp_size; to_size = to_type->tp_size; - switch (fundamental(from_type)) { - case T_SIGNED: switch (fundamental(to_type)) { - case T_SIGNED: C_loc(from_size); C_loc(to_size < word_size ? word_size : to_size); C_cii(); break; - case T_UNSIGNED: C_loc(from_size < word_size ? word_size : from_size); C_loc(to_size < word_size ? word_size : to_size); C_ciu(); break; - #ifndef NOFLOAT case T_FLOATING: C_loc(from_size < word_size ? word_size : from_size); @@ -62,21 +56,16 @@ conversion(from_type, to_type) #endif NOFLOAT } break; - case T_UNSIGNED: C_loc(from_size < word_size ? word_size : from_size); C_loc(to_size < word_size ? word_size : to_size); - switch (fundamental(to_type)) { - case T_SIGNED: C_cui(); break; - case T_UNSIGNED: C_cuu(); break; - #ifndef NOFLOAT case T_FLOATING: C_cuf(); @@ -84,22 +73,17 @@ conversion(from_type, to_type) #endif NOFLOAT } break; - #ifndef NOFLOAT case T_FLOATING: C_loc(from_size < word_size ? word_size : from_size); C_loc(to_size < word_size ? word_size : to_size); - switch (fundamental(to_type)) { - case T_SIGNED: C_cfi(); break; - case T_UNSIGNED: C_cfu(); break; - case T_FLOATING: C_cff(); break; @@ -116,10 +100,9 @@ conversion(from_type, to_type) */ int fundamental(tp) - struct type *tp; + register struct type *tp; { switch (tp->tp_fund) { - case CHAR: case SHORT: case INT: @@ -127,13 +110,11 @@ fundamental(tp) case LONG: case ENUM: return tp->tp_unsigned ? T_UNSIGNED : T_SIGNED; - #ifndef NOFLOAT case FLOAT: case DOUBLE: return T_FLOATING; #endif NOFLOAT - case POINTER: /* pointer : signed / unsigned ??? */ return T_SIGNED; } diff --git a/lang/cem/cemcom/cstoper.c b/lang/cem/cemcom/cstoper.c index e9ce5349..8c515410 100644 --- a/lang/cem/cemcom/cstoper.c +++ b/lang/cem/cemcom/cstoper.c @@ -1,8 +1,7 @@ /* $Header$ */ /* C O N S T A N T E X P R E S S I O N H A N D L I N G */ -#include "target_sizes.h" /* UF */ - +#include "target_sizes.h" #include "idf.h" #include "arith.h" #include "type.h" @@ -19,14 +18,14 @@ arith max_int; /* maximum integer on target machine */ arith max_unsigned; /* maximum unsigned on target machine */ cstbin(expp, oper, expr) - struct expr **expp, *expr; + register struct expr **expp, *expr; { /* The operation oper is performed on the constant expressions *expp(ld) and expr(ct), and the result restored in *expp. */ - arith o1 = (*expp)->VL_VALUE; - arith o2 = expr->VL_VALUE; + register arith o1 = (*expp)->VL_VALUE; + register arith o2 = expr->VL_VALUE; int uns = (*expp)->ex_type->tp_unsigned; ASSERT(is_ld_cst(*expp) && is_cp_cst(expr)); @@ -184,7 +183,7 @@ cstbin(expp, oper, expr) } cut_size(expr) - struct expr *expr; + register struct expr *expr; { /* The constant value of the expression expr is made to conform to the size of the type of the expression. @@ -214,8 +213,8 @@ cut_size(expr) init_cst() { - int i = 0; - arith bt = (arith)0; + register int i = 0; + register arith bt = (arith)0; while (!(bt < 0)) { bt = (bt << 8) + 0377, i++; @@ -227,8 +226,6 @@ init_cst() mach_long_sign = 1 << (mach_long_size * 8 - 1); if (long_size < mach_long_size) fatal("sizeof (long) insufficient on this machine"); - - max_int = full_mask[int_size] & ~(1 << (int_size * 8 - 1)); max_unsigned = full_mask[int_size]; } diff --git a/lang/cem/cemcom/declarator.c b/lang/cem/cemcom/declarator.c index dba30694..ff79ab0a 100644 --- a/lang/cem/cemcom/declarator.c +++ b/lang/cem/cemcom/declarator.c @@ -33,7 +33,7 @@ declare_type(tp, dc) } add_decl_unary(dc, fund, count, fm) - struct declarator *dc; + register struct declarator *dc; arith count; struct formal *fm; { @@ -77,7 +77,7 @@ remove_declarator(dc) } reject_params(dc) - struct declarator *dc; + register struct declarator *dc; { /* The declarator is checked to have no parameters, if it is a function. @@ -90,7 +90,7 @@ reject_params(dc) } array_subscript(expr) - struct expr *expr; + register struct expr *expr; { arith size = expr->VL_VALUE; diff --git a/lang/cem/cemcom/decspecs.c b/lang/cem/cemcom/decspecs.c index 564b8d0b..ead1cbe6 100644 --- a/lang/cem/cemcom/decspecs.c +++ b/lang/cem/cemcom/decspecs.c @@ -1,6 +1,7 @@ /* $Header$ */ /* D E C L A R A T I O N S P E C I F I E R C H E C K I N G */ +#include "nofloat.h" #include "Lpars.h" #include "decspecs.h" #include "arith.h" @@ -15,12 +16,12 @@ extern char *symbol2str(); struct decspecs null_decspecs; do_decspecs(ds) - struct decspecs *ds; + register struct decspecs *ds; { /* The provisional decspecs ds as obtained from the program is turned into a legal consistent decspecs. */ - struct type *tp = ds->ds_type; + register struct type *tp = ds->ds_type; if (level == L_FORMAL1) crash("do_decspecs"); diff --git a/lang/cem/cemcom/dumpidf.c b/lang/cem/cemcom/dumpidf.c index c027c646..4e5e41e9 100644 --- a/lang/cem/cemcom/dumpidf.c +++ b/lang/cem/cemcom/dumpidf.c @@ -4,6 +4,7 @@ #include "debug.h" #ifdef DEBUG +#include "nofloat.h" #include "nopp.h" #include "nobitfield.h" #include "arith.h" @@ -41,7 +42,7 @@ static int dumplevel; static newline() { - int dl = dumplevel; + register int dl = dumplevel; print("\n"); while (dl >= 2) { @@ -66,7 +67,7 @@ dumpidftab(msg, opt) print(">>> DUMPIDF, %s (start)", msg); dumpstack(); for (i = 0; i < HASHSIZE; i++) { - struct idf *notch = idf_hashtable[i]; + register struct idf *notch = idf_hashtable[i]; while (notch) { dumpidf(notch, opt); @@ -77,13 +78,14 @@ dumpidftab(msg, opt) print(">>> DUMPIDF, %s (end)\n", msg); } -dumpstack() { +dumpstack() +{ /* Dumps the identifier stack, starting at the top. */ - struct stack_level *stl = local_level; + register struct stack_level *stl = local_level; while (stl) { - struct stack_entry *se = stl->sl_entry; + register struct stack_entry *se = stl->sl_entry; newline(); print("%3d: ", stl->sl_level); @@ -97,7 +99,7 @@ dumpstack() { } dumpidf(idf, opt) - struct idf *idf; + register struct idf *idf; { /* All information about the identifier idf is divulged in a hopefully readable format. @@ -174,7 +176,7 @@ dumpdefs(def, opt) } dumptags(tag) - struct tag *tag; + register struct tag *tag; { dumplevel++; while (tag) { @@ -202,7 +204,7 @@ dumptags(tag) } dumpsdefs(sdef, sdk) - struct sdef *sdef; + register struct sdef *sdef; enum sdef_kind sdk; { /* Since sdef's are members of two chains, there are actually @@ -235,7 +237,7 @@ dumpsdefs(sdef, sdk) char * type2str(tp) - struct type *tp; + register struct type *tp; { /* Yields a pointer to a one-line description of the type tp. */ @@ -312,7 +314,7 @@ print_expr(msg, expr) } p1_expr(lvl, expr) - struct expr *expr; + register struct expr *expr; { extern char *type2str(), *symbol2str(); @@ -389,7 +391,9 @@ p1_expr(lvl, expr) } } -p1_indent(lvl) { +p1_indent(lvl) + register int lvl; +{ while (lvl--) print(" "); } diff --git a/lang/cem/cemcom/eval.c b/lang/cem/cemcom/eval.c index 5374ef46..4923c857 100644 --- a/lang/cem/cemcom/eval.c +++ b/lang/cem/cemcom/eval.c @@ -12,11 +12,10 @@ compare() */ +#include "nofloat.h" #include - #include "debug.h" #include "nobitfield.h" - #include "dataflow.h" #include "arith.h" #include "type.h" @@ -71,13 +70,13 @@ arith tmp_pointer_var(); */ EVAL(expr, val, code, true_label, false_label) - struct expr *expr; /* the expression tree itself */ + register struct expr *expr; /* the expression tree itself */ int val; /* either RVAL or LVAL */ int code; /* generate explicit code or not */ label true_label; label false_label; /* labels to jump to in logical expr's */ { - register gencode = (code == TRUE); + register int gencode = (code == TRUE); switch (expr->ex_class) { case Value: /* just a simple value */ @@ -87,7 +86,9 @@ EVAL(expr, val, code, true_label, false_label) case String: /* a string constant */ expr_warning(expr, "(DEBUG) value-class 'String' seen"); if (gencode) { - string2pointer(&expr); + struct expr *ex = expr; + string2pointer(&ex); + expr = ex; C_lae_dlb(expr->VL_LBL, expr->VL_VALUE); } break; @@ -105,7 +106,7 @@ EVAL(expr, val, code, true_label, false_label) #endif NOFLOAT case Oper: /* compound expression */ { - register int oper = expr->OP_OPER; + int oper = expr->OP_OPER; register struct expr *leftop = expr->OP_LEFT; register struct expr *rightop = expr->OP_RIGHT; register struct type *tp = expr->OP_TYPE; @@ -250,12 +251,11 @@ EVAL(expr, val, code, true_label, false_label) EVAL(leftop, RVAL, code, NO_LABEL, NO_LABEL); EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); ASSERT(tp->tp_fund==INT || tp->tp_fund==LONG); - if (gencode) { + if (gencode) if (tp->tp_unsigned) C_rmu(tp->tp_size); else C_rmi(tp->tp_size); - } break; case LEFT: EVAL(leftop, RVAL, code, NO_LABEL, NO_LABEL); @@ -429,22 +429,21 @@ EVAL(expr, val, code, true_label, false_label) } case '(': { - register struct expr *expr; + register struct expr *ex; arith ParSize = (arith)0; - if (expr = rightop) { + if ((ex = rightop) != NILEXPR) { /* function call with parameters*/ - while ( expr->ex_class == Oper && - expr->OP_OPER == PARCOMMA - ) { - EVAL(expr->OP_RIGHT, RVAL, TRUE, + while ( ex->ex_class == Oper && + ex->OP_OPER == PARCOMMA + ) { + EVAL(ex->OP_RIGHT, RVAL, TRUE, NO_LABEL, NO_LABEL); - ParSize += - ATW(expr->ex_type->tp_size); - expr = expr->OP_LEFT; + ParSize += ATW(ex->ex_type->tp_size); + ex = ex->OP_LEFT; } - EVAL(expr, RVAL, TRUE, NO_LABEL, NO_LABEL); - ParSize += ATW(expr->ex_type->tp_size); + EVAL(ex, RVAL, TRUE, NO_LABEL, NO_LABEL); + ParSize += ATW(ex->ex_type->tp_size); } if ( leftop->ex_class == Value && leftop->VL_CLASS == Name @@ -469,14 +468,14 @@ EVAL(expr, val, code, true_label, false_label) /* remove parameters from stack */ if (ParSize > (arith)0) C_asp(ParSize); - if (!gencode) - break; - if (is_struct_or_union(tp->tp_fund)) { - C_lfr(pointer_size); - load_block(tp->tp_size, tp->tp_align); + if (gencode) { + if (is_struct_or_union(tp->tp_fund)) { + C_lfr(pointer_size); + load_block(tp->tp_size, tp->tp_align); + } + else + C_lfr(ATW(tp->tp_size)); } - else - C_lfr(ATW(tp->tp_size)); break; } case '.': @@ -507,22 +506,32 @@ EVAL(expr, val, code, true_label, false_label) { arith old_offset, tmp; arith esize = tp->tp_size; + int compl; /* Complexity of left operand */ #ifndef NOBITFIELD if (leftop->ex_type->tp_fund == FIELD) { eval_field(expr, code); break; } #endif NOBITFIELD - if (leftop->ex_class != Value) { + if (leftop->ex_class == Value) { + compl = 0; /* Value */ + load_val(leftop, RVAL); + } + else + if (leftop->ex_depth == 1 && leftop->OP_OPER == ARROW) { + compl = 1; /* Value->sel */ + ASSERT(leftop->OP_LEFT->ex_class == Value); + EVAL(leftop, RVAL, TRUE, NO_LABEL, NO_LABEL); + } + else { + compl = 2; /* otherwise */ tmp = tmp_pointer_var(&old_offset); EVAL(leftop, LVAL, TRUE, NO_LABEL, NO_LABEL); C_dup(pointer_size); C_lal(tmp); C_sti(pointer_size); - C_loi(tp->tp_size); + C_loi(esize); } - else - load_val(leftop, RVAL); /* We made the choice to put this stuff here and not to put the conversion in the expression @@ -542,17 +551,23 @@ EVAL(expr, val, code, true_label, false_label) C_dup(esize); if (tp->tp_size < word_size) conversion(word_type, tp); - if (leftop->ex_class != Value) { + if (compl == 0) { + store_val( + &(leftop->ex_object.ex_value), + leftop->ex_type + ); + } + else + if (compl == 1) { + EVAL(leftop, LVAL, TRUE, NO_LABEL, NO_LABEL); + C_sti(tp->tp_size); + } + else { C_lal(tmp); /* always init'd */ C_loi(pointer_size); C_sti(tp->tp_size); free_tmp_var(old_offset); } - else - store_val( - &(leftop->ex_object.ex_value), - leftop->ex_type - ); break; } case '?': /* must be followed by ':' */ @@ -685,7 +700,6 @@ EVAL(expr, val, code, true_label, false_label) expr->ex_type->tp_align); break; } - case Type: default: crash("(EVAL) bad expression class"); } @@ -722,13 +736,13 @@ compare(relop, lbl) /* assop() generates the opcode of an assignment operators op= */ assop(type, oper) - struct type *type; + register struct type *type; int oper; { - register arith size = type->tp_size; + register arith size; register uns = type->tp_unsigned; - if (size < word_size) + if ((size = type->tp_size) < word_size) size = word_size; switch (type->tp_fund) { case CHAR: @@ -837,7 +851,7 @@ arith tmp_pointer_var(oldoffset) arith *oldoffset; /* previous allocated address */ { - struct stack_level *stl = local_level; + register struct stack_level *stl = local_level; *oldoffset = stl->sl_local_offset; stl->sl_local_offset = @@ -940,16 +954,16 @@ store_val(vl, tp) - local variable */ load_val(expr, val) - struct expr *expr; /* expression containing the value */ + register struct expr *expr; /* expression containing the value */ int val; /* generate either LVAL or RVAL */ { register struct type *tp = expr->ex_type; - register int rvalue = (val == RVAL && expr->ex_lvalue != 0); - register arith size = tp->tp_size; - register int tpalign = tp->tp_align; - register int al_on_word; + int rvalue = (val == RVAL && expr->ex_lvalue != 0); + arith size = tp->tp_size; + int tpalign = tp->tp_align; + int al_on_word; register int inword, indword; - register arith val = expr->VL_VALUE; + arith val = expr->VL_VALUE; if (expr->VL_CLASS == Const) { if (rvalue) { /* absolute addressing */ diff --git a/lang/cem/cemcom/expr.c b/lang/cem/cemcom/expr.c index 6426ec5b..282e3391 100644 --- a/lang/cem/cemcom/expr.c +++ b/lang/cem/cemcom/expr.c @@ -1,7 +1,8 @@ /* $Header$ */ /* EXPRESSION TREE HANDLING */ -#include "botch_free.h" /* UF */ +#include "nofloat.h" +#include "botch_free.h" #include "alloc.h" #include "idf.h" #include "arith.h" @@ -92,7 +93,7 @@ rank_of(oper) int rank_of_expression(expr) - struct expr *expr; + register struct expr *expr; { /* Returns the rank of the top node in the expression. */ @@ -115,7 +116,7 @@ check_conditional(expr, oper, pos_descr) } dot2expr(expp) - struct expr **expp; + register struct expr **expp; { /* The token in dot is converted into an expression, a pointer to which is stored in *expp. @@ -146,7 +147,7 @@ dot2expr(expp) } idf2expr(expr) - struct expr *expr; + register struct expr *expr; { /* Dot contains an identifier which is turned into an expression. @@ -205,7 +206,7 @@ idf2expr(expr) } string2expr(expr) - struct expr *expr; + register struct expr *expr; { /* Dot contains a string which is turned into an expression. */ @@ -228,7 +229,7 @@ int2expr(expr) #ifndef NOFLOAT float2expr(expr) - struct expr *expr; + register struct expr *expr; { /* Dot contains a floating point constant which is turned into an expression. @@ -243,11 +244,12 @@ float2expr(expr) struct expr* intexpr(ivalue, fund) arith ivalue; + int fund; { /* The value ivalue is turned into an integer expression of the size indicated by fund. */ - struct expr *expr = new_expr(); + register struct expr *expr = new_expr(); clear((char *)expr, sizeof(struct expr)); expr->ex_file = dot.tk_file; @@ -258,8 +260,9 @@ intexpr(ivalue, fund) } fill_int_expr(expr, ivalue, fund) - struct expr *expr; + register struct expr *expr; arith ivalue; + int fund; { /* Details derived from ivalue and fund are put into the constant integer expression expr. @@ -308,12 +311,12 @@ new_oper(tp, e1, oper, e2) During the construction of the right recursive initialisation tree it is possible for e2 to be NILEXPR. */ - struct expr *expr = new_expr(); - struct oper *op; + register struct expr *expr = new_expr(); + register struct oper *op; clear((char *)expr, sizeof(struct expr)); if (e2) { - struct expr *e = e2; + register struct expr *e = e2; while (e->ex_class == Oper && e->OP_LEFT) e = e->OP_LEFT; @@ -322,7 +325,7 @@ new_oper(tp, e1, oper, e2) } else if (e1) { - struct expr *e = e1; + register struct expr *e = e1; while (e->ex_class == Oper && e->OP_RIGHT) e = e->OP_RIGHT; @@ -387,7 +390,7 @@ chk_cst_expr(expp) register struct expr *expr = *expp; register int fund = expr->ex_type->tp_fund; register int flags = expr->ex_flags; - register int err = 0; + int err = 0; #ifdef DEBUG print_expr("constant_expression", expr); @@ -417,7 +420,7 @@ chk_cst_expr(expp) } init_expression(eppp, expr) - struct expr ***eppp, *expr; + register struct expr ***eppp, *expr; { /* The expression expr is added to the tree designated indirectly by **eppp. @@ -468,7 +471,7 @@ is_fp_cst(expr) #endif NOFLOAT free_expression(expr) - struct expr *expr; + register struct expr *expr; { /* The expression expr is freed recursively. */ diff --git a/lang/cem/cemcom/expr.str b/lang/cem/cemcom/expr.str index cf74c7e9..c80f9a7b 100644 --- a/lang/cem/cemcom/expr.str +++ b/lang/cem/cemcom/expr.str @@ -5,6 +5,8 @@ a union of various goodies, we define them first; so be patient. */ +#include "nofloat.h" + /* classes of value */ #define Const 1 #define Name 2 diff --git a/lang/cem/cemcom/idf.c b/lang/cem/cemcom/idf.c index 2cda12a9..92a3f736 100644 --- a/lang/cem/cemcom/idf.c +++ b/lang/cem/cemcom/idf.c @@ -1,6 +1,7 @@ /* $Header$ */ /* IDENTIFIER FIDDLING & SYMBOL TABLE HANDLING */ +#include "nofloat.h" #include "debug.h" #include "idfsize.h" #include "botch_free.h" @@ -86,11 +87,11 @@ idf_hashed(tg, size, hc) hash_stat() { if (options['h']) { - int i; + register int i; print("Hash table tally:\n"); for (i = 0; i < HASHSIZE; i++) { - struct idf *notch = idf_hashtable[i]; + register struct idf *notch = idf_hashtable[i]; int cnt = 0; while (notch) { @@ -374,8 +375,8 @@ actual_declaration(sc, tp) } global_redecl(idf, new_sc, tp) - struct idf *idf; - struct type *tp; + register struct idf *idf; + register struct type *tp; { /* A global identifier may be declared several times, provided the declarations do not conflict; they might @@ -386,7 +387,7 @@ global_redecl(idf, new_sc, tp) register struct def *def = idf->id_def; if (tp != def->df_type) { - struct type *otp = def->df_type; + register struct type *otp = def->df_type; if ( tp->tp_fund != ARRAY || otp->tp_fund != ARRAY || tp->tp_up != otp->tp_up @@ -425,10 +426,8 @@ global_redecl(idf, new_sc, tp) return; /* no new information */ switch (def->df_sc) { /* the old storage class */ - case EXTERN: switch (new_sc) { /* the new storage class */ - case EXTERN: case GLOBAL: break; @@ -449,10 +448,8 @@ global_redecl(idf, new_sc, tp) break; } break; - case GLOBAL: switch (new_sc) { /* the new storage class */ - case EXTERN: def->df_sc = EXTERN; break; @@ -475,10 +472,8 @@ global_redecl(idf, new_sc, tp) break; } break; - case STATIC: switch (new_sc) { /* the new storage class */ - case EXTERN: if (def->df_initialized) { error("cannot redeclare %s to extern", @@ -501,10 +496,8 @@ global_redecl(idf, new_sc, tp) break; } break; - case IMPLICIT: switch (new_sc) { /* the new storage class */ - case EXTERN: case GLOBAL: def->df_sc = new_sc; @@ -520,7 +513,6 @@ global_redecl(idf, new_sc, tp) break; } break; - case ENUM: case TYPEDEF: error("illegal redeclaration of %s", idf->id_text); @@ -550,7 +542,7 @@ good_formal(def, idf) } declare_params(dc) - struct declarator *dc; + register struct declarator *dc; { /* Declares the formal parameters if they exist. */ @@ -607,7 +599,7 @@ declare_formals(fp) An address is assigned to each formal parameter. The total size of the formals is returned in *fp; */ - struct stack_entry *se = stack_level_of(L_FORMAL1)->sl_entry; + register struct stack_entry *se = stack_level_of(L_FORMAL1)->sl_entry; arith f_offset = (arith)0; #ifdef DEBUG @@ -615,8 +607,7 @@ declare_formals(fp) dumpidftab("start declare_formals", 0); #endif DEBUG while (se) { - struct idf *idf = se->se_idf; - struct def *def = idf->id_def; + register struct def *def = se->se_idf->id_def; def->df_address = f_offset; @@ -624,8 +615,7 @@ declare_formals(fp) word boundaries, i.e. take care that the following parameter starts on a new word boundary. */ - f_offset = align(f_offset + def->df_type->tp_size, - word_align); + f_offset = align(f_offset + def->df_type->tp_size, word_align); /* the following is absurd: any char or short formal must be converted from integer to that type @@ -673,7 +663,7 @@ update_ahead(idf) } free_formals(fm) - struct formal *fm; + register struct formal *fm; { while (fm) { register struct formal *tmp = fm->next; @@ -684,11 +674,12 @@ free_formals(fm) char hmask[IDFSIZE]; -init_hmask() { +init_hmask() +{ /* A simple congruence random number generator, as described in Knuth, vol 2. */ - int h, rnd = HASH_X; + register int h, rnd = HASH_X; for (h = 0; h < IDFSIZE; h++) { hmask[h] = rnd; diff --git a/lang/cem/cemcom/ival.c b/lang/cem/cemcom/ival.c index 61ce90f2..75525498 100644 --- a/lang/cem/cemcom/ival.c +++ b/lang/cem/cemcom/ival.c @@ -1,11 +1,10 @@ /* $Header$ */ /* CODE FOR THE INITIALISATION OF GLOBAL VARIABLES */ +#include "nofloat.h" #include - #include "debug.h" #include "nobitfield.h" - #include "arith.h" #include "align.h" #include "label.h" @@ -54,7 +53,7 @@ do_ival(tpp, ex) struct expr * IVAL(tpp, ex) struct type **tpp; /* type of global variable */ - struct expr *ex; /* initialiser expression */ + register struct expr *ex; /* initialiser expression */ { register struct type *tp = *tpp; @@ -116,7 +115,7 @@ IVAL(tpp, ex) */ struct expr * do_array(ex, tpp) - struct expr *ex; + register struct expr *ex; struct type **tpp; { register struct type *tp = *tpp; @@ -215,10 +214,10 @@ do_array(ex, tpp) */ struct expr * do_struct(ex, tp) - struct expr *ex; - struct type *tp; + register struct expr *ex; + register struct type *tp; { - struct sdef *sd = tp->tp_sdef; + register struct sdef *sd = tp->tp_sdef; arith bytes_upto_here = (arith)0; arith last_offset = (arith)-1; @@ -248,8 +247,7 @@ do_struct(ex, tp) put_bf(sd->sd_type, (arith)0); else { /* fundamental type, not embraced */ - check_ival(ex->OP_LEFT, - sd->sd_type); + check_ival(ex->OP_LEFT, sd->sd_type); ex = ex->OP_RIGHT; } #endif NOBITFIELD @@ -293,11 +291,11 @@ do_struct(ex, tp) the rest is zeroed. */ check_and_pad(ex, tpp) - struct expr *ex; + register struct expr *ex; struct type **tpp; { /* ex is of a fundamental type */ - struct type *tp = *tpp; + register struct type *tp = *tpp; if (tp->tp_fund == ARRAY) { if (valid_type(tp->tp_up, "array element") == 0) @@ -339,7 +337,7 @@ check_and_pad(ex, tpp) If the element is an aggregate, pad() is called recursively. */ pad(tp) - struct type *tp; + register struct type *tp; { switch (tp->tp_fund) { case ARRAY: @@ -408,7 +406,7 @@ pad(tp) */ check_ival(ex, tp) struct expr *ex; - struct type *tp; + register struct type *tp; { /* The philosophy here is that ch7cast puts an explicit conversion node in front of the expression if the types @@ -506,8 +504,8 @@ ch_array(tpp, ex) { register struct type *tp = *tpp; register arith length; - char *s = ex->SG_VALUE; - arith ntopad; + register char *s = ex->SG_VALUE; + register arith ntopad; ASSERT(ex->ex_class == String); length = ex->SG_LEN; @@ -588,7 +586,7 @@ put_bf(tp, val) int zero_bytes(sd) - struct sdef *sd; + register struct sdef *sd; { /* fills the space between a selector of a struct and the next selector of that struct with zero-bytes. @@ -640,7 +638,7 @@ too_many_initialisers(ex) } aggregate_type(tp) - struct type *tp; + register struct type *tp; { return tp->tp_fund == ARRAY || tp->tp_fund == STRUCT; } diff --git a/lang/cem/cemcom/main.c b/lang/cem/cemcom/main.c index f3a3cd6c..e6235214 100644 --- a/lang/cem/cemcom/main.c +++ b/lang/cem/cemcom/main.c @@ -1,6 +1,7 @@ /* $Header$ */ /* MAIN PROGRAM */ +#include "nofloat.h" #include #include "nopp.h" #include "target_sizes.h" @@ -9,7 +10,6 @@ #include "use_tmp.h" #include "maxincl.h" #include "inputtype.h" - #include "input.h" #include "level.h" #include "idf.h" @@ -84,6 +84,7 @@ main(argc, argv) #endif OWNALLOC init_hmask(); + #ifndef NOPP init_pp(); /* initialise the preprocessor macros */ #endif NOPP @@ -289,7 +290,7 @@ init() } init_specials(si) - struct sp_id *si; + register struct sp_id *si; { while (si->si_identifier) { struct idf *idf = str2idf(si->si_identifier); diff --git a/lang/cem/cemcom/options.c b/lang/cem/cemcom/options.c index 90a94f16..d862e0f7 100644 --- a/lang/cem/cemcom/options.c +++ b/lang/cem/cemcom/options.c @@ -1,6 +1,7 @@ /* $Header$ */ /* U S E R O P T I O N - H A N D L I N G */ +#include "nofloat.h" #include "nopp.h" #include "idfsize.h" #include "maxincl.h" @@ -174,7 +175,6 @@ do_option(text) align = txt2int(&text); } switch (c) { - case 's': /* short */ if (size != (arith)0) short_size = size; @@ -242,11 +242,9 @@ do_option(text) } break; } - case 'n': options['n'] = 1; /* use no registers */ break; - case 'w': options['w'] = 1; /* no warnings will be given */ break; @@ -260,8 +258,7 @@ txt2int(tp) /* the integer pointed to by *tp is read, while increasing *tp; the resulting value is yielded. */ - register int val = 0; - register int ch; + register int val = 0, ch; while (ch = **tp, ch >= '0' && ch <= '9') { val = val * 10 + ch - '0'; diff --git a/lang/cem/cemcom/sizes.h b/lang/cem/cemcom/sizes.h index a4af4f2e..f3685d1c 100644 --- a/lang/cem/cemcom/sizes.h +++ b/lang/cem/cemcom/sizes.h @@ -1,6 +1,8 @@ /* $Header$ */ /* VARIOUS TARGET MACHINE SIZE DESCRIPTORS */ +#include "nofloat.h" + extern arith short_size, word_size, dword_size, int_size, long_size, #ifndef NOFLOAT diff --git a/lang/cem/cemcom/stack.c b/lang/cem/cemcom/stack.c index adb71aa6..24b95ea1 100644 --- a/lang/cem/cemcom/stack.c +++ b/lang/cem/cemcom/stack.c @@ -1,14 +1,13 @@ /* $Header$ */ /* S T A C K / U N S T A C K R O U T I N E S */ +#include "nofloat.h" #include #include #include - #include "debug.h" #include "use_tmp.h" #include "botch_free.h" - #include "alloc.h" #include "Lpars.h" #include "arith.h" @@ -42,7 +41,7 @@ int level; /* Always equal to local_level->sl_level. */ stack_level() { /* A new level is added on top of the identifier stack. */ - struct stack_level *stl = new_stack_level(); + register struct stack_level *stl = new_stack_level(); clear((char *)stl, sizeof(struct stack_level)); local_level->sl_next = stl; @@ -55,7 +54,7 @@ stack_level() { stack_idf(idf, stl) struct idf *idf; - struct stack_level *stl; + register struct stack_level *stl; { /* The identifier idf is inserted in the stack on level stl. */ diff --git a/lang/cem/cemcom/struct.c b/lang/cem/cemcom/struct.c index b5af15c0..7eea59d8 100644 --- a/lang/cem/cemcom/struct.c +++ b/lang/cem/cemcom/struct.c @@ -49,9 +49,9 @@ int lcm(); */ add_sel(stp, tp, idf, sdefpp, szp, fd) /* this is horrible */ - struct type *stp; /* type of the structure */ - struct type *tp; /* type of the selector */ - struct idf *idf; /* idf of the selector */ + register struct type *stp; /* type of the structure */ + struct type *tp; /* type of the selector */ + register struct idf *idf; /* idf of the selector */ struct sdef ***sdefpp; /* address of hook to selector definition */ arith *szp; /* pointer to struct size upto here */ struct field *fd; @@ -67,8 +67,8 @@ add_sel(stp, tp, idf, sdefpp, szp, fd) /* this is horrible */ extern arith add_field(); #endif NOBITFIELD - register struct tag *tg = stp->tp_idf->id_struct; /* or union */ - register struct sdef *sdef = idf->id_sdef; + struct tag *tg = stp->tp_idf->id_struct; /* or union */ + struct sdef *sdef = idf->id_sdef; register struct sdef *newsdef; int lvl = tg->tg_level; @@ -164,7 +164,7 @@ check_selector(idf, stp) /* checks if idf occurs already as a selector in struct or union *stp. */ - struct sdef *sdef = stp->tp_sdef; + register struct sdef *sdef = stp->tp_sdef; while (sdef) { if (sdef->sd_idf == idf) @@ -174,7 +174,7 @@ check_selector(idf, stp) } declare_struct(fund, idf, tpp) - struct idf *idf; + register struct idf *idf; struct type **tpp; { /* A struct, union or enum (depending on fund) with tag (!) @@ -251,7 +251,7 @@ declare_struct(fund, idf, tpp) } apply_struct(fund, idf, tpp) - struct idf *idf; + register struct idf *idf; struct type **tpp; { /* The occurrence of a struct, union or enum (depending on @@ -271,7 +271,7 @@ apply_struct(fund, idf, tpp) struct sdef * idf2sdef(idf, tp) - struct idf *idf; + register struct idf *idf; struct type *tp; { /* The identifier idf is identified as a selector, preferably @@ -280,7 +280,7 @@ idf2sdef(idf, tp) If the attempt fails, a selector of type error_type is created. */ - struct sdef **sdefp = &idf->id_sdef, *sdef; + register struct sdef **sdefp = &idf->id_sdef, *sdef; /* Follow chain from idf, to meet tp. */ while ((sdef = *sdefp)) { @@ -316,7 +316,7 @@ idf2sdef(idf, tp) int uniq_selector(idf_sdef) - struct sdef *idf_sdef; + register struct sdef *idf_sdef; { /* Returns true if idf_sdef (which is guaranteed to exist) is unique for this level, i.e there is no other selector @@ -326,7 +326,7 @@ uniq_selector(idf_sdef) case! */ - struct sdef *sdef = idf_sdef->next; + register struct sdef *sdef = idf_sdef->next; while (sdef && sdef->sd_level == idf_sdef->sd_level) { if ( sdef->sd_type != idf_sdef->sd_type @@ -342,11 +342,11 @@ uniq_selector(idf_sdef) #ifndef NOBITFIELD arith add_field(szp, fd, fdtpp, idf, stp) - arith *szp; /* size of struct upto here */ - struct field *fd; /* bitfield, containing width */ - struct type **fdtpp; /* type of selector */ - struct idf *idf; /* name of selector */ - struct type *stp; /* current struct descriptor */ + arith *szp; /* size of struct upto here */ + register struct field *fd; /* bitfield, containing width */ + register struct type **fdtpp; /* type of selector */ + struct idf *idf; /* name of selector */ + register struct type *stp; /* current struct descriptor */ { /* The address where this selector is put is returned. If the selector with specified width does not fit in the word, or @@ -376,7 +376,6 @@ add_field(szp, fd, fdtpp, idf, stp) } switch ((*fdtpp)->tp_fund) { - case CHAR: case SHORT: case INT: @@ -419,22 +418,19 @@ add_field(szp, fd, fdtpp, idf, stp) bits_declared = fd->fd_width; } else - if (fd->fd_width == 0) { + if (fd->fd_width == 0) /* next field should be aligned on the next boundary. This will take care that no field will fit in the space allocated upto here. */ bits_declared = bits_in_type + 1; - } - else { /* the bitfield fits in the current field */ + else /* the bitfield fits in the current field */ bits_declared += fd->fd_width; - } /* Arrived here, the place where the selector is stored in the struct is computed. Now we need a mask to use its value in expressions. */ - *fdtpp = construct_type(FIELD, *fdtpp, (arith)0); (*fdtpp)->tp_field = fd; @@ -446,12 +442,10 @@ add_field(szp, fd, fdtpp, idf, stp) */ fd->fd_mask = (1 << fd->fd_width) - 1; - if (options['r']) { /* adjust the field at the right */ + if (options['r']) /* adjust the field at the right */ fd->fd_shift = bits_declared - fd->fd_width; - } - else { /* adjust the field at the left */ + else /* adjust the field at the left */ fd->fd_shift = bits_in_type - bits_declared; - } return field_offset; } diff --git a/lang/cem/cemcom/switch.c b/lang/cem/cemcom/switch.c index 35d131ba..8a3fa20d 100644 --- a/lang/cem/cemcom/switch.c +++ b/lang/cem/cemcom/switch.c @@ -1,12 +1,11 @@ /* $Header$ */ /* S W I T C H - S T A T E M E N T A D M I N I S T R A T I O N */ +#include "nofloat.h" #include - #include "debug.h" #include "botch_free.h" #include "density.h" - #include "Lpars.h" #include "idf.h" #include "label.h" diff --git a/lang/cem/cemcom/type.c b/lang/cem/cemcom/type.c index 52021832..73f805d9 100644 --- a/lang/cem/cemcom/type.c +++ b/lang/cem/cemcom/type.c @@ -1,6 +1,7 @@ /* $Header$ */ /* T Y P E D E F I N I T I O N M E C H A N I S M */ +#include "nofloat.h" #include "nobitfield.h" #include "alloc.h" #include "Lpars.h" @@ -52,13 +53,13 @@ create_type(fund) struct type * construct_type(fund, tp, count) - struct type *tp; + register struct type *tp; arith count; /* for fund == ARRAY only */ { /* fund must be a type constructor: FIELD, FUNCTION, POINTER or ARRAY. The pointer to the constructed type is returned. */ - struct type *dtp; + register struct type *dtp; switch (fund) { #ifndef NOBITFIELD @@ -97,9 +98,9 @@ construct_type(fund, tp, count) struct type * function_of(tp) - struct type *tp; + register struct type *tp; { - struct type *dtp = tp->tp_function; + register struct type *dtp = tp->tp_function; if (!dtp) { tp->tp_function = dtp = create_type(FUNCTION); @@ -112,9 +113,9 @@ function_of(tp) struct type * pointer_to(tp) - struct type *tp; + register struct type *tp; { - struct type *dtp = tp->tp_pointer; + register struct type *dtp = tp->tp_pointer; if (!dtp) { tp->tp_pointer = dtp = create_type(POINTER); @@ -128,10 +129,10 @@ pointer_to(tp) struct type * array_of(tp, count) - struct type *tp; + register struct type *tp; arith count; { - struct type *dtp = tp->tp_array; + register struct type *dtp = tp->tp_array; /* look for a type with the right size */ while (dtp && dtp->tp_size != count) @@ -151,9 +152,9 @@ array_of(tp, count) #ifndef NOBITFIELD struct type * field_of(tp) - struct type *tp; + register struct type *tp; { - struct type *dtp = create_type(FIELD); + register struct type *dtp = create_type(FIELD); dtp->tp_up = tp; dtp->tp_align = tp->tp_align; @@ -177,7 +178,7 @@ size_of_type(tp, nm) } idf2type(idf, tpp) - struct idf *idf; + register struct idf *idf; struct type **tpp; { /* Decoding a typedef-ed identifier: if the size is yet diff --git a/lang/cem/cemcom/type.str b/lang/cem/cemcom/type.str index 837ebc85..13fad9db 100644 --- a/lang/cem/cemcom/type.str +++ b/lang/cem/cemcom/type.str @@ -1,7 +1,8 @@ /* $Header$ */ /* TYPE DESCRIPTOR */ -#include "nobitfield.h" +#include "nofloat.h" +#include "nobitfield.h" struct type { struct type *next; /* used only with ARRAY */ From 624c5a83c5d5f2c3bc9bb97b1d5a207b2875071b Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 25 Sep 1986 19:39:06 +0000 Subject: [PATCH 0269/1625] many bug fixes --- lang/m2/comp/LLlex.c | 358 ++++++++++++++++++--------------------- lang/m2/comp/LLlex.h | 10 +- lang/m2/comp/LLmessage.c | 3 +- lang/m2/comp/Makefile | 8 +- lang/m2/comp/Resolve | 43 +++++ lang/m2/comp/chk_expr.c | 62 ++++--- lang/m2/comp/class.h | 8 +- lang/m2/comp/code.c | 23 ++- lang/m2/comp/declar.g | 26 ++- lang/m2/comp/def.H | 2 + lang/m2/comp/def.c | 2 +- lang/m2/comp/desig.c | 17 +- lang/m2/comp/enter.c | 33 ++-- lang/m2/comp/lookup.c | 5 +- lang/m2/comp/options.c | 22 +-- lang/m2/comp/program.g | 1 - lang/m2/comp/scope.C | 15 +- lang/m2/comp/statement.g | 2 +- lang/m2/comp/type.H | 11 +- lang/m2/comp/type.c | 43 +++-- lang/m2/comp/walk.c | 184 ++++++++++++-------- 21 files changed, 480 insertions(+), 398 deletions(-) create mode 100755 lang/m2/comp/Resolve diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index 20d08b3b..d97afee1 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -25,10 +25,10 @@ static char *RcsId = "$Header$"; long str2long(); -struct token dot, aside; -struct type *toktype; -struct string string; -int idfsize = IDFSIZE; +struct token dot, + aside; +struct type *toktype; +int idfsize = IDFSIZE; #ifdef DEBUG extern int cntlines; #endif @@ -40,10 +40,9 @@ SkipComment() Note that comments may be nested (par. 3.5). */ register int ch; - register int NestLevel = 0; - LoadChar(ch); for (;;) { + LoadChar(ch); if (class(ch) == STNL) { LineNumber++; #ifdef DEBUG @@ -52,32 +51,26 @@ SkipComment() } else if (ch == '(') { LoadChar(ch); - if (ch == '*') ++NestLevel; - else continue; + if (ch == '*') SkipComment(); } else if (ch == '*') { LoadChar(ch); - if (ch == ')') { - if (NestLevel-- == 0) return; - } - else continue; + if (ch == ')') break; } - LoadChar(ch); } } -STATIC +STATIC struct string * GetString(upto) { /* Read a Modula-2 string, delimited by the character "upto". */ register int ch; - register struct string *str = &string; + register struct string *str = (struct string *) Malloc(sizeof(struct string)); register char *p; str->s_str = p = Malloc((unsigned int) (str->s_length = ISTRSIZE)); - LoadChar(ch); - while (ch != upto) { + while (LoadChar(ch), ch != upto) { if (class(ch) == STNL) { lexerror("newline in string"); LineNumber++; @@ -86,7 +79,7 @@ GetString(upto) #endif break; } - if (ch == EOI) { + if (ch == EOI) { lexerror("end-of-file in string"); break; } @@ -97,10 +90,10 @@ GetString(upto) p = str->s_str + str->s_length; str->s_length += RSTRSIZE; } - LoadChar(ch); } *p = '\0'; str->s_length = p - str->s_str; + return str; } int @@ -131,15 +124,15 @@ again: switch (class(ch)) { - case STSKIP: - goto again; - case STNL: LineNumber++; #ifdef DEBUG cntlines++; #endif tk->tk_lineno++; + /* Fall Through */ + + case STSKIP: goto again; case STGARB: @@ -172,15 +165,13 @@ again: if (nch == '.') { return tk->tk_symb = UPTO; } - PushBack(nch); - return tk->tk_symb = ch; + break; case ':': if (nch == '=') { return tk->tk_symb = BECOMES; } - PushBack(nch); - return tk->tk_symb = ch; + break; case '<': if (nch == '=') { @@ -190,50 +181,52 @@ again: lexwarning("'<>' is old-fashioned; use '#'"); return tk->tk_symb = '#'; } - PushBack(nch); - return tk->tk_symb = ch; + break; case '>': if (nch == '=') { return tk->tk_symb = GREATEREQUAL; } - PushBack(nch); - return tk->tk_symb = ch; + break; default : crash("(LLlex, STCOMP)"); } + PushBack(nch); + return tk->tk_symb = ch; case STIDF: { - register char *tg = &buf[0]; + register char *tag = &buf[0]; register struct idf *id; do { - if (tg - buf < idfsize) *tg++ = ch; + if (tag - buf < idfsize) *tag++ = ch; LoadChar(ch); } while(in_idf(ch)); if (ch != EOI) PushBack(ch); - *tg++ = '\0'; + *tag++ = '\0'; tk->TOK_IDF = id = str2idf(buf, 1); return tk->tk_symb = id->id_reserved ? id->id_reserved : IDENT; } - case STSTR: - GetString(ch); - if (string.s_length == 1) { - tk->TOK_INT = *(string.s_str) & 0377; + case STSTR: { + register struct string *str = GetString(ch); + + if (str->s_length == 1) { + tk->TOK_INT = *(str->s_str) & 0377; toktype = char_type; + free(str->s_str); + free((char *) str); } else { - tk->tk_data.tk_str = (struct string *) - Malloc(sizeof (struct string)); - *(tk->tk_data.tk_str) = string; - toktype = standard_type(T_STRING, 1, string.s_length); + tk->tk_data.tk_str = str; + toktype = standard_type(T_STRING, 1, str->s_length); } return tk->tk_symb = STRING; + } case STNUM: { @@ -241,172 +234,157 @@ again: is that we don't know the base in advance so we have to read the number with the help of a rather complex finite automaton. - Excuses for the very ugly code! */ + enum statetp {Oct,Hex,Dec,OctEndOrHex,End,OptReal,Real}; + register enum statetp state; + register int base; register char *np = &buf[1]; /* allow a '-' to be added */ buf[0] = '-'; *np++ = ch; - + state = is_oct(ch) ? Oct : Dec; LoadChar(ch); - while (is_oct(ch)) { - if (np < &buf[NUMSIZE]) { - *np++ = ch; - } - LoadChar(ch); - } - switch (ch) { - case 'H': -Shex: *np++ = '\0'; - tk->TOK_INT = str2long(&buf[1], 16); - if (tk->TOK_INT >= 0 && tk->TOK_INT <= max_int) { - toktype = intorcard_type; - } - else toktype = card_type; - return tk->tk_symb = INTEGER; - - case '8': - case '9': - do { - if (np < &buf[NUMSIZE]) { - *np++ = ch; + for (;;) { + switch(state) { + case Oct: + while (is_oct(ch)) { + if (np < &buf[NUMSIZE]) *np++ = ch; + LoadChar(ch); } - LoadChar(ch); - } while (is_dig(ch)); - - if (is_hex(ch)) - goto S2; - if (ch == 'H') - goto Shex; - if (ch == '.') - goto Sreal; - PushBack(ch); - goto Sdec; - - case 'B': - case 'C': - if (np < &buf[NUMSIZE]) { - *np++ = ch; - } - LoadChar(ch); - if (ch == 'H') - goto Shex; - if (is_hex(ch)) - goto S2; - PushBack(ch); - ch = *--np; - *np++ = '\0'; - tk->TOK_INT = str2long(&buf[1], 8); - if (ch == 'C') { - toktype = char_type; - if (tk->TOK_INT < 0 || tk->TOK_INT > 255) { -lexwarning("Character constant out of range"); + if (ch == 'B' || ch == 'C') { + base = 8; + state = OctEndOrHex; + break; } - } - else if (tk->TOK_INT >= 0 && tk->TOK_INT <= max_int) { - toktype = intorcard_type; - } - else toktype = card_type; - return tk->tk_symb = INTEGER; - - case 'A': - case 'D': - case 'E': - case 'F': -S2: - do { - if (np < &buf[NUMSIZE]) { - *np++ = ch; - } - LoadChar(ch); - } while (is_hex(ch)); - if (ch != 'H') { - lexerror("H expected after hex number"); - PushBack(ch); - } - goto Shex; - - case '.': -Sreal: - /* This '.' could be the first of the '..' - token. At this point, we need a look-ahead - of two characters. - */ - LoadChar(ch); - if (ch == '.') { - /* Indeed the '..' token - */ - PushBack(ch); - PushBack(ch); - goto Sdec; - } - - /* a real constant */ - if (np < &buf[NUMSIZE]) { - *np++ = '.'; - } - - if (is_dig(ch)) { - /* Fractional part - */ - do { + /* Fall Through */ + case Dec: + base = 10; + while (is_dig(ch)) { if (np < &buf[NUMSIZE]) { *np++ = ch; } LoadChar(ch); + } + if (is_hex(ch)) state = Hex; + else if (ch == '.') state = OptReal; + else { + state = End; + if (ch == 'H') base = 16; + else PushBack(ch); + } + break; + + case Hex: + while (is_hex(ch)) { + if (np < &buf[NUMSIZE]) *np++ = ch; + LoadChar(ch); + } + base = 16; + state = End; + if (ch != 'H') { + lexerror("H expected after hex number"); + PushBack(ch); + } + break; + + case OctEndOrHex: + if (np < &buf[NUMSIZE]) *np++ = ch; + LoadChar(ch); + if (ch == 'H') { + base = 16; + state = End; + break; + } + if (is_hex(ch)) { + state = Hex; + break; + } + PushBack(ch); + ch = *--np; + *np++ = '\0'; + base = 8; + /* Fall through */ + + case End: + *np++ = '\0'; + tk->TOK_INT = str2long(&buf[1], base); + if (ch == 'C' && base == 8) { + toktype = char_type; + if (tk->TOK_INT<0 || tk->TOK_INT>255) { +lexwarning("Character constant out of range"); + } + } + else if (tk->TOK_INT>=0 && + tk->TOK_INT<=max_int) { + toktype = intorcard_type; + } + else toktype = card_type; + return tk->tk_symb = INTEGER; + + case OptReal: + /* The '.' could be the first of the '..' + token. At this point, we need a + look-ahead of two characters. + */ + LoadChar(ch); + if (ch == '.') { + /* Indeed the '..' token + */ + PushBack(ch); + PushBack(ch); + state = End; + base = 10; + break; + } + state = Real; + break; + } + if (state == Real) break; + } + + /* a real real constant */ + if (np < &buf[NUMSIZE]) *np++ = '.'; + + while (is_dig(ch)) { + /* Fractional part + */ + if (np < &buf[NUMSIZE]) *np++ = ch; + LoadChar(ch); + } + + if (ch == 'E') { + /* Scale factor + */ + if (np < &buf[NUMSIZE]) *np++ = 'E'; + LoadChar(ch); + if (ch == '+' || ch == '-') { + /* Signed scalefactor + */ + if (np < &buf[NUMSIZE]) *np++ = ch; + LoadChar(ch); + } + if (is_dig(ch)) { + do { + if (np < &buf[NUMSIZE]) *np++ = ch; + LoadChar(ch); } while (is_dig(ch)); } - - if (ch == 'E') { - /* Scale factor - */ - if (np < &buf[NUMSIZE]) { - *np++ = 'E'; - } - LoadChar(ch); - if (ch == '+' || ch == '-') { - /* Signed scalefactor - */ - if (np < &buf[NUMSIZE]) { - *np++ = ch; - } - LoadChar(ch); - } - if (is_dig(ch)) { - do { - if (np < &buf[NUMSIZE]) { - *np++ = ch; - } - LoadChar(ch); - } while (is_dig(ch)); - } - else { - lexerror("bad scale factor"); - } + else { + lexerror("bad scale factor"); } - - PushBack(ch); - - if (np == &buf[NUMSIZE + 1]) { - tk->TOK_REL = Salloc("0.0", 5); - lexerror("floating constant too long"); - } - else tk->TOK_REL = Salloc(buf, np - buf) + 1; - toktype = real_type; - return tk->tk_symb = REAL; - - default: - PushBack(ch); -Sdec: - *np++ = '\0'; - tk->TOK_INT = str2long(&buf[1], 10); - if (tk->TOK_INT < 0 || tk->TOK_INT > max_int) { - toktype = card_type; - } - else toktype = intorcard_type; - return tk->tk_symb = INTEGER; } + + PushBack(ch); + + if (np >= &buf[NUMSIZE]) { + tk->TOK_REL = Salloc("0.0", 5); + lexerror("floating constant too long"); + } + else tk->TOK_REL = Salloc(buf, np - buf) + 1; + toktype = real_type; + return tk->tk_symb = REAL; + /*NOTREACHED*/ } diff --git a/lang/m2/comp/LLlex.h b/lang/m2/comp/LLlex.h index 8ba0bd94..16495e10 100644 --- a/lang/m2/comp/LLlex.h +++ b/lang/m2/comp/LLlex.h @@ -2,13 +2,17 @@ /* $Header$ */ +/* Structure to store a string constant +*/ struct string { - arith s_length; /* length of a string */ - char *s_str; /* the string itself */ + arith s_length; /* length of a string */ + char *s_str; /* the string itself */ }; +/* Token structure. Keep it small, as it is part of a parse-tree node +*/ struct token { - short tk_symb; /* token itself */ + short tk_symb; /* token itself */ unsigned short tk_lineno; /* linenumber on which it occurred */ union { struct idf *tk_idf; /* IDENT */ diff --git a/lang/m2/comp/LLmessage.c b/lang/m2/comp/LLmessage.c index ffb3d80b..3fabfbc6 100644 --- a/lang/m2/comp/LLmessage.c +++ b/lang/m2/comp/LLmessage.c @@ -20,12 +20,11 @@ static char *RcsId = "$Header$"; extern char *symbol2str(); extern struct idf *gen_anon_idf(); -int err_occurred = 0; +extern int err_occurred; LLmessage(tk) int tk; { - ++err_occurred; if (tk) { /* if (tk != 0), it represents the token to be inserted. otherwize, the current token is deleted diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index 25407363..02c58fe2 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -11,7 +11,7 @@ INCLUDES = -I$(MHDIR) -I$(EMDIR)/h -I$(PKGDIR) LSRC = tokenfile.g program.g declar.g expression.g statement.g CC = cc LLGENOPTIONS = -PROFILE = +PROFILE = CFLAGS = $(PROFILE) $(INCLUDES) -DSTATIC= LINTFLAGS = -DSTATIC= -DNORCSID LFLAGS = $(PROFILE) @@ -52,13 +52,13 @@ lint: Cfiles @rm -f nmclash.o a.out mkdep: mkdep.o - $(CC) -o mkdep mkdep.o + $(CC) $(LFLAGS) -o mkdep mkdep.o cclash: cclash.o - $(CC) -o cclash cclash.o + $(CC) $(LFLAGS) -o cclash cclash.o cid: cid.o - $(CC) -o cid cid.o + $(CC) $(LFLAGS) -o cid cid.o # entry points not to be used directly diff --git a/lang/m2/comp/Resolve b/lang/m2/comp/Resolve new file mode 100755 index 00000000..cabad11d --- /dev/null +++ b/lang/m2/comp/Resolve @@ -0,0 +1,43 @@ +case $# in +1) + ;; +*) echo "$0: one argument expected" 1>&2 + exit 1 + ;; +esac +case $1 in +main) + ;; +Xlint) + ;; +*) echo "$0: $1: Illegal argument" 1>&2 + exit 1 + ;; +esac +if test -d ../Xsrc +then + : +else mkdir ../Xsrc +fi +make cclash +make cid +./cclash -c -l7 `cat Cfiles` > clashes +sed '/^C_/d' < clashes > ../Xsrc/Xclashes +cd ../Xsrc +if cmp -s Xclashes clashes +then + : +else + mv Xclashes clashes +fi +rm -f Makefile +for i in `cat ../src/Cfiles` +do + cat >> Makefile < $i + +EOF +done +make `cat ../src/Cfiles` +make -f ../src/Makefile $1 diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index ae2571eb..981b9806 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -64,7 +64,7 @@ ChkArrow(expp) return 0; } - expp->nd_type = PointedtoType(tp); + expp->nd_type = RemoveEqual(PointedtoType(tp)); return 1; } @@ -106,7 +106,7 @@ ChkArr(expp) return 0; } - expp->nd_type = tpl->arr_elem; + expp->nd_type = RemoveEqual(tpl->arr_elem); return 1; } @@ -137,7 +137,7 @@ ChkLinkOrName(expp) if (expp->nd_class == Name) { expp->nd_def = lookfor(expp, CurrVis, 1); expp->nd_class = Def; - expp->nd_type = expp->nd_def->df_type; + expp->nd_type = RemoveEqual(expp->nd_def->df_type); } else if (expp->nd_class == Link) { register struct node *left = expp->nd_left; @@ -161,7 +161,7 @@ ChkLinkOrName(expp) } else { expp->nd_def = df; - expp->nd_type = df->df_type; + expp->nd_type = RemoveEqual(df->df_type); expp->nd_class = LinkDef; if (!(df->df_flags & (D_EXPORTED|D_QEXPORTED))) { /* Fields of a record are always D_QEXPORTED, @@ -418,19 +418,17 @@ getarg(argp, bases, designator) variable. */ struct type *tp; - register struct node *arg = *argp; + register struct node *arg = (*argp)->nd_right; register struct node *left; - if (! arg->nd_right) { - node_error(arg, "too few arguments supplied"); + if (! arg) { + node_error(*argp, "too few arguments supplied"); return 0; } - arg = arg->nd_right; left = arg->nd_left; - if ((!designator && !ChkExpression(left)) || - (designator && !ChkVariable(left))) { + if (designator ? !ChkVariable(left) : !ChkExpression(left)) { return 0; } @@ -438,11 +436,12 @@ getarg(argp, bases, designator) left->nd_def->df_flags |= D_NOREG; } - tp = BaseType(left->nd_type); - - if (bases && !(tp->tp_fund & bases)) { - node_error(arg, "unexpected type"); - return 0; + if (bases) { + tp = BaseType(left->nd_type); + if (!(tp->tp_fund & bases)) { + node_error(arg, "unexpected type"); + return 0; + } } *argp = arg; @@ -489,14 +488,14 @@ ChkProcCall(expp) left = expp->nd_left; arg = expp; - expp->nd_type = ResultType(left->nd_type); + expp->nd_type = RemoveEqual(ResultType(left->nd_type)); for (param = ParamList(left->nd_type); param; param = param->next) { if (!(left = getarg(&arg, 0, IsVarParam(param)))) return 0; if (left->nd_symb == STRING) { TryToString(left, TypeOfParam(param)); } - if (! TstParCompat(TypeOfParam(param), + if (! TstParCompat(RemoveEqual(TypeOfParam(param)), left->nd_type, IsVarParam(param), left)) { @@ -689,15 +688,29 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R } allowed = AllowedTypes(expp->nd_symb); - if (!(tpl->tp_fund & allowed) || - (tpl != bool_type && Boolean(expp->nd_symb))) { - if (!(tpl->tp_fund == T_POINTER && - (T_CARDINAL & allowed) && - ChkAddress(tpl, tpr))) { + + /* Check that the application of the operator is allowed on the type + of the operands. + There are two tricky parts: + - Boolean operators are only allowed on boolean operands, but + the "allowed-mask" of "AllowedTypes" can only indicate + an enumeration type. + - All operations that are allowed on CARDINALS are also allowed + on ADDRESS. + */ + if (Boolean(expp->nd_symb) && tpl != bool_type) { +node_error(expp,"operator \"%s\": illegal operand type(s)", symbol2str(expp->nd_symb)); + + return 0; + } + if (!(tpl->tp_fund & allowed)) { + if (!(tpl->tp_fund == T_POINTER && + (T_CARDINAL & allowed) && + ChkAddress(tpl, tpr))) { node_error(expp,"operator \"%s\": illegal operand type(s)", symbol2str(expp->nd_symb)); return 0; } - expp->nd_type = card_type; + if (expp->nd_type == card_type) expp->nd_type = address_type; } if (tpl->tp_fund == T_SET) { @@ -1058,6 +1071,9 @@ TryToString(nd, tp) { /* Try a coercion from character constant to string. */ + + assert(nd->nd_symb == STRING); + if (tp->tp_fund == T_ARRAY && nd->nd_type == char_type) { int ch = nd->nd_INT; diff --git a/lang/m2/comp/class.h b/lang/m2/comp/class.h index 72341981..5fb0f3d2 100644 --- a/lang/m2/comp/class.h +++ b/lang/m2/comp/class.h @@ -29,10 +29,10 @@ class. This is implemented as a collection of tables to speed up the decision whether a character has a special meaning. */ -#define in_idf(ch) (inidf[ch]) -#define is_oct(ch) (isoct[ch]) -#define is_dig(ch) (isdig[ch]) -#define is_hex(ch) (ishex[ch]) +#define in_idf(ch) ((unsigned)ch < 0177 && inidf[ch]) +#define is_oct(ch) ((unsigned)ch < 0177 && isoct[ch]) +#define is_dig(ch) ((unsigned)ch < 0177 && isdig[ch]) +#define is_hex(ch) ((unsigned)ch < 0177 && ishex[ch]) extern char tkclass[]; extern char inidf[], isoct[], isdig[], ishex[]; diff --git a/lang/m2/comp/code.c b/lang/m2/comp/code.c index acfeda5e..d70f2f3e 100644 --- a/lang/m2/comp/code.c +++ b/lang/m2/comp/code.c @@ -55,7 +55,7 @@ CodeString(nd) { label lab; - if (nd->nd_type == char_type) { + if (nd->nd_type->tp_fund != T_STRING) { C_loc(nd->nd_INT); } else { @@ -237,6 +237,7 @@ CodeCoercion(t1, t2) case T_CHAR: case T_CARDINAL: case T_POINTER: + case T_EQUAL: case T_INTORCARD: if (t2->tp_size > word_size) { C_loc(word_size); @@ -353,7 +354,7 @@ CodeParameters(param, arg) register struct type *tp; register struct node *left; register struct type *left_type; - + assert(param != 0 && arg != 0); if (param->next) { @@ -406,7 +407,7 @@ CodeParameters(param, arg) CodePadString(left, tp->tp_size); } else CodePExpr(left); - CheckAssign(left_type, tp); + RangeCheck(left_type, tp); } } @@ -451,7 +452,7 @@ CodeStd(nd) case S_CHR: CodePExpr(left); - CheckAssign(char_type, tp); + RangeCheck(char_type, tp); break; case S_FLOAT: @@ -489,7 +490,7 @@ CodeStd(nd) case S_VAL: CodePExpr(left); - CheckAssign(nd->nd_type, tp); + RangeCheck(nd->nd_type, tp); break; case S_ADR: @@ -510,7 +511,7 @@ CodeStd(nd) if (tp->tp_fund == T_INTEGER) C_adi(word_size); else C_adu(word_size); } - CheckAssign(tp, int_type); + RangeCheck(tp, int_type); } else { CodeCoercion(int_type, tp); @@ -576,7 +577,7 @@ CodeAssign(nd, dss, dst) C_blm(nd->nd_left->nd_type->tp_size); } -CheckAssign(tpl, tpr) +RangeCheck(tpl, tpr) register struct type *tpl, *tpr; { /* Generate a range check if neccessary @@ -634,6 +635,7 @@ CodeOper(expr, true_label, false_label) C_adf(tp->tp_size); break; case T_POINTER: + case T_EQUAL: case T_CARDINAL: case T_INTORCARD: C_adu(tp->tp_size); @@ -655,6 +657,7 @@ CodeOper(expr, true_label, false_label) C_sbf(tp->tp_size); break; case T_POINTER: + case T_EQUAL: case T_CARDINAL: case T_INTORCARD: C_sbu(tp->tp_size); @@ -674,6 +677,7 @@ CodeOper(expr, true_label, false_label) C_mli(tp->tp_size); break; case T_POINTER: + case T_EQUAL: case T_CARDINAL: case T_INTORCARD: C_mlu(tp->tp_size); @@ -708,6 +712,7 @@ CodeOper(expr, true_label, false_label) C_dvi(tp->tp_size); break; case T_POINTER: + case T_EQUAL: case T_CARDINAL: case T_INTORCARD: C_dvu(tp->tp_size); @@ -723,6 +728,7 @@ CodeOper(expr, true_label, false_label) C_rmi(tp->tp_size); break; case T_POINTER: + case T_EQUAL: case T_CARDINAL: case T_INTORCARD: C_rmu(tp->tp_size); @@ -744,8 +750,9 @@ CodeOper(expr, true_label, false_label) case T_INTEGER: C_cmi(tp->tp_size); break; - case T_HIDDEN: case T_POINTER: + case T_EQUAL: + case T_HIDDEN: case T_CARDINAL: case T_INTORCARD: C_cmu(tp->tp_size); diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index a9fdac97..167bcf99 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -31,7 +31,7 @@ int return_occurred; /* set if a return occurred in a ProcedureDeclaration { register struct def *df; - struct def *df1; + struct def *df1; /* only exists because &df is illegal */ } : { ++proclevel; return_occurred = 0; @@ -53,9 +53,10 @@ error("function procedure %s does not return a value", df->df_idf->id_text); ProcedureHeading(struct def **pdf; int type;) { struct paramlist *params = 0; - struct type *tp = 0; + register struct type *tp; + struct type *tp1 = 0; register struct def *df; - arith NBytesParams; + arith NBytesParams; /* parameter offset counter */ } : PROCEDURE IDENT { df = DeclProc(type); @@ -64,8 +65,8 @@ ProcedureHeading(struct def **pdf; int type;) } else NBytesParams = 0; } - FormalParameters(¶ms, &tp, &NBytesParams)? - { tp = construct_type(T_PROCEDURE, tp); + FormalParameters(¶ms, &tp1, &NBytesParams)? + { tp = construct_type(T_PROCEDURE, tp1); tp->prc_params = params; tp->prc_nbpar = NBytesParams; if (df->df_type) { @@ -151,7 +152,7 @@ TypeDeclaration struct def *df; struct type *tp; }: - IDENT { df = define(dot.TOK_IDF,CurrentScope,D_TYPE); } + IDENT { df = define(dot.TOK_IDF, CurrentScope, D_TYPE); } '=' type(&tp) { DeclareType(df, tp); } ; @@ -398,9 +399,7 @@ node_error(nd1,"type incompatibility in case label"); } ; -SetType(struct type **ptp;) -{ -} : +SetType(struct type **ptp;) : SET OF SimpleType(ptp) { *ptp = set_type(*ptp); } ; @@ -411,7 +410,6 @@ SetType(struct type **ptp;) */ PointerType(struct type **ptp;) { - register struct def *df; register struct node *nd; } : POINTER TO @@ -422,10 +420,9 @@ PointerType(struct type **ptp;) */ qualtype(&((*ptp)->next)) | %if ( nd = new_node(), nd->nd_token = dot, - df = lookfor(nd, CurrVis, 0), - df->df_kind == D_MODULE) + lookfor(nd, CurrVis, 0)->df_kind == D_MODULE) + { if (dot.tk_symb == IDENT) free_node(nd); } type(&((*ptp)->next)) - { free_node(nd); } | IDENT { Forward(nd, (*ptp)); } ] @@ -436,11 +433,10 @@ qualtype(struct type **ptp;) struct def *df; } : qualident(D_ISTYPE, &df, "type", (struct node **) 0) - { if (!df->df_type) { + { if (!(*ptp = df->df_type)) { error("type \"%s\" not declared", df->df_idf->id_text); *ptp = error_type; } - else *ptp = df->df_type; } ; diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H index 774fd798..56431ae6 100644 --- a/lang/m2/comp/def.H +++ b/lang/m2/comp/def.H @@ -113,6 +113,8 @@ struct def { /* list of definitions for a name */ } df_value; }; +#define SetUsed(df) ((df)->df_flags |= D_USED) + /* ALLOCDEF "def" */ extern struct def diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index 8c189150..04b43ebe 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -60,6 +60,7 @@ InitDef() struct idf *gen_anon_idf(); ill_df = MkDef(gen_anon_idf(), CurrentScope, D_ERROR); + ill_df->df_type = error_type; } struct def * @@ -204,7 +205,6 @@ DeclProc(type) sprint(buf,"%s_%s",CurrentScope->sc_name,df->df_idf->id_text); df->for_name = Salloc(buf, (unsigned) (strlen(buf)+1)); if (CurrVis == Defined->mod_vis) C_exp(df->for_name); - open_scope(OPENSCOPE); } else { df = lookup(dot.TOK_IDF, CurrentScope); diff --git a/lang/m2/comp/desig.c b/lang/m2/comp/desig.c index f33a589d..c9fca726 100644 --- a/lang/m2/comp/desig.c +++ b/lang/m2/comp/desig.c @@ -166,18 +166,17 @@ CodeFieldDesig(df, ds) in "ds". "df" indicates the definition of the field. */ - register struct withdesig *wds; if (ds->dsg_kind == DSG_INIT) { /* In a WITH statement. We must find the designator in the WITH statement, and act as if the field is a selection of this designator. So, first find the right WITH statement, which is the - first one of the proper record type. - Notice that the proper record type is recognized by its - scope indication. + first one of the proper record type, which is + recognized by its scope indication. */ - wds = WithDesigs; + register struct withdesig *wds = WithDesigs; + assert(wds != 0); while (wds->w_scope != df->df_scope) { @@ -225,7 +224,7 @@ CodeVarDesig(df, ds) */ assert(ds->dsg_kind == DSG_INIT); - df->df_flags |= D_USED; + SetUsed(df); if (df->var_addrgiven) { /* the programmer specified an address in the declaration of the variable. Generate code to push the address. @@ -258,7 +257,9 @@ CodeVarDesig(df, ds) C_lxa((arith) (proclevel - sc->sc_level)); if ((df->df_flags & D_VARPAR) || IsConformantArray(df->df_type)) { - /* var parameter + /* var parameter or conformant array. + For conformant array's, the address is + passed. */ C_adp(df->var_off); C_loi(pointer_size); @@ -297,7 +298,7 @@ CodeDesig(nd, ds) case Def: df = nd->nd_def; - df->df_flags |= D_USED; + SetUsed(df); switch(df->df_kind) { case D_FIELD: CodeFieldDesig(df, ds); diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index 2c9f8743..237ee29b 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -172,6 +172,7 @@ EnterParamList(ppr, Idlist, type, VARp, off) static struct paramlist *last; if (! idlist) { + /* Can only happen when a procedure type is defined */ dummy = Idlist = idlist = MkLeaf(Name, &dot); } for ( ; idlist; idlist = idlist->next) { @@ -182,7 +183,7 @@ EnterParamList(ppr, Idlist, type, VARp, off) } else last->next = pr; last = pr; - if (idlist != dummy) { + if (!DefinitionModule && idlist != dummy) { df = define(idlist->nd_IDF, CurrentScope, D_VARIABLE); df->var_off = *off; } @@ -222,22 +223,20 @@ DoImport(df, scope) if (df->df_kind == D_TYPE && df->df_type->tp_fund == T_ENUMERATION) { /* Also import all enumeration literals */ - df = df->df_type->enm_enums; - while (df) { + for (df = df->df_type->enm_enums; df; df = df->enm_next) { define(df->df_idf, scope, D_IMPORT)->imp_def = df; - df = df->enm_next; } } else if (df->df_kind == D_MODULE) { /* Also import all definitions that are exported from this module */ - df = df->mod_vis->sc_scope->sc_def; - while (df) { + for (df = df->mod_vis->sc_scope->sc_def; + df; + df = df->df_nextinscope) { if (df->df_flags & D_EXPORTED) { define(df->df_idf,scope,D_IMPORT)->imp_def = df; } - df = df->df_nextinscope; } } } @@ -337,18 +336,22 @@ idlist->nd_IDF->id_text); scope. There are two legal possibilities, which are examined below. */ - if ((df1->df_kind == D_PROCHEAD && - df->df_kind == D_PROCEDURE) || - (df1->df_kind == D_HIDDEN && - df->df_kind == D_TYPE)) { - if (df->df_kind == D_TYPE && - df->df_type->tp_fund != T_POINTER) { -node_error(idlist, "opaque type \"%s\" is not a pointer type", df->df_idf->id_text); - } + if (df1->df_kind == D_PROCHEAD && + df->df_kind == D_PROCEDURE) { df1->df_kind = D_IMPORT; df1->imp_def = df; continue; } + if (df1->df_kind == D_HIDDEN && + df->df_kind == D_TYPE) { + if (df->df_type->tp_fund != T_POINTER) { +node_error(idlist, "opaque type \"%s\" is not a pointer type", df->df_idf->id_text); + } + assert(df1->df_type->next == NULLTYPE); + df1->df_kind = D_TYPE; + df1->df_type->next = df->df_type; + continue; + } } DoImport(df, enclosing(CurrVis)->sc_scope); diff --git a/lang/m2/comp/lookup.c b/lang/m2/comp/lookup.c index d8b89ef6..a2785916 100644 --- a/lang/m2/comp/lookup.c +++ b/lang/m2/comp/lookup.c @@ -15,6 +15,7 @@ static char *RcsId = "$Header$"; #include "scope.h" #include "LLlex.h" #include "node.h" +#include "type.h" struct def * lookup(id, scope) @@ -73,5 +74,7 @@ lookfor(id, vis, give_error) if (give_error) id_not_declared(id); - return MkDef(id->nd_IDF, vis->sc_scope, D_ERROR); + df = MkDef(id->nd_IDF, vis->sc_scope, D_ERROR); + df->df_type = error_type; + return df; } diff --git a/lang/m2/comp/options.c b/lang/m2/comp/options.c index 25f16c90..69931fe3 100644 --- a/lang/m2/comp/options.c +++ b/lang/m2/comp/options.c @@ -24,10 +24,14 @@ DoOption(text) default: options[text[-1]]++; /* flags, debug options etc. */ break; + /* recognized flags: + -L: don't generate fil/lin + -p: generate procentry/procexit + -w: no warnings + -n: no register messages + and many more if DEBUG + */ - case 'L' : /* don't generate fil/lin */ - options['L'] = 1; - break; case 'M': /* maximum identifier length */ idfsize = txt2int(&text); @@ -37,10 +41,6 @@ DoOption(text) fatal("maximum identifier length is %d", IDFSIZE); break; - case 'p' : /* generate profiling code procentry/procexit ???? */ - options['p'] = 1; - break; - case 'I' : if (++ndirs >= NDIRS) { fatal("Too many -I options"); @@ -99,14 +99,6 @@ DoOption(text) } break; } - - case 'n': - options['n'] = 1; /* use no registers */ - break; - - case 'w': - options['w'] = 1; /* no warnings will be given */ - break; } } diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 0573fde3..993d53c3 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -193,7 +193,6 @@ definition VAR [ VariableDeclaration Semicolon ]* | ProcedureHeading(&dummy, D_PROCHEAD) - { close_scope(0); } Semicolon ; diff --git a/lang/m2/comp/scope.C b/lang/m2/comp/scope.C index 9962b67c..23959a2f 100644 --- a/lang/m2/comp/scope.C +++ b/lang/m2/comp/scope.C @@ -90,19 +90,6 @@ Forward(tk, ptp) CurrentScope->sc_forw = f; } -ChForward(was, becomes) - struct type *was, *becomes; -{ - /* The declaration of a hidden type had a forward reference. - In this case, the "forwards" list must be adapted. - */ - register struct forwards *f = CurrentScope->sc_forw; - - while (f && f->fo_ptyp != was) f = f->next; - assert(f != 0); - f->fo_ptyp = becomes; -} - STATIC chk_proc(df) register struct def *df; @@ -114,7 +101,7 @@ chk_proc(df) if (df->df_kind == D_PROCHEAD) { /* A not defined procedure */ -node_error(df->for_node, "procedure \"%s\" not defined", df->df_idf->id_text); +error("procedure \"%s\" not defined", df->df_idf->id_text); FreeNode(df->for_node); } df = df->df_nextinscope; diff --git a/lang/m2/comp/statement.g b/lang/m2/comp/statement.g index 6c45f898..c04b36bd 100644 --- a/lang/m2/comp/statement.g +++ b/lang/m2/comp/statement.g @@ -85,7 +85,7 @@ StatementSequence(register struct node **pnd;) struct node *nd; } : statement(pnd) - [ + [ %persistent ';' statement(&nd) { if (nd) { *pnd = MkNode(Link, *pnd, nd, &dot); diff --git a/lang/m2/comp/type.H b/lang/m2/comp/type.H index c20e7a15..68dc1666 100644 --- a/lang/m2/comp/type.H +++ b/lang/m2/comp/type.H @@ -52,14 +52,14 @@ struct proc { struct type { struct type *next; /* used with ARRAY, PROCEDURE, POINTER, SET, - SUBRANGE + SUBRANGE, EQUAL */ int tp_fund; /* fundamental type or constructor */ #define T_RECORD 0x0001 #define T_ENUMERATION 0x0002 #define T_INTEGER 0x0004 #define T_CARDINAL 0x0008 -/* #define T_LONGINT 0x0010 */ +#define T_EQUAL 0x0010 #define T_REAL 0x0020 #define T_HIDDEN 0x0040 #define T_POINTER 0x0080 @@ -129,7 +129,8 @@ struct type *construct_type(), *standard_type(), *set_type(), - *subr_type(); /* All from type.c */ + *subr_type(), + *RemoveEqual(); /* All from type.c */ #define NULLTYPE ((struct type *) 0) @@ -147,6 +148,6 @@ struct type (tpx)->next) #define PointedtoType(tpx) (assert((tpx)->tp_fund == T_POINTER),\ (tpx)->next) -#define BaseType(tpx) ((tpx)->tp_fund == T_SUBRANGE ? (tpx)->next\ - : (tpx)) +#define BaseType(tpx) ((tpx)->tp_fund == T_SUBRANGE ? (tpx)->next : \ + (tpx)) #define IsConstructed(tpx) ((tpx)->tp_fund & T_CONSTRUCTED) diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index c04f1931..41727ea7 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -224,6 +224,8 @@ chk_basesubrange(tp, base) /* A subrange had a specified base. Check that the bases conform. */ + assert(tp->tp_fund == T_SUBRANGE); + if (base->tp_fund == T_SUBRANGE) { /* Check that the bounds of "tp" fall within the range of "base". @@ -231,22 +233,22 @@ chk_basesubrange(tp, base) if (base->sub_lb > tp->sub_lb || base->sub_ub < tp->sub_ub) { error("Base type has insufficient range"); } - base = BaseType(base); + base = base->next; } if (base->tp_fund & (T_ENUMERATION|T_CHAR)) { - if (BaseType(tp) != base) { + if (tp->next != base) { error("Specified base does not conform"); } } else if (base != card_type && base != int_type) { error("Illegal base for a subrange"); } - else if (base == int_type && BaseType(tp) == card_type && + else if (base == int_type && tp->next == card_type && (tp->sub_ub > max_int || tp->sub_ub < 0)) { error("Upperbound to large for type INTEGER"); } - else if (base != BaseType(tp) && base != int_type) { + else if (base != tp->next && base != int_type) { error("Specified base does not conform"); } @@ -462,24 +464,31 @@ DeclareType(df, tp) */ if (df->df_type && df->df_type->tp_fund == T_HIDDEN) { - if (tp->tp_fund != T_POINTER) { + if (! (tp->tp_fund & (T_POINTER|T_HIDDEN|T_EQUAL))) { error("opaque type \"%s\" is not a pointer type", df->df_idf->id_text); } - /* Careful now ... we might have declarations - referring to the hidden type. - */ - *(df->df_type) = *tp; - if (! tp->next) { - /* It also contains a forward reference, - so update the forwardlist - */ - ChForward(tp, df->df_type); + df->df_type->next = tp; + df->df_type->tp_fund = T_EQUAL; + while (tp != df->df_type && tp->tp_fund == T_EQUAL) { + tp = tp->next; + } + if (tp == df->df_type) { + /* Circular definition! */ +error("opaque type \"%s\" has a circular definition", df->df_idf->id_text); } - free_type(tp); } else df->df_type = tp; } +struct type * +RemoveEqual(tpx) + register struct type *tpx; +{ + + if (tpx) while (tpx->tp_fund == T_EQUAL) tpx = tpx->next; + return tpx; +} + int gcd(m, n) register int m, n; @@ -532,6 +541,10 @@ DumpType(tp) print("CARDINAL"); break; case T_REAL: print("REAL"); break; + case T_HIDDEN: + print("HIDDEN"); break; + case T_EQUAL: + print("EQUAL"); break; case T_POINTER: print("POINTER"); break; case T_CHAR: diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index c6324938..098744df 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -38,6 +38,9 @@ static struct type *func_type; struct withdesig *WithDesigs; struct node *Modules; +#define NO_EXIT_LABEL ((label) 0) +#define RETURN_LABEL ((label) 1) + STATIC DoProfil() { @@ -59,6 +62,7 @@ WalkModule(module) { /* Walk through a module, and all its local definitions. Also generate code for its body. + This code is collected in an initialization routine. */ register struct scope *sc; struct scopelist *savevis = CurrVis; @@ -75,7 +79,7 @@ WalkModule(module) this module. */ sc->sc_off = 0; /* no locals (yet) */ - text_label = 1; + text_label = 1; /* label at end of initialization routine */ TmpOpen(sc); /* Initialize for temporaries */ C_pro_narg(sc->sc_name); DoProfil(); @@ -93,10 +97,12 @@ WalkModule(module) */ C_df_dlb(l1); C_bss_cst(word_size, (arith) 0, 1); + /* if this one is set to non-zero, the initialization + was already done. + */ C_loe_dlb(l1, (arith) 0); - C_zne((label) 1); - C_loc((arith) 1); - C_ste_dlb(l1, (arith) 0); + C_zne(RETURN_LABEL); + C_ine_dlb(l1, (arith) 0); /* Prevent this module from calling its own initialization routine */ @@ -111,8 +117,8 @@ WalkModule(module) MkCalls(sc->sc_def); proclevel++; DO_DEBUG(options['X'], PrNode(module->mod_body, 0)); - WalkNode(module->mod_body, (label) 0); - C_df_ilb((label) 1); + WalkNode(module->mod_body, NO_EXIT_LABEL); + C_df_ilb(RETURN_LABEL); C_ret((arith) 0); C_end(-sc->sc_off); proclevel--; @@ -132,8 +138,9 @@ WalkProcedure(procedure) register struct type *tp; register struct paramlist *param; label func_res_label = 0; - arith tmpvar1 = 0; + arith StackAdjustment = 0; arith retsav = 0; + arith func_res_size = 0; proclevel++; CurrVis = procedure->prc_vis; @@ -152,11 +159,19 @@ WalkProcedure(procedure) func_type = tp = ResultType(procedure->df_type); if (tp && IsConstructed(tp)) { + /* The result type of this procedure is constructed. + The actual procedure will return a pointer to a global + data area in which the function result is stored. + Notice that this does make the code non-reentrant. + Here, we create the data area for the function result. + */ func_res_label = ++data_label; C_df_dlb(func_res_label); C_bss_cst(tp->tp_size, (arith) 0, 0); } + if (tp) func_res_size = WA(tp->tp_size); + /* Generate calls to initialization routines of modules defined within this procedure */ @@ -192,22 +207,25 @@ WalkProcedure(procedure) */ arith tmpvar = NewInt(); - if (! tmpvar1) { + if (! StackAdjustment) { + /* First time we get here + */ if (tp && !func_res_label) { /* Some local space, only needed if the value itself is returned */ - sc->sc_off -= WA(tp->tp_size); + sc->sc_off -= func_res_size; retsav = sc->sc_off; } - tmpvar1 = NewInt(); + StackAdjustment = NewInt(); C_loc((arith) 0); - C_stl(tmpvar1); + C_stl(StackAdjustment); } - /* First compute the size */ + /* First compute the size of the array */ C_lol(param->par_def->var_off + pointer_size + word_size); + /* upper - lower */ C_inc(); /* gives number of elements */ C_loc(tp->arr_elem->tp_size); C_cal("_wa"); @@ -219,15 +237,22 @@ WalkProcedure(procedure) /* size in bytes */ C_stl(tmpvar); C_lol(tmpvar); - C_dup(word_size); - C_lol(tmpvar1); + C_lol(tmpvar); + C_lol(StackAdjustment); C_adi(word_size); - C_stl(tmpvar1); /* remember all stack adjustments */ + C_stl(StackAdjustment); + /* remember stack adjustments */ C_ngi(word_size); + /* Assumption: stack grows + downwards!! ??? + */ C_ass(word_size); /* adjusted stack pointer */ C_lor((arith) 1); - /* destination address */ + /* destination address (sp), + also assumes stack grows + downwards ??? + */ C_lal(param->par_def->var_off); C_loi(pointer_size); /* push source address */ @@ -237,7 +262,9 @@ WalkProcedure(procedure) C_bls(word_size); /* copy */ C_lor((arith) 1); - /* push new address of array */ + /* push new address of array + ... downwards ... ??? + */ C_lal(param->par_def->var_off); C_sti(pointer_size); FreeInt(tmpvar); @@ -245,41 +272,50 @@ WalkProcedure(procedure) } } - text_label = 1; + text_label = 1; /* label at end of procedure */ DO_DEBUG(options['X'], PrNode(procedure->prc_body, 0)); - WalkNode(procedure->prc_body, (label) 0); - C_df_ilb((label) 1); + WalkNode(procedure->prc_body, NO_EXIT_LABEL); + C_df_ilb(RETURN_LABEL); /* label at end */ tp = func_type; if (func_res_label) { + /* Fill the data area reserved for the function result + with the result + */ C_lae_dlb(func_res_label, (arith) 0); C_sti(tp->tp_size); - if (tmpvar1) { - C_lol(tmpvar1); + if (StackAdjustment) { + /* Remove copies of conformant arrays + */ + C_lol(StackAdjustment); C_ass(word_size); } C_lae_dlb(func_res_label, (arith) 0); C_ret(pointer_size); } else if (tp) { - if (tmpvar1) { + if (StackAdjustment) { + /* First save the function result in a safe place. + Then remove copies of conformant arrays, + and put function result back on the stack + */ C_lal(retsav); - C_sti(WA(tp->tp_size)); - C_lol(tmpvar1); + C_sti(func_res_size); + C_lol(StackAdjustment); C_ass(word_size); C_lal(retsav); - C_loi(WA(tp->tp_size)); + C_loi(func_res_size); } - C_ret(WA(tp->tp_size)); + C_ret(func_res_size); } else { - if (tmpvar1) { - C_lol(tmpvar1); + if (StackAdjustment) { + C_lol(StackAdjustment); C_ass(word_size); } C_ret((arith) 0); } - if (tmpvar1) FreeInt(tmpvar1); + if (StackAdjustment) FreeInt(StackAdjustment); if (! options['n']) RegisterMessages(sc->sc_def); C_end(-sc->sc_off); TmpClose(); @@ -293,20 +329,26 @@ WalkDef(df) /* Walk through a list of definitions */ - while (df) { - if (df->df_kind == D_MODULE) { + for ( ; df; df = df->df_nextinscope) { + switch(df->df_kind) { + case D_MODULE: WalkModule(df); - } - else if (df->df_kind == D_PROCEDURE) { + break; + case D_PROCEDURE: WalkProcedure(df); + break; + case D_VARIABLE: + if (!proclevel) { + C_df_dnam(df->var_name); + C_bss_cst( + WA(df->df_type->tp_size), + (arith) 0, 0); + } + break; + default: + /* nothing */ + ; } - else if (!proclevel && df->df_kind == D_VARIABLE) { - C_df_dnam(df->var_name); - C_bss_cst( - WA(df->df_type->tp_size), - (arith) 0, 0); - } - df = df->df_nextinscope; } } @@ -316,31 +358,28 @@ MkCalls(df) /* Generate calls to initialization routines of modules */ - while (df) { + for ( ; df; df = df->df_nextinscope) { if (df->df_kind == D_MODULE) { C_lxl((arith) 0); C_cal(df->mod_vis->sc_scope->sc_name); C_asp(pointer_size); } - df = df->df_nextinscope; } } -WalkLink(nd, lab) +WalkLink(nd, exit_label) register struct node *nd; - label lab; + label exit_label; { /* Walk node "nd", which is a link. - "lab" represents the label that must be jumped to on - encountering an EXIT statement. */ while (nd && nd->nd_class == Link) { /* statement list */ - WalkNode(nd->nd_left, lab); + WalkNode(nd->nd_left, exit_label); nd = nd->nd_right; } - WalkNode(nd, lab); + WalkNode(nd, exit_label); } WalkCall(nd) @@ -358,13 +397,11 @@ WalkCall(nd) } } -WalkStat(nd, lab) +WalkStat(nd, exit_label) struct node *nd; - label lab; + label exit_label; { /* Walk through a statement, generating code for it. - "lab" represents the label that must be jumped to on - encountering an EXIT statement. */ register struct node *left = nd->nd_left; register struct node *right = nd->nd_right; @@ -386,12 +423,12 @@ WalkStat(nd, lab) ExpectBool(left, l3, l1); assert(right->nd_symb == THEN); C_df_ilb(l3); - WalkNode(right->nd_left, lab); + WalkNode(right->nd_left, exit_label); if (right->nd_right) { /* ELSE part */ C_bra(l2); C_df_ilb(l1); - WalkNode(right->nd_right, lab); + WalkNode(right->nd_right, exit_label); C_df_ilb(l2); } else C_df_ilb(l1); @@ -399,7 +436,7 @@ WalkStat(nd, lab) } case CASE: - CaseCode(nd, lab); + CaseCode(nd, exit_label); break; case WHILE: @@ -411,7 +448,7 @@ WalkStat(nd, lab) C_df_ilb(l1); ExpectBool(left, l3, l2); C_df_ilb(l3); - WalkNode(right, lab); + WalkNode(right, exit_label); C_bra(l1); C_df_ilb(l2); break; @@ -423,7 +460,7 @@ WalkStat(nd, lab) l1 = ++text_label; l2 = ++text_label; C_df_ilb(l1); - WalkNode(left, lab); + WalkNode(left, exit_label); ExpectBool(right, l2, l1); C_df_ilb(l2); break; @@ -457,9 +494,9 @@ WalkStat(nd, lab) } C_bra(l1); C_df_ilb(l2); - CheckAssign(nd->nd_type, int_type); + RangeCheck(nd->nd_type, int_type); CodeDStore(nd); - WalkNode(right, lab); + WalkNode(right, exit_label); CodePExpr(nd); C_loc(left->nd_INT); C_adi(int_size); @@ -493,8 +530,7 @@ WalkStat(nd, lab) wds.w_scope = left->nd_type->rec_scope; CodeAddress(&ds); ds.dsg_kind = DSG_FIXED; - /* Create a designator structure for the - temporary. + /* Create a designator structure for the temporary. */ ds.dsg_offset = tmp = NewPtr(); ds.dsg_name = 0; @@ -505,7 +541,7 @@ WalkStat(nd, lab) link.sc_scope = wds.w_scope; link.next = CurrVis; CurrVis = &link; - WalkNode(right, lab); + WalkNode(right, exit_label); CurrVis = link.next; WithDesigs = wds.w_next; FreePtr(tmp); @@ -513,9 +549,9 @@ WalkStat(nd, lab) } case EXIT: - assert(lab != 0); + assert(exit_label != 0); - C_bra(lab); + C_bra(exit_label); break; case RETURN: @@ -529,7 +565,7 @@ WalkStat(nd, lab) node_error(right, "type incompatibility in RETURN statement"); } } - C_bra((label) 1); + C_bra(RETURN_LABEL); break; default: @@ -576,7 +612,7 @@ ExpectBool(nd, true_label, false_label) int WalkExpr(nd) - struct node *nd; + register struct node *nd; { /* Check an expression and generate code for it */ @@ -664,12 +700,15 @@ DoAssign(nd, left, right) struct node *nd; register struct node *left, *right; { - /* May we do it in this order (expression first) ??? */ + /* May we do it in this order (expression first) ??? + The reference manual sais nothing about it, but the book does: + it sais that the left hand side is evaluated first. + */ struct desig dsl, dsr; if (! ChkExpression(right)) return; if (! ChkVariable(left)) return; - TryToString(right, left->nd_type); + if (right->nd_symb == STRING) TryToString(right, left->nd_type); dsr = InitDesig; CodeExpr(right, &dsr, NO_LABEL, NO_LABEL); @@ -683,7 +722,7 @@ DoAssign(nd, left, right) } else { CodeValue(&dsr, right->nd_type->tp_size); - CheckAssign(left->nd_type, right->nd_type); + RangeCheck(left->nd_type, right->nd_type); } dsl = InitDesig; CodeDesig(left, &dsl); @@ -702,12 +741,11 @@ RegisterMessages(df) */ tp = BaseType(df->df_type); if ((df->df_flags & D_VARPAR) || - tp->tp_fund == T_POINTER) { + (tp->tp_fund & (T_POINTER|T_HIDDEN|T_EQUAL))) { C_ms_reg(df->var_off, pointer_size, reg_pointer, 0); } - else if ((tp->tp_fund & T_NUMERIC) && - tp->tp_size <= dword_size) { + else if (tp->tp_fund & T_NUMERIC) { C_ms_reg(df->var_off, tp->tp_size, tp->tp_fund == T_REAL ? From b1f511e1879ad7a16d84dfcddadf24522b9b696e Mon Sep 17 00:00:00 2001 From: dick Date: Sun, 28 Sep 1986 20:33:15 +0000 Subject: [PATCH 0270/1625] some very minor changes --- lang/cem/cemcom/arith.c | 19 +++++++++++-------- lang/cem/cemcom/declar.g | 2 +- lang/cem/cemcom/declarator.c | 4 ++-- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lang/cem/cemcom/arith.c b/lang/cem/cemcom/arith.c index 51382e41..bcf6047c 100644 --- a/lang/cem/cemcom/arith.c +++ b/lang/cem/cemcom/arith.c @@ -141,24 +141,27 @@ any2arith(expp, oper) case LONG: break; case ENUM: + /* test the admissibility of the operator */ if ( is_test_op(oper) || oper == '=' || oper == PARCOMMA || - oper == ',' || oper == ':' || - ( !options['R'] && - (is_arith_op(oper) || is_asgn_op(oper)) - ) - ) - {} + oper == ',' || oper == ':' + ) { + /* allowed by K & R */ + } + else + if (!options['R']) { + /* allowed by us */ + } else expr_warning(*expp, "%s on enum", symbol2str(oper)); int2int(expp, int_type); break; -#ifndef NOFLOAT +#ifndef NOFLOAT case FLOAT: float2float(expp, double_type); break; case DOUBLE: break; -#endif NOFLOAT +#endif NOFLOAT #ifndef NOBITFIELD case FIELD: field2arith(expp); diff --git a/lang/cem/cemcom/declar.g b/lang/cem/cemcom/declar.g index ac6535c9..71f8202a 100644 --- a/lang/cem/cemcom/declar.g +++ b/lang/cem/cemcom/declar.g @@ -208,7 +208,7 @@ arrayer(arith *sizep;) [ constant_expression(&expr) { - array_subscript(expr); + check_array_subscript(expr); *sizep = expr->VL_VALUE; free_expression(expr); } diff --git a/lang/cem/cemcom/declarator.c b/lang/cem/cemcom/declarator.c index ff79ab0a..f74705fb 100644 --- a/lang/cem/cemcom/declarator.c +++ b/lang/cem/cemcom/declarator.c @@ -89,7 +89,7 @@ reject_params(dc) } } -array_subscript(expr) +check_array_subscript(expr) register struct expr *expr; { arith size = expr->VL_VALUE; @@ -104,7 +104,7 @@ array_subscript(expr) expr->VL_VALUE = (arith)-1; } else - if (size & ~max_unsigned) { /* absolute ridiculous */ + if (size & ~max_unsigned) { /* absolutely ridiculous */ expr_error(expr, "overflow in array size"); expr->VL_VALUE = (arith)1; } From 803315bb42af0c553f71da84edaa5f13028cd4fa Mon Sep 17 00:00:00 2001 From: erikb Date: Mon, 29 Sep 1986 13:16:11 +0000 Subject: [PATCH 0271/1625] modified the treatment of op=, ++ and -- operators --- lang/cem/cemcom/LLlex.c | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/lang/cem/cemcom/LLlex.c b/lang/cem/cemcom/LLlex.c index 10780846..a9a8db8f 100644 --- a/lang/cem/cemcom/LLlex.c +++ b/lang/cem/cemcom/LLlex.c @@ -105,13 +105,8 @@ GetToken(ptok) again: /* rescan the input after an error or replacement */ LoadChar(ch); go_on: /* rescan, the following character has been read */ - /* The following test is made to strip off the nonascii's */ - if ((ch & 0200) && ch != EOI) { - /* this is the only user-error which causes the - process to stop abruptly. - */ + if ((ch & 0200) && ch != EOI) /* stop on non-ascii character */ fatal("non-ascii '\\%03o' read", ch & 0377); - } switch (class(ch)) { /* detect character class */ case STNL: /* newline, vertical space or formfeed */ LineNumber++; /* also at vs and ff */ @@ -150,8 +145,7 @@ go_on: /* rescan, the following character has been read */ case STSIMP: /* a simple character, no part of compound token*/ if (ch == '/') { /* probably the start of comment */ LoadChar(ch); - if (ch == '*') { - /* start of comment */ + if (ch == '*') { /* start of comment */ skipcomment(); goto again; } @@ -189,12 +183,8 @@ go_on: /* rescan, the following character has been read */ case '<': if (AccFileSpecifier) { PushBack(); /* pushback nch */ - ptok->tk_bts = - string_token( - "file specifier", - '>', - &(ptok->tk_len) - ); + ptok->tk_bts = string_token("file specifier", + '>', &(ptok->tk_len)); return ptok->tk_symb = FILESPECIFIER; } if (nch == '<') @@ -284,11 +274,10 @@ go_on: /* rescan, the following character has been read */ } #endif NOPP ptok->tk_symb = ( - idef->id_reserved ? - idef->id_reserved : - idef->id_def && idef->id_def->df_sc == TYPEDEF ? - TYPE_IDENTIFIER : - IDENTIFIER + idef->id_reserved ? idef->id_reserved + : idef->id_def && idef->id_def->df_sc == TYPEDEF ? + TYPE_IDENTIFIER + : IDENTIFIER ); return IDENTIFIER; } @@ -467,8 +456,7 @@ skipcomment() return; } LoadChar(c); - } - /* Last Character seen was '*' */ + } /* last Character seen was '*' */ LoadChar(c); } while (c != '/'); NoUnstack--; @@ -557,8 +545,8 @@ val_in_base(ch, base) register int ch; { return - is_dig(ch) ? ch - '0' : - base != 16 ? -1 : - is_hex(ch) ? (ch - 'a' + 10) & 017 : - -1; + is_dig(ch) ? ch - '0' + : base != 16 ? -1 + : is_hex(ch) ? (ch - 'a' + 10) & 017 + : -1; } From 974f71ab6e84bc6cdba2814edf178f3ec85a29ea Mon Sep 17 00:00:00 2001 From: erikb Date: Mon, 29 Sep 1986 14:01:34 +0000 Subject: [PATCH 0272/1625] modified the treatment of op=, ++ and -- operators --- lang/cem/cemcom/Makefile.erik | 3 +- lang/cem/cemcom/arith.c | 4 + lang/cem/cemcom/blocks.c | 88 ++++++- lang/cem/cemcom/ch7.c | 51 +--- lang/cem/cemcom/ch7bin.c | 28 +-- lang/cem/cemcom/code.c | 73 +++--- lang/cem/cemcom/declarator.c | 2 +- lang/cem/cemcom/domacro.c | 13 +- lang/cem/cemcom/eval.c | 453 ++++++++++++++-------------------- lang/cem/cemcom/expr.c | 65 ++--- lang/cem/cemcom/field.c | 32 +-- lang/cem/cemcom/idf.c | 69 ++---- lang/cem/cemcom/ival.c | 60 ++--- lang/cem/cemcom/replace.c | 15 +- lang/cem/cemcom/switch.c | 66 ++--- 15 files changed, 421 insertions(+), 601 deletions(-) diff --git a/lang/cem/cemcom/Makefile.erik b/lang/cem/cemcom/Makefile.erik index 8e7b76aa..4f1c3217 100644 --- a/lang/cem/cemcom/Makefile.erik +++ b/lang/cem/cemcom/Makefile.erik @@ -17,7 +17,8 @@ EMELIB = $(EM)/modules/lib/libeme.a STRLIB = $(EM)/modules/lib/libstr.a PRTLIB = $(EM)/modules/lib/libprint.a EMMESLIB = $(EM)/modules/lib/libem_mes.a -CH3LIB = $(EM)/modules/lib/libch3.a +#CH3LIB = $(EM)/modules/lib/libch3.a +CH3LIB = LIBS = $(CH3LIB) $(EMMESLIB) $(EMKLIB) $(PRTLIB) $(STRLIB) $(SYSLIB) ELIBS = $(CH3LIB) $(EMMESLIB) $(EMELIB) $(PRTLIB) $(STRLIB) $(SYSLIB) LIB_INCLUDES = $(EM)/modules/h diff --git a/lang/cem/cemcom/arith.c b/lang/cem/cemcom/arith.c index bcf6047c..c11ad70c 100644 --- a/lang/cem/cemcom/arith.c +++ b/lang/cem/cemcom/arith.c @@ -423,6 +423,10 @@ is_asgn_op(oper) case ANDAB: case ORAB: case XORAB: + case PLUSPLUS: + case POSTINCR: + case MINMIN: + case POSTDECR: return 1; default: return 0; diff --git a/lang/cem/cemcom/blocks.c b/lang/cem/cemcom/blocks.c index 3e4640d3..1d769939 100644 --- a/lang/cem/cemcom/blocks.c +++ b/lang/cem/cemcom/blocks.c @@ -1,10 +1,14 @@ /* $Header$ */ /* B L O C K S T O R I N G A N D L O A D I N G */ -#include -#include "arith.h" -#include "sizes.h" -#include "atw.h" +#include +#include "arith.h" +#include "sizes.h" +#include "atw.h" +#ifndef STB +#include "label.h" +#include "stack.h" +#endif STB /* Because EM does not support the loading and storing of objects having other sizes than word fragment and multiple, @@ -38,17 +42,33 @@ store_block(sz, al) arith sz; int al; { - /* Next condition contains Lots of Irritating Stupid Parentheses - */ if ( ((sz == al) && (word_align % al == 0)) || ( (sz % word_size == 0 || word_size % sz == 0) && (al % word_align == 0) ) - ) + ) /* Lots of Irritating Stupid Parentheses */ C_sti(sz); - else { + else { +#ifndef STB + arith src, dst, src_offs, dst_offs; + + /* allocate two pointer temporaries */ + src = tmp_pointer_var(&src_offs); + dst = tmp_pointer_var(&dst_offs); + + /* load the addresses */ + C_lal(dst); + C_sti(pointer_size); + C_lor((arith)1); /* push current sp */ + C_lal(src); + C_sti(pointer_size); + copy_loop(sz, src, dst); + C_asp(ATW(sz)); + free_tmp_var(dst_offs); + free_tmp_var(src_offs); +#else STB /* address of destination lies on the stack */ /* push address of first byte of block on stack onto @@ -60,6 +80,7 @@ store_block(sz, al) C_loc(sz); /* number of bytes to transfer */ C_cal("__stb"); /* call transfer routine */ C_asp(pointer_size + pointer_size + int_size + ATW(sz)); +#endif STB } } @@ -75,7 +96,23 @@ load_block(sz, al) if (al % word_align == 0) C_loi(esz); else { - /* do not try to understand this... */ +#ifndef STB + arith src, dst, src_offs, dst_offs; + + /* allocate two pointer temporaries */ + src = tmp_pointer_var(&src_offs); + dst = tmp_pointer_var(&dst_offs); + + C_lal(src); + C_sti(pointer_size); + C_asp(-esz); /* allocate stack block */ + C_lor((arith)1); /* push & of stack block as dst */ + C_lal(dst); + C_sti(pointer_size); + copy_loop(sz, src, dst); + free_tmp_var(dst_offs); + free_tmp_var(src_offs); +#else STB C_asp(-(esz - pointer_size)); /* allocate stack block */ C_lor((arith)1); /* push & of stack block as dst */ C_dup(pointer_size); /* fetch source address */ @@ -84,5 +121,38 @@ load_block(sz, al) C_loc(sz); /* # bytes to copy */ C_cal("__stb"); /* library copy routine */ C_asp(int_size + pointer_size + pointer_size); +#endif STB } } + +#ifndef STB +copy_loop(sz, src, dst) + arith sz, src, dst; +{ + /* generate inline byte-copy loop */ + label l_cont = text_label(), l_stop = text_label(); + + C_loc(sz); /* amount of bytes */ + C_df_ilb(l_cont); + C_dup(word_size); + C_zle(l_stop); + C_dec(); + C_lal(src); + C_loi(pointer_size); + C_dup(pointer_size); + C_adp((arith)1); + C_lal(src); + C_sti(pointer_size); + C_loi((arith)1); + C_lal(dst); + C_loi(pointer_size); + C_dup(pointer_size); + C_adp((arith)1); + C_lal(dst); + C_sti(pointer_size); + C_sti((arith)1); + C_bra(l_cont); + C_df_ilb(l_stop); + C_asp(word_size); +} +#endif STB diff --git a/lang/cem/cemcom/ch7.c b/lang/cem/cemcom/ch7.c index 1317571c..356497d2 100644 --- a/lang/cem/cemcom/ch7.c +++ b/lang/cem/cemcom/ch7.c @@ -121,11 +121,9 @@ ch7sel(expp, oper, idf) intexpr(sd->sd_offset, INT)); } } - else { - /* oper == ARROW */ + else /* oper == ARROW */ *expp = new_oper(sd->sd_type, *expp, oper, intexpr(sd->sd_offset, INT)); - } (*expp)->ex_lvalue = (sd->sd_type->tp_fund != ARRAY); } @@ -135,44 +133,7 @@ ch7incr(expp, oper) /* The monadic prefix/postfix incr/decr operator oper is applied to *expp. */ - arith addend; - struct expr *expr; - register int fund = (*expp)->ex_type->tp_fund; - - if (!(*expp)->ex_lvalue) { - expr_error(*expp, "no lvalue with %s", symbol2str(oper)); - return; - } - if (fund == ENUM) { - expr_warning(*expp, "%s on enum", symbol2str(oper)); - addend = (arith)1; - } - else - if (is_arith_type((*expp)->ex_type)) - addend = (arith)1; - else - if (fund == POINTER) - addend = size_of_type((*expp)->ex_type->tp_up, "object"); -#ifndef NOBITFIELD - else - if (fund == FIELD) - addend = (arith)1; -#endif NOBITFIELD - else { - expr_error(*expp, "%s on %s", - symbol2str(oper), - symbol2str((*expp)->ex_type->tp_fund) - ); - return; - } - expr = intexpr(addend, INT); - ch7cast(&expr, CAST, (*expp)->ex_type); -#ifndef NOBITFIELD - if (fund == FIELD) - *expp = new_oper((*expp)->ex_type->tp_up, *expp, oper, expr); - else -#endif NOBITFIELD - *expp = new_oper((*expp)->ex_type, *expp, oper, expr); + ch7asgn(expp, oper, intexpr((arith)1, INT)); } ch7cast(expp, oper, tp) @@ -293,10 +254,8 @@ ch7cast(expp, oper, tp) (*expp)->ex_type = tp; } else - if (oldtp->tp_fund == ERRONEOUS) { - /* we just won't look */ - (*expp)->ex_type = tp; /* brute force */ - } + if (oldtp->tp_fund == ERRONEOUS) /* we just won't look */ + (*expp)->ex_type = tp; /* brute force */ else if (oldtp->tp_size == tp->tp_size && oper == CAST) { expr_warning(*expp, "dubious conversion based on equal size"); @@ -365,7 +324,6 @@ ch7asgn(expp, oper, expr) else expr = extmp; } - #ifndef NOBITFIELD if (fund == FIELD) *expp = new_oper((*expp)->ex_type->tp_up, *expp, oper, expr); @@ -374,7 +332,6 @@ ch7asgn(expp, oper, expr) #else NOBITFIELD *expp = new_oper((*expp)->ex_type, *expp, oper, expr); #endif NOBITFIELD - (*expp)->OP_TYPE = tp; /* for EVAL() */ } diff --git a/lang/cem/cemcom/ch7bin.c b/lang/cem/cemcom/ch7bin.c index 848f14cf..484b1caf 100644 --- a/lang/cem/cemcom/ch7bin.c +++ b/lang/cem/cemcom/ch7bin.c @@ -82,16 +82,6 @@ ch7bin(expp, oper, expr) break; case '%': case MODAB: -/*** NB "not float" means "integral" !!! - fund = arithbalance(expp, oper, &expr); - if (fund == DOUBLE) { - expr_error(*expp, "floating operand to %s", - symbol2str(oper)); - erroneous2int(expp); - } - else - non_commutative_binop(expp, oper, expr); -***/ opnd2integral(expp, oper); opnd2integral(&expr, oper); fund = arithbalance(expp, oper, &expr); @@ -111,21 +101,19 @@ ch7bin(expp, oper, expr) non_commutative_binop(expp, oper, expr); break; case '+': - if (expr->ex_type->tp_fund == POINTER) { - /* swap operands */ + if (expr->ex_type->tp_fund == POINTER) { /* swap operands */ struct expr *etmp = expr; expr = *expp; *expp = etmp; } /*FALLTHROUGH*/ case PLUSAB: + case POSTINCR: + case PLUSPLUS: if ((*expp)->ex_type->tp_fund == POINTER) { pointer_arithmetic(expp, oper, &expr); - if ( expr->ex_type->tp_size != - (*expp)->ex_type->tp_size - ) { + if (expr->ex_type->tp_size != (*expp)->ex_type->tp_size) ch7cast(&expr, CAST, (*expp)->ex_type); - } pointer_binary(expp, oper, expr); } else { @@ -138,6 +126,8 @@ ch7bin(expp, oper, expr) break; case '-': case MINAB: + case POSTDECR: + case MINMIN: if ((*expp)->ex_type->tp_fund == POINTER) { if (expr->ex_type->tp_fund == POINTER) pntminuspnt(expp, oper, expr); @@ -231,13 +221,11 @@ ch7bin(expp, oper, expr) if ( is_struct_or_union((*expp)->ex_type->tp_fund) || is_struct_or_union(expr->ex_type->tp_fund) ) { - if ((*expp)->ex_type != expr->ex_type) { + if ((*expp)->ex_type != expr->ex_type) expr_error(*expp, "illegal balance"); - } } - else { + else relbalance(expp, oper, &expr); - } *expp = new_oper((*expp)->ex_type, *expp, oper, expr); break; case '?': diff --git a/lang/cem/cemcom/code.c b/lang/cem/cemcom/code.c index a5c245de..665dc38c 100644 --- a/lang/cem/cemcom/code.c +++ b/lang/cem/cemcom/code.c @@ -28,16 +28,15 @@ #include "atw.h" #include "assert.h" -static struct stmt_block *stmt_stack; - -char *symbol2str(); -#ifndef NOFLOAT -int fp_used; -#endif NOFLOAT label lab_count = 1; label datlab_count = 1; +#ifndef NOFLOAT +int fp_used; +#endif NOFLOAT + extern char options[]; +char *symbol2str(); init_code(dst_file) char *dst_file; @@ -112,16 +111,11 @@ prepend_scopes(dst_file) fatal("cannot create %s", dst_file ? dst_file : "stdout"); famous_first_words(); while (se != 0) { - register struct idf *idf = se->se_idf; - register struct def *def = idf->id_def; + register struct idf *id = se->se_idf; + register struct def *df = id->id_def; - if (def && - ( def->df_initialized || - def->df_used || - def->df_alloc - ) - ) - code_scope(idf->id_text, def); + if (df && (df->df_initialized || df->df_used || df->df_alloc)) + code_scope(id->id_text, df); se = se->next; } C_close(); @@ -198,7 +192,6 @@ begin_proc(name, def) /* to be called when entering a procedure */ } else func_res_label = 0; - /* Special arrangements if the function result doesn't fit in the function return area of the EM machine. The size of the function return area is implementation dependent. @@ -206,15 +199,12 @@ begin_proc(name, def) /* to be called when entering a procedure */ lab_count = (label) 1; return_label = text_label(); return_expr_occurred = 0; - if (options['p']) { /* profiling */ if (strcmp(last_fn_given, FileName) != 0) { /* previous function came from other file */ C_df_dlb(file_name_label = data_label()); - C_con_scon( - last_fn_given = FileName, - (arith)(strlen(FileName) + 1) - ); + C_con_scon(last_fn_given = FileName, + (arith)(strlen(FileName) + 1)); } /* enable debug trace of EM source */ C_fil_dlb(file_name_label, (arith)0); @@ -345,17 +335,14 @@ code_declaration(idf, expr, lvl, sc) } else if (lvl >= L_LOCAL) { /* local variable */ - /* they are STATIC, EXTERN, GLOBAL, IMPLICIT, AUTO or - REGISTER - */ + /* STATIC, EXTERN, GLOBAL, IMPLICIT, AUTO or REGISTER */ switch (def_sc) { case STATIC: /* they are handled on the spot and get an integer label in EM. */ C_df_dlb((label)def->df_address); - if (expr) { - /* there is an initialisation */ + if (expr) { /* there is an initialisation */ do_ival(&(def->df_type), expr); free_expression(expr); } @@ -364,8 +351,7 @@ code_declaration(idf, expr, lvl, sc) error("size of %s unknown", text); size = (arith)0; } - C_bss_cst(align(size, word_align), - (arith)0, 1); + C_bss_cst(align(size, word_align), (arith)0, 1); } break; case EXTERN: @@ -399,7 +385,6 @@ loc_init(expr, id) register struct type *tp = id->id_def->df_type; ASSERT(id->id_def->df_sc != STATIC); - /* automatic aggregates cannot be initialised. */ switch (tp->tp_fund) { case ARRAY: case STRUCT: @@ -408,7 +393,6 @@ loc_init(expr, id) free_expression(expr); return; } - if (ISCOMMA(expr)) { /* embraced: int i = {12}; */ if (options['R']) { if (ISCOMMA(expr->OP_LEFT)) /* int i = {{1}} */ @@ -463,14 +447,15 @@ formal_cvt(df) */ register struct type *tp = df->df_type; - if (tp->tp_size != int_size) - if (tp->tp_fund == CHAR || tp->tp_fund == SHORT) { - C_lol(df->df_address); - conversion(int_type, df->df_type); - C_lal(df->df_address); - C_sti(tp->tp_size); - df->df_register = REG_NONE; - } + if (tp->tp_size != int_size && + (tp->tp_fund == CHAR || tp->tp_fund == SHORT) + ) { + C_lol(df->df_address); + /* conversion(int_type, df->df_type); ??? */ + C_lal(df->df_address); + C_sti(tp->tp_size); + df->df_register = REG_NONE; + } } code_expr(expr, val, code, tlbl, flbl) @@ -478,8 +463,7 @@ code_expr(expr, val, code, tlbl, flbl) label tlbl, flbl; { /* code_expr() is the parser's interface to the expression code - generator. - If line number trace is wanted, it generates a + generator. If line number trace is wanted, it generates a lin instruction. EVAL() is called directly. */ if (options['p']) /* profiling */ @@ -493,6 +477,8 @@ code_expr(expr, val, code, tlbl, flbl) EM labels where a subsequent break or continue causes the program to jump to. */ +static struct stmt_block *stmt_stack; /* top of statement stack */ + /* code_break() generates EM code needed at the occurrence of "break": it generates a branch instruction to the break label of the innermost statement in which break has a meaning. @@ -504,11 +490,10 @@ code_break() { register struct stmt_block *stmt_block = stmt_stack; - if (stmt_block) { + if (stmt_block) C_bra(stmt_block->st_break); - return; - } - error("break not inside for, while, do or switch"); + else + error("break not inside for, while, do or switch"); } /* code_continue() generates EM code needed at the occurrence of diff --git a/lang/cem/cemcom/declarator.c b/lang/cem/cemcom/declarator.c index f74705fb..33bb4e8f 100644 --- a/lang/cem/cemcom/declarator.c +++ b/lang/cem/cemcom/declarator.c @@ -1,7 +1,7 @@ /* $Header$ */ /* D E C L A R A T O R M A N I P U L A T I O N */ -#include "botch_free.h" /* UF */ +#include "botch_free.h" #include "alloc.h" #include "arith.h" #include "type.h" diff --git a/lang/cem/cemcom/domacro.c b/lang/cem/cemcom/domacro.c index f215b5bb..b3d32151 100644 --- a/lang/cem/cemcom/domacro.c +++ b/lang/cem/cemcom/domacro.c @@ -17,7 +17,6 @@ #include "parbufsize.h" #include "textsize.h" #include "idfsize.h" - #include "assert.h" #include "alloc.h" #include "class.h" @@ -301,14 +300,10 @@ PRIVATE do_elif() { if (nestlevel < 0 || (ifstack[nestlevel])) { - /* invalid elif encountered.. */ lexerror("#elif without corresponding #if"); SkipRestOfLine(); } - else { - /* restart at this level as if a #if - is detected. - */ + else { /* restart at this level as if a #if is detected. */ nestlevel--; push_if(); skip_block(); @@ -377,8 +372,7 @@ do_undef() if (id && id->id_macro) { /* forget the macro */ free_macro(id->id_macro); id->id_macro = (struct macro *) 0; - } - /* else: don't complain */ + } /* else: don't complain */ } else lexerror("illegal #undef construction"); @@ -470,8 +464,7 @@ macro_def(id, text, nformals, length, flags) if (macroeq(newdef->mc_text, text)) return; lexwarning("redefine \"%s\"", id->id_text); - } - /* else: overwrite pre-definition */ + } /* else: overwrite pre-definition */ } else id->id_macro = newdef = new_macro(); diff --git a/lang/cem/cemcom/eval.c b/lang/cem/cemcom/eval.c index 4923c857..7a08dbcc 100644 --- a/lang/cem/cemcom/eval.c +++ b/lang/cem/cemcom/eval.c @@ -1,17 +1,6 @@ /* $Header$ */ /* EXPRESSION-CODE GENERATOR */ -/* main functions : - EVAL() -- expression tree evaluator - tmp_pointer_var() -- deliver temporary pointer variable - free_tmp_var() -- return the pointer var - store_val() -- store primary expression - load_val() -- load primary expression - auxiliary functions: - assop() - compare() -*/ - #include "nofloat.h" #include #include "debug.h" @@ -40,45 +29,40 @@ char *symbol2str(); char *long2str(); arith tmp_pointer_var(); -/* EVAL() serves as the main expression tree evaluator, which turns - any legal expression tree into legal EM code. - The parameters describe how EVAL should treat the expression tree: +/* EVAL() is the main expression-tree evaluator, which turns + any legal expression tree into EM code. Parameters: - struct expr *expr: pointer to root of the expression tree to - be evaluated + struct expr *expr + pointer to root of the expression tree to be evaluated - int val: indicates whether the resulting expression - is to be dereferenced (if val == RVAL and - expr->ex_lvalue == 1) or not (val == LVAL). - The latter case indicates that the resulting - expression is an lvalue expression which should - not be dereferenced by EVAL + int val + indicates whether the resulting expression is to be + dereferenced (if val == RVAL and expr->ex_lvalue == 1) + or not (val == LVAL). The latter case indicates that + the resulting expression is an lvalue expression which + should not be dereferenced by EVAL - int code: indicates whether the expression tree must be - turned into EM code or not. E.g. the expression - statement "12;" delivers the expression "12" to - EVAL while this should not result in any EM - code + int code + indicates whether the expression tree must be turned + into EM code or not. E.g. the expression statement "12;" + delivers the expression "12" to EVAL while this should + not result in any EM code - label false_label: - label true_label: if the expression is a logical or relational - expression and if the loop of the program - depends on the resulting value then EVAL - generates jumps to the specified program - labels, in case they are specified - (i.e. are non-zero) + label false_label, label true_label + if the expression is a logical or relational expression + and if the loop of the program depends on the resulting + value then EVAL generates jumps to the specified program + labels, in case they are specified (i.e. are non-zero) */ EVAL(expr, val, code, true_label, false_label) - register struct expr *expr; /* the expression tree itself */ - int val; /* either RVAL or LVAL */ - int code; /* generate explicit code or not */ - label true_label; - label false_label; /* labels to jump to in logical expr's */ + register struct expr *expr; + int val, code; + label true_label, false_label; { register int gencode = (code == TRUE); - switch (expr->ex_class) { + switch (expr->ex_class) { case Value: /* just a simple value */ if (gencode) load_val(expr, val); @@ -107,23 +91,22 @@ EVAL(expr, val, code, true_label, false_label) case Oper: /* compound expression */ { int oper = expr->OP_OPER; - register struct expr *leftop = expr->OP_LEFT; - register struct expr *rightop = expr->OP_RIGHT; + register struct expr *left = expr->OP_LEFT; + register struct expr *right = expr->OP_RIGHT; register struct type *tp = expr->OP_TYPE; if (tp->tp_fund == ERRONEOUS) /* stop immediately */ break; - switch (oper) { + switch (oper) { case '+': /* We have the following possibilities : int + int, pointer + int, pointer + long, long + long, double + double */ - EVAL(leftop, RVAL, code, NO_LABEL, NO_LABEL); - EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); - + EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); if (gencode) { - switch (tp->tp_fund) { + switch (tp->tp_fund) { case INT: case LONG: if (tp->tp_unsigned) @@ -132,7 +115,7 @@ EVAL(expr, val, code, true_label, false_label) C_adi(tp->tp_size); break; case POINTER: - C_ads(rightop->ex_type->tp_size); + C_ads(right->ex_type->tp_size); break; #ifndef NOFLOAT case DOUBLE: @@ -145,10 +128,10 @@ EVAL(expr, val, code, true_label, false_label) } break; case '-': - if (leftop == 0) { /* unary */ - EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); + if (left == 0) { /* unary */ + EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); if (gencode) { - switch (tp->tp_fund) { + switch (tp->tp_fund) { case INT: case LONG: case POINTER: @@ -165,16 +148,15 @@ EVAL(expr, val, code, true_label, false_label) } break; } - /* Binary: we have the following flavours: + /* else binary; we have the following flavours: int - int, pointer - int, pointer - long, pointer - pointer, long - long, double - double */ - EVAL(leftop, RVAL, code, NO_LABEL, NO_LABEL); - EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); - + EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); if (!gencode) break; - switch (tp->tp_fund) { + switch (tp->tp_fund) { case INT: case LONG: if (tp->tp_unsigned) @@ -183,11 +165,11 @@ EVAL(expr, val, code, true_label, false_label) C_sbi(tp->tp_size); break; case POINTER: - if (rightop->ex_type->tp_fund == POINTER) + if (right->ex_type->tp_fund == POINTER) C_sbs(pointer_size); - else { - C_ngi(rightop->ex_type->tp_size); - C_ads(rightop->ex_type->tp_size); + else { + C_ngi(right->ex_type->tp_size); + C_ads(right->ex_type->tp_size); } break; #ifndef NOFLOAT @@ -200,13 +182,13 @@ EVAL(expr, val, code, true_label, false_label) } break; case '*': - if (leftop == 0) /* unary */ - EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); - else { /* binary */ - EVAL(leftop, RVAL, code, NO_LABEL, NO_LABEL); - EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); + if (left == 0) /* unary */ + EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); + else { /* binary */ + EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); if (gencode) - switch (tp->tp_fund) { + switch (tp->tp_fund) { case INT: case LONG: case POINTER: @@ -226,10 +208,10 @@ EVAL(expr, val, code, true_label, false_label) } break; case '/': - EVAL(leftop, RVAL, code, NO_LABEL, NO_LABEL); - EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); if (gencode) - switch (tp->tp_fund) { + switch (tp->tp_fund) { case INT: case LONG: case POINTER: @@ -248,8 +230,8 @@ EVAL(expr, val, code, true_label, false_label) } break; case '%': - EVAL(leftop, RVAL, code, NO_LABEL, NO_LABEL); - EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); ASSERT(tp->tp_fund==INT || tp->tp_fund==LONG); if (gencode) if (tp->tp_unsigned) @@ -258,8 +240,8 @@ EVAL(expr, val, code, true_label, false_label) C_rmi(tp->tp_size); break; case LEFT: - EVAL(leftop, RVAL, code, NO_LABEL, NO_LABEL); - EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); if (gencode) if (tp->tp_unsigned) C_slu(tp->tp_size); @@ -267,8 +249,8 @@ EVAL(expr, val, code, true_label, false_label) C_sli(tp->tp_size); break; case RIGHT: - EVAL(leftop, RVAL, code, NO_LABEL, NO_LABEL); - EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); if (gencode) if (tp->tp_unsigned) C_sru(tp->tp_size); @@ -281,16 +263,16 @@ EVAL(expr, val, code, true_label, false_label) case GREATEREQ: case EQUAL: case NOTEQUAL: - EVAL(leftop, RVAL, code, NO_LABEL, NO_LABEL); - EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); if (gencode) { /* The operands have the same type */ - arith size = leftop->ex_type->tp_size; + arith size = left->ex_type->tp_size; - switch (tp->tp_fund) { + switch (tp->tp_fund) { case INT: case LONG: - if (leftop->ex_type->tp_unsigned) + if (left->ex_type->tp_unsigned) C_cmu(size); else C_cmi(size); @@ -310,11 +292,11 @@ EVAL(expr, val, code, true_label, false_label) default: CRASH(); } - if (true_label != 0) { + if (true_label != 0) { compare(oper, true_label); C_bra(false_label); } - else { + else { label l_true = text_label(); label l_end = text_label(); @@ -331,14 +313,14 @@ EVAL(expr, val, code, true_label, false_label) case '|': case '^': /* both operands should have type int */ - EVAL(leftop, RVAL, code, NO_LABEL, NO_LABEL); - EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); if (gencode) { arith size = tp->tp_size; if (size < word_size) size = word_size; - switch (oper) { + switch (oper) { case '&': C_and(size); break; @@ -353,26 +335,21 @@ EVAL(expr, val, code, true_label, false_label) break; case '=': #ifndef NOBITFIELD - if (leftop->ex_type->tp_fund == FIELD) { - /* assignment to bitfield variable - */ + if (left->ex_type->tp_fund == FIELD) { eval_field(expr, code); break; } #endif NOBITFIELD - EVAL(rightop, RVAL, TRUE, NO_LABEL, NO_LABEL); + EVAL(right, RVAL, TRUE, NO_LABEL, NO_LABEL); if (gencode) C_dup(ATW(tp->tp_size)); - - if (leftop->ex_class != Value) { - EVAL(leftop, LVAL, TRUE, NO_LABEL, NO_LABEL); + if (left->ex_class != Value) { + EVAL(left, LVAL, TRUE, NO_LABEL, NO_LABEL); store_block(tp->tp_size, tp->tp_align); } else - store_val( - &(leftop->ex_object.ex_value), - leftop->ex_type - ); + store_val(&(left->ex_object.ex_value), + left->ex_type); break; case PLUSAB: case MINAB: @@ -384,47 +361,60 @@ EVAL(expr, val, code, true_label, false_label) case ANDAB: case XORAB: case ORAB: + case POSTINCR: + case POSTDECR: + case PLUSPLUS: + case MINMIN: { - arith old_offset; - arith tmpvar = tmp_pointer_var(&old_offset); - + arith old_offset, tmp; + int compl; /* Complexity of left operand */ #ifndef NOBITFIELD - if (leftop->ex_type->tp_fund == FIELD) { + if (left->ex_type->tp_fund == FIELD) { eval_field(expr, code); break; } #endif NOBITFIELD - if (leftop->ex_class != Value) { - EVAL(leftop, LVAL, TRUE, NO_LABEL, NO_LABEL); - C_lal(tmpvar); - C_sti(pointer_size); - C_lal(tmpvar); - C_loi(pointer_size); - C_loi(leftop->ex_type->tp_size); + if (left->ex_class == Value) { + compl = 0; /* Value */ + load_val(left, RVAL); } - else { - load_val(leftop, RVAL); - } - conversion(leftop->ex_type, tp); - EVAL(rightop, RVAL, TRUE, NO_LABEL, NO_LABEL); - assop(tp, oper); - conversion(tp, leftop->ex_type); - if (gencode) - C_dup(toword(leftop->ex_type->tp_size)); - if (leftop->ex_class != Value) { - C_lal(tmpvar); - C_loi(pointer_size); - C_sti(leftop->ex_type->tp_size); - free_tmp_var(old_offset); + else + if (left->ex_depth == 1 && left->OP_OPER == ARROW) { + compl = 1; /* Value->sel */ + ASSERT(left->OP_LEFT->ex_class == Value); + EVAL(left, RVAL, TRUE, NO_LABEL, NO_LABEL); } else { - store_val( - &(leftop->ex_object.ex_value), - leftop->ex_type - ); + compl = 2; /* otherwise */ + tmp = tmp_pointer_var(&old_offset); + EVAL(left, LVAL, TRUE, NO_LABEL, NO_LABEL); + C_dup(pointer_size); + C_lal(tmp); + C_sti(pointer_size); + C_loi(left->ex_type->tp_size); + } + conversion(left->ex_type, tp); + if (gencode && (oper == POSTINCR || oper == POSTDECR)) + C_dup(tp->tp_size); + EVAL(right, RVAL, TRUE, NO_LABEL, NO_LABEL); + assop(tp, oper); + if (gencode && oper != POSTINCR && oper != POSTDECR) + C_dup(tp->tp_size); + conversion(tp, left->ex_type); + if (compl == 0) + store_val(&(left->ex_object.ex_value), + left->ex_type); + else + if (compl == 1) { + EVAL(left, LVAL, TRUE, NO_LABEL, NO_LABEL); + C_sti(left->ex_type->tp_size); + } + else { + C_lal(tmp); /* always init'd */ + C_loi(pointer_size); + C_sti(left->ex_type->tp_size); + free_tmp_var(old_offset); } - if (gencode) - conversion(leftop->ex_type, expr->ex_type); break; } case '(': @@ -432,7 +422,7 @@ EVAL(expr, val, code, true_label, false_label) register struct expr *ex; arith ParSize = (arith)0; - if ((ex = rightop) != NILEXPR) { + if ((ex = right) != NILEXPR) { /* function call with parameters*/ while ( ex->ex_class == Oper && ex->OP_OPER == PARCOMMA @@ -445,24 +435,19 @@ EVAL(expr, val, code, true_label, false_label) EVAL(ex, RVAL, TRUE, NO_LABEL, NO_LABEL); ParSize += ATW(ex->ex_type->tp_size); } - if ( leftop->ex_class == Value - && leftop->VL_CLASS == Name - ) { - /* just an example: - main() { (*((int (*)())0))(); } - */ - C_cal(leftop->VL_IDF->id_text); + if (left->ex_class == Value && left->VL_CLASS == Name) { + /* e.g., main() { (*((int (*)())0))(); } */ + C_cal(left->VL_IDF->id_text); #ifdef DATAFLOW { extern char options[]; if (options['d']) DfaCallFunction( - leftop->VL_IDF->id_text - ); + left->VL_IDF->id_text); } #endif DATAFLOW } - else { - EVAL(leftop, LVAL, TRUE, NO_LABEL, NO_LABEL); + else { + EVAL(left, LVAL, TRUE, NO_LABEL, NO_LABEL); C_cai(); } /* remove parameters from stack */ @@ -479,124 +464,53 @@ EVAL(expr, val, code, true_label, false_label) break; } case '.': - EVAL(leftop, LVAL, code, NO_LABEL, NO_LABEL); - ASSERT(is_cp_cst(rightop)); + EVAL(left, LVAL, code, NO_LABEL, NO_LABEL); + ASSERT(is_cp_cst(right)); if (gencode) - C_adp(rightop->VL_VALUE); + C_adp(right->VL_VALUE); break; case ARROW: - EVAL(leftop, RVAL, code, NO_LABEL, NO_LABEL); - ASSERT(is_cp_cst(rightop)); + EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); + ASSERT(is_cp_cst(right)); if (gencode) - C_adp(rightop->VL_VALUE); + C_adp(right->VL_VALUE); break; case ',': - EVAL(leftop, RVAL, FALSE, NO_LABEL, NO_LABEL); - EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(left, RVAL, FALSE, NO_LABEL, NO_LABEL); + EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); break; case '~': - EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); if (gencode) C_com(tp->tp_size); break; - case POSTINCR: - case POSTDECR: - case PLUSPLUS: - case MINMIN: - { - arith old_offset, tmp; - arith esize = tp->tp_size; - int compl; /* Complexity of left operand */ -#ifndef NOBITFIELD - if (leftop->ex_type->tp_fund == FIELD) { - eval_field(expr, code); - break; - } -#endif NOBITFIELD - if (leftop->ex_class == Value) { - compl = 0; /* Value */ - load_val(leftop, RVAL); - } - else - if (leftop->ex_depth == 1 && leftop->OP_OPER == ARROW) { - compl = 1; /* Value->sel */ - ASSERT(leftop->OP_LEFT->ex_class == Value); - EVAL(leftop, RVAL, TRUE, NO_LABEL, NO_LABEL); - } - else { - compl = 2; /* otherwise */ - tmp = tmp_pointer_var(&old_offset); - EVAL(leftop, LVAL, TRUE, NO_LABEL, NO_LABEL); - C_dup(pointer_size); - C_lal(tmp); - C_sti(pointer_size); - C_loi(esize); - } - - /* We made the choice to put this stuff here - and not to put the conversion in the expression - tree because this conversion is EM dependent - and not described in C - */ - if (esize < word_size) { - conversion(tp, word_type); - esize = word_size; - } - - if (gencode && (oper == POSTINCR || oper == POSTDECR)) - C_dup(esize); - EVAL(rightop, RVAL, TRUE, NO_LABEL, NO_LABEL); - assop(tp, oper); - if (gencode && (oper == PLUSPLUS || oper == MINMIN)) - C_dup(esize); - if (tp->tp_size < word_size) - conversion(word_type, tp); - if (compl == 0) { - store_val( - &(leftop->ex_object.ex_value), - leftop->ex_type - ); - } - else - if (compl == 1) { - EVAL(leftop, LVAL, TRUE, NO_LABEL, NO_LABEL); - C_sti(tp->tp_size); - } - else { - C_lal(tmp); /* always init'd */ - C_loi(pointer_size); - C_sti(tp->tp_size); - free_tmp_var(old_offset); - } - break; - } case '?': /* must be followed by ':' */ { label l_true = text_label(); label l_false = text_label(); label l_end = text_label(); - EVAL(leftop, RVAL, TRUE, l_true, l_false); + EVAL(left, RVAL, TRUE, l_true, l_false); C_df_ilb(l_true); - EVAL(rightop->OP_LEFT, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(right->OP_LEFT, RVAL, code, NO_LABEL, NO_LABEL); C_bra(l_end); C_df_ilb(l_false); - EVAL(rightop->OP_RIGHT, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(right->OP_RIGHT, RVAL, code, NO_LABEL, NO_LABEL); C_df_ilb(l_end); break; } case AND: - if (true_label == 0) { + if (true_label == 0) { label l_true = text_label(); label l_false = text_label(); label l_maybe = text_label(); label l_end = text_label(); - EVAL(leftop, RVAL, TRUE, l_maybe, l_false); + EVAL(left, RVAL, TRUE, l_maybe, l_false); C_df_ilb(l_maybe); - if (gencode) { - EVAL(rightop, RVAL, TRUE, - l_true, l_false); + if (gencode) { + EVAL(right, RVAL, TRUE, l_true, + l_false); C_df_ilb(l_true); C_loc((arith)1); C_bra(l_end); @@ -605,32 +519,32 @@ EVAL(expr, val, code, true_label, false_label) C_df_ilb(l_end); } else { - EVAL(rightop, RVAL, FALSE, l_false, + EVAL(right, RVAL, FALSE, l_false, l_false); C_df_ilb(l_false); } } - else { + else { label l_maybe = text_label(); - EVAL(leftop, RVAL, TRUE, l_maybe, false_label); + EVAL(left, RVAL, TRUE, l_maybe, false_label); C_df_ilb(l_maybe); - EVAL(rightop, RVAL, code, true_label, + EVAL(right, RVAL, code, true_label, false_label); } break; case OR: - if (true_label == 0) { + if (true_label == 0) { label l_true = text_label(); label l_false = text_label(); label l_maybe = text_label(); label l_end = text_label(); - EVAL(leftop, RVAL, TRUE, l_true, l_maybe); + EVAL(left, RVAL, TRUE, l_true, l_maybe); C_df_ilb(l_maybe); - if (gencode) { - EVAL(rightop, RVAL, TRUE, - l_true, l_false); + if (gencode) { + EVAL(right, RVAL, TRUE, l_true, + l_false); C_df_ilb(l_false); C_loc((arith)0); C_bra(l_end); @@ -638,30 +552,30 @@ EVAL(expr, val, code, true_label, false_label) C_loc((arith)1); C_df_ilb(l_end); } - else { - EVAL(rightop, RVAL, FALSE, l_true, + else { + EVAL(right, RVAL, FALSE, l_true, l_true); C_df_ilb(l_true); } } - else { + else { label l_maybe = text_label(); - EVAL(leftop, RVAL, TRUE, true_label, l_maybe); + EVAL(left, RVAL, TRUE, true_label, l_maybe); C_df_ilb(l_maybe); - EVAL(rightop, RVAL, code, true_label, + EVAL(right, RVAL, code, true_label, false_label); } break; case '!': - if (true_label == 0) { - if (gencode) { + if (true_label == 0) { + if (gencode) { label l_true = text_label(); label l_false = text_label(); label l_end = text_label(); - EVAL(rightop, RVAL, TRUE, - l_false, l_true); + EVAL(right, RVAL, TRUE, l_false, + l_true); C_df_ilb(l_false); C_loc((arith)0); C_bra(l_end); @@ -670,11 +584,11 @@ EVAL(expr, val, code, true_label, false_label) C_df_ilb(l_end); } else - EVAL(rightop, RVAL, FALSE, - NO_LABEL, NO_LABEL); + EVAL(right, RVAL, FALSE, NO_LABEL, + NO_LABEL); } else - EVAL(rightop, RVAL, code, false_label, + EVAL(right, RVAL, code, false_label, true_label); break; case INT2INT: @@ -683,14 +597,13 @@ EVAL(expr, val, code, true_label, false_label) case FLOAT2INT: case FLOAT2FLOAT: #endif NOFLOAT - EVAL(rightop, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); if (gencode) - conversion(rightop->ex_type, leftop->ex_type); + conversion(right->ex_type, left->ex_type); break; default: crash("(EVAL) bad operator %s\n", symbol2str(oper)); } - /* If the rvalue of the expression is required but only its lvalue is evaluated, its rvalue is loaded by the following statements: @@ -710,7 +623,7 @@ compare(relop, lbl) int relop; label lbl; { - switch (relop) { + switch (relop) { case '<': C_zlt(lbl); break; @@ -744,13 +657,13 @@ assop(type, oper) if ((size = type->tp_size) < word_size) size = word_size; - switch (type->tp_fund) { + switch (type->tp_fund) { case CHAR: case SHORT: case INT: case LONG: case ENUM: - switch (oper) { + switch (oper) { case PLUSAB: case PLUSPLUS: case POSTINCR: @@ -811,7 +724,7 @@ assop(type, oper) #ifndef NOFLOAT case FLOAT: case DOUBLE: - switch (oper) { + switch (oper) { case PLUSAB: case PLUSPLUS: case POSTINCR: @@ -888,21 +801,19 @@ store_val(vl, tp) register int indword; arith val = vl->vl_value; - if (vl->vl_class == Const) { /* absolute addressing */ + if (vl->vl_class == Const) { /* absolute addressing */ load_cst(val, pointer_size); store_block(size, tpalign); return; } - al_on_word = (tpalign % word_align == 0); if (!(inword = (size == word_size && al_on_word))) indword = (size == dword_size && al_on_word); - - if (vl->vl_class == Name) { + if (vl->vl_class == Name) { register struct idf *id = vl->vl_data.vl_idf; register struct def *df = id->id_def; - if (df->df_level == L_GLOBAL) { + if (df->df_level == L_GLOBAL) { if (inword) C_ste_dnam(id->id_text, val); else @@ -920,7 +831,7 @@ store_val(vl, tp) else if (indword) C_sdl(df->df_address + val); - else { + else { C_lal(df->df_address + val); store_block(size, tpalign); df->df_register = REG_NONE; @@ -965,8 +876,8 @@ load_val(expr, val) register int inword, indword; arith val = expr->VL_VALUE; - if (expr->VL_CLASS == Const) { - if (rvalue) { /* absolute addressing */ + if (expr->VL_CLASS == Const) { + if (rvalue) { /* absolute addressing */ load_cst(val, pointer_size); load_block(size, tpalign); } @@ -980,7 +891,7 @@ load_val(expr, val) indword = (size == dword_size && al_on_word); } if (expr->VL_CLASS == Label) { - if (rvalue) { + if (rvalue) { if (inword) C_loe_dlb(expr->VL_LBL, val); else @@ -992,7 +903,7 @@ load_val(expr, val) } } - else { + else { C_lae_dlb(expr->VL_LBL, (arith)0); C_adp(val); } @@ -1010,8 +921,8 @@ load_val(expr, val) */ C_lpi(id->id_text); else - if (df->df_level == L_GLOBAL) { - if (rvalue) { + if (df->df_level == L_GLOBAL) { + if (rvalue) { if (inword) C_loe_dnam(id->id_text, val); else @@ -1022,14 +933,14 @@ load_val(expr, val) load_block(size, tpalign); } } - else { + else { C_lae_dnam(id->id_text, (arith)0); C_adp(val); } } - else { + else { ASSERT(df->df_sc != STATIC); - if (rvalue) { + if (rvalue) { if (inword) C_lol(df->df_address + val); else @@ -1041,7 +952,7 @@ load_val(expr, val) df->df_register = REG_NONE; } } - else { + else { C_lal(df->df_address); C_adp(val); df->df_register = REG_NONE; diff --git a/lang/cem/cemcom/expr.c b/lang/cem/cemcom/expr.c index 282e3391..cdfaa5a5 100644 --- a/lang/cem/cemcom/expr.c +++ b/lang/cem/cemcom/expr.c @@ -92,14 +92,14 @@ rank_of(oper) } int -rank_of_expression(expr) - register struct expr *expr; +rank_of_expression(ex) + register struct expr *ex; { /* Returns the rank of the top node in the expression. */ - if (!expr || (expr->ex_flags & EX_PARENS) || expr->ex_class != Oper) + if (!ex || (ex->ex_flags & EX_PARENS) || ex->ex_class != Oper) return 0; - return rank_of(expr->OP_OPER); + return rank_of(ex->OP_OPER); } check_conditional(expr, oper, pos_descr) @@ -158,15 +158,12 @@ idf2expr(expr) register struct def *def = idf->id_def; if (def == 0) { - if (AHEAD == '(') { - /* Function call, so declare the name IMPLICITly. */ - /* See RM 13. */ - add_def(idf, IMPLICIT, funint_type, level); - } + if (AHEAD == '(') /* function call, declare name IMPLICITly */ + add_def(idf, IMPLICIT, funint_type, level); /* RM 13 */ else { if (!is_anon_idf(idf)) error("%s undefined", idf->id_text); - /* Declare the idf anyway */ + /* declare idf anyway */ add_def(idf, 0, error_type, level); } def = idf->id_def; @@ -254,25 +251,24 @@ intexpr(ivalue, fund) clear((char *)expr, sizeof(struct expr)); expr->ex_file = dot.tk_file; expr->ex_line = dot.tk_line; - fill_int_expr(expr, ivalue, fund); return expr; } -fill_int_expr(expr, ivalue, fund) - register struct expr *expr; +fill_int_expr(ex, ivalue, fund) + register struct expr *ex; arith ivalue; int fund; { /* Details derived from ivalue and fund are put into the - constant integer expression expr. + constant integer expression ex. */ switch (fund) { case INT: - expr->ex_type = int_type; + ex->ex_type = int_type; break; case LONG: - expr->ex_type = long_type; + ex->ex_type = long_type; break; case UNSIGNED: /* We cannot make a test like @@ -284,20 +280,18 @@ fill_int_expr(expr, ivalue, fund) answer. We assume that the type "unsigned long" is not part of portable C ! */ - expr->ex_type = - (ivalue & ~max_unsigned) ? long_type : uint_type; + ex->ex_type = (ivalue & ~max_unsigned) ? long_type : uint_type; break; case INTEGER: - expr->ex_type = (ivalue <= max_int) ? int_type : long_type; + ex->ex_type = (ivalue <= max_int) ? int_type : long_type; break; default: crash("(intexpr) bad fund %s\n", symbol2str(fund)); } - expr->ex_class = Value; - expr->VL_CLASS = Const; - expr->VL_VALUE = ivalue; - - cut_size(expr); + ex->ex_class = Value; + ex->VL_CLASS = Const; + ex->VL_VALUE = ivalue; + cut_size(ex); } struct expr * @@ -344,8 +338,7 @@ new_oper(tp, e1, oper, e2) int e1_flags = e1 ? e1->ex_flags : 0; expr->ex_depth = - (e1_depth > e2->ex_depth ? e1_depth : e2->ex_depth) - + 1; + (e1_depth > e2->ex_depth ? e1_depth : e2->ex_depth) + 1; expr->ex_flags = (e1_flags | e2->ex_flags) & ~EX_PARENS; } op = &expr->ex_object.ex_oper; @@ -353,7 +346,6 @@ new_oper(tp, e1, oper, e2) op->op_oper = oper; op->op_left = e1; op->op_right = e2; - return expr; } @@ -397,17 +389,14 @@ chk_cst_expr(expp) #endif DEBUG if ( fund != CHAR && fund != SHORT && fund != INT && fund != ENUM && fund != LONG - ) { + ) expr_error(expr, "non-numerical constant expression"), err++; - } else if (!is_ld_cst(expr)) expr_error(expr, "expression is not constant"), err++; - if (options['R']) { if (flags & EX_CAST) - expr_warning(expr, - "cast in constant expression"); + expr_warning(expr, "cast in constant expression"); if (flags & EX_LOGICAL) expr_warning(expr, "logical operator in constant expression"); @@ -475,11 +464,11 @@ free_expression(expr) { /* The expression expr is freed recursively. */ - if (!expr) - return; - if (expr->ex_class == Oper) { - free_expression(expr->OP_LEFT); - free_expression(expr->OP_RIGHT); + if (expr) { + if (expr->ex_class == Oper) { + free_expression(expr->OP_LEFT); + free_expression(expr->OP_RIGHT); + } + free_expr(expr); } - free_expr(expr); } diff --git a/lang/cem/cemcom/field.c b/lang/cem/cemcom/field.c index 747656ad..63c1b61b 100644 --- a/lang/cem/cemcom/field.c +++ b/lang/cem/cemcom/field.c @@ -5,9 +5,7 @@ #ifndef NOBITFIELD #include - #include "debug.h" - #include "arith.h" #include "type.h" #include "idf.h" @@ -27,39 +25,33 @@ char *symbol2str(); /* symbol2str.c */ tree and are therefore dealt with in this function. The actions taken at any operation are described clearly by the code for this actions. - Note: the bitfields are packed in target machine integers! + Notes + [1] the bitfields are packed in target machine integers! + [2] op is either an assignment operator or an increment/ + decrement operator + [3] atype: the type in which the bitfield arithmetic is done; + and in which bitfields are stored! */ eval_field(expr, code) struct expr *expr; int code; { int op = expr->OP_OPER; - struct expr *leftop = expr->OP_LEFT; - struct expr *rightop = expr->OP_RIGHT; - struct field *fd = leftop->ex_type->tp_field; + register struct expr *leftop = expr->OP_LEFT; + register struct expr *rightop = expr->OP_RIGHT; + register struct field *fd = leftop->ex_type->tp_field; struct type *tp = leftop->ex_type->tp_up; arith old_offset, tmpvar; - - /* The type in which the bitfield arithmetic is done; - AND IN WHICH BITFIELDS ARE STORED! - */ struct type *atype = tp->tp_unsigned ? uword_type : word_type; arith asize = atype->tp_size; /* First some assertions to be sure that the rest is legal */ ASSERT(asize == word_size); /* make sure that C_loc() is legal */ ASSERT(leftop->ex_type->tp_fund == FIELD); - leftop->ex_type = atype; /* this is cheating but it works... */ - - /* Note that op is either an assignment operator or an increment/ - decrement operator - */ if (op == '=') { - /* F = E: f = ((E & mask)<ex_type); - EVAL(rightop, RVAL, TRUE, NO_LABEL, NO_LABEL); conversion(tp, atype); C_loc(fd->fd_mask); @@ -116,10 +108,9 @@ eval_field(expr, code) C_and(asize); if (code == TRUE && (op == POSTINCR || op == POSTDECR)) C_dup(asize); - - /* the 'op' operation: */ conversion(atype, rightop->ex_type); EVAL(rightop, RVAL, TRUE, NO_LABEL, NO_LABEL); + /* the 'op' operation: */ if (op == PLUSPLUS || op == POSTINCR) assop(rightop->ex_type, PLUSAB); else @@ -128,7 +119,6 @@ eval_field(expr, code) else assop(rightop->ex_type, op); conversion(rightop->ex_type, atype); - C_loc(fd->fd_mask); C_and(asize); if (code == TRUE && op != POSTINCR && op != POSTDECR) diff --git a/lang/cem/cemcom/idf.c b/lang/cem/cemcom/idf.c index 92a3f736..200a05ab 100644 --- a/lang/cem/cemcom/idf.c +++ b/lang/cem/cemcom/idf.c @@ -201,7 +201,6 @@ declare_idf(ds, dc, lvl) /* some additional work for formal definitions */ if (lvl == L_FORMAL2) { switch (type->tp_fund) { - case FUNCTION: warning("%s is a function; cannot be formal", idf->id_text); @@ -227,7 +226,6 @@ declare_idf(ds, dc, lvl) break; } } - /* The tests on types, postponed from do_decspecs(), can now be performed. */ @@ -241,23 +239,15 @@ declare_idf(ds, dc, lvl) ds->ds_sc = sc = GLOBAL; } } - else { /* non-FUNCTION */ + else /* non-FUNCTION */ if (sc == 0) - sc = - lvl == L_GLOBAL ? - GLOBAL : - lvl == L_FORMAL1 || lvl == L_FORMAL2 ? - FORMAL : - AUTO; - } - - if (options['R']) { - /* some special K & R tests */ - + sc = lvl == L_GLOBAL ? GLOBAL + : lvl == L_FORMAL1 || lvl == L_FORMAL2 ? FORMAL + : AUTO; + if (options['R']) { /* some special K & R tests */ /* is it also an enum? */ if (idf->id_enum && idf->id_enum->tg_level == level) warning("%s is also an enum tag", idf->id_text); - /* is it a universal typedef? */ if (def && def->df_level == L_UNIVERSAL) warning("redeclaring reserved word %s", idf->id_text); @@ -299,15 +289,13 @@ declare_idf(ds, dc, lvl) */ if ( options['R'] && (sc == STATIC && type->tp_fund == FUNCTION) - ) { + ) if (!is_anon_idf(idf)) warning("non-global static function %s", idf->id_text); - } declare_idf(ds, dc, L_GLOBAL); } - else { - /* fill in the def block */ + else { /* fill in the def block */ register struct def *newdef = new_def(); clear((char *)newdef, sizeof(struct def)); @@ -315,24 +303,19 @@ declare_idf(ds, dc, lvl) newdef->df_level = lvl; newdef->df_type = type; newdef->df_sc = sc; - /* link it into the name list in the proper place */ idf->id_def = newdef; update_ahead(idf); stack_idf(idf, stl); - /* We now calculate the address. Globals have names and don't get addresses, they get numbers instead (through data_label()). Formals are handled by declare_formals(). So here we hand out local addresses only. */ - if (lvl >= L_LOCAL) { + ASSERT(sc); switch (sc) { - case 0: - crash("local sc == 0"); - break; case REGISTER: case AUTO: if (type->tp_size == (arith)-1) { @@ -341,8 +324,8 @@ declare_idf(ds, dc, lvl) /** type = idf->id_def->df_type = int_type; **/ } idf->id_def->df_register = - (sc == REGISTER) - ? REG_BONUS : REG_DEFAULT; + (sc == REGISTER) ? REG_BONUS + : REG_DEFAULT; idf->id_def->df_address = stl->sl_max_block = stl->sl_local_offset = @@ -358,17 +341,17 @@ declare_idf(ds, dc, lvl) } actual_declaration(sc, tp) + int sc; struct type *tp; { /* An actual_declaration needs space, right here and now. */ register int fund = tp->tp_fund; - /* virtual declarations */ - if (sc == ENUM || sc == TYPEDEF) + if (sc == ENUM || sc == TYPEDEF) /* virtual declarations */ return 0; - /* allocation solved in other ways */ if (fund == FUNCTION || fund == ARRAY) + /* allocation solved in other ways */ return 0; /* to be allocated */ return 1; @@ -388,7 +371,6 @@ global_redecl(idf, new_sc, tp) if (tp != def->df_type) { register struct type *otp = def->df_type; - if ( tp->tp_fund != ARRAY || otp->tp_fund != ARRAY || tp->tp_up != otp->tp_up ) { @@ -409,9 +391,8 @@ global_redecl(idf, new_sc, tp) error("inconsistent size in redeclaration of array %s", idf->id_text); } - - /* Now we may be able to update the storage class. */ - /* Clean out this mess as soon as we know all the possibilities + /* Now we may be able to update the storage class. + Clean out this mess as soon as we know all the possibilities for new_sc. For now we have: EXTERN: we have seen the word "extern" @@ -424,7 +405,6 @@ global_redecl(idf, new_sc, tp) */ if (new_sc == IMPLICIT) return; /* no new information */ - switch (def->df_sc) { /* the old storage class */ case EXTERN: switch (new_sc) { /* the new storage class */ @@ -456,10 +436,9 @@ global_redecl(idf, new_sc, tp) case GLOBAL: break; case STATIC: - if (def->df_initialized) { + if (def->df_initialized) error("cannot redeclare %s to static", idf->id_text); - } else { if (options['R']) warning("%s redeclared to static", @@ -475,10 +454,9 @@ global_redecl(idf, new_sc, tp) case STATIC: switch (new_sc) { /* the new storage class */ case EXTERN: - if (def->df_initialized) { + if (def->df_initialized) error("cannot redeclare %s to extern", idf->id_text); - } else { warning("%s redeclared to extern", idf->id_text); @@ -531,11 +509,9 @@ good_formal(def, idf) /* Succeeds if def is a proper L_FORMAL1 definition and gives an error message otherwise. */ - if (!def || def->df_level != L_FORMAL1) { - /* not in parameter list */ + if (!def || def->df_level != L_FORMAL1) { /* not in parameter list */ if (!is_anon_idf(idf)) - error("%s not in parameter list", - idf->id_text); + error("%s not in parameter list", idf->id_text); return 0; } return 1; @@ -610,17 +586,12 @@ declare_formals(fp) register struct def *def = se->se_idf->id_def; def->df_address = f_offset; - /* the alignment convention for parameters is: align on word boundaries, i.e. take care that the following parameter starts on a new word boundary. */ f_offset = align(f_offset + def->df_type->tp_size, word_align); - - /* the following is absurd: any char or short formal - must be converted from integer to that type - */ - formal_cvt(def); + formal_cvt(def); /* cvt int to char or short, if necessary */ se = se->next; } *fp = f_offset; diff --git a/lang/cem/cemcom/ival.c b/lang/cem/cemcom/ival.c index 75525498..f7e94121 100644 --- a/lang/cem/cemcom/ival.c +++ b/lang/cem/cemcom/ival.c @@ -24,7 +24,6 @@ char *symbol2str(); char *long2str(); - struct expr *do_array(), *do_struct(), *IVAL(); /* do_ival() performs the initialisation of a global variable @@ -58,26 +57,23 @@ IVAL(tpp, ex) register struct type *tp = *tpp; switch (tp->tp_fund) { - case ARRAY: - /* array initialisation */ + case ARRAY: /* array initialisation */ if (valid_type(tp->tp_up, "array element") == 0) return 0; if (ISCOMMA(ex)) /* list of initialisation expressions */ return do_array(ex, tpp); - /* catch initialisations like char s[] = "I am a string" */ if (tp->tp_up->tp_fund == CHAR && ex->ex_class == String) + /* initialisation like char s[] = "I am a string" */ ch_array(tpp, ex); else /* " int i[24] = 12;" */ check_and_pad(ex, tpp); break; - case STRUCT: - /* struct initialisation */ + case STRUCT: /* struct initialisation */ if (valid_type(tp, "struct") == 0) return 0; if (ISCOMMA(ex)) /* list of initialisation expressions */ return do_struct(ex, tp); - /* "struct foo f = 12;" */ - check_and_pad(ex, tpp); + check_and_pad(ex, tpp); /* "struct foo f = 12;" */ break; case UNION: error("union initialisation not allowed"); @@ -85,7 +81,7 @@ IVAL(tpp, ex) case ERRONEOUS: break; default: /* fundamental type */ - if (ISCOMMA(ex)) { /* " int i = {12};" */ + if (ISCOMMA(ex)) { /* " int i = {12};" */ if (IVAL(tpp, ex->OP_LEFT) != 0) too_many_initialisers(ex); /* return remainings of the list for the @@ -94,8 +90,7 @@ IVAL(tpp, ex) */ return ex->OP_RIGHT; } - /* "int i = 12;" */ - check_ival(ex, tp); + check_ival(ex, tp); /* "int i = 12;" */ break; } return 0; @@ -131,8 +126,7 @@ do_array(ex, tpp) is completely foolish, we did it!! (no applause, thank you) */ if (tp->tp_up->tp_fund == CHAR) { - register struct expr *f = ex->OP_LEFT; - register struct expr *g = 0; + register struct expr *f = ex->OP_LEFT, *g = NILEXPR; while (ISCOMMA(f)) { /* eat the brackets!!! */ g = f; @@ -150,8 +144,7 @@ do_array(ex, tpp) /* declared with unknown size: [] */ for (elem_count = 0; ex; elem_count++) { /* eat whole initialisation expression */ - if (ISCOMMA(ex->OP_LEFT)) { - /* the member expression is embraced */ + if (ISCOMMA(ex->OP_LEFT)) { /* embraced member */ if (IVAL(&(tp->tp_up), ex->OP_LEFT) != 0) too_many_initialisers(ex); ex = ex->OP_RIGHT; @@ -172,15 +165,13 @@ do_array(ex, tpp) arith dim = tp->tp_size / tp->tp_up->tp_size; for (elem_count = 0; elem_count < dim && ex; elem_count++) { - if (ISCOMMA(ex->OP_LEFT)) { - /* embraced member initialisation */ + if (ISCOMMA(ex->OP_LEFT)) { /* embraced member */ if (IVAL(&(tp->tp_up), ex->OP_LEFT) != 0) too_many_initialisers(ex); ex = ex->OP_RIGHT; } else { if (aggregate_type(tp->tp_up)) - /* the member is an aggregate */ ex = IVAL(&(tp->tp_up), ex); else { check_ival(ex->OP_LEFT, tp->tp_up); @@ -194,7 +185,7 @@ do_array(ex, tpp) is returned */ return ex; - if ((ex == 0) && elem_count < dim) { + if ((ex == 0) && elem_count < dim) /* the expression tree is completely absorbed but there are still members which must be initialised with zeroes @@ -202,7 +193,6 @@ do_array(ex, tpp) do pad(tp->tp_up); while (++elem_count < dim); - } } return 0; } @@ -245,16 +235,14 @@ do_struct(ex, tp) definition. */ put_bf(sd->sd_type, (arith)0); - else { - /* fundamental type, not embraced */ + else { /* fundamental type, not embraced */ check_ival(ex->OP_LEFT, sd->sd_type); ex = ex->OP_RIGHT; } #endif NOBITFIELD } } - /* align upto the next selector boundary */ - if (sd->sd_sdef) + if (sd->sd_sdef) /* align upto the next selector boundary */ bytes_upto_here += zero_bytes(sd); if (last_offset != sd->sd_offset) { /* don't take the field-width more than once */ @@ -266,9 +254,7 @@ do_struct(ex, tp) } /* perfect fit if (ex && (sd == 0)) holds */ if ((ex == 0) && (sd != 0)) { - /* there are selectors left which must be padded with - zeroes - */ + /* there are selectors left which must be padded with zeroes */ do { pad(sd->sd_type); /* take care of the alignment restrictions */ @@ -307,7 +293,7 @@ check_and_pad(ex, tpp) */ tp = *tpp = construct_type(ARRAY, tp->tp_up, (arith)1); else { - register dim = tp->tp_size / tp->tp_up->tp_size; + register int dim = tp->tp_size / tp->tp_up->tp_size; /* pad remaining members with zeroes */ while (--dim > 0) pad(tp->tp_up); @@ -320,7 +306,7 @@ check_and_pad(ex, tpp) if (valid_type(tp, "struct") == 0) return; check_and_pad(ex, &(sd->sd_type)); - /* Next selector is aligned by adding extra zeroes */ + /* next selector is aligned by adding extra zeroes */ if (sd->sd_sdef) zero_bytes(sd); while (sd = sd->sd_sdef) { /* pad remaining selectors */ @@ -346,10 +332,8 @@ pad(tp) if (valid_type(tp->tp_up, "array element") == 0) return; - dim = tp->tp_size / tp->tp_up->tp_size; - - /* Assume the dimension is known */ + /* assume dimension is known */ while (dim-- > 0) pad(tp->tp_up); break; @@ -360,7 +344,6 @@ pad(tp) if (valid_type(tp, "struct") == 0) return; - do { pad(sdef->sd_type); if (sdef->sd_sdef) @@ -462,10 +445,8 @@ check_ival(ex, tp) /* float f = 1; */ ex = ex->OP_RIGHT; if (is_cp_cst(ex)) - C_con_fcon( - long2str((long)ex->VL_VALUE, 10), - tp->tp_size - ); + C_con_fcon(long2str((long)ex->VL_VALUE, 10), + tp->tp_size); else illegal_init_cst(ex); } @@ -509,7 +490,7 @@ ch_array(tpp, ex) ASSERT(ex->ex_class == String); length = ex->SG_LEN; - if (tp->tp_size == (arith)-1) { + if (tp->tp_size == (arith)-1) { /* set the dimension */ tp = *tpp = construct_type(ARRAY, tp->tp_up, length); ntopad = align(tp->tp_size, word_align) - tp->tp_size; @@ -591,8 +572,7 @@ zero_bytes(sd) /* fills the space between a selector of a struct and the next selector of that struct with zero-bytes. */ - register int n = - sd->sd_sdef->sd_offset - sd->sd_offset - + register int n = sd->sd_sdef->sd_offset - sd->sd_offset - size_of_type(sd->sd_type, "struct member"); register count = n; diff --git a/lang/cem/cemcom/replace.c b/lang/cem/cemcom/replace.c index 675d37d2..b64e4fed 100644 --- a/lang/cem/cemcom/replace.c +++ b/lang/cem/cemcom/replace.c @@ -7,7 +7,6 @@ #include "debug.h" /* UF */ #include "pathlength.h" /* UF */ #include "strsize.h" /* UF */ - #include "alloc.h" #include "idf.h" #include "input.h" @@ -52,13 +51,11 @@ replace(idef) } actpars = getactuals(idef); /* get act.param. list */ } - if ((flags & PREDEF) && (UnknownIdIsZero == 0)) - /* don't replace this one... */ - return 0; + if ((flags & PREDEF) && (UnknownIdIsZero == 0)) /* don't replace */ + return 0; if (flags & FUNC) /* this macro leads to special action */ macro_func(idef); - /* create and input buffer */ - reptext = macro2buffer(idef, actpars, &size); + reptext = macro2buffer(idef, actpars, &size); /* create input buffer */ InsertText(reptext, size); return 1; } @@ -74,8 +71,7 @@ macro_func(idef) replacement texts must be evaluated at the time they are used. */ - /* This switch is very blunt... */ - switch (idef->id_text[2]) { + switch (idef->id_text[2]) { /* This switch is very blunt... */ case 'F' : /* __FILE__ */ FilNamBuf[0] = '"'; strcpy(&FilNamBuf[1], FileName); @@ -126,8 +122,7 @@ macro2buffer(idef, actpars, siztext) for (p = actpars[n - 1]; *p; p++) { text[pos++] = *p; if (pos == size) - text = Srealloc(text, - size += RSTRSIZE); + text = Srealloc(text, size += RSTRSIZE); } } else { diff --git a/lang/cem/cemcom/switch.c b/lang/cem/cemcom/switch.c index 8a3fa20d..759b97dc 100644 --- a/lang/cem/cemcom/switch.c +++ b/lang/cem/cemcom/switch.c @@ -27,7 +27,6 @@ static struct switch_hdr *switch_stack = 0; - the expression E in "switch(E)" is cast to 'int' (RM 9.7) - the expression E in "case E:" must be 'int' (RM 9.7) - the values in the CSA/CSB tables are words (EM 7.4) - For simplicity, we suppose int_size == word_size. */ @@ -42,7 +41,7 @@ code_startswitch(expp) register struct switch_hdr *sh = new_switch_hdr(); int fund = any2arith(expp, SWITCH); /* INT, LONG or DOUBLE */ - switch (fund) { + switch (fund) { case LONG: if (options['R']) warning("long in switch (cast to int)"); @@ -55,7 +54,6 @@ code_startswitch(expp) break; #endif NOFLOAT } - stack_stmt(l_break, NO_LABEL); sh->sh_break = l_break; sh->sh_default = 0; @@ -66,8 +64,8 @@ code_startswitch(expp) sh->sh_entries = (struct case_entry *) 0; /* case-entry list */ sh->next = switch_stack; /* push onto switch-stack */ switch_stack = sh; + /* evaluate the switch expr. */ code_expr(*expp, RVAL, TRUE, NO_LABEL, NO_LABEL); - /* evaluate the switch expr. */ C_bra(l_table); /* goto start of switch_table */ } @@ -93,7 +91,7 @@ code_endswitch() ce = sh->sh_entries; for (val = sh->sh_lowerbd; val <= sh->sh_upperbd; val++) { ASSERT(ce); - if (val == ce->ce_value) { + if (val == ce->ce_value) { C_rom_ilb(ce->ce_label); ce = ce->next; } @@ -103,9 +101,9 @@ code_endswitch() C_lae_dlb(tablabel, (arith)0); /* perform the switch */ C_csa(sh->sh_type->tp_size); } - else { /* CSB */ + else { /* CSB */ C_rom_cst((arith)sh->sh_nrofentries); - for (ce = sh->sh_entries; ce; ce = ce->next) { + for (ce = sh->sh_entries; ce; ce = ce->next) { /* generate the entries: value + prog.label */ C_rom_cst(ce->ce_value); C_rom_ilb(ce->ce_label); @@ -115,11 +113,9 @@ code_endswitch() } C_df_ilb(sh->sh_break); switch_stack = sh->next; /* unstack the switch descriptor */ - - /* free the allocated switch structure */ - ce = sh->sh_entries; - while (ce) { + for (ce = sh->sh_entries; ce;) { /* free allocated switch structure */ register struct case_entry *tmp = ce->next; + free_case_entry(ce); ce = tmp; } @@ -135,28 +131,23 @@ code_case(expr) register struct switch_hdr *sh = switch_stack; ASSERT(is_cp_cst(expr)); - if (sh == 0) { + if (sh == 0) { error("case statement not in switch"); return; } - if (expr->ex_flags & EX_ERROR) { - /* is probably 0 anyway */ + if (expr->ex_flags & EX_ERROR) /* is probably 0 anyway */ return; - } ch7cast(&expr, SWITCH, sh->sh_type); ce = new_case_entry(); C_df_ilb(ce->ce_label = text_label()); ce->ce_value = val = expr->VL_VALUE; - if (sh->sh_entries == 0) { - /* first case entry */ + if (sh->sh_entries == 0) { /* first case entry */ ce->next = (struct case_entry *) 0; sh->sh_entries = ce; sh->sh_lowerbd = sh->sh_upperbd = val; sh->sh_nrofentries = 1; } - else { - /* second etc. case entry */ - /* find the proper place to put ce into the list */ + else { /* second etc. case entry; put ce into proper place */ register struct case_entry *c1 = sh->sh_entries, *c2 = 0; if (val < sh->sh_lowerbd) @@ -164,37 +155,34 @@ code_case(expr) else if (val > sh->sh_upperbd) sh->sh_upperbd = val; - while (c1 && c1->ce_value < ce->ce_value) { + while (c1 && c1->ce_value < ce->ce_value) { c2 = c1; c1 = c1->next; } /* At this point three cases are possible: - 1: c1 != 0 && c2 != 0: - insert ce somewhere in the middle - 2: c1 != 0 && c2 == 0: - insert ce right after the head - 3: c1 == 0 && c2 != 0: - append ce to last element + 1: c1 != 0 && c2 != 0: insert ce somewhere in the middle + 2: c1 != 0 && c2 == 0: insert ce right after the head + 3: c1 == 0 && c2 != 0: append ce to last element The case c1 == 0 && c2 == 0 cannot occur, since - the list is guaranteed not to be empty. + the list is guaranteed to be non-empty. */ - if (c1) { - if (c1->ce_value == ce->ce_value) { + if (c1) { + if (c1->ce_value == ce->ce_value) { error("multiple case entry for value %ld", ce->ce_value); free_case_entry(ce); return; } - if (c2) { + if (c2) { ce->next = c2->next; c2->next = ce; } - else { + else { ce->next = sh->sh_entries; sh->sh_entries = ce; } } - else { + else { ASSERT(c2); ce->next = (struct case_entry *) 0; c2->next = ce; @@ -207,13 +195,11 @@ code_default() { register struct switch_hdr *sh = switch_stack; - if (sh == 0) { + if (sh == 0) error("default not in switch"); - return; - } - if (sh->sh_default != 0) { + else + if (sh->sh_default != 0) error("multiple entry for default in switch"); - return; - } - C_df_ilb(sh->sh_default = text_label()); + else + C_df_ilb(sh->sh_default = text_label()); } From 6cc0c7f4614fba712923e9a5956fa49f0dff6731 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 30 Sep 1986 11:13:44 +0000 Subject: [PATCH 0273/1625] There was an error in test 026. It used local variables but declared none. This is corrected. --- emtest/tests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emtest/tests b/emtest/tests index 25220012..c3a74ddb 100644 --- a/emtest/tests +++ b/emtest/tests @@ -486,7 +486,7 @@ MAIN 20 bne *1 OK TEST 026: test sti 1 and lol -MAIN 0 +MAIN 20 loc 257 stl -12+WS loc 514 From f066c3691d4464caf0881e63306ae3169c661870 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 6 Oct 1986 20:36:30 +0000 Subject: [PATCH 0274/1625] newer version --- lang/m2/comp/LLlex.c | 25 ++-- lang/m2/comp/LLlex.h | 2 - lang/m2/comp/LLmessage.c | 22 +-- lang/m2/comp/Makefile | 40 +++--- lang/m2/comp/Parameters | 16 +-- lang/m2/comp/Resolve | 8 +- lang/m2/comp/Version.c | 1 + lang/m2/comp/casestat.C | 97 +++++++------ lang/m2/comp/chk_expr.c | 228 ++++++++++++++++------------- lang/m2/comp/chk_expr.h | 2 - lang/m2/comp/class.h | 2 - lang/m2/comp/code.c | 150 ++++++++----------- lang/m2/comp/const.h | 2 - lang/m2/comp/cstoper.c | 8 +- lang/m2/comp/declar.g | 293 +++++++++++++++++--------------------- lang/m2/comp/def.H | 15 +- lang/m2/comp/def.c | 179 ++++++++++++----------- lang/m2/comp/defmodule.c | 36 +++-- lang/m2/comp/desig.c | 5 - lang/m2/comp/desig.h | 2 - lang/m2/comp/enter.c | 79 +++++----- lang/m2/comp/error.c | 4 - lang/m2/comp/expression.g | 31 ++-- lang/m2/comp/f_info.h | 2 - lang/m2/comp/idf.c | 2 - lang/m2/comp/idf.h | 2 - lang/m2/comp/input.c | 12 +- lang/m2/comp/input.h | 2 - lang/m2/comp/lookup.c | 4 - lang/m2/comp/main.c | 24 ++-- lang/m2/comp/main.h | 5 - lang/m2/comp/make.allocd | 13 +- lang/m2/comp/misc.H | 2 - lang/m2/comp/misc.c | 4 - lang/m2/comp/node.H | 4 +- lang/m2/comp/node.c | 4 - lang/m2/comp/options.c | 28 ++-- lang/m2/comp/program.g | 43 +++--- lang/m2/comp/scope.C | 101 ++++++------- lang/m2/comp/scope.h | 2 - lang/m2/comp/standards.h | 2 - lang/m2/comp/statement.g | 36 +++-- lang/m2/comp/tmpvar.C | 10 +- lang/m2/comp/tokenname.c | 4 - lang/m2/comp/tokenname.h | 2 - lang/m2/comp/type.H | 8 +- lang/m2/comp/type.c | 85 ++++++----- lang/m2/comp/typequiv.c | 4 - lang/m2/comp/walk.c | 109 +++++++------- lang/m2/comp/walk.h | 2 - 50 files changed, 839 insertions(+), 924 deletions(-) create mode 100644 lang/m2/comp/Version.c diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index d97afee1..2f488734 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -1,9 +1,5 @@ /* L E X I C A L A N A L Y S E R F O R M O D U L A - 2 */ -#ifndef NORCSID -static char *RcsId = "$Header$"; -#endif - #include "debug.h" #include "idfsize.h" #include "numsize.h" @@ -40,9 +36,10 @@ SkipComment() Note that comments may be nested (par. 3.5). */ register int ch; + register int CommentLevel = 0; + LoadChar(ch); for (;;) { - LoadChar(ch); if (class(ch) == STNL) { LineNumber++; #ifdef DEBUG @@ -51,12 +48,22 @@ SkipComment() } else if (ch == '(') { LoadChar(ch); - if (ch == '*') SkipComment(); + if (ch == '*') CommentLevel++; + else continue; } else if (ch == '*') { LoadChar(ch); - if (ch == ')') break; + if (ch == ')') { + CommentLevel--; + if (CommentLevel < 0) break; + } + else continue; } + else if (ch == EOI) { + lexerror("unterminated comment"); + break; + } + LoadChar(ch); } } @@ -69,7 +76,8 @@ GetString(upto) register struct string *str = (struct string *) Malloc(sizeof(struct string)); register char *p; - str->s_str = p = Malloc((unsigned int) (str->s_length = ISTRSIZE)); + str->s_length = ISTRSIZE; + str->s_str = p = Malloc((unsigned int) ISTRSIZE); while (LoadChar(ch), ch != upto) { if (class(ch) == STNL) { lexerror("newline in string"); @@ -394,6 +402,7 @@ lexwarning("Character constant out of range"); case STCHAR: default: crash("(LLlex) Impossible character class"); + /*NOTREACHED*/ } /*NOTREACHED*/ } diff --git a/lang/m2/comp/LLlex.h b/lang/m2/comp/LLlex.h index 16495e10..c6cc4a40 100644 --- a/lang/m2/comp/LLlex.h +++ b/lang/m2/comp/LLlex.h @@ -1,7 +1,5 @@ /* T O K E N D E S C R I P T O R D E F I N I T I O N */ -/* $Header$ */ - /* Structure to store a string constant */ struct string { diff --git a/lang/m2/comp/LLmessage.c b/lang/m2/comp/LLmessage.c index 3fabfbc6..ead8f103 100644 --- a/lang/m2/comp/LLmessage.c +++ b/lang/m2/comp/LLmessage.c @@ -1,9 +1,5 @@ /* S Y N T A X E R R O R R E P O R T I N G */ -#ifndef NORCSID -static char *RcsId = "$Header$"; -#endif - /* Defines the LLmessage routine. LLgen-generated parsers require the existence of a routine of that name. The routine must do syntax-error reporting and must be able to @@ -39,24 +35,28 @@ LLmessage(tk) insert_token(tk) int tk; { - aside = dot; + register struct token *dotp = ˙ - dot.tk_symb = tk; + aside = *dotp; + + dotp->tk_symb = tk; switch (tk) { /* The operands need some body */ case IDENT: - dot.TOK_IDF = gen_anon_idf(); + dotp->TOK_IDF = gen_anon_idf(); break; case STRING: - dot.TOK_SLE = 1; - dot.TOK_STR = Salloc("", 1); + dotp->tk_data.tk_str = (struct string *) + Malloc(sizeof (struct string)); + dotp->TOK_SLE = 1; + dotp->TOK_STR = Salloc("", 1); break; case INTEGER: - dot.TOK_INT = 1; + dotp->TOK_INT = 1; break; case REAL: - dot.TOK_REL = Salloc("0.0", 4); + dotp->TOK_REL = Salloc("0.0", 4); break; } } diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index 02c58fe2..772b3ac7 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -1,5 +1,4 @@ # make modula-2 "compiler" -# $Header$ EMDIR = /usr/ceriel/em MHDIR = $(EMDIR)/modules/h PKGDIR = $(EMDIR)/modules/pkg @@ -8,19 +7,26 @@ LLGEN = $(EMDIR)/bin/LLgen INCLUDES = -I$(MHDIR) -I$(EMDIR)/h -I$(PKGDIR) -LSRC = tokenfile.g program.g declar.g expression.g statement.g +GFILES = tokenfile.g program.g declar.g expression.g statement.g CC = cc LLGENOPTIONS = PROFILE = CFLAGS = $(PROFILE) $(INCLUDES) -DSTATIC= LINTFLAGS = -DSTATIC= -DNORCSID LFLAGS = $(PROFILE) +LSRC = tokenfile.c program.c declar.c expression.c statement.c LOBJ = tokenfile.o program.o declar.o expression.o statement.o +CSRC = LLlex.c LLmessage.c char.c error.c main.c \ + symbol2str.c tokenname.c idf.c input.c type.c def.c \ + scope.c misc.c enter.c defmodule.c typequiv.c node.c \ + cstoper.c chk_expr.c options.c walk.c casestat.c desig.c \ + code.c tmpvar.c lookup.c Version.c COBJ = LLlex.o LLmessage.o char.o error.o main.o \ symbol2str.o tokenname.o idf.o input.o type.o def.o \ scope.o misc.o enter.o defmodule.o typequiv.o node.o \ cstoper.o chk_expr.o options.o walk.o casestat.o desig.o \ - code.o tmpvar.o lookup.o + code.o tmpvar.o lookup.o Version.o +SRC = $(CSRC) $(LSRC) Lpars.c OBJ = $(COBJ) $(LOBJ) Lpars.o # Keep the next entries up to date! @@ -44,11 +50,11 @@ all: Cfiles @rm -f nmclash.o a.out clean: - rm -f $(OBJ) $(GENFILES) LLfiles hfiles Cfiles tab cclash.o cid.o cclash cid + rm -f $(OBJ) $(GENFILES) LLfiles hfiles Cfiles tab cclash.o cid.o cclash cid clashes (cd .. ; rm -rf Xsrc) lint: Cfiles - sh -c `if $(CC) nmclash.c > /dev/null 2>&1 ; then make Xlint ; else sh Resolve Xlint ; fi' + sh -c 'if $(CC) nmclash.c > /dev/null 2>&1 ; then make Xlint ; else sh Resolve Xlint ; fi' @rm -f nmclash.o a.out mkdep: mkdep.o @@ -57,20 +63,22 @@ mkdep: mkdep.o cclash: cclash.o $(CC) $(LFLAGS) -o cclash cclash.o +clashes: $(SRC) $(HFILES) + sh -c 'if test -f clashes ; then ./cclash -l7 clashes $? > Xclashes ; mv Xclashes clashes ; else ./cclash -l7 $? > clashes ; fi' + cid: cid.o $(CC) $(LFLAGS) -o cid cid.o # entry points not to be used directly Xlint: - lint $(INCLUDES) $(LINTFLAGS) `./sources $(OBJ)` + lint $(INCLUDES) $(LINTFLAGS) $(SRC) -Cfiles: hfiles LLfiles $(GENHFILES) $(GENCFILES) - ./sources $(OBJ) > Cfiles - sh -c 'for i in $(HFILES) ; do echo $$i ; done >> Cfiles' +Cfiles: hfiles LLfiles $(GENCFILES) $(GENHFILES) + echo $(SRC) $(HFILES) > Cfiles -LLfiles: $(LSRC) - $(LLGEN) $(LLGENOPTIONS) $(LSRC) +LLfiles: $(GFILES) + $(LLGEN) $(LLGENOPTIONS) $(GFILES) @touch LLfiles hfiles: Parameters make.hfiles @@ -78,7 +86,7 @@ hfiles: Parameters make.hfiles touch hfiles main: $(OBJ) ../src/Makefile - $(CC) $(LFLAGS) $(OBJ) $(LIBDIR)/libem_mes.a $(LIBDIR)/libemk.a $(LIBDIR)/input.a $(LIBDIR)/assert.a $(LIBDIR)/alloc.a $(LIBDIR)/malloc.o $(LIBDIR)/libprint.a $(LIBDIR)/libstr.a $(LIBDIR)/libsystem.a -o ../src/main + $(CC) $(LFLAGS) $(OBJ) $(LIBDIR)/libem_mes.a $(LIBDIR)/libemk.a $(LIBDIR)/input.a $(LIBDIR)/assert.a $(LIBDIR)/alloc.a $(LIBDIR)/dickmalloc.o $(LIBDIR)/libprint.a $(LIBDIR)/libstr.a $(LIBDIR)/libsystem.a -o ../src/main size ../src/main tokenfile.g: tokenname.c make.tokfile @@ -114,7 +122,7 @@ char.c: ../src/char.tab ../src/tab depend: mkdep sed '/^#AUTOAUTO/,$$d' Makefile > Makefile.new echo '#AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO' >> Makefile.new - ./mkdep `./sources $(OBJ)` |\ + ./mkdep $(SRC) |\ sed 's/\.c:/\.o:/' >> Makefile.new mv Makefile Makefile.old mv Makefile.new Makefile @@ -128,13 +136,13 @@ main.o: LLlex.h Lpars.h debug.h def.h f_info.h idf.h input.h inputtype.h ndir.h symbol2str.o: Lpars.h tokenname.o: Lpars.h idf.h tokenname.h idf.o: idf.h -input.o: f_info.h input.h inputtype.h +input.o: def.h f_info.h idf.h input.h inputtype.h scope.h type.o: LLlex.h const.h debug.h def.h idf.h maxset.h node.h scope.h target_sizes.h type.h walk.h def.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h type.h scope.o: LLlex.h debug.h def.h idf.h node.h scope.h type.h misc.o: LLlex.h f_info.h idf.h misc.h node.h enter.o: LLlex.h debug.h def.h idf.h main.h node.h scope.h type.h -defmodule.o: LLlex.h debug.h def.h f_info.h idf.h input.h inputtype.h main.h scope.h +defmodule.o: LLlex.h Lpars.h debug.h def.h f_info.h idf.h input.h inputtype.h main.h node.h scope.h typequiv.o: LLlex.h debug.h def.h node.h type.h node.o: LLlex.h debug.h def.h node.h type.h cstoper.o: LLlex.h Lpars.h debug.h idf.h node.h standards.h target_sizes.h type.h @@ -145,7 +153,7 @@ casestat.o: LLlex.h Lpars.h debug.h density.h desig.h node.h type.h walk.h desig.o: LLlex.h debug.h def.h desig.h node.h scope.h type.h code.o: LLlex.h Lpars.h debug.h def.h desig.h node.h scope.h standards.h type.h walk.h tmpvar.o: debug.h def.h main.h scope.h type.h -lookup.o: LLlex.h debug.h def.h idf.h node.h scope.h +lookup.o: LLlex.h debug.h def.h idf.h node.h scope.h type.h tokenfile.o: Lpars.h program.o: LLlex.h Lpars.h debug.h def.h f_info.h idf.h main.h node.h scope.h type.h declar.o: LLlex.h Lpars.h chk_expr.h debug.h def.h idf.h main.h misc.h node.h scope.h type.h diff --git a/lang/m2/comp/Parameters b/lang/m2/comp/Parameters index a1d3ff8c..0fe8880a 100644 --- a/lang/m2/comp/Parameters +++ b/lang/m2/comp/Parameters @@ -34,13 +34,13 @@ /* target machine alignment requirements */ #define AL_CHAR 1 -#define AL_SHORT SZ_SHORT -#define AL_WORD SZ_WORD -#define AL_INT SZ_WORD -#define AL_LONG SZ_WORD -#define AL_FLOAT SZ_WORD -#define AL_DOUBLE SZ_WORD -#define AL_POINTER SZ_WORD +#define AL_SHORT (int)SZ_SHORT +#define AL_WORD (int)SZ_WORD +#define AL_INT (int)SZ_WORD +#define AL_LONG (int)SZ_WORD +#define AL_FLOAT (int)SZ_WORD +#define AL_DOUBLE (int)SZ_WORD +#define AL_POINTER (int)SZ_WORD #define AL_STRUCT 1 #define AL_UNION 1 @@ -55,7 +55,7 @@ extern char options[]; #endif DEBUG !File: inputtype.h -#undef INP_READ_IN_ONE 1 /* read input file in one */ +#define INP_READ_IN_ONE 1 /* read input file in one */ !File: maxset.h diff --git a/lang/m2/comp/Resolve b/lang/m2/comp/Resolve index cabad11d..7c96827f 100755 --- a/lang/m2/comp/Resolve +++ b/lang/m2/comp/Resolve @@ -19,10 +19,10 @@ then : else mkdir ../Xsrc fi -make cclash -make cid -./cclash -c -l7 `cat Cfiles` > clashes -sed '/^C_/d' < clashes > ../Xsrc/Xclashes +make cclash clashes cid +sed '/^C_/d' < clashes > tmp$$ +./cclash -c -l7 tmp$$ > ../Xsrc/Xclashes +rm -f tmp$$ cd ../Xsrc if cmp -s Xclashes clashes then diff --git a/lang/m2/comp/Version.c b/lang/m2/comp/Version.c new file mode 100644 index 00000000..ac7bbbfa --- /dev/null +++ b/lang/m2/comp/Version.c @@ -0,0 +1 @@ +char Version[] = "Version 0.5"; diff --git a/lang/m2/comp/casestat.C b/lang/m2/comp/casestat.C index eeb9162a..8216036f 100644 --- a/lang/m2/comp/casestat.C +++ b/lang/m2/comp/casestat.C @@ -1,8 +1,11 @@ /* C A S E S T A T E M E N T C O D E G E N E R A T I O N */ -#ifndef NORCSID -static char *RcsId = "$Header$"; -#endif +/* Generation of case statements is done by first creating a + description structure for the statement, build a list of the + case-labels, then generating a case description in the code, + and generating either CSA or CSB, and then generating code for the + cases themselves. +*/ #include "debug.h" @@ -22,30 +25,32 @@ static char *RcsId = "$Header$"; #include "density.h" struct switch_hdr { - struct switch_hdr *next; - label sh_break; - label sh_default; - int sh_nrofentries; - struct type *sh_type; - arith sh_lowerbd; - arith sh_upperbd; - struct case_entry *sh_entries; + struct switch_hdr *next; /* in the free list */ + label sh_break; /* label of statement after this one */ + label sh_default; /* label of ELSE part, or 0 */ + int sh_nrofentries; /* number of cases */ + struct type *sh_type; /* type of case expression */ + arith sh_lowerbd; /* lowest case label */ + arith sh_upperbd; /* highest case label */ + struct case_entry *sh_entries; /* the cases with their generated + labels + */ }; -/* STATICALLOCDEF "switch_hdr" */ +/* STATICALLOCDEF "switch_hdr" 5 */ struct case_entry { - struct case_entry *next; - label ce_label; - arith ce_value; + struct case_entry *next; /* next in list */ + label ce_label; /* generated label */ + arith ce_value; /* value of case label */ }; -/* STATICALLOCDEF "case_entry" */ +/* STATICALLOCDEF "case_entry" 20 */ /* The constant DENSITY determines when CSA and when CSB instructions are generated. Reasonable values are: 2, 3, 4. On machines that have lots of address space and memory, higher values - are also reasonable. On these machines the density of jump tables + might also be reasonable. On these machines the density of jump tables may be lower. */ #define compact(nr, low, up) (nr != 0 && (up - low) / nr <= DENSITY) @@ -56,30 +61,36 @@ CaseCode(nd, exitlabel) { /* Check the expression, stack a new case header and fill in the necessary fields. + "exitlabel" is the exit-label of the closest enclosing + LOOP-statement, or 0. */ register struct switch_hdr *sh = new_switch_hdr(); register struct node *pnode = nd; register struct case_entry *ce; register arith val; - label tablabel; + label CaseDescrLab; assert(pnode->nd_class == Stat && pnode->nd_symb == CASE); - clear((char *) sh, sizeof(*sh)); - WalkExpr(pnode->nd_left); + WalkExpr(pnode->nd_left); /* evaluate case expression */ sh->sh_type = pnode->nd_left->nd_type; sh->sh_break = ++text_label; /* Now, create case label list */ - while (pnode && pnode->nd_right) { + while (pnode->nd_right) { pnode = pnode->nd_right; if (pnode->nd_class == Link && pnode->nd_symb == '|') { if (pnode->nd_left) { + /* non-empty case + */ pnode->nd_lab = ++text_label; - if (! AddCases(sh, + if (! AddCases(sh, /* to descriptor */ pnode->nd_left->nd_left, - pnode->nd_lab)) { + /* of case labels */ + pnode->nd_lab + /* and code label */ + )) { FreeSh(sh); return; } @@ -90,19 +101,20 @@ CaseCode(nd, exitlabel) */ sh->sh_default = ++text_label; - pnode = 0; + break; } } /* Now generate code for the switch itself + First the part that CSA and CSB descriptions have in common. */ - tablabel = ++data_label; /* the rom must have a label */ - C_df_dlb(tablabel); + CaseDescrLab = ++data_label; /* the rom must have a label */ + C_df_dlb(CaseDescrLab); if (sh->sh_default) C_rom_ilb(sh->sh_default); else C_rom_ucon("0", pointer_size); if (compact(sh->sh_nrofentries, sh->sh_lowerbd, sh->sh_upperbd)) { - /* CSA */ - + /* CSA + */ C_rom_cst(sh->sh_lowerbd); C_rom_cst(sh->sh_upperbd - sh->sh_lowerbd); ce = sh->sh_entries; @@ -115,24 +127,27 @@ CaseCode(nd, exitlabel) else if (sh->sh_default) C_rom_ilb(sh->sh_default); else C_rom_ucon("0", pointer_size); } - C_lae_dlb(tablabel, (arith)0); /* perform the switch */ + C_lae_dlb(CaseDescrLab, (arith)0); /* perform the switch */ C_csa(word_size); } - else { /* CSB */ + else { + /* CSB + */ C_rom_cst((arith)sh->sh_nrofentries); for (ce = sh->sh_entries; ce; ce = ce->next) { - /* generate the entries: value + prog.label */ + /* generate the entries: value + prog.label + */ C_rom_cst(ce->ce_value); C_rom_ilb(ce->ce_label); } - C_lae_dlb(tablabel, (arith)0); /* perform the switch */ + C_lae_dlb(CaseDescrLab, (arith)0); /* perform the switch */ C_csb(word_size); } /* Now generate code for the cases */ pnode = nd; - while (pnode && pnode->nd_right) { + while (pnode->nd_right) { pnode = pnode->nd_right; if (pnode->nd_class == Link && pnode->nd_symb == '|') { if (pnode->nd_left) { @@ -148,7 +163,7 @@ CaseCode(nd, exitlabel) C_df_ilb(sh->sh_default); WalkNode(pnode, exitlabel); - pnode = 0; + break; } } @@ -157,7 +172,7 @@ CaseCode(nd, exitlabel) } FreeSh(sh) - struct switch_hdr *sh; + register struct switch_hdr *sh; { /* free the allocated switch structure */ @@ -176,7 +191,7 @@ FreeSh(sh) AddCases(sh, node, lbl) struct switch_hdr *sh; - struct node *node; + register struct node *node; label lbl; { /* Add case labels to the case label list @@ -208,7 +223,7 @@ AddCases(sh, node, lbl) AddOneCase(sh, node, lbl) register struct switch_hdr *sh; - struct node *node; + register struct node *node; label lbl; { register struct case_entry *ce = new_case_entry(); @@ -222,15 +237,17 @@ AddOneCase(sh, node, lbl) return 0; } if (sh->sh_entries == 0) { - /* first case entry */ + /* first case entry + */ ce->next = (struct case_entry *) 0; sh->sh_entries = ce; sh->sh_lowerbd = sh->sh_upperbd = ce->ce_value; sh->sh_nrofentries = 1; } else { - /* second etc. case entry */ - /* find the proper place to put ce into the list */ + /* second etc. case entry + find the proper place to put ce into the list + */ if (ce->ce_value < sh->sh_lowerbd) { sh->sh_lowerbd = ce->ce_value; diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index 981b9806..0b963838 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -1,9 +1,5 @@ /* E X P R E S S I O N C H E C K I N G */ -#ifndef NORCSID -static char *RcsId = "$Header$"; -#endif - /* Check expressions, and try to evaluate them as far as possible. */ @@ -31,6 +27,9 @@ int ChkVariable(expp) register struct node *expp; { + /* Check that "expp" indicates an item that can be + assigned to. + */ if (! ChkDesignator(expp)) return 0; @@ -47,6 +46,9 @@ STATIC int ChkArrow(expp) register struct node *expp; { + /* Check an application of the '^' operator. + The operand must be a variable of a pointer type. + */ register struct type *tp; assert(expp->nd_class == Arrow); @@ -59,8 +61,7 @@ ChkArrow(expp) tp = expp->nd_right->nd_type; if (tp->tp_fund != T_POINTER) { - node_error(expp, "illegal operand for unary operator \"%s\"", - symbol2str(expp->nd_symb)); + node_error(expp, "illegal operand for unary operator \"^\""); return 0; } @@ -72,6 +73,12 @@ STATIC int ChkArr(expp) register struct node *expp; { + /* Check an array selection. + The left hand side must be a variable of an array type, + and the right hand side must be an expression that is + assignment compatible with the array-index. + */ + register struct type *tpl, *tpr; assert(expp->nd_class == Arrsel); @@ -91,7 +98,7 @@ ChkArr(expp) tpr = expp->nd_right->nd_type; if (tpl->tp_fund != T_ARRAY) { - node_error(expp, "array index not belonging to an ARRAY"); + node_error(expp, "not indexing an ARRAY type"); return 0; } @@ -110,6 +117,7 @@ ChkArr(expp) return 1; } +#ifdef DEBUG STATIC int ChkValue(expp) struct node *expp; @@ -125,11 +133,15 @@ ChkValue(expp) } /*NOTREACHED*/ } +#endif STATIC int ChkLinkOrName(expp) register struct node *expp; { + /* Check either an ID or a construction of the form + ID.ID [ .ID ]* + */ register struct def *df; expp->nd_type = error_type; @@ -140,6 +152,9 @@ ChkLinkOrName(expp) expp->nd_type = RemoveEqual(expp->nd_def->df_type); } else if (expp->nd_class == Link) { + /* A selection from a record or a module. + Modules also have a record type. + */ register struct node *left = expp->nd_left; assert(expp->nd_symb == '.'); @@ -188,16 +203,17 @@ df->df_idf->id_text); if (df->df_kind == D_ERROR) return 0; if (df->df_kind & (D_ENUM | D_CONST)) { + /* Replace an enum-literal or a CONST identifier by its value. + */ if (df->df_kind == D_ENUM) { expp->nd_class = Value; expp->nd_INT = df->enm_val; expp->nd_symb = INTEGER; } else { - unsigned int ln; + unsigned int ln = expp->nd_lineno; assert(df->df_kind == D_CONST); - ln = expp->nd_lineno; *expp = *(df->con_const); expp->nd_lineno = ln; } @@ -210,25 +226,28 @@ STATIC int ChkExLinkOrName(expp) register struct node *expp; { + /* Check either an ID or an ID.ID [.ID]* occurring in an + expression. + */ register struct def *df; if (! ChkLinkOrName(expp)) return 0; if (expp->nd_class != Def) return 1; df = expp->nd_def; - if (!(df->df_kind & (D_ENUM|D_CONST|D_PROCEDURE|D_FIELD|D_VARIABLE|D_PROCHEAD))) { + if (!(df->df_kind & D_VALUE)) { node_error(expp, "value expected"); } if (df->df_kind == D_PROCEDURE) { - /* Check that this procedure is one that we - may take the address from. + /* Check that this procedure is one that we may take the + address from. */ if (df->df_type == std_type || df->df_scope->sc_level > 0) { /* Address of standard or nested procedure taken. */ -node_error(expp, "it is illegal to take the address of a standard or local procedure"); +node_error(expp, "standard or local procedures may not be assigned"); return 0; } } @@ -236,20 +255,6 @@ node_error(expp, "it is illegal to take the address of a standard or local proce return 1; } -STATIC int -RemoveSet(set) - arith **set; -{ - /* This routine is only used for error exits of ChkElement. - It frees the set indicated by "set", and returns 0. - */ - if (*set) { - free((char *) *set); - *set = 0; - } - return 0; -} - STATIC int ChkElement(expp, tp, set) register struct node *expp; @@ -279,7 +284,7 @@ ChkElement(expp, tp, set) if (left->nd_INT > right->nd_INT) { node_error(expp, "lower bound exceeds upper bound in range"); - return RemoveSet(set); + return 0; } if (*set) { @@ -298,28 +303,24 @@ node_error(expp, "lower bound exceeds upper bound in range"); /* Here, a single element is checked */ - if (!ChkExpression(expp)) { - return RemoveSet(set); - } + if (!ChkExpression(expp)) return 0; if (!TstCompat(tp, expp->nd_type)) { node_error(expp, "set element has incompatible type"); - return RemoveSet(set); + return 0; } if (expp->nd_class == Value) { /* a constant element */ - i = expp->nd_INT; + arith low, high; - if ((tp->tp_fund != T_ENUMERATION && - (i < tp->sub_lb || i > tp->sub_ub)) - || - (tp->tp_fund == T_ENUMERATION && - (i < 0 || i > tp->enm_ncst)) - ) { + i = expp->nd_INT; + getbounds(tp, &low, &high); + + if (i < low || i > high) { node_error(expp, "set element out of range"); - return RemoveSet(set); + return 0; } if (*set) (*set)[i/wrd_bits] |= (1 << (i%wrd_bits)); @@ -353,9 +354,11 @@ ChkSet(expp) assert(nd->nd_class == Def); df = nd->nd_def; - if (!(df->df_kind & (D_TYPE|D_ERROR)) || + if (!is_type(df) || (df->df_type->tp_fund != T_SET)) { -node_error(expp, "specifier does not represent a set type"); + if (df->df_kind != D_ERROR) { +node_error(expp, "type specifier does not represent a set type"); + } return 0; } tp = df->df_type; @@ -394,7 +397,8 @@ node_error(expp, "specifier does not represent a set type"); /* Yes, it was a constant set, and we managed to compute it! Notice that at the moment there is no such thing as partial evaluation. Either we evaluate the set, or we - don't (at all). Improvement not neccesary. (???) + don't (at all). Improvement not neccesary (???) + ??? sets have a contant part and a variable part ??? */ expp->nd_class = Set; expp->nd_set = set; @@ -417,7 +421,6 @@ getarg(argp, bases, designator) that it must be a designator and may not be a register variable. */ - struct type *tp; register struct node *arg = (*argp)->nd_right; register struct node *left; @@ -437,8 +440,7 @@ getarg(argp, bases, designator) } if (bases) { - tp = BaseType(left->nd_type); - if (!(tp->tp_fund & bases)) { + if (!(BaseType(left->nd_type)->tp_fund & bases)) { node_error(arg, "unexpected type"); return 0; } @@ -452,7 +454,12 @@ STATIC struct node * getname(argp, kinds) struct node **argp; { + /* Get the next argument from argument list "argp". + The argument must indicate a definition, and the + definition kind must be one of "kinds". + */ register struct node *arg = *argp; + register struct node *left; if (!arg->nd_right) { node_error(arg, "too few arguments supplied"); @@ -460,25 +467,26 @@ getname(argp, kinds) } arg = arg->nd_right; - if (! ChkDesignator(arg->nd_left)) return 0; + left = arg->nd_left; + if (! ChkDesignator(left)) return 0; - if (arg->nd_left->nd_class != Def && arg->nd_left->nd_class != LinkDef) { + if (left->nd_class != Def && left->nd_class != LinkDef) { node_error(arg, "identifier expected"); return 0; } - if (!(arg->nd_left->nd_def->df_kind & kinds)) { + if (!(left->nd_def->df_kind & kinds)) { node_error(arg, "unexpected type"); return 0; } *argp = arg; - return arg->nd_left; + return left; } STATIC int ChkProcCall(expp) - register struct node *expp; + struct node *expp; { /* Check a procedure call */ @@ -487,11 +495,12 @@ ChkProcCall(expp) register struct paramlist *param; left = expp->nd_left; - arg = expp; expp->nd_type = RemoveEqual(ResultType(left->nd_type)); + /* Check parameter list + */ for (param = ParamList(left->nd_type); param; param = param->next) { - if (!(left = getarg(&arg, 0, IsVarParam(param)))) return 0; + if (!(left = getarg(&expp, 0, IsVarParam(param)))) return 0; if (left->nd_symb == STRING) { TryToString(left, TypeOfParam(param)); } @@ -504,8 +513,8 @@ node_error(left, "type incompatibility in parameter"); } } - if (arg->nd_right) { - node_error(arg->nd_right, "too many parameters supplied"); + if (expp->nd_right) { + node_error(expp->nd_right, "too many parameters supplied"); return 0; } @@ -517,7 +526,7 @@ ChkCall(expp) register struct node *expp; { /* Check something that looks like a procedure or function call. - Of course this does not have to be a call at all. + Of course this does not have to be a call at all, it may also be a cast or a standard procedure call. */ register struct node *left; @@ -531,14 +540,14 @@ ChkCall(expp) if (! ChkDesignator(left)) return 0; if (IsCast(left)) { - /* It was a type cast. This is of course not portable. + /* It was a type cast. */ return ChkCast(expp, left); } if (IsProcCall(left)) { - /* A procedure call. it may also be a call to a - standard procedure + /* A procedure call. + It may also be a call to a standard procedure */ if (left->nd_type == std_type) { /* A standard procedure @@ -559,6 +568,10 @@ STATIC struct type * ResultOfOperation(operator, tp) struct type *tp; { + /* Return the result type of the binary operation "operator", + with operand type "tp". + */ + switch(operator) { case '=': case '#': @@ -582,6 +595,10 @@ Boolean(operator) STATIC int AllowedTypes(operator) { + /* Return a bit mask indicating the allowed operand types + for binary operator "operator". + */ + switch(operator) { case '+': case '-': @@ -615,13 +632,17 @@ STATIC int ChkAddress(tpl, tpr) register struct type *tpl, *tpr; { + /* Check that either "tpl" or "tpr" are both of type + address_type, or that one of them is, but the other is + of type cardinal. + */ if (tpl == address_type) { - return tpr == address_type || tpr->tp_fund != T_POINTER; + return tpr == address_type || (tpr->tp_fund & T_CARDINAL); } if (tpr == address_type) { - return tpl->tp_fund != T_POINTER; + return (tpl->tp_fund & T_CARDINAL); } return 0; @@ -656,21 +677,26 @@ ChkBinOper(expp) } } - expp->nd_type = ResultOfOperation(expp->nd_symb, tpl); + expp->nd_type = ResultOfOperation(expp->nd_symb, tpr); + /* Check that the application of the operator is allowed on the type + of the operands. + There are three tricky parts: + - Boolean operators are only allowed on boolean operands, but + the "allowed-mask" of "AllowedTypes" can only indicate + an enumeration type. + - All operations that are allowed on CARDINALS are also allowed + on ADDRESS. + - The IN-operator has as right-hand-size operand a set. + */ if (expp->nd_symb == IN) { - /* Handle this one specially */ - if (tpr->tp_fund != T_SET) { -node_error(expp, "RHS of IN operator not a SET type"); - return 0; - } if (!TstAssCompat(tpl, ElementType(tpr))) { /* Assignment compatible ??? I don't know! Should we be allowed to check if a CARDINAL is a member of a BITSET??? */ -node_error(expp, "IN operator: type of LHS not compatible with element type of RHS"); +node_error(expp, "incompatible types for operator \"IN\""); return 0; } if (left->nd_class == Value && right->nd_class == Set) { @@ -679,6 +705,25 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R return 1; } + allowed = AllowedTypes(expp->nd_symb); + + if (!(tpr->tp_fund & allowed) || !(tpl->tp_fund & allowed)) { + if (!((T_CARDINAL & allowed) && + ChkAddress(tpl, tpr))) { +node_error(expp,"operator \"%s\": illegal operand type(s)", symbol2str(expp->nd_symb)); + return 0; + } + if (expp->nd_type->tp_fund & T_CARDINAL) { + expp->nd_type = address_type; + } + } + + if (Boolean(expp->nd_symb) && tpl != bool_type) { +node_error(expp,"operator \"%s\": illegal operand type(s)", symbol2str(expp->nd_symb)); + + return 0; + } + /* Operands must be compatible (distilled from Def 8.2) */ if (!TstCompat(tpl, tpr)) { @@ -687,32 +732,6 @@ node_error(expp, "IN operator: type of LHS not compatible with element type of R return 0; } - allowed = AllowedTypes(expp->nd_symb); - - /* Check that the application of the operator is allowed on the type - of the operands. - There are two tricky parts: - - Boolean operators are only allowed on boolean operands, but - the "allowed-mask" of "AllowedTypes" can only indicate - an enumeration type. - - All operations that are allowed on CARDINALS are also allowed - on ADDRESS. - */ - if (Boolean(expp->nd_symb) && tpl != bool_type) { -node_error(expp,"operator \"%s\": illegal operand type(s)", symbol2str(expp->nd_symb)); - - return 0; - } - if (!(tpl->tp_fund & allowed)) { - if (!(tpl->tp_fund == T_POINTER && - (T_CARDINAL & allowed) && - ChkAddress(tpl, tpr))) { -node_error(expp,"operator \"%s\": illegal operand type(s)", symbol2str(expp->nd_symb)); - return 0; - } - if (expp->nd_type == card_type) expp->nd_type = address_type; - } - if (tpl->tp_fund == T_SET) { if (left->nd_class == Set && right->nd_class == Set) { cstset(expp); @@ -737,9 +756,8 @@ ChkUnOper(expp) if (! ChkExpression(right)) return 0; - tpr = BaseType(right->nd_type); + expp->nd_type = tpr = BaseType(right->nd_type); if (tpr == address_type) tpr = card_type; - expp->nd_type = tpr; switch(expp->nd_symb) { case '+': @@ -799,6 +817,9 @@ STATIC struct node * getvariable(argp) struct node **argp; { + /* Get the next argument from argument list "argp". + It must obey the rules of "ChkVariable". + */ register struct node *arg = *argp; arg = arg->nd_right; @@ -807,10 +828,11 @@ getvariable(argp) return 0; } - if (! ChkVariable(arg->nd_left)) return 0; - *argp = arg; - return arg->nd_left; + arg = arg->nd_left; + if (! ChkVariable(arg)) return 0; + + return arg; } STATIC int @@ -1104,7 +1126,11 @@ done_before(expp) extern int NodeCrash(); int (*ExprChkTable[])() = { +#ifdef DEBUG ChkValue, +#else + done_before, +#endif ChkArr, ChkBinOper, ChkUnOper, @@ -1120,7 +1146,11 @@ int (*ExprChkTable[])() = { }; int (*DesigChkTable[])() = { +#ifdef DEBUG ChkValue, +#else + done_before, +#endif ChkArr, no_desig, no_desig, diff --git a/lang/m2/comp/chk_expr.h b/lang/m2/comp/chk_expr.h index 288bb719..7b9b4b18 100644 --- a/lang/m2/comp/chk_expr.h +++ b/lang/m2/comp/chk_expr.h @@ -1,7 +1,5 @@ /* E X P R E S S I O N C H E C K I N G */ -/* $Header$ */ - extern int (*ExprChkTable[])(); /* table of expression checking functions, indexed by node class */ diff --git a/lang/m2/comp/class.h b/lang/m2/comp/class.h index 5fb0f3d2..50f88e54 100644 --- a/lang/m2/comp/class.h +++ b/lang/m2/comp/class.h @@ -1,7 +1,5 @@ /* U S E O F C H A R A C T E R C L A S S E S */ -/* $Header$ */ - /* As a starter, chars are divided into classes, according to which token they can be the start of. At present such a class number is supposed to fit in 4 bits. diff --git a/lang/m2/comp/code.c b/lang/m2/comp/code.c index d70f2f3e..9a58a7a1 100644 --- a/lang/m2/comp/code.c +++ b/lang/m2/comp/code.c @@ -1,9 +1,5 @@ /* C O D E G E N E R A T I O N R O U T I N E S */ -#ifndef NORCSID -static char *RcsId = "$Header$"; -#endif - /* Code generation for expressions and coercions */ @@ -34,7 +30,6 @@ CodeConst(cst, size) { /* Generate code to push constant "cst" with size "size" */ - label dlab; if (size <= word_size) { C_loc(cst); @@ -43,23 +38,28 @@ CodeConst(cst, size) C_ldc(cst); } else { - C_df_dlb(dlab = ++data_label); + crash("(CodeConst)"); +/* + label dlab = ++data_label; + + C_df_dlb(dlab); C_rom_icon(long2str((long) cst), size); C_lae_dlb(dlab, (arith) 0); C_loi(size); +*/ } } CodeString(nd) register struct node *nd; { - label lab; - if (nd->nd_type->tp_fund != T_STRING) { C_loc(nd->nd_INT); } else { - C_df_dlb(lab = ++data_label); + label lab = ++data_label; + + C_df_dlb(lab); C_rom_scon(nd->nd_STR, WA(nd->nd_SLE + 1)); C_lae_dlb(lab, (arith) 0); } @@ -85,16 +85,6 @@ CodePadString(nd, sz) C_loi(sizearg); } -CodeReal(nd) - register struct node *nd; -{ - label lab = ++data_label; - - C_df_dlb(lab); - C_rom_fcon(nd->nd_REL, nd->nd_type->tp_size); - C_lae_dlb(lab, (arith) 0); - C_loi(nd->nd_type->tp_size); -} CodeExpr(nd, ds, true_label, false_label) register struct node *nd; @@ -136,8 +126,14 @@ CodeExpr(nd, ds, true_label, false_label) case Value: switch(nd->nd_symb) { - case REAL: - CodeReal(nd); + case REAL: { + label lab = ++data_label; + + C_df_dlb(lab); + C_rom_fcon(nd->nd_REL, nd->nd_type->tp_size); + C_lae_dlb(lab, (arith) 0); + C_loi(nd->nd_type->tp_size); + } break; case STRING: CodeString(nd); @@ -157,8 +153,8 @@ CodeExpr(nd, ds, true_label, false_label) break; case Set: { - arith *st; - int i; + register arith *st = nd->nd_set; + register int i; st = nd->nd_set; ds->dsg_kind = DSG_LOADED; @@ -182,6 +178,8 @@ CodeExpr(nd, ds, true_label, false_label) } if (true_label != 0) { + /* Only for boolean expressions + */ CodeValue(ds, tp->tp_size); *ds = InitDesig; C_zne(true_label); @@ -293,6 +291,7 @@ CodeCall(nd) and result is already done. */ register struct node *left = nd->nd_left; + register struct node *right = nd->nd_right; register struct type *result_tp; if (left->nd_type == std_type) { @@ -303,16 +302,16 @@ CodeCall(nd) if (IsCast(left)) { /* it was just a cast. Simply ignore it */ - CodePExpr(nd->nd_right->nd_left); - *nd = *(nd->nd_right->nd_left); + CodePExpr(right->nd_left); + *nd = *(right->nd_left); nd->nd_type = left->nd_def->df_type; return; } assert(IsProcCall(left)); - if (nd->nd_right) { - CodeParameters(ParamList(left->nd_type), nd->nd_right); + if (right) { + CodeParameters(ParamList(left->nd_type), right); } switch(left->nd_class) { @@ -387,11 +386,9 @@ CodeParameters(param, arg) C_loc((left_type->tp_size+word_size-1) / word_size - 1); } else { - tp = IndexType(left_type); - if (tp->tp_fund == T_SUBRANGE) { - C_loc(tp->sub_ub - tp->sub_lb); - } - else C_loc((arith) (tp->enm_ncst - 1)); + arith lb, ub; + getbounds(IndexType(left_type), &lb, &ub); + C_loc(ub - lb); } C_loc((arith) 0); if (left->nd_symb == STRING) { @@ -417,7 +414,7 @@ CodeStd(nd) register struct node *arg = nd->nd_right; register struct node *left = 0; register struct type *tp = 0; - int std; + int std = nd->nd_left->nd_def->df_value.df_stdname; if (arg) { left = arg->nd_left; @@ -425,7 +422,7 @@ CodeStd(nd) arg = arg->nd_right; } - switch(std = nd->nd_left->nd_def->df_value.df_stdname) { + switch(std) { case S_ABS: CodePExpr(left); if (tp->tp_fund == T_INTEGER) { @@ -446,7 +443,7 @@ CodeStd(nd) case S_CAP: CodePExpr(left); - C_loc((arith) 0137); + C_loc((arith) 0137); /* ASCII assumed */ C_and(word_size); break; @@ -498,34 +495,25 @@ CodeStd(nd) break; case S_DEC: - case S_INC: + case S_INC: { + register arith size = tp->tp_size; + + if (size < word_size) size = word_size; CodePExpr(left); if (arg) CodePExpr(arg->nd_left); else C_loc((arith) 1); - if (tp->tp_size <= word_size) { - if (std == S_DEC) { - if (tp->tp_fund == T_INTEGER) C_sbi(word_size); - else C_sbu(word_size); - } - else { - if (tp->tp_fund == T_INTEGER) C_adi(word_size); - else C_adu(word_size); - } - RangeCheck(tp, int_type); + if (std == S_DEC) { + if (tp->tp_fund == T_INTEGER) C_sbi(size); + else C_sbu(size); } else { - CodeCoercion(int_type, tp); - if (std == S_DEC) { - if (tp->tp_fund==T_INTEGER) C_sbi(tp->tp_size); - else C_sbu(tp->tp_size); - } - else { - if (tp->tp_fund==T_INTEGER) C_adi(tp->tp_size); - else C_adu(tp->tp_size); - } + if (tp->tp_fund == T_INTEGER) C_adi(size); + else C_adu(size); } + if (size == word_size) RangeCheck(tp, int_type); CodeDStore(left); break; + } case S_HALT: C_cal("_halt"); @@ -552,29 +540,30 @@ CodeStd(nd) } CodeAssign(nd, dss, dst) - struct node *nd; + register struct node *nd; struct desig *dst, *dss; { /* Generate code for an assignment. Testing of type compatibility and the like is already done. */ register struct type *tp = nd->nd_right->nd_type; + arith size = nd->nd_left->nd_type->tp_size; if (dss->dsg_kind == DSG_LOADED) { if (tp->tp_fund == T_STRING) { CodeAddress(dst); C_loc(tp->tp_size); - C_loc(nd->nd_left->nd_type->tp_size); + C_loc(size); C_cal("_StringAssign"); C_asp((int_size << 1) + (pointer_size << 1)); return; } - CodeStore(dst, nd->nd_left->nd_type->tp_size); + CodeStore(dst, size); return; } CodeAddress(dss); CodeAddress(dst); - C_blm(nd->nd_left->nd_type->tp_size); + C_blm(size); } RangeCheck(tpl, tpr) @@ -593,7 +582,10 @@ RangeCheck(tpl, tpr) } else { /* both types are restricted. check the bounds - to see wether we need a range check + to see wether we need a range check. + We don't need one if the range of values of the + right hand side is a subset of the range of values + of the left hand side. */ getbounds(tpl, &llo, &lhi); getbounds(tpr, &rlo, &rhi); @@ -806,6 +798,7 @@ CodeOper(expr, true_label, false_label) C_bra(false_label); } break; + case OR: case AND: case '&': { label l_true, l_false, l_maybe = ++text_label, l_end; @@ -822,7 +815,10 @@ CodeOper(expr, true_label, false_label) } Des = InitDesig; - CodeExpr(leftop, &Des, l_maybe, l_false); + if (expr->nd_symb == OR) { + CodeExpr(leftop, &Des, l_true, l_maybe); + } + else CodeExpr(leftop, &Des, l_maybe, l_false); C_df_ilb(l_maybe); Des = InitDesig; CodeExpr(rightop, &Des, l_true, l_false); @@ -836,34 +832,6 @@ CodeOper(expr, true_label, false_label) } break; } - case OR: { - label l_true, l_false, l_maybe = ++text_label, l_end; - struct desig Des; - - if (true_label == 0) { - l_true = ++text_label; - l_false = ++text_label; - l_end = ++text_label; - } - else { - l_true = true_label; - l_false = false_label; - } - Des = InitDesig; - CodeExpr(leftop, &Des, l_true, l_maybe); - C_df_ilb(l_maybe); - Des = InitDesig; - CodeExpr(rightop, &Des, l_true, l_false); - if (true_label == 0) { - C_df_ilb(l_false); - C_loc((arith)0); - C_bra(l_end); - C_df_ilb(l_true); - C_loc((arith)1); - C_df_ilb(l_end); - } - break; - } default: crash("(CodeOper) Bad operator %s\n",symbol2str(expr->nd_symb)); } @@ -958,9 +926,9 @@ CodeUoper(nd) CodeSet(nd) register struct node *nd; { - struct type *tp = nd->nd_type; + register struct type *tp = nd->nd_type; - C_zer(nd->nd_type->tp_size); /* empty set */ + C_zer(tp->tp_size); /* empty set */ nd = nd->nd_right; while (nd) { assert(nd->nd_class == Link && nd->nd_symb == ','); diff --git a/lang/m2/comp/const.h b/lang/m2/comp/const.h index 28cf5c99..37874808 100644 --- a/lang/m2/comp/const.h +++ b/lang/m2/comp/const.h @@ -1,7 +1,5 @@ /* C O N S T A N T S F O R E X P R E S S I O N H A N D L I N G */ -/* $Header$ */ - extern long mach_long_sign; /* sign bit of the machine long */ extern int diff --git a/lang/m2/comp/cstoper.c b/lang/m2/comp/cstoper.c index 6620b985..9e5135c7 100644 --- a/lang/m2/comp/cstoper.c +++ b/lang/m2/comp/cstoper.c @@ -1,9 +1,5 @@ /* C O N S T A N T E X P R E S S I O N H A N D L I N G */ -#ifndef NORCSID -static char *RcsId = "$Header$"; -#endif - #include "debug.h" #include "target_sizes.h" @@ -35,8 +31,10 @@ cstunary(expp) register arith o1 = expp->nd_right->nd_INT; switch(expp->nd_symb) { + /* Should not get here case '+': break; + */ case '-': o1 = -o1; @@ -71,7 +69,7 @@ cstbin(expp) */ register arith o1 = expp->nd_left->nd_INT; register arith o2 = expp->nd_right->nd_INT; - int uns = expp->nd_type != int_type; + register int uns = expp->nd_type != int_type; assert(expp->nd_class == Oper); assert(expp->nd_left->nd_class == Value); diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 167bcf99..9087a00f 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -1,10 +1,6 @@ /* D E C L A R A T I O N S */ { -#ifndef NORCSID -static char *RcsId = "$Header$"; -#endif - #include "debug.h" #include @@ -23,69 +19,38 @@ static char *RcsId = "$Header$"; #include "chk_expr.h" int proclevel = 0; /* nesting level of procedures */ -int return_occurred; /* set if a return occurred in a - procedure or function - */ +int return_occurred; /* set if a return occurs in a block */ } ProcedureDeclaration { - register struct def *df; - struct def *df1; /* only exists because &df is illegal */ + struct def *df; } : - { ++proclevel; - return_occurred = 0; - } - ProcedureHeading(&df1, D_PROCEDURE) - { CurrentScope->sc_definedby = df = df1; - df->prc_vis = CurrVis; - } - ';' block(&(df->prc_body)) IDENT - { match_id(dot.TOK_IDF, df->df_idf); - close_scope(SC_CHKFORW|SC_REVERSE); - if (! return_occurred && ResultType(df->df_type)) { -error("function procedure %s does not return a value", df->df_idf->id_text); - } + { ++proclevel; } + ProcedureHeading(&df, D_PROCEDURE) + ';' block(&(df->prc_body)) + IDENT + { EndProc(df, dot.TOK_IDF); --proclevel; } ; ProcedureHeading(struct def **pdf; int type;) { - struct paramlist *params = 0; - register struct type *tp; - struct type *tp1 = 0; - register struct def *df; - arith NBytesParams; /* parameter offset counter */ + struct type *tp = 0; +#define needs_static_link() (proclevel > 1) + arith parmaddr = needs_static_link() ? pointer_size : 0; + struct paramlist *pr = 0; } : PROCEDURE IDENT - { df = DeclProc(type); - if (proclevel > 1) { /* need room for static link */ - NBytesParams = pointer_size; - } - else NBytesParams = 0; - } - FormalParameters(¶ms, &tp1, &NBytesParams)? - { tp = construct_type(T_PROCEDURE, tp1); - tp->prc_params = params; - tp->prc_nbpar = NBytesParams; - if (df->df_type) { - /* We already saw a definition of this type - in the definition module. - */ - if (!TstProcEquiv(tp, df->df_type)) { -error("inconsistent procedure declaration for \"%s\"", df->df_idf->id_text); - } - FreeType(df->df_type); - } - df->df_type = tp; - *pdf = df; - } + { *pdf = DeclProc(type, dot.TOK_IDF); } + FormalParameters(&pr, &parmaddr, &tp)? + { CheckWithDef(*pdf, proc_type(tp, pr, parmaddr)); } ; block(struct node **pnd;) : declaration* - [ + [ { return_occurred = 0; } BEGIN StatementSequence(pnd) | @@ -106,15 +71,12 @@ declaration: ModuleDeclaration ';' ; -FormalParameters(struct paramlist **pr; - struct type **ptp; - arith *parmaddr;) -: +FormalParameters(struct paramlist *ppr; arith *parmaddr; struct type **ptp;): '(' [ - FPSection(pr, parmaddr) + FPSection(ppr, parmaddr) [ - ';' FPSection(pr, parmaddr) + ';' FPSection(ppr, parmaddr) ]* ]? ')' @@ -134,12 +96,12 @@ FPSection(struct paramlist **ppr; arith *parmaddr;) FormalType(struct type **ptp;) { - register struct type *tp; extern arith ArrayElSize(); } : ARRAY OF qualtype(ptp) - { tp = construct_type(T_ARRAY, NULLTYPE); - tp->arr_elem = *ptp; *ptp = tp; + { register struct type *tp = construct_type(T_ARRAY, NULLTYPE); + tp->arr_elem = *ptp; + *ptp = tp; tp->arr_elsize = ArrayElSize(tp->arr_elem); tp->tp_align = lcm(word_align, pointer_align); } @@ -194,12 +156,12 @@ SimpleType(struct type **ptp;) enumeration(struct type **ptp;) { struct node *EnumList; - register struct type *tp; } : '(' IdentList(&EnumList) ')' - { *ptp = tp = standard_type(T_ENUMERATION, 1, (arith) 1); - EnterEnumList(EnumList, tp); - if (tp->enm_ncst > 256) { /* ??? is this reasonable ??? */ + { + *ptp = standard_type(T_ENUMERATION, 1, (arith) 1); + EnterEnumList(EnumList, *ptp); + if ((*ptp)->enm_ncst > 256) { /* ??? is this reasonable ??? */ error("Too many enumeration literals"); } } @@ -230,7 +192,10 @@ SubrangeType(struct type **ptp;) '[' ConstExpression(&nd1) UPTO ConstExpression(&nd2) ']' - { *ptp = subr_type(nd1, nd2); } + { *ptp = subr_type(nd1, nd2); + free_node(nd1); + free_node(nd2); + } ; ArrayType(struct type **ptp;) @@ -254,18 +219,18 @@ ArrayType(struct type **ptp;) RecordType(struct type **ptp;) { register struct scope *scope; - arith count; + arith size; int xalign = struct_align; } : RECORD - { open_scope(OPENSCOPE); + { open_scope(OPENSCOPE); /* scope for fields of record */ scope = CurrentScope; close_scope(0); - count = 0; + size = 0; } - FieldListSequence(scope, &count, &xalign) - { *ptp = standard_type(T_RECORD, xalign, WA(count)); + FieldListSequence(scope, &size, &xalign) + { *ptp = standard_type(T_RECORD, xalign, WA(size)); (*ptp)->rec_scope = scope; } END @@ -281,10 +246,10 @@ FieldListSequence(struct scope *scope; arith *cnt; int *palign;): FieldList(struct scope *scope; arith *cnt; int *palign;) { struct node *FldList; - register struct idf *id = gen_anon_idf(); - register struct def *df; + register struct idf *id = 0; struct type *tp; - struct node *nd; + struct node *nd1; + register struct node *nd; arith tcnt, max; } : [ @@ -294,77 +259,81 @@ FieldList(struct scope *scope; arith *cnt; int *palign;) } | CASE - /* Also accept old fashioned Modula-2 syntax, but give a warning + /* Also accept old fashioned Modula-2 syntax, but give a warning. + Sorry for the complicated code. */ - [ qualident(0, (struct def **) 0, (char *) 0, &nd) - [ ':' qualtype(&tp) + [ qualident(0, (struct def **) 0, (char *) 0, &nd1) + { nd = nd1; } + [ ':' qualtype(&tp) /* This is correct, in both kinds of Modula-2, if - the first qualident is a single identifier. + the first qualident is a single identifier. */ - { if (nd->nd_class != Name) { - error("illegal variant tag"); - } - else id = nd->nd_IDF; - } - | - /* Old fashioned! the first qualident now represents + { if (nd->nd_class != Name) { + error("illegal variant tag"); + } + else id = nd->nd_IDF; + FreeNode(nd); + } + | /* Old fashioned! the first qualident now represents the type */ - { warning("Old fashioned Modula-2 syntax!"); - if (ChkDesignator(nd) && - (nd->nd_class != Def || - !(nd->nd_def->df_kind&(D_ERROR|D_ISTYPE)) || - !nd->nd_def->df_type)) { - node_error(nd, "type expected"); - tp = error_type; - } - else tp = nd->nd_def->df_type; - FreeNode(nd); - } - ] - | - /* Aha, third edition. Well done! */ - ':' qualtype(&tp) + { warning("Old fashioned Modula-2 syntax; ':' missing"); + if (ChkDesignator(nd) && + (nd->nd_class != Def || + !(nd->nd_def->df_kind&(D_ERROR|D_ISTYPE)) || + !nd->nd_def->df_type)) { + node_error(nd, "type expected"); + tp = error_type; + } + else tp = nd->nd_def->df_type; + FreeNode(nd); + } + ] + | ':' qualtype(&tp) + /* Aha, third edition. Well done! */ ] - { if (!(tp->tp_fund & T_DISCRETE)) { + { if (id) { + register struct def *df = define(id, + scope, + D_FIELD); + if (!(tp->tp_fund & T_DISCRETE)) { error("Illegal type in variant"); - } - df = define(id, scope, D_FIELD); - df->df_type = tp; - df->fld_off = align(*cnt, tp->tp_align); - *cnt = tcnt = df->fld_off + tp->tp_size; - df->df_flags |= D_QEXPORTED; - } + } + df->df_type = tp; + df->fld_off = align(*cnt, tp->tp_align); + *cnt = tcnt = df->fld_off + tp->tp_size; + df->df_flags |= D_QEXPORTED; + } + } OF variant(scope, &tcnt, tp, palign) - { max = tcnt; tcnt = *cnt; } + { max = tcnt; tcnt = *cnt; } [ - '|' variant(scope, &tcnt, tp, palign) - { if (tcnt > max) max = tcnt; tcnt = *cnt; } + '|' variant(scope, &tcnt, tp, palign) + { if (tcnt > max) max = tcnt; tcnt = *cnt; } ]* [ ELSE FieldListSequence(scope, &tcnt, palign) - { if (tcnt > max) max = tcnt; } + { if (tcnt > max) max = tcnt; } ]? END - { *cnt = max; } + { *cnt = max; } ]? ; variant(struct scope *scope; arith *cnt; struct type *tp; int *palign;) { - struct type *tp1 = tp; struct node *nd; } : [ - CaseLabelList(&tp1, &nd) - { /* Ignore the cases for the time being. - Maybe a checking version will be supplied - later ??? - */ - FreeNode(nd); - } + CaseLabelList(&tp, &nd) + { /* Ignore the cases for the time being. + Maybe a checking version will be supplied + later ??? (Improbable) + */ + FreeNode(nd); + } ':' FieldListSequence(scope, cnt, palign) ]? - /* Changed rule in new modula-2 */ + /* Changed rule in new modula-2 */ ; CaseLabelList(struct type **ptp; struct node **pnd;): @@ -376,27 +345,29 @@ CaseLabelList(struct type **ptp; struct node **pnd;): ]* ; -CaseLabels(struct type **ptp; struct node **pnd;) +CaseLabels(struct type **ptp; register struct node **pnd;) { - struct node *nd1, *nd2 = 0; + register struct node *nd1; }: - ConstExpression(&nd1) { *pnd = nd1; } + ConstExpression(pnd) + { nd1 = *pnd; } [ - UPTO { *pnd = MkNode(Link,nd1,NULLNODE,&dot); } - ConstExpression(&nd2) - { if (!TstCompat(nd1->nd_type, nd2->nd_type)) { -node_error(nd2,"type incompatibility in case label"); - nd1->nd_type = error_type; - } - (*pnd)->nd_right = nd2; - } + UPTO { *pnd = MkNode(Link,nd1,NULLNODE,&dot); } + ConstExpression(&(*pnd)->nd_right) + { if (!TstCompat(nd1->nd_type, + (*pnd)->nd_right->nd_type)) { + node_error((*pnd)->nd_right, + "type incompatibility in case label"); + nd1->nd_type = error_type; + } + } ]? - { if (*ptp != 0 && - !TstCompat(*ptp, nd1->nd_type)) { -node_error(nd1,"type incompatibility in case label"); - } - *ptp = nd1->nd_type; - } + { if (*ptp != 0 && !TstCompat(*ptp, nd1->nd_type)) { + node_error(nd1, + "type incompatibility in case label"); + } + *ptp = nd1->nd_type; + } ; SetType(struct type **ptp;) : @@ -410,7 +381,7 @@ SetType(struct type **ptp;) : */ PointerType(struct type **ptp;) { - register struct node *nd; + register struct node *nd = 0; } : POINTER TO { *ptp = construct_type(T_POINTER, NULLTYPE); } @@ -418,49 +389,51 @@ PointerType(struct type **ptp;) /* Either a Module or a Type, but in both cases defined in this scope, so this is the correct identification */ - qualtype(&((*ptp)->next)) - | %if ( nd = new_node(), nd->nd_token = dot, + qualtype(&((*ptp)->next)) + | %if ( nd = new_node(), + nd->nd_token = dot, lookfor(nd, CurrVis, 0)->df_kind == D_MODULE) - { if (dot.tk_symb == IDENT) free_node(nd); } - type(&((*ptp)->next)) + type(&((*ptp)->next)) + { if (nd) free_node(nd); } | - IDENT { Forward(nd, (*ptp)); } + IDENT { Forward(nd, (*ptp)); } ] ; qualtype(struct type **ptp;) { - struct def *df; + struct def *df = 0; } : qualident(D_ISTYPE, &df, "type", (struct node **) 0) - { if (!(*ptp = df->df_type)) { - error("type \"%s\" not declared", df->df_idf->id_text); - *ptp = error_type; - } - } + { if (df && !(*ptp = df->df_type)) { + error("type \"%s\" not declared", + df->df_idf->id_text); + *ptp = error_type; + } + } ; ProcedureType(struct type **ptp;) { struct paramlist *pr = 0; - register struct type *tp; - arith nbytes = 0; -} : + arith parmaddr = 0; +} +: { *ptp = 0; } - PROCEDURE FormalTypeList(&pr, ptp, &nbytes)? - { *ptp = tp = construct_type(T_PROCEDURE, *ptp); - tp->prc_params = pr; - tp->prc_nbpar = nbytes; - } + PROCEDURE + [ + FormalTypeList(&pr, &parmaddr, ptp) + ]? + { *ptp = proc_type(*ptp, pr, parmaddr); } ; -FormalTypeList(struct paramlist **ppr; struct type **ptp; arith *parmaddr;) +FormalTypeList(struct paramlist **ppr; arith *parmaddr; struct type **ptp;) { - int VARp; struct type *tp; + int VARp; } : - '(' { *ppr = 0; } + '(' [ var(&VARp) FormalType(&tp) { EnterParamList(ppr,NULLNODE,tp,VARp,parmaddr); } diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H index 56431ae6..226395c3 100644 --- a/lang/m2/comp/def.H +++ b/lang/m2/comp/def.H @@ -1,7 +1,5 @@ /* I D E N T I F I E R D E S C R I P T O R S T R U C T U R E */ -/* $Header$ */ - struct module { arith mo_priority; /* priority of a module */ struct scopelist *mo_vis;/* scope of this module */ @@ -82,12 +80,12 @@ struct def { /* list of definitions for a name */ #define D_IMPORT 0x0080 /* an imported definition */ #define D_PROCHEAD 0x0100 /* a procedure heading in a definition module */ #define D_HIDDEN 0x0200 /* a hidden type */ -#define D_FORWARD 0x0800 /* not yet defined */ -#define D_UNDEF_IMPORT 0x1000 /* imported from an undefined name */ -#define D_FORWMODULE 0x2000 /* module must be declared later */ -#define D_ERROR 0x4000 /* a compiler generated definition for an +#define D_FORWARD 0x0400 /* not yet defined */ +#define D_FORWMODULE 0x0800 /* module must be declared later */ +#define D_ERROR 0x1000 /* a compiler generated definition for an undefined variable */ +#define D_VALUE (D_PROCEDURE|D_VARIABLE|D_FIELD|D_ENUM|D_CONST|D_PROCHEAD) #define D_ISTYPE (D_HIDDEN|D_TYPE) #define is_type(dfx) ((dfx)->df_kind & D_ISTYPE) char df_flags; @@ -115,14 +113,13 @@ struct def { /* list of definitions for a name */ #define SetUsed(df) ((df)->df_flags |= D_USED) -/* ALLOCDEF "def" */ +/* ALLOCDEF "def" 50 */ extern struct def *define(), *DefineLocalModule(), *MkDef(), - *DeclProc(), - *ill_df; + *DeclProc(); extern struct def *lookup(), diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index 04b43ebe..c57f9154 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -1,9 +1,5 @@ /* D E F I N I T I O N M E C H A N I S M */ -#ifndef NORCSID -static char *RcsId = "$Header$"; -#endif - #include "debug.h" #include @@ -25,11 +21,42 @@ struct def *h_def; /* pointer to free list of def structures */ int cnt_def; /* count number of allocated ones */ #endif -struct def *ill_df; +STATIC +DefInFront(df) + register struct def *df; +{ + /* Put definition "df" in front of the list of definitions + in its scope. + This is neccessary because in some cases the order in this + list is important. + */ + register struct def *df1 = df->df_scope->sc_def; + + if (df1 != df) { + /* Definition "df" is not in front of the list + */ + while (df1) { + /* Find definition "df" + */ + if (df1->df_nextinscope == df) { + /* It already was in the list. Remove it + */ + df1->df_nextinscope = df->df_nextinscope; + break; + } + df1 = df1->df_nextinscope; + } + + /* Now put it in front + */ + df->df_nextinscope = df->df_scope->sc_def; + df->df_scope->sc_def = df; + } +} struct def * MkDef(id, scope, kind) - struct idf *id; + register struct idf *id; register struct scope *scope; { /* Create a new definition structure in scope "scope", with @@ -38,7 +65,6 @@ MkDef(id, scope, kind) register struct def *df; df = new_def(); - clear((char *) df, sizeof (*df)); df->df_idf = id; df->df_scope = scope; df->df_kind = kind; @@ -52,24 +78,16 @@ MkDef(id, scope, kind) return df; } -InitDef() -{ - /* Initialize this module. Easy, the only thing to be initialized - is "ill_df". - */ - struct idf *gen_anon_idf(); - - ill_df = MkDef(gen_anon_idf(), CurrentScope, D_ERROR); - ill_df->df_type = error_type; -} - struct def * define(id, scope, kind) register struct idf *id; register struct scope *scope; + int kind; { /* Declare an identifier in a scope, but first check if it - already has been defined. If so, error message. + already has been defined. + If so, then check for the cases in which this is legal, + and otherwise give an error message. */ register struct def *df; @@ -133,7 +151,8 @@ define(id, scope, kind) if (kind != D_ERROR) { /* Avoid spurious error messages */ -error("identifier \"%s\" already declared", id->id_text); + error("identifier \"%s\" already declared", + id->id_text); } return df; @@ -143,7 +162,7 @@ error("identifier \"%s\" already declared", id->id_text); } RemoveImports(pdf) - struct def **pdf; + register struct def **pdf; { /* Remove all imports from a definition module. This is neccesary because the implementation module might import @@ -165,16 +184,15 @@ RemoveImports(pdf) } RemoveFromIdList(df) - struct def *df; + register struct def *df; { /* Remove definition "df" from the definition list */ register struct idf *id = df->df_idf; register struct def *df1; - if (id->id_def == df) id->id_def = df->next; + if ((df1 = id->id_def) == df) id->id_def = df->next; else { - df1 = id->id_def; while (df1->next != df) { assert(df1->next != 0); df1 = df1->next; @@ -184,13 +202,15 @@ RemoveFromIdList(df) } struct def * -DeclProc(type) +DeclProc(type, id) + register struct idf *id; { /* A procedure is declared, either in a definition or a program module. Create a def structure for it (if neccessary). Also create a name for it. */ register struct def *df; + register struct scope *scope; extern char *sprint(); static int nmcount; char buf[256]; @@ -200,85 +220,61 @@ DeclProc(type) if (type == D_PROCHEAD) { /* In a definition module */ - df = define(dot.TOK_IDF, CurrentScope, type); + df = define(id, CurrentScope, type); df->for_node = MkLeaf(Name, &dot); - sprint(buf,"%s_%s",CurrentScope->sc_name,df->df_idf->id_text); + sprint(buf,"%s_%s",CurrentScope->sc_name,id->id_text); df->for_name = Salloc(buf, (unsigned) (strlen(buf)+1)); - if (CurrVis == Defined->mod_vis) C_exp(df->for_name); + if (CurrVis == Defined->mod_vis) { + /* The current module will define this routine. + make sure the name is exported. + */ + C_exp(df->for_name); + } } else { - df = lookup(dot.TOK_IDF, CurrentScope); + char *name; + + df = lookup(id, CurrentScope); if (df && df->df_kind == D_PROCHEAD) { /* C_exp already generated when we saw the definition in the definition module */ df->df_kind = D_PROCEDURE; - open_scope(OPENSCOPE); - CurrentScope->sc_name = df->for_name; - df->prc_vis = CurrVis; + name = df->for_name; DefInFront(df); } else { - df = define(dot.TOK_IDF, CurrentScope, type); - open_scope(OPENSCOPE); - df->prc_vis = CurrVis; - sprint(buf,"_%d_%s",++nmcount,df->df_idf->id_text); - CurrentScope->sc_name = - Salloc(buf, (unsigned)(strlen(buf)+1)); + df = define(id, CurrentScope, type); + sprint(buf,"_%d_%s",++nmcount,id->id_text); + name = Salloc(buf, (unsigned)(strlen(buf)+1)); C_inp(buf); } + open_scope(OPENSCOPE); + scope = CurrentScope; + scope->sc_name = name; + scope->sc_definedby = df; + df->prc_vis = CurrVis; } return df; } -AddModule(id) +EndProc(df, id) + register struct def *df; struct idf *id; { - /* Add the name of a module to the Module list. This list is - maintained to create the initialization routine of the - program/implementation module currently defined. + /* The end of a procedure declaration. + Check that the closing identifier matches the name of the + procedure, close the scope, and check that a function + procedure has at least one RETURN statement. */ - static struct node *nd_end; /* to remember end of list */ - register struct node *n; - extern struct node *Modules; + extern int return_occurred; - n = MkLeaf(Name, &dot); - n->nd_IDF = id; - n->nd_symb = IDENT; - if (nd_end) nd_end->next = n; - else Modules = n; - nd_end = n; -} - -DefInFront(df) - register struct def *df; -{ - /* Put definition "df" in front of the list of definitions - in its scope. - This is neccessary because in some cases the order in this - list is important. - */ - register struct def *df1 = df->df_scope->sc_def; - - if (df1 != df) { - /* Definition "df" is not in front of the list - */ - while (df1 && df1->df_nextinscope != df) { - /* Find definition "df" - */ - df1 = df1->df_nextinscope; - } - if (df1) { - /* It already was in the list. Remove it - */ - df1->df_nextinscope = df->df_nextinscope; - } - - /* Now put it in front - */ - df->df_nextinscope = df->df_scope->sc_def; - df->df_scope->sc_def = df; + match_id(id, df->df_idf); + close_scope(SC_CHKFORW|SC_REVERSE); + if (! return_occurred && ResultType(df->df_type)) { + error("function procedure %s does not return a value", + df->df_idf->id_text); } } @@ -326,6 +322,27 @@ DefineLocalModule(id) return df; } +CheckWithDef(df, tp) + register struct def *df; + struct type *tp; +{ + /* Check the header of a procedure declaration against a + possible earlier definition in the definition module. + */ + + if (df->df_type) { + /* We already saw a definition of this type + in the definition module. + */ + if (!TstProcEquiv(tp, df->df_type)) { + error("inconsistent procedure declaration for \"%s\"", + df->df_idf->id_text); + } + FreeType(df->df_type); + } + df->df_type = tp; +} + #ifdef DEBUG PrDef(df) register struct def *df; diff --git a/lang/m2/comp/defmodule.c b/lang/m2/comp/defmodule.c index 94881826..3ba1f6d8 100644 --- a/lang/m2/comp/defmodule.c +++ b/lang/m2/comp/defmodule.c @@ -1,9 +1,5 @@ /* D E F I N I T I O N M O D U L E S */ -#ifndef NORCSID -static char *RcsId = "$Header$"; -#endif - #include "debug.h" #include @@ -15,23 +11,27 @@ static char *RcsId = "$Header$"; #include "scope.h" #include "def.h" #include "LLlex.h" +#include "Lpars.h" #include "f_info.h" #include "main.h" +#include "node.h" #ifdef DEBUG long sys_filesize(); #endif +struct idf * CurrentId; + GetFile(name) char *name; { /* Try to find a file with basename "name" and extension ".def", in the directories mentioned in "DEFPATH". */ - char buf[256]; + char buf[15]; char *strcpy(), *strcat(); - strcpy(buf, name); + strncpy(buf, name, 10); buf[10] = '\0'; /* maximum length */ strcat(buf, ".def"); if (! InsertFile(buf, DEFPATH, &(FileName))) { @@ -42,17 +42,18 @@ GetFile(name) } struct def * -GetDefinitionModule(id) - struct idf *id; +GetDefinitionModule(id, incr) + register struct idf *id; { /* Return a pointer to the "def" structure of the definition module indicated by "id". We may have to read the definition module itself. + Also increment level by "incr". */ struct def *df; static int level; - level++; + level += incr; df = lookup(id, GlobalScope); if (!df) { /* Read definition module. Make an exception for SYSTEM. @@ -62,6 +63,8 @@ GetDefinitionModule(id) } else { GetFile(id->id_text); + CurrentId = id; + open_scope(CLOSEDSCOPE); DefModule(); if (level == 1) { /* The module is directly imported by the @@ -69,12 +72,23 @@ GetDefinitionModule(id) remember its name because we have to call its initialization routine */ - AddModule(id); + static struct node *nd_end; /* end of list */ + register struct node *n; + extern struct node *Modules; + + n = MkLeaf(Name, &dot); + n->nd_IDF = id; + n->nd_symb = IDENT; + if (nd_end) nd_end->next = n; + else Modules = n; + nd_end = n; } + close_scope(SC_CHKFORW); } df = lookup(id, GlobalScope); } + CurrentId = 0; assert(df && df->df_kind == D_MODULE); - level--; + level -= incr; return df; } diff --git a/lang/m2/comp/desig.c b/lang/m2/comp/desig.c index c9fca726..b8736335 100644 --- a/lang/m2/comp/desig.c +++ b/lang/m2/comp/desig.c @@ -1,9 +1,5 @@ /* D E S I G N A T O R E V A L U A T I O N */ -#ifndef NORCSID -static char *RcsId = "$Header$"; -#endif - /* Code generation for designators. This file contains some routines that generate code common to address as well as value computations, and leave a description in a "desig" @@ -166,7 +162,6 @@ CodeFieldDesig(df, ds) in "ds". "df" indicates the definition of the field. */ - if (ds->dsg_kind == DSG_INIT) { /* In a WITH statement. We must find the designator in the WITH statement, and act as if the field is a selection diff --git a/lang/m2/comp/desig.h b/lang/m2/comp/desig.h index a7c1c736..4b6bb97b 100644 --- a/lang/m2/comp/desig.h +++ b/lang/m2/comp/desig.h @@ -1,7 +1,5 @@ /* D E S I G N A T O R D E S C R I P T I O N S */ -/* $Header$ */ - /* Generating code for designators is not particularly easy, especially if you don't know wether you want the address or the value. The next structure is used to generate code for designators. diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index 237ee29b..85f1f764 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -1,9 +1,5 @@ /* H I G H L E V E L S Y M B O L E N T R Y */ -#ifndef NORCSID -static char *RcsId = "$Header$"; -#endif - #include "debug.h" #include @@ -119,7 +115,8 @@ EnterVarList(Idlist, type, local) df->var_addrgiven = 1; df->df_flags |= D_NOREG; if (idlist->nd_left->nd_type != card_type) { -node_error(idlist->nd_left,"Illegal type for address"); + node_error(idlist->nd_left, + "Illegal type for address"); } df->var_off = idlist->nd_left->nd_INT; } @@ -155,8 +152,8 @@ node_error(idlist->nd_left,"Illegal type for address"); } EnterParamList(ppr, Idlist, type, VARp, off) - struct node *Idlist; struct paramlist **ppr; + struct node *Idlist; struct type *type; int VARp; arith *off; @@ -178,18 +175,14 @@ EnterParamList(ppr, Idlist, type, VARp, off) for ( ; idlist; idlist = idlist->next) { pr = new_paramlist(); pr->next = 0; - if (!*ppr) { - *ppr = pr; - } + if (!*ppr) *ppr = pr; else last->next = pr; last = pr; if (!DefinitionModule && idlist != dummy) { df = define(idlist->nd_IDF, CurrentScope, D_VARIABLE); df->var_off = *off; } - else { - df = new_def(); - } + else df = new_def(); pr->par_def = df; df->df_type = type; df->df_flags = VARp; @@ -259,11 +252,11 @@ ForwModule(df, idn) enclosing scope, but this must be done AFTER closing this one */ - df->for_vis = vis; - df->for_node = MkLeaf(Name, &(idn->nd_token)); close_scope(0); vis->sc_encl = enclosing(CurrVis); /* Here ! */ + df->for_vis = vis; + df->for_node = MkLeaf(Name, &(idn->nd_token)); return vis; } @@ -294,7 +287,6 @@ EnterExportList(Idlist, qualified) */ register struct node *idlist = Idlist; register struct def *df, *df1; - register struct def *impmod; for (;idlist; idlist = idlist->next) { df = lookup(idlist->nd_IDF, CurrentScope); @@ -302,13 +294,16 @@ EnterExportList(Idlist, qualified) if (!df) { /* undefined item in export list */ -node_error(idlist, "identifier \"%s\" not defined", idlist->nd_IDF->id_text); + node_error(idlist, + "identifier \"%s\" not defined", + idlist->nd_IDF->id_text); continue; } if (df->df_flags & (D_EXPORTED|D_QEXPORTED)) { -node_error(idlist, "identifier \"%s\" occurs more than once in export list", -idlist->nd_IDF->id_text); + node_error(idlist, + "multiple occurrences of \"%s\" in export list", + idlist->nd_IDF->id_text); } df->df_flags |= qualified; @@ -317,13 +312,13 @@ idlist->nd_IDF->id_text); Find all imports of the module in which this export occurs, and export the current definition to it */ - impmod = CurrentScope->sc_definedby->df_idf->id_def; - while (impmod) { - if (impmod->df_kind == D_IMPORT && - impmod->imp_def == CurrentScope->sc_definedby) { - DoImport(df, impmod->df_scope); + df1 = CurrentScope->sc_definedby->df_idf->id_def; + while (df1) { + if (df1->df_kind == D_IMPORT && + df1->imp_def == CurrentScope->sc_definedby) { + DoImport(df, df1->df_scope); } - impmod = impmod->next; + df1 = df1->next; } /* Also handle the definition as if the enclosing @@ -345,7 +340,9 @@ idlist->nd_IDF->id_text); if (df1->df_kind == D_HIDDEN && df->df_kind == D_TYPE) { if (df->df_type->tp_fund != T_POINTER) { -node_error(idlist, "opaque type \"%s\" is not a pointer type", df->df_idf->id_text); + node_error(idlist, +"opaque type \"%s\" is not a pointer type", + df->df_idf->id_text); } assert(df1->df_type->next == NULLTYPE); df1->df_kind = D_TYPE; @@ -388,23 +385,23 @@ EnterFromImportList(Idlist, FromDef) vis = FromDef->mod_vis; break; default: -error("identifier \"%s\" does not represent a module", -FromDef->df_idf->id_text); + error("identifier \"%s\" does not represent a module", + FromDef->df_idf->id_text); break; } for (; idlist; idlist = idlist->next) { - if (forwflag) { - df = ForwDef(idlist, vis->sc_scope); - } - else if (!(df = lookup(idlist->nd_IDF, vis->sc_scope))) { -node_error(idlist, "identifier \"%s\" not declared in qualifying module", -idlist->nd_IDF->id_text); + if (forwflag) df = ForwDef(idlist, vis->sc_scope); + else if (! (df = lookup(idlist->nd_IDF, vis->sc_scope))) { + node_error(idlist, + "identifier \"%s\" not declared in qualifying module", + idlist->nd_IDF->id_text); df = define(idlist->nd_IDF,vis->sc_scope,D_ERROR); } - else if (!(df->df_flags&(D_EXPORTED|D_QEXPORTED))) { -node_error(idlist,"identifier \"%s\" not exported from qualifying module", -idlist->nd_IDF->id_text); + else if (! (df->df_flags & (D_EXPORTED|D_QEXPORTED))) { + node_error(idlist, + "identifier \"%s\" not exported from qualifying module", + idlist->nd_IDF->id_text); df->df_flags |= D_QEXPORTED; } DoImport(df, CurrentScope); @@ -422,14 +419,14 @@ EnterImportList(Idlist, local) This case is indicated by the value 0 of the "local" flag. */ register struct node *idlist = Idlist; - register struct def *df; - struct scopelist *vis = enclosing(CurrVis); + struct scope *sc = enclosing(CurrVis)->sc_scope; extern struct def *GetDefinitionModule(); for (; idlist; idlist = idlist->next) { - if (local) df = ForwDef(idlist, vis->sc_scope); - else df = GetDefinitionModule(idlist->nd_IDF); - DoImport(df, CurrentScope); + DoImport(local ? + ForwDef(idlist, sc) : + GetDefinitionModule(idlist->nd_IDF) , + CurrentScope); } FreeNode(Idlist); } diff --git a/lang/m2/comp/error.c b/lang/m2/comp/error.c index 3c612e16..cde6d7c3 100644 --- a/lang/m2/comp/error.c +++ b/lang/m2/comp/error.c @@ -5,10 +5,6 @@ number of arguments! */ -#ifndef NORCSID -static char *RcsId = "$Header$"; -#endif - #include "errout.h" #include "debug.h" diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index 18a04cba..bd2f8d64 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -1,10 +1,6 @@ /* E X P R E S S I O N S */ { -#ifndef NORCSID -static char *RcsId = "$Header$"; -#endif - #include "debug.h" #include @@ -38,22 +34,19 @@ qualident(int types; struct node **p; ) { - register struct def *df; struct node *nd; } : IDENT { nd = MkLeaf(Name, &dot); } [ selector(&nd) ]* - { if (types) { - df = ill_df; - - if (ChkDesignator(nd)) { - if (nd->nd_class != Def) { + { if (types && ChkDesignator(nd)) { + if (nd->nd_class != Def) { node_error(nd, "%s expected", str); - } - else { - df = nd->nd_def; + } + else { + register struct def *df = nd->nd_def; + if ( !((types|D_ERROR) & df->df_kind)) { if (df->df_kind == D_FORWARD) { node_error(nd,"%s \"%s\" not declared", str, df->df_idf->id_text); @@ -62,9 +55,8 @@ node_error(nd,"%s \"%s\" not declared", str, df->df_idf->id_text); node_error(nd,"identifier \"%s\" is not a %s", df->df_idf->id_text, str); } } - } + if (pdf) *pdf = df; } - *pdf = df; } if (!p) FreeNode(nd); else *p = nd; @@ -170,10 +162,9 @@ MulOperator: factor(register struct node **p;) { - struct def *df; struct node *nd; } : - qualident(0, &df, (char *) 0, p) + qualident(0, (struct def **) 0, (char *) 0, p) [ designator_tail(p)? [ @@ -236,10 +227,8 @@ element(struct node *nd;) ; designator(struct node **pnd;) -{ - struct def *df; -} : - qualident(0, &df, (char *) 0, pnd) +: + qualident(0, (struct def **) 0, (char *) 0, pnd) designator_tail(pnd)? ; diff --git a/lang/m2/comp/f_info.h b/lang/m2/comp/f_info.h index edee620d..7efbec72 100644 --- a/lang/m2/comp/f_info.h +++ b/lang/m2/comp/f_info.h @@ -1,7 +1,5 @@ /* F I L E D E S C R I P T O R S T R U C T U R E */ -/* $Header$ */ - struct f_info { unsigned short f_lineno; char *f_filename; diff --git a/lang/m2/comp/idf.c b/lang/m2/comp/idf.c index 3f59640a..6fc41b52 100644 --- a/lang/m2/comp/idf.c +++ b/lang/m2/comp/idf.c @@ -1,6 +1,4 @@ /* I N S T A N T I A T I O N O F I D F P A C K A G E */ -/* $Header$ */ - #include "idf.h" #include diff --git a/lang/m2/comp/idf.h b/lang/m2/comp/idf.h index 60322ff4..62e72bb5 100644 --- a/lang/m2/comp/idf.h +++ b/lang/m2/comp/idf.h @@ -1,7 +1,5 @@ /* U S E R D E C L A R E D P A R T O F I D F */ -/* $Header$ */ - struct id_u { int id_res; struct def *id_df; diff --git a/lang/m2/comp/input.c b/lang/m2/comp/input.c index 7dd53d9b..acf29915 100644 --- a/lang/m2/comp/input.c +++ b/lang/m2/comp/input.c @@ -1,17 +1,25 @@ /* I N S T A N T I A T I O N O F I N P U T P A C K A G E */ -/* $Header$ */ - #include "f_info.h" struct f_info file_info; #include "input.h" +#include +#include +#include "def.h" +#include "idf.h" +#include "scope.h" #include +extern struct idf *CurrentId; + AtEoIF() { /* Make the unstacking of input streams noticable to the lexical analyzer */ + if (CurrentId && ! lookup(CurrentId, GlobalScope)) { +fatal("No definition module read for \"%s\"", CurrentId->id_text); + } return 1; } diff --git a/lang/m2/comp/input.h b/lang/m2/comp/input.h index abb111c6..74ac774b 100644 --- a/lang/m2/comp/input.h +++ b/lang/m2/comp/input.h @@ -1,7 +1,5 @@ /* I N S T A N T I A T I O N O F I N P U T M O D U L E */ -/* $Header$ */ - #include "inputtype.h" #define INP_NPUSHBACK 2 diff --git a/lang/m2/comp/lookup.c b/lang/m2/comp/lookup.c index a2785916..7109e6a5 100644 --- a/lang/m2/comp/lookup.c +++ b/lang/m2/comp/lookup.c @@ -1,9 +1,5 @@ /* L O O K U P R O U T I N E S */ -#ifndef NORCSID -static char *RcsId = "$Header$"; -#endif - #include "debug.h" #include diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index 18d1ad6d..2ac8c2e5 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -1,9 +1,5 @@ /* M A I N P R O G R A M */ -#ifndef NORCSID -static char *RcsId = "$Header$"; -#endif - #include "debug.h" #include "ndir.h" @@ -26,7 +22,6 @@ static char *RcsId = "$Header$"; int state; /* either IMPLEMENTATION or PROGRAM */ char options[128]; int DefinitionModule; -int SYSTEMModule; char *ProgName; char *DEFPATH[NDIRS+1]; struct def *Defined; @@ -73,7 +68,6 @@ Compile(src, dst) reserve(tkidf); InitScope(); InitTypes(); - InitDef(); AddStandards(); #ifdef DEBUG if (options['l']) { @@ -186,27 +180,29 @@ AddStandards() df->enm_next = 0; } -do_SYSTEM() -{ - /* Simulate the reading of the SYSTEM definition module - */ - char *SYSTEM = "\ +/* How do you like that! Modula-2 in a C-program. +*/ +char SYSTEM[] = "\ DEFINITION MODULE SYSTEM;\n\ +TYPE PROCESS = ADDRESS;\n\ PROCEDURE NEWPROCESS(P:PROC; A:ADDRESS; n:CARDINAL; VAR p1:ADDRESS);\n\ PROCEDURE TRANSFER(VAR p1,p2:ADDRESS);\n\ END SYSTEM.\n"; +do_SYSTEM() +{ + /* Simulate the reading of the SYSTEM definition module + */ open_scope(CLOSEDSCOPE); (void) Enter("WORD", D_TYPE, word_type, 0); (void) Enter("ADDRESS", D_TYPE, address_type, 0); (void) Enter("ADR", D_PROCEDURE, std_type, S_ADR); (void) Enter("TSIZE", D_PROCEDURE, std_type, S_TSIZE); - if (!InsertText(SYSTEM, strlen(SYSTEM))) { + if (!InsertText(SYSTEM, sizeof(SYSTEM) - 1)) { fatal("Could not insert text"); } - SYSTEMModule = 1; DefModule(); - SYSTEMModule = 0; + close_scope(SC_CHKFORW); } #ifdef DEBUG diff --git a/lang/m2/comp/main.h b/lang/m2/comp/main.h index 642f7f5e..906af4cb 100644 --- a/lang/m2/comp/main.h +++ b/lang/m2/comp/main.h @@ -1,7 +1,5 @@ /* S O M E G L O B A L V A R I A B L E S */ -/* $Header$ */ - extern char options[]; /* indicating which options were given */ extern int DefinitionModule; @@ -9,9 +7,6 @@ extern int DefinitionModule; module */ -extern int SYSTEMModule;/* flag indicating that we are handling the SYSTEM - module - */ extern struct def *Defined; /* definition structure of module defined in this compilation diff --git a/lang/m2/comp/make.allocd b/lang/m2/comp/make.allocd index 364ff9d3..ae2ae6f3 100755 --- a/lang/m2/comp/make.allocd +++ b/lang/m2/comp/make.allocd @@ -1,25 +1,26 @@ sed -e ' -s:^.*[ ]ALLOCDEF[ ].*"\(.*\)".*$:\ +s:^.*[ ]ALLOCDEF[ ].*"\(.*\)"[ ]*\([0-9][0-9]*\).*$:\ /* allocation definitions of struct \1 */\ extern char *st_alloc();\ extern struct \1 *h_\1;\ #ifdef DEBUG\ extern int cnt_\1;\ -#define new_\1() ((struct \1 *) std_alloc((char **)\&h_\1, sizeof(struct \1), \&cnt_\1))\ +extern char *std_alloc();\ +#define new_\1() ((struct \1 *) std_alloc((char **)\&h_\1, sizeof(struct \1), \2, \&cnt_\1))\ #else\ -#define new_\1() ((struct \1 *) st_alloc((char **)\&h_\1, sizeof(struct \1)))\ +#define new_\1() ((struct \1 *) st_alloc((char **)\&h_\1, sizeof(struct \1), \2))\ #endif\ #define free_\1(p) st_free(p, h_\1, sizeof(struct \1))\ :' -e ' -s:^.*[ ]STATICALLOCDEF[ ].*"\(.*\)".*$:\ +s:^.*[ ]STATICALLOCDEF[ ].*"\(.*\)"[ ]*\([0-9][0-9]*\).*$:\ /* allocation definitions of struct \1 */\ extern char *st_alloc();\ struct \1 *h_\1;\ #ifdef DEBUG\ int cnt_\1;\ -#define new_\1() ((struct \1 *) std_alloc((char **)\&h_\1, sizeof(struct \1), \&cnt_\1))\ +#define new_\1() ((struct \1 *) std_alloc((char **)\&h_\1, sizeof(struct \1), \2, \&cnt_\1))\ #else\ -#define new_\1() ((struct \1 *) st_alloc((char **)\&h_\1, sizeof(struct \1)))\ +#define new_\1() ((struct \1 *) st_alloc((char **)\&h_\1, sizeof(struct \1), \2))\ #endif\ #define free_\1(p) st_free(p, h_\1, sizeof(struct \1))\ :' diff --git a/lang/m2/comp/misc.H b/lang/m2/comp/misc.H index 82a8ed5e..5cf1ae8e 100644 --- a/lang/m2/comp/misc.H +++ b/lang/m2/comp/misc.H @@ -1,7 +1,5 @@ /* M I S C E L L A N E O U S */ -/* $Header$ */ - #define is_anon_idf(x) ((x)->id_text[0] == '#') extern struct idf diff --git a/lang/m2/comp/misc.c b/lang/m2/comp/misc.c index d3f00bad..573fd035 100644 --- a/lang/m2/comp/misc.c +++ b/lang/m2/comp/misc.c @@ -1,9 +1,5 @@ /* M I S C E L L A N E O U S R O U T I N E S */ -#ifndef NORCSID -static char *RcsId = "$Header$"; -#endif - #include #include #include diff --git a/lang/m2/comp/node.H b/lang/m2/comp/node.H index 80006975..0bb5a28b 100644 --- a/lang/m2/comp/node.H +++ b/lang/m2/comp/node.H @@ -1,7 +1,5 @@ /* N O D E O F A N A B S T R A C T P A R S E T R E E */ -/* $Header$ */ - struct node { struct node *next; #define nd_left next @@ -35,7 +33,7 @@ struct node { #define nd_REL nd_token.TOK_REL }; -/* ALLOCDEF "node" */ +/* ALLOCDEF "node" 50 */ extern struct node *MkNode(), *MkLeaf(); diff --git a/lang/m2/comp/node.c b/lang/m2/comp/node.c index 6f16617c..1a5b33b9 100644 --- a/lang/m2/comp/node.c +++ b/lang/m2/comp/node.c @@ -1,9 +1,5 @@ /* N O D E O F A N A B S T R A C T P A R S E T R E E */ -#ifndef NORCSID -static char *RcsId = "$Header$"; -#endif - #include "debug.h" #include diff --git a/lang/m2/comp/options.c b/lang/m2/comp/options.c index 69931fe3..c66341bd 100644 --- a/lang/m2/comp/options.c +++ b/lang/m2/comp/options.c @@ -1,9 +1,5 @@ /* U S E R O P T I O N - H A N D L I N G */ -#ifndef NORCSID -static char *RcsId = "$Header$"; -#endif - #include "idfsize.h" #include "ndir.h" @@ -17,7 +13,7 @@ extern int idfsize; static int ndirs; DoOption(text) - char *text; + register char *text; { switch(*text++) { @@ -33,12 +29,15 @@ DoOption(text) */ - case 'M': /* maximum identifier length */ - idfsize = txt2int(&text); - if (*text || idfsize <= 0) + case 'M': { /* maximum identifier length */ + char *t = text; /* because &text is illegal */ + + idfsize = txt2int(&t); + if (*t || idfsize <= 0) fatal("malformed -M option"); if (idfsize > IDFSIZE) fatal("maximum identifier length is %d", IDFSIZE); + } break; case 'I' : @@ -53,13 +52,16 @@ DoOption(text) arith size; int align; char c; + char *t; while (c = *text++) { - size = txt2int(&text); + t = text; + size = txt2int(&t); align = 0; - if (*text == '.') { - text++; - align = txt2int(&text); + if (*(text = t) == '.') { + t = text + 1; + align = txt2int(&t); + text = t; } switch (c) { @@ -104,7 +106,7 @@ DoOption(text) int txt2int(tp) - char **tp; + register char **tp; { /* the integer pointed to by *tp is read, while increasing *tp; the resulting value is yielded. diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 993d53c3..b6a1d27e 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -1,10 +1,6 @@ /* O V E R A L L S T R U C T U R E */ { -#ifndef NORCSID -static char *RcsId = "$Header$"; -#endif - #include "debug.h" #include @@ -42,14 +38,11 @@ static char *RcsId = "$Header$"; ModuleDeclaration { - struct idf *id; /* save module identifier */ register struct def *df; struct node *exportlist = 0; int qualified; } : - MODULE IDENT { id = dot.TOK_IDF; - df = DefineLocalModule(id); - } + MODULE IDENT { df = DefineLocalModule(dot.TOK_IDF); } priority(&(df->mod_priority))? ';' import(1)* @@ -59,7 +52,7 @@ ModuleDeclaration EnterExportList(exportlist, qualified); } close_scope(SC_CHKFORW|SC_CHKPROC|SC_REVERSE); - match_id(id, dot.TOK_IDF); + match_id(df->df_idf, dot.TOK_IDF); } ; @@ -104,7 +97,7 @@ import(int local;) df = lookfor(nd,enclosing(CurrVis),0); FreeNode(nd); } - else df = GetDefinitionModule(dot.TOK_IDF); + else df = GetDefinitionModule(dot.TOK_IDF, 1); } | { fromid = 0; } @@ -124,16 +117,13 @@ import(int local;) DefinitionModule { register struct def *df; - struct idf *id; /* save module identifier */ struct node *exportlist; int dummy; } : DEFINITION - MODULE IDENT { id = dot.TOK_IDF; - df = define(id, GlobalScope, D_MODULE); + MODULE IDENT { df = define(dot.TOK_IDF, GlobalScope, D_MODULE); if (!Defined) Defined = df; - if (!SYSTEMModule) open_scope(CLOSEDSCOPE); - CurrentScope->sc_name = id->id_text; + CurrentScope->sc_name = df->df_idf->id_text; df->mod_vis = CurrVis; df->df_type = standard_type(T_RECORD, 0, (arith) 0); df->df_type->rec_scope = df->mod_vis->sc_scope; @@ -154,15 +144,14 @@ node_warning(exportlist, "export list in definition module ignored"); /* empty */ ] definition* END IDENT - { df = CurrentScope->sc_def; - while (df) { + { register struct def *df1 = CurrentScope->sc_def; + while (df1) { /* Make all definitions "QUALIFIED EXPORT" */ - df->df_flags |= D_QEXPORTED; - df = df->df_nextinscope; + df1->df_flags |= D_QEXPORTED; + df1 = df1->df_nextinscope; } - close_scope(SC_CHKFORW); DefinitionModule--; - match_id(id, dot.TOK_IDF); + match_id(df->df_idf, dot.TOK_IDF); } '.' ; @@ -206,19 +195,17 @@ Semicolon: ProgramModule { - struct idf *id; struct def *GetDefinitionModule(); register struct def *df; } : MODULE - IDENT { id = dot.TOK_IDF; - if (state == IMPLEMENTATION) { - df = GetDefinitionModule(id); + IDENT { if (state == IMPLEMENTATION) { + df = GetDefinitionModule(dot.TOK_IDF, 0); CurrVis = df->mod_vis; RemoveImports(&(CurrentScope->sc_def)); } else { - Defined = df = define(id, CurrentScope, D_MODULE); + Defined = df = define(dot.TOK_IDF, CurrentScope, D_MODULE); open_scope(CLOSEDSCOPE); df->mod_vis = CurrVis; CurrentScope->sc_name = "_M2M"; @@ -229,13 +216,15 @@ ProgramModule ';' import(0)* block(&(df->mod_body)) IDENT { close_scope(SC_CHKFORW|SC_CHKPROC|SC_REVERSE); - match_id(id, dot.TOK_IDF); + match_id(df->df_idf, dot.TOK_IDF); } '.' ; Module: + { open_scope(CLOSEDSCOPE); } DefinitionModule + { close_scope(SC_CHKFORW); } | [ IMPLEMENTATION { state = IMPLEMENTATION; } diff --git a/lang/m2/comp/scope.C b/lang/m2/comp/scope.C index 23959a2f..fda13e58 100644 --- a/lang/m2/comp/scope.C +++ b/lang/m2/comp/scope.C @@ -1,9 +1,5 @@ /* S C O P E M E C H A N I S M */ -#ifndef NORCSID -static char *RcsId = "$Header$"; -#endif - #include "debug.h" #include @@ -23,9 +19,9 @@ struct scopelist *CurrVis; extern int proclevel; static struct scopelist *PervVis; -/* STATICALLOCDEF "scope" */ +/* STATICALLOCDEF "scope" 10 */ -/* STATICALLOCDEF "scopelist" */ +/* STATICALLOCDEF "scopelist" 10 */ open_scope(scopetype) { @@ -36,15 +32,14 @@ open_scope(scopetype) assert(scopetype == OPENSCOPE || scopetype == CLOSEDSCOPE); - clear((char *) sc, sizeof (struct scope)); sc->sc_scopeclosed = scopetype == CLOSEDSCOPE; sc->sc_level = proclevel; - if (scopetype == OPENSCOPE) { - ls->next = CurrVis; - } - else ls->next = PervVis; ls->sc_scope = sc; ls->sc_encl = CurrVis; + if (scopetype == OPENSCOPE) { + ls->next = ls->sc_encl; + } + else ls->next = PervVis; CurrVis = ls; } @@ -71,7 +66,7 @@ struct forwards { struct type *fo_ptyp; }; -/* STATICALLOCDEF "forwards" */ +/* STATICALLOCDEF "forwards" 5 */ Forward(tk, ptp) struct node *tk; @@ -83,11 +78,12 @@ Forward(tk, ptp) same scope. */ register struct forwards *f = new_forwards(); + register struct scope *sc = CurrentScope; f->fo_tok = tk; f->fo_ptyp = ptp; - f->next = CurrentScope->sc_forw; - CurrentScope->sc_forw = f; + f->next = sc->sc_forw; + sc->sc_forw = f; } STATIC @@ -95,13 +91,14 @@ chk_proc(df) register struct def *df; { /* Called at scope closing. Check all definitions, and if one - is a D_PROCHEAD, the procedure was not defined + is a D_PROCHEAD, the procedure was not defined. */ while (df) { if (df->df_kind == D_PROCHEAD) { /* A not defined procedure */ -error("procedure \"%s\" not defined", df->df_idf->id_text); + error("procedure \"%s\" not defined", + df->df_idf->id_text); FreeNode(df->for_node); } df = df->df_nextinscope; @@ -110,46 +107,48 @@ error("procedure \"%s\" not defined", df->df_idf->id_text); STATIC chk_forw(pdf) - register struct def **pdf; + struct def **pdf; { /* Called at scope close. Look for all forward definitions and if the scope was a closed scope, give an error message for them, and otherwise move them to the enclosing scope. */ - while (*pdf) { - if ((*pdf)->df_kind & (D_FORWARD|D_FORWMODULE)) { + register struct def *df; + + while (df = *pdf) { + if (df->df_kind & (D_FORWARD|D_FORWMODULE)) { /* These definitions must be found in the enclosing closed scope, which of course may be the scope that is now closed! */ - struct def *df1 = (*pdf)->df_nextinscope; - if (scopeclosed(CurrentScope)) { /* Indeed, the scope was a closed scope, so give error message */ -node_error((*pdf)->for_node, "identifier \"%s\" has not been declared", -(*pdf)->df_idf->id_text); - FreeNode((*pdf)->for_node); - pdf = &(*pdf)->df_nextinscope; +node_error(df->for_node, "identifier \"%s\" has not been declared", +df->df_idf->id_text); + FreeNode(df->for_node); } - else { /* This scope was an open scope. + else { + /* This scope was an open scope. Maybe the definitions are in the enclosing scope? */ - struct scopelist *ls; - - ls = nextvisible(CurrVis); - if ((*pdf)->df_kind == D_FORWMODULE) { - (*pdf)->for_vis->next = ls; + register struct scopelist *ls = + nextvisible(CurrVis); + struct def *df1 = df->df_nextinscope; + + if (df->df_kind == D_FORWMODULE) { + df->for_vis->next = ls; } - (*pdf)->df_nextinscope = ls->sc_scope->sc_def; - ls->sc_scope->sc_def = *pdf; - (*pdf)->df_scope = ls->sc_scope; + df->df_nextinscope = ls->sc_scope->sc_def; + ls->sc_scope->sc_def = df; + df->df_scope = ls->sc_scope; *pdf = df1; + continue; } } - else pdf = &(*pdf)->df_nextinscope; + pdf = &df->df_nextinscope; } } @@ -163,20 +162,17 @@ rem_forwards(fo) if (fo->next) rem_forwards(fo->next); df = lookfor(fo->fo_tok, CurrVis, 0); - if (df->df_kind == D_ERROR) { - node_error(fo->fo_tok, "identifier \"%s\" not declared", - df->df_idf->id_text); - } - else if (df->df_kind != D_TYPE) { - node_error(fo->fo_tok, "identifier \"%s\" not a type", - df->df_idf->id_text); + if (! is_type(df)) { + node_error(fo->fo_tok, + "identifier \"%s\" does not represent a type", + df->df_idf->id_text); } fo->fo_ptyp->next = df->df_type; free_forwards(fo); } Reverse(pdf) - register struct def **pdf; + struct def **pdf; { /* Reverse the order in the list of definitions in a scope. This is neccesary because this list is built in reverse. @@ -188,23 +184,18 @@ Reverse(pdf) df = 0; df1 = *pdf; - while (df1) { - if (df1->df_kind & INTERESTING) break; - df1 = df1->df_nextinscope; - } - - if (!(*pdf = df1)) return; while (df1) { - *pdf = df1; - df1 = df1->df_nextinscope; - while (df1) { - if (df1->df_kind & INTERESTING) break; + if (df1->df_kind & INTERESTING) { + struct def *prev = df; + + df = df1; df1 = df1->df_nextinscope; + df->df_nextinscope = prev; } - (*pdf)->df_nextinscope = df; - df = *pdf; + else df1 = df1->df_nextinscope; } + *pdf = df; } close_scope(flag) diff --git a/lang/m2/comp/scope.h b/lang/m2/comp/scope.h index 9657870e..770919c1 100644 --- a/lang/m2/comp/scope.h +++ b/lang/m2/comp/scope.h @@ -1,7 +1,5 @@ /* S C O P E M E C H A N I S M */ -/* $Header$ */ - #define OPENSCOPE 0 /* Indicating an open scope */ #define CLOSEDSCOPE 1 /* Indicating a closed scope (module) */ diff --git a/lang/m2/comp/standards.h b/lang/m2/comp/standards.h index 4c445b97..3f1bd60a 100644 --- a/lang/m2/comp/standards.h +++ b/lang/m2/comp/standards.h @@ -1,7 +1,5 @@ /* S T A N D A R D P R O C E D U R E S A N D F U N C T I O N S */ -/* $Header$ */ - #define S_ABS 1 #define S_CAP 2 #define S_CHR 3 diff --git a/lang/m2/comp/statement.g b/lang/m2/comp/statement.g index c04b36bd..45dc3993 100644 --- a/lang/m2/comp/statement.g +++ b/lang/m2/comp/statement.g @@ -1,10 +1,6 @@ /* S T A T E M E N T S */ { -#ifndef NORCSID -static char *RcsId = "$Header$"; -#endif - #include #include #include @@ -22,6 +18,7 @@ static int loopcount = 0; /* Count nested loops */ statement(register struct node **pnd;) { register struct node *nd; + extern int return_occurred; } : /* * This part is not in the reference grammar. The reference grammar @@ -64,6 +61,7 @@ statement(register struct node **pnd;) } | ReturnStatement(pnd) + { return_occurred = 1; } | /* empty */ { *pnd = 0; } ; @@ -88,9 +86,12 @@ StatementSequence(register struct node **pnd;) [ %persistent ';' statement(&nd) { if (nd) { - *pnd = MkNode(Link, *pnd, nd, &dot); - (*pnd)->nd_symb = ';'; - pnd = &((*pnd)->nd_right); + register struct node *nd1 = + MkNode(Link, *pnd, nd, &dot); + + *pnd = nd1; + nd1->nd_symb = ';'; + pnd = &(nd1->nd_right); } } ]* @@ -178,31 +179,29 @@ RepeatStatement(struct node **pnd;) ForStatement(struct node **pnd;) { - register struct node *nd; + register struct node *nd, *nd1; struct node *dummy; }: FOR { *pnd = nd = MkLeaf(Stat, &dot); } IDENT { nd->nd_IDF = dot.TOK_IDF; } - BECOMES { nd->nd_left = MkLeaf(Stat, &dot); - nd = nd->nd_left; - } - expression(&(nd->nd_left)) + BECOMES { nd->nd_left = nd1 = MkLeaf(Stat, &dot); } + expression(&(nd1->nd_left)) TO - expression(&(nd->nd_right)) + expression(&(nd1->nd_right)) [ BY ConstExpression(&dummy) { if (!(dummy->nd_type->tp_fund & T_INTORCARD)) { error("illegal type in BY clause"); } - nd->nd_INT = dummy->nd_INT; + nd1->nd_INT = dummy->nd_INT; FreeNode(dummy); } | - { nd->nd_INT = 1; } + { nd1->nd_INT = 1; } ] DO - StatementSequence(&((*pnd)->nd_right)) + StatementSequence(&(nd->nd_right)) END ; @@ -227,12 +226,9 @@ ReturnStatement(struct node **pnd;) { register struct def *df = CurrentScope->sc_definedby; register struct node *nd; - extern int return_occurred; } : - RETURN { *pnd = nd = MkLeaf(Stat, &dot); - return_occurred = 1; - } + RETURN { *pnd = nd = MkLeaf(Stat, &dot); } [ expression(&(nd->nd_right)) { if (scopeclosed(CurrentScope)) { diff --git a/lang/m2/comp/tmpvar.C b/lang/m2/comp/tmpvar.C index 0c5ade1c..7e0cea21 100644 --- a/lang/m2/comp/tmpvar.C +++ b/lang/m2/comp/tmpvar.C @@ -1,9 +1,5 @@ /* T E M P O R A R Y V A R I A B L E S */ -#ifndef NORCSID -static char *RcsId = "$Header$"; -#endif - /* Code for the allocation and de-allocation of temporary variables, allowing re-use. The routines use "ProcScope" instead of "CurrentScope", because @@ -29,7 +25,7 @@ struct tmpvar { arith t_offset; /* offset from LocalBase */ }; -/* STATICALLOCDEF "tmpvar" */ +/* STATICALLOCDEF "tmpvar" 10 */ static struct tmpvar *TmpInts, /* for integer temporaries */ *TmpPtrs; /* for pointer temporaries */ @@ -47,7 +43,7 @@ TmpOpen(sc) struct scope *sc; arith NewInt() { - arith offset; + register arith offset; register struct tmpvar *tmp; if (!TmpInts) { @@ -67,7 +63,7 @@ NewInt() arith NewPtr() { - arith offset; + register arith offset; register struct tmpvar *tmp; if (!TmpPtrs) { diff --git a/lang/m2/comp/tokenname.c b/lang/m2/comp/tokenname.c index e6add612..1e8dd3e3 100644 --- a/lang/m2/comp/tokenname.c +++ b/lang/m2/comp/tokenname.c @@ -1,9 +1,5 @@ /* T O K E N D E F I N I T I O N S */ -#ifndef NORCSID -static char *RcsId = "$Header$"; -#endif - #include "tokenname.h" #include "Lpars.h" #include "idf.h" diff --git a/lang/m2/comp/tokenname.h b/lang/m2/comp/tokenname.h index 7838ae87..79ccdc4c 100644 --- a/lang/m2/comp/tokenname.h +++ b/lang/m2/comp/tokenname.h @@ -1,7 +1,5 @@ /* T O K E N N A M E S T R U C T U R E */ -/* $Header$ */ - struct tokenname { /* Used for defining the name of a token as identified by its symbol */ diff --git a/lang/m2/comp/type.H b/lang/m2/comp/type.H index 68dc1666..0e612f20 100644 --- a/lang/m2/comp/type.H +++ b/lang/m2/comp/type.H @@ -1,7 +1,5 @@ /* T Y P E D E S C R I P T O R S T R U C T U R E */ -/* $Header$ */ - struct paramlist { /* structure for parameterlist of a PROCEDURE */ struct paramlist *next; struct def *par_def; /* "df" of parameter */ @@ -9,7 +7,7 @@ struct paramlist { /* structure for parameterlist of a PROCEDURE */ #define TypeOfParam(xpar) ((xpar)->par_def->df_type) }; -/* ALLOCDEF "paramlist" */ +/* ALLOCDEF "paramlist" 20 */ struct enume { struct def *en_enums; /* Definitions of enumeration literals */ @@ -86,7 +84,7 @@ struct type { } tp_value; }; -/* ALLOCDEF "type" */ +/* ALLOCDEF "type" 50 */ extern struct type *bool_type, @@ -125,11 +123,11 @@ extern arith align(); /* type.c */ struct type - *create_type(), *construct_type(), *standard_type(), *set_type(), *subr_type(), + *proc_type(), *RemoveEqual(); /* All from type.c */ #define NULLTYPE ((struct type *) 0) diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index 41727ea7..9fc4435c 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -1,9 +1,5 @@ /* T Y P E D E F I N I T I O N M E C H A N I S M */ -#ifndef NORCSID -static char *RcsId = "$Header$"; -#endif - #include "target_sizes.h" #include "debug.h" #include "maxset.h" @@ -66,21 +62,6 @@ struct type *h_type; int cnt_type; #endif -struct type * -create_type(fund) - int fund; -{ - /* A brand new struct type is created, and its tp_fund set - to fund. - */ - register struct type *ntp = new_type(); - - clear((char *)ntp, sizeof(struct type)); - ntp->tp_fund = fund; - - return ntp; -} - struct type * construct_type(fund, tp) int fund; @@ -89,9 +70,9 @@ construct_type(fund, tp) /* fund must be a type constructor. The pointer to the constructed type is returned. */ - register struct type *dtp = create_type(fund); + register struct type *dtp = new_type(); - switch (fund) { + switch (dtp->tp_fund = fund) { case T_PROCEDURE: case T_POINTER: case T_HIDDEN: @@ -135,8 +116,9 @@ standard_type(fund, align, size) int align; arith size; { - register struct type *tp = create_type(fund); + register struct type *tp = new_type(); + tp->tp_fund = fund; tp->tp_align = align; tp->tp_size = size; @@ -167,10 +149,6 @@ InitTypes() fatal("long real size smaller than real size"); } - if (!pointer_size || pointer_size % word_size != 0) { - fatal("illegal pointer size"); - } - /* character type */ char_type = standard_type(T_CHAR, 1, (arith) 1); @@ -303,6 +281,19 @@ subr_type(lb, ub) return res; } +struct type * +proc_type(result_type, parameters, n_bytes_params) + struct type *result_type; + struct paramlist *parameters; + arith n_bytes_params; +{ + register struct type *tp = construct_type(T_PROCEDURE, result_type); + + tp->prc_params = parameters; + tp->prc_nbpar = n_bytes_params; + return tp; +} + genrck(tp) register struct type *tp; { @@ -310,20 +301,22 @@ genrck(tp) neccessary. Return its label. */ arith lb, ub; - label ol, l; + register label ol; + int newlabel = 0; getbounds(tp, &lb, &ub); if (tp->tp_fund == T_SUBRANGE) { if (!(ol = tp->sub_rck)) { - tp->sub_rck = l = ++data_label; + tp->sub_rck = ol = ++data_label; + newlabel = 1; } } else if (!(ol = tp->enm_rck)) { - tp->enm_rck = l = ++data_label; + tp->enm_rck = ol = ++data_label; + newlabel = 1; } - if (!ol) { - ol = l; + if (newlabel) { C_df_dlb(ol); C_rom_cst(lb); C_rom_cst(ub); @@ -385,7 +378,7 @@ ArrayElSize(tp) Also make sure that its size is either a dividor of the word_size, or a multiple of it. */ - arith algn; + register arith algn; if (tp->tp_fund == T_ARRAY) ArraySizes(tp); algn = align(tp->tp_size, tp->tp_align); @@ -446,6 +439,7 @@ FreeType(tp) while (pr) { pr1 = pr; pr = pr->next; + free_def(pr1->par_def); free_paramlist(pr1); } @@ -520,21 +514,14 @@ DumpType(tp) { if (!tp) return; - print(" a:%d; s:%ld;", tp->tp_align, (long) tp->tp_size); - if (tp->next && tp->tp_fund != T_POINTER) { - /* Avoid printing recursive types! - */ - print(" n:("); - DumpType(tp->next); - print(")"); - } + print("align:%d; size:%ld;", tp->tp_align, (long) tp->tp_size); - print(" f:"); + print(" fund:"); switch(tp->tp_fund) { case T_RECORD: print("RECORD"); break; case T_ENUMERATION: - print("ENUMERATION; n:%d", tp->enm_ncst); break; + print("ENUMERATION; ncst:%d", tp->enm_ncst); break; case T_INTEGER: print("INTEGER"); break; case T_CARDINAL: @@ -562,7 +549,7 @@ DumpType(tp) print("PROCEDURE"); if (par) { - print("; p:"); + print("("); while(par) { if (IsVarParam(par)) print("VAR "); DumpType(TypeOfParam(par)); @@ -573,11 +560,12 @@ DumpType(tp) } case T_ARRAY: print("ARRAY"); - print("; el:"); + print("; element:"); DumpType(tp->arr_elem); print("; index:"); DumpType(tp->next); - break; + print(";"); + return; case T_STRING: print("STRING"); break; case T_INTORCARD: @@ -585,6 +573,13 @@ DumpType(tp) default: crash("DumpType"); } + if (tp->next && tp->tp_fund != T_POINTER) { + /* Avoid printing recursive types! + */ + print(" next:("); + DumpType(tp->next); + print(")"); + } print(";"); } #endif diff --git a/lang/m2/comp/typequiv.c b/lang/m2/comp/typequiv.c index 422638c8..0f4e8c3c 100644 --- a/lang/m2/comp/typequiv.c +++ b/lang/m2/comp/typequiv.c @@ -1,9 +1,5 @@ /* T Y P E E Q U I V A L E N C E */ -#ifndef NORCSID -static char *RcsId = "$Header$"; -#endif - /* Routines for testing type equivalence, type compatibility, and assignment compatibility */ diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index 098744df..2679b537 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -1,9 +1,5 @@ /* P A R S E T R E E W A L K E R */ -#ifndef NORCSID -static char *RcsId = "$Header$"; -#endif - /* Routines to walk through parts of the parse tree, and generate code for these parts. */ @@ -103,11 +99,6 @@ WalkModule(module) C_loe_dlb(l1, (arith) 0); C_zne(RETURN_LABEL); C_ine_dlb(l1, (arith) 0); - /* Prevent this module from calling its own - initialization routine - */ - assert(nd->nd_IDF == module->df_idf); - nd = nd->next; } for (; nd; nd = nd->next) { @@ -415,17 +406,16 @@ WalkStat(nd, exit_label) break; case IF: - { label l1, l2, l3; + { label l1 = ++text_label, l3 = ++text_label; - l1 = ++text_label; - l2 = ++text_label; - l3 = ++text_label; ExpectBool(left, l3, l1); assert(right->nd_symb == THEN); C_df_ilb(l3); WalkNode(right->nd_left, exit_label); if (right->nd_right) { /* ELSE part */ + label l2 = ++text_label; + C_bra(l2); C_df_ilb(l1); WalkNode(right->nd_right, exit_label); @@ -440,73 +430,72 @@ WalkStat(nd, exit_label) break; case WHILE: - { label l1, l2, l3; + { label loop = ++text_label, + exit = ++text_label, + dummy = ++text_label; - l1 = ++text_label; - l2 = ++text_label; - l3 = ++text_label; - C_df_ilb(l1); - ExpectBool(left, l3, l2); - C_df_ilb(l3); + C_df_ilb(loop); + ExpectBool(left, dummy, exit); + C_df_ilb(dummy); WalkNode(right, exit_label); - C_bra(l1); - C_df_ilb(l2); + C_bra(loop); + C_df_ilb(exit); break; } case REPEAT: - { label l1, l2; + { label loop = ++text_label, exit = ++text_label; - l1 = ++text_label; - l2 = ++text_label; - C_df_ilb(l1); + C_df_ilb(loop); WalkNode(left, exit_label); - ExpectBool(right, l2, l1); - C_df_ilb(l2); + ExpectBool(right, exit, loop); + C_df_ilb(exit); break; } case LOOP: - { label l1, l2; + { label loop = ++text_label, exit = ++text_label; - l1 = ++text_label; - l2 = ++text_label; - C_df_ilb(l1); - WalkNode(right, l2); - C_bra(l1); - C_df_ilb(l2); + C_df_ilb(loop); + WalkNode(right, exit); + C_bra(loop); + C_df_ilb(exit); break; } case FOR: { arith tmp = 0; - struct node *fnd; + register struct node *fnd; label l1 = ++text_label; label l2 = ++text_label; if (! DoForInit(nd, left)) break; fnd = left->nd_right; if (fnd->nd_class != Value) { + /* Upperbound not constant. + The expression may only be evaluated once, + so generate a temporary for it + */ CodePExpr(fnd); tmp = NewInt(); C_stl(tmp); } - C_bra(l1); - C_df_ilb(l2); + C_df_ilb(l1); + C_dup(int_size); + if (tmp) C_lol(tmp); else C_loc(fnd->nd_INT); + if (left->nd_INT > 0) { + C_bgt(l2); + } + else C_blt(l2); RangeCheck(nd->nd_type, int_type); CodeDStore(nd); WalkNode(right, exit_label); CodePExpr(nd); C_loc(left->nd_INT); C_adi(int_size); - C_df_ilb(l1); - C_dup(int_size); - if (tmp) C_lol(tmp); else C_loc(fnd->nd_INT); - if (left->nd_INT > 0) { - C_ble(l2); - } - else C_bge(l2); + C_bra(l1); + C_df_ilb(l2); C_asp(int_size); if (tmp) FreeInt(tmp); } @@ -517,7 +506,6 @@ WalkStat(nd, exit_label) struct scopelist link; struct withdesig wds; struct desig ds; - arith tmp = 0; if (! WalkDesignator(left, &ds)) break; if (left->nd_type->tp_fund != T_RECORD) { @@ -532,7 +520,7 @@ WalkStat(nd, exit_label) ds.dsg_kind = DSG_FIXED; /* Create a designator structure for the temporary. */ - ds.dsg_offset = tmp = NewPtr(); + ds.dsg_offset = NewPtr(); ds.dsg_name = 0; CodeStore(&ds, pointer_size); ds.dsg_kind = DSG_PFIXED; @@ -544,7 +532,7 @@ WalkStat(nd, exit_label) WalkNode(right, exit_label); CurrVis = link.next; WithDesigs = wds.w_next; - FreePtr(tmp); + FreePtr(ds.dsg_offset); break; } @@ -648,12 +636,13 @@ DoForInit(nd, left) nd->nd_symb = IDENT; if (! ChkVariable(nd) || - ! ChkExpression(left->nd_left) || + ! WalkExpr(left->nd_left) || ! ChkExpression(left->nd_right)) return 0; df = nd->nd_def; if (df->df_kind == D_FIELD) { - node_error(nd, "FOR-loop variable may not be a field of a record"); + node_error(nd, + "FOR-loop variable may not be a field of a record"); return 0; } @@ -665,14 +654,15 @@ DoForInit(nd, left) if (df->df_scope != CurrentScope) { register struct scopelist *sc = CurrVis; - while (sc && sc->sc_scope != df->df_scope) { + for (;;) { + if (!sc) { + node_error(nd, + "FOR-loop variable may not be imported"); + return 0; + } + if (sc->sc_scope == df->df_scope) break; sc = nextvisible(sc); } - - if (!sc) { - node_error(nd, "FOR-loop variable may not be imported"); - return 0; - } } if (df->df_type->tp_size > word_size || @@ -691,8 +681,6 @@ DoForInit(nd, left) node_warning(nd, "old-fashioned! compatibility required in FOR statement"); } - CodePExpr(left->nd_left); - return 1; } @@ -703,11 +691,12 @@ DoAssign(nd, left, right) /* May we do it in this order (expression first) ??? The reference manual sais nothing about it, but the book does: it sais that the left hand side is evaluated first. + DAMN THE BOOK! */ struct desig dsl, dsr; - if (! ChkExpression(right)) return; - if (! ChkVariable(left)) return; + if (! ChkExpression(right) || ! ChkVariable(left)) return; + if (right->nd_symb == STRING) TryToString(right, left->nd_type); dsr = InitDesig; CodeExpr(right, &dsr, NO_LABEL, NO_LABEL); diff --git a/lang/m2/comp/walk.h b/lang/m2/comp/walk.h index 439f2c2a..4222dbeb 100644 --- a/lang/m2/comp/walk.h +++ b/lang/m2/comp/walk.h @@ -1,7 +1,5 @@ /* P A R S E T R E E W A L K E R */ -/* $Header$ */ - /* Definition of WalkNode macro */ From 15c2d7c8b22d59dab86a782e339a235d7d46d871 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 9 Oct 1986 10:37:56 +0000 Subject: [PATCH 0275/1625] Changed a test that was word_size and alignment dependant. --- lang/pc/test/t4.p | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/pc/test/t4.p b/lang/pc/test/t4.p index 8a3cf1ff..3afe6460 100644 --- a/lang/pc/test/t4.p +++ b/lang/pc/test/t4.p @@ -91,7 +91,7 @@ var s:record b:boolean; case t:boolean of false:(c:char);true:(d:cmat) end; w: packed record case z:boolean of false: (x:array[0..20] of integer); - true: (a,b,c,d,e,f,g,h,i,j,k,l:char) + true: (x1,x2,x3,a,b,c,d,e,f,g,h,i,j,k,l:char) end; y: record From b42a39df903c763076dd82833f93b91f4f6c6435 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 9 Oct 1986 11:09:27 +0000 Subject: [PATCH 0276/1625] Addition of some changes by Kees Visser. In packed structures, subrange types now occupy 1 byte if they fit in 1 byte, they occupy 2 bytes if they fit in 2, etc. --- lang/pc/pem/pem.p | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/lang/pc/pem/pem.p b/lang/pc/pem/pem.p index cf06c724..674baef8 100644 --- a/lang/pc/pem/pem.p +++ b/lang/pc/pem/pem.p @@ -36,7 +36,7 @@ {$s+ : test conformancy to standard} #endif -program pem(input,output,em,errors); +program pem(input,em,errors); {/* This Pascal compiler produces EM code as described in - A.S.Tanenbaum, J.W.Stevenson & H. van Staveren, @@ -79,6 +79,8 @@ const {fundamental constants} MB1 = 7; NB1 = 8; + MI1 = 127; + NI1 = 128; MI2 = 32767; MU1 = 255; NU1 = 256; @@ -541,6 +543,7 @@ begin put1(i1); put1(i2) end; +#if EM_WSIZE == 4 procedure put4(i:integer); var i1,i2:integer; begin @@ -551,6 +554,7 @@ begin put1(i1 mod NU1); put1(i1 div NU1); put1(i2 mod NU1); put1(i2 div NU1) end; +#endif procedure argend; begin put1(sp_cend) end; @@ -559,9 +563,14 @@ procedure argcst(i:integer); begin if (i >= -sp_zcst0) and (i < sp_ncst0-sp_zcst0) then put1(i + sp_zcst0 + sp_fcst0) - else if (i >= -MI2-1) and (i <= MI2) then + else +#if EM_WSIZE == 4 + if (i >= -MI2-1) and (i <= MI2) then +#endif begin put1(sp_cst2); put2(i) end +#if EM_WSIZE == 4 else begin put1(sp_cst4); put4(i) end +#endif end; procedure argnil; @@ -864,6 +873,11 @@ begin with a do begin sz:=sizeof(asp,packbit); gencst(op_lar,sz_word); end; {case} ak:=loaded; + if asp^.form = subrange then + if sz < sz_word then + if asp^.min < 0 then + { do sign extension } + begin gencst(op_loc, sz); gencst(op_loc, sz_word); genop(op_cii) end end end; procedure store; @@ -1500,7 +1514,11 @@ begin lsp:=nil; if lip<>nil then begin enterid(lip); hip:=lip; lip^.value:=max; max:=max+1 end; until endofloop(fsys+[rparent],[ident],comma,+027); {+028} - if max<=MU1 then lsp^.size:=sz_byte; + if max<=MU1 then lsp^.size:=sz_byte +#if EM_WSIZE == 4 + else if max <= MU2 then lsp^.size = 2*sz_byte +#endif + ; lsp^.fconst:=hip; top:=lnp; nextif(rparent,+029); end else @@ -1520,7 +1538,13 @@ begin lsp:=nil; lsp^.rangetype:=lsp1; nextif(colon2,+031); max:=cstinteger(fsys,lsp1,+032); if min>max then begin error(+033); max:=min end; - if (min>=0) and (max<=MU1) then lsp^.size:=sz_byte; + if ((min>=0) and (max<=MU1)) or ((min>=-NI1) and (max<=MI1)) then + lsp^.size:=sz_byte +#if EM_WSIZE == 4 + else if ((min>=0) and (max<=MU2)) or ((min>=-MI2-1) and (max<=MI2)) then + lsp^.size := 2*sz_byte +#endif + ; lsp^.min:=min; lsp^.max:=max end end; From 9eeb2ec6fa148715e745041254ae2842e948ba57 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 9 Oct 1986 11:44:28 +0000 Subject: [PATCH 0277/1625] Removed the "wordsize" variable. it was'nt needed, as we also have EM_WSIZE. --- lang/pc/pem/pem.p | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lang/pc/pem/pem.p b/lang/pc/pem/pem.p index 674baef8..c6caede3 100644 --- a/lang/pc/pem/pem.p +++ b/lang/pc/pem/pem.p @@ -89,7 +89,6 @@ const imax = 10; max2bytes = '0000032767'; max4bytes = '2147483647'; - wordsize = EM_WSIZE; #if EM_WSIZE == 4 {this can only be compiled with a compiler that has integer size 4} @@ -1516,7 +1515,7 @@ begin lsp:=nil; until endofloop(fsys+[rparent],[ident],comma,+027); {+028} if max<=MU1 then lsp^.size:=sz_byte #if EM_WSIZE == 4 - else if max <= MU2 then lsp^.size = 2*sz_byte + else if max <= MU2 then lsp^.size := 2*sz_byte #endif ; lsp^.fconst:=hip; top:=lnp; nextif(rparent,+029); @@ -3295,7 +3294,9 @@ end; procedure init3; var n:np; p,q:ip; i:integer; c:char; +#if EM_WSIZE == 2 is:packed array[1..imax] of char; +#endif begin for i:=0 to sz_last do readln(errors,sizes[i]); if sz_int = 2 then maxintstring := max2bytes @@ -3336,12 +3337,16 @@ begin {maxint of the target machine} p:=newip(konst,'maxint ',intptr,nil); if sz_int = 2 then p^.value:=MI2 - else if wordsize = 4 then p^.value := MI - else {wordsize = 2, sz_int = 4} + else +#if EM_WSIZE == 4 + p^.value := MI; +#else + {EM_WSIZE = 2, sz_int = 4} begin p^.idtype:=longptr; ix:=imax; is:=max4bytes; for i:=1 to ix do strbuf[i]:=is[i]; p^.value:=romstr(sp_icon,sz_int); end; +#endif enterid(p); p:=newip(konst,spaces,charptr,nil); p^.value:=maxcharord; charptr^.fconst:=p; @@ -3360,7 +3365,7 @@ end; procedure init4; begin copt:=opt['c']; - dopt:=opt['d']; if wordsize < sz_int then dopt:=on; + dopt:=opt['d']; if EM_WSIZE < sz_int then dopt:=on; iopt:=opt['i']; sopt:=opt['s']; if sopt<>off then begin copt:=off; dopt:=off end From ab19fa71d6cad19fb1ab871965a08f7f4a49c579 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 9 Oct 1986 13:21:33 +0000 Subject: [PATCH 0278/1625] Added RANLIB --- mach/vax4/libpc/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/mach/vax4/libpc/Makefile b/mach/vax4/libpc/Makefile index 87bf4fbe..9fbb701a 100644 --- a/mach/vax4/libpc/Makefile +++ b/mach/vax4/libpc/Makefile @@ -3,6 +3,7 @@ MACHDEF="MACH=vax4" "SUF=o" "ASAR=ar" PCDEF="PREF=pc" "SUB=" "SRC=lang/pc/libpc" install: + RANLIB=ranlib ; export RANLIB ;\ make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) cp cmp: From 09afb442c41db186e09eb0846d7d3c96360d1137 Mon Sep 17 00:00:00 2001 From: sater Date: Thu, 9 Oct 1986 16:12:24 +0000 Subject: [PATCH 0279/1625] nullpointer and empty string were confused. Long live the PDP and VAX --- mach/proto/ncg/compute.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/proto/ncg/compute.c b/mach/proto/ncg/compute.c index 0de478fa..c86e073d 100644 --- a/mach/proto/ncg/compute.c +++ b/mach/proto/ncg/compute.c @@ -340,7 +340,7 @@ result_t compute(node) register node_p node; { case EX_TOSTRING: assert(leaf1.e_typ == EV_INT); result.e_typ = EV_ADDR; - result.e_v.e_addr.ea_str = 0; + result.e_v.e_addr.ea_str = ""; result.e_v.e_addr.ea_off = leaf1.e_v.e_con; return(result); #ifdef REGVARS From cb0741ad6d9cceab8118d1f18056c988dbbc89d4 Mon Sep 17 00:00:00 2001 From: sater Date: Thu, 9 Oct 1986 16:15:00 +0000 Subject: [PATCH 0280/1625] empty string was returned when it was not so good. --- mach/proto/ncg/gencode.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mach/proto/ncg/gencode.c b/mach/proto/ncg/gencode.c index 1f84faf2..a1701820 100644 --- a/mach/proto/ncg/gencode.c +++ b/mach/proto/ncg/gencode.c @@ -84,8 +84,12 @@ string ad2str(ad) addr_t ad; { if (ad.ea_str==0) ad.ea_str=""; - if (ad.ea_off==0) - return(mystrcpy(ad.ea_str)); + if ((long)ad.ea_off==(long)0) { + if strcmp(ad.ea_str,"") + return(mystrcpy("0")); /* don't return empty string */ + else + return(mystrcpy(ad.ea_str)); + } sprintf(buf,"%s%c%ld",ad.ea_str,ad.ea_off>=0 ? '+' : ' ',(long)ad.ea_off); return(mystrcpy(buf)); } From 680f7f4fb5732e2a107e5b8c5d9a0f70b579e1fb Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 10 Oct 1986 15:05:10 +0000 Subject: [PATCH 0281/1625] Added a "fmt_id" define, to prevent that no '_' is placed in front of an identifier longer than 8 characters. --- mach/m68k2/cg/mach.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mach/m68k2/cg/mach.h b/mach/m68k2/cg/mach.h index 92a56218..671e1a58 100644 --- a/mach/m68k2/cg/mach.h +++ b/mach/m68k2/cg/mach.h @@ -21,6 +21,8 @@ #define con_ilb(x) fprintf(codefile,".data4\t%s\n",x) #define con_dlb(x) fprintf(codefile,".data4\t%s\n",x) +#define fmt_id(fr,to) sprintf(to, "_%s", fr) + #define modhead ".sect .text;.sect .rom;.sect .data;.sect .bss\n" #define id_first '_' From 78d0c0ec3dec7f999949a9a521d982d9bd646252 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 10 Oct 1986 15:09:34 +0000 Subject: [PATCH 0282/1625] Oops, forgot to remove the id_first definition. --- mach/m68k2/cg/mach.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/mach/m68k2/cg/mach.h b/mach/m68k2/cg/mach.h index 671e1a58..d2db72ff 100644 --- a/mach/m68k2/cg/mach.h +++ b/mach/m68k2/cg/mach.h @@ -1,4 +1,3 @@ -#define ex_ap(y) fprintf(codefile,".extern %s\n",y) #define in_ap(y) /* nothing */ #define newilb(x) fprintf(codefile,"%s:\n",x) @@ -25,6 +24,5 @@ #define modhead ".sect .text;.sect .rom;.sect .data;.sect .bss\n" -#define id_first '_' #define BSS_INIT 0 From b9bc4942918d6debe9cc2356caa293fcbf5f6c9f Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 10 Oct 1986 15:21:35 +0000 Subject: [PATCH 0283/1625] Apparently, ex_ap disappeared. Put it in again. --- mach/m68k2/cg/mach.h | 1 + 1 file changed, 1 insertion(+) diff --git a/mach/m68k2/cg/mach.h b/mach/m68k2/cg/mach.h index d2db72ff..8a385ffb 100644 --- a/mach/m68k2/cg/mach.h +++ b/mach/m68k2/cg/mach.h @@ -1,3 +1,4 @@ +#define ex_ap(y) fprintf(codefile,".extern %s\n", y) #define in_ap(y) /* nothing */ #define newilb(x) fprintf(codefile,"%s:\n",x) From 0e9a59ad6c74ef73ee68b3ef754abab11edbc04e Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 13 Oct 1986 14:42:31 +0000 Subject: [PATCH 0284/1625] Added a NOFLOAT define. (Taken from Koen Langendoen) --- lang/pc/test/t3.p | 109 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/lang/pc/test/t3.p b/lang/pc/test/t3.p index dc5134a2..d2fc4fbd 100644 --- a/lang/pc/test/t3.p +++ b/lang/pc/test/t3.p @@ -1,3 +1,4 @@ +# { (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. @@ -24,14 +25,30 @@ type wavelength = (red,blue,yellow,q1,q2,q3,q4,q5,q6,q7,q8,q9,q10,q11, pink,green,orange); spectrum= set of wavelength; bit = 0..1; + +#ifndef NOFLOAT tp3= packed record c1:char; i:integer; p:boolean; x:real end; tp4= record c1:char; i:integer; p:boolean; x:real end; +#else + tp3= packed record c1:char; i:integer; p:boolean; end; + tp4= record c1:char; i:integer; p:boolean; end; +#endif + vec1 = array [-10..+10] of integer; + +#ifndef NOFLOAT vrec = record case t:boolean of false:(r:real); true:(b:bit) end; +#else + vrec = record case t:boolean of false:(); true:(b:bit) end; +#endif var t,pct,ect:integer; i,j,k,l:integer; + +#ifndef NOFLOAT x,y: real; +#endif + p:boolean; c2:char; a1: vec1; @@ -104,12 +121,23 @@ begin t:=36; pct:=pct+1; colors := f2^; get(f2); if colors <> [red] then e(5); colors := f2^; get(f2); if colors <> [blue,red] then e(6); colors := f2^; get(f2); if colors <> [blue,yellow] then e(7); + +#ifndef NOFLOAT r3.c1:='w'; r3.i:= -100; r3.x:=303.56; r3.p:=true; f3^:=r3; put(f3); r3.c1:='y'; r3.i:= -35; r3.x:=26.32; f3^:=r3; put(f3); r3.c1:='q'; r3.i:= +29; r3.x:=10.00; f3^:=r3; put(f3); r3.c1:='j'; r3.i:= 8; r3.x:=10000; f3^:=r3; put(f3); +#else + r3.c1:='w'; r3.i:= -100; r3.p:=true; f3^:=r3; put(f3); + r3.c1:='y'; r3.i:= -35; f3^:=r3; put(f3); + r3.c1:='q'; r3.i:= +29; f3^:=r3; put(f3); + r3.c1:='j'; r3.i:= 8; f3^:=r3; put(f3); +#endif + for i:= 1 to 1000 do begin f3^ := r3; put(f3) end; reset(f3); + +#ifndef NOFLOAT r3 := f3^; get(f3); if (r3.c1<>'w') or (r3.i<>-100) or (r3.x<>303.56) then e(8); r3 := f3^; get(f3); @@ -118,13 +146,34 @@ begin t:=36; pct:=pct+1; if (r3.c1<>'q') or (r3.i<> 29) or (r3.x<> 10.00) then e(10); r3 := f3^; get(f3); if (r3.c1<>'j') or (r3.i<> 8) or (r3.x<> 10000) then e(11); +#else + r3 := f3^; get(f3); + if (r3.c1<>'w') or (r3.i<>-100) then e(8); + r3 := f3^; get(f3); + if (r3.c1<>'y') or (r3.i<> -35) then e(9); + r3 := f3^; get(f3); + if (r3.c1<>'q') or (r3.i<> 29) then e(10); + r3 := f3^; get(f3); + if (r3.c1<>'j') or (r3.i<> 8) then e(11); +#endif + +#ifndef NOFLOAT r4.c1:='w'; r4.i:= -100; r4.x:=303.56; r4.p:=true; f4^:=r4; put(f4); r4.c1:='y'; r4.i:= -35; r4.x:=26.32; f4^:=r4; put(f4); r4.c1:='q'; r4.i:= +29; r4.x:=10.00; f4^:=r4; put(f4); r4.c1:='j'; r4.i:= 8; r4.x:=10000; f4^:=r4; put(f4); +#else + r4.c1:='w'; r4.i:= -100; r4.p:=true; f4^:=r4; put(f4); + r4.c1:='y'; r4.i:= -35; f4^:=r4; put(f4); + r4.c1:='q'; r4.i:= +29; f4^:=r4; put(f4); + r4.c1:='j'; r4.i:= 8; f4^:=r4; put(f4); +#endif + for i:= 1 to 1000 do begin f4^ := r4; put(f4) end; reset(f4); + +#ifndef NOFLOAT r4 := f4^; get(f4); if (r4.c1<>'w') or (r4.i<>-100) or (r4.x<>303.56) then e(12); r4 := f4^; get(f4); @@ -133,6 +182,17 @@ begin t:=36; pct:=pct+1; if (r4.c1<>'q') or (r4.i<> 29) or (r4.x<> 10.00) then e(13); r4 := f4^; get(f4); if (r4.c1<>'j') or (r4.i<> 8) or (r4.x<> 10000) then e(14); +#else + r4 := f4^; get(f4); + if (r4.c1<>'w') or (r4.i<>-100) then e(12); + r4 := f4^; get(f4); + if (r4.c1<>'y') or (r4.i<> -35) then e(13); + r4 := f4^; get(f4); + if (r4.c1<>'q') or (r4.i<> 29) then e(13); + r4 := f4^; get(f4); + if (r4.c1<>'j') or (r4.i<> 8) then e(14); +#endif + for j:= 1 to 100 do begin for i:= -10 to +10 do a1[i] := i*j; f5^ := a1; put(f5); end; @@ -140,12 +200,15 @@ begin t:=36; pct:=pct+1; for j:= 1 to 99 do begin a1:=f5^; get(f5); for i:= -10 to +10 do if a1[i]<> i*j then e(14) end; +#ifndef NOFLOAT vr.t:=false; for i:= 1 to 1000 do begin vr.r:=i+0.5; f6^:=vr; put(f6) ; p:=true; end; reset(f6); p:=false; for i:= 1 to 999 do begin vr:=f6^; get(f6); if vr.r <> i+0.5 then p:=true end; if p then e(15); +#endif + rewrite(f6); if not eof(f6) then e(16); for i:= 1 to 1000 do begin vr.b:=i mod 2; f6^:=vr; put(f6) end; @@ -163,12 +226,15 @@ begin t:=36; pct:=pct+1; reset(f1); if ord(f1^) <> 32 then e(20); +#ifndef NOFLOAT rewrite(f1); x:=0.0625; write(f1,x:6:4, x:6:2); reset(f1); read(f1,y); if y <> 0.0625 then e(21); reset(f1); for i:= 1 to 12 do begin c[i]:= f1^; get(f1) end; if (c[1]<>'0') or (c[2]<>'.') or (c[4]<>'6') then e(22); if (c[7]<>' ') or (c[9]<>'0') or (c[10]<>'.') or (c[12]<>'6') then e(23); +#endif + end; {************************************************************************} @@ -202,13 +268,24 @@ var g1: text; colors := g2^; get(g2); if colors <> [pink] then e(8); colors := g2^; get(g2); if colors <> [green,pink] then e(9); colors := g2^; get(g2); if colors <> [green,orange] then e(10); + +#ifndef NOFLOAT r4.c1:='w'; r4.i:= -100; r4.x:=303.56; g3^:=r4; put(g3); r4.c1:='y'; r4.i:= -35; r4.x:=26.32; g3^:=r4; put(g3); r4.c1:='q'; r4.i:= +29; r4.x:=10.00; g3^:=r4; put(g3); r4.c1:='j'; r4.i:= 8; r4.x:=10000; g3^:=r4; put(g3); +#else + r4.c1:='w'; r4.i:= -100; g3^:=r4; put(g3); + r4.c1:='y'; r4.i:= -35; g3^:=r4; put(g3); + r4.c1:='q'; r4.i:= +29; g3^:=r4; put(g3); + r4.c1:='j'; r4.i:= 8; g3^:=r4; put(g3); +#endif + for i:= 1 to 1000 do begin g3^ := r4; put(g3) end; reset(g3); if eof(g3) then e(11); + +#ifndef NOFLOAT r4 := g3^; get(g3); if (r4.c1<>'w') or (r4.i<>-100) or (r4.x<>303.56) then e(12); r4 := g3^; get(g3); @@ -217,6 +294,17 @@ var g1: text; if (r4.c1<>'q') or (r4.i<> 29) or (r4.x<> 10.00) then e(14); r4 := g3^; get(g3); if (r4.c1<>'j') or (r4.i<> 8) or (r4.x<> 10000) then e(15); +#else + r4 := g3^; get(g3); + if (r4.c1<>'w') or (r4.i<>-100) then e(12); + r4 := g3^; get(g3); + if (r4.c1<>'y') or (r4.i<> -35) then e(13); + r4 := g3^; get(g3); + if (r4.c1<>'q') or (r4.i<> 29) then e(14); + r4 := g3^; get(g3); + if (r4.c1<>'j') or (r4.i<> 8) then e(15); +#endif + for j:= 1 to 100 do begin for i:= -10 to +10 do a1[i] := i*j; g4^ := a1; put(g4) end; @@ -261,13 +349,24 @@ var g1: text; colors := g2^; get(g2); if colors <> [pink] then e(8); colors := g2^; get(g2); if colors <> [green,pink] then e(9); colors := g2^; get(g2); if colors <> [green,orange] then e(10); + +#ifndef NOFLOAT r4.c1:='w'; r4.i:= -100; r4.x:=303.56; g3^:=r4; put(g3); r4.c1:='y'; r4.i:= -35; r4.x:=26.32; g3^:=r4; put(g3); r4.c1:='q'; r4.i:= +29; r4.x:=10.00; g3^:=r4; put(g3); r4.c1:='j'; r4.i:= 8; r4.x:=10000; g3^:=r4; put(g3); +#else + r4.c1:='w'; r4.i:= -100; g3^:=r4; put(g3); + r4.c1:='y'; r4.i:= -35; g3^:=r4; put(g3); + r4.c1:='q'; r4.i:= +29; g3^:=r4; put(g3); + r4.c1:='j'; r4.i:= 8; g3^:=r4; put(g3); +#endif + for i:= 1 to 1000 do begin g3^ := r4; put(g3) end; reset(g3); if eof(g3) then e(11); + +#ifndef NOFLOAT r4 := g3^; get(g3); if (r4.c1<>'w') or (r4.i<>-100) or (r4.x<>303.56) then e(12); r4 := g3^; get(g3); @@ -276,6 +375,16 @@ var g1: text; if (r4.c1<>'q') or (r4.i<> 29) or (r4.x<> 10.00) then e(14); r4 := g3^; get(g3); if (r4.c1<>'j') or (r4.i<> 8) or (r4.x<> 10000) then e(15); +#else + r4 := g3^; get(g3); + if (r4.c1<>'w') or (r4.i<>-100) then e(12); + r4 := g3^; get(g3); + if (r4.c1<>'y') or (r4.i<> -35) then e(13); + r4 := g3^; get(g3); + if (r4.c1<>'q') or (r4.i<> 29) then e(14); + r4 := g3^; get(g3); + if (r4.c1<>'j') or (r4.i<> 8) then e(15); +#endif for j:= 1 to 100 do begin for i:= -10 to +10 do a1[i] := i*j; g4^ := a1; put(g4) end; From de4de74d33df581323a55014ff537040ae1468ae Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 13 Oct 1986 14:45:18 +0000 Subject: [PATCH 0285/1625] Removed part of test 127. It tried a LFR after doing a LOC and an ASS. This is of course not allowed. --- emtest/tests | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/emtest/tests b/emtest/tests index c3a74ddb..d71da49a 100644 --- a/emtest/tests +++ b/emtest/tests @@ -3583,19 +3583,6 @@ OK cmp zne *1 OK -; same as above but with ASS instead of ASP - lxl 0 - cal $retp2 - loc PS - ass WS - lfr 2*PS - lpi $retp2 - cmp - zne *1 - lxl 0 - cmp - zne *1 -OK PROC pro $retw0,0 ret 0 From ed66c5a3e2d841d40ba809cf2954b15aea2f055d Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 15 Oct 1986 13:58:51 +0000 Subject: [PATCH 0286/1625] Removed some ridiculous code. --- mach/vax4/libem/cuu.s | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/mach/vax4/libem/cuu.s b/mach/vax4/libem/cuu.s index 14931e22..efafd2aa 100644 --- a/mach/vax4/libem/cuu.s +++ b/mach/vax4/libem/cuu.s @@ -6,20 +6,11 @@ .cuu: movl (sp)+,r1 - movl (sp)+,r0 - cmpl (sp),$1 - beql Lfrom1 - cmpl (sp),$2 - beql Lfrom2 + cmpl (sp)+,$4 + bneq Lerr cmpl (sp)+, $4 bneq Lerr jmp (r1) -Lfrom1: - movzbw 4(sp), 4(sp) -Lfrom2: - tstl (sp)+ - movzwl (sp), (sp) - jmp (r1) Lerr: pushl $EILLINS jmp .fat From 275a42de8b0cb24f61862ea141fb6897f3b721b2 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 16 Oct 1986 16:36:00 +0000 Subject: [PATCH 0287/1625] Deleted the #ifdef JOHAN stuff, and added a #define MAXSECT. --- h/out.h | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/h/out.h b/h/out.h index 6bcceaa1..190b1321 100644 --- a/h/out.h +++ b/h/out.h @@ -19,11 +19,8 @@ struct outhead { #define O_MAGIC 0x0201 /* magic number of output file */ #define O_STAMP 0 /* version stamp */ +#define MAXSECT 64 /* Maximum number of sections */ -#ifdef JOHAN -#define HF_BREV 0x0001 /* high order byte lowest address */ -#define HF_WREV 0x0002 /* high order word lowest address */ -#endif JOHAN #define HF_LINK 0x0004 /* unresolved references left */ #define HF_8086 0x0008 /* os_base specially encoded */ @@ -62,10 +59,8 @@ struct outname { #define RELO2 2 /* 2 bytes */ #define RELO4 4 /* 4 bytes */ #define RELPC 0x08 /* pc relative */ -#ifndef JOHAN #define RELBR 0x10 /* High order byte lowest address. */ #define RELWR 0x20 /* High order word lowest address. */ -#endif JOHAN /* * section type bits and fields @@ -89,9 +84,7 @@ struct outname { #define S_LIN 0x0200 /* hll source line item */ #define S_FIL 0x0300 /* hll source file item */ #define S_MOD 0x0400 /* ass source file item */ -#ifndef JOHAN #define S_COM 0x1000 /* Common name. */ -#endif JOHAN /* * structure format strings From a6609855290c6b88d8c38db72a0796f5001c4f51 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 20 Oct 1986 09:35:51 +0000 Subject: [PATCH 0288/1625] I don't really know why, but the file was changed. --- util/led/relocate.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/util/led/relocate.c b/util/led/relocate.c index 4164a7af..bd06e2d9 100644 --- a/util/led/relocate.c +++ b/util/led/relocate.c @@ -158,7 +158,19 @@ addrelo(relo, names, sects, valu_out) register ushort index = NLocals; register long valu = *valu_out; - if (ISUNDEFINED(local) || ISCOMMON(local)) { + if ((local->on_type & S_SCT)) { + register int sectindex = (local->on_type & S_TYP) - S_MIN; + + if (refers_zero(valu, relo, sects[sectindex].os_flen)) { + valu -= sects[sectindex].os_flen; + valu += outsect[sectindex].os_flen; + valu += relorig[sectindex].org_zero; + } else { + valu += relorig[sectindex].org_flen; + } + valu += outsect[sectindex].os_base; + index += NGlobals + sectindex; + } else { register struct outname *name; extern int hash(); extern struct outname *searchname(); @@ -174,20 +186,6 @@ addrelo(relo, names, sects, valu_out) valu += name->on_valu; index += NGlobals + (name->on_type & S_TYP) - S_MIN; } - } else { - register int sectindex = (local->on_type & S_TYP) - S_MIN; - - if (!(local->on_type & S_SCT)) - fatal("bad relocation index"); - if (refers_zero(valu, relo, sects[sectindex].os_flen)) { - valu -= sects[sectindex].os_flen; - valu += outsect[sectindex].os_flen; - valu += relorig[sectindex].org_zero; - } else { - valu += relorig[sectindex].org_flen; - } - valu += outsect[sectindex].os_base; - index += NGlobals + sectindex; } *valu_out = valu; return index; From 6365a82a0603f9781ab7cd0c9ee1dd0614869df8 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 20 Oct 1986 10:17:57 +0000 Subject: [PATCH 0289/1625] A new version, that no longer tries to move all null parts to the end of a segment. It also uses the "object" library to read and write ACK- object files and libraries. --- util/led/Makefile | 75 ++------------ util/led/WRONG | 53 +--------- util/led/archive.c | 20 ++-- util/led/const.h | 6 -- util/led/debug.h | 5 +- util/led/error.c | 9 +- util/led/extract.c | 39 +++---- util/led/finish.c | 34 +++--- util/led/main.c | 45 ++++---- util/led/memory.c | 85 ++++----------- util/led/orig.h | 3 +- util/led/output.c | 2 +- util/led/read.c | 152 +-------------------------- util/led/relocate.c | 57 ++-------- util/led/save.c | 4 +- util/led/scan.c | 80 ++++++++------ util/led/sym.c | 15 ++- util/led/write.c | 247 ++++++-------------------------------------- 18 files changed, 212 insertions(+), 719 deletions(-) diff --git a/util/led/Makefile b/util/led/Makefile index 39008c0b..3cf9ab62 100644 --- a/util/led/Makefile +++ b/util/led/Makefile @@ -2,36 +2,24 @@ # Author: L.J. Bekema @ VU Informatica, Amsterdam # -.SUFFIXES: .c,v .h .h,v - -.c,v.o: - co -q $*.c - $(CC) $(CFLAGS) -c $*.c - rm -f $*.c - -.h,v.h: - co -q $*.h - # Definitions for the making programs. -LIBDIR=../../lib -PREFLAGS= -DNDEBUG -DNASSERT -CFLAGS = -O $(PREFLAGS) +EM = ../.. +LIBDIR= $(EM)/lib +PREFLAGS= -I$(EM)/h -DNDEBUG -DNASSERT +CFLAGS = $(PREFLAGS) -O LDFLAGS = -LINTFLAGS=-phbxac $(PREFLAGS) +LDLIBS = $(EM)/modules/lib/libstr.a $(EM)/modules/lib/libobj.a +LINTFLAGS=-phbxa $(PREFLAGS) PR = pr PRFLAGS = # Some convenient macro definitions. -CFILES = archive.c byte_order.c error.c extract.c finish.c main.c memory.c\ +CFILES = archive.c error.c extract.c finish.c main.c memory.c\ output.c read.c relocate.c save.c scan.c sym.c write.c -CVFILES = archive.c,v byte_order.c,v error.c,v extract.c,v finish.c,v main.c,v\ - memory.c,v output.c,v read.c,v relocate.c,v save.c,v scan.c,v\ - sym.c,v write.c,v HFILES = assert.h const.h debug.h defs.h memory.h orig.h scan.h -HVFILES = assert.h,v const.h,v debug.h,v defs.h,v memory.h,v orig.h,v scan.h,v -OFILES = archive.o byte_order.o error.o extract.o finish.o main.o memory.o\ +OFILES = archive.o error.o extract.o finish.o main.o memory.o\ output.o read.o relocate.o save.o scan.o sym.o write.o # Things that can be made. @@ -39,9 +27,6 @@ OFILES = archive.o byte_order.o error.o extract.o finish.o main.o memory.o\ led: $(OFILES) $(CC) $(LDFLAGS) $(OFILES) $(LDLIBS) -o led -mach.c: mach.c,v - co -q mach.c - install:led cp led $(LIBDIR)/em_led @@ -49,103 +34,65 @@ cmp: led cmp led $(LIBDIR)/em_led lint: - -for i in $(CFILES) $(HFILES) mach.c; do\ - if test ! -f $$i; then\ - echo $$i >> checked.out;\ - co -q $$i;\ - fi;\ - done lint $(LINTFLAGS) $(CFILES) - rm -f `cat checked.out` checked.out -pr: $(CVFILES) $(HVFILES) mach.c - @-for i in $?; do\ - co -q -p $$i | $(PR) $(PRFLAGS) -h `basename $$i ,v`;\ - done +pr: $(CFILES) $(HFILES) mach.c + $(PR) $(PRFLAGS) $? @touch pr opr: make pr | opr clean: - rm *.o led + rm -f Out *.o led nohup.out depend: - -for i in $(CFILES); do\ - if test ! -f $$i; then\ - echo $$i >> checked.out;\ - co -q $$i;\ - fi;\ - done makedepend $(CFILES) - rm -f `cat checked.out` checked.out # The next lines are generated automatically. # AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO -archive.o: ../../h/arch.h -archive.o: ../../h/out.h -archive.o: ../../h/ranlib.h archive.o: const.h archive.o: debug.h archive.o: defs.h archive.o: memory.h -byte_order.o: assert.h -byte_order.o: const.h -error.o: ../../h/out.h error.o: const.h -extract.o: ../../h/out.h extract.o: const.h extract.o: debug.h extract.o: defs.h extract.o: memory.h extract.o: orig.h extract.o: scan.h -finish.o: ../../h/out.h finish.o: const.h finish.o: defs.h finish.o: memory.h finish.o: orig.h finish.o: scan.h -main.o: ../../h/out.h main.o: const.h main.o: debug.h main.o: defs.h main.o: memory.h main.o: orig.h -memory.o: ../../h/out.h memory.o: assert.h memory.o: const.h memory.o: debug.h memory.o: mach.c memory.o: memory.h -output.o: ../../h/out.h output.o: const.h output.o: memory.h -read.o: ../../h/arch.h -read.o: ../../h/out.h -read.o: ../../h/ranlib.h read.o: assert.h read.o: const.h -relocate.o: ../../h/out.h relocate.o: const.h relocate.o: debug.h relocate.o: defs.h relocate.o: orig.h -save.o: ../../h/arch.h -save.o: ../../h/out.h save.o: assert.h save.o: const.h save.o: memory.h -scan.o: ../../h/arch.h -scan.o: ../../h/out.h -scan.o: ../../h/ranlib.h scan.o: assert.h scan.o: const.h scan.o: memory.h scan.o: scan.h -sym.o: ../../h/out.h sym.o: const.h sym.o: memory.h -write.o: ../../h/out.h write.o: assert.h write.o: const.h write.o: memory.h diff --git a/util/led/WRONG b/util/led/WRONG index 1c3a17b4..226f0e39 100644 --- a/util/led/WRONG +++ b/util/led/WRONG @@ -1,56 +1,12 @@ This file contains a summary of the bugs/features/inconsistencies Robbert and Ed found while making the linker usable for the 68000 and amoeba. +I (Ceriel Jacobs) took the liberty of removing the ones that I fixed from +this list. -There is something wrong with the way the combination of -assembler and linker handle bss. -In the original (Duk's) the assembler translated .space and, worse, .align -to a sequence of zero's. If this sequence was at the end of a segment -within a module the assembler didn't put zero in the segment but sets -os_flen to the amount of space initialized before the zero space -and os_size to the segements size. (os_size - os_flen) is then the -size of the space filled by zeroes. -For the sake of clarity, let us call 0...os_flen-1 initialized space -and os_flen..os_size-1 uninitialized space. -Now the linker, it does a nasty trick. It gathers the uninitialized space -of all modules within a segment and puts it consequtively at the end -of the segment. I think that I understand the reason: This way you can keep -your resultant a.out smaller and you don't need a special bss segment -(a la unix). But it is incorrect, the net effect is that the .align's -at the end of segments within a module do have the desired effect, -the space thus allocated is removed to 'higher spheres' thereby -leaving the first items of that segment in the inmediatly following -modules at unaligned boundaries. -What should be done is that the linker leaves the initialized and -the unitialized code alone and regards the whole a a chunk that can be -relocated. Only producing a difference of os_size and os_flen for -the zeroes at the very end of the segment. Thereby collapsing all -.space (and .align) commands into zero space only if they -are in consequtive modules at the end of the segment, with modules -NOT containing any initialized data. -I already, ad-hoc, changed the code of the assembler to producing 'hard' -zeroes when aligning. The trick could also be done for .space -but is a bit harder here. -The reason: .space is also used to allocate space in the BSS segment -if that produced zeroes in the a.out file (0..bss_size) we would -have a.out files that are far too large. -This feature of the linker also caused weird effects for names that -are defined as the very last in a section within a module, without -any data (initialized or uninitialezed) after it. -The names a regarded as pointing into the uninitialized space and -thus relocated to the end of the section. -The sequence - .sect .data -begdata: - .sect .... -in an head_em.s resulted in the relocation of begdata to the END -of the .data segment. Another problem form the commons: 1 - Local commons are not handled by led and not produced by as. - using .comm for unitialized data is not correct because (from C) - two uninitialized static declarations for the same name in - different modules will be handled as external commons and thus - be overlayed. + Must, and will be handled by as. 2 - The commons are allocated at the very end of the first pass, after the initialezed data has been allocated in the segments. The order on which the commons are allocated seems to be random. That way it is impossible @@ -67,6 +23,3 @@ replacing/adding/deleting modules is likely to produce libraries with incorrect ranlib entries. The major troublemaker seems to be the extra padding byte at the end of odd sized modules. - -Led should return a non-zero value when it has found Undefined symbols -or has another reason for not being able to produce a correct output file. diff --git a/util/led/archive.c b/util/led/archive.c index 57e6fbdf..70a59c3c 100644 --- a/util/led/archive.c +++ b/util/led/archive.c @@ -2,9 +2,9 @@ static char rcsid[] = "$Header$"; #endif -#include "../../h/arch.h" -#include "../../h/out.h" -#include "../../h/ranlib.h" +#include +#include +#include #include "const.h" #include "debug.h" #include "defs.h" @@ -30,20 +30,21 @@ getsymdeftable() register struct ranlib *ran; register long count; register long nran, nchar; - extern long getlong(); + extern long rd_long(); + extern int infile; - count = nran = getlong(); + count = nran = rd_long(infile); debug("%ld ranlib structs, ", nran, 0, 0, 0); off = hard_alloc(ALLORANL, nran * sizeof(struct ranlib)); if (off == BADOFF) fatal("no space for ranlib structs"); ran = (struct ranlib *)address(ALLORANL, off); - read_table(ran, count); - nchar = getlong(); + rd_ranlib(infile, ran, count); + nchar = rd_long(infile); debug("%ld ranlib chars\n", nchar, 0, 0, 0); if ((off = hard_alloc(ALLORANL, nchar)) == BADOFF) fatal("no space for ranlib strings"); - read_char(address(ALLORANL, off), nchar); + rd_bytes(infile, address(ALLORANL, off), nchar); ran = (struct ranlib *)address(ALLORANL, (ind_t)0); while (count--) { /* @@ -60,7 +61,6 @@ getsymdeftable() } extern char *modulname; -extern long position; /* * Process archive with table of contents. The table of contents tells @@ -107,7 +107,6 @@ arch() get_archive_header(&arhdr); modulname = arhdr.ar_name; debug("%s defines %s\n", modulname, string, 0, 0); - position = ran->ran_pos + AR_SIZE; resolved = TRUE; /* * This archive member is going to be linked, @@ -170,7 +169,6 @@ arch2() get_archive_header(&arhdr); modulname = arhdr.ar_name; debug("%s: archive member\n", modulname, 0, 0, 0); - position = *pos + AR_SIZE; finish(); } localpos += sizeof(long); /* Skip ENDLIB. */ diff --git a/util/led/const.h b/util/led/const.h index 6c70358d..7252e9c8 100644 --- a/util/led/const.h +++ b/util/led/const.h @@ -5,18 +5,12 @@ typedef int bool; #define FALSE 0 #define TRUE 1 -#define S_ZER 0x2000 /* Internal use only. */ - #define WIDTH 8 /* Number of bits in a byte. */ #define BYTEMASK 0xFF /* Mask to get low order byte. */ -#define MININT (1 << (sizeof(int) * WIDTH - 1)) -#define MAXCHUNK (-(MININT + 1)) /* Highest count we write(2). */ #define RFLAG 0x01 /* -r flag given. */ #define SFLAG 0x02 /* -s flag given. */ -#define MAXSECT 64 /* Maximum number of sections. */ - #define PLAIN 0 /* Input file is a normal file. */ #define ARCHIVE 1 /* Input file is an archive. */ diff --git a/util/led/debug.h b/util/led/debug.h index 25ca825a..1f7d7a65 100644 --- a/util/led/debug.h +++ b/util/led/debug.h @@ -2,10 +2,11 @@ #ifdef NDEBUG -#define debug(s, a1, a2, a3, a4) dummy() +#define debug(s, a1, a2, a3, a4) #else +extern int DEB; -#define debug(s, a1, a2, a3, a4) printf(s, a1, a2, a3, a4) +#define debug(s, a1, a2, a3, a4) (DEB && printf(s, a1, a2, a3, a4)) #endif diff --git a/util/led/error.c b/util/led/error.c index 63b047b6..358cd9cd 100644 --- a/util/led/error.c +++ b/util/led/error.c @@ -4,7 +4,7 @@ static char rcsid[] = "$Header$"; #include #include -#include "../../h/out.h" +#include #include "const.h" static short nerrors = 0; @@ -13,11 +13,14 @@ static diag(); stop() { extern char *outputname; + extern int exitstatus; - if (nerrors) + if (nerrors) { unlink(outputname); + exit(nerrors); + } - exit(nerrors); + exit(exitstatus); } trap_signals() diff --git a/util/led/extract.c b/util/led/extract.c index dd6753ba..ea3040a9 100644 --- a/util/led/extract.c +++ b/util/led/extract.c @@ -2,7 +2,7 @@ static char rcsid[] = "$Header$"; #endif -#include "../../h/out.h" +#include #include "const.h" #include "debug.h" #include "defs.h" @@ -47,23 +47,20 @@ get_names(head) register struct outhead *head; { register int nnames; - register ind_t sectindex, nameindex, charindex; + register ind_t nameindex, charindex; register ind_t charoff; extern int flagword; nnames = head->oh_nname; - sectindex = IND_SECT(*head); nameindex = IND_NAME(*head); charindex = IND_CHAR(*head); charoff = OFF_CHAR(*head); while (nnames--) { - register struct outsect *sects; struct outname name; /* A local copy. */ /* * Because savelocal/getexternal might relocate the modules * we have to compute the core addresses again. */ - sects = (struct outsect *)modulptr(sectindex); name = *(struct outname *)modulptr(nameindex); /* * Change the offset in file into an offset in the memory area. @@ -73,7 +70,7 @@ get_names(head) */ if (name.on_foff) name.on_foff += charindex - charoff; - namerelocate(&name, sects); + namerelocate(&name); if (name.on_type & S_EXT) { getexternal(&name); } else { @@ -111,14 +108,19 @@ process(head) nsect = head->oh_nsect; outsp = outsect; while (nsect--) { + if (sects->os_flen) { + /* contains non-zero stuff */ + outsp->os_flen = outsp->os_size + sects->os_flen; + } + else { + outsp->os_flen += sects->os_flen; + } outsp->os_size += sects->os_size; - outsp->os_flen += sects->os_flen; /* * Add all flen's and all (size - flen == zero)'s of * preceding sections with the same number. */ - orig->org_flen += sects->os_flen; - orig->org_zero += sects->os_size - sects->os_flen; + orig->org_size = outsp->os_size; orig++; outsp++; sects++; } } @@ -127,21 +129,13 @@ process(head) * Add relocation constant for names in user defined sections. * The value of a common name indicates a size instead of an offset, * and hence shouldn't be relocated. - * The value of a name in the zero part of a section is relative from the - * beginning of the section, not from the beginning of the zero part; but - * all zero parts will be put after the normal section contents, so we - * must subtract the flen of its section from the value (and later on add - * the total flen of its section) and add the accumulated size of all - * zero parts in preceding sections with the same number. * Otherwise we just add the accumulated size of all normal parts in preceding * sections with the same size. */ -namerelocate(name, sects) +namerelocate(name) register struct outname *name; - struct outsect *sects; { register int type = name->on_type; - register int sectindex; if ((type & S_TYP) == S_UND || (type & S_TYP) == S_ABS) return; @@ -150,14 +144,7 @@ namerelocate(name, sects) return; } - sectindex = (type & S_TYP) - S_MIN; - if (name->on_valu >= sects[sectindex].os_flen) { - name->on_type |= S_ZER; - name->on_valu -= sects[sectindex].os_flen; - name->on_valu += relorig[sectindex].org_zero; - } else { - name->on_valu += relorig[sectindex].org_flen; - } + name->on_valu += relorig[(type & S_TYP) - S_MIN].org_size; } /* diff --git a/util/led/finish.c b/util/led/finish.c index c2592859..5eb5ec1a 100644 --- a/util/led/finish.c +++ b/util/led/finish.c @@ -2,7 +2,7 @@ static char rcsid[] = "$Header$"; #endif -#include "../../h/out.h" +#include #include "const.h" #include "defs.h" #include "memory.h" @@ -38,7 +38,7 @@ finish() adjust_names(names, head, chars); handle_relos(head, sects, names); if (!incore && !(flagword & SFLAG)) { - put_locals(names, head->oh_nname, sects); + put_locals(names, head->oh_nname); #ifdef SYMDBUG put_dbug(OFF_DBUG(*head)); #endif SYMDBUG @@ -86,6 +86,7 @@ handle_relos(head, sects, names) register char *emit; extern char *getemit(); extern struct outrelo *nextrelo(); + static long zeros[MAXSECT]; if (incore) { nrelo = head->oh_nrelo; sectindex = -1; @@ -95,7 +96,7 @@ handle_relos(head, sects, names) sectindex = relo->or_sect - S_MIN; emit = getemit(head, sects, sectindex); } - relocate(head, emit, names, relo, sects); + relocate(head, emit, names, relo); relo++; } } else { @@ -105,16 +106,22 @@ handle_relos(head, sects, names) while (nrelo--) { relo = nextrelo(); if (relo->or_sect - S_MIN == sectindex) { - relocate(head,emit,names,relo,sects); + relocate(head,emit,names,relo); /* * Write out the (probably changed) * relocation information. */ if (flagword & RFLAG) - wrt_relo(relo); + wr_relo(relo, 1); } } - wrt_emit(emit, sectindex, sects[sectindex].os_flen); + if (sects[sectindex].os_flen) { + wrt_nulls(sectindex, zeros[sectindex]); + zeros[sectindex] = 0; + wrt_emit(emit, sectindex, sects[sectindex].os_flen); + } + zeros[sectindex] += sects[sectindex].os_size - + sects[sectindex].os_flen; /* * XXX We should be able to free the emitted bytes. */ @@ -126,14 +133,13 @@ handle_relos(head, sects, names) * Write out the local names that must be saved. */ static -put_locals(name, nnames, sects) +put_locals(name, nnames) register struct outname *name; register ushort nnames; - register struct outsect *sects; { while (nnames--) { if ((name->on_type & S_EXT) == 0 && mustsavelocal(name)) { - namerelocate(name, sects); + namerelocate(name); addbase(name); wrt_name(name); } @@ -154,8 +160,8 @@ compute_origins(sect, nsect) register struct orig *orig = relorig; while (nsect--) { - orig->org_flen += sect->os_flen; - orig->org_zero += sect->os_size - sect->os_flen; + + orig->org_size += sect->os_size; orig++; sect++; } } @@ -173,14 +179,12 @@ put_dbug(offdbug) register int nbytes; register long dbugsize; extern long objectsize; - extern long position; dbugsize = objectsize - offdbug; - seek(position + offdbug); while (dbugsize) { nbytes = dbugsize > 512 ? 512 : dbugsize; - read_char(buf, (long)nbytes); - wrt_dbug(buf, nbytes); + rd_dbug(buf, (long)nbytes); + wr_dbug(buf, (long) nbytes); dbugsize -= nbytes; } } diff --git a/util/led/main.c b/util/led/main.c index 131e2c04..a372d85b 100644 --- a/util/led/main.c +++ b/util/led/main.c @@ -7,7 +7,7 @@ static char rcsid[] = "$Header$"; */ #include -#include "../../h/out.h" +#include #include "const.h" #include "debug.h" #include "defs.h" @@ -15,6 +15,9 @@ static char rcsid[] = "$Header$"; #include "orig.h" extern bool incore; +#ifndef NDEBUG +int DEB = 0; +#endif static initializations(); static first_pass(); @@ -65,7 +68,6 @@ initializations(argc, argv) progname = argv[0]; passnumber = FIRST; - determine_ordering(); init_core(); init_symboltable(); outhead.oh_magic = O_MAGIC; @@ -76,6 +78,7 @@ initializations(argc, argv) int flagword = 0; /* To store command-line options. */ char *outputname = "a.out"; /* Name of the resulting object file. */ +int exitstatus = 0; /* * Scan the arguments. @@ -90,7 +93,7 @@ first_pass(argv) int sectno; int h; extern int atoi(); - extern char *index(); + extern char *strindex(); extern int hash(); extern struct outname *searchname(); @@ -111,7 +114,7 @@ first_pass(argv) * section
. */ sectno = atoi(++argp); - if ((argp = index(argp, ':')) == (char *)0) + if ((argp = strindex(argp, ':')) == (char *)0) fatal("usage: -a
:"); setlign(sectno, number(++argp)); break; @@ -124,10 +127,15 @@ first_pass(argv) *
. */ sectno = atoi(++argp); - if ((argp = index(argp, ':')) == (char *)0) + if ((argp = strindex(argp, ':')) == (char *)0) fatal("usage: -b
:"); setbase(sectno, number(++argp)); break; +#ifndef NDEBUG + case 'd': + DEB = 1; + break; +#endif case 'o': /* * The `name' argument after -o is used as name @@ -311,8 +319,7 @@ pass1(file) static evaluate() { - if (!(flagword & RFLAG)) - norm_commons(); + norm_commons(); complete_sections(); if (!(flagword & RFLAG)) change_names(); @@ -324,7 +331,7 @@ extern ushort NGlobals, NLocals; * Sect_comm[N] is the number of common bytes in section N. * It is computed after pass 1. */ -static long sect_comm[MAXSECT]; +long sect_comm[MAXSECT]; /* * If there are undefined names, we print them and we set a flag so that @@ -347,9 +354,13 @@ norm_commons() if (ISUNDEFINED(name)) { if (!und) { und = TRUE; + if (!(flagword & RFLAG)) { + exitstatus = 1; + fprintf(stderr, "Undefined:\n"); + } outhead.oh_flags |= HF_LINK; + if (flagword & RFLAG) break; flagword = (flagword & ~SFLAG) | RFLAG; - fprintf(stderr, "Undefined:\n"); } fprintf(stderr, "\t%s\n", address(ALLOGCHR, (ind_t)name->on_foff) @@ -398,8 +409,7 @@ complete_sections() foff = SZ_HEAD + outhead.oh_nsect * SZ_SECT; for (sectindex = 0; sectindex < outhead.oh_nsect; sectindex++) { - relorig[sectindex].org_flen = (long)0; - relorig[sectindex].org_zero = (long)0; + relorig[sectindex].org_size = (long)0; outsect[sectindex].os_foff = foff; foff += outsect[sectindex].os_flen; @@ -497,8 +507,7 @@ tstbit(indx, string) } /* - * Add the base of the section of a name to its value. For a name in the zero - * part, the size of the normal part is also a "base". + * Add the base of the section of a name to its value. */ addbase(name) struct outname *name; @@ -511,10 +520,6 @@ addbase(name) if (name->on_type & S_COM) return; - if (name->on_type & S_ZER) { - name->on_valu += outsect[sectindex].os_flen; - name->on_type &= ~S_ZER; - } name->on_valu += outsect[sectindex].os_base; debug( "%s: type 0x%x, value %ld\n", address((name->on_type & S_EXT) ? ALLOGCHR : ALLOLCHR, @@ -564,9 +569,3 @@ pass2(file) } closefile(file); } - -#ifdef NDEBUG - -dummy() { ; } - -#endif diff --git a/util/led/memory.c b/util/led/memory.c index 0f41696b..af93d45d 100644 --- a/util/led/memory.c +++ b/util/led/memory.c @@ -9,7 +9,7 @@ static char rcsid[] = "$Header$"; * is done and pieces after the one that requested the growth are moved up. */ -#include "../../h/out.h" +#include #include "const.h" #include "assert.h" #include "debug.h" @@ -19,8 +19,6 @@ static copy_down(); static copy_up(); static free_saved_moduls(); static writelong(); -static sectswap(); -static reloswap(); static namecpy(); struct memory mems[NMEMS]; @@ -201,11 +199,11 @@ copy_up(mem, dist) */ ind_t alloc(piece, size) - register int piece; + int piece; register long size; { register ind_t incr = 0; - register ind_t left = mems[piece].mem_left; + ind_t left = mems[piece].mem_left; register ind_t full = mems[piece].mem_full; assert(passnumber == FIRST || (!incore && piece == ALLOMODL)); @@ -347,18 +345,14 @@ freeze_core() /* ------------------------------------------------------------------------- */ -extern bool bytes_reversed; -extern bool words_reversed; - /* * To transform the various pieces of the output in core to the file format, * we must order the bytes in the ushorts and longs as ACK prescribes. */ write_bytes() { - ushort nsect, nrelo; + ushort nsect; long offchar; - int fd; register struct memory *mem; extern ushort NLocals, NGlobals; extern long NLChars, NGChars; @@ -366,16 +360,11 @@ write_bytes() extern struct outhead outhead; extern struct outsect outsect[]; extern char *outputname; + int sectionno = 0; nsect = outhead.oh_nsect; - nrelo = outhead.oh_nrelo; offchar = OFF_CHAR(outhead); - if (bytes_reversed || words_reversed) { - swap((char *)&outhead, SF_HEAD); - sectswap(outsect, nsect); - reloswap(nrelo); - } /* * We allocated two areas: one for local and one for global names. * Also, we used another kind of on_foff than on file. @@ -391,66 +380,34 @@ write_bytes() offchar + NLChars ); } - if ((fd = creat(outputname, 0666)) < 0) + if (! wr_open(outputname)) { fatal("can't create %s", outputname); + } /* * These pieces must always be written. */ - writelong(fd, (char *)&outhead, (ind_t)SZ_HEAD); - writelong(fd, (char *)outsect, (ind_t)nsect * SZ_SECT); + wr_ohead(&outhead); + wr_sect(outsect, nsect); for (mem = &mems[ALLOEMIT]; mem < &mems[ALLORELO]; mem++) - writelong(fd, mem->mem_base, mem->mem_full); + wrt_emit(mem->mem_base, sectionno++, mem->mem_full); /* * The rest depends on the flags. */ if (flagword & RFLAG) - writelong(fd, mems[ALLORELO].mem_base, mems[ALLORELO].mem_full); + wr_relo((struct outrelo *) mems[ALLORELO].mem_base, + outhead.oh_nrelo); if (!(flagword & SFLAG)) { - writelong(fd, mems[ALLOLOCL].mem_base, mems[ALLOLOCL].mem_full); - writelong(fd, mems[ALLOGLOB].mem_base, mems[ALLOGLOB].mem_full); - writelong(fd, mems[ALLOLCHR].mem_base + 1, (ind_t)NLChars); - writelong(fd, mems[ALLOGCHR].mem_base + 1, (ind_t)NGChars); + wr_name((struct outname *) mems[ALLOLOCL].mem_base, + NLocals); + wr_name((struct outname *) mems[ALLOGLOB].mem_base, + NGlobals+nsect); + wr_string(mems[ALLOLCHR].mem_base + 1, (long)NLChars); + wr_string(mems[ALLOGCHR].mem_base + 1, (long)NGChars); #ifdef SYMDBUG - writelong(fd, mems[ALLODBUG].mem_base, mems[ALLODBUG].mem_full); + wr_dbug(mems[ALLODBUG].mem_base, mems[ALLODBUG].mem_full); #endif SYMDBUG } - close(fd); -} - -static -writelong(fd, base, size) - register int fd; - register char *base; - register ind_t size; -{ - register int chunk; - - while (size) { - chunk = size > (ind_t)MAXCHUNK ? MAXCHUNK : size; - write(fd, base, chunk); - size -= chunk; - base += chunk; - } -} - -static -sectswap(sect, nsect) - register struct outsect *sect; - register ushort nsect; -{ - while (nsect--) - swap((char *)sect++, SF_SECT); -} - -static -reloswap(nrelo) - register ushort nrelo; -{ - register struct outrelo *relo; - - relo = (struct outrelo *)mems[ALLORELO].mem_base; - while (nrelo--) - swap((char *)relo++, SF_RELO); + wr_close(); } static @@ -462,8 +419,6 @@ namecpy(name, nname, offchar) while (nname--) { if (name->on_foff) name->on_foff += offchar - 1; - if (bytes_reversed || words_reversed) - swap((char *)name, SF_NAME); name++; } } diff --git a/util/led/orig.h b/util/led/orig.h index 0fed9e97..004eebe7 100644 --- a/util/led/orig.h +++ b/util/led/orig.h @@ -1,6 +1,5 @@ /* $Header$ */ struct orig { - long org_flen; /* Accumulated length of preceding sections. */ - long org_zero; /* " " " zeroparts. */ + long org_size; /* Accumulated length of preceding sections. */ }; diff --git a/util/led/output.c b/util/led/output.c index b02337c3..74b5b88a 100644 --- a/util/led/output.c +++ b/util/led/output.c @@ -2,7 +2,7 @@ static char rcsid[] = "$Header$"; #endif -#include "../../h/out.h" +#include #include "const.h" #include "memory.h" diff --git a/util/led/read.c b/util/led/read.c index d33da712..eeb606e4 100644 --- a/util/led/read.c +++ b/util/led/read.c @@ -2,157 +2,9 @@ static char rcsid[] = "$Header$"; #endif -/* - * Routines to read in the various parts of the object file. - */ - -#include "../../h/arch.h" -#include "../../h/out.h" -#include "../../h/ranlib.h" -#include "const.h" -#include "assert.h" - int infile; /* The current input file. */ -extern bool bytes_reversed; -extern bool words_reversed; - -ushort -getushort() +rd_fatal() { - ushort ubuf; - - if (read(infile, (char *)&ubuf, 2) != 2) - fatal("premature EOF"); - if (bytes_reversed) - swap((char *)&ubuf, "2"); - return ubuf; -} - -long -getlong() -{ - long lbuf; - - if (read(infile, (char *)&lbuf, 4) != 4) - fatal("premature EOF"); - if (bytes_reversed || words_reversed) - swap((char *)&lbuf, "4"); - return lbuf; -} - -read_head(head) - register struct outhead *head; -{ - if (read(infile, (char *)head, SZ_HEAD) != SZ_HEAD) - fatal("premature EOF"); - if (bytes_reversed || words_reversed) - swap((char *)head, SF_HEAD); - if (BADMAGIC(*head)) - fatal("bad magic number"); -} - -read1(fd, val) -char *val ; { - if ( read(fd, val, 1)!=1 ) return 0 ; - return 1 ; -} -read2(fd, val) -int *val ; { - char rch[2] ; - if ( read(fd, rch, 2)!=2 ) return 0 ; - *val= (rch[0]&0377) + ((rch[1]&0377)<<8) ; - return 1 ; -} -read4(fd, val) -long *val ; { - int v1,v2 ; - if ( !read2(fd, &v1) ) return 0 ; - if ( !read2(fd, &v2) ) return 0 ; - *val = ((long)v1<<16) + (unsigned)v2 ; - return 1 ; -} - - -read_arhdr(arhdr) - register struct ar_hdr *arhdr; -{ - if ( read(infile,arhdr->ar_name,sizeof arhdr->ar_name)!= - sizeof arhdr->ar_name) { - goto peof ; - } - if ( !read4(infile,&arhdr->ar_date) ) goto peof ; - if ( !read1(infile,&arhdr->ar_uid) ) goto peof ; - if ( !read1(infile,&arhdr->ar_gid) ) goto peof ; - if ( !read2(infile,&arhdr->ar_mode) ) goto peof ; - if ( !read4(infile,&arhdr->ar_size) ) goto peof ; - return ; -peof: - fatal("Prematute EOF") ; -} - -read_table(ran, cnt) - register struct ranlib *ran; - register long cnt; -{ - read_char((char *)ran, cnt * SZ_RAN); - if (bytes_reversed || words_reversed) - while (cnt--) - swap((char *)ran++, SF_RAN); -} - -read_sect(sect, cnt) - register struct outsect *sect; - register ushort cnt; -{ - if (read(infile, (char *)sect, cnt * SZ_SECT) != cnt * SZ_SECT) - fatal("premature EOF"); - if (bytes_reversed || words_reversed) - while (cnt--) - swap((char *)sect++, SF_SECT); -} - -read_emit(emit, cnt) - register char *emit; - register long cnt; -{ - read_char(emit, cnt); -} - -read_relo(relo, cnt) - register struct outrelo *relo; - register ushort cnt; -{ - read_char((char *)relo, (long)cnt * SZ_RELO); - if (bytes_reversed || words_reversed) - while (cnt--) - swap((char *)relo++, SF_RELO); -} - -read_name(name, cnt) - register struct outname *name; - register ushort cnt; -{ - read_char((char *)name, (long)cnt * SZ_NAME); - if (bytes_reversed || words_reversed) - while (cnt--) - swap((char *)name++, SF_NAME); -} - -/* - * We don't have to worry about byte order here. - */ -read_char(string, cnt) - register char *string; - register long cnt; -{ - register int n; - - while (cnt) { - n = cnt >= MAXCHUNK ? MAXCHUNK : cnt; - if (read(infile, string, n) != n) - fatal("premature EOF"); - string += n; - cnt -= n; - } + fatal("read error"); } diff --git a/util/led/relocate.c b/util/led/relocate.c index bd06e2d9..354e08df 100644 --- a/util/led/relocate.c +++ b/util/led/relocate.c @@ -2,7 +2,7 @@ static char rcsid[] = "$Header$"; #endif -#include "../../h/out.h" +#include #include "const.h" #include "debug.h" #include "defs.h" @@ -98,39 +98,6 @@ putvalu(valu, addr, type) } } -/* - * Returns whether `valu' refers to the zero part of its section. - * The address of its zero part (relative to the beginning of the section) - * is in `zero_addr'. If `valu' is used in a pc-relative address computation, - * we have to do that computation ourselves. A pc-relative address is the - * difference between the address of the byte after the value and the "real" - * address: - * referencing address + its size + pc-relative address == "real" address. - */ -static bool -refers_zero(valu, relo, zero_addr) - register long valu; - struct outrelo *relo; - long zero_addr; -{ - if (relo->or_type & RELPC) { - valu += relo->or_addr; - /* - * Below is a dirty switch-statement. But an even dirtier - * statement would be: valu += (relo->or_type & RELSZ), - * because in that case you would have to know the values - * of the RELO[124] symbols. - */ - switch (relo->or_type & RELSZ) { - case RELO4: valu += 1; - valu += 1; - case RELO2: valu += 1; - case RELO1: valu += 1; - } - } - return valu >= zero_addr; -} - extern ushort NLocals, NGlobals; extern struct outsect outsect[]; extern struct orig relorig[]; @@ -148,10 +115,9 @@ extern struct orig relorig[]; * in position of the section of local. */ static ushort -addrelo(relo, names, sects, valu_out) +addrelo(relo, names, valu_out) struct outrelo *relo; struct outname *names; - struct outsect *sects; long *valu_out; /* Out variable. */ { register struct outname *local = &names[relo->or_nami]; @@ -161,13 +127,7 @@ addrelo(relo, names, sects, valu_out) if ((local->on_type & S_SCT)) { register int sectindex = (local->on_type & S_TYP) - S_MIN; - if (refers_zero(valu, relo, sects[sectindex].os_flen)) { - valu -= sects[sectindex].os_flen; - valu += outsect[sectindex].os_flen; - valu += relorig[sectindex].org_zero; - } else { - valu += relorig[sectindex].org_flen; - } + valu += relorig[sectindex].org_size; valu += outsect[sectindex].os_base; index += NGlobals + sectindex; } else { @@ -196,12 +156,11 @@ addrelo(relo, names, sects, valu_out) * which the header is pointed to by `head'. Relocation is relative to the * names in `names'; `relo' tells how to relocate. */ -relocate(head, emit, names, relo, sects) +relocate(head, emit, names, relo) struct outhead *head; char *emit; struct outname names[]; struct outrelo *relo; - struct outsect *sects; { long valu; int sectindex = relo->or_sect - S_MIN; @@ -220,7 +179,7 @@ relocate(head, emit, names, relo, sects) */ if (relo->or_nami < head->oh_nname) { /* First two cases. */ - relo->or_nami = addrelo(relo, names, sects, &valu); + relo->or_nami = addrelo(relo, names, &valu); } else { /* * Third case: it is absolute. The relocation of absolute @@ -234,11 +193,9 @@ relocate(head, emit, names, relo, sects) * the change in distance between the referencING and referencED * section. We already added the origin of the referencED section; * now we subtract the origin of the referencING section. - * Note that the the value to be relocated cannot lie within the - * zero part. */ if (relo->or_type & RELPC) - valu -= relorig[sectindex].org_flen+outsect[sectindex].os_base; + valu -= relorig[sectindex].org_size+outsect[sectindex].os_base; /* * Now put the value back. @@ -250,5 +207,5 @@ relocate(head, emit, names, relo, sects) * relocated to its offset in the new section. `Or_addr' must again be * in the normal part, of course. */ - relo->or_addr += relorig[sectindex].org_flen; + relo->or_addr += relorig[sectindex].org_size; } diff --git a/util/led/save.c b/util/led/save.c index b9483a40..fabca873 100644 --- a/util/led/save.c +++ b/util/led/save.c @@ -6,8 +6,8 @@ static char rcsid[] = "$Header$"; * If everything is kept in core, we must save some things for the second pass. */ -#include "../../h/arch.h" -#include "../../h/out.h" +#include +#include #include "const.h" #include "assert.h" #include "memory.h" diff --git a/util/led/scan.c b/util/led/scan.c index facb4adf..0ac32dd3 100644 --- a/util/led/scan.c +++ b/util/led/scan.c @@ -6,13 +6,14 @@ static char rcsid[] = "$Header$"; #include #include #endif SYMDBUG -#include "../../h/arch.h" -#include "../../h/out.h" -#include "../../h/ranlib.h" +#include +#include +#include #include "const.h" #include "assert.h" #include "memory.h" #include "scan.h" +#include "debug.h" #define READ 0 @@ -29,7 +30,6 @@ extern int passnumber; char *archname; /* Name of archive, if reading from archive. */ char *modulname; /* Name of object module. */ -long position; /* Byte offset within cuurent input file. */ #ifdef SYMDBUG long objectsize; #endif SYMDBUG @@ -65,7 +65,6 @@ getfile(filename) struct stat statbuf; extern int fstat(); #endif SYMDBUG - extern ushort getushort(); archname = (char *)0; modulname = (char *)0; @@ -73,7 +72,7 @@ getfile(filename) if (passnumber == FIRST || !incore) { if ((infile = open(filename, READ)) < 0) fatal("can't read %s", filename); - magic_number = getushort(); + magic_number = rd_unsigned2(infile); } else { modulbase = modulptr((ind_t)0); magic_number = *(ushort *)modulbase; @@ -88,7 +87,6 @@ getfile(filename) objectsize = statbuf.st_size; } #endif SYMDBUG - position = (long)0; seek((long)0); modulname = filename; return PLAIN; @@ -97,7 +95,7 @@ getfile(filename) case AALMAG: archname = filename; if (passnumber == FIRST) { - read_arhdr(&archive_header); + rd_arhdr(infile, &archive_header); if (strcmp(archive_header.ar_name, SYMDEF)) fatal("no table of contents"); } else if (incore) { @@ -123,7 +121,7 @@ get_archive_header(archive_header) register struct ar_hdr *archive_header; { if (passnumber == FIRST || !incore) { - read_arhdr(archive_header); + rd_arhdr(infile, archive_header); } else { /* Copy structs. */ *archive_header = *(struct ar_hdr *)modulbase; @@ -138,8 +136,10 @@ get_archive_header(archive_header) get_modul() { if (passnumber == FIRST) { + rd_fdopen(infile); scan_modul(); } else if (!incore) { + rd_fdopen(infile); read_modul(); } } @@ -161,11 +161,9 @@ scan_modul() if (space) { sect = (struct outsect *)modulptr(IND_SECT(*head)); get_indirect(head, sect); - } else { - lseek(infile, OFF_NAME(*head) - OFF_EMIT(*head), 1); } - read_name((struct outname *)modulptr(IND_NAME(*head)), head->oh_nname); - read_char((char *)modulptr(IND_CHAR(*head)), head->oh_nchar); + rd_name((struct outname *)modulptr(IND_NAME(*head)), head->oh_nname); + rd_string((char *)modulptr(IND_CHAR(*head)), head->oh_nchar); #ifdef SYMDBUG if (space) { get_dbug(*(ind_t *)modulptr(IND_DBUG(*head)), @@ -191,7 +189,7 @@ all_alloc() if (hard_alloc(ALLOMODL, (long)sizeof(struct outhead)) == BADOFF) fatal("no space for module header"); - read_head((struct outhead *)modulptr(IND_HEAD)); + rd_ohead((struct outhead *)modulptr(IND_HEAD)); /* * Copy the header because we need it so often. */ @@ -226,7 +224,7 @@ direct_alloc(head) size = modulsize(head) - sizeof(struct outhead) - rest; if (hard_alloc(ALLOMODL, size) == BADOFF) fatal("no space for module"); - read_sect((struct outsect *)modulptr(sectindex), nsect); + rd_sect((struct outsect *)modulptr(sectindex), nsect); return incore && alloc(ALLOMODL, rest) != BADOFF; } @@ -281,8 +279,28 @@ putemitindex(sectindex, emitoff, allopiece) long flen; ind_t emitindex; extern ind_t alloc(); + static long zeros[MAXSECT]; + register long zero = zeros[allopiece - ALLOEMIT]; + + /* + * Notice that "sectindex" is not a section number! + * It contains the offset of the section from the beginning + * of the module. Thus, it cannot be used to index "zeros". + * AIAIAIAIA + */ flen = ((struct outsect *)modulptr(sectindex))->os_flen; + if (flen && zero) { + if ((emitindex = alloc(allopiece, zero)) != BADOFF){ + register char *p = address(allopiece, emitindex); + + debug("Zeros %ld\n", zero, 0,0,0); + while (zero--) *p++ = 0; + } + else return FALSE; + } + zeros[allopiece - ALLOEMIT] = + ((struct outsect *) modulptr(sectindex))->os_size - flen; if ((emitindex = alloc(allopiece, flen)) != BADOFF) { *(ind_t *)modulptr(emitoff) = emitindex; return TRUE; @@ -343,13 +361,14 @@ get_indirect(head, sect) ind_t *reloindex; emitindex = (ind_t *)modulptr(IND_EMIT(*head)); - nsect = head->oh_nsect; piece = ALLOEMIT; - while (nsect--) { - read_emit(address(piece, *emitindex), sect->os_flen); + piece = ALLOEMIT; + for (nsect = 0; nsect < head->oh_nsect; nsect++) { + rd_outsect(nsect); + rd_emit(address(piece, *emitindex), sect->os_flen); piece++; emitindex++; sect++; } reloindex = (ind_t *)modulptr(IND_RELO(*head)); - read_relo((struct outrelo *)address(ALLORELO, *reloindex), + rd_relo((struct outrelo *)address(ALLORELO, *reloindex), head->oh_nrelo ); } @@ -398,7 +417,6 @@ read_modul() ushort nsect, nname; long size; long nchar; - long skip; extern ind_t hard_alloc(); assert(passnumber == SECOND); @@ -406,11 +424,10 @@ read_modul() if (hard_alloc(ALLOMODL, (long)sizeof(struct outhead)) == BADOFF) fatal("no space for module header"); head = (struct outhead *)modulptr(IND_HEAD); - read_head(head); + rd_ohead(head); nsect = head->oh_nsect; sectindex = IND_SECT(*head); nname = head->oh_nname; nameindex = IND_NAME(*head); nchar = head->oh_nchar; charindex = IND_CHAR(*head); - skip = OFF_NAME(*head) - OFF_EMIT(*head); #ifdef SYMDBUG size = modulsize(head) - (nsect * sizeof(ind_t) + 2 * sizeof(ind_t)); #else SYMDBUG @@ -423,10 +440,9 @@ read_modul() names = (struct outname *)modulptr(nameindex); chars = modulptr(charindex); - read_sect(sects, nsect); - lseek(infile, skip, 1); - read_name(names, nname); - read_char(chars, nchar); + rd_sect(sects, nsect); + rd_name(names, nname); + rd_string(chars, nchar); } /* @@ -437,8 +453,7 @@ static long align(size) register long size; { - size += sizeof(double) - 1; - return size - (size & (sizeof(double) - 1)); + return (size + (sizeof(double) - 1)) & ~(sizeof(double) - 1); } /* @@ -488,8 +503,7 @@ startrelo(head) if (incore) { reloindex = *(ind_t *)(modulbase + IND_RELO(*head)); walkrelo = (struct outrelo *)address(ALLORELO, reloindex); - } else - lseek(infile, position + OFF_RELO(*head), 0); + } } struct outrelo * @@ -500,7 +514,7 @@ nextrelo() if (incore) return walkrelo++; - read_relo(&relobuf, (ushort)1); + rd_relo(&relobuf, 1); return &relobuf; } @@ -524,8 +538,8 @@ getemit(head, sects, sectindex) ret = core_alloc(ALLOMODL, sects[sectindex].os_flen); if (ret == (char *)0) fatal("no space for section contents"); - lseek(infile, position + sects[sectindex].os_foff, 0); - read_emit(ret, sects[sectindex].os_flen); + rd_outsect(sectindex); + rd_emit(ret, sects[sectindex].os_flen); return ret; } /* diff --git a/util/led/sym.c b/util/led/sym.c index 335c404f..a5b172dc 100644 --- a/util/led/sym.c +++ b/util/led/sym.c @@ -6,9 +6,10 @@ static char rcsid[] = "$Header$"; * Symbol table management. */ -#include "../../h/out.h" +#include #include "const.h" #include "memory.h" +#include "debug.h" /* * Symbol table types. Each hash table entry contains the offset of a symbol @@ -55,17 +56,23 @@ searchname(string, hashval) register struct symbol *sym; symindex = hashtable[hashval]; + debug("looking for %s %d %ld:", string, hashval, hashtable[hashval], 0); while (symindex != BADOFF) { sym = (struct symbol *)address(ALLOSYMB, symindex); name = (struct outname *)address(ALLOGLOB, sym->sy_name); namestring = address(ALLOGCHR, (ind_t)name->on_foff); rcp = string; + debug("comp %s;", namestring, 0, 0, 0); while (*rcp == *namestring++) - if (*rcp++ == '\0') + if (*rcp++ == '\0') { + debug("found %x, %x, %lx\n", + name->on_type, name->on_desc, name->on_valu, 0); return name; + } symindex = sym->sy_next; } /* Not found. */ + debug("not found\n", 0, 0, 0, 0); return (struct outname *)0; } @@ -82,13 +89,15 @@ entername(name, hashval) ind_t savindex; ind_t symindex; ind_t namindex; - struct symbol *sym; + register struct symbol *sym; struct outname *newname; extern ind_t savechar(); extern ind_t hard_alloc(); + debug("entername %s %d %x %x", modulptr((ind_t)name->on_foff), hashval, name->on_type, name->on_desc); savindex = savechar(ALLOGCHR, (ind_t)name->on_foff); symindex = hard_alloc(ALLOSYMB, (long)sizeof(struct symbol)); + debug("; %ld\n", symindex, 0, 0, 0); namindex = hard_alloc(ALLOGLOB, (long)sizeof(struct outname)); if (savindex == BADOFF || symindex == BADOFF || namindex == BADOFF) fatal("symbol table overflow"); diff --git a/util/led/write.c b/util/led/write.c index 36d8a95d..0efbf28b 100644 --- a/util/led/write.c +++ b/util/led/write.c @@ -2,105 +2,23 @@ static char rcsid[] = "$Header$"; #endif -/* - * You can choose between two strategies: - * - Open the output file several times, once for each logical part, and - * write to it in multiple places. - * - Open the output file once and seek back and forth to each logical - * part. In this case #define OUTSEEK. - */ - +#include #include -#include "../../h/out.h" #include "const.h" #include "assert.h" #include "memory.h" -#include "orig.h" - -static openoutput(); -static wrt_head(); -static wrt_sect(); -extern long lseek(); - -#define WRITE 1 /* Argument to open(). */ - -/* - * Parts of the output file. - */ -#define PARTEMIT 0 -#define PARTRELO 1 -#define PARTNAME 2 -#define PARTCHAR 3 -#ifdef SYMDBUG -#define PARTDBUG 4 -#else SYMDBUG -#define PARTDBUG PARTCHAR -#endif SYMDBUG -#define NPARTS (PARTDBUG + 1) - -/* - * Call OUTPART() with the part you want to write on as argument, before - * you call OUTWRITE(). - */ -static int outpart = NPARTS; - -#ifdef OUTSEEK - -static int outfile; -static long outseek[NPARTS]; - -#define OUTPART(p) \ - { if (outpart != (p)) {\ - outpart = (p);\ - lseek(outfile, outseek[(p)], 0);\ - }\ - } -#define OUTSECT(i) \ - { outpart = NPARTS;\ - outseek[PARTEMIT] =\ - outsect[(i)].os_foff + relorig[(i)].org_flen;\ - } -#define OUTWRITE(b, n) \ - { if (write(outfile, (b), (n)) != (n))\ - fatal("write error");\ - outseek[outpart] += (n);\ - } -#define BEGINSEEK(p, o) \ - { outseek[(p)] = (o);\ - } - -#else OUTSEEK - -static int outfile[NPARTS]; - -#define OUTPART(p) \ - { outpart = (p);\ - } -#define OUTSECT(i) \ - { lseek( outfile[PARTEMIT],\ - outsect[(i)].os_foff + relorig[(i)].org_flen,\ - 0\ - );\ - } -#define OUTWRITE(b, n) \ - { if (write(outfile[outpart], (b), (n)) != (n))\ - fatal("write error");\ - } -#define BEGINSEEK(p, o) \ - { lseek(outfile[(p)], (o), 0);\ - } - -#endif OUTSEEK extern struct outhead outhead; extern struct outsect outsect[]; extern int flagword; -extern struct orig relorig[]; -extern bool bytes_reversed, words_reversed; extern bool incore; +wr_fatal() +{ + fatal("write error"); +} -static long offchar; +static long off_char; /* * Open the output file according to the chosen strategy. @@ -108,52 +26,16 @@ static long offchar; */ begin_write() { - register long off; + extern char *outputname; + register struct outhead *hd = &outhead; - openoutput(); - BEGINSEEK(PARTEMIT, (long)0); - wrt_head(&outhead); - wrt_sect(outsect, outhead.oh_nsect); - - off = SZ_HEAD + (long)outhead.oh_nsect * SZ_SECT + outhead.oh_nemit; - - if (flagword & RFLAG) { - /* A relocation table will be produced. */ - BEGINSEEK(PARTRELO, off); - off += (long)outhead.oh_nrelo * SZ_RELO; + assert(! incore); + if (! wr_open(outputname)) { + fatal("cannot write %s", outputname); } - - if (flagword & SFLAG) - return; - - /* A name table will be produced. */ - BEGINSEEK(PARTNAME, off); - off += (long)outhead.oh_nname * SZ_NAME; - BEGINSEEK(PARTCHAR, off); - offchar = off; /* See wrt_name(). */ -#ifdef SYMDBUG - off += outhead.oh_nchar; - BEGINSEEK(PARTDBUG, off); -#endif SYMDBUG -} - -static -openoutput() -{ -#ifndef OUTSEEK - register int *fdp; -#endif OUTSEEK - extern char *outputname; - - close(creat(outputname, 0666)); -#ifdef OUTSEEK - if ((outfile = open(outputname, WRITE)) < 0) - fatal("can't write %s", outputname); -#else OUTSEEK - for (fdp = &outfile[PARTEMIT]; fdp < &outfile[NPARTS]; fdp++) - if ((*fdp = open(outputname, WRITE)) < 0) - fatal("can't write %s", outputname); -#endif OUTSEEK + wr_ohead(hd); + wr_sect(outsect, hd->oh_nsect); + off_char = OFF_CHAR(*hd); } static struct outname * @@ -198,103 +80,42 @@ end_write() wrt_name(sectname(sectindex)); } -static -wrt_head(head) - register struct outhead *head; -{ - assert(!incore); - OUTPART(PARTEMIT); - if (bytes_reversed || words_reversed) - swap((char *)head, SF_HEAD); - OUTWRITE((char *)head, SZ_HEAD); - /* - * Swap back because we will need it again. - */ - if (bytes_reversed || words_reversed) - swap((char *)head, SF_HEAD); -} - -static -wrt_sect(sect, cnt) - register struct outsect *sect; - register ushort cnt; -{ - assert(!incore); - OUTPART(PARTEMIT); - while (cnt--) { - if (bytes_reversed || words_reversed) - swap((char *)sect, SF_SECT); - OUTWRITE((char *)sect, SZ_SECT); - /* - * Swap back because we will need it again. - */ - if (bytes_reversed || words_reversed) - swap((char *)sect, SF_SECT); - sect++; - } -} - -/* - * We don't have to worry about byte order here. - */ wrt_emit(emit, sectindex, cnt) - register char *emit; - int sectindex; - register long cnt; + char *emit; + int sectindex; + long cnt; { - register int n; - assert(!incore); - OUTPART(PARTEMIT); - OUTSECT(sectindex); + wr_outsect(sectindex); + wr_emit(emit, cnt); +} + +wrt_nulls(sectindex, cnt) + register long cnt; +{ + static char nullbuf[BUFSIZ]; + + wr_outsect(sectindex); while (cnt) { - n = cnt >= BUFSIZ ? BUFSIZ : cnt; - OUTWRITE(emit, n); - emit += n; + register int n = cnt >= BUFSIZ ? BUFSIZ : cnt; + wr_emit(nullbuf, (long)n); cnt -= n; } } -wrt_relo(relo) - register struct outrelo *relo; -{ - assert(!incore); - assert(flagword & RFLAG); - OUTPART(PARTRELO); - if (bytes_reversed || words_reversed) - swap((char *)relo, SF_RELO); - OUTWRITE((char *)relo, SZ_RELO); -} - wrt_name(name) register struct outname *name; { assert(!incore); assert(!(flagword & SFLAG)); if (name->on_mptr != (char *)0) { - register int len = strlen(name->on_mptr) + 1; + register long len = strlen(name->on_mptr) + 1; - OUTPART(PARTCHAR); - OUTWRITE(name->on_mptr, len); - name->on_foff = offchar; - offchar += len; + wr_string(name->on_mptr, len); + name->on_foff = off_char; + off_char += len; } else { name->on_foff = (long)0; } - OUTPART(PARTNAME); - if (bytes_reversed || words_reversed) - swap((char *)name, SF_NAME); - OUTWRITE((char *)name, SZ_NAME); + wr_name(name, 1); } -#ifdef SYMDBUG - -wrt_dbug(buf, size) - char *buf; - int size; -{ - assert(!incore); - assert(!(flagword & SFLAG)); - OUTPART(PARTDBUG); - OUTWRITE((char *)buf, size); -} -#endif SYMDBUG From db2859a2354ac30b8f5c5e6e2f15e82fc187420c Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 20 Oct 1986 11:28:29 +0000 Subject: [PATCH 0290/1625] Replaced a few "bss 2" by "bss EM_WSIZE". --- lang/basic/src.old/gencode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lang/basic/src.old/gencode.c b/lang/basic/src.old/gencode.c index e36aa7b7..8efd79f5 100644 --- a/lang/basic/src.old/gencode.c +++ b/lang/basic/src.old/gencode.c @@ -517,9 +517,9 @@ prologcode() fprintf(emfile,"dummy1\n con 0,0,0,0\n"); fprintf(emfile," exa _iomode\n_iomode\n rom \"O\"\n"); fprintf(emfile," exa _errsym\n"); - fprintf(emfile,"_errsym\n bss 2,0,1\n"); + fprintf(emfile,"_errsym\n bss EM_WSIZE,0,1\n"); fprintf(emfile," exa _erlsym\n"); - fprintf(emfile,"_erlsym\n bss 2,0,1\n"); + fprintf(emfile,"_erlsym\n bss EM_WSIZE,0,1\n"); } prolog2() From bcc72bb315111cf67117c962e022ccf8c5e386ee Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 20 Oct 1986 13:28:59 +0000 Subject: [PATCH 0291/1625] Caused a core dump on 68000-based machines (read: non-VAX) when called at a certain (high) level of verbosity, -v5 for instance. Cause: a null-reference. This is fixed. --- util/ack/rmach.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/ack/rmach.c b/util/ack/rmach.c index 14c946ac..16b3c893 100644 --- a/util/ack/rmach.c +++ b/util/ack/rmach.c @@ -257,7 +257,7 @@ intrf() { if ( debug>=3 ) { register list_elem *elem ; vprint("%s: from %s to %s '%s'\n", - new->t_name,new->t_in,new->t_out,new->t_prog) ; + new->t_name,new->t_in ? new->t_in : "(null)",new->t_out,new->t_prog) ; vprint("\targs: ") ; prns(new->t_argd) ; scanlist( l_first(new->t_mapf), elem ) { vprint("\t%s\n",l_content(*elem)) ; From b14786091068b996cb318242dacb1ed80cc09ea5 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 20 Oct 1986 13:47:26 +0000 Subject: [PATCH 0292/1625] Fixed a bug: ack could not see the difference between ".mod" and ".m". This is corrected. --- util/ack/scan.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/util/ack/scan.c b/util/ack/scan.c index 9165537f..a43193fc 100644 --- a/util/ack/scan.c +++ b/util/ack/scan.c @@ -200,11 +200,13 @@ int satisfy(trafo,suffix) register trf *trafo; char *suffix ; { fuerror("Illegal input suffix entry for %s", trafo->t_name) ; } - l_char=index(f_char+1,SUFCHAR); - if ( l_char ? strncmp(f_char,suffix,l_char-f_char)==0 : - strcmp(f_char,suffix)==0 ) { - return 1 ; + l_char=strindex(f_char+1,SUFCHAR); + if ( l_char ) *l_char = 0; + if ( strcmp(f_char,suffix)==0 ) { + if ( l_char ) *l_char = SUFCHAR; + return 1; } + if ( l_char ) *l_char = SUFCHAR; } return 0 ; } From dcfe6512526c40e8017ca0e06d0301bd303a9a93 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 20 Oct 1986 13:48:26 +0000 Subject: [PATCH 0293/1625] Use our own string routines strindex and strrindex. At least we know their name! --- util/ack/ack.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/ack/ack.h b/util/ack/ack.h index 51e605f4..0153e994 100644 --- a/util/ack/ack.h +++ b/util/ack/ack.h @@ -61,8 +61,8 @@ enum f_path { F_OK, F_NOMATCH, F_NOPATH } ; /* Library routines */ -extern char *index(); -extern char *rindex(); +extern char *strindex(); +extern char *strrindex(); extern char *strcpy(); extern char *strcat(); extern int getpid(); From 95a615f3bc0fcbc1bfe833141556c048102ce034 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 20 Oct 1986 13:52:16 +0000 Subject: [PATCH 0294/1625] Use our own string-routines "strindex" and "strrindex". At least we know their name! --- util/ack/main.c | 4 ++-- util/ack/run.c | 2 +- util/ack/trans.c | 14 +++++++------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/util/ack/main.c b/util/ack/main.c index c1e7a4a5..e4432de5 100644 --- a/util/ack/main.c +++ b/util/ack/main.c @@ -251,7 +251,7 @@ vieuwargs(argc,argv) char **argv ; { firstarg(argp) register char *argp ; { register char *name ; - name=rindex(argp,'/') ; + name=strrindex(argp,'/') ; if ( name && *(name+1) ) { name++ ; } else { @@ -270,7 +270,7 @@ process(arg) char *arg ; { #ifdef DEBUG if ( debug ) vprint("Processing %s\n",arg) ; #endif - p_suffix= rindex(arg,SUFCHAR) ; + p_suffix= strrindex(arg,SUFCHAR) ; orig.p_keep= YES ; /* Don't throw away the original ! */ orig.p_keeps= NO; orig.p_path= arg ; diff --git a/util/ack/run.c b/util/ack/run.c index b46769ba..2ea332d5 100644 --- a/util/ack/run.c +++ b/util/ack/run.c @@ -45,7 +45,7 @@ int runphase(phase) register trf *phase ; { vprint("%s",phase->t_name) ; if ( !phase->t_combine ) { vprint(" %s%s\n",p_basename, - rindex(in.p_path,SUFCHAR) ) ; + strrindex(in.p_path,SUFCHAR) ) ; } else { scanlist(l_first(phase->t_inputs), elem) { vprint(" %s",p_cont(*elem)->p_path); diff --git a/util/ack/trans.c b/util/ack/trans.c index 8d016255..d1b4aa0d 100644 --- a/util/ack/trans.c +++ b/util/ack/trans.c @@ -168,9 +168,9 @@ set_Rflag(argp) register char *argp ; { register int length ; char *eq, *colon ; - eos= index(&argp[2],'-'); - eq= index(&argp[2],EQUAL) ; - colon= index(&argp[2],':'); + eos= strindex(&argp[2],'-'); + eq= strindex(&argp[2],EQUAL) ; + colon= strindex(&argp[2],':'); if ( !eos ) { eos= eq ; } else { @@ -479,7 +479,7 @@ int mapexpand(mapentry,cflag) register char *space ; int length ; - star=index(mapentry,STAR) ; + star=strindex(mapentry,STAR) ; space=firstblank(mapentry) ; if ( star >space ) star= (char *)0 ; if ( star ) { @@ -523,7 +523,7 @@ doassign(line,star,length) char *line, *star ; { for ( ; *ptr && *ptr!=SPACE && *ptr!=TAB && *ptr!=EQUAL ; ptr++ ) { gr_add(&name,*ptr) ; } - ptr= index(ptr,EQUAL) ; + ptr= strindex(ptr,EQUAL) ; if ( !ptr ) { error("Missing %c in assignment %s",EQUAL,line); return ; @@ -611,7 +611,7 @@ addargs(string) char *string ; { register char *temp, *repc ; register list_elem *elem ; - repc=index(string,C_IN) ; + repc=strindex(string,C_IN) ; if ( repc ) { /* INPUT FILE TOKEN seen, replace it and scan further */ if ( repc==string && string[1]==0 ) { @@ -637,7 +637,7 @@ addargs(string) char *string ; { } return ; } - repc=index(string,C_OUT) ; + repc=strindex(string,C_OUT) ; if ( repc ) { /* replace the outfile token as with the infile token */ #ifdef DEBUG From d03ecb5b773451466dae0c6c9cb7301971a371a8 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 20 Oct 1986 13:59:14 +0000 Subject: [PATCH 0295/1625] Adapted to the use of ../../modules/lib/libstr.a --- util/ack/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util/ack/Makefile b/util/ack/Makefile index b33790fd..aa927275 100644 --- a/util/ack/Makefile +++ b/util/ack/Makefile @@ -12,6 +12,7 @@ LNTABLES=acc apc abc vax2 vax4 i86 ix m68k2 m68k4 pmds pmds4 z8000\ int22 int24 int44 6500 6800 6805 6809 i80 ns s2650 z80 CFLAGS=-O -n BINDIR=../../bin +MODDIR=../../modules/lib head: ack @@ -31,7 +32,7 @@ clean: (cd pc ; make clean ) ack: $(OBJ) - $(CC) -o ack $(CFLAGS) $(OBJ) + $(CC) -o ack $(CFLAGS) $(OBJ) $(MODDIR)/libstr.a grows.o files.o list.o run.o \ data.o main.o scan.o trans.o rmach.o util.o : ack.h list.h From 2dedd7c2a45530ca2df5637a63cff435f637974a Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 20 Oct 1986 14:09:09 +0000 Subject: [PATCH 0296/1625] Added "Modules" --- Action | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Action b/Action index 7caae0ba..3366eac5 100644 --- a/Action +++ b/Action @@ -13,6 +13,10 @@ end name "EM definition library" dir util/data end +name "Modules" +dir modules +indir +end name "Encode/Decode" dir util/misc end From 472f51257a3ee2391224a817c3dad13eb62d62b9 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 20 Oct 1986 14:42:41 +0000 Subject: [PATCH 0297/1625] *** empty log message *** --- util/cmisc/cclash.c | 465 ++++++++++++++++++++++++++++++++++++++++++++ util/cmisc/cid.c | 388 ++++++++++++++++++++++++++++++++++++ util/cmisc/mkdep.c | 191 ++++++++++++++++++ 3 files changed, 1044 insertions(+) create mode 100644 util/cmisc/cclash.c create mode 100644 util/cmisc/cid.c create mode 100644 util/cmisc/mkdep.c diff --git a/util/cmisc/cclash.c b/util/cmisc/cclash.c new file mode 100644 index 00000000..850f0b64 --- /dev/null +++ b/util/cmisc/cclash.c @@ -0,0 +1,465 @@ +/* + cclash: find clashing names within C programs + + Flags: + -c : produce oldname=newname line for each clashing id + (useful input for cid) + -l : check identifiers of or more characters + (default = 8) + -m : output a #define for each clashing id + + Author: Erik Baalbergen + Date: Nov 8, 1985 + + Revised: Dec 10, 1985 + C keywords are not listed + Revised: Aug 27, 1986 + Skip C numeric constants + Revised: Wed Jul 23 13:27:16 MDT 1986 + by Ceriel Jacobs, + replaced "stoi" by "atoi" + Revised: Wed Oct 1 14:23:35 MDT 1986 + by Ceriel Jacobs, + to produce lists in the order in which they were read. +*/ + +#include + +#define DEF_LENGTH 8 + +struct idf { + struct idf *id_next; + char *id_name; + struct idf *id_same; + char *id_key; +}; + +#define ACT_LISTONLY 0 +#define ACT_MAPFILE 1 +#define ACT_CID 2 + +int maxlen = DEF_LENGTH; +int action = ACT_LISTONLY; + +char *ProgName; + +char * keywords[] = { + "asm", + "auto", + "break", + "case", + "char", + "continue", + "default", + "do", + "double", + "else", + "entry", + "extern", + "float", + "for", + "fortran", + "goto", + "if", + "int", + "long", + "register", + "return", + "short", + "sizeof", + "static", + "struct", + "switch", + "typedef", + "union", + "unsigned", + "while", + 0 +}; + +DefineKeys() +{ + register char **pkey = &keywords[0]; + register char *id; + + while (id = *pkey++) + if (strlen(id) >= maxlen) + InsertId(id, 1); +} + +DoOption(str) + char *str; +{ + switch (str[1]) { + + case 'c': + action = ACT_CID; + break; + + case 'l': + if ((maxlen = atoi(&str[2])) <= 0) { + fprintf(stderr, "%s: option \"-l%s\" ignored\n", + ProgName, &str[2]); + maxlen = DEF_LENGTH; + } + break; + + case 'm': + action = ACT_MAPFILE; + break; + + default: + fprintf(stderr, "%s: bad option \"%s\"\n", ProgName, str); + break; + } +} + +#define HASHSIZE 257 + +struct idf *hash_tab[HASHSIZE]; + +char *Malloc(), *Salloc(); + +InsertId(id, key) + char *id; +{ + int hash_val = EnHash(id); + register struct idf *idp = hash_tab[hash_val]; + register struct idf *p = 0; + + while (idp && strncmp(idp->id_name, id, maxlen)) { + p = idp; + idp = idp->id_next; + } + + if (idp == 0) { + idp = (struct idf *) Malloc(sizeof(struct idf)); + idp->id_next = 0; + if (!p) hash_tab[hash_val] = idp; + else p->id_next = idp; + idp->id_name = Salloc(id); + idp->id_same = 0; + } + + p = idp; + + while (p && strcmp(p->id_name, id)) { + idp = p; + p = p->id_same; + } + + if (p == 0) { + p = (struct idf *) Malloc(sizeof(struct idf)); + p->id_next = 0; + p->id_same = 0; + p->id_name = Salloc(id); + idp->id_same = p; + } + + if (key) + p->id_key = id; +} + +char * +Malloc(n) + unsigned n; +{ + char *mem, *malloc(); + + if ((mem = malloc(n)) == 0) { + fprintf(stderr, "%s: out of memory\n", ProgName); + exit(1); + } + return mem; +} + +char * +Salloc(str) + char *str; +{ + char *strcpy(); + + if (str == 0) + str = ""; + + return strcpy(Malloc(strlen(str) + 1), str); +} + +EnHash(id) + char *id; +{ + register unsigned hash_val = 0; + register n = maxlen; + + while (n-- && *id) + hash_val = 31 * hash_val + *id++; + + return hash_val % (unsigned) HASHSIZE; +} + +Results() +{ + register int i; + register struct idf *idp, *p; + + for (i = 0; i < HASHSIZE; i++) { + for (idp = hash_tab[i]; idp; idp = idp->id_next) { + if (idp->id_same == 0) + continue; + + switch (action) { + register n; + + case ACT_LISTONLY: + n = 0; + if (idp->id_key == 0) { + printf(idp->id_name); + n++; + } + for (p = idp->id_same; p; p = p->id_same) + if (p->id_key == 0) { + printf("%s%s", + n ? " " : "", + p->id_name + ); + n++; + } + if (n) + printf("\n"); + break; + + case ACT_CID: + case ACT_MAPFILE: + if (idp->id_key == 0) + mapline(idp->id_name); + for (p = idp->id_same; p; p = p->id_same) + if (p->id_key == 0) + mapline(p->id_name); + break; + } + } + } +} + +mapline(nm) + char *nm; +{ + static map_count = 0; + + switch (action) { + + case ACT_MAPFILE: + printf("#define %s _%d_%s\n", nm, ++map_count, nm); + break; + + case ACT_CID: + printf("%s=_%d_%s\n", nm, ++map_count, nm); + break; + } +} + +#define MAX_ID_LEN 256 + +main(argc, argv) + char *argv[]; +{ + char **nargv; + int nargc = 0; + FILE *fp; + + ProgName = *argv++; + nargv = argv; + + while (--argc > 0) + if ((*argv)[0] == '-') + DoOption(*argv++); + else + nargv[nargc++] = *argv++; + + DefineKeys(); + if (nargc > 0) + while (nargc-- > 0) { + if ((fp = fopen(*nargv, "r")) == NULL) + fprintf(stderr, "%s: cannot read file \"%s\"\n", + ProgName, *nargv); + else + DoFile(fp); + nargv++; + } + else + DoFile(stdin); + Results(); + return 0; +} + +DoFile(fp) + FILE *fp; +{ + register c; + + while ((c = getc(fp)) != EOF) + switch (c) { + + case '"': + case '\'': + SkipString(fp, c); + break; + + case '/': + if ((c = getc(fp)) == '*') + SkipComment(fp); + else + ungetc(c, fp); + break; + + default: + if (StartId(c)) + DoIdent(fp, c); + else + if (StartNum(c)) + DoNum(fp, c); + break; + } + + fclose(fp); +} + +SkipString(fp, stopc) + FILE *fp; +{ + register c; + + while ((c = getc(fp)) != EOF) { + if (c == stopc) + return; + if (c == '\\') + c = getc(fp); + } +} + +SkipComment(fp) + FILE *fp; +{ + register c; + + while ((c = getc(fp)) != EOF) + if (c == '*') { + if ((c = getc(fp)) == '/') + return; + ungetc(c, fp); + } +} + +DoIdent(fp, s) + FILE *fp; +{ + char id_buf[MAX_ID_LEN]; + register cnt = 1; + register c; + + id_buf[0] = s; + + while ((c = getc(fp)) != EOF) + if (InId(c)) + id_buf[cnt++] = c; + else { + ungetc(c, fp); + id_buf[cnt] = '\0'; + if (cnt >= maxlen) + InsertId(&id_buf[0], 0); + return; + } +} + +#define inrange(c, l, u) ((unsigned)((c) - (l)) <= ((u) - (l))) +#define isdec(c) inrange(c, '0', '9') +#define isoct(c) inrange(c, '0', '7') +#define ishex(c) (isdec(c) || inrange(c, 'a', 'f') || inrange(c, 'A', 'F')) +#define getdec(c, fp) do c = getc((fp)); while (isdec(c)) +#define getoct(c, fp) do c = getc((fp)); while (isoct(c)) +#define gethex(c, fp) do c = getc((fp)); while (ishex(c)) + +DoNum(fp, c) + FILE *fp; +{ + if (c != '0') { + getdec(c, fp); + if (c == '.') + getdec(c, fp); + if (c == 'e') { + c = getc(fp); + if (c == '+' || c == '-') + c = getc(fp); + if (isdec(c)) + getdec(c, fp); + } + } + else { + c = getc(fp); + if (c == 'x' || c == 'X') + gethex(c, fp); + else + if (isoct(c)) + getoct(c, fp); + } +} + +StartId(c) +{ + switch (c) { + + case 'a': case 'b': case 'c': case 'd': case 'e': + case 'f': case 'g': case 'h': case 'i': case 'j': + case 'k': case 'l': case 'm': case 'n': case 'o': + case 'p': case 'q': case 'r': case 's': case 't': + case 'u': case 'v': case 'w': case 'x': case 'y': + case 'z': + case 'A': case 'B': case 'C': case 'D': case 'E': + case 'F': case 'G': case 'H': case 'I': case 'J': + case 'K': case 'L': case 'M': case 'N': case 'O': + case 'P': case 'Q': case 'R': case 'S': case 'T': + case 'U': case 'V': case 'W': case 'X': case 'Y': + case 'Z': + case '_': + return 1; + + default: + return 0; + } +} + +StartNum(c) +{ + switch(c) { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + return 1; + } + return 0; +} + +InId(c) +{ + switch (c) { + + case 'a': case 'b': case 'c': case 'd': case 'e': + case 'f': case 'g': case 'h': case 'i': case 'j': + case 'k': case 'l': case 'm': case 'n': case 'o': + case 'p': case 'q': case 'r': case 's': case 't': + case 'u': case 'v': case 'w': case 'x': case 'y': + case 'z': + case 'A': case 'B': case 'C': case 'D': case 'E': + case 'F': case 'G': case 'H': case 'I': case 'J': + case 'K': case 'L': case 'M': case 'N': case 'O': + case 'P': case 'Q': case 'R': case 'S': case 'T': + case 'U': case 'V': case 'W': case 'X': case 'Y': + case 'Z': + case '_': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + return 1; + + default: + return 0; + } +} diff --git a/util/cmisc/cid.c b/util/cmisc/cid.c new file mode 100644 index 00000000..f8da1acf --- /dev/null +++ b/util/cmisc/cid.c @@ -0,0 +1,388 @@ +/* @cc % $LIBDIR/stoi.o -o cid@ */ + +/* Change IDentifiers occurring in C programs outside comment, strings + and character constants. + -Dname=text : replace all occerences of name by text + -Dname : same as -Dname= + -Ffile : read sentences of the from name=text from file + + Author: Erik Baalbergen + Date: Oct 23, 1985 +*/ + + +/*** Generic C Identifier Processing Module ***/ +/* IMPORT CheckId(char *) and DoOption(char *, int) +*/ + +#include + +extern CheckId(); +extern DoOption(); + +#define MAX_ID_LEN 256 + +char *ProgName; + +main(argc, argv) + char *argv[]; +{ + char **nargv; + int nargc = 0; + FILE *fp; + + ProgName = *argv++; + nargv = argv; + + while (--argc > 0) { + if ((*argv)[0] == '-') { + DoOption(*argv++); + } + else { + nargv[nargc++] = *argv++; + } + } + + if (nargc > 0) { + while (nargc-- > 0) { + if ((fp = fopen(*nargv, "r")) == NULL) { + fprintf(stderr, "%s: cannot read file \"%s\"\n", + ProgName, *nargv); + } + else { + DoFile(fp); + } + nargv++; + } + } + else { + DoFile(stdin); + } + return 0; +} + +DoFile(fp) + FILE *fp; +{ + register c; + + while ((c = getc(fp)) != EOF) { + switch (c) { + + case '"': + case '\'': + SkipString(fp, c); + break; + + case '/': + if ((c = getc(fp)) == '*') { + SkipComment(fp); + } + else { + putchar('/'); + ungetc(c, fp); + } + break; + + default: + if (StartId(c)) { + DoIdent(fp, c); + } + else + putchar(c); + break; + } + } + fclose(fp); +} + +SkipString(fp, stopc) + FILE *fp; +{ + register c; + + putchar(stopc); + while ((c = getc(fp)) != EOF) { + if (c == stopc) { + putchar(stopc); + return; + } + + if (c == '\\') { + putchar(c); + c = getc(fp); + } + putchar(c); + } +} + +SkipComment(fp) + FILE *fp; +{ + register c; + + putchar('/'); + putchar('*'); + while ((c = getc(fp)) != EOF) { + if (c == '*') { + putchar('*'); + if ((c = getc(fp)) == '/') { + putchar('/'); + return; + } + ungetc(c, fp); + } + else + putchar(c); + } +} + +DoIdent(fp, s) + FILE *fp; +{ + char id_buf[MAX_ID_LEN]; + register cnt = 1; + register c; + + id_buf[0] = s; + + while ((c = getc(fp)) != EOF) { + if (InId(c)) { + id_buf[cnt++] = c; + } + else { + ungetc(c, fp); + id_buf[cnt] = '\0'; + CheckId(id_buf, cnt); + return; + } + } +} + +StartId(c) +{ + switch (c) { + + case 'a': case 'b': case 'c': case 'd': case 'e': + case 'f': case 'g': case 'h': case 'i': case 'j': + case 'k': case 'l': case 'm': case 'n': case 'o': + case 'p': case 'q': case 'r': case 's': case 't': + case 'u': case 'v': case 'w': case 'x': case 'y': + case 'z': + case 'A': case 'B': case 'C': case 'D': case 'E': + case 'F': case 'G': case 'H': case 'I': case 'J': + case 'K': case 'L': case 'M': case 'N': case 'O': + case 'P': case 'Q': case 'R': case 'S': case 'T': + case 'U': case 'V': case 'W': case 'X': case 'Y': + case 'Z': + case '_': + return 1; + + default: + return 0; + } +} + +InId(c) +{ + switch (c) { + + case 'a': case 'b': case 'c': case 'd': case 'e': + case 'f': case 'g': case 'h': case 'i': case 'j': + case 'k': case 'l': case 'm': case 'n': case 'o': + case 'p': case 'q': case 'r': case 's': case 't': + case 'u': case 'v': case 'w': case 'x': case 'y': + case 'z': + case 'A': case 'B': case 'C': case 'D': case 'E': + case 'F': case 'G': case 'H': case 'I': case 'J': + case 'K': case 'L': case 'M': case 'N': case 'O': + case 'P': case 'Q': case 'R': case 'S': case 'T': + case 'U': case 'V': case 'W': case 'X': case 'Y': + case 'Z': + case '_': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + return 1; + + default: + return 0; + } +} +/*** end of GCIPM ***/ + +#ifndef DEF_LENGTH +#define DEF_LENGTH 8 +#endif + +#define LINE_LEN 1024 + +#define HASHSIZE 257 + +struct idf { + struct idf *id_next; + char *id_name; + char *id_text; +}; + +struct idf *hash_tab[HASHSIZE]; + +char *Malloc(), *Salloc(); +struct idf *FindId(); + +DoOption(str) + char *str; +{ + switch (str[1]) { + + case 'D': + DoMacro(&str[2]); + break; + + case 'F': + GetMacros(&str[2]); + break; + + default: + fprintf(stderr, "%s: bad option \"%s\"\n", ProgName, str); + break; + } +} + +CheckId(id, len) + char *id; +{ + struct idf *idp = FindId(id); + + if (idp) { + printf("%s", idp->id_text); + } + else { + printf("%s", id); + } +} + +DoMacro(str) + char *str; +{ + char *id, *text; + + id = str++; + + while (*str != '\0' && *str != '=') { + str++; + } + + if (*str == '=') { + *str++ = '\0'; + text = str; + } + else { + text = ""; + } + + InsertMacro(id, text); +} + +GetMacros(fn) + char *fn; +{ + FILE *fp; + register c; + char buf[LINE_LEN]; + char *bufp = &buf[0]; + + if ((fp = fopen(fn, "r")) == NULL) { + fprintf(stderr, "%s: cannot read file \"%s\"\n", ProgName, fn); + return 0; + } + + while ((c = getc(fp)) != EOF) { + if (c == '\n' && bufp != &buf[0]) { + *bufp = '\0'; + DoMacro(&buf[0]); + bufp = &buf[0]; + } + else { + *bufp++ = c; + } + } + fclose(fp); +} + +InsertMacro(id, text) + char *id, *text; +{ + int hash_val = EnHash(id); + struct idf *idp = hash_tab[hash_val]; + + while (idp) { + if (strcmp(idp->id_name, id) == 0) { + fprintf(stderr, "%s: (warning) redefinition of %s\n", + ProgName, id); + break; + } + idp = idp->id_next; + } + + if (idp == 0) { + idp = (struct idf *) Malloc(sizeof(struct idf)); + } + + idp->id_next = hash_tab[hash_val]; + idp->id_name = Salloc(id); + idp->id_text = Salloc(text); + hash_tab[hash_val] = idp; +} + +char * +Malloc(n) + unsigned n; +{ + char *mem, *malloc(); + + if ((mem = malloc(n)) == 0) { + fprintf(stderr, "%s: out of memory\n", ProgName); + exit(1); + } + return mem; +} + +char * +Salloc(str) + char *str; +{ + char *strcpy(); + + if (str == 0) { + str = ""; + } + return strcpy(Malloc(strlen(str) + 1), str); +} + +struct idf * +FindId(id) + char *id; +{ + register hash_val = EnHash(id); + register struct idf *idp = hash_tab[hash_val]; + + while (idp) { + if (strcmp(idp->id_name, id) == 0) { + return idp; + } + idp = idp->id_next; + } + return 0; +} + +EnHash(id) + char *id; +{ + register unsigned hash_val = 0; + + while (*id) { + hash_val = 31 * hash_val + *id++; + } + + return hash_val % (unsigned) HASHSIZE; +} diff --git a/util/cmisc/mkdep.c b/util/cmisc/mkdep.c new file mode 100644 index 00000000..a9e0700b --- /dev/null +++ b/util/cmisc/mkdep.c @@ -0,0 +1,191 @@ +/* make dependencies; Date: jan 07, 1986; Author: Erik Baalbergen */ + +#include + +#define BSIZ 1024 +char *progname; + +struct namelist { + struct namelist *next; + char *name; +}; + +struct namelist *freelist; +struct namelist *new_namelist(); +struct namelist *nl = 0; + +int lflag = 0; /* produce vertical list of included files */ + +char *Malloc(u) + unsigned u; +{ + char *sp, *malloc(); + + if ((sp = malloc(u)) == 0) { + fprintf(stderr, "%s: out of space\n"); + exit(1); + } + return sp; +} + +struct namelist * +new_namelist() +{ + register struct namelist *nlp = freelist; + + if (nlp) { + freelist = nlp->next; + return nlp; + } + + return (struct namelist *) Malloc(sizeof(struct namelist)); +} + +free_namelist(nlp) + struct namelist *nlp; +{ + if (nlp) { + free_namelist(nlp->next); + nlp->next = freelist; + freelist = nlp; + } +} + +add_name(nm) + char *nm; +{ + struct namelist *nlp = nl; + struct namelist *lnlp = 0; + struct namelist *nnlp; + char *strcpy(); + + while (nlp) { + register i = strcmp(nm, nlp->name); + if (i < 0) + break; + if (i == 0) /* already present */ + return; + lnlp = nlp; + nlp = nlp->next; + } + + (nnlp = new_namelist())->name = strcpy(Malloc(strlen(nm) + 1), nm); + + if (lnlp) { + nnlp->next = lnlp->next; + lnlp->next = nnlp; + } + else { + nnlp->next = nl; + nl = nnlp; + } +} + +print_namelist(nm, nlp) + char *nm; + struct namelist *nlp; +{ + if (nlp) { + if (lflag) { + while (nlp) { + printf("%s\n", nlp->name); + nlp = nlp->next; + } + } + else { + printf("%s:", nm); + while (nlp) { + printf(" %s", nlp->name); + nlp = nlp->next; + } + printf("\n"); + } + } +} + +main(argc, argv) + char *argv[]; +{ + int err = 0; + + progname = *argv++; + if (**argv == '-') { + register char *s = *argv++; + + argc--; + while (*++s) { + switch (*s) { + case 'l': + lflag = 1; + break; + default: + fprintf(stderr, "use: %s [-l] file ...\n", + progname); + return 0; + } + } + } + while (--argc > 0) { + free_namelist(nl); + nl = 0; + if (dofile(*argv) == 0) + ++err; + print_namelist(*argv++, nl); + } + return err ? 1 : 0; +} + +dofile(fn) + char *fn; +{ + char *fgets(), buf[BSIZ]; + FILE *fp; + char *nm, *include_line(); + + if ((fp = fopen(fn, "r")) == 0) { + fprintf(stderr, "%s: cannot read %s\n", progname, fn); + return 0; + } + + while (fgets(buf, BSIZ, fp) != NULL) + if (nm = include_line(buf)) { + add_name(nm); + dofile(nm); + } + + fclose(fp); + return 1; +} + +char * +include_line(s) + char *s; +{ + while ((*s == '\t') || (*s == ' ')) + s++; + + if (*s++ == '#') { + while ((*s == '\t') || (*s == ' ')) + s++; + if ( + (*s++ == 'i') && + (*s++ == 'n') && + (*s++ == 'c') && + (*s++ == 'l') && + (*s++ == 'u') && + (*s++ == 'd') && + (*s++ == 'e') + ) { + while ((*s == '\t') || (*s == ' ')) + s++; + if (*s++ == '"') { + register char *nm = s; + while (*s != 0 && *s != '"') + s++; + *s = '\0'; + return nm; + } + } + } + return (char *) 0; +} From 1a553fda1ba5b55dffb1dff35dbb6f64b5ab8665 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 20 Oct 1986 14:56:37 +0000 Subject: [PATCH 0298/1625] Initial revision --- util/cmisc/Makefile | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 util/cmisc/Makefile diff --git a/util/cmisc/Makefile b/util/cmisc/Makefile new file mode 100644 index 00000000..ce363108 --- /dev/null +++ b/util/cmisc/Makefile @@ -0,0 +1,21 @@ +EMBIN = ../../bin +CFLAGS = -O +LDFLAGS = +TARGETS = mkdep cid cclash + +all: $(TARGETS) + +install: all + cp $(TARGETS) $(EMBIN) + +clean: + rm -f *.o + +mkdep: mkdep.o + $(CC) $(LDFLAGS) -o mkdep mkdep.o + +cid: cid.o + $(CC) $(LDFLAGS) -o cid cid.o + +cclash: cclash.o + $(CC) $(LDFLAGS) -o cclash cclash.o From c598ed56ae4923d458e7b622e02dfc62f816a82c Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 20 Oct 1986 14:58:25 +0000 Subject: [PATCH 0299/1625] Improved the "clean"-entry --- util/cmisc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/cmisc/Makefile b/util/cmisc/Makefile index ce363108..5d401bee 100644 --- a/util/cmisc/Makefile +++ b/util/cmisc/Makefile @@ -9,7 +9,7 @@ install: all cp $(TARGETS) $(EMBIN) clean: - rm -f *.o + rm -f *.o $(TARGETS) mkdep: mkdep.o $(CC) $(LDFLAGS) -o mkdep mkdep.o From ad706c95d584564f4e3de7e75cb3e9b0600e5101 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 20 Oct 1986 15:00:14 +0000 Subject: [PATCH 0300/1625] Added an entry for the util/cmisc directory. --- Action | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Action b/Action index 3366eac5..9cbfe00c 100644 --- a/Action +++ b/Action @@ -17,6 +17,9 @@ name "Modules" dir modules indir end +name "C utilities" +dir util/cmisc +end name "Encode/Decode" dir util/misc end From c601bbacd51c133dd623f6e31add601d97865f20 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 20 Oct 1986 17:40:41 +0000 Subject: [PATCH 0301/1625] newer version --- lang/m2/comp/MakeVersion | 8 ++++++++ lang/m2/comp/Makefile | 17 ++++------------- lang/m2/comp/Resolve | 17 ++++++++--------- lang/m2/comp/Version.c | 2 +- 4 files changed, 21 insertions(+), 23 deletions(-) create mode 100755 lang/m2/comp/MakeVersion diff --git a/lang/m2/comp/MakeVersion b/lang/m2/comp/MakeVersion new file mode 100755 index 00000000..6b9d7f5e --- /dev/null +++ b/lang/m2/comp/MakeVersion @@ -0,0 +1,8 @@ +V=`cat Version.c` +VERSION=`expr "$V" ':' '.*[0-9][0-9]*\.\([0-9][0-9]*\).*'` +NEWVERSION=`expr $VERSION + 1` +sed "s/\.$VERSION/.$NEWVERSION/" < Version.c > tmp$$ +mv tmp$$ Version.c +CM "$*" +V=`cat Version.c` +SV > ../versions/V`expr "$V" ':' '.*\([0-9][0-9]*\.[0-9][0-9]*\).*'` diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index 772b3ac7..da51723a 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -50,24 +50,15 @@ all: Cfiles @rm -f nmclash.o a.out clean: - rm -f $(OBJ) $(GENFILES) LLfiles hfiles Cfiles tab cclash.o cid.o cclash cid clashes + rm -f $(OBJ) $(GENFILES) LLfiles hfiles Cfiles tab clashes (cd .. ; rm -rf Xsrc) lint: Cfiles sh -c 'if $(CC) nmclash.c > /dev/null 2>&1 ; then make Xlint ; else sh Resolve Xlint ; fi' @rm -f nmclash.o a.out -mkdep: mkdep.o - $(CC) $(LFLAGS) -o mkdep mkdep.o - -cclash: cclash.o - $(CC) $(LFLAGS) -o cclash cclash.o - clashes: $(SRC) $(HFILES) - sh -c 'if test -f clashes ; then ./cclash -l7 clashes $? > Xclashes ; mv Xclashes clashes ; else ./cclash -l7 $? > clashes ; fi' - -cid: cid.o - $(CC) $(LFLAGS) -o cid cid.o + sh -c 'if test -f clashes ; then cclash -l7 clashes $? > Xclashes ; mv Xclashes clashes ; else cclash -l7 $? > clashes ; fi' # entry points not to be used directly @@ -119,10 +110,10 @@ char.c: ../src/char.tab ../src/tab ../src/tab: $(CC) ../src/tab.c -o ../src/tab -depend: mkdep +depend: sed '/^#AUTOAUTO/,$$d' Makefile > Makefile.new echo '#AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO' >> Makefile.new - ./mkdep $(SRC) |\ + mkdep $(SRC) |\ sed 's/\.c:/\.o:/' >> Makefile.new mv Makefile Makefile.old mv Makefile.new Makefile diff --git a/lang/m2/comp/Resolve b/lang/m2/comp/Resolve index 7c96827f..def1f2a6 100755 --- a/lang/m2/comp/Resolve +++ b/lang/m2/comp/Resolve @@ -6,9 +6,7 @@ case $# in ;; esac case $1 in -main) - ;; -Xlint) +main|Xlint) ;; *) echo "$0: $1: Illegal argument" 1>&2 exit 1 @@ -19,10 +17,11 @@ then : else mkdir ../Xsrc fi -make cclash clashes cid +make clashes sed '/^C_/d' < clashes > tmp$$ ./cclash -c -l7 tmp$$ > ../Xsrc/Xclashes rm -f tmp$$ +PW=`pwd` cd ../Xsrc if cmp -s Xclashes clashes then @@ -31,13 +30,13 @@ else mv Xclashes clashes fi rm -f Makefile -for i in `cat ../src/Cfiles` +for i in `cat $PW/Cfiles` do cat >> Makefile < $i +$i: clashes $PW/$i + cid -Fclashes < $PW/$i > $i EOF done -make `cat ../src/Cfiles` -make -f ../src/Makefile $1 +make `cat $PW/Cfiles` +make -f $PW/Makefile $1 diff --git a/lang/m2/comp/Version.c b/lang/m2/comp/Version.c index ac7bbbfa..0be24d41 100644 --- a/lang/m2/comp/Version.c +++ b/lang/m2/comp/Version.c @@ -1 +1 @@ -char Version[] = "Version 0.5"; +char Version[] = "Version 0.6"; From 1bf54a839e7c8d5a7fe3c54a1c2f088508bf82a5 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 21 Oct 1986 14:45:43 +0000 Subject: [PATCH 0302/1625] minor fix to LLlex.c --- lang/m2/comp/LLlex.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index 2f488734..2884c029 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -383,6 +383,7 @@ lexwarning("Character constant out of range"); } } + *np++ = '\0'; PushBack(ch); if (np >= &buf[NUMSIZE]) { From 06ea1f505eeeadfb50a76dee128fbf8fc726aa6d Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 22 Oct 1986 13:36:04 +0000 Subject: [PATCH 0303/1625] minor simplification. --- util/LLgen/src/Makefile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/util/LLgen/src/Makefile b/util/LLgen/src/Makefile index 39e9fe82..b1187016 100644 --- a/util/LLgen/src/Makefile +++ b/util/LLgen/src/Makefile @@ -1,7 +1,7 @@ # $Header$ PROF= LLOPT= # -vvv -x -CFLAGS=$(PROF) -O -DNDEBUG +CFLAGS=-O -DNDEBUG $(PROF) LDFLAGS=-i OBJECTS = main.o gencode.o compute.o LLgen.o tokens.o check.o reach.o global.o name.o sets.o Lpars.o alloc.o machdep.o cclass.o CFILES = main.c gencode.c compute.c LLgen.c tokens.c check.c reach.c global.c name.c sets.c Lpars.c alloc.c machdep.c cclass.c @@ -9,9 +9,8 @@ FILES =types.h tunable.h extern.h io.h sets.h assert.h tokens.g LLgen.g main.c n GFILES = tokens.g LLgen.g LINT = lint -b -DNDEBUG -DNORCSID -all: - @make parser "LLOPT=$(LLOPT)" - @make LLgen "LDFLAGS=$(LDFLAGS)" "CC=$(CC)" "PROF=$(PROF)" "CFLAGS=$(CFLAGS)" +all: parser + @make LLgen "LDFLAGS=$(LDFLAGS)" "CC=$(CC)" "CFLAGS=$(CFLAGS)" "PROF=$(PROF)" parser: $(GFILES) -LLgen $(LLOPT) $(GFILES) From 55dd98fd3c044bc775d39ff76991604add5100db Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 22 Oct 1986 13:36:22 +0000 Subject: [PATCH 0304/1625] Bug fix involving '\\'. --- util/LLgen/src/tokens.g | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/util/LLgen/src/tokens.g b/util/LLgen/src/tokens.g index be7d17e5..321a9de8 100644 --- a/util/LLgen/src/tokens.g +++ b/util/LLgen/src/tokens.g @@ -115,7 +115,6 @@ scanner() { register int ch; /* Current char */ register char *p = ltext; int reserved = 0; /* reserved word? */ - int last; /* Char before current char */ char *max = <ext[LTEXTSZ - 1]; if (ch = savedtok.t_tokno) { @@ -138,13 +137,16 @@ scanner() { switch(c_class[ch]) { case ISLIT : for (;;) { - last = ch; ch = input(); if (ch == '\n' || ch == EOF) { error(linecount,"missing '"); break; } - if (ch == '\'' && last != '\\') break; + if (ch == '\'') break; + if (ch == '\\') { + *p++ = ch; + ch = input(); + } *p++ = ch; if (p > max) p--; } From 935a12a56e7f5b227bad53eed0cf9740a9298eb1 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 22 Oct 1986 15:30:46 +0000 Subject: [PATCH 0305/1625] Error messages are printed differently now. A '%' in an error message used to cause difficulties. --- util/LLgen/src/tokens.g | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/util/LLgen/src/tokens.g b/util/LLgen/src/tokens.g index 321a9de8..1248a5d3 100644 --- a/util/LLgen/src/tokens.g +++ b/util/LLgen/src/tokens.g @@ -413,7 +413,11 @@ LLmessage(d) { s = cpy(LLsymb,s,0); *s = '\0'; } - error(linecount,buf); + error(linecount, "%s", buf); + /* Don't change this line to + * error(linecount, buf). + * The string in "buf" might contain '%' ... + */ if (d) { /* * Save the current token and make up some * attributes for the inserted token From e52cd587fb205800149b754878dec8c8a0479d76 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 22 Oct 1986 15:38:24 +0000 Subject: [PATCH 0306/1625] newer version with some bug fixes --- lang/m2/comp/LLlex.c | 34 +++++++++++++------- lang/m2/comp/Makefile | 67 +++++++++++++++++++++------------------ lang/m2/comp/Resolve | 19 ++++++++--- lang/m2/comp/chk_expr.c | 18 +++++++++-- lang/m2/comp/code.c | 2 +- lang/m2/comp/declar.g | 5 +-- lang/m2/comp/enter.c | 6 ++-- lang/m2/comp/expression.g | 2 +- lang/m2/comp/lookup.c | 1 + lang/m2/comp/misc.H | 3 +- lang/m2/comp/misc.c | 8 +++-- 11 files changed, 106 insertions(+), 59 deletions(-) diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index 2884c029..6489389c 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -113,6 +113,7 @@ LLlex() register struct token *tk = ˙ char buf[(IDFSIZE > NUMSIZE ? IDFSIZE : NUMSIZE) + 2]; register int ch, nch; + static int eofseen; toktype = error_type; @@ -124,10 +125,16 @@ LLlex() tk->tk_lineno = LineNumber; + if (eofseen) { + eofseen = 0; + ch = EOI; + } + else { again: - LoadChar(ch); - if ((ch & 0200) && ch != EOI) { - fatal("non-ascii '\\%03o' read", ch & 0377); + LoadChar(ch); + if ((ch & 0200) && ch != EOI) { + fatal("non-ascii '\\%03o' read", ch & 0377); + } } switch (class(ch)) { @@ -159,9 +166,8 @@ again: SkipComment(); goto again; } - else { - PushBack(nch); - } + else if (nch == EOI) eofseen = 1; + else PushBack(nch); } return tk->tk_symb = ch; @@ -200,7 +206,8 @@ again: default : crash("(LLlex, STCOMP)"); } - PushBack(nch); + if (nch == EOI) eofseen = 1; + else PushBack(nch); return tk->tk_symb = ch; case STIDF: @@ -213,7 +220,8 @@ again: LoadChar(ch); } while(in_idf(ch)); - if (ch != EOI) PushBack(ch); + if (ch == EOI) eofseen = 1; + else PushBack(ch); *tag++ = '\0'; tk->TOK_IDF = id = str2idf(buf, 1); @@ -279,6 +287,7 @@ again: else { state = End; if (ch == 'H') base = 16; + else if (ch == EOI) eofseen = 1; else PushBack(ch); } break; @@ -292,7 +301,8 @@ again: state = End; if (ch != 'H') { lexerror("H expected after hex number"); - PushBack(ch); + if (ch == EOI) eofseen = 1; + else PushBack(ch); } break; @@ -308,7 +318,8 @@ again: state = Hex; break; } - PushBack(ch); + if (ch == EOI) eofseen = 1; + else PushBack(ch); ch = *--np; *np++ = '\0'; base = 8; @@ -384,7 +395,8 @@ lexwarning("Character constant out of range"); } *np++ = '\0'; - PushBack(ch); + if (ch == EOI) eofseen = 1; + else PushBack(ch); if (np >= &buf[NUMSIZE]) { tk->TOK_REL = Salloc("0.0", 5); diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index da51723a..3e4ad43f 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -1,5 +1,5 @@ # make modula-2 "compiler" -EMDIR = /usr/ceriel/em +EMDIR = ../../.. MHDIR = $(EMDIR)/modules/h PKGDIR = $(EMDIR)/modules/pkg LIBDIR = $(EMDIR)/modules/lib @@ -45,12 +45,17 @@ HFILES= LLlex.h\ # GENFILES = $(GENGFILES) $(GENCFILES) $(GENHFILES) +#EXCLEXCLEXCLEXCL + all: Cfiles - sh -c 'if $(CC) nmclash.c > /dev/null 2>&1 ; then make main ; else sh Resolve main ; fi' + sh -c 'if $(CC) nmclash.c > /dev/null 2>&1 ; then make ../comp/main ; else sh Resolve ../comp/main ; fi' @rm -f nmclash.o a.out +install: all + cp main $(EMDIR)/lib/em_m2 + clean: - rm -f $(OBJ) $(GENFILES) LLfiles hfiles Cfiles tab clashes + rm -f $(OBJ) $(GENFILES) LLfiles hfiles Cfiles tab clashes main (cd .. ; rm -rf Xsrc) lint: Cfiles @@ -62,9 +67,6 @@ clashes: $(SRC) $(HFILES) # entry points not to be used directly -Xlint: - lint $(INCLUDES) $(LINTFLAGS) $(SRC) - Cfiles: hfiles LLfiles $(GENCFILES) $(GENHFILES) echo $(SRC) $(HFILES) > Cfiles @@ -76,39 +78,35 @@ hfiles: Parameters make.hfiles make.hfiles Parameters touch hfiles -main: $(OBJ) ../src/Makefile - $(CC) $(LFLAGS) $(OBJ) $(LIBDIR)/libem_mes.a $(LIBDIR)/libemk.a $(LIBDIR)/input.a $(LIBDIR)/assert.a $(LIBDIR)/alloc.a $(LIBDIR)/dickmalloc.o $(LIBDIR)/libprint.a $(LIBDIR)/libstr.a $(LIBDIR)/libsystem.a -o ../src/main - size ../src/main - tokenfile.g: tokenname.c make.tokfile make.tokfile tokenfile.g -symbol2str.c: ../src/tokenname.c ../src/make.tokcase - ../src/make.tokcase <../src/tokenname.c >symbol2str.c +symbol2str.c: tokenname.c make.tokcase + make.tokcase symbol2str.c -def.h: ../src/def.H ../src/make.allocd - ../src/make.allocd < ../src/def.H > def.h +def.h: def.H make.allocd + make.allocd < def.H > def.h -type.h: ../src/type.H ../src/make.allocd - ../src/make.allocd < ../src/type.H > type.h +type.h: type.H make.allocd + make.allocd < type.H > type.h -node.h: ../src/node.H ../src/make.allocd - ../src/make.allocd < ../src/node.H > node.h +node.h: node.H make.allocd + make.allocd < node.H > node.h -scope.c: ../src/scope.C ../src/make.allocd - ../src/make.allocd < ../src/scope.C > scope.c +scope.c: scope.C make.allocd + make.allocd < scope.C > scope.c -tmpvar.c: ../src/tmpvar.C ../src/make.allocd - ../src/make.allocd < ../src/tmpvar.C > tmpvar.c +tmpvar.c: tmpvar.C make.allocd + make.allocd < tmpvar.C > tmpvar.c -casestat.c: ../src/casestat.C ../src/make.allocd - ../src/make.allocd < ../src/casestat.C > casestat.c +casestat.c: casestat.C make.allocd + make.allocd < casestat.C > casestat.c -char.c: ../src/char.tab ../src/tab - ../src/tab -fchar.tab >char.c +char.c: char.tab tab + tab -fchar.tab >char.c -../src/tab: - $(CC) ../src/tab.c -o ../src/tab +tab: + $(CC) tab.c -o tab depend: sed '/^#AUTOAUTO/,$$d' Makefile > Makefile.new @@ -118,6 +116,15 @@ depend: mv Makefile Makefile.old mv Makefile.new Makefile +#INCLINCLINCLINCL + +Xlint: + lint $(INCLUDES) $(LINTFLAGS) $(SRC) + +../comp/main: $(OBJ) ../comp/Makefile + $(CC) $(LFLAGS) $(OBJ) $(LIBDIR)/libem_mes.a $(LIBDIR)/libemk.a $(LIBDIR)/input.a $(LIBDIR)/assert.a $(LIBDIR)/alloc.a $(LIBDIR)/malloc.o $(LIBDIR)/libprint.a $(LIBDIR)/libstr.a $(LIBDIR)/libsystem.a -o ../comp/main + size ../comp/main + #AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO LLlex.o: LLlex.h Lpars.h class.h const.h debug.h f_info.h idf.h idfsize.h input.h inputtype.h numsize.h strsize.h type.h LLmessage.o: LLlex.h Lpars.h idf.h @@ -137,14 +144,14 @@ defmodule.o: LLlex.h Lpars.h debug.h def.h f_info.h idf.h input.h inputtype.h ma typequiv.o: LLlex.h debug.h def.h node.h type.h node.o: LLlex.h debug.h def.h node.h type.h cstoper.o: LLlex.h Lpars.h debug.h idf.h node.h standards.h target_sizes.h type.h -chk_expr.o: LLlex.h Lpars.h chk_expr.h const.h debug.h def.h idf.h node.h scope.h standards.h type.h +chk_expr.o: LLlex.h Lpars.h chk_expr.h const.h debug.h def.h idf.h misc.h node.h scope.h standards.h type.h options.o: idfsize.h main.h ndir.h type.h walk.o: LLlex.h Lpars.h chk_expr.h debug.h def.h desig.h f_info.h idf.h main.h node.h scope.h type.h walk.h casestat.o: LLlex.h Lpars.h debug.h density.h desig.h node.h type.h walk.h desig.o: LLlex.h debug.h def.h desig.h node.h scope.h type.h code.o: LLlex.h Lpars.h debug.h def.h desig.h node.h scope.h standards.h type.h walk.h tmpvar.o: debug.h def.h main.h scope.h type.h -lookup.o: LLlex.h debug.h def.h idf.h node.h scope.h type.h +lookup.o: LLlex.h debug.h def.h idf.h misc.h node.h scope.h type.h tokenfile.o: Lpars.h program.o: LLlex.h Lpars.h debug.h def.h f_info.h idf.h main.h node.h scope.h type.h declar.o: LLlex.h Lpars.h chk_expr.h debug.h def.h idf.h main.h misc.h node.h scope.h type.h diff --git a/lang/m2/comp/Resolve b/lang/m2/comp/Resolve index def1f2a6..b8712499 100755 --- a/lang/m2/comp/Resolve +++ b/lang/m2/comp/Resolve @@ -1,3 +1,6 @@ +: create a directory Xsrc with name clashes resolved +: and run make in that directory + case $# in 1) ;; @@ -6,7 +9,7 @@ case $# in ;; esac case $1 in -main|Xlint) +../comp/main|Xlint) ;; *) echo "$0: $1: Illegal argument" 1>&2 exit 1 @@ -18,8 +21,10 @@ then else mkdir ../Xsrc fi make clashes +: remove code generating routines from the clashes list as they are defines. +: code generating routine names start with C_ sed '/^C_/d' < clashes > tmp$$ -./cclash -c -l7 tmp$$ > ../Xsrc/Xclashes +cclash -c -l7 tmp$$ > ../Xsrc/Xclashes rm -f tmp$$ PW=`pwd` cd ../Xsrc @@ -30,13 +35,17 @@ else mv Xclashes clashes fi rm -f Makefile +ed - $PW/Makefile <<'EOF' +/^#EXCLEXCL/,/^#INCLINCL/d +w Makefile +q +EOF for i in `cat $PW/Cfiles` do cat >> Makefile < $i - EOF done -make `cat $PW/Cfiles` -make -f $PW/Makefile $1 +make $1 diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index 0b963838..40a2064a 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -20,6 +20,7 @@ #include "const.h" #include "standards.h" #include "chk_expr.h" +#include "misc.h" extern char *symbol2str(); @@ -875,17 +876,30 @@ ChkStandard(expp, left) break; case S_HIGH: - if (!(left = getarg(&arg, T_ARRAY, 0))) return 0; + if (!(left = getarg(&arg, T_ARRAY|T_STRING|T_CHAR, 0))) return 0; if (IsConformantArray(left->nd_type)) { /* A conformant array has no explicit index type ??? So, what can we use as index-type ??? */ expp->nd_type = intorcard_type; + break; } - else { + if (left->nd_type->tp_fund == T_ARRAY) { expp->nd_type = IndexType(left->nd_type); cstcall(expp, S_MAX); + break; } + if (left->nd_type->tp_fund == T_CHAR) { + if (left->nd_symb != STRING) { + node_error(left,"HIGH: array parameter expected"); + return 0; + } + } + expp->nd_type = intorcard_type; + expp->nd_class = Value; + expp->nd_INT = left->nd_type->tp_fund == T_CHAR ? 0 : + left->nd_SLE - 1; + expp->nd_symb = INTEGER; break; case S_MAX: diff --git a/lang/m2/comp/code.c b/lang/m2/comp/code.c index 9a58a7a1..d5d419ee 100644 --- a/lang/m2/comp/code.c +++ b/lang/m2/comp/code.c @@ -380,7 +380,7 @@ CodeParameters(param, arg) } } else if (left->nd_symb == STRING) { - C_loc(left->nd_SLE); + C_loc(left->nd_SLE - 1); } else if (tp->arr_elem == word_type) { C_loc((left_type->tp_size+word_size-1) / word_size - 1); diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 9087a00f..7bca82d6 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -219,7 +219,7 @@ ArrayType(struct type **ptp;) RecordType(struct type **ptp;) { register struct scope *scope; - arith size; + arith size = 0; int xalign = struct_align; } : @@ -301,9 +301,10 @@ FieldList(struct scope *scope; arith *cnt; int *palign;) } df->df_type = tp; df->fld_off = align(*cnt, tp->tp_align); - *cnt = tcnt = df->fld_off + tp->tp_size; + *cnt = df->fld_off + tp->tp_size; df->df_flags |= D_QEXPORTED; } + tcnt = *cnt; } OF variant(scope, &tcnt, tp, palign) { max = tcnt; tcnt = *cnt; } diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index 85f1f764..fb87c58c 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -393,10 +393,8 @@ EnterFromImportList(Idlist, FromDef) for (; idlist; idlist = idlist->next) { if (forwflag) df = ForwDef(idlist, vis->sc_scope); else if (! (df = lookup(idlist->nd_IDF, vis->sc_scope))) { - node_error(idlist, - "identifier \"%s\" not declared in qualifying module", - idlist->nd_IDF->id_text); - df = define(idlist->nd_IDF,vis->sc_scope,D_ERROR); + not_declared("identifier", idlist, " in qualifying module"); + df = define(idlist->nd_IDF,vis->sc_scope,D_ERROR); } else if (! (df->df_flags & (D_EXPORTED|D_QEXPORTED))) { node_error(idlist, diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index bd2f8d64..5edf0c85 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -49,7 +49,7 @@ qualident(int types; if ( !((types|D_ERROR) & df->df_kind)) { if (df->df_kind == D_FORWARD) { -node_error(nd,"%s \"%s\" not declared", str, df->df_idf->id_text); + not_declared(str, nd, ""); } else { node_error(nd,"identifier \"%s\" is not a %s", df->df_idf->id_text, str); diff --git a/lang/m2/comp/lookup.c b/lang/m2/comp/lookup.c index 7109e6a5..6143502c 100644 --- a/lang/m2/comp/lookup.c +++ b/lang/m2/comp/lookup.c @@ -12,6 +12,7 @@ #include "LLlex.h" #include "node.h" #include "type.h" +#include "misc.h" struct def * lookup(id, scope) diff --git a/lang/m2/comp/misc.H b/lang/m2/comp/misc.H index 5cf1ae8e..8d8b48ed 100644 --- a/lang/m2/comp/misc.H +++ b/lang/m2/comp/misc.H @@ -1,6 +1,7 @@ /* M I S C E L L A N E O U S */ -#define is_anon_idf(x) ((x)->id_text[0] == '#') +#define is_anon_idf(x) ((x)->id_text[0] == '#') +#define id_not_declared(x) (not_declared("identifier", (x), "")) extern struct idf *gen_anon_idf(); diff --git a/lang/m2/comp/misc.c b/lang/m2/comp/misc.c index 573fd035..d945e553 100644 --- a/lang/m2/comp/misc.c +++ b/lang/m2/comp/misc.c @@ -40,7 +40,8 @@ gen_anon_idf() return str2idf(buff, 1); } -id_not_declared(id) +not_declared(what, id, where) + char *what, *where; register struct node *id; { /* The identifier "id" is not declared. If it is not generated, @@ -48,6 +49,9 @@ id_not_declared(id) */ if (!is_anon_idf(id->nd_IDF)) { node_error(id, - "identifier \"%s\" not declared", id->nd_IDF->id_text); + "%s \"%s\" not declared%s", + what, + id->nd_IDF->id_text, + where); } } From 13dfcedcefbc2fc8ad527292cc7357727e9194df Mon Sep 17 00:00:00 2001 From: sater Date: Fri, 24 Oct 1986 16:58:46 +0000 Subject: [PATCH 0307/1625] Typo corrected --- mach/proto/ncg/gencode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/proto/ncg/gencode.c b/mach/proto/ncg/gencode.c index a1701820..f7547408 100644 --- a/mach/proto/ncg/gencode.c +++ b/mach/proto/ncg/gencode.c @@ -85,7 +85,7 @@ string ad2str(ad) addr_t ad; { if (ad.ea_str==0) ad.ea_str=""; if ((long)ad.ea_off==(long)0) { - if strcmp(ad.ea_str,"") + if(ad.ea_str[0]==0) return(mystrcpy("0")); /* don't return empty string */ else return(mystrcpy(ad.ea_str)); From bca7ff59fb3313bc89300b6aa1a4b2c1a716e5aa Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 27 Oct 1986 09:57:42 +0000 Subject: [PATCH 0308/1625] Did not work properly, printed wrong trap number. Does not work properly now, because it does no save the registers. --- mach/m68k4/libem/trp.s | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mach/m68k4/libem/trp.s b/mach/m68k4/libem/trp.s index 0978c898..f5311228 100644 --- a/mach/m68k4/libem/trp.s +++ b/mach/m68k4/libem/trp.s @@ -6,9 +6,9 @@ .sect .text .trp: - cmp.l #16,4(sp) - bcc 1f move.l d0,-(sp) + cmp.l #16,8(sp) + bcc 1f move.l 8(sp),d0 btst d0,.trpim bne 3f @@ -37,5 +37,5 @@ jmp EXIT .sect .data -fmt: .asciz "trap %d called\n" +fmt: .asciz "EM trap %d called\n" .align 2 From c3e6f3aef67a47a61a4f9f0836937e2700c3ace0 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 27 Oct 1986 10:17:36 +0000 Subject: [PATCH 0309/1625] Made the trap message more readable. --- mach/vax4/libem/trp.s | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mach/vax4/libem/trp.s b/mach/vax4/libem/trp.s index e6779037..f9a2e1aa 100644 --- a/mach/vax4/libem/trp.s +++ b/mach/vax4/libem/trp.s @@ -27,7 +27,7 @@ L1: L2: # Put the (octal) trapnumber in the zeroes in Lemes[]. - movl $Lemesend-1,r1 # Addres after last '0'. + movl $Lemesend-9,r1 # Addres after last '0'. movl $5,r2 # Max number of digits. movl (sp),r0 # Trap number in r0. L3: @@ -42,7 +42,7 @@ L3: bpt .data Lemes: -.byte 'E,'r,'r,' ,'0,'0,'0,'0,'0,0xa +.byte 'E,'M,' ,'t,'r,'a,'p,' ,'0,'0,'0,'0,'0,' ,'(,'o,'c,'t,'a,'l,'),0xa Lemesend: .align 2 Lwr: From 04f1820b223f5b119a2d9fa0a5116612becfeb3b Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 28 Oct 1986 17:04:40 +0000 Subject: [PATCH 0310/1625] Some name changes in ../../modules/lib. --- util/led/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/led/Makefile b/util/led/Makefile index 3cf9ab62..e3587f90 100644 --- a/util/led/Makefile +++ b/util/led/Makefile @@ -9,7 +9,7 @@ LIBDIR= $(EM)/lib PREFLAGS= -I$(EM)/h -DNDEBUG -DNASSERT CFLAGS = $(PREFLAGS) -O LDFLAGS = -LDLIBS = $(EM)/modules/lib/libstr.a $(EM)/modules/lib/libobj.a +LDLIBS = $(EM)/modules/lib/libstring.a $(EM)/modules/lib/libobject.a LINTFLAGS=-phbxa $(PREFLAGS) PR = pr PRFLAGS = From d02d0632c0af9583caf83ef9ce3b2c41766b32aa Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 29 Oct 1986 11:16:55 +0000 Subject: [PATCH 0311/1625] Bug fix. Error recovery did not always work as expected. The generated parser sometimes assumed that a token would not be deleted, and inserted tokens in front of it, and then deleted the token after all. It should at each error, first delete, and then insert. --- util/LLgen/src/compute.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/util/LLgen/src/compute.c b/util/LLgen/src/compute.c index 00c74192..fd42e1ba 100644 --- a/util/LLgen/src/compute.c +++ b/util/LLgen/src/compute.c @@ -759,6 +759,10 @@ STATIC int nsafes(p) register p_nont p; { i = getntsafe(p); if (i != NOSAFETY) { i = do_safes(p->n_rule, i, &ch); + if (i < SCANDONE) i = SCANDONE; + /* After a nonterminal, we only know whether a scan was done + or not + */ if (getntout(p) != i) { ch = 1; setntout(p,i); From 07626ee7b30902f844a26e4ddbd1e7f14bea7d43 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 29 Oct 1986 11:27:47 +0000 Subject: [PATCH 0312/1625] Added nflag, that allows the LLmessage(-1) call, to indicate garbage at end of program. --- util/LLgen/src/gencode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util/LLgen/src/gencode.c b/util/LLgen/src/gencode.c index 528777e5..9dc37377 100644 --- a/util/LLgen/src/gencode.c +++ b/util/LLgen/src/gencode.c @@ -178,7 +178,7 @@ genrecovery() { for (st = start; st; st = st->ff_next) { fputs(st->ff_name, f); p = &nonterms[st->ff_nont]; - fputs("() {\n\tunsigned int s[LL_NTERMINALS+LL_NSETS+1];\n\tLLnewlevel(s);\n\tLLread();\n", f); + fputs("() {\n\tunsigned int s[LL_NTERMINALS+LL_NSETS+2];\n\tLLnewlevel(s);\n\tLLread();\n", f); if (g_gettype(p->n_rule) == ALTERNATION) { genpush(findindex(p->n_contains)); } @@ -206,6 +206,7 @@ genrecovery() { } fputs(c_arrend, f); free((p_mem) index); + if (nflag) fputs("#define LL_NEWMESS\n", f); copyfile(rec_file); if (ferror(f) != 0) { fatal(0,"write error on temporary"); From 96e1ce1b52c27792478d5a4dc11bba08da0c7c6e Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 29 Oct 1986 11:29:47 +0000 Subject: [PATCH 0313/1625] Added "nflag". --- util/LLgen/src/extern.h | 1 + util/LLgen/src/main.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/util/LLgen/src/extern.h b/util/LLgen/src/extern.h index 81563af5..66d6f06e 100644 --- a/util/LLgen/src/extern.h +++ b/util/LLgen/src/extern.h @@ -82,3 +82,4 @@ extern int nerrors; extern string rec_file, incl_file; extern p_term terms; extern p_link links; +extern int nflag; diff --git a/util/LLgen/src/main.c b/util/LLgen/src/main.c index c7db5a7a..3803782a 100644 --- a/util/LLgen/src/main.c +++ b/util/LLgen/src/main.c @@ -50,6 +50,7 @@ extern install(); # ifndef NDEBUG extern badassertion(); # endif not NDEBUG +int nflag; main(argc,argv) register string argv[]; { register string arg; @@ -89,6 +90,10 @@ main(argc,argv) register string argv[]; { incl_file = ++arg; break; # endif not NDEBUG + case 'n': + case 'N': + nflag = 1; + continue; case 'x': case 'X': ntneeded = 1; From 8503344eea06cf2378d8fd6f12abdaaad8821314 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 29 Oct 1986 11:30:50 +0000 Subject: [PATCH 0314/1625] Added code that calls LLmessage(-1) when needed, and when LL_NEWMESS is defined. --- util/LLgen/lib/rec | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/util/LLgen/lib/rec b/util/LLgen/lib/rec index eff58df1..7eaea1f4 100644 --- a/util/LLgen/lib/rec +++ b/util/LLgen/lib/rec @@ -55,6 +55,12 @@ LLread() { LLerror(t) { register int i; +#ifdef LL_NEWMESSAGE + if (t == EOFILE) { + LLmessage(-1); + return; + } +#endif if ((LLcsymb = LLindex[LLsymb]) < 0) { LLmessage(0); LLread(); From 60e95ef3468c03e85aaa130c2b5992e9382078e5 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 30 Oct 1986 15:01:16 +0000 Subject: [PATCH 0315/1625] forgot to restore return address in case ".trp" is called. --- mach/vax4/libem/cui.s | 1 + 1 file changed, 1 insertion(+) diff --git a/mach/vax4/libem/cui.s b/mach/vax4/libem/cui.s index 8d2f35f0..4fcf3f4a 100644 --- a/mach/vax4/libem/cui.s +++ b/mach/vax4/libem/cui.s @@ -22,4 +22,5 @@ Lerr: jmp .fat Liovfl: pushl $EIOVFL + pushl r1 jmp .trp From 4abeef8300c4a15bb391d99e6d2bc80fc6cced79 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 30 Oct 1986 15:44:25 +0000 Subject: [PATCH 0316/1625] Removed the integer overflow check, as it is'nt checked by "cg". --- mach/vax4/libem/cui.s | 8 -------- 1 file changed, 8 deletions(-) diff --git a/mach/vax4/libem/cui.s b/mach/vax4/libem/cui.s index 4fcf3f4a..9242ea7d 100644 --- a/mach/vax4/libem/cui.s +++ b/mach/vax4/libem/cui.s @@ -12,15 +12,7 @@ movl (sp)+,r0 cmpl r0,$4 bneq Lerr - tstl (sp) - bgeq L1 - jbr Liovfl -L1: jmp (r1) Lerr: pushl $EILLINS jmp .fat -Liovfl: - pushl $EIOVFL - pushl r1 - jmp .trp From e364c641d0ed66b7cb773772ff04f2a6404b7539 Mon Sep 17 00:00:00 2001 From: sater Date: Mon, 3 Nov 1986 09:13:32 +0000 Subject: [PATCH 0317/1625] Output was wrong with maxmembers<2 --- util/ncgg/output.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/ncgg/output.c b/util/ncgg/output.c index 48ba9510..959fdd6b 100644 --- a/util/ncgg/output.c +++ b/util/ncgg/output.c @@ -271,7 +271,7 @@ outregs() { l_regs[i].ri_size); if (maxmembers!=0) { fprintf(ctable,",{"); - for(j=0;j<2;j++) + for(j=0;j Date: Mon, 3 Nov 1986 10:28:21 +0000 Subject: [PATCH 0318/1625] That was: LL_NEWMESS, not LL_NEWMESSAGE! --- util/LLgen/lib/rec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/LLgen/lib/rec b/util/LLgen/lib/rec index 7eaea1f4..d066f00d 100644 --- a/util/LLgen/lib/rec +++ b/util/LLgen/lib/rec @@ -55,7 +55,7 @@ LLread() { LLerror(t) { register int i; -#ifdef LL_NEWMESSAGE +#ifdef LL_NEWMESS if (t == EOFILE) { LLmessage(-1); return; From eb91f2c19d0f80d408fdc095632fb11213d51893 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 3 Nov 1986 14:09:28 +0000 Subject: [PATCH 0319/1625] Added some code to skip to EOF with LL_NEWMESS. --- util/LLgen/lib/rec | 1 + 1 file changed, 1 insertion(+) diff --git a/util/LLgen/lib/rec b/util/LLgen/lib/rec index d066f00d..3c885044 100644 --- a/util/LLgen/lib/rec +++ b/util/LLgen/lib/rec @@ -57,6 +57,7 @@ LLerror(t) { #ifdef LL_NEWMESS if (t == EOFILE) { + while ((LLsymb = LL_LEXI()) > 0) /* nothing */ ; LLmessage(-1); return; } From c92a7f411d483aab48154152203f128f37bda78c Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 5 Nov 1986 14:33:00 +0000 Subject: [PATCH 0320/1625] Several bug fixes --- lang/m2/comp/LLlex.c | 93 ++++++++++++++++++++++++++++++++++++--- lang/m2/comp/LLmessage.c | 11 ++--- lang/m2/comp/Makefile | 58 ++++++++++++------------ lang/m2/comp/Parameters | 8 +--- lang/m2/comp/Version.c | 2 +- lang/m2/comp/casestat.C | 15 ++++++- lang/m2/comp/chk_expr.c | 3 +- lang/m2/comp/cstoper.c | 10 +++-- lang/m2/comp/debug.h | 10 +++++ lang/m2/comp/declar.g | 43 +++++++++++++----- lang/m2/comp/defmodule.c | 56 +++++++++++++---------- lang/m2/comp/enter.c | 33 +++++++++----- lang/m2/comp/error.c | 35 +++++++++------ lang/m2/comp/expression.g | 8 +++- lang/m2/comp/input.c | 4 -- lang/m2/comp/lookup.c | 32 ++++++++++++++ lang/m2/comp/main.c | 6 ++- lang/m2/comp/misc.c | 2 +- lang/m2/comp/options.c | 39 +++++++++++++++- lang/m2/comp/program.g | 40 ++++++----------- lang/m2/comp/scope.C | 3 +- lang/m2/comp/tokenname.c | 2 +- lang/m2/comp/type.c | 26 ++++++----- lang/m2/comp/typequiv.c | 3 +- lang/m2/comp/walk.c | 5 ++- lang/m2/comp/warning.h | 18 ++++++++ 26 files changed, 401 insertions(+), 164 deletions(-) create mode 100644 lang/m2/comp/debug.h create mode 100644 lang/m2/comp/warning.h diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index 6489389c..733ba3b3 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -18,6 +18,7 @@ #include "type.h" #include "LLlex.h" #include "const.h" +#include "warning.h" long str2long(); @@ -29,6 +30,8 @@ int idfsize = IDFSIZE; extern int cntlines; #endif +static int eofseen; + STATIC SkipComment() { @@ -104,6 +107,81 @@ GetString(upto) return str; } +static char *s_error = "illegal line directive"; + +STATIC int +getch() +{ + register int ch; + + for (;;) { + LoadChar(ch); + if ((ch & 0200) && ch != EOI) { + error("non-ascii '\\%03o' read", ch & 0377); + continue; + } + break; + } + if (ch == EOI) { + eofseen = 1; + return '\n'; + } + return ch; +} + +STATIC +linedirective() { + /* Read a line directive + */ + register int ch; + register int i = 0; + char buf[IDFSIZE + 2]; + register char *c = buf; + + do { /* + * Skip to next digit + * Do not skip newlines + */ + ch = getch(); + if (class(ch) == STNL) { + LineNumber++; + error(s_error); + return; + } + } while (class(ch) != STNUM); + do { + i = i*10 + (ch - '0'); + ch = getch(); + } while (class(ch) == STNUM); + while (ch != '"' && class(ch) != STNL) ch = getch(); + if (ch == '"') { + c = buf; + do { + *c++ = ch = getch(); + if (class(ch) == STNL) { + LineNumber++; + error(s_error); + return; + } + } while (ch != '"'); + *--c = '\0'; + do { + ch = getch(); + } while (class(ch) != STNL); + /* + * Remember the file name + */ + if (!eofseen && strcmp(FileName,buf)) { + FileName = Salloc(buf,strlen(buf) + 1); + } + } + if (eofseen) { + error(s_error); + return; + } + LineNumber = i; +} + int LLlex() { @@ -113,7 +191,6 @@ LLlex() register struct token *tk = ˙ char buf[(IDFSIZE > NUMSIZE ? IDFSIZE : NUMSIZE) + 2]; register int ch, nch; - static int eofseen; toktype = error_type; @@ -125,6 +202,7 @@ LLlex() tk->tk_lineno = LineNumber; +again2: if (eofseen) { eofseen = 0; ch = EOI; @@ -132,8 +210,10 @@ LLlex() else { again: LoadChar(ch); +again1: if ((ch & 0200) && ch != EOI) { - fatal("non-ascii '\\%03o' read", ch & 0377); + error("non-ascii '\\%03o' read", ch & 0377); + goto again; } } @@ -145,7 +225,10 @@ again: cntlines++; #endif tk->tk_lineno++; - /* Fall Through */ + LoadChar(ch); + if (ch != '#') goto again1; + linedirective(); + goto again2; case STSKIP: goto again; @@ -192,7 +275,7 @@ again: return tk->tk_symb = LESSEQUAL; } if (nch == '>') { - lexwarning("'<>' is old-fashioned; use '#'"); + lexwarning(W_STRICT, "'<>' is old-fashioned; use '#'"); return tk->tk_symb = '#'; } break; @@ -331,7 +414,7 @@ again: if (ch == 'C' && base == 8) { toktype = char_type; if (tk->TOK_INT<0 || tk->TOK_INT>255) { -lexwarning("Character constant out of range"); +lexwarning(W_ORDINARY, "character constant out of range"); } } else if (tk->TOK_INT>=0 && diff --git a/lang/m2/comp/LLmessage.c b/lang/m2/comp/LLmessage.c index ead8f103..7de4385a 100644 --- a/lang/m2/comp/LLmessage.c +++ b/lang/m2/comp/LLmessage.c @@ -21,15 +21,16 @@ extern int err_occurred; LLmessage(tk) int tk; { - if (tk) { - /* if (tk != 0), it represents the token to be inserted. - otherwize, the current token is deleted + if (tk > 0) { + /* if (tk > 0), it represents the token to be inserted. */ error("%s missing", symbol2str(tk)); insert_token(tk); } - else - error("%s deleted", symbol2str(dot.tk_symb)); + else if (tk < 0) { + error("garbage at end of program"); + } + else error("%s deleted", symbol2str(dot.tk_symb)); } insert_token(tk) diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index 3e4ad43f..f9746fd1 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -3,6 +3,7 @@ EMDIR = ../../.. MHDIR = $(EMDIR)/modules/h PKGDIR = $(EMDIR)/modules/pkg LIBDIR = $(EMDIR)/modules/lib +OBJECTCODE = $(LIBDIR)/libemk.a LLGEN = $(EMDIR)/bin/LLgen INCLUDES = -I$(MHDIR) -I$(EMDIR)/h -I$(PKGDIR) @@ -13,6 +14,7 @@ LLGENOPTIONS = PROFILE = CFLAGS = $(PROFILE) $(INCLUDES) -DSTATIC= LINTFLAGS = -DSTATIC= -DNORCSID +MALLOC = $(LIBDIR)/dickmalloc.o LFLAGS = $(PROFILE) LSRC = tokenfile.c program.c declar.c expression.c statement.c LOBJ = tokenfile.o program.o declar.o expression.o statement.o @@ -35,13 +37,13 @@ GENCFILES= tokenfile.c \ symbol2str.c char.c Lpars.c casestat.c tmpvar.c scope.c GENGFILES= tokenfile.g GENHFILES= errout.h\ - idfsize.h numsize.h strsize.h target_sizes.h debug.h\ + idfsize.h numsize.h strsize.h target_sizes.h \ inputtype.h maxset.h ndir.h density.h\ - def.h type.h Lpars.h node.h + def.h debugcst.h type.h Lpars.h node.h HFILES= LLlex.h\ - chk_expr.h class.h const.h desig.h f_info.h idf.h\ + chk_expr.h class.h const.h debug.h desig.h f_info.h idf.h\ input.h main.h misc.h scope.h standards.h tokenname.h\ - walk.h $(GENHFILES) + walk.h warning.h $(GENHFILES) # GENFILES = $(GENGFILES) $(GENCFILES) $(GENHFILES) @@ -67,7 +69,7 @@ clashes: $(SRC) $(HFILES) # entry points not to be used directly -Cfiles: hfiles LLfiles $(GENCFILES) $(GENHFILES) +Cfiles: hfiles LLfiles $(GENCFILES) $(GENHFILES) Makefile echo $(SRC) $(HFILES) > Cfiles LLfiles: $(GFILES) @@ -122,39 +124,39 @@ Xlint: lint $(INCLUDES) $(LINTFLAGS) $(SRC) ../comp/main: $(OBJ) ../comp/Makefile - $(CC) $(LFLAGS) $(OBJ) $(LIBDIR)/libem_mes.a $(LIBDIR)/libemk.a $(LIBDIR)/input.a $(LIBDIR)/assert.a $(LIBDIR)/alloc.a $(LIBDIR)/malloc.o $(LIBDIR)/libprint.a $(LIBDIR)/libstr.a $(LIBDIR)/libsystem.a -o ../comp/main + $(CC) $(LFLAGS) $(OBJ) $(LIBDIR)/libem_mes.a $(OBJECTCODE) $(LIBDIR)/libinput.a $(LIBDIR)/libassert.a $(LIBDIR)/liballoc.a $(MALLOC) $(LIBDIR)/libprint.a $(LIBDIR)/libstring.a $(LIBDIR)/libsystem.a -o ../comp/main size ../comp/main #AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO -LLlex.o: LLlex.h Lpars.h class.h const.h debug.h f_info.h idf.h idfsize.h input.h inputtype.h numsize.h strsize.h type.h +LLlex.o: LLlex.h Lpars.h class.h const.h debug.h debugcst.h f_info.h idf.h idfsize.h input.h inputtype.h numsize.h strsize.h type.h warning.h LLmessage.o: LLlex.h Lpars.h idf.h char.o: class.h -error.o: LLlex.h debug.h errout.h f_info.h input.h inputtype.h main.h node.h -main.o: LLlex.h Lpars.h debug.h def.h f_info.h idf.h input.h inputtype.h ndir.h node.h scope.h standards.h tokenname.h type.h +error.o: LLlex.h debug.h debugcst.h errout.h f_info.h input.h inputtype.h main.h node.h warning.h +main.o: LLlex.h Lpars.h debug.h debugcst.h def.h f_info.h idf.h input.h inputtype.h ndir.h node.h scope.h standards.h tokenname.h type.h warning.h symbol2str.o: Lpars.h tokenname.o: Lpars.h idf.h tokenname.h idf.o: idf.h input.o: def.h f_info.h idf.h input.h inputtype.h scope.h -type.o: LLlex.h const.h debug.h def.h idf.h maxset.h node.h scope.h target_sizes.h type.h walk.h -def.o: LLlex.h Lpars.h debug.h def.h idf.h main.h node.h scope.h type.h -scope.o: LLlex.h debug.h def.h idf.h node.h scope.h type.h +type.o: LLlex.h const.h debug.h debugcst.h def.h idf.h maxset.h node.h scope.h target_sizes.h type.h walk.h +def.o: LLlex.h Lpars.h debug.h debugcst.h def.h idf.h main.h node.h scope.h type.h +scope.o: LLlex.h debug.h debugcst.h def.h idf.h node.h scope.h type.h misc.o: LLlex.h f_info.h idf.h misc.h node.h -enter.o: LLlex.h debug.h def.h idf.h main.h node.h scope.h type.h -defmodule.o: LLlex.h Lpars.h debug.h def.h f_info.h idf.h input.h inputtype.h main.h node.h scope.h -typequiv.o: LLlex.h debug.h def.h node.h type.h -node.o: LLlex.h debug.h def.h node.h type.h -cstoper.o: LLlex.h Lpars.h debug.h idf.h node.h standards.h target_sizes.h type.h -chk_expr.o: LLlex.h Lpars.h chk_expr.h const.h debug.h def.h idf.h misc.h node.h scope.h standards.h type.h -options.o: idfsize.h main.h ndir.h type.h -walk.o: LLlex.h Lpars.h chk_expr.h debug.h def.h desig.h f_info.h idf.h main.h node.h scope.h type.h walk.h -casestat.o: LLlex.h Lpars.h debug.h density.h desig.h node.h type.h walk.h -desig.o: LLlex.h debug.h def.h desig.h node.h scope.h type.h -code.o: LLlex.h Lpars.h debug.h def.h desig.h node.h scope.h standards.h type.h walk.h -tmpvar.o: debug.h def.h main.h scope.h type.h -lookup.o: LLlex.h debug.h def.h idf.h misc.h node.h scope.h type.h +enter.o: LLlex.h debug.h debugcst.h def.h idf.h main.h node.h scope.h type.h +defmodule.o: LLlex.h Lpars.h debug.h debugcst.h def.h f_info.h idf.h input.h inputtype.h main.h node.h scope.h type.h +typequiv.o: LLlex.h debug.h debugcst.h def.h node.h type.h warning.h +node.o: LLlex.h debug.h debugcst.h def.h node.h type.h +cstoper.o: LLlex.h Lpars.h debug.h debugcst.h idf.h node.h standards.h target_sizes.h type.h warning.h +chk_expr.o: LLlex.h Lpars.h chk_expr.h const.h debug.h debugcst.h def.h idf.h misc.h node.h scope.h standards.h type.h warning.h +options.o: idfsize.h main.h ndir.h type.h warning.h +walk.o: LLlex.h Lpars.h chk_expr.h debug.h debugcst.h def.h desig.h f_info.h idf.h main.h node.h scope.h type.h walk.h warning.h +casestat.o: LLlex.h Lpars.h debug.h debugcst.h density.h desig.h node.h type.h walk.h +desig.o: LLlex.h debug.h debugcst.h def.h desig.h node.h scope.h type.h +code.o: LLlex.h Lpars.h debug.h debugcst.h def.h desig.h node.h scope.h standards.h type.h walk.h +tmpvar.o: debug.h debugcst.h def.h main.h scope.h type.h +lookup.o: LLlex.h debug.h debugcst.h def.h idf.h misc.h node.h scope.h type.h tokenfile.o: Lpars.h -program.o: LLlex.h Lpars.h debug.h def.h f_info.h idf.h main.h node.h scope.h type.h -declar.o: LLlex.h Lpars.h chk_expr.h debug.h def.h idf.h main.h misc.h node.h scope.h type.h -expression.o: LLlex.h Lpars.h chk_expr.h const.h debug.h def.h idf.h node.h type.h +program.o: LLlex.h Lpars.h debug.h debugcst.h def.h f_info.h idf.h main.h node.h scope.h type.h warning.h +declar.o: LLlex.h Lpars.h chk_expr.h debug.h debugcst.h def.h idf.h main.h misc.h node.h scope.h type.h warning.h +expression.o: LLlex.h Lpars.h chk_expr.h const.h debug.h debugcst.h def.h idf.h node.h type.h warning.h statement.o: LLlex.h Lpars.h def.h idf.h node.h scope.h type.h Lpars.o: Lpars.h diff --git a/lang/m2/comp/Parameters b/lang/m2/comp/Parameters index 0fe8880a..9aa80fbe 100644 --- a/lang/m2/comp/Parameters +++ b/lang/m2/comp/Parameters @@ -45,14 +45,8 @@ #define AL_UNION 1 -!File: debug.h +!File: debugcst.h #define DEBUG 1 /* perform various self-tests */ -extern char options[]; -#ifdef DEBUG -#define DO_DEBUG(y, x) ((y) && (x)) -#else -#define DO_DEBUG(y, x) -#endif DEBUG !File: inputtype.h #define INP_READ_IN_ONE 1 /* read input file in one */ diff --git a/lang/m2/comp/Version.c b/lang/m2/comp/Version.c index 0be24d41..44e57907 100644 --- a/lang/m2/comp/Version.c +++ b/lang/m2/comp/Version.c @@ -1 +1 @@ -char Version[] = "Version 0.6"; +char Version[] = "Version 0.7"; diff --git a/lang/m2/comp/casestat.C b/lang/m2/comp/casestat.C index 8216036f..63913e73 100644 --- a/lang/m2/comp/casestat.C +++ b/lang/m2/comp/casestat.C @@ -69,6 +69,7 @@ CaseCode(nd, exitlabel) register struct case_entry *ce; register arith val; label CaseDescrLab; + int casecnt = 0; assert(pnode->nd_class == Stat && pnode->nd_symb == CASE); @@ -85,6 +86,7 @@ CaseCode(nd, exitlabel) /* non-empty case */ pnode->nd_lab = ++text_label; + casecnt++; if (! AddCases(sh, /* to descriptor */ pnode->nd_left->nd_left, /* of case labels */ @@ -105,6 +107,17 @@ CaseCode(nd, exitlabel) } } + if (!casecnt) { + /* There were no cases, so we have to check the case-expression + here + */ + if (! (sh->sh_type->tp_fund & T_DISCRETE)) { + node_error(nd, "illegal type in CASE-expression"); + FreeSh(sh); + return; + } + } + /* Now generate code for the switch itself First the part that CSA and CSB descriptions have in common. */ @@ -232,7 +245,7 @@ AddOneCase(sh, node, lbl) ce->ce_label = lbl; ce->ce_value = node->nd_INT; if (! TstCompat(sh->sh_type, node->nd_type)) { - node_error(node, "Type incompatibility in case"); + node_error(node, "type incompatibility in case"); free_case_entry(ce); return 0; } diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index 40a2064a..c01ae1a5 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -21,6 +21,7 @@ #include "standards.h" #include "chk_expr.h" #include "misc.h" +#include "warning.h" extern char *symbol2str(); @@ -936,7 +937,7 @@ node_error(left, "illegal type in %s", std == S_MAX ? "MAX" : "MIN"); if (!warning_given) { warning_given = 1; - node_warning(expp, "NEW and DISPOSE are old-fashioned"); + node_warning(expp, W_OLDFASHIONED, "NEW and DISPOSE are old-fashioned"); } } if (! (left = getvariable(&arg))) return 0; diff --git a/lang/m2/comp/cstoper.c b/lang/m2/comp/cstoper.c index 9e5135c7..aeb9bb8d 100644 --- a/lang/m2/comp/cstoper.c +++ b/lang/m2/comp/cstoper.c @@ -13,6 +13,7 @@ #include "node.h" #include "Lpars.h" #include "standards.h" +#include "warning.h" long mach_long_sign; /* sign bit of the machine long */ int mach_long_size; /* size of long on this machine == sizeof(long) */ @@ -22,6 +23,8 @@ arith max_unsigned; /* maximum unsigned on target machine */ arith max_longint; /* maximum longint on target machine */ arith wrd_bits; /* number of bits in a word */ +static char ovflow[] = "overflow in constant expression"; + cstunary(expp) register struct node *expp; { @@ -485,7 +488,7 @@ cstcall(expp, call) || expp->nd_INT >= expp->nd_type->enm_ncst ) ) - ) node_warning(expp,"overflow in constant expression"); + ) node_warning(expp, W_ORDINARY, ovflow); else CutSize(expp); break; @@ -512,8 +515,7 @@ CutSize(expr) uns = (tp->tp_fund & (T_CARDINAL|T_CHAR)); if (uns) { if (o1 & ~full_mask[size]) { - node_warning(expr, - "overflow in constant expression"); + node_warning(expr, W_ORDINARY, ovflow); o1 &= full_mask[size]; } } @@ -522,7 +524,7 @@ CutSize(expr) long remainder = o1 & ~full_mask[size]; if (remainder != 0 && remainder != ~full_mask[size]) { - node_warning(expr, "overflow in constant expression"); + node_warning(expr, W_ORDINARY, ovflow); o1 <<= nbits; o1 >>= nbits; } diff --git a/lang/m2/comp/debug.h b/lang/m2/comp/debug.h new file mode 100644 index 00000000..670c29d1 --- /dev/null +++ b/lang/m2/comp/debug.h @@ -0,0 +1,10 @@ +/* A debugging macro +*/ + +#include "debugcst.h" + +#ifdef DEBUG +#define DO_DEBUG(x, y) ((x) && (y)) +#else +#define DO_DEBUG(x, y) +#endif diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 7bca82d6..8a277ed8 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -17,6 +17,7 @@ #include "misc.h" #include "main.h" #include "chk_expr.h" +#include "warning.h" int proclevel = 0; /* nesting level of procedures */ int return_occurred; /* set if a return occurs in a block */ @@ -162,7 +163,7 @@ enumeration(struct type **ptp;) *ptp = standard_type(T_ENUMERATION, 1, (arith) 1); EnterEnumList(EnumList, *ptp); if ((*ptp)->enm_ncst > 256) { /* ??? is this reasonable ??? */ - error("Too many enumeration literals"); + error("too many enumeration literals"); } } ; @@ -277,7 +278,7 @@ FieldList(struct scope *scope; arith *cnt; int *palign;) | /* Old fashioned! the first qualident now represents the type */ - { warning("Old fashioned Modula-2 syntax; ':' missing"); + { warning(W_OLDFASHIONED, "old fashioned Modula-2 syntax; ':' missing"); if (ChkDesignator(nd) && (nd->nd_class != Def || !(nd->nd_def->df_kind&(D_ERROR|D_ISTYPE)) || @@ -297,7 +298,7 @@ FieldList(struct scope *scope; arith *cnt; int *palign;) scope, D_FIELD); if (!(tp->tp_fund & T_DISCRETE)) { - error("Illegal type in variant"); + error("illegal type in variant"); } df->df_type = tp; df->fld_off = align(*cnt, tp->tp_align); @@ -386,18 +387,36 @@ PointerType(struct type **ptp;) } : POINTER TO { *ptp = construct_type(T_POINTER, NULLTYPE); } - [ %if ( lookup(dot.TOK_IDF, CurrentScope)) - /* Either a Module or a Type, but in both cases defined - in this scope, so this is the correct identification - */ - qualtype(&((*ptp)->next)) - | %if ( nd = new_node(), - nd->nd_token = dot, - lookfor(nd, CurrVis, 0)->df_kind == D_MODULE) + [ %if ( lookup(dot.TOK_IDF, CurrentScope) + /* Either a Module or a Type, but in both cases defined + in this scope, so this is the correct identification + */ + || + ( nd = new_node(), + nd->nd_token = dot, + lookfor(nd, CurrVis, 0)->df_kind == D_MODULE + ) + /* A Modulename in one of the enclosing scopes. + It is not clear from the language definition that + it is correct to handle these like this, but + existing compilers do it like this, and the + alternative is difficult with a lookahead of only + one token. + ??? + */ + ) type(&((*ptp)->next)) { if (nd) free_node(nd); } | - IDENT { Forward(nd, (*ptp)); } + IDENT { if (nd) { + /* nd could be a null pointer, if we had a + syntax error exactly at this alternation. + MORAL: Be careful with %if resolvers with + side effects! + */ + Forward(nd, (*ptp)); + } + } ] ; diff --git a/lang/m2/comp/defmodule.c b/lang/m2/comp/defmodule.c index 3ba1f6d8..aaf49e9d 100644 --- a/lang/m2/comp/defmodule.c +++ b/lang/m2/comp/defmodule.c @@ -15,13 +15,13 @@ #include "f_info.h" #include "main.h" #include "node.h" +#include "type.h" #ifdef DEBUG long sys_filesize(); #endif -struct idf * CurrentId; - +STATIC GetFile(name) char *name; { @@ -35,10 +35,12 @@ GetFile(name) buf[10] = '\0'; /* maximum length */ strcat(buf, ".def"); if (! InsertFile(buf, DEFPATH, &(FileName))) { - fatal("Could'nt find a DEFINITION MODULE for \"%s\"", name); + error("could'nt find a DEFINITION MODULE for \"%s\"", name); + return 0; } LineNumber = 1; DO_DEBUG(options['F'], debug("File %s : %ld characters", FileName, sys_filesize(FileName))); + return 1; } struct def * @@ -52,6 +54,7 @@ GetDefinitionModule(id, incr) */ struct def *df; static int level; + struct scopelist *vis; level += incr; df = lookup(id, GlobalScope); @@ -62,33 +65,40 @@ GetDefinitionModule(id, incr) do_SYSTEM(); } else { - GetFile(id->id_text); - CurrentId = id; open_scope(CLOSEDSCOPE); - DefModule(); - if (level == 1) { - /* The module is directly imported by the - currently defined module, so we have to - remember its name because we have to call - its initialization routine - */ - static struct node *nd_end; /* end of list */ - register struct node *n; - extern struct node *Modules; + if (GetFile(id->id_text)) { + DefModule(); + if (level == 1) { + /* The module is directly imported by + the currently defined module, so we + have to remember its name because + we have to call its initialization + routine + */ + static struct node *nd_end; + register struct node *n; + extern struct node *Modules; - n = MkLeaf(Name, &dot); - n->nd_IDF = id; - n->nd_symb = IDENT; - if (nd_end) nd_end->next = n; - else Modules = n; - nd_end = n; + n = MkLeaf(Name, &dot); + n->nd_IDF = id; + n->nd_symb = IDENT; + if (nd_end) nd_end->next = n; + else Modules = n; + nd_end = n; + } } + vis = CurrVis; close_scope(SC_CHKFORW); } df = lookup(id, GlobalScope); + if (! df) { + df = MkDef(id, GlobalScope, D_ERROR); + df->df_type = error_type; + df->mod_vis = CurrVis; + return df; + } } - CurrentId = 0; - assert(df && df->df_kind == D_MODULE); + assert(df); level -= incr; return df; } diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index fb87c58c..b5c0aa02 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -116,7 +116,7 @@ EnterVarList(Idlist, type, local) df->df_flags |= D_NOREG; if (idlist->nd_left->nd_type != card_type) { node_error(idlist->nd_left, - "Illegal type for address"); + "illegal type for address"); } df->var_off = idlist->nd_left->nd_INT; } @@ -235,17 +235,20 @@ DoImport(df, scope) } STATIC struct scopelist * -ForwModule(df, idn) +ForwModule(df, nd) register struct def *df; - struct node *idn; + struct node *nd; { - /* An import is done from a not yet defined module "idn". + /* An import is done from a not yet defined module "df". + We could also end up here for not found DEFINITION MODULES. Create a declaration and a scope for this module. */ struct scopelist *vis; - df->df_scope = enclosing(CurrVis)->sc_scope; - df->df_kind = D_FORWMODULE; + if (df->df_scope != GlobalScope) { + df->df_scope = enclosing(CurrVis)->sc_scope; + df->df_kind = D_FORWMODULE; + } open_scope(CLOSEDSCOPE); vis = CurrVis; /* The new scope, but watch out, it's "sc_encl" field is not set right. It must indicate the @@ -256,7 +259,7 @@ ForwModule(df, idn) vis->sc_encl = enclosing(CurrVis); /* Here ! */ df->for_vis = vis; - df->for_node = MkLeaf(Name, &(idn->nd_token)); + df->for_node = nd; return vis; } @@ -289,7 +292,9 @@ EnterExportList(Idlist, qualified) register struct def *df, *df1; for (;idlist; idlist = idlist->next) { - df = lookup(idlist->nd_IDF, CurrentScope); + extern struct def *NoImportlookup(); + + df = NoImportlookup(idlist->nd_IDF, CurrentScope); if (!df) { /* undefined item in export list @@ -306,6 +311,8 @@ EnterExportList(Idlist, qualified) idlist->nd_IDF->id_text); } + if (df->df_kind == D_IMPORT) df = df->imp_def; + df->df_flags |= qualified; if (qualified == D_EXPORTED) { /* Export, but not qualified. @@ -357,9 +364,10 @@ EnterExportList(Idlist, qualified) FreeNode(Idlist); } -EnterFromImportList(Idlist, FromDef) +EnterFromImportList(Idlist, FromDef, FromId) struct node *Idlist; register struct def *FromDef; + struct node *FromId; { /* Import the list Idlist from the module indicated by Fromdef. */ @@ -373,9 +381,11 @@ EnterFromImportList(Idlist, FromDef) /* The module from which the import was done is not yet declared. I'm not sure if I must accept this, but for the time being I will. + We also end up here if some definition module could not + be found. ??? */ - vis = ForwModule(FromDef, FromDef->df_idf); + vis = ForwModule(FromDef, FromId); forwflag = 1; break; case D_FORWMODULE: @@ -385,7 +395,7 @@ EnterFromImportList(Idlist, FromDef) vis = FromDef->mod_vis; break; default: - error("identifier \"%s\" does not represent a module", + node_error(FromId, "identifier \"%s\" does not represent a module", FromDef->df_idf->id_text); break; } @@ -405,6 +415,7 @@ EnterFromImportList(Idlist, FromDef) DoImport(df, CurrentScope); } + if (!forwflag) FreeNode(FromId); FreeNode(Idlist); } diff --git a/lang/m2/comp/error.c b/lang/m2/comp/error.c index cde6d7c3..468abbe0 100644 --- a/lang/m2/comp/error.c +++ b/lang/m2/comp/error.c @@ -17,6 +17,7 @@ #include "LLlex.h" #include "main.h" #include "node.h" +#include "warning.h" /* error classes */ #define ERROR 1 @@ -30,6 +31,7 @@ #endif int err_occurred; +static int warn_class; extern char *symbol2str(); @@ -69,18 +71,20 @@ node_error(node, fmt, args) } /*VARARGS1*/ -warning(fmt, args) +warning(class, fmt, args) char *fmt; { - _error(WARNING, NULLNODE, fmt, &args); + warn_class = class; + if (class & warning_classes) _error(WARNING, NULLNODE, fmt, &args); } /*VARARGS2*/ -node_warning(node, fmt, args) +node_warning(node, class, fmt, args) struct node *node; char *fmt; { - _error(WARNING, node, fmt, &args); + warn_class = class; + if (class & warning_classes) _error(WARNING, node, fmt, &args); } /*VARARGS1*/ @@ -91,10 +95,11 @@ lexerror(fmt, args) } /*VARARGS1*/ -lexwarning(fmt, args) +lexwarning(class, fmt, args) char *fmt; { - _error(LEXWARNING, NULLNODE, fmt, &args); + warn_class = class; + if (class & warning_classes) _error(LEXWARNING, NULLNODE, fmt, &args); } /*VARARGS1*/ @@ -149,19 +154,23 @@ _error(class, node, fmt, argv) if (C_busy()) C_ms_err(); err_occurred = 1; break; - - case WARNING: - case LEXWARNING: - if (options['w']) - return; - break; } /* the remark */ switch (class) { case WARNING: case LEXWARNING: - remark = "(warning)"; + switch(warn_class) { + case W_OLDFASHIONED: + remark = "(old-fashioned use)"; + break; + case W_STRICT: + remark = "(strict)"; + break; + default: + remark = "(warning)"; + break; + } break; case CRASH: remark = "CRASH\007"; diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index 5edf0c85..0baa3356 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -15,6 +15,9 @@ #include "const.h" #include "type.h" #include "chk_expr.h" +#include "warning.h" + +extern char options[]; } number(struct node **p;) : @@ -93,7 +96,7 @@ ConstExpression(struct node **pnd;): DO_DEBUG(options['X'], PrNode(*pnd, 0)); if (ChkExpression(*pnd) && ((*pnd)->nd_class != Set && (*pnd)->nd_class != Value)) { - error("Constant expression expected"); + error("constant expression expected"); } DO_DEBUG(options['X'], print("RESULTS IN\n")); DO_DEBUG(options['X'], PrNode(*pnd, 0)); @@ -234,7 +237,8 @@ designator(struct node **pnd;) designator_tail(struct node **pnd;): visible_designator_tail(pnd) - [ + [ %persistent + %default selector(pnd) | visible_designator_tail(pnd) diff --git a/lang/m2/comp/input.c b/lang/m2/comp/input.c index acf29915..48f0525a 100644 --- a/lang/m2/comp/input.c +++ b/lang/m2/comp/input.c @@ -10,16 +10,12 @@ struct f_info file_info; #include "scope.h" #include -extern struct idf *CurrentId; AtEoIF() { /* Make the unstacking of input streams noticable to the lexical analyzer */ - if (CurrentId && ! lookup(CurrentId, GlobalScope)) { -fatal("No definition module read for \"%s\"", CurrentId->id_text); - } return 1; } diff --git a/lang/m2/comp/lookup.c b/lang/m2/comp/lookup.c index 6143502c..599cf77f 100644 --- a/lang/m2/comp/lookup.c +++ b/lang/m2/comp/lookup.c @@ -51,6 +51,38 @@ lookup(id, scope) return df; } +struct def * +NoImportlookup(id, scope) + register struct idf *id; + struct scope *scope; +{ + /* Look up a definition of an identifier in scope "scope". + Make the "def" list self-organizing. + Don't check if the definition is imported! + */ + register struct def *df, *df1; + + /* Look in the chain of definitions of this "id" for one with scope + "scope". + */ + for (df = id->id_def, df1 = 0; + df && df->df_scope != scope; + df1 = df, df = df->next) { /* nothing */ } + + if (df) { + /* Found it + */ + if (df1) { + /* Put the definition in front + */ + df1->next = df->next; + df->next = id->id_def; + id->id_def = df; + } + } + return df; +} + struct def * lookfor(id, vis, give_error) register struct node *id; diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index 2ac8c2e5..9468c466 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -18,6 +18,7 @@ #include "standards.h" #include "tokenname.h" #include "node.h" +#include "warning.h" int state; /* either IMPLEMENTATION or PROGRAM */ char options[128]; @@ -35,6 +36,7 @@ main(argc, argv) register char **Nargv = &argv[0]; ProgName = *argv++; + warning_classes = W_INITIAL; while (--argc > 0) { if (**argv == '-') @@ -78,7 +80,7 @@ Compile(src, dst) open_scope(CLOSEDSCOPE); GlobalScope = CurrentScope; C_init(word_size, pointer_size); - if (! C_open(dst)) fatal("Could not open output file"); + if (! C_open(dst)) fatal("could not open output file"); C_magic(); C_ms_emx(word_size, pointer_size); CompUnit(); @@ -199,7 +201,7 @@ do_SYSTEM() (void) Enter("ADR", D_PROCEDURE, std_type, S_ADR); (void) Enter("TSIZE", D_PROCEDURE, std_type, S_TSIZE); if (!InsertText(SYSTEM, sizeof(SYSTEM) - 1)) { - fatal("Could not insert text"); + fatal("could not insert text"); } DefModule(); close_scope(SC_CHKFORW); diff --git a/lang/m2/comp/misc.c b/lang/m2/comp/misc.c index d945e553..dc589d6f 100644 --- a/lang/m2/comp/misc.c +++ b/lang/m2/comp/misc.c @@ -18,7 +18,7 @@ match_id(id1, id2) first place, and if not, give an error message */ if (id1 != id2 && !is_anon_idf(id1) && !is_anon_idf(id2)) { - error("Name \"%s\" does not match block name \"%s\"", + error("name \"%s\" does not match block name \"%s\"", id1->id_text, id2->id_text ); diff --git a/lang/m2/comp/options.c b/lang/m2/comp/options.c index c66341bd..782c67a5 100644 --- a/lang/m2/comp/options.c +++ b/lang/m2/comp/options.c @@ -8,9 +8,11 @@ #include "type.h" #include "main.h" +#include "warning.h" extern int idfsize; static int ndirs; +int warning_classes; DoOption(text) register char *text; @@ -29,6 +31,41 @@ DoOption(text) */ + case 'w': + if (*text) { + while (*text) { + switch(*text++) { + case 'O': + warning_classes &= ~W_OLDFASHIONED; + break; + case 'R': + warning_classes &= ~W_STRICT; + break; + case 'W': + warning_classes &= ~W_ORDINARY; + break; + } + } + } + else warning_classes = 0; + break; + + case 'W': + while (*text) { + switch(*text++) { + case 'O': + warning_classes |= W_OLDFASHIONED; + break; + case 'R': + warning_classes |= W_STRICT; + break; + case 'W': + warning_classes |= W_ORDINARY; + break; + } + } + break; + case 'M': { /* maximum identifier length */ char *t = text; /* because &text is illegal */ @@ -42,7 +79,7 @@ DoOption(text) case 'I' : if (++ndirs >= NDIRS) { - fatal("Too many -I options"); + fatal("too many -I options"); } DEFPATH[ndirs] = text; break; diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index b6a1d27e..afaeb722 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -15,6 +15,7 @@ #include "type.h" #include "node.h" #include "f_info.h" +#include "warning.h" } /* @@ -62,7 +63,7 @@ priority(arith *pprio;) } : '[' ConstExpression(&nd) ']' { if (!(nd->nd_type->tp_fund & T_CARDINAL)) { - node_error(nd, "Illegal priority"); + node_error(nd, "illegal priority"); } *pprio = nd->nd_INT; FreeNode(nd); @@ -85,23 +86,16 @@ export(int *QUALflag; struct node **ExportList;) import(int local;) { struct node *ImportList; + struct node *FromId = 0; register struct def *df; - int fromid; extern struct def *GetDefinitionModule(); } : [ FROM - IDENT { fromid = 1; - if (local) { - struct node *nd = MkLeaf(Name, &dot); - - df = lookfor(nd,enclosing(CurrVis),0); - FreeNode(nd); - } - else df = GetDefinitionModule(dot.TOK_IDF, 1); + IDENT { FromId = MkLeaf(Name, &dot); + if (local) df = lookfor(FromId,enclosing(CurrVis),0); + else df = GetDefinitionModule(dot.TOK_IDF, 1); } - | - { fromid = 0; } - ] + ]? IMPORT IdentList(&ImportList) ';' /* When parsing a global module, this is the place where we must @@ -109,7 +103,9 @@ import(int local;) If the FROM clause is present, the identifier in it is a module name, otherwise the names in the import list are module names. */ - { if (fromid) EnterFromImportList(ImportList, df); + { if (FromId) { + EnterFromImportList(ImportList, df, FromId); + } else EnterImportList(ImportList, local); } ; @@ -137,7 +133,7 @@ DefinitionModule modules. Issue a warning. */ { -node_warning(exportlist, "export list in definition module ignored"); +node_warning(exportlist, W_ORDINARY, "export list in definition module ignored"); FreeNode(exportlist); } | @@ -161,7 +157,7 @@ definition register struct def *df; struct def *dummy; } : - CONST [ ConstantDeclaration Semicolon ]* + CONST [ ConstantDeclaration ';' ]* | TYPE [ IDENT { df = define(dot.TOK_IDF, CurrentScope, D_TYPE); } @@ -176,21 +172,13 @@ definition df->df_type = construct_type(T_HIDDEN, NULLTYPE); } ] - Semicolon + ';' ]* | - VAR [ VariableDeclaration Semicolon ]* + VAR [ VariableDeclaration ';' ]* | ProcedureHeading(&dummy, D_PROCHEAD) - Semicolon -; - -/* The next nonterminal is used to relax the grammar a little. -*/ -Semicolon: ';' -| - /* empty */ { warning("; expected"); } ; ProgramModule diff --git a/lang/m2/comp/scope.C b/lang/m2/comp/scope.C index fda13e58..d2a26c55 100644 --- a/lang/m2/comp/scope.C +++ b/lang/m2/comp/scope.C @@ -18,6 +18,7 @@ struct scope *PervasiveScope, *GlobalScope; struct scopelist *CurrVis; extern int proclevel; static struct scopelist *PervVis; +extern char options[]; /* STATICALLOCDEF "scope" 10 */ @@ -107,7 +108,7 @@ chk_proc(df) STATIC chk_forw(pdf) - struct def **pdf; + register struct def **pdf; { /* Called at scope close. Look for all forward definitions and if the scope was a closed scope, give an error message for diff --git a/lang/m2/comp/tokenname.c b/lang/m2/comp/tokenname.c index 1e8dd3e3..1de739fd 100644 --- a/lang/m2/comp/tokenname.c +++ b/lang/m2/comp/tokenname.c @@ -92,7 +92,7 @@ reserve(resv) while (resv->tn_symbol) { p = str2idf(resv->tn_name, 0); - if (!p) fatal("Out of Memory"); + if (!p) fatal("out of Memory"); p->id_reserved = resv->tn_symbol; resv++; } diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index 9fc4435c..13fac532 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -107,7 +107,9 @@ align(pos, al) arith pos; int al; { - return ((pos + al - 1) / al) * al; + arith i; + + return pos + ((i = pos % al) ? al - i : 0); } struct type * @@ -209,25 +211,25 @@ chk_basesubrange(tp, base) of "base". */ if (base->sub_lb > tp->sub_lb || base->sub_ub < tp->sub_ub) { - error("Base type has insufficient range"); + error("base type has insufficient range"); } base = base->next; } if (base->tp_fund & (T_ENUMERATION|T_CHAR)) { if (tp->next != base) { - error("Specified base does not conform"); + error("specified base does not conform"); } } else if (base != card_type && base != int_type) { - error("Illegal base for a subrange"); + error("illegal base for a subrange"); } else if (base == int_type && tp->next == card_type && (tp->sub_ub > max_int || tp->sub_ub < 0)) { - error("Upperbound to large for type INTEGER"); + error("upperbound to large for type INTEGER"); } else if (base != tp->next && base != int_type) { - error("Specified base does not conform"); + error("specified base does not conform"); } tp->next = base; @@ -246,7 +248,7 @@ subr_type(lb, ub) register struct type *tp = BaseType(lb->nd_type), *res; if (!TstCompat(lb->nd_type, ub->nd_type)) { - node_error(ub, "Types of subrange bounds not equal"); + node_error(ub, "types of subrange bounds not equal"); return error_type; } @@ -261,14 +263,14 @@ subr_type(lb, ub) /* Check base type */ if (! (tp->tp_fund & T_DISCRETE)) { - node_error(ub, "Illegal base type for subrange"); + node_error(ub, "illegal base type for subrange"); return error_type; } /* Check bounds */ if (lb->nd_INT > ub->nd_INT) { - node_error(ub, "Lower bound exceeds upper bound"); + node_error(ub, "lower bound exceeds upper bound"); } /* Now construct resulting type @@ -361,12 +363,12 @@ set_type(tp) getbounds(tp, &lb, &ub); if (lb < 0 || ub > MAXSET-1) { - error("Set type limits exceeded"); + error("set type limits exceeded"); return error_type; } tp = construct_type(T_SET, tp); - tp->tp_size = WA(((ub - lb) + 8)/8); + tp->tp_size = WA(((ub - lb) + 8) >> 3); return tp; } @@ -406,7 +408,7 @@ ArraySizes(tp) /* check index type */ if (! bounded(index_type)) { - error("Illegal index type"); + error("illegal index type"); tp->tp_size = 0; return; } diff --git a/lang/m2/comp/typequiv.c b/lang/m2/comp/typequiv.c index 0f4e8c3c..9735e0cb 100644 --- a/lang/m2/comp/typequiv.c +++ b/lang/m2/comp/typequiv.c @@ -13,6 +13,7 @@ #include "def.h" #include "LLlex.h" #include "node.h" +#include "warning.h" int TstTypeEquiv(tp1, tp2) @@ -218,7 +219,7 @@ TstParCompat(formaltype, actualtype, VARflag, nd) ( VARflag && ( TstCompat(formaltype, actualtype) && -(node_warning(nd, "oldfashioned! types of formal and actual must be identical"), +(node_warning(nd, W_OLDFASHIONED, "types of formal and actual must be identical"), 1) ) ) diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index 2679b537..1672cf58 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -24,6 +24,7 @@ #include "idf.h" #include "chk_expr.h" #include "walk.h" +#include "warning.h" extern arith NewPtr(); extern arith NewInt(); @@ -147,7 +148,7 @@ WalkProcedure(procedure) DoProfil(); TmpOpen(sc); - func_type = tp = ResultType(procedure->df_type); + func_type = tp = RemoveEqual(ResultType(procedure->df_type)); if (tp && IsConstructed(tp)) { /* The result type of this procedure is constructed. @@ -678,7 +679,7 @@ DoForInit(nd, left) node_error(nd, "type incompatibility in FOR statement"); return 0; } -node_warning(nd, "old-fashioned! compatibility required in FOR statement"); +node_warning(nd, W_OLDFASHIONED, "compatibility required in FOR statement"); } return 1; diff --git a/lang/m2/comp/warning.h b/lang/m2/comp/warning.h new file mode 100644 index 00000000..ee7cc60c --- /dev/null +++ b/lang/m2/comp/warning.h @@ -0,0 +1,18 @@ +/* Warning classes, at the moment three of them: + Strict (R) + Ordinary (W) + Old-fashioned(O) +*/ + +/* Bits for a bit mask: */ + +#define W_ORDINARY 1 +#define W_STRICT 2 +#define W_OLDFASHIONED 4 + +#define W_ALL (W_ORDINARY|W_STRICT|W_OLDFASHIONED) + +#define W_INITIAL (W_ORDINARY | W_OLDFASHIONED) + +/* The bit mask itself: */ +extern int warning_classes; From 20b488059ba6413c3aa91b3a916d0517e5558e6d Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 5 Nov 1986 21:31:23 +0000 Subject: [PATCH 0321/1625] *** empty log message *** --- util/LLgen/lib/rec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/LLgen/lib/rec b/util/LLgen/lib/rec index 3c885044..a8d08352 100644 --- a/util/LLgen/lib/rec +++ b/util/LLgen/lib/rec @@ -57,8 +57,8 @@ LLerror(t) { #ifdef LL_NEWMESS if (t == EOFILE) { - while ((LLsymb = LL_LEXI()) > 0) /* nothing */ ; LLmessage(-1); + while ((LLsymb = LL_LEXI()) > 0) /* nothing */ ; return; } #endif From f136bb04d67c049f681ac94896c350234daa4e98 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 7 Nov 1986 16:01:45 +0000 Subject: [PATCH 0322/1625] Added "register" to a declaration. --- util/LLgen/src/alloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/LLgen/src/alloc.c b/util/LLgen/src/alloc.c index 2e8f2967..2a29733a 100644 --- a/util/LLgen/src/alloc.c +++ b/util/LLgen/src/alloc.c @@ -62,7 +62,7 @@ ralloc(p,size) p_mem p; unsigned size; { } p_mem -new_mem(p) p_info p; { +new_mem(p) register p_info p; { /* This routine implements arrays that can grow. It must be called every time a new element is added to it. @@ -75,7 +75,7 @@ new_mem(p) p_info p; { */ p_mem rp; unsigned sz; - + if (p->i_max >= p->i_top) { /* No more free elements */ sz = p->i_size; p->i_size += p->i_incr * p->i_esize; From 40fe162a04914a64bb9b407999ee0b3c1c917de6 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 7 Nov 1986 16:20:33 +0000 Subject: [PATCH 0323/1625] Constants changed to more sensible values. --- util/LLgen/src/LLgen.g | 4 ++-- util/LLgen/src/name.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/util/LLgen/src/LLgen.g b/util/LLgen/src/LLgen.g index c842ee5b..dbd3ece2 100644 --- a/util/LLgen/src/LLgen.g +++ b/util/LLgen/src/LLgen.g @@ -61,9 +61,9 @@ STATIC p_gram copyrule(); a_init() { term_info.i_esize = sizeof (t_term); - term_info.i_incr = 50; + term_info.i_incr = 100; link_info.i_esize = sizeof (t_link); - link_info.i_incr = 50; + link_info.i_incr = 100; name_init(); } diff --git a/util/LLgen/src/name.c b/util/LLgen/src/name.c index e9b1cf5c..28fdd861 100644 --- a/util/LLgen/src/name.c +++ b/util/LLgen/src/name.c @@ -59,9 +59,9 @@ p_mem new_mem(); name_init() { token_info.i_esize = sizeof (t_token); - token_info.i_incr = 25; + token_info.i_incr = 100; nont_info.i_esize = sizeof (t_nont); - nont_info.i_incr = 25; + nont_info.i_incr = 100; search(TERMINAL,"EOFILE",ENTERING); } From 8f511e95b9594d38601b2cdad20711679d553245 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 7 Nov 1986 17:54:30 +0000 Subject: [PATCH 0324/1625] Avoid a bug in the C-optimizer of 4.1 BSD. --- util/LLgen/src/tokens.g | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/LLgen/src/tokens.g b/util/LLgen/src/tokens.g index 1248a5d3..54c88383 100644 --- a/util/LLgen/src/tokens.g +++ b/util/LLgen/src/tokens.g @@ -117,13 +117,13 @@ scanner() { int reserved = 0; /* reserved word? */ char *max = <ext[LTEXTSZ - 1]; - if (ch = savedtok.t_tokno) { + if (savedtok.t_tokno) { /* A token has been inserted. * Now deliver the last lextoken again */ lextoken = savedtok; savedtok.t_tokno = 0; - return ch; + return lextoken.t_tokno; } for (;;) { ch = input(); From 5346f46c31d0dec5871dd1a9aca023305a632264 Mon Sep 17 00:00:00 2001 From: erikb Date: Mon, 10 Nov 1986 09:14:29 +0000 Subject: [PATCH 0325/1625] use programs and modules from ACK instead of local versions --- lang/cem/cemcom/Makefile.erik | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lang/cem/cemcom/Makefile.erik b/lang/cem/cemcom/Makefile.erik index 4f1c3217..c247c546 100644 --- a/lang/cem/cemcom/Makefile.erik +++ b/lang/cem/cemcom/Makefile.erik @@ -2,9 +2,9 @@ # M A K E F I L E F O R A C K C - C O M P I L E R # Machine and environ dependent definitions -EM = /user1/erikb/em# # ACK tree on this machine +EM = /usr/em# # ACK tree on this machine DESTINATION = /user1/$$USER/bin# # where to put the stuff -MKDEP = /user1/erikb/bin/mkdep# # dependency generator +MKDEP = $(EM)/bin/mkdep# # dependency generator MAP = #MAP = -DInsertFile=ins_file -DInsertText=ins_text# # bug in m68k2 back end SIM = /user1/dick/bin/sim# # Dicks sim program From 00a884b7456cef2aa927ab90038f47d8e0c1d8df Mon Sep 17 00:00:00 2001 From: erikb Date: Mon, 10 Nov 1986 09:16:27 +0000 Subject: [PATCH 0326/1625] corrected the treatment of static functions declared on non-global level --- lang/cem/cemcom/code.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lang/cem/cemcom/code.c b/lang/cem/cemcom/code.c index 665dc38c..696c99b5 100644 --- a/lang/cem/cemcom/code.c +++ b/lang/cem/cemcom/code.c @@ -338,6 +338,10 @@ code_declaration(idf, expr, lvl, sc) /* STATIC, EXTERN, GLOBAL, IMPLICIT, AUTO or REGISTER */ switch (def_sc) { case STATIC: + if (def->df_type->tp_fund == FUNCTION) { + /* should produce "inp $function" ??? */ + break; + } /* they are handled on the spot and get an integer label in EM. */ From ea7fcdfc89c216223bdfac574e9b768672d4b3e1 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 11 Nov 1986 13:34:20 +0000 Subject: [PATCH 0327/1625] Initial revision --- util/cmisc/GCIPM.c | 244 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 244 insertions(+) create mode 100644 util/cmisc/GCIPM.c diff --git a/util/cmisc/GCIPM.c b/util/cmisc/GCIPM.c new file mode 100644 index 00000000..fe2b050a --- /dev/null +++ b/util/cmisc/GCIPM.c @@ -0,0 +1,244 @@ +/*** Generic C Identifier Processing Module ***/ +/* IMPORT CheckId(char *, int), DoOption(char *), BeginOfProgram(), and + EndOfProgram(). +*/ + +#include + +extern CheckId(); +extern DoOption(); +extern BeginOfProgram(), EndOfProgram(); + +#define MAX_ID_LEN 256 + +char *ProgName; +int GCcopy; + +main(argc, argv) + char *argv[]; +{ + char **nargv; + int nargc = 0; + FILE *fp; + + ProgName = *argv++; + nargv = argv; + + BeginOfProgram(); + while (--argc > 0) { + if ((*argv)[0] == '-') { + DoOption(*argv++); + } + else { + nargv[nargc++] = *argv++; + } + } + + if (nargc > 0) { + while (nargc-- > 0) { + if ((fp = fopen(*nargv, "r")) == NULL) { + fprintf(stderr, "%s: cannot read file \"%s\"\n", + ProgName, *nargv); + } + else { + DoFile(fp); + } + nargv++; + } + } + else { + DoFile(stdin); + } + EndOfProgram(); +} + +DoFile(fp) + FILE *fp; +{ + register c; + + while ((c = getc(fp)) != EOF) { + switch (c) { + + case '"': + case '\'': + if (GCcopy) putchar(c); + SkipString(fp, c); + break; + + case '/': + if (GCcopy) putchar(c); + if ((c = getc(fp)) == '*') { + if (GCcopy) putchar(c); + SkipComment(fp); + } + else { + ungetc(c, fp); + } + break; + + default: + if (StartId(c)) { + DoIdent(fp, c); + } + else if (StartNum(c)) { + if (GCcopy) putchar(c); + DoNum(fp, c); + } + else if (GCcopy) putchar(c); + break; + } + } + fclose(fp); +} + +SkipString(fp, stopc) + FILE *fp; +{ + register c; + + while ((c = getc(fp)) != EOF) { + if (GCcopy) putchar(c); + if (c == stopc) { + return; + } + + if (c == '\\') { + c = getc(fp); + if (GCcopy) putchar(c); + } + } +} + +SkipComment(fp) + FILE *fp; +{ + register c; + + while ((c = getc(fp)) != EOF) { + if (GCcopy) putchar(c); + if (c == '*') { + if ((c = getc(fp)) == '/') { + if (GCcopy) putchar(c); + return; + } + ungetc(c, fp); + } + } +} + +DoIdent(fp, s) + FILE *fp; +{ + char id_buf[MAX_ID_LEN]; + register cnt = 1; + register c; + + id_buf[0] = s; + + while ((c = getc(fp)) != EOF) { + if (InId(c)) { + id_buf[cnt++] = c; + } + else { + ungetc(c, fp); + id_buf[cnt] = '\0'; + CheckId(id_buf, cnt); + return; + } + } +} + +StartId(c) +{ + switch (c) { + + case 'a': case 'b': case 'c': case 'd': case 'e': + case 'f': case 'g': case 'h': case 'i': case 'j': + case 'k': case 'l': case 'm': case 'n': case 'o': + case 'p': case 'q': case 'r': case 's': case 't': + case 'u': case 'v': case 'w': case 'x': case 'y': + case 'z': + case 'A': case 'B': case 'C': case 'D': case 'E': + case 'F': case 'G': case 'H': case 'I': case 'J': + case 'K': case 'L': case 'M': case 'N': case 'O': + case 'P': case 'Q': case 'R': case 'S': case 'T': + case 'U': case 'V': case 'W': case 'X': case 'Y': + case 'Z': + case '_': + return 1; + + default: + return 0; + } +} + +InId(c) +{ + switch (c) { + + case 'a': case 'b': case 'c': case 'd': case 'e': + case 'f': case 'g': case 'h': case 'i': case 'j': + case 'k': case 'l': case 'm': case 'n': case 'o': + case 'p': case 'q': case 'r': case 's': case 't': + case 'u': case 'v': case 'w': case 'x': case 'y': + case 'z': + case 'A': case 'B': case 'C': case 'D': case 'E': + case 'F': case 'G': case 'H': case 'I': case 'J': + case 'K': case 'L': case 'M': case 'N': case 'O': + case 'P': case 'Q': case 'R': case 'S': case 'T': + case 'U': case 'V': case 'W': case 'X': case 'Y': + case 'Z': + case '_': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + return 1; + + default: + return 0; + } +} + +StartNum(c) +{ + switch(c) { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + return 1; + } + return 0; +} + +#define inrange(c, l, u) ((unsigned)((c) - (l)) <= ((u) - (l))) +#define isdec(c) inrange(c, '0', '9') +#define isoct(c) inrange(c, '0', '7') +#define ishex(c) (isdec(c) || inrange(c, 'a', 'f') || inrange(c, 'A', 'F')) +#define getdec(c, fp) do { c = getc((fp)); if (GCcopy) putchar(c);} while (isdec(c)) +#define getoct(c, fp) do { c = getc((fp)); if (GCcopy) putchar(c);} while (isoct(c)) +#define gethex(c, fp) do { c = getc((fp)); if (GCcopy) putchar(c);} while (ishex(c)) + +DoNum(fp, c) + register FILE *fp; +{ + if (c != '0') { + getdec(c, fp); + if (c == '.') + getdec(c, fp); + if (c == 'e') { + c = getc(fp); + if (c == '+' || c == '-') + c = getc(fp); + if (isdec(c)) + getdec(c, fp); + } + } + else { + c = getc(fp); + if (GCcopy) putchar(c); + if (c == 'x' || c == 'X') + gethex(c, fp); + else + if (isoct(c)) + getoct(c, fp); + } +} From 6059f82461277cd7abab44a58d61e0631c2c0cae Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 11 Nov 1986 13:42:16 +0000 Subject: [PATCH 0328/1625] Adapted to new versions of programs --- util/cmisc/Makefile | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/util/cmisc/Makefile b/util/cmisc/Makefile index 5d401bee..ea0063a1 100644 --- a/util/cmisc/Makefile +++ b/util/cmisc/Makefile @@ -1,7 +1,8 @@ -EMBIN = ../../bin +EM = ../.. +EMBIN = $(EM)/bin CFLAGS = -O LDFLAGS = -TARGETS = mkdep cid cclash +TARGETS = mkdep cid cclash prid all: $(TARGETS) @@ -14,8 +15,11 @@ clean: mkdep: mkdep.o $(CC) $(LDFLAGS) -o mkdep mkdep.o -cid: cid.o - $(CC) $(LDFLAGS) -o cid cid.o +cid: cid.o GCIPM.o + $(CC) $(LDFLAGS) -o cid cid.o GCIPM.o -cclash: cclash.o - $(CC) $(LDFLAGS) -o cclash cclash.o +cclash: cclash.o GCIPM.o + $(CC) $(LDFLAGS) -o cclash cclash.o GCIPM.o + +prid: prid.o GCIPM.o + $(CC) $(LDFLAGS) -o prid prid.o GCIPM.o From 19c074d2b46dc045150caf6db4f5393edc37de8f Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 11 Nov 1986 13:42:42 +0000 Subject: [PATCH 0329/1625] Adapted to use General C Identifier processing Module (GCIPM). Also changed so that output for "cid" or "cpp" is in alphabetical order. --- util/cmisc/cclash.c | 257 ++++++++------------------------------------ 1 file changed, 46 insertions(+), 211 deletions(-) diff --git a/util/cmisc/cclash.c b/util/cmisc/cclash.c index 850f0b64..237fcd64 100644 --- a/util/cmisc/cclash.c +++ b/util/cmisc/cclash.c @@ -18,9 +18,10 @@ Revised: Wed Jul 23 13:27:16 MDT 1986 by Ceriel Jacobs, replaced "stoi" by "atoi" - Revised: Wed Oct 1 14:23:35 MDT 1986 + Revised: Tue Nov 11 13:32:31 MET 1986 by Ceriel Jacobs, - to produce lists in the order in which they were read. + to produce lists for "cid" or preprocessor in + alphabetical order. */ #include @@ -41,7 +42,7 @@ struct idf { int maxlen = DEF_LENGTH; int action = ACT_LISTONLY; -char *ProgName; +extern char *ProgName; char * keywords[] = { "asm", @@ -77,6 +78,8 @@ char * keywords[] = { 0 }; +struct idf *maplist = 0; + DefineKeys() { register char **pkey = &keywords[0]; @@ -197,7 +200,9 @@ EnHash(id) return hash_val % (unsigned) HASHSIZE; } -Results() +BeginOfProgram() { } + +EndOfProgram() { register int i; register struct idf *idp, *p; @@ -230,15 +235,44 @@ Results() case ACT_CID: case ACT_MAPFILE: - if (idp->id_key == 0) - mapline(idp->id_name); - for (p = idp->id_same; p; p = p->id_same) + for (p = idp->id_same; p;) { + register struct idf *q = p->id_same; + if (p->id_key == 0) - mapline(p->id_name); + saveline(p); + p = q; + } + if (idp->id_key == 0) + saveline(idp); break; } } } + switch(action) { + case ACT_CID: + case ACT_MAPFILE: + for (idp = maplist; idp; idp = idp->id_same) { + mapline(idp->id_name); + } + } +} + +saveline(p) + register struct idf *p; +{ + register struct idf *idp = maplist, *idp1 = 0; + + while (idp && strcmp(idp->id_name, p->id_name) < 0) { + idp1 = idp; + idp = idp->id_same; + } + p->id_same = idp; + if (idp1 == 0) { + maplist = p; + } + else { + idp1->id_same = p; + } } mapline(nm) @@ -258,208 +292,9 @@ mapline(nm) } } -#define MAX_ID_LEN 256 - -main(argc, argv) - char *argv[]; +CheckId(id, s) + char *id; { - char **nargv; - int nargc = 0; - FILE *fp; - - ProgName = *argv++; - nargv = argv; - - while (--argc > 0) - if ((*argv)[0] == '-') - DoOption(*argv++); - else - nargv[nargc++] = *argv++; - - DefineKeys(); - if (nargc > 0) - while (nargc-- > 0) { - if ((fp = fopen(*nargv, "r")) == NULL) - fprintf(stderr, "%s: cannot read file \"%s\"\n", - ProgName, *nargv); - else - DoFile(fp); - nargv++; - } - else - DoFile(stdin); - Results(); - return 0; -} - -DoFile(fp) - FILE *fp; -{ - register c; - - while ((c = getc(fp)) != EOF) - switch (c) { - - case '"': - case '\'': - SkipString(fp, c); - break; - - case '/': - if ((c = getc(fp)) == '*') - SkipComment(fp); - else - ungetc(c, fp); - break; - - default: - if (StartId(c)) - DoIdent(fp, c); - else - if (StartNum(c)) - DoNum(fp, c); - break; - } - - fclose(fp); -} - -SkipString(fp, stopc) - FILE *fp; -{ - register c; - - while ((c = getc(fp)) != EOF) { - if (c == stopc) - return; - if (c == '\\') - c = getc(fp); - } -} - -SkipComment(fp) - FILE *fp; -{ - register c; - - while ((c = getc(fp)) != EOF) - if (c == '*') { - if ((c = getc(fp)) == '/') - return; - ungetc(c, fp); - } -} - -DoIdent(fp, s) - FILE *fp; -{ - char id_buf[MAX_ID_LEN]; - register cnt = 1; - register c; - - id_buf[0] = s; - - while ((c = getc(fp)) != EOF) - if (InId(c)) - id_buf[cnt++] = c; - else { - ungetc(c, fp); - id_buf[cnt] = '\0'; - if (cnt >= maxlen) - InsertId(&id_buf[0], 0); - return; - } -} - -#define inrange(c, l, u) ((unsigned)((c) - (l)) <= ((u) - (l))) -#define isdec(c) inrange(c, '0', '9') -#define isoct(c) inrange(c, '0', '7') -#define ishex(c) (isdec(c) || inrange(c, 'a', 'f') || inrange(c, 'A', 'F')) -#define getdec(c, fp) do c = getc((fp)); while (isdec(c)) -#define getoct(c, fp) do c = getc((fp)); while (isoct(c)) -#define gethex(c, fp) do c = getc((fp)); while (ishex(c)) - -DoNum(fp, c) - FILE *fp; -{ - if (c != '0') { - getdec(c, fp); - if (c == '.') - getdec(c, fp); - if (c == 'e') { - c = getc(fp); - if (c == '+' || c == '-') - c = getc(fp); - if (isdec(c)) - getdec(c, fp); - } - } - else { - c = getc(fp); - if (c == 'x' || c == 'X') - gethex(c, fp); - else - if (isoct(c)) - getoct(c, fp); - } -} - -StartId(c) -{ - switch (c) { - - case 'a': case 'b': case 'c': case 'd': case 'e': - case 'f': case 'g': case 'h': case 'i': case 'j': - case 'k': case 'l': case 'm': case 'n': case 'o': - case 'p': case 'q': case 'r': case 's': case 't': - case 'u': case 'v': case 'w': case 'x': case 'y': - case 'z': - case 'A': case 'B': case 'C': case 'D': case 'E': - case 'F': case 'G': case 'H': case 'I': case 'J': - case 'K': case 'L': case 'M': case 'N': case 'O': - case 'P': case 'Q': case 'R': case 'S': case 'T': - case 'U': case 'V': case 'W': case 'X': case 'Y': - case 'Z': - case '_': - return 1; - - default: - return 0; - } -} - -StartNum(c) -{ - switch(c) { - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - return 1; - } - return 0; -} - -InId(c) -{ - switch (c) { - - case 'a': case 'b': case 'c': case 'd': case 'e': - case 'f': case 'g': case 'h': case 'i': case 'j': - case 'k': case 'l': case 'm': case 'n': case 'o': - case 'p': case 'q': case 'r': case 's': case 't': - case 'u': case 'v': case 'w': case 'x': case 'y': - case 'z': - case 'A': case 'B': case 'C': case 'D': case 'E': - case 'F': case 'G': case 'H': case 'I': case 'J': - case 'K': case 'L': case 'M': case 'N': case 'O': - case 'P': case 'Q': case 'R': case 'S': case 'T': - case 'U': case 'V': case 'W': case 'X': case 'Y': - case 'Z': - case '_': - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - return 1; - - default: - return 0; - } + if (s >= maxlen) + InsertId(id, 0); } From 93f7e9f4de57344b8e3e5661a7a5d1c0d59e1a24 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 11 Nov 1986 13:44:13 +0000 Subject: [PATCH 0330/1625] Adapted to use of GCIPM. --- util/cmisc/cid.c | 213 +++-------------------------------------------- 1 file changed, 13 insertions(+), 200 deletions(-) diff --git a/util/cmisc/cid.c b/util/cmisc/cid.c index f8da1acf..5a400982 100644 --- a/util/cmisc/cid.c +++ b/util/cmisc/cid.c @@ -1,5 +1,3 @@ -/* @cc % $LIBDIR/stoi.o -o cid@ */ - /* Change IDentifiers occurring in C programs outside comment, strings and character constants. -Dname=text : replace all occerences of name by text @@ -10,206 +8,8 @@ Date: Oct 23, 1985 */ - -/*** Generic C Identifier Processing Module ***/ -/* IMPORT CheckId(char *) and DoOption(char *, int) -*/ - #include -extern CheckId(); -extern DoOption(); - -#define MAX_ID_LEN 256 - -char *ProgName; - -main(argc, argv) - char *argv[]; -{ - char **nargv; - int nargc = 0; - FILE *fp; - - ProgName = *argv++; - nargv = argv; - - while (--argc > 0) { - if ((*argv)[0] == '-') { - DoOption(*argv++); - } - else { - nargv[nargc++] = *argv++; - } - } - - if (nargc > 0) { - while (nargc-- > 0) { - if ((fp = fopen(*nargv, "r")) == NULL) { - fprintf(stderr, "%s: cannot read file \"%s\"\n", - ProgName, *nargv); - } - else { - DoFile(fp); - } - nargv++; - } - } - else { - DoFile(stdin); - } - return 0; -} - -DoFile(fp) - FILE *fp; -{ - register c; - - while ((c = getc(fp)) != EOF) { - switch (c) { - - case '"': - case '\'': - SkipString(fp, c); - break; - - case '/': - if ((c = getc(fp)) == '*') { - SkipComment(fp); - } - else { - putchar('/'); - ungetc(c, fp); - } - break; - - default: - if (StartId(c)) { - DoIdent(fp, c); - } - else - putchar(c); - break; - } - } - fclose(fp); -} - -SkipString(fp, stopc) - FILE *fp; -{ - register c; - - putchar(stopc); - while ((c = getc(fp)) != EOF) { - if (c == stopc) { - putchar(stopc); - return; - } - - if (c == '\\') { - putchar(c); - c = getc(fp); - } - putchar(c); - } -} - -SkipComment(fp) - FILE *fp; -{ - register c; - - putchar('/'); - putchar('*'); - while ((c = getc(fp)) != EOF) { - if (c == '*') { - putchar('*'); - if ((c = getc(fp)) == '/') { - putchar('/'); - return; - } - ungetc(c, fp); - } - else - putchar(c); - } -} - -DoIdent(fp, s) - FILE *fp; -{ - char id_buf[MAX_ID_LEN]; - register cnt = 1; - register c; - - id_buf[0] = s; - - while ((c = getc(fp)) != EOF) { - if (InId(c)) { - id_buf[cnt++] = c; - } - else { - ungetc(c, fp); - id_buf[cnt] = '\0'; - CheckId(id_buf, cnt); - return; - } - } -} - -StartId(c) -{ - switch (c) { - - case 'a': case 'b': case 'c': case 'd': case 'e': - case 'f': case 'g': case 'h': case 'i': case 'j': - case 'k': case 'l': case 'm': case 'n': case 'o': - case 'p': case 'q': case 'r': case 's': case 't': - case 'u': case 'v': case 'w': case 'x': case 'y': - case 'z': - case 'A': case 'B': case 'C': case 'D': case 'E': - case 'F': case 'G': case 'H': case 'I': case 'J': - case 'K': case 'L': case 'M': case 'N': case 'O': - case 'P': case 'Q': case 'R': case 'S': case 'T': - case 'U': case 'V': case 'W': case 'X': case 'Y': - case 'Z': - case '_': - return 1; - - default: - return 0; - } -} - -InId(c) -{ - switch (c) { - - case 'a': case 'b': case 'c': case 'd': case 'e': - case 'f': case 'g': case 'h': case 'i': case 'j': - case 'k': case 'l': case 'm': case 'n': case 'o': - case 'p': case 'q': case 'r': case 's': case 't': - case 'u': case 'v': case 'w': case 'x': case 'y': - case 'z': - case 'A': case 'B': case 'C': case 'D': case 'E': - case 'F': case 'G': case 'H': case 'I': case 'J': - case 'K': case 'L': case 'M': case 'N': case 'O': - case 'P': case 'Q': case 'R': case 'S': case 'T': - case 'U': case 'V': case 'W': case 'X': case 'Y': - case 'Z': - case '_': - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - return 1; - - default: - return 0; - } -} -/*** end of GCIPM ***/ - #ifndef DEF_LENGTH #define DEF_LENGTH 8 #endif @@ -229,6 +29,8 @@ struct idf *hash_tab[HASHSIZE]; char *Malloc(), *Salloc(); struct idf *FindId(); +extern char *ProgName; + DoOption(str) char *str; { @@ -386,3 +188,14 @@ EnHash(id) return hash_val % (unsigned) HASHSIZE; } + +extern int GCcopy; + +BeginOfProgram() +{ + GCcopy = 1; +} + +EndOfProgram() +{ +} From 8adf908bc6091604960d3c163bd44192ee2c40d1 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 11 Nov 1986 13:44:58 +0000 Subject: [PATCH 0331/1625] Initial revision --- util/cmisc/prid.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 util/cmisc/prid.c diff --git a/util/cmisc/prid.c b/util/cmisc/prid.c new file mode 100644 index 00000000..99ce5bd6 --- /dev/null +++ b/util/cmisc/prid.c @@ -0,0 +1,129 @@ +/* Print IDentifiers occurring in C programs outside comment, strings + and character constants. + Flags: + -l : print identifiers of or more characters + (default = 8) + + Author: Erik Baalbergen + Date: Oct 23, 1985 +*/ + +#include + +extern char *ProgName; + +#ifndef DEF_LENGTH +#define DEF_LENGTH 8 +#endif + +int maxlen = DEF_LENGTH; + +BeginOfProgram() {} + +DoOption(str) + char *str; +{ + switch (str[1]) { + + case 'l': + if ((maxlen = atoi(&str[2])) <= 0) { + fprintf(stderr, "%s: option \"-l%s\" ignored\n", + ProgName, &str[2]); + maxlen = DEF_LENGTH; + } + break; + + default: + fprintf(stderr, "%s: bad option \"%s\"\n", ProgName, str); + break; + } +} + +CheckId(id, len) + char *id; +{ + if (len >= maxlen) { + InsertId(id); + } +} + +#define HASHSIZE 257 + +struct idf { + char *id_name; + struct idf *id_next; +}; + +struct idf *hash_tab[HASHSIZE]; + +char *Malloc(), *Salloc(); + +InsertId(id) + char *id; +{ + int hash_val = EnHash(id); + register struct idf *idp = hash_tab[hash_val]; + register struct idf *p = 0; + + while (idp && strcmp(idp->id_name, id)) { + p = idp; + idp = idp->id_next; + } + + if (idp == 0) { + idp = (struct idf *) Malloc(sizeof(struct idf)); + idp->id_next = 0; + if (!p) hash_tab[hash_val] = idp; + else p->id_next = idp; + idp->id_name = Salloc(id); + } +} + +char * +Malloc(n) + unsigned n; +{ + char *mem, *malloc(); + + if ((mem = malloc(n)) == 0) { + fprintf(stderr, "%s: out of memory\n", ProgName); + exit(1); + } + return mem; +} + +char * +Salloc(str) + char *str; +{ + char *strcpy(); + + if (str == 0) + str = ""; + + return strcpy(Malloc(strlen(str) + 1), str); +} + +EnHash(id) + char *id; +{ + register unsigned hash_val = 0; + register n = maxlen; + + while (n-- && *id) + hash_val = 31 * hash_val + *id++; + + return hash_val % (unsigned) HASHSIZE; +} + +EndOfProgram() +{ + register struct idf *idp; + register int i; + + for (i = 0; i < HASHSIZE; i++) { + for (idp = hash_tab[i]; idp; idp = idp->id_next) { + printf("%s\n", idp->id_name); + } + } +} From c6a5bb46edd9a149cc03b49242cbaf9501fa7002 Mon Sep 17 00:00:00 2001 From: erikb Date: Tue, 11 Nov 1986 13:47:58 +0000 Subject: [PATCH 0332/1625] merged the vax and mantra versions --- lang/cem/cemcom/cem.c | 301 ++++++++++++++++++++++-------------------- 1 file changed, 158 insertions(+), 143 deletions(-) diff --git a/lang/cem/cemcom/cem.c b/lang/cem/cemcom/cem.c index 7f8a3495..8a3d2e8b 100644 --- a/lang/cem/cemcom/cem.c +++ b/lang/cem/cemcom/cem.c @@ -1,11 +1,13 @@ /* $Header$ */ /* - Driver for the CEMCOM compiler: works like /bin/cc and accepts the - options accepted by /bin/cc and /usr/em/bin/ack. + Driver for the CEMCOM compiler: works like /bin/cc and accepts + most of the options accepted by /bin/cc and /usr/em/bin/ack. Date written: dec 4, 1985 + Adapted for 68000 (Aug 19, 1986) + Merged the vax and mantra versions (Nov 10, 1986) Author: Erik Baalbergen */ - + #include #include #include @@ -22,29 +24,43 @@ struct arglist { /* some system-dependent variables */ char *PP = "/lib/cpp"; -char *CEM = "/user1/erikb/bin/cemcom"; -char *AS_FIX = "/user1/erikb/bin/mcomm"; +char *CEM = "/usr/em/lib/em_cemcom"; char *ENCODE = "/usr/em/lib/em_encode"; char *DECODE = "/usr/em/lib/em_decode"; char *OPT = "/usr/em/lib/em_opt"; -char *CG = "/usr/em/lib/vax4/cg"; -char *AS = "/bin/as"; -char *LD = "/bin/ld"; char *SHELL = "/bin/sh"; +#ifndef MANTRA +char *CG = "/usr/em/lib/vax4/cg"; +char *AS = "/bin/as"; +char *AS_FIX = "/user1/erikb/bin/mcomm"; +char *LD = "/bin/ld"; char *LIBDIR = "/user1/cem/lib"; - char *V_FLAG = "-Vs2.2w4.4i4.4l4.4f4.4d8.4p4.4"; +#else MANTRA +char *CG = "/usr/em/lib/m68k2/cg"; +char *AS = "/usr/em/lib/m68k2/as"; +char *LD = "/usr/em/lib/em_led"; +char *CV = "/usr/em/lib/m68k2/cv"; +char *LIBDIR = "/usr/em/lib/m68k2"; +char *V_FLAG = "-Vs2.2w2.2i2.2l4.2f4.2d8.2p4.2"; +#endif MANTRA struct arglist LD_HEAD = { 2, { +#ifndef MANTRA "/usr/em/lib/vax4/head_em", "/usr/em/lib/vax4/head_cc" +#else MANTRA + "/usr/em/lib/m68k2/head_em", + "/usr/em/lib/m68k2/head_cc" +#endif MANTRA } }; struct arglist LD_TAIL = { +#ifndef MANTRA 4, { "/user1/cem/lib/libc.a", @@ -52,11 +68,26 @@ struct arglist LD_TAIL = { "/usr/em/lib/vax4/tail_mon", "/usr/em/lib/vax4/tail_em" } +#else MANTRA + 7, + { + "/usr/em/lib/m68k2/tail_cc.1s", + "/usr/em/lib/m68k2/tail_cc.2g", + "/usr/em/lib/m68k2/tail_cem", + "/usr/em/lib/m68k2/tail_fp.a", + "/usr/em/lib/m68k2/tail_em.rt", + "/usr/em/lib/m68k2/tail_mon", + "/usr/em/lib/m68k2/end_em" + } +#endif MANTRA }; char *o_FILE = "a.out"; +#ifdef MANTRA +char *cv_FILE = "cv.out"; +#endif MANTRA -#define remove(str) (((t_flag == 0) && unlink(str)), (str)[0] = '\0') +#define remove(str) (((FLAG(t) == 0) && unlink(str)), (str)[0] = '\0') #define cleanup(str) (str && remove(str)) #define mkname(dst, s1, s2) mkstr(dst, (s1), (s2), 0) #define init(al) (al)->al_argc = 1 @@ -64,42 +95,34 @@ char *o_FILE = "a.out"; mkstr(alloc((unsigned int)strlen(nm) + strlen(LIBDIR) + 7), \ LIBDIR, "/lib", nm, ".a", 0) -char *ProgCall = 0; +struct arglist SRCFILES, LDFILES, GEN_LDFILES, PP_FLAGS, CEM_FLAGS, + OPT_FLAGS, DECODE_FLAGS, ENCODE_FLAGS, CG_FLAGS, AS_FLAGS, + O_FLAGS, DEBUG_FLAGS, CALL_VEC; -struct arglist SRCFILES; -struct arglist LDFILES; -struct arglist GEN_LDFILES; - -struct arglist PP_FLAGS; -struct arglist CEM_FLAGS; - -int debug = 0; -int exec = 1; - -int RET_CODE = 0; - -struct arglist OPT_FLAGS; -struct arglist DECODE_FLAGS; -struct arglist ENCODE_FLAGS; -struct arglist CG_FLAGS; -struct arglist AS_FLAGS; +#ifndef MANTRA struct arglist LD_FLAGS; -struct arglist O_FLAGS; -struct arglist DEBUG_FLAGS; +#else MANTRA +struct arglist LD_FLAGS = { + 5, + { + "-b0:0x80000", + "-a0:2", + "-a1:2", + "-a2:2", + "-a3:2" + } +}; +struct arglist CV_FLAGS; +int Nc_flag = 0; +#endif MANTRA -struct arglist CALL_VEC; - -int e_flag = 0; -int E_flag = 0; -int c_flag = 0; -int k_flag = 0; -int m_flag = 0; -int o_flag = 0; -int S_flag = 0; -int t_flag = 0; -int v_flag = 0; -int P_flag = 0; +/* option naming */ +#define NAME(chr) chr +#define FLAG(chr) NAME(chr)_flag +int E_flag, P_flag, S_flag, c_flag, e_flag, k_flag, + m_flag, o_flag, t_flag, v_flag; +/* various passes */ struct prog { char *p_name; char **p_task; @@ -114,87 +137,83 @@ struct prog { { "cg", &CG, &CG_FLAGS }, { "as", &AS, &AS_FLAGS }, { "ld", &LD, &LD_FLAGS }, +#ifdef MANTRA + { "cv", &CV, &CV_FLAGS }, +#endif MANTRA { 0, 0, 0 } }; +/* various forward declarations */ int trap(); char *mkstr(); char *alloc(); long sizeof_file(); +/* various globals */ +char *ProgCall = 0; +int debug = 0; +int exec = 1; +int RET_CODE = 0; + main(argc, argv) char *argv[]; { - char *str; - char **argvec; - int count; - int ext; - char Nfile[USTR_SIZE]; - char kfile[USTR_SIZE]; - char sfile[USTR_SIZE]; - char mfile[USTR_SIZE]; - char ofile[USTR_SIZE]; + char *str, **argvec, *file, *ldfile = 0; + int count, ext; + char Nfile[USTR_SIZE], kfile[USTR_SIZE], sfile[USTR_SIZE], + mfile[USTR_SIZE], ofile[USTR_SIZE], BASE[USTR_SIZE]; register struct arglist *call = &CALL_VEC; - char BASE[USTR_SIZE]; - char *file; - char *ldfile = 0; set_traps(trap); - ProgCall = *argv++; - while (--argc > 0) { if (*(str = *argv++) != '-') { append(&SRCFILES, str); continue; } - switch (str[1]) { - case '-': switch (str[2]) { case 'C': case 'E': case 'P': - E_flag = 1; + FLAG(E) = 1; append(&PP_FLAGS, str); PP = CEM; - P_flag = (str[2] == 'P'); + FLAG(P) = (str[2] == 'P'); break; default: append(&DEBUG_FLAGS, str); break; } break; - case 'B': PP = CEM = &str[2]; break; case 'C': case 'E': case 'P': - E_flag = 1; + FLAG(E) = 1; append(&PP_FLAGS, str); - P_flag = (str[1] == 'P'); + FLAG(P) = (str[1] == 'P'); break; case 'c': if (str[2] == '.') { switch (str[3]) { - case 's': - S_flag = 1; + FLAG(S) = 1; break; case 'k': - k_flag = 1; + FLAG(k) = 1; break; case 'o': - c_flag = 1; + FLAG(c) = 1; break; case 'm': - m_flag = 1; + FLAG(m) = 1; break; case 'e': - e_flag = 1; + FLAG(e) = 1; break; default: bad_option(str); @@ -202,7 +221,7 @@ main(argc, argv) } else if (str[2] == '\0') - c_flag = 1; + FLAG(c) = 1; else bad_option(str); break; @@ -212,7 +231,7 @@ main(argc, argv) append(&PP_FLAGS, str); break; case 'k': - k_flag = 1; + FLAG(k) = 1; break; case 'l': if (str[2] == '\0') /* no standard libraries */ @@ -224,10 +243,24 @@ main(argc, argv) LIBDIR = &str[2]; break; case 'm': - m_flag = 1; + FLAG(m) = 1; break; +#ifdef MANTRA + case 'N': + switch (str[2]) { + case 'c': /* no a.out conversion */ + Nc_flag = 1; + break; + case 'l': /* no default options to led */ + LD_FLAGS.al_argc = 0; + break; + default: + bad_option(str); + } + break; +#endif MANTRA case 'o': - o_flag = 1; + FLAG(o) = 1; if (argc-- < 0) bad_option(str); else @@ -246,58 +279,42 @@ main(argc, argv) Roption(str); break; case 'S': - S_flag = 1; + FLAG(S) = 1; break; case 't': - t_flag = 1; + FLAG(t) = 1; break; case 'v': /* set debug switches */ - v_flag = 1; + FLAG(v) = 1; switch (str[2]) { - case 'd': debug = 1; break; case 'n': /* no execute */ exec = 0; break; + case '\0': + break; + default: + bad_option(str); } break; case 'V': V_FLAG = str; break; - case 'e': - case 'F': - case 'd': - case 'n': - case 'N': - case 'r': - case 's': - case 'u': - case 'x': - case 'X': - case 'z': - append(&LD_FLAGS, str); - break; default: - append(&CEM_FLAGS, str); + append(&LD_FLAGS, str); } } - - if (debug) - report("Note: debug output"); + if (debug) report("Note: debug output"); if (exec == 0) report("Note: no execution"); - count = SRCFILES.al_argc; argvec = &(SRCFILES.al_argv[0]); - Nfile[0] = '\0'; - while (count-- > 0) { basename(file = *argvec++, BASE); - - if (E_flag) { + if (FLAG(E)) { char ifile[USTR_SIZE]; init(call); @@ -305,12 +322,10 @@ main(argc, argv) concat(call, &DEBUG_FLAGS); concat(call, &PP_FLAGS); append(call, file); - runvec(call, P_flag ? mkname(ifile, BASE, ".i") : 0); + runvec(call, FLAG(P) ? mkname(ifile, BASE, ".i") : 0); continue; } - ext = extension(file); - /* .c to .k and .N */ if (ext == 'c' || ext == 'i') { init(call); @@ -322,7 +337,6 @@ main(argc, argv) append(call, file); append(call, mkname(kfile, BASE, ".k")); append(call, mkname(Nfile, BASE, ".N")); - if (runvec(call, (char *)0)) { file = kfile; ext = 'k'; @@ -335,7 +349,6 @@ main(argc, argv) continue; } } - /* .e to .k */ if (ext == 'e') { init(call); @@ -348,14 +361,11 @@ main(argc, argv) file = kfile; ext = 'k'; } - - if (k_flag) + if (FLAG(k)) continue; - /* decode .k or .m */ - if (e_flag && (ext == 'k' || ext == 'm')) { + if (FLAG(e) && (ext == 'k' || ext == 'm')) { char efile[USTR_SIZE]; - init(call); append(call, DECODE); concat(call, &DECODE_FLAGS); @@ -365,7 +375,6 @@ main(argc, argv) cleanup(kfile); continue; } - /* .k to .m */ if (ext == 'k') { init(call); @@ -378,10 +387,8 @@ main(argc, argv) ext = 'm'; cleanup(kfile); } - - if (m_flag) + if (FLAG(m)) continue; - /* .m to .s */ if (ext == 'm') { init(call); @@ -392,29 +399,32 @@ main(argc, argv) if (runvec(call, (char *)0) == 0) continue; if (Nfile[0] != '\0') { +#ifndef MANTRA init(call); append(call, AS_FIX); append(call, Nfile); append(call, sfile); runvec(call, (char *)0); +#endif MANTRA remove(Nfile); } cleanup(mfile); file = sfile; ext = 's'; } - - if (S_flag) + if (FLAG(S)) continue; - /* .s to .o */ if (ext == 's') { - ldfile = c_flag ? + ldfile = FLAG(c) ? ofile : alloc((unsigned)strlen(BASE) + 3); init(call); append(call, AS); concat(call, &AS_FLAGS); +#ifdef MANTRA + append(call, "-"); +#endif MANTRA append(call, "-o"); append(call, mkname(ldfile, BASE, ".o")); append(call, file); @@ -424,24 +434,25 @@ main(argc, argv) ext = 'o'; cleanup(sfile); } - - if (c_flag) + if (FLAG(c)) continue; - append(&LDFILES, file); if (ldfile) { append(&GEN_LDFILES, ldfile); ldfile = 0; } } - /* *.o to a.out */ if (RET_CODE == 0 && LDFILES.al_argc > 0) { init(call); append(call, LD); concat(call, &LD_FLAGS); append(call, "-o"); +#ifndef MANTRA append(call, o_FILE); +#else MANTRA + append(call, Nc_flag ? o_FILE : cv_FILE); +#endif MANTRA concat(call, &LD_HEAD); concat(call, &LDFILES); concat(call, &LD_TAIL); @@ -450,29 +461,40 @@ main(argc, argv) while (i-- > 0) remove(GEN_LDFILES.al_argv[i]); +#ifdef MANTRA + /* convert to local a.out format */ + if (Nc_flag == 0) { + init(call); + append(call, CV); + concat(call, &CV_FLAGS); + append(call, cv_FILE); + append(call, o_FILE); + if (runvec(call, (char *)0)) + remove(cv_FILE); + } +#endif MANTRA } } - exit(RET_CODE); } +#define BUFSIZE (USTR_SIZE * MAXARGC) +char alloc_buf[BUFSIZE]; char * alloc(u) unsigned u; { -#define BUFSIZE (USTR_SIZE * MAXARGC) - static char buf[BUFSIZE]; - static char *bufptr = &buf[0]; + static char *bufptr = &alloc_buf[0]; register char *p = bufptr; - if ((bufptr += u) >= &buf[BUFSIZE]) + if ((bufptr += u) >= &alloc_buf[BUFSIZE]) panic("no space"); return p; } append(al, arg) - struct arglist *al; + register struct arglist *al; char *arg; { if (al->al_argc >= MAXARGC) @@ -483,7 +505,7 @@ append(al, arg) concat(al1, al2) struct arglist *al1, *al2; { - register i = al2->al_argc; + register int i = al2->al_argc; register char **p = &(al1->al_argv[al1->al_argc]); register char **q = &(al2->al_argv[0]); @@ -520,9 +542,8 @@ Roption(str) char *prog, *arg; char bc; char *cindex(); - - prog = &str[2]; + prog = &str[2]; if (eq = cindex(prog, '=')) bc = '='; else @@ -532,17 +553,14 @@ Roption(str) bad_option(str); return; } - *eq++ = '\0'; if (arg = eq) { char *opt = 0; struct prog *pp = &ProgParts[0]; - if (bc == '-') { + if (bc == '-') opt = mkstr(alloc((unsigned)strlen(arg) + 2), "-", arg, 0); - } - while (pp->p_name) { if (strcmp(prog, pp->p_name) == 0) { if (opt) @@ -570,7 +588,7 @@ basename(str, dst) p1--; if (*--p1 == '.') *p1 = '\0'; - while (*dst++ = *p2++); + while (*dst++ = *p2++) {} *p1 = '.'; } @@ -580,7 +598,7 @@ extension(fn) { char c; - while (*fn++) ; + while (*fn++) {} fn--; c = *--fn; return (*--fn == '.') ? c : 0; @@ -625,30 +643,27 @@ runvec(vec, outp) char *task = vec->al_argv[1]; vec->al_argv[vec->al_argc] = 0; - if (v_flag) + if (FLAG(v)) print_vec(vec); if (exec == 0) return 1; if (fork() == 0) { /* start up the process */ extern int errno; - if (outp) { /* redirect standard output */ + close(1); if ((fd = creat(outp, 0666)) < 0) panic("cannot create %s", outp); - if (dup2(fd, 1) == -1) - panic("dup failure"); - close(fd); + if (fd != 1) + panic("illegal redirection"); } if (debug) report("exec %s", task); execv(task, &(vec->al_argv[1])); - /* not an a.out file, let's try it with the SHELL */ if (debug) report("try it with %s", SHELL); if (errno == ENOEXEC) { vec->al_argv[0] = SHELL; execv(SHELL, &(vec->al_argv[0])); } - /* failed, so ... */ panic("cannot execute %s", task); exit(1); From 830cebff5adc37837a5838b234873b33c6ad1502 Mon Sep 17 00:00:00 2001 From: erikb Date: Wed, 12 Nov 1986 09:53:18 +0000 Subject: [PATCH 0333/1625] updated the manual pages --- lang/cem/cemcom/cem.1 | 98 ++++++++++++++++------------------------ lang/cem/cemcom/cemcom.1 | 17 ++----- 2 files changed, 43 insertions(+), 72 deletions(-) diff --git a/lang/cem/cemcom/cem.1 b/lang/cem/cemcom/cem.1 index 93093514..ea79f3aa 100644 --- a/lang/cem/cemcom/cem.1 +++ b/lang/cem/cemcom/cem.1 @@ -1,4 +1,4 @@ -.TH CEM 1L 86/03/10 +.TH CEM 1L 86/11/12 .SH NAME cem \- ACK C compiler .SH SYNOPSIS @@ -24,9 +24,9 @@ C source code .IP .e EM assembler source file. .IP .k -compact EM file, not yet optimised by the EM peephole optimiser. +compact EM file, not yet optimized by the EM peephole optimizer. .IP .m -compact EM file, already optimised by the peephole optimiser. +compact EM file, already optimized by the peephole optimizer. .IP .s assembler file. .LP @@ -41,9 +41,7 @@ and .I ack (?) are interpreted by .I cem . -(The options not specified here are passed to the front-end -compiler -.I cemcom (1L).) +(The options not specified here are passed to the loader.) .IP \fB\-B\fP\fIname\fP Use .I name @@ -72,6 +70,21 @@ in \fB\-I\fP options, then in directories on a standard list (which in fact consists of "/usr/include"). .IP \fB\-L\fP\fIdir\fP Use \fIdir\fP as library-containing directory instead of the default. +.IP \fB\-N\fP\fIc\fP +Only effective if ACK pipeline is used. +This option causes some default actions and options to be suppressed, according +to +.I c : +.RS +.IP \fBc\fP +do not convert from EM a.out to local a.out format (i.e., skip the +.B cv +pass.) +.IP \fBl\fP +do not pass the default loader flags to the +.B ld +pass. +.RE .IP \fB\-P\fP Same as \fB\-E\fP, but sending the result of input file \fIfile\fP\fB.[ceis]\fP to \fIfile\fP\fB.i\fP. @@ -85,24 +98,25 @@ the default. \&\fIProg\fP is one of the following names: .RS .IP \fBcpp\fP -macro preprocessor (default: /lib/cpp) +macro preprocessor .IP \fBcem\fP -front\-end compiler (default: $CEM/bin/cemcom) +front\-end compiler .IP \fBopt\fP -EM peephole optimiser (default: $EM/lib/em_opt) +EM peephole optimizer .IP \fBdecode\fP -EM compact to EM assembler translator (default: $EM/lib/em_decode) +EM compact to EM assembler translator .IP \fBencode\fP -EM assembler to EM compact translator (default: $EM/lib/em_encode) +EM assembler to EM compact translator .IP \fBbe\fP EM compact code to target\-machine assembly code compiler -(default: $EM/lib/vax4/cg) .IP \fBcg\fP same as \fBbe\fP .IP \fBas\fP -assembler (default: /bin/as) +assembler .IP \fBld\fP -linker/loader (default: /bin/ld) +linker/loader +.IP \fBcv\fP +a.out format converting program (only if ACK pipeline is used) .RE .IP \fB\-R\fP\fIprog\fP\fB\-\fP\fIoption\fP .br @@ -130,17 +144,17 @@ This option is passed directly to \fIcemcom\fP(1). .IP \fB\-c\fP Same as \fB\-c.o\fP. .IP \fB\-c.e\fP -Produce EM assembly code on \fIfile\fP\fB.e\fP for the +Produce human-readable EM assembly code on \fIfile\fP\fB.e\fP for the named files \fIfile\fP\fB.[cikm]\fP .IP \fB\-c.k\fP Compile C source \fIfile\fP\fB.[ci]\fP or -encode EM assembly code from \fIfile\fP\fB.e\fP -into unoptimised compact EM code and write the result on \fIfile\fP\fB.k\fP +encode human-readable EM assembly code from \fIfile\fP\fB.e\fP +into non-optimized compact EM code and write the result on \fIfile\fP\fB.k\fP .IP \fB\-c.m\fP Compile C source \fIfile\fP\fB.[ci]\fP, -translate unoptimised EM code from \fIfile\fP\fB.k\fP or +translate non-optimized EM code from \fIfile\fP\fB.k\fP or encode EM assembly code from \fIfile\fP\fB.e\fP -into optimised compact EM code and write the result on \fIfile\fP\fB.m\fP +into optimized compact EM code and write the result on \fIfile\fP\fB.m\fP .IP \fB\-c.o\fP Suppress the loading phase of the compilation, and force an object file to be produced even if only one program is compiled @@ -176,7 +190,7 @@ Print the commands before they are executed. Do not really execute (for debugging purposes only). .IP \fB\-vd\fP Print some additional information (for debugging purposes only). -.IP \fB\-\-\fP\fIanything\f +.IP \fB\-\-\fP\fIanything\fP .br Equivalent to \fB\-Rcem\-\-\fP\fIanything\fP. The options @@ -194,34 +208,7 @@ built\-in preprocessor of the \fBcem\fP phase. Most "\-\-" options are used by .I cemcom (1) to set some internal debug switches. -.IP loader\ options -.br -The options -.B \-d , -.B \-e , -.B \-F , -.B \-n , -.B \-N , -.B \-r , -.B \-s , -.B \-u , -.B \-x , -.B \-X -and -.B \-z -are directly passed to the loader. -.SH FILES -$CEM/bin/cem: this program -.br -$CEM/src/cem.c: C source of the \fBcem\fP program -.br -$CEM/bin/cemcom: C front end compiler -.br -$CEM/lib: default library-containing directory -.br -$CEM/src/cem.1: this manual page -.br -$CEM/src/cemcom.1: manual page for the C front end compiler +.LP .SH SEE ALSO cemcom(1), cc(1), ack(?), as(1), ld(1) .br @@ -229,22 +216,15 @@ cemcom(1), cc(1), ack(?), as(1), ld(1) B.W. Kernighan and D.M. Ritchie, \fIThe C Programming Language\fP, Prentice-Hall, 1978. .SH DIAGNOSTICS -Any failure of one of the phases is reported. -.SH NOTES -.IP \(bu -The names $CEM and $EM refer to the directories containing the CEM compiler -and the ACK distribution tree respectively. -.IP \(bu -This manual page contains references to programs that reside on our site -which is a VAX 11/750 running UNIX BSD4.1. -Setting up \fBcem\fP requires some names to be declared in $CEM/src/cem.c +.I Cem +reports any failure of its components. .SH BUGS .IP \(bu All intermediate files are placed in the current working directory which causes files with the same name as the intermediate files to be overwritten. .IP \(bu .B Cem -only accepts a limited number of arguments to be passed to the various phases. +only accepts a limited number of arguments to be passed to the components. (e.g., 256). .IP \(bu -Please report suggestions and other bugs to erikb@tjalk.UUCP +Please report suggestions and other bugs to erikb@vu44.uucp diff --git a/lang/cem/cemcom/cemcom.1 b/lang/cem/cemcom/cemcom.1 index 656742ba..64aa283e 100644 --- a/lang/cem/cemcom/cemcom.1 +++ b/lang/cem/cemcom/cemcom.1 @@ -1,4 +1,4 @@ -.TH CEMCOM 1L 86/03/10 +.TH CEMCOM 1L 86/11/12 .SH NAME cemcom \- C to EM compiler .SH SYNOPSIS @@ -74,21 +74,12 @@ This feature can be used in various shell scripts and surrounding programs to force a certain option to be handed over to \fBcemcom\fR. .LP .SH FILES -.IR /user1/cem/bin/cemcom : -binary of the CEM compiler. -.br -.IR /user1/cem/bin/cem : -a \fIcc\fP(1)-like driver for the VAX running 4.1BSD UNIX. -.br -.IR /user1/sjoerd/bin/CC : -a \fIcc\fP(1)-like driver for the 68000 running Amoeba. +.IR /usr/em/lib/em_cemcom : +the compiler .SH DIAGNOSTICS All warning and error messages are written on standard error output. .SH BUGS -Debugging and profiling facilities may be present during the development -of \fIcemcom\fP. -.br -Please report all bugs to ..tjalk!cem or ..tjalk!erikb +Feel free to report them to erikb@vu44.uucp .SH REFERENCE Baalbergen, E.H., D. Grune, M. Waage ;"\fIThe CEM compiler\fR", Informatica Manual IM-4 From 1754d9404770e684b060b1215394db740058d11a Mon Sep 17 00:00:00 2001 From: erikb Date: Wed, 12 Nov 1986 09:55:28 +0000 Subject: [PATCH 0334/1625] removed the debug message for encountering STRING-type Values --- lang/cem/cemcom/eval.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lang/cem/cemcom/eval.c b/lang/cem/cemcom/eval.c index 7a08dbcc..6c1d260f 100644 --- a/lang/cem/cemcom/eval.c +++ b/lang/cem/cemcom/eval.c @@ -68,7 +68,6 @@ EVAL(expr, val, code, true_label, false_label) load_val(expr, val); break; case String: /* a string constant */ - expr_warning(expr, "(DEBUG) value-class 'String' seen"); if (gencode) { struct expr *ex = expr; string2pointer(&ex); From 52e8a88abb60fbc6a77c870c6363242648297163 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 12 Nov 1986 21:04:38 +0000 Subject: [PATCH 0335/1625] Changed sizes of "argstr" and "labstr", to accomodate longer identifiers. --- mach/proto/cg/fillem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/proto/cg/fillem.c b/mach/proto/cg/fillem.c index c4bf21d8..f3ee53c7 100644 --- a/mach/proto/cg/fillem.c +++ b/mach/proto/cg/fillem.c @@ -78,7 +78,7 @@ int opcode; int offtyp; long argval; int dlbval; -char str[MAXSTR],argstr[32],labstr[32]; +char str[MAXSTR],argstr[128],labstr[128]; int strsiz; int holno=0; int procno=0; From 3ffbb31b34fe2e45d58beab0f2e91d5b8e22b0b4 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 12 Nov 1986 21:14:05 +0000 Subject: [PATCH 0336/1625] changed sizes of labstr and argstr to accomodate longer identifiers. --- mach/proto/ncg/fillem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/proto/ncg/fillem.c b/mach/proto/ncg/fillem.c index 5e87991b..dfb85047 100644 --- a/mach/proto/ncg/fillem.c +++ b/mach/proto/ncg/fillem.c @@ -78,7 +78,7 @@ int opcode; int offtyp; long argval; int dlbval; -char str[MAXSTR],argstr[32],labstr[32]; +char str[MAXSTR],argstr[128],labstr[128]; int strsiz; int holno=0; int procno=0; From 6f6380329d0e03fdcda60f63922df59202cda134 Mon Sep 17 00:00:00 2001 From: erikb Date: Fri, 14 Nov 1986 08:16:38 +0000 Subject: [PATCH 0337/1625] adapted default IDEPTH value --- lang/cem/cemcom/Parameters | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/cem/cemcom/Parameters b/lang/cem/cemcom/Parameters index a1d0d240..6de92789 100644 --- a/lang/cem/cemcom/Parameters +++ b/lang/cem/cemcom/Parameters @@ -9,7 +9,7 @@ !File: idepth.h -#define IDEPTH 20 /* maximum nr of stacked input buffers */ +#define IDEPTH 100 /* maximum nr of stacked input buffers */ !File: errout.h From ad86f01119042aedb870c7f0b1c2f70bb517a506 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 17 Nov 1986 11:41:28 +0000 Subject: [PATCH 0338/1625] Trying to check more of an expression, giving some more sophisticated error messages,and be less wasteful with space for subranges --- lang/m2/comp/LLlex.c | 21 ++-- lang/m2/comp/Makefile | 4 +- lang/m2/comp/Parameters | 2 +- lang/m2/comp/Resolve | 4 +- lang/m2/comp/Version.c | 2 +- lang/m2/comp/chk_expr.c | 222 +++++++++++++++++++++----------------- lang/m2/comp/code.c | 21 ++-- lang/m2/comp/cstoper.c | 2 +- lang/m2/comp/declar.g | 60 +++++++---- lang/m2/comp/def.H | 5 +- lang/m2/comp/def.c | 6 +- lang/m2/comp/defmodule.c | 14 ++- lang/m2/comp/desig.c | 2 - lang/m2/comp/enter.c | 12 +-- lang/m2/comp/expression.g | 36 +------ lang/m2/comp/lookup.c | 38 +------ lang/m2/comp/options.c | 21 +++- lang/m2/comp/program.g | 8 +- lang/m2/comp/type.H | 7 ++ lang/m2/comp/type.c | 23 ++++ lang/m2/comp/walk.c | 10 +- 21 files changed, 280 insertions(+), 240 deletions(-) diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index 733ba3b3..c9372ecb 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -76,10 +76,12 @@ GetString(upto) /* Read a Modula-2 string, delimited by the character "upto". */ register int ch; - register struct string *str = (struct string *) Malloc(sizeof(struct string)); + register struct string *str = (struct string *) + Malloc((unsigned) sizeof(struct string)); register char *p; + register int len; - str->s_length = ISTRSIZE; + len = ISTRSIZE; str->s_str = p = Malloc((unsigned int) ISTRSIZE); while (LoadChar(ch), ch != upto) { if (class(ch) == STNL) { @@ -95,15 +97,18 @@ GetString(upto) break; } *p++ = ch; - if (p - str->s_str == str->s_length) { + if (p - str->s_str == len) { str->s_str = Srealloc(str->s_str, - (unsigned int) str->s_length + RSTRSIZE); - p = str->s_str + str->s_length; - str->s_length += RSTRSIZE; + (unsigned int) len + RSTRSIZE); + p = str->s_str + len; + len += RSTRSIZE; } } - *p = '\0'; str->s_length = p - str->s_str; + while (p - str->s_str < len) *p++ = '\0'; + if (str->s_length == 0) str->s_length = 1; /* ??? string length + at least 1 ??? + */ return str; } @@ -172,7 +177,7 @@ linedirective() { * Remember the file name */ if (!eofseen && strcmp(FileName,buf)) { - FileName = Salloc(buf,strlen(buf) + 1); + FileName = Salloc(buf,(unsigned) strlen(buf) + 1); } } if (eofseen) { diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index f9746fd1..aff09b74 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -64,8 +64,8 @@ lint: Cfiles sh -c 'if $(CC) nmclash.c > /dev/null 2>&1 ; then make Xlint ; else sh Resolve Xlint ; fi' @rm -f nmclash.o a.out -clashes: $(SRC) $(HFILES) - sh -c 'if test -f clashes ; then cclash -l7 clashes $? > Xclashes ; mv Xclashes clashes ; else cclash -l7 $? > clashes ; fi' +longnames: $(SRC) $(HFILES) + sh -c 'if test -f longnames ; then prid -l7 longnames $? > Xlongnames ; mv Xlongnames longnames ; else prid -l7 $? > longnames ; fi' # entry points not to be used directly diff --git a/lang/m2/comp/Parameters b/lang/m2/comp/Parameters index 9aa80fbe..fecdc8a7 100644 --- a/lang/m2/comp/Parameters +++ b/lang/m2/comp/Parameters @@ -1,6 +1,6 @@ !File: errout.h #define ERROUT STDERR /* file pointer for writing messages */ -#define MAXERR_LINE 5 /* maximum number of error messages given +#define MAXERR_LINE 100 /* maximum number of error messages given on the same input line. */ diff --git a/lang/m2/comp/Resolve b/lang/m2/comp/Resolve index b8712499..eeb0a7b8 100755 --- a/lang/m2/comp/Resolve +++ b/lang/m2/comp/Resolve @@ -20,10 +20,10 @@ then : else mkdir ../Xsrc fi -make clashes +make longnames : remove code generating routines from the clashes list as they are defines. : code generating routine names start with C_ -sed '/^C_/d' < clashes > tmp$$ +sed '/^C_/d' < longnames > tmp$$ cclash -c -l7 tmp$$ > ../Xsrc/Xclashes rm -f tmp$$ PW=`pwd` diff --git a/lang/m2/comp/Version.c b/lang/m2/comp/Version.c index 44e57907..521e211a 100644 --- a/lang/m2/comp/Version.c +++ b/lang/m2/comp/Version.c @@ -1 +1 @@ -char Version[] = "Version 0.7"; +char Version[] = "ACK Modula-2 compiler Version 0.8"; diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index c01ae1a5..fb1dd190 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -25,6 +25,20 @@ extern char *symbol2str(); +STATIC +Xerror(nd, mess, edf) + struct node *nd; + char *mess; + struct def *edf; +{ + if (edf) { + if (edf->df_kind != D_ERROR) { + node_error(nd, "\"%s\": %s", edf->df_idf->id_text, mess); + } + } + else node_error(nd, "%s", mess); +} + int ChkVariable(expp) register struct node *expp; @@ -37,7 +51,7 @@ ChkVariable(expp) if (expp->nd_class == Def && !(expp->nd_def->df_kind & (D_FIELD|D_VARIABLE))) { - node_error(expp, "variable expected"); + Xerror(expp, "variable expected", expp->nd_def); return 0; } @@ -63,7 +77,7 @@ ChkArrow(expp) tp = expp->nd_right->nd_type; if (tp->tp_fund != T_POINTER) { - node_error(expp, "illegal operand for unary operator \"^\""); + node_error(expp, "\"^\": illegal operand"); return 0; } @@ -82,22 +96,18 @@ ChkArr(expp) */ register struct type *tpl, *tpr; + int retval; assert(expp->nd_class == Arrsel); assert(expp->nd_symb == '['); expp->nd_type = error_type; - if ( - !ChkVariable(expp->nd_left) - || - !ChkExpression(expp->nd_right) - || - expp->nd_left->nd_type == error_type - ) return 0; + retval = ChkVariable(expp->nd_left) & ChkExpression(expp->nd_right); tpl = expp->nd_left->nd_type; tpr = expp->nd_right->nd_type; + if (tpl == error_type || tpr == error_type) return 0; if (tpl->tp_fund != T_ARRAY) { node_error(expp, "not indexing an ARRAY type"); @@ -116,7 +126,7 @@ ChkArr(expp) } expp->nd_type = RemoveEqual(tpl->arr_elem); - return 1; + return retval; } #ifdef DEBUG @@ -168,11 +178,11 @@ ChkLinkOrName(expp) !(left->nd_def->df_kind & (D_MODULE|D_VARIABLE|D_FIELD)) ) ) { - node_error(left, "illegal selection"); + Xerror(left, "illegal selection", left->nd_def); return 0; } - if (!(df = lookup(expp->nd_IDF, left->nd_type->rec_scope))) { + if (!(df = lookup(expp->nd_IDF, left->nd_type->rec_scope, 1))) { id_not_declared(expp); return 0; } @@ -184,9 +194,7 @@ ChkLinkOrName(expp) /* Fields of a record are always D_QEXPORTED, so ... */ -node_error(expp, "identifier \"%s\" not exported from qualifying module", -df->df_idf->id_text); - return 0; +Xerror(expp, "not exported from qualifying module", df); } } @@ -202,7 +210,6 @@ df->df_idf->id_text); assert(expp->nd_class == Def); df = expp->nd_def; - if (df->df_kind == D_ERROR) return 0; if (df->df_kind & (D_ENUM | D_CONST)) { /* Replace an enum-literal or a CONST identifier by its value. @@ -220,8 +227,7 @@ df->df_idf->id_text); expp->nd_lineno = ln; } } - - return 1; + return df->df_kind != D_ERROR; } STATIC int @@ -238,7 +244,7 @@ ChkExLinkOrName(expp) df = expp->nd_def; if (!(df->df_kind & D_VALUE)) { - node_error(expp, "value expected"); + Xerror(expp, "value expected", df); } if (df->df_kind == D_PROCEDURE) { @@ -352,19 +358,18 @@ ChkSet(expp) /* A type was given. Check it out */ if (! ChkDesignator(nd)) return 0; - assert(nd->nd_class == Def); df = nd->nd_def; if (!is_type(df) || - (df->df_type->tp_fund != T_SET)) { + (df->df_type->tp_fund != T_SET)) { if (df->df_kind != D_ERROR) { -node_error(expp, "type specifier does not represent a set type"); + Xerror(expp, "not a set type", df); } return 0; } tp = df->df_type; - FreeNode(expp->nd_left); + FreeNode(nd); expp->nd_left = 0; } else tp = bitset_type; @@ -412,8 +417,9 @@ node_error(expp, "type specifier does not represent a set type"); } STATIC struct node * -getarg(argp, bases, designator) +getarg(argp, bases, designator, edf) struct node **argp; + struct def *edf; { /* This routine is used to fetch the next argument from an argument list. The argument list is indicated by "argp". @@ -427,7 +433,7 @@ getarg(argp, bases, designator) register struct node *left; if (! arg) { - node_error(*argp, "too few arguments supplied"); + Xerror(*argp, "too few arguments supplied", edf); return 0; } @@ -443,7 +449,7 @@ getarg(argp, bases, designator) if (bases) { if (!(BaseType(left->nd_type)->tp_fund & bases)) { - node_error(arg, "unexpected type"); + Xerror(arg, "unexpected parameter type", edf); return 0; } } @@ -453,8 +459,9 @@ getarg(argp, bases, designator) } STATIC struct node * -getname(argp, kinds) +getname(argp, kinds, bases, edf) struct node **argp; + struct def *edf; { /* Get the next argument from argument list "argp". The argument must indicate a definition, and the @@ -464,7 +471,7 @@ getname(argp, kinds) register struct node *left; if (!arg->nd_right) { - node_error(arg, "too few arguments supplied"); + Xerror(arg, "too few arguments supplied", edf); return 0; } @@ -473,15 +480,22 @@ getname(argp, kinds) if (! ChkDesignator(left)) return 0; if (left->nd_class != Def && left->nd_class != LinkDef) { - node_error(arg, "identifier expected"); + Xerror(arg, "identifier expected", edf); return 0; } if (!(left->nd_def->df_kind & kinds)) { - node_error(arg, "unexpected type"); + Xerror(arg, "unexpected parameter type", edf); return 0; } + if (bases) { + if (!(left->nd_type->tp_fund & bases)) { + Xerror(arg, "unexpected parameter type", edf); + return 0; + } + } + *argp = arg; return left; } @@ -493,16 +507,25 @@ ChkProcCall(expp) /* Check a procedure call */ register struct node *left; - struct node *arg; + struct def *edf = 0; register struct paramlist *param; + char ebuf[256]; + int retval = 1; + int cnt = 0; left = expp->nd_left; + if (left->nd_class == Def || left->nd_class == LinkDef) { + edf = left->nd_def; + } expp->nd_type = RemoveEqual(ResultType(left->nd_type)); /* Check parameter list */ for (param = ParamList(left->nd_type); param; param = param->next) { - if (!(left = getarg(&expp, 0, IsVarParam(param)))) return 0; + if (!(left = getarg(&expp, 0, IsVarParam(param), edf))) { + return 0; + } + cnt++; if (left->nd_symb == STRING) { TryToString(left, TypeOfParam(param)); } @@ -510,17 +533,19 @@ ChkProcCall(expp) left->nd_type, IsVarParam(param), left)) { -node_error(left, "type incompatibility in parameter"); - return 0; + sprint(ebuf, "type incompatibility in parameter %d", + cnt); + Xerror(left, ebuf, edf); + retval = 0; } } if (expp->nd_right) { - node_error(expp->nd_right, "too many parameters supplied"); + Xerror(expp->nd_right, "too many parameters supplied", edf); return 0; } - return 1; + return retval; } int @@ -659,11 +684,12 @@ ChkBinOper(expp) register struct node *left, *right; struct type *tpl, *tpr; int allowed; + int retval; left = expp->nd_left; right = expp->nd_right; - if (!ChkExpression(left) || !ChkExpression(right)) return 0; + retval = ChkExpression(left) & ChkExpression(right); tpl = BaseType(left->nd_type); tpr = BaseType(right->nd_type); @@ -695,24 +721,27 @@ ChkBinOper(expp) if (!TstAssCompat(tpl, ElementType(tpr))) { /* Assignment compatible ??? I don't know! Should we be allowed to check - if a CARDINAL is a member of a BITSET??? + if a INTEGER is a member of a BITSET??? */ -node_error(expp, "incompatible types for operator \"IN\""); + node_error(expp, "\"IN\": incompatible types"); return 0; } if (left->nd_class == Value && right->nd_class == Set) { cstset(expp); } - return 1; + return retval; } + if (!retval) return 0; + allowed = AllowedTypes(expp->nd_symb); if (!(tpr->tp_fund & allowed) || !(tpl->tp_fund & allowed)) { if (!((T_CARDINAL & allowed) && ChkAddress(tpl, tpr))) { -node_error(expp,"operator \"%s\": illegal operand type(s)", symbol2str(expp->nd_symb)); + node_error(expp, "\"%s\": illegal operand type(s)", + symbol2str(expp->nd_symb)); return 0; } if (expp->nd_type->tp_fund & T_CARDINAL) { @@ -721,16 +750,15 @@ node_error(expp,"operator \"%s\": illegal operand type(s)", symbol2str(expp->nd_ } if (Boolean(expp->nd_symb) && tpl != bool_type) { -node_error(expp,"operator \"%s\": illegal operand type(s)", symbol2str(expp->nd_symb)); - + node_error(expp, "\"%s\": illegal operand type(s)", + symbol2str(expp->nd_symb)); return 0; } /* Operands must be compatible (distilled from Def 8.2) */ if (!TstCompat(tpl, tpr)) { - node_error(expp, "incompatible types for operator \"%s\"", - symbol2str(expp->nd_symb)); + node_error(expp, "\"%s\": incompatible types", symbol2str(expp->nd_symb)); return 0; } @@ -810,14 +838,14 @@ ChkUnOper(expp) default: crash("ChkUnOper"); } - node_error(expp, "illegal operand for unary operator \"%s\"", - symbol2str(expp->nd_symb)); + node_error(expp, "\"%s\": illegal operand", symbol2str(expp->nd_symb)); return 0; } STATIC struct node * -getvariable(argp) +getvariable(argp, edf) struct node **argp; + struct def *edf; { /* Get the next argument from argument list "argp". It must obey the rules of "ChkVariable". @@ -826,7 +854,7 @@ getvariable(argp) arg = arg->nd_right; if (!arg) { - node_error(arg, "too few parameters supplied"); + Xerror(arg, "too few parameters supplied", edf); return 0; } @@ -844,14 +872,16 @@ ChkStandard(expp, left) /* Check a call of a standard procedure or function */ struct node *arg = expp; + register struct def *edf; int std; assert(left->nd_class == Def); std = left->nd_def->df_value.df_stdname; + edf = left->nd_def; switch(std) { case S_ABS: - if (!(left = getarg(&arg, T_NUMERIC, 0))) return 0; + if (!(left = getarg(&arg, T_NUMERIC, 0, edf))) return 0; expp->nd_type = left->nd_type; if (left->nd_class == Value && expp->nd_type->tp_fund != T_REAL) { @@ -861,28 +891,31 @@ ChkStandard(expp, left) case S_CAP: expp->nd_type = char_type; - if (!(left = getarg(&arg, T_CHAR, 0))) return 0; + if (!(left = getarg(&arg, T_CHAR, 0, edf))) return 0; if (left->nd_class == Value) cstcall(expp, S_CAP); break; case S_CHR: expp->nd_type = char_type; - if (!(left = getarg(&arg, T_INTORCARD, 0))) return 0; + if (!(left = getarg(&arg, T_INTORCARD, 0, edf))) return 0; if (left->nd_class == Value) cstcall(expp, S_CHR); break; case S_FLOAT: expp->nd_type = real_type; - if (!(left = getarg(&arg, T_INTORCARD, 0))) return 0; + if (!(left = getarg(&arg, T_INTORCARD, 0, edf))) return 0; break; case S_HIGH: - if (!(left = getarg(&arg, T_ARRAY|T_STRING|T_CHAR, 0))) return 0; + if (!(left = getarg(&arg, T_ARRAY|T_STRING|T_CHAR, 0, edf))) { + return 0; + } if (IsConformantArray(left->nd_type)) { - /* A conformant array has no explicit index type - ??? So, what can we use as index-type ??? + /* A conformant array has no explicit index type, + but it is a subrange with lower bound 0, so + it is of type CARDINAL !!! */ - expp->nd_type = intorcard_type; + expp->nd_type = card_type; break; } if (left->nd_type->tp_fund == T_ARRAY) { @@ -890,14 +923,17 @@ ChkStandard(expp, left) cstcall(expp, S_MAX); break; } - if (left->nd_type->tp_fund == T_CHAR) { - if (left->nd_symb != STRING) { - node_error(left,"HIGH: array parameter expected"); - return 0; - } + if (left->nd_symb != STRING) { + Xerror(left,"array parameter expected", edf); + return 0; } - expp->nd_type = intorcard_type; + expp->nd_type = card_type; expp->nd_class = Value; + /* Notice that we could disallow HIGH("") here by checking + that left->nd_type->tp_fund != T_CHAR || left->nd_INT != 0. + ??? For the time being, we don't. !!! + Maybe the empty string should not be allowed at all. + */ expp->nd_INT = left->nd_type->tp_fund == T_CHAR ? 0 : left->nd_SLE - 1; expp->nd_symb = INTEGER; @@ -905,9 +941,7 @@ ChkStandard(expp, left) case S_MAX: case S_MIN: - if (!(left = getname(&arg, D_ISTYPE))) return 0; - if (!(left->nd_type->tp_fund & (T_DISCRETE))) { -node_error(left, "illegal type in %s", std == S_MAX ? "MAX" : "MIN"); + if (!(left = getname(&arg, D_ISTYPE, T_DISCRETE, edf))) { return 0; } expp->nd_type = left->nd_type; @@ -915,17 +949,13 @@ node_error(left, "illegal type in %s", std == S_MAX ? "MAX" : "MIN"); break; case S_ODD: - if (!(left = getarg(&arg, T_INTORCARD, 0))) return 0; + if (!(left = getarg(&arg, T_INTORCARD, 0, edf))) return 0; expp->nd_type = bool_type; if (left->nd_class == Value) cstcall(expp, S_ODD); break; case S_ORD: - if (!(left = getarg(&arg, T_DISCRETE, 0))) return 0; - if (left->nd_type->tp_size > word_size) { - node_error(left, "illegal type in argument of ORD"); - return 0; - } + if (!(left = getarg(&arg, T_DISCRETE, 0, edf))) return 0; expp->nd_type = card_type; if (left->nd_class == Value) cstcall(expp, S_ORD); break; @@ -937,12 +967,12 @@ node_error(left, "illegal type in %s", std == S_MAX ? "MAX" : "MIN"); if (!warning_given) { warning_given = 1; - node_warning(expp, W_OLDFASHIONED, "NEW and DISPOSE are old-fashioned"); + node_warning(expp, W_OLDFASHIONED, "NEW and DISPOSE are obsolete"); } } - if (! (left = getvariable(&arg))) return 0; + if (! (left = getvariable(&arg, edf))) return 0; if (! (left->nd_type->tp_fund == T_POINTER)) { - node_error(left, "pointer variable expected"); + Xerror(left, "pointer variable expected", edf); return 0; } if (left->nd_class == Def) { @@ -974,23 +1004,19 @@ node_error(left, "illegal type in %s", std == S_MAX ? "MAX" : "MIN"); case S_TSIZE: /* ??? */ case S_SIZE: expp->nd_type = intorcard_type; - if (! getname(&arg, D_FIELD|D_VARIABLE|D_ISTYPE)) return 0; + if (! getname(&arg, D_FIELD|D_VARIABLE|D_ISTYPE, 0, edf)) { + return 0; + } cstcall(expp, S_SIZE); break; case S_TRUNC: expp->nd_type = card_type; - if (!(left = getarg(&arg, T_REAL, 0))) return 0; + if (!(left = getarg(&arg, T_REAL, 0, edf))) return 0; break; case S_VAL: - { - struct type *tp; - - if (!(left = getname(&arg, D_ISTYPE))) return 0; - tp = left->nd_def->df_type; - if (!(tp->tp_fund & T_DISCRETE)) { - node_error(arg, "unexpected type"); + if (!(left = getname(&arg, D_ISTYPE, T_DISCRETE, edf))) { return 0; } expp->nd_type = left->nd_def->df_type; @@ -998,26 +1024,25 @@ node_error(left, "illegal type in %s", std == S_MAX ? "MAX" : "MIN"); arg->nd_right = 0; FreeNode(arg); arg = expp; - if (!(left = getarg(&arg, T_INTORCARD, 0))) return 0; + if (!(left = getarg(&arg, T_INTORCARD, 0, edf))) return 0; if (left->nd_class == Value) cstcall(expp, S_VAL); break; - } case S_ADR: expp->nd_type = address_type; - if (!(left = getarg(&arg, 0, 1))) return 0; + if (!(left = getarg(&arg, 0, 1, edf))) return 0; break; case S_DEC: case S_INC: expp->nd_type = 0; - if (! (left = getvariable(&arg))) return 0; + if (! (left = getvariable(&arg, edf))) return 0; if (! (left->nd_type->tp_fund & T_DISCRETE)) { -node_error(left,"illegal type in argument of %s",std == S_INC ? "INC" : "DEC"); + Xerror(left,"illegal parameter type", edf); return 0; } if (arg->nd_right) { - if (! getarg(&arg, T_INTORCARD, 0)) return 0; + if (! getarg(&arg, T_INTORCARD, 0, edf)) return 0; } break; @@ -1031,18 +1056,18 @@ node_error(left,"illegal type in argument of %s",std == S_INC ? "INC" : "DEC"); struct type *tp; expp->nd_type = 0; - if (!(left = getvariable(&arg))) return 0; + if (!(left = getvariable(&arg, edf))) return 0; tp = left->nd_type; if (tp->tp_fund != T_SET) { -node_error(arg, "%s expects a SET parameter", std == S_EXCL ? "EXCL" : "INCL"); + Xerror(arg, "SET parameter expected", edf); return 0; } - if (!(left = getarg(&arg, T_DISCRETE, 0))) return 0; + if (!(left = getarg(&arg, T_DISCRETE, 0, edf))) return 0; if (!TstAssCompat(ElementType(tp), left->nd_type)) { /* What type of compatibility do we want here? apparently assignment compatibility! ??? ??? */ - node_error(arg, "unexpected type"); + Xerror(arg, "unexpected parameter type", edf); return 0; } break; @@ -1053,7 +1078,7 @@ node_error(arg, "%s expects a SET parameter", std == S_EXCL ? "EXCL" : "INCL"); } if (arg->nd_right) { - node_error(arg->nd_right, "too many parameters supplied"); + Xerror(arg->nd_right, "too many parameters supplied", edf); return 0; } @@ -1074,7 +1099,7 @@ ChkCast(expp, left) register struct node *arg = expp->nd_right; if ((! arg) || arg->nd_right) { -node_error(expp, "only one parameter expected in type cast"); + Xerror(expp, "too many parameters in type cast", left->nd_def); return 0; } @@ -1084,7 +1109,7 @@ node_error(expp, "only one parameter expected in type cast"); if (arg->nd_type->tp_size != left->nd_type->tp_size && (arg->nd_type->tp_size > word_size || left->nd_type->tp_size > word_size)) { - node_error(expp, "unequal sizes in type cast"); + Xerror(expp, "unequal sizes in type cast", left->nd_def); } if (arg->nd_class == Value) { @@ -1132,8 +1157,7 @@ no_desig(expp) } STATIC int -done_before(expp) - struct node *expp; +done_before() { return 1; } diff --git a/lang/m2/comp/code.c b/lang/m2/comp/code.c index d5d419ee..1fbea8be 100644 --- a/lang/m2/comp/code.c +++ b/lang/m2/comp/code.c @@ -65,6 +65,7 @@ CodeString(nd) } } +STATIC CodePadString(nd, sz) register struct node *nd; arith sz; @@ -96,7 +97,7 @@ CodeExpr(nd, ds, true_label, false_label) if (tp->tp_fund == T_REAL) fp_used = 1; switch(nd->nd_class) { case Def: - if (nd->nd_def->df_kind == D_PROCEDURE) { + if (nd->nd_def->df_kind & (D_PROCEDURE|D_PROCHEAD)) { C_lpi(NameOfProc(nd->nd_def)); ds->dsg_kind = DSG_LOADED; break; @@ -380,7 +381,7 @@ CodeParameters(param, arg) } } else if (left->nd_symb == STRING) { - C_loc(left->nd_SLE - 1); + C_loc(left->nd_SLE); } else if (tp->arr_elem == word_type) { C_loc((left_type->tp_size+word_size-1) / word_size - 1); @@ -403,8 +404,10 @@ CodeParameters(param, arg) if (left_type->tp_fund == T_STRING) { CodePadString(left, tp->tp_size); } - else CodePExpr(left); - RangeCheck(left_type, tp); + else { + CodePExpr(left); + RangeCheck(left_type, tp); + } } } @@ -413,7 +416,7 @@ CodeStd(nd) { register struct node *arg = nd->nd_right; register struct node *left = 0; - register struct type *tp = 0; + register struct type *tp; int std = nd->nd_left->nd_def->df_value.df_stdname; if (arg) { @@ -426,15 +429,11 @@ CodeStd(nd) case S_ABS: CodePExpr(left); if (tp->tp_fund == T_INTEGER) { - if (tp->tp_size == int_size) { - C_cal("_absi"); - } + if (tp->tp_size == int_size) C_cal("_absi"); else C_cal("_absl"); } else if (tp->tp_fund == T_REAL) { - if (tp->tp_size == float_size) { - C_cal("_absf"); - } + if (tp->tp_size == float_size) C_cal("_absf"); else C_cal("_absd"); } C_asp(tp->tp_size); diff --git a/lang/m2/comp/cstoper.c b/lang/m2/comp/cstoper.c index aeb9bb8d..5f743b42 100644 --- a/lang/m2/comp/cstoper.c +++ b/lang/m2/comp/cstoper.c @@ -72,7 +72,7 @@ cstbin(expp) */ register arith o1 = expp->nd_left->nd_INT; register arith o2 = expp->nd_right->nd_INT; - register int uns = expp->nd_type != int_type; + register int uns = expp->nd_left->nd_type != int_type; assert(expp->nd_class == Oper); assert(expp->nd_left->nd_class == Value); diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 8a277ed8..00624af5 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -50,13 +50,14 @@ ProcedureHeading(struct def **pdf; int type;) ; block(struct node **pnd;) : - declaration* - [ { return_occurred = 0; } + [ %persistent + declaration + ]* + { return_occurred = 0; *pnd = 0; } + [ %persistent BEGIN StatementSequence(pnd) - | - { *pnd = 0; } - ] + ]? END ; @@ -72,7 +73,7 @@ declaration: ModuleDeclaration ';' ; -FormalParameters(struct paramlist *ppr; arith *parmaddr; struct type **ptp;): +FormalParameters(struct paramlist **ppr; arith *parmaddr; struct type **ptp;): '(' [ FPSection(ppr, parmaddr) @@ -160,10 +161,15 @@ enumeration(struct type **ptp;) } : '(' IdentList(&EnumList) ')' { - *ptp = standard_type(T_ENUMERATION, 1, (arith) 1); + *ptp = standard_type(T_ENUMERATION, int_align, int_size); EnterEnumList(EnumList, *ptp); - if ((*ptp)->enm_ncst > 256) { /* ??? is this reasonable ??? */ - error("too many enumeration literals"); + if (ufit((*ptp)->enm_ncst-1, 1)) { + (*ptp)->tp_size = 1; + (*ptp)->tp_align = 1; + } + else if (ufit((*ptp)->enm_ncst-1, short_size)) { + (*ptp)->tp_size = short_size; + (*ptp)->tp_align = short_align; } } ; @@ -263,7 +269,7 @@ FieldList(struct scope *scope; arith *cnt; int *palign;) /* Also accept old fashioned Modula-2 syntax, but give a warning. Sorry for the complicated code. */ - [ qualident(0, (struct def **) 0, (char *) 0, &nd1) + [ qualident(&nd1) { nd = nd1; } [ ':' qualtype(&tp) /* This is correct, in both kinds of Modula-2, if @@ -387,7 +393,7 @@ PointerType(struct type **ptp;) } : POINTER TO { *ptp = construct_type(T_POINTER, NULLTYPE); } - [ %if ( lookup(dot.TOK_IDF, CurrentScope) + [ %if ( lookup(dot.TOK_IDF, CurrentScope, 1) /* Either a Module or a Type, but in both cases defined in this scope, so this is the correct identification */ @@ -422,17 +428,33 @@ PointerType(struct type **ptp;) qualtype(struct type **ptp;) { - struct def *df = 0; + register struct node *nd; + struct node *nd1; /* because &nd is illegal */ } : - qualident(D_ISTYPE, &df, "type", (struct node **) 0) - { if (df && !(*ptp = df->df_type)) { - error("type \"%s\" not declared", - df->df_idf->id_text); - *ptp = error_type; - } + qualident(&nd1) + { nd = nd1; + *ptp = error_type; + if (ChkDesignator(nd)) { + if (nd->nd_class != Def) { + node_error(nd, "type expected"); } -; + else { + register struct def *df = nd->nd_def; + if (df->df_kind&(D_ISTYPE|D_FORWARD|D_ERROR)) { + if (! df->df_type) { +node_error(nd,"type \"%s\" not (yet) declared", df->df_idf->id_text); + } + else *ptp = df->df_type; + } + else { +node_error(nd,"identifier \"%s\" is not a type", df->df_idf->id_text); + } + } + } + FreeNode(nd); + } +; ProcedureType(struct type **ptp;) { diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H index 226395c3..dee4b94b 100644 --- a/lang/m2/comp/def.H +++ b/lang/m2/comp/def.H @@ -90,9 +90,8 @@ struct def { /* list of definitions for a name */ #define is_type(dfx) ((dfx)->df_kind & D_ISTYPE) char df_flags; #define D_NOREG 0x01 /* set if it may not reside in a register */ -#define D_USED 0x02 /* set if used */ -#define D_DEFINED 0x04 /* set if it is assigned a value */ -#define D_REFERRED 0x08 /* set if it is referred to */ +#define D_USED 0x02 /* set if used (future use ???) */ +#define D_DEFINED 0x04 /* set if it is assigned a value (future use ???) */ #define D_VARPAR 0x10 /* set if it is a VAR parameter */ #define D_VALPAR 0x20 /* set if it is a value parameter */ #define D_EXPORTED 0x40 /* set if exported */ diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index c57f9154..36c8906a 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -91,14 +91,14 @@ define(id, scope, kind) */ register struct def *df; - df = lookup(id, scope); + df = lookup(id, scope, 1); if ( /* Already in this scope */ df || /* A closed scope, and id defined in the pervasive scope */ ( scopeclosed(scope) && - (df = lookup(id, PervasiveScope))) + (df = lookup(id, PervasiveScope, 1))) ) { switch(df->df_kind) { case D_HIDDEN: @@ -234,7 +234,7 @@ DeclProc(type, id) else { char *name; - df = lookup(id, CurrentScope); + df = lookup(id, CurrentScope, 1); if (df && df->df_kind == D_PROCHEAD) { /* C_exp already generated when we saw the definition in the definition module diff --git a/lang/m2/comp/defmodule.c b/lang/m2/comp/defmodule.c index aaf49e9d..b381d68b 100644 --- a/lang/m2/comp/defmodule.c +++ b/lang/m2/comp/defmodule.c @@ -16,6 +16,7 @@ #include "main.h" #include "node.h" #include "type.h" +#include "misc.h" #ifdef DEBUG long sys_filesize(); @@ -57,7 +58,7 @@ GetDefinitionModule(id, incr) struct scopelist *vis; level += incr; - df = lookup(id, GlobalScope); + df = lookup(id, GlobalScope, 1); if (!df) { /* Read definition module. Make an exception for SYSTEM. */ @@ -66,7 +67,7 @@ GetDefinitionModule(id, incr) } else { open_scope(CLOSEDSCOPE); - if (GetFile(id->id_text)) { + if (!is_anon_idf(id) && GetFile(id->id_text)) { DefModule(); if (level == 1) { /* The module is directly imported by @@ -90,14 +91,17 @@ GetDefinitionModule(id, incr) vis = CurrVis; close_scope(SC_CHKFORW); } - df = lookup(id, GlobalScope); + df = lookup(id, GlobalScope, 1); if (! df) { df = MkDef(id, GlobalScope, D_ERROR); df->df_type = error_type; - df->mod_vis = CurrVis; - return df; + df->mod_vis = vis; } } + else if (df == Defined) { + error("cannot import from currently defined module"); + df->df_kind = D_ERROR; + } assert(df); level -= incr; return df; diff --git a/lang/m2/comp/desig.c b/lang/m2/comp/desig.c index b8736335..66d7ab4e 100644 --- a/lang/m2/comp/desig.c +++ b/lang/m2/comp/desig.c @@ -219,7 +219,6 @@ CodeVarDesig(df, ds) */ assert(ds->dsg_kind == DSG_INIT); - SetUsed(df); if (df->var_addrgiven) { /* the programmer specified an address in the declaration of the variable. Generate code to push the address. @@ -293,7 +292,6 @@ CodeDesig(nd, ds) case Def: df = nd->nd_def; - SetUsed(df); switch(df->df_kind) { case D_FIELD: CodeFieldDesig(df, ds); diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index b5c0aa02..04a948e1 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -273,7 +273,7 @@ ForwDef(ids, scope) */ register struct def *df; - if (!(df = lookup(ids->nd_IDF, scope))) { + if (!(df = lookup(ids->nd_IDF, scope, 1))) { df = define(ids->nd_IDF, scope, D_FORWARD); df->for_node = MkLeaf(Name, &(ids->nd_token)); } @@ -292,9 +292,7 @@ EnterExportList(Idlist, qualified) register struct def *df, *df1; for (;idlist; idlist = idlist->next) { - extern struct def *NoImportlookup(); - - df = NoImportlookup(idlist->nd_IDF, CurrentScope); + df = lookup(idlist->nd_IDF, CurrentScope, 0); if (!df) { /* undefined item in export list @@ -332,7 +330,7 @@ EnterExportList(Idlist, qualified) scope imports it. */ df1 = lookup(idlist->nd_IDF, - enclosing(CurrVis)->sc_scope); + enclosing(CurrVis)->sc_scope, 1); if (df1) { /* It was already defined in the enclosing scope. There are two legal possibilities, @@ -402,7 +400,7 @@ EnterFromImportList(Idlist, FromDef, FromId) for (; idlist; idlist = idlist->next) { if (forwflag) df = ForwDef(idlist, vis->sc_scope); - else if (! (df = lookup(idlist->nd_IDF, vis->sc_scope))) { + else if (! (df = lookup(idlist->nd_IDF, vis->sc_scope, 1))) { not_declared("identifier", idlist, " in qualifying module"); df = define(idlist->nd_IDF,vis->sc_scope,D_ERROR); } @@ -434,7 +432,7 @@ EnterImportList(Idlist, local) for (; idlist; idlist = idlist->next) { DoImport(local ? ForwDef(idlist, sc) : - GetDefinitionModule(idlist->nd_IDF) , + GetDefinitionModule(idlist->nd_IDF, 1) , CurrentScope); } FreeNode(Idlist); diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index 0baa3356..787669bd 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -31,39 +31,13 @@ number(struct node **p;) : } ; -qualident(int types; - struct def **pdf; - char *str; - struct node **p; - ) +qualident(struct node **p;) { - struct node *nd; } : - IDENT { nd = MkLeaf(Name, &dot); } + IDENT { *p = MkLeaf(Name, &dot); } [ - selector(&nd) + selector(p) ]* - { if (types && ChkDesignator(nd)) { - if (nd->nd_class != Def) { - node_error(nd, "%s expected", str); - } - else { - register struct def *df = nd->nd_def; - - if ( !((types|D_ERROR) & df->df_kind)) { - if (df->df_kind == D_FORWARD) { - not_declared(str, nd, ""); - } - else { -node_error(nd,"identifier \"%s\" is not a %s", df->df_idf->id_text, str); - } - } - if (pdf) *pdf = df; - } - } - if (!p) FreeNode(nd); - else *p = nd; - } ; selector(struct node **pnd;): @@ -167,7 +141,7 @@ factor(register struct node **p;) { struct node *nd; } : - qualident(0, (struct def **) 0, (char *) 0, p) + qualident(p) [ designator_tail(p)? [ @@ -231,7 +205,7 @@ element(struct node *nd;) designator(struct node **pnd;) : - qualident(0, (struct def **) 0, (char *) 0, pnd) + qualident(pnd) designator_tail(pnd)? ; diff --git a/lang/m2/comp/lookup.c b/lang/m2/comp/lookup.c index 599cf77f..c4c297a0 100644 --- a/lang/m2/comp/lookup.c +++ b/lang/m2/comp/lookup.c @@ -15,7 +15,7 @@ #include "misc.h" struct def * -lookup(id, scope) +lookup(id, scope, import) register struct idf *id; struct scope *scope; { @@ -43,7 +43,7 @@ lookup(id, scope) df->next = id->id_def; id->id_def = df; } - if (df->df_kind == D_IMPORT) { + if (import && df->df_kind == D_IMPORT) { assert(df->imp_def != 0); return df->imp_def; } @@ -51,38 +51,6 @@ lookup(id, scope) return df; } -struct def * -NoImportlookup(id, scope) - register struct idf *id; - struct scope *scope; -{ - /* Look up a definition of an identifier in scope "scope". - Make the "def" list self-organizing. - Don't check if the definition is imported! - */ - register struct def *df, *df1; - - /* Look in the chain of definitions of this "id" for one with scope - "scope". - */ - for (df = id->id_def, df1 = 0; - df && df->df_scope != scope; - df1 = df, df = df->next) { /* nothing */ } - - if (df) { - /* Found it - */ - if (df1) { - /* Put the definition in front - */ - df1->next = df->next; - df->next = id->id_def; - id->id_def = df; - } - } - return df; -} - struct def * lookfor(id, vis, give_error) register struct node *id; @@ -96,7 +64,7 @@ lookfor(id, vis, give_error) register struct scopelist *sc = vis; while (sc) { - df = lookup(id->nd_IDF, sc->sc_scope); + df = lookup(id->nd_IDF, sc->sc_scope, 1); if (df) return df; sc = nextvisible(sc); } diff --git a/lang/m2/comp/options.c b/lang/m2/comp/options.c index 782c67a5..8bdea33c 100644 --- a/lang/m2/comp/options.c +++ b/lang/m2/comp/options.c @@ -10,6 +10,13 @@ #include "main.h" #include "warning.h" +#define MINIDFSIZE 14 + +#if MINIDFSIZE < 14 +You fouled up! MINIDFSIZE has to be at least 14 or the compiler will not +recognize some keywords! +#endif + extern int idfsize; static int ndirs; int warning_classes; @@ -72,8 +79,14 @@ DoOption(text) idfsize = txt2int(&t); if (*t || idfsize <= 0) fatal("malformed -M option"); - if (idfsize > IDFSIZE) - fatal("maximum identifier length is %d", IDFSIZE); + if (idfsize > IDFSIZE) { + idfsize = IDFSIZE; + warning(W_ORDINARY,"maximum identifier length is %d", IDFSIZE); + } + if (idfsize < MINIDFSIZE) { + warning(W_ORDINARY, "minimum identifier length is %d", MINIDFSIZE); + idfsize = MINIDFSIZE; + } } break; @@ -113,6 +126,10 @@ DoOption(text) if (size != (arith)0) int_size = size; if (align != 0) int_align = align; break; + case 's': /* short (subranges) */ + if (size != 0) short_size = size; + if (align != 0) short_align = align; + break; case 'l': /* longint */ if (size != (arith)0) long_size = size; if (align != 0) long_align = align; diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index afaeb722..100c55df 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -133,7 +133,7 @@ DefinitionModule modules. Issue a warning. */ { -node_warning(exportlist, W_ORDINARY, "export list in definition module ignored"); +node_warning(exportlist, W_OLDFASHIONED, "export list in definition module ignored"); FreeNode(exportlist); } | @@ -183,7 +183,7 @@ definition ProgramModule { - struct def *GetDefinitionModule(); + extern struct def *GetDefinitionModule(); register struct def *df; } : MODULE @@ -210,7 +210,9 @@ ProgramModule ; Module: - { open_scope(CLOSEDSCOPE); } + { open_scope(CLOSEDSCOPE); + warning(W_ORDINARY, "Compiling a definition module"); + } DefinitionModule { close_scope(SC_CHKFORW); } | diff --git a/lang/m2/comp/type.H b/lang/m2/comp/type.H index 0e612f20..d8a345a7 100644 --- a/lang/m2/comp/type.H +++ b/lang/m2/comp/type.H @@ -103,6 +103,7 @@ extern struct type extern int word_align, + short_align, int_align, long_align, float_align, @@ -113,6 +114,7 @@ extern int extern arith word_size, dword_size, + short_size, int_size, long_size, float_size, @@ -149,3 +151,8 @@ struct type #define BaseType(tpx) ((tpx)->tp_fund == T_SUBRANGE ? (tpx)->next : \ (tpx)) #define IsConstructed(tpx) ((tpx)->tp_fund & T_CONSTRUCTED) + +extern long full_mask[]; + +#define fit(n, i) (((n) + (0x80<<(((i)-1)*8)) & ~full_mask[(i)]) == 0) +#define ufit(n, i) (((n) & ~full_mask[(i)]) == 0) diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index 13fac532..e7656580 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -21,6 +21,7 @@ int word_align = AL_WORD, + short_align = AL_SHORT, int_align = AL_INT, long_align = AL_LONG, float_align = AL_FLOAT, @@ -32,6 +33,7 @@ arith word_size = SZ_WORD, dword_size = 2 * SZ_WORD, int_size = SZ_INT, + short_size = SZ_SHORT, long_size = SZ_LONG, float_size = SZ_FLOAT, double_size = SZ_DOUBLE, @@ -280,6 +282,27 @@ subr_type(lb, ub) res->sub_ub = ub->nd_INT; res->tp_size = tp->tp_size; res->tp_align = tp->tp_align; + if (tp == card_type) { + if (ufit(res->sub_ub, 1)) { + res->tp_size = 1; + res->tp_align = 1; + } + else if (ufit(res->sub_ub, 2)) { + res->tp_size = short_size; + res->tp_align = short_align; + } + } + else if (tp == int_type) { + if (fit(res->sub_lb, 1) && fit(res->sub_ub, 1)) { + res->tp_size = 1; + res->tp_align = 1; + } + else if (fit(res->sub_lb, short_size) && + fit(res->sub_ub, short_size)) { + res->tp_size = short_size; + res->tp_align = short_align; + } + } return res; } diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index 1672cf58..5eb55204 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -636,9 +636,9 @@ DoForInit(nd, left) nd->nd_class = Name; nd->nd_symb = IDENT; - if (! ChkVariable(nd) || - ! WalkExpr(left->nd_left) || - ! ChkExpression(left->nd_right)) return 0; + if (!( ChkVariable(nd) & + WalkExpr(left->nd_left) & + ChkExpression(left->nd_right))) return 0; df = nd->nd_def; if (df->df_kind == D_FIELD) { @@ -696,17 +696,17 @@ DoAssign(nd, left, right) */ struct desig dsl, dsr; - if (! ChkExpression(right) || ! ChkVariable(left)) return; + if (! (ChkExpression(right) & ChkVariable(left))) return; if (right->nd_symb == STRING) TryToString(right, left->nd_type); dsr = InitDesig; - CodeExpr(right, &dsr, NO_LABEL, NO_LABEL); if (! TstAssCompat(left->nd_type, right->nd_type)) { node_error(nd, "type incompatibility in assignment"); return; } + CodeExpr(right, &dsr, NO_LABEL, NO_LABEL); if (complex(right->nd_type)) { CodeAddress(&dsr); } From d9c7ccc6e5d6a70c39f6b0e5936d43d5f72a1fac Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 17 Nov 1986 13:08:18 +0000 Subject: [PATCH 0339/1625] Check more, when an error occurred --- lang/m2/comp/chk_expr.c | 57 ++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index fb1dd190..7d27a38b 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -29,11 +29,11 @@ STATIC Xerror(nd, mess, edf) struct node *nd; char *mess; - struct def *edf; + register struct def *edf; { if (edf) { if (edf->df_kind != D_ERROR) { - node_error(nd, "\"%s\": %s", edf->df_idf->id_text, mess); + node_error(nd,"\"%s\": %s", edf->df_idf->id_text, mess); } } else node_error(nd, "%s", mess); @@ -517,6 +517,16 @@ ChkProcCall(expp) if (left->nd_class == Def || left->nd_class == LinkDef) { edf = left->nd_def; } + if (left->nd_type == error_type) { + /* Just check parameters as if they were value parameters + */ + expp->nd_type = error_type; + while (expp->nd_right) { + getarg(&expp, 0, 0, edf); + } + return 0; + } + expp->nd_type = RemoveEqual(ResultType(left->nd_type)); /* Check parameter list @@ -564,31 +574,30 @@ ChkCall(expp) */ expp->nd_type = error_type; left = expp->nd_left; - if (! ChkDesignator(left)) return 0; - - if (IsCast(left)) { - /* It was a type cast. - */ - return ChkCast(expp, left); - } - - if (IsProcCall(left)) { - /* A procedure call. - It may also be a call to a standard procedure - */ - if (left->nd_type == std_type) { - /* A standard procedure + if (ChkDesignator(left)) { + if (IsCast(left)) { + /* It was a type cast. */ - return ChkStandard(expp, left); + return ChkCast(expp, left); } - /* Here, we have found a real procedure call. The left hand - side may also represent a procedure variable. - */ - return ChkProcCall(expp); - } - node_error(left, "procedure, type, or function expected"); - return 0; + if (IsProcCall(left)) { + /* A procedure call. + It may also be a call to a standard procedure + */ + if (left->nd_type == std_type) { + /* A standard procedure + */ + return ChkStandard(expp, left); + } + /* Here, we have found a real procedure call. + The left hand side may also represent a procedure + variable. + */ + } + else node_error(left, "procedure, type, or function expected"); + } + return ChkProcCall(expp); } STATIC struct type * From 7b14da0eb1ef97a28c4d68331fc09cbe343473a5 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 24 Nov 1986 10:42:29 +0000 Subject: [PATCH 0340/1625] Bug fix in "inc loc adi" patterns and the like. --- util/opt/patterns | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/util/opt/patterns b/util/opt/patterns index 03db7f93..fb4d4f62 100644 --- a/util/opt/patterns +++ b/util/opt/patterns @@ -1,10 +1,10 @@ "$Header$" loc adi loc sbi $2==w && $4==w: loc $1-$3 adi w inc dec: -inc loc adi $3==w: loc $1+1 adi w -inc loc sbi $3==w: loc $1-1 sbi w -dec loc adi $3==w: loc $1-1 adi w -dec loc sbi $3==w: loc $1+1 sbi w +inc loc adi $3==w: loc $2+1 adi w +inc loc sbi $3==w: loc $2-1 sbi w +dec loc adi $3==w: loc $2-1 adi w +dec loc sbi $3==w: loc $2+1 sbi w ldc adi ldc sbi $2==2*w && $4==2*w: ldc $1-$3 adi 2*w loc adi loc adi $2==w && $4==w: loc $1+$3 adi w ldc adi ldc adi $2==2*w && $4==2*w: ldc $1+$3 adi 2*w From 374d4aac1701ae012b9e20a30ddb0f334ee88fdd Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 24 Nov 1986 20:42:13 +0000 Subject: [PATCH 0341/1625] Initial revision --- util/topgen/LLlex.c | 129 ++++++++++++++++++ util/topgen/Makefile | 40 ++++++ util/topgen/hash.c | 83 ++++++++++++ util/topgen/main.c | 56 ++++++++ util/topgen/misc.h | 10 ++ util/topgen/pattern.c | 129 ++++++++++++++++++ util/topgen/symtab.c | 48 +++++++ util/topgen/symtab.h | 18 +++ util/topgen/token.h | 10 ++ util/topgen/topgen.g | 307 ++++++++++++++++++++++++++++++++++++++++++ util/topgen/tunable.h | 11 ++ 11 files changed, 841 insertions(+) create mode 100644 util/topgen/LLlex.c create mode 100644 util/topgen/Makefile create mode 100644 util/topgen/hash.c create mode 100644 util/topgen/main.c create mode 100644 util/topgen/misc.h create mode 100644 util/topgen/pattern.c create mode 100644 util/topgen/symtab.c create mode 100644 util/topgen/symtab.h create mode 100644 util/topgen/token.h create mode 100644 util/topgen/topgen.g create mode 100644 util/topgen/tunable.h diff --git a/util/topgen/LLlex.c b/util/topgen/LLlex.c new file mode 100644 index 00000000..3b4b0f53 --- /dev/null +++ b/util/topgen/LLlex.c @@ -0,0 +1,129 @@ +/* L L l e x . c + * + * Very simple lexical analyzer. + * Also contains LLmessage(). + */ +# include +# include +# include "tunable.h" +# include "token.h" +# include "Lpars.h" + +struct token dot; /* current token */ +static struct token aside; /* to put currrent token aside, when a token + * is inserted + */ +int newline, lineno; /* To keep track of linenumbers */ +extern FILE *input; /* file descriptor of machine table */ + +LLlex() { + register c; + + if (aside.t_tokno) { /* A token was pushed aside, return it now */ + dot = aside; + aside.t_tokno = 0; + return dot.t_tokno; + } + if (newline) { /* delayed increment of lineno, needed to give + * correct line numbers in error messages + */ + lineno++; + newline = 0; + } + c = getc(input); + while (c == '/') { /* Could be a comment */ + if ((c = getc(input)) == '*') { + /* Yes, it is a comment */ + int l; + + l = lineno; + do { + do { + if (c == '\n') lineno++; + c = getc(input); + } while (c != '*' && c != EOF); + if (c != EOF) c = getc(input); + } while (c != '/' && c != EOF); + if (c == EOF) { + c = lineno; + lineno = l; + error("Unterminated comment"); + lineno = c; + c = EOF; + } + else c = getc(input); + } + else { + ungetc(c, stdin); + c = '/'; + break; + } + } + dot.t_tokno = c; + dot.t_attrib = c; + if (isupper(c) || islower(c) || c == '_') { + dot.t_tokno = LETTER; + return LETTER; + } + if (isdigit(c)) { + dot.t_tokno = DIGIT; + return DIGIT; + } + switch(c) { + case line_term : + dot.t_tokno = LINE_TERMINATOR; + return LINE_TERMINATOR; + case operand_sep : + dot.t_tokno = OPERAND_SEPARATOR; + return OPERAND_SEPARATOR; + case instruction_sep : + dot.t_tokno = INSTRUCTION_SEPARATOR; + return INSTRUCTION_SEPARATOR; + case '-' : + c = getc(input); + if (c == '>') { + dot.t_tokno = PATTERN_SEPARATOR; + return PATTERN_SEPARATOR; + } + ungetc(c,stdin); + dot.t_tokno = OTHER; + return OTHER; + case open_bracket : + dot.t_tokno = OPEN_BRACKET; + return OPEN_BRACKET; + case close_bracket : + dot.t_tokno = CLOSE_BRACKET; + return CLOSE_BRACKET; + case '\n' : + newline = 1; + /* Fall through */ + case ' ' : + case '\t' : + dot.t_tokno = SPACE; + return SPACE; + case '%' : + case EOF : + return c; + default : + /* Let the C-compiler find out what is illegal! */ + dot.t_tokno = OTHER; + return OTHER; + } +} + +LLmessage(d) { + static int savlineno; + + if (savlineno != lineno) { + /* Only an error message if on another line number */ + savlineno = lineno; + error("Syntax error"); + } + if (d > 0) { + /* "d" is the token to be inserted. + * This is the place to put the current token aside and + * give the inserted token an attribute ... but who cares + */ + aside = dot; + } +} diff --git a/util/topgen/Makefile b/util/topgen/Makefile new file mode 100644 index 00000000..2feeeae7 --- /dev/null +++ b/util/topgen/Makefile @@ -0,0 +1,40 @@ +EM = ../.. +CFLAGS = -O +SOURCE = token.h symtab.h misc.h tunable.h main.c topgen.g LLlex.c symtab.c pattern.c hash.c +CFILES = main.c topgen.c Lpars.c LLlex.c symtab.c pattern.c hash.c +OFILES = main.o topgen.o Lpars.o LLlex.o symtab.o pattern.o hash.o + +all: parser + @make topgen + +cmp: all + cmp topgen $(EM)/lib/topgen + +install: all + cp topgen $(EM)/lib/topgen + +clean: + rm -f topgen *.o Lpars.c Lpars.h topgen.c parser + +parser: topgen.g + $(EM)/bin/LLgen topgen.g + touch parser + +topgen.o: token.h Lpars.h symtab.h misc.h +Lpars.o: Lpars.h +LLlex.o: token.h Lpars.h tunable.h +symtab.o: symtab.h +hash.o: misc.h +pattern.o: misc.h symtab.h + +topgen: $(OFILES) + cc $(OFILES) -o topgen + +lint: parser + lint $(CFILES) + +pr: + @pr $(SOURCE) Makefile + +opr: + make pr ^ opr diff --git a/util/topgen/hash.c b/util/topgen/hash.c new file mode 100644 index 00000000..c8c45826 --- /dev/null +++ b/util/topgen/hash.c @@ -0,0 +1,83 @@ +/* h a s h . c + * + * maintains the the lists of hashed patterns + * Functions : addtohashtable() and printhashtable() + */ +# include +# include "misc.h" + +struct hlist { /* linear list of pattern numbers */ + int h_patno; + struct hlist *h_next; +}; + +static struct hlist *hashtable[129]; /* an array of ptr's to these lists, + * the index in the array is the + * result of hashing + */ + +static unsigned +hash(string) char *string; { + register char *p; + register unsigned i,sum; + + if (strcmp(string,"ANY") == 0) return 128; + for (sum=i=0,p=string;*p;i += 3) + sum += (*p++)<<(i&07); + return sum % 127; +} + + +addtohashtable(s,n) char *s; { + /* + * Add a new pattern number to the hashtable. + * s is the key, n the pattern number + */ + unsigned hval; + register struct hlist *p; + char *malloc(); + + hval = hash(s); + p = (struct hlist *) malloc(sizeof *p); + p->h_patno = n; + /* + * Now insert in front of the list + * This way, the list will be sorted from high to low, which is the + * wrong way around, but easy + */ + p->h_next = hashtable[hval]; + hashtable[hval] = p; +} + +static +prhlist(p) struct hlist *p; { + /* + * Print a list in reversed order (see comment above) + */ + + if (p) { + prhlist(p->h_next); + fprintf(genc,"%d, ",p->h_patno - 1); + } +} + +printhashtable() { + /* + * Print the linear lists, and also output an array of + * pointers to them + */ + register i; + register struct hlist *p; + + for (i = 1; i <= 128; i++) { + fprintf(genc,"int hash%d[] = { ",i); + prhlist(hashtable[i-1]); + fputs("-1};\n",genc); + } + fputs("int hashany[] = { ", genc); + prhlist(hashtable[128]); + fputs("-1 };\n",genc); + fputs("int *hashtab[] = {",genc); + for (i = 1; i <= 128; i++) fprintf(genc,"hash%d,",i); + fputs("hashany};\n",genc); +} diff --git a/util/topgen/main.c b/util/topgen/main.c new file mode 100644 index 00000000..b82b4afc --- /dev/null +++ b/util/topgen/main.c @@ -0,0 +1,56 @@ +/* m a i n . c + * + * Contains the main program, the error reporting routine, and a routine + * to check wether a constraint consists only of space + */ +# include + +extern int lineno, newline; + +FILE *genc, *genh, *input; +static int nerrors; +char *linedir = "#line %d \"%s\"\n"; /* format of line directive */ +char *inpfile; + +main(argc,argv) char *argv[]; { + + newline = 1; + if (argc != 2) { + fprintf(stderr,"Usage : %s targetoptimizerdescription\n",argv[0]); + return 1; + } + if ((input = fopen(argv[1],"r")) == NULL) { + fprintf(stderr,"Fatal error : couldn't open %s\n",argv[1]); + return 1; + } + if ((genc = fopen("gen.c","w")) == NULL) { + fputs("Fatal error : couldn't open gen.c\n",stderr); + return 1; + } + if ((genh = fopen("gen.h","w")) == NULL) { + fputs("Fatal error : couldn't open gen.h\n",stderr); + return 1; + } + inpfile = argv[1]; /* needed for line directives and errors */ + LLparse(); + if (nerrors) return 1; + return 0; +} + +/* VARARGS1 */ +error(s, s1) char *s, *s1; { + + nerrors++; + fprintf(stderr,"\"%s\", line %d: ",inpfile,lineno); + fprintf(stderr,s,s1); + putc('\n',stderr); +} + +onlyspace(s) register char *s; { + + while (*s) { + if (*s != ' ' && *s != '\t' && *s != '\n') return 0; + s++; + } + return 1; +} diff --git a/util/topgen/misc.h b/util/topgen/misc.h new file mode 100644 index 00000000..dcd406d1 --- /dev/null +++ b/util/topgen/misc.h @@ -0,0 +1,10 @@ +/* m i s c . h + * + * Some external declarations + */ +extern int countid; /* # of variables */ +extern int countpat; /* # of patterns */ +extern int lineno; /* line number */ +extern FILE *genc, *genh; /* Output files */ +extern char *inpfile; /* input file name */ +extern char *linedir; /* line directive format */ diff --git a/util/topgen/pattern.c b/util/topgen/pattern.c new file mode 100644 index 00000000..d53f7325 --- /dev/null +++ b/util/topgen/pattern.c @@ -0,0 +1,129 @@ +/* p a t t e r n . c + * + * Deals with the pattern stuff. + * it maintains a table of information about the patterns + * Functions : addpattern() and printpatterns() + */ +# include +# include +# include "misc.h" +# include "symtab.h" + +struct pattern { + char *p_constraint; /* constraint of this pattern */ + int p_lineno, /* line number of constraint */ + p_npat, /* # of instructions in pattern */ + p_nrepl; /* # of instructions in replacement */ +}; + +static struct pattern *pattable, /* ptr to pattern array */ + *current, /* ptr to first unoccupied el of + * pattern array + */ + *maxpat; /* if beyond this, new space must + * be allocated + */ + +addpattern(str,l,np,nr) char *str; { + /* + * Just add a pattern to the list. + * "str" is the constraint, "l" is the line number, + * "np" is the number of instructions in the pattern, + * "nr" is the number of instructions in the replacement + * Space is allocated in chunks of 50 + */ + char *malloc(), *realloc(); + register struct pattern *p; + + if (!pattable) { /* No space allocated yet */ + pattable = (struct pattern *) malloc(50 * sizeof *pattable); + current = pattable; + maxpat = pattable + 50; + } + if (current >= maxpat) { /* Allocate some new space */ + p = pattable; + pattable = (struct pattern *) realloc( + (char *) pattable, + (unsigned) (sizeof *pattable * (50 + (maxpat - pattable)))); + current = pattable + (current - p); + maxpat = pattable + (maxpat - p) + 50; + } + p = current++; + p->p_constraint = str; + p->p_lineno = l; + p->p_npat = np; + p->p_nrepl = nr; +} + +static +prconstraint(str) char *str; { + /* + * prints a constraint, with variable names replaced + */ + char c; + register char *p, *q; + struct symtab *name; + + p = str; + while (*p) { + if (isupper(*p) || islower(*p) || *p == '_') { + /* + * Start of identifier + */ + q = p + 1; + while (*q && ( + isupper(*q) || islower(*q) || isdigit(*q) || *q == '_')) { + q++; + } + c = *q; + *q = '\0'; + /* Temporarily let it end with null byte */ + name = findident(p,LOOKING,&idtable); + if (name) { /* yeah, it was a variable */ + fprintf(genc,"var[%d].value", name->s_num); + } + else fputs(p,genc); + /* Now replace null byte with whatever used to be there */ + *q = c; + p = q; + } + else { + putc(*p,genc); + p++; + } + } +} + +printpatterns() { + /* + * Prints the pattern_descr table and generates the routine + * "check_constraint" + */ + register struct pattern *p; + register i; + + p = pattable; + i = 1; + fputs("struct pattern_descr patterns[] = {\n", genc); + while (p != current) { + fprintf(genc," {%d,pat%d,%d,rep%d,},\n", + p->p_npat, i, p->p_nrepl, i); + p++; + i++; + } + fputs("};\n", genc); + fputs("int\ncheck_constraint(patno){\n\tint r;\n\tswitch(patno){\n",genc); + p = pattable; + while (p < current) { + if (p->p_constraint) { + /* The pattern has a constraint */ + fprintf(genc,"\tcase %d :\n",p - pattable); + fprintf(genc,linedir,p->p_lineno,inpfile); /* linedirective */ + fputs("\tr = (",genc); + prconstraint(p->p_constraint); + fputs("); break;\n",genc); + } + p++; + } + fputs("\tdefault :\n\t\tr = 1;\n\t}\n\treturn r;\n}\n\n",genc); +} diff --git a/util/topgen/symtab.c b/util/topgen/symtab.c new file mode 100644 index 00000000..1d1792bc --- /dev/null +++ b/util/topgen/symtab.c @@ -0,0 +1,48 @@ +/* s y m t a b . c + * + * Contains the routine findident, which builds the symbol table and + * searches identifiers + */ +# include "symtab.h" + +struct symtab *idtable, *deftable; + +struct symtab * +findident(s, mode, table) char *s; struct symtab **table; { + /* + * Look for identifier s in the symboltable referred to by *table. + * If mode = LOOKING, no new entry's will be made. + * If mode = ENTERING, a new entry will be made if s is not in the + * table yet, otherwise an error results + */ + char *malloc(); + char *strcpy(); + register struct symtab *p; + register n; + + if (!*table) { /* No entry for this symbol */ + if (mode == LOOKING) return (struct symtab *) 0; + /* + * Make new entry + */ + p = (struct symtab *) malloc(sizeof *p); + p->s_left = p->s_right = (struct symtab *) 0; + p->s_name = malloc( (unsigned) (strlen(s) + 1)); + strcpy(p->s_name,s); + *table = p; + return p; + } + else { + p = *table; + if ((n = strcmp(p->s_name,s)) == 0) { /* This is it! */ + if (mode == ENTERING) { + error("Identifier %s redefined",s); + } + return p; + } + /* Binary tree ..... */ + if (n < 0) return findident(s,mode,&(p->s_left)); + return findident(s,mode,&(p->s_right)); + } + /* NOTREACHED */ +} diff --git a/util/topgen/symtab.h b/util/topgen/symtab.h new file mode 100644 index 00000000..db61fe05 --- /dev/null +++ b/util/topgen/symtab.h @@ -0,0 +1,18 @@ +/* s y m t a b . h + * + * Contains a structure declaration for a symbol table that is a + * binary tree + */ +struct symtab { + char *s_name; /* The name of the symbol */ + int s_num; /* it's number */ + struct symtab *s_left, *s_right; +}; + +extern struct symtab *idtable, /* table for variables */ + *deftable; /* table for tunable defines */ +struct symtab *findident(); + +/* Options to "findident" */ +#define LOOKING 1 +#define ENTERING 0 diff --git a/util/topgen/token.h b/util/topgen/token.h new file mode 100644 index 00000000..3c5af9fc --- /dev/null +++ b/util/topgen/token.h @@ -0,0 +1,10 @@ +/* t o k e n . h + * + * Contains the structure declaration for a token + */ +struct token { + int t_tokno; /* token number */ + char t_attrib; /* it's attribute (always a character) */ +}; + +extern struct token dot; /* current token */ diff --git a/util/topgen/topgen.g b/util/topgen/topgen.g new file mode 100644 index 00000000..d3413b6c --- /dev/null +++ b/util/topgen/topgen.g @@ -0,0 +1,307 @@ +/* t o p g e n . g + * + * Grammar of optimizer description, and some code generation + */ + +%token LETTER, DIGIT, OTHER, SPACE; +%token LINE_TERMINATOR, OPERAND_SEPARATOR, INSTRUCTION_SEPARATOR, + PATTERN_SEPARATOR, OPEN_BRACKET, CLOSE_BRACKET; +%lexical LLlex; +%start LLparse, optim_description; + +{ +# include +# include "token.h" +# include "symtab.h" +# include "misc.h" + +char idbuf[BUFSIZ], buf[BUFSIZ]; +int countid; /* # of variables */ +int countpat; /* # of patterns */ +char * malloc(); +char * strcpy(); +static int patlen; /* Maximum number of instructions in pattern */ +static int maxoperand; /* Maximum number of operands of instruction */ +extern FILE *input; /* file descriptor of inputfile */ +} + +optim_description + { struct symtab *p; } : + SPACE* parameter_line* + { p = findident("MAXOP",LOOKING,&deftable); + if (p == 0) maxoperand = 2; /* default */ + else maxoperand = p->s_num; + } + separator SPACE* mode_definitions + separator SPACE* patterns + separator user_routines +; + +parameter_line + { struct symtab *p;} : + identifier + { p = findident(idbuf,ENTERING,&deftable);} + SPACE + value + { p->s_num = atoi(buf);} + /* This action in fact only needed for MAXOP */ + LINE_TERMINATOR + SPACE* + { fprintf(genh,"#define %s %s\n",p->s_name,buf);} +; + +value + { char *p1 = buf;} : + [ + [ OPEN_BRACKET + | CLOSE_BRACKET + | OPERAND_SEPARATOR + | PATTERN_SEPARATOR + | INSTRUCTION_SEPARATOR + | SPACE + | LETTER + | DIGIT + | OTHER + | '%' + ] + { *p1++ = dot.t_attrib;} + ]* + { *p1 = '\0';} +; + +mode_definitions + { int lin; } : + { fputs("tok_chk(varno) {\n\tint r;\n", genc); + fputs("\tchar *VAL;\n\n",genc); + fputs("\tVAL = var[varno].value;\n",genc); + fputs("\tswitch(varno) {\n",genc); + } + [ + token_list + constraint(&lin) + { fprintf(genc,linedir,lin,inpfile); + fprintf(genc,"\t\tr = (%s); break;\n",buf); + } + LINE_TERMINATOR + SPACE* + ]* + { fputs("\tdefault :\n\t\tassert(0);\n",genc); + fputs("\t}\n\treturn r;\n}\n\n",genc); + } +; + +token_list : + new_identifier + SPACE* + [ + OPERAND_SEPARATOR + SPACE* + new_identifier + SPACE* + ]* +; + +new_identifier + { struct symtab *p;} : + identifier + { p = findident(idbuf,ENTERING,&idtable); + p->s_num = ++countid; + fprintf(genc,"\tcase %d:\n", countid); + } +; + +constraint (int *lin;) + { char *p = buf; } : + OPEN_BRACKET + { *lin = lineno;} + [ + [ LINE_TERMINATOR + | OPERAND_SEPARATOR + | PATTERN_SEPARATOR + | INSTRUCTION_SEPARATOR + | LETTER + | DIGIT + | SPACE + | OTHER + | '%' + ] + { *p++ = dot.t_attrib;} + ]* + { *p = '\0'; + if (onlyspace(buf)) strcpy(buf,"TRUE"); + } + CLOSE_BRACKET + SPACE* +; + +patterns + { int lin; + char *constr; + int np, nr; + } : +[ + { countpat++; + constr = (char *) 0; + fprintf(genc,"struct instr_descr pat%d[] = {\n", + countpat); + } + instruction_list(&np) + { if (np > patlen) patlen = np; + fputs("\n};\n\n",genc); + } + [ + constraint(&lin) + { /* Save the constraint, we need it later on */ + constr = malloc((unsigned)(strlen(buf)+1)); + strcpy(constr,buf); + } + ]? + PATTERN_SEPARATOR + { fprintf(genc,"struct instr_descr rep%d[] = {\n", + countpat); + } + replacement(&nr) + { fputs("\n};\n\n",genc);} + LINE_TERMINATOR + SPACE* + { addpattern(constr,lin,np,nr);} +]* + { printhashtable(); + printpatterns(); + fprintf(genh,"#define NRVARS %d\n",countid); + fprintf(genh,"#define NRPATTERNS %d\n",countpat); + fprintf(genh,"#define MIN_WINDOW_SIZE %d\n", + patlen+3); + fclose(genh); + } +; + +instruction_list(int *n;) : + instruction(1) + { *n = 1;} + [ + INSTRUCTION_SEPARATOR + { fputs(",\n",genc);} + SPACE* + instruction(0) + { *n += 1;} + ]* +; + +instruction(int opt;) + { int count;} : + opcode(opt) + { if (strcmp(buf,"ANY") != 0) { + fprintf(genc,"\t{\"%s\"",buf); + } + else fputs("\t{(char *) 0",genc); + count = 0; + } + [ + operand + { count = 1;} + [ + OPERAND_SEPARATOR + { count++;} + SPACE* + operand + ]* + { if (count > maxoperand) { + error("Too many operands"); + } + } + ]? + { while (count++ < maxoperand) { + fputs(",{\"\",-1,\"\"}",genc); + } + putc('}',genc); + } +; + +opcode(int opt;) + { char *p = buf;} : + [ + [ LETTER + | DIGIT + | OTHER + ] + { *p++ = dot.t_attrib;} + ]+ + SPACE+ + { *p = '\0'; + if (opt) addtohashtable(buf,countpat); + } +; + +operand + { register struct symtab *p = 0;} : + { fputs(",{\"",genc);} + [ + identifier + { if (!p) { + p = findident(idbuf,LOOKING,&idtable); + if (p) fprintf(genc,"\",%d,\"",p->s_num); + else fputs(idbuf,genc); + } + else fputs(idbuf,genc); + } + | DIGIT + { putc(dot.t_attrib,genc);} + | OTHER + { putc(dot.t_attrib,genc);} + ]+ + { if (p) fputs("\"}",genc); + else fputs("\",0,\"\"}",genc); + } + SPACE* +; + +replacement (int *n;) + {register i;} : + SPACE* + { *n = 0;} + [ + instruction(0) + { *n = 1;} + [ + INSTRUCTION_SEPARATOR + { fputs(",\n", genc);} + SPACE* + instruction(0) + { *n += 1;} + ]* + | /* empty replacement, but there must be a + * structure initializer anyway + */ + { fputs("\t{\"\"",genc); + for (i = 0; i < maxoperand; i++) { + fputs(",{\"\",-1,\"\"}",genc); + } + putc('}',genc); + } + ] +; + +user_routines + {register c;} : + { fprintf(genc, linedir, lineno, inpfile); + while ((c = getc(input)) != EOF) { + putc(c,genc); + } + } +; + +identifier + { char *p = idbuf; } : + LETTER + { *p++ = dot.t_attrib;} + [ %while (1) + LETTER { *p++ = dot.t_attrib;} + | DIGIT { *p++ = dot.t_attrib;} + ]* + { *p = '\0';} +; + +separator : + '%' '%' SPACE* LINE_TERMINATOR +; diff --git a/util/topgen/tunable.h b/util/topgen/tunable.h new file mode 100644 index 00000000..e79f3820 --- /dev/null +++ b/util/topgen/tunable.h @@ -0,0 +1,11 @@ +/* t u n a b l e . h + * + * Contains some tunable constants. + * They should all differ, not be a letter or digit or '_', not be a '%', + * and not be space (' ','\t','\n' and the like). + */ +# define line_term ';' +# define operand_sep ',' +# define instruction_sep ':' +# define open_bracket '{' +# define close_bracket '}' From 0e38359528237bb35d352dfff898ebbdb79dbda3 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 24 Nov 1986 20:58:35 +0000 Subject: [PATCH 0342/1625] Initial revision --- mach/arm/top/Makefile | 41 +++ mach/m68020/top/Makefile | 41 +++ mach/m68k2/top/Makefile | 41 +++ mach/pdp/top/Makefile | 41 +++ mach/proto/top/Makefile | 41 +++ mach/proto/top/queue.c | 72 +++++ mach/proto/top/queue.h | 12 + mach/proto/top/top.c | 651 +++++++++++++++++++++++++++++++++++++++ mach/proto/top/top.h | 88 ++++++ mach/vax4/top/Makefile | 41 +++ mach/vax4/top/table | 287 +++++++++++++++++ 11 files changed, 1356 insertions(+) create mode 100644 mach/arm/top/Makefile create mode 100644 mach/m68020/top/Makefile create mode 100644 mach/m68k2/top/Makefile create mode 100644 mach/pdp/top/Makefile create mode 100644 mach/proto/top/Makefile create mode 100644 mach/proto/top/queue.c create mode 100644 mach/proto/top/queue.h create mode 100644 mach/proto/top/top.c create mode 100644 mach/proto/top/top.h create mode 100644 mach/vax4/top/Makefile create mode 100644 mach/vax4/top/table diff --git a/mach/arm/top/Makefile b/mach/arm/top/Makefile new file mode 100644 index 00000000..37628d51 --- /dev/null +++ b/mach/arm/top/Makefile @@ -0,0 +1,41 @@ +EM=../../.. +PREFLAGS=-I. +PFLAGS= +CFLAGS=$(PREFLAGS) $(PFLAGS) -O +LDFLAGS=-i $(PFLAGS) +LINTOPTS=-hbxac +CDIR=$(EM)/mach/proto/top +CFILES=$(CDIR)/top.c $(CDIR)/queue.c gen.c +OFILES=top.o queue.o gen.o + +all: gen.c + make top + +top: $(OFILES) + $(CC) $(LDFLAGS) $(OFILES) $(LIBS) -o top + +top.o: $(CDIR)/top.c + $(CC) -c $(CFLAGS) $(CDIR)/top.c + +queue.o: $(CDIR)/queue.c + $(CC) -c $(CFLAGS) $(CDIR)/queue.c + +install: all + $(EM)/mach/install top + +cmp: all + -$(EM)/mach/compare top + +gen.c: table + $(EM)/lib/topgen table + +lint: $(CFILES) + lint $(LINTOPTS) $(PREFLAGS) $(CFILES) + +clean: + rm -f *.o gen.c gen.h top + +top.o: gen.h +top.o: $(CDIR)/top.h +top.o: $(CDIR)/queue.h +queue.o: $(CDIR)/queue.h diff --git a/mach/m68020/top/Makefile b/mach/m68020/top/Makefile new file mode 100644 index 00000000..37628d51 --- /dev/null +++ b/mach/m68020/top/Makefile @@ -0,0 +1,41 @@ +EM=../../.. +PREFLAGS=-I. +PFLAGS= +CFLAGS=$(PREFLAGS) $(PFLAGS) -O +LDFLAGS=-i $(PFLAGS) +LINTOPTS=-hbxac +CDIR=$(EM)/mach/proto/top +CFILES=$(CDIR)/top.c $(CDIR)/queue.c gen.c +OFILES=top.o queue.o gen.o + +all: gen.c + make top + +top: $(OFILES) + $(CC) $(LDFLAGS) $(OFILES) $(LIBS) -o top + +top.o: $(CDIR)/top.c + $(CC) -c $(CFLAGS) $(CDIR)/top.c + +queue.o: $(CDIR)/queue.c + $(CC) -c $(CFLAGS) $(CDIR)/queue.c + +install: all + $(EM)/mach/install top + +cmp: all + -$(EM)/mach/compare top + +gen.c: table + $(EM)/lib/topgen table + +lint: $(CFILES) + lint $(LINTOPTS) $(PREFLAGS) $(CFILES) + +clean: + rm -f *.o gen.c gen.h top + +top.o: gen.h +top.o: $(CDIR)/top.h +top.o: $(CDIR)/queue.h +queue.o: $(CDIR)/queue.h diff --git a/mach/m68k2/top/Makefile b/mach/m68k2/top/Makefile new file mode 100644 index 00000000..37628d51 --- /dev/null +++ b/mach/m68k2/top/Makefile @@ -0,0 +1,41 @@ +EM=../../.. +PREFLAGS=-I. +PFLAGS= +CFLAGS=$(PREFLAGS) $(PFLAGS) -O +LDFLAGS=-i $(PFLAGS) +LINTOPTS=-hbxac +CDIR=$(EM)/mach/proto/top +CFILES=$(CDIR)/top.c $(CDIR)/queue.c gen.c +OFILES=top.o queue.o gen.o + +all: gen.c + make top + +top: $(OFILES) + $(CC) $(LDFLAGS) $(OFILES) $(LIBS) -o top + +top.o: $(CDIR)/top.c + $(CC) -c $(CFLAGS) $(CDIR)/top.c + +queue.o: $(CDIR)/queue.c + $(CC) -c $(CFLAGS) $(CDIR)/queue.c + +install: all + $(EM)/mach/install top + +cmp: all + -$(EM)/mach/compare top + +gen.c: table + $(EM)/lib/topgen table + +lint: $(CFILES) + lint $(LINTOPTS) $(PREFLAGS) $(CFILES) + +clean: + rm -f *.o gen.c gen.h top + +top.o: gen.h +top.o: $(CDIR)/top.h +top.o: $(CDIR)/queue.h +queue.o: $(CDIR)/queue.h diff --git a/mach/pdp/top/Makefile b/mach/pdp/top/Makefile new file mode 100644 index 00000000..37628d51 --- /dev/null +++ b/mach/pdp/top/Makefile @@ -0,0 +1,41 @@ +EM=../../.. +PREFLAGS=-I. +PFLAGS= +CFLAGS=$(PREFLAGS) $(PFLAGS) -O +LDFLAGS=-i $(PFLAGS) +LINTOPTS=-hbxac +CDIR=$(EM)/mach/proto/top +CFILES=$(CDIR)/top.c $(CDIR)/queue.c gen.c +OFILES=top.o queue.o gen.o + +all: gen.c + make top + +top: $(OFILES) + $(CC) $(LDFLAGS) $(OFILES) $(LIBS) -o top + +top.o: $(CDIR)/top.c + $(CC) -c $(CFLAGS) $(CDIR)/top.c + +queue.o: $(CDIR)/queue.c + $(CC) -c $(CFLAGS) $(CDIR)/queue.c + +install: all + $(EM)/mach/install top + +cmp: all + -$(EM)/mach/compare top + +gen.c: table + $(EM)/lib/topgen table + +lint: $(CFILES) + lint $(LINTOPTS) $(PREFLAGS) $(CFILES) + +clean: + rm -f *.o gen.c gen.h top + +top.o: gen.h +top.o: $(CDIR)/top.h +top.o: $(CDIR)/queue.h +queue.o: $(CDIR)/queue.h diff --git a/mach/proto/top/Makefile b/mach/proto/top/Makefile new file mode 100644 index 00000000..37628d51 --- /dev/null +++ b/mach/proto/top/Makefile @@ -0,0 +1,41 @@ +EM=../../.. +PREFLAGS=-I. +PFLAGS= +CFLAGS=$(PREFLAGS) $(PFLAGS) -O +LDFLAGS=-i $(PFLAGS) +LINTOPTS=-hbxac +CDIR=$(EM)/mach/proto/top +CFILES=$(CDIR)/top.c $(CDIR)/queue.c gen.c +OFILES=top.o queue.o gen.o + +all: gen.c + make top + +top: $(OFILES) + $(CC) $(LDFLAGS) $(OFILES) $(LIBS) -o top + +top.o: $(CDIR)/top.c + $(CC) -c $(CFLAGS) $(CDIR)/top.c + +queue.o: $(CDIR)/queue.c + $(CC) -c $(CFLAGS) $(CDIR)/queue.c + +install: all + $(EM)/mach/install top + +cmp: all + -$(EM)/mach/compare top + +gen.c: table + $(EM)/lib/topgen table + +lint: $(CFILES) + lint $(LINTOPTS) $(PREFLAGS) $(CFILES) + +clean: + rm -f *.o gen.c gen.h top + +top.o: gen.h +top.o: $(CDIR)/top.h +top.o: $(CDIR)/queue.h +queue.o: $(CDIR)/queue.h diff --git a/mach/proto/top/queue.c b/mach/proto/top/queue.c new file mode 100644 index 00000000..3cf1e59c --- /dev/null +++ b/mach/proto/top/queue.c @@ -0,0 +1,72 @@ +#include "top.h" +#include "queue.h" + +empty_queue(q) + queue q; +{ + q->head = q->tail = (instr_p) 0; + q->qlen = 0; +} + +int empty(q) + queue q; +{ + return q->qlen == 0; +} + +remove_head(q) + queue q; +{ + if ( (q->head = q->head->fw) == (instr_p) 0) { + q->tail = (instr_p) 0; + } else { + q->head->bw = (instr_p) 0; + } + q->qlen--; +} + +add(q,instr) + register queue q; + register instr_p instr; +{ + if (q->qlen++ == 0) { + q->head = q->tail = instr; + instr->bw = (instr_p) 0; + } else { + q->tail->fw = instr; + instr->bw = q->tail; + q->tail = instr; + } + instr->fw = (instr_p) 0; +} + +insert(q,instr) + queue q; + instr_p instr; +{ + if (q->qlen++ == 0) { + q->head = q->tail = instr; + instr->fw = (instr_p) 0; + } else { + q->head->bw = instr; + instr->fw = q->head; + q->head = instr; + } + instr->bw = (instr_p) 0; +} + +join_queues(q1,q2) + queue q1,q2; +{ + if (q1->qlen > 0) { + q2->qlen += q1->qlen; + q1->tail->fw = q2->head; + if (q2->qlen > 0) { + q2->head->bw = q1->tail; + } else { + q2->tail = q1->tail; + } + q2->head = q1->head; + empty_queue(q1); + } +} diff --git a/mach/proto/top/queue.h b/mach/proto/top/queue.h new file mode 100644 index 00000000..d2adebf0 --- /dev/null +++ b/mach/proto/top/queue.h @@ -0,0 +1,12 @@ +typedef struct item *item_p; +typedef struct queue_t *queue; + +struct queue_t { + instr_p head; + instr_p tail; + int qlen; +}; + +#define qhead(q) (q)->head +#define qlength(q) (q)->qlen +#define next(x) (x)->fw diff --git a/mach/proto/top/top.c b/mach/proto/top/top.c new file mode 100644 index 00000000..11ea8247 --- /dev/null +++ b/mach/proto/top/top.c @@ -0,0 +1,651 @@ +#include +#include "gen.h" +#include "top.h" +#include "queue.h" + +/* STANDARD MACHINE-INDEPENT C CODE *************/ + +extern char *lstrip(); +extern instr_p newinstr(); +extern instr_p read_instr(); +extern instr_p gen_instr(); +extern char *eval_templ(); +extern instr_p malloc(); + +struct variable var[NRVARS+1]; +struct variable ANY; /* ANY symbol matching any instruction */ + +char *REST; /* Opcode of first instruction not matched by current pattern */ + +#include "gen.c" + + +/* Macros for efficiency: */ + +#define is_white(c) ( (c) == ' ' || (c) == '\t') + +/* Skip white space in the unprocessed part of instruction 'ip' */ +#define skip_white(ip) while (is_white(*(ip)->rest_line)) (ip)->rest_line++ + +main() +{ + optimize(); + exit(0); +} + + +/* Optimize the standard input. + * The optimizer uses a moving window. The instructions in the current + * window are matched against a set of patterns generated from the + * machine description table. If the match fails, the first instruction of + * the window is moved to a back-up queue and a new instruction is + * read from the input and appended to the end of the window. + * If a matching pattern is found (and its operands etc. are ok), + * the instructions at the head of the window are replaced by new + * instructions, as indicated in the descriptor table; a new window + * is created, consisting of the back-up instructions and the new + * instructions and the rest of the old window. So effectively the + * window moves a bit to the left after every hit. Hence sequences of + * optimizations like: + * movl r0,x ; cmpl $0,x -> movl r0,x ; tstl x -> movl r0,x + * are captured without having a separate pattern for "movl ; cmpl". + * + * Whenever the backup queue exceeds some threshold, its first instruction + * is written to the output and is removed. + */ + +optimize() +{ + struct queue_t windowq, backupq; + queue window, backup; + instr_p ip; + bool change; + + window = &windowq; + backup = &backupq; + empty_queue(window); + empty_queue(backup); + fill_window(window,MIN_WINDOW_SIZE); + while (!empty(window)) { + if (try_hashentry(hashtab[hash(window)],window) || + try_hashentry(hashany,window)) { + join_queues(backup,window); + } else { + ip = qhead(window); + remove_head(window); + add(backup,ip); + if (qlength(backup) > MIN_WINDOW_SIZE) { + write_first(backup); + } + } + fill_window(window,MIN_WINDOW_SIZE); + } + while (!empty(backup)) write_first(backup); +} + + + +bool try_hashentry(list,window) + int *list; + queue window; +{ + int *pp; + patdescr_p p; + + for (pp = list; *pp != -1; pp++) { + p = &patterns[*pp]; + if (check_pattern(p,window) && + check_operands(p,window) && + check_constraint(p-patterns)) { + xform(p,window); + return TRUE; + } + } + return FALSE; +} + + +/* TEMP. */ + +/* int hash(w) + queue w; +{ + instr_p ip; + + ip = qhead(w); + return ip->opc[0] % 31; +} +*/ + + +int hash(w) + queue w; +{ + register char *p; + register sum,i; + instr_p ip; + + ip = qhead(w); +/* for (sum=0,p=ip->opc;*p;p++) + sum += *p; +*/ + + for (sum=i=0,p=ip->opc;*p;i += 3) + sum += (*p++)<<(i&07); + return(sum%127); +} + +/* Fill the working window until it contains at least 'len' items. + * When end-of-file is encountered it may contain fewer items. + */ + +fill_window(w,len) + queue w; +{ + instr_p ip; + + while(qlength(w) < len) { + if ((ip = read_instr()) == NIL) break; + ip->rest_line = ip->line; + set_opcode(ip); + add(w,ip); + } +} + +write_first(w) + queue w; +{ + instr_p ip; + + write_instr(ip = qhead(w)); + remove_head(w); + oldinstr(ip); +} + + +/* Try to recognize the opcode part of an instruction */ + +set_opcode(ip) + instr_p ip; +{ + register char *p,*q; + char *qlim; + + if (ip->state == JUNK) return; + skip_white(ip); + p = ip->rest_line; + if (*p == LABEL_STARTER) { + strcpy(ip->opc,"labdef"); + ip->state = ONLY_OPC; + return; + } + q = ip->opc; + qlim = q + MAX_OPC_LEN; + while(*p != OPC_TERMINATOR && *p != '\n') { + if (q == qlim) { + ip->state = JUNK; + return; + } + *q++ = *p++; + } + *q = '\0'; + ip->rest_line = p; + ip->state = (well_shaped(ip->opc) ? ONLY_OPC : JUNK); +} + + + +/* Check if pattern 'p' matches the current input */ + +bool check_pattern(p,w) + patdescr_p p; + queue w; +{ + register idescr_p id_p; + idescr_p idlim; + register instr_p ip; + + ip = qhead(w); + ANY.vstate = UNINSTANTIATED; + idlim = &p->pat[p->patlen]; + for (id_p = p->pat; id_p < idlim; id_p++) { + if (ip == NIL || ip->state == JUNK) return FALSE; + if (id_p->opcode == (char *) 0) { + unify(ip->opc,&ANY); + } else { + if (strcmp(ip->opc,id_p->opcode) != 0) return FALSE; + } + ip = next(ip); + } + REST = ip->opc; + return TRUE; +} + + + +bool check_operands(p,w) + patdescr_p p; + queue w; +{ + instr_p ip; + idescr_p id_p; + int n; + + /* fprintf(stderr,"try pattern %d\n",p-patterns); */ + clear_vars(); + for (id_p = p->pat, ip = qhead(w); id_p < &p->pat[p->patlen]; + id_p++, ip = next(ip)) { + assert(ip != NIL); + if (ip->state == JUNK || + (ip->state == ONLY_OPC && !split_operands(ip))) { + return FALSE; + } + for (n = 0; n < MAXOP; n++) { + if (!opmatch(&id_p->templates[n],ip->op[n])) { + return FALSE; + } + } + } + /* fprintf(stderr,"yes\n"); */ + return TRUE; +} + + + +/* Reset all variables to uninstantiated */ + +clear_vars() +{ + register v; + + for (v = 1; v <= NRVARS; v++) var[v].vstate = UNINSTANTIATED; +} + + +/* See if operand 's' matches the operand described by template 't'. + * As a side effect, any uninstantiated variables used in the + * template may become instantiated. For such a variable we also + * check if it satisfies the constraint imposed on it in the + * mode-definitions part of the table. + */ + +bool opmatch(t,s) + templ_p t; + char *s; +{ + char *l, buf[MAXOPLEN]; + bool was_instantiated; + int vno; + + vno = t->varno; + if (vno == -1 || s[0] == '\0' ) { + return (vno == -1 && s[0] == '\0'); + } + was_instantiated = (var[vno].vstate == INSTANTIATED); + strcpy(buf,s); + if ( (l=lstrip(buf,t->lctxt)) != NULLSTRING && rstrip(l,t->rctxt)) { + return vno == 0 || (unify(l,&var[vno]) && + (was_instantiated || tok_chk(vno))); + } + return FALSE; +} + + + +/* Try to recognize the operands of an instruction */ + +bool split_operands(ip) + instr_p ip; +{ + int i; + bool res; + + if (strcmp(ip->opc,"labdef") ==0) { + labeldef(ip); + } else { + for (i = 0; operand(ip,i) && op_separator(ip); i++); + } + res = remainder_empty(ip); + ip->state = (res ? DONE : JUNK); + return res; +} + + + +labeldef(ip) + instr_p ip; +{ + char *p; + int oplen; + + p = ip->rest_line; + while( *p != LABEL_TERMINATOR) p++; + oplen = p - ip->rest_line; + if (oplen == 0 || oplen > MAXOPLEN) return; + strncpy(ip->op[0],ip->rest_line,oplen); + ip->op[0][oplen] = '\0'; + ip->rest_line = ++p; + return; +} + + + + +/* Try to recognize the next operand of instruction 'ip' */ + +bool operand(ip,n) + register instr_p ip; +{ + register char *p; + int oplen; + + skip_white(ip); + p = ip->rest_line; + while( *p != OP_SEPARATOR && *p != '\n') p++; + oplen = p - ip->rest_line; + if (oplen == 0 || oplen > MAXOPLEN) return FALSE; + strncpy(ip->op[n],ip->rest_line,oplen); + ip->op[n][oplen] = '\0'; + ip->rest_line = p; + return TRUE; +} + + + +/* See if the unprocessed part of instruction 'ip' is empty + * (or contains only white space). + */ + +bool remainder_empty(ip) + instr_p ip; +{ + skip_white(ip); + return *ip->rest_line == '\n'; +} + + +/* Try to match 'ctxt' at the beginning of string 'str'. If this + * succeeds then return a pointer to the rest (unmatched part) of 'str'. + */ + +char *lstrip(str,ctxt) + register char *str, *ctxt; +{ + assert(ctxt != NULLSTRING); + while (*str != '\0' && *str == *ctxt) { + str++; + ctxt++; + } + return (*ctxt == '\0' ? str : NULLSTRING); +} + + + +/* Try to match 'ctxt' at the end of 'str'. If this succeeds then + * replace truncate 'str'. + */ + +bool rstrip(str,ctxt) + char *str,*ctxt; +{ + register char *s, *c; + + for (s = str; *s != '\0'; s++); + for (c = ctxt; *c != '\0'; c++); + while (c >= ctxt) { + if (s < str || *s != *c--) return FALSE; + *s-- = '\0'; + } + return TRUE; +} + + + +/* Try to unify variable 'v' with string 'str'. If the variable + * was instantiated the unification only succeeds if the variable + * and the string match; else the unification succeeds and the + * variable becomes instantiated to the string. + */ + +bool unify(str,v) + char *str; + struct variable *v; +{ + if (v->vstate == UNINSTANTIATED) { + v->vstate = INSTANTIATED; + strcpy(v->value,str); + return TRUE; + } else { + return strcmp(v->value,str) == 0; + } +} + + + +/* Transform the working window according to pattern 'p' */ + +xform(p,w) + patdescr_p p; + queue w; +{ + register instr_p ip; + int i; + + for (i = 0; i < p->patlen; i++) { + ip = qhead(w); + remove_head(w); + oldinstr(ip); + } + replacement(p,w); +} + + + +/* Generate the replacement for pattern 'p' and insert it + * at the front of the working window. + * Note that we generate instructions in reverser order. + */ + +replacement(p,w) + patdescr_p p; + queue w; +{ + idescr_p id_p; + + for (id_p = &p->repl[p->replen-1]; id_p >= p->repl; id_p--) { + insert(w,gen_instr(id_p)); + } +} + + + +/* Generate an instruction described by 'id_p'. + * We build a 'line' for the new instruction and call set_opcode() + * to re-recognize its opcode. Hence generated instructions are treated + * in exactly the same way as normal instructions that are just read in. + */ + +instr_p gen_instr(id_p) + idescr_p id_p; +{ + char *opc; + instr_p ip; + templ_p t; + register char *s; + bool islabdef; + int n; + static char tmp[] = "x"; + + ip = newinstr(); + s = ip->line; + opc = id_p->opcode; + if (opc == (char *) 0) opc = ANY.value; + if (strcmp(opc,"labdef") == 0) { + islabdef = TRUE; + s[0] = '\0'; + } else { + strcpy(s,opc); + tmp[0] = OPC_TERMINATOR; + strcat(s,tmp); + islabdef = FALSE; + } + for (n = 0; n < MAXOP;) { + t = &id_p->templates[n++]; + if (t->varno == -1) break; + strcat(s,t->lctxt); + if (t->varno != 0) strcat(s,var[t->varno].value); + strcat(s,t->rctxt); + if (ntemplates[n].varno!=-1) { + tmp[0] = OP_SEPARATOR; + strcat(s,tmp); + } + } + if (islabdef) { + tmp[0] = LABEL_TERMINATOR; + strcat(s,tmp); + } + strcat(s,"\n"); + ip->rest_line = ip->line; + set_opcode(ip); + return ip; +} + + + +/* Reading and writing instructions. + * An instruction is assumed to be on one line. The line + * is copied to the 'line' field of an instruction struct, + * terminated by a \n and \0. If the line is too long (>MAXLINELEN), + * it is split into pieces of length MAXLINELEN and the state of + * each such struct is set to JUNK (so it will not be optimized). + */ + +static bool junk_state = FALSE; /* TRUE while processing a very long line */ + +instr_p read_instr() +{ + register instr_p ip; + register int c; + register char *p; + char *plim; + + ip = newinstr(); + plim = &ip->line[MAXLINELEN]; + if (( c = getchar()) == EOF) return NIL; + for (p = ip->line; p < plim;) { + *p++ = c; + if (c == '\n') { + *p = '\0'; + if (junk_state) ip->state = JUNK; + junk_state = FALSE; + return ip; + } + c = getchar(); + } + ungetc(c,stdin); + *p = '\0'; + junk_state = ip->state = JUNK; + return ip; +} + + +write_instr(ip) + instr_p ip; +{ + register char *p; + + for (p = ip->line; *p != '\0'; p++) { + putchar(*p); + } +} + + + +/* Core allocation. + * As all instruction struct have the same size we can re-use every struct. + * We maintain a pool of free instruction structs. + */ + +static instr_p instr_pool; +int nr_mallocs = 0; /* for statistics */ + +instr_p newinstr() +{ + register instr_p ip; + int i; + + if (instr_pool == NIL) { + instr_pool = malloc(sizeof(struct instruction)); + nr_mallocs++; + } + assert(instr_pool != NIL); + ip = instr_pool; + instr_pool = instr_pool->fw; + ip->fw = ip->bw = NIL; + ip->rest_line = NULLSTRING; + ip->line[0] = ip->opc[0] = '\0'; + ip->state = ONLY_OPC; + for (i = 0; i < MAXOP; i++) ip->op[i][0] = '\0'; + return ip; +} + +oldinstr(ip) + instr_p ip; +{ + ip->fw = instr_pool; + instr_pool = ip; +} + + + +/* Debugging stuff */ + +badassertion(file,line) + char *file; + unsigned line; +{ + fprintf(stderr,"assertion failed file %s, line %u\n",file,line); + error("assertion"); +} + +/* VARARGS1 */ +error(s,a) + char *s,*a; +{ + fprintf(stderr,s,a); + fprintf(stderr,"\n"); + _cleanup(); + abort(); + exit(-1); +} + +/* Low level routines */ + +bool op_separator(ip) + instr_p ip; +{ + skip_white(ip); + if (*(ip->rest_line) == OP_SEPARATOR) { + ip->rest_line++; + return TRUE; + } else { + return FALSE; + } +} + + + +bool well_shaped(opc) + char *opc; +{ + return is_letter(opc[0]); +} + + +bool is_letter(c) +{ + return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); +} + +/* is_white(c) : turned into a macro, see beginning of file */ + diff --git a/mach/proto/top/top.h b/mach/proto/top/top.h new file mode 100644 index 00000000..899b7fe2 --- /dev/null +++ b/mach/proto/top/top.h @@ -0,0 +1,88 @@ +/* Tunable constants; may be overruled by machine descriptor table */ + +#ifndef OP_SEPARATOR +#define OP_SEPARATOR ',' +#endif +#ifndef LABEL_TERMINATOR +#define LABEL_TERMINATOR ':' +#endif +#ifndef LABEL_STARTER +#define LABEL_STARTER 'I' +#endif +#ifndef OPC_TERMINATOR +#define OPC_TERMINATOR ' ' +#endif + +#ifndef MAX_OPC_LEN +#define MAX_OPC_LEN 10 +#endif +#ifndef MAXOPLEN +#define MAXOPLEN 25 +#endif +#ifndef MAXOP +#define MAXOP 2 +#endif +#ifndef MAXLINELEN +#define MAXLINELEN 100 +#endif +#ifndef MAXVARLEN +#define MAXVARLEN 25 +#endif + + +typedef struct instruction *instr_p; +typedef struct pattern_descr *patdescr_p; +typedef struct instr_descr *idescr_p; +typedef struct template *templ_p; + +struct instruction { + instr_p fw; + instr_p bw; + char line[MAXLINELEN+1]; + char *rest_line; + char opc[MAX_OPC_LEN+1]; + char op[MAXOP][MAXOPLEN+1]; + short state; +}; + +/* state: */ +#define ONLY_OPC 0 +#define JUNK 1 +#define DONE 2 + +struct variable { + int vstate; + char value[MAXVARLEN]; +}; + +/* vstate: */ +#define UNINSTANTIATED 0 +#define INSTANTIATED 1 + +struct pattern_descr { + int patlen; + idescr_p pat; + int replen; + idescr_p repl; +}; + +struct template { + char *lctxt; + int varno; + char *rctxt; +}; + +struct instr_descr { + char *opcode; + struct template templates[MAXOP]; +}; + +typedef int bool; + +#define TRUE 1 +#define FALSE 0 + +#define NIL (instr_p) 0 +#define NULLSTRING (char *) 0 + +#define assert(x) if(!(x)) badassertion(__FILE__,__LINE__) diff --git a/mach/vax4/top/Makefile b/mach/vax4/top/Makefile new file mode 100644 index 00000000..37628d51 --- /dev/null +++ b/mach/vax4/top/Makefile @@ -0,0 +1,41 @@ +EM=../../.. +PREFLAGS=-I. +PFLAGS= +CFLAGS=$(PREFLAGS) $(PFLAGS) -O +LDFLAGS=-i $(PFLAGS) +LINTOPTS=-hbxac +CDIR=$(EM)/mach/proto/top +CFILES=$(CDIR)/top.c $(CDIR)/queue.c gen.c +OFILES=top.o queue.o gen.o + +all: gen.c + make top + +top: $(OFILES) + $(CC) $(LDFLAGS) $(OFILES) $(LIBS) -o top + +top.o: $(CDIR)/top.c + $(CC) -c $(CFLAGS) $(CDIR)/top.c + +queue.o: $(CDIR)/queue.c + $(CC) -c $(CFLAGS) $(CDIR)/queue.c + +install: all + $(EM)/mach/install top + +cmp: all + -$(EM)/mach/compare top + +gen.c: table + $(EM)/lib/topgen table + +lint: $(CFILES) + lint $(LINTOPTS) $(PREFLAGS) $(CFILES) + +clean: + rm -f *.o gen.c gen.h top + +top.o: gen.h +top.o: $(CDIR)/top.h +top.o: $(CDIR)/queue.h +queue.o: $(CDIR)/queue.h diff --git a/mach/vax4/top/table b/mach/vax4/top/table new file mode 100644 index 00000000..ea754dd4 --- /dev/null +++ b/mach/vax4/top/table @@ -0,0 +1,287 @@ +/* VAX descriptor table for ACK target optimizer, + * Prolog prototype + */ + +/* tunable constants-> */ + +MAXOP 4; +MAXLINELEN 50; +LABEL_STARTER 'L'; +OPC_TERMINATOR ' '; + +%%; + +ZERO {strcmp(VAL,"$0") == 0}; +ONE {strcmp(VAL,"$1") == 0}; +M_ONE {strcmp(VAL,"$-1") == 0}; +CONST {VAL[0] == '$'}; +NUM,NUM1 {is_number(VAL)}; +REG {is_register(VAL)}; +SREG {is_scratchreg(VAL)}; +LAB,LAB2 {VAL[0] == 'L'}; +A,B {no_side_effects(VAL) }; +X,Y,LOG {TRUE}; + +%%; + +movab 1(X),X -> incl X; +movab -1(X),X -> decl X; + +movzbw ZERO,X -> clrw X; +movzbl ZERO,X -> clrl X; +movb ZERO,X -> clrb X; +movw ZERO,X -> clrw X; +movl ZERO,X -> clrl X; +cvtbw ZERO,X -> clrw X; +cvtww ZERO,X -> clrw X; +cvtbl ZERO,X -> clrl X; +cvtwl ZERO,X -> clrl X; + +/* change 3-operand instructions to 2-operand instructions */ + +addw3 X,Y,Y -> addw2 X,Y; +addl3 X,Y,Y -> addl2 X,Y; +addf3 X,Y,Y -> addf2 X,Y; +addd3 X,Y,Y -> addd2 X,Y; + +addw3 X,Y,X -> addw2 Y,X; +addl3 X,Y,X -> addl2 Y,X; +addf3 X,Y,X -> addf2 Y,X; +addd3 X,Y,X -> addd2 Y,X; + +subw3 X,Y,Y -> subw2 X,Y; +subl3 X,Y,Y -> subl2 X,Y; +subf3 X,Y,Y -> subf2 X,Y; +subd3 X,Y,Y -> subd2 X,Y; + +mulw3 X,Y,Y -> mulw2 X,Y; +mull3 X,Y,Y -> mull2 X,Y; +mulf3 X,Y,Y -> mulf2 X,Y; +muld3 X,Y,Y -> muld2 X,Y; + +mulw3 X,Y,X -> mulw2 Y,X; +mull3 X,Y,X -> mull2 Y,X; +mulf3 X,Y,X -> mulf2 Y,X; +muld3 X,Y,X -> muld2 Y,X; + +divw3 X,Y,Y -> divw2 X,Y; +divl3 X,Y,Y -> divl2 X,Y; +divf3 X,Y,Y -> divf2 X,Y; +divd3 X,Y,Y -> divd2 X,Y; + +xorw3 X,Y,Y -> xorw2 X,Y; +xorl3 X,Y,Y -> xorl2 X,Y; + +bisw3 X,Y,Y -> bisw2 X,Y; +bisl3 X,Y,Y -> bisl2 X,Y; +bisw3 X,Y,X -> bisw2 Y,X; +bisl3 X,Y,X -> bisl2 Y,X; + +bicw3 X,Y,Y -> bicw2 X,Y; +bicl3 X,Y,Y -> bicl2 X,Y; + +/* eliminate negative constants */ + +addw2 $-NUM,X -> subw2 $NUM,X; +addl2 $-NUM,X -> subl2 $NUM,X; +addw3 $-NUM,X,Y -> subw3 $NUM,X,Y; +addl3 $-NUM,X,Y -> subl3 $NUM,X,Y; +addw3 X,$-NUM,Y -> subw3 $NUM,X,Y; +addl3 X,$-NUM,Y -> subl3 $NUM,X,Y; + +subw2 $-NUM,X -> addw2 $NUM,X; +subl2 $-NUM,X -> addl2 $NUM,X; +subw3 $-NUM,X,Y -> addw3 $NUM,X,Y; +subl3 $-NUM,X,Y -> addl3 $NUM,X,Y; +subw3 X,$-NUM,Y -> addw3 $NUM,X,Y; +subl3 X,$-NUM,Y -> addl3 $NUM,X,Y; + +/* use special instructions */ + +addw2 ONE,X -> incw X; +addl2 ONE,X -> incl X; +subw2 ONE,X -> decw X; +subl2 ONE,X -> decl X; + +addw2 M_ONE,X -> decw X; +addl2 M_ONE,X -> decl X; +subw2 M_ONE,X -> incw X; +subl2 M_ONE,X -> incl X; + +bitw $NUM,A : jneq LAB + {is_poweroftwo(NUM,LOG)}-> jbs $LOG,A,LAB; +bitl $NUM,A : jneq LAB + {is_poweroftwo(NUM,LOG)}-> jbs $LOG,A,LAB; +bitw $NUM,A : jeql LAB + {is_poweroftwo(NUM,LOG)}-> jbc $LOG,A,LAB; +bitl $NUM,A : jeql LAB + {is_poweroftwo(NUM,LOG)}-> jbc $LOG,A,LAB; +bitw ONE,A : jneq LAB -> jlbs A,LAB; +bitl ONE,A : jneq LAB -> jlbs A,LAB; +bitw ONE,A : jneq LAB -> jlbc A,LAB; +bitl ONE,A : jneq LAB -> jlbc A,LAB; +ashl $-NUM,A,REG : bicw2 $~NUM1,REG + {is_p2m1(NUM1,LOG)} -> extzv $NUM,$LOG,A,REG; +ashl $-NUM,A,REG : bicl2 $~NUM1,REG + {is_p2m1(NUM1,LOG)} -> extzv $NUM,$LOG,A,REG; + +/* stack optimizations */ + +movl (sp)+,X : pushl X -> movl (sp),X; +tstw (sp)+ : movw X,-(sp) -> movw X,(sp); +tstl (sp)+ : movl X,-(sp) -> movl X,(sp); +tstw (sp)+ : clrw -(sp) -> clrw (sp); +tstl (sp)+ : clrl -(sp) -> clrl (sp); +tstw (sp)+ : movzbw X,-(sp) -> movzbw X,(sp); +tstl (sp)+ : movzbl X,-(sp) -> movzbl X,(sp); +tstw (sp)+ : cvtbw X,-(sp) -> cvtbw X,(sp); +tstl (sp)+ : cvtbl X,-(sp) -> cvtbl X,(sp); +tstw (sp)+ : tstw X -> movw X,(sp)+; +tstl (sp)+ : tstl X -> movl X,(sp)+; +tstl (sp)+ : pushl X -> movl X,(sp); +tstl (sp)+ : pushab X -> movab X,(sp); +tstl (sp)+ : pushaw X -> movaw X,(sp); +tstl (sp)+ : pushal X -> moval X,(sp); +tstl (sp)+ : pushaq X -> movaq X,(sp); + +/* push constants */ + +clrw -(sp) : movw $NUM,-(sp) -> pushl $NUM; +clrw -(sp) : mnegw $NUM, -(sp) -> movzwl $-NUM,-(sp); +clrw -(sp) : movw X,-(sp) -> movzwl X,-(sp); +clrw -(sp) : cvtbw $NUM,-(sp) -> pushl $NUM; +clrw -(sp) : cvtbw CONST,-(sp) -> movzwl CONST,-(sp); + +/* compare with zero */ + +cmpb X,ZERO -> tstb X; +cmpw X,ZERO -> tstw X; +cmpl X,ZERO -> tstl X; +cmpb ZERO,X : jneq LAB -> tstb X: jneq LAB; +cmpw ZERO,X : jneq LAB -> tstw X: jneq LAB; +cmpl ZERO,X : jneq LAB -> tstl X: jneq LAB; + +cmpb ZERO,X : jeql LAB -> tstb X: jeql LAB; +cmpw ZERO,X : jeql LAB -> tstw X: jeql LAB; +cmpl ZERO,X : jeql LAB -> tstl X: jeql LAB; + +cmpb ZERO,X : jgtr LAB -> tstb X: jlss LAB; +cmpw ZERO,X : jgtr LAB -> tstw X: jlss LAB; +cmpl ZERO,X : jgtr LAB -> tstl X: jlss LAB; + +cmpb ZERO,X : jlss LAB -> tstb X: jgtr LAB; +cmpw ZERO,X : jlss LAB -> tstw X: jgtr LAB; +cmpl ZERO,X : jlss LAB -> tstl X: jgtr LAB; + +cmpb ZERO,X : jgeq LAB -> tstb X: jleq LAB; +cmpw ZERO,X : jgeq LAB -> tstw X: jleq LAB; +cmpl ZERO,X : jgeq LAB -> tstl X: jleq LAB; + +cmpb ZERO,X : jleq LAB -> tstb X: jgeq LAB; +cmpw ZERO,X : jleq LAB -> tstw X: jgeq LAB; +cmpl ZERO,X : jleq LAB -> tstl X: jgeq LAB; + +/* compare with -1 */ + +cmpw M_ONE,SREG : jeql LAB -> incw SREG : jeql LAB; +cmpl M_ONE,SREG : jeql LAB -> incl SREG : jeql LAB; +cmpw M_ONE,SREG : jneq LAB -> incw SREG : jneq LAB; +cmpl M_ONE,SREG : jneq LAB -> incl SREG : jneq LAB; + +/* eliminate redundant tests */ + +movw X,A : tstw A -> movw X,A; +movl X,A : tstl A -> movl X,A; +movw A,X : tstw A -> movw A,X; +movl A,X : tstl A -> movl A,X; + +/* skip over jumps */ + +jeql LAB : jbr LAB2 : labdef LAB -> jneq LAB2 : labdef LAB; +jgeq LAB : jbr LAB2 : labdef LAB -> jlss LAB2 : labdef LAB; +jgtr LAB : jbr LAB2 : labdef LAB -> jleq LAB2 : labdef LAB; +jlss LAB : jbr LAB2 : labdef LAB -> jgeq LAB2 : labdef LAB; +jleq LAB : jbr LAB2 : labdef LAB -> jgtr LAB2 : labdef LAB; +jneq LAB : jbr LAB2 : labdef LAB -> jeql LAB2 : labdef LAB; + +/* Register propagation */ + +movl REG,A : ANY *A -> movl REG,A : ANY *REG; +movl REG,A : ANY *A,X -> movl REG,A : ANY *REG,X; +movl REG,A : ANY X,*A -> movl REG,A : ANY X,*REG; +movl REG,A : ANY *A,X,Y -> movl REG,A : ANY *REG,X,Y; +movl REG,A : ANY X,*A,Y -> movl REG,A : ANY X,*REG,Y; +movl REG,A : ANY X,Y,*A -> movl REG,A : ANY X,Y,*REG; + + +%%; + +/* Auxiliary routines: */ + +int is_number(s) + register char *s; +{ + while (*s >= '0' && *s <= '9') s++; + return *s == '\0'; +} + +int is_poweroftwo(s,t) + char *s,*t; +{ + long arg, pow; + register int i; + + arg = atol(s); + pow = 1; + i = 0; + while (pow > 0) { + if (pow == arg) { + sprintf(t,"%d",i); + return 1; + } + pow <<= 1; + i++; + } + return 0; +} + +int is_p2m1(s,t) + char *s,*t; +{ + long arg; + char buf[MAXLINELEN]; + + arg = atol(s)+1; + sprintf(buf,"%ld",arg); + return is_poweroftwo(buf,t); +} + +int no_side_effects(s) + register char *s; +{ + + for(;;) { + switch(*s++) { + case '\0': return TRUE; + case '-': if (*s == '(') return FALSE; break; + case ')': if (*s == '+') return FALSE; break; + } + } + /* NOTREACHED */ +} + +int is_register(s) + register char *s; +{ + if (*s++ == 'r' && *s >= '0' && *s <= '9') { + if (*s++ == '1' && (*s == '0' || *s == '1')) s++; + return *s == '\0'; + } + return FALSE; +} + +int is_scratchreg(s) + register char *s; +{ + return *s++ == 'r' && *s >= '0' && *s++ <= '3' && *s == '\0'; +} From 66156680b62e15f9c71ada3d4659dbd64155dbfb Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 24 Nov 1986 21:01:42 +0000 Subject: [PATCH 0343/1625] Added -DNDEBUG --- mach/arm/top/Makefile | 2 +- mach/m68020/top/Makefile | 2 +- mach/m68k2/top/Makefile | 2 +- mach/pdp/top/Makefile | 2 +- mach/proto/top/Makefile | 2 +- mach/vax4/top/Makefile | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mach/arm/top/Makefile b/mach/arm/top/Makefile index 37628d51..24b25c5e 100644 --- a/mach/arm/top/Makefile +++ b/mach/arm/top/Makefile @@ -1,7 +1,7 @@ EM=../../.. PREFLAGS=-I. PFLAGS= -CFLAGS=$(PREFLAGS) $(PFLAGS) -O +CFLAGS=$(PREFLAGS) $(PFLAGS) -O -DNDEBUG LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac CDIR=$(EM)/mach/proto/top diff --git a/mach/m68020/top/Makefile b/mach/m68020/top/Makefile index 37628d51..24b25c5e 100644 --- a/mach/m68020/top/Makefile +++ b/mach/m68020/top/Makefile @@ -1,7 +1,7 @@ EM=../../.. PREFLAGS=-I. PFLAGS= -CFLAGS=$(PREFLAGS) $(PFLAGS) -O +CFLAGS=$(PREFLAGS) $(PFLAGS) -O -DNDEBUG LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac CDIR=$(EM)/mach/proto/top diff --git a/mach/m68k2/top/Makefile b/mach/m68k2/top/Makefile index 37628d51..24b25c5e 100644 --- a/mach/m68k2/top/Makefile +++ b/mach/m68k2/top/Makefile @@ -1,7 +1,7 @@ EM=../../.. PREFLAGS=-I. PFLAGS= -CFLAGS=$(PREFLAGS) $(PFLAGS) -O +CFLAGS=$(PREFLAGS) $(PFLAGS) -O -DNDEBUG LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac CDIR=$(EM)/mach/proto/top diff --git a/mach/pdp/top/Makefile b/mach/pdp/top/Makefile index 37628d51..24b25c5e 100644 --- a/mach/pdp/top/Makefile +++ b/mach/pdp/top/Makefile @@ -1,7 +1,7 @@ EM=../../.. PREFLAGS=-I. PFLAGS= -CFLAGS=$(PREFLAGS) $(PFLAGS) -O +CFLAGS=$(PREFLAGS) $(PFLAGS) -O -DNDEBUG LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac CDIR=$(EM)/mach/proto/top diff --git a/mach/proto/top/Makefile b/mach/proto/top/Makefile index 37628d51..24b25c5e 100644 --- a/mach/proto/top/Makefile +++ b/mach/proto/top/Makefile @@ -1,7 +1,7 @@ EM=../../.. PREFLAGS=-I. PFLAGS= -CFLAGS=$(PREFLAGS) $(PFLAGS) -O +CFLAGS=$(PREFLAGS) $(PFLAGS) -O -DNDEBUG LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac CDIR=$(EM)/mach/proto/top diff --git a/mach/vax4/top/Makefile b/mach/vax4/top/Makefile index 37628d51..24b25c5e 100644 --- a/mach/vax4/top/Makefile +++ b/mach/vax4/top/Makefile @@ -1,7 +1,7 @@ EM=../../.. PREFLAGS=-I. PFLAGS= -CFLAGS=$(PREFLAGS) $(PFLAGS) -O +CFLAGS=$(PREFLAGS) $(PFLAGS) -O -DNDEBUG LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac CDIR=$(EM)/mach/proto/top From aa1567659479dc9915bbd90089692efe8d8ae291 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 24 Nov 1986 21:24:42 +0000 Subject: [PATCH 0344/1625] make to work with newer version of LLgen. --- util/topgen/topgen.g | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/util/topgen/topgen.g b/util/topgen/topgen.g index d3413b6c..1b27f0ee 100644 --- a/util/topgen/topgen.g +++ b/util/topgen/topgen.g @@ -34,7 +34,13 @@ optim_description } separator SPACE* mode_definitions separator SPACE* patterns - separator user_routines + separator + { register int c; + fprintf(genc, linedir, lineno, inpfile); + while ((c = getc(input)) != EOF) { + putc(c,genc); + } + } ; parameter_line @@ -282,14 +288,6 @@ replacement (int *n;) ] ; -user_routines - {register c;} : - { fprintf(genc, linedir, lineno, inpfile); - while ((c = getc(input)) != EOF) { - putc(c,genc); - } - } -; identifier { char *p = idbuf; } : From bef7369dc5424db4b089b1785fcc935f035c00da Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 24 Nov 1986 21:30:57 +0000 Subject: [PATCH 0345/1625] Handled gen.c wrong. This is corrected. --- mach/arm/top/Makefile | 6 +++--- mach/m68020/top/Makefile | 6 +++--- mach/m68k2/top/Makefile | 6 +++--- mach/pdp/top/Makefile | 6 +++--- mach/proto/top/Makefile | 6 +++--- mach/vax4/top/Makefile | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/mach/arm/top/Makefile b/mach/arm/top/Makefile index 24b25c5e..38293cb7 100644 --- a/mach/arm/top/Makefile +++ b/mach/arm/top/Makefile @@ -5,8 +5,8 @@ CFLAGS=$(PREFLAGS) $(PFLAGS) -O -DNDEBUG LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac CDIR=$(EM)/mach/proto/top -CFILES=$(CDIR)/top.c $(CDIR)/queue.c gen.c -OFILES=top.o queue.o gen.o +CFILES=$(CDIR)/top.c $(CDIR)/queue.c +OFILES=top.o queue.o all: gen.c make top @@ -14,7 +14,7 @@ all: gen.c top: $(OFILES) $(CC) $(LDFLAGS) $(OFILES) $(LIBS) -o top -top.o: $(CDIR)/top.c +top.o: $(CDIR)/top.c gen.c $(CC) -c $(CFLAGS) $(CDIR)/top.c queue.o: $(CDIR)/queue.c diff --git a/mach/m68020/top/Makefile b/mach/m68020/top/Makefile index 24b25c5e..38293cb7 100644 --- a/mach/m68020/top/Makefile +++ b/mach/m68020/top/Makefile @@ -5,8 +5,8 @@ CFLAGS=$(PREFLAGS) $(PFLAGS) -O -DNDEBUG LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac CDIR=$(EM)/mach/proto/top -CFILES=$(CDIR)/top.c $(CDIR)/queue.c gen.c -OFILES=top.o queue.o gen.o +CFILES=$(CDIR)/top.c $(CDIR)/queue.c +OFILES=top.o queue.o all: gen.c make top @@ -14,7 +14,7 @@ all: gen.c top: $(OFILES) $(CC) $(LDFLAGS) $(OFILES) $(LIBS) -o top -top.o: $(CDIR)/top.c +top.o: $(CDIR)/top.c gen.c $(CC) -c $(CFLAGS) $(CDIR)/top.c queue.o: $(CDIR)/queue.c diff --git a/mach/m68k2/top/Makefile b/mach/m68k2/top/Makefile index 24b25c5e..38293cb7 100644 --- a/mach/m68k2/top/Makefile +++ b/mach/m68k2/top/Makefile @@ -5,8 +5,8 @@ CFLAGS=$(PREFLAGS) $(PFLAGS) -O -DNDEBUG LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac CDIR=$(EM)/mach/proto/top -CFILES=$(CDIR)/top.c $(CDIR)/queue.c gen.c -OFILES=top.o queue.o gen.o +CFILES=$(CDIR)/top.c $(CDIR)/queue.c +OFILES=top.o queue.o all: gen.c make top @@ -14,7 +14,7 @@ all: gen.c top: $(OFILES) $(CC) $(LDFLAGS) $(OFILES) $(LIBS) -o top -top.o: $(CDIR)/top.c +top.o: $(CDIR)/top.c gen.c $(CC) -c $(CFLAGS) $(CDIR)/top.c queue.o: $(CDIR)/queue.c diff --git a/mach/pdp/top/Makefile b/mach/pdp/top/Makefile index 24b25c5e..38293cb7 100644 --- a/mach/pdp/top/Makefile +++ b/mach/pdp/top/Makefile @@ -5,8 +5,8 @@ CFLAGS=$(PREFLAGS) $(PFLAGS) -O -DNDEBUG LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac CDIR=$(EM)/mach/proto/top -CFILES=$(CDIR)/top.c $(CDIR)/queue.c gen.c -OFILES=top.o queue.o gen.o +CFILES=$(CDIR)/top.c $(CDIR)/queue.c +OFILES=top.o queue.o all: gen.c make top @@ -14,7 +14,7 @@ all: gen.c top: $(OFILES) $(CC) $(LDFLAGS) $(OFILES) $(LIBS) -o top -top.o: $(CDIR)/top.c +top.o: $(CDIR)/top.c gen.c $(CC) -c $(CFLAGS) $(CDIR)/top.c queue.o: $(CDIR)/queue.c diff --git a/mach/proto/top/Makefile b/mach/proto/top/Makefile index 24b25c5e..38293cb7 100644 --- a/mach/proto/top/Makefile +++ b/mach/proto/top/Makefile @@ -5,8 +5,8 @@ CFLAGS=$(PREFLAGS) $(PFLAGS) -O -DNDEBUG LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac CDIR=$(EM)/mach/proto/top -CFILES=$(CDIR)/top.c $(CDIR)/queue.c gen.c -OFILES=top.o queue.o gen.o +CFILES=$(CDIR)/top.c $(CDIR)/queue.c +OFILES=top.o queue.o all: gen.c make top @@ -14,7 +14,7 @@ all: gen.c top: $(OFILES) $(CC) $(LDFLAGS) $(OFILES) $(LIBS) -o top -top.o: $(CDIR)/top.c +top.o: $(CDIR)/top.c gen.c $(CC) -c $(CFLAGS) $(CDIR)/top.c queue.o: $(CDIR)/queue.c diff --git a/mach/vax4/top/Makefile b/mach/vax4/top/Makefile index 24b25c5e..38293cb7 100644 --- a/mach/vax4/top/Makefile +++ b/mach/vax4/top/Makefile @@ -5,8 +5,8 @@ CFLAGS=$(PREFLAGS) $(PFLAGS) -O -DNDEBUG LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac CDIR=$(EM)/mach/proto/top -CFILES=$(CDIR)/top.c $(CDIR)/queue.c gen.c -OFILES=top.o queue.o gen.o +CFILES=$(CDIR)/top.c $(CDIR)/queue.c +OFILES=top.o queue.o all: gen.c make top @@ -14,7 +14,7 @@ all: gen.c top: $(OFILES) $(CC) $(LDFLAGS) $(OFILES) $(LIBS) -o top -top.o: $(CDIR)/top.c +top.o: $(CDIR)/top.c gen.c $(CC) -c $(CFLAGS) $(CDIR)/top.c queue.o: $(CDIR)/queue.c From db589c5d0207854297c47fc52b361b3dad02d0ce Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 24 Nov 1986 21:45:03 +0000 Subject: [PATCH 0346/1625] Initial revision --- mach/pdp/top/table | 104 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 mach/pdp/top/table diff --git a/mach/pdp/top/table b/mach/pdp/top/table new file mode 100644 index 00000000..2b4e433b --- /dev/null +++ b/mach/pdp/top/table @@ -0,0 +1,104 @@ +/* PDP-11 desciptor table for ACK target optimizer */ + +/* Tunable constants: */ + +MAXOP 2; +LABEL_STARTER 'I'; +OPC_TERMINATOR ' '; + +%%; + +/* useful addressing modes: */ + +ZERO {strcmp(VAL,"$00") == 0 }; +ONE {strcmp(VAL,"$01") == 0 }; +CONST {VAL[0] == '$' }; /* constant */ +A,B {no_side_effects(VAL) }; +X,Y {TRUE }; +REG {is_register(VAL) }; /* register */ +SREG {is_scratchreg(VAL) }; /* scratch reg */ +M_ONE {strcmp(VAL,"$037777777777") == 0 }; /* -1 */ +LAB,L1,L2 {VAL[0] == 'I' }; /* label */ + +%%; + +/* optimization patterns: */ + +add ZERO,A {carry_dead(REST)} -> ; +add ONE, X {carry_dead(REST)} -> inc X; +sub ONE, X {carry_dead(REST)} -> dec X; + +/* tst-elimination */ +tst (sp)+ : tst X -> mov X,(sp)+; +tst (sp)+ : mov X,-(sp) -> mov X,(sp); +mov A,X : tst A -> mov A,X; + +/* register subsumption */ +mov REG,A : ANY A,X -> mov REG,A : ANY REG,X; +mov REG,A : ANY *A -> mov REG,A : ANY *REG; +mov REG,A : ANY *A,X -> mov REG,A : ANY *REG,X; +mov REG,A : ANY X,*A -> mov REG,A : ANY X,*REG; + +/* compare with -1 */ +cmp SREG,M_ONE : jeq LAB -> inc SREG : jeq LAB; +cmp SREG,M_ONE : jne LAB -> inc SREG : jne LAB; + +/* skip over jump */ +jeq L1 : jbr L2: labdef L1 -> jne L2 : labdef L1; +jge L1 : jbr L2: labdef L1 -> jlt L2 : labdef L1; +jgt L1 : jbr L2: labdef L1 -> jle L2 : labdef L1; +jlt L1 : jbr L2: labdef L1 -> jge L2 : labdef L1; +jle L1 : jbr L2: labdef L1 -> jgt L2 : labdef L1; +jne L1 : jbr L2: labdef L1 -> jeq L2 : labdef L1; + +/* byte-test */ +clr SREG : bisb X,SREG : tst SREG : jeq LAB + -> tstb X : jeq LAB; +clr SREG : bisb X,SREG : tst SREG : jne LAB + -> tstb X : jne LAB; + +%%; + +/* auxiliary routines: */ + +int no_side_effects(s) + register char *s; +{ + + for(;;) { + switch(*s++) { + case '\0': return TRUE; + case '-': if (*s == '(') return FALSE; break; + case ')': if (*s == '+') return FALSE; break; + } + } + /* NOTREACHED */ +} + +int is_register(s) + register char *s; +{ + return *s++ == 'r' && *s >= '0' && *s <= '5'; +} + +int is_scratchreg(s) + register char *s; +{ + return *s++ == 'r' && (*s == '0' || *s == '1' || *s == '3'); +} + +int carry_dead(s) + char *s; +{ + switch(*s++) { + case 'a': /* adc and adcb */ + return *s++ != 'd' || *s != 'c'; + case 'b': /* bcc, bcs, bhi, bhis, blo, blos */ + return *s != 'c' && *s != 'h' && + (*s++ != 'l' || *s != 'o'); + case 's': /* sbc and sbcb */ + return *s++ != 'b' || *s != 'c'; + default: + return TRUE; + } +} From 3476883ee1b04c472959217a1ba0d0cce86b2c01 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 24 Nov 1986 21:52:09 +0000 Subject: [PATCH 0347/1625] Initial revision --- mach/m68k2/top/table | 178 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 mach/m68k2/top/table diff --git a/mach/m68k2/top/table b/mach/m68k2/top/table new file mode 100644 index 00000000..8ea7726d --- /dev/null +++ b/mach/m68k2/top/table @@ -0,0 +1,178 @@ + +/* 68000 desciptor table for ACK target optimizer */ + +MAXOP 2; + +%%; + +/* useful addressing modes-> */ + +CONST {VAL[0] == '#' }; /* constant */ +NUM {is_number(VAL) }; +A,B {no_side_effects(VAL) }; +D {VAL[0] != '#' && !is_areg(VAL) }; /* not an addr. reg */ +X,Y {TRUE }; +DREG,DREG2 {is_dreg(VAL) }; /* data register */ +DSREG {is_dsreg(VAL) }; /* data register */ +AREG {is_areg(VAL) }; /* addressregister */ +LAB,L1,L2 {VAL[0] == 'I' }; /* label */ +BITNO {TRUE }; + +%%; + +/* optimization patterns-> */ + +/* rewriting rules */ +tst X -> tst.w X ; +cmp X,Y -> cmp.w X,Y ; + +/* special instructions */ +move.w #0,D -> clr.w D ; +move.l #0,D -> clr.l D ; +move.l #0,AREG -> sub.l AREG,AREG ; + +/* tst-elimination */ +add.l #2,sp : tst.w X {no_part("sp",X)} -> move.w X,(sp)+ ; +add.l #4,sp : tst.l D {no_part("sp",D)} -> move.l D,(sp)+ ; +add.l #2,sp : move.w X,-(sp) -> move.w X,(sp) ; +add.l #4,sp : move.l X,-(sp) -> move.l X,(sp) ; +move.w A,X : tst.w A -> move.w A,X ; +move.w X,A : tst.w A -> move.w X,A ; +move.l A,D : tst.l A {no_part(D,A)} -> move.l A,D ; +move.l X,D : tst.l D -> move.l X,D ; +move.l A,AREG : tst.l A + {no_part(AREG,A)} -> tst.l A: move.l A,AREG ; +move.l X,AREG : move.l AREG,DREG : + tst.l DREG : beq LAB -> move.l X,DREG : + move.l DREG,AREG: beq LAB ; +move.l X,AREG : move.l AREG,DREG : + tst.l DREG : bne LAB -> move.l X,DREG : + move.l DREG,AREG: bne LAB ; + +/* redundant move */ +move.w DREG,DREG2 : move.w DREG2,DREG -> move.w DREG,DREG2 ; + +/* register subsumption */ +move.w DREG,A : ANY A,X + {reg_subs_allowed(ANY) && + !is_dreg(A) } -> move.w DREG,A : ANY DREG,X ; + +/* change "cmp" into "add" or "sub" (possibly "addq" or "subq") */ +cmp.w #-NUM,DSREG : beq LAB -> add.w #NUM,DSREG : beq LAB ; +cmp.l #-NUM,DSREG : beq LAB -> add.l #NUM,DSREG : beq LAB ; +cmp.w #-NUM,DSREG : bne LAB -> add.w #NUM,DSREG : bne LAB ; +cmp.l #-NUM,DSREG : bne LAB -> add.l #NUM,DSREG : bne LAB ; + +cmp.w #NUM,DSREG : beq LAB -> sub.w #NUM,DSREG : beq LAB ; +cmp.l #NUM,DSREG : beq LAB -> sub.l #NUM,DSREG : beq LAB ; +cmp.w #NUM,DSREG : bne LAB -> sub.w #NUM,DSREG : bne LAB ; +cmp.l #NUM,DSREG : bne LAB -> sub.l #NUM,DSREG : bne LAB ; + +/* addq and subq */ +lea -1(AREG),AREG -> sub.l #1,AREG ; +add.w #-NUM,X -> sub.w #NUM,X ; +add.l #-NUM,X -> sub.l #NUM,X ; +sub.w #-NUM,X -> add.w #NUM,X ; +sub.l #-NUM,X -> add.l #NUM,X ; + +/* bit-test instruction */ +move.b X,DSREG : and.w #NUM,DSREG : + tst.w DSREG : beq LAB + { bitno(NUM,BITNO)} -> btst #BITNO,X ; + +/* skip over jump */ +beq L1 : bra L2: labdef L1 -> bne L2 : labdef L1 ; +bge L1 : bra L2: labdef L1 -> blt L2 : labdef L1 ; +bgt L1 : bra L2: labdef L1 -> ble L2 : labdef L1 ; +blt L1 : bra L2: labdef L1 -> bge L2 : labdef L1 ; +ble L1 : bra L2: labdef L1 -> bgt L2 : labdef L1 ; +bne L1 : bra L2: labdef L1 -> beq L2 : labdef L1 ; + +%%; + +/* auxiliary routines: */ + +int no_side_effects(s) + register char *s; +{ + + for(;;) { + switch(*s++) { + case '\0': return TRUE; + case '-': if (*s == '(') return FALSE; break; + case ')': if (*s == '+') return FALSE; break; + } + } + /* NOTREACHED */ +} + + +int is_dreg(s) + register char *s; +{ + return *s++ == 'd' && *s >= '0' && *s++ <= '7' && *s == '\0'; +} + +int is_dsreg(s) + register char *s; +{ + return *s++ == 'd' && *s >= '0' && *s++ <= '2' && *s == '\0'; +} + +int is_areg(s) + register char *s; +{ + return *s++ == 'a' && *s >= '0' && *s++ <= '6' && *s == '\0'; +} + +int no_part(part,s) + char *part,*s; +{ + char *tmp1,*tmp2; + + while (*s != '\0') { + if (*s == *part) { + for (tmp1=part,tmp2=s;; tmp1++,tmp2++) { + if (*tmp1== '\0') return FALSE; + if (*tmp1 != *tmp2) break; + } + } + s++; + } + return TRUE; +} + + +/* see if register subsumption is allowed for instruction Opc */ + +int reg_subs_allowed(opc) + char *opc; +{ + return strcmp(opc,"cmp") != 0 && strcmp(opc,"lea") != 0; +} + +int is_number(s) + register char *s; +{ + while (*s != '\0') { + if (*s < '0' || *s++ > '9') return FALSE; + } + return TRUE; +} + +int bitno(s,no) + char *s,*no; +{ + int n,i; + + n = atoi(s); + if (n < 1 || n > 128) return FALSE; + for (i = 0; i < 8 ; i++) { + if (n == 1) { + sprintf(no,"%d",i); + return TRUE; + } + n >>= 1; + } + return FALSE; +} From 3bc8215b69a7bdf737454dc3c39e47b097360c45 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 26 Nov 1986 16:40:45 +0000 Subject: [PATCH 0348/1625] newer version --- lang/m2/comp/LLlex.c | 11 ++-- lang/m2/comp/Makefile | 14 ++--- lang/m2/comp/Resolve | 7 ++- lang/m2/comp/chk_expr.c | 12 ++-- lang/m2/comp/code.c | 112 +++++++++++++++++--------------------- lang/m2/comp/declar.g | 24 ++++---- lang/m2/comp/def.H | 24 +++++--- lang/m2/comp/def.c | 20 ++++++- lang/m2/comp/defmodule.c | 7 ++- lang/m2/comp/expression.g | 21 ++++--- lang/m2/comp/main.c | 11 +++- lang/m2/comp/program.g | 25 ++++----- lang/m2/comp/scope.C | 50 +++++------------ lang/m2/comp/scope.h | 1 - lang/m2/comp/tmpvar.C | 16 ++++-- lang/m2/comp/type.H | 1 + lang/m2/comp/type.c | 12 ++-- lang/m2/comp/typequiv.c | 7 ++- lang/m2/comp/walk.c | 94 ++++++++++++++++++++++---------- 19 files changed, 264 insertions(+), 205 deletions(-) diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index c9372ecb..902ed71b 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -106,9 +106,8 @@ GetString(upto) } str->s_length = p - str->s_str; while (p - str->s_str < len) *p++ = '\0'; - if (str->s_length == 0) str->s_length = 1; /* ??? string length - at least 1 ??? - */ + if (str->s_length == 0) str->s_length = 1; + /* ??? string length at least 1 ??? */ return str; } @@ -239,12 +238,10 @@ again1: goto again; case STGARB: - if (040 < ch && ch < 0177) { + if ((unsigned) ch - 040 < 0137) { lexerror("garbage char %c", ch); } - else { - lexerror("garbage char \\%03o", ch); - } + else lexerror("garbage char \\%03o", ch); goto again; case STSIMP: diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index aff09b74..d434e74e 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -5,11 +5,11 @@ PKGDIR = $(EMDIR)/modules/pkg LIBDIR = $(EMDIR)/modules/lib OBJECTCODE = $(LIBDIR)/libemk.a LLGEN = $(EMDIR)/bin/LLgen +CURRDIR = . INCLUDES = -I$(MHDIR) -I$(EMDIR)/h -I$(PKGDIR) GFILES = tokenfile.g program.g declar.g expression.g statement.g -CC = cc LLGENOPTIONS = PROFILE = CFLAGS = $(PROFILE) $(INCLUDES) -DSTATIC= @@ -50,14 +50,14 @@ GENFILES = $(GENGFILES) $(GENCFILES) $(GENHFILES) #EXCLEXCLEXCLEXCL all: Cfiles - sh -c 'if $(CC) nmclash.c > /dev/null 2>&1 ; then make ../comp/main ; else sh Resolve ../comp/main ; fi' + sh -c 'if $(CC) nmclash.c > /dev/null 2>&1 ; then make $(CURRDIR)/main ; else sh Resolve main ; fi' @rm -f nmclash.o a.out install: all - cp main $(EMDIR)/lib/em_m2 + cp $(CURRDIR)/main $(EMDIR)/lib/em_m2 clean: - rm -f $(OBJ) $(GENFILES) LLfiles hfiles Cfiles tab clashes main + rm -f $(OBJ) $(GENFILES) LLfiles hfiles Cfiles tab clashes $(CURRDIR)/main (cd .. ; rm -rf Xsrc) lint: Cfiles @@ -123,9 +123,9 @@ depend: Xlint: lint $(INCLUDES) $(LINTFLAGS) $(SRC) -../comp/main: $(OBJ) ../comp/Makefile - $(CC) $(LFLAGS) $(OBJ) $(LIBDIR)/libem_mes.a $(OBJECTCODE) $(LIBDIR)/libinput.a $(LIBDIR)/libassert.a $(LIBDIR)/liballoc.a $(MALLOC) $(LIBDIR)/libprint.a $(LIBDIR)/libstring.a $(LIBDIR)/libsystem.a -o ../comp/main - size ../comp/main +$(CURRDIR)/main: $(OBJ) + $(CC) $(LFLAGS) $(OBJ) $(LIBDIR)/libem_mes.a $(OBJECTCODE) $(LIBDIR)/libinput.a $(LIBDIR)/libassert.a $(LIBDIR)/liballoc.a $(MALLOC) $(LIBDIR)/libprint.a $(LIBDIR)/libstring.a $(LIBDIR)/libsystem.a -o $(CURRDIR)/main + size $(CURRDIR)/main #AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO LLlex.o: LLlex.h Lpars.h class.h const.h debug.h debugcst.h f_info.h idf.h idfsize.h input.h inputtype.h numsize.h strsize.h type.h warning.h diff --git a/lang/m2/comp/Resolve b/lang/m2/comp/Resolve index eeb0a7b8..e107d789 100755 --- a/lang/m2/comp/Resolve +++ b/lang/m2/comp/Resolve @@ -8,8 +8,11 @@ case $# in exit 1 ;; esac +currdir=`pwd` case $1 in -../comp/main|Xlint) +main) target=$currdir/$1 + ;; +Xlint) target=$1 ;; *) echo "$0: $1: Illegal argument" 1>&2 exit 1 @@ -48,4 +51,4 @@ $i: clashes $PW/$i cid -Fclashes < $PW/$i > $i EOF done -make $1 +make CURRDIR=$currdir $target diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index 7d27a38b..0e2b0ccc 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -438,6 +438,7 @@ getarg(argp, bases, designator, edf) } left = arg->nd_left; + *argp = arg; if (designator ? !ChkVariable(left) : !ChkExpression(left)) { return 0; @@ -454,7 +455,6 @@ getarg(argp, bases, designator, edf) } } - *argp = arg; return left; } @@ -470,6 +470,8 @@ getname(argp, kinds, bases, edf) register struct node *arg = *argp; register struct node *left; + *argp = arg->nd_right; + if (!arg->nd_right) { Xerror(arg, "too few arguments supplied", edf); return 0; @@ -496,7 +498,6 @@ getname(argp, kinds, bases, edf) } } - *argp = arg; return left; } @@ -539,7 +540,7 @@ ChkProcCall(expp) if (left->nd_symb == STRING) { TryToString(left, TypeOfParam(param)); } - if (! TstParCompat(RemoveEqual(TypeOfParam(param)), + else if (! TstParCompat(RemoveEqual(TypeOfParam(param)), left->nd_type, IsVarParam(param), left)) { @@ -552,6 +553,9 @@ ChkProcCall(expp) if (expp->nd_right) { Xerror(expp->nd_right, "too many parameters supplied", edf); + while (expp->nd_right) { + getarg(&expp, 0, 0, edf); + } return 0; } @@ -581,7 +585,7 @@ ChkCall(expp) return ChkCast(expp, left); } - if (IsProcCall(left)) { + if (IsProcCall(left) || left->nd_type == error_type) { /* A procedure call. It may also be a call to a standard procedure */ diff --git a/lang/m2/comp/code.c b/lang/m2/comp/code.c index 1fbea8be..a91f0c98 100644 --- a/lang/m2/comp/code.c +++ b/lang/m2/comp/code.c @@ -86,7 +86,6 @@ CodePadString(nd, sz) C_loi(sizearg); } - CodeExpr(nd, ds, true_label, false_label) register struct node *nd; register struct desig *ds; @@ -365,27 +364,37 @@ CodeParameters(param, arg) left = arg->nd_left; left_type = left->nd_type; if (IsConformantArray(tp)) { + register struct type *elem = tp->arr_elem; + C_loc(tp->arr_elsize); if (IsConformantArray(left_type)) { DoHIGH(left); - if (tp->arr_elem->tp_size != - left_type->arr_elem->tp_size) { + if (elem->tp_size != left_type->arr_elem->tp_size) { /* This can only happen if the formal type is - ARRAY OF WORD + ARRAY OF (WORD|BYTE) */ - assert(tp->arr_elem == word_type); C_loc(left_type->arr_elem->tp_size); - C_cal("_wa"); - C_asp(dword_size); - C_lfr(word_size); + C_mli(word_size); + if (elem == word_type) { + C_loc(word_size - 1); + C_adi(word_size); + C_loc(word_size); + C_dvi(word_size); + } + else { + assert(elem == byte_type); + } } } else if (left->nd_symb == STRING) { - C_loc(left->nd_SLE); + C_loc(left->nd_SLE - 1); } - else if (tp->arr_elem == word_type) { + else if (elem == word_type) { C_loc((left_type->tp_size+word_size-1) / word_size - 1); } + else if (elem == byte_type) { + C_loc(left_type->tp_size - 1); + } else { arith lb, ub; getbounds(IndexType(left_type), &lb, &ub); @@ -395,20 +404,30 @@ CodeParameters(param, arg) if (left->nd_symb == STRING) { CodeString(left); } - else CodeDAddress(left); - } - else if (IsVarParam(param)) { - CodeDAddress(left); - } - else { - if (left_type->tp_fund == T_STRING) { - CodePadString(left, tp->tp_size); - } - else { + else if (left->nd_class == Call) { + /* ouch! forgot about this one! */ + arith tmp, TmpSpace(); + CodePExpr(left); - RangeCheck(left_type, tp); + tmp = TmpSpace(left->nd_type->tp_size, left->nd_type->tp_align); + C_lal(tmp); + C_sti(WA(left->nd_type->tp_size)); + C_lal(tmp); } + else CodeDAddress(left); + return; } + if (IsVarParam(param)) { + CodeDAddress(left); + return; + } + if (left_type->tp_fund == T_STRING) { + CodePadString(left, tp->tp_size); + return; + } + CodePExpr(left); + RangeCheck(tp, left_type); + CodeCoercion(left_type, tp); } CodeStd(nd) @@ -538,33 +557,6 @@ CodeStd(nd) } } -CodeAssign(nd, dss, dst) - register struct node *nd; - struct desig *dst, *dss; -{ - /* Generate code for an assignment. Testing of type - compatibility and the like is already done. - */ - register struct type *tp = nd->nd_right->nd_type; - arith size = nd->nd_left->nd_type->tp_size; - - if (dss->dsg_kind == DSG_LOADED) { - if (tp->tp_fund == T_STRING) { - CodeAddress(dst); - C_loc(tp->tp_size); - C_loc(size); - C_cal("_StringAssign"); - C_asp((int_size << 1) + (pointer_size << 1)); - return; - } - CodeStore(dst, size); - return; - } - CodeAddress(dss); - CodeAddress(dst); - C_blm(size); -} - RangeCheck(tpl, tpr) register struct type *tpl, *tpr; { @@ -800,32 +792,30 @@ CodeOper(expr, true_label, false_label) case OR: case AND: case '&': { - label l_true, l_false, l_maybe = ++text_label, l_end; + label l_maybe = ++text_label, l_end; struct desig Des; + int genlabels = 0; if (true_label == 0) { - l_true = ++text_label; - l_false = ++text_label; + genlabels = 1; + true_label = ++text_label; + false_label = ++text_label; l_end = ++text_label; } - else { - l_true = true_label; - l_false = false_label; - } Des = InitDesig; if (expr->nd_symb == OR) { - CodeExpr(leftop, &Des, l_true, l_maybe); + CodeExpr(leftop, &Des, true_label, l_maybe); } - else CodeExpr(leftop, &Des, l_maybe, l_false); + else CodeExpr(leftop, &Des, l_maybe, false_label); C_df_ilb(l_maybe); Des = InitDesig; - CodeExpr(rightop, &Des, l_true, l_false); - if (true_label == 0) { - C_df_ilb(l_true); + CodeExpr(rightop, &Des, true_label, false_label); + if (genlabels) { + C_df_ilb(true_label); C_loc((arith)1); C_bra(l_end); - C_df_ilb(l_false); + C_df_ilb(false_label); C_loc((arith)0); C_df_ilb(l_end); } diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 00624af5..0f309aec 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -102,10 +102,11 @@ FormalType(struct type **ptp;) } : ARRAY OF qualtype(ptp) { register struct type *tp = construct_type(T_ARRAY, NULLTYPE); + tp->arr_elem = *ptp; *ptp = tp; tp->arr_elsize = ArrayElSize(tp->arr_elem); - tp->tp_align = lcm(word_align, pointer_align); + tp->tp_align = tp->arr_elem->tp_align; } | qualtype(ptp) @@ -160,16 +161,18 @@ enumeration(struct type **ptp;) struct node *EnumList; } : '(' IdentList(&EnumList) ')' - { - *ptp = standard_type(T_ENUMERATION, int_align, int_size); - EnterEnumList(EnumList, *ptp); - if (ufit((*ptp)->enm_ncst-1, 1)) { - (*ptp)->tp_size = 1; - (*ptp)->tp_align = 1; + { register struct type *tp = + standard_type(T_ENUMERATION, int_align, int_size); + + *ptp = tp; + EnterEnumList(EnumList, tp); + if (ufit(tp->enm_ncst-1, 1)) { + tp->tp_size = 1; + tp->tp_align = 1; } - else if (ufit((*ptp)->enm_ncst-1, short_size)) { - (*ptp)->tp_size = short_size; - (*ptp)->tp_align = short_align; + else if (ufit(tp->enm_ncst-1, short_size)) { + tp->tp_size = short_size; + tp->tp_align = short_align; } } ; @@ -234,7 +237,6 @@ RecordType(struct type **ptp;) { open_scope(OPENSCOPE); /* scope for fields of record */ scope = CurrentScope; close_scope(0); - size = 0; } FieldListSequence(scope, &size, &xalign) { *ptp = standard_type(T_RECORD, xalign, WA(size)); diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H index dee4b94b..a1725310 100644 --- a/lang/m2/comp/def.H +++ b/lang/m2/comp/def.H @@ -63,13 +63,20 @@ struct dforward { #define for_name df_value.df_forward.fo_name }; +struct forwtype { + struct node *f_node; + struct type *f_type; +#define df_forw_type df_value.df_fortype.f_type +#define df_forw_node df_value.df_fortype.f_node +}; + struct def { /* list of definitions for a name */ struct def *next; /* next definition in definitions chain */ struct def *df_nextinscope; /* link all definitions in a scope */ struct idf *df_idf; /* link back to the name */ struct scope *df_scope; /* scope in which this definition resides */ - short df_kind; /* the kind of this definition: */ + unsigned short df_kind; /* the kind of this definition: */ #define D_MODULE 0x0001 /* a module */ #define D_PROCEDURE 0x0002 /* procedure of function */ #define D_VARIABLE 0x0004 /* a variable */ @@ -82,20 +89,22 @@ struct def { /* list of definitions for a name */ #define D_HIDDEN 0x0200 /* a hidden type */ #define D_FORWARD 0x0400 /* not yet defined */ #define D_FORWMODULE 0x0800 /* module must be declared later */ -#define D_ERROR 0x1000 /* a compiler generated definition for an +#define D_FORWTYPE 0x1000 /* forward type */ +#define D_FTYPE 0x2000 /* resolved forward type */ +#define D_ERROR 0x4000 /* a compiler generated definition for an undefined variable */ #define D_VALUE (D_PROCEDURE|D_VARIABLE|D_FIELD|D_ENUM|D_CONST|D_PROCHEAD) -#define D_ISTYPE (D_HIDDEN|D_TYPE) +#define D_ISTYPE (D_HIDDEN|D_TYPE|D_FTYPE) #define is_type(dfx) ((dfx)->df_kind & D_ISTYPE) char df_flags; #define D_NOREG 0x01 /* set if it may not reside in a register */ #define D_USED 0x02 /* set if used (future use ???) */ #define D_DEFINED 0x04 /* set if it is assigned a value (future use ???) */ -#define D_VARPAR 0x10 /* set if it is a VAR parameter */ -#define D_VALPAR 0x20 /* set if it is a value parameter */ -#define D_EXPORTED 0x40 /* set if exported */ -#define D_QEXPORTED 0x80 /* set if qualified exported */ +#define D_VARPAR 0x08 /* set if it is a VAR parameter */ +#define D_VALPAR 0x10 /* set if it is a value parameter */ +#define D_EXPORTED 0x20 /* set if exported */ +#define D_QEXPORTED 0x40 /* set if qualified exported */ struct type *df_type; union { struct module df_module; @@ -106,6 +115,7 @@ struct def { /* list of definitions for a name */ struct import df_import; struct dfproc df_proc; struct dforward df_forward; + struct forwtype df_fortype; int df_stdname; /* define for standard name */ } df_value; }; diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index 36c8906a..e32e5484 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -21,6 +21,8 @@ struct def *h_def; /* pointer to free list of def structures */ int cnt_def; /* count number of allocated ones */ #endif +extern int (*c_inp)(); + STATIC DefInFront(df) register struct def *df; @@ -129,6 +131,18 @@ define(id, scope, kind) } break; + case D_FORWTYPE: + if (kind == D_FORWTYPE) return df; + if (kind == D_TYPE) { + df->df_kind = D_FTYPE; + FreeNode(df->df_forw_node); + } + else { + error("identifier \"%s\" must be a type", + id->id_text); + } + return df; + case D_FORWARD: /* A forward reference, for which we may now have found a definition. @@ -247,7 +261,7 @@ DeclProc(type, id) df = define(id, CurrentScope, type); sprint(buf,"_%d_%s",++nmcount,id->id_text); name = Salloc(buf, (unsigned)(strlen(buf)+1)); - C_inp(buf); + (*c_inp)(buf); } open_scope(OPENSCOPE); scope = CurrentScope; @@ -311,13 +325,13 @@ DefineLocalModule(id) /* Create a type for it */ - df->df_type = standard_type(T_RECORD, 0, (arith) 0); + df->df_type = standard_type(T_RECORD, 1, (arith) 0); df->df_type->rec_scope = sc; /* Generate code that indicates that the initialization procedure for this module is local. */ - C_inp(buf); + (*c_inp)(buf); return df; } diff --git a/lang/m2/comp/defmodule.c b/lang/m2/comp/defmodule.c index b381d68b..e1a86160 100644 --- a/lang/m2/comp/defmodule.c +++ b/lang/m2/comp/defmodule.c @@ -36,7 +36,7 @@ GetFile(name) buf[10] = '\0'; /* maximum length */ strcat(buf, ".def"); if (! InsertFile(buf, DEFPATH, &(FileName))) { - error("could'nt find a DEFINITION MODULE for \"%s\"", name); + error("could not find a DEFINITION MODULE for \"%s\"", name); return 0; } LineNumber = 1; @@ -56,6 +56,7 @@ GetDefinitionModule(id, incr) struct def *df; static int level; struct scopelist *vis; + int didread = 0; level += incr; df = lookup(id, GlobalScope, 1); @@ -68,6 +69,7 @@ GetDefinitionModule(id, incr) else { open_scope(CLOSEDSCOPE); if (!is_anon_idf(id) && GetFile(id->id_text)) { + didread = 1; DefModule(); if (level == 1) { /* The module is directly imported by @@ -93,6 +95,9 @@ GetDefinitionModule(id, incr) } df = lookup(id, GlobalScope, 1); if (! df) { + if (didread) { + error("did not read a DEFINITION MODULE for \"%s\"", id->id_text); + } df = MkDef(id, GlobalScope, D_ERROR); df->df_type = error_type; df->mod_vis = vis; diff --git a/lang/m2/comp/expression.g b/lang/m2/comp/expression.g index 787669bd..542d18e8 100644 --- a/lang/m2/comp/expression.g +++ b/lang/m2/comp/expression.g @@ -50,7 +50,7 @@ ExpList(struct node **pnd;) register struct node *nd; } : expression(pnd) { *pnd = nd = MkNode(Link,*pnd,NULLNODE,&dot); - (*pnd)->nd_symb = ','; + nd->nd_symb = ','; } [ ',' { nd->nd_right = MkLeaf(Link, &dot); @@ -60,20 +60,26 @@ ExpList(struct node **pnd;) ]* ; -ConstExpression(struct node **pnd;): +ConstExpression(struct node **pnd;) +{ + register struct node *nd; +}: expression(pnd) /* * Changed rule in new Modula-2. * Check that the expression is a constant expression and evaluate! */ - { DO_DEBUG(options['X'], print("CONSTANT EXPRESSION\n")); - DO_DEBUG(options['X'], PrNode(*pnd, 0)); - if (ChkExpression(*pnd) && - ((*pnd)->nd_class != Set && (*pnd)->nd_class != Value)) { + { nd = *pnd; + DO_DEBUG(options['X'], print("CONSTANT EXPRESSION\n")); + DO_DEBUG(options['X'], PrNode(nd, 0)); + + if (ChkExpression(nd) && + ((nd)->nd_class != Set && (nd)->nd_class != Value)) { error("constant expression expected"); } + DO_DEBUG(options['X'], print("RESULTS IN\n")); - DO_DEBUG(options['X'], PrNode(*pnd, 0)); + DO_DEBUG(options['X'], PrNode(nd, 0)); } ; @@ -102,6 +108,7 @@ SimpleExpression(struct node **pnd;) [ '+' | '-' ] { *pnd = MkLeaf(Uoper, &dot); pnd = &((*pnd)->nd_right); + /* priority of unary operator ??? */ } ]? term(pnd) diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index 9468c466..10c44f0e 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -29,6 +29,9 @@ struct def *Defined; extern int err_occurred; extern int fp_used; /* set if floating point used */ +extern C_inp(), C_exp(); +int (*c_inp)() = C_inp; + main(argc, argv) register char **argv; { @@ -49,6 +52,7 @@ main(argc, argv) fprint(STDERR, "%s: Use a file argument\n", ProgName); return 1; } + if (options['x']) c_inp = C_exp; return !Compile(Nargv[1], Nargv[2]); } @@ -197,6 +201,7 @@ do_SYSTEM() */ open_scope(CLOSEDSCOPE); (void) Enter("WORD", D_TYPE, word_type, 0); + (void) Enter("BYTE", D_TYPE, byte_type, 0); (void) Enter("ADDRESS", D_TYPE, address_type, 0); (void) Enter("ADR", D_PROCEDURE, std_type, S_ADR); (void) Enter("TSIZE", D_PROCEDURE, std_type, S_TSIZE); @@ -215,14 +220,14 @@ Info() { extern int cnt_def, cnt_node, cnt_paramlist, cnt_type, cnt_switch_hdr, cnt_case_entry, - cnt_scope, cnt_scopelist, cnt_forwards, cnt_tmpvar; + cnt_scope, cnt_scopelist, cnt_tmpvar; print("\ %6d def\n%6d node\n%6d paramlist\n%6d type\n%6d switch_hdr\n\ -%6d case_entry\n%6d scope\n%6d scopelist\n%6d forwards\n%6d tmpvar\n", +%6d case_entry\n%6d scope\n%6d scopelist\n%6d tmpvar\n", cnt_def, cnt_node, cnt_paramlist, cnt_type, cnt_switch_hdr, cnt_case_entry, -cnt_scope, cnt_scopelist, cnt_forwards, cnt_tmpvar); +cnt_scope, cnt_scopelist, cnt_tmpvar); print("\nNumber of lines read: %d\n", cntlines); } #endif diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 100c55df..b45e5f9c 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -59,10 +59,12 @@ ModuleDeclaration priority(arith *pprio;) { - struct node *nd; + register struct node *nd; + struct node *nd1; /* &nd is illegal */ } : - '[' ConstExpression(&nd) ']' - { if (!(nd->nd_type->tp_fund & T_CARDINAL)) { + '[' ConstExpression(&nd1) ']' + { nd = nd1; + if (!(nd->nd_type->tp_fund & T_CARDINAL)) { node_error(nd, "illegal priority"); } *pprio = nd->nd_INT; @@ -70,9 +72,7 @@ priority(arith *pprio;) } ; -export(int *QUALflag; struct node **ExportList;) -{ -} : +export(int *QUALflag; struct node **ExportList;): EXPORT [ QUALIFIED @@ -86,7 +86,7 @@ export(int *QUALflag; struct node **ExportList;) import(int local;) { struct node *ImportList; - struct node *FromId = 0; + register struct node *FromId = 0; register struct def *df; extern struct def *GetDefinitionModule(); } : @@ -121,7 +121,7 @@ DefinitionModule if (!Defined) Defined = df; CurrentScope->sc_name = df->df_idf->id_text; df->mod_vis = CurrVis; - df->df_type = standard_type(T_RECORD, 0, (arith) 0); + df->df_type = standard_type(T_RECORD, 1, (arith) 0); df->df_type->rec_scope = df->mod_vis->sc_scope; DefinitionModule++; } @@ -210,12 +210,9 @@ ProgramModule ; Module: - { open_scope(CLOSEDSCOPE); - warning(W_ORDINARY, "Compiling a definition module"); - } - DefinitionModule - { close_scope(SC_CHKFORW); } -| + DEFINITION + { fatal("Compiling a definition module"); } +| %default [ IMPLEMENTATION { state = IMPLEMENTATION; } | diff --git a/lang/m2/comp/scope.C b/lang/m2/comp/scope.C index d2a26c55..a81557f4 100644 --- a/lang/m2/comp/scope.C +++ b/lang/m2/comp/scope.C @@ -50,7 +50,6 @@ InitScope() register struct scopelist *ls = new_scopelist(); sc->sc_scopeclosed = 0; - sc->sc_forw = 0; sc->sc_def = 0; sc->sc_level = proclevel; PervasiveScope = sc; @@ -61,14 +60,6 @@ InitScope() CurrVis = ls; } -struct forwards { - struct forwards *next; - struct node *fo_tok; - struct type *fo_ptyp; -}; - -/* STATICALLOCDEF "forwards" 5 */ - Forward(tk, ptp) struct node *tk; struct type *ptp; @@ -78,13 +69,10 @@ Forward(tk, ptp) may have forward references that must howewer be declared in the same scope. */ - register struct forwards *f = new_forwards(); - register struct scope *sc = CurrentScope; + register struct def *df = define(tk->nd_IDF, CurrentScope, D_FORWTYPE); - f->fo_tok = tk; - f->fo_ptyp = ptp; - f->next = sc->sc_forw; - sc->sc_forw = f; + df->df_forw_type = ptp; + df->df_forw_node = tk; } STATIC @@ -117,7 +105,15 @@ chk_forw(pdf) register struct def *df; while (df = *pdf) { - if (df->df_kind & (D_FORWARD|D_FORWMODULE)) { + if (df->df_kind == D_FORWTYPE) { +node_error(df->df_forw_node, "type \"%s\" not declared", df->df_idf->id_text); + FreeNode(df->df_forw_node); + } + else if (df->df_kind == D_FTYPE) { + df->df_kind = D_TYPE; + df->df_forw_type->next = df->df_type; + } + else if (df->df_kind & (D_FORWARD|D_FORWMODULE)) { /* These definitions must be found in the enclosing closed scope, which of course may be the scope that is now closed! @@ -126,7 +122,7 @@ chk_forw(pdf) /* Indeed, the scope was a closed scope, so give error message */ -node_error(df->for_node, "identifier \"%s\" has not been declared", +node_error(df->for_node, "identifier \"%s\" not declared", df->df_idf->id_text); FreeNode(df->for_node); } @@ -153,25 +149,6 @@ df->df_idf->id_text); } } -STATIC -rem_forwards(fo) - register struct forwards *fo; -{ - /* When closing a scope, all forward references must be resolved - */ - register struct def *df; - - if (fo->next) rem_forwards(fo->next); - df = lookfor(fo->fo_tok, CurrVis, 0); - if (! is_type(df)) { - node_error(fo->fo_tok, - "identifier \"%s\" does not represent a type", - df->df_idf->id_text); - } - fo->fo_ptyp->next = df->df_type; - free_forwards(fo); -} - Reverse(pdf) struct def **pdf; { @@ -210,7 +187,6 @@ close_scope(flag) assert(sc != 0); if (flag) { - if (sc->sc_forw) rem_forwards(sc->sc_forw); DO_DEBUG(options['S'], PrScopeDef(sc->sc_def)); if (flag & SC_CHKPROC) chk_proc(sc->sc_def); if (flag & SC_CHKFORW) chk_forw(&(sc->sc_def)); diff --git a/lang/m2/comp/scope.h b/lang/m2/comp/scope.h index 770919c1..8e105b72 100644 --- a/lang/m2/comp/scope.h +++ b/lang/m2/comp/scope.h @@ -15,7 +15,6 @@ struct scope { struct scope *next; - struct forwards *sc_forw; char *sc_name; /* name of this scope */ struct def *sc_def; /* list of definitions in this scope */ arith sc_off; /* offsets of variables in this scope */ diff --git a/lang/m2/comp/tmpvar.C b/lang/m2/comp/tmpvar.C index 7e0cea21..294ef077 100644 --- a/lang/m2/comp/tmpvar.C +++ b/lang/m2/comp/tmpvar.C @@ -40,6 +40,16 @@ TmpOpen(sc) struct scope *sc; ProcScope = sc; } +arith +TmpSpace(sz, al) + arith sz; +{ + register struct scope *sc = ProcScope; + + sc->sc_off = - WA(align(sz - sc->sc_off, al)); + return sc->sc_off; +} + arith NewInt() { @@ -47,8 +57,7 @@ NewInt() register struct tmpvar *tmp; if (!TmpInts) { - offset = - WA(align(int_size - ProcScope->sc_off, int_align)); - ProcScope->sc_off = offset; + offset = TmpSpace(int_size, int_align); if (! options['n']) C_ms_reg(offset, int_size, reg_any, 0); } else { @@ -67,8 +76,7 @@ NewPtr() register struct tmpvar *tmp; if (!TmpPtrs) { - offset = - WA(align(pointer_size - ProcScope->sc_off, pointer_align)); - ProcScope->sc_off = offset; + offset = TmpSpace(pointer_size, pointer_align); if (! options['n']) C_ms_reg(offset, pointer_size, reg_pointer, 0); } else { diff --git a/lang/m2/comp/type.H b/lang/m2/comp/type.H index d8a345a7..b22559c3 100644 --- a/lang/m2/comp/type.H +++ b/lang/m2/comp/type.H @@ -95,6 +95,7 @@ extern struct type *real_type, *longreal_type, *word_type, + *byte_type, *address_type, *intorcard_type, *bitset_type, diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index e7656580..134cbec6 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -48,6 +48,7 @@ struct type *real_type, *longreal_type, *word_type, + *byte_type, *address_type, *intorcard_type, *bitset_type, @@ -123,7 +124,7 @@ standard_type(fund, align, size) register struct type *tp = new_type(); tp->tp_fund = fund; - tp->tp_align = align; + tp->tp_align = align ? align : 1; tp->tp_size = size; return tp; @@ -179,6 +180,7 @@ InitTypes() /* SYSTEM types */ word_type = standard_type(T_WORD, word_align, word_size); + byte_type = standard_type(T_WORD, 1, (arith) 1); address_type = construct_type(T_POINTER, word_type); /* create BITSET type @@ -407,11 +409,11 @@ ArrayElSize(tp) if (tp->tp_fund == T_ARRAY) ArraySizes(tp); algn = align(tp->tp_size, tp->tp_align); - if (algn && word_size % algn != 0) { + if (word_size % algn != 0) { /* algn is not a dividor of the word size, so make sure it is a multiple */ - algn = WA(algn); + return WA(algn); } return algn; } @@ -432,13 +434,13 @@ ArraySizes(tp) */ if (! bounded(index_type)) { error("illegal index type"); - tp->tp_size = 0; + tp->tp_size = tp->arr_elsize; return; } getbounds(index_type, &lo, &hi); - tp->tp_size = WA((hi - lo + 1) * tp->arr_elsize); + tp->tp_size = (hi - lo + 1) * tp->arr_elsize; /* generate descriptor and remember label. */ diff --git a/lang/m2/comp/typequiv.c b/lang/m2/comp/typequiv.c index 9735e0cb..ffd5aa42 100644 --- a/lang/m2/comp/typequiv.c +++ b/lang/m2/comp/typequiv.c @@ -177,7 +177,7 @@ TstParCompat(formaltype, actualtype, VARflag, nd) /* Check type compatibility for a parameter in a procedure call. Assignment compatibility may do if the parameter is a value parameter. - Otherwise, a conformant array may do, or an ARRAY OF WORD + Otherwise, a conformant array may do, or an ARRAY OF (WORD|BYTE) may do too. Or: a WORD may do. */ @@ -201,10 +201,15 @@ TstParCompat(formaltype, actualtype, VARflag, nd) ) ) ) + || + ( formaltype == byte_type + && actualtype->tp_size == (arith) 1 + ) || ( IsConformantArray(formaltype) && ( formaltype->arr_elem == word_type + || formaltype->arr_elem == byte_type || ( actualtype->tp_fund == T_ARRAY && TstTypeEquiv(formaltype->arr_elem,actualtype->arr_elem) diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index 5eb55204..e513174b 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -44,13 +44,15 @@ DoProfil() static label filename_label = 0; if (! options['L']) { - if (!filename_label) { - filename_label = ++data_label; - C_df_dlb(filename_label); + register label fn_label = filename_label; + + if (!fn_label) { + filename_label = fn_label = ++data_label; + C_df_dlb(fn_label); C_rom_scon(FileName, (arith) (strlen(FileName) + 1)); } - C_fil_dlb(filename_label, (arith) 0); + C_fil_dlb(fn_label, (arith) 0); } } @@ -126,7 +128,7 @@ WalkProcedure(procedure) local definitions, checking and generating code. */ struct scopelist *savevis = CurrVis; - register struct scope *sc; + register struct scope *sc = procedure->prc_vis->sc_scope; register struct type *tp; register struct paramlist *param; label func_res_label = 0; @@ -136,7 +138,6 @@ WalkProcedure(procedure) proclevel++; CurrVis = procedure->prc_vis; - sc = CurrentScope; /* Generate code for all local modules and procedures */ @@ -390,7 +391,7 @@ WalkCall(nd) } WalkStat(nd, exit_label) - struct node *nd; + register struct node *nd; label exit_label; { /* Walk through a statement, generating code for it. @@ -468,10 +469,11 @@ WalkStat(nd, exit_label) { arith tmp = 0; register struct node *fnd; + int good_forvar; label l1 = ++text_label; label l2 = ++text_label; - if (! DoForInit(nd, left)) break; + good_forvar = DoForInit(nd, left); fnd = left->nd_right; if (fnd->nd_class != Value) { /* Upperbound not constant. @@ -489,15 +491,19 @@ WalkStat(nd, exit_label) C_bgt(l2); } else C_blt(l2); - RangeCheck(nd->nd_type, int_type); - CodeDStore(nd); + if (good_forvar) { + RangeCheck(nd->nd_type, int_type); + CodeDStore(nd); + } WalkNode(right, exit_label); - CodePExpr(nd); - C_loc(left->nd_INT); - C_adi(int_size); - C_bra(l1); - C_df_ilb(l2); - C_asp(int_size); + if (good_forvar) { + CodePExpr(nd); + C_loc(left->nd_INT); + C_adi(int_size); + C_bra(l1); + C_df_ilb(l2); + C_asp(int_size); + } if (tmp) FreeInt(tmp); } break; @@ -545,14 +551,23 @@ WalkStat(nd, exit_label) case RETURN: if (right) { - if (! WalkExpr(right)) break; + if (! ChkExpression(right)) break; /* The type of the return-expression must be assignment compatible with the result type of the function procedure (See Rep. 9.11). */ if (!TstAssCompat(func_type, right->nd_type)) { node_error(right, "type incompatibility in RETURN statement"); + break; } + if (right->nd_type->tp_fund == T_STRING) { + arith strsize = WA(right->nd_type->tp_size); + + C_zer(WA(func_type->tp_size) - strsize); + CodePExpr(right); + C_loi(strsize); + } + else CodePExpr(right); } C_bra(RETURN_LABEL); break; @@ -644,12 +659,12 @@ DoForInit(nd, left) if (df->df_kind == D_FIELD) { node_error(nd, "FOR-loop variable may not be a field of a record"); - return 0; + return 1; } if (!df->var_name && df->var_off >= 0) { node_error(nd, "FOR-loop variable may not be a parameter"); - return 0; + return 1; } if (df->df_scope != CurrentScope) { @@ -659,7 +674,7 @@ DoForInit(nd, left) if (!sc) { node_error(nd, "FOR-loop variable may not be imported"); - return 0; + return 1; } if (sc->sc_scope == df->df_scope) break; sc = nextvisible(sc); @@ -669,7 +684,7 @@ DoForInit(nd, left) if (df->df_type->tp_size > word_size || !(df->df_type->tp_fund & T_DISCRETE)) { node_error(nd, "illegal type of FOR loop variable"); - return 0; + return 1; } if (!TstCompat(df->df_type, left->nd_left->nd_type) || @@ -677,7 +692,7 @@ DoForInit(nd, left) if (!TstAssCompat(df->df_type, left->nd_left->nd_type) || !TstAssCompat(df->df_type, left->nd_right->nd_type)) { node_error(nd, "type incompatibility in FOR statement"); - return 0; + return 1; } node_warning(nd, W_OLDFASHIONED, "compatibility required in FOR statement"); } @@ -695,29 +710,48 @@ DoAssign(nd, left, right) DAMN THE BOOK! */ struct desig dsl, dsr; + register struct type *rtp, *ltp; if (! (ChkExpression(right) & ChkVariable(left))) return; + rtp = right->nd_type; + ltp = left->nd_type; - if (right->nd_symb == STRING) TryToString(right, left->nd_type); + if (right->nd_symb == STRING) TryToString(right, ltp); dsr = InitDesig; - if (! TstAssCompat(left->nd_type, right->nd_type)) { + if (! TstAssCompat(ltp, rtp)) { node_error(nd, "type incompatibility in assignment"); return; } CodeExpr(right, &dsr, NO_LABEL, NO_LABEL); - if (complex(right->nd_type)) { - CodeAddress(&dsr); - } + if (complex(rtp)) CodeAddress(&dsr); else { - CodeValue(&dsr, right->nd_type->tp_size); - RangeCheck(left->nd_type, right->nd_type); + CodeValue(&dsr, rtp->tp_size); + RangeCheck(ltp, rtp); + CodeCoercion(rtp, ltp); } dsl = InitDesig; CodeDesig(left, &dsl); - CodeAssign(nd, &dsr, &dsl); + /* Generate code for an assignment. Testing of type + compatibility and the like is already done. + */ + + if (dsr.dsg_kind == DSG_LOADED) { + if (rtp->tp_fund == T_STRING) { + CodeAddress(&dsl); + C_loc(rtp->tp_size); + C_loc(ltp->tp_size); + C_cal("_StringAssign"); + C_asp((int_size << 1) + (pointer_size << 1)); + return; + } + CodeStore(&dsl, ltp->tp_size); + return; + } + CodeAddress(&dsl); + C_blm(ltp->tp_size); } RegisterMessages(df) From 43f4599a42c3bcc6f7bfd38489f19381aab6a8a5 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 28 Nov 1986 11:59:08 +0000 Subject: [PATCH 0349/1625] many bug fixes, and added flexibility in alignments --- lang/m2/comp/Version.c | 2 +- lang/m2/comp/chk_expr.c | 10 +- lang/m2/comp/code.c | 54 ++++---- lang/m2/comp/cstoper.c | 2 +- lang/m2/comp/declar.g | 13 +- lang/m2/comp/def.c | 3 + lang/m2/comp/defmodule.c | 2 +- lang/m2/comp/desig.c | 263 ++++++++++++++++++++++++++++++++++----- lang/m2/comp/enter.c | 18 ++- lang/m2/comp/program.g | 7 +- lang/m2/comp/scope.C | 17 ++- lang/m2/comp/statement.g | 7 +- lang/m2/comp/walk.c | 61 +++------ 13 files changed, 337 insertions(+), 122 deletions(-) diff --git a/lang/m2/comp/Version.c b/lang/m2/comp/Version.c index 521e211a..3eac6923 100644 --- a/lang/m2/comp/Version.c +++ b/lang/m2/comp/Version.c @@ -1 +1 @@ -char Version[] = "ACK Modula-2 compiler Version 0.8"; +static char Version[] = "ACK Modula-2 compiler Version 0.9"; diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index 0e2b0ccc..d97a51f2 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -540,7 +540,7 @@ ChkProcCall(expp) if (left->nd_symb == STRING) { TryToString(left, TypeOfParam(param)); } - else if (! TstParCompat(RemoveEqual(TypeOfParam(param)), + if (! TstParCompat(RemoveEqual(TypeOfParam(param)), left->nd_type, IsVarParam(param), left)) { @@ -1017,10 +1017,14 @@ ChkStandard(expp, left) case S_TSIZE: /* ??? */ case S_SIZE: expp->nd_type = intorcard_type; - if (! getname(&arg, D_FIELD|D_VARIABLE|D_ISTYPE, 0, edf)) { + if (!(left = getname(&arg,D_FIELD|D_VARIABLE|D_ISTYPE,0,edf))) { return 0; } - cstcall(expp, S_SIZE); + if (! IsConformantArray(left->nd_type)) cstcall(expp, S_SIZE); + else node_warning(expp, + W_STRICT, + "%s on conformant array", + expp->nd_left->nd_def->df_idf->id_text); break; case S_TRUNC: diff --git a/lang/m2/comp/code.c b/lang/m2/comp/code.c index a91f0c98..bbef689f 100644 --- a/lang/m2/comp/code.c +++ b/lang/m2/comp/code.c @@ -65,27 +65,6 @@ CodeString(nd) } } -STATIC -CodePadString(nd, sz) - register struct node *nd; - arith sz; -{ - /* Generate code to push the string indicated by "nd". - Make it null-padded to "sz" bytes - */ - register arith sizearg = WA(nd->nd_type->tp_size); - - assert(nd->nd_type->tp_fund == T_STRING); - - if (sizearg != sz) { - /* null padding required */ - assert(sizearg < sz); - C_zer(sz - sizearg); - } - CodeString(nd); /* push address of string */ - C_loi(sizearg); -} - CodeExpr(nd, ds, true_label, false_label) register struct node *nd; register struct desig *ds; @@ -180,7 +159,7 @@ CodeExpr(nd, ds, true_label, false_label) if (true_label != 0) { /* Only for boolean expressions */ - CodeValue(ds, tp->tp_size); + CodeValue(ds, tp->tp_size, tp->tp_align); *ds = InitDesig; C_zne(true_label); C_bra(false_label); @@ -422,7 +401,16 @@ CodeParameters(param, arg) return; } if (left_type->tp_fund == T_STRING) { - CodePadString(left, tp->tp_size); + register arith szarg = WA(left_type->tp_size); + arith sz = WA(tp->tp_size); + + if (szarg != sz) { + /* null padding required */ + assert(szarg < sz); + C_zer(sz - szarg); + } + CodeString(left); /* push address of string */ + C_loi(szarg); return; } CodePExpr(left); @@ -480,6 +468,15 @@ CodeStd(nd) DoHIGH(left); break; + case S_SIZE: + case S_TSIZE: + assert(IsConformantArray(tp)); + DoHIGH(left); + C_inc(); + C_loc(tp->arr_elem->tp_size); + C_mlu(word_size); + break; + case S_ODD: CodePExpr(left); if (tp->tp_size == word_size) { @@ -951,7 +948,7 @@ CodeEl(nd, tp) } CodePExpr(nd) - struct node *nd; + register struct node *nd; { /* Generate code to push the value of the expression "nd" on the stack. @@ -960,7 +957,7 @@ CodePExpr(nd) designator = InitDesig; CodeExpr(nd, &designator, NO_LABEL, NO_LABEL); - CodeValue(&designator, nd->nd_type->tp_size); + CodeValue(&designator, nd->nd_type->tp_size, nd->nd_type->tp_align); } CodeDAddress(nd) @@ -988,7 +985,7 @@ CodeDStore(nd) designator = InitDesig; CodeDesig(nd, &designator); - CodeStore(&designator, nd->nd_type->tp_size); + CodeStore(&designator, nd->nd_type->tp_size, nd->nd_type->tp_align); } DoHIGH(nd) @@ -1006,8 +1003,9 @@ DoHIGH(nd) assert(IsConformantArray(df->df_type)); highoff = df->var_off /* base address and descriptor */ - + pointer_size /* skip base address */ - + word_size; /* skip first field of descriptor */ + + 2 * word_size; /* skip base and first field of + descriptor + */ if (df->df_scope->sc_level < proclevel) { C_lxa((arith) (proclevel - df->df_scope->sc_level)); C_lof(highoff); diff --git a/lang/m2/comp/cstoper.c b/lang/m2/comp/cstoper.c index 5f743b42..878bc2c6 100644 --- a/lang/m2/comp/cstoper.c +++ b/lang/m2/comp/cstoper.c @@ -469,7 +469,7 @@ cstcall(expp, call) break; case S_SIZE: - expp->nd_INT = WA(expr->nd_type->tp_size); + expp->nd_INT = expr->nd_type->tp_size; break; case S_VAL: diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 0f309aec..c08bfe12 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -62,11 +62,11 @@ block(struct node **pnd;) : ; declaration: - CONST [ ConstantDeclaration ';' ]* + CONST [ %persistent ConstantDeclaration ';' ]* | - TYPE [ TypeDeclaration ';' ]* + TYPE [ %persistent TypeDeclaration ';' ]* | - VAR [ VariableDeclaration ';' ]* + VAR [ %persistent VariableDeclaration ';' ]* | ProcedureDeclaration ';' | @@ -239,7 +239,7 @@ RecordType(struct type **ptp;) close_scope(0); } FieldListSequence(scope, &size, &xalign) - { *ptp = standard_type(T_RECORD, xalign, WA(size)); + { *ptp = standard_type(T_RECORD, xalign, size); (*ptp)->rec_scope = scope; } END @@ -525,5 +525,8 @@ VariableDeclaration IdentAddr(struct node **pnd;) : IDENT { *pnd = MkLeaf(Name, &dot); } - ConstExpression(&((*pnd)->nd_left))? + [ '[' + ConstExpression(&((*pnd)->nd_left)) + ']' + ]? ; diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index e32e5484..c7e1d5b3 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -131,6 +131,9 @@ define(id, scope, kind) } break; + case D_TYPE: + if (kind == D_FORWTYPE) return df; + break; case D_FORWTYPE: if (kind == D_FORWTYPE) return df; if (kind == D_TYPE) { diff --git a/lang/m2/comp/defmodule.c b/lang/m2/comp/defmodule.c index e1a86160..0e661447 100644 --- a/lang/m2/comp/defmodule.c +++ b/lang/m2/comp/defmodule.c @@ -103,7 +103,7 @@ GetDefinitionModule(id, incr) df->mod_vis = vis; } } - else if (df == Defined) { + else if (df == Defined && level == 1) { error("cannot import from currently defined module"); df->df_kind = D_ERROR; } diff --git a/lang/m2/comp/desig.c b/lang/m2/comp/desig.c index 66d7ab4e..09e66db0 100644 --- a/lang/m2/comp/desig.c +++ b/lang/m2/comp/desig.c @@ -24,39 +24,85 @@ extern int proclevel; struct desig InitDesig = {DSG_INIT, 0, 0}; -CodeValue(ds, size) +STATIC int +properly(ds, size, al) + register struct desig *ds; + arith size; +{ + /* Check if it is allowed to load or store the value indicated + by "ds" with LOI/STI. + - if the size is not either a multiple or a dividor of the + wordsize, then not. + - if the alignment is at least "word" then OK. + - if size is dividor of word_size and alignment >= size then OK. + - otherwise check alignment of address. This can only be done + with DSG_FIXED. + */ + + arith szmodword = size % word_size; /* 0 if multiple of wordsize */ + arith wordmodsz = word_size % size; /* 0 if dividor of wordsize */ + + if (szmodword && wordmodsz) return 0; + if (al >= word_size) return 1; + if (szmodword && al >= szmodword) return 1; + + return ds->dsg_kind == DSG_FIXED && + ((! szmodword && ds->dsg_offset % word_size == 0) || + (! wordmodsz && ds->dsg_offset % size == 0)); +} + +CodeValue(ds, size, al) register struct desig *ds; arith size; { /* Generate code to load the value of the designator described in "ds" */ + arith tmp = 0; switch(ds->dsg_kind) { case DSG_LOADED: break; case DSG_FIXED: - if (size == word_size) { - if (ds->dsg_name) { - C_loe_dnam(ds->dsg_name, ds->dsg_offset); + if (ds->dsg_offset % word_size == 0) { + if (size == word_size) { + if (ds->dsg_name) { + C_loe_dnam(ds->dsg_name,ds->dsg_offset); + } + else C_lol(ds->dsg_offset); + break; } - else C_lol(ds->dsg_offset); - break; - } - - if (size == dword_size) { - if (ds->dsg_name) { - C_lde_dnam(ds->dsg_name, ds->dsg_offset); + + if (size == dword_size) { + if (ds->dsg_name) { + C_lde_dnam(ds->dsg_name,ds->dsg_offset); + } + else C_ldl(ds->dsg_offset); + break; } - else C_ldl(ds->dsg_offset); - break; } /* Fall through */ case DSG_PLOADED: case DSG_PFIXED: - CodeAddress(ds); - C_loi(size); + if (properly(ds, size, al)) { + CodeAddress(ds); + C_loi(size); + break; + } + if (ds->dsg_kind == DSG_PLOADED) { + tmp = NewPtr(); + C_stl(tmp); + } + C_asp(-WA(size)); + if (!tmp) CodeAddress(ds); + else { + C_lol(tmp); + FreePtr(tmp); + } + C_loc(size); + C_cal("_load"); + C_asp(2 * word_size); break; case DSG_INDEXED: @@ -70,36 +116,46 @@ CodeValue(ds, size) ds->dsg_kind = DSG_LOADED; } -CodeStore(ds, size) +CodeStore(ds, size, al) register struct desig *ds; arith size; { /* Generate code to store the value on the stack in the designator described in "ds" */ + struct desig save; + save = *ds; switch(ds->dsg_kind) { case DSG_FIXED: - if (size == word_size) { - if (ds->dsg_name) { - C_ste_dnam(ds->dsg_name, ds->dsg_offset); + if (ds->dsg_offset % word_size == 0) { + if (size == word_size) { + if (ds->dsg_name) { + C_ste_dnam(ds->dsg_name,ds->dsg_offset); + } + else C_stl(ds->dsg_offset); + break; } - else C_stl(ds->dsg_offset); - break; - } - if (size == dword_size) { - if (ds->dsg_name) { - C_sde_dnam(ds->dsg_name, ds->dsg_offset); + if (size == dword_size) { + if (ds->dsg_name) { + C_sde_dnam(ds->dsg_name,ds->dsg_offset); + } + else C_sdl(ds->dsg_offset); + break; } - else C_sdl(ds->dsg_offset); - break; } /* Fall through */ case DSG_PLOADED: case DSG_PFIXED: - CodeAddress(ds); - C_sti(size); + CodeAddress(&save); + if (properly(ds, size, al)) { + C_sti(size); + break; + } + C_loc(size); + C_cal("_store"); + C_asp(2 * word_size + WA(size)); break; case DSG_INDEXED: @@ -113,6 +169,146 @@ CodeStore(ds, size) ds->dsg_kind = DSG_INIT; } +CodeCopy(lhs, rhs, sz, psize) + register struct desig *lhs, *rhs; + arith sz, *psize; +{ + struct desig l, r; + + l = *lhs; r = *rhs; + *psize -= sz; + lhs->dsg_offset += sz; + rhs->dsg_offset += sz; + CodeAddress(&r); + C_loi(sz); + CodeAddress(&l); + C_sti(sz); +} + +CodeMove(rhs, left, rtp) + register struct desig *rhs; + register struct node *left; + struct type *rtp; +{ + struct desig dsl; + register struct desig *lhs = &dsl; + register struct type *tp = left->nd_type; + int loadedflag = 0; + + dsl = InitDesig; + + /* Generate code for an assignment. Testing of type + compatibility and the like is already done. + Go through some (considerable) trouble to see if a BLM can be + generated. + */ + + switch(rhs->dsg_kind) { + case DSG_LOADED: + CodeDesig(left, lhs); + CodeAddress(lhs); + if (rtp->tp_fund == T_STRING) { + C_loc(rtp->tp_size); + C_loc(tp->tp_size); + C_cal("_StringAssign"); + C_asp(word_size << 2); + return; + } + CodeStore(lhs, tp->tp_size, tp->tp_align); + return; + case DSG_PLOADED: + case DSG_PFIXED: + CodeAddress(rhs); + if (tp->tp_size % word_size == 0 && tp->tp_align >= word_size) { + CodeDesig(left, lhs); + CodeAddress(lhs); + C_blm(tp->tp_size); + return; + } + CodeValue(rhs, tp->tp_size, tp->tp_align); + CodeDStore(left); + return; + case DSG_FIXED: + CodeDesig(left, lhs); + if (lhs->dsg_kind == DSG_FIXED && + lhs->dsg_offset % word_size == + rhs->dsg_offset % word_size) { + register arith sz; + arith size = tp->tp_size; + + while (size && (sz = (lhs->dsg_offset % word_size))) { + /* First copy up to word-aligned + boundaries + */ + if (sz < 0) sz = -sz; /* bloody '%' */ + while (word_size % sz) sz--; + CodeCopy(lhs, rhs, sz, &size); + } + if (size > 3*dword_size) { + /* Do a block move + */ + struct desig l, r; + + sz = (size / word_size) * word_size; + l = *lhs; r = *rhs; + CodeAddress(&r); + CodeAddress(&l); + C_blm(sz); + rhs->dsg_offset += sz; + lhs->dsg_offset += sz; + size -= sz; + } + else for (sz = dword_size; sz; sz -= word_size) { + while (size >= sz) { + /* Then copy dwords, words. + Depend on peephole optimizer + */ + CodeCopy(lhs, rhs, sz, &size); + } + } + sz = word_size; + while (size && --sz) { + /* And then copy remaining parts + */ + while (word_size % sz) sz--; + while (size >= sz) { + CodeCopy(lhs, rhs, sz, &size); + } + } + return; + } + if (lhs->dsg_kind == DSG_PLOADED || + lhs->dsg_kind == DSG_INDEXED) { + CodeAddress(lhs); + loadedflag = 1; + } + if (tp->tp_size % word_size == 0 && tp->tp_align >= word_size) { + CodeAddress(rhs); + if (loadedflag) C_exg(pointer_size); + else CodeAddress(lhs); + C_blm(tp->tp_size); + return; + } + { + arith tmp; + + if (loadedflag) { + tmp = NewPtr(); + lhs->dsg_offset = tmp; + lhs->dsg_name = 0; + lhs->dsg_kind = DSG_PFIXED; + C_stl(tmp); /* address of lhs */ + } + CodeValue(rhs, tp->tp_size, tp->tp_align); + CodeStore(lhs, tp->tp_size, tp->tp_align); + if (loadedflag) FreePtr(tmp); + return; + } + default: + crash("CodeMove"); + } +} + CodeAddress(ds) register struct desig *ds; { @@ -136,8 +332,11 @@ CodeAddress(ds) break; case DSG_PFIXED: - ds->dsg_kind = DSG_FIXED; - CodeValue(ds, pointer_size); + if (ds->dsg_name) { + C_loe_dnam(ds->dsg_name,ds->dsg_offset); + break; + } + C_lol(ds->dsg_offset); break; case DSG_INDEXED: @@ -353,7 +552,7 @@ CodeDesig(nd, ds) case DSG_INDEXED: case DSG_PLOADED: case DSG_PFIXED: - CodeValue(ds, pointer_size); + CodeValue(ds, pointer_size, pointer_align); ds->dsg_kind = DSG_PLOADED; ds->dsg_offset = 0; break; diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index 04a948e1..0680a0b5 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -112,9 +112,11 @@ EnterVarList(Idlist, type, local) if (idlist->nd_left) { /* An address was supplied */ + register struct type *tp = idlist->nd_left->nd_type; + df->var_addrgiven = 1; df->df_flags |= D_NOREG; - if (idlist->nd_left->nd_type != card_type) { + if (tp != error_type && !(tp->tp_fund & T_CARDINAL)){ node_error(idlist->nd_left, "illegal type for address"); } @@ -224,6 +226,11 @@ DoImport(df, scope) /* Also import all definitions that are exported from this module */ + if (df->mod_vis == CurrVis) { + error("cannot import current module \"%s\"", + df->df_idf->id_text); + return; + } for (df = df->mod_vis->sc_scope->sc_def; df; df = df->df_nextinscope) { @@ -391,11 +398,16 @@ EnterFromImportList(Idlist, FromDef, FromId) break; case D_MODULE: vis = FromDef->mod_vis; + if (vis == CurrVis) { +node_error(FromId, "cannot import from current module \"%s\"", + FromDef->df_idf->id_text); + return; + } break; default: - node_error(FromId, "identifier \"%s\" does not represent a module", +node_error(FromId, "identifier \"%s\" does not represent a module", FromDef->df_idf->id_text); - break; + return; } for (; idlist; idlist = idlist->next) { diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index b45e5f9c..f7eed0d1 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -157,10 +157,11 @@ definition register struct def *df; struct def *dummy; } : - CONST [ ConstantDeclaration ';' ]* + CONST [ %persistent ConstantDeclaration ';' ]* | TYPE - [ IDENT { df = define(dot.TOK_IDF, CurrentScope, D_TYPE); } + [ %persistent + IDENT { df = define(dot.TOK_IDF, CurrentScope, D_TYPE); } [ '=' type(&(df->df_type)) | /* empty */ /* @@ -175,7 +176,7 @@ definition ';' ]* | - VAR [ VariableDeclaration ';' ]* + VAR [ %persistent VariableDeclaration ';' ]* | ProcedureHeading(&dummy, D_PROCHEAD) ';' diff --git a/lang/m2/comp/scope.C b/lang/m2/comp/scope.C index a81557f4..e94f895c 100644 --- a/lang/m2/comp/scope.C +++ b/lang/m2/comp/scope.C @@ -71,6 +71,10 @@ Forward(tk, ptp) */ register struct def *df = define(tk->nd_IDF, CurrentScope, D_FORWTYPE); + if (df->df_kind == D_TYPE) { + ptp->next = df->df_type; + return; + } df->df_forw_type = ptp; df->df_forw_node = tk; } @@ -106,8 +110,17 @@ chk_forw(pdf) while (df = *pdf) { if (df->df_kind == D_FORWTYPE) { -node_error(df->df_forw_node, "type \"%s\" not declared", df->df_idf->id_text); - FreeNode(df->df_forw_node); + register struct def *df1 = df; + + *pdf = df->df_nextinscope; + RemoveFromIdList(df); + df = lookfor(df->df_forw_node, CurrVis, 1); + if (! df->df_kind & (D_ERROR|D_FTYPE|D_TYPE)) { +node_error(df1->df_forw_node, "\"%s\" is not a type", df1->df_idf->id_text); + } + df1->df_forw_type->next = df->df_type; + FreeNode(df1->df_forw_node); + free_def(df1); } else if (df->df_kind == D_FTYPE) { df->df_kind = D_TYPE; diff --git a/lang/m2/comp/statement.g b/lang/m2/comp/statement.g index 45dc3993..875ea1ea 100644 --- a/lang/m2/comp/statement.g +++ b/lang/m2/comp/statement.g @@ -31,7 +31,12 @@ statement(register struct node **pnd;) } ActualParameters(&(nd->nd_right))? | - BECOMES { nd = MkNode(Stat, *pnd, NULLNODE, &dot); } + [ BECOMES + | '=' { error("':=' expected instead of '='"); + DOT = BECOMES; + } + ] + { nd = MkNode(Stat, *pnd, NULLNODE, &dot); } expression(&(nd->nd_right)) ] { *pnd = nd; } diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index e513174b..4a6da47e 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -221,9 +221,11 @@ WalkProcedure(procedure) /* upper - lower */ C_inc(); /* gives number of elements */ C_loc(tp->arr_elem->tp_size); - C_cal("_wa"); - C_asp(dword_size); - C_lfr(word_size); + C_mli(word_size); + C_loc(word_size - 1); + C_adi(word_size); + C_loc(word_size); + C_dvi(word_size); /* size in words */ C_loc(word_size); C_mli(word_size); @@ -241,25 +243,16 @@ WalkProcedure(procedure) */ C_ass(word_size); /* adjusted stack pointer */ - C_lor((arith) 1); - /* destination address (sp), - also assumes stack grows - downwards ??? - */ - C_lal(param->par_def->var_off); - C_loi(pointer_size); + C_lol(param->par_def->var_off); /* push source address */ - C_exg(pointer_size); - /* exchange them */ C_lol(tmpvar); /* push size */ - C_bls(word_size); - /* copy */ + C_cal("_load"); /* copy */ + C_asp(2 * word_size); C_lor((arith) 1); /* push new address of array ... downwards ... ??? */ - C_lal(param->par_def->var_off); - C_sti(pointer_size); + C_stl(param->par_def->var_off); FreeInt(tmpvar); } } @@ -529,7 +522,7 @@ WalkStat(nd, exit_label) */ ds.dsg_offset = NewPtr(); ds.dsg_name = 0; - CodeStore(&ds, pointer_size); + CodeStore(&ds, pointer_size, pointer_align); ds.dsg_kind = DSG_PFIXED; /* the record is indirectly available */ wds.w_desig = ds; @@ -709,7 +702,7 @@ DoAssign(nd, left, right) it sais that the left hand side is evaluated first. DAMN THE BOOK! */ - struct desig dsl, dsr; + struct desig dsr; register struct type *rtp, *ltp; if (! (ChkExpression(right) & ChkVariable(left))) return; @@ -724,34 +717,18 @@ DoAssign(nd, left, right) return; } +#define StackNeededFor(ds) ((ds)->dsg_kind == DSG_PLOADED \ + || (ds)->dsg_kind == DSG_INDEXED) CodeExpr(right, &dsr, NO_LABEL, NO_LABEL); - if (complex(rtp)) CodeAddress(&dsr); + if (complex(rtp)) { + if (StackNeededFor(&dsr)) CodeAddress(&dsr); + } else { - CodeValue(&dsr, rtp->tp_size); - RangeCheck(ltp, rtp); + CodeValue(&dsr, rtp->tp_size, rtp->tp_align); CodeCoercion(rtp, ltp); + RangeCheck(ltp, rtp); } - dsl = InitDesig; - CodeDesig(left, &dsl); - - /* Generate code for an assignment. Testing of type - compatibility and the like is already done. - */ - - if (dsr.dsg_kind == DSG_LOADED) { - if (rtp->tp_fund == T_STRING) { - CodeAddress(&dsl); - C_loc(rtp->tp_size); - C_loc(ltp->tp_size); - C_cal("_StringAssign"); - C_asp((int_size << 1) + (pointer_size << 1)); - return; - } - CodeStore(&dsl, ltp->tp_size); - return; - } - CodeAddress(&dsl); - C_blm(ltp->tp_size); + CodeMove(&dsr, left, rtp); } RegisterMessages(df) From f55a90224e15074646ef21bf238a81802f0a2c0d Mon Sep 17 00:00:00 2001 From: sater Date: Fri, 28 Nov 1986 13:41:09 +0000 Subject: [PATCH 0350/1625] debugging stuff happened to end up on stdout instead of stderr. --- mach/proto/ncg/nextem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/proto/ncg/nextem.c b/mach/proto/ncg/nextem.c index a9616efd..6f938317 100644 --- a/mach/proto/ncg/nextem.c +++ b/mach/proto/ncg/nextem.c @@ -72,7 +72,7 @@ byte *trypat(bp,len) register byte *bp; { for (i=0;i Date: Fri, 28 Nov 1986 13:47:44 +0000 Subject: [PATCH 0351/1625] added support for modhead --- mach/proto/ncg/fillem.c | 6 ++++++ mach/proto/ncg/main.c | 1 + 2 files changed, 7 insertions(+) diff --git a/mach/proto/ncg/fillem.c b/mach/proto/ncg/fillem.c index dfb85047..b671d896 100644 --- a/mach/proto/ncg/fillem.c +++ b/mach/proto/ncg/fillem.c @@ -111,6 +111,12 @@ in_init(filename) char *filename; { error("Bad format %s",filename); } +in_start() { +#ifdef modhead + fprintf(codefile,"%s",modhead) ; +#endif +} + in_finish() { } diff --git a/mach/proto/ncg/main.c b/mach/proto/ncg/main.c index f8f7d007..e644642d 100644 --- a/mach/proto/ncg/main.c +++ b/mach/proto/ncg/main.c @@ -85,6 +85,7 @@ main(argc,argv) char **argv; { out_init(argv[1]); readcodebytes(); itokcost(); + in_start(); codegen(startupcode,maxply,TRUE,MAXINT,0); error("Bombed out of codegen"); } From 5296d5f9e7febce50b819017ea4b4ce6a3bccbbf Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 1 Dec 1986 09:43:00 +0000 Subject: [PATCH 0352/1625] Removed some signal handling stuff. The Ack-program should do that. --- util/led/error.c | 11 ----------- util/led/output.c | 1 - 2 files changed, 12 deletions(-) diff --git a/util/led/error.c b/util/led/error.c index 358cd9cd..52da2a72 100644 --- a/util/led/error.c +++ b/util/led/error.c @@ -3,7 +3,6 @@ static char rcsid[] = "$Header$"; #endif #include -#include #include #include "const.h" @@ -23,16 +22,6 @@ stop() exit(exitstatus); } -trap_signals() -{ - static int trap_them[] = { SIGHUP, SIGINT, SIGQUIT, SIGTERM, 0 }; - register int *ip; - - for (ip = trap_them; *ip; ip++) - if (signal(*ip, stop) == SIG_IGN) - signal(*ip, SIG_IGN); /* Oops, reset. */ -} - /* VARARGS1 */ fatal(format, a1, a2, a3, a4) char *format; diff --git a/util/led/output.c b/util/led/output.c index 74b5b88a..2c059a1f 100644 --- a/util/led/output.c +++ b/util/led/output.c @@ -35,7 +35,6 @@ beginoutput() outhead.oh_nname = NLocals + NGlobals + outhead.oh_nsect; outhead.oh_nchar = NLChars + NGChars; } - trap_signals(); if (!incore) begin_write(); } From 5617c657b63ef4215d15d424cc885ca652708de8 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 1 Dec 1986 10:00:23 +0000 Subject: [PATCH 0353/1625] handle void properly, avoid 0-alignments, handle #if defined(..) --- lang/cem/cemcom/LLlex.c | 2 +- lang/cem/cemcom/arith.c | 4 +- lang/cem/cemcom/ch7.c | 2 +- lang/cem/cemcom/ch7bin.c | 82 +++++++++------------ lang/cem/cemcom/ch7mon.c | 2 +- lang/cem/cemcom/code.c | 9 ++- lang/cem/cemcom/cstoper.c | 28 ++++---- lang/cem/cemcom/declarator.c | 1 - lang/cem/cemcom/decspecs.c | 2 +- lang/cem/cemcom/eval.c | 134 ++++++++++++++++++++--------------- lang/cem/cemcom/idf.c | 38 ++++++---- lang/cem/cemcom/init.c | 3 + lang/cem/cemcom/main.c | 4 +- lang/cem/cemcom/replace.c | 21 +++++- lang/cem/cemcom/stack.c | 1 + lang/cem/cemcom/type.c | 2 + 16 files changed, 187 insertions(+), 148 deletions(-) diff --git a/lang/cem/cemcom/LLlex.c b/lang/cem/cemcom/LLlex.c index a9a8db8f..84d5b29d 100644 --- a/lang/cem/cemcom/LLlex.c +++ b/lang/cem/cemcom/LLlex.c @@ -267,7 +267,7 @@ go_on: /* rescan, the following character has been read */ if (idef->id_macro && ReplaceMacros && replace(idef)) /* macro replacement should be performed */ goto again; - if (UnknownIdIsZero) { + if (UnknownIdIsZero && idef->id_reserved != SIZEOF) { ptok->tk_ival = (arith)0; ptok->tk_fund = INT; return ptok->tk_symb = INTEGER; diff --git a/lang/cem/cemcom/arith.c b/lang/cem/cemcom/arith.c index c11ad70c..d628ad49 100644 --- a/lang/cem/cemcom/arith.c +++ b/lang/cem/cemcom/arith.c @@ -464,7 +464,7 @@ any2opnd(expp, oper) #ifndef NOBITFIELD field2arith(expp) - struct expr **expp; + register struct expr **expp; { /* The expression to extract the bitfield value from the memory word is put in the tree. @@ -500,7 +500,7 @@ field2arith(expp) take care of the first byte the fl_value pointer points to. */ switch_sign_fp(expr) - struct expr *expr; + register struct expr *expr; { if (*(expr->FL_VALUE) == '-') ++(expr->FL_VALUE); diff --git a/lang/cem/cemcom/ch7.c b/lang/cem/cemcom/ch7.c index 356497d2..a4da640b 100644 --- a/lang/cem/cemcom/ch7.c +++ b/lang/cem/cemcom/ch7.c @@ -128,7 +128,7 @@ ch7sel(expp, oper, idf) } ch7incr(expp, oper) - register struct expr **expp; + struct expr **expp; { /* The monadic prefix/postfix incr/decr operator oper is applied to *expp. diff --git a/lang/cem/cemcom/ch7bin.c b/lang/cem/cemcom/ch7bin.c index 484b1caf..90211bb6 100644 --- a/lang/cem/cemcom/ch7bin.c +++ b/lang/cem/cemcom/ch7bin.c @@ -20,6 +20,9 @@ extern char *symbol2str(); depending on the constancy of the operands. */ +#define commutative_binop(expp, oper, expr) mk_binop(expp, oper, expr, 1) +#define non_commutative_binop(expp, oper, expr) mk_binop(expp, oper, expr, 0) + ch7bin(expp, oper, expr) register struct expr **expp; struct expr *expr; @@ -82,24 +85,28 @@ ch7bin(expp, oper, expr) break; case '%': case MODAB: + case ANDAB: + case XORAB: + case ORAB: opnd2integral(expp, oper); opnd2integral(&expr, oper); - fund = arithbalance(expp, oper, &expr); - non_commutative_binop(expp, oper, expr); - break; + /* Fall through */ case '/': case DIVAB: - fund = arithbalance(expp, oper, &expr); - non_commutative_binop(expp, oper, expr); - break; - case '*': - fund = arithbalance(expp, oper, &expr); - commutative_binop(expp, oper, expr); - break; case TIMESAB: fund = arithbalance(expp, oper, &expr); non_commutative_binop(expp, oper, expr); break; + case '&': + case '^': + case '|': + opnd2integral(expp, oper); + opnd2integral(&expr, oper); + /* Fall through */ + case '*': + fund = arithbalance(expp, oper, &expr); + commutative_binop(expp, oper, expr); + break; case '+': if (expr->ex_type->tp_fund == POINTER) { /* swap operands */ struct expr *etmp = expr; @@ -161,41 +168,27 @@ ch7bin(expp, oper, expr) non_commutative_binop(expp, oper, expr); (*expp)->ex_type = int_type; break; - case '&': - case '^': - case '|': - opnd2integral(expp, oper); - opnd2integral(&expr, oper); - fund = arithbalance(expp, oper, &expr); - commutative_binop(expp, oper, expr); - break; - case ANDAB: - case XORAB: - case ORAB: - opnd2integral(expp, oper); - opnd2integral(&expr, oper); - fund = arithbalance(expp, oper, &expr); - non_commutative_binop(expp, oper, expr); - break; case AND: case OR: opnd2test(expp, oper); opnd2test(&expr, oper); if (is_cp_cst(*expp)) { - struct expr *ex = *expp; + register struct expr *ex = *expp; /* the following condition is a short-hand for ((oper == AND) && o1) || ((oper == OR) && !o1) where o1 == (*expp)->VL_VALUE; and ((oper == AND) || (oper == OR)) */ - if ((oper == AND) == ((*expp)->VL_VALUE != (arith)0)) + if ((oper == AND) == (ex->VL_VALUE != (arith)0)) *expp = expr; else { + ex->ex_flags |= expr->ex_flags; free_expression(expr); *expp = intexpr((arith)((oper == AND) ? 0 : 1), INT); } + (*expp)->ex_flags |= ex->ex_flags; free_expression(ex); } else @@ -205,8 +198,10 @@ ch7bin(expp, oper, expr) where o2 == expr->VL_VALUE and ((oper == AND) || (oper == OR)) */ - if ((oper == AND) == (expr->VL_VALUE != (arith)0)) + if ((oper == AND) == (expr->VL_VALUE != (arith)0)) { + (*expp)->ex_flags |= expr->ex_flags; free_expression(expr); + } else { if (oper == OR) expr->VL_VALUE = (arith)1; @@ -270,31 +265,22 @@ pntminuspnt(expp, oper, expr) ch7cast(expp, CAST, int_type); /* result will be an integer expr */ } -non_commutative_binop(expp, oper, expr) +mk_binop(expp, oper, expr, commutative) register struct expr **expp, *expr; { /* Constructs in *expp the operation indicated by the operands. - "oper" is a non-commutative operator + "commutative" indicates wether "oper" is a commutative + operator. */ - if (is_cp_cst(expr) && is_cp_cst(*expp)) - cstbin(expp, oper, expr); - else - *expp = new_oper((*expp)->ex_type, *expp, oper, expr); -} + register struct expr *ex = *expp; -commutative_binop(expp, oper, expr) - register struct expr **expp, *expr; -{ - /* Constructs in *expp the operation indicated by the operands. - "oper" is a commutative operator - */ - if (is_cp_cst(expr) && is_cp_cst(*expp)) + if (is_cp_cst(expr) && is_cp_cst(ex)) cstbin(expp, oper, expr); - else - if ((*expp)->ex_depth > expr->ex_depth) - *expp = new_oper((*expp)->ex_type, *expp, oper, expr); - else - *expp = new_oper((*expp)->ex_type, expr, oper, *expp); + else { + *expp = (commutative && expr->ex_depth >= ex->ex_depth) ? + new_oper(ex->ex_type, expr, oper, ex) : + new_oper(ex->ex_type, ex, oper, expr); + } } pointer_arithmetic(expp1, oper, expp2) diff --git a/lang/cem/cemcom/ch7mon.c b/lang/cem/cemcom/ch7mon.c index 23c3f5c3..e42ef4fe 100644 --- a/lang/cem/cemcom/ch7mon.c +++ b/lang/cem/cemcom/ch7mon.c @@ -151,9 +151,9 @@ ch7mon(oper, expp) warning("sizeof formal array %s is sizeof pointer!", (*expp)->VL_IDF->id_text); expr = intexpr(size_of_type((*expp)->ex_type, "object"), INT); + expr->ex_flags |= EX_SIZEOF; free_expression(*expp); *expp = expr; - (*expp)->ex_flags |= EX_SIZEOF; break; } } diff --git a/lang/cem/cemcom/code.c b/lang/cem/cemcom/code.c index 696c99b5..ca5013c6 100644 --- a/lang/cem/cemcom/code.c +++ b/lang/cem/cemcom/code.c @@ -437,8 +437,13 @@ bss(idf) /* Since bss() is only called if df_alloc is non-zero, and since df_alloc is only non-zero if size >= 0, we have: */ + /* but we already gave a warning at the declaration of the + array. Besides, the message given here does not apply to + voids + if (options['R'] && size == 0) warning("actual array of size 0"); + */ C_df_dnam(idf->id_text); C_bss_cst(align(size, word_align), (arith)0, 1); } @@ -455,7 +460,9 @@ formal_cvt(df) (tp->tp_fund == CHAR || tp->tp_fund == SHORT) ) { C_lol(df->df_address); - /* conversion(int_type, df->df_type); ??? */ + /* conversion(int_type, df->df_type); ??? + No, you can't do this on the stack! (CJ) + */ C_lal(df->df_address); C_sti(tp->tp_size); df->df_register = REG_NONE; diff --git a/lang/cem/cemcom/cstoper.c b/lang/cem/cemcom/cstoper.c index 8c515410..82f1e3f6 100644 --- a/lang/cem/cemcom/cstoper.c +++ b/lang/cem/cemcom/cstoper.c @@ -120,15 +120,13 @@ cstbin(expp, oper, expr) o1 >>= o2; break; case '<': - if (uns) { - o1 = (o1 & mach_long_sign ? - (o2 & mach_long_sign ? o1 < o2 : 0) : - (o2 & mach_long_sign ? 1 : o1 < o2) - ); + { + arith tmp = o1; + + o1 = o2; + o2 = tmp; } - else - o1 = o1 < o2; - break; + /* Fall through */ case '>': if (uns) { o1 = (o1 & mach_long_sign ? @@ -140,15 +138,13 @@ cstbin(expp, oper, expr) o1 = o1 > o2; break; case LESSEQ: - if (uns) { - o1 = (o1 & mach_long_sign ? - (o2 & mach_long_sign ? o1 <= o2 : 0) : - (o2 & mach_long_sign ? 1 : o1 <= o2) - ); + { + arith tmp = o1; + + o1 = o2; + o2 = tmp; } - else - o1 = o1 <= o2; - break; + /* Fall through */ case GREATEREQ: if (uns) { o1 = (o1 & mach_long_sign ? diff --git a/lang/cem/cemcom/declarator.c b/lang/cem/cemcom/declarator.c index 33bb4e8f..f1a1eb2e 100644 --- a/lang/cem/cemcom/declarator.c +++ b/lang/cem/cemcom/declarator.c @@ -101,7 +101,6 @@ check_array_subscript(expr) else if (size == 0) { warning("empty array declaration"); - expr->VL_VALUE = (arith)-1; } else if (size & ~max_unsigned) { /* absolutely ridiculous */ diff --git a/lang/cem/cemcom/decspecs.c b/lang/cem/cemcom/decspecs.c index ead1cbe6..235fb1ae 100644 --- a/lang/cem/cemcom/decspecs.c +++ b/lang/cem/cemcom/decspecs.c @@ -39,8 +39,8 @@ do_decspecs(ds) ds->ds_sc != REGISTER){ extern char *symbol2str(); error("%s formal illegal", symbol2str(ds->ds_sc)); + ds->ds_sc = FORMAL; } - ds->ds_sc = FORMAL; } /* The tests concerning types require a full knowledge of the type and will have to be postponed to declare_idf. diff --git a/lang/cem/cemcom/eval.c b/lang/cem/cemcom/eval.c index 6c1d260f..12f92437 100644 --- a/lang/cem/cemcom/eval.c +++ b/lang/cem/cemcom/eval.c @@ -96,14 +96,16 @@ EVAL(expr, val, code, true_label, false_label) if (tp->tp_fund == ERRONEOUS) /* stop immediately */ break; + if (tp->tp_fund == VOID) + gencode = 0; switch (oper) { case '+': /* We have the following possibilities : int + int, pointer + int, pointer + long, long + long, double + double */ - EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); - EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL); + EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL); if (gencode) { switch (tp->tp_fund) { case INT: @@ -128,7 +130,7 @@ EVAL(expr, val, code, true_label, false_label) break; case '-': if (left == 0) { /* unary */ - EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL); if (gencode) { switch (tp->tp_fund) { case INT: @@ -151,8 +153,8 @@ EVAL(expr, val, code, true_label, false_label) int - int, pointer - int, pointer - long, pointer - pointer, long - long, double - double */ - EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); - EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL); + EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL); if (!gencode) break; switch (tp->tp_fund) { @@ -182,10 +184,10 @@ EVAL(expr, val, code, true_label, false_label) break; case '*': if (left == 0) /* unary */ - EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL); else { /* binary */ - EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); - EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL); + EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL); if (gencode) switch (tp->tp_fund) { case INT: @@ -207,8 +209,8 @@ EVAL(expr, val, code, true_label, false_label) } break; case '/': - EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); - EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL); + EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL); if (gencode) switch (tp->tp_fund) { case INT: @@ -229,8 +231,8 @@ EVAL(expr, val, code, true_label, false_label) } break; case '%': - EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); - EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL); + EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL); ASSERT(tp->tp_fund==INT || tp->tp_fund==LONG); if (gencode) if (tp->tp_unsigned) @@ -239,8 +241,8 @@ EVAL(expr, val, code, true_label, false_label) C_rmi(tp->tp_size); break; case LEFT: - EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); - EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL); + EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL); if (gencode) if (tp->tp_unsigned) C_slu(tp->tp_size); @@ -248,8 +250,8 @@ EVAL(expr, val, code, true_label, false_label) C_sli(tp->tp_size); break; case RIGHT: - EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); - EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL); + EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL); if (gencode) if (tp->tp_unsigned) C_sru(tp->tp_size); @@ -262,8 +264,8 @@ EVAL(expr, val, code, true_label, false_label) case GREATEREQ: case EQUAL: case NOTEQUAL: - EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); - EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL); + EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL); if (gencode) { /* The operands have the same type */ arith size = left->ex_type->tp_size; @@ -312,8 +314,8 @@ EVAL(expr, val, code, true_label, false_label) case '|': case '^': /* both operands should have type int */ - EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); - EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL); + EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL); if (gencode) { arith size = tp->tp_size; @@ -332,23 +334,26 @@ EVAL(expr, val, code, true_label, false_label) } } break; - case '=': + case '=': { + int newcode = tp->tp_size > 0; /* CJ */ #ifndef NOBITFIELD if (left->ex_type->tp_fund == FIELD) { - eval_field(expr, code); + eval_field(expr, gencode); break; } #endif NOBITFIELD - EVAL(right, RVAL, TRUE, NO_LABEL, NO_LABEL); + EVAL(right, RVAL, newcode, NO_LABEL, NO_LABEL); if (gencode) C_dup(ATW(tp->tp_size)); if (left->ex_class != Value) { - EVAL(left, LVAL, TRUE, NO_LABEL, NO_LABEL); - store_block(tp->tp_size, tp->tp_align); + EVAL(left, LVAL, newcode, NO_LABEL, NO_LABEL); + if (newcode) + store_block(tp->tp_size, tp->tp_align); } - else + else if (newcode) store_val(&(left->ex_object.ex_value), left->ex_type); + } break; case PLUSAB: case MINAB: @@ -367,13 +372,14 @@ EVAL(expr, val, code, true_label, false_label) { arith old_offset, tmp; int compl; /* Complexity of left operand */ + int newcode = left->ex_type->tp_size > 0; /* CJ */ #ifndef NOBITFIELD if (left->ex_type->tp_fund == FIELD) { - eval_field(expr, code); + eval_field(expr, gencode); break; } #endif NOBITFIELD - if (left->ex_class == Value) { + if (newcode && left->ex_class == Value) { compl = 0; /* Value */ load_val(left, RVAL); } @@ -381,34 +387,42 @@ EVAL(expr, val, code, true_label, false_label) if (left->ex_depth == 1 && left->OP_OPER == ARROW) { compl = 1; /* Value->sel */ ASSERT(left->OP_LEFT->ex_class == Value); - EVAL(left, RVAL, TRUE, NO_LABEL, NO_LABEL); + EVAL(left, RVAL, newcode, NO_LABEL, NO_LABEL); } else { compl = 2; /* otherwise */ - tmp = tmp_pointer_var(&old_offset); - EVAL(left, LVAL, TRUE, NO_LABEL, NO_LABEL); - C_dup(pointer_size); - C_lal(tmp); - C_sti(pointer_size); - C_loi(left->ex_type->tp_size); + EVAL(left, LVAL, newcode, NO_LABEL, NO_LABEL); + if (newcode) { + tmp = tmp_pointer_var(&old_offset); + C_dup(pointer_size); + C_lal(tmp); + C_sti(pointer_size); + C_loi(left->ex_type->tp_size); + } } - conversion(left->ex_type, tp); - if (gencode && (oper == POSTINCR || oper == POSTDECR)) - C_dup(tp->tp_size); - EVAL(right, RVAL, TRUE, NO_LABEL, NO_LABEL); - assop(tp, oper); - if (gencode && oper != POSTINCR && oper != POSTDECR) - C_dup(tp->tp_size); - conversion(tp, left->ex_type); - if (compl == 0) + if (newcode) { + conversion(left->ex_type, tp); + if (gencode && (oper == POSTINCR || + oper == POSTDECR)) + C_dup(tp->tp_size); + } + EVAL(right, RVAL, newcode, NO_LABEL, NO_LABEL); + if (newcode) { + assop(tp, oper); + if (gencode && oper != POSTINCR && + oper != POSTDECR) + C_dup(tp->tp_size); + conversion(tp, left->ex_type); + } + if (newcode && compl == 0) store_val(&(left->ex_object.ex_value), left->ex_type); else if (compl == 1) { - EVAL(left, LVAL, TRUE, NO_LABEL, NO_LABEL); - C_sti(left->ex_type->tp_size); + EVAL(left, LVAL, newcode, NO_LABEL, NO_LABEL); + if (newcode) C_sti(left->ex_type->tp_size); } - else { + else if (newcode) { C_lal(tmp); /* always init'd */ C_loi(pointer_size); C_sti(left->ex_type->tp_size); @@ -426,12 +440,14 @@ EVAL(expr, val, code, true_label, false_label) while ( ex->ex_class == Oper && ex->OP_OPER == PARCOMMA ) { - EVAL(ex->OP_RIGHT, RVAL, TRUE, + EVAL(ex->OP_RIGHT, RVAL, + ex->ex_type->tp_size > 0, NO_LABEL, NO_LABEL); ParSize += ATW(ex->ex_type->tp_size); ex = ex->OP_LEFT; } - EVAL(ex, RVAL, TRUE, NO_LABEL, NO_LABEL); + EVAL(ex, RVAL, ex->ex_type->tp_size > 0, + NO_LABEL, NO_LABEL); ParSize += ATW(ex->ex_type->tp_size); } if (left->ex_class == Value && left->VL_CLASS == Name) { @@ -463,23 +479,23 @@ EVAL(expr, val, code, true_label, false_label) break; } case '.': - EVAL(left, LVAL, code, NO_LABEL, NO_LABEL); + EVAL(left, LVAL, gencode, NO_LABEL, NO_LABEL); ASSERT(is_cp_cst(right)); if (gencode) C_adp(right->VL_VALUE); break; case ARROW: - EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL); ASSERT(is_cp_cst(right)); if (gencode) C_adp(right->VL_VALUE); break; case ',': EVAL(left, RVAL, FALSE, NO_LABEL, NO_LABEL); - EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL); break; case '~': - EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL); if (gencode) C_com(tp->tp_size); break; @@ -491,10 +507,10 @@ EVAL(expr, val, code, true_label, false_label) EVAL(left, RVAL, TRUE, l_true, l_false); C_df_ilb(l_true); - EVAL(right->OP_LEFT, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(right->OP_LEFT, RVAL, gencode, NO_LABEL, NO_LABEL); C_bra(l_end); C_df_ilb(l_false); - EVAL(right->OP_RIGHT, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(right->OP_RIGHT, RVAL, gencode, NO_LABEL, NO_LABEL); C_df_ilb(l_end); break; } @@ -528,7 +544,7 @@ EVAL(expr, val, code, true_label, false_label) EVAL(left, RVAL, TRUE, l_maybe, false_label); C_df_ilb(l_maybe); - EVAL(right, RVAL, code, true_label, + EVAL(right, RVAL, gencode, true_label, false_label); } break; @@ -562,7 +578,7 @@ EVAL(expr, val, code, true_label, false_label) EVAL(left, RVAL, TRUE, true_label, l_maybe); C_df_ilb(l_maybe); - EVAL(right, RVAL, code, true_label, + EVAL(right, RVAL, gencode, true_label, false_label); } break; @@ -587,7 +603,7 @@ EVAL(expr, val, code, true_label, false_label) NO_LABEL); } else - EVAL(right, RVAL, code, false_label, + EVAL(right, RVAL, gencode, false_label, true_label); break; case INT2INT: @@ -596,7 +612,7 @@ EVAL(expr, val, code, true_label, false_label) case FLOAT2INT: case FLOAT2FLOAT: #endif NOFLOAT - EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); + EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL); if (gencode) conversion(right->ex_type, left->ex_type); break; diff --git a/lang/cem/cemcom/idf.c b/lang/cem/cemcom/idf.c index 200a05ab..23473af6 100644 --- a/lang/cem/cemcom/idf.c +++ b/lang/cem/cemcom/idf.c @@ -187,17 +187,23 @@ declare_idf(ds, dc, lvl) else { /* combine the decspecs and the declarator into one type */ type = declare_type(ds->ds_type, dc); - if (type->tp_size == (arith)-1) { - /* the type is not yet known */ - if (actual_declaration(sc, type)) { - /* but it has to be: */ + if (type->tp_size <= (arith)0 && + actual_declaration(sc, type)) { + if (type->tp_size == (arith) -1) { + /* the type is not yet known, + but it has to be: + */ extern char *symbol2str(); error("unknown %s-type", symbol2str(type->tp_fund)); } + else { + /* CJ */ + warning("%s has size 0", idf->id_text); + } } } - + /* some additional work for formal definitions */ if (lvl == L_FORMAL2) { switch (type->tp_fund) { @@ -276,9 +282,8 @@ declare_idf(ds, dc, lvl) def->df_type = type; def->df_formal_array = formal_array; def->df_sc = sc; - if (def->df_sc != FORMAL) - crash("non-formal formal"); - def->df_register = (sc == REGISTER) ? REG_BONUS : REG_DEFAULT; + def->df_level = L_FORMAL2; /* CJ */ + if (sc == REGISTER) def->df_register = REG_BONUS; } else if ( lvl >= L_LOCAL && @@ -303,6 +308,8 @@ declare_idf(ds, dc, lvl) newdef->df_level = lvl; newdef->df_type = type; newdef->df_sc = sc; + if (lvl == L_FORMAL1) /* CJ */ + newdef->df_register = REG_DEFAULT; /* link it into the name list in the proper place */ idf->id_def = newdef; update_ahead(idf); @@ -323,17 +330,17 @@ declare_idf(ds, dc, lvl) idf->id_text); /** type = idf->id_def->df_type = int_type; **/ } - idf->id_def->df_register = + newdef->df_register = (sc == REGISTER) ? REG_BONUS : REG_DEFAULT; - idf->id_def->df_address = + newdef->df_address = stl->sl_max_block = stl->sl_local_offset = -align(-stl->sl_local_offset + type->tp_size, type->tp_align); break; case STATIC: - idf->id_def->df_address = (arith) data_label(); + newdef->df_address = (arith) data_label(); break; } } @@ -504,7 +511,7 @@ global_redecl(idf, new_sc, tp) int good_formal(def, idf) register struct def *def; - struct idf *idf; + register struct idf *idf; { /* Succeeds if def is a proper L_FORMAL1 definition and gives an error message otherwise. @@ -514,6 +521,7 @@ good_formal(def, idf) error("%s not in parameter list", idf->id_text); return 0; } + ASSERT(def->df_sc == FORMAL); /* CJ */ return 1; } @@ -533,7 +541,7 @@ declare_params(dc) } init_idf(idf) - struct idf *idf; + register struct idf *idf; { /* The topmost definition of idf is set to initialized. */ @@ -593,6 +601,7 @@ declare_formals(fp) f_offset = align(f_offset + def->df_type->tp_size, word_align); formal_cvt(def); /* cvt int to char or short, if necessary */ se = se->next; + def->df_level = L_FORMAL2; /* CJ */ } *fp = f_offset; } @@ -637,7 +646,8 @@ free_formals(fm) register struct formal *fm; { while (fm) { - register struct formal *tmp = fm->next; + struct formal *tmp = fm->next; + free_formal(fm); fm = tmp; } diff --git a/lang/cem/cemcom/init.c b/lang/cem/cemcom/init.c index dcdf1bfc..2c0b6a6c 100644 --- a/lang/cem/cemcom/init.c +++ b/lang/cem/cemcom/init.c @@ -75,6 +75,9 @@ init_pp() /* __FILE__ */ macro_def(str2idf("__FILE__"), "", -1, 1, FUNC); + /* defined(??) */ + macro_def(str2idf("defined"), "", 1, 1, FUNC); + #ifdef PREDEFINE { /* PREDEFINE is a compile-time defined string diff --git a/lang/cem/cemcom/main.c b/lang/cem/cemcom/main.c index e6235214..b9fa6917 100644 --- a/lang/cem/cemcom/main.c +++ b/lang/cem/cemcom/main.c @@ -170,7 +170,7 @@ compile(argc, argv) tmpfile = mktemp(tmpf); #endif USE_TMP - if (strcmp(destination, "-") == 0) + if (destination && strcmp(destination, "-") == 0) destination = 0; if (!InsertFile(source, (char **) 0)) /* read the source file */ fatal("%s: no source file %s\n", prog_name, @@ -246,7 +246,7 @@ init() float_type = standard_type(FLOAT, 0, float_align, float_size); double_type = standard_type(DOUBLE, 0, double_align, double_size); #endif NOFLOAT - void_type = standard_type(VOID, 0, 0, (arith)0); + void_type = standard_type(VOID, 0, 1, (arith)0); label_type = standard_type(LABEL, 0, 0, (arith)0); error_type = standard_type(ERRONEOUS, 0, 1, (arith)1); diff --git a/lang/cem/cemcom/replace.c b/lang/cem/cemcom/replace.c index b64e4fed..21c98c06 100644 --- a/lang/cem/cemcom/replace.c +++ b/lang/cem/cemcom/replace.c @@ -41,6 +41,15 @@ replace(idef) int size; if (idef->id_macro->mc_nps != -1) { /* with parameter list */ + if (flags & FUNC) { + /* must be "defined". + Unfortunately, the next assertion + will not compile ... + ASSERT( ! strcmp("defined", idef->id_text)); + */ + if (! AccDefined) + return 0; + } LoadChar(c); c = skipspaces(c); if (c != '(') { /* no replacement if no () */ @@ -50,10 +59,20 @@ replace(idef) return 0; } actpars = getactuals(idef); /* get act.param. list */ + if (flags & FUNC) { + struct idf *param = str2idf(*actpars); + + if (param->id_macro) + reptext = "\0001"; + else + reptext = "\0000"; + InsertText(reptext, 2); + return 1; + } } if ((flags & PREDEF) && (UnknownIdIsZero == 0)) /* don't replace */ return 0; - if (flags & FUNC) /* this macro leads to special action */ + if (flags & FUNC) /* this macro leads to special action */ macro_func(idef); reptext = macro2buffer(idef, actpars, &size); /* create input buffer */ InsertText(reptext, size); diff --git a/lang/cem/cemcom/stack.c b/lang/cem/cemcom/stack.c index 24b95ea1..7b0119d7 100644 --- a/lang/cem/cemcom/stack.c +++ b/lang/cem/cemcom/stack.c @@ -118,6 +118,7 @@ unstack_level() if (level == L_LOCAL || level == L_FORMAL1) { if ( def->df_register != REG_NONE && def->df_sc != STATIC && + def->df_type->tp_size > 0 && options['n'] == 0 ) { int reg; diff --git a/lang/cem/cemcom/type.c b/lang/cem/cemcom/type.c index 73f805d9..ec2c96bb 100644 --- a/lang/cem/cemcom/type.c +++ b/lang/cem/cemcom/type.c @@ -88,6 +88,8 @@ construct_type(fund, tp, count) error("cannot construct array of unknown type"); count = (arith)-1; } + else if (tp->tp_size == 0) /* CJ */ + warning("array elements have size 0"); if (count >= (arith)0) count *= tp->tp_size; dtp = array_of(tp, count); From 1864229bae508c5fe7929d0e34e6f45260a19e04 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 1 Dec 1986 10:06:53 +0000 Subject: [PATCH 0354/1625] some minor bug fixes --- lang/m2/comp/LLlex.c | 16 +++++++++-- lang/m2/comp/LLmessage.c | 57 ++++++++++++++++++---------------------- lang/m2/comp/Makefile | 4 +-- lang/m2/comp/chk_expr.c | 21 ++++++++------- lang/m2/comp/code.c | 29 ++++++++++++-------- lang/m2/comp/declar.g | 15 ++++++++--- lang/m2/comp/def.H | 2 +- lang/m2/comp/enter.c | 30 ++++++++++----------- lang/m2/comp/main.c | 6 ++--- lang/m2/comp/program.g | 26 +++++++++--------- lang/m2/comp/scope.C | 12 ++++++--- lang/m2/comp/scope.h | 6 ++--- lang/m2/comp/tokenname.c | 2 +- lang/m2/comp/type.c | 11 +++++--- lang/m2/comp/walk.c | 34 +++++++++++++++++++----- 15 files changed, 165 insertions(+), 106 deletions(-) diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index 902ed71b..0a4f021a 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -411,8 +411,20 @@ again1: /* Fall through */ case End: - *np++ = '\0'; - tk->TOK_INT = str2long(&buf[1], base); + *np = '\0'; + if (np >= &buf[NUMSIZE]) { + tk->TOK_INT = 1; + lexerror("constant too long"); + } + else { + np = &buf[1]; + while (*np == '0') np++; + tk->TOK_INT = str2long(np, base); + if (strlen(np) > 14 /* ??? */ || + tk->TOK_INT < 0) { +lexwarning(W_ORDINARY, "overflow in constant"); + } + } if (ch == 'C' && base == 8) { toktype = char_type; if (tk->TOK_INT<0 || tk->TOK_INT>255) { diff --git a/lang/m2/comp/LLmessage.c b/lang/m2/comp/LLmessage.c index 7de4385a..a6386621 100644 --- a/lang/m2/comp/LLmessage.c +++ b/lang/m2/comp/LLmessage.c @@ -16,16 +16,39 @@ extern char *symbol2str(); extern struct idf *gen_anon_idf(); -extern int err_occurred; LLmessage(tk) - int tk; + register int tk; { if (tk > 0) { /* if (tk > 0), it represents the token to be inserted. */ + register struct token *dotp = ˙ + error("%s missing", symbol2str(tk)); - insert_token(tk); + + aside = *dotp; + + dotp->tk_symb = tk; + + switch (tk) { + /* The operands need some body */ + case IDENT: + dotp->TOK_IDF = gen_anon_idf(); + break; + case STRING: + dotp->tk_data.tk_str = (struct string *) + Malloc(sizeof (struct string)); + dotp->TOK_SLE = 1; + dotp->TOK_STR = Salloc("", 1); + break; + case INTEGER: + dotp->TOK_INT = 1; + break; + case REAL: + dotp->TOK_REL = Salloc("0.0", 4); + break; + } } else if (tk < 0) { error("garbage at end of program"); @@ -33,31 +56,3 @@ LLmessage(tk) else error("%s deleted", symbol2str(dot.tk_symb)); } -insert_token(tk) - int tk; -{ - register struct token *dotp = ˙ - - aside = *dotp; - - dotp->tk_symb = tk; - - switch (tk) { - /* The operands need some body */ - case IDENT: - dotp->TOK_IDF = gen_anon_idf(); - break; - case STRING: - dotp->tk_data.tk_str = (struct string *) - Malloc(sizeof (struct string)); - dotp->TOK_SLE = 1; - dotp->TOK_STR = Salloc("", 1); - break; - case INTEGER: - dotp->TOK_INT = 1; - break; - case REAL: - dotp->TOK_REL = Salloc("0.0", 4); - break; - } -} diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index d434e74e..d62ebacf 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -141,8 +141,8 @@ type.o: LLlex.h const.h debug.h debugcst.h def.h idf.h maxset.h node.h scope.h t def.o: LLlex.h Lpars.h debug.h debugcst.h def.h idf.h main.h node.h scope.h type.h scope.o: LLlex.h debug.h debugcst.h def.h idf.h node.h scope.h type.h misc.o: LLlex.h f_info.h idf.h misc.h node.h -enter.o: LLlex.h debug.h debugcst.h def.h idf.h main.h node.h scope.h type.h -defmodule.o: LLlex.h Lpars.h debug.h debugcst.h def.h f_info.h idf.h input.h inputtype.h main.h node.h scope.h type.h +enter.o: LLlex.h debug.h debugcst.h def.h idf.h main.h misc.h node.h scope.h type.h +defmodule.o: LLlex.h Lpars.h debug.h debugcst.h def.h f_info.h idf.h input.h inputtype.h main.h misc.h node.h scope.h type.h typequiv.o: LLlex.h debug.h debugcst.h def.h node.h type.h warning.h node.o: LLlex.h debug.h debugcst.h def.h node.h type.h cstoper.o: LLlex.h Lpars.h debug.h debugcst.h idf.h node.h standards.h target_sizes.h type.h warning.h diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index d97a51f2..401571d5 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -994,23 +994,24 @@ ChkStandard(expp, left) /* Now, make it look like a call to ALLOCATE or DEALLOCATE */ { struct token dt; + register struct token *tk = &dt; struct node *nd; - dt.TOK_INT = PointedtoType(left->nd_type)->tp_size; - dt.tk_symb = INTEGER; - dt.tk_lineno = left->nd_lineno; + tk->TOK_INT = PointedtoType(left->nd_type)->tp_size; + tk->tk_symb = INTEGER; + tk->tk_lineno = left->nd_lineno; nd = MkLeaf(Value, &dt); nd->nd_type = card_type; - dt.tk_symb = ','; - arg->nd_right = MkNode(Link, nd, NULLNODE, &dt); + tk->tk_symb = ','; + arg->nd_right = MkNode(Link, nd, NULLNODE, tk); /* Ignore other arguments to NEW and/or DISPOSE ??? */ FreeNode(expp->nd_left); - dt.tk_symb = IDENT; - dt.tk_lineno = expp->nd_left->nd_lineno; - dt.TOK_IDF = str2idf(std == S_NEW ? + tk->tk_symb = IDENT; + tk->tk_lineno = expp->nd_left->nd_lineno; + tk->TOK_IDF = str2idf(std == S_NEW ? "ALLOCATE" : "DEALLOCATE", 0); - expp->nd_left = MkLeaf(Name, &dt); + expp->nd_left = MkLeaf(Name, tk); } return ChkCall(expp); @@ -1145,7 +1146,7 @@ ChkCast(expp, left) } TryToString(nd, tp) - struct node *nd; + register struct node *nd; struct type *tp; { /* Try a coercion from character constant to string. diff --git a/lang/m2/comp/code.c b/lang/m2/comp/code.c index bbef689f..d415d7a9 100644 --- a/lang/m2/comp/code.c +++ b/lang/m2/comp/code.c @@ -401,16 +401,7 @@ CodeParameters(param, arg) return; } if (left_type->tp_fund == T_STRING) { - register arith szarg = WA(left_type->tp_size); - arith sz = WA(tp->tp_size); - - if (szarg != sz) { - /* null padding required */ - assert(szarg < sz); - C_zer(sz - szarg); - } - CodeString(left); /* push address of string */ - C_loi(szarg); + CodePString(left, tp); return; } CodePExpr(left); @@ -418,6 +409,22 @@ CodeParameters(param, arg) CodeCoercion(left_type, tp); } +CodePString(nd, tp) + struct node *nd; + struct type *tp; +{ + arith szarg = WA(nd->nd_type->tp_size); + register arith zersz = WA(tp->tp_size) - szarg; + + if (zersz) { + /* null padding required */ + assert(zersz > 0); + C_zer(zersz); + } + CodeString(nd); /* push address of string */ + C_loi(szarg); +} + CodeStd(nd) struct node *nd; { @@ -731,8 +738,8 @@ CodeOper(expr, true_label, false_label) C_cmi(tp->tp_size); break; case T_POINTER: - case T_EQUAL: case T_HIDDEN: + case T_EQUAL: case T_CARDINAL: case T_INTORCARD: C_cmu(tp->tp_size); diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index c08bfe12..7e93eb90 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -116,10 +116,15 @@ TypeDeclaration { struct def *df; struct type *tp; + struct node *nd; }: - IDENT { df = define(dot.TOK_IDF, CurrentScope, D_TYPE); } + IDENT { df = define(dot.TOK_IDF, CurrentScope, D_TYPE); + nd = MkLeaf(Name, &dot); + } '=' type(&tp) - { DeclareType(df, tp); } + { DeclareType(nd, df, tp); + free_node(nd); + } ; type(struct type **ptp;): @@ -239,7 +244,11 @@ RecordType(struct type **ptp;) close_scope(0); } FieldListSequence(scope, &size, &xalign) - { *ptp = standard_type(T_RECORD, xalign, size); + { if (size == 0) { + warning(W_ORDINARY, "empty record declaration"); + size = 1; + } + *ptp = standard_type(T_RECORD, xalign, size); (*ptp)->rec_scope = scope; } END diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H index a1725310..d27f32c7 100644 --- a/lang/m2/comp/def.H +++ b/lang/m2/comp/def.H @@ -1,7 +1,7 @@ /* I D E N T I F I E R D E S C R I P T O R S T R U C T U R E */ struct module { - arith mo_priority; /* priority of a module */ + struct node *mo_priority;/* priority of a module */ struct scopelist *mo_vis;/* scope of this module */ struct node *mo_body; /* body of this module */ #define mod_priority df_value.df_module.mo_priority diff --git a/lang/m2/comp/enter.c b/lang/m2/comp/enter.c index 0680a0b5..52debbc7 100644 --- a/lang/m2/comp/enter.c +++ b/lang/m2/comp/enter.c @@ -15,6 +15,7 @@ #include "LLlex.h" #include "node.h" #include "main.h" +#include "misc.h" struct def * Enter(name, kind, type, pnam) @@ -351,14 +352,8 @@ EnterExportList(Idlist, qualified) } if (df1->df_kind == D_HIDDEN && df->df_kind == D_TYPE) { - if (df->df_type->tp_fund != T_POINTER) { - node_error(idlist, -"opaque type \"%s\" is not a pointer type", - df->df_idf->id_text); - } - assert(df1->df_type->next == NULLTYPE); + DeclareType(idlist, df1, df->df_type); df1->df_kind = D_TYPE; - df1->df_type->next = df->df_type; continue; } } @@ -379,6 +374,7 @@ EnterFromImportList(Idlist, FromDef, FromId) register struct node *idlist = Idlist; register struct scopelist *vis; register struct def *df; + char *module_name = FromDef->df_idf->id_text; int forwflag = 0; switch(FromDef->df_kind) { @@ -399,27 +395,31 @@ EnterFromImportList(Idlist, FromDef, FromId) case D_MODULE: vis = FromDef->mod_vis; if (vis == CurrVis) { -node_error(FromId, "cannot import from current module \"%s\"", - FromDef->df_idf->id_text); +node_error(FromId, "cannot import from current module \"%s\"", module_name); return; } break; default: -node_error(FromId, "identifier \"%s\" does not represent a module", - FromDef->df_idf->id_text); +node_error(FromId,"identifier \"%s\" does not represent a module",module_name); return; } for (; idlist; idlist = idlist->next) { if (forwflag) df = ForwDef(idlist, vis->sc_scope); else if (! (df = lookup(idlist->nd_IDF, vis->sc_scope, 1))) { - not_declared("identifier", idlist, " in qualifying module"); - df = define(idlist->nd_IDF,vis->sc_scope,D_ERROR); + if (! is_anon_idf(idlist->nd_IDF)) { + node_error(idlist, + "identifier \"%s\" not declared in module \"%s\"", + idlist->nd_IDF->id_text, + module_name); + } + df = define(idlist->nd_IDF,vis->sc_scope,D_ERROR); } else if (! (df->df_flags & (D_EXPORTED|D_QEXPORTED))) { node_error(idlist, - "identifier \"%s\" not exported from qualifying module", - idlist->nd_IDF->id_text); + "identifier \"%s\" not exported from module \"%s\"", + idlist->nd_IDF->id_text, + module_name); df->df_flags |= D_QEXPORTED; } DoImport(df, CurrentScope); diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index 10c44f0e..babf4681 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -81,15 +81,15 @@ Compile(src, dst) return 1; } #endif DEBUG - open_scope(CLOSEDSCOPE); - GlobalScope = CurrentScope; + open_scope(OPENSCOPE); + GlobalVis = CurrVis; + close_scope(0); C_init(word_size, pointer_size); if (! C_open(dst)) fatal("could not open output file"); C_magic(); C_ms_emx(word_size, pointer_size); CompUnit(); C_ms_src((arith) (LineNumber - 1), FileName); - close_scope(SC_REVERSE); if (!err_occurred) { C_exp(Defined->mod_vis->sc_scope->sc_name); WalkModule(Defined); diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index f7eed0d1..e80578c8 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -44,7 +44,7 @@ ModuleDeclaration int qualified; } : MODULE IDENT { df = DefineLocalModule(dot.TOK_IDF); } - priority(&(df->mod_priority))? + priority(df) ';' import(1)* export(&qualified, &exportlist)? @@ -57,19 +57,21 @@ ModuleDeclaration } ; -priority(arith *pprio;) +priority(register struct def *df;) { register struct node *nd; - struct node *nd1; /* &nd is illegal */ } : - '[' ConstExpression(&nd1) ']' - { nd = nd1; - if (!(nd->nd_type->tp_fund & T_CARDINAL)) { - node_error(nd, "illegal priority"); + [ + '[' ConstExpression(&(df->mod_priority)) ']' + { if (!(df->mod_priority->nd_type->tp_fund & + T_CARDINAL)) { + node_error(df->mod_priority, + "illegal priority"); } - *pprio = nd->nd_INT; - FreeNode(nd); } + | + { df->mod_priority = 0; } + ] ; export(int *QUALflag; struct node **ExportList;): @@ -121,7 +123,7 @@ DefinitionModule if (!Defined) Defined = df; CurrentScope->sc_name = df->df_idf->id_text; df->mod_vis = CurrVis; - df->df_type = standard_type(T_RECORD, 1, (arith) 0); + df->df_type = standard_type(T_RECORD, 1, (arith) 1); df->df_type->rec_scope = df->mod_vis->sc_scope; DefinitionModule++; } @@ -194,14 +196,14 @@ ProgramModule RemoveImports(&(CurrentScope->sc_def)); } else { - Defined = df = define(dot.TOK_IDF, CurrentScope, D_MODULE); + Defined = df = define(dot.TOK_IDF, GlobalScope, D_MODULE); open_scope(CLOSEDSCOPE); df->mod_vis = CurrVis; CurrentScope->sc_name = "_M2M"; } CurrentScope->sc_definedby = df; } - priority(&(df->mod_priority))? + priority(df) ';' import(0)* block(&(df->mod_body)) IDENT { close_scope(SC_CHKFORW|SC_CHKPROC|SC_REVERSE); diff --git a/lang/m2/comp/scope.C b/lang/m2/comp/scope.C index e94f895c..790e0ad2 100644 --- a/lang/m2/comp/scope.C +++ b/lang/m2/comp/scope.C @@ -14,8 +14,8 @@ #include "def.h" #include "node.h" -struct scope *PervasiveScope, *GlobalScope; -struct scopelist *CurrVis; +struct scope *PervasiveScope; +struct scopelist *CurrVis, *GlobalVis; extern int proclevel; static struct scopelist *PervVis; extern char options[]; @@ -85,9 +85,14 @@ chk_proc(df) { /* Called at scope closing. Check all definitions, and if one is a D_PROCHEAD, the procedure was not defined. + Also check that hidden types are defined. */ while (df) { - if (df->df_kind == D_PROCHEAD) { + if (df->df_kind == D_HIDDEN) { + error("hidden type \"%s\" not declared", + df->df_idf->id_text); + } + else if (df->df_kind == D_PROCHEAD) { /* A not defined procedure */ error("procedure \"%s\" not defined", @@ -121,6 +126,7 @@ node_error(df1->df_forw_node, "\"%s\" is not a type", df1->df_idf->id_text); df1->df_forw_type->next = df->df_type; FreeNode(df1->df_forw_node); free_def(df1); + continue; } else if (df->df_kind == D_FTYPE) { df->df_kind = D_TYPE; diff --git a/lang/m2/comp/scope.h b/lang/m2/comp/scope.h index 8e105b72..2fd385b3 100644 --- a/lang/m2/comp/scope.h +++ b/lang/m2/comp/scope.h @@ -30,13 +30,13 @@ struct scopelist { }; extern struct scope - *PervasiveScope, - *GlobalScope; + *PervasiveScope; extern struct scopelist - *CurrVis; + *CurrVis, *GlobalVis; #define CurrentScope (CurrVis->sc_scope) +#define GlobalScope (GlobalVis->sc_scope) #define enclosing(x) ((x)->sc_encl) #define scopeclosed(x) ((x)->sc_scopeclosed) #define nextvisible(x) ((x)->next) /* use with scopelists */ diff --git a/lang/m2/comp/tokenname.c b/lang/m2/comp/tokenname.c index 1de739fd..223c2a66 100644 --- a/lang/m2/comp/tokenname.c +++ b/lang/m2/comp/tokenname.c @@ -14,7 +14,7 @@ struct tokenname tkspec[] = { /* the names of the special tokens */ {IDENT, "identifier"}, {STRING, "string"}, - {INTEGER, "integer"}, + {INTEGER, "number"}, {REAL, "real"}, {0, ""} }; diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index 134cbec6..d30e19e5 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -473,9 +473,10 @@ FreeType(tp) free_type(tp); } -DeclareType(df, tp) +DeclareType(nd, df, tp) register struct def *df; register struct type *tp; + struct node *nd; { /* A type with type-description "tp" is declared and must be bound to definition "df". @@ -486,7 +487,9 @@ DeclareType(df, tp) if (df->df_type && df->df_type->tp_fund == T_HIDDEN) { if (! (tp->tp_fund & (T_POINTER|T_HIDDEN|T_EQUAL))) { -error("opaque type \"%s\" is not a pointer type", df->df_idf->id_text); + node_error(nd, + "opaque type \"%s\" is not a pointer type", + df->df_idf->id_text); } df->df_type->next = tp; df->df_type->tp_fund = T_EQUAL; @@ -495,7 +498,9 @@ error("opaque type \"%s\" is not a pointer type", df->df_idf->id_text); } if (tp == df->df_type) { /* Circular definition! */ -error("opaque type \"%s\" has a circular definition", df->df_idf->id_text); + node_error(nd, + "opaque type \"%s\" has a circular definition", + df->df_idf->id_text); } } else df->df_type = tp; diff --git a/lang/m2/comp/walk.c b/lang/m2/comp/walk.c index 4a6da47e..4fce4011 100644 --- a/lang/m2/comp/walk.c +++ b/lang/m2/comp/walk.c @@ -34,10 +34,29 @@ label data_label; static struct type *func_type; struct withdesig *WithDesigs; struct node *Modules; +static struct node *priority; #define NO_EXIT_LABEL ((label) 0) #define RETURN_LABEL ((label) 1) +STATIC +DoPriority() +{ + if (priority) { + C_loc(priority->nd_INT); + C_cal("_stackprio"); + C_asp(word_size); + } +} + +STATIC +EndPriority() +{ + if (priority) { + C_cal("_unstackprio"); + } +} + STATIC DoProfil() { @@ -67,6 +86,7 @@ WalkModule(module) struct scopelist *savevis = CurrVis; CurrVis = module->mod_vis; + priority = module->mod_priority; sc = CurrentScope; /* Walk through it's local definitions @@ -81,6 +101,7 @@ WalkModule(module) text_label = 1; /* label at end of initialization routine */ TmpOpen(sc); /* Initialize for temporaries */ C_pro_narg(sc->sc_name); + DoPriority(); DoProfil(); if (module == Defined) { /* Body of implementation or program module. @@ -113,6 +134,7 @@ WalkModule(module) DO_DEBUG(options['X'], PrNode(module->mod_body, 0)); WalkNode(module->mod_body, NO_EXIT_LABEL); C_df_ilb(RETURN_LABEL); + EndPriority(); C_ret((arith) 0); C_end(-sc->sc_off); proclevel--; @@ -146,6 +168,7 @@ WalkProcedure(procedure) /* Generate code for this procedure */ C_pro_narg(sc->sc_name); + DoPriority(); DoProfil(); TmpOpen(sc); @@ -277,6 +300,7 @@ WalkProcedure(procedure) C_ass(word_size); } C_lae_dlb(func_res_label, (arith) 0); + EndPriority(); C_ret(pointer_size); } else if (tp) { @@ -292,6 +316,7 @@ WalkProcedure(procedure) C_lal(retsav); C_loi(func_res_size); } + EndPriority(); C_ret(func_res_size); } else { @@ -299,6 +324,7 @@ WalkProcedure(procedure) C_lol(StackAdjustment); C_ass(word_size); } + EndPriority(); C_ret((arith) 0); } if (StackAdjustment) FreeInt(StackAdjustment); @@ -324,7 +350,7 @@ WalkDef(df) WalkProcedure(df); break; case D_VARIABLE: - if (!proclevel) { + if (!proclevel && !df->var_addrgiven) { C_df_dnam(df->var_name); C_bss_cst( WA(df->df_type->tp_size), @@ -554,11 +580,7 @@ node_error(right, "type incompatibility in RETURN statement"); break; } if (right->nd_type->tp_fund == T_STRING) { - arith strsize = WA(right->nd_type->tp_size); - - C_zer(WA(func_type->tp_size) - strsize); - CodePExpr(right); - C_loi(strsize); + CodePString(right, func_type); } else CodePExpr(right); } From a93111d3d158ad67845db18f53bc4c4c102aa3eb Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 1 Dec 1986 15:35:28 +0000 Subject: [PATCH 0355/1625] Version that uses libobject.a. --- mach/6500/as/Makefile | 8 +++++--- mach/6800/as/Makefile | 8 +++++--- mach/6805/as/Makefile | 8 +++++--- mach/6809/as/Makefile | 8 +++++--- mach/arm/as/Makefile | 8 +++++--- mach/i386/as/Makefile | 8 +++++--- mach/i80/as/Makefile | 8 +++++--- mach/i86/as/Makefile | 8 +++++--- mach/m68020/as/Makefile | 8 +++++--- mach/m68k2/as/Makefile | 8 +++++--- mach/ns/as/Makefile | 8 +++++--- mach/pdp/as/Makefile | 8 +++++--- mach/proto/as/Makefile | 8 +++++--- mach/s2650/as/Makefile | 8 +++++--- mach/vax4/as/Makefile | 8 +++++--- mach/z80/as/Makefile | 8 +++++--- mach/z8000/as/Makefile | 8 +++++--- 17 files changed, 85 insertions(+), 51 deletions(-) diff --git a/mach/6500/as/Makefile b/mach/6500/as/Makefile index 695d2b20..becc0d3d 100644 --- a/mach/6500/as/Makefile +++ b/mach/6500/as/Makefile @@ -1,12 +1,14 @@ # $Header$ EM = ../../.. h = $(EM)/h +LIBOBJ = $(EM)/modules/lib/libobject.a CDIR = $(EM)/mach/proto/nas CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) +INCL = -I. -I$h $(DEF) +CFLAGS = $(FFLAG) -O $(INCL) YFLAGS = -d LDFLAGS = $(FFLAG) -i @@ -34,14 +36,14 @@ pr: $(MACH) opr: make pr | opr as: $(COBJ) as.o - $(CC) $(LDFLAGS) $(COBJ) as.o -o as + $(CC) $(LDFLAGS) $(COBJ) as.o $(LIBOBJ) -o as as.y: $(CDIR)/comm2.y $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c - lint $(CSRC) as.c + lint $(INCL) $(CSRC) as.c y.tab.h: as.c $(COBJ): y.tab.h diff --git a/mach/6800/as/Makefile b/mach/6800/as/Makefile index 695d2b20..becc0d3d 100644 --- a/mach/6800/as/Makefile +++ b/mach/6800/as/Makefile @@ -1,12 +1,14 @@ # $Header$ EM = ../../.. h = $(EM)/h +LIBOBJ = $(EM)/modules/lib/libobject.a CDIR = $(EM)/mach/proto/nas CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) +INCL = -I. -I$h $(DEF) +CFLAGS = $(FFLAG) -O $(INCL) YFLAGS = -d LDFLAGS = $(FFLAG) -i @@ -34,14 +36,14 @@ pr: $(MACH) opr: make pr | opr as: $(COBJ) as.o - $(CC) $(LDFLAGS) $(COBJ) as.o -o as + $(CC) $(LDFLAGS) $(COBJ) as.o $(LIBOBJ) -o as as.y: $(CDIR)/comm2.y $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c - lint $(CSRC) as.c + lint $(INCL) $(CSRC) as.c y.tab.h: as.c $(COBJ): y.tab.h diff --git a/mach/6805/as/Makefile b/mach/6805/as/Makefile index 695d2b20..becc0d3d 100644 --- a/mach/6805/as/Makefile +++ b/mach/6805/as/Makefile @@ -1,12 +1,14 @@ # $Header$ EM = ../../.. h = $(EM)/h +LIBOBJ = $(EM)/modules/lib/libobject.a CDIR = $(EM)/mach/proto/nas CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) +INCL = -I. -I$h $(DEF) +CFLAGS = $(FFLAG) -O $(INCL) YFLAGS = -d LDFLAGS = $(FFLAG) -i @@ -34,14 +36,14 @@ pr: $(MACH) opr: make pr | opr as: $(COBJ) as.o - $(CC) $(LDFLAGS) $(COBJ) as.o -o as + $(CC) $(LDFLAGS) $(COBJ) as.o $(LIBOBJ) -o as as.y: $(CDIR)/comm2.y $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c - lint $(CSRC) as.c + lint $(INCL) $(CSRC) as.c y.tab.h: as.c $(COBJ): y.tab.h diff --git a/mach/6809/as/Makefile b/mach/6809/as/Makefile index 695d2b20..becc0d3d 100644 --- a/mach/6809/as/Makefile +++ b/mach/6809/as/Makefile @@ -1,12 +1,14 @@ # $Header$ EM = ../../.. h = $(EM)/h +LIBOBJ = $(EM)/modules/lib/libobject.a CDIR = $(EM)/mach/proto/nas CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) +INCL = -I. -I$h $(DEF) +CFLAGS = $(FFLAG) -O $(INCL) YFLAGS = -d LDFLAGS = $(FFLAG) -i @@ -34,14 +36,14 @@ pr: $(MACH) opr: make pr | opr as: $(COBJ) as.o - $(CC) $(LDFLAGS) $(COBJ) as.o -o as + $(CC) $(LDFLAGS) $(COBJ) as.o $(LIBOBJ) -o as as.y: $(CDIR)/comm2.y $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c - lint $(CSRC) as.c + lint $(INCL) $(CSRC) as.c y.tab.h: as.c $(COBJ): y.tab.h diff --git a/mach/arm/as/Makefile b/mach/arm/as/Makefile index 695d2b20..becc0d3d 100644 --- a/mach/arm/as/Makefile +++ b/mach/arm/as/Makefile @@ -1,12 +1,14 @@ # $Header$ EM = ../../.. h = $(EM)/h +LIBOBJ = $(EM)/modules/lib/libobject.a CDIR = $(EM)/mach/proto/nas CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) +INCL = -I. -I$h $(DEF) +CFLAGS = $(FFLAG) -O $(INCL) YFLAGS = -d LDFLAGS = $(FFLAG) -i @@ -34,14 +36,14 @@ pr: $(MACH) opr: make pr | opr as: $(COBJ) as.o - $(CC) $(LDFLAGS) $(COBJ) as.o -o as + $(CC) $(LDFLAGS) $(COBJ) as.o $(LIBOBJ) -o as as.y: $(CDIR)/comm2.y $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c - lint $(CSRC) as.c + lint $(INCL) $(CSRC) as.c y.tab.h: as.c $(COBJ): y.tab.h diff --git a/mach/i386/as/Makefile b/mach/i386/as/Makefile index 695d2b20..becc0d3d 100644 --- a/mach/i386/as/Makefile +++ b/mach/i386/as/Makefile @@ -1,12 +1,14 @@ # $Header$ EM = ../../.. h = $(EM)/h +LIBOBJ = $(EM)/modules/lib/libobject.a CDIR = $(EM)/mach/proto/nas CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) +INCL = -I. -I$h $(DEF) +CFLAGS = $(FFLAG) -O $(INCL) YFLAGS = -d LDFLAGS = $(FFLAG) -i @@ -34,14 +36,14 @@ pr: $(MACH) opr: make pr | opr as: $(COBJ) as.o - $(CC) $(LDFLAGS) $(COBJ) as.o -o as + $(CC) $(LDFLAGS) $(COBJ) as.o $(LIBOBJ) -o as as.y: $(CDIR)/comm2.y $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c - lint $(CSRC) as.c + lint $(INCL) $(CSRC) as.c y.tab.h: as.c $(COBJ): y.tab.h diff --git a/mach/i80/as/Makefile b/mach/i80/as/Makefile index 695d2b20..becc0d3d 100644 --- a/mach/i80/as/Makefile +++ b/mach/i80/as/Makefile @@ -1,12 +1,14 @@ # $Header$ EM = ../../.. h = $(EM)/h +LIBOBJ = $(EM)/modules/lib/libobject.a CDIR = $(EM)/mach/proto/nas CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) +INCL = -I. -I$h $(DEF) +CFLAGS = $(FFLAG) -O $(INCL) YFLAGS = -d LDFLAGS = $(FFLAG) -i @@ -34,14 +36,14 @@ pr: $(MACH) opr: make pr | opr as: $(COBJ) as.o - $(CC) $(LDFLAGS) $(COBJ) as.o -o as + $(CC) $(LDFLAGS) $(COBJ) as.o $(LIBOBJ) -o as as.y: $(CDIR)/comm2.y $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c - lint $(CSRC) as.c + lint $(INCL) $(CSRC) as.c y.tab.h: as.c $(COBJ): y.tab.h diff --git a/mach/i86/as/Makefile b/mach/i86/as/Makefile index 695d2b20..becc0d3d 100644 --- a/mach/i86/as/Makefile +++ b/mach/i86/as/Makefile @@ -1,12 +1,14 @@ # $Header$ EM = ../../.. h = $(EM)/h +LIBOBJ = $(EM)/modules/lib/libobject.a CDIR = $(EM)/mach/proto/nas CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) +INCL = -I. -I$h $(DEF) +CFLAGS = $(FFLAG) -O $(INCL) YFLAGS = -d LDFLAGS = $(FFLAG) -i @@ -34,14 +36,14 @@ pr: $(MACH) opr: make pr | opr as: $(COBJ) as.o - $(CC) $(LDFLAGS) $(COBJ) as.o -o as + $(CC) $(LDFLAGS) $(COBJ) as.o $(LIBOBJ) -o as as.y: $(CDIR)/comm2.y $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c - lint $(CSRC) as.c + lint $(INCL) $(CSRC) as.c y.tab.h: as.c $(COBJ): y.tab.h diff --git a/mach/m68020/as/Makefile b/mach/m68020/as/Makefile index 695d2b20..becc0d3d 100644 --- a/mach/m68020/as/Makefile +++ b/mach/m68020/as/Makefile @@ -1,12 +1,14 @@ # $Header$ EM = ../../.. h = $(EM)/h +LIBOBJ = $(EM)/modules/lib/libobject.a CDIR = $(EM)/mach/proto/nas CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) +INCL = -I. -I$h $(DEF) +CFLAGS = $(FFLAG) -O $(INCL) YFLAGS = -d LDFLAGS = $(FFLAG) -i @@ -34,14 +36,14 @@ pr: $(MACH) opr: make pr | opr as: $(COBJ) as.o - $(CC) $(LDFLAGS) $(COBJ) as.o -o as + $(CC) $(LDFLAGS) $(COBJ) as.o $(LIBOBJ) -o as as.y: $(CDIR)/comm2.y $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c - lint $(CSRC) as.c + lint $(INCL) $(CSRC) as.c y.tab.h: as.c $(COBJ): y.tab.h diff --git a/mach/m68k2/as/Makefile b/mach/m68k2/as/Makefile index 695d2b20..becc0d3d 100644 --- a/mach/m68k2/as/Makefile +++ b/mach/m68k2/as/Makefile @@ -1,12 +1,14 @@ # $Header$ EM = ../../.. h = $(EM)/h +LIBOBJ = $(EM)/modules/lib/libobject.a CDIR = $(EM)/mach/proto/nas CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) +INCL = -I. -I$h $(DEF) +CFLAGS = $(FFLAG) -O $(INCL) YFLAGS = -d LDFLAGS = $(FFLAG) -i @@ -34,14 +36,14 @@ pr: $(MACH) opr: make pr | opr as: $(COBJ) as.o - $(CC) $(LDFLAGS) $(COBJ) as.o -o as + $(CC) $(LDFLAGS) $(COBJ) as.o $(LIBOBJ) -o as as.y: $(CDIR)/comm2.y $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c - lint $(CSRC) as.c + lint $(INCL) $(CSRC) as.c y.tab.h: as.c $(COBJ): y.tab.h diff --git a/mach/ns/as/Makefile b/mach/ns/as/Makefile index 695d2b20..becc0d3d 100644 --- a/mach/ns/as/Makefile +++ b/mach/ns/as/Makefile @@ -1,12 +1,14 @@ # $Header$ EM = ../../.. h = $(EM)/h +LIBOBJ = $(EM)/modules/lib/libobject.a CDIR = $(EM)/mach/proto/nas CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) +INCL = -I. -I$h $(DEF) +CFLAGS = $(FFLAG) -O $(INCL) YFLAGS = -d LDFLAGS = $(FFLAG) -i @@ -34,14 +36,14 @@ pr: $(MACH) opr: make pr | opr as: $(COBJ) as.o - $(CC) $(LDFLAGS) $(COBJ) as.o -o as + $(CC) $(LDFLAGS) $(COBJ) as.o $(LIBOBJ) -o as as.y: $(CDIR)/comm2.y $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c - lint $(CSRC) as.c + lint $(INCL) $(CSRC) as.c y.tab.h: as.c $(COBJ): y.tab.h diff --git a/mach/pdp/as/Makefile b/mach/pdp/as/Makefile index 695d2b20..becc0d3d 100644 --- a/mach/pdp/as/Makefile +++ b/mach/pdp/as/Makefile @@ -1,12 +1,14 @@ # $Header$ EM = ../../.. h = $(EM)/h +LIBOBJ = $(EM)/modules/lib/libobject.a CDIR = $(EM)/mach/proto/nas CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) +INCL = -I. -I$h $(DEF) +CFLAGS = $(FFLAG) -O $(INCL) YFLAGS = -d LDFLAGS = $(FFLAG) -i @@ -34,14 +36,14 @@ pr: $(MACH) opr: make pr | opr as: $(COBJ) as.o - $(CC) $(LDFLAGS) $(COBJ) as.o -o as + $(CC) $(LDFLAGS) $(COBJ) as.o $(LIBOBJ) -o as as.y: $(CDIR)/comm2.y $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c - lint $(CSRC) as.c + lint $(INCL) $(CSRC) as.c y.tab.h: as.c $(COBJ): y.tab.h diff --git a/mach/proto/as/Makefile b/mach/proto/as/Makefile index 695d2b20..becc0d3d 100644 --- a/mach/proto/as/Makefile +++ b/mach/proto/as/Makefile @@ -1,12 +1,14 @@ # $Header$ EM = ../../.. h = $(EM)/h +LIBOBJ = $(EM)/modules/lib/libobject.a CDIR = $(EM)/mach/proto/nas CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) +INCL = -I. -I$h $(DEF) +CFLAGS = $(FFLAG) -O $(INCL) YFLAGS = -d LDFLAGS = $(FFLAG) -i @@ -34,14 +36,14 @@ pr: $(MACH) opr: make pr | opr as: $(COBJ) as.o - $(CC) $(LDFLAGS) $(COBJ) as.o -o as + $(CC) $(LDFLAGS) $(COBJ) as.o $(LIBOBJ) -o as as.y: $(CDIR)/comm2.y $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c - lint $(CSRC) as.c + lint $(INCL) $(CSRC) as.c y.tab.h: as.c $(COBJ): y.tab.h diff --git a/mach/s2650/as/Makefile b/mach/s2650/as/Makefile index 695d2b20..becc0d3d 100644 --- a/mach/s2650/as/Makefile +++ b/mach/s2650/as/Makefile @@ -1,12 +1,14 @@ # $Header$ EM = ../../.. h = $(EM)/h +LIBOBJ = $(EM)/modules/lib/libobject.a CDIR = $(EM)/mach/proto/nas CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) +INCL = -I. -I$h $(DEF) +CFLAGS = $(FFLAG) -O $(INCL) YFLAGS = -d LDFLAGS = $(FFLAG) -i @@ -34,14 +36,14 @@ pr: $(MACH) opr: make pr | opr as: $(COBJ) as.o - $(CC) $(LDFLAGS) $(COBJ) as.o -o as + $(CC) $(LDFLAGS) $(COBJ) as.o $(LIBOBJ) -o as as.y: $(CDIR)/comm2.y $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c - lint $(CSRC) as.c + lint $(INCL) $(CSRC) as.c y.tab.h: as.c $(COBJ): y.tab.h diff --git a/mach/vax4/as/Makefile b/mach/vax4/as/Makefile index 695d2b20..becc0d3d 100644 --- a/mach/vax4/as/Makefile +++ b/mach/vax4/as/Makefile @@ -1,12 +1,14 @@ # $Header$ EM = ../../.. h = $(EM)/h +LIBOBJ = $(EM)/modules/lib/libobject.a CDIR = $(EM)/mach/proto/nas CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) +INCL = -I. -I$h $(DEF) +CFLAGS = $(FFLAG) -O $(INCL) YFLAGS = -d LDFLAGS = $(FFLAG) -i @@ -34,14 +36,14 @@ pr: $(MACH) opr: make pr | opr as: $(COBJ) as.o - $(CC) $(LDFLAGS) $(COBJ) as.o -o as + $(CC) $(LDFLAGS) $(COBJ) as.o $(LIBOBJ) -o as as.y: $(CDIR)/comm2.y $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c - lint $(CSRC) as.c + lint $(INCL) $(CSRC) as.c y.tab.h: as.c $(COBJ): y.tab.h diff --git a/mach/z80/as/Makefile b/mach/z80/as/Makefile index 695d2b20..becc0d3d 100644 --- a/mach/z80/as/Makefile +++ b/mach/z80/as/Makefile @@ -1,12 +1,14 @@ # $Header$ EM = ../../.. h = $(EM)/h +LIBOBJ = $(EM)/modules/lib/libobject.a CDIR = $(EM)/mach/proto/nas CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) +INCL = -I. -I$h $(DEF) +CFLAGS = $(FFLAG) -O $(INCL) YFLAGS = -d LDFLAGS = $(FFLAG) -i @@ -34,14 +36,14 @@ pr: $(MACH) opr: make pr | opr as: $(COBJ) as.o - $(CC) $(LDFLAGS) $(COBJ) as.o -o as + $(CC) $(LDFLAGS) $(COBJ) as.o $(LIBOBJ) -o as as.y: $(CDIR)/comm2.y $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c - lint $(CSRC) as.c + lint $(INCL) $(CSRC) as.c y.tab.h: as.c $(COBJ): y.tab.h diff --git a/mach/z8000/as/Makefile b/mach/z8000/as/Makefile index 695d2b20..becc0d3d 100644 --- a/mach/z8000/as/Makefile +++ b/mach/z8000/as/Makefile @@ -1,12 +1,14 @@ # $Header$ EM = ../../.. h = $(EM)/h +LIBOBJ = $(EM)/modules/lib/libobject.a CDIR = $(EM)/mach/proto/nas CPP = $(EM)/lib/cpp DEF = FFLAG = -CFLAGS = $(FFLAG) -O -I. -I$h $(DEF) +INCL = -I. -I$h $(DEF) +CFLAGS = $(FFLAG) -O $(INCL) YFLAGS = -d LDFLAGS = $(FFLAG) -i @@ -34,14 +36,14 @@ pr: $(MACH) opr: make pr | opr as: $(COBJ) as.o - $(CC) $(LDFLAGS) $(COBJ) as.o -o as + $(CC) $(LDFLAGS) $(COBJ) as.o $(LIBOBJ) -o as as.y: $(CDIR)/comm2.y $(CPP) -P -I. -I$h $(DEF) $(CDIR)/comm2.y >as.y @echo "expect 1 shift/reduce conflict" lint: $(CSRC) as.c - lint $(CSRC) as.c + lint $(INCL) $(CSRC) as.c y.tab.h: as.c $(COBJ): y.tab.h From fc0149621ee17230d1cd2b8f06b9ed98471b01c6 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 1 Dec 1986 15:41:29 +0000 Subject: [PATCH 0356/1625] Version that uses libobject.a --- mach/proto/as/comm0.h | 44 +++++----- mach/proto/as/comm1.h | 11 +-- mach/proto/as/comm2.y | 40 +-------- mach/proto/as/comm3.c | 10 +-- mach/proto/as/comm4.c | 183 +++++++++++++++++++++++------------------- mach/proto/as/comm5.c | 14 +--- mach/proto/as/comm6.c | 94 ++++++++++------------ mach/proto/as/comm7.c | 47 ++--------- 8 files changed, 181 insertions(+), 262 deletions(-) diff --git a/mach/proto/as/comm0.h b/mach/proto/as/comm0.h index 7d05690f..2aed1a68 100644 --- a/mach/proto/as/comm0.h +++ b/mach/proto/as/comm0.h @@ -15,7 +15,6 @@ * DEBUG: for debugging purposes only * TMPDIR: directory for temporary files * ASLD: combined assembler/linker - * AOUTSEEK: seek on a.out instead of multiple opens */ /* ========== constants (use #undef, #define in mach0.c) ========== */ @@ -64,10 +63,6 @@ /* ========== default option setting ========== */ -#ifndef NOLD -#define ASLD /* default ON */ -#endif - #ifndef ASLD #ifndef RELOCATION separate linker only possible if relocation info produced @@ -91,7 +86,7 @@ _include #endif #ifdef ASLD -#include "aar.h" +#include "arch.h" #endif #include "out.h" @@ -155,6 +150,7 @@ _include /* miscellaneous */ #define KEYDEFINE 0 +#define KEYSECT 12 #define DOTGAIN DOTSCT->s_gain /* ========== type declarations ========== */ @@ -179,6 +175,17 @@ struct item_t { char *i_name; /* symbol name */ }; +struct common_t { + struct common_t * + c_next; + struct item_t *c_it; +#ifndef ASLD + valu_t c_size; +#endif +}; + +typedef struct common_t common_t; + typedef struct item_t item_t; struct sect_t { @@ -213,24 +220,17 @@ typedef struct sect_t sect_t; /* * extra type bits out of S_ETC, internal use only -#ifndef DUK - * S_COM: - * - symbols declared by .comm -#endif DUK * S_VAR: * - type not known at end of PASS_1 (S_VAR|S_UND) * - value not known at end of PASS_2 (S_VAR|S_ABS) * S_DOT: * - dot expression */ -#ifndef DUK -#define S_COM 0x0100 -#endif DUK #define S_VAR 0x0200 #define S_DOT 0x0400 /* should be tested by preprocessor * due to error in preprocessor it cannot - * test performed at runtime now + * test performed at compiletime by a switch now * #if (S_ETC|S_COM|S_VAR|S_DOT) != S_ETC * incorrect type bits * #endif @@ -243,10 +243,16 @@ typedef struct sect_t sect_t; #define PARTCHAR 3 #define PARTS 4 -#ifdef AOUTSEEK -#define AOUTPART(p) if(aoutpart!=p){aoutpart=p;fseek(aoutfile,aoutseek[p],0);} -#define AOUTPUTC(c,p) {putc(c,aoutfile);aoutseek[p]++;if(ferror(aoutfile))werror();} +#ifdef BYTES_REVERSED +#ifdef WORDS_REVERSED +#define MACHREL_BWR (RELBR|RELWR) #else -#define AOUTPART(p) /* empty */ -#define AOUTPUTC(c,p) {putc(c,aoutfile[p]);if(ferror(aoutfile[p]))werror();} +#define MACHREL_BWR (RELBR) +#endif +#else +#ifdef WORDS_REVERSED +#define MACHREL_BWR (RELWR) +#else +#define MACHREL_BWR (0) +#endif #endif diff --git a/mach/proto/as/comm1.h b/mach/proto/as/comm1.h index ca433311..c4b6dec2 100644 --- a/mach/proto/as/comm1.h +++ b/mach/proto/as/comm1.h @@ -20,6 +20,7 @@ extern short sflag INIT(SYM_DEF); /* -s option (symbol table info) */ extern char *progname; /* for error messages */ extern char *modulename; /* for error messages */ +extern common_t *commons; /* header of commons list */ #ifdef ASLD extern short archmode; /* scanning archives */ @@ -52,14 +53,6 @@ extern char temppath[50]; extern FILE *input; extern FILE *tempfile; -#ifdef AOUTSEEK -extern FILE *aoutfile; -extern int aoutpart INIT(-1); -extern long aoutseek[PARTS]; -#else -extern FILE *aoutfile[PARTS]; -#endif - extern char stringbuf[STRINGMAX]; /* contains last string value */ @@ -72,6 +65,8 @@ extern sect_t *DOTSCT; /* §[DOTTYP-S_MIN] or NULL */ extern addr_t DOTVAL; /* DOTSCT->s_size + DOTSCT->s_base */ extern short DOTTYP; /* S_MIN..S_MAX or S_UND */ +extern ushort nname; /* Counts name table index in PASS_3 */ + extern item_t *hashtab[H_TOTAL]; extern short hashindex; /* see item_search() */ diff --git a/mach/proto/as/comm2.y b/mach/proto/as/comm2.y index 0e5c37c8..005f5f30 100644 --- a/mach/proto/as/comm2.y +++ b/mach/proto/as/comm2.y @@ -229,25 +229,7 @@ datalist { #ifdef RELOCATION if (rflag != 0 && PASS_RELO) -#ifdef DUK -#ifdef BYTES_REVERSED -#ifdef WORDS_REVERSED - newrelo($1.typ, - (int)$0 | RELBR | RELWR - ); -#else WORDS_REVERSED - newrelo($1.typ, (int)$0|RELBR); -#endif WORDS_REVERSED -#else BYTES_REVERSED -#ifdef WORDS_REVERSED - newrelo($1.typ, (int)$0|RELWR); -#else WORDS_REVERSED - newrelo($1.typ, (int)$0); -#endif WORDS_REVERSED -#endif BYTES_REVERSED -#else DUK - newrelo($1.typ, (int)$0); -#endif DUK + newrelo($1.typ, (int)$0|MACHREL_BWR); #endif emitx($1.val, (int)$0); } @@ -255,25 +237,7 @@ datalist { #ifdef RELOCATION if (rflag != 0 && PASS_RELO) -#ifdef DUK -#ifdef BYTES_REVERSED -#ifdef WORDS_REVERSED - newrelo($3.typ, - (int)$0 | RELBR | RELWR - ); -#else WORDS_REVERSED - newrelo($3.typ, (int)$0|RELBR); -#endif WORDS_REVERSED -#else BYTES_REVERSED -#ifdef WORDS_REVERSED - newrelo($3.typ, (int)$0|RELWR); -#else WORDS_REVERSED - newrelo($3.typ, (int)$0); -#endif WORDS_REVERSED -#endif BYTES_REVERSED -#else DUK - newrelo($3.typ, (int)$0); -#endif DUK + newrelo($3.typ, (int)$0|MACHREL_BWR); #endif emitx($3.val, (int)$0); } diff --git a/mach/proto/as/comm3.c b/mach/proto/as/comm3.c index 937114e7..1547e3cd 100644 --- a/mach/proto/as/comm3.c +++ b/mach/proto/as/comm3.c @@ -9,16 +9,10 @@ #include "comm1.h" +#undef extern + struct outhead outhead = { O_MAGIC, O_STAMP, 0 -#ifndef DUK -#ifdef BYTES_REVERSED - | HF_BREV -#endif -#ifdef WORDS_REVERSED - | HF_WREV -#endif -#endif DUK }; #include "y.tab.h" diff --git a/mach/proto/as/comm4.c b/mach/proto/as/comm4.c index 14a1093f..3bfec2bc 100644 --- a/mach/proto/as/comm4.c +++ b/mach/proto/as/comm4.c @@ -34,11 +34,14 @@ char **argv; SIGHUP, SIGINT, SIGQUIT, SIGTERM, 0 }; - /* this test should be performed by the - * preprocessor, but it cannot + /* the next test should be performed by the + * preprocessor, but it cannot, so it is performed by the compiler. */ - if ((S_ETC|S_COM|S_VAR|S_DOT) != S_ETC) - fatal("incorrect type bits"); + + switch(0) { + case 1: break; + case (S_ETC|S_COM|S_VAR|S_DOT) != S_ETC : break; + } progname = *argv++; argc--; for (p = sigs; i = *p++; ) @@ -106,6 +109,7 @@ char **argv; pass_23(PASS_2); #endif pass_23(PASS_3); + wr_close(); stop(); } @@ -114,11 +118,10 @@ char **argv; pass_1(argc, argv) char **argv; { - register i; register char *p; register item_t *ip; #ifdef ASLD - char armagic[SZMAGIC]; + char armagic[2]; #else register nfile = 0; #endif @@ -136,24 +139,25 @@ char **argv; p = *argv++; if (p == 0) continue; -#ifdef ASLD +#ifndef ASLD + if (nfile != 0) + fatal("second source file %s", p); + nfile++; +#endif if (p[0] == '-' && p[1] == '\0') { input = stdin; parse("STDIN"); continue; } -#else - if (nfile != 0) - fatal("second source file %s", p); - nfile++; -#endif + if ((input = fopen(p, "r")) == NULL) fatal("can't open %s", p); #ifdef ASLD if ( - fread(armagic, SZMAGIC, 1, input) == 1 + fread(armagic, 2, 1, input) == 1 && - strncmp(armagic, ARMAGIC, SZMAGIC) == 0 + ((armagic[0]&0377) | + ((unsigned)(armagic[1]&0377)<<8)) == ARMAG ) { archive(); fclose(input); @@ -168,6 +172,8 @@ char **argv; machfinish(PASS_1); #ifdef ASLD if (unresolved) { + register int i; + nerrors++; fflush(stdout); fprintf(stderr, "unresolved references:\n"); @@ -189,40 +195,35 @@ char **argv; } #ifdef ASLD -archive() -{ +archive() { register long offset; - register i; - register long modsize; - char modhead[SZMHEAD]; + struct ar_hdr header; + char getsize[AR_TOTAL]; archmode++; - offset = SZMAGIC; + offset = 2; for (;;) { if (unresolved == 0) break; - fseek(input, offset, 0); - if (fread(modhead, SZMHEAD, 1, input) != 1) + fseek(input,offset,0); + if (fread(getsize,AR_TOTAL,1,input) != 1) break; - if ( - strncmp(&modhead[OFF_BEG], STR_BEG, LEN_BEG) - || - strncmp(&modhead[OFF_END], STR_END, LEN_END) - ) - fatal("bad archive"); - offset += SZMHEAD; - modsize = atol(&modhead[OFF_SIZ]); - archsize = modsize; + offset += AR_TOTAL; + strncpy(header.ar_name,getsize,sizeof header.ar_name) ; + header.ar_size= (((((long) (getsize[AR_SIZE+1]&0377))<<8)+ + ((long) (getsize[AR_SIZE ]&0377))<<8)+ + ((long) (getsize[AR_SIZE+3]&0377))<<8)+ + ((long) (getsize[AR_SIZE+2]&0377)) ; + archsize = header.ar_size; if (needed()) { - fseek(input, offset, 0); - archsize = modsize; - for (i = 0; i < LEN_NAM; i++) - if (modhead[OFF_NAM+i] == ' ') - break; - modhead[OFF_NAM+i] = '\0'; - parse(remember(&modhead[OFF_NAM])); + fseek(input,offset,0); + archsize = header.ar_size; + header.ar_name[14] = '\0'; + parse(remember(header.ar_name)); } - offset += modsize; + offset += header.ar_size; + while (offset % 2) + offset++; } archmode = 0; } @@ -257,6 +258,12 @@ needed() continue; } if (first) { + if (ip == &keytab[KEYSECT]) { + while ((c = nextchar()) != '\n') + ; + continue; + } + if (ip != &keytab[KEYDEFINE]) break; first = 0; @@ -417,24 +424,12 @@ setupoutput() register sect_t *sp; register long off; struct outsect outsect; + register struct outsect *pos = &outsect; -#ifdef AOUTSEEK -#define AOUTseek(p,o) {aoutseek[p]=o;} - aoutfile = ffcreat(aoutpath); -#else -#define AOUTseek(p,o) {fseek(aoutfile[p],o,0);} - aoutfile[PARTEMIT]=ffcreat(aoutpath); -#ifdef RELOCATION - aoutfile[PARTRELO]=ffcreat(aoutpath); -#endif - aoutfile[PARTNAME]=ffcreat(aoutpath); - aoutfile[PARTCHAR]=ffcreat(aoutpath); -#endif - /* - * header generation - */ - AOUTseek(PARTEMIT, 0); - putofmt((char *)&outhead, SF_HEAD, PARTEMIT); + if (! wr_open(aoutpath)) { + fatal("can't create %s", aoutpath); + } + wr_ohead(&outhead); /* * section table generation */ @@ -442,52 +437,56 @@ setupoutput() off += (long)outhead.oh_nsect * SZ_SECT; for (sp = sect; sp < §[outhead.oh_nsect]; sp++) { sp->s_foff = off; - outsect.os_base = SETBASE(sp); - outsect.os_size = sp->s_size + sp->s_comm; - outsect.os_foff = sp->s_foff; - outsect.os_flen = sp->s_size - sp->s_zero; - outsect.os_lign = sp->s_lign; - off += outsect.os_flen; - putofmt((char *)&outsect, SF_SECT, PARTEMIT); + pos->os_base = SETBASE(sp); + pos->os_size = sp->s_size + sp->s_comm; + pos->os_foff = sp->s_foff; + pos->os_flen = sp->s_size - sp->s_zero; + pos->os_lign = sp->s_lign; + off += pos->os_flen; + wr_sect(pos, 1); } #ifdef RELOCATION - AOUTseek(PARTRELO, off); off += (long)outhead.oh_nrelo * SZ_RELO; #endif if (sflag == 0) return; - AOUTseek(PARTNAME, off); off += (long)outhead.oh_nname * SZ_NAME; - AOUTseek(PARTCHAR, off); outhead.oh_nchar = off; /* see newsymb() */ -#undef AOUTseek } commfinish() { - register i; +#ifndef ASLD + register int i; +#endif + register struct common_t *cp; register item_t *ip; register sect_t *sp; register valu_t addr; switchsect(S_UND); -#ifdef ASLD /* * assign .comm labels and produce .comm symbol table entries */ - for (i = 0; ii_next) { - if ((ip->i_type & S_COM) == 0) - continue; + for (cp = commons; cp; cp = cp->c_next) { + ip = cp->c_it; +#ifndef ASLD + if (!( ip->i_type & S_EXT)) { +#endif sp = §[(ip->i_type & S_TYP) - S_MIN]; if (pass == PASS_1) { addr = sp->s_size + sp->s_comm; sp->s_comm += ip->i_valu; ip->i_valu = addr; +#ifndef ASLD + ip->i_type &= ~S_COM; +#endif } +#ifdef ASLD #ifdef THREE_PASS - if (pass == PASS_2) + if (pass == PASS_2) { ip->i_valu -= sp->s_gain; + } #endif if ((sflag & SYM_EXT) && PASS_SYMB) newsymb( @@ -496,8 +495,27 @@ commfinish() (short)0, load(ip) ); +#else not ASLD +#ifdef THREE_PASS + if (pass == PASS_2) { + cp->c_size -= sp->s_gain; + } +#endif THREE_PASS } -#endif + if (pass == PASS_1) cp->c_size = ip->i_valu; + if (PASS_SYMB) { + if (pass != PASS_3 && (ip->i_type & S_EXT)) { + ip->i_valu = outhead.oh_nname; + } + newsymb( + ip->i_name, + ip->i_type, + (short) 0, + cp->c_size + ); + } +#endif not ASLD + } if (PASS_SYMB == 0) return; #ifndef ASLD @@ -514,15 +532,14 @@ commfinish() * for possible relocation */ ip->i_valu = outhead.oh_nname; - if (sflag & SYM_SCT) - newsymb( - ip->i_name, - S_EXT|S_UND, - (short)0, - (valu_t)0 - ); + newsymb( + ip->i_name, + S_EXT|S_UND, + (short)0, + (valu_t)0 + ); } -#endif ASLD +#endif not ASLD /* * produce symbol table entries for sections */ diff --git a/mach/proto/as/comm5.c b/mach/proto/as/comm5.c index 09a00d27..795ac72f 100644 --- a/mach/proto/as/comm5.c +++ b/mach/proto/as/comm5.c @@ -162,13 +162,7 @@ getval(c) #endif case STRING: p = stringbuf; -#ifdef DUK - *p++ = n = getc(tempfile); - p[n] = '\0'; - break; -#else DUK - *p++ = n = getc(tempfile); break; -#endif DUK + *p++ = n = getc(tempfile); p[n] = '\0'; break; case OP_EQ: case OP_NE: case OP_LE: @@ -360,18 +354,12 @@ instring(termc) break; if (c == '\\') c = inescape(); -#ifdef DUK if (p >= &stringbuf[STRINGMAX - 1]) -#else DUK - if (p >= &stringbuf[STRINGMAX]) -#endif DUK fatal("string buffer overflow"); *p++ = c; } stringbuf[0] = p - stringbuf - 1; -#ifdef DUK *p = '\0'; -#endif DUK return(STRING); } diff --git a/mach/proto/as/comm6.c b/mach/proto/as/comm6.c index da76ed95..7d6f33e0 100644 --- a/mach/proto/as/comm6.c +++ b/mach/proto/as/comm6.c @@ -106,11 +106,11 @@ register item_t *ip; sp = §[typ - S_MIN]; sp->s_item = ip; sp->s_lign = ALIGNSECT; -#ifdef DUK +#ifndef ASLD ip->i_type = typ; -#else DUK +#else ip->i_type = typ | S_EXT; -#endif DUK +#endif ip->i_valu = 0; } else if (typ >= S_MIN) { sp = §[typ - S_MIN]; @@ -142,16 +142,14 @@ valu_t base; } /* - * NOTE: A rather different solution is used for ASLD and NOLD: - * ASLD: + * NOTE: A rather different solution is used for ASLD and not ASLD: + * ASLD, or local commons: * - maximum length of .comm is recorded in i_valu during PASS_1 * - address of .comm is recorded in i_valu in later passes: * assigned at end of PASS_1, corrected for s_gain at end of PASS_2 - * - symbol table entries are produced in commfinish() - * NOLD: - * - i_valu cannot be used since it is needed for relocation info - * - only one .comm with a particular symbol is allowed per module - * - symbol table entries are produced in newcomm() + * not ASLD: + * - maximum length of .comm is recorded in i_valu during PASS_1 + * - i_valu is used for relocation info during PASS_3 */ newcomm(ip, val) register item_t *ip; @@ -165,31 +163,15 @@ valu_t val; /* printf("declare %s: %o\n", ip->i_name, DOTTYP); */ if ((ip->i_type & ~S_EXT) == S_UND) { --unresolved; - ip->i_type = S_COM|S_EXT|DOTTYP; -#ifdef ASLD + ip->i_type = S_COM|DOTTYP|(ip->i_type&S_EXT); ip->i_valu = val; - } else if (ip->i_type == (S_COM|S_EXT|DOTTYP)) { + new_common(ip); + } else if (ip->i_type == (S_COM|DOTTYP|(ip->i_type&S_EXT))) { if (ip->i_valu < val) ip->i_valu = val; -#endif } else serror("multiple declared"); } -#ifndef ASLD - if (PASS_SYMB == 0) - return; - if (pass != PASS_3) - /* - * save symbol table index - * for possible relocation - */ - ip->i_valu = outhead.oh_nname; -#ifdef DUK - newsymb(ip->i_name, S_COM|S_EXT|DOTTYP, (short)0, val); -#else DUK - newsymb(ip->i_name, S_EXT|DOTTYP, (short)0, val); -#endif DUK -#endif } switchsect(newtyp) @@ -207,12 +189,7 @@ short newtyp; assert(newtyp >= S_MIN); sp = §[newtyp - S_MIN]; if (pass == PASS_3) { -#ifdef AOUTSEEK - aoutpart = -1; - aoutseek[PARTEMIT] = sp->s_foff + sp->s_size - sp->s_zero; -#else - fseek(aoutfile[PARTEMIT], sp->s_foff + sp->s_size - sp->s_zero, 0); -#endif + wr_outsect(newtyp - S_MIN); } DOTVAL = sp->s_size + sp->s_base; DOTSCT = sp; @@ -254,9 +231,8 @@ valu_t bytes; DOTGAIN += (bytes - 1) - gap; #endif } - /* I don't play the os_zero game here, but plainly write out zero's */ - /* Led abuses trailing zero parts */ - while (gap--) emit1(0) ; + DOTVAL += gap; + sp->s_zero += gap; } #ifdef RELOCATION @@ -264,9 +240,7 @@ newrelo(s, n) short s; { struct outrelo outrelo; -#ifdef DUK int iscomm; -#endif DUK if (rflag == 0) return; @@ -284,9 +258,7 @@ short s; * b=a * a: .data2 0 */ -#ifdef DUK iscomm = s & S_COM; -#endif DUK s &= ~S_COM; if ((n & RELPC) == 0 && s == S_ABS) return; @@ -300,11 +272,7 @@ short s; outrelo.or_type = (char)n; outrelo.or_sect = (char)DOTTYP; #ifndef ASLD -#ifdef DUK if (s == S_UND || iscomm) { -#else DUK - if (s == S_UND) { -#endif DUK assert(relonami != 0); outrelo.or_nami = relonami-1; relonami = 0; @@ -326,7 +294,7 @@ short s; ; } outrelo.or_addr = (long)DOTVAL; - putofmt((char *)&outrelo, SF_RELO, PARTRELO); + wr_relo(&outrelo, 1); } #endif @@ -347,17 +315,37 @@ valu_t valu; outhead.oh_nname++; return; } + nname++; if (name) { - AOUTPART(PARTCHAR); + int len = strlen(name) + 1; + + wr_string(name, len); outname.on_foff = outhead.oh_nchar; - do { - AOUTPUTC(*name, PARTCHAR); - outhead.oh_nchar++; - } while (*name++); + outhead.oh_nchar += len; } else outname.on_foff = 0; outname.on_type = type; outname.on_desc = desc; outname.on_valu = valu & ~((0xFFFFFFFF)<<(8*sizeof(valu_t))); - putofmt((char *)&outname, SF_NAME, PARTNAME); + wr_name(&outname, 1); +} + +new_common(ip) + item_t *ip; +{ + register struct common_t *cp; + static nleft = 0; + static struct common_t *next; + + if (--nleft < 0) { + next = (struct common_t *) sbrk(MEMINCR); + if ((int) next == -1) { + fatal("out of memory"); + } + nleft += (MEMINCR / sizeof (struct common_t)); + } + cp = next++; + cp->c_next = commons; + cp->c_it = ip; + commons = cp; } diff --git a/mach/proto/as/comm7.c b/mach/proto/as/comm7.c index 38612b77..560ed7f8 100644 --- a/mach/proto/as/comm7.c +++ b/mach/proto/as/comm7.c @@ -19,11 +19,7 @@ register item_t *ip; return(ip->i_valu); return(ip->i_valu + sect[typ].s_base); #else -#ifdef DUK if ((ip->i_type & S_TYP) == S_UND || (ip->i_type & S_COM)) { -#else DUK - if ((ip->i_type & S_TYP) == S_UND) { -#endif DUK if (pass == PASS_3) { if (relonami != 0) serror("relocation error"); @@ -200,6 +196,7 @@ small(fitsmall, gain) assert(fitsmall || (*p & bit) == 0); return(*p & bit); } + /*NOTREACHED*/ } #endif @@ -229,12 +226,12 @@ char arg; DOTSCT->s_zero = 0; break; case PASS_3: - AOUTPART(PARTEMIT); + wr_outsect(DOTTYP-S_MIN); while (DOTSCT->s_zero) { - AOUTPUTC(0, PARTEMIT); + wr_putc(0); DOTSCT->s_zero--; } - AOUTPUTC(arg, PARTEMIT); + wr_putc(arg); break; } DOTVAL++; @@ -262,7 +259,7 @@ long arg; emitx(val, n) valu_t val; -register n; +int n; { switch (n) { case 1: @@ -312,7 +309,7 @@ char *s; FILE * fftemp(path, tail) -char *path; +char *path, *tail; { register char *dir; @@ -326,36 +323,6 @@ char *path; return(ffcreat(mktemp(path))); } -putofmt(p, s, part) -register char *p; -register char *s; -{ - register i; - register long l; - - AOUTPART(part); - while (i = *s++) { - switch (i -= '0') { -/* case 0: p++; break; */ - case 1: - l = (long) *((char *)p); p += sizeof(char ); - break; - case 2: - l = (long) *((short *)p); p += sizeof(short); - break; - case 4: - l = (long) *((long *)p); p += sizeof(long ); - break; - default: - assert(0); - } - while (--i >= 0) { - AOUTPUTC((int)l, part); - l >>= 8; - } - } -} - /* ---------- Error handling ---------- */ yyerror(){} /* we will do our own error printing */ @@ -365,7 +332,7 @@ nosect() fatal("no sections"); } -werror() +wr_fatal() { fatal("write error"); } From 0bd78213b646020aecd746e652023107889f1544 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 2 Dec 1986 11:25:51 +0000 Subject: [PATCH 0357/1625] Added -i to LDFLAGS. --- util/led/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/led/Makefile b/util/led/Makefile index e3587f90..916fa5ef 100644 --- a/util/led/Makefile +++ b/util/led/Makefile @@ -8,7 +8,7 @@ EM = ../.. LIBDIR= $(EM)/lib PREFLAGS= -I$(EM)/h -DNDEBUG -DNASSERT CFLAGS = $(PREFLAGS) -O -LDFLAGS = +LDFLAGS = -i LDLIBS = $(EM)/modules/lib/libstring.a $(EM)/modules/lib/libobject.a LINTFLAGS=-phbxa $(PREFLAGS) PR = pr From aa759091308fb4cad9a758ce2a355f9fc4401744 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 2 Dec 1986 11:39:34 +0000 Subject: [PATCH 0358/1625] bug fix: size 0 error messages also appeared for labels --- lang/cem/cemcom/idf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/cem/cemcom/idf.c b/lang/cem/cemcom/idf.c index 23473af6..de391853 100644 --- a/lang/cem/cemcom/idf.c +++ b/lang/cem/cemcom/idf.c @@ -197,7 +197,7 @@ declare_idf(ds, dc, lvl) error("unknown %s-type", symbol2str(type->tp_fund)); } - else { + else if (type->tp_fund != LABEL) { /* CJ */ warning("%s has size 0", idf->id_text); } From af341d2dde0bbef0619c6ec1142013d68c8035a6 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 2 Dec 1986 16:16:08 +0000 Subject: [PATCH 0359/1625] made to work on small machines. --- util/led/memory.c | 80 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 61 insertions(+), 19 deletions(-) diff --git a/util/led/memory.c b/util/led/memory.c index af93d45d..2baa5f2b 100644 --- a/util/led/memory.c +++ b/util/led/memory.c @@ -7,6 +7,14 @@ static char rcsid[] = "$Header$"; * for each piece telling where it is, how many bytes are used, and how may * are left. If a request for core doesn't fit in the left bytes, an sbrk() * is done and pieces after the one that requested the growth are moved up. + * + * Unfortunately, we cannot use sbrk to request more memory, because its + * result cannot be trusted. More specifically, it does not work properly + * on 2.9 BSD, and probably does not work properly on 2.8 BSD and V7 either. + * The problem is that "sbrk" adds the increment to the current "break" + * WITHOUT testing the carry bit. So, if your break is at 40000, and + * you "sbrk(30000)", it will succeed, but your break will be at 4464 + * (70000 - 65536). */ #include @@ -26,7 +34,32 @@ struct memory mems[NMEMS]; bool incore = TRUE; /* TRUE while everything can be kept in core. */ ind_t core_position = (ind_t)0; /* Index of current module. */ -#define AT_LEAST 2 /* See comment about string areas. */ +#define AT_LEAST (ind_t)2 /* See comment about string areas. */ +#define GRANULE 64 /* power of 2 */ + +static char *BASE; +static ind_t refused; + +sbreak(incr) + ind_t incr; +{ + extern char *sbrk(); + extern char *brk(); + unsigned int inc; + + incr = (incr + (GRANULE - 1)) & ~(GRANULE - 1); + + inc = incr; + if ((refused && refused < incr) || + inc != incr || + BASE + inc < BASE || + (int) brk(BASE + inc) == -1) { + refused = refused && refused > incr ? incr : refused; + return -1; + } + BASE = sbrk(0); + return 0; +} /* * Initialize some pieces of core. We hope that this will be our last @@ -37,9 +70,8 @@ init_core() register char *base; register ind_t total_size; register struct memory *mem; - extern char *sbrk(); extern char *brk(); -char *BASE; + extern char *sbrk(); #include "mach.c" @@ -64,14 +96,22 @@ char *BASE; total_size += 1; else mems[ALLOGCHR].mem_left -= 1; + + if (sbreak(total_size) == -1) { + incore = FALSE; /* In core strategy failed. */ + if (sbreak(AT_LEAST) == -1) + fatal("no core at all"); + + base = BASE; + for (mem = mems; mem < &mems[NMEMS]; mem++) { + mem->mem_base = base; + mem->mem_full = (ind_t)0; + mem->mem_left = 0; + } + } + mems[ALLOLCHR].mem_full = 1; mems[ALLOGCHR].mem_full = 1; - - if (brk(BASE + total_size) == (char *) -1) { - incore = FALSE; /* In core strategy failed. */ - if ((int)sbrk(AT_LEAST) == -1) - fatal("no core at all"); - } } /* @@ -85,10 +125,9 @@ move_up(piece, incr) register ind_t incr; { register struct memory *mem; - extern char *sbrk(); debug("move_up(%d, %d)\n", piece, (int)incr, 0, 0); - if (incr != (int)incr || sbrk((int)incr) == (char *) -1) + if (sbreak(incr) == -1) return FALSE; for (mem = &mems[NMEMS - 1]; mem > &mems[piece]; mem--) @@ -114,16 +153,17 @@ compact(piece, incr) { register ind_t gain; register struct memory *mem; +#define ALIGN 8 debug("compact(%d, %d)\n", piece, (int)incr, 0, 0); - gain = mems[0].mem_left; - mems[0].mem_left = (ind_t)0; + gain = mems[0].mem_left & ~(ALIGN - 1); + mems[0].mem_left &= (ALIGN - 1); for (mem = &mems[1]; mem <= &mems[piece]; mem++) { /* Here memory is inserted before a piece. */ assert(passnumber == FIRST || gain == (ind_t)0); copy_down(mem, gain); - gain += mem->mem_left; - mem->mem_left = (ind_t)0; + gain += mem->mem_left & ~(ALIGN - 1); + mem->mem_left &= (ALIGN - 1); } /* * Note that we already added the left bytes of the piece we want to @@ -134,13 +174,13 @@ compact(piece, incr) for (mem = &mems[NMEMS - 1]; mem > &mems[piece]; mem--) { /* Here memory is appended after a piece. */ - up += mem->mem_left; + up += mem->mem_left & ~(ALIGN - 1); copy_up(mem, up); - mem->mem_left = (ind_t)0; + mem->mem_left &= (ALIGN - 1); } gain += up; } - mems[piece].mem_left = gain; + mems[piece].mem_left += gain; return gain >= incr; } @@ -159,6 +199,7 @@ copy_down(mem, dist) register char *new; register ind_t size; + if (!dist) return; size = mem->mem_full; old = mem->mem_base; new = old - dist; @@ -182,6 +223,7 @@ copy_up(mem, dist) register char *new; register ind_t size; + if (!dist) return; size = mem->mem_full; old = mem->mem_base + size; new = old + dist; @@ -215,7 +257,7 @@ alloc(piece, size) while (left + incr < size) incr += INCRSIZE; - if (incr == 0 || move_up(piece, incr) || compact(piece, incr)) { + if (incr == 0 || move_up(piece, incr) || compact(piece, size)) { mems[piece].mem_full += size; mems[piece].mem_left -= size; return full; From abfed9b1f54f695977526d8f2dc06ed789451559 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 3 Dec 1986 13:02:37 +0000 Subject: [PATCH 0360/1625] Added definitions for "alloc", "hard_alloc". --- util/led/memory.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/util/led/memory.h b/util/led/memory.h index b5615ef8..239c9341 100644 --- a/util/led/memory.h +++ b/util/led/memory.h @@ -33,3 +33,5 @@ extern struct memory mems[]; #define modulptr(offset) (mems[ALLOMODL].mem_base+core_position+(offset)) extern ind_t core_position; +extern ind_t hard_alloc(); +extern ind_t alloc(); From e12b25522cbfa905aa1300131cac1e0475166e9b Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 3 Dec 1986 13:06:48 +0000 Subject: [PATCH 0361/1625] Improved compactification code. It was much to persistent, and also too greedy. This causes long LONG linking times. The current version is less greedy, but also gives up more easily. Linking times are acceptable now. --- util/led/memory.c | 73 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 59 insertions(+), 14 deletions(-) diff --git a/util/led/memory.c b/util/led/memory.c index 2baa5f2b..dc9ac03b 100644 --- a/util/led/memory.c +++ b/util/led/memory.c @@ -147,40 +147,85 @@ extern int passnumber; * enough bytes, the first or the second time. */ static bool -compact(piece, incr) +compact(piece, incr, freeze) register int piece; register ind_t incr; { - register ind_t gain; + register ind_t gain, size; register struct memory *mem; -#define ALIGN 8 +#define ALIGN 8 /* minimum alignment for pieces */ +#define SHIFT_COUNT 2 /* let pieces only contribute if their free + memory is more than 1/2**SHIFT_COUNT * 100 % + of its occupied memory + */ debug("compact(%d, %d)\n", piece, (int)incr, 0, 0); - gain = mems[0].mem_left & ~(ALIGN - 1); - mems[0].mem_left &= (ALIGN - 1); - for (mem = &mems[1]; mem <= &mems[piece]; mem++) { + for (mem = &mems[0]; mem < &mems[NMEMS - 1]; mem++) { + assert(mem->mem_base + mem->mem_full + mem->mem_left == (mem+1)->mem_base); + } + /* + * First, check that moving will result in enough space + */ + if (! freeze) { + gain = mems[piece].mem_left & ~(ALIGN - 1); + for (mem = &mems[0]; mem <= &mems[NMEMS-1]; mem++) { + /* + * Don't give it all away! + * If this does not give us enough, bad luck + */ + if (mem == &mems[piece]) continue; + size = mem->mem_full >> SHIFT_COUNT; + if (mem->mem_left > size) + gain += (mem->mem_left - size) & ~(ALIGN - 1); + } + if (gain < incr) return 0; + } + + gain = 0; + for (mem = &mems[0]; mem != &mems[piece]; mem++) { /* Here memory is inserted before a piece. */ assert(passnumber == FIRST || gain == (ind_t)0); copy_down(mem, gain); - gain += mem->mem_left & ~(ALIGN - 1); - mem->mem_left &= (ALIGN - 1); + if (freeze || gain < incr) { + if (freeze) size = 0; + else size = mem->mem_full >> SHIFT_COUNT; + if (mem->mem_left > size) { + size = (mem->mem_left - size) & ~(ALIGN - 1); + gain += size; + mem->mem_left -= size; + } + } } /* - * Note that we already added the left bytes of the piece we want to - * enlarge to `gain'. + * Now mems[piece]: */ + copy_down(mem, gain); + gain += mem->mem_left & ~(ALIGN - 1); + mem->mem_left &= (ALIGN - 1); + if (gain < incr) { register ind_t up = (ind_t)0; for (mem = &mems[NMEMS - 1]; mem > &mems[piece]; mem--) { /* Here memory is appended after a piece. */ - up += mem->mem_left & ~(ALIGN - 1); + if (freeze || gain + up < incr) { + if (freeze) size = 0; + else size = mem->mem_full >> SHIFT_COUNT; + if (mem->mem_left > size) { + size = (mem->mem_left - size) & ~(ALIGN - 1); + up += size; + mem->mem_left -= size; + } + } copy_up(mem, up); - mem->mem_left &= (ALIGN - 1); } gain += up; } mems[piece].mem_left += gain; + assert(freeze || gain >= incr); + for (mem = &mems[0]; mem < &mems[NMEMS - 1]; mem++) { + assert(mem->mem_base + mem->mem_full + mem->mem_left == (mem+1)->mem_base); + } return gain >= incr; } @@ -257,7 +302,7 @@ alloc(piece, size) while (left + incr < size) incr += INCRSIZE; - if (incr == 0 || move_up(piece, incr) || compact(piece, size)) { + if (incr == 0 || move_up(piece, incr) || compact(piece, size, 0)) { mems[piece].mem_full += size; mems[piece].mem_left -= size; return full; @@ -382,7 +427,7 @@ freeze_core() break; } } - compact(NMEMS - 1, (ind_t)0); + compact(NMEMS - 1, (ind_t)0, 1); } /* ------------------------------------------------------------------------- */ From fabb83eddccd9aa83ec5234cc063088421045865 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 3 Dec 1986 13:09:15 +0000 Subject: [PATCH 0362/1625] Improved relocation reading code for the !incore strategy. --- util/led/scan.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/util/led/scan.c b/util/led/scan.c index 0ac32dd3..e9d87ae3 100644 --- a/util/led/scan.c +++ b/util/led/scan.c @@ -494,9 +494,11 @@ modulsize(head) */ static struct outrelo *walkrelo; +static unsigned short cnt_relos; +static unsigned short index; startrelo(head) - struct outhead *head; + register struct outhead *head; { ind_t reloindex; @@ -504,18 +506,29 @@ startrelo(head) reloindex = *(ind_t *)(modulbase + IND_RELO(*head)); walkrelo = (struct outrelo *)address(ALLORELO, reloindex); } + else { + index = 20; + rd_rew_relos(head); + cnt_relos = head->oh_nrelos; + } } struct outrelo * nextrelo() { - static struct outrelo relobuf; + static struct outrelo relobuf[20]; if (incore) return walkrelo++; - rd_relo(&relobuf, 1); - return &relobuf; + if (index == 20) { + int i = cnt_relos >= 20 ? 20 : cnt_relos; + + cnt_relos -= i; + rd_relo(relobuf, i); + index = 0; + } + return &relobuf[index++]; } /* ------------------------------------------------------------------------- */ From bd0740dc421040b55ed7079cfcd0f25c3e74ce2f Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 4 Dec 1986 16:29:44 +0000 Subject: [PATCH 0363/1625] version using input module and detecting preprocessor loops --- lang/cem/cemcom/LLlex.c | 20 +- lang/cem/cemcom/LLlex.h | 4 +- lang/cem/cemcom/Makefile.erik | 88 +++---- lang/cem/cemcom/Parameters | 6 +- lang/cem/cemcom/domacro.c | 81 +++--- lang/cem/cemcom/file_info.h | 14 + lang/cem/cemcom/init.c | 34 +-- lang/cem/cemcom/input.c | 466 ++-------------------------------- lang/cem/cemcom/input.h | 12 +- lang/cem/cemcom/macro.str | 5 +- lang/cem/cemcom/main.c | 21 +- lang/cem/cemcom/options.c | 10 +- lang/cem/cemcom/replace.c | 77 ++++-- 13 files changed, 239 insertions(+), 599 deletions(-) create mode 100644 lang/cem/cemcom/file_info.h diff --git a/lang/cem/cemcom/LLlex.c b/lang/cem/cemcom/LLlex.c index 84d5b29d..e8b245cc 100644 --- a/lang/cem/cemcom/LLlex.c +++ b/lang/cem/cemcom/LLlex.c @@ -21,9 +21,6 @@ /* Data about the token yielded */ struct token dot, ahead, aside; -unsigned int LineNumber = 0; /* current LineNumber */ -char *FileName = 0; /* current filename */ - int ReplaceMacros = 1; /* replacing macros */ int EoiForNewline = 0; /* return EOI upon encountering newline */ int PreProcKeys = 0; /* return preprocessor key */ @@ -31,6 +28,7 @@ int AccFileSpecifier = 0; /* return filespecifier <...> */ int AccDefined = 0; /* accept "defined(...)" */ int UnknownIdIsZero = 0; /* interpret unknown id as integer 0 */ int SkipEscNewline = 0; /* how to interpret backslash-newline */ +int Unstacked = 0; /* an unstack is done */ #define MAX_LL_DEPTH 2 @@ -102,21 +100,28 @@ GetToken(ptok) char buf[(IDFSIZE > NUMSIZE ? IDFSIZE : NUMSIZE) + 1]; register int ch, nch; + if (! LineNumber) goto firstline; again: /* rescan the input after an error or replacement */ +#ifndef NOPP + if (Unstacked) EnableMacros(); +#endif LoadChar(ch); go_on: /* rescan, the following character has been read */ if ((ch & 0200) && ch != EOI) /* stop on non-ascii character */ fatal("non-ascii '\\%03o' read", ch & 0377); switch (class(ch)) { /* detect character class */ case STNL: /* newline, vertical space or formfeed */ +firstline: LineNumber++; /* also at vs and ff */ if (EoiForNewline) /* called in control line */ /* a newline in a control line indicates the end-of-information of the line. */ return ptok->tk_symb = EOI; - while (LoadChar(ch), ch == '#') /* a control line follows */ + while (LoadChar(ch), ch == '#') { /* a control line follows */ domacro(); + if (!LineNumber) goto firstline; + } /* We have to loop here, because in `domacro' the nl, vt or ff is read. The character following it may again be a `#'. @@ -253,6 +258,9 @@ go_on: /* rescan, the following character has been read */ hash = STARTHASH(); do { /* read the identifier */ if (++pos < idfsize) { +#ifndef NOPP + if (Unstacked) EnableMacros(); +#endif *tg++ = ch; hash = ENHASH(hash, ch, pos); } @@ -485,8 +493,10 @@ string_token(nm, stop_char, plen) } if (ch == '\\') { LoadChar(ch); - if (ch == '\n') + if (ch == '\n') { LineNumber++; + continue; + } ch = quoted(ch); } str[pos++] = ch; diff --git a/lang/cem/cemcom/LLlex.h b/lang/cem/cemcom/LLlex.h index 569a2e90..c01aaf46 100644 --- a/lang/cem/cemcom/LLlex.h +++ b/lang/cem/cemcom/LLlex.h @@ -7,6 +7,7 @@ */ #include "nofloat.h" +#include "file_info.h" /* the structure of a token: */ struct token { @@ -42,8 +43,6 @@ struct token { #endif NOFLOAT extern struct token dot, ahead, aside; -extern unsigned int LineNumber; /* "LLlex.c" */ -extern char *FileName; /* "LLlex.c" */ extern int ReplaceMacros; /* "LLlex.c" */ extern int EoiForNewline; /* "LLlex.c" */ @@ -52,6 +51,7 @@ extern int AccFileSpecifier; /* "LLlex.c" */ extern int AccDefined; /* "LLlex.c" */ extern int UnknownIdIsZero; /* "LLlex.c" */ extern int SkipEscNewline; /* "LLlex.c" */ +extern int Unstacked; /* "LLlex.c" */ extern int NoUnstack; /* buffer.c */ diff --git a/lang/cem/cemcom/Makefile.erik b/lang/cem/cemcom/Makefile.erik index c247c546..d7f9352f 100644 --- a/lang/cem/cemcom/Makefile.erik +++ b/lang/cem/cemcom/Makefile.erik @@ -17,21 +17,23 @@ EMELIB = $(EM)/modules/lib/libeme.a STRLIB = $(EM)/modules/lib/libstr.a PRTLIB = $(EM)/modules/lib/libprint.a EMMESLIB = $(EM)/modules/lib/libem_mes.a +INPLIB = $(EM)/modules/lib/libinput.a #CH3LIB = $(EM)/modules/lib/libch3.a CH3LIB = -LIBS = $(CH3LIB) $(EMMESLIB) $(EMKLIB) $(PRTLIB) $(STRLIB) $(SYSLIB) -ELIBS = $(CH3LIB) $(EMMESLIB) $(EMELIB) $(PRTLIB) $(STRLIB) $(SYSLIB) -LIB_INCLUDES = $(EM)/modules/h -EM_INCLUDES = $(EM)/h +LIBS = $(INPLIB) $(CH3LIB) $(EMMESLIB) $(EMKLIB) $(PRTLIB) $(STRLIB) $(SYSLIB) +ELIBS = $(INPLIB) $(CH3LIB) $(EMMESLIB) $(EMELIB) $(PRTLIB) $(STRLIB) $(SYSLIB) +LIB_INCLUDES = -I$(EM)/modules/h -I$(EM)/modules/pkg +EM_INCLUDES = -I$(EM)/h SYSLLIB = $(EM)/modules/lib/llib-lsys.ln EMKLLIB = $(EM)/modules/lib/llib-lemk.ln EMELLIB = $(EM)/modules/lib/llib-leme.ln STRLLIB = $(EM)/modules/lib/llib-lstr.ln PRTLLIB = $(EM)/modules/lib/llib-lprint.ln EMMESLLIB = $(EM)/modules/lib/llib-lmes.ln +INPLLIB = $(EM)/modules/lib/llib-linput.ln CH3LLIB = $(EM)/modules/lib/llib-lch3.ln LINTLIBS = -#LINTLIBS = $(CH3LLIB) $(EMMESLLIB) $(EMKLLIB) $(PRTLLIB) $(STRLLIB) $(SYSLLIB) +#LINTLIBS = $(CH3LLIB) $(INPLLIB) $(EMMESLLIB) $(EMKLLIB) $(PRTLLIB) $(STRLLIB) $(SYSLLIB) # Where to install the compiler and its driver CEMCOM = $(DESTINATION)/cemcom @@ -48,7 +50,7 @@ GEN = $(EM)/bin/LLgen GENOPTIONS = -vv # Special #defines during compilation -CDEFS = $(MAP) -I$(EM_INCLUDES) -I$(LIB_INCLUDES) +CDEFS = $(MAP) $(EM_INCLUDES) $(LIB_INCLUDES) CFLAGS = $(CDEFS) $(COPTIONS) -O# # we cannot pass the COPTIONS to lint! # Grammar files and their objects @@ -77,7 +79,7 @@ GSRC = char.c symbol2str.c next.c \ GHSRC = botch_free.h dataflow.h debug.h density.h errout.h \ idepth.h idfsize.h ifdepth.h inputtype.h inumlength.h lapbuf.h \ maxincl.h myalloc.h nobitfield.h nofloat.h nopp.h \ - nparams.h numsize.h parbufsize.h pathlength.h predefine.h \ + nparams.h numsize.h parbufsize.h pathlength.h \ strsize.h target_sizes.h textsize.h use_tmp.h spec_arith.h static.h # Other generated files, for 'make clean' only @@ -206,47 +208,47 @@ sim: cfiles $(SIM) $(SIMFLAGS) `sources $(COBJ)` $(GSRC) $(LSRC) #AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO -LLlex.o: LLlex.h Lpars.h alloc.h arith.h assert.h class.h debug.h def.h idf.h idfsize.h input.h nofloat.h nopp.h numsize.h sizes.h spec_arith.h strsize.h -LLmessage.o: LLlex.h Lpars.h alloc.h arith.h idf.h nofloat.h nopp.h spec_arith.h -Lpars.o: Lpars.h -alloc.o: alloc.h assert.h debug.h myalloc.h -arith.o: Lpars.h alloc.h arith.h botch_free.h expr.h field.h idf.h label.h mes.h nobitfield.h nofloat.h nopp.h spec_arith.h storage.h type.h -blocks.o: arith.h atw.h nofloat.h sizes.h spec_arith.h -ch7.o: Lpars.h arith.h assert.h debug.h def.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h struct.h type.h -ch7bin.o: Lpars.h arith.h botch_free.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h storage.h struct.h type.h -ch7mon.o: Lpars.h arith.h botch_free.h def.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h storage.h type.h -char.o: class.h -code.o: LLlex.h Lpars.h alloc.h arith.h assert.h atw.h botch_free.h code.h dataflow.h debug.h declar.h decspecs.h def.h expr.h idf.h label.h level.h mes.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h specials.h stack.h stmt.h storage.h type.h use_tmp.h -conversion.o: Lpars.h arith.h nobitfield.h nofloat.h sizes.h spec_arith.h type.h -cstoper.o: Lpars.h arith.h assert.h debug.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h target_sizes.h type.h -dataflow.o: dataflow.h -declar.o: LLlex.h Lpars.h arith.h debug.h declar.h decspecs.h def.h expr.h field.h idf.h label.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h storage.h struct.h type.h +main.o: LLlex.h Lpars.h alloc.h arith.h debug.h declar.h file_info.h idf.h input.h inputtype.h level.h maxincl.h myalloc.h nobitfield.h nofloat.h nopp.h spec_arith.h specials.h target_sizes.h tokenname.h type.h use_tmp.h +idf.o: LLlex.h Lpars.h align.h alloc.h arith.h assert.h botch_free.h debug.h declar.h decspecs.h def.h file_info.h idf.h idfsize.h label.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h specials.h stack.h storage.h struct.h type.h declarator.o: Lpars.h alloc.h arith.h botch_free.h declar.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h storage.h type.h decspecs.o: Lpars.h arith.h decspecs.h def.h level.h nobitfield.h nofloat.h spec_arith.h type.h -domacro.o: LLlex.h Lpars.h alloc.h arith.h assert.h botch_free.h class.h debug.h idf.h idfsize.h ifdepth.h input.h interface.h macro.h nofloat.h nopp.h nparams.h parbufsize.h spec_arith.h storage.h textsize.h +struct.o: LLlex.h Lpars.h align.h arith.h assert.h botch_free.h debug.h def.h field.h file_info.h idf.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h stack.h storage.h struct.h type.h +expr.o: LLlex.h Lpars.h alloc.h arith.h botch_free.h declar.h decspecs.h def.h expr.h file_info.h idf.h label.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h storage.h type.h +ch7.o: Lpars.h arith.h assert.h debug.h def.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h struct.h type.h +ch7bin.o: Lpars.h arith.h botch_free.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h storage.h struct.h type.h +cstoper.o: Lpars.h arith.h assert.h debug.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h target_sizes.h type.h +arith.o: Lpars.h alloc.h arith.h botch_free.h expr.h field.h idf.h label.h mes.h nobitfield.h nofloat.h nopp.h spec_arith.h storage.h type.h +alloc.o: alloc.h assert.h debug.h myalloc.h +code.o: LLlex.h Lpars.h alloc.h arith.h assert.h atw.h botch_free.h code.h dataflow.h debug.h declar.h decspecs.h def.h expr.h file_info.h idf.h label.h level.h mes.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h specials.h stack.h stmt.h storage.h type.h use_tmp.h dumpidf.o: Lpars.h arith.h debug.h def.h expr.h field.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h stack.h static.h struct.h type.h -error.o: LLlex.h arith.h debug.h errout.h expr.h label.h nofloat.h nopp.h spec_arith.h tokenname.h use_tmp.h -eval.o: Lpars.h align.h arith.h assert.h atw.h code.h dataflow.h debug.h def.h expr.h idf.h label.h level.h mes.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h stack.h type.h -expr.o: LLlex.h Lpars.h alloc.h arith.h botch_free.h declar.h decspecs.h def.h expr.h idf.h label.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h storage.h type.h -expression.o: LLlex.h Lpars.h arith.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h +error.o: LLlex.h arith.h debug.h errout.h expr.h file_info.h label.h nofloat.h nopp.h spec_arith.h tokenname.h use_tmp.h field.o: Lpars.h arith.h assert.h code.h debug.h expr.h field.h idf.h label.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h type.h -idf.o: LLlex.h Lpars.h align.h alloc.h arith.h assert.h botch_free.h debug.h declar.h decspecs.h def.h idf.h idfsize.h label.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h specials.h stack.h storage.h struct.h type.h -init.o: alloc.h class.h idf.h interface.h macro.h nopp.h predefine.h -input.o: LLlex.h alloc.h arith.h assert.h debug.h idepth.h input.h inputtype.h interface.h nofloat.h nopp.h pathlength.h spec_arith.h static.h -ival.o: Lpars.h align.h arith.h assert.h class.h debug.h def.h expr.h field.h idf.h label.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h struct.h type.h -label.o: Lpars.h arith.h def.h idf.h label.h level.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h -main.o: LLlex.h Lpars.h alloc.h arith.h debug.h declar.h idf.h input.h inputtype.h level.h maxincl.h myalloc.h nobitfield.h nofloat.h nopp.h spec_arith.h specials.h target_sizes.h tokenname.h type.h use_tmp.h +tokenname.o: LLlex.h Lpars.h arith.h file_info.h idf.h nofloat.h nopp.h spec_arith.h tokenname.h +LLlex.o: LLlex.h Lpars.h alloc.h arith.h assert.h class.h debug.h def.h file_info.h idf.h idfsize.h input.h nofloat.h nopp.h numsize.h sizes.h spec_arith.h strsize.h +LLmessage.o: LLlex.h Lpars.h alloc.h arith.h file_info.h idf.h nofloat.h nopp.h spec_arith.h +input.o: file_info.h input.h inputtype.h nopp.h +domacro.o: LLlex.h Lpars.h alloc.h arith.h assert.h botch_free.h class.h debug.h file_info.h idf.h idfsize.h ifdepth.h input.h interface.h macro.h nofloat.h nopp.h nparams.h parbufsize.h spec_arith.h storage.h textsize.h +replace.o: LLlex.h alloc.h arith.h assert.h class.h debug.h file_info.h idf.h input.h interface.h macro.h nofloat.h nopp.h pathlength.h spec_arith.h static.h strsize.h +init.o: alloc.h class.h idf.h interface.h macro.h nopp.h options.o: align.h arith.h class.h idf.h idfsize.h macro.h maxincl.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h storage.h use_tmp.h -program.o: LLlex.h Lpars.h alloc.h arith.h code.h declar.h decspecs.h def.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h -replace.o: LLlex.h alloc.h arith.h assert.h class.h debug.h idf.h input.h interface.h macro.h nofloat.h nopp.h pathlength.h spec_arith.h static.h strsize.h scan.o: class.h idf.h input.h interface.h lapbuf.h macro.h nopp.h nparams.h -skip.o: LLlex.h arith.h class.h input.h interface.h nofloat.h nopp.h spec_arith.h +skip.o: LLlex.h arith.h class.h file_info.h input.h interface.h nofloat.h nopp.h spec_arith.h stack.o: Lpars.h alloc.h arith.h botch_free.h debug.h def.h idf.h level.h mes.h nobitfield.h nofloat.h nopp.h spec_arith.h stack.h storage.h struct.h type.h use_tmp.h -statement.o: LLlex.h Lpars.h arith.h botch_free.h code.h debug.h def.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h stack.h storage.h type.h -storage.o: alloc.h assert.h botch_free.h debug.h storage.h -struct.o: LLlex.h Lpars.h align.h arith.h assert.h botch_free.h debug.h def.h field.h idf.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h stack.h storage.h struct.h type.h -switch.o: Lpars.h arith.h assert.h botch_free.h code.h debug.h density.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h storage.h switch.h type.h -symbol2str.o: Lpars.h -tokenfile.o: Lpars.h -tokenname.o: LLlex.h Lpars.h arith.h idf.h nofloat.h nopp.h spec_arith.h tokenname.h type.o: Lpars.h align.h alloc.h arith.h def.h idf.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h storage.h type.h +ch7mon.o: Lpars.h arith.h botch_free.h def.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h storage.h type.h +label.o: Lpars.h arith.h def.h idf.h label.h level.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h +eval.o: Lpars.h align.h arith.h assert.h atw.h code.h dataflow.h debug.h def.h expr.h idf.h label.h level.h mes.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h stack.h type.h +switch.o: Lpars.h arith.h assert.h botch_free.h code.h debug.h density.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h storage.h switch.h type.h +storage.o: alloc.h assert.h botch_free.h debug.h storage.h +ival.o: Lpars.h align.h arith.h assert.h class.h debug.h def.h expr.h field.h idf.h label.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h struct.h type.h +conversion.o: Lpars.h arith.h nobitfield.h nofloat.h sizes.h spec_arith.h type.h +blocks.o: arith.h atw.h label.h nofloat.h sizes.h spec_arith.h stack.h +dataflow.o: dataflow.h +tokenfile.o: Lpars.h +declar.o: LLlex.h Lpars.h arith.h debug.h declar.h decspecs.h def.h expr.h field.h file_info.h idf.h label.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h storage.h struct.h type.h +statement.o: LLlex.h Lpars.h arith.h botch_free.h code.h debug.h def.h expr.h file_info.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h stack.h storage.h type.h +expression.o: LLlex.h Lpars.h arith.h expr.h file_info.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h +program.o: LLlex.h Lpars.h alloc.h arith.h code.h declar.h decspecs.h def.h expr.h file_info.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h +Lpars.o: Lpars.h +char.o: class.h +symbol2str.o: Lpars.h diff --git a/lang/cem/cemcom/Parameters b/lang/cem/cemcom/Parameters index 6de92789..5466fb21 100644 --- a/lang/cem/cemcom/Parameters +++ b/lang/cem/cemcom/Parameters @@ -42,10 +42,6 @@ #define DENSITY 2 /* see switch.[ch] for an explanation */ -!File: predefine.h -#define PREDEFINE "vax,VAX,BSD4_1,bsd4_1" - - !File: lapbuf.h #define LAPBUF 4096 /* size of macro actual parameter buffer */ @@ -115,7 +111,7 @@ !File: inputtype.h -#undef READ_IN_ONE 1 /* read input file in one */ +#undef INP_READ_IN_ONE 1 /* read input file in one */ !File: nopp.h diff --git a/lang/cem/cemcom/domacro.c b/lang/cem/cemcom/domacro.c index b3d32151..fe2f9f1e 100644 --- a/lang/cem/cemcom/domacro.c +++ b/lang/cem/cemcom/domacro.c @@ -24,6 +24,7 @@ #include "storage.h" IMPORT char *inctable[]; /* list of include directories */ +IMPORT char *getwdir(); PRIVATE char ifstack[IFDEPTH]; /* if-stack: the content of an entry is */ /* 1 if a corresponding ELSE has been */ /* encountered. */ @@ -223,6 +224,7 @@ do_include() /* do_include() performs the inclusion of a file. */ char *filenm; + char *result; int tok; struct token tk; @@ -235,8 +237,17 @@ do_include() } AccFileSpecifier = 0; SkipRestOfLine(); - if (filenm && !InsertFile(filenm, &inctable[tok == FILESPECIFIER])) - lexerror("cannot find include file \"%s\"", filenm); + inctable[0] = WorkingDir; + if (filenm) { + if (!InsertFile(filenm, &inctable[tok==FILESPECIFIER],&result)){ + lexerror("cannot find include file \"%s\"", filenm); + } + else { + WorkingDir = getwdir(result); + FileName = result; + LineNumber = 0; + } + } } PRIVATE @@ -341,35 +352,31 @@ do_if() PRIVATE do_ifdef(how) { - struct idf *id; + register struct idf *id; /* how == 1 : ifdef; how == 0 : ifndef */ push_if(); - if (id = GetIdentifier()) { - if ( - (how && !(id && id->id_macro)) - || - (!how && id && id->id_macro) - ) /* this id is not defined */ - skip_block(); - else - SkipRestOfLine(); - } - else { + if (!(id = GetIdentifier())) lexerror("illegal #ifdef construction"); + + /* The next test is a shorthand for: + (how && !id->id_macro) || (!how && id->id_macro) + */ + if (how ^ (id && id->id_macro != 0)) + skip_block(); + else SkipRestOfLine(); - } } PRIVATE do_undef() { - struct idf *id; + register struct idf *id; /* Forget a macro definition. */ if (id = GetIdentifier()) { - if (id && id->id_macro) { /* forget the macro */ + if (id->id_macro) { /* forget the macro */ free_macro(id->id_macro); id->id_macro = (struct macro *) 0; } /* else: don't complain */ @@ -406,14 +413,15 @@ getparams(buf, parbuf) Note that the '(' has already been eaten. The names of the formal parameters are stored into parbuf. */ - register count = 0; - register c; + register char **pbuf = &buf[0]; + register int c; register char *ptr = &parbuf[0]; + register char **pbuf2; LoadChar(c); c = skipspaces(c); if (c == ')') { /* no parameters: #define name() */ - buf[0] = (char *) 0; + *pbuf = (char *) 0; return 0; } for (;;) { /* eat the formal parameter list */ @@ -421,7 +429,7 @@ getparams(buf, parbuf) lexerror("#define: bad formal parameter"); return -1; } - buf[count++] = ptr; /* name of the formal */ + *pbuf = ptr; /* name of the formal */ *ptr++ = c; if (ptr >= &parbuf[PARBUFSIZE]) fatal("formal parameter buffer overflow"); @@ -432,10 +440,22 @@ getparams(buf, parbuf) fatal("formal parameter buffer overflow"); } while (in_idf(c)); *(ptr - 1) = '\0'; /* mark end of the name */ + + /* Check if this formal parameter is already used. + Usually, macros do not have many parameters, so ... + */ + for (pbuf2 = pbuf - 1; pbuf2 >= &buf[0]; pbuf2--) { + if (!strcmp(*pbuf2, *pbuf)) { + warning("formal parameter \"%s\" already used", + *pbuf); + } + } + + pbuf++; c = skipspaces(c); if (c == ')') { /* end of the formal parameter list */ - buf[count] = (char *) 0; - return count; + *pbuf = (char *) 0; + return pbuf - buf; } if (c != ',') { lexerror("#define: bad formal parameter list"); @@ -444,11 +464,12 @@ getparams(buf, parbuf) LoadChar(c); c = skipspaces(c); } + /*NOTREACHED*/ } EXPORT macro_def(id, text, nformals, length, flags) - struct idf *id; + register struct idf *id; char *text; { register struct macro *newdef = id->id_macro; @@ -456,15 +477,12 @@ macro_def(id, text, nformals, length, flags) /* macro_def() puts the contents and information of a macro definition into a structure and stores it into the symbol table entry belonging to the name of the macro. - A warning is given if the definition overwrites another - (unless predefined!) + A warning is given if the definition overwrites another. */ if (newdef) { /* is there a redefinition? */ - if ((newdef->mc_flag & PREDEF) == 0) { - if (macroeq(newdef->mc_text, text)) - return; - lexwarning("redefine \"%s\"", id->id_text); - } /* else: overwrite pre-definition */ + if (macroeq(newdef->mc_text, text)) + return; + lexwarning("redefine \"%s\"", id->id_text); } else id->id_macro = newdef = new_macro(); @@ -472,6 +490,7 @@ macro_def(id, text, nformals, length, flags) newdef->mc_nps = nformals; /* nr of formals */ newdef->mc_length = length; /* length of repl. text */ newdef->mc_flag = flags; /* special flags */ + newdef->mc_count = 0; } PRIVATE int diff --git a/lang/cem/cemcom/file_info.h b/lang/cem/cemcom/file_info.h new file mode 100644 index 00000000..1cb1db03 --- /dev/null +++ b/lang/cem/cemcom/file_info.h @@ -0,0 +1,14 @@ +/* $Header$ */ +/* F I L E I N F O R M A T I O N S T R U C T U R E */ + +struct file_info { + unsigned int fil_lino; + char *fil_name; + char *fil_wdir; +}; + +#define LineNumber finfo.fil_lino +#define FileName finfo.fil_name +#define WorkingDir finfo.fil_wdir + +extern struct file_info finfo; /* input.c */ diff --git a/lang/cem/cemcom/init.c b/lang/cem/cemcom/init.c index 2c0b6a6c..20c120e2 100644 --- a/lang/cem/cemcom/init.c +++ b/lang/cem/cemcom/init.c @@ -5,7 +5,6 @@ #ifndef NOPP #include -#include "predefine.h" /* UF */ #include "alloc.h" #include "class.h" #include "macro.h" @@ -57,10 +56,7 @@ init_pp() } /* Initialize __DATE__, __FILE__ and __LINE__ macro - definitions. The compile-time specified predefined macros - are also predefined: if this file is compiled with - -DPREDEFINE="vax,pdp", the macro definitions "vax" and - "pdp" are predefined macros. + definitions. */ /* __DATE__ */ clock = sys_time(); @@ -77,33 +73,5 @@ init_pp() /* defined(??) */ macro_def(str2idf("defined"), "", 1, 1, FUNC); - -#ifdef PREDEFINE - { - /* PREDEFINE is a compile-time defined string - containing a number of identifiers to be - predefined at the host machine (for example - -DPREDEFINE="vax,unix,pmds"). - */ - register char *s = PREDEFINE; - register char *id; - char c; - - for (;;) { - while (*s && class(*s++) != STIDF); - if (*s) { - /* gobble identifier */ - id = s - 1; - while (in_idf(*s++)); - c = *--s; - *s = '\0'; - macro_def(str2idf(id), "1", -1, 1, PREDEF); - *s = c; - } - else - break; - } - } -#endif PREDEFINE } #endif NOPP diff --git a/lang/cem/cemcom/input.c b/lang/cem/cemcom/input.c index fd6de239..c3625037 100644 --- a/lang/cem/cemcom/input.c +++ b/lang/cem/cemcom/input.c @@ -1,427 +1,18 @@ /* $Header$ */ -/* INPUT AND BUFFER HANDLING MODULE */ -/* - [input.c input.h] - Input buffering module: this module contains the routines that - offers an input buffering mechanism to the user. - - This module exports the following objects: - InsertFile() : suspend input from current buffer and obtain the - next input characters from the specified file - InsertText() : suspend input from current buffer and take the - specified text as stream of input characters - LoadChar() : (defined in input.h) read next character from - the input ; LoadChar() invokes loadbuf() on - encounting a ASCII NUL character - NoUnstack : if set to non-zero: - loadbuf() reports "unexpected EOF" on encounting - the end-of-file or end-of-stacked-text. - - Imported objects are: - IDEPTH, DEBUG, READ_IN_ONE, PATHLENGTH: compile-time parameters - Malloc(), Salloc(): memory allocation routines - fatal(), lexerror(): exception handling - FileName, LineNumber, WorkingDir: input trace for lexical analyser - - READ_IN_ONE DEFINED: every input file is read into memory completely - and made an input buffer - READ_IN_ONE NOT DEFINED: the input from files is buffered in - a fixed length input buffer -*/ - -#include -#include "nopp.h" -#include "inputtype.h" -#include "interface.h" -#include "arith.h" -#include "LLlex.h" -#include "input.h" -#include "alloc.h" +#include "inputtype.h" +#include "file_info.h" +#include "input.h" +#define INP_TYPE struct file_info +#define INP_VAR finfo +struct file_info finfo; +#include +#include "nopp.h" #ifndef NOPP -#include "idepth.h" -#include "debug.h" -#include "pathlength.h" -#include "assert.h" -#include "static.h" -#endif NOPP - -EXPORT char *ipp = 0; /* input pointer */ -EXPORT int NoUnstack = 0; /* if 1: report EOF */ - -#ifndef READ_IN_ONE -PRIVATE File *FilDes = 0; /* current input medium */ -#endif READ_IN_ONE - -#ifndef NOPP -struct buffer_header { - char *bh_name; /* file name where the text comes from */ - unsigned int bh_lineno; - /* current lineno in file */ - long bh_size; /* = strlen (text), should be unsigned */ - char *bh_text; /* pointer to buffer containing text */ - char *bh_ipp; /* current read pointer (= stacked ipp) */ - char *bh_wdir; /* directory of current file */ - File *bh_fp; /* needed for files if !READ_IN_ONE */ -}; - -PRIVATE struct buffer_header instack[IDEPTH]; /* stack of input media */ -PRIVATE struct buffer_header *head = 0; /* current input buffer */ - -IMPORT char **WorkingDir; /* name of current working directory */ -#else NOPP -long isize; -char ibuf[BUFSIZ + 1]; -#endif NOPP - -#ifdef READ_IN_ONE -/* readfile() creates a buffer in which the text of the file - is situated. A pointer to the start of this text is - returned. *size is initialized with the buffer length. - Note that the file input buffer is prepared for the - preprocessor by inserting a '\n' in the beginning of the - text and appending a '\n' at the end of the text. The - file text start at position 1 of the input buffer. This is - done to allow pushback. -*/ - -PRIVATE char * -readfile(filename, size) - char *filename; - long *size; -{ - File *fp; /* filedescriptor for `filename' */ - char *cbuf; /* pointer to buffer to be returned */ - int tmp; - long sys_filesize(); - - if (sys_open(filename, OP_READ, &fp) == 0) /* can't open this file */ - return (char *) 0; - if ((*size = sys_filesize(filename)) == -1L) - fatal("(readfile) cannot get size of file"); - /* allocate enough space to store contents of the file */ - cbuf = Malloc(*size + 2); - if (sys_read(fp, cbuf + 1, (int) *size, &tmp) == 0 || tmp != *size) - fatal("(readfile) bad read"); - (*size)++; /* keep book of the size! */ - sys_close(fp); /* filedes no longer needed */ - cbuf[0] = '\0'; /* allow pushback of first char */ - cbuf[*size] = '\0'; /* invoke loadbuf() at end */ - return cbuf; -} -#endif READ_IN_ONE - -#ifndef NOPP -#ifndef READ_IN_ONE -/* Input buffer supplying routines: pushbuf() and popbuf() -*/ -PRIVATE char *bufstack[IDEPTH] = 0; -PRIVATE bufstptr = 0; - -PRIVATE char * -pushbuf() -{ - if (bufstptr >= IDEPTH) - fatal("ran out of input buffers"); - if (bufstack[bufstptr] == 0) { - bufstack[bufstptr] = Malloc(BUFSIZ + 4); - } - return bufstack[bufstptr++]; -} - -PRIVATE -popbuf() -{ - bufstptr--; - ASSERT(bufstptr >= 0); -} -#endif READ_IN_ONE -#endif NOPP - -#ifndef NOPP -/* Input buffer administration: push_bh() and pop_bh() -*/ -PRIVATE struct buffer_header * -push_bh() -{ - if (head) { - if (head >= &instack[IDEPTH - 1]) - fatal("too many nested input texts"); - head->bh_ipp = ipp; - head->bh_lineno = LineNumber; - head++; - } - else - head = &instack[0]; - - return head; -} -#endif NOPP - -#ifndef NOPP -/* pop_bh() uncovers the previous inputbuffer on the stack - of headers. 0 is returned if there are no more - inputbuffers on the stack, 1 is returned in the other case. -*/ -PRIVATE int -pop_bh() -{ - File *pfp = head->bh_fp; - - if (NoUnstack) { - lexerror("unexpected EOF"); - } - - if (head <= &instack[0]) { /* no more entries */ - head = (struct buffer_header *) 0; - return 0; - } - - ipp = (--head)->bh_ipp; /* restore the previous input pointer */ - - if (pfp != 0) { /* unstack a file */ -#ifndef READ_IN_ONE - closefile(pfp); - popbuf(); /* free last buffer */ -#endif READ_IN_ONE - LineNumber = head->bh_lineno; - FileName = head->bh_name; - *WorkingDir = head->bh_wdir; - } - -#ifndef READ_IN_ONE - FilDes = head->bh_fp; -#endif READ_IN_ONE - - return 1; -} -#endif NOPP - -#ifndef READ_IN_ONE -/* low level IO routines: openfile(), readblock() and closefile() -*/ - -PRIVATE File * -openfile(filename) - char *filename; -{ - File *fp; - - if (filename == 0) - return STDIN; - if (sys_open(filename, OP_READ, &fp) == 0) - return (File *)0; - return fp; -} - -PRIVATE -closefile(fp) - File *fp; -{ - if (fp != STDIN) - sys_close(fp); -} - -PRIVATE int -readblock(fp, buf) - File *fp; - char buf[]; -{ - int n; - - if (sys_read(fp, &buf[1], BUFSIZ, &n) == 0) - fatal("(readblock) bad read"); - buf[0] = buf[n + 1] = '\0'; - return n; -} -#endif READ_IN_ONE - -/* Interface routines : InsertFile(), InsertText() and loadbuf() -*/ - -EXPORT int -InsertFile(filnam, table) - char *filnam; - char *table[]; -{ - char *mk_filename(), *newfn; - char *strcpy(); - File *openfile(); - -#ifdef READ_IN_ONE - char *readfile(), *text; - long size; -#else READ_IN_ONE - File *fp = 0; -#endif READ_IN_ONE - -#ifdef READ_IN_ONE - if (!filnam) - return 0; -#endif READ_IN_ONE - -#ifndef NOPP - if (table == 0 || filnam[0] == '/') { /* don't look in the table! */ -#endif NOPP -#ifdef READ_IN_ONE - text = readfile(filnam, &size); -#else READ_IN_ONE - fp = openfile(filnam); - if (filnam == 0) - filnam = "standard input"; -#endif READ_IN_ONE -#ifndef NOPP - } - else { - ASSERT(filnam != 0); - while (*table) { /* look in the directory table */ - newfn = mk_filename(*table++, filnam); -#ifdef READ_IN_ONE - if (text = readfile(newfn, &size)) -#else READ_IN_ONE - if ((fp = openfile(newfn)) != 0) -#endif READ_IN_ONE - { - /* free filnam ??? */ - filnam = Salloc(newfn, strlen(newfn) + 1); - break; - } - } - } -#endif NOPP - -#ifdef READ_IN_ONE - if (text) -#else READ_IN_ONE - if (fp != 0) -#endif READ_IN_ONE -#ifndef NOPP - { - struct buffer_header *push_bh(); - register struct buffer_header *bh = push_bh(); - - setwdir(WorkingDir, filnam); - bh->bh_lineno = LineNumber = 0; - bh->bh_name = FileName = filnam; - bh->bh_wdir = *WorkingDir; -#ifdef READ_IN_ONE - bh->bh_size = size; - bh->bh_fp = STDIN; /* this is a file */ - ipp = bh->bh_text = text; -#else READ_IN_ONE - bh->bh_size = readblock(fp, ipp = bh->bh_text = pushbuf()) + 1; - FilDes = bh->bh_fp = fp; -#endif READ_IN_ONE - bh->bh_text[0] = '\n'; /* wake up pp if '#' comes first */ - return 1; - } -#else NOPP - { - LineNumber = 0; - FileName = filnam; -#ifdef READ_IN_ONE - isize = size; - ipp = text; -#else READ_IN_ONE - isize = readblock(FilDes = fp, ipp = &ibuf[0]) + 1; -#endif READ_IN_ONE - ibuf[0] = '\n'; - return 1; - } -#endif NOPP - return 0; -} - -#ifndef NOPP -EXPORT -InsertText(text, length) - char *text; -{ - struct buffer_header *push_bh(); - register struct buffer_header *bh = push_bh(); - - bh->bh_name = FileName; - bh->bh_lineno = LineNumber; - bh->bh_size = (long) length; - bh->bh_text = text; - bh->bh_wdir = *WorkingDir; - bh->bh_fp = 0; /* this is not a file ! */ - ipp = text + 1; -#ifndef READ_IN_ONE - FilDes = 0; -#endif READ_IN_ONE -} -#endif NOPP - -/* loadbuf() is called if LoadChar meets a '\0' character - which may be the end-of-buffer mark of the current input - buffer. The '\0' could be genuine although not likely. - Note: this routine is exported due to its occurence in the definition - of LoadChar [input.h], that is defined as a macro. -*/ -EXPORT int -loadbuf() -{ -#ifndef NOPP - if (!head) /* stack exhausted, EOF on sourcefile */ - return EOI; -#endif NOPP - -#ifndef NOPP - if (ipp < &(head->bh_text[head->bh_size])) -#else NOPP - if (ipp < &ibuf[isize]) -#endif NOPP - return '\0'; /* a genuine '\0' character has been seen */ - -#ifndef READ_IN_ONE -#ifndef NOPP - if ( FilDes != 0 - && (head->bh_size = readblock(FilDes, head->bh_text)) > 0 - ) - return ipp = &(head->bh_text[1]), *ipp++; -#else NOPP - if (FilDes != 0 && (isize = readblock(FilDes, &ibuf[0])) > 0) - return ipp = &ibuf[1], *ipp++; -#endif NOPP -#endif READ_IN_ONE - -#ifdef NOPP - if (NoUnstack) - lexerror("unexpected EOF"); -#ifndef READ_IN_ONE - closefile(FilDes); -#endif READ_IN_ONE -#endif NOPP - -#ifndef NOPP - if (pop_bh()) - return *ipp ? *ipp++ : loadbuf(); -#endif NOPP - ipp = &"\0\0"[1]; - return EOI; -} - -/* Some miscellaneous routines : setwdir() and mk_filename() -*/ - -#ifndef NOPP -/* setwdir() updates *wdir according to the old working - directory (*wdir) and the filename fn, which may contain - some path name. The algorithm used here is: - setwdir(DIR, FILE): - if (FILE == "/***") - *DIR = "/" - else - if (contains(FILE, '/')) - *DIR = directory(FILE) - else - *DIR remains unchanged -*/ -PRIVATE -setwdir(wdir, fn) - char *fn, **wdir; +char * +getwdir(fn) + char *fn; { register char *p; char *strrindex(); @@ -433,32 +24,31 @@ setwdir(wdir, fn) } if (fn[0] == '\0' || (fn[0] == '/' && p == &fn[0])) /* absolute path */ - *wdir = "/"; + return ""; else if (p) { *p = '\0'; - *wdir = Salloc(fn, p - &fn[0] + 1); + fn = Salloc(fn, p - &fn[0] + 1); *p = '/'; + return fn; } + else return "."; } #endif NOPP -#ifndef NOPP -/* mk_filename() concatenates a dir and filename. -*/ -GSTATIC char path[PATHLENGTH]; +int NoUnstack; -PRIVATE char * -mk_filename(dir, file) - register char *dir, *file; +AtEoIT() { - register char *dst = &path[0]; - - if (!(dir[0] == '.' && dir[1] == '\0')) { - while (*dst++ = *dir++); - *(dst - 1) = '/'; - } - while (*dst++ = *file++); - return &path[0]; -} +#ifndef NOPP + if (NoUnstack) lexerror("unexpected EOF"); + DoUnstack(); #endif NOPP + return 0; +} + +AtEoIF() +{ + if (NoUnstack) lexerror("unexpected EOF"); + return 0; +} diff --git a/lang/cem/cemcom/input.h b/lang/cem/cemcom/input.h index 11185622..aa22fff0 100644 --- a/lang/cem/cemcom/input.h +++ b/lang/cem/cemcom/input.h @@ -1,13 +1,3 @@ /* $Header$ */ -/* INPUT PRIMITIVES */ -#define LoadChar(dest) ((dest = *ipp++) || (dest = loadbuf())) -#define PushBack() (ipp--) - -/* EOF may be defined as -1 in most programs but the character -1 may - be expanded to the int -1 which causes troubles at the indexing in - the class or boolean arrays. -*/ -#define EOI (0200) - -extern char *ipp; +#include diff --git a/lang/cem/cemcom/macro.str b/lang/cem/cemcom/macro.str index 34a62dd5..ef324327 100644 --- a/lang/cem/cemcom/macro.str +++ b/lang/cem/cemcom/macro.str @@ -9,7 +9,7 @@ */ #define NOFLAG 0 /* no special flags */ #define FUNC 01 /* function attached */ -#define PREDEF 02 /* predefined macro */ +#define NOREPLACE 02 /* don't replace */ #define FORMALP 0200 /* mask for creating macro formal parameter */ @@ -21,8 +21,9 @@ struct macro { struct macro *next; char * mc_text; /* the replacement text */ - int mc_nps; /* number of formal parameters */ + int mc_nps; /* number of formal parameters */ int mc_length; /* length of replacement text */ + int mc_count; /* # of "concurrent" invocations*/ char mc_flag; /* marking this macro */ }; diff --git a/lang/cem/cemcom/main.c b/lang/cem/cemcom/main.c index b9fa6917..28d67c2b 100644 --- a/lang/cem/cemcom/main.c +++ b/lang/cem/cemcom/main.c @@ -34,7 +34,7 @@ char *inctable[MAXINCL] = { /* list for includes */ 0 }; -char **WorkingDir = &inctable[0]; +extern char *getwdir(); #endif NOPP struct sp_id special_ids[] = { @@ -90,19 +90,17 @@ main(argc, argv) #endif NOPP /* Note: source file "-" indicates that the source is supplied - as standard input. This is only allowed if READ_IN_ONE is + as standard input. This is only allowed if INP_READ_IN_ONE is not defined! */ -#ifdef READ_IN_ONE +#ifdef INP_READ_IN_ONE while (argc > 1 && *argv[1] == '-') -#else READ_IN_ONE +#else INP_READ_IN_ONE while (argc > 1 && *argv[1] == '-' && argv[1][1] != '\0') -#endif READ_IN_ONE +#endif INP_READ_IN_ONE { char *par = &argv[1][1]; - if (*par == '-') - par++; do_option(par); argc--, argv++; } @@ -139,6 +137,7 @@ compile(argc, argv) #ifdef USE_TMP char tmpf[256]; #endif + char *result; #ifndef NOPP int pp_only = options['E'] || options['P']; @@ -172,11 +171,15 @@ compile(argc, argv) if (destination && strcmp(destination, "-") == 0) destination = 0; - if (!InsertFile(source, (char **) 0)) /* read the source file */ + if (!InsertFile(source, (char **) 0, &result)) /* read the source file */ fatal("%s: no source file %s\n", prog_name, source ? source : "stdin"); init(); - /* FileName = source; /* needed ??? */ + FileName = source; + LineNumber = 0; +#ifndef NOPP + WorkingDir = getwdir(source); +#endif NOPP PushLex(); #ifndef NOPP diff --git a/lang/cem/cemcom/options.c b/lang/cem/cemcom/options.c index d862e0f7..38525c0f 100644 --- a/lang/cem/cemcom/options.c +++ b/lang/cem/cemcom/options.c @@ -34,7 +34,10 @@ do_option(text) switch(*text++) { default: - options[text[-1]] = 1; /* flags, debug options etc. */ + fatal("illegal option: %c", *--text); + + case '-': + options[*text] = 1; /* flags, debug options etc. */ break; case 'C' : /* E option + comment output */ @@ -105,6 +108,7 @@ do_option(text) new = tmp; } } + else inctable[inc_pos] = 0; #else NOPP warning("-I option ignored"); #endif NOPP @@ -135,6 +139,10 @@ do_option(text) #endif NOPP break; + case 'R': + options['R'] = 1; + break; + #ifdef USE_TMP case 'T' : if (*text) diff --git a/lang/cem/cemcom/replace.c b/lang/cem/cemcom/replace.c index 21c98c06..169f0a16 100644 --- a/lang/cem/cemcom/replace.c +++ b/lang/cem/cemcom/replace.c @@ -21,9 +21,11 @@ char *strcpy(), *strcat(); char *long2str(); +PRIVATE struct macro *ReplaceList; /* list of currently active macros */ + EXPORT int replace(idef) - struct idf *idef; + register struct idf *idef; { /* replace() is called by the lexical analyzer to perform macro replacement. "idef" is the description of the @@ -34,14 +36,18 @@ replace(idef) replace() returns 1 if the replacement succeeded and 0 if some error has occurred. */ + register struct macro *mac = idef->id_macro; register char c; - register char flags = idef->id_macro->mc_flag; char **actpars, **getactuals(); char *reptext, *macro2buffer(); int size; - if (idef->id_macro->mc_nps != -1) { /* with parameter list */ - if (flags & FUNC) { + if (mac->mc_flag & NOREPLACE) { + lexwarning("macro %s is recursive", idef->id_text); + return 0; + } + if (mac->mc_nps != -1) { /* with parameter list */ + if (mac->mc_flag & FUNC) { /* must be "defined". Unfortunately, the next assertion will not compile ... @@ -50,6 +56,12 @@ replace(idef) if (! AccDefined) return 0; } + if (++mac->mc_count > 100) { + /* 100 must be some number in Parameters */ + lexwarning("macro %s is assumed recursive", + idef->id_text); + return 0; + } LoadChar(c); c = skipspaces(c); if (c != '(') { /* no replacement if no () */ @@ -59,23 +71,27 @@ replace(idef) return 0; } actpars = getactuals(idef); /* get act.param. list */ - if (flags & FUNC) { + if (mac->mc_flag & FUNC) { struct idf *param = str2idf(*actpars); if (param->id_macro) - reptext = "\0001"; + reptext = "1"; else - reptext = "\0000"; - InsertText(reptext, 2); + reptext = "0"; + InsertText(reptext, 1); + mac->next = ReplaceList; + ReplaceList = mac; return 1; } } - if ((flags & PREDEF) && (UnknownIdIsZero == 0)) /* don't replace */ - return 0; - if (flags & FUNC) /* this macro leads to special action */ + if (mac->mc_flag & FUNC) /* this macro leads to special action */ macro_func(idef); + if (mac->mc_nps <= 0) + mac->mc_flag |= NOREPLACE; reptext = macro2buffer(idef, actpars, &size); /* create input buffer */ InsertText(reptext, size); + mac->next = ReplaceList; + ReplaceList = mac; return 1; } @@ -83,24 +99,26 @@ GSTATIC char FilNamBuf[PATHLENGTH]; PRIVATE macro_func(idef) - struct idf *idef; + register struct idf *idef; { /* macro_func() performs the special actions needed with some macros. These macros are __FILE__ and __LINE__ which replacement texts must be evaluated at the time they are used. */ + register struct macro *mac = idef->id_macro; + switch (idef->id_text[2]) { /* This switch is very blunt... */ case 'F' : /* __FILE__ */ FilNamBuf[0] = '"'; strcpy(&FilNamBuf[1], FileName); strcat(FilNamBuf, "\""); - idef->id_macro->mc_text = FilNamBuf; - idef->id_macro->mc_length = strlen(FilNamBuf); + mac->mc_text = FilNamBuf; + mac->mc_length = strlen(FilNamBuf); break; case 'L' : /* __LINE__ */ - idef->id_macro->mc_text = long2str((long)LineNumber, 10); - idef->id_macro->mc_length = 1; + mac->mc_text = long2str((long)LineNumber, 10); + mac->mc_length = 1; break; default : crash("(macro_func)"); @@ -125,10 +143,9 @@ macro2buffer(idef, actpars, siztext) */ register int size = 8; register char *text = Malloc(size); - register pos = 0; + register int pos = 0; register char *ptr = idef->id_macro->mc_text; - text[pos++] = '\0'; /* allow pushback */ while (*ptr) { if (*ptr & FORMALP) { /* non-asc formal param. mark */ register int n = *ptr++ & 0177; @@ -138,7 +155,7 @@ macro2buffer(idef, actpars, siztext) /* copy the text of the actual parameter into the replacement text */ - for (p = actpars[n - 1]; *p; p++) { + for (p = actpars[n - 1]; p && *p; p++) { text[pos++] = *p; if (pos == size) text = Srealloc(text, size += RSTRSIZE); @@ -154,4 +171,26 @@ macro2buffer(idef, actpars, siztext) *siztext = pos; return text; } + +EXPORT +DoUnstack() +{ + Unstacked++; +} + +EXPORT +EnableMacros() +{ + register struct macro *p = ReplaceList; + + ASSERT(Unstacked > 0); + while (Unstacked > 0) { + ASSERT(p != 0); + p->mc_flag &= ~NOREPLACE; + p->mc_count = 0; + p = p->next; + Unstacked--; + } + ReplaceList = p; +} #endif NOPP From 84f6c45869d27a2d5649d2a2933080776266fe8e Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 4 Dec 1986 16:35:04 +0000 Subject: [PATCH 0364/1625] Removed DUK --- mach/m68k2/as/mach0.c | 3 --- mach/m68k2/as/mach4.c | 4 ---- mach/m68k2/as/mach5.c | 8 -------- 3 files changed, 15 deletions(-) diff --git a/mach/m68k2/as/mach0.c b/mach/m68k2/as/mach0.c index 76d1a7a0..9d254f6e 100644 --- a/mach/m68k2/as/mach0.c +++ b/mach/m68k2/as/mach0.c @@ -1,4 +1,3 @@ -#define DUK /* @(#)mach0.c 1.5 */ /* * Motorola 68000/68010 options @@ -24,5 +23,3 @@ #undef VALWIDTH #define VALWIDTH 8 - -#define NOLD /* Added by Duk Bekema. */ diff --git a/mach/m68k2/as/mach4.c b/mach/m68k2/as/mach4.c index 070a09be..c2519b25 100644 --- a/mach/m68k2/as/mach4.c +++ b/mach/m68k2/as/mach4.c @@ -21,11 +21,7 @@ operation fit(fitw($4.val)); emit2($1 | $2); #ifdef RELOCATION -#ifdef DUK newrelo($4.typ, RELPC|RELO2|RELBR|RELWR); -#else DUK - newrelo($4.typ, RELPC|RELO2); -#endif DUK #endif emit2(loww($4.val)); } diff --git a/mach/m68k2/as/mach5.c b/mach/m68k2/as/mach5.c index bec9624a..27805b44 100644 --- a/mach/m68k2/as/mach5.c +++ b/mach/m68k2/as/mach5.c @@ -37,11 +37,7 @@ ea_1(sz, bits) #ifdef RELOCATION RELOMOVE(relonami, rel_1); if (flag & ~0xFF) -#ifdef DUK newrelo(exp_1.typ, (flag>>8) | RELBR | RELWR); -#else DUK - newrelo(exp_1.typ, flag>>8); -#endif DUK #endif if (flag & PUTL) emit4(exp_1.val); @@ -361,11 +357,7 @@ expr_t exp; fit(fitw(exp.val)); emit2(opc); #ifdef RELOCATION -#ifdef DUK newrelo(exp.typ, RELPC|RELO2|RELBR|RELWR); -#else DUK - newrelo(exp.typ, RELPC|RELO2); -#endif DUK #endif emit2(loww(exp.val)); } From 237bf7d966732fd13f86cdd59cb414bbdc61c9d5 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 5 Dec 1986 16:36:40 +0000 Subject: [PATCH 0365/1625] ??? --- mach/6809/as/mach0.c | 2 -- mach/6809/as/mach4.c | 4 ++-- mach/6809/as/mach5.c | 3 ++- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/mach/6809/as/mach0.c b/mach/6809/as/mach0.c index 679af47e..2a1a0256 100644 --- a/mach/6809/as/mach0.c +++ b/mach/6809/as/mach0.c @@ -1,4 +1,3 @@ -#define DUK #define RCSID0 "$Header$" /* @@ -9,4 +8,3 @@ #define THREE_PASS #define LISTING #define RELOCATION -#define NOLD diff --git a/mach/6809/as/mach4.c b/mach/6809/as/mach4.c index 5d64544c..deb9a017 100644 --- a/mach/6809/as/mach4.c +++ b/mach/6809/as/mach4.c @@ -129,9 +129,9 @@ operation { emit1or2($1); emit1(0x9F); #ifdef RELOCATION - newrelo($3.typ, RELO1); + newrelo($3.typ, RELO2|RELBR); #endif - emit1($3.val); + emit2($3.val); } | XOP xmode diff --git a/mach/6809/as/mach5.c b/mach/6809/as/mach5.c index b820c571..9f6eab7f 100644 --- a/mach/6809/as/mach5.c +++ b/mach/6809/as/mach5.c @@ -71,11 +71,12 @@ expr_t exp; sm = fitb(dist); if ((exp.typ & S_TYP) != DOTTYP) sm = 0; - if (small(sm,0)) { + if (small(sm,1)) { emit1(0x8C + ind); emit1(dist); } else { emit1(0x8D + ind); + emit1((dist-1)>>8); emit1(dist - 1); } } else if ((reg = regno(reg)) < 0) From c411730b6b659cc1e603495a48ceee10bf34c509 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 5 Dec 1986 16:58:29 +0000 Subject: [PATCH 0366/1625] Initial revision --- mach/6805/as/mach0.c | 11 ++ mach/6805/as/mach1.c | 9 + mach/6805/as/mach2.c | 17 ++ mach/6805/as/mach3.c | 123 ++++++++++++ mach/6805/as/mach4.c | 205 ++++++++++++++++++++ mach/6805/as/mach5.c | 51 +++++ mach/ns/as/mach0.c | 21 ++ mach/ns/as/mach1.c | 113 +++++++++++ mach/ns/as/mach2.c | 59 ++++++ mach/ns/as/mach3.c | 453 +++++++++++++++++++++++++++++++++++++++++++ mach/ns/as/mach4.c | 416 +++++++++++++++++++++++++++++++++++++++ mach/ns/as/mach5.c | 311 +++++++++++++++++++++++++++++ 12 files changed, 1789 insertions(+) create mode 100644 mach/6805/as/mach0.c create mode 100644 mach/6805/as/mach1.c create mode 100644 mach/6805/as/mach2.c create mode 100644 mach/6805/as/mach3.c create mode 100644 mach/6805/as/mach4.c create mode 100644 mach/6805/as/mach5.c create mode 100644 mach/ns/as/mach0.c create mode 100644 mach/ns/as/mach1.c create mode 100644 mach/ns/as/mach2.c create mode 100644 mach/ns/as/mach3.c create mode 100644 mach/ns/as/mach4.c create mode 100644 mach/ns/as/mach5.c diff --git a/mach/6805/as/mach0.c b/mach/6805/as/mach0.c new file mode 100644 index 00000000..1d3ae708 --- /dev/null +++ b/mach/6805/as/mach0.c @@ -0,0 +1,11 @@ +#define RCSID0 "$Header$" + +/* + * Motorola 6805 options + */ + +#define BYTES_REVERSED +#define WORDS_REVERSED +#define THREE_PASS +#define LISTING +#define RELOCATION diff --git a/mach/6805/as/mach1.c b/mach/6805/as/mach1.c new file mode 100644 index 00000000..83620183 --- /dev/null +++ b/mach/6805/as/mach1.c @@ -0,0 +1,9 @@ +#define RCSID1 "$Header$" + +/* + * Motorola 6805 C declarations + */ + +extern int opt_cmos; + +#define fitj(z) ((unsigned)z + 0x80 <= 0xFF) diff --git a/mach/6805/as/mach2.c b/mach/6805/as/mach2.c new file mode 100644 index 00000000..6948f5c6 --- /dev/null +++ b/mach/6805/as/mach2.c @@ -0,0 +1,17 @@ +#define RCSID2 "$Header$" + +/* + * Motorola 6805 tokens + */ + +%token X +%token A +%token NOARG +%token BRANCH +%token BBRANCH +%token BIT +%token RMR +%token RM +%token CMOS +%type expr8 +%type bitexp diff --git a/mach/6805/as/mach3.c b/mach/6805/as/mach3.c new file mode 100644 index 00000000..58e4d1ce --- /dev/null +++ b/mach/6805/as/mach3.c @@ -0,0 +1,123 @@ +#define RCSID3 "$Header$" + +/* + * Motorola 6805 keywords + */ +/* + * The X register + */ +0, X, 0, "x", +/* + * Bit test and branch + */ +0, BBRANCH, 0x00, "brset", +0, BBRANCH, 0x01, "brclr", +/* + * Bit manipulation + */ +0, BIT, 0x10, "bset", +0, BIT, 0x11, "bclr", +/* + * Branches + */ +0, BRANCH, 0x20, "bra", +0, BRANCH, 0x21, "brn", +0, BRANCH, 0x22, "bhi", +0, BRANCH, 0x23, "bls", +0, BRANCH, 0x24, "bcc", +0, BRANCH, 0x25, "bcs", +0, BRANCH, 0x26, "bne", +0, BRANCH, 0x27, "beq", +0, BRANCH, 0x28, "bhcc", +0, BRANCH, 0x29, "bhcs", +0, BRANCH, 0x2a, "bpl", +0, BRANCH, 0x2b, "bmi", +0, BRANCH, 0x2c, "bmc", +0, BRANCH, 0x2d, "bms", +0, BRANCH, 0x2e, "bil", +0, BRANCH, 0x2f, "bih", +/* + * Read modify write on anything but registers + */ +0, RMR, 0x30, "neg", +0, RMR, 0x33, "com", +0, RMR, 0x34, "lsr", +0, RMR, 0x36, "ror", +0, RMR, 0x36, "asr", +0, RMR, 0x38, "lsl", +0, RMR, 0x39, "rol", +0, RMR, 0x3a, "dec", +0, RMR, 0x3c, "inc", +0, RMR, 0x3d, "tst", +0, RMR, 0x3f, "clr", +/* + * Implied stuff + */ +0, NOARG, 0x80, "rti", +0, NOARG, 0x81, "rts", +0, NOARG, 0x83, "swi", +0, NOARG, 0x97, "tax", +0, NOARG, 0x98, "clc", +0, NOARG, 0x99, "sec", +0, NOARG, 0x9a, "cli", +0, NOARG, 0x9b, "sei", +0, NOARG, 0x9c, "rsp", +0, NOARG, 0x9d, "nop", +0, NOARG, 0x9f, "txa", +/* + * Register memory. + * Warning. Some imediate opcodes excluded in parser actions. + */ +0, RM, 0xa0, "sub", +0, RM, 0xa1, "cmp", +0, RM, 0xa2, "sbc", +0, RM, 0xa3, "cpx", +0, RM, 0xa4, "and", +0, RM, 0xa5, "bit", +0, RM, 0xa6, "lda", +0, RM, 0xa7, "sta", +0, RM, 0xa8, "eor", +0, RM, 0xa9, "adc", +0, RM, 0xaa, "ora", +0, RM, 0xab, "add", +0, RM, 0xac, "jmp", +0, BRANCH, 0xad, "bsr", +0, RM, 0xad, "jsr", +0, RM, 0xae, "ldx", +0, RM, 0xaf, "stx", +/* + * Branch synonyms + */ +0, BRANCH, 0x24, "bhs", /* bcc */ +0, BRANCH, 0x25, "blo", /* bcs */ +/* + * Brain damaged concatenated opcodes for RMR on registers + */ +0, NOARG, 0x40, "nega", +0, NOARG, 0x43, "coma", +0, NOARG, 0x44, "lsra", +0, NOARG, 0x46, "rora", +0, NOARG, 0x47, "asra", +0, NOARG, 0x48, "lsla", +0, NOARG, 0x49, "rola", +0, NOARG, 0x4a, "deca", +0, NOARG, 0x4c, "inca", +0, NOARG, 0x4d, "tsta", +0, NOARG, 0x4f, "clra", +0, NOARG, 0x50, "negx", +0, NOARG, 0x53, "comx", +0, NOARG, 0x54, "lsrx", +0, NOARG, 0x56, "rorx", +0, NOARG, 0x57, "asrx", +0, NOARG, 0x58, "lslx", +0, NOARG, 0x59, "rolx", +0, NOARG, 0x5a, "decx", +0, NOARG, 0x5c, "incx", +0, NOARG, 0x5d, "tstx", +0, NOARG, 0x5f, "clrx", +/* + * CMOS support + */ +0, CMOS, 0, ".cmos", +0, CMOS, 0x8e, "stop", +0, CMOS, 0x8f, "wait", diff --git a/mach/6805/as/mach4.c b/mach/6805/as/mach4.c new file mode 100644 index 00000000..6f2d2181 --- /dev/null +++ b/mach/6805/as/mach4.c @@ -0,0 +1,205 @@ +#define RCSID4 "$Header$" + +/* + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. + * + * This product is part of the Amsterdam Compiler Kit. + * + * Permission to use, sell, duplicate or disclose this software must be + * obtained in writing. Requests for such permissions may be sent to + * + * Dr. Andrew S. Tanenbaum + * Wiskundig Seminarium + * Vrije Universiteit + * Postbox 7161 + * 1007 MC Amsterdam + * The Netherlands + * + */ + +/* + * Motorola 6805 parsing rules + */ + +expr8 + : + expr + { + fit(fitb($1.val)); + } + ; +bitexp + : + absexp + { + fit((unsigned) $1 <= 7); + $$ = $1 & 07; + } + ; +operation + : + NOARG + { emit1($1);} + | + BRANCH expr + { branch($1,$2);} + | + BBRANCH bitexp ',' expr8 ',' expr + { + branch($1+($2 << 1), $6, $4); + } + | + BIT bitexp ',' expr8 + { + emit1($1+($2 << 1)); +#ifdef RELOCATION + newrelo($4.typ, RELO1); +#endif + emit1($4.val); + } + | + RMR '<' expr8 + | + RMR expr8 + { + emit1($1); +#ifdef RELOCATION + newrelo($2.typ, RELO1); +#endif + emit1($2.val); + } + | + RMR expr8 ',' X + { + if(small($2.val == 0 && + ($2.typ & ~S_DOT) == DOTTYP && + pass == PASS_2, 1)) + emit1($1+0x40); + else + { + emit1($1+0x30); +#ifdef RELOCATION + newrelo($2.typ, RELO1); +#endif + emit1($2.val); + } + } + | + RMR ',' X + { emit1($1+0x40); } + | + RM '#' expr8 + { + switch($1) { + case 0xa7: + case 0xac: + case 0xad: + case 0xaf: + serror("mode error"); + default: + emit1($1); + } +#ifdef RELOCATION + newrelo($3.typ, RELO1); +#endif + emit1($3.val); + } + | + RM '<' expr8 + { + emit1($1+0x10); +#ifdef RELOCATION + newrelo($3.typ, RELO1); +#endif + emit1($3.val); + } + | + RM expr + { + if(small(pass == PASS_2 && + ($2.typ & ~S_DOT) == DOTTYP && + fitb($2.val),1)) { + emit1($1+0x10); +#ifdef RELOCATION + newrelo($2.typ, RELO1); +#endif + emit1($2.val); + } else { + emit1($1+0x20); +#ifdef RELOCATION + newrelo($2.typ, RELO2|RELBR); +#endif + emit2($2.val); + } + } + | + RM '>' expr + { + emit1($1+0x20); +#ifdef RELOCATION + newrelo($3.typ, RELO2|RELBR); +#endif + emit2($3.val); + } + | + RM '>' expr ',' X + { + emit1($1+0x30); +#ifdef RELOCATION + newrelo($3.typ, RELO2|RELBR); +#endif + emit2($3.val); + } + | + RM expr ',' X + { + if(small(pass == PASS_2 && + ($2.typ & ~S_DOT) == DOTTYP && + fitb($2.val),1)) { + if(small(pass == PASS_2 && + ($2.typ & ~S_DOT) == DOTTYP && + $2.val == 0,1)) + emit1($1+0x50); + else { + emit1($1+0x40); +#ifdef RELOCATION + newrelo($2.typ, RELO1); +#endif + emit1($2.val); + } + } else { + small(0,1); /* dummy */ + emit1($1+0x30); +#ifdef RELOCATION + newrelo($2.typ, RELO2|RELBR); +#endif + emit2($2.val); + } + } + | + RM '<' expr8 ',' X + { + emit1($1+0x40); +#ifdef RELOCATION + newrelo($3.typ, RELO1); +#endif + emit1($3.val); + } + | + RM ',' X + { emit1($1+0x50); } + | + CMOS + { + switch($1) { + case 0: + opt_cmos = 1; + break; + case 0x8e: + case 0x8f: + if(! opt_cmos) + serror("bad opcode"); + emit1($1); + } + } + ; diff --git a/mach/6805/as/mach5.c b/mach/6805/as/mach5.c new file mode 100644 index 00000000..33c41278 --- /dev/null +++ b/mach/6805/as/mach5.c @@ -0,0 +1,51 @@ +#define RCSID5 "$Header$" + +/* + * Motorola 6805 special routines + */ + +/* VARARGS2 */ +branch(opc,exp,cell) register opc; expr_t cell; expr_t exp; { + register sm, dist; + int saving; + + dist = exp.val - (DOTVAL + 2); + if((opc & 0xf0) == 0) dist -= 1; /* bitbranch */ + if (pass == PASS_2 && dist > 0 && !(exp.typ & S_DOT)) + dist -= DOTGAIN; + sm = fitj(dist); + if ((exp.typ & ~S_DOT) != DOTTYP) + sm = 0; + if (opc == 0x20 || opc == 0xAD) + saving = 1; + else + saving = 3; + if (small(sm,saving)) { + emit1(opc); + if((opc & 0xF0) == 0) /* bit branch */ + emit1(cell.val); +#ifdef RELOCATION + newrelo(exp.typ, RELPC|RELO1); +#endif + emit1(dist); + } else { + if (opc == 0xAD) /* bsr */ + emit1(0xBD); /* jsr */ + else { + if (opc != 0x20) { /* bra */ + + /* reverse condition : */ + + emit1(opc ^ 1); + if((opc & 0xF0) == 0) /* bitbranch */ + emit1(cell.val); + emit1(3); + } + emit1(0xCC); /* jmp */ + } +#ifdef RELOCATION + newrelo(exp.typ, RELPC|RELO2|RELBR); +#endif + emit2(exp.val); + } +} diff --git a/mach/ns/as/mach0.c b/mach/ns/as/mach0.c new file mode 100644 index 00000000..8ead9e5f --- /dev/null +++ b/mach/ns/as/mach0.c @@ -0,0 +1,21 @@ +#define RCSID0 "$Header$" + +/* + * NS 16032 options + */ +#define THREE_PASS /* branch and offset optimization */ +#define LISTING /* enable listing facilities */ + +#undef valu_t +#define valu_t long +#undef addr_t +#define addr_t long +#undef ALIGNSECT +#define ALIGNSECT 2 + +#undef VALWIDTH +#define VALWIDTH 8 + +#define RELOCATION + +#define UNUSED /* Assemble the 'unused' instructions like bfalse */ diff --git a/mach/ns/as/mach1.c b/mach/ns/as/mach1.c new file mode 100644 index 00000000..6c8ae00b --- /dev/null +++ b/mach/ns/as/mach1.c @@ -0,0 +1,113 @@ +#define RCSID1 "$Header$" + +/* + * NS 16032 C declarations + */ + +#define low4(val) ((int)(val&0xF)) + +/* signed value fits in ? bits */ +#define fit32(val) ( (val)>= -2147483648 && (val)<=2147483647 ) +#define fit16(val) ( (val)>= -32768 && (val)<=32767 ) +#define fit8(val) ( (val)>= -128 && (val)<=127 ) +#define fit4(val) ( (val)>= -8 && (val)<=7 ) + +/* Fits in byte, word displacement */ +#define fitd_b(val) ( (val)>= -64 && (val)<=63 ) +#define fitd_w(val) ( (val)>= -8192 && (val)<=8191 ) + +/* Assemble and disassemble operator id's */ +/* the i_value's in the instruction keyword table + contain five bit fields: + 0-3 Opcode used in format indicated by the i_type field + 4-7 Condition Code field. B_?? Also used for reg in FFS type. + 8-11 The type of the first addressing mode gen1 + 12-15 The type of the second addressing mode gen2 + The integer type T_???? + The custom Slave type S_???? + The Floating point type F_???? +*/ + +#define MK_op(op) (op) +#define MK_cc(cc) ( (cc)<<4 ) +#define MK_g1(g1) ( (g1)<<8 ) +#define MK_g2(g2) ( (g2)<<12 ) + +#define mk_op(o) (MK_op(o)|MK_g1(X_ILLGL)|MK_g2(X_ILLGL)) +#define mk_op1(o,g1) (MK_op(o)|MK_g1(g1)|MK_g2(X_ILLGL)) +#define mk_op2(o,g1,g2) (MK_op(o)|MK_g1(g1)|MK_g2(g2)) +#define mk_c(c) MK_cc(c) +#define mk_op1c(o,g1,c) (MK_op(o)|MK_g1(g1)|MK_g2(X_ILLGL)|MK_cc(c)) +#define mk_op2c(o,g1,g2,c) (MK_op(o)|MK_g1(g1)|MK_g2(g2)|MK_cc(c)) + +#define id_op(id) ((id) &0xF) +#define id_cc(id) (((id)>>4) &0xF) +#define id_g1(id) (((id)>>8) &3) +#define id_g2(id) (((id)>>12)&3) +#define id_t1(id) (((id)>>10)&3) +#define id_t2(id) (((id)>>14)&3) + +/* Type definitions */ +#define T_INT 0 +#define T_FL 1 +#define T_SLAVE 2 +#define T_ILLGL 3 + +#define I_BYTE (T_INT<<2) | 0 +#define I_WORD (T_INT<<2) | 1 +#define I_DOUBLE (T_INT<<2) | 3 + +#define F_FLOAT (T_FL<<2) | 1 +#define F_LONG (T_FL<<2) | 0 + +#define S_DOUBLE (T_SLAVE<<2) | 1 +#define S_QUAD (T_SLAVE<<2) | 0 + +#define X_ILLGL (T_ILLGL<<2) | 2 + +#define B_EQ 0x0 +#define B_NE 0x1 +#define B_CS 0x2 +#define B_CC 0x3 +#define B_HI 0x4 +#define B_LS 0x5 +#define B_GT 0x6 +#define B_LE 0x7 +#define B_FS 0x8 +#define B_FC 0x9 +#define B_LO 0xA +#define B_HS 0xB +#define B_LT 0xC +#define B_GE 0xD +#define B_TRUE 0xE +#define B_FALSE 0xF + +/* String option bits */ +#define SO_UNTIL 0xC +#define SO_WHILE 0x4 +#define SO_BACKW 0x2 +#define SO_TRANS 0x1 + +/* output definitions */ +#define form0(id) emit1(0xA + (id_cc(id)<<4) ) +#define form1(id) emit1(0x2 + (id_op(id)<<4) ) +#define form6(id) emit1(0x4E) ; form4(id) +#define form7(id) emit1(0xCE) ; form4(id) + + +/* Structure contains information for generation of an addressing mode */ +/* The size of immediates is not stored in here and must be fetched from + a id-field +*/ +extern struct { + int m_mode; /* The main mode bits */ + int m_index ; /* m_mode= index mode, m_index has index byte */ + int m_ndisp ; /* The number of displacements */ + expr_t m_expr1 ; /* The first expression */ +#ifdef RELOCATION + int m_rel1, m_rel2; /* relocation */ +#endif + expr_t m_expr2 ; /* The second expression */ +} mode1, mode2, *mode_ptr ; + +#define not_imm(mode_ptr) if ( (mode_ptr)->m_mode==0x14 ) ill_imm() ; diff --git a/mach/ns/as/mach2.c b/mach/ns/as/mach2.c new file mode 100644 index 00000000..27444aac --- /dev/null +++ b/mach/ns/as/mach2.c @@ -0,0 +1,59 @@ +#define RCSID2 "$Header$" + +/* + * NS 16032 tokens + */ + +%token REG +%token AREG +%token FREG +%token MREG +%token CREG +%token EXTERNAL +%token TOS +%token PC +%token INDICATOR + +/* + * Instruction types + */ +%token SETCFG +%token LPR +%token LCR +%token BR +%token RET +%token BSR +%token RDVAL +%token CATST +%token LCSR +%token SEQ +%token ADJSP +%token JSR +%token JUMP +%token LFSR +%token ADD_F +%token CCVIS +%token CCVSI +%token CCVSS +%token CMOV +%token ADD_I +%token COM +%token MUL_I +%token MOVID +%token FFS +%token MOVIF +%token MOVFL +%token TRUNC +%token MOVM +%token INSS +%token SAVE +%token ENTER +%token LMR +%token MOVS +%token CHECK +%token INS +%token MOVQ +%token ACB +%token WAIT + +%type cpu_opts, cpu_list, string_opts, reg_list, reg_items diff --git a/mach/ns/as/mach3.c b/mach/ns/as/mach3.c new file mode 100644 index 00000000..cad69261 --- /dev/null +++ b/mach/ns/as/mach3.c @@ -0,0 +1,453 @@ +#define RCSID3 "$Header$" + +/* + * NS 16032 keywords + */ + +/* Registers */ +0, REG, 0, "r0", +0, REG, 1, "r1", +0, REG, 2, "r2", +0, REG, 3, "r3", +0, REG, 4, "r4", +0, REG, 5, "r5", +0, REG, 6, "r6", +0, REG, 7, "r7", +0, FREG, 0, "f0", +0, FREG, 1, "f1", +0, FREG, 2, "f2", +0, FREG, 3, "f3", +0, FREG, 4, "f4", +0, FREG, 5, "f5", +0, FREG, 6, "f6", +0, FREG, 7, "f7", +/* CPU dedicated registers */ +0, AREG, 0x0, "us", +0, AREG, 0x8, "fp", +0, AREG, 0x9, "sp", +0, AREG, 0xA, "sb", +0, AREG, 0xD, "psr", +0, AREG, 0xE, "intbase", +0, AREG, 0xF, "mod", +/* Tokens dedicated to addressing modes */ +0, TOS, 0x17, "tos", +0, EXTERNAL, 0x16, "external", +0, PC, 0, "pc", +0, INDICATOR, 'b', "b", +0, INDICATOR, 'c', "c", +0, INDICATOR, 'd', "d", +0, INDICATOR, 'f', "f", +0, INDICATOR, 'i', "i", +0, INDICATOR, 'm', "m", +0, INDICATOR, 'q', "q", +0, INDICATOR, 'u', "u", +0, INDICATOR, 'w', "w", +/* Memory management registers */ +0, MREG, 0x0, "bpr0", +0, MREG, 0x1, "bpr1", +0, MREG, 0x4, "pf0", +0, MREG, 0x5, "pf1", +0, MREG, 0x8, "sc", +0, MREG, 0xA, "msr", +0, MREG, 0xB, "bcnt", +0, MREG, 0xC, "ptb0", +0, MREG, 0xD, "ptb1", +0, MREG, 0xF, "eia", +/* Instruction types */ +/* Integer instructions */ +0, ADD_I, mk_op2(0x5,I_BYTE,I_BYTE), "movb", +0, ADD_I, mk_op2(0x5,I_WORD,I_WORD), "movw", +0, ADD_I, mk_op2(0x5,I_DOUBLE,I_DOUBLE), "movd", +0, ADD_I, mk_op2(0x1,I_BYTE,I_BYTE), "cmpb", +0, ADD_I, mk_op2(0x1,I_WORD,I_WORD), "cmpw", +0, ADD_I, mk_op2(0x1,I_DOUBLE,I_DOUBLE), "cmpd", +0, ADD_I, mk_op2(0x0,I_BYTE,I_BYTE), "addb", +0, ADD_I, mk_op2(0x0,I_WORD,I_WORD), "addw", +0, ADD_I, mk_op2(0x0,I_DOUBLE,I_DOUBLE), "addd", +0, ADD_I, mk_op2(0x4,I_BYTE,I_BYTE), "addcb", +0, ADD_I, mk_op2(0x4,I_WORD,I_WORD), "addcw", +0, ADD_I, mk_op2(0x4,I_DOUBLE,I_DOUBLE), "addcd", +0, ADD_I, mk_op2(0x8,I_BYTE,I_BYTE), "subb", +0, ADD_I, mk_op2(0x8,I_WORD,I_WORD), "subw", +0, ADD_I, mk_op2(0x8,I_DOUBLE,I_DOUBLE), "subd", +0, ADD_I, mk_op2(0xC,I_BYTE,I_BYTE), "subcb", +0, ADD_I, mk_op2(0xC,I_WORD,I_WORD), "subcw", +0, ADD_I, mk_op2(0xC,I_DOUBLE,I_DOUBLE), "subcd", +0, COM, mk_op2(0x8,I_BYTE,I_BYTE), "negb", +0, COM, mk_op2(0x8,I_WORD,I_WORD), "negw", +0, COM, mk_op2(0x8,I_DOUBLE,I_DOUBLE), "negd", +0, COM, mk_op2(0xC,I_BYTE,I_BYTE), "absb", +0, COM, mk_op2(0xC,I_WORD,I_WORD), "absw", +0, COM, mk_op2(0xC,I_DOUBLE,I_DOUBLE), "absd", +0, MUL_I, mk_op2(0x8,I_BYTE,I_BYTE), "mulb", +0, MUL_I, mk_op2(0x8,I_WORD,I_WORD), "mulw", +0, MUL_I, mk_op2(0x8,I_DOUBLE,I_DOUBLE), "muld", +0, MUL_I, mk_op2(0xF,I_BYTE,I_BYTE), "divb", +0, MUL_I, mk_op2(0xF,I_WORD,I_WORD), "divw", +0, MUL_I, mk_op2(0xF,I_DOUBLE,I_DOUBLE), "divd", +0, MUL_I, mk_op2(0xE,I_BYTE,I_BYTE), "modb", +0, MUL_I, mk_op2(0xE,I_WORD,I_WORD), "modw", +0, MUL_I, mk_op2(0xE,I_DOUBLE,I_DOUBLE), "modd", +0, MUL_I, mk_op2(0xC,I_BYTE,I_BYTE), "quob", +0, MUL_I, mk_op2(0xC,I_WORD,I_WORD), "quow", +0, MUL_I, mk_op2(0xC,I_DOUBLE,I_DOUBLE), "quod", +0, MUL_I, mk_op2(0xD,I_BYTE,I_BYTE), "remb", +0, MUL_I, mk_op2(0xD,I_WORD,I_WORD), "remw", +0, MUL_I, mk_op2(0xD,I_DOUBLE,I_DOUBLE), "remd", +0, ADD_I, mk_op2(0xA,I_BYTE,I_BYTE), "andb", +0, ADD_I, mk_op2(0xA,I_WORD,I_WORD), "andw", +0, ADD_I, mk_op2(0xA,I_DOUBLE,I_DOUBLE), "andd", +0, ADD_I, mk_op2(0x6,I_BYTE,I_BYTE), "orb", +0, ADD_I, mk_op2(0x6,I_WORD,I_WORD), "orw", +0, ADD_I, mk_op2(0x6,I_DOUBLE,I_DOUBLE), "ord", +0, ADD_I, mk_op2(0x2,I_BYTE,I_BYTE), "bicb", +0, ADD_I, mk_op2(0x2,I_WORD,I_WORD), "bicw", +0, ADD_I, mk_op2(0x2,I_DOUBLE,I_DOUBLE), "bicd", +0, ADD_I, mk_op2(0xE,I_BYTE,I_BYTE), "xorb", +0, ADD_I, mk_op2(0xE,I_WORD,I_WORD), "xorw", +0, ADD_I, mk_op2(0xE,I_DOUBLE,I_DOUBLE), "xord", +0, COM, mk_op2(0xD,I_BYTE,I_BYTE), "comb", +0, COM, mk_op2(0xD,I_WORD,I_WORD), "comw", +0, COM, mk_op2(0xD,I_DOUBLE,I_DOUBLE), "comd", +0, COM, mk_op2(0x1,I_BYTE,I_BYTE), "ashb", +0, COM, mk_op2(0x1,I_BYTE,I_WORD), "ashw", +0, COM, mk_op2(0x1,I_BYTE,I_DOUBLE), "ashd", +0, COM, mk_op2(0x5,I_BYTE,I_BYTE), "lshb", +0, COM, mk_op2(0x5,I_BYTE,I_WORD), "lshw", +0, COM, mk_op2(0x5,I_BYTE,I_DOUBLE), "lshd", +0, COM, mk_op2(0x0,I_BYTE,I_BYTE), "rotb", +0, COM, mk_op2(0x0,I_BYTE,I_WORD), "rotw", +0, COM, mk_op2(0x0,I_BYTE,I_DOUBLE), "rotd", +0, MOVID, mk_op2(0x4,I_BYTE,I_WORD), "movxbw", +0, MOVID, mk_op2(0x7,I_BYTE,I_DOUBLE), "movxbd", +0, MOVID, mk_op2(0x7,I_WORD,I_DOUBLE), "movxwd", +0, MOVID, mk_op2(0x5,I_BYTE,I_WORD), "movzbw", +0, MOVID, mk_op2(0x6,I_BYTE,I_DOUBLE), "movzbd", +0, MOVID, mk_op2(0x6,I_WORD,I_DOUBLE), "movzwd", +#ifdef UNUSED +0, MOVID, mk_op2(0x7,I_DOUBLE,I_DOUBLE), "movxdd", +0, MOVID, mk_op2(0x6,I_DOUBLE,I_DOUBLE), "movzdd", +#endif +0, ADD_I, mk_op2(0x9,I_DOUBLE,I_DOUBLE), "addr", +/* Quick integer instructions */ +0, MOVQ, mk_op1(0x5,I_BYTE), "movqb", +0, MOVQ, mk_op1(0x5,I_WORD), "movqw", +0, MOVQ, mk_op1(0x5,I_DOUBLE), "movqd", +0, MOVQ, mk_op1(0x1,I_BYTE), "cmpqb", +0, MOVQ, mk_op1(0x1,I_WORD), "cmpqw", +0, MOVQ, mk_op1(0x1,I_DOUBLE), "cmpqd", +0, MOVQ, mk_op1(0x0,I_BYTE), "addqb", +0, MOVQ, mk_op1(0x0,I_WORD), "addqw", +0, MOVQ, mk_op1(0x0,I_DOUBLE), "addqd", +/* Extended integer instructions */ +0, MUL_I, mk_op2(0x9,I_BYTE,I_BYTE), "meib", +0, MUL_I, mk_op2(0x9,I_WORD,I_WORD), "meiw", +0, MUL_I, mk_op2(0x9,I_DOUBLE,I_DOUBLE), "meid", +0, MUL_I, mk_op2(0xB,I_BYTE,I_BYTE), "deib", +0, MUL_I, mk_op2(0xB,I_WORD,I_WORD), "deiw", +0, MUL_I, mk_op2(0xB,I_DOUBLE,I_DOUBLE), "deid", +/* Boolean instructions */ +0, COM, mk_op2(0x9,I_BYTE,I_BYTE), "notb", +0, COM, mk_op2(0x9,I_WORD,I_WORD), "notw", +0, COM, mk_op2(0x9,I_DOUBLE,I_DOUBLE), "notd", +0, SEQ, mk_op1c(0x3,I_BYTE,B_EQ), "seqb", +0, SEQ, mk_op1c(0x3,I_WORD,B_EQ), "seqw", +0, SEQ, mk_op1c(0x3,I_DOUBLE,B_EQ), "seqd", +0, SEQ, mk_op1c(0x3,I_BYTE,B_NE), "sneb", +0, SEQ, mk_op1c(0x3,I_WORD,B_NE), "snew", +0, SEQ, mk_op1c(0x3,I_DOUBLE,B_NE), "sned", +0, SEQ, mk_op1c(0x3,I_BYTE,B_CS), "scsb", +0, SEQ, mk_op1c(0x3,I_WORD,B_CS), "scsw", +0, SEQ, mk_op1c(0x3,I_DOUBLE,B_CS), "scsd", +0, SEQ, mk_op1c(0x3,I_BYTE,B_CC), "sccb", +0, SEQ, mk_op1c(0x3,I_WORD,B_CC), "sccw", +0, SEQ, mk_op1c(0x3,I_DOUBLE,B_CC), "sccd", +0, SEQ, mk_op1c(0x3,I_BYTE,B_HI), "shib", +0, SEQ, mk_op1c(0x3,I_WORD,B_HI), "shiw", +0, SEQ, mk_op1c(0x3,I_DOUBLE,B_HI), "shid", +0, SEQ, mk_op1c(0x3,I_BYTE,B_LS), "slsb", +0, SEQ, mk_op1c(0x3,I_WORD,B_LS), "slsw", +0, SEQ, mk_op1c(0x3,I_DOUBLE,B_LS), "slsd", +0, SEQ, mk_op1c(0x3,I_BYTE,B_GT), "sgtb", +0, SEQ, mk_op1c(0x3,I_WORD,B_GT), "sgtw", +0, SEQ, mk_op1c(0x3,I_DOUBLE,B_GT), "sgtd", +0, SEQ, mk_op1c(0x3,I_BYTE,B_LE), "sleb", +0, SEQ, mk_op1c(0x3,I_WORD,B_LE), "slew", +0, SEQ, mk_op1c(0x3,I_DOUBLE,B_LE), "sled", +0, SEQ, mk_op1c(0x3,I_BYTE,B_FS), "sfsb", +0, SEQ, mk_op1c(0x3,I_WORD,B_FS), "sfsw", +0, SEQ, mk_op1c(0x3,I_DOUBLE,B_FS), "sfsd", +0, SEQ, mk_op1c(0x3,I_BYTE,B_FC), "sfcb", +0, SEQ, mk_op1c(0x3,I_WORD,B_FC), "sfcw", +0, SEQ, mk_op1c(0x3,I_DOUBLE,B_FC), "sfcd", +0, SEQ, mk_op1c(0x3,I_BYTE,B_LO), "slob", +0, SEQ, mk_op1c(0x3,I_WORD,B_LO), "slow", +0, SEQ, mk_op1c(0x3,I_DOUBLE,B_LO), "slod", +0, SEQ, mk_op1c(0x3,I_BYTE,B_HS), "shsb", +0, SEQ, mk_op1c(0x3,I_WORD,B_HS), "shsw", +0, SEQ, mk_op1c(0x3,I_DOUBLE,B_HS), "shsd", +0, SEQ, mk_op1c(0x3,I_BYTE,B_LT), "sltb", +0, SEQ, mk_op1c(0x3,I_WORD,B_LT), "sltw", +0, SEQ, mk_op1c(0x3,I_DOUBLE,B_LT), "sltd", +0, SEQ, mk_op1c(0x3,I_BYTE,B_GE), "sgeb", +0, SEQ, mk_op1c(0x3,I_WORD,B_GE), "sgew", +0, SEQ, mk_op1c(0x3,I_DOUBLE,B_GE), "sged", +#ifdef UNUSED +0, SEQ, mk_op1c(0x3,I_BYTE,B_TRUE), "strueb", +0, SEQ, mk_op1c(0x3,I_WORD,B_TRUE), "struew", +0, SEQ, mk_op1c(0x3,I_DOUBLE,B_TRUE), "strued", +0, SEQ, mk_op1c(0x3,I_BYTE,B_FALSE), "sfalseb", +0, SEQ, mk_op1c(0x3,I_WORD,B_FALSE), "sfalsew", +0, SEQ, mk_op1c(0x3,I_DOUBLE,B_FALSE), "sfalsed", +#endif +/* Bit instructions */ +0, ADD_I, mk_op2(0xD,I_BYTE,I_BYTE), "tbitb", +0, ADD_I, mk_op2(0xD,I_WORD,I_WORD), "tbitw", +0, ADD_I, mk_op2(0xD,I_DOUBLE,I_DOUBLE), "tbitd", +0, COM, mk_op2(0x6,I_BYTE,I_BYTE), "sbitb", +0, COM, mk_op2(0x6,I_WORD,I_WORD), "sbitw", +0, COM, mk_op2(0x6,I_DOUBLE,I_DOUBLE), "sbitd", +0, COM, mk_op2(0x7,I_BYTE,I_BYTE), "sbitib", +0, COM, mk_op2(0x7,I_WORD,I_WORD), "sbitiw", +0, COM, mk_op2(0x7,I_DOUBLE,I_DOUBLE), "sbitid", +0, COM, mk_op2(0x2,I_BYTE,I_BYTE), "cbitb", +0, COM, mk_op2(0x2,I_WORD,I_WORD), "cbitw", +0, COM, mk_op2(0x2,I_DOUBLE,I_DOUBLE), "cbitd", +0, COM, mk_op2(0x3,I_BYTE,I_BYTE), "cbitib", +0, COM, mk_op2(0x3,I_WORD,I_WORD), "cbitiw", +0, COM, mk_op2(0x3,I_DOUBLE,I_DOUBLE), "cbitid", +0, COM, mk_op2(0xE,I_BYTE,I_BYTE), "ibitb", +0, COM, mk_op2(0xE,I_WORD,I_WORD), "ibitw", +0, COM, mk_op2(0xE,I_DOUBLE,I_DOUBLE), "ibitd", +0, CHECK, mk_op1(0x1,I_DOUBLE), "cvtp", +0, FFS, mk_op2c(0x5,I_BYTE,I_BYTE,0), "ffsb", +0, FFS, mk_op2c(0x5,I_WORD,I_BYTE,0), "ffsw", +0, FFS, mk_op2c(0x5,I_DOUBLE,I_BYTE,0), "ffsd", +/* Field instructions */ +0, INS, mk_op2(0x0,I_BYTE,I_BYTE), "extb", +0, INS, mk_op2(0x0,I_WORD,I_WORD), "extw", +0, INS, mk_op2(0x0,I_DOUBLE,I_DOUBLE), "extd", +0, INSS, mk_op2(0x3,I_BYTE,I_BYTE), "extsb", +0, INSS, mk_op2(0x3,I_WORD,I_WORD), "extsw", +0, INSS, mk_op2(0x3,I_DOUBLE,I_DOUBLE), "extsd", +0, INS, mk_op2(0x2,I_BYTE,I_BYTE), "insb", +0, INS, mk_op2(0x2,I_WORD,I_WORD), "insw", +0, INS, mk_op2(0x2,I_DOUBLE,I_DOUBLE), "insd", +0, INSS, mk_op2(0x2,I_BYTE,I_BYTE), "inssb", +0, INSS, mk_op2(0x2,I_WORD,I_WORD), "inssw", +0, INSS, mk_op2(0x2,I_DOUBLE,I_DOUBLE), "inssd", +/* String instructions */ +0, MOVS, mk_op1c(0x0,I_BYTE,0), "movsb", +0, MOVS, mk_op1c(0x0,I_WORD,0), "movsw", +0, MOVS, mk_op1c(0x0,I_DOUBLE,0), "movsd", +0, MOVS, mk_op1c(0x0,I_BYTE,SO_TRANS), "movst", +0, MOVS, mk_op1c(0x1,I_BYTE,0), "cmpsb", +0, MOVS, mk_op1c(0x1,I_WORD,0), "cmpsw", +0, MOVS, mk_op1c(0x1,I_DOUBLE,0), "cmpsd", +0, MOVS, mk_op1c(0x1,I_BYTE,SO_TRANS), "cmpst", +0, MOVS, mk_op1c(0x3,I_BYTE,0), "skpsb", +0, MOVS, mk_op1c(0x3,I_WORD,0), "skpsw", +0, MOVS, mk_op1c(0x3,I_DOUBLE,0), "skpsd", +0, MOVS, mk_op1c(0x3,I_BYTE,SO_TRANS), "skpst", +/* Block instructions */ +0, MOVM, mk_op2(0x0,I_BYTE,I_BYTE), "movmb", +0, MOVM, mk_op2(0x0,I_WORD,I_WORD), "movmw", +0, MOVM, mk_op2(0x0,I_DOUBLE,I_DOUBLE), "movmd", +0, MOVM, mk_op2(0x1,I_BYTE,I_BYTE), "cmpmb", +0, MOVM, mk_op2(0x1,I_WORD,I_WORD), "cmpmw", +0, MOVM, mk_op2(0x1,I_DOUBLE,I_DOUBLE), "cmpmd", +/* Packed decimal instructions */ +0, COM, mk_op2(0xF,I_BYTE,I_BYTE), "addpb", +0, COM, mk_op2(0xF,I_WORD,I_WORD), "addpw", +0, COM, mk_op2(0xF,I_DOUBLE,I_DOUBLE), "addpd", +0, COM, mk_op2(0xB,I_BYTE,I_BYTE), "subpb", +0, COM, mk_op2(0xB,I_WORD,I_WORD), "subpw", +0, COM, mk_op2(0xB,I_DOUBLE,I_DOUBLE), "subpd", +/* Array instructions */ +0, CHECK, mk_op2(0x4,I_BYTE,I_BYTE), "indexb", +0, CHECK, mk_op2(0x4,I_WORD,I_WORD), "indexw", +0, CHECK, mk_op2(0x4,I_DOUBLE,I_DOUBLE), "indexd", +0, CHECK, mk_op2(0x3,I_BYTE,I_BYTE), "checkb", +0, CHECK, mk_op2(0x3,I_WORD,I_WORD), "checkw", +0, CHECK, mk_op2(0x3,I_DOUBLE,I_DOUBLE), "checkd", +/* Processor control instructions */ +0, JUMP, mk_op1(0x4,I_DOUBLE), "jump", +0, BR, mk_c(B_EQ), "beq", +0, BR, mk_c(B_NE), "bne", +0, BR, mk_c(B_CS), "bcs", +0, BR, mk_c(B_CC), "bcc", +0, BR, mk_c(B_HI), "bhi", +0, BR, mk_c(B_LS), "bls", +0, BR, mk_c(B_GT), "bgt", +0, BR, mk_c(B_LE), "ble", +0, BR, mk_c(B_FS), "bfs", +0, BR, mk_c(B_FC), "bfc", +0, BR, mk_c(B_LO), "blo", +0, BR, mk_c(B_HS), "bhs", +0, BR, mk_c(B_LT), "blt", +0, BR, mk_c(B_GE), "bge", +0, BR, mk_c(B_TRUE), "br", +#ifdef UNUSED +0, BR, mk_c(B_FALSE), "bfalse", +#endif +0, ADJSP, mk_op1(0xE,I_BYTE), "caseb", +0, ADJSP, mk_op1(0xE,I_WORD), "casew", +0, ADJSP, mk_op1(0xE,I_DOUBLE), "cased", +0, ACB, mk_op1(0x4,I_BYTE), "acbb", +0, ACB, mk_op1(0x4,I_WORD), "acbw", +0, ACB, mk_op1(0x4,I_DOUBLE), "acbd", +0, JSR, mk_op1(0xC,I_DOUBLE), "jsr", +0, BSR, mk_op(0x0), "bsr", +0, RET, mk_op(0x1), "ret", +0, RET, mk_op(0x2), "cxp", +0, ADJSP, mk_op1(0x0,I_DOUBLE), "cxpd", +0, RET, mk_op(0x3), "rxp", +0, RET, mk_op(0x4), "rett", +0, WAIT, mk_op(0x5), "reti", +0, WAIT, mk_op(0xC), "dia", +/* Processor service instructions */ +0, ADJSP, mk_op1(0xA,I_BYTE), "adjspb", +0, ADJSP, mk_op1(0xA,I_WORD), "adjspw", +0, ADJSP, mk_op1(0xA,I_DOUBLE), "adjspd", +0, ADJSP, mk_op1(0x2,I_BYTE), "bicpsrb", +0, ADJSP, mk_op1(0x2,I_WORD), "bicpsrw", +0, ADJSP, mk_op1(0x6,I_BYTE), "bispsrb", +0, ADJSP, mk_op1(0x6,I_WORD), "bispsrw", +#ifdef UNUSED +0, ADJSP, mk_op1(0x2,I_DOUBLE), "bicpsrd", +0, ADJSP, mk_op1(0x6,I_DOUBLE), "bispsrd", +#endif +0, SAVE, mk_op(0x6), "save", +0, SAVE, mk_op(0x7), "restore", +0, ENTER, mk_op(0x8), "enter", +0, SAVE, mk_op(0x9), "exit", +0, LPR, mk_op1(0x6,I_BYTE), "lprb", +0, LPR, mk_op1(0x6,I_WORD), "lprw", +0, LPR, mk_op1(0x6,I_DOUBLE), "lprd", +0, LPR, mk_op1(0x2,I_BYTE), "sprb", +0, LPR, mk_op1(0x2,I_WORD), "sprw", +0, LPR, mk_op1(0x2,I_DOUBLE), "sprd", +0, SETCFG, mk_op1(0x2,I_DOUBLE), "setcfg", +0, WAIT, mk_op(0xF), "bpt", +0, WAIT, mk_op(0xD), "flag", +0, WAIT, mk_op(0xE), "svc", +0, WAIT, mk_op(0xA), "nop", +0, WAIT, mk_op(0xB), "wait", +/* Memory management instructions */ +0, LMR, mk_op1(0x2,I_DOUBLE), "lmr", +0, LMR, mk_op1(0x3,I_DOUBLE), "smr", +0, RDVAL, mk_op1(0x0,I_DOUBLE), "rdval", +0, RDVAL, mk_op1(0x1,I_DOUBLE), "wrval", +#ifdef SU_ASSEM +/* The assembler ref. man and the CPU description booklet differ + in the encoding of these instructions +*/ +0, FFS, mk_op2c(0x6,I_BYTE,I_BYTE,1), "movsub", +0, FFS, mk_op2c(0x6,I_WORD,I_WORD,1), "movsuw", +0, FFS, mk_op2c(0x6,I_DOUBLE,I_DOUBLE,1),"movsud", +0, FFS, mk_op2c(0x6,I_BYTE,I_BYTE,3), "movusb", +0, FFS, mk_op2c(0x6,I_WORD,I_WORD,3), "movusw", +0, FFS, mk_op2c(0x6,I_DOUBLE,I_DOUBLE,3),"movusd", +#else +/* assembler reference manual version */ +0, FFS, mk_op2c(0x7,I_BYTE,I_BYTE,0), "movsub", +0, FFS, mk_op2c(0x7,I_WORD,I_WORD,0), "movsuw", +0, FFS, mk_op2c(0x7,I_DOUBLE,I_DOUBLE,0),"movsud", +0, FFS, mk_op2c(0x6,I_BYTE,I_BYTE,0), "movusb", +0, FFS, mk_op2c(0x6,I_WORD,I_WORD,0), "movusw", +0, FFS, mk_op2c(0x6,I_DOUBLE,I_DOUBLE,0),"movusd", +#endif +/* Floating point instructions */ +0, ADD_F, mk_op2(0xD,F_FLOAT,F_FLOAT), "absf", +0, ADD_F, mk_op2(0xD,F_LONG,F_LONG), "absl", +0, ADD_F, mk_op2(0x0,F_FLOAT,F_FLOAT), "addf", +0, ADD_F, mk_op2(0x0,F_LONG,F_LONG), "addl", +0, ADD_F, mk_op2(0x2,F_FLOAT,F_FLOAT), "cmpf", +0, ADD_F, mk_op2(0x2,F_LONG,F_LONG), "cmpl", +0, ADD_F, mk_op2(0x8,F_FLOAT,F_FLOAT), "divf", +0, ADD_F, mk_op2(0x8,F_LONG,F_LONG), "divl", +0, ADD_F, mk_op2(0xC,F_FLOAT,F_FLOAT), "mulf", +0, ADD_F, mk_op2(0xC,F_LONG,F_LONG), "mull", +0, ADD_F, mk_op2(0x4,F_FLOAT,F_FLOAT), "subf", +0, ADD_F, mk_op2(0x4,F_LONG,F_LONG), "subl", +0, ADD_F, mk_op2(0x5,F_FLOAT,F_FLOAT), "negf", +0, ADD_F, mk_op2(0x5,F_LONG,F_LONG), "negl", +0, ADD_F, mk_op2(0x1,F_FLOAT,F_FLOAT), "movf", +0, ADD_F, mk_op2(0x1,F_LONG,F_LONG), "movl", +0, MOVIF, mk_op2(0x0,I_BYTE,F_FLOAT), "movbf", +0, MOVIF, mk_op2(0x0,I_WORD,F_FLOAT), "movwf", +0, MOVIF, mk_op2(0x0,I_DOUBLE,F_FLOAT), "movdf", +0, MOVIF, mk_op2(0x0,I_BYTE,F_LONG), "movbl", +0, MOVIF, mk_op2(0x0,I_WORD,F_LONG), "movwl", +0, MOVIF, mk_op2(0x0,I_DOUBLE,F_LONG), "movdl", +0, MOVFL, mk_op2(0x3,F_FLOAT,F_LONG), "movfl", +0, MOVFL, mk_op2(0x2,F_LONG,F_FLOAT), "movlf", +0, TRUNC, mk_op2(0x7,F_FLOAT,I_BYTE), "floorfb", +0, TRUNC, mk_op2(0x7,F_FLOAT,I_WORD), "floorfw", +0, TRUNC, mk_op2(0x7,F_FLOAT,I_DOUBLE), "floorfd", +0, TRUNC, mk_op2(0x7,F_LONG,I_BYTE), "floorlb", +0, TRUNC, mk_op2(0x7,F_LONG,I_WORD), "floorlw", +0, TRUNC, mk_op2(0x7,F_LONG,I_DOUBLE), "floorld", +0, TRUNC, mk_op2(0x4,F_FLOAT,I_BYTE), "roundfb", +0, TRUNC, mk_op2(0x4,F_FLOAT,I_WORD), "roundfw", +0, TRUNC, mk_op2(0x4,F_FLOAT,I_DOUBLE), "roundfd", +0, TRUNC, mk_op2(0x4,F_LONG,I_BYTE), "roundlb", +0, TRUNC, mk_op2(0x4,F_LONG,I_WORD), "roundlw", +0, TRUNC, mk_op2(0x4,F_LONG,I_DOUBLE), "roundld", +0, TRUNC, mk_op2(0x5,F_FLOAT,I_BYTE), "truncfb", +0, TRUNC, mk_op2(0x5,F_FLOAT,I_WORD), "truncfw", +0, TRUNC, mk_op2(0x5,F_FLOAT,I_DOUBLE), "truncfd", +0, TRUNC, mk_op2(0x5,F_LONG,I_BYTE), "trunclb", +0, TRUNC, mk_op2(0x5,F_LONG,I_WORD), "trunclw", +0, TRUNC, mk_op2(0x5,F_LONG,I_DOUBLE), "truncld", +0, LFSR, mk_op(0x1), "lfsr", +0, LFSR, mk_op(0x6), "sfsr", +/* Slave processor instructions */ +0, LCR, mk_op1(0x2,I_DOUBLE), "lcr", /* Sure ? */ +0, LCR, mk_op1(0x3,I_DOUBLE), "scr", /* Sure ? */ +0, CATST, mk_op1(0x0,I_DOUBLE), "catst0",/* Sure ? */ +0, CATST, mk_op1(0x1,I_DOUBLE), "catst1",/* Sure ? */ +0, LCSR, mk_op1(0x1,S_DOUBLE), "lcsr", /* Sure ? */ +0, LCSR, mk_op1(0x6,S_DOUBLE), "scsr", /* Sure ? */ +0, CCVSI, mk_op2(0x7,S_DOUBLE,I_BYTE), "ccv0db", +0, CCVSI, mk_op2(0x7,S_DOUBLE,I_WORD), "ccv0dw", +0, CCVSI, mk_op2(0x7,S_DOUBLE,I_DOUBLE), "ccv0dd", +0, CCVSI, mk_op2(0x7,S_QUAD,I_BYTE), "ccv0qb", +0, CCVSI, mk_op2(0x7,S_QUAD,I_WORD), "ccv0qw", +0, CCVSI, mk_op2(0x7,S_QUAD,I_DOUBLE), "ccv0qd", +0, CCVSI, mk_op2(0x5,S_DOUBLE,I_BYTE), "ccv1db", +0, CCVSI, mk_op2(0x5,S_DOUBLE,I_WORD), "ccv1dw", +0, CCVSI, mk_op2(0x5,S_DOUBLE,I_DOUBLE), "ccv1dd", +0, CCVSI, mk_op2(0x5,S_QUAD,I_BYTE), "ccv1qb", +0, CCVSI, mk_op2(0x5,S_QUAD,I_WORD), "ccv1qw", +0, CCVSI, mk_op2(0x5,S_QUAD,I_DOUBLE), "ccv1qd", +0, CCVSI, mk_op2(0x4,S_DOUBLE,I_BYTE), "ccv2db", +0, CCVSI, mk_op2(0x4,S_DOUBLE,I_WORD), "ccv2dw", +0, CCVSI, mk_op2(0x4,S_DOUBLE,I_DOUBLE), "ccv2dd", +0, CCVSI, mk_op2(0x4,S_QUAD,I_BYTE), "ccv2qb", +0, CCVSI, mk_op2(0x4,S_QUAD,I_WORD), "ccv2qw", +0, CCVSI, mk_op2(0x4,S_QUAD,I_DOUBLE), "ccv2qd", +0, CCVIS, mk_op2(0x0,I_BYTE,S_DOUBLE), "ccv3bd", +0, CCVIS, mk_op2(0x0,I_WORD,S_DOUBLE), "ccv3wd", +0, CCVIS, mk_op2(0x0,I_DOUBLE,S_DOUBLE), "ccv3dd", +0, CCVIS, mk_op2(0x0,I_BYTE,S_QUAD), "ccv3bq", +0, CCVIS, mk_op2(0x0,I_WORD,S_QUAD), "ccv3wq", +0, CCVIS, mk_op2(0x0,I_DOUBLE,S_QUAD), "ccv3dq", +0, CCVSS, mk_op2(0x3,S_DOUBLE,S_QUAD), "ccv4dq", +0, CCVSS, mk_op2(0x2,S_QUAD,S_DOUBLE), "ccv5qd", +0, CMOV, mk_op2(0x0,S_DOUBLE,S_DOUBLE), "ccal0d", +0, CMOV, mk_op2(0x0,S_QUAD,S_QUAD), "ccal0q", +0, CMOV, mk_op2(0x4,S_DOUBLE,S_DOUBLE), "ccal1d", +0, CMOV, mk_op2(0x4,S_QUAD,S_QUAD), "ccal1q", +0, CMOV, mk_op2(0xC,S_DOUBLE,S_DOUBLE), "ccal2d", +0, CMOV, mk_op2(0xC,S_QUAD,S_QUAD), "ccal2q", +0, CMOV, mk_op2(0x8,S_DOUBLE,S_DOUBLE), "ccal3d", +0, CMOV, mk_op2(0x8,S_QUAD,S_QUAD), "ccal3q", +0, CMOV, mk_op2(0x2,S_DOUBLE,S_DOUBLE), "ccmpd", +0, CMOV, mk_op2(0x2,S_QUAD,S_QUAD), "ccmpq", +0, CMOV, mk_op2(0x1,S_DOUBLE,S_DOUBLE), "cmov0d", +0, CMOV, mk_op2(0x1,S_QUAD,S_QUAD), "cmov0q", +0, CMOV, mk_op2(0xD,S_DOUBLE,S_DOUBLE), "cmov1d", +0, CMOV, mk_op2(0xD,S_QUAD,S_QUAD), "cmov1q", +0, CMOV, mk_op2(0x5,S_DOUBLE,S_DOUBLE), "cmov2d", +0, CMOV, mk_op2(0x5,S_QUAD,S_QUAD), "cmov2q", diff --git a/mach/ns/as/mach4.c b/mach/ns/as/mach4.c new file mode 100644 index 00000000..74772fcd --- /dev/null +++ b/mach/ns/as/mach4.c @@ -0,0 +1,416 @@ +#define RCSID4 "$Header$" + +/* + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. + * + * This product is part of the Amsterdam Compiler Kit. + * + * Permission to use, sell, duplicate or disclose this software must be + * obtained in writing. Requests for such permissions may be sent to + * + * Dr. Andrew S. Tanenbaum + * Wiskundig Seminarium + * Vrije Universiteit + * Postbox 7161 + * 1007 MC Amsterdam + * The Netherlands + * + */ + +/* Author: Ed Keizer */ + +operation: + BR expr + /* format 0 */ + { dot_adjust(&$2) ; form0($1) ; disp(&$2, RELPC) ;} + | WAIT + /* format 1 */ + { form1($1) ;} + | BSR expr + /* format 1 */ + { dot_adjust(&$2) ; form1($1) ; disp(&$2, RELPC) ;} + | RET expr + /* format 1 */ + { form1($1) ; disp(&$2, 0) ;} + | SAVE reg_list + /* format 1 */ + { form1($1) ; emit1(reg_list($2,id_op($1)!=0x6)) ;} + | ENTER reg_list ',' expr + /* format 1 */ + { form1($1) ; emit1(reg_list($2,0)) ; disp(&$4, 0) ;} + | LPR AREG ',' gen1 + /* format 2 */ + { if ( id_op($1)==0x2 ) not_imm(&mode1) ; + form2($1,$2) ; gen1($1) ; + } + | SEQ gen1 + /* format 2 */ + { form2($1,id_cc($1)) ; gen1($1) ; not_imm(&mode1) ;} + | MOVQ absexp ',' gen1 + /* format 2 */ + { + if ( !fit4($2) ) { + serror("Constant too large") ; + } + form2($1,low4($2)) ; gen1($1) ; + if ( id_op($1)!=0x1 ) not_imm(&mode1) ; /* !cmp */ + } + | ACB absexp ',' gen1 ',' expr + /* format 2 */ + { + dot_adjust(&$6) ; + if (!fit4($2) ) { + serror("Constant too large") ; + } + form2($1,low4($2)) ; gen1($1) ; not_imm(&mode1) ; + disp(&$6, RELPC) ; + } + | ADJSP gen1 + /* format 3 */ + { + if ( id_op($1)==0 ) not_imm(&mode1) ; /* cxpd */ + form3($1) ; gen1($1) ;} + | JSR gen1 + /* format 3 */ + { +#ifndef NO_OPTIM + if ( mode1.m_mode==0x15 ) { /* Absolute */ + dot_adjust(&mode1.m_expr1) ; + RELOMOVE(relonami, mode1.m_rel1); + form1(0) ; disp(&mode1.m_expr1, RELPC) ; /* bsr */ + } else +#endif + { form3($1) ; gen1($1) ; } + not_imm(&mode1) ; + } + | JUMP gen1 + /* format 3 */ + { +#ifndef NO_OPTIM + if ( mode1.m_mode==0x15 ) { /* Absolute */ + dot_adjust(&mode1.m_expr1) ; + RELOMOVE(relonami, mode1.m_rel1); + form0(B_TRUE) ; disp(&mode1.m_expr1, RELPC) ; /* br */ + } else +#endif + { form3($1) ; gen1($1) ; } + not_imm(&mode1) ; + } + | ADD_I gen1 ',' gen2 + /* format 4 */ + { + register opc ; + opc=id_op($1) ; + if ( opc==0x9 ) not_imm(&mode1) ; /* addr */ + if ( opc!=0x1 ) not_imm(&mode2) ; /* !cmp */ +#ifndef NO_OPTIM + if ( mode1.m_mode==0x14 && /* Immediate */ + (mode1.m_expr1.typ & ~S_EXT) == S_ABS && + ( + (fit4(mode1.m_expr1.val) && + (opc==0 || opc==1 || opc==5)) + || + (fit4(-mode1.m_expr1.val) && + (opc==8)) + ) + ) + { + /* Warning, an absolute expression derived + from a symbol that is defined after + use might - if the value now suddenly fits - + cause failed assertions in newlabel + */ + /* add, cmp, mov */ + /* added: the subtract of a signed + * short is the same as the add + * of the negation of that short + * so: subi short,x == addqi -short,x + * 19/04/85 h.m.kodden,m.j.a.leliveld + */ + if (opc==8) /* do the negate */ + mode1.m_expr1.val = + (~mode1.m_expr1.val+1)&0xF; + opc=low4(mode1.m_expr1.val) ; + mode1= mode2 ; + form2($1,opc) ; gen1($1) ; + } else +#endif + { form4($1) ; gengen($1) ; } + } + | SETCFG cpu_opts + /* format 5 */ + { form5($1,$2) ;} + | MOVS string_opts + /* format 5 */ + { form5($1,($2)|id_cc($1)) ;} + | COM gen1 ',' gen2 + /* format 6 */ + { form6($1) ; gengen($1) ; not_imm(&mode2) ;} + | MUL_I gen1 ',' gen2 + /* format 7 */ + { + if ( id_op($1)==0x9 || id_op($1)==0xB ) { + /* mei or dei */ + switch ( mode2.m_mode ) { + case 1 : case 3 : case 5 : case 7 : + serror("register must be even") ; + } + } + form7($1) ; gengen($1) ; not_imm(&mode2) ; + } + | MOVID gen1 ',' gen2 + /* format 7 */ + { form7x($1,id_g1($1)) ; gengen($1) ; not_imm(&mode2) ;} + | MOVM gen1 ',' gen2 ',' expr + /* format 7 */ + { + register s_size ; + s_size= id_g1($1)+1 ; + /* $6.val= $6.val*s_size - s_size ; */ + $6.val= $6.val -1 ; + form7($1) ; gengen($1) ; disp(&$6, 0) ; + not_imm(&mode1) ; not_imm(&mode2) ; + } + | INSS gen1 ',' gen2 ',' absexp ',' absexp + /* format 7 */ + { + if ( ( $6<0 || $6>7 || $8<1 || $8>32 ) + ) { serror("Constant out of bounds") ; } + form7($1) ; gengen($1) ; + if ( id_op($1)==0x3 ) not_imm(&mode1) ; /* exts */ + not_imm(&mode2) ; + emit1((((int)$6)<<5)+(int)$8-1) ; + } + | FFS gen1 ',' gen2 + /* format 8 */ + { form8($1,id_cc($1)) ; gengen($1) ; not_imm(&mode2) ;} + | CHECK REG ',' gen1 ',' gen2 + /* format 8 */ + { + form8($1,$2) ; gengen($1) ; + if ( id_op($1)!=0x4 ) { + not_imm(&mode1) ; /* check, cvtp */ + if ( id_op($1)==0x1 ) not_imm(&mode2) ;/*cvtp */ + } + } + | INS REG ',' gen1 ',' gen2 ',' expr + /* format 8 */ + { + form8($1,$2) ; gengen($1) ; disp(&$8, 0) ; + if ( id_op($1)==0x0 ) not_imm(&mode1) ; + not_imm(&mode2) ; + } + | MOVIF gen1 ',' fgen2 + /* format 9 */ + { + assert( id_t1($1)==T_INT && id_t2($1)==T_FL ) ; + form9($1,id_g1($1),id_g2($1)) ; gengen($1) ; + not_imm(&mode2) ; + } + | MOVFL fgen1 ',' fgen2 + /* format 9 */ + { + assert( id_t1($1)==T_FL && id_t2($1)==T_FL ) ; + form9($1,id_g1($1),( id_g2($1)==F_LONG?3:2 )) ; + gengen($1) ; not_imm(&mode2) ; + } + | TRUNC fgen1 ',' gen2 + /* format 9 */ + { + assert( id_t1($1)==T_FL && id_t2($1)==T_INT ) ; + form9($1,id_g2($1),id_g1($1)) ; gengen($1) ; + not_imm(&mode2) ; + } + | LFSR gen1 + /* format 9 */ + { + if ( id_op($1)==6 ) { /* SFSR */ + not_imm(&mode1) ; + mode2.m_mode=mode1.m_mode ; + mode1.m_mode=0 ; + } else { + mode2.m_mode=0 ; + } + form9($1,0,0) ; + if ( id_op($1)==6 ) { + mode1.m_mode=mode2.m_mode ; + } + gen1($1) ; + } + | ADD_F fgen1 ',' fgen2 + /* format 11 */ + { if ( id_op($1)!=0x2 ) not_imm(&mode2) ; /* !CMPF */ + form11($1) ; gengen($1) ; + } + | RDVAL gen1 + /* format 14 */ + { form14($1,0) ; gen1($1) ; not_imm(&mode1) ;} + | LMR MREG ',' gen1 + /* format 14 */ + { + form14($1,$2) ; gen1($1) ; + if ( id_op($1)==0x3 ) not_imm(&mode1) ; + } + /* All remaining categories are not checked for + illegal immediates */ + | LCR CREG ',' gen1 + /* format 15.0 */ + { frm15_0($1,$2) ; gen1($1) ;} + | CATST gen1 + /* format 15.0 */ + { frm15_0($1,0) ; gen1($1) ;} + | LCSR gen1 + /* format 15.1 */ /* Sure? */ + { mode2.m_mode=0 ; frm15_1($1,0,0) ; gen1($1) ;} + | CCVIS gen1 ',' gen2 + /* format 15.1 */ + { + assert( id_t1($1)==T_INT && id_t2($1)==T_SLAVE ) ; + frm15_1($1,id_g1($1),id_g2($1)) ; gengen($1) ; + } + | CCVSI gen1 ',' gen2 + /* format 15.1 */ + { + assert( id_t1($1)==T_SLAVE && id_t2($1)==T_INT ) ; + frm15_1($1,id_g2($1),id_g1($1)) ; gengen($1) ; + } + | CCVSS gen1 ',' gen2 + /* format 15.1 */ + { + assert( id_t1($1)==T_SLAVE && id_t2($1)==T_SLAVE ) ; + frm15_1($1,0,0) ; gengen($1) ; /* Sure? */ + } + | CMOV gen1 ',' gen2 + /* format 15.5 */ + { frm15_5($1) ; gengen($1) ;} + ; + +gen1 : { mode_ptr= &mode1 ; clrmode() ; } gen + ; +gen2 : { mode_ptr= &mode2 ; clrmode() ; } gen + ; +fgen1 : { mode_ptr= &mode1 ; clrmode() ; } fgen + ; +fgen2 : { mode_ptr= &mode2 ; clrmode() ; } fgen + ; + +gen : gen_not_reg /* Every mode except register */ + | REG + { mode_ptr->m_mode= $1 ; } + ; +fgen : gen_not_reg /* Every mode except register */ + | FREG + { mode_ptr->m_mode= $1 ; } + ; + +gen_not_reg: gen_a /* general mode with eff. address */ + | REG { mode_ptr->m_mode=$1 ;} index + /* The register is supposed to contain the + address + */ + | gen_a index /* As above, but indexed */ + | expr /* Immediate */ + { mode_ptr->m_mode= 0x14 ; + mode_ptr->m_expr1= $1 ; + RELOMOVE(mode_ptr->m_rel1, relonami); + } + ; + +gen_a : expr '(' REG ')' /* Register relative */ + { mode_ptr->m_mode= 0x8 + $3 ; + mode_ptr->m_ndisp= 1 ; + mode_ptr->m_expr1= $1 ; + RELOMOVE(mode_ptr->m_rel1, relonami); + } + | expr '(' AREG ')' /* Memory space */ + { if ( $3<0x8 || $3>0xA ) badsyntax() ; + mode_ptr->m_mode= 0x18 + ($3&3) ; + mode_ptr->m_ndisp= 1 ; + mode_ptr->m_expr1= $1 ; + RELOMOVE(mode_ptr->m_rel1, relonami); + } + | expr '(' PC ')' /* Memory space */ + { mode_ptr->m_mode= 0x1B ; + mode_ptr->m_ndisp= 1 ; + mode_ptr->m_expr1= $1 ; + RELOMOVE(mode_ptr->m_rel1, relonami); + dot_adjust(&mode_ptr->m_expr1) ; + } + | expr '(' + { mode_ptr->m_expr2 = $1; + RELOMOVE(mode_ptr->m_rel2, relonami); + } + expr '(' AREG ')' ')' /* Memory relative */ + { if ( $6<0x8 || $6>0xA ) badsyntax() ; + mode_ptr->m_mode= 0x10 + ($6&3) ; + mode_ptr->m_ndisp= 2 ; + mode_ptr->m_expr1= $4 ; + RELOMOVE(mode_ptr->m_rel1, relonami); + } + | '@' expr /* Absolute */ + { mode_ptr->m_mode= 0x15 ; + mode_ptr->m_ndisp= 1 ; + mode_ptr->m_expr1= $2 ; + RELOMOVE(mode_ptr->m_rel1, relonami); + } + | EXTERNAL '(' expr ')' + { mode_ptr->m_mode= 0x16 ; + mode_ptr->m_ndisp= 2 ; + mode_ptr->m_expr1= $3 ; + RELOMOVE(mode_ptr->m_rel1, relonami); + } + '+' expr /* External */ + { + mode_ptr->m_expr2= $7 ; + RELOMOVE(mode_ptr->m_rel2, relonami); + } + | TOS /* Top Of Stack */ + { mode_ptr->m_mode= 0x17 ; } + ; + +index : '[' REG ':' INDICATOR ']' /* Indexed postfix */ + { mode_ptr->m_index= (mode_ptr->m_mode<<3) | $2 ; + mode_ptr->m_mode= ind_mode( $4 ) ; + } + ; + +cpu_opts: + '[' ']' + { $$=0 ;} + | '[' cpu_list ']' + { $$= $2 ;} + ; + +cpu_list: + INDICATOR + { $$=cpu_opt($1) ; } + | cpu_list ',' INDICATOR + { $$= ($1) | cpu_opt($3) ;} + ; + +string_opts: + { $$=0 ;} + | INDICATOR + { $$= string_opt($1) ; } + | INDICATOR ',' INDICATOR + { if ( $1 != 'b' || + ( $3 != 'u' && $3 != 'w' ) ) { + serror("illegal string options") ; + } + $$ = string_opt($1)|string_opt($3) ; + } + ; + +reg_list: + '[' ']' + { $$=0 ;} + | '[' reg_items ']' + { $$= $2 ;} + ; + +reg_items: + REG + { $$= 1<<($1) ; } + | reg_items ',' REG + { $$= ($1) | ( 1<<($3) ) ;} + ; diff --git a/mach/ns/as/mach5.c b/mach/ns/as/mach5.c new file mode 100644 index 00000000..b61ccb18 --- /dev/null +++ b/mach/ns/as/mach5.c @@ -0,0 +1,311 @@ +#define RCSID5 "$Header$" + +/* + * NS 16032 special routines + */ + +clrmode() { /* clear the current mode */ + mode_ptr->m_ndisp = 0 ; +} + +int ind_mode(type) { + switch ( type ) { + case 'b' : return 0x1C ; + case 'w' : return 0x1D ; + case 'd' : return 0x1E ; + case 'q' : return 0x1F ; + default : + serror("illegal size indicator") ; + return 0x1F ; + } +} + +badsyntax() { + + serror("bad operands"); +} + +ill_imm() { + serror("immediate operand not allowed") ; +} +/* Create the output formats */ +form2(id,sval) { + assert ( id_t1(id)==T_INT ) ; + emit1( id_g1(id) | 0xC | (id_op(id)<<4) | ((sval&1)<<7 ) ) ; + emit1( (sval>>1) | (mode1.m_mode<<3) ) ; +} + +form3(id) { + assert ( id_t1(id)==T_INT ) ; + emit1( id_g1(id) | 0x7C | ((id_op(id)&1)<<7) ) ; + emit1( (id_op(id)>>1) | (mode1.m_mode<<3) ) ; +} + +form4(id) { + assert ( id_t1(id)==T_INT && id_t2(id)==T_INT ); + emit1( id_g2(id) | (id_op(id)<<2) | ((mode2.m_mode&3)<<6) ) ; + emit1( (mode2.m_mode>>2) | (mode1.m_mode<<3) ) ; +} + +form5(id,sval) { + assert ( id_t1(id)==T_INT ) ; + emit1(0xE) ; + emit1( id_g1(id) | (id_op(id)<<2) | ((sval&1)<<7 ) ) ; + emit1( (sval>>1) ) ; +} + +form7x(id,i_type) { + assert ( id_t1(id)==T_INT && id_t2(id)==T_INT ); + emit1(0xCE) ; + emit1( i_type | (id_op(id)<<2) | ((mode2.m_mode&3)<<6) ) ; + emit1( (mode2.m_mode>>2) | (mode1.m_mode<<3) ) ; +} + +form8(id,reg) { + assert ( id_t1(id)==T_INT ) ; + emit1( 0x2E | ((id_op(id)&3)<<6) ) ; + emit1( id_g1(id) | (id_op(id)&04) | (reg<<3) | ((mode2.m_mode&03)<<6) ) ; + emit1( (mode2.m_mode>>2) | (mode1.m_mode<<3) ) ; +} + +form9(id,i_type,f_type) { + emit1(0x3E) ; + emit1( i_type | (f_type<<2) | (id_op(id)<<3) | ((mode2.m_mode&03)<<6) ) ; + emit1( (mode2.m_mode>>2) | (mode1.m_mode<<3) ) ; +} + +form11(id) { + assert ( id_t1(id)==T_FL && id_t2(id)==T_FL && id_g1(id)==id_g2(id) ); + emit1(0xBE) ; + emit1( id_g1(id) | (id_op(id)<<2) | ((mode2.m_mode&3)<<6) ) ; + emit1( (mode2.m_mode>>2) | (mode1.m_mode<<3) ) ; +} + +form14(id,reg) { + assert ( id_t1(id)==T_INT ) ; + emit1(0x1E) ; + emit1( id_g1(id) | (id_op(id)<<2) | ((reg&1)<<7 ) ) ; + emit1( (reg>>1) | (mode1.m_mode<<3) ) ; +} + +frm15_0(id,reg) { + assert ( id_t1(id)==T_INT ) ; + emit1(0x16 /* + slave<<5 */ ) ; + emit1( id_g1(id) | (id_op(id)<<2) | ((reg&1)<<7 ) ) ; + emit1( (reg>>1) | (mode1.m_mode<<3) ) ; +} + +frm15_1(id,i_type,s_type) { + emit1(0x16 /* + slave<<5 */ ) ; + emit1( i_type | (s_type<<2) | (id_op(id)<<3) | ((mode2.m_mode&03)<<6) ) ; + emit1( (mode2.m_mode>>2) | (mode1.m_mode<<3) ) ; +} + +frm15_5(id) { + assert(id_t1(id)==T_SLAVE&& id_t2(id)==T_SLAVE&& id_g1(id)==id_g2(id) ); + emit1(0x16 /* + slave<<5 */ ) ; + emit1( id_g1(id) | (id_op(id)<<2) | ((mode2.m_mode&3)<<6) ) ; + emit1( (mode2.m_mode>>2) | (mode1.m_mode<<3) ) ; +} + +gen1(id) { + if ( (mode1.m_mode&0x1C)==0x1C ) { + emit1(mode1.m_index) ; + } + if ( mode1.m_mode==0x14 ) { /* Immediate */ + RELOMOVE(relonami, mode1.m_rel1); + imm(id_g1(id),&mode1.m_expr1) ; + } else + if ( mode1.m_ndisp >0 ) { + RELOMOVE(relonami, mode1.m_rel1); + disp(&mode1.m_expr1, mode1.m_mode == 0x1B ? RELPC : 0) ; + if ( mode1.m_ndisp >1 ) { + RELOMOVE(relonami, mode1.m_rel2); + disp(&mode1.m_expr2, 0) ; + } + } +} + +gengen(id) { + if ( (mode1.m_mode&0x1C)==0x1C ) { + emit1(mode1.m_index) ; + } + if ( (mode2.m_mode&0x1C)==0x1C ) { + emit1(mode2.m_index) ; + } + if ( mode1.m_mode==0x14 ) { /* Immediate */ + RELOMOVE(relonami, mode1.m_rel1); + imm(id_g1(id),&mode1.m_expr1) ; + } else + if ( mode1.m_ndisp >0 ) { + RELOMOVE(relonami, mode1.m_rel1); + disp(&mode1.m_expr1, mode1.m_mode == 0x1B ? RELPC : 0) ; + if ( mode1.m_ndisp >1 ) { + RELOMOVE(relonami, mode1.m_rel2); + disp(&mode1.m_expr2, 0) ; + } + } + if ( mode2.m_mode==0x14 ) { /* Immediate */ + RELOMOVE(relonami, mode2.m_rel1); + imm(id_g2(id),&mode2.m_expr1) ; + } else + if ( mode2.m_ndisp >0 ) { + RELOMOVE(relonami, mode2.m_rel1); + disp(&mode2.m_expr1, mode2.m_mode == 0x1B ? RELPC : 0) ; + if ( mode2.m_ndisp >1 ) { + RELOMOVE(relonami, mode2.m_rel2); + disp(&mode2.m_expr2, 0) ; + } + } +} + +disp(expr, relpc) register expr_t *expr ; { + register sm1, sm2 ; + + sm1=0 ; sm2=0 ; + if (DOTTYP >= 0x2 && DOTTYP<=0x7F && +#ifdef ASLD + (pass==PASS_1 ? expr->typ==S_ABS : expr->typ!=S_VAR ) ) { +#else + expr->typ == S_ABS) { +#endif + /* All non-text displacements are quad-sized. + The algorithm currently used for minimizing the size + (See CACM article) might generate assertion failures if + any displacement it is trying to minimize increases during + the assembly process. The only way to avoid increases + like that is to fix the sizes of all displacements in + non-text segments. + If the framework included enough information one + might detect in the first pass (0) whether the value + of the expression depends on any symbols whose value + might alter later on in the assembly process. In that case + one could determine the right size in the first pass in + most cases. + */ + if ( fitd_b(expr->val) ) { + sm1=1 ; sm2= 1 ; + } else { + if ( fitd_w(expr->val) ) sm2=1 ; + } + } + sm1=small(sm1,1) ; sm2=small(sm2,2) ; +#ifdef RELOCATION + newrelo(expr->typ, RELO4|RELBR|RELWR|relpc); +#endif + if ( sm1 ) putdisp(expr->val,1) ; + else if ( sm2 ) putdisp(expr->val,2) ; + else putdisp(expr->val,4) ; +} + +putdisp(val,size) valu_t val ; { + switch ( size ) { + case 1 : + emit1( ((int)val)&0x7F ) ; + break ; + case 2 : + emit1( ( (((int)val)>>8)&0x3F ) | 0x80 ) ; + emit1( ((int)val)&0xFF ) ; + break ; + case 4 : + emit1( (((int)(val>>24)) | 0xC0) & 0xFF ) ; + emit1( ((int)(val>>16)) & 0xFF ) ; + emit1( (((int)val)>>8) & 0xFF ) ; + emit1( ((int)val)&0xFF ) ; + break ; + } +} + +dot_adjust(expr) register expr_t *expr ; { + expr->val -= DOTVAL ; + if ( pass==PASS_2 ) { + if ( (expr->typ&S_DOT) == 0 && expr->val>0 ) { + expr->val -= DOTGAIN; + } + } + if ( (expr->typ & ~S_DOT) == DOTTYP ) { + expr->typ=S_ABS ; + } else { + expr->typ=S_VAR ; + } +} + +/* The idea of the following is: + * Give the assembler programmer a warning if he tries to store + * an immediate value in a field which is too small to fit in. + */ + +testsize(type,val) { +/* check if value fits in type */ + switch( type ) { + case I_DOUBLE : return fit32(val); + case I_WORD : return fit16(val); + case I_BYTE : return fit8(val); + } +} + +imm(i_type,expr) register expr_t *expr ; { +/* emit value of immediate expression , after check on FIT */ + if (!testsize(i_type,(int)expr->val)) + warning("immediate operand too large"); + switch( i_type ) { + case I_DOUBLE : +#ifdef RELOCATION + newrelo(expr->typ, RELO4|RELBR|RELWR); +#endif + emit1( ((int)(expr->val>>24)) & 0xFF ) ; + emit1( ((int)(expr->val>>16)) & 0xFF ) ; + emit1( (((int)expr->val)>>8) & 0xFF ) ; + emit1( ((int)expr->val) & 0xFF ) ; + break; + case I_WORD: +#ifdef RELOCATION + newrelo(expr->typ, RELO2|RELBR); +#endif + emit1( (((int)expr->val)>>8) & 0xFF ) ; + emit1( ((int)expr->val) & 0xFF ) ; + break; + case I_BYTE: +#ifdef RELOCATION + newrelo(expr->typ, RELO1); +#endif + emit1( ((int)expr->val) & 0xFF ) ; + } +} + + +reg_list(list,reverse) { + register rev_list, i ; + if ( !reverse ) { + return list ; + } + rev_list= 0 ; + for ( i=0 ; i<8 ; i++ ) { + if ( list & (1< Date: Fri, 5 Dec 1986 16:59:51 +0000 Subject: [PATCH 0367/1625] *** empty log message *** --- mach/6500/as/mach0.c | 4 +--- mach/6800/as/mach0.c | 2 -- mach/i80/as/mach0.c | 2 -- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/mach/6500/as/mach0.c b/mach/6500/as/mach0.c index 7cf4e3b7..5d03fd16 100644 --- a/mach/6500/as/mach0.c +++ b/mach/6500/as/mach0.c @@ -1,4 +1,3 @@ -#define DUK #define RCSID0 "$Header$" /* @@ -6,5 +5,4 @@ */ #define THREE_PASS /* Distinguish short and long branches. */ #define LISTING /* Enable listing facilities. */ -#define RELOCATION /* Produce relocation information. */ -#define NOLD /* Output must be fed into separate linker. */ +#define ASLD diff --git a/mach/6800/as/mach0.c b/mach/6800/as/mach0.c index d979ec92..0861d806 100644 --- a/mach/6800/as/mach0.c +++ b/mach/6800/as/mach0.c @@ -1,4 +1,3 @@ -#define DUK #define RCSID0 "$Header$" /* @@ -10,4 +9,3 @@ #define THREE_PASS #define LISTING #define RELOCATION -#define NOLD diff --git a/mach/i80/as/mach0.c b/mach/i80/as/mach0.c index 94fae314..a05659d3 100644 --- a/mach/i80/as/mach0.c +++ b/mach/i80/as/mach0.c @@ -1,4 +1,3 @@ -#define DUK #define RCSID0 "$Header$" /* @@ -6,4 +5,3 @@ */ #define LISTING #define RELOCATION -#define NOLD From 83ef4238fa926502ebadd089209d5220ebe94a3c Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 5 Dec 1986 17:09:41 +0000 Subject: [PATCH 0368/1625] initial version --- mach/z8000/as/mach0.c | 16 ++ mach/z8000/as/mach1.c | 78 ++++++ mach/z8000/as/mach2.c | 34 +++ mach/z8000/as/mach3.c | 365 +++++++++++++++++++++++++++ mach/z8000/as/mach4.c | 569 ++++++++++++++++++++++++++++++++++++++++++ mach/z8000/as/mach5.c | 174 +++++++++++++ 6 files changed, 1236 insertions(+) create mode 100644 mach/z8000/as/mach0.c create mode 100644 mach/z8000/as/mach1.c create mode 100644 mach/z8000/as/mach2.c create mode 100644 mach/z8000/as/mach3.c create mode 100644 mach/z8000/as/mach4.c create mode 100644 mach/z8000/as/mach5.c diff --git a/mach/z8000/as/mach0.c b/mach/z8000/as/mach0.c new file mode 100644 index 00000000..398247f0 --- /dev/null +++ b/mach/z8000/as/mach0.c @@ -0,0 +1,16 @@ +#define RCSID0 "$Header$" + +/* +** Zilog z8000 machine dependent options +*/ +#define THREE_PASS +#define BYTES_REVERSED +#define WORDS_REVERSED +#define LISTING +#define ASLD +#undef ALIGNSECT +#define ALIGNSECT 2 +#undef valu_t +#define valu_t long +#undef addr_t +#define addr_t long diff --git a/mach/z8000/as/mach1.c b/mach/z8000/as/mach1.c new file mode 100644 index 00000000..686594bb --- /dev/null +++ b/mach/z8000/as/mach1.c @@ -0,0 +1,78 @@ +#define RCSID1 "$Header$" + +/* +** Zilog z8000 machine dependent C declarations +*/ +#define REG 1 +#define IM 2 +#define IR 4 +#define DA 8 +#define X 16 +#define RA 32 +#define BA 64 +#define BX 128 + +#define TYPE_11a23 IR | DA | X +#define TYPE_11b23 REG | IR | DA | X +#define TYPE_12 REG | IR | DA | X +#define TYPE_1263 REG | IR | DA | X +#define TYPE_jp IR | DA | X +#define TYPE_21a REG | IR | DA | X +#define TYPE_21b REG +#define TYPE_2151 REG | IM | IR | DA | X +#define TYPE_pop REG | IR | DA | X +#define TYPE_push REG | IM | IR | DA | X +#define TYPE_ldm IR | DA | X +#define TYPE_ld IR | DA | X + +#define DST 0 +#define SRC 1 + +#define DJNZ_ 0xF000 +#define JR_ 0xE000 +#define CALR_ 0xD000 + +#define low3(z) ( ((short) z) & 07 ) +#define low4(z) ( ((short) z) & 017 ) +#define low5(z) ( ((short) z) & 037 ) +#define low7(z) ( ((short) z) & 0177 ) +#define low8(z) ( ((short) z) & 0377 ) +#define low11(z) ( ((short) z) & 03777 ) +#define low12(z) ( ((short) z) & 07777 ) +#define low15(z) ( ((short) z) & 077777 ) +#define fit3(z) ( low3(z) == (z) ) +#define fit4(z) ( low4(z) == (z) ) +#define fit5(z) ( low5(z) == (z) ) +#define fit7(z) ( low7(z) == (z) ) +#define fit8(z) ( low8(z) == (z) ) +#define fits8(z) ( low7(z) == (z) || low7(-z-1) == (-z-1) ) +#define fits12(z) ( low11(z) == (z) || low11(-z-1) == (-z-1) ) +#define fits16(z) ( low15(z) == (z) || low15(-z-1) == (-z-1) ) + +#define bitset(x,b) ( ((int) x) & ((int) 1< CALR CC CTLR CTLRFLAGS DJNZ FLAG F1_1a F1_1b +%token F1_1F2_3 F1_2 F1_2F6_3 F2_1 F2_1F5_1 F5_1L F5_1R +%token F6_4 F6_5 F6_6 F9_1 F9_2 F9_3 IN INTCB JP JR +%token LD LDA LDAR LDCTL LDCTLB LDK LDL LDM LDR MREQ +%token OUT POP PUSH R8 R16 R32 R64 RET SC TCC + + + /* From all addressing modes only 'im' and 'ra' might need more than + ** 16 bits; This is achieved by using the global var 'immed' in + ** case of 'im' and by returning a long in case of 'ra'. + */ +%type ba bx coco1 coco2 ctlargs ctlbargs da dst flags +%type im imexpr ints ir opr option option2 reg src x + +%type ra diff --git a/mach/z8000/as/mach3.c b/mach/z8000/as/mach3.c new file mode 100644 index 00000000..ffea8603 --- /dev/null +++ b/mach/z8000/as/mach3.c @@ -0,0 +1,365 @@ +#define RCSID3 "$Header$" + +/* +** Zilog z8000 keywords +*/ +0, R8, 8, "RL0", +0, R8, 0, "RH0", +0, R8, 9, "RL1", +0, R8, 1, "RH1", +0, R8, 10, "RL2", +0, R8, 2, "RH2", +0, R8, 11, "RL3", +0, R8, 3, "RH3", +0, R8, 12, "RL4", +0, R8, 4, "RH4", +0, R8, 13, "RL5", +0, R8, 5, "RH5", +0, R8, 14, "RL6", +0, R8, 6, "RH6", +0, R8, 15, "RL7", +0, R8, 7, "RH7", +/* Special format for some byte-registers. Not really available on +** the z8000 but designed to ease writing a z8000-backend-table. +** LR[0..7] are equivalent with RL[0..7]. +*/ +0, R8, 8, "LR0", +0, R8, 9, "LR1", +0, R8, 10, "LR2", +0, R8, 11, "LR3", +0, R8, 12, "LR4", +0, R8, 13, "LR5", +0, R8, 14, "LR6", +0, R8, 15, "LR7", +0, R16, 0, "R0", +0, R16, 1, "R1", +0, R16, 2, "R2", +0, R16, 3, "R3", +0, R16, 4, "R4", +0, R16, 5, "R5", +0, R16, 6, "R6", +0, R16, 7, "R7", +0, R16, 8, "R8", +0, R16, 9, "R9", +0, R16, 10, "R10", +0, R16, 11, "R11", +0, R16, 12, "R12", +0, R16, 13, "R13", +0, R16, 14, "R14", +0, R16, 15, "R15", +0, R32, 0, "RR0", +0, R32, 2, "RR2", +0, R32, 4, "RR4", +0, R32, 6, "RR6", +0, R32, 8, "RR8", +0, R32, 10, "RR10", +0, R32, 12, "RR12", +0, R32, 14, "RR14", +0, R64, 0, "RQ0", +0, R64, 4, "RQ4", +0, R64, 8, "RQ8", +0, R64, 12, "RQ12", +0, CC, 14, "NZ", +0, CC, 15, "NC", +0, CC, 13, "PL", +0, CC, 5, "MI", +0, CC, 14, "NE", +0, CC, 6, "EQ", +0, CC, 4, "OV", +0, CC, 12, "NOV", +0, CC, 4, "PE", +0, CC, 12, "PO", +0, CC, 9, "GE", +0, CC, 1, "LT", +0, CC, 10, "GT", +0, CC, 2, "LE", +0, CC, 15, "UGE", +0, CC, 7, "ULT", +0, CC, 11, "UGT", +0, CC, 3, "ULE", +0, FLAG, 0x80, "C", +0, FLAG, 0x40, "Z", +0, FLAG, 0x20, "S", +0, FLAG, 0x10, "P", +0, FLAG, 0x10, "V", +0, INTCB, 2, "VI", +0, INTCB, 1, "NVI", +0, CTLRFLAGS, 1, "FLAGS", +0, CTLR, 2, "FCW", +0, CTLR, 3, "REFRESH", +0, CTLR, 4, "PSAPSEG", +0, CTLR, 5, "PSAPOFF", +0, CTLR, 6, "NSPSEG", +0, CTLR, 7, "NSPOFF", +0, CTLR, 5, "PSAP", +0, CTLR, 7, "NSP", + + /* TYPE_11a23 */ +0, F1_1F2_3, 0x1F00, "call", +0, F1_1F2_3, 0x3900, "ldps", + /* TYPE_11b23 */ +0, F1_1F2_3, 0x0D08, "clr", +0, F1_1F2_3, 0x0C08, "clrb", +0, F1_1F2_3, 0x0D00, "com", +0, F1_1F2_3, 0x0C00, "comb", +0, F1_1F2_3, 0x0D02, "neg", +0, F1_1F2_3, 0x0C02, "negb", +0, F1_1F2_3, 0x0D04, "test", +0, F1_1F2_3, 0x0C04, "testb", +0, F1_1F2_3, 0x1C08, "testl", +0, F1_1F2_3, 0x0D06, "tset", +0, F1_1F2_3, 0x0C06, "tsetb", + +0, F1_1a, 0xB000, "dab", +0, F1_1a, 0xB10A, "exts", +0, F1_1a, 0xB100, "extsb", +0, F1_1a, 0xB107, "extsl", + +0, F1_1b, 0xB300, "rl", +0, F1_1b, 0xB200, "rlb", +0, F1_1b, 0xB308, "rlc", +0, F1_1b, 0xB208, "rlcb", +0, F1_1b, 0xB304, "rr", +0, F1_1b, 0xB204, "rrb", +0, F1_1b, 0xB30C, "rrc", +0, F1_1b, 0xB20C, "rrcb", + + /* TYPE_12 */ +0, F1_2, 0x2B00, "dec", +0, F1_2, 0x2A00, "decb", +0, F1_2, 0x2900, "inc", +0, F1_2, 0x2800, "incb", +0, LDK, 0xBD00, "ldk", + /* TYPE_1263 */ +0, F1_2F6_3, 0x2700, "bit", +0, F1_2F6_3, 0x2600, "bitb", +0, F1_2F6_3, 0x2300, "res", +0, F1_2F6_3, 0x2200, "resb", +0, F1_2F6_3, 0x2500, "set", +0, F1_2F6_3, 0x2400, "setb", + + /* TYPE_jp */ +0, JP, 0x1E00, "jp", + +0, TCC, 0xAF00, "tcc", +0, TCC, 0xAE00, "tccb", + + /* TYPE_21a */ +0, F2_1, 0x2D00, "ex", +0, F2_1, 0x2C00, "exb", + /* TYPE_21b */ +0, F2_1, 0x3500, "adc", +0, F2_1, 0x3400, "adcb", +0, F2_1, 0x3E00, "rldb", +0, F2_1, 0x3C00, "rrdb", +0, F2_1, 0x3700, "sbc", +0, F2_1, 0x3600, "sbcb", + /* TYPE_2151. + ** Depending on their operands the cp-instructions might + ** have an opcode of 0x201 more then listed below. This is + ** added at the appropriate place. + ** The difference in opcode between byte-,word- and long- + ** instructions of the F2_1F5_1 group is as follows: + ** If bit 8 is on it is a word instruction; If it is not a + ** word instruction and bit 12 is on it is a long instruction, + ** else it is a byte instruction. This information is used + ** when one of the operands is of type IM. + */ +0, F2_1F5_1, 0x0100, "add", +0, F2_1F5_1, 0x0000, "addb", +0, F2_1F5_1, 0x1600, "addl", +0, F2_1F5_1, 0x0700, "and", +0, F2_1F5_1, 0x0600, "andb", +0, F2_1F5_1, 0x1B00, "div", +0, F2_1F5_1, 0x1A00, "divl", +0, F2_1F5_1, 0x1900, "mult", +0, F2_1F5_1, 0x1800, "multl", +0, F2_1F5_1, 0x0500, "or", +0, F2_1F5_1, 0x0400, "orb", +0, F2_1F5_1, 0x0300, "sub", +0, F2_1F5_1, 0x0200, "subb", +0, F2_1F5_1, 0x1200, "subl", +0, F2_1F5_1, 0x0900, "xor", +0, F2_1F5_1, 0x0800, "xorb", +0, F2_1F5_1, 0x0B00, "cp", +0, F2_1F5_1, 0x0A00, "cpb", +0, F2_1F5_1, 0x1000, "cpl", + +0, LDA, 0, "lda", + /* TYPE_pop */ +0, POP, 0x1700, "pop", +0, POP, 0x1500, "popl", + /* TYPE_push */ +0, PUSH, 0x1300, "push", +0, PUSH, 0x1100, "pushl", + + /* TYPE_ld */ +0, LD, 0x0100, "ld", +0, LD, 0, "ldb", +0, LDL, 0, "ldl", + +0, DJNZ, 0xF080, "djnz", +0, DJNZ, 0xF000, "dbjnz", +0, JR, 0xE000, "jr", +0, CALR, 0xD000, "calr", + + /* Depending on their operands the LDR-instructions might + ** have an opcode of 0x200 more then listed below. This is + ** or-ed in at the appropriate place. + */ +0, LDR, 0x3100, "ldr", +0, LDR, 0x3000, "ldrb", +0, LDR, 0x3500, "ldrl", + +0, LDAR, 0x3400, "ldar", + +0, F5_1L, 0xB309, "sla", +0, F5_1L, 0xB209, "slab", +0, F5_1L, 0xB30D, "slal", +0, F5_1L, 0xB301, "sll", +0, F5_1L, 0xB201, "sllb", +0, F5_1L, 0xB305, "slll", +0, F5_1R, 0xB309, "sra", +0, F5_1R, 0xB209, "srab", +0, F5_1R, 0xB30D, "sral", +0, F5_1R, 0xB301, "srl", +0, F5_1R, 0xB201, "srlb", +0, F5_1R, 0xB305, "srll", + + /* Depending on its operands the LDM-instruction might have + ** an opcode of 8 more then listed below. This is added at the + ** appropriate place. + ** TYPE_ldm + */ +0, LDM, 0x1C01, "ldm", + + /* For the F6.4 instructions below the yylval-column contains + ** the opcode for the instruction. However the third hexa-digit + ** should be 0; But this is the opcode which must be put into + ** the second word of the instruction! + */ +0, F6_4, 0x3B88, "ind", +0, F6_4, 0x3A88, "indb", +0, F6_4, 0x3B08, "indr", +0, F6_4, 0x3A08, "indrb", +0, F6_4, 0x3B80, "ini", +0, F6_4, 0x3A80, "inib", +0, F6_4, 0x3B00, "inir", +0, F6_4, 0x3A00, "inirb", +0, F6_4, 0xBB89, "ldd", +0, F6_4, 0xBA89, "lddb", +0, F6_4, 0xBB09, "lddr", +0, F6_4, 0xBA09, "lddrb", +0, F6_4, 0xBB81, "ldi", +0, F6_4, 0xBA81, "ldib", +0, F6_4, 0xBB01, "ldir", +0, F6_4, 0xBA01, "ldirb", +0, F6_4, 0x3B0A, "otdr", +0, F6_4, 0x3A0A, "otdrb", +0, F6_4, 0x3B02, "otir", +0, F6_4, 0x3A02, "otirb", +0, F6_4, 0x3B8A, "outd", +0, F6_4, 0x3A8A, "outdb", +0, F6_4, 0x3B82, "outi", +0, F6_4, 0x3A82, "outib", +0, F6_4, 0x3B89, "sind", +0, F6_4, 0x3A89, "sindb", +0, F6_4, 0x3B09, "sindr", +0, F6_4, 0x3A09, "sindrb", +0, F6_4, 0x3B81, "sini", +0, F6_4, 0x3A81, "sinib", +0, F6_4, 0x3B01, "sinir", +0, F6_4, 0x3A01, "sinirb", +0, F6_4, 0x3B0B, "sotdr", +0, F6_4, 0x3A0B, "sotdrb", +0, F6_4, 0x3B03, "sotir", +0, F6_4, 0x3A03, "sotirb", +0, F6_4, 0x3B8B, "soutd", +0, F6_4, 0x3A8B, "soutdb", +0, F6_4, 0x3B83, "souti", +0, F6_4, 0x3A83, "soutib", +0, F6_4, 0xB808, "trdb", +0, F6_4, 0xB80C, "trdrb", +0, F6_4, 0xB800, "trib", +0, F6_4, 0xB804, "trirb", +0, F6_4, 0xB80A, "trtdb", +0, F6_4, 0xB8EE, "trtdrb", +0, F6_4, 0xB802, "trtib", +0, F6_4, 0xB8E6, "trtirb", + + /* From the F6.5 instructions below the last eight ('string'- + ** instructions) want an 'ir' as operand; The others want a 'r'. + ** In the opcode for the string-instructions bit 1 is on, which + ** indicates the difference. + */ +0, F6_5, 0xBB08, "cpd", +0, F6_5, 0xBA08, "cpdb", +0, F6_5, 0xBB0C, "cpdr", +0, F6_5, 0xBA0C, "cpdrb", +0, F6_5, 0xBB00, "cpi", +0, F6_5, 0xBA00, "cpib", +0, F6_5, 0xBB04, "cpir", +0, F6_5, 0xBA04, "cpirb", +0, F6_5, 0xBB0A, "cpsd", +0, F6_5, 0xBA0A, "cpsdb", +0, F6_5, 0xBB0E, "cpsdr", +0, F6_5, 0xBA0E, "cpsdrb", +0, F6_5, 0xBB02, "cpsi", +0, F6_5, 0xBA02, "cpsib", +0, F6_5, 0xBB06, "cpsir", +0, F6_5, 0xBA06, "cpsirb", + +0, F6_6, 0xB30B, "sda", +0, F6_6, 0xB20B, "sdab", +0, F6_6, 0xB30F, "sdal", +0, F6_6, 0xB303, "sdl", +0, F6_6, 0xB203, "sdlb", +0, F6_6, 0xB307, "sdll", + + /* The instructions in\b and out\b have two different opcodes + ** depending on their operands (...). Therefore the opcodes + ** below are not complete. The rest is or-ed in at the ap- + ** propriate place! + ** rest | r and da r and ir + ** --------------------------------- + ** in\b | 0xA04 0xC00 + ** out\b | 0xA06 OxE00 + ** Furthermore the 'special'-instructions don't allow an 'ir' + ** as operand. In their opcode bit 0 is on, which indicates + ** the difference with the other instructions of this group. + */ +0, IN, 0x3100, "in", +0, IN, 0x3000, "inb", +0, IN, 0x3B05, "sin", +0, IN, 0x3A05, "sinb", +0, OUT, 0x3100, "out", +0, OUT, 0x3000, "outb", +0, OUT, 0x3B07, "sout", +0, OUT, 0x3A07, "soutb", + + /* Depending on their operands the LDCTL-instructions might + ** have an opcode of 8 more then listed below. This is or-ed + ** in at the appropriate place. + */ +0, LDCTL, 0x7D00, "ldctl", +0, LDCTLB, 0x8C00, "ldctlb", +0, MREQ, 0x7B0D, "mreq", + +0, F9_1, 0x8D05, "comflg", +0, F9_1, 0x8D03, "resflg", +0, F9_1, 0x8D01, "setflg", + +0, F9_2, 0x7C00, "di", +0, F9_2, 0x7C04, "ei", + +0, F9_3, 0x7A00, "halt", +0, F9_3, 0x7B00, "iret", +0, F9_3, 0x7B0A, "mbit", +0, F9_3, 0x7B09, "mres", +0, F9_3, 0x7B08, "mset", +0, F9_3, 0x8D07, "nop", + + /* Rest of the opcode-0x200 is or-ed in at the appropriate place + */ +0, RET, 0x9E00, "ret", +0, SC, 0x7F00, "sc", diff --git a/mach/z8000/as/mach4.c b/mach/z8000/as/mach4.c new file mode 100644 index 00000000..88653615 --- /dev/null +++ b/mach/z8000/as/mach4.c @@ -0,0 +1,569 @@ +#define RCSID4 "$Header$" + +/* +** Zilog z8000 yacc parsing rules +*/ +operation + : f1 + | f2 + | f3 + | f4 + | f5 + | f6 + | f7 + | f8 + | f9 + ; + + +f1 : F1_1F2_3 dst + { switch( ($1 & 0x0F00)>>8 ) { + case 9: case 0xF: chtype( DST, TYPE_11a23 ); break; + case 0xC: case 0xD: chtype( DST, TYPE_11b23 ); break; + } + emit2( mode | $1 | $2<<4 ); + if ( mode>>12 == 4 ) emit_ad( addr_inf ); + } + | F1_1a reg + { chreg( $1, $2 ); + emit2( $1 | $2<<4 ); + } + | F1_1b reg option + { if ( $3 != 1 && $3 != 2 ) argerr(); + emit2( $1 | $2<<4 | ($3-1)<<1 ); + } + | F1_2 dst option + { chtype( DST, TYPE_12 ); + fit(fit4($3-1)); + emit2( mode | $1 | $2<<4 | $3-1 ); + if ( mode>>12 == 4 ) emit_ad( addr_inf ); + } + | LDK reg ',' imexpr + { fit(fit4($4)); + emit2( $1 | $2<<4 | $4 ); + } + | F1_2F6_3 dst ',' src + { if ( oprtype[ DST ] == REG && oprtype[ SRC ] == REG ) + { emit2( $1 | $4 ); + emit2( $2<<8 ); + } + else if ( oprtype[ SRC ] == IM ) + { chtype( DST, TYPE_1263 ); + if ((immed.typ & ~S_EXT) != S_ABS) { + serror("must be absolute"); + } + if ( bitset($1,8) ) /* word */ fit(fit4(immed.val)); + else /* byte */ fit(fit3(immed.val)); + emit2( mode | $1 | $2<<4 | (int)immed.val ); + if ( mode>>12 == 4 ) emit_ad( addr_inf ); + } + else argerr(); + } + | JP coco1 dst + { chtype( DST, TYPE_jp ); + emit2( mode | $1 | $3<<4 | $2 ); + if ( mode>>12 == 4 ) emit_ad( addr_inf ); + } + | TCC coco1 reg + { emit2( $1 | $3<<4 | $2 ); } + ; + + +f2 : F2_1 reg ',' src + { switch( ($1 & 0xF000)>>12 ) + { case 2: chtype( SRC, TYPE_21a ); break; + case 3: chtype( SRC, TYPE_21b ); break; + } + emit2( mode | $1 | $4<<4 | $2 ); + if ( mode>>12 == 4 ) emit_ad( addr_inf ); + } + | F2_1F5_1 dst ',' src + { switch( oprtype[ DST ] ) + { case REG: chtype( SRC, TYPE_2151 ); + chreg( $1, $2 ); + emit2( mode | $1 | $4<<4 | $2 ); + break; + case IR: case DA: case X: + if ( oprtype[ SRC ] == IM + && ( $1 == 0x0B00 || $1 == 0x0A00 ) ) + /* cp or cpb */ + { setmode( DST ); + emit2( mode | $1 + 0x201 | $2<<4 ); + break; + } + default: argerr(); + } + if ( mode>>12 == 4 ) emit_ad( addr_inf ); + if ( oprtype[ SRC ] == IM ) + { if (bitset($1,8)) /* word */ { +#ifdef RELOCATION + newrelo(immed.typ, RELO2|RELBR); +#endif + emit2( (int)immed.val ); + } + else if (bitset($1,12)) /* long */ { +#ifdef RELOCATION + newrelo(immed.typ, RELO4|RELWR|RELBR); +#endif + emit4( immed.val ); + } + else /* byte */ { +#ifdef RELOCATION + newrelo(immed.typ, RELO1); +#endif + emit1((int) immed.val); + /* emit1((int) immed.val); ??? twice ??? */ + } + } + } + | LDA R32 ',' src + { switch( oprtype[ SRC ] ) + { case DA: case X: emit2( 0x7600 | $4<<4 | $2 ); + emit_ad( addr_inf ); + break; + case BA: emit2( 0x3400 | $4<<4 | $2 ); +#ifdef RELOCATION + newrelo(displ.typ,RELO2|RELBR); +#endif + emit2( (int) displ.val ); break; + case BX: emit2( 0x7400 | $4<<4 | $2 ); + emit2( index<<8 ); break; + default: argerr(); + } + } + | POP dst ',' ir + { chtype( DST, TYPE_pop ); + emit2( mode | $1 | $4<<4 | $2 ); + if ( mode>>12 == 4 ) emit_ad( addr_inf ); + } + | PUSH ir ',' src + { chtype( SRC, TYPE_push ); + switch ( oprtype[ SRC ] ) + { case IM: if ( $1 == 0x1100 ) /* pushl */ argerr(); + /* { emit2( 0x9109 | $2<<4 ); + ** emit4( immed ); + ** } + */ + else + { emit2( 0x0D09 | $2<<4 ); +#ifdef RELOCATION + newrelo(immed.typ, RELO2|RELBR); +#endif + emit2( (int)immed.val ); + } + break; + default: emit2( mode | $1 | $2<<4 | $4 ); + if ( mode>>12 == 4 ) emit_ad( addr_inf ); + } + } + | LD dst ',' src + { if ( oprtype[ DST ] == REG ) + { switch( oprtype[ SRC ] ) + { case IM: + if ( $1 == 0 ) /* ldb: F3.2 */ + { /* fit(fits8(immed)); */ + emit1( 0xC000 | $2<<8); +#ifdef RELOCATION + newrelo(immed.typ, RELO1); +#endif + emit1((int) immed.val); + } + else + { /*fit(fits16(immed));*/ + emit2( 0x2100 | $2 ); +#ifdef RELOCATION + newrelo(immed.typ, RELO2|RELBR); +#endif + emit2( (int)immed.val ); + } + break; + case REG: case IR: case DA: case X: + setmode( SRC ); + emit2( mode | 0x2000 | $1 | $4<<4 | $2 ); + if ( mode>>12 == 4 ) emit_ad( addr_inf ); + break; + case BA: emit2( 0x3000 | $1 | $4<<4 | $2 ); +#ifdef RELOCATION + newrelo(displ.typ,RELO2|RELBR); +#endif + emit2( (int) displ.val ); + break; + case BX: emit2( 0x7000 | $1 | $4<<4 | $2 ); + emit2( index<<8 ); + break; + default: argerr(); + } + break; + } + if ( oprtype[ SRC ] == REG ) + { switch( oprtype[ DST ] ) + { case IR: case DA: case X: + setmode( DST ); + emit2( mode | 0x2E00 | $1 | $2<<4 | $4 ); + if ( mode>>12 == 4 ) emit_ad( addr_inf ); + break; + case BA: emit2( 0x3200 | $1 | $2<<4 | $4 ); +#ifdef RELOCATION + newrelo(displ.typ,RELO2|RELBR); +#endif + emit2( (int) displ.val ); + break; + case BX: emit2( 0x7200 | $1 | $2<<4 | $4 ); + emit2( index<<8 ); + break; + default: argerr(); + } + break; + } + if ( oprtype[ SRC ] == IM ) /* F5.1 */ + { chtype( DST, TYPE_ld ); + emit2( mode | 0xC05 | $1 | $2<<4 ); + if ( mode>>12 == 4 ) emit_ad( addr_inf ); + if ( $1 == 0 ) /* ldb */ + { /* fit(fits8(immed)); */ +#ifdef RELOCATION + newrelo(immed.typ, RELO1); +#endif + emit1((int) immed.val); + /* emit1((int) immed.val); ??? twice ??? */ + } + else /* ld */ + { /*fit(fits16(immed));*/ +#ifdef RELOCATION + newrelo(immed.typ, RELO2 | RELBR); +#endif + emit2( (int)immed.val ); + } + break; + } + argerr(); + } + | LDL dst ',' src + { if ( oprtype[ DST ] == REG ) + { switch( oprtype[ SRC ] ) + { case IM: emit2( 0x1400 | $2 ); +#ifdef RELOCATION + newrelo(immed.typ, RELO4|RELBR|RELWR); +#endif + emit4( immed.val ); + break; + case REG: case IR: case DA: case X: + setmode( SRC ); + emit2( mode | 0x1400 | $4<<4 | $2 ); + if ( mode>>12 == 4 ) emit_ad( addr_inf ); + break; + case BA: emit2( 0x3500 | $4<<4 | $2 ); +#ifdef RELOCATION + newrelo(displ.typ,RELO2|RELBR); +#endif + emit2((int) displ.val ); + break; + case BX: emit2( 0x7500 | $4<<4 | $2 ); + emit2( index<<8 ); + break; + default: argerr(); + } + break; + } + if ( oprtype[ SRC ] == REG ) + { switch( oprtype[ DST ] ) + { case IR: case DA: case X: + setmode( DST ); + emit2( mode | 0x1D00 | $2<<4 | $4 ); + if ( mode>>12 == 4 ) emit_ad( addr_inf ); + break; + case BA: emit2( 0x3700 | $2<<4 | $4 ); +#ifdef RELOCATION + newrelo(displ.typ,RELO2|RELBR); +#endif + emit2( (int) displ.val ); + break; + case BX: emit2( 0x7700 | $2<<4 | $4 ); + emit2( index<<8 ); + break; + default: argerr(); + } + break; + } + /* if ( oprtype[ SRC ] == IM ) + ** { chtype( DST, TYPE_ld ); + ** emit2( mode | 0xD07 | $2<<4 ); + ** if ( mode>>12 == 4 ) emit_ad( addr_inf ); + ** emit4( immed ); + ** break; + ** } + */ + argerr(); + } + ; + + +f3 : DJNZ reg ',' ra + { branch( $1 | $2<<8, $4 ); } + | JR coco1 ra + { branch( $1 | $2<<8, $3 ); } + | CALR ra + { branch( $1, $2 ); } + ; + + +f4 : LDR reg ',' ra + { ldrel( $1 | $2, $4 ); } + | LDR ra ',' reg + { ldrel( $1 | 0x200 | $4, $2 ); } + | LDAR R32 ',' ra + { ldrel( $1 | $2, $4 ); } + ; + + +f5 : F5_1L reg option + { if ( $3 < 0 ) + { warning( "neg src results in a right shift!" ); + warning( "warning only"); + } + shiftcode( $1 | $2<<4, $3 ); + } + | F5_1R reg option2 + { if ( $3 > 0 ) + { warning( "pos src results in a left shift!" ); + warning( "warning only"); + } + shiftcode( $1 | $2<<4, $3 ); + } + ; + +option2 : ',' imexpr + { $$ = $2; } + | /* empty */ + { $$ = -1; } + ; + +f6 : LDM dst ',' src ',' imexpr + { switch( oprtype[ DST ] ) + { case REG: chtype( SRC, TYPE_ldm ); + ldmcode( $1 | $4<<4, $2, $6 ); + break; + default: switch( oprtype[ SRC ] ) + { case REG: chtype( DST, TYPE_ldm ); + ldmcode($1+8 | $2<<4, $4, $6); + break; + default: argerr(); + } + } + } + | F6_4 ir ',' ir ',' R16 + { /* For translate instructions the roles of $2 and $4 + ** are interchanged with respect to the other + ** instructions of this group. + */ + if ( ($1 & 0xB8FF) == $1 ) + { /* translate instruction */ + emit2( ($1 & ~0xF0) | $2<<4 ); + emit2( ($1 & 0xF0)>>4 | $6<<8 | $4<<4 ); + } + else + { emit2( ($1 & ~0xF0) | $4<<4 ); + emit2( ($1 & 0xF0)>>4 | $6<<8 | $2<<4 ); + } + } + | F6_5 dst ',' ir ',' R16 coco2 + { switch( oprtype[ DST ] ) + { case REG: if ( bitset($1,1) ) argerr(); break; + case IR : if ( !bitset($1,1) ) argerr(); break; + default : argerr(); + } + emit2( $1 | $4<<4 ); + emit2( $6<<8 | $2<<4 | $7 ); + } + | F6_6 reg ',' R16 + { emit2( $1 | $2<<4 ); + emit2( $4<<8 ); + } + ; + + +f7 : IN reg ',' da + { emit2( $1 | 0xA04 | $2<<4 ); +#ifdef RELOCATION + newrelo(adr_inf.typ, RELO2|RELBR); +#endif + emit2( (short)addr_inf.val ); /* i/o address */ + } + | OUT da ',' reg + { emit2( $1 | 0xA06 | $4<<4 ); +#ifdef RELOCATION + newrelo(adr_inf.typ, RELO2|RELBR); +#endif + emit2( (short)addr_inf.val ); /* i/o address */ + } + | IN reg ',' ir + { if ( bitset($1,0) ) argerr(); + emit2( $1 | 0xC00 | $4<<4 | $2 ); + } + | OUT ir ',' reg + { if ( bitset($1,0) ) argerr(); + emit2( $1 | 0xE00 | $2<<4 | $4 ); + } + ; + + +f8 : LDCTL ctlargs + { emit2( $1 | $2 ); } + | LDCTLB ctlbargs + { emit2( $1 | $2 ); } + | MREQ reg + { emit2( $1 | $2<<4 ); } + ; +ctlargs : CTLR ',' R16 + { $$ = $3<<4 | $1 | 8; } + | R16 ',' CTLR + { $$ = $1<<4 | $3; } + ; +ctlbargs: CTLRFLAGS ',' R8 + { $$ = $3<<4 | $1 | 8;} + | R8 ',' CTLRFLAGS + { $$ = $1<<4 | $3; } + ; + + + + +f9 : F9_1 flags + { emit2( $1 | $2 ); } + | F9_2 ints + { emit2( $1 | $2 ); } + | F9_3 + { emit2( $1 ); } + | RET + { emit2( $1 | 8 ); } + | RET CC + { emit2( $1 | $2 ); } + | SC imexpr + { fit(fit8($2)); + emit2( $1 | $2 ); + } + ; +flags : flags ',' FLAG + { $$ = $1 | $3; } + | FLAG + { $$ = $1; } + ; +ints : ints ',' INTCB + { $$ = $1 | $3; } + | INTCB + { $$ = $1; } + ; + + + + +coco1 : CC ',' + { $$ = $1; } + | /* empty */ + { $$ = 8; } + ; +coco2 : ',' CC + { $$ = $2; } + | /* empty */ + { $$ = 8; } + ; +option : ',' imexpr + { $$ = $2; } + | /* empty */ + { $$ = 1; } + ; +/* `imexpr', just as `im', is used to implement immediate data. +** But `imexpr' is used in those cases where the immediate value +** always will fit into 16 bits, so (long) `immed' is not needed. +** Those cases are in `option', `option2', f9-`SC', f6-`LDM' and +** f1-`LDK'. +*/ +imexpr : '$' absexp + { $$ = $2; } + ; +/* Destination (dst) as well as source (src) operands never +** have RA as addressing mode, except for some instructions of the +** F3 and F4 instruction format group. In those cases RA is even +** the only addressing mode which is allowed. This is why `ra' +** has a yacc-rule not being part of `opr'. +*/ +ra : expr + { $$ = $1; } + ; +dst : { operand = DST;} + opr + { $$ = $2; } + ; +src : { operand = SRC;} + opr + { $$ = $2; } + ; +opr : reg + { settype( REG ); } + | im + { settype( IM ); } + | ir + { settype( IR ); } + | da + { settype( DA ); } + | x + { settype( X ); } + | ba + { settype( BA ); } + | bx + { settype( BX ); } + ; +reg : R8 + | R16 + | R32 + | R64 + ; +im : '$' expr + { $$ = 0; + immed = $2; + } + | '$' '<' '<' expr '>' '>' expr + { $$ = 0; + immed.typ = combine($4.typ, $7.typ, '+'); + immed.val = $4.val<<16 | $7.val; + } + ; +ir : '*' R32 + { if ( $2 == 0 ) regerr(); + $$ = $2; + } + ; +da : expr + { $$ = 0; + addr_inf = $1; + } + | '<' '<' expr '>' '>' expr + { $$ = 0; + addr_inf.typ = combine( $3.typ, $6.typ, '+' ); + addr_inf.val = $3.val<<16 | $6.val; + } + ; +x : expr '(' R16 ')' + { if ( $3 == 0 ) regerr(); + $$ = $3; + addr_inf = $1; + } + | '<' '<' expr '>' '>' expr '(' R16 ')' + { if ( $8 == 0 ) regerr(); + $$ = $8; + addr_inf.typ = combine( $3.typ, $6.typ, '+' ); + addr_inf.val = $3.val<<16 | $6.val; + } + ; +ba : R32 '(' '$' expr ')' + { if ( $1 == 0 ) regerr(); + $$ = $1; + displ = $4; + } + ; +bx : R32 '(' R16 ')' + { if ( $1 == 0 || $3 == 0 ) regerr(); + $$ = $1; + index = $3; + } + ; diff --git a/mach/z8000/as/mach5.c b/mach/z8000/as/mach5.c new file mode 100644 index 00000000..93724b67 --- /dev/null +++ b/mach/z8000/as/mach5.c @@ -0,0 +1,174 @@ +#define RCSID5 "$Header$" + +settype( type ) +int type; +{ oprtype[ operand ] = type; } + + +short twolog( s ) +short s; +{ short twopower = 0; + while ( (s>>=1) != 0 ) twopower++; + return( twopower ); +} + + +setmode( opr ) +short opr; +{ mode = modetbl[ twolog( oprtype[opr] ) ] << 12; } + + +chtype( opr, typerange ) +short opr, + typerange; +/* Check type of 'opr' with given 'typerange' and +** set the global var 'mode'. +*/ +{ if ( (oprtype[opr] & typerange) != oprtype[opr] ) argerr(); + else /* We have a permitted type for 'opr'. */ setmode( opr ); +} + + +chreg( opc, reg ) +short opc, reg; +{ switch( opc ) { + case 0xB10A: case 0x1B00: case 0x1900: + /* R32 expected */ if (reg & 1) regerr(); break; + case 0xB107: case 0x1A00: case 0x1800: + /* R64 expected */ if (reg & 3) regerr(); break; + } +} + +ATYPE checkaddr( addr ) +valu_t addr; +/* Called by functions emit_ad() and branch(). */ +{ ATYPE addr_struct; + + addr_struct.seg = addr >> 16; + addr_struct.off = addr & 0xFFFF; + if ( addr_struct.seg < 0 ) addr_struct.seg = 0; +#ifdef ASLD + else fit(fit7(addr_struct.seg)); +#endif + return( addr_struct ); +} + +emit_ad( ad_inf ) +expr_t ad_inf; +/* When the type of an operand is 'da' or 'x' this function +** emits the address. +*/ +{ short sm; + ATYPE addr; + + addr = checkaddr( ad_inf.val ); + /* Always the long format is emitted, because the binary + ** will be downloaded into one z8000-segment with offset + ** 0x0000 upto 0xFFFF,so the chance we can use the short + ** format is very small. + */ + emit2( 1<<15 | addr.seg<<8 ); + emit2( addr.off ); /* ??? relocation information ??? */ +} + + +ldmcode( wrd1, wrd2, num ) +int wrd1, wrd2, num; +{ fit(fit4(num-1)); + emit2( mode | wrd1 ); + emit2( wrd2<<8 | num-1 ); + if ( mode>>12 == 4 ) emit_ad( addr_inf ); +} + + +valu_t adjust( absval ) +valu_t absval; +{ valu_t val = absval - DOTVAL - 2; + + if ( pass == PASS_2 && val > 0 ) val -= DOTGAIN; + return( val ); +} + + +branch( opc, exp ) +short opc; +expr_t exp; +/* This routine determines for the F3 format instructions whether the +** relative address is small enough to fit in normal code; If this is +** so normal code is emitted otherwise 'long' code is emitted contai- +** ning the direct address. +*/ +{ short longopc = 0, reladdr = 0, sm2, sm4; + valu_t val; + ATYPE addr; + + val = adjust(exp.val) >> 1; + if ( (exp.typ & ~S_DOT) != DOTTYP ) sm2 = sm4 = 0; + else + { switch ( opc & 0xF000 ) + { case DJNZ_: sm2 = fit7( -val ); + reladdr = -val; + break; + case JR_: sm2 = fits8( val ); + reladdr = low8( val ); + longopc = 0x5E00 | (opc>>8 & 0xF); + break; + case CALR_: sm2 = fits12( -val ); + reladdr = low12( -val ); + longopc = 0x5F00; + break; + } + sm4 = sm2 || fit8( (short)exp.val ); + } + switch ( opc & 0xF000 ) + { case DJNZ_: fit( sm2 ); /* djnz must be short */ + emit2( opc | reladdr ); + break; + case JR_: case CALR_: + sm4 = small(sm4, 2); + sm2 = small(sm2, 2); + if ( sm2 ) emit2( opc | reladdr ); + else /* replace by jp/call da */ + { emit2( longopc ); + addr = checkaddr( exp.val ); + if ( sm4 ) /* short-offset */ + emit2( addr.seg<<8 | addr.off ); + else + { emit2( 1<<15 | addr.seg<<8 ); + emit2( addr.off ); + } + } + } +} + + +ldrel( opc, exp ) +short opc; +expr_t exp; +/* This routine determines for the F4 format instructions whether the +** address is within the same segment (meaning a relative address of +** less than 16 bits); If this is so normal code is emitted otherwise +** an error message is given. +*/ +{ if ( pass >= PASS_2 && (exp.typ & ~S_DOT) != DOTTYP ) + serror( "relative too far" ); + emit2( opc ); + emit2( (short)adjust(exp.val) ); +} + + +shiftcode( w1, w2 ) +int w1, w2; +{ switch( w1 & 0x0F04 ) + { /* Remember: w2 negative means right shift ! */ + case 0x200: /*byte*/ fit( w2>=-8 && w2<=8 ); break; + case 0x300: /*word*/ fit( w2>=-16 && w2<=16 ); break; + case 0x304: /*long*/ fit( w2>=-32 && w2<=32 ); break; + } + emit2( w1 ); + emit2( w2 ); +} + + +argerr() +{ serror( "illegal operand" ); } From e8f6a27f1e060b570b4a4f7f983fa4c3e8178baf Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 5 Dec 1986 17:10:12 +0000 Subject: [PATCH 0369/1625] Initial revision --- mach/z8000/as/README | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 mach/z8000/as/README diff --git a/mach/z8000/as/README b/mach/z8000/as/README new file mode 100644 index 00000000..a23897bf --- /dev/null +++ b/mach/z8000/as/README @@ -0,0 +1,2 @@ +How do we generate relocation information for the strangely encoded +z8000-segments? From e4bf2b5799660ebe2bed3b7b8c019f645d375831 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 5 Dec 1986 17:12:24 +0000 Subject: [PATCH 0370/1625] *** empty log message *** --- mach/z80/as/mach0.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/mach/z80/as/mach0.c b/mach/z80/as/mach0.c index e7718347..0b334c5e 100644 --- a/mach/z80/as/mach0.c +++ b/mach/z80/as/mach0.c @@ -1,4 +1,3 @@ -#define DUK #define RCSID0 "$Header$" /* @@ -7,4 +6,3 @@ #define THREE_PASS /* distinguish short and long branches */ #define LISTING /* enable listing facilities */ #define RELOCATION -#define NOLD From d9fa4a7e85489b146937ef9598a3a010841e780e Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 5 Dec 1986 17:17:03 +0000 Subject: [PATCH 0371/1625] Working version. --- mach/i86/as/mach0.c | 5 ++--- mach/i86/as/mach5.c | 51 ++++++++++++++++++++++++++++++++++++--------- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/mach/i86/as/mach0.c b/mach/i86/as/mach0.c index d5bce732..d52820c2 100644 --- a/mach/i86/as/mach0.c +++ b/mach/i86/as/mach0.c @@ -1,4 +1,3 @@ -#define DUK #define RCSID0 "$Header$" /* @@ -6,5 +5,5 @@ */ #define THREE_PASS /* branch and offset optimization */ #define LISTING /* enable listing facilities */ -#define RELOCATION -#define NOLD +#define RELOCATION /* generate relocation info */ +#define DEBUG 0 diff --git a/mach/i86/as/mach5.c b/mach/i86/as/mach5.c index ecb8bd15..b98c73b0 100644 --- a/mach/i86/as/mach5.c +++ b/mach/i86/as/mach5.c @@ -11,7 +11,7 @@ ea_1(param) { emit1(mrg_1 | param); switch(mrg_1 >> 6) { case 0: - if (mrg_1 == 6) { + if (mrg_1 == 6 || (mrg_1 & 040)) { #ifdef RELOCATION RELOMOVE(relonami, rel_1); newrelo(exp_1.typ, RELO2); @@ -138,7 +138,12 @@ addop(opc) register opc; { if (mrg_2 >= 0300) { emit1(opc); ea_1((mrg_2&7)<<3); } else if ((mrg_2 & 040) && mrg_1 == 0300) { - emit1(opc | 4); emitx((opc&1)+1,exp_2.val); + emit1(opc | 4); +#ifdef RELOCATION + RELOMOVE(relonami, rel_2); + newrelo(exp_2.typ, (opc&1)? RELO2 : RELO1); +#endif + emitx(exp_2.val, (opc&1)+1); } else if (mrg_2 & 040) { if ((opc&1) == 0) { emit1(0200); @@ -148,9 +153,15 @@ addop(opc) register opc; { } else { emit1(0203); opc &= ~1; } - ea_1(opc & 070); emitx((opc&1)+1,exp_2.val); + ea_1(opc & 070); +#ifdef RELOCATION + RELOMOVE(relonami, rel_2); + newrelo(exp_2.typ, (opc&1)? RELO2 : RELO1); +#endif + emitx(exp_2.val, (opc&1)+1); } else if (mrg_1 >= 0300) { - emit1(opc | 2); ea_2((mrg_1&7)<<3); + emit1(opc | 2); + ea_2((mrg_1&7)<<3); } else badsyntax(); } @@ -185,6 +196,7 @@ callop(opc) register opc; { regsize(1); if (mrg_1 & 040) { if (opc == (040+(0351<<8))) { + RELOMOVE(relonami, rel_1); branch(0353,exp_1); } else { exp_1.val -= (DOTVAL+3); @@ -219,9 +231,20 @@ test(opc) register opc; { if ((mrg_1 & 040) || mrg_2 >= 0300) reverse(); if ((mrg_2 & 040) && mrg_1 == 0300) { - emit1(0250 | opc); emitx((opc&1)+1,exp_2.val); + emit1(0250 | opc); +#ifdef RELOCATION + RELOMOVE(relonami, rel_2); + newrelo(exp_2.typ, (opc&1)? RELO2 : RELO1); +#endif + emitx(exp_2.val, (opc&1)+1); } else if (mrg_2 & 040) { - emit1(0366 | opc); ea_1(0<<3); emitx((opc&1)+1,exp_2.val); + emit1(0366 | opc); + ea_1(0<<3); +#ifdef RELOCATION + RELOMOVE(relonami, rel_2); + newrelo(exp_2.typ, (opc&1)? RELO2 : RELO1); +#endif + emitx(exp_2.val, (opc&1)+1); } else if (mrg_1 >= 0300) { emit1(0204 | opc); ea_2((mrg_1&7)<<3); } else @@ -238,10 +261,18 @@ mov(opc) register opc; { } else if (mrg_2 & 040) { if (mrg_1 >= 0300) { emit1(0260 | opc<<3 | (mrg_1&7)); - emitx((opc&1)+1,exp_2.val); +#ifdef RELOCATION + RELOMOVE(relonami, rel_2); + newrelo(exp_2.typ, (opc&1)? RELO2 : RELO1); +#endif + emitx(exp_2.val, (opc&1)+1); } else { emit1(0306 | opc); ea_1(0<<3); - emitx((opc&1)+1,exp_2.val); +#ifdef RELOCATION + RELOMOVE(relonami, rel_2); + newrelo(exp_2.typ, (opc&1)? RELO2 : RELO1); +#endif + emitx(exp_2.val, (opc&1)+1); } } else if (mrg_2 == 0300 && mrg_1 == 6) { emit1(0242 | opc); @@ -253,8 +284,8 @@ mov(opc) register opc; { } else if (mrg_1 == 0300 && mrg_2 == 6) { emit1(0240 | opc); #ifdef RELOCATION - RELOMOVE(relonami, rel_1); - newrelo(exp_1.typ, RELO2); + RELOMOVE(relonami, rel_2); + newrelo(exp_2.typ, RELO2); #endif emit2(exp_2.val); } else if (mrg_2 >= 0300) { From bdfa65a9624fed9d88e2b451fbe968dc64528263 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 5 Dec 1986 17:18:54 +0000 Subject: [PATCH 0372/1625] *** empty log message *** --- mach/i86/as/READ_ME | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mach/i86/as/READ_ME b/mach/i86/as/READ_ME index c4a937c5..b620073b 100644 --- a/mach/i86/as/READ_ME +++ b/mach/i86/as/READ_ME @@ -3,3 +3,7 @@ the universal assembler and are too dependent on its innards. I have no idea in what way they should be changed. Duk Bekema + +I adapted them to the new framework. It appears to work now. + + Ceriel Jacobs From b9823c8daaecc8f5c02eeff90e63b45d2607219a Mon Sep 17 00:00:00 2001 From: erikb Date: Mon, 8 Dec 1986 08:58:21 +0000 Subject: [PATCH 0373/1625] corrected basename() --- lang/cem/cemcom/cem.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lang/cem/cemcom/cem.c b/lang/cem/cemcom/cem.c index 8a3d2e8b..1607dfb5 100644 --- a/lang/cem/cemcom/cem.c +++ b/lang/cem/cemcom/cem.c @@ -586,10 +586,13 @@ basename(str, dst) if (*p1++ == '/') p2 = p1; p1--; - if (*--p1 == '.') + if (*--p1 == '.') { *p1 = '\0'; - while (*dst++ = *p2++) {} - *p1 = '.'; + while (*dst++ = *p2++) {} + *p1 = '.'; + } + else + while (*dst++ = *p2++) {} } int From 0dd7ecb8301fd5a752d13e899c44276d9cdb6c0b Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 8 Dec 1986 09:24:58 +0000 Subject: [PATCH 0374/1625] *** empty log message *** --- mach/s2650/as/mach0.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/mach/s2650/as/mach0.c b/mach/s2650/as/mach0.c index 6a2eda23..bb22a9bc 100644 --- a/mach/s2650/as/mach0.c +++ b/mach/s2650/as/mach0.c @@ -1,4 +1,3 @@ -#define DUK #define RCSID0 "$Header$" /* @@ -8,4 +7,3 @@ #define BYTES_REVERSED #define THREE_PASS #define RELOCATION -#define NOLD From e1d7671027350ca5b8f559f68a5609c0c3b196a5 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 8 Dec 1986 10:39:13 +0000 Subject: [PATCH 0375/1625] Only call "newrelo" when needed. --- mach/6809/as/mach4.c | 29 +++++++++++++++++++---------- mach/6809/as/mach5.c | 6 ++++-- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/mach/6809/as/mach4.c b/mach/6809/as/mach4.c index deb9a017..8ea2aba3 100644 --- a/mach/6809/as/mach4.c +++ b/mach/6809/as/mach4.c @@ -35,7 +35,8 @@ operation { emit1(0x10); emit1($1); $2.val -= (DOTVAL+2); #ifdef RELOCATION - newrelo($2.typ, RELPC|RELO2|RELBR); + if (rflag != 0 && PASS_RELO) + newrelo($2.typ, RELPC|RELO2|RELBR); #endif emit2($2.val); } @@ -44,7 +45,8 @@ operation { emit1($1); $2.val -= (DOTVAL+2); #ifdef RELOCATION - newrelo($2.typ, RELPC|RELO2|RELBR); + if (rflag != 0 && PASS_RELO) + newrelo($2.typ, RELPC|RELO2|RELBR); #endif emit2($2.val); } @@ -52,7 +54,8 @@ operation IMMED '#' expr { emit1($1); #ifdef RELOCATION - newrelo($3.typ, RELO1); + if (rflag != 0 && PASS_RELO) + newrelo($3.typ, RELO1); #endif emit1($3.val); } @@ -64,13 +67,15 @@ operation case 0x0C: case 0x0E: #ifdef RELOCATION - newrelo($3.typ, RELO2|RELBR); + if (rflag != 0 && PASS_RELO) + newrelo($3.typ, RELO2|RELBR); #endif emit2($3.val); - break; + break; default: #ifdef RELOCATION - newrelo($3.typ, RELO1); + if (rflag != 0 && PASS_RELO) + newrelo($3.typ, RELO1); #endif emit1($3.val); break; @@ -83,7 +88,8 @@ operation else emit1or2($1 - 0x10); #ifdef RELOCATION - newrelo($3.typ, RELO1); + if (rflag != 0 && PASS_RELO) + newrelo($3.typ, RELO1); #endif emit1($3.val); } @@ -91,7 +97,8 @@ operation XOP '>' expr { emit1or2($1 + 0x10); #ifdef RELOCATION - newrelo($3.typ, RELO2|RELBR); + if (rflag != 0 && PASS_RELO) + newrelo($3.typ, RELO2|RELBR); #endif emit2($3.val); } @@ -129,7 +136,8 @@ operation { emit1or2($1); emit1(0x9F); #ifdef RELOCATION - newrelo($3.typ, RELO2|RELBR); + if (rflag != 0 && PASS_RELO) + newrelo($3.typ, RELO2|RELBR); #endif emit2($3.val); } @@ -158,7 +166,8 @@ operation } else { emit1or2($1 + 0x10); #ifdef RELOCATION - newrelo($2.typ, RELO2|RELBR); + if (rflag != 0 && PASS_RELO) + newrelo($2.typ, RELO2|RELBR); #endif emit2($2.val); } diff --git a/mach/6809/as/mach5.c b/mach/6809/as/mach5.c index 9f6eab7f..ad2f7a4f 100644 --- a/mach/6809/as/mach5.c +++ b/mach/6809/as/mach5.c @@ -35,7 +35,8 @@ expr_t exp; emit1(opc); if (sm == 0) { #ifdef RELOCATION - newrelo(exp.typ, RELPC|RELO2|RELBR); + if (rflag != 0 && PASS_RELO) + newrelo(exp.typ, RELPC|RELO2|RELBR); #endif emit2(dist); } else @@ -93,7 +94,8 @@ expr_t exp; } else { emit1(0x89 + reg + ind); #ifdef RELOCATION - newrelo(exp.typ, RELO2|RELBR); + if (rflag != 0 && PASS_RELO) + newrelo(exp.typ, RELO2|RELBR); #endif emit2(exp.val); } From 8591d582847072446330566b172a1e7fdaeca384 Mon Sep 17 00:00:00 2001 From: erikb Date: Tue, 9 Dec 1986 08:19:55 +0000 Subject: [PATCH 0376/1625] added: file_info.h --- lang/cem/cemcom/Files | 1 + 1 file changed, 1 insertion(+) diff --git a/lang/cem/cemcom/Files b/lang/cem/cemcom/Files index 26fb953f..13726df5 100644 --- a/lang/cem/cemcom/Files +++ b/lang/cem/cemcom/Files @@ -42,6 +42,7 @@ expression.g faulty.h field.c field.str +file_info.h idf.c idf.str init.c From 36ec50a706ab67d74beea6cbb7ea6f2fcd758591 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 9 Dec 1986 11:13:14 +0000 Subject: [PATCH 0377/1625] Adapted to new assembler --- mach/mantra/int/mloop0 | 53 +++-- mach/mantra/int/mloop1 | 487 +++++++++++++++++++++-------------------- mach/mantra/int/mloop2 | 5 + mach/mantra/int/mloop3 | 5 + mach/mantra/int/mloop4 | 5 + mach/mantra/int/mloop5 | 5 + mach/mantra/int/mloop6 | 13 +- mach/mantra/int/mloop7 | 5 + mach/mantra/int/mloop8 | 5 + mach/mantra/int/mloop9 | 55 ++--- mach/mantra/int/mloopa | 55 ++--- mach/mantra/int/mloopb | 25 ++- mach/mantra/int/mloopc | 113 +++++----- mach/mantra/int/mloope | 11 +- 14 files changed, 456 insertions(+), 386 deletions(-) diff --git a/mach/mantra/int/mloop0 b/mach/mantra/int/mloop0 index e3541a69..6cd9bdb3 100644 --- a/mach/mantra/int/mloop0 +++ b/mach/mantra/int/mloop0 @@ -1,3 +1,21 @@ + .define filb + .define curproc + .define pd + .define nproc + .define retarea + .define retsize + .define hp + .define maxcount + .define firstp + .define globmax + .define tblmax + .define ml + .define argc +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text !--------------------------------------------------------------------------- ! START OF THE PROGRAM !--------------------------------------------------------------------------- @@ -18,10 +36,10 @@ move.l (a2),filb !interpreter name in filb sub.l #1,(sp) bgt 0f - .data + .sect .data emfile: .asciz "e.out" .align 2 - .text + .sect .text move.l 4(sp),a0 !4(sp) is argv move.l #emfile,(a0) !pointer to e.out in argp1 add.l #1,(sp) !only 1 argument in this case @@ -103,10 +121,10 @@ datloop: cmp.l a4,a5 ; bhi 9f !Go on filling data asl.l #2,d1 ; move.l -4(a6,d1),a0 jmp (a0) - .data -datswi: .long dat1; .long dat2; .long dat3; .long dat4 - .long dat5; .long dat6; .long dat6; .long dofloat - .text + .sect .data +datswi: .data4 dat1; .data4 dat2; .data4 dat3; .data4 dat4 + .data4 dat5; .data4 dat6; .data4 dat6; .data4 dofloat + .sect .text dat0: add.l #4,a1 move.b (a4)+,-(a1) ; move.b (a4)+,-(a1) @@ -331,7 +349,7 @@ procinf: move.l #1,maxcount !count pointer for first procedure 1: countlabel: - .data + .sect .data skipdisp: .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; .byte 0; @@ -394,7 +412,7 @@ skipdisp: .byte 2; .byte 0; .byte 2; .byte 2; .byte 2; .byte 2; .byte 2; .byte 2; .byte 0; .byte 2; .byte 0; .byte 1; .byte 2; .byte 0; .byte 0; .byte 2; - .text + .sect .text move.l globmax,d1 move.l d1,a3 #if prof @@ -458,12 +476,12 @@ nofile: mov #0xD,d0 ; bra notrap1 badarg: move.l eb,a6 badarg1: mov #0xE,d0 ; bra notrap1 toolarge: mov #0xF,d0 ; bra notrap1 - .data + .sect .data retsize: .space 2 retarea: .space 32 - .bss + .sect .bss argc: .space 4 argv: .space 4 envp: .space 4 @@ -488,18 +506,5 @@ pb: .space 4 pd: .space 4 hp: .space 4 - .define filb - .define curproc - .define pd - .define nproc - .define retarea - .define retsize - .define hp - .define maxcount - .define firstp - .define globmax - .define tblmax - .define ml - .define argc - .text + .sect .text diff --git a/mach/mantra/int/mloop1 b/mach/mantra/int/mloop1 index e22bb6c1..801bdc18 100644 --- a/mach/mantra/int/mloop1 +++ b/mach/mantra/int/mloop1 @@ -1,3 +1,8 @@ +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text !------------------------------------------------------------------------------- ! Main loop of the interpreter starts here !---------------------------------------------------------------------------- @@ -92,7 +97,7 @@ bra zle_s0 ; bra zlt_s0 ; bra zne_s0 ; bra zne_s_1 bra zre_lw ; bra zre_w0 ; bra zrl__1W ; bra zrl__2W bra zrl_w_1 ; bra zrl_nw -.errnz .-dispat-1016 +.assert .-dispat-1016 == 0 !----------------------------------------------------------------------------- ! Two byte opcodes come here for decoding of second byte !---------------------------------------------------------------------------- @@ -166,7 +171,7 @@ bra zle_l ; bra zlt_l ; bra zne_l ; bra zrf_l bra zrf_z ; bra zrl_pw ; bra dch_z ; bra exg_s0 bra exg_l ; bra exg_z ; bra lpb_z ; bra gto_l -.errnz .-dispae1-640 +.assert .-dispae1-640 == 0 !---------------------------------------------------------------------------- @@ -214,7 +219,7 @@ bra stl_qpw ; bra stl_qnw ; bra zeq_q ; bra zge_q bra zgt_q ; bra zle_q ; bra zlt_q ; bra zne_q bra zre_qw ; bra zrl_qpw ; bra zrl_qnw -.errnz .-dispae2-220 +.assert .-dispae2-220 == 0 !------------------------------------------------------------------------------ ! timeinf tables, first the unescaped opcodes these tables are parallel @@ -235,255 +240,255 @@ bra zre_qw ; bra zrl_qpw ; bra zrl_qnw #if prof - .data + .sect .data #ifdef lword timeinf: -.long 32 ; .long 37 ; .long 37 ; .long 37 -.long 37 ; .long 37 ; .long 37 ; .long 37 -.long 37 ; .long 37 ; .long 37 ; .long 37 -.long 37 ; .long 37 ; .long 37 ; .long 37 -.long 37 ; .long 37 ; .long 37 ; .long 37 -.long 37 ; .long 37 ; .long 37 ; .long 37 -.long 37 ; .long 37 ; .long 37 ; .long 37 -.long 37 ; .long 37 ; .long 37 ; .long 37 -.long 37 ; .long 37 ; .long 134 ; .long 00 -.long 42 ; .long 00 ; .long 56 ; .long 40 -.long 40 ; .long 42 ; .long 42 ; .long 42 -.long 42 ; .long 38 ; .long 38 ; .long 38 -.long 38 ; .long 38 ; .long 42 ; .long 71 -.long 52 ; .long 52 ; .long 52 ; .long 52 -.long 118 ; .long 52 ; .long 52 ; .long 55 -.long 45 ; .long 45 ; .long 36 ; .long 43 -.long 231 ; .long 231 ; .long 231 ; .long 231 -.long 231 ; .long 231 ; .long 231 ; .long 231 -.long 231 ; .long 231 ; .long 231 ; .long 231 -.long 231 ; .long 231 ; .long 231 ; .long 231 -.long 231 ; .long 231 ; .long 231 ; .long 231 -.long 231 ; .long 231 ; .long 231 ; .long 231 -.long 231 ; .long 231 ; .long 231 ; .long 231 -.long 233 ; .long 00 ; .long 00 ; .long 75 -.long 00 ; .long 58 ; .long 00 ; .long 54 -.long 91 ; .long 113 ; .long 116 ; .long 38 -.long 59 ; .long 59 ; .long 36 ; .long 00 -.long 1100 ; .long 77; .long 32 ; .long 66 -.long 51 ; .long 45 ; .long 49 ; .long 49 -.long 53 ; .long 127 ; .long 52 ; .long 152 -.long 54 ; .long 57 ; .long 57 ; .long 57 -.long 57 ; .long 57 ; .long 57 ; .long 57 -.long 72 ; .long 61 ; .long 34 ; .long 37 -.long 59 ; .long 51 ; .long 58 ; .long 178 -.long 48 ; .long 83 ; .long 66 ; .long 50 -.long 66 ; .long 63 ; .long 88 ; .long 140 -.long 60 ; .long 62 ; .long 44 ; .long 44 -.long 66 ; .long 49 ; .long 41 ; .long 52 -.long 36 ; .long 38 ; .long 42 ; .long 69 -.long 63 ; .long 63 ; .long 63 ; .long 63 -.long 63 ; .long 66 ; .long 54 ; .long 59 -.long 59 ; .long 59 ; .long 57 ; .long 276 -.long 44 ; .long 75 ; .long 91 ; .long 107 -.long 123 ; .long 193 ; .long 68 ; .long 68 -.long 38 ; .long 38 ; .long 38 ; .long 38 -.long 38 ; .long 38 ; .long 38 ; .long 38 -.long 38 ; .long 38 ; .long 38 ; .long 38 -.long 50 ; .long 50 ; .long 58 ; .long 38 -.long 64 ; .long 00 ; .long 205 ; .long 00 -.long 64 ; .long 79 ; .long 112 ; .long 171 -.long 1094 ; .long 136 ; .long 00 ; .long 38 -.long 00 ; .long 66 ; .long 144 ; .long 60 -.long 62 ; .long 57 ; .long 71 ; .long 54 -.long 61 ; .long 61 ; .long 72 ; .long 47 -.long 54 ; .long 60 ; .long 46 ; .long 58 -.long 73 ; .long 88; .long 103 ; .long 181 -.long 68 ; .long 73 ; .long 38 ; .long 38 -.long 38 ; .long 38 ; .long 38 ; .long 38 -.long 38 ; .long 54 ; .long 47 ; .long 47 -.long 47 ; .long 47 ; .long 56 ; .long 47 -.long 50 ; .long 91 ; .long 47 ; .long 47 -.long 47 ; .long 47 ; .long 47 ; .long 51 -.long 71 ; .long 54 ; .long 38 ; .long 38 -.long 54 ; .long 73 ; .long 63 ; .long 99 +.data4 32 ; .data4 37 ; .data4 37 ; .data4 37 +.data4 37 ; .data4 37 ; .data4 37 ; .data4 37 +.data4 37 ; .data4 37 ; .data4 37 ; .data4 37 +.data4 37 ; .data4 37 ; .data4 37 ; .data4 37 +.data4 37 ; .data4 37 ; .data4 37 ; .data4 37 +.data4 37 ; .data4 37 ; .data4 37 ; .data4 37 +.data4 37 ; .data4 37 ; .data4 37 ; .data4 37 +.data4 37 ; .data4 37 ; .data4 37 ; .data4 37 +.data4 37 ; .data4 37 ; .data4 134 ; .data4 00 +.data4 42 ; .data4 00 ; .data4 56 ; .data4 40 +.data4 40 ; .data4 42 ; .data4 42 ; .data4 42 +.data4 42 ; .data4 38 ; .data4 38 ; .data4 38 +.data4 38 ; .data4 38 ; .data4 42 ; .data4 71 +.data4 52 ; .data4 52 ; .data4 52 ; .data4 52 +.data4 118 ; .data4 52 ; .data4 52 ; .data4 55 +.data4 45 ; .data4 45 ; .data4 36 ; .data4 43 +.data4 231 ; .data4 231 ; .data4 231 ; .data4 231 +.data4 231 ; .data4 231 ; .data4 231 ; .data4 231 +.data4 231 ; .data4 231 ; .data4 231 ; .data4 231 +.data4 231 ; .data4 231 ; .data4 231 ; .data4 231 +.data4 231 ; .data4 231 ; .data4 231 ; .data4 231 +.data4 231 ; .data4 231 ; .data4 231 ; .data4 231 +.data4 231 ; .data4 231 ; .data4 231 ; .data4 231 +.data4 233 ; .data4 00 ; .data4 00 ; .data4 75 +.data4 00 ; .data4 58 ; .data4 00 ; .data4 54 +.data4 91 ; .data4 113 ; .data4 116 ; .data4 38 +.data4 59 ; .data4 59 ; .data4 36 ; .data4 00 +.data4 1100 ; .data4 77; .data4 32 ; .data4 66 +.data4 51 ; .data4 45 ; .data4 49 ; .data4 49 +.data4 53 ; .data4 127 ; .data4 52 ; .data4 152 +.data4 54 ; .data4 57 ; .data4 57 ; .data4 57 +.data4 57 ; .data4 57 ; .data4 57 ; .data4 57 +.data4 72 ; .data4 61 ; .data4 34 ; .data4 37 +.data4 59 ; .data4 51 ; .data4 58 ; .data4 178 +.data4 48 ; .data4 83 ; .data4 66 ; .data4 50 +.data4 66 ; .data4 63 ; .data4 88 ; .data4 140 +.data4 60 ; .data4 62 ; .data4 44 ; .data4 44 +.data4 66 ; .data4 49 ; .data4 41 ; .data4 52 +.data4 36 ; .data4 38 ; .data4 42 ; .data4 69 +.data4 63 ; .data4 63 ; .data4 63 ; .data4 63 +.data4 63 ; .data4 66 ; .data4 54 ; .data4 59 +.data4 59 ; .data4 59 ; .data4 57 ; .data4 276 +.data4 44 ; .data4 75 ; .data4 91 ; .data4 107 +.data4 123 ; .data4 193 ; .data4 68 ; .data4 68 +.data4 38 ; .data4 38 ; .data4 38 ; .data4 38 +.data4 38 ; .data4 38 ; .data4 38 ; .data4 38 +.data4 38 ; .data4 38 ; .data4 38 ; .data4 38 +.data4 50 ; .data4 50 ; .data4 58 ; .data4 38 +.data4 64 ; .data4 00 ; .data4 205 ; .data4 00 +.data4 64 ; .data4 79 ; .data4 112 ; .data4 171 +.data4 1094 ; .data4 136 ; .data4 00 ; .data4 38 +.data4 00 ; .data4 66 ; .data4 144 ; .data4 60 +.data4 62 ; .data4 57 ; .data4 71 ; .data4 54 +.data4 61 ; .data4 61 ; .data4 72 ; .data4 47 +.data4 54 ; .data4 60 ; .data4 46 ; .data4 58 +.data4 73 ; .data4 88; .data4 103 ; .data4 181 +.data4 68 ; .data4 73 ; .data4 38 ; .data4 38 +.data4 38 ; .data4 38 ; .data4 38 ; .data4 38 +.data4 38 ; .data4 54 ; .data4 47 ; .data4 47 +.data4 47 ; .data4 47 ; .data4 56 ; .data4 47 +.data4 50 ; .data4 91 ; .data4 47 ; .data4 47 +.data4 47 ; .data4 47 ; .data4 47 ; .data4 51 +.data4 71 ; .data4 54 ; .data4 38 ; .data4 38 +.data4 54 ; .data4 73 ; .data4 63 ; .data4 99 timeinf1: -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 58 -.long 63 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 -.long 40 ; .long 40 ; .long 40 ; .long 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 58 +.data4 63 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 +.data4 40 ; .data4 40 ; .data4 40 ; .data4 40 timeinf2: -.long 29 ; .long 29 ; .long 29 ; .long 29 -.long 29 ; .long 29 ; .long 29 ; .long 29 -.long 29 ; .long 29 ; .long 29 ; .long 29 -.long 29 ; .long 29 ; .long 29 ; .long 29 -.long 29 ; .long 29 ; .long 29 ; .long 29 -.long 29 ; .long 29 ; .long 29 ; .long 29 -.long 29 ; .long 29 ; .long 29 ; .long 29 -.long 29 ; .long 29 ; .long 29 ; .long 29 -.long 29 ; .long 29 ; .long 29 ; .long 29 -.long 29 ; .long 29 ; .long 29 ; .long 29 -.long 29 ; .long 29 ; .long 29 ; .long 29 -.long 29 ; .long 29 ; .long 29 ; .long 29 -.long 29 ; .long 29 ; .long 29 ; .long 29 -.long 29 ; .long 29 ; .long 29 +.data4 29 ; .data4 29 ; .data4 29 ; .data4 29 +.data4 29 ; .data4 29 ; .data4 29 ; .data4 29 +.data4 29 ; .data4 29 ; .data4 29 ; .data4 29 +.data4 29 ; .data4 29 ; .data4 29 ; .data4 29 +.data4 29 ; .data4 29 ; .data4 29 ; .data4 29 +.data4 29 ; .data4 29 ; .data4 29 ; .data4 29 +.data4 29 ; .data4 29 ; .data4 29 ; .data4 29 +.data4 29 ; .data4 29 ; .data4 29 ; .data4 29 +.data4 29 ; .data4 29 ; .data4 29 ; .data4 29 +.data4 29 ; .data4 29 ; .data4 29 ; .data4 29 +.data4 29 ; .data4 29 ; .data4 29 ; .data4 29 +.data4 29 ; .data4 29 ; .data4 29 ; .data4 29 +.data4 29 ; .data4 29 ; .data4 29 ; .data4 29 +.data4 29 ; .data4 29 ; .data4 29 #else timeinf: -.long 30 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 127 ; .long 00 -.long 36 ; .long 42 ; .long 56 ; .long 40 -.long 40 ; .long 42 ; .long 42 ; .long 42 -.long 36 ; .long 39 ; .long 39 ; .long 39 -.long 39 ; .long 39 ; .long 41 ; .long 67 -.long 48 ; .long 48 ; .long 48 ; .long 48 -.long 97 ; .long 48 ; .long 48 ; .long 55 -.long 45 ; .long 45 ; .long 36 ; .long 43 -.long 211 ; .long 211 ; .long 211 ; .long 211 -.long 211 ; .long 211 ; .long 211 ; .long 211 -.long 211 ; .long 211 ; .long 211 ; .long 211 -.long 211 ; .long 211 ; .long 211 ; .long 211 -.long 211 ; .long 211 ; .long 211 ; .long 211 -.long 211 ; .long 211 ; .long 211 ; .long 211 -.long 211 ; .long 211 ; .long 211 ; .long 211 -.long 213 ; .long 00 ; .long 00 ; .long 66 -.long 00 ; .long 50 ; .long 54 ; .long 54 -.long 75 ; .long 105 ; .long 106 ; .long 34 -.long 53 ; .long 54 ; .long 32 ; .long 00 -.long 146 ; .long 77; .long 30 ; .long 61 -.long 47 ; .long 43 ; .long 43 ; .long 43 -.long 49 ; .long 104 ; .long 36 ; .long 121 -.long 54 ; .long 56 ; .long 56 ; .long 56 -.long 56 ; .long 56 ; .long 56 ; .long 56 -.long 72 ; .long 61 ; .long 34 ; .long 37 -.long 58 ; .long 50 ; .long 57 ; .long 160 -.long 40 ; .long 73 ; .long 56 ; .long 42 -.long 56 ; .long 59 ; .long 80 ; .long 111 -.long 54 ; .long 56 ; .long 40 ; .long 40 -.long 66 ; .long 49 ; .long 41 ; .long 50 -.long 32 ; .long 36 ; .long 38 ; .long 63 -.long 57 ; .long 57 ; .long 57 ; .long 57 -.long 57 ; .long 62 ; .long 48 ; .long 53 -.long 53 ; .long 53 ; .long 53 ; .long 227 -.long 42 ; .long 69 ; .long 83 ; .long 97 -.long 111 ; .long 160 ; .long 62 ; .long 62 -.long 34 ; .long 34 ; .long 34 ; .long 34 -.long 34 ; .long 34 ; .long 34 ; .long 34 -.long 34 ; .long 34 ; .long 34 ; .long 34 -.long 45 ; .long 45 ; .long 58 ; .long 38 -.long 64 ; .long 00 ; .long 71 ; .long 200 -.long 56 ; .long 79 ; .long 103 ; .long 156 -.long 148 ; .long 121 ; .long 00 ; .long 34 -.long 38 ; .long 57 ; .long 128 ; .long 55 -.long 57 ; .long 50 ; .long 66 ; .long 49 -.long 56 ; .long 56 ; .long 68 ; .long 43 -.long 50 ; .long 56 ; .long 46 ; .long 54 -.long 65 ; .long 76; .long 87 ; .long 138 -.long 63 ; .long 68 ; .long 34 ; .long 34 -.long 34 ; .long 34 ; .long 34 ; .long 34 -.long 34 ; .long 49 ; .long 41 ; .long 41 -.long 41 ; .long 41 ; .long 54 ; .long 45 -.long 48 ; .long 73 ; .long 45 ; .long 45 -.long 45 ; .long 45 ; .long 45 ; .long 49 -.long 66 ; .long 49 ; .long 34 ; .long 34 -.long 49 ; .long 68 ; .long 63 ; .long 99 +.data4 30 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 127 ; .data4 00 +.data4 36 ; .data4 42 ; .data4 56 ; .data4 40 +.data4 40 ; .data4 42 ; .data4 42 ; .data4 42 +.data4 36 ; .data4 39 ; .data4 39 ; .data4 39 +.data4 39 ; .data4 39 ; .data4 41 ; .data4 67 +.data4 48 ; .data4 48 ; .data4 48 ; .data4 48 +.data4 97 ; .data4 48 ; .data4 48 ; .data4 55 +.data4 45 ; .data4 45 ; .data4 36 ; .data4 43 +.data4 211 ; .data4 211 ; .data4 211 ; .data4 211 +.data4 211 ; .data4 211 ; .data4 211 ; .data4 211 +.data4 211 ; .data4 211 ; .data4 211 ; .data4 211 +.data4 211 ; .data4 211 ; .data4 211 ; .data4 211 +.data4 211 ; .data4 211 ; .data4 211 ; .data4 211 +.data4 211 ; .data4 211 ; .data4 211 ; .data4 211 +.data4 211 ; .data4 211 ; .data4 211 ; .data4 211 +.data4 213 ; .data4 00 ; .data4 00 ; .data4 66 +.data4 00 ; .data4 50 ; .data4 54 ; .data4 54 +.data4 75 ; .data4 105 ; .data4 106 ; .data4 34 +.data4 53 ; .data4 54 ; .data4 32 ; .data4 00 +.data4 146 ; .data4 77; .data4 30 ; .data4 61 +.data4 47 ; .data4 43 ; .data4 43 ; .data4 43 +.data4 49 ; .data4 104 ; .data4 36 ; .data4 121 +.data4 54 ; .data4 56 ; .data4 56 ; .data4 56 +.data4 56 ; .data4 56 ; .data4 56 ; .data4 56 +.data4 72 ; .data4 61 ; .data4 34 ; .data4 37 +.data4 58 ; .data4 50 ; .data4 57 ; .data4 160 +.data4 40 ; .data4 73 ; .data4 56 ; .data4 42 +.data4 56 ; .data4 59 ; .data4 80 ; .data4 111 +.data4 54 ; .data4 56 ; .data4 40 ; .data4 40 +.data4 66 ; .data4 49 ; .data4 41 ; .data4 50 +.data4 32 ; .data4 36 ; .data4 38 ; .data4 63 +.data4 57 ; .data4 57 ; .data4 57 ; .data4 57 +.data4 57 ; .data4 62 ; .data4 48 ; .data4 53 +.data4 53 ; .data4 53 ; .data4 53 ; .data4 227 +.data4 42 ; .data4 69 ; .data4 83 ; .data4 97 +.data4 111 ; .data4 160 ; .data4 62 ; .data4 62 +.data4 34 ; .data4 34 ; .data4 34 ; .data4 34 +.data4 34 ; .data4 34 ; .data4 34 ; .data4 34 +.data4 34 ; .data4 34 ; .data4 34 ; .data4 34 +.data4 45 ; .data4 45 ; .data4 58 ; .data4 38 +.data4 64 ; .data4 00 ; .data4 71 ; .data4 200 +.data4 56 ; .data4 79 ; .data4 103 ; .data4 156 +.data4 148 ; .data4 121 ; .data4 00 ; .data4 34 +.data4 38 ; .data4 57 ; .data4 128 ; .data4 55 +.data4 57 ; .data4 50 ; .data4 66 ; .data4 49 +.data4 56 ; .data4 56 ; .data4 68 ; .data4 43 +.data4 50 ; .data4 56 ; .data4 46 ; .data4 54 +.data4 65 ; .data4 76; .data4 87 ; .data4 138 +.data4 63 ; .data4 68 ; .data4 34 ; .data4 34 +.data4 34 ; .data4 34 ; .data4 34 ; .data4 34 +.data4 34 ; .data4 49 ; .data4 41 ; .data4 41 +.data4 41 ; .data4 41 ; .data4 54 ; .data4 45 +.data4 48 ; .data4 73 ; .data4 45 ; .data4 45 +.data4 45 ; .data4 45 ; .data4 45 ; .data4 49 +.data4 66 ; .data4 49 ; .data4 34 ; .data4 34 +.data4 49 ; .data4 68 ; .data4 63 ; .data4 99 timeinf1: -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 49 -.long 54 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 -.long 35 ; .long 35 ; .long 35 ; .long 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 49 +.data4 54 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 +.data4 35 ; .data4 35 ; .data4 35 ; .data4 35 timeinf2: -.long 25 ; .long 25 ; .long 25 ; .long 25 -.long 25 ; .long 25 ; .long 25 ; .long 25 -.long 25 ; .long 25 ; .long 25 ; .long 25 -.long 25 ; .long 25 ; .long 25 ; .long 25 -.long 25 ; .long 25 ; .long 25 ; .long 25 -.long 25 ; .long 25 ; .long 25 ; .long 25 -.long 25 ; .long 25 ; .long 25 ; .long 25 -.long 25 ; .long 25 ; .long 25 ; .long 25 -.long 25 ; .long 25 ; .long 25 ; .long 25 -.long 25 ; .long 25 ; .long 25 ; .long 25 -.long 25 ; .long 25 ; .long 25 ; .long 25 -.long 25 ; .long 25 ; .long 25 ; .long 25 -.long 25 ; .long 25 ; .long 25 ; .long 25 -.long 25 ; .long 25 ; .long 25 +.data4 25 ; .data4 25 ; .data4 25 ; .data4 25 +.data4 25 ; .data4 25 ; .data4 25 ; .data4 25 +.data4 25 ; .data4 25 ; .data4 25 ; .data4 25 +.data4 25 ; .data4 25 ; .data4 25 ; .data4 25 +.data4 25 ; .data4 25 ; .data4 25 ; .data4 25 +.data4 25 ; .data4 25 ; .data4 25 ; .data4 25 +.data4 25 ; .data4 25 ; .data4 25 ; .data4 25 +.data4 25 ; .data4 25 ; .data4 25 ; .data4 25 +.data4 25 ; .data4 25 ; .data4 25 ; .data4 25 +.data4 25 ; .data4 25 ; .data4 25 ; .data4 25 +.data4 25 ; .data4 25 ; .data4 25 ; .data4 25 +.data4 25 ; .data4 25 ; .data4 25 ; .data4 25 +.data4 25 ; .data4 25 ; .data4 25 ; .data4 25 +.data4 25 ; .data4 25 ; .data4 25 #endif #endif - .text + .sect .text diff --git a/mach/mantra/int/mloop2 b/mach/mantra/int/mloop2 index b466d822..51069e11 100644 --- a/mach/mantra/int/mloop2 +++ b/mach/mantra/int/mloop2 @@ -1,3 +1,8 @@ +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text !-------------------------------------------------------------------------- ! Load constant , load local , store local !-------------------------------------------------------------------------- diff --git a/mach/mantra/int/mloop3 b/mach/mantra/int/mloop3 index cdc52480..283db0f0 100644 --- a/mach/mantra/int/mloop3 +++ b/mach/mantra/int/mloop3 @@ -1,3 +1,8 @@ +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text !--------------------------------------------------------------------- ! STORE GROUP !--------------------------------------------------------------------- diff --git a/mach/mantra/int/mloop4 b/mach/mantra/int/mloop4 index cf1d1ee6..41339172 100644 --- a/mach/mantra/int/mloop4 +++ b/mach/mantra/int/mloop4 @@ -1,3 +1,8 @@ +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text !---------------------------------------------------------------------------- ! CLEARS , INCREMENTS , DECREMENTS !----------------------------------------------------------------------------- diff --git a/mach/mantra/int/mloop5 b/mach/mantra/int/mloop5 index 80b54c44..ab48545e 100644 --- a/mach/mantra/int/mloop5 +++ b/mach/mantra/int/mloop5 @@ -1,3 +1,8 @@ +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text !-----------------------------------------------------------------------------. ! ARRAY GROUP !------------------------------------------------------------------------------- diff --git a/mach/mantra/int/mloop6 b/mach/mantra/int/mloop6 index bba4eb40..c5aa47af 100644 --- a/mach/mantra/int/mloop6 +++ b/mach/mantra/int/mloop6 @@ -1,3 +1,10 @@ + .define mlu4 + .define dvu4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text !---------------------------------------------------------------------------- ! SIGNED INTEGER ARITHMETIC !------------------------------------------------------------------------------ @@ -117,8 +124,7 @@ mli_2W: ! multiplicant in d1 . Returns 4 byte result in d0 . If d4=0 overflow did ! not occur on the multiplication , else it did . - .define mlu4 - .text + .sect .text mlu4: move.l d1,d3 ; move.l d0,d2 swap d2 ; swap d3 @@ -232,8 +238,7 @@ dvi4: move.l (sp)+,d5 !Expects d0 divisor , d1 dividend. Gives d1 quotient ,d3 remainder - .define dvu4 - .text + .sect .text dvu4: #if test tst.l d0 ; bne 1f diff --git a/mach/mantra/int/mloop7 b/mach/mantra/int/mloop7 index 2bbf739a..5e5aee7b 100644 --- a/mach/mantra/int/mloop7 +++ b/mach/mantra/int/mloop7 @@ -1,3 +1,8 @@ +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text !------------------------------------------------------------------------------ ! UNSIGNED ARITHMETIC !----------------------------------------------------------------------------- diff --git a/mach/mantra/int/mloop8 b/mach/mantra/int/mloop8 index 611868cb..ae6c5a34 100644 --- a/mach/mantra/int/mloop8 +++ b/mach/mantra/int/mloop8 @@ -1,3 +1,8 @@ +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text !------------------------------------------------------------------------- ! TEST AND BRANCH GROUP !------------------------------------------------------------------------- diff --git a/mach/mantra/int/mloop9 b/mach/mantra/int/mloop9 index ba012d6c..f07d4d1f 100644 --- a/mach/mantra/int/mloop9 +++ b/mach/mantra/int/mloop9 @@ -1,3 +1,10 @@ + .define ignmask + .define itoa +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text !--------------------------------------------------------------------------- ! MISCELLANEOUS !---------------------------------------------------------------------------- @@ -148,10 +155,9 @@ gto_l: move.l d6,a0 ; move.b (a3)+,-(sp) lim_z: move.w ignmask,-(sp) ; jmp (a4) sim_z: move.w (sp)+,ignmask ; jmp (a4) - .bss + .sect .bss ignmask: .space 2 - .define ignmask - .text + .sect .text !--------------------------------------------------------------------------- lor_s0: move.l d6,d0 ; move.b (a3)+,d0 @@ -204,15 +210,14 @@ lblnop: lea nopln+16,a0 ; move.l (a6),d1 add.l wrd+4,sp jmp (a4) - .data + .sect .data nopln: .asciz "line number nop sp \n" .align 2 - .text + .sect .text !unsigned to ascii for integers , a0 is address of first character ! d1 contains integer. Output is 11 characters of which the first is a space. - .define itoa - .text + .sect .text itoa: move.l #9,d4 ; add.l #11,a0 move.l #10,d0 @@ -291,23 +296,23 @@ mon_z: mov (sp)+,d0 ; bmi e_badmon add.l #syscal,d0 ; move.l d0,a0 move.l (a0),a0 ; jmp (a0) - .data + .sect .data syscal: -.long e_badmon ; .long hlt_z ; .long _fork ; .long _read -.long _write ; .long _open ; .long _close ; .long _wait -.long _creat ; .long _link ; .long _unlink ; .long e_badmon -.long _chdir ; .long e_badmon ; .long _mknod ; .long _chmod -.long _chown ; .long _break ; .long _stat ; .long _lseek -.long _getpid ; .long _mount ; .long _umount ; .long _setuid -.long _getuid ; .long _stime ; .long _ptrace ; .long _alarm -.long _fstat ; .long _pause ; .long _utime ; .long e_badmon -.long e_badmon ; .long _access ; .long _nice ; .long _ftime -.long _sync ; .long _kill ; .long e_badmon ; .long e_badmon -.long e_badmon ; .long _dup ; .long _pipe ; .long _times -.long _profil ; .long e_badmon ; .long _setgid ; .long _getgid -.long _sigtrp ; .long e_badmon ; .long e_badmon ; .long _acct -.long e_badmon ; .long _lock ; .long _ioctl ; .long e_badmon -.long _mpxcall ; .long e_badmon ; .long e_badmon ; .long _exece -.long _umask ; .long _chroot ; .long e_badmon ; .long e_badmon +.data4 e_badmon ; .data4 hlt_z ; .data4 _fork ; .data4 _read +.data4 _write ; .data4 _open ; .data4 _close ; .data4 _wait +.data4 _creat ; .data4 _link ; .data4 _unlink ; .data4 e_badmon +.data4 _chdir ; .data4 e_badmon ; .data4 _mknod ; .data4 _chmod +.data4 _chown ; .data4 _break ; .data4 _stat ; .data4 _lseek +.data4 _getpid ; .data4 _mount ; .data4 _umount ; .data4 _setuid +.data4 _getuid ; .data4 _stime ; .data4 _ptrace ; .data4 _alarm +.data4 _fstat ; .data4 _pause ; .data4 _utime ; .data4 e_badmon +.data4 e_badmon ; .data4 _access ; .data4 _nice ; .data4 _ftime +.data4 _sync ; .data4 _kill ; .data4 e_badmon ; .data4 e_badmon +.data4 e_badmon ; .data4 _dup ; .data4 _pipe ; .data4 _times +.data4 _profil ; .data4 e_badmon ; .data4 _setgid ; .data4 _getgid +.data4 _sigtrp ; .data4 e_badmon ; .data4 e_badmon ; .data4 _acct +.data4 e_badmon ; .data4 _lock ; .data4 _ioctl ; .data4 e_badmon +.data4 _mpxcall ; .data4 e_badmon ; .data4 e_badmon ; .data4 _exece +.data4 _umask ; .data4 _chroot ; .data4 e_badmon ; .data4 e_badmon - .text + .sect .text diff --git a/mach/mantra/int/mloopa b/mach/mantra/int/mloopa index 547b20e8..37de48fb 100644 --- a/mach/mantra/int/mloopa +++ b/mach/mantra/int/mloopa @@ -1,3 +1,9 @@ + .define e_memflt +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text e_array: cl -(sp) ; bra error e_range: mov #0x1,-(sp) ; bra error e_set: mov #0x2,-(sp) ; bra error @@ -24,7 +30,6 @@ e_badgto: mov #0x1B,-(sp) ; bra error flnim: mov #0xB,-(sp) ; bra error no8bar: mov #0xC,-(sp) ; bra error - .define e_memflt !--------------------------------------------------------------------------- ! ERRORS AND TRAPS !---------------------------------------------------------------------------- @@ -85,9 +90,9 @@ sig_z: move.l (sp),d0 move.l d0,uerrorp jmp (a4) - .data -uerrorp: .long 0x-1 - .text + .sect .data +uerrorp: .data4 0x-1 + .sect .text !----------------------------------------------------------------------------- !FIRST INFORMATION ABOUT THE KIND OF THE ERROR @@ -153,14 +158,14 @@ notrap1: comp #29,d0 !ERROR NUMBER STILL IN d0 !-------------------------------------------------------------------------- hlt_z: add.l #4,sp !remove return address #if prof - .data + .sect .data emprof: .asciz "em_profile\0" .align 2 - .bss + .sect .bss profile: .space 4 ltime: .space 4 profsiz: .space 4 - .text + .sect .text tst.l firstp beq lhalt mov #0x1B6,-(sp) @@ -184,13 +189,13 @@ profsiz: .space 4 mov d0,-(sp) bsr _write add.l wrd+4,sp - .data + .sect .data emflow: .asciz "em_flow\0" .align 2 - .bss + .sect .bss lflow: .space 4 flowsiz: .space 4 - .text + .sect .text #endif #if count tst.l firstp @@ -202,20 +207,20 @@ flowsiz: .space 4 mov (sp)+,d0 move.l lcount,a4 bsr tabprint - .data + .sect .data emcount: .asciz "em_count\0" .align 2 - .bss + .sect .bss lcount: .space 4 countsiz: .space 4 #endif #if opfreq - .data + .sect .data emopf: .asciz "em_opfreq\0" .align - .bss + .sect .bss counttab: .space 1884 - .text + .sect .text mov #0x1B6,-(sp) pea emopf bsr _creat @@ -228,13 +233,13 @@ counttab: .space 1884 add.l wrd+4,sp #endif #if count+flow+prof - .bss + .sect .bss countfld: .space 4 !COUNT NUMBER - NUMBER OF LINE 1 OF PROC countptr: .space 4 !COUNT NUMBER OF CURRENT LINE #endif lhalt: #if last - .text + .sect .text mov #0x1B6,-(sp) pea emlast bsr _creat @@ -286,20 +291,20 @@ lhalt: clr.l (a5)+ !skip file name bra 4b !only new line 9: - .data + .sect .data emlast: .asciz "em_last" mess1: .asciz "no line processed yet\n" mess2: .asciz "\nfile :" mess3: .asciz " \n" .align 2 - .bss + .sect .bss lasttable: .space 512 linused: .space 4 #endif - .text + .sect .text halt: bsr _exit - .data + .sect .data emerr: .asciz "ARRAY BOUND ERROR \n" .asciz "RANGE BOUND ERROR \n" @@ -338,7 +343,7 @@ emess: !----------------------------------------------------------------------------- ! SUBROUTINES FOR THE INTERPRETOR !------------------------------------------------------------------------------ - .text + .sect .text #if last nexttab: move.l linused,a5 add.l #8,a5 @@ -351,7 +356,7 @@ nexttab: move.l linused,a5 #if count+prof !SUBROUTINE FOR PRINTING TABLES . EXPECTS BOTTOM OF TABLE IN a4 AND FILE !DESCRIPTOR IN d0 .IN maxcount NUMBER OF 4 BYTE WORDS IN THE TABLE. - .text + .sect .text tabprint: mov d0,-(sp) !KEEP FILE DESCRIPTOR FOR WRITING lea buffer,a3 move.l firstp,a5 !IN a5 POINTER TO CURRENT PROC. @@ -411,7 +416,7 @@ tabprint: mov d0,-(sp) !KEEP FILE DESCRIPTOR FOR WRITING move.l #0,a6 !NO NEXT PROCEDURE. bra 8b - .data + .sect .data buffer: .asciz " \n" - .text + .sect .text #endif diff --git a/mach/mantra/int/mloopb b/mach/mantra/int/mloopb index ab6a1fa9..8e21fa72 100644 --- a/mach/mantra/int/mloopb +++ b/mach/mantra/int/mloopb @@ -1,3 +1,8 @@ +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _sigtrp: move.l (sp)+,d2 !save return address mov (sp)+,d1 !trapno in d1 mov (sp)+,d4 !signo in d4 @@ -28,16 +33,16 @@ sig_bad: mov 22,-(sp) !_signal. If pointer 0 trapping is mov d4,-(sp) !pointer ,signo to be trapped bsr _signal jmp (a4) - .data -sig_adr: .long sig1 ; .long sig2 ; .long sig3 ; .long 0 - .long 0 ; .long 0 ; .long 0 ; .long 0 - .long 0 ; .long 0 ; .long sig11 ; .long sig12 - .long sig13 ; .long sig14 ; .long sig15 ; .long sig16 -sig_trp: .long -2 ; .long -2 ; .long -2 ; .long -2 - .long -2 ; .long -2 ; .long -2 ; .long -2 - .long -2 ; .long -2 ; .long 21 ; .long 25 - .long -2 ; .long -2 ; .long -2 ; .long -2 - .text + .sect .data +sig_adr: .data4 sig1 ; .data4 sig2 ; .data4 sig3 ; .data4 0 + .data4 0 ; .data4 0 ; .data4 0 ; .data4 0 + .data4 0 ; .data4 0 ; .data4 sig11 ; .data4 sig12 + .data4 sig13 ; .data4 sig14 ; .data4 sig15 ; .data4 sig16 +sig_trp: .data4 -2 ; .data4 -2 ; .data4 -2 ; .data4 -2 + .data4 -2 ; .data4 -2 ; .data4 -2 ; .data4 -2 + .data4 -2 ; .data4 -2 ; .data4 21 ; .data4 25 + .data4 -2 ; .data4 -2 ; .data4 -2 ; .data4 -2 + .sect .text !the next procedures map the catched signal to em errors. The em error !procedure will handle this. sig1: pea retutrap diff --git a/mach/mantra/int/mloopc b/mach/mantra/int/mloopc index 7b60d6ff..c859d1c1 100644 --- a/mach/mantra/int/mloopc +++ b/mach/mantra/int/mloopc @@ -1,3 +1,8 @@ +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text !THIS FILE CONTAINS THE SYSTEM CALLS FOR PMDS-II AS SUBROUTINES FOR THE !EM-INTERPRETER. a1 CONTAINS A POINTER TO THE RETURN AREA . EACH SUBROUTINE !EXPECTS ITS DATA IN THE FORM EM PRODUCES AND GIVES ITS RESULTS AS EM @@ -11,17 +16,17 @@ _exit: move.l (sp),(a1) bsr st241 #endif trap #0 - .short 1 + .data2 1 _fork: move.l (sp),(a1) trap #0 - .short 2 + .data2 2 lea 4(sp),sp bcs 2f tst.l d0 !PID OF CHILD IN PARENT, 0 IN CHILD bne 1f trap #0 - .short 20 + .data2 20 mov d1,-(sp) !PID OF PARENT IN d1 mov #1,-(sp) !(PID OF CHILD IN D0),FLAG 1 IN CHILD bra 0f @@ -40,7 +45,7 @@ _read: move.l (sp),(a1) bsr st241 #endif trap #0 - .short 3 + .data2 3 sys0: lea 16(sp),sp bcc 1f mov d0,-(sp) @@ -56,7 +61,7 @@ _write: move.l (sp),(a1) bsr st241 #endif trap #0 - .short 4 + .data2 4 bra sys0 _open: move.l (sp),(a1) @@ -64,7 +69,7 @@ _open: move.l (sp),(a1) bsr st243 #endif trap #0 - .short 5 + .data2 5 sys1: lea 12(sp),sp sys5: bcc 1f mov d0,-(sp) @@ -80,7 +85,7 @@ _close: move.l (sp),(a1) bsr st241 #endif trap #0 - .short 6 + .data2 6 sys3: lea 8(sp),sp sys4: bcc 1f mov d0,-(sp) @@ -92,7 +97,7 @@ sys4: bcc 1f _wait: move.l (sp),(a1) trap #0 - .short 7 + .data2 7 sys6: lea 4(sp),sp bcc 1f mov d0,-(sp) @@ -109,23 +114,23 @@ _creat: move.l (sp),(a1) bsr st243 #endif trap #0 - .short 8 + .data2 8 bra sys1 _link: move.l (sp),(a1) trap #0 - .short 9 + .data2 9 lea 12(sp),sp bra sys4 _unlink: move.l (sp),(a1) trap #0 - .short 10 + .data2 10 bra sys3 _chdir: move.l (sp),(a1) trap #0 - .short 12 + .data2 12 bra sys3 _mknod: move.l (sp),(a1) @@ -133,7 +138,7 @@ _mknod: move.l (sp),(a1) bsr st244 #endif trap #0 - .short 14 + .data2 14 lea 16(sp),sp bra sys4 @@ -142,7 +147,7 @@ _chmod: move.l (sp),(a1) bsr st243 #endif trap #0 - .short 15 + .data2 15 lea 12(sp),sp bra sys4 @@ -151,13 +156,13 @@ _chown: move.l (sp),(a1) bsr st244 #endif trap #0 - .short 16 + .data2 16 lea 16(sp),sp bra sys4 _break: move.l (sp),(a1) trap #0 - .short 17 + .data2 17 lea 8(sp),sp bcc 1f mov d0,-(sp) @@ -168,13 +173,13 @@ _break: move.l (sp),(a1) 2: move.l (a1),a0 jmp (a0) - .data -nd: .long endbss - .text + .sect .data +nd: .data4 endbss + .sect .text _stat: move.l (sp),(a1) trap #0 - .short 18 + .data2 18 lea 12(sp),sp bra sys4 @@ -183,7 +188,7 @@ _lseek: move.l (sp),(a1) bsr st245 #endif trap #0 - .short 19 + .data2 19 lea 16(sp),sp bcc 1f mov d0,-(sp) @@ -197,7 +202,7 @@ _lseek: move.l (sp),(a1) _getpid: move.l (sp),(a1) trap #0 - .short 20 + .data2 20 add.l #4,sp mov d0,-(sp) move.l (a1),a0 @@ -208,13 +213,13 @@ _mount: move.l (sp),(a1) bsr st246 #endif trap #0 - .short 21 + .data2 21 lea 16(sp),sp bra sys4 _umount: move.l (sp),(a1) trap #0 - .short 22 + .data2 22 bra sys3 _setuid: move.l (sp),(a1) @@ -222,12 +227,12 @@ _setuid: move.l (sp),(a1) bsr st241 #endif trap #0 - .short 23 + .data2 23 bra sys3 _getuid: move.l (sp),(a1) trap #0 - .short 24 + .data2 24 sys7: add.l #4,sp mov d1,-(sp) mov d0,-(sp) @@ -236,7 +241,7 @@ sys7: add.l #4,sp _stime: move.l (sp),(a1) trap #0 - .short 25 + .data2 25 bra sys3 _ptrace: move.l (sp),(a1) @@ -244,7 +249,7 @@ _ptrace: move.l (sp),(a1) bsr st247 #endif trap #0 - .short 26 + .data2 26 lea 20(sp),sp bra sys5 @@ -254,7 +259,7 @@ _alarm: move.l (sp),(a1) clr.w 4(sp) #endif trap #0 - .short 27 + .data2 27 lea 8(sp),sp mov d0,-(sp) move.l (a1),a0 @@ -265,17 +270,17 @@ _fstat: move.l (sp),(a1) bsr st241 #endif trap #0 - .short 28 + .data2 28 lea 12(sp),sp bra sys4 _pause: trap #0 - .short 29 + .data2 29 rts _utime: move.l (sp),(a1) trap #0 - .short 30 + .data2 30 lea 12(sp),sp bra sys4 @@ -284,7 +289,7 @@ _access: move.l (sp),(a1) bsr st248 #endif trap #0 - .short 33 + .data2 33 lea 12(sp),sp bra sys4 @@ -293,17 +298,17 @@ _nice: bsr 241 #endif trap #0 - .short 34 + .data2 34 move.l (sp)+,(sp) rts _ftime: move.l (sp),(a1) trap #0 - .short 35 + .data2 35 bra sys3 _sync: trap #0 - .short 36 + .data2 36 rts _kill: move.l (sp),(a1) @@ -311,7 +316,7 @@ _kill: move.l (sp),(a1) bsr st248 #endif trap #0 - .short 37 + .data2 37 lea 12(sp),sp bra sys4 @@ -320,22 +325,22 @@ _dup: move.l (sp),(a1) bsr st248 #endif trap #0 - .short 38 + .data2 38 bra sys1 _pipe: move.l (sp),(a1) trap #0 - .short 42 + .data2 42 bra sys6 _times: trap #0 - .short 43 + .data2 43 move.l (sp),a0 add.l #8,sp jmp (a0) _profil: trap #0 - .short 44 + .data2 44 move.l (sp),a0 lea 20(sp),sp jmp (a0) @@ -345,12 +350,12 @@ _setgid: move.l (sp),(a1) bsr st241 #endif trap #0 - .short 46 + .data2 46 bra sys3 _getgid: move.l (sp),(a1) trap #0 - .short 47 + .data2 47 bra sys7 @@ -360,7 +365,7 @@ _signal: move.l (sp)+,retaddr move.l d4,-(sp) move.l retaddr,-(sp) trap #0 - .short 48 + .data2 48 lea 12(sp),sp !remove arguments bcc 1f mov d0,-(sp) @@ -370,20 +375,20 @@ _signal: move.l (sp)+,retaddr cl -(sp) 2: move.l retaddr,a0 jmp (a0) - .data -retaddr: .long 0 - .text + .sect .data +retaddr: .data4 0 + .sect .text _acct: move.l (sp),(a1) trap #0 - .short 51 + .data2 51 bra sys3 _lock: move.l (sp),(a1) #ifndef lword bsr st241 #endif trap #0 - .short 53 + .data2 53 bra sys3 _ioctl: move.l (sp),(a1) @@ -391,7 +396,7 @@ _ioctl: move.l (sp),(a1) bsr st248 #endif trap #0 - .short 54 + .data2 54 lea 16(sp),sp bra sys4 @@ -400,13 +405,13 @@ _mpxcall: move.l (sp),(a1) bsr st241 #endif trap #0 - .short 56 + .data2 56 lea 12(sp),sp bra sys4 _exece: move.l (sp),(a1) trap #0 - .short 59 + .data2 59 lea 16(sp),sp bra sys4 @@ -415,7 +420,7 @@ _umask: move.l (sp),(a1) bsr st241 #endif trap #0 - .short 60 + .data2 60 add.l #8,sp mov d0,-(sp) move.l (a1),a0 @@ -423,7 +428,7 @@ _umask: move.l (sp),(a1) _chroot: move.l (sp),(a1) trap #0 - .short 61 + .data2 61 bra sys3 diff --git a/mach/mantra/int/mloope b/mach/mantra/int/mloope index a79543aa..9507ea16 100644 --- a/mach/mantra/int/mloope +++ b/mach/mantra/int/mloope @@ -1,6 +1,11 @@ - .text +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text + .sect .text end: - .bss + .sect .bss endbss: - .data + .sect .data enddata: From 4de92e9ab673169b0d6f0d3137387d6bfd37c45b Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 9 Dec 1986 17:41:06 +0000 Subject: [PATCH 0378/1625] minor fixes --- lang/m2/comp/LLlex.c | 18 +++++++++--------- lang/m2/comp/Makefile | 36 +++++++++++++++++++----------------- lang/m2/comp/Version.c | 2 +- lang/m2/comp/declar.g | 7 ++++++- lang/m2/comp/def.c | 5 ----- lang/m2/comp/defmodule.c | 8 +++----- lang/m2/comp/main.c | 2 +- lang/m2/comp/make.next | 7 +++++++ lang/m2/comp/node.c | 5 ----- lang/m2/comp/options.c | 15 ++++++++++++--- lang/m2/comp/program.g | 5 +++++ lang/m2/comp/type.c | 10 ---------- 12 files changed, 63 insertions(+), 57 deletions(-) create mode 100755 lang/m2/comp/make.next diff --git a/lang/m2/comp/LLlex.c b/lang/m2/comp/LLlex.c index 0a4f021a..158bc296 100644 --- a/lang/m2/comp/LLlex.c +++ b/lang/m2/comp/LLlex.c @@ -252,7 +252,7 @@ again1: goto again; } else if (nch == EOI) eofseen = 1; - else PushBack(nch); + else PushBack(); } return tk->tk_symb = ch; @@ -292,7 +292,7 @@ again1: crash("(LLlex, STCOMP)"); } if (nch == EOI) eofseen = 1; - else PushBack(nch); + else PushBack(); return tk->tk_symb = ch; case STIDF: @@ -306,7 +306,7 @@ again1: } while(in_idf(ch)); if (ch == EOI) eofseen = 1; - else PushBack(ch); + else PushBack(); *tag++ = '\0'; tk->TOK_IDF = id = str2idf(buf, 1); @@ -373,7 +373,7 @@ again1: state = End; if (ch == 'H') base = 16; else if (ch == EOI) eofseen = 1; - else PushBack(ch); + else PushBack(); } break; @@ -387,7 +387,7 @@ again1: if (ch != 'H') { lexerror("H expected after hex number"); if (ch == EOI) eofseen = 1; - else PushBack(ch); + else PushBack(); } break; @@ -404,7 +404,7 @@ again1: break; } if (ch == EOI) eofseen = 1; - else PushBack(ch); + else PushBack(); ch = *--np; *np++ = '\0'; base = 8; @@ -447,8 +447,8 @@ lexwarning(W_ORDINARY, "character constant out of range"); if (ch == '.') { /* Indeed the '..' token */ - PushBack(ch); - PushBack(ch); + PushBack(); + PushBack(); state = End; base = 10; break; @@ -493,7 +493,7 @@ lexwarning(W_ORDINARY, "character constant out of range"); *np++ = '\0'; if (ch == EOI) eofseen = 1; - else PushBack(ch); + else PushBack(); if (np >= &buf[NUMSIZE]) { tk->TOK_REL = Salloc("0.0", 5); diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index d62ebacf..9178d4ee 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -22,19 +22,19 @@ CSRC = LLlex.c LLmessage.c char.c error.c main.c \ symbol2str.c tokenname.c idf.c input.c type.c def.c \ scope.c misc.c enter.c defmodule.c typequiv.c node.c \ cstoper.c chk_expr.c options.c walk.c casestat.c desig.c \ - code.c tmpvar.c lookup.c Version.c + code.c tmpvar.c lookup.c Version.c next.c COBJ = LLlex.o LLmessage.o char.o error.o main.o \ symbol2str.o tokenname.o idf.o input.o type.o def.o \ scope.o misc.o enter.o defmodule.o typequiv.o node.o \ cstoper.o chk_expr.o options.o walk.o casestat.o desig.o \ - code.o tmpvar.o lookup.o Version.o + code.o tmpvar.o lookup.o Version.o next.o SRC = $(CSRC) $(LSRC) Lpars.c OBJ = $(COBJ) $(LOBJ) Lpars.o # Keep the next entries up to date! GENCFILES= tokenfile.c \ program.c declar.c expression.c statement.c \ - symbol2str.c char.c Lpars.c casestat.c tmpvar.c scope.c + symbol2str.c char.c Lpars.c casestat.c tmpvar.c scope.c next.c GENGFILES= tokenfile.g GENHFILES= errout.h\ idfsize.h numsize.h strsize.h target_sizes.h \ @@ -46,6 +46,7 @@ HFILES= LLlex.h\ walk.h warning.h $(GENHFILES) # GENFILES = $(GENGFILES) $(GENCFILES) $(GENHFILES) +NEXTFILES = def.H type.H node.H scope.C tmpvar.C casestat.C #EXCLEXCLEXCLEXCL @@ -86,23 +87,23 @@ tokenfile.g: tokenname.c make.tokfile symbol2str.c: tokenname.c make.tokcase make.tokcase symbol2str.c -def.h: def.H make.allocd - make.allocd < def.H > def.h +.SUFFIXES: .H .h +.H.h: + ./make.allocd < $*.H > $*.h -type.h: type.H make.allocd - make.allocd < type.H > type.h +.SUFFIXES: .C .c +.C.c: + ./make.allocd < $*.C > $*.c -node.h: node.H make.allocd - make.allocd < node.H > node.h +def.h: make.allocd +type.h: make.allocd +node.h: make.allocd +scope.c: make.allocd +tmpvar.c: make.allocd +casestat.c: make.allocd -scope.c: scope.C make.allocd - make.allocd < scope.C > scope.c - -tmpvar.c: tmpvar.C make.allocd - make.allocd < tmpvar.C > tmpvar.c - -casestat.c: casestat.C make.allocd - make.allocd < casestat.C > casestat.c +next.c: $(NEXTFILES) ./make.next + ./make.next $(NEXTFILES) > next.c char.c: char.tab tab tab -fchar.tab >char.c @@ -154,6 +155,7 @@ desig.o: LLlex.h debug.h debugcst.h def.h desig.h node.h scope.h type.h code.o: LLlex.h Lpars.h debug.h debugcst.h def.h desig.h node.h scope.h standards.h type.h walk.h tmpvar.o: debug.h debugcst.h def.h main.h scope.h type.h lookup.o: LLlex.h debug.h debugcst.h def.h idf.h misc.h node.h scope.h type.h +next.o: debug.h debugcst.h tokenfile.o: Lpars.h program.o: LLlex.h Lpars.h debug.h debugcst.h def.h f_info.h idf.h main.h node.h scope.h type.h warning.h declar.o: LLlex.h Lpars.h chk_expr.h debug.h debugcst.h def.h idf.h main.h misc.h node.h scope.h type.h warning.h diff --git a/lang/m2/comp/Version.c b/lang/m2/comp/Version.c index 3eac6923..129bf329 100644 --- a/lang/m2/comp/Version.c +++ b/lang/m2/comp/Version.c @@ -1 +1 @@ -static char Version[] = "ACK Modula-2 compiler Version 0.9"; +static char Version[] = "ACK Modula-2 compiler Version 0.10"; diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 7e93eb90..12a6e068 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -46,7 +46,12 @@ ProcedureHeading(struct def **pdf; int type;) PROCEDURE IDENT { *pdf = DeclProc(type, dot.TOK_IDF); } FormalParameters(&pr, &parmaddr, &tp)? - { CheckWithDef(*pdf, proc_type(tp, pr, parmaddr)); } + { CheckWithDef(*pdf, proc_type(tp, pr, parmaddr)); + if (tp && IsConstructed(tp)) { +warning(W_STRICT, "procedure \"%s\" has a constructed result type", + (*pdf)->df_idf->id_text); + } + } ; block(struct node **pnd;) : diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index c7e1d5b3..40d613eb 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -16,11 +16,6 @@ #include "node.h" #include "Lpars.h" -struct def *h_def; /* pointer to free list of def structures */ -#ifdef DEBUG -int cnt_def; /* count number of allocated ones */ -#endif - extern int (*c_inp)(); STATIC diff --git a/lang/m2/comp/defmodule.c b/lang/m2/comp/defmodule.c index 0e661447..2fe30ead 100644 --- a/lang/m2/comp/defmodule.c +++ b/lang/m2/comp/defmodule.c @@ -22,6 +22,8 @@ long sys_filesize(); #endif +struct idf *DefId; + STATIC GetFile(name) char *name; @@ -56,7 +58,6 @@ GetDefinitionModule(id, incr) struct def *df; static int level; struct scopelist *vis; - int didread = 0; level += incr; df = lookup(id, GlobalScope, 1); @@ -69,7 +70,7 @@ GetDefinitionModule(id, incr) else { open_scope(CLOSEDSCOPE); if (!is_anon_idf(id) && GetFile(id->id_text)) { - didread = 1; + DefId = id; DefModule(); if (level == 1) { /* The module is directly imported by @@ -95,9 +96,6 @@ GetDefinitionModule(id, incr) } df = lookup(id, GlobalScope, 1); if (! df) { - if (didread) { - error("did not read a DEFINITION MODULE for \"%s\"", id->id_text); - } df = MkDef(id, GlobalScope, D_ERROR); df->df_type = error_type; df->mod_vis = vis; diff --git a/lang/m2/comp/main.c b/lang/m2/comp/main.c index babf4681..80ed934c 100644 --- a/lang/m2/comp/main.c +++ b/lang/m2/comp/main.c @@ -67,7 +67,7 @@ Compile(src, dst) } LineNumber = 1; FileName = src; - DEFPATH[0] = ""; + DEFPATH[0] = "."; DEFPATH[NDIRS] = 0; init_idf(); InitCst(); diff --git a/lang/m2/comp/make.next b/lang/m2/comp/make.next new file mode 100755 index 00000000..72786759 --- /dev/null +++ b/lang/m2/comp/make.next @@ -0,0 +1,7 @@ +echo '#include "debug.h"' +sed -n ' +s:^.*[ ]ALLOCDEF[ ].*"\(.*\)".*$:struct \1 *h_\1 = 0;\ +#ifdef DEBUG\ +int cnt_\1 = 0;\ +#endif:p +' $* diff --git a/lang/m2/comp/node.c b/lang/m2/comp/node.c index 1a5b33b9..2ca29e60 100644 --- a/lang/m2/comp/node.c +++ b/lang/m2/comp/node.c @@ -12,11 +12,6 @@ #include "LLlex.h" #include "node.h" -struct node *h_node; /* header of free list */ -#ifdef DEBUG -int cnt_node; /* count number of allocated ones */ -#endif - struct node * MkNode(class, left, right, token) struct node *left, *right; diff --git a/lang/m2/comp/options.c b/lang/m2/comp/options.c index 8bdea33c..4a7c86b1 100644 --- a/lang/m2/comp/options.c +++ b/lang/m2/comp/options.c @@ -91,10 +91,19 @@ DoOption(text) break; case 'I' : - if (++ndirs >= NDIRS) { - fatal("too many -I options"); + if (*text) { + register int i = ndirs++; + register char *new = text; + while (new) { + register char *tmp = DEFPATH[i]; + + if (i >= NDIRS) + fatal("too many -I options"); + DEFPATH[i++] = new; + new = tmp; + } } - DEFPATH[ndirs] = text; + else DEFPATH[ndirs] = 0; break; case 'V' : /* set object sizes and alignment requirements */ diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index e80578c8..6867279d 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -117,10 +117,15 @@ DefinitionModule register struct def *df; struct node *exportlist; int dummy; + extern struct idf *DefId; } : DEFINITION MODULE IDENT { df = define(dot.TOK_IDF, GlobalScope, D_MODULE); if (!Defined) Defined = df; + if (df->df_idf != DefId) { + error("DEFINITION MODULE name is not \"%s\"", + DefId->id_text); + } CurrentScope->sc_name = df->df_idf->id_text; df->mod_vis = CurrVis; df->df_type = standard_type(T_RECORD, 1, (arith) 1); diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index d30e19e5..a7003717 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -55,16 +55,6 @@ struct type *std_type, *error_type; -struct paramlist *h_paramlist; -#ifdef DEBUG -int cnt_paramlist; -#endif - -struct type *h_type; -#ifdef DEBUG -int cnt_type; -#endif - struct type * construct_type(fund, tp) int fund; From b6ab6a5eb08af6eb7bd8d31f5b1826481bd2a985 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 10 Dec 1986 09:32:57 +0000 Subject: [PATCH 0379/1625] removed the -n flag, but not its effect. The generated parser will call LLmessage(-1) when saying "garbage at end of input". --- util/LLgen/src/extern.h | 1 - util/LLgen/src/gencode.c | 2 +- util/LLgen/src/main.c | 5 ----- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/util/LLgen/src/extern.h b/util/LLgen/src/extern.h index 66d6f06e..81563af5 100644 --- a/util/LLgen/src/extern.h +++ b/util/LLgen/src/extern.h @@ -82,4 +82,3 @@ extern int nerrors; extern string rec_file, incl_file; extern p_term terms; extern p_link links; -extern int nflag; diff --git a/util/LLgen/src/gencode.c b/util/LLgen/src/gencode.c index 9dc37377..1d17f08c 100644 --- a/util/LLgen/src/gencode.c +++ b/util/LLgen/src/gencode.c @@ -206,7 +206,7 @@ genrecovery() { } fputs(c_arrend, f); free((p_mem) index); - if (nflag) fputs("#define LL_NEWMESS\n", f); + fputs("#define LL_NEWMESS\n", f); copyfile(rec_file); if (ferror(f) != 0) { fatal(0,"write error on temporary"); diff --git a/util/LLgen/src/main.c b/util/LLgen/src/main.c index 3803782a..c7db5a7a 100644 --- a/util/LLgen/src/main.c +++ b/util/LLgen/src/main.c @@ -50,7 +50,6 @@ extern install(); # ifndef NDEBUG extern badassertion(); # endif not NDEBUG -int nflag; main(argc,argv) register string argv[]; { register string arg; @@ -90,10 +89,6 @@ main(argc,argv) register string argv[]; { incl_file = ++arg; break; # endif not NDEBUG - case 'n': - case 'N': - nflag = 1; - continue; case 'x': case 'X': ntneeded = 1; From 3f59bd779bbe960d062de48cf735bb41683cbcf8 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 10 Dec 1986 10:38:42 +0000 Subject: [PATCH 0380/1625] Initial revision --- doc/LLgen/LLgen.n | 1017 ++++++++++++++++++++++++++++++++++++++++++ doc/LLgen/LLgen.refs | 54 +++ doc/LLgen/Makefile | 12 + 3 files changed, 1083 insertions(+) create mode 100644 doc/LLgen/LLgen.n create mode 100644 doc/LLgen/LLgen.refs create mode 100644 doc/LLgen/Makefile diff --git a/doc/LLgen/LLgen.n b/doc/LLgen/LLgen.n new file mode 100644 index 00000000..ec64ca02 --- /dev/null +++ b/doc/LLgen/LLgen.n @@ -0,0 +1,1017 @@ +.\" $Header$ +.\" Run this paper off with +.\" refer [options] -p LLgen.refs LLgen.doc | [n]eqn | tbl | (nt)roff -ms +.cs 5 22u +.RP +.ND +.EQ +delim @@ +.EN +.TL +LLgen, an extended LL(1) parser generator +.AU +Ceriel J. H. Jacobs +.AI +Dept. of Mathematics and Computer Science +Vrije Universiteit +Amsterdam, The Netherlands +.AB +\fILLgen\fR provides a +tool for generating an efficient recursive descent parser +with no backtrack from +an Extended Context Free syntax. +The \fILLgen\fR +user specifies the syntax, together with code +describing actions associated with the parsing process. +\fILLgen\fR +turns this specification into a number of subroutines that handle the +parsing process. +.PP +The grammar may be ambiguous. +\fILLgen\fR contains both static and dynamic facilities +to resolve these ambiguities. +.PP +The specification can be split into several files, for each of +which \fILLgen\fR generates an output file containing the +corresponding part of the parser. +Furthermore, only output files that differ from their previous +version are updated. +Other output files are not affected in any +way. +This allows the user to recompile only those output files that have +changed. +.PP +The subroutine produced by \fILLgen\fR calls a user supplied routine +that must return the next token. This way, the input to the +parser can be split into single characters or higher level +tokens. +.PP +An error recovery mechanism is generated almost completely +automatically. +It is based on so called \fBdefault choices\fR, which are +implicitly or explicitly specified by the user. +.PP +\fILLgen\fR has succesfully been used to create recognizers for +Pascal and C. +.AE +.NH +Introduction +.PP +\fILLgen\fR +provides a tool for generating an efficient recursive +descent parser with no backtrack from an Extended Context Free +syntax. +A parser generated by +\fILLgen\fR +will be called +\fILLparse\fR +for the rest of this document. +It is assumed that the reader has some knowledge of LL(1) grammars and +recursive descent parsers. +For a survey on the subject, see . +.[ +griffiths +.] +.PP +Extended LL(1) parsers are an extension of LL(1) parsers. They are +derived from an Extended Context-Free (ECF) syntax instead of a Context-Free +(CF) syntax. +ECF syntax is described in section 2. +Section 3 provides an outline of a +specification as accepted by +\fILLgen\fR and also discusses the lexical conventions of +grammar specification files. +Section 4 provides a description of the way the +\fILLgen\fR +user can associate +actions with the syntax. These actions must be written in the programming +language C , +.[ +kernighan ritchie +.] +which also is the target language of \fILLgen\fR. +The error recovery technique is discussed in section 5. +This section also discusses what the user can do about it. +Section 6 discusses +the facilities \fILLgen\fR offers +to resolve ambiguities and conflicts. +\fILLgen\fR offers facilities to resolve them both at parser +generation time and during the execution of \fILLparse\fR. +Section 7 discusses the +\fILLgen\fR +working environment. +It also discusses the lexical analyzer that must be supplied by the +user. +This lexical analyzer must read the input stream and break it +up into basic input items, called \fBtokens\fR for the rest of +this document. +Appendix A gives a summary of the +\fILLgen\fR +input syntax. +Appendix B gives an example. +It is very instructive to compare this example with the one +given in . +.[ +yacc +.] +It demonstrates the struggle \fILLparse\fR and other LL(1) +parsers have with expressions. +Appendix C gives an example of the \fILLgen\fR features +allowing the user to recompile only those output files that +have changed, using the \fImake\fR program . +.[ +make +.] +.NH +The Extended Context-Free Syntax +.PP +The extensions of an ECF syntax with respect to an ordinary CF syntax are: +.IP 1. 10 +An ECF syntax contains the repetition operator: "N" (N represents a positive +integer). +.IP 2. 10 +An ECF syntax contains the closure set operator without and with +upperbound: "*" and "*N". +.IP 3. 10 +An ECF syntax contains the positive closure set operator without and with +upperbound: "+" and "+N". +.IP 4. 10 +An ECF syntax contains the optional operator: "?", which is a +shorthand for "*1". +.IP 5. 10 +An ECF syntax contains parentheses "[" and "]" which can be +used for grouping. +.PP +We can describe the syntax of an ECF syntax with an ECF syntax : +.DS +.ft 5 +grammar : rule + + ; +.ft P +.DE +This grammar rule states that a grammar consists of one or more +rules. +.DS +.ft 5 +rule : nonterminal ':' productionrule ';' + ; +.ft P +.DE +A rule consists of a left hand side, the nonterminal, +followed by ":", +the \fBproduce symbol\fR, followed by a production rule, followed by a +";", in\%di\%ca\%ting the end of the rule. +.DS +.ft 5 +productionrule : production [ '|' production ]* + ; +.ft P +.DE +A production rule consists of one or +more alternative productions separated by "|". This symbol is called the +\fBalternation symbol\fR. +.DS +.ft 5 +production : term * + ; +.ft P +.DE +A production consists of a possibly empty list of terms. +So, empty productions are allowed. +.DS +.ft 5 +term : element repeats + ; +.ft P +.DE +A term is an element, possibly with a repeat specification. +.DS +.ft 5 +element : LITERAL + | IDENTIFIER + | '[' productionrule ']' + ; +.ft P +.DE +An element can be a LITERAL, which basically is a single character +between apostrophes, it can be an IDENTIFIER, which is either a +nonterminal or a token, and it can be a production rule +between square parentheses. +.DS +.ft 5 +repeats : '?' + | [ '*' | '+' ] NUMBER ? + | NUMBER ? + ; +.ft P +.DE +These are the repeat specifications discussed above. Notice that +this specification may be empty. +.PP +The class of ECF languages +is identical with the class of CF languages. However, in many +cases recursive definitions of language features can now be +replaced by iterative ones. This tends to reduce the number of +nonterminals and gives rise to very efficient recursive descent +parsers. +.NH +Grammar Specifications +.PP +The major part of a +\fILLgen\fR +grammar specification consists of an +ECF syntax specification. +Names in this syntax specification refer to either tokens or nonterminal +symbols. +\fILLgen\fR +requires token names to be declared as such. This way it +can be avoided that a typing error in a nonterminal name causes it to +be accepted as a token name. The token declarations will be +discussed later. +A name will be regarded as a nonterminal symbol, unless it is declared +as a token name. +If there is no production rule for a nonterminal symbol, \fILLgen\fR +will complain. +.PP +A grammar specification may also include some C routines, +for instance the lexical analyzer and an error reporting +routine. +Thus, a grammar specification file can contain declarations, +grammar rules and C-code. +.PP +Blanks, tabs and newlines are ignored, but may not appear in names or +keywords. +Comments may appear wherever a name is legal (which is almost +everywhere). +They are enclosed in +/* ... */, as in C. Comments do not nest. +.PP +Names may be of arbitrary length, and can be made up of letters, underscore +"\_" and non-initial digits. Upper and lower case letters are distinct. +Only the first 50 characters are significant. +Notice however, that the names for the tokens will be used by the +C-preprocessor. +The number of significant characters therefore depends on the +underlying C-implementation. +A safe rule is to make the identifiers distinct in the first six +characters, case ignored. +.PP +There are two kinds of tokens: +those that are declared and are denoted by a name, +and literals. +.PP +A literal consists of a character enclosed in apostrophes "'". +The "\e" is an escape character within literals. The following escapes +are recognized : +.TS +center; +l l. +\&'\en' newline +\&'\er' return +\&'\e'' apostrophe "'" +\&'\e\e' backslash "\e" +\&'\et' tab +\&'\eb' backspace +\&'\ef' form feed +\&'\exxx' "xxx" in octal +.TE +.PP +Names representing tokens must be declared before they are used. +This can be done using the "\fB%token\fR" keyword, +by writing +.nf +.ft 5 +.sp 1 +%token name1, name2, . . . ; +.ft P +.fi +.PP +\fILLparse\fR is designed to recognize special nonterminal +symbols called \fBstart symbols\fR. +\fILLgen\fR allows for more than one start symbol. +Thus, grammars with more than one entry point are accepted. +The start symbols must be declared explicitly using the +"\fB%start\fR" keyword. It can be used whenever a declaration is +legal, f.i.: +.nf +.ft 5 +.sp 1 +%start LLparse, specification ; +.ft P +.fi +.sp 1 +declares "specification" as a start symbol and associates the +identifier "LLparse" with it. +"LLparse" will now be the name of the C-function that must be +called to recognize "specification". +.NH +Actions +.PP +\fILLgen\fR +allows arbitrary insertions of actions within the right hand side +of a production rule in the ECF syntax. An action consists of a number of C +statements, enclosed in the brackets "{" and "}". +.PP +\fILLgen\fR +generates a parsing routine for each rule in the grammar. The actions +supplied by the user are just inserted in the proper place. +There may also be declarations before the statements in the +action, as +the "{" and "}" are copied into the target code along with the +action. The scope of these declarations terminates with the +closing bracket "}" of the action. +.PP +In addition to actions, it is also possible to declare local variables +in the parsing routine, which can then be used in the actions. +Such a declaration consists of a number of C variable declarations, +enclosed in the brackets "{" and "}". It must be placed +right in front of the ":" in the grammar rule. +The scope of these local variables consists of the complete +grammar rule. +.PP +In order to facilitate communication between the actions and +\fILLparse\fR, +the parsing routines can be given C-like parameters. So, for example +.nf +.ft 5 +.sp 1 +expr(int *pval;) { int fact; } : + /* + * Rule with one parameter, a pointer to an int. + * Parameter specifications are ordinary C declarations. + * One local variable, of type int. + */ + factor (&fact) { *pval = fact; } + /* + * factor is another nonterminal symbol. + * One actual parameter is supplied. + * Notice that the parameter passing mechanism is that + * of C. + */ + [ '+' factor (&fact) { *pval += fact; } ]* + /* + * remember the '*' means zero or more times + */ + ; +.sp 1 +.ft P +.fi +is a rule to recognize a number of factors, separated by "+", and +to compute their sum. +.PP +\fILLgen\fR +generates C code, so the parameter passing mechanism is that of +C, as is shown in the example above. +.PP +Actions often manipulate attributes of the token just read. +For instance, when an identifier is read, its name must be +looked up in a symbol table. +Therefore, \fILLgen\fR generates code +such that at a number of places in the grammar rule +it is defined which token has last been read. +After a token, the last token read is this token. +After a "[" or a "|", the last token read is the next token to +be accepted by \fILLparse\fR. +At all other places, it is undefined which token has last been +read. +The last token read is available in the global integer variable +\fILLsymb\fR. +.PP +The user may also specify C-code wherever a \fILLgen\fR-declaration is +legal. +Again, this code must be enclosed in the brackets "{" and "}". +This way, the user can define global declarations and +C-functions. +To avoid name-conflicts with identifiers generated by +\fILLgen\fR, \fILLparse\fR only uses names beginning with +"LL"; the user should avoid such names. +.NH +Error Recovery +.PP +The error recovery technique used by \fILLgen\fR is a +modification of the one presented in . +.[ +Rohrich +.] +It is based on \fBdefault choices\fR, which just are +what the word says, default choices at +every point in the grammar where there is a +choice. +Thus, in an alternation, one of the productions is marked as a +default choice, and in a term with a non-fixed repetition +specification there will also be a default choice (between +doing the term (once more) and continuing with the rest of the +production in which the term appears). +.PP +When \fILLparse\fR detects an error after having parsed the +string @s@, the default choices enable it to compute one +syntactically correct continuation, +consisting of the tokens @t sub 1~...~t sub n@, +such that @s~t sub 1~...~t sub n@ is a string of tokens that +is a member of the language defined by the grammar. +Notice, that the computation of this continuation must +terminate, which implies that the default choices may not +invoke recursive rules. +.PP +At each point in this continuation, a certain number of other +tokens could also be syntactically correct, f.i. the token +@t@ is syntactically correct at point @t sub i@ in this +continuation, if the string @s~t sub 1~...~t sub i~t~s sub 1@ +is a string of the language defined by the grammar for some +string @s sub 1@ and i >= 0. +.PP +The set @T@ +containing all these tokens (including @t sub 1 ,~...,~t sub n@) is computed. +Next, \fILLparse\fR discards zero +or more tokens from its input, until a token +@t@ \(mo @T@ is found. +The error is then corrected by inserting i (i >= 0) tokens +@t sub 1~...~t sub i@, such that the string +@s~t sub 1~...~t sub i~t~s sub 1@ is a string of the language +defined by the grammar, for some @s sub 1@. +Then, normal parsing is resumed. +.PP +The above is difficult to implement in a recursive decent +parser, and is not the way \fILLparse\fR does it, but the +effect is the same. In fact, \fILLparse\fR maintains a list +of tokens that may not be discarded, which is adjusted as +\fILLparse\fR proceeds. This list is just a representation +of the set @T@ mentioned +above. When an error occurs, \fILLparse\fR discards tokens until +a token @t@ that is a member of this list is found. +Then, it continues parsing, following the default choices, +inserting tokens along the way, until this token @t@ is legal. +The selection of +the default choices must guarantee that this will always +happen. +.PP +The default choices are explicitly or implicitly +specified by the user. +By default, the default choice in an alternation is the +alternative with the shortest possible terminal production. +The user can select one of the other productions in the +alternation as the default choice by putting the keyword +"\fB%default\fR" in front of it. +.PP +By default, for terms with a repetition count containing "*" or +"?" the default choice is to continue with the rest of the rule +in which the term appears, and +.sp 1 +.ft 5 +.nf + term+ +.fi +.ft P +.sp 1 +is treated as +.sp 1 +.nf +.ft 5 + term term* . +.ft P +.fi +.PP +It is also clear, that it can never be the default choice to do +the term (once more), because this could cause the parser to +loop, inserting tokens forever. +However, when the user does not want the parser to skip +tokens that would not have been skipped if the term +would have been the default choice, +the skipping of such a term can be prevented by +using the keyword "\fB%persistent\fR". +For instance, the rule +.sp 1 +.ft 5 +.nf +commandlist : command* ; +.fi +.ft P +.sp 1 +could be changed to +.sp 1 +.ft 5 +.nf +commandlist : [ %persistent command ]* ; +.fi +.ft P +.sp 1 +The effects of this in case of a syntax error are twofold: +The set @T@ mentioned above will be extended as if "command" were +in the default production, so that fewer tokens will be +skipped. +Also, if the first token that is not skipped is a member of the +subset of @T@ arising from the grammar rule for "command", +\fILLparse\fR will enter that rule. +So, in fact the default choice +is determined dynamically (by \fILLparse\fR). +Again, \fILLgen\fR checks (statically) +that \fILLparse\fR will always terminate, and if not, +\fILLgen\fR will complain. +.PP +An important property of this error recovery method is that, +once a rule is started, it will be finished. +This means that all actions in the rule will be executed +normally, so that the user can be sure that there will be no +inconsistencies in his data structures because of syntax +errors. +Also, as the method is in fact error correcting, the +actions in a rule only have to deal with syntactically correct +input. +.NH +Ambiguities and conflicts +.PP +As \fILLgen\fR generates a recursive descent parser with no backtrack, +it must at all times be able to determine what to do, +based on the current input symbol. +Unfortunately, this cannot be done for all grammars. +Two kinds of conflicts can arise : +.IP 1) 10 +the grammar rule is of the form "production1 | production2", +and \fILLparse\fR cannot decide which production to chose. +This we call an \fBalternation conflict\fR. +.IP 2) 10 +the grammar rule is of the form "[ productionrule ]...", +where ... specifies a non-fixed repetition count, +and \fILLparse\fR cannot decide whether to +choose "productionrule" once more, or to continue. +This we call a \fBrepetition conflict\fR. +.PP +There can be several causes for conflicts: the grammar may be +ambiguous, or the grammar may require a more complex parser +than \fILLgen\fR can construct. +The conflicts can be examined by inspecting the verbose +(-\fBv\fR) option output file. +The conflicts can be resolved by rewriting the grammar +or by using \fBconflict resolvers\fR. +The mechanism described here is based on the attributed parsing +of. +.[ +milton +.] +.PP +An alternation conflict can be resolved by putting an \fBif condition\fR +in front of the first conflicting production. +It consists of a "\fB%if\fR" followed by a +C-expression between parentheses. +\fILLparse\fR will then evaluate this expression whenever a +token is met at this point on which there is a conflict, so +the conflict will be resolved dynamically. +If the expression evaluates to +non-zero, the first conflicting production is chosen, +otherwise one of the remaining ones is chosen. +.PP +An alternation conflict can also be resolved using the keywords +"\fB%prefer\fR" or "\fB%avoid\fR". "\fB%prefer\fR" +is equivalent in behaviour to +"\fB%if\fR (1)". "\fB%avoid\fR" is equivalent to "\fB%if\fR (0)". +In these cases however, "\fB%prefer\fR" and "\fB%avoid\fR" should be used, +as they resolve the conflict statically and thus +give rise to better C-code. +.PP +A repetition conflict can be resolved by putting a \fBwhile condition\fR +right after the opening parentheses. This while condition +consists of a "\fB%while\fR" followed by a C-expression between +parentheses. Again, \fILLparse\fR will then +evaluate this expression whenever a token is met +at this point on which there is a conflict. +If the expression evaluates to non-zero, the +repeating part is chosen, otherwise the parser continues with +the rest of the rule. +Appendix B will give an example of these features. +.PP +A useful aid in writing conflict resolvers is the "\fB%first\fR" keyword. +It is used to declare a C-macro that forms an expression +returning 1 if the parameter supplied can start a specified +nonterminal, f.i.: +.sp 1 +.nf +.ft 5 +%first fmac, nonterm ; +.ft P +.sp 1 +.fi +declares "fmac" as a macro with one parameter, whose value +is a token number. If the parameter +X can start the nonterminal "nonterm", "fmac(X)" is true, +otherwise it is false. +.NH +The LLgen working environment +.PP +\fILLgen\fR generates a number of files: one for each input +file, and two other files: \fILpars.c\fR and \fILpars.h\fR. +\fILpars.h\fR contains "#-define"s for the tokennames. +\fILpars.c\fR contains the error recovery routines and tables. +Only those output files that differ from their previous version +are updated. See appendix C for a possible application of this +feature. +.PP +The names of the output files are constructed as +follows: +in the input file name, the suffix after the last point is +replaced by a "c". If no point is present in the input file +name, ".c" is appended to it. \fILLgen\fR checks that the +filename constructed this way in fact represents a previous +version, or does not exist already. +.PP +The user must provide some environment to obtain a complete +program. +Routines called \fImain\fR and \fILLmessage\fR must be defined. +Also, a lexical analyzer must be provided. +.PP +The routine \fImain\fR must be defined, as it must be in every +C-program. It should eventually call one of the startsymbol +routines. +.PP +The routine \fILLmessage\fR must accept one +parameter, whose value is a token number, zero or negative. +.br +A zero parameter indicates that the current token (the one in +the external variable \fILLsymb\fR) is deleted. +.br +A negative parameter indicates that a stack overflow occurred. +This usually is a fatal error. +.br +A parameter that is a token number (a positive parameter) +indicates that this +token is to be inserted in front of the token currently in +\fILLsymb\fR. +The user can give the token the proper attributes. +Also, the user must take care, that the token currently in +\fILLsymb\fR is again returned by the \fBnext\fR call to the +lexical analyzer, with the proper attributes. +So, the lexical analyzer must have a facility to push back one +token. +.PP +The user must supply a lexical analyzer to read the input stream and +break it up into tokens, which are passed to +.I LLparse. +It should be an integer valued function, returning the token number. +The name of this function can be declared using the +"\fB%lexical\fR" keyword. +This keyword can be used wherever a declaration is legal and may appear +only once in the grammar specification, f.i.: +.sp 1 +.nf +.ft 5 +%lexical scanner ; +.ft P +.fi +.sp 1 +declares "scanner" as the name of the lexical analyzer. +The default name for the lexical analyzer is "yylex". +The reason for this funny name is that a useful tool for constructing +lexical analyzers is the +.I Lex +program , +.[ +lex +.] +which generates a routine of that name. +.PP +The token numbers are chosen by \fILLgen\fR. +The token number for a literal +is the numerical value of the character in the local character set. +If the tokens have a name, +the "#\ define" mechanism of C is used to give them a value and +to allow the lexical analyzer to return their token numbers symbolically. +These "#\ define"s are collected in the file \fILpars.h\fR which +can be "#\ include"d in any file that needs the token-names. +.PP +The lexical analyzer must signal the end +of input to \fILLparse\fR +by returning a number less than or equal to zero. +.bp +.[ +$LIST$ +.] +.bp +.SH +Appendix A : LLgen Input Syntax +.PP +This appendix has a description of the \fILLgen\fR input syntax, +as a \fILLgen\fR specification. As a matter of fact, the current +version of \fILLgen\fR is written with \fILLgen\fR. +.nf +.ft 5 +.sp 2 +/* + * First the declarations of the terminals + * The order is not important + */ + +%token IDENTIFIER; /* terminal or nonterminal name */ +%token NUMBER; +%token LITERAL; + +/* + * Reserved words + */ + +%token TOKEN; /* %token */ +%token START; /* %start */ +%token PERSISTENT; /* %persistent */ +%token IF; /* %if */ +%token WHILE; /* %while */ +%token AVOID; /* %avoid */ +%token PREFER; /* %prefer */ +%token DEFAULT; /* %default */ +%token LEXICAL; /* %lexical */ +%token FIRST; /* %first */ + +/* + * Declare LLparse to be a C-routine that recognizes "specification" + */ + +%start LLparse, specification; + +specification + : declaration* + ; + +declaration + : START + IDENTIFIER ',' IDENTIFIER + ';' + | '{' + /* Read C-declaration here */ + '}' + | TOKEN + IDENTIFIER + [ ',' IDENTIFIER ]* + ';' + | FIRST + IDENTIFIER ',' IDENTIFIER + ';' + | LEXICAL + IDENTIFIER + ';' + | rule + ; + +rule : IDENTIFIER parameters? ldecl? + ':' productions + ';' + ; + +ldecl : '{' + /* Read C-declaration here */ + '}' + ; + +productions + : simpleproduction + [ '|' DEFAULT? simpleproduction ]* + ; + +simpleproduction + : [ IF '(' /* Read C-expression here */ ')' + | PREFER + | AVOID + ]? + [ element repeats ]* + ; + +element : '{' + /* Read action here */ + '}' + | '[' [ WHILE '(' /* Read C-expression here */ ')' ]? + PERSISTENT? + productions + ']' + | LITERAL + | IDENTIFIER parameters? + ; + +parameters + : '(' /* Read C-parameters here */ ')' + ; + +repeats : /* empty */ + | [ '*' | '+' ] NUMBER? + | NUMBER + | '?' + ; + +.fi +.ft P +.bp +.SH +Appendix B : An example +.PP +This example gives the complete \fILLgen\fR specification of a simple +desk calculator. It has 26 registers, labeled "a" through "z", +and accepts arithmetic expressions made up of the C operators ++, -, *, /, %, &, and |, with their usual priorities. +The value of the expression is +printed. As in C, an integer that begins with 0 is assumed to +be octal; otherwise it is assumed to be decimal. +.PP +Although the example is short and not very complicated, it +demonstrates the use of if and while conditions. In +the example they are in fact used to reduce the number of +nonterminals, and to reduce the overhead due to the recursion +that would be involved in parsing an expression with an +ordinary recursive descent parser. In an ordinary LL(1) +grammar there would be one nonterminal for each operator +priority. The example shows how we can do it all with one +nonterminal, no matter how many priority levels there are. +.sp 1 +.nf +.ft 5 +{ +#include +#include +#define MAXPRIO 5 +#define prio(op) (ptab[op]) + +struct token { + int t_tokno; /* token number */ + int t_tval; /* Its attribute */ +} stok = { 0,0 }, tok; + +int nerrors = 0; +int regs[26]; /* Space for the registers */ +int ptab[128]; /* Attribute table */ + +struct token +nexttok() { /* Read next token and return it */ + register c; + struct token new; + + while ((c = getchar()) == ' ' || c == '\et') { /* nothing */ } + if (isdigit(c)) new.t_tokno = DIGIT; + else if (islower(c)) new.t_tokno = IDENT; + else new.t_tokno = c; + if (c >= 0) new.t_tval = ptab[c]; + return new; +} } + +%token DIGIT, IDENT; +%start parse, list; + +list : stat* ; + +stat { int ident, val; } : + %if (stok = nexttok(), + stok.t_tokno == '=') + /* The conflict is resolved by looking one further + * token ahead. The grammar is LL(2) + */ + IDENT + { ident = tok.t_tval; } + '=' expr(1,&val) '\en' + { if (!nerrors) regs[ident] = val; } + | expr(1,&val) '\en' + { if (!nerrors) printf("%d\en",val); } + | '\en' + ; + +expr(int level, *val;) { int expr; } : + %if (level <= MAXPRIO) + /* The grammar is ambiguous here. If level > MAXPRIO, + * this invocation will only scan one factor + */ + expr(MAXPRIO+1,val) + [ %while (prio(tok.t_tokno) >= level) + /* Swallow operators as long as their priority is + * larger than or equal to the level of this invocation + */ + '+' expr(prio('+')+1,&expr) + { *val += expr; } + /* This states that '+' groups left to right. If it + * should group right to left, the rule should read: + * '+' expr(prio('+'),&expr) + */ + | '-' expr(prio('-'),&expr) + { *val -= expr; } + | '*' expr(prio('*'),&expr) + { *val *= expr; } + | '/' expr(prio('/'),&expr) + { *val /= expr; } + | '%' expr(prio('%'),&expr) + { *val %= expr; } + | '&' expr(prio('&'),&expr) + { *val &= expr; } + | '|' expr(prio('|'),&expr) + { *val |= expr; } + ]* + /* Notice the "*" here. It is important. + */ + | '(' expr(1,val) ')' + | '-' expr(MAXPRIO+1,val) + { *val = -*val; } + | number(val) + | IDENT + { *val = regs[tok.t_tval]; } + ; + +number(int *val;) { int base; } + : DIGIT + { base = (*val=tok.t_tval)==0?8:10; } + [ DIGIT + { *val = base * *val + tok.t_tval; } + ]* ; + +%lexical scanner ; +{ +scanner() { + if (stok.t_tokno) { /* a token has been inserted or read ahead */ + tok = stok; + stok.t_tokno = 0; + return tok.t_tokno; + } + if (nerrors && tok.t_tokno == '\en') { + printf("ERROR\en"); + nerrors = 0; + } + tok = nexttok(); + return tok.t_tokno; +} + +LLmessage(insertedtok) { + nerrors++; + if (insertedtok) { /* token inserted, save old token */ + stok = tok; + tok.t_tval = 0; + if (insertedtok < 128) tok.t_tval = ptab[insertedtok]; + } +} + +main() { + register *p; + + for (p = ptab; p < &ptab[128]; p++) *p = 0; + /* for letters, their attribute is their index in the regs array */ + for (p = &ptab['a']; p <= &ptab['z']; p++) *p = p - &ptab['a']; + /* for digits, their attribute is their value */ + for (p = &ptab['0']; p <= &ptab['9']; p++) *p = p - &ptab['0']; + /* for operators, their attribute is their priority */ + ptab['*'] = 4; + ptab['/'] = 4; + ptab['%'] = 4; + ptab['+'] = 3; + ptab['-'] = 3; + ptab['&'] = 2; + ptab['|'] = 1; + return parse(); +} } +.fi +.ft P +.bp +.SH +Appendix C. How to use \fILLgen\fR. +.PP +This appendix demonstrates how \fILLgen\fR can be used in +combination with the \fImake\fR program, to make effective use +of the \fILLgen\fR-feature that it only changes output files +when neccessary. \fIMake\fR uses a "makefile", which +is a file containing dependencies and associated commands. +A dependency usually indicates that some files depend on other +files. When a file depends on another file and is older than +that other file, the commands associated with the dependency +are executed. +.PP +So, \fImake\fR seems just the program that we always wanted. +However, it +is not very good in handling programs that generate more than +one file. +As usual, there is a way around this problem. +A sample makefile follows: +.sp 1 +.ft 5 +.nf +# The grammar exists of the files decl.g, stat.g and expr.g. +# The ".o"-files are the result of a C-compilation. + +GFILES = decl.g stat.g expr.g +OFILES = decl.o stat.o expr.o Lpars.o +LLOPT = + +# As make does'nt handle programs that generate more than one +# file well, we just don't tell make about it. +# We just create a dummy file, and touch it whenever LLgen is +# executed. This way, the dummy in fact depends on the grammar +# files. +# Then, we execute make again, to do the C-compilations and +# such. + +all: dummy + make parser + +dummy: $(GFILES) + LLgen $(LLOPT) $(GFILES) + touch dummy + +parser: $(OFILES) + $(CC) -o parser $(LDFLAGS) $(OFILES) + +# Some dependencies without actions : +# make already knows what to do about them + +Lpars.o: Lpars.h +stat.o: Lpars.h +decl.o: Lpars.h +expr.o: Lpars.h + +.fi +.ft P diff --git a/doc/LLgen/LLgen.refs b/doc/LLgen/LLgen.refs new file mode 100644 index 00000000..102e8459 --- /dev/null +++ b/doc/LLgen/LLgen.refs @@ -0,0 +1,54 @@ +%T An ALL(1) Compiler Generator +%A D. R. Milton +%A L. W. Kirchhoff +%A B. R. Rowland +%B Proc. of the SIGPLAN '79 Symposium on Compiler Construction +%D August 1979 +%J SIGPLAN Notices +%N 8 +%P 152-157 +%V 14 + +%T Lex - A Lexical Analyser Generator +%A M. E. Lesk +%I Bell Laboratories +%D October 1975 +%C Murrey Hill, New Jersey +%R Comp. Sci. Tech. Rep. No. 39 + +%T Yacc: Yet Another Compiler Compiler +%A S. C. Johnson +%I Bell Laboratories +%D 1975 +%C Murray Hill, New Jersey +%R Comp. Sci. Tech. Rep. No. 32 + +%T The C Programming Language +%A B. W. Kernighan +%A D. M. Ritchie +%I Prentice-Hall, Inc. +%C Englewood Cliffs, New Jersey +%D 1978 + +%A M. Griffiths +%T LL(1) Grammars and Analysers +%E F. L. Bauer and J. Eickel +%B Compiler Construction, An Advanced Course +%I Springer-Verlag +%C New York, N.Y. +%D 1974 + +%T Make - A Program for Maintaining Computer Programs +%A S. I. Feldman +%J Software - Practice and Experience +%V 10 +%N 8 +%P 255-265 +%D August 1979 + +%T Methods for the Automatic Construction of Error Correcting Parsers +%A J. R\*:ohrich +%J Acta Informatica +%V 13 +%P 115-139 +%D 1980 diff --git a/doc/LLgen/Makefile b/doc/LLgen/Makefile new file mode 100644 index 00000000..0f056482 --- /dev/null +++ b/doc/LLgen/Makefile @@ -0,0 +1,12 @@ +# $Header$ + +MS=-ms +EQN=eqn +NROFF=nroff +REFER=refer +TBL=tbl +SUF=pr + +../LLgen.$(SUF): LLgen.doc LLgen.refs + $(REFER) -sA+T -p LLgen.refs LLgen.doc | $(EQN) | $(TBL) | \ + $(NROFF) $(MS) > $@ From 4d1f2e4f350c304cf81fc6dc4950ecfb4996429a Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 10 Dec 1986 11:31:35 +0000 Subject: [PATCH 0381/1625] minor mods. --- doc/LLgen/LLgen.n | 54 +++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/doc/LLgen/LLgen.n b/doc/LLgen/LLgen.n index ec64ca02..1c048585 100644 --- a/doc/LLgen/LLgen.n +++ b/doc/LLgen/LLgen.n @@ -1,6 +1,14 @@ .\" $Header$ .\" Run this paper off with .\" refer [options] -p LLgen.refs LLgen.doc | [n]eqn | tbl | (nt)roff -ms +.if '\*(>.'' \{\ +. if '\*(.>'' \{\ +. if n .ds >. . +. if n .ds >, , +. if t .ds .> . +. if t .ds ,> ,\ +\}\ +\} .cs 5 22u .RP .ND @@ -147,7 +155,7 @@ We can describe the syntax of an ECF syntax with an ECF syntax : .ft 5 grammar : rule + ; -.ft P +.ft R .DE This grammar rule states that a grammar consists of one or more rules. @@ -155,7 +163,7 @@ rules. .ft 5 rule : nonterminal ':' productionrule ';' ; -.ft P +.ft R .DE A rule consists of a left hand side, the nonterminal, followed by ":", @@ -165,7 +173,7 @@ the \fBproduce symbol\fR, followed by a production rule, followed by a .ft 5 productionrule : production [ '|' production ]* ; -.ft P +.ft R .DE A production rule consists of one or more alternative productions separated by "|". This symbol is called the @@ -174,7 +182,7 @@ more alternative productions separated by "|". This symbol is called the .ft 5 production : term * ; -.ft P +.ft R .DE A production consists of a possibly empty list of terms. So, empty productions are allowed. @@ -182,7 +190,7 @@ So, empty productions are allowed. .ft 5 term : element repeats ; -.ft P +.ft R .DE A term is an element, possibly with a repeat specification. .DS @@ -191,7 +199,7 @@ element : LITERAL | IDENTIFIER | '[' productionrule ']' ; -.ft P +.ft R .DE An element can be a LITERAL, which basically is a single character between apostrophes, it can be an IDENTIFIER, which is either a @@ -203,7 +211,7 @@ repeats : '?' | [ '*' | '+' ] NUMBER ? | NUMBER ? ; -.ft P +.ft R .DE These are the repeat specifications discussed above. Notice that this specification may be empty. @@ -283,7 +291,7 @@ by writing .ft 5 .sp 1 %token name1, name2, . . . ; -.ft P +.ft R .fi .PP \fILLparse\fR is designed to recognize special nonterminal @@ -297,7 +305,7 @@ legal, f.i.: .ft 5 .sp 1 %start LLparse, specification ; -.ft P +.ft R .fi .sp 1 declares "specification" as a start symbol and associates the @@ -354,7 +362,7 @@ expr(int *pval;) { int fact; } : */ ; .sp 1 -.ft P +.ft R .fi is a rule to recognize a number of factors, separated by "+", and to compute their sum. @@ -391,7 +399,7 @@ Error Recovery The error recovery technique used by \fILLgen\fR is a modification of the one presented in . .[ -Rohrich +automatic construction error correcting .] It is based on \fBdefault choices\fR, which just are what the word says, default choices at @@ -461,14 +469,14 @@ in which the term appears, and .nf term+ .fi -.ft P +.ft R .sp 1 is treated as .sp 1 .nf .ft 5 term term* . -.ft P +.ft R .fi .PP It is also clear, that it can never be the default choice to do @@ -485,7 +493,7 @@ For instance, the rule .nf commandlist : command* ; .fi -.ft P +.ft R .sp 1 could be changed to .sp 1 @@ -493,7 +501,7 @@ could be changed to .nf commandlist : [ %persistent command ]* ; .fi -.ft P +.ft R .sp 1 The effects of this in case of a syntax error are twofold: The set @T@ mentioned above will be extended as if "command" were @@ -544,7 +552,7 @@ The conflicts can be examined by inspecting the verbose The conflicts can be resolved by rewriting the grammar or by using \fBconflict resolvers\fR. The mechanism described here is based on the attributed parsing -of. +of . .[ milton .] @@ -587,7 +595,7 @@ nonterminal, f.i.: .nf .ft 5 %first fmac, nonterm ; -.ft P +.ft R .sp 1 .fi declares "fmac" as a macro with one parameter, whose value @@ -654,7 +662,7 @@ only once in the grammar specification, f.i.: .nf .ft 5 %lexical scanner ; -.ft P +.ft R .fi .sp 1 declares "scanner" as the name of the lexical analyzer. @@ -793,7 +801,7 @@ repeats : /* empty */ ; .fi -.ft P +.ft R .bp .SH Appendix B : An example @@ -821,8 +829,8 @@ nonterminal, no matter how many priority levels there are. { #include #include -#define MAXPRIO 5 -#define prio(op) (ptab[op]) +#define MAXPRIO 5 +#define prio(op) (ptab[op]) struct token { int t_tokno; /* token number */ @@ -956,7 +964,7 @@ main() { return parse(); } } .fi -.ft P +.ft R .bp .SH Appendix C. How to use \fILLgen\fR. @@ -1014,4 +1022,4 @@ decl.o: Lpars.h expr.o: Lpars.h .fi -.ft P +.ft R From e5a90d3bd8e86c25eae2b9daf3d540a3f254f39c Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 10 Dec 1986 11:40:00 +0000 Subject: [PATCH 0382/1625] Initial revision --- doc/top/Makefile | 6 + doc/top/refs.top | 79 +++++ doc/top/top.n | 792 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 877 insertions(+) create mode 100644 doc/top/Makefile create mode 100644 doc/top/refs.top create mode 100644 doc/top/top.n diff --git a/doc/top/Makefile b/doc/top/Makefile new file mode 100644 index 00000000..fa5ee63c --- /dev/null +++ b/doc/top/Makefile @@ -0,0 +1,6 @@ +top.f: + refer -sA+T -l4,2 -p refs.top top.n | nroff -ms > top.f +top.f.35: + refer -sA+T -l4,2 -p refs.top top.n | nroff -ms -Thr35 > top.f.35 +top.f.agfa: + refer -sA+T -l4,2 -p refs.top top.n | nroff -ms -Tlp > top.f.agfa diff --git a/doc/top/refs.top b/doc/top/refs.top new file mode 100644 index 00000000..5cac9ed6 --- /dev/null +++ b/doc/top/refs.top @@ -0,0 +1,79 @@ +%T A Practical Toolkit for Making Portable Compilers +%A A.S. Tanenbaum +%A J.M. van Staveren +%A E.G. Keizer +%A J.W. Stevenson +%I Vrije Universiteit, Amsterdam +%R Rapport nr IR-74 +%D October 1981 + +%T A Practical Toolkit for Making Portable Compilers +%A A.S. Tanenbaum +%A J.M. van Staveren +%A E.G. Keizer +%A J.W. Stevenson +%J CACM +%V 26 +%N 9 +%P 654-660 +%D September 1983 + +%T A Unix Toolkit for Making Portable Compilers +%A A.S. Tanenbaum +%A J.M. van Staveren +%A E.G. Keizer +%A J.W. Stevenson +%J Proceedings USENIX conf. +%C Toronto, Canada +%V 26 +%D July 1983 +%P 255-261 + +%T Using Peephole Optimization on Intermediate Code +%A A.S. Tanenbaum +%A J.M. van Staveren +%A J.W. Stevenson +%J TOPLAS +%V 4 +%N 1 +%P 21-36 +%D January 1982 + +%T Amsterdam Compiler Kit documentation +%A A.S. Tanenbaum +%A E.G. Keizer +%A J.M. van Staveren +%A J.W. Stevenson +%I Vrije Universiteit, Amsterdam +%R Rapport nr IR-90 +%D June 1984 + +%T Language- and Machine-independant Global Optimization on +Intermediate Code +%A H.E. Bal +%A A.S. Tanenbaum +%I Vrije Universiteit, Amsterdam +%R Rapport IR-98 +%D March 1985 + +%T The Design and Implementation of the EM Global Optimizer +%A H.E. Bal +%I Vrije Universiteit, Amsterdam +%R Rapport IR-99 +%D March 1985 + + +%T The C Programming Language +%A B.W. Kernighan +%A D.M. Ritchie +%I Prentice-Hall, Inc +%C Englewood Cliffs,NJ +%D 1978 + +%T Principles of compiler design +%A A.V. Aho +%A J.D. Ullman +%I Addison-Wesley +%C Reading, Massachusetts +%D 1978 + diff --git a/doc/top/top.n b/doc/top/top.n new file mode 100644 index 00000000..5c524a7b --- /dev/null +++ b/doc/top/top.n @@ -0,0 +1,792 @@ +.ND +.pl 11.7i +.ll 80m +.nr LL 80m +.nr tl 78m +.tr ~ +.ds >. . +.TL +The ACK Target Optimizer +.AU +H.E. Bal +.AI +Vrije Universiteit +Wiskundig Seminarium, Amsterdam +.AB +The Target Optimizer is one of several optimizers that are part of +the Amsterdam Compiler Kit. +It operates directly on assembly code, +rather than on a higher level intermediate code, +as the Peephole Optimizer and Global Optimizer do. +Consequently, the Target Optimizer can do optimizations +that are highly machine-dependent. +.PP +Each target machine has its own Target Optimizer. +New optimizers are generated by the Target Optimizer Generator, +which uses a machine-dependent table as input. +This document contains full information on how to +write such a table for a new machine. +It also discusses the implementation of the +Target Optimizer and its generator. +.AE +.bp +.NH 1 +Introduction +.PP +.FS +This work was supported by the +Stichting Technische Wetenschappen (STW) +under grant VWI03.0001. +.FE +This document describes the target optimizer component +of the Amsterdam Compiler Kit (ACK) . +.[ +tanenbaum staveren amsterdam toolkit +.] +.[ +tanenbaum staveren cacm +.] +.[ +tanenbaum staveren toronto +.] +Optimization takes place in several parts of ACK compilers, +most notably in the Peephole Optimizer +.[ +staveren peephole toplas +.] +and +the Global Optimizer, +.[ +bal tanenbaum global optimization +.] +.[ +bal implementation global optimizer +.] +which are both language- and machine-independent, +and in the machine-specific code generators. +.[ +documentation amsterdam compiler kit +.] +The target optimizer is the finishing touch in this sequence of +optimizers. +It can be used to capture those optimizations that are hard +to express in the other parts of ACK. +These optimizations will typically be very machine-specific. +.PP +The target optimizer operates on the assembly code of some target machine. +Hence there is one target optimizer per machine. +However, just as for the ACK code generators and assemblers, +a framework has been build that allows easy generation of +target optimizers out of machine-independent parts and a +machine-dependent description table (see figure 1.). +So the major part of the code of a target optimizer is +shared among all target optimizers. +.DS + + + |-------------------------| + | machine-independent | + | code | + | | + |-----------------| |-------------------------| +descrip- |target optimizer | | machine-dependent code | + tion --> |generator | ----> | + tables | +table | | | | + |-----------------| |-------------------------| + + target optimizer + + Figure 1: Generation of a target optimizer. + +.DE +.PP +This document focusses on the description of the machine-dependent table. +In chapter 2 we give an informal introduction to the optimization +algorithm and to the definition of the table format. +Chapters 3 and 4 discuss the implementation of the target optimizer +and the target optimizer generator. +Appendix A gives full information for writing a description table. +.bp +.NH 1 +Global structure of the target optimizer +.PP +The target optimizer is based on the well understood model +of a \fIpeephole optimizer\fR. +.[ +aho ullman compiler +.] +It contains a machine-dependent table +of (pattern,replacement) pairs. +Each pattern describes +a sequence of one or more assembler instructions +that can be replaced by zero or more equivalent, yet cheaper, +instructions (the 'replacement'). +The optimizer maintains a \fIwindow\fR that moves over the input. +At any moment, the window contains some contiguous part of the input. +If the instructions in the current window match some pattern +in the table, +they are replaced by the corresponding replacement; +else, the window moves one instruction to the right. +.PP +In the remainder of this section we will give an informal +description of the machine-dependent table. +A more precise definition is given in appendix A. +We will first discuss the restrictions put on the +format of the assembly code. +.NH 2 +Assumptions about the assembly code format +.PP +We assume that a line of assembly code begins with an +instruction \fImnemonic\fR (opcode), +followed by zero or more \fIoperands\fR. +The mnemonic and the first operand must be separated by a special +character (e.g. a space or a tab). +Likewise, the operands must be separated by a special +character (e.g. a comma). +These separators need not be the same for all machines. +.NH 2 +Informal description of the machine-dependent tables +.PP +The major part of the table consists of (pattern,replacement) pairs +called \fIentries\fR. +.PP +A pattern is a list of instruction descriptions. +Each instruction description describes the instruction mnemonic and +the operands. +.PP +A mnemonic is described either by a string constant or by the +keyword ANY. +As all entities dealt with by the target optimizer are strings, +string constants do not contain quotes. +A string constant matches only itself. +ANY matches every instruction mnemonic. +.nf + +Examples of mnemonic descriptions: + + add + sub.l + mulw3 + ANY +.fi +.PP +An operand can also be described by a string constant. +.nf + +Examples: + + (sp)+ + r5 + -4(r6) + +.fi +Alternatively, it can be described by means of a \fIvariable name\fR. +Variables have values which are strings. +They have to be declared in the table before the patterns. +Each such declaration defines the name of a variable and +a \fIrestriction\fR to which its value is subjected. +.nf +Example of variable declarations: + + CONST { VAL[0] == '$' }; + REG { VAL[0] == 'r' && VAL[1] >= '0' && VAL[1] <= '3' && + VAL[2] == '\\0' }; + X { TRUE }; + +.fi +The keyword VAL denotes the value of the variable, which is +a null-terminated string. +An operand description given via a variable name matches an +actual operand if the actual operand obeys the associated restriction. +.nf + + CONST matches $1, $-5, $foo etc. + REG matches r0, r1, r2 and r3 + X matches anything +.fi +The restriction (between curly braces) may be any legal "C" +.[ +kernighan ritchie c programming +.] +expression. +It may also contain calls to user-defined procedures. +These procedures must be added to the table after the patterns. +.nf + +Example: + + FERMAT_NUMBER { VAL[0] == '$' && is_fermat_number(&VAL[1]) }; + +.fi +An operand can also be described by a mixture of a string constant +and a variable name. +The most general form allowed is: +.nf + + string_constant1 variable_name string_constant2 + +Example: + + (REG)+ matches (r0)+, (r1)+, (r2)+ and (r3)+ + +.fi +Any of the three components may be omitted, +so the first two forms are just special cases of the general form. +The name of a variable can not be used as a string constant. +In the above context, it is impossible to define an operand that +matches the string "REG". +This limitation is of little consequence, +as the table writer is free to choose the names of variables. +This approach, however, avoids the need for awkward escape sequences. +.PP +A pattern consists of one or more instruction descriptions +(separated by a colon) +followed by an optional constraint. +A pattern "P1 : P2 : .. : Pn C" matches the sequence of +instructions "I1 I2 .. In" if: +.IP (i) 7 +for each i, 1 <= i <= n, Pi matches Ii, as described above; +.IP (ii) +multiple occurrences of the same variable name or of +the keyword ANY stand for the same values throughout the pattern; +.IP (iii) +the optional constraint C is satisfied, i.e. it evaluates to TRUE. +.LP +.nf +The pattern: + + dec REG : move.b CONST,(REG) + +matches: + + dec r0 : move.b $4,(r0) + +but not: + + dec r0 : move.b $4,(r1) + +(as the variable REG matches two different strings). +.fi +If a pattern containing different registers must be described, +extra names for a register should be declared, all sharing +the same restriction. +.nf +Example: + + REG1,REG2 { VAL[0] == 'r' && ..... }; + + addl3 REG1,REG1,REG2 : subl2 REG2,REG1 +.fi +.PP +The optional constraint is an auxiliary "C" expression (just like +the parameter restrictions). +The expression may refer to the variables and to ANY. +.nf +Example: + + move REG1,REG2 { REG1[1] == REG2[1] + 1 } + +matches + + move r1,r0 + move r2,r1 + move r3,r2 +.fi +.PP +The replacement part of a (pattern,replacement) table entry +has the same structure as a pattern, except that: +.IP (i) +it may not contain an additional constraint; +.IP (ii) +it may be empty. +.LP +A replacement may also refer to the values of variables and ANY. +.NH 2 +Examples +.PP +This section contains some realistic examples for +optimization on PDP-11 and Vax assembly code. +.NH 3 +Vax examples +.PP +Suppose the table contains the following declarations: +.nf + X, LOG { TRUE }; + LAB { VAL[0] == 'L' }; /* e.g. L0017 */ + A { no_side_effects(VAL) }; + NUM { is_number(VAL) }; + +.fi +The procedure "no_side_effects" checks if its argument +contains any side effects, i.e. auto increment or auto decrement. +The procedure "is_number" checks if its argument contains only digits. +These procedures must be supplied by the table-writer and must be +included in the table. +.PP +.nf +\fIentry:\fR addl3 X,A,A -> addl2 X,A; + +.fi +This entry changes a 3-operand instruction into a cheaper 2-operand +instruction. +An optimization like: +.nf + + addl3 r0,(r2)+,(r2)+ -> addl2 r0,(r2)+ + +.fi +is illegal, as r2 should be incremented twice. +Hence the second argument is required to +be side-effect free. +.PP +.nf +\fIentry:\fR addw2 $-NUM,X -> subw2 $NUM,X; + +.fi +An instruction like "subw2 $5,r0" is cheaper +than "addw2 $-5,r0", +because constants in the range 0 to 63 are represented +very efficiently on the Vax. +.PP +.nf +\fIentry:\fR bitw $NUM,A : jneq LAB + { is_poweroftwo(NUM,LOG) } -> jbs $LOG,A,LAB; + +.fi +A "bitw x,y" sets the condition codes to the bitwise "and" of +x and y. +A "jbs n,x,l" branches to l if bit n of x is set. +So, for example, the following transformation is possible: +.nf + + bitw $32,r0 : jneq L0017 -> jbs $5,r0,L0017 + +.fi +The user-defined procedure "is_poweroftwo" checks if its first argument is +a power of 2 and, if so, sets its second argument to the logarithm +of the first argument. (Both arguments are strings). +Note that the variable LOG is not used in the pattern itself. +It is assigned a (string) value by "is_poweroftwo" and is used +in the replacement. +.NH 3 +PDP-11 examples +.PP +Suppose we have the following declarations: +.nf + X { TRUE }; + A { no_side_effects(VAL) }; + L1, L2 { VAL[0] == 'I' }; + REG { VAL[0] == 'r' && VAL[1] >= '0' && VAL[1] <= '5' && + VAL[2] == '\\0' }; + +.fi +The implementation of "no_side_effects" may of course +differ for the PDP-11 and the Vax. +.PP +.nf +\fIentry:\fR mov REG,A : ANY A,X -> mov REG,A : ANY REG,X ; + +.fi +This entry implements register subsumption. +If A and REG hold the same value (which is true after "mov REG,A") +and A is used as source (first) operand, it is cheaper to use REG instead. +.PP +.nf +\fIentry:\fR jeq L1 : jbr L2 : labdef L1 -> jne L2 : labdef L1; + +.fi +The "jeq L1" is a "skip over an unconditional jump". "labdef L1" +denotes the definition (i.e. defining occurrence) of label L1. +As the target optimizer has to know how such a definition +looks like, this must be expressed in the table (see Appendix A). +.PP +.nf +\fIentry:\fR add $01,X { carry_dead(REST) } -> inc X; + +.fi +On the PDP-11, an add-one is not equivalent to an increment. +The latter does not set the carry-bit of the condition codes, +while the former does. +So a look-ahead is needed to see if the rest of the input uses +the carry-bit before changing the condition codes. +A look-ahead of one instruction is provided by +the target optimizer. +This will normally be sufficient for compiler-generated code. +The keyword REST contains the mnemonic of the first instruction of +the rest of the input. +If this instruction uses the carry-bit (e.g. an adc, subc, bhis) +the transformation is not allowed. +.bp +.NH 1 +Implementation of the target optimizer +.PP +The target optimizer reads one input file of assembler instructions, +processes it, and writes the optimized code +to the output file. +So it performs one pass over the input. +.NH 2 +The window mechanism +.PP +The optimizer uses a \fIwindow\fR that moves over the input. +It repeatedly tries to match the instructions in the window +with the patterns in the table. +If no match is possible, the window moves +one instruction forwards (to the right). +After a successful match the matched instructions are +removed from the window and are replaced by the +replacement part of the table entry. +Furthermore, the window is moved a few instructions +backwards, +as it is possible that instructions that were rejected earlier now do match. +For example, consider the following patterns: +.DS +cmp $0, X -> tst X ; +mov REG,X : tst X -> move REG.X ; /* redundant test */ +.DE +If the input is: +.DS +mov r0,foo : cmp $0,foo +.DE +then the first instruction is initially rejected. +However, after the transformation +.DS +cmp $0,foo -> tst foo +.DE +the following optimization is possible: +.DS +mov r0,foo : tst foo -> mov r0,foo +.DE +.PP +The window is implemented a a \fIqueue\fR. +Matching takes place at the head of the queue. +New instructions are added at the tail. +If the window is moved forwards, the instruction at the head +is not yet written to the output, +as it may be needed later on. +Instead it is added to a second queue, +the \fIbackup queue\fR. +After a successful match, the entire backup queue is +inserted at the front of the window queue, +which effectively implements the shift backwards. +.PP +Both queues have the length of the longest pattern in the table. +If, as a result of a forward window move, +the backup queue gets full, +the instruction at its head is outputted and removed. +Instructions are read from the input whenever the +window queue contains fewer elements than the length +of the longest pattern. +.NH 2 +Pattern matching +.PP +Pattern matching is done in three steps: +.IP (i) 7 +find patterns in the table whose instruction mnemonics +match the mnemonics of the instructions in the +current window; +.IP (ii) +check if the operands of the pattern match the operands of the +instructions in the current window; +.IP (iii) +check if the optional constraint is satisfied. +.LP +For step (i) hashing is used. +The mnemonic of the first instruction of the window +is used to determine a list of possible patterns. +Patterns starting with ANY are always tried. +.PP +Matching of operand descriptions against actual operands +takes place as follows. +The general form of an operand description is: +.DS +string_constant1 variable_name string_constant2 +.DE +The actual operand should begin with string_constant1 and end +on string_constant2. +If so, these strings are stripped from it and the remaining string is +matched against the variable. +Matching a string against a variable is +defined as follows: +.IP 1. +initially (before the entire pattern match) +all variables are uninstantiated; +.IP 2. +matching a string against an uninstantiated variable +succeeds if the restriction associated with the variable is +satisfied. +As a side effect, it causes the variable to be instantiated to +the string; +.IP 3. +matching a string against an instantiated variable succeeds +only if the variable was instantiated to the same string. +.LP +Matching an actual mnemonic against the keyword ANY is defined likewise. +.PP +The matching scheme implements the requirement that multiple occurrences +of the same variable name or of the keyword ANY should +stand for the same values throughout the entire pattern +(see section 2.). +.PP +Both the parameter restriction of 2. and the constraint of step (iii) +are checked by executing the "C" expression. +.NH 2 +Data structures +.PP +The most important data structure is the representation +of the input instructions. +For every instruction we use two representations: +.IP (i) +the textual representation, +i.e. the exact code as it appeared in the input; +.IP (ii) +a structural representation, +containing the opcode and the operands. +.LP +The opcode of an instruction is determined as soon as it is read. +If the line contains a label definition, the opcode is set +to "labdef", so a label definition is treated like a normal +instruction. +.PP +The operands of an instruction are not determined until +they are needed, i.e. until step (i) of the pattern matching +process has succeeded. +For every instruction we keep track of a \fIstate\fR. +After the opcode has successfully been determined, +the state is OPC_ONLY. +Once the operands have been recognized, the state is set to DONE. +If the opcode or operands can not be determined, +or if the instruction cannot be optimized for any other +reason (see Appendix A), the state is set to JUNK +and any attempt to match it will fail. +.PP +For each table entry we record the following information: +.IP (i) 7 +the length of the pattern (i.e. the number of instruction descriptions) +.IP (ii) +a description of the instructions of the pattern +.IP (iii) +the length of the replacement +.IP (iv) +a description of the instructions of the replacement. +.LP +The description of an instruction consists of: +.IP (i) +the opcode +.IP (ii) +for each operand, a description of the operand. +.LP +The description of an operand of the form: +.DS +string_constant1 variable_name string_constant2 +.DE +contains: +.IP (i) +both string constants +.IP (ii) +the number of the variable. +.LP +Each declared variable is assigned a unique number. +For every variable we maintain: +.IP (i) +its state (instantiated or not instantiated) +.IP (ii) +its current value (a string). +.LP +The restrictions on variables and the constraints are stored +in a switch-statement, +indexed by variable number and entry number respectively. +.bp +.NH 1 +Implementation of the target optimizer generator +.PP +The target optimizer generator (\fItopgen\fR) +reads a target machine description table and produces +two files: +.IP gen.h: 9 +contains macro definitions for +machine parameters that were changed +in the parameter section of the table (see appendix A) +and for some attributes derived from the table +(longest pattern, number of patterns, number +of variables). +.IP gen.c: +contains the entry description tables, +code for checking the parameter restrictions and constraints +(switch statements) +and the user-defined procedures. +.LP +These two files are compiled together with some machine-independent +files to produce a target optimizer. +.PP +Topgen is implemented using +the LL(1) parser generator system LLgen, +a powerful tool of the Amsterdam Compiler Kit. +This system provides a flexible way of describing the syntax of the tables. +The syntactical description of the table format included +in Appendix A was derived from the LLgen syntax rules. +.PP +The parser uses a simple, hand-written, lexical analyzer (scanner). +The scanner returns a single character in most cases. +The recognition of identifiers is left to the parser, as +this eases the analysis of operand descriptions. +Comments are removed from the input by the scanner, +but white space is passed to the parser, +as it is meaningful in some contexts (it separates the +opcode description from the description of the first operand). +.PP +Topgen maintains two symbol tables, one for variable names and one +for tunable parameters. +The symbol tables are organized as binary trees. +.bp +.SH +Appendix A +.PP +In this appendix we present a complete definition of the target +optimizer description table format. +This appendix is intended for table-writers. +We use syntax rules for the description of the table format. +The following notation is used: +.nf + { a } zero or more of a + [ a ] zero or one of a + a b a followed by b + a | b a or b + +.fi +Terminals are given in quotes, as in ';'. +.PP +The table may contain white space and comment at all reasonable places. +Comments are as in "C", so they begin with /* and end on */. +Identifiers are sequences of letters, digits and the underscore ('_'), +beginning with a letter. +.PP +.DS +table -> {parameter_line} '%%;' {variable_declaration} '%%;' + {entry} '%%;' user_routines. + +.DE +A table consists of four sections, containing machine-dependent +constants, variable declarations, pattern rules and +user-supplied subroutines. +.PP +.DS +parameter_line -> identifier value ';' . + +.DE +A parameter line defines some attributes of the target machines +assembly code. +For unspecified parameters default values apply. +The names of the parameters and the corresponding defaults +are shown in table 1. +.DS + OPC_TERMINATOR ' ' + OP_SEPARATOR ',' + LABEL_STARTER 'I' + LABEL_TERMINATOR ':' + MAXOP 2 + MAXOPLEN 25 + MAX_OPC_LEN 10 + MAXVARLEN 25 + MAXLINELEN 100 + + table 1: parameter names and defaults +.DE +The OPC_TERMINATOR is the character that separates the instruction +mnemonic from the first operand (if any). +The OP_SEPARATOR separates adjacent operands. +A LABEL_STARTER is the first character of an instruction label. +(Instruction labels are assumed to start with the same character). +The LABEL_TERMINATOR is the last character of a label definition. +It is assumed that this character is not used in an applied +occurrence of the label identifier. +For example, the defining occurrence may be "I0017:" +and the applied occurrence may be "I0017" +as in "jmp I0017". +MAXOP defines the maximum number of operands an instruction can have. +MAXOPLEN is the maximum length (in characters) of an operand. +MAX_OPC_LEN is the maximum length of an instruction opcode. +MAXVARLEN is the maximum length of a declared string variable. +As variables may be set by user routines (see "bitw" example for +the Vax) the table-writer must have access to this length and +must be able to change it. +MAXLINELEN denotes the maximum length of a line of assembly code. +.PP +If a line of assembly code violates any of the assumptions or +exceeds some limit, +the line is not optimized. +Optimization does, however, proceed with the rest of the input. +.PP +.DS +variable_declaration -> identifier {',' identifier} restriction ';' . + +restriction -> '{' anything '}' . +.DE +A variable declaration declares one or more string variables +that may be used in the patterns and in the replacements. +If a variable is used as part of an operand description in +a pattern, the entire pattern can only match if the +restriction evaluates to TRUE. +If the pattern does match, the variable is assigned the matching +part of the actual operand. +Variables that are not used in a pattern are initialized to +null-strings and may be assigned a value in the constraint-part of +the pattern. +.PP +The restriction must be a legal "C" expression. +It may not contain a closing bracket ('}'). +Inside the expression, the name VAL stands for the part of the actual +(matching) operand. +The expression may contain calls to procedures that are defined in the +user-routines section. +.DS +entry -> pattern '->' replacement ';' . + +pattern -> instruction_descr + { ':' instruction_descr } + constraint . + +replacement -> [ instruction_descr { ':' instruction_descr } ] . + +instruction_descr -> opcode + white + [ operand_descr { ',' operand_descr } ] . + +constraint -> '{' anything '}' . + +operand_descr -> [ string_constant ] + [ variable_name ] + [ string_constant ] . + +variable_name -> identifier . + +opcode -> anything . +.DE +The symbol 'white' stands for white space (space or tab). +An opcode can be any string not containing the special +symbols ';', '{', '}', ':', ',', '->' or white space. +To be recognized, it must begin with a letter. +The opcode should either be a mnemonic of a target machine +instruction or it should be one of the keywords ANY and labdef. +ANY matches any actual opcode. labdef matches only label definitions. +.PP +If an operand description contains an identifier (as defined earlier), +it is checked if the identifier is the name of a declared variable. +This effects the semantics of the matching rules for the operand, +as described in section 2. +An operand may contain at most one such variable name. +.PP +The constraint must be a legal "C" expression, just as the operand restriction. +It may call user-defined procedures and use or change the value of +declared variables. +It may also use the string variable REST, +which contains the mnemonic of the first instruction of the +rest of the input. (REST is a null-string if this mnemonic can +not be determined). +.DS +user_routines -> anything . +.DE +The remainder of the table consists of user-defined subroutines. +.bp +.[ +$LIST$ +.] From 55afae9ad0097bff897f423617efc621d8abae9b Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 10 Dec 1986 12:00:55 +0000 Subject: [PATCH 0383/1625] simplified 0-padding, minor cosmetic changes --- lang/cem/cemcom/code.c | 38 ++++++------ lang/cem/cemcom/domacro.c | 8 +-- lang/cem/cemcom/idf.c | 1 - lang/cem/cemcom/ival.c | 125 +++++++++++++++++--------------------- lang/cem/cemcom/stack.c | 3 +- lang/cem/cemcom/struct.c | 2 +- lang/cem/cemcom/type.c | 17 +++--- 7 files changed, 90 insertions(+), 104 deletions(-) diff --git a/lang/cem/cemcom/code.c b/lang/cem/cemcom/code.c index ca5013c6..e7cadc6a 100644 --- a/lang/cem/cemcom/code.c +++ b/lang/cem/cemcom/code.c @@ -169,6 +169,7 @@ begin_proc(name, def) /* to be called when entering a procedure */ - a fil pseudo instruction */ arith size; + register struct type *tp = def->df_type; #ifndef USE_TMP code_scope(name, def); @@ -178,15 +179,16 @@ begin_proc(name, def) /* to be called when entering a procedure */ DfaStartFunction(name); #endif DATAFLOW - if (def->df_type->tp_fund != FUNCTION) { + if (tp->tp_fund != FUNCTION) { error("making function body for non-function"); - func_tp = error_type; + tp = error_type; } else - func_tp = def->df_type->tp_up; - size = ATW(func_tp->tp_size); + tp = tp->tp_up; + func_tp = tp; + size = ATW(tp->tp_size); C_pro_narg(name); - if (is_struct_or_union(func_tp->tp_fund)) { + if (is_struct_or_union(tp->tp_fund)) { C_df_dlb(func_res_label = data_label()); C_bss_cst(size, (arith)0, 1); } @@ -309,7 +311,7 @@ code_declaration(idf, expr, lvl, sc) */ char *text = idf->id_text; register struct def *def = idf->id_def; - arith size = def->df_type->tp_size; + register arith size = def->df_type->tp_size; int def_sc = def->df_sc; if (def_sc == TYPEDEF) /* no code for typedefs */ @@ -387,6 +389,7 @@ loc_init(expr, id) It frees the expression afterwards. */ register struct type *tp = id->id_def->df_type; + register struct expr *e = expr; ASSERT(id->id_def->df_sc != STATIC); switch (tp->tp_fund) { @@ -394,20 +397,20 @@ loc_init(expr, id) case STRUCT: case UNION: error("no automatic aggregate initialisation"); - free_expression(expr); + free_expression(e); return; } - if (ISCOMMA(expr)) { /* embraced: int i = {12}; */ + if (ISCOMMA(e)) { /* embraced: int i = {12}; */ if (options['R']) { - if (ISCOMMA(expr->OP_LEFT)) /* int i = {{1}} */ - expr_error(expr, "extra braces not allowed"); + if (ISCOMMA(e->OP_LEFT)) /* int i = {{1}} */ + expr_error(e, "extra braces not allowed"); else - if (expr->OP_RIGHT != 0) /* int i = {1 , 2} */ - expr_error(expr, "too many initializers"); + if (e->OP_RIGHT != 0) /* int i = {1 , 2} */ + expr_error(e, "too many initializers"); } - while (expr) { - loc_init(expr->OP_LEFT, id); - expr = expr->OP_RIGHT; + while (e) { + loc_init(e->OP_LEFT, id); + e = e->OP_RIGHT; } } else { /* not embraced */ @@ -428,11 +431,10 @@ bss(idf) { /* bss() allocates bss space for the global idf. */ - register struct def *def = idf->id_def; - arith size = def->df_type->tp_size; + arith size = idf->id_def->df_type->tp_size; #ifndef USE_TMP - code_scope(idf->id_text, def); + code_scope(idf->id_text, idf->id_def); #endif USE_TMP /* Since bss() is only called if df_alloc is non-zero, and since df_alloc is only non-zero if size >= 0, we have: diff --git a/lang/cem/cemcom/domacro.c b/lang/cem/cemcom/domacro.c index fe2f9f1e..ba92c11e 100644 --- a/lang/cem/cemcom/domacro.c +++ b/lang/cem/cemcom/domacro.c @@ -134,7 +134,7 @@ skip_block() seen. */ register int ch; - register skiplevel = nestlevel; /* current nesting level */ + register int skiplevel = nestlevel; /* current nesting level */ struct token tk; NoUnstack++; @@ -530,10 +530,10 @@ get_text(formals, length) identifiers, because they might be replaced by some actual parameter. Other tokens will not be seen as such. */ - register c; - register text_size; + register int c; + register int text_size; char *text = Malloc(text_size = ITEXTSIZE); - register pos = 0; + register int pos = 0; LoadChar(c); diff --git a/lang/cem/cemcom/idf.c b/lang/cem/cemcom/idf.c index de391853..9baace1f 100644 --- a/lang/cem/cemcom/idf.c +++ b/lang/cem/cemcom/idf.c @@ -426,7 +426,6 @@ global_redecl(idf, new_sc, tp) else { warning("%s redeclared to static", idf->id_text); - def->df_sc = STATIC; } def->df_sc = new_sc; break; diff --git a/lang/cem/cemcom/ival.c b/lang/cem/cemcom/ival.c index f7e94121..b64577d9 100644 --- a/lang/cem/cemcom/ival.c +++ b/lang/cem/cemcom/ival.c @@ -25,6 +25,7 @@ char *symbol2str(); char *long2str(); struct expr *do_array(), *do_struct(), *IVAL(); +extern char options[]; /* do_ival() performs the initialisation of a global variable of type tp with the initialisation expression expr by calling IVAL(). @@ -325,59 +326,40 @@ check_and_pad(ex, tpp) pad(tp) register struct type *tp; { + register arith sz = tp->tp_size; + switch (tp->tp_fund) { case ARRAY: - { - register long dim; - if (valid_type(tp->tp_up, "array element") == 0) return; - dim = tp->tp_size / tp->tp_up->tp_size; - /* assume dimension is known */ - while (dim-- > 0) - pad(tp->tp_up); break; - } case STRUCT: - { - register struct sdef *sdef = tp->tp_sdef; - if (valid_type(tp, "struct") == 0) return; - do { - pad(sdef->sd_type); - if (sdef->sd_sdef) - zero_bytes(sdef); - } while (sdef = sdef->sd_sdef); break; - } + case UNION: + if (valid_type(tp, "union") == 0) + return; + if (options['R']) { + warning("initialisation of unions not allowed"); + } + break; #ifndef NOBITFIELD case FIELD: put_bf(tp, (arith)0); - break; + return; #endif NOBITFIELD - case INT: - case SHORT: - case LONG: - case CHAR: - case ENUM: - case POINTER: - C_con_ucon("0", tp->tp_size); - break; -#ifndef NOFLOAT - case FLOAT: - case DOUBLE: - C_con_fcon("0", tp->tp_size); - break; -#endif NOFLOAT - case UNION: - error("initialisation of unions not allowed"); - break; case ERRONEOUS: - break; - default: - crash("(generate) bad fundamental type %s\n", - symbol2str(tp->tp_fund)); + return; + } + + while (sz >= word_size) { + C_con_cst((arith) 0); + sz -= word_size; + } + while (sz) { + C_con_icon("0", (arith) 1); + sz--; } } @@ -387,8 +369,8 @@ pad(tp) No further comment is needed to explain the internal structure of this straightforward function. */ -check_ival(ex, tp) - struct expr *ex; +check_ival(expr, tp) + register struct expr *expr; register struct type *tp; { /* The philosophy here is that ch7cast puts an explicit @@ -396,6 +378,7 @@ check_ival(ex, tp) are not compatible. In this case, the initialisation expression is no longer a constant. */ + struct expr *ex = expr; switch (tp->tp_fund) { case CHAR: @@ -405,66 +388,68 @@ check_ival(ex, tp) case ENUM: case POINTER: ch7cast(&ex, '=', tp); + expr = ex; #ifdef DEBUG - print_expr("init-expr after cast", ex); + print_expr("init-expr after cast", expr); #endif DEBUG - if (!is_ld_cst(ex)) - illegal_init_cst(ex); + if (!is_ld_cst(expr)) + illegal_init_cst(expr); else - if (ex->VL_CLASS == Const) - con_int(ex); + if (expr->VL_CLASS == Const) + con_int(expr); else - if (ex->VL_CLASS == Name) { - register struct idf *id = ex->VL_IDF; - register struct def *df = id->id_def; + if (expr->VL_CLASS == Name) { + register struct idf *idf = expr->VL_IDF; - if (df->df_level >= L_LOCAL) - illegal_init_cst(ex); + if (idf->id_def->df_level >= L_LOCAL) + illegal_init_cst(expr); else /* e.g., int f(); int p = f; */ - if (df->df_type->tp_fund == FUNCTION) - C_con_pnam(id->id_text); + if (idf->id_def->df_type->tp_fund == FUNCTION) + C_con_pnam(idf->id_text); else /* e.g., int a; int *p = &a; */ - C_con_dnam(id->id_text, ex->VL_VALUE); + C_con_dnam(idf->id_text, expr->VL_VALUE); } else { - ASSERT(ex->VL_CLASS == Label); - C_con_dlb(ex->VL_LBL, ex->VL_VALUE); + ASSERT(expr->VL_CLASS == Label); + C_con_dlb(expr->VL_LBL, expr->VL_VALUE); } break; #ifndef NOFLOAT case FLOAT: case DOUBLE: ch7cast(&ex, '=', tp); + expr = ex; #ifdef DEBUG - print_expr("init-expr after cast", ex); + print_expr("init-expr after cast", expr); #endif DEBUG - if (ex->ex_class == Float) - C_con_fcon(ex->FL_VALUE, ex->ex_type->tp_size); + if (expr->ex_class == Float) + C_con_fcon(expr->FL_VALUE, expr->ex_type->tp_size); else - if (ex->ex_class == Oper && ex->OP_OPER == INT2FLOAT) { + if (expr->ex_class == Oper && expr->OP_OPER == INT2FLOAT) { /* float f = 1; */ - ex = ex->OP_RIGHT; - if (is_cp_cst(ex)) - C_con_fcon(long2str((long)ex->VL_VALUE, 10), + expr = expr->OP_RIGHT; + if (is_cp_cst(expr)) + C_con_fcon(long2str((long)expr->VL_VALUE, 10), tp->tp_size); else - illegal_init_cst(ex); + illegal_init_cst(expr); } else - illegal_init_cst(ex); + illegal_init_cst(expr); break; #endif NOFLOAT #ifndef NOBITFIELD case FIELD: ch7cast(&ex, '=', tp->tp_up); + expr = ex; #ifdef DEBUG - print_expr("init-expr after cast", ex); + print_expr("init-expr after cast", expr); #endif DEBUG - if (is_cp_cst(ex)) - put_bf(tp, ex->VL_VALUE); + if (is_cp_cst(expr)) + put_bf(tp, expr->VL_VALUE); else - illegal_init_cst(ex); + illegal_init_cst(expr); break; #endif NOBITFIELD @@ -574,7 +559,7 @@ zero_bytes(sd) */ register int n = sd->sd_sdef->sd_offset - sd->sd_offset - size_of_type(sd->sd_type, "struct member"); - register count = n; + register int count = n; while (n-- > 0) con_nullbyte(); diff --git a/lang/cem/cemcom/stack.c b/lang/cem/cemcom/stack.c index 7b0119d7..237fdf2e 100644 --- a/lang/cem/cemcom/stack.c +++ b/lang/cem/cemcom/stack.c @@ -251,7 +251,8 @@ unstack_world() ) { /* space must be allocated */ bss(idf); - namelist(idf->id_text); /* may be common */ + if (def->df_sc != STATIC) + namelist(idf->id_text); /* may be common */ def->df_alloc = ALLOC_DONE; /* see Note below */ } se = se->next; diff --git a/lang/cem/cemcom/struct.c b/lang/cem/cemcom/struct.c index 7eea59d8..2728738e 100644 --- a/lang/cem/cemcom/struct.c +++ b/lang/cem/cemcom/struct.c @@ -158,7 +158,7 @@ add_sel(stp, tp, idf, sdefpp, szp, fd) /* this is horrible */ } check_selector(idf, stp) - struct idf *idf; + register struct idf *idf; struct type *stp; /* the type of the struct */ { /* checks if idf occurs already as a selector in diff --git a/lang/cem/cemcom/type.c b/lang/cem/cemcom/type.c index ec2c96bb..6243395e 100644 --- a/lang/cem/cemcom/type.c +++ b/lang/cem/cemcom/type.c @@ -37,7 +37,7 @@ struct type *pa_type; /* Pointer-Arithmetic type */ struct type * create_type(fund) - register int fund; + int fund; { /* A brand new struct type is created, and its tp_fund set to fund. @@ -180,7 +180,7 @@ size_of_type(tp, nm) } idf2type(idf, tpp) - register struct idf *idf; + struct idf *idf; struct type **tpp; { /* Decoding a typedef-ed identifier: if the size is yet @@ -188,16 +188,15 @@ idf2type(idf, tpp) prevent garbage at the initialisation of arrays with unknown size. */ - if ( idf->id_def->df_type->tp_size < (arith)0 && - idf->id_def->df_type->tp_fund == ARRAY - ) { - struct type *ntp = new_type(); - *ntp = *(idf->id_def->df_type); + register struct type *tp = idf->id_def->df_type; + + if ( tp->tp_size < (arith)0 && tp->tp_fund == ARRAY) { + *tpp = new_type(); + **tpp = *tp; /* this is really a structure assignment, AAGH!!! */ - *tpp = ntp; } else { - *tpp = idf->id_def->df_type; + *tpp = tp; } } From 11f62381268f0a3c844393351f2ef423366c2f3a Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 10 Dec 1986 15:13:04 +0000 Subject: [PATCH 0384/1625] added nmclash.c, mods to Makefile/Resolve --- lang/m2/comp/Makefile | 23 +++++++++++++---------- lang/m2/comp/Resolve | 2 +- lang/m2/comp/nmclash.c | 4 ++++ 3 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 lang/m2/comp/nmclash.c diff --git a/lang/m2/comp/Makefile b/lang/m2/comp/Makefile index 9178d4ee..a38abbe0 100644 --- a/lang/m2/comp/Makefile +++ b/lang/m2/comp/Makefile @@ -1,20 +1,23 @@ # make modula-2 "compiler" -EMDIR = ../../.. -MHDIR = $(EMDIR)/modules/h -PKGDIR = $(EMDIR)/modules/pkg -LIBDIR = $(EMDIR)/modules/lib +EMHOME = ../../.. +MHDIR = $(EMHOME)/modules/h +PKGDIR = $(EMHOME)/modules/pkg +LIBDIR = $(EMHOME)/modules/lib OBJECTCODE = $(LIBDIR)/libemk.a -LLGEN = $(EMDIR)/bin/LLgen +LLGEN = $(EMHOME)/bin/LLgen +MKDEP = $(EMHOME)/bin/mkdep +PRID = $(EMHOME)/bin/prid +CID = $(EMHOME)/bin/cid CURRDIR = . -INCLUDES = -I$(MHDIR) -I$(EMDIR)/h -I$(PKGDIR) +INCLUDES = -I$(MHDIR) -I$(EMHOME)/h -I$(PKGDIR) GFILES = tokenfile.g program.g declar.g expression.g statement.g LLGENOPTIONS = PROFILE = CFLAGS = $(PROFILE) $(INCLUDES) -DSTATIC= LINTFLAGS = -DSTATIC= -DNORCSID -MALLOC = $(LIBDIR)/dickmalloc.o +MALLOC = $(LIBDIR)/malloc.o LFLAGS = $(PROFILE) LSRC = tokenfile.c program.c declar.c expression.c statement.c LOBJ = tokenfile.o program.o declar.o expression.o statement.o @@ -55,7 +58,7 @@ all: Cfiles @rm -f nmclash.o a.out install: all - cp $(CURRDIR)/main $(EMDIR)/lib/em_m2 + cp $(CURRDIR)/main $(EMHOME)/lib/em_m2 clean: rm -f $(OBJ) $(GENFILES) LLfiles hfiles Cfiles tab clashes $(CURRDIR)/main @@ -66,7 +69,7 @@ lint: Cfiles @rm -f nmclash.o a.out longnames: $(SRC) $(HFILES) - sh -c 'if test -f longnames ; then prid -l7 longnames $? > Xlongnames ; mv Xlongnames longnames ; else prid -l7 $? > longnames ; fi' + sh -c 'if test -f longnames ; then $(PRID) -l7 longnames $? > Xlongnames ; mv Xlongnames longnames ; else $(PRID) -l7 $? > longnames ; fi' # entry points not to be used directly @@ -114,7 +117,7 @@ tab: depend: sed '/^#AUTOAUTO/,$$d' Makefile > Makefile.new echo '#AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO' >> Makefile.new - mkdep $(SRC) |\ + $(MKDEP) $(SRC) |\ sed 's/\.c:/\.o:/' >> Makefile.new mv Makefile Makefile.old mv Makefile.new Makefile diff --git a/lang/m2/comp/Resolve b/lang/m2/comp/Resolve index e107d789..388b55df 100755 --- a/lang/m2/comp/Resolve +++ b/lang/m2/comp/Resolve @@ -48,7 +48,7 @@ do cat >> Makefile < $i + \$(CID) -Fclashes < $PW/$i > $i EOF done make CURRDIR=$currdir $target diff --git a/lang/m2/comp/nmclash.c b/lang/m2/comp/nmclash.c new file mode 100644 index 00000000..ca2567a8 --- /dev/null +++ b/lang/m2/comp/nmclash.c @@ -0,0 +1,4 @@ +/* Accepted if many characters of long names are significant */ +abcdefghijklmnopr() { } +abcdefghijklmnopq() { } +main() { } From 1412249c414f92ec98f2581358272e3dbe6683ce Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 10 Dec 1986 15:26:10 +0000 Subject: [PATCH 0385/1625] Documented LLmessage(-1). --- doc/LLgen/LLgen.n | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/LLgen/LLgen.n b/doc/LLgen/LLgen.n index 1c048585..2071a965 100644 --- a/doc/LLgen/LLgen.n +++ b/doc/LLgen/LLgen.n @@ -10,7 +10,6 @@ \}\ \} .cs 5 22u -.RP .ND .EQ delim @@ @@ -631,13 +630,14 @@ C-program. It should eventually call one of the startsymbol routines. .PP The routine \fILLmessage\fR must accept one -parameter, whose value is a token number, zero or negative. +parameter, whose value is a token number, zero or -1. .br A zero parameter indicates that the current token (the one in the external variable \fILLsymb\fR) is deleted. .br -A negative parameter indicates that a stack overflow occurred. -This usually is a fatal error. +A -1 parameter indicates that the parser expected end of file, but did'nt get +it. +The parser will then skip tokens until end of file is detected. .br A parameter that is a token number (a positive parameter) indicates that this From cad1a202b17d5fdb75ec78e1c8d465586014065a Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 10 Dec 1986 15:27:36 +0000 Subject: [PATCH 0386/1625] Adapted to possible use of troff --- doc/top/Makefile | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/doc/top/Makefile b/doc/top/Makefile index fa5ee63c..a572b6d3 100644 --- a/doc/top/Makefile +++ b/doc/top/Makefile @@ -1,6 +1,11 @@ -top.f: - refer -sA+T -l4,2 -p refs.top top.n | nroff -ms > top.f -top.f.35: - refer -sA+T -l4,2 -p refs.top top.n | nroff -ms -Thr35 > top.f.35 -top.f.agfa: - refer -sA+T -l4,2 -p refs.top top.n | nroff -ms -Tlp > top.f.agfa +# $Header$ + +MS=-ms +NROFF=nroff +REFER=refer +TBL=tbl +SUF=pr + +../top.$(SUF): top.n refs.top + $(REFER) -sA+T -l4,2 -p refs.top top.n | $(TBL) | \ + $(NROFF) $(MS) > $@ From 9ac07096485e6749a9a3a61f37f6cbb0f431d4b1 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 10 Dec 1986 15:28:06 +0000 Subject: [PATCH 0387/1625] Added a reference for LLgen. --- doc/top/refs.top | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/top/refs.top b/doc/top/refs.top index 5cac9ed6..c4438987 100644 --- a/doc/top/refs.top +++ b/doc/top/refs.top @@ -77,3 +77,8 @@ Intermediate Code %C Reading, Massachusetts %D 1978 +%T Some Topics in Parser Generation +%A C.J.H. Jacobs +%R Rapport IR-105 +%D October 1985 +%I Vrije Universiteit, Amsterdam From 96b2cf829844534d102c98f9dc337d7c75c56147 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 10 Dec 1986 15:28:30 +0000 Subject: [PATCH 0388/1625] Adapted to typesetter and added a reference for LLgen. --- doc/top/top.n | 134 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 101 insertions(+), 33 deletions(-) diff --git a/doc/top/top.n b/doc/top/top.n index 5c524a7b..7013f361 100644 --- a/doc/top/top.n +++ b/doc/top/top.n @@ -1,8 +1,4 @@ .ND -.pl 11.7i -.ll 80m -.nr LL 80m -.nr tl 78m .tr ~ .ds >. . .TL @@ -82,6 +78,7 @@ machine-dependent description table (see figure 1.). So the major part of the code of a target optimizer is shared among all target optimizers. .DS +.ft 5 |-------------------------| @@ -95,6 +92,7 @@ table | | | | |-----------------| |-------------------------| target optimizer +.ft R Figure 1: Generation of a target optimizer. @@ -163,22 +161,26 @@ ANY matches every instruction mnemonic. .nf Examples of mnemonic descriptions: +.ft 5 add sub.l mulw3 ANY +.ft R .fi .PP An operand can also be described by a string constant. .nf Examples: +.ft 5 (sp)+ r5 -4(r6) +.ft R .fi Alternatively, it can be described by means of a \fIvariable name\fR. Variables have values which are strings. @@ -187,22 +189,27 @@ Each such declaration defines the name of a variable and a \fIrestriction\fR to which its value is subjected. .nf Example of variable declarations: +.ft 5 CONST { VAL[0] == '$' }; REG { VAL[0] == 'r' && VAL[1] >= '0' && VAL[1] <= '3' && VAL[2] == '\\0' }; X { TRUE }; +.ft R .fi The keyword VAL denotes the value of the variable, which is a null-terminated string. An operand description given via a variable name matches an actual operand if the actual operand obeys the associated restriction. .nf +.ft 5 CONST matches $1, $-5, $foo etc. REG matches r0, r1, r2 and r3 X matches anything +.ft R + .fi The restriction (between curly braces) may be any legal "C" .[ @@ -214,9 +221,11 @@ These procedures must be added to the table after the patterns. .nf Example: +.ft 5 FERMAT_NUMBER { VAL[0] == '$' && is_fermat_number(&VAL[1]) }; +.ft R .fi An operand can also be described by a mixture of a string constant and a variable name. @@ -226,9 +235,11 @@ The most general form allowed is: string_constant1 variable_name string_constant2 Example: +.ft 5 (REG)+ matches (r0)+, (r1)+, (r2)+ and (r3)+ +.ft R .fi Any of the three components may be omitted, so the first two forms are just special cases of the general form. @@ -254,17 +265,23 @@ the optional constraint C is satisfied, i.e. it evaluates to TRUE. .LP .nf The pattern: +.ft 5 dec REG : move.b CONST,(REG) +.ft R matches: +.ft 5 dec r0 : move.b $4,(r0) +.ft R but not: +.ft 5 dec r0 : move.b $4,(r1) +.ft R (as the variable REG matches two different strings). .fi If a pattern containing different registers must be described, @@ -272,10 +289,12 @@ extra names for a register should be declared, all sharing the same restriction. .nf Example: +.ft 5 REG1,REG2 { VAL[0] == 'r' && ..... }; addl3 REG1,REG1,REG2 : subl2 REG2,REG1 +.ft R .fi .PP The optional constraint is an auxiliary "C" expression (just like @@ -283,14 +302,18 @@ the parameter restrictions). The expression may refer to the variables and to ANY. .nf Example: +.ft 5 move REG1,REG2 { REG1[1] == REG2[1] + 1 } +.ft R matches +.ft 5 move r1,r0 move r2,r1 move r3,r2 +.ft R .fi .PP The replacement part of a (pattern,replacement) table entry @@ -311,10 +334,13 @@ Vax examples .PP Suppose the table contains the following declarations: .nf + +.ft 5 X, LOG { TRUE }; LAB { VAL[0] == 'L' }; /* e.g. L0017 */ A { no_side_effects(VAL) }; NUM { is_number(VAL) }; +.ft R .fi The procedure "no_side_effects" checks if its argument @@ -324,23 +350,29 @@ These procedures must be supplied by the table-writer and must be included in the table. .PP .nf -\fIentry:\fR addl3 X,A,A -> addl2 X,A; +.ft 5 +\fIentry:\fP addl3 X,A,A -> addl2 X,A; +.ft R .fi This entry changes a 3-operand instruction into a cheaper 2-operand instruction. An optimization like: .nf +.ft 5 addl3 r0,(r2)+,(r2)+ -> addl2 r0,(r2)+ +.ft R .fi is illegal, as r2 should be incremented twice. Hence the second argument is required to be side-effect free. .PP .nf -\fIentry:\fR addw2 $-NUM,X -> subw2 $NUM,X; +.ft 5 +\fIentry:\fP addw2 $-NUM,X -> subw2 $NUM,X; +.ft R .fi An instruction like "subw2 $5,r0" is cheaper @@ -349,18 +381,22 @@ because constants in the range 0 to 63 are represented very efficiently on the Vax. .PP .nf -\fIentry:\fR bitw $NUM,A : jneq LAB +.ft 5 +\fIentry:\fP bitw $NUM,A : jneq LAB { is_poweroftwo(NUM,LOG) } -> jbs $LOG,A,LAB; +.ft R .fi A "bitw x,y" sets the condition codes to the bitwise "and" of x and y. A "jbs n,x,l" branches to l if bit n of x is set. So, for example, the following transformation is possible: .nf +.ft 5 bitw $32,r0 : jneq L0017 -> jbs $5,r0,L0017 +.ft R .fi The user-defined procedure "is_poweroftwo" checks if its first argument is a power of 2 and, if so, sets its second argument to the logarithm @@ -373,18 +409,23 @@ PDP-11 examples .PP Suppose we have the following declarations: .nf + +.ft 5 X { TRUE }; A { no_side_effects(VAL) }; L1, L2 { VAL[0] == 'I' }; REG { VAL[0] == 'r' && VAL[1] >= '0' && VAL[1] <= '5' && VAL[2] == '\\0' }; +.ft P .fi The implementation of "no_side_effects" may of course differ for the PDP-11 and the Vax. .PP .nf -\fIentry:\fR mov REG,A : ANY A,X -> mov REG,A : ANY REG,X ; +.ft 5 +\fIentry:\fP mov REG,A : ANY A,X -> mov REG,A : ANY REG,X ; +.ft R .fi This entry implements register subsumption. @@ -392,7 +433,9 @@ If A and REG hold the same value (which is true after "mov REG,A") and A is used as source (first) operand, it is cheaper to use REG instead. .PP .nf -\fIentry:\fR jeq L1 : jbr L2 : labdef L1 -> jne L2 : labdef L1; +.ft 5 +\fIentry:\fP jeq L1 : jbr L2 : labdef L1 -> jne L2 : labdef L1; +.ft R .fi The "jeq L1" is a "skip over an unconditional jump". "labdef L1" @@ -401,7 +444,9 @@ As the target optimizer has to know how such a definition looks like, this must be expressed in the table (see Appendix A). .PP .nf -\fIentry:\fR add $01,X { carry_dead(REST) } -> inc X; +.ft 5 +\fIentry:\fP add $01,X { carry_dead(REST) } -> inc X; +.ft R .fi On the PDP-11, an add-one is not equivalent to an increment. @@ -440,24 +485,32 @@ backwards, as it is possible that instructions that were rejected earlier now do match. For example, consider the following patterns: .DS +.ft 5 cmp $0, X -> tst X ; mov REG,X : tst X -> move REG.X ; /* redundant test */ +.ft R .DE If the input is: .DS +.ft 5 mov r0,foo : cmp $0,foo +.ft R .DE then the first instruction is initially rejected. However, after the transformation .DS +.ft 5 cmp $0,foo -> tst foo +.ft R .DE the following optimization is possible: .DS +.ft 5 mov r0,foo : tst foo -> mov r0,foo +.ft R .DE .PP -The window is implemented a a \fIqueue\fR. +The window is implemented as a \fIqueue\fR. Matching takes place at the head of the queue. New instructions are added at the tail. If the window is moved forwards, the instruction at the head @@ -619,7 +672,10 @@ These two files are compiled together with some machine-independent files to produce a target optimizer. .PP Topgen is implemented using -the LL(1) parser generator system LLgen, +the LL(1) parser generator system LLgen , +.[ +jacobs topics parser generation +.] a powerful tool of the Amsterdam Compiler Kit. This system provides a flexible way of describing the syntax of the tables. The syntactical description of the table format included @@ -646,13 +702,14 @@ optimizer description table format. This appendix is intended for table-writers. We use syntax rules for the description of the table format. The following notation is used: -.nf - { a } zero or more of a - [ a ] zero or one of a - a b a followed by b - a | b a or b - -.fi +.TS +center; +l l. +{ a } zero or more of a +[ a ] zero or one of a +a b a followed by b +a | b a or b +.TE Terminals are given in quotes, as in ';'. .PP The table may contain white space and comment at all reasonable places. @@ -661,35 +718,40 @@ Identifiers are sequences of letters, digits and the underscore ('_'), beginning with a letter. .PP .DS +.ft 5 table -> {parameter_line} '%%;' {variable_declaration} '%%;' {entry} '%%;' user_routines. - +.ft R .DE A table consists of four sections, containing machine-dependent constants, variable declarations, pattern rules and user-supplied subroutines. .PP .DS +.ft 5 parameter_line -> identifier value ';' . - +.ft R .DE A parameter line defines some attributes of the target machines assembly code. For unspecified parameters default values apply. The names of the parameters and the corresponding defaults are shown in table 1. -.DS - OPC_TERMINATOR ' ' - OP_SEPARATOR ',' - LABEL_STARTER 'I' - LABEL_TERMINATOR ':' - MAXOP 2 - MAXOPLEN 25 - MAX_OPC_LEN 10 - MAXVARLEN 25 - MAXLINELEN 100 - - table 1: parameter names and defaults +.TS +center; +l l. +OPC_TERMINATOR ' ' +OP_SEPARATOR ',' +LABEL_STARTER 'I' +LABEL_TERMINATOR ':' +MAXOP 2 +MAXOPLEN 25 +MAX_OPC_LEN 10 +MAXVARLEN 25 +MAXLINELEN 100 +.TE +.ce 1 +table 1: parameter names and defaults .DE The OPC_TERMINATOR is the character that separates the instruction mnemonic from the first operand (if any). @@ -717,9 +779,11 @@ the line is not optimized. Optimization does, however, proceed with the rest of the input. .PP .DS +.ft 5 variable_declaration -> identifier {',' identifier} restriction ';' . restriction -> '{' anything '}' . +.ft R .DE A variable declaration declares one or more string variables that may be used in the patterns and in the replacements. @@ -739,6 +803,7 @@ Inside the expression, the name VAL stands for the part of the actual The expression may contain calls to procedures that are defined in the user-routines section. .DS +.ft 5 entry -> pattern '->' replacement ';' . pattern -> instruction_descr @@ -760,6 +825,7 @@ operand_descr -> [ string_constant ] variable_name -> identifier . opcode -> anything . +.ft R .DE The symbol 'white' stands for white space (space or tab). An opcode can be any string not containing the special @@ -783,7 +849,9 @@ which contains the mnemonic of the first instruction of the rest of the input. (REST is a null-string if this mnemonic can not be determined). .DS +.ft 5 user_routines -> anything . +.ft R .DE The remainder of the table consists of user-defined subroutines. .bp From a2516baa2feb0d54013900a451e60ad8f99cb72e Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 10 Dec 1986 15:30:42 +0000 Subject: [PATCH 0389/1625] Added EMHOME. --- util/LLgen/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/util/LLgen/Makefile b/util/LLgen/Makefile index deea77f0..9b798f92 100644 --- a/util/LLgen/Makefile +++ b/util/LLgen/Makefile @@ -1,6 +1,7 @@ # $Header$ -INSTALLDIR=../../bin -LIBDIR=../../lib/LLgen +EMHOME=../.. +INSTALLDIR=$(EMHOME)/bin +LIBDIR=$(EMHOME)/lib/LLgen all: cmp From f5cc9fcd9fac89b2c06e2628286b5e697fc2195b Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 10 Dec 1986 16:53:24 +0000 Subject: [PATCH 0390/1625] Entry for "top", different entry for "LLgen". --- doc/Makefile | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/doc/Makefile b/doc/Makefile index 764fe7d9..f8df1850 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -11,7 +11,7 @@ RESFILES= \ toolkit.$(SUF) install.$(SUF) ack.$(SUF) v7bugs.$(SUF) \ peep.$(SUF) cg.$(SUF) ncg.$(SUF) regadd.$(SUF) LLgen.$(SUF) \ basic.$(SUF) cref.$(SUF) pcref.$(SUF) val.$(SUF) \ - 6500.$(SUF) i80.$(SUF) z80.$(SUF) + 6500.$(SUF) i80.$(SUF) z80.$(SUF) top.$(SUF) cref.$(SUF): cref.doc $(TBL) $? | $(NROFF) >$@ @@ -37,14 +37,18 @@ val.$(SUF): val.doc $(NROFF) $? >$@ toolkit.$(SUF): toolkit.doc $(NROFF) $(MS) $? >$@ -LLgen.$(SUF): LLgen.doc - $(EQN) $? | $(TBL) | $(NROFF) $(MS) >$@ +LLgen.$(SUF): LLgen/Makefile LLgen/LLgen.doc LLgen/LLgen.refs + cd LLgen; make "NROFF="$(NROFF) "MS="$(MS) "EQN="$(EQN) \ + "TBL="$(TBL) "SUF="$(SUF) 6500.$(SUF): 6500.doc $(TBL) $? | $(NROFF) $(MS) >$@ i80.$(SUF): i80.doc $(NROFF) $(MS) $? >$@ z80.$(SUF): z80.doc $(NROFF) $(MS) $? >$@ +top.$(SUF): top/Makefile top/top.n top/refs.top + cd top; make "NROFF="$(NROFF) "MS="$(MS) "EQN="$(EQN) \ + "TBL="$(TBL) "SUF="$(SUF) install cmp: From 17a2481bb326dc596a09b15e7443535283407b29 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 11 Dec 1986 17:03:11 +0000 Subject: [PATCH 0391/1625] Corrected a typo. --- mach/proto/ncg/gencode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/proto/ncg/gencode.c b/mach/proto/ncg/gencode.c index f7547408..8e54e33b 100644 --- a/mach/proto/ncg/gencode.c +++ b/mach/proto/ncg/gencode.c @@ -90,7 +90,7 @@ string ad2str(ad) addr_t ad; { else return(mystrcpy(ad.ea_str)); } - sprintf(buf,"%s%c%ld",ad.ea_str,ad.ea_off>=0 ? '+' : ' ',(long)ad.ea_off); + sprintf(buf,"%s%c%ld",ad.ea_str,ad.ea_off>=0 ? '+' : '-',(long)ad.ea_off); return(mystrcpy(buf)); } From 4e92b0777c3ad32ca27c156d39eeb73e794efd03 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 11 Dec 1986 17:04:40 +0000 Subject: [PATCH 0392/1625] Improved testing for 0-strings in the routine "mycat". --- mach/proto/ncg/compute.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mach/proto/ncg/compute.c b/mach/proto/ncg/compute.c index c86e073d..d023fd89 100644 --- a/mach/proto/ncg/compute.c +++ b/mach/proto/ncg/compute.c @@ -86,8 +86,8 @@ string salloc(),strcpy(),strcat(); string mycat(s1,s2) register string s1,s2; { register string s; - if (s1==0) return(s2); - if (s2==0) return(s1); + if (s1==0 || *s1=='\0') return(s2); + if (s2==0 || *s2=='\0') return(s1); s=salloc(strlen(s1)+strlen(s2)+1); strcpy(s,s1); strcat(s,"+"); From 3536ae71703bc26fec41d73a6fd19a9f38aeda5d Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 12 Dec 1986 12:49:50 +0000 Subject: [PATCH 0393/1625] Initial revision --- mach/vax4/libbsd4_1a/LIST | 60 +++++++++++++++++++++++++++ mach/vax4/libbsd4_1a/Makefile | 30 ++++++++++++++ mach/vax4/libbsd4_1a/_exit.s | 8 ++++ mach/vax4/libbsd4_1a/access.s | 11 +++++ mach/vax4/libbsd4_1a/acct.s | 11 +++++ mach/vax4/libbsd4_1a/alarm.s | 8 ++++ mach/vax4/libbsd4_1a/chdir.s | 12 ++++++ mach/vax4/libbsd4_1a/chmod.s | 12 ++++++ mach/vax4/libbsd4_1a/chown.s | 12 ++++++ mach/vax4/libbsd4_1a/close.s | 12 ++++++ mach/vax4/libbsd4_1a/creat.s | 11 +++++ mach/vax4/libbsd4_1a/dup.s | 19 +++++++++ mach/vax4/libbsd4_1a/errmon.s | 8 ++++ mach/vax4/libbsd4_1a/execl.s | 11 +++++ mach/vax4/libbsd4_1a/execle.s | 11 +++++ mach/vax4/libbsd4_1a/execv.s | 11 +++++ mach/vax4/libbsd4_1a/execve.s | 8 ++++ mach/vax4/libbsd4_1a/fork.s | 14 +++++++ mach/vax4/libbsd4_1a/fstat.s | 12 ++++++ mach/vax4/libbsd4_1a/ftime.s | 8 ++++ mach/vax4/libbsd4_1a/getgid.s | 15 +++++++ mach/vax4/libbsd4_1a/getpid.s | 15 +++++++ mach/vax4/libbsd4_1a/getuid.s | 15 +++++++ mach/vax4/libbsd4_1a/head_em.s | 76 ++++++++++++++++++++++++++++++++++ mach/vax4/libbsd4_1a/ioctl.s | 11 +++++ mach/vax4/libbsd4_1a/kill.s | 12 ++++++ mach/vax4/libbsd4_1a/link.s | 12 ++++++ mach/vax4/libbsd4_1a/lseek.s | 11 +++++ mach/vax4/libbsd4_1a/mknod.s | 12 ++++++ mach/vax4/libbsd4_1a/mount.s | 12 ++++++ mach/vax4/libbsd4_1a/mpx.s | 11 +++++ mach/vax4/libbsd4_1a/nice.s | 12 ++++++ mach/vax4/libbsd4_1a/open.s | 11 +++++ mach/vax4/libbsd4_1a/pause.s | 8 ++++ mach/vax4/libbsd4_1a/pipe.s | 15 +++++++ mach/vax4/libbsd4_1a/profil.s | 8 ++++ mach/vax4/libbsd4_1a/ptrace.s | 12 ++++++ mach/vax4/libbsd4_1a/read.s | 11 +++++ mach/vax4/libbsd4_1a/sbrk.s | 32 ++++++++++++++ mach/vax4/libbsd4_1a/setgid.s | 12 ++++++ mach/vax4/libbsd4_1a/setuid.s | 12 ++++++ mach/vax4/libbsd4_1a/signal.s | 11 +++++ mach/vax4/libbsd4_1a/stat.s | 12 ++++++ mach/vax4/libbsd4_1a/stime.s | 13 ++++++ mach/vax4/libbsd4_1a/sync.s | 8 ++++ mach/vax4/libbsd4_1a/syscall.s | 12 ++++++ mach/vax4/libbsd4_1a/time.s | 12 ++++++ mach/vax4/libbsd4_1a/times.s | 8 ++++ mach/vax4/libbsd4_1a/umask.s | 11 +++++ mach/vax4/libbsd4_1a/umount.s | 12 ++++++ mach/vax4/libbsd4_1a/unlink.s | 12 ++++++ mach/vax4/libbsd4_1a/utime.s | 11 +++++ mach/vax4/libbsd4_1a/vadvise.s | 12 ++++++ mach/vax4/libbsd4_1a/vfork.s | 22 ++++++++++ mach/vax4/libbsd4_1a/vhangup.s | 8 ++++ mach/vax4/libbsd4_1a/vlimit.s | 11 +++++ mach/vax4/libbsd4_1a/vread.s | 11 +++++ mach/vax4/libbsd4_1a/vtimes.s | 8 ++++ mach/vax4/libbsd4_1a/vwait.s | 15 +++++++ mach/vax4/libbsd4_1a/vwrite.s | 11 +++++ mach/vax4/libbsd4_1a/wait.s | 15 +++++++ mach/vax4/libbsd4_1a/write.s | 11 +++++ 62 files changed, 870 insertions(+) create mode 100644 mach/vax4/libbsd4_1a/LIST create mode 100644 mach/vax4/libbsd4_1a/Makefile create mode 100644 mach/vax4/libbsd4_1a/_exit.s create mode 100644 mach/vax4/libbsd4_1a/access.s create mode 100644 mach/vax4/libbsd4_1a/acct.s create mode 100644 mach/vax4/libbsd4_1a/alarm.s create mode 100644 mach/vax4/libbsd4_1a/chdir.s create mode 100644 mach/vax4/libbsd4_1a/chmod.s create mode 100644 mach/vax4/libbsd4_1a/chown.s create mode 100644 mach/vax4/libbsd4_1a/close.s create mode 100644 mach/vax4/libbsd4_1a/creat.s create mode 100644 mach/vax4/libbsd4_1a/dup.s create mode 100644 mach/vax4/libbsd4_1a/errmon.s create mode 100644 mach/vax4/libbsd4_1a/execl.s create mode 100644 mach/vax4/libbsd4_1a/execle.s create mode 100644 mach/vax4/libbsd4_1a/execv.s create mode 100644 mach/vax4/libbsd4_1a/execve.s create mode 100644 mach/vax4/libbsd4_1a/fork.s create mode 100644 mach/vax4/libbsd4_1a/fstat.s create mode 100644 mach/vax4/libbsd4_1a/ftime.s create mode 100644 mach/vax4/libbsd4_1a/getgid.s create mode 100644 mach/vax4/libbsd4_1a/getpid.s create mode 100644 mach/vax4/libbsd4_1a/getuid.s create mode 100644 mach/vax4/libbsd4_1a/head_em.s create mode 100644 mach/vax4/libbsd4_1a/ioctl.s create mode 100644 mach/vax4/libbsd4_1a/kill.s create mode 100644 mach/vax4/libbsd4_1a/link.s create mode 100644 mach/vax4/libbsd4_1a/lseek.s create mode 100644 mach/vax4/libbsd4_1a/mknod.s create mode 100644 mach/vax4/libbsd4_1a/mount.s create mode 100644 mach/vax4/libbsd4_1a/mpx.s create mode 100644 mach/vax4/libbsd4_1a/nice.s create mode 100644 mach/vax4/libbsd4_1a/open.s create mode 100644 mach/vax4/libbsd4_1a/pause.s create mode 100644 mach/vax4/libbsd4_1a/pipe.s create mode 100644 mach/vax4/libbsd4_1a/profil.s create mode 100644 mach/vax4/libbsd4_1a/ptrace.s create mode 100644 mach/vax4/libbsd4_1a/read.s create mode 100644 mach/vax4/libbsd4_1a/sbrk.s create mode 100644 mach/vax4/libbsd4_1a/setgid.s create mode 100644 mach/vax4/libbsd4_1a/setuid.s create mode 100644 mach/vax4/libbsd4_1a/signal.s create mode 100644 mach/vax4/libbsd4_1a/stat.s create mode 100644 mach/vax4/libbsd4_1a/stime.s create mode 100644 mach/vax4/libbsd4_1a/sync.s create mode 100644 mach/vax4/libbsd4_1a/syscall.s create mode 100644 mach/vax4/libbsd4_1a/time.s create mode 100644 mach/vax4/libbsd4_1a/times.s create mode 100644 mach/vax4/libbsd4_1a/umask.s create mode 100644 mach/vax4/libbsd4_1a/umount.s create mode 100644 mach/vax4/libbsd4_1a/unlink.s create mode 100644 mach/vax4/libbsd4_1a/utime.s create mode 100644 mach/vax4/libbsd4_1a/vadvise.s create mode 100644 mach/vax4/libbsd4_1a/vfork.s create mode 100644 mach/vax4/libbsd4_1a/vhangup.s create mode 100644 mach/vax4/libbsd4_1a/vlimit.s create mode 100644 mach/vax4/libbsd4_1a/vread.s create mode 100644 mach/vax4/libbsd4_1a/vtimes.s create mode 100644 mach/vax4/libbsd4_1a/vwait.s create mode 100644 mach/vax4/libbsd4_1a/vwrite.s create mode 100644 mach/vax4/libbsd4_1a/wait.s create mode 100644 mach/vax4/libbsd4_1a/write.s diff --git a/mach/vax4/libbsd4_1a/LIST b/mach/vax4/libbsd4_1a/LIST new file mode 100644 index 00000000..31b368e7 --- /dev/null +++ b/mach/vax4/libbsd4_1a/LIST @@ -0,0 +1,60 @@ +tail_mon.a +_exit.s +access.s +acct.s +alarm.s +chdir.s +chmod.s +chown.s +close.s +creat.s +dup.s +errmon.s +execl.s +execle.s +execv.s +execve.s +fork.s +fstat.s +ftime.s +getgid.s +getpid.s +getuid.s +ioctl.s +kill.s +link.s +lseek.s +mknod.s +mount.s +mpx.s +nice.s +open.s +pause.s +pipe.s +profil.s +ptrace.s +read.s +sbrk.s +setgid.s +setuid.s +signal.s +stat.s +stime.s +sync.s +syscall.s +time.s +times.s +umask.s +umount.s +unlink.s +utime.s +vadvise.s +vfork.s +vhangup.s +vlimit.s +vread.s +vtimes.s +vwait.s +vwrite.s +wait.s +write.s diff --git a/mach/vax4/libbsd4_1a/Makefile b/mach/vax4/libbsd4_1a/Makefile new file mode 100644 index 00000000..92b9aaf6 --- /dev/null +++ b/mach/vax4/libbsd4_1a/Makefile @@ -0,0 +1,30 @@ +# $Header$ +install: cp + +cp: all + ../../install head_em + ../../install tail_mon + rm -f head_em tail_mon + +cmp: all + -../../compare head_em + -../../compare tail_mon + rm -f head_em tail_mon + +all: head_em tail_mon + +head_em: head_em.s + vax4 -I../../../h -c head_em.s ; mv head_em.o head_em + +tail_mon: + ASAR=ar ; export ASAR ;\ + RANLIB=ranlib ; export RANLIB ;\ + march . tail_mon + +clean: + rm -f *.o +opr: + make pr | opr +pr: + @pr `pwd`/Makefile `pwd`/head_em.s + @pr -l33 `tail +1 LIST|sort` diff --git a/mach/vax4/libbsd4_1a/_exit.s b/mach/vax4/libbsd4_1a/_exit.s new file mode 100644 index 00000000..04e8e241 --- /dev/null +++ b/mach/vax4/libbsd4_1a/_exit.s @@ -0,0 +1,8 @@ +.globl __exit +.set exit,1 + +.align 1 +__exit: + .word 0x0000 + chmk $exit + halt diff --git a/mach/vax4/libbsd4_1a/access.s b/mach/vax4/libbsd4_1a/access.s new file mode 100644 index 00000000..0c1baffd --- /dev/null +++ b/mach/vax4/libbsd4_1a/access.s @@ -0,0 +1,11 @@ +.globl _access +.set access,33 + +.align 1 +_access: + .word 0x0000 + chmk $access + bcc 1f + jmp errmon +1: + ret diff --git a/mach/vax4/libbsd4_1a/acct.s b/mach/vax4/libbsd4_1a/acct.s new file mode 100644 index 00000000..f201d79f --- /dev/null +++ b/mach/vax4/libbsd4_1a/acct.s @@ -0,0 +1,11 @@ +.globl _acct +.set acct,51 + +.align 1 +_acct: + .word 0x0000 + chmk $acct + bcc 1f + jmp errmon +1: + ret diff --git a/mach/vax4/libbsd4_1a/alarm.s b/mach/vax4/libbsd4_1a/alarm.s new file mode 100644 index 00000000..b7079b5c --- /dev/null +++ b/mach/vax4/libbsd4_1a/alarm.s @@ -0,0 +1,8 @@ +.globl _alarm +.set alarm,27 + +.align 1 +_alarm: + .word 0x0000 + chmk $alarm + ret diff --git a/mach/vax4/libbsd4_1a/chdir.s b/mach/vax4/libbsd4_1a/chdir.s new file mode 100644 index 00000000..7bf11fd1 --- /dev/null +++ b/mach/vax4/libbsd4_1a/chdir.s @@ -0,0 +1,12 @@ +.globl _chdir +.set chdir,12 + +.align 1 +_chdir: + .word 0x0000 + chmk $chdir + bcc 1f + jmp errmon +1: + clrl r0 + ret diff --git a/mach/vax4/libbsd4_1a/chmod.s b/mach/vax4/libbsd4_1a/chmod.s new file mode 100644 index 00000000..9af97c3c --- /dev/null +++ b/mach/vax4/libbsd4_1a/chmod.s @@ -0,0 +1,12 @@ +.globl _chmod +.set chmod,15 + +.align 1 +_chmod: + .word 0x0000 + chmk $chmod + bcc 1f + jmp errmon +1: + clrl r0 + ret diff --git a/mach/vax4/libbsd4_1a/chown.s b/mach/vax4/libbsd4_1a/chown.s new file mode 100644 index 00000000..aa276df7 --- /dev/null +++ b/mach/vax4/libbsd4_1a/chown.s @@ -0,0 +1,12 @@ +.globl _chown +.set chown,16 + +.align 1 +_chown: + .word 0x0000 + chmk $chown + bcc 1f + jmp errmon +1: + clrl r0 + ret diff --git a/mach/vax4/libbsd4_1a/close.s b/mach/vax4/libbsd4_1a/close.s new file mode 100644 index 00000000..743c9b06 --- /dev/null +++ b/mach/vax4/libbsd4_1a/close.s @@ -0,0 +1,12 @@ +.globl _close +.set close,6 + +.align 1 +_close: + .word 0x0000 + chmk $close + bcc 1f + jmp errmon +1: + clrl r0 + ret diff --git a/mach/vax4/libbsd4_1a/creat.s b/mach/vax4/libbsd4_1a/creat.s new file mode 100644 index 00000000..bee4615a --- /dev/null +++ b/mach/vax4/libbsd4_1a/creat.s @@ -0,0 +1,11 @@ +.globl _creat +.set creat,8 + +.align 1 +_creat: + .word 0x0000 + chmk $creat + bcc 1f + jmp errmon +1: + ret diff --git a/mach/vax4/libbsd4_1a/dup.s b/mach/vax4/libbsd4_1a/dup.s new file mode 100644 index 00000000..c82e2a7b --- /dev/null +++ b/mach/vax4/libbsd4_1a/dup.s @@ -0,0 +1,19 @@ +.globl _dup +.globl _dup2 +.set dup,41 + +.align 1 +_dup: + .word 0x0000 + brb 1f + +.align 1 +_dup2: + .word 0x0000 + bisb2 $0100,4(ap) +1: + chmk $dup + bcc 1f + jmp errmon +1: + ret diff --git a/mach/vax4/libbsd4_1a/errmon.s b/mach/vax4/libbsd4_1a/errmon.s new file mode 100644 index 00000000..dee150d6 --- /dev/null +++ b/mach/vax4/libbsd4_1a/errmon.s @@ -0,0 +1,8 @@ +.globl errmon +.comm _errno,4 + +.align 1 +errmon: + movl r0,_errno + mnegl $1,r0 + ret diff --git a/mach/vax4/libbsd4_1a/execl.s b/mach/vax4/libbsd4_1a/execl.s new file mode 100644 index 00000000..e4016d9c --- /dev/null +++ b/mach/vax4/libbsd4_1a/execl.s @@ -0,0 +1,11 @@ +.globl _execl +.globl _environ + +.align 1 +_execl: + .word 0x0000 + pushl _environ + pushab 8(ap) + pushl 4(ap) + calls $3,_execve + ret diff --git a/mach/vax4/libbsd4_1a/execle.s b/mach/vax4/libbsd4_1a/execle.s new file mode 100644 index 00000000..f206e6ac --- /dev/null +++ b/mach/vax4/libbsd4_1a/execle.s @@ -0,0 +1,11 @@ +.globl _execle + +.align 1 +_execle: + .word 0x0000 + movl (ap),r0 + pushl (ap)[r0] + pushab 8(ap) + pushl 4(ap) + calls $3,_execve + ret diff --git a/mach/vax4/libbsd4_1a/execv.s b/mach/vax4/libbsd4_1a/execv.s new file mode 100644 index 00000000..2df3ad1c --- /dev/null +++ b/mach/vax4/libbsd4_1a/execv.s @@ -0,0 +1,11 @@ +.globl _execv +.globl _environ + +.align 1 +_execv: + .word 0x0000 + pushl _environ + pushl 8(ap) + pushl 4(ap) + calls $3,_execve + ret diff --git a/mach/vax4/libbsd4_1a/execve.s b/mach/vax4/libbsd4_1a/execve.s new file mode 100644 index 00000000..a51c2a1b --- /dev/null +++ b/mach/vax4/libbsd4_1a/execve.s @@ -0,0 +1,8 @@ +.globl _execve +.set exec,59 + +.align 1 +_execve: + .word 0x0000 + chmk $exec + jmp errmon diff --git a/mach/vax4/libbsd4_1a/fork.s b/mach/vax4/libbsd4_1a/fork.s new file mode 100644 index 00000000..8ad3e937 --- /dev/null +++ b/mach/vax4/libbsd4_1a/fork.s @@ -0,0 +1,14 @@ +.globl _fork +.set fork,2 + +.align 1 +_fork: + .word 0x0000 + chmk $fork + bcc 1f + jmp errmon +1: + jlbc r1,1f + clrl r0 +1: + ret diff --git a/mach/vax4/libbsd4_1a/fstat.s b/mach/vax4/libbsd4_1a/fstat.s new file mode 100644 index 00000000..b9fef791 --- /dev/null +++ b/mach/vax4/libbsd4_1a/fstat.s @@ -0,0 +1,12 @@ +.globl _fstat +.set fstat,28 + +.align 1 +_fstat: + .word 0x0000 + chmk $fstat + bcc 1f + jmp errmon +1: + clrl r0 + ret diff --git a/mach/vax4/libbsd4_1a/ftime.s b/mach/vax4/libbsd4_1a/ftime.s new file mode 100644 index 00000000..ecf05601 --- /dev/null +++ b/mach/vax4/libbsd4_1a/ftime.s @@ -0,0 +1,8 @@ +.globl _ftime +.set ftime,35 + +.align 1 +_ftime: + .word 0x0000 + chmk $ftime + ret diff --git a/mach/vax4/libbsd4_1a/getgid.s b/mach/vax4/libbsd4_1a/getgid.s new file mode 100644 index 00000000..9ae921ad --- /dev/null +++ b/mach/vax4/libbsd4_1a/getgid.s @@ -0,0 +1,15 @@ +.globl _getgid, _getegid +.set getgid,47 + +.align 1 +_getgid: + .word 0x0000 + chmk $getgid + ret + +.align 1 +_getegid: + .word 0x0000 + chmk $getgid + movl r1,r0 + ret diff --git a/mach/vax4/libbsd4_1a/getpid.s b/mach/vax4/libbsd4_1a/getpid.s new file mode 100644 index 00000000..06ab9dbb --- /dev/null +++ b/mach/vax4/libbsd4_1a/getpid.s @@ -0,0 +1,15 @@ +.globl _getpid, _getppid +.set getpid,20 + +.align 1 +_getpid: + .word 0x0000 + chmk $getpid + ret + +.align 1 +_getppid: + .word 0x0000 + chmk $getpid + movl r1,r0 + ret diff --git a/mach/vax4/libbsd4_1a/getuid.s b/mach/vax4/libbsd4_1a/getuid.s new file mode 100644 index 00000000..2d1a13e2 --- /dev/null +++ b/mach/vax4/libbsd4_1a/getuid.s @@ -0,0 +1,15 @@ +.globl _getuid, _geteuid +.set getuid,24 + +.align 1 +_getuid: + .word 0x0000 + chmk $getuid + ret + +.align 1 +_geteuid: + .word 0x0000 + chmk $getuid + movl r1,r0 + ret diff --git a/mach/vax4/libbsd4_1a/head_em.s b/mach/vax4/libbsd4_1a/head_em.s new file mode 100644 index 00000000..2608535e --- /dev/null +++ b/mach/vax4/libbsd4_1a/head_em.s @@ -0,0 +1,76 @@ +#include "em_abs.h" + + # $Header$ + +.globl hol0 +.globl .reghp +.globl .trppc +.globl .trpim + + # run time startoff + .word 0 + bispsw $0100 # set FU(0100) + movl 4(sp),r0 + clrl -4(r0) + movl sp,r0 + movl (r0)+,r1 + movl r0,r2 +a1: + tstl (r0)+ + bneq a1 + cmpl r0,(r2) + blssu a2 + tstl -(r0) +a2: + pushl r0 + pushl r2 + pushl r1 + movl $m1,ap + chmk (ap)+ # catch floating point exception + calls $3,_m_a_i_n + movl $m2,ap + movl r0,6(ap) + chmk (ap)+ + halt + + .align 1 +sig8: + .word 0x0000 + pushl 8(ap) + movl (sp)+,ap + pushl tab [ap] + jsb .trp + movl $m1,ap + chmk (ap)+ + ret + + .data +m1: + .word 48 + .long 2 + .long 8 + .long sig8 +m2: + .word 1 + .long 1 + .long 0 +.reghp: + .long _end +hol0: + .space 8 +.trppc: + .space 4 +.trpim: + .long 0 +tab: + .long 0 + .long EIOVFL + .long EIDIVZ + .long EFOVFL + .long EFDIVZ + .long EFUNFL + .long EILLINS + .long EARRAY + .long EFOVFL + .long EFDIVZ + .long EFUNFL diff --git a/mach/vax4/libbsd4_1a/ioctl.s b/mach/vax4/libbsd4_1a/ioctl.s new file mode 100644 index 00000000..e3e0d88d --- /dev/null +++ b/mach/vax4/libbsd4_1a/ioctl.s @@ -0,0 +1,11 @@ +.globl _ioctl +.set ioctl,54 + +.align 1 +_ioctl: + .word 0x0000 + chmk $ioctl + bcc 1f + jmp errmon +1: + ret diff --git a/mach/vax4/libbsd4_1a/kill.s b/mach/vax4/libbsd4_1a/kill.s new file mode 100644 index 00000000..7a41a0fe --- /dev/null +++ b/mach/vax4/libbsd4_1a/kill.s @@ -0,0 +1,12 @@ +.globl _kill +.set kill,37 + +.align 1 +_kill: + .word 0x0000 + chmk $kill + bcc 1f + jmp errmon +1: + clrl r0 + ret diff --git a/mach/vax4/libbsd4_1a/link.s b/mach/vax4/libbsd4_1a/link.s new file mode 100644 index 00000000..2c6c35fb --- /dev/null +++ b/mach/vax4/libbsd4_1a/link.s @@ -0,0 +1,12 @@ +.globl _link +.set link,9 + +.align 1 +_link: + .word 0x0000 + chmk $link + bcc 1f + jmp errmon +1: + clrl r0 + ret diff --git a/mach/vax4/libbsd4_1a/lseek.s b/mach/vax4/libbsd4_1a/lseek.s new file mode 100644 index 00000000..2cae1d28 --- /dev/null +++ b/mach/vax4/libbsd4_1a/lseek.s @@ -0,0 +1,11 @@ +.globl _lseek +.set lseek,19 + +.align 1 +_lseek: + .word 0x0000 + chmk $lseek + bcc 1f + jmp errmon +1: + ret diff --git a/mach/vax4/libbsd4_1a/mknod.s b/mach/vax4/libbsd4_1a/mknod.s new file mode 100644 index 00000000..5cbb729b --- /dev/null +++ b/mach/vax4/libbsd4_1a/mknod.s @@ -0,0 +1,12 @@ +.globl _mknod +.set mknod,14 + +.align 1 +_mknod: + .word 0x0000 + chmk $mknod + bcc 1f + jmp errmod +1: + clrl r0 + ret diff --git a/mach/vax4/libbsd4_1a/mount.s b/mach/vax4/libbsd4_1a/mount.s new file mode 100644 index 00000000..c803979b --- /dev/null +++ b/mach/vax4/libbsd4_1a/mount.s @@ -0,0 +1,12 @@ +.globl _mount +.set mount,21 + +.align 1 +_mount: + .word 0x0000 + chmk $mount + bcc 1f + jmp errmon +1: + clrl r0 + ret diff --git a/mach/vax4/libbsd4_1a/mpx.s b/mach/vax4/libbsd4_1a/mpx.s new file mode 100644 index 00000000..983d1f94 --- /dev/null +++ b/mach/vax4/libbsd4_1a/mpx.s @@ -0,0 +1,11 @@ +.set mpxcall,56 +.globl _mpxcall + +.align 1 +_mpxcall: + .word 0x0000 + chmk $mpxcall + bcc 1f + jmp errmon +1: + ret diff --git a/mach/vax4/libbsd4_1a/nice.s b/mach/vax4/libbsd4_1a/nice.s new file mode 100644 index 00000000..73c3c297 --- /dev/null +++ b/mach/vax4/libbsd4_1a/nice.s @@ -0,0 +1,12 @@ +.globl _nice +.set nice,34 + +.align 1 +_nice: + .word 0x0000 + chmk $nice + bcc 1f + jmp errmon +1: + clrl r0 + ret diff --git a/mach/vax4/libbsd4_1a/open.s b/mach/vax4/libbsd4_1a/open.s new file mode 100644 index 00000000..a7cdf30f --- /dev/null +++ b/mach/vax4/libbsd4_1a/open.s @@ -0,0 +1,11 @@ +.globl _open +.set open,5 + +.align 1 +_open: + .word 0x0000 + chmk $open + bcc 1f + jmp errmon +1: + ret diff --git a/mach/vax4/libbsd4_1a/pause.s b/mach/vax4/libbsd4_1a/pause.s new file mode 100644 index 00000000..be98a1e2 --- /dev/null +++ b/mach/vax4/libbsd4_1a/pause.s @@ -0,0 +1,8 @@ +.globl _pause +.set pause,29 + +.align 1 +_pause: + .word 0x0000 + chmk $pause + ret diff --git a/mach/vax4/libbsd4_1a/pipe.s b/mach/vax4/libbsd4_1a/pipe.s new file mode 100644 index 00000000..bcbf1b96 --- /dev/null +++ b/mach/vax4/libbsd4_1a/pipe.s @@ -0,0 +1,15 @@ +.globl _pipe +.set pipe,42 + +.align 1 +_pipe: + .word 0x0000 + chmk $pipe + bcc 1f + jmp errmon +1: + movl 4(ap),r2 + movl r0,(r2)+ + movl r1,(r2) + clrl r0 + ret diff --git a/mach/vax4/libbsd4_1a/profil.s b/mach/vax4/libbsd4_1a/profil.s new file mode 100644 index 00000000..c56b4d39 --- /dev/null +++ b/mach/vax4/libbsd4_1a/profil.s @@ -0,0 +1,8 @@ +.globl _profil +.set profil,44 + +.align 1 +_profil: + .word 0x0000 + chmk $profil + ret diff --git a/mach/vax4/libbsd4_1a/ptrace.s b/mach/vax4/libbsd4_1a/ptrace.s new file mode 100644 index 00000000..e60c1200 --- /dev/null +++ b/mach/vax4/libbsd4_1a/ptrace.s @@ -0,0 +1,12 @@ +.globl _ptrace +.set ptrace,26 + +.align 1 +_ptrace: + .word 0x0000 + clrl _errno + chmk $ptrace + bcc 1f + jmp errmon +1: + ret diff --git a/mach/vax4/libbsd4_1a/read.s b/mach/vax4/libbsd4_1a/read.s new file mode 100644 index 00000000..c6ff6e38 --- /dev/null +++ b/mach/vax4/libbsd4_1a/read.s @@ -0,0 +1,11 @@ +.globl _read +.set read,3 + +.align 1 +_read: + .word 0x0000 + chmk $read + bcc 1f + jmp errmon +1: + ret diff --git a/mach/vax4/libbsd4_1a/sbrk.s b/mach/vax4/libbsd4_1a/sbrk.s new file mode 100644 index 00000000..605a2aa3 --- /dev/null +++ b/mach/vax4/libbsd4_1a/sbrk.s @@ -0,0 +1,32 @@ +.set break,17 +.globl _sbrk, _brk +.globl _end + +.align 1 +_sbrk: + .word 0x0000 + addl3 brk,4(ap),-(sp) + bcc 1f + movl $0xFFFFFFFF,(sp) # will cause an error (I hope) +1: + movl brk,r3 + calls $1,_brk + tstl r0 + blss 1f + movl r3,r0 +1: + ret + +.align 1 +_brk: + .word 0x0000 + chmk $break + bcc 1f + jmp errmon +1: + movl 4(ap),brk + clrl r0 + ret + +.data +brk: .long _end diff --git a/mach/vax4/libbsd4_1a/setgid.s b/mach/vax4/libbsd4_1a/setgid.s new file mode 100644 index 00000000..86ced036 --- /dev/null +++ b/mach/vax4/libbsd4_1a/setgid.s @@ -0,0 +1,12 @@ +.globl _setgid +.set setgid,46 + +.align 1 +_setgid: + .word 0x0000 + chmk $setgid + bcc 1f + jmp errmon +1: + clrl r0 + ret diff --git a/mach/vax4/libbsd4_1a/setuid.s b/mach/vax4/libbsd4_1a/setuid.s new file mode 100644 index 00000000..8f3fe388 --- /dev/null +++ b/mach/vax4/libbsd4_1a/setuid.s @@ -0,0 +1,12 @@ +.globl _setuid +.set setuid,23 + +.align 1 +_setuid: + .word 0x0000 + chmk $setuid + bcc 1f + jmp errmon +1: + clrl r0 + ret diff --git a/mach/vax4/libbsd4_1a/signal.s b/mach/vax4/libbsd4_1a/signal.s new file mode 100644 index 00000000..d416bffe --- /dev/null +++ b/mach/vax4/libbsd4_1a/signal.s @@ -0,0 +1,11 @@ +.globl _signal +.set signal,48 + +.align 1 +_signal: + .word 0x0000 + chmk $signal + bcc 1f + jmp errmon +1: + ret diff --git a/mach/vax4/libbsd4_1a/stat.s b/mach/vax4/libbsd4_1a/stat.s new file mode 100644 index 00000000..e57a4ee3 --- /dev/null +++ b/mach/vax4/libbsd4_1a/stat.s @@ -0,0 +1,12 @@ +.globl _stat +.set stat,18 + +.align 1 +_stat: + .word 0x0000 + chmk $stat + bcc 1f + jmp errmon +1: + clrl r0 + ret diff --git a/mach/vax4/libbsd4_1a/stime.s b/mach/vax4/libbsd4_1a/stime.s new file mode 100644 index 00000000..c8bcc2c3 --- /dev/null +++ b/mach/vax4/libbsd4_1a/stime.s @@ -0,0 +1,13 @@ +.globl _stime +.set stime,25 + +.align 1 +_stime: + .word 0x0000 + movl *4(ap),4(ap) + chmk $stime + bcc 1f + jmp errmon +1: + clrl r0 + ret diff --git a/mach/vax4/libbsd4_1a/sync.s b/mach/vax4/libbsd4_1a/sync.s new file mode 100644 index 00000000..cdeaecd8 --- /dev/null +++ b/mach/vax4/libbsd4_1a/sync.s @@ -0,0 +1,8 @@ +.globl _sync +.set sync,36 + +.align 1 +_sync: + .word 0x0000 + chmk $sync + ret diff --git a/mach/vax4/libbsd4_1a/syscall.s b/mach/vax4/libbsd4_1a/syscall.s new file mode 100644 index 00000000..f0dbbc8e --- /dev/null +++ b/mach/vax4/libbsd4_1a/syscall.s @@ -0,0 +1,12 @@ +.globl _syscall + +.align 1 +_syscall: + .word 0x0000 + movl 4(ap),r0 + subl3 $1,(ap)+,(ap) + chmk r0 + bcc 1f + jmp errmon +1: + ret diff --git a/mach/vax4/libbsd4_1a/time.s b/mach/vax4/libbsd4_1a/time.s new file mode 100644 index 00000000..91219033 --- /dev/null +++ b/mach/vax4/libbsd4_1a/time.s @@ -0,0 +1,12 @@ +.globl _time +.set time,13 + +.align 1 +_time: + .word 0x0000 + chmk $time + movl 4(ap),r1 + beql 1f + movl r0,(r1) +1: + ret diff --git a/mach/vax4/libbsd4_1a/times.s b/mach/vax4/libbsd4_1a/times.s new file mode 100644 index 00000000..160117fb --- /dev/null +++ b/mach/vax4/libbsd4_1a/times.s @@ -0,0 +1,8 @@ +.globl _times +.set times,43 + +.align 1 +_times: + .word 0x0000 + chmk $times + ret diff --git a/mach/vax4/libbsd4_1a/umask.s b/mach/vax4/libbsd4_1a/umask.s new file mode 100644 index 00000000..8f76038d --- /dev/null +++ b/mach/vax4/libbsd4_1a/umask.s @@ -0,0 +1,11 @@ +.globl _umask +.set umask,60 + +.align 1 +_umask: + .word 0x0000 + chmk $umask + bcc 1f + jmp errmon +1: + ret diff --git a/mach/vax4/libbsd4_1a/umount.s b/mach/vax4/libbsd4_1a/umount.s new file mode 100644 index 00000000..15667c0e --- /dev/null +++ b/mach/vax4/libbsd4_1a/umount.s @@ -0,0 +1,12 @@ +.globl _umount +.set umount,22 + +.align 1 +_umount: + .word 0x0000 + chmk $umount + bcc 1f + jmp errmon +1: + clrl r0 + ret diff --git a/mach/vax4/libbsd4_1a/unlink.s b/mach/vax4/libbsd4_1a/unlink.s new file mode 100644 index 00000000..6b59e4b5 --- /dev/null +++ b/mach/vax4/libbsd4_1a/unlink.s @@ -0,0 +1,12 @@ +.globl _unlink +.set unlink,10 + +.align 1 +_unlink: + .word 0x0000 + chmk $unlink + bcc 1f + jmp errmon +1: + clrl r0 + ret diff --git a/mach/vax4/libbsd4_1a/utime.s b/mach/vax4/libbsd4_1a/utime.s new file mode 100644 index 00000000..f8d9b428 --- /dev/null +++ b/mach/vax4/libbsd4_1a/utime.s @@ -0,0 +1,11 @@ +.globl _utime +.set utime,30 + +.align 1 +_utime: + .word 0x0000 + chmk $utime + bcc 1f + jmp errmon +1: + ret diff --git a/mach/vax4/libbsd4_1a/vadvise.s b/mach/vax4/libbsd4_1a/vadvise.s new file mode 100644 index 00000000..3175f993 --- /dev/null +++ b/mach/vax4/libbsd4_1a/vadvise.s @@ -0,0 +1,12 @@ +.set vadvise,72 +.globl _vadvise + +.align 1 +_vadvise: + .word 0x0000 + chmk $vadvise + bcc 1f + jmp errmon +1: + clrl r0 + ret diff --git a/mach/vax4/libbsd4_1a/vfork.s b/mach/vax4/libbsd4_1a/vfork.s new file mode 100644 index 00000000..5b59cdfe --- /dev/null +++ b/mach/vax4/libbsd4_1a/vfork.s @@ -0,0 +1,22 @@ +.globl _vfork +.set vfork,66 + +.align 1 +_vfork: + .word 0x0000 + movl 16(fp),r2 + movab 1f,16(fp) # dirty. Only one process can do return, + # so do it before forking + ret +1: + chmk $vfork + bcs 3f + tstl r1 + bneq 1f + clrl r0 +1: + jmp (r2) +3: + movl r0,_errno + mnegl $1,r0 + jmp (r2) diff --git a/mach/vax4/libbsd4_1a/vhangup.s b/mach/vax4/libbsd4_1a/vhangup.s new file mode 100644 index 00000000..8c674d4a --- /dev/null +++ b/mach/vax4/libbsd4_1a/vhangup.s @@ -0,0 +1,8 @@ +.globl _vhangup +.set vhangup,76 + +.align 1 +_vhangup: + .word 0x0000 + chmk $vhangup + ret diff --git a/mach/vax4/libbsd4_1a/vlimit.s b/mach/vax4/libbsd4_1a/vlimit.s new file mode 100644 index 00000000..8ce31948 --- /dev/null +++ b/mach/vax4/libbsd4_1a/vlimit.s @@ -0,0 +1,11 @@ +.globl _vlimit +.set vlimit,77 + +.align 1 +_vlimit: + .word 0x0000 + chmk $vlimit + bcc 1f + jmp errmon +1: + ret diff --git a/mach/vax4/libbsd4_1a/vread.s b/mach/vax4/libbsd4_1a/vread.s new file mode 100644 index 00000000..622d3a88 --- /dev/null +++ b/mach/vax4/libbsd4_1a/vread.s @@ -0,0 +1,11 @@ +.globl _vread +.set vread,67 + +.align 1 +_vread: + .word 0x0000 + chmk $vread + bcc 1f + jmp errmon +1: + ret diff --git a/mach/vax4/libbsd4_1a/vtimes.s b/mach/vax4/libbsd4_1a/vtimes.s new file mode 100644 index 00000000..3e4792e8 --- /dev/null +++ b/mach/vax4/libbsd4_1a/vtimes.s @@ -0,0 +1,8 @@ +.globl _vtimes +.set vtimes,107 + +.align 1 +_vtimes: + .word 0x0000 + chmk $vtimes + ret diff --git a/mach/vax4/libbsd4_1a/vwait.s b/mach/vax4/libbsd4_1a/vwait.s new file mode 100644 index 00000000..4863d88b --- /dev/null +++ b/mach/vax4/libbsd4_1a/vwait.s @@ -0,0 +1,15 @@ +.globl _vwait +.set vwait,71 + +.align 1 +_vwait: + .word 0x0000 + chmk $vwait + bcc 1f + jmp errmon +1: + tstl 4(ap) + beql 1f + movl r1,*4(ap) +1: + ret diff --git a/mach/vax4/libbsd4_1a/vwrite.s b/mach/vax4/libbsd4_1a/vwrite.s new file mode 100644 index 00000000..25b7997e --- /dev/null +++ b/mach/vax4/libbsd4_1a/vwrite.s @@ -0,0 +1,11 @@ +.globl _vwrite +.set vwrite,68 + +.align 1 +_vwrite: + .word 0x0000 + chmk $vwrite + bcc 1f + jmp errmon +1: + ret diff --git a/mach/vax4/libbsd4_1a/wait.s b/mach/vax4/libbsd4_1a/wait.s new file mode 100644 index 00000000..9962b0d4 --- /dev/null +++ b/mach/vax4/libbsd4_1a/wait.s @@ -0,0 +1,15 @@ +.set wait,7 +.globl _wait + +.align 1 +_wait: + .word 0x0000 + chmk $wait + bcc 1f + jmp errmon +1: + tstl 4(ap) + beql 1f + movl r1,*4(ap) +1: + ret diff --git a/mach/vax4/libbsd4_1a/write.s b/mach/vax4/libbsd4_1a/write.s new file mode 100644 index 00000000..3c69d958 --- /dev/null +++ b/mach/vax4/libbsd4_1a/write.s @@ -0,0 +1,11 @@ +.globl _write +.set write,4 + +.align 1 +_write: + .word 0x0000 + chmk $write + bcc 1f + jmp errmon +1: + ret From 1145e16e152dc7faabbc09ebe0b8d47ebbc603bf Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 12 Dec 1986 13:43:06 +0000 Subject: [PATCH 0394/1625] Initial revision --- mach/vax4/libbsd4_1a/compmodule | 4 ++++ 1 file changed, 4 insertions(+) create mode 100755 mach/vax4/libbsd4_1a/compmodule diff --git a/mach/vax4/libbsd4_1a/compmodule b/mach/vax4/libbsd4_1a/compmodule new file mode 100755 index 00000000..67777e8a --- /dev/null +++ b/mach/vax4/libbsd4_1a/compmodule @@ -0,0 +1,4 @@ +if vax4 -O -c -I../../../h -I. $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 +fi From a02f330f2fe52ab3ce2e8e8ced22ceab880bd974 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 12 Dec 1986 14:40:25 +0000 Subject: [PATCH 0395/1625] .globl does not accept comma's --- mach/vax4/libbsd4_1a/sbrk.s | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mach/vax4/libbsd4_1a/sbrk.s b/mach/vax4/libbsd4_1a/sbrk.s index 605a2aa3..436da401 100644 --- a/mach/vax4/libbsd4_1a/sbrk.s +++ b/mach/vax4/libbsd4_1a/sbrk.s @@ -1,5 +1,6 @@ .set break,17 -.globl _sbrk, _brk +.globl _sbrk +.globl _brk .globl _end .align 1 From 4ebfccb17f6f79527f5135112b1b0931e65b5411 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 12 Dec 1986 14:45:20 +0000 Subject: [PATCH 0396/1625] Bloody assembler does not recognize ',' in .globl --- mach/vax4/libbsd4_1a/getgid.s | 3 ++- mach/vax4/libbsd4_1a/getpid.s | 3 ++- mach/vax4/libbsd4_1a/getuid.s | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/mach/vax4/libbsd4_1a/getgid.s b/mach/vax4/libbsd4_1a/getgid.s index 9ae921ad..55e936fd 100644 --- a/mach/vax4/libbsd4_1a/getgid.s +++ b/mach/vax4/libbsd4_1a/getgid.s @@ -1,4 +1,5 @@ -.globl _getgid, _getegid +.globl _getgid +.globl _getegid .set getgid,47 .align 1 diff --git a/mach/vax4/libbsd4_1a/getpid.s b/mach/vax4/libbsd4_1a/getpid.s index 06ab9dbb..f1e14a68 100644 --- a/mach/vax4/libbsd4_1a/getpid.s +++ b/mach/vax4/libbsd4_1a/getpid.s @@ -1,4 +1,5 @@ -.globl _getpid, _getppid +.globl _getpid +.globl _getppid .set getpid,20 .align 1 diff --git a/mach/vax4/libbsd4_1a/getuid.s b/mach/vax4/libbsd4_1a/getuid.s index 2d1a13e2..5ec2af85 100644 --- a/mach/vax4/libbsd4_1a/getuid.s +++ b/mach/vax4/libbsd4_1a/getuid.s @@ -1,4 +1,5 @@ -.globl _getuid, _geteuid +.globl _getuid +.globl _geteuid .set getuid,24 .align 1 From 4a0f9dbe8e83c4f6e28dec8d9b17e05f6b1b7126 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 12 Dec 1986 16:12:19 +0000 Subject: [PATCH 0397/1625] Initial revision --- mach/vax4/libbsd4_2/Makefile | 30 +++++++++++++ mach/vax4/libbsd4_2/head_em.s | 82 +++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 mach/vax4/libbsd4_2/Makefile create mode 100644 mach/vax4/libbsd4_2/head_em.s diff --git a/mach/vax4/libbsd4_2/Makefile b/mach/vax4/libbsd4_2/Makefile new file mode 100644 index 00000000..92b9aaf6 --- /dev/null +++ b/mach/vax4/libbsd4_2/Makefile @@ -0,0 +1,30 @@ +# $Header$ +install: cp + +cp: all + ../../install head_em + ../../install tail_mon + rm -f head_em tail_mon + +cmp: all + -../../compare head_em + -../../compare tail_mon + rm -f head_em tail_mon + +all: head_em tail_mon + +head_em: head_em.s + vax4 -I../../../h -c head_em.s ; mv head_em.o head_em + +tail_mon: + ASAR=ar ; export ASAR ;\ + RANLIB=ranlib ; export RANLIB ;\ + march . tail_mon + +clean: + rm -f *.o +opr: + make pr | opr +pr: + @pr `pwd`/Makefile `pwd`/head_em.s + @pr -l33 `tail +1 LIST|sort` diff --git a/mach/vax4/libbsd4_2/head_em.s b/mach/vax4/libbsd4_2/head_em.s new file mode 100644 index 00000000..1afad8bc --- /dev/null +++ b/mach/vax4/libbsd4_2/head_em.s @@ -0,0 +1,82 @@ +#include "em_abs.h" +#include "/usr/include/syscall.h" + + # $Header$ + +.globl hol0 +.globl .reghp +.globl .trppc +.globl .trpim + + # run time startoff + .word 0 + bispsw $0100 # set FU(0100) + movl 4(sp),r0 + clrl -4(r0) + movl sp,r0 + movl (r0)+,r1 + movl r0,r2 +a1: + tstl (r0)+ + bneq a1 + cmpl r0,(r2) + blssu a2 + tstl -(r0) +a2: + pushl r0 + pushl r2 + pushl r1 + movl $m1,ap + chmk (ap)+ # catch floating point exception + calls $3,_m_a_i_n + movl $m2,ap + movl r0,6(ap) + chmk (ap)+ + halt + + .align 1 +sig8: + .word 0x0000 + pushl 8(ap) + movl (sp)+,ap + pushl tab [ap] + jsb .trp + movl $m1,ap + chmk (ap)+ + ret + + .data +m1: + .word SYS_sigvec + .long 3 + .long 8 + .long m1a + .long 0 +m1a: + .long sig8 + .long 0 + .long 0 +m2: + .word 1 + .long 1 + .long 0 +.reghp: + .long _end +hol0: + .space 8 +.trppc: + .space 4 +.trpim: + .long 0 +tab: + .long 0 + .long EIOVFL + .long EIDIVZ + .long EFOVFL + .long EFDIVZ + .long EFUNFL + .long EILLINS + .long EARRAY + .long EFOVFL + .long EFDIVZ + .long EFUNFL From 373dc426967ebbdc3c1f991ae72f9e863a1a93e6 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 12 Dec 1986 17:51:03 +0000 Subject: [PATCH 0398/1625] Removed almost the whole file, as we now use assembly routines to interface the systemcalls. --- mach/vax4/libem/mon.s | 349 +----------------------------------------- 1 file changed, 1 insertion(+), 348 deletions(-) diff --git a/mach/vax4/libem/mon.s b/mach/vax4/libem/mon.s index f81e9ead..760f1ba4 100644 --- a/mach/vax4/libem/mon.s +++ b/mach/vax4/libem/mon.s @@ -1,354 +1,7 @@ -#include "system.h" -#include "em_abs.h" -#define MOVL movl (sp)+,(ap)+ -#define MOVQ movq (sp)+,(ap)+ - - # $Header$ - -.set sigvec,108 + # $Header$ .globl .mon .mon: - movl (sp)+,r2 # return address in r2 - movl (sp)+,r0 # monitor call in r0 - movl ap,r3 - movl $args,ap - cvtlw r0,(ap)+ - cmpl r0,$61 - jgtru Lbadmon - ashl $2,r0,r0 - jmp *L0(r0) -.data -.align 2 -L0: -#ifndef BSD41a -.long Lbadmon, Lexit, Lfork, Lread, Lwrite -.long Lopen, Lclose, Lwait, Lcreat, Llink -.long Lunlink, Lbadmon, Lchdir, Lbadmon, Lbadmon -.long Lchmod, Lchown, Lbadmon, Lstat, Llseek -.long Lgetpid, Lbadmon, Lbadmon, Lbadmon, Lgetuid -.long Lbadmon, Lptrace, Lalarm, Lfstat, Lpause -.long Lutime, Lbadmon, Lbadmon, Laccess, Lnice -.long Lbadmon, Lsync, Lkill, Lbadmon, Lbadmon -.long Lbadmon, Ldup, Lpipe, Lbadmon, Lprofil -.long Lbadmon, Lbadmon, Lgetgid, Lsigtrp, Lbadmon -.long Lbadmon, Lacct, Lbadmon, Lbadmon, Lioctl -.long Lbadmon, Lbadmon, Lbadmon, Lbadmon, Lexece -.long Lumask, Lchroot -#else -.long Lbadmon, Lexit, Lfork, Lread, Lwrite -.long Lopen, Lclose, Lwait, Lcreat, Llink -.long Lunlink, Lbadmon, Lchdir, Lbadmon, Lmknod -.long Lchmod, Lchown, Lbadmon, Lstat, Llseek -.long Lgetpid, Lmount, Lumount, Lsetuid, Lgetuid -.long Lstime, Lptrace, Lalarm, Lfstat, Lpause -.long Lutime, Lbadmon, Lbadmon, Laccess, Lnice -.long Lftime, Lsync, Lkill, Lbadmon, Lbadmon -.long Lbadmon, Ldup, Lpipe, Ltimes, Lprofil -.long Lbadmon, Lsetgid, Lgetgid, Lsigtrp, Lbadmon -.long Lbadmon, Lacct, Lbadmon, Llock, Lioctl -.long Lbadmon, Lmpxall, Lbadmon, Lbadmon, Lexece -.long Lumask, Lchroot -#endif -.text - - # Each system call first stores its number of arguments, then the - # arguments themselves. - # The system calls are grouped according to their number of arguments - # and their results. - # Le*: an errornumber is expected - # L*r0*: the value of r0 is expected - # L*r1*: the value of r1 is expected - # Lnores: no results expected - - # 0 arguments. -Lsync: -Lpause: - clrl (ap)+ -Lnores: - jsb Lsyscall - movl r3,ap - jmp (r2) -Lgetpid: - clrl (ap)+ -Lr0: - jsb Lsyscall - pushl r0 - movl r3,ap - jmp (r2) -Lgetuid: -Lgetgid: - clrl (ap)+ -Lr0r1: - jsb Lsyscall - pushl r0 - pushl r1 - movl r3,ap - jmp (r2) -Lpipe: -Lwait: -Lfork: - clrl (ap)+ -Ler0r1: - jsb Lsyscall - pushl r0 - pushl r1 - clrl -(sp) - movl r3,ap - jmp (r2) - - # 1 argument. -Lexit: -Ltimes: - cvtbl $1,(ap)+ - MOVL - jbr Lnores -Lclose: -Lunlink: -Lchdir: -Lumount: -Lsetuid: -Lstime: -Lnice: -Lftime: -Lsetgid: -Lacct: -Llock: -Lchroot: - cvtbl $1,(ap)+ - MOVL -Le: - jsb Lsyscall - clrl -(sp) - movl r3,ap - jmp (r2) -Lalarm: -Lumask: - cvtbl $1,(ap)+ - MOVL - jbr Lr0 - - # 2 arguments. -Llink: -Lchmod: -Lstat: -Lfstat: -Lutime: -Laccess: -Lkill: -Lmpxall: - cvtbl $2,(ap)+ - MOVQ - jbr Le -Ldup: - cvtbl $2,(ap)+ - MOVQ -Ler0: - jsb Lsyscall - pushl r0 - clrl -(sp) - movl r3,ap - jmp (r2) - - # 3 arguments. -Lioctl: -Lexece: -Lmknod: -Lchown: -Lmount: - cvtbl $3,(ap)+ - MOVL - MOVQ - jbr Le -Llseek: -Lread: -Lwrite: - cvtbl $3,(ap)+ - MOVL - MOVQ - jbr Ler0 - - # 4 arguments. -Lprofil: - cvtbl $4,(ap)+ - MOVQ - MOVQ - jbr Lnores -Lptrace: - cvtbl $4,(ap)+ - MOVQ - MOVQ - jbr Ler0 - -Lopen: -#ifndef BSD41a - # The old open(name, mode) system call is simulated by - # open(name, mode, 0). - cvtbl $3,(ap)+ -#else - cvtbl $2,(ap)+ -#endif - MOVQ -#ifndef BSD41a - clrl (ap)+ -#endif - jbr Ler0 -Lcreat: -#ifndef BSD41a - # The old creat(name, mode) system call is simulated by - # open(name, O_WRONLY | O_CREAT | O_TRUNC, mode). - cvtbl $5,-2(ap) - cvtbl $3,(ap)+ -#else - cvtbl $2,(ap)+ -#endif - MOVL -#ifndef BSD41a - movl $0x601,(ap)+ -#endif - MOVL - jbr Ler0 - -Lsyscall: - movl $args,ap - chmk (ap)+ - bcc L1 - cvtwl r0,(sp) # Push the error returned twice, - cvtwl r0,-(sp) # overwrite the return address - movl r3,ap - jmp (r2) -L1: - rsb -Lbadmon: pushl $EBADMON jmp .fat -Lsigtrp: - movl 4(sp),r1 # Sig in r1 - movl (sp)+,(sp) # Trapno on top of stack - cmpl r1,$16 - jgtru badsig - tstl r1 - jeql badsig -#ifdef BSD42 - movl $3,(ap)+ # sigvec(sig, vec, ovec) -#else BSD42 - movl $2,(ap)+ # signal(sig, func) -#endif BSD42 - movl r1,(ap)+ - movl sigadr0 [r1],r0 - tstl (sp) - blss L2 - cmpl (sp),$252 - bgtr badtrp - movl r0,(ap)+ - brb sys -L2: cmpl $-3,(sp) - bneq L3 - movl $1,(ap)+ # SIG_IGN - brb sys -L3: cmpl $-2,(sp) - bneq badtrp - clrl (ap)+ # SIG_DFL -sys: -#ifdef BSD42 - movl -(ap),vec # vec->sv_handler = func - movl $vec,(ap)+ - movl $ovec,(ap)+ # Not used. -#endif BSD42 - pushl sigtrp0 [r1] - movl 4(sp),sigtrp0 [r1] - movl (sp)+,(sp) # Old trap number on top of stack. - movl $args,ap -#ifdef BSD42 - movw $sigvec,(ap) -#endif - chmk (ap)+ - bcc L4 - movl (sp),sigtrp0 [r1] # Error, reset old trap number. - pushl r0 - movl r3,ap - jmp (r2) -L4: clrl -(sp) - movl r3,ap - jmp (r2) -badsig: - movl $-1,(sp) - pushl (sp) - movl r3,ap - jmp (r2) -badtrp: - movl sigtrp0 [r1],(sp) - pushl $-1 - movl r3,ap - jmp (r2) - -sigs: - .word 0x0000 - # Routine to catch signals. - pushl fp - movl 12(fp),fp - movl 12(fp),fp # Restore local base, two levels! - movl 4(ap),ap - pushl sigtrp0 [ap] - jsb .trp - movl (sp)+,fp - ret - -.data -#ifdef BSD42 -vec: - .long 0 # sv_handler - .long 0 # sv_mask - .long 0 # sv_onstack -ovec: - .long 0 # sv_onstack - .long 0 # sv_mask - .long 0 # sv_onstack -#endif BSD42 -args: - .word 0 - .long 0 - .long 0 - .long 0 - .long 0 - .long 0 - .long 0 - -sigadr0: - .long 0 #0 - .long sigs #1 - .long sigs #2 - .long sigs #3 - .long sigs #4 - .long sigs #5 - .long sigs #6 - .long sigs #7 - .long sigs #8 - .long sigs #9 - .long sigs #10 - .long sigs #11 - .long sigs #12 - .long sigs #13 - .long sigs #14 - .long sigs #15 - .long sigs #16 - -sigtrp0: - .long -2 - .long -2 - .long -2 - .long -2 - .long -2 - .long -2 - .long -2 - .long -2 - .long -2 - .long -2 - .long -2 - .long -2 - .long -2 - .long -2 - .long -2 - .long -2 - .long -2 From ddc2469aa39d079598651b084cc4a4e0eb4ae592 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 12 Dec 1986 17:54:21 +0000 Subject: [PATCH 0399/1625] head_em now resides in system dependant library. --- mach/vax4/libem/Makefile | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/mach/vax4/libem/Makefile b/mach/vax4/libem/Makefile index d50c1ba9..2177b365 100644 --- a/mach/vax4/libem/Makefile +++ b/mach/vax4/libem/Makefile @@ -2,19 +2,14 @@ install: cp cp: all - ../../install head_em ../../install tail_em - rm -f head_em tail_em + rm -f tail_em cmp: all - -../../compare head_em -../../compare tail_em - rm -f head_em tail_em + rm -f tail_em -all: head_em tail_em - -head_em: head_em.s - vax4 -I../../../h -c head_em.s ; mv head_em.o head_em +all: tail_em tail_em: ASAR=ar ; export ASAR ;\ @@ -26,5 +21,5 @@ clean: opr: make pr | opr pr: - @pr `pwd`/Makefile `pwd`/head_em.s + @pr `pwd`/Makefile @pr -l33 `tail +1 LIST|sort` From 013f816c6cd2599e2a6a03c13b9aa4d2e4357a08 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 12 Dec 1986 17:56:05 +0000 Subject: [PATCH 0400/1625] No longer use the "system-independant" tail_mon. --- mach/vax4/libcc/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mach/vax4/libcc/Makefile b/mach/vax4/libcc/Makefile index 082bedfc..b8100794 100644 --- a/mach/vax4/libcc/Makefile +++ b/mach/vax4/libcc/Makefile @@ -6,7 +6,7 @@ MON="PREF=mon" "SRC=lang/cem/libcc/mon" LIBM="PREF=m" "SRC=lang/cem/libcc/libm" LIBLN="PREF=ln" "SRC=lang/cem/libcc/libln" -install: cpstdio cpgen cpmon cplibm cplibln +install: cpstdio cpgen cplibm cplibln cpstdio: RANLIB=ranlib ; export RANLIB ;\ @@ -24,7 +24,7 @@ cplibln: RANLIB=ranlib ; export RANLIB ;\ make -f $(MAKEFILE) $(LIBLN) $(MACHDEF) tailcp -cmp: cmpstdio cmpgen cmpmon cmplib cmplibln +cmp: cmpstdio cmpgen cmplib cmplibln cmpstdio: make -f $(MAKEFILE) $(STDIO) $(MACHDEF) tail From 62e81f129233b8b8885adcb1e391fbbc3206d6ba Mon Sep 17 00:00:00 2001 From: dick Date: Sat, 13 Dec 1986 20:57:40 +0000 Subject: [PATCH 0401/1625] some small changes, asm() yields error message --- lang/cem/cemcom/Makefile.erik | 73 ++++++++++++++++++----------------- lang/cem/cemcom/asm.c | 5 ++- lang/cem/cemcom/options | 2 +- lang/cem/cemcom/program.g | 2 +- lang/cem/cemcom/statement.g | 2 +- 5 files changed, 44 insertions(+), 40 deletions(-) diff --git a/lang/cem/cemcom/Makefile.erik b/lang/cem/cemcom/Makefile.erik index d7f9352f..de577f40 100644 --- a/lang/cem/cemcom/Makefile.erik +++ b/lang/cem/cemcom/Makefile.erik @@ -2,42 +2,45 @@ # M A K E F I L E F O R A C K C - C O M P I L E R # Machine and environ dependent definitions -EM = /usr/em# # ACK tree on this machine -DESTINATION = /user1/$$USER/bin# # where to put the stuff -MKDEP = $(EM)/bin/mkdep# # dependency generator +EMHOME = /usr/em# # ACK tree on this machine +DESTINATION = /user1/$$USER/bin# # where to put the stuff +MKDEP = $(EMHOME)/bin/mkdep# # dependency generator MAP = -#MAP = -DInsertFile=ins_file -DInsertText=ins_text# # bug in m68k2 back end -SIM = /user1/dick/bin/sim# # Dicks sim program -LINT = /usr/new/lint +#MAP = -DInsertFile=ins_file -DInsertText=ins_text# bug in m68k2 back end +SIM = /user1/dick/bin/sim# # Dicks sim program +LINT = /usr/new/lint # Libraries and EM interface definitions -SYSLIB = $(EM)/modules/lib/libsystem.a -EMKLIB = $(EM)/modules/lib/libemk.a -EMELIB = $(EM)/modules/lib/libeme.a -STRLIB = $(EM)/modules/lib/libstr.a -PRTLIB = $(EM)/modules/lib/libprint.a -EMMESLIB = $(EM)/modules/lib/libem_mes.a -INPLIB = $(EM)/modules/lib/libinput.a -#CH3LIB = $(EM)/modules/lib/libch3.a +SYSLIB = $(EMHOME)/modules/lib/libsystem.a +EMKLIB = $(EMHOME)/modules/lib/libemk.a +EMELIB = $(EMHOME)/modules/lib/libeme.a +STRLIB = $(EMHOME)/modules/lib/libstr.a +PRTLIB = $(EMHOME)/modules/lib/libprint.a +EMMESLIB = $(EMHOME)/modules/lib/libem_mes.a +INPLIB = $(EMHOME)/modules/lib/libinput.a +#CH3LIB = $(EMHOME)/modules/lib/libch3.a CH3LIB = -LIBS = $(INPLIB) $(CH3LIB) $(EMMESLIB) $(EMKLIB) $(PRTLIB) $(STRLIB) $(SYSLIB) -ELIBS = $(INPLIB) $(CH3LIB) $(EMMESLIB) $(EMELIB) $(PRTLIB) $(STRLIB) $(SYSLIB) -LIB_INCLUDES = -I$(EM)/modules/h -I$(EM)/modules/pkg -EM_INCLUDES = -I$(EM)/h -SYSLLIB = $(EM)/modules/lib/llib-lsys.ln -EMKLLIB = $(EM)/modules/lib/llib-lemk.ln -EMELLIB = $(EM)/modules/lib/llib-leme.ln -STRLLIB = $(EM)/modules/lib/llib-lstr.ln -PRTLLIB = $(EM)/modules/lib/llib-lprint.ln -EMMESLLIB = $(EM)/modules/lib/llib-lmes.ln -INPLLIB = $(EM)/modules/lib/llib-linput.ln -CH3LLIB = $(EM)/modules/lib/llib-lch3.ln +LIBS = $(INPLIB) $(CH3LIB) $(EMMESLIB) $(EMKLIB) \ + $(PRTLIB) $(STRLIB) $(SYSLIB) +ELIBS = $(INPLIB) $(CH3LIB) $(EMMESLIB) $(EMELIB) \ + $(PRTLIB) $(STRLIB) $(SYSLIB) +LIB_INCLUDES = -I$(EMHOME)/modules/h -I$(EMHOME)/modules/pkg +EM_INCLUDES = -I$(EMHOME)/h +SYSLLIB = $(EMHOME)/modules/lib/llib-lsys.ln +EMKLLIB = $(EMHOME)/modules/lib/llib-lemk.ln +EMELLIB = $(EMHOME)/modules/lib/llib-leme.ln +STRLLIB = $(EMHOME)/modules/lib/llib-lstr.ln +PRTLLIB = $(EMHOME)/modules/lib/llib-lprint.ln +EMMESLLIB = $(EMHOME)/modules/lib/llib-lmes.ln +INPLLIB = $(EMHOME)/modules/lib/llib-linput.ln +CH3LLIB = $(EMHOME)/modules/lib/llib-lch3.ln LINTLIBS = -#LINTLIBS = $(CH3LLIB) $(INPLLIB) $(EMMESLLIB) $(EMKLLIB) $(PRTLLIB) $(STRLLIB) $(SYSLLIB) +#LINTLIBS = $(CH3LLIB) $(INPLLIB) $(EMMESLLIB) $(EMKLLIB) \ +# $(PRTLLIB) $(STRLLIB) $(SYSLLIB) # Where to install the compiler and its driver -CEMCOM = $(DESTINATION)/cemcom -DRIVER = $(DESTINATION)/cem +CEMCOM = $(DESTINATION)/cemcom +DRIVER = $(DESTINATION)/cem # What C compiler to use and how # CC = $(ACK) -.c @@ -46,12 +49,12 @@ DRIVER = $(DESTINATION)/cem COPTIONS = # What parser generator to use and how -GEN = $(EM)/bin/LLgen -GENOPTIONS = -vv +GEN = $(EMHOME)/bin/LLgen +GENOPTIONS = -vv # Special #defines during compilation -CDEFS = $(MAP) $(EM_INCLUDES) $(LIB_INCLUDES) -CFLAGS = $(CDEFS) $(COPTIONS) -O# # we cannot pass the COPTIONS to lint! +CDEFS = $(MAP) $(EM_INCLUDES) $(LIB_INCLUDES) +CFLAGS = $(CDEFS) $(COPTIONS) -O# we cannot pass the COPTIONS to lint! # Grammar files and their objects LSRC = tokenfile.g declar.g statement.g expression.g program.g @@ -76,7 +79,7 @@ GSRC = char.c symbol2str.c next.c \ idf.h macro.h stack.h stmt.h struct.h switch.h type.h # .h files generated by `make hfiles'; PLEASE KEEP THIS UP-TO-DATE! -GHSRC = botch_free.h dataflow.h debug.h density.h errout.h \ +GHSRC = botch_free.h dataflow.h debug.h density.h errout.h \ idepth.h idfsize.h ifdepth.h inputtype.h inumlength.h lapbuf.h \ maxincl.h myalloc.h nobitfield.h nofloat.h nopp.h \ nparams.h numsize.h parbufsize.h pathlength.h \ @@ -159,7 +162,7 @@ install: main cem cp main $(CEMCOM) cp cem $(DRIVER) -print: files +print: files pr `cat files` > print tags: cfiles diff --git a/lang/cem/cemcom/asm.c b/lang/cem/cemcom/asm.c index 3b8cd1f9..56f02e41 100644 --- a/lang/cem/cemcom/asm.c +++ b/lang/cem/cemcom/asm.c @@ -1,11 +1,12 @@ /* $Header$ */ /* A S M */ -asm_seen(s, l) +code_asm(s, l) char *s; int l; { /* 'asm' '(' string ')' ';' */ - warning("\"asm(\"%s\")\" instruction skipped", s); + s = s; l = l; + error("\"asm instruction not implemented", s); } diff --git a/lang/cem/cemcom/options b/lang/cem/cemcom/options index d1faf7cf..0dce7fa7 100644 --- a/lang/cem/cemcom/options +++ b/lang/cem/cemcom/options @@ -6,7 +6,7 @@ I expand include table with directory name following M set identifier length n don't generate register messages p generate linenumbers and filename indications - while generating compact EM code + while generating EM code P in running the preprocessor do not output '# line' lines R restricted C T take path following as directory for storing temporary file(s) diff --git a/lang/cem/cemcom/program.g b/lang/cem/cemcom/program.g index c44b44e5..91b46027 100644 --- a/lang/cem/cemcom/program.g +++ b/lang/cem/cemcom/program.g @@ -89,7 +89,7 @@ program: the declaration in a way different from most other languages: e.g., rather than defining x as a pointer-to-integer, it defines *x as an integer and lets the compiler deduce that x is actually - pointer-to-integer. This has profound consequences, but for the + pointer-to-integer. This has profound consequences, both for the structure of an identifier definition and for the compiler. A definition starts with a decl_specifiers, which contains things diff --git a/lang/cem/cemcom/statement.g b/lang/cem/cemcom/statement.g index 4109ba07..466bec8b 100644 --- a/lang/cem/cemcom/statement.g +++ b/lang/cem/cemcom/statement.g @@ -393,6 +393,6 @@ asm_statement } ')' ';' - { asm_seen(asm_bts, asm_len); + { code_asm(asm_bts, asm_len); } ; From 9f1d5f8c5ab12a2210741e4e99a8be04bcc91e1a Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 16 Dec 1986 10:23:21 +0000 Subject: [PATCH 0402/1625] Initial revision --- mach/vax4/libbsd4_1a/exit.c | 5 +++++ mach/vax4/libbsd4_1a/gtty.c | 7 +++++++ mach/vax4/libbsd4_1a/stty.c | 7 +++++++ 3 files changed, 19 insertions(+) create mode 100644 mach/vax4/libbsd4_1a/exit.c create mode 100644 mach/vax4/libbsd4_1a/gtty.c create mode 100644 mach/vax4/libbsd4_1a/stty.c diff --git a/mach/vax4/libbsd4_1a/exit.c b/mach/vax4/libbsd4_1a/exit.c new file mode 100644 index 00000000..8f5f9a84 --- /dev/null +++ b/mach/vax4/libbsd4_1a/exit.c @@ -0,0 +1,5 @@ +exit(code) +{ + _cleanup() ; + _exit(code) ; +} diff --git a/mach/vax4/libbsd4_1a/gtty.c b/mach/vax4/libbsd4_1a/gtty.c new file mode 100644 index 00000000..7f42ea1f --- /dev/null +++ b/mach/vax4/libbsd4_1a/gtty.c @@ -0,0 +1,7 @@ +#include +int gtty(fildes,argp) + int fildes ; + struct sgttyb *argp ; +{ + return ioctl(fildes,TIOCGETP,argp) ; +} diff --git a/mach/vax4/libbsd4_1a/stty.c b/mach/vax4/libbsd4_1a/stty.c new file mode 100644 index 00000000..222310cc --- /dev/null +++ b/mach/vax4/libbsd4_1a/stty.c @@ -0,0 +1,7 @@ +#include +int stty(fildes,argp) + int fildes ; + struct sgttyb *argp ; +{ + return ioctl(fildes,TIOCSETP,argp) ; +} From 3cc63b8c020b43de81b49ce1548117a55b3f409b Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 16 Dec 1986 10:25:44 +0000 Subject: [PATCH 0403/1625] Added exit.c stty.c gtty.c --- mach/vax4/libbsd4_1a/LIST | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mach/vax4/libbsd4_1a/LIST b/mach/vax4/libbsd4_1a/LIST index 31b368e7..7e2cbef6 100644 --- a/mach/vax4/libbsd4_1a/LIST +++ b/mach/vax4/libbsd4_1a/LIST @@ -1,4 +1,7 @@ tail_mon.a +exit.c +gtty.c +stty.c _exit.s access.s acct.s From 947f62f2783caf90014eb832249473ae1f1313ed Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 16 Dec 1986 13:50:54 +0000 Subject: [PATCH 0404/1625] Introduced EMHOME. --- util/ack/Makefile | 16 +++++++++------- util/ack/pc/Makefile | 6 +++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/util/ack/Makefile b/util/ack/Makefile index aa927275..18c91a41 100644 --- a/util/ack/Makefile +++ b/util/ack/Makefile @@ -1,18 +1,20 @@ # $Header$ +EMHOME=../.. HFILES=ack.h list.h trans.h data.h dmach.h grows.h DSRC=list.c data.c main.c scan.c svars.c trans.c util.c rmach.c run.c grows.c\ files.c ISRC=dmach.c intable.c OBJ=list.o data.o main.o scan.o svars.o trans.o util.o rmach.o run.o \ dmach.o intable.o grows.o files.o -ACKDIR=../../lib/ack +ACKDIR=$(EMHOME)/lib/ack FE=fe INTABLES=pdp int LNTABLES=acc apc abc vax2 vax4 i86 ix m68k2 m68k4 pmds pmds4 z8000\ int22 int24 int44 6500 6800 6805 6809 i80 ns s2650 z80 -CFLAGS=-O -n -BINDIR=../../bin -MODDIR=../../modules/lib +INCLUDES=-I $(EMHOME)/h +CFLAGS=-O -n $(INCLUDES) +BINDIR=$(EMHOME)/bin +MODDIR=$(EMHOME)/modules/lib head: ack @@ -32,7 +34,7 @@ clean: (cd pc ; make clean ) ack: $(OBJ) - $(CC) -o ack $(CFLAGS) $(OBJ) $(MODDIR)/libstr.a + $(CC) -o ack $(CFLAGS) $(OBJ) $(MODDIR)/libstring.a grows.o files.o list.o run.o \ data.o main.o scan.o trans.o rmach.o util.o : ack.h list.h @@ -43,9 +45,9 @@ files.o rmach.o trans.o grows.c : grows.h rmach.c: dmach.h -files.o main.o rmach.o : ../../h/em_path.h +files.o main.o rmach.o : $(EMHOME)/h/em_path.h -main.o : ../../h/local.h +main.o : $(EMHOME)/h/local.h malloc.o svars.o: ack.h diff --git a/util/ack/pc/Makefile b/util/ack/pc/Makefile index 3d55256b..68181057 100644 --- a/util/ack/pc/Makefile +++ b/util/ack/pc/Makefile @@ -1,7 +1,7 @@ -d=../../.. -h=$d/h +EMHOME=../../.. +h=$(EMHOME)/h -PC_PATH=$d/lib/em_pc +PC_PATH=$(EMHOME)/lib/em_pc em_pc: em_pc.c $h/local.h $h/em_path.h cc -n -o em_pc -O -I$h em_pc.c From 40a554bc9bd6afe1c1b58c67b0236dde2d8cc029 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 16 Dec 1986 14:30:33 +0000 Subject: [PATCH 0405/1625] bug fix in LLlex.c, "string_token" --- lang/cem/cemcom/LLlex.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lang/cem/cemcom/LLlex.c b/lang/cem/cemcom/LLlex.c index e8b245cc..309b21bb 100644 --- a/lang/cem/cemcom/LLlex.c +++ b/lang/cem/cemcom/LLlex.c @@ -495,6 +495,7 @@ string_token(nm, stop_char, plen) LoadChar(ch); if (ch == '\n') { LineNumber++; + LoadChar(ch); continue; } ch = quoted(ch); From bb0969ede63816d088bf81f666de2689dd8f8f36 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 16 Dec 1986 15:22:33 +0000 Subject: [PATCH 0406/1625] D_BUSY added, to check recursive deps in def modules --- lang/m2/comp/def.H | 5 ++--- lang/m2/comp/defmodule.c | 6 +++++- lang/m2/comp/program.g | 2 ++ lang/m2/comp/type.c | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H index d27f32c7..3462d4b2 100644 --- a/lang/m2/comp/def.H +++ b/lang/m2/comp/def.H @@ -97,7 +97,7 @@ struct def { /* list of definitions for a name */ #define D_VALUE (D_PROCEDURE|D_VARIABLE|D_FIELD|D_ENUM|D_CONST|D_PROCHEAD) #define D_ISTYPE (D_HIDDEN|D_TYPE|D_FTYPE) #define is_type(dfx) ((dfx)->df_kind & D_ISTYPE) - char df_flags; + unsigned short df_flags; #define D_NOREG 0x01 /* set if it may not reside in a register */ #define D_USED 0x02 /* set if used (future use ???) */ #define D_DEFINED 0x04 /* set if it is assigned a value (future use ???) */ @@ -105,6 +105,7 @@ struct def { /* list of definitions for a name */ #define D_VALPAR 0x10 /* set if it is a value parameter */ #define D_EXPORTED 0x20 /* set if exported */ #define D_QEXPORTED 0x40 /* set if qualified exported */ +#define D_BUSY 0x80 /* set if busy reading this definition module */ struct type *df_type; union { struct module df_module; @@ -120,8 +121,6 @@ struct def { /* list of definitions for a name */ } df_value; }; -#define SetUsed(df) ((df)->df_flags |= D_USED) - /* ALLOCDEF "def" 50 */ extern struct def diff --git a/lang/m2/comp/defmodule.c b/lang/m2/comp/defmodule.c index 2fe30ead..d5f68767 100644 --- a/lang/m2/comp/defmodule.c +++ b/lang/m2/comp/defmodule.c @@ -55,7 +55,7 @@ GetDefinitionModule(id, incr) We may have to read the definition module itself. Also increment level by "incr". */ - struct def *df; + register struct def *df; static int level; struct scopelist *vis; @@ -101,6 +101,10 @@ GetDefinitionModule(id, incr) df->mod_vis = vis; } } + else if (df->df_flags & D_BUSY) { + error("definition module \"%s\" depends on itself", + id->id_text); + } else if (df == Defined && level == 1) { error("cannot import from currently defined module"); df->df_kind = D_ERROR; diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 6867279d..40d8113a 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -121,6 +121,7 @@ DefinitionModule } : DEFINITION MODULE IDENT { df = define(dot.TOK_IDF, GlobalScope, D_MODULE); + df->df_flags |= D_BUSY; if (!Defined) Defined = df; if (df->df_idf != DefId) { error("DEFINITION MODULE name is not \"%s\"", @@ -155,6 +156,7 @@ node_warning(exportlist, W_OLDFASHIONED, "export list in definition module ignor } DefinitionModule--; match_id(df->df_idf, dot.TOK_IDF); + df->df_flags &= ~D_BUSY; } '.' ; diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index a7003717..cea61145 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -383,7 +383,7 @@ set_type(tp) } tp = construct_type(T_SET, tp); - tp->tp_size = WA(((ub - lb) + 8) >> 3); + tp->tp_size = WA((ub - lb + 8) >> 3); return tp; } From 5dacfb665db9f0f6a1e8ec135fa2ebaf616423a3 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 5 Jan 1987 10:58:34 +0000 Subject: [PATCH 0407/1625] Initial revision --- modules/compare | 10 ++++++++++ modules/install | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100755 modules/compare create mode 100755 modules/install diff --git a/modules/compare b/modules/compare new file mode 100755 index 00000000..5eca5d66 --- /dev/null +++ b/modules/compare @@ -0,0 +1,10 @@ +case $# in +1) DEST="$1" + SRC=`basename $DEST` + ;; +2) DEST="$2" + SRC="$1" + ;; +*) echo $0 [source] destination ;; +esac +cmp "$SRC" ../../$DEST diff --git a/modules/install b/modules/install new file mode 100755 index 00000000..7aa57e7b --- /dev/null +++ b/modules/install @@ -0,0 +1,33 @@ +case $# in +1) DEST="$1" + SRC=`basename $DEST` + ;; +2) DEST="$2" + SRC="$1" + ;; +*) echo 'Usage:' $0 [source] destination 1>&2 + exit 1 + ;; +esac +DIR=`expr "$DEST" ':' '\(.*\)/[^/]*' '|' "XXXX"` +case $DIR in +XXXX) echo 'Illegal desination argument:' "$DEST" + exit 1 + ;; +esac +mkdir ../../$DIR > /dev/null 2>&1 +chmod 775 ../../$DIR > /dev/null 2>&1 +if cp "$SRC" ../../$DEST >/dev/null 2>&1 || + { rm -f ../../$DEST >/dev/null 2>&1 && + cp "$SRC" ../../$DEST >/dev/null 2>&1 + } +then + if (ar t ../../$DEST | grep __.SYMDEF ) >/dev/null 2>&1 + then + ranlib ../../$DEST + fi + exit 0 +else + echo Sorry, can not create "$DEST". + exit 1 +fi From 898222c41c68ea8881a764413a3590b12e367679 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 5 Jan 1987 11:08:47 +0000 Subject: [PATCH 0408/1625] Initial revision --- mach/vax4/libbsd4_1a/cleanup.c | 1 + 1 file changed, 1 insertion(+) create mode 100644 mach/vax4/libbsd4_1a/cleanup.c diff --git a/mach/vax4/libbsd4_1a/cleanup.c b/mach/vax4/libbsd4_1a/cleanup.c new file mode 100644 index 00000000..6cd9c63e --- /dev/null +++ b/mach/vax4/libbsd4_1a/cleanup.c @@ -0,0 +1 @@ +_cleanup() { } From eab4c1e0b9c4cf1720d63fb8c94eaf43a03e5964 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 5 Jan 1987 11:12:55 +0000 Subject: [PATCH 0409/1625] added cleanup.c --- mach/vax4/libbsd4_1a/LIST | 1 + 1 file changed, 1 insertion(+) diff --git a/mach/vax4/libbsd4_1a/LIST b/mach/vax4/libbsd4_1a/LIST index 7e2cbef6..1e6f6472 100644 --- a/mach/vax4/libbsd4_1a/LIST +++ b/mach/vax4/libbsd4_1a/LIST @@ -1,5 +1,6 @@ tail_mon.a exit.c +cleanup.c gtty.c stty.c _exit.s From 8cbbe6659d5bb4c2ae2954de5d4f85d71bf96b86 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 5 Jan 1987 12:51:37 +0000 Subject: [PATCH 0410/1625] Extended for new read_em module. --- h/em_ptyp.h | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/h/em_ptyp.h b/h/em_ptyp.h index 6cb3da2c..ad6d500c 100644 --- a/h/em_ptyp.h +++ b/h/em_ptyp.h @@ -1,8 +1,20 @@ #define ptyp(x) (1<<(x-sp_fspec)) -#define cst_ptyp 0000140 -#define sym_ptyp 0000034 -#define arg_ptyp 0000574 -#define con_ptyp 0036000 -#define val_ptyp 0037777 -#define any_ptyp 0137777 +#define cst_ptyp (ptyp(sp_cst2)|ptyp(sp_cst4)) +#define nof_ptyp (ptyp(sp_dlb1)|ptyp(sp_dlb2)|ptyp(sp_doff)) +#define sof_ptyp (ptyp(sp_dnam)|ptyp(sp_doff)) +#define lab_ptyp (ptyp(sp_dlb1)|ptyp(sp_dlb2)|ptyp(sp_dnam)) +#define ico_ptyp (ptyp(sp_icon)) +#define uco_ptyp (ptyp(sp_ucon)) +#define fco_ptyp (ptyp(sp_fcon)) +#define str_ptyp (ptyp(sp_scon)) +#define con_ptyp (str_ptyp|ico_ptyp|uco_ptyp|fco_ptyp) +#define ilb_ptyp (ptyp(sp_ilb1)|ptyp(sp_ilb2)) +#define pro_ptyp (ptyp(sp_pnam)) +#define off_ptyp (ptyp(sp_doff)) +#define end_ptyp (ptyp(sp_cend)) +#define sym_ptyp (lab_ptyp) +#define arg_ptyp (nof_ptyp|cst_ptyp|sof_ptyp) +#define par_ptyp (arg_ptyp|ico_ptyp|uco_ptyp|fco_ptyp|pro_ptyp|ilb_ptyp) +#define val_ptyp (par_ptyp|str_ptyp) +#define any_ptyp (val_ptyp|end_ptyp) From be8f6b74525376c16bc9dd8946e0d2a371b638ad Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 5 Jan 1987 12:59:41 +0000 Subject: [PATCH 0411/1625] Initial revision --- modules/h/em.h | 3 +++ modules/h/em_arith.h | 3 +++ modules/h/em_code.h | 40 ++++++++++++++++++++++++++++++++++++++++ modules/h/em_label.h | 3 +++ 4 files changed, 49 insertions(+) create mode 100644 modules/h/em.h create mode 100644 modules/h/em_arith.h create mode 100644 modules/h/em_code.h create mode 100644 modules/h/em_label.h diff --git a/modules/h/em.h b/modules/h/em.h new file mode 100644 index 00000000..4257467e --- /dev/null +++ b/modules/h/em.h @@ -0,0 +1,3 @@ +#include "em_arith.h" +#include "em_label.h" +#include "em_code.h" diff --git a/modules/h/em_arith.h b/modules/h/em_arith.h new file mode 100644 index 00000000..a5dbb2ec --- /dev/null +++ b/modules/h/em_arith.h @@ -0,0 +1,3 @@ +/* $Header$ */ + +#define arith long diff --git a/modules/h/em_code.h b/modules/h/em_code.h new file mode 100644 index 00000000..9c3f28e5 --- /dev/null +++ b/modules/h/em_code.h @@ -0,0 +1,40 @@ +#define C_lae_dnam _1_C_lae_dnam +#define C_lae_dlb _2_C_lae_dlb +#define C_sde_dnam _3_C_sde_dnam +#define C_sde_dlb _4_C_sde_dlb +#define C_zre_dnam _5_C_zre_dnam +#define C_zre_dlb _6_C_zre_dlb +#define C_hol_dnam _7_C_hol_dnam +#define C_hol_dlb _8_C_hol_dlb +#define C_hol_icon _9_C_hol_icon +#define C_hol_ilb _10_C_hol_ilb +#define C_bss_dnam _11_C_bss_dnam +#define C_bss_dlb _12_C_bss_dlb +#define C_bss_icon _13_C_bss_icon +#define C_bss_ilb _14_C_bss_ilb +#define C_con_dnam _15_C_con_dnam +#define C_con_dlb _16_C_con_dlb +#define C_con_icon _17_C_con_icon +#define C_con_ilb _18_C_con_ilb +#define C_gto_dnam _19_C_gto_dnam +#define C_gto_dlb _20_C_gto_dlb +#define C_ine_dnam _21_C_ine_dnam +#define C_ine_dlb _22_C_ine_dlb +#define C_rom_dnam _23_C_rom_dnam +#define C_rom_dlb _24_C_rom_dlb +#define C_ina_dnam _25_C_ina_dnam +#define C_ina_dlb _26_C_ina_dlb +#define C_rom_icon _27_C_rom_icon +#define C_rom_ilb _28_C_rom_ilb +#define C_ste_dnam _29_C_ste_dnam +#define C_ste_dlb _30_C_ste_dlb +#define C_fil_dnam _31_C_fil_dnam +#define C_fil_dlb _32_C_fil_dlb +#define C_lde_dnam _33_C_lde_dnam +#define C_lde_dlb _34_C_lde_dlb +#define C_loe_dnam _35_C_loe_dnam +#define C_loe_dlb _36_C_loe_dlb +#define C_exa_dnam _37_C_exa_dnam +#define C_exa_dlb _38_C_exa_dlb +#define C_dee_dnam _39_C_dee_dnam +#define C_dee_dlb _40_C_dee_dlb diff --git a/modules/h/em_label.h b/modules/h/em_label.h new file mode 100644 index 00000000..8665fb7a --- /dev/null +++ b/modules/h/em_label.h @@ -0,0 +1,3 @@ +/* $Header$ */ + +#define label unsigned int From 68d498ce30eda7228351d51efce8b82b9394c625 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 5 Jan 1987 13:26:29 +0000 Subject: [PATCH 0412/1625] Initial revision --- modules/src/Action | 39 ++++++++++ modules/src/Xmalloc/Makefile | 21 +++++ modules/src/Xmalloc/Xmalloc.c | 142 ++++++++++++++++++++++++++++++++++ 3 files changed, 202 insertions(+) create mode 100644 modules/src/Action create mode 100644 modules/src/Xmalloc/Makefile create mode 100644 modules/src/Xmalloc/Xmalloc.c diff --git a/modules/src/Action b/modules/src/Action new file mode 100644 index 00000000..d30d0b02 --- /dev/null +++ b/modules/src/Action @@ -0,0 +1,39 @@ +name "system-call interface module" +dir system +end +name "string routines module" +dir string +end +name "formatted print module" +dir print +end +name "assertion module" +dir assert +end +name "memory allocation module" +dir alloc +end +name "fast, wasting malloc" +dir Xmalloc +end +name "fast, memory efficient malloc" +dir malloc +end +name "EM messages generation module" +dir em_mes +end +name "identifier table module" +dir idf +end +name "input module" +dir input +end +name "ACK-object reading and writing module" +dir object +end +name "EM-code reading module" +dir read_em +end +name "EM code generation module" +dir em_code +end diff --git a/modules/src/Xmalloc/Makefile b/modules/src/Xmalloc/Makefile new file mode 100644 index 00000000..de3288a9 --- /dev/null +++ b/modules/src/Xmalloc/Makefile @@ -0,0 +1,21 @@ +EMHOME=../../.. +HDIR = $(EMHOME)/modules/h +INSTALL=$(EMHOME)/modules/install +COMPARE=$(EMHOME)/modules/compare + +CFLAGS = -O -I$(HDIR) + +SOURCES = Xmalloc.c + +OBJECTS = Xmalloc.o + +all: $(OBJECTS) + +install: all + $(INSTALL) lib/Xmalloc.o + +compare: all + $(COMPARE) lib/Xmalloc.o + +clean: + rm -f *.[oa] diff --git a/modules/src/Xmalloc/Xmalloc.c b/modules/src/Xmalloc/Xmalloc.c new file mode 100644 index 00000000..3320d1ce --- /dev/null +++ b/modules/src/Xmalloc/Xmalloc.c @@ -0,0 +1,142 @@ +/* M E M O R Y A L L O C A T I O N R O U T I N E S */ + +/* The reason for having own memory allocation routines (malloc(), + realloc() and free()) is plain: the garbage collection performed by + the library functions malloc(), realloc() and free() costs a lot of + time, while in most cases (on a VAX) the freeing and reallocation of + memory is not necessary. + The (basic) memory allocating routines offered by this memory + handling package are: + + char *malloc(n) : allocate n bytes + char *realloc(ptr, n) : reallocate buffer to n bytes + (works only if ptr was last allocated) + free(ptr) : if ptr points to last allocated + memory, this memory is re-allocatable + + This module imports routines from "system", an assertion macro, + and the compile-time + constants ALIGNBITS, ALLOCSIZ, DEBUG. + ALIGNBITS is an integer constant defining suitable alignment, + ALLOCSIZ is the size of the chunks of memory asked from the system, + DEBUG enables the assertions. +*/ + +#include +#include + +#ifndef ALIGNBITS +#define ALIGNBITS 07 +#endif + +#ifndef ALLOCSIZ +#define ALLOCSIZ 4096 +#endif + +/* the following variables are used for book-keeping */ +static int nfreebytes = 0; /* # free bytes in sys_break-ed space */ +static char *freeb = 0; /* pointer to first free byte */ +static char *lastalloc; /* pointer to last malloced sp */ +static int lastnbytes; /* nr of bytes in last allocated space */ +static char *firstfreeb; /* pointer to first ever free byte */ + +#define ALIGN(m) (((m)&ALIGNBITS)? (m)+((1+ALIGNBITS)-((m)&ALIGNBITS)):(m)) + +char *sys_break(); + +char * +malloc(n) + unsigned int n; +{ + /* malloc() is a very simple malloc(). + */ + + n = ALIGN(n); + if (nfreebytes < n) { + register int nbts = (n <= ALLOCSIZ) ? ALLOCSIZ : n; + + if (!nfreebytes) { + if (!firstfreeb) { + /* We arrive here the first time malloc is + called + */ + int diff; + + if (!(freeb = sys_break(0))) return 0; + if ((diff = (int)((long)freeb&ALIGNBITS))!=0) { + /* align memory to ALIGNBITS ... */ + diff = (1 + ALIGNBITS) - diff; + if (!(freeb = sys_break(diff))) { + return 0; + } + freeb += diff; + assert(((long)freeb & ALIGNBITS) == 0); + } + firstfreeb = freeb; + } + if (!(freeb = sys_break(nbts))) return 0; + } + else { + if (!sys_break(nbts)) return 0; + } + nfreebytes += nbts; + } + lastalloc = freeb; + freeb = lastalloc + n; + lastnbytes = n; + nfreebytes -= n; + return lastalloc; +} + +char * +realloc(ptr, n) + char *ptr; + unsigned int n; +{ + /* realloc() is designed to append more bytes to the latest + allocated piece of memory. + */ + register int nbytes = n; + + if (!ptr || ptr != lastalloc) { /* security */ + return 0; + } + nbytes -= lastnbytes; /* # bytes required */ + if (nbytes == 0) { /* no extra bytes */ + return lastalloc; + } + + /* if nbytes < 0: free last allocated bytes; + if nbytes > 0: allocate more bytes + */ + if (nbytes > 0) nbytes = ALIGN(nbytes); + if (nfreebytes < nbytes) { + register int nbts = (nbytes < ALLOCSIZ) ? ALLOCSIZ : nbytes; + if (!sys_break(nbts)) return 0; + nfreebytes += nbts; + } + freeb += nbytes; /* less bytes */ + lastnbytes += nbytes; /* change nr of last all. bytes */ + nfreebytes -= nbytes; /* less or more free bytes */ + return lastalloc; +} + +free(p) + char *p; +{ + if (lastalloc && lastalloc == p) { + nfreebytes += lastnbytes; + freeb = lastalloc; + lastnbytes = 0; + lastalloc = 0; + } +} + +#ifdef DEBUG +mem_stat() +{ + + printf("Total nr of bytes allocated: %d\n", + sys_break(0) - firstfreeb); +} +#endif DEBUG From 2aaea46322644680bded5abf6b56a52e25bd2408 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 5 Jan 1987 14:44:25 +0000 Subject: [PATCH 0413/1625] Initial revision --- modules/src/alloc/Malloc.c | 59 ++++++++++++++++++++++++++++ modules/src/alloc/alloc.3 | 73 +++++++++++++++++++++++++++++++++++ modules/src/alloc/alloc.h | 23 +++++++++++ modules/src/alloc/botch.c | 20 ++++++++++ modules/src/alloc/clear.c | 23 +++++++++++ modules/src/alloc/in_all.h | 7 ++++ modules/src/alloc/st_alloc.c | 47 ++++++++++++++++++++++ modules/src/alloc/std_alloc.c | 38 ++++++++++++++++++ 8 files changed, 290 insertions(+) create mode 100644 modules/src/alloc/Malloc.c create mode 100644 modules/src/alloc/alloc.3 create mode 100644 modules/src/alloc/alloc.h create mode 100644 modules/src/alloc/botch.c create mode 100644 modules/src/alloc/clear.c create mode 100644 modules/src/alloc/in_all.h create mode 100644 modules/src/alloc/st_alloc.c create mode 100644 modules/src/alloc/std_alloc.c diff --git a/modules/src/alloc/Malloc.c b/modules/src/alloc/Malloc.c new file mode 100644 index 00000000..97b7cddf --- /dev/null +++ b/modules/src/alloc/Malloc.c @@ -0,0 +1,59 @@ +/* M E M O R Y A L L O C A T I O N R O U T I N E S */ + +/* The memory allocation routines offered in this file are: + + char *Malloc(n) : allocate n bytes + char *Srealloc(ptr, n) : reallocate buffer to n bytes + char *Salloc(str, n) : allocate n bytes, initialized with the string + str + + This file imports routines from "system". +*/ + +#include +#include "in_all.h" +#include "alloc.h" + +PRIVATE +m_fatal() { + + (void) sys_write(2, "Out of memory\n", 14); + sys_stop(S_EXIT); +} + +EXPORT char * +Malloc(sz) + unsigned int sz; +{ + char *res = malloc(sz); + + if (res == 0) m_fatal(); + return res; +} + +EXPORT char * +Salloc(str, sz) + register char str[]; + register unsigned int sz; +{ + /* Salloc() is not a primitive function: it just allocates a + piece of storage and copies a given string into it. + */ + char *res = malloc(sz); + register char *m = res; + + if (m == 0) m_fatal(); + while (sz--) + *m++ = *str++; + return res; +} + +EXPORT char * +Srealloc(str, sz) + char str[]; + unsigned int sz; +{ + str = realloc(str, sz); + if (str == 0) m_fatal(); + return str; +} diff --git a/modules/src/alloc/alloc.3 b/modules/src/alloc/alloc.3 new file mode 100644 index 00000000..3a71beb2 --- /dev/null +++ b/modules/src/alloc/alloc.3 @@ -0,0 +1,73 @@ +.TH ALLOC 3ACK "March 25, 1986" +.SH NAME +Malloc, Salloc, Srealloc, st_alloc, st_free\ \-\ low level memory allocation routines +.SH SYNOPSIS +.B #include +.PP +.B char *Malloc(size) +.br +.B unsigned int size; +.PP +.B char *Salloc(str, size) +.br +.B char *str; +.B unsigned int size; +.PP +.B char *Srealloc(str, size) +.br +.B char *str; +.br +.B unsigned int size; +.PP +.B char *st_alloc(phead, size, count) +.br +.B char **phead; +.br +.B unsigned int size; +.PP +.B st_free(ptr, phead, size) +.br +.B char *ptr; +.br +.B char **phead; +.br +.B unsigned int size; +.PP +.SH DESCRIPTION +This set of routines provides a checking memory allocation mechanism. +.PP +\fIMalloc\fR returns a pointer to a block of at least \fIsize\fR +bytes, beginning on a boundary suitable for any data type. +.PP +\fISalloc\fR returns a pointer to a block of at least \fIsize\fR +bytes, initialized with the null-terminated string \fIstr\fR. +.PP +\fISrealloc\fR reallocates +the string at \fIstr\fR to \fIsize\fR bytes. +.PP +All these routines use \fImalloc\fR and \fIrealloc\fR. +\fIFree\fR can be used on pointers returned by these routines. +.PP +\fISt_alloc\fR and \fIst_free\fR provide a mechanism for maintaining free lists +of structures, whose first field is a pointer called \fBnext\fR. +This field is used to chain free structures together. +\fISt_alloc\fR takes three parameters: \fIphead\fR is a pointer to a field +containing the head of the free list, \fIsize\fR contains the size of the +structures, and \fIcount\fR indicates how many new structures must be allocated +in case the free list is exhausted. +It returns a pointer to a zero-initialized structure. +\fISt_free\fR also takes three parameters: \fIptr\fR is a pointer to +the structure to be freed, \fIphead\fR is again a pointer to a field +containing the head of the free list, and \fIsize\fR again contains the size +of the structures. +These last two routines are best used in a macro. +.SH FILES +.nf +~em/modules/h/alloc.h +~em/modules/lib/liballoc.a +.fi +.SH "SEE ALSO" +malloc(3) +.SH DIAGNOSTICS +\fIMalloc\fR, \fISalloc\fR, \fISrealloc\fR, and \fIst_alloc\fR +give an error message and stop execution if there is no memory available. diff --git a/modules/src/alloc/alloc.h b/modules/src/alloc/alloc.h new file mode 100644 index 00000000..f872971a --- /dev/null +++ b/modules/src/alloc/alloc.h @@ -0,0 +1,23 @@ +/* PROGRAM'S INTERFACE TO MEMORY ALLOCATION ROUTINES */ + +/* This file serves as the interface between the program and the + memory allocating routines. + There are 3 memory allocation routines: + char *Malloc(n) allocate n bytes + char *Salloc(str, n) allocate n bytes and fill them with + string str + char *Realloc(str, n) reallocate the string at str to n bytes, + only works if str was last allocated +*/ + +extern char *Salloc(), *Malloc(), *Srealloc(); +extern char *malloc(), *realloc(); + +/* S T R U C T U R E - S T O R A G E D E F I N I T I O N S */ + +#ifndef BOTCH_FREE +#define st_free(ptr, phead, size) (ptr->next = *phead, *phead = ptr) +#else def BOTCH_FREE +#define st_free(ptr, phead, size) (botch((char *)(ptr), size), \ + ptr->next = *phead, *phead = ptr) +#endif BOTCH_FREE diff --git a/modules/src/alloc/botch.c b/modules/src/alloc/botch.c new file mode 100644 index 00000000..e163c286 --- /dev/null +++ b/modules/src/alloc/botch.c @@ -0,0 +1,20 @@ +/* botch - write garbage over a chunk of memory, useful if you want + to check if freed memory is used inappopriately. +*/ + +#include +#include "in_all.h" + +EXPORT +botch(ptr, n) + char *ptr; + int n; +{ + assert((long)ptr % sizeof (long) == 0); + while (n >= sizeof (long)) { + /* high-speed botch loop */ + *(long *)ptr = 025252525252L; + ptr += sizeof (long), n -= sizeof (long); + } + while (n--) *ptr++ = '\252'; +} diff --git a/modules/src/alloc/clear.c b/modules/src/alloc/clear.c new file mode 100644 index 00000000..ad8d6038 --- /dev/null +++ b/modules/src/alloc/clear.c @@ -0,0 +1,23 @@ +/* clear - clear a block of memory, and try to do it fast. +*/ + +#include +#include "in_all.h" + +/* instead of Calloc: */ +EXPORT +clear(ptr, n) + register char *ptr; + register int n; +{ + register long *q = (long *) ptr; + + assert((long)q % sizeof (long) == 0); + while (n >= sizeof (long)) { + /* high-speed clear loop */ + *q++ = 0; + n -= sizeof (long); + } + ptr = (char *) q; + while (n--) *ptr++ = '\0'; +} diff --git a/modules/src/alloc/in_all.h b/modules/src/alloc/in_all.h new file mode 100644 index 00000000..8850f61a --- /dev/null +++ b/modules/src/alloc/in_all.h @@ -0,0 +1,7 @@ +#ifdef DEBUG +#define PRIVATE +#else +#define PRIVATE static +#endif + +#define EXPORT diff --git a/modules/src/alloc/st_alloc.c b/modules/src/alloc/st_alloc.c new file mode 100644 index 00000000..434fa7c0 --- /dev/null +++ b/modules/src/alloc/st_alloc.c @@ -0,0 +1,47 @@ +/* st_alloc - get a structure from a free list. If no structures left, + create new ones. The structures for which this works are + supposed to have as their first tag the string "next", which + should be a pointer type. + The counterpart, st_free, is a macro, defined in alloc.h +*/ + +#include "alloc.h" + +struct xxx { + char *next; +}; + +char * +st_alloc(phead, size, count) + char **phead; + register unsigned int size; +{ + register char *p; + char *retval; + + if (*phead == 0) { + + p = Malloc(size * count); + ((struct xxx *) p)->next = 0; + while (--count) { + p += size; + ((struct xxx *) p)->next = p - size; + } + *phead = p; + } + else p = *phead; + *phead = ((struct xxx *)p)->next; + retval = p; + if (size >= sizeof(long)) { + register long *q = (long *) p; + do { + *q++ = 0; + size -= sizeof(long); + } while (size >= sizeof(long)); + + p = (char *) q; + } + + while (size--) *p++ = 0; + return retval; +} diff --git a/modules/src/alloc/std_alloc.c b/modules/src/alloc/std_alloc.c new file mode 100644 index 00000000..2f8697d0 --- /dev/null +++ b/modules/src/alloc/std_alloc.c @@ -0,0 +1,38 @@ +/* st_alloc - get a structure from a free list. If no structures left, + create new ones. The structures for which this works are + supposed to have as their first tag the string "next", which + should be a pointer type. + The counterpart, st_free, is a macro, defined in alloc.h +*/ + +#include "alloc.h" + +struct xxx { + char *next; +}; + +char * +std_alloc(phead, size, count, pcnt) + char **phead; + register unsigned int size; + int *pcnt; +{ + register char *p; + + if (*phead == 0) { + + p = Malloc(size * count); + *pcnt += count; + ((struct xxx *) p)->next = 0; + while (--count) { + p += size; + ((struct xxx *) p)->next = p - size; + } + *phead = p; + } + else p = *phead; + *phead = ((struct xxx *) p)->next; + p += size; + while (size--) *--p = 0; + return p; +} From 6390b1669e03afed3618a13570a7d9ad275043b2 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 5 Jan 1987 14:56:11 +0000 Subject: [PATCH 0414/1625] Initial revision --- modules/src/assert/assert.3 | 60 +++++++++++++++++++++++++++++++++++++ modules/src/assert/assert.h | 9 ++++++ 2 files changed, 69 insertions(+) create mode 100644 modules/src/assert/assert.3 create mode 100644 modules/src/assert/assert.h diff --git a/modules/src/assert/assert.3 b/modules/src/assert/assert.3 new file mode 100644 index 00000000..e5cdd60f --- /dev/null +++ b/modules/src/assert/assert.3 @@ -0,0 +1,60 @@ +.TH assert 3ACK "march 25, 1986" +.SH NAME +assert \- program verification +.SH SYNOPSIS +.B #include +.PP +.B assert(expression) +.PP +.B _BadAssertion(fn, lino, ass) +.br +char *fn, *ass; +.br +unsigned int lino; +.SH DESCRIPTION +.PP +.I Assert +is a macro that indicates +.I expression +is expected to be true at this point in the program. +It causes a call to +.I _BadAssertion +when +.I expression +is false (0). +.PP +The routine +.I_BadAssertion +accepts three parameters: +a filename, a linenumber, +and a string representing a failed assertion. +It causes a +.IR sys_stop (S_ABORT) +with a diagnostic comment on standard error. +.PP +The assertions are enabled by defining the preprocessor constant DEBUG. +.SH DIAGNOSTICS +.IR fn , +line +.IR lino : +assertion +.I ass +failed. +.br +.I fn +is the source file, +.I lino +is the source line number, +and +.I ass +is the assertion +of the +.I assert +statement. +.SH MODULES +system(3) +.SH FILES +.nf +~em/modules/h/assert.h +~em/modules/lib/libassert.a +.fi diff --git a/modules/src/assert/assert.h b/modules/src/assert/assert.h new file mode 100644 index 00000000..ca825817 --- /dev/null +++ b/modules/src/assert/assert.h @@ -0,0 +1,9 @@ +/* $Header$ */ +/* A S S E R T I O N M A C R O D E F I N I T I O N */ + +#ifdef DEBUG +/* Note: this macro uses parameter substitution inside strings */ +#define assert(exp) (exp || _BadAssertion(__FILE__, __LINE__, "exp")) +#else +#define assert(exp) (1) +#endif DEBUG From ad0cab046a9a380582f3d34e83b3c70c62ecb903 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 5 Jan 1987 17:20:13 +0000 Subject: [PATCH 0415/1625] Initial revision --- modules/src/em_mes/C_ms_com.c | 9 + modules/src/em_mes/C_ms_ego.c | 14 ++ modules/src/em_mes/C_ms_emx.c | 11 + modules/src/em_mes/C_ms_err.c | 8 + modules/src/em_mes/C_ms_flt.c | 8 + modules/src/em_mes/C_ms_gto.c | 8 + modules/src/em_mes/C_ms_opt.c | 8 + modules/src/em_mes/C_ms_par.c | 10 + modules/src/em_mes/C_ms_reg.c | 14 ++ modules/src/em_mes/C_ms_src.c | 12 + modules/src/em_mes/em_mes.3 | 146 ++++++++++++ modules/src/idf/Makefile | 17 ++ modules/src/idf/idf.3 | 88 +++++++ modules/src/idf/idf_pkg.body | 159 +++++++++++++ modules/src/idf/idf_pkg.spec | 42 ++++ modules/src/input/AtEoIF.c | 10 + modules/src/input/AtEoIT.c | 10 + modules/src/input/inp_pkg.body | 413 +++++++++++++++++++++++++++++++++ modules/src/input/inp_pkg.spec | 53 +++++ modules/src/input/input.3 | 140 +++++++++++ 20 files changed, 1180 insertions(+) create mode 100644 modules/src/em_mes/C_ms_com.c create mode 100644 modules/src/em_mes/C_ms_ego.c create mode 100644 modules/src/em_mes/C_ms_emx.c create mode 100644 modules/src/em_mes/C_ms_err.c create mode 100644 modules/src/em_mes/C_ms_flt.c create mode 100644 modules/src/em_mes/C_ms_gto.c create mode 100644 modules/src/em_mes/C_ms_opt.c create mode 100644 modules/src/em_mes/C_ms_par.c create mode 100644 modules/src/em_mes/C_ms_reg.c create mode 100644 modules/src/em_mes/C_ms_src.c create mode 100644 modules/src/em_mes/em_mes.3 create mode 100644 modules/src/idf/Makefile create mode 100644 modules/src/idf/idf.3 create mode 100644 modules/src/idf/idf_pkg.body create mode 100644 modules/src/idf/idf_pkg.spec create mode 100644 modules/src/input/AtEoIF.c create mode 100644 modules/src/input/AtEoIT.c create mode 100644 modules/src/input/inp_pkg.body create mode 100644 modules/src/input/inp_pkg.spec create mode 100644 modules/src/input/input.3 diff --git a/modules/src/em_mes/C_ms_com.c b/modules/src/em_mes/C_ms_com.c new file mode 100644 index 00000000..050d32c3 --- /dev/null +++ b/modules/src/em_mes/C_ms_com.c @@ -0,0 +1,9 @@ +#include +#include + +C_ms_com(str) + char *str; +{ + C_mes_begin(ms_com); + C_mes_end(); +} diff --git a/modules/src/em_mes/C_ms_ego.c b/modules/src/em_mes/C_ms_ego.c new file mode 100644 index 00000000..acd27c5f --- /dev/null +++ b/modules/src/em_mes/C_ms_ego.c @@ -0,0 +1,14 @@ +#include +#include + +C_ms_ego(hint, offs, siz, regno) + int hint, regno; + arith offs, siz; +{ + C_mes_begin(ms_ego); + C_cst((arith)hint); + C_cst(offs); + C_cst(siz); + C_cst((arith)regno); + C_mes_end(); +} diff --git a/modules/src/em_mes/C_ms_emx.c b/modules/src/em_mes/C_ms_emx.c new file mode 100644 index 00000000..f585bd29 --- /dev/null +++ b/modules/src/em_mes/C_ms_emx.c @@ -0,0 +1,11 @@ +#include +#include + +C_ms_emx(wsiz, psiz) + arith wsiz, psiz; +{ + C_mes_begin(ms_emx); + C_cst(wsiz); + C_cst(psiz); + C_mes_end(); +} diff --git a/modules/src/em_mes/C_ms_err.c b/modules/src/em_mes/C_ms_err.c new file mode 100644 index 00000000..037e78ac --- /dev/null +++ b/modules/src/em_mes/C_ms_err.c @@ -0,0 +1,8 @@ +#include +#include + +C_ms_err() +{ + C_mes_begin(ms_err); + C_mes_end(); +} diff --git a/modules/src/em_mes/C_ms_flt.c b/modules/src/em_mes/C_ms_flt.c new file mode 100644 index 00000000..4d63a820 --- /dev/null +++ b/modules/src/em_mes/C_ms_flt.c @@ -0,0 +1,8 @@ +#include +#include + +C_ms_flt() +{ + C_mes_begin(ms_flt); + C_mes_end(); +} diff --git a/modules/src/em_mes/C_ms_gto.c b/modules/src/em_mes/C_ms_gto.c new file mode 100644 index 00000000..d169cc1c --- /dev/null +++ b/modules/src/em_mes/C_ms_gto.c @@ -0,0 +1,8 @@ +#include +#include + +C_ms_gto() +{ + C_mes_begin(ms_gto); + C_mes_end(); +} diff --git a/modules/src/em_mes/C_ms_opt.c b/modules/src/em_mes/C_ms_opt.c new file mode 100644 index 00000000..097c2747 --- /dev/null +++ b/modules/src/em_mes/C_ms_opt.c @@ -0,0 +1,8 @@ +#include +#include + +C_ms_opt() +{ + C_mes_begin(ms_opt); + C_mes_end(); +} diff --git a/modules/src/em_mes/C_ms_par.c b/modules/src/em_mes/C_ms_par.c new file mode 100644 index 00000000..09e1640a --- /dev/null +++ b/modules/src/em_mes/C_ms_par.c @@ -0,0 +1,10 @@ +#include +#include + +C_ms_par(nparams) + arith nparams; +{ + C_mes_begin(ms_par); + C_cst(nparams); + C_mes_end(); +} diff --git a/modules/src/em_mes/C_ms_reg.c b/modules/src/em_mes/C_ms_reg.c new file mode 100644 index 00000000..9da6068c --- /dev/null +++ b/modules/src/em_mes/C_ms_reg.c @@ -0,0 +1,14 @@ +#include +#include + +C_ms_reg(offs, siz, class, prior) + arith offs, siz; + int class, prior; +{ + C_mes_begin(ms_reg); + C_cst(offs); + C_cst(siz); + C_cst((arith)class); + C_cst((arith)prior); + C_mes_end(); +} diff --git a/modules/src/em_mes/C_ms_src.c b/modules/src/em_mes/C_ms_src.c new file mode 100644 index 00000000..fb31239d --- /dev/null +++ b/modules/src/em_mes/C_ms_src.c @@ -0,0 +1,12 @@ +#include +#include + +C_ms_src(nlines, filnam) + int nlines; + char *filnam; +{ + C_mes_begin(ms_src); + C_cst((arith)nlines); + C_scon(filnam, strlen(filnam) + 1); + C_mes_end(); +} diff --git a/modules/src/em_mes/em_mes.3 b/modules/src/em_mes/em_mes.3 new file mode 100644 index 00000000..35630d82 --- /dev/null +++ b/modules/src/em_mes/em_mes.3 @@ -0,0 +1,146 @@ +.TH EM_MES 3ACK "86/03/18" +.SH NAME +em_mes \- EM-message generating routines +.SH SYNOPSIS +.nf +.B #include +.PP +.B C_ms_err() +.PP +.B C_ms_opt() +.PP +.B C_ms_emx(wsiz, psiz) +.B arith wsiz, psiz; +.PP +.B #include +.B C_ms_reg(offs, siz, class, prior) +.B arith offs, siz; +.B int class, prior; +.PP +.B C_ms_src(nlines, filnam) +.B int nlines; +.B char *filnam; +.PP +.B C_ms_flt() +.PP +.B C_ms_com(str) +.B char *str; +.PP +.B C_ms_par(nparams) +.B arith nparams; +.PP +.B #include +.B C_ms_ego(hint, offs, siz, regno) +.B int hint, regno; +.B arith offs, siz; +.PP +.B C_ms_gto() +.fi +.SH DESCRIPTION +This set of routines forms a front end for the +.IR em_code (3L) +module. +The philosophy behind this package is to provide a single routine for +each type of EM message that is generated by a front-end compiler. +Each routine internally builds a message instruction by using the +.BR C_mes_begin , +.B C_mes_end +and the +.BI C_ cstp +routines from the +.I em_code +module. +The actions taken by these functions depend on the type of +.I em_code +module that is loaded together with this module. +The routines described here do not prevent the user from directly +composing EM messages himself. +.PP +.BR C_ms_err () +generates a message that indicates some error during the compilation. +.PP +.BR C_ms_opt () +causes any optimization to be suppressed. +.PP +.BR C_ms_emx () +indicates the wordsize +.I wsiz +and pointersize +.IR psiz . +This must be the first code generated, or the generated code is illegal. +.PP +.BR C_ms_reg () +can be used to indicate that a local variable, having offset +.I offs +and size (in bytes) +.IR siz , +may be stored in a register. +.I Class +indicates the use of the variable. +The following classes are allowed (the names are defined in em_reg.h): +.RS +.IP reg_any 12 +no specific type +.IP reg_loop 12 +loop control variable +.IP reg_pointer 12 +pointer variable +.IP reg_float 12 +floating point variable +.LP +.RE +.I Prior +is taken to be the priority of the variable; higher numbers indicate +better candidates. +.PP +.BR C_ms_src () +produces an indication of the number of source lines, +.IR nlines , +in file +.IR filnam . +This information can be used by a profiler. +.PP +.BR C_ms_flt () +produces an indication that floating-point operations are used. +.PP +.BR C_ms_com () +causes the string +.I str +to be inserted as comment in the resulting output. +Note that this routine does not provide the full semantics of EM in this +area, but the user himself can build a comment message with other types +of comment if he likes. +.PP +.BR C_ms_par () +produces an indication that no more than +.I nbytes +of parameters are accessed, either directly or indirectly. +.PP +.BR C_ms_ego () +produces a hint from the EM global optimizer. +The parameters needed are conform to the format of the message. +.PP +.BR C_ms_gto () +can be invoked to indicate that a procedure uses a non-local goto. +.SH FILES +.nf +~em/modules/h/em.h +~em/h/em_reg.h +~em/h/em_ego.h +~em/modules/lib/libem_mes.a +.fi +.SH MODULES +em_code(3) +.SH SEE ALSO +em_code(3), read_em(3) +.SH DIAGNOSTICS +None of the functions return a value. +.SH BUGS +The +.BR C_ms_ext () +routine has not yet been implemented, since this message uses +a variable number of arguments. +.PP +Please report other bugs to the author. +.SH AUTHOR +Erik Baalbergen diff --git a/modules/src/idf/Makefile b/modules/src/idf/Makefile new file mode 100644 index 00000000..9725feeb --- /dev/null +++ b/modules/src/idf/Makefile @@ -0,0 +1,17 @@ +EMHOME = ../../.. +INSTALL = $(EMHOME)/modules/install +COMPARE = $(EMHOME)/modules/compare + +all: + +install: all + $(INSTALL) pkg/idf_pkg.body + $(INSTALL) pkg/idf_pkg.spec + $(INSTALL) man/idf.3 + +cmp: all + $(COMPARE) pkg/idf_pkg.body + $(COMPARE) pkg/idf_pkg.spec + $(COMPARE) man/idf.3 + +clean: diff --git a/modules/src/idf/idf.3 b/modules/src/idf/idf.3 new file mode 100644 index 00000000..eb2ff5fb --- /dev/null +++ b/modules/src/idf/idf.3 @@ -0,0 +1,88 @@ +.TH IDF 3ACK "March 17, 1986" +.UC +.SH NAME +init_idf, str2idf\ \-\ a namelist module +.SH SYNOPSIS +.PP +.B init_idf() +.PP +.B struct idf *str2idf(tag, cpy) +.br +.B char *tag; +.PP +.B struct idf *findidf(tag) +.br +.B char *tag; +.SH DESCRIPTION +This is a generic namelist module. It provides a fast mechanism for +associating information with identifiers. To get an instantiation, the +user must provide two files \fIidf.h\fR and \fIidf.c\fR. +\fIidf.h\fR could contain the following: +.br +.PP +.RS +.nf +#define IDF_TYPE struct id_info +#define IDF_HSIZE 8 + +#include +.fi +.RE +.PP +and \fIidf.c\fR could contain: +.br +.PP +.RS +.nf +#include "id_info.h" /* contains definition for struct id_info */ +#include "idf.h" +#include +.fi +.RE +.PP +IDF_TYPE denotes a type containing all information associated with +an identifier. If it is not defined, the instantiation will not contain +any user-defined information. +.PP +IDF_HSIZE denotes the number of significant characters for the hashing +function. It's default value is 64. Notice that this value does \fBnot\fP +denote the number of significant characters, but only the number of characters +that are used for hashing. +.PP +The user can also define IDF_NAME, to give a name to the selector in the +idf-structure. It's default value is \fIid_user\fP. +.PP +The routine \fIinit_idf\fR initializes the namelist. +.PP +The function +\fIstr2idf\fR searches for the string \fItag\fR in the namelist, and +creates an entry for it if necessary. A pointer to this entry is +returned. If \fIcpy\fR is non-zero, a copy of the \fItag\fR is made, +otherwise the \fItag\fR itself is used. +The entry has the following structure, defined in \fIinp_pkg.spec\fR: +.PP +.nf +struct idf { + struct idf *next; \kx/* links idf-structures together */ + char *id_text;\h'|\nxu'/* string representing the name */ +#ifdef IDF_TYPE + IDF_TYPE IDF_NAME;\h'|\nxu'/* user defined type */ +#endif +}; +.fi +.PP +The field \fIid_text\fR will point to a copy of \fItag\fR, or +to the \fItag\fR itself, depending on \fIcpy\fR. +The field \fInext\fR is used for internal information and must not +be changed by the user of this module. +.PP +The function \fIfindidf\fP searches for the string \fItag\fP in the +namelist, but returns 0 when it is'nt present. +.SH "MODULES USED" +alloc(3) +.SH FILES +~em/modules/pkg/idf_pkg.spec +.br +~em/modules/pkg/idf_pkg.body +.SH DIAGNOSTICS +\fIstr2idf\fP returns a null pointer if there is no memory available. diff --git a/modules/src/idf/idf_pkg.body b/modules/src/idf/idf_pkg.body new file mode 100644 index 00000000..3fd6757a --- /dev/null +++ b/modules/src/idf/idf_pkg.body @@ -0,0 +1,159 @@ +/* SYMBOL TABLE HANDLING */ + +#include + +/* Each character of the identifier is xored with an 8-bit mask which + depends on the position of the character; the sum of these results + is the hash value. The random masks are obtained from a + congruence generator. +*/ + +#define HASHSIZE 256 /* size of hashtable, must be a power of 2 */ +#ifndef IDF_HSIZE +#define IDF_HSIZE 64 /* # of significant characters for hashing. + This is NOT the number of significant + characters! + */ +#endif +#define HASH_X 0253 /* Knuth's X */ +#define HASH_A 77 /* Knuth's a */ +#define HASH_C 153 /* Knuth's c */ + +#define HASHMASK (HASHSIZE-1) /* since it is a power of 2 */ +#define STARTHASH() (0) +#define ENHASH(hs,ch,hm) (hs + (ch ^ hm)) +#define STOPHASH(hs) (hs & HASHMASK) + +static char hmask[IDF_HSIZE]; + +static struct idf *id_hashtable[HASHSIZE]; + /* All identifiers can in principle be reached through + id_hashtable; id_hashtable[hc] is the start of a chain of + idf's whose tags all hash to hc. + Any identifier is entered into this + list, regardless of the nature of its declaration + (variable, selector, structure tag, etc.). + */ + +static struct idf * +new_idf(tg, size, cpy) + register char *tg; + register int size; +{ + static int nidf; + static struct idf *pidf; +#define NIDS 50 +#define IBUFSIZ 2048 + static unsigned int icnt; + static char *ip; + register char *p; + + + if (! nidf--) { + nidf += NIDS; + pidf = (struct idf *) Malloc(NIDS * sizeof (struct idf)); + clear((char *) pidf, NIDS * sizeof(struct idf)); + } + + if (cpy) { + if (size > icnt) { + icnt = size > IBUFSIZ ? size : IBUFSIZ; + p = Malloc(icnt); + } + else p = ip; + icnt -= size; + pidf->id_text = p; + while (size--) { + *p++ = *tg++; + } + ip = p; + } + else pidf->id_text = tg; + return pidf++; +} + +#ifdef DEBUG +hash_stat() +{ + register int i; + + print("Hash table tally:\n"); + for (i = 0; i < HASHSIZE; i++) { + register struct idf *notch = id_hashtable[i]; + register int cnt = 0; + + while (notch) { + cnt++; + notch = notch->next; + } + print("%d %d\n", i, cnt); + } + print("End hash table tally\n"); +} +#endif DEBUG + +struct idf * +str2idf(tg, cpy) + char tg[]; +{ + /* str2idf() returns an entry in the symbol table for the + identifier tg. If necessary, an entry is created. + */ + register char *cp = tg; + register char *phm = &hmask[0]; + struct idf **hook; + register struct idf *notch; + register int hash; + int size; + + hash = STARTHASH(); + while (*cp && phm < &hmask[IDF_HSIZE]) { + hash = ENHASH(hash, *cp++, *phm++); + } + hash = STOPHASH(hash); + while (*cp++) /* nothing. Find end of string */ ; + size = cp - tg; + + /* The tag tg with length size and known hash value hash is + looked up in the identifier table; if not found, it is + entered if cpy >= 0. A pointer to it is returned. + Notice that the chains of idf's are sorted alphabetically. + */ + hook = &id_hashtable[hash]; + + while ((notch = *hook)) { + register char *s1 = tg; + int cmp; + + cp = notch->id_text; + + while (!(cmp = (*s1 - *cp++))) { + if (*s1++ == '\0') { + break; + } + } + + if (cmp == 0) return notch; + if (cmp < 0) break; + hook = ¬ch->next; + } + /* a new struct idf must be inserted at the hook */ + if (cpy < 0) return 0; + notch = new_idf(tg, size, cpy); + notch->next = *hook; + *hook = notch; /* hooked in */ + return notch; +} + +init_idf() { + /* A simple congruence random number generator, as + described in Knuth, vol 2. + */ + int rnd = HASH_X; + register char *phm; + + for (phm = &hmask[0]; phm < &hmask[IDF_HSIZE];) { + *phm++ = rnd; + rnd = (HASH_A * rnd + HASH_C) & HASHMASK; + } +} diff --git a/modules/src/idf/idf_pkg.spec b/modules/src/idf/idf_pkg.spec new file mode 100644 index 00000000..95e66115 --- /dev/null +++ b/modules/src/idf/idf_pkg.spec @@ -0,0 +1,42 @@ +/* $Header$ */ +/* IDENTIFIER DESCRIPTOR */ + +/* This a generic package for maintaining a name list */ + +/* Instantiation parameters, supplied by #define, are : + IDF_TYPE: the type of the user-defined part of the idf-structure, + IDF_NAME: the selector name for this field in the idf_structure, and + IDF_HSIZE: the number of significant characters for hashing +*/ + +#ifndef IDF_NAME +#define IDF_NAME id_user +#endif + +struct idf { + struct idf *next; /* links idf-structures together */ + char *id_text; /* string representing the name */ +#ifdef IDF_TYPE + IDF_TYPE IDF_NAME; /* user defined type and selector */ +#endif +}; + +/* init_idf() + + Initializes the namelist +*/ +extern init_idf(); + +/* struct idf * str2idf(tg, cp) + char *tg; + int cp; + + Adds the string indicated by "tg" to the namelist, and returns a + pointer to the entry. + If cp > 0, a copy of tg is made for id_text, otherwise tg itself + is used. + If cp < 0, the string is not entered, but only looked for. +*/ +extern struct idf * str2idf(); + +#define findidf(tg) str2idf(tg, -1) diff --git a/modules/src/input/AtEoIF.c b/modules/src/input/AtEoIF.c new file mode 100644 index 00000000..7136fcf2 --- /dev/null +++ b/modules/src/input/AtEoIF.c @@ -0,0 +1,10 @@ +/* $Header$ */ + +/* AtEoIF : a routine doing nothing. It is called at the end of an + inserted file. +*/ +int +AtEoIF() +{ + return 0; +} diff --git a/modules/src/input/AtEoIT.c b/modules/src/input/AtEoIT.c new file mode 100644 index 00000000..ceabdebb --- /dev/null +++ b/modules/src/input/AtEoIT.c @@ -0,0 +1,10 @@ +/* $Header$ */ + +/* AtEoIT : a routine doing nothing. It is called at the end of an + inserted text. +*/ +int +AtEoIT() +{ + return 0; +} diff --git a/modules/src/input/inp_pkg.body b/modules/src/input/inp_pkg.body new file mode 100644 index 00000000..c0d519f0 --- /dev/null +++ b/modules/src/input/inp_pkg.body @@ -0,0 +1,413 @@ +/* INPUT AND BUFFER HANDLING MODULE */ + +/* + [input.X inp_pkg.spec input.h] + Input buffering module: this module contains the routines that + offers an input buffering mechanism to the user. + + This module exports the following objects: + input.h : an include-file, which must be included when using + this module + InsertFile() : suspend input from current buffer and obtain the + next input characters from the specified file + InsertText() : suspend input from current buffer and take the + specified text as stream of input characters + LoadChar() : (defined in input.h) read next character from + the input ; LoadChar() invokes loadbuf() on + encounting a ASCII NUL character + PushBack() : (defined in input.h) push last character back onto + the input stream; NPUSHBACK characters of pushback + are guaranteed, provided that they have all been read + from the current input stream + AtEoIT() : this routine is called at the end of an inserted text. + A default one is provided, which does nothing. + AtEoIF() : this routine is called at the end of an inserted file. + A default one is provided, which does nothing. + + Imported objects are: + INP_NPUSHBACK, INP_READ_IN_ONE, INP_TYPE, INP_VAR, + routines from the "alloc" package, routines from the "storage" + package, and routines from the "system" package. + + INP_READ_IN_ONE defined: every input file is read into memory completely + and made an input buffer. Only use it if the size of a file + fits always fits in an integer and you have lots of memory. + INP_READ_IN_ONE not defined: the input from files is buffered in + a fixed length input buffer + INP_NPUSHBACK: the number of characters pushback +*/ + +#include +#include + +#ifndef INP_NPUSHBACK +#define INP_NPUSHBACK 1 +#endif + +#if INP_NPUSHBACK < 1 +#define INP_NPUSHBACK 1 +#endif + +#ifndef INP_BUFSIZE +#define INP_BUFSIZE BUFSIZ +#endif + +#if INP_NPUSHBACK > INP_BUFSIZE/2 +Now this is really ridiculous! You deserve what you get!! +#endif + +#ifdef INP_TYPE +extern INP_TYPE INP_VAR; +#endif INP_TYPE + +#ifdef DEBUG +#define PRIVATE +#else +#define PRIVATE static +#endif + +struct buffer_header { + struct buffer_header *next; + int bh_size; /* = strlen (text), should be unsigned */ + char *bh_text; /* pointer to buffer containing text */ + char *bh_ipp; /* current read pointer (= stacked ipp) */ +#ifdef INP_TYPE + INP_TYPE bh_i; /* user defined */ +#endif INP_TYPE + File *bh_fd; /* A file descriptor in case of a file */ + char bh_eofreturned; /* set if we returned eof for this buffer */ +}; + +#ifndef INP_READ_IN_ONE +struct i_buf { + struct i_buf *next; + char ib_text[INP_BUFSIZE+INP_NPUSHBACK-1]; +}; + +# endif not INP_READ_IN_ONE + +char *_ipp; +PRIVATE struct buffer_header *head; + +#ifdef INP_READ_IN_ONE +/* readfile() creates a buffer in which the text of the file + is situated. A pointer to the start of this text is + returned. *size is initialized with the buffer length. +*/ + +PRIVATE int +readfile(fd, fn, size, pbuf) + register File *fd; + char *fn; /* file name */ + register long *size; + extern long sys_filesize(); + char **pbuf; /* output parameter */ +{ + int rsize; + + if ( + (*size = sys_filesize(fn)) < 0 + || + ((unsigned) (*size + 1) != (*size + 1)) + || + !(*pbuf = malloc((unsigned) (*size + 1)))) { + sys_close(fd); + return 0; + } + if ( + !sys_read(fd, *pbuf, (int) *size, &rsize) + || + *size != rsize + ) { + sys_close(fd); + free(*pbuf); + return 0; + } + sys_close(fd); + (*pbuf)[*size] = '\0'; /* invoke loadbuf() at end */ + return 1; +} +#endif INP_READ_IN_ONE + +#ifndef INP_READ_IN_ONE +/* Input buffer supplying routines: pushbuf() +*/ + +PRIVATE struct i_buf *i_ptr; + +PRIVATE char * +pushbuf() +{ + register struct i_buf *ib = + (struct i_buf *) malloc(sizeof(struct i_buf)); + + if (!ib) return 0; + ib->next = i_ptr; + i_ptr = ib; + + /* Don't give him all of it, we need some to implement a good + PushBack + */ + return &(ib->ib_text[INP_NPUSHBACK-1]); +} +#endif not INP_READ_IN_ONE + +/* Input buffer administration: push_bh() and pop_bh() +*/ +PRIVATE struct buffer_header * +push_bh() +{ + register struct buffer_header *bh; + + if (bh = head) { + bh->bh_ipp = _ipp; +#ifdef INP_TYPE + bh->bh_i = INP_VAR; +#endif INP_TYPE + } + if (!(bh = (struct buffer_header *)malloc(sizeof(struct buffer_header)))) return 0; + bh->next = head; + bh->bh_eofreturned = 0; + head = bh; + return bh; +} + +/* pop_bh() uncovers the previous inputbuffer on the stack + of headers. 0 is returned if there are no more + inputbuffers on the stack, 1 is returned in the other case. +*/ +PRIVATE int +pop_bh() +{ + register struct buffer_header *bh = head; + + if (bh->bh_fd) { /* unstack a file */ +#ifndef INP_READ_IN_ONE + struct i_buf *ib; + + ib = i_ptr->next; + free((char *) i_ptr); + i_ptr = ib; +#else INP_READ_IN_ONE + free(bh->bh_text); +#endif INP_READ_IN_ONE + } + + bh = bh->next; + free((char *) head); + head = bh; + + if (!bh) { /* no more entries */ + head = (struct buffer_header *) 0; + return 0; + } + + _ipp = bh->bh_ipp; /* restore previous input pointer */ +#ifdef INP_TYPE + INP_VAR = bh->bh_i; +#endif INP_TYPE + + return 1; +} + +#ifndef INP_READ_IN_ONE +/* low level I/O routine : read one block from current input + stream : readblock +*/ + +PRIVATE int +readblock(fd, buf, n) + File *fd; + char buf[]; + int *n; +{ + + if (!sys_read(fd, buf, INP_BUFSIZE, n)) { + return 0; + } + buf[*n] = '\0'; + return 1; +} +#endif not INP_READ_IN_ONE + +/* Miscellaneous routines : + mk_filename() +*/ + +/* mk_filename() concatenates a dir and filename. +*/ +PRIVATE int +mk_filename(dir, file, newname) + register char *dir, *file; + char **newname; +{ + + register char *dst; + + dst = malloc((unsigned) (strlen(dir) + strlen(file) + 2)); + if (!dst) return 0; + *newname = dst; + while (*dst++ = *dir++); + *--dst = '/'; + while (*++dst = *file++); + return 1; +} + +/* Interface routines : InsertFile, InsertText, and loadbuf +*/ + +int +InsertFile(filnam, table, result) + char *filnam; + char *table[]; + char **result; +{ + char *newfn = 0; + +#ifdef INP_READ_IN_ONE + char *text; + long size; +#endif INP_READ_IN_ONE + File *fd = 0; + + if (!filnam) fd = STDIN; + else { + if (table == 0 || filnam[0] == '/') { + /* don't look in the table! */ + if (!sys_open(filnam, OP_READ, &fd)) return 0; + } + else { + while (*table) { + /* look in the directory table */ + if (!mk_filename(*table++, filnam, &newfn)) { + return 0; + } + if (sys_open(newfn, OP_READ, &fd)) { + /* free filnam ??? NO we don't know + where it comes from! + */ + filnam = newfn; + break; + } + free(newfn); + newfn = 0; + } + } + } + + if (fd) { + struct buffer_header *push_bh(); + register struct buffer_header *bh = push_bh(); + + if (!bh) { + if (fd != STDIN) sys_close(fd); + return 0; + } +#ifdef INP_READ_IN_ONE + if (fd == STDIN) return 0; /* illegal */ + if (!readfile(fd, filnam, &size, &text)) { + sys_close(fd); + return 0; + } + bh->bh_size = size; + _ipp = bh->bh_text = text; +#else not INP_READ_IN_ONE + if ( + !(_ipp = bh->bh_text = pushbuf()) + || + !readblock(fd,_ipp,&(bh->bh_size))) { + if (fd != STDIN) sys_close(fd); + return 0; + } +#endif INP_READ_IN_ONE + bh->bh_fd = fd; /* this is a file */ + *result = filnam; + return 1; + } + return 0; +} + +int +InsertText(text, length) + char *text; +{ + struct buffer_header *push_bh(); + register struct buffer_header *bh = push_bh(); + + if (!bh) return 0; + bh->bh_size = (long) length; + _ipp = bh->bh_text = text; + bh->bh_fd = 0; /* No file! */ + return 1; +} + +/* loadbuf() is called if LoadChar meets a '\0' character + which may be the end-of-buffer mark of the current input + buffer. The '\0' could be genuine although not likely. + Note: this routine is exported due to its occurence in the definition + of LoadChar [input.h], that is defined as a macro. +*/ +int +loadbuf() +{ + register struct buffer_header *bh = head; + static char buf[INP_NPUSHBACK + 1]; + int FromFile; + + if (!bh) { /* stack exhausted, EOF on sourcefile */ + return EOI; + } + + if (_ipp < &(bh->bh_text[bh->bh_size])) { + /* a genuine '\0' character has been seen */ + return '\0'; + } + + FromFile = (bh->bh_fd != 0); + +#ifndef INP_READ_IN_ONE + if (FromFile) { +#if INP_PUSHBACK > 1 + register char *so = &(bh->bh_text[bh->bh_size]); + register char *de = bh->bh_text; + register int i = INP_NPUSHBACK - 1; + + while (i-- > 0) { + /* make sure PushBack will work */ + *--de = *--so; + } +#endif + if ( + readblock(bh->bh_fd, bh->bh_text, &(bh->bh_size)) + && + bh->bh_size > 0 + ) { + _ipp = bh->bh_text; + return *_ipp++; + } + } + +#endif not INP_READ_IN_ONE + + if (!bh->bh_eofreturned) { + bh->bh_eofreturned = 1; + _ipp--; + if (FromFile) { + if (AtEoIF()) return EOI; + } + else { + if (AtEoIT()) return EOI; + } + } + +#ifndef INP_READ_IN_ONE + if (FromFile && bh->bh_fd != STDIN) sys_close(bh->bh_fd); +#endif not INP_READ_IN_ONE + + if (pop_bh()) { + if (*_ipp) return *_ipp++; + return loadbuf(); + } + _ipp = &buf[INP_NPUSHBACK]; + return EOI; +} diff --git a/modules/src/input/inp_pkg.spec b/modules/src/input/inp_pkg.spec new file mode 100644 index 00000000..69c2248e --- /dev/null +++ b/modules/src/input/inp_pkg.spec @@ -0,0 +1,53 @@ +/* This is the specification of the generic part of the input package. + It can be instantiated by #defining or not #defining + INP_TYPE, INP_VAR, INP_READ_IN_ONE, and INP_NPUSHBACK. + INP_TYPE is the type of the variable INP_VAR, which contains + all values the user wants to save when an InsertFile is done, + and restored when an input stream is continued after a suspend. + For instance, line numbers and position within a line might + be interesting. + Not defining INP_TYPE has the effect that the instantiation is + done without saving and restoring INP_VAR. + Defining INP_READ_IN_ONE has the effect that files will be read + completely with one "read". Only use this if you have lots of + memory. Not defining it causes files to be read in blocks, with + a suitable blocksize. + INP_NPUSHBACK is the number of PushBacks that are guaranteed + to work. Its default value is 1. +*/ + +/* INPUT PRIMITIVES */ + +#define LoadChar(dest) ((dest = *_ipp++) || (dest = loadbuf())) +#define PushBack() (--_ipp) + +/* EOF may be defined as -1 in most programs but the character -1 may + be expanded to the int -1 which causes troubles at the indexing in + the class or boolean arrays. +*/ +#define EOI (0200) + +extern char *_ipp; + +/* int InsertFile(filename, table, result) + char *filename; + char **table; + char **result; + + This function suspends input from the current input stream. The next + characters are obtained from the file indicated by "filename". This file + will be looked for in the directories, mentioned in the null-terminated + list indicated by "table". It returns 1 if it succeeds, 0 if it fails. + "result" will contain the full path if InsertFile returns 1. +*/ +extern int InsertFile(); + +/* int InsertText(text, length) + char *text; + int length; + This funtion suspends input from the current input stream. The next + input characters are obtained from the string indicated by "text", + whose length is indicated by "length". + It returns 1 if it succeeds, 0 if it fails. +*/ +extern int InsertText(); diff --git a/modules/src/input/input.3 b/modules/src/input/input.3 new file mode 100644 index 00000000..82a6f452 --- /dev/null +++ b/modules/src/input/input.3 @@ -0,0 +1,140 @@ +.TH INPUT 3 "March 25, 1986" +.SH NAME +LoadChar, PushBack, InsertFile, InsertText, AtEoIF, AtEoIT\ \-\ input +module for compilers +.SH SYNOPSIS +.B LoadChar(ch) +.br +.B int ch; +.PP +.B PushBack() +.PP +.B int InsertFile(filename, table, result) +.br +.B char *filename; +.br +.B char *table[]; +.br +.B char **result; +.PP +.B int InsertText(text, length) +.br +.B char *text; +.br +.B int length; +.PP +.B int AtEoIF() +.PP +.B int AtEoIT() +.SH DESCRIPTION +This set of variables, macros and routines provides a fast input mechanism +for use by compilers. +They also provide a means of inserting new input streams, +thereby temporarily suspending an input +stream to read another one. +The \fBcurrent input stream\fR is the last inserted input stream that +has not reached its end. +.PP +The module is generic: it must be instantiated by #defining INP_TYPE, +INP_VAR, INP_READ_IN_ONE, INP_BUFSIZE, and INP_NPUSHBACK. +An instantiation can be obtained by creating two files: \fIinput.c\fR and +\fIinput.h\fR. +\fIinput.h\fR could contain the following: +.PP +.RS +.nf +#define INP_NPUSHBACK 2 +#define INP_TYPE struct f_info +#define INP_VAR file_info +#define INP_BUFSIZE 4096 + +#include +.fi +.RE +.PP +and \fIinput.c\fR could contain: +.PP +.RS +.nf +#include "f_info.h" /* contains definition for struct f_info */ +#include "input.h" +#include +.fi +.RE +.PP +The user may associate certain data with each input stream. The input module +has a facility to save these data when inserting a new input stream, and +restoring them when restoring the suspended input stream. Examples of these +data are for instance a linenumber, a filename, etc. +These data must be collected in a variable INP_VAR of type INP_TYPE. +INP_VAR and INP_TYPE must be preprocessor-#defined. +Not #defining INP_TYPE has the effect that an instantiation will be created +that does not save and restore these data. +.PP +INP_NPUSHBACK is the number of PushBacks that are guaranteed to work. +Its default value is 1. It is expected to be small. +.PP +INP_READ_IN_ONE can either be defined or not defined. Defining it has the +effect that files will be read completely with one read-system call. This +should only be used on machines with lots of memory. +.PP +INP_BUFSIZE defines the input buffer size that is used when INP_READ_IN_ONE +is not defined. Its default value is BUFSIZ, from the \fIsystem\fP(3) module. +.PP +The macro \fILoadChar\fR stores the next character from the current input stream +in the variable \fIch\fR, +which is passed as a parameter. +Note that this simulates an output parameter! +When the end of the current input stream is reached, the next character from +the last suspended input stream will be stored, etc. +If there are no suspended input streams left, the constant EOI, +which is defined in \fIinp_pkg.spec\fR, is returned. +.PP +The macro \fIPushBack\fR pushes the last character read back onto the +input stream. +.PP +The routine \fIInsertFile\fR suspends input from the current input stream. +The next input characters will be obtained from the specified file +\fIfilename\fR. +This file will be looked for in the directories, mentioned in the +null-terminated list \fItable\fR. +If \fIfilename\fR is a null pointer, standard input is used. In this case, +the package may not have been instantiated with INP_READ_IN_ONE defined. +\fIInsertFile\fR returns 1 if it succeeds, 0 if it fails. +When it succeeds, it stores the file name in the \fIresult\fR parameter. +.PP +The routine \fIInsertText\fR also suspends input from the current input stream. +The next input characters will be obtained from the string \fItext\fR, +which is \fIlength\fR characters long. +\fIInsertText\fR returns 1 if it succeeds, 0 if it fails. +.PP +The routine \fIAtEoIF\fR is called at the end of the input stream +inserted by \fIInsertFile\fR. +If it returns 1, the LoadChar causing the call returns EOI, otherwize +the LoadChar returns the next character of the suspended and now restored +input stream. +A default \fIAtEoIF\fR is provided. It does nothing, and returns 0, +making the "unstacking" completely transparent. +The user of the module can write his own if this is not what he wants. +.PP +The routine \fIAtEoIT\fR is called at the end of the string +inserted by \fIInsertText\fR. +If it returns 1, the LoadChar causing the call returns EOI, otherwise +the LoadChar returns the next character of the suspended and now restored +input stream. +A default \fIAtEoIT\fR is provided. It does nothing, and returns 0, +making the "unstacking" completely transparent. +The user of the module can write his own if this is not what he wants. +.SH FILES +~em/modules/pkg/inp_pkg.spec +.br +~em/modules/pkg/inp_pkg.body +.br +~em/modules/lib/libinput.a +.SH MODULES +system(3), alloc(3) +.SH "SEE ALSO" +\fIGeneric Packages in C\fR by Dick Grune. +.SH BUGS +A \fILoadChar\fR-call does look like a function call, +but behaves differently. All for the sake of speed of course ... From 76d4ac5194f7e817efcf7e41fee8b79ae40a21fb Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 5 Jan 1987 17:31:38 +0000 Subject: [PATCH 0416/1625] Initial revision --- modules/src/object/Makefile | 60 ++++++ modules/src/object/byte_order.c | 49 +++++ modules/src/object/object.3 | 287 +++++++++++++++++++++++++++++ modules/src/object/object.h | 30 +++ modules/src/object/rd.c | 237 ++++++++++++++++++++++++ modules/src/object/rd_arhdr.c | 29 +++ modules/src/object/rd_bytes.c | 22 +++ modules/src/object/rd_int2.c | 10 + modules/src/object/rd_long.c | 10 + modules/src/object/rd_ranlib.c | 21 +++ modules/src/object/rd_unsig2.c | 10 + modules/src/object/wr.c | 314 ++++++++++++++++++++++++++++++++ modules/src/object/wr_arhdr.c | 29 +++ modules/src/object/wr_bytes.c | 20 ++ modules/src/object/wr_int2.c | 9 + modules/src/object/wr_long.c | 10 + modules/src/object/wr_putc.c | 15 ++ modules/src/object/wr_ranlib.c | 31 ++++ 18 files changed, 1193 insertions(+) create mode 100644 modules/src/object/Makefile create mode 100644 modules/src/object/byte_order.c create mode 100644 modules/src/object/object.3 create mode 100644 modules/src/object/object.h create mode 100644 modules/src/object/rd.c create mode 100644 modules/src/object/rd_arhdr.c create mode 100644 modules/src/object/rd_bytes.c create mode 100644 modules/src/object/rd_int2.c create mode 100644 modules/src/object/rd_long.c create mode 100644 modules/src/object/rd_ranlib.c create mode 100644 modules/src/object/rd_unsig2.c create mode 100644 modules/src/object/wr.c create mode 100644 modules/src/object/wr_arhdr.c create mode 100644 modules/src/object/wr_bytes.c create mode 100644 modules/src/object/wr_int2.c create mode 100644 modules/src/object/wr_long.c create mode 100644 modules/src/object/wr_putc.c create mode 100644 modules/src/object/wr_ranlib.c diff --git a/modules/src/object/Makefile b/modules/src/object/Makefile new file mode 100644 index 00000000..88f84776 --- /dev/null +++ b/modules/src/object/Makefile @@ -0,0 +1,60 @@ +EMHOME = ../../.. +MODULES = $(EMHOME)/modules +INSTALL = $(MODULES)/install +COMPARE = $(MODULES)/compare +CFLAGS = -O -I$(EMHOME)/h +CFILES = rd_arhdr.c wr_arhdr.c \ + rd_ranlib.c wr_ranlib.c \ + rd_bytes.c wr_bytes.c \ + rd.c wr.c \ + wr_putc.c \ + rd_int2.c wr_int2.c \ + rd_unsig2.c \ + rd_long.c wr_long.c +# do not change the order in OFILES +OFILES = rd.o rd_arhdr.o rd_int2.o rd_long.o rd_ranlib.o rd_unsig2.o \ + rd_bytes.o wr_arhdr.o wr_int2.o wr_long.o wr_putc.o wr.o \ + wr_ranlib.o wr_bytes.o + +all: libobject.a + +install: all + $(INSTALL) lib/libobject.a + $(INSTALL) man/object.3 + +compare: all + $(COMPARE) lib/libobject.a + $(COMPARE) man/object.3 + +clean: + rm -f *.[oa] nohup.out Out byte_order byte_order.h + +libobject.a: $(OFILES) + ar r libobject.a $(OFILES) + -sh -c 'ranlib libobject.a' + +depend: byte_order.h + sed '/^#AUTOAUTO/,$$d' Makefile > Makefile.new + echo '#AUTOAUTOAUTOAUTOAUTOAUTOAUTO' >> Makefile.new + mkdep $(CFILES) | sed 's/\.c:/\.o:/' >> Makefile.new + mv Makefile Makefile.old + mv Makefile.new Makefile + +byte_order: byte_order.o + $(CC) $(LDFLAGS) -o byte_order byte_order.o + +byte_order.h: byte_order + byte_order > byte_order.h + +#AUTOAUTOAUTOAUTOAUTOAUTOAUTO +rd_arhdr.o: byte_order.h object.h +wr_arhdr.o: byte_order.h object.h +rd_ranlib.o: byte_order.h object.h +wr_ranlib.o: byte_order.h object.h +rd.o: byte_order.h object.h +wr.o: byte_order.h object.h +rd_int2.o: byte_order.h object.h +wr_int2.o: byte_order.h object.h +rd_unsig2.o: byte_order.h object.h +rd_long.o: byte_order.h object.h +wr_long.o: byte_order.h object.h diff --git a/modules/src/object/byte_order.c b/modules/src/object/byte_order.c new file mode 100644 index 00000000..cc9990e4 --- /dev/null +++ b/modules/src/object/byte_order.c @@ -0,0 +1,49 @@ +#include + +char bytes_reversed = 0; +char words_reversed = 0; +char char_unsigned = 0; + +/* + * Determine the byte/word order in shorts/longs, assuming the size of a short + * is 2 chars, and the size of a long is 4 chars. Not all theoretical + * possibilities are tested; only bytes reversed and/or words reversed. + */ +determine_ordering() +{ + short s; + long l; + register char *cp; + register short *sp; + + cp = (char *)&s; + cp[0] = 0x01; cp[1] = 0x02; + if (s != 0x01 + (0x02 << 8)) + bytes_reversed = 1; + sp = (short *)&l; + sp[0] = 0x0001; sp[1] = 0x0002; + if (l != 0x0001 + (0x0002L << 16)) + words_reversed = 1; +} + +/* + * determine whether characters are unsigned or signed + */ + +uns_char() +{ + char c = 0200; + int i = c; + + if (i > 0) char_unsigned = 1; +} + +main() +{ + determine_ordering(); + uns_char(); + printf("#define BYTES_REVERSED %d\n", bytes_reversed); + printf("#define WORDS_REVERSED %d\n", words_reversed); + printf("#define CHAR_UNSIGNED %d\n", char_unsigned); + return 0; +} diff --git a/modules/src/object/object.3 b/modules/src/object/object.3 new file mode 100644 index 00000000..52bd8ac5 --- /dev/null +++ b/modules/src/object/object.3 @@ -0,0 +1,287 @@ +.TH OBJECT 3 "October 16, 1986" +.SH NAME +wr_open, wr_close, wr_ohead, wr_sect, wr_outsect, wr_emit, wr_putc, wr_relo, +wr_name, wr_string, wr_arhdr, wr_ranlib, wr_int2, wr_long, +rd_open, rd_fdopen, rd_close, rd_ohead, rd_sect, rd_outsect, +rd_emit, rd_relo, rd_rew_relo, rd_name, rd_string, rd_arhdr, rd_ranlib, +rd_int2, rd_unsigned2, rd_long\ \-\ routines to read +and write ACK-object files and libraries +.SH SYNOPSIS +.B #include +.br +.B #include +.br +.B #include +.PP +.B int wr_open(filename) +.br +.B char *filename; +.PP +.B wr_close() +.PP +.B wr_ohead(head) +.br +.B struct outsect *head; +.PP +.B wr_sect(sect, cnt) +.br +.B struct outsect *sect; +.br +.B unsigned int cnt; +.PP +.B wr_outsect(sectionnr) +.br +.B int sectionnr; +.PP +.B wr_emit(emit, cnt) +.br +.B char *emit; +.br +.B long cnt; +.PP +.B wr_putc(ch) +.PP +.B wr_relo(relo, cnt) +.br +.B struct outrelo *relo; +.br +.B unsigned int cnt; +.PP +.B wr_name(name, cnt) +.br +.B struct name *name; +.br +.B unsigned int cnt; +.PP +.B wr_string(stringaddr, cnt) +.br +.B char *stringaddr; +.br +.B long cnt; +.PP +.B wr_arhdr(fd, arhdr) +.br +.B struct arhdr *arhdr; +.PP +.B wr_ranlib(fd, ran, cnt) +.br +.B struct ranlib *ran; +.br +.B long cnt; +.PP +.B wr_int2(fd, i) +.PP +.B wr_long(fd, l) +.br +.B long l; +.PP +.B int rd_open(filename) +.br +.B char *filename; +.PP +.B int rd_fdopen(fd) +.PP +.B rd_close() +.PP +.B rd_ohead(head) +.br +.B struct outsect *head; +.PP +.B rd_sect(sect, cnt) +.br +.B struct outsect *sect; +.br +.B unsigned int cnt; +.PP +.B rd_outsect(sectionnr) +.br +.B int sectionnr; +.PP +.B rd_emit(emit, cnt) +.br +.B char *emit; +.br +.B long cnt; +.PP +.B rd_relo(relo, cnt) +.br +.B struct outrelo *relo; +.br +.B unsigned int cnt; +.PP +.B rd_rew_relo(head) +.br +.B struct outhead *head; +.PP +.B rd_name(name, cnt) +.br +.B struct name *name; +.br +.B unsigned int cnt; +.PP +.B rd_string(stringaddr, cnt) +.br +.B char *stringaddr; +.br +.B long cnt; +.PP +.B rd_arhdr(fd, arhdr) +.br +.B struct arhdr *arhdr; +.PP +.B rd_ranlib(fd, ran, cnt) +.br +.B struct ranlib *ran; +.br +.B long cnt; +.PP +.B int rd_int2(fd) +.PP +.B unsigned int rd_unsigned2(fd) +.PP +.B long rd_long(fd) +.SH DESCRIPTION +These routines come in handy when reading or writing ACK-object files +or libraries. No checking is performed. +.PP +.I Wr_open +opens the file +.I filename +for writing and initializes some of this modules local variables. +It must be called before writing parts of the object file. +It returns 1 if it succeeds, 0 if it fails. +.PP +.I Wr_close +closes the object file. Don't forget to call it, because it might +flush internal buffers. +.PP +.I Wr_ohead +writes the +.I head +header structure. +This routine must be called before the routines to write the other +parts. +.PP +.I Wr_sect +writes +.I cnt +section headers, starting at +.IB sect . +Before writing a section, its section header must be written. +.PP +.I Wr_outsect +indicates that the next section to be written is +.IB sectionnr . +This routine can be used to switch between sections. +.PP +.I Wr_emit +writes +.I cnt +bytes, starting at +.IB emit , +of the current section. +.PP +.I Wr_putc +adds character +.I ch +to the current section. +.PP +.I Wr_relo +writes +.I cnt +outrelo structures, indicated by +.IB relo , +in the relocation information part of the object file. +.PP +.I Wr_name +writes +.I cnt +outname structures, indicated by +.IB name , +in the name-table part of the object file. +.PP +.I Wr_string +writes +.I cnt +bytes, indicated by +.IB stringaddr , +in the string table part of the object file. +.PP +The next few routines can be used independantly: +.I Wr_arhdr +writes the archive member header +.I arhdr +to file descriptor +.IB fd . +.PP +.I Wr_ranlib +writes +.I cnt +ranlib structures, indicated by +.IB ran , +to file descriptor +.IB fd. +.PP +.I Wr_int2 +writes a 2-byte integer +.I i +to file descriptor +.IB fd , +low order byte first. +.PP +.I Wr_long +writes a 4-byte integer +.I l +to file descriptor +.IB fd , +low order word first, low order byte first. +.PP +Most of the +.I rd_ +routines are the opposite of the +.I wr_ +routines. However, a few of them deserve special mentioning: +.PP +.I Rd_fdopen +initialises for reading an "object file" from file descriptor +.IB fd , +at its current position. +This is useful for reading an object that resides in an archive. +It returns 1 if it succeeds, 0 otherwise. +If you use this entry point for reading, you don't have to call +.I rd_close +to close the file. You can close the file yourself. +.PP +.I Rd_rew_relo +rewinds the relocation part, so that it can be read again. +\fILed\fR(1) sometimes needs this. +.PP +.I Rd_unsigned2 +reads two bytes from file descriptor +.I fd +and interpretes them as an unsigned integer. +.PP +When using any of the reading routines, you must define a routine +named +.IB rd_fatal . +It is called when a read fails, and is not supposed to return. +Likewise, a routine +.I wr_fatal +must be defined when using any of the writing routines. +.SH FILES +~em/h/out.h +.br +~em/h/arch.h +.br +~em/h/ranlib.h +.br +~em/modules/lib/libobject.a: the library in which these routines reside +.SH "SEE ALSO" +ack.out(5), arch(1), aal(1) +.SH DIAGNOSTICS +The routines +.IB wr_open , +.IB rd_open , +and +.I rd_fdopen +return 0 if they fail, and 1 if they succeed. diff --git a/modules/src/object/object.h b/modules/src/object/object.h new file mode 100644 index 00000000..87eb933e --- /dev/null +++ b/modules/src/object/object.h @@ -0,0 +1,30 @@ +#include "byte_order.h" + +#if CHAR_UNSIGNED +#define Xchar(ch) (ch) +#else +#define Xchar(ch) ((ch) & 0377) +#endif + +#if BYTES_REVERSED +#define uget2(c) (Xchar((c)[0]) | ((unsigned) Xchar((c)[1]) << 8)) +#define Xput2(i, c) (((c)[0] = (i)), ((c)[1] = (i) >> 8)) +#define put2(i, c) { register int j = (i); Xput2(j, c); } +#else +#define uget2(c) (* ((unsigned short *) (c))) +#define Xput2(i, c) (* ((short *) (c)) = (i)) +#define put2(i, c) Xput2(i, c) +#endif + +#define get2(c) ((short) uget2(c)) + +#if WORDS_REVERSED || BYTES_REVERSED +#define get4(c) (uget2(c) | ((long) uget2((c)+2) << 16)) +#define put4(l, c) { register long x=(l); \ + Xput2((int)x,c); \ + Xput2((int)(x>>16),(c)+2); \ + } +#else +#define get4(c) (* ((long *) (c))) +#define put4(l, c) (* ((long *) (c)) = (l)) +#endif diff --git a/modules/src/object/rd.c b/modules/src/object/rd.c new file mode 100644 index 00000000..52c1f718 --- /dev/null +++ b/modules/src/object/rd.c @@ -0,0 +1,237 @@ +#include +#include "object.h" + +extern long lseek(); + +/* + * Parts of the output file. + */ +#define PARTEMIT 0 +#define PARTRELO 1 +#define PARTNAME 2 +#define PARTCHAR 3 +#ifdef SYMDBUG +#define PARTDBUG 4 +#else +#define PARTDBUG 3 +#define NPARTS (PARTDBUG + 1) + +static long offset[MAXSECT]; + +static int outfile; +static long outseek[NPARTS]; +static long currpos; +static long rd_base; +#define OUTSECT(i) \ + (outseek[PARTEMIT] = offset[i]) +#define BEGINSEEK(p, o) \ + (outseek[(p)] = (o)) + +static int sectionnr; + +static +OUTREAD(p, b, n) + char *b; + long n; +{ + register long l = outseek[p]; + + if (currpos != l) { + lseek(outfile, l, 0); + } + rd_bytes(outfile, b, n); + l += n; + currpos = l; + outseek[p] = l; +} + +/* + * Open the output file according to the chosen strategy. + */ +int +rd_open(f) + char *f; +{ + + if ((outfile = open(f, 0)) < 0) + return 0; + return rd_fdopen(outfile); +} + +static int offcnt; + +rd_fdopen(fd) +{ + register int i; + + for (i = 0; i < NPARTS; i++) outseek[i] = 0; + offcnt = 0; + rd_base = lseek(fd, 0L, 1); + if (rd_base < 0) { + return 0; + } + currpos = rd_base; + outseek[PARTEMIT] = currpos; + outfile = fd; + sectionnr = 0; + return 1; +} + +rd_close() +{ + + close(outfile); +} + +rd_ohead(head) + register struct outhead *head; +{ + register long off; + + OUTREAD(PARTEMIT, (char *) head, (long) SZ_HEAD); +#if ! (BYTES_REVERSED || WORDS_REVERSED) + if (sizeof(struct outhead) != SZ_HEAD) +#endif + { + register char *c = (char *) head + (SZ_HEAD-4); + + head->oh_nchar = get4(c); + c -= 4; head->oh_nemit = get4(c); + c -= 2; head->oh_nname = uget2(c); + c -= 2; head->oh_nrelo = uget2(c); + c -= 2; head->oh_nsect = uget2(c); + c -= 2; head->oh_flags = uget2(c); + c -= 2; head->oh_stamp = uget2(c); + c -= 2; head->oh_magic = uget2(c); + } + off = OFF_RELO(*head) + rd_base; + BEGINSEEK(PARTRELO, off); + off += (long) head->oh_nrelo * SZ_RELO; + BEGINSEEK(PARTNAME, off); + off += (long) head->oh_nname * SZ_NAME; + BEGINSEEK(PARTCHAR, off); +#ifdef SYMDBUG + off += head->oh_nchar; + BEGINSEEK(PARTDBUG, off); +#endif +} + +rd_rew_relos(head) + register struct outhead *head; +{ + register long off = OFF_RELO(*head) + rd_base; + + BEGINSEEK(PARTRELO, off); +} + +rd_sect(sect, cnt) + register struct outsect *sect; + register unsigned int cnt; +{ + register char *c = (char *) sect + cnt * SZ_SECT; + + OUTREAD(PARTEMIT, (char *) sect, (long)cnt * SZ_SECT); + sect += cnt; + offcnt += cnt; + while (cnt--) { + sect--; +#if ! (BYTES_REVERSED || WORDS_REVERSED) + if (sizeof(struct outsect) != SZ_SECT) { +#endif + c -= 4; sect->os_lign = get4(c); + c -= 4; sect->os_flen = get4(c); + c -= 4; sect->os_foff = get4(c); +#if ! (BYTES_REVERSED || WORDS_REVERSED) + } +#endif + offset[--offcnt] = sect->os_foff + rd_base; +#if ! (BYTES_REVERSED || WORDS_REVERSED) + if (sizeof(struct outsect) != SZ_SECT) { +#endif + c -= 4; sect->os_size = get4(c); + c -= 4; sect->os_base = get4(c); +#if ! (BYTES_REVERSED || WORDS_REVERSED) + } +#endif + } +} + +rd_outsect(s) +{ + OUTSECT(s); + sectionnr = s; +} + +/* + * We don't have to worry about byte order here. + */ +rd_emit(emit, cnt) + char *emit; + long cnt; +{ + OUTREAD(PARTEMIT, emit, cnt); + offset[sectionnr] += cnt; +} + +rd_relo(relo, cnt) + register struct outrelo *relo; + register unsigned int cnt; +{ + + OUTREAD(PARTRELO, (char *) relo, (long) cnt * SZ_RELO); +#if ! (BYTES_REVERSED || WORDS_REVERSED) + if (sizeof(struct outrelo) != SZ_RELO) +#endif + { + register char *c = (char *) relo + (long) cnt * SZ_RELO; + + relo += cnt; + while (cnt--) { + relo--; + c -= 4; relo->or_addr = get4(c); + c -= 2; relo->or_nami = uget2(c); + relo->or_sect = *--c; + relo->or_type = *--c; + } + } +} + +rd_name(name, cnt) + register struct outname *name; + register unsigned int cnt; +{ + + OUTREAD(PARTNAME, (char *) name, (long) cnt * SZ_NAME); +#if ! (BYTES_REVERSED || WORDS_REVERSED) + if (sizeof(struct outname) != SZ_NAME) +#endif + { + register char *c = (char *) name + (long) cnt * SZ_NAME; + + name += cnt; + while (cnt--) { + name--; + c -= 4; name->on_valu = get4(c); + c -= 2; name->on_desc = uget2(c); + c -= 2; name->on_type = uget2(c); + c -= 4; name->on_foff = get4(c); + } + } +} + +rd_string(addr, len) + char *addr; + long len; +{ + + OUTREAD(PARTCHAR, addr, len); +} + +#ifdef SYMDBUG +rd_dbug(buf, size) + char *buf; + long size; +{ + OUTREAD(PARTDBUG, buf, size); +} +#endif diff --git a/modules/src/object/rd_arhdr.c b/modules/src/object/rd_arhdr.c new file mode 100644 index 00000000..00a1ca7e --- /dev/null +++ b/modules/src/object/rd_arhdr.c @@ -0,0 +1,29 @@ +#include +#include "object.h" + +rd_arhdr(fd, arhdr) + register struct ar_hdr *arhdr; +{ +#if ! (BYTES_REVERSED || WORDS_REVERSED) + if (sizeof (struct ar_hdr) != AR_TOTAL) +#endif + { + char buf[AR_TOTAL]; + register char *c = buf; + register char *p = arhdr->ar_name; + register int i = 14; + + rd_bytes(fd, c, (long) AR_TOTAL); + while (i--) { + *p++ = *c++; + } + arhdr->ar_date = get4(c); c += 4; + arhdr->ar_uid = *c++; + arhdr->ar_gid = *c++; + arhdr->ar_mode = get2(c); c += 2; + arhdr->ar_size = get4(c); + } +#if ! (BYTES_REVERSED || WORDS_REVERSED) + else rd_bytes(fd, (char *) arhdr, (long) AR_TOTAL); +#endif +} diff --git a/modules/src/object/rd_bytes.c b/modules/src/object/rd_bytes.c new file mode 100644 index 00000000..e46f4cb4 --- /dev/null +++ b/modules/src/object/rd_bytes.c @@ -0,0 +1,22 @@ +#define MININT (1 << (sizeof(int) * 8 - 1)) +#define MAXCHUNK (-(MININT + 1)) /* Highest count we write(2). */ + +/* + * We don't have to worry about byte order here. + * Just read "cnt" bytes from file-descriptor "fd". + */ +int +rd_bytes(fd, string, cnt) + register char *string; + register long cnt; +{ + + while (cnt) { + register int n = cnt >= MAXCHUNK ? MAXCHUNK : cnt; + + if (read(fd, string, n) != n) + rd_fatal(); + string += n; + cnt -= n; + } +} diff --git a/modules/src/object/rd_int2.c b/modules/src/object/rd_int2.c new file mode 100644 index 00000000..7dbc2b57 --- /dev/null +++ b/modules/src/object/rd_int2.c @@ -0,0 +1,10 @@ +#include "object.h" + +int +rd_int2(fd) +{ + char buf[2]; + + rd_bytes(fd, buf, 2L); + return get2(buf); +} diff --git a/modules/src/object/rd_long.c b/modules/src/object/rd_long.c new file mode 100644 index 00000000..af369be2 --- /dev/null +++ b/modules/src/object/rd_long.c @@ -0,0 +1,10 @@ +#include "object.h" + +long +rd_long(fd) +{ + char buf[4]; + + rd_bytes(fd, buf, 4L); + return get4(buf); +} diff --git a/modules/src/object/rd_ranlib.c b/modules/src/object/rd_ranlib.c new file mode 100644 index 00000000..f1797cfd --- /dev/null +++ b/modules/src/object/rd_ranlib.c @@ -0,0 +1,21 @@ +#include +#include "object.h" + +rd_ranlib(fd, ran, cnt) + register struct ranlib *ran; + register long cnt; +{ + rd_bytes(fd, (char *) ran, cnt * SZ_RAN); +#if ! (BYTES_REVERSED || WORDS_REVERSED) + if (sizeof (struct ranlib) != SZ_RAN) +#endif + { + register char *c = (char *) ran; + + while (cnt--) { + ran->ran_off = get4(c); c += 4; + ran->ran_pos = get4(c); c += 4; + ran++; + } + } +} diff --git a/modules/src/object/rd_unsig2.c b/modules/src/object/rd_unsig2.c new file mode 100644 index 00000000..5321c0d2 --- /dev/null +++ b/modules/src/object/rd_unsig2.c @@ -0,0 +1,10 @@ +#include "object.h" + +unsigned int +rd_unsigned2(fd) +{ + char buf[2]; + + rd_bytes(fd, buf, 2L); + return uget2(buf); +} diff --git a/modules/src/object/wr.c b/modules/src/object/wr.c new file mode 100644 index 00000000..5bcf55ca --- /dev/null +++ b/modules/src/object/wr.c @@ -0,0 +1,314 @@ +/* + * You can choose between two strategies: + * - Open the output file several times, once for each logical part, and + * write to it in multiple places. + * - Open the output file once and seek back and forth to each logical + * part. In this case #define OUTSEEK. + */ + +#include +#include "object.h" + +extern long lseek(); + +/* + * Parts of the output file. + */ +#define PARTEMIT 0 +#define PARTRELO 1 +#define PARTNAME 2 +#define PARTCHAR 3 +#ifdef SYMDBUG +#define PARTDBUG 4 +#else +#define PARTDBUG 3 +#endif +#define NPARTS (PARTDBUG + 1) + +static long offset[MAXSECT]; + +#ifdef OUTSEEK +static int outfile; +static long outseek[NPARTS]; +static long currpos; +#define OUTSECT(i) \ + (outseek[PARTEMIT] = offset[i]) +static +OUTWRITE(p, b, n) { + char *b; + long n; +{ + register long l = outseek[p]; + + if (currpos != l) { + lseek(outfile, l, 0); + } + wr_bytes(outfile, b, n); + currpos = l + n; + outseek[p] = currpos; +} + +#define BEGINSEEK(p, o) \ + (outseek[(p)] = (o)) + +#else OUTSEEK + +static int outfile[NPARTS]; +static long currpos[NPARTS]; +#define OUTSECT(i) \ + (currpos[PARTEMIT] == offset[(i)] ?\ + 0 :\ + (currpos[PARTEMIT] = offset[(i)],\ + lseek(outfile[PARTEMIT], currpos[PARTEMIT], 0))) +#define OUTWRITE(p, b, n) \ + (wr_bytes(outfile[(p)], (b), (n)), currpos[(p)] += (n)) +#define BEGINSEEK(p, o) \ + (currpos[(p)] = lseek(outfile[(p)], (o), 0)) + +#endif OUTSEEK + +int _ocnt; +char *_pbuf; +static int sectionnr; +static int offcnt; + +/* + * Open the output file according to the chosen strategy. + */ +int +wr_open(f) + char *f; +{ +#ifndef OUTSEEK + register int *fdp; +#endif OUTSEEK + + close(creat(f, 0666)); +#ifdef OUTSEEK + if ((outfile = open(f, 1)) < 0) + return 0; + currpos = 0; +#else OUTSEEK + for (fdp = &outfile[PARTEMIT]; fdp < &outfile[NPARTS]; fdp++) + if ((*fdp = open(f, 1)) < 0) + return 0; +#endif OUTSEEK + offcnt = 0; + return 1; +} + +wr_close() +{ +#ifndef OUTSEEK + register int *fdp; +#endif not OUTSEEK + + if (_ocnt) { + wr_flush(); + } +#ifdef OUTSEEK + close(outfile); +#else not OUTSEEK + for (fdp = &outfile[PARTEMIT]; fdp < &outfile[NPARTS]; fdp++) { + close(*fdp); + } +#endif not OUTSEEK +} + +wr_ohead(head) + register struct outhead *head; +{ + register long off = OFF_RELO(*head); + + BEGINSEEK(PARTEMIT, 0L); + BEGINSEEK(PARTRELO, off); + off += (long) head->oh_nrelo * SZ_RELO; + BEGINSEEK(PARTNAME, off); + off += (long) head->oh_nname * SZ_NAME; + BEGINSEEK(PARTCHAR, off); +#ifdef SYMDBUG + off += head->oh_nchar; + BEGINSEEK(PARTDBUG, off); +#endif +#if ! (BYTES_REVERSED || WORDS_REVERSED) + if (sizeof(struct outhead) != SZ_HEAD) +#endif + { + char buf[SZ_HEAD]; + register char *c = buf; + + put2(head->oh_magic, c); c += 2; + put2(head->oh_stamp, c); c += 2; + put2(head->oh_flags, c); c += 2; + put2(head->oh_nsect, c); c += 2; + put2(head->oh_nrelo, c); c += 2; + put2(head->oh_nname, c); c += 2; + put4(head->oh_nemit, c); c += 4; + put4(head->oh_nchar, c); + OUTWRITE(PARTEMIT, buf, (long) SZ_HEAD); + } +#if ! (BYTES_REVERSED || WORDS_REVERSED) + else OUTWRITE(PARTEMIT, (char *) head, (long) SZ_HEAD); +#endif +} + +wr_sect(sect, cnt1) + register struct outsect *sect; + unsigned int cnt1; +{ + char buf[MAXSECT * SZ_SECT]; + register char *c = buf; + register unsigned int cnt = cnt1; + + while (cnt--) { +#if ! (BYTES_REVERSED || WORDS_REVERSED) + if (sizeof(struct outsect) != SZ_SECT) +#endif + { + put4(sect->os_base, c); c += 4; + put4(sect->os_size, c); c += 4; + put4(sect->os_foff, c); c += 4; + } + offset[offcnt++] = sect->os_foff; +#if ! (BYTES_REVERSED || WORDS_REVERSED) + if (sizeof(struct outsect) != SZ_SECT) +#endif + { + put4(sect->os_flen, c); c += 4; + put4(sect->os_lign, c); c += 4; + } + sect++; + } +#if ! (BYTES_REVERSED || WORDS_REVERSED) + if (sizeof(struct outsect) != SZ_SECT) +#endif + OUTWRITE(PARTEMIT, buf, (long) cnt1 * SZ_SECT); +#if ! (BYTES_REVERSED || WORDS_REVERSED) + else + OUTWRITE(PARTEMIT, (char *) (sect - cnt1), (long) cnt1 * SZ_SECT); +#endif +} + +wr_flush() +{ + OUTWRITE(PARTEMIT, _pbuf, (long) _ocnt); + offset[sectionnr] += _ocnt; + _ocnt = 0; +} + +wr_outsect(s) +{ + if (s != sectionnr) { + if (_ocnt) { + wr_flush(); + } + sectionnr = s; + OUTSECT(s); + } +} + +/* + * We don't have to worry about byte order here. + */ +wr_emit(emit, cnt) + char *emit; + long cnt; +{ + if (_ocnt) wr_flush(); + OUTWRITE(PARTEMIT, emit, cnt); + offset[sectionnr] += cnt; +} + +wr_relo(relo, cnt) + register struct outrelo *relo; + register unsigned int cnt; +{ + long l; + +#if ! (BYTES_REVERSED || WORDS_REVERSED) + if (sizeof(struct outrelo) != SZ_RELO) +#endif + { + char buf[100 * SZ_RELO]; + register char *c = buf; + register int i = 0; + + while (cnt--) { + *c++ = relo->or_type; + *c++ = relo->or_sect; + put2(relo->or_nami, c); c += 2; + put4(relo->or_addr, c); c += 4; + relo++; + i++; + if (i == 100 || cnt == 0) { + c = buf; + l = (long) (i * SZ_RELO); + OUTWRITE(PARTRELO, c, l); + i = 0; + } + } + } +#if ! (BYTES_REVERSED || WORDS_REVERSED) + else { + l = (long) cnt * SZ_RELO; + OUTWRITE(PARTRELO, (char *) relo, l); + } +#endif +} + +wr_name(name, cnt) + register struct outname *name; + register unsigned int cnt; +{ + long l; + +#if ! (BYTES_REVERSED || WORDS_REVERSED) + if (sizeof(struct outname) != SZ_NAME) +#endif + { + char buf[100 * SZ_NAME]; + register char *c = buf; + register int i = 0; + + while (cnt--) { + put4(name->on_foff,c); c += 4; + put2(name->on_type,c); c += 2; + put2(name->on_desc,c); c += 2; + put4(name->on_valu,c); c += 4; + name++; + i++; + if (i == 100 || !cnt) { + c = buf; + l = (long) (i * SZ_NAME); + OUTWRITE(PARTNAME, c, l); + i = 0; + } + } + } +#if ! (BYTES_REVERSED || WORDS_REVERSED) + else { + l = (long)cnt * SZ_NAME; + OUTWRITE(PARTNAME, (char *) name, l); + } +#endif + +} + +wr_string(addr, len) + char *addr; + long len; +{ + + OUTWRITE(PARTCHAR, addr, len); +} + +#ifdef SYMDBUG + +wr_dbug(buf, size) + char *buf; + long size; +{ + OUTWRITE(PARTDBUG, buf, size); +} + +#endif SYMDBUG diff --git a/modules/src/object/wr_arhdr.c b/modules/src/object/wr_arhdr.c new file mode 100644 index 00000000..f7ac67ba --- /dev/null +++ b/modules/src/object/wr_arhdr.c @@ -0,0 +1,29 @@ +#include +#include "object.h" + +wr_arhdr(fd, arhdr) + register struct ar_hdr *arhdr; +{ +#if ! (BYTES_REVERSED || WORDS_REVERSED) + if (sizeof (struct ar_hdr) != AR_TOTAL) +#endif + { + char buf[AR_TOTAL]; + register char *c = buf; + register char *p = arhdr->ar_name; + register int i = 14; + + while (i--) { + *c++ = *p++; + } + put4(arhdr->ar_date,c); c += 4; + *c++ = arhdr->ar_uid; + *c++ = arhdr->ar_gid; + put2(arhdr->ar_mode,c); c += 2; + put4(arhdr->ar_size,c); + wr_bytes(fd, buf, (long) AR_TOTAL); + } +#if ! (BYTES_REVERSED || WORDS_REVERSED) + else wr_bytes(fd, (char *) arhdr, (long) AR_TOTAL); +#endif +} diff --git a/modules/src/object/wr_bytes.c b/modules/src/object/wr_bytes.c new file mode 100644 index 00000000..8dccc4b1 --- /dev/null +++ b/modules/src/object/wr_bytes.c @@ -0,0 +1,20 @@ +#define MININT (1 << (sizeof(int) * 8 - 1)) +#define MAXCHUNK (-(MININT + 1)) /* Highest count we write(2). */ + +/* + * Just write "cnt" bytes to file-descriptor "fd". + */ +wr_bytes(fd, string, cnt) + register char *string; + register long cnt; +{ + + while (cnt) { + register int n = cnt >= MAXCHUNK ? MAXCHUNK : cnt; + + if (write(fd, string, n) != n) + wr_fatal(); + string += n; + cnt -= n; + } +} diff --git a/modules/src/object/wr_int2.c b/modules/src/object/wr_int2.c new file mode 100644 index 00000000..d836a4a9 --- /dev/null +++ b/modules/src/object/wr_int2.c @@ -0,0 +1,9 @@ +#include "object.h" + +wr_int2(fd, i) +{ + char buf[2]; + + put2(i, buf); + wr_bytes(fd, buf, 2L); +} diff --git a/modules/src/object/wr_long.c b/modules/src/object/wr_long.c new file mode 100644 index 00000000..1d9217ea --- /dev/null +++ b/modules/src/object/wr_long.c @@ -0,0 +1,10 @@ +#include "object.h" + +wr_long(fd, l) + long l; +{ + char buf[4]; + + put4(l, buf); + wr_bytes(fd, buf, 4L); +} diff --git a/modules/src/object/wr_putc.c b/modules/src/object/wr_putc.c new file mode 100644 index 00000000..c5b05c57 --- /dev/null +++ b/modules/src/object/wr_putc.c @@ -0,0 +1,15 @@ +#include + +static char buf[BUFSIZ]; + +extern char *_pbuf; +extern int _ocnt; + +wr_putc(ch) +{ + _pbuf = buf; + buf[_ocnt++] = ch; + if (_ocnt == BUFSIZ) { + wr_flush(); + } +} diff --git a/modules/src/object/wr_ranlib.c b/modules/src/object/wr_ranlib.c new file mode 100644 index 00000000..f20772c1 --- /dev/null +++ b/modules/src/object/wr_ranlib.c @@ -0,0 +1,31 @@ +#include +#include "object.h" + +wr_ranlib(fd, ran, cnt) + register struct ranlib *ran; + register long cnt; +{ +#if ! (BYTES_REVERSED || WORDS_REVERSED) + if (sizeof (struct ranlib) != SZ_RAN) +#endif + { + char buf[100 * SZ_RAN]; + + while (cnt) { + register int i = (cnt > 100) ? 100 : cnt; + register char *c = buf; + long j = i * SZ_RAN; + + cnt -= i; + while (i--) { + put4(ran->ran_off,c); c += 4; + put4(ran->ran_pos,c); c += 4; + ran++; + } + wr_bytes(fd, c, j); + } + } +#if ! (BYTES_REVERSED || WORDS_REVERSED) + else wr_bytes(fd, (char *) ran, cnt * SZ_RAN); +#endif +} From dc536d3e4a5dec2dde6f5e518a519e558e27d2c3 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 5 Jan 1987 17:37:37 +0000 Subject: [PATCH 0417/1625] Initial revision --- modules/src/print/doprnt.c | 14 +++++ modules/src/print/format.c | 99 +++++++++++++++++++++++++++++ modules/src/print/fprint.c | 15 +++++ modules/src/print/param.h | 3 + modules/src/print/print.3 | 124 +++++++++++++++++++++++++++++++++++++ modules/src/print/print.c | 14 +++++ modules/src/print/print.h | 11 ++++ modules/src/print/sprint.c | 14 +++++ 8 files changed, 294 insertions(+) create mode 100644 modules/src/print/doprnt.c create mode 100644 modules/src/print/format.c create mode 100644 modules/src/print/fprint.c create mode 100644 modules/src/print/param.h create mode 100644 modules/src/print/print.3 create mode 100644 modules/src/print/print.c create mode 100644 modules/src/print/print.h create mode 100644 modules/src/print/sprint.c diff --git a/modules/src/print/doprnt.c b/modules/src/print/doprnt.c new file mode 100644 index 00000000..7dca0ea9 --- /dev/null +++ b/modules/src/print/doprnt.c @@ -0,0 +1,14 @@ +/* $Header$ */ + +#include +#include "param.h" + +doprnt(fp, fmt, argp) + File *fp; + char *fmt; + int argp[]; +{ + char buf[SSIZE]; + + sys_write(fp, buf, _format(buf, fmt, (char *)argp)); +} diff --git a/modules/src/print/format.c b/modules/src/print/format.c new file mode 100644 index 00000000..31f1f6d4 --- /dev/null +++ b/modules/src/print/format.c @@ -0,0 +1,99 @@ +/* $Header$ */ + +char *long2str(); + +static int +integral(c) +{ + switch (c) { + case 'b': + return -2; + case 'd': + return 10; + case 'o': + return -8; + case 'u': + return -10; + case 'x': + return -16; + } + return 0; +} + +int +_format(buf, fmt, argp) + char *buf, *fmt; + char *argp; +{ + register char *pf = fmt, *pa = argp; + register char *pb = buf; + + while (*pf) { + if (*pf == '%') { + register width, base, pad, npad; + char *arg; + char cbuf[2]; + char *badformat = ""; + + /* get padder */ + if (*++pf == '0') { + pad = '0'; + ++pf; + } + else + pad = ' '; + + /* get width */ + width = 0; + while (*pf >= '0' && *pf <= '9') + width = 10 * width + *pf++ - '0'; + + /* get text and move pa */ + if (*pf == 's') { + arg = *(char **)pa; + pa += sizeof(char *); + } + else + if (*pf == 'c') { + cbuf[0] = * (char *) pa; + cbuf[1] = '\0'; + pa += sizeof(int); + arg = &cbuf[0]; + } + else + if (*pf == 'l') { + /* alignment ??? */ + if (base = integral(*++pf)) { + arg = long2str(*(long *)pa, base); + pa += sizeof(long); + } + else { + pf--; + arg = badformat; + } + } + else + if (base = integral(*pf)) { + arg = long2str((long)*(int *)pa, base); + pa += sizeof(int); + } + else + if (*pf == '%') + arg = "%"; + else + arg = badformat; + + npad = width - strlen(arg); + + while (npad-- > 0) + *pb++ = pad; + + while (*pb++ = *arg++); + pb--; + pf++; + } + else + *pb++ = *pf++; + } + return pb - buf; +} diff --git a/modules/src/print/fprint.c b/modules/src/print/fprint.c new file mode 100644 index 00000000..97b8ebbe --- /dev/null +++ b/modules/src/print/fprint.c @@ -0,0 +1,15 @@ +/* $Header$ */ + +#include +#include "param.h" + +/*VARARGS1*/ +fprint(fp, fmt, args) + File *fp; + char *fmt; + int args; +{ + char buf[SSIZE]; + + sys_write(fp, buf, _format(buf, fmt, &args)); +} diff --git a/modules/src/print/param.h b/modules/src/print/param.h new file mode 100644 index 00000000..45bb5c84 --- /dev/null +++ b/modules/src/print/param.h @@ -0,0 +1,3 @@ +/* $Header$ */ + +#define SSIZE 1024 diff --git a/modules/src/print/print.3 b/modules/src/print/print.3 new file mode 100644 index 00000000..a71f98ca --- /dev/null +++ b/modules/src/print/print.3 @@ -0,0 +1,124 @@ +.TH PRINT 3ACK "86/04/02" +.SH NAME +print, fprint, sprint, doprnt -- very simple formatted-output routines +.SH SYNOPSIS +.nf +.B #include +.PP +.B print(format [, arg] ... ) +.B char *format; +.PP +.B fprint(filep, format [, arg] ... ) +.B File *filep; +.B char *format; +.PP +.B sprint(s, format [, arg] ... ) +.B char *s, *format; +.PP +.B doprnt(filep, format, args) +.B File *filep; +.B char *format; +.B int args[]; +.fi +.SH DESCRIPTION +.I Print +writes output on standard output. +.I Fprint +and +.I doprnt +place output on the open file known by +.IR filep . +.I Sprint +places `output' in the string +.IR s , +followed by the character `\\0'. +.PP +Each of these functions converts, formats and prints its arguments, following +the +.I format +argument, under control of +.IR format . +.I Format +is a character string which contains two types of objects: plain characters, +which are simply copied to the output destination, and conversion +specifications, each of which causes conversion and printing of the next +successive argument. +.PP +A conversion specification is introduced by the character %. +Following the %, there may be +.IP \(bu +an optional row of decimal digits specifying the field width; +if the converted integral value has fewer characters than +the field width, it will be blank-padded on the left; +if the field width begins with a zero, zero-padding will be done; +.IP \(bu +the character +.B l +specifying that a following +.BR b , +.BR d , +.BR o , +.B u +or +.B x +corresponds to a long-integer argument; +.IP \(bu +a character which indicates the type of conversion to be applied. +.LP +.PP +The conversion characters and their meanings are +.IP \fBbdox\fP +The next argument is an integer and is converted to binary, decimal, octal +or hexadecimal notation respectively. +.IP \fBc\fP +Next argument is a character and is put directly into the resulting string. +the field width is one character. +.IP \fBs\fP +Next argument is taken to be a character pointer and characters from the +string are taken until a null character is reached; a specified field width +is not taken into account. +.IP \fBu\fP +The unsigned integer argument is converted to decimal. +.LP +.PP +Integral arguments are not truncated, even if their size exceeds the specified +field width. +Padding takes place only if the specified field width exceeds the actual width. +.PP +The printing routines build the string to be printed internally and use +.I sys_write +to print it. +.I Doprnt +takes +.I args +as the address of the arguments of the format string. +This allows routines, e.g. +.IR print , +to be defined as follows: +.br +.RS +.nf +/*VARARGS1*/ +print(fmt, argv) + char *fmt; + int argv; +{ + doprnt(STDOUT, fmt, &argv); +} +.fi +.RE +.SH FILES +.nf +~em/modules/lib/libprint.a +.fi +.SH MODULES +system(3), string(3) +.SH DIAGNOSTICS +.PP +Each illegal conversion specification is replaced by the string "". +.SH BUGS +The maximum length of the string to be printed is 1024 characters. +.SH SEE ALSO +printf(3) +.SH AUTHOR +Erik Baalbergen diff --git a/modules/src/print/print.c b/modules/src/print/print.c new file mode 100644 index 00000000..dee93c23 --- /dev/null +++ b/modules/src/print/print.c @@ -0,0 +1,14 @@ +/* $Header$ */ + +#include +#include "param.h" + +/*VARARGS1*/ +print(fmt, args) + char *fmt; + int args; +{ + char buf[SSIZE]; + + sys_write(STDOUT, buf, _format(buf, fmt, &args)); +} diff --git a/modules/src/print/print.h b/modules/src/print/print.h new file mode 100644 index 00000000..06bfc665 --- /dev/null +++ b/modules/src/print/print.h @@ -0,0 +1,11 @@ +/* $Header$ */ + +#define stdin STDIN +#define stdout STDOUT +#define stderr STDERR + +#define printf print +#define sprintf sprint +#define fprintf fprint + +#define FILE File diff --git a/modules/src/print/sprint.c b/modules/src/print/sprint.c new file mode 100644 index 00000000..64360ffa --- /dev/null +++ b/modules/src/print/sprint.c @@ -0,0 +1,14 @@ +/* $Header$ */ + +#include +#include "param.h" + +/*VARARGS1*/ +char * +sprint(buf, fmt, args) + char *buf, *fmt; + int args; +{ + buf[_format(buf, fmt, &args)] = '\0'; + return buf; +} From 2730da52c6d414d65a7fa58cb5b24fbb3d5881c8 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 6 Jan 1987 11:05:35 +0000 Subject: [PATCH 0418/1625] Initial revision --- modules/src/read_em/EM_vars.c | 7 + modules/src/read_em/Makefile | 86 +++++ modules/src/read_em/argtype | 14 + modules/src/read_em/em_comp.h | 64 ++++ modules/src/read_em/m_C_mnem | 91 +++++ modules/src/read_em/m_C_mnem_na | 15 + modules/src/read_em/mkcalls.c | 467 +++++++++++++++++++++++ modules/src/read_em/read_em.3 | 281 ++++++++++++++ modules/src/read_em/read_em.c | 452 ++++++++++++++++++++++ modules/src/read_em/reade.c | 640 ++++++++++++++++++++++++++++++++ modules/src/read_em/readk.c | 367 ++++++++++++++++++ 11 files changed, 2484 insertions(+) create mode 100644 modules/src/read_em/EM_vars.c create mode 100644 modules/src/read_em/Makefile create mode 100755 modules/src/read_em/argtype create mode 100644 modules/src/read_em/em_comp.h create mode 100755 modules/src/read_em/m_C_mnem create mode 100755 modules/src/read_em/m_C_mnem_na create mode 100644 modules/src/read_em/mkcalls.c create mode 100644 modules/src/read_em/read_em.3 create mode 100644 modules/src/read_em/read_em.c create mode 100644 modules/src/read_em/reade.c create mode 100644 modules/src/read_em/readk.c diff --git a/modules/src/read_em/EM_vars.c b/modules/src/read_em/EM_vars.c new file mode 100644 index 00000000..347ee07e --- /dev/null +++ b/modules/src/read_em/EM_vars.c @@ -0,0 +1,7 @@ +/* $Header$ */ + +/* Variables must be declared somewhere ... */ + +char *EM_error; +char *EM_filename; +unsigned int EM_lineno; diff --git a/modules/src/read_em/Makefile b/modules/src/read_em/Makefile new file mode 100644 index 00000000..2c4baf87 --- /dev/null +++ b/modules/src/read_em/Makefile @@ -0,0 +1,86 @@ +EMHOME = ../../.. +MODULES = $(EMHOME)/modules +HDIR = $(MODULES)/h +EMHDIR = $(EMHOME)/h +INCLUDES = -I$(HDIR) -I$(EMHDIR) +CFLAGS = -O $(INCLUDES) -DPRIVATE=static -DEXPORT= +INSTALL = $(MODULES)/install +COMPARE = $(MODULES)/compare + +TARGETS = libread_emk.a\ + libread_emkV.a\ + libread_emeV.a + +SRCFILES = em_comp.h\ + read_em.c\ + reade.c\ + readk.c\ + mkcalls.c\ + EM_vars.c + +EV_OFILES = read_emeV.o makecallsV.o EM_vars.o +KV_OFILES = read_emkV.o makecallsV.o EM_vars.o +K_OFILES = read_emk.o makecalls.o EM_vars.o + +all: $(TARGETS) + +install: all + $(INSTALL) h/em_comp.h + $(INSTALL) lib/libread_emk.a + $(INSTALL) lib/libread_emkV.a + $(INSTALL) lib/libread_emeV.a + $(INSTALL) man/read_em.3 + +cmp: all + $(COMPARE) h/em_comp.h + $(COMPARE) lib/libread_emk.a + $(COMPARE) lib/libread_emkV.a + $(COMPARE) lib/libread_emeV.a + $(COMPARE) man/read_em.3 + +pr: + @pr Makefile m_C_mnem m_C_mnem_na argtype $(SRCFILES) + +opr: + make pr | opr + +clean: + rm -f *.o *.a C_mnem C_mnem_narg + +libread_emk.a: $(K_OFILES) + ar r libread_emk.a $(K_OFILES) + -sh -c 'ranlib libread_emk.a' + +libread_emkV.a: $(KV_OFILES) + ar r libread_emkV.a $(KV_OFILES) + -sh -c 'ranlib libread_emkV.a' + +libread_emeV.a: $(EV_OFILES) + ar r libread_emeV.a $(EV_OFILES) + -sh -c 'ranlib libread_emeV.a' + +read_emk.o: read_em.c em_comp.h readk.c + $(CC) -c $(CFLAGS) -DCOMPACT read_em.c + mv read_em.o read_emk.o + +read_emkV.o: read_em.c em_comp.h readk.c + $(CC) -c $(CFLAGS) -DCOMPACT -DCHECKING read_em.c + mv read_em.o read_emkV.o + +read_emeV.o: read_em.c em_comp.h reade.c + $(CC) -c $(CFLAGS) -DCHECKING read_em.c + mv read_em.o read_emeV.o + +makecalls.o: C_mnem C_mnem_narg em_comp.h mkcalls.c + $(CC) -c $(CFLAGS) mkcalls.c + mv mkcalls.o makecalls.o + +makecallsV.o: C_mnem C_mnem_narg em_comp.h mkcalls.c + $(CC) -c $(CFLAGS) -DCHECKING mkcalls.c + mv mkcalls.o makecallsV.o + +C_mnem: m_C_mnem argtype + sh m_C_mnem > C_mnem + +C_mnem_narg: m_C_mnem_na argtype + sh m_C_mnem_na > C_mnem_narg diff --git a/modules/src/read_em/argtype b/modules/src/read_em/argtype new file mode 100755 index 00000000..3ca1d7dc --- /dev/null +++ b/modules/src/read_em/argtype @@ -0,0 +1,14 @@ +: argtype lists all em mnemonics that have an argument type equal to +: one of the letters specified in the argument +case x$# in + x2) + ;; + x*) echo "Usage: $0 argtypes " 1>&2 + exit 1 + ;; +esac +ed - $2 << A +1,/^\$/d +1,/^\$/d +1,/^\$/g/^\(...\) [$1].*/s//\\1/gp +A diff --git a/modules/src/read_em/em_comp.h b/modules/src/read_em/em_comp.h new file mode 100644 index 00000000..0d946c96 --- /dev/null +++ b/modules/src/read_em/em_comp.h @@ -0,0 +1,64 @@ +/* $Header$ */ + +struct e_instr { + int em_type; /* Type of this instr */ +#define EM_MNEM 256 /* A machine instruction */ +#define EM_PSEU 257 /* A pseudo */ +#define EM_STARTMES 258 /* Start of a MES pseudo */ +#define EM_MESARG 259 /* A member in a MES list */ +#define EM_ENDMES 260 /* End of a MES pseudo */ +#define EM_DEFILB 261 /* An instruction label definition */ +#define EM_DEFDLB 262 /* A numeric data label definition */ +#define EM_DEFDNAM 263 /* A non-numeric data label def */ +#define EM_ERROR 264 /* Recoverable error */ +#define EM_FATAL 265 /* Unrecoverable error */ + union { + struct { + int emus_opcode; /* Opcode of instruction */ + struct e_args *emus_args; /* Arguments of instruction */ + } emu_mp; + label emu_deflb; /* Numeric label definition */ + char *emu_defdnam; /* Non-numeric label definition */ + struct e_args *emu_arg; /* For an argument */ + } em_i; +#define em_opcode em_i.emu_mp.emus_opcode +#define em_args em_i.emu_mp.emus_args +#define em_deflb em_i.emu_deflb +#define em_defdnam em_i.emu_defdnam +#define em_arg em_i.emu_arg +}; + +struct e_args { + struct e_args *em_next; /* Next argument */ + short em_argtype; /* Type of this argument */ + union { + arith emu_cst; /* A constant */ + label emu_ilb; /* An instruction label */ + char *emu_pnam; /* A procedure name (not including '$') */ + struct { + label emus_dlb; + arith emus_noff; + } emu_ndlb; /* Numeric data label + offset */ + struct { + char *emus_dnam; + arith emus_soff; + } emu_sdlb; /* String data label + offset */ + struct { + char *emus_str; + arith emus_size; + } emu_con; /* An scon, icon, ucon or fcon */ + } em_value; +#define em_cst em_value.emu_cst +#define em_ilb em_value.emu_ilb +#define em_pnam em_value.emu_pnam +#define em_dlb em_value.emu_ndlb.emus_dlb +#define em_noff em_value.emu_ndlb.emus_noff +#define em_dnam em_value.emu_sdlb.emus_dnam +#define em_soff em_value.emu_sdlb.emus_soff +#define em_str em_value.emu_con.emus_str +#define em_size em_value.emu_con.emus_size +}; + +extern char *EM_error; +extern unsigned int EM_lineno; +extern char *EM_filename; diff --git a/modules/src/read_em/m_C_mnem b/modules/src/read_em/m_C_mnem new file mode 100755 index 00000000..f31347e8 --- /dev/null +++ b/modules/src/read_em/m_C_mnem @@ -0,0 +1,91 @@ +EM_TABLE=../../../etc/em_table +echo "switch(opcode) {" +for i in - cdflnorswz p b +do + list=`./argtype $i $EM_TABLE` + case $i in + -) args='()' + echo "/* no arguments */" + ;; + cdflnorswz) + args='(arg->em_cst)' + echo "/* one integer constant argument */" + ;; + p) + args='(arg->em_pnam)' + echo "/* a procedure name argument */" + ;; + b) + +: Grumbl, an instruction label as argument is encoded in a sp_cst2 + + args='((label) (arg->em_cst))' + echo "/* An instruction label argument */" + ;; + esac + for i in $list + do + cat << EOF + case op_$i: + C_$i$args; + break; +EOF + done +done +list=`./argtype g $EM_TABLE` +cat << 'EOF' + default: +/* a "g" argument */ + if (arg->em_argtype == nof_ptyp) { + switch(opcode) { + default: + EM_error = "Illegal mnemonic"; + break; +EOF +for i in $list +do + cat << EOF + case op_$i: + C_${i}_dlb(arg->em_dlb, arg->em_noff); + break; +EOF +done +cat << 'EOF' + } + } + else if (arg->em_argtype == sof_ptyp) { + switch(opcode) { + default: + EM_error = "Illegal mnemonic"; + break; +EOF +for i in $list +do + cat << EOF + case op_$i: + C_${i}_dnam(arg->em_dnam, arg->em_soff); + break; +EOF +done +cat << 'EOF' + } + } + else /*argtype == cst_ptyp */ { + switch(opcode) { + default: + EM_error = "Illegal mnemonic"; + break; +EOF +for i in $list +do + cat << EOF + case op_$i: + C_$i(arg->em_cst); + break; +EOF +done +cat << 'EOF' + } + } +} +EOF diff --git a/modules/src/read_em/m_C_mnem_na b/modules/src/read_em/m_C_mnem_na new file mode 100755 index 00000000..d0bdab94 --- /dev/null +++ b/modules/src/read_em/m_C_mnem_na @@ -0,0 +1,15 @@ +EM_TABLE=../../../etc/em_table +list=`./argtype w $EM_TABLE` +echo "switch(opcode) {" +for i in $list +do + cat << EOF + case op_$i: + C_${i}_narg(); + break; +EOF +done +cat << EOF + default: EM_error = "Illegal mnemonic"; +} +EOF diff --git a/modules/src/read_em/mkcalls.c b/modules/src/read_em/mkcalls.c new file mode 100644 index 00000000..3aee2fb6 --- /dev/null +++ b/modules/src/read_em/mkcalls.c @@ -0,0 +1,467 @@ +/* makecalls: expand a datastructure as delivered by "EM_getline" + into calls to the procedural interface. + Exported routine: + EM_mkcalls +*/ + +#include +#include +#include +#include +#include "em_ptyp.h" +#include +#include "em_comp.h" +#include + +extern char em_flag[]; /* One per EM instruction: indicates parameter kind */ +extern short em_ptyp[]; /* One per parameter kind: indicates parameter type */ + +static int listtype = 0; /* indicates pseudo when generating code for + variable length argument lists + (only for MES) + */ + +#ifdef CHECKING +/* c_getarg: Check the argument indicated by "args". + The argument must be of a type allowed by "typset". + Return a pointer to the next argument. +*/ +PRIVATE struct e_args * +c_getarg(args, typset) + register struct e_args *args; +{ + + if (((!typset) && args) || + ((!args) && typset)) { + /* End of arguments expected, but there are more, or + an argument expected, but there is none + */ + EM_error = "Illegal number of parameters"; + return 0; + } + + if (!args) return 0; + if (!(args->em_argtype & typset)) { + /* Type error */ + EM_error = "Illegal parameter type"; + } + + return args->em_next; +} +#else not CHECKING +#define c_getarg(arg, x) ((arg) ? (arg)->em_next : (arg)) +#endif CHECKING + +/* EM_doinstr: An EM instruction +*/ +PRIVATE +EM_doinstr(opcode, arg) + register struct e_args *arg; +{ + register int parametertype; /* parametertype of the instruction */ + register struct e_args *args; + + parametertype = em_flag[opcode-sp_fmnem] & EM_PAR; +#ifdef CHECKING + if (parametertype != PAR_NO && parametertype != PAR_W) { + if (!arg) { + EM_error = "Illegal number of parameters"; + return; + } + } +#endif CHECKING + switch(parametertype) { + case PAR_NO: + break; + default: + args = c_getarg(arg, em_ptyp[parametertype]); + args = c_getarg(args, 0); + break; + case PAR_W: + if (arg) { + args = c_getarg(arg, cst_ptyp); + args = c_getarg(args, 0); + } + else { +#include "C_mnem_narg" + return; + } + break; + } +#include "C_mnem" +} + +PRIVATE +EM_dopseudo(opcode, args) + register struct e_args *args; +{ + register struct e_args *arg; + + switch(opcode) { + case ps_exc: { + register struct e_args *args2; + + arg = c_getarg(args, cst_ptyp); + args2 = c_getarg(arg, cst_ptyp); + args2 = c_getarg(args2, 0); + C_exc(args->em_cst, arg->em_cst); + break; + } + case ps_hol: { + register struct e_args *args2, *args3; + + arg = c_getarg(args, cst_ptyp); + args2 = c_getarg(arg, arg_ptyp); + args3 = c_getarg(args2, cst_ptyp); + args3 = c_getarg(args3, 0); + switch(arg->em_argtype) { + case cst_ptyp: + C_hol_cst(args->em_cst, + arg->em_cst, + args2->em_cst); + break; + case ico_ptyp: + C_hol_icon(args->em_cst, + arg->em_str, + arg->em_size, + args2->em_cst); + break; + case uco_ptyp: + C_hol_ucon(args->em_cst, + arg->em_str, + arg->em_size, + args2->em_cst); + break; + case fco_ptyp: + C_hol_fcon(args->em_cst, + arg->em_str, + arg->em_size, + args2->em_cst); + break; + case sof_ptyp: + C_hol_dnam(args->em_cst, + arg->em_dnam, + arg->em_soff, + args2->em_cst); + break; + case nof_ptyp: + C_hol_dlb(args->em_cst, + arg->em_dlb, + arg->em_noff, + args2->em_cst); + break; + case ilb_ptyp: + C_hol_ilb(args->em_cst, + arg->em_ilb, + args2->em_cst); + break; + case pro_ptyp: + C_hol_pnam(args->em_cst, + arg->em_pnam, + args2->em_cst); + break; + default: + EM_error = "Illegal parameter type"; + break; + } + break; + } + case ps_bss: { + register struct e_args *args2, *args3; + + arg = c_getarg(args, cst_ptyp); + args2 = c_getarg(arg, arg_ptyp); + args3 = c_getarg(args2, cst_ptyp); + args3 = c_getarg(args3, 0); + switch(arg->em_argtype) { + case cst_ptyp: + C_bss_cst(args->em_cst, + arg->em_cst, + args2->em_cst); + break; + case ico_ptyp: + C_bss_icon(args->em_cst, + arg->em_str, + arg->em_size, + args2->em_cst); + break; + case uco_ptyp: + C_bss_ucon(args->em_cst, + arg->em_str, + arg->em_size, + args2->em_cst); + break; + case fco_ptyp: + C_bss_fcon(args->em_cst, + arg->em_str, + arg->em_size, + args2->em_cst); + break; + case sof_ptyp: + C_bss_dnam(args->em_cst, + arg->em_dnam, + arg->em_soff, + args2->em_cst); + break; + case nof_ptyp: + C_bss_dlb(args->em_cst, + arg->em_dlb, + arg->em_noff, + args2->em_cst); + break; + case ilb_ptyp: + C_bss_ilb(args->em_cst, + arg->em_ilb, + args2->em_cst); + break; + case pro_ptyp: + C_bss_pnam(args->em_cst, + arg->em_pnam, + args2->em_cst); + break; + default: + EM_error = "Illegal parameter type"; + break; + } + break; + } + case ps_end: + if (args) { + arg = c_getarg(args, cst_ptyp); + arg = c_getarg(arg, 0); + C_end(args->em_cst); + break; + } + C_end_narg(); + break; + case ps_exa: + case ps_ina: + arg = c_getarg(args, lab_ptyp); + arg = c_getarg(arg, 0); + if (args->em_argtype == nof_ptyp) { + if (opcode == ps_exa) { + C_exa_dlb(args->em_dlb); + } + else C_ina_dlb(args->em_dlb); + break; + } + if (opcode == ps_exa) { + C_exa_dnam(args->em_dnam); + } + else C_ina_dnam(args->em_dnam); + break; + case ps_exp: + case ps_inp: + arg = c_getarg(args, pro_ptyp); + arg = c_getarg(arg, 0); + if (opcode == ps_exp) { + C_exp(args->em_pnam); + } + else C_inp(args->em_pnam); + break; + case ps_pro: + arg = c_getarg(args, pro_ptyp); + if (arg) { + struct e_args *args2; + + args2 = c_getarg(arg, cst_ptyp); + args2 = c_getarg(args2, 0); + C_pro(args->em_pnam, arg->em_cst); + } + else C_pro_narg(args->em_pnam); + break; + case ps_con: + arg = c_getarg(args, val_ptyp); + arg = c_getarg(arg, 0); + switch(args->em_argtype) { + case ilb_ptyp: + C_con_ilb(args->em_ilb); + break; + case nof_ptyp: + C_con_dlb(args->em_dlb, args->em_noff); + break; + case sof_ptyp: + C_con_dnam(args->em_dnam, args->em_soff); + break; + case cst_ptyp: + C_con_cst(args->em_cst); + break; + case pro_ptyp: + C_con_pnam(args->em_pnam); + break; + case str_ptyp: + C_con_scon(args->em_str, args->em_size); + break; + case ico_ptyp: + C_con_icon(args->em_str, args->em_size); + break; + case uco_ptyp: + C_con_ucon(args->em_str, args->em_size); + break; + case fco_ptyp: + C_con_fcon(args->em_str, args->em_size); + break; + default: + EM_error = "Illegal argument type"; + return 0; + } + break; + case ps_rom: + arg = c_getarg(args, val_ptyp); + arg = c_getarg(arg, 0); + switch(args->em_argtype) { + case ilb_ptyp: + C_rom_ilb(args->em_ilb); + break; + case nof_ptyp: + C_rom_dlb(args->em_dlb, args->em_noff); + break; + case sof_ptyp: + C_rom_dnam(args->em_dnam, args->em_soff); + break; + case cst_ptyp: + C_rom_cst(args->em_cst); + break; + case pro_ptyp: + C_rom_pnam(args->em_pnam); + break; + case str_ptyp: + C_rom_scon(args->em_str, args->em_size); + break; + case ico_ptyp: + C_rom_icon(args->em_str, args->em_size); + break; + case uco_ptyp: + C_rom_ucon(args->em_str, args->em_size); + break; + case fco_ptyp: + C_rom_fcon(args->em_str, args->em_size); + break; + default: + EM_error = "Illegal argument type"; + return 0; + } + break; + default: + EM_error = "Illegal pseudo instruction"; + break; + } +} + +PRIVATE +EM_docon(args) + register struct e_args *args; +{ + register struct e_args *arg; + + arg = c_getarg(args, val_ptyp); + arg = c_getarg(arg, 0); + switch(args->em_argtype) { + case ilb_ptyp: + C_ilb(args->em_ilb); + break; + case nof_ptyp: + C_dlb(args->em_dlb, args->em_noff); + break; + case sof_ptyp: + C_dnam(args->em_dnam, args->em_soff); + break; + case cst_ptyp: + C_cst(args->em_cst); + break; + case pro_ptyp: + C_pnam(args->em_pnam); + break; + case str_ptyp: + C_scon(args->em_str, args->em_size); + break; + case ico_ptyp: + C_icon(args->em_str, args->em_size); + break; + case uco_ptyp: + C_ucon(args->em_str, args->em_size); + break; + case fco_ptyp: + C_fcon(args->em_str, args->em_size); + break; + default: + EM_error = "Illegal argument type"; + break; + } +} + +PRIVATE +EM_dostartmes(args) + register struct e_args *args; +{ + register struct e_args *arg; + + if (listtype) { + EM_error = "Message not ended"; + return; + } + arg = c_getarg(args, cst_ptyp); + arg = c_getarg(arg, 0); + C_mes_begin(args->em_cst); + listtype = ps_mes; +} + +EXPORT int +EM_mkcalls(line) + register struct e_instr *line; +{ + +#ifdef CHECKING + if (listtype && line->em_type != EM_MESARG && line->em_type != EM_ENDMES) { + EM_error = "Message not ended"; + return 0; + } +#endif CHECKING + EM_error = 0; + switch(line->em_type) { + default: + EM_error = "Illegal EM line"; + break; + case EM_MNEM: + /* normal instruction */ + EM_doinstr(line->em_opcode, line->em_args); + break; + case EM_DEFILB: + /* defining occurrence of an instruction label */ + C_df_ilb(line->em_deflb); + break; + case EM_DEFDLB: + /* defining occurrence of a global data label */ + C_df_dlb(line->em_deflb); + break; + case EM_DEFDNAM: + /* defining occurrence of a non-numeric data label */ + C_df_dnam(line->em_defdnam); + break; + case EM_PSEU: + /* pseudo */ + EM_dopseudo(line->em_opcode, line->em_args); + break; + case EM_STARTMES: + /* start of a MES pseudo */ + EM_dostartmes(line->em_arg); + break; + case EM_MESARG: + case EM_ENDMES: +#ifdef CHECKING + if (!listtype) { + EM_error = "Message not started"; + return 0; + } +#endif + if (line->em_type == EM_MESARG) { + EM_docon(line->em_args); + break; + } + C_mes_end(); + listtype = 0; + break; + } + if (EM_error) return 0; + return 1; +} diff --git a/modules/src/read_em/read_em.3 b/modules/src/read_em/read_em.3 new file mode 100644 index 00000000..4cadc3ed --- /dev/null +++ b/modules/src/read_em/read_em.3 @@ -0,0 +1,281 @@ +.TH READ_EM 3ACK "March 17, 1986" +.SH NAME +EM_open, EM_getinstr, EM_close, +EM_mkcalls\ \-\ a module to read EM assembly code +.SH SYNOPSIS +.B #include +.br +.B #include +.br +.B #include +.br +.B #include +.br +.B #include +.br +.B #include +.br +.B #include +.PP +.B int EM_open(filename) +.br +.B EM_close() +.br +.B char *filename; +.PP +.B struct e_instr *EM_getinstr() +.PP +.B int EM_mkcalls(instr) +.br +.B struct e_instr *instr; +.PP +.B char *EM_error; +.PP +.B unsigned int EM_lineno; +.PP +.B char *EM_filename; +.SH DESCRIPTION +This package provides routines to read EM assembly code. +The object is to simplify the program +writer's task of reading EM assembly code, +either in compact or human-readable form. +.PP +\fIEM_open\fR must be called as initializer of the package. +If \fIfilename\fR is a null pointer, reading is done from standard input, +otherwise it is done from the file \fIfilename\fR. +\fIEM_open\fR returns 1 on success and 0 on failure +with an error message in \fIEM_error\fR. +\fIEM_close\fR must be called after all other calls to this package. +.PP +\fIEM_getinstr\fR reads an EM instruction, and +returns it as a pointer to a structure having the following +layout: +.br +.PP +.ta \w'struct'u +\w'struct e_instr *\ \ \ \ \ \ \ \ \ 'u +\w'em_argtype\ \ \ \ \ \ 'u +.nf +struct e_instr { + int em_type; /* Type of this instruction */ + union { + struct { + int emus_opcode; /* Opcode of instruction */ + struct e_args *emus_args; /* Arguments of instruction */ + } emu_mp; + label emu_deflb; /* Numeric label definition */ + char *emu_defdnam; /* Non-numeric label definition */ + struct e_args *emu_arg; /* For a message argument */ + } em_i; +#define em_opcode \kaem_i.emu_mp.emus_opcode +#define em_args\h'|\nau'em_i.emu_mp.emus_args +#define em_deflb\h'|\nau'em_i.emu_deflb +#define em_defdnam\h'|\nau'em_i.emu_defdnam +#define em_arg\h'|\nau'em_i.emu_arg +}; +.fi +.PP +Possible arguments to the EM instruction read are supplied in a linked list +of structures: +.PP +.nf +struct e_args { + struct e_args *em_next; /* Next argument */ + short em_argtype; /* Type of this argument */ + union { + arith emu_cst; /* A constant */ + label emu_ilb; /* An instruction label */ + char *emu_pnam; /* A procedure name (not including '$') */ + struct { + label emus_dlb; + arith emus_noff; + } emu_ndlb; /* Numeric data label + offset */ + struct { + char *emus_dnam; + arith emus_soff; + } emu_sdlb; /* String data label + offset */ + struct { + char *emus_str; + arith emus_size; + } emu_con; /* An scon, icon, ucon or fcon */ + } em_value; +#define em_cst\h'|\nau'em_value.emu_cst +#define em_ilb\h'|\nau'em_value.emu_ilb +#define em_pnam\h'|\nau'em_value.emu_pnam +#define em_dlb\h'|\nau'em_value.emu_ndlb.emus_dlb +#define em_noff\h'|\nau'em_value.emu_ndlb.emus_noff +#define em_dnam\h'|\nau'em_value.emu_sdlb.emus_dnam +#define em_soff\h'|\nau'em_value.emu_sdlb.emus_soff +#define em_str\h'|\nau'em_value.emu_con.emus_str +#define em_size\h'|\nau'em_value.emu_con.emus_size +}; +.fi +.PP +The named types \fBarith\fR and \fBlabel\fR refer to types on the local machine +that are suitable for doing arithmetic and storing EM numeric labels +respectively. +Common definitions are \fBlong\fR for \fBarith\fR and \fBunsigned int\fR for +\fBlabel\fR. +.PP +The \fIe_instr\fR structure consists of the fields +\fIem_type\fR, containing the type of this \fIe_instr\fR, and +\fIem_i\fR, containing its value of this \fIe_instr\fR. +.PP +The possible values of +\fIem_type\fR, defined in , are summarized below: +.br +.ta \w'EM_STARTMES\ \ \ 'u +\w'em_defdnam\ \ \ 'u +.di xx + \ka +.br +.di +.IP "Value Selector" \nau +Meaning +.IP "EM_MNEM em_opcode" \nau +an EM machine instruction. +.br +.PD 0 +.IP " em_args" \nau +The \fIem_opcode\fR field +contains the opcode of the instruction, and \fIem_args\fR may indicate +arguments. +.IP "EM_PSEU em_opcode" \nau +an EM pseudo instruction. +.IP " em_args" \nau +The \fIem_opcode\fR field +contains the opcode, and \fIem_args\fR may indicate arguments. +As consecutive CON-pseudos are allocated consecutively, a CON delivered by +\fIEM_getinstr\fR has exactly one argument. +If the CON-pseudo read has more, they are delivered as separate CON's. +The same holds for ROM-pseudos. +Also, if the length of a string constant exceeds 256 characters, it will be +delivered as several CON's or ROM's. +.IP "EM_STARTMES em_arg" \nau +the start of a MES pseudo. +.br +There is one argument: the message number. +The other arguments, if any, are delivered as separate EM_MESARG's. +.IP "EM_MESARG em_arg" \nau +an argument of a MES pseudo. +.IP "EM_ENDMES none" \nau +the end of a MES pseudo. +.IP "EM_DEFILB em_deflb" \nau +an instruction label definition. +.br +The field \fIem_deflb\fR contains the label (instruction labels are always +numeric). +.IP "EM_DEFDLB em_deflb" \nau +a numeric data label definition. +.br +The field \fIem_deflb\fR contains the label. +.IP "EM_DEFDNAM em_defdnam" \nau +a non-numeric data label definition. +.br +The field \fIem_defdnam\fR contains the label. +.IP "EM_ERROR none" \nau +an error in the input. +.br +\fIEM_error\fR +contains an error message. +.IP "EM_FATAL none" \nau +a fatal error. +.br +\fIEM_error\fR contains an +error message. +.PD +.PP +The \fIe_args\fR structure consists of the fields +\fIem_next\fR, containing a pointer to the next argument or null, +the field \fIem_argtype\fR, containing the type of this argument, and +the field \fIem_value\fR, containing the value of the argument. +The possible values of \fIem_argtype\fR, defined in , +are summarized below: +.br +.ta \w'dlb_ptyp\ \ \ \ 'u +\w'em_opcode\ \ \ 'u +.di xx + \ka +.br +.di +.IP "Value Selector" \nau +Meaning +.IP "ilb_ptyp em_ilb" \nau +an instruction label. +.PD 0 +.IP "nof_ptyp em_dlb" \nau +an offset from a numeric data label. +.IP " em_noff" \nau +The +\fIem_noff\fR field contains the offset and the +\fIem_dlb\fR field contains the label. +.IP "sof_ptyp em_dnam" \nau +an offset from a non-numeric data label. +.IP " em_soff" \nau +The \fIem_soff\fR field contains the offset and the \fIem_dnam\fR field +contains the label, represented as a string. +.IP "cst_ptyp em_cst" \nau +a numeric constant. +.IP "pro_ptyp em_pnam" \nau +a procedure name, not including the '$', +represented as a string. +.IP "str_ptyp em_str" \nau +a string constant. +.IP " em_size" \nau +The string is found in \fIem_str\fR, represented as a row of bytes, of +length \fIem_size\fR. +.IP "ico_ptyp em_str" \nau +an integer constant. +.IP " em_size" \nau +A string representation of the constant is found in \fIem_str\fR. +It has size \fIem_size\fR bytes on the target machine. +.IP "uco_ptyp em_str" \nau +an unsigned constant. +.IP " em_size" \nau +A string representation of the constant is found in \fIem_str\fR. +It has size \fIem_size\fR bytes on the target machine. +.IP "fco_ptyp em_str" \nau +a floating constant. +.IP " em_size" \nau +A string representation of the constant is found in \fIem_str\fR. +It has size \fIem_size\fR bytes on the target machine. +.PD +.PP +The routine \fIEM_mkcalls\fR "translates" the EM instruction indicated +by \fIinstr\fR +into calls of the procedural interface defined in \fIem_code\fR(3L). +It returns 1 if it succeeds, 0 if it fails for some reason. The +reason can then be found in \fIEM_error\fR. +.PP +\fIEM_lineno\fR contains the line number of the last line read by +\fIEM_getinstr\fR. +.PP +\fIEM_filename\fR contains a filename. It usually contains the value +given as parameter to \fIEM_open\fR, but may have a different value, when +the input was the result of some preprocessing. +.PP +.SH FILES +.nf +~em/modules/h/em.h +~em/modules/h/em_ptyp.h +~em/modules/h/em_comp.h +~em/modules/lib/libread_emk.a: non-checking library for reading compact EM code +~em/modules/lib/libread_emkV.a: checking library for reading compact EM code +~em/modules/lib/libread_emeV.a: checking library for reading human-readable EM code +.fi +.SH MODULES +em_code(3), string(3), system(3), ~em/lib/em_data.a +.SH "SEE ALSO" +em_code(3) +.br +A.S. Tanenbaum, H. v Staveren, E.G. Keizer, J.W. Stevenson, "\fBDescription +of a Machine Architecture for use with Block Structured Languages\fR", +Informatica Rapport IR-81, Vrije Universiteit, Amsterdam, 1983. +.SH DIAGNOSTICS +\fIEM_getinstr\fR returns a null pointer on end of file. +.SH REMARKS +All information must be considered to be contained in a static area so it +must be copied to be saved. +.SH BUGS +As CON's and ROM's may be delivered in several parts, the count fields in +a static exchange may be wrong. +.PP +Please report bugs to the author. +.SH AUTHOR +Ceriel J.H. Jacobs diff --git a/modules/src/read_em/read_em.c b/modules/src/read_em/read_em.c new file mode 100644 index 00000000..085fa414 --- /dev/null +++ b/modules/src/read_em/read_em.c @@ -0,0 +1,452 @@ +/* Read_em: a module to read either compact or human readable EM code. + Exported are the following routines: + EM_open() : has a parameter representing either a pointer to a + filename or a null pointer, indicating that input is + from standard input. This routine initializes for + reading. + EM_getinstr() : Delivers the next EM instruction in a format + defined in . + Imported are: + The constants COMPACT (either defined or not defined) and + CHECKING (again either defined or not defined), + some routines from the system module. and the em_code module +*/ + +#include +#include +#include +#include +#include +#include +#include "em_ptyp.h" +#include "em_comp.h" +#include +#include + +/* Buffered input */ + +#define getbyte() (*_ich ? (*_ich++ & 0377) : _fill()) +#define ungetbyte(uch) ((uch) >= 0 && (*--_ich = (uch))) +#define init_input() (_fill(), _ich--) + +#define EOF -1 + +static File *fd; +static char *_ich; + +PRIVATE int +_fill() +{ + static char text[BUFSIZ + 1]; + static int sz; + + if (_ich && _ich < &text[sz]) return _ich++, '\0'; + if (sys_read(fd, text, BUFSIZ, &sz) && + sz > 0 + ) { + text[sz] = '\0'; + return _ich = text, (*_ich++&0377); + } + else return EOF; +} + +#define NARGS 3 /* Maximum number of arguments */ +#define STRSIZ 256 /* Maximum length of strings */ + +static struct e_instr emhead; /* Where we put the head */ +static struct e_args emargs[NARGS]; /* Where we put the arguments */ +static struct e_args *i_emargs; +#define argentry() (i_emargs++) +static struct string { + int length; + char str[STRSIZ + 1]; +} strings[NARGS]; /* Room for strings */ +static struct string *i_strings; /* Index of last one used */ +#define stringentry() (i_strings++) + +static struct e_args *argp; /* Indicates arguments yet to be + delivered + */ +static arith strleft; /* count # of chars left to read + in a string + */ + +static int state; /* What state are we in? */ +#define CON 01 /* Reading a CON */ +#define ROM 02 /* Reading a ROM */ +#define MES 03 /* Reading a MES */ +#define PSEUMASK 03 +#define INSTRING 010 /* Reading a string */ + +static int EM_initialized; /* EM_open called? */ + +static long wordmask[] = { /* allowed bits in a word */ + 0x00000000, + 0x000000FF, + 0x0000FFFF, + 0x00000000, + 0xFFFFFFFF +}; + +static int wsize, psize; /* word size and pointer size */ + +#ifdef CHECKING +static char *argrange = "Argument range error"; +#define check(expr) (expr || (xerror(argrange))) +#else not CHECKING +#define check(x) /* nothing */ +#endif CHECKING + +/* Error handling +*/ + +PRIVATE +xerror(s) + char *s; +{ + if (emhead.em_type != EM_FATAL) emhead.em_type = EM_ERROR; + if (!EM_error) EM_error = s; +} + +PRIVATE +xfatal(s) + char *s; +{ + emhead.em_type = EM_FATAL; + if (!EM_error) EM_error = s; +} + +#ifdef COMPACT +#include "readk.c" +#else not COMPACT +#include "reade.c" +#endif COMPACT + +/* EM_open: Open input file, get magic word if COMPACT. +*/ +EXPORT int +EM_open(filename) + char *filename; +{ + + if (EM_initialized) { + EM_error = "EM_open already called"; + return 0; + } + + if (filename) { + if (!sys_open(filename, OP_READ, &fd)) { + EM_error = "Could not open input file"; + return 0; + } + } + else fd = STDIN; + EM_filename = filename; + init_input(); + +#ifdef COMPACT + if (get16() != sp_magic) { + EM_error = "Illegal magic word"; + return 0; + } +#else not COMPACT + inithash(); /* initialize hashtable */ +#endif COMPACT + + EM_initialized = 1; + return 1; +} + +/* EM_close: Close input file +*/ +EXPORT +EM_close() +{ + + register struct string *pstr; + + if (fd != STDIN) { + sys_close(fd); + fd = STDIN; + } + EM_initialized = 0; +} + + +/* startmes: handle the start of a message. The only important thing here + is to get the wordsize and pointer size, and remember that they + have already been read, not only to check that they are not specified + again, but also to deliver the arguments on next calls to EM_getinstr. + This is indicated by the variable "argp". +*/ +PRIVATE +startmes(p) + register struct e_instr *p; +{ + register struct e_args *ap; + + ap = getarg(cst_ptyp); + p->em_arg = ap; + state = MES; + + if (ap->em_cst == ms_emx) { + if (wsize || psize) { + xerror("Duplicate ms_emx"); + } + argp = ap = getarg(cst_ptyp); + wsize = ap->em_cst; + ap->em_next = getarg(cst_ptyp); + ap = ap->em_next; + psize = ap->em_cst; + } +} + + +/* EM_getinstr: read an "EM_line" +*/ +EXPORT struct e_instr * +EM_getinstr() +{ + register struct e_instr *p = &emhead; + register struct e_args *args; + + i_emargs = emargs; + i_strings = strings; + EM_error = 0; +#ifdef CHECKING + if (!EM_initialized) { + EM_error = "Initialization not done"; + p->em_type = EM_FATAL; + return p; + } +#endif CHECKING + + if (argp) { /* We have some arguments left to deliver */ + args = argp; + argp = args->em_next; + p->em_type = EM_MESARG; + p->em_args = args; + args->em_next = 0; + return p; + } + + if (!state) { /* All clear, get a new line */ + p = gethead(); + if (!p) { /* End of file */ + return p; + } + switch(p->em_type) { + case EM_MNEM: { + register int i,j; + register struct e_args *ap; + extern char em_flag[]; + extern short em_ptyp[]; + + p->em_args = 0; + j = em_flag[p->em_opcode - sp_fmnem] & EM_PAR; + i = em_ptyp[j]; + if (j == PAR_NO) { /* No arguments */ + break; + } +#ifndef COMPACT + if (j == PAR_B) i = ptyp(sp_ilb2); +#endif COMPACT + ap = getarg(i); +#ifndef COMPACT + if (j == PAR_B) { + ap->em_cst = ap->em_ilb; + ap->em_argtype = cst_ptyp; + } +#endif COMPACT + /* range checking + */ +#ifdef CHECKING + if (wsize <= 4 && psize <= 4) switch(j) { + case PAR_B: + check(ap->em_cst <= 32767); + /* Fall through */ + case PAR_N: + check(ap->em_cst >= 0); + break; + case PAR_G: + if (ap->em_argtype == cst_ptyp) { + check(ap->em_cst >= 0); + } + /* Fall through */ + case PAR_F: + /* ??? not in original em_decode or em_encode */ + case PAR_L: + { arith m = ap->em_cst >= 0 ? ap->em_cst : + - ap->em_cst; + + /* Check that the number fits in a pointer */ + check((m & ~wordmask[psize]) == 0); + break; + } + case PAR_W: + if (!ap) break; + check((ap->em_cst & ~wordmask[wsize]) == 0); + /* Fall through */ + case PAR_S: + check(ap->em_cst > 0); + /* Fall through */ + case PAR_Z: + check(ap->em_cst >= 0 && + ap->em_cst % wsize == 0); + break; + case PAR_O: + check(ap->em_cst > 0 && + ( ap->em_cst % wsize == 0 || + wsize % ap->em_cst == 0)); + break; + case PAR_R: + check(ap->em_cst >= 0 && ap->em_cst <= 2); + break; + } +#endif CHECKING + p->em_args = ap; +#ifndef COMPACT + checkeol(); +#endif COMPACT + } + break; + case EM_PSEU: + /* handle a pseudo, read possible arguments. CON's and + ROM's are handled especially: Only one argument is + read, and a mark is set that an argument list of + type ROM or CON is in process + */ + { + register struct e_args *ap = 0, *ap1; + + switch(p->em_opcode) { + case ps_bss: + case ps_hol: + ap = getarg(cst_ptyp); + ap->em_next = ap1 = getarg(par_ptyp); + ap->em_next->em_next = ap1 = getarg(cst_ptyp); +#ifdef CHECKING + /* Check that the last value is 0 or 1 + */ + if (ap1->em_cst != 1 && ap1->em_cst != 0) { + xerror("Third argument of hol/bss not 0/1"); + } +#endif CHECKING + break; + case ps_exa: + case ps_ina: + ap = getarg(lab_ptyp); + break; + case ps_exp: + case ps_inp: + ap = getarg(pro_ptyp); + break; + case ps_exc: + ap = getarg(cst_ptyp); + ap->em_next = getarg(cst_ptyp); + break; + case ps_pro: + ap = getarg(pro_ptyp); + ap->em_next = getarg(cst_ptyp|ptyp(sp_cend)); + break; + case ps_end: + ap = getarg(cst_ptyp|ptyp(sp_cend)); + break; + case ps_con: + ap = getarg(val_ptyp); + state |= CON; + break; + case ps_rom: + ap = getarg(val_ptyp); + state |= ROM; + break; + default: + xerror("Bad pseudo"); + break; + } + p->em_args = ap; + } +#ifndef COMPACT + if (p->em_opcode != ps_con && p->em_opcode != ps_rom) { + checkeol(); + } +#endif COMPACT + break; + case EM_STARTMES: + startmes(p); + break; + } + if (!wsize) { + xerror("EM code should start with mes 2"); + } + if (EM_error && p->em_type != EM_FATAL) p->em_type = EM_ERROR; + return p; + } + + if (state & INSTRING) { /* We already delivered part of a string. + Deliver the next part + */ + register struct string *s; + + s = getstring(0); + args = argentry(); + args->em_next = 0; + args->em_argtype = str_ptyp; + args->em_str = s->str; + args->em_size = s->length; + switch(state & PSEUMASK) { + default: + assert(0); + case MES: + xerror("String too long in message"); + /* p->em_type = EM_MESARG; + p->em_arg = args; + */ + break; + case CON: + p->em_type = EM_PSEU; + p->em_opcode = ps_con; + p->em_args = args; + break; + case ROM: + p->em_type = EM_PSEU; + p->em_opcode = ps_rom; + p->em_args = args; + break; + } + if (EM_error && p->em_type != EM_FATAL) p->em_type = EM_ERROR; + return p; + } + + /* Here, we are in a state reading arguments */ + args = getarg(any_ptyp); + if (EM_error && p->em_type != EM_FATAL) { + p->em_type = EM_ERROR; + return p; + } + if (!args) { /* No more arguments */ +#ifndef COMPACT + checkeol(); +#endif + if (state == MES) { + state = 0; + p->em_type = EM_ENDMES; + return p; + } + /* Here, we have to get the next instruction */ + state = 0; + return EM_getinstr(); + } + + /* Here, there was an argument */ + if (state == MES) { + p->em_type = EM_MESARG; + p->em_arg = args; + return p; + } + p->em_type = EM_PSEU; + p->em_args = args; + if (state == CON) p->em_opcode = ps_con; + else p->em_opcode = ps_rom; + return p; +} diff --git a/modules/src/read_em/reade.c b/modules/src/read_em/reade.c new file mode 100644 index 00000000..16ba0c0f --- /dev/null +++ b/modules/src/read_em/reade.c @@ -0,0 +1,640 @@ +/* This file is ment to be included in the file read_emeV.c. + It contains the part that takes care of the reading of human readable + EM-code. +*/ + +#include + +/* #define XXX_YYY /* only for early debugging */ + +#ifdef XXX_YYY +#define out(str) ((void) sys_write(STDOUT, str, strlen(str))) +#else +#define out(s) +#endif + +#define fit16i(x) ((x) >= -32768L && (x) <= 32767L) + +#define HSIZE 256 /* Size of hashtable for mnemonics */ + +static int hashtab[HSIZE]; /* The hashtable for mnemonics */ + +static int argnum; /* Number of arguments */ + +#define COMMENTSTARTER ';' + +/* inithash, pre_hash, hash: Simple hashtable mechanism +*/ +PRIVATE int +hash(s) + register char *s; +{ + register int h = 0; + + while (*s) { + h <<= 1; + h += *s++; + } + return h; +} + +PRIVATE +pre_hash(i, s) + char *s; +{ + register int h; + + assert(i != 0); + h = hash(s); + + for (;;) { + h++; + if (h >= HSIZE) h %= HSIZE; + if (hashtab[h] == 0) { + hashtab[h] = i; + return; + } + } + /*NOTREACHED*/ +} + +extern char em_mnem[][4]; +extern char em_pseu[][4]; + +PRIVATE +inithash() +{ + register int i; + + /* Enter instructions ... */ + for (i = sp_fmnem; i <= sp_lmnem; i++) { + pre_hash(i, em_mnem[i - sp_fmnem]); + } + + /* and pseudos ... */ + for (i = sp_fpseu; i <= sp_lpseu; i++) { + pre_hash(i, em_pseu[i - sp_fpseu]); + } +} + +/* nospace: skip until we find a non-space character. Also skip + comments. +*/ +PRIVATE int +nospace() +{ + register int c; + + do c = getbyte(); + while (isspace(c) && c != '\n'); + + if (c == COMMENTSTARTER) { + do c = getbyte(); + while (c != '\n' && c != EOF); + } + + return c; +} + +/* syntax: Put an error message in EM_error and skip to the end of the line +*/ +PRIVATE +syntax(s) + char *s; +{ + register int c; + + xerror(s); + state = 0; + while ((c = getbyte()) != '\n' && c != EOF) /* nothing */ ; + ungetbyte(c); +} + +/* checkeol: check that we have a complete line (except maybe for spaces) +*/ +PRIVATE +checkeol() +{ + + if (nospace() != '\n') { + syntax("end of line expected"); + (void) nospace(); + } +} + +/* getescape: read a '\' escape sequence +*/ +PRIVATE int +getescape() +{ + register int c, j, r; + + if ((c = getbyte()) >= '0' && c <= '7') { /* numeric escape */ + r = c - '0'; + + for (j = 0; j < 2; j++) { + if ((c = getbyte()) < '0' || c > '7') { + ungetbyte(c); + return r; + } + r <<= 3; + r += c - '0'; + } + + return r; + } + + switch(c) { + case 'b': return '\b'; + case 'f': return '\f'; + case 'n': return '\n'; + case 'r': return '\r'; + case 't': return '\t'; + } + + return c; +} + +/* getname: Read a string of characters representing an identifier +*/ +PRIVATE struct string * +getname() +{ + register char *p; + register struct string *s; + register int c; + + s = stringentry(); + p = s->str; + c = getbyte(); + + if (!(isalpha(c) || c == '_')) { + ungetbyte(c); + syntax("Letter expected"); + return s; + } + + while (isalnum(c) || c == '_') { + if (p < &(s->str[STRSIZ])) *p++ = c; + c = getbyte(); + } + + ungetbyte(c); + *p = '\0'; + s->length = p - s->str; + return s; +} + +/* getstring: read a string of characters between quotes +*/ +PRIVATE struct string * +getstring() +{ + register char *p; + struct string *s; + register int c; + static int termc; + + s = stringentry(); + p = s->str; + + if (!(state & INSTRING)) { /* Not reading a string yet */ + termc = getbyte(); + /* assert(termc == '"' || termc == '\''); */ + /* This assertion does not work. Compiler error messages. + The trouble lies in the ", it terminates the string + created in the assertion macro + */ + } + + for (;;) { + if ((c = getbyte()) == '\n' || c == EOF) { + ungetbyte(c); + syntax("non-terminated string"); + break; + } + + if (c == termc) { + if (termc == '"') *p++ = '\0'; + state &= ~INSTRING; + break; + } + + if (c == '\\') c = getescape(); + + if (p >= &(s->str[STRSIZ])) { + state |= INSTRING; + ungetbyte(c); + break; + } + + *p++ = c; + } + *p = '\0'; + + s->length = p - s->str; + return s; +} + +PRIVATE struct e_args *gettyp(); + +PRIVATE int +offsetted(argtyp, ap) + arith *ap; +{ + register int c; + register struct e_args *ap1; + + if ((c = nospace()) == '+' || c == '-') { + ap1 = gettyp(cst_ptyp); + if (c == '-') *ap = -(ap1->em_cst); + else *ap = ap1->em_cst; + return sp_doff; + } + else *ap = 0; + + ungetbyte(c); + return argtyp; +} + +PRIVATE int +getnumber(c, ap) + register int c; + register struct e_args *ap; +{ + register char *p; + int n; + register struct string *s = stringentry(); + int expsign; + long str2long(); + + p = s->str; + ap->em_argtype = cst_ptyp; + expsign = 0; + + if (c == '+' || c == '-') { + if (c == '-') *p++ = c; + c = getbyte(); + } + + if (! isdigit(c)) { + ungetbyte(c); + syntax("digit expected"); + return sp_cst4; + } + + n = sp_cst4; + + for (;;) { + if (p >= &(s->str[STRSIZ])) { + syntax("number too long"); + return sp_cst4; + } + + *p++ = c; + + if ((c = getbyte()) == '.' || c == 'e' || c == 'E') { + expsign = c != '.'; + n = sp_fcon; + continue; + } + + if (expsign) { + expsign = 0; + if (c == '+' || c == '-') continue; + } + + if (! isdigit(c)) break; + } + + ungetbyte(c); + *p = '\0'; + c = nospace(); + + if (n == sp_fcon && c != 'F') { + ungetbyte(c); + syntax("'F' expected"); + return n; + } + + if (c == 'I' || c == 'U' || c == 'F') { + ap->em_str = s->str; + ap->em_size = gettyp(cst_ptyp)->em_cst; + + switch(c) { + case 'I': + ap->em_argtype = ico_ptyp; + return sp_icon; + case 'U': + ap->em_argtype = uco_ptyp; + return sp_ucon; + case 'F': + ap->em_argtype = fco_ptyp; + return sp_fcon; + } + assert(0); + } + + ungetbyte(c); + ap->em_cst = (arith) str2long(s->str, 10); + i_strings--; + return sp_cst4; +} + +PRIVATE int getexpr(); + +PRIVATE int +getfactor(c, ap) + register int c; + register struct e_args *ap; +{ + if (c == '(') { + if (getexpr(nospace(), ap) != sp_cst4) { + syntax("expression expected"); + } + else if ((c = nospace()) != ')') { + ungetbyte(c); + syntax("')' expected"); + } + return sp_cst4; + } + return getnumber(c, ap); +} + +PRIVATE int +getterm(c, ap) + register int c; + register struct e_args *ap; +{ + arith left; + + if ((c = getfactor(c, ap)) != sp_cst4) return c; + + for (;;) { + if ((c = nospace()) != '*' && c != '/' && c != '%') { + ungetbyte(c); + break; + } + + left = ap->em_cst; + if (getfactor(nospace(), ap) != sp_cst4) { + syntax("factor expected"); + break; + } + + if (c == '*') ap->em_cst *= left; + else if (c == '/') ap->em_cst = left / ap->em_cst; + else ap->em_cst = left % ap->em_cst; + } + return sp_cst4; +} + +PRIVATE int +getexpr(c, ap) + register int c; + register struct e_args *ap; +{ + arith left; + + if ((c = getterm(c, ap)) != sp_cst4) return c; + + for (;;) { + if ((c = nospace()) != '+' && c != '-') { + ungetbyte(c); + break; + } + + left = ap->em_cst; + if (getterm(nospace(), ap) != sp_cst4) { + syntax("term expected"); + break; + } + + if (c == '+') ap->em_cst += left; + else ap->em_cst = left - ap->em_cst; + } + return sp_cst4; +} + +PRIVATE int +get15u() +{ + register struct e_args *ap = argentry(); + + ap->em_next = 0; + if (getnumber(getbyte(), ap) != sp_cst4) { + syntax("integer expected"); + } + else check((ap->em_cst & ~077777) == 0); + i_emargs--; + return (int) (ap->em_cst); +} + +PRIVATE struct e_args * +gettyp(typset) +{ + register int c, t; + register struct e_args *ap = argentry(); + register int argtyp; + + ap->em_next = 0; + if ((c = nospace()) == '\n') { + ungetbyte(c); + out("newline\n"); + argtyp = sp_cend; + } + else if (isdigit(c) || c == '+' || c == '-' || c == '(') { + out("expr\n"); + argtyp = getexpr(c, ap); + if (argtyp == sp_cst4 && fit16i(ap->em_cst)) argtyp = sp_cst2; + } + else if (isalpha(c) || c == '_') { + out("name\n"); + ungetbyte(c); + ap->em_dnam = getname()->str; + ap->em_argtype = sof_ptyp; + argtyp = offsetted(sp_dnam, &(ap->em_soff)); + } + else if (c == '.') { + out(".label\n"); + ap->em_dlb = get15u(); + ap->em_argtype = nof_ptyp; + argtyp = offsetted(sp_dlb2, &(ap->em_noff)); + } + else if (c == '*') { + out("*label\n"); + ap->em_ilb = get15u(); + ap->em_argtype = ilb_ptyp; + argtyp = sp_ilb2; + } + else if (c == '$') { + out("$name\n"); + ap->em_pnam = getname()->str; + ap->em_argtype = pro_ptyp; + argtyp = sp_pnam; + } + else if (c == '"' || c == '\'') { + register struct string *s; + + out("string\n"); + ungetbyte(c); + s = getstring(0); + ap->em_str = s->str; + ap->em_size = s->length; + ap->em_argtype = str_ptyp; + argtyp = sp_scon; + } + else if (c == '?') { + out("?\n"); + argtyp = sp_cend; + } + else { + /* c != '\n', so "ungetbyte" not neccesary */ + syntax("operand expected"); + return ap; + } + + t = argtyp - sp_fspec; + assert(t >= 0 && t < 16); + if ((typset & (1 << t)) == 0) { + syntax("Bad argument type"); + return ap; + } + + if (argtyp == sp_cend) return 0; + return ap; +} + +PRIVATE struct e_args * +getarg(typset) +{ + register int c; + + if (argnum != 1) { + if ((c = nospace()) != ',') { + if (c != '\n') { + syntax("comma expected"); + return 0; + } + ungetbyte(c); + } + } + argnum++; + return gettyp(typset); +} + +/* getmnem: We found the start of either an instruction or a pseudo. + get the rest of it +*/ +PRIVATE +getmnem(c, p) + register struct e_instr *p; +{ + register int h; + int i; + register struct string *s; + + ungetbyte(c); + s = getname(); + h = hash(s->str); + + for (;;) { + h++; + if (h >= HSIZE) h %= HSIZE; + if ((i = hashtab[h]) == 0) { + syntax("bad mnemonic"); + return; + } + else if (i <= sp_lmnem) { + assert(i >= sp_fmnem); + if (strcmp(s->str, em_mnem[i - sp_fmnem]) != 0) { + continue; + } + p->em_type = EM_MNEM; + p->em_opcode = i; + break; + } + assert(i <= sp_lpseu && i >= sp_fpseu); + if (strcmp(s->str, em_pseu[i - sp_fpseu]) != 0) { + continue; + } + if (i == ps_mes) { + p->em_type = EM_STARTMES; + break; + } + p->em_opcode = i; + p->em_type = EM_PSEU; + break; + } + i_strings--; +} + +PRIVATE +line_line() +{ + register struct e_args *ap; + static char filebuf[STRSIZ + 1]; + char *btscpy(); + + ap = gettyp(ptyp(sp_cst2)); + EM_lineno = ap->em_cst; + i_emargs--; + ap = gettyp(str_ptyp); + btscpy(filebuf, ap->em_str, (int) ap->em_size); + i_emargs--; + EM_filename = filebuf; +} + +PRIVATE +getlabel(c, p) + register struct e_instr *p; +{ + register struct e_args *ap; + + ungetbyte(c); + ap = gettyp(lab_ptyp|ptyp(sp_cst2)); + switch(ap->em_argtype) { + case cst_ptyp: + p->em_type = EM_DEFILB; + p->em_deflb = ap->em_cst; + break; + case sof_ptyp: + p->em_type = EM_DEFDNAM; + p->em_defdnam = ap->em_dnam; + break; + case nof_ptyp: + p->em_type = EM_DEFDLB; + p->em_deflb = ap->em_dlb; + break; + } + checkeol(); +} + +PRIVATE struct e_instr * +gethead() +{ + register int c, i; + register struct e_instr *p = &emhead; + + argnum = 1; + for (;;) { + EM_lineno++; + if ((c = getbyte()) == EOF) return 0; + if (c == '\n') continue; + if (isspace(c)) { + c = nospace(); + if (isalpha(c) || c == '_') { + getmnem(c, p); + return p; + } + ungetbyte(c); + } + else if (c == '#') line_line(); + else { + getlabel(c, p); + return p; + } + checkeol(); + } + /*NOTREACHED*/ +} diff --git a/modules/src/read_em/readk.c b/modules/src/read_em/readk.c new file mode 100644 index 00000000..1ba9df64 --- /dev/null +++ b/modules/src/read_em/readk.c @@ -0,0 +1,367 @@ +/* This file must be included in the file "read_emk.c". + It takes care of the reading of compact EM code. +*/ + +#include + +/* get16, get32: read a signed constant +*/ +PRIVATE int +get16() +{ + register int l_byte, h_byte; + + l_byte = getbyte(); + h_byte = getbyte(); + if (h_byte >= 128) h_byte -= 256; + return l_byte | (h_byte << 8); +} + +PRIVATE arith +get32() +{ + register arith l; + register int h_byte; + + l = getbyte(); + l |= ((unsigned) getbyte() << 8); + l |= ((arith) getbyte() << 16); + h_byte = getbyte(); + if (h_byte >= 128) h_byte -= 256; + return l | ((arith) h_byte << 24); +} + +PRIVATE struct string *getstring(); + +/* getarg : read an argument of any type, and check it against "typset" + if neccesary. Return a pointer to the argument. +*/ +PRIVATE struct e_args * +getarg(typset) +{ + register struct e_args *ap = argentry(); + register int i = getbyte(); +#ifdef CHECKING + int argtyp; +#endif CHECKING + + ap->em_next = 0; + switch(i) { + default: + if (i < sp_fcst0+sp_ncst0 && i >= sp_fcst0) { /* A cst */ + ap->em_cst = i - sp_zcst0; + ap->em_argtype = cst_ptyp; + i = sp_cst2; + } + break; + + case sp_dlb1: /* Numeric data label encoded in one byte */ + ap->em_dlb = getbyte(); + ap->em_noff = 0; + ap->em_argtype = nof_ptyp; + break; + + case sp_dlb2: /* Numeric data label encoded in two bytes */ + ap->em_dlb = get16(); + ap->em_noff = 0; + ap->em_argtype = nof_ptyp; +#ifdef CHECKING + if (ap->em_dlb < 0) { + xerror("Illegal data label"); + break; + } +#endif CHECKING + break; + + case sp_ilb1: /* Instruction label encoded in one byte */ + ap->em_ilb = getbyte(); + ap->em_argtype = ilb_ptyp; + break; + + case sp_ilb2: /* Instruction label encoded in two bytes */ + ap->em_ilb = get16(); + ap->em_argtype = ilb_ptyp; +#ifdef CHECKING + if (ap->em_ilb < 0) { + xerror("Illegal instruction label"); + break; + } +#endif CHECKING + break; + + case sp_cst2: /* A cst encoded in two bytes */ + ap->em_cst = get16(); + ap->em_argtype = cst_ptyp; + break; + + case sp_cst4: /* A cst encoded in four bytes */ + ap->em_cst = get32(); + ap->em_argtype = cst_ptyp; + break; + + case sp_pnam: /* A procedure name */ + { + register struct string *p; + + p = getstring(1); +#ifdef CHECKING + if (state & INSTRING) { + xerror("Procedure name too long"); + } +#endif CHECKING + ap->em_pnam = p->str; + ap->em_argtype = pro_ptyp; + break; + } + + case sp_dnam: /* A Non-numeric data label */ + { + register struct string *p; + + p = getstring(1); +#ifdef CHECKING + if (state & INSTRING) { + xerror("Data label too long"); + } +#endif CHECKING + ap->em_dnam = p->str; + ap->em_soff = 0; + ap->em_argtype = sof_ptyp; + break; + } + + case sp_doff: /* A data label + offset */ + { + register struct e_args *ap1, *ap2; + + ap1 = getarg(lab_ptyp); + ap2 = getarg(cst_ptyp); + *ap = *ap1; + if (ap->em_argtype == sof_ptyp) { /* non-numeric label */ + ap->em_soff = ap2->em_cst; + } + else ap->em_noff = ap2->em_cst; + i_emargs -= 2; + break; + } + + case sp_icon: /* An integer constant */ + case sp_ucon: /* An unsigned constant */ + case sp_fcon: /* A floating constant */ + { + register struct e_args *ap1; + register struct string *p; + + ap1 = getarg(cst_ptyp); + p = getstring(0); +#ifdef CHECKING + if (state & INSTRING) { + xerror("Numeric constant too long"); + } +#endif CHECKING + ap->em_argtype = ptyp(i); + ap->em_str = p->str; + ap->em_size = ap1->em_cst; + i_emargs--; + break; + } + + case sp_scon: /* A string constant */ + { + register struct string *p; + + p = getstring(0); + ap->em_argtype = str_ptyp; + ap->em_str = p->str; + ap->em_size = p->length; + break; + } + } +#ifdef CHECKING + argtyp = i; + if (EM_error) return 0; + + if (i == EOF) { + xfatal("Unexpected EOF"); + return 0; + } + + if ((i -= sp_fspec) < 0 || i >= 16) { + xerror("Illegal byte"); + return 0; + } + + if ((typset & (1 << i)) == 0) { + xerror("Bad argument type"); + } + if (argtyp == sp_cend) return 0; +#else not CHECKING + if (i == sp_cend) return 0; +#endif CHECKING + return ap; +} + +#ifdef CHECKING +/* checkident: check that a string indeed represents an identifier +*/ +PRIVATE int +checkident(s) + register struct string *s; +{ + register char *p; + register int n; + + p = s->str; + if (!isascii(*p) || (!isalpha(*p) && *p != '_')) { + return 0; + } + p++; + for (n = s->length; --n > 0; p++) { + if (!isascii(*p) || (!isalnum(*p) && *p != '_')) { + return 0; + } + } + return 1; +} +#endif CHECKING + +/* getstring: read a string from the input, but at most STRSIZ characters + of it. The next characters will be read another time around +*/ +/*ARGSUSED*/ +PRIVATE struct string * +getstring(isident) +{ + register char *p; + register int n; + register struct string *s; + + if (!(state & INSTRING)) { /* Not reading a string yet */ + struct e_args *ap = getarg(cst_ptyp); + /* Read length of string */ + i_emargs--; + strleft = ap->em_cst; +#ifdef CHECKING + if (strleft < 0) { + xerror("Negative length in string"); + return 0; + } +#endif CHECKING + } + + s = stringentry(); + + if (strleft <= STRSIZ) { /* Handle the whole string */ + n = strleft; + state &= ~INSTRING; + } + else { /* Handle STRSIZ characters of it, and + indicate that there is more + */ + n = STRSIZ; + strleft -= STRSIZ; + state |= INSTRING; + } + + s->length = n; + p = s->str; + while (--n >= 0) { + *p++ = getbyte(); + } + *p++ = '\0'; + +#ifdef CHECKING + if (isident) { + if (!checkident(s)) { + xerror("Illegal identifier"); + } + } +#endif CHECKING + return s; +} + +/* gethead: read the start of an EM-line +*/ +PRIVATE struct e_instr * +gethead() +{ + register int i; + register struct e_instr *p = &emhead; + + EM_lineno++; + + if ((i = getbyte()) < sp_fmnem+sp_nmnem && i >= sp_fmnem) { + /* A mnemonic */ + p->em_type = EM_MNEM; + p->em_opcode = i; + return p; + } + + if (i < sp_fpseu+sp_npseu && i >= sp_fpseu) { /* A pseudo */ + if (i == ps_mes) { + p->em_type = EM_STARTMES; + } + else p->em_type = EM_PSEU; + p->em_opcode = i; + return p; + } + + if (i < sp_filb0+sp_nilb0 && i >= sp_filb0) { /* Instruction label */ + p->em_type = EM_DEFILB; + p->em_deflb = i - sp_filb0; + return p; + } + + switch(i) { + case sp_ilb1: /* Instruction label */ + p->em_type = EM_DEFILB; + p->em_deflb = getbyte(); + break; + + case sp_ilb2: /* Instruction label */ + p->em_type = EM_DEFILB; + p->em_deflb = get16(); +#ifdef CHECKING + if (p->em_deflb < 0) { + xerror("Illegal instruction label definition"); + } +#endif CHECKING + break; + + case sp_dlb1: /* Numeric data label */ + p->em_type = EM_DEFDLB; + p->em_deflb = getbyte(); + break; + + case sp_dlb2: /* Numeric data label */ + p->em_type = EM_DEFDLB; + p->em_deflb = get16(); +#ifdef CHECKING + if (p->em_deflb < 0) { + xerror("Illegal data label definition"); + } +#endif CHECKING + break; + + case sp_dnam: /* Non-numeric data label */ + { + struct string *s; + + p->em_type = EM_DEFDNAM; + if (!(s = getstring(1))) { + p->em_type = EM_ERROR; + } + else p->em_defdnam = s->str; + break; + } + + case EOF: /* End of file */ + return 0; + + default: + xerror("Unknown opcode"); + break; + } + + return p; +} From 12869eaa07f32aa7fb1dbab4d2d947c3b5fca871 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 6 Jan 1987 11:25:09 +0000 Subject: [PATCH 0419/1625] Initial revision --- modules/src/malloc/Makefile | 38 +++++ modules/src/malloc/READ_ME | 27 ++++ modules/src/malloc/add_file | 14 ++ modules/src/malloc/check.c | 297 +++++++++++++++++++++++++++++++++++ modules/src/malloc/check.h | 15 ++ modules/src/malloc/getsize.c | 19 +++ modules/src/malloc/global.c | 6 + modules/src/malloc/impl.h | 73 +++++++++ modules/src/malloc/log.c | 128 +++++++++++++++ modules/src/malloc/log.h | 12 ++ modules/src/malloc/mal.c | 293 ++++++++++++++++++++++++++++++++++ modules/src/malloc/param.h | 51 ++++++ modules/src/malloc/phys.c | 93 +++++++++++ modules/src/malloc/phys.h | 61 +++++++ 14 files changed, 1127 insertions(+) create mode 100644 modules/src/malloc/Makefile create mode 100644 modules/src/malloc/READ_ME create mode 100755 modules/src/malloc/add_file create mode 100644 modules/src/malloc/check.c create mode 100644 modules/src/malloc/check.h create mode 100644 modules/src/malloc/getsize.c create mode 100644 modules/src/malloc/global.c create mode 100644 modules/src/malloc/impl.h create mode 100644 modules/src/malloc/log.c create mode 100644 modules/src/malloc/log.h create mode 100644 modules/src/malloc/mal.c create mode 100644 modules/src/malloc/param.h create mode 100644 modules/src/malloc/phys.c create mode 100644 modules/src/malloc/phys.h diff --git a/modules/src/malloc/Makefile b/modules/src/malloc/Makefile new file mode 100644 index 00000000..994d0996 --- /dev/null +++ b/modules/src/malloc/Makefile @@ -0,0 +1,38 @@ +EMHOME = ../../.. +INSTALL = $(EMHOME)/modules/install +COMPARE = $(EMHOME)/modules/compare +CFLAGS = -O -I$(EMHOME)/modules/h + +MALLOCSRC = READ_ME size_type.h param.h impl.h check.h log.h phys.h \ + mal.c log.c phys.c check.c + +all: malloc.o + +install: all + $(INSTALL) lib/malloc.o + +cmp: all + $(COMPARE) lib/malloc.o + +malloc1.c: $(MALLOCSRC) Makefile add_file + rm -f malloc1.c + for i in $(MALLOCSRC) ; do add_file $$i >> malloc1.c ; done + +malloc.c: malloc1.c + cclash -l7 -c malloc1.c > clashes + cid -Fclashes < malloc1.c > malloc.c + +pr: + @pr Makefile add_file $(MALLOCSRC) + +opr: + make pr | opr + +clean: + rm -f *.o clashes malloc1.c size_type.h getsize malloc.c + +size_type.h: getsize + getsize > size_type.h + +getsize: getsize.o + $(CC) -o getsize getsize.o diff --git a/modules/src/malloc/READ_ME b/modules/src/malloc/READ_ME new file mode 100644 index 00000000..37be2152 --- /dev/null +++ b/modules/src/malloc/READ_ME @@ -0,0 +1,27 @@ +/* + PROGRAM + malloc(), free(), realloc() + AUTHOR + Dick Grune, Free University, Amsterdam + Modified by Ceriel Jacobs, Free University, Amsterdam, + to make it faster + VERSION + $Header$ + DESCRIPTION + This is an independent rewrite of the malloc/free package; it is + fast and efficient. Free blocks are kept in doubly linked lists, + list N holding blocks with sizes between 2**N and 2**(N+1)-1. + Consequently neither malloc nor free have to do any searching: + the cost of a call of malloc() (or free()) is constant, however + many blocks you have got. + + If you switch on the NON_STANDARD macro (see param.h) every block + costs 2 pointers overhead (otherwise it's 4). +*/ +/* + There is an organisational problem here: during devellopment + I want the package divided into modules, which implies external + names for the communication. The only external names I want in + the finished product are malloc, realloc and free. This requires + some hanky-panky. +*/ diff --git a/modules/src/malloc/add_file b/modules/src/malloc/add_file new file mode 100755 index 00000000..7a5eace5 --- /dev/null +++ b/modules/src/malloc/add_file @@ -0,0 +1,14 @@ +echo '' +echo '/**********************************************************/' +echo '/*' +echo '/* ' This was file $1 +echo '/*' +echo '/**********************************************************/' +echo '' +cat $1 | +sed ' + /#include[ ].*"/d + s/^public/private/ + s/^publicdata/static/ +' +echo '' diff --git a/modules/src/malloc/check.c b/modules/src/malloc/check.c new file mode 100644 index 00000000..cb88d471 --- /dev/null +++ b/modules/src/malloc/check.c @@ -0,0 +1,297 @@ +#include +#include "param.h" +#include "impl.h" +#include "check.h" +#include "phys.h" +#include "log.h" + +#ifdef CHECK /* otherwise this whole file is skipped */ + +private acquire_malout(), check_ml_last(); +private dump_all_mallinks(), dump_free_list(), dump_mallink(), print_loop(); +private working_on(); +private unsigned int checksum(); +static FILE *malout; + +public mallink *free_list_entry(); + +#define for_free_list(i,p) \ + for (p = free_list_entry(i); p; p = log_next_of(p)) + +#define for_all_mallinks(ml) /* backwards! */ \ + for (ml = ml_last; ml; \ + ml = first_mallink(ml) ? MAL_NULL : phys_prev_of(ml)) + +/* Maldump */ + +static int pr_cnt = 0; + +maldump(n) { + /* Dump pertinent info in pseudo-readable format; + abort afterwards if n != 0. + */ + static int dumping = 0; + int i; + + if (dumping) + return; + dumping++; + acquire_malout(); + fprintf(malout, + ">>>>>>>>>>>>>>>> DUMP OF ALL MALLINKS <<<<<<<<<<<<<<<<"); + fprintf(malout, " ml_last = %ld\n", (long)ml_last); + if (++pr_cnt == 100) pr_cnt = 0; + dump_all_mallinks(); + fprintf(malout, + ">>>>>>>>>>>>>>>> DUMP OF FREE_LISTS <<<<<<<<<<<<<<<<\n"); + if (++pr_cnt == 100) pr_cnt = 0; + for (i = 0; i < MAX_FLIST; i++) + dump_free_list(i); + fprintf(malout, + ">>>>>>>>>>>>>>>> END OF DUMP <<<<<<<<<<<<<<<<\n"); + fclose(malout); + dumping--; + if (n) + abort(); +} + +private +acquire_malout() { + static char buf[BUFSIZ]; + + if (!malout) { + malout = fopen("mal.out", "w"); + setbuf(malout, buf); + } +} + +private +dump_all_mallinks() { + mallink *ml; + + for_all_mallinks (ml) { + if (print_loop(ml)) + return; + dump_mallink((char *)0, ml); + } +} + +private +dump_free_list(i) { + mallink *ml = free_list_entry(i); + + if (!ml) + return; + fprintf(malout, "%2d: ", i); + for_free_list(i, ml) { + if (print_loop(ml)) + return; + fprintf(malout, "%ld ", ml); + } + fprintf(malout, "<\n"); +} + +private int +print_loop(ml) mallink *ml; { + if (print_of(ml) == pr_cnt) { + fprintf(malout, "... PRINT LOOP\n"); + return 1; + } + set_print(ml, pr_cnt); + return 0; +} + +private +dump_mallink(s, ml) char *s; mallink *ml; { + acquire_malout(); + if (s) + fprintf(malout, "%s: ", s); + fprintf(malout, "@: %ld;", (long)ml); + if (ml && checksum_of(ml) != checksum(ml)) + fprintf(malout, ">>>> CORRUPTED <<<<"); + if (!ml) { + fprintf(malout, "\n"); + return; + } + if (free_of(ml)) { + fprintf(malout, " l_p: %ld;", (long)_log_prev_of(ml)); + fprintf(malout, " l_n: %ld;", (long)_log_next_of(ml)); + } + fprintf(malout, " p_s: %ld;", (long)prev_size_of(ml)); + fprintf(malout, " t_s: %ld;", (long)_this_size_of(ml)); + fprintf(malout, " sz: %ld;", (long)size_of(ml)); + fprintf(malout, " fr: %d;", free_of(ml)); + fprintf(malout, "\n"); +} + +/* Check_mallinks() checks the total data structure as accessible + through free_list[] and ml_last. All check_sums should be OK, + except those held in the small array off_colour. This is a + trick to allow to continue checking even when a few mallinks + are temporarily out of order. + Check_mallinks() tests for a lot of internal consistency. +*/ + +/* Some arbitrary constants */ +#define IN_ML_LAST 93 +#define IN_FREE_LIST 57 /* and in ml_last */ +#define CLEAR 21 + +#define VRIJ 1 +#define BEZET 2 + +public +check_mallinks(s) char *s; { + mallink *ml; + unsigned int size; + int i; + char stat; + + check_ml_last(s); + stat = BEZET; + for_all_mallinks(ml) { + if (checksum_of(ml) != checksum(ml)) + Error("mallink info at %ld corrupted", s, ml); + if (working_on(ml)) { + stat = BEZET; + continue; + } + if ( !last_mallink(ml) && + phys_prev_of(phys_next_of(ml)) != ml + ) + Error("upward chain bad at %ld", s, ml); + if ( !first_mallink(ml) && + phys_next_of(phys_prev_of(ml)) != ml + ) + Error("downward chain bad at %ld", s, ml); + if (free_of(ml)) { + if (stat == VRIJ) + Error("free mallink at %ld follows free mallink", + s, ml); + stat = VRIJ; + } + else + stat = BEZET; + set_mark(ml, IN_ML_LAST); + } + + for (i = 0, size = MIN_SIZE; i < MAX_FLIST; i++, size *= 2) { + for_free_list(i, ml) { + if (working_on(ml)) + continue; + if (!free_of(ml)) + Error("occupied mallink %ld occurs in free_list", s, ml); + switch (mark_of(ml)) { + case IN_ML_LAST: + set_mark(ml, IN_FREE_LIST); + break; + case IN_FREE_LIST: + Error("mallink %ld occurs in 2 free_lists", + s, ml); + default: + Error("unknown mallink %ld in free_list", + s, ml); + } + if (size_of(ml) < size) + Error("size of mallink %ld too small", s, ml); + if (size_of(ml) >= 2*size) + Error("size of mallink %ld too large", s, ml); + } + } + for_all_mallinks (ml) { + if (working_on(ml)) + continue; + if (free_of(ml) && mark_of(ml) != IN_FREE_LIST) + Error("free mallink %ld is in no free_list", s, ml); + set_mark(ml, CLEAR); + } +} + +private +check_ml_last(s) char *s; { + if (ml_last && _this_size_of(ml_last) == 0) + Error("size of ml_last == 0, at %ld", s, ml_last); +} + +private unsigned int +checksum(ml) mallink *ml; { + unsigned int sum = 0; + + if (free_of(ml)) { + sum += (unsigned int)_log_prev_of(ml); + sum += (unsigned int)_log_next_of(ml); + } + sum += (unsigned int)prev_size_of(ml); + sum += (unsigned int)_this_size_of(ml); + return sum; +} + +public +calc_checksum(ml) mallink *ml; { + set_checksum(ml, checksum(ml)); +} + +#define N_COLOUR 10 +static mallink *off_colour[N_COLOUR]; + +public +started_working_on(ml) mallink *ml; { + int i; + + for (i = 0; i < N_COLOUR; i++) + if (off_colour[i] == MAL_NULL) { + off_colour[i] = ml; + return; + } + Error("out of off_colour array at %ld", "started_working_on", ml); +} + +public +stopped_working_on(ml) mallink *ml; { + int i; + + for (i = 0; i < N_COLOUR; i++) + if (off_colour[i] == ml) { + off_colour[i] = MAL_NULL; + return; + } + Error("stopped working on mallink %ld", "stopped_working_on", ml); +} + +private int +working_on(ml) mallink *ml; { + int i; + + for (i = 0; i < N_COLOUR; i++) + if (off_colour[i] == ml) + return 1; + return 0; +} + +public +check_work_empty(s) char *s; { + int i; + int cnt = 0; + + for (i = 0; i < N_COLOUR; i++) + if (off_colour[i] != MAL_NULL) + cnt++; + if (cnt != 0) + Error("off_colour not empty", s, MAL_NULL); +} + +public int +Error(fmt, s, ml) char *fmt, *s; mallink *ml; { + printf("%s: ", s); + printf(fmt, (long)ml); + printf("\n"); + acquire_malout(); + fprintf(malout, "%s: ", s); + fprintf(malout, fmt, (long)ml); + fprintf(malout, "\n"); + fflush(stdout); + maldump(1); + return 0; /* to satisfy lint */ +} + +#endif CHECK diff --git a/modules/src/malloc/check.h b/modules/src/malloc/check.h new file mode 100644 index 00000000..c9697c7e --- /dev/null +++ b/modules/src/malloc/check.h @@ -0,0 +1,15 @@ +#ifdef CHECK + +public check_mallinks(), calc_checksum(), check_work_empty(); +public started_working_on(), stopped_working_on(); + +#else ifndef CHECK + +#define maldump(n) abort() +#define check_mallinks(s) 0 +#define calc_checksum(ml) 0 +#define started_working_on(ml) 0 +#define stopped_working_on(ml) 0 +#define check_work_empty(s) 0 + +#endif CHECK diff --git a/modules/src/malloc/getsize.c b/modules/src/malloc/getsize.c new file mode 100644 index 00000000..d7cd3a49 --- /dev/null +++ b/modules/src/malloc/getsize.c @@ -0,0 +1,19 @@ +/* find out if a pointer-sized integer, preferably unsigned, + must be declared as an unsigned int or a long +*/ + +#include + +main() +{ + if (sizeof(unsigned int) == sizeof(char *)) { + puts("typedef unsigned int size_type;"); + return 0; + } + if (sizeof(long) == sizeof(char *)) { + puts("typedef long size_type;"); + return 0; + } + fputs(stderr, "funny pointer size\n"); + return 1; +} diff --git a/modules/src/malloc/global.c b/modules/src/malloc/global.c new file mode 100644 index 00000000..0061ed4e --- /dev/null +++ b/modules/src/malloc/global.c @@ -0,0 +1,6 @@ +#include "param.h" +#include "impl.h" + +/* The only global data item: +*/ +mallink *ml_last; /* link to the world */ diff --git a/modules/src/malloc/impl.h b/modules/src/malloc/impl.h new file mode 100644 index 00000000..8c39f954 --- /dev/null +++ b/modules/src/malloc/impl.h @@ -0,0 +1,73 @@ +/* This file essentially describes how the mallink info block + is implemented. +*/ + +#define MIN_SIZE (1<>= 1; + mlp++; + } + while (n >= MIN_SIZE); + + ml1 = *mlp; + set_log_prev(ml, MAL_NULL); + set_log_next(ml, ml1); + calc_checksum(ml); + if (ml1) { + /* link backwards + */ + set_log_prev(ml1, ml); + calc_checksum(ml1); + } + *mlp = ml; +} + +public +unlink_free_chunk(ml) + register mallink *ml; +{ + /* Unlinks a free chunk from (the middle of) the + logical chain. + */ + register mallink *next = log_next_of(ml); + register mallink *prev = log_prev_of(ml); + + if (!prev) { + /* it is the first in the chain */ + register mallink **mlp = &free_list[-1]; + register unsigned int n = size_of(ml); + + assert(n < (1 << LOG_MAX_SIZE)); + do { + n >>= 1; + mlp++; + } + while (n >= MIN_SIZE); + *mlp = next; + } + else { + set_log_next(prev, next); + calc_checksum(prev); + } + if (next) { + set_log_prev(next, prev); + calc_checksum(next); + } +} + +public mallink * +search_free_list(class, n) + unsigned int n; +{ + /* Searches the free_list[class] for a chunk of at least size n; + since it is searching a slightly undersized list, + such a block may not be there. + */ + register mallink *ml; + + for (ml = free_list[class]; ml; ml = log_next_of(ml)) + if (size_of(ml) >= n) + return ml; + return MAL_NULL; /* nothing found */ +} + +public mallink * +first_present(class) + int class; +{ + /* Find the index i in free_list[] such that: + i >= class && free_list[i] != MAL_NULL. + Return MAL_NULL if no such i exists; + Otherwise, return the first block of this list, after + unlinking it. + */ + register mallink **mlp, *ml; + + for (mlp = &free_list[class]; mlp < &free_list[MAX_FLIST]; mlp++) { + if ((ml = *mlp) != MAL_NULL) { + + *mlp = log_next_of(ml); /* may be MAL_NULL */ + if (*mlp) { + /* unhook backward link + */ + set_log_prev(*mlp, MAL_NULL); + calc_checksum(*mlp); + } + return ml; + } + } + return MAL_NULL; +} + +#ifdef CHECK +public mallink * +free_list_entry(i) { + /* To allow maldump.c access to log.c's private data. + */ + return free_list[i]; +} +#endif CHECK diff --git a/modules/src/malloc/log.h b/modules/src/malloc/log.h new file mode 100644 index 00000000..c69f2f66 --- /dev/null +++ b/modules/src/malloc/log.h @@ -0,0 +1,12 @@ +/* Algorithms to manipulate the doubly-linked lists of free + chunks. +*/ + +public link_free_chunk(), unlink_free_chunk(); +public mallink *first_present(), *search_free_list(); + +#define set_log_prev(ml,e) (_log_prev_of(ml) = (e)) +#define log_prev_of(ml) (mallink *) (_log_prev_of(ml)) + +#define set_log_next(ml,e) (_log_next_of(ml) = (e)) +#define log_next_of(ml) (mallink *) (_log_next_of(ml)) diff --git a/modules/src/malloc/mal.c b/modules/src/malloc/mal.c new file mode 100644 index 00000000..629318cf --- /dev/null +++ b/modules/src/malloc/mal.c @@ -0,0 +1,293 @@ +#include "param.h" +#include "impl.h" +#include "check.h" +#include "log.h" +#include "phys.h" + +/* Malloc space is traversed by N doubly-linked lists of chunks, each + containing a couple of house-keeping data addressed as a + 'mallink' and a piece of useful space, called the block. + The N lists are accessed through their starting pointers in + free_list[]. Free_list[n] points to a list of chunks between + 2**(n+LOG_MIN_SIZE) and 2**(n+LOG_MIN_SIZE+1)-1, which means + that the smallest chunk is 2**LOG_MIN_SIZE (== MIN_SIZE). +*/ + +#ifdef SYSTEM +#include +#define SBRK sys_break +#else +#define SBRK sbrk +#define ILL_BREAK (char *)(-1) /* funny failure value */ +#endif +extern char *SBRK(); +#ifdef STORE +#define MAX_STORE 32 +private do_free(), sell_out(); +privatedata mallink *store[MAX_STORE]; +#endif STORE + +char * +malloc(n) + register unsigned int n; +{check_mallinks("malloc entry");{ + register mallink *ml; + register int min_class; + + if (n < MIN_SIZE) n = align(MIN_SIZE); else n = align(n); +#ifdef STORE + if (n <= MAX_STORE*MIN_SIZE) { + /* look in the store first */ + register mallink **stp = &store[(n >> LOG_MIN_SIZE) - 1]; + + if (ml = *stp) { + *stp = log_next_of(ml); + check_mallinks("malloc fast exit"); + return block_of_mallink(ml); + } + } +#endif STORE + + check_work_empty("malloc, entry"); + + /* Acquire a chunk of at least size n if at all possible; + Try everything. + */ + { + /* Inline substitution of "smallest". + */ + register unsigned int n1 = n; + + assert(n1 < (1 << LOG_MAX_SIZE)); + min_class = 0; + + while (n1 >= MIN_SIZE) { + n1 >>= 1; + min_class++; + } + } + + if (min_class >= MAX_FLIST) + return (char *) 0; /* we don't deal in blocks that big */ + ml = first_present(min_class); + if (ml == MAL_NULL) { + /* Try and extend */ + register char *p; +#define GRABSIZE 4096 /* Power of 2 */ + register unsigned int req = + (n+mallink_size()+GRABSIZE-1)&~(GRABSIZE-1); + + if (!ml_last) { + /* first align SBRK() */ + + p = SBRK(0); + SBRK((int) (align((size_type) p) - (size_type) p)); + } + + p = SBRK((int)req); + if (p == ILL_BREAK) { + /* Now this is bad. The system will not give us + more memory. We can only liquidate our store + and hope it helps. + */ +#ifdef STORE + sell_out(); + ml = first_present(min_class); + if (ml == MAL_NULL) { +#endif STORE + /* In this emergency we try to locate a suitable + chunk in the free_list just below the safe + one; some of these chunks may fit the job. + */ + ml = search_free_list(min_class - 1, n); + if (!ml) /* really out of space */ + return (char *) 0; + started_working_on(ml); + unlink_free_chunk(ml); + check_mallinks("suitable_chunk, forced"); +#ifdef STORE + } + else started_working_on(ml); +#endif STORE + } + else { + ml = create_chunk(p, req); + } + check_mallinks("suitable_chunk, extended"); + } + else started_working_on(ml); + + /* we have a chunk */ + set_free(ml, 0); + calc_checksum(ml); + check_mallinks("suitable_chunk, removed"); + n += mallink_size(); + if (n + MIN_SIZE <= size_of(ml)) { + truncate(ml, n); + } + stopped_working_on(ml); + check_mallinks("malloc exit"); + check_work_empty("malloc exit"); + return block_of_mallink(ml); +}} + +free(addr) + char *addr; +{check_mallinks("free entry");{ + register mallink *ml = mallink_of_block(addr); +#ifdef STORE + + if (free_of(ml)) + return; /* user frees free block */ + if (size_of(ml) <= MAX_STORE*MIN_SIZE) { + /* return to store */ + mallink **stp = &store[(size_of(ml) >> LOG_MIN_SIZE) - 1]; + + set_log_next(ml, *stp); + *stp = ml; + check_mallinks("free fast exit"); + } + else { + do_free(ml); + check_mallinks("free exit"); + } +}} + +private +do_free(ml) + register mallink *ml; +{{ +#endif + +#ifndef STORE + if (free_of(ml)) return; +#endif STORE + started_working_on(ml); + set_free(ml, 1); + calc_checksum(ml); + if (! last_mallink(ml)) { + register mallink *next = phys_next_of(ml); + + if (free_of(next)) coalesce_forw(ml, next); + } + + if (! first_mallink(ml)) { + register mallink *prev = phys_prev_of(ml); + + if (free_of(prev)) { + coalesce_backw(ml, prev); + ml = prev; + } + } + link_free_chunk(ml); + stopped_working_on(ml); + check_work_empty("free"); + + /* Compile-time checks on param.h */ + switch (0) { + case MIN_SIZE < OFF_SET * sizeof(mallink): break; + case 1: break; + /* If this statement does not compile due to duplicate case + entry, the minimum size block cannot hold the links for + the free blocks. Either raise LOG_MIN_SIZE or switch + off NON_STANDARD. + */ + } + switch(0) { + case sizeof(char *) != sizeof(size_type): break; + case 1: break; + /* If this statement does not compile due to duplicate + case entry, size_type is not defined correctly. + Redefine and compile again. + */ + } +}} + +char * +realloc(addr, n) + char *addr; + register unsigned int n; +{check_mallinks("realloc entry");{ + register mallink *ml = mallink_of_block(addr), *ph_next; + register unsigned int size; + + if (n < MIN_SIZE) n = align(MIN_SIZE); else n = align(n); + if (free_of(ml)) { + unlink_free_chunk(ml); + set_free(ml, 0); /* user reallocs free block */ + } + started_working_on(ml); + size = size_of(ml); + if ( /* we can simplify the problem by adding the next chunk: */ + n > size && + !last_mallink(ml) && + (ph_next = phys_next_of(ml), free_of(ph_next)) && + n <= size + mallink_size() + size_of(ph_next) + ) { + /* add in the physically next chunk */ + unlink_free_chunk(ph_next); + combine_chunks(ml, ph_next); + size = size_of(ml); + check_mallinks("realloc, combining"); + } + if (n > size) { /* this didn't help */ + char *new; + register char *l1, *l2 = addr; + + stopped_working_on(ml); + if (!(new = l1 = malloc(n))) return (char *) 0; /* no way */ + while (size--) *l1++ = *l2++; + free(addr); + check_work_empty("mv_realloc"); + return new; + } + /* it helped, but maybe too well */ + n += mallink_size(); + if (n + MIN_SIZE <= size_of(ml)) { + truncate(ml, n); + } + stopped_working_on(ml); + check_mallinks("realloc exit"); + check_work_empty("realloc"); + return addr; +}} + +/* Auxiliary routines */ + +#ifdef STORE +private +sell_out() { + /* Frees all block in store. + */ + register mallink **stp; + + for (stp = &store[0]; stp < &store[MAX_STORE]; stp++) { + register mallink *ml = *stp; + + while (ml) { + *stp = log_next_of(ml); + do_free(ml); + ml = *stp; + } + } + +} +#endif STORE + +#ifdef ASSERT +public +m_assert(fn, ln) + char *fn; +{ + char ch; + + while (*fn) + write(2, fn++, 1); + write(2, ": malloc assert failed in line ", 31); + ch = (ln / 100) + '0'; write(2, &ch, 1); ln %= 100; + ch = (ln / 10) + '0'; write(2, &ch, 1); ln %= 10; + ch = (ln / 1) + '0'; write(2, &ch, 1); + write(2, "\n", 1); + maldump(1); +} +#endif ASSERT diff --git a/modules/src/malloc/param.h b/modules/src/malloc/param.h new file mode 100644 index 00000000..a89e6b99 --- /dev/null +++ b/modules/src/malloc/param.h @@ -0,0 +1,51 @@ +#include "size_type.h" + +/*# define NON_STANDARD /* If defined, the contents of a block + will NOT be left undisturbed after it + is freed, as opposed to what it says + in the manual (malloc(2)). + Setting this option reduces the memory + overhead considerably. I personally + consider the specified behaviour an + artefact of the original + implementation. + */ + +/*# define ASSERT /* If defined, some inexpensive tests + will be made to ensure the + correctness of some sensitive data. + It often turns an uncontrolled crash + into a controlled one. + */ + +/*# define CHECK /* If defined, extensive and expensive + tests will be done, inculding a + checksum on the mallinks (chunk + information blocks). The resulting + information will be printed on a file + called mal.out . + Additionally a function + maldump(n) int n; + will be defined, which will dump + pertinent info in pseudo-readable + form; it aborts afterwards if n != 0. + */ + +/*# define EXTERN /* If defined, all static names will + become extern, which is a help in + using adb(1) or prof(1) + */ + +# define STORE /* If defined, separate free lists will + be kept of chunks with small sizes, + to speed things up a little. + */ + +# define SYSTEM /* If defined, the system module is used. + Otherwise, "sbrk" is called directly. + */ + +#define ALIGNMENT 8 + /* alignment common to all types */ +#define LOG_MIN_SIZE 3 +#define LOG_MAX_SIZE 24 diff --git a/modules/src/malloc/phys.c b/modules/src/malloc/phys.c new file mode 100644 index 00000000..da42536e --- /dev/null +++ b/modules/src/malloc/phys.c @@ -0,0 +1,93 @@ +#include "param.h" +#include "impl.h" +#include "check.h" +#include "phys.h" + +/* Physical manipulations. + The blocks concerned are not in any logical chain. +*/ + +public mallink * +create_chunk(p, n) + char *p; + unsigned int n; +{ + /* The newly acquired piece of memory at p, of length n, + is turned into a free chunk, properly chained in the + physical chain. + The address of the chunk is returned. + */ + register mallink *ml; + /* All of malloc memory is followed by a virtual chunk, the + mallink of which starts mallink_size() bytes past the last + byte in memory. + Its use is prevented by testing for ml == ml_last first. + */ + register mallink *last = ml_last; + + assert(!last || p == (char *)phys_next_of(last) - mallink_size()); + ml = (mallink *)(p + mallink_size()); /* bump ml */ + started_working_on(ml); + set_free(ml, 1); + set_phys_prev(ml, last); + ml_last = ml; + + set_phys_next(ml, (mallink *)((char *)ml + n)); + calc_checksum(ml); + assert(size_of(ml) + mallink_size() == n); + if (last && free_of(last)) { + coalesce_backw(ml, last); + ml = last; + } + check_mallinks("create_chunk, phys. linked"); + return ml; +} + +public +truncate(ml, size) + register mallink *ml; + unsigned int size; +{ + /* The chunk ml is truncated. + The chunk at ml is split in two. + The remaining part is then freed. + */ + register mallink *new = (mallink *)((char *)ml + size); + register mallink *ph_next = phys_next_of(ml); + + set_free(new, 1); + set_phys_prev(new, ml); + set_phys_next(new, ph_next); + calc_checksum(new); + if (! last_mallink(ml)) { + set_phys_prev(ph_next, new); + calc_checksum(ph_next); + if (free_of(ph_next)) coalesce_forw(new, ph_next); + } + else ml_last = new; + set_phys_next(ml, new); + calc_checksum(ml); + + started_working_on(new); + link_free_chunk(new); + stopped_working_on(new); + check_mallinks("truncate"); +} + +public +combine_chunks(ml1, ml2) + register mallink *ml1, *ml2; +{ + /* The chunks ml1 and ml2 are combined. + */ + register mallink *ml3 = phys_next_of(ml2); + + set_phys_next(ml1, ml3); + calc_checksum(ml1); + if (!last_mallink(ml2)) { + set_phys_prev(ml3, ml1); + calc_checksum(ml3); + } + if (ml_last == ml2) + ml_last = ml1; +} diff --git a/modules/src/malloc/phys.h b/modules/src/malloc/phys.h new file mode 100644 index 00000000..f11d4765 --- /dev/null +++ b/modules/src/malloc/phys.h @@ -0,0 +1,61 @@ +/* Algorithms to manipulate the doubly-linked list of physical + chunks. +*/ +publicdata mallink *ml_last; + +#define __free_of(ml) ((size_type)_phys_prev_of(ml) & 01) +#define __phys_prev_of(ml) (mallink *)((size_type)_phys_prev_of(ml) & ~01) +#define prev_size_of(ml) ((char *)(ml) - \ + (char *)__phys_prev_of(ml) - \ + mallink_size() \ + ) +#define set_phys_prev(ml,e) \ + (_phys_prev_of(ml) = (mallink *) ((char *)e + __free_of(ml))) + +#ifdef CHECK +public Error(); +#define phys_prev_of(ml) (mallink *) \ + (first_mallink(ml) ? \ + (char *)Error("phys_prev_of first_mallink %ld", "somewhere", ml) : \ + (char *)__phys_prev_of(ml) \ + ) +#else ndef CHECK +#define phys_prev_of(ml) __phys_prev_of(ml) +#endif CHECK + +#define first_mallink(ml) (int) (__phys_prev_of(ml) == 0) +#define last_mallink(ml) (int) ((ml) == ml_last) + +/* There is an ambiguity in the semantics of phys_next_of: sometimes + one wants it to return MAL_NULL if there is no next chunk, at + other times one wants the address of the virtual chunk at the + end of memory. The present version returns the address of the + (virtual) chunk and relies on the user to test last_mallink(ml) + first. +*/ +#define size_of(ml) (_this_size_of(ml) - mallink_size()) +#define set_phys_next(ml,e) \ + (_this_size_of(ml) = (unsigned int)((char *)(e) - (char *)(ml))) +#define phys_next_of(ml) (mallink *) ((char *)(ml) + _this_size_of(ml)) + +#define set_free(ml,e) \ + (_phys_prev_of(ml) = (mallink *) \ + ((e) ? (size_type) _phys_prev_of(ml) | 01 : \ + (size_type) _phys_prev_of(ml) & ~01)) +#define free_of(ml) (__free_of(ml)) + +#define coalesce_forw(ml,nxt) ( unlink_free_chunk(nxt), \ + combine_chunks((ml), (nxt))) + +#define coalesce_backw(ml,prv) ( unlink_free_chunk(prv), \ + stopped_working_on(ml), \ + combine_chunks((prv), (ml)), \ + started_working_on(prv)) + +#ifdef CHECK +#define set_print(ml,e) (_print_of(ml) = (e)) +#define print_of(ml) (_print_of(ml)) +#endif CHECK + +public truncate(), combine_chunks(); +public mallink *create_chunk(); From d0a3ad87044468f56b5a397926956bfc77290746 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 6 Jan 1987 11:41:50 +0000 Subject: [PATCH 0420/1625] Initial revision --- modules/src/string/bts2str.c | 33 ++++ modules/src/string/btscat.c | 16 ++ modules/src/string/btscmp.c | 16 ++ modules/src/string/btscpy.c | 14 ++ modules/src/string/btszero.c | 11 ++ modules/src/string/long2str.c | 60 +++++++ modules/src/string/str2bts.c | 67 ++++++++ modules/src/string/str2long.c | 32 ++++ modules/src/string/strcat.c | 15 ++ modules/src/string/strcmp.c | 12 ++ modules/src/string/strcpy.c | 12 ++ modules/src/string/strindex.c | 12 ++ modules/src/string/string.3 | 250 +++++++++++++++++++++++++++++ modules/src/string/strlen.c | 12 ++ modules/src/string/strncat.c | 16 ++ modules/src/string/strncmp.c | 18 +++ modules/src/string/strncpy.c | 13 ++ modules/src/string/strrindex.c | 11 ++ modules/src/string/strzero.c | 9 ++ modules/src/system/access.c | 11 ++ modules/src/system/break.c | 17 ++ modules/src/system/chmode.c | 9 ++ modules/src/system/close.c | 11 ++ modules/src/system/create.c | 24 +++ modules/src/system/exit.c | 9 ++ modules/src/system/filesize.c | 15 ++ modules/src/system/lock.c | 27 ++++ modules/src/system/modtime.c | 15 ++ modules/src/system/open.c | 53 +++++++ modules/src/system/read.c | 12 ++ modules/src/system/remove.c | 8 + modules/src/system/stop.c | 17 ++ modules/src/system/system.3 | 281 +++++++++++++++++++++++++++++++++ modules/src/system/system.c | 20 +++ modules/src/system/system.h | 40 +++++ modules/src/system/time.c | 9 ++ modules/src/system/unlock.c | 8 + modules/src/system/write.c | 12 ++ 38 files changed, 1227 insertions(+) create mode 100644 modules/src/string/bts2str.c create mode 100644 modules/src/string/btscat.c create mode 100644 modules/src/string/btscmp.c create mode 100644 modules/src/string/btscpy.c create mode 100644 modules/src/string/btszero.c create mode 100644 modules/src/string/long2str.c create mode 100644 modules/src/string/str2bts.c create mode 100644 modules/src/string/str2long.c create mode 100644 modules/src/string/strcat.c create mode 100644 modules/src/string/strcmp.c create mode 100644 modules/src/string/strcpy.c create mode 100644 modules/src/string/strindex.c create mode 100644 modules/src/string/string.3 create mode 100644 modules/src/string/strlen.c create mode 100644 modules/src/string/strncat.c create mode 100644 modules/src/string/strncmp.c create mode 100644 modules/src/string/strncpy.c create mode 100644 modules/src/string/strrindex.c create mode 100644 modules/src/string/strzero.c create mode 100644 modules/src/system/access.c create mode 100644 modules/src/system/break.c create mode 100644 modules/src/system/chmode.c create mode 100644 modules/src/system/close.c create mode 100644 modules/src/system/create.c create mode 100644 modules/src/system/exit.c create mode 100644 modules/src/system/filesize.c create mode 100644 modules/src/system/lock.c create mode 100644 modules/src/system/modtime.c create mode 100644 modules/src/system/open.c create mode 100644 modules/src/system/read.c create mode 100644 modules/src/system/remove.c create mode 100644 modules/src/system/stop.c create mode 100644 modules/src/system/system.3 create mode 100644 modules/src/system/system.c create mode 100644 modules/src/system/system.h create mode 100644 modules/src/system/time.c create mode 100644 modules/src/system/unlock.c create mode 100644 modules/src/system/write.c diff --git a/modules/src/string/bts2str.c b/modules/src/string/bts2str.c new file mode 100644 index 00000000..d6a4705d --- /dev/null +++ b/modules/src/string/bts2str.c @@ -0,0 +1,33 @@ +/* bts2str() turns a row of bytes b with length n into string s + The ASCII set of characters is used. + 86/03/17 EHB +*/ + +#define is_print(c) ((unsigned)((c) - ' ') <= '~' - ' ') + +char * +bts2str(b, n, s) + char *b, *s; + register int n; +{ + register char *f = b, *t = s; + + while (n-- > 0) { + if (is_print(*f)) + *t++ = *f++; + else { + register int n = (*f++ & 0377); + register int i; + register char *p; + + *t = '\\'; + p = (t += 4); + for (i = 0; i < 3; i++) { + *--p = (n & 07) + '0'; + n >>= 3; + } + } + } + *t = '\000'; + return s; +} diff --git a/modules/src/string/btscat.c b/modules/src/string/btscat.c new file mode 100644 index 00000000..a5f3caf6 --- /dev/null +++ b/modules/src/string/btscat.c @@ -0,0 +1,16 @@ +/* btscat() +*/ + +char * +btscat(b1, n1, b2, n2) + char *b1; + int n1; + register char *b2; + register int n2; +{ + register char *b = b1 + n1; + + while (n2-- > 0) + *b++ = *b2++; + return b1; +} diff --git a/modules/src/string/btscmp.c b/modules/src/string/btscmp.c new file mode 100644 index 00000000..32e794b5 --- /dev/null +++ b/modules/src/string/btscmp.c @@ -0,0 +1,16 @@ +/* btscmp() +*/ + +int +btscmp(b1, n1, b2, n2) + register char *b1, *b2; + int n1, n2; +{ + register n = (n1 <= n2) ? n1 : n2; + + while (n-- > 0) { + if (*b1++ != *b2++) + return *--b1 - *--b2; + } + return n2 - n1; +} diff --git a/modules/src/string/btscpy.c b/modules/src/string/btscpy.c new file mode 100644 index 00000000..e5c6adbb --- /dev/null +++ b/modules/src/string/btscpy.c @@ -0,0 +1,14 @@ +/* btscpy() +*/ + +char * +btscpy(b1, b2, n) + register char *b1, *b2; + register int n; +{ + char *b1s = b1; + + while (n-- > 0) + *b1++ = *b2++; + return b1s; +} diff --git a/modules/src/string/btszero.c b/modules/src/string/btszero.c new file mode 100644 index 00000000..c4aca369 --- /dev/null +++ b/modules/src/string/btszero.c @@ -0,0 +1,11 @@ +/* btszero() +*/ + +char * +btszero(b, n) + register char *b; + register int n; +{ + while (n-- > 0) + *b++ = '\0'; +} diff --git a/modules/src/string/long2str.c b/modules/src/string/long2str.c new file mode 100644 index 00000000..b50eaa0e --- /dev/null +++ b/modules/src/string/long2str.c @@ -0,0 +1,60 @@ +/* Integer to String translator + -> base is a value from [-16,-2] V [2,16] + -> base < 0: see 'val' as unsigned value + -> no checks for buffer overflow and illegal parameters + (1985, EHB) +*/ + +#define MAXWIDTH 32 + +char * +long2str(val, base) + register long val; + register base; +{ + static char numbuf[MAXWIDTH]; + static char vec[] = "0123456789ABCDEF"; + register char *p = &numbuf[MAXWIDTH]; + int sign = (base > 0); + + *--p = '\0'; /* null-terminate string */ + if (val) { + if (base > 0) { + if (val < 0L) { + if ((val = -val) < 0L) + goto overflow; + } + else + sign = 0; + } + else + if (base < 0) { /* unsigned */ + base = -base; + if (val < 0L) { /* taken from Amoeba src */ + register mod, i; + overflow: + mod = 0; + for (i = 0; i < 8 * sizeof val; i++) { + mod <<= 1; + if (val < 0) + mod++; + val <<= 1; + if (mod >= base) { + mod -= base; + val++; + } + } + *--p = vec[mod]; + } + } + do { + *--p = vec[(int) (val % base)]; + val /= base; + } while (val != 0L); + if (sign) + *--p = '-'; /* don't forget it !! */ + } + else + *--p = '0'; /* just a simple 0 */ + return p; +} diff --git a/modules/src/string/str2bts.c b/modules/src/string/str2bts.c new file mode 100644 index 00000000..eec3b645 --- /dev/null +++ b/modules/src/string/str2bts.c @@ -0,0 +1,67 @@ +/* str2bts -- (1985, EHB) +*/ +static +is_oct(c) + char c; +{ + return (c == '0' || c == '1' || c == '2' || c == '3' || + c == '4' || c == '5' || c == '6' || c == '7'); +} + +/* str2bts() strips the escaped characters of a + string and replaces them by the ascii characters they stand for. + The ascii length of the resulting string is returned, including the + terminating null-character. +*/ +char * +str2bts(str, bts, pn) + register char *str; + char *bts; + int *pn; +{ + register char *t = bts; + + while (*str) { + if (*str == '\\') { + switch (*++str) { + case 'b': + *t++ = '\b'; + str++; + break; + case 'f': + *t++ = '\f'; + str++; + break; + case 'n': + *t++ = '\n'; + str++; + break; + case 'r': + *t++ = '\r'; + str++; + break; + case 't': + *t++ = '\t'; + str++; + break; + default: + if (is_oct(*str)) { + register cnt = 0, oct = 0; + + do + oct = oct * 8 + *str - '0'; + while (is_oct(*++str) && ++cnt < 3); + *t++ = (char) oct; + break; + } + *t++ = *str++; + break; + } + } + else + *t++ = *str++; + } + *t = '\0'; /* don't forget this one !!! */ + *pn = t - bts + 1; + return bts; +} diff --git a/modules/src/string/str2long.c b/modules/src/string/str2long.c new file mode 100644 index 00000000..a058987c --- /dev/null +++ b/modules/src/string/str2long.c @@ -0,0 +1,32 @@ +/* str2long() +*/ + +value(c, b) + char c; + int b; +{ + if (c >= '0' && c <= '9') + return c - '0'; + if (c >= 'A' && c <= 'F') + return c - 'A' + 10; + if (c >= 'a' && c <= 'f') + return c - 'a' + 10; + return b; +} + +long +str2long(str, base) + register char *str; + int base; +{ + int minus = 0, d; + long l = 0; + + if (*str == '-') { + minus++; + str++; + } + while ((d = value(*str++, base)) < base) + l = base * l + d; + return minus ? -l : l; +} diff --git a/modules/src/string/strcat.c b/modules/src/string/strcat.c new file mode 100644 index 00000000..861d663f --- /dev/null +++ b/modules/src/string/strcat.c @@ -0,0 +1,15 @@ +/* append t to s +*/ +char * +strcat(s, t) + register char *s, *t; +{ + register char *b = s; + + while (*s++) + ; + s--; + while (*s++ = *t++) + ; + return b; +} diff --git a/modules/src/string/strcmp.c b/modules/src/string/strcmp.c new file mode 100644 index 00000000..ca69d45f --- /dev/null +++ b/modules/src/string/strcmp.c @@ -0,0 +1,12 @@ +/* return negative, zero or positive value if + resp. s < t, s == t or s > t +*/ +int +strcmp(s, t) + register char *s, *t; +{ + while (*s == *t++) + if (*s++ == '\0') + return 0; + return *s - *--t; +} diff --git a/modules/src/string/strcpy.c b/modules/src/string/strcpy.c new file mode 100644 index 00000000..409d0bf3 --- /dev/null +++ b/modules/src/string/strcpy.c @@ -0,0 +1,12 @@ +/* Copy t into s +*/ +char * +strcpy(s, t) + register char *s, *t; +{ + register char *b = s; + + while (*s++ = *t++) + ; + return b; +} diff --git a/modules/src/string/strindex.c b/modules/src/string/strindex.c new file mode 100644 index 00000000..49e44644 --- /dev/null +++ b/modules/src/string/strindex.c @@ -0,0 +1,12 @@ +/* strindex() -- (86/03/18 EHB) +*/ + +char * +strindex(s, c) + register char *s, c; +{ + while (*s) + if (*s++ == c) + return --s; + return (char *)0; +} diff --git a/modules/src/string/string.3 b/modules/src/string/string.3 new file mode 100644 index 00000000..e4ea42d1 --- /dev/null +++ b/modules/src/string/string.3 @@ -0,0 +1,250 @@ +.TH STRING 3ACK "86/03/18" +.SH NAME +strcpy, strncpy, strcat, strncat, strcmp, strncmp, +strlen, strindex, strrindex, strzero, str2bts, +long2str, str2long, +btscpy, btscat, btscmp, btszero, bts2str \- operations on and +conversions between strings and row of bytes +.SH SYNOPSIS +.nf +.B char *strcpy(s1, s2) +.B char *s1, *s2; +.PP +.B char *strncpy(s1, s2, n) +.B char *s1, *s2; +.PP +.B char *strcat(s1, s2) +.B char *s1, *s2; +.PP +.B char *strncat(s1, s2, n) +.B char *s1, *s2; +.PP +.B int strcmp(s1, s2) +.B char *s1, *s2; +.PP +.B int strncmp(s1, s2, n) +.B char *s1, *s2; +.PP +.B int strlen(s) +.B char *s; +.PP +.B char *strindex(s, c) +.B char *s, c; +.PP +.B char *strrindex(s, c) +.B char *s, c; +.PP +.B char *strzero(s) +.B char *s; +.PP +.B char *str2bts(s, b, pn) +.B char *s, *b; +.B int *pn; +.PP +.B char *long2str(l, base) +.B long l; +.B int base; +.PP +.B long str2long(s, base) +.B char *s; +.B int base; +.PP +.B char *btscpy(b1, b2, n) +.B char *b1, *b2; +.B int n; +.PP +.B char *btscat(b1, n1, b2, n2) +.B char *b1, *b2; +.B int n1, n2; +.PP +.B int btscmp(b1, n1, b2, n2) +.B char *b1, *b2; +.B int n1, n2; +.PP +.B char *btszero(b, n) +.B char *b; +.B int n; +.PP +.B char *bts2str(b, n, s) +.B char *b, *s; +.B int n; +.fi +.SH DESCRIPTION +The +.IR str * +functions operate on null-terminated strings. +The +.IR bts * +functions operate on variable-length rows of bytes, +regardless of null bytes. +Neither of these functions check for overflow of any receiving area. +.PP +.I Strcpy +copies string +.I s2 +to +.I s1, +stopping after the null character has been moved. +.I Strncpy +copies exactly +.I n +characters, +truncating or null-padding +.I s2; +the target may not be null-terminated if the length +of +.I s2 +is +.I n +or more. +Both return +.IR s1 . +.PP +.I Strcat +appends a copy of string +.I s2 +to the end of string +.IR s1 . +.I Strncat +copies at most +.I n +characters. +Both return a pointer to the null-terminated result +.IR s1 . +.PP +.I Strcmp +compares its arguments and returns an integer +greater than, equal to, or less than 0, if +.I s1 +is lexicographically greater than, equal to, or +less than +.IR s2 , +respectively. +.I Strncmp +makes the same comparison but checks at most +.I n +characters. +.PP +.I Strlen +returns the number of characters before the null-character. +.IR s . +.PP +.I Strindex +.RI ( strrindex ) +returns a pointer to the first (last) +occurrence of character +.I c +in string +.I s, +or zero if +.I c +does not occur in +.IR s . +.PP +.I Bts2str +turns a row of +.I n +consecutive bytes, the first of which is pointed by +.IR b , +into a null-terminated string, starting at +.IR s . +Printable characters are copied and non-printable characters are transformed +into sequences of printable characters, representing those characters. +The transformation agrees with the representation of non-printable +characters in C strings. +.br +E.g., the row of 2 bytes +.RS +\&'\e0' '\en' +.RE +is turned into the string consisting of the following characters +.RS +\&'\e\e' '0' '0' '0' '\e\e' 'n' '\e0' +.RE +The latter string could be represented in C as "\e\e000\e\en". +.PP +.I Str2bts +turns string +.I s +into a sequence of bytes pointed by +.IR b . +It has the inverse effect to +.IR bts2str . +The length of the resulting byte sequence is returned in +.RI * pn . +.br +Both the functions +.I bts2str +and +.I str2bts +return a pointer to the result. +.PP +.I Long2str +converts a long value +.I l +into a null-terminated string according to +.IR base , +which indicates the base to use. +This base may be any of 2..16. +A negative base (in the range -16..-2) indicates that the long must be +seen as unsigned. +A pointer to the string is returned. +.I Str2long +returns the value that is represented in +.IR s , +according to +.IR base . +.PP +.I Btscpy +copies +.I n +bytes from the string of bytes +.I b2 +to +.I b1 +and returns +.IR b1 . +.PP +.I Btscat +appends a copy of +.I n2 +bytes from +.I b2 +to the end of +.IR b1 , +consisting of +.I n1 +bytes. +.I B1 +is returned. +.PP +.I Btscmp +compares row of bytes +.I b1 +with length +.I n1 +and +.I b2 +with length +.I n2 +and returns an integer greater than, equal to, or less than 0, if +.I b1 +is lexicographically greater then, equal to, or less than +.IR b2 , +respectively. +.PP +.I Btszero +places +.I n +null bytes in the string +.IR b . +.I B +is returned. +.SH FILES +~em/modules/lib/libstring.a +.SH "SEE ALSO" +string(3), bstring(3), atof(3) +.SH BUGS +No checks for overflow or illegal parameters. +.SH AUTHOR +Erik Baalbergen diff --git a/modules/src/string/strlen.c b/modules/src/string/strlen.c new file mode 100644 index 00000000..581fcbd5 --- /dev/null +++ b/modules/src/string/strlen.c @@ -0,0 +1,12 @@ +/* return length of s +*/ +int +strlen(s) + char *s; +{ + register char *b = s; + + while (*b++) + ; + return b - s - 1; +} diff --git a/modules/src/string/strncat.c b/modules/src/string/strncat.c new file mode 100644 index 00000000..881454a7 --- /dev/null +++ b/modules/src/string/strncat.c @@ -0,0 +1,16 @@ +/* append t to s, upto n characters +*/ +char * +strncat(s, t, n) + register char *s, *t; + register int n; +{ + register char *b = s; + + while (*s++) + ; + s--; + while ((n-- > 0) && (*s++ = *t++)) + ; + return b; +} diff --git a/modules/src/string/strncmp.c b/modules/src/string/strncmp.c new file mode 100644 index 00000000..86d39c02 --- /dev/null +++ b/modules/src/string/strncmp.c @@ -0,0 +1,18 @@ +/* return negative, zero or positive value if + resp. s < t, s == t or s > t; compare at most n characters +*/ +int +strncmp(s, t, n) + register char *s, *t; + register int n; +{ + while (n-- > 0) { + if (*s == *t++) { + if (*s++ == '\0') + return 0; + } + else + return *s - *--t; + } + return 0; +} diff --git a/modules/src/string/strncpy.c b/modules/src/string/strncpy.c new file mode 100644 index 00000000..f554d0c2 --- /dev/null +++ b/modules/src/string/strncpy.c @@ -0,0 +1,13 @@ +/* Copy t into s, upto n characters +*/ +char * +strncpy(s, t, n) + register char *s, *t; + register int n; +{ + register char *b = s; + + while ((n-- > 0) && (*s++ = *t++)) + ; + return b; +} diff --git a/modules/src/string/strrindex.c b/modules/src/string/strrindex.c new file mode 100644 index 00000000..d55bf01b --- /dev/null +++ b/modules/src/string/strrindex.c @@ -0,0 +1,11 @@ +char * +strrindex(str, chr) + register char *str, chr; +{ + register char *retptr = 0; + + while (*str) + if (*str++ == chr) + retptr = &str[-1]; + return retptr; +} diff --git a/modules/src/string/strzero.c b/modules/src/string/strzero.c new file mode 100644 index 00000000..86036a92 --- /dev/null +++ b/modules/src/string/strzero.c @@ -0,0 +1,9 @@ +/* strzero() +*/ + +char * +strzero(s) + char *s; +{ + *s = '\0'; +} diff --git a/modules/src/system/access.c b/modules/src/system/access.c new file mode 100644 index 00000000..7300c87e --- /dev/null +++ b/modules/src/system/access.c @@ -0,0 +1,11 @@ +/* $Header$ */ + +#include + +int +sys_access(path, mode) + char *path; + int mode; +{ + return access(path, mode) == 0; +} diff --git a/modules/src/system/break.c b/modules/src/system/break.c new file mode 100644 index 00000000..1160d326 --- /dev/null +++ b/modules/src/system/break.c @@ -0,0 +1,17 @@ +/* $Header$ */ + +#include + +char *sbrk(); + +char * +sys_break(incr) + int incr; +{ + char *sbrk(); + char *brk = sbrk(incr); + + if (brk == (char *) 0 || brk == (char *)-1) + return ILL_BREAK; + return brk; +} diff --git a/modules/src/system/chmode.c b/modules/src/system/chmode.c new file mode 100644 index 00000000..ce14844e --- /dev/null +++ b/modules/src/system/chmode.c @@ -0,0 +1,9 @@ +/* $Header$ */ + +int +sys_chmode(path, mode) + char *path; + int mode; +{ + return chmod(path, mode) == 0; +} diff --git a/modules/src/system/close.c b/modules/src/system/close.c new file mode 100644 index 00000000..ffb9b7ea --- /dev/null +++ b/modules/src/system/close.c @@ -0,0 +1,11 @@ +/* $Header$ */ + +#include + +sys_close(fp) + register File *fp; +{ + fp->o_flags = 0; + close(fp->o_fd); + fp->o_fd = -1; +} diff --git a/modules/src/system/create.c b/modules/src/system/create.c new file mode 100644 index 00000000..c33ddbfb --- /dev/null +++ b/modules/src/system/create.c @@ -0,0 +1,24 @@ +/* $Header$ */ + +#include + +extern File *_get_entry(); + +int +sys_create(filep, path, mode) + File **filep; + char *path; + int mode; +{ + register fd; + register File *fp; + + if ((fp = _get_entry()) == (File *)0) + return 0; + if ((fd = creat(path, mode)) < 0) + return 0; + fp->o_fd = fd; + fp->o_flags = OP_WRITE; + *filep = fp; + return 1; +} diff --git a/modules/src/system/exit.c b/modules/src/system/exit.c new file mode 100644 index 00000000..011fd466 --- /dev/null +++ b/modules/src/system/exit.c @@ -0,0 +1,9 @@ +/* $Header$ */ +/* called by /lib/crt0.o; needed to suppress the loading of the + standard exit() which performs unnecessary cleanup actions +*/ + +exit(n) +{ + _exit(n); +} diff --git a/modules/src/system/filesize.c b/modules/src/system/filesize.c new file mode 100644 index 00000000..588d66eb --- /dev/null +++ b/modules/src/system/filesize.c @@ -0,0 +1,15 @@ +/* $Header$ */ + +#include +#include + +long +sys_filesize(path) + char *path; +{ + struct stat st_buf; + + if (stat(path, &st_buf) != 0) + return -1L; + return (long) st_buf.st_size; +} diff --git a/modules/src/system/lock.c b/modules/src/system/lock.c new file mode 100644 index 00000000..608ad3c5 --- /dev/null +++ b/modules/src/system/lock.c @@ -0,0 +1,27 @@ +/* $Header$ */ + +int +sys_lock(path) + char *path; +{ + char buf[1024]; + char *tmpf = ".lockXXXXXX"; + char *strrindex(); + char *p; + int ok, fd; + + strcpy(buf, path); + if (p = strrindex(buf, '/')) { + ++p; + strcpy(p, tmpf); + } + else + strcpy(buf, tmpf); + mktemp(buf); + if ((fd = creat(buf, 0)) < 0) + return 0; + close(fd); + ok = (link(buf, path) == 0); + unlink(buf); + return ok; +} diff --git a/modules/src/system/modtime.c b/modules/src/system/modtime.c new file mode 100644 index 00000000..ff81b00c --- /dev/null +++ b/modules/src/system/modtime.c @@ -0,0 +1,15 @@ +/* $Header$ */ + +#include +#include + +long +sys_modtime(path) + char *path; +{ + struct stat st_buf; + + if (stat(path, &st_buf) != 0) + return -1L; + return (long) st_buf.st_mtime; +} diff --git a/modules/src/system/open.c b/modules/src/system/open.c new file mode 100644 index 00000000..65aefd0d --- /dev/null +++ b/modules/src/system/open.c @@ -0,0 +1,53 @@ +/* $Header$ */ + +#include + +extern File *_get_entry(); + +int +sys_open(path, flag, filep) + char *path; + int flag; + File **filep; +{ + register fd; + register File *fp; + int open_mode; + long lseek(); + + switch (flag) { + case OP_READ: + open_mode = 0; + break; + case OP_WRITE: + case OP_APPEND: + open_mode = 1; + break; + default: + return 0; + } + if ((fp = _get_entry()) == (File *)0) + return 0; + if (flag == OP_WRITE) { + if ((fd = creat(path, 0644)) < 0) + return 0; + } + else /* OP_READ or OP_APPEND */ + if ((fd = open(path, open_mode)) < 0) { + if (flag == OP_READ || access(path, 0) == 0) + return 0; + /* now: flag == OP_APPEND */ + if ((fd = creat(path, 0644)) < 0) + return 0; + } + else { + if (flag == OP_APPEND && (lseek(fd, 0L, 2) < 0L)) { + close(fd); + return 0; + } + } + fp->o_flags = flag; + fp->o_fd = fd; + *filep = fp; + return 1; +} diff --git a/modules/src/system/read.c b/modules/src/system/read.c new file mode 100644 index 00000000..93e08e03 --- /dev/null +++ b/modules/src/system/read.c @@ -0,0 +1,12 @@ +/* $Header$ */ + +#include + +int +sys_read(fp, bufptr, bufsiz, pnbytes) + File *fp; + char *bufptr; + int bufsiz, *pnbytes; +{ + return (*pnbytes = read(fp->o_fd, bufptr, bufsiz)) >= 0; +} diff --git a/modules/src/system/remove.c b/modules/src/system/remove.c new file mode 100644 index 00000000..0b6452cb --- /dev/null +++ b/modules/src/system/remove.c @@ -0,0 +1,8 @@ +/* $Header$ */ + +int +sys_remove(path) + char *path; +{ + return unlink(path) == 0; +} diff --git a/modules/src/system/stop.c b/modules/src/system/stop.c new file mode 100644 index 00000000..57ea3811 --- /dev/null +++ b/modules/src/system/stop.c @@ -0,0 +1,17 @@ +/* $Header$ */ + +#include + +sys_stop(how) + int how; +{ + switch(how) { + case S_END: + exit(0); + case S_EXIT: + exit(1); + case S_ABORT: + default: + abort(); + } +} diff --git a/modules/src/system/system.3 b/modules/src/system/system.3 new file mode 100644 index 00000000..a2fb5102 --- /dev/null +++ b/modules/src/system/system.3 @@ -0,0 +1,281 @@ +.TH SYSTEM 3ACK "86/03/24" +.SH NAME +sys_open, sys_close, sys_read, sys_write, sys_reset, sys_access, +sys_modtime, sys_remove, sys_filesize, sys_chmode, +sys_lock, sys_unlock, +sys_break, sys_stop, sys_time \- system call interface +.SH SYNOPSIS +.nf +.B #include +.PP +.B File *STDIN, *STDOUT, *STDERR; +.PP +.B int sys_open(path, flag, filep) +.B char *path; +.B int flag; +.B File **filep; +.PP +.B sys_close(filep) +.B File *filep; +.PP +.B int sys_read(filep, bufptr, bufsiz, pnbytes) +.B File *filep; +.B char *bufptr; +.B int bufsiz, *pnbytes; +.PP +.B int sys_write(filep, bufptr, nbytes) +.B File *filep; +.B char *bufptr; +.B int nbytes; +.PP +.B int sys_reset(filep) +.B File *filep +.PP +.B int sys_access(path, mode) +.B char *path; +.B int mode; +.PP +.B int sys_remove(path) +.B char *path; +.PP +.B long sys_filesize(path) +.B char *path; +.PP +.B int sys_chmode(path, mode) +.B char *path; +.B int mode; +.PP +.B int sys_lock(name) +.B char *name; +.PP +.B int sys_unlock(name) +.B char *name; +.PP +.B char *sys_break(incr) +.B int incr; +.PP +.B sys_stop(how) +.B int how; +.PP +.B long sys_time(); +.PP +.B long sys_modtime(path) +.B char *path; +.fi +.SH DESCRIPTION +This package provides a rather system-independent set of "system" calls +primarily intended for use in compilers. +The include file contains a defined constant, +.IR BUFSIZ , +which gives the system-dependent block size. +Another constant, +.IR SYS_NOPEN , +gives the maximum number of open files in a process. +.PP +.I Sys_open +opens a file called +.I path +for sequential reading or writing, as specified by +.I flag +and returns in +.I filep +a decsriptor for the opened file. +The allowed values for +.I flag +are +.IP OP_READ 15 +open for reading +.IP OP_WRITE 15 +open for rewriting (create +.I path +if it did not exist) +.IP OP_APPEND 15 +open for writing at the end (create +.I path +if it did not exist) +.LP +Created files are given read and write permission for its creator and +read permission for other users. +.br +Specifying +.I path +as null pointer opens a so-called anonymous file, which has no name and +disappears when it is closed or when the program exits. +It is possible to read the contents of an anonymous file by using +.I reset . +.br +There are three normally open files with the following descriptors: +.IP STDIN 15 +standard input file; opened as OP_READ +.IP STDOUT 15 +standard output file; opened as OP_APPEND +.IP STDERR 15 +standard error file; opened as OP_APPEND +.LP +.I Sys_close +causes the open file known by +.I filep +to be closed. +.PP +.I Sys_read +causes up to +.I bufsiz +contiguous bytes to be read from the open file known by +.I filep +into a piece of memory pointed at by +.IR bufptr . +The number of bytes actually read is returned in +.IR *pnbytes . +If +.I *pnbytes +is set to 0 then the end-of-file is reached. +.PP +.I Sys_write +writes +.I nbytes +contiguous bytes from the memory pointed at by +.I bufptr +onto the open file known by +.IR filep . +A non-zero return value indicates that +.I nbytes +are actually written. +.PP +.I Sys_reset +causes the open file known by +.I filep +to be re-opened for reading (cf. open flag OP_READ). +This may be useful in reading anonymous files. +.PP +.I Sys_access +checks the given file +.I path +for accessibility according to +.I mode +which is the result of +.IR or 'ing +one or more of the following values: +.IP AC_READ 15 +file exists and is readable +.IP AC_WRITE 15 +file exists and is writable +.IP AC_EXEC 15 +file exists and is executable +.LP +Specifying +.I mode +as 0 tests whether the directories leading to the file can be searched and the +file exists. +The return value is either 0 if the +file is not reachable, does not exist or if the access is not allowed, +or 1 if the indicated access is permitted. +.PP +.I Sys_modtime +returns the last-modified time of the file specified in +.IR path . +Any failure is indicated by a return value of \-1L. +.PP +.I Sys_remove +removes file +.I path +from the system. +It is supposed that, if the file is still open, the contents of +the file are available until the last +.I sys_close +is performed on it. +A non-zero return value indicates successful action whereas 0 +indicates that the given file does not exist or cannot be removed. +.PP +The function +.I sys_filesize +returns the size in bytes of the +file specified by +.IR path , +if possible. +The value \-1L is returned if the size cannot be retrieved for some reason. +.PP +.I Sys_chmode +changes the file-protection mode of file +.I path +to +.IR mode . +.PP +.I Sys_lock +and +.I sys_unlock +provide a mechanism for setting and clearing symbolic locks for external +objects. +This is done by creating and removing file +.IR name . +.I Sys_lock +returns zero if the lock is already set and a non-zero value if the lock +did not exist and has been created. +.I Sys_unlock +returns a non-zero value if the lock did not exist or if the lock has been +removed succesfully. +Zero is returned otherwise. +The actions performed by these routines are atomic: +race conditions cannot +occur. +.PP +.I Sys_break +adds +.I incr +more bytes to the program's data space and returns a pointer to +the newly allocated area. +ILL_BREAK is returned in case of some error, due to a lack of space or +some interrupt. +It is equivalent to the UNIX version 7 +.IR sbrk (2). +.PP +.I Sys_stop +should be called when the process is terminated due to +the end of the program or some error. +This routine closes all open files and causes the program to +stop in a way specified by +.IR how , +which parameter has one of the following values: +.IP S_END 15 +normal termination, indicate successful completion +.IP S_EXIT 15 +terminate the process with status +.B 1 +.IP S_ABORT 15 +abort this process and produce a post-mortem dump +.LP +.PP +.I Sys_time +returns a long value that stands for the system's time. +Its return value is a long that stands for the time +since 00:00:00 GMT, Jan. 1, 1970, measured in seconds. +.SH FILES +.nf +~em/modules/h/system.h +~em/modules/lib/libsystem.a +.fi +.SH DIAGNOSTICS +.PP +The routines +.IR sys_open , +.IR sys_read , +.IR sys_write , +.IR sys_reset , +.I sys_chmode +and +.I sys_remove +return a value of zero upon any failure and a non-zero +value if the call succeeds. +.SH BUGS +The current implementation does not allow the use of anonymous files. +.br +.I Sys_reset +is not implemented. +A +.I sys_close +followed by a +.I sys_open +with the proper mode has the same effect on non-anonymous files. +.SH "SEE ALSO" +UNIX version 7 manual volume 1, chapter 2 +.SH AUTHOR +Erik Baalbergen diff --git a/modules/src/system/system.c b/modules/src/system/system.c new file mode 100644 index 00000000..68871dea --- /dev/null +++ b/modules/src/system/system.c @@ -0,0 +1,20 @@ +/* RCS: $Header$ */ + +#include + +File _sys_ftab[SYS_NOPEN] = { + { 0, OP_READ}, + { 1, OP_APPEND}, + { 2, OP_APPEND} +}; + +File * +_get_entry() +{ + register File *fp; + + for (fp = &_sys_ftab[0]; fp < &_sys_ftab[SYS_NOPEN]; fp++) + if (fp->o_flags == 0) + return fp; + return (File *)0; +} diff --git a/modules/src/system/system.h b/modules/src/system/system.h new file mode 100644 index 00000000..a43e1e2a --- /dev/null +++ b/modules/src/system/system.h @@ -0,0 +1,40 @@ +/* RCS: $Header$ */ + +struct _sys_fildes { + int o_fd; /* UNIX filedescriptor */ + int o_flags; /* flags for open; 0 if not used */ +}; + +typedef struct _sys_fildes File; + +extern File _sys_ftab[]; + +/* flags for sys_open() */ +#define OP_READ 01 +#define OP_WRITE 02 +#define OP_APPEND 04 + +/* flags for sys_access() */ +#define AC_EXIST 00 +#define AC_READ 04 +#define AC_WRITE 02 +#define AC_EXEC 01 + +/* flags for sys_stop() */ +#define S_END 0 +#define S_EXIT 1 +#define S_ABORT 2 + +/* standard file decsriptors */ +#define STDIN &_sys_ftab[0] +#define STDOUT &_sys_ftab[1] +#define STDERR &_sys_ftab[2] + +/* maximum number of open files */ +#define SYS_NOPEN 20 + +/* return value for sys_break */ +#define ILL_BREAK ((char *)0) + +/* system's idea of block */ +#define BUFSIZ 1024 diff --git a/modules/src/system/time.c b/modules/src/system/time.c new file mode 100644 index 00000000..ede8eee5 --- /dev/null +++ b/modules/src/system/time.c @@ -0,0 +1,9 @@ +/* $Header$ */ + +long time(); + +long +sys_time() +{ + return time(0); +} diff --git a/modules/src/system/unlock.c b/modules/src/system/unlock.c new file mode 100644 index 00000000..9d30a411 --- /dev/null +++ b/modules/src/system/unlock.c @@ -0,0 +1,8 @@ +/* $Header$ */ + +int +sys_unlock(path) + char *path; +{ + return unlink(path) == 0; +} diff --git a/modules/src/system/write.c b/modules/src/system/write.c new file mode 100644 index 00000000..97b7de71 --- /dev/null +++ b/modules/src/system/write.c @@ -0,0 +1,12 @@ +/* $Header$ */ + +#include + +int +sys_write(fp, bufptr, nbytes) + File *fp; + char *bufptr; + int nbytes; +{ + return write(fp->o_fd, bufptr, nbytes) == nbytes; +} From 785fd2f8acbebc44bb26cf16e850105a1628af7c Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 6 Jan 1987 12:42:31 +0000 Subject: [PATCH 0421/1625] Added a "pr" and an "opr" entry. --- modules/src/idf/Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/src/idf/Makefile b/modules/src/idf/Makefile index 9725feeb..717d1483 100644 --- a/modules/src/idf/Makefile +++ b/modules/src/idf/Makefile @@ -14,4 +14,10 @@ cmp: all $(COMPARE) pkg/idf_pkg.spec $(COMPARE) man/idf.3 +pr: + @pr Makefile idf_pkg.spec idf_pkg.body + +opr: + make pr | opr + clean: From 3c964956879fc19c6d5a490f2985ee6bff7ee512 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 6 Jan 1987 12:59:16 +0000 Subject: [PATCH 0422/1625] Added a "pr" and an "opr" entry. --- modules/src/object/Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/src/object/Makefile b/modules/src/object/Makefile index 88f84776..d7699b74 100644 --- a/modules/src/object/Makefile +++ b/modules/src/object/Makefile @@ -26,6 +26,12 @@ compare: all $(COMPARE) lib/libobject.a $(COMPARE) man/object.3 +pr: + @pr Makefile byte_order.c object.h $(CFILES) + +opr: + make pr | opr + clean: rm -f *.[oa] nohup.out Out byte_order byte_order.h From 37e693b91a180dc0f7d6ff2f405f127573324b04 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 6 Jan 1987 13:42:33 +0000 Subject: [PATCH 0423/1625] Initial revision --- modules/src/em_code/e/em.c | 143 ++++++++++ modules/src/em_code/e/em_private.h | 33 +++ modules/src/em_code/em.nogen | 106 ++++++++ modules/src/em_code/em_code.3X | 408 +++++++++++++++++++++++++++++ modules/src/em_code/make.em.gen | 17 ++ modules/src/em_code/make.fun | 51 ++++ 6 files changed, 758 insertions(+) create mode 100644 modules/src/em_code/e/em.c create mode 100644 modules/src/em_code/e/em_private.h create mode 100644 modules/src/em_code/em.nogen create mode 100644 modules/src/em_code/em_code.3X create mode 100755 modules/src/em_code/make.em.gen create mode 100755 modules/src/em_code/make.fun diff --git a/modules/src/em_code/e/em.c b/modules/src/em_code/e/em.c new file mode 100644 index 00000000..172df600 --- /dev/null +++ b/modules/src/em_code/e/em.c @@ -0,0 +1,143 @@ +/* EM CODE OUTPUT ROUTINES */ + +#include +#include "em_private.h" + +/* + putbyte(), C_open() and C_close() are the basic routines for + respectively write on, open and close the output file. + The put_*() functions serve as formatting functions of the + various EM language constructs. + See "Description of a Machine Architecture for use with + Block Structured Languages" par. 11.2 for the meaning of these + names. +*/ + +static File *ofp = 0; + +C_open(nm) /* open file for readable code output */ + char *nm; +{ + if (nm == 0) + ofp = STDOUT; /* standard output */ + else + if (sys_open(nm, OP_WRITE, &ofp) == 0) + return 0; + return 1; +} + +C_close() +{ + if (ofp != STDOUT) + sys_close(ofp); + ofp = 0; +} + +C_busy() +{ + return ofp != 0; /* true if code is being generated */ +} + +C_magic() +{ +} + +/*** the readable code generating routines ***/ + +put_ilb(l) + label l; +{ + _prnt("*%ld", (long) l); +} + +extern char em_mnem[][4]; +extern char em_pseu[][4]; + +put_op(x) +{ + _prnt(" %s ", em_mnem[x - sp_fmnem]); +} + +put_cst(l) + arith l; +{ + _prnt("%ld", (long) l); +} + +put_scon(x, y) + char *x; + arith y; +{ + char buf[1024]; + char sbuf[1024]; + register char *p, *q = &sbuf[0]; + char *bts2str(); + + p = bts2str(x, (int) y, buf); + while (*p) { + if (*p == '\'') + *q++ = '\\'; + *q++ = *p++; + } + *q = '\0'; + _prnt("'%s'", buf); +} + +put_ps(x) +{ + _prnt(" %s ", em_pseu[x - sp_fpseu]); +} + +put_dlb(l) + label l; +{ + _prnt(".%ld", (long) l); +} + +put_doff(l, v) + label l; + arith v; +{ + if (v == 0) put_dlb(l); + else _prnt(".%ld+%ld", (long) l, (long) v); +} + +put_noff(s, v) + char *s; + arith v; +{ + if (v == 0) _prnt(s); + else _prnt("%s+%ld", s, (long) v); +} + +put_pnam(s) + char *s; +{ + _prnt("$%s", s); +} + +put_dfilb(l) + label l; +{ + _prnt("%ld", (long) l); +} + +put_wcon(sp, v, sz) /* sp_icon, sp_ucon or sp_fcon with int repr */ + int sp; + char *v; + arith sz; +{ + _prnt("%s%c%ld", v, sp == sp_icon ? 'I' : sp == sp_ucon ? 'U' : 'F', + (long) sz); +} + +_prnt(fmt, args) + char *fmt; + int args; +{ + doprnt(ofp, fmt, (int *)&args); +} + +put_nl() { _prnt("\n"); } +put_comma() { _prnt(","); } +put_ccend() { _prnt(" ?"); } diff --git a/modules/src/em_code/e/em_private.h b/modules/src/em_code/e/em_private.h new file mode 100644 index 00000000..0a6a2b42 --- /dev/null +++ b/modules/src/em_code/e/em_private.h @@ -0,0 +1,33 @@ +/* private inclusion file */ + +#include +#include +#include + +/* include the EM description files */ +#include +#include +#include +#include + +/* macros used in the definitions of the interface functions C_* */ +#define OP(x) put_op(x) +#define CST(x) put_cst(x) +#define DCST(x) put_cst(x) +#define SCON(x,y) put_scon((x), (y)) +#define PS(x) put_ps(x) +#define DLB(x) put_dlb(x) +#define DFDLB(x) put_dlb(x) +#define ILB(x) put_ilb(x) +#define DFILB(x) put_dfilb(x) +#define NOFF(x,y) put_noff((x), (y)) +#define DOFF(x,y) put_doff((x), (y)) +#define PNAM(x) put_pnam(x) +#define DNAM(x) _prnt(x) +#define DFDNAM(x) _prnt(x) +#define CEND() +#define CCEND() put_ccend() +#define WCON(x,y,z) put_wcon((x), (y), (z)) +#define COMMA() put_comma() +#define NL() put_nl() +#define CILB(x) put_ilb(x) diff --git a/modules/src/em_code/em.nogen b/modules/src/em_code/em.nogen new file mode 100644 index 00000000..e3e63969 --- /dev/null +++ b/modules/src/em_code/em.nogen @@ -0,0 +1,106 @@ +% Definition of EM procedural interface: hand-written definitions + +% C_open | char *:filename | +% C_busy | | +% C_close | | +% C_magic | | + +C_df_dlb | label:l | DFDLB(l); NL() +C_df_dnam | char *:s | DFDNAM(s); NL() +C_df_ilb | label:l | DFILB(l); NL() + +C_pro | char *:s arith:l | + PS(ps_pro); PNAM(s); COMMA(); CST(l); NL() +C_pro_narg | char *:s | + PS(ps_pro); PNAM(s); COMMA(); CCEND(); NL() +C_end | arith:l | PS(ps_end); CST(l); NL() +C_end_narg | | PS(ps_end); CCEND(); NL() + +C_exa_dnam | char *:s | PS(ps_exa); DNAM(s); NL() +C_exa_dlb | label:l | PS(ps_exa); DLB(l); NL() +C_exp | char *:s | PS(ps_exp); PNAM(s); NL() +C_ina_dnam | char *:s | PS(ps_ina); DNAM(s); NL() +C_ina_dlb | label:l | PS(ps_ina); DLB(l); NL() +C_inp | char *:s | PS(ps_inp); PNAM(s); NL() + +C_bss_cst | arith:n arith:w int:i | + PS(ps_bss); DCST(n); COMMA(); CST(w); COMMA(); CST((arith) i); NL() +C_bss_icon | arith:n char *:s arith:sz int:i | + PS(ps_bss); DCST(n); COMMA(); WCON(sp_icon, s, sz); COMMA(); CST((arith) i); NL() +C_bss_ucon | arith:n char *:s arith:sz int:i | + PS(ps_bss); DCST(n); COMMA(); WCON(sp_ucon, s, sz); COMMA(); CST((arith) i); NL() +C_bss_fcon | arith:n char *:s arith:sz int:i | + PS(ps_bss); DCST(n); COMMA(); WCON(sp_fcon, s, sz); COMMA(); CST((arith) i); NL() +C_bss_dnam | arith:n char *:s arith:offs int:i | + PS(ps_bss); DCST(n); COMMA(); NOFF(s, offs); COMMA(); CST((arith) i); NL() +C_bss_dlb | arith:n label:l arith:offs int:i | + PS(ps_bss); DCST(n); COMMA(); DOFF(l, offs); COMMA(); CST((arith) i); NL() +C_bss_ilb | arith:n label:l int:i | + PS(ps_bss); DCST(n); COMMA(); ILB(l); COMMA(); CST((arith) i); NL() +C_bss_pnam | arith:n char *:s int:i | + PS(ps_bss); DCST(n); COMMA(); PNAM(s); COMMA(); CST((arith) i); NL() + +C_hol_cst | arith:n arith:w int:i | + PS(ps_hol); DCST(n); COMMA(); CST(w); COMMA(); CST((arith) i); NL() +C_hol_icon | arith:n char *:s arith:sz int:i | + PS(ps_hol); DCST(n); COMMA(); WCON(sp_icon, s, sz); COMMA(); CST((arith) i); NL() +C_hol_ucon | arith:n char *:s arith:sz int:i | + PS(ps_hol); DCST(n); COMMA(); WCON(sp_ucon, s, sz); COMMA(); CST((arith) i); NL() +C_hol_fcon | arith:n char *:s arith:sz int:i | + PS(ps_hol); DCST(n); COMMA(); WCON(sp_fcon, s, sz); COMMA(); CST((arith) i); NL() +C_hol_dnam | arith:n char *:s arith:offs int:i | + PS(ps_hol); DCST(n); COMMA(); NOFF(s, offs); COMMA(); CST((arith) i); NL() +C_hol_dlb | arith:n label:l arith:offs int:i | + PS(ps_hol); DCST(n); COMMA(); DOFF(l, offs); COMMA(); CST((arith) i); NL() +C_hol_ilb | arith:n label:l int:i | + PS(ps_hol); DCST(n); COMMA(); ILB(l); COMMA(); CST((arith) i); NL() +C_hol_pnam | arith:n char *:s int:i | + PS(ps_hol); DCST(n); COMMA(); PNAM(s); COMMA(); CST((arith) i); NL() + +C_con_cst | arith:l | PS(ps_con); CST(l); CEND(); NL() +C_con_icon | char *:val arith:siz | + PS(ps_con); WCON(sp_icon, val, siz); CEND(); NL() +C_con_ucon | char *:val arith:siz | + PS(ps_con); WCON(sp_ucon, val, siz); CEND(); NL() +C_con_fcon | char *:val arith:siz | + PS(ps_con); WCON(sp_fcon, val, siz); CEND(); NL() +C_con_scon | char *:str arith:siz | + PS(ps_con); SCON(str, siz); CEND(); NL() +C_con_dnam | char *:str arith:val | + PS(ps_con); NOFF(str, val); CEND(); NL() +C_con_dlb | label:l arith:val | + PS(ps_con); DOFF(l, val); CEND(); NL() +C_con_ilb | label:l | PS(ps_con); ILB(l); CEND(); NL() +C_con_pnam | char *:str | PS(ps_con); PNAM(str); CEND(); NL() + +C_rom_cst | arith:l | PS(ps_rom); CST(l); CEND(); NL() +C_rom_icon | char *:val arith:siz | + PS(ps_rom); WCON(sp_icon, val, siz); CEND(); NL() +C_rom_ucon | char *:val arith:siz | + PS(ps_rom); WCON(sp_ucon, val, siz); CEND(); NL() +C_rom_fcon | char *:val arith:siz | + PS(ps_rom); WCON(sp_fcon, val, siz); CEND(); NL() +C_rom_scon | char *:str arith:siz | + PS(ps_rom); SCON(str, siz); CEND(); NL() +C_rom_dnam | char *:str arith:val | + PS(ps_rom); NOFF(str, val); CEND(); NL() +C_rom_dlb | label:l arith:val | + PS(ps_rom); DOFF(l, val); CEND(); NL() +C_rom_ilb | label:l | PS(ps_rom); ILB(l); CEND(); NL() +C_rom_pnam | char *:str | PS(ps_rom); PNAM(str); CEND(); NL() + +C_cst | arith:l | COMMA(); CST(l) +C_icon | char *:val arith:siz | COMMA(); WCON(sp_icon, val, siz) +C_ucon | char *:val arith:siz | COMMA(); WCON(sp_ucon, val, siz) +C_fcon | char *:val arith:siz | COMMA(); WCON(sp_fcon, val, siz) +C_scon | char *:str arith:siz | COMMA(); SCON(str, siz) +C_dnam | char *:str arith:val | COMMA(); NOFF(str, val) +C_dlb | label:l arith:val | COMMA(); DOFF(l, val) +C_ilb | label:l | COMMA(); ILB(l) +C_pnam | char *:str | COMMA(); PNAM(str) + +C_mes_begin | int:ms | PS(ps_mes); CST((arith)ms) +C_mes_end | | CEND(); NL() + +% Yes, there really is a C_exc routine... +C_exc | arith:c1 arith:c2 | PS(ps_exc); CST(c1); COMMA(); CST(c2); NL() diff --git a/modules/src/em_code/em_code.3X b/modules/src/em_code/em_code.3X new file mode 100644 index 00000000..9300f630 --- /dev/null +++ b/modules/src/em_code/em_code.3X @@ -0,0 +1,408 @@ +.TH EM_CODE 3ACK "86/04/02" +.SH NAME +emcode \- EM code interface for compilers +.SH SYNOPSIS +.nf +.B #include +.PP +.B int C_open(filename) +.B C_close() +.B int C_busy() +.B char *filename; +.PP +.B C_magic() +.PP +.B C_df_dlb(l) +.B C_df_dnam(s) +.B C_df_ilb(l) +.B label l; char *s; +.PP +.B C_pro(s, l) +.B C_pro_narg(s) +.B C_end(l) +.B C_end_narg() +.B char *s; arith l; +.PP +.B C_exa_dlb(l) +.B C_exa_dnam(s) +.B C_exp(s) +.B C_ina_dlb(l) +.B C_ina_dnam(s) +.B C_inp(s) +.B char *s; label l; +.PP +.BI C_bss_ cstp () +.BI C_hol_ cstp () +.BI C_con_ cstp () +.BI C_rom_ cstp () +.PP +.B #include +.B C_mes_begin(ms) +.BI C_ cstp () +.B C_mes_end() +.B int ms; +.PP +.B C_exc(c1, c2) +.B arith c1, c2; +.PP +.BI C_ mnem () +.BI C_ mnem _dlb() +.BI C_ mnem _dnam() +.BI C_ mnem _narg() +.fi +.SH DESCRIPTION +This package provides a procedural EM code interface to be used in +compilers and other EM code producing programs. +The basic idea behind this package is to simplify the program writer's task +of producing EM code in any form, either compact or human-readable +EM assembly code or a sequence of procedure calls. +.PP +The named types +.B arith +and +.B label +refer to types on the local +machine that are suitable for doing arithmetics and storing EM numeric labels +respectively. +Common definitions are +.B long +for +.B arith +and +.B +unsigned int +for +.BR label . +.PP +.BI C_open( filename ) +should be invoked as initialiser for +a sequence of calls that produce EM code on file +.IR filename . +When +.I filename +is a null pointer, the code is produced on standard output. +Some implementations, such as fast back ends, may ignore the parameter. +.B C_close +causes some internal buffers to be flushed and the output file to be closed. +All subsequent routines, except for +.BR C_busy , +must be invoked between the calls to +.B C_open +and +.BR C_close . +.PP +.B C_busy +can be invoked in order +to detect whether EM code is currently being generated, i.e. whether you are +in between calls to +.B C_open +and +.BR C_close . +If this is the case, +.B C_busy +returns a 1. +.PP +.B C_magic() +produces the EM magic word. +.PP +Two routines can be used to generate code for the definitions of global data +labels: +.BI C_df_dlb( l ) +for numeric labels +.BI . l +and +.BI C_df_dnam( s ) +for alphanumeric labels +.IR s . +.PP +.BI C_df_ilb( l ) +produces EM code for instruction label +.IR l . +.PP +The routines for producing the EM procedure delimiters are: +.PP +.RS +.TS +box; +l|l. +routine EM pattern += +\&\fBC_pro(\fP\fIs\fP\fB,\ \fP\fIl\fP\fB)\fP \fBpro\ \fP\fIs\fP\fB,\ \fP\fIl\fP +_ +\&\fBC_pro_narg(\fP\fIs\fP\fB)\fP \fBpro\ \fP\fIs\fP\fB,\ ?\fP +_ +\&\fBC_end(\fP\fIl\fP\fB)\fP \fBend\ \fP\fIl\fP +_ +\&\fBC_end_narg()\fP \fBend\ ?\fP +.TE +.RE +.PP +A set of routines, concerning the scope definition pseudo instructions, is: +.PP +.RS +.TS +box; +l|l. +routine EM pattern += +\&\fBC_exa_dnam(\fP\fIs\fP\fB)\fP \fBexa \fP\fIs\fP +_ +\&\fBC_exa_dlb(\fP\fIl\fP\fB)\fP \fBexa .\fP\fIl\fP +_ +\&\fBC_exp(\fP\fIs\fP\fB)\fP \fBexp $\fP\fIs\fP +_ +\&\fBC_ina_dnam(\fP\fIs\fP\fB)\fP \fBina \fP\fIs\fP +_ +\&\fBC_ina_dlb(\fP\fIl\fP\fB)\fP \fBina .\fP\fIl\fP +_ +\&\fBC_inp(\fP\fIs\fP\fB)\fP \fBinp $\fP\fIs\fP +.TE +.RE +.PP +In the set of +.B storage-declaration +pseudo instructions, we can +distinguish four groups, one for each type of storage declaration: +.BR con , +.BR rom , +.B bss +and +.BR hol . +.PP +The +.BR con / rom +instructions are generated by +.BI C_con_ cstp +and +.BI C_rom_ cstp , +respectively. +The type of the initialization value and the number and type of the parameters +are determined by +.I cstp +according to the following table: +.PP +.RS +.TS +box; +l|l|l|l +l|l|l|l +l|n|l|l. +\&\fIcstp\fP number of type of description + parameters parameters += +\&\fBcst\fP 1 \fBarith\fP word-sized integer of \fBarith\fP-type +_ +\&\fBicon\fP 2 \fBchar *\fP integer in string representation + \fBarith\fP number of bytes on target machine +_ +\&\fBucon\fP 2 \fBchar *\fP unsigned integer in string representation + \fBarith\fP number of bytes on target machine +_ +\&\fBfcon\fP 2 \fBchar *\fP floating in string representation + \fBarith\fP number of bytes on target machine +_ +\&\fBscon\fP 2 \fBchar *\fP row of bytes + \fBarith\fP length of the row of bytes +_ +\&\fBdnam\fP 2 \fBchar *\fP alphanumeric global data label + \fBarith\fP offset (possibly 0) +_ +\&\fBdlb\fP 2 \fBlabel\fP numeric global data label + \fBarith\fP offset (possibly 0) +_ +\&\fBilb\fP 1 \fBlabel\fP instruction label +_ +\&\fBpnam\fP 1 \fBchar *\fP procedure identifier +.TE +.RE +.PP +As an example of the use of the +.BR con / rom +routines, consider the +following +.B con +instruction: +.RS +con 23I4, "hello world", .12, table + 12, *33 +.RE +A sequence of calls to get this, is +.RS +.nf +C_con_icon("23", (arith)4); +C_con_scon("hello world"); +C_con_dlb((label)12, (arith)0); +C_con_dnam("table", (arith)12); +C_con_ilb((label)33); +.fi +.RE +.PP +A +.B bss +or +.B hol +instruction is produced by invoking +.BI C_bss_ cstp +or +.BI C_hol_ cstp +where +.I cstp +indicates the type of value that is used at initialisation. +The parameter list of +.BI C_bss_ cstp +and +.BI C_hol_ cstp +is similar to that of the corresponding +.BI C_con_ cstp, +except that it is preceeded by an +.BR arith -typed +operand +.I nbytes, +and followed by an +.BR int -typed +operand +.IR init ; +.I nbytes +indicates the number of bytes to reserve for the data; +.I init +has value 1 if the initialization is strictly necessary and 0 if not. +Note that, according to the EM definition, an initialisation type of +.B scon +is not allowed in the +.BR bss / hol +instruction. +.PP +Another set of routines is that of the EM +.B mes +pseudo instructions. +As there is an undefined number of messages and each type of message has +its own number of parameters and each parameter its own type, +the user is responsible for building his own message lists. +Such a list consists of a list of +.BI C_ cstp +routine calls enclosed +by +.BI C_mes_begin( ms ) +where +.I ms +is the message number, +and +.BR C_mes_end() . +.PP +.I C_exc +produces the EM +.B exc +.IR c1 , c2 +instruction. +The use of this function may cause trouble in some implementations of this +module. +A fast back end, for instance, may refuse to implement +.IR C_exc . +The use of this function is therefore not recommended. +.PP +The final class of routines is that of the EM machine-instruction generating +routines +.BI C_ mnem, +.BI C_ mnem _dlb , +.BI C_ mnem _dnam +and +.BI C_ mnem _narg . +The best way to describe them is according to section 11.3 of [EM]. +Depending on the class of the argument (as indicated by a letter), one +or more routines are available for each machine instruction. +The following table gives an overview of the available routines for +the EM machine instruction +.IR mnem : +.PP +.RS +.TS +box; +l|l|l|l +l|l|l|l +l|l|n|l. +class routine(s) number of type of + parameters parameter(s) += +[\fBcdflnorsz\fP] \fBC_\fP\fImnem\fP 1 \fBarith\fP +_ +\&\fBw\fP \fBC_\fP\fImnem\fP 1 \fBarith\fP + \fBC_\fP\fImnem\fP\fB_narg\fP 0 +_ +\&\fBg\fP \fBC_\fP\fImnem\fP 1 \fBarith\fP + \fBC_\fP\fImnem\fP\fB_dnam\fP 2 \fBchar *\fP + \fBarith\fP + \fBC_\fP\fImnem\fP\fB_dlb\fP 2 \fBlabel\fP + \fBarith\fP +_ +\&\fBp\fP \fBC_\fP\fImnem\fP 1 \fBchar *\fP +_ +\&\fBb\fP \fBC_\fP\fImnem\fP 1 \fBlabel\fP +_ +\&\fB\-\fP \fBC_\fP\fImnem\fP 0 +.TE +.RE +.PP +The available routines for, for example, the EM machine instruction +.B adi +(with argument class +.BR w ) +are +.BI C_adi( w ) +for +.B adi +with a given argument, and +.B C_adi_narg() +for +.B adi +with an argument on top of the stack. +Likewise are the available routines for +.BR loe +(which instruction has argument class +.BR g ): +.BI C_loe( g ) +where +.I g +is a constant, +.BI C_loe_dnam( g , o ) +where +.I g +is an alphanumeric label, and +.BI C_loe_dlb( g , o ) +where +.I g +is a numeric label. +The latter two routines have the (possibly zero) offset +.I o +as second parameter. +.SH FILES +.nf +~em/modules/h/em.h +~em/modules/lib/libemk.a: library for generating compact EM code +~em/modules/lib/libeme.a: library for generating human-readable EM code +.fi +.SH MODULES +.nf +libemk.a: system(3L), string(3L) +libeme.a: print(3L), system(3L), string(3L) +.fi +.SH SEE ALSO +read_em(3L), em_mes(3L) +.SH REFERENCES +.IP [EM] 6 +Andrew S. Tanenbaum, Hans van Staveren, Ed G. Keizer, Johan W. Stevenson, +.B +"Description of a Machine Architecture for use with Block Structured Languages", +Informatica Rapport IR-81, Vrije Universiteit, Amsterdam, 1983. +.LP +.SH DIAGNOSTICS +.I C_open +returns 1 if the open is successful and 0 if not. +The other routines do not give any information about their completion. +.SH BUGS +.IP \(bu +Feel free to report them to the author. +.IP \(bu +It is not possible to indicate that the argument of +.B C_con_cst () +must be seen as an unsigned value. +.SH AUTHOR +Erik Baalbergen diff --git a/modules/src/em_code/make.em.gen b/modules/src/em_code/make.em.gen new file mode 100755 index 00000000..e46e16d3 --- /dev/null +++ b/modules/src/em_code/make.em.gen @@ -0,0 +1,17 @@ +echo '% this part is generated from ../../../etc/em_table at: ' `date` +ed - ../../../etc/em_table <<'EOI' +1,/^$/d +1,/^$/d +1,$s/^\(...\) \(.\).*/\1:\2/ +g/:d/s/^\(...\):\(.\).*/C_\1 | arith:\2 | OP(op_\1); DCST(\2); NL()/ +g/:[cslnfzor]/s/^\(...\):\(.\).*/C_\1 | arith:\2 | OP(op_\1); CST(\2); NL()/ +g/:w/s/^\(...\).*/C_\1 | arith:w | OP(op_\1); CST(w); NL()\ +C_\1_narg | | OP(op_\1); CCEND(); NL()/ +g/:g/s/^\(...\).*/C_\1 | arith:g | OP(op_\1); CST(g); NL()\ +C_\1_dnam | char *:g arith:o | OP(op_\1); NOFF(g,o); NL()\ +C_\1_dlb | label:g arith:o | OP(op_\1); DOFF(g,o); NL()/ +g/:p/s/^\(...\).*/C_\1 | char *:p | OP(op_\1); PNAM(p); NL()/ +g/:b/s/^\(...\).*/C_\1 | label:b | OP(op_\1); CILB(b); NL()/ +g/:-/s/^\(...\).*/C_\1 | | OP(op_\1); NL()/ +1,$p +EOI diff --git a/modules/src/em_code/make.fun b/modules/src/em_code/make.fun new file mode 100755 index 00000000..1a69660b --- /dev/null +++ b/modules/src/em_code/make.fun @@ -0,0 +1,51 @@ +TMP=tmp$$ +cat $* >$TMP +ed - $TMP <<'--EOI--' +g/^%/d +g/^$/d +g/^ /.-1,.j +1,$s/[ ]*|[ ]*/|/g +g/NOTIMPLEMENTED/d +1,$s/\([^|]*\)|\([^|]*\)|\(.*\)$/\ +NAME \1\ +HEAD \1\ +PLST \2\ +DECL \2\ +BODY \3/ +$a +END +. +g/^NAME/m$ +g/^PLST/s/[ ][ ]*\([^:]*\):\([^ ]*\)/,\2/g +g/^PLST,/s//PLST / +g/^PLST /s/^PLST \(.*\)$/(\1)/ +g/^HEAD/.,.+1j +g/^HEAD /s/^HEAD \([^(]*\)\(.*\)$/cat >\1.c <<'--EOF--'\ +#include "em_private.h"\ +\ +\1\2/ +g/^DECL/s/[ ][ ]*\([^:]*\):\([^ ]*\)/\ + \1 \2;/g +g/^DECL/d +g/^BODY/s/^BODY \(.*\)$/{\ + \1;\ +}\ +--EOF--/ +1,/^END/-1p +1,/^END/d +g:^NAME:s:^NAME \(.*\)$:cc -c -O -I$1 -I../../h -I../../../h \1.c: +1i +cat >make.sh <<'--EOF--' +: script for making lib +rm -f *.o +. +$a +cc -c -O -I$1 -I../../h -I../../../h $1/em.c +mv em.o em$1.o +rm -f libem$1.a +ar rc libem$1.a *.o +--EOF-- +. +1,$p +--EOI-- +rm -f $TMP From 6942ec9a85611e1eb2965abea0c5fe36465420d8 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 6 Jan 1987 13:46:48 +0000 Subject: [PATCH 0424/1625] removed the Xmalloc entry --- modules/src/Action | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/modules/src/Action b/modules/src/Action index d30d0b02..cf5d774e 100644 --- a/modules/src/Action +++ b/modules/src/Action @@ -13,10 +13,7 @@ end name "memory allocation module" dir alloc end -name "fast, wasting malloc" -dir Xmalloc -end -name "fast, memory efficient malloc" +name "fast, linear time malloc" dir malloc end name "EM messages generation module" From 17598fae791a75c3006b33ade47f84ff4b7b7781 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 6 Jan 1987 14:04:26 +0000 Subject: [PATCH 0425/1625] Initial revision --- modules/src/alloc/Makefile | 44 +++++++++++++++++++++++++++++++++ modules/src/assert/Makefile | 31 +++++++++++++++++++++++ modules/src/em_mes/Makefile | 33 +++++++++++++++++++++++++ modules/src/input/Makefile | 35 ++++++++++++++++++++++++++ modules/src/print/Makefile | 37 ++++++++++++++++++++++++++++ modules/src/system/Makefile | 49 +++++++++++++++++++++++++++++++++++++ 6 files changed, 229 insertions(+) create mode 100644 modules/src/alloc/Makefile create mode 100644 modules/src/assert/Makefile create mode 100644 modules/src/em_mes/Makefile create mode 100644 modules/src/input/Makefile create mode 100644 modules/src/print/Makefile create mode 100644 modules/src/system/Makefile diff --git a/modules/src/alloc/Makefile b/modules/src/alloc/Makefile new file mode 100644 index 00000000..a5371920 --- /dev/null +++ b/modules/src/alloc/Makefile @@ -0,0 +1,44 @@ +EMHOME=../../.. +HDIR = $(EMHOME)/modules/h +INSTALL=$(EMHOME)/modules/install +COMPARE=$(EMHOME)/modules/compare + +CFLAGS = -O -I. -I$(HDIR) + +SOURCES = alloc.h\ + Malloc.c\ + botch.c\ + clear.c\ + st_alloc.c\ + std_alloc.c + +OBJECTS = botch.o clear.o st_alloc.o Malloc.o std_alloc.o + +all: liballoc.a + +liballoc.a: all + ar cr liballoc.a $(OBJECTS) + -sh -c 'ranlib liballoc.a' + +install: all + $(INSTALL) lib/liballoc.a + $(INSTALL) man/alloc.3 + $(INSTALL) h/alloc.h + +cmp: liballoc.a + $(COMPARE) lib/liballoc.a + $(COMPARE) man/alloc.3 + $(COMPARE) h/alloc.h + +pr: + @pr Makefile $(SOURCES) + +opr: + make pr | opr + +clean: + rm -f *.[oa] + +st_alloc.o: alloc.h +std_alloc.o: alloc.h +Malloc.o: alloc.h diff --git a/modules/src/assert/Makefile b/modules/src/assert/Makefile new file mode 100644 index 00000000..cc5b6cc8 --- /dev/null +++ b/modules/src/assert/Makefile @@ -0,0 +1,31 @@ +EMHOME=../../.. +MODULES=$(EMHOME)/modules +HDIR = $(MODULES)/h +CFLAGS = -I$(HDIR) -O +INSTALL = $(MODULES)/install +COMPARE = $(MODULES)/compare + +all: libassert.a + +libassert.a: BadAssertion.o + ar r libassert.a BadAssertion.o + -sh -c 'ranlib libassert.a' + +install: all + $(INSTALL) lib/libassert.a + $(INSTALL) man/assert.3 + $(INSTALL) h/assert.h + +cmp: all + $(COMPARE) lib/libassert.a + $(COMPARE) man/assert.3 + $(COMPARE) h/assert.h + +pr: + @pr Makefile assert.h BadAssertion.c + +opr: + make pr | opr + +clean: + rm -f *.[oa] diff --git a/modules/src/em_mes/Makefile b/modules/src/em_mes/Makefile new file mode 100644 index 00000000..23945ff1 --- /dev/null +++ b/modules/src/em_mes/Makefile @@ -0,0 +1,33 @@ +EMHOME = ../../.. +HDIR = $(EMHOME)/modules/h +INSTALL = $(EMHOME)/modules/install +COMPARE = $(EMHOME)/modules/compare +SRC = C_ms_err.c C_ms_opt.c C_ms_emx.c C_ms_reg.c C_ms_src.c\ + C_ms_flt.c C_ms_com.c C_ms_par.c C_ms_ego.c C_ms_gto.c +OBJ = C_ms_err.o C_ms_opt.o C_ms_emx.o C_ms_reg.o C_ms_src.o\ + C_ms_flt.o C_ms_com.o C_ms_par.o C_ms_ego.o C_ms_gto.o +CFLAGS=-I$(EMHOME)/h -I$(HDIR) -O + +all: libem_mes.a + +libem_mes.a: $(OBJ) + rm -f libem_mes.a + ar cr libem_mes.a $(OBJ) + -sh -c 'ranlib libem_mes.a' + +install: all + $(INSTALL) lib/libem_mes.a + $(INSTALL) man/em_mes.3 + +cmp: all + $(COMPARE) lib/libem_mes.a + $(COMPARE) man/em_mes.3 + +pr: + @pr Makefile $(SRC) + +opr: + make pr | opr + +clean: + rm -f *.[oa] diff --git a/modules/src/input/Makefile b/modules/src/input/Makefile new file mode 100644 index 00000000..bc97a719 --- /dev/null +++ b/modules/src/input/Makefile @@ -0,0 +1,35 @@ +EMHOME = ../../.. +MODULES = $(EMHOME)/modules +INSTALL = $(MODULES)/install +COMPARE = $(MODULES)/compare +CFLAGS = -O + +OBJECTS = AtEoIF.o\ + AtEoIT.o + +all: libinput.a + +libinput.a: $(OBJECTS) + ar cr libinput.a $(OBJECTS) + -sh -c 'ranlib libinput.a' + +install: all + $(INSTALL) lib/libinput.a + $(INSTALL) man/input.3 + $(INSTALL) pkg/inp_pkg.body + $(INSTALL) pkg/inp_pkg.spec + +cmp: all + $(COMPARE) lib/libinput.a + $(COMPARE) man/input.3 + $(COMPARE) pkg/inp_pkg.body + $(COMPARE) pkg/inp_pkg.spec + +pr: + @pr Makefile inp_pkg.spec inp_pkg.body AtEoIF.c AtEoIT.c + +opr: + make pr | opr + +clean: + rm -f *.[oa] diff --git a/modules/src/print/Makefile b/modules/src/print/Makefile new file mode 100644 index 00000000..c31d46f8 --- /dev/null +++ b/modules/src/print/Makefile @@ -0,0 +1,37 @@ +EMHOME = ../../.. +LIBPRINT = libprint.a +MODDIR=$(EMHOME)/modules +INSTALL = $(MODDIR)/install +COMPARE = $(MODDIR)/compare +CFLAGS = -c -O -I$(MODDIR)/h +SRC = doprnt.c fprint.c print.c sprint.c format.c +OBJ = doprnt.o fprint.o print.o sprint.o format.o + +all: $(LIBPRINT) + +$(LIBPRINT): $(OBJ) + rm -f $(LIBPRINT) + ar r $(LIBPRINT) $(OBJ) + -sh -c 'ranlib $(LIBPRINT)' + +install: all + $(INSTALL) lib/$(LIBPRINT) + $(INSTALL) man/print.3 + +cmp: all + $(COMPARE) lib/$(LIBPRINT) + $(COMPARE) man/print.3 + +pr: + @pr Makefile $(SRC) + +opr: + make pr | opr + +clean: + rm -f *.o $(LIBPRINT) + +doprnt.o: param.h +fprint.o: param.h +print.o: param.h +sprint.o: param.h diff --git a/modules/src/system/Makefile b/modules/src/system/Makefile new file mode 100644 index 00000000..9c3fcab2 --- /dev/null +++ b/modules/src/system/Makefile @@ -0,0 +1,49 @@ +EMHOME = ../../.. +MODULES = $(EMHOME)/modules +INSTALL = $(MODULES)/install +COMPARE = $(MODULES)/compare +LIBSYS = libsystem.a +CFLAGS = -I. -O +OBJ = access.o break.o chmode.o close.o create.o exit.o filesize.o \ + modtime.o lock.o open.o read.o remove.o stop.o \ + system.o time.o unlock.o write.o +CSRC = access.c break.c chmode.c close.c create.c exit.c filesize.c \ + modtime.c lock.c open.c read.c remove.c stop.c \ + system.c time.c unlock.c write.c +SRC = Makefile system.h $(CSRC) + +all: $(LIBSYS) + +$(LIBSYS): $(OBJ) + rm -f $(LIBSYS) + ar r $(LIBSYS) $(OBJ) + -sh -c 'ranlib $(LIBSYS)' + +install: all + $(INSTALL) lib/$(LIBSYS) + $(INSTALL) man/system.3 + $(INSTALL) h/system.h + +cmp: all + $(COMPARE) lib/$(LIBSYS) + $(COMPARE) man/system.3 + $(COMPARE) h/system.h + +clean: + rm -f *.[oa] + +pr: + @pr $(SRC) + +opr: + make pr | opr + +access.o: system.h +break.o: system.h +close.o: system.h +create.o: system.h +open.o: system.h +read.o: system.h +stop.o: system.h +system.o: system.h +write.o: system.h From 846e79a2b00b75b966116fd72ffc2024b1d34f37 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 6 Jan 1987 15:16:53 +0000 Subject: [PATCH 0426/1625] Initial revision --- util/cpp/LLlex.c | 372 +++++++++++++++++++++++ util/cpp/LLlex.h | 37 +++ util/cpp/LLmessage.c | 19 ++ util/cpp/Makefile | 164 ++++++++++ util/cpp/Parameters | 71 +++++ util/cpp/bits.h | 13 + util/cpp/ch7bin.c | 74 +++++ util/cpp/ch7mon.c | 19 ++ util/cpp/char.tab | 36 +++ util/cpp/chtab.c | 316 +++++++++++++++++++ util/cpp/class.h | 41 +++ util/cpp/domacro.c | 693 ++++++++++++++++++++++++++++++++++++++++++ util/cpp/error.c | 59 ++++ util/cpp/expr.c | 53 ++++ util/cpp/expression.g | 124 ++++++++ util/cpp/file_info.h | 13 + util/cpp/idf.c | 2 + util/cpp/idf.h | 11 + util/cpp/init.c | 72 +++++ util/cpp/input.c | 47 +++ util/cpp/input.h | 2 + util/cpp/interface.h | 3 + util/cpp/macro.h | 52 ++++ util/cpp/main.c | 65 ++++ util/cpp/make.hfiles | 35 +++ util/cpp/make.tokcase | 34 +++ util/cpp/make.tokfile | 6 + util/cpp/next.c | 5 + util/cpp/options.c | 119 ++++++++ util/cpp/preprocess.c | 209 +++++++++++++ util/cpp/replace.c | 196 ++++++++++++ util/cpp/scan.c | 224 ++++++++++++++ util/cpp/skip.c | 64 ++++ util/cpp/tokenname.c | 51 ++++ 34 files changed, 3301 insertions(+) create mode 100644 util/cpp/LLlex.c create mode 100644 util/cpp/LLlex.h create mode 100644 util/cpp/LLmessage.c create mode 100644 util/cpp/Makefile create mode 100644 util/cpp/Parameters create mode 100644 util/cpp/bits.h create mode 100644 util/cpp/ch7bin.c create mode 100644 util/cpp/ch7mon.c create mode 100644 util/cpp/char.tab create mode 100644 util/cpp/chtab.c create mode 100644 util/cpp/class.h create mode 100644 util/cpp/domacro.c create mode 100644 util/cpp/error.c create mode 100644 util/cpp/expr.c create mode 100644 util/cpp/expression.g create mode 100644 util/cpp/file_info.h create mode 100644 util/cpp/idf.c create mode 100644 util/cpp/idf.h create mode 100644 util/cpp/init.c create mode 100644 util/cpp/input.c create mode 100644 util/cpp/input.h create mode 100644 util/cpp/interface.h create mode 100644 util/cpp/macro.h create mode 100644 util/cpp/main.c create mode 100755 util/cpp/make.hfiles create mode 100755 util/cpp/make.tokcase create mode 100755 util/cpp/make.tokfile create mode 100644 util/cpp/next.c create mode 100644 util/cpp/options.c create mode 100644 util/cpp/preprocess.c create mode 100644 util/cpp/replace.c create mode 100644 util/cpp/scan.c create mode 100644 util/cpp/skip.c create mode 100644 util/cpp/tokenname.c diff --git a/util/cpp/LLlex.c b/util/cpp/LLlex.c new file mode 100644 index 00000000..744fd728 --- /dev/null +++ b/util/cpp/LLlex.c @@ -0,0 +1,372 @@ +/* $Header$ */ +/* L E X I C A L A N A L Y Z E R */ + +#include "idfsize.h" +#include "numsize.h" +#include "strsize.h" + +#include +#include "input.h" +#include "idf.h" +#include "LLlex.h" +#include "Lpars.h" +#include "class.h" +#include "bits.h" + +/* Data about the token yielded */ +struct token dot; + +int ReplaceMacros = 1; /* replacing macros */ +int AccFileSpecifier = 0; /* return filespecifier <...> */ +int AccDefined = 0; /* accept "defined(...)" */ +int UnknownIdIsZero = 0; /* interpret unknown id as integer 0 */ + +char *string_token(); + +PushLex() +{ + DOT = 0; +} + +PopLex() +{} + +int +LLlex() +{ + return (DOT != EOF) ? GetToken(&dot) : EOF; +} + +#define BUFSIZ 1024 + +int +GetToken(ptok) + register struct token *ptok; +{ + char buf[BUFSIZ]; + register int c, nch; + +again: /* rescan the input after an error or replacement */ + LoadChar(c); +go_on: + if ((c & 0200) && c != EOI) + fatal("non-ascii '\\%03o' read", c & 0377); + switch (class(c)) { /* detect character class */ + case STNL: + LineNumber++; + return ptok->tk_symb = EOF; + case STSKIP: + goto again; + case STGARB: /* garbage character */ + if (c == '\\') { + /* a '\\' is allowed in #if/#elif expression */ + LoadChar(c); + if (class(c) == STNL) { /* vt , ff ? */ + ++LineNumber; + goto again; + } + PushBack(); + c = '\\'; + } + if (040 < c && c < 0177) + error("garbage char %c", c); + else + error("garbage char \\%03o", c); + goto again; + case STSIMP: /* a simple character, no part of compound token*/ + if (c == '/') { /* probably the start of comment */ + LoadChar(c); + if (c == '*') { /* start of comment */ + skipcomment(); + goto again; + } + else { + PushBack(); + c = '/'; /* restore c */ + } + } + return ptok->tk_symb = c; + case STCOMP: /* maybe the start of a compound token */ + LoadChar(nch); /* character lookahead */ + switch (c) { + case '!': + if (nch == '=') + return ptok->tk_symb = NOTEQUAL; + PushBack(); + return ptok->tk_symb = c; + case '&': + if (nch == '&') + return ptok->tk_symb = AND; + PushBack(); + return ptok->tk_symb = c; + case '<': + if (AccFileSpecifier) { + PushBack(); /* pushback nch */ + ptok->tk_str = + string_token("file specifier", '>'); + return ptok->tk_symb = FILESPECIFIER; + } + if (nch == '<') + return ptok->tk_symb = LEFT; + if (nch == '=') + return ptok->tk_symb = LESSEQ; + PushBack(); + return ptok->tk_symb = c; + case '=': + if (nch == '=') + return ptok->tk_symb = EQUAL; + /* The following piece of code tries to recognise + old-fashioned assignment operators `=op' + */ + error("illegal character"); + goto go_on; + case '>': + if (nch == '=') + return ptok->tk_symb = GREATEREQ; + if (nch == '>') + return ptok->tk_symb = RIGHT; + PushBack(); + return ptok->tk_symb = c; + case '|': + if (nch == '|') + return ptok->tk_symb = OR; + PushBack(); + return ptok->tk_symb = c; + } + case STIDF: + { + extern int idfsize; /* ??? */ + register char *tg = &buf[0]; + register char *maxpos = &buf[idfsize]; + register struct idf *idef; + +#define tstmac(bx) if (!(bits[c] & bx)) goto nomac +#define cpy if (Unstacked) EnableMacros(); *tg++ = c +#define load LoadChar(c); if (!in_idf(c)) goto endidf + +#ifdef DOBITS + cpy; tstmac(bit0); load; + cpy; tstmac(bit1); load; + cpy; tstmac(bit2); load; + cpy; tstmac(bit3); load; + cpy; tstmac(bit4); load; + cpy; tstmac(bit5); load; + cpy; tstmac(bit6); load; + cpy; tstmac(bit7); load; +#endif + + for(;;) { + if (tg < maxpos) { + cpy; + } + load; + } + endidf: + PushBack(); + *tg = '\0'; /* mark the end of the identifier */ + if (ReplaceMacros) { + idef = findidf(buf); + if ((idef && idef->id_macro && replace(idef))) { + goto again; + } + } + nomac: + LoadChar(c); + while (in_idf(c)) { + if (tg < maxpos) *tg++ = c; + LoadChar(c); + } + PushBack(); + *tg++ = '\0'; /* mark the end of the identifier */ + if (UnknownIdIsZero) { + ptok->tk_val = 0; + return ptok->tk_symb = INTEGER; + } + ptok->tk_str = Malloc(idfsize + 1); + strcpy(ptok->tk_str, buf); + return ptok->tk_symb = IDENTIFIER; + } + case STCHAR: /* character constant */ + { + register int val = 0, size = 0; + + LoadChar(c); + if (c == '\'') + error("character constant too short"); + else + while (c != '\'') { + if (c == '\n') { + error("newline in character constant"); + LineNumber++; + break; + } + if (c == '\\') { + LoadChar(c); + if (c == '\n') { + LoadChar(c); + LineNumber++; + continue; + } + c = quoted(c); + } + val = val*256 + c; + size++; + LoadChar(c); + } + if (size > sizeof(int)) + error("character constant too long"); + ptok->tk_val = val; + return ptok->tk_symb = INTEGER; + } + case STNUM: + { + register char *np = &buf[1]; + register int base = 10; + register int vch; + register int val = 0; + + if (c == '0') { + *np++ = c; + LoadChar(c); + if (c == 'x' || c == 'X') { + base = 16; + LoadChar(c); + } + else + base = 8; + } + while (vch = val_in_base(c, base), vch >= 0) { + val = val*base + vch; + if (np < &buf[NUMSIZE]) + *np++ = c; + LoadChar(c); + } + if (c == 'l' || c == 'L') + LoadChar(c); + PushBack(); + ptok->tk_val = val; + return ptok->tk_symb = INTEGER; + } + case STSTR: + ptok->tk_str = string_token("string", '"'); + return ptok->tk_symb = STRING; + case STEOI: /* end of text on source file */ + return ptok->tk_symb = EOF; + default: + crash("Impossible character class"); + } + /*NOTREACHED*/ +} + +skipcomment() +{ + register int c; + + NoUnstack++; + LoadChar(c); + do { + while (c != '*') { + if (class(c) == STNL) + ++LineNumber; + else + if (c == EOI) { + NoUnstack--; + return; + } + LoadChar(c); + } + /* Last Character seen was '*' */ + LoadChar(c); + } while (c != '/'); + NoUnstack--; +} + +char * +string_token(nm, stop_char) + char *nm; +{ + register int c; + register int str_size; + register char *str = Malloc(str_size = ISTRSIZE); + register int pos = 0; + + LoadChar(c); + while (c != stop_char) { + if (c == '\n') { + error("newline in %s", nm); + LineNumber++; + break; + } + if (c == EOI) { + error("end-of-file inside %s", nm); + break; + } + if (c == '\\') { + LoadChar(c); + if (c == '\n') { + LineNumber++; + LoadChar(c); + continue; + } + c = quoted(c); + } + str[pos++] = c; + if (pos == str_size) + str = Srealloc(str, str_size += RSTRSIZE); + LoadChar(c); + } + str[pos++] = '\0'; /* for filenames etc. */ + return str; +} + +int +quoted(c) + register int c; +{ + /* quoted() replaces an escaped character sequence by the + character meant. + */ + /* first char after backslash already in c */ + if (!is_oct(c)) { /* a quoted char */ + switch (c) { + 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; + } + } + else { /* a quoted octal */ + register int oct = 0, cnt = 0; + + do { + oct = oct*8 + (c-'0'); + LoadChar(c); + } while (is_oct(c) && ++cnt < 3); + PushBack(); + c = oct; + } + return c&0377; +} + +/* provisional */ +int +val_in_base(c, base) + register int c; +{ + return + is_dig(c) ? c - '0' : + base != 16 ? -1 : + is_hex(c) ? (c - 'a' + 10) & 017 : + -1; +} diff --git a/util/cpp/LLlex.h b/util/cpp/LLlex.h new file mode 100644 index 00000000..f85444ae --- /dev/null +++ b/util/cpp/LLlex.h @@ -0,0 +1,37 @@ +/* D E F I N I T I O N S F O R T H E L E X I C A L A N A L Y Z E R */ + +/* A token from the input stream is represented by an integer, + called a "symbol", but it may have other information associated + to it. +*/ + +/* the structure of a token: */ +struct token { + int tok_symb; /* the token itself */ + union { + int tok_val; /* numeric values */ + char *tok_str; /* string/filespecifier */ + } tok_data; +}; + +#include "file_info.h" + +#define tk_symb tok_symb +#define tk_val tok_data.tok_val +#define tk_str tok_data.tok_str + +extern struct token dot; + +extern int ReplaceMacros; /* "LLlex.c" */ +extern int AccFileSpecifier; /* "LLlex.c" */ +extern int AccDefined; /* "LLlex.c" */ +extern int UnknownIdIsZero; /* "LLlex.c" */ + +extern int NoUnstack; /* "input.c" */ +extern int Unstacked; /* "input.c" */ + +extern int err_occurred; /* "error.c" */ + +#define DOT dot.tk_symb + +#define EOF (-1) diff --git a/util/cpp/LLmessage.c b/util/cpp/LLmessage.c new file mode 100644 index 00000000..81b11333 --- /dev/null +++ b/util/cpp/LLmessage.c @@ -0,0 +1,19 @@ +/* PARSER ERROR ADMINISTRATION */ + +#include "LLlex.h" +#include "Lpars.h" + +extern char *symbol2str(); + +LLmessage(tk) { + err_occurred = 1; + if (tk < 0) + error("garbage at end of line"); + else if (tk) { + error("%s missing", symbol2str(tk)); + skipline(); + DOT = EOF; + } + else + error("%s deleted", symbol2str(DOT)); +} diff --git a/util/cpp/Makefile b/util/cpp/Makefile new file mode 100644 index 00000000..d02b1155 --- /dev/null +++ b/util/cpp/Makefile @@ -0,0 +1,164 @@ +# MAKEFILE FOR (STAND_ALONE) CEM PREPROCESSOR + +EMHOME=../.. +MODULES=$(EMHOME)/modules +MODULESLIB=$(MODULES)/lib +BIN=$(EMHOME)/lib + +# Some paths + +# Libraries +SYSLIB = $(MODULESLIB)/libsystem.a +STRLIB = $(MODULESLIB)/libstring.a +PRTLIB = $(MODULESLIB)/libprint.a +ALLOCLIB = $(MODULESLIB)/liballoc.a +ASSERTLIB = $(MODULESLIB)/libassert.a +MALLOC = $(MODULESLIB)/malloc.o +LIBS = $(PRTLIB) $(STRLIB) $(ALLOCLIB) $(MALLOC) $(ASSERTLIB) $(SYSLIB) +LIB_INCLUDES = -I$(MODULES)/h -I$(MODULES)/pkg + +# Where to install the preprocessor +CEMPP = $(BIN)/cpp + +# What C compiler to use and how +CC = cc +COPTIONS = +LFLAGS = -n + +# What parser generator to use and how +GEN = $(EMHOME)/bin/LLgen +GENOPTIONS = + +# Special #defines during compilation +CDEFS = $(LIB_INCLUDES) +CFLAGS = $(CDEFS) $(COPTIONS) -O# # we cannot pass the COPTIONS to lint! + +# Grammar files and their objects +LSRC = tokenfile.g expression.g +LCSRC = tokenfile.c expression.c Lpars.c +LOBJ = tokenfile.o expression.o Lpars.o + +# Objects of hand-written C files +CSRC = LLlex.c LLmessage.c ch7bin.c ch7mon.c domacro.c \ + error.c idf.c init.c input.c main.c options.c \ + preprocess.c replace.c scan.c skip.c tokenname.c next.c expr.c +COBJ = LLlex.o LLmessage.o ch7bin.o ch7mon.o domacro.o \ + error.o idf.o init.o input.o main.o options.o \ + preprocess.o replace.o scan.o skip.o tokenname.o next.o expr.o + +PRFILES = Makefile Parameters \ + make.hfiles make.tokcase make.tokfile LLlex.h bits.h file_info.h \ + idf.h input.h interface.h macro.h \ + class.h chtab.c char.tab expression.g $(CSRC) + +# Objects of other generated C files +GOBJ = char.o symbol2str.o + +# generated source files +GSRC = char.c symbol2str.c + +# .h files generated by `make hfiles'; PLEASE KEEP THIS UP-TO-DATE! +GHSRC = errout.h idfsize.h ifdepth.h lapbuf.h \ + maxincl.h nparams.h numsize.h obufsize.h \ + parbufsize.h pathlength.h strsize.h textsize.h \ + botch_free.h debug.h inputtype.h dobits.h + +# Other generated files, for 'make clean' only +GENERATED = tokenfile.g Lpars.h LLfiles LL.output lint.out \ + Xref hfiles cfiles charoffset.h + +all: cc + +cc: hfiles LLfiles + make "EMHOME="$(EMHOME) cpp + +hfiles: Parameters + ./make.hfiles Parameters + @touch hfiles + +LLfiles: $(LSRC) + $(GEN) $(GENOPTIONS) $(LSRC) + @touch LLfiles + +tokenfile.g: tokenname.c make.tokfile + tokenfile.g + +symbol2str.c: tokenname.c make.tokcase + symbol2str.c + +char.c: char.tab chtab + chtab -fchar.tab > char.c + +charoffset.h: chtab char.tab + chtab -fchar.tab > /dev/null + +chtab: chtab.o + $(CC) -o chtab chtab.o + +# Objects needed for 'cpp' +OBJ = $(COBJ) $(LOBJ) $(GOBJ) +SRC = $(CSRC) $(LCSRC) $(GSRC) + +cpp: $(OBJ) Makefile + $(CC) $(COPTIONS) $(LFLAGS) $(OBJ) $(LIBS) -o cpp + size cpp + +cfiles: hfiles LLfiles $(GSRC) + @touch cfiles + +install: all + cp cpp $(CEMPP) + +cmp: all + cmp cpp $(CEMPP) + +pr: + @pr $(PRFILES) + +opr: + make pr | opr + +tags: cfiles + ctags $(SRC) + +depend: cfiles + sed '/^#AUTOAUTO/,$$d' Makefile >Makefile.new + echo '#AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO' >>Makefile.new + $(EMHOME)/bin/mkdep $(SRC) | \ + sed 's/\.c:/.o:/' >>Makefile.new + mv Makefile Makefile.old + mv Makefile.new Makefile + +xref: + ctags -x `grep "\.[ch]" Files`|sed "s/).*/)/">Xref + +lint: cfiles + lint -bx $(CDEFS) $(SRC) >lint.out + +clean: + rm -f $(LCSRC) $(OBJ) $(GENERATED) $(GSRC) $(GHSRC) chtab.o chtab + +#AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO +LLlex.o: LLlex.h Lpars.h bits.h charoffset.h class.h dobits.h file_info.h idf.h idfsize.h input.h inputtype.h numsize.h strsize.h +LLmessage.o: LLlex.h Lpars.h file_info.h +ch7bin.o: Lpars.h +ch7mon.o: Lpars.h +domacro.o: LLlex.h Lpars.h bits.h botch_free.h charoffset.h class.h debug.h dobits.h file_info.h idf.h idfsize.h ifdepth.h input.h inputtype.h interface.h macro.h nparams.h parbufsize.h textsize.h +error.o: LLlex.h errout.h file_info.h +idf.o: idf.h +init.o: charoffset.h class.h idf.h interface.h macro.h +input.o: file_info.h input.h inputtype.h +main.o: file_info.h idfsize.h +options.o: charoffset.h class.h idf.h idfsize.h macro.h maxincl.h +preprocess.o: LLlex.h bits.h charoffset.h class.h dobits.h file_info.h idf.h idfsize.h input.h inputtype.h maxincl.h obufsize.h +replace.o: LLlex.h charoffset.h class.h debug.h file_info.h idf.h input.h inputtype.h interface.h macro.h pathlength.h textsize.h +scan.o: charoffset.h class.h idf.h input.h inputtype.h interface.h lapbuf.h macro.h nparams.h +skip.o: LLlex.h charoffset.h class.h file_info.h input.h inputtype.h +tokenname.o: LLlex.h Lpars.h file_info.h idf.h +next.o: debug.h +expr.o: Lpars.h +tokenfile.o: Lpars.h +expression.o: LLlex.h Lpars.h file_info.h +Lpars.o: Lpars.h +char.o: charoffset.h class.h +symbol2str.o: Lpars.h diff --git a/util/cpp/Parameters b/util/cpp/Parameters new file mode 100644 index 00000000..21bd8a66 --- /dev/null +++ b/util/cpp/Parameters @@ -0,0 +1,71 @@ +!File: pathlength.h +#define PATHLENGTH 1024 /* max. length of path to file */ + + +!File: errout.h +#define ERROUT STDERR /* file pointer for writing messages */ +#define MAXERR_LINE 5 /* maximum number of error messages given + on the same input line. */ + + +!File: idfsize.h +#define IDFSIZE 64 /* maximum significant length of an identifier */ + + +!File: numsize.h +#define NUMSIZE 256 /* maximum length of a numeric constant */ + + +!File: nparams.h +#define NPARAMS 32 /* maximum number of parameters of macros */ + + +!File: ifdepth.h +#define IFDEPTH 256 /* maximum number of nested if-constructions */ + + +!File: maxincl.h +#define MAXINCL 16 /* maximum number of #include directories */ + + +!File: lapbuf.h +#define LAPBUF 4096 /* size of macro actual parameter buffer */ + + +!File: strsize.h +#define ISTRSIZE 32 /* minimum number of bytes allocated for + storing a string */ +#define RSTRSIZE 8 /* step size in enlarging the memory for + the storage of a string */ + + +!File: botch_free.h +#undef BOTCH_FREE 1 /* botch freed memory, as a check */ + + +!File: debug.h +#undef DEBUG 1 /* perform various self-tests */ + + +!File: parbufsize.h +#define PARBUFSIZE 1024 + + +!File: textsize.h +#define ITEXTSIZE 32 /* 1st piece of memory for repl. text */ +#define RTEXTSIZE 32 /* stepsize for enlarging repl.text */ + + +!File: inputtype.h +#undef INP_READ_IN_ONE 1 /* read input file in one. */ + /* If defined, we cannot read from a pipe */ + + +!File: obufsize.h +#define OBUFSIZE 8192 /* output buffer size */ + + +!File: dobits.h +#define DOBITS 1 /* use trick to reduce symboltable accesses */ + + diff --git a/util/cpp/bits.h b/util/cpp/bits.h new file mode 100644 index 00000000..97195218 --- /dev/null +++ b/util/cpp/bits.h @@ -0,0 +1,13 @@ +#include "dobits.h" +#ifdef DOBITS +#define bit0 0x01 +#define bit1 0x02 +#define bit2 0x04 +#define bit3 0x08 +#define bit4 0x10 +#define bit5 0x20 +#define bit6 0x40 +#define bit7 0x80 + +extern char bits[]; +#endif diff --git a/util/cpp/ch7bin.c b/util/cpp/ch7bin.c new file mode 100644 index 00000000..120f8bec --- /dev/null +++ b/util/cpp/ch7bin.c @@ -0,0 +1,74 @@ +/* EVALUATION OF BINARY OPERATORS */ + +#include "Lpars.h" + +ch7bin(pval, oper, val) + register int *pval, val; + int oper; +{ + switch (oper) { + case '%': + if (val == 0) + error("% by 0"); + else + *pval = *pval % val; + break; + case '/': + if (val == 0) + error("/ by 0"); + else + *pval = *pval / val; + break; + case '*': + *pval = *pval * val; + break; + case '+': + *pval = *pval + val; + break; + case '-': + *pval = *pval - val; + break; + case LEFT: + *pval = *pval << val; + break; + case RIGHT: + *pval = *pval >> val; + break; + case '<': + *pval = (*pval < val); + break; + case '>': + *pval = (*pval > val); + break; + case LESSEQ: + *pval = (*pval <= val); + break; + case GREATEREQ: + *pval = (*pval >= val); + break; + case EQUAL: + *pval = (*pval == val); + break; + case NOTEQUAL: + *pval = (*pval != val); + break; + case '&': + *pval = *pval & val; + break; + case '^': + *pval = *pval ^ val; + break; + case '|': + *pval = *pval | val; + break; + case AND: + *pval = (*pval && val); + break; + case OR: + *pval = (*pval || val); + break; + case ',': + *pval = val; + break; + } +} diff --git a/util/cpp/ch7mon.c b/util/cpp/ch7mon.c new file mode 100644 index 00000000..5856dbab --- /dev/null +++ b/util/cpp/ch7mon.c @@ -0,0 +1,19 @@ +/* EVALUATION OF MONADIC OPERATORS */ + +#include "Lpars.h" + +ch7mon(oper, pval) + register int *pval; +{ + switch (oper) { + case '~': + *pval = ~(*pval); + break; + case '-': + *pval = -(*pval); + break; + case '!': + *pval = !(*pval); + break; + } +} diff --git a/util/cpp/char.tab b/util/cpp/char.tab new file mode 100644 index 00000000..d5e8d9a7 --- /dev/null +++ b/util/cpp/char.tab @@ -0,0 +1,36 @@ +% +% CHARACTER CLASSES +% +% some general settings: +%F %s, +% +% START OF TOKEN +% +%C +STGARB:\000-\377 +STSKIP:\r \t +STNL:\n\f\013 +STCOMP:!&<=>| +STSIMP:-%()+*,/:?^~ +STCHAR:' +STIDF:a-zA-Z_ +STNUM:0-9 +STSTR:" +STEOI:\200 +%T/* character classes */ +%T#include "class.h" +%Tchar tkclass[] = { +%p +%T}; +% +% other kinds of classes +% +%C +_D_|_H_|_I_|_O_:0-7 +_D_|_H_|_I_:89 +_H_|_I_:a-fA-F +_I_:g-zG-Z_ +%Tchar tk2class[] = { +%F %s, +%p +%T}; diff --git a/util/cpp/chtab.c b/util/cpp/chtab.c new file mode 100644 index 00000000..8b369f38 --- /dev/null +++ b/util/cpp/chtab.c @@ -0,0 +1,316 @@ +/* + chtab - character table generator + + Author: Erik Baalbergen (..tjalk!erikb) + Modified by Ceriel Jacobs +*/ + +#include + +static char *RcsId = "$Header$"; + +#define MAXBUF 256 +#define TABSIZE 257 +#define COMCOM '-' +#define FILECOM '%' + +int InputForm = 'c'; +char OutputForm[MAXBUF] = "%s,\n"; +char *Table[TABSIZE]; +char *Name; +char *ProgCall; +int signedch = 0; +char *OutputName; +char *chroffsetfile = "charoffset.h"; + +main(argc, argv) + char *argv[]; +{ + char c = 0200; + int i = c; + + if (i < 0) signedch = 1; + + ProgCall = *argv++; + argc--; + while (argc-- > 0) { + if (**argv == COMCOM) { + option(*argv++); + } + else { + process(*argv++, InputForm); + } + } + MkCharIndex(); +} + +MkCharIndex() +{ + FILE *fp; + + if ((fp = fopen(chroffsetfile, "w")) == NULL) { + fprintf(stderr, "%s: cannot write file %s\n", ProgCall, chroffsetfile); + exit(1); + } + if (signedch) { + fputs("#define CharOffset 128\n"); + } + else fputs("#define CharOffset 0\n"); + fclose(fp); +} + +char * +Salloc(s) + char *s; +{ + char *malloc(); + char *ns = malloc(strlen(s) + 1); + + if (ns) { + strcpy(ns, s); + } + return ns; +} + +option(str) + char *str; +{ + /* note that *str indicates the source of the option: + either COMCOM (from command line) or FILECOM (from a file). + */ + switch (*++str) { + + case ' ': /* command */ + case '\t': + case '\0': + break; + case 'I': + InputForm = *++str; + break; + case 'f': + if (*++str == '\0') { + fprintf(stderr, "%s: -f: name expected\n", ProgCall); + exit(1); + } + DoFile(str); + break; + case 'F': + sprintf(OutputForm, "%s\n", ++str); + break; + case 'T': + printf("%s\n", ++str); + break; + case 'p': + PrintTable(); + break; + case 'C': + ClearTable(); + break; + case 'H': + if (*++str == '\0') { + fprintf(stderr, "%s: -H: name expected\n", ProgCall); + } + else chroffsetfile = ++str; + break; + default: + fprintf(stderr, "%s: bad option -%s\n", ProgCall, str); + } +} + +ClearTable() +{ + register i; + + for (i = 0; i < TABSIZE; i++) { + Table[i] = 0; + } +} + +PrintTable() +{ + register i; + + for (i = 0; i < TABSIZE; i++) { + if (Table[i]) { + printf(OutputForm, Table[i]); + } + else { + printf(OutputForm, "0"); + } + } +} + +process(str, format) + char *str; +{ + char *cstr = str; + char *Name = cstr; /* overwrite original string! */ + + /* strip of the entry name + */ + while (*str && *str != ':') { + if (*str == '\\') { + ++str; + } + *cstr++ = *str++; + } + + if (*str != ':') { + fprintf(stderr, "%s: bad specification: \"%s\", ignored\n", + ProgCall, Name); + return 0; + } + *cstr = '\0'; + str++; + + switch (format) { + + case 'c': + return c_proc(str, Name); + default: + fprintf(stderr, "%s: bad input format\n", ProgCall); + } + return 0; +} + +c_proc(str, Name) + char *str; + char *Name; +{ + int ch, ch2; + int quoted(); + char *name = Salloc(Name); + + while (*str) { + if (*str == '\\') { + ch = quoted(&str); + } + else { + ch = *str++; + } + if (*str == '-') { + if (*++str == '\\') { + ch2 = quoted(&str); + } + else { + if (ch2 = *str++); + else str--; + } + if (ch > ch2) { + fprintf(stderr, "%s: bad range\n", ProgCall); + return 0; + } +#define ind(X) (signedch?(X>=128?X-128:X+128):X) + while (ch <= ch2) { + Table[ind(ch)] = name; + ch++; + } + } + else { + if (ch >= 0 && ch <= 255) + Table[ind(ch)] = name; + } + } + Table[256] = Table[0]; + return 1; +} + +int +quoted(pstr) + char **pstr; +{ + register int ch; + register int i; + register char *str = *pstr; + + if ((*++str >= '0') && (*str <= '9')) { + ch = 0; + for (i = 0; i < 3; i++) { + ch = 8 * ch + (*str - '0'); + if (*++str < '0' || *str > '9') + break; + } + } + else { + switch (*str++) { + + case 'n': + ch = '\n'; + break; + case 't': + ch = '\t'; + break; + case 'b': + ch = '\b'; + break; + case 'r': + ch = '\r'; + break; + case 'f': + ch = '\f'; + break; + default : + ch = *str; + } + } + *pstr = str; + return ch & 0377; +} + +int +stoi(str) + char *str; +{ + register i = 0; + + while (*str >= '0' && *str <= '9') { + i = i * 10 + *str++ - '0'; + } + return i; +} + +char * +getline(s, n, fp) + char *s; + FILE *fp; +{ + register c = getc(fp); + char *str = s; + + while (n--) { + if (c == EOF) { + return NULL; + } + else + if (c == '\n') { + *str++ = '\0'; + return s; + } + *str++ = c; + c = getc(fp); + } + s[n - 1] = '\0'; + return s; +} + +#define BUFSIZE 1024 + +DoFile(name) + char *name; +{ + char text[BUFSIZE]; + FILE *fp; + + if ((fp = fopen(name, "r")) == NULL) { + fprintf(stderr, "%s: cannot read file %s\n", ProgCall, name); + exit(1); + } + while (getline(text, BUFSIZE, fp) != NULL) { + if (text[0] == FILECOM) { + option(text); + } + else { + process(text, InputForm); + } + } +} diff --git a/util/cpp/class.h b/util/cpp/class.h new file mode 100644 index 00000000..3697fd57 --- /dev/null +++ b/util/cpp/class.h @@ -0,0 +1,41 @@ +/* U S E O F C H A R A C T E R C L A S S E S */ + +/* As a starter, chars are divided into classes, according to which + token they can be the start of. + At present such a class number is supposed to fit in 4 bits. +*/ + +#include "charoffset.h" + +#define class(ch) ((tkclass+CharOffset)[ch]) + +/* Being the start of a token is, fortunately, a mutual exclusive + property, so, as there are less than 16 classes they can be + packed in 4 bits. +*/ + +#define STSKIP 0 /* spaces and so on: skipped characters */ +#define STNL 1 /* newline character(s): update linenumber etc. */ +#define STGARB 2 /* garbage ascii character: not allowed */ +#define STSIMP 3 /* this character can occur as token */ +#define STCOMP 4 /* this one can start a compound token */ +#define STIDF 5 /* being the initial character of an identifier */ +#define STCHAR 6 /* the starter of a character constant */ +#define STSTR 7 /* the starter of a string */ +#define STNUM 8 /* the starter of a numeric constant */ +#define STEOI 9 /* End-Of-Information mark */ + +/* But occurring inside a token is not, so we need 1 bit for each + class. +*/ +#define _I_ 01 +#define _O_ 02 +#define _D_ 04 +#define _H_ 010 + +#define in_idf(ch) ((tk2class+CharOffset)[ch] & _I_) +#define is_oct(ch) ((tk2class+CharOffset)[ch] & _O_) +#define is_dig(ch) ((tk2class+CharOffset)[ch] & _D_) +#define is_hex(ch) ((tk2class+CharOffset)[ch] & _H_) + +extern char tkclass[], tk2class[]; diff --git a/util/cpp/domacro.c b/util/cpp/domacro.c new file mode 100644 index 00000000..2b908448 --- /dev/null +++ b/util/cpp/domacro.c @@ -0,0 +1,693 @@ +/* $Header$ */ +/* PREPROCESSOR: CONTROLLINE INTERPRETER */ + +#include "interface.h" +#include +#include "LLlex.h" +#include "Lpars.h" +#include "debug.h" +#include "idf.h" +#include "input.h" + +#include "ifdepth.h" +#include "botch_free.h" +#include "nparams.h" +#include "parbufsize.h" +#include "textsize.h" +#include "idfsize.h" +#include +#include +#include "class.h" +#include "macro.h" +#include "bits.h" + +IMPORT char *inctable[]; /* list of include directories */ +IMPORT char *getwdir(); +PRIVATE char ifstack[IFDEPTH]; /* if-stack: the content of an entry is */ + /* 1 if a corresponding ELSE has been */ + /* encountered. */ +PRIVATE int nestlevel = -1; /* initially no nesting level. */ + +PRIVATE char * +GetIdentifier() +{ + /* returns a pointer to the descriptor of the identifier that is + read from the input stream. A null-pointer is returned if + the input does not contain an identifier. + The substitution of macros is disabled. + */ + int tok; + struct token tk; + + ReplaceMacros = 0; + tok = GetToken(&tk); + ReplaceMacros = 1; + return tok == IDENTIFIER ? tk.tk_str : (char *)0; +} + +/* domacro() is the control line interpreter. The '#' has already + been read by the lexical analyzer by which domacro() is called. + The token appearing directly after the '#' is obtained by calling + the basic lexical analyzing function GetToken() and is interpreted + to perform the action belonging to that token. + An error message is produced when the token is not recognized, + i.e. it is not one of "define" .. "undef" , integer or newline. +*/ +EXPORT +domacro() +{ + struct token tk; /* the token itself */ + register struct idf *id; + + switch(GetToken(&tk)) { /* select control line action */ + case IDENTIFIER: /* is it a macro keyword? */ + id = findidf(tk.tk_str); + if (!id) { + error("%s: unknown control", tk.tk_str); + PushBack(); + skipline(); + free(tk.tk_str); + break; + } + free(tk.tk_str); + switch (id->id_resmac) { + case K_DEFINE: /* "define" */ + do_define(); + break; + case K_ELIF: /* "elif" */ + do_elif(); + break; + case K_ELSE: /* "else" */ + do_else(); + break; + case K_ENDIF: /* "endif" */ + do_endif(); + break; + case K_IF: /* "if" */ + do_if(); + break; + case K_IFDEF: /* "ifdef" */ + do_ifdef(1); + break; + case K_IFNDEF: /* "ifndef" */ + do_ifdef(0); + break; + case K_INCLUDE: /* "include" */ + do_include(); + break; + case K_LINE: /* "line" */ + /* set LineNumber and FileName according to + the arguments. + */ + if (GetToken(&tk) != INTEGER) { + error("#line without linenumber"); + PushBack(); + skipline(); + } + else + do_line((unsigned int)tk.tk_val); + break; + case K_UNDEF: /* "undef" */ + do_undef(); + break; + default: + /* invalid word seen after the '#' */ + error("%s: unknown control", id->id_text); + PushBack(); + skipline(); + } + break; + case INTEGER: /* # []? */ + do_line((unsigned int)tk.tk_val); + break; + case EOI: /* only `#' on this line: do nothing, ignore */ + break; + default: /* invalid token following '#' */ + error("illegal # line"); + PushBack(); + skipline(); + } +} + +PRIVATE +skip_block() +{ + /* skip_block() skips the input from + 1) a false #if, #ifdef, #ifndef or #elif until the + corresponding #elif (resulting in true), #else or + #endif is read. + 2) a #else corresponding to a true #if, #ifdef, + #ifndef or #elif until the corresponding #endif is + seen. + */ + register int ch; + register int skiplevel = nestlevel; /* current nesting level */ + struct token tk; + struct idf *id; + + NoUnstack++; + for (;;) { + LoadChar(ch); /* read first character after newline */ + if (ch != '#') { + if (ch == EOI) { + NoUnstack--; + return; + } + PushBack(); + skipline(); + continue; + } + if (GetToken(&tk) != IDENTIFIER) { + PushBack(); + skipline(); + continue; + } + /* an IDENTIFIER: look for #if, #ifdef and #ifndef + without interpreting them. + Interpret #else, #elif and #endif if they occur + on the same level. + */ + id = findidf(tk.tk_str); + free(tk.tk_str); + switch(id->id_resmac) { + case K_IF: + case K_IFDEF: + case K_IFNDEF: + push_if(); + continue; + case K_ELIF: + if (nestlevel == skiplevel) { + nestlevel--; + push_if(); + if (ifexpr()) { + NoUnstack--; + return; + } + } + break; + case K_ELSE: + ++(ifstack[nestlevel]); + if (nestlevel == skiplevel) { + PushBack(); + skipline(); + NoUnstack--; + return; + } + break; + case K_ENDIF: + assert(nestlevel >= 0); + if (nestlevel == skiplevel) { + PushBack(); + skipline(); + nestlevel--; + NoUnstack--; + return; + } + nestlevel--; + break; + } + } +} + +PRIVATE +ifexpr() +{ + /* ifexpr() returns whether the restricted constant + expression following #if or #elif evaluates to true. This + is done by calling the LLgen generated subparser for + constant expressions. The result of this expression will + be given in the extern long variable "ifval". + */ + IMPORT arith ifval; + int errors = err_occurred; + + ifval = (arith)0; + AccDefined = 1; + UnknownIdIsZero = 1; + PushLex(); /* NEW parser */ + If_expr(); /* invoke constant expression parser */ + PopLex(); /* OLD parser */ + AccDefined = 0; + UnknownIdIsZero = 0; + return (errors == err_occurred) && (ifval != (arith)0); +} + +PRIVATE +do_include() +{ + /* do_include() performs the inclusion of a file. + */ + char *filenm; + char *result; + int tok; + struct token tk; + + AccFileSpecifier = 1; + if (((tok = GetToken(&tk)) == FILESPECIFIER) || tok == STRING) + filenm = tk.tk_str; + else { + error("bad include syntax"); + filenm = (char *)0; + } + AccFileSpecifier = 0; + PushBack(); + skipline(); + inctable[0] = WorkingDir; + if (filenm) { + if (!InsertFile(filenm, &inctable[tok==FILESPECIFIER],&result)){ + error("cannot find include file \"%s\"", filenm); + } + else { + WorkingDir = getwdir(result); + FileName = result; + LineNumber = 1; + } + } +} + +PRIVATE +do_define() +{ + /* do_define() interprets a #define control line. + */ + char *str; + int nformals = -1; /* keep track of the number of formals */ + char *formals[NPARAMS]; /* pointers to the names of the formals */ + char parbuf[PARBUFSIZE]; /* names of formals */ + char *repl_text; /* start of the replacement text */ + int length; /* length of the replacement text */ + register ch; + char *get_text(); + + /* read the #defined macro's name */ + if (!(str = GetIdentifier())) { + error("#define: illegal macro name"); + PushBack(); + skipline(); + return; + } + /* there is a formal parameter list if the identifier is + followed immediately by a '('. + */ + LoadChar(ch); + if (ch == '(') { + if ((nformals = getparams(formals, parbuf)) == -1) { + PushBack(); + skipline(); + return; /* an error occurred */ + } + LoadChar(ch); + } + /* read the replacement text if there is any */ + ch = skipspaces(ch); /* find first character of the text */ + assert(ch != EOI); + if (class(ch) == STNL) { + /* Treat `#define something' as `#define something ""' + */ + repl_text = ""; + length = 0; + } + else { + PushBack(); + repl_text = get_text((nformals > 0) ? formals : 0, &length); + } + macro_def(str2idf(str, 0), repl_text, nformals, length, NOFLAG); + LineNumber++; +} + +PRIVATE +push_if() +{ + if (nestlevel >= IFDEPTH) + fatal("too many nested #if/#ifdef/#ifndef"); + else + ifstack[++nestlevel] = 0; +} + +PRIVATE +do_elif() +{ + if (nestlevel < 0 || (ifstack[nestlevel])) { + error("#elif without corresponding #if"); + PushBack(); + skipline(); + } + else { /* restart at this level as if a #if is detected. */ + nestlevel--; + push_if(); + skip_block(); + } +} + +PRIVATE +do_else() +{ + PushBack(); + skipline(); + if (nestlevel < 0 || (ifstack[nestlevel])) + error("#else without corresponding #if"); + else { /* mark this level as else-d */ + ++(ifstack[nestlevel]); + skip_block(); + } +} + +PRIVATE +do_endif() +{ + PushBack(); + skipline(); + if (nestlevel-- < 0) + error("#endif without corresponding #if"); +} + +PRIVATE +do_if() +{ + push_if(); + if (!ifexpr()) /* a false #if/#elif expression */ + skip_block(); +} + +PRIVATE +do_ifdef(how) +{ + register struct idf *id; + char *str; + + /* how == 1 : ifdef; how == 0 : ifndef + */ + push_if(); + str = GetIdentifier(); + if (!str) { + error("illegal #ifdef construction"); + id = 0; + } + else { + id = findidf(str); + free(str); + } + + /* The next test is a shorthand for: + (how && !id->id_macro) || (!how && id->id_macro) + */ + if (how ^ (id && id->id_macro != 0)) + skip_block(); + else { + PushBack(); + skipline(); + } +} + +PRIVATE +do_undef() +{ + register struct idf *id; + register char *str = GetIdentifier(); + + /* Forget a macro definition. */ + if (str) { + if (id = findidf(str)) { + if (id->id_macro) { /* forget the macro */ + free_macro(id->id_macro); + id->id_macro = (struct macro *) 0; + } /* else: don't complain */ + } + free(str); + } + else + error("illegal #undef construction"); + PushBack(); + skipline(); +} + +PRIVATE +do_line(l) + unsigned int l; +{ + struct token tk; + + LineNumber = l - 1; /* the number of the next input line */ + if (GetToken(&tk) == STRING) /* is there a filespecifier? */ + FileName = tk.tk_str; + PushBack(); + skipline(); +} + +PRIVATE int +getparams(buf, parbuf) + char *buf[]; + char parbuf[]; +{ + /* getparams() reads the formal parameter list of a macro + definition. + The number of parameters is returned. + As a formal parameter list is expected when calling this + routine, -1 is returned if an error is detected, for + example: + #define one(1), where 1 is not an identifier. + Note that the '(' has already been eaten. + The names of the formal parameters are stored into parbuf. + */ + register char **pbuf = &buf[0]; + register int c; + register char *ptr = &parbuf[0]; + register char **pbuf2; + + LoadChar(c); + c = skipspaces(c); + if (c == ')') { /* no parameters: #define name() */ + *pbuf = (char *) 0; + return 0; + } + for (;;) { /* eat the formal parameter list */ + if (class(c) != STIDF) { /* not an identifier */ + error("#define: bad formal parameter"); + return -1; + } + *pbuf = ptr; /* name of the formal */ + *ptr++ = c; + if (ptr >= &parbuf[PARBUFSIZE]) + fatal("formal parameter buffer overflow"); + do { /* eat the identifier name */ + LoadChar(c); + *ptr++ = c; + if (ptr >= &parbuf[PARBUFSIZE]) + fatal("formal parameter buffer overflow"); + } while (in_idf(c)); + *(ptr - 1) = '\0'; /* mark end of the name */ + + /* Check if this formal parameter is already used. + Usually, macros do not have many parameters, so ... + */ + for (pbuf2 = pbuf - 1; pbuf2 >= &buf[0]; pbuf2--) { + if (!strcmp(*pbuf2, *pbuf)) { + warning("formal parameter \"%s\" already used", + *pbuf); + } + } + + pbuf++; + c = skipspaces(c); + if (c == ')') { /* end of the formal parameter list */ + *pbuf = (char *) 0; + return pbuf - buf; + } + if (c != ',') { + error("#define: bad formal parameter list"); + return -1; + } + LoadChar(c); + c = skipspaces(c); + } + /*NOTREACHED*/ +} + +EXPORT +macro_def(id, text, nformals, length, flags) + register struct idf *id; + char *text; +{ + /* macro_def() puts the contents and information of a macro + definition into a structure and stores it into the symbol + table entry belonging to the name of the macro. + A warning is given if the definition overwrites another. + */ + register struct macro *newdef = id->id_macro; + + if (newdef) { /* is there a redefinition? */ + if (macroeq(newdef->mc_text, text)) + return; + warning("redefine \"%s\"", id->id_text); + } + else { +#ifdef DOBITS + register char *p = id->id_text; +#define setbit(bx) if (!*p) goto go_on; bits[*p++] |= (bx) + setbit(bit0); + setbit(bit1); + setbit(bit2); + setbit(bit3); + setbit(bit4); + setbit(bit5); + setbit(bit6); + setbit(bit7); + + go_on: +#endif + id->id_macro = newdef = new_macro(); + } + newdef->mc_text = text; /* replacement text */ + newdef->mc_nps = nformals; /* nr of formals */ + newdef->mc_length = length; /* length of repl. text */ + newdef->mc_flag = flags; /* special flags */ + newdef->mc_count = 0; +} + +PRIVATE int +find_name(nm, index) + char *nm, *index[]; +{ + /* find_name() returns the index of "nm" in the namelist + "index" if it can be found there. 0 is returned if it is + not there. + */ + register char **ip = &index[0]; + + while (*ip) + if (strcmp(nm, *ip++) == 0) + return ip - &index[0]; + /* arrived here, nm is not in the name list. */ + return 0; +} + +PRIVATE char * +get_text(formals, length) + char *formals[]; + int *length; +{ + /* get_text() copies the replacement text of a macro + definition with zero, one or more parameters, thereby + substituting each formal parameter by a special character + (non-ascii: 0200 & (order-number in the formal parameter + list)) in order to substitute this character later by the + actual parameter. The replacement text is copied into + itself because the copied text will contain fewer or the + same amount of characters. The length of the replacement + text is returned. + + Implementation: + finite automaton : we are only interested in + identifiers, because they might be replaced by some actual + parameter. Other tokens will not be seen as such. + */ + register int c; + register int text_size; + char *text = Malloc(text_size = ITEXTSIZE); + register int pos = 0; + + LoadChar(c); + + while ((c != EOI) && (class(c) != STNL)) { + if (c == '\\') { /* check for "\\\n" */ + LoadChar(c); + if (c == '\n') { + /* More than one line is used for the + replacement text. + Replace "\\\n" by " ". + */ + text[pos++] = ' '; + ++LineNumber; + LoadChar(c); + } + else + text[pos++] = '\\'; + if (pos == text_size) + text = Srealloc(text, text_size += RTEXTSIZE); + } + else + if ( c == '/') { + LoadChar(c); + if (c == '*') { + skipcomment(); + text[pos++] = ' '; + LoadChar(c); + } + else + text[pos++] = '/'; + if (pos == text_size) + text = Srealloc(text, text_size += RTEXTSIZE); + } + else + if (formals && class(c) == STIDF) { + char id_buf[IDFSIZE + 1]; + register id_size = 0; + register n; + + /* read identifier: it may be a formal parameter */ + id_buf[id_size++] = c; + do { + LoadChar(c); + if (id_size <= IDFSIZE) + id_buf[id_size++] = c; + } while (in_idf(c)); + id_buf[--id_size] = '\0'; + if (n = find_name(id_buf, formals)) { + /* construct the formal parameter mark */ + text[pos++] = FORMALP | (char) n; + if (pos == text_size) + text = Srealloc(text, + text_size += RTEXTSIZE); + } + else { + register char *ptr = &id_buf[0]; + + while (pos + id_size >= text_size) + text = Srealloc(text, + text_size += RTEXTSIZE); + while (text[pos++] = *ptr++) ; + pos--; + } + } + else { + text[pos++] = c; + if (pos == text_size) + text = Srealloc(text, text_size += RTEXTSIZE); + LoadChar(c); + } + } + text[pos++] = '\0'; + *length = pos - 1; + return text; +} + +#define BLANK(ch) ((ch == ' ') || (ch == '\t')) + +/* macroeq() decides whether two macro replacement texts are + identical. This version compares the texts, which occur + as strings, without taking care of the leading and trailing + blanks (spaces and tabs). +*/ +PRIVATE +macroeq(s, t) + register char *s, *t; +{ + + /* skip leading spaces */ + while (BLANK(*s)) s++; + while (BLANK(*t)) t++; + /* first non-blank encountered in both strings */ + /* The actual comparison loop: */ + while (*s && *s == *t) + s++, t++; + /* two cases are possible when arrived here: */ + if (*s == '\0') { /* *s == '\0' */ + while (BLANK(*t)) t++; + return *t == '\0'; + } + else { /* *s != *t */ + while (BLANK(*s)) s++; + while (BLANK(*t)) t++; + return (*s == '\0') && (*t == '\0'); + } +} diff --git a/util/cpp/error.c b/util/cpp/error.c new file mode 100644 index 00000000..f19ce53d --- /dev/null +++ b/util/cpp/error.c @@ -0,0 +1,59 @@ +/* E R R O R A N D D I A G N O S T I C R O U T I N E S */ + +#include + +#include "errout.h" +#include "LLlex.h" + +/* This file contains the (non-portable) error-message and diagnostic + functions. Beware, they are called with a variable number of + arguments! +*/ + +int err_occurred; + +err_hdr(s) + char *s; +{ + fprint(ERROUT, "\"%s\", line %d: %s", FileName, LineNumber, s); +} + +/*VARARGS1*/ +error(fmt, args) + char *fmt; +{ + err_hdr(""); + doprnt(ERROUT, fmt, &args); + fprint(ERROUT, "\n"); +} + +/*VARARGS1*/ +warning(fmt, args) + char *fmt; +{ + err_hdr("warning "); + doprnt(ERROUT, fmt, &args); + fprint(ERROUT, "\n"); +} + +/*VARARGS1*/ +crash(fmt, args) + char *fmt; + int args; +{ + err_hdr("crash "); + doprnt(ERROUT, fmt, &args); + fprint(ERROUT, "\n"); + sys_stop(S_ABORT); +} + +/*VARARGS1*/ +fatal(fmt, args) + char *fmt; + int args; +{ + err_hdr("fatal "); + doprnt(ERROUT, fmt, &args); + fprint(ERROUT, "\n"); + sys_stop(S_EXIT); +} diff --git a/util/cpp/expr.c b/util/cpp/expr.c new file mode 100644 index 00000000..45ce1a05 --- /dev/null +++ b/util/cpp/expr.c @@ -0,0 +1,53 @@ +/* OPERATOR HANDLING */ + +#include "Lpars.h" + +int +rank_of(oper) + int oper; +{ + /* The rank of the operator oper is returned. + */ + switch (oper) { + default: + return 0; + case '(': + return 1; + case '!': + return 2; + case '*': + case '/': + case '%': + return 3; + case '+': + case '-': + return 4; + case LEFT: + case RIGHT: + return 5; + case '<': + case '>': + case LESSEQ: + case GREATEREQ: + return 6; + case EQUAL: + case NOTEQUAL: + return 7; + case '&': + return 8; + case '^': + return 9; + case '|': + return 10; + case AND: + return 11; + case OR: + return 12; + case '?': + case ':': + return 13; + case ',': + return 15; + } + /*NOTREACHED*/ +} diff --git a/util/cpp/expression.g b/util/cpp/expression.g new file mode 100644 index 00000000..109b5644 --- /dev/null +++ b/util/cpp/expression.g @@ -0,0 +1,124 @@ +/* EXPRESSION SYNTAX PARSER */ + +%lexical LLlex; +%start If_expr, if_expression; + +{ +#include "LLlex.h" + +extern int ifval; +} + +if_expression +: + constant_expression(&ifval) +; + +/* 7.1 */ +primary(int *pval;) +: + constant(pval) +| + '(' expression(pval) ')' +; + +unary(int *pval;) + {int oper;} +: + unop(&oper) + unary(pval) + { ch7mon(oper, pval); } +| + primary(pval) +; + +binary_expression(int maxrank; int *pval;) + {int oper; int val1;} +: + unary(pval) + [%while (rank_of(DOT) <= maxrank) + binop(&oper) + binary_expression(rank_of(oper)-1, &val1) + { + ch7bin(pval, oper, val1); + } + ]* +; + +/* 7.13 */ +conditional_expression(int *pval;) + {int val1 = 0, val2 = 0;} +: + /* allow all binary operators */ + binary_expression(rank_of('?') - 1, pval) + [ '?' + expression(&val1) + ':' + assignment_expression(&val2) + { *pval = (*pval ? val1 : val2); } + ]? +; + +/* 7.14 */ +assignment_expression(int *pval;) +: + conditional_expression(pval) +; + +/* 7.15 */ +expression(int *pval;) + {int val1;} +: + assignment_expression(pval) + [ ',' + assignment_expression(&val1) + { + ch7bin(pval, ',', val1); + } + ]* +; + +unop(int *oper;) : + [ '-' | '!' | '~' ] + {*oper = DOT;} +; + +multop: + '*' | '/' | '%' +; + +addop: + '+' | '-' +; + +shiftop: + LEFT | RIGHT +; + +relop: + '<' | '>' | LESSEQ | GREATEREQ +; + +eqop: + EQUAL | NOTEQUAL +; + +arithop: + multop | addop | shiftop +| + '&' | '^' | '|' +; + +binop(int *oper;) : + [ arithop | relop | eqop | AND | OR ] + {*oper = DOT;} +; + +constant(int *pval;) : + INTEGER + {*pval = dot.tk_val;} +; + +constant_expression (int *pval;) : + assignment_expression(pval) +; diff --git a/util/cpp/file_info.h b/util/cpp/file_info.h new file mode 100644 index 00000000..8a3c8a89 --- /dev/null +++ b/util/cpp/file_info.h @@ -0,0 +1,13 @@ +/* F I L E I N F O R M A T I O N S T R U C T U R E */ + +struct file_info { + unsigned int fil_lino; + char *fil_name; + char *fil_wdir; +}; + +#define LineNumber finfo.fil_lino +#define FileName finfo.fil_name +#define WorkingDir finfo.fil_wdir + +extern struct file_info finfo; /* input.c */ diff --git a/util/cpp/idf.c b/util/cpp/idf.c new file mode 100644 index 00000000..4bbd88a8 --- /dev/null +++ b/util/cpp/idf.c @@ -0,0 +1,2 @@ +#include "idf.h" +#include diff --git a/util/cpp/idf.h b/util/cpp/idf.h new file mode 100644 index 00000000..a017b9cf --- /dev/null +++ b/util/cpp/idf.h @@ -0,0 +1,11 @@ +struct id_usr { + struct macro *idu_macro; + int idu_resmac; +}; + +#define IDF_TYPE struct id_usr +#define IDF_HSIZE 6 +#define id_macro id_user.idu_macro +#define id_resmac id_user.idu_resmac + +#include diff --git a/util/cpp/init.c b/util/cpp/init.c new file mode 100644 index 00000000..64ec4cba --- /dev/null +++ b/util/cpp/init.c @@ -0,0 +1,72 @@ +/* PREPROCESSOR: INITIALIZATION ROUTINES */ + +#include +#include +#include "class.h" +#include "macro.h" +#include "idf.h" +#include "interface.h" + +PRIVATE struct mkey { + char *mk_reserved; + int mk_key; +} mkey[] = { + {"define", K_DEFINE}, + {"elif", K_ELIF}, + {"else", K_ELSE}, + {"endif", K_ENDIF}, + {"if", K_IF}, + {"ifdef", K_IFDEF}, + {"ifndef", K_IFNDEF}, + {"include", K_INCLUDE}, + {"line", K_LINE}, + {"undef", K_UNDEF}, + {0, K_UNKNOWN} +}; + +char *strcpy(); + +EXPORT +init_pp() +{ + long clock, sys_time(); + static char date[30]; + char *ctime(); + + /* Initialise the control line keywords (if, include, define, etc) + Although the lexical analyzer treats them as identifiers, the + control line handler can recognize them as keywords by the + id_resmac field of the identifier. + */ + { + register struct mkey *mk = &mkey[0]; + + while (mk->mk_reserved) { + struct idf *idf = str2idf(mk->mk_reserved, 0); + + if (idf->id_resmac) + fatal("maximum identifier length insufficient"); + idf->id_resmac = mk->mk_key; + mk++; + } + } + + /* Initialize __DATE__, __FILE__ and __LINE__ macro + definitions. + */ + /* __DATE__ */ + clock = sys_time(); + strcpy(&date[1], ctime(&clock)); + date[26] = '\0'; /* zap nl */ + date[0] = date[25] = '"'; + macro_def(str2idf("__DATE__", 0), date, -1, 26, NOFLAG); + + /* __LINE__ */ + macro_def(str2idf("__LINE__", 0), "0", -1, 1, FUNC); + + /* __FILE__ */ + macro_def(str2idf("__FILE__", 0), "", -1, 1, FUNC); + + /* defined(??) */ + macro_def(str2idf("defined", 0), "", 1, 1, FUNC); +} diff --git a/util/cpp/input.c b/util/cpp/input.c new file mode 100644 index 00000000..b26bfc03 --- /dev/null +++ b/util/cpp/input.c @@ -0,0 +1,47 @@ +#include "file_info.h" +#include "input.h" +#define INP_TYPE struct file_info +#define INP_VAR finfo +struct file_info finfo; +#include + +char * +getwdir(fn) + char *fn; +{ + register char *p; + char *strrindex(); + + p = strrindex(fn, '/'); + while (p && *(p + 1) == '\0') { /* remove trailing /'s */ + *p = '\0'; + p = strrindex(fn, '/'); + } + + if (fn[0] == '\0' || (fn[0] == '/' && p == &fn[0])) /* absolute path */ + return ""; + else + if (p) { + *p = '\0'; + fn = Salloc(fn, p - &fn[0] + 1); + *p = '/'; + return fn; + } + else return "."; +} + +int NoUnstack; +int Unstacked; + +AtEoIT() +{ + if (NoUnstack) error("unexpected EOF"); + DoUnstack(); + return 0; +} + +AtEoIF() +{ + if (NoUnstack) error("unexpected EOF"); + return 0; +} diff --git a/util/cpp/input.h b/util/cpp/input.h new file mode 100644 index 00000000..b1221d58 --- /dev/null +++ b/util/cpp/input.h @@ -0,0 +1,2 @@ +#include "inputtype.h" +#include diff --git a/util/cpp/interface.h b/util/cpp/interface.h new file mode 100644 index 00000000..d4a8c651 --- /dev/null +++ b/util/cpp/interface.h @@ -0,0 +1,3 @@ +#define PRIVATE +#define IMPORT extern +#define EXPORT diff --git a/util/cpp/macro.h b/util/cpp/macro.h new file mode 100644 index 00000000..b04953a7 --- /dev/null +++ b/util/cpp/macro.h @@ -0,0 +1,52 @@ +/* PREPROCESSOR: DEFINITION OF MACRO DESCRIPTOR */ + +/* The flags of the mc_flag field of the macro structure. Note that + these flags can be set simultaneously. +*/ +#define NOFLAG 0 /* no special flags */ +#define FUNC 01 /* function attached */ +#define NOREPLACE 02 /* don't replace */ + +#define FORMALP 0200 /* mask for creating macro formal parameter */ + +/* The macro descriptor is very simple, except the fact that the + mc_text, which points to the replacement text, contains the + non-ascii characters \201, \202, etc, indicating the position of a + formal parameter in this text. +*/ +struct macro { + struct macro *next; + char * mc_text; /* the replacement text */ + int mc_nps; /* number of formal parameters */ + int mc_length; /* length of replacement text */ + int mc_count; /* # of "concurrent" invocations*/ + char mc_flag; /* marking this macro */ +}; + + +/* allocation definitions of struct macro */ +extern char *st_alloc(); +extern struct macro *h_macro; +#ifdef DEBUG +extern int cnt_macro; +extern char *std_alloc(); +#define new_macro() ((struct macro *) std_alloc((char **)&h_macro, sizeof(struct macro), 20, &cnt_macro)) +#else +#define new_macro() ((struct macro *) st_alloc((char **)&h_macro, sizeof(struct macro), 20)) +#endif +#define free_macro(p) st_free(p, &h_macro, sizeof(struct macro)) + + +/* `token' numbers of keywords of command-line processor +*/ +#define K_UNKNOWN 0 +#define K_DEFINE 1 +#define K_ELIF 2 +#define K_ELSE 3 +#define K_ENDIF 4 +#define K_IF 5 +#define K_IFDEF 6 +#define K_IFNDEF 7 +#define K_INCLUDE 8 +#define K_LINE 9 +#define K_UNDEF 10 diff --git a/util/cpp/main.c b/util/cpp/main.c new file mode 100644 index 00000000..fc581c3b --- /dev/null +++ b/util/cpp/main.c @@ -0,0 +1,65 @@ +/* MAIN PROGRAM */ + +#include "file_info.h" +#include "idfsize.h" + +extern struct tokenname tkidf[], tkkey[]; +extern char *symbol2str(); +extern char *inctable[]; +extern int err_occurred; +int idfsize = IDFSIZE; + +int ifval; + +char *prog_name; + +main(argc, argv) + char *argv[]; +{ + /* parse and interpret the command line options */ + prog_name = argv[0]; + + init_idf(); + init_pp(); /* initialise the preprocessor macros */ + + /* Note: source file "-" indicates that the source is supplied + as standard input. This is only allowed if INP_READ_IN_ONE is + not defined! + */ + while (argc > 1 && *argv[1] == '-' && argv[1][1] != '\0') { + char *par = &argv[1][1]; + + if (*par == '-') + par++; + do_option(par); + argc--, argv++; + } + compile(argc - 1, &argv[1]); + return err_occurred; +} + +compile(argc, argv) + char *argv[]; +{ + register char *source = 0; + char *dummy; + + switch (argc) { + case 1: + source = argv[0]; + FileName = source; + break; + case 0: + FileName = ""; + break; + default: + fatal("use: %s [options] [source]", prog_name); + break; + } + WorkingDir = inctable[0]; + + if (!InsertFile(source, (char **) 0, &dummy)) /* read the source file */ + fatal("%s: no source file %s\n", prog_name, + source ? source : "stdin"); + preprocess(source); +} diff --git a/util/cpp/make.hfiles b/util/cpp/make.hfiles new file mode 100755 index 00000000..2132dd61 --- /dev/null +++ b/util/cpp/make.hfiles @@ -0,0 +1,35 @@ +: Update Files from database + +PATH=/bin:/usr/bin + +case $# in +1) ;; +*) echo use: $0 file >&2 + exit 1 +esac + +( +IFCOMMAND="if (<\$FN) 2>/dev/null;\ + then if cmp -s \$FN \$TMP;\ + then rm \$TMP;\ + else mv \$TMP \$FN;\ + echo update \$FN;\ + fi;\ + else mv \$TMP \$FN;\ + echo create \$FN;\ + fi" +echo 'TMP=.uf$$' +echo 'FN=$TMP' +echo 'cat >$TMP <<\!EOF!' +sed -n '/^!File:/,${ +/^$/d +/^!File:[ ]*\(.*\)$/s@@!EOF!\ +'"$IFCOMMAND"'\ +FN=\1\ +cat >$TMP <<\\!EOF!@ +p +}' $1 +echo '!EOF!' +echo $IFCOMMAND +) | +sh diff --git a/util/cpp/make.tokcase b/util/cpp/make.tokcase new file mode 100755 index 00000000..ef32292f --- /dev/null +++ b/util/cpp/make.tokcase @@ -0,0 +1,34 @@ +cat <<'--EOT--' +#include "Lpars.h" + +char * +symbol2str(tok) + int tok; +{ + static char buf[2] = { '\0', '\0' }; + + if (040 <= tok && tok < 0177) { + buf[0] = tok; + buf[1] = '\0'; + return buf; + } + switch (tok) { +--EOT-- +sed ' +/{[A-Z]/!d +s/.*{\(.*\),.*\(".*"\).*$/ case \1 :\ + return \2;/ +' +cat <<'--EOT--' + case '\n': + case '\f': + case '\v': + case '\r': + case '\t': + buf[0] = tok; + return buf; + default: + return "bad token"; + } +} +--EOT-- diff --git a/util/cpp/make.tokfile b/util/cpp/make.tokfile new file mode 100755 index 00000000..494b7e3c --- /dev/null +++ b/util/cpp/make.tokfile @@ -0,0 +1,6 @@ +sed ' +/{[A-Z]/!d +s/.*{// +s/,.*// +s/.*/%token &;/ +' diff --git a/util/cpp/next.c b/util/cpp/next.c new file mode 100644 index 00000000..64ff5ff2 --- /dev/null +++ b/util/cpp/next.c @@ -0,0 +1,5 @@ +#include "debug.h" +struct macro *h_macro = 0; +#ifdef DEBUG +int cnt_macro = 0; +#endif diff --git a/util/cpp/options.c b/util/cpp/options.c new file mode 100644 index 00000000..c1ef969c --- /dev/null +++ b/util/cpp/options.c @@ -0,0 +1,119 @@ +/* USER-OPTION HANDLING */ + +#include +#include "idfsize.h" +#include "maxincl.h" +#include "class.h" +#include "macro.h" +#include "idf.h" + +char options[128]; /* one for every char */ +int inc_pos = 1; /* place where next -I goes */ +char *inctable[MAXINCL] = { /* list for includes */ + ".", + "/usr/include", + 0 +}; + +extern int idfsize; +int txt2int(); + +do_option(text) + char *text; +{ + switch(*text++) { + case '-': + options[*text] = 1; + break; + default: + error("illegal option: %c", text[-1]); + break; + case 'C' : /* comment output */ + options['C'] = 1; + break; + case 'D' : /* -Dname : predefine name */ + { + register char *cp = text, *name, *mactext; + + if (class(*cp) != STIDF) { + error("identifier missing in -D%s", text); + break; + } + name = cp; + while (*cp && in_idf(*cp)) + ++cp; + if (!*cp) /* -Dname */ + mactext = "1"; + else + if (*cp == '=') { /* -Dname=text */ + *cp++ = '\0'; /* end of name */ + mactext = cp; + } + else { /* -Dname?? */ + error("malformed option -D%s", text); + break; + } + macro_def(str2idf(name, 0), mactext, -1, strlen(mactext), NOFLAG); + break; + } + case 'I' : /* -Ipath : insert "path" into include list */ + if (*text) { + register int i = inc_pos++; + register char *new = text; + + while (new) { + register char *tmp = inctable[i]; + + inctable[i++] = new; + if (i == MAXINCL) + fatal("too many -I options"); + new = tmp; + } + } + else inctable[inc_pos] = 0; + break; + case 'M': /* maximum identifier length */ + idfsize = txt2int(&text); + if (*text) + error("malformed -M option"); + if (idfsize > IDFSIZE) { + warning("maximum identifier length is %d", IDFSIZE); + idfsize = IDFSIZE; + } + if (idfsize < 8) { + warning("minimum identifier length is 8"); + idfsize = 8; + } + break; + case 'P' : /* run preprocessor stand-alone, without #'s */ + options['P'] = 1; + break; + case 'U' : /* -Uname : undefine predefined */ + if (*text) { + register struct idf *idef = findidf(text); + + if (idef && idef->id_macro) { + free_macro(idef->id_macro); + idef->id_macro = (struct macro *) 0; + } + } + break; + } +} + +int +txt2int(tp) + char **tp; +{ + /* the integer pointed to by *tp is read, while increasing + *tp; the resulting value is yielded. + */ + register int val = 0; + register int ch; + + while (ch = **tp, ch >= '0' && ch <= '9') { + val = val * 10 + ch - '0'; + (*tp)++; + } + return val; +} diff --git a/util/cpp/preprocess.c b/util/cpp/preprocess.c new file mode 100644 index 00000000..935d178c --- /dev/null +++ b/util/cpp/preprocess.c @@ -0,0 +1,209 @@ +/* PREPROCESSOR DRIVER */ + +#include +#include "input.h" +#include "maxincl.h" +#include "obufsize.h" +#include "LLlex.h" +#include "class.h" +#include "idf.h" +#include "idfsize.h" +#include "bits.h" + +char _obuf[OBUFSIZE]; + +#ifdef DOBITS +char bits[128]; +#endif + +preprocess(fn) + char *fn; +{ + register int c; + register char *op = _obuf; + register char *ob = &_obuf[OBUFSIZE]; + int lineno = 0; + extern char options[]; + +#define flush(X) (sys_write(STDOUT,_obuf,X), op = _obuf) +#define echo(ch) (op != ob || flush(OBUFSIZE), *op++ = (ch)) +#define newline() echo('\n') + + for (;;) { + LineNumber++; + lineno++; + LoadChar(c); + while (c == '#') { + domacro(); + lineno++; + newline(); + LoadChar(c); + } + if (! options['P'] && + (lineno != LineNumber || fn != FileName)) { + char Xbuf[256]; + register char *p = Xbuf; + + fn = FileName; + lineno = LineNumber; + sprint(p, "#line %d \"%s\"\n", LineNumber, + FileName); + while (*p) echo(*p++); + } + for (;;) { + if (c & 0200) { + if (c == EOI) { + flush(op-_obuf); + return; + } + fatal("non-ascii character read"); + } + if (c == '/') { + LoadChar(c); + if (c == '*') { + NoUnstack++; + if (options['C']) { + echo('/'); + echo('*'); + } + for (;;) { + LoadChar(c); + if (class(c) == STNL) { + ++LineNumber; + ++lineno; + echo(c); + } + else if (c == EOI) { + flush(op - _obuf); + return; + } + else if (c == '*') { + if (options['C']) echo(c); + LoadChar(c); + if (c == '/') { + if (options['C']) echo(c); + break; + } + else { + PushBack(); + } + } + else if (options['C']) echo(c); + } + NoUnstack--; + LoadChar(c); + continue; + } + echo('/'); + continue; + } + switch(class(c)) { + case STNL: + echo(c); + break; + case STSTR: + case STCHAR: { + register int stopc = c; + + do { + echo(c); + LoadChar(c); + if (c == '\\') { + echo(c); + LoadChar(c); + } + if (c == '\n') { + ++LineNumber; + lineno++; + } + else if (c == EOI) { + flush(op-_obuf); + return; + } + } + while (c != stopc); + echo(c); + LoadChar(c); + continue; + } + case STNUM: +#define getdec(c) do { echo(c); LoadChar(c);} while (is_dig(c)) +#define gethex(c) do { echo(c); LoadChar(c);} while (is_hex(c)) + + if (c != '0') { + getdec(c); + if (c == '.') getdec(c); + if (c == 'e') { + echo(c); + LoadChar(c); + if (c == '+' || c == '-') { + echo(c); + LoadChar(c); + } + if (is_dig(c)) getdec(c); + } + } + else { + echo(c); + LoadChar(c); + if (c == 'x' || c == 'X') gethex(c); + else if (is_dig(c)) getdec(c); + } + continue; + case STIDF: { + extern int idfsize; /* ??? */ + char buf[IDFSIZE + 1]; + register char *tg = &buf[0]; + register char *maxpos = &buf[idfsize]; + register struct idf *idef; + +#define tstmac(bx) if (!(bits[c] & bx)) goto nomac +#define cpy if (Unstacked) EnableMacros(); *tg++ = c +#define load LoadChar(c); if (!in_idf(c)) goto endidf + +#ifdef DOBITS + cpy; tstmac(bit0); load; + cpy; tstmac(bit1); load; + cpy; tstmac(bit2); load; + cpy; tstmac(bit3); load; + cpy; tstmac(bit4); load; + cpy; tstmac(bit5); load; + cpy; tstmac(bit6); load; + cpy; tstmac(bit7); load; +#endif + + for(;;) { + if (tg < maxpos) { + cpy; + } + load; + } + endidf: + PushBack(); + *tg = '\0'; /* mark the end of the identifier */ + idef = findidf(buf); + if ((idef && idef->id_macro && replace(idef))) { + LoadChar(c); + continue; + } + nomac: + *tg = 0; + tg = buf; + while (*tg) echo(*tg++); + LoadChar(c); + while (in_idf(c)) { + echo(c); + LoadChar(c); + } + continue; + } + default: + echo(c); + LoadChar(c); + continue; + } + break; + } + } + /*NOTREACHED*/ +} diff --git a/util/cpp/replace.c b/util/cpp/replace.c new file mode 100644 index 00000000..e8e78d30 --- /dev/null +++ b/util/cpp/replace.c @@ -0,0 +1,196 @@ +/* PREPROCESSOR: MACRO-TEXT REPLACEMENT ROUTINES */ + +#include "debug.h" /* UF */ +#include "pathlength.h" /* UF */ +#include "textsize.h" /* UF */ + +#include +#include +#include +#include "idf.h" +#include "input.h" +#include "macro.h" +#include "LLlex.h" +#include "class.h" +#include "interface.h" + +char *strcpy(), *strcat(); +char *long2str(); + +PRIVATE struct macro *ReplaceList; /* list of currently active macros */ + +EXPORT int +replace(idef) + register struct idf *idef; +{ + /* replace() is called by the lexical analyzer to perform + macro replacement. "idef" is the description of the + identifier which leads to the replacement. If the + optional actual parameters of the macro are OK, the text + of the macro is prepared to serve as an input buffer, + which is pushed onto the input stack. + replace() returns 1 if the replacement succeeded and 0 if + some error has occurred. + */ + register struct macro *mac = idef->id_macro; + register char c; + char **actpars, **getactuals(); + char *reptext, *macro2buffer(); + int size; + + if (mac->mc_flag & NOREPLACE) { + warning("macro %s is recursive", idef->id_text); + return 0; + } + if (mac->mc_nps != -1) { /* with parameter list */ + if (mac->mc_flag & FUNC) { + /* must be "defined". + Unfortunately, the next assertion + will not compile ... + assert( ! strcmp("defined", idef->id_text)); + */ + if (! AccDefined) + return 0; + } + if (++mac->mc_count > 100) { + /* 100 must be some number in Parameters */ + warning("macro %s is assumed recursive", + idef->id_text); + return 0; + } + LoadChar(c); + c = skipspaces(c); + if (c != '(') { /* no replacement if no () */ + error("macro %s needs arguments", + idef->id_text); + PushBack(); + return 0; + } + actpars = getactuals(idef); /* get act.param. list */ + if (mac->mc_flag & FUNC) { + struct idf *param = findidf(*actpars); + + if (param && param->id_macro) + reptext = "1"; + else + reptext = "0"; + InsertText(reptext, 1); + mac->next = ReplaceList; + ReplaceList = mac; + return 1; + } + } + if (mac->mc_flag & FUNC) /* this macro leads to special action */ + macro_func(idef); + if (mac->mc_nps <= 0) { + mac->mc_flag |= NOREPLACE; + reptext = mac->mc_text; + size = mac->mc_length; + } + else reptext = macro2buffer(idef, actpars, &size); /* create input buffer */ + InsertText(reptext, size); + mac->next = ReplaceList; + ReplaceList = mac; + return 1; +} + +char FilNamBuf[PATHLENGTH]; + +PRIVATE +macro_func(idef) + register struct idf *idef; +{ + /* macro_func() performs the special actions needed with some + macros. These macros are __FILE__ and __LINE__ which + replacement texts must be evaluated at the time they are + used. + */ + register struct macro *mac = idef->id_macro; + + switch (idef->id_text[2]) { /* This switch is very blunt... */ + case 'F' : /* __FILE__ */ + mac->mc_length = strlen(FileName) + 2; + mac->mc_text = FilNamBuf; + mac->mc_text[0] = '"'; + strcpy(&(mac->mc_text[1]), FileName); + strcat(mac->mc_text, "\""); + break; + case 'L' : /* __LINE__ */ + { + mac->mc_text = long2str((long) LineNumber, 10); + mac->mc_length = strlen(mac->mc_text); + break; + } + default : + crash("(macro_func)"); + } +} + +PRIVATE char * +macro2buffer(idef, actpars, siztext) + struct idf *idef; + char **actpars; + int *siztext; +{ + /* Macro2buffer() turns the macro replacement text, as it is + stored, into an input buffer, while each occurrence of the + non-ascii formal parameter mark is replaced by its + corresponding actual parameter specified in the actual + parameter list actpars. A pointer to the beginning of the + constructed text is returned, while *siztext is filled + with its length. + If there are no parameters, this function behaves + the same as strcpy(). + */ + register int size = idef->id_macro->mc_length + ITEXTSIZE; + register char *text = Malloc(size); + register int pos = 0; + register char *ptr = idef->id_macro->mc_text; + + while (*ptr) { + if (*ptr & FORMALP) { /* non-asc formal param. mark */ + register int n = *ptr++ & 0177; + register char *p; + + assert(n != 0); + /* copy the text of the actual parameter + into the replacement text + */ + for (p = actpars[n - 1]; p && *p; p++) { + text[pos++] = *p; + if (pos == size) + text = Srealloc(text, size += RTEXTSIZE); + } + } + else { + text[pos++] = *ptr++; + if (pos == size) + text = Srealloc(text, size += RTEXTSIZE); + } + } + text[pos] = '\0'; + *siztext = pos; + return text; +} + +EXPORT +DoUnstack() +{ + Unstacked++; +} + +EXPORT +EnableMacros() +{ + register struct macro *p = ReplaceList; + + assert(Unstacked > 0); + while (Unstacked > 0) { + assert(p != 0); + p->mc_flag &= ~NOREPLACE; + p->mc_count = 0; + p = p->next; + Unstacked--; + } + ReplaceList = p; +} diff --git a/util/cpp/scan.c b/util/cpp/scan.c new file mode 100644 index 00000000..8be12de2 --- /dev/null +++ b/util/cpp/scan.c @@ -0,0 +1,224 @@ +/* PREPROCESSOR: SCANNER FOR THE ACTUAL PARAMETERS OF MACROS */ + +/* This file contains the function getactuals() which scans an actual + parameter list and splits it up into a list of strings, each one + representing an actual parameter. +*/ + +#include "lapbuf.h" /* UF */ +#include "nparams.h" /* UF */ + +#include "input.h" +#include "class.h" +#include "idf.h" +#include "macro.h" +#include "interface.h" + +#define EOS '\0' +#define overflow() (fatal("actual parameter buffer overflow")) + +PRIVATE char apbuf[LAPBUF]; /* temporary storage for actual parameters */ +PRIVATE char *actparams[NPARAMS]; /* pointers to the text of the actuals */ +PRIVATE char *aptr; /* pointer to last inserted character in apbuf */ + +#define copy(ch) ((aptr < &apbuf[LAPBUF]) ? (*aptr++ = ch) : overflow()) + +PRIVATE int nr_of_params; /* number of actuals read until now */ + +PRIVATE char ** +getactuals(idef) + struct idf *idef; +{ + /* getactuals() collects the actual parameters and turns them + into a list of strings, a pointer to which is returned. + */ + register acnt = idef->id_macro->mc_nps; + + nr_of_params = 0; + actparams[0] = aptr = &apbuf[0]; + copyact('(', ')', 0); /* read the actual parameters */ + copy(EOS); /* mark the end of it all */ + + if (!nr_of_params++) { /* 0 or 1 parameter */ + /* there could be a ( ) + */ + register char *p = actparams[0]; + + while ((class(*p) == STSKIP) || (*p == '\n')) { + ++p; + } + + if (!*p) { /* the case () : 0 parameters */ + nr_of_params--; + } + } + + if (nr_of_params != acnt) { + /* argument mismatch: too many or too few + actual parameters. + */ + error("argument mismatch, %s", idef->id_text); + + while (++nr_of_params < acnt) { + /* too few paraeters: remaining actuals are "" + */ + actparams[nr_of_params] = (char *) 0; + } + } + + return actparams; +} + +PRIVATE +copyact(ch1, ch2, level) + char ch1, ch2; + int level; +{ + /* copyact() is taken from Ceriel Jacobs' LLgen, with + permission. Its task is to build a list of actuals + parameters, which list is surrounded by '(' and ')' and in + which the parameters are separated by ',' if there are + more than 1. The balancing of '(',')' and '[',']' and + '{','}' is taken care of by calling this function + recursively. At each level, copyact() reads the input, + upto the corresponding closing bracket. + + Opening bracket is ch1, closing bracket is ch2. If + level != 0, copy opening and closing parameters too. + */ + register int ch; /* Current char */ + register int match; /* used to read strings */ + + if (level) { + copy(ch1); + } + + for (;;) { + LoadChar(ch); + + if (ch == ch2) { + if (level) { + copy(ch); + } + return; + } + + switch(ch) { + + case ')': + case '}': + case ']': + error("unbalanced parenthesis"); + break; + + case '(': + copyact('(', ')', level+1); + break; + + case '{': + /* example: + #define declare(v, t) t v + declare(v, union{int i, j; float r;}); + */ + copyact('{', '}', level+1); + break; + + case '[': + copyact('[', ']', level+1); + break; + + case '\n': + LoadChar(ch); + while (ch == '#') { + /* This piece of code needs some + explanation: consider the call of + the macro defined as: + #define sum(b,c) (b + c) + in the following form: + sum( + #include my_phone_number + ,2) + in which case the include must be + interpreted as such. + */ + domacro(); /* has read nl, vt or ff */ + LoadChar(ch); + /* Loop, for another control line */ + } + + PushBack(); + copy('\n'); + break; + + case '/': + LoadChar(ch); + + if (ch == '*') { /* skip comment */ + skipcomment(); + continue; + } + + PushBack(); + copy('/'); + break; + + case ',': + if (!level) { + /* next parameter encountered */ + copy(EOS); + + if (++nr_of_params >= NPARAMS) { + fatal("(getact) too many actuals"); + } + + actparams[nr_of_params] = aptr; + } + else { + copy(ch); + } + break; + + case '\'': + case '"' : + /* watch out for brackets in strings, they do + not count ! + */ + match = ch; + copy(ch); + LoadChar(ch); + while (ch != EOI) { + if (ch == match) { + break; + } + + if (ch == '\\') { + copy(ch); + LoadChar(ch); + } + else + if (ch == '\n') { + error("newline in string"); + copy(match); + break; + } + + copy(ch); + LoadChar(ch); + } + + if (ch == match) { + copy(ch); + break; + } + /* Fall through */ + + case EOI : + error("unterminated macro call"); + return; + + default: + copy(ch); + break; + } + } +} diff --git a/util/cpp/skip.c b/util/cpp/skip.c new file mode 100644 index 00000000..636e79b3 --- /dev/null +++ b/util/cpp/skip.c @@ -0,0 +1,64 @@ +/* $Header$ */ +/* PREPROCESSOR: INPUT SKIP FUNCTIONS */ + +#include "LLlex.h" +#include "class.h" +#include "input.h" + +int +skipspaces(ch) + register int ch; +{ + /* skipspaces() skips any white space and returns the first + non-space character. + */ + for (;;) { + while (class(ch) == STSKIP) + LoadChar(ch); + /* How about "\\\n"????????? */ + if (ch == '/') { + LoadChar(ch); + if (ch == '*') { + skipcomment(); + LoadChar(ch); + } + else { + PushBack(); + return '/'; + } + } + else + return ch; + } +} + +skipline() +{ + /* skipline() skips all characters until a newline character + is seen, not escaped by a '\\'. + Any comment is skipped. + */ + register int c; + + LoadChar(c); + while (class(c) != STNL && c != EOI) { + if (c == '\\') { + LoadChar(c); + if (class(c) == STNL) + ++LineNumber; + } + if (c == '/') { + LoadChar(c); + if (c == '*') + skipcomment(); + else + continue; + } + LoadChar(c); + } + ++LineNumber; + if (c == EOI) { /* garbage input... */ + error("unexpected EOF while skipping text"); + PushBack(); + } +} diff --git a/util/cpp/tokenname.c b/util/cpp/tokenname.c new file mode 100644 index 00000000..82fc1f55 --- /dev/null +++ b/util/cpp/tokenname.c @@ -0,0 +1,51 @@ +/* $Header$ */ +/* TOKEN NAME DEFINITIONS */ + +#include "idf.h" +#include "LLlex.h" +#include "Lpars.h" + +struct tokenname { /* Used for defining the name of a + token as identified by its symbol + */ + int tn_symbol; + char *tn_name; +}; + +/* To centralize the declaration of %tokens, their presence in this + file is taken as their declaration. The Makefile will produce + a grammar file (tokenfile.g) from this file. + Moreover, rather than looking up a symbol in all these lists + to find its printable name, a fast version of symbol2str() is + generated from these tables. + Consequenty some of these tables are not referenced explicitly + in the C text any more. To save space and to avoid lint confusion, + these have been made pseudo-invisible by #ifdefs. +*/ + +#ifdef ____ +struct tokenname tkspec[] = { /* the names of the special tokens */ + {IDENTIFIER, "identifier"}, + {STRING, "string"}, + {FILESPECIFIER, "filespecifier"}, + {INTEGER, "integer"}, + {0, ""} +}; + +struct tokenname tkcomp[] = { /* names of the composite tokens */ + {NOTEQUAL, "!="}, + {AND, "&&"}, + {LEFT, "<<"}, + {LESSEQ, "<="}, + {EQUAL, "=="}, + {GREATEREQ, ">="}, + {RIGHT, ">>"}, + {OR, "||"}, + {0, ""} +}; + +struct tokenname tkfunny[] = { /* internal keywords */ + {ERRONEOUS, "erroneous"}, + {0, ""} +}; +#endif ____ From ca9f784e67c3a3f8a8c34a64e1fb16a32ab54e79 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 6 Jan 1987 18:31:02 +0000 Subject: [PATCH 0427/1625] Initial revision --- modules/src/em_code/k/em_private.h | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 modules/src/em_code/k/em_private.h diff --git a/modules/src/em_code/k/em_private.h b/modules/src/em_code/k/em_private.h new file mode 100644 index 00000000..61f85a1d --- /dev/null +++ b/modules/src/em_code/k/em_private.h @@ -0,0 +1,37 @@ +/* private inclusion file */ + +#include +#include +#include + +/* include the EM description files */ +#include +#include +#include +#include + +/* macros used in the definitions of the interface functions C_* */ +#define OP(x) put_op(x) +#define CST(x) put_cst(x) +#define DCST(x) put_cst(x) +#define SCON(x,y) put_scon((x), (y)) +#define PS(x) put_ps(x) +#define DLB(x) put_dlb(x) +#define DFDLB(x) put_dlb(x) +#define ILB(x) put_ilb(x) +#define DFILB(x) put_ilb(x) +#define NOFF(x,y) put_noff((x), (y)) +#define DOFF(x,y) put_doff((x), (y)) +#define PNAM(x) put_pnam(x) +#define DNAM(x) put_dnam(x) +#define DFDNAM(x) put_dnam(x) +#define CEND() put_cend() +#define CCEND() put_cend() +#define WCON(x,y,z) put_wcon((x), (y), (z)) +#define COMMA() +#define NL() +#define CILB(x) CST(x) + +#define put_cend() putbyte(sp_cend) +#define put_op(x) putbyte(x) +#define put_ps(x) putbyte(x) From db18fcf83e0de9f5b719ce0a2e1765f5ba049eff Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 6 Jan 1987 18:45:35 +0000 Subject: [PATCH 0428/1625] Initial revision --- modules/src/em_code/Makefile | 45 ++++++++ modules/src/em_code/k/em.c | 197 +++++++++++++++++++++++++++++++++++ 2 files changed, 242 insertions(+) create mode 100644 modules/src/em_code/Makefile create mode 100644 modules/src/em_code/k/em.c diff --git a/modules/src/em_code/Makefile b/modules/src/em_code/Makefile new file mode 100644 index 00000000..d8a58d79 --- /dev/null +++ b/modules/src/em_code/Makefile @@ -0,0 +1,45 @@ +EMHOME = ../../.. +INSTALL = $(EMHOME)/modules/install +COMPARE = $(EMHOME)/modules/compare + +all: libeme.a libemk.a em_code.3 + +install: all + $(INSTALL) lib/libeme.a + $(INSTALL) lib/libemk.a + $(INSTALL) man/em_code.3 + +compare: all + $(COMPARE) lib/libeme.a + $(COMPARE) lib/libemk.a + $(COMPARE) man/em_code.3 + +em_code.3: em_code.3X + tbl < em_code.3X > em_code.3 + +libeme.a: make.sh e/em_private.h e/em.c + sh make.sh e + -sh -c 'ranlib libeme.a' + +libemk.a: make.sh k/em_private.h k/em.c + sh make.sh k + -sh -c 'ranlib libemk.a' + +make.sh: em.gen em.nogen + make.fun em.gen em.nogen | sh + +em.gen: make.em.gen $(EMHOME)/etc/em_table + make.em.gen > em.gen + +pr: + @pr Makefile make.em.gen make.fun em.nogen e/em_private.h e/em.c k/em_private.h k/em.c + +opr: + make pr | opr + +# don't put the next "rm"s all on one line. the argument list then +# becomes too long for some systems +clean: + rm -f *.o + rm -f *.c + rm -f *.a em_code.3 em.gen make.sh diff --git a/modules/src/em_code/k/em.c b/modules/src/em_code/k/em.c new file mode 100644 index 00000000..84b1a08d --- /dev/null +++ b/modules/src/em_code/k/em.c @@ -0,0 +1,197 @@ +/* $Header$ */ +/* EM CODE OUTPUT ROUTINES */ + +#include +#include "em_private.h" + +#define put8(x) putbyte(x) +#define put16(x) put8((int) x); put8((int) (x >> 8)) +#define put32(x) put16((int) x); put16((int) (x >> 16)) + +/* + putbyte(), C_open() and C_close() are the basic routines for + respectively write on, open and close the output file. + The put_*() functions serve as formatting functions of the + various EM language constructs. + See "Description of a Machine Architecture for use with + Block Structured Languages" par. 11.2 for the meaning of these + names. +*/ + +/* supply a kind of buffered output */ + +static char obuf[BUFSIZ]; +static char *opp = &obuf[0]; +static File *ofp = 0; + +static +flush() { + if (sys_write(ofp, &obuf[0], opp - &obuf[0]) == 0) { + sys_stop(S_ABORT); + } + opp = &obuf[0]; +} + +#define Xputbyte(c) if (opp == &obuf[BUFSIZ]) flush(); *opp++ = (c) + +putbyte(b) + int b; +{ + Xputbyte(b); +} + +#define putbyte(c) Xputbyte(c) + +C_open(nm) /* open file for compact code output */ + char *nm; +{ + if (nm == 0) + ofp = STDOUT; /* standard output */ + else + if (sys_open(nm, OP_WRITE, &ofp) == 0) + return 0; + return 1; +} + +C_close() +{ + if (opp != &obuf[0]) flush(); + if (ofp != STDOUT) + sys_close(ofp); + ofp = 0; +} + +C_busy() +{ + return ofp != 0; /* true if code is being generated */ +} + +C_magic() +{ + put16(sp_magic); +} + +/*** the compact code generating routines ***/ +#define fit16i(x) ((x) >= (long)0xFFFF8000 && (x) <= (long)0x00007FFF) +#define fit8u(x) ((x) <= 0xFF) /* x is already unsigned */ + +put_ilb(l) + register label l; +{ + if (fit8u(l)) { + put8(sp_ilb1); + put8(l); + } + else { + put8(sp_ilb2); + put16(l); + } +} + +put_dlb(l) + register label l; +{ + if (fit8u(l)) { + put8(sp_dlb1); + put8(l); + } + else { + put8(sp_dlb2); + put16((int)l); + } +} + +put_cst(l) + register arith l; +{ + if (l >= (arith) -sp_zcst0 && l < (arith) (sp_ncst0 - sp_zcst0)) { + /* we can convert 'l' to an int because its value + can be stored in a byte. + */ + put8((int)l + (sp_zcst0 + sp_fcst0)); + } + else + if (fit16i(l)) { /* the cast from long to int causes no trouble here */ + put8(sp_cst2); + put16((int) l); + } + else { + put8(sp_cst4); + put32(l); + } +} + +put_doff(l, v) + label l; + arith v; +{ + if (v == 0) { + put_dlb(l); + } + else { + put8(sp_doff); + put_dlb(l); + put_cst(v); + } +} + +put_noff(s, v) + char *s; + arith v; +{ + if (v == 0) { + put_dnam(s); + } + else { + put8(sp_doff); + put_dnam(s); + put_cst(v); + } +} + +put_dnam(s) + char *s; +{ + put8(sp_dnam); + put_str(s); +} + +put_pnam(s) + char *s; +{ + put8(sp_pnam); + put_str(s); +} + +put_wcon(sp, v, sz) /* sp_icon, sp_ucon or sp_fcon with int repr */ + int sp; + char *v; + arith sz; +{ + /* how 'bout signextension int --> long ??? */ + put8(sp); + put_cst(sz); + put_str(v); +} + +put_str(s) + register char *s; +{ + register int len; + + put_cst((arith) (len = strlen(s))); + while (--len >= 0) { + put8(*s++); + } +} + +put_scon(b, n) + register char *b; + register arith n; +{ + put8(sp_scon); + put_cst(n); + while (--n >= 0) { + put8(*b++); + } +} From c34565adef1e3eb9ca5f932d2fe5a4896abafcc7 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 6 Jan 1987 18:49:00 +0000 Subject: [PATCH 0429/1625] Removed a bug that led to infinite looping in obscure cases. --- mach/proto/cg/reg.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mach/proto/cg/reg.c b/mach/proto/cg/reg.c index 4482dce1..bc94e896 100644 --- a/mach/proto/cg/reg.c +++ b/mach/proto/cg/reg.c @@ -71,6 +71,12 @@ getrefcount(regno) { erasereg(regno) { register struct reginfo *rp; + register int i; + + rp = &machregs[regno]; + rp->r_contents.t_token = 0; + for (i=0;ir_contents.t_att[i].aw = 0; #if MAXMEMBERS==0 awayreg(regno); @@ -86,11 +92,6 @@ awayreg(regno) { register tkdef_p tdp; register i; - rp = &machregs[regno]; - rp->r_contents.t_token = 0; - for (i=0;ir_contents.t_att[i].aw = 0; - /* Now erase recursively all registers containing * something using this one */ From e4a2f55de6999be6df50f84711c8769c47ca989f Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 6 Jan 1987 18:54:48 +0000 Subject: [PATCH 0430/1625] 3 --> 3ACK --- modules/src/input/input.3 | 2 +- modules/src/object/object.3 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/src/input/input.3 b/modules/src/input/input.3 index 82a6f452..0fd2cc6c 100644 --- a/modules/src/input/input.3 +++ b/modules/src/input/input.3 @@ -1,4 +1,4 @@ -.TH INPUT 3 "March 25, 1986" +.TH INPUT 3ACK "March 25, 1986" .SH NAME LoadChar, PushBack, InsertFile, InsertText, AtEoIF, AtEoIT\ \-\ input module for compilers diff --git a/modules/src/object/object.3 b/modules/src/object/object.3 index 52bd8ac5..79ebf09f 100644 --- a/modules/src/object/object.3 +++ b/modules/src/object/object.3 @@ -1,4 +1,4 @@ -.TH OBJECT 3 "October 16, 1986" +.TH OBJECT 3ACK "October 16, 1986" .SH NAME wr_open, wr_close, wr_ohead, wr_sect, wr_outsect, wr_emit, wr_putc, wr_relo, wr_name, wr_string, wr_arhdr, wr_ranlib, wr_int2, wr_long, From ebe9f3f4664d9c3853353faad36e5621694f278e Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 7 Jan 1987 11:10:33 +0000 Subject: [PATCH 0431/1625] *** empty log message *** --- util/cpp/Makefile | 11 ++++------- util/cpp/Parameters | 6 +++--- util/cpp/preprocess.c | 31 +++++++++++++++++++++++-------- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/util/cpp/Makefile b/util/cpp/Makefile index d02b1155..4df03654 100644 --- a/util/cpp/Makefile +++ b/util/cpp/Makefile @@ -72,10 +72,13 @@ all: cc cc: hfiles LLfiles make "EMHOME="$(EMHOME) cpp -hfiles: Parameters +hfiles: Parameters char.c charoffset.h ./make.hfiles Parameters @touch hfiles +charoffset.h char.c: chtab char.tab + chtab -fchar.tab > char.c + LLfiles: $(LSRC) $(GEN) $(GENOPTIONS) $(LSRC) @touch LLfiles @@ -86,12 +89,6 @@ tokenfile.g: tokenname.c make.tokfile symbol2str.c: tokenname.c make.tokcase symbol2str.c -char.c: char.tab chtab - chtab -fchar.tab > char.c - -charoffset.h: chtab char.tab - chtab -fchar.tab > /dev/null - chtab: chtab.o $(CC) -o chtab chtab.o diff --git a/util/cpp/Parameters b/util/cpp/Parameters index 21bd8a66..74694b52 100644 --- a/util/cpp/Parameters +++ b/util/cpp/Parameters @@ -35,7 +35,7 @@ !File: strsize.h #define ISTRSIZE 32 /* minimum number of bytes allocated for storing a string */ -#define RSTRSIZE 8 /* step size in enlarging the memory for +#define RSTRSIZE 32 /* step size in enlarging the memory for the storage of a string */ @@ -52,8 +52,8 @@ !File: textsize.h -#define ITEXTSIZE 32 /* 1st piece of memory for repl. text */ -#define RTEXTSIZE 32 /* stepsize for enlarging repl.text */ +#define ITEXTSIZE 64 /* 1st piece of memory for repl. text */ +#define RTEXTSIZE 64 /* stepsize for enlarging repl.text */ !File: inputtype.h diff --git a/util/cpp/preprocess.c b/util/cpp/preprocess.c index 935d178c..bd05c568 100644 --- a/util/cpp/preprocess.c +++ b/util/cpp/preprocess.c @@ -16,6 +16,11 @@ char _obuf[OBUFSIZE]; char bits[128]; #endif +Xflush() +{ + sys_write(STDOUT, _obuf, OBUFSIZE); +} + preprocess(fn) char *fn; { @@ -25,8 +30,8 @@ preprocess(fn) int lineno = 0; extern char options[]; -#define flush(X) (sys_write(STDOUT,_obuf,X), op = _obuf) -#define echo(ch) (op != ob || flush(OBUFSIZE), *op++ = (ch)) +#define flush(X) (sys_write(STDOUT,_obuf,X)) +#define echo(ch) if (op == ob) { Xflush(); op = _obuf; } *op++ = (ch); #define newline() echo('\n') for (;;) { @@ -48,7 +53,9 @@ preprocess(fn) lineno = LineNumber; sprint(p, "#line %d \"%s\"\n", LineNumber, FileName); - while (*p) echo(*p++); + while (*p) { + echo(*p++); + } } for (;;) { if (c & 0200) { @@ -78,17 +85,23 @@ preprocess(fn) return; } else if (c == '*') { - if (options['C']) echo(c); + if (options['C']) { + echo(c); + } LoadChar(c); if (c == '/') { - if (options['C']) echo(c); - break; + if (options['C']) { + echo(c); + } + break; } else { PushBack(); } } - else if (options['C']) echo(c); + else if (options['C']) { + echo(c); + } } NoUnstack--; LoadChar(c); @@ -189,7 +202,9 @@ preprocess(fn) nomac: *tg = 0; tg = buf; - while (*tg) echo(*tg++); + while (*tg) { + echo(*tg++); + } LoadChar(c); while (in_idf(c)) { echo(c); From fcc880c8f716f3d8a03569e70932732a687bd1c8 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 7 Jan 1987 17:13:41 +0000 Subject: [PATCH 0432/1625] Initial revision --- mach/pdp/libsys/LIST | 81 +++++++++++++++++++++++++++++++ mach/pdp/libsys/Makefile | 25 ++++++++++ mach/pdp/libsys/_exit.s | 6 +++ mach/pdp/libsys/access.s | 17 +++++++ mach/pdp/libsys/acct.s | 17 +++++++ mach/pdp/libsys/alarm.s | 12 +++++ mach/pdp/libsys/chdir.s | 17 +++++++ mach/pdp/libsys/chmod.s | 18 +++++++ mach/pdp/libsys/chown.s | 19 ++++++++ mach/pdp/libsys/chroot.s | 17 +++++++ mach/pdp/libsys/cleanup.c | 3 ++ mach/pdp/libsys/close.s | 14 ++++++ mach/pdp/libsys/compmodule | 4 ++ mach/pdp/libsys/creat.s | 16 +++++++ mach/pdp/libsys/dup.s | 20 ++++++++ mach/pdp/libsys/errno.s | 3 ++ mach/pdp/libsys/execl.s | 18 +++++++ mach/pdp/libsys/execle.s | 20 ++++++++ mach/pdp/libsys/execv.s | 16 +++++++ mach/pdp/libsys/execve.s | 15 ++++++ mach/pdp/libsys/exit.c | 5 ++ mach/pdp/libsys/fetchi.s | 15 ++++++ mach/pdp/libsys/fork.s | 15 ++++++ mach/pdp/libsys/fperr.s | 20 ++++++++ mach/pdp/libsys/fstat.s | 18 +++++++ mach/pdp/libsys/ftime.s | 11 +++++ mach/pdp/libsys/getgid.s | 12 +++++ mach/pdp/libsys/getgrp.s | 17 +++++++ mach/pdp/libsys/getpid.s | 6 +++ mach/pdp/libsys/getppid.s | 7 +++ mach/pdp/libsys/getuid.s | 12 +++++ mach/pdp/libsys/gldav.s | 17 +++++++ mach/pdp/libsys/gtty.c | 7 +++ mach/pdp/libsys/ioctl.s | 19 ++++++++ mach/pdp/libsys/kill.s | 19 ++++++++ mach/pdp/libsys/killbkg.s | 18 +++++++ mach/pdp/libsys/killpg.s | 19 ++++++++ mach/pdp/libsys/link.s | 18 +++++++ mach/pdp/libsys/lock.s | 15 ++++++ mach/pdp/libsys/login.s | 19 ++++++++ mach/pdp/libsys/lseek.s | 19 ++++++++ mach/pdp/libsys/lstat.s | 18 +++++++ mach/pdp/libsys/mknod.s | 19 ++++++++ mach/pdp/libsys/mount.s | 19 ++++++++ mach/pdp/libsys/mpxcall.s | 17 +++++++ mach/pdp/libsys/nice.s | 14 ++++++ mach/pdp/libsys/nostk.s | 9 ++++ mach/pdp/libsys/open.s | 16 +++++++ mach/pdp/libsys/pause.s | 6 +++ mach/pdp/libsys/phys.s | 18 +++++++ mach/pdp/libsys/pipe.s | 18 +++++++ mach/pdp/libsys/profil.s | 13 +++++ mach/pdp/libsys/ptrace.s | 20 ++++++++ mach/pdp/libsys/qfstat.s | 18 +++++++ mach/pdp/libsys/qstat.s | 18 +++++++ mach/pdp/libsys/quota.s | 21 +++++++++ mach/pdp/libsys/read.s | 17 +++++++ mach/pdp/libsys/readlink.s | 17 +++++++ mach/pdp/libsys/reboot.s | 18 +++++++ mach/pdp/libsys/renice.s | 18 +++++++ mach/pdp/libsys/rtp.s | 14 ++++++ mach/pdp/libsys/sbrk.s | 38 +++++++++++++++ mach/pdp/libsys/setgid.s | 14 ++++++ mach/pdp/libsys/setgrp.s | 17 +++++++ mach/pdp/libsys/setuid.s | 14 ++++++ mach/pdp/libsys/signal.s | 88 ++++++++++++++++++++++++++++++++++ mach/pdp/libsys/stat.s | 18 +++++++ mach/pdp/libsys/stime.s | 16 +++++++ mach/pdp/libsys/stty.c | 7 +++ mach/pdp/libsys/submit.s | 15 ++++++ mach/pdp/libsys/symlink.s | 18 +++++++ mach/pdp/libsys/sync.s | 6 +++ mach/pdp/libsys/sys.h | 97 ++++++++++++++++++++++++++++++++++++++ mach/pdp/libsys/time.s | 13 +++++ mach/pdp/libsys/times.s | 10 ++++ mach/pdp/libsys/ucall.s | 13 +++++ mach/pdp/libsys/umask.s | 15 ++++++ mach/pdp/libsys/umount.s | 18 +++++++ mach/pdp/libsys/unlink.s | 17 +++++++ mach/pdp/libsys/utime.s | 18 +++++++ mach/pdp/libsys/vfork.s | 18 +++++++ mach/pdp/libsys/vhangup.s | 14 ++++++ mach/pdp/libsys/wait.s | 16 +++++++ mach/pdp/libsys/write.s | 17 +++++++ 84 files changed, 1511 insertions(+) create mode 100644 mach/pdp/libsys/LIST create mode 100644 mach/pdp/libsys/Makefile create mode 100644 mach/pdp/libsys/_exit.s create mode 100644 mach/pdp/libsys/access.s create mode 100644 mach/pdp/libsys/acct.s create mode 100644 mach/pdp/libsys/alarm.s create mode 100644 mach/pdp/libsys/chdir.s create mode 100644 mach/pdp/libsys/chmod.s create mode 100644 mach/pdp/libsys/chown.s create mode 100644 mach/pdp/libsys/chroot.s create mode 100644 mach/pdp/libsys/cleanup.c create mode 100644 mach/pdp/libsys/close.s create mode 100755 mach/pdp/libsys/compmodule create mode 100644 mach/pdp/libsys/creat.s create mode 100644 mach/pdp/libsys/dup.s create mode 100644 mach/pdp/libsys/errno.s create mode 100644 mach/pdp/libsys/execl.s create mode 100644 mach/pdp/libsys/execle.s create mode 100644 mach/pdp/libsys/execv.s create mode 100644 mach/pdp/libsys/execve.s create mode 100644 mach/pdp/libsys/exit.c create mode 100644 mach/pdp/libsys/fetchi.s create mode 100644 mach/pdp/libsys/fork.s create mode 100644 mach/pdp/libsys/fperr.s create mode 100644 mach/pdp/libsys/fstat.s create mode 100644 mach/pdp/libsys/ftime.s create mode 100644 mach/pdp/libsys/getgid.s create mode 100644 mach/pdp/libsys/getgrp.s create mode 100644 mach/pdp/libsys/getpid.s create mode 100644 mach/pdp/libsys/getppid.s create mode 100644 mach/pdp/libsys/getuid.s create mode 100644 mach/pdp/libsys/gldav.s create mode 100644 mach/pdp/libsys/gtty.c create mode 100644 mach/pdp/libsys/ioctl.s create mode 100644 mach/pdp/libsys/kill.s create mode 100644 mach/pdp/libsys/killbkg.s create mode 100644 mach/pdp/libsys/killpg.s create mode 100644 mach/pdp/libsys/link.s create mode 100644 mach/pdp/libsys/lock.s create mode 100644 mach/pdp/libsys/login.s create mode 100644 mach/pdp/libsys/lseek.s create mode 100644 mach/pdp/libsys/lstat.s create mode 100644 mach/pdp/libsys/mknod.s create mode 100644 mach/pdp/libsys/mount.s create mode 100644 mach/pdp/libsys/mpxcall.s create mode 100644 mach/pdp/libsys/nice.s create mode 100644 mach/pdp/libsys/nostk.s create mode 100644 mach/pdp/libsys/open.s create mode 100644 mach/pdp/libsys/pause.s create mode 100644 mach/pdp/libsys/phys.s create mode 100644 mach/pdp/libsys/pipe.s create mode 100644 mach/pdp/libsys/profil.s create mode 100644 mach/pdp/libsys/ptrace.s create mode 100644 mach/pdp/libsys/qfstat.s create mode 100644 mach/pdp/libsys/qstat.s create mode 100644 mach/pdp/libsys/quota.s create mode 100644 mach/pdp/libsys/read.s create mode 100644 mach/pdp/libsys/readlink.s create mode 100644 mach/pdp/libsys/reboot.s create mode 100644 mach/pdp/libsys/renice.s create mode 100644 mach/pdp/libsys/rtp.s create mode 100644 mach/pdp/libsys/sbrk.s create mode 100644 mach/pdp/libsys/setgid.s create mode 100644 mach/pdp/libsys/setgrp.s create mode 100644 mach/pdp/libsys/setuid.s create mode 100644 mach/pdp/libsys/signal.s create mode 100644 mach/pdp/libsys/stat.s create mode 100644 mach/pdp/libsys/stime.s create mode 100644 mach/pdp/libsys/stty.c create mode 100644 mach/pdp/libsys/submit.s create mode 100644 mach/pdp/libsys/symlink.s create mode 100644 mach/pdp/libsys/sync.s create mode 100644 mach/pdp/libsys/sys.h create mode 100644 mach/pdp/libsys/time.s create mode 100644 mach/pdp/libsys/times.s create mode 100644 mach/pdp/libsys/ucall.s create mode 100644 mach/pdp/libsys/umask.s create mode 100644 mach/pdp/libsys/umount.s create mode 100644 mach/pdp/libsys/unlink.s create mode 100644 mach/pdp/libsys/utime.s create mode 100644 mach/pdp/libsys/vfork.s create mode 100644 mach/pdp/libsys/vhangup.s create mode 100644 mach/pdp/libsys/wait.s create mode 100644 mach/pdp/libsys/write.s diff --git a/mach/pdp/libsys/LIST b/mach/pdp/libsys/LIST new file mode 100644 index 00000000..0db8f411 --- /dev/null +++ b/mach/pdp/libsys/LIST @@ -0,0 +1,81 @@ +tail_mon.a +exit.c +cleanup.c +stty.c +gtty.c +_exit.s +access.s +acct.s +alarm.s +chdir.s +chmod.s +chown.s +chroot.s +close.s +creat.s +dup.s +execl.s +execle.s +execv.s +execve.s +fetchi.s +fork.s +fperr.s +fstat.s +ftime.s +getgid.s +getgrp.s +getpid.s +getppid.s +getuid.s +gldav.s +ioctl.s +kill.s +killbkg.s +killpg.s +link.s +lock.s +login.s +lseek.s +lstat.s +mknod.s +mount.s +mpxcall.s +nice.s +nostk.s +open.s +pause.s +phys.s +pipe.s +profil.s +ptrace.s +qfstat.s +qstat.s +quota.s +read.s +readlink.s +reboot.s +renice.s +rtp.s +sbrk.s +setgid.s +setgrp.s +setuid.s +signal.s +stat.s +stime.s +submit.s +symlink.s +sync.s +time.s +times.s +ucall.s +umask.s +umount.s +unlink.s +utime.s +vfork.s +vhangup.s +wait.s +write.s +errno.s diff --git a/mach/pdp/libsys/Makefile b/mach/pdp/libsys/Makefile new file mode 100644 index 00000000..733850b9 --- /dev/null +++ b/mach/pdp/libsys/Makefile @@ -0,0 +1,25 @@ +# $Header$ +install: cp + +cp: all + ../../install tail_mon + rm -f head_em tail_mon + +cmp: all + -../../compare tail_mon + rm -f head_em tail_mon + +all: tail_mon + +tail_mon: + ASAR=ar ; export ASAR ;\ + RANLIB=ranlib ; export RANLIB ;\ + march . tail_mon + +clean: + rm -f *.o +opr: + make pr | opr +pr: + @pr `pwd`/Makefile `pwd`/head_em.s + @pr -l33 `tail +1 LIST|sort` diff --git a/mach/pdp/libsys/_exit.s b/mach/pdp/libsys/_exit.s new file mode 100644 index 00000000..c98b1886 --- /dev/null +++ b/mach/pdp/libsys/_exit.s @@ -0,0 +1,6 @@ +#include "sys.h" +.globl __exit + +__exit: + mov 2(sp),r0 + sys exit diff --git a/mach/pdp/libsys/access.s b/mach/pdp/libsys/access.s new file mode 100644 index 00000000..a355d0a6 --- /dev/null +++ b/mach/pdp/libsys/access.s @@ -0,0 +1,17 @@ +#include "sys.h" +.globl _access +.globl _errno + +_access: + mov 2(sp),0f+2 + mov 4(sp),0f+4 + clr r0 + sys indir; 0f + bec 1f + mov r0,_errno + mov $-1,r0 +1: + rts pc +.data +0: + sys access; ..; .. diff --git a/mach/pdp/libsys/acct.s b/mach/pdp/libsys/acct.s new file mode 100644 index 00000000..de948c45 --- /dev/null +++ b/mach/pdp/libsys/acct.s @@ -0,0 +1,17 @@ +#include "sys.h" +.globl _acct +.globl _errno + +_acct: + mov 2(sp),0f+2 + sys indir; 0f + bec 1f + mov r0, _errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc +.data +0: + sys acct; .. diff --git a/mach/pdp/libsys/alarm.s b/mach/pdp/libsys/alarm.s new file mode 100644 index 00000000..ef2de4e3 --- /dev/null +++ b/mach/pdp/libsys/alarm.s @@ -0,0 +1,12 @@ +#include "sys.h" +.globl _alarm +.globl _errno + +_alarm: + mov 2(sp),r0 + sys alarm + bec 1f + mov r0,_errno + mov $-1,r0 +1: + rts pc diff --git a/mach/pdp/libsys/chdir.s b/mach/pdp/libsys/chdir.s new file mode 100644 index 00000000..a184b79f --- /dev/null +++ b/mach/pdp/libsys/chdir.s @@ -0,0 +1,17 @@ +#include "sys.h" +.globl _chdir +.globl _errno + +_chdir: + mov 2(sp),0f+2 + sys indir; 0f + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc +.data +0: + sys chdir; .. diff --git a/mach/pdp/libsys/chmod.s b/mach/pdp/libsys/chmod.s new file mode 100644 index 00000000..7cfaed48 --- /dev/null +++ b/mach/pdp/libsys/chmod.s @@ -0,0 +1,18 @@ +#include "sys.h" +.globl _chmod +.globl _errno + +_chmod: + mov 2(sp),0f+2 + mov 4(sp),0f+4 + sys indir; 0f + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc +.data +0: + sys chmod; ..; .. diff --git a/mach/pdp/libsys/chown.s b/mach/pdp/libsys/chown.s new file mode 100644 index 00000000..81377caa --- /dev/null +++ b/mach/pdp/libsys/chown.s @@ -0,0 +1,19 @@ +#include "sys.h" +.globl _chown +.globl _errno + +_chown: + mov 2(sp),0f+2 + mov 4(sp),0f+4 + mov 6(sp),0f+6 + sys indir; 0f + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc +.data +0: + sys chown; ..; ..; .. diff --git a/mach/pdp/libsys/chroot.s b/mach/pdp/libsys/chroot.s new file mode 100644 index 00000000..7e77a121 --- /dev/null +++ b/mach/pdp/libsys/chroot.s @@ -0,0 +1,17 @@ +#include "sys.h" +.globl _chroot +.globl _errno + +_chroot: + mov 2(sp),0f+2 + sys indir; 0f + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc +.data +0: + sys chroot; .. diff --git a/mach/pdp/libsys/cleanup.c b/mach/pdp/libsys/cleanup.c new file mode 100644 index 00000000..07d507e3 --- /dev/null +++ b/mach/pdp/libsys/cleanup.c @@ -0,0 +1,3 @@ +_cleanup() +{ +} diff --git a/mach/pdp/libsys/close.s b/mach/pdp/libsys/close.s new file mode 100644 index 00000000..4c8e55fa --- /dev/null +++ b/mach/pdp/libsys/close.s @@ -0,0 +1,14 @@ +#include "sys.h" +.globl _close +.globl _errno + +_close: + mov 2(sp),r0 + sys close + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc diff --git a/mach/pdp/libsys/compmodule b/mach/pdp/libsys/compmodule new file mode 100755 index 00000000..32b04832 --- /dev/null +++ b/mach/pdp/libsys/compmodule @@ -0,0 +1,4 @@ +if pdp -O -c -I../../../h -I. $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 +fi diff --git a/mach/pdp/libsys/creat.s b/mach/pdp/libsys/creat.s new file mode 100644 index 00000000..32a74e5e --- /dev/null +++ b/mach/pdp/libsys/creat.s @@ -0,0 +1,16 @@ +#include "sys.h" +.globl _creat +.globl _errno + +_creat: + mov 2(sp),0f+2 + mov 4(sp),0f+4 + sys indir; 0f + bec 1f + mov r0,_errno + mov $-1,r0 +1: + rts pc +.data +0: + sys creat; ..; .. diff --git a/mach/pdp/libsys/dup.s b/mach/pdp/libsys/dup.s new file mode 100644 index 00000000..12b9a49c --- /dev/null +++ b/mach/pdp/libsys/dup.s @@ -0,0 +1,20 @@ +#include "sys.h" +.globl _dup +.globl _dup2 +.globl _errno + +_dup2: + mov 2(sp),r0 + bis $100,r0 + br 1f + +_dup: + mov 2(sp),r0 +1: + mov 4(sp),r1 + sys dup + bec 1f + mov r0,_errno + mov $-1,r0 +1: + rts pc diff --git a/mach/pdp/libsys/errno.s b/mach/pdp/libsys/errno.s new file mode 100644 index 00000000..9dbf81df --- /dev/null +++ b/mach/pdp/libsys/errno.s @@ -0,0 +1,3 @@ +.globl _errno +.bss +_errno: .=.+2 diff --git a/mach/pdp/libsys/execl.s b/mach/pdp/libsys/execl.s new file mode 100644 index 00000000..13607bae --- /dev/null +++ b/mach/pdp/libsys/execl.s @@ -0,0 +1,18 @@ +#include "sys.h" +.globl _execl +.globl _environ +.globl _errno + +_execl: + mov 2(sp),0f+2 + mov sp,r0 + add $4,r0 + mov r0,0f+4 + mov _environ,0f+6 + sys indir; 0f + mov r0,_errno + mov $-1,r0 + rts pc +.data +0: + sys exece; ..; ..; .. diff --git a/mach/pdp/libsys/execle.s b/mach/pdp/libsys/execle.s new file mode 100644 index 00000000..8e7cc1bc --- /dev/null +++ b/mach/pdp/libsys/execle.s @@ -0,0 +1,20 @@ +#include "sys.h" +.globl _execle +.globl _errno + +_execle: + mov 2(sp),0f+2 + mov sp,r0 + add $4,r0 + mov r0,0f+4 +1: + tst (r0)+ + bne 1b + mov (r0),0f+6 + sys indir; 0f + mov r0,_errno + mov $-1,r0 + rts pc +.data +0: + sys exece; ..; ..; .. diff --git a/mach/pdp/libsys/execv.s b/mach/pdp/libsys/execv.s new file mode 100644 index 00000000..f8de47e7 --- /dev/null +++ b/mach/pdp/libsys/execv.s @@ -0,0 +1,16 @@ +#include "sys.h" +.globl _execv, +.globl _environ +.globl _errno + +_execv: + mov 2(sp),0f+2 + mov 4(sp),0f+4 + mov _environ,0f+6 + sys indir; 0f + mov r0,_errno + mov $-1,r0 + rts pc +.data +0: + sys exece; ..; ..; .. diff --git a/mach/pdp/libsys/execve.s b/mach/pdp/libsys/execve.s new file mode 100644 index 00000000..98292c45 --- /dev/null +++ b/mach/pdp/libsys/execve.s @@ -0,0 +1,15 @@ +#include "sys.h" +.globl _execve +.globl _errno + +_execve: + mov 2(sp),0f+2 + mov 4(sp),0f+4 + mov 6(sp),0f+6 + sys indir; 0f + mov r0,_errno + mov $-1,r0 + rts pc +.data +0: + sys exece; ..; ..; .. diff --git a/mach/pdp/libsys/exit.c b/mach/pdp/libsys/exit.c new file mode 100644 index 00000000..afd54b3f --- /dev/null +++ b/mach/pdp/libsys/exit.c @@ -0,0 +1,5 @@ +exit(n) +{ + _cleanup(); + _exit(n); +} diff --git a/mach/pdp/libsys/fetchi.s b/mach/pdp/libsys/fetchi.s new file mode 100644 index 00000000..c9306739 --- /dev/null +++ b/mach/pdp/libsys/fetchi.s @@ -0,0 +1,15 @@ +#include "sys.h" +.globl _fetchi +.globl _errno + +_fetchi: + mov 2(sp),r0 + sys local; 0f + bec 1f + mov r0,_errno + mov $-1,r0 +1: + rts pc +.data +0: + sys fetchi diff --git a/mach/pdp/libsys/fork.s b/mach/pdp/libsys/fork.s new file mode 100644 index 00000000..f549cfe9 --- /dev/null +++ b/mach/pdp/libsys/fork.s @@ -0,0 +1,15 @@ +#include "sys.h" +.globl _fork +.globl _errno + +_fork: + sys fork + br 1f + bec 2f + mov r0,_errno + mov $-1,r0 +2: + rts pc +1: + clr r0 + rts pc diff --git a/mach/pdp/libsys/fperr.s b/mach/pdp/libsys/fperr.s new file mode 100644 index 00000000..d0f20421 --- /dev/null +++ b/mach/pdp/libsys/fperr.s @@ -0,0 +1,20 @@ +#include "sys.h" +.globl _fperr +.globl _errno + +_fperr: + sys local; 0f + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + mov r5,-(sp) + mov 4(sp),r5 + mov r0,(r5)+ + mov r1,(r5) + mov (sp)+,r5 + rts pc +.data +0: + sys fperr diff --git a/mach/pdp/libsys/fstat.s b/mach/pdp/libsys/fstat.s new file mode 100644 index 00000000..b1bff51f --- /dev/null +++ b/mach/pdp/libsys/fstat.s @@ -0,0 +1,18 @@ +#include "sys.h" +.globl _fstat +.globl _errno + +_fstat: + mov 2(sp),r0 + mov 4(sp),0f+2 + sys indir; 0f + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc +.data +0: + sys fstat; .. diff --git a/mach/pdp/libsys/ftime.s b/mach/pdp/libsys/ftime.s new file mode 100644 index 00000000..c29924dd --- /dev/null +++ b/mach/pdp/libsys/ftime.s @@ -0,0 +1,11 @@ +#include "sys.h" +.globl _ftime + +_ftime: + mov 2(sp),0f+2 + sys indir; 0f + rts pc + +.data +0: + sys ftime; .. diff --git a/mach/pdp/libsys/getgid.s b/mach/pdp/libsys/getgid.s new file mode 100644 index 00000000..8faaf9fa --- /dev/null +++ b/mach/pdp/libsys/getgid.s @@ -0,0 +1,12 @@ +#include "sys.h" +.globl _getgid +.globl _getegid + +_getgid: + sys getgid + rts pc + +_getegid: + sys getgid + mov r1,r0 + rts pc diff --git a/mach/pdp/libsys/getgrp.s b/mach/pdp/libsys/getgrp.s new file mode 100644 index 00000000..d4c059eb --- /dev/null +++ b/mach/pdp/libsys/getgrp.s @@ -0,0 +1,17 @@ +#include "sys.h" +.globl _getgrp +.globl _errno + +_getgrp: + mov 2(sp),0f+2 + sys indir; 0f + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc +.data +0: + sys getgrp; .. diff --git a/mach/pdp/libsys/getpid.s b/mach/pdp/libsys/getpid.s new file mode 100644 index 00000000..54aa094f --- /dev/null +++ b/mach/pdp/libsys/getpid.s @@ -0,0 +1,6 @@ +#include "sys.h" +.globl _getpid + +_getpid: + sys getpid + rts pc diff --git a/mach/pdp/libsys/getppid.s b/mach/pdp/libsys/getppid.s new file mode 100644 index 00000000..8af5c2b1 --- /dev/null +++ b/mach/pdp/libsys/getppid.s @@ -0,0 +1,7 @@ +#include "sys.h" +.globl _getppid + +_getppid: + sys getpid + mov r1,r0 + rts pc diff --git a/mach/pdp/libsys/getuid.s b/mach/pdp/libsys/getuid.s new file mode 100644 index 00000000..2b8db794 --- /dev/null +++ b/mach/pdp/libsys/getuid.s @@ -0,0 +1,12 @@ +#include "sys.h" +.globl _getuid +.globl _geteuid + +_getuid: + sys getuid + rts pc + +_geteuid: + sys getuid + mov r1,r0 + rts pc diff --git a/mach/pdp/libsys/gldav.s b/mach/pdp/libsys/gldav.s new file mode 100644 index 00000000..c6db2d13 --- /dev/null +++ b/mach/pdp/libsys/gldav.s @@ -0,0 +1,17 @@ +#include "sys.h" +.globl _gldav +.globl _errno + +_gldav: + mov 2(sp),r0 + sys local; 0f + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc +.data +0: + sys gldav diff --git a/mach/pdp/libsys/gtty.c b/mach/pdp/libsys/gtty.c new file mode 100644 index 00000000..7f42ea1f --- /dev/null +++ b/mach/pdp/libsys/gtty.c @@ -0,0 +1,7 @@ +#include +int gtty(fildes,argp) + int fildes ; + struct sgttyb *argp ; +{ + return ioctl(fildes,TIOCGETP,argp) ; +} diff --git a/mach/pdp/libsys/ioctl.s b/mach/pdp/libsys/ioctl.s new file mode 100644 index 00000000..95e2474e --- /dev/null +++ b/mach/pdp/libsys/ioctl.s @@ -0,0 +1,19 @@ +#include "sys.h" +.globl _ioctl +.globl _errno + +_ioctl: + mov 2(sp),0f+2 + mov 4(sp),0f+4 + mov 6(sp),0f+6 + sys indir; 0f + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc +.data +0: + sys ioctl; ..; ..; .. diff --git a/mach/pdp/libsys/kill.s b/mach/pdp/libsys/kill.s new file mode 100644 index 00000000..d96fbf69 --- /dev/null +++ b/mach/pdp/libsys/kill.s @@ -0,0 +1,19 @@ +#include "sys.h" +.globl _kill +.globl _errno + +_kill: + mov 2(sp),r0 + mov 4(sp),0f+2 + sys indir; 0f + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc + +.data +0: + sys kill; .. diff --git a/mach/pdp/libsys/killbkg.s b/mach/pdp/libsys/killbkg.s new file mode 100644 index 00000000..edfcae27 --- /dev/null +++ b/mach/pdp/libsys/killbkg.s @@ -0,0 +1,18 @@ +#include "sys.h" +.globl _killbkg +.globl _errno + +_killbkg: + mov 2(sp),0f+2 + mov 4(sp),0f+4 + sys local; 0f + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc +.data +0: + sys killbkg; ..; .. diff --git a/mach/pdp/libsys/killpg.s b/mach/pdp/libsys/killpg.s new file mode 100644 index 00000000..99509668 --- /dev/null +++ b/mach/pdp/libsys/killpg.s @@ -0,0 +1,19 @@ +#include "sys.h" +.globl _killpg +.globl _errno + +_killpg: + mov 2(sp),0f+2 + mov 4(sp),0f+4 + sys local; 0f + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc + +.data +0: + sys killpg; ..; .. diff --git a/mach/pdp/libsys/link.s b/mach/pdp/libsys/link.s new file mode 100644 index 00000000..1a0e3489 --- /dev/null +++ b/mach/pdp/libsys/link.s @@ -0,0 +1,18 @@ +#include "sys.h" +.globl _link +.globl _errno + +_link: + mov 2(sp),0f+2 + mov 4(sp),0f+4 + sys indir; 0f + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc +.data +0: + sys link; ..; .. diff --git a/mach/pdp/libsys/lock.s b/mach/pdp/libsys/lock.s new file mode 100644 index 00000000..fdd63e8e --- /dev/null +++ b/mach/pdp/libsys/lock.s @@ -0,0 +1,15 @@ +#include "sys.h" +.globl _lock +.globl _errno + +_lock: + mov 2(sp),0f+2 + sys indir; 0f + bec 1f + mov r0,_errno + mov $-1,r0 +1: + rts pc +.data +0: + sys lock; .. diff --git a/mach/pdp/libsys/login.s b/mach/pdp/libsys/login.s new file mode 100644 index 00000000..d79d0d9f --- /dev/null +++ b/mach/pdp/libsys/login.s @@ -0,0 +1,19 @@ +#include "sys.h" +.globl _login +.globl _errno + +_login: + mov 2(sp),0f+2 + mov 4(sp),0f+4 + mov 6(sp),0f+6 + sys local; 0f + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc +.data +0: + sys login; ..; ..; ..; diff --git a/mach/pdp/libsys/lseek.s b/mach/pdp/libsys/lseek.s new file mode 100644 index 00000000..c2c36b58 --- /dev/null +++ b/mach/pdp/libsys/lseek.s @@ -0,0 +1,19 @@ +#include "sys.h" +.globl _lseek +.globl _errno + +_lseek: + mov 2(sp),r0 + mov 4(sp),0f+2 + mov 6(sp),0f+4 + mov 10(sp),0f+6 + sys indir; 0f + bec 1f + mov $-1,r1 + mov r0,_errno + mov $-1,r0 +1: + rts pc +.data +0: + sys lseek; ..; ..; .. diff --git a/mach/pdp/libsys/lstat.s b/mach/pdp/libsys/lstat.s new file mode 100644 index 00000000..72276804 --- /dev/null +++ b/mach/pdp/libsys/lstat.s @@ -0,0 +1,18 @@ +#include "sys.h" +.globl _lstat +.globl _errno + +_lstat: + mov 2(sp),0f+2 + mov 4(sp),0f+4 + sys local; 0f + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc +.data +0: + sys lstat; ..; .. diff --git a/mach/pdp/libsys/mknod.s b/mach/pdp/libsys/mknod.s new file mode 100644 index 00000000..be7dce3b --- /dev/null +++ b/mach/pdp/libsys/mknod.s @@ -0,0 +1,19 @@ +#include "sys.h" +.globl _mknod +.globl _errno + +_mknod: + mov 2(sp),0f+2 + mov 4(sp),0f+4 + mov 6(sp),0f+6 + sys indir; 0f + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc +.data +0: + sys mknod; ..; ..; .. diff --git a/mach/pdp/libsys/mount.s b/mach/pdp/libsys/mount.s new file mode 100644 index 00000000..31338e35 --- /dev/null +++ b/mach/pdp/libsys/mount.s @@ -0,0 +1,19 @@ +#include "sys.h" +.globl _mount +.globl _errno + +_mount: + mov 2(sp),0f+2 + mov 4(sp),0f+4 + mov 6(sp),0f+6 + sys indir; 0f + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc +.data +0: + sys mount; ..; ..; .. diff --git a/mach/pdp/libsys/mpxcall.s b/mach/pdp/libsys/mpxcall.s new file mode 100644 index 00000000..ab1a85c3 --- /dev/null +++ b/mach/pdp/libsys/mpxcall.s @@ -0,0 +1,17 @@ +#include "sys.h" +.globl _mpxcall +.globl _errno + +_mpxcall: + mov 2(sp),0f+2 + mov 4(sp),0f+4 + sys indir; 0f + bec 1f + mov r0,_errno + mov $-1,r0 +1: + rts pc +.data +0: + sys mpx; ..; .. + diff --git a/mach/pdp/libsys/nice.s b/mach/pdp/libsys/nice.s new file mode 100644 index 00000000..2a0b033a --- /dev/null +++ b/mach/pdp/libsys/nice.s @@ -0,0 +1,14 @@ +#include "sys.h" +.globl _nice +.globl _errno + +_nice: + mov 2(sp),r0 + sys nice + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc diff --git a/mach/pdp/libsys/nostk.s b/mach/pdp/libsys/nostk.s new file mode 100644 index 00000000..4421c72a --- /dev/null +++ b/mach/pdp/libsys/nostk.s @@ -0,0 +1,9 @@ +#include "sys.h" +.globl _nostk + +_nostk: + sys local; 0f + rts pc +.data: +0: + sys nostk diff --git a/mach/pdp/libsys/open.s b/mach/pdp/libsys/open.s new file mode 100644 index 00000000..6e7d8c90 --- /dev/null +++ b/mach/pdp/libsys/open.s @@ -0,0 +1,16 @@ +#include "sys.h" +.globl _open +.globl _errno + +_open: + mov 2(sp),0f+2 + mov 4(sp),0f+4 + sys indir; 0f + bec 1f + mov r0,_errno + mov $-1,r0 +1: + rts pc +.data +0: + sys open; ..; .. diff --git a/mach/pdp/libsys/pause.s b/mach/pdp/libsys/pause.s new file mode 100644 index 00000000..da11a626 --- /dev/null +++ b/mach/pdp/libsys/pause.s @@ -0,0 +1,6 @@ +#include "sys.h" +.globl _pause + +_pause: + sys pause + rts pc diff --git a/mach/pdp/libsys/phys.s b/mach/pdp/libsys/phys.s new file mode 100644 index 00000000..04740cda --- /dev/null +++ b/mach/pdp/libsys/phys.s @@ -0,0 +1,18 @@ +#include "sys.h" +.globl _phys +.globl _errno + +_phys: + mov 2(sp),0f+2 + mov 4(sp),0f+4 + mov 6(sp),0f+6 + sys indir; 0f + bec 1f + mov r0,_errno + mov $-1,r0 +1: + rts pc + +.data +0: + sys phys; ..; ..; .. diff --git a/mach/pdp/libsys/pipe.s b/mach/pdp/libsys/pipe.s new file mode 100644 index 00000000..be017ab7 --- /dev/null +++ b/mach/pdp/libsys/pipe.s @@ -0,0 +1,18 @@ +#include "sys.h" +.globl _pipe +.globl _errno + +_pipe: + sys pipe + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + mov r5,-(sp) + mov 4(sp),r5 + mov r0,(r5)+ + mov r1,(r5) + mov (sp)+,r5 + clr r0 + rts pc diff --git a/mach/pdp/libsys/profil.s b/mach/pdp/libsys/profil.s new file mode 100644 index 00000000..28864242 --- /dev/null +++ b/mach/pdp/libsys/profil.s @@ -0,0 +1,13 @@ +#include "sys.h" +.globl _profil + +_profil: + mov 2(sp),0f+2 + mov 4(sp),0f+4 + mov 6(sp),0f+6 + mov 10(sp),0f+10 + sys indir; 0f + rts pc +.data +0: + sys profil; ..; ..; ..; .. diff --git a/mach/pdp/libsys/ptrace.s b/mach/pdp/libsys/ptrace.s new file mode 100644 index 00000000..1dd598a4 --- /dev/null +++ b/mach/pdp/libsys/ptrace.s @@ -0,0 +1,20 @@ +#include "sys.h" +.globl _ptrace +.globl _errno + +_ptrace: + mov 2(sp),0f+6 + mov 4(sp),0f+2 + mov 6(sp),0f+4 + mov 10(sp),r0 + clr _errno + sys indir; 9f + bec 1f + mov r0,_errno + mov $-1,r0 +1: + rts pc + +.data +0: + sys ptrace; ..; ..; .. diff --git a/mach/pdp/libsys/qfstat.s b/mach/pdp/libsys/qfstat.s new file mode 100644 index 00000000..affcb508 --- /dev/null +++ b/mach/pdp/libsys/qfstat.s @@ -0,0 +1,18 @@ +#include "sys.h" +.globl _qfstat +.globl _errno + +_qfstat: + mov 2(sp),r0 + mov 4(sp),0f+2 + sys local; 0f + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc +.data +0: + sys qfstat; .. diff --git a/mach/pdp/libsys/qstat.s b/mach/pdp/libsys/qstat.s new file mode 100644 index 00000000..d5143f3b --- /dev/null +++ b/mach/pdp/libsys/qstat.s @@ -0,0 +1,18 @@ +#include "sys.h" +.globl _qstat +.globl _errno + +_qstat: + mov 2(sp),0f+2 + mov 4(sp),0f+4 + sys local; 0f + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc +.data +0: + sys qstat; ..; .. diff --git a/mach/pdp/libsys/quota.s b/mach/pdp/libsys/quota.s new file mode 100644 index 00000000..89ef1095 --- /dev/null +++ b/mach/pdp/libsys/quota.s @@ -0,0 +1,21 @@ +#include "sys.h" +.globl _quota +.globl _errno + +_quota: + mov 2(sp),0f+2 + mov 4(sp),0f+4 + mov 6(sp),0f+6 + mov 10(sp),0f+10 + mov 12(sp),0f+12 + sys local; 0f + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc +.data +0: + sys quota; ..; ..; ..; ..; .. diff --git a/mach/pdp/libsys/read.s b/mach/pdp/libsys/read.s new file mode 100644 index 00000000..f89a36e0 --- /dev/null +++ b/mach/pdp/libsys/read.s @@ -0,0 +1,17 @@ +#include "sys.h" +.globl _read +.globl _errno + +_read: + mov 2(sp),r0 + mov 4(sp),0f+2 + mov 6(sp),0f+4 + sys indir; 0f + bec 1f + mov r0,_errno + mov $-1,r0 +1: + rts pc +.data +0: + sys read; ..; .. diff --git a/mach/pdp/libsys/readlink.s b/mach/pdp/libsys/readlink.s new file mode 100644 index 00000000..72c2f9dc --- /dev/null +++ b/mach/pdp/libsys/readlink.s @@ -0,0 +1,17 @@ +#include "sys.h" +.globl _readlink +.globl _errno + +_readlink: + mov 2(sp),r0 + mov 4(sp),0f+2 + mov 6(sp),0f+4 + sys local; 0f + bec 1f + mov r0,_errno + mov $-1,r0 +1: + rts pc +.data +0: + sys readlink; ..; .. diff --git a/mach/pdp/libsys/reboot.s b/mach/pdp/libsys/reboot.s new file mode 100644 index 00000000..bef5ab28 --- /dev/null +++ b/mach/pdp/libsys/reboot.s @@ -0,0 +1,18 @@ +#include "sys.h" +.globl _reboot +.globl _errno + +_reboot: + mov 2(sp),0f+2 + mov 4(sp),0f+4 + sys indir; 0f + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc +.data +0: + sys reboot; ..; .. diff --git a/mach/pdp/libsys/renice.s b/mach/pdp/libsys/renice.s new file mode 100644 index 00000000..a2e95956 --- /dev/null +++ b/mach/pdp/libsys/renice.s @@ -0,0 +1,18 @@ +#include "sys.h" +.globl _renice +.globl _errno + +_renice: + mov 2(sp),0f+2 + mov 4(sp),0f+4 + sys local; 0f + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc +.data +0: + sys renice; ..; .. diff --git a/mach/pdp/libsys/rtp.s b/mach/pdp/libsys/rtp.s new file mode 100644 index 00000000..5fe3dc29 --- /dev/null +++ b/mach/pdp/libsys/rtp.s @@ -0,0 +1,14 @@ +#include "sys.h" +.globl _rtp +.globl _errno + +_rtp: + mov 2(sp),r0 + sys rtp + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc diff --git a/mach/pdp/libsys/sbrk.s b/mach/pdp/libsys/sbrk.s new file mode 100644 index 00000000..c4b764f7 --- /dev/null +++ b/mach/pdp/libsys/sbrk.s @@ -0,0 +1,38 @@ +#include "sys.h" +.globl _sbrk +.globl _brk +.globl _end +.globl _errno + +_sbrk: + mov 2(sp),0f+2 + beq 1f + add xxx,0f+2 + bcs 2f + sys indir; 0f + bec 1f +2: + mov r0,_errno + mov $-1,r0 + rts pc +1: + mov xxx,r0 + add 2(sp),xxx + rts pc + +_brk: + mov 2(sp),0f+2 + sys indir; 0f + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + mov 2(sp),xxx + clr r0 + rts pc + +.data +0: + sys break; .. +xxx: _end diff --git a/mach/pdp/libsys/setgid.s b/mach/pdp/libsys/setgid.s new file mode 100644 index 00000000..5538f1c6 --- /dev/null +++ b/mach/pdp/libsys/setgid.s @@ -0,0 +1,14 @@ +#include "sys.h" +.globl _setgid +.globl _errno + +_setgid: + mov 2(sp),r0 + sys setgid + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc diff --git a/mach/pdp/libsys/setgrp.s b/mach/pdp/libsys/setgrp.s new file mode 100644 index 00000000..987ba1ac --- /dev/null +++ b/mach/pdp/libsys/setgrp.s @@ -0,0 +1,17 @@ +#include "sys.h" +.globl _setgrp +.globl _errno + +_setgrp: + mov 2(sp),0f+2 + sys indir; 0f + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc +.data +0: + sys setgrp; .. diff --git a/mach/pdp/libsys/setuid.s b/mach/pdp/libsys/setuid.s new file mode 100644 index 00000000..7c7fb4f9 --- /dev/null +++ b/mach/pdp/libsys/setuid.s @@ -0,0 +1,14 @@ +#include "sys.h" +.globl _setuid +.globl _errno + +_setuid: + mov 2(sp),r0 + sys setuid + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc diff --git a/mach/pdp/libsys/signal.s b/mach/pdp/libsys/signal.s new file mode 100644 index 00000000..86633093 --- /dev/null +++ b/mach/pdp/libsys/signal.s @@ -0,0 +1,88 @@ +#include +#include "sys.h" +rtt = 6 +.globl _signal +.globl _errno + +NSIGNALS = 0 +tvect: + jsr r0,1f; NSIGNALS=NSIGNALS+1 + jsr r0,1f; NSIGNALS=NSIGNALS+1 + jsr r0,1f; NSIGNALS=NSIGNALS+1 + jsr r0,1f; NSIGNALS=NSIGNALS+1 + jsr r0,1f; NSIGNALS=NSIGNALS+1 + jsr r0,1f; NSIGNALS=NSIGNALS+1 + jsr r0,1f; NSIGNALS=NSIGNALS+1 + jsr r0,1f; NSIGNALS=NSIGNALS+1 + jsr r0,1f; NSIGNALS=NSIGNALS+1 + jsr r0,1f; NSIGNALS=NSIGNALS+1 + jsr r0,1f; NSIGNALS=NSIGNALS+1 + jsr r0,1f; NSIGNALS=NSIGNALS+1 + jsr r0,1f; NSIGNALS=NSIGNALS+1 + jsr r0,1f; NSIGNALS=NSIGNALS+1 + jsr r0,1f; NSIGNALS=NSIGNALS+1 + jsr r0,1f; NSIGNALS=NSIGNALS+1 + jsr r0,1f; NSIGNALS=NSIGNALS+1 + jsr r0,1f; NSIGNALS=NSIGNALS+1 + jsr r0,1f; NSIGNALS=NSIGNALS+1 + jsr r0,1f; NSIGNALS=NSIGNALS+1 + +1: + mov r1,-(sp) + mov r2,-(sp) + mov r3,-(sp) + mov r4,-(sp) + sub $tvect+4,r0 + asr r0 + mov r0,-(sp) + asr (sp) + jsr pc,*dvect(r0) + tst (sp)+ + mov (sp)+,r4 + mov (sp)+,r3 + mov (sp)+,r2 + mov (sp)+,r1 + mov (sp)+,r0 + rtt + +_signal: + mov r5,-(sp) + mov sp,r5 + mov 4(r5),r1 + cmp r1,$NSIGNALS + bhis 2f + mov 6(r5),r0 + mov r1,0f+2 + asl r1 + mov dvect(r1),-(sp) + mov r0,dvect(r1) + mov r0,0f+4 + beq 1f + bit $1,r0 + bne 1f + asl r1 + add $tvect,r1 + mov r1,0f+4 +1: + sys indir; 0f + bes 3f + bit $1,r0 + beq 1f + mov r0,(sp) +1: + mov (sp)+,r0 + mov (sp)+,r5 + rts pc +2: + mov $EINVAL.,r0 +3: + mov r0,_errno + mov $-1,r0 + mov (sp)+,r5 + rts pc + +.data +0: + sys signal; ..; .. +.bss +dvect: .=.+[NSIGNALS*2] diff --git a/mach/pdp/libsys/stat.s b/mach/pdp/libsys/stat.s new file mode 100644 index 00000000..87cdc05d --- /dev/null +++ b/mach/pdp/libsys/stat.s @@ -0,0 +1,18 @@ +#include "sys.h" +.globl _stat +.globl _errno + +_stat: + mov 2(sp),0f+2 + mov 4(sp),0f+4 + sys indir; 0f + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc +.data +0: + sys stat; ..; .. diff --git a/mach/pdp/libsys/stime.s b/mach/pdp/libsys/stime.s new file mode 100644 index 00000000..3d0172b2 --- /dev/null +++ b/mach/pdp/libsys/stime.s @@ -0,0 +1,16 @@ +#include "sys.h" +.globl _stime +.globl _errno + +_stime: + mov 2(sp),r1 + mov (r1)+,r0 + mov (r1),r1 + sys stime + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc diff --git a/mach/pdp/libsys/stty.c b/mach/pdp/libsys/stty.c new file mode 100644 index 00000000..222310cc --- /dev/null +++ b/mach/pdp/libsys/stty.c @@ -0,0 +1,7 @@ +#include +int stty(fildes,argp) + int fildes ; + struct sgttyb *argp ; +{ + return ioctl(fildes,TIOCSETP,argp) ; +} diff --git a/mach/pdp/libsys/submit.s b/mach/pdp/libsys/submit.s new file mode 100644 index 00000000..089d6e78 --- /dev/null +++ b/mach/pdp/libsys/submit.s @@ -0,0 +1,15 @@ +#include "sys.h" +.globl _submit +.globl _errno + +_submit: + mov 2(sp),r0 + sys local; 0f + bec 1f + mov r0,_errno + mov $-1,r0 +1: + rts pc +.data +0: + sys submit diff --git a/mach/pdp/libsys/symlink.s b/mach/pdp/libsys/symlink.s new file mode 100644 index 00000000..0cce298f --- /dev/null +++ b/mach/pdp/libsys/symlink.s @@ -0,0 +1,18 @@ +#include "sys.h" +.globl _symlink +.globl _errno + +_symlink: + mov 2(sp),r0 + mov 4(sp),0f+2 + sys local; 0f + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc +.data +0: + sys symlink; .. diff --git a/mach/pdp/libsys/sync.s b/mach/pdp/libsys/sync.s new file mode 100644 index 00000000..0ef9ba91 --- /dev/null +++ b/mach/pdp/libsys/sync.s @@ -0,0 +1,6 @@ +#include "sys.h" +.globl _sync + +_sync: + sys sync + rts pc diff --git a/mach/pdp/libsys/sys.h b/mach/pdp/libsys/sys.h new file mode 100644 index 00000000..16898d5f --- /dev/null +++ b/mach/pdp/libsys/sys.h @@ -0,0 +1,97 @@ +#define indir 0. +#define exit 1. +#define fork 2. +#define read 3. +#define write 4. +#define open 5. +#define close 6. +#define wait 7. +#define creat 8. +#define link 9. +#define unlink 10. +#define exec 11. +#define chdir 12. +#define time 13. +#define mknod 14. +#define chmod 15. +#define chown 16. +#define break 17. +#define stat 18. +#define lseek 19. +#define getpid 20. +#define mount 21. +#define umount 22. +#define setuid 23. +#define getuid 24. +#define stime 25. +#define ptrace 26. +#define alarm 27. +#define fstat 28. +#define pause 29. +#define utime 30. +#define smdate 30. +#define stty 31. +#define gtty 32. +#define access 33. +#define nice 34. +#define sleep 35. +#define ftime 35. +#define sync 36. +#define kill 37. +#define csw 38. +#define setpgrp 39. +#define dup 41. +#define pipe 42. +#define times 43. +#define profil 44. +#define getgrp 45. +#define setgid 46. +#define getgid 47. +#define signal 48. +#define rtp 49. +#define setgrp 50. +#define acct 51. +#define phys 52. +#define lock 53. +#define ioctl 54. +#define reboot 55. +#define mpx 56. +#define vfork 57. +#define setinf 59. +#define exece 59. +#define local 58. +#define umask 60. +#define getinf 60. +#define chroot 61. + +#define login 1. +#define lstat 2. +#define submit 3. +#define nostk 4. +#define killbkg 5. +#define killpg 6. +#define renice 7. +#define fetchi 8. +#define ucall 9. +#define quota 10. +#define qfstat 11. +#define qstat 12. +#define gldav 14. +#define fperr 15. +#define vhangup 16. +#define symlink 29. +#define readlink 30. + +#define select 18. +#define gethost 19. +#define sethost 20. +#define socket 21. +#define connect 22. +#define accept 23. +#define send 24. +#define receive 25. +#define socketa 26. +#define setreuid 27. +#define setregid 28. +#define gethstid 31. +#define sethstid 32. diff --git a/mach/pdp/libsys/time.s b/mach/pdp/libsys/time.s new file mode 100644 index 00000000..c545ff8c --- /dev/null +++ b/mach/pdp/libsys/time.s @@ -0,0 +1,13 @@ +#include "sys.h" +.globl _time + +_time: + sys time + mov r5,-(sp) + mov 4(sp),r5 + beq 1f + mov r0,(r5)+ + mov r1,(r5)+ +1: + mov (sp)+,r5 + rts pc diff --git a/mach/pdp/libsys/times.s b/mach/pdp/libsys/times.s new file mode 100644 index 00000000..4b928d7d --- /dev/null +++ b/mach/pdp/libsys/times.s @@ -0,0 +1,10 @@ +#include "sys.h" +.globl _times + +_times: + mov 2(sp),0f+2 + sys indir; 0f + rts pc +.data +0: + sys times; .. diff --git a/mach/pdp/libsys/ucall.s b/mach/pdp/libsys/ucall.s new file mode 100644 index 00000000..09150631 --- /dev/null +++ b/mach/pdp/libsys/ucall.s @@ -0,0 +1,13 @@ +#include "sys.h" +.globl _ucall + +_ucall: + mov 2(sp),0f+2 + mov 4(sp),0f+4 + mov 6(sp),0f+6 + mov 10(sp),0f+10 + sys local; 0f + rts pc +.data +0: + sys ucall; ..; ..; ..; .. diff --git a/mach/pdp/libsys/umask.s b/mach/pdp/libsys/umask.s new file mode 100644 index 00000000..317d02a8 --- /dev/null +++ b/mach/pdp/libsys/umask.s @@ -0,0 +1,15 @@ +#include "sys.h" +.globl _umask +.globl _errno + +_umask: + mov 2(sp),0f+2 + sys indir; 0f + bec 1f + mov r0,_errno + mov $-1,r0 +1: + rts pc +.data +0: + sys umask; .. diff --git a/mach/pdp/libsys/umount.s b/mach/pdp/libsys/umount.s new file mode 100644 index 00000000..ed78e084 --- /dev/null +++ b/mach/pdp/libsys/umount.s @@ -0,0 +1,18 @@ +#include "sys.h" +.globl _umount +.globl _errno + +_umount: + mov 2(sp),0f+2 + sys indir; 0f + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc + +.data +0: + sys umount; .. diff --git a/mach/pdp/libsys/unlink.s b/mach/pdp/libsys/unlink.s new file mode 100644 index 00000000..699ca90e --- /dev/null +++ b/mach/pdp/libsys/unlink.s @@ -0,0 +1,17 @@ +#include "sys.h" +.globl _unlink +.globl _errno + +_unlink: + mov 2(sp),0f+2 + sys indir; 0f + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc +.data +0: + sys unlink; .. diff --git a/mach/pdp/libsys/utime.s b/mach/pdp/libsys/utime.s new file mode 100644 index 00000000..6f4c6a63 --- /dev/null +++ b/mach/pdp/libsys/utime.s @@ -0,0 +1,18 @@ +#include "sys.h" +.globl _utime +.globl _errno + +_utime: + mov 2(sp),0f+2 + mov 4(sp),0f+4 + sys indir; 0f + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + clr r0 + rts pc +.data +0: + sys utime; ..; .. diff --git a/mach/pdp/libsys/vfork.s b/mach/pdp/libsys/vfork.s new file mode 100644 index 00000000..dca86e85 --- /dev/null +++ b/mach/pdp/libsys/vfork.s @@ -0,0 +1,18 @@ +#include "sys.h" +.globl _vfork +.globl _errno + +_vfork: + mov (sp)+,r1 + sys vfork + br 1f + bec 2f +3: mov r0,_errno + mov $-1,r0 + jmp (r1) + +1: / child, or vfork systemcall does not exist + bes 3b + clr r0 +2: + jmp (r1) diff --git a/mach/pdp/libsys/vhangup.s b/mach/pdp/libsys/vhangup.s new file mode 100644 index 00000000..f7cd0256 --- /dev/null +++ b/mach/pdp/libsys/vhangup.s @@ -0,0 +1,14 @@ +#include "sys.h" +.globl _vhangup +.globl _errno + +_vhangup: + sys local; 0f + bec 1f + mov r0,_errno + mov $-1,r0 +1: + rts pc +.data +0: + sys vhangup diff --git a/mach/pdp/libsys/wait.s b/mach/pdp/libsys/wait.s new file mode 100644 index 00000000..cc335a3f --- /dev/null +++ b/mach/pdp/libsys/wait.s @@ -0,0 +1,16 @@ +#include "sys.h" +.globl _wait +.globl _errno + +_wait: + sys wait + bec 1f + mov r0,_errno + mov $-1,r0 + rts pc +1: + tst 2(sp) + beq 1f + mov r1,*2(sp) +1: + rts pc diff --git a/mach/pdp/libsys/write.s b/mach/pdp/libsys/write.s new file mode 100644 index 00000000..38c0f5e0 --- /dev/null +++ b/mach/pdp/libsys/write.s @@ -0,0 +1,17 @@ +#include "sys.h" +.globl _write +.globl _errno + +_write: + mov 2(sp),r0 + mov 4(sp),0f+2 + mov 6(sp),0f+4 + sys indir; 0f + bec 1f + mov r0,_errno + mov $-1,r0 +1: + rts pc +.data +0: + sys write; ..; .. From 36b275be3446ec62a543765f65082688eb378152 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 8 Jan 1987 09:39:54 +0000 Subject: [PATCH 0433/1625] Adapted to new assembler syntax. --- mach/i86/cg/mach.c | 12 ++++++------ mach/i86/cg/mach.h | 11 ++++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/mach/i86/cg/mach.c b/mach/i86/cg/mach.c index aca612b1..84f2ccaa 100644 --- a/mach/i86/cg/mach.c +++ b/mach/i86/cg/mach.c @@ -48,7 +48,7 @@ con_mult(sz) word sz; { if (sz != 4) fatal("bad icon/ucon size"); l = atol(str); - fprintf(codefile,"\t.word %d,%d\n", + fprintf(codefile,"\t.data2 %d,%d\n", (int)l&0xFFFF,(int)(l>>16)&0xFFFF); } @@ -59,7 +59,7 @@ con_float() { if (i!= 4 && i!= 8) fatal("bad fcon size"); while ( i ) { - fprintf(codefile," .word 0,0\n") ; + fprintf(codefile," .data2 0,0\n") ; i -=4 ; } } @@ -109,8 +109,8 @@ mes(type) word type ; { } char *segname[] = { - ".text", /* SEGTXT */ - ".data", /* SEGCON */ - ".data", /* SEGROM */ - ".bss" /* SEGBSS */ + ".sect .text", /* SEGTXT */ + ".sect .data", /* SEGCON */ + ".sect .rom", /* SEGROM */ + ".sect .bss" /* SEGBSS */ }; diff --git a/mach/i86/cg/mach.h b/mach/i86/cg/mach.h index 139393eb..8410ca9a 100644 --- a/mach/i86/cg/mach.h +++ b/mach/i86/cg/mach.h @@ -20,11 +20,12 @@ #define arg_off "4+%d(bp)" #define hol_off "%d+hol%d" -#define con_cst(x) fprintf(codefile,".word\t%d\n",x) -#define con_ilb(x) fprintf(codefile,".word\t%s\n",x) -#define con_dlb(x) fprintf(codefile,".word\t%s\n",x) +#define con_cst(x) fprintf(codefile,".data2\t%d\n",x) +#define con_ilb(x) fprintf(codefile,".data2\t%s\n",x) +#define con_dlb(x) fprintf(codefile,".data2\t%s\n",x) -#define modhead "" +#define modhead ".sect .text; .sect .rom; .sect .data; .sect .bss\n" + +#define fmt_id(fr,to) sprintf(to, "_%s", fr) -#define id_first '_' #define BSS_INIT 0 From 85a6fd789d960dfa727ad9fd9db318198a35fab8 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 8 Jan 1987 09:56:17 +0000 Subject: [PATCH 0434/1625] I don't know! but it was changed. --- mach/i86/libem/tail.s | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mach/i86/libem/tail.s b/mach/i86/libem/tail.s index cdadec8b..059b2376 100644 --- a/mach/i86/libem/tail.s +++ b/mach/i86/libem/tail.s @@ -7,10 +7,10 @@ endtext: _etext: .align 2 .data - .align 2 enddata: _edata: - .bss .align 2 + .bss _end: endbss: + .align 2 From bfc664479fcbd884d6dc0f2ee0073c9f7a4665df Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 8 Jan 1987 10:07:43 +0000 Subject: [PATCH 0435/1625] Initial revision --- mach/i86/libem/end.s | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 mach/i86/libem/end.s diff --git a/mach/i86/libem/end.s b/mach/i86/libem/end.s new file mode 100644 index 00000000..6b9ce418 --- /dev/null +++ b/mach/i86/libem/end.s @@ -0,0 +1,17 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.define endtext,enddata,endbss +.define _end,_etext,_edata + + ! $Header$ + .sect .text +endtext: +_etext: + .align 2 + .sect .data +enddata: +_edata: + .align 2 +.sect .endsect +_end: +endbss: + .align 2 From 7dbdc7763d486c106803d4c20d37884c85b90b28 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 8 Jan 1987 10:13:48 +0000 Subject: [PATCH 0436/1625] adapted to new assembler syntax --- mach/i86/libem/LIST | 3 +- mach/i86/libem/Makefile | 37 ++++++++++++----- mach/i86/libem/adi.s | 5 ++- mach/i86/libem/and.s | 3 +- mach/i86/libem/cii.s | 5 ++- mach/i86/libem/cms.s | 3 +- mach/i86/libem/cmu4.s | 3 +- mach/i86/libem/com.s | 3 +- mach/i86/libem/csa2.s | 5 ++- mach/i86/libem/csb2.s | 5 ++- mach/i86/libem/cuu.s | 5 ++- mach/i86/libem/dup.s | 3 +- mach/i86/libem/dvi.s | 6 ++- mach/i86/libem/dvi4.s | 3 +- mach/i86/libem/dvu.s | 6 ++- mach/i86/libem/dvu4.s | 3 +- mach/i86/libem/error.s | 5 ++- mach/i86/libem/exg.s | 3 +- mach/i86/libem/fakfp.s | 5 ++- mach/i86/libem/fat.s | 5 ++- mach/i86/libem/gto.s | 3 +- mach/i86/libem/iaar.s | 4 +- mach/i86/libem/ilar.s | 5 ++- mach/i86/libem/inn.s | 7 ++-- mach/i86/libem/ior.s | 3 +- mach/i86/libem/isar.s | 5 ++- mach/i86/libem/lar2.s | 3 +- mach/i86/libem/loi.s | 3 +- mach/i86/libem/mli.s | 5 ++- mach/i86/libem/mli4.s | 3 +- mach/i86/libem/mon.s | 4 +- mach/i86/libem/ngi.s | 5 ++- mach/i86/libem/nop.s | 4 +- mach/i86/libem/print.s | 4 +- mach/i86/libem/printf.s | 4 +- mach/i86/libem/rck.s | 5 ++- mach/i86/libem/rmi.s | 6 ++- mach/i86/libem/rmi4.s | 3 +- mach/i86/libem/rmu.s | 6 ++- mach/i86/libem/rmu4.s | 3 +- mach/i86/libem/rol.s | 5 ++- mach/i86/libem/ror.s | 5 ++- mach/i86/libem/sar2.s | 3 +- mach/i86/libem/sbi.s | 7 +++- mach/i86/libem/set.s | 9 +++-- mach/i86/libem/sli.s | 5 ++- mach/i86/libem/sri.s | 5 ++- mach/i86/libem/sti.s | 3 +- mach/i86/libem/stop.s | 3 +- mach/i86/libem/strhp.s | 4 +- mach/i86/libem/trp.s | 4 +- mach/i86/libem/unknown.s | 4 +- mach/i86/libem/xor.s | 3 +- mach/i86/libsys/head_em.s | 83 ++++++++++++++++----------------------- 54 files changed, 225 insertions(+), 119 deletions(-) diff --git a/mach/i86/libem/LIST b/mach/i86/libem/LIST index 370909b6..a94a4e3f 100644 --- a/mach/i86/libem/LIST +++ b/mach/i86/libem/LIST @@ -1,4 +1,4 @@ -tail_em.a +libem_s.a adi.s and.s cii.s @@ -50,4 +50,3 @@ trp.s stop.s printf.s print.s -tail.s diff --git a/mach/i86/libem/Makefile b/mach/i86/libem/Makefile index 351b5160..3dcf0e6b 100644 --- a/mach/i86/libem/Makefile +++ b/mach/i86/libem/Makefile @@ -1,16 +1,33 @@ -install: - ../../install head_em.s head_em - ../../install tail_em.a tail_em +# $Header$ +MACH=i86 +install: all + ../../install head_em.o head_em + ../../install libem_o.a tail_em + ../../install end.o end_em -cmp: - -../../compare head_em.s head_em - -../../compare tail_em.a tail_em +cmp: all + -../../compare head_em.o head_em + -../../compare libem_o.a tail_em + -../../compare end.o end_em -clean : +all: head_em.o libem_o.a end.o +end.o: end.s + $(MACH) -I../../../h -c end.s + +head_em.o: head_em.s + $(MACH) -I../../../h -c head_em.s + +libem_o.a: libem_s.a + ASAR=aal ; export ASAR ;\ + march . libem_o.a + +clean: + rm -f *.o opr : - make pr | opr + make pr | opr pr: - @pr head_em.s - @arch pv tail_em.a | pr -h `pwd`/tail_em.a + @pr `pwd`/head_em.s + @arch pv libem_s.a | pr -h `pwd`/libem_s.a + @pr `pwd`/end.s diff --git a/mach/i86/libem/adi.s b/mach/i86/libem/adi.s index f1f06090..88f12a29 100644 --- a/mach/i86/libem/adi.s +++ b/mach/i86/libem/adi.s @@ -1,7 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss .define .adi - ! $Header$ ! #bytes in cx , top of stack in ax + .sect .text .adi: pop bx ! return address cmp cx,2 @@ -20,6 +21,8 @@ push dx jmp bx 9: +.extern EODDZ +.extern .trp mov ax,EODDZ push ax jmp .trp diff --git a/mach/i86/libem/and.s b/mach/i86/libem/and.s index e77b09d5..07e2c74d 100644 --- a/mach/i86/libem/and.s +++ b/mach/i86/libem/and.s @@ -1,7 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss .define .and - ! $Header$ ! #bytes in cx + .sect .text .and: pop bx ! return address mov di,sp diff --git a/mach/i86/libem/cii.s b/mach/i86/libem/cii.s index 4304a0ee..4cf0cb3c 100644 --- a/mach/i86/libem/cii.s +++ b/mach/i86/libem/cii.s @@ -1,7 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss .define .cii +.sect .text .cii: - ! $Header$ pop di ! return address ! pop cx, dest. size ! pop bx, src. size @@ -31,6 +32,8 @@ jmp di 9: push ax ! push low source +.extern EILLINS +.extern .fat mov ax,EILLINS push ax jmp .fat diff --git a/mach/i86/libem/cms.s b/mach/i86/libem/cms.s index cec20db0..308d70a1 100644 --- a/mach/i86/libem/cms.s +++ b/mach/i86/libem/cms.s @@ -1,7 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss .define .cms - ! $Header$ ! #bytes in cx + .sect .text .cms: pop bx ! return address mov dx,sp diff --git a/mach/i86/libem/cmu4.s b/mach/i86/libem/cmu4.s index 2e4bf946..fc14b4dd 100644 --- a/mach/i86/libem/cmu4.s +++ b/mach/i86/libem/cmu4.s @@ -1,7 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss .define .cmu4 +.sect .text .cmu4: - ! $Header$ pop bx ! return address xor ax,ax pop cx diff --git a/mach/i86/libem/com.s b/mach/i86/libem/com.s index 23aee51d..ea398d83 100644 --- a/mach/i86/libem/com.s +++ b/mach/i86/libem/com.s @@ -1,7 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss .define .com - ! $Header$ ! #bytes in cx + .sect .text .com: pop bx ! return address mov di,sp diff --git a/mach/i86/libem/csa2.s b/mach/i86/libem/csa2.s index 60ef8ed1..257f7036 100644 --- a/mach/i86/libem/csa2.s +++ b/mach/i86/libem/csa2.s @@ -1,7 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss .define .csa2 +.sect .text .csa2: - ! $Header$ ! si, descriptor address ! bx, index mov dx,(si) ! default @@ -16,6 +17,8 @@ mov bx,dx test bx,bx jnz 2f +.extern ECASE +.extern .fat mov ax,ECASE push ax jmp .fat diff --git a/mach/i86/libem/csb2.s b/mach/i86/libem/csb2.s index f49fe8a5..bae85588 100644 --- a/mach/i86/libem/csb2.s +++ b/mach/i86/libem/csb2.s @@ -1,7 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss .define .csb2 +.sect .text .csb2: - ! $Header$ !si, descriptor address !dx, index lods @@ -19,6 +20,8 @@ 2: test bx,bx jnz 3f +.extern ECASE +.extern .fat mov ax,ECASE push ax jmp .fat diff --git a/mach/i86/libem/cuu.s b/mach/i86/libem/cuu.s index 7719f39d..3d47d5f8 100644 --- a/mach/i86/libem/cuu.s +++ b/mach/i86/libem/cuu.s @@ -1,11 +1,12 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss .define .ciu .define .cui .define .cuu +.sect .text .ciu: .cui: .cuu: - ! $Header$ pop di ! return address ! pop cx, dest. size ! pop bx, source size @@ -29,6 +30,8 @@ jmp di 9: push ax ! to help debugging ? +.extern EILLINS +.extern .fat mov ax,EILLINS push ax jmp .fat diff --git a/mach/i86/libem/dup.s b/mach/i86/libem/dup.s index 9634463c..ba2c7530 100644 --- a/mach/i86/libem/dup.s +++ b/mach/i86/libem/dup.s @@ -1,7 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss .define .dup - ! $Header$ ! #bytes in cx + .sect .text .dup: pop bx ! return address mov si,sp diff --git a/mach/i86/libem/dvi.s b/mach/i86/libem/dvi.s index fd3daac8..38cabc6e 100644 --- a/mach/i86/libem/dvi.s +++ b/mach/i86/libem/dvi.s @@ -1,7 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss .define .dvi - ! $Header$ ! #bytes in ax + .sect .text .dvi: pop bx ! return address cmp ax,2 @@ -24,12 +25,15 @@ push si push dx push ax +.extern .dvi4 call .dvi4 pop bx push cx push ax jmp bx 9: +.extern EODDZ +.extern .trp mov ax,EODDZ push ax jmp .trp diff --git a/mach/i86/libem/dvi4.s b/mach/i86/libem/dvi4.s index e4c66ff1..c9c9714e 100644 --- a/mach/i86/libem/dvi4.s +++ b/mach/i86/libem/dvi4.s @@ -1,3 +1,4 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss .define .dvi4 yl=2 @@ -5,8 +6,8 @@ yh=4 xl=6 xh=8 +.sect .text .dvi4: - ! $Header$ mov si,sp ! copy of sp mov bx,yl(si) mov ax,yh(si) diff --git a/mach/i86/libem/dvu.s b/mach/i86/libem/dvu.s index b2bcdd67..71dcdfa5 100644 --- a/mach/i86/libem/dvu.s +++ b/mach/i86/libem/dvu.s @@ -1,7 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss .define .dvu - ! $Header$ ! #bytes in ax + .sect .text .dvu: pop bx ! return address cmp ax,2 @@ -24,12 +25,15 @@ push si push dx push ax +.extern .dvu4 call .dvu4 pop bx push cx push ax jmp bx 9: +.extern EODDZ +.extern .trp mov ax,EODDZ push ax jmp .trp diff --git a/mach/i86/libem/dvu4.s b/mach/i86/libem/dvu4.s index fff547b6..bc189ff5 100644 --- a/mach/i86/libem/dvu4.s +++ b/mach/i86/libem/dvu4.s @@ -1,3 +1,4 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss .define .dvu4 yl=2 @@ -5,8 +6,8 @@ yh=4 xl=6 xh=8 +.sect .text .dvu4: - ! $Header$ mov si,sp ! copy of sp mov bx,yl(si) mov ax,yh(si) diff --git a/mach/i86/libem/error.s b/mach/i86/libem/error.s index 64354e67..dedc9df0 100644 --- a/mach/i86/libem/error.s +++ b/mach/i86/libem/error.s @@ -1,10 +1,11 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss .define .error - ! $Header$ ! ax is trap number ! all registers must be saved ! because return is possible ! May only be called with error no's <16 +.sect .text .error: push bp push si @@ -16,6 +17,8 @@ mov cx,ax mov bx,1 sal bx,cl +.extern .ignmask +.extern .trp test bx,(.ignmask) jne 2f call .trp diff --git a/mach/i86/libem/exg.s b/mach/i86/libem/exg.s index 8b5bf4b9..be2f6cb4 100644 --- a/mach/i86/libem/exg.s +++ b/mach/i86/libem/exg.s @@ -1,7 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss .define .exg - ! $Header$ ! #bytes in cx +.sect .text .exg: pop bx ! return address mov dx,cx diff --git a/mach/i86/libem/fakfp.s b/mach/i86/libem/fakfp.s index df97bc26..5d6bb3c7 100644 --- a/mach/i86/libem/fakfp.s +++ b/mach/i86/libem/fakfp.s @@ -1,3 +1,5 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .mlf,.dvf,.ngf,.adf,.sbf,.cmf,.zrf,.fif,.fef .define .mlf8,.dvf8,.ngf8,.adf8,.sbf8,.cmf8,.zrf8,.fif8,.fef8 .define .mlf4,.dvf4,.ngf4,.adf4,.sbf4,.cmf4,.zrf4,.fif4,.fef4 @@ -35,8 +37,9 @@ .cuf: .cfu: .cff: - ! $Header$ pop bx ! return address +.extern EILLINS +.extern .fat mov ax,EILLINS push ax jmp .fat diff --git a/mach/i86/libem/fat.s b/mach/i86/libem/fat.s index 5a0dd072..0302552d 100644 --- a/mach/i86/libem/fat.s +++ b/mach/i86/libem/fat.s @@ -1,7 +1,10 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .fat .fat: - ! $Header$ +.extern .trp +.extern .stop call .trp call .stop ! no return diff --git a/mach/i86/libem/gto.s b/mach/i86/libem/gto.s index 8fdb23ba..b7c325b5 100644 --- a/mach/i86/libem/gto.s +++ b/mach/i86/libem/gto.s @@ -1,7 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .gto .gto: - ! $Header$ mov bp,4(bx) mov sp,2(bx) jmp (bx) diff --git a/mach/i86/libem/iaar.s b/mach/i86/libem/iaar.s index 4a2a92eb..679c9b22 100644 --- a/mach/i86/libem/iaar.s +++ b/mach/i86/libem/iaar.s @@ -1,10 +1,12 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .iaar .iaar: - ! $Header$ pop bx pop dx cmp dx,2 +.extern .unknown jne .unknown pop si ! descriptor address pop ax ! index diff --git a/mach/i86/libem/ilar.s b/mach/i86/libem/ilar.s index 11fbed54..a1de8be5 100644 --- a/mach/i86/libem/ilar.s +++ b/mach/i86/libem/ilar.s @@ -1,13 +1,16 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .ilar .ilar: - ! $Header$ pop bx pop dx +.extern .unknown cmp dx,2 jne .unknown pop di ! descriptor address pop ax ! index pop si ! array base push bx +.extern .lar2 jmp .lar2 diff --git a/mach/i86/libem/inn.s b/mach/i86/libem/inn.s index ced6bbc2..9b29e9f5 100644 --- a/mach/i86/libem/inn.s +++ b/mach/i86/libem/inn.s @@ -1,6 +1,7 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .inn - ! $Header$ ! #bytes in cx ! bit # in ax .inn: @@ -24,6 +25,6 @@ ! ax is result jmp bx - .data + .sect .data bits: - .byte 1,2,4,8,16,32,64,128 + .data1 1,2,4,8,16,32,64,128 diff --git a/mach/i86/libem/ior.s b/mach/i86/libem/ior.s index 0fc130a4..489eff7b 100644 --- a/mach/i86/libem/ior.s +++ b/mach/i86/libem/ior.s @@ -1,6 +1,7 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .ior - ! $Header$ ! #bytes in cx .ior: pop bx ! return address diff --git a/mach/i86/libem/isar.s b/mach/i86/libem/isar.s index 569bb779..af83d30c 100644 --- a/mach/i86/libem/isar.s +++ b/mach/i86/libem/isar.s @@ -1,13 +1,16 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .isar .isar: - ! $Header$ pop bx pop dx cmp dx,2 +.extern .unknown jne .unknown pop si ! descriptor address pop ax ! index pop di ! array base push bx +.extern .sar2 jmp .sar2 diff --git a/mach/i86/libem/lar2.s b/mach/i86/libem/lar2.s index 58a7c3aa..caa6575c 100644 --- a/mach/i86/libem/lar2.s +++ b/mach/i86/libem/lar2.s @@ -1,7 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .lar2 .lar2: - ! $Header$ pop bx ! return address ! di, descriptor address ! ax, index diff --git a/mach/i86/libem/loi.s b/mach/i86/libem/loi.s index c958d5e7..b6c750d8 100644 --- a/mach/i86/libem/loi.s +++ b/mach/i86/libem/loi.s @@ -1,6 +1,7 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .loi - ! $Header$ ! #bytes in cx ! source address in si .loi: diff --git a/mach/i86/libem/mli.s b/mach/i86/libem/mli.s index f143488d..0fdf338a 100644 --- a/mach/i86/libem/mli.s +++ b/mach/i86/libem/mli.s @@ -1,6 +1,7 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .mli - ! $Header$ ! #bytes in ax .mli: pop bx ! return address @@ -22,6 +23,8 @@ push dx jmp .mli4 9: +.extern EODDZ +.extern .trp mov ax,EODDZ push ax jmp .trp diff --git a/mach/i86/libem/mli4.s b/mach/i86/libem/mli4.s index 36395fd7..d3b87c69 100644 --- a/mach/i86/libem/mli4.s +++ b/mach/i86/libem/mli4.s @@ -1,6 +1,7 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .mli4 - ! $Header$ ! x * y with ! x.low = si x.high = di ! y.low = bx y.high = ax diff --git a/mach/i86/libem/mon.s b/mach/i86/libem/mon.s index 30dd48ef..42cac7ca 100644 --- a/mach/i86/libem/mon.s +++ b/mach/i86/libem/mon.s @@ -1,5 +1,7 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .mon .mon: - ! $Header$ +.extern .stop call .stop diff --git a/mach/i86/libem/ngi.s b/mach/i86/libem/ngi.s index 6a479f7f..ce458951 100644 --- a/mach/i86/libem/ngi.s +++ b/mach/i86/libem/ngi.s @@ -1,6 +1,7 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .ngi - ! $Header$ ! #bytes in ax .ngi: pop bx ! return address @@ -22,6 +23,8 @@ push ax jmp bx 9: +.extern EODDZ +.extern .trp mov ax,EODDZ push ax jmp .trp diff --git a/mach/i86/libem/nop.s b/mach/i86/libem/nop.s index 26aa071d..62e861b5 100644 --- a/mach/i86/libem/nop.s +++ b/mach/i86/libem/nop.s @@ -1,11 +1,13 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .nop +.extern printd, printc, hol0 SIO_S = 0xDA SIO_D = 0xD8 RXRDY = 0x02 .nop: - ! $Header$ mov ax,(hol0) call printd ! movb al,' ' diff --git a/mach/i86/libem/print.s b/mach/i86/libem/print.s index bb8ea8ae..5cb8c04b 100644 --- a/mach/i86/libem/print.s +++ b/mach/i86/libem/print.s @@ -1,10 +1,11 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define printc,printd,prints SIO_D = 0xD8 SIO_S = 0xDA TXRDY = 0x01 - ! $Header$ ! argument in ax ! uses bx prints: @@ -33,7 +34,6 @@ printd: 1: xchg ax,dx addb al,'0' - .errnz printc - . ! argument in ax printc: diff --git a/mach/i86/libem/printf.s b/mach/i86/libem/printf.s index 31ea794b..83f13320 100644 --- a/mach/i86/libem/printf.s +++ b/mach/i86/libem/printf.s @@ -1,7 +1,9 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define printf +.extern printc, printd, prints printf: - ! $Header$ pop bx ! return address xchg ax,di mov si,sp diff --git a/mach/i86/libem/rck.s b/mach/i86/libem/rck.s index 5a012147..acc5330b 100644 --- a/mach/i86/libem/rck.s +++ b/mach/i86/libem/rck.s @@ -1,6 +1,7 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .rck - ! $Header$ ! descriptor address in si ! value in ax, must be left there .rck: @@ -11,6 +12,8 @@ ret 2: push ax +.extern ERANGE +.extern .error mov ax,ERANGE call .error pop ax diff --git a/mach/i86/libem/rmi.s b/mach/i86/libem/rmi.s index 81fdc89e..eda6ffd7 100644 --- a/mach/i86/libem/rmi.s +++ b/mach/i86/libem/rmi.s @@ -1,6 +1,7 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .rmi - ! $Header$ ! #bytes in ax .rmi: pop bx ! return address @@ -24,12 +25,15 @@ push si push dx push ax +.extern .rmi4 call .rmi4 pop ax push bx push dx jmp ax 9: +.extern EODDZ +.extern .trp mov ax,EODDZ push ax jmp .trp diff --git a/mach/i86/libem/rmi4.s b/mach/i86/libem/rmi4.s index 6abaea1b..cdfcf75c 100644 --- a/mach/i86/libem/rmi4.s +++ b/mach/i86/libem/rmi4.s @@ -1,3 +1,5 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .rmi4 yl=2 @@ -6,7 +8,6 @@ xl=6 xh=8 .rmi4: - ! $Header$ mov si,sp ! copy of sp mov bx,yl(si) mov ax,yh(si) diff --git a/mach/i86/libem/rmu.s b/mach/i86/libem/rmu.s index 3e74de7e..7b89c669 100644 --- a/mach/i86/libem/rmu.s +++ b/mach/i86/libem/rmu.s @@ -1,6 +1,7 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .rmu - ! $Header$ ! #bytes in ax .rmu: pop bx ! return address @@ -24,12 +25,15 @@ push si push dx push ax +.extern .rmu4 call .rmu4 pop ax push bx push dx jmp ax 9: +.extern EODDZ +.extern .trp mov ax,EODDZ push ax jmp .trp diff --git a/mach/i86/libem/rmu4.s b/mach/i86/libem/rmu4.s index 4a79fcf0..4ef5dd2f 100644 --- a/mach/i86/libem/rmu4.s +++ b/mach/i86/libem/rmu4.s @@ -1,3 +1,5 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .rmu4 yl=2 @@ -6,7 +8,6 @@ xl=6 xh=8 .rmu4: - ! $Header$ mov si,sp ! copy of sp mov bx,yl(si) mov ax,yh(si) diff --git a/mach/i86/libem/rol.s b/mach/i86/libem/rol.s index 6de420f4..df862991 100644 --- a/mach/i86/libem/rol.s +++ b/mach/i86/libem/rol.s @@ -1,6 +1,7 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .rol - ! $Header$ ! #bytes in ax .rol: pop dx ! return address @@ -28,6 +29,8 @@ 2: jmp dx 9: +.extern EODDZ +.extern .trp mov ax,EODDZ push ax jmp .trp diff --git a/mach/i86/libem/ror.s b/mach/i86/libem/ror.s index 5b98ec8f..ea1183c1 100644 --- a/mach/i86/libem/ror.s +++ b/mach/i86/libem/ror.s @@ -1,6 +1,7 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .ror - ! $Header$ ! #bytes in ax .ror: pop dx ! return address @@ -29,6 +30,8 @@ 2: jmp dx 9: +.extern EODDZ +.extern .trp mov ax,EODDZ push ax jmp .trp diff --git a/mach/i86/libem/sar2.s b/mach/i86/libem/sar2.s index 8a317de4..61205bf8 100644 --- a/mach/i86/libem/sar2.s +++ b/mach/i86/libem/sar2.s @@ -1,7 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .sar2 .sar2: - ! $Header$ pop bx ! return address ! si, descriptor address ! ax, index diff --git a/mach/i86/libem/sbi.s b/mach/i86/libem/sbi.s index 018f399f..13018ff3 100644 --- a/mach/i86/libem/sbi.s +++ b/mach/i86/libem/sbi.s @@ -1,6 +1,7 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .sbi - ! $Header$ ! #bytes in cx , top of stack in ax .sbi: pop bx ! return subress @@ -18,10 +19,12 @@ sub cx,ax mov ax,cx pop cx - sbc cx,dx + sbb cx,dx push cx jmp bx 9: +.extern EODDZ +.extern .trp mov ax,EODDZ push ax jmp .trp diff --git a/mach/i86/libem/set.s b/mach/i86/libem/set.s index 0c5dabd8..b5d4c05d 100644 --- a/mach/i86/libem/set.s +++ b/mach/i86/libem/set.s @@ -1,6 +1,7 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .set - ! $Header$ ! #bytes in cx ! bit # in ax .set: @@ -25,11 +26,13 @@ orb (di),dl jmp bx 2: +.extern ESET +.extern .trp push bx mov ax,ESET push ax jmp .trp - .data + .sect .data bits: - .byte 1,2,4,8,16,32,64,128 + .data1 1,2,4,8,16,32,64,128 diff --git a/mach/i86/libem/sli.s b/mach/i86/libem/sli.s index 3d57008b..b8b0f1ef 100644 --- a/mach/i86/libem/sli.s +++ b/mach/i86/libem/sli.s @@ -1,6 +1,7 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .sli - ! $Header$ ! #bytes in ax .sli: pop dx ! return address @@ -27,6 +28,8 @@ 2: jmp dx 9: +.extern EODDZ +.extern .trp mov ax,EODDZ push ax jmp .trp diff --git a/mach/i86/libem/sri.s b/mach/i86/libem/sri.s index 9cd97357..1566ac3b 100644 --- a/mach/i86/libem/sri.s +++ b/mach/i86/libem/sri.s @@ -1,6 +1,7 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .sri - ! $Header$ ! #bytes in ax .sri: pop dx ! return address @@ -27,6 +28,8 @@ 2: jmp dx 9: +.extern EODDZ +.extern .trp mov ax,EODDZ push ax jmp .trp diff --git a/mach/i86/libem/sti.s b/mach/i86/libem/sti.s index 9e2fcc67..eb49d2f4 100644 --- a/mach/i86/libem/sti.s +++ b/mach/i86/libem/sti.s @@ -1,6 +1,7 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .sti - ! $Header$ ! #bytes in cx ! destination address in di .sti: diff --git a/mach/i86/libem/stop.s b/mach/i86/libem/stop.s index 5aeaf51f..fbf0e691 100644 --- a/mach/i86/libem/stop.s +++ b/mach/i86/libem/stop.s @@ -1,4 +1,5 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .stop .stop: - ! $Header$ int 3 diff --git a/mach/i86/libem/strhp.s b/mach/i86/libem/strhp.s index e5e11bf8..1dd17a96 100644 --- a/mach/i86/libem/strhp.s +++ b/mach/i86/libem/strhp.s @@ -1,7 +1,9 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .strhp +.extern .reghp, .limhp, EHEAP, .fat .strhp: - ! $Header$ pop bx pop ax mov (.reghp),ax diff --git a/mach/i86/libem/trp.s b/mach/i86/libem/trp.s index 7f95dc28..12373955 100644 --- a/mach/i86/libem/trp.s +++ b/mach/i86/libem/trp.s @@ -1,6 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .trp +.extern .trppc, .stop - ! $Header$ ! ax is trap number .trp: xor bx,bx diff --git a/mach/i86/libem/unknown.s b/mach/i86/libem/unknown.s index 2da916e2..a436afd4 100644 --- a/mach/i86/libem/unknown.s +++ b/mach/i86/libem/unknown.s @@ -1,7 +1,9 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .unknown +.extern EILLINS, .fat .unknown: - ! $Header$ mov ax,EILLINS push ax jmp .fat diff --git a/mach/i86/libem/xor.s b/mach/i86/libem/xor.s index 913d3429..093e9c3f 100644 --- a/mach/i86/libem/xor.s +++ b/mach/i86/libem/xor.s @@ -1,6 +1,7 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.sect .text .define .xor - ! $Header$ ! #bytes in cx .xor: pop bx ! return address diff --git a/mach/i86/libsys/head_em.s b/mach/i86/libsys/head_em.s index d421e79b..956765b1 100644 --- a/mach/i86/libsys/head_em.s +++ b/mach/i86/libsys/head_em.s @@ -1,6 +1,10 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss + .define begtext,begdata,begbss .define hol0,.reghp,.limhp,.trppc,.ignmask -.define ERANGE,ESET,EHEAP,ECASE,EILLINS,EODDZ +.define ERANGE,ESET,EHEAP,ECASE,EILLINS +.extern _end +.extern np ERANGE = 1 ESET = 2 @@ -10,66 +14,45 @@ EILLINS = 18 EODDZ = 19 ECASE = 20 -base = 0x01C0 -topmem = 0xFFF0 - - .org topmem-16 -.extern __n_line -maxmem: -__n_line: - .space 16 - .errnz __n_line-0xFFE0 - - .base base - - .text +.sect .text begtext: - cld - xor ax,ax - mov ss,ax - mov ds,ax - mov es,ax - mov (2),cs - mov (0),.diverr - mov sp,maxmem - mov di,begbss - mov cx,[[endbss-begbss]/2]&0x7FFF - ! xor ax,ax ! ax still is 0 - rep stos - mov ax,envp - push ax - mov ax,argv - push ax - mov ax,1 - push ax + mov bx,sp + mov cx,(bx) + add bx,2 + mov ax,cx + inc ax + shl ax,1 + add ax,bx + push ax + push bx + push cx + mov (np),begbss + mov bx,endbss + push bx + call _brk ! allocate space for bss + pop si + xor bp,bp call _m_a_i_n - call .stop -.diverr: - push ax - mov ax,EIDIVZ - call .error - pop ax - iret - - .data + int 0x81 +.sect .data begdata: hol0: - .word 0,0 - .word 0,0 + .data2 0,0 + .data2 0,0 argv: - .word 3f + .data2 3f envp: - .word 0 + .data2 0 3: .asciz "PROGRAM" .reghp: - .word endbss + .data2 endbss .limhp: - .word endbss + .data2 endbss .ignmask: - .word 0 + .data2 0 .trppc: - .word 0 + .data2 0 - .bss + .sect .bss begbss: From ee9b44c04143e7251194b3b205cd59c36082e3ce Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 8 Jan 1987 10:19:47 +0000 Subject: [PATCH 0437/1625] changed name back: libem_s.a --> tail_em.a --- mach/i86/libem/LIST | 2 +- mach/i86/libem/Makefile | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/mach/i86/libem/LIST b/mach/i86/libem/LIST index a94a4e3f..4bd01814 100644 --- a/mach/i86/libem/LIST +++ b/mach/i86/libem/LIST @@ -1,4 +1,4 @@ -libem_s.a +tail_em.a adi.s and.s cii.s diff --git a/mach/i86/libem/Makefile b/mach/i86/libem/Makefile index 3dcf0e6b..c1ebb198 100644 --- a/mach/i86/libem/Makefile +++ b/mach/i86/libem/Makefile @@ -2,15 +2,15 @@ MACH=i86 install: all ../../install head_em.o head_em - ../../install libem_o.a tail_em + ../../install tail_em ../../install end.o end_em cmp: all -../../compare head_em.o head_em - -../../compare libem_o.a tail_em + -../../compare tail_em -../../compare end.o end_em -all: head_em.o libem_o.a end.o +all: head_em.o tail_em end.o end.o: end.s $(MACH) -I../../../h -c end.s @@ -18,9 +18,9 @@ end.o: end.s head_em.o: head_em.s $(MACH) -I../../../h -c head_em.s -libem_o.a: libem_s.a +tail_em: tail_em.a ASAR=aal ; export ASAR ;\ - march . libem_o.a + march . tail_em clean: rm -f *.o @@ -29,5 +29,5 @@ opr : pr: @pr `pwd`/head_em.s - @arch pv libem_s.a | pr -h `pwd`/libem_s.a + @arch pv tail_em.a | pr -h `pwd`/tail_em.a @pr `pwd`/end.s From 0f2eadb5e2c088e276a63a00ff07df6be07eae1a Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 8 Jan 1987 10:21:35 +0000 Subject: [PATCH 0438/1625] Initial revision --- mach/i86/libem/compmodule | 4 ++++ 1 file changed, 4 insertions(+) create mode 100755 mach/i86/libem/compmodule diff --git a/mach/i86/libem/compmodule b/mach/i86/libem/compmodule new file mode 100755 index 00000000..8ec2f672 --- /dev/null +++ b/mach/i86/libem/compmodule @@ -0,0 +1,4 @@ +if i86 -c $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 +fi From 6cc04d5e39772e7080c9dd6c6eab4e28be1207c5 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 8 Jan 1987 10:28:26 +0000 Subject: [PATCH 0439/1625] use "compare" shell script --- mach/i86/libcc/Makefile | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/mach/i86/libcc/Makefile b/mach/i86/libcc/Makefile index 8a3ebdf3..08395baa 100644 --- a/mach/i86/libcc/Makefile +++ b/mach/i86/libcc/Makefile @@ -3,7 +3,6 @@ MACHDEF="MACH=i86" "SUF=s" STDIO="PREF=cc" "SUB=.1s" "SRC=lang/cem/libcc/stdio" GEN="PREF=cc" "SUB=.2g" "SRC=lang/cem/libcc/gen" MON="PREF=mon" "SRC=lang/cem/libcc/mon" -LIBDIR=../lib install: cpstdio cpgen cpmon @@ -18,15 +17,15 @@ cmp: cmpstdio cmpgen cmpmon cmpstdio: make -f $(MAKEFILE) $(STDIO) $(MACHDEF) tail - -cmp tail_cc.1s $(LIBDIR)/tail_cc.1s + ../../compare tail_cc.1s cmpgen: make -f $(MAKEFILE) $(GEN) $(MACHDEF) head - -cmp head_cc $(LIBDIR)/head_cc + ../../compare head_cc make -f $(MAKEFILE) $(GEN) $(MACHDEF) tail - -cmp tail_cc.2g $(LIBDIR)/tail_cc.2g + ../../compare tail_cc.2g cmpmon: make -f $(MAKEFILE) $(MON) $(MACHDEF) tail - -cmp tail_mon $(LIBDIR)/tail_mon + ../../compare tail_mon clean: -rm -f *.old *.[ce$(SUF)] tail* head* From b5a04df6cd9429abe051d4d890c67a63652cfd4b Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 8 Jan 1987 10:29:45 +0000 Subject: [PATCH 0440/1625] Adapted to get .o files. --- mach/i86/libcc/Makefile | 14 +++++++------- mach/i86/libcc/compmodule | 8 ++++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/mach/i86/libcc/Makefile b/mach/i86/libcc/Makefile index 08395baa..c80e2a60 100644 --- a/mach/i86/libcc/Makefile +++ b/mach/i86/libcc/Makefile @@ -1,10 +1,10 @@ MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=i86" "SUF=s" +MACHDEF="MACH=l86" "SUF=o" "ASAR=aal" STDIO="PREF=cc" "SUB=.1s" "SRC=lang/cem/libcc/stdio" GEN="PREF=cc" "SUB=.2g" "SRC=lang/cem/libcc/gen" MON="PREF=mon" "SRC=lang/cem/libcc/mon" -install: cpstdio cpgen cpmon +install: cpstdio cpgen cpstdio: make -f $(MAKEFILE) $(STDIO) $(MACHDEF) tailcp @@ -13,19 +13,19 @@ cpgen: cpmon: make -f $(MAKEFILE) $(MON) $(MACHDEF) tailcp -cmp: cmpstdio cmpgen cmpmon +cmp: cmpstdio cmpgen cmpstdio: make -f $(MAKEFILE) $(STDIO) $(MACHDEF) tail - ../../compare tail_cc.1s + -../../compare tail_cc.1s cmpgen: make -f $(MAKEFILE) $(GEN) $(MACHDEF) head - ../../compare head_cc + -../../compare head_cc make -f $(MAKEFILE) $(GEN) $(MACHDEF) tail - ../../compare tail_cc.2g + -../../compare tail_cc.2g cmpmon: make -f $(MAKEFILE) $(MON) $(MACHDEF) tail - ../../compare tail_mon + -../../compare tail_mon clean: -rm -f *.old *.[ce$(SUF)] tail* head* diff --git a/mach/i86/libcc/compmodule b/mach/i86/libcc/compmodule index 2bcf66ca..6327cb99 100755 --- a/mach/i86/libcc/compmodule +++ b/mach/i86/libcc/compmodule @@ -1,2 +1,6 @@ -${MACH?ack} -I../../../h ${MACHFL?} $1 1>&2 -echo `basename $1 $2`.s +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then + echo `basename $1 $2`.o +else + exit 1 +fi From 68e60eb8a439a28da8392a1815988faa5f6f80f4 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 8 Jan 1987 10:41:08 +0000 Subject: [PATCH 0441/1625] Initial revision --- mach/i86/libsys/LIST | 52 ++++++++++++++++++++++++++++++++ mach/i86/libsys/Makefile | 21 +++++++++++++ mach/i86/libsys/_exit.s | 10 ++++++ mach/i86/libsys/abort.s | 13 ++++++++ mach/i86/libsys/access.s | 9 ++++++ mach/i86/libsys/alarm.s | 8 +++++ mach/i86/libsys/brk.s | 39 ++++++++++++++++++++++++ mach/i86/libsys/cerror.s | 9 ++++++ mach/i86/libsys/chdir.s | 8 +++++ mach/i86/libsys/chmod.s | 8 +++++ mach/i86/libsys/chown.s | 8 +++++ mach/i86/libsys/cleanup.s | 9 ++++++ mach/i86/libsys/close.s | 8 +++++ mach/i86/libsys/compmodule | 4 +++ mach/i86/libsys/creat.s | 7 +++++ mach/i86/libsys/dup.s | 8 +++++ mach/i86/libsys/error.s | 7 +++++ mach/i86/libsys/exece.s | 7 +++++ mach/i86/libsys/execl.s | 20 ++++++++++++ mach/i86/libsys/execle.s | 24 +++++++++++++++ mach/i86/libsys/execv.s | 12 ++++++++ mach/i86/libsys/execve.s | 8 +++++ mach/i86/libsys/exit.s | 13 ++++++++ mach/i86/libsys/fork.s | 11 +++++++ mach/i86/libsys/fstat.s | 8 +++++ mach/i86/libsys/ftime.s | 8 +++++ mach/i86/libsys/getgid.s | 8 +++++ mach/i86/libsys/getpid.s | 8 +++++ mach/i86/libsys/getuid.s | 8 +++++ mach/i86/libsys/gtty.s | 15 +++++++++ mach/i86/libsys/ioctl.s | 7 +++++ mach/i86/libsys/kill.s | 8 +++++ mach/i86/libsys/link.s | 7 +++++ mach/i86/libsys/lseek.s | 7 +++++ mach/i86/libsys/mknod.s | 8 +++++ mach/i86/libsys/mount.s | 8 +++++ mach/i86/libsys/nice.s | 8 +++++ mach/i86/libsys/open.s | 7 +++++ mach/i86/libsys/pause.s | 8 +++++ mach/i86/libsys/pipe.s | 8 +++++ mach/i86/libsys/profil.s | 8 +++++ mach/i86/libsys/read.s | 7 +++++ mach/i86/libsys/sbrk.s | 25 +++++++++++++++ mach/i86/libsys/setgid.s | 8 +++++ mach/i86/libsys/setuid.s | 8 +++++ mach/i86/libsys/signal.s | 62 ++++++++++++++++++++++++++++++++++++++ mach/i86/libsys/stat.s | 8 +++++ mach/i86/libsys/stty.s | 15 +++++++++ mach/i86/libsys/sync.s | 8 +++++ mach/i86/libsys/time.s | 27 +++++++++++++++++ mach/i86/libsys/umount.s | 9 ++++++ mach/i86/libsys/unlink.s | 8 +++++ mach/i86/libsys/wait.s | 17 +++++++++++ mach/i86/libsys/write.s | 7 +++++ 54 files changed, 671 insertions(+) create mode 100644 mach/i86/libsys/LIST create mode 100644 mach/i86/libsys/Makefile create mode 100644 mach/i86/libsys/_exit.s create mode 100644 mach/i86/libsys/abort.s create mode 100644 mach/i86/libsys/access.s create mode 100644 mach/i86/libsys/alarm.s create mode 100644 mach/i86/libsys/brk.s create mode 100644 mach/i86/libsys/cerror.s create mode 100644 mach/i86/libsys/chdir.s create mode 100644 mach/i86/libsys/chmod.s create mode 100644 mach/i86/libsys/chown.s create mode 100644 mach/i86/libsys/cleanup.s create mode 100644 mach/i86/libsys/close.s create mode 100755 mach/i86/libsys/compmodule create mode 100644 mach/i86/libsys/creat.s create mode 100644 mach/i86/libsys/dup.s create mode 100644 mach/i86/libsys/error.s create mode 100644 mach/i86/libsys/exece.s create mode 100644 mach/i86/libsys/execl.s create mode 100644 mach/i86/libsys/execle.s create mode 100644 mach/i86/libsys/execv.s create mode 100644 mach/i86/libsys/execve.s create mode 100644 mach/i86/libsys/exit.s create mode 100644 mach/i86/libsys/fork.s create mode 100644 mach/i86/libsys/fstat.s create mode 100644 mach/i86/libsys/ftime.s create mode 100644 mach/i86/libsys/getgid.s create mode 100644 mach/i86/libsys/getpid.s create mode 100644 mach/i86/libsys/getuid.s create mode 100644 mach/i86/libsys/gtty.s create mode 100644 mach/i86/libsys/ioctl.s create mode 100644 mach/i86/libsys/kill.s create mode 100644 mach/i86/libsys/link.s create mode 100644 mach/i86/libsys/lseek.s create mode 100644 mach/i86/libsys/mknod.s create mode 100644 mach/i86/libsys/mount.s create mode 100644 mach/i86/libsys/nice.s create mode 100644 mach/i86/libsys/open.s create mode 100644 mach/i86/libsys/pause.s create mode 100644 mach/i86/libsys/pipe.s create mode 100644 mach/i86/libsys/profil.s create mode 100644 mach/i86/libsys/read.s create mode 100644 mach/i86/libsys/sbrk.s create mode 100644 mach/i86/libsys/setgid.s create mode 100644 mach/i86/libsys/setuid.s create mode 100644 mach/i86/libsys/signal.s create mode 100644 mach/i86/libsys/stat.s create mode 100644 mach/i86/libsys/stty.s create mode 100644 mach/i86/libsys/sync.s create mode 100644 mach/i86/libsys/time.s create mode 100644 mach/i86/libsys/umount.s create mode 100644 mach/i86/libsys/unlink.s create mode 100644 mach/i86/libsys/wait.s create mode 100644 mach/i86/libsys/write.s diff --git a/mach/i86/libsys/LIST b/mach/i86/libsys/LIST new file mode 100644 index 00000000..90121971 --- /dev/null +++ b/mach/i86/libsys/LIST @@ -0,0 +1,52 @@ +tail_mon.a +exit.s +_exit.s +abort.s +access.s +chdir.s +chmod.s +chown.s +cleanup.s +close.s +creat.s +dup.s +execl.s +execle.s +execv.s +execve.s +time.s +exece.s +fork.s +fstat.s +getgid.s +getpid.s +getuid.s +gtty.s +stty.s +ioctl.s +kill.s +link.s +lseek.s +mknod.s +mount.s +nice.s +open.s +pipe.s +profil.s +read.s +sbrk.s +brk.s +setgid.s +setuid.s +signal.s +stat.s +sync.s +umount.s +unlink.s +wait.s +write.s +cerror.s +error.s +pause.s +alarm.s +ftime.s diff --git a/mach/i86/libsys/Makefile b/mach/i86/libsys/Makefile new file mode 100644 index 00000000..2e2f7129 --- /dev/null +++ b/mach/i86/libsys/Makefile @@ -0,0 +1,21 @@ +# $Header$ +MACH=l86 +all: tail_mon +install: all + ../../install tail_mon + +cmp: all + -../../compare tail_mon + +tail_mon: + ASAR=aal ; export ASAR ;\ + march . tail_mon + +clean: + rm -f *.o + +opr : + make pr | opr + +pr: + @ar pv tail_mon.a diff --git a/mach/i86/libsys/_exit.s b/mach/i86/libsys/_exit.s new file mode 100644 index 00000000..0f138b88 --- /dev/null +++ b/mach/i86/libsys/_exit.s @@ -0,0 +1,10 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define __exit +.sect .text +__exit: + mov bx,sp + xor ax,ax + push ax ! unused memory + push 2(bx) + push ax ! dummy return address + int 0x81 diff --git a/mach/i86/libsys/abort.s b/mach/i86/libsys/abort.s new file mode 100644 index 00000000..bd6d7544 --- /dev/null +++ b/mach/i86/libsys/abort.s @@ -0,0 +1,13 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _abort +.extern _abort +_abort: push si + push di + push bp + mov bp,sp + int 128 + mov sp,bp + pop bp + pop di + pop si + ret diff --git a/mach/i86/libsys/access.s b/mach/i86/libsys/access.s new file mode 100644 index 00000000..f0059aa0 --- /dev/null +++ b/mach/i86/libsys/access.s @@ -0,0 +1,9 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _access +.extern _access, cerror +_access: int 0xa1 + jb 9f + xor ax,ax + ret +9: + jmp cerror diff --git a/mach/i86/libsys/alarm.s b/mach/i86/libsys/alarm.s new file mode 100644 index 00000000..df92e892 --- /dev/null +++ b/mach/i86/libsys/alarm.s @@ -0,0 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _alarm +.extern _alarm, cerror +_alarm: int 0x9b + jb 9f + ret +9: + jmp cerror diff --git a/mach/i86/libsys/brk.s b/mach/i86/libsys/brk.s new file mode 100644 index 00000000..0ddc5874 --- /dev/null +++ b/mach/i86/libsys/brk.s @@ -0,0 +1,39 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _brk +.define xbrk +.define np +.extern _brk +.extern xbrk +.extern np, cerror +_brk: + mov bx,sp + mov ax,2(bx) + mov cx,sp + sub cx,128 + jbe 1f + mov bx,(np) + mov (np),ax + sub ax,bx + jbe 2f + call xbrk +2: + xor ax,ax + ret +1: + mov ax,0xc + jmp cerror +xbrk: + push di + mov di,bx + mov cx,ax + xor ax,ax + shr cx,1 + repz stos + jae 3f + stosb +3: + pop di + ret +.sect .data +np: .data2 0 +.sect .text diff --git a/mach/i86/libsys/cerror.s b/mach/i86/libsys/cerror.s new file mode 100644 index 00000000..fad3993d --- /dev/null +++ b/mach/i86/libsys/cerror.s @@ -0,0 +1,9 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define cerror +.extern cerror +.extern _errno +cerror: + mov (_errno),ax + mov dx,-1 + mov ax,dx + ret diff --git a/mach/i86/libsys/chdir.s b/mach/i86/libsys/chdir.s new file mode 100644 index 00000000..c5012f94 --- /dev/null +++ b/mach/i86/libsys/chdir.s @@ -0,0 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _chdir +.extern _chdir, cerror +_chdir: int 0x8c + jb 9f + xor ax,ax + ret +9: jmp cerror diff --git a/mach/i86/libsys/chmod.s b/mach/i86/libsys/chmod.s new file mode 100644 index 00000000..298babef --- /dev/null +++ b/mach/i86/libsys/chmod.s @@ -0,0 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _chmod +.extern _chmod, cerror +_chmod: int 0x8f + jb 9f + xor ax,ax + ret +9: jmp cerror diff --git a/mach/i86/libsys/chown.s b/mach/i86/libsys/chown.s new file mode 100644 index 00000000..dc39ab6a --- /dev/null +++ b/mach/i86/libsys/chown.s @@ -0,0 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _chown +.extern _chown, cerror +_chown: int 0x90 + jb 9f + xor ax,ax + ret +9: jmp cerror diff --git a/mach/i86/libsys/cleanup.s b/mach/i86/libsys/cleanup.s new file mode 100644 index 00000000..61db5665 --- /dev/null +++ b/mach/i86/libsys/cleanup.s @@ -0,0 +1,9 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define __cleanup +.extern __cleanup +__cleanup: + push bp + mov bp,sp +mov sp,bp +pop bp +ret diff --git a/mach/i86/libsys/close.s b/mach/i86/libsys/close.s new file mode 100644 index 00000000..29e7b03d --- /dev/null +++ b/mach/i86/libsys/close.s @@ -0,0 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _close +.extern _close, cerror +_close: int 0x86 + jb 9f + xor ax,ax + ret +9: jmp cerror diff --git a/mach/i86/libsys/compmodule b/mach/i86/libsys/compmodule new file mode 100755 index 00000000..8ec2f672 --- /dev/null +++ b/mach/i86/libsys/compmodule @@ -0,0 +1,4 @@ +if i86 -c $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 +fi diff --git a/mach/i86/libsys/creat.s b/mach/i86/libsys/creat.s new file mode 100644 index 00000000..ababb864 --- /dev/null +++ b/mach/i86/libsys/creat.s @@ -0,0 +1,7 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _creat +.extern _creat, cerror +_creat: int 0x88 + jb 9f + ret +9: jmp cerror diff --git a/mach/i86/libsys/dup.s b/mach/i86/libsys/dup.s new file mode 100644 index 00000000..d0e6ba09 --- /dev/null +++ b/mach/i86/libsys/dup.s @@ -0,0 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text + +.define _dup +.extern _dup, cerror +_dup: int 0xc9 + jb 9f + ret +9: jmp cerror diff --git a/mach/i86/libsys/error.s b/mach/i86/libsys/error.s new file mode 100644 index 00000000..ec32cc39 --- /dev/null +++ b/mach/i86/libsys/error.s @@ -0,0 +1,7 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.define _errno +.extern _errno + +_errno: + .space 2 +.sect .text diff --git a/mach/i86/libsys/exece.s b/mach/i86/libsys/exece.s new file mode 100644 index 00000000..c2495ad6 --- /dev/null +++ b/mach/i86/libsys/exece.s @@ -0,0 +1,7 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _exece +.extern _exece, cerror +_exece: int 0xdb + jb 9f + ret +9: jmp cerror diff --git a/mach/i86/libsys/execl.s b/mach/i86/libsys/execl.s new file mode 100644 index 00000000..9f2130f2 --- /dev/null +++ b/mach/i86/libsys/execl.s @@ -0,0 +1,20 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text + +.define _execl +.extern _execl, _environ, _execve +_execl: + push si + push di + push bp + mov bp,sp + push (_environ) + lea ax,10(bp) + push ax + push 8(bp) + call _execve + add sp,6 + mov sp,bp + pop bp + pop di + pop si + ret diff --git a/mach/i86/libsys/execle.s b/mach/i86/libsys/execle.s new file mode 100644 index 00000000..bba54083 --- /dev/null +++ b/mach/i86/libsys/execle.s @@ -0,0 +1,24 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _execle +.extern _execle, _execve +_execle: + push si + push di + push bp + mov bp,sp + lea si,10(bp) +1: mov di,si + add si,2 + cmp (di),0 + jne 1b + push (si) + lea ax,10(bp) + push ax + push 8(bp) + call _execve + add sp,6 + mov sp,bp + pop bp + pop di + pop si + ret diff --git a/mach/i86/libsys/execv.s b/mach/i86/libsys/execv.s new file mode 100644 index 00000000..bbbc2e63 --- /dev/null +++ b/mach/i86/libsys/execv.s @@ -0,0 +1,12 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _execv +.extern _execv, _environ, cerror +_execv: + mov bx,sp + push (_environ) + push 4(bx) + push 2(bx) + push ax + int 0xbb + add sp,8 + jmp cerror diff --git a/mach/i86/libsys/execve.s b/mach/i86/libsys/execve.s new file mode 100644 index 00000000..964b6b9c --- /dev/null +++ b/mach/i86/libsys/execve.s @@ -0,0 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _execve +.extern _execve, cerror +_execve: + int 0x8b + jb 9f + ret +9: jmp cerror diff --git a/mach/i86/libsys/exit.s b/mach/i86/libsys/exit.s new file mode 100644 index 00000000..28cfca10 --- /dev/null +++ b/mach/i86/libsys/exit.s @@ -0,0 +1,13 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _exit +.extern _exit, __cleanup, __exit +_exit: + push bp + mov bp,sp +call __cleanup +push 4(bp) +call __exit +pop si +mov sp,bp +pop bp +ret diff --git a/mach/i86/libsys/fork.s b/mach/i86/libsys/fork.s new file mode 100644 index 00000000..e280f58d --- /dev/null +++ b/mach/i86/libsys/fork.s @@ -0,0 +1,11 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _fork +.extern _fork, cerror +_fork: int 0x82 + jmp 1f + jae 2f + jmp cerror +1: + xor ax,ax +2: + ret diff --git a/mach/i86/libsys/fstat.s b/mach/i86/libsys/fstat.s new file mode 100644 index 00000000..d7977f9e --- /dev/null +++ b/mach/i86/libsys/fstat.s @@ -0,0 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _fstat +.extern _fstat, cerror +_fstat: int 0x9c + jb 9f + xor ax,ax + ret +9: jmp cerror diff --git a/mach/i86/libsys/ftime.s b/mach/i86/libsys/ftime.s new file mode 100644 index 00000000..be3604fd --- /dev/null +++ b/mach/i86/libsys/ftime.s @@ -0,0 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _ftime +.extern _ftime, cerror +_ftime: int 0xa3 + jb 9f + ret +9: + jmp cerror diff --git a/mach/i86/libsys/getgid.s b/mach/i86/libsys/getgid.s new file mode 100644 index 00000000..dc769aec --- /dev/null +++ b/mach/i86/libsys/getgid.s @@ -0,0 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _getgid +.extern _getgid, cerror +_getgid: int 0xaf + jb 9f + ret +9: + jmp cerror diff --git a/mach/i86/libsys/getpid.s b/mach/i86/libsys/getpid.s new file mode 100644 index 00000000..8300a7af --- /dev/null +++ b/mach/i86/libsys/getpid.s @@ -0,0 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _getpid +.extern _getpid, cerror +_getpid: int 0x94 + jb 9f + ret +9: + jmp cerror diff --git a/mach/i86/libsys/getuid.s b/mach/i86/libsys/getuid.s new file mode 100644 index 00000000..ff5d6fa8 --- /dev/null +++ b/mach/i86/libsys/getuid.s @@ -0,0 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _getuid +.extern _getuid, cerror +_getuid: int 0x98 + jb 9f + ret +9: + jmp cerror diff --git a/mach/i86/libsys/gtty.s b/mach/i86/libsys/gtty.s new file mode 100644 index 00000000..4e8b0e6c --- /dev/null +++ b/mach/i86/libsys/gtty.s @@ -0,0 +1,15 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _gtty +.extern _gtty, _ioctl +_gtty: + push bp + mov bp,sp +push 6(bp) +mov ax,29704 +push ax +push 4(bp) +call _ioctl +add sp,6 +mov sp,bp +pop bp +ret diff --git a/mach/i86/libsys/ioctl.s b/mach/i86/libsys/ioctl.s new file mode 100644 index 00000000..b7e24279 --- /dev/null +++ b/mach/i86/libsys/ioctl.s @@ -0,0 +1,7 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _ioctl +.extern _ioctl, cerror +_ioctl: int 0xb6 + jb 9f + ret +9: jmp cerror diff --git a/mach/i86/libsys/kill.s b/mach/i86/libsys/kill.s new file mode 100644 index 00000000..3c6ce526 --- /dev/null +++ b/mach/i86/libsys/kill.s @@ -0,0 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _kill +.extern _kill, cerror +_kill: int 0xa5 + jb 9f + xor ax,ax + ret +9: jmp cerror diff --git a/mach/i86/libsys/link.s b/mach/i86/libsys/link.s new file mode 100644 index 00000000..0be0cf2e --- /dev/null +++ b/mach/i86/libsys/link.s @@ -0,0 +1,7 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _link +.extern _link, cerror +_link: int 0x89 + jb 9f + ret +9: jmp cerror diff --git a/mach/i86/libsys/lseek.s b/mach/i86/libsys/lseek.s new file mode 100644 index 00000000..a54326b1 --- /dev/null +++ b/mach/i86/libsys/lseek.s @@ -0,0 +1,7 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _lseek +.extern _lseek, cerror +_lseek: int 0x93 + jb 9f + ret +9: jmp cerror diff --git a/mach/i86/libsys/mknod.s b/mach/i86/libsys/mknod.s new file mode 100644 index 00000000..0d6aa3db --- /dev/null +++ b/mach/i86/libsys/mknod.s @@ -0,0 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _mknod +.extern _mknod, cerror +_mknod: int 0x8e + jb 9f + xor ax,ax + ret +9: jmp cerror diff --git a/mach/i86/libsys/mount.s b/mach/i86/libsys/mount.s new file mode 100644 index 00000000..ad3e4b2c --- /dev/null +++ b/mach/i86/libsys/mount.s @@ -0,0 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _mount +.extern _mount, cerror +_mount: int 0x95 + jb 9f + xor ax,ax + ret +9: jmp cerror diff --git a/mach/i86/libsys/nice.s b/mach/i86/libsys/nice.s new file mode 100644 index 00000000..1e897742 --- /dev/null +++ b/mach/i86/libsys/nice.s @@ -0,0 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _nice +.extern _nice, cerror +_nice: int 0xa2 + jb 9f + ret +9: + jmp cerror diff --git a/mach/i86/libsys/open.s b/mach/i86/libsys/open.s new file mode 100644 index 00000000..2cf6df3c --- /dev/null +++ b/mach/i86/libsys/open.s @@ -0,0 +1,7 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _open +.extern _open, cerror +_open: int 0x85 + jb 9f + ret +9: jmp cerror diff --git a/mach/i86/libsys/pause.s b/mach/i86/libsys/pause.s new file mode 100644 index 00000000..05a6fe70 --- /dev/null +++ b/mach/i86/libsys/pause.s @@ -0,0 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _pause +.extern _pause, cerror +_pause: int 0x9d + jb 9f + ret +9: + jmp cerror diff --git a/mach/i86/libsys/pipe.s b/mach/i86/libsys/pipe.s new file mode 100644 index 00000000..47865c82 --- /dev/null +++ b/mach/i86/libsys/pipe.s @@ -0,0 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _pipe +.extern _pipe, cerror +_pipe: int 0xaa + jb 9f + xor ax,ax + ret +9: jmp cerror diff --git a/mach/i86/libsys/profil.s b/mach/i86/libsys/profil.s new file mode 100644 index 00000000..52e3b7fb --- /dev/null +++ b/mach/i86/libsys/profil.s @@ -0,0 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _profil +.extern _profil, cerror +_profil: int 0xac + jb 9f + ret +9: + jmp cerror diff --git a/mach/i86/libsys/read.s b/mach/i86/libsys/read.s new file mode 100644 index 00000000..a9839bf6 --- /dev/null +++ b/mach/i86/libsys/read.s @@ -0,0 +1,7 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _read +.extern _read, cerror +_read: int 0x83 + jb 9f + ret +9: jmp cerror diff --git a/mach/i86/libsys/sbrk.s b/mach/i86/libsys/sbrk.s new file mode 100644 index 00000000..b3b4e6a2 --- /dev/null +++ b/mach/i86/libsys/sbrk.s @@ -0,0 +1,25 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _sbrk +.extern _sbrk, xbrk, cerror +_sbrk: +push bp +mov bp,sp +mov ax,4(bp) +mov bx,(np) +add ax,bx +mov cx,sp +sub cx,128 +sub cx,ax +jbe 1f +mov (np),ax +sub ax,bx +jbe 2f +call xbrk +2: +mov ax,bx +pop bp +ret +1: +mov ax,0xc +pop bp +jmp cerror diff --git a/mach/i86/libsys/setgid.s b/mach/i86/libsys/setgid.s new file mode 100644 index 00000000..52f9b11e --- /dev/null +++ b/mach/i86/libsys/setgid.s @@ -0,0 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _setgid +.extern _setgid, cerror +setgid: int 0xae + jb 9f + xor ax,ax + ret +9: jmp cerror diff --git a/mach/i86/libsys/setuid.s b/mach/i86/libsys/setuid.s new file mode 100644 index 00000000..e27c0fd1 --- /dev/null +++ b/mach/i86/libsys/setuid.s @@ -0,0 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _setuid +.extern _setuid, cerror +_setuid: int 0x97 + jb 9f + xor ax,ax + ret +9: jmp cerror diff --git a/mach/i86/libsys/signal.s b/mach/i86/libsys/signal.s new file mode 100644 index 00000000..cc23eb83 --- /dev/null +++ b/mach/i86/libsys/signal.s @@ -0,0 +1,62 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _signal +.extern _signal, cerror +NSIG=16 +_signal: mov bx,sp + mov cx,4(bx) + mov bx,2(bx) + cmp bx,NSIG + jae 1f + shl bx,1 + mov dx,dvect(bx) + cmp cx,1 + jbe 2f + mov dvect(bx),cx + mov bx,sp + mov 4(bx),enter + mov bx,dx + int 0xb0 + mov dx,bx + mov bx,sp + mov 4(bx),cx + jb 3f + jmp 4f +2: + int 0xb0 + jb 3f + mov dvect(bx),cx +4: + cmp ax,1 + jbe 5f + mov ax,dx +5: + ret +1: + mov ax,22 +3: + jmp cerror + +enter: + push bx + push cx + push dx + push di + push si + mov bx,sp + mov di,10(bx) + mov 10(bx),ax + push di + shl di,1 + call dvect(di) + add sp,2 + pop si + pop di + pop dx + pop cx + pop bx + pop ax + popf + ret +.sect .bss +dvect: .space 2*NSIG +.sect .text diff --git a/mach/i86/libsys/stat.s b/mach/i86/libsys/stat.s new file mode 100644 index 00000000..31153b4a --- /dev/null +++ b/mach/i86/libsys/stat.s @@ -0,0 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _stat +.extern _stat, cerror +_stat: int 0x92 + jb 9f + xor ax,ax + ret +9: jmp cerror diff --git a/mach/i86/libsys/stty.s b/mach/i86/libsys/stty.s new file mode 100644 index 00000000..701bb18a --- /dev/null +++ b/mach/i86/libsys/stty.s @@ -0,0 +1,15 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _stty +.extern _stty, _ioctl +_stty: + push bp + mov bp,sp +push 6(bp) +mov ax,29705 +push ax +push 4(bp) +call _ioctl +add sp,6 +mov sp,bp +pop bp +ret diff --git a/mach/i86/libsys/sync.s b/mach/i86/libsys/sync.s new file mode 100644 index 00000000..973cc27a --- /dev/null +++ b/mach/i86/libsys/sync.s @@ -0,0 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _sync +.extern _sync, cerror +_sync: int 0xa4 + jb 9f + ret +9: + jmp cerror diff --git a/mach/i86/libsys/time.s b/mach/i86/libsys/time.s new file mode 100644 index 00000000..ec87adb6 --- /dev/null +++ b/mach/i86/libsys/time.s @@ -0,0 +1,27 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _time +.extern _time, _ftime +_time: + push si + push di + push bp + mov bp,sp + sub sp,10 + lea ax,-10(bp) + push ax + call _ftime + add sp,2 + cmp 8(bp),0 + je 1f + mov ax,-10(bp) + mov dx,-8(bp) + mov di,8(bp) + mov (di),ax + mov 2(di),dx +1: mov ax,-10(bp) + mov dx,-8(bp) + mov sp,bp + pop bp + pop di + pop si + ret diff --git a/mach/i86/libsys/umount.s b/mach/i86/libsys/umount.s new file mode 100644 index 00000000..bee18150 --- /dev/null +++ b/mach/i86/libsys/umount.s @@ -0,0 +1,9 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _umount +.extern _umount, cerror +_umount: int 0x96 + jb 9f + xor ax,ax + ret +9: + jmp cerror diff --git a/mach/i86/libsys/unlink.s b/mach/i86/libsys/unlink.s new file mode 100644 index 00000000..6d545997 --- /dev/null +++ b/mach/i86/libsys/unlink.s @@ -0,0 +1,8 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _unlink +.extern _unlink, cerror +_unlink: int 0x8a + jb 9f + xor ax,ax + ret +9: jmp cerror diff --git a/mach/i86/libsys/wait.s b/mach/i86/libsys/wait.s new file mode 100644 index 00000000..ae27c3bd --- /dev/null +++ b/mach/i86/libsys/wait.s @@ -0,0 +1,17 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _wait +.extern _wait, cerror +_wait: + mov bx,sp + mov ax,2 ! void info about unused memory + ! Should be 0 according to /usr/include/sys.s, but + ! that doesn't work + push ax + push 2(bx) + push ax ! dummy return address + int 0x87 + jb 9f + add sp,6 + ret +9: add sp,6 + jmp cerror diff --git a/mach/i86/libsys/write.s b/mach/i86/libsys/write.s new file mode 100644 index 00000000..935d3eea --- /dev/null +++ b/mach/i86/libsys/write.s @@ -0,0 +1,7 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _write +.extern _write, cerror +_write: int 0x84 + jb 9f + ret +9: jmp cerror From 93ae60e5d6497d269f5c3c8531e9759a503609d6 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 8 Jan 1987 11:04:25 +0000 Subject: [PATCH 0442/1625] "l86" --> "i86". --- mach/i86/libcc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/i86/libcc/Makefile b/mach/i86/libcc/Makefile index c80e2a60..07b125b0 100644 --- a/mach/i86/libcc/Makefile +++ b/mach/i86/libcc/Makefile @@ -1,5 +1,5 @@ MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=l86" "SUF=o" "ASAR=aal" +MACHDEF="MACH=i86" "SUF=o" "ASAR=aal" STDIO="PREF=cc" "SUB=.1s" "SRC=lang/cem/libcc/stdio" GEN="PREF=cc" "SUB=.2g" "SRC=lang/cem/libcc/gen" MON="PREF=mon" "SRC=lang/cem/libcc/mon" From 9bc436271f2411da7fbd6b10d63fe91286d4eb1b Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 8 Jan 1987 11:09:06 +0000 Subject: [PATCH 0443/1625] adapted to get .o files --- mach/i86/libbc/Makefile | 4 ++-- mach/i86/libbc/compmodule | 8 ++++++-- mach/i86/libpc/Makefile | 4 ++-- mach/i86/libpc/compmodule | 8 ++++++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/mach/i86/libbc/Makefile b/mach/i86/libbc/Makefile index 69179491..0b1a1cb5 100644 --- a/mach/i86/libbc/Makefile +++ b/mach/i86/libbc/Makefile @@ -1,5 +1,5 @@ MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=i86" "SUF=s" +MACHDEF="MACH=i86" "SUF=o" "ASAR=aal" BCDEF="PREF=bc" "SUB=" "SRC=lang/basic/lib" install: @@ -11,7 +11,7 @@ cmp: -../../compare tail_bc clean: - -rm -f *.old *.[ce$(SUF)] tail* head* + -rm -f *.old *.[ce$(SUF)] tail* head* opr: make pr | opr diff --git a/mach/i86/libbc/compmodule b/mach/i86/libbc/compmodule index 2bcf66ca..6327cb99 100755 --- a/mach/i86/libbc/compmodule +++ b/mach/i86/libbc/compmodule @@ -1,2 +1,6 @@ -${MACH?ack} -I../../../h ${MACHFL?} $1 1>&2 -echo `basename $1 $2`.s +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then + echo `basename $1 $2`.o +else + exit 1 +fi diff --git a/mach/i86/libpc/Makefile b/mach/i86/libpc/Makefile index 5c669cf0..546722ac 100644 --- a/mach/i86/libpc/Makefile +++ b/mach/i86/libpc/Makefile @@ -1,5 +1,5 @@ MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=i86" "SUF=s" +MACHDEF="MACH=i86" "SUF=o" "ASAR=aal" PCDEF="PREF=pc" "SUB=" "SRC=lang/pc/libpc" install: @@ -11,7 +11,7 @@ cmp: -../../compare tail_pc clean: - -rm -f *.old *.[ce$(SUF)] tail* head* + -rm -f *.old *.[ce$(SUF)] tail* head* opr: make pr | opr diff --git a/mach/i86/libpc/compmodule b/mach/i86/libpc/compmodule index 2bcf66ca..6327cb99 100755 --- a/mach/i86/libpc/compmodule +++ b/mach/i86/libpc/compmodule @@ -1,2 +1,6 @@ -${MACH?ack} -I../../../h ${MACHFL?} $1 1>&2 -echo `basename $1 $2`.s +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then + echo `basename $1 $2`.o +else + exit 1 +fi From 82aa07e7b785f657ae87243d27bef6d93ce3c2a2 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 8 Jan 1987 11:22:44 +0000 Subject: [PATCH 0444/1625] New description file, using LED. --- lib/i86/descr | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/lib/i86/descr b/lib/i86/descr index 598aaaec..89fbb865 100644 --- a/lib/i86/descr +++ b/lib/i86/descr @@ -5,11 +5,13 @@ var s=2 var l=4 var f=4 var d=8 -var NAME=i8086 +var NAME=i86 var M=i86 var LIB=lib/{M}/tail_ var RT=lib/{M}/head_ +var CPP_F=-Dunix var INCLUDES=-I{EM}/include -I/usr/include +var ALIGN=-a0:2 -a1:2 -a2:2 -a3:2 name be from .m.g to .s @@ -18,19 +20,31 @@ name be stdout need .e end -name asld - from .s.a - to .out - outfile a.out +name as + from .s + to .o program {EM}/lib/{M}/as + args - -o > < + prep cond +end +name led + from .o.a + to .out + program {EM}/lib/em_led mapflag -l* LNAME={EM}/{LIB}* - mapflag -i IFILE={EM}/{RT}i - args {IFILE?} (.e:{HEAD}={EM}/{RT}em) \ - ({RTS}:.b.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \ + mapflag -i SEPID=-b1:0 + args (.e:{HEAD}={ALIGN} {SEPID?} {EM}/{RT}em) \ +({RTS}:.b.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \ (.p:{TAIL}={EM}/{LIB}pc) \ (.b:{TAIL}={EM}/{LIB}bc) \ (.b.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \ - (.b.c.p.e:{TAIL}={EM}/{LIB}alo) (.b.c.p:{TAIL}={EM}/{LIB}mon) \ - (.e:{TAIL}={EM}/{LIB}em) + (.e:{TAIL}={EM}/{LIB}em {EM}/{LIB}mon {EM}/lib/{M}/end_em) linker end +name cv + from .out + to .cv + program {EM}/lib/{M}/cv_ix + args < > + outfile a.out +end From 33384848318c767e614ba2ee2548afa8bd8d0f2b Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 8 Jan 1987 12:38:05 +0000 Subject: [PATCH 0445/1625] wrong number of parameters no longer is an error. --- util/cpp/replace.c | 2 +- util/cpp/scan.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/util/cpp/replace.c b/util/cpp/replace.c index e8e78d30..846cadf5 100644 --- a/util/cpp/replace.c +++ b/util/cpp/replace.c @@ -156,7 +156,7 @@ macro2buffer(idef, actpars, siztext) /* copy the text of the actual parameter into the replacement text */ - for (p = actpars[n - 1]; p && *p; p++) { + for (p = actpars[n - 1]; *p; p++) { text[pos++] = *p; if (pos == size) text = Srealloc(text, size += RTEXTSIZE); diff --git a/util/cpp/scan.c b/util/cpp/scan.c index 8be12de2..5b6a51ec 100644 --- a/util/cpp/scan.c +++ b/util/cpp/scan.c @@ -57,12 +57,12 @@ getactuals(idef) /* argument mismatch: too many or too few actual parameters. */ - error("argument mismatch, %s", idef->id_text); + warning("argument mismatch, %s", idef->id_text); while (++nr_of_params < acnt) { /* too few paraeters: remaining actuals are "" */ - actparams[nr_of_params] = (char *) 0; + actparams[nr_of_params] = ""; } } From af59e1769ce888427180611d02bda3ccd96085da Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 8 Jan 1987 12:42:44 +0000 Subject: [PATCH 0446/1625] Generate line directives that are similar to the ones generated by the Reiser preprocessor. --- util/cpp/preprocess.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/cpp/preprocess.c b/util/cpp/preprocess.c index bd05c568..c8347afc 100644 --- a/util/cpp/preprocess.c +++ b/util/cpp/preprocess.c @@ -51,7 +51,7 @@ preprocess(fn) fn = FileName; lineno = LineNumber; - sprint(p, "#line %d \"%s\"\n", LineNumber, + sprint(p, "# %d \"%s\"\n", LineNumber, FileName); while (*p) { echo(*p++); From 30a46b2e5fbe7071820037ea988f49ec1d3f5dfc Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 8 Jan 1987 14:03:43 +0000 Subject: [PATCH 0447/1625] Added bitwise EX_OR and EX_AND. --- h/cgg_cg.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/h/cgg_cg.h b/h/cgg_cg.h index ea8c4a16..ae3d2b5c 100644 --- a/h/cgg_cg.h +++ b/h/cgg_cg.h @@ -120,6 +120,8 @@ typedef struct exprnode *node_p; #define EX_HIGHW 38 #define EX_INREG 39 #define EX_REGVAR 40 +#define EX_OR 41 +#define EX_AND 42 typedef struct { /* to stack coercions */ From 08ced09518462c7eb17c5b142b1336897743446f Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 8 Jan 1987 14:09:14 +0000 Subject: [PATCH 0448/1625] small adaption to "awayreg". --- mach/proto/cg/reg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/proto/cg/reg.c b/mach/proto/cg/reg.c index bc94e896..b9db3a4c 100644 --- a/mach/proto/cg/reg.c +++ b/mach/proto/cg/reg.c @@ -99,7 +99,7 @@ awayreg(regno) { if (rp->r_contents.t_token == -1) { if (rp->r_contents.t_att[0].ar == regno) erasereg(rp-machregs); - } else { + } else if (rp->r_contents.t_token > 0) { tdp= & tokens[rp->r_contents.t_token]; for (i=0;it_type[i] == EV_REG && From 826157760d9cbe99736f2df4b4f4388cc6f27cd2 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 8 Jan 1987 14:10:02 +0000 Subject: [PATCH 0449/1625] fix to prevent loop resulting in stack overflow --- mach/proto/ncg/reg.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mach/proto/ncg/reg.c b/mach/proto/ncg/reg.c index fc3546c6..9f645fbe 100644 --- a/mach/proto/ncg/reg.c +++ b/mach/proto/ncg/reg.c @@ -71,6 +71,12 @@ getrefcount(regno) { erasereg(regno) { register struct reginfo *rp; + register int i; + + rp = &machregs[regno]; + rp->r_contents.t_token = 0; + for (i=0;ir_contents.t_att[i].aw = 0; #if MAXMEMBERS==0 awayreg(regno); @@ -86,11 +92,6 @@ awayreg(regno) { register tkdef_p tdp; register i; - rp = &machregs[regno]; - rp->r_contents.t_token = 0; - for (i=0;ir_contents.t_att[i].aw = 0; - /* Now erase recursively all registers containing * something using this one */ @@ -98,7 +99,7 @@ awayreg(regno) { if (rp->r_contents.t_token == -1) { if (rp->r_contents.t_att[0].ar == regno) erasereg(rp-machregs); - } else { + } else if (rp->r_contents.t_token > 0) { tdp= & tokens[rp->r_contents.t_token]; for (i=0;it_type[i] == EV_REG && From 5b65b239f13de4446552faf88a8842de1a097784 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 8 Jan 1987 14:11:23 +0000 Subject: [PATCH 0450/1625] Added bitwise and and or operators --- mach/proto/ncg/compute.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mach/proto/ncg/compute.c b/mach/proto/ncg/compute.c index d023fd89..90b7d13f 100644 --- a/mach/proto/ncg/compute.c +++ b/mach/proto/ncg/compute.c @@ -79,6 +79,8 @@ char opdesc[] = { 0, /* EX_HIGHW */ LLDEF, /* EX_INREG */ LLDEF, /* EX_REGVAR */ + LLDEF|RLDEF, /* EX_OR */ + LLDEF|RLDEF, /* EX_AND */ }; string salloc(),strcpy(),strcat(); @@ -290,6 +292,14 @@ result_t compute(node) register node_p node; { assert(leaf1.e_typ == EV_INT && leaf2.e_typ == EV_INT); result.e_v.e_con = leaf1.e_v.e_con - leaf2.e_v.e_con; return(result); + case EX_OR: + assert(leaf1.e_typ == EV_INT && leaf2.e_typ == EV_INT); + result.e_v.e_con = leaf1.e_v.e_con | leaf2.e_v.e_con; + return(result); + case EX_AND: + assert(leaf1.e_typ == EV_INT && leaf2.e_typ == EV_INT); + result.e_v.e_con = leaf1.e_v.e_con & leaf2.e_v.e_con; + return(result); case EX_TIMES: assert(leaf1.e_typ == EV_INT && leaf2.e_typ == EV_INT); result.e_v.e_con = leaf1.e_v.e_con * leaf2.e_v.e_con; From cf083c56a36925095f11556139547d66d1ece62a Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 8 Jan 1987 14:21:56 +0000 Subject: [PATCH 0451/1625] Added xor-oprator --- h/cgg_cg.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/h/cgg_cg.h b/h/cgg_cg.h index ae3d2b5c..e10a7cae 100644 --- a/h/cgg_cg.h +++ b/h/cgg_cg.h @@ -121,7 +121,8 @@ typedef struct exprnode *node_p; #define EX_INREG 39 #define EX_REGVAR 40 #define EX_OR 41 -#define EX_AND 42 +#define EX_XOR 42 +#define EX_AND 43 typedef struct { /* to stack coercions */ From 11a429eb996c1d09d1d6503140f605de10ed63c7 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 8 Jan 1987 14:22:32 +0000 Subject: [PATCH 0452/1625] Added bitwise operators --- util/ncgg/cgg.y | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/util/ncgg/cgg.y b/util/ncgg/cgg.y index 58c56f14..5bce1787 100644 --- a/util/ncgg/cgg.y +++ b/util/ncgg/cgg.y @@ -98,6 +98,9 @@ iocc_t iops[20]; %left OR2 %left AND2 +%left '|' +%left '^' +%left '&' %left CMPEQ,CMPNE %left CMPLT,CMPLE,CMPGT,CMPGE %left RSHIFT,LSHIFT @@ -958,6 +961,12 @@ expr { $$ = make_expr(TYPBOOL,EX_OR2,b_expr($1),b_expr($3)); } | expr AND2 expr { $$ = make_expr(TYPBOOL,EX_AND2,b_expr($1),b_expr($3)); } + | expr '|' expr + { $$ = make_expr(TYPINT,EX_OR,i_expr($1),i_expr($3)); } + | expr '^' expr + { $$ = make_expr(TYPINT,EX_XOR,i_expr($1),i_expr($3)); } + | expr '&' expr + { $$ = make_expr(TYPINT,EX_AND,i_expr($1),i_expr($3)); } | expr '+' expr { $$ = sum_expr($1,$3); } | expr '-' expr From 8c67176f3d1bbaf32a420a000317836898485cd2 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 8 Jan 1987 14:27:07 +0000 Subject: [PATCH 0453/1625] Added exclusive or operator --- mach/proto/ncg/compute.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mach/proto/ncg/compute.c b/mach/proto/ncg/compute.c index 90b7d13f..a47c0655 100644 --- a/mach/proto/ncg/compute.c +++ b/mach/proto/ncg/compute.c @@ -80,6 +80,7 @@ char opdesc[] = { LLDEF, /* EX_INREG */ LLDEF, /* EX_REGVAR */ LLDEF|RLDEF, /* EX_OR */ + LLDEF|RLDEF, /* EX_XOR */ LLDEF|RLDEF, /* EX_AND */ }; @@ -296,6 +297,10 @@ result_t compute(node) register node_p node; { assert(leaf1.e_typ == EV_INT && leaf2.e_typ == EV_INT); result.e_v.e_con = leaf1.e_v.e_con | leaf2.e_v.e_con; return(result); + case EX_XOR: + assert(leaf1.e_typ == EV_INT && leaf2.e_typ == EV_INT); + result.e_v.e_con = leaf1.e_v.e_con ^ leaf2.e_v.e_con; + return(result); case EX_AND: assert(leaf1.e_typ == EV_INT && leaf2.e_typ == EV_INT); result.e_v.e_con = leaf1.e_v.e_con & leaf2.e_v.e_con; From 6e706da0f486b1781248e8c836f57de8f43196c0 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 8 Jan 1987 14:57:18 +0000 Subject: [PATCH 0454/1625] made error in macro parameter count into a warning --- lang/cem/cemcom/scan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lang/cem/cemcom/scan.c b/lang/cem/cemcom/scan.c index d75f8743..2dde8b79 100644 --- a/lang/cem/cemcom/scan.c +++ b/lang/cem/cemcom/scan.c @@ -61,12 +61,12 @@ getactuals(idef) /* argument mismatch: too many or too few actual parameters. */ - lexerror("argument mismatch, %s", idef->id_text); + lexwarning("argument mismatch, %s", idef->id_text); while (++nr_of_params < acnt) { /* too few paraeters: remaining actuals are "" */ - actparams[nr_of_params] = (char *) 0; + actparams[nr_of_params] = ""; } } From e334c5ebfc461bc48721c9960c1b514e69aee491 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 8 Jan 1987 16:04:20 +0000 Subject: [PATCH 0455/1625] rd_arhdr now returns 1 if it succeeds, and 0 at end-of-file. --- modules/src/object/rd_arhdr.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/modules/src/object/rd_arhdr.c b/modules/src/object/rd_arhdr.c index 00a1ca7e..691799fb 100644 --- a/modules/src/object/rd_arhdr.c +++ b/modules/src/object/rd_arhdr.c @@ -1,6 +1,7 @@ #include #include "object.h" +int rd_arhdr(fd, arhdr) register struct ar_hdr *arhdr; { @@ -11,9 +12,14 @@ rd_arhdr(fd, arhdr) char buf[AR_TOTAL]; register char *c = buf; register char *p = arhdr->ar_name; - register int i = 14; + register int i; - rd_bytes(fd, c, (long) AR_TOTAL); + i = read(fd, c, AR_TOTAL); + if (i == 0) return 0; + if (i < 0 || i != AR_TOTAL) { + rd_fatal(); + } + i = 14; while (i--) { *p++ = *c++; } @@ -24,6 +30,12 @@ rd_arhdr(fd, arhdr) arhdr->ar_size = get4(c); } #if ! (BYTES_REVERSED || WORDS_REVERSED) - else rd_bytes(fd, (char *) arhdr, (long) AR_TOTAL); + else { + register int i; + i = read(fd, (char *) arhdr, AR_TOTAL); + if (i == 0) return 0; + if (i < 0 || i != AR_TOTAL) rd_fatal(); + } #endif + return 1; } From 31ae1f0d95d5530f9a605575b0defcc4ee4f9c13 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 8 Jan 1987 16:05:52 +0000 Subject: [PATCH 0456/1625] arhdr --> ar_hdr. updated docs on rd_arhdr. --- modules/src/object/object.3 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/src/object/object.3 b/modules/src/object/object.3 index 79ebf09f..e01cb17b 100644 --- a/modules/src/object/object.3 +++ b/modules/src/object/object.3 @@ -61,7 +61,7 @@ and write ACK-object files and libraries .PP .B wr_arhdr(fd, arhdr) .br -.B struct arhdr *arhdr; +.B struct ar_hdr *arhdr; .PP .B wr_ranlib(fd, ran, cnt) .br @@ -125,9 +125,9 @@ and write ACK-object files and libraries .br .B long cnt; .PP -.B rd_arhdr(fd, arhdr) +.B int rd_arhdr(fd, arhdr) .br -.B struct arhdr *arhdr; +.B struct ar_hdr *arhdr; .PP .B rd_ranlib(fd, ran, cnt) .br @@ -261,6 +261,8 @@ reads two bytes from file descriptor .I fd and interpretes them as an unsigned integer. .PP +.I Rd_arhdr returns 1 if a header was read, and 0 on end-of-file. +.PP When using any of the reading routines, you must define a routine named .IB rd_fatal . From b9e516837f168143aab976d187aa528a62be61f0 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 8 Jan 1987 16:19:16 +0000 Subject: [PATCH 0457/1625] Added C_init. --- modules/src/em_code/e/em.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/src/em_code/e/em.c b/modules/src/em_code/e/em.c index 172df600..963e853f 100644 --- a/modules/src/em_code/e/em.c +++ b/modules/src/em_code/e/em.c @@ -15,6 +15,11 @@ static File *ofp = 0; +C_init(w, p) + arith w, p; +{ +} + C_open(nm) /* open file for readable code output */ char *nm; { From 35422761e422b311f7476683106663c5b59a7076 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 8 Jan 1987 16:20:59 +0000 Subject: [PATCH 0458/1625] Added C_init --- modules/src/em_code/k/em.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/src/em_code/k/em.c b/modules/src/em_code/k/em.c index 84b1a08d..f38e2a33 100644 --- a/modules/src/em_code/k/em.c +++ b/modules/src/em_code/k/em.c @@ -42,6 +42,11 @@ putbyte(b) #define putbyte(c) Xputbyte(c) +C_init(w, p) + arith w, p; +{ +} + C_open(nm) /* open file for compact code output */ char *nm; { From c15f8492de8e7bdfe0d0afb2bf122aea0110409a Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 8 Jan 1987 16:35:00 +0000 Subject: [PATCH 0459/1625] added doc for C_init --- modules/src/em_code/em_code.3X | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/modules/src/em_code/em_code.3X b/modules/src/em_code/em_code.3X index 9300f630..872bbcbc 100644 --- a/modules/src/em_code/em_code.3X +++ b/modules/src/em_code/em_code.3X @@ -5,6 +5,9 @@ emcode \- EM code interface for compilers .nf .B #include .PP +.B C_init(wsize, psize) +.B arith wsize, psize; +.PP .B int C_open(filename) .B C_close() .B int C_busy() @@ -74,6 +77,15 @@ unsigned int for .BR label . .PP +.B C_init() +should be called to initialize the module. +.I Wsize +is the word size and +.I psize +the pointer size on the target machine. +Checking implementations of this module use these values to check +whether arguments of an instruction are legal. +.PP .BI C_open( filename ) should be invoked as initialiser for a sequence of calls that produce EM code on file From 4c7e878c6cc156b5106db660c91c85c8f4a9489b Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 8 Jan 1987 17:39:37 +0000 Subject: [PATCH 0460/1625] Bug fix: order in archive longs is PDP-11 order! --- modules/src/object/rd_arhdr.c | 10 ++++++---- modules/src/object/wr_arhdr.c | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/modules/src/object/rd_arhdr.c b/modules/src/object/rd_arhdr.c index 691799fb..bce8b183 100644 --- a/modules/src/object/rd_arhdr.c +++ b/modules/src/object/rd_arhdr.c @@ -5,7 +5,7 @@ int rd_arhdr(fd, arhdr) register struct ar_hdr *arhdr; { -#if ! (BYTES_REVERSED || WORDS_REVERSED) +#if WORDS_REVERSED && ! BYTES_REVERSED if (sizeof (struct ar_hdr) != AR_TOTAL) #endif { @@ -23,13 +23,15 @@ rd_arhdr(fd, arhdr) while (i--) { *p++ = *c++; } - arhdr->ar_date = get4(c); c += 4; + arhdr->ar_date = get2(c) << 16; c += 2; + arhdr->ar_date |= get2(c) & 0xffff; c += 2; arhdr->ar_uid = *c++; arhdr->ar_gid = *c++; arhdr->ar_mode = get2(c); c += 2; - arhdr->ar_size = get4(c); + arhdr->ar_size = get2(c) << 16; c += 2; + arhdr->ar_size |= get2(c) & 0xffff; } -#if ! (BYTES_REVERSED || WORDS_REVERSED) +#if WORDS_REVERSED && !BYTES_REVERSED else { register int i; i = read(fd, (char *) arhdr, AR_TOTAL); diff --git a/modules/src/object/wr_arhdr.c b/modules/src/object/wr_arhdr.c index f7ac67ba..6ad9b99c 100644 --- a/modules/src/object/wr_arhdr.c +++ b/modules/src/object/wr_arhdr.c @@ -4,7 +4,7 @@ wr_arhdr(fd, arhdr) register struct ar_hdr *arhdr; { -#if ! (BYTES_REVERSED || WORDS_REVERSED) +#if WORDS_REVERSED && !BYTES_REVERSED if (sizeof (struct ar_hdr) != AR_TOTAL) #endif { @@ -16,14 +16,16 @@ wr_arhdr(fd, arhdr) while (i--) { *c++ = *p++; } - put4(arhdr->ar_date,c); c += 4; + put2(arhdr->ar_date>>16,c); c += 2; + put2(arhdr->ar_date,c); c += 2; *c++ = arhdr->ar_uid; *c++ = arhdr->ar_gid; put2(arhdr->ar_mode,c); c += 2; - put4(arhdr->ar_size,c); + put2(arhdr->ar_size>>16,c); c += 2; + put2(arhdr->ar_size,c); wr_bytes(fd, buf, (long) AR_TOTAL); } -#if ! (BYTES_REVERSED || WORDS_REVERSED) +#if WORDS_REVERSED && !BYTES_REVERSED else wr_bytes(fd, (char *) arhdr, (long) AR_TOTAL); #endif } From d050d88f892169e5de0f5b2fcb6bb0694f9795cc Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 8 Jan 1987 17:40:25 +0000 Subject: [PATCH 0461/1625] %c did not work on systems that have their bytes or their words reversed. --- modules/src/print/format.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/src/print/format.c b/modules/src/print/format.c index 31f1f6d4..d040e8d6 100644 --- a/modules/src/print/format.c +++ b/modules/src/print/format.c @@ -55,7 +55,7 @@ _format(buf, fmt, argp) } else if (*pf == 'c') { - cbuf[0] = * (char *) pa; + cbuf[0] = * (int *) pa; cbuf[1] = '\0'; pa += sizeof(int); arg = &cbuf[0]; From 2aa7a6977b9a527daa329773c4626c891762490f Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 9 Jan 1987 14:11:59 +0000 Subject: [PATCH 0462/1625] Bug fix. --- modules/src/object/wr_ranlib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/src/object/wr_ranlib.c b/modules/src/object/wr_ranlib.c index f20772c1..0a8516a9 100644 --- a/modules/src/object/wr_ranlib.c +++ b/modules/src/object/wr_ranlib.c @@ -22,7 +22,7 @@ wr_ranlib(fd, ran, cnt) put4(ran->ran_pos,c); c += 4; ran++; } - wr_bytes(fd, c, j); + wr_bytes(fd, buf, j); } } #if ! (BYTES_REVERSED || WORDS_REVERSED) From 0ec2e206419d9e2d9081dc8d2cda93fcf7a39d43 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 9 Jan 1987 15:16:22 +0000 Subject: [PATCH 0463/1625] In some cases, the number after a HOL was'nt accurate. --- emtest/tests | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/emtest/tests b/emtest/tests index d71da49a..30da6ca8 100644 --- a/emtest/tests +++ b/emtest/tests @@ -146,11 +146,11 @@ OK bne *1 OK TEST 005: test loe, ste -HOL 8 +HOL 2*WS MAIN 0 loc 95 - ste 4 - loe 4 + ste WS + loe WS loc 95 bne *1 OK @@ -162,7 +162,7 @@ OK OK loc 95 ste 0 - loe 4 + loe WS loe 0 bne *1 OK @@ -392,7 +392,7 @@ MAIN 20 bne *1 OK TEST 019: test lde -HOL 20 +HOL 12+2*WS MAIN 0 loc 70 ste 12 @@ -442,7 +442,7 @@ MAIN 20 bne *1 OK TEST 023: test sde -HOL 20 +HOL 16+2*WS MAIN 0 loc 40 loc 41 @@ -455,7 +455,7 @@ MAIN 0 bne *1 OK TEST 024: test sdf -HOL 20 +HOL 16+2*WS MAIN 0 loc 51 loc 50 @@ -1707,7 +1707,7 @@ MAIN 12 bne *1 OK TEST 077: test cal -HOL 12 +HOL 4+WS MAIN 0 cal $p077 loe 4 @@ -1721,7 +1721,7 @@ PROC ret 0 end TEST 078: test cai -HOL 12 +HOL 4+WS MAIN 0 lpi $p078 cai @@ -1833,7 +1833,7 @@ OK bne *1 OK TEST 083: test blm -HOL 40 +HOL 12+4*WS MAIN 32 loc 61 ste 12 @@ -1869,7 +1869,7 @@ OK bne *1 OK TEST 084: test bls WS -HOL 40 +HOL 20+2*WS MAIN 32 loc 20 stl -8 @@ -3293,7 +3293,7 @@ OK OK #endif TEST 120: test cal -HOL 12 +HOL 4+WS MAIN 0 loc 0 ste 4 From 25ecc31433301a4d81b53d416a7a8912dedfa88c Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 12 Jan 1987 12:30:16 +0000 Subject: [PATCH 0464/1625] Corrected the "install" entry. --- util/cpp/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/util/cpp/Makefile b/util/cpp/Makefile index 4df03654..18ffbf25 100644 --- a/util/cpp/Makefile +++ b/util/cpp/Makefile @@ -104,6 +104,7 @@ cfiles: hfiles LLfiles $(GSRC) @touch cfiles install: all + rm -f $(CEMPP) cp cpp $(CEMPP) cmp: all From 4b916d7c48b69749edaa69ed814f7259a584ee8b Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 12 Jan 1987 14:01:26 +0000 Subject: [PATCH 0465/1625] New Makefile, also generating opt2 (t.i. peephole optimizer after global ..) --- util/opt/Makefile | 197 +++++++++++++--------------------------------- 1 file changed, 56 insertions(+), 141 deletions(-) diff --git a/util/opt/Makefile b/util/opt/Makefile index ed067c94..4c7a40f5 100644 --- a/util/opt/Makefile +++ b/util/opt/Makefile @@ -1,13 +1,16 @@ # $Header$ +EMHOME=../.. CFILES=main.c getline.c lookup.c var.c process.c backward.c util.c\ alloc.c putline.c cleanup.c peephole.c flow.c reg.c OFILES=main.o getline.o lookup.o var.o process.o backward.o util.o\ - alloc.o putline.o cleanup.o peephole.o flow.o reg.o + alloc.o putline.o cleanup.o peephole.o flow.o +ONOGLOB=regnoglob.o +OGLOB=regglob.o KFILES=main.k getline.k lookup.k var.k process.k backward.k util.k\ - alloc.k putline.k cleanup.k peephole.k flow.k reg.k -LIBS=../../lib/em_data.a -CFLAGS=-O -DNDEBUG + alloc.k putline.k cleanup.k peephole.k flow.k regnoglob.k regglob.k +LIBS=$(EMHOME)/lib/em_data.a +CFLAGS=-O -DNDEBUG -I$(EMHOME)/h LDFLAGS=-i LINT=lint OPR=wide|opr @@ -19,18 +22,28 @@ LEXLIB=-ll .DEFAULT: co -q $< -opt: $(OFILES) pattern.o $(LIBS) - cc $(LDFLAGS) $(CFLAGS) $(OFILES) pattern.o $(LIBS) -o opt +all: opt opt2 + +opt: $(OFILES) $(ONOGLOB) pattern.o $(LIBS) + cc $(LDFLAGS) $(CFLAGS) $(OFILES) $(ONOGLOB) pattern.o $(LIBS) -o opt + +opt2: $(OFILES) $(OGLOB) pattern.o $(LIBS) + cc $(LDFLAGS) $(CFLAGS) $(OFILES) $(OGLOB) pattern.o $(LIBS) -o opt2 test: opt testopt testopt -cmp : opt - cmp opt ../../lib/em_opt +cmp : all + -cmp opt $(EMHOME)/lib/em_opt + -cmp opt2 $(EMHOME)/lib/em_opt2 -install:opt - -size opt ../../lib/em_opt - cp opt ../../lib/em_opt +install:all + -size opt $(EMHOME)/lib/em_opt + rm -f $(EMHOME)/lib/opt + cp opt $(EMHOME)/lib/em_opt + -size opt2 $(EMHOME)/lib/em_opt2 + rm -f $(EMHOME)/lib/opt2 + cp opt2 $(EMHOME)/lib/em_opt2 pattern.c: patterns mktab /lib/cpp patterns | mktab > pattern.c @@ -38,8 +51,12 @@ pattern.c: patterns mktab mktab: mktab.o $(LIBS) cc $(CFLAGS) mktab.o $(LIBS) $(LEXLIB) -o mktab -depend: makedepend - makedepend +depend: regglob.c regnoglob.c pattern.c + sed '/^#AUTOAUTO/,$$d' Makefile >Makefile.new + echo '#AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO' >> Makefile.new + mkdep $(CFILES) pattern.c regglob.c regnoglob.c | sed 's/\.c:/.o:/' >> Makefile.new + mv Makefile Makefile.old + mv Makefile.new Makefile lint: $(CFILES) pattern.c $(LINT) $(CFILES) pattern.c>lint 2>&1 @@ -66,137 +83,35 @@ sizes: opt clean: rm -f *.o opt mktab mktab.c scan.c pattern.c +regnoglob.c: reg.c + cp reg.c regnoglob.c + +regglob.c: reg.c + cp reg.c regglob.c + +regglob.o: regglob.c + $(CC) $(CFLAGS) -c -DGLOBAL_OPT regglob.c + kfiles: $(KFILES) .SUFFIXES: .k .c.k: ; cem -c $*.c # the next lines are generated automatically -# AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO -alloc.o: alloc.h -alloc.o: assert.h -alloc.o: line.h -alloc.o: lookup.h -alloc.o: param.h -alloc.o: proinf.h -alloc.o: types.h -backward.o: ../../h/em_mnem.h -backward.o: ../../h/em_pseu.h -backward.o: ../../h/em_spec.h -backward.o: alloc.h -backward.o: assert.h -backward.o: ext.h -backward.o: line.h -backward.o: lookup.h -backward.o: param.h -backward.o: proinf.h -backward.o: types.h -cleanup.o: ../../h/em_mes.h -cleanup.o: ../../h/em_pseu.h -cleanup.o: ../../h/em_spec.h -cleanup.o: assert.h -cleanup.o: ext.h -cleanup.o: lookup.h -cleanup.o: param.h -cleanup.o: types.h -flow.o: ../../h/em_flag.h -flow.o: ../../h/em_mnem.h -flow.o: ../../h/em_spec.h -flow.o: alloc.h -flow.o: ext.h -flow.o: line.h -flow.o: optim.h -flow.o: param.h -flow.o: proinf.h -flow.o: types.h -getline.o: ../../h/em_flag.h -getline.o: ../../h/em_mes.h -getline.o: ../../h/em_pseu.h -getline.o: ../../h/em_spec.h -getline.o: alloc.h -getline.o: assert.h -getline.o: ext.h -getline.o: line.h -getline.o: lookup.h -getline.o: param.h -getline.o: proinf.h -getline.o: types.h -lookup.o: alloc.h -lookup.o: lookup.h -lookup.o: param.h -lookup.o: proinf.h -lookup.o: types.h -main.o: ../../h/em_spec.h -main.o: alloc.h -main.o: ext.h -main.o: param.h -main.o: types.h -mktab.o: ../../h/em_mnem.h -mktab.o: ../../h/em_spec.h -mktab.o: optim.h -mktab.o: param.h -mktab.o: pattern.h -mktab.o: scan.c -mktab.o: types.h -pattern.o: param.h -pattern.o: pattern.h -pattern.o: types.h -peephole.o: ../../h/em_mnem.h -peephole.o: ../../h/em_spec.h -peephole.o: alloc.h -peephole.o: assert.h -peephole.o: ext.h -peephole.o: line.h -peephole.o: lookup.h -peephole.o: optim.h -peephole.o: param.h -peephole.o: pattern.h -peephole.o: proinf.h -peephole.o: types.h -process.o: ../../h/em_pseu.h -process.o: ../../h/em_spec.h -process.o: alloc.h -process.o: assert.h -process.o: ext.h -process.o: line.h -process.o: lookup.h -process.o: param.h -process.o: proinf.h -process.o: types.h -putline.o: ../../h/em_flag.h -putline.o: ../../h/em_mnem.h -putline.o: ../../h/em_pseu.h -putline.o: ../../h/em_spec.h -putline.o: alloc.h -putline.o: assert.h -putline.o: ext.h -putline.o: line.h -putline.o: lookup.h -putline.o: optim.h -putline.o: param.h -putline.o: proinf.h -putline.o: types.h -reg.o: ../../h/em_mes.h -reg.o: ../../h/em_pseu.h -reg.o: ../../h/em_spec.h -reg.o: alloc.h -reg.o: assert.h -reg.o: ext.h -reg.o: line.h -reg.o: param.h -reg.o: proinf.h -reg.o: types.h -scan.o: stdio.h -special.o: param.h -special.o: types.h -util.o: assert.h -util.o: ext.h -util.o: lookup.h -util.o: optim.h -util.o: param.h -util.o: proinf.h -util.o: types.h -var.o: lookup.h -var.o: param.h -var.o: proinf.h -var.o: types.h +#AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO +main.o: ../../h/em_spec.h alloc.h ext.h param.h types.h +getline.o: ../../h/em_flag.h ../../h/em_mes.h ../../h/em_pseu.h ../../h/em_spec.h alloc.h ext.h line.h lookup.h param.h proinf.h types.h +lookup.o: alloc.h lookup.h param.h proinf.h types.h +var.o: lookup.h param.h proinf.h types.h +process.o: ../../h/em_pseu.h ../../h/em_spec.h alloc.h assert.h ext.h line.h lookup.h param.h proinf.h types.h +backward.o: ../../h/em_mnem.h ../../h/em_pseu.h ../../h/em_spec.h alloc.h assert.h ext.h line.h lookup.h param.h proinf.h types.h +util.o: assert.h ext.h lookup.h optim.h param.h proinf.h types.h +alloc.o: alloc.h assert.h line.h lookup.h param.h proinf.h types.h +putline.o: ../../h/em_flag.h ../../h/em_mnem.h ../../h/em_pseu.h ../../h/em_spec.h alloc.h assert.h ext.h line.h lookup.h optim.h param.h proinf.h types.h +cleanup.o: ../../h/em_mes.h ../../h/em_pseu.h ../../h/em_spec.h assert.h ext.h lookup.h param.h types.h +peephole.o: ../../h/em_mnem.h ../../h/em_spec.h alloc.h assert.h ext.h line.h lookup.h optim.h param.h pattern.h proinf.h types.h +flow.o: ../../h/em_flag.h ../../h/em_mnem.h ../../h/em_spec.h alloc.h ext.h line.h optim.h param.h proinf.h types.h +reg.o: ../../h/em_mes.h ../../h/em_pseu.h ../../h/em_spec.h alloc.h assert.h ext.h line.h param.h proinf.h types.h +pattern.o: param.h pattern.h types.h +regglob.o: ../../h/em_mes.h ../../h/em_pseu.h ../../h/em_spec.h alloc.h assert.h ext.h line.h param.h proinf.h types.h +regnoglob.o: ../../h/em_mes.h ../../h/em_pseu.h ../../h/em_spec.h alloc.h assert.h ext.h line.h param.h proinf.h types.h From 46ce3ce464bf6affb514b15ed7d6eaa314c8387a Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 12 Jan 1987 14:06:47 +0000 Subject: [PATCH 0466/1625] This one works. --- util/opt/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/opt/Makefile b/util/opt/Makefile index 4c7a40f5..988b2743 100644 --- a/util/opt/Makefile +++ b/util/opt/Makefile @@ -39,10 +39,10 @@ cmp : all install:all -size opt $(EMHOME)/lib/em_opt - rm -f $(EMHOME)/lib/opt + rm -f $(EMHOME)/lib/em_opt cp opt $(EMHOME)/lib/em_opt -size opt2 $(EMHOME)/lib/em_opt2 - rm -f $(EMHOME)/lib/opt2 + rm -f $(EMHOME)/lib/em_opt2 cp opt2 $(EMHOME)/lib/em_opt2 pattern.c: patterns mktab From fda21b626ccb0c1a2abbfa192dc726e4ac707836 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 12 Jan 1987 14:21:14 +0000 Subject: [PATCH 0467/1625] force first line directive --- util/cpp/preprocess.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/util/cpp/preprocess.c b/util/cpp/preprocess.c index c8347afc..394770c3 100644 --- a/util/cpp/preprocess.c +++ b/util/cpp/preprocess.c @@ -27,7 +27,7 @@ preprocess(fn) register int c; register char *op = _obuf; register char *ob = &_obuf[OBUFSIZE]; - int lineno = 0; + int lineno = 32767; /* force line directive */ extern char options[]; #define flush(X) (sys_write(STDOUT,_obuf,X)) @@ -44,17 +44,18 @@ preprocess(fn) newline(); LoadChar(c); } - if (! options['P'] && - (lineno != LineNumber || fn != FileName)) { - char Xbuf[256]; - register char *p = Xbuf; - + if (lineno != LineNumber || fn != FileName) { fn = FileName; lineno = LineNumber; - sprint(p, "# %d \"%s\"\n", LineNumber, - FileName); - while (*p) { - echo(*p++); + if (! options['P']) { + char Xbuf[256]; + register char *p = Xbuf; + + sprint(p, "# %d \"%s\"\n", LineNumber, + FileName); + while (*p) { + echo(*p++); + } } } for (;;) { From d5987d64d386a9758b6b1d9911251581bf68bf9c Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 12 Jan 1987 14:38:45 +0000 Subject: [PATCH 0468/1625] Allow reading from standard input --- util/ncgg/main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/util/ncgg/main.c b/util/ncgg/main.c index 5ab322b3..f0b992e4 100644 --- a/util/ncgg/main.c +++ b/util/ncgg/main.c @@ -34,8 +34,11 @@ main(argc,argv) char **argv; { exit(-1); } filename = argv[1]; + } + else if (argc == 1) { + filename = ""; } else - error("Usage: %s [-c] [-d] [-v] table",argv[0]); + error("Usage: %s [-c] [-d] [-v] [table]",argv[0]); initemhash(); enterkeyw(); initnodes(); From 38a7a6e104beb113a9b04fc0e013e66878e02a26 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 12 Jan 1987 14:50:25 +0000 Subject: [PATCH 0469/1625] Preprocess table. --- mach/arm/ncg/Makefile | 41 ++++++++++++++++++++-------------------- mach/i386/ncg/Makefile | 41 ++++++++++++++++++++-------------------- mach/i80/ncg/Makefile | 41 ++++++++++++++++++++-------------------- mach/i86/ncg/Makefile | 41 ++++++++++++++++++++-------------------- mach/m68020/ncg/Makefile | 41 ++++++++++++++++++++-------------------- mach/m68k2/ncg/Makefile | 41 ++++++++++++++++++++-------------------- mach/m68k4/ncg/Makefile | 41 ++++++++++++++++++++-------------------- mach/moon3/ncg/Makefile | 41 ++++++++++++++++++++-------------------- mach/ns/ncg/Makefile | 41 ++++++++++++++++++++-------------------- mach/pdp/ncg/Makefile | 41 ++++++++++++++++++++-------------------- mach/proto/ncg/Makefile | 41 ++++++++++++++++++++-------------------- 11 files changed, 231 insertions(+), 220 deletions(-) diff --git a/mach/arm/ncg/Makefile b/mach/arm/ncg/Makefile index e3ceffce..8465b654 100644 --- a/mach/arm/ncg/Makefile +++ b/mach/arm/ncg/Makefile @@ -1,13 +1,14 @@ # $Header$ -PREFLAGS=-I../../../h -I. +EMHOME=../../.. +PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= CFLAGS=$(PREFLAGS) $(PFLAGS) LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac -LIBS=../../../lib/em_data.a -CDIR=../../proto/ncg -CGG=../../../lib/ncgg +LIBS=$(EMHOME)/lib/em_data.a +CDIR=$(EMHOME)/mach/proto/ncg +CGG=$(EMHOME)/lib/ncgg CFILES=$(CDIR)/codegen.c $(CDIR)/compute.c $(CDIR)/equiv.c $(CDIR)/fillem.c \ $(CDIR)/gencode.c $(CDIR)/glosym.c $(CDIR)/main.c $(CDIR)/move.c \ $(CDIR)/nextem.c $(CDIR)/reg.c $(CDIR)/regvar.c $(CDIR)/salloc.c \ @@ -57,14 +58,14 @@ var.o: $(CDIR)/var.c cc -c $(CFLAGS) $(CDIR)/var.c install: all - ../../install cg + $(EMHOME)/mach/install cg cmp: all - -../../compare cg + -$(EMHOME)/mach/compare cg tables.c: table $(CGG) - $(CGG) table + $(EMHOME)/lib/cpp table | $(CGG) -cmp tables.h tables.H || cp tables.H tables.h lint: $(CFILES) @@ -72,7 +73,7 @@ lint: $(CFILES) clean: rm -f *.o tables.c tables.h debug.out cg tables.H -codegen.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +codegen.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h codegen.o: $(CDIR)/data.h codegen.o: $(CDIR)/equiv.h codegen.o: $(CDIR)/extern.h @@ -81,7 +82,7 @@ codegen.o: $(CDIR)/result.h codegen.o: $(CDIR)/state.h codegen.o: tables.h codegen.o: $(CDIR)/types.h -compute.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +compute.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h compute.o: $(CDIR)/data.h compute.o: $(CDIR)/extern.h compute.o: $(CDIR)/glosym.h @@ -90,14 +91,14 @@ compute.o: $(CDIR)/result.h compute.o: tables.h compute.o: $(CDIR)/types.h equiv.o: $(CDIR)/assert.h -equiv.o: $(CDIR)/data.h ../../../h/cgg_cg.h +equiv.o: $(CDIR)/data.h $(EMHOME)/h/cgg_cg.h equiv.o: $(CDIR)/equiv.h equiv.o: $(CDIR)/extern.h equiv.o: $(CDIR)/param.h equiv.o: $(CDIR)/result.h equiv.o: tables.h equiv.o: $(CDIR)/types.h -fillem.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +fillem.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h fillem.o: $(CDIR)/data.h fillem.o: $(CDIR)/extern.h fillem.o: mach.c @@ -107,7 +108,7 @@ fillem.o: $(CDIR)/regvar.h fillem.o: $(CDIR)/result.h fillem.o: tables.h fillem.o: $(CDIR)/types.h -gencode.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +gencode.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h gencode.o: $(CDIR)/data.h gencode.o: $(CDIR)/extern.h gencode.o: $(CDIR)/param.h @@ -120,28 +121,28 @@ glosym.o: tables.h glosym.o: $(CDIR)/types.h main.o: $(CDIR)/param.h main.o: tables.h -move.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +move.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h move.o: $(CDIR)/data.h move.o: $(CDIR)/extern.h move.o: $(CDIR)/param.h move.o: $(CDIR)/result.h move.o: tables.h move.o: $(CDIR)/types.h -nextem.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +nextem.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h nextem.o: $(CDIR)/data.h nextem.o: $(CDIR)/extern.h nextem.o: $(CDIR)/param.h nextem.o: $(CDIR)/result.h nextem.o: tables.h nextem.o: $(CDIR)/types.h -reg.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +reg.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h reg.o: $(CDIR)/data.h reg.o: $(CDIR)/extern.h reg.o: $(CDIR)/param.h reg.o: $(CDIR)/result.h reg.o: tables.h reg.o: $(CDIR)/types.h -regvar.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +regvar.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h regvar.o: $(CDIR)/data.h regvar.o: $(CDIR)/extern.h regvar.o: $(CDIR)/param.h @@ -149,14 +150,14 @@ regvar.o: $(CDIR)/regvar.h regvar.o: $(CDIR)/result.h regvar.o: tables.h regvar.o: $(CDIR)/types.h -salloc.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +salloc.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h salloc.o: $(CDIR)/data.h salloc.o: $(CDIR)/extern.h salloc.o: $(CDIR)/param.h salloc.o: $(CDIR)/result.h salloc.o: tables.h salloc.o: $(CDIR)/types.h -state.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +state.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h state.o: $(CDIR)/data.h state.o: $(CDIR)/extern.h state.o: $(CDIR)/param.h @@ -164,14 +165,14 @@ state.o: $(CDIR)/result.h state.o: $(CDIR)/state.h state.o: tables.h state.o: $(CDIR)/types.h -subr.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +subr.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h subr.o: $(CDIR)/data.h subr.o: $(CDIR)/extern.h subr.o: $(CDIR)/param.h subr.o: $(CDIR)/result.h subr.o: tables.h subr.o: $(CDIR)/types.h -var.o: $(CDIR)/data.h ../../../h/cgg_cg.h +var.o: $(CDIR)/data.h $(EMHOME)/h/cgg_cg.h var.o: $(CDIR)/param.h var.o: $(CDIR)/result.h var.o: tables.h diff --git a/mach/i386/ncg/Makefile b/mach/i386/ncg/Makefile index e3ceffce..8465b654 100644 --- a/mach/i386/ncg/Makefile +++ b/mach/i386/ncg/Makefile @@ -1,13 +1,14 @@ # $Header$ -PREFLAGS=-I../../../h -I. +EMHOME=../../.. +PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= CFLAGS=$(PREFLAGS) $(PFLAGS) LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac -LIBS=../../../lib/em_data.a -CDIR=../../proto/ncg -CGG=../../../lib/ncgg +LIBS=$(EMHOME)/lib/em_data.a +CDIR=$(EMHOME)/mach/proto/ncg +CGG=$(EMHOME)/lib/ncgg CFILES=$(CDIR)/codegen.c $(CDIR)/compute.c $(CDIR)/equiv.c $(CDIR)/fillem.c \ $(CDIR)/gencode.c $(CDIR)/glosym.c $(CDIR)/main.c $(CDIR)/move.c \ $(CDIR)/nextem.c $(CDIR)/reg.c $(CDIR)/regvar.c $(CDIR)/salloc.c \ @@ -57,14 +58,14 @@ var.o: $(CDIR)/var.c cc -c $(CFLAGS) $(CDIR)/var.c install: all - ../../install cg + $(EMHOME)/mach/install cg cmp: all - -../../compare cg + -$(EMHOME)/mach/compare cg tables.c: table $(CGG) - $(CGG) table + $(EMHOME)/lib/cpp table | $(CGG) -cmp tables.h tables.H || cp tables.H tables.h lint: $(CFILES) @@ -72,7 +73,7 @@ lint: $(CFILES) clean: rm -f *.o tables.c tables.h debug.out cg tables.H -codegen.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +codegen.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h codegen.o: $(CDIR)/data.h codegen.o: $(CDIR)/equiv.h codegen.o: $(CDIR)/extern.h @@ -81,7 +82,7 @@ codegen.o: $(CDIR)/result.h codegen.o: $(CDIR)/state.h codegen.o: tables.h codegen.o: $(CDIR)/types.h -compute.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +compute.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h compute.o: $(CDIR)/data.h compute.o: $(CDIR)/extern.h compute.o: $(CDIR)/glosym.h @@ -90,14 +91,14 @@ compute.o: $(CDIR)/result.h compute.o: tables.h compute.o: $(CDIR)/types.h equiv.o: $(CDIR)/assert.h -equiv.o: $(CDIR)/data.h ../../../h/cgg_cg.h +equiv.o: $(CDIR)/data.h $(EMHOME)/h/cgg_cg.h equiv.o: $(CDIR)/equiv.h equiv.o: $(CDIR)/extern.h equiv.o: $(CDIR)/param.h equiv.o: $(CDIR)/result.h equiv.o: tables.h equiv.o: $(CDIR)/types.h -fillem.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +fillem.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h fillem.o: $(CDIR)/data.h fillem.o: $(CDIR)/extern.h fillem.o: mach.c @@ -107,7 +108,7 @@ fillem.o: $(CDIR)/regvar.h fillem.o: $(CDIR)/result.h fillem.o: tables.h fillem.o: $(CDIR)/types.h -gencode.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +gencode.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h gencode.o: $(CDIR)/data.h gencode.o: $(CDIR)/extern.h gencode.o: $(CDIR)/param.h @@ -120,28 +121,28 @@ glosym.o: tables.h glosym.o: $(CDIR)/types.h main.o: $(CDIR)/param.h main.o: tables.h -move.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +move.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h move.o: $(CDIR)/data.h move.o: $(CDIR)/extern.h move.o: $(CDIR)/param.h move.o: $(CDIR)/result.h move.o: tables.h move.o: $(CDIR)/types.h -nextem.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +nextem.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h nextem.o: $(CDIR)/data.h nextem.o: $(CDIR)/extern.h nextem.o: $(CDIR)/param.h nextem.o: $(CDIR)/result.h nextem.o: tables.h nextem.o: $(CDIR)/types.h -reg.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +reg.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h reg.o: $(CDIR)/data.h reg.o: $(CDIR)/extern.h reg.o: $(CDIR)/param.h reg.o: $(CDIR)/result.h reg.o: tables.h reg.o: $(CDIR)/types.h -regvar.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +regvar.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h regvar.o: $(CDIR)/data.h regvar.o: $(CDIR)/extern.h regvar.o: $(CDIR)/param.h @@ -149,14 +150,14 @@ regvar.o: $(CDIR)/regvar.h regvar.o: $(CDIR)/result.h regvar.o: tables.h regvar.o: $(CDIR)/types.h -salloc.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +salloc.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h salloc.o: $(CDIR)/data.h salloc.o: $(CDIR)/extern.h salloc.o: $(CDIR)/param.h salloc.o: $(CDIR)/result.h salloc.o: tables.h salloc.o: $(CDIR)/types.h -state.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +state.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h state.o: $(CDIR)/data.h state.o: $(CDIR)/extern.h state.o: $(CDIR)/param.h @@ -164,14 +165,14 @@ state.o: $(CDIR)/result.h state.o: $(CDIR)/state.h state.o: tables.h state.o: $(CDIR)/types.h -subr.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +subr.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h subr.o: $(CDIR)/data.h subr.o: $(CDIR)/extern.h subr.o: $(CDIR)/param.h subr.o: $(CDIR)/result.h subr.o: tables.h subr.o: $(CDIR)/types.h -var.o: $(CDIR)/data.h ../../../h/cgg_cg.h +var.o: $(CDIR)/data.h $(EMHOME)/h/cgg_cg.h var.o: $(CDIR)/param.h var.o: $(CDIR)/result.h var.o: tables.h diff --git a/mach/i80/ncg/Makefile b/mach/i80/ncg/Makefile index e3ceffce..8465b654 100644 --- a/mach/i80/ncg/Makefile +++ b/mach/i80/ncg/Makefile @@ -1,13 +1,14 @@ # $Header$ -PREFLAGS=-I../../../h -I. +EMHOME=../../.. +PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= CFLAGS=$(PREFLAGS) $(PFLAGS) LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac -LIBS=../../../lib/em_data.a -CDIR=../../proto/ncg -CGG=../../../lib/ncgg +LIBS=$(EMHOME)/lib/em_data.a +CDIR=$(EMHOME)/mach/proto/ncg +CGG=$(EMHOME)/lib/ncgg CFILES=$(CDIR)/codegen.c $(CDIR)/compute.c $(CDIR)/equiv.c $(CDIR)/fillem.c \ $(CDIR)/gencode.c $(CDIR)/glosym.c $(CDIR)/main.c $(CDIR)/move.c \ $(CDIR)/nextem.c $(CDIR)/reg.c $(CDIR)/regvar.c $(CDIR)/salloc.c \ @@ -57,14 +58,14 @@ var.o: $(CDIR)/var.c cc -c $(CFLAGS) $(CDIR)/var.c install: all - ../../install cg + $(EMHOME)/mach/install cg cmp: all - -../../compare cg + -$(EMHOME)/mach/compare cg tables.c: table $(CGG) - $(CGG) table + $(EMHOME)/lib/cpp table | $(CGG) -cmp tables.h tables.H || cp tables.H tables.h lint: $(CFILES) @@ -72,7 +73,7 @@ lint: $(CFILES) clean: rm -f *.o tables.c tables.h debug.out cg tables.H -codegen.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +codegen.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h codegen.o: $(CDIR)/data.h codegen.o: $(CDIR)/equiv.h codegen.o: $(CDIR)/extern.h @@ -81,7 +82,7 @@ codegen.o: $(CDIR)/result.h codegen.o: $(CDIR)/state.h codegen.o: tables.h codegen.o: $(CDIR)/types.h -compute.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +compute.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h compute.o: $(CDIR)/data.h compute.o: $(CDIR)/extern.h compute.o: $(CDIR)/glosym.h @@ -90,14 +91,14 @@ compute.o: $(CDIR)/result.h compute.o: tables.h compute.o: $(CDIR)/types.h equiv.o: $(CDIR)/assert.h -equiv.o: $(CDIR)/data.h ../../../h/cgg_cg.h +equiv.o: $(CDIR)/data.h $(EMHOME)/h/cgg_cg.h equiv.o: $(CDIR)/equiv.h equiv.o: $(CDIR)/extern.h equiv.o: $(CDIR)/param.h equiv.o: $(CDIR)/result.h equiv.o: tables.h equiv.o: $(CDIR)/types.h -fillem.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +fillem.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h fillem.o: $(CDIR)/data.h fillem.o: $(CDIR)/extern.h fillem.o: mach.c @@ -107,7 +108,7 @@ fillem.o: $(CDIR)/regvar.h fillem.o: $(CDIR)/result.h fillem.o: tables.h fillem.o: $(CDIR)/types.h -gencode.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +gencode.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h gencode.o: $(CDIR)/data.h gencode.o: $(CDIR)/extern.h gencode.o: $(CDIR)/param.h @@ -120,28 +121,28 @@ glosym.o: tables.h glosym.o: $(CDIR)/types.h main.o: $(CDIR)/param.h main.o: tables.h -move.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +move.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h move.o: $(CDIR)/data.h move.o: $(CDIR)/extern.h move.o: $(CDIR)/param.h move.o: $(CDIR)/result.h move.o: tables.h move.o: $(CDIR)/types.h -nextem.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +nextem.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h nextem.o: $(CDIR)/data.h nextem.o: $(CDIR)/extern.h nextem.o: $(CDIR)/param.h nextem.o: $(CDIR)/result.h nextem.o: tables.h nextem.o: $(CDIR)/types.h -reg.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +reg.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h reg.o: $(CDIR)/data.h reg.o: $(CDIR)/extern.h reg.o: $(CDIR)/param.h reg.o: $(CDIR)/result.h reg.o: tables.h reg.o: $(CDIR)/types.h -regvar.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +regvar.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h regvar.o: $(CDIR)/data.h regvar.o: $(CDIR)/extern.h regvar.o: $(CDIR)/param.h @@ -149,14 +150,14 @@ regvar.o: $(CDIR)/regvar.h regvar.o: $(CDIR)/result.h regvar.o: tables.h regvar.o: $(CDIR)/types.h -salloc.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +salloc.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h salloc.o: $(CDIR)/data.h salloc.o: $(CDIR)/extern.h salloc.o: $(CDIR)/param.h salloc.o: $(CDIR)/result.h salloc.o: tables.h salloc.o: $(CDIR)/types.h -state.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +state.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h state.o: $(CDIR)/data.h state.o: $(CDIR)/extern.h state.o: $(CDIR)/param.h @@ -164,14 +165,14 @@ state.o: $(CDIR)/result.h state.o: $(CDIR)/state.h state.o: tables.h state.o: $(CDIR)/types.h -subr.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +subr.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h subr.o: $(CDIR)/data.h subr.o: $(CDIR)/extern.h subr.o: $(CDIR)/param.h subr.o: $(CDIR)/result.h subr.o: tables.h subr.o: $(CDIR)/types.h -var.o: $(CDIR)/data.h ../../../h/cgg_cg.h +var.o: $(CDIR)/data.h $(EMHOME)/h/cgg_cg.h var.o: $(CDIR)/param.h var.o: $(CDIR)/result.h var.o: tables.h diff --git a/mach/i86/ncg/Makefile b/mach/i86/ncg/Makefile index e3ceffce..8465b654 100644 --- a/mach/i86/ncg/Makefile +++ b/mach/i86/ncg/Makefile @@ -1,13 +1,14 @@ # $Header$ -PREFLAGS=-I../../../h -I. +EMHOME=../../.. +PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= CFLAGS=$(PREFLAGS) $(PFLAGS) LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac -LIBS=../../../lib/em_data.a -CDIR=../../proto/ncg -CGG=../../../lib/ncgg +LIBS=$(EMHOME)/lib/em_data.a +CDIR=$(EMHOME)/mach/proto/ncg +CGG=$(EMHOME)/lib/ncgg CFILES=$(CDIR)/codegen.c $(CDIR)/compute.c $(CDIR)/equiv.c $(CDIR)/fillem.c \ $(CDIR)/gencode.c $(CDIR)/glosym.c $(CDIR)/main.c $(CDIR)/move.c \ $(CDIR)/nextem.c $(CDIR)/reg.c $(CDIR)/regvar.c $(CDIR)/salloc.c \ @@ -57,14 +58,14 @@ var.o: $(CDIR)/var.c cc -c $(CFLAGS) $(CDIR)/var.c install: all - ../../install cg + $(EMHOME)/mach/install cg cmp: all - -../../compare cg + -$(EMHOME)/mach/compare cg tables.c: table $(CGG) - $(CGG) table + $(EMHOME)/lib/cpp table | $(CGG) -cmp tables.h tables.H || cp tables.H tables.h lint: $(CFILES) @@ -72,7 +73,7 @@ lint: $(CFILES) clean: rm -f *.o tables.c tables.h debug.out cg tables.H -codegen.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +codegen.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h codegen.o: $(CDIR)/data.h codegen.o: $(CDIR)/equiv.h codegen.o: $(CDIR)/extern.h @@ -81,7 +82,7 @@ codegen.o: $(CDIR)/result.h codegen.o: $(CDIR)/state.h codegen.o: tables.h codegen.o: $(CDIR)/types.h -compute.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +compute.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h compute.o: $(CDIR)/data.h compute.o: $(CDIR)/extern.h compute.o: $(CDIR)/glosym.h @@ -90,14 +91,14 @@ compute.o: $(CDIR)/result.h compute.o: tables.h compute.o: $(CDIR)/types.h equiv.o: $(CDIR)/assert.h -equiv.o: $(CDIR)/data.h ../../../h/cgg_cg.h +equiv.o: $(CDIR)/data.h $(EMHOME)/h/cgg_cg.h equiv.o: $(CDIR)/equiv.h equiv.o: $(CDIR)/extern.h equiv.o: $(CDIR)/param.h equiv.o: $(CDIR)/result.h equiv.o: tables.h equiv.o: $(CDIR)/types.h -fillem.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +fillem.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h fillem.o: $(CDIR)/data.h fillem.o: $(CDIR)/extern.h fillem.o: mach.c @@ -107,7 +108,7 @@ fillem.o: $(CDIR)/regvar.h fillem.o: $(CDIR)/result.h fillem.o: tables.h fillem.o: $(CDIR)/types.h -gencode.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +gencode.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h gencode.o: $(CDIR)/data.h gencode.o: $(CDIR)/extern.h gencode.o: $(CDIR)/param.h @@ -120,28 +121,28 @@ glosym.o: tables.h glosym.o: $(CDIR)/types.h main.o: $(CDIR)/param.h main.o: tables.h -move.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +move.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h move.o: $(CDIR)/data.h move.o: $(CDIR)/extern.h move.o: $(CDIR)/param.h move.o: $(CDIR)/result.h move.o: tables.h move.o: $(CDIR)/types.h -nextem.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +nextem.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h nextem.o: $(CDIR)/data.h nextem.o: $(CDIR)/extern.h nextem.o: $(CDIR)/param.h nextem.o: $(CDIR)/result.h nextem.o: tables.h nextem.o: $(CDIR)/types.h -reg.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +reg.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h reg.o: $(CDIR)/data.h reg.o: $(CDIR)/extern.h reg.o: $(CDIR)/param.h reg.o: $(CDIR)/result.h reg.o: tables.h reg.o: $(CDIR)/types.h -regvar.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +regvar.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h regvar.o: $(CDIR)/data.h regvar.o: $(CDIR)/extern.h regvar.o: $(CDIR)/param.h @@ -149,14 +150,14 @@ regvar.o: $(CDIR)/regvar.h regvar.o: $(CDIR)/result.h regvar.o: tables.h regvar.o: $(CDIR)/types.h -salloc.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +salloc.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h salloc.o: $(CDIR)/data.h salloc.o: $(CDIR)/extern.h salloc.o: $(CDIR)/param.h salloc.o: $(CDIR)/result.h salloc.o: tables.h salloc.o: $(CDIR)/types.h -state.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +state.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h state.o: $(CDIR)/data.h state.o: $(CDIR)/extern.h state.o: $(CDIR)/param.h @@ -164,14 +165,14 @@ state.o: $(CDIR)/result.h state.o: $(CDIR)/state.h state.o: tables.h state.o: $(CDIR)/types.h -subr.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +subr.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h subr.o: $(CDIR)/data.h subr.o: $(CDIR)/extern.h subr.o: $(CDIR)/param.h subr.o: $(CDIR)/result.h subr.o: tables.h subr.o: $(CDIR)/types.h -var.o: $(CDIR)/data.h ../../../h/cgg_cg.h +var.o: $(CDIR)/data.h $(EMHOME)/h/cgg_cg.h var.o: $(CDIR)/param.h var.o: $(CDIR)/result.h var.o: tables.h diff --git a/mach/m68020/ncg/Makefile b/mach/m68020/ncg/Makefile index e3ceffce..8465b654 100644 --- a/mach/m68020/ncg/Makefile +++ b/mach/m68020/ncg/Makefile @@ -1,13 +1,14 @@ # $Header$ -PREFLAGS=-I../../../h -I. +EMHOME=../../.. +PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= CFLAGS=$(PREFLAGS) $(PFLAGS) LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac -LIBS=../../../lib/em_data.a -CDIR=../../proto/ncg -CGG=../../../lib/ncgg +LIBS=$(EMHOME)/lib/em_data.a +CDIR=$(EMHOME)/mach/proto/ncg +CGG=$(EMHOME)/lib/ncgg CFILES=$(CDIR)/codegen.c $(CDIR)/compute.c $(CDIR)/equiv.c $(CDIR)/fillem.c \ $(CDIR)/gencode.c $(CDIR)/glosym.c $(CDIR)/main.c $(CDIR)/move.c \ $(CDIR)/nextem.c $(CDIR)/reg.c $(CDIR)/regvar.c $(CDIR)/salloc.c \ @@ -57,14 +58,14 @@ var.o: $(CDIR)/var.c cc -c $(CFLAGS) $(CDIR)/var.c install: all - ../../install cg + $(EMHOME)/mach/install cg cmp: all - -../../compare cg + -$(EMHOME)/mach/compare cg tables.c: table $(CGG) - $(CGG) table + $(EMHOME)/lib/cpp table | $(CGG) -cmp tables.h tables.H || cp tables.H tables.h lint: $(CFILES) @@ -72,7 +73,7 @@ lint: $(CFILES) clean: rm -f *.o tables.c tables.h debug.out cg tables.H -codegen.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +codegen.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h codegen.o: $(CDIR)/data.h codegen.o: $(CDIR)/equiv.h codegen.o: $(CDIR)/extern.h @@ -81,7 +82,7 @@ codegen.o: $(CDIR)/result.h codegen.o: $(CDIR)/state.h codegen.o: tables.h codegen.o: $(CDIR)/types.h -compute.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +compute.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h compute.o: $(CDIR)/data.h compute.o: $(CDIR)/extern.h compute.o: $(CDIR)/glosym.h @@ -90,14 +91,14 @@ compute.o: $(CDIR)/result.h compute.o: tables.h compute.o: $(CDIR)/types.h equiv.o: $(CDIR)/assert.h -equiv.o: $(CDIR)/data.h ../../../h/cgg_cg.h +equiv.o: $(CDIR)/data.h $(EMHOME)/h/cgg_cg.h equiv.o: $(CDIR)/equiv.h equiv.o: $(CDIR)/extern.h equiv.o: $(CDIR)/param.h equiv.o: $(CDIR)/result.h equiv.o: tables.h equiv.o: $(CDIR)/types.h -fillem.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +fillem.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h fillem.o: $(CDIR)/data.h fillem.o: $(CDIR)/extern.h fillem.o: mach.c @@ -107,7 +108,7 @@ fillem.o: $(CDIR)/regvar.h fillem.o: $(CDIR)/result.h fillem.o: tables.h fillem.o: $(CDIR)/types.h -gencode.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +gencode.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h gencode.o: $(CDIR)/data.h gencode.o: $(CDIR)/extern.h gencode.o: $(CDIR)/param.h @@ -120,28 +121,28 @@ glosym.o: tables.h glosym.o: $(CDIR)/types.h main.o: $(CDIR)/param.h main.o: tables.h -move.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +move.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h move.o: $(CDIR)/data.h move.o: $(CDIR)/extern.h move.o: $(CDIR)/param.h move.o: $(CDIR)/result.h move.o: tables.h move.o: $(CDIR)/types.h -nextem.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +nextem.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h nextem.o: $(CDIR)/data.h nextem.o: $(CDIR)/extern.h nextem.o: $(CDIR)/param.h nextem.o: $(CDIR)/result.h nextem.o: tables.h nextem.o: $(CDIR)/types.h -reg.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +reg.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h reg.o: $(CDIR)/data.h reg.o: $(CDIR)/extern.h reg.o: $(CDIR)/param.h reg.o: $(CDIR)/result.h reg.o: tables.h reg.o: $(CDIR)/types.h -regvar.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +regvar.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h regvar.o: $(CDIR)/data.h regvar.o: $(CDIR)/extern.h regvar.o: $(CDIR)/param.h @@ -149,14 +150,14 @@ regvar.o: $(CDIR)/regvar.h regvar.o: $(CDIR)/result.h regvar.o: tables.h regvar.o: $(CDIR)/types.h -salloc.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +salloc.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h salloc.o: $(CDIR)/data.h salloc.o: $(CDIR)/extern.h salloc.o: $(CDIR)/param.h salloc.o: $(CDIR)/result.h salloc.o: tables.h salloc.o: $(CDIR)/types.h -state.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +state.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h state.o: $(CDIR)/data.h state.o: $(CDIR)/extern.h state.o: $(CDIR)/param.h @@ -164,14 +165,14 @@ state.o: $(CDIR)/result.h state.o: $(CDIR)/state.h state.o: tables.h state.o: $(CDIR)/types.h -subr.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +subr.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h subr.o: $(CDIR)/data.h subr.o: $(CDIR)/extern.h subr.o: $(CDIR)/param.h subr.o: $(CDIR)/result.h subr.o: tables.h subr.o: $(CDIR)/types.h -var.o: $(CDIR)/data.h ../../../h/cgg_cg.h +var.o: $(CDIR)/data.h $(EMHOME)/h/cgg_cg.h var.o: $(CDIR)/param.h var.o: $(CDIR)/result.h var.o: tables.h diff --git a/mach/m68k2/ncg/Makefile b/mach/m68k2/ncg/Makefile index e3ceffce..8465b654 100644 --- a/mach/m68k2/ncg/Makefile +++ b/mach/m68k2/ncg/Makefile @@ -1,13 +1,14 @@ # $Header$ -PREFLAGS=-I../../../h -I. +EMHOME=../../.. +PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= CFLAGS=$(PREFLAGS) $(PFLAGS) LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac -LIBS=../../../lib/em_data.a -CDIR=../../proto/ncg -CGG=../../../lib/ncgg +LIBS=$(EMHOME)/lib/em_data.a +CDIR=$(EMHOME)/mach/proto/ncg +CGG=$(EMHOME)/lib/ncgg CFILES=$(CDIR)/codegen.c $(CDIR)/compute.c $(CDIR)/equiv.c $(CDIR)/fillem.c \ $(CDIR)/gencode.c $(CDIR)/glosym.c $(CDIR)/main.c $(CDIR)/move.c \ $(CDIR)/nextem.c $(CDIR)/reg.c $(CDIR)/regvar.c $(CDIR)/salloc.c \ @@ -57,14 +58,14 @@ var.o: $(CDIR)/var.c cc -c $(CFLAGS) $(CDIR)/var.c install: all - ../../install cg + $(EMHOME)/mach/install cg cmp: all - -../../compare cg + -$(EMHOME)/mach/compare cg tables.c: table $(CGG) - $(CGG) table + $(EMHOME)/lib/cpp table | $(CGG) -cmp tables.h tables.H || cp tables.H tables.h lint: $(CFILES) @@ -72,7 +73,7 @@ lint: $(CFILES) clean: rm -f *.o tables.c tables.h debug.out cg tables.H -codegen.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +codegen.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h codegen.o: $(CDIR)/data.h codegen.o: $(CDIR)/equiv.h codegen.o: $(CDIR)/extern.h @@ -81,7 +82,7 @@ codegen.o: $(CDIR)/result.h codegen.o: $(CDIR)/state.h codegen.o: tables.h codegen.o: $(CDIR)/types.h -compute.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +compute.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h compute.o: $(CDIR)/data.h compute.o: $(CDIR)/extern.h compute.o: $(CDIR)/glosym.h @@ -90,14 +91,14 @@ compute.o: $(CDIR)/result.h compute.o: tables.h compute.o: $(CDIR)/types.h equiv.o: $(CDIR)/assert.h -equiv.o: $(CDIR)/data.h ../../../h/cgg_cg.h +equiv.o: $(CDIR)/data.h $(EMHOME)/h/cgg_cg.h equiv.o: $(CDIR)/equiv.h equiv.o: $(CDIR)/extern.h equiv.o: $(CDIR)/param.h equiv.o: $(CDIR)/result.h equiv.o: tables.h equiv.o: $(CDIR)/types.h -fillem.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +fillem.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h fillem.o: $(CDIR)/data.h fillem.o: $(CDIR)/extern.h fillem.o: mach.c @@ -107,7 +108,7 @@ fillem.o: $(CDIR)/regvar.h fillem.o: $(CDIR)/result.h fillem.o: tables.h fillem.o: $(CDIR)/types.h -gencode.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +gencode.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h gencode.o: $(CDIR)/data.h gencode.o: $(CDIR)/extern.h gencode.o: $(CDIR)/param.h @@ -120,28 +121,28 @@ glosym.o: tables.h glosym.o: $(CDIR)/types.h main.o: $(CDIR)/param.h main.o: tables.h -move.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +move.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h move.o: $(CDIR)/data.h move.o: $(CDIR)/extern.h move.o: $(CDIR)/param.h move.o: $(CDIR)/result.h move.o: tables.h move.o: $(CDIR)/types.h -nextem.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +nextem.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h nextem.o: $(CDIR)/data.h nextem.o: $(CDIR)/extern.h nextem.o: $(CDIR)/param.h nextem.o: $(CDIR)/result.h nextem.o: tables.h nextem.o: $(CDIR)/types.h -reg.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +reg.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h reg.o: $(CDIR)/data.h reg.o: $(CDIR)/extern.h reg.o: $(CDIR)/param.h reg.o: $(CDIR)/result.h reg.o: tables.h reg.o: $(CDIR)/types.h -regvar.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +regvar.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h regvar.o: $(CDIR)/data.h regvar.o: $(CDIR)/extern.h regvar.o: $(CDIR)/param.h @@ -149,14 +150,14 @@ regvar.o: $(CDIR)/regvar.h regvar.o: $(CDIR)/result.h regvar.o: tables.h regvar.o: $(CDIR)/types.h -salloc.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +salloc.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h salloc.o: $(CDIR)/data.h salloc.o: $(CDIR)/extern.h salloc.o: $(CDIR)/param.h salloc.o: $(CDIR)/result.h salloc.o: tables.h salloc.o: $(CDIR)/types.h -state.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +state.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h state.o: $(CDIR)/data.h state.o: $(CDIR)/extern.h state.o: $(CDIR)/param.h @@ -164,14 +165,14 @@ state.o: $(CDIR)/result.h state.o: $(CDIR)/state.h state.o: tables.h state.o: $(CDIR)/types.h -subr.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +subr.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h subr.o: $(CDIR)/data.h subr.o: $(CDIR)/extern.h subr.o: $(CDIR)/param.h subr.o: $(CDIR)/result.h subr.o: tables.h subr.o: $(CDIR)/types.h -var.o: $(CDIR)/data.h ../../../h/cgg_cg.h +var.o: $(CDIR)/data.h $(EMHOME)/h/cgg_cg.h var.o: $(CDIR)/param.h var.o: $(CDIR)/result.h var.o: tables.h diff --git a/mach/m68k4/ncg/Makefile b/mach/m68k4/ncg/Makefile index e3ceffce..8465b654 100644 --- a/mach/m68k4/ncg/Makefile +++ b/mach/m68k4/ncg/Makefile @@ -1,13 +1,14 @@ # $Header$ -PREFLAGS=-I../../../h -I. +EMHOME=../../.. +PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= CFLAGS=$(PREFLAGS) $(PFLAGS) LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac -LIBS=../../../lib/em_data.a -CDIR=../../proto/ncg -CGG=../../../lib/ncgg +LIBS=$(EMHOME)/lib/em_data.a +CDIR=$(EMHOME)/mach/proto/ncg +CGG=$(EMHOME)/lib/ncgg CFILES=$(CDIR)/codegen.c $(CDIR)/compute.c $(CDIR)/equiv.c $(CDIR)/fillem.c \ $(CDIR)/gencode.c $(CDIR)/glosym.c $(CDIR)/main.c $(CDIR)/move.c \ $(CDIR)/nextem.c $(CDIR)/reg.c $(CDIR)/regvar.c $(CDIR)/salloc.c \ @@ -57,14 +58,14 @@ var.o: $(CDIR)/var.c cc -c $(CFLAGS) $(CDIR)/var.c install: all - ../../install cg + $(EMHOME)/mach/install cg cmp: all - -../../compare cg + -$(EMHOME)/mach/compare cg tables.c: table $(CGG) - $(CGG) table + $(EMHOME)/lib/cpp table | $(CGG) -cmp tables.h tables.H || cp tables.H tables.h lint: $(CFILES) @@ -72,7 +73,7 @@ lint: $(CFILES) clean: rm -f *.o tables.c tables.h debug.out cg tables.H -codegen.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +codegen.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h codegen.o: $(CDIR)/data.h codegen.o: $(CDIR)/equiv.h codegen.o: $(CDIR)/extern.h @@ -81,7 +82,7 @@ codegen.o: $(CDIR)/result.h codegen.o: $(CDIR)/state.h codegen.o: tables.h codegen.o: $(CDIR)/types.h -compute.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +compute.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h compute.o: $(CDIR)/data.h compute.o: $(CDIR)/extern.h compute.o: $(CDIR)/glosym.h @@ -90,14 +91,14 @@ compute.o: $(CDIR)/result.h compute.o: tables.h compute.o: $(CDIR)/types.h equiv.o: $(CDIR)/assert.h -equiv.o: $(CDIR)/data.h ../../../h/cgg_cg.h +equiv.o: $(CDIR)/data.h $(EMHOME)/h/cgg_cg.h equiv.o: $(CDIR)/equiv.h equiv.o: $(CDIR)/extern.h equiv.o: $(CDIR)/param.h equiv.o: $(CDIR)/result.h equiv.o: tables.h equiv.o: $(CDIR)/types.h -fillem.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +fillem.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h fillem.o: $(CDIR)/data.h fillem.o: $(CDIR)/extern.h fillem.o: mach.c @@ -107,7 +108,7 @@ fillem.o: $(CDIR)/regvar.h fillem.o: $(CDIR)/result.h fillem.o: tables.h fillem.o: $(CDIR)/types.h -gencode.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +gencode.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h gencode.o: $(CDIR)/data.h gencode.o: $(CDIR)/extern.h gencode.o: $(CDIR)/param.h @@ -120,28 +121,28 @@ glosym.o: tables.h glosym.o: $(CDIR)/types.h main.o: $(CDIR)/param.h main.o: tables.h -move.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +move.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h move.o: $(CDIR)/data.h move.o: $(CDIR)/extern.h move.o: $(CDIR)/param.h move.o: $(CDIR)/result.h move.o: tables.h move.o: $(CDIR)/types.h -nextem.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +nextem.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h nextem.o: $(CDIR)/data.h nextem.o: $(CDIR)/extern.h nextem.o: $(CDIR)/param.h nextem.o: $(CDIR)/result.h nextem.o: tables.h nextem.o: $(CDIR)/types.h -reg.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +reg.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h reg.o: $(CDIR)/data.h reg.o: $(CDIR)/extern.h reg.o: $(CDIR)/param.h reg.o: $(CDIR)/result.h reg.o: tables.h reg.o: $(CDIR)/types.h -regvar.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +regvar.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h regvar.o: $(CDIR)/data.h regvar.o: $(CDIR)/extern.h regvar.o: $(CDIR)/param.h @@ -149,14 +150,14 @@ regvar.o: $(CDIR)/regvar.h regvar.o: $(CDIR)/result.h regvar.o: tables.h regvar.o: $(CDIR)/types.h -salloc.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +salloc.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h salloc.o: $(CDIR)/data.h salloc.o: $(CDIR)/extern.h salloc.o: $(CDIR)/param.h salloc.o: $(CDIR)/result.h salloc.o: tables.h salloc.o: $(CDIR)/types.h -state.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +state.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h state.o: $(CDIR)/data.h state.o: $(CDIR)/extern.h state.o: $(CDIR)/param.h @@ -164,14 +165,14 @@ state.o: $(CDIR)/result.h state.o: $(CDIR)/state.h state.o: tables.h state.o: $(CDIR)/types.h -subr.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +subr.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h subr.o: $(CDIR)/data.h subr.o: $(CDIR)/extern.h subr.o: $(CDIR)/param.h subr.o: $(CDIR)/result.h subr.o: tables.h subr.o: $(CDIR)/types.h -var.o: $(CDIR)/data.h ../../../h/cgg_cg.h +var.o: $(CDIR)/data.h $(EMHOME)/h/cgg_cg.h var.o: $(CDIR)/param.h var.o: $(CDIR)/result.h var.o: tables.h diff --git a/mach/moon3/ncg/Makefile b/mach/moon3/ncg/Makefile index e3ceffce..8465b654 100644 --- a/mach/moon3/ncg/Makefile +++ b/mach/moon3/ncg/Makefile @@ -1,13 +1,14 @@ # $Header$ -PREFLAGS=-I../../../h -I. +EMHOME=../../.. +PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= CFLAGS=$(PREFLAGS) $(PFLAGS) LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac -LIBS=../../../lib/em_data.a -CDIR=../../proto/ncg -CGG=../../../lib/ncgg +LIBS=$(EMHOME)/lib/em_data.a +CDIR=$(EMHOME)/mach/proto/ncg +CGG=$(EMHOME)/lib/ncgg CFILES=$(CDIR)/codegen.c $(CDIR)/compute.c $(CDIR)/equiv.c $(CDIR)/fillem.c \ $(CDIR)/gencode.c $(CDIR)/glosym.c $(CDIR)/main.c $(CDIR)/move.c \ $(CDIR)/nextem.c $(CDIR)/reg.c $(CDIR)/regvar.c $(CDIR)/salloc.c \ @@ -57,14 +58,14 @@ var.o: $(CDIR)/var.c cc -c $(CFLAGS) $(CDIR)/var.c install: all - ../../install cg + $(EMHOME)/mach/install cg cmp: all - -../../compare cg + -$(EMHOME)/mach/compare cg tables.c: table $(CGG) - $(CGG) table + $(EMHOME)/lib/cpp table | $(CGG) -cmp tables.h tables.H || cp tables.H tables.h lint: $(CFILES) @@ -72,7 +73,7 @@ lint: $(CFILES) clean: rm -f *.o tables.c tables.h debug.out cg tables.H -codegen.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +codegen.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h codegen.o: $(CDIR)/data.h codegen.o: $(CDIR)/equiv.h codegen.o: $(CDIR)/extern.h @@ -81,7 +82,7 @@ codegen.o: $(CDIR)/result.h codegen.o: $(CDIR)/state.h codegen.o: tables.h codegen.o: $(CDIR)/types.h -compute.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +compute.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h compute.o: $(CDIR)/data.h compute.o: $(CDIR)/extern.h compute.o: $(CDIR)/glosym.h @@ -90,14 +91,14 @@ compute.o: $(CDIR)/result.h compute.o: tables.h compute.o: $(CDIR)/types.h equiv.o: $(CDIR)/assert.h -equiv.o: $(CDIR)/data.h ../../../h/cgg_cg.h +equiv.o: $(CDIR)/data.h $(EMHOME)/h/cgg_cg.h equiv.o: $(CDIR)/equiv.h equiv.o: $(CDIR)/extern.h equiv.o: $(CDIR)/param.h equiv.o: $(CDIR)/result.h equiv.o: tables.h equiv.o: $(CDIR)/types.h -fillem.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +fillem.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h fillem.o: $(CDIR)/data.h fillem.o: $(CDIR)/extern.h fillem.o: mach.c @@ -107,7 +108,7 @@ fillem.o: $(CDIR)/regvar.h fillem.o: $(CDIR)/result.h fillem.o: tables.h fillem.o: $(CDIR)/types.h -gencode.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +gencode.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h gencode.o: $(CDIR)/data.h gencode.o: $(CDIR)/extern.h gencode.o: $(CDIR)/param.h @@ -120,28 +121,28 @@ glosym.o: tables.h glosym.o: $(CDIR)/types.h main.o: $(CDIR)/param.h main.o: tables.h -move.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +move.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h move.o: $(CDIR)/data.h move.o: $(CDIR)/extern.h move.o: $(CDIR)/param.h move.o: $(CDIR)/result.h move.o: tables.h move.o: $(CDIR)/types.h -nextem.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +nextem.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h nextem.o: $(CDIR)/data.h nextem.o: $(CDIR)/extern.h nextem.o: $(CDIR)/param.h nextem.o: $(CDIR)/result.h nextem.o: tables.h nextem.o: $(CDIR)/types.h -reg.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +reg.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h reg.o: $(CDIR)/data.h reg.o: $(CDIR)/extern.h reg.o: $(CDIR)/param.h reg.o: $(CDIR)/result.h reg.o: tables.h reg.o: $(CDIR)/types.h -regvar.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +regvar.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h regvar.o: $(CDIR)/data.h regvar.o: $(CDIR)/extern.h regvar.o: $(CDIR)/param.h @@ -149,14 +150,14 @@ regvar.o: $(CDIR)/regvar.h regvar.o: $(CDIR)/result.h regvar.o: tables.h regvar.o: $(CDIR)/types.h -salloc.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +salloc.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h salloc.o: $(CDIR)/data.h salloc.o: $(CDIR)/extern.h salloc.o: $(CDIR)/param.h salloc.o: $(CDIR)/result.h salloc.o: tables.h salloc.o: $(CDIR)/types.h -state.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +state.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h state.o: $(CDIR)/data.h state.o: $(CDIR)/extern.h state.o: $(CDIR)/param.h @@ -164,14 +165,14 @@ state.o: $(CDIR)/result.h state.o: $(CDIR)/state.h state.o: tables.h state.o: $(CDIR)/types.h -subr.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +subr.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h subr.o: $(CDIR)/data.h subr.o: $(CDIR)/extern.h subr.o: $(CDIR)/param.h subr.o: $(CDIR)/result.h subr.o: tables.h subr.o: $(CDIR)/types.h -var.o: $(CDIR)/data.h ../../../h/cgg_cg.h +var.o: $(CDIR)/data.h $(EMHOME)/h/cgg_cg.h var.o: $(CDIR)/param.h var.o: $(CDIR)/result.h var.o: tables.h diff --git a/mach/ns/ncg/Makefile b/mach/ns/ncg/Makefile index e3ceffce..8465b654 100644 --- a/mach/ns/ncg/Makefile +++ b/mach/ns/ncg/Makefile @@ -1,13 +1,14 @@ # $Header$ -PREFLAGS=-I../../../h -I. +EMHOME=../../.. +PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= CFLAGS=$(PREFLAGS) $(PFLAGS) LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac -LIBS=../../../lib/em_data.a -CDIR=../../proto/ncg -CGG=../../../lib/ncgg +LIBS=$(EMHOME)/lib/em_data.a +CDIR=$(EMHOME)/mach/proto/ncg +CGG=$(EMHOME)/lib/ncgg CFILES=$(CDIR)/codegen.c $(CDIR)/compute.c $(CDIR)/equiv.c $(CDIR)/fillem.c \ $(CDIR)/gencode.c $(CDIR)/glosym.c $(CDIR)/main.c $(CDIR)/move.c \ $(CDIR)/nextem.c $(CDIR)/reg.c $(CDIR)/regvar.c $(CDIR)/salloc.c \ @@ -57,14 +58,14 @@ var.o: $(CDIR)/var.c cc -c $(CFLAGS) $(CDIR)/var.c install: all - ../../install cg + $(EMHOME)/mach/install cg cmp: all - -../../compare cg + -$(EMHOME)/mach/compare cg tables.c: table $(CGG) - $(CGG) table + $(EMHOME)/lib/cpp table | $(CGG) -cmp tables.h tables.H || cp tables.H tables.h lint: $(CFILES) @@ -72,7 +73,7 @@ lint: $(CFILES) clean: rm -f *.o tables.c tables.h debug.out cg tables.H -codegen.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +codegen.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h codegen.o: $(CDIR)/data.h codegen.o: $(CDIR)/equiv.h codegen.o: $(CDIR)/extern.h @@ -81,7 +82,7 @@ codegen.o: $(CDIR)/result.h codegen.o: $(CDIR)/state.h codegen.o: tables.h codegen.o: $(CDIR)/types.h -compute.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +compute.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h compute.o: $(CDIR)/data.h compute.o: $(CDIR)/extern.h compute.o: $(CDIR)/glosym.h @@ -90,14 +91,14 @@ compute.o: $(CDIR)/result.h compute.o: tables.h compute.o: $(CDIR)/types.h equiv.o: $(CDIR)/assert.h -equiv.o: $(CDIR)/data.h ../../../h/cgg_cg.h +equiv.o: $(CDIR)/data.h $(EMHOME)/h/cgg_cg.h equiv.o: $(CDIR)/equiv.h equiv.o: $(CDIR)/extern.h equiv.o: $(CDIR)/param.h equiv.o: $(CDIR)/result.h equiv.o: tables.h equiv.o: $(CDIR)/types.h -fillem.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +fillem.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h fillem.o: $(CDIR)/data.h fillem.o: $(CDIR)/extern.h fillem.o: mach.c @@ -107,7 +108,7 @@ fillem.o: $(CDIR)/regvar.h fillem.o: $(CDIR)/result.h fillem.o: tables.h fillem.o: $(CDIR)/types.h -gencode.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +gencode.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h gencode.o: $(CDIR)/data.h gencode.o: $(CDIR)/extern.h gencode.o: $(CDIR)/param.h @@ -120,28 +121,28 @@ glosym.o: tables.h glosym.o: $(CDIR)/types.h main.o: $(CDIR)/param.h main.o: tables.h -move.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +move.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h move.o: $(CDIR)/data.h move.o: $(CDIR)/extern.h move.o: $(CDIR)/param.h move.o: $(CDIR)/result.h move.o: tables.h move.o: $(CDIR)/types.h -nextem.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +nextem.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h nextem.o: $(CDIR)/data.h nextem.o: $(CDIR)/extern.h nextem.o: $(CDIR)/param.h nextem.o: $(CDIR)/result.h nextem.o: tables.h nextem.o: $(CDIR)/types.h -reg.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +reg.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h reg.o: $(CDIR)/data.h reg.o: $(CDIR)/extern.h reg.o: $(CDIR)/param.h reg.o: $(CDIR)/result.h reg.o: tables.h reg.o: $(CDIR)/types.h -regvar.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +regvar.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h regvar.o: $(CDIR)/data.h regvar.o: $(CDIR)/extern.h regvar.o: $(CDIR)/param.h @@ -149,14 +150,14 @@ regvar.o: $(CDIR)/regvar.h regvar.o: $(CDIR)/result.h regvar.o: tables.h regvar.o: $(CDIR)/types.h -salloc.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +salloc.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h salloc.o: $(CDIR)/data.h salloc.o: $(CDIR)/extern.h salloc.o: $(CDIR)/param.h salloc.o: $(CDIR)/result.h salloc.o: tables.h salloc.o: $(CDIR)/types.h -state.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +state.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h state.o: $(CDIR)/data.h state.o: $(CDIR)/extern.h state.o: $(CDIR)/param.h @@ -164,14 +165,14 @@ state.o: $(CDIR)/result.h state.o: $(CDIR)/state.h state.o: tables.h state.o: $(CDIR)/types.h -subr.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +subr.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h subr.o: $(CDIR)/data.h subr.o: $(CDIR)/extern.h subr.o: $(CDIR)/param.h subr.o: $(CDIR)/result.h subr.o: tables.h subr.o: $(CDIR)/types.h -var.o: $(CDIR)/data.h ../../../h/cgg_cg.h +var.o: $(CDIR)/data.h $(EMHOME)/h/cgg_cg.h var.o: $(CDIR)/param.h var.o: $(CDIR)/result.h var.o: tables.h diff --git a/mach/pdp/ncg/Makefile b/mach/pdp/ncg/Makefile index e3ceffce..8465b654 100644 --- a/mach/pdp/ncg/Makefile +++ b/mach/pdp/ncg/Makefile @@ -1,13 +1,14 @@ # $Header$ -PREFLAGS=-I../../../h -I. +EMHOME=../../.. +PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= CFLAGS=$(PREFLAGS) $(PFLAGS) LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac -LIBS=../../../lib/em_data.a -CDIR=../../proto/ncg -CGG=../../../lib/ncgg +LIBS=$(EMHOME)/lib/em_data.a +CDIR=$(EMHOME)/mach/proto/ncg +CGG=$(EMHOME)/lib/ncgg CFILES=$(CDIR)/codegen.c $(CDIR)/compute.c $(CDIR)/equiv.c $(CDIR)/fillem.c \ $(CDIR)/gencode.c $(CDIR)/glosym.c $(CDIR)/main.c $(CDIR)/move.c \ $(CDIR)/nextem.c $(CDIR)/reg.c $(CDIR)/regvar.c $(CDIR)/salloc.c \ @@ -57,14 +58,14 @@ var.o: $(CDIR)/var.c cc -c $(CFLAGS) $(CDIR)/var.c install: all - ../../install cg + $(EMHOME)/mach/install cg cmp: all - -../../compare cg + -$(EMHOME)/mach/compare cg tables.c: table $(CGG) - $(CGG) table + $(EMHOME)/lib/cpp table | $(CGG) -cmp tables.h tables.H || cp tables.H tables.h lint: $(CFILES) @@ -72,7 +73,7 @@ lint: $(CFILES) clean: rm -f *.o tables.c tables.h debug.out cg tables.H -codegen.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +codegen.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h codegen.o: $(CDIR)/data.h codegen.o: $(CDIR)/equiv.h codegen.o: $(CDIR)/extern.h @@ -81,7 +82,7 @@ codegen.o: $(CDIR)/result.h codegen.o: $(CDIR)/state.h codegen.o: tables.h codegen.o: $(CDIR)/types.h -compute.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +compute.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h compute.o: $(CDIR)/data.h compute.o: $(CDIR)/extern.h compute.o: $(CDIR)/glosym.h @@ -90,14 +91,14 @@ compute.o: $(CDIR)/result.h compute.o: tables.h compute.o: $(CDIR)/types.h equiv.o: $(CDIR)/assert.h -equiv.o: $(CDIR)/data.h ../../../h/cgg_cg.h +equiv.o: $(CDIR)/data.h $(EMHOME)/h/cgg_cg.h equiv.o: $(CDIR)/equiv.h equiv.o: $(CDIR)/extern.h equiv.o: $(CDIR)/param.h equiv.o: $(CDIR)/result.h equiv.o: tables.h equiv.o: $(CDIR)/types.h -fillem.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +fillem.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h fillem.o: $(CDIR)/data.h fillem.o: $(CDIR)/extern.h fillem.o: mach.c @@ -107,7 +108,7 @@ fillem.o: $(CDIR)/regvar.h fillem.o: $(CDIR)/result.h fillem.o: tables.h fillem.o: $(CDIR)/types.h -gencode.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +gencode.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h gencode.o: $(CDIR)/data.h gencode.o: $(CDIR)/extern.h gencode.o: $(CDIR)/param.h @@ -120,28 +121,28 @@ glosym.o: tables.h glosym.o: $(CDIR)/types.h main.o: $(CDIR)/param.h main.o: tables.h -move.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +move.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h move.o: $(CDIR)/data.h move.o: $(CDIR)/extern.h move.o: $(CDIR)/param.h move.o: $(CDIR)/result.h move.o: tables.h move.o: $(CDIR)/types.h -nextem.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +nextem.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h nextem.o: $(CDIR)/data.h nextem.o: $(CDIR)/extern.h nextem.o: $(CDIR)/param.h nextem.o: $(CDIR)/result.h nextem.o: tables.h nextem.o: $(CDIR)/types.h -reg.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +reg.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h reg.o: $(CDIR)/data.h reg.o: $(CDIR)/extern.h reg.o: $(CDIR)/param.h reg.o: $(CDIR)/result.h reg.o: tables.h reg.o: $(CDIR)/types.h -regvar.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +regvar.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h regvar.o: $(CDIR)/data.h regvar.o: $(CDIR)/extern.h regvar.o: $(CDIR)/param.h @@ -149,14 +150,14 @@ regvar.o: $(CDIR)/regvar.h regvar.o: $(CDIR)/result.h regvar.o: tables.h regvar.o: $(CDIR)/types.h -salloc.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +salloc.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h salloc.o: $(CDIR)/data.h salloc.o: $(CDIR)/extern.h salloc.o: $(CDIR)/param.h salloc.o: $(CDIR)/result.h salloc.o: tables.h salloc.o: $(CDIR)/types.h -state.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +state.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h state.o: $(CDIR)/data.h state.o: $(CDIR)/extern.h state.o: $(CDIR)/param.h @@ -164,14 +165,14 @@ state.o: $(CDIR)/result.h state.o: $(CDIR)/state.h state.o: tables.h state.o: $(CDIR)/types.h -subr.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +subr.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h subr.o: $(CDIR)/data.h subr.o: $(CDIR)/extern.h subr.o: $(CDIR)/param.h subr.o: $(CDIR)/result.h subr.o: tables.h subr.o: $(CDIR)/types.h -var.o: $(CDIR)/data.h ../../../h/cgg_cg.h +var.o: $(CDIR)/data.h $(EMHOME)/h/cgg_cg.h var.o: $(CDIR)/param.h var.o: $(CDIR)/result.h var.o: tables.h diff --git a/mach/proto/ncg/Makefile b/mach/proto/ncg/Makefile index e3ceffce..8465b654 100644 --- a/mach/proto/ncg/Makefile +++ b/mach/proto/ncg/Makefile @@ -1,13 +1,14 @@ # $Header$ -PREFLAGS=-I../../../h -I. +EMHOME=../../.. +PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= CFLAGS=$(PREFLAGS) $(PFLAGS) LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac -LIBS=../../../lib/em_data.a -CDIR=../../proto/ncg -CGG=../../../lib/ncgg +LIBS=$(EMHOME)/lib/em_data.a +CDIR=$(EMHOME)/mach/proto/ncg +CGG=$(EMHOME)/lib/ncgg CFILES=$(CDIR)/codegen.c $(CDIR)/compute.c $(CDIR)/equiv.c $(CDIR)/fillem.c \ $(CDIR)/gencode.c $(CDIR)/glosym.c $(CDIR)/main.c $(CDIR)/move.c \ $(CDIR)/nextem.c $(CDIR)/reg.c $(CDIR)/regvar.c $(CDIR)/salloc.c \ @@ -57,14 +58,14 @@ var.o: $(CDIR)/var.c cc -c $(CFLAGS) $(CDIR)/var.c install: all - ../../install cg + $(EMHOME)/mach/install cg cmp: all - -../../compare cg + -$(EMHOME)/mach/compare cg tables.c: table $(CGG) - $(CGG) table + $(EMHOME)/lib/cpp table | $(CGG) -cmp tables.h tables.H || cp tables.H tables.h lint: $(CFILES) @@ -72,7 +73,7 @@ lint: $(CFILES) clean: rm -f *.o tables.c tables.h debug.out cg tables.H -codegen.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +codegen.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h codegen.o: $(CDIR)/data.h codegen.o: $(CDIR)/equiv.h codegen.o: $(CDIR)/extern.h @@ -81,7 +82,7 @@ codegen.o: $(CDIR)/result.h codegen.o: $(CDIR)/state.h codegen.o: tables.h codegen.o: $(CDIR)/types.h -compute.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +compute.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h compute.o: $(CDIR)/data.h compute.o: $(CDIR)/extern.h compute.o: $(CDIR)/glosym.h @@ -90,14 +91,14 @@ compute.o: $(CDIR)/result.h compute.o: tables.h compute.o: $(CDIR)/types.h equiv.o: $(CDIR)/assert.h -equiv.o: $(CDIR)/data.h ../../../h/cgg_cg.h +equiv.o: $(CDIR)/data.h $(EMHOME)/h/cgg_cg.h equiv.o: $(CDIR)/equiv.h equiv.o: $(CDIR)/extern.h equiv.o: $(CDIR)/param.h equiv.o: $(CDIR)/result.h equiv.o: tables.h equiv.o: $(CDIR)/types.h -fillem.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +fillem.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h fillem.o: $(CDIR)/data.h fillem.o: $(CDIR)/extern.h fillem.o: mach.c @@ -107,7 +108,7 @@ fillem.o: $(CDIR)/regvar.h fillem.o: $(CDIR)/result.h fillem.o: tables.h fillem.o: $(CDIR)/types.h -gencode.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +gencode.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h gencode.o: $(CDIR)/data.h gencode.o: $(CDIR)/extern.h gencode.o: $(CDIR)/param.h @@ -120,28 +121,28 @@ glosym.o: tables.h glosym.o: $(CDIR)/types.h main.o: $(CDIR)/param.h main.o: tables.h -move.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +move.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h move.o: $(CDIR)/data.h move.o: $(CDIR)/extern.h move.o: $(CDIR)/param.h move.o: $(CDIR)/result.h move.o: tables.h move.o: $(CDIR)/types.h -nextem.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +nextem.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h nextem.o: $(CDIR)/data.h nextem.o: $(CDIR)/extern.h nextem.o: $(CDIR)/param.h nextem.o: $(CDIR)/result.h nextem.o: tables.h nextem.o: $(CDIR)/types.h -reg.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +reg.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h reg.o: $(CDIR)/data.h reg.o: $(CDIR)/extern.h reg.o: $(CDIR)/param.h reg.o: $(CDIR)/result.h reg.o: tables.h reg.o: $(CDIR)/types.h -regvar.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +regvar.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h regvar.o: $(CDIR)/data.h regvar.o: $(CDIR)/extern.h regvar.o: $(CDIR)/param.h @@ -149,14 +150,14 @@ regvar.o: $(CDIR)/regvar.h regvar.o: $(CDIR)/result.h regvar.o: tables.h regvar.o: $(CDIR)/types.h -salloc.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +salloc.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h salloc.o: $(CDIR)/data.h salloc.o: $(CDIR)/extern.h salloc.o: $(CDIR)/param.h salloc.o: $(CDIR)/result.h salloc.o: tables.h salloc.o: $(CDIR)/types.h -state.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +state.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h state.o: $(CDIR)/data.h state.o: $(CDIR)/extern.h state.o: $(CDIR)/param.h @@ -164,14 +165,14 @@ state.o: $(CDIR)/result.h state.o: $(CDIR)/state.h state.o: tables.h state.o: $(CDIR)/types.h -subr.o: $(CDIR)/assert.h ../../../h/cgg_cg.h +subr.o: $(CDIR)/assert.h $(EMHOME)/h/cgg_cg.h subr.o: $(CDIR)/data.h subr.o: $(CDIR)/extern.h subr.o: $(CDIR)/param.h subr.o: $(CDIR)/result.h subr.o: tables.h subr.o: $(CDIR)/types.h -var.o: $(CDIR)/data.h ../../../h/cgg_cg.h +var.o: $(CDIR)/data.h $(EMHOME)/h/cgg_cg.h var.o: $(CDIR)/param.h var.o: $(CDIR)/result.h var.o: tables.h From 7363c1cd09f7559ddda8808afb79a74e16f5cb96 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 12 Jan 1987 15:10:49 +0000 Subject: [PATCH 0470/1625] Added TABLEFLAGS and CGGFLAGS. --- mach/arm/ncg/Makefile | 7 ++++++- mach/i386/ncg/Makefile | 7 ++++++- mach/i80/ncg/Makefile | 7 ++++++- mach/i86/ncg/Makefile | 7 ++++++- mach/m68020/ncg/Makefile | 7 ++++++- mach/m68k2/ncg/Makefile | 7 ++++++- mach/m68k4/ncg/Makefile | 7 ++++++- mach/moon3/ncg/Makefile | 7 ++++++- mach/ns/ncg/Makefile | 7 ++++++- mach/pdp/ncg/Makefile | 7 ++++++- mach/proto/ncg/Makefile | 7 ++++++- 11 files changed, 66 insertions(+), 11 deletions(-) diff --git a/mach/arm/ncg/Makefile b/mach/arm/ncg/Makefile index 8465b654..bc68ab4a 100644 --- a/mach/arm/ncg/Makefile +++ b/mach/arm/ncg/Makefile @@ -1,6 +1,11 @@ # $Header$ EMHOME=../../.. +#preprocessor flags for table +TABLEFLAGS= +#cgg options +CGGFLAGS= + PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= CFLAGS=$(PREFLAGS) $(PFLAGS) @@ -65,7 +70,7 @@ cmp: all tables.c: table $(CGG) - $(EMHOME)/lib/cpp table | $(CGG) + $(EMHOME)/lib/cpp $(TABLEFLAGS) table | $(CGG) $(CGGFLAGS) -cmp tables.h tables.H || cp tables.H tables.h lint: $(CFILES) diff --git a/mach/i386/ncg/Makefile b/mach/i386/ncg/Makefile index 8465b654..bc68ab4a 100644 --- a/mach/i386/ncg/Makefile +++ b/mach/i386/ncg/Makefile @@ -1,6 +1,11 @@ # $Header$ EMHOME=../../.. +#preprocessor flags for table +TABLEFLAGS= +#cgg options +CGGFLAGS= + PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= CFLAGS=$(PREFLAGS) $(PFLAGS) @@ -65,7 +70,7 @@ cmp: all tables.c: table $(CGG) - $(EMHOME)/lib/cpp table | $(CGG) + $(EMHOME)/lib/cpp $(TABLEFLAGS) table | $(CGG) $(CGGFLAGS) -cmp tables.h tables.H || cp tables.H tables.h lint: $(CFILES) diff --git a/mach/i80/ncg/Makefile b/mach/i80/ncg/Makefile index 8465b654..bc68ab4a 100644 --- a/mach/i80/ncg/Makefile +++ b/mach/i80/ncg/Makefile @@ -1,6 +1,11 @@ # $Header$ EMHOME=../../.. +#preprocessor flags for table +TABLEFLAGS= +#cgg options +CGGFLAGS= + PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= CFLAGS=$(PREFLAGS) $(PFLAGS) @@ -65,7 +70,7 @@ cmp: all tables.c: table $(CGG) - $(EMHOME)/lib/cpp table | $(CGG) + $(EMHOME)/lib/cpp $(TABLEFLAGS) table | $(CGG) $(CGGFLAGS) -cmp tables.h tables.H || cp tables.H tables.h lint: $(CFILES) diff --git a/mach/i86/ncg/Makefile b/mach/i86/ncg/Makefile index 8465b654..bc68ab4a 100644 --- a/mach/i86/ncg/Makefile +++ b/mach/i86/ncg/Makefile @@ -1,6 +1,11 @@ # $Header$ EMHOME=../../.. +#preprocessor flags for table +TABLEFLAGS= +#cgg options +CGGFLAGS= + PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= CFLAGS=$(PREFLAGS) $(PFLAGS) @@ -65,7 +70,7 @@ cmp: all tables.c: table $(CGG) - $(EMHOME)/lib/cpp table | $(CGG) + $(EMHOME)/lib/cpp $(TABLEFLAGS) table | $(CGG) $(CGGFLAGS) -cmp tables.h tables.H || cp tables.H tables.h lint: $(CFILES) diff --git a/mach/m68020/ncg/Makefile b/mach/m68020/ncg/Makefile index 8465b654..bc68ab4a 100644 --- a/mach/m68020/ncg/Makefile +++ b/mach/m68020/ncg/Makefile @@ -1,6 +1,11 @@ # $Header$ EMHOME=../../.. +#preprocessor flags for table +TABLEFLAGS= +#cgg options +CGGFLAGS= + PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= CFLAGS=$(PREFLAGS) $(PFLAGS) @@ -65,7 +70,7 @@ cmp: all tables.c: table $(CGG) - $(EMHOME)/lib/cpp table | $(CGG) + $(EMHOME)/lib/cpp $(TABLEFLAGS) table | $(CGG) $(CGGFLAGS) -cmp tables.h tables.H || cp tables.H tables.h lint: $(CFILES) diff --git a/mach/m68k2/ncg/Makefile b/mach/m68k2/ncg/Makefile index 8465b654..bc68ab4a 100644 --- a/mach/m68k2/ncg/Makefile +++ b/mach/m68k2/ncg/Makefile @@ -1,6 +1,11 @@ # $Header$ EMHOME=../../.. +#preprocessor flags for table +TABLEFLAGS= +#cgg options +CGGFLAGS= + PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= CFLAGS=$(PREFLAGS) $(PFLAGS) @@ -65,7 +70,7 @@ cmp: all tables.c: table $(CGG) - $(EMHOME)/lib/cpp table | $(CGG) + $(EMHOME)/lib/cpp $(TABLEFLAGS) table | $(CGG) $(CGGFLAGS) -cmp tables.h tables.H || cp tables.H tables.h lint: $(CFILES) diff --git a/mach/m68k4/ncg/Makefile b/mach/m68k4/ncg/Makefile index 8465b654..bc68ab4a 100644 --- a/mach/m68k4/ncg/Makefile +++ b/mach/m68k4/ncg/Makefile @@ -1,6 +1,11 @@ # $Header$ EMHOME=../../.. +#preprocessor flags for table +TABLEFLAGS= +#cgg options +CGGFLAGS= + PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= CFLAGS=$(PREFLAGS) $(PFLAGS) @@ -65,7 +70,7 @@ cmp: all tables.c: table $(CGG) - $(EMHOME)/lib/cpp table | $(CGG) + $(EMHOME)/lib/cpp $(TABLEFLAGS) table | $(CGG) $(CGGFLAGS) -cmp tables.h tables.H || cp tables.H tables.h lint: $(CFILES) diff --git a/mach/moon3/ncg/Makefile b/mach/moon3/ncg/Makefile index 8465b654..bc68ab4a 100644 --- a/mach/moon3/ncg/Makefile +++ b/mach/moon3/ncg/Makefile @@ -1,6 +1,11 @@ # $Header$ EMHOME=../../.. +#preprocessor flags for table +TABLEFLAGS= +#cgg options +CGGFLAGS= + PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= CFLAGS=$(PREFLAGS) $(PFLAGS) @@ -65,7 +70,7 @@ cmp: all tables.c: table $(CGG) - $(EMHOME)/lib/cpp table | $(CGG) + $(EMHOME)/lib/cpp $(TABLEFLAGS) table | $(CGG) $(CGGFLAGS) -cmp tables.h tables.H || cp tables.H tables.h lint: $(CFILES) diff --git a/mach/ns/ncg/Makefile b/mach/ns/ncg/Makefile index 8465b654..bc68ab4a 100644 --- a/mach/ns/ncg/Makefile +++ b/mach/ns/ncg/Makefile @@ -1,6 +1,11 @@ # $Header$ EMHOME=../../.. +#preprocessor flags for table +TABLEFLAGS= +#cgg options +CGGFLAGS= + PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= CFLAGS=$(PREFLAGS) $(PFLAGS) @@ -65,7 +70,7 @@ cmp: all tables.c: table $(CGG) - $(EMHOME)/lib/cpp table | $(CGG) + $(EMHOME)/lib/cpp $(TABLEFLAGS) table | $(CGG) $(CGGFLAGS) -cmp tables.h tables.H || cp tables.H tables.h lint: $(CFILES) diff --git a/mach/pdp/ncg/Makefile b/mach/pdp/ncg/Makefile index 8465b654..bc68ab4a 100644 --- a/mach/pdp/ncg/Makefile +++ b/mach/pdp/ncg/Makefile @@ -1,6 +1,11 @@ # $Header$ EMHOME=../../.. +#preprocessor flags for table +TABLEFLAGS= +#cgg options +CGGFLAGS= + PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= CFLAGS=$(PREFLAGS) $(PFLAGS) @@ -65,7 +70,7 @@ cmp: all tables.c: table $(CGG) - $(EMHOME)/lib/cpp table | $(CGG) + $(EMHOME)/lib/cpp $(TABLEFLAGS) table | $(CGG) $(CGGFLAGS) -cmp tables.h tables.H || cp tables.H tables.h lint: $(CFILES) diff --git a/mach/proto/ncg/Makefile b/mach/proto/ncg/Makefile index 8465b654..bc68ab4a 100644 --- a/mach/proto/ncg/Makefile +++ b/mach/proto/ncg/Makefile @@ -1,6 +1,11 @@ # $Header$ EMHOME=../../.. +#preprocessor flags for table +TABLEFLAGS= +#cgg options +CGGFLAGS= + PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= CFLAGS=$(PREFLAGS) $(PFLAGS) @@ -65,7 +70,7 @@ cmp: all tables.c: table $(CGG) - $(EMHOME)/lib/cpp table | $(CGG) + $(EMHOME)/lib/cpp $(TABLEFLAGS) table | $(CGG) $(CGGFLAGS) -cmp tables.h tables.H || cp tables.H tables.h lint: $(CFILES) From 6f2d67cd2f68e05c5e9dc5892426cc24e3e6e8c4 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 12 Jan 1987 15:42:38 +0000 Subject: [PATCH 0471/1625] Also export EM_wordsize and EM_pointersize. --- modules/src/read_em/read_em.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/src/read_em/read_em.c b/modules/src/read_em/read_em.c index 085fa414..f8a9d4ae 100644 --- a/modules/src/read_em/read_em.c +++ b/modules/src/read_em/read_em.c @@ -89,6 +89,7 @@ static long wordmask[] = { /* allowed bits in a word */ }; static int wsize, psize; /* word size and pointer size */ +int EM_wordsize, EM_pointersize; #ifdef CHECKING static char *argrange = "Argument range error"; @@ -128,7 +129,6 @@ EXPORT int EM_open(filename) char *filename; { - if (EM_initialized) { EM_error = "EM_open already called"; return 0; @@ -195,9 +195,11 @@ startmes(p) } argp = ap = getarg(cst_ptyp); wsize = ap->em_cst; + EM_wordsize = ap->em_cst; ap->em_next = getarg(cst_ptyp); ap = ap->em_next; psize = ap->em_cst; + EM_pointersize = ap->em_cst; } } From 55bf9759da79552d047ac10e570e59a9693e2d1a Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 12 Jan 1987 15:54:16 +0000 Subject: [PATCH 0472/1625] Added documentation on EM_wordsize and EM_pointersize. --- modules/src/read_em/read_em.3 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/src/read_em/read_em.3 b/modules/src/read_em/read_em.3 index 4cadc3ed..f89aa30d 100644 --- a/modules/src/read_em/read_em.3 +++ b/modules/src/read_em/read_em.3 @@ -34,6 +34,8 @@ EM_mkcalls\ \-\ a module to read EM assembly code .B unsigned int EM_lineno; .PP .B char *EM_filename; +.PP +.B int EM_wordsize, EM_pointersize; .SH DESCRIPTION This package provides routines to read EM assembly code. The object is to simplify the program @@ -250,10 +252,15 @@ reason can then be found in \fIEM_error\fR. given as parameter to \fIEM_open\fR, but may have a different value, when the input was the result of some preprocessing. .PP +.I EM_wordsize +and +.I EM_pointersize +contain the wordsize and pointersize, but only after the first +(pseudo-)instruction has successfully been read. .SH FILES .nf ~em/modules/h/em.h -~em/modules/h/em_ptyp.h +~em/h/em_ptyp.h ~em/modules/h/em_comp.h ~em/modules/lib/libread_emk.a: non-checking library for reading compact EM code ~em/modules/lib/libread_emkV.a: checking library for reading compact EM code From abd81f80765b6d185c915bb2a7c45ce442bee7d6 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 12 Jan 1987 17:21:59 +0000 Subject: [PATCH 0473/1625] Initial revision --- util/arch/Makefile | 47 +++ util/arch/aal.1 | 79 +++++ util/arch/arch.1 | 83 ++++++ util/arch/archiver.c | 679 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 888 insertions(+) create mode 100644 util/arch/Makefile create mode 100644 util/arch/aal.1 create mode 100644 util/arch/arch.1 create mode 100644 util/arch/archiver.c diff --git a/util/arch/Makefile b/util/arch/Makefile new file mode 100644 index 00000000..633048ca --- /dev/null +++ b/util/arch/Makefile @@ -0,0 +1,47 @@ +EMHOME = ../.. +EMH = $(EMHOME)/h +EMBIN = $(EMHOME)/bin +LIB = $(EMHOME)/modules/lib + +LIBS = $(LIB)/libobject.a $(LIB)/libprint.a \ + $(LIB)/libstring.a $(LIB)/libsystem.a + +CFLAGS=-O -I$(EMH) + +all: arch aal + +arch: arch.o + $(CC) -n -o arch arch.o $(LIBS) + +aal: aal.o + $(CC) -i -o aal aal.o $(LIBS) + +arch.o: $(EMH)/arch.h archiver.c + $(CC) $(CFLAGS) -c archiver.c + mv archiver.o arch.o + +aal.o: $(EMH)/arch.h archiver.c $(EMH)/ranlib.h $(EMH)/out.h + $(CC) -DAAL $(CFLAGS) -c archiver.c + mv archiver.o aal.o + +clean: + rm -f aal arch *.o *.old + +install : all + rm -f $(EMBIN)/arch $(EMBIN)/aal + cp aal $(EMBIN)/aal + cp arch $(EMBIN)/arch + rm -f $(EMHOME)/man/arch.1 $(EMHOME)/man/aal.1 + cp aal.1 $(EMHOME)/man/aal.1 + cp arch.1 $(EMHOME)/man/arch.1 + +cmp : all + -cmp aal $(EMBIN)/aal + -cmp arch $(EMBIN)/arch + -cmp aal.1 $(EMHOME)/man/aal.1 + -cmp arch.1 $(EMHOME)/man/arch.1 + +opr: + make pr ^ opr +pr: + @pr Makefile archiver.c diff --git a/util/arch/aal.1 b/util/arch/aal.1 new file mode 100644 index 00000000..ce73e5e0 --- /dev/null +++ b/util/arch/aal.1 @@ -0,0 +1,79 @@ +.\" $Header$ +.TH ARCH 1ACK +.SH NAME +aal \- archive and library maintainer +.SH SYNOPSIS +.B aal +key afile name ... +.SH DESCRIPTION +.I Aal +maintains groups of ACK-object files +combined into a single archive file. +An index-table is automatically maintained. +The link editor +.IR led (6) +only understands archives made with +.IR aal . +.PP +.I Key +is one character from the set +.B adrtx, +optionally concatenated with +one or more of +.B vl. +.I Afile +is the archive file. +The +.I names +are constituent files in the archive file. +The meanings of the +.I key +characters are: +.TP +.B d +Delete the named files from the archive file. +.TP +.B a +Append the named files to the archive file. +.TP +.B r +Replace the named files in the archive file. +New files are placed at the end. +.TP +.B t +Print a table of contents of the archive file. +If no names are given, all files in the archive are listed. +If names are given, only those files are listed. +.TP +.B x +Extract the named files. +If no names are given, all files in the archive are +extracted. +In neither case does +.B x +alter the archive file. +.TP +.B v +Verbose. +Under the verbose option, +.I aal +gives a file-by-file +description of the making of a +new archive file from the old archive and the constituent files. +When used with +.B t, +it gives a long listing of all information about the files. +.TP +.B l +Local. +Normally +.I aal +places its temporary files in the directory /tmp. +This option causes them to be placed in the local directory. +.SH FILES +/tmp/ar.* temporaries +.SH "SEE ALSO" +em_ass(I), arch(V), +.SH BUGS +If the same file is mentioned twice in an argument list, +it may be put in the archive twice. diff --git a/util/arch/arch.1 b/util/arch/arch.1 new file mode 100644 index 00000000..7d688307 --- /dev/null +++ b/util/arch/arch.1 @@ -0,0 +1,83 @@ +.\" $Header$ +.TH ARCH 1ACK +.SH NAME +arch \- archive and library maintainer +.SH SYNOPSIS +.B arch +key afile name ... +.SH DESCRIPTION +.I Arch +maintains groups of files +combined into a single archive file. +The Amsterdam compiler kit provides its own archiver with a +fixed, machine-independent format, much like the UNIX-V7 +archive format. +.PP +.I Key +is one character from the set +.B adrtpx, +optionally concatenated with +one or more of +.B vl. +.I Afile +is the archive file. +The +.I names +are constituent files in the archive file. +The meanings of the +.I key +characters are: +.TP +.B d +Delete the named files from the archive file. +.TP +.B a +Append the named files to the archive file. +.TP +.B r +Replace the named files in the archive file. +New files are placed at the end. +.TP +.B t +Print a table of contents of the archive file. +If no names are given, all files in the archive are listed. +If names are given, only those files are listed. +.TP +.B p +Print the named files in the archive. +.TP +.B x +Extract the named files. +If no names are given, all files in the archive are +extracted. +In neither case does +.B x +alter the archive file. +.TP +.B v +Verbose. +Under the verbose option, +.I arch +gives a file-by-file +description of the making of a +new archive file from the old archive and the constituent files. +When used with +.B t, +it gives a long listing of all information about the files. +When used with +.BR p , +it precedes each file with a name. +.TP +.B l +Local. +Normally +.I arch +places its temporary files in the directory /tmp. +This option causes them to be placed in the local directory. +.SH FILES +/tmp/ar.* temporaries +.SH "SEE ALSO" +em_ass(I), arch(V), +.SH BUGS +If the same file is mentioned twice in an argument list, +it may be put in the archive twice. diff --git a/util/arch/archiver.c b/util/arch/archiver.c new file mode 100644 index 00000000..2187194e --- /dev/null +++ b/util/arch/archiver.c @@ -0,0 +1,679 @@ +/* ar - archiver Author: Michiel Huisjes */ +/* Made into arch/aal by Ceriel Jacobs + */ + +static char RcsId[] = "$Header$"; + +/* + * Usage: [arch|aal] [adprtvx] archive [file] ... + * v: verbose + * x: extract + * a: append + * r: replace (append when not in archive) + * d: delete + * t: print contents of archive + * p: print named files + * l: temporaries in current directory instead of /tmp + */ + +#include +#include +#include +#include +#ifdef AAL +#include +#include +#define MAGIC_NUMBER AALMAG +#ifdef AAL +#define TABSZ 2000 /* maximum # of ranlib table entries */ +#define STRTABSZ 8*TABSZ /* maximum size of string table */ +long offset; +struct ranlib tab[TABSZ]; +long tnum = 0; +char tstrtab[STRTABSZ]; +long tssiz = 0; +char *malloc(), *strcpy(); +long tell(); +long time(); +#endif AAL +#else +#define MAGIC_NUMBER ARMAG +#endif + +#define odd(nr) (nr & 01) +#define even(nr) (odd(nr) ? nr + 1 : nr) + +typedef char BOOL; +#define FALSE 0 +#define TRUE 1 + +#define READ 0 +#define APPEND 2 +#define CREATE 1 + +#define MEMBER struct ar_hdr + +#define NIL_PTR ((char *) 0) +#define NIL_MEM ((MEMBER *) 0) +#define NIL_LONG ((long *) 0) + +#define IO_SIZE (10 * 1024) + +#define equal(str1, str2) (!strncmp((str1), (str2), 14)) + +BOOL verbose; +BOOL app_fl; +BOOL ex_fl; +BOOL show_fl; +BOOL pr_fl; +BOOL rep_fl; +BOOL del_fl; +BOOL local_fl; + +int ar_fd; + +char io_buffer[IO_SIZE]; + +char *progname; + +char temp_buf[32]; +char *temp_arch = &temp_buf[0]; +extern char *mktemp(); +extern char *ctime(); + +usage() +{ + error(TRUE, "usage: %s %s archive [file] ...\n", + progname, +#ifdef AAL + "[adrtxvl]" +#else + "[adprtxvl]" +#endif + ); +} + +/*VARARGS2*/ +error(quit, str1, str2, str3, str4) +BOOL quit; +char *str1, *str2, *str3, *str4; +{ + char errbuf[256]; + + sprint(errbuf, str1, str2, str3, str4); + write(2, errbuf, strlen(errbuf)); + if (quit) { + unlink(temp_arch); + _exit(1); + } +} + +char *basename(path) +char *path; +{ + register char *ptr = path; + register char *last = NIL_PTR; + + while (*ptr != '\0') { + if (*ptr == '/') + last = ptr; + ptr++; + } + if (last == NIL_PTR) + return path; + if (*(last + 1) == '\0') { + *last = '\0'; + return basename(path); + } + return last + 1; +} + +extern unsigned int rd_unsigned2(); + +open_archive(name, mode) +register char *name; +register int mode; +{ + unsigned short magic = 0; + int fd; + + if (mode == CREATE) { + if ((fd = creat(name, 0644)) < 0) + error(TRUE, "cannot creat %s\n", name); + magic = MAGIC_NUMBER; + wr_int2(fd, magic); + return fd; + } + + if ((fd = open(name, mode)) < 0) { + if (mode == APPEND) { + close(open_archive(name, CREATE)); + error(FALSE, "%s: creating %s\n", progname, name); + return open_archive(name, APPEND); + } + error(TRUE, "cannot open %s\n", name); + } + lseek(fd, 0L, 0); + magic = rd_unsigned2(fd); + if (magic != MAGIC_NUMBER) + error(TRUE, "%s is not in ar format\n", name); + + return fd; +} + +catch() +{ + unlink(temp_arch); + _exit (2); +} + +main(argc, argv) +int argc; +char *argv[]; +{ + register char *ptr; + int pow, pid; + + progname = argv[0]; + + if (argc < 3) + usage(); + + for (ptr = argv[1]; *ptr; ptr++) { + switch (*ptr) { + case 't' : + show_fl = TRUE; + break; + case 'v' : + verbose = TRUE; + break; + case 'x' : + ex_fl = TRUE; + break; + case 'a' : + app_fl = TRUE; + break; +#ifndef AAL + case 'p' : + pr_fl = TRUE; + break; +#endif + case 'd' : + del_fl = TRUE; + break; + case 'r' : + rep_fl = TRUE; + break; + case 'l' : + local_fl = TRUE; + break; + default : + usage(); + } + } + if (local_fl) strcpy(temp_arch, "ar.XXXXXX"); + else strcpy(temp_arch, "/tmp/ar.XXXXXX"); + + if (app_fl + ex_fl + del_fl + rep_fl + show_fl + pr_fl != 1) + usage(); + + if (rep_fl || del_fl +#ifdef AAL + || app_fl +#endif + ) { + mktemp(temp_arch); + } + + signal(SIGINT, catch); + get(argc, argv); + + return 0; +} + +MEMBER * +get_member() +{ + static MEMBER member; + register int ret; + +again: + if ((ret = rd_arhdr(ar_fd, &member)) == 0) + return NIL_MEM; +#ifdef AAL + if (equal(SYMDEF, member.ar_name)) { + lseek(ar_fd, member.ar_size, 1); + goto again; + } +#endif + return &member; +} + +char *get_mode(); + +get(argc, argv) +int argc; +register char *argv[]; +{ + register MEMBER *member; + int i = 0; + int temp_fd, read_chars; + + ar_fd = open_archive(argv[2], (show_fl || pr_fl) ? READ : APPEND); + if (rep_fl || del_fl +#ifdef AAL + || app_fl +#endif + ) + temp_fd = open_archive(temp_arch, CREATE); + while ((member = get_member()) != NIL_MEM) { + if (argc > 3) { + for (i = 3; i < argc; i++) { + if (equal(basename(argv[i]), member->ar_name)) + break; + } + if (i == argc || app_fl) { + if (rep_fl || del_fl +#ifdef AAL + || app_fl +#endif + ) { +#ifdef AAL + if (i != argc) { + print("%s: already in archive\n", argv[i]); + argv[i] = ""; + } +#endif + wr_arhdr(temp_fd, member); + copy_member(member, ar_fd, temp_fd, 0); + } +#ifndef AAL + else { + if (app_fl && i != argc) { + print("%s: already in archive\n", argv[i]); + argv[i] = ""; + } + lseek(ar_fd, even(member->ar_size),1); + } +#endif + continue; + } + } + if (ex_fl || pr_fl) + extract(member); + else { + if (rep_fl) + add(argv[i], temp_fd, "r - %s\n"); + else if (show_fl) { + char buf[sizeof(member->ar_name) + 2]; + register char *p = buf, *q = member->ar_name; + + while (q <= &member->ar_name[sizeof(member->ar_name)-1] && *q) { + *p++ = *q++; + } + *p++ = '\n'; + *p = '\0'; + if (verbose) { + char *mode = get_mode(member->ar_mode); + char *date = ctime(&(member->ar_date)); + + *(date + 16) = '\0'; + *(date + 24) = '\0'; + + print("%s%3u/%u%7ld %s %s %s", + mode, + (unsigned) member->ar_uid, + (unsigned) member->ar_gid, + member->ar_size, + date+4, + date+20, + buf); + } + else print(buf); + } + else if (del_fl) + show("d - %s\n", member->ar_name); + lseek(ar_fd, even(member->ar_size), 1); + } + argv[i] = ""; + } + + if (argc > 3) { + for (i = 3; i < argc; i++) + if (argv[i][0] != '\0') { +#ifndef AAL + if (app_fl) + add(argv[i], ar_fd, "a - %s\n"); + else +#endif + if (rep_fl +#ifdef AAL + || app_fl +#endif + ) + add(argv[i], temp_fd, "a - %s\n"); + else { + print("%s: not found\n", argv[i]); + } + } + } + + if (rep_fl || del_fl +#ifdef AAL + || app_fl +#endif + ) { + signal(SIGINT, SIG_IGN); + close(ar_fd); + close(temp_fd); + ar_fd = open_archive(argv[2], CREATE); + temp_fd = open_archive(temp_arch, APPEND); +#ifdef AAL + write_symdef(); +#endif + while ((read_chars = read(temp_fd, io_buffer, IO_SIZE)) > 0) + mwrite(ar_fd, io_buffer, read_chars); + close(temp_fd); + unlink(temp_arch); + } + close(ar_fd); +} + +add(name, fd, mess) +char *name; +int fd; +char *mess; +{ + static MEMBER member; + register int read_chars; + struct stat status; + int src_fd; + + if (stat(name, &status) < 0) { + error(FALSE, "cannot find %s\n", name); + return; + } + else if ((src_fd = open(name, 0)) < 0) { + error(FALSE, "cannot open %s\n", name); + return; + } + + strncpy (member.ar_name, basename (name), sizeof(member.ar_name)); + member.ar_uid = status.st_uid; + member.ar_gid = status.st_gid; + member.ar_mode = status.st_mode; + member.ar_date = status.st_mtime; + member.ar_size = status.st_size; + wr_arhdr(fd, &member); +#ifdef AAL + do_object(src_fd, member.ar_size); + lseek(src_fd, 0L, 0); + offset += AR_TOTAL + even(member.ar_size); +#endif + while (status.st_size > 0) { + int x = IO_SIZE; + + read_chars = x; + if (status.st_size < x) { + x = status.st_size; + read_chars = x; + status.st_size = 0; + x = even(x); + } + else status.st_size -= x; + if (read(src_fd, io_buffer, read_chars) != read_chars) + error(FALSE,"%s seems to shrink\n", name); + mwrite(fd, io_buffer, x); + } + + if (verbose) + show(mess, name); + close(src_fd); +} + +extract(member) +register MEMBER *member; +{ + int fd = 1; + + if (pr_fl == FALSE && (fd = creat(member->ar_name, 0644)) < 0) { + error(FALSE, "cannot create %s\n", member->ar_name); + return; + } + + if (verbose) { + if (pr_fl == FALSE) show("x - %s\n", member->ar_name); + else show("\n<%s>\n\n", member->ar_name); + } + + copy_member(member, ar_fd, fd, 1); + + if (fd != 1) + close(fd); + if (pr_fl == FALSE) chmod(member->ar_name, member->ar_mode); +} + +copy_member(member, from, to, extracting) +register MEMBER *member; +int from, to; +{ + register int rest; + long mem_size = member->ar_size; + BOOL is_odd = odd(mem_size) ? TRUE : FALSE; + +#ifdef AAL + if (! extracting) { + long pos = lseek(from, 0L, 1); + + do_object(from, mem_size); + offset += AR_TOTAL + even(mem_size); + lseek(from, pos, 0); + } +#endif + do { + rest = mem_size > (long) IO_SIZE ? IO_SIZE : (int) mem_size; + if (read(from, io_buffer, rest) != rest) + error(TRUE, "read error on %s\n", member->ar_name); + mwrite(to, io_buffer, rest); + mem_size -= (long) rest; + } while (mem_size != 0L); + + if (is_odd) { + lseek(from, 1L, 1); + if (! extracting) + lseek(to, 1L, 1); + } +} + +char * +get_mode(mode) +register int mode; +{ + static char mode_buf[11]; + register int tmp = mode; + int i; + + mode_buf[9] = ' '; + for (i = 0; i < 3; i++) { + mode_buf[i * 3] = (tmp & S_IREAD) ? 'r' : '-'; + mode_buf[i * 3 + 1] = (tmp & S_IWRITE) ? 'w' : '-'; + mode_buf[i * 3 + 2] = (tmp & S_IEXEC) ? 'x' : '-'; + tmp <<= 3; + } + if (mode & S_ISUID) + mode_buf[2] = 's'; + if (mode & S_ISGID) + mode_buf[5] = 's'; + return mode_buf; +} + +wr_fatal() +{ + error(TRUE, "write error\n"); +} + +rd_fatal() +{ + error(TRUE, "read error\n"); +} + +mwrite(fd, address, bytes) +int fd; +register char *address; +register int bytes; +{ + if (write(fd, address, bytes) != bytes) + error(TRUE, "write error\n"); +} + +show(s, name) +char *s, *name; +{ + MEMBER x; + char buf[sizeof(x.ar_name)+1]; + register char *p = buf, *q = name; + + while (q <= &name[sizeof(x.ar_name)-1] && *q) *p++ = *q++; + *p++ = '\0'; + print(s, buf); +} + +#ifdef AAL +/* + * Write out the ranlib table: first 4 bytes telling how many ranlib structs + * there are, followed by the ranlib structs, + * then 4 bytes giving the size of the string table, followed by the string + * table itself. + */ +write_symdef() +{ + register struct ranlib *ran; + register char *str; + register int i; + register long delta; + MEMBER arbuf; + + if (odd(tssiz)) + tstrtab[tssiz++] = '\0'; + for (i = 0; i < sizeof(arbuf.ar_name); i++) + arbuf.ar_name[i] = '\0'; + strcpy(arbuf.ar_name, SYMDEF); + arbuf.ar_size = 4 + 2 * 4 * tnum + 4 + tssiz; + time(&arbuf.ar_date); + arbuf.ar_uid = getuid(); + arbuf.ar_gid = getgid(); + arbuf.ar_mode = 0444; + wr_arhdr(ar_fd,&arbuf); + wr_long(ar_fd, tnum); + /* + * Account for the space occupied by the magic number + * and the ranlib table. + */ + delta = 2 + AR_TOTAL + arbuf.ar_size; + for (ran = tab; ran < &tab[tnum]; ran++) { + ran->ran_pos += delta; + } + + wr_ranlib(ar_fd, tab, tnum); + wr_long(ar_fd, tssiz); + wr_bytes(ar_fd, tstrtab, tssiz); +} + +/* + * Return whether the bytes in `buf' form a good object header. + * The header is put in `headp'. + */ +int +is_outhead(headp) + register struct outhead *headp; +{ + + return !BADMAGIC(*headp) && headp->oh_nname != 0; +} + +do_object(f, size) + long size; +{ + struct outhead headbuf; + + if (size < SZ_HEAD) { + /* It can't be an object file. */ + return; + } + /* + * Read a header to see if it is an object file. + */ + if (! rd_fdopen(f)) { + rd_fatal(); + } + rd_ohead(&headbuf); + if (!is_outhead(&headbuf)) { + return; + } + do_names(&headbuf); +} + +/* + * First skip the names and read in the string table, then seek back to the + * name table and read and write the names one by one. Update the ranlib table + * accordingly. + */ +do_names(headp) + struct outhead *headp; +{ + register char *strings; + register int nnames = headp->oh_nname; +#define NNAMES 100 + struct outname namebuf[NNAMES]; + char *xxx; + + if ( headp->oh_nchar != (unsigned int)headp->oh_nchar || + (strings = malloc((unsigned int)headp->oh_nchar)) == (char *)0 + ) { + error(TRUE, "string table too big\n"); + } + rd_string(strings, headp->oh_nchar); + xxx = strings - OFF_CHAR(*headp); + while (nnames) { + int i = nnames >= NNAMES ? NNAMES : nnames; + register struct outname *p = namebuf; + + nnames -= i; + rd_name(namebuf, i); + while (i--) { + if (p->on_foff == (long)0) + continue; /* An unrecognizable name. */ + p->on_mptr = xxx + p->on_foff; + /* + * Only enter names that are exported and are really + * defined. + */ + if ( (p->on_type & S_EXT) && + (p->on_type & S_TYP) != S_UND && + !(p->on_type & S_COM) + ) + enter_name(p); + p++; + } + } + free(strings); +} + +enter_name(namep) + struct outname *namep; +{ + register char *cp; + + if (tnum >= TABSZ) { + error(TRUE, "symbol table overflow\n"); + } + tab[tnum].ran_off = tssiz; + tab[tnum].ran_pos = offset; + + for (cp = namep->on_mptr; tstrtab[tssiz++] = *cp++;) + if (tssiz >= STRTABSZ) { + error(TRUE, "string table overflow\n"); + } + tnum++; +} +#endif AAL From 928ca277c25e9257e490aab0e2ad9d27a445dd19 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 13 Jan 1987 09:24:13 +0000 Subject: [PATCH 0474/1625] Initial revision --- mach/m68020/ncg/mach.c | 236 +++ mach/m68020/ncg/mach.h | 39 + mach/m68020/ncg/table | 3288 ++++++++++++++++++++++++++++++++++++++++ mach/m68k2/ncg/mach.c | 236 +++ mach/m68k2/ncg/mach.h | 39 + mach/m68k2/ncg/table | 3288 ++++++++++++++++++++++++++++++++++++++++ mach/m68k4/ncg/mach.c | 236 +++ mach/m68k4/ncg/mach.h | 39 + mach/m68k4/ncg/table | 3288 ++++++++++++++++++++++++++++++++++++++++ mach/moon3/ncg/mach.c | 236 +++ mach/moon3/ncg/mach.h | 39 + mach/moon3/ncg/table | 3288 ++++++++++++++++++++++++++++++++++++++++ 12 files changed, 14252 insertions(+) create mode 100644 mach/m68020/ncg/mach.c create mode 100644 mach/m68020/ncg/mach.h create mode 100644 mach/m68020/ncg/table create mode 100644 mach/m68k2/ncg/mach.c create mode 100644 mach/m68k2/ncg/mach.h create mode 100644 mach/m68k2/ncg/table create mode 100644 mach/m68k4/ncg/mach.c create mode 100644 mach/m68k4/ncg/mach.h create mode 100644 mach/m68k4/ncg/table create mode 100644 mach/moon3/ncg/mach.c create mode 100644 mach/moon3/ncg/mach.h create mode 100644 mach/moon3/ncg/table diff --git a/mach/m68020/ncg/mach.c b/mach/m68020/ncg/mach.c new file mode 100644 index 00000000..ec51f8bf --- /dev/null +++ b/mach/m68020/ncg/mach.c @@ -0,0 +1,236 @@ +/* + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. + * + * This product is part of the Amsterdam Compiler Kit. + * + * Permission to use, sell, duplicate or disclose this software must be + * obtained in writing. Requests for such permissions may be sent to + * + * Dr. Andrew S. Tanenbaum + * Wiskundig Seminarium + * Vrije Universiteit + * Postbox 7161 + * 1007 MC Amsterdam + * The Netherlands + * + */ + +/* + * machine dependent back end routines for the Motorola 68000, 68010 or 68020 + */ + +#ifndef m68k4 +#define m68020 +#endif + /* use m68020 when you want a m68020 cg, don't if you want a + * m68k4 cg. The m68k4 cg can be used for both the MC68000 + * and the MC68010. + */ + +con_part(sz,w) register sz; word w; { + + while (part_size % sz) + part_size++; + if (part_size == 4) + part_flush(); + if (sz == 1) { + w &= 0xFF; + w <<= 8*(3-part_size); + part_word |= w; + } else if (sz == 2) { + w &= 0xFFFF; + if (part_size == 0) + w <<= 16; + part_word |= w; + } else { + assert(sz == 4); + part_word = w; + } + part_size += sz; +} + +con_mult(sz) word sz; { + + if (sz != 4) + fatal("bad icon/ucon size"); + fprintf(codefile,".data4 %s\n",str); +} + +con_float() { + +static int been_here; + if (argval != 4 && argval != 8) + fatal("bad fcon size"); + fprintf(codefile,".data4\t"); + if (argval == 8) + fprintf(codefile,"F_DUM,"); + fprintf(codefile,"F_DUM\n"); + if ( !been_here++) + { + fprintf(stderr,"Warning : dummy float-constant(s)\n"); + } +} + +regscore(off,size,typ,score,totyp) + long off; +{ + if (score == 0) return -1; + switch(typ) { + case reg_float: + return -1; + case reg_pointer: + if (size != 4 || totyp != reg_pointer) return -1; + score *= 2; + break; + case reg_loop: + score += 5; + /* fall through .. */ + case reg_any: + if (size != 4 || totyp == reg_pointer) return -1; + break; + } + if (off >= 0) { + /* parameters must be initialised with an instruction + * like "move.l 4(a6),d0", which costs 2 words. + */ + score -= 2; + } + score -= 1; /* take save/restore into account */ + return score; +} +struct regsav_t { + char *rs_reg; /* e.g. "a3" or "d5" */ + long rs_off; /* offset of variable */ + int rs_size; /* 2 or 4 bytes */ +} regsav[9]; + + +int regnr; + +i_regsave() +{ + regnr = 0; +} + +#define MOVEM_LIMIT 2 +/* If #registers to be saved exceeds MOVEM_LIMIT, we +* use the movem instruction to save registers; else +* we simply use several move.l's. +*/ + +save() +{ + register struct regsav_t *p; + + if (regnr > MOVEM_LIMIT) { + fprintf(codefile,"movem.l "); + for (p = regsav; ;) { + fprintf(codefile,"%s",p->rs_reg); + if (++p == ®sav[regnr]) break; + putc('/',codefile); + } + fprintf(codefile,",-(sp)\n"); + } else { + for (p = regsav; p < ®sav[regnr]; p++) { + fprintf(codefile,"move.l %s,-(sp)\n",p->rs_reg); + } + } + /* initialise register-parameters */ + for (p = regsav; p < ®sav[regnr]; p++) { + if (p->rs_off >= 0) { +#ifdef m68020 + fprintf(codefile,"move.%c (%ld,a6),%s\n", +#else + fprintf(codefile,"move.%c %ld(a6),%s\n", +#endif + (p->rs_size == 4 ? 'l' : 'w'), + p->rs_off, + p->rs_reg); + } + } +} + +restr() +{ + register struct regsav_t *p; + + if (regnr > MOVEM_LIMIT) { + fprintf(codefile,"movem.l (sp)+,"); + for (p = regsav; ;) { + fprintf(codefile,"%s",p->rs_reg); + if (++p == ®sav[regnr]) break; + putc('/',codefile); + } + putc('\n',codefile); + } else { + for (p = ®sav[regnr-1]; p >= regsav; p--) { + fprintf(codefile,"move.l (sp)+,%s\n",p->rs_reg); + } + } + fprintf(codefile,"unlk a6\n"); + fprintf(codefile,"rts\n"); +} + + +f_regsave() +{ + save(); +} + +regsave(str,off,size) + char *str; + long off; +{ + assert (regnr < 9); + regsav[regnr].rs_reg = str; + regsav[regnr].rs_off = off; + regsav[regnr++].rs_size = size; + fprintf(codefile, "!Local %ld into %s\n",off,str); +} + +regreturn() +{ + restr(); +} + + +prolog(nlocals) full nlocals; { + +#ifdef m68020 + fprintf(codefile,"tst.b (-%ld,sp)\nlink\ta6,#-%ld\n",nlocals+40,nlocals); +#else + fprintf(codefile,"tst.b -%ld(sp)\nlink\ta6,#-%ld\n",nlocals+40,nlocals); +#endif +} + + + +mes(type) word type ; { + int argt ; + + switch ( (int)type ) { + case ms_ext : + for (;;) { + switch ( argt=getarg( + ptyp(sp_cend)|ptyp(sp_pnam)|sym_ptyp) ) { + case sp_cend : + return ; + default: + strarg(argt) ; + fprintf(codefile,".define %s\n",argstr) ; + break ; + } + } + default : + while ( getarg(any_ptyp) != sp_cend ) ; + break ; + } +} + + +char *segname[] = { + ".sect .text", /* SEGTXT */ + ".sect .data", /* SEGCON */ + ".sect .rom", /* SEGROM */ + ".sect .bss" /* SEGBSS */ +}; diff --git a/mach/m68020/ncg/mach.h b/mach/m68020/ncg/mach.h new file mode 100644 index 00000000..ff2cf66c --- /dev/null +++ b/mach/m68020/ncg/mach.h @@ -0,0 +1,39 @@ +#ifndef m68k4 +#define m68020 +#endif + /* m68020 should be used for a m68020 cg, and it should + * not be used for a m68k4 cg + */ + +#define ex_ap(y) fprintf(codefile,".extern %s\n",y) +#define in_ap(y) /* nothing */ + +#define newilb(x) fprintf(codefile,"%s:\n",x) +#define newdlb(x) fprintf(codefile,"%s:\n",x) +#define dlbdlb(x,y) fprintf(codefile,"%s = %s\n",x,y) +#define newlbss(l,x) fprintf(codefile,"%s:.space\t%ld\n",l,x); + +#define pop_fmt "(sp)+" +#define cst_fmt "%ld" +#define off_fmt "%ld" +#define ilb_fmt "I%03x%x" +#define dlb_fmt "_%d" +#define hol_fmt "hol%d" + +#ifdef m68020 +#define loc_off "(%d,a6)" +#define arg_off "(8+%d,a6)" +#else +#define loc_off "%d(a6)" +#define arg_off "8+%d(a6)" +#endif +#define hol_off "%ld+hol%d" + +#define con_cst(x) fprintf(codefile,".data4\t%ld\n",x) +#define con_ilb(x) fprintf(codefile,".data4\t%s\n",x) +#define con_dlb(x) fprintf(codefile,".data4\t%s\n",x) + +#define modhead ".sect .text\n.sect .rom\n.sect .data\n.sect .bss\n" + +#define id_first '_' +#define BSS_INIT 0 diff --git a/mach/m68020/ncg/table b/mach/m68020/ncg/table new file mode 100644 index 00000000..6518487a --- /dev/null +++ b/mach/m68020/ncg/table @@ -0,0 +1,3288 @@ + /******************************** + * * + * 68000, 68010 and 68020 * + * back end table * + * * + ********************************/ + + +#ifndef m68k4 +#define m68020 +#endif + /* m68020 to be defined if this is the 68020 table. + * The 68000 and 68010 tables are identical. + */ + + +#define small(x) ((x)>=1 && (x)<=8) +#define nicesize(x) ((x)==1||(x)==2||(x)==4||(x)==8) +#define lowb(x) (((x)<<24)>>24) +#define loww(x) (((x)<<16)>>16) +#define in_1(x) ((x)>=0-128 && (x)<128) +#define in_2(x) ((x)>=0-32768 && (x)<32768) + + +EM_WSIZE = 4 +EM_PSIZE = 4 +EM_BSIZE = 8 + +SL = 8 + +TIMEFACTOR = 1/2 + + +PROPERTIES + +D_REG /* data registers */ +A_REG /* address registers */ +DD_REG /* allocatable D_REG, may not be a register variable */ +AA_REG /* allocatable A_REG, may not be a register variable */ + + + +REGISTERS + +d0, d1, d2 :D_REG, DD_REG. +d3, d4, d5, d6, d7 :D_REG regvar. +a0, a1 :A_REG, AA_REG. +a2, a3, a4, a5 :A_REG regvar(reg_pointer). +lb ("a6"), sp :A_REG. /* localbase and stack pointer */ + + + + +TOKENS + + /* Not all addressing modes available on the MC68020 are used in this + * table. E.g (Dn), data register indirect is not used. Compared to + * (An), address register indirect, (Dn) requires two more bytes and + * several more clock cycles. Using (Dn) is even more expensive in + * time than first moving Dn to an address register An, and then using + * (An). For this kind of reasons several addressing modes are + * not used in this table. + * + * Cost in bytes may sometimes be incorrect. Several effective addresses + * use displacements that can occupy either 2 or 4 bytes. These are not + * considered different TOKENS in this table. + * + * Data registers are the only registers used as index registers in this + * table; address registers are only used to hold addresses. + * + * For the m68k4 table: the MC68000 and MC68010 have two modes that use + * displacements (offsets) of limited size: + * - offset(A_REG, Index_reg), where offset is only 8 bits, and + * - offset(A_REG), where offset can only be 16 bits. + * To make sure that no output is given with offsets too large, two + * extra tokens are declared: t_regAregXcon and t_regAcon. These are + * used as addresses to these modes. Whenever the displacements become + * too large, they are transformed into different tokens. + * + * Sometimes some TOKENS are used with displacements (offsets) of 0. + * It would have been possible to provide separate TOKENS for these, in + * case the assembler doesn't handle zero offsets optimally. This + * however would mean a very large amount of extra TOKENS and SETS for + * a very small profit in code bytes, so we won't do that. + * + * To prevent the TOKENS list from getting too unreadable, #ifdefs are + * used to form three parts: + * (i) the common part; + * (ii) the m68k4 part; + * (iii) the m68020 part; + */ + + /* Part (i) */ +const = {INT num;} 4 cost(4,4) "#" num . +indirect4 = {A_REG reg;} 4 cost(0,4) "(" reg ")" . +post_inc4 = {A_REG reg;} 4 cost(0,4) "(" reg ")+" . +pre_dec4 = {A_REG reg;} 4 cost(0,5) "-(" reg ")" . +indirect2 = {A_REG reg;} 4 cost(0,4) "(" reg ")" . +post_inc2 = {A_REG reg;} 4 cost(0,4) "(" reg ")+" . +pre_dec2 = {A_REG reg;} 4 cost(0,5) "-(" reg ")" . +indirect1 = {A_REG reg;} 4 cost(0,4) "(" reg ")" . +post_inc1 = {A_REG reg;} 4 cost(0,4) "(" reg ")+" . +pre_dec1 = {A_REG reg;} 4 cost(0,5) "-(" reg ")" . + +ext_addr = {ADDR bd;} 4 cost(4,5) "#" bd . +llabel = {ADDR bd;} 4 cost(2,0) bd . +slabel = {ADDR bd;} 4 cost(0,0) bd . +shconst = {INT num;} 4 cost(0,0) "#" num . + +#ifndef m68020 + /* Part (ii) */ +absolute4 = {ADDR bd;} 4 cost(4,8) bd . +offsetted4 = {A_REG reg; INT bd;} 4 cost(2,6) bd "(" reg ")" . +index_off4 = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,7) + bd "(" reg "," xreg ".l)" . +absolute2 = {ADDR bd;} 4 cost(4,6) bd . +offsetted2 = {A_REG reg; INT bd;} 4 cost(2,4) bd "(" reg ")" . +index_off2 = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,5) + bd "(" reg "," xreg ".l)" . +absolute1 = {ADDR bd;} 4 cost(4,6) bd . +offsetted1 = {A_REG reg; INT bd;} 4 cost(2,4) bd "(" reg ")" . +index_off1 = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,5) + bd "(" reg "," xreg ".l)" . + +LOCAL = {INT bd;} 4 cost(2,6) bd "(a6)" . + +local_addr = {INT bd;} 4 cost(2,6) bd "(a6)" . +regAcon = {A_REG reg; INT bd;} 4 cost(2,6) bd "(" reg ")" . +regAregXcon = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,8) + bd "(" reg "," xreg ".l)" . + /* note: in the m68k4 version %sc always equals 1 */ + +t_regAregXcon = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,8) . +t_regAcon = {A_REG reg; INT bd;} 4 cost(2,6) . + +#else m68020 + /* Part (iii) */ +absolute4 = {ADDR bd;} 4 cost(4,7) "(" bd ")" . +offsetted4 = {A_REG reg; INT bd;} 4 cost(2,6) "(" bd "," reg ")" . +index_off4 = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(4,9) + "(" bd "," reg "," xreg ".l*" sc ")" . +abs_index4 = {INT sc; D_REG xreg; ADDR bd;} 4 cost(6,9) + "(" bd "," xreg ".l*" sc ")" . +OFF_off4 = {A_REG reg; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "]," od ")" . +OFF_indoff4 = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "]," xreg ".l*" sc "," od ")" . +INDOFF_off4 = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "," xreg ".l*" sc "]," od ")" . +ABS_off4 = {ADDR bd; ADDR od;} 4 cost(8,22) "([" bd "]," od ")" . +ABS_indoff4 = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,22) + "([" bd "]," xreg ".l*" sc "," od ")" . +ABSIND_off4 = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,22) + "([" bd "," xreg ".l*" sc "]," od ")" . + +absolute2 = {ADDR bd;} 4 cost(4,7) "(" bd ")" . +offsetted2 = {A_REG reg; INT bd;} 4 cost(2,6) "(" bd "," reg ")" . +index_off2 = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(4,9) + "(" bd "," reg "," xreg ".l*" sc ")" . +abs_index2 = {INT sc; D_REG xreg; ADDR bd;} 4 cost(6,9) + "(" bd "," xreg ".l*" sc ")" . +OFF_off2 = {A_REG reg; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "]," od ")" . +OFF_indoff2 = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "]," xreg ".l*" sc "," od ")" . +INDOFF_off2 = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "," xreg ".l*" sc "]," od ")" . +ABS_off2 = {ADDR bd; ADDR od;} 4 cost(8,22) "([" bd "]," od ")" . +ABS_indoff2 = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,22) + "([" bd "]," xreg ".l*" sc "," od ")" . +ABSIND_off2 = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,22) + "([" bd "," xreg ".l*" sc "]," od ")" . + +absolute1 = {ADDR bd;} 4 cost(4,7) "(" bd ")" . +offsetted1 = {A_REG reg; INT bd;} 4 cost(2,6) "(" bd "," reg ")" . +index_off1 = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(4,9) + "(" bd "," reg "," xreg ".l*" sc ")" . +abs_index1 = {INT sc; D_REG xreg; ADDR bd;} 4 cost(6,9) + "(" bd "," xreg ".l*" sc ")" . +OFF_off1 = {A_REG reg; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "]," od ")" . +OFF_indoff1 = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "]," xreg ".l*" sc "," od ")" . +INDOFF_off1 = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "," xreg ".l*" sc "]," od ")" . +ABS_off1 = {ADDR bd; ADDR od;} 4 cost(8,22) "([" bd "]," od ")" . +ABS_indoff1 = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,22) + "([" bd "]," xreg ".l*" sc "," od ")" . +ABSIND_off1 = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,22) + "([" bd "," xreg ".l*" sc "]," od ")" . + +LOCAL = {INT bd;} 4 cost(2,6) "(" bd ",a6)" . +ILOCAL = {INT bd;} 4 cost(4,16) "([" bd ",a6])" . + +local_addr = {INT bd;} 4 cost(2,3) "(" bd ",a6)" . +regAcon = {A_REG reg; INT bd;} 4 cost(2,3) "(" bd "," reg ")" . +regAregXcon = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,7) + "(" bd "," reg "," xreg ".l*" sc ")" . +off_con = {A_REG reg; INT bd; ADDR od;} 4 cost(6,18) + "([" bd "," reg "]," od ")". +off_regXcon = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,18) + "([" bd "," reg "]," xreg ".l*" sc "," od ")" . +indoff_con = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,18) + "([" bd "," reg "," xreg ".l*" sc "]," od ")" . +abs_con = {ADDR bd; ADDR od;} 4 cost(8,21) "([" bd "]," od ")" . +abs_regXcon = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,21) + "([" bd "]," xreg ".l*" sc "," od ")" . +absind_con = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,21) + "([" bd "," xreg ".l*" sc "]," od ")" . +ext_regX = {INT sc; D_REG xreg; ADDR bd;} 4 cost(6,15) + "(" bd "," xreg ".l*" sc ")" . + +regX = {INT sc; D_REG xreg;} 4 cost(2,7) "(" xreg ".l*" sc ")" . +DREG_pair = {D_REG reg1; D_REG reg2;} 8 cost(2,0) reg1 ":" reg2 . + +#define t_regAregXcon regAregXcon +#define t_regAcon regAcon + +#endif m68020 + +SETS + + /* The SETS list cannot be kept as 'readable' as the TOKENS list + * because cgg is one pass. + */ + +#ifndef m68020 + /* A m68k4 part */ +data4 = D_REG + LOCAL + const + post_inc4 + pre_dec4 + + indirect4 + offsetted4 + index_off4 + absolute4 + + ext_addr . +memory4 = data4 - D_REG . +control4 = indirect4 + offsetted4 + index_off4 + absolute4 + + LOCAL . +alterable4 = data4 + A_REG - const - ext_addr . +any4 = data4 + A_REG . /* all four above together */ + +data2 = D_REG + post_inc2 + pre_dec2 + indirect2 + + offsetted2 + index_off2 + absolute2 + const . +memory2 = data2 - D_REG . +control2 = indirect2 + offsetted2 + index_off2 + absolute2 . +alterable2 = data2 + A_REG - const . +any2 = data2 + A_REG . + +data1 = D_REG + post_inc1 + pre_dec1 + indirect1 + + offsetted1 + index_off1 + absolute1 + const . +memory1 = data1 - D_REG . +control1 = indirect1 + offsetted1 + index_off1 + absolute1 . +alterable1 = data1 - const . +any1 = data1 . + +#else m68020 + +data4 = D_REG + indirect4 + post_inc4 + pre_dec4 + index_off4 + + offsetted4 + OFF_off4 + OFF_indoff4 + + INDOFF_off4 + + ABS_off4 + ABS_indoff4 + ABSIND_off4 + + absolute4 + abs_index4 + const + ext_addr + + LOCAL + ILOCAL . +memory4 = data4 - D_REG . +control4 = memory4 - (post_inc4 + pre_dec4 + const + ext_addr) . +alterable4 = data4 + A_REG - const - ext_addr . +any4 = data4 + A_REG . /* all four above together */ + +data2 = D_REG + indirect2 + post_inc2 + pre_dec2 + index_off2 + + offsetted2 + OFF_off2 + OFF_indoff2 + + INDOFF_off2 + + ABS_off2 + ABS_indoff2 + ABSIND_off2 + + absolute2 + abs_index2 + const . +memory2 = data2 - D_REG . +control2 = memory2 - (post_inc2 + pre_dec2 + const) . +alterable2 = data2 + A_REG - const . +any2 = data2 + A_REG . /* all four above together */ + +data1 = D_REG + indirect1 + post_inc1 + pre_dec1 + index_off1 + + offsetted1 + OFF_off1 + OFF_indoff1 + + INDOFF_off1 + + ABS_off1 + ABS_indoff1 + ABSIND_off1 + + absolute1 + abs_index1 + const . +memory1 = data1 - D_REG . +control1 = memory1 - (post_inc1 + pre_dec1 + const) . +alterable1 = data1 - const . +any1 = data1 . /* all four above together */ + +#endif m68020 + /* This is a common part */ +any = any4 + any2 + any1 . +absolute = absolute4 + absolute2 + absolute1 . +control = control4 + control2 + control1 . +indirect = indirect4 + indirect2 + indirect1 . +pre_post = pre_dec4 + pre_dec2 + pre_dec1 + + post_inc4 + post_inc2 + post_inc1 . +offsetted = offsetted4 + offsetted2 + offsetted1 . +index_off = index_off4 + index_off2 + index_off1 . + +#ifndef m68020 + /* A m68k4 part */ +regind_addr = regAcon + regAregXcon + t_regAcon + t_regAregXcon . +address = ext_addr + local_addr + regAcon + regAregXcon . +all_regind = indirect + offsetted + pre_post + index_off + + regind_addr . +all_indir = all_regind . +allexceptcon = ALL - ( D_REG + A_REG + const + + local_addr + ext_addr + regAcon + regAregXcon + + t_regAcon + t_regAregXcon ) . +use_index = index_off4 + index_off2 + index_off1 . + +#else m68020 + +reg_memind4 = OFF_off4 + OFF_indoff4 + INDOFF_off4 . +memind4 = reg_memind4 + + ABS_off4 + ABS_indoff4 . +reg_memind2 = OFF_off2 + OFF_indoff2 + INDOFF_off2 . +memind2 = reg_memind2 + + ABS_off2 + ABS_indoff2 . +reg_memind1 = OFF_off1 + OFF_indoff1 + INDOFF_off1 . +memind1 = reg_memind1 + + ABS_off1 + ABS_indoff1 . +reg_memind = reg_memind4 + reg_memind2 + reg_memind1 . +memind = memind4 + memind2 + memind1 . +regind_addr = regAcon + regAregXcon + + off_con + off_regXcon + + indoff_con . +address = regind_addr + + ext_addr + local_addr + + abs_con + abs_regXcon + + absind_con + + ext_regX . +all_regind = indirect + offsetted + index_off + pre_post + + reg_memind + regind_addr . +all_indir = all_regind + memind + ILOCAL . +allexceptcon = ALL - ( D_REG + A_REG + const + + local_addr + ext_addr + regAcon + regAregXcon + ext_regX ) . +use_index4 = index_off4 + abs_index4 + + OFF_indoff4 + INDOFF_off4 + + ABS_indoff4 + ABSIND_off4 . +use_index2 = index_off2 + abs_index2 + + OFF_indoff2 + INDOFF_off2 + + ABS_indoff2 + ABSIND_off2 . +use_index1 = index_off1 + abs_index1 + + OFF_indoff1 + INDOFF_off1 + + ABS_indoff1 + ABSIND_off1 . +use_indaddr = regAregXcon + + off_regXcon + indoff_con + + abs_regXcon + absind_con + + ext_regX . + +use_index = use_index4 + use_index2 + use_index1 + use_indaddr + regX . + +#endif m68020 + /* A common part */ +posextern = absolute + all_indir . + +genreg = D_REG + A_REG. +label = llabel + slabel . +immediate4 = const + ext_addr . +conreg4 = D_REG + immediate4 . +conreg2 = D_REG + const . +conreg1 = D_REG + const . +shconreg = D_REG + shconst . +datalt4 = data4 * alterable4 . +datalt2 = data2 * alterable2 . +datalt1 = data1 * alterable1 . +datalt = datalt4 + datalt2 + datalt1 . +memalt4 = memory4 * alterable4 . +memalt2 = memory2 * alterable2 . +memalt1 = memory1 * alterable1 . + +#ifndef m68020 + /* A m68k4 part */ +imm_cmp4 = alterable4 . +imm_cmp2 = alterable2 . +imm_cmp1 = datalt1 . + +test_set4 = datalt4 . +test_set2 = datalt2 . +test_set1 = datalt1 . + +#else m68020 + +imm_cmp4 = any4 - immediate4 . +imm_cmp2 = any2 - const . +imm_cmp1 = data1 - const . + +test_set4 = data4 - immediate4 . +test_set2 = data2 - const . +test_set1 = data1 - const . + +#endif m68020 + +test_set = test_set4 + test_set2 + test_set1 . + +#ifndef m68020 +t_address = address + t_regAregXcon + t_regAcon . +#else m68020 +#define t_address address +#endif m68020 + + +INSTRUCTIONS + + /* Since the 68000 , the 68010 and the 68020 instruction sets are rather + * extensive, especially because e.g. 'add.l' and 'add.w' are + * considered different instructions, only those instructions are + * listed here that are used in the rest of this table. + * + * Instruction timing cost cannot be accurately given, nor the timing + * cost for getting operands. Detailed information about this can be + * found in the "MC68020 User's Manual", section 9, about instruction + * timing. The cost used in this table are 'worst case' cost, as + * mentioned in section 9 of the user's manual. + * + * The first few instructions had to be added because register + * variables are used. The LOCALs below are register variables. + * One may not conclude that these operations are also allowed + * on LOCALs that are not register variables. + * The cost have been adapted, but are not accurate; when 'real' + * LOCALs are used the cost are very inaccurate. + */ + +add_l "add.l" any4:ro, LOCAL:rw:cc cost(0,0). +lea address:ro, LOCAL:wo cost(0,0). +sub_l "sub.l" any4:ro, LOCAL:rw:cc cost(0,0). +sh "illegal" shconreg:ro, LOCAL:rw:cc cost(0,0). +sh "illegal" LOCAL:ro, LOCAL:rw:cc cost(0,0). +xxx "illegal" data4:ro, LOCAL:rw:cc cost(0,0). +xxx "illegal" LOCAL:ro, alterable4:rw:cc cost(0,0). +#ifdef m68020 +divs_l "divs.l" data4:ro, LOCAL:rw:cc cost(0,90). +divu_l "divu.l" data4:ro, LOCAL:rw:cc cost(0,78). +muls_l "muls.l" data4:ro, LOCAL:rw:cc cost(0,44). +mulu_l "mulu.l" data4:ro, LOCAL:rw:cc cost(0,44). +#endif m68020 + +add_l "add.l" any4:ro, D_REG:rw:cc cost(2,3). +add_l "add.l" any4:ro, A_REG:rw cost(2,3). +add_l "add.l" conreg4:ro, alterable4:rw:cc cost(2,6). +and_l "and.l" data4:ro, D_REG:rw:cc cost(2,3). +and_l "and.l" D_REG:ro, memalt4:rw:cc cost(2,6). +and_l "and.l" const:ro, datalt4:rw:cc cost(2,6). +asl_l "asl.l" shconreg:ro, D_REG:rw:cc cost(2,5). +asl "asl #1," memalt2:rw:cc cost(2,4). +asr_l "asr.l" shconreg:ro, D_REG:rw:cc cost(2,4). +asr "asr #1," memalt2:rw:cc cost(2,4). +bra label cost(2,5). +bcc label cost(2,5). +bcs label cost(2,5). +beq label cost(2,5). +bge label cost(2,5). +bgt label cost(2,5). +bhi label cost(2,5). +ble label cost(2,5). +bls label cost(2,5). +blt label cost(2,5). +bmi label cost(2,5). +bne label cost(2,5). +bpl label cost(2,5). +bvc label cost(2,5). +bvs label cost(2,5). +bset conreg2:ro, D_REG:rw kills :cc cost(2,4). +btst conreg2:ro, data1:rw kills :cc cost(2,3). +clr_l "clr.l" D_REG:wo:cc cost(2,3). +clr_l "clr.l" memalt4:wo:cc cost(2,6). +clr_w "clr.w" D_REG:wo:cc cost(2,2). +clr_w "clr.w" memalt2:wo:cc cost(2,4). +clr_b "clr.b" D_REG:wo:cc cost(2,2). +clr_b "clr.b" memalt1:wo:cc cost(2,4). +cmp_l "cmp.l" any4:ro, genreg:ro kills :cc cost(2,3). +cmp_l "cmp.l" post_inc4:ro, post_inc4:ro kills :cc cost(2,2). +cmp_l "cmp.l" immediate4:ro, imm_cmp4:ro kills :cc cost(2,2). +cmp_w "cmp.w" any2:ro, genreg:ro kills :cc cost(2,3). +cmp_w "cmp.w" post_inc2:ro, post_inc2:ro kills :cc cost(2,2). +cmp_w "cmp.w" const:ro, imm_cmp2:ro kills :cc cost(2,2). +cmp_b "cmp.b" data1:ro, D_REG:ro kills :cc cost(2,3). +cmp_b "cmp.b" post_inc1:ro, post_inc1:ro kills :cc cost(2,2). +cmp_b "cmp.b" const:ro, imm_cmp1:ro kills :cc cost(2,2). +dbf D_REG:rw, label cost(2,5). +eor_l "eor.l" conreg4:ro, datalt4:rw:cc cost(2,6). +ext_l "ext.l" D_REG:rw:cc cost(2,2). +ext_w "ext.w" D_REG:rw:cc cost(2,2). +jmp address+control4 cost(2,0). +jsr address+control4 kills :cc cost(2,3). +lea address+control4:ro, A_REG:wo cost(2,0). +lsl_l "lsl.l" shconreg:ro, D_REG:rw:cc cost(2,4). +lsl "lsl #1," memalt2:rw:cc cost(2,4). +lsr_l "lsr.l" shconreg:ro, D_REG:rw:cc cost(2,4). +lsr "lsr #1," memalt2:rw:cc cost(2,4). +move_l "move.l" any4:ro, alterable4:wo:cc cost(2,2). +move_w "move.w" any2:ro, alterable2:wo:cc cost(2,2). +move_b "move.b" data1:ro, alterable1:wo:cc cost(2,2). +neg_l "neg.l" D_REG:rw:cc cost(2,3). +neg_l "neg.l" memory4:rw:cc cost(2,6). +not_l "not.l" D_REG:rw:cc cost(2,3). +not_l "not.l" memory4:rw:cc cost(2,6). +or_l "or.l" data4:ro, D_REG:rw:cc cost(2,3). +or_l "or.l" D_REG:ro, memalt4:rw:cc cost(2,6). +or_l "or.l" const:ro, datalt4:rw:cc cost(2,6). +rol_l "rol.l" shconreg:ro, D_REG:rw:cc cost(2,4). +rol "rol #1," memalt2:rw:cc cost(2,4). +ror_l "ror.l" shconreg:ro, D_REG:rw:cc cost(2,4). +ror "ror #1," memalt2:rw:cc cost(2,4). +roxl "roxl #1," memalt2:rw:cc cost(2,4). +roxr "roxr #1," memalt2:rw:cc cost(2,4). +sne datalt1:rw cost(2,3). +sub_l "sub.l" any4:ro, D_REG:rw:cc cost(2,3). +sub_l "sub.l" any4:ro, A_REG:rw cost(2,3). +sub_l "sub.l" conreg4:ro, alterable4:rw:cc cost(2,6). +tst_l "tst.l" test_set4:ro:cc cost(2,3). +tst_w "tst.w" test_set2:ro:cc cost(2,3). +tst_b "tst.b" test_set1:ro:cc cost(2,3). +unlk A_REG cost(2,6). + +bxx "illegal" label cost(2,5). +xxx "illegal" data4:ro, D_REG:rw:cc cost(2,3). +xxx "illegal" conreg4:ro, memalt4:rw:cc cost(2,6). +bit "illegal" control4:rw:cc cost(2,6). +sh "illegal" shconreg:ro, D_REG:rw:cc cost(2,4). +shw "illegal" control2:rw:cc cost(2,4). + +#ifdef m68020 +cmp2_l "cmp2.l" address+control4:ro, genreg:ro kills :cc cost(2,18). +divs_l "divs.l" data4:ro, D_REG:rw:cc cost(2,90). +divsl_l "divsl.l" data4:ro, DREG_pair:rw kills :cc cost(2,90). +divu_l "divu.l" data4:ro, D_REG:rw:cc cost(2,78). +divul_l "divul.l" data4:ro, DREG_pair:rw kills :cc cost(2,78). +extb_l "extb.l" D_REG:rw:cc cost(2,4). +muls_l "muls.l" data4:ro, D_REG:rw:cc cost(2,44). +mulu_l "mulu.l" data4:ro, D_REG:rw:cc cost(2,44). +pea address+control4+regX cost(2,4). +#else m68020 +pea address+control4 cost(2,4). +#endif m68020 + + /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * Extra pseudo instruction; it just kills a D_REG; + * it is necessary with long divides where remainders are important; + * see also: 'pat rmi' and 'pat rmu' + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ +killreg "! kill" D_REG:wo cost(0,0). + + +MOVES + +from const %num==0 to D_REG + gen clr_l %2 + +from const %num==0 to memalt4 + gen clr_l %2 + +from const %num==0 to memalt2 + gen clr_w %2 + +from const %num==0 to memalt1 + gen clr_b %2 + +from const to memalt1 + gen move_b {const, lowb(%1.num)}, %2 + +from const to memalt2 + gen move_w {const, loww(%1.num)}, %2 + +from regAcon %bd==0 to A_REG + gen move_l %1.reg, %2 + +#ifndef m68020 +from t_regAregXcon sfit(%bd, 8) to A_REG + gen lea {regAregXcon, %1.reg, %1.xreg, 1, %1.bd}, %2 + +from t_regAregXcon to A_REG + gen lea {regAregXcon, %1.reg, %1.xreg, 1, 0}, %2 + add_l {const, %1.bd}, %2 + +from t_regAcon sfit(%bd, 16) to A_REG + gen lea {regAcon, %1.reg, %1.bd}, %2 + +from t_regAcon to A_REG + gen move_l %1.reg, %2 + add_l {const, %1.bd}, %2 +#endif m68020 + +from address - ext_addr to A_REG + gen lea %1, %2 + +from any4 to alterable4 + gen move_l %1, %2 + +from any2 to datalt2 + gen move_w %1, %2 + +from data1 to datalt1 + gen move_b %1, %2 + + + + +TESTS + + +to test test_set4 + gen tst_l %1 + +to test test_set2 + gen tst_w %1 + +to test test_set1 + gen tst_b %1 + + +STACKINGRULES + + +from const %num==0 to STACK + gen clr_l {pre_dec4, sp} + +#ifndef m68020 +from t_regAregXcon sfit(%bd, 8) to STACK + gen pea {regAregXcon, %1.reg, %1.xreg, 1, %1.bd} + +from t_regAregXcon to STACK + gen pea {regAregXcon, %1.reg, %1.xreg, 1, 0} + add_l {const, %1.bd}, {indirect4, sp} + +from t_regAcon sfit(%bd, 16) to STACK + gen pea {regAcon, %1.reg, %1.bd} + +from t_regAcon to STACK + gen move_l %1.reg, {pre_dec4, sp} + add_l {const, %1.bd}, {indirect4, sp} +#endif m68020 + +from address - ext_addr to STACK + gen pea %1 + +from ext_addr to STACK + gen pea {absolute4, %1.bd} + +from const to STACK + gen pea {absolute4, %1.num} + +from any4 to STACK + gen move_l %1, {pre_dec4, sp} + +from any2 to STACK + gen clr_l {pre_dec4, sp} + move_w %1, {offsetted2, sp, 2} + +from data1 to STACK + gen clr_l {pre_dec4, sp} + move_b %1, {offsetted1, sp, 3} + +#ifdef m68020 +from regX to STACK + gen pea %1 +#endif m68020 + /* This last stackingrule is never used: whenever regX is put on + * the fakestack, some em-instuctions are left that remove it + * immediately. However cgg complained about not having a + * stackingrule for regX, so here it is + */ + + +COERCIONS + + +from STACK + uses DD_REG + gen move_l {post_inc4, sp}, %a + yields %a + +from STACK + uses AA_REG + gen move_l {post_inc4, sp}, %a + yields %a + +#ifndef m68020 +from t_regAregXcon sfit(%bd, 8) + yields {regAregXcon, %1.reg, %1.xreg, 1, %1.bd} + +from t_regAregXcon + uses AA_REG=%1.reg + gen add_l {const, %1.bd}, %a + yields {regAregXcon, %a, %1.xreg, 1, 0} + +from t_regAcon sfit(%bd, 16) + yields {regAcon, %1.reg, %1.bd} + +from t_regAcon + uses reusing %1, AA_REG=%1.reg + gen add_l {const, %1.bd}, %a + yields %a +#endif m68020 + +from t_address + uses reusing %1, AA_REG = %1 + yields %a + +from any4 + uses reusing %1, DD_REG = %1 + yields %a + +from any4 + uses reusing %1, AA_REG = %1 + yields %a + +from memory2 + uses DD_REG = {const, 0} + gen move_w %1, %a yields %a + +from memory1 + uses DD_REG = {const, 0} + gen move_b %1, %a yields %a + + + + +PATTERNS + +/************************************************ + * Group 0: rules for register variables * + * LOCALs mentioned here refer to registers * + ************************************************/ + +pat lol inreg($1)==reg_pointer + kills pre_post %reg==regvar($1, reg_pointer) + yields {LOCAL, $1} + +pat lil inreg($1)==reg_pointer + kills pre_post %reg==regvar($1, reg_pointer) + yields {indirect4, regvar($1, reg_pointer)} + +pat stl inreg($1)==reg_any +with any4 + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen move %1, {LOCAL, $1} + +pat stl inreg($1)==reg_pointer +with any4 + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + gen move %1, {LOCAL, $1} +with exact ext_addr + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + gen move %1, {LOCAL, $1} +with exact address-ext_addr + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + gen lea %1, {LOCAL, $1} + +pat sil inreg($1)==reg_pointer +with any4 + kills allexceptcon + gen move %1, {indirect4, regvar($1, reg_pointer)} + + +pat lol sbi stl $1==$3 && $2==4 && inreg($1)==reg_any +with any4 + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen sub_l %1, {LOCAL, $1} + neg_l {LOCAL, $1} + +pat lol sbu stl $1==$3 && $2==4 && inreg($1)==reg_any +with any4 + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen sub_l %1, {LOCAL, $1} + neg_l {LOCAL, $1} + +pat lil sbi sil $1==$3 && $2==4 && inreg($1)==reg_pointer +with conreg4 + kills allexceptcon + gen sub_l %1, {indirect4, regvar($1, reg_pointer)} + neg_l {indirect4, regvar($1, reg_pointer)} + +pat lil sbu sil $1==$3 && $2==4 && inreg($1)==reg_pointer +with conreg4 + kills allexceptcon + gen sub_l %1, {indirect4, regvar($1, reg_pointer)} + neg_l {indirect4, regvar($1, reg_pointer)} + + +pat lil ngi sil $1==$3 && $2==4 && inreg($1)==reg_pointer + kills allexceptcon + gen neg_l {indirect4, regvar($1, reg_pointer)} + +pat lil com sil $1==$3 && $2==4 && inreg($1)==reg_pointer + kills allexceptcon + gen not_l {indirect4, regvar($1, reg_pointer)} + + +proc lolcshstl example lol loc sli stl + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen sh* {shconst, $2}, {LOCAL, $1} + +proc lolrshstl example lol lol sli stl + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen sh* {LOCAL, $2}, {LOCAL, $1} + +proc lil1shlsil example lil loc sli sil /* only left */ + kills allexceptcon + gen shw* {offsetted2, regvar($1, reg_pointer), 2} + roxl {indirect2, regvar($1, reg_pointer)} + +proc lil1shrsil example lil loc sli sil /* only right */ + kills allexceptcon + gen shw* {indirect2, regvar($1, reg_pointer)} + roxr {offsetted2, regvar($1, reg_pointer), 2} + +pat lol loc sli stl $1==$4 && small($2) && $3==4 && inreg($1)==reg_any + call lolcshstl("asl.l") +pat lol loc slu stl $1==$4 && small($2) && $3==4 && inreg($1)==reg_any + call lolcshstl("asl.l") +pat lol lol sli stl $1==$4 && inreg($1)==reg_any && $3==4 && inreg($2)==reg_any + call lolrshstl("asl.l") +pat lol lol slu stl $1==$4 && inreg($1)==reg_any && $3==4 && inreg($2)==reg_any + call lolrshstl("asl.l") +pat lil loc sli sil $1==$4 && $2==1 && $3==4 && inreg($1)==reg_pointer + call lil1shlsil("asl #1,") +pat lil loc slu sil $1==$4 && $2==1 && $3==4 && inreg($1)==reg_pointer + call lil1shlsil("asl #1,") +pat lol loc sri stl $1==$4 && small($2) && $3==4 && inreg($1)==reg_any + call lolcshstl("asr.l") +pat lol loc sru stl $1==$4 && small($2) && $3==4 && inreg($1)==reg_any + call lolcshstl("lsr.l") +pat lol lol sri stl $1==$4 && inreg($1)==reg_any && $3==4 && inreg($2)==reg_any + call lolrshstl("asr.l") +pat lol lol sru stl $1==$4 && inreg($1)==reg_any && $3==4 && inreg($2)==reg_any + call lolrshstl("lsr.l") +pat lil loc sri sil $1==$4 && $2==1 && $3==4 && inreg($1)==reg_pointer + call lil1shrsil("asr #1,") +pat lil loc sru sil $1==$4 && $2==1 && $3==4 && inreg($1)==reg_pointer + call lil1shrsil("lsr #1,") +pat lol loc rol stl $1==$4 && small($2) && $3==4 && inreg($1)==reg_any + call lolcshstl("rol.l") +pat lol lol rol stl $1==$4 && inreg($2)==reg_any && $3==4 && inreg($1)==reg_any + call lolrshstl("rol.l") +pat lol loc ror stl $1==$4 && small($2) && $3==4 && inreg($1)==reg_any + call lolcshstl("ror.l") +pat lol lol ror stl $1==$4 && inreg($2)==reg_any && $3==4 && inreg($1)==reg_any + call lolrshstl("ror.l") + +#ifdef m68020 +pat lol loc dvi stl $1==$4 && $3==4 && inreg($1)==reg_any + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen divs_l {const, $2}, {LOCAL, $1} + +pat lol loc dvu stl $1==$4 && $3==4 && inreg($1)==reg_any + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen divu_l {const, $2}, {LOCAL, $1} + +pat lol loc mli stl $1==$4 && $3==4 && inreg($1)==reg_any + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen muls_l {const, $2}, {LOCAL, $1} + +pat lol loc mlu stl $1==$4 && $3==4 && inreg($1)==reg_any + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen mulu_l {const, $2}, {LOCAL, $1} + +pat lol mli stl $1==$3 && $2==4 && inreg($1)==reg_any + with data4 + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen muls_l %1, {LOCAL, $1} + +pat lol mlu stl $1==$3 && $2==4 && inreg($1)==reg_any + with data4 + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen mulu_l %1, {LOCAL, $1} +#endif m68020 + + +pat lil inc sil $1==$3 && inreg($1)==reg_pointer + kills allexceptcon + gen add_l {const, 1}, {indirect4, regvar($1, reg_pointer)} + +pat lil dec sil $1==$3 && inreg($1)==reg_pointer + kills allexceptcon + gen sub_l {const, 1}, {indirect4, regvar($1, reg_pointer)} + +pat inl inreg($1)==reg_any + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen add_l {const, 1}, {LOCAL, $1} + +pat del inreg($1)==reg_any + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen sub_l {const, 1}, {LOCAL, $1} + +pat zrl inreg($1)==reg_any + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen clr_l {LOCAL, $1} + +pat zrl inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + gen move_l {const, 0}, {LOCAL, $1} + + +proc lolxxstl example lol and stl +with data4 + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen xxx* %1, {LOCAL, $1} + +proc lilxxsil example lil and sil +with conreg4 + kills allexceptcon + gen xxx* %1, {indirect4, regvar($1, reg_pointer)} + +proc lolcxxstl example lol loc and stl + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen xxx* {const, $2}, {LOCAL, $1} + +proc lilcxxsil example lil loc and sil + kills allexceptcon + gen xxx* {const, $2}, {indirect4, regvar($1, reg_pointer)} + +proc lolrxxstl example lol lol and stl + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen xxx* {LOCAL, $2}, {LOCAL, $1} + +proc lilrxxsil example lil lol and sil + kills allexceptcon + gen xxx* {LOCAL, $2}, {indirect4, regvar($1, reg_pointer)} + +pat lol adi stl $1==$3 && $2==4 && inreg($1)==reg_any + call lolxxstl("add.l") +pat lol loc adi stl $1==$4 && $3==4 && inreg($1)==reg_any + call lolcxxstl("add.l") +pat lil adi sil $1==$3 && $2==4 &&inreg($1)==reg_pointer + call lilxxsil("add.l") +pat lil loc adi sil $1==$4 && $3==4 && inreg($1)==reg_pointer + call lilcxxsil("add.l") +pat lol lol adi stl $1==$4 && $3==4 && inreg($1)==reg_any && inreg($2)==reg_any + call lolrxxstl("add.l") +pat lil lol adi sil $1==$4 && $3==4 && inreg($1)==reg_pointer && + inreg($2)==reg_any + call lilrxxsil("add.l") +pat lol adu stl $1==$3 && $2==4 && inreg($1)==reg_any + call lolxxstl("add.l") +pat lol loc adu stl $1==$4 && $3==4 && inreg($1)==reg_any + call lolcxxstl("add.l") +pat lil adu sil $1==$3 && $2==4 &&inreg($1)==reg_pointer + call lilxxsil("add.l") +pat lil loc adu sil $1==$4 && $3==4 && inreg($1)==reg_pointer + call lilcxxsil("add.l") +pat lol lol adu stl $1==$4 && $3==4 && inreg($1)==reg_any && inreg($2)==reg_any + call lolrxxstl("add.l") +pat lil lol adu sil $1==$4 && $3==4 && inreg($1)==reg_pointer && + inreg($2)==reg_any + call lilrxxsil("add.l") +pat lol loc sbi stl $1==$4 && $3==4 && inreg($1)==reg_any + call lolcxxstl("sub.l") +pat lil loc sbi sil $1==$4 && $3==4 && inreg($1)==reg_pointer + call lilcxxsil("sub.l") +pat lol lol sbi stl $1==$4 && $3==4 && inreg($1)==reg_any && inreg($2)==reg_any + call lolrxxstl("sub.l") +pat lil lol sbi sil $1==$4 && $3==4 && inreg($1)==reg_pointer && + inreg($2)==reg_any + call lilrxxsil("sub.l") +pat lol loc sbu stl $1==$4 && $3==4 && inreg($1)==reg_any + call lolcxxstl("sub.l") +pat lil loc sbu sil $1==$4 && $3==4 && inreg($1)==reg_pointer + call lilcxxsil("sub.l") +pat lol lol sbu stl $1==$4 && $3==4 && inreg($1)==reg_any && inreg($2)==reg_any + call lolrxxstl("sub.l") +pat lil lol sbu sil $1==$4 && $3==4 && inreg($1)==reg_pointer && + inreg($2)==reg_any + call lilrxxsil("sub.l") +pat lol and stl $1==$3 && $2==4 && inreg($1)==reg_any + call lolxxstl("and.l") +pat lol loc and stl $1==$4 && $3==4 && inreg($1)==reg_any + call lolcxxstl("and.l") +pat lil and sil $1==$3 && $2==4 &&inreg($1)==reg_pointer + call lilxxsil("and.l") +pat lil loc and sil $1==$4 && $3==4 && inreg($1)==reg_pointer + call lilcxxsil("and.l") +pat lol lol and stl $1==$4 && $3==4 && inreg($1)==reg_any && inreg($2)==reg_any + call lolrxxstl("and.l") +pat lil lol and sil $1==$4 && $3==4 && inreg($1)==reg_pointer && + inreg($2)==reg_any + call lilrxxsil("and.l") +pat lol ior stl $1==$3 && $2==4 && inreg($1)==reg_any + call lolxxstl("or.l") +pat lol loc ior stl $1==$4 && $3==4 && inreg($1)==reg_any + call lolcxxstl("or.l") +pat lil ior sil $1==$3 && $2==4 && inreg($1)==reg_pointer + call lilxxsil("or.l") +pat lil loc ior sil $1==$4 && $3==4 && inreg($1)==reg_pointer + call lilcxxsil("or.l") +pat lol lol ior stl $1==$4 && $3==4 && inreg($1)==reg_any && + inreg($2)==reg_any + call lolrxxstl("or.l") +pat lil lol ior sil $1==$4 && $3==4 && inreg($1)==reg_pointer && + inreg($2)==reg_any + call lilrxxsil("or.l") +pat lol xor stl $1==$3 && $2==4 && inreg($1)==reg_any + call lolxxstl("eor.l") +pat lol loc xor stl $1==$4 && $3==4 && inreg($1)==reg_any + call lolcxxstl("eor.l") +pat lil xor sil $1==$3 && $2==4 &&inreg($1)==reg_pointer + call lilxxsil("eor.l") +pat lil loc xor sil $1==$4 && $3==4 && inreg($1)==reg_pointer + call lilcxxsil("eor.l") +pat lol lol xor stl $1==$4 && $3==4 && inreg($1)==reg_any && + inreg($2)==reg_any + call lolrxxstl("eor.l") +pat lil lol xor sil $1==$4 && $3==4 && inreg($1)==reg_pointer && + inreg($2)==reg_any + call lilrxxsil("eor.l") + +pat lil adp sil $1==$3 && inreg($1)==reg_pointer + kills allexceptcon + gen add_l {const, $2}, {indirect4, regvar($1, reg_pointer)} + +pat lil lil adp sil $1==$2 && $1==$4 && inreg($1)==reg_pointer + kills allexceptcon + uses AA_REG = {indirect4, regvar($1, reg_pointer)} + gen add_l {const, $3}, {indirect4, regvar($1, reg_pointer)} + yields %a + +pat lol lol adp stl loi $1==$2 && $1==$4 && $3==1 && $5==1 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {post_inc1, regvar($1, reg_pointer)} + +pat lol loi lol adp stl $1==$3 && $1==$5 && $2==1 && $4==1 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {post_inc1, regvar($1, reg_pointer)} + +pat lol lol adp stl loi $1==$2 && $1==$4 && $3==2 && $5==2 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {post_inc2, regvar($1, reg_pointer)} + +pat lol loi lol adp stl $1==$3 && $1==$5 && $2==2 && $4==2 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {post_inc2, regvar($1, reg_pointer)} + +pat lol lol adp stl loi $1==$2 && $1==$4 && $3==4 && $5==4 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {post_inc4, regvar($1, reg_pointer)} + +pat lil lol adp stl $1==$2 && $1==$4 && $3==4 && inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {post_inc4, regvar($1, reg_pointer)} + +pat lol lol adp stl sti $1==$2 && $1==$4 && $3==1 && $5==1 && + inreg($1)==reg_pointer +with data1 + kills allexceptcon + gen move %1, {post_inc1, regvar($1, reg_pointer)} + +pat lol sti lol adp stl $1==$3 && $1==$5 && $2==1 && $4==1 && + inreg($1)==reg_pointer +with data1 + kills allexceptcon + gen move %1, {post_inc1, regvar($1, reg_pointer)} + +pat lol lol adp stl sti $1==$2 && $1==$4 && $3==2 && $5==2 && + inreg($1)==reg_pointer +with any2 + kills allexceptcon + gen move %1, {post_inc2, regvar($1, reg_pointer)} + +pat lol sti lol adp stl $1==$3 && $1==$5 && $2==2 && $4==2 && + inreg($1)==reg_pointer +with any2 + kills allexceptcon + gen move %1, {post_inc2, regvar($1, reg_pointer)} + +pat lol lol adp stl sti $1==$2 && $1==$4 && $3==4 && $5==4 && + inreg($1)==reg_pointer +with any4 + kills allexceptcon + gen move_l %1, {post_inc4, regvar($1, reg_pointer)} + +pat sil lol adp stl $1==$2 && $1==$4 && $3==4 && inreg($1)==reg_pointer +with any4 + kills allexceptcon + gen move_l %1, {post_inc4, regvar($1, reg_pointer)} + +pat lol adp stl lol loi $1==$3 && $1==$4 && $2==0-1 && $5==1 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {pre_dec1, regvar($1, reg_pointer)} + +pat lol adp stl lol loi $1==$3 && $1==$4 && $2==0-2 && $5==2 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {pre_dec2, regvar($1, reg_pointer)} + +pat lol adp stl lil $1==$3 && $1==$4 && $2==0-4 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {pre_dec4, regvar($1, reg_pointer)} + +pat lol adp stl lol sti $1==$3 && $1==$4 && $2==0-1 && $5==1 && + inreg($1)==reg_pointer +with data1 + kills allexceptcon + gen move %1, {pre_dec1, regvar($1, reg_pointer)} + +pat lol adp stl lol sti $1==$3 && $1==$4 && $2==0-2 && $5==2 && + inreg($1)==reg_pointer +with any2 + kills allexceptcon + gen move %1, {pre_dec2, regvar($1, reg_pointer)} + +pat lol adp stl sil $1==$3 && $1==$4 && $2==0-4 && + inreg($1)==reg_pointer +with any4 + kills allexceptcon + gen move_l %1, {pre_dec4, regvar($1, reg_pointer)} + + + + +/************************************************ + * Group 1: load instructions * + ************************************************/ + +pat loc yields {const, $1} + +pat ldc leaving loc 18 trp + +pat lol yields {LOCAL, $1} + +pat ldl leaving lol $1+4 lol $1 + +pat loe yields {absolute4, $1} + +pat lil +#ifdef m68020 + yields {ILOCAL, $1} +#else m68020 + uses AA_REG = {LOCAL, $1} + yields {indirect4, %a} +#endif m68020 + + /* When using the 'offsetted' intructions regAregXcon cannot be used + * for the m68k4; there is no way of knowing about the size of + * %1.bd+$1, because expressions are not allowed in stack patterns, and + * this may lead to outputting too large displacements. With regAcon + * the chance that this will happen is very slim, because it can + * have displacements of 16 bits. Besides, leaving out regAcon here + * would make it very hard to handle this instruction efficiently. + */ +pat lof +with A_REG yields {offsetted4, %1, $1} +with exact local_addr yields {LOCAL, %1.bd+$1} +with exact ext_addr yields {absolute4, %1.bd+$1} +#ifndef m68020 +with regAcon yields {offsetted4, %1.reg, %1.bd+$1} +#else m68020 +with exact regAcon yields {offsetted4, %1.reg, %1.bd+$1} +with exact regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1} +with exact offsetted4 yields {OFF_off4, %1.reg, %1.bd, $1} +with exact indirect yields {OFF_off4, %1.reg, 0, $1} +with exact LOCAL yields {OFF_off4, lb, %1.bd, $1} +with exact off_con yields {OFF_off4, %1.reg, %1.bd, %1.od+$1} +with exact off_regXcon yields {OFF_indoff4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact index_off4 yields {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, $1} +with exact indoff_con yields {INDOFF_off4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact absolute4 yields {ABS_off4, %1.bd, $1} +with exact abs_con yields {ABS_off4, %1.bd, %1.od+$1} +with exact abs_regXcon yields {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact abs_index4 yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, $1} +with exact absind_con yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact ext_regX yields {abs_index4, %1.sc, %1.xreg, %1.bd+$1} +#endif m68020 + +pat lal yields {local_addr, $1} + +pat lae yields {ext_addr, $1} + +pat lxl $1==0 yields lb + +pat lxl $1==1 yields {LOCAL, SL} + +pat lxl $1==2 +#ifdef m68020 + yields {OFF_off4, lb, SL, SL} +#else m68020 + uses AA_REG = {LOCAL, SL} + yields {offsetted4, %a, SL} +#endif m68020 + +pat lxl $1==3 +#ifdef m68020 + uses AA_REG = {OFF_off4, lb, SL, SL} +#else m68020 + uses AA_REG = {LOCAL, SL} + gen move {offsetted4, %a, SL}, %a +#endif m68020 + yields {offsetted4, %a, SL} + +pat lxl $1>3 + uses AA_REG = {LOCAL, SL}, + DD_REG = {const, $1-2} + gen 1: + move_l {offsetted4, %a, SL} ,%a + dbf %b, {slabel, 1b} + yields %a + +pat lxa $1==0 yields {local_addr, SL} + +pat lxa $1==1 +#ifdef m68020 + yields {off_con, lb, SL, SL} +#else m68020 + uses AA_REG = {LOCAL, SL} + yields {regAcon, %a, SL} +#endif m68020 + +pat lxa $1==2 +#ifdef m68020 + uses AA_REG = {OFF_off4, lb, SL, SL} +#else m68020 + uses AA_REG = {LOCAL, SL} + gen move {offsetted4, %a, SL}, %a +#endif m68020 + yields {regAcon, %a, SL} + +pat lxa $1>2 + uses AA_REG = {LOCAL, SL}, + DD_REG = {const, $1-1} + gen 1: + move_l {offsetted4, %a, SL} ,%a + dbf %b, {slabel, 1b} + yields {regAcon, %a, SL} + +pat loi $1==1 +with A_REG yields {indirect1, %1} +with exact local_addr yields {offsetted1, lb, %1.bd} +with exact ext_addr yields {absolute1, %1.bd} +#ifndef m68020 +with regAcon yields {offsetted1, %1.reg, %1.bd} +with regAregXcon yields {index_off1, %1.reg, %1.xreg, %1.sc, %1.bd} +#else m68020 +with exact regAcon yields {offsetted1, %1.reg, %1.bd} +with exact regAregXcon yields {index_off1, %1.reg, %1.xreg, %1.sc, %1.bd} +with exact indirect4 yields {OFF_off1, %1.reg, 0, 0} +with exact offsetted4 yields {OFF_off1, %1.reg, %1.bd, 0} +with exact LOCAL yields {OFF_off1, lb, %1.bd, 0} +with exact off_con yields {OFF_off1, %1.reg, %1.bd, %1.od} +with exact off_regXcon yields {OFF_indoff1, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact index_off4 yields {INDOFF_off1, %1.reg, %1.xreg, %1.sc, %1.bd, 0} +with exact indoff_con yields {INDOFF_off1, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact absolute4 yields {ABS_off1, %1.bd, 0} +with exact abs_con yields {ABS_off1, %1.bd, %1.od} +with exact abs_regXcon yields {ABS_indoff1, %1.sc, %1.xreg, %1.bd, %1.od} +with exact abs_index4 yields {ABSIND_off1, %1.sc, %1.xreg, %1.bd, 0} +with exact absind_con yields {ABSIND_off1, %1.sc, %1.xreg, %1.bd, %1.od} +with exact ext_regX yields {abs_index1, %1.sc, %1.xreg, %1.bd} +#endif m68020 + +pat loi $1==2 +with A_REG yields {indirect2, %1} +with exact local_addr yields {offsetted2, lb, %1.bd} +with exact ext_addr yields {absolute2, %1.bd} +#ifndef m68020 +with regAcon yields {offsetted2, %1.reg, %1.bd} +with regAregXcon yields {index_off2, %1.reg, %1.xreg, %1.sc, %1.bd} +#else m68020 +with exact regAcon yields {offsetted2, %1.reg, %1.bd} +with exact regAregXcon yields {index_off2, %1.reg, %1.xreg, %1.sc, %1.bd} +with exact indirect4 yields {OFF_off2, %1.reg, 0, 0} +with exact offsetted4 yields {OFF_off2, %1.reg, %1.bd, 0} +with exact LOCAL yields {OFF_off2, lb, %1.bd, 0} +with exact off_con yields {OFF_off2, %1.reg, %1.bd, %1.od} +with exact off_regXcon yields {OFF_indoff2, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact index_off4 yields {INDOFF_off2, %1.reg, %1.xreg, %1.sc, %1.bd, 0} +with exact indoff_con yields {INDOFF_off2, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact absolute4 yields {ABS_off2, %1.bd, 0} +with exact abs_con yields {ABS_off2, %1.bd, %1.od} +with exact abs_regXcon yields {ABS_indoff2, %1.sc, %1.xreg, %1.bd, %1.od} +with exact abs_index4 yields {ABSIND_off2, %1.sc, %1.xreg, %1.bd, 0} +with exact absind_con yields {ABSIND_off2, %1.sc, %1.xreg, %1.bd, %1.od} +with exact ext_regX yields {abs_index2, %1.sc, %1.xreg, %1.bd} +#endif m68020 + +pat loi $1==4 +with A_REG yields {indirect4, %1} +with exact local_addr yields {LOCAL, %1.bd} +with exact ext_addr yields {absolute4, %1.bd} +#ifndef m68020 +with regAcon yields {offsetted4, %1.reg, %1.bd} +with regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd} +#else m68020 +with exact regAcon yields {offsetted4, %1.reg, %1.bd} +with exact regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd} +with exact LOCAL yields {ILOCAL, %1.bd} +with exact indirect4 yields {OFF_off4, %1.reg, 0, 0} +with exact offsetted4 yields {OFF_off4, %1.reg, %1.bd, 0} +with exact off_con yields {OFF_off4, %1.reg, %1.bd, %1.od} +with exact off_regXcon yields {OFF_indoff4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact index_off4 yields {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, 0} +with exact indoff_con yields {INDOFF_off4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact absolute4 yields {ABS_off4, %1.bd, 0} +with exact abs_con yields {ABS_off4, %1.bd, %1.od} +with exact abs_regXcon yields {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od} +with exact abs_index4 yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, 0} +with exact absind_con yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od} +with exact ext_regX yields {abs_index4, %1.sc, %1.xreg, %1.bd} +#endif m68020 + +pat loi $1==8 +with A_REG yields {offsetted4, %1, 4} + {indirect4, %1} +pat loi $1>8 +with AA_REG STACK + uses DD_REG = {const, $1/4 -1} + gen add_l {const, $1}, %1 + 1: + move_l {pre_dec4, %1}, {pre_dec4, sp} + dbf %a, {slabel, 1b} + +pat los $1==4 +with STACK + gen jsr {absolute4, ".los"} + +pat lde yields {absolute4, $1+4} + {absolute4, $1} + +pat ldf +with A_REG yields {offsetted4, %1, $1+4} + {offsetted4, %1, $1} +with exact local_addr yields {LOCAL, %1.bd+$1+4} + {LOCAL, %1.bd+$1} +with exact ext_addr yields {absolute4, %1.bd+$1+4} + {absolute4, %1.bd+$1} +#ifndef m68020 +with regAcon yields {offsetted4, %1.reg, %1.bd+$1+4} + {offsetted4, %1.reg, %1.bd+$1} +#else m68020 +with exact regAcon yields {offsetted4, %1.reg, %1.bd+$1+4} + {offsetted4, %1.reg, %1.bd+$1} +with exact regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1+4} + {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1} +with exact indirect4 yields {OFF_off4, %1.reg, 0, $1+4} + {OFF_off4, %1.reg, 0, $1} +with exact offsetted4 yields {OFF_off4, %1.reg, %1.bd, $1+4} + {OFF_off4, %1.reg, %1.bd, $1} +with exact LOCAL yields {OFF_off4, lb, %1.bd, $1+4} + {OFF_off4, lb, %1.bd, $1} +with exact off_con yields {OFF_off4, %1.reg, %1.bd, %1.od+$1+4} + {OFF_off4, %1.reg, %1.bd, %1.od+$1} +with exact off_regXcon yields {OFF_indoff4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1+4} + {OFF_indoff4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact index_off4 yields {INDOFF_off4, %1.reg, %1.xreg, %1.sc,%1.bd,$1+4} + {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, $1} +with exact indoff_con yields {INDOFF_off4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1+4} + {INDOFF_off4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact absolute4 yields {ABS_off4, %1.bd, $1+4} + {ABS_off4, %1.bd, $1} +with exact abs_con yields {ABS_off4, %1.bd, %1.od+$1+4} + {ABS_off4, %1.bd, %1.od+$1} +with exact abs_regXcon yields {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od+$1+4} + {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact abs_index4 yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, $1+4} + {ABSIND_off4, %1.sc, %1.xreg, %1.bd, $1} +with exact absind_con yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1+4} + {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact ext_regX yields {abs_index4, %1.sc, %1.xreg, %1.bd+$1+4} + {abs_index4, %1.sc, %1.xreg, %1.bd+$1} +#endif m68020 + +pat lpi yields {ext_addr, $1} + + + +/************************************************ + * Group 2: store instructions * + ************************************************/ + +pat stl +with any4 + kills all_indir, LOCAL %bd==$1 + gen move %1, {LOCAL, $1} +with exact STACK + gen move {post_inc4,sp}, {LOCAL, $1} + +pat ste +with any4 + kills posextern + gen move %1, {absolute4, $1} +with exact STACK + gen move {post_inc4, sp}, {absolute4, $1} + +pat sil +#ifdef m68020 +with any4 + kills allexceptcon + gen move %1, {ILOCAL, $1} +with exact STACK + gen move {post_inc4, sp}, {ILOCAL, $1} +#else m68020 +with any4 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen move %1, {indirect4, %a} +with exact STACK + uses AA_REG = {LOCAL, $1} + gen move {post_inc4, sp}, {indirect4, %a} +#endif m68020 + +pat stf +with A_REG any4 + kills allexceptcon + gen move %2, {offsetted4, %1, $1} +with A_REG STACK + gen move {post_inc4, sp}, {offsetted4, %1, $1} +with exact local_addr any4 + kills allexceptcon + gen move %2, {LOCAL, %1.bd+$1} +with exact ext_addr any4 + kills allexceptcon + gen move %2, {absolute4, %1.bd+$1} +#ifndef m68020 +with regAcon any4 + kills allexceptcon + gen move %2, {offsetted4, %1.reg, %1.bd+$1} +#else m68020 +with exact regAcon any4 + kills allexceptcon + gen move %2, {offsetted4, %1.reg, %1.bd+$1} +with exact regAregXcon any4 + kills allexceptcon + gen move %2, {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1} +with exact indirect4 any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, 0, $1} +with exact offsetted4 any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, %1.bd, $1} +with exact LOCAL any4 + kills allexceptcon + gen move %2, {OFF_off4, lb, %1.bd, $1} +with exact off_con any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, %1.bd, %1.od+$1} +with exact off_regXcon any4 + kills allexceptcon + gen move %2, {OFF_indoff4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact index_off4 any4 + kills allexceptcon + gen move %2, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, $1} +with exact indoff_con any4 + kills allexceptcon + gen move %2, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact absolute4 any4 + kills allexceptcon + gen move %2, {ABS_off4, %1.bd, $1} +with exact abs_con any4 + kills allexceptcon + gen move %2, {ABS_off4, %1.bd, %1.od+$1} +with exact abs_regXcon any4 + kills allexceptcon + gen move %2, {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact abs_index4 any4 + kills allexceptcon + gen move %2, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, $1} +with exact absind_con any4 + kills allexceptcon + gen move %2, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact ext_regX any4 + kills allexceptcon + gen move %2, {abs_index4, %1.sc, %1.xreg, %1.bd+$1} +#endif m68020 + +pat sti $1==1 +with A_REG data1 + kills allexceptcon + gen move %2, {indirect1, %1} +with exact local_addr data1 + kills allexceptcon + gen move %2, {offsetted1, lb, %1.bd} +with exact ext_addr data1 + kills allexceptcon + gen move %2, {absolute1, %1.bd} +#ifndef m68020 +with regAcon data1 + kills allexceptcon + gen move %2, {offsetted1, %1.reg, %1.bd} +with regAregXcon data1 + kills allexceptcon + gen move %2, {index_off1, %1.reg, %1.xreg, %1.sc, %1.bd} +#else m68020 +with exact regAcon data1 + kills allexceptcon + gen move %2, {offsetted1, %1.reg, %1.bd} +with exact regAregXcon data1 + kills allexceptcon + gen move %2, {index_off1, %1.reg, %1.xreg, %1.sc, %1.bd} +with exact indirect4 data1 + kills allexceptcon + gen move %2, {OFF_off1, %1.reg, 0, 0} +with exact offsetted4 data1 + kills allexceptcon + gen move %2, {OFF_off1, %1.reg, %1.bd, 0} +with exact LOCAL data1 + kills allexceptcon + gen move %2, {OFF_off1, lb, %1.bd, 0} +with exact off_con data1 + kills allexceptcon + gen move %2, {OFF_off1, %1.reg, %1.bd, %1.od} +with exact off_regXcon data1 + kills allexceptcon + gen move %2, {OFF_indoff1, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact index_off4 data1 + kills allexceptcon + gen move %2, {INDOFF_off1, %1.reg, %1.xreg, %1.sc, %1.bd, 0} +with exact indoff_con data1 + kills allexceptcon + gen move %2, {INDOFF_off1, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact absolute4 data1 + kills allexceptcon + gen move %2, {ABS_off1, %1.bd, 0} +with exact abs_con data1 + kills allexceptcon + gen move %2, {ABS_off1, %1.bd, %1.od} +with exact abs_regXcon data1 + kills allexceptcon + gen move %2, {ABS_indoff1, %1.sc, %1.xreg, %1.bd, %1.od} +with exact abs_index4 data1 + kills allexceptcon + gen move %2, {ABSIND_off1, %1.sc, %1.xreg, %1.bd, 0} +with exact absind_con data1 + kills allexceptcon + gen move %2, {ABSIND_off1, %1.sc, %1.xreg, %1.bd, %1.od} +with exact ext_regX data1 + kills allexceptcon + gen move %2, {abs_index1, %1.sc, %1.xreg, %1.bd} +#endif m68020 + +pat sti $1==2 +with A_REG any2 + kills allexceptcon + gen move %2, {indirect2, %1} +with exact local_addr any2 + kills allexceptcon + gen move %2, {offsetted2, lb, %1.bd} +with exact ext_addr any2 + kills allexceptcon + gen move %2, {absolute2, %1.bd} +#ifndef m68020 +with regAcon any2 + kills allexceptcon + gen move %2, {offsetted2, %1.reg, %1.bd} +with regAregXcon any2 + kills allexceptcon + gen move %2, {index_off2, %1.reg, %1.xreg, %1.sc, %1.bd} +#else m68020 +with exact regAcon any2 + kills allexceptcon + gen move %2, {offsetted2, %1.reg, %1.bd} +with exact regAregXcon any2 + kills allexceptcon + gen move %2, {index_off2, %1.reg, %1.xreg, %1.sc, %1.bd} +with exact indirect4 any2 + kills allexceptcon + gen move %2, {OFF_off2, %1.reg, 0, 0} +with exact offsetted4 any2 + kills allexceptcon + gen move %2, {OFF_off2, %1.reg, %1.bd, 0} +with exact LOCAL any2 + kills allexceptcon + gen move %2, {OFF_off2, lb, %1.bd, 0} +with exact off_con any2 + kills allexceptcon + gen move %2, {OFF_off2, %1.reg, %1.bd, %1.od} +with exact index_off4 any2 + kills allexceptcon + gen move %2, {INDOFF_off2, %1.reg, %1.xreg, %1.sc, %1.bd, 0} +with exact off_regXcon any2 + kills allexceptcon + gen move %2, {OFF_indoff2, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact indoff_con any2 + kills allexceptcon + gen move %2, {INDOFF_off2, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact absolute4 any2 + kills allexceptcon + gen move %2, {ABS_off2, %1.bd, 0} +with exact abs_con any2 + kills allexceptcon + gen move %2, {ABS_off2, %1.bd, %1.od} +with exact abs_regXcon any2 + kills allexceptcon + gen move %2, {ABS_indoff2, %1.sc, %1.xreg, %1.bd, %1.od} +with exact abs_index4 any2 + kills allexceptcon + gen move %2, {ABSIND_off2, %1.sc, %1.xreg, %1.bd, 0} +with exact absind_con any2 + kills allexceptcon + gen move %2, {ABSIND_off2, %1.sc, %1.xreg, %1.bd, %1.od} +with exact ext_regX any2 + kills allexceptcon + gen move %2, {abs_index2, %1.sc, %1.xreg, %1.bd} +#endif m68020 + +pat sti $1==4 +with A_REG any4 + kills allexceptcon + gen move %2, {indirect4, %1} +with A_REG STACK + gen move {post_inc4, sp}, {indirect4, %1} +with exact local_addr any4 + kills allexceptcon + gen move %2, {LOCAL, %1.bd} +with exact ext_addr any4 + kills allexceptcon + gen move %2, {absolute4, %1.bd} +#ifndef m68020 +with regAcon any4 + kills allexceptcon + gen move %2, {offsetted4, %1.reg, %1.bd} +with regAregXcon any4 + kills allexceptcon + gen move %2, {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd} +#else m68020 +with exact regAcon any4 + kills allexceptcon + gen move %2, {offsetted4, %1.reg, %1.bd} +with exact regAregXcon any4 + kills allexceptcon + gen move %2, {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd} +with exact LOCAL any4 + kills allexceptcon + gen move %2, {ILOCAL, %1.bd} +with exact indirect4 any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, 0, 0} +with exact offsetted4 any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, %1.bd, 0} +with exact off_con any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, %1.bd, %1.od} +with exact off_regXcon any4 + kills allexceptcon + gen move %2, {OFF_indoff4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact index_off4 any4 + kills allexceptcon + gen move %2, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, 0} +with exact indoff_con any4 + kills allexceptcon + gen move %2, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact absolute4 any4 + kills allexceptcon + gen move %2, {ABS_off4, %1.bd, 0} +with exact abs_con any4 + kills allexceptcon + gen move %2, {ABS_off4, %1.bd, %1.od} +with exact abs_regXcon any4 + kills allexceptcon + gen move %2, {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od} +with exact abs_index4 any4 + kills allexceptcon + gen move %2, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, 0} +with exact absind_con any4 + kills allexceptcon + gen move %2, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od} +with exact ext_regX any4 + kills allexceptcon + gen move %2, {abs_index4, %1.sc, %1.xreg, %1.bd} +#endif m68020 + +pat sti $1>4 +with AA_REG STACK + uses DD_REG = {const, $1/4 -1} + gen 1: + move_l {post_inc4, sp}, {post_inc4, %1} + dbf %a, {slabel, 1b} + +pat sts $1==4 +with STACK + gen jsr {absolute4, ".sts"} + +pat sdl +with any4 any4 + kills all_indir, LOCAL %bd==$1 + gen move %1, {LOCAL, $1} + move %2, {LOCAL, $1+4} + +pat sde +with any4 any4 + kills posextern + gen move %1, {absolute4, $1} + move %2, {absolute4, $1+4} + +pat sdf +with A_REG any4 any4 + kills allexceptcon + gen move %2, {offsetted4, %1, $1} + move %3, {offsetted4, %1, $1+4} +with exact local_addr any4 any4 + kills allexceptcon + gen move %2, {LOCAL, %1.bd+$1} + move %3, {LOCAL, %1.bd+$1+4} +with exact ext_addr any4 any4 + kills allexceptcon + gen move %2, {absolute4, %1.bd+$1} + move %3, {absolute4, %1.bd+$1+4} +#ifndef m68020 +with regAcon any4 any4 + kills allexceptcon + gen move %2, {offsetted4, %1.reg, %1.bd+$1} + move %3, {offsetted4, %1.reg, %1.bd+$1+4} +#else m68020 +with exact regAcon any4 any4 + kills allexceptcon + gen move %2, {offsetted4, %1.reg, %1.bd+$1} + move %3, {offsetted4, %1.reg, %1.bd+$1+4} +with exact regAregXcon any4 any4 + kills allexceptcon + gen move %2, {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1} + move %3, {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1+4} +with exact indirect4 any4 any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, 0, $1} + move %3, {OFF_off4, %1.reg, 0, $1+4} +with exact offsetted4 any4 any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, %1.bd, $1} + move %3, {OFF_off4, %1.reg, %1.bd, $1+4} +with exact LOCAL any4 any4 + kills allexceptcon + gen move %2, {OFF_off4, lb, %1.bd, $1} + move %3, {OFF_off4, lb, %1.bd, $1+4} +with exact off_con any4 any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, %1.bd, %1.od+$1} + move %3, {OFF_off4, %1.reg, %1.bd, %1.od+$1+4} +with exact off_regXcon any4 any4 + kills allexceptcon + gen move %2, {OFF_indoff4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} + move %3, {OFF_indoff4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1+4} +with exact index_off4 any4 any4 + kills allexceptcon + gen move %2, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, $1} + move %3, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, $1+4} +with exact indoff_con any4 any4 + kills allexceptcon + gen move %2, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} + move %3, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1+4} +with exact absolute4 any4 any4 + kills allexceptcon + gen move %2, {ABS_off4, %1.bd, $1} + move %3, {ABS_off4, %1.bd, $1+4} +with exact abs_con any4 any4 + kills allexceptcon + gen move %2, {ABS_off4, %1.bd, %1.od+$1} + move %3, {ABS_off4, %1.bd, %1.od+$1+4} +with exact abs_regXcon any4 any4 + kills allexceptcon + gen move %2, {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od+$1} + move %3, {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od+$1+4} +with exact abs_index4 any4 any4 + kills allexceptcon + gen move %2, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, $1} + move %3, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, $1+4} +with exact absind_con any4 any4 + kills allexceptcon + gen move %2, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1} + move %3, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1+4} +with exact ext_regX any4 any4 + kills allexceptcon + gen move %2, {abs_index4, %1.sc, %1.xreg, %1.bd+$1} + move %3, {abs_index4, %1.sc, %1.xreg, %1.bd+$1+4} +#endif m68020 + + + +/************************************************ + * Group 3: integer arithmetic. * + ************************************************/ + + +pat adi $1==4 +with any4 DD_REG + gen add_l %1, %2 yields %2 +with DD_REG any4-DD_REG + gen add_l %2, %1 yields %1 +with DD_REG STACK + gen add_l {post_inc4, sp}, %1 + yields %1 + +pat sbi $1==4 +with any4 DD_REG + gen sub_l %1, %2 yields %2 +with DD_REG any4-DD_REG + gen sub_l %2, %1 + neg_l %1 yields %1 +with DD_REG STACK + gen sub_l {post_inc4, sp}, %1 + neg_l %1 yields %1 +with any4 AA_REG + gen sub_l %1, %2 yields %2 + +pat mli $1==4 +#ifdef m68020 +with data4 DD_REG + gen muls_l %1, %2 yields %2 +#else m68020 +with STACK + gen jsr {absolute4, ".mli"} + yields d1 +#endif m68020 + +pat dvi $1==4 +#ifdef m68020 +with data4 DD_REG + gen divs_l %1, %2 yields %2 +#else m68020 +with STACK + gen jsr {absolute4, ".dvi"} + yields d1 +#endif m68020 + +pat rmi $1==4 +#ifdef m68020 +with data4 DD_REG + uses DD_REG + gen divsl_l %1, {DREG_pair, %a, %2} + killreg %2 + /* !!!! contents of %2 have changed: make this known to cg */ + yields %a +#else m68020 +with STACK + gen jsr {absolute4, ".dvi"} + yields d0 +#endif m68020 + +pat ngi $1==4 +with DD_REG + gen neg_l %1 yields %1 + +pat sli $1==4 +with D_REG DD_REG + gen asl_l %1, %2 yields %2 + +pat sri $1==4 +with D_REG DD_REG + gen asr_l %1, %2 yields %2 + + + +/************************************************ + * Group 4: unsigned arithmetic. * + ************************************************/ + + +pat adu leaving adi $1 + +pat sbu leaving sbi $1 + +pat mlu $1==4 +#ifdef m68020 +with data4 DD_REG + gen mulu_l %1, %2 yields %2 +#else m68020 +with STACK + gen jsr {absolute4, ".mlu"} + yields d1 +#endif m68020 + +pat dvu $1==4 +#ifdef m68020 +with data4 DD_REG + gen divu_l %1, %2 yields %2 +#else m68020 +with STACK + gen jsr {absolute4, ".dvu"} + yields d1 +#endif m68020 + +pat rmu $1==4 +#ifdef m68020 +with data4 DD_REG + uses DD_REG + gen divul_l %1, {DREG_pair, %a, %2} + killreg %2 + /* !!!! contents of %2 have changed: make this known to cg */ + yields %a +#else m68020 +with STACK + gen jsr {absolute4, ".dvu"} + yields d0 +#endif m68020 + +pat slu leaving sli $1 + +pat sru $1==4 +with D_REG DD_REG + gen lsr_l %1, %2 yields %2 + + + +/************************************************ + * Group 5: floating point arithmetic * + * * + * is not available on 68000, 68010 or 68020 * + * so traps will be generated * + ************************************************/ + +pat adf leaving loc 18 trp +pat sbf leaving loc 18 trp +pat mlf leaving loc 18 trp +pat dvf leaving loc 18 trp +pat ngf leaving loc 18 trp +pat fif leaving loc 18 trp +pat fef leaving loc 18 trp + + + +/************************************************ + * Group 6: pointer arithmetic * + ************************************************/ + +pat adp $1==0 /* skip; array instructions might 'leave' this */ + +pat adp +with A_REG yields {t_regAcon, %1, $1} +with exact local_addr yields {local_addr, %1.bd+$1} +with exact ext_addr yields {ext_addr, %1.bd+$1} +with exact regAcon + t_regAcon + yields {t_regAcon, %1.reg, %1.bd+$1} +with exact regAregXcon + t_regAregXcon + yields {t_regAregXcon,%1.reg, %1.xreg, %1.sc, %1.bd+$1} +#ifdef m68020 +with exact indirect4 yields {off_con, %1.reg, 0, $1} +with exact LOCAL yields {off_con, lb, %1.bd, $1} +with exact offsetted4 yields {off_con, %1.reg, %1.bd, $1} +with exact off_con yields {off_con, %1.reg, %1.bd, %1.od+$1} +with exact off_regXcon yields {off_regXcon, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact index_off4 yields {indoff_con, %1.reg, %1.xreg, %1.sc, %1.bd, $1} +with exact indoff_con yields {indoff_con, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact absolute4 yields {abs_con, %1.bd, $1} +with exact abs_con yields {abs_con, %1.bd, %1.od+$1} +with exact abs_regXcon yields {abs_regXcon, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact abs_index4 yields {absind_con, %1.sc, %1.xreg, %1.bd, $1} +with exact absind_con yields {absind_con, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact ext_regX yields {ext_regX, %1.sc, %1.xreg, %1.bd+$1} +#endif m68020 + +pat ads $1==4 +with D_REG A_REG yields {regAregXcon, %2, %1, 1, 0} +with D_REG regAcon + t_regAcon + yields {t_regAregXcon, %2.reg, %1, 1, %2.bd} +with D_REG local_addr yields {t_regAregXcon, lb, %1, 1, %2.bd} +with any4-D_REG AA_REG + gen add_l %1, %2 yields %2 + +#ifdef m68020 + +with D_REG yields {regX, 1, %1} + leaving ads 4 +with regX A_REG yields {regAregXcon, %2, %1.xreg, %1.sc, 0} +with exact regX regAcon yields {regAregXcon, %2.reg, %1.xreg, %1.sc, %2.bd} +with exact regX local_addr + yields {regAregXcon, lb, %1.xreg, %1.sc, %2.bd} +with exact regX ext_addr + yields {ext_regX, %1.sc, %1.xreg, %2.bd} +with exact regX indirect4 + yields {off_regXcon, %2.reg, %1.xreg,%1.sc,0,0} +with exact regX offsetted4 + yields {off_regXcon, %2.reg, %1.xreg, %1.sc, %2.bd, 0} +with exact regX LOCAL yields {off_regXcon, lb, %1.xreg, %1.sc, %2.bd, 0} +with exact regX off_con yields {off_regXcon, %2.reg, %1.xreg,%1.sc,%2.bd,%2.od} +with exact regX absolute4 + yields {abs_regXcon, %1.sc, %1.xreg, %2.bd, 0} +with exact regX abs_con yields {abs_regXcon, %1.sc, %1.xreg, %2.bd, %2.od} +with exact indirect4 ext_addr + yields {off_con, %1.reg, 0, %2.bd} +with exact offsetted4 ext_addr + yields {off_con, %1.reg, %1.bd, %2.bd} +with exact LOCAL ext_addr + yields {off_con, lb, %1.bd, %2.bd} +with exact index_off4 ext_addr + yields {indoff_con, %1.reg, %1.xreg, %1.sc,%1.bd,%2.bd} +with exact absolute4 ext_addr + yields {abs_con, %1.bd, %2.bd} +with exact abs_index4 ext_addr + yields {absind_con, %1.sc, %1.xreg, %1.bd, %2.bd} +with exact indirect4 ext_regX + yields {off_regXcon, %1.reg, %2.xreg, %2.sc, 0, %2.bd} +with exact offsetted4 ext_regX + yields {off_regXcon, %1.reg, %2.xreg,%2.sc,%1.bd,%2.bd} +with exact LOCAL ext_regX + yields {off_regXcon, lb, %2.xreg, %2.sc, %1.bd, %2.bd} +with exact absolute4 ext_regX + yields {abs_regXcon, %2.sc, %2.xreg, %1.bd, %2.bd} +#endif m68020 + + /* I WOULD ALSO LIKE THIS: + * pat ads + * with const leaving adp %1.num + * BUT THAT DOESN'T WORK. + */ + +pat sbs $1==4 leaving sbi 4 + +#ifdef m68020 +pat loc sli ads $1==1 && $2==4 && $3==4 +with D_REG yields {regX, 2, %1} + leaving ads 4 + +pat loc sli ads $1==2 && $2==4 && $3==4 +with D_REG yields {regX, 4, %1} + leaving ads 4 + +pat loc sli ads $1==3 && $2==4 && $3==4 +with D_REG yields {regX, 8, %1} + leaving ads 4 +#endif m68020 + + +/************************************************ + * Group 7: increment / decrement / zero * + ************************************************/ + +pat inc +with exact STACK + gen add_l {const, 1}, {indirect4, sp} +with DD_REG+AA_REG + gen add_l {const, 1}, %1 + yields %1 + +pat inl + kills all_indir, LOCAL %bd==$1 + gen add_l {const, 1}, {LOCAL, $1} + +pat ine + kills posextern + gen add_l {const, 1}, {absolute4, $1} + +pat dec +with exact STACK + gen sub_l {const, 1}, {indirect4, sp} +with DD_REG+AA_REG + gen sub_l {const, 1}, %1 + yields %1 + +pat del + kills all_indir, LOCAL %bd==$1 + gen sub_l {const, 1}, {LOCAL, $1} + +pat dee + kills posextern + gen sub_l {const, 1}, {absolute4, $1} + +pat zrl + kills all_indir, LOCAL %bd==$1 + gen clr_l {LOCAL, $1} + +pat zre + kills posextern + gen clr_l {absolute4, $1} + +pat zer $1==4 yields {const, 0} +pat zer $1==8 yields {const, 0} {const, 0} +pat zer $1==12 yields {const, 0} {const, 0} {const, 0} + +pat zer +with STACK + uses DD_REG = {const, $1/4 -1} + gen 1: + clr_l {pre_dec4, sp} + dbf %a, {slabel, 1b} + + +pat zrf leaving loc 18 trp + + + +/************************************************ + * Group 8: convert instructions * + * for float conversions traps are generated * + ************************************************/ + + + +pat cii +with STACK + gen jsr {absolute4, ".cii"} + +pat cuu +with STACK + gen jsr {absolute4, ".cuu"} + +pat ciu leaving cuu + +pat cui leaving cuu + +pat cfi leaving loc 18 trp +pat cif leaving loc 18 trp +pat cfu leaving loc 18 trp +pat cuf leaving loc 18 trp +pat cff leaving loc 18 trp + + +/************************************************ + * Group 9: logical instructions * + ************************************************/ + + +proc log4 +with datalt4+const DD_REG + gen xxx* %1, %2 yields %2 +with DD_REG datalt4+const + gen xxx* %2, %1 yields %1 + +proc logdef example and +with STACK + uses DD_REG = {const, $1/4 -1}, + AA_REG = {regAcon, sp, $1}, + DD_REG + gen 1: + move_l {post_inc4, sp}, %c + xxx* %c, {post_inc4, %b} + dbf %a, {slabel, 1b} + +proc logndef +with DD_REG STACK + uses AA_REG = {regAregXcon, sp, %1, 1, 0}, + DD_REG + gen asr_l {shconst, 2}, %1 + sub_l {const, 1}, %1 + 1: + move_l {post_inc4, sp}, %b + xxx* %b, {post_inc4, %a} + dbf %1, {slabel, 1b} + +pat and $1==4 call log4("and.l") +pat and $1>4 call logdef("and.l") +pat and !defined($1) call logndef("and.l") +pat ior $1==4 call log4("or.l") +pat ior $1>4 call logdef("or.l") +pat ior !defined($1) call logndef("or.l") + +pat xor $1==4 +with conreg4 DD_REG + gen eor_l %1, %2 yields %2 +with DD_REG conreg4 + gen eor_l %2, %1 yields %1 + +pat xor $1>4 call logdef("eor.l") +pat xor !defined($1) call logndef("eor.l") + +pat com $1==4 +with DD_REG + gen not_l %1 yields %1 + +pat com $1==8 +with DD_REG DD_REG + gen not_l %1 + not_l %2 yields %2 %1 + +pat com $1>4 +with STACK + uses AA_REG, + DD_REG = {const, $1/4 -1} + gen move_l sp, %a + 1: + not_l {post_inc4, %a} + dbf %b, {slabel, 1b} + +pat com !defined($1) +with DD_REG STACK + uses AA_REG + gen move_l sp, %a + asr_l {shconst, 2}, %1 + sub_l {const, 1}, %1 + 1: + not_l {post_inc4, %a} + dbf %1, {slabel, 1b} + +pat rol $1==4 +with D_REG DD_REG + gen rol_l %1, %2 yields %2 + +pat ror $1==4 +with D_REG DD_REG + gen ror_l %1, %2 yields %2 + + + + +/************************************************ + * Group 10: sets * + ************************************************/ + + +pat inn $1==4 +with conreg2 DD_REG + gen btst %1, %2 + sne %2 + and_l {const, 1}, %2 + yields %2 + +pat inn defined($1) +with any4 STACK + gen move %1, d0 + move {const, $1}, d1 + jsr {absolute4, ".inn"} + yields d0 + +pat inn !defined($1) +with any4 any4 STACK + gen move %2, d0 + move %1, d1 + jsr {absolute4, ".inn"} + yields d0 + +pat loc inn $2==4 && small($1) +with DD_REG + gen asr_l {shconst, $1}, %1 + and_l {const, 1}, %1 + yields %1 + +pat set $1==4 +with conreg2 + uses DD_REG = {const, 0} + gen bset %1, %a yields %a + +pat set $1>4 +with any4 STACK + gen move %1, d0 + move {const, $1}, d1 + jsr {absolute4, ".set"} + +pat set !defined($1) +with any4 any4 STACK + gen move %2, d0 + move %1, d1 + jsr {absolute4, ".set"} + + + + +/************************************************ + * Group 11: arrays * + ************************************************/ + + +pat lar defined($1) +with STACK + gen move {const, $1}, d0 + jsr {absolute4, ".lar"} + +pat lar !defined($1) +with any4 STACK + gen move %1, d0 + jsr {absolute4, ".lar"} + +pat sar defined($1) +with STACK + gen move {const, $1}, d0 + jsr {absolute4, ".sar"} + +pat sar !defined($1) +with any4 STACK + gen move %1, d0 + jsr {absolute4, ".sar"} + +pat aar defined($1) +with STACK + gen move {const, $1}, d0 + jsr {absolute4, ".aar"} + yields a0 + +pat aar !defined($1) +with any4 STACK + gen move %1, d0 + jsr {absolute4, ".aar"} + yields a0 + +pat lae lar $2==4 && nicesize(rom($1,3)) + leaving lae $1 aar 4 loi rom($1, 3) +pat lae sar $2==4 && nicesize(rom($1,3)) + leaving lae $1 aar 4 sti rom($1, 3) + +pat lae aar $2==4 && rom($1,3)==1 + leaving ads 4 adp 0-rom($1,1) + +#ifdef m68020 +pat lae aar $2==4 && nicesize(rom($1,3)) +with D_REG yields {regX, rom($1,3), %1} + leaving ads 4 adp rom($1,3)*(0-rom($1,1)) +#else m68020 +pat lae aar $2==4 && rom($1,3)==2 +with DD_REG + gen asl_l {shconst, 1}, %1 + yields %1 + leaving ads 4 adp (0 - rom($1,1))<<1 + +pat lae aar $2==4 && rom($1,3)==4 +with DD_REG + gen asl_l {shconst, 2}, %1 + yields %1 + leaving ads 4 adp (0 - rom($1,1))<<2 + +pat lae aar $2==4 && rom($1,3)==8 +with DD_REG + gen asl_l {shconst, 3}, %1 + yields %1 + leaving ads 4 adp (0 - rom($1,1))<<3 +#endif m68020 + + /* I WOULD ALSO LIKE THESE: + * pat lae aar $2==4 && defined(rom($1,3)) + * with const leaving adp rom($1,3)*(%1.num-rom($1,1)) + * pat lae lar $2==4 && defined(rom($1,3)) + * with const leaving adp rom($1,3)*(%1.num-rom($1,1)) + * loi rom($1,3) + * pat lae sar $2==4 && defined(rom($1,3)) + * with const leaving adp rom($1,3)*(%1.num-rom($1,1)) + * sti rom($1,3) + * BUT THEY DON'T WORK. + */ + + + +/************************************************ + * Group 12: compare instructions * + ************************************************/ + + +pat cmi $1==4 leaving sbi 4 + +pat cmi defined($1) +with STACK + gen move {const, $1}, d0 + jsr {absolute4, ".cmi"} + yields d0 + +pat cmi !defined($1) +with any4 STACK + gen move %1, d0 + jsr {absolute4, ".cmi"} + yields d0 + +pat cmu $1==4 leaving sbi 4 + +pat cmu defined($1) +with STACK + gen move {const, $1}, d0 + jsr {absolute4, ".cmu"} + yields d0 + +pat cmu !defined($1) +with any4 STACK + gen move %1, d0 + jsr {absolute4, ".cmu"} + yields d0 + +pat cms $1==4 leaving sbi 4 + +pat cms defined($1) +with STACK + gen move {const, $1}, d0 + jsr {absolute4, ".cms"} + yields d0 + +pat cms !defined($1) +with any4 STACK + gen move %1, d0 + jsr {absolute4, ".cms"} + yields d0 + +pat cmp leaving cmu 4 + +proc txx +with test_set + uses DD_REG = {const, 1} + gen test %1 + bxx* {slabel, 1f} + clr_l %a + 1: + yields %a + +pat tlt call txx("blt") +pat tle call txx("ble") +pat teq call txx("beq") +pat tne call txx("bne") +pat tge call txx("bge") +pat tgt call txx("bgt") + +pat cmf leaving loc 18 trp + + + +/************************************************ + * Group 13: branch instructions * + ************************************************/ + +pat bra +with STACK + gen bra {llabel, $1} + +proc brxx example beq +with any4 genreg STACK + gen cmp_l %1, %2 + bxx[1] {llabel, $1} +with genreg any4 STACK + gen cmp_l %2, %1 + bxx[2] {llabel, $1} +with exact immediate4 imm_cmp4 + kills ALL + gen cmp_l %1, %2 + bxx[1] {llabel, $1} +with exact imm_cmp4 immediate4 + kills ALL + gen cmp_l %2, %1 + bxx[2] {llabel, $1} +with genreg STACK + gen cmp_l {post_inc4, sp}, %1 + bxx[2] {llabel, $1} +with exact immediate4 STACK + gen cmp_l %1, {post_inc4, sp} + bxx[1] {llabel, $1} +with any2-conreg2 genreg STACK + gen cmp_w %1, %2 + bxx[1] {llabel, $1} +with genreg any2-conreg2 STACK + gen cmp_w %2, %1 + bxx[2] {llabel, $1} +with exact const imm_cmp2 + kills ALL + gen cmp_w {const, loww(%1.num)}, %2 + bxx[1] {llabel, $1} +with exact imm_cmp2 const + kills ALL + gen cmp_w {const, loww(%2.num)}, %1 + bxx[2] {llabel, $1} +with data1-conreg1 D_REG STACK + gen cmp_b %1, %2 + bxx[1] {llabel, $1} +with D_REG data1-conreg1 STACK + gen cmp_b %2, %1 + bxx[2] {llabel, $1} +with exact const imm_cmp1 + kills ALL + gen cmp_b {const, lowb(%1.num)}, %2 + bxx[1] {llabel, $1} +with exact imm_cmp1 const + kills ALL + gen cmp_b {const, lowb(%2.num)}, %1 + bxx[2] {llabel, $1} + +pat blt call brxx("blt","bgt") +pat ble call brxx("ble","bge") +pat beq call brxx("beq","beq") +pat bne call brxx("bne","bne") +pat bge call brxx("bge","ble") +pat bgt call brxx("bgt","blt") + +proc zxx example zeq +with test_set STACK + gen test %1 + bxx* {llabel, $1} +with exact STACK + gen test {post_inc4, sp} + bxx* {llabel, $1} + +pat zlt call zxx("blt") +pat zle call zxx("ble") +pat zeq call zxx("beq") +pat zne call zxx("bne") +pat zge call zxx("bge") +pat zgt call zxx("bgt") + +/************************************************ + * Group 14: procedure calls instructions * + ************************************************/ + + +pat cai +with exact ext_addr + kills ALL + gen jsr {absolute4, %1.bd} +with A_REG STACK + gen jsr {indirect4, %1} +with STACK + uses AA_REG = {post_inc4, sp} + gen jsr {indirect4, %a} +#ifdef m68020 +with exact address + kills ALL + gen jsr %1 +#else m68020 +with address STACK + gen jsr %1 +#endif m68020 + +pat cal +with STACK + gen jsr {absolute4, $1} + +pat lfr $1==4 yields d0 +pat lfr $1==8 yields d1 d0 + +pat ret $1==0 +with STACK + gen return + +pat ret $1==4 +with any4 STACK + gen move %1, d0 + return +with STACK + gen move {post_inc4, sp}, d0 + return + +pat ret $1==8 +with any4 any4 STACK + gen move %1, d0 + move %2, d1 + return +with any4 STACK + gen move %1, d0 + move {post_inc4, sp}, d1 + return +with STACK + gen move {post_inc4, sp}, d0 + move {post_inc4, sp}, d1 + return + + +/************************************************ + * Group 15: miscellaneous instructions * + ************************************************/ + +pat asp small($1) +with STACK + gen add_l {const, $1}, sp +pat asp +with STACK + gen move {regAcon, sp, $1}, sp + +pat ass $1==4 +with any4 STACK + gen add_l %1, sp + +pat blm $1==4 +with A_REG A_REG + kills allexceptcon + gen move_l {indirect4, %2}, {indirect4, %1} + +pat blm $1==8 +with A_REG A_REG + kills allexceptcon + gen move_l {indirect4, %2}, {indirect4, %1} + move_l {offsetted4, %2, 4}, {offsetted4, %1, 4} + +pat blm $1>8 +with AA_REG AA_REG + kills allexceptcon + uses DD_REG={const, $1/4 -1} + gen 1: + move_l {post_inc4, %2}, {post_inc4, %1} + dbf %a, {slabel, 1b} + +pat bls $1==4 +with DD_REG AA_REG AA_REG + kills allexceptcon + gen asr_l {shconst, 2}, %1 + beq {slabel, 2f} + sub_l {const, 1}, %1 + 1: + move_l {post_inc4, %3}, {post_inc4, %2} + dbf %1, {slabel, 1b} + 2: + +pat csa $1==4 +with STACK + gen jmp {absolute4, ".csa"} + +pat csb $1==4 +with STACK + gen jmp {absolute4, ".csb"} + +pat dch leaving loi 4 + +pat dup $1==4 +with exact STACK + gen move_l {indirect4, sp}, {pre_dec4, sp} +with any4 yields %1 %1 + +pat dup $1==8 +with exact STACK + gen move_l {offsetted4, sp, 4}, {pre_dec4, sp} + move_l {offsetted4, sp, 4}, {pre_dec4, sp} +with any4 any4 yields %2 %1 %2 %1 + +pat dup $1>8 +with STACK + uses DD_REG = {const, $1/4 -1} + gen 1: + move_l {offsetted4, sp, $1 -4}, {pre_dec4, sp} + dbf %a, {slabel, 1b} + +pat dus $1==4 +with DD_REG STACK + uses AA_REG = {regAregXcon, sp, %1, 1, 0} + gen asr_l {shconst, 2}, %1 + beq {slabel, 2f} + sub_l {const, 1}, %1 + 1: + move_l {pre_dec4, %a}, {pre_dec4, sp} + dbf %1, {slabel, 1b} + 2: + +pat exg $1==4 +with any4 any4 yields %1 %2 + +pat exg defined($1) +with STACK + gen move {const, $1}, d0 + jsr {absolute4, ".exg"} + +pat exg !defined($1) +with any4 STACK + gen move_l %1, d0 + jsr {absolute4, ".exg"} + +pat fil + gen move_l {ext_addr, $1}, {absolute4, ".filn"} + +pat gto +with STACK + uses AA_REG = {ext_addr, $1} + gen move_l {offsetted4, %a, 8}, lb + move_l {offsetted4, %a, 4}, sp +#ifdef m68020 + jmp {OFF_off4, %a, 0, 0} +#else m68020 + move_l {indirect4, %a}, %a + jmp {indirect4, %a} +#endif m68020 + +pat lim yields {absolute4, ".trpim"} + +pat lin + gen move {const, $1}, {absolute4, ".lino"} + +pat lni + gen add_l {const, 1}, {absolute4, ".lino"} + +pat lor $1==0 yields lb + +pat lor $1==1 +with STACK + uses AA_REG = sp yields %a + +pat lor $1==2 yields {absolute4, ".reghp"} + +pat lpb leaving adp 8 + +pat mon +with STACK + gen jsr {absolute4, ".mon"} + +pat nop +with STACK + gen jsr {absolute4, ".nop"} + +pat rck +#ifdef m68020 +with ext_addr D_REG + gen cmp2_l {absolute4, %1.bd}, %2 + bcc {slabel, 1f} + pea {absolute4, 1} /* push constant 1 == ERANGE */ + jsr {absolute4, ".trp"} + 1: yields %2 +with address-ext_addr D_REG + gen cmp2_l %1, %2 + bcc {slabel, 1f} + pea {absolute4, 1} /* push constant 1 == ERANGE */ + jsr {absolute4, ".trp"} + 1: yields %2 +with A_REG D_REG + gen cmp2_l {indirect4, %1}, %2 + bcc {slabel, 1f} + pea {absolute4, 1} /* push constant 1 == ERANGE */ + jsr {absolute4, ".trp"} + 1: yields %2 +#else m68020 +with STACK + gen jsr {absolute4, ".rck"} +#endif m68020 + +pat rtt leaving ret 0 + +pat sig +with any4 + uses AA_REG + gen move {absolute4, ".trppc"}, %a + move %1, {absolute4, ".trppc"} + yields %a + +pat sim +with any4 + gen move_l %1, {absolute4, ".trpim"} + +pat str $1==0 +with any4 +#ifdef m68020 + kills LOCAL, ILOCAL, all_regind %reg==lb, local_addr +#else m68020 + kills LOCAL, all_regind %reg==lb, local_addr +#endif m68020 + gen move %1, lb + +pat str $1==1 +with any4 STACK + gen move %1, sp + +pat str $1==2 +with STACK + gen jsr {absolute4, ".strhp"} + +pat trp +with STACK + gen jsr {absolute4, ".trp"} + + + +/************************************************ + * rules for long EM-patterns * + ************************************************/ + +proc lolxxxstl example lol adi stl +with conreg4 + kills all_indir, LOCAL %bd==$1 + gen xxx* %1, {LOCAL, $1} + +proc loexxxste example loe adi ste +with conreg4 + kills posextern + gen xxx* %1, {absolute4, $1} + +proc lilxxxsil example lil adi sil +with conreg4 +#ifdef m68020 + kills allexceptcon + gen xxx* %1, {ILOCAL, $1} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen xxx* %1, {indirect4, %a} +#endif m68020 + +proc lolcxxxstl example lol loc adi stl + kills all_indir, LOCAL %bd==$1 + gen xxx* {const, $2}, {LOCAL, $1} + +proc loecxxxste example loe loc adi ste + kills posextern + gen xxx* {const, $2}, {absolute4, $1} + +proc lilcxxxsil example lil loc adi sil +#ifdef m68020 + kills allexceptcon + gen xxx* {const, $2}, {ILOCAL, $1} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen xxx* {const, $2}, {indirect4, %a} +#endif m68020 + +proc lolrxxxstl example lol lol adi stl + kills all_indir, LOCAL %bd==$1 + gen xxx* {LOCAL, $2}, {LOCAL, $1} + +proc loerxxxste example loe lol adi ste + kills posextern + gen xxx* {LOCAL, $2}, {absolute4, $1} + +proc lilrxxxsil example lil lol adi sil +#ifdef m68020 + kills allexceptcon + gen xxx* {LOCAL, $2}, {ILOCAL, $1} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen xxx* {LOCAL, $2}, {indirect4, %a} +#endif m68020 + +pat lol adi stl $1==$3 && $2==4 call lolxxxstl("add.l") +pat loe adi ste $1==$3 && $2==4 call loexxxste("add.l") +pat lil adi sil $1==$3 && $2==4 call lilxxxsil("add.l") +pat lol loc adi stl $1==$4 && $3==4 call lolcxxxstl("add.l") +pat loe loc adi ste $1==$4 && $3==4 call loecxxxste("add.l") +pat lil loc adi sil $1==$4 && $3==4 call lilcxxxsil("add.l") +pat lol lol adi stl $1==$4 && $3==4 && inreg($2)==reg_any + call lolrxxxstl("add.l") +pat loe lol adi ste $1==$4 && $3==4 && inreg($2)==reg_any + call loerxxxste("add.l") +pat lil lol adi sil $1==$4 && $3==4 && inreg($2)==reg_any + call lilrxxxsil("add.l") + +pat lol adu stl $1==$3 && $2==4 call lolxxxstl("add.l") +pat loe adu ste $1==$3 && $2==4 call loexxxste("add.l") +pat lil adu sil $1==$3 && $2==4 call lilxxxsil("add.l") +pat lol loc adu stl $1==$4 && $3==4 call lolcxxxstl("add.l") +pat loe loc adu ste $1==$4 && $3==4 call loecxxxste("add.l") +pat lil loc adu sil $1==$4 && $3==4 call lilcxxxsil("add.l") +pat lol lol adu stl $1==$4 && $3==4 && inreg($2)==reg_any + call lolrxxxstl("add.l") +pat loe lol adu ste $1==$4 && $3==4 && inreg($2)==reg_any + call loerxxxste("add.l") +pat lil lol adu sil $1==$4 && $3==4 && inreg($2)==reg_any + call lilrxxxsil("add.l") + + +pat lol adp stl $1==$3 + kills all_indir, LOCAL %bd==$1 + gen add_l {const, $2}, {LOCAL, $1} + +pat lil adp sil $1==$3 + kills allexceptcon +#ifdef m68020 + gen add_l {const, $2}, {ILOCAL, $1} +#else m68020 + uses AA_REG = {LOCAL, $1} + gen add_l {const, $2}, {indirect4, %a} +#endif m68020 + +pat loe adp ste $1==$3 + kills posextern + gen add_l {const, $2}, {absolute4, $1} + +pat lol lol adp stl $1==$2 && $1==$4 + kills all_indir, LOCAL %bd==$1 + uses AA_REG = {LOCAL, $1} + gen add_l {const, $3}, {LOCAL, $1} + yields %a + +pat lil lil adp sti $1==$2 && $1==$4 + kills allexceptcon +#ifdef m68020 + uses AA_REG = {ILOCAL, $1} + gen add_l {const, $3}, {ILOCAL, $1} +#else m68020 + uses AA_REG, AA_REG = {LOCAL, $1} + gen move {indirect4, %b}, %a + add_l {const, $3}, {indirect4, %b} +#endif m68020 + yields %a + +pat loe loe adp ste $1==$2 && $1==$4 + kills posextern + uses AA_REG = {absolute4, $1} + gen add_l {const, $3}, {absolute4, $1} + yields %a + + +pat lol loc sbi stl $1==$4 && $3==4 call lolcxxxstl("sub.l") +pat loe loc sbi ste $1==$4 && $3==4 call loecxxxste("sub.l") +pat lil loc sbi sil $1==$4 && $3==4 call lilcxxxsil("sub.l") +pat lol lol sbi stl $1==$4 && $3==4 && inreg($2)==reg_any + call lolrxxxstl("sub.l") +pat loe lol sbi ste $1==$4 && $3==4 && inreg($2)==reg_any + call loerxxxste("sub.l") +pat lil lol sbi sil $1==$4 && $3==4 && inreg($2)==reg_any + call lilrxxxsil("sub.l") + +pat lol loc sbu stl $1==$4 && $3==4 call lolcxxxstl("sub.l") +pat loe loc sbu ste $1==$4 && $3==4 call loecxxxste("sub.l") +pat lil loc sbu sil $1==$4 && $3==4 call lilcxxxsil("sub.l") +pat lol lol sbu stl $1==$4 && $3==4 && inreg($2)==reg_any + call lolrxxxstl("sub.l") +pat loe lol sbu ste $1==$4 && $3==4 && inreg($2)==reg_any + call loerxxxste("sub.l") +pat lil lol sbu sil $1==$4 && $3==4 && inreg($2)==reg_any + call lilrxxxsil("sub.l") + +pat lol and stl $1==$3 && $2==4 call lolxxxstl("and.l") +pat loe and ste $1==$3 && $2==4 call loexxxste("and.l") +pat lil and sil $1==$3 && $2==4 call lilxxxsil("and.l") +pat lol loc and stl $1==$4 && $3==4 call lolcxxxstl("and.l") +pat loe loc and ste $1==$4 && $3==4 call loecxxxste("and.l") +pat lil loc and sil $1==$4 && $3==4 call lilcxxxsil("and.l") +pat lol lol and stl $1==$4 && $3==4 && inreg($2)==reg_any + call lolrxxxstl("and.l") +pat loe lol and ste $1==$4 && $3==4 && inreg($2)==reg_any + call loerxxxste("and.l") +pat lil lol and sil $1==$4 && $3==4 && inreg($2)==reg_any + call lilrxxxsil("and.l") + +pat lol ior stl $1==$3 && $2==4 call lolxxxstl("or.l") +pat loe ior ste $1==$3 && $2==4 call loexxxste("or.l") +pat lil ior sil $1==$3 && $2==4 call lilxxxsil("or.l") +pat lol loc ior stl $1==$4 && $3==4 call lolcxxxstl("or.l") +pat loe loc ior ste $1==$4 && $3==4 call loecxxxste("or.l") +pat lil loc ior sil $1==$4 && $3==4 call lilcxxxsil("or.l") +pat lol lol ior stl $1==$4 && $3==4 && inreg($2)==reg_any + call lolrxxxstl("or.l") +pat loe lol ior ste $1==$4 && $3==4 && inreg($2)==reg_any + call loerxxxste("or.l") +pat lil lol ior sil $1==$4 && $3==4 && inreg($2)==reg_any + call lilrxxxsil("or.l") + +pat lol xor stl $1==$3 && $2==4 call lolxxxstl("eor.l") +pat loe xor ste $1==$3 && $2==4 call loexxxste("eor.l") +pat lil xor sil $1==$3 && $2==4 call lilxxxsil("eor.l") +pat lol loc xor stl $1==$4 && $3==4 call lolcxxxstl("eor.l") +pat loe loc xor ste $1==$4 && $3==4 call loecxxxste("eor.l") +pat lil loc xor sil $1==$4 && $3==4 call lilcxxxsil("eor.l") +pat lol lol xor stl $1==$4 && $3==4 && inreg($2)==reg_any + call lolrxxxstl("eor.l") +pat loe lol xor ste $1==$4 && $3==4 && inreg($2)==reg_any + call loerxxxste("eor.l") +pat lil lol xor sil $1==$4 && $3==4 && inreg($2)==reg_any + call lilrxxxsil("eor.l") + +proc llol1shstl example lol loc sli stl /* only left */ + kills all_indir, LOCAL %bd==$1 + gen shw* {offsetted2, lb, $1+2} + roxl {offsetted2, lb, $1} + +proc lloe1shste example loe loc sli ste /* only left */ + kills posextern + gen shw* {absolute2, $1+2} + roxl {absolute2, $1} + +proc llil1shsil example lil loc sli sil /* only left */ +#ifdef m68020 + kills allexceptcon + gen shw* {OFF_off2, lb, $1, 2} + roxl {OFF_off2, lb, $1, 0} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen shw* {offsetted2, %a, 2} + roxl {indirect2, %a} +#endif m68020 + +proc rlol1shstl example lol loc sri stl /* only right */ + kills all_indir, LOCAL %bd==$1 + gen shw* {offsetted2, lb, $1} + roxr {offsetted2, lb, $1+2} + +proc rloe1shste example loe loc sri ste /* only right */ + kills posextern + gen shw* {absolute2, $1} + roxr {absolute2, $1+2} + +proc rlil1shsil example lil loc sri sil /* only right */ +#ifdef m68020 + kills allexceptcon + gen shw* {OFF_off2, lb, $1, 0} + roxr {OFF_off2, lb, $1, 2} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen shw* {indirect2, %a} + roxr {offsetted2, %a, 2} +#endif m68020 + +pat lol loc sli stl $1==$4 && $2==1 && $3==4 call llol1shstl("asl #1,") +pat loe loc sli ste $1==$4 && $2==1 && $3==4 call lloe1shste("asl #1,") +pat lil loc sli sil $1==$4 && $2==1 && $3==4 call llil1shsil("asl #1,") +pat lol loc sri stl $1==$4 && $2==1 && $3==4 call rlol1shstl("asr #1,") +pat loe loc sri ste $1==$4 && $2==1 && $3==4 call rloe1shste("asr #1,") +pat lil loc sri sil $1==$4 && $2==1 && $3==4 call rlil1shsil("asr #1,") +pat lol loc slu stl $1==$4 && $2==1 && $3==4 call llol1shstl("asl #1,") +pat loe loc slu ste $1==$4 && $2==1 && $3==4 call lloe1shste("asl #1,") +pat lil loc slu sil $1==$4 && $2==1 && $3==4 call llil1shsil("asl #1,") +pat lol loc sru stl $1==$4 && $2==1 && $3==4 call rlol1shstl("lsr #1,") +pat loe loc sru ste $1==$4 && $2==1 && $3==4 call rloe1shste("lsr #1,") +pat lil loc sru sil $1==$4 && $2==1 && $3==4 call rlil1shsil("lsr #1,") + +proc locsh example loc sli +with DD_REG + gen sh* {shconst, $1}, %1 + yields %1 + +pat loc sli small($1) && $2==4 call locsh("asl.l") +pat loc sri small($1) && $2==4 call locsh("asr.l") +pat loc slu small($1) && $2==4 call locsh("asl.l") +pat loc sru small($1) && $2==4 call locsh("lsr.l") +pat loc rol small($1) && $2==4 call locsh("rol.l") +pat loc ror small($1) && $2==4 call locsh("ror.l") + +proc lolbitstl example lol ngi stl + kills all_indir, LOCAL %bd==$1 + gen bit* {LOCAL, $1} + +proc loebitste example loe ngi ste + kills posextern + gen bit* {absolute4, $1} + +proc lilbitsil example lil ngi sil +#ifdef m68020 + kills allexceptcon + gen bit* {ILOCAL, $1} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen bit* {indirect4, %a} +#endif m68020 + +pat lol ngi stl $1==$3 && $2==4 call lolbitstl("neg.l") +pat loe ngi ste $1==$3 && $2==4 call loebitste("neg.l") +pat lil ngi sil $1==$3 && $2==4 call lilbitsil("neg.l") +pat lol com stl $1==$3 && $2==4 call lolbitstl("not.l") +pat loe com ste $1==$3 && $2==4 call loebitste("not.l") +pat lil com sil $1==$3 && $2==4 call lilbitsil("not.l") + +pat lil inc sil $1==$3 +#ifdef m68020 + kills allexceptcon + gen add_l {const, 1}, {ILOCAL, $1} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen add_l {const, 1}, {indirect4, %a} +#endif m68020 + +pat lil dec sil $1==$3 +#ifdef m68020 + kills allexceptcon + gen sub_l {const, 1}, {ILOCAL, $1} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen sub_l {const, 1}, {indirect4, %a} +#endif m68020 + + +proc txxand +with test_set DD_REG + gen test %1 + bxx* {slabel, 1f} + clr_l %2 + 1: yields %2 + +proc txxior +with test_set DD_REG + gen test %1 + bxx* {slabel, 1f} + bset {const, 0}, %2 + 1: yields %2 + +pat tlt and $2==4 call txxand("blt") +pat tle and $2==4 call txxand("ble") +pat teq and $2==4 call txxand("beq") +pat tne and $2==4 call txxand("bne") +pat tge and $2==4 call txxand("bge") +pat tgt and $2==4 call txxand("bgt") + +pat tlt ior $2==4 call txxior("bge") +pat tle ior $2==4 call txxior("bgt") +pat teq ior $2==4 call txxior("bne") +pat tne ior $2==4 call txxior("beq") +pat tge ior $2==4 call txxior("blt") +pat tgt ior $2==4 call txxior("ble") + +proc cmxtxxand +with any4 genreg DD_REG + gen cmp_l %1, %2 + bxx[1] {slabel, 1f} + clr_l %3 + 1: yields %3 +with genreg any4-genreg DD_REG + gen cmp_l %2, %1 + bxx[2] {slabel, 1f} + clr_l %3 + 1: yields %3 +with exact immediate4 imm_cmp4 DD_REG + gen cmp_l %1, %2 + bxx[1] {slabel, 1f} + clr_l %3 + 1: yields %3 +with exact imm_cmp4 immediate4 DD_REG + gen cmp_l %2, %1 + bxx[2] {slabel, 1f} + clr_l %3 + 1: yields %3 + +proc cmxtxxior +with any4 genreg DD_REG + gen cmp_l %1, %2 + bxx[1] {slabel, 1f} + move {const, 1}, %3 + 1: yields %3 +with genreg any4-genreg DD_REG + gen cmp_l %2, %1 + bxx[2] {slabel, 1f} + move {const, 1}, %3 + 1: yields %3 +with exact immediate4 imm_cmp4 DD_REG + gen cmp_l %1, %2 + bxx[1] {slabel, 1f} + move {const, 1}, %3 + 1: yields %3 +with exact imm_cmp4 immediate4 DD_REG + gen cmp_l %2, %1 + bxx[2] {slabel, 1f} + move {const, 1}, %3 + 1: yields %3 + +proc cmxtxx +with any4 genreg + uses DD_REG = {const, 1} + gen cmp_l %1, %2 + bxx[1] {slabel, 1f} + clr_l %a + 1: yields %a +with genreg any4-genreg + uses DD_REG = {const, 1} + gen cmp_l %2, %1 + bxx[2] {slabel, 1f} + clr_l %a + 1: yields %a +with exact immediate4 imm_cmp4 + uses DD_REG = {const, 1} + gen cmp_l %1, %2 + bxx[1] {slabel, 1f} + clr_l %a + 1: yields %a +with exact imm_cmp4 immediate4 + uses DD_REG = {const, 1} + gen cmp_l %2, %1 + bxx[2] {slabel, 1f} + clr_l %a + 1: yields %a +with genreg STACK + uses DD_REG = {const, 1} + gen cmp_l {post_inc4, sp}, %1 + bxx[2] {slabel, 1f} + clr_l %a + 1: yields %a +with exact immediate4 STACK + uses DD_REG = {const, 1} + gen cmp_l %1, {post_inc4, sp} + bxx[1] {slabel, 1f} + clr_l %a + 1: yields %a + +pat cmi tlt and $1==4 && $3==4 call cmxtxxand("blt","bgt") +pat cmi tle and $1==4 && $3==4 call cmxtxxand("ble","bge") +pat cmi teq and $1==4 && $3==4 call cmxtxxand("beq","beq") +pat cmi tne and $1==4 && $3==4 call cmxtxxand("bne","bne") +pat cmi tge and $1==4 && $3==4 call cmxtxxand("bge","ble") +pat cmi tgt and $1==4 && $3==4 call cmxtxxand("bgt","blt") + +pat cmu tlt and $1==4 && $3==4 call cmxtxxand("bcs","bhi") +pat cmu tle and $1==4 && $3==4 call cmxtxxand("bls","bcc") +pat cmu teq and $1==4 && $3==4 call cmxtxxand("beq","beq") +pat cmu tne and $1==4 && $3==4 call cmxtxxand("bne","bne") +pat cmu tge and $1==4 && $3==4 call cmxtxxand("bcc","bls") +pat cmu tgt and $1==4 && $3==4 call cmxtxxand("bhi","bcs") + +pat cmi tlt ior $1==4 && $3==4 call cmxtxxior("bge","ble") +pat cmi tle ior $1==4 && $3==4 call cmxtxxior("bgt","blt") +pat cmi teq ior $1==4 && $3==4 call cmxtxxior("bne","bne") +pat cmi tne ior $1==4 && $3==4 call cmxtxxior("beq","beq") +pat cmi tge ior $1==4 && $3==4 call cmxtxxior("blt","bgt") +pat cmi tgt ior $1==4 && $3==4 call cmxtxxior("ble","bge") + +pat cmu tlt ior $1==4 && $3==4 call cmxtxxior("bcc","bls") +pat cmu tle ior $1==4 && $3==4 call cmxtxxior("bhi","bcs") +pat cmu teq ior $1==4 && $3==4 call cmxtxxior("bne","bne") +pat cmu tne ior $1==4 && $3==4 call cmxtxxior("beq","beq") +pat cmu tge ior $1==4 && $3==4 call cmxtxxior("bcs","bhi") +pat cmu tgt ior $1==4 && $3==4 call cmxtxxior("bls","bcc") + +pat cmi tlt $1==4 call cmxtxx("blt","bgt") +pat cmi tle $1==4 call cmxtxx("ble","bge") +pat cmi teq $1==4 call cmxtxx("beq","beq") +pat cmi tne $1==4 call cmxtxx("bne","bne") +pat cmi tge $1==4 call cmxtxx("bge","blt") +pat cmi tgt $1==4 call cmxtxx("bgt","blt") + +pat cmu tlt $1==4 call cmxtxx("bcs","bhi") +pat cmu tle $1==4 call cmxtxx("bls","bcc") +pat cmu teq $1==4 call cmxtxx("beq","beq") +pat cmu tne $1==4 call cmxtxx("bne","bne") +pat cmu tge $1==4 call cmxtxx("bcc","bls") +pat cmu tgt $1==4 call cmxtxx("bhi","bcs") + +proc cmxzxx example cmu zlt +with any4 genreg STACK + gen cmp_l %1, %2 + bxx[1] {llabel, $2} +with genreg any4-genreg STACK + gen cmp_l %2, %1 + bxx[2] {llabel, $2} +with exact immediate4 imm_cmp4 + kills ALL + gen cmp_l %1, %2 + bxx[1] {llabel, $2} +with exact imm_cmp4 immediate4 + kills ALL + gen cmp_l %2, %1 + bxx[2] {llabel, $2} +with genreg STACK + gen cmp_l {post_inc4, sp}, %1 + bxx[2] {llabel, $2} +with exact immediate4 STACK + gen cmp_l %1, {post_inc4, sp} + bxx[1] {llabel, $2} + +pat cmu zlt $1==4 call cmxzxx("bcs","bhi") +pat cmu zle $1==4 call cmxzxx("bls","bcc") +pat cmu zeq $1==4 call cmxzxx("beq","beq") +pat cmu zne $1==4 call cmxzxx("bne","bne") +pat cmu zge $1==4 call cmxzxx("bcc","bls") +pat cmu zgt $1==4 call cmxzxx("bhi","bcs") + + +proc bxx1_in example loc loc cii loc bne +with imm_cmp1 STACK + gen cmp_b {const, lowb($4)}, %1 + bxx* {llabel, $5} + +proc bxx2_in example loc loc cii loc bne +with imm_cmp2 STACK + gen cmp_w {const, loww($4)}, %1 + bxx* {llabel, $5} + +pat loc loc cii loc blt $1==1 && $2==4 && in_1($4) call bxx1_in("blt") +pat loc loc cii loc ble $1==1 && $2==4 && in_1($4) call bxx1_in("ble") +pat loc loc cii loc beq $1==1 && $2==4 && in_1($4) call bxx1_in("beq") +pat loc loc cii loc bne $1==1 && $2==4 && in_1($4) call bxx1_in("bne") +pat loc loc cii loc bge $1==1 && $2==4 && in_1($4) call bxx1_in("bge") +pat loc loc cii loc bgt $1==1 && $2==4 && in_1($4) call bxx1_in("bgt") + +pat loc loc cii loc blt $1==2 && $2==4 && in_2($4) call bxx2_in("blt") +pat loc loc cii loc ble $1==2 && $2==4 && in_2($4) call bxx2_in("ble") +pat loc loc cii loc beq $1==2 && $2==4 && in_2($4) call bxx2_in("beq") +pat loc loc cii loc bne $1==2 && $2==4 && in_2($4) call bxx2_in("bne") +pat loc loc cii loc bge $1==2 && $2==4 && in_2($4) call bxx2_in("bge") +pat loc loc cii loc bgt $1==2 && $2==4 && in_2($4) call bxx2_in("bgt") + +pat loc loc cii $1==1 && $2==2 +with DD_REG + gen ext_w %1 yields %1 + +pat loc loc cii $1==2 && $2==4 +with DD_REG + gen ext_l %1 yields %1 + +pat loc loc cii $1==1 && $2==4 +with DD_REG +#ifdef m68020 + gen extb_l %1 yields %1 +#else m68020 + gen ext_w %1 + ext_l %1 yields %1 +#endif m68020 + +pat loc loc ciu $1==$2 /* skip this */ +pat loc loc cui $1==$2 /* skip this */ + + +/* The following rules should be handled by the peephole optimizer, I think */ + +pat loc dvi $1==2 && $2==4 leaving loc 1 sri 4 +pat loc dvi $1==4 && $2==4 leaving loc 2 sri 4 +pat loc dvi $1==8 && $2==4 leaving loc 3 sri 4 +pat loc dvi $1==16 && $2==4 leaving loc 4 sri 4 +pat loc dvi $1==32 && $2==4 leaving loc 5 sri 4 +pat loc dvi $1==64 && $2==4 leaving loc 6 sri 4 +pat loc dvi $1==128 && $2==4 leaving loc 7 sri 4 +pat loc dvi $1==256 && $2==4 leaving loc 8 sri 4 + +pat loc dvu $1==2 && $2==4 leaving loc 1 sru 4 +pat loc dvu $1==4 && $2==4 leaving loc 2 sru 4 +pat loc dvu $1==8 && $2==4 leaving loc 3 sru 4 +pat loc dvu $1==16 && $2==4 leaving loc 4 sru 4 +pat loc dvu $1==32 && $2==4 leaving loc 5 sru 4 +pat loc dvu $1==64 && $2==4 leaving loc 6 sru 4 +pat loc dvu $1==128 && $2==4 leaving loc 7 sru 4 +pat loc dvu $1==256 && $2==4 leaving loc 8 sru 4 diff --git a/mach/m68k2/ncg/mach.c b/mach/m68k2/ncg/mach.c new file mode 100644 index 00000000..ec51f8bf --- /dev/null +++ b/mach/m68k2/ncg/mach.c @@ -0,0 +1,236 @@ +/* + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. + * + * This product is part of the Amsterdam Compiler Kit. + * + * Permission to use, sell, duplicate or disclose this software must be + * obtained in writing. Requests for such permissions may be sent to + * + * Dr. Andrew S. Tanenbaum + * Wiskundig Seminarium + * Vrije Universiteit + * Postbox 7161 + * 1007 MC Amsterdam + * The Netherlands + * + */ + +/* + * machine dependent back end routines for the Motorola 68000, 68010 or 68020 + */ + +#ifndef m68k4 +#define m68020 +#endif + /* use m68020 when you want a m68020 cg, don't if you want a + * m68k4 cg. The m68k4 cg can be used for both the MC68000 + * and the MC68010. + */ + +con_part(sz,w) register sz; word w; { + + while (part_size % sz) + part_size++; + if (part_size == 4) + part_flush(); + if (sz == 1) { + w &= 0xFF; + w <<= 8*(3-part_size); + part_word |= w; + } else if (sz == 2) { + w &= 0xFFFF; + if (part_size == 0) + w <<= 16; + part_word |= w; + } else { + assert(sz == 4); + part_word = w; + } + part_size += sz; +} + +con_mult(sz) word sz; { + + if (sz != 4) + fatal("bad icon/ucon size"); + fprintf(codefile,".data4 %s\n",str); +} + +con_float() { + +static int been_here; + if (argval != 4 && argval != 8) + fatal("bad fcon size"); + fprintf(codefile,".data4\t"); + if (argval == 8) + fprintf(codefile,"F_DUM,"); + fprintf(codefile,"F_DUM\n"); + if ( !been_here++) + { + fprintf(stderr,"Warning : dummy float-constant(s)\n"); + } +} + +regscore(off,size,typ,score,totyp) + long off; +{ + if (score == 0) return -1; + switch(typ) { + case reg_float: + return -1; + case reg_pointer: + if (size != 4 || totyp != reg_pointer) return -1; + score *= 2; + break; + case reg_loop: + score += 5; + /* fall through .. */ + case reg_any: + if (size != 4 || totyp == reg_pointer) return -1; + break; + } + if (off >= 0) { + /* parameters must be initialised with an instruction + * like "move.l 4(a6),d0", which costs 2 words. + */ + score -= 2; + } + score -= 1; /* take save/restore into account */ + return score; +} +struct regsav_t { + char *rs_reg; /* e.g. "a3" or "d5" */ + long rs_off; /* offset of variable */ + int rs_size; /* 2 or 4 bytes */ +} regsav[9]; + + +int regnr; + +i_regsave() +{ + regnr = 0; +} + +#define MOVEM_LIMIT 2 +/* If #registers to be saved exceeds MOVEM_LIMIT, we +* use the movem instruction to save registers; else +* we simply use several move.l's. +*/ + +save() +{ + register struct regsav_t *p; + + if (regnr > MOVEM_LIMIT) { + fprintf(codefile,"movem.l "); + for (p = regsav; ;) { + fprintf(codefile,"%s",p->rs_reg); + if (++p == ®sav[regnr]) break; + putc('/',codefile); + } + fprintf(codefile,",-(sp)\n"); + } else { + for (p = regsav; p < ®sav[regnr]; p++) { + fprintf(codefile,"move.l %s,-(sp)\n",p->rs_reg); + } + } + /* initialise register-parameters */ + for (p = regsav; p < ®sav[regnr]; p++) { + if (p->rs_off >= 0) { +#ifdef m68020 + fprintf(codefile,"move.%c (%ld,a6),%s\n", +#else + fprintf(codefile,"move.%c %ld(a6),%s\n", +#endif + (p->rs_size == 4 ? 'l' : 'w'), + p->rs_off, + p->rs_reg); + } + } +} + +restr() +{ + register struct regsav_t *p; + + if (regnr > MOVEM_LIMIT) { + fprintf(codefile,"movem.l (sp)+,"); + for (p = regsav; ;) { + fprintf(codefile,"%s",p->rs_reg); + if (++p == ®sav[regnr]) break; + putc('/',codefile); + } + putc('\n',codefile); + } else { + for (p = ®sav[regnr-1]; p >= regsav; p--) { + fprintf(codefile,"move.l (sp)+,%s\n",p->rs_reg); + } + } + fprintf(codefile,"unlk a6\n"); + fprintf(codefile,"rts\n"); +} + + +f_regsave() +{ + save(); +} + +regsave(str,off,size) + char *str; + long off; +{ + assert (regnr < 9); + regsav[regnr].rs_reg = str; + regsav[regnr].rs_off = off; + regsav[regnr++].rs_size = size; + fprintf(codefile, "!Local %ld into %s\n",off,str); +} + +regreturn() +{ + restr(); +} + + +prolog(nlocals) full nlocals; { + +#ifdef m68020 + fprintf(codefile,"tst.b (-%ld,sp)\nlink\ta6,#-%ld\n",nlocals+40,nlocals); +#else + fprintf(codefile,"tst.b -%ld(sp)\nlink\ta6,#-%ld\n",nlocals+40,nlocals); +#endif +} + + + +mes(type) word type ; { + int argt ; + + switch ( (int)type ) { + case ms_ext : + for (;;) { + switch ( argt=getarg( + ptyp(sp_cend)|ptyp(sp_pnam)|sym_ptyp) ) { + case sp_cend : + return ; + default: + strarg(argt) ; + fprintf(codefile,".define %s\n",argstr) ; + break ; + } + } + default : + while ( getarg(any_ptyp) != sp_cend ) ; + break ; + } +} + + +char *segname[] = { + ".sect .text", /* SEGTXT */ + ".sect .data", /* SEGCON */ + ".sect .rom", /* SEGROM */ + ".sect .bss" /* SEGBSS */ +}; diff --git a/mach/m68k2/ncg/mach.h b/mach/m68k2/ncg/mach.h new file mode 100644 index 00000000..ff2cf66c --- /dev/null +++ b/mach/m68k2/ncg/mach.h @@ -0,0 +1,39 @@ +#ifndef m68k4 +#define m68020 +#endif + /* m68020 should be used for a m68020 cg, and it should + * not be used for a m68k4 cg + */ + +#define ex_ap(y) fprintf(codefile,".extern %s\n",y) +#define in_ap(y) /* nothing */ + +#define newilb(x) fprintf(codefile,"%s:\n",x) +#define newdlb(x) fprintf(codefile,"%s:\n",x) +#define dlbdlb(x,y) fprintf(codefile,"%s = %s\n",x,y) +#define newlbss(l,x) fprintf(codefile,"%s:.space\t%ld\n",l,x); + +#define pop_fmt "(sp)+" +#define cst_fmt "%ld" +#define off_fmt "%ld" +#define ilb_fmt "I%03x%x" +#define dlb_fmt "_%d" +#define hol_fmt "hol%d" + +#ifdef m68020 +#define loc_off "(%d,a6)" +#define arg_off "(8+%d,a6)" +#else +#define loc_off "%d(a6)" +#define arg_off "8+%d(a6)" +#endif +#define hol_off "%ld+hol%d" + +#define con_cst(x) fprintf(codefile,".data4\t%ld\n",x) +#define con_ilb(x) fprintf(codefile,".data4\t%s\n",x) +#define con_dlb(x) fprintf(codefile,".data4\t%s\n",x) + +#define modhead ".sect .text\n.sect .rom\n.sect .data\n.sect .bss\n" + +#define id_first '_' +#define BSS_INIT 0 diff --git a/mach/m68k2/ncg/table b/mach/m68k2/ncg/table new file mode 100644 index 00000000..6518487a --- /dev/null +++ b/mach/m68k2/ncg/table @@ -0,0 +1,3288 @@ + /******************************** + * * + * 68000, 68010 and 68020 * + * back end table * + * * + ********************************/ + + +#ifndef m68k4 +#define m68020 +#endif + /* m68020 to be defined if this is the 68020 table. + * The 68000 and 68010 tables are identical. + */ + + +#define small(x) ((x)>=1 && (x)<=8) +#define nicesize(x) ((x)==1||(x)==2||(x)==4||(x)==8) +#define lowb(x) (((x)<<24)>>24) +#define loww(x) (((x)<<16)>>16) +#define in_1(x) ((x)>=0-128 && (x)<128) +#define in_2(x) ((x)>=0-32768 && (x)<32768) + + +EM_WSIZE = 4 +EM_PSIZE = 4 +EM_BSIZE = 8 + +SL = 8 + +TIMEFACTOR = 1/2 + + +PROPERTIES + +D_REG /* data registers */ +A_REG /* address registers */ +DD_REG /* allocatable D_REG, may not be a register variable */ +AA_REG /* allocatable A_REG, may not be a register variable */ + + + +REGISTERS + +d0, d1, d2 :D_REG, DD_REG. +d3, d4, d5, d6, d7 :D_REG regvar. +a0, a1 :A_REG, AA_REG. +a2, a3, a4, a5 :A_REG regvar(reg_pointer). +lb ("a6"), sp :A_REG. /* localbase and stack pointer */ + + + + +TOKENS + + /* Not all addressing modes available on the MC68020 are used in this + * table. E.g (Dn), data register indirect is not used. Compared to + * (An), address register indirect, (Dn) requires two more bytes and + * several more clock cycles. Using (Dn) is even more expensive in + * time than first moving Dn to an address register An, and then using + * (An). For this kind of reasons several addressing modes are + * not used in this table. + * + * Cost in bytes may sometimes be incorrect. Several effective addresses + * use displacements that can occupy either 2 or 4 bytes. These are not + * considered different TOKENS in this table. + * + * Data registers are the only registers used as index registers in this + * table; address registers are only used to hold addresses. + * + * For the m68k4 table: the MC68000 and MC68010 have two modes that use + * displacements (offsets) of limited size: + * - offset(A_REG, Index_reg), where offset is only 8 bits, and + * - offset(A_REG), where offset can only be 16 bits. + * To make sure that no output is given with offsets too large, two + * extra tokens are declared: t_regAregXcon and t_regAcon. These are + * used as addresses to these modes. Whenever the displacements become + * too large, they are transformed into different tokens. + * + * Sometimes some TOKENS are used with displacements (offsets) of 0. + * It would have been possible to provide separate TOKENS for these, in + * case the assembler doesn't handle zero offsets optimally. This + * however would mean a very large amount of extra TOKENS and SETS for + * a very small profit in code bytes, so we won't do that. + * + * To prevent the TOKENS list from getting too unreadable, #ifdefs are + * used to form three parts: + * (i) the common part; + * (ii) the m68k4 part; + * (iii) the m68020 part; + */ + + /* Part (i) */ +const = {INT num;} 4 cost(4,4) "#" num . +indirect4 = {A_REG reg;} 4 cost(0,4) "(" reg ")" . +post_inc4 = {A_REG reg;} 4 cost(0,4) "(" reg ")+" . +pre_dec4 = {A_REG reg;} 4 cost(0,5) "-(" reg ")" . +indirect2 = {A_REG reg;} 4 cost(0,4) "(" reg ")" . +post_inc2 = {A_REG reg;} 4 cost(0,4) "(" reg ")+" . +pre_dec2 = {A_REG reg;} 4 cost(0,5) "-(" reg ")" . +indirect1 = {A_REG reg;} 4 cost(0,4) "(" reg ")" . +post_inc1 = {A_REG reg;} 4 cost(0,4) "(" reg ")+" . +pre_dec1 = {A_REG reg;} 4 cost(0,5) "-(" reg ")" . + +ext_addr = {ADDR bd;} 4 cost(4,5) "#" bd . +llabel = {ADDR bd;} 4 cost(2,0) bd . +slabel = {ADDR bd;} 4 cost(0,0) bd . +shconst = {INT num;} 4 cost(0,0) "#" num . + +#ifndef m68020 + /* Part (ii) */ +absolute4 = {ADDR bd;} 4 cost(4,8) bd . +offsetted4 = {A_REG reg; INT bd;} 4 cost(2,6) bd "(" reg ")" . +index_off4 = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,7) + bd "(" reg "," xreg ".l)" . +absolute2 = {ADDR bd;} 4 cost(4,6) bd . +offsetted2 = {A_REG reg; INT bd;} 4 cost(2,4) bd "(" reg ")" . +index_off2 = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,5) + bd "(" reg "," xreg ".l)" . +absolute1 = {ADDR bd;} 4 cost(4,6) bd . +offsetted1 = {A_REG reg; INT bd;} 4 cost(2,4) bd "(" reg ")" . +index_off1 = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,5) + bd "(" reg "," xreg ".l)" . + +LOCAL = {INT bd;} 4 cost(2,6) bd "(a6)" . + +local_addr = {INT bd;} 4 cost(2,6) bd "(a6)" . +regAcon = {A_REG reg; INT bd;} 4 cost(2,6) bd "(" reg ")" . +regAregXcon = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,8) + bd "(" reg "," xreg ".l)" . + /* note: in the m68k4 version %sc always equals 1 */ + +t_regAregXcon = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,8) . +t_regAcon = {A_REG reg; INT bd;} 4 cost(2,6) . + +#else m68020 + /* Part (iii) */ +absolute4 = {ADDR bd;} 4 cost(4,7) "(" bd ")" . +offsetted4 = {A_REG reg; INT bd;} 4 cost(2,6) "(" bd "," reg ")" . +index_off4 = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(4,9) + "(" bd "," reg "," xreg ".l*" sc ")" . +abs_index4 = {INT sc; D_REG xreg; ADDR bd;} 4 cost(6,9) + "(" bd "," xreg ".l*" sc ")" . +OFF_off4 = {A_REG reg; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "]," od ")" . +OFF_indoff4 = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "]," xreg ".l*" sc "," od ")" . +INDOFF_off4 = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "," xreg ".l*" sc "]," od ")" . +ABS_off4 = {ADDR bd; ADDR od;} 4 cost(8,22) "([" bd "]," od ")" . +ABS_indoff4 = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,22) + "([" bd "]," xreg ".l*" sc "," od ")" . +ABSIND_off4 = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,22) + "([" bd "," xreg ".l*" sc "]," od ")" . + +absolute2 = {ADDR bd;} 4 cost(4,7) "(" bd ")" . +offsetted2 = {A_REG reg; INT bd;} 4 cost(2,6) "(" bd "," reg ")" . +index_off2 = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(4,9) + "(" bd "," reg "," xreg ".l*" sc ")" . +abs_index2 = {INT sc; D_REG xreg; ADDR bd;} 4 cost(6,9) + "(" bd "," xreg ".l*" sc ")" . +OFF_off2 = {A_REG reg; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "]," od ")" . +OFF_indoff2 = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "]," xreg ".l*" sc "," od ")" . +INDOFF_off2 = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "," xreg ".l*" sc "]," od ")" . +ABS_off2 = {ADDR bd; ADDR od;} 4 cost(8,22) "([" bd "]," od ")" . +ABS_indoff2 = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,22) + "([" bd "]," xreg ".l*" sc "," od ")" . +ABSIND_off2 = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,22) + "([" bd "," xreg ".l*" sc "]," od ")" . + +absolute1 = {ADDR bd;} 4 cost(4,7) "(" bd ")" . +offsetted1 = {A_REG reg; INT bd;} 4 cost(2,6) "(" bd "," reg ")" . +index_off1 = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(4,9) + "(" bd "," reg "," xreg ".l*" sc ")" . +abs_index1 = {INT sc; D_REG xreg; ADDR bd;} 4 cost(6,9) + "(" bd "," xreg ".l*" sc ")" . +OFF_off1 = {A_REG reg; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "]," od ")" . +OFF_indoff1 = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "]," xreg ".l*" sc "," od ")" . +INDOFF_off1 = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "," xreg ".l*" sc "]," od ")" . +ABS_off1 = {ADDR bd; ADDR od;} 4 cost(8,22) "([" bd "]," od ")" . +ABS_indoff1 = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,22) + "([" bd "]," xreg ".l*" sc "," od ")" . +ABSIND_off1 = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,22) + "([" bd "," xreg ".l*" sc "]," od ")" . + +LOCAL = {INT bd;} 4 cost(2,6) "(" bd ",a6)" . +ILOCAL = {INT bd;} 4 cost(4,16) "([" bd ",a6])" . + +local_addr = {INT bd;} 4 cost(2,3) "(" bd ",a6)" . +regAcon = {A_REG reg; INT bd;} 4 cost(2,3) "(" bd "," reg ")" . +regAregXcon = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,7) + "(" bd "," reg "," xreg ".l*" sc ")" . +off_con = {A_REG reg; INT bd; ADDR od;} 4 cost(6,18) + "([" bd "," reg "]," od ")". +off_regXcon = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,18) + "([" bd "," reg "]," xreg ".l*" sc "," od ")" . +indoff_con = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,18) + "([" bd "," reg "," xreg ".l*" sc "]," od ")" . +abs_con = {ADDR bd; ADDR od;} 4 cost(8,21) "([" bd "]," od ")" . +abs_regXcon = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,21) + "([" bd "]," xreg ".l*" sc "," od ")" . +absind_con = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,21) + "([" bd "," xreg ".l*" sc "]," od ")" . +ext_regX = {INT sc; D_REG xreg; ADDR bd;} 4 cost(6,15) + "(" bd "," xreg ".l*" sc ")" . + +regX = {INT sc; D_REG xreg;} 4 cost(2,7) "(" xreg ".l*" sc ")" . +DREG_pair = {D_REG reg1; D_REG reg2;} 8 cost(2,0) reg1 ":" reg2 . + +#define t_regAregXcon regAregXcon +#define t_regAcon regAcon + +#endif m68020 + +SETS + + /* The SETS list cannot be kept as 'readable' as the TOKENS list + * because cgg is one pass. + */ + +#ifndef m68020 + /* A m68k4 part */ +data4 = D_REG + LOCAL + const + post_inc4 + pre_dec4 + + indirect4 + offsetted4 + index_off4 + absolute4 + + ext_addr . +memory4 = data4 - D_REG . +control4 = indirect4 + offsetted4 + index_off4 + absolute4 + + LOCAL . +alterable4 = data4 + A_REG - const - ext_addr . +any4 = data4 + A_REG . /* all four above together */ + +data2 = D_REG + post_inc2 + pre_dec2 + indirect2 + + offsetted2 + index_off2 + absolute2 + const . +memory2 = data2 - D_REG . +control2 = indirect2 + offsetted2 + index_off2 + absolute2 . +alterable2 = data2 + A_REG - const . +any2 = data2 + A_REG . + +data1 = D_REG + post_inc1 + pre_dec1 + indirect1 + + offsetted1 + index_off1 + absolute1 + const . +memory1 = data1 - D_REG . +control1 = indirect1 + offsetted1 + index_off1 + absolute1 . +alterable1 = data1 - const . +any1 = data1 . + +#else m68020 + +data4 = D_REG + indirect4 + post_inc4 + pre_dec4 + index_off4 + + offsetted4 + OFF_off4 + OFF_indoff4 + + INDOFF_off4 + + ABS_off4 + ABS_indoff4 + ABSIND_off4 + + absolute4 + abs_index4 + const + ext_addr + + LOCAL + ILOCAL . +memory4 = data4 - D_REG . +control4 = memory4 - (post_inc4 + pre_dec4 + const + ext_addr) . +alterable4 = data4 + A_REG - const - ext_addr . +any4 = data4 + A_REG . /* all four above together */ + +data2 = D_REG + indirect2 + post_inc2 + pre_dec2 + index_off2 + + offsetted2 + OFF_off2 + OFF_indoff2 + + INDOFF_off2 + + ABS_off2 + ABS_indoff2 + ABSIND_off2 + + absolute2 + abs_index2 + const . +memory2 = data2 - D_REG . +control2 = memory2 - (post_inc2 + pre_dec2 + const) . +alterable2 = data2 + A_REG - const . +any2 = data2 + A_REG . /* all four above together */ + +data1 = D_REG + indirect1 + post_inc1 + pre_dec1 + index_off1 + + offsetted1 + OFF_off1 + OFF_indoff1 + + INDOFF_off1 + + ABS_off1 + ABS_indoff1 + ABSIND_off1 + + absolute1 + abs_index1 + const . +memory1 = data1 - D_REG . +control1 = memory1 - (post_inc1 + pre_dec1 + const) . +alterable1 = data1 - const . +any1 = data1 . /* all four above together */ + +#endif m68020 + /* This is a common part */ +any = any4 + any2 + any1 . +absolute = absolute4 + absolute2 + absolute1 . +control = control4 + control2 + control1 . +indirect = indirect4 + indirect2 + indirect1 . +pre_post = pre_dec4 + pre_dec2 + pre_dec1 + + post_inc4 + post_inc2 + post_inc1 . +offsetted = offsetted4 + offsetted2 + offsetted1 . +index_off = index_off4 + index_off2 + index_off1 . + +#ifndef m68020 + /* A m68k4 part */ +regind_addr = regAcon + regAregXcon + t_regAcon + t_regAregXcon . +address = ext_addr + local_addr + regAcon + regAregXcon . +all_regind = indirect + offsetted + pre_post + index_off + + regind_addr . +all_indir = all_regind . +allexceptcon = ALL - ( D_REG + A_REG + const + + local_addr + ext_addr + regAcon + regAregXcon + + t_regAcon + t_regAregXcon ) . +use_index = index_off4 + index_off2 + index_off1 . + +#else m68020 + +reg_memind4 = OFF_off4 + OFF_indoff4 + INDOFF_off4 . +memind4 = reg_memind4 + + ABS_off4 + ABS_indoff4 . +reg_memind2 = OFF_off2 + OFF_indoff2 + INDOFF_off2 . +memind2 = reg_memind2 + + ABS_off2 + ABS_indoff2 . +reg_memind1 = OFF_off1 + OFF_indoff1 + INDOFF_off1 . +memind1 = reg_memind1 + + ABS_off1 + ABS_indoff1 . +reg_memind = reg_memind4 + reg_memind2 + reg_memind1 . +memind = memind4 + memind2 + memind1 . +regind_addr = regAcon + regAregXcon + + off_con + off_regXcon + + indoff_con . +address = regind_addr + + ext_addr + local_addr + + abs_con + abs_regXcon + + absind_con + + ext_regX . +all_regind = indirect + offsetted + index_off + pre_post + + reg_memind + regind_addr . +all_indir = all_regind + memind + ILOCAL . +allexceptcon = ALL - ( D_REG + A_REG + const + + local_addr + ext_addr + regAcon + regAregXcon + ext_regX ) . +use_index4 = index_off4 + abs_index4 + + OFF_indoff4 + INDOFF_off4 + + ABS_indoff4 + ABSIND_off4 . +use_index2 = index_off2 + abs_index2 + + OFF_indoff2 + INDOFF_off2 + + ABS_indoff2 + ABSIND_off2 . +use_index1 = index_off1 + abs_index1 + + OFF_indoff1 + INDOFF_off1 + + ABS_indoff1 + ABSIND_off1 . +use_indaddr = regAregXcon + + off_regXcon + indoff_con + + abs_regXcon + absind_con + + ext_regX . + +use_index = use_index4 + use_index2 + use_index1 + use_indaddr + regX . + +#endif m68020 + /* A common part */ +posextern = absolute + all_indir . + +genreg = D_REG + A_REG. +label = llabel + slabel . +immediate4 = const + ext_addr . +conreg4 = D_REG + immediate4 . +conreg2 = D_REG + const . +conreg1 = D_REG + const . +shconreg = D_REG + shconst . +datalt4 = data4 * alterable4 . +datalt2 = data2 * alterable2 . +datalt1 = data1 * alterable1 . +datalt = datalt4 + datalt2 + datalt1 . +memalt4 = memory4 * alterable4 . +memalt2 = memory2 * alterable2 . +memalt1 = memory1 * alterable1 . + +#ifndef m68020 + /* A m68k4 part */ +imm_cmp4 = alterable4 . +imm_cmp2 = alterable2 . +imm_cmp1 = datalt1 . + +test_set4 = datalt4 . +test_set2 = datalt2 . +test_set1 = datalt1 . + +#else m68020 + +imm_cmp4 = any4 - immediate4 . +imm_cmp2 = any2 - const . +imm_cmp1 = data1 - const . + +test_set4 = data4 - immediate4 . +test_set2 = data2 - const . +test_set1 = data1 - const . + +#endif m68020 + +test_set = test_set4 + test_set2 + test_set1 . + +#ifndef m68020 +t_address = address + t_regAregXcon + t_regAcon . +#else m68020 +#define t_address address +#endif m68020 + + +INSTRUCTIONS + + /* Since the 68000 , the 68010 and the 68020 instruction sets are rather + * extensive, especially because e.g. 'add.l' and 'add.w' are + * considered different instructions, only those instructions are + * listed here that are used in the rest of this table. + * + * Instruction timing cost cannot be accurately given, nor the timing + * cost for getting operands. Detailed information about this can be + * found in the "MC68020 User's Manual", section 9, about instruction + * timing. The cost used in this table are 'worst case' cost, as + * mentioned in section 9 of the user's manual. + * + * The first few instructions had to be added because register + * variables are used. The LOCALs below are register variables. + * One may not conclude that these operations are also allowed + * on LOCALs that are not register variables. + * The cost have been adapted, but are not accurate; when 'real' + * LOCALs are used the cost are very inaccurate. + */ + +add_l "add.l" any4:ro, LOCAL:rw:cc cost(0,0). +lea address:ro, LOCAL:wo cost(0,0). +sub_l "sub.l" any4:ro, LOCAL:rw:cc cost(0,0). +sh "illegal" shconreg:ro, LOCAL:rw:cc cost(0,0). +sh "illegal" LOCAL:ro, LOCAL:rw:cc cost(0,0). +xxx "illegal" data4:ro, LOCAL:rw:cc cost(0,0). +xxx "illegal" LOCAL:ro, alterable4:rw:cc cost(0,0). +#ifdef m68020 +divs_l "divs.l" data4:ro, LOCAL:rw:cc cost(0,90). +divu_l "divu.l" data4:ro, LOCAL:rw:cc cost(0,78). +muls_l "muls.l" data4:ro, LOCAL:rw:cc cost(0,44). +mulu_l "mulu.l" data4:ro, LOCAL:rw:cc cost(0,44). +#endif m68020 + +add_l "add.l" any4:ro, D_REG:rw:cc cost(2,3). +add_l "add.l" any4:ro, A_REG:rw cost(2,3). +add_l "add.l" conreg4:ro, alterable4:rw:cc cost(2,6). +and_l "and.l" data4:ro, D_REG:rw:cc cost(2,3). +and_l "and.l" D_REG:ro, memalt4:rw:cc cost(2,6). +and_l "and.l" const:ro, datalt4:rw:cc cost(2,6). +asl_l "asl.l" shconreg:ro, D_REG:rw:cc cost(2,5). +asl "asl #1," memalt2:rw:cc cost(2,4). +asr_l "asr.l" shconreg:ro, D_REG:rw:cc cost(2,4). +asr "asr #1," memalt2:rw:cc cost(2,4). +bra label cost(2,5). +bcc label cost(2,5). +bcs label cost(2,5). +beq label cost(2,5). +bge label cost(2,5). +bgt label cost(2,5). +bhi label cost(2,5). +ble label cost(2,5). +bls label cost(2,5). +blt label cost(2,5). +bmi label cost(2,5). +bne label cost(2,5). +bpl label cost(2,5). +bvc label cost(2,5). +bvs label cost(2,5). +bset conreg2:ro, D_REG:rw kills :cc cost(2,4). +btst conreg2:ro, data1:rw kills :cc cost(2,3). +clr_l "clr.l" D_REG:wo:cc cost(2,3). +clr_l "clr.l" memalt4:wo:cc cost(2,6). +clr_w "clr.w" D_REG:wo:cc cost(2,2). +clr_w "clr.w" memalt2:wo:cc cost(2,4). +clr_b "clr.b" D_REG:wo:cc cost(2,2). +clr_b "clr.b" memalt1:wo:cc cost(2,4). +cmp_l "cmp.l" any4:ro, genreg:ro kills :cc cost(2,3). +cmp_l "cmp.l" post_inc4:ro, post_inc4:ro kills :cc cost(2,2). +cmp_l "cmp.l" immediate4:ro, imm_cmp4:ro kills :cc cost(2,2). +cmp_w "cmp.w" any2:ro, genreg:ro kills :cc cost(2,3). +cmp_w "cmp.w" post_inc2:ro, post_inc2:ro kills :cc cost(2,2). +cmp_w "cmp.w" const:ro, imm_cmp2:ro kills :cc cost(2,2). +cmp_b "cmp.b" data1:ro, D_REG:ro kills :cc cost(2,3). +cmp_b "cmp.b" post_inc1:ro, post_inc1:ro kills :cc cost(2,2). +cmp_b "cmp.b" const:ro, imm_cmp1:ro kills :cc cost(2,2). +dbf D_REG:rw, label cost(2,5). +eor_l "eor.l" conreg4:ro, datalt4:rw:cc cost(2,6). +ext_l "ext.l" D_REG:rw:cc cost(2,2). +ext_w "ext.w" D_REG:rw:cc cost(2,2). +jmp address+control4 cost(2,0). +jsr address+control4 kills :cc cost(2,3). +lea address+control4:ro, A_REG:wo cost(2,0). +lsl_l "lsl.l" shconreg:ro, D_REG:rw:cc cost(2,4). +lsl "lsl #1," memalt2:rw:cc cost(2,4). +lsr_l "lsr.l" shconreg:ro, D_REG:rw:cc cost(2,4). +lsr "lsr #1," memalt2:rw:cc cost(2,4). +move_l "move.l" any4:ro, alterable4:wo:cc cost(2,2). +move_w "move.w" any2:ro, alterable2:wo:cc cost(2,2). +move_b "move.b" data1:ro, alterable1:wo:cc cost(2,2). +neg_l "neg.l" D_REG:rw:cc cost(2,3). +neg_l "neg.l" memory4:rw:cc cost(2,6). +not_l "not.l" D_REG:rw:cc cost(2,3). +not_l "not.l" memory4:rw:cc cost(2,6). +or_l "or.l" data4:ro, D_REG:rw:cc cost(2,3). +or_l "or.l" D_REG:ro, memalt4:rw:cc cost(2,6). +or_l "or.l" const:ro, datalt4:rw:cc cost(2,6). +rol_l "rol.l" shconreg:ro, D_REG:rw:cc cost(2,4). +rol "rol #1," memalt2:rw:cc cost(2,4). +ror_l "ror.l" shconreg:ro, D_REG:rw:cc cost(2,4). +ror "ror #1," memalt2:rw:cc cost(2,4). +roxl "roxl #1," memalt2:rw:cc cost(2,4). +roxr "roxr #1," memalt2:rw:cc cost(2,4). +sne datalt1:rw cost(2,3). +sub_l "sub.l" any4:ro, D_REG:rw:cc cost(2,3). +sub_l "sub.l" any4:ro, A_REG:rw cost(2,3). +sub_l "sub.l" conreg4:ro, alterable4:rw:cc cost(2,6). +tst_l "tst.l" test_set4:ro:cc cost(2,3). +tst_w "tst.w" test_set2:ro:cc cost(2,3). +tst_b "tst.b" test_set1:ro:cc cost(2,3). +unlk A_REG cost(2,6). + +bxx "illegal" label cost(2,5). +xxx "illegal" data4:ro, D_REG:rw:cc cost(2,3). +xxx "illegal" conreg4:ro, memalt4:rw:cc cost(2,6). +bit "illegal" control4:rw:cc cost(2,6). +sh "illegal" shconreg:ro, D_REG:rw:cc cost(2,4). +shw "illegal" control2:rw:cc cost(2,4). + +#ifdef m68020 +cmp2_l "cmp2.l" address+control4:ro, genreg:ro kills :cc cost(2,18). +divs_l "divs.l" data4:ro, D_REG:rw:cc cost(2,90). +divsl_l "divsl.l" data4:ro, DREG_pair:rw kills :cc cost(2,90). +divu_l "divu.l" data4:ro, D_REG:rw:cc cost(2,78). +divul_l "divul.l" data4:ro, DREG_pair:rw kills :cc cost(2,78). +extb_l "extb.l" D_REG:rw:cc cost(2,4). +muls_l "muls.l" data4:ro, D_REG:rw:cc cost(2,44). +mulu_l "mulu.l" data4:ro, D_REG:rw:cc cost(2,44). +pea address+control4+regX cost(2,4). +#else m68020 +pea address+control4 cost(2,4). +#endif m68020 + + /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * Extra pseudo instruction; it just kills a D_REG; + * it is necessary with long divides where remainders are important; + * see also: 'pat rmi' and 'pat rmu' + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ +killreg "! kill" D_REG:wo cost(0,0). + + +MOVES + +from const %num==0 to D_REG + gen clr_l %2 + +from const %num==0 to memalt4 + gen clr_l %2 + +from const %num==0 to memalt2 + gen clr_w %2 + +from const %num==0 to memalt1 + gen clr_b %2 + +from const to memalt1 + gen move_b {const, lowb(%1.num)}, %2 + +from const to memalt2 + gen move_w {const, loww(%1.num)}, %2 + +from regAcon %bd==0 to A_REG + gen move_l %1.reg, %2 + +#ifndef m68020 +from t_regAregXcon sfit(%bd, 8) to A_REG + gen lea {regAregXcon, %1.reg, %1.xreg, 1, %1.bd}, %2 + +from t_regAregXcon to A_REG + gen lea {regAregXcon, %1.reg, %1.xreg, 1, 0}, %2 + add_l {const, %1.bd}, %2 + +from t_regAcon sfit(%bd, 16) to A_REG + gen lea {regAcon, %1.reg, %1.bd}, %2 + +from t_regAcon to A_REG + gen move_l %1.reg, %2 + add_l {const, %1.bd}, %2 +#endif m68020 + +from address - ext_addr to A_REG + gen lea %1, %2 + +from any4 to alterable4 + gen move_l %1, %2 + +from any2 to datalt2 + gen move_w %1, %2 + +from data1 to datalt1 + gen move_b %1, %2 + + + + +TESTS + + +to test test_set4 + gen tst_l %1 + +to test test_set2 + gen tst_w %1 + +to test test_set1 + gen tst_b %1 + + +STACKINGRULES + + +from const %num==0 to STACK + gen clr_l {pre_dec4, sp} + +#ifndef m68020 +from t_regAregXcon sfit(%bd, 8) to STACK + gen pea {regAregXcon, %1.reg, %1.xreg, 1, %1.bd} + +from t_regAregXcon to STACK + gen pea {regAregXcon, %1.reg, %1.xreg, 1, 0} + add_l {const, %1.bd}, {indirect4, sp} + +from t_regAcon sfit(%bd, 16) to STACK + gen pea {regAcon, %1.reg, %1.bd} + +from t_regAcon to STACK + gen move_l %1.reg, {pre_dec4, sp} + add_l {const, %1.bd}, {indirect4, sp} +#endif m68020 + +from address - ext_addr to STACK + gen pea %1 + +from ext_addr to STACK + gen pea {absolute4, %1.bd} + +from const to STACK + gen pea {absolute4, %1.num} + +from any4 to STACK + gen move_l %1, {pre_dec4, sp} + +from any2 to STACK + gen clr_l {pre_dec4, sp} + move_w %1, {offsetted2, sp, 2} + +from data1 to STACK + gen clr_l {pre_dec4, sp} + move_b %1, {offsetted1, sp, 3} + +#ifdef m68020 +from regX to STACK + gen pea %1 +#endif m68020 + /* This last stackingrule is never used: whenever regX is put on + * the fakestack, some em-instuctions are left that remove it + * immediately. However cgg complained about not having a + * stackingrule for regX, so here it is + */ + + +COERCIONS + + +from STACK + uses DD_REG + gen move_l {post_inc4, sp}, %a + yields %a + +from STACK + uses AA_REG + gen move_l {post_inc4, sp}, %a + yields %a + +#ifndef m68020 +from t_regAregXcon sfit(%bd, 8) + yields {regAregXcon, %1.reg, %1.xreg, 1, %1.bd} + +from t_regAregXcon + uses AA_REG=%1.reg + gen add_l {const, %1.bd}, %a + yields {regAregXcon, %a, %1.xreg, 1, 0} + +from t_regAcon sfit(%bd, 16) + yields {regAcon, %1.reg, %1.bd} + +from t_regAcon + uses reusing %1, AA_REG=%1.reg + gen add_l {const, %1.bd}, %a + yields %a +#endif m68020 + +from t_address + uses reusing %1, AA_REG = %1 + yields %a + +from any4 + uses reusing %1, DD_REG = %1 + yields %a + +from any4 + uses reusing %1, AA_REG = %1 + yields %a + +from memory2 + uses DD_REG = {const, 0} + gen move_w %1, %a yields %a + +from memory1 + uses DD_REG = {const, 0} + gen move_b %1, %a yields %a + + + + +PATTERNS + +/************************************************ + * Group 0: rules for register variables * + * LOCALs mentioned here refer to registers * + ************************************************/ + +pat lol inreg($1)==reg_pointer + kills pre_post %reg==regvar($1, reg_pointer) + yields {LOCAL, $1} + +pat lil inreg($1)==reg_pointer + kills pre_post %reg==regvar($1, reg_pointer) + yields {indirect4, regvar($1, reg_pointer)} + +pat stl inreg($1)==reg_any +with any4 + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen move %1, {LOCAL, $1} + +pat stl inreg($1)==reg_pointer +with any4 + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + gen move %1, {LOCAL, $1} +with exact ext_addr + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + gen move %1, {LOCAL, $1} +with exact address-ext_addr + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + gen lea %1, {LOCAL, $1} + +pat sil inreg($1)==reg_pointer +with any4 + kills allexceptcon + gen move %1, {indirect4, regvar($1, reg_pointer)} + + +pat lol sbi stl $1==$3 && $2==4 && inreg($1)==reg_any +with any4 + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen sub_l %1, {LOCAL, $1} + neg_l {LOCAL, $1} + +pat lol sbu stl $1==$3 && $2==4 && inreg($1)==reg_any +with any4 + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen sub_l %1, {LOCAL, $1} + neg_l {LOCAL, $1} + +pat lil sbi sil $1==$3 && $2==4 && inreg($1)==reg_pointer +with conreg4 + kills allexceptcon + gen sub_l %1, {indirect4, regvar($1, reg_pointer)} + neg_l {indirect4, regvar($1, reg_pointer)} + +pat lil sbu sil $1==$3 && $2==4 && inreg($1)==reg_pointer +with conreg4 + kills allexceptcon + gen sub_l %1, {indirect4, regvar($1, reg_pointer)} + neg_l {indirect4, regvar($1, reg_pointer)} + + +pat lil ngi sil $1==$3 && $2==4 && inreg($1)==reg_pointer + kills allexceptcon + gen neg_l {indirect4, regvar($1, reg_pointer)} + +pat lil com sil $1==$3 && $2==4 && inreg($1)==reg_pointer + kills allexceptcon + gen not_l {indirect4, regvar($1, reg_pointer)} + + +proc lolcshstl example lol loc sli stl + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen sh* {shconst, $2}, {LOCAL, $1} + +proc lolrshstl example lol lol sli stl + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen sh* {LOCAL, $2}, {LOCAL, $1} + +proc lil1shlsil example lil loc sli sil /* only left */ + kills allexceptcon + gen shw* {offsetted2, regvar($1, reg_pointer), 2} + roxl {indirect2, regvar($1, reg_pointer)} + +proc lil1shrsil example lil loc sli sil /* only right */ + kills allexceptcon + gen shw* {indirect2, regvar($1, reg_pointer)} + roxr {offsetted2, regvar($1, reg_pointer), 2} + +pat lol loc sli stl $1==$4 && small($2) && $3==4 && inreg($1)==reg_any + call lolcshstl("asl.l") +pat lol loc slu stl $1==$4 && small($2) && $3==4 && inreg($1)==reg_any + call lolcshstl("asl.l") +pat lol lol sli stl $1==$4 && inreg($1)==reg_any && $3==4 && inreg($2)==reg_any + call lolrshstl("asl.l") +pat lol lol slu stl $1==$4 && inreg($1)==reg_any && $3==4 && inreg($2)==reg_any + call lolrshstl("asl.l") +pat lil loc sli sil $1==$4 && $2==1 && $3==4 && inreg($1)==reg_pointer + call lil1shlsil("asl #1,") +pat lil loc slu sil $1==$4 && $2==1 && $3==4 && inreg($1)==reg_pointer + call lil1shlsil("asl #1,") +pat lol loc sri stl $1==$4 && small($2) && $3==4 && inreg($1)==reg_any + call lolcshstl("asr.l") +pat lol loc sru stl $1==$4 && small($2) && $3==4 && inreg($1)==reg_any + call lolcshstl("lsr.l") +pat lol lol sri stl $1==$4 && inreg($1)==reg_any && $3==4 && inreg($2)==reg_any + call lolrshstl("asr.l") +pat lol lol sru stl $1==$4 && inreg($1)==reg_any && $3==4 && inreg($2)==reg_any + call lolrshstl("lsr.l") +pat lil loc sri sil $1==$4 && $2==1 && $3==4 && inreg($1)==reg_pointer + call lil1shrsil("asr #1,") +pat lil loc sru sil $1==$4 && $2==1 && $3==4 && inreg($1)==reg_pointer + call lil1shrsil("lsr #1,") +pat lol loc rol stl $1==$4 && small($2) && $3==4 && inreg($1)==reg_any + call lolcshstl("rol.l") +pat lol lol rol stl $1==$4 && inreg($2)==reg_any && $3==4 && inreg($1)==reg_any + call lolrshstl("rol.l") +pat lol loc ror stl $1==$4 && small($2) && $3==4 && inreg($1)==reg_any + call lolcshstl("ror.l") +pat lol lol ror stl $1==$4 && inreg($2)==reg_any && $3==4 && inreg($1)==reg_any + call lolrshstl("ror.l") + +#ifdef m68020 +pat lol loc dvi stl $1==$4 && $3==4 && inreg($1)==reg_any + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen divs_l {const, $2}, {LOCAL, $1} + +pat lol loc dvu stl $1==$4 && $3==4 && inreg($1)==reg_any + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen divu_l {const, $2}, {LOCAL, $1} + +pat lol loc mli stl $1==$4 && $3==4 && inreg($1)==reg_any + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen muls_l {const, $2}, {LOCAL, $1} + +pat lol loc mlu stl $1==$4 && $3==4 && inreg($1)==reg_any + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen mulu_l {const, $2}, {LOCAL, $1} + +pat lol mli stl $1==$3 && $2==4 && inreg($1)==reg_any + with data4 + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen muls_l %1, {LOCAL, $1} + +pat lol mlu stl $1==$3 && $2==4 && inreg($1)==reg_any + with data4 + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen mulu_l %1, {LOCAL, $1} +#endif m68020 + + +pat lil inc sil $1==$3 && inreg($1)==reg_pointer + kills allexceptcon + gen add_l {const, 1}, {indirect4, regvar($1, reg_pointer)} + +pat lil dec sil $1==$3 && inreg($1)==reg_pointer + kills allexceptcon + gen sub_l {const, 1}, {indirect4, regvar($1, reg_pointer)} + +pat inl inreg($1)==reg_any + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen add_l {const, 1}, {LOCAL, $1} + +pat del inreg($1)==reg_any + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen sub_l {const, 1}, {LOCAL, $1} + +pat zrl inreg($1)==reg_any + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen clr_l {LOCAL, $1} + +pat zrl inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + gen move_l {const, 0}, {LOCAL, $1} + + +proc lolxxstl example lol and stl +with data4 + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen xxx* %1, {LOCAL, $1} + +proc lilxxsil example lil and sil +with conreg4 + kills allexceptcon + gen xxx* %1, {indirect4, regvar($1, reg_pointer)} + +proc lolcxxstl example lol loc and stl + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen xxx* {const, $2}, {LOCAL, $1} + +proc lilcxxsil example lil loc and sil + kills allexceptcon + gen xxx* {const, $2}, {indirect4, regvar($1, reg_pointer)} + +proc lolrxxstl example lol lol and stl + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen xxx* {LOCAL, $2}, {LOCAL, $1} + +proc lilrxxsil example lil lol and sil + kills allexceptcon + gen xxx* {LOCAL, $2}, {indirect4, regvar($1, reg_pointer)} + +pat lol adi stl $1==$3 && $2==4 && inreg($1)==reg_any + call lolxxstl("add.l") +pat lol loc adi stl $1==$4 && $3==4 && inreg($1)==reg_any + call lolcxxstl("add.l") +pat lil adi sil $1==$3 && $2==4 &&inreg($1)==reg_pointer + call lilxxsil("add.l") +pat lil loc adi sil $1==$4 && $3==4 && inreg($1)==reg_pointer + call lilcxxsil("add.l") +pat lol lol adi stl $1==$4 && $3==4 && inreg($1)==reg_any && inreg($2)==reg_any + call lolrxxstl("add.l") +pat lil lol adi sil $1==$4 && $3==4 && inreg($1)==reg_pointer && + inreg($2)==reg_any + call lilrxxsil("add.l") +pat lol adu stl $1==$3 && $2==4 && inreg($1)==reg_any + call lolxxstl("add.l") +pat lol loc adu stl $1==$4 && $3==4 && inreg($1)==reg_any + call lolcxxstl("add.l") +pat lil adu sil $1==$3 && $2==4 &&inreg($1)==reg_pointer + call lilxxsil("add.l") +pat lil loc adu sil $1==$4 && $3==4 && inreg($1)==reg_pointer + call lilcxxsil("add.l") +pat lol lol adu stl $1==$4 && $3==4 && inreg($1)==reg_any && inreg($2)==reg_any + call lolrxxstl("add.l") +pat lil lol adu sil $1==$4 && $3==4 && inreg($1)==reg_pointer && + inreg($2)==reg_any + call lilrxxsil("add.l") +pat lol loc sbi stl $1==$4 && $3==4 && inreg($1)==reg_any + call lolcxxstl("sub.l") +pat lil loc sbi sil $1==$4 && $3==4 && inreg($1)==reg_pointer + call lilcxxsil("sub.l") +pat lol lol sbi stl $1==$4 && $3==4 && inreg($1)==reg_any && inreg($2)==reg_any + call lolrxxstl("sub.l") +pat lil lol sbi sil $1==$4 && $3==4 && inreg($1)==reg_pointer && + inreg($2)==reg_any + call lilrxxsil("sub.l") +pat lol loc sbu stl $1==$4 && $3==4 && inreg($1)==reg_any + call lolcxxstl("sub.l") +pat lil loc sbu sil $1==$4 && $3==4 && inreg($1)==reg_pointer + call lilcxxsil("sub.l") +pat lol lol sbu stl $1==$4 && $3==4 && inreg($1)==reg_any && inreg($2)==reg_any + call lolrxxstl("sub.l") +pat lil lol sbu sil $1==$4 && $3==4 && inreg($1)==reg_pointer && + inreg($2)==reg_any + call lilrxxsil("sub.l") +pat lol and stl $1==$3 && $2==4 && inreg($1)==reg_any + call lolxxstl("and.l") +pat lol loc and stl $1==$4 && $3==4 && inreg($1)==reg_any + call lolcxxstl("and.l") +pat lil and sil $1==$3 && $2==4 &&inreg($1)==reg_pointer + call lilxxsil("and.l") +pat lil loc and sil $1==$4 && $3==4 && inreg($1)==reg_pointer + call lilcxxsil("and.l") +pat lol lol and stl $1==$4 && $3==4 && inreg($1)==reg_any && inreg($2)==reg_any + call lolrxxstl("and.l") +pat lil lol and sil $1==$4 && $3==4 && inreg($1)==reg_pointer && + inreg($2)==reg_any + call lilrxxsil("and.l") +pat lol ior stl $1==$3 && $2==4 && inreg($1)==reg_any + call lolxxstl("or.l") +pat lol loc ior stl $1==$4 && $3==4 && inreg($1)==reg_any + call lolcxxstl("or.l") +pat lil ior sil $1==$3 && $2==4 && inreg($1)==reg_pointer + call lilxxsil("or.l") +pat lil loc ior sil $1==$4 && $3==4 && inreg($1)==reg_pointer + call lilcxxsil("or.l") +pat lol lol ior stl $1==$4 && $3==4 && inreg($1)==reg_any && + inreg($2)==reg_any + call lolrxxstl("or.l") +pat lil lol ior sil $1==$4 && $3==4 && inreg($1)==reg_pointer && + inreg($2)==reg_any + call lilrxxsil("or.l") +pat lol xor stl $1==$3 && $2==4 && inreg($1)==reg_any + call lolxxstl("eor.l") +pat lol loc xor stl $1==$4 && $3==4 && inreg($1)==reg_any + call lolcxxstl("eor.l") +pat lil xor sil $1==$3 && $2==4 &&inreg($1)==reg_pointer + call lilxxsil("eor.l") +pat lil loc xor sil $1==$4 && $3==4 && inreg($1)==reg_pointer + call lilcxxsil("eor.l") +pat lol lol xor stl $1==$4 && $3==4 && inreg($1)==reg_any && + inreg($2)==reg_any + call lolrxxstl("eor.l") +pat lil lol xor sil $1==$4 && $3==4 && inreg($1)==reg_pointer && + inreg($2)==reg_any + call lilrxxsil("eor.l") + +pat lil adp sil $1==$3 && inreg($1)==reg_pointer + kills allexceptcon + gen add_l {const, $2}, {indirect4, regvar($1, reg_pointer)} + +pat lil lil adp sil $1==$2 && $1==$4 && inreg($1)==reg_pointer + kills allexceptcon + uses AA_REG = {indirect4, regvar($1, reg_pointer)} + gen add_l {const, $3}, {indirect4, regvar($1, reg_pointer)} + yields %a + +pat lol lol adp stl loi $1==$2 && $1==$4 && $3==1 && $5==1 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {post_inc1, regvar($1, reg_pointer)} + +pat lol loi lol adp stl $1==$3 && $1==$5 && $2==1 && $4==1 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {post_inc1, regvar($1, reg_pointer)} + +pat lol lol adp stl loi $1==$2 && $1==$4 && $3==2 && $5==2 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {post_inc2, regvar($1, reg_pointer)} + +pat lol loi lol adp stl $1==$3 && $1==$5 && $2==2 && $4==2 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {post_inc2, regvar($1, reg_pointer)} + +pat lol lol adp stl loi $1==$2 && $1==$4 && $3==4 && $5==4 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {post_inc4, regvar($1, reg_pointer)} + +pat lil lol adp stl $1==$2 && $1==$4 && $3==4 && inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {post_inc4, regvar($1, reg_pointer)} + +pat lol lol adp stl sti $1==$2 && $1==$4 && $3==1 && $5==1 && + inreg($1)==reg_pointer +with data1 + kills allexceptcon + gen move %1, {post_inc1, regvar($1, reg_pointer)} + +pat lol sti lol adp stl $1==$3 && $1==$5 && $2==1 && $4==1 && + inreg($1)==reg_pointer +with data1 + kills allexceptcon + gen move %1, {post_inc1, regvar($1, reg_pointer)} + +pat lol lol adp stl sti $1==$2 && $1==$4 && $3==2 && $5==2 && + inreg($1)==reg_pointer +with any2 + kills allexceptcon + gen move %1, {post_inc2, regvar($1, reg_pointer)} + +pat lol sti lol adp stl $1==$3 && $1==$5 && $2==2 && $4==2 && + inreg($1)==reg_pointer +with any2 + kills allexceptcon + gen move %1, {post_inc2, regvar($1, reg_pointer)} + +pat lol lol adp stl sti $1==$2 && $1==$4 && $3==4 && $5==4 && + inreg($1)==reg_pointer +with any4 + kills allexceptcon + gen move_l %1, {post_inc4, regvar($1, reg_pointer)} + +pat sil lol adp stl $1==$2 && $1==$4 && $3==4 && inreg($1)==reg_pointer +with any4 + kills allexceptcon + gen move_l %1, {post_inc4, regvar($1, reg_pointer)} + +pat lol adp stl lol loi $1==$3 && $1==$4 && $2==0-1 && $5==1 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {pre_dec1, regvar($1, reg_pointer)} + +pat lol adp stl lol loi $1==$3 && $1==$4 && $2==0-2 && $5==2 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {pre_dec2, regvar($1, reg_pointer)} + +pat lol adp stl lil $1==$3 && $1==$4 && $2==0-4 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {pre_dec4, regvar($1, reg_pointer)} + +pat lol adp stl lol sti $1==$3 && $1==$4 && $2==0-1 && $5==1 && + inreg($1)==reg_pointer +with data1 + kills allexceptcon + gen move %1, {pre_dec1, regvar($1, reg_pointer)} + +pat lol adp stl lol sti $1==$3 && $1==$4 && $2==0-2 && $5==2 && + inreg($1)==reg_pointer +with any2 + kills allexceptcon + gen move %1, {pre_dec2, regvar($1, reg_pointer)} + +pat lol adp stl sil $1==$3 && $1==$4 && $2==0-4 && + inreg($1)==reg_pointer +with any4 + kills allexceptcon + gen move_l %1, {pre_dec4, regvar($1, reg_pointer)} + + + + +/************************************************ + * Group 1: load instructions * + ************************************************/ + +pat loc yields {const, $1} + +pat ldc leaving loc 18 trp + +pat lol yields {LOCAL, $1} + +pat ldl leaving lol $1+4 lol $1 + +pat loe yields {absolute4, $1} + +pat lil +#ifdef m68020 + yields {ILOCAL, $1} +#else m68020 + uses AA_REG = {LOCAL, $1} + yields {indirect4, %a} +#endif m68020 + + /* When using the 'offsetted' intructions regAregXcon cannot be used + * for the m68k4; there is no way of knowing about the size of + * %1.bd+$1, because expressions are not allowed in stack patterns, and + * this may lead to outputting too large displacements. With regAcon + * the chance that this will happen is very slim, because it can + * have displacements of 16 bits. Besides, leaving out regAcon here + * would make it very hard to handle this instruction efficiently. + */ +pat lof +with A_REG yields {offsetted4, %1, $1} +with exact local_addr yields {LOCAL, %1.bd+$1} +with exact ext_addr yields {absolute4, %1.bd+$1} +#ifndef m68020 +with regAcon yields {offsetted4, %1.reg, %1.bd+$1} +#else m68020 +with exact regAcon yields {offsetted4, %1.reg, %1.bd+$1} +with exact regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1} +with exact offsetted4 yields {OFF_off4, %1.reg, %1.bd, $1} +with exact indirect yields {OFF_off4, %1.reg, 0, $1} +with exact LOCAL yields {OFF_off4, lb, %1.bd, $1} +with exact off_con yields {OFF_off4, %1.reg, %1.bd, %1.od+$1} +with exact off_regXcon yields {OFF_indoff4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact index_off4 yields {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, $1} +with exact indoff_con yields {INDOFF_off4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact absolute4 yields {ABS_off4, %1.bd, $1} +with exact abs_con yields {ABS_off4, %1.bd, %1.od+$1} +with exact abs_regXcon yields {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact abs_index4 yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, $1} +with exact absind_con yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact ext_regX yields {abs_index4, %1.sc, %1.xreg, %1.bd+$1} +#endif m68020 + +pat lal yields {local_addr, $1} + +pat lae yields {ext_addr, $1} + +pat lxl $1==0 yields lb + +pat lxl $1==1 yields {LOCAL, SL} + +pat lxl $1==2 +#ifdef m68020 + yields {OFF_off4, lb, SL, SL} +#else m68020 + uses AA_REG = {LOCAL, SL} + yields {offsetted4, %a, SL} +#endif m68020 + +pat lxl $1==3 +#ifdef m68020 + uses AA_REG = {OFF_off4, lb, SL, SL} +#else m68020 + uses AA_REG = {LOCAL, SL} + gen move {offsetted4, %a, SL}, %a +#endif m68020 + yields {offsetted4, %a, SL} + +pat lxl $1>3 + uses AA_REG = {LOCAL, SL}, + DD_REG = {const, $1-2} + gen 1: + move_l {offsetted4, %a, SL} ,%a + dbf %b, {slabel, 1b} + yields %a + +pat lxa $1==0 yields {local_addr, SL} + +pat lxa $1==1 +#ifdef m68020 + yields {off_con, lb, SL, SL} +#else m68020 + uses AA_REG = {LOCAL, SL} + yields {regAcon, %a, SL} +#endif m68020 + +pat lxa $1==2 +#ifdef m68020 + uses AA_REG = {OFF_off4, lb, SL, SL} +#else m68020 + uses AA_REG = {LOCAL, SL} + gen move {offsetted4, %a, SL}, %a +#endif m68020 + yields {regAcon, %a, SL} + +pat lxa $1>2 + uses AA_REG = {LOCAL, SL}, + DD_REG = {const, $1-1} + gen 1: + move_l {offsetted4, %a, SL} ,%a + dbf %b, {slabel, 1b} + yields {regAcon, %a, SL} + +pat loi $1==1 +with A_REG yields {indirect1, %1} +with exact local_addr yields {offsetted1, lb, %1.bd} +with exact ext_addr yields {absolute1, %1.bd} +#ifndef m68020 +with regAcon yields {offsetted1, %1.reg, %1.bd} +with regAregXcon yields {index_off1, %1.reg, %1.xreg, %1.sc, %1.bd} +#else m68020 +with exact regAcon yields {offsetted1, %1.reg, %1.bd} +with exact regAregXcon yields {index_off1, %1.reg, %1.xreg, %1.sc, %1.bd} +with exact indirect4 yields {OFF_off1, %1.reg, 0, 0} +with exact offsetted4 yields {OFF_off1, %1.reg, %1.bd, 0} +with exact LOCAL yields {OFF_off1, lb, %1.bd, 0} +with exact off_con yields {OFF_off1, %1.reg, %1.bd, %1.od} +with exact off_regXcon yields {OFF_indoff1, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact index_off4 yields {INDOFF_off1, %1.reg, %1.xreg, %1.sc, %1.bd, 0} +with exact indoff_con yields {INDOFF_off1, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact absolute4 yields {ABS_off1, %1.bd, 0} +with exact abs_con yields {ABS_off1, %1.bd, %1.od} +with exact abs_regXcon yields {ABS_indoff1, %1.sc, %1.xreg, %1.bd, %1.od} +with exact abs_index4 yields {ABSIND_off1, %1.sc, %1.xreg, %1.bd, 0} +with exact absind_con yields {ABSIND_off1, %1.sc, %1.xreg, %1.bd, %1.od} +with exact ext_regX yields {abs_index1, %1.sc, %1.xreg, %1.bd} +#endif m68020 + +pat loi $1==2 +with A_REG yields {indirect2, %1} +with exact local_addr yields {offsetted2, lb, %1.bd} +with exact ext_addr yields {absolute2, %1.bd} +#ifndef m68020 +with regAcon yields {offsetted2, %1.reg, %1.bd} +with regAregXcon yields {index_off2, %1.reg, %1.xreg, %1.sc, %1.bd} +#else m68020 +with exact regAcon yields {offsetted2, %1.reg, %1.bd} +with exact regAregXcon yields {index_off2, %1.reg, %1.xreg, %1.sc, %1.bd} +with exact indirect4 yields {OFF_off2, %1.reg, 0, 0} +with exact offsetted4 yields {OFF_off2, %1.reg, %1.bd, 0} +with exact LOCAL yields {OFF_off2, lb, %1.bd, 0} +with exact off_con yields {OFF_off2, %1.reg, %1.bd, %1.od} +with exact off_regXcon yields {OFF_indoff2, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact index_off4 yields {INDOFF_off2, %1.reg, %1.xreg, %1.sc, %1.bd, 0} +with exact indoff_con yields {INDOFF_off2, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact absolute4 yields {ABS_off2, %1.bd, 0} +with exact abs_con yields {ABS_off2, %1.bd, %1.od} +with exact abs_regXcon yields {ABS_indoff2, %1.sc, %1.xreg, %1.bd, %1.od} +with exact abs_index4 yields {ABSIND_off2, %1.sc, %1.xreg, %1.bd, 0} +with exact absind_con yields {ABSIND_off2, %1.sc, %1.xreg, %1.bd, %1.od} +with exact ext_regX yields {abs_index2, %1.sc, %1.xreg, %1.bd} +#endif m68020 + +pat loi $1==4 +with A_REG yields {indirect4, %1} +with exact local_addr yields {LOCAL, %1.bd} +with exact ext_addr yields {absolute4, %1.bd} +#ifndef m68020 +with regAcon yields {offsetted4, %1.reg, %1.bd} +with regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd} +#else m68020 +with exact regAcon yields {offsetted4, %1.reg, %1.bd} +with exact regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd} +with exact LOCAL yields {ILOCAL, %1.bd} +with exact indirect4 yields {OFF_off4, %1.reg, 0, 0} +with exact offsetted4 yields {OFF_off4, %1.reg, %1.bd, 0} +with exact off_con yields {OFF_off4, %1.reg, %1.bd, %1.od} +with exact off_regXcon yields {OFF_indoff4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact index_off4 yields {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, 0} +with exact indoff_con yields {INDOFF_off4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact absolute4 yields {ABS_off4, %1.bd, 0} +with exact abs_con yields {ABS_off4, %1.bd, %1.od} +with exact abs_regXcon yields {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od} +with exact abs_index4 yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, 0} +with exact absind_con yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od} +with exact ext_regX yields {abs_index4, %1.sc, %1.xreg, %1.bd} +#endif m68020 + +pat loi $1==8 +with A_REG yields {offsetted4, %1, 4} + {indirect4, %1} +pat loi $1>8 +with AA_REG STACK + uses DD_REG = {const, $1/4 -1} + gen add_l {const, $1}, %1 + 1: + move_l {pre_dec4, %1}, {pre_dec4, sp} + dbf %a, {slabel, 1b} + +pat los $1==4 +with STACK + gen jsr {absolute4, ".los"} + +pat lde yields {absolute4, $1+4} + {absolute4, $1} + +pat ldf +with A_REG yields {offsetted4, %1, $1+4} + {offsetted4, %1, $1} +with exact local_addr yields {LOCAL, %1.bd+$1+4} + {LOCAL, %1.bd+$1} +with exact ext_addr yields {absolute4, %1.bd+$1+4} + {absolute4, %1.bd+$1} +#ifndef m68020 +with regAcon yields {offsetted4, %1.reg, %1.bd+$1+4} + {offsetted4, %1.reg, %1.bd+$1} +#else m68020 +with exact regAcon yields {offsetted4, %1.reg, %1.bd+$1+4} + {offsetted4, %1.reg, %1.bd+$1} +with exact regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1+4} + {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1} +with exact indirect4 yields {OFF_off4, %1.reg, 0, $1+4} + {OFF_off4, %1.reg, 0, $1} +with exact offsetted4 yields {OFF_off4, %1.reg, %1.bd, $1+4} + {OFF_off4, %1.reg, %1.bd, $1} +with exact LOCAL yields {OFF_off4, lb, %1.bd, $1+4} + {OFF_off4, lb, %1.bd, $1} +with exact off_con yields {OFF_off4, %1.reg, %1.bd, %1.od+$1+4} + {OFF_off4, %1.reg, %1.bd, %1.od+$1} +with exact off_regXcon yields {OFF_indoff4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1+4} + {OFF_indoff4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact index_off4 yields {INDOFF_off4, %1.reg, %1.xreg, %1.sc,%1.bd,$1+4} + {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, $1} +with exact indoff_con yields {INDOFF_off4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1+4} + {INDOFF_off4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact absolute4 yields {ABS_off4, %1.bd, $1+4} + {ABS_off4, %1.bd, $1} +with exact abs_con yields {ABS_off4, %1.bd, %1.od+$1+4} + {ABS_off4, %1.bd, %1.od+$1} +with exact abs_regXcon yields {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od+$1+4} + {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact abs_index4 yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, $1+4} + {ABSIND_off4, %1.sc, %1.xreg, %1.bd, $1} +with exact absind_con yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1+4} + {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact ext_regX yields {abs_index4, %1.sc, %1.xreg, %1.bd+$1+4} + {abs_index4, %1.sc, %1.xreg, %1.bd+$1} +#endif m68020 + +pat lpi yields {ext_addr, $1} + + + +/************************************************ + * Group 2: store instructions * + ************************************************/ + +pat stl +with any4 + kills all_indir, LOCAL %bd==$1 + gen move %1, {LOCAL, $1} +with exact STACK + gen move {post_inc4,sp}, {LOCAL, $1} + +pat ste +with any4 + kills posextern + gen move %1, {absolute4, $1} +with exact STACK + gen move {post_inc4, sp}, {absolute4, $1} + +pat sil +#ifdef m68020 +with any4 + kills allexceptcon + gen move %1, {ILOCAL, $1} +with exact STACK + gen move {post_inc4, sp}, {ILOCAL, $1} +#else m68020 +with any4 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen move %1, {indirect4, %a} +with exact STACK + uses AA_REG = {LOCAL, $1} + gen move {post_inc4, sp}, {indirect4, %a} +#endif m68020 + +pat stf +with A_REG any4 + kills allexceptcon + gen move %2, {offsetted4, %1, $1} +with A_REG STACK + gen move {post_inc4, sp}, {offsetted4, %1, $1} +with exact local_addr any4 + kills allexceptcon + gen move %2, {LOCAL, %1.bd+$1} +with exact ext_addr any4 + kills allexceptcon + gen move %2, {absolute4, %1.bd+$1} +#ifndef m68020 +with regAcon any4 + kills allexceptcon + gen move %2, {offsetted4, %1.reg, %1.bd+$1} +#else m68020 +with exact regAcon any4 + kills allexceptcon + gen move %2, {offsetted4, %1.reg, %1.bd+$1} +with exact regAregXcon any4 + kills allexceptcon + gen move %2, {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1} +with exact indirect4 any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, 0, $1} +with exact offsetted4 any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, %1.bd, $1} +with exact LOCAL any4 + kills allexceptcon + gen move %2, {OFF_off4, lb, %1.bd, $1} +with exact off_con any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, %1.bd, %1.od+$1} +with exact off_regXcon any4 + kills allexceptcon + gen move %2, {OFF_indoff4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact index_off4 any4 + kills allexceptcon + gen move %2, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, $1} +with exact indoff_con any4 + kills allexceptcon + gen move %2, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact absolute4 any4 + kills allexceptcon + gen move %2, {ABS_off4, %1.bd, $1} +with exact abs_con any4 + kills allexceptcon + gen move %2, {ABS_off4, %1.bd, %1.od+$1} +with exact abs_regXcon any4 + kills allexceptcon + gen move %2, {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact abs_index4 any4 + kills allexceptcon + gen move %2, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, $1} +with exact absind_con any4 + kills allexceptcon + gen move %2, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact ext_regX any4 + kills allexceptcon + gen move %2, {abs_index4, %1.sc, %1.xreg, %1.bd+$1} +#endif m68020 + +pat sti $1==1 +with A_REG data1 + kills allexceptcon + gen move %2, {indirect1, %1} +with exact local_addr data1 + kills allexceptcon + gen move %2, {offsetted1, lb, %1.bd} +with exact ext_addr data1 + kills allexceptcon + gen move %2, {absolute1, %1.bd} +#ifndef m68020 +with regAcon data1 + kills allexceptcon + gen move %2, {offsetted1, %1.reg, %1.bd} +with regAregXcon data1 + kills allexceptcon + gen move %2, {index_off1, %1.reg, %1.xreg, %1.sc, %1.bd} +#else m68020 +with exact regAcon data1 + kills allexceptcon + gen move %2, {offsetted1, %1.reg, %1.bd} +with exact regAregXcon data1 + kills allexceptcon + gen move %2, {index_off1, %1.reg, %1.xreg, %1.sc, %1.bd} +with exact indirect4 data1 + kills allexceptcon + gen move %2, {OFF_off1, %1.reg, 0, 0} +with exact offsetted4 data1 + kills allexceptcon + gen move %2, {OFF_off1, %1.reg, %1.bd, 0} +with exact LOCAL data1 + kills allexceptcon + gen move %2, {OFF_off1, lb, %1.bd, 0} +with exact off_con data1 + kills allexceptcon + gen move %2, {OFF_off1, %1.reg, %1.bd, %1.od} +with exact off_regXcon data1 + kills allexceptcon + gen move %2, {OFF_indoff1, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact index_off4 data1 + kills allexceptcon + gen move %2, {INDOFF_off1, %1.reg, %1.xreg, %1.sc, %1.bd, 0} +with exact indoff_con data1 + kills allexceptcon + gen move %2, {INDOFF_off1, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact absolute4 data1 + kills allexceptcon + gen move %2, {ABS_off1, %1.bd, 0} +with exact abs_con data1 + kills allexceptcon + gen move %2, {ABS_off1, %1.bd, %1.od} +with exact abs_regXcon data1 + kills allexceptcon + gen move %2, {ABS_indoff1, %1.sc, %1.xreg, %1.bd, %1.od} +with exact abs_index4 data1 + kills allexceptcon + gen move %2, {ABSIND_off1, %1.sc, %1.xreg, %1.bd, 0} +with exact absind_con data1 + kills allexceptcon + gen move %2, {ABSIND_off1, %1.sc, %1.xreg, %1.bd, %1.od} +with exact ext_regX data1 + kills allexceptcon + gen move %2, {abs_index1, %1.sc, %1.xreg, %1.bd} +#endif m68020 + +pat sti $1==2 +with A_REG any2 + kills allexceptcon + gen move %2, {indirect2, %1} +with exact local_addr any2 + kills allexceptcon + gen move %2, {offsetted2, lb, %1.bd} +with exact ext_addr any2 + kills allexceptcon + gen move %2, {absolute2, %1.bd} +#ifndef m68020 +with regAcon any2 + kills allexceptcon + gen move %2, {offsetted2, %1.reg, %1.bd} +with regAregXcon any2 + kills allexceptcon + gen move %2, {index_off2, %1.reg, %1.xreg, %1.sc, %1.bd} +#else m68020 +with exact regAcon any2 + kills allexceptcon + gen move %2, {offsetted2, %1.reg, %1.bd} +with exact regAregXcon any2 + kills allexceptcon + gen move %2, {index_off2, %1.reg, %1.xreg, %1.sc, %1.bd} +with exact indirect4 any2 + kills allexceptcon + gen move %2, {OFF_off2, %1.reg, 0, 0} +with exact offsetted4 any2 + kills allexceptcon + gen move %2, {OFF_off2, %1.reg, %1.bd, 0} +with exact LOCAL any2 + kills allexceptcon + gen move %2, {OFF_off2, lb, %1.bd, 0} +with exact off_con any2 + kills allexceptcon + gen move %2, {OFF_off2, %1.reg, %1.bd, %1.od} +with exact index_off4 any2 + kills allexceptcon + gen move %2, {INDOFF_off2, %1.reg, %1.xreg, %1.sc, %1.bd, 0} +with exact off_regXcon any2 + kills allexceptcon + gen move %2, {OFF_indoff2, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact indoff_con any2 + kills allexceptcon + gen move %2, {INDOFF_off2, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact absolute4 any2 + kills allexceptcon + gen move %2, {ABS_off2, %1.bd, 0} +with exact abs_con any2 + kills allexceptcon + gen move %2, {ABS_off2, %1.bd, %1.od} +with exact abs_regXcon any2 + kills allexceptcon + gen move %2, {ABS_indoff2, %1.sc, %1.xreg, %1.bd, %1.od} +with exact abs_index4 any2 + kills allexceptcon + gen move %2, {ABSIND_off2, %1.sc, %1.xreg, %1.bd, 0} +with exact absind_con any2 + kills allexceptcon + gen move %2, {ABSIND_off2, %1.sc, %1.xreg, %1.bd, %1.od} +with exact ext_regX any2 + kills allexceptcon + gen move %2, {abs_index2, %1.sc, %1.xreg, %1.bd} +#endif m68020 + +pat sti $1==4 +with A_REG any4 + kills allexceptcon + gen move %2, {indirect4, %1} +with A_REG STACK + gen move {post_inc4, sp}, {indirect4, %1} +with exact local_addr any4 + kills allexceptcon + gen move %2, {LOCAL, %1.bd} +with exact ext_addr any4 + kills allexceptcon + gen move %2, {absolute4, %1.bd} +#ifndef m68020 +with regAcon any4 + kills allexceptcon + gen move %2, {offsetted4, %1.reg, %1.bd} +with regAregXcon any4 + kills allexceptcon + gen move %2, {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd} +#else m68020 +with exact regAcon any4 + kills allexceptcon + gen move %2, {offsetted4, %1.reg, %1.bd} +with exact regAregXcon any4 + kills allexceptcon + gen move %2, {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd} +with exact LOCAL any4 + kills allexceptcon + gen move %2, {ILOCAL, %1.bd} +with exact indirect4 any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, 0, 0} +with exact offsetted4 any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, %1.bd, 0} +with exact off_con any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, %1.bd, %1.od} +with exact off_regXcon any4 + kills allexceptcon + gen move %2, {OFF_indoff4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact index_off4 any4 + kills allexceptcon + gen move %2, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, 0} +with exact indoff_con any4 + kills allexceptcon + gen move %2, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact absolute4 any4 + kills allexceptcon + gen move %2, {ABS_off4, %1.bd, 0} +with exact abs_con any4 + kills allexceptcon + gen move %2, {ABS_off4, %1.bd, %1.od} +with exact abs_regXcon any4 + kills allexceptcon + gen move %2, {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od} +with exact abs_index4 any4 + kills allexceptcon + gen move %2, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, 0} +with exact absind_con any4 + kills allexceptcon + gen move %2, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od} +with exact ext_regX any4 + kills allexceptcon + gen move %2, {abs_index4, %1.sc, %1.xreg, %1.bd} +#endif m68020 + +pat sti $1>4 +with AA_REG STACK + uses DD_REG = {const, $1/4 -1} + gen 1: + move_l {post_inc4, sp}, {post_inc4, %1} + dbf %a, {slabel, 1b} + +pat sts $1==4 +with STACK + gen jsr {absolute4, ".sts"} + +pat sdl +with any4 any4 + kills all_indir, LOCAL %bd==$1 + gen move %1, {LOCAL, $1} + move %2, {LOCAL, $1+4} + +pat sde +with any4 any4 + kills posextern + gen move %1, {absolute4, $1} + move %2, {absolute4, $1+4} + +pat sdf +with A_REG any4 any4 + kills allexceptcon + gen move %2, {offsetted4, %1, $1} + move %3, {offsetted4, %1, $1+4} +with exact local_addr any4 any4 + kills allexceptcon + gen move %2, {LOCAL, %1.bd+$1} + move %3, {LOCAL, %1.bd+$1+4} +with exact ext_addr any4 any4 + kills allexceptcon + gen move %2, {absolute4, %1.bd+$1} + move %3, {absolute4, %1.bd+$1+4} +#ifndef m68020 +with regAcon any4 any4 + kills allexceptcon + gen move %2, {offsetted4, %1.reg, %1.bd+$1} + move %3, {offsetted4, %1.reg, %1.bd+$1+4} +#else m68020 +with exact regAcon any4 any4 + kills allexceptcon + gen move %2, {offsetted4, %1.reg, %1.bd+$1} + move %3, {offsetted4, %1.reg, %1.bd+$1+4} +with exact regAregXcon any4 any4 + kills allexceptcon + gen move %2, {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1} + move %3, {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1+4} +with exact indirect4 any4 any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, 0, $1} + move %3, {OFF_off4, %1.reg, 0, $1+4} +with exact offsetted4 any4 any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, %1.bd, $1} + move %3, {OFF_off4, %1.reg, %1.bd, $1+4} +with exact LOCAL any4 any4 + kills allexceptcon + gen move %2, {OFF_off4, lb, %1.bd, $1} + move %3, {OFF_off4, lb, %1.bd, $1+4} +with exact off_con any4 any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, %1.bd, %1.od+$1} + move %3, {OFF_off4, %1.reg, %1.bd, %1.od+$1+4} +with exact off_regXcon any4 any4 + kills allexceptcon + gen move %2, {OFF_indoff4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} + move %3, {OFF_indoff4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1+4} +with exact index_off4 any4 any4 + kills allexceptcon + gen move %2, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, $1} + move %3, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, $1+4} +with exact indoff_con any4 any4 + kills allexceptcon + gen move %2, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} + move %3, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1+4} +with exact absolute4 any4 any4 + kills allexceptcon + gen move %2, {ABS_off4, %1.bd, $1} + move %3, {ABS_off4, %1.bd, $1+4} +with exact abs_con any4 any4 + kills allexceptcon + gen move %2, {ABS_off4, %1.bd, %1.od+$1} + move %3, {ABS_off4, %1.bd, %1.od+$1+4} +with exact abs_regXcon any4 any4 + kills allexceptcon + gen move %2, {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od+$1} + move %3, {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od+$1+4} +with exact abs_index4 any4 any4 + kills allexceptcon + gen move %2, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, $1} + move %3, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, $1+4} +with exact absind_con any4 any4 + kills allexceptcon + gen move %2, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1} + move %3, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1+4} +with exact ext_regX any4 any4 + kills allexceptcon + gen move %2, {abs_index4, %1.sc, %1.xreg, %1.bd+$1} + move %3, {abs_index4, %1.sc, %1.xreg, %1.bd+$1+4} +#endif m68020 + + + +/************************************************ + * Group 3: integer arithmetic. * + ************************************************/ + + +pat adi $1==4 +with any4 DD_REG + gen add_l %1, %2 yields %2 +with DD_REG any4-DD_REG + gen add_l %2, %1 yields %1 +with DD_REG STACK + gen add_l {post_inc4, sp}, %1 + yields %1 + +pat sbi $1==4 +with any4 DD_REG + gen sub_l %1, %2 yields %2 +with DD_REG any4-DD_REG + gen sub_l %2, %1 + neg_l %1 yields %1 +with DD_REG STACK + gen sub_l {post_inc4, sp}, %1 + neg_l %1 yields %1 +with any4 AA_REG + gen sub_l %1, %2 yields %2 + +pat mli $1==4 +#ifdef m68020 +with data4 DD_REG + gen muls_l %1, %2 yields %2 +#else m68020 +with STACK + gen jsr {absolute4, ".mli"} + yields d1 +#endif m68020 + +pat dvi $1==4 +#ifdef m68020 +with data4 DD_REG + gen divs_l %1, %2 yields %2 +#else m68020 +with STACK + gen jsr {absolute4, ".dvi"} + yields d1 +#endif m68020 + +pat rmi $1==4 +#ifdef m68020 +with data4 DD_REG + uses DD_REG + gen divsl_l %1, {DREG_pair, %a, %2} + killreg %2 + /* !!!! contents of %2 have changed: make this known to cg */ + yields %a +#else m68020 +with STACK + gen jsr {absolute4, ".dvi"} + yields d0 +#endif m68020 + +pat ngi $1==4 +with DD_REG + gen neg_l %1 yields %1 + +pat sli $1==4 +with D_REG DD_REG + gen asl_l %1, %2 yields %2 + +pat sri $1==4 +with D_REG DD_REG + gen asr_l %1, %2 yields %2 + + + +/************************************************ + * Group 4: unsigned arithmetic. * + ************************************************/ + + +pat adu leaving adi $1 + +pat sbu leaving sbi $1 + +pat mlu $1==4 +#ifdef m68020 +with data4 DD_REG + gen mulu_l %1, %2 yields %2 +#else m68020 +with STACK + gen jsr {absolute4, ".mlu"} + yields d1 +#endif m68020 + +pat dvu $1==4 +#ifdef m68020 +with data4 DD_REG + gen divu_l %1, %2 yields %2 +#else m68020 +with STACK + gen jsr {absolute4, ".dvu"} + yields d1 +#endif m68020 + +pat rmu $1==4 +#ifdef m68020 +with data4 DD_REG + uses DD_REG + gen divul_l %1, {DREG_pair, %a, %2} + killreg %2 + /* !!!! contents of %2 have changed: make this known to cg */ + yields %a +#else m68020 +with STACK + gen jsr {absolute4, ".dvu"} + yields d0 +#endif m68020 + +pat slu leaving sli $1 + +pat sru $1==4 +with D_REG DD_REG + gen lsr_l %1, %2 yields %2 + + + +/************************************************ + * Group 5: floating point arithmetic * + * * + * is not available on 68000, 68010 or 68020 * + * so traps will be generated * + ************************************************/ + +pat adf leaving loc 18 trp +pat sbf leaving loc 18 trp +pat mlf leaving loc 18 trp +pat dvf leaving loc 18 trp +pat ngf leaving loc 18 trp +pat fif leaving loc 18 trp +pat fef leaving loc 18 trp + + + +/************************************************ + * Group 6: pointer arithmetic * + ************************************************/ + +pat adp $1==0 /* skip; array instructions might 'leave' this */ + +pat adp +with A_REG yields {t_regAcon, %1, $1} +with exact local_addr yields {local_addr, %1.bd+$1} +with exact ext_addr yields {ext_addr, %1.bd+$1} +with exact regAcon + t_regAcon + yields {t_regAcon, %1.reg, %1.bd+$1} +with exact regAregXcon + t_regAregXcon + yields {t_regAregXcon,%1.reg, %1.xreg, %1.sc, %1.bd+$1} +#ifdef m68020 +with exact indirect4 yields {off_con, %1.reg, 0, $1} +with exact LOCAL yields {off_con, lb, %1.bd, $1} +with exact offsetted4 yields {off_con, %1.reg, %1.bd, $1} +with exact off_con yields {off_con, %1.reg, %1.bd, %1.od+$1} +with exact off_regXcon yields {off_regXcon, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact index_off4 yields {indoff_con, %1.reg, %1.xreg, %1.sc, %1.bd, $1} +with exact indoff_con yields {indoff_con, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact absolute4 yields {abs_con, %1.bd, $1} +with exact abs_con yields {abs_con, %1.bd, %1.od+$1} +with exact abs_regXcon yields {abs_regXcon, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact abs_index4 yields {absind_con, %1.sc, %1.xreg, %1.bd, $1} +with exact absind_con yields {absind_con, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact ext_regX yields {ext_regX, %1.sc, %1.xreg, %1.bd+$1} +#endif m68020 + +pat ads $1==4 +with D_REG A_REG yields {regAregXcon, %2, %1, 1, 0} +with D_REG regAcon + t_regAcon + yields {t_regAregXcon, %2.reg, %1, 1, %2.bd} +with D_REG local_addr yields {t_regAregXcon, lb, %1, 1, %2.bd} +with any4-D_REG AA_REG + gen add_l %1, %2 yields %2 + +#ifdef m68020 + +with D_REG yields {regX, 1, %1} + leaving ads 4 +with regX A_REG yields {regAregXcon, %2, %1.xreg, %1.sc, 0} +with exact regX regAcon yields {regAregXcon, %2.reg, %1.xreg, %1.sc, %2.bd} +with exact regX local_addr + yields {regAregXcon, lb, %1.xreg, %1.sc, %2.bd} +with exact regX ext_addr + yields {ext_regX, %1.sc, %1.xreg, %2.bd} +with exact regX indirect4 + yields {off_regXcon, %2.reg, %1.xreg,%1.sc,0,0} +with exact regX offsetted4 + yields {off_regXcon, %2.reg, %1.xreg, %1.sc, %2.bd, 0} +with exact regX LOCAL yields {off_regXcon, lb, %1.xreg, %1.sc, %2.bd, 0} +with exact regX off_con yields {off_regXcon, %2.reg, %1.xreg,%1.sc,%2.bd,%2.od} +with exact regX absolute4 + yields {abs_regXcon, %1.sc, %1.xreg, %2.bd, 0} +with exact regX abs_con yields {abs_regXcon, %1.sc, %1.xreg, %2.bd, %2.od} +with exact indirect4 ext_addr + yields {off_con, %1.reg, 0, %2.bd} +with exact offsetted4 ext_addr + yields {off_con, %1.reg, %1.bd, %2.bd} +with exact LOCAL ext_addr + yields {off_con, lb, %1.bd, %2.bd} +with exact index_off4 ext_addr + yields {indoff_con, %1.reg, %1.xreg, %1.sc,%1.bd,%2.bd} +with exact absolute4 ext_addr + yields {abs_con, %1.bd, %2.bd} +with exact abs_index4 ext_addr + yields {absind_con, %1.sc, %1.xreg, %1.bd, %2.bd} +with exact indirect4 ext_regX + yields {off_regXcon, %1.reg, %2.xreg, %2.sc, 0, %2.bd} +with exact offsetted4 ext_regX + yields {off_regXcon, %1.reg, %2.xreg,%2.sc,%1.bd,%2.bd} +with exact LOCAL ext_regX + yields {off_regXcon, lb, %2.xreg, %2.sc, %1.bd, %2.bd} +with exact absolute4 ext_regX + yields {abs_regXcon, %2.sc, %2.xreg, %1.bd, %2.bd} +#endif m68020 + + /* I WOULD ALSO LIKE THIS: + * pat ads + * with const leaving adp %1.num + * BUT THAT DOESN'T WORK. + */ + +pat sbs $1==4 leaving sbi 4 + +#ifdef m68020 +pat loc sli ads $1==1 && $2==4 && $3==4 +with D_REG yields {regX, 2, %1} + leaving ads 4 + +pat loc sli ads $1==2 && $2==4 && $3==4 +with D_REG yields {regX, 4, %1} + leaving ads 4 + +pat loc sli ads $1==3 && $2==4 && $3==4 +with D_REG yields {regX, 8, %1} + leaving ads 4 +#endif m68020 + + +/************************************************ + * Group 7: increment / decrement / zero * + ************************************************/ + +pat inc +with exact STACK + gen add_l {const, 1}, {indirect4, sp} +with DD_REG+AA_REG + gen add_l {const, 1}, %1 + yields %1 + +pat inl + kills all_indir, LOCAL %bd==$1 + gen add_l {const, 1}, {LOCAL, $1} + +pat ine + kills posextern + gen add_l {const, 1}, {absolute4, $1} + +pat dec +with exact STACK + gen sub_l {const, 1}, {indirect4, sp} +with DD_REG+AA_REG + gen sub_l {const, 1}, %1 + yields %1 + +pat del + kills all_indir, LOCAL %bd==$1 + gen sub_l {const, 1}, {LOCAL, $1} + +pat dee + kills posextern + gen sub_l {const, 1}, {absolute4, $1} + +pat zrl + kills all_indir, LOCAL %bd==$1 + gen clr_l {LOCAL, $1} + +pat zre + kills posextern + gen clr_l {absolute4, $1} + +pat zer $1==4 yields {const, 0} +pat zer $1==8 yields {const, 0} {const, 0} +pat zer $1==12 yields {const, 0} {const, 0} {const, 0} + +pat zer +with STACK + uses DD_REG = {const, $1/4 -1} + gen 1: + clr_l {pre_dec4, sp} + dbf %a, {slabel, 1b} + + +pat zrf leaving loc 18 trp + + + +/************************************************ + * Group 8: convert instructions * + * for float conversions traps are generated * + ************************************************/ + + + +pat cii +with STACK + gen jsr {absolute4, ".cii"} + +pat cuu +with STACK + gen jsr {absolute4, ".cuu"} + +pat ciu leaving cuu + +pat cui leaving cuu + +pat cfi leaving loc 18 trp +pat cif leaving loc 18 trp +pat cfu leaving loc 18 trp +pat cuf leaving loc 18 trp +pat cff leaving loc 18 trp + + +/************************************************ + * Group 9: logical instructions * + ************************************************/ + + +proc log4 +with datalt4+const DD_REG + gen xxx* %1, %2 yields %2 +with DD_REG datalt4+const + gen xxx* %2, %1 yields %1 + +proc logdef example and +with STACK + uses DD_REG = {const, $1/4 -1}, + AA_REG = {regAcon, sp, $1}, + DD_REG + gen 1: + move_l {post_inc4, sp}, %c + xxx* %c, {post_inc4, %b} + dbf %a, {slabel, 1b} + +proc logndef +with DD_REG STACK + uses AA_REG = {regAregXcon, sp, %1, 1, 0}, + DD_REG + gen asr_l {shconst, 2}, %1 + sub_l {const, 1}, %1 + 1: + move_l {post_inc4, sp}, %b + xxx* %b, {post_inc4, %a} + dbf %1, {slabel, 1b} + +pat and $1==4 call log4("and.l") +pat and $1>4 call logdef("and.l") +pat and !defined($1) call logndef("and.l") +pat ior $1==4 call log4("or.l") +pat ior $1>4 call logdef("or.l") +pat ior !defined($1) call logndef("or.l") + +pat xor $1==4 +with conreg4 DD_REG + gen eor_l %1, %2 yields %2 +with DD_REG conreg4 + gen eor_l %2, %1 yields %1 + +pat xor $1>4 call logdef("eor.l") +pat xor !defined($1) call logndef("eor.l") + +pat com $1==4 +with DD_REG + gen not_l %1 yields %1 + +pat com $1==8 +with DD_REG DD_REG + gen not_l %1 + not_l %2 yields %2 %1 + +pat com $1>4 +with STACK + uses AA_REG, + DD_REG = {const, $1/4 -1} + gen move_l sp, %a + 1: + not_l {post_inc4, %a} + dbf %b, {slabel, 1b} + +pat com !defined($1) +with DD_REG STACK + uses AA_REG + gen move_l sp, %a + asr_l {shconst, 2}, %1 + sub_l {const, 1}, %1 + 1: + not_l {post_inc4, %a} + dbf %1, {slabel, 1b} + +pat rol $1==4 +with D_REG DD_REG + gen rol_l %1, %2 yields %2 + +pat ror $1==4 +with D_REG DD_REG + gen ror_l %1, %2 yields %2 + + + + +/************************************************ + * Group 10: sets * + ************************************************/ + + +pat inn $1==4 +with conreg2 DD_REG + gen btst %1, %2 + sne %2 + and_l {const, 1}, %2 + yields %2 + +pat inn defined($1) +with any4 STACK + gen move %1, d0 + move {const, $1}, d1 + jsr {absolute4, ".inn"} + yields d0 + +pat inn !defined($1) +with any4 any4 STACK + gen move %2, d0 + move %1, d1 + jsr {absolute4, ".inn"} + yields d0 + +pat loc inn $2==4 && small($1) +with DD_REG + gen asr_l {shconst, $1}, %1 + and_l {const, 1}, %1 + yields %1 + +pat set $1==4 +with conreg2 + uses DD_REG = {const, 0} + gen bset %1, %a yields %a + +pat set $1>4 +with any4 STACK + gen move %1, d0 + move {const, $1}, d1 + jsr {absolute4, ".set"} + +pat set !defined($1) +with any4 any4 STACK + gen move %2, d0 + move %1, d1 + jsr {absolute4, ".set"} + + + + +/************************************************ + * Group 11: arrays * + ************************************************/ + + +pat lar defined($1) +with STACK + gen move {const, $1}, d0 + jsr {absolute4, ".lar"} + +pat lar !defined($1) +with any4 STACK + gen move %1, d0 + jsr {absolute4, ".lar"} + +pat sar defined($1) +with STACK + gen move {const, $1}, d0 + jsr {absolute4, ".sar"} + +pat sar !defined($1) +with any4 STACK + gen move %1, d0 + jsr {absolute4, ".sar"} + +pat aar defined($1) +with STACK + gen move {const, $1}, d0 + jsr {absolute4, ".aar"} + yields a0 + +pat aar !defined($1) +with any4 STACK + gen move %1, d0 + jsr {absolute4, ".aar"} + yields a0 + +pat lae lar $2==4 && nicesize(rom($1,3)) + leaving lae $1 aar 4 loi rom($1, 3) +pat lae sar $2==4 && nicesize(rom($1,3)) + leaving lae $1 aar 4 sti rom($1, 3) + +pat lae aar $2==4 && rom($1,3)==1 + leaving ads 4 adp 0-rom($1,1) + +#ifdef m68020 +pat lae aar $2==4 && nicesize(rom($1,3)) +with D_REG yields {regX, rom($1,3), %1} + leaving ads 4 adp rom($1,3)*(0-rom($1,1)) +#else m68020 +pat lae aar $2==4 && rom($1,3)==2 +with DD_REG + gen asl_l {shconst, 1}, %1 + yields %1 + leaving ads 4 adp (0 - rom($1,1))<<1 + +pat lae aar $2==4 && rom($1,3)==4 +with DD_REG + gen asl_l {shconst, 2}, %1 + yields %1 + leaving ads 4 adp (0 - rom($1,1))<<2 + +pat lae aar $2==4 && rom($1,3)==8 +with DD_REG + gen asl_l {shconst, 3}, %1 + yields %1 + leaving ads 4 adp (0 - rom($1,1))<<3 +#endif m68020 + + /* I WOULD ALSO LIKE THESE: + * pat lae aar $2==4 && defined(rom($1,3)) + * with const leaving adp rom($1,3)*(%1.num-rom($1,1)) + * pat lae lar $2==4 && defined(rom($1,3)) + * with const leaving adp rom($1,3)*(%1.num-rom($1,1)) + * loi rom($1,3) + * pat lae sar $2==4 && defined(rom($1,3)) + * with const leaving adp rom($1,3)*(%1.num-rom($1,1)) + * sti rom($1,3) + * BUT THEY DON'T WORK. + */ + + + +/************************************************ + * Group 12: compare instructions * + ************************************************/ + + +pat cmi $1==4 leaving sbi 4 + +pat cmi defined($1) +with STACK + gen move {const, $1}, d0 + jsr {absolute4, ".cmi"} + yields d0 + +pat cmi !defined($1) +with any4 STACK + gen move %1, d0 + jsr {absolute4, ".cmi"} + yields d0 + +pat cmu $1==4 leaving sbi 4 + +pat cmu defined($1) +with STACK + gen move {const, $1}, d0 + jsr {absolute4, ".cmu"} + yields d0 + +pat cmu !defined($1) +with any4 STACK + gen move %1, d0 + jsr {absolute4, ".cmu"} + yields d0 + +pat cms $1==4 leaving sbi 4 + +pat cms defined($1) +with STACK + gen move {const, $1}, d0 + jsr {absolute4, ".cms"} + yields d0 + +pat cms !defined($1) +with any4 STACK + gen move %1, d0 + jsr {absolute4, ".cms"} + yields d0 + +pat cmp leaving cmu 4 + +proc txx +with test_set + uses DD_REG = {const, 1} + gen test %1 + bxx* {slabel, 1f} + clr_l %a + 1: + yields %a + +pat tlt call txx("blt") +pat tle call txx("ble") +pat teq call txx("beq") +pat tne call txx("bne") +pat tge call txx("bge") +pat tgt call txx("bgt") + +pat cmf leaving loc 18 trp + + + +/************************************************ + * Group 13: branch instructions * + ************************************************/ + +pat bra +with STACK + gen bra {llabel, $1} + +proc brxx example beq +with any4 genreg STACK + gen cmp_l %1, %2 + bxx[1] {llabel, $1} +with genreg any4 STACK + gen cmp_l %2, %1 + bxx[2] {llabel, $1} +with exact immediate4 imm_cmp4 + kills ALL + gen cmp_l %1, %2 + bxx[1] {llabel, $1} +with exact imm_cmp4 immediate4 + kills ALL + gen cmp_l %2, %1 + bxx[2] {llabel, $1} +with genreg STACK + gen cmp_l {post_inc4, sp}, %1 + bxx[2] {llabel, $1} +with exact immediate4 STACK + gen cmp_l %1, {post_inc4, sp} + bxx[1] {llabel, $1} +with any2-conreg2 genreg STACK + gen cmp_w %1, %2 + bxx[1] {llabel, $1} +with genreg any2-conreg2 STACK + gen cmp_w %2, %1 + bxx[2] {llabel, $1} +with exact const imm_cmp2 + kills ALL + gen cmp_w {const, loww(%1.num)}, %2 + bxx[1] {llabel, $1} +with exact imm_cmp2 const + kills ALL + gen cmp_w {const, loww(%2.num)}, %1 + bxx[2] {llabel, $1} +with data1-conreg1 D_REG STACK + gen cmp_b %1, %2 + bxx[1] {llabel, $1} +with D_REG data1-conreg1 STACK + gen cmp_b %2, %1 + bxx[2] {llabel, $1} +with exact const imm_cmp1 + kills ALL + gen cmp_b {const, lowb(%1.num)}, %2 + bxx[1] {llabel, $1} +with exact imm_cmp1 const + kills ALL + gen cmp_b {const, lowb(%2.num)}, %1 + bxx[2] {llabel, $1} + +pat blt call brxx("blt","bgt") +pat ble call brxx("ble","bge") +pat beq call brxx("beq","beq") +pat bne call brxx("bne","bne") +pat bge call brxx("bge","ble") +pat bgt call brxx("bgt","blt") + +proc zxx example zeq +with test_set STACK + gen test %1 + bxx* {llabel, $1} +with exact STACK + gen test {post_inc4, sp} + bxx* {llabel, $1} + +pat zlt call zxx("blt") +pat zle call zxx("ble") +pat zeq call zxx("beq") +pat zne call zxx("bne") +pat zge call zxx("bge") +pat zgt call zxx("bgt") + +/************************************************ + * Group 14: procedure calls instructions * + ************************************************/ + + +pat cai +with exact ext_addr + kills ALL + gen jsr {absolute4, %1.bd} +with A_REG STACK + gen jsr {indirect4, %1} +with STACK + uses AA_REG = {post_inc4, sp} + gen jsr {indirect4, %a} +#ifdef m68020 +with exact address + kills ALL + gen jsr %1 +#else m68020 +with address STACK + gen jsr %1 +#endif m68020 + +pat cal +with STACK + gen jsr {absolute4, $1} + +pat lfr $1==4 yields d0 +pat lfr $1==8 yields d1 d0 + +pat ret $1==0 +with STACK + gen return + +pat ret $1==4 +with any4 STACK + gen move %1, d0 + return +with STACK + gen move {post_inc4, sp}, d0 + return + +pat ret $1==8 +with any4 any4 STACK + gen move %1, d0 + move %2, d1 + return +with any4 STACK + gen move %1, d0 + move {post_inc4, sp}, d1 + return +with STACK + gen move {post_inc4, sp}, d0 + move {post_inc4, sp}, d1 + return + + +/************************************************ + * Group 15: miscellaneous instructions * + ************************************************/ + +pat asp small($1) +with STACK + gen add_l {const, $1}, sp +pat asp +with STACK + gen move {regAcon, sp, $1}, sp + +pat ass $1==4 +with any4 STACK + gen add_l %1, sp + +pat blm $1==4 +with A_REG A_REG + kills allexceptcon + gen move_l {indirect4, %2}, {indirect4, %1} + +pat blm $1==8 +with A_REG A_REG + kills allexceptcon + gen move_l {indirect4, %2}, {indirect4, %1} + move_l {offsetted4, %2, 4}, {offsetted4, %1, 4} + +pat blm $1>8 +with AA_REG AA_REG + kills allexceptcon + uses DD_REG={const, $1/4 -1} + gen 1: + move_l {post_inc4, %2}, {post_inc4, %1} + dbf %a, {slabel, 1b} + +pat bls $1==4 +with DD_REG AA_REG AA_REG + kills allexceptcon + gen asr_l {shconst, 2}, %1 + beq {slabel, 2f} + sub_l {const, 1}, %1 + 1: + move_l {post_inc4, %3}, {post_inc4, %2} + dbf %1, {slabel, 1b} + 2: + +pat csa $1==4 +with STACK + gen jmp {absolute4, ".csa"} + +pat csb $1==4 +with STACK + gen jmp {absolute4, ".csb"} + +pat dch leaving loi 4 + +pat dup $1==4 +with exact STACK + gen move_l {indirect4, sp}, {pre_dec4, sp} +with any4 yields %1 %1 + +pat dup $1==8 +with exact STACK + gen move_l {offsetted4, sp, 4}, {pre_dec4, sp} + move_l {offsetted4, sp, 4}, {pre_dec4, sp} +with any4 any4 yields %2 %1 %2 %1 + +pat dup $1>8 +with STACK + uses DD_REG = {const, $1/4 -1} + gen 1: + move_l {offsetted4, sp, $1 -4}, {pre_dec4, sp} + dbf %a, {slabel, 1b} + +pat dus $1==4 +with DD_REG STACK + uses AA_REG = {regAregXcon, sp, %1, 1, 0} + gen asr_l {shconst, 2}, %1 + beq {slabel, 2f} + sub_l {const, 1}, %1 + 1: + move_l {pre_dec4, %a}, {pre_dec4, sp} + dbf %1, {slabel, 1b} + 2: + +pat exg $1==4 +with any4 any4 yields %1 %2 + +pat exg defined($1) +with STACK + gen move {const, $1}, d0 + jsr {absolute4, ".exg"} + +pat exg !defined($1) +with any4 STACK + gen move_l %1, d0 + jsr {absolute4, ".exg"} + +pat fil + gen move_l {ext_addr, $1}, {absolute4, ".filn"} + +pat gto +with STACK + uses AA_REG = {ext_addr, $1} + gen move_l {offsetted4, %a, 8}, lb + move_l {offsetted4, %a, 4}, sp +#ifdef m68020 + jmp {OFF_off4, %a, 0, 0} +#else m68020 + move_l {indirect4, %a}, %a + jmp {indirect4, %a} +#endif m68020 + +pat lim yields {absolute4, ".trpim"} + +pat lin + gen move {const, $1}, {absolute4, ".lino"} + +pat lni + gen add_l {const, 1}, {absolute4, ".lino"} + +pat lor $1==0 yields lb + +pat lor $1==1 +with STACK + uses AA_REG = sp yields %a + +pat lor $1==2 yields {absolute4, ".reghp"} + +pat lpb leaving adp 8 + +pat mon +with STACK + gen jsr {absolute4, ".mon"} + +pat nop +with STACK + gen jsr {absolute4, ".nop"} + +pat rck +#ifdef m68020 +with ext_addr D_REG + gen cmp2_l {absolute4, %1.bd}, %2 + bcc {slabel, 1f} + pea {absolute4, 1} /* push constant 1 == ERANGE */ + jsr {absolute4, ".trp"} + 1: yields %2 +with address-ext_addr D_REG + gen cmp2_l %1, %2 + bcc {slabel, 1f} + pea {absolute4, 1} /* push constant 1 == ERANGE */ + jsr {absolute4, ".trp"} + 1: yields %2 +with A_REG D_REG + gen cmp2_l {indirect4, %1}, %2 + bcc {slabel, 1f} + pea {absolute4, 1} /* push constant 1 == ERANGE */ + jsr {absolute4, ".trp"} + 1: yields %2 +#else m68020 +with STACK + gen jsr {absolute4, ".rck"} +#endif m68020 + +pat rtt leaving ret 0 + +pat sig +with any4 + uses AA_REG + gen move {absolute4, ".trppc"}, %a + move %1, {absolute4, ".trppc"} + yields %a + +pat sim +with any4 + gen move_l %1, {absolute4, ".trpim"} + +pat str $1==0 +with any4 +#ifdef m68020 + kills LOCAL, ILOCAL, all_regind %reg==lb, local_addr +#else m68020 + kills LOCAL, all_regind %reg==lb, local_addr +#endif m68020 + gen move %1, lb + +pat str $1==1 +with any4 STACK + gen move %1, sp + +pat str $1==2 +with STACK + gen jsr {absolute4, ".strhp"} + +pat trp +with STACK + gen jsr {absolute4, ".trp"} + + + +/************************************************ + * rules for long EM-patterns * + ************************************************/ + +proc lolxxxstl example lol adi stl +with conreg4 + kills all_indir, LOCAL %bd==$1 + gen xxx* %1, {LOCAL, $1} + +proc loexxxste example loe adi ste +with conreg4 + kills posextern + gen xxx* %1, {absolute4, $1} + +proc lilxxxsil example lil adi sil +with conreg4 +#ifdef m68020 + kills allexceptcon + gen xxx* %1, {ILOCAL, $1} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen xxx* %1, {indirect4, %a} +#endif m68020 + +proc lolcxxxstl example lol loc adi stl + kills all_indir, LOCAL %bd==$1 + gen xxx* {const, $2}, {LOCAL, $1} + +proc loecxxxste example loe loc adi ste + kills posextern + gen xxx* {const, $2}, {absolute4, $1} + +proc lilcxxxsil example lil loc adi sil +#ifdef m68020 + kills allexceptcon + gen xxx* {const, $2}, {ILOCAL, $1} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen xxx* {const, $2}, {indirect4, %a} +#endif m68020 + +proc lolrxxxstl example lol lol adi stl + kills all_indir, LOCAL %bd==$1 + gen xxx* {LOCAL, $2}, {LOCAL, $1} + +proc loerxxxste example loe lol adi ste + kills posextern + gen xxx* {LOCAL, $2}, {absolute4, $1} + +proc lilrxxxsil example lil lol adi sil +#ifdef m68020 + kills allexceptcon + gen xxx* {LOCAL, $2}, {ILOCAL, $1} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen xxx* {LOCAL, $2}, {indirect4, %a} +#endif m68020 + +pat lol adi stl $1==$3 && $2==4 call lolxxxstl("add.l") +pat loe adi ste $1==$3 && $2==4 call loexxxste("add.l") +pat lil adi sil $1==$3 && $2==4 call lilxxxsil("add.l") +pat lol loc adi stl $1==$4 && $3==4 call lolcxxxstl("add.l") +pat loe loc adi ste $1==$4 && $3==4 call loecxxxste("add.l") +pat lil loc adi sil $1==$4 && $3==4 call lilcxxxsil("add.l") +pat lol lol adi stl $1==$4 && $3==4 && inreg($2)==reg_any + call lolrxxxstl("add.l") +pat loe lol adi ste $1==$4 && $3==4 && inreg($2)==reg_any + call loerxxxste("add.l") +pat lil lol adi sil $1==$4 && $3==4 && inreg($2)==reg_any + call lilrxxxsil("add.l") + +pat lol adu stl $1==$3 && $2==4 call lolxxxstl("add.l") +pat loe adu ste $1==$3 && $2==4 call loexxxste("add.l") +pat lil adu sil $1==$3 && $2==4 call lilxxxsil("add.l") +pat lol loc adu stl $1==$4 && $3==4 call lolcxxxstl("add.l") +pat loe loc adu ste $1==$4 && $3==4 call loecxxxste("add.l") +pat lil loc adu sil $1==$4 && $3==4 call lilcxxxsil("add.l") +pat lol lol adu stl $1==$4 && $3==4 && inreg($2)==reg_any + call lolrxxxstl("add.l") +pat loe lol adu ste $1==$4 && $3==4 && inreg($2)==reg_any + call loerxxxste("add.l") +pat lil lol adu sil $1==$4 && $3==4 && inreg($2)==reg_any + call lilrxxxsil("add.l") + + +pat lol adp stl $1==$3 + kills all_indir, LOCAL %bd==$1 + gen add_l {const, $2}, {LOCAL, $1} + +pat lil adp sil $1==$3 + kills allexceptcon +#ifdef m68020 + gen add_l {const, $2}, {ILOCAL, $1} +#else m68020 + uses AA_REG = {LOCAL, $1} + gen add_l {const, $2}, {indirect4, %a} +#endif m68020 + +pat loe adp ste $1==$3 + kills posextern + gen add_l {const, $2}, {absolute4, $1} + +pat lol lol adp stl $1==$2 && $1==$4 + kills all_indir, LOCAL %bd==$1 + uses AA_REG = {LOCAL, $1} + gen add_l {const, $3}, {LOCAL, $1} + yields %a + +pat lil lil adp sti $1==$2 && $1==$4 + kills allexceptcon +#ifdef m68020 + uses AA_REG = {ILOCAL, $1} + gen add_l {const, $3}, {ILOCAL, $1} +#else m68020 + uses AA_REG, AA_REG = {LOCAL, $1} + gen move {indirect4, %b}, %a + add_l {const, $3}, {indirect4, %b} +#endif m68020 + yields %a + +pat loe loe adp ste $1==$2 && $1==$4 + kills posextern + uses AA_REG = {absolute4, $1} + gen add_l {const, $3}, {absolute4, $1} + yields %a + + +pat lol loc sbi stl $1==$4 && $3==4 call lolcxxxstl("sub.l") +pat loe loc sbi ste $1==$4 && $3==4 call loecxxxste("sub.l") +pat lil loc sbi sil $1==$4 && $3==4 call lilcxxxsil("sub.l") +pat lol lol sbi stl $1==$4 && $3==4 && inreg($2)==reg_any + call lolrxxxstl("sub.l") +pat loe lol sbi ste $1==$4 && $3==4 && inreg($2)==reg_any + call loerxxxste("sub.l") +pat lil lol sbi sil $1==$4 && $3==4 && inreg($2)==reg_any + call lilrxxxsil("sub.l") + +pat lol loc sbu stl $1==$4 && $3==4 call lolcxxxstl("sub.l") +pat loe loc sbu ste $1==$4 && $3==4 call loecxxxste("sub.l") +pat lil loc sbu sil $1==$4 && $3==4 call lilcxxxsil("sub.l") +pat lol lol sbu stl $1==$4 && $3==4 && inreg($2)==reg_any + call lolrxxxstl("sub.l") +pat loe lol sbu ste $1==$4 && $3==4 && inreg($2)==reg_any + call loerxxxste("sub.l") +pat lil lol sbu sil $1==$4 && $3==4 && inreg($2)==reg_any + call lilrxxxsil("sub.l") + +pat lol and stl $1==$3 && $2==4 call lolxxxstl("and.l") +pat loe and ste $1==$3 && $2==4 call loexxxste("and.l") +pat lil and sil $1==$3 && $2==4 call lilxxxsil("and.l") +pat lol loc and stl $1==$4 && $3==4 call lolcxxxstl("and.l") +pat loe loc and ste $1==$4 && $3==4 call loecxxxste("and.l") +pat lil loc and sil $1==$4 && $3==4 call lilcxxxsil("and.l") +pat lol lol and stl $1==$4 && $3==4 && inreg($2)==reg_any + call lolrxxxstl("and.l") +pat loe lol and ste $1==$4 && $3==4 && inreg($2)==reg_any + call loerxxxste("and.l") +pat lil lol and sil $1==$4 && $3==4 && inreg($2)==reg_any + call lilrxxxsil("and.l") + +pat lol ior stl $1==$3 && $2==4 call lolxxxstl("or.l") +pat loe ior ste $1==$3 && $2==4 call loexxxste("or.l") +pat lil ior sil $1==$3 && $2==4 call lilxxxsil("or.l") +pat lol loc ior stl $1==$4 && $3==4 call lolcxxxstl("or.l") +pat loe loc ior ste $1==$4 && $3==4 call loecxxxste("or.l") +pat lil loc ior sil $1==$4 && $3==4 call lilcxxxsil("or.l") +pat lol lol ior stl $1==$4 && $3==4 && inreg($2)==reg_any + call lolrxxxstl("or.l") +pat loe lol ior ste $1==$4 && $3==4 && inreg($2)==reg_any + call loerxxxste("or.l") +pat lil lol ior sil $1==$4 && $3==4 && inreg($2)==reg_any + call lilrxxxsil("or.l") + +pat lol xor stl $1==$3 && $2==4 call lolxxxstl("eor.l") +pat loe xor ste $1==$3 && $2==4 call loexxxste("eor.l") +pat lil xor sil $1==$3 && $2==4 call lilxxxsil("eor.l") +pat lol loc xor stl $1==$4 && $3==4 call lolcxxxstl("eor.l") +pat loe loc xor ste $1==$4 && $3==4 call loecxxxste("eor.l") +pat lil loc xor sil $1==$4 && $3==4 call lilcxxxsil("eor.l") +pat lol lol xor stl $1==$4 && $3==4 && inreg($2)==reg_any + call lolrxxxstl("eor.l") +pat loe lol xor ste $1==$4 && $3==4 && inreg($2)==reg_any + call loerxxxste("eor.l") +pat lil lol xor sil $1==$4 && $3==4 && inreg($2)==reg_any + call lilrxxxsil("eor.l") + +proc llol1shstl example lol loc sli stl /* only left */ + kills all_indir, LOCAL %bd==$1 + gen shw* {offsetted2, lb, $1+2} + roxl {offsetted2, lb, $1} + +proc lloe1shste example loe loc sli ste /* only left */ + kills posextern + gen shw* {absolute2, $1+2} + roxl {absolute2, $1} + +proc llil1shsil example lil loc sli sil /* only left */ +#ifdef m68020 + kills allexceptcon + gen shw* {OFF_off2, lb, $1, 2} + roxl {OFF_off2, lb, $1, 0} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen shw* {offsetted2, %a, 2} + roxl {indirect2, %a} +#endif m68020 + +proc rlol1shstl example lol loc sri stl /* only right */ + kills all_indir, LOCAL %bd==$1 + gen shw* {offsetted2, lb, $1} + roxr {offsetted2, lb, $1+2} + +proc rloe1shste example loe loc sri ste /* only right */ + kills posextern + gen shw* {absolute2, $1} + roxr {absolute2, $1+2} + +proc rlil1shsil example lil loc sri sil /* only right */ +#ifdef m68020 + kills allexceptcon + gen shw* {OFF_off2, lb, $1, 0} + roxr {OFF_off2, lb, $1, 2} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen shw* {indirect2, %a} + roxr {offsetted2, %a, 2} +#endif m68020 + +pat lol loc sli stl $1==$4 && $2==1 && $3==4 call llol1shstl("asl #1,") +pat loe loc sli ste $1==$4 && $2==1 && $3==4 call lloe1shste("asl #1,") +pat lil loc sli sil $1==$4 && $2==1 && $3==4 call llil1shsil("asl #1,") +pat lol loc sri stl $1==$4 && $2==1 && $3==4 call rlol1shstl("asr #1,") +pat loe loc sri ste $1==$4 && $2==1 && $3==4 call rloe1shste("asr #1,") +pat lil loc sri sil $1==$4 && $2==1 && $3==4 call rlil1shsil("asr #1,") +pat lol loc slu stl $1==$4 && $2==1 && $3==4 call llol1shstl("asl #1,") +pat loe loc slu ste $1==$4 && $2==1 && $3==4 call lloe1shste("asl #1,") +pat lil loc slu sil $1==$4 && $2==1 && $3==4 call llil1shsil("asl #1,") +pat lol loc sru stl $1==$4 && $2==1 && $3==4 call rlol1shstl("lsr #1,") +pat loe loc sru ste $1==$4 && $2==1 && $3==4 call rloe1shste("lsr #1,") +pat lil loc sru sil $1==$4 && $2==1 && $3==4 call rlil1shsil("lsr #1,") + +proc locsh example loc sli +with DD_REG + gen sh* {shconst, $1}, %1 + yields %1 + +pat loc sli small($1) && $2==4 call locsh("asl.l") +pat loc sri small($1) && $2==4 call locsh("asr.l") +pat loc slu small($1) && $2==4 call locsh("asl.l") +pat loc sru small($1) && $2==4 call locsh("lsr.l") +pat loc rol small($1) && $2==4 call locsh("rol.l") +pat loc ror small($1) && $2==4 call locsh("ror.l") + +proc lolbitstl example lol ngi stl + kills all_indir, LOCAL %bd==$1 + gen bit* {LOCAL, $1} + +proc loebitste example loe ngi ste + kills posextern + gen bit* {absolute4, $1} + +proc lilbitsil example lil ngi sil +#ifdef m68020 + kills allexceptcon + gen bit* {ILOCAL, $1} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen bit* {indirect4, %a} +#endif m68020 + +pat lol ngi stl $1==$3 && $2==4 call lolbitstl("neg.l") +pat loe ngi ste $1==$3 && $2==4 call loebitste("neg.l") +pat lil ngi sil $1==$3 && $2==4 call lilbitsil("neg.l") +pat lol com stl $1==$3 && $2==4 call lolbitstl("not.l") +pat loe com ste $1==$3 && $2==4 call loebitste("not.l") +pat lil com sil $1==$3 && $2==4 call lilbitsil("not.l") + +pat lil inc sil $1==$3 +#ifdef m68020 + kills allexceptcon + gen add_l {const, 1}, {ILOCAL, $1} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen add_l {const, 1}, {indirect4, %a} +#endif m68020 + +pat lil dec sil $1==$3 +#ifdef m68020 + kills allexceptcon + gen sub_l {const, 1}, {ILOCAL, $1} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen sub_l {const, 1}, {indirect4, %a} +#endif m68020 + + +proc txxand +with test_set DD_REG + gen test %1 + bxx* {slabel, 1f} + clr_l %2 + 1: yields %2 + +proc txxior +with test_set DD_REG + gen test %1 + bxx* {slabel, 1f} + bset {const, 0}, %2 + 1: yields %2 + +pat tlt and $2==4 call txxand("blt") +pat tle and $2==4 call txxand("ble") +pat teq and $2==4 call txxand("beq") +pat tne and $2==4 call txxand("bne") +pat tge and $2==4 call txxand("bge") +pat tgt and $2==4 call txxand("bgt") + +pat tlt ior $2==4 call txxior("bge") +pat tle ior $2==4 call txxior("bgt") +pat teq ior $2==4 call txxior("bne") +pat tne ior $2==4 call txxior("beq") +pat tge ior $2==4 call txxior("blt") +pat tgt ior $2==4 call txxior("ble") + +proc cmxtxxand +with any4 genreg DD_REG + gen cmp_l %1, %2 + bxx[1] {slabel, 1f} + clr_l %3 + 1: yields %3 +with genreg any4-genreg DD_REG + gen cmp_l %2, %1 + bxx[2] {slabel, 1f} + clr_l %3 + 1: yields %3 +with exact immediate4 imm_cmp4 DD_REG + gen cmp_l %1, %2 + bxx[1] {slabel, 1f} + clr_l %3 + 1: yields %3 +with exact imm_cmp4 immediate4 DD_REG + gen cmp_l %2, %1 + bxx[2] {slabel, 1f} + clr_l %3 + 1: yields %3 + +proc cmxtxxior +with any4 genreg DD_REG + gen cmp_l %1, %2 + bxx[1] {slabel, 1f} + move {const, 1}, %3 + 1: yields %3 +with genreg any4-genreg DD_REG + gen cmp_l %2, %1 + bxx[2] {slabel, 1f} + move {const, 1}, %3 + 1: yields %3 +with exact immediate4 imm_cmp4 DD_REG + gen cmp_l %1, %2 + bxx[1] {slabel, 1f} + move {const, 1}, %3 + 1: yields %3 +with exact imm_cmp4 immediate4 DD_REG + gen cmp_l %2, %1 + bxx[2] {slabel, 1f} + move {const, 1}, %3 + 1: yields %3 + +proc cmxtxx +with any4 genreg + uses DD_REG = {const, 1} + gen cmp_l %1, %2 + bxx[1] {slabel, 1f} + clr_l %a + 1: yields %a +with genreg any4-genreg + uses DD_REG = {const, 1} + gen cmp_l %2, %1 + bxx[2] {slabel, 1f} + clr_l %a + 1: yields %a +with exact immediate4 imm_cmp4 + uses DD_REG = {const, 1} + gen cmp_l %1, %2 + bxx[1] {slabel, 1f} + clr_l %a + 1: yields %a +with exact imm_cmp4 immediate4 + uses DD_REG = {const, 1} + gen cmp_l %2, %1 + bxx[2] {slabel, 1f} + clr_l %a + 1: yields %a +with genreg STACK + uses DD_REG = {const, 1} + gen cmp_l {post_inc4, sp}, %1 + bxx[2] {slabel, 1f} + clr_l %a + 1: yields %a +with exact immediate4 STACK + uses DD_REG = {const, 1} + gen cmp_l %1, {post_inc4, sp} + bxx[1] {slabel, 1f} + clr_l %a + 1: yields %a + +pat cmi tlt and $1==4 && $3==4 call cmxtxxand("blt","bgt") +pat cmi tle and $1==4 && $3==4 call cmxtxxand("ble","bge") +pat cmi teq and $1==4 && $3==4 call cmxtxxand("beq","beq") +pat cmi tne and $1==4 && $3==4 call cmxtxxand("bne","bne") +pat cmi tge and $1==4 && $3==4 call cmxtxxand("bge","ble") +pat cmi tgt and $1==4 && $3==4 call cmxtxxand("bgt","blt") + +pat cmu tlt and $1==4 && $3==4 call cmxtxxand("bcs","bhi") +pat cmu tle and $1==4 && $3==4 call cmxtxxand("bls","bcc") +pat cmu teq and $1==4 && $3==4 call cmxtxxand("beq","beq") +pat cmu tne and $1==4 && $3==4 call cmxtxxand("bne","bne") +pat cmu tge and $1==4 && $3==4 call cmxtxxand("bcc","bls") +pat cmu tgt and $1==4 && $3==4 call cmxtxxand("bhi","bcs") + +pat cmi tlt ior $1==4 && $3==4 call cmxtxxior("bge","ble") +pat cmi tle ior $1==4 && $3==4 call cmxtxxior("bgt","blt") +pat cmi teq ior $1==4 && $3==4 call cmxtxxior("bne","bne") +pat cmi tne ior $1==4 && $3==4 call cmxtxxior("beq","beq") +pat cmi tge ior $1==4 && $3==4 call cmxtxxior("blt","bgt") +pat cmi tgt ior $1==4 && $3==4 call cmxtxxior("ble","bge") + +pat cmu tlt ior $1==4 && $3==4 call cmxtxxior("bcc","bls") +pat cmu tle ior $1==4 && $3==4 call cmxtxxior("bhi","bcs") +pat cmu teq ior $1==4 && $3==4 call cmxtxxior("bne","bne") +pat cmu tne ior $1==4 && $3==4 call cmxtxxior("beq","beq") +pat cmu tge ior $1==4 && $3==4 call cmxtxxior("bcs","bhi") +pat cmu tgt ior $1==4 && $3==4 call cmxtxxior("bls","bcc") + +pat cmi tlt $1==4 call cmxtxx("blt","bgt") +pat cmi tle $1==4 call cmxtxx("ble","bge") +pat cmi teq $1==4 call cmxtxx("beq","beq") +pat cmi tne $1==4 call cmxtxx("bne","bne") +pat cmi tge $1==4 call cmxtxx("bge","blt") +pat cmi tgt $1==4 call cmxtxx("bgt","blt") + +pat cmu tlt $1==4 call cmxtxx("bcs","bhi") +pat cmu tle $1==4 call cmxtxx("bls","bcc") +pat cmu teq $1==4 call cmxtxx("beq","beq") +pat cmu tne $1==4 call cmxtxx("bne","bne") +pat cmu tge $1==4 call cmxtxx("bcc","bls") +pat cmu tgt $1==4 call cmxtxx("bhi","bcs") + +proc cmxzxx example cmu zlt +with any4 genreg STACK + gen cmp_l %1, %2 + bxx[1] {llabel, $2} +with genreg any4-genreg STACK + gen cmp_l %2, %1 + bxx[2] {llabel, $2} +with exact immediate4 imm_cmp4 + kills ALL + gen cmp_l %1, %2 + bxx[1] {llabel, $2} +with exact imm_cmp4 immediate4 + kills ALL + gen cmp_l %2, %1 + bxx[2] {llabel, $2} +with genreg STACK + gen cmp_l {post_inc4, sp}, %1 + bxx[2] {llabel, $2} +with exact immediate4 STACK + gen cmp_l %1, {post_inc4, sp} + bxx[1] {llabel, $2} + +pat cmu zlt $1==4 call cmxzxx("bcs","bhi") +pat cmu zle $1==4 call cmxzxx("bls","bcc") +pat cmu zeq $1==4 call cmxzxx("beq","beq") +pat cmu zne $1==4 call cmxzxx("bne","bne") +pat cmu zge $1==4 call cmxzxx("bcc","bls") +pat cmu zgt $1==4 call cmxzxx("bhi","bcs") + + +proc bxx1_in example loc loc cii loc bne +with imm_cmp1 STACK + gen cmp_b {const, lowb($4)}, %1 + bxx* {llabel, $5} + +proc bxx2_in example loc loc cii loc bne +with imm_cmp2 STACK + gen cmp_w {const, loww($4)}, %1 + bxx* {llabel, $5} + +pat loc loc cii loc blt $1==1 && $2==4 && in_1($4) call bxx1_in("blt") +pat loc loc cii loc ble $1==1 && $2==4 && in_1($4) call bxx1_in("ble") +pat loc loc cii loc beq $1==1 && $2==4 && in_1($4) call bxx1_in("beq") +pat loc loc cii loc bne $1==1 && $2==4 && in_1($4) call bxx1_in("bne") +pat loc loc cii loc bge $1==1 && $2==4 && in_1($4) call bxx1_in("bge") +pat loc loc cii loc bgt $1==1 && $2==4 && in_1($4) call bxx1_in("bgt") + +pat loc loc cii loc blt $1==2 && $2==4 && in_2($4) call bxx2_in("blt") +pat loc loc cii loc ble $1==2 && $2==4 && in_2($4) call bxx2_in("ble") +pat loc loc cii loc beq $1==2 && $2==4 && in_2($4) call bxx2_in("beq") +pat loc loc cii loc bne $1==2 && $2==4 && in_2($4) call bxx2_in("bne") +pat loc loc cii loc bge $1==2 && $2==4 && in_2($4) call bxx2_in("bge") +pat loc loc cii loc bgt $1==2 && $2==4 && in_2($4) call bxx2_in("bgt") + +pat loc loc cii $1==1 && $2==2 +with DD_REG + gen ext_w %1 yields %1 + +pat loc loc cii $1==2 && $2==4 +with DD_REG + gen ext_l %1 yields %1 + +pat loc loc cii $1==1 && $2==4 +with DD_REG +#ifdef m68020 + gen extb_l %1 yields %1 +#else m68020 + gen ext_w %1 + ext_l %1 yields %1 +#endif m68020 + +pat loc loc ciu $1==$2 /* skip this */ +pat loc loc cui $1==$2 /* skip this */ + + +/* The following rules should be handled by the peephole optimizer, I think */ + +pat loc dvi $1==2 && $2==4 leaving loc 1 sri 4 +pat loc dvi $1==4 && $2==4 leaving loc 2 sri 4 +pat loc dvi $1==8 && $2==4 leaving loc 3 sri 4 +pat loc dvi $1==16 && $2==4 leaving loc 4 sri 4 +pat loc dvi $1==32 && $2==4 leaving loc 5 sri 4 +pat loc dvi $1==64 && $2==4 leaving loc 6 sri 4 +pat loc dvi $1==128 && $2==4 leaving loc 7 sri 4 +pat loc dvi $1==256 && $2==4 leaving loc 8 sri 4 + +pat loc dvu $1==2 && $2==4 leaving loc 1 sru 4 +pat loc dvu $1==4 && $2==4 leaving loc 2 sru 4 +pat loc dvu $1==8 && $2==4 leaving loc 3 sru 4 +pat loc dvu $1==16 && $2==4 leaving loc 4 sru 4 +pat loc dvu $1==32 && $2==4 leaving loc 5 sru 4 +pat loc dvu $1==64 && $2==4 leaving loc 6 sru 4 +pat loc dvu $1==128 && $2==4 leaving loc 7 sru 4 +pat loc dvu $1==256 && $2==4 leaving loc 8 sru 4 diff --git a/mach/m68k4/ncg/mach.c b/mach/m68k4/ncg/mach.c new file mode 100644 index 00000000..ec51f8bf --- /dev/null +++ b/mach/m68k4/ncg/mach.c @@ -0,0 +1,236 @@ +/* + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. + * + * This product is part of the Amsterdam Compiler Kit. + * + * Permission to use, sell, duplicate or disclose this software must be + * obtained in writing. Requests for such permissions may be sent to + * + * Dr. Andrew S. Tanenbaum + * Wiskundig Seminarium + * Vrije Universiteit + * Postbox 7161 + * 1007 MC Amsterdam + * The Netherlands + * + */ + +/* + * machine dependent back end routines for the Motorola 68000, 68010 or 68020 + */ + +#ifndef m68k4 +#define m68020 +#endif + /* use m68020 when you want a m68020 cg, don't if you want a + * m68k4 cg. The m68k4 cg can be used for both the MC68000 + * and the MC68010. + */ + +con_part(sz,w) register sz; word w; { + + while (part_size % sz) + part_size++; + if (part_size == 4) + part_flush(); + if (sz == 1) { + w &= 0xFF; + w <<= 8*(3-part_size); + part_word |= w; + } else if (sz == 2) { + w &= 0xFFFF; + if (part_size == 0) + w <<= 16; + part_word |= w; + } else { + assert(sz == 4); + part_word = w; + } + part_size += sz; +} + +con_mult(sz) word sz; { + + if (sz != 4) + fatal("bad icon/ucon size"); + fprintf(codefile,".data4 %s\n",str); +} + +con_float() { + +static int been_here; + if (argval != 4 && argval != 8) + fatal("bad fcon size"); + fprintf(codefile,".data4\t"); + if (argval == 8) + fprintf(codefile,"F_DUM,"); + fprintf(codefile,"F_DUM\n"); + if ( !been_here++) + { + fprintf(stderr,"Warning : dummy float-constant(s)\n"); + } +} + +regscore(off,size,typ,score,totyp) + long off; +{ + if (score == 0) return -1; + switch(typ) { + case reg_float: + return -1; + case reg_pointer: + if (size != 4 || totyp != reg_pointer) return -1; + score *= 2; + break; + case reg_loop: + score += 5; + /* fall through .. */ + case reg_any: + if (size != 4 || totyp == reg_pointer) return -1; + break; + } + if (off >= 0) { + /* parameters must be initialised with an instruction + * like "move.l 4(a6),d0", which costs 2 words. + */ + score -= 2; + } + score -= 1; /* take save/restore into account */ + return score; +} +struct regsav_t { + char *rs_reg; /* e.g. "a3" or "d5" */ + long rs_off; /* offset of variable */ + int rs_size; /* 2 or 4 bytes */ +} regsav[9]; + + +int regnr; + +i_regsave() +{ + regnr = 0; +} + +#define MOVEM_LIMIT 2 +/* If #registers to be saved exceeds MOVEM_LIMIT, we +* use the movem instruction to save registers; else +* we simply use several move.l's. +*/ + +save() +{ + register struct regsav_t *p; + + if (regnr > MOVEM_LIMIT) { + fprintf(codefile,"movem.l "); + for (p = regsav; ;) { + fprintf(codefile,"%s",p->rs_reg); + if (++p == ®sav[regnr]) break; + putc('/',codefile); + } + fprintf(codefile,",-(sp)\n"); + } else { + for (p = regsav; p < ®sav[regnr]; p++) { + fprintf(codefile,"move.l %s,-(sp)\n",p->rs_reg); + } + } + /* initialise register-parameters */ + for (p = regsav; p < ®sav[regnr]; p++) { + if (p->rs_off >= 0) { +#ifdef m68020 + fprintf(codefile,"move.%c (%ld,a6),%s\n", +#else + fprintf(codefile,"move.%c %ld(a6),%s\n", +#endif + (p->rs_size == 4 ? 'l' : 'w'), + p->rs_off, + p->rs_reg); + } + } +} + +restr() +{ + register struct regsav_t *p; + + if (regnr > MOVEM_LIMIT) { + fprintf(codefile,"movem.l (sp)+,"); + for (p = regsav; ;) { + fprintf(codefile,"%s",p->rs_reg); + if (++p == ®sav[regnr]) break; + putc('/',codefile); + } + putc('\n',codefile); + } else { + for (p = ®sav[regnr-1]; p >= regsav; p--) { + fprintf(codefile,"move.l (sp)+,%s\n",p->rs_reg); + } + } + fprintf(codefile,"unlk a6\n"); + fprintf(codefile,"rts\n"); +} + + +f_regsave() +{ + save(); +} + +regsave(str,off,size) + char *str; + long off; +{ + assert (regnr < 9); + regsav[regnr].rs_reg = str; + regsav[regnr].rs_off = off; + regsav[regnr++].rs_size = size; + fprintf(codefile, "!Local %ld into %s\n",off,str); +} + +regreturn() +{ + restr(); +} + + +prolog(nlocals) full nlocals; { + +#ifdef m68020 + fprintf(codefile,"tst.b (-%ld,sp)\nlink\ta6,#-%ld\n",nlocals+40,nlocals); +#else + fprintf(codefile,"tst.b -%ld(sp)\nlink\ta6,#-%ld\n",nlocals+40,nlocals); +#endif +} + + + +mes(type) word type ; { + int argt ; + + switch ( (int)type ) { + case ms_ext : + for (;;) { + switch ( argt=getarg( + ptyp(sp_cend)|ptyp(sp_pnam)|sym_ptyp) ) { + case sp_cend : + return ; + default: + strarg(argt) ; + fprintf(codefile,".define %s\n",argstr) ; + break ; + } + } + default : + while ( getarg(any_ptyp) != sp_cend ) ; + break ; + } +} + + +char *segname[] = { + ".sect .text", /* SEGTXT */ + ".sect .data", /* SEGCON */ + ".sect .rom", /* SEGROM */ + ".sect .bss" /* SEGBSS */ +}; diff --git a/mach/m68k4/ncg/mach.h b/mach/m68k4/ncg/mach.h new file mode 100644 index 00000000..ff2cf66c --- /dev/null +++ b/mach/m68k4/ncg/mach.h @@ -0,0 +1,39 @@ +#ifndef m68k4 +#define m68020 +#endif + /* m68020 should be used for a m68020 cg, and it should + * not be used for a m68k4 cg + */ + +#define ex_ap(y) fprintf(codefile,".extern %s\n",y) +#define in_ap(y) /* nothing */ + +#define newilb(x) fprintf(codefile,"%s:\n",x) +#define newdlb(x) fprintf(codefile,"%s:\n",x) +#define dlbdlb(x,y) fprintf(codefile,"%s = %s\n",x,y) +#define newlbss(l,x) fprintf(codefile,"%s:.space\t%ld\n",l,x); + +#define pop_fmt "(sp)+" +#define cst_fmt "%ld" +#define off_fmt "%ld" +#define ilb_fmt "I%03x%x" +#define dlb_fmt "_%d" +#define hol_fmt "hol%d" + +#ifdef m68020 +#define loc_off "(%d,a6)" +#define arg_off "(8+%d,a6)" +#else +#define loc_off "%d(a6)" +#define arg_off "8+%d(a6)" +#endif +#define hol_off "%ld+hol%d" + +#define con_cst(x) fprintf(codefile,".data4\t%ld\n",x) +#define con_ilb(x) fprintf(codefile,".data4\t%s\n",x) +#define con_dlb(x) fprintf(codefile,".data4\t%s\n",x) + +#define modhead ".sect .text\n.sect .rom\n.sect .data\n.sect .bss\n" + +#define id_first '_' +#define BSS_INIT 0 diff --git a/mach/m68k4/ncg/table b/mach/m68k4/ncg/table new file mode 100644 index 00000000..6518487a --- /dev/null +++ b/mach/m68k4/ncg/table @@ -0,0 +1,3288 @@ + /******************************** + * * + * 68000, 68010 and 68020 * + * back end table * + * * + ********************************/ + + +#ifndef m68k4 +#define m68020 +#endif + /* m68020 to be defined if this is the 68020 table. + * The 68000 and 68010 tables are identical. + */ + + +#define small(x) ((x)>=1 && (x)<=8) +#define nicesize(x) ((x)==1||(x)==2||(x)==4||(x)==8) +#define lowb(x) (((x)<<24)>>24) +#define loww(x) (((x)<<16)>>16) +#define in_1(x) ((x)>=0-128 && (x)<128) +#define in_2(x) ((x)>=0-32768 && (x)<32768) + + +EM_WSIZE = 4 +EM_PSIZE = 4 +EM_BSIZE = 8 + +SL = 8 + +TIMEFACTOR = 1/2 + + +PROPERTIES + +D_REG /* data registers */ +A_REG /* address registers */ +DD_REG /* allocatable D_REG, may not be a register variable */ +AA_REG /* allocatable A_REG, may not be a register variable */ + + + +REGISTERS + +d0, d1, d2 :D_REG, DD_REG. +d3, d4, d5, d6, d7 :D_REG regvar. +a0, a1 :A_REG, AA_REG. +a2, a3, a4, a5 :A_REG regvar(reg_pointer). +lb ("a6"), sp :A_REG. /* localbase and stack pointer */ + + + + +TOKENS + + /* Not all addressing modes available on the MC68020 are used in this + * table. E.g (Dn), data register indirect is not used. Compared to + * (An), address register indirect, (Dn) requires two more bytes and + * several more clock cycles. Using (Dn) is even more expensive in + * time than first moving Dn to an address register An, and then using + * (An). For this kind of reasons several addressing modes are + * not used in this table. + * + * Cost in bytes may sometimes be incorrect. Several effective addresses + * use displacements that can occupy either 2 or 4 bytes. These are not + * considered different TOKENS in this table. + * + * Data registers are the only registers used as index registers in this + * table; address registers are only used to hold addresses. + * + * For the m68k4 table: the MC68000 and MC68010 have two modes that use + * displacements (offsets) of limited size: + * - offset(A_REG, Index_reg), where offset is only 8 bits, and + * - offset(A_REG), where offset can only be 16 bits. + * To make sure that no output is given with offsets too large, two + * extra tokens are declared: t_regAregXcon and t_regAcon. These are + * used as addresses to these modes. Whenever the displacements become + * too large, they are transformed into different tokens. + * + * Sometimes some TOKENS are used with displacements (offsets) of 0. + * It would have been possible to provide separate TOKENS for these, in + * case the assembler doesn't handle zero offsets optimally. This + * however would mean a very large amount of extra TOKENS and SETS for + * a very small profit in code bytes, so we won't do that. + * + * To prevent the TOKENS list from getting too unreadable, #ifdefs are + * used to form three parts: + * (i) the common part; + * (ii) the m68k4 part; + * (iii) the m68020 part; + */ + + /* Part (i) */ +const = {INT num;} 4 cost(4,4) "#" num . +indirect4 = {A_REG reg;} 4 cost(0,4) "(" reg ")" . +post_inc4 = {A_REG reg;} 4 cost(0,4) "(" reg ")+" . +pre_dec4 = {A_REG reg;} 4 cost(0,5) "-(" reg ")" . +indirect2 = {A_REG reg;} 4 cost(0,4) "(" reg ")" . +post_inc2 = {A_REG reg;} 4 cost(0,4) "(" reg ")+" . +pre_dec2 = {A_REG reg;} 4 cost(0,5) "-(" reg ")" . +indirect1 = {A_REG reg;} 4 cost(0,4) "(" reg ")" . +post_inc1 = {A_REG reg;} 4 cost(0,4) "(" reg ")+" . +pre_dec1 = {A_REG reg;} 4 cost(0,5) "-(" reg ")" . + +ext_addr = {ADDR bd;} 4 cost(4,5) "#" bd . +llabel = {ADDR bd;} 4 cost(2,0) bd . +slabel = {ADDR bd;} 4 cost(0,0) bd . +shconst = {INT num;} 4 cost(0,0) "#" num . + +#ifndef m68020 + /* Part (ii) */ +absolute4 = {ADDR bd;} 4 cost(4,8) bd . +offsetted4 = {A_REG reg; INT bd;} 4 cost(2,6) bd "(" reg ")" . +index_off4 = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,7) + bd "(" reg "," xreg ".l)" . +absolute2 = {ADDR bd;} 4 cost(4,6) bd . +offsetted2 = {A_REG reg; INT bd;} 4 cost(2,4) bd "(" reg ")" . +index_off2 = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,5) + bd "(" reg "," xreg ".l)" . +absolute1 = {ADDR bd;} 4 cost(4,6) bd . +offsetted1 = {A_REG reg; INT bd;} 4 cost(2,4) bd "(" reg ")" . +index_off1 = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,5) + bd "(" reg "," xreg ".l)" . + +LOCAL = {INT bd;} 4 cost(2,6) bd "(a6)" . + +local_addr = {INT bd;} 4 cost(2,6) bd "(a6)" . +regAcon = {A_REG reg; INT bd;} 4 cost(2,6) bd "(" reg ")" . +regAregXcon = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,8) + bd "(" reg "," xreg ".l)" . + /* note: in the m68k4 version %sc always equals 1 */ + +t_regAregXcon = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,8) . +t_regAcon = {A_REG reg; INT bd;} 4 cost(2,6) . + +#else m68020 + /* Part (iii) */ +absolute4 = {ADDR bd;} 4 cost(4,7) "(" bd ")" . +offsetted4 = {A_REG reg; INT bd;} 4 cost(2,6) "(" bd "," reg ")" . +index_off4 = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(4,9) + "(" bd "," reg "," xreg ".l*" sc ")" . +abs_index4 = {INT sc; D_REG xreg; ADDR bd;} 4 cost(6,9) + "(" bd "," xreg ".l*" sc ")" . +OFF_off4 = {A_REG reg; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "]," od ")" . +OFF_indoff4 = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "]," xreg ".l*" sc "," od ")" . +INDOFF_off4 = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "," xreg ".l*" sc "]," od ")" . +ABS_off4 = {ADDR bd; ADDR od;} 4 cost(8,22) "([" bd "]," od ")" . +ABS_indoff4 = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,22) + "([" bd "]," xreg ".l*" sc "," od ")" . +ABSIND_off4 = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,22) + "([" bd "," xreg ".l*" sc "]," od ")" . + +absolute2 = {ADDR bd;} 4 cost(4,7) "(" bd ")" . +offsetted2 = {A_REG reg; INT bd;} 4 cost(2,6) "(" bd "," reg ")" . +index_off2 = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(4,9) + "(" bd "," reg "," xreg ".l*" sc ")" . +abs_index2 = {INT sc; D_REG xreg; ADDR bd;} 4 cost(6,9) + "(" bd "," xreg ".l*" sc ")" . +OFF_off2 = {A_REG reg; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "]," od ")" . +OFF_indoff2 = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "]," xreg ".l*" sc "," od ")" . +INDOFF_off2 = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "," xreg ".l*" sc "]," od ")" . +ABS_off2 = {ADDR bd; ADDR od;} 4 cost(8,22) "([" bd "]," od ")" . +ABS_indoff2 = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,22) + "([" bd "]," xreg ".l*" sc "," od ")" . +ABSIND_off2 = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,22) + "([" bd "," xreg ".l*" sc "]," od ")" . + +absolute1 = {ADDR bd;} 4 cost(4,7) "(" bd ")" . +offsetted1 = {A_REG reg; INT bd;} 4 cost(2,6) "(" bd "," reg ")" . +index_off1 = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(4,9) + "(" bd "," reg "," xreg ".l*" sc ")" . +abs_index1 = {INT sc; D_REG xreg; ADDR bd;} 4 cost(6,9) + "(" bd "," xreg ".l*" sc ")" . +OFF_off1 = {A_REG reg; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "]," od ")" . +OFF_indoff1 = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "]," xreg ".l*" sc "," od ")" . +INDOFF_off1 = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "," xreg ".l*" sc "]," od ")" . +ABS_off1 = {ADDR bd; ADDR od;} 4 cost(8,22) "([" bd "]," od ")" . +ABS_indoff1 = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,22) + "([" bd "]," xreg ".l*" sc "," od ")" . +ABSIND_off1 = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,22) + "([" bd "," xreg ".l*" sc "]," od ")" . + +LOCAL = {INT bd;} 4 cost(2,6) "(" bd ",a6)" . +ILOCAL = {INT bd;} 4 cost(4,16) "([" bd ",a6])" . + +local_addr = {INT bd;} 4 cost(2,3) "(" bd ",a6)" . +regAcon = {A_REG reg; INT bd;} 4 cost(2,3) "(" bd "," reg ")" . +regAregXcon = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,7) + "(" bd "," reg "," xreg ".l*" sc ")" . +off_con = {A_REG reg; INT bd; ADDR od;} 4 cost(6,18) + "([" bd "," reg "]," od ")". +off_regXcon = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,18) + "([" bd "," reg "]," xreg ".l*" sc "," od ")" . +indoff_con = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,18) + "([" bd "," reg "," xreg ".l*" sc "]," od ")" . +abs_con = {ADDR bd; ADDR od;} 4 cost(8,21) "([" bd "]," od ")" . +abs_regXcon = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,21) + "([" bd "]," xreg ".l*" sc "," od ")" . +absind_con = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,21) + "([" bd "," xreg ".l*" sc "]," od ")" . +ext_regX = {INT sc; D_REG xreg; ADDR bd;} 4 cost(6,15) + "(" bd "," xreg ".l*" sc ")" . + +regX = {INT sc; D_REG xreg;} 4 cost(2,7) "(" xreg ".l*" sc ")" . +DREG_pair = {D_REG reg1; D_REG reg2;} 8 cost(2,0) reg1 ":" reg2 . + +#define t_regAregXcon regAregXcon +#define t_regAcon regAcon + +#endif m68020 + +SETS + + /* The SETS list cannot be kept as 'readable' as the TOKENS list + * because cgg is one pass. + */ + +#ifndef m68020 + /* A m68k4 part */ +data4 = D_REG + LOCAL + const + post_inc4 + pre_dec4 + + indirect4 + offsetted4 + index_off4 + absolute4 + + ext_addr . +memory4 = data4 - D_REG . +control4 = indirect4 + offsetted4 + index_off4 + absolute4 + + LOCAL . +alterable4 = data4 + A_REG - const - ext_addr . +any4 = data4 + A_REG . /* all four above together */ + +data2 = D_REG + post_inc2 + pre_dec2 + indirect2 + + offsetted2 + index_off2 + absolute2 + const . +memory2 = data2 - D_REG . +control2 = indirect2 + offsetted2 + index_off2 + absolute2 . +alterable2 = data2 + A_REG - const . +any2 = data2 + A_REG . + +data1 = D_REG + post_inc1 + pre_dec1 + indirect1 + + offsetted1 + index_off1 + absolute1 + const . +memory1 = data1 - D_REG . +control1 = indirect1 + offsetted1 + index_off1 + absolute1 . +alterable1 = data1 - const . +any1 = data1 . + +#else m68020 + +data4 = D_REG + indirect4 + post_inc4 + pre_dec4 + index_off4 + + offsetted4 + OFF_off4 + OFF_indoff4 + + INDOFF_off4 + + ABS_off4 + ABS_indoff4 + ABSIND_off4 + + absolute4 + abs_index4 + const + ext_addr + + LOCAL + ILOCAL . +memory4 = data4 - D_REG . +control4 = memory4 - (post_inc4 + pre_dec4 + const + ext_addr) . +alterable4 = data4 + A_REG - const - ext_addr . +any4 = data4 + A_REG . /* all four above together */ + +data2 = D_REG + indirect2 + post_inc2 + pre_dec2 + index_off2 + + offsetted2 + OFF_off2 + OFF_indoff2 + + INDOFF_off2 + + ABS_off2 + ABS_indoff2 + ABSIND_off2 + + absolute2 + abs_index2 + const . +memory2 = data2 - D_REG . +control2 = memory2 - (post_inc2 + pre_dec2 + const) . +alterable2 = data2 + A_REG - const . +any2 = data2 + A_REG . /* all four above together */ + +data1 = D_REG + indirect1 + post_inc1 + pre_dec1 + index_off1 + + offsetted1 + OFF_off1 + OFF_indoff1 + + INDOFF_off1 + + ABS_off1 + ABS_indoff1 + ABSIND_off1 + + absolute1 + abs_index1 + const . +memory1 = data1 - D_REG . +control1 = memory1 - (post_inc1 + pre_dec1 + const) . +alterable1 = data1 - const . +any1 = data1 . /* all four above together */ + +#endif m68020 + /* This is a common part */ +any = any4 + any2 + any1 . +absolute = absolute4 + absolute2 + absolute1 . +control = control4 + control2 + control1 . +indirect = indirect4 + indirect2 + indirect1 . +pre_post = pre_dec4 + pre_dec2 + pre_dec1 + + post_inc4 + post_inc2 + post_inc1 . +offsetted = offsetted4 + offsetted2 + offsetted1 . +index_off = index_off4 + index_off2 + index_off1 . + +#ifndef m68020 + /* A m68k4 part */ +regind_addr = regAcon + regAregXcon + t_regAcon + t_regAregXcon . +address = ext_addr + local_addr + regAcon + regAregXcon . +all_regind = indirect + offsetted + pre_post + index_off + + regind_addr . +all_indir = all_regind . +allexceptcon = ALL - ( D_REG + A_REG + const + + local_addr + ext_addr + regAcon + regAregXcon + + t_regAcon + t_regAregXcon ) . +use_index = index_off4 + index_off2 + index_off1 . + +#else m68020 + +reg_memind4 = OFF_off4 + OFF_indoff4 + INDOFF_off4 . +memind4 = reg_memind4 + + ABS_off4 + ABS_indoff4 . +reg_memind2 = OFF_off2 + OFF_indoff2 + INDOFF_off2 . +memind2 = reg_memind2 + + ABS_off2 + ABS_indoff2 . +reg_memind1 = OFF_off1 + OFF_indoff1 + INDOFF_off1 . +memind1 = reg_memind1 + + ABS_off1 + ABS_indoff1 . +reg_memind = reg_memind4 + reg_memind2 + reg_memind1 . +memind = memind4 + memind2 + memind1 . +regind_addr = regAcon + regAregXcon + + off_con + off_regXcon + + indoff_con . +address = regind_addr + + ext_addr + local_addr + + abs_con + abs_regXcon + + absind_con + + ext_regX . +all_regind = indirect + offsetted + index_off + pre_post + + reg_memind + regind_addr . +all_indir = all_regind + memind + ILOCAL . +allexceptcon = ALL - ( D_REG + A_REG + const + + local_addr + ext_addr + regAcon + regAregXcon + ext_regX ) . +use_index4 = index_off4 + abs_index4 + + OFF_indoff4 + INDOFF_off4 + + ABS_indoff4 + ABSIND_off4 . +use_index2 = index_off2 + abs_index2 + + OFF_indoff2 + INDOFF_off2 + + ABS_indoff2 + ABSIND_off2 . +use_index1 = index_off1 + abs_index1 + + OFF_indoff1 + INDOFF_off1 + + ABS_indoff1 + ABSIND_off1 . +use_indaddr = regAregXcon + + off_regXcon + indoff_con + + abs_regXcon + absind_con + + ext_regX . + +use_index = use_index4 + use_index2 + use_index1 + use_indaddr + regX . + +#endif m68020 + /* A common part */ +posextern = absolute + all_indir . + +genreg = D_REG + A_REG. +label = llabel + slabel . +immediate4 = const + ext_addr . +conreg4 = D_REG + immediate4 . +conreg2 = D_REG + const . +conreg1 = D_REG + const . +shconreg = D_REG + shconst . +datalt4 = data4 * alterable4 . +datalt2 = data2 * alterable2 . +datalt1 = data1 * alterable1 . +datalt = datalt4 + datalt2 + datalt1 . +memalt4 = memory4 * alterable4 . +memalt2 = memory2 * alterable2 . +memalt1 = memory1 * alterable1 . + +#ifndef m68020 + /* A m68k4 part */ +imm_cmp4 = alterable4 . +imm_cmp2 = alterable2 . +imm_cmp1 = datalt1 . + +test_set4 = datalt4 . +test_set2 = datalt2 . +test_set1 = datalt1 . + +#else m68020 + +imm_cmp4 = any4 - immediate4 . +imm_cmp2 = any2 - const . +imm_cmp1 = data1 - const . + +test_set4 = data4 - immediate4 . +test_set2 = data2 - const . +test_set1 = data1 - const . + +#endif m68020 + +test_set = test_set4 + test_set2 + test_set1 . + +#ifndef m68020 +t_address = address + t_regAregXcon + t_regAcon . +#else m68020 +#define t_address address +#endif m68020 + + +INSTRUCTIONS + + /* Since the 68000 , the 68010 and the 68020 instruction sets are rather + * extensive, especially because e.g. 'add.l' and 'add.w' are + * considered different instructions, only those instructions are + * listed here that are used in the rest of this table. + * + * Instruction timing cost cannot be accurately given, nor the timing + * cost for getting operands. Detailed information about this can be + * found in the "MC68020 User's Manual", section 9, about instruction + * timing. The cost used in this table are 'worst case' cost, as + * mentioned in section 9 of the user's manual. + * + * The first few instructions had to be added because register + * variables are used. The LOCALs below are register variables. + * One may not conclude that these operations are also allowed + * on LOCALs that are not register variables. + * The cost have been adapted, but are not accurate; when 'real' + * LOCALs are used the cost are very inaccurate. + */ + +add_l "add.l" any4:ro, LOCAL:rw:cc cost(0,0). +lea address:ro, LOCAL:wo cost(0,0). +sub_l "sub.l" any4:ro, LOCAL:rw:cc cost(0,0). +sh "illegal" shconreg:ro, LOCAL:rw:cc cost(0,0). +sh "illegal" LOCAL:ro, LOCAL:rw:cc cost(0,0). +xxx "illegal" data4:ro, LOCAL:rw:cc cost(0,0). +xxx "illegal" LOCAL:ro, alterable4:rw:cc cost(0,0). +#ifdef m68020 +divs_l "divs.l" data4:ro, LOCAL:rw:cc cost(0,90). +divu_l "divu.l" data4:ro, LOCAL:rw:cc cost(0,78). +muls_l "muls.l" data4:ro, LOCAL:rw:cc cost(0,44). +mulu_l "mulu.l" data4:ro, LOCAL:rw:cc cost(0,44). +#endif m68020 + +add_l "add.l" any4:ro, D_REG:rw:cc cost(2,3). +add_l "add.l" any4:ro, A_REG:rw cost(2,3). +add_l "add.l" conreg4:ro, alterable4:rw:cc cost(2,6). +and_l "and.l" data4:ro, D_REG:rw:cc cost(2,3). +and_l "and.l" D_REG:ro, memalt4:rw:cc cost(2,6). +and_l "and.l" const:ro, datalt4:rw:cc cost(2,6). +asl_l "asl.l" shconreg:ro, D_REG:rw:cc cost(2,5). +asl "asl #1," memalt2:rw:cc cost(2,4). +asr_l "asr.l" shconreg:ro, D_REG:rw:cc cost(2,4). +asr "asr #1," memalt2:rw:cc cost(2,4). +bra label cost(2,5). +bcc label cost(2,5). +bcs label cost(2,5). +beq label cost(2,5). +bge label cost(2,5). +bgt label cost(2,5). +bhi label cost(2,5). +ble label cost(2,5). +bls label cost(2,5). +blt label cost(2,5). +bmi label cost(2,5). +bne label cost(2,5). +bpl label cost(2,5). +bvc label cost(2,5). +bvs label cost(2,5). +bset conreg2:ro, D_REG:rw kills :cc cost(2,4). +btst conreg2:ro, data1:rw kills :cc cost(2,3). +clr_l "clr.l" D_REG:wo:cc cost(2,3). +clr_l "clr.l" memalt4:wo:cc cost(2,6). +clr_w "clr.w" D_REG:wo:cc cost(2,2). +clr_w "clr.w" memalt2:wo:cc cost(2,4). +clr_b "clr.b" D_REG:wo:cc cost(2,2). +clr_b "clr.b" memalt1:wo:cc cost(2,4). +cmp_l "cmp.l" any4:ro, genreg:ro kills :cc cost(2,3). +cmp_l "cmp.l" post_inc4:ro, post_inc4:ro kills :cc cost(2,2). +cmp_l "cmp.l" immediate4:ro, imm_cmp4:ro kills :cc cost(2,2). +cmp_w "cmp.w" any2:ro, genreg:ro kills :cc cost(2,3). +cmp_w "cmp.w" post_inc2:ro, post_inc2:ro kills :cc cost(2,2). +cmp_w "cmp.w" const:ro, imm_cmp2:ro kills :cc cost(2,2). +cmp_b "cmp.b" data1:ro, D_REG:ro kills :cc cost(2,3). +cmp_b "cmp.b" post_inc1:ro, post_inc1:ro kills :cc cost(2,2). +cmp_b "cmp.b" const:ro, imm_cmp1:ro kills :cc cost(2,2). +dbf D_REG:rw, label cost(2,5). +eor_l "eor.l" conreg4:ro, datalt4:rw:cc cost(2,6). +ext_l "ext.l" D_REG:rw:cc cost(2,2). +ext_w "ext.w" D_REG:rw:cc cost(2,2). +jmp address+control4 cost(2,0). +jsr address+control4 kills :cc cost(2,3). +lea address+control4:ro, A_REG:wo cost(2,0). +lsl_l "lsl.l" shconreg:ro, D_REG:rw:cc cost(2,4). +lsl "lsl #1," memalt2:rw:cc cost(2,4). +lsr_l "lsr.l" shconreg:ro, D_REG:rw:cc cost(2,4). +lsr "lsr #1," memalt2:rw:cc cost(2,4). +move_l "move.l" any4:ro, alterable4:wo:cc cost(2,2). +move_w "move.w" any2:ro, alterable2:wo:cc cost(2,2). +move_b "move.b" data1:ro, alterable1:wo:cc cost(2,2). +neg_l "neg.l" D_REG:rw:cc cost(2,3). +neg_l "neg.l" memory4:rw:cc cost(2,6). +not_l "not.l" D_REG:rw:cc cost(2,3). +not_l "not.l" memory4:rw:cc cost(2,6). +or_l "or.l" data4:ro, D_REG:rw:cc cost(2,3). +or_l "or.l" D_REG:ro, memalt4:rw:cc cost(2,6). +or_l "or.l" const:ro, datalt4:rw:cc cost(2,6). +rol_l "rol.l" shconreg:ro, D_REG:rw:cc cost(2,4). +rol "rol #1," memalt2:rw:cc cost(2,4). +ror_l "ror.l" shconreg:ro, D_REG:rw:cc cost(2,4). +ror "ror #1," memalt2:rw:cc cost(2,4). +roxl "roxl #1," memalt2:rw:cc cost(2,4). +roxr "roxr #1," memalt2:rw:cc cost(2,4). +sne datalt1:rw cost(2,3). +sub_l "sub.l" any4:ro, D_REG:rw:cc cost(2,3). +sub_l "sub.l" any4:ro, A_REG:rw cost(2,3). +sub_l "sub.l" conreg4:ro, alterable4:rw:cc cost(2,6). +tst_l "tst.l" test_set4:ro:cc cost(2,3). +tst_w "tst.w" test_set2:ro:cc cost(2,3). +tst_b "tst.b" test_set1:ro:cc cost(2,3). +unlk A_REG cost(2,6). + +bxx "illegal" label cost(2,5). +xxx "illegal" data4:ro, D_REG:rw:cc cost(2,3). +xxx "illegal" conreg4:ro, memalt4:rw:cc cost(2,6). +bit "illegal" control4:rw:cc cost(2,6). +sh "illegal" shconreg:ro, D_REG:rw:cc cost(2,4). +shw "illegal" control2:rw:cc cost(2,4). + +#ifdef m68020 +cmp2_l "cmp2.l" address+control4:ro, genreg:ro kills :cc cost(2,18). +divs_l "divs.l" data4:ro, D_REG:rw:cc cost(2,90). +divsl_l "divsl.l" data4:ro, DREG_pair:rw kills :cc cost(2,90). +divu_l "divu.l" data4:ro, D_REG:rw:cc cost(2,78). +divul_l "divul.l" data4:ro, DREG_pair:rw kills :cc cost(2,78). +extb_l "extb.l" D_REG:rw:cc cost(2,4). +muls_l "muls.l" data4:ro, D_REG:rw:cc cost(2,44). +mulu_l "mulu.l" data4:ro, D_REG:rw:cc cost(2,44). +pea address+control4+regX cost(2,4). +#else m68020 +pea address+control4 cost(2,4). +#endif m68020 + + /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * Extra pseudo instruction; it just kills a D_REG; + * it is necessary with long divides where remainders are important; + * see also: 'pat rmi' and 'pat rmu' + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ +killreg "! kill" D_REG:wo cost(0,0). + + +MOVES + +from const %num==0 to D_REG + gen clr_l %2 + +from const %num==0 to memalt4 + gen clr_l %2 + +from const %num==0 to memalt2 + gen clr_w %2 + +from const %num==0 to memalt1 + gen clr_b %2 + +from const to memalt1 + gen move_b {const, lowb(%1.num)}, %2 + +from const to memalt2 + gen move_w {const, loww(%1.num)}, %2 + +from regAcon %bd==0 to A_REG + gen move_l %1.reg, %2 + +#ifndef m68020 +from t_regAregXcon sfit(%bd, 8) to A_REG + gen lea {regAregXcon, %1.reg, %1.xreg, 1, %1.bd}, %2 + +from t_regAregXcon to A_REG + gen lea {regAregXcon, %1.reg, %1.xreg, 1, 0}, %2 + add_l {const, %1.bd}, %2 + +from t_regAcon sfit(%bd, 16) to A_REG + gen lea {regAcon, %1.reg, %1.bd}, %2 + +from t_regAcon to A_REG + gen move_l %1.reg, %2 + add_l {const, %1.bd}, %2 +#endif m68020 + +from address - ext_addr to A_REG + gen lea %1, %2 + +from any4 to alterable4 + gen move_l %1, %2 + +from any2 to datalt2 + gen move_w %1, %2 + +from data1 to datalt1 + gen move_b %1, %2 + + + + +TESTS + + +to test test_set4 + gen tst_l %1 + +to test test_set2 + gen tst_w %1 + +to test test_set1 + gen tst_b %1 + + +STACKINGRULES + + +from const %num==0 to STACK + gen clr_l {pre_dec4, sp} + +#ifndef m68020 +from t_regAregXcon sfit(%bd, 8) to STACK + gen pea {regAregXcon, %1.reg, %1.xreg, 1, %1.bd} + +from t_regAregXcon to STACK + gen pea {regAregXcon, %1.reg, %1.xreg, 1, 0} + add_l {const, %1.bd}, {indirect4, sp} + +from t_regAcon sfit(%bd, 16) to STACK + gen pea {regAcon, %1.reg, %1.bd} + +from t_regAcon to STACK + gen move_l %1.reg, {pre_dec4, sp} + add_l {const, %1.bd}, {indirect4, sp} +#endif m68020 + +from address - ext_addr to STACK + gen pea %1 + +from ext_addr to STACK + gen pea {absolute4, %1.bd} + +from const to STACK + gen pea {absolute4, %1.num} + +from any4 to STACK + gen move_l %1, {pre_dec4, sp} + +from any2 to STACK + gen clr_l {pre_dec4, sp} + move_w %1, {offsetted2, sp, 2} + +from data1 to STACK + gen clr_l {pre_dec4, sp} + move_b %1, {offsetted1, sp, 3} + +#ifdef m68020 +from regX to STACK + gen pea %1 +#endif m68020 + /* This last stackingrule is never used: whenever regX is put on + * the fakestack, some em-instuctions are left that remove it + * immediately. However cgg complained about not having a + * stackingrule for regX, so here it is + */ + + +COERCIONS + + +from STACK + uses DD_REG + gen move_l {post_inc4, sp}, %a + yields %a + +from STACK + uses AA_REG + gen move_l {post_inc4, sp}, %a + yields %a + +#ifndef m68020 +from t_regAregXcon sfit(%bd, 8) + yields {regAregXcon, %1.reg, %1.xreg, 1, %1.bd} + +from t_regAregXcon + uses AA_REG=%1.reg + gen add_l {const, %1.bd}, %a + yields {regAregXcon, %a, %1.xreg, 1, 0} + +from t_regAcon sfit(%bd, 16) + yields {regAcon, %1.reg, %1.bd} + +from t_regAcon + uses reusing %1, AA_REG=%1.reg + gen add_l {const, %1.bd}, %a + yields %a +#endif m68020 + +from t_address + uses reusing %1, AA_REG = %1 + yields %a + +from any4 + uses reusing %1, DD_REG = %1 + yields %a + +from any4 + uses reusing %1, AA_REG = %1 + yields %a + +from memory2 + uses DD_REG = {const, 0} + gen move_w %1, %a yields %a + +from memory1 + uses DD_REG = {const, 0} + gen move_b %1, %a yields %a + + + + +PATTERNS + +/************************************************ + * Group 0: rules for register variables * + * LOCALs mentioned here refer to registers * + ************************************************/ + +pat lol inreg($1)==reg_pointer + kills pre_post %reg==regvar($1, reg_pointer) + yields {LOCAL, $1} + +pat lil inreg($1)==reg_pointer + kills pre_post %reg==regvar($1, reg_pointer) + yields {indirect4, regvar($1, reg_pointer)} + +pat stl inreg($1)==reg_any +with any4 + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen move %1, {LOCAL, $1} + +pat stl inreg($1)==reg_pointer +with any4 + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + gen move %1, {LOCAL, $1} +with exact ext_addr + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + gen move %1, {LOCAL, $1} +with exact address-ext_addr + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + gen lea %1, {LOCAL, $1} + +pat sil inreg($1)==reg_pointer +with any4 + kills allexceptcon + gen move %1, {indirect4, regvar($1, reg_pointer)} + + +pat lol sbi stl $1==$3 && $2==4 && inreg($1)==reg_any +with any4 + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen sub_l %1, {LOCAL, $1} + neg_l {LOCAL, $1} + +pat lol sbu stl $1==$3 && $2==4 && inreg($1)==reg_any +with any4 + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen sub_l %1, {LOCAL, $1} + neg_l {LOCAL, $1} + +pat lil sbi sil $1==$3 && $2==4 && inreg($1)==reg_pointer +with conreg4 + kills allexceptcon + gen sub_l %1, {indirect4, regvar($1, reg_pointer)} + neg_l {indirect4, regvar($1, reg_pointer)} + +pat lil sbu sil $1==$3 && $2==4 && inreg($1)==reg_pointer +with conreg4 + kills allexceptcon + gen sub_l %1, {indirect4, regvar($1, reg_pointer)} + neg_l {indirect4, regvar($1, reg_pointer)} + + +pat lil ngi sil $1==$3 && $2==4 && inreg($1)==reg_pointer + kills allexceptcon + gen neg_l {indirect4, regvar($1, reg_pointer)} + +pat lil com sil $1==$3 && $2==4 && inreg($1)==reg_pointer + kills allexceptcon + gen not_l {indirect4, regvar($1, reg_pointer)} + + +proc lolcshstl example lol loc sli stl + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen sh* {shconst, $2}, {LOCAL, $1} + +proc lolrshstl example lol lol sli stl + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen sh* {LOCAL, $2}, {LOCAL, $1} + +proc lil1shlsil example lil loc sli sil /* only left */ + kills allexceptcon + gen shw* {offsetted2, regvar($1, reg_pointer), 2} + roxl {indirect2, regvar($1, reg_pointer)} + +proc lil1shrsil example lil loc sli sil /* only right */ + kills allexceptcon + gen shw* {indirect2, regvar($1, reg_pointer)} + roxr {offsetted2, regvar($1, reg_pointer), 2} + +pat lol loc sli stl $1==$4 && small($2) && $3==4 && inreg($1)==reg_any + call lolcshstl("asl.l") +pat lol loc slu stl $1==$4 && small($2) && $3==4 && inreg($1)==reg_any + call lolcshstl("asl.l") +pat lol lol sli stl $1==$4 && inreg($1)==reg_any && $3==4 && inreg($2)==reg_any + call lolrshstl("asl.l") +pat lol lol slu stl $1==$4 && inreg($1)==reg_any && $3==4 && inreg($2)==reg_any + call lolrshstl("asl.l") +pat lil loc sli sil $1==$4 && $2==1 && $3==4 && inreg($1)==reg_pointer + call lil1shlsil("asl #1,") +pat lil loc slu sil $1==$4 && $2==1 && $3==4 && inreg($1)==reg_pointer + call lil1shlsil("asl #1,") +pat lol loc sri stl $1==$4 && small($2) && $3==4 && inreg($1)==reg_any + call lolcshstl("asr.l") +pat lol loc sru stl $1==$4 && small($2) && $3==4 && inreg($1)==reg_any + call lolcshstl("lsr.l") +pat lol lol sri stl $1==$4 && inreg($1)==reg_any && $3==4 && inreg($2)==reg_any + call lolrshstl("asr.l") +pat lol lol sru stl $1==$4 && inreg($1)==reg_any && $3==4 && inreg($2)==reg_any + call lolrshstl("lsr.l") +pat lil loc sri sil $1==$4 && $2==1 && $3==4 && inreg($1)==reg_pointer + call lil1shrsil("asr #1,") +pat lil loc sru sil $1==$4 && $2==1 && $3==4 && inreg($1)==reg_pointer + call lil1shrsil("lsr #1,") +pat lol loc rol stl $1==$4 && small($2) && $3==4 && inreg($1)==reg_any + call lolcshstl("rol.l") +pat lol lol rol stl $1==$4 && inreg($2)==reg_any && $3==4 && inreg($1)==reg_any + call lolrshstl("rol.l") +pat lol loc ror stl $1==$4 && small($2) && $3==4 && inreg($1)==reg_any + call lolcshstl("ror.l") +pat lol lol ror stl $1==$4 && inreg($2)==reg_any && $3==4 && inreg($1)==reg_any + call lolrshstl("ror.l") + +#ifdef m68020 +pat lol loc dvi stl $1==$4 && $3==4 && inreg($1)==reg_any + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen divs_l {const, $2}, {LOCAL, $1} + +pat lol loc dvu stl $1==$4 && $3==4 && inreg($1)==reg_any + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen divu_l {const, $2}, {LOCAL, $1} + +pat lol loc mli stl $1==$4 && $3==4 && inreg($1)==reg_any + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen muls_l {const, $2}, {LOCAL, $1} + +pat lol loc mlu stl $1==$4 && $3==4 && inreg($1)==reg_any + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen mulu_l {const, $2}, {LOCAL, $1} + +pat lol mli stl $1==$3 && $2==4 && inreg($1)==reg_any + with data4 + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen muls_l %1, {LOCAL, $1} + +pat lol mlu stl $1==$3 && $2==4 && inreg($1)==reg_any + with data4 + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen mulu_l %1, {LOCAL, $1} +#endif m68020 + + +pat lil inc sil $1==$3 && inreg($1)==reg_pointer + kills allexceptcon + gen add_l {const, 1}, {indirect4, regvar($1, reg_pointer)} + +pat lil dec sil $1==$3 && inreg($1)==reg_pointer + kills allexceptcon + gen sub_l {const, 1}, {indirect4, regvar($1, reg_pointer)} + +pat inl inreg($1)==reg_any + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen add_l {const, 1}, {LOCAL, $1} + +pat del inreg($1)==reg_any + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen sub_l {const, 1}, {LOCAL, $1} + +pat zrl inreg($1)==reg_any + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen clr_l {LOCAL, $1} + +pat zrl inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + gen move_l {const, 0}, {LOCAL, $1} + + +proc lolxxstl example lol and stl +with data4 + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen xxx* %1, {LOCAL, $1} + +proc lilxxsil example lil and sil +with conreg4 + kills allexceptcon + gen xxx* %1, {indirect4, regvar($1, reg_pointer)} + +proc lolcxxstl example lol loc and stl + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen xxx* {const, $2}, {LOCAL, $1} + +proc lilcxxsil example lil loc and sil + kills allexceptcon + gen xxx* {const, $2}, {indirect4, regvar($1, reg_pointer)} + +proc lolrxxstl example lol lol and stl + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen xxx* {LOCAL, $2}, {LOCAL, $1} + +proc lilrxxsil example lil lol and sil + kills allexceptcon + gen xxx* {LOCAL, $2}, {indirect4, regvar($1, reg_pointer)} + +pat lol adi stl $1==$3 && $2==4 && inreg($1)==reg_any + call lolxxstl("add.l") +pat lol loc adi stl $1==$4 && $3==4 && inreg($1)==reg_any + call lolcxxstl("add.l") +pat lil adi sil $1==$3 && $2==4 &&inreg($1)==reg_pointer + call lilxxsil("add.l") +pat lil loc adi sil $1==$4 && $3==4 && inreg($1)==reg_pointer + call lilcxxsil("add.l") +pat lol lol adi stl $1==$4 && $3==4 && inreg($1)==reg_any && inreg($2)==reg_any + call lolrxxstl("add.l") +pat lil lol adi sil $1==$4 && $3==4 && inreg($1)==reg_pointer && + inreg($2)==reg_any + call lilrxxsil("add.l") +pat lol adu stl $1==$3 && $2==4 && inreg($1)==reg_any + call lolxxstl("add.l") +pat lol loc adu stl $1==$4 && $3==4 && inreg($1)==reg_any + call lolcxxstl("add.l") +pat lil adu sil $1==$3 && $2==4 &&inreg($1)==reg_pointer + call lilxxsil("add.l") +pat lil loc adu sil $1==$4 && $3==4 && inreg($1)==reg_pointer + call lilcxxsil("add.l") +pat lol lol adu stl $1==$4 && $3==4 && inreg($1)==reg_any && inreg($2)==reg_any + call lolrxxstl("add.l") +pat lil lol adu sil $1==$4 && $3==4 && inreg($1)==reg_pointer && + inreg($2)==reg_any + call lilrxxsil("add.l") +pat lol loc sbi stl $1==$4 && $3==4 && inreg($1)==reg_any + call lolcxxstl("sub.l") +pat lil loc sbi sil $1==$4 && $3==4 && inreg($1)==reg_pointer + call lilcxxsil("sub.l") +pat lol lol sbi stl $1==$4 && $3==4 && inreg($1)==reg_any && inreg($2)==reg_any + call lolrxxstl("sub.l") +pat lil lol sbi sil $1==$4 && $3==4 && inreg($1)==reg_pointer && + inreg($2)==reg_any + call lilrxxsil("sub.l") +pat lol loc sbu stl $1==$4 && $3==4 && inreg($1)==reg_any + call lolcxxstl("sub.l") +pat lil loc sbu sil $1==$4 && $3==4 && inreg($1)==reg_pointer + call lilcxxsil("sub.l") +pat lol lol sbu stl $1==$4 && $3==4 && inreg($1)==reg_any && inreg($2)==reg_any + call lolrxxstl("sub.l") +pat lil lol sbu sil $1==$4 && $3==4 && inreg($1)==reg_pointer && + inreg($2)==reg_any + call lilrxxsil("sub.l") +pat lol and stl $1==$3 && $2==4 && inreg($1)==reg_any + call lolxxstl("and.l") +pat lol loc and stl $1==$4 && $3==4 && inreg($1)==reg_any + call lolcxxstl("and.l") +pat lil and sil $1==$3 && $2==4 &&inreg($1)==reg_pointer + call lilxxsil("and.l") +pat lil loc and sil $1==$4 && $3==4 && inreg($1)==reg_pointer + call lilcxxsil("and.l") +pat lol lol and stl $1==$4 && $3==4 && inreg($1)==reg_any && inreg($2)==reg_any + call lolrxxstl("and.l") +pat lil lol and sil $1==$4 && $3==4 && inreg($1)==reg_pointer && + inreg($2)==reg_any + call lilrxxsil("and.l") +pat lol ior stl $1==$3 && $2==4 && inreg($1)==reg_any + call lolxxstl("or.l") +pat lol loc ior stl $1==$4 && $3==4 && inreg($1)==reg_any + call lolcxxstl("or.l") +pat lil ior sil $1==$3 && $2==4 && inreg($1)==reg_pointer + call lilxxsil("or.l") +pat lil loc ior sil $1==$4 && $3==4 && inreg($1)==reg_pointer + call lilcxxsil("or.l") +pat lol lol ior stl $1==$4 && $3==4 && inreg($1)==reg_any && + inreg($2)==reg_any + call lolrxxstl("or.l") +pat lil lol ior sil $1==$4 && $3==4 && inreg($1)==reg_pointer && + inreg($2)==reg_any + call lilrxxsil("or.l") +pat lol xor stl $1==$3 && $2==4 && inreg($1)==reg_any + call lolxxstl("eor.l") +pat lol loc xor stl $1==$4 && $3==4 && inreg($1)==reg_any + call lolcxxstl("eor.l") +pat lil xor sil $1==$3 && $2==4 &&inreg($1)==reg_pointer + call lilxxsil("eor.l") +pat lil loc xor sil $1==$4 && $3==4 && inreg($1)==reg_pointer + call lilcxxsil("eor.l") +pat lol lol xor stl $1==$4 && $3==4 && inreg($1)==reg_any && + inreg($2)==reg_any + call lolrxxstl("eor.l") +pat lil lol xor sil $1==$4 && $3==4 && inreg($1)==reg_pointer && + inreg($2)==reg_any + call lilrxxsil("eor.l") + +pat lil adp sil $1==$3 && inreg($1)==reg_pointer + kills allexceptcon + gen add_l {const, $2}, {indirect4, regvar($1, reg_pointer)} + +pat lil lil adp sil $1==$2 && $1==$4 && inreg($1)==reg_pointer + kills allexceptcon + uses AA_REG = {indirect4, regvar($1, reg_pointer)} + gen add_l {const, $3}, {indirect4, regvar($1, reg_pointer)} + yields %a + +pat lol lol adp stl loi $1==$2 && $1==$4 && $3==1 && $5==1 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {post_inc1, regvar($1, reg_pointer)} + +pat lol loi lol adp stl $1==$3 && $1==$5 && $2==1 && $4==1 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {post_inc1, regvar($1, reg_pointer)} + +pat lol lol adp stl loi $1==$2 && $1==$4 && $3==2 && $5==2 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {post_inc2, regvar($1, reg_pointer)} + +pat lol loi lol adp stl $1==$3 && $1==$5 && $2==2 && $4==2 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {post_inc2, regvar($1, reg_pointer)} + +pat lol lol adp stl loi $1==$2 && $1==$4 && $3==4 && $5==4 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {post_inc4, regvar($1, reg_pointer)} + +pat lil lol adp stl $1==$2 && $1==$4 && $3==4 && inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {post_inc4, regvar($1, reg_pointer)} + +pat lol lol adp stl sti $1==$2 && $1==$4 && $3==1 && $5==1 && + inreg($1)==reg_pointer +with data1 + kills allexceptcon + gen move %1, {post_inc1, regvar($1, reg_pointer)} + +pat lol sti lol adp stl $1==$3 && $1==$5 && $2==1 && $4==1 && + inreg($1)==reg_pointer +with data1 + kills allexceptcon + gen move %1, {post_inc1, regvar($1, reg_pointer)} + +pat lol lol adp stl sti $1==$2 && $1==$4 && $3==2 && $5==2 && + inreg($1)==reg_pointer +with any2 + kills allexceptcon + gen move %1, {post_inc2, regvar($1, reg_pointer)} + +pat lol sti lol adp stl $1==$3 && $1==$5 && $2==2 && $4==2 && + inreg($1)==reg_pointer +with any2 + kills allexceptcon + gen move %1, {post_inc2, regvar($1, reg_pointer)} + +pat lol lol adp stl sti $1==$2 && $1==$4 && $3==4 && $5==4 && + inreg($1)==reg_pointer +with any4 + kills allexceptcon + gen move_l %1, {post_inc4, regvar($1, reg_pointer)} + +pat sil lol adp stl $1==$2 && $1==$4 && $3==4 && inreg($1)==reg_pointer +with any4 + kills allexceptcon + gen move_l %1, {post_inc4, regvar($1, reg_pointer)} + +pat lol adp stl lol loi $1==$3 && $1==$4 && $2==0-1 && $5==1 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {pre_dec1, regvar($1, reg_pointer)} + +pat lol adp stl lol loi $1==$3 && $1==$4 && $2==0-2 && $5==2 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {pre_dec2, regvar($1, reg_pointer)} + +pat lol adp stl lil $1==$3 && $1==$4 && $2==0-4 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {pre_dec4, regvar($1, reg_pointer)} + +pat lol adp stl lol sti $1==$3 && $1==$4 && $2==0-1 && $5==1 && + inreg($1)==reg_pointer +with data1 + kills allexceptcon + gen move %1, {pre_dec1, regvar($1, reg_pointer)} + +pat lol adp stl lol sti $1==$3 && $1==$4 && $2==0-2 && $5==2 && + inreg($1)==reg_pointer +with any2 + kills allexceptcon + gen move %1, {pre_dec2, regvar($1, reg_pointer)} + +pat lol adp stl sil $1==$3 && $1==$4 && $2==0-4 && + inreg($1)==reg_pointer +with any4 + kills allexceptcon + gen move_l %1, {pre_dec4, regvar($1, reg_pointer)} + + + + +/************************************************ + * Group 1: load instructions * + ************************************************/ + +pat loc yields {const, $1} + +pat ldc leaving loc 18 trp + +pat lol yields {LOCAL, $1} + +pat ldl leaving lol $1+4 lol $1 + +pat loe yields {absolute4, $1} + +pat lil +#ifdef m68020 + yields {ILOCAL, $1} +#else m68020 + uses AA_REG = {LOCAL, $1} + yields {indirect4, %a} +#endif m68020 + + /* When using the 'offsetted' intructions regAregXcon cannot be used + * for the m68k4; there is no way of knowing about the size of + * %1.bd+$1, because expressions are not allowed in stack patterns, and + * this may lead to outputting too large displacements. With regAcon + * the chance that this will happen is very slim, because it can + * have displacements of 16 bits. Besides, leaving out regAcon here + * would make it very hard to handle this instruction efficiently. + */ +pat lof +with A_REG yields {offsetted4, %1, $1} +with exact local_addr yields {LOCAL, %1.bd+$1} +with exact ext_addr yields {absolute4, %1.bd+$1} +#ifndef m68020 +with regAcon yields {offsetted4, %1.reg, %1.bd+$1} +#else m68020 +with exact regAcon yields {offsetted4, %1.reg, %1.bd+$1} +with exact regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1} +with exact offsetted4 yields {OFF_off4, %1.reg, %1.bd, $1} +with exact indirect yields {OFF_off4, %1.reg, 0, $1} +with exact LOCAL yields {OFF_off4, lb, %1.bd, $1} +with exact off_con yields {OFF_off4, %1.reg, %1.bd, %1.od+$1} +with exact off_regXcon yields {OFF_indoff4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact index_off4 yields {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, $1} +with exact indoff_con yields {INDOFF_off4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact absolute4 yields {ABS_off4, %1.bd, $1} +with exact abs_con yields {ABS_off4, %1.bd, %1.od+$1} +with exact abs_regXcon yields {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact abs_index4 yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, $1} +with exact absind_con yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact ext_regX yields {abs_index4, %1.sc, %1.xreg, %1.bd+$1} +#endif m68020 + +pat lal yields {local_addr, $1} + +pat lae yields {ext_addr, $1} + +pat lxl $1==0 yields lb + +pat lxl $1==1 yields {LOCAL, SL} + +pat lxl $1==2 +#ifdef m68020 + yields {OFF_off4, lb, SL, SL} +#else m68020 + uses AA_REG = {LOCAL, SL} + yields {offsetted4, %a, SL} +#endif m68020 + +pat lxl $1==3 +#ifdef m68020 + uses AA_REG = {OFF_off4, lb, SL, SL} +#else m68020 + uses AA_REG = {LOCAL, SL} + gen move {offsetted4, %a, SL}, %a +#endif m68020 + yields {offsetted4, %a, SL} + +pat lxl $1>3 + uses AA_REG = {LOCAL, SL}, + DD_REG = {const, $1-2} + gen 1: + move_l {offsetted4, %a, SL} ,%a + dbf %b, {slabel, 1b} + yields %a + +pat lxa $1==0 yields {local_addr, SL} + +pat lxa $1==1 +#ifdef m68020 + yields {off_con, lb, SL, SL} +#else m68020 + uses AA_REG = {LOCAL, SL} + yields {regAcon, %a, SL} +#endif m68020 + +pat lxa $1==2 +#ifdef m68020 + uses AA_REG = {OFF_off4, lb, SL, SL} +#else m68020 + uses AA_REG = {LOCAL, SL} + gen move {offsetted4, %a, SL}, %a +#endif m68020 + yields {regAcon, %a, SL} + +pat lxa $1>2 + uses AA_REG = {LOCAL, SL}, + DD_REG = {const, $1-1} + gen 1: + move_l {offsetted4, %a, SL} ,%a + dbf %b, {slabel, 1b} + yields {regAcon, %a, SL} + +pat loi $1==1 +with A_REG yields {indirect1, %1} +with exact local_addr yields {offsetted1, lb, %1.bd} +with exact ext_addr yields {absolute1, %1.bd} +#ifndef m68020 +with regAcon yields {offsetted1, %1.reg, %1.bd} +with regAregXcon yields {index_off1, %1.reg, %1.xreg, %1.sc, %1.bd} +#else m68020 +with exact regAcon yields {offsetted1, %1.reg, %1.bd} +with exact regAregXcon yields {index_off1, %1.reg, %1.xreg, %1.sc, %1.bd} +with exact indirect4 yields {OFF_off1, %1.reg, 0, 0} +with exact offsetted4 yields {OFF_off1, %1.reg, %1.bd, 0} +with exact LOCAL yields {OFF_off1, lb, %1.bd, 0} +with exact off_con yields {OFF_off1, %1.reg, %1.bd, %1.od} +with exact off_regXcon yields {OFF_indoff1, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact index_off4 yields {INDOFF_off1, %1.reg, %1.xreg, %1.sc, %1.bd, 0} +with exact indoff_con yields {INDOFF_off1, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact absolute4 yields {ABS_off1, %1.bd, 0} +with exact abs_con yields {ABS_off1, %1.bd, %1.od} +with exact abs_regXcon yields {ABS_indoff1, %1.sc, %1.xreg, %1.bd, %1.od} +with exact abs_index4 yields {ABSIND_off1, %1.sc, %1.xreg, %1.bd, 0} +with exact absind_con yields {ABSIND_off1, %1.sc, %1.xreg, %1.bd, %1.od} +with exact ext_regX yields {abs_index1, %1.sc, %1.xreg, %1.bd} +#endif m68020 + +pat loi $1==2 +with A_REG yields {indirect2, %1} +with exact local_addr yields {offsetted2, lb, %1.bd} +with exact ext_addr yields {absolute2, %1.bd} +#ifndef m68020 +with regAcon yields {offsetted2, %1.reg, %1.bd} +with regAregXcon yields {index_off2, %1.reg, %1.xreg, %1.sc, %1.bd} +#else m68020 +with exact regAcon yields {offsetted2, %1.reg, %1.bd} +with exact regAregXcon yields {index_off2, %1.reg, %1.xreg, %1.sc, %1.bd} +with exact indirect4 yields {OFF_off2, %1.reg, 0, 0} +with exact offsetted4 yields {OFF_off2, %1.reg, %1.bd, 0} +with exact LOCAL yields {OFF_off2, lb, %1.bd, 0} +with exact off_con yields {OFF_off2, %1.reg, %1.bd, %1.od} +with exact off_regXcon yields {OFF_indoff2, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact index_off4 yields {INDOFF_off2, %1.reg, %1.xreg, %1.sc, %1.bd, 0} +with exact indoff_con yields {INDOFF_off2, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact absolute4 yields {ABS_off2, %1.bd, 0} +with exact abs_con yields {ABS_off2, %1.bd, %1.od} +with exact abs_regXcon yields {ABS_indoff2, %1.sc, %1.xreg, %1.bd, %1.od} +with exact abs_index4 yields {ABSIND_off2, %1.sc, %1.xreg, %1.bd, 0} +with exact absind_con yields {ABSIND_off2, %1.sc, %1.xreg, %1.bd, %1.od} +with exact ext_regX yields {abs_index2, %1.sc, %1.xreg, %1.bd} +#endif m68020 + +pat loi $1==4 +with A_REG yields {indirect4, %1} +with exact local_addr yields {LOCAL, %1.bd} +with exact ext_addr yields {absolute4, %1.bd} +#ifndef m68020 +with regAcon yields {offsetted4, %1.reg, %1.bd} +with regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd} +#else m68020 +with exact regAcon yields {offsetted4, %1.reg, %1.bd} +with exact regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd} +with exact LOCAL yields {ILOCAL, %1.bd} +with exact indirect4 yields {OFF_off4, %1.reg, 0, 0} +with exact offsetted4 yields {OFF_off4, %1.reg, %1.bd, 0} +with exact off_con yields {OFF_off4, %1.reg, %1.bd, %1.od} +with exact off_regXcon yields {OFF_indoff4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact index_off4 yields {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, 0} +with exact indoff_con yields {INDOFF_off4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact absolute4 yields {ABS_off4, %1.bd, 0} +with exact abs_con yields {ABS_off4, %1.bd, %1.od} +with exact abs_regXcon yields {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od} +with exact abs_index4 yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, 0} +with exact absind_con yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od} +with exact ext_regX yields {abs_index4, %1.sc, %1.xreg, %1.bd} +#endif m68020 + +pat loi $1==8 +with A_REG yields {offsetted4, %1, 4} + {indirect4, %1} +pat loi $1>8 +with AA_REG STACK + uses DD_REG = {const, $1/4 -1} + gen add_l {const, $1}, %1 + 1: + move_l {pre_dec4, %1}, {pre_dec4, sp} + dbf %a, {slabel, 1b} + +pat los $1==4 +with STACK + gen jsr {absolute4, ".los"} + +pat lde yields {absolute4, $1+4} + {absolute4, $1} + +pat ldf +with A_REG yields {offsetted4, %1, $1+4} + {offsetted4, %1, $1} +with exact local_addr yields {LOCAL, %1.bd+$1+4} + {LOCAL, %1.bd+$1} +with exact ext_addr yields {absolute4, %1.bd+$1+4} + {absolute4, %1.bd+$1} +#ifndef m68020 +with regAcon yields {offsetted4, %1.reg, %1.bd+$1+4} + {offsetted4, %1.reg, %1.bd+$1} +#else m68020 +with exact regAcon yields {offsetted4, %1.reg, %1.bd+$1+4} + {offsetted4, %1.reg, %1.bd+$1} +with exact regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1+4} + {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1} +with exact indirect4 yields {OFF_off4, %1.reg, 0, $1+4} + {OFF_off4, %1.reg, 0, $1} +with exact offsetted4 yields {OFF_off4, %1.reg, %1.bd, $1+4} + {OFF_off4, %1.reg, %1.bd, $1} +with exact LOCAL yields {OFF_off4, lb, %1.bd, $1+4} + {OFF_off4, lb, %1.bd, $1} +with exact off_con yields {OFF_off4, %1.reg, %1.bd, %1.od+$1+4} + {OFF_off4, %1.reg, %1.bd, %1.od+$1} +with exact off_regXcon yields {OFF_indoff4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1+4} + {OFF_indoff4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact index_off4 yields {INDOFF_off4, %1.reg, %1.xreg, %1.sc,%1.bd,$1+4} + {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, $1} +with exact indoff_con yields {INDOFF_off4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1+4} + {INDOFF_off4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact absolute4 yields {ABS_off4, %1.bd, $1+4} + {ABS_off4, %1.bd, $1} +with exact abs_con yields {ABS_off4, %1.bd, %1.od+$1+4} + {ABS_off4, %1.bd, %1.od+$1} +with exact abs_regXcon yields {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od+$1+4} + {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact abs_index4 yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, $1+4} + {ABSIND_off4, %1.sc, %1.xreg, %1.bd, $1} +with exact absind_con yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1+4} + {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact ext_regX yields {abs_index4, %1.sc, %1.xreg, %1.bd+$1+4} + {abs_index4, %1.sc, %1.xreg, %1.bd+$1} +#endif m68020 + +pat lpi yields {ext_addr, $1} + + + +/************************************************ + * Group 2: store instructions * + ************************************************/ + +pat stl +with any4 + kills all_indir, LOCAL %bd==$1 + gen move %1, {LOCAL, $1} +with exact STACK + gen move {post_inc4,sp}, {LOCAL, $1} + +pat ste +with any4 + kills posextern + gen move %1, {absolute4, $1} +with exact STACK + gen move {post_inc4, sp}, {absolute4, $1} + +pat sil +#ifdef m68020 +with any4 + kills allexceptcon + gen move %1, {ILOCAL, $1} +with exact STACK + gen move {post_inc4, sp}, {ILOCAL, $1} +#else m68020 +with any4 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen move %1, {indirect4, %a} +with exact STACK + uses AA_REG = {LOCAL, $1} + gen move {post_inc4, sp}, {indirect4, %a} +#endif m68020 + +pat stf +with A_REG any4 + kills allexceptcon + gen move %2, {offsetted4, %1, $1} +with A_REG STACK + gen move {post_inc4, sp}, {offsetted4, %1, $1} +with exact local_addr any4 + kills allexceptcon + gen move %2, {LOCAL, %1.bd+$1} +with exact ext_addr any4 + kills allexceptcon + gen move %2, {absolute4, %1.bd+$1} +#ifndef m68020 +with regAcon any4 + kills allexceptcon + gen move %2, {offsetted4, %1.reg, %1.bd+$1} +#else m68020 +with exact regAcon any4 + kills allexceptcon + gen move %2, {offsetted4, %1.reg, %1.bd+$1} +with exact regAregXcon any4 + kills allexceptcon + gen move %2, {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1} +with exact indirect4 any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, 0, $1} +with exact offsetted4 any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, %1.bd, $1} +with exact LOCAL any4 + kills allexceptcon + gen move %2, {OFF_off4, lb, %1.bd, $1} +with exact off_con any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, %1.bd, %1.od+$1} +with exact off_regXcon any4 + kills allexceptcon + gen move %2, {OFF_indoff4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact index_off4 any4 + kills allexceptcon + gen move %2, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, $1} +with exact indoff_con any4 + kills allexceptcon + gen move %2, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact absolute4 any4 + kills allexceptcon + gen move %2, {ABS_off4, %1.bd, $1} +with exact abs_con any4 + kills allexceptcon + gen move %2, {ABS_off4, %1.bd, %1.od+$1} +with exact abs_regXcon any4 + kills allexceptcon + gen move %2, {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact abs_index4 any4 + kills allexceptcon + gen move %2, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, $1} +with exact absind_con any4 + kills allexceptcon + gen move %2, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact ext_regX any4 + kills allexceptcon + gen move %2, {abs_index4, %1.sc, %1.xreg, %1.bd+$1} +#endif m68020 + +pat sti $1==1 +with A_REG data1 + kills allexceptcon + gen move %2, {indirect1, %1} +with exact local_addr data1 + kills allexceptcon + gen move %2, {offsetted1, lb, %1.bd} +with exact ext_addr data1 + kills allexceptcon + gen move %2, {absolute1, %1.bd} +#ifndef m68020 +with regAcon data1 + kills allexceptcon + gen move %2, {offsetted1, %1.reg, %1.bd} +with regAregXcon data1 + kills allexceptcon + gen move %2, {index_off1, %1.reg, %1.xreg, %1.sc, %1.bd} +#else m68020 +with exact regAcon data1 + kills allexceptcon + gen move %2, {offsetted1, %1.reg, %1.bd} +with exact regAregXcon data1 + kills allexceptcon + gen move %2, {index_off1, %1.reg, %1.xreg, %1.sc, %1.bd} +with exact indirect4 data1 + kills allexceptcon + gen move %2, {OFF_off1, %1.reg, 0, 0} +with exact offsetted4 data1 + kills allexceptcon + gen move %2, {OFF_off1, %1.reg, %1.bd, 0} +with exact LOCAL data1 + kills allexceptcon + gen move %2, {OFF_off1, lb, %1.bd, 0} +with exact off_con data1 + kills allexceptcon + gen move %2, {OFF_off1, %1.reg, %1.bd, %1.od} +with exact off_regXcon data1 + kills allexceptcon + gen move %2, {OFF_indoff1, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact index_off4 data1 + kills allexceptcon + gen move %2, {INDOFF_off1, %1.reg, %1.xreg, %1.sc, %1.bd, 0} +with exact indoff_con data1 + kills allexceptcon + gen move %2, {INDOFF_off1, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact absolute4 data1 + kills allexceptcon + gen move %2, {ABS_off1, %1.bd, 0} +with exact abs_con data1 + kills allexceptcon + gen move %2, {ABS_off1, %1.bd, %1.od} +with exact abs_regXcon data1 + kills allexceptcon + gen move %2, {ABS_indoff1, %1.sc, %1.xreg, %1.bd, %1.od} +with exact abs_index4 data1 + kills allexceptcon + gen move %2, {ABSIND_off1, %1.sc, %1.xreg, %1.bd, 0} +with exact absind_con data1 + kills allexceptcon + gen move %2, {ABSIND_off1, %1.sc, %1.xreg, %1.bd, %1.od} +with exact ext_regX data1 + kills allexceptcon + gen move %2, {abs_index1, %1.sc, %1.xreg, %1.bd} +#endif m68020 + +pat sti $1==2 +with A_REG any2 + kills allexceptcon + gen move %2, {indirect2, %1} +with exact local_addr any2 + kills allexceptcon + gen move %2, {offsetted2, lb, %1.bd} +with exact ext_addr any2 + kills allexceptcon + gen move %2, {absolute2, %1.bd} +#ifndef m68020 +with regAcon any2 + kills allexceptcon + gen move %2, {offsetted2, %1.reg, %1.bd} +with regAregXcon any2 + kills allexceptcon + gen move %2, {index_off2, %1.reg, %1.xreg, %1.sc, %1.bd} +#else m68020 +with exact regAcon any2 + kills allexceptcon + gen move %2, {offsetted2, %1.reg, %1.bd} +with exact regAregXcon any2 + kills allexceptcon + gen move %2, {index_off2, %1.reg, %1.xreg, %1.sc, %1.bd} +with exact indirect4 any2 + kills allexceptcon + gen move %2, {OFF_off2, %1.reg, 0, 0} +with exact offsetted4 any2 + kills allexceptcon + gen move %2, {OFF_off2, %1.reg, %1.bd, 0} +with exact LOCAL any2 + kills allexceptcon + gen move %2, {OFF_off2, lb, %1.bd, 0} +with exact off_con any2 + kills allexceptcon + gen move %2, {OFF_off2, %1.reg, %1.bd, %1.od} +with exact index_off4 any2 + kills allexceptcon + gen move %2, {INDOFF_off2, %1.reg, %1.xreg, %1.sc, %1.bd, 0} +with exact off_regXcon any2 + kills allexceptcon + gen move %2, {OFF_indoff2, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact indoff_con any2 + kills allexceptcon + gen move %2, {INDOFF_off2, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact absolute4 any2 + kills allexceptcon + gen move %2, {ABS_off2, %1.bd, 0} +with exact abs_con any2 + kills allexceptcon + gen move %2, {ABS_off2, %1.bd, %1.od} +with exact abs_regXcon any2 + kills allexceptcon + gen move %2, {ABS_indoff2, %1.sc, %1.xreg, %1.bd, %1.od} +with exact abs_index4 any2 + kills allexceptcon + gen move %2, {ABSIND_off2, %1.sc, %1.xreg, %1.bd, 0} +with exact absind_con any2 + kills allexceptcon + gen move %2, {ABSIND_off2, %1.sc, %1.xreg, %1.bd, %1.od} +with exact ext_regX any2 + kills allexceptcon + gen move %2, {abs_index2, %1.sc, %1.xreg, %1.bd} +#endif m68020 + +pat sti $1==4 +with A_REG any4 + kills allexceptcon + gen move %2, {indirect4, %1} +with A_REG STACK + gen move {post_inc4, sp}, {indirect4, %1} +with exact local_addr any4 + kills allexceptcon + gen move %2, {LOCAL, %1.bd} +with exact ext_addr any4 + kills allexceptcon + gen move %2, {absolute4, %1.bd} +#ifndef m68020 +with regAcon any4 + kills allexceptcon + gen move %2, {offsetted4, %1.reg, %1.bd} +with regAregXcon any4 + kills allexceptcon + gen move %2, {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd} +#else m68020 +with exact regAcon any4 + kills allexceptcon + gen move %2, {offsetted4, %1.reg, %1.bd} +with exact regAregXcon any4 + kills allexceptcon + gen move %2, {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd} +with exact LOCAL any4 + kills allexceptcon + gen move %2, {ILOCAL, %1.bd} +with exact indirect4 any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, 0, 0} +with exact offsetted4 any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, %1.bd, 0} +with exact off_con any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, %1.bd, %1.od} +with exact off_regXcon any4 + kills allexceptcon + gen move %2, {OFF_indoff4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact index_off4 any4 + kills allexceptcon + gen move %2, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, 0} +with exact indoff_con any4 + kills allexceptcon + gen move %2, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact absolute4 any4 + kills allexceptcon + gen move %2, {ABS_off4, %1.bd, 0} +with exact abs_con any4 + kills allexceptcon + gen move %2, {ABS_off4, %1.bd, %1.od} +with exact abs_regXcon any4 + kills allexceptcon + gen move %2, {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od} +with exact abs_index4 any4 + kills allexceptcon + gen move %2, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, 0} +with exact absind_con any4 + kills allexceptcon + gen move %2, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od} +with exact ext_regX any4 + kills allexceptcon + gen move %2, {abs_index4, %1.sc, %1.xreg, %1.bd} +#endif m68020 + +pat sti $1>4 +with AA_REG STACK + uses DD_REG = {const, $1/4 -1} + gen 1: + move_l {post_inc4, sp}, {post_inc4, %1} + dbf %a, {slabel, 1b} + +pat sts $1==4 +with STACK + gen jsr {absolute4, ".sts"} + +pat sdl +with any4 any4 + kills all_indir, LOCAL %bd==$1 + gen move %1, {LOCAL, $1} + move %2, {LOCAL, $1+4} + +pat sde +with any4 any4 + kills posextern + gen move %1, {absolute4, $1} + move %2, {absolute4, $1+4} + +pat sdf +with A_REG any4 any4 + kills allexceptcon + gen move %2, {offsetted4, %1, $1} + move %3, {offsetted4, %1, $1+4} +with exact local_addr any4 any4 + kills allexceptcon + gen move %2, {LOCAL, %1.bd+$1} + move %3, {LOCAL, %1.bd+$1+4} +with exact ext_addr any4 any4 + kills allexceptcon + gen move %2, {absolute4, %1.bd+$1} + move %3, {absolute4, %1.bd+$1+4} +#ifndef m68020 +with regAcon any4 any4 + kills allexceptcon + gen move %2, {offsetted4, %1.reg, %1.bd+$1} + move %3, {offsetted4, %1.reg, %1.bd+$1+4} +#else m68020 +with exact regAcon any4 any4 + kills allexceptcon + gen move %2, {offsetted4, %1.reg, %1.bd+$1} + move %3, {offsetted4, %1.reg, %1.bd+$1+4} +with exact regAregXcon any4 any4 + kills allexceptcon + gen move %2, {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1} + move %3, {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1+4} +with exact indirect4 any4 any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, 0, $1} + move %3, {OFF_off4, %1.reg, 0, $1+4} +with exact offsetted4 any4 any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, %1.bd, $1} + move %3, {OFF_off4, %1.reg, %1.bd, $1+4} +with exact LOCAL any4 any4 + kills allexceptcon + gen move %2, {OFF_off4, lb, %1.bd, $1} + move %3, {OFF_off4, lb, %1.bd, $1+4} +with exact off_con any4 any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, %1.bd, %1.od+$1} + move %3, {OFF_off4, %1.reg, %1.bd, %1.od+$1+4} +with exact off_regXcon any4 any4 + kills allexceptcon + gen move %2, {OFF_indoff4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} + move %3, {OFF_indoff4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1+4} +with exact index_off4 any4 any4 + kills allexceptcon + gen move %2, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, $1} + move %3, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, $1+4} +with exact indoff_con any4 any4 + kills allexceptcon + gen move %2, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} + move %3, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1+4} +with exact absolute4 any4 any4 + kills allexceptcon + gen move %2, {ABS_off4, %1.bd, $1} + move %3, {ABS_off4, %1.bd, $1+4} +with exact abs_con any4 any4 + kills allexceptcon + gen move %2, {ABS_off4, %1.bd, %1.od+$1} + move %3, {ABS_off4, %1.bd, %1.od+$1+4} +with exact abs_regXcon any4 any4 + kills allexceptcon + gen move %2, {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od+$1} + move %3, {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od+$1+4} +with exact abs_index4 any4 any4 + kills allexceptcon + gen move %2, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, $1} + move %3, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, $1+4} +with exact absind_con any4 any4 + kills allexceptcon + gen move %2, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1} + move %3, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1+4} +with exact ext_regX any4 any4 + kills allexceptcon + gen move %2, {abs_index4, %1.sc, %1.xreg, %1.bd+$1} + move %3, {abs_index4, %1.sc, %1.xreg, %1.bd+$1+4} +#endif m68020 + + + +/************************************************ + * Group 3: integer arithmetic. * + ************************************************/ + + +pat adi $1==4 +with any4 DD_REG + gen add_l %1, %2 yields %2 +with DD_REG any4-DD_REG + gen add_l %2, %1 yields %1 +with DD_REG STACK + gen add_l {post_inc4, sp}, %1 + yields %1 + +pat sbi $1==4 +with any4 DD_REG + gen sub_l %1, %2 yields %2 +with DD_REG any4-DD_REG + gen sub_l %2, %1 + neg_l %1 yields %1 +with DD_REG STACK + gen sub_l {post_inc4, sp}, %1 + neg_l %1 yields %1 +with any4 AA_REG + gen sub_l %1, %2 yields %2 + +pat mli $1==4 +#ifdef m68020 +with data4 DD_REG + gen muls_l %1, %2 yields %2 +#else m68020 +with STACK + gen jsr {absolute4, ".mli"} + yields d1 +#endif m68020 + +pat dvi $1==4 +#ifdef m68020 +with data4 DD_REG + gen divs_l %1, %2 yields %2 +#else m68020 +with STACK + gen jsr {absolute4, ".dvi"} + yields d1 +#endif m68020 + +pat rmi $1==4 +#ifdef m68020 +with data4 DD_REG + uses DD_REG + gen divsl_l %1, {DREG_pair, %a, %2} + killreg %2 + /* !!!! contents of %2 have changed: make this known to cg */ + yields %a +#else m68020 +with STACK + gen jsr {absolute4, ".dvi"} + yields d0 +#endif m68020 + +pat ngi $1==4 +with DD_REG + gen neg_l %1 yields %1 + +pat sli $1==4 +with D_REG DD_REG + gen asl_l %1, %2 yields %2 + +pat sri $1==4 +with D_REG DD_REG + gen asr_l %1, %2 yields %2 + + + +/************************************************ + * Group 4: unsigned arithmetic. * + ************************************************/ + + +pat adu leaving adi $1 + +pat sbu leaving sbi $1 + +pat mlu $1==4 +#ifdef m68020 +with data4 DD_REG + gen mulu_l %1, %2 yields %2 +#else m68020 +with STACK + gen jsr {absolute4, ".mlu"} + yields d1 +#endif m68020 + +pat dvu $1==4 +#ifdef m68020 +with data4 DD_REG + gen divu_l %1, %2 yields %2 +#else m68020 +with STACK + gen jsr {absolute4, ".dvu"} + yields d1 +#endif m68020 + +pat rmu $1==4 +#ifdef m68020 +with data4 DD_REG + uses DD_REG + gen divul_l %1, {DREG_pair, %a, %2} + killreg %2 + /* !!!! contents of %2 have changed: make this known to cg */ + yields %a +#else m68020 +with STACK + gen jsr {absolute4, ".dvu"} + yields d0 +#endif m68020 + +pat slu leaving sli $1 + +pat sru $1==4 +with D_REG DD_REG + gen lsr_l %1, %2 yields %2 + + + +/************************************************ + * Group 5: floating point arithmetic * + * * + * is not available on 68000, 68010 or 68020 * + * so traps will be generated * + ************************************************/ + +pat adf leaving loc 18 trp +pat sbf leaving loc 18 trp +pat mlf leaving loc 18 trp +pat dvf leaving loc 18 trp +pat ngf leaving loc 18 trp +pat fif leaving loc 18 trp +pat fef leaving loc 18 trp + + + +/************************************************ + * Group 6: pointer arithmetic * + ************************************************/ + +pat adp $1==0 /* skip; array instructions might 'leave' this */ + +pat adp +with A_REG yields {t_regAcon, %1, $1} +with exact local_addr yields {local_addr, %1.bd+$1} +with exact ext_addr yields {ext_addr, %1.bd+$1} +with exact regAcon + t_regAcon + yields {t_regAcon, %1.reg, %1.bd+$1} +with exact regAregXcon + t_regAregXcon + yields {t_regAregXcon,%1.reg, %1.xreg, %1.sc, %1.bd+$1} +#ifdef m68020 +with exact indirect4 yields {off_con, %1.reg, 0, $1} +with exact LOCAL yields {off_con, lb, %1.bd, $1} +with exact offsetted4 yields {off_con, %1.reg, %1.bd, $1} +with exact off_con yields {off_con, %1.reg, %1.bd, %1.od+$1} +with exact off_regXcon yields {off_regXcon, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact index_off4 yields {indoff_con, %1.reg, %1.xreg, %1.sc, %1.bd, $1} +with exact indoff_con yields {indoff_con, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact absolute4 yields {abs_con, %1.bd, $1} +with exact abs_con yields {abs_con, %1.bd, %1.od+$1} +with exact abs_regXcon yields {abs_regXcon, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact abs_index4 yields {absind_con, %1.sc, %1.xreg, %1.bd, $1} +with exact absind_con yields {absind_con, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact ext_regX yields {ext_regX, %1.sc, %1.xreg, %1.bd+$1} +#endif m68020 + +pat ads $1==4 +with D_REG A_REG yields {regAregXcon, %2, %1, 1, 0} +with D_REG regAcon + t_regAcon + yields {t_regAregXcon, %2.reg, %1, 1, %2.bd} +with D_REG local_addr yields {t_regAregXcon, lb, %1, 1, %2.bd} +with any4-D_REG AA_REG + gen add_l %1, %2 yields %2 + +#ifdef m68020 + +with D_REG yields {regX, 1, %1} + leaving ads 4 +with regX A_REG yields {regAregXcon, %2, %1.xreg, %1.sc, 0} +with exact regX regAcon yields {regAregXcon, %2.reg, %1.xreg, %1.sc, %2.bd} +with exact regX local_addr + yields {regAregXcon, lb, %1.xreg, %1.sc, %2.bd} +with exact regX ext_addr + yields {ext_regX, %1.sc, %1.xreg, %2.bd} +with exact regX indirect4 + yields {off_regXcon, %2.reg, %1.xreg,%1.sc,0,0} +with exact regX offsetted4 + yields {off_regXcon, %2.reg, %1.xreg, %1.sc, %2.bd, 0} +with exact regX LOCAL yields {off_regXcon, lb, %1.xreg, %1.sc, %2.bd, 0} +with exact regX off_con yields {off_regXcon, %2.reg, %1.xreg,%1.sc,%2.bd,%2.od} +with exact regX absolute4 + yields {abs_regXcon, %1.sc, %1.xreg, %2.bd, 0} +with exact regX abs_con yields {abs_regXcon, %1.sc, %1.xreg, %2.bd, %2.od} +with exact indirect4 ext_addr + yields {off_con, %1.reg, 0, %2.bd} +with exact offsetted4 ext_addr + yields {off_con, %1.reg, %1.bd, %2.bd} +with exact LOCAL ext_addr + yields {off_con, lb, %1.bd, %2.bd} +with exact index_off4 ext_addr + yields {indoff_con, %1.reg, %1.xreg, %1.sc,%1.bd,%2.bd} +with exact absolute4 ext_addr + yields {abs_con, %1.bd, %2.bd} +with exact abs_index4 ext_addr + yields {absind_con, %1.sc, %1.xreg, %1.bd, %2.bd} +with exact indirect4 ext_regX + yields {off_regXcon, %1.reg, %2.xreg, %2.sc, 0, %2.bd} +with exact offsetted4 ext_regX + yields {off_regXcon, %1.reg, %2.xreg,%2.sc,%1.bd,%2.bd} +with exact LOCAL ext_regX + yields {off_regXcon, lb, %2.xreg, %2.sc, %1.bd, %2.bd} +with exact absolute4 ext_regX + yields {abs_regXcon, %2.sc, %2.xreg, %1.bd, %2.bd} +#endif m68020 + + /* I WOULD ALSO LIKE THIS: + * pat ads + * with const leaving adp %1.num + * BUT THAT DOESN'T WORK. + */ + +pat sbs $1==4 leaving sbi 4 + +#ifdef m68020 +pat loc sli ads $1==1 && $2==4 && $3==4 +with D_REG yields {regX, 2, %1} + leaving ads 4 + +pat loc sli ads $1==2 && $2==4 && $3==4 +with D_REG yields {regX, 4, %1} + leaving ads 4 + +pat loc sli ads $1==3 && $2==4 && $3==4 +with D_REG yields {regX, 8, %1} + leaving ads 4 +#endif m68020 + + +/************************************************ + * Group 7: increment / decrement / zero * + ************************************************/ + +pat inc +with exact STACK + gen add_l {const, 1}, {indirect4, sp} +with DD_REG+AA_REG + gen add_l {const, 1}, %1 + yields %1 + +pat inl + kills all_indir, LOCAL %bd==$1 + gen add_l {const, 1}, {LOCAL, $1} + +pat ine + kills posextern + gen add_l {const, 1}, {absolute4, $1} + +pat dec +with exact STACK + gen sub_l {const, 1}, {indirect4, sp} +with DD_REG+AA_REG + gen sub_l {const, 1}, %1 + yields %1 + +pat del + kills all_indir, LOCAL %bd==$1 + gen sub_l {const, 1}, {LOCAL, $1} + +pat dee + kills posextern + gen sub_l {const, 1}, {absolute4, $1} + +pat zrl + kills all_indir, LOCAL %bd==$1 + gen clr_l {LOCAL, $1} + +pat zre + kills posextern + gen clr_l {absolute4, $1} + +pat zer $1==4 yields {const, 0} +pat zer $1==8 yields {const, 0} {const, 0} +pat zer $1==12 yields {const, 0} {const, 0} {const, 0} + +pat zer +with STACK + uses DD_REG = {const, $1/4 -1} + gen 1: + clr_l {pre_dec4, sp} + dbf %a, {slabel, 1b} + + +pat zrf leaving loc 18 trp + + + +/************************************************ + * Group 8: convert instructions * + * for float conversions traps are generated * + ************************************************/ + + + +pat cii +with STACK + gen jsr {absolute4, ".cii"} + +pat cuu +with STACK + gen jsr {absolute4, ".cuu"} + +pat ciu leaving cuu + +pat cui leaving cuu + +pat cfi leaving loc 18 trp +pat cif leaving loc 18 trp +pat cfu leaving loc 18 trp +pat cuf leaving loc 18 trp +pat cff leaving loc 18 trp + + +/************************************************ + * Group 9: logical instructions * + ************************************************/ + + +proc log4 +with datalt4+const DD_REG + gen xxx* %1, %2 yields %2 +with DD_REG datalt4+const + gen xxx* %2, %1 yields %1 + +proc logdef example and +with STACK + uses DD_REG = {const, $1/4 -1}, + AA_REG = {regAcon, sp, $1}, + DD_REG + gen 1: + move_l {post_inc4, sp}, %c + xxx* %c, {post_inc4, %b} + dbf %a, {slabel, 1b} + +proc logndef +with DD_REG STACK + uses AA_REG = {regAregXcon, sp, %1, 1, 0}, + DD_REG + gen asr_l {shconst, 2}, %1 + sub_l {const, 1}, %1 + 1: + move_l {post_inc4, sp}, %b + xxx* %b, {post_inc4, %a} + dbf %1, {slabel, 1b} + +pat and $1==4 call log4("and.l") +pat and $1>4 call logdef("and.l") +pat and !defined($1) call logndef("and.l") +pat ior $1==4 call log4("or.l") +pat ior $1>4 call logdef("or.l") +pat ior !defined($1) call logndef("or.l") + +pat xor $1==4 +with conreg4 DD_REG + gen eor_l %1, %2 yields %2 +with DD_REG conreg4 + gen eor_l %2, %1 yields %1 + +pat xor $1>4 call logdef("eor.l") +pat xor !defined($1) call logndef("eor.l") + +pat com $1==4 +with DD_REG + gen not_l %1 yields %1 + +pat com $1==8 +with DD_REG DD_REG + gen not_l %1 + not_l %2 yields %2 %1 + +pat com $1>4 +with STACK + uses AA_REG, + DD_REG = {const, $1/4 -1} + gen move_l sp, %a + 1: + not_l {post_inc4, %a} + dbf %b, {slabel, 1b} + +pat com !defined($1) +with DD_REG STACK + uses AA_REG + gen move_l sp, %a + asr_l {shconst, 2}, %1 + sub_l {const, 1}, %1 + 1: + not_l {post_inc4, %a} + dbf %1, {slabel, 1b} + +pat rol $1==4 +with D_REG DD_REG + gen rol_l %1, %2 yields %2 + +pat ror $1==4 +with D_REG DD_REG + gen ror_l %1, %2 yields %2 + + + + +/************************************************ + * Group 10: sets * + ************************************************/ + + +pat inn $1==4 +with conreg2 DD_REG + gen btst %1, %2 + sne %2 + and_l {const, 1}, %2 + yields %2 + +pat inn defined($1) +with any4 STACK + gen move %1, d0 + move {const, $1}, d1 + jsr {absolute4, ".inn"} + yields d0 + +pat inn !defined($1) +with any4 any4 STACK + gen move %2, d0 + move %1, d1 + jsr {absolute4, ".inn"} + yields d0 + +pat loc inn $2==4 && small($1) +with DD_REG + gen asr_l {shconst, $1}, %1 + and_l {const, 1}, %1 + yields %1 + +pat set $1==4 +with conreg2 + uses DD_REG = {const, 0} + gen bset %1, %a yields %a + +pat set $1>4 +with any4 STACK + gen move %1, d0 + move {const, $1}, d1 + jsr {absolute4, ".set"} + +pat set !defined($1) +with any4 any4 STACK + gen move %2, d0 + move %1, d1 + jsr {absolute4, ".set"} + + + + +/************************************************ + * Group 11: arrays * + ************************************************/ + + +pat lar defined($1) +with STACK + gen move {const, $1}, d0 + jsr {absolute4, ".lar"} + +pat lar !defined($1) +with any4 STACK + gen move %1, d0 + jsr {absolute4, ".lar"} + +pat sar defined($1) +with STACK + gen move {const, $1}, d0 + jsr {absolute4, ".sar"} + +pat sar !defined($1) +with any4 STACK + gen move %1, d0 + jsr {absolute4, ".sar"} + +pat aar defined($1) +with STACK + gen move {const, $1}, d0 + jsr {absolute4, ".aar"} + yields a0 + +pat aar !defined($1) +with any4 STACK + gen move %1, d0 + jsr {absolute4, ".aar"} + yields a0 + +pat lae lar $2==4 && nicesize(rom($1,3)) + leaving lae $1 aar 4 loi rom($1, 3) +pat lae sar $2==4 && nicesize(rom($1,3)) + leaving lae $1 aar 4 sti rom($1, 3) + +pat lae aar $2==4 && rom($1,3)==1 + leaving ads 4 adp 0-rom($1,1) + +#ifdef m68020 +pat lae aar $2==4 && nicesize(rom($1,3)) +with D_REG yields {regX, rom($1,3), %1} + leaving ads 4 adp rom($1,3)*(0-rom($1,1)) +#else m68020 +pat lae aar $2==4 && rom($1,3)==2 +with DD_REG + gen asl_l {shconst, 1}, %1 + yields %1 + leaving ads 4 adp (0 - rom($1,1))<<1 + +pat lae aar $2==4 && rom($1,3)==4 +with DD_REG + gen asl_l {shconst, 2}, %1 + yields %1 + leaving ads 4 adp (0 - rom($1,1))<<2 + +pat lae aar $2==4 && rom($1,3)==8 +with DD_REG + gen asl_l {shconst, 3}, %1 + yields %1 + leaving ads 4 adp (0 - rom($1,1))<<3 +#endif m68020 + + /* I WOULD ALSO LIKE THESE: + * pat lae aar $2==4 && defined(rom($1,3)) + * with const leaving adp rom($1,3)*(%1.num-rom($1,1)) + * pat lae lar $2==4 && defined(rom($1,3)) + * with const leaving adp rom($1,3)*(%1.num-rom($1,1)) + * loi rom($1,3) + * pat lae sar $2==4 && defined(rom($1,3)) + * with const leaving adp rom($1,3)*(%1.num-rom($1,1)) + * sti rom($1,3) + * BUT THEY DON'T WORK. + */ + + + +/************************************************ + * Group 12: compare instructions * + ************************************************/ + + +pat cmi $1==4 leaving sbi 4 + +pat cmi defined($1) +with STACK + gen move {const, $1}, d0 + jsr {absolute4, ".cmi"} + yields d0 + +pat cmi !defined($1) +with any4 STACK + gen move %1, d0 + jsr {absolute4, ".cmi"} + yields d0 + +pat cmu $1==4 leaving sbi 4 + +pat cmu defined($1) +with STACK + gen move {const, $1}, d0 + jsr {absolute4, ".cmu"} + yields d0 + +pat cmu !defined($1) +with any4 STACK + gen move %1, d0 + jsr {absolute4, ".cmu"} + yields d0 + +pat cms $1==4 leaving sbi 4 + +pat cms defined($1) +with STACK + gen move {const, $1}, d0 + jsr {absolute4, ".cms"} + yields d0 + +pat cms !defined($1) +with any4 STACK + gen move %1, d0 + jsr {absolute4, ".cms"} + yields d0 + +pat cmp leaving cmu 4 + +proc txx +with test_set + uses DD_REG = {const, 1} + gen test %1 + bxx* {slabel, 1f} + clr_l %a + 1: + yields %a + +pat tlt call txx("blt") +pat tle call txx("ble") +pat teq call txx("beq") +pat tne call txx("bne") +pat tge call txx("bge") +pat tgt call txx("bgt") + +pat cmf leaving loc 18 trp + + + +/************************************************ + * Group 13: branch instructions * + ************************************************/ + +pat bra +with STACK + gen bra {llabel, $1} + +proc brxx example beq +with any4 genreg STACK + gen cmp_l %1, %2 + bxx[1] {llabel, $1} +with genreg any4 STACK + gen cmp_l %2, %1 + bxx[2] {llabel, $1} +with exact immediate4 imm_cmp4 + kills ALL + gen cmp_l %1, %2 + bxx[1] {llabel, $1} +with exact imm_cmp4 immediate4 + kills ALL + gen cmp_l %2, %1 + bxx[2] {llabel, $1} +with genreg STACK + gen cmp_l {post_inc4, sp}, %1 + bxx[2] {llabel, $1} +with exact immediate4 STACK + gen cmp_l %1, {post_inc4, sp} + bxx[1] {llabel, $1} +with any2-conreg2 genreg STACK + gen cmp_w %1, %2 + bxx[1] {llabel, $1} +with genreg any2-conreg2 STACK + gen cmp_w %2, %1 + bxx[2] {llabel, $1} +with exact const imm_cmp2 + kills ALL + gen cmp_w {const, loww(%1.num)}, %2 + bxx[1] {llabel, $1} +with exact imm_cmp2 const + kills ALL + gen cmp_w {const, loww(%2.num)}, %1 + bxx[2] {llabel, $1} +with data1-conreg1 D_REG STACK + gen cmp_b %1, %2 + bxx[1] {llabel, $1} +with D_REG data1-conreg1 STACK + gen cmp_b %2, %1 + bxx[2] {llabel, $1} +with exact const imm_cmp1 + kills ALL + gen cmp_b {const, lowb(%1.num)}, %2 + bxx[1] {llabel, $1} +with exact imm_cmp1 const + kills ALL + gen cmp_b {const, lowb(%2.num)}, %1 + bxx[2] {llabel, $1} + +pat blt call brxx("blt","bgt") +pat ble call brxx("ble","bge") +pat beq call brxx("beq","beq") +pat bne call brxx("bne","bne") +pat bge call brxx("bge","ble") +pat bgt call brxx("bgt","blt") + +proc zxx example zeq +with test_set STACK + gen test %1 + bxx* {llabel, $1} +with exact STACK + gen test {post_inc4, sp} + bxx* {llabel, $1} + +pat zlt call zxx("blt") +pat zle call zxx("ble") +pat zeq call zxx("beq") +pat zne call zxx("bne") +pat zge call zxx("bge") +pat zgt call zxx("bgt") + +/************************************************ + * Group 14: procedure calls instructions * + ************************************************/ + + +pat cai +with exact ext_addr + kills ALL + gen jsr {absolute4, %1.bd} +with A_REG STACK + gen jsr {indirect4, %1} +with STACK + uses AA_REG = {post_inc4, sp} + gen jsr {indirect4, %a} +#ifdef m68020 +with exact address + kills ALL + gen jsr %1 +#else m68020 +with address STACK + gen jsr %1 +#endif m68020 + +pat cal +with STACK + gen jsr {absolute4, $1} + +pat lfr $1==4 yields d0 +pat lfr $1==8 yields d1 d0 + +pat ret $1==0 +with STACK + gen return + +pat ret $1==4 +with any4 STACK + gen move %1, d0 + return +with STACK + gen move {post_inc4, sp}, d0 + return + +pat ret $1==8 +with any4 any4 STACK + gen move %1, d0 + move %2, d1 + return +with any4 STACK + gen move %1, d0 + move {post_inc4, sp}, d1 + return +with STACK + gen move {post_inc4, sp}, d0 + move {post_inc4, sp}, d1 + return + + +/************************************************ + * Group 15: miscellaneous instructions * + ************************************************/ + +pat asp small($1) +with STACK + gen add_l {const, $1}, sp +pat asp +with STACK + gen move {regAcon, sp, $1}, sp + +pat ass $1==4 +with any4 STACK + gen add_l %1, sp + +pat blm $1==4 +with A_REG A_REG + kills allexceptcon + gen move_l {indirect4, %2}, {indirect4, %1} + +pat blm $1==8 +with A_REG A_REG + kills allexceptcon + gen move_l {indirect4, %2}, {indirect4, %1} + move_l {offsetted4, %2, 4}, {offsetted4, %1, 4} + +pat blm $1>8 +with AA_REG AA_REG + kills allexceptcon + uses DD_REG={const, $1/4 -1} + gen 1: + move_l {post_inc4, %2}, {post_inc4, %1} + dbf %a, {slabel, 1b} + +pat bls $1==4 +with DD_REG AA_REG AA_REG + kills allexceptcon + gen asr_l {shconst, 2}, %1 + beq {slabel, 2f} + sub_l {const, 1}, %1 + 1: + move_l {post_inc4, %3}, {post_inc4, %2} + dbf %1, {slabel, 1b} + 2: + +pat csa $1==4 +with STACK + gen jmp {absolute4, ".csa"} + +pat csb $1==4 +with STACK + gen jmp {absolute4, ".csb"} + +pat dch leaving loi 4 + +pat dup $1==4 +with exact STACK + gen move_l {indirect4, sp}, {pre_dec4, sp} +with any4 yields %1 %1 + +pat dup $1==8 +with exact STACK + gen move_l {offsetted4, sp, 4}, {pre_dec4, sp} + move_l {offsetted4, sp, 4}, {pre_dec4, sp} +with any4 any4 yields %2 %1 %2 %1 + +pat dup $1>8 +with STACK + uses DD_REG = {const, $1/4 -1} + gen 1: + move_l {offsetted4, sp, $1 -4}, {pre_dec4, sp} + dbf %a, {slabel, 1b} + +pat dus $1==4 +with DD_REG STACK + uses AA_REG = {regAregXcon, sp, %1, 1, 0} + gen asr_l {shconst, 2}, %1 + beq {slabel, 2f} + sub_l {const, 1}, %1 + 1: + move_l {pre_dec4, %a}, {pre_dec4, sp} + dbf %1, {slabel, 1b} + 2: + +pat exg $1==4 +with any4 any4 yields %1 %2 + +pat exg defined($1) +with STACK + gen move {const, $1}, d0 + jsr {absolute4, ".exg"} + +pat exg !defined($1) +with any4 STACK + gen move_l %1, d0 + jsr {absolute4, ".exg"} + +pat fil + gen move_l {ext_addr, $1}, {absolute4, ".filn"} + +pat gto +with STACK + uses AA_REG = {ext_addr, $1} + gen move_l {offsetted4, %a, 8}, lb + move_l {offsetted4, %a, 4}, sp +#ifdef m68020 + jmp {OFF_off4, %a, 0, 0} +#else m68020 + move_l {indirect4, %a}, %a + jmp {indirect4, %a} +#endif m68020 + +pat lim yields {absolute4, ".trpim"} + +pat lin + gen move {const, $1}, {absolute4, ".lino"} + +pat lni + gen add_l {const, 1}, {absolute4, ".lino"} + +pat lor $1==0 yields lb + +pat lor $1==1 +with STACK + uses AA_REG = sp yields %a + +pat lor $1==2 yields {absolute4, ".reghp"} + +pat lpb leaving adp 8 + +pat mon +with STACK + gen jsr {absolute4, ".mon"} + +pat nop +with STACK + gen jsr {absolute4, ".nop"} + +pat rck +#ifdef m68020 +with ext_addr D_REG + gen cmp2_l {absolute4, %1.bd}, %2 + bcc {slabel, 1f} + pea {absolute4, 1} /* push constant 1 == ERANGE */ + jsr {absolute4, ".trp"} + 1: yields %2 +with address-ext_addr D_REG + gen cmp2_l %1, %2 + bcc {slabel, 1f} + pea {absolute4, 1} /* push constant 1 == ERANGE */ + jsr {absolute4, ".trp"} + 1: yields %2 +with A_REG D_REG + gen cmp2_l {indirect4, %1}, %2 + bcc {slabel, 1f} + pea {absolute4, 1} /* push constant 1 == ERANGE */ + jsr {absolute4, ".trp"} + 1: yields %2 +#else m68020 +with STACK + gen jsr {absolute4, ".rck"} +#endif m68020 + +pat rtt leaving ret 0 + +pat sig +with any4 + uses AA_REG + gen move {absolute4, ".trppc"}, %a + move %1, {absolute4, ".trppc"} + yields %a + +pat sim +with any4 + gen move_l %1, {absolute4, ".trpim"} + +pat str $1==0 +with any4 +#ifdef m68020 + kills LOCAL, ILOCAL, all_regind %reg==lb, local_addr +#else m68020 + kills LOCAL, all_regind %reg==lb, local_addr +#endif m68020 + gen move %1, lb + +pat str $1==1 +with any4 STACK + gen move %1, sp + +pat str $1==2 +with STACK + gen jsr {absolute4, ".strhp"} + +pat trp +with STACK + gen jsr {absolute4, ".trp"} + + + +/************************************************ + * rules for long EM-patterns * + ************************************************/ + +proc lolxxxstl example lol adi stl +with conreg4 + kills all_indir, LOCAL %bd==$1 + gen xxx* %1, {LOCAL, $1} + +proc loexxxste example loe adi ste +with conreg4 + kills posextern + gen xxx* %1, {absolute4, $1} + +proc lilxxxsil example lil adi sil +with conreg4 +#ifdef m68020 + kills allexceptcon + gen xxx* %1, {ILOCAL, $1} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen xxx* %1, {indirect4, %a} +#endif m68020 + +proc lolcxxxstl example lol loc adi stl + kills all_indir, LOCAL %bd==$1 + gen xxx* {const, $2}, {LOCAL, $1} + +proc loecxxxste example loe loc adi ste + kills posextern + gen xxx* {const, $2}, {absolute4, $1} + +proc lilcxxxsil example lil loc adi sil +#ifdef m68020 + kills allexceptcon + gen xxx* {const, $2}, {ILOCAL, $1} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen xxx* {const, $2}, {indirect4, %a} +#endif m68020 + +proc lolrxxxstl example lol lol adi stl + kills all_indir, LOCAL %bd==$1 + gen xxx* {LOCAL, $2}, {LOCAL, $1} + +proc loerxxxste example loe lol adi ste + kills posextern + gen xxx* {LOCAL, $2}, {absolute4, $1} + +proc lilrxxxsil example lil lol adi sil +#ifdef m68020 + kills allexceptcon + gen xxx* {LOCAL, $2}, {ILOCAL, $1} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen xxx* {LOCAL, $2}, {indirect4, %a} +#endif m68020 + +pat lol adi stl $1==$3 && $2==4 call lolxxxstl("add.l") +pat loe adi ste $1==$3 && $2==4 call loexxxste("add.l") +pat lil adi sil $1==$3 && $2==4 call lilxxxsil("add.l") +pat lol loc adi stl $1==$4 && $3==4 call lolcxxxstl("add.l") +pat loe loc adi ste $1==$4 && $3==4 call loecxxxste("add.l") +pat lil loc adi sil $1==$4 && $3==4 call lilcxxxsil("add.l") +pat lol lol adi stl $1==$4 && $3==4 && inreg($2)==reg_any + call lolrxxxstl("add.l") +pat loe lol adi ste $1==$4 && $3==4 && inreg($2)==reg_any + call loerxxxste("add.l") +pat lil lol adi sil $1==$4 && $3==4 && inreg($2)==reg_any + call lilrxxxsil("add.l") + +pat lol adu stl $1==$3 && $2==4 call lolxxxstl("add.l") +pat loe adu ste $1==$3 && $2==4 call loexxxste("add.l") +pat lil adu sil $1==$3 && $2==4 call lilxxxsil("add.l") +pat lol loc adu stl $1==$4 && $3==4 call lolcxxxstl("add.l") +pat loe loc adu ste $1==$4 && $3==4 call loecxxxste("add.l") +pat lil loc adu sil $1==$4 && $3==4 call lilcxxxsil("add.l") +pat lol lol adu stl $1==$4 && $3==4 && inreg($2)==reg_any + call lolrxxxstl("add.l") +pat loe lol adu ste $1==$4 && $3==4 && inreg($2)==reg_any + call loerxxxste("add.l") +pat lil lol adu sil $1==$4 && $3==4 && inreg($2)==reg_any + call lilrxxxsil("add.l") + + +pat lol adp stl $1==$3 + kills all_indir, LOCAL %bd==$1 + gen add_l {const, $2}, {LOCAL, $1} + +pat lil adp sil $1==$3 + kills allexceptcon +#ifdef m68020 + gen add_l {const, $2}, {ILOCAL, $1} +#else m68020 + uses AA_REG = {LOCAL, $1} + gen add_l {const, $2}, {indirect4, %a} +#endif m68020 + +pat loe adp ste $1==$3 + kills posextern + gen add_l {const, $2}, {absolute4, $1} + +pat lol lol adp stl $1==$2 && $1==$4 + kills all_indir, LOCAL %bd==$1 + uses AA_REG = {LOCAL, $1} + gen add_l {const, $3}, {LOCAL, $1} + yields %a + +pat lil lil adp sti $1==$2 && $1==$4 + kills allexceptcon +#ifdef m68020 + uses AA_REG = {ILOCAL, $1} + gen add_l {const, $3}, {ILOCAL, $1} +#else m68020 + uses AA_REG, AA_REG = {LOCAL, $1} + gen move {indirect4, %b}, %a + add_l {const, $3}, {indirect4, %b} +#endif m68020 + yields %a + +pat loe loe adp ste $1==$2 && $1==$4 + kills posextern + uses AA_REG = {absolute4, $1} + gen add_l {const, $3}, {absolute4, $1} + yields %a + + +pat lol loc sbi stl $1==$4 && $3==4 call lolcxxxstl("sub.l") +pat loe loc sbi ste $1==$4 && $3==4 call loecxxxste("sub.l") +pat lil loc sbi sil $1==$4 && $3==4 call lilcxxxsil("sub.l") +pat lol lol sbi stl $1==$4 && $3==4 && inreg($2)==reg_any + call lolrxxxstl("sub.l") +pat loe lol sbi ste $1==$4 && $3==4 && inreg($2)==reg_any + call loerxxxste("sub.l") +pat lil lol sbi sil $1==$4 && $3==4 && inreg($2)==reg_any + call lilrxxxsil("sub.l") + +pat lol loc sbu stl $1==$4 && $3==4 call lolcxxxstl("sub.l") +pat loe loc sbu ste $1==$4 && $3==4 call loecxxxste("sub.l") +pat lil loc sbu sil $1==$4 && $3==4 call lilcxxxsil("sub.l") +pat lol lol sbu stl $1==$4 && $3==4 && inreg($2)==reg_any + call lolrxxxstl("sub.l") +pat loe lol sbu ste $1==$4 && $3==4 && inreg($2)==reg_any + call loerxxxste("sub.l") +pat lil lol sbu sil $1==$4 && $3==4 && inreg($2)==reg_any + call lilrxxxsil("sub.l") + +pat lol and stl $1==$3 && $2==4 call lolxxxstl("and.l") +pat loe and ste $1==$3 && $2==4 call loexxxste("and.l") +pat lil and sil $1==$3 && $2==4 call lilxxxsil("and.l") +pat lol loc and stl $1==$4 && $3==4 call lolcxxxstl("and.l") +pat loe loc and ste $1==$4 && $3==4 call loecxxxste("and.l") +pat lil loc and sil $1==$4 && $3==4 call lilcxxxsil("and.l") +pat lol lol and stl $1==$4 && $3==4 && inreg($2)==reg_any + call lolrxxxstl("and.l") +pat loe lol and ste $1==$4 && $3==4 && inreg($2)==reg_any + call loerxxxste("and.l") +pat lil lol and sil $1==$4 && $3==4 && inreg($2)==reg_any + call lilrxxxsil("and.l") + +pat lol ior stl $1==$3 && $2==4 call lolxxxstl("or.l") +pat loe ior ste $1==$3 && $2==4 call loexxxste("or.l") +pat lil ior sil $1==$3 && $2==4 call lilxxxsil("or.l") +pat lol loc ior stl $1==$4 && $3==4 call lolcxxxstl("or.l") +pat loe loc ior ste $1==$4 && $3==4 call loecxxxste("or.l") +pat lil loc ior sil $1==$4 && $3==4 call lilcxxxsil("or.l") +pat lol lol ior stl $1==$4 && $3==4 && inreg($2)==reg_any + call lolrxxxstl("or.l") +pat loe lol ior ste $1==$4 && $3==4 && inreg($2)==reg_any + call loerxxxste("or.l") +pat lil lol ior sil $1==$4 && $3==4 && inreg($2)==reg_any + call lilrxxxsil("or.l") + +pat lol xor stl $1==$3 && $2==4 call lolxxxstl("eor.l") +pat loe xor ste $1==$3 && $2==4 call loexxxste("eor.l") +pat lil xor sil $1==$3 && $2==4 call lilxxxsil("eor.l") +pat lol loc xor stl $1==$4 && $3==4 call lolcxxxstl("eor.l") +pat loe loc xor ste $1==$4 && $3==4 call loecxxxste("eor.l") +pat lil loc xor sil $1==$4 && $3==4 call lilcxxxsil("eor.l") +pat lol lol xor stl $1==$4 && $3==4 && inreg($2)==reg_any + call lolrxxxstl("eor.l") +pat loe lol xor ste $1==$4 && $3==4 && inreg($2)==reg_any + call loerxxxste("eor.l") +pat lil lol xor sil $1==$4 && $3==4 && inreg($2)==reg_any + call lilrxxxsil("eor.l") + +proc llol1shstl example lol loc sli stl /* only left */ + kills all_indir, LOCAL %bd==$1 + gen shw* {offsetted2, lb, $1+2} + roxl {offsetted2, lb, $1} + +proc lloe1shste example loe loc sli ste /* only left */ + kills posextern + gen shw* {absolute2, $1+2} + roxl {absolute2, $1} + +proc llil1shsil example lil loc sli sil /* only left */ +#ifdef m68020 + kills allexceptcon + gen shw* {OFF_off2, lb, $1, 2} + roxl {OFF_off2, lb, $1, 0} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen shw* {offsetted2, %a, 2} + roxl {indirect2, %a} +#endif m68020 + +proc rlol1shstl example lol loc sri stl /* only right */ + kills all_indir, LOCAL %bd==$1 + gen shw* {offsetted2, lb, $1} + roxr {offsetted2, lb, $1+2} + +proc rloe1shste example loe loc sri ste /* only right */ + kills posextern + gen shw* {absolute2, $1} + roxr {absolute2, $1+2} + +proc rlil1shsil example lil loc sri sil /* only right */ +#ifdef m68020 + kills allexceptcon + gen shw* {OFF_off2, lb, $1, 0} + roxr {OFF_off2, lb, $1, 2} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen shw* {indirect2, %a} + roxr {offsetted2, %a, 2} +#endif m68020 + +pat lol loc sli stl $1==$4 && $2==1 && $3==4 call llol1shstl("asl #1,") +pat loe loc sli ste $1==$4 && $2==1 && $3==4 call lloe1shste("asl #1,") +pat lil loc sli sil $1==$4 && $2==1 && $3==4 call llil1shsil("asl #1,") +pat lol loc sri stl $1==$4 && $2==1 && $3==4 call rlol1shstl("asr #1,") +pat loe loc sri ste $1==$4 && $2==1 && $3==4 call rloe1shste("asr #1,") +pat lil loc sri sil $1==$4 && $2==1 && $3==4 call rlil1shsil("asr #1,") +pat lol loc slu stl $1==$4 && $2==1 && $3==4 call llol1shstl("asl #1,") +pat loe loc slu ste $1==$4 && $2==1 && $3==4 call lloe1shste("asl #1,") +pat lil loc slu sil $1==$4 && $2==1 && $3==4 call llil1shsil("asl #1,") +pat lol loc sru stl $1==$4 && $2==1 && $3==4 call rlol1shstl("lsr #1,") +pat loe loc sru ste $1==$4 && $2==1 && $3==4 call rloe1shste("lsr #1,") +pat lil loc sru sil $1==$4 && $2==1 && $3==4 call rlil1shsil("lsr #1,") + +proc locsh example loc sli +with DD_REG + gen sh* {shconst, $1}, %1 + yields %1 + +pat loc sli small($1) && $2==4 call locsh("asl.l") +pat loc sri small($1) && $2==4 call locsh("asr.l") +pat loc slu small($1) && $2==4 call locsh("asl.l") +pat loc sru small($1) && $2==4 call locsh("lsr.l") +pat loc rol small($1) && $2==4 call locsh("rol.l") +pat loc ror small($1) && $2==4 call locsh("ror.l") + +proc lolbitstl example lol ngi stl + kills all_indir, LOCAL %bd==$1 + gen bit* {LOCAL, $1} + +proc loebitste example loe ngi ste + kills posextern + gen bit* {absolute4, $1} + +proc lilbitsil example lil ngi sil +#ifdef m68020 + kills allexceptcon + gen bit* {ILOCAL, $1} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen bit* {indirect4, %a} +#endif m68020 + +pat lol ngi stl $1==$3 && $2==4 call lolbitstl("neg.l") +pat loe ngi ste $1==$3 && $2==4 call loebitste("neg.l") +pat lil ngi sil $1==$3 && $2==4 call lilbitsil("neg.l") +pat lol com stl $1==$3 && $2==4 call lolbitstl("not.l") +pat loe com ste $1==$3 && $2==4 call loebitste("not.l") +pat lil com sil $1==$3 && $2==4 call lilbitsil("not.l") + +pat lil inc sil $1==$3 +#ifdef m68020 + kills allexceptcon + gen add_l {const, 1}, {ILOCAL, $1} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen add_l {const, 1}, {indirect4, %a} +#endif m68020 + +pat lil dec sil $1==$3 +#ifdef m68020 + kills allexceptcon + gen sub_l {const, 1}, {ILOCAL, $1} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen sub_l {const, 1}, {indirect4, %a} +#endif m68020 + + +proc txxand +with test_set DD_REG + gen test %1 + bxx* {slabel, 1f} + clr_l %2 + 1: yields %2 + +proc txxior +with test_set DD_REG + gen test %1 + bxx* {slabel, 1f} + bset {const, 0}, %2 + 1: yields %2 + +pat tlt and $2==4 call txxand("blt") +pat tle and $2==4 call txxand("ble") +pat teq and $2==4 call txxand("beq") +pat tne and $2==4 call txxand("bne") +pat tge and $2==4 call txxand("bge") +pat tgt and $2==4 call txxand("bgt") + +pat tlt ior $2==4 call txxior("bge") +pat tle ior $2==4 call txxior("bgt") +pat teq ior $2==4 call txxior("bne") +pat tne ior $2==4 call txxior("beq") +pat tge ior $2==4 call txxior("blt") +pat tgt ior $2==4 call txxior("ble") + +proc cmxtxxand +with any4 genreg DD_REG + gen cmp_l %1, %2 + bxx[1] {slabel, 1f} + clr_l %3 + 1: yields %3 +with genreg any4-genreg DD_REG + gen cmp_l %2, %1 + bxx[2] {slabel, 1f} + clr_l %3 + 1: yields %3 +with exact immediate4 imm_cmp4 DD_REG + gen cmp_l %1, %2 + bxx[1] {slabel, 1f} + clr_l %3 + 1: yields %3 +with exact imm_cmp4 immediate4 DD_REG + gen cmp_l %2, %1 + bxx[2] {slabel, 1f} + clr_l %3 + 1: yields %3 + +proc cmxtxxior +with any4 genreg DD_REG + gen cmp_l %1, %2 + bxx[1] {slabel, 1f} + move {const, 1}, %3 + 1: yields %3 +with genreg any4-genreg DD_REG + gen cmp_l %2, %1 + bxx[2] {slabel, 1f} + move {const, 1}, %3 + 1: yields %3 +with exact immediate4 imm_cmp4 DD_REG + gen cmp_l %1, %2 + bxx[1] {slabel, 1f} + move {const, 1}, %3 + 1: yields %3 +with exact imm_cmp4 immediate4 DD_REG + gen cmp_l %2, %1 + bxx[2] {slabel, 1f} + move {const, 1}, %3 + 1: yields %3 + +proc cmxtxx +with any4 genreg + uses DD_REG = {const, 1} + gen cmp_l %1, %2 + bxx[1] {slabel, 1f} + clr_l %a + 1: yields %a +with genreg any4-genreg + uses DD_REG = {const, 1} + gen cmp_l %2, %1 + bxx[2] {slabel, 1f} + clr_l %a + 1: yields %a +with exact immediate4 imm_cmp4 + uses DD_REG = {const, 1} + gen cmp_l %1, %2 + bxx[1] {slabel, 1f} + clr_l %a + 1: yields %a +with exact imm_cmp4 immediate4 + uses DD_REG = {const, 1} + gen cmp_l %2, %1 + bxx[2] {slabel, 1f} + clr_l %a + 1: yields %a +with genreg STACK + uses DD_REG = {const, 1} + gen cmp_l {post_inc4, sp}, %1 + bxx[2] {slabel, 1f} + clr_l %a + 1: yields %a +with exact immediate4 STACK + uses DD_REG = {const, 1} + gen cmp_l %1, {post_inc4, sp} + bxx[1] {slabel, 1f} + clr_l %a + 1: yields %a + +pat cmi tlt and $1==4 && $3==4 call cmxtxxand("blt","bgt") +pat cmi tle and $1==4 && $3==4 call cmxtxxand("ble","bge") +pat cmi teq and $1==4 && $3==4 call cmxtxxand("beq","beq") +pat cmi tne and $1==4 && $3==4 call cmxtxxand("bne","bne") +pat cmi tge and $1==4 && $3==4 call cmxtxxand("bge","ble") +pat cmi tgt and $1==4 && $3==4 call cmxtxxand("bgt","blt") + +pat cmu tlt and $1==4 && $3==4 call cmxtxxand("bcs","bhi") +pat cmu tle and $1==4 && $3==4 call cmxtxxand("bls","bcc") +pat cmu teq and $1==4 && $3==4 call cmxtxxand("beq","beq") +pat cmu tne and $1==4 && $3==4 call cmxtxxand("bne","bne") +pat cmu tge and $1==4 && $3==4 call cmxtxxand("bcc","bls") +pat cmu tgt and $1==4 && $3==4 call cmxtxxand("bhi","bcs") + +pat cmi tlt ior $1==4 && $3==4 call cmxtxxior("bge","ble") +pat cmi tle ior $1==4 && $3==4 call cmxtxxior("bgt","blt") +pat cmi teq ior $1==4 && $3==4 call cmxtxxior("bne","bne") +pat cmi tne ior $1==4 && $3==4 call cmxtxxior("beq","beq") +pat cmi tge ior $1==4 && $3==4 call cmxtxxior("blt","bgt") +pat cmi tgt ior $1==4 && $3==4 call cmxtxxior("ble","bge") + +pat cmu tlt ior $1==4 && $3==4 call cmxtxxior("bcc","bls") +pat cmu tle ior $1==4 && $3==4 call cmxtxxior("bhi","bcs") +pat cmu teq ior $1==4 && $3==4 call cmxtxxior("bne","bne") +pat cmu tne ior $1==4 && $3==4 call cmxtxxior("beq","beq") +pat cmu tge ior $1==4 && $3==4 call cmxtxxior("bcs","bhi") +pat cmu tgt ior $1==4 && $3==4 call cmxtxxior("bls","bcc") + +pat cmi tlt $1==4 call cmxtxx("blt","bgt") +pat cmi tle $1==4 call cmxtxx("ble","bge") +pat cmi teq $1==4 call cmxtxx("beq","beq") +pat cmi tne $1==4 call cmxtxx("bne","bne") +pat cmi tge $1==4 call cmxtxx("bge","blt") +pat cmi tgt $1==4 call cmxtxx("bgt","blt") + +pat cmu tlt $1==4 call cmxtxx("bcs","bhi") +pat cmu tle $1==4 call cmxtxx("bls","bcc") +pat cmu teq $1==4 call cmxtxx("beq","beq") +pat cmu tne $1==4 call cmxtxx("bne","bne") +pat cmu tge $1==4 call cmxtxx("bcc","bls") +pat cmu tgt $1==4 call cmxtxx("bhi","bcs") + +proc cmxzxx example cmu zlt +with any4 genreg STACK + gen cmp_l %1, %2 + bxx[1] {llabel, $2} +with genreg any4-genreg STACK + gen cmp_l %2, %1 + bxx[2] {llabel, $2} +with exact immediate4 imm_cmp4 + kills ALL + gen cmp_l %1, %2 + bxx[1] {llabel, $2} +with exact imm_cmp4 immediate4 + kills ALL + gen cmp_l %2, %1 + bxx[2] {llabel, $2} +with genreg STACK + gen cmp_l {post_inc4, sp}, %1 + bxx[2] {llabel, $2} +with exact immediate4 STACK + gen cmp_l %1, {post_inc4, sp} + bxx[1] {llabel, $2} + +pat cmu zlt $1==4 call cmxzxx("bcs","bhi") +pat cmu zle $1==4 call cmxzxx("bls","bcc") +pat cmu zeq $1==4 call cmxzxx("beq","beq") +pat cmu zne $1==4 call cmxzxx("bne","bne") +pat cmu zge $1==4 call cmxzxx("bcc","bls") +pat cmu zgt $1==4 call cmxzxx("bhi","bcs") + + +proc bxx1_in example loc loc cii loc bne +with imm_cmp1 STACK + gen cmp_b {const, lowb($4)}, %1 + bxx* {llabel, $5} + +proc bxx2_in example loc loc cii loc bne +with imm_cmp2 STACK + gen cmp_w {const, loww($4)}, %1 + bxx* {llabel, $5} + +pat loc loc cii loc blt $1==1 && $2==4 && in_1($4) call bxx1_in("blt") +pat loc loc cii loc ble $1==1 && $2==4 && in_1($4) call bxx1_in("ble") +pat loc loc cii loc beq $1==1 && $2==4 && in_1($4) call bxx1_in("beq") +pat loc loc cii loc bne $1==1 && $2==4 && in_1($4) call bxx1_in("bne") +pat loc loc cii loc bge $1==1 && $2==4 && in_1($4) call bxx1_in("bge") +pat loc loc cii loc bgt $1==1 && $2==4 && in_1($4) call bxx1_in("bgt") + +pat loc loc cii loc blt $1==2 && $2==4 && in_2($4) call bxx2_in("blt") +pat loc loc cii loc ble $1==2 && $2==4 && in_2($4) call bxx2_in("ble") +pat loc loc cii loc beq $1==2 && $2==4 && in_2($4) call bxx2_in("beq") +pat loc loc cii loc bne $1==2 && $2==4 && in_2($4) call bxx2_in("bne") +pat loc loc cii loc bge $1==2 && $2==4 && in_2($4) call bxx2_in("bge") +pat loc loc cii loc bgt $1==2 && $2==4 && in_2($4) call bxx2_in("bgt") + +pat loc loc cii $1==1 && $2==2 +with DD_REG + gen ext_w %1 yields %1 + +pat loc loc cii $1==2 && $2==4 +with DD_REG + gen ext_l %1 yields %1 + +pat loc loc cii $1==1 && $2==4 +with DD_REG +#ifdef m68020 + gen extb_l %1 yields %1 +#else m68020 + gen ext_w %1 + ext_l %1 yields %1 +#endif m68020 + +pat loc loc ciu $1==$2 /* skip this */ +pat loc loc cui $1==$2 /* skip this */ + + +/* The following rules should be handled by the peephole optimizer, I think */ + +pat loc dvi $1==2 && $2==4 leaving loc 1 sri 4 +pat loc dvi $1==4 && $2==4 leaving loc 2 sri 4 +pat loc dvi $1==8 && $2==4 leaving loc 3 sri 4 +pat loc dvi $1==16 && $2==4 leaving loc 4 sri 4 +pat loc dvi $1==32 && $2==4 leaving loc 5 sri 4 +pat loc dvi $1==64 && $2==4 leaving loc 6 sri 4 +pat loc dvi $1==128 && $2==4 leaving loc 7 sri 4 +pat loc dvi $1==256 && $2==4 leaving loc 8 sri 4 + +pat loc dvu $1==2 && $2==4 leaving loc 1 sru 4 +pat loc dvu $1==4 && $2==4 leaving loc 2 sru 4 +pat loc dvu $1==8 && $2==4 leaving loc 3 sru 4 +pat loc dvu $1==16 && $2==4 leaving loc 4 sru 4 +pat loc dvu $1==32 && $2==4 leaving loc 5 sru 4 +pat loc dvu $1==64 && $2==4 leaving loc 6 sru 4 +pat loc dvu $1==128 && $2==4 leaving loc 7 sru 4 +pat loc dvu $1==256 && $2==4 leaving loc 8 sru 4 diff --git a/mach/moon3/ncg/mach.c b/mach/moon3/ncg/mach.c new file mode 100644 index 00000000..ec51f8bf --- /dev/null +++ b/mach/moon3/ncg/mach.c @@ -0,0 +1,236 @@ +/* + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. + * + * This product is part of the Amsterdam Compiler Kit. + * + * Permission to use, sell, duplicate or disclose this software must be + * obtained in writing. Requests for such permissions may be sent to + * + * Dr. Andrew S. Tanenbaum + * Wiskundig Seminarium + * Vrije Universiteit + * Postbox 7161 + * 1007 MC Amsterdam + * The Netherlands + * + */ + +/* + * machine dependent back end routines for the Motorola 68000, 68010 or 68020 + */ + +#ifndef m68k4 +#define m68020 +#endif + /* use m68020 when you want a m68020 cg, don't if you want a + * m68k4 cg. The m68k4 cg can be used for both the MC68000 + * and the MC68010. + */ + +con_part(sz,w) register sz; word w; { + + while (part_size % sz) + part_size++; + if (part_size == 4) + part_flush(); + if (sz == 1) { + w &= 0xFF; + w <<= 8*(3-part_size); + part_word |= w; + } else if (sz == 2) { + w &= 0xFFFF; + if (part_size == 0) + w <<= 16; + part_word |= w; + } else { + assert(sz == 4); + part_word = w; + } + part_size += sz; +} + +con_mult(sz) word sz; { + + if (sz != 4) + fatal("bad icon/ucon size"); + fprintf(codefile,".data4 %s\n",str); +} + +con_float() { + +static int been_here; + if (argval != 4 && argval != 8) + fatal("bad fcon size"); + fprintf(codefile,".data4\t"); + if (argval == 8) + fprintf(codefile,"F_DUM,"); + fprintf(codefile,"F_DUM\n"); + if ( !been_here++) + { + fprintf(stderr,"Warning : dummy float-constant(s)\n"); + } +} + +regscore(off,size,typ,score,totyp) + long off; +{ + if (score == 0) return -1; + switch(typ) { + case reg_float: + return -1; + case reg_pointer: + if (size != 4 || totyp != reg_pointer) return -1; + score *= 2; + break; + case reg_loop: + score += 5; + /* fall through .. */ + case reg_any: + if (size != 4 || totyp == reg_pointer) return -1; + break; + } + if (off >= 0) { + /* parameters must be initialised with an instruction + * like "move.l 4(a6),d0", which costs 2 words. + */ + score -= 2; + } + score -= 1; /* take save/restore into account */ + return score; +} +struct regsav_t { + char *rs_reg; /* e.g. "a3" or "d5" */ + long rs_off; /* offset of variable */ + int rs_size; /* 2 or 4 bytes */ +} regsav[9]; + + +int regnr; + +i_regsave() +{ + regnr = 0; +} + +#define MOVEM_LIMIT 2 +/* If #registers to be saved exceeds MOVEM_LIMIT, we +* use the movem instruction to save registers; else +* we simply use several move.l's. +*/ + +save() +{ + register struct regsav_t *p; + + if (regnr > MOVEM_LIMIT) { + fprintf(codefile,"movem.l "); + for (p = regsav; ;) { + fprintf(codefile,"%s",p->rs_reg); + if (++p == ®sav[regnr]) break; + putc('/',codefile); + } + fprintf(codefile,",-(sp)\n"); + } else { + for (p = regsav; p < ®sav[regnr]; p++) { + fprintf(codefile,"move.l %s,-(sp)\n",p->rs_reg); + } + } + /* initialise register-parameters */ + for (p = regsav; p < ®sav[regnr]; p++) { + if (p->rs_off >= 0) { +#ifdef m68020 + fprintf(codefile,"move.%c (%ld,a6),%s\n", +#else + fprintf(codefile,"move.%c %ld(a6),%s\n", +#endif + (p->rs_size == 4 ? 'l' : 'w'), + p->rs_off, + p->rs_reg); + } + } +} + +restr() +{ + register struct regsav_t *p; + + if (regnr > MOVEM_LIMIT) { + fprintf(codefile,"movem.l (sp)+,"); + for (p = regsav; ;) { + fprintf(codefile,"%s",p->rs_reg); + if (++p == ®sav[regnr]) break; + putc('/',codefile); + } + putc('\n',codefile); + } else { + for (p = ®sav[regnr-1]; p >= regsav; p--) { + fprintf(codefile,"move.l (sp)+,%s\n",p->rs_reg); + } + } + fprintf(codefile,"unlk a6\n"); + fprintf(codefile,"rts\n"); +} + + +f_regsave() +{ + save(); +} + +regsave(str,off,size) + char *str; + long off; +{ + assert (regnr < 9); + regsav[regnr].rs_reg = str; + regsav[regnr].rs_off = off; + regsav[regnr++].rs_size = size; + fprintf(codefile, "!Local %ld into %s\n",off,str); +} + +regreturn() +{ + restr(); +} + + +prolog(nlocals) full nlocals; { + +#ifdef m68020 + fprintf(codefile,"tst.b (-%ld,sp)\nlink\ta6,#-%ld\n",nlocals+40,nlocals); +#else + fprintf(codefile,"tst.b -%ld(sp)\nlink\ta6,#-%ld\n",nlocals+40,nlocals); +#endif +} + + + +mes(type) word type ; { + int argt ; + + switch ( (int)type ) { + case ms_ext : + for (;;) { + switch ( argt=getarg( + ptyp(sp_cend)|ptyp(sp_pnam)|sym_ptyp) ) { + case sp_cend : + return ; + default: + strarg(argt) ; + fprintf(codefile,".define %s\n",argstr) ; + break ; + } + } + default : + while ( getarg(any_ptyp) != sp_cend ) ; + break ; + } +} + + +char *segname[] = { + ".sect .text", /* SEGTXT */ + ".sect .data", /* SEGCON */ + ".sect .rom", /* SEGROM */ + ".sect .bss" /* SEGBSS */ +}; diff --git a/mach/moon3/ncg/mach.h b/mach/moon3/ncg/mach.h new file mode 100644 index 00000000..ff2cf66c --- /dev/null +++ b/mach/moon3/ncg/mach.h @@ -0,0 +1,39 @@ +#ifndef m68k4 +#define m68020 +#endif + /* m68020 should be used for a m68020 cg, and it should + * not be used for a m68k4 cg + */ + +#define ex_ap(y) fprintf(codefile,".extern %s\n",y) +#define in_ap(y) /* nothing */ + +#define newilb(x) fprintf(codefile,"%s:\n",x) +#define newdlb(x) fprintf(codefile,"%s:\n",x) +#define dlbdlb(x,y) fprintf(codefile,"%s = %s\n",x,y) +#define newlbss(l,x) fprintf(codefile,"%s:.space\t%ld\n",l,x); + +#define pop_fmt "(sp)+" +#define cst_fmt "%ld" +#define off_fmt "%ld" +#define ilb_fmt "I%03x%x" +#define dlb_fmt "_%d" +#define hol_fmt "hol%d" + +#ifdef m68020 +#define loc_off "(%d,a6)" +#define arg_off "(8+%d,a6)" +#else +#define loc_off "%d(a6)" +#define arg_off "8+%d(a6)" +#endif +#define hol_off "%ld+hol%d" + +#define con_cst(x) fprintf(codefile,".data4\t%ld\n",x) +#define con_ilb(x) fprintf(codefile,".data4\t%s\n",x) +#define con_dlb(x) fprintf(codefile,".data4\t%s\n",x) + +#define modhead ".sect .text\n.sect .rom\n.sect .data\n.sect .bss\n" + +#define id_first '_' +#define BSS_INIT 0 diff --git a/mach/moon3/ncg/table b/mach/moon3/ncg/table new file mode 100644 index 00000000..6518487a --- /dev/null +++ b/mach/moon3/ncg/table @@ -0,0 +1,3288 @@ + /******************************** + * * + * 68000, 68010 and 68020 * + * back end table * + * * + ********************************/ + + +#ifndef m68k4 +#define m68020 +#endif + /* m68020 to be defined if this is the 68020 table. + * The 68000 and 68010 tables are identical. + */ + + +#define small(x) ((x)>=1 && (x)<=8) +#define nicesize(x) ((x)==1||(x)==2||(x)==4||(x)==8) +#define lowb(x) (((x)<<24)>>24) +#define loww(x) (((x)<<16)>>16) +#define in_1(x) ((x)>=0-128 && (x)<128) +#define in_2(x) ((x)>=0-32768 && (x)<32768) + + +EM_WSIZE = 4 +EM_PSIZE = 4 +EM_BSIZE = 8 + +SL = 8 + +TIMEFACTOR = 1/2 + + +PROPERTIES + +D_REG /* data registers */ +A_REG /* address registers */ +DD_REG /* allocatable D_REG, may not be a register variable */ +AA_REG /* allocatable A_REG, may not be a register variable */ + + + +REGISTERS + +d0, d1, d2 :D_REG, DD_REG. +d3, d4, d5, d6, d7 :D_REG regvar. +a0, a1 :A_REG, AA_REG. +a2, a3, a4, a5 :A_REG regvar(reg_pointer). +lb ("a6"), sp :A_REG. /* localbase and stack pointer */ + + + + +TOKENS + + /* Not all addressing modes available on the MC68020 are used in this + * table. E.g (Dn), data register indirect is not used. Compared to + * (An), address register indirect, (Dn) requires two more bytes and + * several more clock cycles. Using (Dn) is even more expensive in + * time than first moving Dn to an address register An, and then using + * (An). For this kind of reasons several addressing modes are + * not used in this table. + * + * Cost in bytes may sometimes be incorrect. Several effective addresses + * use displacements that can occupy either 2 or 4 bytes. These are not + * considered different TOKENS in this table. + * + * Data registers are the only registers used as index registers in this + * table; address registers are only used to hold addresses. + * + * For the m68k4 table: the MC68000 and MC68010 have two modes that use + * displacements (offsets) of limited size: + * - offset(A_REG, Index_reg), where offset is only 8 bits, and + * - offset(A_REG), where offset can only be 16 bits. + * To make sure that no output is given with offsets too large, two + * extra tokens are declared: t_regAregXcon and t_regAcon. These are + * used as addresses to these modes. Whenever the displacements become + * too large, they are transformed into different tokens. + * + * Sometimes some TOKENS are used with displacements (offsets) of 0. + * It would have been possible to provide separate TOKENS for these, in + * case the assembler doesn't handle zero offsets optimally. This + * however would mean a very large amount of extra TOKENS and SETS for + * a very small profit in code bytes, so we won't do that. + * + * To prevent the TOKENS list from getting too unreadable, #ifdefs are + * used to form three parts: + * (i) the common part; + * (ii) the m68k4 part; + * (iii) the m68020 part; + */ + + /* Part (i) */ +const = {INT num;} 4 cost(4,4) "#" num . +indirect4 = {A_REG reg;} 4 cost(0,4) "(" reg ")" . +post_inc4 = {A_REG reg;} 4 cost(0,4) "(" reg ")+" . +pre_dec4 = {A_REG reg;} 4 cost(0,5) "-(" reg ")" . +indirect2 = {A_REG reg;} 4 cost(0,4) "(" reg ")" . +post_inc2 = {A_REG reg;} 4 cost(0,4) "(" reg ")+" . +pre_dec2 = {A_REG reg;} 4 cost(0,5) "-(" reg ")" . +indirect1 = {A_REG reg;} 4 cost(0,4) "(" reg ")" . +post_inc1 = {A_REG reg;} 4 cost(0,4) "(" reg ")+" . +pre_dec1 = {A_REG reg;} 4 cost(0,5) "-(" reg ")" . + +ext_addr = {ADDR bd;} 4 cost(4,5) "#" bd . +llabel = {ADDR bd;} 4 cost(2,0) bd . +slabel = {ADDR bd;} 4 cost(0,0) bd . +shconst = {INT num;} 4 cost(0,0) "#" num . + +#ifndef m68020 + /* Part (ii) */ +absolute4 = {ADDR bd;} 4 cost(4,8) bd . +offsetted4 = {A_REG reg; INT bd;} 4 cost(2,6) bd "(" reg ")" . +index_off4 = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,7) + bd "(" reg "," xreg ".l)" . +absolute2 = {ADDR bd;} 4 cost(4,6) bd . +offsetted2 = {A_REG reg; INT bd;} 4 cost(2,4) bd "(" reg ")" . +index_off2 = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,5) + bd "(" reg "," xreg ".l)" . +absolute1 = {ADDR bd;} 4 cost(4,6) bd . +offsetted1 = {A_REG reg; INT bd;} 4 cost(2,4) bd "(" reg ")" . +index_off1 = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,5) + bd "(" reg "," xreg ".l)" . + +LOCAL = {INT bd;} 4 cost(2,6) bd "(a6)" . + +local_addr = {INT bd;} 4 cost(2,6) bd "(a6)" . +regAcon = {A_REG reg; INT bd;} 4 cost(2,6) bd "(" reg ")" . +regAregXcon = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,8) + bd "(" reg "," xreg ".l)" . + /* note: in the m68k4 version %sc always equals 1 */ + +t_regAregXcon = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,8) . +t_regAcon = {A_REG reg; INT bd;} 4 cost(2,6) . + +#else m68020 + /* Part (iii) */ +absolute4 = {ADDR bd;} 4 cost(4,7) "(" bd ")" . +offsetted4 = {A_REG reg; INT bd;} 4 cost(2,6) "(" bd "," reg ")" . +index_off4 = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(4,9) + "(" bd "," reg "," xreg ".l*" sc ")" . +abs_index4 = {INT sc; D_REG xreg; ADDR bd;} 4 cost(6,9) + "(" bd "," xreg ".l*" sc ")" . +OFF_off4 = {A_REG reg; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "]," od ")" . +OFF_indoff4 = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "]," xreg ".l*" sc "," od ")" . +INDOFF_off4 = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "," xreg ".l*" sc "]," od ")" . +ABS_off4 = {ADDR bd; ADDR od;} 4 cost(8,22) "([" bd "]," od ")" . +ABS_indoff4 = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,22) + "([" bd "]," xreg ".l*" sc "," od ")" . +ABSIND_off4 = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,22) + "([" bd "," xreg ".l*" sc "]," od ")" . + +absolute2 = {ADDR bd;} 4 cost(4,7) "(" bd ")" . +offsetted2 = {A_REG reg; INT bd;} 4 cost(2,6) "(" bd "," reg ")" . +index_off2 = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(4,9) + "(" bd "," reg "," xreg ".l*" sc ")" . +abs_index2 = {INT sc; D_REG xreg; ADDR bd;} 4 cost(6,9) + "(" bd "," xreg ".l*" sc ")" . +OFF_off2 = {A_REG reg; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "]," od ")" . +OFF_indoff2 = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "]," xreg ".l*" sc "," od ")" . +INDOFF_off2 = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "," xreg ".l*" sc "]," od ")" . +ABS_off2 = {ADDR bd; ADDR od;} 4 cost(8,22) "([" bd "]," od ")" . +ABS_indoff2 = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,22) + "([" bd "]," xreg ".l*" sc "," od ")" . +ABSIND_off2 = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,22) + "([" bd "," xreg ".l*" sc "]," od ")" . + +absolute1 = {ADDR bd;} 4 cost(4,7) "(" bd ")" . +offsetted1 = {A_REG reg; INT bd;} 4 cost(2,6) "(" bd "," reg ")" . +index_off1 = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(4,9) + "(" bd "," reg "," xreg ".l*" sc ")" . +abs_index1 = {INT sc; D_REG xreg; ADDR bd;} 4 cost(6,9) + "(" bd "," xreg ".l*" sc ")" . +OFF_off1 = {A_REG reg; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "]," od ")" . +OFF_indoff1 = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "]," xreg ".l*" sc "," od ")" . +INDOFF_off1 = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,19) + "([" bd "," reg "," xreg ".l*" sc "]," od ")" . +ABS_off1 = {ADDR bd; ADDR od;} 4 cost(8,22) "([" bd "]," od ")" . +ABS_indoff1 = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,22) + "([" bd "]," xreg ".l*" sc "," od ")" . +ABSIND_off1 = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,22) + "([" bd "," xreg ".l*" sc "]," od ")" . + +LOCAL = {INT bd;} 4 cost(2,6) "(" bd ",a6)" . +ILOCAL = {INT bd;} 4 cost(4,16) "([" bd ",a6])" . + +local_addr = {INT bd;} 4 cost(2,3) "(" bd ",a6)" . +regAcon = {A_REG reg; INT bd;} 4 cost(2,3) "(" bd "," reg ")" . +regAregXcon = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,7) + "(" bd "," reg "," xreg ".l*" sc ")" . +off_con = {A_REG reg; INT bd; ADDR od;} 4 cost(6,18) + "([" bd "," reg "]," od ")". +off_regXcon = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,18) + "([" bd "," reg "]," xreg ".l*" sc "," od ")" . +indoff_con = {A_REG reg; D_REG xreg; INT sc; INT bd; ADDR od;} 4 cost(6,18) + "([" bd "," reg "," xreg ".l*" sc "]," od ")" . +abs_con = {ADDR bd; ADDR od;} 4 cost(8,21) "([" bd "]," od ")" . +abs_regXcon = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,21) + "([" bd "]," xreg ".l*" sc "," od ")" . +absind_con = {INT sc; D_REG xreg; ADDR bd; ADDR od;} 4 cost(8,21) + "([" bd "," xreg ".l*" sc "]," od ")" . +ext_regX = {INT sc; D_REG xreg; ADDR bd;} 4 cost(6,15) + "(" bd "," xreg ".l*" sc ")" . + +regX = {INT sc; D_REG xreg;} 4 cost(2,7) "(" xreg ".l*" sc ")" . +DREG_pair = {D_REG reg1; D_REG reg2;} 8 cost(2,0) reg1 ":" reg2 . + +#define t_regAregXcon regAregXcon +#define t_regAcon regAcon + +#endif m68020 + +SETS + + /* The SETS list cannot be kept as 'readable' as the TOKENS list + * because cgg is one pass. + */ + +#ifndef m68020 + /* A m68k4 part */ +data4 = D_REG + LOCAL + const + post_inc4 + pre_dec4 + + indirect4 + offsetted4 + index_off4 + absolute4 + + ext_addr . +memory4 = data4 - D_REG . +control4 = indirect4 + offsetted4 + index_off4 + absolute4 + + LOCAL . +alterable4 = data4 + A_REG - const - ext_addr . +any4 = data4 + A_REG . /* all four above together */ + +data2 = D_REG + post_inc2 + pre_dec2 + indirect2 + + offsetted2 + index_off2 + absolute2 + const . +memory2 = data2 - D_REG . +control2 = indirect2 + offsetted2 + index_off2 + absolute2 . +alterable2 = data2 + A_REG - const . +any2 = data2 + A_REG . + +data1 = D_REG + post_inc1 + pre_dec1 + indirect1 + + offsetted1 + index_off1 + absolute1 + const . +memory1 = data1 - D_REG . +control1 = indirect1 + offsetted1 + index_off1 + absolute1 . +alterable1 = data1 - const . +any1 = data1 . + +#else m68020 + +data4 = D_REG + indirect4 + post_inc4 + pre_dec4 + index_off4 + + offsetted4 + OFF_off4 + OFF_indoff4 + + INDOFF_off4 + + ABS_off4 + ABS_indoff4 + ABSIND_off4 + + absolute4 + abs_index4 + const + ext_addr + + LOCAL + ILOCAL . +memory4 = data4 - D_REG . +control4 = memory4 - (post_inc4 + pre_dec4 + const + ext_addr) . +alterable4 = data4 + A_REG - const - ext_addr . +any4 = data4 + A_REG . /* all four above together */ + +data2 = D_REG + indirect2 + post_inc2 + pre_dec2 + index_off2 + + offsetted2 + OFF_off2 + OFF_indoff2 + + INDOFF_off2 + + ABS_off2 + ABS_indoff2 + ABSIND_off2 + + absolute2 + abs_index2 + const . +memory2 = data2 - D_REG . +control2 = memory2 - (post_inc2 + pre_dec2 + const) . +alterable2 = data2 + A_REG - const . +any2 = data2 + A_REG . /* all four above together */ + +data1 = D_REG + indirect1 + post_inc1 + pre_dec1 + index_off1 + + offsetted1 + OFF_off1 + OFF_indoff1 + + INDOFF_off1 + + ABS_off1 + ABS_indoff1 + ABSIND_off1 + + absolute1 + abs_index1 + const . +memory1 = data1 - D_REG . +control1 = memory1 - (post_inc1 + pre_dec1 + const) . +alterable1 = data1 - const . +any1 = data1 . /* all four above together */ + +#endif m68020 + /* This is a common part */ +any = any4 + any2 + any1 . +absolute = absolute4 + absolute2 + absolute1 . +control = control4 + control2 + control1 . +indirect = indirect4 + indirect2 + indirect1 . +pre_post = pre_dec4 + pre_dec2 + pre_dec1 + + post_inc4 + post_inc2 + post_inc1 . +offsetted = offsetted4 + offsetted2 + offsetted1 . +index_off = index_off4 + index_off2 + index_off1 . + +#ifndef m68020 + /* A m68k4 part */ +regind_addr = regAcon + regAregXcon + t_regAcon + t_regAregXcon . +address = ext_addr + local_addr + regAcon + regAregXcon . +all_regind = indirect + offsetted + pre_post + index_off + + regind_addr . +all_indir = all_regind . +allexceptcon = ALL - ( D_REG + A_REG + const + + local_addr + ext_addr + regAcon + regAregXcon + + t_regAcon + t_regAregXcon ) . +use_index = index_off4 + index_off2 + index_off1 . + +#else m68020 + +reg_memind4 = OFF_off4 + OFF_indoff4 + INDOFF_off4 . +memind4 = reg_memind4 + + ABS_off4 + ABS_indoff4 . +reg_memind2 = OFF_off2 + OFF_indoff2 + INDOFF_off2 . +memind2 = reg_memind2 + + ABS_off2 + ABS_indoff2 . +reg_memind1 = OFF_off1 + OFF_indoff1 + INDOFF_off1 . +memind1 = reg_memind1 + + ABS_off1 + ABS_indoff1 . +reg_memind = reg_memind4 + reg_memind2 + reg_memind1 . +memind = memind4 + memind2 + memind1 . +regind_addr = regAcon + regAregXcon + + off_con + off_regXcon + + indoff_con . +address = regind_addr + + ext_addr + local_addr + + abs_con + abs_regXcon + + absind_con + + ext_regX . +all_regind = indirect + offsetted + index_off + pre_post + + reg_memind + regind_addr . +all_indir = all_regind + memind + ILOCAL . +allexceptcon = ALL - ( D_REG + A_REG + const + + local_addr + ext_addr + regAcon + regAregXcon + ext_regX ) . +use_index4 = index_off4 + abs_index4 + + OFF_indoff4 + INDOFF_off4 + + ABS_indoff4 + ABSIND_off4 . +use_index2 = index_off2 + abs_index2 + + OFF_indoff2 + INDOFF_off2 + + ABS_indoff2 + ABSIND_off2 . +use_index1 = index_off1 + abs_index1 + + OFF_indoff1 + INDOFF_off1 + + ABS_indoff1 + ABSIND_off1 . +use_indaddr = regAregXcon + + off_regXcon + indoff_con + + abs_regXcon + absind_con + + ext_regX . + +use_index = use_index4 + use_index2 + use_index1 + use_indaddr + regX . + +#endif m68020 + /* A common part */ +posextern = absolute + all_indir . + +genreg = D_REG + A_REG. +label = llabel + slabel . +immediate4 = const + ext_addr . +conreg4 = D_REG + immediate4 . +conreg2 = D_REG + const . +conreg1 = D_REG + const . +shconreg = D_REG + shconst . +datalt4 = data4 * alterable4 . +datalt2 = data2 * alterable2 . +datalt1 = data1 * alterable1 . +datalt = datalt4 + datalt2 + datalt1 . +memalt4 = memory4 * alterable4 . +memalt2 = memory2 * alterable2 . +memalt1 = memory1 * alterable1 . + +#ifndef m68020 + /* A m68k4 part */ +imm_cmp4 = alterable4 . +imm_cmp2 = alterable2 . +imm_cmp1 = datalt1 . + +test_set4 = datalt4 . +test_set2 = datalt2 . +test_set1 = datalt1 . + +#else m68020 + +imm_cmp4 = any4 - immediate4 . +imm_cmp2 = any2 - const . +imm_cmp1 = data1 - const . + +test_set4 = data4 - immediate4 . +test_set2 = data2 - const . +test_set1 = data1 - const . + +#endif m68020 + +test_set = test_set4 + test_set2 + test_set1 . + +#ifndef m68020 +t_address = address + t_regAregXcon + t_regAcon . +#else m68020 +#define t_address address +#endif m68020 + + +INSTRUCTIONS + + /* Since the 68000 , the 68010 and the 68020 instruction sets are rather + * extensive, especially because e.g. 'add.l' and 'add.w' are + * considered different instructions, only those instructions are + * listed here that are used in the rest of this table. + * + * Instruction timing cost cannot be accurately given, nor the timing + * cost for getting operands. Detailed information about this can be + * found in the "MC68020 User's Manual", section 9, about instruction + * timing. The cost used in this table are 'worst case' cost, as + * mentioned in section 9 of the user's manual. + * + * The first few instructions had to be added because register + * variables are used. The LOCALs below are register variables. + * One may not conclude that these operations are also allowed + * on LOCALs that are not register variables. + * The cost have been adapted, but are not accurate; when 'real' + * LOCALs are used the cost are very inaccurate. + */ + +add_l "add.l" any4:ro, LOCAL:rw:cc cost(0,0). +lea address:ro, LOCAL:wo cost(0,0). +sub_l "sub.l" any4:ro, LOCAL:rw:cc cost(0,0). +sh "illegal" shconreg:ro, LOCAL:rw:cc cost(0,0). +sh "illegal" LOCAL:ro, LOCAL:rw:cc cost(0,0). +xxx "illegal" data4:ro, LOCAL:rw:cc cost(0,0). +xxx "illegal" LOCAL:ro, alterable4:rw:cc cost(0,0). +#ifdef m68020 +divs_l "divs.l" data4:ro, LOCAL:rw:cc cost(0,90). +divu_l "divu.l" data4:ro, LOCAL:rw:cc cost(0,78). +muls_l "muls.l" data4:ro, LOCAL:rw:cc cost(0,44). +mulu_l "mulu.l" data4:ro, LOCAL:rw:cc cost(0,44). +#endif m68020 + +add_l "add.l" any4:ro, D_REG:rw:cc cost(2,3). +add_l "add.l" any4:ro, A_REG:rw cost(2,3). +add_l "add.l" conreg4:ro, alterable4:rw:cc cost(2,6). +and_l "and.l" data4:ro, D_REG:rw:cc cost(2,3). +and_l "and.l" D_REG:ro, memalt4:rw:cc cost(2,6). +and_l "and.l" const:ro, datalt4:rw:cc cost(2,6). +asl_l "asl.l" shconreg:ro, D_REG:rw:cc cost(2,5). +asl "asl #1," memalt2:rw:cc cost(2,4). +asr_l "asr.l" shconreg:ro, D_REG:rw:cc cost(2,4). +asr "asr #1," memalt2:rw:cc cost(2,4). +bra label cost(2,5). +bcc label cost(2,5). +bcs label cost(2,5). +beq label cost(2,5). +bge label cost(2,5). +bgt label cost(2,5). +bhi label cost(2,5). +ble label cost(2,5). +bls label cost(2,5). +blt label cost(2,5). +bmi label cost(2,5). +bne label cost(2,5). +bpl label cost(2,5). +bvc label cost(2,5). +bvs label cost(2,5). +bset conreg2:ro, D_REG:rw kills :cc cost(2,4). +btst conreg2:ro, data1:rw kills :cc cost(2,3). +clr_l "clr.l" D_REG:wo:cc cost(2,3). +clr_l "clr.l" memalt4:wo:cc cost(2,6). +clr_w "clr.w" D_REG:wo:cc cost(2,2). +clr_w "clr.w" memalt2:wo:cc cost(2,4). +clr_b "clr.b" D_REG:wo:cc cost(2,2). +clr_b "clr.b" memalt1:wo:cc cost(2,4). +cmp_l "cmp.l" any4:ro, genreg:ro kills :cc cost(2,3). +cmp_l "cmp.l" post_inc4:ro, post_inc4:ro kills :cc cost(2,2). +cmp_l "cmp.l" immediate4:ro, imm_cmp4:ro kills :cc cost(2,2). +cmp_w "cmp.w" any2:ro, genreg:ro kills :cc cost(2,3). +cmp_w "cmp.w" post_inc2:ro, post_inc2:ro kills :cc cost(2,2). +cmp_w "cmp.w" const:ro, imm_cmp2:ro kills :cc cost(2,2). +cmp_b "cmp.b" data1:ro, D_REG:ro kills :cc cost(2,3). +cmp_b "cmp.b" post_inc1:ro, post_inc1:ro kills :cc cost(2,2). +cmp_b "cmp.b" const:ro, imm_cmp1:ro kills :cc cost(2,2). +dbf D_REG:rw, label cost(2,5). +eor_l "eor.l" conreg4:ro, datalt4:rw:cc cost(2,6). +ext_l "ext.l" D_REG:rw:cc cost(2,2). +ext_w "ext.w" D_REG:rw:cc cost(2,2). +jmp address+control4 cost(2,0). +jsr address+control4 kills :cc cost(2,3). +lea address+control4:ro, A_REG:wo cost(2,0). +lsl_l "lsl.l" shconreg:ro, D_REG:rw:cc cost(2,4). +lsl "lsl #1," memalt2:rw:cc cost(2,4). +lsr_l "lsr.l" shconreg:ro, D_REG:rw:cc cost(2,4). +lsr "lsr #1," memalt2:rw:cc cost(2,4). +move_l "move.l" any4:ro, alterable4:wo:cc cost(2,2). +move_w "move.w" any2:ro, alterable2:wo:cc cost(2,2). +move_b "move.b" data1:ro, alterable1:wo:cc cost(2,2). +neg_l "neg.l" D_REG:rw:cc cost(2,3). +neg_l "neg.l" memory4:rw:cc cost(2,6). +not_l "not.l" D_REG:rw:cc cost(2,3). +not_l "not.l" memory4:rw:cc cost(2,6). +or_l "or.l" data4:ro, D_REG:rw:cc cost(2,3). +or_l "or.l" D_REG:ro, memalt4:rw:cc cost(2,6). +or_l "or.l" const:ro, datalt4:rw:cc cost(2,6). +rol_l "rol.l" shconreg:ro, D_REG:rw:cc cost(2,4). +rol "rol #1," memalt2:rw:cc cost(2,4). +ror_l "ror.l" shconreg:ro, D_REG:rw:cc cost(2,4). +ror "ror #1," memalt2:rw:cc cost(2,4). +roxl "roxl #1," memalt2:rw:cc cost(2,4). +roxr "roxr #1," memalt2:rw:cc cost(2,4). +sne datalt1:rw cost(2,3). +sub_l "sub.l" any4:ro, D_REG:rw:cc cost(2,3). +sub_l "sub.l" any4:ro, A_REG:rw cost(2,3). +sub_l "sub.l" conreg4:ro, alterable4:rw:cc cost(2,6). +tst_l "tst.l" test_set4:ro:cc cost(2,3). +tst_w "tst.w" test_set2:ro:cc cost(2,3). +tst_b "tst.b" test_set1:ro:cc cost(2,3). +unlk A_REG cost(2,6). + +bxx "illegal" label cost(2,5). +xxx "illegal" data4:ro, D_REG:rw:cc cost(2,3). +xxx "illegal" conreg4:ro, memalt4:rw:cc cost(2,6). +bit "illegal" control4:rw:cc cost(2,6). +sh "illegal" shconreg:ro, D_REG:rw:cc cost(2,4). +shw "illegal" control2:rw:cc cost(2,4). + +#ifdef m68020 +cmp2_l "cmp2.l" address+control4:ro, genreg:ro kills :cc cost(2,18). +divs_l "divs.l" data4:ro, D_REG:rw:cc cost(2,90). +divsl_l "divsl.l" data4:ro, DREG_pair:rw kills :cc cost(2,90). +divu_l "divu.l" data4:ro, D_REG:rw:cc cost(2,78). +divul_l "divul.l" data4:ro, DREG_pair:rw kills :cc cost(2,78). +extb_l "extb.l" D_REG:rw:cc cost(2,4). +muls_l "muls.l" data4:ro, D_REG:rw:cc cost(2,44). +mulu_l "mulu.l" data4:ro, D_REG:rw:cc cost(2,44). +pea address+control4+regX cost(2,4). +#else m68020 +pea address+control4 cost(2,4). +#endif m68020 + + /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * Extra pseudo instruction; it just kills a D_REG; + * it is necessary with long divides where remainders are important; + * see also: 'pat rmi' and 'pat rmu' + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ +killreg "! kill" D_REG:wo cost(0,0). + + +MOVES + +from const %num==0 to D_REG + gen clr_l %2 + +from const %num==0 to memalt4 + gen clr_l %2 + +from const %num==0 to memalt2 + gen clr_w %2 + +from const %num==0 to memalt1 + gen clr_b %2 + +from const to memalt1 + gen move_b {const, lowb(%1.num)}, %2 + +from const to memalt2 + gen move_w {const, loww(%1.num)}, %2 + +from regAcon %bd==0 to A_REG + gen move_l %1.reg, %2 + +#ifndef m68020 +from t_regAregXcon sfit(%bd, 8) to A_REG + gen lea {regAregXcon, %1.reg, %1.xreg, 1, %1.bd}, %2 + +from t_regAregXcon to A_REG + gen lea {regAregXcon, %1.reg, %1.xreg, 1, 0}, %2 + add_l {const, %1.bd}, %2 + +from t_regAcon sfit(%bd, 16) to A_REG + gen lea {regAcon, %1.reg, %1.bd}, %2 + +from t_regAcon to A_REG + gen move_l %1.reg, %2 + add_l {const, %1.bd}, %2 +#endif m68020 + +from address - ext_addr to A_REG + gen lea %1, %2 + +from any4 to alterable4 + gen move_l %1, %2 + +from any2 to datalt2 + gen move_w %1, %2 + +from data1 to datalt1 + gen move_b %1, %2 + + + + +TESTS + + +to test test_set4 + gen tst_l %1 + +to test test_set2 + gen tst_w %1 + +to test test_set1 + gen tst_b %1 + + +STACKINGRULES + + +from const %num==0 to STACK + gen clr_l {pre_dec4, sp} + +#ifndef m68020 +from t_regAregXcon sfit(%bd, 8) to STACK + gen pea {regAregXcon, %1.reg, %1.xreg, 1, %1.bd} + +from t_regAregXcon to STACK + gen pea {regAregXcon, %1.reg, %1.xreg, 1, 0} + add_l {const, %1.bd}, {indirect4, sp} + +from t_regAcon sfit(%bd, 16) to STACK + gen pea {regAcon, %1.reg, %1.bd} + +from t_regAcon to STACK + gen move_l %1.reg, {pre_dec4, sp} + add_l {const, %1.bd}, {indirect4, sp} +#endif m68020 + +from address - ext_addr to STACK + gen pea %1 + +from ext_addr to STACK + gen pea {absolute4, %1.bd} + +from const to STACK + gen pea {absolute4, %1.num} + +from any4 to STACK + gen move_l %1, {pre_dec4, sp} + +from any2 to STACK + gen clr_l {pre_dec4, sp} + move_w %1, {offsetted2, sp, 2} + +from data1 to STACK + gen clr_l {pre_dec4, sp} + move_b %1, {offsetted1, sp, 3} + +#ifdef m68020 +from regX to STACK + gen pea %1 +#endif m68020 + /* This last stackingrule is never used: whenever regX is put on + * the fakestack, some em-instuctions are left that remove it + * immediately. However cgg complained about not having a + * stackingrule for regX, so here it is + */ + + +COERCIONS + + +from STACK + uses DD_REG + gen move_l {post_inc4, sp}, %a + yields %a + +from STACK + uses AA_REG + gen move_l {post_inc4, sp}, %a + yields %a + +#ifndef m68020 +from t_regAregXcon sfit(%bd, 8) + yields {regAregXcon, %1.reg, %1.xreg, 1, %1.bd} + +from t_regAregXcon + uses AA_REG=%1.reg + gen add_l {const, %1.bd}, %a + yields {regAregXcon, %a, %1.xreg, 1, 0} + +from t_regAcon sfit(%bd, 16) + yields {regAcon, %1.reg, %1.bd} + +from t_regAcon + uses reusing %1, AA_REG=%1.reg + gen add_l {const, %1.bd}, %a + yields %a +#endif m68020 + +from t_address + uses reusing %1, AA_REG = %1 + yields %a + +from any4 + uses reusing %1, DD_REG = %1 + yields %a + +from any4 + uses reusing %1, AA_REG = %1 + yields %a + +from memory2 + uses DD_REG = {const, 0} + gen move_w %1, %a yields %a + +from memory1 + uses DD_REG = {const, 0} + gen move_b %1, %a yields %a + + + + +PATTERNS + +/************************************************ + * Group 0: rules for register variables * + * LOCALs mentioned here refer to registers * + ************************************************/ + +pat lol inreg($1)==reg_pointer + kills pre_post %reg==regvar($1, reg_pointer) + yields {LOCAL, $1} + +pat lil inreg($1)==reg_pointer + kills pre_post %reg==regvar($1, reg_pointer) + yields {indirect4, regvar($1, reg_pointer)} + +pat stl inreg($1)==reg_any +with any4 + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen move %1, {LOCAL, $1} + +pat stl inreg($1)==reg_pointer +with any4 + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + gen move %1, {LOCAL, $1} +with exact ext_addr + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + gen move %1, {LOCAL, $1} +with exact address-ext_addr + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + gen lea %1, {LOCAL, $1} + +pat sil inreg($1)==reg_pointer +with any4 + kills allexceptcon + gen move %1, {indirect4, regvar($1, reg_pointer)} + + +pat lol sbi stl $1==$3 && $2==4 && inreg($1)==reg_any +with any4 + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen sub_l %1, {LOCAL, $1} + neg_l {LOCAL, $1} + +pat lol sbu stl $1==$3 && $2==4 && inreg($1)==reg_any +with any4 + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen sub_l %1, {LOCAL, $1} + neg_l {LOCAL, $1} + +pat lil sbi sil $1==$3 && $2==4 && inreg($1)==reg_pointer +with conreg4 + kills allexceptcon + gen sub_l %1, {indirect4, regvar($1, reg_pointer)} + neg_l {indirect4, regvar($1, reg_pointer)} + +pat lil sbu sil $1==$3 && $2==4 && inreg($1)==reg_pointer +with conreg4 + kills allexceptcon + gen sub_l %1, {indirect4, regvar($1, reg_pointer)} + neg_l {indirect4, regvar($1, reg_pointer)} + + +pat lil ngi sil $1==$3 && $2==4 && inreg($1)==reg_pointer + kills allexceptcon + gen neg_l {indirect4, regvar($1, reg_pointer)} + +pat lil com sil $1==$3 && $2==4 && inreg($1)==reg_pointer + kills allexceptcon + gen not_l {indirect4, regvar($1, reg_pointer)} + + +proc lolcshstl example lol loc sli stl + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen sh* {shconst, $2}, {LOCAL, $1} + +proc lolrshstl example lol lol sli stl + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen sh* {LOCAL, $2}, {LOCAL, $1} + +proc lil1shlsil example lil loc sli sil /* only left */ + kills allexceptcon + gen shw* {offsetted2, regvar($1, reg_pointer), 2} + roxl {indirect2, regvar($1, reg_pointer)} + +proc lil1shrsil example lil loc sli sil /* only right */ + kills allexceptcon + gen shw* {indirect2, regvar($1, reg_pointer)} + roxr {offsetted2, regvar($1, reg_pointer), 2} + +pat lol loc sli stl $1==$4 && small($2) && $3==4 && inreg($1)==reg_any + call lolcshstl("asl.l") +pat lol loc slu stl $1==$4 && small($2) && $3==4 && inreg($1)==reg_any + call lolcshstl("asl.l") +pat lol lol sli stl $1==$4 && inreg($1)==reg_any && $3==4 && inreg($2)==reg_any + call lolrshstl("asl.l") +pat lol lol slu stl $1==$4 && inreg($1)==reg_any && $3==4 && inreg($2)==reg_any + call lolrshstl("asl.l") +pat lil loc sli sil $1==$4 && $2==1 && $3==4 && inreg($1)==reg_pointer + call lil1shlsil("asl #1,") +pat lil loc slu sil $1==$4 && $2==1 && $3==4 && inreg($1)==reg_pointer + call lil1shlsil("asl #1,") +pat lol loc sri stl $1==$4 && small($2) && $3==4 && inreg($1)==reg_any + call lolcshstl("asr.l") +pat lol loc sru stl $1==$4 && small($2) && $3==4 && inreg($1)==reg_any + call lolcshstl("lsr.l") +pat lol lol sri stl $1==$4 && inreg($1)==reg_any && $3==4 && inreg($2)==reg_any + call lolrshstl("asr.l") +pat lol lol sru stl $1==$4 && inreg($1)==reg_any && $3==4 && inreg($2)==reg_any + call lolrshstl("lsr.l") +pat lil loc sri sil $1==$4 && $2==1 && $3==4 && inreg($1)==reg_pointer + call lil1shrsil("asr #1,") +pat lil loc sru sil $1==$4 && $2==1 && $3==4 && inreg($1)==reg_pointer + call lil1shrsil("lsr #1,") +pat lol loc rol stl $1==$4 && small($2) && $3==4 && inreg($1)==reg_any + call lolcshstl("rol.l") +pat lol lol rol stl $1==$4 && inreg($2)==reg_any && $3==4 && inreg($1)==reg_any + call lolrshstl("rol.l") +pat lol loc ror stl $1==$4 && small($2) && $3==4 && inreg($1)==reg_any + call lolcshstl("ror.l") +pat lol lol ror stl $1==$4 && inreg($2)==reg_any && $3==4 && inreg($1)==reg_any + call lolrshstl("ror.l") + +#ifdef m68020 +pat lol loc dvi stl $1==$4 && $3==4 && inreg($1)==reg_any + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen divs_l {const, $2}, {LOCAL, $1} + +pat lol loc dvu stl $1==$4 && $3==4 && inreg($1)==reg_any + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen divu_l {const, $2}, {LOCAL, $1} + +pat lol loc mli stl $1==$4 && $3==4 && inreg($1)==reg_any + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen muls_l {const, $2}, {LOCAL, $1} + +pat lol loc mlu stl $1==$4 && $3==4 && inreg($1)==reg_any + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen mulu_l {const, $2}, {LOCAL, $1} + +pat lol mli stl $1==$3 && $2==4 && inreg($1)==reg_any + with data4 + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen muls_l %1, {LOCAL, $1} + +pat lol mlu stl $1==$3 && $2==4 && inreg($1)==reg_any + with data4 + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen mulu_l %1, {LOCAL, $1} +#endif m68020 + + +pat lil inc sil $1==$3 && inreg($1)==reg_pointer + kills allexceptcon + gen add_l {const, 1}, {indirect4, regvar($1, reg_pointer)} + +pat lil dec sil $1==$3 && inreg($1)==reg_pointer + kills allexceptcon + gen sub_l {const, 1}, {indirect4, regvar($1, reg_pointer)} + +pat inl inreg($1)==reg_any + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen add_l {const, 1}, {LOCAL, $1} + +pat del inreg($1)==reg_any + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen sub_l {const, 1}, {LOCAL, $1} + +pat zrl inreg($1)==reg_any + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen clr_l {LOCAL, $1} + +pat zrl inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + gen move_l {const, 0}, {LOCAL, $1} + + +proc lolxxstl example lol and stl +with data4 + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen xxx* %1, {LOCAL, $1} + +proc lilxxsil example lil and sil +with conreg4 + kills allexceptcon + gen xxx* %1, {indirect4, regvar($1, reg_pointer)} + +proc lolcxxstl example lol loc and stl + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen xxx* {const, $2}, {LOCAL, $1} + +proc lilcxxsil example lil loc and sil + kills allexceptcon + gen xxx* {const, $2}, {indirect4, regvar($1, reg_pointer)} + +proc lolrxxstl example lol lol and stl + kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) + gen xxx* {LOCAL, $2}, {LOCAL, $1} + +proc lilrxxsil example lil lol and sil + kills allexceptcon + gen xxx* {LOCAL, $2}, {indirect4, regvar($1, reg_pointer)} + +pat lol adi stl $1==$3 && $2==4 && inreg($1)==reg_any + call lolxxstl("add.l") +pat lol loc adi stl $1==$4 && $3==4 && inreg($1)==reg_any + call lolcxxstl("add.l") +pat lil adi sil $1==$3 && $2==4 &&inreg($1)==reg_pointer + call lilxxsil("add.l") +pat lil loc adi sil $1==$4 && $3==4 && inreg($1)==reg_pointer + call lilcxxsil("add.l") +pat lol lol adi stl $1==$4 && $3==4 && inreg($1)==reg_any && inreg($2)==reg_any + call lolrxxstl("add.l") +pat lil lol adi sil $1==$4 && $3==4 && inreg($1)==reg_pointer && + inreg($2)==reg_any + call lilrxxsil("add.l") +pat lol adu stl $1==$3 && $2==4 && inreg($1)==reg_any + call lolxxstl("add.l") +pat lol loc adu stl $1==$4 && $3==4 && inreg($1)==reg_any + call lolcxxstl("add.l") +pat lil adu sil $1==$3 && $2==4 &&inreg($1)==reg_pointer + call lilxxsil("add.l") +pat lil loc adu sil $1==$4 && $3==4 && inreg($1)==reg_pointer + call lilcxxsil("add.l") +pat lol lol adu stl $1==$4 && $3==4 && inreg($1)==reg_any && inreg($2)==reg_any + call lolrxxstl("add.l") +pat lil lol adu sil $1==$4 && $3==4 && inreg($1)==reg_pointer && + inreg($2)==reg_any + call lilrxxsil("add.l") +pat lol loc sbi stl $1==$4 && $3==4 && inreg($1)==reg_any + call lolcxxstl("sub.l") +pat lil loc sbi sil $1==$4 && $3==4 && inreg($1)==reg_pointer + call lilcxxsil("sub.l") +pat lol lol sbi stl $1==$4 && $3==4 && inreg($1)==reg_any && inreg($2)==reg_any + call lolrxxstl("sub.l") +pat lil lol sbi sil $1==$4 && $3==4 && inreg($1)==reg_pointer && + inreg($2)==reg_any + call lilrxxsil("sub.l") +pat lol loc sbu stl $1==$4 && $3==4 && inreg($1)==reg_any + call lolcxxstl("sub.l") +pat lil loc sbu sil $1==$4 && $3==4 && inreg($1)==reg_pointer + call lilcxxsil("sub.l") +pat lol lol sbu stl $1==$4 && $3==4 && inreg($1)==reg_any && inreg($2)==reg_any + call lolrxxstl("sub.l") +pat lil lol sbu sil $1==$4 && $3==4 && inreg($1)==reg_pointer && + inreg($2)==reg_any + call lilrxxsil("sub.l") +pat lol and stl $1==$3 && $2==4 && inreg($1)==reg_any + call lolxxstl("and.l") +pat lol loc and stl $1==$4 && $3==4 && inreg($1)==reg_any + call lolcxxstl("and.l") +pat lil and sil $1==$3 && $2==4 &&inreg($1)==reg_pointer + call lilxxsil("and.l") +pat lil loc and sil $1==$4 && $3==4 && inreg($1)==reg_pointer + call lilcxxsil("and.l") +pat lol lol and stl $1==$4 && $3==4 && inreg($1)==reg_any && inreg($2)==reg_any + call lolrxxstl("and.l") +pat lil lol and sil $1==$4 && $3==4 && inreg($1)==reg_pointer && + inreg($2)==reg_any + call lilrxxsil("and.l") +pat lol ior stl $1==$3 && $2==4 && inreg($1)==reg_any + call lolxxstl("or.l") +pat lol loc ior stl $1==$4 && $3==4 && inreg($1)==reg_any + call lolcxxstl("or.l") +pat lil ior sil $1==$3 && $2==4 && inreg($1)==reg_pointer + call lilxxsil("or.l") +pat lil loc ior sil $1==$4 && $3==4 && inreg($1)==reg_pointer + call lilcxxsil("or.l") +pat lol lol ior stl $1==$4 && $3==4 && inreg($1)==reg_any && + inreg($2)==reg_any + call lolrxxstl("or.l") +pat lil lol ior sil $1==$4 && $3==4 && inreg($1)==reg_pointer && + inreg($2)==reg_any + call lilrxxsil("or.l") +pat lol xor stl $1==$3 && $2==4 && inreg($1)==reg_any + call lolxxstl("eor.l") +pat lol loc xor stl $1==$4 && $3==4 && inreg($1)==reg_any + call lolcxxstl("eor.l") +pat lil xor sil $1==$3 && $2==4 &&inreg($1)==reg_pointer + call lilxxsil("eor.l") +pat lil loc xor sil $1==$4 && $3==4 && inreg($1)==reg_pointer + call lilcxxsil("eor.l") +pat lol lol xor stl $1==$4 && $3==4 && inreg($1)==reg_any && + inreg($2)==reg_any + call lolrxxstl("eor.l") +pat lil lol xor sil $1==$4 && $3==4 && inreg($1)==reg_pointer && + inreg($2)==reg_any + call lilrxxsil("eor.l") + +pat lil adp sil $1==$3 && inreg($1)==reg_pointer + kills allexceptcon + gen add_l {const, $2}, {indirect4, regvar($1, reg_pointer)} + +pat lil lil adp sil $1==$2 && $1==$4 && inreg($1)==reg_pointer + kills allexceptcon + uses AA_REG = {indirect4, regvar($1, reg_pointer)} + gen add_l {const, $3}, {indirect4, regvar($1, reg_pointer)} + yields %a + +pat lol lol adp stl loi $1==$2 && $1==$4 && $3==1 && $5==1 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {post_inc1, regvar($1, reg_pointer)} + +pat lol loi lol adp stl $1==$3 && $1==$5 && $2==1 && $4==1 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {post_inc1, regvar($1, reg_pointer)} + +pat lol lol adp stl loi $1==$2 && $1==$4 && $3==2 && $5==2 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {post_inc2, regvar($1, reg_pointer)} + +pat lol loi lol adp stl $1==$3 && $1==$5 && $2==2 && $4==2 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {post_inc2, regvar($1, reg_pointer)} + +pat lol lol adp stl loi $1==$2 && $1==$4 && $3==4 && $5==4 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {post_inc4, regvar($1, reg_pointer)} + +pat lil lol adp stl $1==$2 && $1==$4 && $3==4 && inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {post_inc4, regvar($1, reg_pointer)} + +pat lol lol adp stl sti $1==$2 && $1==$4 && $3==1 && $5==1 && + inreg($1)==reg_pointer +with data1 + kills allexceptcon + gen move %1, {post_inc1, regvar($1, reg_pointer)} + +pat lol sti lol adp stl $1==$3 && $1==$5 && $2==1 && $4==1 && + inreg($1)==reg_pointer +with data1 + kills allexceptcon + gen move %1, {post_inc1, regvar($1, reg_pointer)} + +pat lol lol adp stl sti $1==$2 && $1==$4 && $3==2 && $5==2 && + inreg($1)==reg_pointer +with any2 + kills allexceptcon + gen move %1, {post_inc2, regvar($1, reg_pointer)} + +pat lol sti lol adp stl $1==$3 && $1==$5 && $2==2 && $4==2 && + inreg($1)==reg_pointer +with any2 + kills allexceptcon + gen move %1, {post_inc2, regvar($1, reg_pointer)} + +pat lol lol adp stl sti $1==$2 && $1==$4 && $3==4 && $5==4 && + inreg($1)==reg_pointer +with any4 + kills allexceptcon + gen move_l %1, {post_inc4, regvar($1, reg_pointer)} + +pat sil lol adp stl $1==$2 && $1==$4 && $3==4 && inreg($1)==reg_pointer +with any4 + kills allexceptcon + gen move_l %1, {post_inc4, regvar($1, reg_pointer)} + +pat lol adp stl lol loi $1==$3 && $1==$4 && $2==0-1 && $5==1 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {pre_dec1, regvar($1, reg_pointer)} + +pat lol adp stl lol loi $1==$3 && $1==$4 && $2==0-2 && $5==2 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {pre_dec2, regvar($1, reg_pointer)} + +pat lol adp stl lil $1==$3 && $1==$4 && $2==0-4 && + inreg($1)==reg_pointer + kills LOCAL %bd==$1, all_regind %reg==regvar($1, reg_pointer) + yields {pre_dec4, regvar($1, reg_pointer)} + +pat lol adp stl lol sti $1==$3 && $1==$4 && $2==0-1 && $5==1 && + inreg($1)==reg_pointer +with data1 + kills allexceptcon + gen move %1, {pre_dec1, regvar($1, reg_pointer)} + +pat lol adp stl lol sti $1==$3 && $1==$4 && $2==0-2 && $5==2 && + inreg($1)==reg_pointer +with any2 + kills allexceptcon + gen move %1, {pre_dec2, regvar($1, reg_pointer)} + +pat lol adp stl sil $1==$3 && $1==$4 && $2==0-4 && + inreg($1)==reg_pointer +with any4 + kills allexceptcon + gen move_l %1, {pre_dec4, regvar($1, reg_pointer)} + + + + +/************************************************ + * Group 1: load instructions * + ************************************************/ + +pat loc yields {const, $1} + +pat ldc leaving loc 18 trp + +pat lol yields {LOCAL, $1} + +pat ldl leaving lol $1+4 lol $1 + +pat loe yields {absolute4, $1} + +pat lil +#ifdef m68020 + yields {ILOCAL, $1} +#else m68020 + uses AA_REG = {LOCAL, $1} + yields {indirect4, %a} +#endif m68020 + + /* When using the 'offsetted' intructions regAregXcon cannot be used + * for the m68k4; there is no way of knowing about the size of + * %1.bd+$1, because expressions are not allowed in stack patterns, and + * this may lead to outputting too large displacements. With regAcon + * the chance that this will happen is very slim, because it can + * have displacements of 16 bits. Besides, leaving out regAcon here + * would make it very hard to handle this instruction efficiently. + */ +pat lof +with A_REG yields {offsetted4, %1, $1} +with exact local_addr yields {LOCAL, %1.bd+$1} +with exact ext_addr yields {absolute4, %1.bd+$1} +#ifndef m68020 +with regAcon yields {offsetted4, %1.reg, %1.bd+$1} +#else m68020 +with exact regAcon yields {offsetted4, %1.reg, %1.bd+$1} +with exact regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1} +with exact offsetted4 yields {OFF_off4, %1.reg, %1.bd, $1} +with exact indirect yields {OFF_off4, %1.reg, 0, $1} +with exact LOCAL yields {OFF_off4, lb, %1.bd, $1} +with exact off_con yields {OFF_off4, %1.reg, %1.bd, %1.od+$1} +with exact off_regXcon yields {OFF_indoff4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact index_off4 yields {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, $1} +with exact indoff_con yields {INDOFF_off4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact absolute4 yields {ABS_off4, %1.bd, $1} +with exact abs_con yields {ABS_off4, %1.bd, %1.od+$1} +with exact abs_regXcon yields {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact abs_index4 yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, $1} +with exact absind_con yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact ext_regX yields {abs_index4, %1.sc, %1.xreg, %1.bd+$1} +#endif m68020 + +pat lal yields {local_addr, $1} + +pat lae yields {ext_addr, $1} + +pat lxl $1==0 yields lb + +pat lxl $1==1 yields {LOCAL, SL} + +pat lxl $1==2 +#ifdef m68020 + yields {OFF_off4, lb, SL, SL} +#else m68020 + uses AA_REG = {LOCAL, SL} + yields {offsetted4, %a, SL} +#endif m68020 + +pat lxl $1==3 +#ifdef m68020 + uses AA_REG = {OFF_off4, lb, SL, SL} +#else m68020 + uses AA_REG = {LOCAL, SL} + gen move {offsetted4, %a, SL}, %a +#endif m68020 + yields {offsetted4, %a, SL} + +pat lxl $1>3 + uses AA_REG = {LOCAL, SL}, + DD_REG = {const, $1-2} + gen 1: + move_l {offsetted4, %a, SL} ,%a + dbf %b, {slabel, 1b} + yields %a + +pat lxa $1==0 yields {local_addr, SL} + +pat lxa $1==1 +#ifdef m68020 + yields {off_con, lb, SL, SL} +#else m68020 + uses AA_REG = {LOCAL, SL} + yields {regAcon, %a, SL} +#endif m68020 + +pat lxa $1==2 +#ifdef m68020 + uses AA_REG = {OFF_off4, lb, SL, SL} +#else m68020 + uses AA_REG = {LOCAL, SL} + gen move {offsetted4, %a, SL}, %a +#endif m68020 + yields {regAcon, %a, SL} + +pat lxa $1>2 + uses AA_REG = {LOCAL, SL}, + DD_REG = {const, $1-1} + gen 1: + move_l {offsetted4, %a, SL} ,%a + dbf %b, {slabel, 1b} + yields {regAcon, %a, SL} + +pat loi $1==1 +with A_REG yields {indirect1, %1} +with exact local_addr yields {offsetted1, lb, %1.bd} +with exact ext_addr yields {absolute1, %1.bd} +#ifndef m68020 +with regAcon yields {offsetted1, %1.reg, %1.bd} +with regAregXcon yields {index_off1, %1.reg, %1.xreg, %1.sc, %1.bd} +#else m68020 +with exact regAcon yields {offsetted1, %1.reg, %1.bd} +with exact regAregXcon yields {index_off1, %1.reg, %1.xreg, %1.sc, %1.bd} +with exact indirect4 yields {OFF_off1, %1.reg, 0, 0} +with exact offsetted4 yields {OFF_off1, %1.reg, %1.bd, 0} +with exact LOCAL yields {OFF_off1, lb, %1.bd, 0} +with exact off_con yields {OFF_off1, %1.reg, %1.bd, %1.od} +with exact off_regXcon yields {OFF_indoff1, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact index_off4 yields {INDOFF_off1, %1.reg, %1.xreg, %1.sc, %1.bd, 0} +with exact indoff_con yields {INDOFF_off1, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact absolute4 yields {ABS_off1, %1.bd, 0} +with exact abs_con yields {ABS_off1, %1.bd, %1.od} +with exact abs_regXcon yields {ABS_indoff1, %1.sc, %1.xreg, %1.bd, %1.od} +with exact abs_index4 yields {ABSIND_off1, %1.sc, %1.xreg, %1.bd, 0} +with exact absind_con yields {ABSIND_off1, %1.sc, %1.xreg, %1.bd, %1.od} +with exact ext_regX yields {abs_index1, %1.sc, %1.xreg, %1.bd} +#endif m68020 + +pat loi $1==2 +with A_REG yields {indirect2, %1} +with exact local_addr yields {offsetted2, lb, %1.bd} +with exact ext_addr yields {absolute2, %1.bd} +#ifndef m68020 +with regAcon yields {offsetted2, %1.reg, %1.bd} +with regAregXcon yields {index_off2, %1.reg, %1.xreg, %1.sc, %1.bd} +#else m68020 +with exact regAcon yields {offsetted2, %1.reg, %1.bd} +with exact regAregXcon yields {index_off2, %1.reg, %1.xreg, %1.sc, %1.bd} +with exact indirect4 yields {OFF_off2, %1.reg, 0, 0} +with exact offsetted4 yields {OFF_off2, %1.reg, %1.bd, 0} +with exact LOCAL yields {OFF_off2, lb, %1.bd, 0} +with exact off_con yields {OFF_off2, %1.reg, %1.bd, %1.od} +with exact off_regXcon yields {OFF_indoff2, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact index_off4 yields {INDOFF_off2, %1.reg, %1.xreg, %1.sc, %1.bd, 0} +with exact indoff_con yields {INDOFF_off2, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact absolute4 yields {ABS_off2, %1.bd, 0} +with exact abs_con yields {ABS_off2, %1.bd, %1.od} +with exact abs_regXcon yields {ABS_indoff2, %1.sc, %1.xreg, %1.bd, %1.od} +with exact abs_index4 yields {ABSIND_off2, %1.sc, %1.xreg, %1.bd, 0} +with exact absind_con yields {ABSIND_off2, %1.sc, %1.xreg, %1.bd, %1.od} +with exact ext_regX yields {abs_index2, %1.sc, %1.xreg, %1.bd} +#endif m68020 + +pat loi $1==4 +with A_REG yields {indirect4, %1} +with exact local_addr yields {LOCAL, %1.bd} +with exact ext_addr yields {absolute4, %1.bd} +#ifndef m68020 +with regAcon yields {offsetted4, %1.reg, %1.bd} +with regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd} +#else m68020 +with exact regAcon yields {offsetted4, %1.reg, %1.bd} +with exact regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd} +with exact LOCAL yields {ILOCAL, %1.bd} +with exact indirect4 yields {OFF_off4, %1.reg, 0, 0} +with exact offsetted4 yields {OFF_off4, %1.reg, %1.bd, 0} +with exact off_con yields {OFF_off4, %1.reg, %1.bd, %1.od} +with exact off_regXcon yields {OFF_indoff4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact index_off4 yields {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, 0} +with exact indoff_con yields {INDOFF_off4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact absolute4 yields {ABS_off4, %1.bd, 0} +with exact abs_con yields {ABS_off4, %1.bd, %1.od} +with exact abs_regXcon yields {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od} +with exact abs_index4 yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, 0} +with exact absind_con yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od} +with exact ext_regX yields {abs_index4, %1.sc, %1.xreg, %1.bd} +#endif m68020 + +pat loi $1==8 +with A_REG yields {offsetted4, %1, 4} + {indirect4, %1} +pat loi $1>8 +with AA_REG STACK + uses DD_REG = {const, $1/4 -1} + gen add_l {const, $1}, %1 + 1: + move_l {pre_dec4, %1}, {pre_dec4, sp} + dbf %a, {slabel, 1b} + +pat los $1==4 +with STACK + gen jsr {absolute4, ".los"} + +pat lde yields {absolute4, $1+4} + {absolute4, $1} + +pat ldf +with A_REG yields {offsetted4, %1, $1+4} + {offsetted4, %1, $1} +with exact local_addr yields {LOCAL, %1.bd+$1+4} + {LOCAL, %1.bd+$1} +with exact ext_addr yields {absolute4, %1.bd+$1+4} + {absolute4, %1.bd+$1} +#ifndef m68020 +with regAcon yields {offsetted4, %1.reg, %1.bd+$1+4} + {offsetted4, %1.reg, %1.bd+$1} +#else m68020 +with exact regAcon yields {offsetted4, %1.reg, %1.bd+$1+4} + {offsetted4, %1.reg, %1.bd+$1} +with exact regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1+4} + {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1} +with exact indirect4 yields {OFF_off4, %1.reg, 0, $1+4} + {OFF_off4, %1.reg, 0, $1} +with exact offsetted4 yields {OFF_off4, %1.reg, %1.bd, $1+4} + {OFF_off4, %1.reg, %1.bd, $1} +with exact LOCAL yields {OFF_off4, lb, %1.bd, $1+4} + {OFF_off4, lb, %1.bd, $1} +with exact off_con yields {OFF_off4, %1.reg, %1.bd, %1.od+$1+4} + {OFF_off4, %1.reg, %1.bd, %1.od+$1} +with exact off_regXcon yields {OFF_indoff4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1+4} + {OFF_indoff4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact index_off4 yields {INDOFF_off4, %1.reg, %1.xreg, %1.sc,%1.bd,$1+4} + {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, $1} +with exact indoff_con yields {INDOFF_off4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1+4} + {INDOFF_off4, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact absolute4 yields {ABS_off4, %1.bd, $1+4} + {ABS_off4, %1.bd, $1} +with exact abs_con yields {ABS_off4, %1.bd, %1.od+$1+4} + {ABS_off4, %1.bd, %1.od+$1} +with exact abs_regXcon yields {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od+$1+4} + {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact abs_index4 yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, $1+4} + {ABSIND_off4, %1.sc, %1.xreg, %1.bd, $1} +with exact absind_con yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1+4} + {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact ext_regX yields {abs_index4, %1.sc, %1.xreg, %1.bd+$1+4} + {abs_index4, %1.sc, %1.xreg, %1.bd+$1} +#endif m68020 + +pat lpi yields {ext_addr, $1} + + + +/************************************************ + * Group 2: store instructions * + ************************************************/ + +pat stl +with any4 + kills all_indir, LOCAL %bd==$1 + gen move %1, {LOCAL, $1} +with exact STACK + gen move {post_inc4,sp}, {LOCAL, $1} + +pat ste +with any4 + kills posextern + gen move %1, {absolute4, $1} +with exact STACK + gen move {post_inc4, sp}, {absolute4, $1} + +pat sil +#ifdef m68020 +with any4 + kills allexceptcon + gen move %1, {ILOCAL, $1} +with exact STACK + gen move {post_inc4, sp}, {ILOCAL, $1} +#else m68020 +with any4 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen move %1, {indirect4, %a} +with exact STACK + uses AA_REG = {LOCAL, $1} + gen move {post_inc4, sp}, {indirect4, %a} +#endif m68020 + +pat stf +with A_REG any4 + kills allexceptcon + gen move %2, {offsetted4, %1, $1} +with A_REG STACK + gen move {post_inc4, sp}, {offsetted4, %1, $1} +with exact local_addr any4 + kills allexceptcon + gen move %2, {LOCAL, %1.bd+$1} +with exact ext_addr any4 + kills allexceptcon + gen move %2, {absolute4, %1.bd+$1} +#ifndef m68020 +with regAcon any4 + kills allexceptcon + gen move %2, {offsetted4, %1.reg, %1.bd+$1} +#else m68020 +with exact regAcon any4 + kills allexceptcon + gen move %2, {offsetted4, %1.reg, %1.bd+$1} +with exact regAregXcon any4 + kills allexceptcon + gen move %2, {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1} +with exact indirect4 any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, 0, $1} +with exact offsetted4 any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, %1.bd, $1} +with exact LOCAL any4 + kills allexceptcon + gen move %2, {OFF_off4, lb, %1.bd, $1} +with exact off_con any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, %1.bd, %1.od+$1} +with exact off_regXcon any4 + kills allexceptcon + gen move %2, {OFF_indoff4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact index_off4 any4 + kills allexceptcon + gen move %2, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, $1} +with exact indoff_con any4 + kills allexceptcon + gen move %2, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact absolute4 any4 + kills allexceptcon + gen move %2, {ABS_off4, %1.bd, $1} +with exact abs_con any4 + kills allexceptcon + gen move %2, {ABS_off4, %1.bd, %1.od+$1} +with exact abs_regXcon any4 + kills allexceptcon + gen move %2, {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact abs_index4 any4 + kills allexceptcon + gen move %2, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, $1} +with exact absind_con any4 + kills allexceptcon + gen move %2, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact ext_regX any4 + kills allexceptcon + gen move %2, {abs_index4, %1.sc, %1.xreg, %1.bd+$1} +#endif m68020 + +pat sti $1==1 +with A_REG data1 + kills allexceptcon + gen move %2, {indirect1, %1} +with exact local_addr data1 + kills allexceptcon + gen move %2, {offsetted1, lb, %1.bd} +with exact ext_addr data1 + kills allexceptcon + gen move %2, {absolute1, %1.bd} +#ifndef m68020 +with regAcon data1 + kills allexceptcon + gen move %2, {offsetted1, %1.reg, %1.bd} +with regAregXcon data1 + kills allexceptcon + gen move %2, {index_off1, %1.reg, %1.xreg, %1.sc, %1.bd} +#else m68020 +with exact regAcon data1 + kills allexceptcon + gen move %2, {offsetted1, %1.reg, %1.bd} +with exact regAregXcon data1 + kills allexceptcon + gen move %2, {index_off1, %1.reg, %1.xreg, %1.sc, %1.bd} +with exact indirect4 data1 + kills allexceptcon + gen move %2, {OFF_off1, %1.reg, 0, 0} +with exact offsetted4 data1 + kills allexceptcon + gen move %2, {OFF_off1, %1.reg, %1.bd, 0} +with exact LOCAL data1 + kills allexceptcon + gen move %2, {OFF_off1, lb, %1.bd, 0} +with exact off_con data1 + kills allexceptcon + gen move %2, {OFF_off1, %1.reg, %1.bd, %1.od} +with exact off_regXcon data1 + kills allexceptcon + gen move %2, {OFF_indoff1, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact index_off4 data1 + kills allexceptcon + gen move %2, {INDOFF_off1, %1.reg, %1.xreg, %1.sc, %1.bd, 0} +with exact indoff_con data1 + kills allexceptcon + gen move %2, {INDOFF_off1, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact absolute4 data1 + kills allexceptcon + gen move %2, {ABS_off1, %1.bd, 0} +with exact abs_con data1 + kills allexceptcon + gen move %2, {ABS_off1, %1.bd, %1.od} +with exact abs_regXcon data1 + kills allexceptcon + gen move %2, {ABS_indoff1, %1.sc, %1.xreg, %1.bd, %1.od} +with exact abs_index4 data1 + kills allexceptcon + gen move %2, {ABSIND_off1, %1.sc, %1.xreg, %1.bd, 0} +with exact absind_con data1 + kills allexceptcon + gen move %2, {ABSIND_off1, %1.sc, %1.xreg, %1.bd, %1.od} +with exact ext_regX data1 + kills allexceptcon + gen move %2, {abs_index1, %1.sc, %1.xreg, %1.bd} +#endif m68020 + +pat sti $1==2 +with A_REG any2 + kills allexceptcon + gen move %2, {indirect2, %1} +with exact local_addr any2 + kills allexceptcon + gen move %2, {offsetted2, lb, %1.bd} +with exact ext_addr any2 + kills allexceptcon + gen move %2, {absolute2, %1.bd} +#ifndef m68020 +with regAcon any2 + kills allexceptcon + gen move %2, {offsetted2, %1.reg, %1.bd} +with regAregXcon any2 + kills allexceptcon + gen move %2, {index_off2, %1.reg, %1.xreg, %1.sc, %1.bd} +#else m68020 +with exact regAcon any2 + kills allexceptcon + gen move %2, {offsetted2, %1.reg, %1.bd} +with exact regAregXcon any2 + kills allexceptcon + gen move %2, {index_off2, %1.reg, %1.xreg, %1.sc, %1.bd} +with exact indirect4 any2 + kills allexceptcon + gen move %2, {OFF_off2, %1.reg, 0, 0} +with exact offsetted4 any2 + kills allexceptcon + gen move %2, {OFF_off2, %1.reg, %1.bd, 0} +with exact LOCAL any2 + kills allexceptcon + gen move %2, {OFF_off2, lb, %1.bd, 0} +with exact off_con any2 + kills allexceptcon + gen move %2, {OFF_off2, %1.reg, %1.bd, %1.od} +with exact index_off4 any2 + kills allexceptcon + gen move %2, {INDOFF_off2, %1.reg, %1.xreg, %1.sc, %1.bd, 0} +with exact off_regXcon any2 + kills allexceptcon + gen move %2, {OFF_indoff2, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact indoff_con any2 + kills allexceptcon + gen move %2, {INDOFF_off2, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact absolute4 any2 + kills allexceptcon + gen move %2, {ABS_off2, %1.bd, 0} +with exact abs_con any2 + kills allexceptcon + gen move %2, {ABS_off2, %1.bd, %1.od} +with exact abs_regXcon any2 + kills allexceptcon + gen move %2, {ABS_indoff2, %1.sc, %1.xreg, %1.bd, %1.od} +with exact abs_index4 any2 + kills allexceptcon + gen move %2, {ABSIND_off2, %1.sc, %1.xreg, %1.bd, 0} +with exact absind_con any2 + kills allexceptcon + gen move %2, {ABSIND_off2, %1.sc, %1.xreg, %1.bd, %1.od} +with exact ext_regX any2 + kills allexceptcon + gen move %2, {abs_index2, %1.sc, %1.xreg, %1.bd} +#endif m68020 + +pat sti $1==4 +with A_REG any4 + kills allexceptcon + gen move %2, {indirect4, %1} +with A_REG STACK + gen move {post_inc4, sp}, {indirect4, %1} +with exact local_addr any4 + kills allexceptcon + gen move %2, {LOCAL, %1.bd} +with exact ext_addr any4 + kills allexceptcon + gen move %2, {absolute4, %1.bd} +#ifndef m68020 +with regAcon any4 + kills allexceptcon + gen move %2, {offsetted4, %1.reg, %1.bd} +with regAregXcon any4 + kills allexceptcon + gen move %2, {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd} +#else m68020 +with exact regAcon any4 + kills allexceptcon + gen move %2, {offsetted4, %1.reg, %1.bd} +with exact regAregXcon any4 + kills allexceptcon + gen move %2, {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd} +with exact LOCAL any4 + kills allexceptcon + gen move %2, {ILOCAL, %1.bd} +with exact indirect4 any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, 0, 0} +with exact offsetted4 any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, %1.bd, 0} +with exact off_con any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, %1.bd, %1.od} +with exact off_regXcon any4 + kills allexceptcon + gen move %2, {OFF_indoff4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact index_off4 any4 + kills allexceptcon + gen move %2, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, 0} +with exact indoff_con any4 + kills allexceptcon + gen move %2, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od} +with exact absolute4 any4 + kills allexceptcon + gen move %2, {ABS_off4, %1.bd, 0} +with exact abs_con any4 + kills allexceptcon + gen move %2, {ABS_off4, %1.bd, %1.od} +with exact abs_regXcon any4 + kills allexceptcon + gen move %2, {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od} +with exact abs_index4 any4 + kills allexceptcon + gen move %2, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, 0} +with exact absind_con any4 + kills allexceptcon + gen move %2, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od} +with exact ext_regX any4 + kills allexceptcon + gen move %2, {abs_index4, %1.sc, %1.xreg, %1.bd} +#endif m68020 + +pat sti $1>4 +with AA_REG STACK + uses DD_REG = {const, $1/4 -1} + gen 1: + move_l {post_inc4, sp}, {post_inc4, %1} + dbf %a, {slabel, 1b} + +pat sts $1==4 +with STACK + gen jsr {absolute4, ".sts"} + +pat sdl +with any4 any4 + kills all_indir, LOCAL %bd==$1 + gen move %1, {LOCAL, $1} + move %2, {LOCAL, $1+4} + +pat sde +with any4 any4 + kills posextern + gen move %1, {absolute4, $1} + move %2, {absolute4, $1+4} + +pat sdf +with A_REG any4 any4 + kills allexceptcon + gen move %2, {offsetted4, %1, $1} + move %3, {offsetted4, %1, $1+4} +with exact local_addr any4 any4 + kills allexceptcon + gen move %2, {LOCAL, %1.bd+$1} + move %3, {LOCAL, %1.bd+$1+4} +with exact ext_addr any4 any4 + kills allexceptcon + gen move %2, {absolute4, %1.bd+$1} + move %3, {absolute4, %1.bd+$1+4} +#ifndef m68020 +with regAcon any4 any4 + kills allexceptcon + gen move %2, {offsetted4, %1.reg, %1.bd+$1} + move %3, {offsetted4, %1.reg, %1.bd+$1+4} +#else m68020 +with exact regAcon any4 any4 + kills allexceptcon + gen move %2, {offsetted4, %1.reg, %1.bd+$1} + move %3, {offsetted4, %1.reg, %1.bd+$1+4} +with exact regAregXcon any4 any4 + kills allexceptcon + gen move %2, {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1} + move %3, {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1+4} +with exact indirect4 any4 any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, 0, $1} + move %3, {OFF_off4, %1.reg, 0, $1+4} +with exact offsetted4 any4 any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, %1.bd, $1} + move %3, {OFF_off4, %1.reg, %1.bd, $1+4} +with exact LOCAL any4 any4 + kills allexceptcon + gen move %2, {OFF_off4, lb, %1.bd, $1} + move %3, {OFF_off4, lb, %1.bd, $1+4} +with exact off_con any4 any4 + kills allexceptcon + gen move %2, {OFF_off4, %1.reg, %1.bd, %1.od+$1} + move %3, {OFF_off4, %1.reg, %1.bd, %1.od+$1+4} +with exact off_regXcon any4 any4 + kills allexceptcon + gen move %2, {OFF_indoff4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} + move %3, {OFF_indoff4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1+4} +with exact index_off4 any4 any4 + kills allexceptcon + gen move %2, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, $1} + move %3, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, $1+4} +with exact indoff_con any4 any4 + kills allexceptcon + gen move %2, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} + move %3, {INDOFF_off4, %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1+4} +with exact absolute4 any4 any4 + kills allexceptcon + gen move %2, {ABS_off4, %1.bd, $1} + move %3, {ABS_off4, %1.bd, $1+4} +with exact abs_con any4 any4 + kills allexceptcon + gen move %2, {ABS_off4, %1.bd, %1.od+$1} + move %3, {ABS_off4, %1.bd, %1.od+$1+4} +with exact abs_regXcon any4 any4 + kills allexceptcon + gen move %2, {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od+$1} + move %3, {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od+$1+4} +with exact abs_index4 any4 any4 + kills allexceptcon + gen move %2, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, $1} + move %3, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, $1+4} +with exact absind_con any4 any4 + kills allexceptcon + gen move %2, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1} + move %3, {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1+4} +with exact ext_regX any4 any4 + kills allexceptcon + gen move %2, {abs_index4, %1.sc, %1.xreg, %1.bd+$1} + move %3, {abs_index4, %1.sc, %1.xreg, %1.bd+$1+4} +#endif m68020 + + + +/************************************************ + * Group 3: integer arithmetic. * + ************************************************/ + + +pat adi $1==4 +with any4 DD_REG + gen add_l %1, %2 yields %2 +with DD_REG any4-DD_REG + gen add_l %2, %1 yields %1 +with DD_REG STACK + gen add_l {post_inc4, sp}, %1 + yields %1 + +pat sbi $1==4 +with any4 DD_REG + gen sub_l %1, %2 yields %2 +with DD_REG any4-DD_REG + gen sub_l %2, %1 + neg_l %1 yields %1 +with DD_REG STACK + gen sub_l {post_inc4, sp}, %1 + neg_l %1 yields %1 +with any4 AA_REG + gen sub_l %1, %2 yields %2 + +pat mli $1==4 +#ifdef m68020 +with data4 DD_REG + gen muls_l %1, %2 yields %2 +#else m68020 +with STACK + gen jsr {absolute4, ".mli"} + yields d1 +#endif m68020 + +pat dvi $1==4 +#ifdef m68020 +with data4 DD_REG + gen divs_l %1, %2 yields %2 +#else m68020 +with STACK + gen jsr {absolute4, ".dvi"} + yields d1 +#endif m68020 + +pat rmi $1==4 +#ifdef m68020 +with data4 DD_REG + uses DD_REG + gen divsl_l %1, {DREG_pair, %a, %2} + killreg %2 + /* !!!! contents of %2 have changed: make this known to cg */ + yields %a +#else m68020 +with STACK + gen jsr {absolute4, ".dvi"} + yields d0 +#endif m68020 + +pat ngi $1==4 +with DD_REG + gen neg_l %1 yields %1 + +pat sli $1==4 +with D_REG DD_REG + gen asl_l %1, %2 yields %2 + +pat sri $1==4 +with D_REG DD_REG + gen asr_l %1, %2 yields %2 + + + +/************************************************ + * Group 4: unsigned arithmetic. * + ************************************************/ + + +pat adu leaving adi $1 + +pat sbu leaving sbi $1 + +pat mlu $1==4 +#ifdef m68020 +with data4 DD_REG + gen mulu_l %1, %2 yields %2 +#else m68020 +with STACK + gen jsr {absolute4, ".mlu"} + yields d1 +#endif m68020 + +pat dvu $1==4 +#ifdef m68020 +with data4 DD_REG + gen divu_l %1, %2 yields %2 +#else m68020 +with STACK + gen jsr {absolute4, ".dvu"} + yields d1 +#endif m68020 + +pat rmu $1==4 +#ifdef m68020 +with data4 DD_REG + uses DD_REG + gen divul_l %1, {DREG_pair, %a, %2} + killreg %2 + /* !!!! contents of %2 have changed: make this known to cg */ + yields %a +#else m68020 +with STACK + gen jsr {absolute4, ".dvu"} + yields d0 +#endif m68020 + +pat slu leaving sli $1 + +pat sru $1==4 +with D_REG DD_REG + gen lsr_l %1, %2 yields %2 + + + +/************************************************ + * Group 5: floating point arithmetic * + * * + * is not available on 68000, 68010 or 68020 * + * so traps will be generated * + ************************************************/ + +pat adf leaving loc 18 trp +pat sbf leaving loc 18 trp +pat mlf leaving loc 18 trp +pat dvf leaving loc 18 trp +pat ngf leaving loc 18 trp +pat fif leaving loc 18 trp +pat fef leaving loc 18 trp + + + +/************************************************ + * Group 6: pointer arithmetic * + ************************************************/ + +pat adp $1==0 /* skip; array instructions might 'leave' this */ + +pat adp +with A_REG yields {t_regAcon, %1, $1} +with exact local_addr yields {local_addr, %1.bd+$1} +with exact ext_addr yields {ext_addr, %1.bd+$1} +with exact regAcon + t_regAcon + yields {t_regAcon, %1.reg, %1.bd+$1} +with exact regAregXcon + t_regAregXcon + yields {t_regAregXcon,%1.reg, %1.xreg, %1.sc, %1.bd+$1} +#ifdef m68020 +with exact indirect4 yields {off_con, %1.reg, 0, $1} +with exact LOCAL yields {off_con, lb, %1.bd, $1} +with exact offsetted4 yields {off_con, %1.reg, %1.bd, $1} +with exact off_con yields {off_con, %1.reg, %1.bd, %1.od+$1} +with exact off_regXcon yields {off_regXcon, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact index_off4 yields {indoff_con, %1.reg, %1.xreg, %1.sc, %1.bd, $1} +with exact indoff_con yields {indoff_con, + %1.reg, %1.xreg, %1.sc, %1.bd, %1.od+$1} +with exact absolute4 yields {abs_con, %1.bd, $1} +with exact abs_con yields {abs_con, %1.bd, %1.od+$1} +with exact abs_regXcon yields {abs_regXcon, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact abs_index4 yields {absind_con, %1.sc, %1.xreg, %1.bd, $1} +with exact absind_con yields {absind_con, %1.sc, %1.xreg, %1.bd, %1.od+$1} +with exact ext_regX yields {ext_regX, %1.sc, %1.xreg, %1.bd+$1} +#endif m68020 + +pat ads $1==4 +with D_REG A_REG yields {regAregXcon, %2, %1, 1, 0} +with D_REG regAcon + t_regAcon + yields {t_regAregXcon, %2.reg, %1, 1, %2.bd} +with D_REG local_addr yields {t_regAregXcon, lb, %1, 1, %2.bd} +with any4-D_REG AA_REG + gen add_l %1, %2 yields %2 + +#ifdef m68020 + +with D_REG yields {regX, 1, %1} + leaving ads 4 +with regX A_REG yields {regAregXcon, %2, %1.xreg, %1.sc, 0} +with exact regX regAcon yields {regAregXcon, %2.reg, %1.xreg, %1.sc, %2.bd} +with exact regX local_addr + yields {regAregXcon, lb, %1.xreg, %1.sc, %2.bd} +with exact regX ext_addr + yields {ext_regX, %1.sc, %1.xreg, %2.bd} +with exact regX indirect4 + yields {off_regXcon, %2.reg, %1.xreg,%1.sc,0,0} +with exact regX offsetted4 + yields {off_regXcon, %2.reg, %1.xreg, %1.sc, %2.bd, 0} +with exact regX LOCAL yields {off_regXcon, lb, %1.xreg, %1.sc, %2.bd, 0} +with exact regX off_con yields {off_regXcon, %2.reg, %1.xreg,%1.sc,%2.bd,%2.od} +with exact regX absolute4 + yields {abs_regXcon, %1.sc, %1.xreg, %2.bd, 0} +with exact regX abs_con yields {abs_regXcon, %1.sc, %1.xreg, %2.bd, %2.od} +with exact indirect4 ext_addr + yields {off_con, %1.reg, 0, %2.bd} +with exact offsetted4 ext_addr + yields {off_con, %1.reg, %1.bd, %2.bd} +with exact LOCAL ext_addr + yields {off_con, lb, %1.bd, %2.bd} +with exact index_off4 ext_addr + yields {indoff_con, %1.reg, %1.xreg, %1.sc,%1.bd,%2.bd} +with exact absolute4 ext_addr + yields {abs_con, %1.bd, %2.bd} +with exact abs_index4 ext_addr + yields {absind_con, %1.sc, %1.xreg, %1.bd, %2.bd} +with exact indirect4 ext_regX + yields {off_regXcon, %1.reg, %2.xreg, %2.sc, 0, %2.bd} +with exact offsetted4 ext_regX + yields {off_regXcon, %1.reg, %2.xreg,%2.sc,%1.bd,%2.bd} +with exact LOCAL ext_regX + yields {off_regXcon, lb, %2.xreg, %2.sc, %1.bd, %2.bd} +with exact absolute4 ext_regX + yields {abs_regXcon, %2.sc, %2.xreg, %1.bd, %2.bd} +#endif m68020 + + /* I WOULD ALSO LIKE THIS: + * pat ads + * with const leaving adp %1.num + * BUT THAT DOESN'T WORK. + */ + +pat sbs $1==4 leaving sbi 4 + +#ifdef m68020 +pat loc sli ads $1==1 && $2==4 && $3==4 +with D_REG yields {regX, 2, %1} + leaving ads 4 + +pat loc sli ads $1==2 && $2==4 && $3==4 +with D_REG yields {regX, 4, %1} + leaving ads 4 + +pat loc sli ads $1==3 && $2==4 && $3==4 +with D_REG yields {regX, 8, %1} + leaving ads 4 +#endif m68020 + + +/************************************************ + * Group 7: increment / decrement / zero * + ************************************************/ + +pat inc +with exact STACK + gen add_l {const, 1}, {indirect4, sp} +with DD_REG+AA_REG + gen add_l {const, 1}, %1 + yields %1 + +pat inl + kills all_indir, LOCAL %bd==$1 + gen add_l {const, 1}, {LOCAL, $1} + +pat ine + kills posextern + gen add_l {const, 1}, {absolute4, $1} + +pat dec +with exact STACK + gen sub_l {const, 1}, {indirect4, sp} +with DD_REG+AA_REG + gen sub_l {const, 1}, %1 + yields %1 + +pat del + kills all_indir, LOCAL %bd==$1 + gen sub_l {const, 1}, {LOCAL, $1} + +pat dee + kills posextern + gen sub_l {const, 1}, {absolute4, $1} + +pat zrl + kills all_indir, LOCAL %bd==$1 + gen clr_l {LOCAL, $1} + +pat zre + kills posextern + gen clr_l {absolute4, $1} + +pat zer $1==4 yields {const, 0} +pat zer $1==8 yields {const, 0} {const, 0} +pat zer $1==12 yields {const, 0} {const, 0} {const, 0} + +pat zer +with STACK + uses DD_REG = {const, $1/4 -1} + gen 1: + clr_l {pre_dec4, sp} + dbf %a, {slabel, 1b} + + +pat zrf leaving loc 18 trp + + + +/************************************************ + * Group 8: convert instructions * + * for float conversions traps are generated * + ************************************************/ + + + +pat cii +with STACK + gen jsr {absolute4, ".cii"} + +pat cuu +with STACK + gen jsr {absolute4, ".cuu"} + +pat ciu leaving cuu + +pat cui leaving cuu + +pat cfi leaving loc 18 trp +pat cif leaving loc 18 trp +pat cfu leaving loc 18 trp +pat cuf leaving loc 18 trp +pat cff leaving loc 18 trp + + +/************************************************ + * Group 9: logical instructions * + ************************************************/ + + +proc log4 +with datalt4+const DD_REG + gen xxx* %1, %2 yields %2 +with DD_REG datalt4+const + gen xxx* %2, %1 yields %1 + +proc logdef example and +with STACK + uses DD_REG = {const, $1/4 -1}, + AA_REG = {regAcon, sp, $1}, + DD_REG + gen 1: + move_l {post_inc4, sp}, %c + xxx* %c, {post_inc4, %b} + dbf %a, {slabel, 1b} + +proc logndef +with DD_REG STACK + uses AA_REG = {regAregXcon, sp, %1, 1, 0}, + DD_REG + gen asr_l {shconst, 2}, %1 + sub_l {const, 1}, %1 + 1: + move_l {post_inc4, sp}, %b + xxx* %b, {post_inc4, %a} + dbf %1, {slabel, 1b} + +pat and $1==4 call log4("and.l") +pat and $1>4 call logdef("and.l") +pat and !defined($1) call logndef("and.l") +pat ior $1==4 call log4("or.l") +pat ior $1>4 call logdef("or.l") +pat ior !defined($1) call logndef("or.l") + +pat xor $1==4 +with conreg4 DD_REG + gen eor_l %1, %2 yields %2 +with DD_REG conreg4 + gen eor_l %2, %1 yields %1 + +pat xor $1>4 call logdef("eor.l") +pat xor !defined($1) call logndef("eor.l") + +pat com $1==4 +with DD_REG + gen not_l %1 yields %1 + +pat com $1==8 +with DD_REG DD_REG + gen not_l %1 + not_l %2 yields %2 %1 + +pat com $1>4 +with STACK + uses AA_REG, + DD_REG = {const, $1/4 -1} + gen move_l sp, %a + 1: + not_l {post_inc4, %a} + dbf %b, {slabel, 1b} + +pat com !defined($1) +with DD_REG STACK + uses AA_REG + gen move_l sp, %a + asr_l {shconst, 2}, %1 + sub_l {const, 1}, %1 + 1: + not_l {post_inc4, %a} + dbf %1, {slabel, 1b} + +pat rol $1==4 +with D_REG DD_REG + gen rol_l %1, %2 yields %2 + +pat ror $1==4 +with D_REG DD_REG + gen ror_l %1, %2 yields %2 + + + + +/************************************************ + * Group 10: sets * + ************************************************/ + + +pat inn $1==4 +with conreg2 DD_REG + gen btst %1, %2 + sne %2 + and_l {const, 1}, %2 + yields %2 + +pat inn defined($1) +with any4 STACK + gen move %1, d0 + move {const, $1}, d1 + jsr {absolute4, ".inn"} + yields d0 + +pat inn !defined($1) +with any4 any4 STACK + gen move %2, d0 + move %1, d1 + jsr {absolute4, ".inn"} + yields d0 + +pat loc inn $2==4 && small($1) +with DD_REG + gen asr_l {shconst, $1}, %1 + and_l {const, 1}, %1 + yields %1 + +pat set $1==4 +with conreg2 + uses DD_REG = {const, 0} + gen bset %1, %a yields %a + +pat set $1>4 +with any4 STACK + gen move %1, d0 + move {const, $1}, d1 + jsr {absolute4, ".set"} + +pat set !defined($1) +with any4 any4 STACK + gen move %2, d0 + move %1, d1 + jsr {absolute4, ".set"} + + + + +/************************************************ + * Group 11: arrays * + ************************************************/ + + +pat lar defined($1) +with STACK + gen move {const, $1}, d0 + jsr {absolute4, ".lar"} + +pat lar !defined($1) +with any4 STACK + gen move %1, d0 + jsr {absolute4, ".lar"} + +pat sar defined($1) +with STACK + gen move {const, $1}, d0 + jsr {absolute4, ".sar"} + +pat sar !defined($1) +with any4 STACK + gen move %1, d0 + jsr {absolute4, ".sar"} + +pat aar defined($1) +with STACK + gen move {const, $1}, d0 + jsr {absolute4, ".aar"} + yields a0 + +pat aar !defined($1) +with any4 STACK + gen move %1, d0 + jsr {absolute4, ".aar"} + yields a0 + +pat lae lar $2==4 && nicesize(rom($1,3)) + leaving lae $1 aar 4 loi rom($1, 3) +pat lae sar $2==4 && nicesize(rom($1,3)) + leaving lae $1 aar 4 sti rom($1, 3) + +pat lae aar $2==4 && rom($1,3)==1 + leaving ads 4 adp 0-rom($1,1) + +#ifdef m68020 +pat lae aar $2==4 && nicesize(rom($1,3)) +with D_REG yields {regX, rom($1,3), %1} + leaving ads 4 adp rom($1,3)*(0-rom($1,1)) +#else m68020 +pat lae aar $2==4 && rom($1,3)==2 +with DD_REG + gen asl_l {shconst, 1}, %1 + yields %1 + leaving ads 4 adp (0 - rom($1,1))<<1 + +pat lae aar $2==4 && rom($1,3)==4 +with DD_REG + gen asl_l {shconst, 2}, %1 + yields %1 + leaving ads 4 adp (0 - rom($1,1))<<2 + +pat lae aar $2==4 && rom($1,3)==8 +with DD_REG + gen asl_l {shconst, 3}, %1 + yields %1 + leaving ads 4 adp (0 - rom($1,1))<<3 +#endif m68020 + + /* I WOULD ALSO LIKE THESE: + * pat lae aar $2==4 && defined(rom($1,3)) + * with const leaving adp rom($1,3)*(%1.num-rom($1,1)) + * pat lae lar $2==4 && defined(rom($1,3)) + * with const leaving adp rom($1,3)*(%1.num-rom($1,1)) + * loi rom($1,3) + * pat lae sar $2==4 && defined(rom($1,3)) + * with const leaving adp rom($1,3)*(%1.num-rom($1,1)) + * sti rom($1,3) + * BUT THEY DON'T WORK. + */ + + + +/************************************************ + * Group 12: compare instructions * + ************************************************/ + + +pat cmi $1==4 leaving sbi 4 + +pat cmi defined($1) +with STACK + gen move {const, $1}, d0 + jsr {absolute4, ".cmi"} + yields d0 + +pat cmi !defined($1) +with any4 STACK + gen move %1, d0 + jsr {absolute4, ".cmi"} + yields d0 + +pat cmu $1==4 leaving sbi 4 + +pat cmu defined($1) +with STACK + gen move {const, $1}, d0 + jsr {absolute4, ".cmu"} + yields d0 + +pat cmu !defined($1) +with any4 STACK + gen move %1, d0 + jsr {absolute4, ".cmu"} + yields d0 + +pat cms $1==4 leaving sbi 4 + +pat cms defined($1) +with STACK + gen move {const, $1}, d0 + jsr {absolute4, ".cms"} + yields d0 + +pat cms !defined($1) +with any4 STACK + gen move %1, d0 + jsr {absolute4, ".cms"} + yields d0 + +pat cmp leaving cmu 4 + +proc txx +with test_set + uses DD_REG = {const, 1} + gen test %1 + bxx* {slabel, 1f} + clr_l %a + 1: + yields %a + +pat tlt call txx("blt") +pat tle call txx("ble") +pat teq call txx("beq") +pat tne call txx("bne") +pat tge call txx("bge") +pat tgt call txx("bgt") + +pat cmf leaving loc 18 trp + + + +/************************************************ + * Group 13: branch instructions * + ************************************************/ + +pat bra +with STACK + gen bra {llabel, $1} + +proc brxx example beq +with any4 genreg STACK + gen cmp_l %1, %2 + bxx[1] {llabel, $1} +with genreg any4 STACK + gen cmp_l %2, %1 + bxx[2] {llabel, $1} +with exact immediate4 imm_cmp4 + kills ALL + gen cmp_l %1, %2 + bxx[1] {llabel, $1} +with exact imm_cmp4 immediate4 + kills ALL + gen cmp_l %2, %1 + bxx[2] {llabel, $1} +with genreg STACK + gen cmp_l {post_inc4, sp}, %1 + bxx[2] {llabel, $1} +with exact immediate4 STACK + gen cmp_l %1, {post_inc4, sp} + bxx[1] {llabel, $1} +with any2-conreg2 genreg STACK + gen cmp_w %1, %2 + bxx[1] {llabel, $1} +with genreg any2-conreg2 STACK + gen cmp_w %2, %1 + bxx[2] {llabel, $1} +with exact const imm_cmp2 + kills ALL + gen cmp_w {const, loww(%1.num)}, %2 + bxx[1] {llabel, $1} +with exact imm_cmp2 const + kills ALL + gen cmp_w {const, loww(%2.num)}, %1 + bxx[2] {llabel, $1} +with data1-conreg1 D_REG STACK + gen cmp_b %1, %2 + bxx[1] {llabel, $1} +with D_REG data1-conreg1 STACK + gen cmp_b %2, %1 + bxx[2] {llabel, $1} +with exact const imm_cmp1 + kills ALL + gen cmp_b {const, lowb(%1.num)}, %2 + bxx[1] {llabel, $1} +with exact imm_cmp1 const + kills ALL + gen cmp_b {const, lowb(%2.num)}, %1 + bxx[2] {llabel, $1} + +pat blt call brxx("blt","bgt") +pat ble call brxx("ble","bge") +pat beq call brxx("beq","beq") +pat bne call brxx("bne","bne") +pat bge call brxx("bge","ble") +pat bgt call brxx("bgt","blt") + +proc zxx example zeq +with test_set STACK + gen test %1 + bxx* {llabel, $1} +with exact STACK + gen test {post_inc4, sp} + bxx* {llabel, $1} + +pat zlt call zxx("blt") +pat zle call zxx("ble") +pat zeq call zxx("beq") +pat zne call zxx("bne") +pat zge call zxx("bge") +pat zgt call zxx("bgt") + +/************************************************ + * Group 14: procedure calls instructions * + ************************************************/ + + +pat cai +with exact ext_addr + kills ALL + gen jsr {absolute4, %1.bd} +with A_REG STACK + gen jsr {indirect4, %1} +with STACK + uses AA_REG = {post_inc4, sp} + gen jsr {indirect4, %a} +#ifdef m68020 +with exact address + kills ALL + gen jsr %1 +#else m68020 +with address STACK + gen jsr %1 +#endif m68020 + +pat cal +with STACK + gen jsr {absolute4, $1} + +pat lfr $1==4 yields d0 +pat lfr $1==8 yields d1 d0 + +pat ret $1==0 +with STACK + gen return + +pat ret $1==4 +with any4 STACK + gen move %1, d0 + return +with STACK + gen move {post_inc4, sp}, d0 + return + +pat ret $1==8 +with any4 any4 STACK + gen move %1, d0 + move %2, d1 + return +with any4 STACK + gen move %1, d0 + move {post_inc4, sp}, d1 + return +with STACK + gen move {post_inc4, sp}, d0 + move {post_inc4, sp}, d1 + return + + +/************************************************ + * Group 15: miscellaneous instructions * + ************************************************/ + +pat asp small($1) +with STACK + gen add_l {const, $1}, sp +pat asp +with STACK + gen move {regAcon, sp, $1}, sp + +pat ass $1==4 +with any4 STACK + gen add_l %1, sp + +pat blm $1==4 +with A_REG A_REG + kills allexceptcon + gen move_l {indirect4, %2}, {indirect4, %1} + +pat blm $1==8 +with A_REG A_REG + kills allexceptcon + gen move_l {indirect4, %2}, {indirect4, %1} + move_l {offsetted4, %2, 4}, {offsetted4, %1, 4} + +pat blm $1>8 +with AA_REG AA_REG + kills allexceptcon + uses DD_REG={const, $1/4 -1} + gen 1: + move_l {post_inc4, %2}, {post_inc4, %1} + dbf %a, {slabel, 1b} + +pat bls $1==4 +with DD_REG AA_REG AA_REG + kills allexceptcon + gen asr_l {shconst, 2}, %1 + beq {slabel, 2f} + sub_l {const, 1}, %1 + 1: + move_l {post_inc4, %3}, {post_inc4, %2} + dbf %1, {slabel, 1b} + 2: + +pat csa $1==4 +with STACK + gen jmp {absolute4, ".csa"} + +pat csb $1==4 +with STACK + gen jmp {absolute4, ".csb"} + +pat dch leaving loi 4 + +pat dup $1==4 +with exact STACK + gen move_l {indirect4, sp}, {pre_dec4, sp} +with any4 yields %1 %1 + +pat dup $1==8 +with exact STACK + gen move_l {offsetted4, sp, 4}, {pre_dec4, sp} + move_l {offsetted4, sp, 4}, {pre_dec4, sp} +with any4 any4 yields %2 %1 %2 %1 + +pat dup $1>8 +with STACK + uses DD_REG = {const, $1/4 -1} + gen 1: + move_l {offsetted4, sp, $1 -4}, {pre_dec4, sp} + dbf %a, {slabel, 1b} + +pat dus $1==4 +with DD_REG STACK + uses AA_REG = {regAregXcon, sp, %1, 1, 0} + gen asr_l {shconst, 2}, %1 + beq {slabel, 2f} + sub_l {const, 1}, %1 + 1: + move_l {pre_dec4, %a}, {pre_dec4, sp} + dbf %1, {slabel, 1b} + 2: + +pat exg $1==4 +with any4 any4 yields %1 %2 + +pat exg defined($1) +with STACK + gen move {const, $1}, d0 + jsr {absolute4, ".exg"} + +pat exg !defined($1) +with any4 STACK + gen move_l %1, d0 + jsr {absolute4, ".exg"} + +pat fil + gen move_l {ext_addr, $1}, {absolute4, ".filn"} + +pat gto +with STACK + uses AA_REG = {ext_addr, $1} + gen move_l {offsetted4, %a, 8}, lb + move_l {offsetted4, %a, 4}, sp +#ifdef m68020 + jmp {OFF_off4, %a, 0, 0} +#else m68020 + move_l {indirect4, %a}, %a + jmp {indirect4, %a} +#endif m68020 + +pat lim yields {absolute4, ".trpim"} + +pat lin + gen move {const, $1}, {absolute4, ".lino"} + +pat lni + gen add_l {const, 1}, {absolute4, ".lino"} + +pat lor $1==0 yields lb + +pat lor $1==1 +with STACK + uses AA_REG = sp yields %a + +pat lor $1==2 yields {absolute4, ".reghp"} + +pat lpb leaving adp 8 + +pat mon +with STACK + gen jsr {absolute4, ".mon"} + +pat nop +with STACK + gen jsr {absolute4, ".nop"} + +pat rck +#ifdef m68020 +with ext_addr D_REG + gen cmp2_l {absolute4, %1.bd}, %2 + bcc {slabel, 1f} + pea {absolute4, 1} /* push constant 1 == ERANGE */ + jsr {absolute4, ".trp"} + 1: yields %2 +with address-ext_addr D_REG + gen cmp2_l %1, %2 + bcc {slabel, 1f} + pea {absolute4, 1} /* push constant 1 == ERANGE */ + jsr {absolute4, ".trp"} + 1: yields %2 +with A_REG D_REG + gen cmp2_l {indirect4, %1}, %2 + bcc {slabel, 1f} + pea {absolute4, 1} /* push constant 1 == ERANGE */ + jsr {absolute4, ".trp"} + 1: yields %2 +#else m68020 +with STACK + gen jsr {absolute4, ".rck"} +#endif m68020 + +pat rtt leaving ret 0 + +pat sig +with any4 + uses AA_REG + gen move {absolute4, ".trppc"}, %a + move %1, {absolute4, ".trppc"} + yields %a + +pat sim +with any4 + gen move_l %1, {absolute4, ".trpim"} + +pat str $1==0 +with any4 +#ifdef m68020 + kills LOCAL, ILOCAL, all_regind %reg==lb, local_addr +#else m68020 + kills LOCAL, all_regind %reg==lb, local_addr +#endif m68020 + gen move %1, lb + +pat str $1==1 +with any4 STACK + gen move %1, sp + +pat str $1==2 +with STACK + gen jsr {absolute4, ".strhp"} + +pat trp +with STACK + gen jsr {absolute4, ".trp"} + + + +/************************************************ + * rules for long EM-patterns * + ************************************************/ + +proc lolxxxstl example lol adi stl +with conreg4 + kills all_indir, LOCAL %bd==$1 + gen xxx* %1, {LOCAL, $1} + +proc loexxxste example loe adi ste +with conreg4 + kills posextern + gen xxx* %1, {absolute4, $1} + +proc lilxxxsil example lil adi sil +with conreg4 +#ifdef m68020 + kills allexceptcon + gen xxx* %1, {ILOCAL, $1} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen xxx* %1, {indirect4, %a} +#endif m68020 + +proc lolcxxxstl example lol loc adi stl + kills all_indir, LOCAL %bd==$1 + gen xxx* {const, $2}, {LOCAL, $1} + +proc loecxxxste example loe loc adi ste + kills posextern + gen xxx* {const, $2}, {absolute4, $1} + +proc lilcxxxsil example lil loc adi sil +#ifdef m68020 + kills allexceptcon + gen xxx* {const, $2}, {ILOCAL, $1} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen xxx* {const, $2}, {indirect4, %a} +#endif m68020 + +proc lolrxxxstl example lol lol adi stl + kills all_indir, LOCAL %bd==$1 + gen xxx* {LOCAL, $2}, {LOCAL, $1} + +proc loerxxxste example loe lol adi ste + kills posextern + gen xxx* {LOCAL, $2}, {absolute4, $1} + +proc lilrxxxsil example lil lol adi sil +#ifdef m68020 + kills allexceptcon + gen xxx* {LOCAL, $2}, {ILOCAL, $1} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen xxx* {LOCAL, $2}, {indirect4, %a} +#endif m68020 + +pat lol adi stl $1==$3 && $2==4 call lolxxxstl("add.l") +pat loe adi ste $1==$3 && $2==4 call loexxxste("add.l") +pat lil adi sil $1==$3 && $2==4 call lilxxxsil("add.l") +pat lol loc adi stl $1==$4 && $3==4 call lolcxxxstl("add.l") +pat loe loc adi ste $1==$4 && $3==4 call loecxxxste("add.l") +pat lil loc adi sil $1==$4 && $3==4 call lilcxxxsil("add.l") +pat lol lol adi stl $1==$4 && $3==4 && inreg($2)==reg_any + call lolrxxxstl("add.l") +pat loe lol adi ste $1==$4 && $3==4 && inreg($2)==reg_any + call loerxxxste("add.l") +pat lil lol adi sil $1==$4 && $3==4 && inreg($2)==reg_any + call lilrxxxsil("add.l") + +pat lol adu stl $1==$3 && $2==4 call lolxxxstl("add.l") +pat loe adu ste $1==$3 && $2==4 call loexxxste("add.l") +pat lil adu sil $1==$3 && $2==4 call lilxxxsil("add.l") +pat lol loc adu stl $1==$4 && $3==4 call lolcxxxstl("add.l") +pat loe loc adu ste $1==$4 && $3==4 call loecxxxste("add.l") +pat lil loc adu sil $1==$4 && $3==4 call lilcxxxsil("add.l") +pat lol lol adu stl $1==$4 && $3==4 && inreg($2)==reg_any + call lolrxxxstl("add.l") +pat loe lol adu ste $1==$4 && $3==4 && inreg($2)==reg_any + call loerxxxste("add.l") +pat lil lol adu sil $1==$4 && $3==4 && inreg($2)==reg_any + call lilrxxxsil("add.l") + + +pat lol adp stl $1==$3 + kills all_indir, LOCAL %bd==$1 + gen add_l {const, $2}, {LOCAL, $1} + +pat lil adp sil $1==$3 + kills allexceptcon +#ifdef m68020 + gen add_l {const, $2}, {ILOCAL, $1} +#else m68020 + uses AA_REG = {LOCAL, $1} + gen add_l {const, $2}, {indirect4, %a} +#endif m68020 + +pat loe adp ste $1==$3 + kills posextern + gen add_l {const, $2}, {absolute4, $1} + +pat lol lol adp stl $1==$2 && $1==$4 + kills all_indir, LOCAL %bd==$1 + uses AA_REG = {LOCAL, $1} + gen add_l {const, $3}, {LOCAL, $1} + yields %a + +pat lil lil adp sti $1==$2 && $1==$4 + kills allexceptcon +#ifdef m68020 + uses AA_REG = {ILOCAL, $1} + gen add_l {const, $3}, {ILOCAL, $1} +#else m68020 + uses AA_REG, AA_REG = {LOCAL, $1} + gen move {indirect4, %b}, %a + add_l {const, $3}, {indirect4, %b} +#endif m68020 + yields %a + +pat loe loe adp ste $1==$2 && $1==$4 + kills posextern + uses AA_REG = {absolute4, $1} + gen add_l {const, $3}, {absolute4, $1} + yields %a + + +pat lol loc sbi stl $1==$4 && $3==4 call lolcxxxstl("sub.l") +pat loe loc sbi ste $1==$4 && $3==4 call loecxxxste("sub.l") +pat lil loc sbi sil $1==$4 && $3==4 call lilcxxxsil("sub.l") +pat lol lol sbi stl $1==$4 && $3==4 && inreg($2)==reg_any + call lolrxxxstl("sub.l") +pat loe lol sbi ste $1==$4 && $3==4 && inreg($2)==reg_any + call loerxxxste("sub.l") +pat lil lol sbi sil $1==$4 && $3==4 && inreg($2)==reg_any + call lilrxxxsil("sub.l") + +pat lol loc sbu stl $1==$4 && $3==4 call lolcxxxstl("sub.l") +pat loe loc sbu ste $1==$4 && $3==4 call loecxxxste("sub.l") +pat lil loc sbu sil $1==$4 && $3==4 call lilcxxxsil("sub.l") +pat lol lol sbu stl $1==$4 && $3==4 && inreg($2)==reg_any + call lolrxxxstl("sub.l") +pat loe lol sbu ste $1==$4 && $3==4 && inreg($2)==reg_any + call loerxxxste("sub.l") +pat lil lol sbu sil $1==$4 && $3==4 && inreg($2)==reg_any + call lilrxxxsil("sub.l") + +pat lol and stl $1==$3 && $2==4 call lolxxxstl("and.l") +pat loe and ste $1==$3 && $2==4 call loexxxste("and.l") +pat lil and sil $1==$3 && $2==4 call lilxxxsil("and.l") +pat lol loc and stl $1==$4 && $3==4 call lolcxxxstl("and.l") +pat loe loc and ste $1==$4 && $3==4 call loecxxxste("and.l") +pat lil loc and sil $1==$4 && $3==4 call lilcxxxsil("and.l") +pat lol lol and stl $1==$4 && $3==4 && inreg($2)==reg_any + call lolrxxxstl("and.l") +pat loe lol and ste $1==$4 && $3==4 && inreg($2)==reg_any + call loerxxxste("and.l") +pat lil lol and sil $1==$4 && $3==4 && inreg($2)==reg_any + call lilrxxxsil("and.l") + +pat lol ior stl $1==$3 && $2==4 call lolxxxstl("or.l") +pat loe ior ste $1==$3 && $2==4 call loexxxste("or.l") +pat lil ior sil $1==$3 && $2==4 call lilxxxsil("or.l") +pat lol loc ior stl $1==$4 && $3==4 call lolcxxxstl("or.l") +pat loe loc ior ste $1==$4 && $3==4 call loecxxxste("or.l") +pat lil loc ior sil $1==$4 && $3==4 call lilcxxxsil("or.l") +pat lol lol ior stl $1==$4 && $3==4 && inreg($2)==reg_any + call lolrxxxstl("or.l") +pat loe lol ior ste $1==$4 && $3==4 && inreg($2)==reg_any + call loerxxxste("or.l") +pat lil lol ior sil $1==$4 && $3==4 && inreg($2)==reg_any + call lilrxxxsil("or.l") + +pat lol xor stl $1==$3 && $2==4 call lolxxxstl("eor.l") +pat loe xor ste $1==$3 && $2==4 call loexxxste("eor.l") +pat lil xor sil $1==$3 && $2==4 call lilxxxsil("eor.l") +pat lol loc xor stl $1==$4 && $3==4 call lolcxxxstl("eor.l") +pat loe loc xor ste $1==$4 && $3==4 call loecxxxste("eor.l") +pat lil loc xor sil $1==$4 && $3==4 call lilcxxxsil("eor.l") +pat lol lol xor stl $1==$4 && $3==4 && inreg($2)==reg_any + call lolrxxxstl("eor.l") +pat loe lol xor ste $1==$4 && $3==4 && inreg($2)==reg_any + call loerxxxste("eor.l") +pat lil lol xor sil $1==$4 && $3==4 && inreg($2)==reg_any + call lilrxxxsil("eor.l") + +proc llol1shstl example lol loc sli stl /* only left */ + kills all_indir, LOCAL %bd==$1 + gen shw* {offsetted2, lb, $1+2} + roxl {offsetted2, lb, $1} + +proc lloe1shste example loe loc sli ste /* only left */ + kills posextern + gen shw* {absolute2, $1+2} + roxl {absolute2, $1} + +proc llil1shsil example lil loc sli sil /* only left */ +#ifdef m68020 + kills allexceptcon + gen shw* {OFF_off2, lb, $1, 2} + roxl {OFF_off2, lb, $1, 0} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen shw* {offsetted2, %a, 2} + roxl {indirect2, %a} +#endif m68020 + +proc rlol1shstl example lol loc sri stl /* only right */ + kills all_indir, LOCAL %bd==$1 + gen shw* {offsetted2, lb, $1} + roxr {offsetted2, lb, $1+2} + +proc rloe1shste example loe loc sri ste /* only right */ + kills posextern + gen shw* {absolute2, $1} + roxr {absolute2, $1+2} + +proc rlil1shsil example lil loc sri sil /* only right */ +#ifdef m68020 + kills allexceptcon + gen shw* {OFF_off2, lb, $1, 0} + roxr {OFF_off2, lb, $1, 2} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen shw* {indirect2, %a} + roxr {offsetted2, %a, 2} +#endif m68020 + +pat lol loc sli stl $1==$4 && $2==1 && $3==4 call llol1shstl("asl #1,") +pat loe loc sli ste $1==$4 && $2==1 && $3==4 call lloe1shste("asl #1,") +pat lil loc sli sil $1==$4 && $2==1 && $3==4 call llil1shsil("asl #1,") +pat lol loc sri stl $1==$4 && $2==1 && $3==4 call rlol1shstl("asr #1,") +pat loe loc sri ste $1==$4 && $2==1 && $3==4 call rloe1shste("asr #1,") +pat lil loc sri sil $1==$4 && $2==1 && $3==4 call rlil1shsil("asr #1,") +pat lol loc slu stl $1==$4 && $2==1 && $3==4 call llol1shstl("asl #1,") +pat loe loc slu ste $1==$4 && $2==1 && $3==4 call lloe1shste("asl #1,") +pat lil loc slu sil $1==$4 && $2==1 && $3==4 call llil1shsil("asl #1,") +pat lol loc sru stl $1==$4 && $2==1 && $3==4 call rlol1shstl("lsr #1,") +pat loe loc sru ste $1==$4 && $2==1 && $3==4 call rloe1shste("lsr #1,") +pat lil loc sru sil $1==$4 && $2==1 && $3==4 call rlil1shsil("lsr #1,") + +proc locsh example loc sli +with DD_REG + gen sh* {shconst, $1}, %1 + yields %1 + +pat loc sli small($1) && $2==4 call locsh("asl.l") +pat loc sri small($1) && $2==4 call locsh("asr.l") +pat loc slu small($1) && $2==4 call locsh("asl.l") +pat loc sru small($1) && $2==4 call locsh("lsr.l") +pat loc rol small($1) && $2==4 call locsh("rol.l") +pat loc ror small($1) && $2==4 call locsh("ror.l") + +proc lolbitstl example lol ngi stl + kills all_indir, LOCAL %bd==$1 + gen bit* {LOCAL, $1} + +proc loebitste example loe ngi ste + kills posextern + gen bit* {absolute4, $1} + +proc lilbitsil example lil ngi sil +#ifdef m68020 + kills allexceptcon + gen bit* {ILOCAL, $1} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen bit* {indirect4, %a} +#endif m68020 + +pat lol ngi stl $1==$3 && $2==4 call lolbitstl("neg.l") +pat loe ngi ste $1==$3 && $2==4 call loebitste("neg.l") +pat lil ngi sil $1==$3 && $2==4 call lilbitsil("neg.l") +pat lol com stl $1==$3 && $2==4 call lolbitstl("not.l") +pat loe com ste $1==$3 && $2==4 call loebitste("not.l") +pat lil com sil $1==$3 && $2==4 call lilbitsil("not.l") + +pat lil inc sil $1==$3 +#ifdef m68020 + kills allexceptcon + gen add_l {const, 1}, {ILOCAL, $1} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen add_l {const, 1}, {indirect4, %a} +#endif m68020 + +pat lil dec sil $1==$3 +#ifdef m68020 + kills allexceptcon + gen sub_l {const, 1}, {ILOCAL, $1} +#else m68020 + kills allexceptcon + uses AA_REG = {LOCAL, $1} + gen sub_l {const, 1}, {indirect4, %a} +#endif m68020 + + +proc txxand +with test_set DD_REG + gen test %1 + bxx* {slabel, 1f} + clr_l %2 + 1: yields %2 + +proc txxior +with test_set DD_REG + gen test %1 + bxx* {slabel, 1f} + bset {const, 0}, %2 + 1: yields %2 + +pat tlt and $2==4 call txxand("blt") +pat tle and $2==4 call txxand("ble") +pat teq and $2==4 call txxand("beq") +pat tne and $2==4 call txxand("bne") +pat tge and $2==4 call txxand("bge") +pat tgt and $2==4 call txxand("bgt") + +pat tlt ior $2==4 call txxior("bge") +pat tle ior $2==4 call txxior("bgt") +pat teq ior $2==4 call txxior("bne") +pat tne ior $2==4 call txxior("beq") +pat tge ior $2==4 call txxior("blt") +pat tgt ior $2==4 call txxior("ble") + +proc cmxtxxand +with any4 genreg DD_REG + gen cmp_l %1, %2 + bxx[1] {slabel, 1f} + clr_l %3 + 1: yields %3 +with genreg any4-genreg DD_REG + gen cmp_l %2, %1 + bxx[2] {slabel, 1f} + clr_l %3 + 1: yields %3 +with exact immediate4 imm_cmp4 DD_REG + gen cmp_l %1, %2 + bxx[1] {slabel, 1f} + clr_l %3 + 1: yields %3 +with exact imm_cmp4 immediate4 DD_REG + gen cmp_l %2, %1 + bxx[2] {slabel, 1f} + clr_l %3 + 1: yields %3 + +proc cmxtxxior +with any4 genreg DD_REG + gen cmp_l %1, %2 + bxx[1] {slabel, 1f} + move {const, 1}, %3 + 1: yields %3 +with genreg any4-genreg DD_REG + gen cmp_l %2, %1 + bxx[2] {slabel, 1f} + move {const, 1}, %3 + 1: yields %3 +with exact immediate4 imm_cmp4 DD_REG + gen cmp_l %1, %2 + bxx[1] {slabel, 1f} + move {const, 1}, %3 + 1: yields %3 +with exact imm_cmp4 immediate4 DD_REG + gen cmp_l %2, %1 + bxx[2] {slabel, 1f} + move {const, 1}, %3 + 1: yields %3 + +proc cmxtxx +with any4 genreg + uses DD_REG = {const, 1} + gen cmp_l %1, %2 + bxx[1] {slabel, 1f} + clr_l %a + 1: yields %a +with genreg any4-genreg + uses DD_REG = {const, 1} + gen cmp_l %2, %1 + bxx[2] {slabel, 1f} + clr_l %a + 1: yields %a +with exact immediate4 imm_cmp4 + uses DD_REG = {const, 1} + gen cmp_l %1, %2 + bxx[1] {slabel, 1f} + clr_l %a + 1: yields %a +with exact imm_cmp4 immediate4 + uses DD_REG = {const, 1} + gen cmp_l %2, %1 + bxx[2] {slabel, 1f} + clr_l %a + 1: yields %a +with genreg STACK + uses DD_REG = {const, 1} + gen cmp_l {post_inc4, sp}, %1 + bxx[2] {slabel, 1f} + clr_l %a + 1: yields %a +with exact immediate4 STACK + uses DD_REG = {const, 1} + gen cmp_l %1, {post_inc4, sp} + bxx[1] {slabel, 1f} + clr_l %a + 1: yields %a + +pat cmi tlt and $1==4 && $3==4 call cmxtxxand("blt","bgt") +pat cmi tle and $1==4 && $3==4 call cmxtxxand("ble","bge") +pat cmi teq and $1==4 && $3==4 call cmxtxxand("beq","beq") +pat cmi tne and $1==4 && $3==4 call cmxtxxand("bne","bne") +pat cmi tge and $1==4 && $3==4 call cmxtxxand("bge","ble") +pat cmi tgt and $1==4 && $3==4 call cmxtxxand("bgt","blt") + +pat cmu tlt and $1==4 && $3==4 call cmxtxxand("bcs","bhi") +pat cmu tle and $1==4 && $3==4 call cmxtxxand("bls","bcc") +pat cmu teq and $1==4 && $3==4 call cmxtxxand("beq","beq") +pat cmu tne and $1==4 && $3==4 call cmxtxxand("bne","bne") +pat cmu tge and $1==4 && $3==4 call cmxtxxand("bcc","bls") +pat cmu tgt and $1==4 && $3==4 call cmxtxxand("bhi","bcs") + +pat cmi tlt ior $1==4 && $3==4 call cmxtxxior("bge","ble") +pat cmi tle ior $1==4 && $3==4 call cmxtxxior("bgt","blt") +pat cmi teq ior $1==4 && $3==4 call cmxtxxior("bne","bne") +pat cmi tne ior $1==4 && $3==4 call cmxtxxior("beq","beq") +pat cmi tge ior $1==4 && $3==4 call cmxtxxior("blt","bgt") +pat cmi tgt ior $1==4 && $3==4 call cmxtxxior("ble","bge") + +pat cmu tlt ior $1==4 && $3==4 call cmxtxxior("bcc","bls") +pat cmu tle ior $1==4 && $3==4 call cmxtxxior("bhi","bcs") +pat cmu teq ior $1==4 && $3==4 call cmxtxxior("bne","bne") +pat cmu tne ior $1==4 && $3==4 call cmxtxxior("beq","beq") +pat cmu tge ior $1==4 && $3==4 call cmxtxxior("bcs","bhi") +pat cmu tgt ior $1==4 && $3==4 call cmxtxxior("bls","bcc") + +pat cmi tlt $1==4 call cmxtxx("blt","bgt") +pat cmi tle $1==4 call cmxtxx("ble","bge") +pat cmi teq $1==4 call cmxtxx("beq","beq") +pat cmi tne $1==4 call cmxtxx("bne","bne") +pat cmi tge $1==4 call cmxtxx("bge","blt") +pat cmi tgt $1==4 call cmxtxx("bgt","blt") + +pat cmu tlt $1==4 call cmxtxx("bcs","bhi") +pat cmu tle $1==4 call cmxtxx("bls","bcc") +pat cmu teq $1==4 call cmxtxx("beq","beq") +pat cmu tne $1==4 call cmxtxx("bne","bne") +pat cmu tge $1==4 call cmxtxx("bcc","bls") +pat cmu tgt $1==4 call cmxtxx("bhi","bcs") + +proc cmxzxx example cmu zlt +with any4 genreg STACK + gen cmp_l %1, %2 + bxx[1] {llabel, $2} +with genreg any4-genreg STACK + gen cmp_l %2, %1 + bxx[2] {llabel, $2} +with exact immediate4 imm_cmp4 + kills ALL + gen cmp_l %1, %2 + bxx[1] {llabel, $2} +with exact imm_cmp4 immediate4 + kills ALL + gen cmp_l %2, %1 + bxx[2] {llabel, $2} +with genreg STACK + gen cmp_l {post_inc4, sp}, %1 + bxx[2] {llabel, $2} +with exact immediate4 STACK + gen cmp_l %1, {post_inc4, sp} + bxx[1] {llabel, $2} + +pat cmu zlt $1==4 call cmxzxx("bcs","bhi") +pat cmu zle $1==4 call cmxzxx("bls","bcc") +pat cmu zeq $1==4 call cmxzxx("beq","beq") +pat cmu zne $1==4 call cmxzxx("bne","bne") +pat cmu zge $1==4 call cmxzxx("bcc","bls") +pat cmu zgt $1==4 call cmxzxx("bhi","bcs") + + +proc bxx1_in example loc loc cii loc bne +with imm_cmp1 STACK + gen cmp_b {const, lowb($4)}, %1 + bxx* {llabel, $5} + +proc bxx2_in example loc loc cii loc bne +with imm_cmp2 STACK + gen cmp_w {const, loww($4)}, %1 + bxx* {llabel, $5} + +pat loc loc cii loc blt $1==1 && $2==4 && in_1($4) call bxx1_in("blt") +pat loc loc cii loc ble $1==1 && $2==4 && in_1($4) call bxx1_in("ble") +pat loc loc cii loc beq $1==1 && $2==4 && in_1($4) call bxx1_in("beq") +pat loc loc cii loc bne $1==1 && $2==4 && in_1($4) call bxx1_in("bne") +pat loc loc cii loc bge $1==1 && $2==4 && in_1($4) call bxx1_in("bge") +pat loc loc cii loc bgt $1==1 && $2==4 && in_1($4) call bxx1_in("bgt") + +pat loc loc cii loc blt $1==2 && $2==4 && in_2($4) call bxx2_in("blt") +pat loc loc cii loc ble $1==2 && $2==4 && in_2($4) call bxx2_in("ble") +pat loc loc cii loc beq $1==2 && $2==4 && in_2($4) call bxx2_in("beq") +pat loc loc cii loc bne $1==2 && $2==4 && in_2($4) call bxx2_in("bne") +pat loc loc cii loc bge $1==2 && $2==4 && in_2($4) call bxx2_in("bge") +pat loc loc cii loc bgt $1==2 && $2==4 && in_2($4) call bxx2_in("bgt") + +pat loc loc cii $1==1 && $2==2 +with DD_REG + gen ext_w %1 yields %1 + +pat loc loc cii $1==2 && $2==4 +with DD_REG + gen ext_l %1 yields %1 + +pat loc loc cii $1==1 && $2==4 +with DD_REG +#ifdef m68020 + gen extb_l %1 yields %1 +#else m68020 + gen ext_w %1 + ext_l %1 yields %1 +#endif m68020 + +pat loc loc ciu $1==$2 /* skip this */ +pat loc loc cui $1==$2 /* skip this */ + + +/* The following rules should be handled by the peephole optimizer, I think */ + +pat loc dvi $1==2 && $2==4 leaving loc 1 sri 4 +pat loc dvi $1==4 && $2==4 leaving loc 2 sri 4 +pat loc dvi $1==8 && $2==4 leaving loc 3 sri 4 +pat loc dvi $1==16 && $2==4 leaving loc 4 sri 4 +pat loc dvi $1==32 && $2==4 leaving loc 5 sri 4 +pat loc dvi $1==64 && $2==4 leaving loc 6 sri 4 +pat loc dvi $1==128 && $2==4 leaving loc 7 sri 4 +pat loc dvi $1==256 && $2==4 leaving loc 8 sri 4 + +pat loc dvu $1==2 && $2==4 leaving loc 1 sru 4 +pat loc dvu $1==4 && $2==4 leaving loc 2 sru 4 +pat loc dvu $1==8 && $2==4 leaving loc 3 sru 4 +pat loc dvu $1==16 && $2==4 leaving loc 4 sru 4 +pat loc dvu $1==32 && $2==4 leaving loc 5 sru 4 +pat loc dvu $1==64 && $2==4 leaving loc 6 sru 4 +pat loc dvu $1==128 && $2==4 leaving loc 7 sru 4 +pat loc dvu $1==256 && $2==4 leaving loc 8 sru 4 From 25fd7185571804ff4ecb7840b3ac1eeb02ec1128 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 13 Jan 1987 09:56:17 +0000 Subject: [PATCH 0475/1625] Added "standard" entries install, cmp, opr --- util/ego/ic/Makefile | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/util/ego/ic/Makefile b/util/ego/ic/Makefile index cf4fd798..e5b492a2 100644 --- a/util/ego/ic/Makefile +++ b/util/ego/ic/Makefile @@ -1,6 +1,11 @@ -EMH=../../../h -EMLIB=../../../lib +EMHOME=../../.. +EMH=$(EMHOME)/h +EMLIB=$(EMHOME)/lib SHR=../share +LDFLAGS=-i +CPPFLAGS=-DVERBOSE -DNOTCOMPACT +CFLAGS=$(CPPFLAGS) -O +LINTFLAGS=-phbac CFILES=\ ic.c ic_aux.c ic_lib.c ic_lookup.c ic_io.c @@ -22,6 +27,8 @@ SHARE_MFILES=\ $(SHR)/put.m $(SHR)/alloc.m $(SHR)/global.m $(SHR)/debug.m \ $(SHR)/files.m $(SHR)/map.m $(SHR)/lset.m $(SHR)/cset.m $(SHR)/aux.m +all: ic + ic: $(OFILES) $(CC) -o ic $(LDFLAGS) $(OFILES) $(SHARE_OFILES) $(EMLIB)/em_data.a @@ -29,12 +36,24 @@ ic_ack: $(CFILES) $(SHARE_MFILES) $(CC) -c.o $(CFLAGS) $(CFILES) $(SHARE_MFILES) $(CC) -o ic -.c $(LDFLAGS) ic.o $(EMLIB)/em_data.a +install: all + ../install ic + +cmp: all + -../compare ic + lint: lint $(LINTFLAGS) $(CPPFLAGS) $(CFILES) -pr: $(PRFILES) +print: $(PRFILES) @pr $? - @touch pr + @touch print + +pr: + @pr $(PRFILES) + +opr: + make pr | opr depend: $(SHR)/makedepend From 6062643c14ce3279928cd7862fae768e2bbbd0fe Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 13 Jan 1987 10:01:07 +0000 Subject: [PATCH 0476/1625] Initial revision --- util/ego/compare | 6 ++++++ util/ego/install | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100755 util/ego/compare create mode 100755 util/ego/install diff --git a/util/ego/compare b/util/ego/compare new file mode 100755 index 00000000..774b4733 --- /dev/null +++ b/util/ego/compare @@ -0,0 +1,6 @@ +case $# in +1) DEST="$1" ;; +2) DEST="$2" ;; +*) echo $0 [source] destination ;; +esac +cmp "$1" ../../../lib/ego/$DEST diff --git a/util/ego/install b/util/ego/install new file mode 100755 index 00000000..02ced829 --- /dev/null +++ b/util/ego/install @@ -0,0 +1,16 @@ +case $# in +1) DEST="$1" ;; +2) DEST="$2" ;; +*) echo $0 [source] destination ;; +esac +mkdir ../../../lib/ego > /dev/null 2>&1 +if cp "$1" ../../../lib/ego/$DEST >/dev/null 2>&1 || + { rm -f ../../../lib/ego/$DEST >/dev/null 2>&1 && + cp "$1" ../../../lib/ego/$DEST >/dev/null 2>&1 + } +then + exit 0 +else + echo Sorry, can not create "lib/ego/$DEST". + exit 1 +fi From cc8b9e32bd6deef3871fda9d4fac35953ee97df6 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 13 Jan 1987 10:07:25 +0000 Subject: [PATCH 0477/1625] Added a "clean" entry. --- util/ego/ic/Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/util/ego/ic/Makefile b/util/ego/ic/Makefile index e5b492a2..00152223 100644 --- a/util/ego/ic/Makefile +++ b/util/ego/ic/Makefile @@ -42,6 +42,9 @@ install: all cmp: all -../compare ic +clean: + rm -f *.o ic Out out nohup.out + lint: lint $(LINTFLAGS) $(CPPFLAGS) $(CFILES) From 264b01aa4300cb995983b62e7ff37d1b3f79ef24 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 13 Jan 1987 10:08:47 +0000 Subject: [PATCH 0478/1625] Added "standard" entries --- util/ego/cf/Makefile | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/util/ego/cf/Makefile b/util/ego/cf/Makefile index 6fd7cc1f..594439fc 100644 --- a/util/ego/cf/Makefile +++ b/util/ego/cf/Makefile @@ -1,6 +1,13 @@ -EMH=../../../h -EMLIB=../../../lib -SHR=../share + +EMHOME=../../.. +EMH=$(EMHOME)/h +EMLIB=$(EMHOME)/lib +SHARE=../share + +LDFLAGS=-i +CPPFLAGS=-DVERBOSE -DNOTCOMPACT +CFLAGS=$(CPPFLAGS) -O +LINTFLAGS=-phbac CFILES=\ cf.c cf_succ.c cf_idom.c cf_loop.c @@ -24,6 +31,8 @@ $(SHR)/get.m $(SHR)/put.m $(SHR)/alloc.m $(SHR)/global.m \ $(SHR)/debug.m $(SHR)/files.m $(SHR)/map.m $(SHR)/lset.m \ $(SHR)/cset.m $(SHR)/aux.m +all: cf + cf: $(OFILES) $(CC) -o cf $(LDFLAGS) $(OFILES) $(SHARE_OFILES) $(EMLIB)/em_data.a @@ -31,12 +40,27 @@ cf_ack: $(CFILES) $(SHARE_MFILES) $(CC) -c.o $(CFLAGS) $(CFILES) $(SHARE_MFILES) $(CC) -o cf -.c $(LDFLAGS) cf.o $(EMLIB)/em_data.a +install: all + ../install cf + +cmp: all + -../compare cf + +pr: + @pr $(PRFILES) + +opr: + make pr | opr + +clean: + rm -f cf *.o Out out nohup.out + lint: lint $(LINTFLAGS) $(CPPFLAGS) $(CFILES) -pr: $(PRFILES) +print: $(PRFILES) @pr $? - @touch pr + @touch print depend: $(SHR)/makedepend From 50150ff96e166dbb645f463f4efa814da08d8941 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 13 Jan 1987 10:30:06 +0000 Subject: [PATCH 0479/1625] Added standard entries --- util/ego/bo/Makefile | 34 +++++++++++++++++++++++++++++----- util/ego/ca/Makefile | 34 +++++++++++++++++++++++++++++----- util/ego/cj/Makefile | 34 +++++++++++++++++++++++++++++----- util/ego/cs/Makefile | 34 +++++++++++++++++++++++++++++----- util/ego/il/Makefile | 34 +++++++++++++++++++++++++++++----- util/ego/lv/Makefile | 34 +++++++++++++++++++++++++++++----- util/ego/ra/Makefile | 34 +++++++++++++++++++++++++++++----- util/ego/sp/Makefile | 34 +++++++++++++++++++++++++++++----- util/ego/sr/Makefile | 34 +++++++++++++++++++++++++++++----- util/ego/ud/Makefile | 34 +++++++++++++++++++++++++++++----- 10 files changed, 290 insertions(+), 50 deletions(-) diff --git a/util/ego/bo/Makefile b/util/ego/bo/Makefile index 043cb382..3d52fbbc 100644 --- a/util/ego/bo/Makefile +++ b/util/ego/bo/Makefile @@ -1,6 +1,13 @@ -EMH=../../../h -EMLIB=../../../lib -SHR=../share + +EMHOME=../../.. +EMH=$(EMHOME)/h +EMLIB=$(EMHOME)/lib +SHARE=../share + +LDFLAGS=-i +CPPFLAGS=-DVERBOSE -DNOTCOMPACT +CFLAGS=$(CPPFLAGS) -O +LINTFLAGS=-phbac CFILES=\ bo.c @@ -23,6 +30,8 @@ $(SHR)/get.m $(SHR)/put.m $(SHR)/alloc.m $(SHR)/global.m $(SHR)/debug.m \ $(SHR)/files.m $(SHR)/map.m $(SHR)/lset.m $(SHR)/cset.m $(SHR)/aux.m \ $(SHR)/stack_chg.m $(SHR)/go.m +all: bo + bo: $(OFILES) $(CC) -o bo $(LDFLAGS) $(OFILES) $(SHARE_OFILES) $(EMLIB)/em_data.a @@ -30,12 +39,27 @@ bo_ack: $(CFILES) $(SHARE_MFILES) $(CC) -c.o $(CFLAGS) $(CFILES) $(SHARE_MFILES) $(CC) -o bo -.c $(LDFLAGS) bo.o $(EMLIB)/em_data.a +install: all + ../install bo + +cmp: all + -../compare bo + +pr: + @pr $(PRFILES) + +opr: + make pr | opr + +clean: + rm -f bo *.o Out out nohup.out + lint: lint $(LINTFLAGS) $(CPPFLAGS) $(CFILES) -pr: $(PRFILES) +print: $(PRFILES) @pr $? - @touch pr + @touch print depend: $(SHR)/makedepend diff --git a/util/ego/ca/Makefile b/util/ego/ca/Makefile index 9677363a..093b5bbb 100644 --- a/util/ego/ca/Makefile +++ b/util/ego/ca/Makefile @@ -1,6 +1,13 @@ -EMH=../../../h -EMLIB=../../../lib -SHR=../share + +EMHOME=../../.. +EMH=$(EMHOME)/h +EMLIB=$(EMHOME)/lib +SHARE=../share + +LDFLAGS=-i +CPPFLAGS=-DVERBOSE -DNOTCOMPACT +CFLAGS=$(CPPFLAGS) -O +LINTFLAGS=-phbac CFILES=\ ca.c ca_put.c @@ -22,6 +29,8 @@ SHARE_MFILES=\ $(SHR)/get.m $(SHR)/alloc.m $(SHR)/global.m $(SHR)/aux.m $(SHR)/debug.m \ $(SHR)/lset.m $(SHR)/cset.m $(SHR)/files.m $(SHR)/map.m +all: ca + ca: $(OFILES) $(CC) -o ca $(LDFLAGS) $(OFILES) $(SHARE_OFILES) $(EMLIB)/em_data.a @@ -29,12 +38,27 @@ ca_ack: $(CFILES) $(SHARE_MFILES) $(CC) -c.o $(CFLAGS) $(CFILES) $(SHARE_MFILES) $(CC) -o ca -.c $(LDFLAGS) ca.o $(EMLIB)/em_data.a +install: all + ../install ca + +cmp: all + -../compare ca + +pr: + @pr $(PRFILES) + +opr: + make pr | opr + +clean: + rm -f ca *.o Out out nohup.out + lint: lint $(LINTFLAGS) $(CPPFLAGS) $(CFILES) -pr: $(PRFILES) +print: $(PRFILES) @pr $? - @touch pr + @touch print depend: $(SHR)/makedepend diff --git a/util/ego/cj/Makefile b/util/ego/cj/Makefile index 15f400c7..e5b3c461 100644 --- a/util/ego/cj/Makefile +++ b/util/ego/cj/Makefile @@ -1,6 +1,13 @@ -EMH=../../../h -EMLIB=../../../lib -SHR=../share + +EMHOME=../../.. +EMH=$(EMHOME)/h +EMLIB=$(EMHOME)/lib +SHARE=../share + +LDFLAGS=-i +CPPFLAGS=-DVERBOSE -DNOTCOMPACT +CFLAGS=$(CPPFLAGS) -O +LINTFLAGS=-phbac CFILES=\ cj.c @@ -22,6 +29,8 @@ SHARE_MFILES=\ $(SHR)/get.m $(SHR)/put.m $(SHR)/alloc.m $(SHR)/global.m $(SHR)/debug.m \ $(SHR)/files.m $(SHR)/map.m $(SHR)/lset.m $(SHR)/cset.m $(SHR)/aux.m $(SHR)/stack_chg.m $(SHR)/go.m +all: cj + cj: $(OFILES) $(CC) -o \ cj $(LDFLAGS) $(OFILES) $(SHARE_OFILES) $(EMLIB)/em_data.a @@ -30,12 +39,27 @@ cj_ack: $(CFILES) $(SHARE_MFILES) $(CC) -c.o $(CFLAGS) $(CFILES) $(SHARE_MFILES) $(CC) -o cj -.c $(LDFLAGS) cj.o $(EMLIB)/em_data.a +install: all + ../install cj + +cmp: all + -../compare cj + +pr: + @pr $(PRFILES) + +opr: + make pr | opr + +clean: + rm -f cj *.o Out out nohup.out + lint: lint $(LINTFLAGS) $(CPPFLAGS) $(CFILES) -pr: $(PRFILES) +print: $(PRFILES) @pr $? - @touch pr + @touch print depend: $(SHR)/makedepend diff --git a/util/ego/cs/Makefile b/util/ego/cs/Makefile index 36b841ec..054e1211 100644 --- a/util/ego/cs/Makefile +++ b/util/ego/cs/Makefile @@ -1,6 +1,13 @@ -EMH=../../../h -EMLIB=../../../lib -SHR=../share + +EMHOME=../../.. +EMH=$(EMHOME)/h +EMLIB=$(EMHOME)/lib +SHARE=../share + +LDFLAGS=-i +CPPFLAGS=-DVERBOSE -DNOTCOMPACT +CFLAGS=$(CPPFLAGS) -O +LINTFLAGS=-phbac CFILES=\ cs.c cs_alloc.c cs_aux.c cs_avail.c cs_debug.c cs_elim.c \ @@ -30,6 +37,8 @@ $(SHR)/get.m $(SHR)/put.m $(SHR)/alloc.m $(SHR)/global.m $(SHR)/debug.m\ $(SHR)/files.m $(SHR)/map.m $(SHR)/lset.m $(SHR)/cset.m $(SHR)/aux.m\ $(SHR)/go.m +all: cs + cs: $(OFILES) $(CC) -o cs $(LDFLAGS) $(OFILES) $(SHARE_OFILES) $(EMLIB)/em_data.a @@ -37,12 +46,27 @@ cs_ack: $(CFILES) $(SHARE_MFILES) $(CC) -c.o $(CFLAGS) $(CFILES) $(SHARE_MFILES) $(CC) -o cs -.c $(LDFLAGS) cs.o $(EMLIB)/em_data.a +install: all + ../install cs + +cmp: all + -../compare cs + +pr: + @pr $(PRFILES) + +opr: + make pr | opr + +clean: + rm -f cs *.o Out out nohup.out + lint: lint $(LINTFLAGS) $(CPPFLAGS) $(CFILES) -pr: $(PRFILES) +print: $(PRFILES) @pr $? - @touch pr + @touch print depend: $(SHR)/makedepend diff --git a/util/ego/il/Makefile b/util/ego/il/Makefile index 5504f502..448b55da 100644 --- a/util/ego/il/Makefile +++ b/util/ego/il/Makefile @@ -1,6 +1,13 @@ -EMH=../../../h -EMLIB=../../../lib -SHR=../share + +EMHOME=../../.. +EMH=$(EMHOME)/h +EMLIB=$(EMHOME)/lib +SHARE=../share + +LDFLAGS=-i +CPPFLAGS=-DVERBOSE -DNOTCOMPACT +CFLAGS=$(CPPFLAGS) -O +LINTFLAGS=-phbac CFILES=\ il.c il1_anal.c il1_cal.c il1_formal.c il1_aux.c il2_aux.c \ @@ -27,6 +34,8 @@ $(SHR)/get.m $(SHR)/put.m $(SHR)/alloc.m $(SHR)/global.m $(SHR)/debug.m \ $(SHR)/files.m $(SHR)/map.m $(SHR)/lset.m $(SHR)/cset.m $(SHR)/parser.m \ $(SHR)/aux.m $(SHR)/go.m +all: il + il: $(OFILES) $(CC) -o il $(LDFLAGS) $(OFILES) $(SHARE_OFILES) $(EMLIB)/em_data.a @@ -34,12 +43,27 @@ il_ack: $(CFILES) $(SHARE_MFILES) $(CC) -c.o $(CFLAGS) $(CFILES) $(SHARE_MFILES) $(CC) -o il -.c $(LDFLAGS) il.o $(EMLIB)/em_data.a +install: all + ../install il + +cmp: all + -../compare il + +pr: + @pr $(PRFILES) + +opr: + make pr | opr + +clean: + rm -f il *.o Out out nohup.out + lint: lint $(LINTFLAGS) $(CPPFLAGS) $(CFILES) -pr: $(PRFILES) +print: $(PRFILES) @pr $? - @touch pr + @touch print depend: $(SHR)/makedepend diff --git a/util/ego/lv/Makefile b/util/ego/lv/Makefile index 32298550..608b0d5f 100644 --- a/util/ego/lv/Makefile +++ b/util/ego/lv/Makefile @@ -1,6 +1,13 @@ -EMH=../../../h -EMLIB=../../../lib -SHR=../share + +EMHOME=../../.. +EMH=$(EMHOME)/h +EMLIB=$(EMHOME)/lib +SHARE=../share + +LDFLAGS=-i +CPPFLAGS=-DVERBOSE -DNOTCOMPACT +CFLAGS=$(CPPFLAGS) -O +LINTFLAGS=-phbac CFILES=\ lv.c @@ -24,6 +31,8 @@ $(SHR)/get.m $(SHR)/aux.m $(SHR)/put.m $(SHR)/map.m $(SHR)/alloc.m \ $(SHR)/global.m $(SHR)/debug.m $(SHR)/lset.m $(SHR)/cset.m $(SHR)/parser.m \ $(SHR)/files.m $(SHR)/locals.m $(SHR)/init_glob.m $(SHR)/go.m +all: lv + lv: $(OFILES) $(CC) -o lv $(LDFLAGS) $(OFILES) $(SHARE_OFILES) $(EMLIB)/em_data.a @@ -31,12 +40,27 @@ lv_ack: $(CFILES) $(SHARE_MFILES) $(CC) -c.o $(CFLAGS) $(CFILES) $(SHARE_MFILES) $(CC) -o lv -.c $(LDFLAGS) lv.o $(EMLIB)/em_data.a +install: all + ../install lv + +cmp: all + -../compare lv + +pr: + @pr $(PRFILES) + +opr: + make pr | opr + +clean: + rm -f lv *.o Out out nohup.out + lint: lint $(LINTFLAGS) $(CPPFLAGS) $(CFILES) -pr: $(PRFILES) +print: $(PRFILES) @pr $? - @touch pr + @touch print depend: $(SHR)/makedepend diff --git a/util/ego/ra/Makefile b/util/ego/ra/Makefile index 0922f804..c2f95ae0 100644 --- a/util/ego/ra/Makefile +++ b/util/ego/ra/Makefile @@ -1,6 +1,13 @@ -EMH=../../../h -EMLIB=../../../lib -SHR=../share + +EMHOME=../../.. +EMH=$(EMHOME)/h +EMLIB=$(EMHOME)/lib +SHARE=../share + +LDFLAGS=-i +CPPFLAGS=-DVERBOSE -DNOTCOMPACT +CFLAGS=$(CPPFLAGS) -O +LINTFLAGS=-phbac CFILES=\ ra.c ra_items.c ra_lifet.c ra_allocl.c ra_profits.c \ @@ -27,6 +34,8 @@ $(SHR)/aux.m $(SHR)/get.m $(SHR)/put.m $(SHR)/alloc.m $(SHR)/global.m \ $(SHR)/debug.m $(SHR)/files.m $(SHR)/map.m $(SHR)/lset.m $(SHR)/cset.m \ $(SHR)/go.m +all: ra + ra: $(OFILES) $(CC) -o ra $(LDFLAGS) $(OFILES) $(SHARE_OFILES) $(EMLIB)/em_data.a @@ -40,12 +49,27 @@ itemtab.h: itemtab.src makeitems $(EMH)/em_mnem.h makeitems: makeitems.c $(CC) -o makeitems makeitems.c +install: all + ../install ra + +cmp: all + -../compare ra + +pr: + @pr $(PRFILES) + +opr: + make pr | opr + +clean: + rm -f ra makeitems itemtab.h *.o Out out nohup.out + lint: lint $(LINTFLAGS) $(CPPFLAGS) $(CFILES) -pr: $(PRFILES) +print: $(PRFILES) @pr $? - @touch pr + @touch print depend: $(SHR)/makedepend diff --git a/util/ego/sp/Makefile b/util/ego/sp/Makefile index dcdac73f..37d5358d 100644 --- a/util/ego/sp/Makefile +++ b/util/ego/sp/Makefile @@ -1,6 +1,13 @@ -EMH=../../../h -EMLIB=../../../lib -SHR=../share + +EMHOME=../../.. +EMH=$(EMHOME)/h +EMLIB=$(EMHOME)/lib +SHARE=../share + +LDFLAGS=-i +CPPFLAGS=-DVERBOSE -DNOTCOMPACT +CFLAGS=$(CPPFLAGS) -O +LINTFLAGS=-phbac CFILES=\ sp.c @@ -23,6 +30,8 @@ $(SHR)/get.m $(SHR)/put.m $(SHR)/alloc.m $(SHR)/global.m $(SHR)/debug.m \ $(SHR)/files.m $(SHR)/map.m $(SHR)/lset.m $(SHR)/cset.m $(SHR)/aux.m \ $(SHR)/stack_chg.m $(SHR)/go.m +all: sp + sp: $(OFILES) $(CC) -o sp $(LDFLAGS) $(OFILES) $(SHARE_OFILES) $(EMLIB)/em_data.a @@ -30,12 +39,27 @@ sp_ack: $(CFILES) $(SHARE_MFILES) $(CC) -c.o $(CFLAGS) $(CFILES) $(SHARE_MFILES) $(CC) -o sp -.c $(LDFLAGS) sp.o $(EMLIB)/em_data.a +install: all + ../install sp + +cmp: all + -../compare sp + +pr: + @pr $(PRFILES) + +opr: + make pr | opr + +clean: + rm -f sp *.o Out out nohup.out + lint: lint $(LINTFLAGS) $(CPPFLAGS) $(CFILES) -pr: $(PRFILES) +print: $(PRFILES) @pr $? - @touch pr + @touch print depend: $(SHR)/makedepend diff --git a/util/ego/sr/Makefile b/util/ego/sr/Makefile index cabdd7d8..2a815355 100644 --- a/util/ego/sr/Makefile +++ b/util/ego/sr/Makefile @@ -1,6 +1,13 @@ -EMH=../../../h -EMLIB=../../../lib -SHR=../share + +EMHOME=../../.. +EMH=$(EMHOME)/h +EMLIB=$(EMHOME)/lib +SHARE=../share + +LDFLAGS=-i +CPPFLAGS=-DVERBOSE -DNOTCOMPACT +CFLAGS=$(CPPFLAGS) -O +LINTFLAGS=-phbac CFILES=\ sr.c sr_iv.c sr_reduce.c sr_cand.c sr_xform.c sr_expr.c sr_aux.c @@ -24,6 +31,8 @@ $(SHR)/get.m $(SHR)/put.m $(SHR)/alloc.m $(SHR)/global.m $(SHR)/debug.m \ $(SHR)/files.m $(SHR)/map.m $(SHR)/lset.m $(SHR)/cset.m $(SHR)/aux.m \ $(SHR)/go.m +all: sr + sr: $(OFILES) $(CC) -o sr $(LDFLAGS) $(OFILES) $(SHARE_OFILES) $(EMLIB)/em_data.a @@ -31,12 +40,27 @@ sr_ack: $(CFILES) $(SHARE_MFILES) $(CC) -c.o $(CFLAGS) $(CFILES) $(SHARE_MFILES) $(CC) -o sr -.c $(LDFLAGS) sr.o $(EMLIB)/em_data.a +install: all + ../install sr + +cmp: all + -../compare sr + +pr: + @pr $(PRFILES) + +opr: + make pr | opr + +clean: + rm -f sr *.o Out out nohup.out + lint: lint $(LINTFLAGS) $(CPPFLAGS) $(CFILES) -pr: $(PRFILES) +print: $(PRFILES) @pr $? - @touch pr + @touch print depend: $(SHR)/makedepend diff --git a/util/ego/ud/Makefile b/util/ego/ud/Makefile index 54fdbf1d..e2b7f46e 100644 --- a/util/ego/ud/Makefile +++ b/util/ego/ud/Makefile @@ -1,6 +1,13 @@ -EMH=../../../h -EMLIB=../../../lib -SHR=../share + +EMHOME=../../.. +EMH=$(EMHOME)/h +EMLIB=$(EMHOME)/lib +SHARE=../share + +LDFLAGS=-i +CPPFLAGS=-DVERBOSE -DNOTCOMPACT +CFLAGS=$(CPPFLAGS) -O +LINTFLAGS=-phbac CFILES=\ ud.c ud_defs.c ud_const.c ud_copy.c ud_aux.c @@ -24,6 +31,8 @@ $(SHR)/get.m $(SHR)/put.m $(SHR)/map.m $(SHR)/alloc.m $(SHR)/global.m \ $(SHR)/debug.m $(SHR)/lset.m $(SHR)/cset.m $(SHR)/files.m $(SHR)/aux.m \ $(SHR)/locals.m $(SHR)/init_glob.m $(SHR)/go.m +all: ud + ud: $(OFILES) $(CC) -o ud $(LDFLAGS) $(OFILES) $(SHARE_OFILES) $(EMLIB)/em_data.a @@ -31,12 +40,27 @@ ud_ack: $(CFILES) $(SHARE_MFILES) $(CC) -c.o $(CFLAGS) $(CFILES) $(SHARE_MFILES) $(CC) -o ud -.c $(LDFLAGS) ud.o $(EMLIB)/em_data.a +install: all + ../install ud + +cmp: all + -../compare ud + +pr: + @pr $(PRFILES) + +opr: + make pr | opr + +clean: + rm -f ud *.o Out out nohup.out + lint: lint $(LINTFLAGS) $(CPPFLAGS) $(CFILES) -pr: $(PRFILES) +print: $(PRFILES) @pr $? - @touch pr + @touch print depend: $(SHR)/makedepend From 4a201891d2f1ed1599a48bb27076d784d2bcffef Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 13 Jan 1987 10:43:12 +0000 Subject: [PATCH 0480/1625] Added standard entries --- util/ego/share/Makefile | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/util/ego/share/Makefile b/util/ego/share/Makefile index 16ef097c..8e880633 100644 --- a/util/ego/share/Makefile +++ b/util/ego/share/Makefile @@ -1,6 +1,13 @@ -EM=../../.. -EMH=$(EM)/h -EML=$(EM)/lib + +EMHOME=../../.. +EMH=$(EMHOME)/h +EMLIB=$(EMHOME)/lib +SHARE=../share + +LDFLAGS=-i +CPPFLAGS=-DVERBOSE -DNOTCOMPACT +CFLAGS=$(CPPFLAGS) -O +LINTFLAGS=-phbac SRC=\ types.h def.h debug.h debug.c global.h global.c files.h files.c go.h go.c\ @@ -19,6 +26,9 @@ classdefs.h pop_push.h wordlen.h alloc.o cset.o debug.o files.o go.o\ global.o lset.o map.o parser.o get.o put.o aux.o stack_chg.o locals.o\ init_glob.o +install: all + +cmp: all em_files:\ classdefs.h pop_push.h wordlen.h alloc.m cset.m debug.m\ @@ -29,6 +39,7 @@ classdefs.h: \ makeclassdef \ cldefs.src makeclassdef $(EMH)/em_mnem.h cldefs.src > classdefs.h + makeclassdef: \ makecldef.c $(CC) -o makeclassdef makecldef.c @@ -40,17 +51,29 @@ pop_push.h: \ wordlen.h: makewordlen makewordlen > wordlen.h rm makewordlen + makewordlen: makewlen.c $(CC) -o makewordlen makewlen.c + show: \ show.c - $(CC) -o show show.c $(EML)/em_data.a + $(CC) -o show show.c $(EMLIB)/em_data.a + +pr: + @pr $(PRFILES) + +opr: + make pr | opr + +clean: + rm -f makeclassdef classdefs.h makewordlen wordlen.h pop_push.h *.o Out out nohup.out *.m + lint: lint $(LINTFLAGS) $(CPPFLAGS) $(CFILES) -pr: $(PRFILES) +print: $(PRFILES) @pr $? - @touch pr + @touch print depend: $(SHR)/makedepend From baca84f98f3d2353be50ecc5601af31825e159cd Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 13 Jan 1987 10:53:33 +0000 Subject: [PATCH 0481/1625] Initial revision --- util/ego/descr/Makefile | 57 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 util/ego/descr/Makefile diff --git a/util/ego/descr/Makefile b/util/ego/descr/Makefile new file mode 100644 index 00000000..1bba9efd --- /dev/null +++ b/util/ego/descr/Makefile @@ -0,0 +1,57 @@ + +EMHOME=../../.. +EMH=$(EMHOME)/h +EMLIB=$(EMHOME)/lib +SHARE=../share + +LDFLAGS=-i +CPPFLAGS=-DVERBOSE -DNOTCOMPACT +CFLAGS=$(CPPFLAGS) -O +LINTFLAGS=-phbac + +SOURCES = i86.descr m68k2.descr pdp.descr vax2.descr vax4.descr + +TARGETS = i86descr m68k2descr vax2descr vax4descr pdpdescr + +PRFILES = Makefile descr.sed $(SOURCES) + +all: $(TARGETS) + +install: all + ../install i86descr + ../install m68k2descr + ../install vax2descr + ../install vax4descr + ../install pdpdescr + +cmp: all + -../compare i86descr + -../compare m68k2descr + -../compare vax2descr + -../compare vax4descr + -../compare pdpdescr + +pr: + @pr $(PRFILES) + +opr: + make pr | opr + +clean: + rm -f $(TARGETS) *.o Out out nohup.out + +i86descr: i86.descr descr.sed + $(CPP) -P -I$(EMH) i86.descr | sed -f descr.sed > i86descr + +pdpdescr: pdp.descr descr.sed + $(CPP) -P -I$(EMH) pdp.descr | sed -f descr.sed > pdpdescr + +m68k2descr: m68k2.descr descr.sed + $(CPP) -P -I$(EMH) m68k2.descr | sed -f descr.sed > m68k2descr + +vax2descr: vax2.descr descr.sed + $(CPP) -P -I$(EMH) vax2.descr | sed -f descr.sed > vax2descr + +vax4descr: vax4.descr descr.sed + $(CPP) -P -I$(EMH) vax4.descr | sed -f descr.sed > vax4descr + From 2b8d085b46412fe32b12a2a79d55522e544b1393 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 13 Jan 1987 11:01:26 +0000 Subject: [PATCH 0482/1625] Initial revision --- util/ego/em_ego/Makefile | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 util/ego/em_ego/Makefile diff --git a/util/ego/em_ego/Makefile b/util/ego/em_ego/Makefile new file mode 100644 index 00000000..f9269884 --- /dev/null +++ b/util/ego/em_ego/Makefile @@ -0,0 +1,28 @@ + +EMHOME=../../.. +EMH=$(EMHOME)/h +EMLIB=$(EMHOME)/lib +SHARE=../share + +LDFLAGS=-i +CPPFLAGS=-DVERBOSE -DNOTCOMPACT +CFLAGS=$(CPPFLAGS) -O +LINTFLAGS=-phbac + +all: + +install: + rm -f $(EMLIB)/em_ego + cp em_ego $(EMLIB)/em_ego + +cmp: all + -cmp em_ego $(EMLIB)/em_ego + +pr: + @pr em_ego + +opr: + make pr | opr + +clean: + From 3f5e970e095d2b154bdbd74e916eaedc5a14b669 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 13 Jan 1987 11:31:24 +0000 Subject: [PATCH 0483/1625] Initial revision --- util/ego/Action | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 util/ego/Action diff --git a/util/ego/Action b/util/ego/Action new file mode 100644 index 00000000..3a94e274 --- /dev/null +++ b/util/ego/Action @@ -0,0 +1,45 @@ +name "Global optimizer, shared code" +dir share +end +name "Global optimizer, intermediate code" +dir ic +end +name "Global optimizer, control flow" +dir cf +end +name "Global optimizer, cross jumping" +dir cj +end +name "Global optimizer, stack pollution" +dir sp +end +name "Global optimizer, branch optimization" +dir bo +end +name "Global optimizer, strength reduction" +dir sr +end +name "Global optimizer, inline substitution" +dir il +end +name "Global optimizer, use-definition analysis" +dir ud +end +name "Global optimizer, common subexpression elimination" +dir cs +end +name "Global optimizer, live-variable analysis" +dir lv +end +name "Global optimizer, register allocation" +dir ra +end +name "Global optimizer, compact assembly generation" +dir ca +end +name "Global optimizer, machine descriptions" +dir descr +end +name "Global optimizer, driver" +dir em_ego +end From fdb292a18239abfacc98261f82780124e44b3534 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 13 Jan 1987 13:13:50 +0000 Subject: [PATCH 0484/1625] *** empty log message *** --- modules/src/object/object.3 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/src/object/object.3 b/modules/src/object/object.3 index e01cb17b..c0c4c556 100644 --- a/modules/src/object/object.3 +++ b/modules/src/object/object.3 @@ -254,14 +254,15 @@ to close the file. You can close the file yourself. .PP .I Rd_rew_relo rewinds the relocation part, so that it can be read again. -\fILed\fR(1) sometimes needs this. +\fILed\fR(6) sometimes needs this. .PP .I Rd_unsigned2 reads two bytes from file descriptor .I fd and interpretes them as an unsigned integer. .PP -.I Rd_arhdr returns 1 if a header was read, and 0 on end-of-file. +.I Rd_arhdr +returns 1 if a header was read, and 0 on end-of-file. .PP When using any of the reading routines, you must define a routine named From 9fd7fe29a2d54b2454ec84dac9f74d560b775f8e Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 13 Jan 1987 15:10:23 +0000 Subject: [PATCH 0485/1625] Added rd_fd and wr_fd. --- modules/src/object/object.3 | 31 +++++++++++++++++++++++++++++-- modules/src/object/rd.c | 6 ++++++ modules/src/object/wr.c | 11 +++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/modules/src/object/object.3 b/modules/src/object/object.3 index c0c4c556..2124f823 100644 --- a/modules/src/object/object.3 +++ b/modules/src/object/object.3 @@ -1,10 +1,10 @@ .TH OBJECT 3ACK "October 16, 1986" .SH NAME wr_open, wr_close, wr_ohead, wr_sect, wr_outsect, wr_emit, wr_putc, wr_relo, -wr_name, wr_string, wr_arhdr, wr_ranlib, wr_int2, wr_long, +wr_name, wr_string, wr_arhdr, wr_ranlib, wr_int2, wr_long, wr_bytes, wr_fd, rd_open, rd_fdopen, rd_close, rd_ohead, rd_sect, rd_outsect, rd_emit, rd_relo, rd_rew_relo, rd_name, rd_string, rd_arhdr, rd_ranlib, -rd_int2, rd_unsigned2, rd_long\ \-\ routines to read +rd_int2, rd_unsigned2, rd_long, rd_bytes, rd_fd\ \-\ routines to read and write ACK-object files and libraries .SH SYNOPSIS .B #include @@ -75,6 +75,14 @@ and write ACK-object files and libraries .br .B long l; .PP +.B wr_bytes(fd, buf, l) +.br +.B char *buf; +.br +.B long l; +.PP +.B int wr_fd() +.PP .B int rd_open(filename) .br .B char *filename; @@ -140,6 +148,14 @@ and write ACK-object files and libraries .B unsigned int rd_unsigned2(fd) .PP .B long rd_long(fd) +.PP +.B rd_bytes(fd, buf, l) +.br +.B char *buf; +.br +.B long l; +.PP +.B rd_fd() .SH DESCRIPTION These routines come in handy when reading or writing ACK-object files or libraries. No checking is performed. @@ -236,6 +252,17 @@ to file descriptor .IB fd , low order word first, low order byte first. .PP +.I Wr_bytes +writes +.I l +bytes from +.I buf +to file descriptor +.IB fd . +.PP +.I Wr_fd +returns the current output file descriptor. +.PP Most of the .I rd_ routines are the opposite of the diff --git a/modules/src/object/rd.c b/modules/src/object/rd.c index 52c1f718..aae7db6c 100644 --- a/modules/src/object/rd.c +++ b/modules/src/object/rd.c @@ -81,6 +81,12 @@ rd_close() { close(outfile); + outfile = -1; +} + +rd_fd() +{ + return outfile; } rd_ohead(head) diff --git a/modules/src/object/wr.c b/modules/src/object/wr.c index 5bcf55ca..165a4dca 100644 --- a/modules/src/object/wr.c +++ b/modules/src/object/wr.c @@ -108,13 +108,24 @@ wr_close() } #ifdef OUTSEEK close(outfile); + outfile = -1; #else not OUTSEEK for (fdp = &outfile[PARTEMIT]; fdp < &outfile[NPARTS]; fdp++) { close(*fdp); + *fdp = -1; } #endif not OUTSEEK } +wr_fd() +{ +#ifdef OUTSEEK + return outfile; +#else + return outfile[PARTEMIT]; +#endif +} + wr_ohead(head) register struct outhead *head; { From b559db4ed4435a3c55a0a0d84657abbb8febbb95 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 14 Jan 1987 09:58:51 +0000 Subject: [PATCH 0486/1625] added EX_SIDEEFFECTS, options['p'] --> ! options['L'], fixed some bugs --- lang/cem/cemcom/Makefile.erik | 2 +- lang/cem/cemcom/cemcom.1 | 5 ++-- lang/cem/cemcom/ch7.c | 1 + lang/cem/cemcom/ch7bin.c | 3 ++- lang/cem/cemcom/code.c | 4 +-- lang/cem/cemcom/domacro.c | 4 ++- lang/cem/cemcom/eval.c | 49 +++++++++++++++++++++++++---------- lang/cem/cemcom/expr.str | 1 + lang/cem/cemcom/options.c | 6 +---- lang/cem/cemcom/replace.c | 2 +- 10 files changed, 51 insertions(+), 26 deletions(-) diff --git a/lang/cem/cemcom/Makefile.erik b/lang/cem/cemcom/Makefile.erik index de577f40..0ba8e0f7 100644 --- a/lang/cem/cemcom/Makefile.erik +++ b/lang/cem/cemcom/Makefile.erik @@ -14,7 +14,7 @@ LINT = /usr/new/lint SYSLIB = $(EMHOME)/modules/lib/libsystem.a EMKLIB = $(EMHOME)/modules/lib/libemk.a EMELIB = $(EMHOME)/modules/lib/libeme.a -STRLIB = $(EMHOME)/modules/lib/libstr.a +STRLIB = $(EMHOME)/modules/lib/libstring.a PRTLIB = $(EMHOME)/modules/lib/libprint.a EMMESLIB = $(EMHOME)/modules/lib/libem_mes.a INPLIB = $(EMHOME)/modules/lib/libinput.a diff --git a/lang/cem/cemcom/cemcom.1 b/lang/cem/cemcom/cemcom.1 index 64aa283e..87c7f766 100644 --- a/lang/cem/cemcom/cemcom.1 +++ b/lang/cem/cemcom/cemcom.1 @@ -42,8 +42,9 @@ set maximum identifier length to \fIn\fP. do not generate EM register messages. The user-declared variables are not stored into registers on the target machine. -.IP \fB\-p\fR -generate the EM \fBfil\fR and \fBlin\fR instructions in order to enable +.IP \fB\-L\fR +don't generate the EM \fBfil\fR and \fBlin\fR instructions +that usually are generated to enable an interpreter to keep track of the current location in the source code. .IP \fB\-P\fR like \fB\-E\fR but without #\fBline\fR control lines. diff --git a/lang/cem/cemcom/ch7.c b/lang/cem/cemcom/ch7.c index a4da640b..bd7fcce2 100644 --- a/lang/cem/cemcom/ch7.c +++ b/lang/cem/cemcom/ch7.c @@ -333,6 +333,7 @@ ch7asgn(expp, oper, expr) *expp = new_oper((*expp)->ex_type, *expp, oper, expr); #endif NOBITFIELD (*expp)->OP_TYPE = tp; /* for EVAL() */ + (*expp)->ex_flags |= EX_SIDEEFFECTS; } /* Some interesting (?) questions answered. diff --git a/lang/cem/cemcom/ch7bin.c b/lang/cem/cemcom/ch7bin.c index 90211bb6..7f9ff084 100644 --- a/lang/cem/cemcom/ch7bin.c +++ b/lang/cem/cemcom/ch7bin.c @@ -77,6 +77,7 @@ ch7bin(expp, oper, expr) else *expp = new_oper((*expp)->ex_type->tp_up, *expp, '(', expr); + (*expp)->ex_flags |= EX_SIDEEFFECTS; break; case PARCOMMA: /* RM 7.1 */ if ((*expp)->ex_type->tp_fund == FUNCTION) @@ -149,8 +150,8 @@ ch7bin(expp, oper, expr) } break; case LEFT: - case LEFTAB: case RIGHT: + case LEFTAB: case RIGHTAB: opnd2integral(expp, oper); opnd2integral(&expr, oper); diff --git a/lang/cem/cemcom/code.c b/lang/cem/cemcom/code.c index e7cadc6a..688a338a 100644 --- a/lang/cem/cemcom/code.c +++ b/lang/cem/cemcom/code.c @@ -201,7 +201,7 @@ begin_proc(name, def) /* to be called when entering a procedure */ lab_count = (label) 1; return_label = text_label(); return_expr_occurred = 0; - if (options['p']) { /* profiling */ + if (! options['L']) { /* profiling */ if (strcmp(last_fn_given, FileName) != 0) { /* previous function came from other file */ C_df_dlb(file_name_label = data_label()); @@ -479,7 +479,7 @@ code_expr(expr, val, code, tlbl, flbl) generator. If line number trace is wanted, it generates a lin instruction. EVAL() is called directly. */ - if (options['p']) /* profiling */ + if (! options['L']) /* profiling */ C_lin((arith)LineNumber); EVAL(expr, val, code, tlbl, flbl); } diff --git a/lang/cem/cemcom/domacro.c b/lang/cem/cemcom/domacro.c index ba92c11e..cb8173f7 100644 --- a/lang/cem/cemcom/domacro.c +++ b/lang/cem/cemcom/domacro.c @@ -337,8 +337,10 @@ PRIVATE do_endif() { SkipRestOfLine(); - if (nestlevel-- < 0) + if (nestlevel < 0) { lexerror("#endif without corresponding #if"); + } + else nestlevel--; } PRIVATE diff --git a/lang/cem/cemcom/eval.c b/lang/cem/cemcom/eval.c index 12f92437..ee501954 100644 --- a/lang/cem/cemcom/eval.c +++ b/lang/cem/cemcom/eval.c @@ -94,8 +94,10 @@ EVAL(expr, val, code, true_label, false_label) register struct expr *right = expr->OP_RIGHT; register struct type *tp = expr->OP_TYPE; - if (tp->tp_fund == ERRONEOUS) /* stop immediately */ + if (tp->tp_fund == ERRONEOUS || (expr->ex_flags & EX_ERROR)) { + /* stop immediately */ break; + } if (tp->tp_fund == VOID) gencode = 0; switch (oper) { @@ -298,15 +300,7 @@ EVAL(expr, val, code, true_label, false_label) C_bra(false_label); } else { - label l_true = text_label(); - label l_end = text_label(); - - compare(oper, l_true); - C_loc((arith)0); - C_bra(l_end); - C_df_ilb(l_true); - C_loc((arith)1); - C_df_ilb(l_end); + truthvalue(oper); } } break; @@ -384,9 +378,9 @@ EVAL(expr, val, code, true_label, false_label) load_val(left, RVAL); } else - if (left->ex_depth == 1 && left->OP_OPER == ARROW) { - compl = 1; /* Value->sel */ - ASSERT(left->OP_LEFT->ex_class == Value); + if (left->ex_depth == 1 && + !(left->ex_flags & EX_SIDEEFFECTS)) { + compl = 1; EVAL(left, RVAL, newcode, NO_LABEL, NO_LABEL); } else { @@ -662,6 +656,35 @@ compare(relop, lbl) } } +/* truthvalue() serves as an auxiliary function of EVAL */ +truthvalue(relop) + int relop; +{ + switch (relop) { + case '<': + C_tlt(); + break; + case LESSEQ: + C_tle(); + break; + case '>': + C_tgt(); + break; + case GREATEREQ: + C_tge(); + break; + case EQUAL: + C_teq(); + break; + case NOTEQUAL: + C_tne(); + break; + default: + CRASH(); + } +} + + /* assop() generates the opcode of an assignment operators op= */ assop(type, oper) register struct type *type; diff --git a/lang/cem/cemcom/expr.str b/lang/cem/cemcom/expr.str index c80f9a7b..47d0f07c 100644 --- a/lang/cem/cemcom/expr.str +++ b/lang/cem/cemcom/expr.str @@ -94,6 +94,7 @@ struct expr { #define EX_LOGICAL 0004 /* contains logical operator */ #define EX_COMMA 0010 /* contains expression comma */ #define EX_PARENS 0020 /* the top level is parenthesized */ +#define EX_SIDEEFFECTS 0040 /* expression has side effects */ #define EX_ERROR 0200 /* the expression is wrong */ #define NILEXPR ((struct expr *)0) diff --git a/lang/cem/cemcom/options.c b/lang/cem/cemcom/options.c index 38525c0f..cebf13e1 100644 --- a/lang/cem/cemcom/options.c +++ b/lang/cem/cemcom/options.c @@ -115,7 +115,7 @@ do_option(text) break; case 'L' : - warning("-L: default no EM profiling; use -p for EM profiling"); + options['L'] = 1; /* no fil/lin */ break; case 'M': /* maximum identifier length */ @@ -126,10 +126,6 @@ do_option(text) fatal("maximum identifier length is %d", IDFSIZE); break; - case 'p' : /* generate profiling code (fil/lin) */ - options['p'] = 1; - break; - case 'P' : /* run preprocessor stand-alone, without #'s */ #ifndef NOPP options['E'] = 1; diff --git a/lang/cem/cemcom/replace.c b/lang/cem/cemcom/replace.c index 169f0a16..7f99c879 100644 --- a/lang/cem/cemcom/replace.c +++ b/lang/cem/cemcom/replace.c @@ -155,7 +155,7 @@ macro2buffer(idef, actpars, siztext) /* copy the text of the actual parameter into the replacement text */ - for (p = actpars[n - 1]; p && *p; p++) { + for (p = actpars[n - 1]; *p; p++) { text[pos++] = *p; if (pos == size) text = Srealloc(text, size += RSTRSIZE); From 49e08c285b7bf5bfbeab1b80643516af54360959 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 14 Jan 1987 17:47:31 +0000 Subject: [PATCH 0487/1625] Fixed a minor problem with off_fmt, when this format would not produce the '-' sign. --- mach/proto/ncg/fillem.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mach/proto/ncg/fillem.c b/mach/proto/ncg/fillem.c index b671d896..83d6f05d 100644 --- a/mach/proto/ncg/fillem.c +++ b/mach/proto/ncg/fillem.c @@ -535,8 +535,12 @@ char *strarg(t) { strarg(offtyp); for (p = argstr; *p; p++) ; - if (argval >= 0) + if ((full) argval >= 0) *p++ = '+'; + else { + *p++ = '-'; + argval = - (full) argval; + } sprintf(p,off_fmt,(full)argval); break; case sp_cend: From 16b6135c10cef833db470c906e13772ff07aa16b Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 14 Jan 1987 17:49:19 +0000 Subject: [PATCH 0488/1625] Fixed a minor problem with off_fmt, when it did not produce a '-' sign when neccesary --- mach/proto/cg/fillem.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mach/proto/cg/fillem.c b/mach/proto/cg/fillem.c index f3ee53c7..83001e71 100644 --- a/mach/proto/cg/fillem.c +++ b/mach/proto/cg/fillem.c @@ -527,8 +527,12 @@ char *strarg(t) { strarg(offtyp); for (p = argstr; *p; p++) ; - if (argval >= 0) + if ((full) argval >= 0) *p++ = '+'; + else { + *p++ = '-'; + argval = - (full) argval; + } sprintf(p,off_fmt,(full)argval); break; case sp_cend: From ccbac369e042a15e4a0d515a14d52bac5d757e50 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 14 Jan 1987 21:37:22 +0000 Subject: [PATCH 0489/1625] Replaced an occurrence of EOI by EOF. --- util/cpp/domacro.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/cpp/domacro.c b/util/cpp/domacro.c index 2b908448..d00abef1 100644 --- a/util/cpp/domacro.c +++ b/util/cpp/domacro.c @@ -120,7 +120,7 @@ domacro() case INTEGER: /* # []? */ do_line((unsigned int)tk.tk_val); break; - case EOI: /* only `#' on this line: do nothing, ignore */ + case EOF: /* only `#' on this line: do nothing, ignore */ break; default: /* invalid token following '#' */ error("illegal # line"); From 5c02ff34c2b8c2679b711198621fc0b2369809d8 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 15 Jan 1987 17:36:26 +0000 Subject: [PATCH 0490/1625] Some bug fixes --- util/opt/patterns | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/opt/patterns b/util/opt/patterns index fb4d4f62..78dd06a5 100644 --- a/util/opt/patterns +++ b/util/opt/patterns @@ -162,7 +162,7 @@ loc blt $1==1: zle $2 loc dvi $1==1 && $2==w: ldc dvi $1==1 && $2==2*w: loc dvu $1==1 && $2==w: -loc dvu $1==1 && $2==2*w: +ldc dvu $1==1 && $2==2*w: loc loe adi $1==1 && $3==w: loe $2 inc loc lol adi $1==1 && $3==w: lol $2 inc loc mli $1==0 && $2==w: asp w loc 0 @@ -180,7 +180,7 @@ loc loe adi inc $3==w: loe $2 loc $1 adi w inc loc loe adi dec $3==w: loe $2 loc $1 adi w dec loc lol mli $3==w: lol $2 loc $1 mli w loc lol adi loc $3==w: lol $2 loc $1 adi w loc $4 -loc lol adi inc $3==w: lol $2 loc $1 adi w dec +loc lol adi inc $3==w: lol $2 loc $1 adi w inc loc lol adi dec $3==w: lol $2 loc $1 adi w dec ldc lde mli $3==2*w: lde $2 ldc $1 mli 2*w ldc lde adi $3==2*w: lde $2 ldc $1 adi 2*w From 31726d68d95ab3fe717984998fd5a805b26c472f Mon Sep 17 00:00:00 2001 From: bruce Date: Thu, 15 Jan 1987 18:12:26 +0000 Subject: [PATCH 0491/1625] Initial revision --- modules/src/em_opt/Makefile | 63 ++++ modules/src/em_opt/aux.c | 88 +++++ modules/src/em_opt/findworst.c | 145 +++++++++ modules/src/em_opt/initlex.c | 62 ++++ modules/src/em_opt/mkcalls.c | 433 +++++++++++++++++++++++++ modules/src/em_opt/nopt.c | 506 +++++++++++++++++++++++++++++ modules/src/em_opt/nopt.h | 65 ++++ modules/src/em_opt/outcalls.c | 127 ++++++++ modules/src/em_opt/outputdfa.c | 392 +++++++++++++++++++++++ modules/src/em_opt/parser.g | 496 ++++++++++++++++++++++++++++ modules/src/em_opt/parser.h | 96 ++++++ modules/src/em_opt/patterns | 569 +++++++++++++++++++++++++++++++++ modules/src/em_opt/pseudo.r | 471 +++++++++++++++++++++++++++ modules/src/em_opt/syntax.l | 59 ++++ 14 files changed, 3572 insertions(+) create mode 100644 modules/src/em_opt/Makefile create mode 100644 modules/src/em_opt/aux.c create mode 100644 modules/src/em_opt/findworst.c create mode 100644 modules/src/em_opt/initlex.c create mode 100644 modules/src/em_opt/mkcalls.c create mode 100644 modules/src/em_opt/nopt.c create mode 100644 modules/src/em_opt/nopt.h create mode 100644 modules/src/em_opt/outcalls.c create mode 100644 modules/src/em_opt/outputdfa.c create mode 100644 modules/src/em_opt/parser.g create mode 100644 modules/src/em_opt/parser.h create mode 100644 modules/src/em_opt/patterns create mode 100644 modules/src/em_opt/pseudo.r create mode 100644 modules/src/em_opt/syntax.l diff --git a/modules/src/em_opt/Makefile b/modules/src/em_opt/Makefile new file mode 100644 index 00000000..c8d1a557 --- /dev/null +++ b/modules/src/em_opt/Makefile @@ -0,0 +1,63 @@ +# $Header$ +EMHOME=/usr/em +MODLIB=$(EMHOME)/modules/lib +PARSERLIB=$(EMHOME)/lib/em_data.a $(MODLIB)/libprint.a $(MODLIB)/liballoc.a\ + $(MODLIB)/libstring.a $(MODLIB)/libsystem.a +HOWMUCH=head -10 +LEXLIB=-ll +INCLDIR=-I$(EMHOME)/h -I$(EMHOME)/modules/h -I$(EMHOME)/modules/pkg +PREFLAGS=$(INCLDIR) -DPRIVATE=static -DDEBUG +PROFFLAG=-O +CFLAGS=$(PREFLAGS) $(PROFFLAG) +LLOPT= +GFILES=parser.g +POFILES=parser.o syntax.o outputdfa.o outcalls.o findworst.o outputrepl.o\ + initlex.o Lpars.o +NOFILES=nopt.o dfa.o trans.o incalls.o psuedo.o aux.o mkcalls.o +GENFILES=Lpars.h Lpars.c parserdummy parser.c syntax.c dfadummy\ + dfa.c dfa.c.save trans.c trans.c.save incalls.c incalls.c.save + +all: libopt.a + +libopt.a: dfadummy $(NOFILES) + ar rc libopt.a $(NOFILES) + ranlib libopt.a + +dfadummy: patterns parser + -mv dfa.c dfa.c.save + -mv trans.c trans.c.save + -mv incalls.c incalls.c.save + -/lib/cpp patterns | $(HOWMUCH) >/tmp/patts + parser > (8*WSIZE-amount))&lowmask)); +} + +samesign(a,b) + int a, b; +{ + return( (a ^ b) >= 0); +} + +sfit(val,nbits) + int val, nbits; +{ + long mask = 0; + int i; + for(i=nbits-1;i<8*sizeof(mask);i++) + mask |= (1<argtype != a2->argtype) return(0); + switch(a1->argtype) { + case cst_ptyp: + return(a1->acst == a2->acst); + case sof_ptyp: + if(a1->asoff != a2->asoff) return(0); + return(strcmp(a1->adnam,a2->adnam)==0); + case nof_ptyp: + if(a1->anoff != a2->anoff) return(0); + return(a1->adlb == a2->adlb); + default: + fatal("illegal type (%d) to sameext!",a1->argtype); + } +} + +samenam(a1,a2) + struct instr *a1, *a2; +{ + if(a1->argtype != a2->argtype) return(0); + switch(a1->argtype) { + case cst_ptyp: + return(1); + case sof_ptyp: + return(strcmp(a1->adnam,a2->adnam)==0); + case nof_ptyp: + return(a1->adlb == a2->adlb); + default: + fatal("illegal type (%d) to samenam!",a1->argtype); + } +} + +offset(a) + struct instr *a; +{ + switch(a->argtype) { + case cst_ptyp: + return(a->acst); + case sof_ptyp: + return(a->asoff); + case nof_ptyp: + return(a->anoff); + default: + fatal("illegal type (%d) to offset!",a->argtype); + } +} diff --git a/modules/src/em_opt/findworst.c b/modules/src/em_opt/findworst.c new file mode 100644 index 00000000..6192faeb --- /dev/null +++ b/modules/src/em_opt/findworst.c @@ -0,0 +1,145 @@ +#ifndef NORCSID +static char rcsid[] = "$Header$"; +#endif + +#include "parser.h" + +#define UPDATEWORST(backups) if(backups>mostbackups) mostbackups = backups; + +findworst(state,repl) + int state; + struct mnems repl; +{ + /* + /* Find the pattern that requires the most backup of output queue. + /* Let repl be r1 r2 ... rn. All these are already on the output queue. + /* Possibilities in order of most backup first are: + /* a) pattern of form: p1 .... pb r1 r2 .... rn pc ... pd + /* i.e. completely in pattern. + /* requires a backup of b+n instructions + /* and a goto to state 0. + /* b) pattern of form: p1 .... pb r1 r2 .... ri + /* i.e. a prefix of ends a pattern. + /* requires a backup of b+n instructions + /* and a goto to state 0. + /* c) pattern of form: ri ri+1 ... rn pc ... pd + /* i.e. a suffix of starts a pattern. + /* requires a backup of n-i+1 instructions and a goto to state 0. + */ + int n = repl.m_len; + int first,i,j; + int s; + int mostbackups = 0; + if(n==0) { + fprint(ofile,"\t\tbackup(%d);\n", longestpattern-1); + return; + } + for(s=1;s<=higheststate;s++) { + /* only match complete patterns */ + if(actions[s]==(struct action *)NULL) + continue; + /* look for case a */ + if(first=rightmatch(patterns[s],repl,1,n)) { + UPDATEWORST(first-1+n); + } + /* look for case b */ + for(i=n-1;i;i--) { + if((first=rightmatch(patterns[s],repl,1,i)) && + (first+i-1==patterns[s].m_len)) { + UPDATEWORST(first-1+n); + } + } + /* look for case c */ + for(i=2;i<=n;i++) { + if((first=leftmatch(patterns[s],repl,i,n)) && + (first==1)) { + UPDATEWORST(n-i+1); + } + } + } + if(mostbackups) + fprint(ofile,"\t\tbackup(%d);\n",mostbackups); +} + +findfail(state) + int state; +{ + /* + /* If pattern matching fails in 'state', how many outputs and how many + /* push backs are requires. If pattern is of the form p1 p2 .... pn + /* look for patterns of the form p2 p3 ... pn; then p3 p4 ... pn; etc. + /* The first such match of the form pi pi+1 ... pn requires an output + /* of p1 p2 ... pi-1 and a push back of pn pn-1 ... pi. + */ + int s,i,j; + struct state *p; + int istrans; + int n = patterns[state].m_len; + for(i=2;i<=n;i++) { + for(s=1;s<=higheststate;s++) { + /* exclude those on transitions from this state */ + istrans = 0; + for(p=states[state];p!=(struct state *)NULL;p=p->next) + if(s==p->goto_state) + istrans++; + if(istrans) + continue; + if((leftmatch(patterns[s],patterns[state],i,n)==1)&& + patterns[s].m_len==(n-i+1)) { + fprint(ofile,"\t{%d,%d,%d},",i-1,n-i+1,s); + return; + } + } + } + fprint(ofile,"\t{%d,0,0},",n); +} + +PRIVATE int +leftmatch(patt,repl,i,j) + struct mnems patt,repl; + int i,j; +{ + /* + /* Return the first complete match of the mnems of + /* 'repl' in the mnems of 'patt'. Find the leftmost match. + /* Return 0 if fails. + */ + int lenrij = j-i+1; + int lastpos = patt.m_len - lenrij + 1; + int k,n; + for(k=1;k<=lastpos;k++) { + for(n=1;n<=lenrij;n++) { + if(patt.m_elems[(k+n-1)-1]->op_code != repl.m_elems[(i+n-1)-1]->op_code) + break; + } + if(n>lenrij) { + return(k); + } + } + return(0); +} + +PRIVATE int +rightmatch(patt,repl,i,j) + struct mnems patt,repl; + int i,j; +{ + /* + /* Return the first complete match of the mnems of + /* 'repl' in the mnems of 'patt'. Find the rightmost match. + /* Return 0 if fails. + */ + int lenrij = j-i+1; + int lastpos = patt.m_len - lenrij + 1; + int k,n; + for(k=lastpos;k>=1;k--) { + for(n=1;n<=lenrij;n++) { + if(patt.m_elems[(k+n-1)-1]->op_code != repl.m_elems[(i+n-1)-1]->op_code) + break; + } + if(n>lenrij) { + return(k); + } + } + return(0); +} diff --git a/modules/src/em_opt/initlex.c b/modules/src/em_opt/initlex.c new file mode 100644 index 00000000..ef05d206 --- /dev/null +++ b/modules/src/em_opt/initlex.c @@ -0,0 +1,62 @@ +#ifndef NORCSID +static char rcsid[] = "$Header$"; +#endif + +#include +#include +#include +#include "parser.h" +#define op_lab 255 + +#include + +extern char em_flag[]; +extern char em_mnem[][4]; + +initlex() +{ + register int i,j; + init_idf(); + idinit("lab",op_lab,DEFILB); + for(i=sp_fmnem;i<=sp_lmnem;i++) { + j=i-sp_fmnem; + switch(em_flag[j] & EM_PAR) { + case PAR_NO: + idinit(em_mnem[j],i,NOARG); break; + case PAR_C: + case PAR_D: + case PAR_F: + case PAR_L: + case PAR_N: + case PAR_O: + case PAR_R: + case PAR_S: + case PAR_Z: + idinit(em_mnem[j],i,CST); break; + case PAR_W: + idinit(em_mnem[j],i,CSTOPT); break; + case PAR_P: + idinit(em_mnem[j],i,PNAM); break; + case PAR_B: + idinit(em_mnem[j],i,LAB); break; + case PAR_G: + idinit(em_mnem[j],i,EXT); break; + } + } +} + +PRIVATE +idinit(tag,opcode,argfmt) + char *tag; + int opcode; + int argfmt; +{ + struct idf *p; + p = str2idf(tag,0); + p->id_nextidf = ops; /* chain into all ops */ + ops = p; + p->id_used = 0; + p->id_startpatt = 0; + p->id_opcode = opcode; + p->id_argfmt = argfmt; +} diff --git a/modules/src/em_opt/mkcalls.c b/modules/src/em_opt/mkcalls.c new file mode 100644 index 00000000..63d54892 --- /dev/null +++ b/modules/src/em_opt/mkcalls.c @@ -0,0 +1,433 @@ +#ifndef NORCSID +static char rcsid[] = "$Header$"; +#endif + +#include "nopt.h" + +mkcalls(p) + struct instr *p; +{ + switch(p->argtype) { + case lab_ptyp: + O_df_ilb(p->alab); break; + case none_ptyp: + switch(p->opcode) { + case op_aar: + O_aar_narg(); break; + case op_adf: + O_adf_narg(); break; + case op_adi: + O_adi_narg(); break; + case op_ads: + O_ads_narg(); break; + case op_adu: + O_adu_narg(); break; + case op_and: + O_and_narg(); break; + case op_ass: + O_ass_narg(); break; + case op_bls: + O_bls_narg(); break; + case op_cmf: + O_cmf_narg(); break; + case op_cmi: + O_cmi_narg(); break; + case op_cms: + O_cms_narg(); break; + case op_cmu: + O_cmu_narg(); break; + case op_com: + O_com_narg(); break; + case op_csa: + O_csa_narg(); break; + case op_csb: + O_csb_narg(); break; + case op_dus: + O_dus_narg(); break; + case op_dvf: + O_dvf_narg(); break; + case op_dvi: + O_dvi_narg(); break; + case op_dvu: + O_dvu_narg(); break; + case op_exg: + O_exg_narg(); break; + case op_fef: + O_fef_narg(); break; + case op_fif: + O_fif_narg(); break; + case op_inn: + O_inn_narg(); break; + case op_ior: + O_ior_narg(); break; + case op_lar: + O_lar_narg(); break; + case op_los: + O_los_narg(); break; + case op_mlf: + O_mlf_narg(); break; + case op_mli: + O_mli_narg(); break; + case op_mlu: + O_mlu_narg(); break; + case op_ngf: + O_ngf_narg(); break; + case op_ngi: + O_ngi_narg(); break; + case op_rck: + O_rck_narg(); break; + case op_rmi: + O_rmi_narg(); break; + case op_rmu: + O_rmu_narg(); break; + case op_rol: + O_rol_narg(); break; + case op_ror: + O_ror_narg(); break; + case op_sar: + O_sar_narg(); break; + case op_sbf: + O_sbf_narg(); break; + case op_sbi: + O_sbi_narg(); break; + case op_sbs: + O_sbs_narg(); break; + case op_sbu: + O_sbu_narg(); break; + case op_set: + O_set_narg(); break; + case op_sli: + O_sli_narg(); break; + case op_slu: + O_slu_narg(); break; + case op_sri: + O_sri_narg(); break; + case op_sru: + O_sru_narg(); break; + case op_sts: + O_sts_narg(); break; + case op_xor: + O_xor_narg(); break; + case op_zer: + O_zer_narg(); break; + case op_zrf: + O_zrf_narg(); break; + /* no arguments */ + case op_cai: + O_cai(); break; + case op_cff: + O_cff(); break; + case op_cfi: + O_cfi(); break; + case op_cfu: + O_cfu(); break; + case op_cif: + O_cif(); break; + case op_cii: + O_cii(); break; + case op_ciu: + O_ciu(); break; + case op_cmp: + O_cmp(); break; + case op_cuf: + O_cuf(); break; + case op_cui: + O_cui(); break; + case op_cuu: + O_cuu(); break; + case op_dch: + O_dch(); break; + case op_dec: + O_dec(); break; + case op_inc: + O_inc(); break; + case op_lim: + O_lim(); break; + case op_lni: + O_lni(); break; + case op_lpb: + O_lpb(); break; + case op_mon: + O_mon(); break; + case op_nop: + O_nop(); break; + case op_rtt: + O_rtt(); break; + case op_sig: + O_sig(); break; + case op_sim: + O_sim(); break; + case op_teq: + O_teq(); break; + case op_tge: + O_tge(); break; + case op_tgt: + O_tgt(); break; + case op_tle: + O_tle(); break; + case op_tlt: + O_tlt(); break; + case op_tne: + O_tne(); break; + case op_trp: + O_trp(); break; + default: + fatal("Illegal mnemonic(%d)",p->opcode); + } + break; + case cst_ptyp: /* one integer constant argument */ + switch(p->opcode) { + case op_aar: + O_aar(p->acst); break; + case op_adf: + O_adf(p->acst); break; + case op_adi: + O_adi(p->acst); break; + case op_adp: + O_adp(p->acst); break; + case op_ads: + O_ads(p->acst); break; + case op_adu: + O_adu(p->acst); break; + case op_and: + O_and(p->acst); break; + case op_asp: + O_asp(p->acst); break; + case op_ass: + O_ass(p->acst); break; + case op_blm: + O_blm(p->acst); break; + case op_bls: + O_bls(p->acst); break; + case op_cmf: + O_cmf(p->acst); break; + case op_cmi: + O_cmi(p->acst); break; + case op_cms: + O_cms(p->acst); break; + case op_cmu: + O_cmu(p->acst); break; + case op_com: + O_com(p->acst); break; + case op_csa: + O_csa(p->acst); break; + case op_csb: + O_csb(p->acst); break; + case op_del: + O_del(p->acst); break; + case op_dup: + O_dup(p->acst); break; + case op_dus: + O_dus(p->acst); break; + case op_dvf: + O_dvf(p->acst); break; + case op_dvi: + O_dvi(p->acst); break; + case op_dvu: + O_dvu(p->acst); break; + case op_exg: + O_exg(p->acst); break; + case op_fef: + O_fef(p->acst); break; + case op_fif: + O_fif(p->acst); break; + case op_inl: + O_inl(p->acst); break; + case op_inn: + O_inn(p->acst); break; + case op_ior: + O_ior(p->acst); break; + case op_lal: + O_lal(p->acst); break; + case op_lar: + O_lar(p->acst); break; + case op_ldc: + O_ldc(p->acst); break; + case op_ldf: + O_ldf(p->acst); break; + case op_ldl: + O_ldl(p->acst); break; + case op_lfr: + O_lfr(p->acst); break; + case op_lil: + O_lil(p->acst); break; + case op_lin: + O_lin(p->acst); break; + case op_loc: + O_loc(p->acst); break; + case op_lof: + O_lof(p->acst); break; + case op_loi: + O_loi(p->acst); break; + case op_lol: + O_lol(p->acst); break; + case op_lor: + O_lor(p->acst); break; + case op_los: + O_los(p->acst); break; + case op_lxa: + O_lxa(p->acst); break; + case op_lxl: + O_lxl(p->acst); break; + case op_mlf: + O_mlf(p->acst); break; + case op_mli: + O_mli(p->acst); break; + case op_mlu: + O_mlu(p->acst); break; + case op_ngf: + O_ngf(p->acst); break; + case op_ngi: + O_ngi(p->acst); break; + case op_rck: + O_rck(p->acst); break; + case op_ret: + O_ret(p->acst); break; + case op_rmi: + O_rmi(p->acst); break; + case op_rmu: + O_rmu(p->acst); break; + case op_rol: + O_rol(p->acst); break; + case op_ror: + O_ror(p->acst); break; + case op_sar: + O_sar(p->acst); break; + case op_sbf: + O_sbf(p->acst); break; + case op_sbi: + O_sbi(p->acst); break; + case op_sbs: + O_sbs(p->acst); break; + case op_sbu: + O_sbu(p->acst); break; + case op_sdf: + O_sdf(p->acst); break; + case op_sdl: + O_sdl(p->acst); break; + case op_set: + O_set(p->acst); break; + case op_sil: + O_sil(p->acst); break; + case op_sli: + O_sli(p->acst); break; + case op_slu: + O_slu(p->acst); break; + case op_sri: + O_sri(p->acst); break; + case op_sru: + O_sru(p->acst); break; + case op_stf: + O_stf(p->acst); break; + case op_sti: + O_sti(p->acst); break; + case op_stl: + O_stl(p->acst); break; + case op_str: + O_str(p->acst); break; + case op_sts: + O_sts(p->acst); break; + case op_xor: + O_xor(p->acst); break; + case op_zer: + O_zer(p->acst); break; + case op_zrf: + O_zrf(p->acst); break; + case op_zrl: + O_zrl(p->acst); break; + case op_beq: + O_beq((label)p->acst); break; + case op_bge: + O_bge((label)p->acst); break; + case op_bgt: + O_bgt((label)p->acst); break; + case op_ble: + O_ble((label)p->acst); break; + case op_blt: + O_blt((label)p->acst); break; + case op_bne: + O_bne((label)p->acst); break; + case op_bra: + O_bra((label)p->acst); break; + case op_zeq: + O_zeq((label)p->acst); break; + case op_zge: + O_zge((label)p->acst); break; + case op_zgt: + O_zgt((label)p->acst); break; + case op_zle: + O_zle((label)p->acst); break; + case op_zlt: + O_zlt((label)p->acst); break; + case op_zne: + O_zne((label)p->acst); break; + default: + fatal("Illegal mnemonic(%d)",p->opcode); + } + break; + case pro_ptyp: /* A procedure name argument */ + switch(p->opcode) { + case op_cal: + O_cal(p->apnam); break; + case op_lpi: + O_lpi(p->apnam); break; + default: + fatal("Illegal mnemonic(%d)",p->opcode); + } + break; + case nof_ptyp: /* a "g" argument */ + switch(p->opcode) { + case op_dee: + O_dee_dlb(p->adlb, p->anoff); break; + case op_fil: + O_fil_dlb(p->adlb, p->anoff); break; + case op_gto: + O_gto_dlb(p->adlb, p->anoff); break; + case op_ine: + O_ine_dlb(p->adlb, p->anoff); break; + case op_lae: + O_lae_dlb(p->adlb, p->anoff); break; + case op_lde: + O_lde_dlb(p->adlb, p->anoff); break; + case op_loe: + O_loe_dlb(p->adlb, p->anoff); break; + case op_sde: + O_sde_dlb(p->adlb, p->anoff); break; + case op_ste: + O_ste_dlb(p->adlb, p->anoff); break; + case op_zre: + O_zre_dlb(p->adlb, p->anoff); break; + default: + fatal("Illegal mnemonic(%d)",p->opcode); + } + break; + case sof_ptyp: + switch(p->opcode) { + case op_dee: + O_dee_dnam(p->adnam, p->asoff); break; + case op_fil: + O_fil_dnam(p->adnam, p->asoff); break; + case op_gto: + O_gto_dnam(p->adnam, p->asoff); break; + case op_ine: + O_ine_dnam(p->adnam, p->asoff); break; + case op_lae: + O_lae_dnam(p->adnam, p->asoff); break; + case op_lde: + O_lde_dnam(p->adnam, p->asoff); break; + case op_loe: + O_loe_dnam(p->adnam, p->asoff); break; + case op_sde: + O_sde_dnam(p->adnam, p->asoff); break; + case op_ste: + O_ste_dnam(p->adnam, p->asoff); break; + case op_zre: + O_zre_dnam(p->adnam, p->asoff); break; + default: + fatal("Illegal mnemonic(%d)",p->opcode); + } + break; + default: + fatal("Illegal argtype(%d)",p->argtype); + } +} diff --git a/modules/src/em_opt/nopt.c b/modules/src/em_opt/nopt.c new file mode 100644 index 00000000..e087e26e --- /dev/null +++ b/modules/src/em_opt/nopt.c @@ -0,0 +1,506 @@ +#ifndef NORCSID +static char rcsid[] = "$Header$"; +#endif + +#include "nopt.h" +#define MAXPATTERN 15 +#define MAXBACKUP 50 +#define MAXOUTPUT 200 +#define MAXFREEI 200 +#define MAXSTRING 1000 + +#define GETINSTR() (nextifree>freeiqueue)?*(--nextifree):\ + ((struct instr *)Malloc(sizeof(struct instr))) + +extern char em_mnem[][4]; + +struct instr **patternqueue, **nextpatt; +struct instr **backupqueue, **nextbackup, **lastbackup; +struct instr **outputqueue, **nextoutput, **lastoutput; +struct instr **freeiqueue, **nextifree, **lastifree; +char *strqueue, *nextstr, *laststr; + +int noutput; /* number of instructions in output queue */ +int WSIZE; /* wordlength */ +int PSIZE; /* pointer length */ + +#ifdef STATS +int sflag = 1; /* pattern statistics output */ +#endif +#ifdef COLLECT +int cflag = 0; /* internal statistics output */ +#define UPDATEMAX(oldmax,n) if(cflag&&n>oldmax) oldmax=n +int numwrites = 0; +int numnextems = 0; +int numpushs = 0; +int numbackups = 0; +int numflushes = 0; +int numfrees = 0; +int numdefaults = 0; +int highestbackup = 0, totalbackup = 0; +int highestoutput = 0, totaloutput = 0; +int highestfreei = 0, totalfreei = 0; +int higheststr = 0, totalstr = 0; +#endif + +C_init(wsize,psize) + arith wsize, psize; +{ + allocmem(); + O_init(wsize,psize); + WSIZE = wsize; + PSIZE = psize; +} + +C_open(fname) + char *fname; +{ + return(O_open(fname)); +} + +C_magic() +{ + O_magic(); +} + +C_close() +{ +#ifdef COLLECT + if(cflag) + outputstats(); +#endif + O_close(); +} + +PRIVATE +allocmem() +{ + /* Allocate memory for queues on heap */ + nextpatt = patternqueue = + (struct instr **)Malloc(MAXPATTERN*sizeof(struct instr *)); + nextbackup = backupqueue = + (struct instr **)Malloc(MAXBACKUP*sizeof(struct instr *)); + lastbackup = backupqueue + MAXBACKUP - 1; + nextoutput = outputqueue = + (struct instr **)Malloc(MAXOUTPUT*sizeof(struct instr *)); + lastoutput = outputqueue + MAXOUTPUT - 1; + noutput = 0; + nextifree = freeiqueue = + (struct instr **)Malloc(MAXFREEI*sizeof(struct instr *)); + lastifree = freeiqueue + MAXFREEI - 1; + nextstr = strqueue = + (char *)Malloc(MAXSTRING*sizeof(char)); + laststr = strqueue + MAXSTRING - 1; +} + +#ifdef COLLECT +PRIVATE +outputstats() +{ + int i; + fprint(STDERR,"Total of %d instructions read, %d written\n",numreads,numwrites); + fprint(STDERR,"Total of %d calls to nextem\n",numnextems); + fprint(STDERR,"Total of %d calls to flush\n",numflushes); + fprint(STDERR,"Total of %d calls to myfree\n",numfrees); + fprint(STDERR,"Total of %d instructions pushed back\n",numpushs-numbackups); + fprint(STDERR,"Total of %d instructions backed up\n",numbackups); + fprint(STDERR,"Total of %d calls to dodefault\n",numdefaults); + fprint(STDERR,"Max of highestbackup\t%d\t(%d)\t",highestbackup,MAXBACKUP); + printav(totalbackup); + fprint(STDERR,"Max of highestoutput\t%d\t(%d)\t",highestoutput,MAXOUTPUT); + printav(totaloutput); + fprint(STDERR,"Max of highestfreei\t%d\t(%d)\t",highestfreei,MAXFREEI); + printav(totalfreei); + fprint(STDERR,"Max of higheststr\t%d\t(%d)\t",higheststr,MAXSTRING); + printav(totalstr); +} + +PRIVATE +printav(n) + int n; +{ + fprint(STDERR,"Av.\t%d.%d\n",n/numflushes,(n*10)%numflushes); +} +#endif + +myfree(p) + struct instr *p; +{ +#ifdef DEBUG + fprint(STDERR,"about to free "); + prtinst(p); + fprint(STDERR,"\n"); +#endif +#ifdef COLLECT + if(cflag) + numfrees++; +#endif + if(nextifree > lastifree) { +#ifdef DEBUG + fprint(STDERR,"Warning: Overflow of freeiqueue-free arg ignored\n"); + printstate("Freea overflow"); +#endif + return; + } + *nextifree++ = p; +#ifdef COLLECT + UPDATEMAX(highestfreei,nextifree-freeiqueue); +#endif +} + +nfree(n) +{ + while(n--) + myfree(*--nextpatt); +} + +PRIVATE char * +freestr(s) + char *s; +{ + char *res = nextstr; + while(*nextstr++ = *s++); + if(nextstr > laststr) { + fprint(STDERR,"string space overflowed!\n"); + sys_stop(S_EXIT); + } +#ifdef COLLECT + UPDATEMAX(higheststr,nextstr-strqueue); +#endif + return(res); +} + +nextem() +{ + /* + /* Return the next instruction from backup queue else 0. + */ +#ifdef COLLECT + if(cflag) + numnextems++; +#endif + if(nextbackup>backupqueue) + return((*nextpatt++ = *(--nextbackup))->opcode); + return(0); +} + +flush() +{ + /* + /* Output all instructions waiting in the output queue and free their + /* storage including the saved strings. + */ + struct instr **p; +#ifdef DEBUG + printstate("Flush"); +#endif +#ifdef COLLECT + if(cflag) { + numflushes++; + totaloutput += nextoutput-outputqueue; + totalbackup += nextbackup-backupqueue; + totalfreei += nextifree-freeiqueue; + totalstr += nextstr-strqueue; + } +#endif + if(noutput) { + for(p=outputqueue;popcode = opcode; + p->argtype = none_ptyp; + output(p); +} + +inop(opcode) + int opcode; +{ + register struct instr *p = GETINSTR(); + p->opcode = opcode; + p->argtype = none_ptyp; + *nextpatt++ = p; +} + +outcst(opcode,cst) + int opcode,cst; +{ + register struct instr *p = GETINSTR(); + p->opcode = opcode; + p->argtype = cst_ptyp; + p->acst = cst; + output(p); +} + +incst(opcode,cst) + int opcode,cst; +{ + register struct instr *p = GETINSTR(); + p->opcode = opcode; + p->argtype = cst_ptyp; + p->acst = cst; + *nextpatt++ = p; +} + +outlab(opcode,lab) + int opcode,lab; +{ + register struct instr *p = GETINSTR(); + p->opcode = opcode; + p->argtype = cst_ptyp; + p->acst = lab; + output(p); +} + +inlab(opcode,lab) + int opcode,lab; +{ + register struct instr *p = GETINSTR(); + p->opcode = opcode; + p->argtype = cst_ptyp; + p->acst = lab; + *nextpatt++ = p; +} + +outpnam(opcode,pnam) + int opcode; + char *pnam; +{ + register struct instr *p = GETINSTR(); + p->opcode = opcode; + p->argtype = pro_ptyp; + p->apnam = pnam; + output(p); +} + +inpnam(opcode,pnam) + int opcode; + char *pnam; +{ + register struct instr *p = GETINSTR(); + p->opcode = opcode; + p->argtype = pro_ptyp; + p->apnam = freestr(pnam); + *nextpatt++ = p; +} + +outdefilb(opcode,deflb) + int opcode; + label deflb; +{ + register struct instr *p = GETINSTR(); + p->opcode = opcode; + p->argtype = lab_ptyp; + p->alab = deflb; + output(p); +} + +indefilb(opcode,deflb) + int opcode; + label deflb; +{ + register struct instr *p = GETINSTR(); + p->opcode = opcode; + p->argtype = lab_ptyp; + p->alab = deflb; + *nextpatt++ = p; +} + +outext(opcode,arg,soff) + int opcode; + struct instr *arg; + int soff; +{ + register struct instr *p = GETINSTR(); + p->opcode = opcode; + switch(p->argtype = arg->argtype) { + case cst_ptyp: + p->acst = soff; + break; + case sof_ptyp: + p->adnam = arg->adnam; + p->asoff = soff; + break; + case nof_ptyp: + p->adlb = arg->adlb; + p->anoff = soff; + break; + default: + fatal("Unexpected type %d in outext",arg->argtype); + } + output(p); +} + +indnam(opcode,name,off) + int opcode; + char *name; + int off; +{ + register struct instr *p = GETINSTR(); + p->opcode = opcode; + p->argtype = sof_ptyp; + p->adnam = freestr(name); + p->asoff = off; + *nextpatt++ = p; +} + +indlb(opcode,lab,off) + int opcode; + label lab; + int off; +{ + register struct instr *p = GETINSTR(); + p->opcode = opcode; + p->argtype = nof_ptyp; + p->adlb = lab; + p->anoff = off; + *nextpatt++ = p; +} + +output(p) + struct instr *p; +{ + /* Put the instruction p on the output queue */ + if(nextoutput > lastoutput) { +#ifdef DEBUG + fprint(STDERR,"Overflow of outputqueue - output flushed\n"); + printstate("Output overflow"); +#endif + flush(); + } + noutput++; + *nextoutput++ = p; +#ifdef COLLECT + UPDATEMAX(highestoutput,nextoutput-outputqueue); +#endif +} + +pushback(p) + struct instr *p; +{ + /* push instr. p onto backupqueue */ + if(nextbackup > lastbackup) { +#ifdef DEBUG + fprint(STDERR,"Warning: Overflow of backupqueue-backup ignored\n"); + printstate("Backup overflow"); +#endif + return; + } + *nextbackup++ = p; +#ifdef COLLECT + UPDATEMAX(highestbackup,nextbackup-backupqueue); + numpushs++; +#endif +} + +backup(n) + int n; +{ + /* copy (up to) n instructions from output to backup queues */ + while(n-- && nextoutput>outputqueue) { +#ifdef COLLECT + if(cflag) + numbackups++; +#endif + pushback(*(--nextoutput)); + noutput--; + } +} + +dodefault(numout, numcopy) + int numout, numcopy; +{ + register struct instr **p,**q; + q = (p = patternqueue) + numout; + while(numcopy--) { + if(numout) { + numout--; + output(*p); + } + *p++ = *q++; + } + nextpatt = p; + while(numout--) output(*p++); +#ifdef COLLECT + if(cflag) + numdefaults++; +#endif +} + +#ifdef DEBUG +PRIVATE +printstate(mess) + char *mess; +{ + struct instr **p; + fprint(STDERR,"%s - state: ",mess); + p = outputqueue; + while(popcode) { + default: + fprint(STDERR,"%s",em_mnem[p->opcode-sp_fmnem]); + break; + case OTHER: + fprint(STDERR,"OTHER"); + break; + case op_lab: + break; + } + switch(p->argtype) { + case none_ptyp: + fprint(STDERR," "); + break; + case cst_ptyp: + fprint(STDERR," %d ",p->acst); + break; + case lab_ptyp: + fprint(STDERR,"%d: ",p->alab); + break; + case nof_ptyp: + fprint(STDERR," .%d+%d ",p->adlb,p->asoff); + break; + case sof_ptyp: + fprint(STDERR," %s+%d ",p->adnam,p->asoff); + break; + case ilb_ptyp: + fprint(STDERR," *%d ",p->alab); + break; + case pro_ptyp: + fprint(STDERR," $%s ",p->apnam); + break; + default: + fatal(" prtinst - Unregognized arg %d ",p->argtype); + } +} +#endif diff --git a/modules/src/em_opt/nopt.h b/modules/src/em_opt/nopt.h new file mode 100644 index 00000000..5702b920 --- /dev/null +++ b/modules/src/em_opt/nopt.h @@ -0,0 +1,65 @@ +/* $Header$ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define NULL 0 +#define FLUSHDFA() if(state) { inop(OTHER); dfa(OTHER); } \ + else if(noutput) flush(); + +#define op_lab 255 +#define OTHER 254 +#define none_ptyp 0 + + +struct e_instr *EM_getinstr(); + +struct instr { + int opcode; + int argtype; + union { + arith cst; + label lab; + char *pnam; + struct { + label dlb; + arith noff; + } ndlb; + struct { + char *dnam; + arith soff; + } sdlb; + } val; +#define acst val.cst +#define alab val.lab +#define apnam val.pnam +#define adlb val.ndlb.dlb +#define anoff val.ndlb.noff +#define adnam val.sdlb.dnam +#define asoff val.sdlb.soff +}; + +extern struct instr **patternqueue, **nextpatt; +extern int state; +extern int noutput; /* number of instructions in output queue */ +extern int WSIZE; /* wordlength */ +extern int PSIZE; /* pointer length */ +#ifdef DEBUG +extern int dflag; /* debugging output */ +#endif +#ifdef STATS +extern int sflag; /* statistics output */ +#endif + +#define CST(p) (p->acst) +#define PNAM(p) (p->apnam) +#define LAB(p) (p->alab) +#define DEFILB(p) (p->alab) diff --git a/modules/src/em_opt/outcalls.c b/modules/src/em_opt/outcalls.c new file mode 100644 index 00000000..0c6727e3 --- /dev/null +++ b/modules/src/em_opt/outcalls.c @@ -0,0 +1,127 @@ +#ifndef NORCSID +static char rcsid[] = "$Header$"; +#endif + +#include "parser.h" + +outputincalls() +{ + struct idf *op; + int opcode; + char *s; + if(!sys_open("incalls.c",OP_WRITE,&ofile)) { + fprint(STDERR,"Fatal Error: cannot open output file incalls.c\n"); + sys_stop(S_EXIT); + } + fprint(ofile,"#include \"nopt.h\"\n\n"); + for(op=ops;op!=(struct idf *)NULL;op=op->id_nextidf) { + opcode = op->id_opcode; + s = op->id_text; + switch(op->id_argfmt) { + case NOARG: + fprint(ofile,"\nC_%s() {\n",s); + if(op->id_used) { + fprint(ofile,"\tinop(op_%s);\n",s); + fprint(ofile,"\tdfa(op_%s);\n",s); + } + else { + fprint(ofile,"\tFLUSHDFA();\n"); + fprint(ofile,"\tO_%s();\n",s); + } + fprint(ofile,"}\n",s); + break; + case CSTOPT: + fprint(ofile,"\nC_%s_narg() {\n",s); + if(op->id_used) { + fprint(ofile,"\tinop(op_%s);\n",s); + fprint(ofile,"\tdfa(op_%s);\n",s); + } + else { + fprint(ofile,"\tFLUSHDFA();\n"); + fprint(ofile,"\tO_%s_narg();\n",s); + } + fprint(ofile,"}\n",s); + /* fall thru */ + case CST: + fprint(ofile,"\nC_%s(n) int n; {\n",s); + if(op->id_used) { + fprint(ofile,"\tincst(op_%s,n);\n",s); + fprint(ofile,"\tdfa(op_%s);\n",s); + } + else { + fprint(ofile,"\tFLUSHDFA();\n"); + fprint(ofile,"\tO_%s(n);\n",s); + } + fprint(ofile,"}\n",s); + break; + case DEFILB: + fprint(ofile,"\nC_df_ilb(l) label l; {\n"); + if(op->id_used) { + fprint(ofile,"\tindefilb(op_%s,l);\n",s); + fprint(ofile,"\tdfa(op_%s);\n",s); + } + else { + fprint(ofile,"\tFLUSHDFA();\n"); + fprint(ofile,"\tO_df_ilb(l);\n",s); + } + fprint(ofile,"}\n",s); + break; + case PNAM: + fprint(ofile,"\nC_%s(s) char *s; {\n",s); + if(op->id_used) { + fprint(ofile,"\tinpnam(op_%s,s);\n",s); + fprint(ofile,"\tdfa(op_%s);\n",s); + } + else { + fprint(ofile,"\tFLUSHDFA();\n"); + fprint(ofile,"\tO_%s(s);\n",s); + } + fprint(ofile,"}\n",s); + break; + case LAB: + fprint(ofile,"\nC_%s(l) label l; {\n",s); + if(op->id_used) { + fprint(ofile,"\tinlab(op_%s,l);\n",s); + fprint(ofile,"\tdfa(op_%s);\n",s); + } + else { + fprint(ofile,"\tFLUSHDFA();\n"); + fprint(ofile,"\tO_%s(l);\n",s); + } + fprint(ofile,"}\n",s); + break; + case EXT: + fprint(ofile,"\nC_%s(n) int n; {\n",s); + if(op->id_used) { + fprint(ofile,"\tincst(op_%s,n);\n",s); + fprint(ofile,"\tdfa(op_%s);\n",s); + } + else { + fprint(ofile,"\tFLUSHDFA();\n"); + fprint(ofile,"\tO_%s(n);\n",s); + } + fprint(ofile,"}\n",s); + fprint(ofile,"\nC_%s_dnam(s,n) char *s; int n; {\n",s); + if(op->id_used) { + fprint(ofile,"\tindnam(op_%s,s,n);\n",s); + fprint(ofile,"\tdfa(op_%s);\n",s); + } + else { + fprint(ofile,"\tFLUSHDFA();\n"); + fprint(ofile,"\tO_%s_dnam(s,n);\n",s); + } + fprint(ofile,"}\n",s); + fprint(ofile,"\nC_%s_dlb(l,n) label l; int n; {\n",s); + if(op->id_used) { + fprint(ofile,"\tindlb(op_%s,l,n);\n",s); + fprint(ofile,"\tdfa(op_%s);\n",s); + } + else { + fprint(ofile,"\tFLUSHDFA();\n"); + fprint(ofile,"\tO_%s_dlb(l,n);\n",s); + } + fprint(ofile,"}\n",s); + break; + } + } +} diff --git a/modules/src/em_opt/outputdfa.c b/modules/src/em_opt/outputdfa.c new file mode 100644 index 00000000..e8eff2a1 --- /dev/null +++ b/modules/src/em_opt/outputdfa.c @@ -0,0 +1,392 @@ +#ifndef NORCSID +static char rcsid[] = "$Header$"; +#endif + +#include "parser.h" +#include "Lpars.h" + +File *ofile; + +outputnopt() +{ + if(!sys_open("dfa.c",OP_WRITE,&ofile)) { + fprint(STDERR,"Couldn't open dfa.c for output\n"); + sys_stop(S_EXIT); + } + outputheaders(); + outputtables(); + outputdfa(); + outputdodefault(); + outputdotrans(); + outputincalls(); +} + +PRIVATE +outputheaders() +{ + fprint(ofile,"#include \"nopt.h\"\n"); + fprint(ofile,"\n"); +} + +PRIVATE +outputtables() +{ + int s; + fprint(ofile,"struct defact {\n"); + fprint(ofile,"\tint numoutput;\n"); + fprint(ofile,"\tint numcopy;\n"); + fprint(ofile,"\tint nextstate;\n"); + fprint(ofile,"} defaultactions[] = {\n"); + for(s=0;s<=higheststate;s++) { + findfail(s); + if(s%4==3) + fprint(ofile,"\n"); + } + fprint(ofile,"};\n"); + fprint(ofile,"\n"); +} + +PRIVATE +outputdfa() +{ + int s; + struct idf *op; + struct state *p; + fprint(ofile,"int state = 0;\n"); + fprint(ofile,"\n"); + fprint(ofile,"dfa(last) int last; {\n"); + fprint(ofile,"\twhile(last) {\n"); + fprint(ofile,"\t\tswitch(last) {\n"); + for(op=ops;op!=(struct idf *)NULL;op=op->id_nextidf) { + if(!op->id_used) + continue; + fprint(ofile,"\t\tcase op_%s:\n",op->id_text); + fprint(ofile,"\t\t\tswitch(state) {\n"); + if(!op->id_startpatt) { + fprint(ofile,"\t\t\tcase 0: "); + fprint(ofile,"output(*--nextpatt); "); + fprint(ofile,"break;\n"); + } + for(s=0;s<=higheststate;s++) + for(p=states[s];p!=(struct state *)NULL;p=p->next) { + if(p->op==op) { + fprint(ofile,"\t\t\tcase %d: ",s); + if(actions[p->goto_state]==(struct action *)NULL) + fprint(ofile,"state = %d; ",p->goto_state); + else fprint(ofile,"dotrans(%d); ",p->goto_state); + fprint(ofile,"break;\n"); + } + } + fprint(ofile,"\t\t\tdefault: defaultaction(); break;\n"); + fprint(ofile,"\t\t\t}\n"); + fprint(ofile,"\t\t\tbreak;\n"); + } + fprint(ofile,"\t\tdefault:\n"); + fprint(ofile,"\t\t\tif(state) defaultaction();\n"); + fprint(ofile,"\t\t\telse {\n"); + fprint(ofile,"\t\t\t\tflush();\n"); + fprint(ofile,"\t\t\t\tmkcalls(*--nextpatt);\n"); + fprint(ofile,"\t\t\t\tmyfree(*nextpatt);\n"); + fprint(ofile,"\t\t\t}\n"); + fprint(ofile,"\t\t\tbreak;\n"); + fprint(ofile,"\t\tcase OTHER:\n"); + fprint(ofile,"\t\t\tif(state) defaultaction();\n"); + fprint(ofile,"\t\t\telse {\n"); + fprint(ofile,"\t\t\t\tflush();\n"); + fprint(ofile,"\t\t\t\tmyfree(*--nextpatt);\n"); + fprint(ofile,"\t\t\t}\n"); + fprint(ofile,"\t\t\tbreak;\n"); + fprint(ofile,"\t\t}\n"); + fprint(ofile,"\tlast = nextem();\n"); + fprint(ofile,"\t}\n"); + fprint(ofile,"}\n"); +} + +PRIVATE +outputmnems(l,state) + struct mnems l; + int state; +{ + int i; + for(i=1;i<=l.m_len;i++) + fprint(ofile,"%s ",l.m_elems[i-1]->op_code->id_text); +} + +PRIVATE +outputdotrans() +{ + int s; + struct state *p; + struct action *a; + int seennontested; + if(!sys_open("trans.c",OP_WRITE,&ofile)) { + fprint(STDERR,"Fatal Error: cannot open output file trans.c\n"); + sys_stop(S_EXIT); + } + fprint(ofile,"#include \"nopt.h\"\n\n"); + fprint(ofile,"\ndotrans(s) int s; {\n"); + fprint(ofile,"\tswitch(state=s) {\n"); + fprint(ofile,"\tdefault: return;\n"); + for(s=0;s<=higheststate;s++) + if(actions[s]!=(struct action *)NULL) { + fprint(ofile,"\tcase %d: /*",s); + outputmnems(patterns[s],s); + fprint(ofile," */\n"); + seennontested=0; + for(a=actions[s];a!=(struct action *)NULL;a=a->next) { + if(a->test!=(struct exp_node *)NULL) { + fprint(ofile,"\t\tif("); + outputexp(a->test,s); + /* + /*fprint(ofile,"dotest(%d)",a->linenum); + */ + fprint(ofile,") {\n"); + /* + /*fprint(ofile,"\t\t\tdoaction(%d);\n",a->linenum); + */ + outputoneaction(s,a); + fprint(ofile,"\t\t\tnfree(%d);\n",patterns[s].m_len); + fprint(ofile,"\t\t\tstate=0;\n"); + fprint(ofile,"\t\t\tbreak;\n"); + fprint(ofile,"\t\t}\n"); + } + else { + if(seennontested) { + fprint(STDERR,"parser: more than one untested action on state %d\n",s); + nerrors++; + } + seennontested++; + /* + /*fprint(ofile,"\t\t\tdoaction(%d);\n",a->linenum); + */ + outputoneaction(s,a); + fprint(ofile,"\t\tnfree(%d);\n",patterns[s].m_len); + fprint(ofile,"\t\tstate=0;\n"); + fprint(ofile,"\t\tbreak;\n"); + } + } + fprint(ofile,"\t\tbreak;\n"); + } + fprint(ofile,"\t}\n"); + fprint(ofile,"}\n"); + fprint(ofile,"\n"); +} + +PRIVATE +outputdodefault() +{ + fprint(ofile,"\nstatic defaultaction() {\n"); + fprint(ofile,"\tregister struct defact *p = &defaultactions[state];\n"); + fprint(ofile,"\tpushback(*--nextpatt);\n"); + fprint(ofile,"\tdodefault(p->numoutput,p->numcopy);\n"); + fprint(ofile,"\tdotrans(p->nextstate);\n"); + fprint(ofile,"}\n"); +} + +PRIVATE +outputoneaction(s,a) + int s; + struct action *a; +{ + fprint(ofile,"\t\t/* "); + fprint(ofile," -> "); + outputmnems(a->replacement,s); + fprint(ofile," */\n"); + outputrepl(s,patterns[s],a->replacement); + findworst(s,a->replacement); +} + +PRIVATE +outputrepl(state,patt,repl) + int state; + struct mnems patt,repl; +{ + /* + /* Contruct =r1 r2 ... rn and put on output queue. + */ + int n = repl.m_len; + int m = patt.m_len; + int i,j,count; + for(i=1;i<=n;i++) { + struct mnem_elem *ri = repl.m_elems[i-1]; + char *mnem = ri->op_code->id_text; + switch(ri->op_code->id_argfmt) { + case NOARG: + fprint(ofile,"\t\toutop(op_%s);\n",mnem); + break; + case CST: + case CSTOPT: + fprint(ofile,"\t\toutcst(op_%s,",mnem); + outputexp(ri->arg,state); + fprint(ofile,");\n"); + break; + case LAB: + fprint(ofile,"\t\toutlab(op_%s,",mnem); + outputexp(ri->arg,state); + fprint(ofile,");\n"); + break; + case DEFILB: + fprint(ofile,"\t\toutdefilb(op_%s,",mnem); + outputexp(ri->arg,state); + fprint(ofile,");\n"); + break; + case PNAM: + fprint(ofile,"\t\toutpnam(op_%s,",mnem); + outputexp(ri->arg,state); + fprint(ofile,");\n"); + break; + case EXT: + fprint(ofile,"\t\toutext(op_%s,",mnem); + outputexp(ri->arg,state); + fprint(ofile,");\n"); + break; + } + } +} + +PRIVATE +outputexp(e,state) + struct exp_node *e; + int state; +{ + switch(e->node_type) { + case LOGAND: + case LOGOR: + case BITAND: + case BITOR: + case XOR: + case MINUS: + case PLUS: + case TIMES: + case DIV: + case MOD: + case EQ: + case NE: + case LT: + case LE: + case GT: + case GE: + case LSHIFT: + case RSHIFT: + fprint(ofile,"("); + outputexp(e->exp_left,state); + outputop(e->node_type); + outputexp(e->exp_right,state); + fprint(ofile,")"); + break; + case NOT: + case COMP: + case UPLUS: + case UMINUS: + fprint(ofile,"("); + outputop(e->node_type); + outputexp(e->exp_left,state); + fprint(ofile,")"); + break; + case DEFINED: + fprint(ofile,"(patternqueue[%d]->argtype!=none_ptyp)",e->leaf_val-1); + break; + case UNDEFINED: + fprint(ofile,"(patternqueue[%d]->argtype==none_ptyp)",e->leaf_val-1); + break; + case COMMA: + outext(e->exp_left); + fprint(ofile,","); outputexp(e->exp_right,state); + break; + case SAMESIGN: + case SFIT: + case UFIT: + case ROTATE: + outputop(e->node_type); + outputexp(e->exp_left,state); + fprint(ofile,","); + outputexp(e->exp_right,state); + fprint(ofile,")"); + break; + case SAMEEXT: + case SAMENAM: + outputop(e->node_type); + outext(e->exp_left); + fprint(ofile,","); + outext(e->exp_right,state); + fprint(ofile,")"); + break; + case PATARG: + switch(patterns[state].m_elems[e->leaf_val-1]->op_code->id_argfmt) { + case NOARG: + fprint(STDERR,"error: mnem %d has no argument\n",e->leaf_val); + nerrors++; + break; + case CST: + case CSTOPT: + fprint(ofile,"CST(patternqueue[%d])",e->leaf_val-1); + break; + case LAB: + fprint(ofile,"LAB(patternqueue[%d])",e->leaf_val-1); + break; + case DEFILB: + fprint(ofile,"DEFILB(patternqueue[%d])",e->leaf_val-1); + break; + case PNAM: + fprint(ofile,"PNAM(patternqueue[%d])",e->leaf_val-1); + break; + case EXT: + fprint(ofile,"offset(patternqueue[%d])",e->leaf_val-1); + break; + } + break; + case PSIZE: + fprint(ofile,"PSIZE"); break; + case WSIZE: + fprint(ofile,"WSIZE"); break; + case INT: + fprint(ofile,"%d",e->leaf_val); break; + } +} + +PRIVATE +outext(e) + struct exp_node *e; +{ + if(e->node_type!=PATARG) { + fprint(STDERR,"Internal error in outext of parser\n"); + nerrors++; + } + fprint(ofile,"patternqueue[%d]",e->leaf_val-1); +} + +PRIVATE +outputop(op) + int op; +{ + switch(op) { + case LOGAND: fprint(ofile,"&&"); break; + case LOGOR: fprint(ofile,"||"); break; + case BITAND: fprint(ofile,"&"); break; + case BITOR: fprint(ofile,"|"); break; + case XOR: fprint(ofile,"^"); break; + case MINUS: fprint(ofile,"-"); break; + case PLUS: fprint(ofile,"+"); break; + case TIMES: fprint(ofile,"*"); break; + case DIV: fprint(ofile,"/"); break; + case MOD: fprint(ofile,"%%"); break; + case EQ: fprint(ofile,"=="); break; + case NE: fprint(ofile,"!="); break; + case LT: fprint(ofile,"<"); break; + case LE: fprint(ofile,"<="); break; + case GT: fprint(ofile,">"); break; + case GE: fprint(ofile,">="); break; + case LSHIFT: fprint(ofile,"<<"); break; + case RSHIFT: fprint(ofile,">>"); break; + case NOT: fprint(ofile,"!"); break; + case COMP: fprint(ofile,"~"); break; + case UPLUS: fprint(ofile,"+"); break; + case UMINUS: fprint(ofile,"-"); break; + case SAMESIGN: fprint(ofile,"samesign("); break; + case SFIT: fprint(ofile,"sfit("); break; + case UFIT: fprint(ofile,"ufit("); break; + case ROTATE: fprint(ofile,"rotate("); break; + case SAMEEXT: fprint(ofile,"sameext("); break; + case SAMENAM: fprint(ofile,"samenam("); break; + } +} diff --git a/modules/src/em_opt/parser.g b/modules/src/em_opt/parser.g new file mode 100644 index 00000000..8573236c --- /dev/null +++ b/modules/src/em_opt/parser.g @@ -0,0 +1,496 @@ +/* $Header$ */ +/* Parser to read optimization patterns of the form: + op1 op2 ... test : action + or + op1 op2 ... : action + and build a program to recognize then */ + +%token SFIT, UFIT, ROTATE, PSIZE, WSIZE, DEFINED, UNDEFINED, SAMESIGN; +%token SAMEEXT, SAMENAM, OFFSET, LOGAND, LOGOR, BITAND, BITOR, XOR; +%token MINUS, PLUS, TIMES, DIV, MOD, EQ, NE, LT, LE, GT, GE, NOT, COMP; +%token LSHIFT, RSHIFT, COMMA, OPCODE, INT, UPLUS, UMINUS, PATARG; + +%start parser, input; + +{ +#include "parser.h" + +#define MAXPRIO 11 + +struct state *states[MAXSTATES]; +struct action *actions[MAXSTATES]; +struct mnems patterns[MAXSTATES]; +int higheststate = 0; /* Highest state yet allocated */ +struct idf *ops; /* Chained list of all ops */ +int longestpattern = 0; +int nerrors = 0; + +static int lencurrpatt; +static int lenthisrepl; +static int currentstate; /* Current state of dfa */ +} + +input : /* empty */ + | optimization input + ; + +optimization + { + int startline; + struct exp_node *restrictions; + struct exp_node *finaltest; + struct mnem_list *repllist; + } + : + { + startline=linenum; currentstate=0; + lencurrpatt=0; lenthisrepl=0; + } + patterns(&restrictions) + { finaltest = (struct exp_node *)NULL; } + [ + '?' + exp(1,&finaltest) + ]? + ':' + action(&repllist) + { + addaction(startline,currentstate,restrictions, + finaltest,repllist); + } + '\n' + ; + +patterns(struct exp_node **tests;) + { struct mnem_list *list; + struct exp_node *pair1, *pair2; + struct exp_node *onetest; int argtype; } + : + { + list = (struct mnem_list *)NULL; + *tests = (struct exp_node *)NULL; + } + [ + OPCODE + { + if(++lencurrpatt>longestpattern) + longestpattern=lencurrpatt; + list = addelem(list,opval, (struct exp_node *)NULL); + opval->id_used=1; + if(lencurrpatt==1) + opval->id_startpatt=1; + currentstate=dotransition(currentstate,opval,list,lencurrpatt); + } + [ + restriction(opval->id_argfmt,&onetest) + { + *tests = combinetests(*tests,onetest); + } + ]? + ]+ + ; + +restriction(int argtype; struct exp_node **test;) + { + struct exp_node *test1,*test2; + int relop; + int offsetop; + } + : + [ %if(argtype==CSTOPT) + [ optrelop(&relop) exp(1,test) + { + *test = mknode(relop,mkleaf(PATARG,lencurrpatt),*test); + *test = mknode(LOGAND, + mkleaf(DEFINED,lencurrpatt), + *test); + } + | DEFINED + { + *test = mkleaf(DEFINED,lencurrpatt); + } + | UNDEFINED + { + *test = mkleaf(UNDEFINED,lencurrpatt); + } + ] + | %if(argtype==EXT) + patarg(&test1) + { + *test=mknode(SAMEEXT, + mkleaf(PATARG,lencurrpatt), + test1); + } + [ + [ PLUS + { offsetop = PLUS; } + | MINUS + { offsetop = MINUS; } + ] + exp(1,&test2) + { + test2 = mknode(offsetop, test1, test2); + test2 = mknode(EQ, mkleaf(PATARG,lencurrpatt), test2); + *test = combinetests( + mknode(SAMENAM, + mkleaf(PATARG,lencurrpatt), + test1), + test2); + } + ]? + | + optrelop(&relop) exp(1,test) + { + *test = mknode(relop,mkleaf(PATARG,lencurrpatt),*test); + } + ] + ; + +optrelop(int *op;) + : + {*op = EQ;} + [ EQ {*op = EQ;} + | NE {*op = NE;} + | LT {*op = LT;} + | LE {*op = LE;} + | GT {*op = GT;} + | GE {*op = GE;} + ]? + ; +action(struct mnem_list **list;) + { + struct exp_node *test, *test2; + struct idf *keepopval; + int offsetop; + } + : + { *list = (struct mnem_list *)NULL; } + [ + OPCODE + { + lenthisrepl++; + test= (struct exp_node *)NULL; + keepopval = opval; + } + [ %if(keepopval->id_argfmt==EXT) + patarg(&test) + { + test2 = test; + } + [ + [ PLUS + { offsetop = PLUS; } + | MINUS + { offsetop = MINUS; } + ] + exp(1,&test2) + { + test2 = mknode(offsetop,test,test2); + } + + ]? + { + test = mknode(COMMA,test,test2); + } + | exp(1,&test) + ]? + { + *list = addelem(*list,keepopval,test); + } + ]* + ; + +exp(int level; struct exp_node **result;) + { struct exp_node *res1, *res2; + int operator, intval; } + : + %if(level <= MAXPRIO) + exp(MAXPRIO+1,&res1) + [ %while (priority(LLsymb) >= level) + binop + { + operator=LLsymb; + } + exp(priority(operator)+1,&res2) + { + res1 = mknode(operator,res1,res2); + } + ]* + { + *result = res1; + } + | '(' exp(1,result) ')' + | unaryop(&operator) exp(priority(operator)+1,&res1) + { + *result = mknode(operator,res1,(struct exp_node *)NULL); + } + | SAMESIGN '(' exp(1,&res1) COMMA exp(1,&res2) ')' + { + *result = mknode(SAMESIGN,res1,res2); + } + | SFIT '(' exp(1,&res1) COMMA exp(1,&res2) ')' + { + *result = mknode(SFIT,res1,res2); + } + | UFIT '(' exp(1,&res1) COMMA exp(1,&res2) ')' + { + *result = mknode(UFIT,res1,res2); + } + | ROTATE '(' exp(1,&res1) COMMA exp(1,&res2) ')' + { + *result = mknode(ROTATE,res1,res2); + } + | SAMEEXT '(' patarg(&res1) COMMA patarg(&res2) ')' + { + *result = mknode(SAMEEXT,res1,res2); + } + | SAMENAM '(' patarg(&res1) COMMA patarg(&res2) ')' + { + *result = mknode(SAMENAM,res1,res2); + } + | OFFSET '(' patarg(&res1) ')' + { + *result = res1; + } + | patarg(result) + | PSIZE + { + *result = mkleaf(PSIZE,0); + } + | WSIZE + { + *result = mkleaf(WSIZE,0); + } + | INT + { + *result = mkleaf(INT,lastintval); + } + ; + +patarg(struct exp_node **result;) + { int intval; } + : PATARG argno(&intval) + { + *result = mkleaf(PATARG,intval); + } + ; + +argno(int *val;) + : INT + { + *val = lastintval; + if(lastintval<0 || (lastintval>lencurrpatt)) { + fprint(STDERR ,"Illegal $%d on line %d\n", + lastintval,linenum); + nerrors++; + } + } + ; + +unaryop(int *operator;) + : PLUS { *operator = UPLUS; } + | MINUS { *operator = UMINUS; } + | NOT { *operator = NOT; } + | COMP { *operator = COMP; } + ; + +binop : LOGAND + | LOGOR + | BITAND + | BITOR + | XOR + | MINUS + | PLUS + | TIMES + | DIV + | MOD + | EQ + | NE + | LT + | LE + | GT + | GE + | LSHIFT + | RSHIFT + ; + +%lexical yylex; + +{ +addaction(startline, state, restrictions, finaltest, repllist) + int startline; + int state; + struct exp_node *restrictions, *finaltest; + struct mnem_list *repllist; +{ + struct action *p, *q; + p=(struct action *)Malloc(sizeof(struct action)); + p->next = (struct action *)NULL; + p->linenum = startline; + p->test = combinetests(restrictions,finaltest); + p->replacement.m_len = lenthisrepl; + p->replacement.m_elems = constructlist(repllist,lenthisrepl); + /* chain new action to END of action chain */ + if((q = actions[currentstate])==(struct action *)NULL) + actions[currentstate] = p; + else { + while(q->next != (struct action *)NULL) + q = q->next; + q->next = p; + } +} + +struct mnem_elem ** +constructlist(list,len) + struct mnem_list *list; + int len; +{ + struct mnem_elem **p; + int i; + p = (struct mnem_elem **)Malloc(len*sizeof(struct mnem_elem *)); + while(len--) { + p[len] = list->elem; + list = list->next; + } + return(p); +} + +struct mnem_list * +addelem(oldlist, mnem, test) + struct mnem_list *oldlist; + struct idf *mnem; + struct exp_node *test; +{ + struct mnem_list *reslist; + struct mnem_elem *element; + element = (struct mnem_elem *)Malloc(sizeof(struct mnem_elem)); + element->op_code = mnem; + element->arg = test; + reslist = (struct mnem_list *)Malloc(sizeof(struct mnem_list)); + reslist->elem = element; + reslist->next = oldlist; + return(reslist); +} + +int +dotransition(state, mnem, mnem_list, lenlist) + int state; + struct idf *mnem; + struct mnem_list *mnem_list; + int lenlist; +{ + struct state *p; + /* look for existing transition */ + for(p=states[state]; + (p!=((struct state *)NULL)) && ((p->op)!=mnem); + p = p->next + ); + if(p==(struct state *)NULL) { + /* none found so add a new state to dfa */ + p=(struct state *)Malloc(sizeof(struct state)); + p->op=mnem; + if(++higheststate>MAXSTATES) { + fprint("Parser: More than %s states\n",MAXSTATES); + sys_stop(S_EXIT); + } + p->goto_state= higheststate; + p->next=states[currentstate]; + states[currentstate]=p; + states[higheststate] = (struct state *)NULL; + actions[higheststate] = (struct action *)NULL; + patterns[higheststate].m_len = lencurrpatt; + patterns[higheststate].m_elems = + constructlist(mnem_list,lenlist); + return(higheststate); + } + else return(p->goto_state); /* already exists */ +} + +struct exp_node * +combinetests(test1, test2) + struct exp_node *test1, *test2; +{ + if(test1==(struct exp_node *)NULL) + return(test2); + else if(test2==(struct exp_node *)NULL) + return(test1); + else + return(mknode(LOGAND,test1,test2)); +} + +priority(op) int op; { + switch (op) { + case LOGOR: return(1); + case LOGAND: return(2); + case BITOR: return(3); + case XOR: return(4); + case BITAND: return(5); + case EQ: + case NE: return(6); + case LT: + case LE: + case GT: + case GE: return(7); + case LSHIFT: + case RSHIFT: return(8); + case MINUS: + case PLUS: return(9); + case TIMES: + case DIV: + case MOD: return(10); + case NOT: + case COMP: + case UPLUS: + case UMINUS: return(11); + } +} + +struct exp_node * +mknode(op,left,right) + int op; + struct exp_node *left,*right; +{ + struct exp_node *p; + p = (struct exp_node *)Malloc(sizeof(struct exp_node)); + p->node_type = op; + p->exp_left = left; + p->exp_right = right; + return(p); +} + +struct exp_node * +mkleaf(op,val) + int op,val; +{ + struct exp_node *p; + p = (struct exp_node *)Malloc(sizeof(struct exp_node)); + p->node_type = op; + p->leaf_val = val; + return(p); +} + +LLmessage(insertedtok) + int insertedtok; +{ + nerrors++; + fprint(STDERR,"parser: syntax error on line %d: ",linenum); + if(insertedtok) { + fprint(STDERR,"Inserted token %d\n",insertedtok); + yyless(0); + } + else fprint(STDERR,"Deleted token %d\n",LLsymb); +} + +main() { + initlex(); + states[0] = (struct state *)NULL; + patterns[0].m_len = 0; + parser(); + if(nerrors) { + fprint(STDERR,"%d errors detected\n",nerrors); + sys_stop(S_EXIT); + } + outputnopt(); + sys_stop(S_END); +} +} diff --git a/modules/src/em_opt/parser.h b/modules/src/em_opt/parser.h new file mode 100644 index 00000000..6df6ef32 --- /dev/null +++ b/modules/src/em_opt/parser.h @@ -0,0 +1,96 @@ +/* $Header$ */ +#include + +#define NULL 0 + +/* type of arguments expected by each instruction */ +#define NOARG 1 +#define CST 2 +#define CSTOPT 3 +#define LAB 4 +#define DEFILB 5 +#define PNAM 6 +#define EXT 7 + +#define IDF_TYPE struct id_info +struct id_info { + struct idf *nextidf; /* chain all opcodes together */ + int used; /* is this op used? */ + int startpatt; /* does it start a pattern? */ + int opcode; /* opcode of operator */ + int argfmt; /* how to access pattern argument */ +#define id_nextidf id_user.nextidf +#define id_used id_user.used +#define id_startpatt id_user.startpatt +#define id_opcode id_user.opcode +#define id_argfmt id_user.argfmt +}; +#include + +struct exp_node { + int node_type; + union { + struct { + struct exp_node *left; + struct exp_node *right; + } interior; + int val; + } node_args; +#define exp_left node_args.interior.left +#define exp_right node_args.interior.right +#define leaf_val node_args.val +}; + +struct mnem_elem { + struct idf *op_code; + struct exp_node *arg; /* optional arg expression if replacement */ +}; + +struct mnem_list { + struct mnem_list *next; /* cdr of list */ + struct mnem_elem *elem; /* car of list */ +}; + +struct mnems { + int m_len; /* number of mnem's in pattern */ + struct mnem_elem **m_elems; /* array of mnem's */ +}; + +struct action { + struct action *next; /* chain all actions for same state together */ + int linenum; /* line number in patterns */ + struct exp_node *test; /* test expression (if any) */ + struct mnems replacement; /* replacement pattern */ +}; + +struct state { + struct state *next; /* chain to next entry for this state */ + struct idf *op; /* transition on op to.. */ + int goto_state; /* state 'goto_state' */ +}; + +#define MAXSTATES 2000 +#define MAXPATTERN 20 + +/* Parser globals */ +extern struct state *states[MAXSTATES]; +extern struct action *actions[MAXSTATES]; +extern struct mnems patterns[MAXSTATES]; +extern int higheststate; /* Highest state yet allocated */ +extern struct idf *ops; /* Chained list of all ops */ +extern int longestpattern; +extern int nerrors; +extern File *ofile; + +/* Lexical analyser globals */ +extern struct idf *opval; /* opcode of returned OPCODE*/ +extern int lastintval; /* value of last integer seen */ +extern int linenum; /*line number of input file*/ + +/* Functions not returning int */ +char *Malloc(); +struct exp_node *mknode(); +struct exp_node *mkleaf(); +struct exp_node *combinetests(); +struct mnem_list *addelem(); +struct mnem_elem **constructlist(); diff --git a/modules/src/em_opt/patterns b/modules/src/em_opt/patterns new file mode 100644 index 00000000..c2f62f81 --- /dev/null +++ b/modules/src/em_opt/patterns @@ -0,0 +1,569 @@ +/* $Header$ */ +loc adi w loc sbi w : loc $1-$3 adi w +inc dec: +inc loc adi w : loc $2+1 adi w +inc loc sbi w : loc $2-1 sbi w +dec loc adi w : loc $2-1 adi w +dec loc sbi w : loc $2+1 sbi w +ldc adi 2*w ldc sbi 2*w : ldc $1-$3 adi 2*w +loc adi w loc adi w : loc $1+$3 adi w +ldc adi 2*w ldc adi 2*w : ldc $1+$3 adi 2*w +loc adi w loc mli w : loc $3 mli w loc $1*$3 adi w +loc adi w loc 1 sli w : loc $3 sli w loc 2*$1 adi w +adp 0 : +adp adp : adp $1+$2 +adp lof : lof $1+$2 +adp ldf : ldf $1+$2 +adp !=0 loi w : lof $1 +adp !=0 loi 2*w : ldf $1 +adp stf : stf $1+$2 +adp sdf : sdf $1+$2 +adp !=0 sti w : stf $1 +adp !=0 sti 2*w : sdf $1 +asp 0 : +asp asp : asp $1+$2 +blm 0 : asp 2*p +cmi w zeq : beq $2 +cmi w zge : bge $2 +cmi w zgt : bgt $2 +cmi w zle : ble $2 +cmi w zlt : blt $2 +cmi w zne : bne $2 +cmu w zeq : beq $2 +cmu w zne : bne $2 +dvi ngi $1 : ngi $1 dvi $1 +lae adp : lae $1+$2 +lae blm w : loi w ste $1 +lae blm 2*w : loi 2*w sde $1 +lae ldf : lde $1+$2 +lae lof : loe $1+$2 +lae loi w : loe $1 +lae loi 2*w : lde $1 +#ifdef INT +lae loi loe $1-w ? $2%w==0: lae $3 loi $2+w +lae loi lde $1-2*w ? $2%w==0: lae $3 loi $2+2*w +lae $3+$4 loi lae loi ? $2%w==0 && $4%w==0: lae $3 loi $2+$4 +lae sti ste $1+$2 : lae $1 sti $2+w +lae sti sde $1+$2 : lae $1 sti $2+2*w +lae sti loc ste $1-w : loc $3 lae $4 sti $2+w +lae sti lol ste $1-w : lol $3 lae $4 sti $2+w +#endif +lae lae blm loe $1+$3 ste $2+$3 : lae $1 lae $2 blm $3+w +lae lae blm lde $1+$3 sde $2+$3 : lae $1 lae $2 blm $3+2*w +lae lae blm lae $1+$3 lae $2+$3 blm : lae $1 lae $2 blm $3+$6 +lae lal blm lae $1+$3 lal $2+$3 blm ? samesign($2,$5): + lae $1 lal $2 blm $3+$6 +lal lae blm lal $1+$3 lae $2+$3 blm ? samesign($1,$4): + lal $1 lae $2 blm $3+$6 +lal lal blm lal $1+$3 lal $2+$3 blm ? samesign($1,$4) && samesign($2,$5): + lal $1 lal $2 blm $3+$6 +lal lal sbs w ? samesign($1,$2): loc $1-$2 +lae sdf : sde $1+$2 +lae stf : ste $1+$2 +lae sti w : ste $1 +lae sti 2*w : sde $1 +lal adp ? samesign($1,$1+$2): lal $1+$2 +lal blm w : loi w stl $1 +lal blm 2*w : loi 2*w sdl $1 +#ifdef INT +/*lal sti loc stl $1-w ? notreg($4) && samesign($1,$4): */ +/* loc $3 lal $4 sti $2+w */ +/*lal sti loe stl $1-w ? notreg($4) && samesign($1,$4): */ +/* loe $3 lal $4 sti $2+w */ +#endif +lal ldf ? samesign($1,$1+$2): ldl $1+$2 +lal lof ? samesign($1,$1+$2): lol $1+$2 +lal loi w : lol $1 +lal loi 2*w : ldl $1 +#ifdef INT +/*lal loi lol $1-w ? notreg($3) && samesign($1,$3) && $2%w==0: */ +/* lal $3 loi $2+w */ +/*lal loi ldl $1-2*w ? notreg($3) && samesign($1,$3) && $2%w==0: */ +/* lal $3 loi $2+2*w */ +lal loi lal loi $1-$3 ? samesign($1,$3) && $2%w==0 && $4%w==0: + lal $3 loi $2+$4 +/*lal sti stl $1+$2 ? notreg($3) && samesign($1,$3): lal $1 sti $2+w */ +/*lal sti sdl $1+$2 ? notreg($3) && samesign($1,$3): lal $1 sti $2+2*w*/ +#endif +lal sdf ? samesign($1,$1+$2): sdl $1+$2 +lal stf ? samesign($1,$1+$2): stl $1+$2 +lal sti w : stl $1 +lal sti 2*w : sdl $1 +#ifdef INT +lde lde $1-2*w : lae $2 loi 4*w +lde loe $1-w : lae $2 loi 3*w +#endif +lde sde $1 : +lde sde lde $1+2*w sde $2+2*w : lae $1 lae $2 blm 4*w +#ifdef INT +/*ldl ldl $1-2*w ? notreg($1) && notreg($2) && samesign($1,$2):*/ +/* lal $2 loi 4*w */ +/*ldl lol $1-w ? notreg($1) && notreg($2) && samesign($1,$2): */ +/* lal $2 loi 3*w */ +#endif +ldl sdl $1: +lxa loi lxa $1 sti $2 : +lxa lof lxa $1 stf $2 : +lxa ldf lxa $1 sdf $2 : +lxa >1 stf lxa $1 lof $2 : dup w lxa $1 stf $2 +lxa >1 sdf lxa $1 ldf $2 : dup 2*w lxa $1 sdf $2 +lxl lof lxl $1 stf $2 : +lxl ldf lxl $1 sdf $2 : +lxl >1 stf lxl $1 lof $2 : dup w lxl $1 stf $2 +lxl >1 sdf lxl $1 ldf $2 : dup 2*w lxl $1 sdf $2 +lxa >1 sti lxa $1 loi $2 ? $2%w==0: dup $2 lxa $1 sti $2 +loc -1 adi w : dec +loc dec ? sfit($1-1,8*w) : loc $1-1 +loc -1 bgt : zge $2 +loc -1 ble : zlt $2 +loc -1 dvi w : ngi w +ldc -1 dvi 2*w : ngi 2*w +loc -1 loe adi w : loe $2 dec +loc -1 lol adi w : lol $2 dec +loc -1 mli w : ngi w +ldc -1 mli 2*w : ngi 2*w +loc -1 sbi w : inc +loc inc ? sfit($1+1,8*w) : loc $1+1 +loc 0 adi w : +ldc 0 adi 2*w : +loc 0 ads w : +ldc 0 ads 2*w : +zer adi $1 : +loc 0 beq : zeq $2 +loc 0 bge : zge $2 +loc 0 bgt : zgt $2 +loc 0 ble : zle $2 +loc 0 blt : zlt $2 +loc 0 bne : zne $2 +loc 0 cmi w teq : teq +loc 0 cmi w tge : tge +loc 0 cmi w tgt : tgt +loc 0 cmi w tle : tle +loc 0 cmi w tlt : tlt +loc 0 cmi w tne : tne +loc 0 cmu w teq : teq +loc 0 cmu w tne : tne +loc 0 cmu w zeq : zeq $3 +loc 0 cmu w zne : zne $3 +loc 0 ior w : +ldc 0 ior 2*w : +zer ior $1 : +loc 0 ste : zre $2 +loc 0 stl : zrl $2 +loc 0 sbi w : +ldc 0 sbi 2*w : +zer sbi $1 : +loc 0 xor w : +ldc 0 xor 2*w : +zer xor $1 : +loc 1 adi w : inc +loc 1 bge : zgt $2 +loc 1 blt : zle $2 +loc 1 dvi w : +ldc 1 dvi 2*w : +loc 1 dvu w : +loc 1 dvu 2*w : +loc 1 loe adi w : loe $2 inc +loc 1 lol adi w : lol $2 inc +loc 0 mli w : asp w loc 0 +ldc 0 mli 2*w : asp 2*w ldc 0 +loc 0 mlu w : asp w loc 0 +ldc 0 mlu 2*w : asp 2*w ldc 0 +loc 1 mli w : +ldc 1 mli 2*w : +loc 1 mlu w : +ldc 1 mlu 2*w : +loc 1 sbi w : dec +loc loe mli w : loe $2 loc $1 mli w +loc loe adi w loc : loe $2 loc $1 adi w loc $4 +loc loe adi w inc : loe $2 loc $1 adi w inc +loc loe adi w dec : loe $2 loc $1 adi w dec +loc lol mli w : lol $2 loc $1 mli w +loc lol adi w loc : lol $2 loc $1 adi w loc $4 +loc lol adi w inc : lol $2 loc $1 adi w dec +loc lol adi w dec : lol $2 loc $1 adi w dec +ldc lde mli 2*w : lde $2 ldc $1 mli 2*w +ldc lde adi 2*w : lde $2 ldc $1 adi 2*w +ldc ldl mli 2*w : ldl $2 ldc $1 mli 2*w +ldc ldl adi 2*w : ldl $2 ldc $1 adi 2*w +loc 2 mli w : loc 1 sli w +loc 4 mli w : loc 2 sli w +loc 8 mli w : loc 3 sli w +loc 16 mli w : loc 4 sli w +loc 32 mli w : loc 5 sli w +loc 64 mli w : loc 6 sli w +loc 128 mli w : loc 7 sli w +loc 256 mli w : loc 8 sli w +loc 2 mlu w : loc 1 slu w +loc 4 mlu w : loc 2 slu w +loc 8 mlu w : loc 3 slu w +loc 16 mlu w : loc 4 slu w +loc 32 mlu w : loc 5 slu w +loc 64 mlu w : loc 6 slu w +loc 128 mlu w : loc 7 slu w +loc 256 mlu w : loc 8 slu w +loc adi undefined : adi $1 +loc sbi undefined : sbi $1 +loc mli undefined : mli $1 +loc dvi undefined : dvi $1 +loc rmi undefined : rmi $1 +loc ngi undefined : ngi $1 +loc sli undefined : sli $1 +loc sri undefined : sri $1 +loc adu undefined : adu $1 +loc sbu undefined : sbu $1 +loc mlu undefined : mlu $1 +loc dvu undefined : dvu $1 +loc rmu undefined : rmu $1 +loc slu undefined : slu $1 +loc sru undefined : sru $1 +loc adf undefined : adf $1 +loc sbf undefined : sbf $1 +loc mlf undefined : mlf $1 +loc dvf undefined : dvf $1 +loc ngf undefined : ngf $1 +loc fif undefined : fif $1 +loc fef undefined : fef $1 +loc zer undefined : zer $1 +loc zrf undefined : zrf $1 +loc los w : loi $1 +loc sts w : sti $1 +loc ads w : adp $1 +ldc ads 2*w ? sfit($1,8*w): adp $1 +loc ass w : asp $1 +loc bls w : blm $1 +loc dus w : dup $1 +loc loc $1 cii : +loc loc $1 cuu : +loc loc $1 cff : +loc and undefined : and $1 +loc ior undefined : ior $1 +loc xor undefined : xor $1 +loc com undefined : com $1 +loc rol undefined : rol $1 +loc 0 rol : +loc ror undefined : ror $1 +loc 0 ror : +loc inn undefined : inn $1 +loc set undefined : set $1 +loc cmi undefined : cmi $1 +loc cmu undefined : cmu $1 +loc cmf undefined : cmf $1 +loe dec ste $1: dee $1 +loe inc ste $1: ine $1 +loe loc 0 mli w : loc 0 +#ifdef INT +loe loe $1-w : lde $2 +loe loe $1+w beq : lde $1 beq $3 +loe loe $1+w bge : lde $1 ble $3 +loe loe $1+w bgt : lde $1 blt $3 +loe loe $1+w ble : lde $1 bge $3 +loe loe $1+w blt : lde $1 bgt $3 +loe loe $1+w bne : lde $1 bne $3 +loe loe $1+w cmi w : lde $1 cmi w ngi w +#endif +ngi w teq : teq +ngi w tge : tle +ngi w tgt : tlt +ngi w tle : tge +ngi w tlt : tgt +ngi w tne : tne +#ifdef INT +loe loe $1+w mli w : lde $1 mli w +loe loe $1+w adi w : lde $1 adi w +loe loe $1 : loe $1 dup w +#endif +loe ste $1 : +lol blm w ? p==w : loi w sil $1 +ldl blm w ? p==2*w : loi w sil $1 +lol dec stl $1 : del $1 +lol inc stl $1 : inl $1 +lol loc 0 mli w : loc 0 +lol loi w ? w==p : lil $1 +ldl loi w ? p==2*w : lil $1 +#ifdef INT +/*lol lol $1-w ? notreg($1) && notreg($2) && samesign($1,$2): */ +/* ldl $2 */ +/*lol lol $1+w beq ? notreg($1) && notreg($2) && samesign($1,$2): */ +/* ldl $1 beq $3 */ +/*lol lol $1+w bge ? notreg($1) && notreg($2) && samesign($1,$2): */ +/* ldl $1 ble $3 */ +/*lol lol $1+w bgt ? notreg($1) && notreg($2) && samesign($1,$2): */ +/* ldl $1 blt $3 */ +/*lol lol $1+w ble ? notreg($1) && notreg($2) && samesign($1,$2): */ +/* ldl $1 bge $3 */ +/*lol lol $1+w blt ? notreg($1) && notreg($2) && samesign($1,$2): */ +/* ldl $1 bgt $3 */ +/*lol lol $1+w bne ? notreg($1) && notreg($2) && samesign($1,$2): */ +/* ldl $1 bne $3 */ +/*lol lol $1+w cmi w ? notreg($1) && notreg($2) && samesign($1,$2): */ +/* ldl $1 cmi w ngi w */ +/*lol lol $1+w mli w ? notreg($1) && notreg($2) && samesign($1,$2): */ +/* ldl $1 mli w */ +/*lol lol $1+w adi w ? notreg($1) && notreg($2) && samesign($1,$2): */ +/* ldl $1 adi w */ +lol lol $1 : lol $1 dup w +#endif +lol stl $1: +lol sti w ? p==w : sil $1 +ldl sti w ? p==2*w : sil $1 +mli ngi $1: ngi $1 mli $1 +ngi adi $1: sbi $1 +ngf adf $1: sbf $1 +ngi sbi $1: adi $1 +ngf sbf $1: adf $1 +ngi ngi $1: +ngf ngf $1: +#ifdef INT +sde sde $1+2*w : lae $1 sti 4*w +sde ste $1+2*w : lae $1 sti 3*w +sde loc ste $1-w : loc $2 lae $3 sti 3*w +sde lol ste $1-w : lol $2 lae $3 sti 3*w +sde lde $1 : dup 2*w sde $1 +#endif +sdf 0 : sti 2*w +#ifdef INT +/*sdl sdl $1+2*w ? notreg($1) && notreg($2) && samesign($1,$2): */ +/* lal $1 sti 4*w */ +/*sdl stl $1+2*w ? notreg($1) && notreg($2) && samesign($1,$2): */ +/* lal $1 sti 3*w */ +/*sdl loc stl $1-w ? notreg($1) && notreg($3) && samesign($1,$3): */ +/* loc $2 lal $3 sti 3*w */ +/*sdl loe stl $1-w ? notreg($1) && notreg($3) && samesign($1,$3): */ +/* loe $2 lal $3 sti 3*w */ +sdl ldl $1 : dup 2*w sdl $1 +ste loe $1 : dup w ste $1 +ste ste $1-w : sde $2 +ste loc ste $1-w : loc $2 sde $3 +ste lol ste $1-w : lol $2 sde $3 +stl lol $1 : dup w stl $1 +#endif +stf 0 : sti w +sdl ldl $1 ret 2*w : ret 2*w +#ifdef INT +/*stl stl $1+w ? notreg($1) && notreg($2) && samesign($1,$2): sdl $1 */ +/*stl loc stl $1-w ? notreg($1) && notreg($3) && samesign($1,$3): */ +/* loc $2 sdl $3 */ +/*stl loe stl $1-w ? notreg($1) && notreg($3) && samesign($1,$3): */ +/* loe $2 sdl $3 */ +#endif +stl lol $1 ret w : ret w +lal sti lal $1 loi $2 ret $2 : ret $2 +loc sbi w loc sbi w : loc $1+$3 sbi w +ldc sbi 2*w ldc sbi 2*w : ldc $1+$3 sbi 2*w +loc sbi w loc adi w : loc $1-$3 sbi w +ldc sbi 2*w ldc adi 2*w : ldc $1-$3 sbi 2*w +loc sbi w loc mli w : loc $3 mli w loc $1*$3 sbi w +loc sbi w loc 1 sli w : loc $3 sli w loc 2*$1 sbi w +teq teq : tne +teq tne : teq +teq zne : zeq $2 +teq zeq : zne $2 +tge teq : tlt +tge tne : tge +tge zeq : zlt $2 +tge zne : zge $2 +tgt teq : tle +tgt tne : tgt +tgt zeq : zle $2 +tgt zne : zgt $2 +tle teq : tgt +tle tne : tle +tle zeq : zgt $2 +tle zne : zle $2 +tlt teq : tge +tlt tne : tlt +tlt zeq : zge $2 +tlt zne : zlt $2 +tne teq : teq +tne tne : tne +tne zeq : zeq $2 +tne zne : zne $2 +#ifdef INT +loc 0 loc 0 loc 0 : zer 3*w +zer defined loc 0 : zer $1+w +#endif +loi 1 loc and w ? ($2&255)==255: loi 1 +loi =0&&$5<128 : loi 1 loc $5 cmi w zeq $7 +loi 1 loc 1 loc w cii loc cmi w zne ? $5>=0&&$5<128 : loi 1 loc $5 cmi w zne $7 +loi 1 loc 1 loc w cii loc w loc w ciu loc 255 and w: loi 1 +cmp teq : cms p teq +cmp tne : cms p tne +cmu defined teq : cms $1 teq +cmu defined tne : cms $1 tne +cms w zeq : beq $2 +cms w zne : bne $2 +lol lae aar w adp : adp $4 lol $1 lae $2 aar w +loe lae aar w adp : adp $4 loe $1 lae $2 aar w +cmi defined zeq : cms $1 zeq $2 +cmi defined zne : cms $1 zne $2 +#ifdef INT +loe $4 inc dup w ste : ine $1 loe $1 +loe $4 dec dup w ste : dee $1 loe $1 +lol $4 inc dup w stl : inl $1 lol $1 +lol $4 dec dup w stl : del $1 lol $1 +adp dup p ste adp -$1 ? p==w : dup p adp $1 ste $3 +adp dup p sde adp -$1 ? p==2*w : dup p adp $1 sde $3 +adp dup p stl adp -$1 ? p==w : dup p adp $1 stl $3 +adp dup p sdl adp -$1 ? p==2*w : dup p adp $1 sdl $3 +inc dup w ste dec : dup w inc ste $3 +inc dup w stl dec : dup w inc stl $3 +#endif +zeq bra lab $1 : zne $2 lab $1 +zge bra lab $1: zlt $2 lab $1 +zgt bra lab $1 : zle $2 lab $1 +zlt bra lab $1 : zge $2 lab $1 +zle bra lab $1 : zgt $2 lab $1 +zne bra lab $1 : zeq $2 lab $1 +beq bra lab $1 : bne $2 lab $1 +bge bra lab $1 : blt $2 lab $1 +bgt bra lab $1 : ble $2 lab $1 +blt bra lab $1 : bge $2 lab $1 +ble bra lab $1 : bgt $2 lab $1 +bne bra lab $1 : beq $2 lab $1 +lin lin : lin $2 +lin lab lin : lab $2 lin $3 +lin ret : ret $2 +lin bra : bra $2 +#ifdef INT +dup p stl loi w ? p==w : stl $2 lil $2 +dup p sdl loi w ? p==2*w : sdl $2 lil $2 +dup p stl sti w ? p==w : stl $2 sil $2 +dup p sdl sti w ? p==2*w : sdl $2 sil $2 +#endif +loc 0 cms w : tne +zer w : loc 0 +loc loc adi w ? sfit($1+$2,8*w) : loc $1+$2 +loc loc sbi w ? sfit($1-$2,8*w) : loc $1-$2 +loc loc mli w ? sfit($1*$2,8*w) : loc $1*$2 +loc loc !=0 dvi w : loc $1/$2 +loc loc and w : loc $1&$2 +loc loc ior w : loc $1|$2 +loc 0 loc 0 ior 2*w : +loc loc xor w : loc $1^$2 +loc 0 loc 0 xor 2*w : +loc loc rol w : loc rotate($1,$2) +loc loc ror w : loc rotate($1,8*w-$2) +loc ngi w ? sfit(-$1,8*w) : loc -$1 +loc com w : loc ~$1 +ldc ngi 2*w : ldc -$1 +/*loc lae aar w ? $1>=rom(2,0) && $1 <= rom(2,0)+rom(2,1) : */ +/* adp ($1-rom(2,0))*rom(2,2) */ +/*loc lae lar w ? $1>=rom(2,0) && $1 <= rom(2,0)+rom(2,1) : */ +/* adp ($1-rom(2,0))*rom(2,2) loi rom(2,2) */ +/*loc lae sar w ? $1>=rom(2,0) && $1 <= rom(2,0)+rom(2,1) : */ +/* adp ($1-rom(2,0))*rom(2,2) sti rom(2,2) */ +loc teq : loc $1==0 +loc tne : loc $1!=0 +loc tge : loc $1>=0 +loc tle : loc $1<=0 +loc tgt : loc $1>0 +loc tlt : loc $1<0 +loc 0 zeq : bra $2 +loc zeq : +loc !=0 zne : bra $2 +loc zne : +loc >=0 zge : bra $2 +loc zge : +loc <=0 zle : bra $2 +loc zle : +loc >0 zgt : bra $2 +loc zgt : +loc <0 zlt : bra $2 +loc zlt : +loc loc $1 beq : bra $3 +loc loc beq : +loc loc !=$1 bne : bra $3 +loc loc bne : +loc loc bge ? $1>=$2 : bra $3 +loc loc bge : +loc loc ble ? $1<=$2 : bra $3 +loc loc ble : +loc loc bgt ? $1>$2 : bra $3 +loc loc bgt : +loc loc blt ? $1<$2 : bra $3 +loc loc blt : +lae loi >4*w lal sti $2 : lae $1 lal $3 blm $2 +lal loi >4*w lae sti $2 : lal $1 lae $3 blm $2 +lal loi >4*w lal sti $2 ? ( $3<=$1-$2 || $3>=$1+$2 ) : + lal $1 lal $3 blm $2 +lae loi >4*w lae sti $2 ? ($3<=$1-$2 || $3>=$1+$2) : + lae $1 lae $3 blm $2 +loc 0 loc w loc cif : zrf $3 +loc >=0 loc w loc 2*w ciu : ldc $1 +loc loc w loc 2*w cii : ldc $1 +loi loc >=0 inn $1 ? $2<$1*8 : + lof ($2/(8*w))*w loc $2&(8*w-1) inn w +ldl loc >=0 inn 2*w ? $2<16*w : + lol $1+($2/(8*w))*w loc $2&(8*w-1) inn w +lde loc >=0 inn 2*w ? $2<16*w : + loe $1+($2/(8*w))*w loc $2&(8*w-1) inn w +ldf loc >=0 inn 2*w ? $2<16*w : + lof $1+($2/(8*w))*w loc $2&(8*w-1) inn w +loc inn ? $1<0 || $1>=8*$2 : asp $2 loc 0 +lol loc adi w stl $1 : loc $2 lol $1 adi w stl $4 +lol loe adi w stl $1 : loe $2 lol $1 adi w stl $4 +lol lol !=$1 adi w stl $1 : lol $2 lol $1 adi w stl $4 +loe loc adi w ste $1 : loc $2 loe $1 adi w ste $4 +loe loe !=$1 adi w ste $1 : loe $2 loe $1 adi w ste $4 +loe lol adi w ste $1 : lol $2 loe $1 adi w ste $4 +lol loc ior w stl $1 : loc $2 lol $1 ior w stl $4 +lol loe ior w stl $1 : loe $2 lol $1 ior w stl $4 +lol lol !=$1 ior w stl $1 : lol $2 lol $1 ior w stl $4 +loe loc ior w ste $1 : loc $2 loe $1 ior w ste $4 +loe loe !=$1 ior w ste $1 : loe $2 loe $1 ior w ste $4 +loe lol ior w ste $1 : lol $2 loe $1 ior w ste $4 +lol loc and w stl $1 : loc $2 lol $1 and w stl $4 +lol loe and w stl $1 : loe $2 lol $1 and w stl $4 +lol lol !=$1 and w stl $1 : lol $2 lol $1 and w stl $4 +loe loc and w ste $1 : loc $2 loe $1 and w ste $4 +loe loe !=$1 and w ste $1 : loe $2 loe $1 and w ste $4 +loe lol and w ste $1 : lol $2 loe $1 and w ste $4 +loi asp $1 : asp p +lal loi 4*w loc loc loc loc ior 4*w ? ($3==0)+($4==0)+($5==0)+($6==0)>2 : + lol $1+3*w loc $3 ior w lol $1+2*w loc $4 ior w lol $1+w loc $5 ior w lol $1 loc $6 ior w +loc dup 2 stl loc dup 2 stl : + loc $1 stl $3 loc $4 stl $6 loc $1 loc $4 +/*LLP LLP adp SLP $2 sti ? (!notreg($2) || $5!=p): */ +/* LLP $1 sti $5 LLP $2 adp $3 SLP $4 */ +loe loe adp ste $2 sti !=p ? p==w : loe $1 sti $5 loe $2 adp $3 ste $4 +lde lde adp sde $2 sti !=p ? p==2*w : lde $1 sti $5 lde $2 adp $3 sde $4 +#ifndef INT +dup w stl : stl $2 lol $2 +dup w ste : ste $2 loe $2 +dup w sil : sil $2 lil $2 +dup w loe sti w ? p==w : loe $2 sti w loe $2 loi w +dup w lde sti w ? p==2*w : lde $2 sti w lde $2 loi w +dup w lol stf ? p==w : lol $2 stf $3 lol $2 lof $3 +dup w ldl stf ? p==2*w : ldl $2 stf $3 ldl $2 lof $3 +dup w loe stf ? p==w : loe $2 stf $3 loe $2 lof $3 +dup w lde stf ? p==2*w : lde $2 stf $3 lde $2 lof $3 +dup 2*w sdl : sdl $2 ldl $2 +dup 2*w sde : sde $2 lde $2 +dup 2*w lol sti 2*w ? p==w : lol $2 sti 2*w lol $2 loi 2*w +dup 2*w ldl sti 2*w ? p==2*w : ldl $2 sti 2*w ldl $2 loi 2*w +dup 2*w loe sti 2*w ? p==w : loe $2 sti 2*w loe $2 loi 2*w +dup 2*w lde sti 2*w ? p==2*w : lde $2 sti 2*w lde $2 loi 2*w +dup 2*w lol sdf ? p==w : lol $2 sdf $3 lol $2 ldf $3 +dup 2*w ldl sdf ? p==2*w : ldl $2 sdf $3 ldl $2 ldf $3 +dup 2*w loe sdf ? p==w : loe $2 sdf $3 loe $2 ldf $3 +dup 2*w lde sdf ? p==2*w : lde $2 sdf $3 lde $2 ldf $3 +lol dup w : lol $1 lol $1 +loe dup w : loe $1 loe $1 +lil dup w : lil $1 lil $1 +loe loi w dup 2 ? p==w : loe $1 loi w loe $1 loi w +lde loi w dup 2 ? p==2*w : lde $1 loi w lde $1 loi w +ldl dup 2*w : ldl $1 ldl $1 +lde dup 2*w : lde $1 lde $1 +#endif +adp stl lol $2 adp -$1 ? p==w : dup p adp $1 stl $2 +adp sdl ldl $2 adp -$1 ? p==2*w : dup p adp $1 sdl $2 +adp ste loe $2 adp -$1 ? p==w : dup p adp $1 ste $2 +adp sde lde $2 adp -$1 ? p==2*w : dup p adp $1 sde $2 +adp sil lil $2 adp -$1 ? p==w : dup p adp $1 sil $2 +adp lol sti p lol $2 loi p adp -$1 ? p==w : dup p adp $1 lol $2 sti p +adp ldl sti p ldl $2 loi p adp -$1 ? p==2*w : dup p adp $1 ldl $2 sti p +adp loe sti p loe $2 loi p adp -$1 ? p==w : dup p adp $1 loe $2 sti p +adp lde sti p lde $2 loi p adp -$1 ? p==2*w : dup p adp $1 lde $2 sti p diff --git a/modules/src/em_opt/pseudo.r b/modules/src/em_opt/pseudo.r new file mode 100644 index 00000000..5e4d6099 --- /dev/null +++ b/modules/src/em_opt/pseudo.r @@ -0,0 +1,471 @@ +#ifndef NORCSID +static char rcsid[] = "$Header$"; +#endif + +#include "nopt.h" + +C_df_dlb(l) + label l; +{ + FLUSHDFA(); + O_df_dlb(l); +} + +C_df_dnam(s) + char * s; +{ + FLUSHDFA(); + O_df_dnam(s); +} + +C_pro(s,l) + char * s; + arith l; +{ + FLUSHDFA(); + O_pro(s,l); +} + +C_pro_narg(s) + char * s; +{ + FLUSHDFA(); + O_pro_narg(s); +} + +C_end(l) + arith l; +{ + FLUSHDFA(); + O_end(l); +} + +C_end_narg() +{ + FLUSHDFA(); + O_end_narg(); +} + +C_exa_dnam(s) + char * s; +{ + FLUSHDFA(); + O_exa_dnam(s); +} + +C_exa_dlb(l) + label l; +{ + FLUSHDFA(); + O_exa_dlb(l); +} + +C_exp(s) + char * s; +{ + FLUSHDFA(); + O_exp(s); +} + +C_ina_dnam(s) + char * s; +{ + FLUSHDFA(); + O_ina_dnam(s); +} + +C_ina_dlb(l) + label l; +{ + FLUSHDFA(); + O_ina_dlb(l); +} + +C_inp(s) + char * s; +{ + FLUSHDFA(); + O_inp(s); +} + +C_bss_cst(n,w,i) + arith n; + arith w; + int i; +{ + FLUSHDFA(); + O_bss_cst(n,w,i); +} + +C_bss_icon(n,s,sz,i) + arith n; + char * s; + arith sz; + int i; +{ + FLUSHDFA(); + O_bss_icon(n,s,sz,i); +} + +C_bss_ucon(n,s,sz,i) + arith n; + char * s; + arith sz; + int i; +{ + FLUSHDFA(); + O_bss_ucon(n,s,sz,i); +} + +C_bss_fcon(n,s,sz,i) + arith n; + char * s; + arith sz; + int i; +{ + FLUSHDFA(); + O_bss_fcon(n,s,sz,i); +} + +C_bss_dnam(n,s,offs,i) + arith n; + char * s; + arith offs; + int i; +{ + FLUSHDFA(); + O_bss_dnam(n,s,offs,i); +} + +C_bss_dlb(n,l,offs,i) + arith n; + label l; + arith offs; + int i; +{ + FLUSHDFA(); + O_bss_dlb(n,l,offs,i); +} + +C_bss_ilb(n,l,i) + arith n; + label l; + int i; +{ + FLUSHDFA(); + O_bss_ilb(n,l,i); +} + +C_bss_pnam(n,s,i) + arith n; + char * s; + int i; +{ + FLUSHDFA(); + O_bss_pnam(n,s,i); +} + +C_hol_cst(n,w,i) + arith n; + arith w; + int i; +{ + FLUSHDFA(); + O_hol_cst(n,w,i); +} + +C_hol_icon(n,s,sz,i) + arith n; + char * s; + arith sz; + int i; +{ + FLUSHDFA(); + O_hol_icon(n,s,sz,i); +} + +C_hol_ucon(n,s,sz,i) + arith n; + char * s; + arith sz; + int i; +{ + FLUSHDFA(); + O_hol_ucon(n,s,sz,i); +} + +C_hol_fcon(n,s,sz,i) + arith n; + char * s; + arith sz; + int i; +{ + FLUSHDFA(); + O_hol_fcon(n,s,sz,i); +} + +C_hol_dnam(n,s,offs,i) + arith n; + char * s; + arith offs; + int i; +{ + FLUSHDFA(); + O_hol_dnam(n,s,offs,i); +} + +C_hol_dlb(n,l,offs,i) + arith n; + label l; + arith offs; + int i; +{ + FLUSHDFA(); + O_hol_dlb(n,l,offs,i); +} + +C_hol_ilb(n,l,i) + arith n; + label l; + int i; +{ + FLUSHDFA(); + O_hol_ilb(n,l,i); +} + +C_hol_pnam(n,s,i) + arith n; + char * s; + int i; +{ + FLUSHDFA(); + O_hol_pnam(n,s,i); +} + +C_con_cst(l) + arith l; +{ + FLUSHDFA(); + O_con_cst(l); +} + +C_con_icon(val,siz) + char * val; + arith siz; +{ + FLUSHDFA(); + O_con_icon(val,siz); +} + +C_con_ucon(val,siz) + char * val; + arith siz; +{ + FLUSHDFA(); + O_con_ucon(val,siz); +} + +C_con_fcon(val,siz) + char * val; + arith siz; +{ + FLUSHDFA(); + O_con_fcon(val,siz); +} + +C_con_scon(str,siz) + char * str; + arith siz; +{ + FLUSHDFA(); + O_con_scon(str,siz); +} + +C_con_dnam(str,val) + char * str; + arith val; +{ + FLUSHDFA(); + O_con_dnam(str,val); +} + +C_con_dlb(l,val) + label l; + arith val; +{ + FLUSHDFA(); + O_con_dlb(l,val); +} + +C_con_ilb(l) + label l; +{ + FLUSHDFA(); + O_con_ilb(l); +} + +C_con_pnam(str) + char * str; +{ + FLUSHDFA(); + O_con_pnam(str); +} + +C_rom_cst(l) + arith l; +{ + FLUSHDFA(); + O_rom_cst(l); +} + +C_rom_icon(val,siz) + char * val; + arith siz; +{ + FLUSHDFA(); + O_rom_icon(val,siz); +} + +C_rom_ucon(val,siz) + char * val; + arith siz; +{ + FLUSHDFA(); + O_rom_ucon(val,siz); +} + +C_rom_fcon(val,siz) + char * val; + arith siz; +{ + FLUSHDFA(); + O_rom_fcon(val,siz); +} + +C_rom_scon(str,siz) + char * str; + arith siz; +{ + FLUSHDFA(); + O_rom_scon(str,siz); +} + +C_rom_dnam(str,val) + char * str; + arith val; +{ + FLUSHDFA(); + O_rom_dnam(str,val); +} + +C_rom_dlb(l,val) + label l; + arith val; +{ + FLUSHDFA(); + O_rom_dlb(l,val); +} + +C_rom_ilb(l) + label l; +{ + FLUSHDFA(); + O_rom_ilb(l); +} + +C_rom_pnam(str) + char * str; +{ + FLUSHDFA(); + O_rom_pnam(str); +} + +C_cst(l) + arith l; +{ + FLUSHDFA(); + O_cst(l); +} + +C_icon(val,siz) + char * val; + arith siz; +{ + FLUSHDFA(); + O_icon(val,siz); +} + +C_ucon(val,siz) + char * val; + arith siz; +{ + FLUSHDFA(); + O_ucon(val,siz); +} + +C_fcon(val,siz) + char * val; + arith siz; +{ + FLUSHDFA(); + O_fcon(val,siz); +} + +C_scon(str,siz) + char * str; + arith siz; +{ + FLUSHDFA(); + O_scon(str,siz); +} + +C_dnam(str,val) + char * str; + arith val; +{ + FLUSHDFA(); + O_dnam(str,val); +} + +C_dlb(l,val) + label l; + arith val; +{ + FLUSHDFA(); + O_dlb(l,val); +} + +C_ilb(l) + label l; +{ + FLUSHDFA(); + O_ilb(l); +} + +C_pnam(str) + char * str; +{ + FLUSHDFA(); + O_pnam(str); +} + +C_mes_begin(ms) + int ms; +{ + FLUSHDFA(); + O_mes_begin(ms); +} + +C_mes_end() +{ + FLUSHDFA(); + O_mes_end(); +} + +C_exc(c1,c2) + arith c1; + arith c2; +{ + FLUSHDFA(); + O_exc(c1,c2); +} diff --git a/modules/src/em_opt/syntax.l b/modules/src/em_opt/syntax.l new file mode 100644 index 00000000..be7dcbce --- /dev/null +++ b/modules/src/em_opt/syntax.l @@ -0,0 +1,59 @@ +%{ +/* $Header$ */ +#include "Lpars.h" +#include "parser.h" + +struct idf *opval; /* opcode of returned OPCODE*/ +int lastintval; /* value of last integer seen */ +int linenum = 1; /*current line number of input file*/ +%} +%% +sfit return(SFIT); +ufit return(UFIT); +rotate return(ROTATE); +p return(PSIZE); +w return(WSIZE); +defined return(DEFINED); +undefined return(UNDEFINED); +samesign return(SAMESIGN); +sameext return(SAMEEXT); +samenam return(SAMENAM); +offset return(OFFSET); +[a-z]* { + opval = str2idf(yytext,0); + return(OPCODE); + } +[0-9]+ { + lastintval = atoi(yytext); + return(INT); + } +"$" return(PATARG); +"&&" return(LOGAND); +"||" return(LOGOR); +"&" return(BITAND); +"|" return(BITOR); +"^" return(XOR); +"-" return(MINUS); +"+" return(PLUS); +"*" return(TIMES); +"/" return(DIV); +"%" return(MOD); +"==" return(EQ); +"!=" return(NE); +"<" return(LT); +"<=" return(LE); +">" return(GT); +">=" return(GE); +"<<" return(LSHIFT); +">>" return(RSHIFT); +"!" return(NOT); +"~" return(COMP); +"," return(COMMA); +:[ \t]*\n[ \t]+ { linenum++; return(':'); } +^"# "[0-9]+.*\n { linenum=atoi(yytext+2); } +^\#.*\n { linenum++; } +^\n { linenum++; } +[ \t] ; +\n { linenum++; return(yytext[0]);} +. return(yytext[0]); +%% From 30820da804a94e7943f81a9cb2f27d1a58570df1 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 15 Jan 1987 22:06:16 +0000 Subject: [PATCH 0492/1625] Using object library --- util/amisc/anm.c | 105 +++++++++++------------------ util/amisc/asize.c | 61 +++-------------- util/amisc/astrip.c | 156 ++++++++++++-------------------------------- 3 files changed, 88 insertions(+), 234 deletions(-) diff --git a/util/amisc/anm.c b/util/amisc/anm.c index da5dfc4f..44cb43ff 100644 --- a/util/amisc/anm.c +++ b/util/amisc/anm.c @@ -1,6 +1,3 @@ -#define DUK /* Modifications by Duk Bekema. */ - -/* @(#)anm.c 1.4 */ /* $Header$ */ /* ** print symbol tables for @@ -8,7 +5,6 @@ ** ** anm [-gopruns] [name ...] */ -#define ushort unsigned short #include "out.h" @@ -23,13 +19,14 @@ int globl_flg; int nosort_flg; int arch_flg; int prep_flg; +int read_error; struct outhead hbuf; struct outsect sbuf; -FILE *fi; long off; char *malloc(); char *realloc(); long s_base[S_MAX]; /* for specially encoded bases */ +char *filename; main(argc, argv) char **argv; @@ -89,16 +86,21 @@ char **argv; unsigned readcount; int i,j; - fi = fopen(*++argv,"r"); - if (fi == NULL) { + read_error = 0; + if (! rd_open(*++argv)) { fprintf(stderr, "anm: cannot open %s\n", *argv); continue; } - getofmt((char *)&hbuf, SF_HEAD, fi); + filename = *argv; + rd_ohead(&hbuf); + if (read_error) { + rd_close(); + continue; + } if (BADMAGIC(hbuf)) { - fprintf(stderr, "anm: %s-- bad format\n", *argv); - fclose(fi); + fprintf(stderr, "anm: %s -- bad format\n", *argv); + rd_close(); continue; } if (narg > 1) @@ -106,14 +108,14 @@ char **argv; n = hbuf.oh_nname; if (n == 0) { - fprintf(stderr, "anm: %s-- no name list\n", *argv); - fclose(fi); + fprintf(stderr, "anm: %s -- no name list\n", *argv); + rd_close(); continue; } if (hbuf.oh_nchar == 0) { - fprintf(stderr, "anm: %s-- no names\n", *argv); - fclose(fi); + fprintf(stderr, "anm: %s -- no names\n", *argv); + rd_close(); continue; } if ((readcount = hbuf.oh_nchar) != hbuf.oh_nchar) { @@ -121,10 +123,14 @@ char **argv; exit(2); } - /* store special section bases */ + /* store special section bases ??? */ if (hbuf.oh_flags & HF_8086) { + rd_sect(&sbuf, hbuf.oh_nsect); + if (read_error) { + rd_close(); + continue; + } for (i=0; i>12) & 03777760; } @@ -134,17 +140,20 @@ char **argv; fprintf(stderr, "anm: out of memory on %s\n", *argv); exit(2); } - fseek(fi, OFF_CHAR(hbuf), 0); - if (fread(cbufp, 1, readcount, fi) == 0) { - fprintf(stderr, "anm: read error on %s\n", *argv); - exit(2); + rd_string(cbufp, hbuf.oh_nchar); + if (read_error) { + free(cbufp); + rd_close(); + continue; } - fi_to_co = cbufp - OFF_CHAR(hbuf); - fseek(fi, OFF_NAME(hbuf), 0); + fi_to_co = (long) (cbufp - OFF_CHAR(hbuf)); i = 0; while (--n >= 0) { - getofmt((char *)&nbuf, SF_NAME, fi); + rd_name(&nbuf, 1); + if (read_error) { + break; + } if (nbuf.on_foff == 0) continue; /* skip entries without names */ @@ -157,7 +166,7 @@ char **argv; ((nbuf.on_type&S_TYP)!=S_UND || (nbuf.on_type&S_ETC)!=0)) continue; - nbuf.on_mptr = nbuf.on_foff + fi_to_co; + nbuf.on_mptr = (char *) (nbuf.on_foff + fi_to_co); /* adjust value for specially encoded bases */ if (hbuf.oh_flags & HF_8086) { @@ -180,7 +189,7 @@ char **argv; nbufp[i++] = nbuf; } - if (nosort_flg==0) + if (nbufp && nosort_flg==0) qsort(nbufp, i, sizeof(struct outname), compare); for (n=0; n #include "out.h" @@ -20,7 +16,6 @@ char **argv; ushort nrsect; long sum; int gorp; - FILE *f; if (--argc == 0) { argc = 1; @@ -29,20 +24,20 @@ char **argv; gorp = argc; while(argc--) { - if ((f = fopen(*++argv, "r"))==NULL) { + if (! rd_open(*++argv)) { fprintf(stderr, "asize: cannot open %s\n", *argv); continue; } - getofmt ((char *)&buf, SF_HEAD , f); + rd_ohead(&buf); if(BADMAGIC(buf)) { fprintf(stderr, "asize: %s-- bad format\n", *argv); - fclose(f); + rd_close(); continue; } nrsect = buf.oh_nsect; if (nrsect == 0) { fprintf(stderr, "asize: %s-- no sections\n", *argv); - fclose(f); + rd_close(); continue; } if (gorp > 1) @@ -50,57 +45,19 @@ char **argv; sum = 0; while (nrsect-- > 0) { - getofmt ((char *)&sbuf, SF_SECT , f); + rd_sect(&sbuf, 1); printf("%ld", sbuf.os_size); sum += sbuf.os_size; if (nrsect > 0) putchar('+'); } printf(" = %ld = 0x%lx\n", sum, sum); - fclose(f); + rd_close(); } } -getofmt(p, s, f) -register char *p; -register char *s; -register FILE *f; +rd_fatal() { - register i; - register long l; - - for (;;) { - switch (*s++) { -/* case '0': p++; continue; */ - case '1': - *p++ = getc(f); - continue; - case '2': - i = getc(f); - i |= (getc(f) << 8); -#ifndef DUK - *((short *)p)++ = i; -#else DUK - *((short *)p) = i; - p += sizeof(short); -#endif DUK - continue; - case '4': - l = (long)getc(f); - l |= (long)(getc(f) << 8); - l |= ((long)getc(f) << 16); - l |= ((long)getc(f) << 24); -#ifndef DUK - *((long *)p)++ = l; -#else DUK - *((long *)p) = l; - p += sizeof(long); -#endif DUK - continue; - default: - case '\0': - break; - } - break; - } + fprintf(stderr, "read error\n"); + exit(2); } diff --git a/util/amisc/astrip.c b/util/amisc/astrip.c index f2ebb915..962eaf47 100644 --- a/util/amisc/astrip.c +++ b/util/amisc/astrip.c @@ -1,8 +1,4 @@ -#define DUK /* Modifications by Duk Bekema. */ - -/* @(#)astrip.c 1.1 */ /* $Header$ */ -#define ushort unsigned short #include "out.h" #include @@ -19,6 +15,7 @@ char *mktemp(); FILE *fopen(); FILE *tf; struct outhead buf; +int readerror, writeerror; main(argc, argv) char **argv; @@ -41,16 +38,17 @@ strip(name) char *name; { long size; - FILE *f; - if ((f = fopen(name,"r")) == NULL) { + if (! rd_open(name)) { fprintf(stderr, "astrip: cannot open %s\n", name); return(1); } - getofmt ((char *)&buf, SF_HEAD , f); - if(BADMAGIC(buf)) { + readerror = 0; + writeerror = 0; + rd_ohead(&buf); + if(readerror || BADMAGIC(buf)) { fprintf(stderr, "astrip: %s-- bad format\n", name); - fclose(f); + rd_close(); return(1); } size = OFF_RELO(buf) - SZ_HEAD; @@ -60,62 +58,68 @@ char *name; buf.oh_nchar = 0; - if ((tf = fopen(tname,"w")) == NULL) { + if (! wr_open(tname)) { fprintf(stderr, "astrip: cannot create temp file %s\n", tname); - fclose(f); + rd_close(); return(2); } - fseek(tf, (long)0, 0); - putofmt((char *)&buf,SF_HEAD,tf,tname); - if(copy(name, tname, f, tf, size)) { - fclose(f); - fclose(tf); + wr_ohead(&buf); + if (writeerror) { + fprintf(stderr, "astrip: write error on temp file %s\n", tname); + rd_close(); + wr_close(); return(1); } - fclose(f); - fclose(tf); + if(copy(name, tname, size)) { + rd_close(); + wr_close(); + return(1); + } + rd_close(); + wr_close(); size += SZ_HEAD; - if ((f = fopen(name,"w")) == NULL) { + if (! wr_open(name)) { fprintf(stderr, "astrip: cannot write %s\n", name); return(1); } - if ((tf = fopen(tname,"r")) == NULL) { + if (! rd_open(tname)) { fprintf(stderr, "astrip: cannot read temp file %s\n", tname); - fclose(f); + wr_close(); return(2); } - fseek(tf, (long)0, 0); - if(copy(tname, name, tf, f, size)) { - fclose(f); - fclose(tf); + if(copy(tname, name, size)) { + wr_close(); + rd_close(); return(2); } - fclose(f); - fclose(tf); + wr_close(); + rd_close(); return(0); } -copy(fnam, tnam, fr, to, size) +copy(fnam, tnam, size) char *fnam; char *tnam; long size; -FILE *fr,*to; { register s, n; char lbuf[512]; + int fr, fw; + fr = rd_fd(); + fw = wr_fd(); while(size != (long)0) { s = 512; if(size < 512) s = (int) size; - n = fread(lbuf,1,s,fr); - if(n != s) { + rd_bytes(fr, lbuf, (long) s); + if (readerror) { fprintf(stderr, "astrip: unexpected eof on %s\n", fnam); return(1); } - n = fwrite(lbuf,1,s,to); - if(n != s) { + wr_bytes(fw, lbuf, (long) s); + if (writeerror) { fprintf(stderr, "astrip: write error on %s\n", tnam); return(1); } @@ -124,90 +128,12 @@ FILE *fr,*to; return(0); } -getofmt(p, s, f) -register char *p; -register char *s; -register FILE *f; +rd_fatal() { - register i; - register long l; - - for (;;) { - switch (*s++) { -/* case '0': p++; continue; */ - case '1': - *p++ = getc(f); - continue; - case '2': - i = getc(f); - i |= (getc(f) << 8); -#ifndef DUK - *((short *)p)++ = i; -#else DUK - *((short *)p) = i; - p += sizeof(short); -#endif DUK - continue; - case '4': - l = (long)getc(f); - l |= (long)(getc(f) << 8); - l |= ((long)getc(f) << 16); - l |= ((long)getc(f) << 24); -#ifndef DUK - *((long *)p)++ = l; -#else DUK - *((long *)p) = l; - p += sizeof(long); -#endif DUK - continue; - default: - case '\0': - break; - } - break; - } + readerror = 1; } -putofmt(p, s, f, fnam) -register char *p; -register char *s; -register FILE *f; -char *fnam; +wr_fatal() { - register i,j; - register long l; - - while (j = *s++) { - switch (j -= '0') { -/* case 0: p++; break; */ - case 1: - i = *p++; putc(i,f); - break; - case 2: -#ifndef DUK - i = *((short *)p)++; -#else DUK - i = *((short *)p); - p += sizeof(short); -#endif DUK - putc(i,f); - i>>=8; putc(i,f); - break; - case 4: -#ifndef DUK - l = *((long *)p)++; -#else DUK - l = *((long *)p); - p += sizeof(long); -#endif DUK - putc(l,f); - l >>=8; putc(l,f); - l >>=8; putc(l,f); - l >>=8; putc(l,f); - break; - default: - break; - } - if (ferror(f)) fprintf(stderr, "astrip: write error on %s\n", fnam); - } + writeerror = 1; } From 810eb7b0d6fb28069d45fde4896f671ac80b2d01 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 16 Jan 1987 13:51:42 +0000 Subject: [PATCH 0493/1625] Some bug fixes and minor extensions --- util/ncgg/Makefile | 18 ++++---- util/ncgg/cgg.y | 104 ++++++++++++++++++++++++++++++++++--------- util/ncgg/expr.c | 9 ++-- util/ncgg/instruct.c | 2 + util/ncgg/iocc.c | 22 ++++++++- util/ncgg/output.c | 13 +++--- util/ncgg/set.c | 9 ++++ util/ncgg/subr.c | 2 +- util/ncgg/var.c | 2 +- 9 files changed, 140 insertions(+), 41 deletions(-) diff --git a/util/ncgg/Makefile b/util/ncgg/Makefile index 9f40e92a..5732f4a4 100644 --- a/util/ncgg/Makefile +++ b/util/ncgg/Makefile @@ -3,23 +3,25 @@ CFILES=cgg.c subr.c main.c coerc.c enterkeyw.c error.c emlookup.c expr.c instruct.c iocc.c lookup.c output.c set.c strlookup.c var.c hall.c OFILES=cgg.o subr.o main.o coerc.o enterkeyw.o error.o emlookup.o expr.o instruct.o iocc.o lookup.o set.o strlookup.o var.o hall.o SOURCES=*.h cgg.y scan.l cvtkeywords keywords coerc.c emlookup.c error.c expr.c hall.c instruct.c iocc.c lookup.c main.c output.c set.c strlookup.c subr.c var.c -EMH=../../h -CFLAGS=-I$(EMH) +EMHOME=../.. +EMH=$(EMHOME)/h +CFLAGS=-O -I$(EMH) YFLAGS=-v -d LDFLAGS=-i cgg: cgg.o $(OFILES) output.o - cc $(LDFLAGS) $(OFILES) output.o ../../lib/em_data.a -ll -o cgg + cc $(LDFLAGS) $(OFILES) output.o $(EMHOME)/lib/em_data.a -ll -o cgg install: cgg - cp cgg ../../lib/ncgg + rm -f $(EMHOME)/lib/ncgg + cp cgg $(EMHOME)/lib/ncgg cmp: cgg - cmp cgg ../../lib/ncgg + cmp cgg $(EMHOME)/lib/ncgg debugcgg: cgg.o $(OFILES) debugoutput.o - cc $(LDFLAGS) $(OFILES) debugoutput.o ../../lib/em_data.a -ll -o cgg + cc $(LDFLAGS) $(OFILES) debugoutput.o $(EMHOME)/lib/em_data.a -ll -o cgg cgg.o: scan.c @@ -43,8 +45,8 @@ clean: pr: pr $(SOURCES) -lpr: - make pr|lpr +opr: + -make pr|opr depend: makedepend diff --git a/util/ncgg/cgg.y b/util/ncgg/cgg.y index 5bce1787..1edca621 100644 --- a/util/ncgg/cgg.y +++ b/util/ncgg/cgg.y @@ -18,6 +18,7 @@ extern int lineno; int instline,saveline; int startline; int npatterns; +int att_type; int patindex[MAXPATTERNS]; int emhere=0; /* lexical analyzer flag */ @@ -27,6 +28,9 @@ int saferulefound=0; int maxempatlen=0; int maxrule=0; struct varinfo *defcost; +int Xstackflag=0; /* set in coercions, moves, and tests. %1 means something + different then. + */ struct varinfo *gen_inst(),*gen_move(),*gen_test(),*gen_preturn(),*gen_tlab(); struct varinfo *make_erase(); @@ -35,7 +39,7 @@ expr_t perc_ident_expr(),sum_expr(),regvar_expr(); set_t ident_to_set(),setproduct(),setsum(),setdiff(); -iocc_t subr_iocc(),tokm_iocc(),ident_iocc(),all_iocc(),descr_iocc(); +iocc_t subr_iocc(),tokm_iocc(),ident_iocc(),all_iocc(),percident_iocc(), descr_iocc(); extern int narexpr; extern expr_t arexp[]; @@ -81,7 +85,7 @@ iocc_t iops[20]; %token TIMEFACTOR SIZEFACTOR %token COST %type prop_list property ident_list ident_list_el -%type att_list att_list_el structdecl optcost optformat +%type att_list att_list_el att_list_el_list structdecl optcost optformat %type kills allocates yields leaving %type generates kill_list kill_list_el uselist uselist_el genlist yieldlist %type leavelist leavelist_el gen_instruction @@ -300,10 +304,24 @@ att_list { $1->vi_next = $2; $$ = $1; } ; att_list_el - : att_list_el_type IDENT ';' - { NEW ($$,struct varinfo); - $$->vi_next = 0; - $$->vi_int[0] = $1; + : att_list_el_type IDENT + { NEW ($$,struct varinfo); + $$->vi_int[0] = $1; + $$->vi_str[0] = $2; + att_type = $1; + } + att_list_el_list ';' + { $3->vi_next = $4; + $$ = $3; + } + ; +att_list_el_list + : /* empty */ + { $$ = 0; } + | ',' IDENT att_list_el_list + { NEW($$, struct varinfo); + $$->vi_next = $3; + $$->vi_int[0] = att_type; $$->vi_str[0] = $2; } ; @@ -446,7 +464,8 @@ erase_list_el /* Now the moves */ moves - : MOVES movedeflist + : MOVES + movedeflist | /* empty */ ; movedeflist @@ -457,19 +476,30 @@ movedeflist_el : FROM {startline = lineno; } tokenset_no - { cursetno = $3; } - optexpr TO tokenset_no - { cursetno = $7; + { Xstackflag = 1; + cursetno = $3; + } + optexpr + { Xstackflag = 0; + cursetno = -1; + } + TO tokenset_no + { cursetno = $8; tokpatlen=2; tokpatset[0] = $3; - tokpatset[1] = $7; + tokpatset[1] = $8; tokpatro[0] = 1; + Xstackflag = 1; } - optexpr GEN genlist + optexpr + { Xstackflag = 0; + cursetno = -1; + } + GEN genlist { tokpatlen=0; tokpatro[0]=0; - n_move($3,$5,$7,$9,$11); - freevi($11); + n_move($3,$5,$8,$10,$13); + freevi($13); } | error ; @@ -477,7 +507,10 @@ movedeflist_el /* Now the test part */ tests - : TESTS testdeflist + : TESTS + { Xstackflag = 1; } + testdeflist + { Xstackflag = 0; } | /* empty */ ; testdeflist @@ -498,6 +531,7 @@ testdeflist_el tokpatro[0] = 0; n_test($4,$6,$8); freevi($8); + cursetno = -1; } | error ; @@ -505,7 +539,10 @@ testdeflist_el /* Now the stacks */ stacks - : STACKINGRULES stackdeflist + : STACKINGRULES + { Xstackflag = 1; } + stackdeflist + { Xstackflag = 0; } ; stackdeflist : stackdeflist_el @@ -524,6 +561,7 @@ stackdeflist_el { tokpatro[0] = 0; n_stack($3,$5,$8,$10); freevi($10); + cursetno = -1; } ; optuses @@ -536,7 +574,10 @@ optuses /* Now the one-to-one coercion rules */ coercs - : COERCIONS coercdeflist + : COERCIONS + { Xstackflag = 1; } + coercdeflist + { Xstackflag = 0; } ; coercdeflist : coercdeflist_el @@ -566,6 +607,7 @@ coercdeflist_el n_coerc($3,$5,$6,$7,$8); freevi($6); freevi($7); + cursetno = -1; } ; @@ -722,6 +764,7 @@ kill_list_el $$->vi_next = 0; $$->vi_int[0]=$1; $$->vi_int[1]=$3; + cursetno = -1; } ; allocates @@ -864,6 +907,13 @@ tokeninstance { $$ = ident_iocc($1); free($1);} | allreg subreg { $$ = all_iocc($1,$2); } + | PERC_IDENT + { if (cursetno < 0) { + error("%% not allowed here"); + } + $$ = percident_iocc($1); + free($1); + } | '{' IDENT attlist '}' { $$ = descr_iocc($2); free($2); } ; @@ -883,12 +933,12 @@ emarg ; tokarg : PERCENT - { if ($1<1 || $1>tokpatlen) { + { $$ = $1; + if ($1<1 || $1>tokpatlen) { error("Only %d tokens in stackpattern",tokpatlen); $$ =1; - } else { - $$ = $1; } + if (Xstackflag) $$ = 0; } ; subreg @@ -928,7 +978,12 @@ expr | allreg subreg { $$ = all_expr($1,$2); } | PERC_IDENT - { $$ = perc_ident_expr($1); free($1); } + { if (cursetno < 0) { + error("%% not allowed here"); + } + $$ = perc_ident_expr($1); + free($1); + } | DEFINED '(' expr ')' { $$ = make_expr(TYPBOOL,EX_DEFINED,i_expr($3),0); } | SAMESIGN '(' expr ',' expr ')' @@ -943,6 +998,13 @@ expr { $$ = make_expr(TYPINT,EX_LOWW,$3-1,0); } | HIGHW '(' emarg ')' { $$ = make_expr(TYPINT,EX_HIGHW,$3-1,0); } +/* Excluded, because it causes a shift-reduce conflict + (problems with a tokenset_no followed by an optexpr) + | '-' expr %prec UMINUS + { $$ = make_expr(TYPINT,EX_CON, 0, 0); + $$ = make_expr(TYPINT,EX_MINUS,i_expr($$),i_expr($2)); + } +*/ | '(' expr ')' { $$ = $2; } | expr CMPEQ expr diff --git a/util/ncgg/expr.c b/util/ncgg/expr.c index 77dd1a09..df3d48bd 100644 --- a/util/ncgg/expr.c +++ b/util/ncgg/expr.c @@ -68,7 +68,8 @@ expr_t subreg_expr(tokarg,subreg) { expr_t result; result.ex_typ = TYPREG; - subregset(l_sets[tokpatset[tokarg-1]].set_val,subreg,result.ex_regset); + subregset(l_sets[tokpatset[tokarg > 0 ? tokarg-1 : tokarg]].set_val, + subreg,result.ex_regset); result.ex_index = ex_lookup(EX_SUBREG,tokarg,subreg); return(result); } @@ -106,6 +107,7 @@ int *typp; int typesdiffer=0; int res_j= -1; + if (setno < 0) return 0; sp = l_sets[setno].set_val; for (i=1;i 0 ? tokarg : 1; - sprintf(app,"%%%d.%s",tokarg,name); - return(memb_expr(tokpatset[tokarg-1],name,app,tokarg)); + sprintf(app,"%%%d.%s",tokarg1,name); + return(memb_expr(tokpatset[tokarg1-1],name,app,tokarg)); } expr_t perc_ident_expr(name) char *name; { diff --git a/util/ncgg/instruct.c b/util/ncgg/instruct.c index d0997461..62b2c466 100644 --- a/util/ncgg/instruct.c +++ b/util/ncgg/instruct.c @@ -55,6 +55,7 @@ onlyreg(argno) { register bitno; register short *sp; + if (! argno) argno++; sp = l_sets[tokpatset[argno-1]].set_val; for(bitno=nregs;bitno1 Coercions",ncoercs,MAXCOERCS); used("Splitting coercions",nsplit,MAXSPLCOERC); used("Register variables",maxregvars,MAXREGVAR); - used("Pat bytes",npatbytes,MAXPATBYTES); + used("Pat bytes",npatbytes+1,MAXPATBYTES); if (tabledebug) used("Source lines",maxline,MAXSOURCELINES); fprintf(stderr,"%ldK heap used\n",((long) (sbrk(0)-end+1023))/1024); diff --git a/util/ncgg/set.c b/util/ncgg/set.c index 54e3f1f1..6234ac0e 100644 --- a/util/ncgg/set.c +++ b/util/ncgg/set.c @@ -114,5 +114,14 @@ set_t setdiff(s1,s2) set_t s1,s2; { result.set_size = 0; for(i=0;isy_value.syv_procoff = npatbytes; + sy_p->sy_value.syv_procoff = npatbytes + 1; } struct varinfo * diff --git a/util/ncgg/var.c b/util/ncgg/var.c index 97ba265d..186cdc2e 100644 --- a/util/ncgg/var.c +++ b/util/ncgg/var.c @@ -23,7 +23,7 @@ int empatlen,emmnem[EMPATMAX]; int empatexpr; int tokpatlen,tokpatset[TOKPATMAX],tokpatro[TOKPATMAX]; int nallreg,allreg[MAXALLREG]; -int cursetno; +int cursetno = -1; int allsetno; int inproc=0; /* scanning "procedure" */ int callproc=0; From a071ceb42526104bdeb9363f23cc5b2834942cba Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 16 Jan 1987 13:51:45 +0000 Subject: [PATCH 0494/1625] Bug fixes --- mach/proto/ncg/compute.c | 13 +++++++---- mach/proto/ncg/gencode.c | 8 ++++--- mach/proto/ncg/subr.c | 50 +++++++++++++++++++++++++++++----------- 3 files changed, 49 insertions(+), 22 deletions(-) diff --git a/mach/proto/ncg/compute.c b/mach/proto/ncg/compute.c index a47c0655..5c2d3d01 100644 --- a/mach/proto/ncg/compute.c +++ b/mach/proto/ncg/compute.c @@ -145,10 +145,10 @@ result_t compute(node) register node_p node; { switch(node->ex_operator) { default: assert(FALSE); case EX_TOKFIELD: - if (node->ex_lnode!=0) - tp = &fakestack[stackheight-node->ex_lnode]; - else - tp = curtoken; + if (node->ex_lnode==0) + if (curtoken) tp = curtoken; + else tp = &fakestack[stackheight-1]; + else tp = &fakestack[stackheight-node->ex_lnode]; switch(result.e_typ = tokens[tp->t_token].t_type[node->ex_rnode-1]) { default: assert(FALSE); @@ -343,7 +343,10 @@ result_t compute(node) register node_p node; { return(result); case EX_SUBREG: result.e_typ = EV_REG; - tp= &fakestack[stackheight-node->ex_lnode]; + if (node->ex_lnode==0) + if (curtoken) tp = curtoken; + else tp = &fakestack[stackheight-1]; + else tp = &fakestack[stackheight-node->ex_lnode]; assert(tp->t_token == -1); tmpreg= tp->t_att[0].ar; #if MAXMEMBERS!=0 diff --git a/mach/proto/ncg/gencode.c b/mach/proto/ncg/gencode.c index 8e54e33b..ca45bc00 100644 --- a/mach/proto/ncg/gencode.c +++ b/mach/proto/ncg/gencode.c @@ -96,12 +96,14 @@ string ad2str(ad) addr_t ad; { praddr(ad) addr_t ad; { - if (ad.ea_str==0) + if (ad.ea_str==0 || *(ad.ea_str) == '\0') fprintf(codefile,WRD_FMT,ad.ea_off); else { fprintf(codefile,"%s",ad.ea_str); - if (ad.ea_off<0) - fprintf(codefile,WRD_FMT,ad.ea_off); + if (ad.ea_off<0) { + fputc('-', codefile); + fprintf(codefile,WRD_FMT,-ad.ea_off); + } else if(ad.ea_off>0) { fputc('+',codefile); fprintf(codefile,WRD_FMT,ad.ea_off); diff --git a/mach/proto/ncg/subr.c b/mach/proto/ncg/subr.c index 825786a4..0805141f 100644 --- a/mach/proto/ncg/subr.c +++ b/mach/proto/ncg/subr.c @@ -78,7 +78,10 @@ instance(instno,token) register token_p token; { default: assert(FALSE); case IN_COPY: - tp= &fakestack[stackheight-inp->in_info[0]]; + if (inp->in_info[0] == 0) + if (curtoken) tp = curtoken; + else tp = &fakestack[stackheight-1]; + else tp= &fakestack[stackheight-inp->in_info[0]]; if (inp->in_info[1]==0) { *token = *tp; } else { @@ -93,7 +96,10 @@ instance(instno,token) register token_p token; { } return; case IN_MEMB: - tp= &fakestack[stackheight-inp->in_info[0]]; + if (inp->in_info[0] == 0) + if (curtoken) tp = curtoken; + else tp = &fakestack[stackheight-1]; + else tp= &fakestack[stackheight-inp->in_info[0]]; assert(inp->in_info[1]!=0); assert(tp->t_token>0); token->t_token= -1; @@ -160,7 +166,7 @@ cinstance(instno,token,tp,regno) register token_p token,tp; { default: assert(FALSE); case IN_COPY: - assert(inp->in_info[0] == 1); + assert(inp->in_info[0] <= 1); if (inp->in_info[1]==0) { *token = *tp; } else { @@ -175,7 +181,7 @@ cinstance(instno,token,tp,regno) register token_p token,tp; { } return; case IN_MEMB: - assert(inp->in_info[0] == 1); + assert(inp->in_info[0] <= 1); token->t_token= -1; assert(tp->t_token>0); assert(tokens[tp->t_token].t_type[inp->in_info[1]-1] == EV_REG); @@ -197,14 +203,19 @@ cinstance(instno,token,tp,regno) register token_p token,tp; { #ifdef REGVARS case IN_S_DESCR: case IN_D_DESCR: - result=compute(&enodes[inp->in_info[1]]); - assert(result.e_typ==EV_INT); - if ((regno=isregvar(result.e_v.e_con)) > 0) { - token->t_token = -1; - token->t_att[0].ar = regno; - for(i=1;it_att[i].aw = 0; - return; + { token_p ct = curtoken; + + curtoken = tp; + result=compute(&enodes[inp->in_info[1]]); + curtoken = ct; + assert(result.e_typ==EV_INT); + if ((regno=isregvar(result.e_v.e_con)) > 0) { + token->t_token = -1; + token->t_att[0].ar = regno; + for(i=1;it_att[i].aw = 0; + return; + } } /* fall through */ #endif @@ -217,7 +228,11 @@ cinstance(instno,token,tp,regno) register token_p token,tp; { assert(tokens[token->t_token].t_type[i]==0); token->t_att[i].aw=0; } else { + token_p ct = curtoken; + + curtoken = tp; result=compute(&enodes[inp->in_info[i+1]]); + curtoken = ct; assert(tokens[token->t_token].t_type[i]==result.e_typ); if (result.e_typ==EV_INT) token->t_att[i].aw=result.e_v.e_con; @@ -605,12 +620,19 @@ itokcost() { error(s,a1,a2,a3,a4,a5,a6,a7,a8) char *s; { - fatal(s,a1,a2,a3,a4,a5,a6,a7,a8); + fprintf(stderr,"Error: "); + fprintf(stderr,s,a1,a2,a3,a4,a5,a6,a7,a8); + fprintf(stderr,"\n"); +#ifdef TABLEDEBUG + ruletrace(); +#endif + out_finish(); + exit(-1); } fatal(s,a1,a2,a3,a4,a5,a6,a7,a8) char *s; { - fprintf(stderr,"Error: "); + fprintf(stderr,"Fatal: "); fprintf(stderr,s,a1,a2,a3,a4,a5,a6,a7,a8); fprintf(stderr,"\n"); #ifdef TABLEDEBUG From 9b8d7d1231ac462305c0712194579bcaa75f372e Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 16 Jan 1987 13:59:02 +0000 Subject: [PATCH 0495/1625] Bug fix. --- mach/ns/ncg/mach.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mach/ns/ncg/mach.c b/mach/ns/ncg/mach.c index e875cf68..0d33f342 100644 --- a/mach/ns/ncg/mach.c +++ b/mach/ns/ncg/mach.c @@ -68,12 +68,12 @@ i_regsave() { f_regsave(){ register i; + register int c = '['; - fprintf(codefile, "enter ["); - if (n_regvars>=1){ - fprintf(codefile,"%s",regadm[0].ra_str); - for (i=1; i=1){ - fprintf(codefile,"%s",regadm[0].ra_str); - for (i=1; i Date: Fri, 16 Jan 1987 15:21:51 +0000 Subject: [PATCH 0496/1625] as --> nas --- mach/ns/Action | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/ns/Action b/mach/ns/Action index 34520181..0ba06509 100644 --- a/mach/ns/Action +++ b/mach/ns/Action @@ -1,5 +1,5 @@ name "NS16032 assembler" -dir as +dir nas end name "NS16032 backend" dir cg From 979b18cbbd3ffed25ed295a90bb614b46c2bfc3b Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 16 Jan 1987 15:40:01 +0000 Subject: [PATCH 0497/1625] version generating .o files --- mach/ns/libsys/LIST | 126 +++++++++++++++++++------------------- mach/ns/libsys/Makefile | 31 +++++++--- mach/ns/libsys/compmodule | 4 ++ 3 files changed, 88 insertions(+), 73 deletions(-) create mode 100755 mach/ns/libsys/compmodule diff --git a/mach/ns/libsys/LIST b/mach/ns/libsys/LIST index 30eb4de6..cd3829cb 100644 --- a/mach/ns/libsys/LIST +++ b/mach/ns/libsys/LIST @@ -1,64 +1,64 @@ LIST -exit.o -gtty.o -signal.o -stty.o -tell.o -time.o -cleanup.o -access.o -acct.o -alarm.o -brk.o -chdir.o -chmod.o -chown.o -chroot.o -close.o -creat.o -dup.o -dup2.o -execl.o -execle.o -execv.o -execve.o -_exit.o -fork.o -fstat.o -ftime.o -getegid.o -geteuid.o -getgid.o -getpid.o -getuid.o -ioctl.o -kill.o -link.o -lock.o -lseek.o -mknod.o -mount.o -mpxcall.o -nice.o -open.o -pause.o -pipe.o -prof.o -ptrace.o -read.o -sbrk.o -setgid.o -setuid.o -setsig.o -sigtrp.o -stat.o -stime.o -sync.o -times.o -umask.o -umount.o -unlink.o -utime.o -wait.o -write.o -errno.o +exit.s +gtty.s +signal.s +stty.s +tell.s +time.s +cleanup.s +access.s +acct.s +alarm.s +brk.s +chdir.s +chmod.s +chown.s +chroot.s +close.s +creat.s +dup.s +dup2.s +execl.s +execle.s +execv.s +execve.s +_exit.s +fork.s +fstat.s +ftime.s +getegid.s +geteuid.s +getgid.s +getpid.s +getuid.s +ioctl.s +kill.s +link.s +lock.s +lseek.s +mknod.s +mount.s +mpxcall.s +nice.s +open.s +pause.s +pipe.s +prof.s +ptrace.s +read.s +sbrk.s +setgid.s +setuid.s +setsig.s +sigtrp.s +stat.s +stime.s +sync.s +times.s +umask.s +umount.s +unlink.s +utime.s +wait.s +write.s +errno.s diff --git a/mach/ns/libsys/Makefile b/mach/ns/libsys/Makefile index 91f2cc35..d56b82c5 100644 --- a/mach/ns/libsys/Makefile +++ b/mach/ns/libsys/Makefile @@ -1,17 +1,28 @@ # $Header$ -install: - ../../install head_em.s head_em - ../../install tail_mon.a tail_mon +MACH=ns +all: tail_mon head_em.o -compare: - -../../compare head_em.s head_em - -../../compare tail_mon.a tail_mon +install: all + ../../install head_em.o head_em + ../../install tail_mon -clean : +cmp: all + -../../compare head_em.o head_em + -../../compare tail_mon + +tail_mon: tail_mon.a + ASAR=aal ; export ASAR ;\ + march . tail_mon + +head_em.o: head_em.s + $(MACH) -I../../../h -c head_em.s + +clean: + rm -f *.o opr : - make pr | opr + make pr | opr pr: - @pr -h `pwd`/head_em.s head_em.s - @ar pv tail_mon.a | pr -h `pwd`/tail_mon.a + @pr -h `pwd`/head_em.s head_em.s + @ar pv tail_mon.a | pr -h `pwd`/tail_mon.a diff --git a/mach/ns/libsys/compmodule b/mach/ns/libsys/compmodule new file mode 100755 index 00000000..adf99cce --- /dev/null +++ b/mach/ns/libsys/compmodule @@ -0,0 +1,4 @@ +if ns -c $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 +fi From 3b4f13672db787385e584102a2b5477ba7eb283a Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 16 Jan 1987 16:14:22 +0000 Subject: [PATCH 0498/1625] Bug fix with WorkingDir --- util/cpp/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util/cpp/main.c b/util/cpp/main.c index fc581c3b..bb1ea8d7 100644 --- a/util/cpp/main.c +++ b/util/cpp/main.c @@ -5,6 +5,7 @@ extern struct tokenname tkidf[], tkkey[]; extern char *symbol2str(); +extern char *getwdir(); extern char *inctable[]; extern int err_occurred; int idfsize = IDFSIZE; @@ -56,10 +57,10 @@ compile(argc, argv) fatal("use: %s [options] [source]", prog_name); break; } - WorkingDir = inctable[0]; if (!InsertFile(source, (char **) 0, &dummy)) /* read the source file */ fatal("%s: no source file %s\n", prog_name, source ? source : "stdin"); + WorkingDir = getwdir(dummy); preprocess(source); } From cf3bc8b3d201cce5e47d51a91c725623382019bf Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 16 Jan 1987 16:34:45 +0000 Subject: [PATCH 0499/1625] conversion to new assembler format --- mach/ns/libsys/_exit.s | 7 ++++++- mach/ns/libsys/access.s | 7 ++++++- mach/ns/libsys/acct.s | 7 ++++++- mach/ns/libsys/alarm.s | 7 ++++++- mach/ns/libsys/brk.s | 7 ++++++- mach/ns/libsys/chdir.s | 7 ++++++- mach/ns/libsys/chmod.s | 7 ++++++- mach/ns/libsys/chown.s | 7 ++++++- mach/ns/libsys/chroot.s | 7 ++++++- mach/ns/libsys/cleanup.s | 7 ++++++- mach/ns/libsys/close.s | 7 ++++++- mach/ns/libsys/creat.s | 7 ++++++- mach/ns/libsys/dup.s | 7 ++++++- mach/ns/libsys/dup2.s | 7 ++++++- mach/ns/libsys/errno.s | 9 +++++++-- mach/ns/libsys/execl.s | 7 ++++++- mach/ns/libsys/execle.s | 7 ++++++- mach/ns/libsys/execv.s | 7 ++++++- mach/ns/libsys/execve.s | 7 ++++++- mach/ns/libsys/exit.s | 7 ++++++- mach/ns/libsys/fork.s | 9 +++++++-- mach/ns/libsys/fstat.s | 7 ++++++- mach/ns/libsys/ftime.s | 7 ++++++- mach/ns/libsys/getegid.s | 7 ++++++- mach/ns/libsys/geteuid.s | 7 ++++++- mach/ns/libsys/getgid.s | 7 ++++++- mach/ns/libsys/getpid.s | 7 ++++++- mach/ns/libsys/getuid.s | 7 ++++++- mach/ns/libsys/gtty.s | 7 ++++++- mach/ns/libsys/head_em.s | 27 +++++++++++++++------------ mach/ns/libsys/ioctl.s | 7 ++++++- mach/ns/libsys/kill.s | 7 ++++++- mach/ns/libsys/link.s | 7 ++++++- mach/ns/libsys/lock.s | 7 ++++++- mach/ns/libsys/lseek.s | 7 ++++++- mach/ns/libsys/mknod.s | 7 ++++++- mach/ns/libsys/mount.s | 7 ++++++- mach/ns/libsys/mpxcall.s | 7 ++++++- mach/ns/libsys/nice.s | 7 ++++++- mach/ns/libsys/open.s | 7 ++++++- mach/ns/libsys/pause.s | 7 ++++++- mach/ns/libsys/pipe.s | 7 ++++++- mach/ns/libsys/prof.s | 7 ++++++- mach/ns/libsys/ptrace.s | 7 ++++++- mach/ns/libsys/read.s | 7 ++++++- mach/ns/libsys/sbrk.s | 7 ++++++- mach/ns/libsys/setgid.s | 7 ++++++- mach/ns/libsys/setsig.s | 9 +++++++-- mach/ns/libsys/setuid.s | 7 ++++++- mach/ns/libsys/stat.s | 7 ++++++- 50 files changed, 312 insertions(+), 64 deletions(-) diff --git a/mach/ns/libsys/_exit.s b/mach/ns/libsys/_exit.s index bcc38fd8..a99c9668 100644 --- a/mach/ns/libsys/_exit.s +++ b/mach/ns/libsys/_exit.s @@ -1,6 +1,11 @@ .define __exit +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern __exit -.text +.sect .text __exit: enter[], 0 movd 8(fp),tos diff --git a/mach/ns/libsys/access.s b/mach/ns/libsys/access.s index 0f2d0f7f..28b183af 100644 --- a/mach/ns/libsys/access.s +++ b/mach/ns/libsys/access.s @@ -1,6 +1,11 @@ .define _access +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _access -.text +.sect .text _access: enter[], 0 movd 12(fp),tos diff --git a/mach/ns/libsys/acct.s b/mach/ns/libsys/acct.s index f7afd78a..7a198126 100644 --- a/mach/ns/libsys/acct.s +++ b/mach/ns/libsys/acct.s @@ -1,6 +1,11 @@ .define _acct +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _acct -.text +.sect .text _acct: enter[], 0 movd 8(fp),tos diff --git a/mach/ns/libsys/alarm.s b/mach/ns/libsys/alarm.s index bedbddd0..e00b7831 100644 --- a/mach/ns/libsys/alarm.s +++ b/mach/ns/libsys/alarm.s @@ -1,6 +1,11 @@ .define _alarm +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _alarm -.text +.sect .text _alarm: enter[], 0 movd 8(fp),tos diff --git a/mach/ns/libsys/brk.s b/mach/ns/libsys/brk.s index a3463ae6..b11758c8 100644 --- a/mach/ns/libsys/brk.s +++ b/mach/ns/libsys/brk.s @@ -1,6 +1,11 @@ .define _brk +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _brk -.text +.sect .text _brk: enter[], 0 movd 8(fp),@.reghp diff --git a/mach/ns/libsys/chdir.s b/mach/ns/libsys/chdir.s index 1840b74b..ab4c2a67 100644 --- a/mach/ns/libsys/chdir.s +++ b/mach/ns/libsys/chdir.s @@ -1,6 +1,11 @@ .define _chdir +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _chdir -.text +.sect .text _chdir: enter[], 0 movd 8(fp),tos diff --git a/mach/ns/libsys/chmod.s b/mach/ns/libsys/chmod.s index 03bf072c..5c6293d9 100644 --- a/mach/ns/libsys/chmod.s +++ b/mach/ns/libsys/chmod.s @@ -1,6 +1,11 @@ .define _chmod +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _chmod -.text +.sect .text _chmod: enter[], 0 movd 12(fp),tos diff --git a/mach/ns/libsys/chown.s b/mach/ns/libsys/chown.s index 72e5cfce..ddc97921 100644 --- a/mach/ns/libsys/chown.s +++ b/mach/ns/libsys/chown.s @@ -1,6 +1,11 @@ .define _chown +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _chown -.text +.sect .text _chown: enter[], 0 addr 8(fp),r7 diff --git a/mach/ns/libsys/chroot.s b/mach/ns/libsys/chroot.s index 2256b1a9..a8d8ab58 100644 --- a/mach/ns/libsys/chroot.s +++ b/mach/ns/libsys/chroot.s @@ -1,6 +1,11 @@ .define _chroot +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _chroot -.text +.sect .text _chroot: enter[], 0 movd 8(fp),tos diff --git a/mach/ns/libsys/cleanup.s b/mach/ns/libsys/cleanup.s index 48c42520..0d1db44f 100644 --- a/mach/ns/libsys/cleanup.s +++ b/mach/ns/libsys/cleanup.s @@ -1,6 +1,11 @@ .define __cleanup +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern __cleanup -.text +.sect .text __cleanup: enter[], 0 exit [] diff --git a/mach/ns/libsys/close.s b/mach/ns/libsys/close.s index b6e217c8..dbe9297f 100644 --- a/mach/ns/libsys/close.s +++ b/mach/ns/libsys/close.s @@ -1,6 +1,11 @@ .define _close +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _close -.text +.sect .text _close: movd 0, r4 ret 0 diff --git a/mach/ns/libsys/creat.s b/mach/ns/libsys/creat.s index b0bf72e9..a9efa4c2 100644 --- a/mach/ns/libsys/creat.s +++ b/mach/ns/libsys/creat.s @@ -1,6 +1,11 @@ .define _creat +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _creat -.text +.sect .text _creat: enter[], 0 movd 12(fp),tos diff --git a/mach/ns/libsys/dup.s b/mach/ns/libsys/dup.s index c4a353c2..607d2e3a 100644 --- a/mach/ns/libsys/dup.s +++ b/mach/ns/libsys/dup.s @@ -1,6 +1,11 @@ .define _dup +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _dup -.text +.sect .text _dup: enter[], 0 movd 8(fp),tos diff --git a/mach/ns/libsys/dup2.s b/mach/ns/libsys/dup2.s index 6f45f4e5..d35a47f6 100644 --- a/mach/ns/libsys/dup2.s +++ b/mach/ns/libsys/dup2.s @@ -1,6 +1,11 @@ .define _dup2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _dup2 -.text +.sect .text _dup2: enter[], 0 movd 8(fp),r7 diff --git a/mach/ns/libsys/errno.s b/mach/ns/libsys/errno.s index 35c87193..914836a9 100644 --- a/mach/ns/libsys/errno.s +++ b/mach/ns/libsys/errno.s @@ -1,5 +1,10 @@ .define _errno +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _errno -.bss +.sect .bss _errno:.space 4 -.text +.sect .text diff --git a/mach/ns/libsys/execl.s b/mach/ns/libsys/execl.s index f637c229..7c043284 100644 --- a/mach/ns/libsys/execl.s +++ b/mach/ns/libsys/execl.s @@ -1,6 +1,11 @@ .define _execl +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _execl -.text +.sect .text _execl: enter[], 0 movd @__penvp,tos diff --git a/mach/ns/libsys/execle.s b/mach/ns/libsys/execle.s index 2bd53858..2e4cb954 100644 --- a/mach/ns/libsys/execle.s +++ b/mach/ns/libsys/execle.s @@ -1,6 +1,11 @@ .define _execle +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _execle -.text +.sect .text _execle: enter[], 0 addr 12(fp),tos diff --git a/mach/ns/libsys/execv.s b/mach/ns/libsys/execv.s index a38e9bdf..9f93526b 100644 --- a/mach/ns/libsys/execv.s +++ b/mach/ns/libsys/execv.s @@ -1,6 +1,11 @@ .define _execv +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _execv -.text +.sect .text _execv: enter[], 0 movd @__penvp,tos diff --git a/mach/ns/libsys/execve.s b/mach/ns/libsys/execve.s index 656278ec..cb663fbd 100644 --- a/mach/ns/libsys/execve.s +++ b/mach/ns/libsys/execve.s @@ -1,6 +1,11 @@ .define _execve +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _execve -.text +.sect .text _execve: enter[], 0 addr 8(fp),r7 diff --git a/mach/ns/libsys/exit.s b/mach/ns/libsys/exit.s index a809dd17..39d03232 100644 --- a/mach/ns/libsys/exit.s +++ b/mach/ns/libsys/exit.s @@ -1,6 +1,11 @@ .define _exit +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _exit -.text +.sect .text _exit: enter[], 0 jsr @__cleanup diff --git a/mach/ns/libsys/fork.s b/mach/ns/libsys/fork.s index 9670ddfb..29d01add 100644 --- a/mach/ns/libsys/fork.s +++ b/mach/ns/libsys/fork.s @@ -1,10 +1,15 @@ .define _fork .define _par_uid +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _par_uid -.bss +.sect .bss _par_uid:.space 4 .extern _fork -.text +.sect .text _fork: enter[], 0 movd 2,tos diff --git a/mach/ns/libsys/fstat.s b/mach/ns/libsys/fstat.s index 4a8f2048..7a23edd6 100644 --- a/mach/ns/libsys/fstat.s +++ b/mach/ns/libsys/fstat.s @@ -1,6 +1,11 @@ .define _fstat +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _fstat -.text +.sect .text _fstat: enter[], 0 movd 12(fp),tos diff --git a/mach/ns/libsys/ftime.s b/mach/ns/libsys/ftime.s index b4a26323..306cc7bb 100644 --- a/mach/ns/libsys/ftime.s +++ b/mach/ns/libsys/ftime.s @@ -1,6 +1,11 @@ .define _ftime +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _ftime -.text +.sect .text _ftime: enter[], 0 movd 8(fp),tos diff --git a/mach/ns/libsys/getegid.s b/mach/ns/libsys/getegid.s index 6f2ff7e8..80a379b6 100644 --- a/mach/ns/libsys/getegid.s +++ b/mach/ns/libsys/getegid.s @@ -1,6 +1,11 @@ .define _getegid +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _getegid -.text +.sect .text _getegid: enter[], 0 movd 47,tos diff --git a/mach/ns/libsys/geteuid.s b/mach/ns/libsys/geteuid.s index c2a99dd9..dd7bc0bc 100644 --- a/mach/ns/libsys/geteuid.s +++ b/mach/ns/libsys/geteuid.s @@ -1,6 +1,11 @@ .define _geteuid +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _geteuid -.text +.sect .text _geteuid: enter[], 0 movd 24,tos diff --git a/mach/ns/libsys/getgid.s b/mach/ns/libsys/getgid.s index 011c894f..3f63ec42 100644 --- a/mach/ns/libsys/getgid.s +++ b/mach/ns/libsys/getgid.s @@ -1,6 +1,11 @@ .define _getgid +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _getgid -.text +.sect .text _getgid: enter[], 0 movd 47,tos diff --git a/mach/ns/libsys/getpid.s b/mach/ns/libsys/getpid.s index c064bc5c..9dfbd9cf 100644 --- a/mach/ns/libsys/getpid.s +++ b/mach/ns/libsys/getpid.s @@ -1,6 +1,11 @@ .define _getpid +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _getpid -.text +.sect .text _getpid: enter[], 0 movd 20,tos diff --git a/mach/ns/libsys/getuid.s b/mach/ns/libsys/getuid.s index 1d3fabd1..78473a4e 100644 --- a/mach/ns/libsys/getuid.s +++ b/mach/ns/libsys/getuid.s @@ -1,6 +1,11 @@ .define _getuid +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _getuid -.text +.sect .text _getuid: enter[], 0 movd 24,tos diff --git a/mach/ns/libsys/gtty.s b/mach/ns/libsys/gtty.s index bbe068d5..473c54f9 100644 --- a/mach/ns/libsys/gtty.s +++ b/mach/ns/libsys/gtty.s @@ -1,6 +1,11 @@ .define _gtty +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _gtty -.text +.sect .text _gtty: enter[], 0 movd 12(fp),tos diff --git a/mach/ns/libsys/head_em.s b/mach/ns/libsys/head_em.s index ffcd6fe5..484b9c23 100644 --- a/mach/ns/libsys/head_em.s +++ b/mach/ns/libsys/head_em.s @@ -2,16 +2,19 @@ .define .ignmask, .trpreg .define .stop .define ERANGE,EILLINS,ECASE +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text -base = 0x10000 topmem = 0xFFFFFF ERANGE = 1 EILLINS = 18 ECASE = 20 - .base base - .text + .sect .text movd begbss, r7 movd endbss, r6 @@ -30,21 +33,21 @@ ECASE = 20 jsr @.putchar bpt -.bss +.sect .bss begbss: -.data +.sect .data hol0: - .long 0 - .long 0 + .data4 0 + .data4 0 argv: - .long 3f + .data4 3f envp: - .long 0 + .data4 0 3: .asciz 'PROGRAM' .reghp: - .long endbss + .data4 endbss .ignmask: - .short 0 + .data2 0 .trpreg: - .long 0 + .data4 0 diff --git a/mach/ns/libsys/ioctl.s b/mach/ns/libsys/ioctl.s index 906d270a..4ca67f82 100644 --- a/mach/ns/libsys/ioctl.s +++ b/mach/ns/libsys/ioctl.s @@ -1,6 +1,11 @@ .define _ioctl +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _ioctl -.text +.sect .text _ioctl: enter[], 0 addr 8(fp),r7 diff --git a/mach/ns/libsys/kill.s b/mach/ns/libsys/kill.s index 7447642f..57b39284 100644 --- a/mach/ns/libsys/kill.s +++ b/mach/ns/libsys/kill.s @@ -1,6 +1,11 @@ .define _kill +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _kill -.text +.sect .text _kill: enter[], 0 movd 12(fp),tos diff --git a/mach/ns/libsys/link.s b/mach/ns/libsys/link.s index 9b82bd2f..a8a43354 100644 --- a/mach/ns/libsys/link.s +++ b/mach/ns/libsys/link.s @@ -1,6 +1,11 @@ .define _link +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _link -.text +.sect .text _link: enter[], 0 movd 12(fp),tos diff --git a/mach/ns/libsys/lock.s b/mach/ns/libsys/lock.s index 88fca256..848e5c06 100644 --- a/mach/ns/libsys/lock.s +++ b/mach/ns/libsys/lock.s @@ -1,6 +1,11 @@ .define _lock +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _lock -.text +.sect .text _lock: enter[], 0 movd 8(fp),tos diff --git a/mach/ns/libsys/lseek.s b/mach/ns/libsys/lseek.s index 8d50a6fd..0dc530d9 100644 --- a/mach/ns/libsys/lseek.s +++ b/mach/ns/libsys/lseek.s @@ -1,6 +1,11 @@ .define _lseek +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _lseek -.text +.sect .text _lseek: enter[], 0 addr 8(fp),r7 diff --git a/mach/ns/libsys/mknod.s b/mach/ns/libsys/mknod.s index 3e85d2a1..0e01edd8 100644 --- a/mach/ns/libsys/mknod.s +++ b/mach/ns/libsys/mknod.s @@ -1,6 +1,11 @@ .define _mknod +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _mknod -.text +.sect .text _mknod: enter[], 0 addr 8(fp),r7 diff --git a/mach/ns/libsys/mount.s b/mach/ns/libsys/mount.s index 216f5e27..ed956548 100644 --- a/mach/ns/libsys/mount.s +++ b/mach/ns/libsys/mount.s @@ -1,6 +1,11 @@ .define _mount +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _mount -.text +.sect .text _mount: enter[], 0 addr 8(fp),r7 diff --git a/mach/ns/libsys/mpxcall.s b/mach/ns/libsys/mpxcall.s index 9cdec1ab..23401da8 100644 --- a/mach/ns/libsys/mpxcall.s +++ b/mach/ns/libsys/mpxcall.s @@ -1,6 +1,11 @@ .define _mpxcall +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _mpxcall -.text +.sect .text _mpxcall: enter[], 0 movd 12(fp),tos diff --git a/mach/ns/libsys/nice.s b/mach/ns/libsys/nice.s index e47a54d3..7a31fce7 100644 --- a/mach/ns/libsys/nice.s +++ b/mach/ns/libsys/nice.s @@ -1,6 +1,11 @@ .define _nice +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _nice -.text +.sect .text _nice: enter[], 0 movd 8(fp),tos diff --git a/mach/ns/libsys/open.s b/mach/ns/libsys/open.s index 4a0cf980..c883882c 100644 --- a/mach/ns/libsys/open.s +++ b/mach/ns/libsys/open.s @@ -1,6 +1,11 @@ .define _open +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _open -.text +.sect .text _open: enter[], 0 movd 12(fp),tos diff --git a/mach/ns/libsys/pause.s b/mach/ns/libsys/pause.s index 607a351b..59d2cc35 100644 --- a/mach/ns/libsys/pause.s +++ b/mach/ns/libsys/pause.s @@ -1,6 +1,11 @@ .define _pause +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _pause -.text +.sect .text _pause: enter[], 0 movd 29,tos diff --git a/mach/ns/libsys/pipe.s b/mach/ns/libsys/pipe.s index 6915b443..f8b6ee30 100644 --- a/mach/ns/libsys/pipe.s +++ b/mach/ns/libsys/pipe.s @@ -1,6 +1,11 @@ .define _pipe +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _pipe -.text +.sect .text _pipe: enter[], 0 movd 42,tos diff --git a/mach/ns/libsys/prof.s b/mach/ns/libsys/prof.s index 822e5beb..61a6e014 100644 --- a/mach/ns/libsys/prof.s +++ b/mach/ns/libsys/prof.s @@ -1,6 +1,11 @@ .define _profil +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _profil -.text +.sect .text _profil: enter[], 0 addr 8(fp),r7 diff --git a/mach/ns/libsys/ptrace.s b/mach/ns/libsys/ptrace.s index a32ebdfc..e1d73aea 100644 --- a/mach/ns/libsys/ptrace.s +++ b/mach/ns/libsys/ptrace.s @@ -1,6 +1,11 @@ .define _ptrace +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _ptrace -.text +.sect .text _ptrace: enter[], 0 xord @_errno,@_errno diff --git a/mach/ns/libsys/read.s b/mach/ns/libsys/read.s index dd3552db..941d9c05 100644 --- a/mach/ns/libsys/read.s +++ b/mach/ns/libsys/read.s @@ -1,6 +1,11 @@ .define _read +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _read -.text +.sect .text _read: enter[], 0 save [r0,r1,r2,r3] diff --git a/mach/ns/libsys/sbrk.s b/mach/ns/libsys/sbrk.s index e7b080b5..3171463b 100644 --- a/mach/ns/libsys/sbrk.s +++ b/mach/ns/libsys/sbrk.s @@ -1,6 +1,11 @@ .define _sbrk +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _sbrk -.text +.sect .text _sbrk: enter[], 0 movd @.reghp,r7 diff --git a/mach/ns/libsys/setgid.s b/mach/ns/libsys/setgid.s index b9cc6698..97a79254 100644 --- a/mach/ns/libsys/setgid.s +++ b/mach/ns/libsys/setgid.s @@ -1,6 +1,11 @@ .define _setgid +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _setgid -.text +.sect .text _setgid: enter[], 0 movd 8(fp),tos diff --git a/mach/ns/libsys/setsig.s b/mach/ns/libsys/setsig.s index 4035a369..4522e77e 100644 --- a/mach/ns/libsys/setsig.s +++ b/mach/ns/libsys/setsig.s @@ -1,9 +1,14 @@ .define __setsig -.bss +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +.sect .bss _save:.space 4 _trf:.space 4 .extern __setsig -.text +.sect .text __setsig: enter[], 0 movd 8(fp),@_trf diff --git a/mach/ns/libsys/setuid.s b/mach/ns/libsys/setuid.s index e9cfc095..25de564b 100644 --- a/mach/ns/libsys/setuid.s +++ b/mach/ns/libsys/setuid.s @@ -1,6 +1,11 @@ .define _setuid +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _setuid -.text +.sect .text _setuid: enter[], 0 movd 8(fp),tos diff --git a/mach/ns/libsys/stat.s b/mach/ns/libsys/stat.s index 66ca3156..7abe3504 100644 --- a/mach/ns/libsys/stat.s +++ b/mach/ns/libsys/stat.s @@ -1,6 +1,11 @@ .define _stat +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _stat -.text +.sect .text _stat: enter[], 0 movd 12(fp),tos From 51d9fcea1205d67c5132277f7aa0a737a386bed2 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 16 Jan 1987 16:49:12 +0000 Subject: [PATCH 0500/1625] Initial revision --- mach/ns/libem/compmodule | 4 ++++ 1 file changed, 4 insertions(+) create mode 100755 mach/ns/libem/compmodule diff --git a/mach/ns/libem/compmodule b/mach/ns/libem/compmodule new file mode 100755 index 00000000..adf99cce --- /dev/null +++ b/mach/ns/libem/compmodule @@ -0,0 +1,4 @@ +if ns -c $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 +fi From a0fe90d2e976c3218ba5642a19c692af401d4ad9 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 16 Jan 1987 16:49:46 +0000 Subject: [PATCH 0501/1625] conversion to new assembler format --- mach/ns/libem/aar.s | 7 ++++++- mach/ns/libem/cff.s | 7 ++++++- mach/ns/libem/cfi.s | 7 ++++++- mach/ns/libem/cif.s | 7 ++++++- mach/ns/libem/cii.s | 7 ++++++- mach/ns/libem/cms.s | 7 ++++++- mach/ns/libem/cmu.s | 7 ++++++- mach/ns/libem/csa.s | 7 ++++++- mach/ns/libem/csb.s | 7 ++++++- mach/ns/libem/dup.s | 7 ++++++- mach/ns/libem/dvu.s | 7 ++++++- mach/ns/libem/end.s | 11 ++++++++--- mach/ns/libem/exg.s | 7 ++++++- mach/ns/libem/gto.s | 7 ++++++- mach/ns/libem/lar.s | 7 ++++++- mach/ns/libem/los.s | 7 ++++++- mach/ns/libem/mon.s | 9 +++++++-- mach/ns/libem/print.s | 7 ++++++- mach/ns/libem/prnl.s | 7 ++++++- mach/ns/libem/prstr.s | 7 ++++++- mach/ns/libem/putchar.s | 7 ++++++- mach/ns/libem/rck.s | 7 ++++++- mach/ns/libem/rmu.s | 7 ++++++- mach/ns/libem/sar.s | 7 ++++++- mach/ns/libem/sts.s | 7 ++++++- mach/ns/libem/trp.s | 7 ++++++- mach/ns/libsys/stty.s | 7 ++++++- mach/ns/libsys/sync.s | 7 ++++++- mach/ns/libsys/tell.s | 7 ++++++- mach/ns/libsys/time.s | 7 ++++++- mach/ns/libsys/times.s | 7 ++++++- mach/ns/libsys/umask.s | 7 ++++++- mach/ns/libsys/umount.s | 7 ++++++- mach/ns/libsys/unlink.s | 7 ++++++- mach/ns/libsys/utime.s | 7 ++++++- mach/ns/libsys/wait.s | 7 ++++++- mach/ns/libsys/write.s | 7 ++++++- 37 files changed, 225 insertions(+), 40 deletions(-) diff --git a/mach/ns/libem/aar.s b/mach/ns/libem/aar.s index 984c57f0..6dd8cac5 100644 --- a/mach/ns/libem/aar.s +++ b/mach/ns/libem/aar.s @@ -1,6 +1,11 @@ .define .aar +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text - .text + .sect .text .aar: movd 8(sp), r7 diff --git a/mach/ns/libem/cff.s b/mach/ns/libem/cff.s index f1cae1da..d797448a 100644 --- a/mach/ns/libem/cff.s +++ b/mach/ns/libem/cff.s @@ -1,6 +1,11 @@ .define .cff +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text - .text + .sect .text .cff : cmpd 4(sp), 8(sp) beq 1f diff --git a/mach/ns/libem/cfi.s b/mach/ns/libem/cfi.s index c0545626..877aed89 100644 --- a/mach/ns/libem/cfi.s +++ b/mach/ns/libem/cfi.s @@ -1,6 +1,11 @@ .define .cfi +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text - .text + .sect .text .cfi: cmpd 4, 8(sp) beq 4f diff --git a/mach/ns/libem/cif.s b/mach/ns/libem/cif.s index 82098184..61bb6da1 100644 --- a/mach/ns/libem/cif.s +++ b/mach/ns/libem/cif.s @@ -1,6 +1,11 @@ .define .cif +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text - .text + .sect .text .cif : cmpd 4, 4(sp) beq 4f diff --git a/mach/ns/libem/cii.s b/mach/ns/libem/cii.s index d25b5fa2..13980503 100644 --- a/mach/ns/libem/cii.s +++ b/mach/ns/libem/cii.s @@ -1,6 +1,11 @@ .define .cii +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text - .text + .sect .text !r7 will save return addres .cii: diff --git a/mach/ns/libem/cms.s b/mach/ns/libem/cms.s index e8b0d501..3b6d6ea8 100644 --- a/mach/ns/libem/cms.s +++ b/mach/ns/libem/cms.s @@ -1,6 +1,11 @@ .define .cms +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text - .text + .sect .text .cms: movd tos, r7 !return addres addr 4(sp), r1 diff --git a/mach/ns/libem/cmu.s b/mach/ns/libem/cmu.s index 66d381c4..c8c1aad7 100644 --- a/mach/ns/libem/cmu.s +++ b/mach/ns/libem/cmu.s @@ -1,6 +1,11 @@ .define .cmu +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text - .text + .sect .text .cmu: movd tos, r7 !return addres addr 4(sp), r1 diff --git a/mach/ns/libem/csa.s b/mach/ns/libem/csa.s index 5f16e4b0..0b4f492f 100644 --- a/mach/ns/libem/csa.s +++ b/mach/ns/libem/csa.s @@ -1,6 +1,11 @@ .define .csa +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text - .text + .sect .text !r0 contains index !r1 contains pointer to csa descriptor diff --git a/mach/ns/libem/csb.s b/mach/ns/libem/csb.s index 15bf815e..56ed6755 100644 --- a/mach/ns/libem/csb.s +++ b/mach/ns/libem/csb.s @@ -1,6 +1,11 @@ .define .csb +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text - .text + .sect .text !r0 contains index !r1 contains pointer to csb descriptor diff --git a/mach/ns/libem/dup.s b/mach/ns/libem/dup.s index 9252019d..0d903ed6 100644 --- a/mach/ns/libem/dup.s +++ b/mach/ns/libem/dup.s @@ -1,6 +1,11 @@ .define .dup +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text - .text + .sect .text !r2 will save return addres .dup: diff --git a/mach/ns/libem/dvu.s b/mach/ns/libem/dvu.s index 34b8ba40..0bfaec78 100644 --- a/mach/ns/libem/dvu.s +++ b/mach/ns/libem/dvu.s @@ -1,6 +1,11 @@ .define .dvu +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text - .text + .sect .text .dvu: enter[r1,r2],0 diff --git a/mach/ns/libem/end.s b/mach/ns/libem/end.s index 9225bd8c..e8d71d80 100644 --- a/mach/ns/libem/end.s +++ b/mach/ns/libem/end.s @@ -1,15 +1,20 @@ .define endtext,enddata,endbss .define _end, _etext, _edata +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text - .text + .sect .text endtext: _etext: .align 4 - .data + .sect .data enddata: _edata: .align 4 - .bss + .sect .bss .align 4 endbss: _end: diff --git a/mach/ns/libem/exg.s b/mach/ns/libem/exg.s index 47bc38e3..123b4fb3 100644 --- a/mach/ns/libem/exg.s +++ b/mach/ns/libem/exg.s @@ -1,6 +1,11 @@ .define .exg +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text - .text + .sect .text .exg: save [r2,r3] diff --git a/mach/ns/libem/gto.s b/mach/ns/libem/gto.s index 8d019990..dbd2d932 100644 --- a/mach/ns/libem/gto.s +++ b/mach/ns/libem/gto.s @@ -1,6 +1,11 @@ .define .gto +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text - .text + .sect .text !r0 contains descriptor addres .gto: diff --git a/mach/ns/libem/lar.s b/mach/ns/libem/lar.s index 8de2d964..cf5a27e0 100644 --- a/mach/ns/libem/lar.s +++ b/mach/ns/libem/lar.s @@ -1,6 +1,11 @@ .define .lar +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text - .text + .sect .text .lar: movd tos, r2 diff --git a/mach/ns/libem/los.s b/mach/ns/libem/los.s index daf36cfb..fc500827 100644 --- a/mach/ns/libem/los.s +++ b/mach/ns/libem/los.s @@ -1,6 +1,11 @@ .define .los +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text - .text + .sect .text .los: movd tos, r7 diff --git a/mach/ns/libem/mon.s b/mach/ns/libem/mon.s index 57ef54a5..31773656 100644 --- a/mach/ns/libem/mon.s +++ b/mach/ns/libem/mon.s @@ -1,6 +1,11 @@ .define .mon +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text - .text + .sect .text .mon: cmpd 1,4(sp) @@ -47,7 +52,7 @@ 5: movd 0, 16(sp) ret 12 -.data +.sect .data .add1: .asciz "monitor call " .add2: .asciz " not implemented\n" .align diff --git a/mach/ns/libem/print.s b/mach/ns/libem/print.s index fa44c1ff..e9350075 100644 --- a/mach/ns/libem/print.s +++ b/mach/ns/libem/print.s @@ -1,6 +1,11 @@ .define .print +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text - .text + .sect .text .print: save[r0,r1,r2] diff --git a/mach/ns/libem/prnl.s b/mach/ns/libem/prnl.s index 62130484..fd0f0e97 100644 --- a/mach/ns/libem/prnl.s +++ b/mach/ns/libem/prnl.s @@ -1,6 +1,11 @@ .define .prnl +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text - .text + .sect .text .prnl: movb "\n", tos jsr @.putchar diff --git a/mach/ns/libem/prstr.s b/mach/ns/libem/prstr.s index 8d7a61aa..ce0df854 100644 --- a/mach/ns/libem/prstr.s +++ b/mach/ns/libem/prstr.s @@ -1,6 +1,11 @@ .define .prstr +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text - .text + .sect .text !het adres van de af te drukken string staat op de stack. .prstr: diff --git a/mach/ns/libem/putchar.s b/mach/ns/libem/putchar.s index d5fe98f2..6a4856b7 100644 --- a/mach/ns/libem/putchar.s +++ b/mach/ns/libem/putchar.s @@ -1,6 +1,11 @@ .define .putchar +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text - .text + .sect .text .putchar: save [r0, r1, r2, r3] diff --git a/mach/ns/libem/rck.s b/mach/ns/libem/rck.s index 8a22761a..f89a4882 100644 --- a/mach/ns/libem/rck.s +++ b/mach/ns/libem/rck.s @@ -1,6 +1,11 @@ .define .rck +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text - .text + .sect .text .rck: cmpd 0(4(sp)), 8(sp) diff --git a/mach/ns/libem/rmu.s b/mach/ns/libem/rmu.s index 670a606f..0bf53d19 100644 --- a/mach/ns/libem/rmu.s +++ b/mach/ns/libem/rmu.s @@ -1,6 +1,11 @@ .define .rmu +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text - .text + .sect .text .rmu: enter[r2],0 diff --git a/mach/ns/libem/sar.s b/mach/ns/libem/sar.s index fe94845b..3b3ab4de 100644 --- a/mach/ns/libem/sar.s +++ b/mach/ns/libem/sar.s @@ -1,6 +1,11 @@ .define .sar +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text - .text + .sect .text .sar: movd tos, r2 diff --git a/mach/ns/libem/sts.s b/mach/ns/libem/sts.s index b95f0ecd..84b4145e 100644 --- a/mach/ns/libem/sts.s +++ b/mach/ns/libem/sts.s @@ -1,6 +1,11 @@ .define .sts +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text - .text + .sect .text .sts: movd tos, r7 diff --git a/mach/ns/libem/trp.s b/mach/ns/libem/trp.s index cea74e4e..274938d6 100644 --- a/mach/ns/libem/trp.s +++ b/mach/ns/libem/trp.s @@ -1,6 +1,11 @@ .define .trp +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text - .text + .sect .text .trp: save [r0, r1] diff --git a/mach/ns/libsys/stty.s b/mach/ns/libsys/stty.s index 2a3fcc44..57266bac 100644 --- a/mach/ns/libsys/stty.s +++ b/mach/ns/libsys/stty.s @@ -1,6 +1,11 @@ .define _stty +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _stty -.text +.sect .text _stty: enter[], 0 movd 12(fp),tos diff --git a/mach/ns/libsys/sync.s b/mach/ns/libsys/sync.s index e0197ac6..b4d528bd 100644 --- a/mach/ns/libsys/sync.s +++ b/mach/ns/libsys/sync.s @@ -1,6 +1,11 @@ .define _sync +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _sync -.text +.sect .text _sync: enter[], 0 movd 36,tos diff --git a/mach/ns/libsys/tell.s b/mach/ns/libsys/tell.s index 4623614b..6456247c 100644 --- a/mach/ns/libsys/tell.s +++ b/mach/ns/libsys/tell.s @@ -1,6 +1,11 @@ .define _tell +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _tell -.text +.sect .text _tell: enter[], 0 movd 1,tos diff --git a/mach/ns/libsys/time.s b/mach/ns/libsys/time.s index 9453664c..c7b5b6e0 100644 --- a/mach/ns/libsys/time.s +++ b/mach/ns/libsys/time.s @@ -1,6 +1,11 @@ .define _time +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _time -.text +.sect .text _time: enter[], 12 addr -12(fp),tos diff --git a/mach/ns/libsys/times.s b/mach/ns/libsys/times.s index d7a26712..3f55a40c 100644 --- a/mach/ns/libsys/times.s +++ b/mach/ns/libsys/times.s @@ -1,6 +1,11 @@ .define _times +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _times -.text +.sect .text _times: enter[], 0 movd 8(fp),tos diff --git a/mach/ns/libsys/umask.s b/mach/ns/libsys/umask.s index 4f2f63cf..7696dc7c 100644 --- a/mach/ns/libsys/umask.s +++ b/mach/ns/libsys/umask.s @@ -1,6 +1,11 @@ .define _umask +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _umask -.text +.sect .text _umask: enter[], 0 movd 8(fp),tos diff --git a/mach/ns/libsys/umount.s b/mach/ns/libsys/umount.s index f1259bf0..430ec986 100644 --- a/mach/ns/libsys/umount.s +++ b/mach/ns/libsys/umount.s @@ -1,6 +1,11 @@ .define _umount +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _umount -.text +.sect .text _umount: enter[], 0 movd 8(fp),tos diff --git a/mach/ns/libsys/unlink.s b/mach/ns/libsys/unlink.s index d5617c1c..0cdade02 100644 --- a/mach/ns/libsys/unlink.s +++ b/mach/ns/libsys/unlink.s @@ -1,6 +1,11 @@ .define _unlink +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _unlink -.text +.sect .text _unlink: enter[], 0 movd 8(fp),tos diff --git a/mach/ns/libsys/utime.s b/mach/ns/libsys/utime.s index 0c98b789..8ce39307 100644 --- a/mach/ns/libsys/utime.s +++ b/mach/ns/libsys/utime.s @@ -1,6 +1,11 @@ .define _utime +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _utime -.text +.sect .text _utime: enter[], 0 movd 12(fp),tos diff --git a/mach/ns/libsys/wait.s b/mach/ns/libsys/wait.s index b63a2586..dd8eae05 100644 --- a/mach/ns/libsys/wait.s +++ b/mach/ns/libsys/wait.s @@ -1,6 +1,11 @@ .define _wait +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _wait -.text +.sect .text _wait: enter[], 0 movd 7,tos diff --git a/mach/ns/libsys/write.s b/mach/ns/libsys/write.s index ab89b528..43866f27 100644 --- a/mach/ns/libsys/write.s +++ b/mach/ns/libsys/write.s @@ -1,6 +1,11 @@ .define _write +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _write -.text +.sect .text _write: enter[], 0 save [r0,r1,r2,r3] From 16c4a067889683a9c8e72cbaefa679fcaab7f0f8 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 16 Jan 1987 16:50:50 +0000 Subject: [PATCH 0502/1625] new version for generating .o files --- mach/ns/libem/Makefile | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/mach/ns/libem/Makefile b/mach/ns/libem/Makefile index 7c0ddba4..78211c40 100644 --- a/mach/ns/libem/Makefile +++ b/mach/ns/libem/Makefile @@ -1,17 +1,28 @@ # $Header$ -install: - ../../install tail_em.a tail_em - ../../install end.s tail_em.vend +MACH=ns -cmp: - -../../compare tail_em.a tail_em - -../../compare end.s end_em +all: libem_o.a end.o -clean : +install: all + ../../install libem_o.a tail_em + ../../install end.o end_em +cmp: all + -../../compare libem_o.a tail_em + -../../compare end.o end_em + +end.o: end.s + $(MACH) -I../../../h -c end.s + +libem_o.a: libem_s.a + ASAR=aal ; export ASAR ;\ + march . libem_o.a + +clean: + rm -f *.o opr : - make pr | opr + make pr | opr pr: - @arch pv tail_em.a | pr -h `pwd`/tail_em.a - @pr `pwd`/end.s + @arch pv libem_s.a | pr -h `pwd`/libem_s.a + @pr `pwd`/end.s From 17858ba48ee30d6a9db06d286447fbc64d6bc099 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 16 Jan 1987 16:51:14 +0000 Subject: [PATCH 0503/1625] new name for archive --- mach/ns/libem/LIST | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/ns/libem/LIST b/mach/ns/libem/LIST index 227c18ee..be3e0366 100644 --- a/mach/ns/libem/LIST +++ b/mach/ns/libem/LIST @@ -1,4 +1,4 @@ -tail_em.a +libem_s.a dup.s aar.s lar.s From 08af3f1781588ff9f63434c734e1befd06d63bdc Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 16 Jan 1987 16:59:41 +0000 Subject: [PATCH 0504/1625] conversion to new assembler syntax --- mach/ns/libsys/signal.s | 57 ++++++++++++++++++++++------------------- mach/ns/libsys/sigtrp.s | 7 ++++- mach/ns/libsys/stime.s | 7 ++++- 3 files changed, 43 insertions(+), 28 deletions(-) diff --git a/mach/ns/libsys/signal.s b/mach/ns/libsys/signal.s index 97d50b24..ec2a48c5 100644 --- a/mach/ns/libsys/signal.s +++ b/mach/ns/libsys/signal.s @@ -1,34 +1,39 @@ .define _signal -.data +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +.sect .data _vector: -.long 0 -.long 0 -.long 0 -.long 0 -.long 0 -.long 0 -.long 0 -.long 0 -.long 0 -.long 0 -.long 0 -.long 0 -.long 0 -.long 0 -.long 0 -.long 0 +.data4 0 +.data4 0 +.data4 0 +.data4 0 +.data4 0 +.data4 0 +.data4 0 +.data4 0 +.data4 0 +.data4 0 +.data4 0 +.data4 0 +.data4 0 +.data4 0 +.data4 0 +.data4 0 _mapvec: -.long 0 -.long 134219784 -.long 2048 -.long 0 -.long 2827 -.long 658176 -.long 3072 +.data4 0 +.data4 134219784 +.data4 2048 +.data4 0 +.data4 2827 +.data4 658176 +.data4 3072 firsttim: .extern _signal -.long 1 -.text +.data4 1 +.sect .text _signal: enter[], 16 movd 8(fp),r7 diff --git a/mach/ns/libsys/sigtrp.s b/mach/ns/libsys/sigtrp.s index b20e9172..183a5970 100644 --- a/mach/ns/libsys/sigtrp.s +++ b/mach/ns/libsys/sigtrp.s @@ -1,6 +1,11 @@ .define _sigtrp +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _sigtrp -.text +.sect .text _sigtrp: enter[], 0 movd 12(fp),tos diff --git a/mach/ns/libsys/stime.s b/mach/ns/libsys/stime.s index a41bdde1..7e2a9fd2 100644 --- a/mach/ns/libsys/stime.s +++ b/mach/ns/libsys/stime.s @@ -1,6 +1,11 @@ .define _stime +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _stime -.text +.sect .text _stime: enter[], 0 movd 0(8(fp)),tos From 85fea44d822b16c5ce25248f778d1f7c08dad8e3 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 16 Jan 1987 17:04:03 +0000 Subject: [PATCH 0505/1625] new archive name. --- mach/ns/libsys/LIST | 2 +- mach/ns/libsys/Makefile | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/mach/ns/libsys/LIST b/mach/ns/libsys/LIST index cd3829cb..c239e828 100644 --- a/mach/ns/libsys/LIST +++ b/mach/ns/libsys/LIST @@ -1,4 +1,4 @@ -LIST +libmon_s.a exit.s gtty.s signal.s diff --git a/mach/ns/libsys/Makefile b/mach/ns/libsys/Makefile index d56b82c5..cee62aac 100644 --- a/mach/ns/libsys/Makefile +++ b/mach/ns/libsys/Makefile @@ -1,18 +1,18 @@ # $Header$ MACH=ns -all: tail_mon head_em.o +all: libmon_o.a head_em.o install: all ../../install head_em.o head_em - ../../install tail_mon + ../../install libmon_o.a tail_mon cmp: all -../../compare head_em.o head_em - -../../compare tail_mon + -../../compare libmon_o.a tail_mon -tail_mon: tail_mon.a +libmon_o.a: libmon_s.a ASAR=aal ; export ASAR ;\ - march . tail_mon + march . libmon_o.a head_em.o: head_em.s $(MACH) -I../../../h -c head_em.s @@ -24,5 +24,5 @@ opr : make pr | opr pr: - @pr -h `pwd`/head_em.s head_em.s - @ar pv tail_mon.a | pr -h `pwd`/tail_mon.a + @pr `pwd`/head_em.s + @ar pv libmon_s.a | pr -h `pwd`/libmon_s.a From 0a1c65dd81910174e92113f1819f8e29c7c98f2a Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 16 Jan 1987 17:17:12 +0000 Subject: [PATCH 0506/1625] conversion to new assembler syntax --- mach/ns/ncg/mach.c | 14 +++++++------- mach/ns/ncg/mach.h | 19 +++++++++++-------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/mach/ns/ncg/mach.c b/mach/ns/ncg/mach.c index 0d33f342..965fecab 100644 --- a/mach/ns/ncg/mach.c +++ b/mach/ns/ncg/mach.c @@ -27,7 +27,7 @@ con_mult(sz) { if (sz != 4) fatal("bad icon/ucon size"); - fprintf(codefile,".long\t%s\n",str); + fprintf(codefile,".data4\t%s\n",str); } #ifdef REGVARS @@ -75,7 +75,7 @@ f_regsave(){ fprintf(codefile,"%c%s", c, regadm[i].ra_str); c = ','; } - fprintf(codefile, "], %d\n", lbytes); + fprintf(codefile, "], %ld\n", lbytes); for (i=0;i=0) fprintf(codefile, "movd %ld(fp), %s", @@ -129,17 +129,17 @@ mes(type) word type ; { prolog(nlocals) full nlocals; { #ifndef REGVARS - fprintf(codefile, "enter[], %d\n",nlocals); + fprintf(codefile, "enter[], %ld\n",nlocals); #else lbytes = nlocals; #endif } char *segname[] = { - ".text", - ".data", - ".data", - ".bss" + ".sect .text", + ".sect .data", + ".sect .rom", + ".sect .bss" }; con_float() { diff --git a/mach/ns/ncg/mach.h b/mach/ns/ncg/mach.h index 91ce7f71..225c9dcd 100644 --- a/mach/ns/ncg/mach.h +++ b/mach/ns/ncg/mach.h @@ -6,19 +6,22 @@ #define newilb(x) fprintf(codefile,"%s:\n",x) #define newdlb(x) fprintf(codefile,"%s:\n",x) #define dlbdlb(x,y) fprintf(codefile,"%s = %s\n",x,y) -#define newlbss(l,x) fprintf(codefile,"%s:.space\t%d\n",l,x); +#define newlbss(l,x) fprintf(codefile,"%s:.space\t%ld\n",l,x); -#define cst_fmt "%d" -#define off_fmt "%d" +#define cst_fmt "%ld" +#define off_fmt "%ld" #define ilb_fmt "I%03x%x" #define dlb_fmt "_%d" #define hol_fmt "hol%d" -#define hol_off "%d+hol%d" +#define hol_off "%ld+hol%d" -#define con_cst(x) fprintf(codefile,".long\t%d\n",x) -#define con_ilb(x) fprintf(codefile,".long\t%s\n",x) -#define con_dlb(x) fprintf(codefile,".long\t%s\n",x) +#define con_cst(x) fprintf(codefile,".data4\t%ld\n",x) +#define con_ilb(x) fprintf(codefile,".data4\t%s\n",x) +#define con_dlb(x) fprintf(codefile,".data4\t%s\n",x) + +#define fmt_id(fr,to) sprintf(to, "_%s", fr) + +#define modhead ".sect .text; .sect .rom; .sect .data; .sect .bss\n" -#define id_first '_' #define BSS_INIT 0 From 9653a59787451f136e75c4abc93d9a7ccd5e0855 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 16 Jan 1987 19:20:58 +0000 Subject: [PATCH 0507/1625] minor bug fix --- util/ncgg/output.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/ncgg/output.c b/util/ncgg/output.c index 978f0955..0175fb12 100644 --- a/util/ncgg/output.c +++ b/util/ncgg/output.c @@ -69,7 +69,7 @@ opnfile(f,s) FILE **f; char *s; { unlfile(f,s) FILE *f; char *s; { - fclose(f); + if (f) fclose(f); if (unlink(s)<0) error("%s incorrect, must be removed!!",s); } From f04dca514b8ec3b6dc39b283124d70bf0e41db44 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 16 Jan 1987 19:25:44 +0000 Subject: [PATCH 0508/1625] New version --- mach/ns/libem/end.s | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/mach/ns/libem/end.s b/mach/ns/libem/end.s index e8d71d80..37e1cef2 100644 --- a/mach/ns/libem/end.s +++ b/mach/ns/libem/end.s @@ -1,20 +1,16 @@ -.define endtext,enddata,endbss -.define _end, _etext, _edata +.define endtext,enddata,endbss,_etext,_edata,_end .sect .text .sect .rom .sect .data .sect .bss -.sect .text +.sect .end ! only for declaration of _end and endbss. .sect .text endtext: _etext: - .align 4 .sect .data enddata: _edata: - .align 4 - .sect .bss - .align 4 -endbss: + .sect .end _end: +endbss: From 5b3aa0f2d7004c42a75f67cb96fabcbd8c2fe699 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 19 Jan 1987 09:36:35 +0000 Subject: [PATCH 0509/1625] Added 'c'-flag --- util/arch/archiver.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/util/arch/archiver.c b/util/arch/archiver.c index 2187194e..8e985854 100644 --- a/util/arch/archiver.c +++ b/util/arch/archiver.c @@ -14,6 +14,7 @@ static char RcsId[] = "$Header$"; * t: print contents of archive * p: print named files * l: temporaries in current directory instead of /tmp + * c: don't give "create" message */ #include @@ -68,6 +69,7 @@ BOOL show_fl; BOOL pr_fl; BOOL rep_fl; BOOL del_fl; +BOOL nocr_fl; BOOL local_fl; int ar_fd; @@ -86,9 +88,9 @@ usage() error(TRUE, "usage: %s %s archive [file] ...\n", progname, #ifdef AAL - "[adrtxvl]" + "[acdrtxvl]" #else - "[adprtxvl]" + "[acdprtxvl]" #endif ); } @@ -148,7 +150,7 @@ register int mode; if ((fd = open(name, mode)) < 0) { if (mode == APPEND) { close(open_archive(name, CREATE)); - error(FALSE, "%s: creating %s\n", progname, name); + if (!nocr_fl) error(FALSE, "%s: creating %s\n", progname, name); return open_archive(name, APPEND); } error(TRUE, "cannot open %s\n", name); @@ -193,6 +195,9 @@ char *argv[]; case 'a' : app_fl = TRUE; break; + case 'c' : + nocr_fl = TRUE; + break; #ifndef AAL case 'p' : pr_fl = TRUE; From 9dedb98dcb1430a8545662fff02de885cba31d6f Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 19 Jan 1987 09:41:49 +0000 Subject: [PATCH 0510/1625] Added c-flag --- util/arch/aal.1 | 12 +++++++++++- util/arch/arch.1 | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/util/arch/aal.1 b/util/arch/aal.1 index ce73e5e0..8e6a3b15 100644 --- a/util/arch/aal.1 +++ b/util/arch/aal.1 @@ -20,7 +20,7 @@ is one character from the set .B adrtx, optionally concatenated with one or more of -.B vl. +.B vlc. .I Afile is the archive file. The @@ -70,6 +70,16 @@ Normally .I aal places its temporary files in the directory /tmp. This option causes them to be placed in the local directory. +.TP +.B c +Create. Normally +.I aal +will create +.I afile +when it needs to. +The create option supresses the normal message that is produced when +.I afile +is created. .SH FILES /tmp/ar.* temporaries .SH "SEE ALSO" diff --git a/util/arch/arch.1 b/util/arch/arch.1 index 7d688307..f93bf680 100644 --- a/util/arch/arch.1 +++ b/util/arch/arch.1 @@ -18,7 +18,7 @@ is one character from the set .B adrtpx, optionally concatenated with one or more of -.B vl. +.B vlc. .I Afile is the archive file. The @@ -74,6 +74,16 @@ Normally .I arch places its temporary files in the directory /tmp. This option causes them to be placed in the local directory. +.TP +.B c +Create. Normally +.I arch +will create +.I afile +when it needs to. +The create option supresses the normal message that is produced when +.I afile +is created. .SH FILES /tmp/ar.* temporaries .SH "SEE ALSO" From b1d52e29ec5a0423e9d8b053f7b120499e06a794 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 19 Jan 1987 10:17:58 +0000 Subject: [PATCH 0511/1625] Improved the "make clean" --- mach/ns/libsys/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/ns/libsys/Makefile b/mach/ns/libsys/Makefile index cee62aac..955ce97d 100644 --- a/mach/ns/libsys/Makefile +++ b/mach/ns/libsys/Makefile @@ -18,7 +18,7 @@ head_em.o: head_em.s $(MACH) -I../../../h -c head_em.s clean: - rm -f *.o + rm -f *.o libmon_o.a nohup.out Out opr : make pr | opr From 4f5efe3a3eec3db1e448055b757a58cda3203f42 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 19 Jan 1987 10:19:56 +0000 Subject: [PATCH 0512/1625] Improved "make clean" --- mach/ns/libem/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mach/ns/libem/Makefile b/mach/ns/libem/Makefile index 78211c40..9f7b50d8 100644 --- a/mach/ns/libem/Makefile +++ b/mach/ns/libem/Makefile @@ -19,7 +19,8 @@ libem_o.a: libem_s.a march . libem_o.a clean: - rm -f *.o + rm -f *.o libem_o.a nohup.out Out + opr : make pr | opr From 0ea3ebf826f8b5e051651fbb4339eefbab43da41 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 19 Jan 1987 10:26:43 +0000 Subject: [PATCH 0513/1625] Initial revision --- mach/ns/libpc/Makefile | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 mach/ns/libpc/Makefile diff --git a/mach/ns/libpc/Makefile b/mach/ns/libpc/Makefile new file mode 100644 index 00000000..0c68be57 --- /dev/null +++ b/mach/ns/libpc/Makefile @@ -0,0 +1,20 @@ +MAKEFILE=../../proto/libg/Makefile +MACHDEF="MACH=ns" "SUF=o" "ASAR=aal" +PCDEF="PREF=pc" "SUB=" "SRC=lang/pc/libpc" + +install: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) cp + +cmp: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) all + -../../compare head_pc + -../../compare tail_pc + +clean: + -rm -f *.old *.[ce$(SUF)] tail* head* + +opr: + make pr | opr + +pr: + @pr Makefile From c082f5dbe5a4506721b6bb23b98d1890856cd7e3 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 19 Jan 1987 10:32:32 +0000 Subject: [PATCH 0514/1625] Initial revision --- mach/ns/libpc/compmodule | 4 ++++ 1 file changed, 4 insertions(+) create mode 100755 mach/ns/libpc/compmodule diff --git a/mach/ns/libpc/compmodule b/mach/ns/libpc/compmodule new file mode 100755 index 00000000..846ba6f1 --- /dev/null +++ b/mach/ns/libpc/compmodule @@ -0,0 +1,4 @@ +if ${MACH?ack} -I../../../h ${MACHFL?} $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 +fi From 74f3ee92062ffb768272c8f9cf28aa9a00041838 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 19 Jan 1987 10:33:24 +0000 Subject: [PATCH 0515/1625] exit when compilation fails --- mach/ns/libcc/compmodule | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/ns/libcc/compmodule b/mach/ns/libcc/compmodule index 6b964394..846ba6f1 100755 --- a/mach/ns/libcc/compmodule +++ b/mach/ns/libcc/compmodule @@ -1,4 +1,4 @@ if ${MACH?ack} -I../../../h ${MACHFL?} $1 1>&2 then echo `basename $1 $2`.o -else rm -f `basename $1 $2`.o +else exit 1 fi From 99877959463b9f49c902c8f3d7570eaeb7b95fc7 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 19 Jan 1987 10:36:27 +0000 Subject: [PATCH 0516/1625] exit on compilation error --- mach/ns/libbc/compmodule | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/ns/libbc/compmodule b/mach/ns/libbc/compmodule index 6b964394..846ba6f1 100755 --- a/mach/ns/libbc/compmodule +++ b/mach/ns/libbc/compmodule @@ -1,4 +1,4 @@ if ${MACH?ack} -I../../../h ${MACHFL?} $1 1>&2 then echo `basename $1 $2`.o -else rm -f `basename $1 $2`.o +else exit 1 fi From c0dac924b4c4ec75448fb3d43f893bfd37627d91 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 19 Jan 1987 10:37:38 +0000 Subject: [PATCH 0517/1625] ASAR=aal --- mach/ns/libbc/Makefile | 2 +- mach/ns/libcc/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mach/ns/libbc/Makefile b/mach/ns/libbc/Makefile index 333eb2fa..225d8173 100644 --- a/mach/ns/libbc/Makefile +++ b/mach/ns/libbc/Makefile @@ -1,5 +1,5 @@ MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=ns" "SUF=o" +MACHDEF="MACH=ns" "SUF=o" "ASAR=aal" BCDEF="PREF=bc" "SUB=" "SRC=lang/basic/lib" install: diff --git a/mach/ns/libcc/Makefile b/mach/ns/libcc/Makefile index 323781a1..848d185f 100644 --- a/mach/ns/libcc/Makefile +++ b/mach/ns/libcc/Makefile @@ -1,5 +1,5 @@ MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=ns" "SUF=o" +MACHDEF="MACH=ns" "SUF=o" "ASAR=aal" STDIO="PREF=cc" "SUB=.1s" "SRC=lang/cem/libcc/stdio" GEN="PREF=cc" "SUB=.2g" "SRC=lang/cem/libcc/gen" MON="PREF=mon" "SRC=lang/cem/libcc/mon" From 0ee423540ce6b145cbb62b8938da4b01a7238453 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 19 Jan 1987 10:42:34 +0000 Subject: [PATCH 0518/1625] bug fix --- mach/ns/ncg/mach.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mach/ns/ncg/mach.c b/mach/ns/ncg/mach.c index 965fecab..1cc07112 100644 --- a/mach/ns/ncg/mach.c +++ b/mach/ns/ncg/mach.c @@ -68,9 +68,9 @@ i_regsave() { f_regsave(){ register i; - register int c = '['; + register int c = ' '; - fprintf(codefile, "enter "); + fprintf(codefile, "enter ["); for (i=0; i Date: Mon, 19 Jan 1987 10:51:50 +0000 Subject: [PATCH 0519/1625] new version for new assembler syntax --- mach/z8000/libem/LIST | 2 +- mach/z8000/libem/Makefile | 9 +++++---- mach/z8000/libem/aar.s | 5 +++++ mach/z8000/libem/blm.s | 5 +++++ mach/z8000/libem/cii.s | 5 +++++ mach/z8000/libem/cmi.s | 5 +++++ mach/z8000/libem/cmi4.s | 5 +++++ mach/z8000/libem/cms.s | 5 +++++ mach/z8000/libem/cmu.s | 5 +++++ mach/z8000/libem/cmu4.s | 5 +++++ mach/z8000/libem/csa.s | 5 +++++ mach/z8000/libem/csb.s | 5 +++++ mach/z8000/libem/cuu.s | 5 +++++ mach/z8000/libem/dup.s | 5 +++++ mach/z8000/libem/dvu2.s | 5 +++++ mach/z8000/libem/dvu4.s | 5 +++++ mach/z8000/libem/end.s | 18 ++++++++++-------- mach/z8000/libem/exg.s | 5 +++++ mach/z8000/libem/gto.s | 5 +++++ mach/z8000/libem/head_em.s | 27 ++++++++++++++++----------- mach/z8000/libem/inn.s | 5 +++++ mach/z8000/libem/lar.s | 5 +++++ mach/z8000/libem/los2.s | 5 +++++ mach/z8000/libem/mon.s | 5 +++++ mach/z8000/libem/noop.s | 7 ++++++- mach/z8000/libem/prf.s | 9 +++++++-- mach/z8000/libem/printf.s | 7 ++++++- mach/z8000/libem/rck.s | 5 +++++ mach/z8000/libem/rmu2.s | 5 +++++ mach/z8000/libem/rmu4.s | 5 +++++ mach/z8000/libem/sar.s | 5 +++++ mach/z8000/libem/save.s | 9 +++++++-- mach/z8000/libem/sigtrp.s | 5 +++++ mach/z8000/libem/strhp.s | 5 +++++ mach/z8000/libem/sts2.s | 5 +++++ mach/z8000/libem/trp.s | 7 ++++++- mach/z8000/libem/unknown.s | 5 +++++ mach/z8000/libem/xset.s | 5 +++++ 38 files changed, 209 insertions(+), 31 deletions(-) diff --git a/mach/z8000/libem/LIST b/mach/z8000/libem/LIST index f7d9999d..dde4ae89 100644 --- a/mach/z8000/libem/LIST +++ b/mach/z8000/libem/LIST @@ -1,4 +1,4 @@ -tail_em.s.a +libem_s.a aar.s blm.s cii.s diff --git a/mach/z8000/libem/Makefile b/mach/z8000/libem/Makefile index 486aa5d7..b94059f9 100644 --- a/mach/z8000/libem/Makefile +++ b/mach/z8000/libem/Makefile @@ -1,11 +1,12 @@ +all: install: ../../install head_em.s head_em - ../../install tail_em.s.a tail_em + ../../install libem_s.a tail_em cmp: -../../compare head_em.s head_em - -../../compare tail_em.s.a tail_em + -../../compare libem_s.a tail_em clean: @@ -13,5 +14,5 @@ opr : make pr | opr pr: - @pr head_em.s - @arch pv tail_em.s.a | pr -h `pwd`/tail_em.s.a + @pr `pwd`/head_em.s + @arch pv libem_s.a | pr -h `pwd`/libem_s.a diff --git a/mach/z8000/libem/aar.s b/mach/z8000/libem/aar.s index 1cf46784..3b004cf9 100644 --- a/mach/z8000/libem/aar.s +++ b/mach/z8000/libem/aar.s @@ -1,4 +1,9 @@ .define aar +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text !R1 contains description address !R3 contains element number diff --git a/mach/z8000/libem/blm.s b/mach/z8000/libem/blm.s index de643ebb..12b61e6a 100644 --- a/mach/z8000/libem/blm.s +++ b/mach/z8000/libem/blm.s @@ -1,4 +1,9 @@ .define blm +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text !size in R0 blm: diff --git a/mach/z8000/libem/cii.s b/mach/z8000/libem/cii.s index 686f1036..9d25a9c6 100644 --- a/mach/z8000/libem/cii.s +++ b/mach/z8000/libem/cii.s @@ -1,4 +1,9 @@ .define cii +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text cii: popl saveret, *RR14 diff --git a/mach/z8000/libem/cmi.s b/mach/z8000/libem/cmi.s index 5459aec8..1980f9f8 100644 --- a/mach/z8000/libem/cmi.s +++ b/mach/z8000/libem/cmi.s @@ -1,4 +1,9 @@ .define cmi +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text !size in R0 cmi: diff --git a/mach/z8000/libem/cmi4.s b/mach/z8000/libem/cmi4.s index ac3ff4e1..4cb9859b 100644 --- a/mach/z8000/libem/cmi4.s +++ b/mach/z8000/libem/cmi4.s @@ -1,4 +1,9 @@ .define cmi4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text cmi4: popl saveret, *RR14 diff --git a/mach/z8000/libem/cms.s b/mach/z8000/libem/cms.s index cfe26c4c..1747739e 100644 --- a/mach/z8000/libem/cms.s +++ b/mach/z8000/libem/cms.s @@ -1,4 +1,9 @@ .define cms +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text cms: popl saveret, *RR14 diff --git a/mach/z8000/libem/cmu.s b/mach/z8000/libem/cmu.s index c3b96136..e7fda3e4 100644 --- a/mach/z8000/libem/cmu.s +++ b/mach/z8000/libem/cmu.s @@ -1,4 +1,9 @@ .define cmu +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text !size in R0 cmu: diff --git a/mach/z8000/libem/cmu4.s b/mach/z8000/libem/cmu4.s index 2135b2d0..9ea7df38 100644 --- a/mach/z8000/libem/cmu4.s +++ b/mach/z8000/libem/cmu4.s @@ -1,4 +1,9 @@ .define cmu4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text cmu4: popl saveret, *RR14 diff --git a/mach/z8000/libem/csa.s b/mach/z8000/libem/csa.s index e4fd1b96..4822fb9e 100644 --- a/mach/z8000/libem/csa.s +++ b/mach/z8000/libem/csa.s @@ -1,4 +1,9 @@ .define csa +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text !R1 contains address of jump table !R2 contains case index diff --git a/mach/z8000/libem/csb.s b/mach/z8000/libem/csb.s index de145d96..f6db0101 100644 --- a/mach/z8000/libem/csb.s +++ b/mach/z8000/libem/csb.s @@ -1,4 +1,9 @@ .define csb +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text !R1 contains address of jump table !R2 contains case index diff --git a/mach/z8000/libem/cuu.s b/mach/z8000/libem/cuu.s index 7e60c5e8..ac7466a9 100644 --- a/mach/z8000/libem/cuu.s +++ b/mach/z8000/libem/cuu.s @@ -1,4 +1,9 @@ .define cuu +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text cuu: popl RR2, *RR14 diff --git a/mach/z8000/libem/dup.s b/mach/z8000/libem/dup.s index 74aa6809..f27743b7 100644 --- a/mach/z8000/libem/dup.s +++ b/mach/z8000/libem/dup.s @@ -1,4 +1,9 @@ .define dup +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text dup: popl saveret, *RR14 diff --git a/mach/z8000/libem/dvu2.s b/mach/z8000/libem/dvu2.s index d1403722..1b2687be 100644 --- a/mach/z8000/libem/dvu2.s +++ b/mach/z8000/libem/dvu2.s @@ -1,4 +1,9 @@ .define dvu2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text dvu2: popl saveret, *RR14 diff --git a/mach/z8000/libem/dvu4.s b/mach/z8000/libem/dvu4.s index d5fc9617..63cdc40e 100644 --- a/mach/z8000/libem/dvu4.s +++ b/mach/z8000/libem/dvu4.s @@ -1,4 +1,9 @@ .define dvu4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text dvu4: popl saveret, *RR14 diff --git a/mach/z8000/libem/end.s b/mach/z8000/libem/end.s index c35d844a..37e1cef2 100644 --- a/mach/z8000/libem/end.s +++ b/mach/z8000/libem/end.s @@ -1,14 +1,16 @@ -.define endtext, enddata, endbss, _etext, _edata, _end +.define endtext,enddata,endbss,_etext,_edata,_end +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .end ! only for declaration of _end and endbss. - .text + .sect .text endtext: _etext: - .align 2 - .data - .align 2 + .sect .data enddata: _edata: - .bss - .align 2 -endbss: + .sect .end _end: +endbss: diff --git a/mach/z8000/libem/exg.s b/mach/z8000/libem/exg.s index 79061cc2..540ff874 100644 --- a/mach/z8000/libem/exg.s +++ b/mach/z8000/libem/exg.s @@ -1,4 +1,9 @@ .define exg +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text !size (bytes) in R0 exg: diff --git a/mach/z8000/libem/gto.s b/mach/z8000/libem/gto.s index 4c78b235..1fd78696 100644 --- a/mach/z8000/libem/gto.s +++ b/mach/z8000/libem/gto.s @@ -1,4 +1,9 @@ .define gto +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text gto: pop R3, *RR14 diff --git a/mach/z8000/libem/head_em.s b/mach/z8000/libem/head_em.s index 202fcbcb..fa8e20a0 100644 --- a/mach/z8000/libem/head_em.s +++ b/mach/z8000/libem/head_em.s @@ -1,6 +1,11 @@ .define EXIT, F_DUM .define ERANGE, ESET, EHEAP, EILLINS, EODDZ, ECASE, EBADMON .define hol0, trppc, trpim, reghp, argv, envp +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text EXIT = 0 F_DUM = 0 @@ -13,8 +18,8 @@ EODDZ = 19 ECASE = 20 EBADMON = 25 -.text - !clear .bss +.sect .text + !clear .sect .bss ldk R2, $0 ld R3, $endbss ld R0, R3 @@ -38,20 +43,20 @@ EBADMON = 25 ldl RR14, $0xC00017FC sc $0 -.bss +.sect .bss begbss: -.data +.sect .data hol0: - .word 0,0 ! line no - .word 0,0 ! file + .data2 0,0 ! line no + .data2 0,0 ! file trppc: - .word 0 + .data2 0 trpim: - .word 0 + .data2 0 argv: envp: - .word 1f - .word 0 + .data2 1f + .data2 0 1: .asciz "program" reghp: - .word endbss + .data2 endbss diff --git a/mach/z8000/libem/inn.s b/mach/z8000/libem/inn.s index ba8ac0f4..11dd15d3 100644 --- a/mach/z8000/libem/inn.s +++ b/mach/z8000/libem/inn.s @@ -1,4 +1,9 @@ .define inn +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text !bitnr in R1 !size (bytes) in R2 diff --git a/mach/z8000/libem/lar.s b/mach/z8000/libem/lar.s index bf82bbb6..83e69ab2 100644 --- a/mach/z8000/libem/lar.s +++ b/mach/z8000/libem/lar.s @@ -1,4 +1,9 @@ .define lar +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text !R1 contains description address !R3 contains element number diff --git a/mach/z8000/libem/los2.s b/mach/z8000/libem/los2.s index a6b9d3e6..ca6c21c7 100644 --- a/mach/z8000/libem/los2.s +++ b/mach/z8000/libem/los2.s @@ -1,4 +1,9 @@ .define los2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text los2: popl saveret, *RR14 diff --git a/mach/z8000/libem/mon.s b/mach/z8000/libem/mon.s index 3d971be1..407a9c57 100644 --- a/mach/z8000/libem/mon.s +++ b/mach/z8000/libem/mon.s @@ -1,4 +1,9 @@ .define mon +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text mon: popl saveret, *RR14 diff --git a/mach/z8000/libem/noop.s b/mach/z8000/libem/noop.s index f6c16c0a..2042941e 100644 --- a/mach/z8000/libem/noop.s +++ b/mach/z8000/libem/noop.s @@ -1,9 +1,14 @@ .define noop +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text noop: push *RR14, hol0 push *RR14, $fmt calr prf ret -.data +.sect .data fmt: .asciz "test %d\n" diff --git a/mach/z8000/libem/prf.s b/mach/z8000/libem/prf.s index 9491b142..e892f84e 100644 --- a/mach/z8000/libem/prf.s +++ b/mach/z8000/libem/prf.s @@ -1,4 +1,9 @@ .define prf +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text prf: ld R0, hol0+4 !pointer to filename @@ -29,8 +34,8 @@ prf: ret 1: ld R0, $name jr 2b -.data +.sect .data fmt1: .asciz "%s, sp = %x, line %d:\n" name: .asciz "_unknown file_" saveprf: - .long 0 + .data4 0 diff --git a/mach/z8000/libem/printf.s b/mach/z8000/libem/printf.s index 0e511b9d..56ca133c 100755 --- a/mach/z8000/libem/printf.s +++ b/mach/z8000/libem/printf.s @@ -1,4 +1,9 @@ .define printf +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text printf: popl saveret, *RR14 @@ -77,6 +82,6 @@ printn: inc R3 ret -.data +.sect .data buff: .space 256 diff --git a/mach/z8000/libem/rck.s b/mach/z8000/libem/rck.s index cf36d8c4..9d33b4b6 100644 --- a/mach/z8000/libem/rck.s +++ b/mach/z8000/libem/rck.s @@ -1,4 +1,9 @@ .define rck +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text rck: ld R0, RR14($4) diff --git a/mach/z8000/libem/rmu2.s b/mach/z8000/libem/rmu2.s index 1bdcb4d4..5dbd8236 100644 --- a/mach/z8000/libem/rmu2.s +++ b/mach/z8000/libem/rmu2.s @@ -1,4 +1,9 @@ .define rmu2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text rmu2: popl saveret, *RR14 diff --git a/mach/z8000/libem/rmu4.s b/mach/z8000/libem/rmu4.s index 1604f734..74f10d54 100644 --- a/mach/z8000/libem/rmu4.s +++ b/mach/z8000/libem/rmu4.s @@ -1,4 +1,9 @@ .define rmu4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text rmu4: popl saveret, *RR14 diff --git a/mach/z8000/libem/sar.s b/mach/z8000/libem/sar.s index 509003a2..721c0461 100644 --- a/mach/z8000/libem/sar.s +++ b/mach/z8000/libem/sar.s @@ -1,4 +1,9 @@ .define sar +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text !R1 contains description address !R3 contains element number diff --git a/mach/z8000/libem/save.s b/mach/z8000/libem/save.s index ef704dd5..66a1715d 100644 --- a/mach/z8000/libem/save.s +++ b/mach/z8000/libem/save.s @@ -1,8 +1,13 @@ .define saveret .define savereg +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text -.data +.sect .data saveret: - .long 0 + .data4 0 savereg: .space 20 diff --git a/mach/z8000/libem/sigtrp.s b/mach/z8000/libem/sigtrp.s index e69de29b..c9890d7e 100644 --- a/mach/z8000/libem/sigtrp.s +++ b/mach/z8000/libem/sigtrp.s @@ -0,0 +1,5 @@ +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text diff --git a/mach/z8000/libem/strhp.s b/mach/z8000/libem/strhp.s index a987aa31..db6bc5a0 100644 --- a/mach/z8000/libem/strhp.s +++ b/mach/z8000/libem/strhp.s @@ -1,4 +1,9 @@ .define strhp +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text strhp: popl RR2, *RR14 diff --git a/mach/z8000/libem/sts2.s b/mach/z8000/libem/sts2.s index 2c404ca2..37e06af2 100644 --- a/mach/z8000/libem/sts2.s +++ b/mach/z8000/libem/sts2.s @@ -1,4 +1,9 @@ .define sts2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text sts2: popl saveret, *RR14 diff --git a/mach/z8000/libem/trp.s b/mach/z8000/libem/trp.s index f9efd641..82ed1df9 100644 --- a/mach/z8000/libem/trp.s +++ b/mach/z8000/libem/trp.s @@ -1,4 +1,9 @@ .define trp, fatal +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text fatal: calr trp @@ -34,5 +39,5 @@ trp: 3: push *RR14, $err calr printf sc $EXIT -.data +.sect .data err: .asciz "trap error %d\n" diff --git a/mach/z8000/libem/unknown.s b/mach/z8000/libem/unknown.s index e3e2e819..c7ac93d3 100644 --- a/mach/z8000/libem/unknown.s +++ b/mach/z8000/libem/unknown.s @@ -1,4 +1,9 @@ .define unknown +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text unknown: push *RR14, $EODDZ diff --git a/mach/z8000/libem/xset.s b/mach/z8000/libem/xset.s index 7ed57945..8a6369af 100644 --- a/mach/z8000/libem/xset.s +++ b/mach/z8000/libem/xset.s @@ -1,4 +1,9 @@ .define xset +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text !bitnr in R1 !size (bytes) in R0 From d608ec850d0fa9662ae785601380e7084e2b2ec8 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 19 Jan 1987 10:52:25 +0000 Subject: [PATCH 0520/1625] Added exit in case of compilation failure --- mach/z8000/libbc/compmodule | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mach/z8000/libbc/compmodule b/mach/z8000/libbc/compmodule index 28461326..081a9755 100755 --- a/mach/z8000/libbc/compmodule +++ b/mach/z8000/libbc/compmodule @@ -1,2 +1,4 @@ -${MACH?} -I../../../h ${MACHFL?} $1 1>&2 -echo `basename $1 $2`.s +if ${MACH?ack} -I../../../h ${MACHFL?} $1 1>&2 +then echo `basename $1 $2`.s +else exit 1 +fi From 7f8c25ea9dba85e70aff7b30d1169523c54ffe65 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 19 Jan 1987 10:53:45 +0000 Subject: [PATCH 0521/1625] *** empty log message *** --- mach/z8000/libcc/compmodule | 6 ++++-- mach/z8000/libpc/compmodule | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/mach/z8000/libcc/compmodule b/mach/z8000/libcc/compmodule index 28461326..081a9755 100755 --- a/mach/z8000/libcc/compmodule +++ b/mach/z8000/libcc/compmodule @@ -1,2 +1,4 @@ -${MACH?} -I../../../h ${MACHFL?} $1 1>&2 -echo `basename $1 $2`.s +if ${MACH?ack} -I../../../h ${MACHFL?} $1 1>&2 +then echo `basename $1 $2`.s +else exit 1 +fi diff --git a/mach/z8000/libpc/compmodule b/mach/z8000/libpc/compmodule index 28461326..081a9755 100755 --- a/mach/z8000/libpc/compmodule +++ b/mach/z8000/libpc/compmodule @@ -1,2 +1,4 @@ -${MACH?} -I../../../h ${MACHFL?} $1 1>&2 -echo `basename $1 $2`.s +if ${MACH?ack} -I../../../h ${MACHFL?} $1 1>&2 +then echo `basename $1 $2`.s +else exit 1 +fi From 07867a1f886f832d4c1cac076936ee8d366b335f Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 19 Jan 1987 15:20:49 +0000 Subject: [PATCH 0522/1625] end.s separate from libem_s.a --- mach/z8000/libem/LIST | 1 - mach/z8000/libem/Makefile | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/mach/z8000/libem/LIST b/mach/z8000/libem/LIST index dde4ae89..de1186d8 100644 --- a/mach/z8000/libem/LIST +++ b/mach/z8000/libem/LIST @@ -33,4 +33,3 @@ unknown.s trp.s printf.s save.s -end.s diff --git a/mach/z8000/libem/Makefile b/mach/z8000/libem/Makefile index b94059f9..b2c179d9 100644 --- a/mach/z8000/libem/Makefile +++ b/mach/z8000/libem/Makefile @@ -3,10 +3,12 @@ all: install: ../../install head_em.s head_em ../../install libem_s.a tail_em + ../../install end.s end_em cmp: -../../compare head_em.s head_em -../../compare libem_s.a tail_em + -../../compare end.s end_em clean: @@ -16,3 +18,4 @@ opr : pr: @pr `pwd`/head_em.s @arch pv libem_s.a | pr -h `pwd`/libem_s.a + @pr `pwd`/end.s From 1b0eeb47a10f901628225c85c2f2a147d8271853 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 20 Jan 1987 09:31:31 +0000 Subject: [PATCH 0523/1625] Bug fix in translation of "cms" --- mach/vax4/cg/table | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/mach/vax4/cg/table b/mach/vax4/cg/table index 941cf0cf..daa30039 100644 --- a/mach/vax4/cg/table +++ b/mach/vax4/cg/table @@ -3156,15 +3156,8 @@ cmp | source4 source4 | erase(%[a]) setcc(%[a]) | %[a] | | cms $1==4 | source4 source4 | - allocate(REG={CONST4,0}) - "cmpl\t%[1],%[2]" -#ifdef LOCLABS - "bneq\t1f" - "incl\t%[a]\n1:" -#else - "bneq\t.+4" - "incl\t%[a]" -#endif + allocate(%[1],%[2],REG) + "xorl3\t%[1],%[2],%[a]" setcc(%[a]) erase(%[a]) | %[a] | | cms defined($1) | STACK | From 572c33c82279dce4f69cdf2807c7d5874571aab8 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 20 Jan 1987 09:53:32 +0000 Subject: [PATCH 0524/1625] Bug fix Under the '-x' option, the archive was opened in "APPEND" mode. --- util/arch/archiver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/arch/archiver.c b/util/arch/archiver.c index 8e985854..35efbfef 100644 --- a/util/arch/archiver.c +++ b/util/arch/archiver.c @@ -264,7 +264,7 @@ register char *argv[]; int i = 0; int temp_fd, read_chars; - ar_fd = open_archive(argv[2], (show_fl || pr_fl) ? READ : APPEND); + ar_fd = open_archive(argv[2], (show_fl || pr_fl || ex_fl) ? READ : APPEND); if (rep_fl || del_fl #ifdef AAL || app_fl From 308da946ff8580badba3e092408b77cef9e098f8 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 20 Jan 1987 10:04:32 +0000 Subject: [PATCH 0525/1625] Adapted to new assembler syntax --- mach/z8000/cg/mach.c | 12 ++++++------ mach/z8000/cg/mach.h | 13 +++++++------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/mach/z8000/cg/mach.c b/mach/z8000/cg/mach.c index e6221a59..68790948 100644 --- a/mach/z8000/cg/mach.c +++ b/mach/z8000/cg/mach.c @@ -41,7 +41,7 @@ con_mult(sz) word sz; { if (sz != 4) fatal("bad icon/ucon size"); - fprintf(codefile,"\t.long %s\n", str); + fprintf(codefile,"\t.data4 %s\n", str); } con_float() { @@ -49,7 +49,7 @@ con_float() { static int been_here; if (argval != 4 && argval != 8) fatal("bad fcon size"); - fprintf(codefile,"\t.long "); + fprintf(codefile,"\t.data4 "); if (argval == 8) fprintf(codefile,"F_DUM, "); fprintf(codefile,"F_DUM\n"); @@ -100,8 +100,8 @@ mes(type) word type ; { } char *segname[] = { - ".text", /* SEGTXT */ - ".data", /* SEGCON */ - ".data", /* SEGROM */ - ".bss" /* SEGBSS */ + ".sect .text", /* SEGTXT */ + ".sect .data", /* SEGCON */ + ".sect .rom", /* SEGROM */ + ".sect .bss" /* SEGBSS */ }; diff --git a/mach/z8000/cg/mach.h b/mach/z8000/cg/mach.h index 868cb725..35f6f3cd 100644 --- a/mach/z8000/cg/mach.h +++ b/mach/z8000/cg/mach.h @@ -8,17 +8,18 @@ #define cst_fmt "%d" #define off_fmt "%d" -#define ilb_fmt "I%03x%x" +#define ilb_fmt "I%x_%x" #define dlb_fmt "_%d" #define hol_fmt "hol%d" #define hol_off "%d+hol%d" -#define con_cst(x) fprintf(codefile,"\t.word %d\n",x) -#define con_ilb(x) fprintf(codefile,"\t.word %s\n",x) -#define con_dlb(x) fprintf(codefile,"\t.word %s\n",x) +#define con_cst(x) fprintf(codefile,"\t.data2 %d\n",x) +#define con_ilb(x) fprintf(codefile,"\t.data2 %s\n",x) +#define con_dlb(x) fprintf(codefile,"\t.data2 %s\n",x) -#define modhead "" +#define modhead ".sect .text; .sect .rom; .sect .data; .sect .bss\n" + +#define fmt_id(sf,st) sprintf(st,"_%s", sf) -#define id_first '_' #define BSS_INIT 0 From 950bd14ca0a2a97618d9fb207a0f3a65486e8836 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 20 Jan 1987 13:09:56 +0000 Subject: [PATCH 0526/1625] Changed /lib/cpp to ../../../lib/cpp --- mach/6500/cg/Makefile | 2 +- mach/pdp/cg/Makefile | 2 +- mach/proto/cg/Makefile | 2 +- mach/vax4/cg/Makefile | 2 +- mach/z80/cg/Makefile | 2 +- mach/z8000/cg/Makefile | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mach/6500/cg/Makefile b/mach/6500/cg/Makefile index 93f97b75..54646908 100644 --- a/mach/6500/cg/Makefile +++ b/mach/6500/cg/Makefile @@ -71,7 +71,7 @@ distr: tables.c: table -mv tables.h tables.h.save - /lib/cpp -P table | ../../../lib/cgg > debug.out + ../../../lib/cpp -P table | ../../../lib/cgg > debug.out -if cmp -s tables.h.save tables.h; then mv tables.h.save tables.h; else exit 0; fi -if cmp -s /dev/null tables.h; then mv tables.h.save tables.h; else exit 0; fi diff --git a/mach/pdp/cg/Makefile b/mach/pdp/cg/Makefile index 93f97b75..54646908 100644 --- a/mach/pdp/cg/Makefile +++ b/mach/pdp/cg/Makefile @@ -71,7 +71,7 @@ distr: tables.c: table -mv tables.h tables.h.save - /lib/cpp -P table | ../../../lib/cgg > debug.out + ../../../lib/cpp -P table | ../../../lib/cgg > debug.out -if cmp -s tables.h.save tables.h; then mv tables.h.save tables.h; else exit 0; fi -if cmp -s /dev/null tables.h; then mv tables.h.save tables.h; else exit 0; fi diff --git a/mach/proto/cg/Makefile b/mach/proto/cg/Makefile index 93f97b75..54646908 100644 --- a/mach/proto/cg/Makefile +++ b/mach/proto/cg/Makefile @@ -71,7 +71,7 @@ distr: tables.c: table -mv tables.h tables.h.save - /lib/cpp -P table | ../../../lib/cgg > debug.out + ../../../lib/cpp -P table | ../../../lib/cgg > debug.out -if cmp -s tables.h.save tables.h; then mv tables.h.save tables.h; else exit 0; fi -if cmp -s /dev/null tables.h; then mv tables.h.save tables.h; else exit 0; fi diff --git a/mach/vax4/cg/Makefile b/mach/vax4/cg/Makefile index 93f97b75..54646908 100644 --- a/mach/vax4/cg/Makefile +++ b/mach/vax4/cg/Makefile @@ -71,7 +71,7 @@ distr: tables.c: table -mv tables.h tables.h.save - /lib/cpp -P table | ../../../lib/cgg > debug.out + ../../../lib/cpp -P table | ../../../lib/cgg > debug.out -if cmp -s tables.h.save tables.h; then mv tables.h.save tables.h; else exit 0; fi -if cmp -s /dev/null tables.h; then mv tables.h.save tables.h; else exit 0; fi diff --git a/mach/z80/cg/Makefile b/mach/z80/cg/Makefile index 93f97b75..54646908 100644 --- a/mach/z80/cg/Makefile +++ b/mach/z80/cg/Makefile @@ -71,7 +71,7 @@ distr: tables.c: table -mv tables.h tables.h.save - /lib/cpp -P table | ../../../lib/cgg > debug.out + ../../../lib/cpp -P table | ../../../lib/cgg > debug.out -if cmp -s tables.h.save tables.h; then mv tables.h.save tables.h; else exit 0; fi -if cmp -s /dev/null tables.h; then mv tables.h.save tables.h; else exit 0; fi diff --git a/mach/z8000/cg/Makefile b/mach/z8000/cg/Makefile index 93f97b75..54646908 100644 --- a/mach/z8000/cg/Makefile +++ b/mach/z8000/cg/Makefile @@ -71,7 +71,7 @@ distr: tables.c: table -mv tables.h tables.h.save - /lib/cpp -P table | ../../../lib/cgg > debug.out + ../../../lib/cpp -P table | ../../../lib/cgg > debug.out -if cmp -s tables.h.save tables.h; then mv tables.h.save tables.h; else exit 0; fi -if cmp -s /dev/null tables.h; then mv tables.h.save tables.h; else exit 0; fi From 345a7f5d06b72397e66775c48938df3695f45ce2 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 20 Jan 1987 14:14:19 +0000 Subject: [PATCH 0527/1625] assembler now produces .o format --- lib/s2650/descr | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/s2650/descr b/lib/s2650/descr index ac6dfbaa..d0fe2ea8 100644 --- a/lib/s2650/descr +++ b/lib/s2650/descr @@ -10,11 +10,17 @@ var M=s2650 var LIB=lib/{M}/tail_ var RT=lib/{M}/head_ var INCLUDES=-I{EM}/include -I/usr/include -name asld - from .s.a - to .out - outfile a.out +name as + from .s.so + to .o program {EM}/lib/{M}/as + args - -o > < + prep cond +end +name led + from .o.a + to .out + program {EM}/lib/em_led mapflag -l* LNAME={EM}/{LIB}* args (.e:{HEAD}={EM}/{RT}em) \ ({RTS}:.b.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \ From cd907fe60bdafe1b3b863a4cc539186f8bbf8439 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 20 Jan 1987 14:20:33 +0000 Subject: [PATCH 0528/1625] new assembler producing .o files --- lib/6800/descr | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/6800/descr b/lib/6800/descr index 51150184..c4ab12f3 100644 --- a/lib/6800/descr +++ b/lib/6800/descr @@ -1,6 +1,5 @@ # $Revision$ var w=2 -var i=2 var p=2 var s=2 var l=4 @@ -11,14 +10,19 @@ var M=6800 var LIB=lib/{M}/tail_ var RT=lib/{M}/head_ var INCLUDES=-I{EM}/include -I/usr/include -name asld - from .s.a - to .out - outfile a.out +name as + from .s.so + to .o program {EM}/lib/{M}/as + args - -o > < + prep cond +end +name led + from .o.a + to .out + program {EM}/lib/em_led mapflag -l* LNAME={EM}/{LIB}* - mapflag -d* ASFL={ASFL?} -d* - args {ASFL?} (.e:{HEAD}={EM}/{RT}em) \ + args (.e:{HEAD}={EM}/{RT}em) \ ({RTS}:.b.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \ (.p:{TAIL}={EM}/{LIB}pc) \ (.b:{TAIL}={EM}/{LIB}bc) \ From 1c38ed3dcf7dd0b5cf8ce8be0865935b25f77e64 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 20 Jan 1987 14:47:49 +0000 Subject: [PATCH 0529/1625] Bug fix (?) --- modules/src/input/inp_pkg.body | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/src/input/inp_pkg.body b/modules/src/input/inp_pkg.body index c0d519f0..54f6a65e 100644 --- a/modules/src/input/inp_pkg.body +++ b/modules/src/input/inp_pkg.body @@ -81,7 +81,7 @@ struct buffer_header { #ifndef INP_READ_IN_ONE struct i_buf { struct i_buf *next; - char ib_text[INP_BUFSIZE+INP_NPUSHBACK-1]; + char ib_text[INP_BUFSIZE+INP_NPUSHBACK]; }; # endif not INP_READ_IN_ONE From a46973cfa7bfc9075b41ad9447c71377f3c5b023 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 20 Jan 1987 14:53:11 +0000 Subject: [PATCH 0530/1625] new assembler producing .o files --- lib/6805/descr | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/6805/descr b/lib/6805/descr index 9690b222..47b7f8a7 100644 --- a/lib/6805/descr +++ b/lib/6805/descr @@ -1,6 +1,5 @@ # $Revision$ var w=2 -var i=2 var p=2 var s=2 var l=4 @@ -11,14 +10,19 @@ var M=6805 var LIB=lib/{M}/tail_ var RT=lib/{M}/head_ var INCLUDES=-I{EM}/include -I/usr/include -name asld - from .s.a - to .out - outfile a.out +name as + from .s.so + to .o program {EM}/lib/{M}/as + args - -o > < + prep cond +end +name led + from .o.a + to .out + program {EM}/lib/em_led mapflag -l* LNAME={EM}/{LIB}* - mapflag -d* ASFL={ASFL?} -d* - args {ASFL?} (.e:{HEAD}={EM}/{RT}em) \ + args (.e:{HEAD}={EM}/{RT}em) \ ({RTS}:.b.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \ (.p:{TAIL}={EM}/{LIB}pc) \ (.b:{TAIL}={EM}/{LIB}bc) \ From 22def1157dbce269989fdd4c2ec3fcac16bcb49a Mon Sep 17 00:00:00 2001 From: bruce Date: Wed, 21 Jan 1987 14:27:04 +0000 Subject: [PATCH 0531/1625] Version that implements a C_XXX to O_XXX library interface. --- modules/src/em_opt/Makefile | 32 +- modules/src/em_opt/aux.c | 20 +- modules/src/em_opt/findworst.c | 7 +- modules/src/em_opt/mkcalls.c | 751 +++++++++++++++------------------ modules/src/em_opt/nopt.c | 203 ++++----- modules/src/em_opt/nopt.h | 21 +- modules/src/em_opt/outcalls.c | 36 +- modules/src/em_opt/outputdfa.c | 120 +++--- 8 files changed, 553 insertions(+), 637 deletions(-) diff --git a/modules/src/em_opt/Makefile b/modules/src/em_opt/Makefile index c8d1a557..943dacce 100644 --- a/modules/src/em_opt/Makefile +++ b/modules/src/em_opt/Makefile @@ -1,25 +1,29 @@ # $Header$ + +# Where to find em home directory + EMHOME=/usr/em MODLIB=$(EMHOME)/modules/lib -PARSERLIB=$(EMHOME)/lib/em_data.a $(MODLIB)/libprint.a $(MODLIB)/liballoc.a\ - $(MODLIB)/libstring.a $(MODLIB)/libsystem.a -HOWMUCH=head -10 + +# set HOWMUCH to head -20 to limit number of patterns used +HOWMUCH=cat + LEXLIB=-ll -INCLDIR=-I$(EMHOME)/h -I$(EMHOME)/modules/h -I$(EMHOME)/modules/pkg -PREFLAGS=$(INCLDIR) -DPRIVATE=static -DDEBUG +INCLDIR=-I$(EMHOME)/h -I$(EMHOME)/modules/h -I$(EMHOME)/modules/pkg -I../h +PREFLAGS=$(INCLDIR) -DPRIVATE=static PROFFLAG=-O CFLAGS=$(PREFLAGS) $(PROFFLAG) LLOPT= -GFILES=parser.g -POFILES=parser.o syntax.o outputdfa.o outcalls.o findworst.o outputrepl.o\ - initlex.o Lpars.o -NOFILES=nopt.o dfa.o trans.o incalls.o psuedo.o aux.o mkcalls.o + GENFILES=Lpars.h Lpars.c parserdummy parser.c syntax.c dfadummy\ dfa.c dfa.c.save trans.c trans.c.save incalls.c incalls.c.save all: libopt.a +NOFILES=nopt.o dfa.o trans.o incalls.o pseudo.o aux.o mkcalls.o + libopt.a: dfadummy $(NOFILES) + rm -f libopt.a ar rc libopt.a $(NOFILES) ranlib libopt.a @@ -35,9 +39,16 @@ dfadummy: patterns parser -if cmp -s incalls.c incalls.c.save; then mv incalls.c.save incalls.c; else exit 0; fi touch dfadummy +POFILES=parser.o syntax.o outputdfa.o outcalls.o findworst.o initlex.o Lpars.o + +PARSERLIB=$(EMHOME)/lib/em_data.a $(MODLIB)/libprint.a $(MODLIB)/liballoc.a\ + $(MODLIB)/libstring.a $(MODLIB)/libsystem.a + parser: parserdummy $(POFILES) $(PARSERLIB) $(CC) -o parser $(LDFLAGS) $(POFILES) $(PARSERLIB) $(LEXLIB) +GFILES=parser.g + parserdummy: $(GFILES) LLgen $(LLOPT) $(GFILES) touch parserdummy @@ -49,7 +60,7 @@ nopt.o: nopt.h dfa.o: nopt.h aux.o: nopt.h trans.o: nopt.h -psuedo.o: nopt.h +pseudo.o: nopt.h incalls.o: nopt.h mkcalls.o: nopt.h @@ -59,5 +70,4 @@ syntax.o: syntax.l parser.h Lpars.h outputdfa.o: parser.h Lpars.h outcalls.o: parser.h findworst.o: parser.h -outputrepl.o: parser.h Lpars.h initlex.o: parser.h diff --git a/modules/src/em_opt/aux.c b/modules/src/em_opt/aux.c index bcb54a00..700fb0e5 100644 --- a/modules/src/em_opt/aux.c +++ b/modules/src/em_opt/aux.c @@ -1,24 +1,24 @@ /* $Header$ */ #include "nopt.h" -rotate(w,amount) +OO_rotate(w,amount) int w, amount; { long highmask, lowmask; highmask = (long)(-1) << amount; lowmask = ~highmask; - if(WSIZE!=4) - highmask &= (WSIZE==2)?0xFFFF:0xFF; - return(((w<> (8*WSIZE-amount))&lowmask)); + if(OO_WSIZE!=4) + highmask &= (OO_WSIZE==2)?0xFFFF:0xFF; + return(((w<> (8*OO_WSIZE-amount))&lowmask)); } -samesign(a,b) +OO_samesign(a,b) int a, b; { return( (a ^ b) >= 0); } -sfit(val,nbits) +OO_sfit(val,nbits) int val, nbits; { long mask = 0; @@ -28,7 +28,7 @@ sfit(val,nbits) return(((val&mask) == 0) | (val&mask)==mask); } -ufit(val, nbits) +OO_ufit(val, nbits) int val, nbits; { long mask = 0; @@ -38,7 +38,7 @@ ufit(val, nbits) return((val&mask) == 0); } -sameext(a1,a2) +OO_sameext(a1,a2) struct instr *a1, *a2; { if(a1->argtype != a2->argtype) return(0); @@ -56,7 +56,7 @@ sameext(a1,a2) } } -samenam(a1,a2) +OO_samenam(a1,a2) struct instr *a1, *a2; { if(a1->argtype != a2->argtype) return(0); @@ -72,7 +72,7 @@ samenam(a1,a2) } } -offset(a) +OO_offset(a) struct instr *a; { switch(a->argtype) { diff --git a/modules/src/em_opt/findworst.c b/modules/src/em_opt/findworst.c index 6192faeb..065e73a8 100644 --- a/modules/src/em_opt/findworst.c +++ b/modules/src/em_opt/findworst.c @@ -6,8 +6,7 @@ static char rcsid[] = "$Header$"; #define UPDATEWORST(backups) if(backups>mostbackups) mostbackups = backups; -findworst(state,repl) - int state; +findworst(repl) struct mnems repl; { /* @@ -31,7 +30,7 @@ findworst(state,repl) int s; int mostbackups = 0; if(n==0) { - fprint(ofile,"\t\tbackup(%d);\n", longestpattern-1); + fprint(ofile,"\t\t\tOO_backup(%d);\n", longestpattern-1); return; } for(s=1;s<=higheststate;s++) { @@ -58,7 +57,7 @@ findworst(state,repl) } } if(mostbackups) - fprint(ofile,"\t\tbackup(%d);\n",mostbackups); + fprint(ofile,"\t\t\tOO_backup(%d);\n",mostbackups); } findfail(state) diff --git a/modules/src/em_opt/mkcalls.c b/modules/src/em_opt/mkcalls.c index 63d54892..c8e105c9 100644 --- a/modules/src/em_opt/mkcalls.c +++ b/modules/src/em_opt/mkcalls.c @@ -4,430 +4,337 @@ static char rcsid[] = "$Header$"; #include "nopt.h" -mkcalls(p) +OO_mkcalls(p) struct instr *p; { - switch(p->argtype) { - case lab_ptyp: + switch(p->opcode) { + case op_aar: + if(p->argtype!=none_ptyp) O_aar(p->acst); + else O_aar_narg(); break; + case op_adf: + if(p->argtype!=none_ptyp) O_adf(p->acst); + else O_adf_narg(); break; + case op_adi: + if(p->argtype!=none_ptyp) O_adi(p->acst); + else O_adi_narg(); break; + case op_adp: + O_adp(p->acst); break; + case op_ads: + if(p->argtype!=none_ptyp) O_ads(p->acst); + else O_ads_narg(); break; + case op_adu: + if(p->argtype!=none_ptyp) O_adu(p->acst); + else O_adu_narg(); break; + case op_and: + if(p->argtype!=none_ptyp) O_and(p->acst); + else O_and_narg(); break; + case op_asp: + O_asp(p->acst); break; + case op_ass: + if(p->argtype!=none_ptyp) O_ass(p->acst); + else O_ass_narg(); break; + case op_beq: + O_beq((label)p->acst); break; + case op_bge: + O_bge((label)p->acst); break; + case op_bgt: + O_bgt((label)p->acst); break; + case op_ble: + O_ble((label)p->acst); break; + case op_blm: + O_blm(p->acst); break; + case op_bls: + if(p->argtype!=none_ptyp) O_bls(p->acst); + else O_bls_narg(); break; + case op_blt: + O_blt((label)p->acst); break; + case op_bne: + O_bne((label)p->acst); break; + case op_bra: + O_bra((label)p->acst); break; + case op_cai: + O_cai(); break; + case op_cal: + O_cal(p->apnam); break; + case op_cff: + O_cff(); break; + case op_cfi: + O_cfi(); break; + case op_cfu: + O_cfu(); break; + case op_cif: + O_cif(); break; + case op_cii: + O_cii(); break; + case op_ciu: + O_ciu(); break; + case op_cmf: + if(p->argtype!=none_ptyp) O_cmf(p->acst); + else O_cmf_narg(); break; + case op_cmi: + if(p->argtype!=none_ptyp) O_cmi(p->acst); + else O_cmi_narg(); break; + case op_cmp: + O_cmp(); break; + case op_cms: + if(p->argtype!=none_ptyp) O_cms(p->acst); + else O_cms_narg(); break; + case op_cmu: + if(p->argtype!=none_ptyp) O_cmu(p->acst); + else O_cmu_narg(); break; + case op_com: + if(p->argtype!=none_ptyp) O_com(p->acst); + else O_com_narg(); break; + case op_csa: + if(p->argtype!=none_ptyp) O_csa(p->acst); + else O_csa_narg(); break; + case op_csb: + if(p->argtype!=none_ptyp) O_csb(p->acst); + else O_csb_narg(); break; + case op_cuf: + O_cuf(); break; + case op_cui: + O_cui(); break; + case op_cuu: + O_cuu(); break; + case op_dch: + O_dch(); break; + case op_dec: + O_dec(); break; + case op_dee: + if(p->argtype==nof_ptyp) O_dee_dlb(p->adlb, p->anoff); + else O_dee_dnam(p->adnam, p->asoff); break; + case op_del: + O_del(p->acst); break; + case op_dup: + O_dup(p->acst); break; + case op_dus: + if(p->argtype!=none_ptyp) O_dus(p->acst); + else O_dus_narg(); break; + case op_dvf: + if(p->argtype!=none_ptyp) O_dvf(p->acst); + else O_dvf_narg(); break; + case op_dvi: + if(p->argtype!=none_ptyp) O_dvi(p->acst); + else O_dvi_narg(); break; + case op_dvu: + if(p->argtype!=none_ptyp) O_dvu(p->acst); + else O_dvu_narg(); break; + case op_exg: + if(p->argtype!=none_ptyp) O_exg(p->acst); + else O_exg_narg(); break; + case op_fef: + if(p->argtype!=none_ptyp) O_fef(p->acst); + else O_fef_narg(); break; + case op_fif: + if(p->argtype!=none_ptyp) O_fif(p->acst); + else O_fif_narg(); break; + case op_fil: + if(p->argtype==nof_ptyp) O_fil_dlb(p->adlb, p->anoff); + else O_fil_dnam(p->adnam, p->asoff); break; + case op_gto: + if(p->argtype==nof_ptyp) O_gto_dlb(p->adlb, p->anoff); + else O_gto_dnam(p->adnam, p->asoff); break; + case op_inc: + O_inc(); break; + case op_ine: + if(p->argtype==nof_ptyp) O_ine_dlb(p->adlb, p->anoff); + else O_ine_dnam(p->adnam, p->asoff); break; + case op_inl: + O_inl(p->acst); break; + case op_inn: + if(p->argtype!=none_ptyp) O_inn(p->acst); + else O_inn_narg(); break; + case op_ior: + if(p->argtype!=none_ptyp) O_ior(p->acst); + else O_ior_narg(); break; + case op_lab: O_df_ilb(p->alab); break; - case none_ptyp: - switch(p->opcode) { - case op_aar: - O_aar_narg(); break; - case op_adf: - O_adf_narg(); break; - case op_adi: - O_adi_narg(); break; - case op_ads: - O_ads_narg(); break; - case op_adu: - O_adu_narg(); break; - case op_and: - O_and_narg(); break; - case op_ass: - O_ass_narg(); break; - case op_bls: - O_bls_narg(); break; - case op_cmf: - O_cmf_narg(); break; - case op_cmi: - O_cmi_narg(); break; - case op_cms: - O_cms_narg(); break; - case op_cmu: - O_cmu_narg(); break; - case op_com: - O_com_narg(); break; - case op_csa: - O_csa_narg(); break; - case op_csb: - O_csb_narg(); break; - case op_dus: - O_dus_narg(); break; - case op_dvf: - O_dvf_narg(); break; - case op_dvi: - O_dvi_narg(); break; - case op_dvu: - O_dvu_narg(); break; - case op_exg: - O_exg_narg(); break; - case op_fef: - O_fef_narg(); break; - case op_fif: - O_fif_narg(); break; - case op_inn: - O_inn_narg(); break; - case op_ior: - O_ior_narg(); break; - case op_lar: - O_lar_narg(); break; - case op_los: - O_los_narg(); break; - case op_mlf: - O_mlf_narg(); break; - case op_mli: - O_mli_narg(); break; - case op_mlu: - O_mlu_narg(); break; - case op_ngf: - O_ngf_narg(); break; - case op_ngi: - O_ngi_narg(); break; - case op_rck: - O_rck_narg(); break; - case op_rmi: - O_rmi_narg(); break; - case op_rmu: - O_rmu_narg(); break; - case op_rol: - O_rol_narg(); break; - case op_ror: - O_ror_narg(); break; - case op_sar: - O_sar_narg(); break; - case op_sbf: - O_sbf_narg(); break; - case op_sbi: - O_sbi_narg(); break; - case op_sbs: - O_sbs_narg(); break; - case op_sbu: - O_sbu_narg(); break; - case op_set: - O_set_narg(); break; - case op_sli: - O_sli_narg(); break; - case op_slu: - O_slu_narg(); break; - case op_sri: - O_sri_narg(); break; - case op_sru: - O_sru_narg(); break; - case op_sts: - O_sts_narg(); break; - case op_xor: - O_xor_narg(); break; - case op_zer: - O_zer_narg(); break; - case op_zrf: - O_zrf_narg(); break; - /* no arguments */ - case op_cai: - O_cai(); break; - case op_cff: - O_cff(); break; - case op_cfi: - O_cfi(); break; - case op_cfu: - O_cfu(); break; - case op_cif: - O_cif(); break; - case op_cii: - O_cii(); break; - case op_ciu: - O_ciu(); break; - case op_cmp: - O_cmp(); break; - case op_cuf: - O_cuf(); break; - case op_cui: - O_cui(); break; - case op_cuu: - O_cuu(); break; - case op_dch: - O_dch(); break; - case op_dec: - O_dec(); break; - case op_inc: - O_inc(); break; - case op_lim: - O_lim(); break; - case op_lni: - O_lni(); break; - case op_lpb: - O_lpb(); break; - case op_mon: - O_mon(); break; - case op_nop: - O_nop(); break; - case op_rtt: - O_rtt(); break; - case op_sig: - O_sig(); break; - case op_sim: - O_sim(); break; - case op_teq: - O_teq(); break; - case op_tge: - O_tge(); break; - case op_tgt: - O_tgt(); break; - case op_tle: - O_tle(); break; - case op_tlt: - O_tlt(); break; - case op_tne: - O_tne(); break; - case op_trp: - O_trp(); break; - default: - fatal("Illegal mnemonic(%d)",p->opcode); - } - break; - case cst_ptyp: /* one integer constant argument */ - switch(p->opcode) { - case op_aar: - O_aar(p->acst); break; - case op_adf: - O_adf(p->acst); break; - case op_adi: - O_adi(p->acst); break; - case op_adp: - O_adp(p->acst); break; - case op_ads: - O_ads(p->acst); break; - case op_adu: - O_adu(p->acst); break; - case op_and: - O_and(p->acst); break; - case op_asp: - O_asp(p->acst); break; - case op_ass: - O_ass(p->acst); break; - case op_blm: - O_blm(p->acst); break; - case op_bls: - O_bls(p->acst); break; - case op_cmf: - O_cmf(p->acst); break; - case op_cmi: - O_cmi(p->acst); break; - case op_cms: - O_cms(p->acst); break; - case op_cmu: - O_cmu(p->acst); break; - case op_com: - O_com(p->acst); break; - case op_csa: - O_csa(p->acst); break; - case op_csb: - O_csb(p->acst); break; - case op_del: - O_del(p->acst); break; - case op_dup: - O_dup(p->acst); break; - case op_dus: - O_dus(p->acst); break; - case op_dvf: - O_dvf(p->acst); break; - case op_dvi: - O_dvi(p->acst); break; - case op_dvu: - O_dvu(p->acst); break; - case op_exg: - O_exg(p->acst); break; - case op_fef: - O_fef(p->acst); break; - case op_fif: - O_fif(p->acst); break; - case op_inl: - O_inl(p->acst); break; - case op_inn: - O_inn(p->acst); break; - case op_ior: - O_ior(p->acst); break; - case op_lal: - O_lal(p->acst); break; - case op_lar: - O_lar(p->acst); break; - case op_ldc: - O_ldc(p->acst); break; - case op_ldf: - O_ldf(p->acst); break; - case op_ldl: - O_ldl(p->acst); break; - case op_lfr: - O_lfr(p->acst); break; - case op_lil: - O_lil(p->acst); break; - case op_lin: - O_lin(p->acst); break; - case op_loc: - O_loc(p->acst); break; - case op_lof: - O_lof(p->acst); break; - case op_loi: - O_loi(p->acst); break; - case op_lol: - O_lol(p->acst); break; - case op_lor: - O_lor(p->acst); break; - case op_los: - O_los(p->acst); break; - case op_lxa: - O_lxa(p->acst); break; - case op_lxl: - O_lxl(p->acst); break; - case op_mlf: - O_mlf(p->acst); break; - case op_mli: - O_mli(p->acst); break; - case op_mlu: - O_mlu(p->acst); break; - case op_ngf: - O_ngf(p->acst); break; - case op_ngi: - O_ngi(p->acst); break; - case op_rck: - O_rck(p->acst); break; - case op_ret: - O_ret(p->acst); break; - case op_rmi: - O_rmi(p->acst); break; - case op_rmu: - O_rmu(p->acst); break; - case op_rol: - O_rol(p->acst); break; - case op_ror: - O_ror(p->acst); break; - case op_sar: - O_sar(p->acst); break; - case op_sbf: - O_sbf(p->acst); break; - case op_sbi: - O_sbi(p->acst); break; - case op_sbs: - O_sbs(p->acst); break; - case op_sbu: - O_sbu(p->acst); break; - case op_sdf: - O_sdf(p->acst); break; - case op_sdl: - O_sdl(p->acst); break; - case op_set: - O_set(p->acst); break; - case op_sil: - O_sil(p->acst); break; - case op_sli: - O_sli(p->acst); break; - case op_slu: - O_slu(p->acst); break; - case op_sri: - O_sri(p->acst); break; - case op_sru: - O_sru(p->acst); break; - case op_stf: - O_stf(p->acst); break; - case op_sti: - O_sti(p->acst); break; - case op_stl: - O_stl(p->acst); break; - case op_str: - O_str(p->acst); break; - case op_sts: - O_sts(p->acst); break; - case op_xor: - O_xor(p->acst); break; - case op_zer: - O_zer(p->acst); break; - case op_zrf: - O_zrf(p->acst); break; - case op_zrl: - O_zrl(p->acst); break; - case op_beq: - O_beq((label)p->acst); break; - case op_bge: - O_bge((label)p->acst); break; - case op_bgt: - O_bgt((label)p->acst); break; - case op_ble: - O_ble((label)p->acst); break; - case op_blt: - O_blt((label)p->acst); break; - case op_bne: - O_bne((label)p->acst); break; - case op_bra: - O_bra((label)p->acst); break; - case op_zeq: - O_zeq((label)p->acst); break; - case op_zge: - O_zge((label)p->acst); break; - case op_zgt: - O_zgt((label)p->acst); break; - case op_zle: - O_zle((label)p->acst); break; - case op_zlt: - O_zlt((label)p->acst); break; - case op_zne: - O_zne((label)p->acst); break; - default: - fatal("Illegal mnemonic(%d)",p->opcode); - } - break; - case pro_ptyp: /* A procedure name argument */ - switch(p->opcode) { - case op_cal: - O_cal(p->apnam); break; - case op_lpi: - O_lpi(p->apnam); break; - default: - fatal("Illegal mnemonic(%d)",p->opcode); - } - break; - case nof_ptyp: /* a "g" argument */ - switch(p->opcode) { - case op_dee: - O_dee_dlb(p->adlb, p->anoff); break; - case op_fil: - O_fil_dlb(p->adlb, p->anoff); break; - case op_gto: - O_gto_dlb(p->adlb, p->anoff); break; - case op_ine: - O_ine_dlb(p->adlb, p->anoff); break; - case op_lae: - O_lae_dlb(p->adlb, p->anoff); break; - case op_lde: - O_lde_dlb(p->adlb, p->anoff); break; - case op_loe: - O_loe_dlb(p->adlb, p->anoff); break; - case op_sde: - O_sde_dlb(p->adlb, p->anoff); break; - case op_ste: - O_ste_dlb(p->adlb, p->anoff); break; - case op_zre: - O_zre_dlb(p->adlb, p->anoff); break; - default: - fatal("Illegal mnemonic(%d)",p->opcode); - } - break; - case sof_ptyp: - switch(p->opcode) { - case op_dee: - O_dee_dnam(p->adnam, p->asoff); break; - case op_fil: - O_fil_dnam(p->adnam, p->asoff); break; - case op_gto: - O_gto_dnam(p->adnam, p->asoff); break; - case op_ine: - O_ine_dnam(p->adnam, p->asoff); break; - case op_lae: - O_lae_dnam(p->adnam, p->asoff); break; - case op_lde: - O_lde_dnam(p->adnam, p->asoff); break; - case op_loe: - O_loe_dnam(p->adnam, p->asoff); break; - case op_sde: - O_sde_dnam(p->adnam, p->asoff); break; - case op_ste: - O_ste_dnam(p->adnam, p->asoff); break; - case op_zre: - O_zre_dnam(p->adnam, p->asoff); break; - default: - fatal("Illegal mnemonic(%d)",p->opcode); - } - break; - default: - fatal("Illegal argtype(%d)",p->argtype); + case op_lae: + if(p->argtype==nof_ptyp) O_lae_dlb(p->adlb, p->anoff); + else O_lae_dnam(p->adnam, p->asoff); break; + case op_lal: + O_lal(p->acst); break; + case op_lar: + if(p->argtype!=none_ptyp) O_lar(p->acst); + else O_lar_narg(); break; + case op_ldc: + O_ldc(p->acst); break; + case op_lde: + if(p->argtype==nof_ptyp) O_lde_dlb(p->adlb, p->anoff); + else O_lde_dnam(p->adnam, p->asoff); break; + case op_ldf: + O_ldf(p->acst); break; + case op_ldl: + O_ldl(p->acst); break; + case op_lfr: + O_lfr(p->acst); break; + case op_lil: + O_lil(p->acst); break; + case op_lim: + O_lim(); break; + case op_lin: + O_lin(p->acst); break; + case op_lni: + O_lni(); break; + case op_loc: + O_loc(p->acst); break; + case op_loe: + if(p->argtype==nof_ptyp) O_loe_dlb(p->adlb, p->anoff); + else O_loe_dnam(p->adnam, p->asoff); break; + case op_lof: + O_lof(p->acst); break; + case op_loi: + O_loi(p->acst); break; + case op_lol: + O_lol(p->acst); break; + case op_lor: + O_lor(p->acst); break; + case op_los: + if(p->argtype!=none_ptyp) O_los(p->acst); + else O_los_narg(); break; + case op_lpb: + O_lpb(); break; + case op_lpi: + O_lpi(p->apnam); break; + case op_lxa: + O_lxa(p->acst); break; + case op_lxl: + O_lxl(p->acst); break; + case op_mlf: + if(p->argtype!=none_ptyp) O_mlf(p->acst); + else O_mlf_narg(); break; + case op_mli: + if(p->argtype!=none_ptyp) O_mli(p->acst); + else O_mli_narg(); break; + case op_mlu: + if(p->argtype!=none_ptyp) O_mlu(p->acst); + else O_mlu_narg(); break; + case op_mon: + O_mon(); break; + case op_ngf: + if(p->argtype!=none_ptyp) O_ngf(p->acst); + else O_ngf_narg(); break; + case op_ngi: + if(p->argtype!=none_ptyp) O_ngi(p->acst); + else O_ngi_narg(); break; + case op_nop: + O_nop(); break; + case op_rck: + if(p->argtype!=none_ptyp) O_rck(p->acst); + else O_rck_narg(); break; + case op_ret: + O_ret(p->acst); break; + case op_rmi: + if(p->argtype!=none_ptyp) O_rmi(p->acst); + else O_rmi_narg(); break; + case op_rmu: + if(p->argtype!=none_ptyp) O_rmu(p->acst); + else O_rmu_narg(); break; + case op_rol: + if(p->argtype!=none_ptyp) O_rol(p->acst); + else O_rol_narg(); break; + case op_ror: + if(p->argtype!=none_ptyp) O_ror(p->acst); + else O_ror_narg(); break; + case op_rtt: + O_rtt(); break; + case op_sar: + if(p->argtype!=none_ptyp) O_sar(p->acst); + else O_sar_narg(); break; + case op_sbf: + if(p->argtype!=none_ptyp) O_sbf(p->acst); + else O_sbf_narg(); break; + case op_sbi: + if(p->argtype!=none_ptyp) O_sbi(p->acst); + else O_sbi_narg(); break; + case op_sbs: + if(p->argtype!=none_ptyp) O_sbs(p->acst); + else O_sbs_narg(); break; + case op_sbu: + if(p->argtype!=none_ptyp) O_sbu(p->acst); + else O_sbu_narg(); break; + case op_sde: + if(p->argtype==nof_ptyp) O_sde_dlb(p->adlb, p->anoff); + else O_sde_dnam(p->adnam, p->asoff); break; + case op_sdf: + O_sdf(p->acst); break; + case op_sdl: + O_sdl(p->acst); break; + case op_set: + if(p->argtype!=none_ptyp) O_set(p->acst); + else O_set_narg(); break; + case op_sig: + O_sig(); break; + case op_sil: + O_sil(p->acst); break; + case op_sim: + O_sim(); break; + case op_sli: + if(p->argtype!=none_ptyp) O_sli(p->acst); + else O_sli_narg(); break; + case op_slu: + if(p->argtype!=none_ptyp) O_slu(p->acst); + else O_slu_narg(); break; + case op_sri: + if(p->argtype!=none_ptyp) O_sri(p->acst); + else O_sri_narg(); break; + case op_sru: + if(p->argtype!=none_ptyp) O_sru(p->acst); + else O_sru_narg(); break; + case op_ste: + if(p->argtype==nof_ptyp) O_ste_dlb(p->adlb, p->anoff); + else O_ste_dnam(p->adnam, p->asoff); break; + case op_stf: + O_stf(p->acst); break; + case op_sti: + O_sti(p->acst); break; + case op_stl: + O_stl(p->acst); break; + case op_str: + O_str(p->acst); break; + case op_sts: + if(p->argtype!=none_ptyp) O_sts(p->acst); + else O_sts_narg(); break; + case op_teq: + O_teq(); break; + case op_tge: + O_tge(); break; + case op_tgt: + O_tgt(); break; + case op_tle: + O_tle(); break; + case op_tlt: + O_tlt(); break; + case op_tne: + O_tne(); break; + case op_trp: + O_trp(); break; + case op_xor: + if(p->argtype!=none_ptyp) O_xor(p->acst); + else O_xor_narg(); break; + case op_zeq: + O_zeq((label)p->acst); break; + case op_zer: + if(p->argtype!=none_ptyp) O_zer(p->acst); + else O_zer_narg(); break; + case op_zge: + O_zge((label)p->acst); break; + case op_zgt: + O_zgt((label)p->acst); break; + case op_zle: + O_zle((label)p->acst); break; + case op_zlt: + O_zlt((label)p->acst); break; + case op_zne: + O_zne((label)p->acst); break; + case op_zre: + if(p->argtype==nof_ptyp) O_zre_dlb(p->adlb, p->anoff); + else O_zre_dnam(p->adnam, p->asoff); break; + case op_zrf: + if(p->argtype!=none_ptyp) O_zrf(p->acst); + else O_zrf_narg(); break; + case op_zrl: + O_zrl(p->acst); break; } } diff --git a/modules/src/em_opt/nopt.c b/modules/src/em_opt/nopt.c index e087e26e..0c41fd04 100644 --- a/modules/src/em_opt/nopt.c +++ b/modules/src/em_opt/nopt.c @@ -14,15 +14,26 @@ static char rcsid[] = "$Header$"; extern char em_mnem[][4]; -struct instr **patternqueue, **nextpatt; -struct instr **backupqueue, **nextbackup, **lastbackup; -struct instr **outputqueue, **nextoutput, **lastoutput; -struct instr **freeiqueue, **nextifree, **lastifree; -char *strqueue, *nextstr, *laststr; +struct instr **OO_patternqueue; +struct instr **OO_nxtpatt; +struct instr **OO_bkupqueue; +struct instr **OO_nxtbackup; -int noutput; /* number of instructions in output queue */ -int WSIZE; /* wordlength */ -int PSIZE; /* pointer length */ +static char *filename; +static struct instr **lastbackup; +static struct instr **outputqueue; +static struct instr **nextoutput; +static struct instr **lastoutput; +static struct instr **freeiqueue; +static struct instr **nextifree; +static struct instr **lastifree; +static char *strqueue; +static char *nextstr; +static char *laststr; + +int OO_noutput; /* number of instructions in output queue */ +int OO_WSIZE; /* wordlength */ +int OO_PSIZE; /* pointer length */ #ifdef STATS int sflag = 1; /* pattern statistics output */ @@ -30,17 +41,16 @@ int sflag = 1; /* pattern statistics output */ #ifdef COLLECT int cflag = 0; /* internal statistics output */ #define UPDATEMAX(oldmax,n) if(cflag&&n>oldmax) oldmax=n -int numwrites = 0; -int numnextems = 0; -int numpushs = 0; -int numbackups = 0; -int numflushes = 0; -int numfrees = 0; -int numdefaults = 0; -int highestbackup = 0, totalbackup = 0; -int highestoutput = 0, totaloutput = 0; -int highestfreei = 0, totalfreei = 0; -int higheststr = 0, totalstr = 0; +static int numwrites = 0; +static int numpushs = 0; +static int numbackups = 0; +static int numflushes = 0; +static int numfrees = 0; +static int numdefaults = 0; +static int highestbackup = 0, totalbackup = 0; +static int highestoutput = 0, totaloutput = 0; +static int highestfreei = 0, totalfreei = 0; +static int higheststr = 0, totalstr = 0; #endif C_init(wsize,psize) @@ -48,13 +58,14 @@ C_init(wsize,psize) { allocmem(); O_init(wsize,psize); - WSIZE = wsize; - PSIZE = psize; + OO_WSIZE = wsize; + OO_PSIZE = psize; } C_open(fname) char *fname; { + filename = fname; return(O_open(fname)); } @@ -72,19 +83,30 @@ C_close() O_close(); } +PRIVATE +fatal(s,a) + char *s; + int a; +{ + fprint(STDERR, "%s: ", filename ? filename : "standard input"); + fprint(STDERR,s,a); + fprint(STDERR,"\n"); + sys_stop(S_EXIT); +} + PRIVATE allocmem() { /* Allocate memory for queues on heap */ - nextpatt = patternqueue = + OO_nxtpatt = OO_patternqueue = (struct instr **)Malloc(MAXPATTERN*sizeof(struct instr *)); - nextbackup = backupqueue = + OO_nxtbackup = OO_bkupqueue = (struct instr **)Malloc(MAXBACKUP*sizeof(struct instr *)); - lastbackup = backupqueue + MAXBACKUP - 1; + lastbackup = OO_bkupqueue + MAXBACKUP - 1; nextoutput = outputqueue = (struct instr **)Malloc(MAXOUTPUT*sizeof(struct instr *)); lastoutput = outputqueue + MAXOUTPUT - 1; - noutput = 0; + OO_noutput = 0; nextifree = freeiqueue = (struct instr **)Malloc(MAXFREEI*sizeof(struct instr *)); lastifree = freeiqueue + MAXFREEI - 1; @@ -99,7 +121,6 @@ outputstats() { int i; fprint(STDERR,"Total of %d instructions read, %d written\n",numreads,numwrites); - fprint(STDERR,"Total of %d calls to nextem\n",numnextems); fprint(STDERR,"Total of %d calls to flush\n",numflushes); fprint(STDERR,"Total of %d calls to myfree\n",numfrees); fprint(STDERR,"Total of %d instructions pushed back\n",numpushs-numbackups); @@ -123,7 +144,7 @@ printav(n) } #endif -myfree(p) +OO_free(p) struct instr *p; { #ifdef DEBUG @@ -148,12 +169,6 @@ myfree(p) #endif } -nfree(n) -{ - while(n--) - myfree(*--nextpatt); -} - PRIVATE char * freestr(s) char *s; @@ -170,21 +185,7 @@ freestr(s) return(res); } -nextem() -{ - /* - /* Return the next instruction from backup queue else 0. - */ -#ifdef COLLECT - if(cflag) - numnextems++; -#endif - if(nextbackup>backupqueue) - return((*nextpatt++ = *(--nextbackup))->opcode); - return(0); -} - -flush() +OO_flush() { /* /* Output all instructions waiting in the output queue and free their @@ -198,86 +199,86 @@ flush() if(cflag) { numflushes++; totaloutput += nextoutput-outputqueue; - totalbackup += nextbackup-backupqueue; + totalbackup += OO_nxtbackup-OO_bkupqueue; totalfreei += nextifree-freeiqueue; totalstr += nextstr-strqueue; } #endif - if(noutput) { + if(OO_noutput) { for(p=outputqueue;popcode = opcode; p->argtype = none_ptyp; - output(p); + OO_output(p); } -inop(opcode) +OO_inop(opcode) int opcode; { register struct instr *p = GETINSTR(); p->opcode = opcode; p->argtype = none_ptyp; - *nextpatt++ = p; + *OO_nxtpatt++ = p; } -outcst(opcode,cst) +OO_outcst(opcode,cst) int opcode,cst; { register struct instr *p = GETINSTR(); p->opcode = opcode; p->argtype = cst_ptyp; p->acst = cst; - output(p); + OO_output(p); } -incst(opcode,cst) +OO_incst(opcode,cst) int opcode,cst; { register struct instr *p = GETINSTR(); p->opcode = opcode; p->argtype = cst_ptyp; p->acst = cst; - *nextpatt++ = p; + *OO_nxtpatt++ = p; } -outlab(opcode,lab) +OO_outlab(opcode,lab) int opcode,lab; { register struct instr *p = GETINSTR(); p->opcode = opcode; p->argtype = cst_ptyp; p->acst = lab; - output(p); + OO_output(p); } -inlab(opcode,lab) +OO_inlab(opcode,lab) int opcode,lab; { register struct instr *p = GETINSTR(); p->opcode = opcode; p->argtype = cst_ptyp; p->acst = lab; - *nextpatt++ = p; + *OO_nxtpatt++ = p; } -outpnam(opcode,pnam) +OO_outpnam(opcode,pnam) int opcode; char *pnam; { @@ -285,10 +286,10 @@ outpnam(opcode,pnam) p->opcode = opcode; p->argtype = pro_ptyp; p->apnam = pnam; - output(p); + OO_output(p); } -inpnam(opcode,pnam) +OO_inpnam(opcode,pnam) int opcode; char *pnam; { @@ -296,10 +297,10 @@ inpnam(opcode,pnam) p->opcode = opcode; p->argtype = pro_ptyp; p->apnam = freestr(pnam); - *nextpatt++ = p; + *OO_nxtpatt++ = p; } -outdefilb(opcode,deflb) +OO_outdefilb(opcode,deflb) int opcode; label deflb; { @@ -307,10 +308,10 @@ outdefilb(opcode,deflb) p->opcode = opcode; p->argtype = lab_ptyp; p->alab = deflb; - output(p); + OO_output(p); } -indefilb(opcode,deflb) +OO_indefilb(opcode,deflb) int opcode; label deflb; { @@ -318,10 +319,10 @@ indefilb(opcode,deflb) p->opcode = opcode; p->argtype = lab_ptyp; p->alab = deflb; - *nextpatt++ = p; + *OO_nxtpatt++ = p; } -outext(opcode,arg,soff) +OO_outext(opcode,arg,soff) int opcode; struct instr *arg; int soff; @@ -343,10 +344,10 @@ outext(opcode,arg,soff) default: fatal("Unexpected type %d in outext",arg->argtype); } - output(p); + OO_output(p); } -indnam(opcode,name,off) +OO_indnam(opcode,name,off) int opcode; char *name; int off; @@ -356,10 +357,10 @@ indnam(opcode,name,off) p->argtype = sof_ptyp; p->adnam = freestr(name); p->asoff = off; - *nextpatt++ = p; + *OO_nxtpatt++ = p; } -indlb(opcode,lab,off) +OO_indlb(opcode,lab,off) int opcode; label lab; int off; @@ -369,10 +370,10 @@ indlb(opcode,lab,off) p->argtype = nof_ptyp; p->adlb = lab; p->anoff = off; - *nextpatt++ = p; + *OO_nxtpatt++ = p; } -output(p) +OO_output(p) struct instr *p; { /* Put the instruction p on the output queue */ @@ -381,34 +382,34 @@ output(p) fprint(STDERR,"Overflow of outputqueue - output flushed\n"); printstate("Output overflow"); #endif - flush(); + OO_flush(); } - noutput++; + OO_noutput++; *nextoutput++ = p; #ifdef COLLECT UPDATEMAX(highestoutput,nextoutput-outputqueue); #endif } -pushback(p) +OO_pushback(p) struct instr *p; { - /* push instr. p onto backupqueue */ - if(nextbackup > lastbackup) { + /* push instr. p onto bkupqueue */ + if(OO_nxtbackup > lastbackup) { #ifdef DEBUG - fprint(STDERR,"Warning: Overflow of backupqueue-backup ignored\n"); + fprint(STDERR,"Warning: Overflow of bkupqueue-backup ignored\n"); printstate("Backup overflow"); #endif return; } - *nextbackup++ = p; + *OO_nxtbackup++ = p; #ifdef COLLECT - UPDATEMAX(highestbackup,nextbackup-backupqueue); + UPDATEMAX(highestbackup,OO_nxtbackup-OO_bkupqueue); numpushs++; #endif } -backup(n) +OO_backup(n) int n; { /* copy (up to) n instructions from output to backup queues */ @@ -417,25 +418,25 @@ backup(n) if(cflag) numbackups++; #endif - pushback(*(--nextoutput)); - noutput--; + OO_pushback(*(--nextoutput)); + OO_noutput--; } } -dodefault(numout, numcopy) +OO_dodefault(numout, numcopy) int numout, numcopy; { register struct instr **p,**q; - q = (p = patternqueue) + numout; + q = (p = OO_patternqueue) + numout; while(numcopy--) { if(numout) { numout--; - output(*p); + OO_output(*p); } *p++ = *q++; } - nextpatt = p; - while(numout--) output(*p++); + OO_nxtpatt = p; + while(numout--) OO_output(*p++); #ifdef COLLECT if(cflag) numdefaults++; @@ -453,12 +454,12 @@ printstate(mess) while(p #include #include +#include #define NULL 0 -#define FLUSHDFA() if(state) { inop(OTHER); dfa(OTHER); } \ - else if(noutput) flush(); +#define FLUSHDFA() if(OO_state) { OO_inop(OTHER); OO_dfa(OTHER); } \ + else if(OO_noutput) OO_flush(); +#define NEXTEM() ((OO_nxtbackup>OO_bkupqueue)?\ + ((*OO_nxtpatt++ = *(--OO_nxtbackup))->opcode):\ + 0) #define op_lab 255 #define OTHER 254 @@ -47,11 +51,14 @@ struct instr { #define asoff val.sdlb.soff }; -extern struct instr **patternqueue, **nextpatt; -extern int state; -extern int noutput; /* number of instructions in output queue */ -extern int WSIZE; /* wordlength */ -extern int PSIZE; /* pointer length */ +extern struct instr **OO_patternqueue; +extern struct instr **OO_nxtpatt; +extern struct instr **OO_bkupqueue; +extern struct instr **OO_nxtbackup; +extern int OO_state; +extern int OO_noutput; /* number of instructions in output queue */ +extern int OO_WSIZE; /* wordlength */ +extern int OO_PSIZE; /* pointer length */ #ifdef DEBUG extern int dflag; /* debugging output */ #endif diff --git a/modules/src/em_opt/outcalls.c b/modules/src/em_opt/outcalls.c index 0c6727e3..17c1d86d 100644 --- a/modules/src/em_opt/outcalls.c +++ b/modules/src/em_opt/outcalls.c @@ -21,8 +21,8 @@ outputincalls() case NOARG: fprint(ofile,"\nC_%s() {\n",s); if(op->id_used) { - fprint(ofile,"\tinop(op_%s);\n",s); - fprint(ofile,"\tdfa(op_%s);\n",s); + fprint(ofile,"\tOO_inop(op_%s);\n",s); + fprint(ofile,"\tOO_dfa(op_%s);\n",s); } else { fprint(ofile,"\tFLUSHDFA();\n"); @@ -33,8 +33,8 @@ outputincalls() case CSTOPT: fprint(ofile,"\nC_%s_narg() {\n",s); if(op->id_used) { - fprint(ofile,"\tinop(op_%s);\n",s); - fprint(ofile,"\tdfa(op_%s);\n",s); + fprint(ofile,"\tOO_inop(op_%s);\n",s); + fprint(ofile,"\tOO_dfa(op_%s);\n",s); } else { fprint(ofile,"\tFLUSHDFA();\n"); @@ -45,8 +45,8 @@ outputincalls() case CST: fprint(ofile,"\nC_%s(n) int n; {\n",s); if(op->id_used) { - fprint(ofile,"\tincst(op_%s,n);\n",s); - fprint(ofile,"\tdfa(op_%s);\n",s); + fprint(ofile,"\tOO_incst(op_%s,n);\n",s); + fprint(ofile,"\tOO_dfa(op_%s);\n",s); } else { fprint(ofile,"\tFLUSHDFA();\n"); @@ -57,8 +57,8 @@ outputincalls() case DEFILB: fprint(ofile,"\nC_df_ilb(l) label l; {\n"); if(op->id_used) { - fprint(ofile,"\tindefilb(op_%s,l);\n",s); - fprint(ofile,"\tdfa(op_%s);\n",s); + fprint(ofile,"\tOO_indefilb(op_%s,l);\n",s); + fprint(ofile,"\tOO_dfa(op_%s);\n",s); } else { fprint(ofile,"\tFLUSHDFA();\n"); @@ -69,8 +69,8 @@ outputincalls() case PNAM: fprint(ofile,"\nC_%s(s) char *s; {\n",s); if(op->id_used) { - fprint(ofile,"\tinpnam(op_%s,s);\n",s); - fprint(ofile,"\tdfa(op_%s);\n",s); + fprint(ofile,"\tOO_inpnam(op_%s,s);\n",s); + fprint(ofile,"\tOO_dfa(op_%s);\n",s); } else { fprint(ofile,"\tFLUSHDFA();\n"); @@ -81,8 +81,8 @@ outputincalls() case LAB: fprint(ofile,"\nC_%s(l) label l; {\n",s); if(op->id_used) { - fprint(ofile,"\tinlab(op_%s,l);\n",s); - fprint(ofile,"\tdfa(op_%s);\n",s); + fprint(ofile,"\tOO_inlab(op_%s,l);\n",s); + fprint(ofile,"\tOO_dfa(op_%s);\n",s); } else { fprint(ofile,"\tFLUSHDFA();\n"); @@ -93,8 +93,8 @@ outputincalls() case EXT: fprint(ofile,"\nC_%s(n) int n; {\n",s); if(op->id_used) { - fprint(ofile,"\tincst(op_%s,n);\n",s); - fprint(ofile,"\tdfa(op_%s);\n",s); + fprint(ofile,"\tOO_incst(op_%s,n);\n",s); + fprint(ofile,"\tOO_dfa(op_%s);\n",s); } else { fprint(ofile,"\tFLUSHDFA();\n"); @@ -103,8 +103,8 @@ outputincalls() fprint(ofile,"}\n",s); fprint(ofile,"\nC_%s_dnam(s,n) char *s; int n; {\n",s); if(op->id_used) { - fprint(ofile,"\tindnam(op_%s,s,n);\n",s); - fprint(ofile,"\tdfa(op_%s);\n",s); + fprint(ofile,"\tOO_indnam(op_%s,s,n);\n",s); + fprint(ofile,"\tOO_dfa(op_%s);\n",s); } else { fprint(ofile,"\tFLUSHDFA();\n"); @@ -113,8 +113,8 @@ outputincalls() fprint(ofile,"}\n",s); fprint(ofile,"\nC_%s_dlb(l,n) label l; int n; {\n",s); if(op->id_used) { - fprint(ofile,"\tindlb(op_%s,l,n);\n",s); - fprint(ofile,"\tdfa(op_%s);\n",s); + fprint(ofile,"\tOO_indlb(op_%s,l,n);\n",s); + fprint(ofile,"\tOO_dfa(op_%s);\n",s); } else { fprint(ofile,"\tFLUSHDFA();\n"); diff --git a/modules/src/em_opt/outputdfa.c b/modules/src/em_opt/outputdfa.c index e8eff2a1..408433f9 100644 --- a/modules/src/em_opt/outputdfa.c +++ b/modules/src/em_opt/outputdfa.c @@ -32,7 +32,7 @@ PRIVATE outputtables() { int s; - fprint(ofile,"struct defact {\n"); + fprint(ofile,"static struct defact {\n"); fprint(ofile,"\tint numoutput;\n"); fprint(ofile,"\tint numcopy;\n"); fprint(ofile,"\tint nextstate;\n"); @@ -52,19 +52,19 @@ outputdfa() int s; struct idf *op; struct state *p; - fprint(ofile,"int state = 0;\n"); + fprint(ofile,"int OO_state = 0;\n"); fprint(ofile,"\n"); - fprint(ofile,"dfa(last) int last; {\n"); + fprint(ofile,"OO_dfa(last) int last; {\n"); fprint(ofile,"\twhile(last) {\n"); fprint(ofile,"\t\tswitch(last) {\n"); for(op=ops;op!=(struct idf *)NULL;op=op->id_nextidf) { if(!op->id_used) continue; fprint(ofile,"\t\tcase op_%s:\n",op->id_text); - fprint(ofile,"\t\t\tswitch(state) {\n"); + fprint(ofile,"\t\t\tswitch(OO_state) {\n"); if(!op->id_startpatt) { fprint(ofile,"\t\t\tcase 0: "); - fprint(ofile,"output(*--nextpatt); "); + fprint(ofile,"OO_output(*--OO_nxtpatt); "); fprint(ofile,"break;\n"); } for(s=0;s<=higheststate;s++) @@ -72,8 +72,8 @@ outputdfa() if(p->op==op) { fprint(ofile,"\t\t\tcase %d: ",s); if(actions[p->goto_state]==(struct action *)NULL) - fprint(ofile,"state = %d; ",p->goto_state); - else fprint(ofile,"dotrans(%d); ",p->goto_state); + fprint(ofile,"OO_state = %d; ",p->goto_state); + else fprint(ofile,"OO_dotrans(%d); ",p->goto_state); fprint(ofile,"break;\n"); } } @@ -82,30 +82,29 @@ outputdfa() fprint(ofile,"\t\t\tbreak;\n"); } fprint(ofile,"\t\tdefault:\n"); - fprint(ofile,"\t\t\tif(state) defaultaction();\n"); + fprint(ofile,"\t\t\tif(OO_state) defaultaction();\n"); fprint(ofile,"\t\t\telse {\n"); - fprint(ofile,"\t\t\t\tflush();\n"); - fprint(ofile,"\t\t\t\tmkcalls(*--nextpatt);\n"); - fprint(ofile,"\t\t\t\tmyfree(*nextpatt);\n"); + fprint(ofile,"\t\t\t\tOO_flush();\n"); + fprint(ofile,"\t\t\t\tOO_mkcalls(*--OO_nxtpatt);\n"); + fprint(ofile,"\t\t\t\tOO_free(*OO_nxtpatt);\n"); fprint(ofile,"\t\t\t}\n"); fprint(ofile,"\t\t\tbreak;\n"); fprint(ofile,"\t\tcase OTHER:\n"); - fprint(ofile,"\t\t\tif(state) defaultaction();\n"); + fprint(ofile,"\t\t\tif(OO_state) defaultaction();\n"); fprint(ofile,"\t\t\telse {\n"); - fprint(ofile,"\t\t\t\tflush();\n"); - fprint(ofile,"\t\t\t\tmyfree(*--nextpatt);\n"); + fprint(ofile,"\t\t\t\tOO_flush();\n"); + fprint(ofile,"\t\t\t\tOO_free(*--OO_nxtpatt);\n"); fprint(ofile,"\t\t\t}\n"); fprint(ofile,"\t\t\tbreak;\n"); fprint(ofile,"\t\t}\n"); - fprint(ofile,"\tlast = nextem();\n"); + fprint(ofile,"\tlast = NEXTEM();\n"); fprint(ofile,"\t}\n"); fprint(ofile,"}\n"); } PRIVATE -outputmnems(l,state) +outputmnems(l) struct mnems l; - int state; { int i; for(i=1;i<=l.m_len;i++) @@ -116,6 +115,7 @@ PRIVATE outputdotrans() { int s; + int i; struct state *p; struct action *a; int seennontested; @@ -124,30 +124,23 @@ outputdotrans() sys_stop(S_EXIT); } fprint(ofile,"#include \"nopt.h\"\n\n"); - fprint(ofile,"\ndotrans(s) int s; {\n"); - fprint(ofile,"\tswitch(state=s) {\n"); + fprint(ofile,"\nOO_dotrans(s) int s; {\n"); + fprint(ofile,"\tregister struct instr **patt = OO_patternqueue;\n"); + fprint(ofile,"\tswitch(OO_state=s) {\n"); fprint(ofile,"\tdefault: return;\n"); for(s=0;s<=higheststate;s++) if(actions[s]!=(struct action *)NULL) { fprint(ofile,"\tcase %d: /*",s); - outputmnems(patterns[s],s); + outputmnems(patterns[s]); fprint(ofile," */\n"); seennontested=0; for(a=actions[s];a!=(struct action *)NULL;a=a->next) { if(a->test!=(struct exp_node *)NULL) { fprint(ofile,"\t\tif("); outputexp(a->test,s); - /* - /*fprint(ofile,"dotest(%d)",a->linenum); - */ fprint(ofile,") {\n"); - /* - /*fprint(ofile,"\t\t\tdoaction(%d);\n",a->linenum); - */ outputoneaction(s,a); - fprint(ofile,"\t\t\tnfree(%d);\n",patterns[s].m_len); - fprint(ofile,"\t\t\tstate=0;\n"); - fprint(ofile,"\t\t\tbreak;\n"); + fprint(ofile,"\t\t\tgoto free%d;\n",patterns[s].m_len); fprint(ofile,"\t\t}\n"); } else { @@ -156,18 +149,17 @@ outputdotrans() nerrors++; } seennontested++; - /* - /*fprint(ofile,"\t\t\tdoaction(%d);\n",a->linenum); - */ outputoneaction(s,a); - fprint(ofile,"\t\tnfree(%d);\n",patterns[s].m_len); - fprint(ofile,"\t\tstate=0;\n"); - fprint(ofile,"\t\tbreak;\n"); + fprint(ofile,"\t\t\tgoto free%d;\n",patterns[s].m_len); } } - fprint(ofile,"\t\tbreak;\n"); + fprint(ofile,"\t\treturn;\n"); } fprint(ofile,"\t}\n"); + for(i=longestpattern;i>0;i--) + fprint(ofile," free%d: OO_free(*--OO_nxtpatt);\n",i); + fprint(ofile," free0: ;\n"); + fprint(ofile,"\tOO_state=0;\n"); fprint(ofile,"}\n"); fprint(ofile,"\n"); } @@ -176,10 +168,10 @@ PRIVATE outputdodefault() { fprint(ofile,"\nstatic defaultaction() {\n"); - fprint(ofile,"\tregister struct defact *p = &defaultactions[state];\n"); - fprint(ofile,"\tpushback(*--nextpatt);\n"); - fprint(ofile,"\tdodefault(p->numoutput,p->numcopy);\n"); - fprint(ofile,"\tdotrans(p->nextstate);\n"); + fprint(ofile,"\tregister struct defact *p = &defaultactions[OO_state];\n"); + fprint(ofile,"\tOO_pushback(*--OO_nxtpatt);\n"); + fprint(ofile,"\tOO_dodefault(p->numoutput,p->numcopy);\n"); + fprint(ofile,"\tOO_dotrans(p->nextstate);\n"); fprint(ofile,"}\n"); } @@ -190,10 +182,10 @@ outputoneaction(s,a) { fprint(ofile,"\t\t/* "); fprint(ofile," -> "); - outputmnems(a->replacement,s); + outputmnems(a->replacement); fprint(ofile," */\n"); outputrepl(s,patterns[s],a->replacement); - findworst(s,a->replacement); + findworst(a->replacement); } PRIVATE @@ -212,31 +204,31 @@ outputrepl(state,patt,repl) char *mnem = ri->op_code->id_text; switch(ri->op_code->id_argfmt) { case NOARG: - fprint(ofile,"\t\toutop(op_%s);\n",mnem); + fprint(ofile,"\t\tOO_outop(op_%s);\n",mnem); break; case CST: case CSTOPT: - fprint(ofile,"\t\toutcst(op_%s,",mnem); + fprint(ofile,"\t\tOO_outcst(op_%s,",mnem); outputexp(ri->arg,state); fprint(ofile,");\n"); break; case LAB: - fprint(ofile,"\t\toutlab(op_%s,",mnem); + fprint(ofile,"\t\tOO_outlab(op_%s,",mnem); outputexp(ri->arg,state); fprint(ofile,");\n"); break; case DEFILB: - fprint(ofile,"\t\toutdefilb(op_%s,",mnem); + fprint(ofile,"\t\tOO_outdefilb(op_%s,",mnem); outputexp(ri->arg,state); fprint(ofile,");\n"); break; case PNAM: - fprint(ofile,"\t\toutpnam(op_%s,",mnem); + fprint(ofile,"\t\tOO_outpnam(op_%s,",mnem); outputexp(ri->arg,state); fprint(ofile,");\n"); break; case EXT: - fprint(ofile,"\t\toutext(op_%s,",mnem); + fprint(ofile,"\t\tOO_outext(op_%s,",mnem); outputexp(ri->arg,state); fprint(ofile,");\n"); break; @@ -284,10 +276,10 @@ outputexp(e,state) fprint(ofile,")"); break; case DEFINED: - fprint(ofile,"(patternqueue[%d]->argtype!=none_ptyp)",e->leaf_val-1); + fprint(ofile,"(patt[%d]->argtype!=none_ptyp)",e->leaf_val-1); break; case UNDEFINED: - fprint(ofile,"(patternqueue[%d]->argtype==none_ptyp)",e->leaf_val-1); + fprint(ofile,"(patt[%d]->argtype==none_ptyp)",e->leaf_val-1); break; case COMMA: outext(e->exp_left); @@ -319,26 +311,26 @@ outputexp(e,state) break; case CST: case CSTOPT: - fprint(ofile,"CST(patternqueue[%d])",e->leaf_val-1); + fprint(ofile,"CST(patt[%d])",e->leaf_val-1); break; case LAB: - fprint(ofile,"LAB(patternqueue[%d])",e->leaf_val-1); + fprint(ofile,"LAB(patt[%d])",e->leaf_val-1); break; case DEFILB: - fprint(ofile,"DEFILB(patternqueue[%d])",e->leaf_val-1); + fprint(ofile,"DEFILB(patt[%d])",e->leaf_val-1); break; case PNAM: - fprint(ofile,"PNAM(patternqueue[%d])",e->leaf_val-1); + fprint(ofile,"PNAM(patt[%d])",e->leaf_val-1); break; case EXT: - fprint(ofile,"offset(patternqueue[%d])",e->leaf_val-1); + fprint(ofile,"OO_offset(patt[%d])",e->leaf_val-1); break; } break; case PSIZE: - fprint(ofile,"PSIZE"); break; + fprint(ofile,"OO_PSIZE"); break; case WSIZE: - fprint(ofile,"WSIZE"); break; + fprint(ofile,"OO_WSIZE"); break; case INT: fprint(ofile,"%d",e->leaf_val); break; } @@ -352,7 +344,7 @@ outext(e) fprint(STDERR,"Internal error in outext of parser\n"); nerrors++; } - fprint(ofile,"patternqueue[%d]",e->leaf_val-1); + fprint(ofile,"patt[%d]",e->leaf_val-1); } PRIVATE @@ -382,11 +374,11 @@ outputop(op) case COMP: fprint(ofile,"~"); break; case UPLUS: fprint(ofile,"+"); break; case UMINUS: fprint(ofile,"-"); break; - case SAMESIGN: fprint(ofile,"samesign("); break; - case SFIT: fprint(ofile,"sfit("); break; - case UFIT: fprint(ofile,"ufit("); break; - case ROTATE: fprint(ofile,"rotate("); break; - case SAMEEXT: fprint(ofile,"sameext("); break; - case SAMENAM: fprint(ofile,"samenam("); break; + case SAMESIGN: fprint(ofile,"OO_samesign("); break; + case SFIT: fprint(ofile,"OO_sfit("); break; + case UFIT: fprint(ofile,"OO_ufit("); break; + case ROTATE: fprint(ofile,"OO_rotate("); break; + case SAMEEXT: fprint(ofile,"OO_sameext("); break; + case SAMENAM: fprint(ofile,"OO_samenam("); break; } } From d429be1be15e41d008a233943524dcb9563f2bbe Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 21 Jan 1987 15:21:49 +0000 Subject: [PATCH 0532/1625] adapted to new assembler syntax --- mach/m68k4/libsys/head_em.s | 43 ++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/mach/m68k4/libsys/head_em.s b/mach/m68k4/libsys/head_em.s index c17a0b44..d8ce66df 100644 --- a/mach/m68k4/libsys/head_em.s +++ b/mach/m68k4/libsys/head_em.s @@ -1,15 +1,16 @@ .define .lino,.filn - -.define F_DUM,EXIT - +.define EXIT .define begtext,begdata,begbss -.define EARRAY,ERANGE,ESET,EIDIVZ,EHEAP,EILLINS,ECASE +.define EARRAY,ERANGE,ESET,EIDIVZ,EHEAP,EILLINS,ECASE,EBADGTO .define hol0,.reghp,.limhp,.trpim,.trppc -.define LINO_AD,FILN_AD +.sect .text +.sect .rom +.sect .data +.sect .bss -! m68k4 runtime start-off for the Bleasdale 68000 system -F_DUM = 0 + +! EM runtime start-off for the Bleasdale 68000 system LINO_AD = 0 @@ -22,9 +23,9 @@ EIDIVZ = 6 EHEAP = 17 EILLINS = 18 ECASE = 20 +EBADGTO = 27 -.base 0x20000 - .text + .sect .text begtext: ! Bleasdale puts the argument and environment vectors ! themselves on top of the stack, instead of POINTERS @@ -49,33 +50,27 @@ begtext: ! Now the stack contains an argc (4 bytes), argv-pointer and ! envp pointer. - pea endbss - jsr _brk - add.l #4,sp jsr _m_a_i_n add #012,sp EXIT: jsr __exit - ! As a temporary measure - jsr .trp - - .data + .sect .data begdata: hol0: .lino: - .long 0 ! lino + .data4 0 ! lino .filn: - .long 0 ! filn + .data4 0 ! filn .reghp: - .long endbss + .data4 endbss .limhp: - .long endbss + .data4 endbss .trppc: - .long 0 + .data4 0 .trpim: - .long 0 ! was short + .data4 0 - .bss -begbss: + .sect .bss +begbss: !initialization is not needed because ALL entries are in zero space! From 8aa2167a3873b11287ca001873e429987cad1cdf Mon Sep 17 00:00:00 2001 From: bruce Date: Wed, 21 Jan 1987 15:36:18 +0000 Subject: [PATCH 0533/1625] Don't put out "return" in outputtrans if action is not tested otherwise compiling trans.c give warning about statment not reached. --- modules/src/em_opt/outputdfa.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/src/em_opt/outputdfa.c b/modules/src/em_opt/outputdfa.c index 408433f9..6d058599 100644 --- a/modules/src/em_opt/outputdfa.c +++ b/modules/src/em_opt/outputdfa.c @@ -153,7 +153,8 @@ outputdotrans() fprint(ofile,"\t\t\tgoto free%d;\n",patterns[s].m_len); } } - fprint(ofile,"\t\treturn;\n"); + if(!seennontested) + fprint(ofile,"\t\treturn;\n"); } fprint(ofile,"\t}\n"); for(i=longestpattern;i>0;i--) From 808332ba2bc548b9176f3d36010aa452db00fc9a Mon Sep 17 00:00:00 2001 From: bruce Date: Thu, 22 Jan 1987 14:27:02 +0000 Subject: [PATCH 0534/1625] Fixed up indentation of trans.c output. --- modules/src/em_opt/outputdfa.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/src/em_opt/outputdfa.c b/modules/src/em_opt/outputdfa.c index 6d058599..d46b36c5 100644 --- a/modules/src/em_opt/outputdfa.c +++ b/modules/src/em_opt/outputdfa.c @@ -205,31 +205,31 @@ outputrepl(state,patt,repl) char *mnem = ri->op_code->id_text; switch(ri->op_code->id_argfmt) { case NOARG: - fprint(ofile,"\t\tOO_outop(op_%s);\n",mnem); + fprint(ofile,"\t\t\tOO_outop(op_%s);\n",mnem); break; case CST: case CSTOPT: - fprint(ofile,"\t\tOO_outcst(op_%s,",mnem); + fprint(ofile,"\t\t\tOO_outcst(op_%s,",mnem); outputexp(ri->arg,state); fprint(ofile,");\n"); break; case LAB: - fprint(ofile,"\t\tOO_outlab(op_%s,",mnem); + fprint(ofile,"\t\t\tOO_outlab(op_%s,",mnem); outputexp(ri->arg,state); fprint(ofile,");\n"); break; case DEFILB: - fprint(ofile,"\t\tOO_outdefilb(op_%s,",mnem); + fprint(ofile,"\t\t\tOO_outdefilb(op_%s,",mnem); outputexp(ri->arg,state); fprint(ofile,");\n"); break; case PNAM: - fprint(ofile,"\t\tOO_outpnam(op_%s,",mnem); + fprint(ofile,"\t\t\tOO_outpnam(op_%s,",mnem); outputexp(ri->arg,state); fprint(ofile,");\n"); break; case EXT: - fprint(ofile,"\t\tOO_outext(op_%s,",mnem); + fprint(ofile,"\t\t\tOO_outext(op_%s,",mnem); outputexp(ri->arg,state); fprint(ofile,");\n"); break; From b2379b8cf4e1051ca91216294f6ab0300f46b86d Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 23 Jan 1987 16:00:37 +0000 Subject: [PATCH 0535/1625] Bug fix: EM_MESARG gives em_arg, not em_args! --- modules/src/read_em/read_em.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/src/read_em/read_em.c b/modules/src/read_em/read_em.c index f8a9d4ae..a72f5866 100644 --- a/modules/src/read_em/read_em.c +++ b/modules/src/read_em/read_em.c @@ -227,7 +227,7 @@ EM_getinstr() args = argp; argp = args->em_next; p->em_type = EM_MESARG; - p->em_args = args; + p->em_arg = args; args->em_next = 0; return p; } From 688754df164878e86c3a3fc8862c13786ce4039d Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 23 Jan 1987 16:04:20 +0000 Subject: [PATCH 0536/1625] corrected typo --- modules/src/read_em/read_em.3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/src/read_em/read_em.3 b/modules/src/read_em/read_em.3 index f89aa30d..3497fba6 100644 --- a/modules/src/read_em/read_em.3 +++ b/modules/src/read_em/read_em.3 @@ -122,7 +122,7 @@ The \fIe_instr\fR structure consists of the fields \fIem_i\fR, containing its value of this \fIe_instr\fR. .PP The possible values of -\fIem_type\fR, defined in , are summarized below: +\fIem_type\fR, defined in , are summarized below: .br .ta \w'EM_STARTMES\ \ \ 'u +\w'em_defdnam\ \ \ 'u .di xx From 66f891dff749daf92fba68e1fc8487dacca92f2c Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 23 Jan 1987 16:15:57 +0000 Subject: [PATCH 0537/1625] added EM_wordsize, EM_pointersize --- modules/src/read_em/em_comp.h | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/src/read_em/em_comp.h b/modules/src/read_em/em_comp.h index 0d946c96..fea23e0f 100644 --- a/modules/src/read_em/em_comp.h +++ b/modules/src/read_em/em_comp.h @@ -62,3 +62,4 @@ struct e_args { extern char *EM_error; extern unsigned int EM_lineno; extern char *EM_filename; +extern int EM_wordsize, EM_pointersize; From a5d7753a8d2229288c6fcc59a659d2692c74e6f8 Mon Sep 17 00:00:00 2001 From: ceriel Date: Sat, 24 Jan 1987 00:25:56 +0000 Subject: [PATCH 0538/1625] now uses alloc module, bug fixes, -N option under USE_TMP, to not do so --- lang/cem/cemcom/LLlex.c | 2 +- lang/cem/cemcom/LLmessage.c | 9 ++--- lang/cem/cemcom/Makefile.erik | 62 ++++++++++++++++++----------------- lang/cem/cemcom/Parameters | 8 +---- lang/cem/cemcom/arith.c | 6 ++-- lang/cem/cemcom/ch7bin.c | 4 +-- lang/cem/cemcom/ch7mon.c | 4 +-- lang/cem/cemcom/code.c | 31 ++++++++++-------- lang/cem/cemcom/code.str | 2 +- lang/cem/cemcom/declar.g | 2 +- lang/cem/cemcom/declar.str | 6 ++-- lang/cem/cemcom/declarator.c | 4 +-- lang/cem/cemcom/decspecs.str | 2 +- lang/cem/cemcom/def.str | 2 +- lang/cem/cemcom/domacro.c | 3 +- lang/cem/cemcom/expr.c | 6 +--- lang/cem/cemcom/expr.str | 2 +- lang/cem/cemcom/field.str | 2 +- lang/cem/cemcom/idf.c | 5 +-- lang/cem/cemcom/idf.str | 2 +- lang/cem/cemcom/init.c | 2 +- lang/cem/cemcom/macro.str | 2 +- lang/cem/cemcom/main.c | 35 +++++++++----------- lang/cem/cemcom/make.allocd | 10 +++--- lang/cem/cemcom/options.c | 11 ++++++- lang/cem/cemcom/program.g | 1 - lang/cem/cemcom/replace.c | 2 +- lang/cem/cemcom/stack.c | 6 +--- lang/cem/cemcom/stack.str | 4 +-- lang/cem/cemcom/statement.g | 1 - lang/cem/cemcom/stmt.str | 2 +- lang/cem/cemcom/struct.c | 3 +- lang/cem/cemcom/struct.str | 4 +-- lang/cem/cemcom/switch.c | 2 +- lang/cem/cemcom/switch.str | 4 +-- lang/cem/cemcom/type.c | 5 ++- lang/cem/cemcom/type.str | 2 +- 37 files changed, 124 insertions(+), 136 deletions(-) diff --git a/lang/cem/cemcom/LLlex.c b/lang/cem/cemcom/LLlex.c index 309b21bb..f3a5771e 100644 --- a/lang/cem/cemcom/LLlex.c +++ b/lang/cem/cemcom/LLlex.c @@ -1,6 +1,7 @@ /* $Header$ */ /* L E X I C A L A N A L Y Z E R */ +#include #include "nofloat.h" #include "idfsize.h" #include "numsize.h" @@ -8,7 +9,6 @@ #include "strsize.h" #include "nopp.h" #include "input.h" -#include "alloc.h" #include "arith.h" #include "def.h" #include "idf.h" diff --git a/lang/cem/cemcom/LLmessage.c b/lang/cem/cemcom/LLmessage.c index 2d4ac43b..cefa9d56 100644 --- a/lang/cem/cemcom/LLmessage.c +++ b/lang/cem/cemcom/LLmessage.c @@ -1,9 +1,9 @@ /* $Header$ */ /* PARSER ERROR ADMINISTRATION */ +#include #include "nofloat.h" #include "idf.h" -#include "alloc.h" #include "arith.h" #include "LLlex.h" #include "Lpars.h" @@ -12,9 +12,10 @@ extern char *symbol2str(); LLmessage(tk) { err_occurred = 1; - if (tk < 0) - fatal("parser administration overflow"); - if (tk) { + if (tk < 0) { + error("end of file expected"); + } + else if (tk) { error("%s missing", symbol2str(tk)); insert_token(tk); } diff --git a/lang/cem/cemcom/Makefile.erik b/lang/cem/cemcom/Makefile.erik index 0ba8e0f7..c0eba725 100644 --- a/lang/cem/cemcom/Makefile.erik +++ b/lang/cem/cemcom/Makefile.erik @@ -18,12 +18,14 @@ STRLIB = $(EMHOME)/modules/lib/libstring.a PRTLIB = $(EMHOME)/modules/lib/libprint.a EMMESLIB = $(EMHOME)/modules/lib/libem_mes.a INPLIB = $(EMHOME)/modules/lib/libinput.a +ALLOCLIB = $(EMHOME)/modules/lib/liballoc.a +MALLOC = $(EMHOME)/modules/lib/malloc.o #CH3LIB = $(EMHOME)/modules/lib/libch3.a CH3LIB = LIBS = $(INPLIB) $(CH3LIB) $(EMMESLIB) $(EMKLIB) \ - $(PRTLIB) $(STRLIB) $(SYSLIB) + $(PRTLIB) $(STRLIB) $(ALLOCLIB) $(MALLOC) $(SYSLIB) ELIBS = $(INPLIB) $(CH3LIB) $(EMMESLIB) $(EMELIB) \ - $(PRTLIB) $(STRLIB) $(SYSLIB) + $(PRTLIB) $(STRLIB) $(ALLOCLIB) $(MALLOC) $(SYSLIB) LIB_INCLUDES = -I$(EMHOME)/modules/h -I$(EMHOME)/modules/pkg EM_INCLUDES = -I$(EMHOME)/h SYSLLIB = $(EMHOME)/modules/lib/llib-lsys.ln @@ -34,9 +36,10 @@ PRTLLIB = $(EMHOME)/modules/lib/llib-lprint.ln EMMESLLIB = $(EMHOME)/modules/lib/llib-lmes.ln INPLLIB = $(EMHOME)/modules/lib/llib-linput.ln CH3LLIB = $(EMHOME)/modules/lib/llib-lch3.ln +ALLOCLLIB = $(EMHOME)/modules/lib/llib-alloc.ln LINTLIBS = #LINTLIBS = $(CH3LLIB) $(INPLLIB) $(EMMESLLIB) $(EMKLLIB) \ -# $(PRTLLIB) $(STRLLIB) $(SYSLLIB) +# $(PRTLLIB) $(STRLLIB) $(SYSLLIB) $(ALLOCLLIB) # Where to install the compiler and its driver CEMCOM = $(DESTINATION)/cemcom @@ -58,16 +61,17 @@ CFLAGS = $(CDEFS) $(COPTIONS) -O# we cannot pass the COPTIONS to lint! # Grammar files and their objects LSRC = tokenfile.g declar.g statement.g expression.g program.g +GLCSRC = tokenfile.c declar.c statement.c expression.c program.c LOBJ = tokenfile.o declar.o statement.o expression.o program.o Lpars.o # Objects of hand-written C files COBJ = main.o idf.o declarator.o decspecs.o struct.o \ expr.o ch7.o ch7bin.o cstoper.o arith.o \ - alloc.o asm.o code.o dumpidf.o error.o field.o\ + asm.o code.o dumpidf.o error.o field.o\ tokenname.o LLlex.o LLmessage.o \ input.o domacro.o replace.o init.o options.o \ scan.o skip.o stack.o type.o ch7mon.o label.o eval.o \ - switch.o storage.o ival.o conversion.o \ + switch.o ival.o conversion.o \ blocks.o dataflow.o # Objects of other generated C files @@ -81,13 +85,13 @@ GSRC = char.c symbol2str.c next.c \ # .h files generated by `make hfiles'; PLEASE KEEP THIS UP-TO-DATE! GHSRC = botch_free.h dataflow.h debug.h density.h errout.h \ idepth.h idfsize.h ifdepth.h inputtype.h inumlength.h lapbuf.h \ - maxincl.h myalloc.h nobitfield.h nofloat.h nopp.h \ + maxincl.h nobitfield.h nofloat.h nopp.h \ nparams.h numsize.h parbufsize.h pathlength.h \ strsize.h target_sizes.h textsize.h use_tmp.h spec_arith.h static.h # Other generated files, for 'make clean' only GENERATED = tab tokenfile.g Lpars.h LLfiles LL.output lint.out \ - print Xref lxref hfiles cfiles + print Xref lxref hfiles cfiles $(GLCSRC) # include files containing ALLOCDEF specifications NEXTFILES = code.str declar.str decspecs.str def.str expr.str field.str \ @@ -211,47 +215,45 @@ sim: cfiles $(SIM) $(SIMFLAGS) `sources $(COBJ)` $(GSRC) $(LSRC) #AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO -main.o: LLlex.h Lpars.h alloc.h arith.h debug.h declar.h file_info.h idf.h input.h inputtype.h level.h maxincl.h myalloc.h nobitfield.h nofloat.h nopp.h spec_arith.h specials.h target_sizes.h tokenname.h type.h use_tmp.h -idf.o: LLlex.h Lpars.h align.h alloc.h arith.h assert.h botch_free.h debug.h declar.h decspecs.h def.h file_info.h idf.h idfsize.h label.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h specials.h stack.h storage.h struct.h type.h -declarator.o: Lpars.h alloc.h arith.h botch_free.h declar.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h storage.h type.h +main.o: LLlex.h Lpars.h arith.h debug.h declar.h file_info.h idf.h input.h inputtype.h level.h maxincl.h nobitfield.h nofloat.h nopp.h spec_arith.h specials.h target_sizes.h tokenname.h type.h use_tmp.h +idf.o: LLlex.h Lpars.h align.h arith.h assert.h botch_free.h debug.h declar.h decspecs.h def.h file_info.h idf.h idfsize.h label.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h specials.h stack.h struct.h type.h +declarator.o: Lpars.h arith.h botch_free.h declar.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h type.h decspecs.o: Lpars.h arith.h decspecs.h def.h level.h nobitfield.h nofloat.h spec_arith.h type.h -struct.o: LLlex.h Lpars.h align.h arith.h assert.h botch_free.h debug.h def.h field.h file_info.h idf.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h stack.h storage.h struct.h type.h -expr.o: LLlex.h Lpars.h alloc.h arith.h botch_free.h declar.h decspecs.h def.h expr.h file_info.h idf.h label.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h storage.h type.h +struct.o: LLlex.h Lpars.h align.h arith.h assert.h botch_free.h debug.h def.h field.h file_info.h idf.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h stack.h struct.h type.h +expr.o: LLlex.h Lpars.h arith.h botch_free.h declar.h decspecs.h def.h expr.h file_info.h idf.h label.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h type.h ch7.o: Lpars.h arith.h assert.h debug.h def.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h struct.h type.h -ch7bin.o: Lpars.h arith.h botch_free.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h storage.h struct.h type.h +ch7bin.o: Lpars.h arith.h botch_free.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h struct.h type.h cstoper.o: Lpars.h arith.h assert.h debug.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h target_sizes.h type.h -arith.o: Lpars.h alloc.h arith.h botch_free.h expr.h field.h idf.h label.h mes.h nobitfield.h nofloat.h nopp.h spec_arith.h storage.h type.h -alloc.o: alloc.h assert.h debug.h myalloc.h -code.o: LLlex.h Lpars.h alloc.h arith.h assert.h atw.h botch_free.h code.h dataflow.h debug.h declar.h decspecs.h def.h expr.h file_info.h idf.h label.h level.h mes.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h specials.h stack.h stmt.h storage.h type.h use_tmp.h +arith.o: Lpars.h arith.h botch_free.h expr.h field.h idf.h label.h mes.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h +code.o: LLlex.h Lpars.h arith.h assert.h atw.h botch_free.h code.h dataflow.h debug.h declar.h decspecs.h def.h expr.h file_info.h idf.h label.h level.h mes.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h specials.h stack.h stmt.h type.h use_tmp.h dumpidf.o: Lpars.h arith.h debug.h def.h expr.h field.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h stack.h static.h struct.h type.h error.o: LLlex.h arith.h debug.h errout.h expr.h file_info.h label.h nofloat.h nopp.h spec_arith.h tokenname.h use_tmp.h field.o: Lpars.h arith.h assert.h code.h debug.h expr.h field.h idf.h label.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h type.h tokenname.o: LLlex.h Lpars.h arith.h file_info.h idf.h nofloat.h nopp.h spec_arith.h tokenname.h -LLlex.o: LLlex.h Lpars.h alloc.h arith.h assert.h class.h debug.h def.h file_info.h idf.h idfsize.h input.h nofloat.h nopp.h numsize.h sizes.h spec_arith.h strsize.h -LLmessage.o: LLlex.h Lpars.h alloc.h arith.h file_info.h idf.h nofloat.h nopp.h spec_arith.h +LLlex.o: LLlex.h Lpars.h arith.h assert.h class.h debug.h def.h file_info.h idf.h idfsize.h input.h nofloat.h nopp.h numsize.h sizes.h spec_arith.h strsize.h +LLmessage.o: LLlex.h Lpars.h arith.h file_info.h idf.h nofloat.h nopp.h spec_arith.h input.o: file_info.h input.h inputtype.h nopp.h -domacro.o: LLlex.h Lpars.h alloc.h arith.h assert.h botch_free.h class.h debug.h file_info.h idf.h idfsize.h ifdepth.h input.h interface.h macro.h nofloat.h nopp.h nparams.h parbufsize.h spec_arith.h storage.h textsize.h -replace.o: LLlex.h alloc.h arith.h assert.h class.h debug.h file_info.h idf.h input.h interface.h macro.h nofloat.h nopp.h pathlength.h spec_arith.h static.h strsize.h -init.o: alloc.h class.h idf.h interface.h macro.h nopp.h -options.o: align.h arith.h class.h idf.h idfsize.h macro.h maxincl.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h storage.h use_tmp.h +domacro.o: LLlex.h Lpars.h arith.h assert.h botch_free.h class.h debug.h file_info.h idf.h idfsize.h ifdepth.h input.h interface.h macro.h nofloat.h nopp.h nparams.h parbufsize.h spec_arith.h textsize.h +replace.o: LLlex.h arith.h assert.h class.h debug.h file_info.h idf.h input.h interface.h macro.h nofloat.h nopp.h pathlength.h spec_arith.h static.h strsize.h +init.o: class.h idf.h interface.h macro.h nopp.h +options.o: align.h arith.h botch_free.h class.h idf.h idfsize.h macro.h maxincl.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h use_tmp.h scan.o: class.h idf.h input.h interface.h lapbuf.h macro.h nopp.h nparams.h skip.o: LLlex.h arith.h class.h file_info.h input.h interface.h nofloat.h nopp.h spec_arith.h -stack.o: Lpars.h alloc.h arith.h botch_free.h debug.h def.h idf.h level.h mes.h nobitfield.h nofloat.h nopp.h spec_arith.h stack.h storage.h struct.h type.h use_tmp.h -type.o: Lpars.h align.h alloc.h arith.h def.h idf.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h storage.h type.h -ch7mon.o: Lpars.h arith.h botch_free.h def.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h storage.h type.h +stack.o: Lpars.h arith.h botch_free.h debug.h def.h idf.h level.h mes.h nobitfield.h nofloat.h nopp.h spec_arith.h stack.h struct.h type.h use_tmp.h +type.o: Lpars.h align.h arith.h botch_free.h def.h idf.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h type.h +ch7mon.o: Lpars.h arith.h botch_free.h def.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h label.o: Lpars.h arith.h def.h idf.h label.h level.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h eval.o: Lpars.h align.h arith.h assert.h atw.h code.h dataflow.h debug.h def.h expr.h idf.h label.h level.h mes.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h stack.h type.h -switch.o: Lpars.h arith.h assert.h botch_free.h code.h debug.h density.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h storage.h switch.h type.h -storage.o: alloc.h assert.h botch_free.h debug.h storage.h +switch.o: Lpars.h arith.h assert.h botch_free.h code.h debug.h density.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h switch.h type.h ival.o: Lpars.h align.h arith.h assert.h class.h debug.h def.h expr.h field.h idf.h label.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h struct.h type.h conversion.o: Lpars.h arith.h nobitfield.h nofloat.h sizes.h spec_arith.h type.h blocks.o: arith.h atw.h label.h nofloat.h sizes.h spec_arith.h stack.h dataflow.o: dataflow.h tokenfile.o: Lpars.h -declar.o: LLlex.h Lpars.h arith.h debug.h declar.h decspecs.h def.h expr.h field.h file_info.h idf.h label.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h storage.h struct.h type.h -statement.o: LLlex.h Lpars.h arith.h botch_free.h code.h debug.h def.h expr.h file_info.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h stack.h storage.h type.h +declar.o: LLlex.h Lpars.h arith.h debug.h declar.h decspecs.h def.h expr.h field.h file_info.h idf.h label.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h struct.h type.h +statement.o: LLlex.h Lpars.h arith.h botch_free.h code.h debug.h def.h expr.h file_info.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h stack.h type.h expression.o: LLlex.h Lpars.h arith.h expr.h file_info.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h -program.o: LLlex.h Lpars.h alloc.h arith.h code.h declar.h decspecs.h def.h expr.h file_info.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h +program.o: LLlex.h Lpars.h arith.h code.h declar.h decspecs.h def.h expr.h file_info.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h Lpars.o: Lpars.h char.o: class.h symbol2str.o: Lpars.h diff --git a/lang/cem/cemcom/Parameters b/lang/cem/cemcom/Parameters index 5466fb21..9e1cf547 100644 --- a/lang/cem/cemcom/Parameters +++ b/lang/cem/cemcom/Parameters @@ -1,9 +1,3 @@ -!File: myalloc.h -#define OWNALLOC 1 /* use own superfast allocation */ -#define ALLOCSIZ 4096 /* allocate pieces of 4K */ -#define ALIGNSIZE 8 /* needed for alloc.c */ - - !File: pathlength.h #define PATHLENGTH 1024 /* max. length of path to file */ @@ -35,7 +29,7 @@ !File: maxincl.h -#define MAXINCL 8 /* maximum number of #include directories */ +#define MAXINCL 12 /* maximum number of #include directories */ !File: density.h diff --git a/lang/cem/cemcom/arith.c b/lang/cem/cemcom/arith.c index d628ad49..62cfae76 100644 --- a/lang/cem/cemcom/arith.c +++ b/lang/cem/cemcom/arith.c @@ -7,17 +7,16 @@ semantics of C is a mess. */ -#include "nofloat.h" #include "botch_free.h" +#include +#include "nofloat.h" #include "nobitfield.h" -#include "alloc.h" #include "idf.h" #include "arith.h" #include "type.h" #include "label.h" #include "expr.h" #include "Lpars.h" -#include "storage.h" #include "field.h" #include "mes.h" @@ -202,7 +201,6 @@ arith2arith(tp, oper, expr) */ register struct expr *new = new_expr(); - clear((char *)new, sizeof(struct expr)); new->ex_file = expr->ex_file; new->ex_line = expr->ex_line; new->ex_type = tp; diff --git a/lang/cem/cemcom/ch7bin.c b/lang/cem/cemcom/ch7bin.c index 7f9ff084..aaddacc6 100644 --- a/lang/cem/cemcom/ch7bin.c +++ b/lang/cem/cemcom/ch7bin.c @@ -1,8 +1,9 @@ /* $Header$ */ /* SEMANTIC ANALYSIS (CHAPTER 7RM) -- BINARY OPERATORS */ -#include "nofloat.h" #include "botch_free.h" +#include +#include "nofloat.h" #include "idf.h" #include "arith.h" #include "type.h" @@ -10,7 +11,6 @@ #include "label.h" #include "expr.h" #include "Lpars.h" -#include "storage.h" extern char options[]; extern char *symbol2str(); diff --git a/lang/cem/cemcom/ch7mon.c b/lang/cem/cemcom/ch7mon.c index e42ef4fe..1bc3090f 100644 --- a/lang/cem/cemcom/ch7mon.c +++ b/lang/cem/cemcom/ch7mon.c @@ -1,15 +1,15 @@ /* $Header$ */ /* SEMANTIC ANALYSIS (CHAPTER 7RM) -- MONADIC OPERATORS */ +#include "botch_free.h" +#include #include "nofloat.h" #include "nobitfield.h" -#include "botch_free.h" #include "Lpars.h" #include "arith.h" #include "type.h" #include "label.h" #include "expr.h" -#include "storage.h" #include "idf.h" #include "def.h" diff --git a/lang/cem/cemcom/code.c b/lang/cem/cemcom/code.c index 688a338a..18b7a1f4 100644 --- a/lang/cem/cemcom/code.c +++ b/lang/cem/cemcom/code.c @@ -1,18 +1,18 @@ /* $Header$ */ /* C O D E - G E N E R A T I N G R O U T I N E S */ -#include "nofloat.h" #include +#include "botch_free.h" +#include +#include "nofloat.h" #include "dataflow.h" #include "use_tmp.h" -#include "botch_free.h" #include "arith.h" #include "type.h" #include "idf.h" #include "label.h" #include "code.h" #include "stmt.h" -#include "alloc.h" #include "def.h" #include "expr.h" #include "sizes.h" @@ -24,7 +24,6 @@ #include "mes.h" #include "LLlex.h" #include "specials.h" -#include "storage.h" #include "atw.h" #include "assert.h" @@ -47,9 +46,10 @@ init_code(dst_file) C_init(word_size, pointer_size); /* initialise EM module */ if (C_open(dst_file) == 0) fatal("cannot write to %s\n", dst_file); -#ifndef USE_TMP - famous_first_words(); +#ifdef USE_TMP + if (options['N']) #endif USE_TMP + famous_first_words(); } famous_first_words() @@ -171,7 +171,9 @@ begin_proc(name, def) /* to be called when entering a procedure */ arith size; register struct type *tp = def->df_type; -#ifndef USE_TMP +#ifdef USE_TMP + if (options['N']) code_scope(name,def); +#else USE_TMP code_scope(name, def); #endif USE_TMP #ifdef DATAFLOW @@ -326,9 +328,10 @@ code_declaration(idf, expr, lvl, sc) ) def->df_alloc = ALLOC_SEEN; if (expr) { /* code only if initialized */ -#ifndef USE_TMP +#ifdef USE_TMP + if (options['N']) +#endif USE_TMP code_scope(text, def); -#endif USE_TMP def->df_alloc = ALLOC_DONE; C_df_dnam(text); do_ival(&(def->df_type), expr); @@ -364,9 +367,10 @@ code_declaration(idf, expr, lvl, sc) case GLOBAL: case IMPLICIT: /* we are sure there is no expression */ -#ifndef USE_TMP - code_scope(text, def); +#ifdef USE_TMP + if (options['N']) #endif USE_TMP + code_scope(text, def); break; case AUTO: case REGISTER: @@ -433,9 +437,10 @@ bss(idf) */ arith size = idf->id_def->df_type->tp_size; -#ifndef USE_TMP - code_scope(idf->id_text, idf->id_def); +#ifdef USE_TMP + if (options['N']) #endif USE_TMP + code_scope(idf->id_text, idf->id_def); /* Since bss() is only called if df_alloc is non-zero, and since df_alloc is only non-zero if size >= 0, we have: */ diff --git a/lang/cem/cemcom/code.str b/lang/cem/cemcom/code.str index b2ca234d..2f22cd5c 100644 --- a/lang/cem/cemcom/code.str +++ b/lang/cem/cemcom/code.str @@ -8,7 +8,7 @@ struct string_cst { /* storing string constants */ label sc_dlb; }; -/* ALLOCDEF "string_cst" */ +/* ALLOCDEF "string_cst" 10 */ #define LVAL 0 #define RVAL 1 diff --git a/lang/cem/cemcom/declar.g b/lang/cem/cemcom/declar.g index 71f8202a..b2f795b4 100644 --- a/lang/cem/cemcom/declar.g +++ b/lang/cem/cemcom/declar.g @@ -2,6 +2,7 @@ /* DECLARATION SYNTAX PARSER */ { +#include #include "nobitfield.h" #include "debug.h" #include "arith.h" @@ -16,7 +17,6 @@ #include "label.h" #include "expr.h" #include "sizes.h" -#include "storage.h" extern char options[]; } diff --git a/lang/cem/cemcom/declar.str b/lang/cem/cemcom/declar.str index c9c197ac..fc802225 100644 --- a/lang/cem/cemcom/declar.str +++ b/lang/cem/cemcom/declar.str @@ -13,7 +13,7 @@ struct declarator { struct formal *dc_formal; /* params for function */ }; -/* ALLOCDEF "declarator" */ +/* ALLOCDEF "declarator" 50 */ struct formal { /* list of formals */ @@ -21,7 +21,7 @@ struct formal { /* list of formals */ struct idf *fm_idf; }; -/* ALLOCDEF "formal" */ +/* ALLOCDEF "formal" 5 */ #define NO_PARAMS ((struct formal *) 0) @@ -31,7 +31,7 @@ struct decl_unary { arith du_count; /* for ARRAYs only */ }; -/* ALLOCDEF "decl_unary" */ +/* ALLOCDEF "decl_unary" 10 */ extern struct type *declare_type(); extern struct declarator null_declarator; diff --git a/lang/cem/cemcom/declarator.c b/lang/cem/cemcom/declarator.c index f1a1eb2e..934f1b3f 100644 --- a/lang/cem/cemcom/declarator.c +++ b/lang/cem/cemcom/declarator.c @@ -2,12 +2,11 @@ /* D E C L A R A T O R M A N I P U L A T I O N */ #include "botch_free.h" -#include "alloc.h" +#include #include "arith.h" #include "type.h" #include "Lpars.h" #include "declar.h" -#include "storage.h" #include "idf.h" #include "label.h" #include "expr.h" @@ -43,7 +42,6 @@ add_decl_unary(dc, fund, count, fm) */ register struct decl_unary *new = new_decl_unary(); - clear((char *)new, sizeof(struct decl_unary)); new->next = dc->dc_decl_unary; new->du_fund = fund; new->du_count = count; diff --git a/lang/cem/cemcom/decspecs.str b/lang/cem/cemcom/decspecs.str index 81764613..f5229cac 100644 --- a/lang/cem/cemcom/decspecs.str +++ b/lang/cem/cemcom/decspecs.str @@ -10,6 +10,6 @@ struct decspecs { int ds_unsigned; /* 0 or 1 */ }; -/* ALLOCDEF "decspecs" */ +/* ALLOCDEF "decspecs" 50 */ extern struct decspecs null_decspecs; diff --git a/lang/cem/cemcom/def.str b/lang/cem/cemcom/def.str index 14b07dea..0ac5df19 100644 --- a/lang/cem/cemcom/def.str +++ b/lang/cem/cemcom/def.str @@ -26,4 +26,4 @@ struct def { /* for ordinary tags */ #define REG_DEFAULT 1 /* register candidate, not declared as such */ #define REG_BONUS 10 /* register candidate, declared as such */ -/* ALLOCDEF "def" */ +/* ALLOCDEF "def" 50 */ diff --git a/lang/cem/cemcom/domacro.c b/lang/cem/cemcom/domacro.c index cb8173f7..abf24819 100644 --- a/lang/cem/cemcom/domacro.c +++ b/lang/cem/cemcom/domacro.c @@ -18,10 +18,9 @@ #include "textsize.h" #include "idfsize.h" #include "assert.h" -#include "alloc.h" +#include #include "class.h" #include "macro.h" -#include "storage.h" IMPORT char *inctable[]; /* list of include directories */ IMPORT char *getwdir(); diff --git a/lang/cem/cemcom/expr.c b/lang/cem/cemcom/expr.c index cdfaa5a5..5d27d6a4 100644 --- a/lang/cem/cemcom/expr.c +++ b/lang/cem/cemcom/expr.c @@ -3,7 +3,7 @@ #include "nofloat.h" #include "botch_free.h" -#include "alloc.h" +#include #include "idf.h" #include "arith.h" #include "def.h" @@ -14,7 +14,6 @@ #include "Lpars.h" #include "decspecs.h" #include "declar.h" -#include "storage.h" #include "sizes.h" #include "level.h" @@ -122,7 +121,6 @@ dot2expr(expp) pointer to which is stored in *expp. */ *expp = new_expr(); - clear((char *)*expp, sizeof(struct expr)); (*expp)->ex_file = dot.tk_file; (*expp)->ex_line = dot.tk_line; switch (DOT) { @@ -248,7 +246,6 @@ intexpr(ivalue, fund) */ register struct expr *expr = new_expr(); - clear((char *)expr, sizeof(struct expr)); expr->ex_file = dot.tk_file; expr->ex_line = dot.tk_line; fill_int_expr(expr, ivalue, fund); @@ -308,7 +305,6 @@ new_oper(tp, e1, oper, e2) register struct expr *expr = new_expr(); register struct oper *op; - clear((char *)expr, sizeof(struct expr)); if (e2) { register struct expr *e = e2; diff --git a/lang/cem/cemcom/expr.str b/lang/cem/cemcom/expr.str index 47d0f07c..5739cc23 100644 --- a/lang/cem/cemcom/expr.str +++ b/lang/cem/cemcom/expr.str @@ -101,6 +101,6 @@ struct expr { extern struct expr *intexpr(), *new_oper(); -/* ALLOCDEF "expr" */ +/* ALLOCDEF "expr" 50 */ #define ISCOMMA(e) ((e)->ex_class == Oper && (e)->OP_OPER == INITCOMMA) diff --git a/lang/cem/cemcom/field.str b/lang/cem/cemcom/field.str index 79830abc..cdb82a13 100644 --- a/lang/cem/cemcom/field.str +++ b/lang/cem/cemcom/field.str @@ -9,4 +9,4 @@ struct field { /* for field specifiers */ struct sdef *fd_sdef; /* upward pointer */ }; -/* ALLOCDEF "field" */ +/* ALLOCDEF "field" 50 */ diff --git a/lang/cem/cemcom/idf.c b/lang/cem/cemcom/idf.c index 9baace1f..252587d8 100644 --- a/lang/cem/cemcom/idf.c +++ b/lang/cem/cemcom/idf.c @@ -6,7 +6,7 @@ #include "idfsize.h" #include "botch_free.h" #include "nopp.h" -#include "alloc.h" +#include #include "arith.h" #include "align.h" #include "LLlex.h" @@ -23,7 +23,6 @@ #include "Lpars.h" #include "assert.h" #include "specials.h" /* registration of special identifiers */ -#include "storage.h" int idfsize = IDFSIZE; extern char options[]; @@ -73,7 +72,6 @@ idf_hashed(tg, size, hc) } /* a new struct idf must be inserted at the hook */ notch = new_idf(); - clear((char *)notch, sizeof(struct idf)); notch->next = *hook; *hook = notch; /* hooked in */ notch->id_text = Salloc(tg, size); @@ -303,7 +301,6 @@ declare_idf(ds, dc, lvl) else { /* fill in the def block */ register struct def *newdef = new_def(); - clear((char *)newdef, sizeof(struct def)); newdef->next = def; newdef->df_level = lvl; newdef->df_type = type; diff --git a/lang/cem/cemcom/idf.str b/lang/cem/cemcom/idf.str index abba9f6b..9896c724 100644 --- a/lang/cem/cemcom/idf.str +++ b/lang/cem/cemcom/idf.str @@ -37,7 +37,7 @@ struct idf { int id_special; /* special action needed at occurrence */ }; -/* ALLOCDEF "idf" */ +/* ALLOCDEF "idf" 50 */ extern struct idf *str2idf(), *idf_hashed(); diff --git a/lang/cem/cemcom/init.c b/lang/cem/cemcom/init.c index 20c120e2..ab462841 100644 --- a/lang/cem/cemcom/init.c +++ b/lang/cem/cemcom/init.c @@ -5,7 +5,7 @@ #ifndef NOPP #include -#include "alloc.h" +#include #include "class.h" #include "macro.h" #include "idf.h" diff --git a/lang/cem/cemcom/macro.str b/lang/cem/cemcom/macro.str index ef324327..2772b4d0 100644 --- a/lang/cem/cemcom/macro.str +++ b/lang/cem/cemcom/macro.str @@ -27,7 +27,7 @@ struct macro { char mc_flag; /* marking this macro */ }; -/* ALLOCDEF "macro" */ +/* ALLOCDEF "macro" 20 */ /* `token' numbers of keywords of command-line processor */ diff --git a/lang/cem/cemcom/main.c b/lang/cem/cemcom/main.c index 28d67c2b..4a97f5e3 100644 --- a/lang/cem/cemcom/main.c +++ b/lang/cem/cemcom/main.c @@ -6,7 +6,6 @@ #include "nopp.h" #include "target_sizes.h" #include "debug.h" -#include "myalloc.h" #include "use_tmp.h" #include "maxincl.h" #include "inputtype.h" @@ -19,7 +18,7 @@ #include "tokenname.h" #include "Lpars.h" #include "LLlex.h" -#include "alloc.h" +#include #include "specials.h" extern struct tokenname tkidf[], tkother[]; @@ -79,10 +78,6 @@ main(argc, argv) /* parse and interpret the command line options */ prog_name = argv[0]; -#ifdef OWNALLOC - init_mem(); -#endif OWNALLOC - init_hmask(); #ifndef NOPP @@ -106,12 +101,6 @@ main(argc, argv) } compile(argc - 1, &argv[1]); -#ifdef OWNALLOC -#ifdef DEBUG - mem_stat(); -#endif DEBUG -#endif OWNALLOC - #ifdef DEBUG hash_stat(); #endif DEBUG @@ -164,9 +153,11 @@ compile(argc, argv) source = strcmp(argv[0], "-") ? argv[0] : 0; #ifdef USE_TMP - strcpy(tmpf, tmpfdir); - strcat(tmpf, tmpfname); - tmpfile = mktemp(tmpf); + if (! options['N']) { + strcpy(tmpf, tmpfdir); + strcat(tmpf, tmpfname); + tmpfile = mktemp(tmpf); + } #endif USE_TMP if (destination && strcmp(destination, "-") == 0) @@ -189,7 +180,11 @@ compile(argc, argv) #endif NOPP #ifdef USE_TMP - init_code(tmpfile); + if (!options['N']) { + init_code(tmpfile); + } + else + init_code(destination); #else USE_TMP init_code(destination); #endif USE_TMP @@ -199,9 +194,11 @@ compile(argc, argv) end_code(); #ifdef USE_TMP - prepend_scopes(destination); - AppendFile(tmpfile, destination); - sys_remove(tmpfile); + if (! options['N']) { + prepend_scopes(destination); + AppendFile(tmpfile, destination); + sys_remove(tmpfile); + } #endif USE_TMP #ifdef DEBUG diff --git a/lang/cem/cemcom/make.allocd b/lang/cem/cemcom/make.allocd index d692801e..08492fad 100755 --- a/lang/cem/cemcom/make.allocd +++ b/lang/cem/cemcom/make.allocd @@ -1,8 +1,8 @@ -sed ' -s:^.*ALLOCDEF.*"\(.*\)".*$:\ +sed -e ' +s:^.*[ ]ALLOCDEF[ ].*"\(.*\)"[ ]*\([0-9][0-9]*\).*$:\ /* allocation definitions of struct \1 */\ +extern char *st_alloc();\ extern struct \1 *h_\1;\ -#define new_\1() ((struct \1 *) \\\ - st_alloc((char **)\&h_\1, sizeof(struct \1)))\ -#define free_\1(p) st_free(p, h_\1, sizeof(struct \1))\ +#define new_\1() ((struct \1 *) st_alloc((char **)\&h_\1, sizeof(struct \1), \2))\ +#define free_\1(p) st_free(p, \&h_\1, sizeof(struct \1))\ :' diff --git a/lang/cem/cemcom/options.c b/lang/cem/cemcom/options.c index cebf13e1..67f82cf6 100644 --- a/lang/cem/cemcom/options.c +++ b/lang/cem/cemcom/options.c @@ -1,6 +1,8 @@ /* $Header$ */ /* U S E R O P T I O N - H A N D L I N G */ +#include "botch_free.h" +#include #include "nofloat.h" #include "nopp.h" #include "idfsize.h" @@ -12,7 +14,6 @@ #include "arith.h" #include "sizes.h" #include "align.h" -#include "storage.h" #include "use_tmp.h" #ifndef NOPP @@ -126,6 +127,14 @@ do_option(text) fatal("maximum identifier length is %d", IDFSIZE); break; + case 'N' : +#ifdef USE_TMP + options['N'] = 1; +#else USE_TMP + warning("-N option ignored"); +#endif USE_TMP + break; + case 'P' : /* run preprocessor stand-alone, without #'s */ #ifndef NOPP options['E'] = 1; diff --git a/lang/cem/cemcom/program.g b/lang/cem/cemcom/program.g index 91b46027..c818df55 100644 --- a/lang/cem/cemcom/program.g +++ b/lang/cem/cemcom/program.g @@ -42,7 +42,6 @@ { #include "nopp.h" -#include "alloc.h" #include "arith.h" #include "LLlex.h" #include "idf.h" diff --git a/lang/cem/cemcom/replace.c b/lang/cem/cemcom/replace.c index 7f99c879..cc0c49d7 100644 --- a/lang/cem/cemcom/replace.c +++ b/lang/cem/cemcom/replace.c @@ -7,7 +7,7 @@ #include "debug.h" /* UF */ #include "pathlength.h" /* UF */ #include "strsize.h" /* UF */ -#include "alloc.h" +#include #include "idf.h" #include "input.h" #include "macro.h" diff --git a/lang/cem/cemcom/stack.c b/lang/cem/cemcom/stack.c index 237fdf2e..206a8f76 100644 --- a/lang/cem/cemcom/stack.c +++ b/lang/cem/cemcom/stack.c @@ -6,9 +6,8 @@ #include #include #include "debug.h" -#include "use_tmp.h" #include "botch_free.h" -#include "alloc.h" +#include #include "Lpars.h" #include "arith.h" #include "stack.h" @@ -16,7 +15,6 @@ #include "idf.h" #include "def.h" #include "struct.h" -#include "storage.h" #include "level.h" #include "mes.h" @@ -43,7 +41,6 @@ stack_level() { */ register struct stack_level *stl = new_stack_level(); - clear((char *)stl, sizeof(struct stack_level)); local_level->sl_next = stl; stl->sl_previous = local_level; stl->sl_level = ++level; @@ -60,7 +57,6 @@ stack_idf(idf, stl) */ register struct stack_entry *se = new_stack_entry(); - clear((char *)se, sizeof(struct stack_entry)); /* link it into the stack level */ se->next = stl->sl_entry; se->se_idf = idf; diff --git a/lang/cem/cemcom/stack.str b/lang/cem/cemcom/stack.str index b2776ea4..fa7de66e 100644 --- a/lang/cem/cemcom/stack.str +++ b/lang/cem/cemcom/stack.str @@ -16,14 +16,14 @@ struct stack_level { int sl_level; }; -/* ALLOCDEF "stack_level" */ +/* ALLOCDEF "stack_level" 5 */ struct stack_entry { struct stack_entry *next; struct idf *se_idf; }; -/* ALLOCDEF "stack_entry" */ +/* ALLOCDEF "stack_entry" 5 */ extern struct stack_level *local_level; extern struct stack_level *stack_level_of(); diff --git a/lang/cem/cemcom/statement.g b/lang/cem/cemcom/statement.g index 466bec8b..2d379320 100644 --- a/lang/cem/cemcom/statement.g +++ b/lang/cem/cemcom/statement.g @@ -14,7 +14,6 @@ #include "label.h" #include "expr.h" #include "code.h" -#include "storage.h" #include "stack.h" #include "def.h" diff --git a/lang/cem/cemcom/stmt.str b/lang/cem/cemcom/stmt.str index 7a79df97..82c02e14 100644 --- a/lang/cem/cemcom/stmt.str +++ b/lang/cem/cemcom/stmt.str @@ -7,4 +7,4 @@ struct stmt_block { label st_continue; }; -/* ALLOCDEF "stmt_block" */ +/* ALLOCDEF "stmt_block" 5 */ diff --git a/lang/cem/cemcom/struct.c b/lang/cem/cemcom/struct.c index 2728738e..37471cb3 100644 --- a/lang/cem/cemcom/struct.c +++ b/lang/cem/cemcom/struct.c @@ -4,6 +4,7 @@ #include "nobitfield.h" #include "debug.h" #include "botch_free.h" +#include #include "arith.h" #include "stack.h" #include "idf.h" @@ -15,7 +16,6 @@ #include "Lpars.h" #include "align.h" #include "level.h" -#include "storage.h" #include "assert.h" #include "sizes.h" @@ -308,7 +308,6 @@ idf2sdef(idf, tp) if (!is_anon_idf(idf)) error("unknown selector %s", idf->id_text); *sdefp = sdef = new_sdef(); - clear((char *)sdef, sizeof(struct sdef)); sdef->sd_idf = idf; sdef->sd_stype = sdef->sd_type = error_type; return sdef; diff --git a/lang/cem/cemcom/struct.str b/lang/cem/cemcom/struct.str index 9c3c51f1..150e0989 100644 --- a/lang/cem/cemcom/struct.str +++ b/lang/cem/cemcom/struct.str @@ -11,7 +11,7 @@ struct sdef { /* for selectors */ arith sd_offset; }; -/* ALLOCDEF "sdef" */ +/* ALLOCDEF "sdef" 50 */ struct tag { /* for struct-, union- and enum tags */ struct tag *next; @@ -21,6 +21,6 @@ struct tag { /* for struct-, union- and enum tags */ }; -/* ALLOCDEF "tag" */ +/* ALLOCDEF "tag" 50 */ struct sdef *idf2sdef(); diff --git a/lang/cem/cemcom/switch.c b/lang/cem/cemcom/switch.c index 759b97dc..b3f85305 100644 --- a/lang/cem/cemcom/switch.c +++ b/lang/cem/cemcom/switch.c @@ -5,6 +5,7 @@ #include #include "debug.h" #include "botch_free.h" +#include #include "density.h" #include "Lpars.h" #include "idf.h" @@ -12,7 +13,6 @@ #include "arith.h" #include "switch.h" #include "code.h" -#include "storage.h" #include "assert.h" #include "expr.h" #include "type.h" diff --git a/lang/cem/cemcom/switch.str b/lang/cem/cemcom/switch.str index 9f95fc0f..ffce9b97 100644 --- a/lang/cem/cemcom/switch.str +++ b/lang/cem/cemcom/switch.str @@ -13,7 +13,7 @@ struct switch_hdr { struct case_entry *sh_entries; }; -/* ALLOCDEF "switch_hdr" */ +/* ALLOCDEF "switch_hdr" 2 */ struct case_entry { struct case_entry *next; @@ -21,4 +21,4 @@ struct case_entry { arith ce_value; }; -/* ALLOCDEF "case_entry" */ +/* ALLOCDEF "case_entry" 40 */ diff --git a/lang/cem/cemcom/type.c b/lang/cem/cemcom/type.c index 6243395e..5461d19c 100644 --- a/lang/cem/cemcom/type.c +++ b/lang/cem/cemcom/type.c @@ -3,7 +3,8 @@ #include "nofloat.h" #include "nobitfield.h" -#include "alloc.h" +#include "botch_free.h" +#include #include "Lpars.h" #include "arith.h" #include "type.h" @@ -11,7 +12,6 @@ #include "def.h" #include "sizes.h" #include "align.h" -#include "storage.h" struct type *function_of(), *array_of(); #ifndef NOBITFIELD @@ -44,7 +44,6 @@ create_type(fund) */ register struct type *ntp = new_type(); - clear((char *)ntp, sizeof(struct type)); ntp->tp_fund = fund; ntp->tp_size = (arith)-1; diff --git a/lang/cem/cemcom/type.str b/lang/cem/cemcom/type.str index 13fad9db..27802351 100644 --- a/lang/cem/cemcom/type.str +++ b/lang/cem/cemcom/type.str @@ -44,4 +44,4 @@ extern struct type *pa_type; /* type.c */ extern arith size_of_type(), align(); -/* ALLOCDEF "type" */ +/* ALLOCDEF "type" 50 */ From 80e4016778599aaa7c2c478afdc1361ac48d398c Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 26 Jan 1987 13:36:40 +0000 Subject: [PATCH 0539/1625] bug fixes in RMI and EXG --- mach/vax4/cg/table | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/mach/vax4/cg/table b/mach/vax4/cg/table index daa30039..2a3044f7 100644 --- a/mach/vax4/cg/table +++ b/mach/vax4/cg/table @@ -170,30 +170,34 @@ adispldefind8 = {REGISTER ireg,reg; STRING ind;} 4 cost=(3,13) TOKENEXPRESSIONS: CONST = CONST1 + CONST2 + CONST4 -source1 = regdef1 + displ1 + displdef1 + +Xsource1 = regdef1 + displ1 + displdef1 + EXTERNAL1 + reldef1 + CONST1 + LOCAL1 + displind1 + extdefind1 + displdefind1 +source1 = Xsource1 #ifdef REGVARS + reginc1 + regdec1 #endif REGVARS -source2 = regdef2 + displ2 + displdef2 + +Xsource2 = regdef2 + displ2 + displdef2 + EXTERNAL2 + reldef2 + CONST2 + LOCAL2 + extind2 + displind2 + extdefind2 + displdefind2 +source2 = Xsource2 #ifdef REGVARS + reginc2 + regdec2 #endif REGVARS -source4 = REG + regdef4 + displ4 + displdef4 + LocaLBase + +Xsource4 = REG + regdef4 + displ4 + displdef4 + LocaLBase + EXTERNAL4 + reldef4 + CONST + DOUBLE + LOCAL4 + FCONST4 + extind4 + displind4 + extdefind4 + displdefind4 +source4 = Xsource4 #ifdef REGVARS + RREG + reginc4 + regdec4 #endif REGVARS dups4 = CONST + regdef1 + displ1 + LOCAL1 + REG + regdef2 + displ2 + LOCAL2 + RREG + regdef4 + displ4 + LOCAL4 + DOUBLE -source8 = QREG + regdef8 + displ8 + displdef8 + +Xsource8 = QREG + regdef8 + displ8 + displdef8 + EXTERNAL8 + reldef8 + CONST8 + LOCAL8 + FCONST8 + extind8 + displind8 + extdefind8 + displdefind8 +source8 = Xsource8 #ifdef REGVARS + reginc8 + regdec8 #endif REGVARS @@ -854,7 +858,7 @@ dvi !defined($1) | source4 | remove(ALL) move(%[1],R0) "jsb\t.dvi" | | | -rmi $1==4 | source4 source4 | +rmi $1==4 | Xsource4 Xsource4 | allocate(REG) "divl3\t%[1],%[2],%[a]" "mull2\t%[1],%[a]" @@ -862,7 +866,7 @@ rmi $1==4 | source4 source4 | setcc(%[a]) | %[a] | | #ifdef REGVARS rmi stl $1==4 && inreg($2)==2 - | source4 source4 | + | Xsource4 Xsource4 | remove(regvar($2)) allocate(REG) "divl3\t%[1],%[2],%[a]" @@ -872,7 +876,7 @@ rmi stl $1==4 && inreg($2)==2 setcc(regvar($2)) | | | #endif REGVARS rmi stl $1==4 && $2<0 - | source4 source4 | + | Xsource4 Xsource4 | remove(displaced) remove(LOCALS,(%[num]<=$2+3 && %[num]+%[size]>$2)) allocate(REG) @@ -881,7 +885,7 @@ rmi stl $1==4 && $2<0 "subl3\t%[a],%[2],$2(fp)" setcc({LOCAL4,LB,$2,4}) | | | rmi stl $1==4 && $2>=0 - | source4 source4 | + | Xsource4 Xsource4 | remove(displaced) remove(LOCALS,(%[num]<=$2+3 && %[num]+%[size]>$2)) allocate(REG) @@ -891,7 +895,7 @@ rmi stl $1==4 && $2>=0 setcc({LOCAL4,AP,$2,4}) | | | #ifdef REGVARS rmi sil $1==4 && inreg($2)==2 - | source4 source4 | + | Xsource4 Xsource4 | REMEXTANDLOC allocate(REG) "divl3\t%[1],%[2],%[a]" @@ -900,7 +904,7 @@ rmi sil $1==4 && inreg($2)==2 setcc({regdef4,regvar($2)}) | | | #endif REGVARS rmi sil $1==4 && $2<0 - | source4 source4 | + | Xsource4 Xsource4 | REMEXTANDLOC allocate(REG) "divl3\t%[1],%[2],%[a]" @@ -908,14 +912,14 @@ rmi sil $1==4 && $2<0 "subl3\t%[a],%[2],*$2(fp)" setcc({displdef4,LB,tostring($2)}) | | | rmi sil $1==4 && $2>=0 - | source4 source4 | + | Xsource4 Xsource4 | REMEXTANDLOC allocate(REG) "divl3\t%[1],%[2],%[a]" "mull2\t%[1],%[a]" "subl3\t%[a],%[2],*$2(ap)" setcc({displdef4,AP,tostring($2)}) | | | -rmi ste $1==4 | source4 source4 | +rmi ste $1==4 | Xsource4 Xsource4 | remove(externals) allocate(REG) "divl3\t%[1],%[2],%[a]" @@ -4379,8 +4383,8 @@ dus !defined($1) | source4 | move(%[1],R0) "jsb\t.dus" erase(R0) | | | -exg $1==4 | bigsource4 bigsource4 | | %[1] %[2] | | -exg $1==8 | bigsource8 bigsource8 | | %[1] %[2] | | +exg $1==4 | bigsource4-source4+Xsource4 bigsource4-source4+Xsource4 | | %[1] %[2] | | +exg $1==8 | bigsource8-source8+Xsource8 bigsource8-source8+Xsource8 | | %[1] %[2] | | exg defined($1) | STACK | move({CONST4,$1},R0) "jsb\t.exg" From bbb70220674a4627c8357179278c341d56b6bb33 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 26 Jan 1987 14:04:33 +0000 Subject: [PATCH 0540/1625] bug fix for EM_MESARG --- modules/src/read_em/mkcalls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/src/read_em/mkcalls.c b/modules/src/read_em/mkcalls.c index 3aee2fb6..bcced4df 100644 --- a/modules/src/read_em/mkcalls.c +++ b/modules/src/read_em/mkcalls.c @@ -455,7 +455,7 @@ EM_mkcalls(line) } #endif if (line->em_type == EM_MESARG) { - EM_docon(line->em_args); + EM_docon(line->em_arg); break; } C_mes_end(); From 0df4055709054591047dee10b8f4e81eb8c4c120 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 26 Jan 1987 15:01:25 +0000 Subject: [PATCH 0541/1625] new dependency --- util/ncgg/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/util/ncgg/Makefile b/util/ncgg/Makefile index 5732f4a4..1e1a4461 100644 --- a/util/ncgg/Makefile +++ b/util/ncgg/Makefile @@ -147,6 +147,7 @@ set.o: extern.h set.o: lookup.h set.o: param.h set.o: property.h +set.o: reg.h set.o: set.h set.o: token.h strlookup.o: param.h From f83997d9f9a242fc0a164ff1c66f0291c4171cff Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 26 Jan 1987 16:14:39 +0000 Subject: [PATCH 0542/1625] Added a check that a tokenset in a stackpattern contains tokens that all have the same size. --- util/ncgg/cgg.y | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/util/ncgg/cgg.y b/util/ncgg/cgg.y index 1edca621..8c1974e9 100644 --- a/util/ncgg/cgg.y +++ b/util/ncgg/cgg.y @@ -20,6 +20,7 @@ int startline; int npatterns; int att_type; int patindex[MAXPATTERNS]; +extern set_t l_sets[]; int emhere=0; /* lexical analyzer flag */ int optexact=0; /* Inside "with exact" rule */ @@ -742,6 +743,9 @@ setlist { NEXT(tokpatlen,TOKPATMAX,"Stack pattern"); tokpatset[tokpatlen-1] = $2; checkunstacking($2); + if (l_sets[$2].set_size == 0) { + error("Tokenset is empty or has elements with different sizes"); + } } ; kills From 7bd562f625e4b02e5b5a87bd7e6d7976098fc010 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 26 Jan 1987 16:16:12 +0000 Subject: [PATCH 0543/1625] Improved "element size" handling. --- util/ncgg/set.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/util/ncgg/set.c b/util/ncgg/set.c index 6234ac0e..b0d709f6 100644 --- a/util/ncgg/set.c +++ b/util/ncgg/set.c @@ -7,6 +7,7 @@ static char rcsid[]= "$Header$"; #include "set.h" #include "token.h" #include "lookup.h" +#include "reg.h" #include #include "extern.h" @@ -80,14 +81,39 @@ set_t ident_to_set(name) char *name; { return(result); } +static +checksize(s) + register set_p s; +{ + register int i; + register int size = -1; + + s->set_size = 0; + for (i = 1; i <= nregs; i++) { + if (BIT(s->set_val, i)) { + register int sz = l_regs[i].ri_size; + + if (size == -1) size = sz; + else if (size != sz) return; + } + } + for (i = 1; i <= ntokens; i++) { + if (BIT(s->set_val, i+nregs)) { + register int sz = l_tokens[i]->tk_size; + if (size == -1) size = sz; + else if (size != sz) return; + } + } + if (size != -1) s->set_size = size; +} + set_t setproduct(s1,s2) set_t s1,s2; { set_t result; register i; - if ((result.set_size=s1.set_size)==0) - result.set_size = s2.set_size; for(i=0;i Date: Mon, 26 Jan 1987 16:35:04 +0000 Subject: [PATCH 0544/1625] Removed all those ../../.. references --- modules/src/em_code/Makefile | 6 +++--- modules/src/em_code/make.em.gen | 4 ++-- modules/src/em_code/make.fun | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/src/em_code/Makefile b/modules/src/em_code/Makefile index d8a58d79..4aeca135 100644 --- a/modules/src/em_code/Makefile +++ b/modules/src/em_code/Makefile @@ -18,18 +18,18 @@ em_code.3: em_code.3X tbl < em_code.3X > em_code.3 libeme.a: make.sh e/em_private.h e/em.c - sh make.sh e + EMHOME=$(EMHOME); export EMHOME; sh make.sh e -sh -c 'ranlib libeme.a' libemk.a: make.sh k/em_private.h k/em.c - sh make.sh k + EMHOME=$(EMHOME); export EMHOME; sh make.sh k -sh -c 'ranlib libemk.a' make.sh: em.gen em.nogen make.fun em.gen em.nogen | sh em.gen: make.em.gen $(EMHOME)/etc/em_table - make.em.gen > em.gen + make.em.gen $(EMHOME)/etc/em_table > em.gen pr: @pr Makefile make.em.gen make.fun em.nogen e/em_private.h e/em.c k/em_private.h k/em.c diff --git a/modules/src/em_code/make.em.gen b/modules/src/em_code/make.em.gen index e46e16d3..f9cae1b8 100755 --- a/modules/src/em_code/make.em.gen +++ b/modules/src/em_code/make.em.gen @@ -1,5 +1,5 @@ -echo '% this part is generated from ../../../etc/em_table at: ' `date` -ed - ../../../etc/em_table <<'EOI' +echo "% this part is generated from $1 at: " `date` +ed - $1 <<'EOI' 1,/^$/d 1,/^$/d 1,$s/^\(...\) \(.\).*/\1:\2/ diff --git a/modules/src/em_code/make.fun b/modules/src/em_code/make.fun index 1a69660b..15363c5a 100755 --- a/modules/src/em_code/make.fun +++ b/modules/src/em_code/make.fun @@ -33,14 +33,14 @@ g/^BODY/s/^BODY \(.*\)$/{\ --EOF--/ 1,/^END/-1p 1,/^END/d -g:^NAME:s:^NAME \(.*\)$:cc -c -O -I$1 -I../../h -I../../../h \1.c: +g:^NAME:s:^NAME \(.*\)$:cc -c -O -I$1 -I$EMHOME/modules/h -I$EMHOME/h \1.c: 1i cat >make.sh <<'--EOF--' : script for making lib rm -f *.o . $a -cc -c -O -I$1 -I../../h -I../../../h $1/em.c +cc -c -O -I$1 -I$EMHOME/modules/h -I$EMHOME/h $1/em.c mv em.o em$1.o rm -f libem$1.a ar rc libem$1.a *.o From b3d7af2422077c9c467fa15d66e27cecb524ea5c Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 26 Jan 1987 21:22:23 +0000 Subject: [PATCH 0545/1625] adapted to new assembler syntax --- mach/pmds4/libsys/LIST | 2 +- mach/pmds4/libsys/Makefile | 32 ++++++++++++++++++++++---------- mach/pmds4/libsys/access.s | 7 ++++++- mach/pmds4/libsys/acct.s | 7 ++++++- mach/pmds4/libsys/alarm.s | 9 +++++++-- mach/pmds4/libsys/cerror.s | 9 +++++++-- mach/pmds4/libsys/chdir.s | 7 ++++++- mach/pmds4/libsys/chmod.s | 7 ++++++- mach/pmds4/libsys/chown.s | 9 +++++++-- mach/pmds4/libsys/chroot.s | 7 ++++++- mach/pmds4/libsys/cleanup.s | 7 ++++++- mach/pmds4/libsys/close.s | 7 ++++++- mach/pmds4/libsys/creat.s | 7 ++++++- mach/pmds4/libsys/dup.s | 9 +++++++-- mach/pmds4/libsys/exec.s | 7 ++++++- mach/pmds4/libsys/exit1.s | 7 ++++++- mach/pmds4/libsys/exit2.s | 7 ++++++- mach/pmds4/libsys/fork.s | 7 ++++++- mach/pmds4/libsys/fstat.s | 7 ++++++- mach/pmds4/libsys/getgid.s | 9 +++++++-- mach/pmds4/libsys/getpid.s | 7 ++++++- mach/pmds4/libsys/getuid.s | 9 +++++++-- mach/pmds4/libsys/head_em.s | 27 ++++++++++++++++----------- mach/pmds4/libsys/ioctl.s | 7 ++++++- mach/pmds4/libsys/kill.s | 7 ++++++- mach/pmds4/libsys/link.s | 7 ++++++- mach/pmds4/libsys/lock.s | 7 ++++++- mach/pmds4/libsys/lseek.s | 7 ++++++- mach/pmds4/libsys/mknod.s | 9 +++++++-- mach/pmds4/libsys/mount.s | 9 +++++++-- mach/pmds4/libsys/nice.s | 9 +++++++-- mach/pmds4/libsys/open.s | 7 ++++++- mach/pmds4/libsys/pause.s | 7 ++++++- mach/pmds4/libsys/pipe.s | 7 ++++++- mach/pmds4/libsys/profil.s | 9 +++++++-- mach/pmds4/libsys/ptrace.s | 7 ++++++- mach/pmds4/libsys/read.s | 7 ++++++- mach/pmds4/libsys/sbrk.s | 9 +++++++-- mach/pmds4/libsys/setgid.s | 9 +++++++-- mach/pmds4/libsys/setuid.s | 9 +++++++-- mach/pmds4/libsys/signal.s | 9 +++++++-- mach/pmds4/libsys/stat.s | 7 ++++++- mach/pmds4/libsys/stime.s | 9 +++++++-- mach/pmds4/libsys/sync.s | 7 ++++++- mach/pmds4/libsys/tell.s | 7 ++++++- mach/pmds4/libsys/time.s | 9 +++++++-- mach/pmds4/libsys/times.s | 7 ++++++- mach/pmds4/libsys/umask.s | 9 +++++++-- mach/pmds4/libsys/umount.s | 7 ++++++- mach/pmds4/libsys/unlink.s | 7 ++++++- mach/pmds4/libsys/utime.s | 7 ++++++- mach/pmds4/libsys/wait.s | 7 ++++++- mach/pmds4/libsys/write.s | 7 ++++++- 53 files changed, 356 insertions(+), 89 deletions(-) diff --git a/mach/pmds4/libsys/LIST b/mach/pmds4/libsys/LIST index 2ba80a63..5ee9694d 100644 --- a/mach/pmds4/libsys/LIST +++ b/mach/pmds4/libsys/LIST @@ -1,4 +1,4 @@ -tail_mon +libmon_s.a access.s acct.s alarm.s diff --git a/mach/pmds4/libsys/Makefile b/mach/pmds4/libsys/Makefile index 05011f7a..397ccf67 100644 --- a/mach/pmds4/libsys/Makefile +++ b/mach/pmds4/libsys/Makefile @@ -1,17 +1,29 @@ # $Header$ -install: - ../../install head_em.s head_em - ../../install tail_mon tail_mon +MACH=pmds4 +all: libmon_o.a head_em -cmp: - -../../compare head_em.s head_em - -../../compare tail_mon tail_mon +install: all + ../../install head_em.o head_em + ../../install libmon_o.a tail_mon -clean : + +cmp: all + -../../compare head_em.o head_em + -../../compare libmon_o.a tail_mon + +libmon_o.a: libmon_s.a + ASAR=aal ; export ASAR ;\ + march . libmon_o.a + +head_em.o: head_em.s + $(MACH) -I../../../h -c head_em.s + +clean: + rm -f *.o opr : - make pr | opr + make pr | opr pr: - pr -h `pwd`/head_em.s head_em.s - @arch pv tail_mon | pr -h `pwd`/tail_mon + @pr `pwd`/head_em.s + @arch pv libmon_s.a | pr -h `pwd`/libmon_s.a diff --git a/mach/pmds4/libsys/access.s b/mach/pmds4/libsys/access.s index ba564c85..af2fa992 100644 --- a/mach/pmds4/libsys/access.s +++ b/mach/pmds4/libsys/access.s @@ -1,7 +1,12 @@ .define _access +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _access _access: trap #0 -.short 0x21 +.data2 0x21 bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/acct.s b/mach/pmds4/libsys/acct.s index 4c97994b..26045554 100644 --- a/mach/pmds4/libsys/acct.s +++ b/mach/pmds4/libsys/acct.s @@ -1,7 +1,12 @@ .define _acct +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _acct _acct: trap #0 -.short 0x33 +.data2 0x33 bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/alarm.s b/mach/pmds4/libsys/alarm.s index 4e8e6982..1f1fd184 100644 --- a/mach/pmds4/libsys/alarm.s +++ b/mach/pmds4/libsys/alarm.s @@ -1,6 +1,11 @@ .define _alarm +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _alarm -.text +.sect .text _alarm: trap #0 -.short 0x1B +.data2 0x1B rts diff --git a/mach/pmds4/libsys/cerror.s b/mach/pmds4/libsys/cerror.s index d9fff34c..a69e2021 100644 --- a/mach/pmds4/libsys/cerror.s +++ b/mach/pmds4/libsys/cerror.s @@ -1,9 +1,14 @@ .define cerror +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern cerror cerror: move.l d0,_errno move.l #-1,d0 rts -.bss +.sect .bss _errno: .space 4 -.text +.sect .text diff --git a/mach/pmds4/libsys/chdir.s b/mach/pmds4/libsys/chdir.s index b596ace3..910f4920 100644 --- a/mach/pmds4/libsys/chdir.s +++ b/mach/pmds4/libsys/chdir.s @@ -1,7 +1,12 @@ .define _chdir +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _chdir _chdir: trap #0 -.short 0xC +.data2 0xC bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/chmod.s b/mach/pmds4/libsys/chmod.s index d51b23b6..b9941630 100644 --- a/mach/pmds4/libsys/chmod.s +++ b/mach/pmds4/libsys/chmod.s @@ -1,7 +1,12 @@ .define _chmod +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _chmod _chmod: trap #0 -.short 0xF +.data2 0xF bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/chown.s b/mach/pmds4/libsys/chown.s index dd96bb18..97d196da 100644 --- a/mach/pmds4/libsys/chown.s +++ b/mach/pmds4/libsys/chown.s @@ -1,8 +1,13 @@ .define _chown +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _chown -.text +.sect .text _chown: trap #0 -.short 0x10 +.data2 0x10 bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/chroot.s b/mach/pmds4/libsys/chroot.s index 563b2a4a..9cde0e7b 100644 --- a/mach/pmds4/libsys/chroot.s +++ b/mach/pmds4/libsys/chroot.s @@ -1,7 +1,12 @@ .define _chroot +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _chroot _chroot: trap #0 -.short 0x3D +.data2 0x3D bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/cleanup.s b/mach/pmds4/libsys/cleanup.s index ce4a7635..db80fbf1 100644 --- a/mach/pmds4/libsys/cleanup.s +++ b/mach/pmds4/libsys/cleanup.s @@ -1,5 +1,10 @@ .define __cleanup +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern __cleanup -.text +.sect .text __cleanup: rts diff --git a/mach/pmds4/libsys/close.s b/mach/pmds4/libsys/close.s index 3f330bc8..2dc8b161 100644 --- a/mach/pmds4/libsys/close.s +++ b/mach/pmds4/libsys/close.s @@ -1,7 +1,12 @@ .define _close +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _close _close: trap #0 -.short 0x6 +.data2 0x6 bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/creat.s b/mach/pmds4/libsys/creat.s index ed29f451..736e80c5 100644 --- a/mach/pmds4/libsys/creat.s +++ b/mach/pmds4/libsys/creat.s @@ -1,7 +1,12 @@ .define _creat +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _creat _creat: trap #0 -.short 0x8 +.data2 0x8 bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/dup.s b/mach/pmds4/libsys/dup.s index 2adfabdd..0cf46c9b 100644 --- a/mach/pmds4/libsys/dup.s +++ b/mach/pmds4/libsys/dup.s @@ -1,12 +1,17 @@ .define _dup .define _dup2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _dup -.text +.sect .text .extern _dup2 _dup2: or.l #64,4(sp) _dup: trap #0 -.short 0x29 +.data2 0x29 bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/exec.s b/mach/pmds4/libsys/exec.s index 124910f3..793de9cd 100644 --- a/mach/pmds4/libsys/exec.s +++ b/mach/pmds4/libsys/exec.s @@ -2,6 +2,11 @@ .define _execve .define _execv .define _execle +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _execl .extern _execve .extern _execv @@ -17,7 +22,7 @@ pushp: unlk a6 rts _execve: trap #0 -.short 3B +.data2 3B jmp cerror _execv: tst.b -48(sp) diff --git a/mach/pmds4/libsys/exit1.s b/mach/pmds4/libsys/exit1.s index 3824a590..18dfc2b4 100644 --- a/mach/pmds4/libsys/exit1.s +++ b/mach/pmds4/libsys/exit1.s @@ -1,6 +1,11 @@ .define _exit +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _exit -.text +.sect .text _exit: tst.b -40(sp) link a6,#-0 diff --git a/mach/pmds4/libsys/exit2.s b/mach/pmds4/libsys/exit2.s index 5cbdc68f..0845e836 100644 --- a/mach/pmds4/libsys/exit2.s +++ b/mach/pmds4/libsys/exit2.s @@ -1,4 +1,9 @@ .define __exit +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern __exit __exit: trap #0 -.short 0x1 +.data2 0x1 diff --git a/mach/pmds4/libsys/fork.s b/mach/pmds4/libsys/fork.s index beb6dbad..fc9a9abd 100644 --- a/mach/pmds4/libsys/fork.s +++ b/mach/pmds4/libsys/fork.s @@ -1,7 +1,12 @@ .define _fork +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _fork _fork: trap #0 -.short 0x2 +.data2 0x2 bra 1f bcs 2f rts diff --git a/mach/pmds4/libsys/fstat.s b/mach/pmds4/libsys/fstat.s index f574f28b..9a756d80 100644 --- a/mach/pmds4/libsys/fstat.s +++ b/mach/pmds4/libsys/fstat.s @@ -1,7 +1,12 @@ .define _fstat +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _fstat _fstat: trap #0 -.short 0x1C +.data2 0x1C bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/getgid.s b/mach/pmds4/libsys/getgid.s index 098977ad..9f945f2c 100644 --- a/mach/pmds4/libsys/getgid.s +++ b/mach/pmds4/libsys/getgid.s @@ -1,12 +1,17 @@ .define _getgid .define _getegid +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _getgid .extern _getegid _getgid: trap #0 -.short 0x2F +.data2 0x2F rts _getegid: trap #0 -.short 0x2F +.data2 0x2F move.l d1,d0 rts diff --git a/mach/pmds4/libsys/getpid.s b/mach/pmds4/libsys/getpid.s index 75894271..e676b508 100644 --- a/mach/pmds4/libsys/getpid.s +++ b/mach/pmds4/libsys/getpid.s @@ -1,5 +1,10 @@ .define _getpid +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _getpid _getpid: trap #0 -.short 0x14 +.data2 0x14 rts diff --git a/mach/pmds4/libsys/getuid.s b/mach/pmds4/libsys/getuid.s index 53f6b0be..487c6fb8 100644 --- a/mach/pmds4/libsys/getuid.s +++ b/mach/pmds4/libsys/getuid.s @@ -1,12 +1,17 @@ .define _getuid .define _geteuid +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _getuid .extern _geteuid _getuid: trap #0 -.short 0x18 +.data2 0x18 rts _geteuid: trap #0 -.short 0x18 +.data2 0x18 move.l d1,d0 rts diff --git a/mach/pmds4/libsys/head_em.s b/mach/pmds4/libsys/head_em.s index 8b9719e1..c3d67cc6 100644 --- a/mach/pmds4/libsys/head_em.s +++ b/mach/pmds4/libsys/head_em.s @@ -1,12 +1,17 @@ .define CERASE,CKILL,CSTOP,CSTART .define .lino,.filn - .define F_DUM,EXIT - .define begtext,begdata,begbss .define EARRAY,ERANGE,ESET,EIDIVZ,EHEAP,EILLINS,ECASE .define hol0,.reghp,.limhp,.trpim,.trppc .define LINO_AD,FILN_AD +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text + + CERASE = 010 @@ -27,7 +32,7 @@ EHEAP = 17 EILLINS = 18 ECASE = 20 - .text + .sect .text begtext: pea endbss jsr _brk @@ -41,22 +46,22 @@ EXIT: jsr .trp - .data + .sect .data begdata: hol0: .lino: - .long 0 ! lino + .data4 0 ! lino .filn: - .long 0 ! filn + .data4 0 ! filn .reghp: - .long endbss + .data4 endbss .limhp: - .long endbss + .data4 endbss .trppc: - .long 0 + .data4 0 .trpim: - .long 0 ! was short + .data4 0 ! was short - .bss + .sect .bss begbss: diff --git a/mach/pmds4/libsys/ioctl.s b/mach/pmds4/libsys/ioctl.s index 4d4a772c..140bed28 100644 --- a/mach/pmds4/libsys/ioctl.s +++ b/mach/pmds4/libsys/ioctl.s @@ -1,7 +1,12 @@ .define _ioctl +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _ioctl _ioctl: trap #0 -.short 0x36 +.data2 0x36 bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/kill.s b/mach/pmds4/libsys/kill.s index 191f044f..d58ffc4f 100644 --- a/mach/pmds4/libsys/kill.s +++ b/mach/pmds4/libsys/kill.s @@ -1,7 +1,12 @@ .define _kill +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _kill _kill: trap #0 -.short 0x25 +.data2 0x25 bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/link.s b/mach/pmds4/libsys/link.s index e1531b95..7a07106a 100644 --- a/mach/pmds4/libsys/link.s +++ b/mach/pmds4/libsys/link.s @@ -1,7 +1,12 @@ .define _link +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _link _link: trap #0 -.short 0x9 +.data2 0x9 bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/lock.s b/mach/pmds4/libsys/lock.s index 5df3eccc..9e481293 100644 --- a/mach/pmds4/libsys/lock.s +++ b/mach/pmds4/libsys/lock.s @@ -1,7 +1,12 @@ .define _lock +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _lock _lock: trap #0 -.short 0x35 +.data2 0x35 bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/lseek.s b/mach/pmds4/libsys/lseek.s index b3e26e73..278ee6d5 100644 --- a/mach/pmds4/libsys/lseek.s +++ b/mach/pmds4/libsys/lseek.s @@ -1,7 +1,12 @@ .define _lseek +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _lseek _lseek: trap #0 -.short 0x13 +.data2 0x13 bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/mknod.s b/mach/pmds4/libsys/mknod.s index bc3cd677..623a09c3 100644 --- a/mach/pmds4/libsys/mknod.s +++ b/mach/pmds4/libsys/mknod.s @@ -1,8 +1,13 @@ .define _mknod +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _mknod -.text +.sect .text _mknod: trap #0 -.short 0xE +.data2 0xE bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/mount.s b/mach/pmds4/libsys/mount.s index 6cb2c42c..5d41c771 100644 --- a/mach/pmds4/libsys/mount.s +++ b/mach/pmds4/libsys/mount.s @@ -1,8 +1,13 @@ .define _mount +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _mount -.text +.sect .text _mount: trap #0 -.short 0x15 +.data2 0x15 bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/nice.s b/mach/pmds4/libsys/nice.s index 2737392d..bf568ba2 100644 --- a/mach/pmds4/libsys/nice.s +++ b/mach/pmds4/libsys/nice.s @@ -1,8 +1,13 @@ .define _nice +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _nice -.text +.sect .text _nice: trap #0 -.short 0x22 +.data2 0x22 bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/open.s b/mach/pmds4/libsys/open.s index ef2b038f..416337c5 100644 --- a/mach/pmds4/libsys/open.s +++ b/mach/pmds4/libsys/open.s @@ -1,7 +1,12 @@ .define _open +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _open _open: trap #0 -.short 0x5 +.data2 0x5 bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/pause.s b/mach/pmds4/libsys/pause.s index 4c52e129..80ce3494 100644 --- a/mach/pmds4/libsys/pause.s +++ b/mach/pmds4/libsys/pause.s @@ -1,5 +1,10 @@ .define _pause +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _pause _pause: trap #0 -.short 0x1D +.data2 0x1D rts diff --git a/mach/pmds4/libsys/pipe.s b/mach/pmds4/libsys/pipe.s index 6f011c01..37929261 100644 --- a/mach/pmds4/libsys/pipe.s +++ b/mach/pmds4/libsys/pipe.s @@ -1,7 +1,12 @@ .define _pipe +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _pipe _pipe: trap #0 -.short 0x2A +.data2 0x2A bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/profil.s b/mach/pmds4/libsys/profil.s index 0651fdba..c45d67ac 100644 --- a/mach/pmds4/libsys/profil.s +++ b/mach/pmds4/libsys/profil.s @@ -1,6 +1,11 @@ .define _profil +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _profil -.text +.sect .text _profil: trap #0 -.short 0x2C +.data2 0x2C rts diff --git a/mach/pmds4/libsys/ptrace.s b/mach/pmds4/libsys/ptrace.s index 003c7465..febf97d7 100644 --- a/mach/pmds4/libsys/ptrace.s +++ b/mach/pmds4/libsys/ptrace.s @@ -1,7 +1,12 @@ .define _ptrace +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _ptrace _ptrace: trap #0 -.short 0x1A +.data2 0x1A bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/read.s b/mach/pmds4/libsys/read.s index 6609752c..02fa60df 100644 --- a/mach/pmds4/libsys/read.s +++ b/mach/pmds4/libsys/read.s @@ -1,7 +1,12 @@ .define _read +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _read _read: trap #0 -.short 0x3 +.data2 0x3 bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/sbrk.s b/mach/pmds4/libsys/sbrk.s index 490cd049..8726f1e8 100644 --- a/mach/pmds4/libsys/sbrk.s +++ b/mach/pmds4/libsys/sbrk.s @@ -1,5 +1,10 @@ .define _sbrk .define _brk +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _sbrk .extern _brk _sbrk: tst.b -8(sp) @@ -9,7 +14,7 @@ _sbrk: tst.b -8(sp) move.l d0,-(sp) clr.l -(sp) trap #0 -.short 0x11 +.data2 0x11 add.l #8,sp bcc 1f jmp cerror @@ -19,7 +24,7 @@ _sbrk: tst.b -8(sp) add.l d1,.reghp rts _brk: trap #0 -.short 0x11 +.data2 0x11 bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/setgid.s b/mach/pmds4/libsys/setgid.s index 94d6abae..7741e37c 100644 --- a/mach/pmds4/libsys/setgid.s +++ b/mach/pmds4/libsys/setgid.s @@ -1,8 +1,13 @@ .define _setgid +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _setgid -.text +.sect .text _setgid: trap #0 -.short 0x2E +.data2 0x2E bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/setuid.s b/mach/pmds4/libsys/setuid.s index a7040765..46daae21 100644 --- a/mach/pmds4/libsys/setuid.s +++ b/mach/pmds4/libsys/setuid.s @@ -1,8 +1,13 @@ .define _setuid +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _setuid -.text +.sect .text _setuid: trap #0 -.short 0x17 +.data2 0x17 bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/signal.s b/mach/pmds4/libsys/signal.s index e4bdb4a2..43715457 100644 --- a/mach/pmds4/libsys/signal.s +++ b/mach/pmds4/libsys/signal.s @@ -1,4 +1,9 @@ .define _signal +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _signal NSIG=32 _signal: @@ -21,7 +26,7 @@ _signal: move.l d0,-(sp) clr.l -(sp) trap #0 -.short 48 +.data2 48 add.l #12,sp bcs 3f btst #0,d0 @@ -48,5 +53,5 @@ enter: movem.l (sp)+,d0/d1/a0/a1 add.l #4,sp rtr -.bss +.sect .bss dvect: .space 4*NSIG diff --git a/mach/pmds4/libsys/stat.s b/mach/pmds4/libsys/stat.s index 45dfa755..2d41ec45 100644 --- a/mach/pmds4/libsys/stat.s +++ b/mach/pmds4/libsys/stat.s @@ -1,7 +1,12 @@ .define _stat +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _stat _stat: trap #0 -.short 0x12 +.data2 0x12 bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/stime.s b/mach/pmds4/libsys/stime.s index 6f497f88..422b8eb1 100644 --- a/mach/pmds4/libsys/stime.s +++ b/mach/pmds4/libsys/stime.s @@ -1,8 +1,13 @@ .define _stime +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _stime -.text +.sect .text _stime: trap #0 -.short 0x19 +.data2 0x19 bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/sync.s b/mach/pmds4/libsys/sync.s index 9fa762e3..0ee26389 100644 --- a/mach/pmds4/libsys/sync.s +++ b/mach/pmds4/libsys/sync.s @@ -1,5 +1,10 @@ .define _sync +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _sync _sync: trap #0 -.short 0x24 +.data2 0x24 rts diff --git a/mach/pmds4/libsys/tell.s b/mach/pmds4/libsys/tell.s index 1b81301c..c951648a 100644 --- a/mach/pmds4/libsys/tell.s +++ b/mach/pmds4/libsys/tell.s @@ -1,5 +1,10 @@ - .define _tell +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text + .extern _tell _tell: pea 1 diff --git a/mach/pmds4/libsys/time.s b/mach/pmds4/libsys/time.s index dce23657..a30be11c 100644 --- a/mach/pmds4/libsys/time.s +++ b/mach/pmds4/libsys/time.s @@ -1,9 +1,14 @@ .define _time .define _ftime +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _time _time: trap #0 -.short 0xD +.data2 0xD tst.l 4(sp) beq 1f move.l 4(sp),a0 @@ -13,7 +18,7 @@ _time: .extern _ftime _ftime: trap #0 -.short 0x23 +.data2 0x23 bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/times.s b/mach/pmds4/libsys/times.s index 4268e3eb..1839d170 100644 --- a/mach/pmds4/libsys/times.s +++ b/mach/pmds4/libsys/times.s @@ -1,6 +1,11 @@ .define _times +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _times _times: trap #0 -.short 0x2B +.data2 0x2B rts diff --git a/mach/pmds4/libsys/umask.s b/mach/pmds4/libsys/umask.s index cb597579..c037c07d 100644 --- a/mach/pmds4/libsys/umask.s +++ b/mach/pmds4/libsys/umask.s @@ -1,6 +1,11 @@ .define _umask +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _umask -.text +.sect .text _umask: trap #0 -.short 0x3C +.data2 0x3C rts diff --git a/mach/pmds4/libsys/umount.s b/mach/pmds4/libsys/umount.s index 9fd13f0e..c8020ba3 100644 --- a/mach/pmds4/libsys/umount.s +++ b/mach/pmds4/libsys/umount.s @@ -1,7 +1,12 @@ .define _umount +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _umount _umount: trap #0 -.short 0x16 +.data2 0x16 bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/unlink.s b/mach/pmds4/libsys/unlink.s index 2093ce74..14fd3b79 100644 --- a/mach/pmds4/libsys/unlink.s +++ b/mach/pmds4/libsys/unlink.s @@ -1,7 +1,12 @@ .define _unlink +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _unlink _unlink: trap #0 -.short 0xA +.data2 0xA bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/utime.s b/mach/pmds4/libsys/utime.s index 68f7ae9b..ed316172 100644 --- a/mach/pmds4/libsys/utime.s +++ b/mach/pmds4/libsys/utime.s @@ -1,7 +1,12 @@ .define _utime +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _utime _utime: trap #0 -.short 0x1E +.data2 0x1E bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/wait.s b/mach/pmds4/libsys/wait.s index 7a8a6ebb..0e569457 100644 --- a/mach/pmds4/libsys/wait.s +++ b/mach/pmds4/libsys/wait.s @@ -1,7 +1,12 @@ .define _wait +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _wait _wait: trap #0 -.short 0x7 +.data2 0x7 bcc 1f jmp cerror 1: diff --git a/mach/pmds4/libsys/write.s b/mach/pmds4/libsys/write.s index cb87ca0f..fec58061 100644 --- a/mach/pmds4/libsys/write.s +++ b/mach/pmds4/libsys/write.s @@ -1,7 +1,12 @@ .define _write +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _write _write: trap #0 -.short 0x4 +.data2 0x4 bcc 1f jmp cerror 1: From 124b2e1be9e050ec4c62f63acf6cc9df5b2d6733 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 26 Jan 1987 21:43:12 +0000 Subject: [PATCH 0546/1625] Initial revision --- mach/pmds4/libsys/gtty.s | 17 +++++++++++++++++ mach/pmds4/libsys/stty.s | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 mach/pmds4/libsys/gtty.s create mode 100644 mach/pmds4/libsys/stty.s diff --git a/mach/pmds4/libsys/gtty.s b/mach/pmds4/libsys/gtty.s new file mode 100644 index 00000000..1cd8c8b1 --- /dev/null +++ b/mach/pmds4/libsys/gtty.s @@ -0,0 +1,17 @@ +.define _gtty +.extern _gtty +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_gtty: +tst.b -40(sp) +link a6,#-0 +move.l 12(a6),-(sp) +move.l #0x7408,-(sp) +move.l 8(a6),-(sp) +jsr _ioctl +add.l #12,sp +unlk a6 +rts diff --git a/mach/pmds4/libsys/stty.s b/mach/pmds4/libsys/stty.s new file mode 100644 index 00000000..d53abe17 --- /dev/null +++ b/mach/pmds4/libsys/stty.s @@ -0,0 +1,17 @@ +.define _stty +.extern _stty +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_stty: +tst.b -40(sp) +link a6,#-0 +move.l 12(a6),-(sp) +move.l #0x7409,-(sp) +move.l 8(a6),-(sp) +jsr _ioctl +add.l #12,sp +unlk a6 +rts From e8dc0bcbd41c271931ed5204b24c3fdd468f31d1 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 26 Jan 1987 21:47:59 +0000 Subject: [PATCH 0547/1625] Added stty, gtty --- mach/pmds4/libsys/LIST | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mach/pmds4/libsys/LIST b/mach/pmds4/libsys/LIST index 5ee9694d..c4b16677 100644 --- a/mach/pmds4/libsys/LIST +++ b/mach/pmds4/libsys/LIST @@ -1,4 +1,7 @@ libmon_s.a +stty.s +gtty.s +exit1.s access.s acct.s alarm.s @@ -45,7 +48,6 @@ unlink.s utime.s wait.s write.s -exit1.s exit2.s cleanup.s cerror.s From 16ba1edbae8138cbc4991880ab25139abe92653d Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 26 Jan 1987 21:51:58 +0000 Subject: [PATCH 0548/1625] Initial revision --- mach/pmds4/libsys/compmodule | 4 ++++ 1 file changed, 4 insertions(+) create mode 100755 mach/pmds4/libsys/compmodule diff --git a/mach/pmds4/libsys/compmodule b/mach/pmds4/libsys/compmodule new file mode 100755 index 00000000..c5b59be9 --- /dev/null +++ b/mach/pmds4/libsys/compmodule @@ -0,0 +1,4 @@ +if pmds4 -c $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 +fi From bde4823eb556db5f1e0eca4a121cc9494c623af2 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 26 Jan 1987 22:15:21 +0000 Subject: [PATCH 0549/1625] system call numbers are longwords From 38fc690dadc25f12e0a05dd910c395dbe610b732 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 26 Jan 1987 22:33:58 +0000 Subject: [PATCH 0550/1625] Initial revision --- mach/m68k4/libsys/execle.s | 20 ++++++++++++++++++++ mach/m68k4/libsys/execv.s | 16 ++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 mach/m68k4/libsys/execle.s create mode 100644 mach/m68k4/libsys/execv.s diff --git a/mach/m68k4/libsys/execle.s b/mach/m68k4/libsys/execle.s new file mode 100644 index 00000000..0bae3ede --- /dev/null +++ b/mach/m68k4/libsys/execle.s @@ -0,0 +1,20 @@ +.define _execle +.extern _execle +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_execle: link a6,#0 + tst.b -48(sp) + lea 12(a6),a0 +1: + tst.l (a0)+ + bne 1b + move.l a0,-(sp) + pea 12(a6) + move.l 8(a6),-(sp) + jsr _execve + add.l #0xC,sp + unlk a6 + rts diff --git a/mach/m68k4/libsys/execv.s b/mach/m68k4/libsys/execv.s new file mode 100644 index 00000000..e8bb105a --- /dev/null +++ b/mach/m68k4/libsys/execv.s @@ -0,0 +1,16 @@ +.define _execv +.extern _execv +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_execv: link a6,#0 + tst.b -48(sp) + move.l _environ,-(sp) + move.l 12(a6),-(sp) + move.l 8(a6),-(sp) + jsr _execve + add.l #0xC,sp + unlk a6 + rts From c461435cfe6f5468e3d5eec4624f574ac2c02c13 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 26 Jan 1987 22:35:41 +0000 Subject: [PATCH 0551/1625] Adaption to new assembler generating .o files --- mach/m68k4/libsys/Makefile | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/mach/m68k4/libsys/Makefile b/mach/m68k4/libsys/Makefile index 8908c873..f234ee51 100644 --- a/mach/m68k4/libsys/Makefile +++ b/mach/m68k4/libsys/Makefile @@ -1,15 +1,22 @@ # $Header$ MACH=m68k4 -all: tail_mon +all: libmon_o.a head_em + install: all - ../../install tail_mon + ../../install head_em.o head_em + ../../install libmon_o.a tail_mon + cmp: all - -../../compare tail_mon + -../../compare head_em.o head_em + -../../compare libmon_o.a tail_mon -tail_mon: tail_mon.a +libmon_o.a: libmon_s.a ASAR=aal ; export ASAR ;\ - march . tail_mon + march . libmon_o.a + +head_em.o: head_em.s + $(MACH) -I../../../h -c head_em.s clean: rm -f *.o @@ -18,4 +25,5 @@ opr : make pr | opr pr: - @ar pv tail_mon.a + @pr `pwd`/head_em.s + @arch pv libmon_s.a | pr -h `pwd`/libmon_s.a From 7965aef382752da2fc1f010f360ff7aafbdb67f1 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 27 Jan 1987 10:41:19 +0000 Subject: [PATCH 0552/1625] Better "clean" entry" --- mach/m68k4/libsys/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mach/m68k4/libsys/Makefile b/mach/m68k4/libsys/Makefile index f234ee51..142afee5 100644 --- a/mach/m68k4/libsys/Makefile +++ b/mach/m68k4/libsys/Makefile @@ -1,6 +1,6 @@ # $Header$ MACH=m68k4 -all: libmon_o.a head_em +all: libmon_o.a head_em.o install: all ../../install head_em.o head_em @@ -19,7 +19,7 @@ head_em.o: head_em.s $(MACH) -I../../../h -c head_em.s clean: - rm -f *.o + rm -f *.o libmon_o.a opr : make pr | opr From 86898515ced0d36d6628169376c0deba7a3f3eaa Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 27 Jan 1987 10:45:01 +0000 Subject: [PATCH 0553/1625] Contained syntax errors --- mach/pmds4/libsys/exec.s | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mach/pmds4/libsys/exec.s b/mach/pmds4/libsys/exec.s index 793de9cd..a73da05c 100644 --- a/mach/pmds4/libsys/exec.s +++ b/mach/pmds4/libsys/exec.s @@ -22,14 +22,14 @@ pushp: unlk a6 rts _execve: trap #0 -.data2 3B +.data2 0x3b jmp cerror _execv: tst.b -48(sp) link a6,#0 move.l _environ,-(sp) move.l 12(a6),-(sp) - br pushp + bra pushp _execle: tst.b -48(sp) link a6,#0 lea 12(a6),a0 @@ -37,4 +37,4 @@ _execle: tst.b -48(sp) tst.l (a0)+ bne 1b move.l a0,-(sp) - br pusha + bra pusha From 88025345b990e5d46f3b450a553a9e79bbdea44c Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 27 Jan 1987 10:50:43 +0000 Subject: [PATCH 0554/1625] correction of syntax errors --- mach/pmds4/libsys/tell.s | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mach/pmds4/libsys/tell.s b/mach/pmds4/libsys/tell.s index c951648a..e10c8d29 100644 --- a/mach/pmds4/libsys/tell.s +++ b/mach/pmds4/libsys/tell.s @@ -8,8 +8,8 @@ .extern _tell _tell: pea 1 - clrl.l -(sp) - mov.l 12(sp),-(sp) + clr.l -(sp) + move.l 12(sp),-(sp) jsr _lseek add #12,sp rts From 55e2a3d018b34d81d3227ba7e05688b6e26fd623 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 27 Jan 1987 10:52:09 +0000 Subject: [PATCH 0555/1625] Improved "clean" entry" --- mach/pmds4/libsys/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mach/pmds4/libsys/Makefile b/mach/pmds4/libsys/Makefile index 397ccf67..c796c26e 100644 --- a/mach/pmds4/libsys/Makefile +++ b/mach/pmds4/libsys/Makefile @@ -1,6 +1,6 @@ # $Header$ MACH=pmds4 -all: libmon_o.a head_em +all: libmon_o.a head_em.o install: all ../../install head_em.o head_em @@ -19,7 +19,7 @@ head_em.o: head_em.s $(MACH) -I../../../h -c head_em.s clean: - rm -f *.o + rm -f *.o libmon_o.a opr : make pr | opr From b04aa79797c82d8895fa52d964050be7fb61b489 Mon Sep 17 00:00:00 2001 From: bruce Date: Tue, 27 Jan 1987 11:42:08 +0000 Subject: [PATCH 0556/1625] Changed to reflect location of EMHOME and conform to standard syntax. --- modules/src/em_opt/Makefile | 104 +++++++++++++++++++++--------------- 1 file changed, 62 insertions(+), 42 deletions(-) diff --git a/modules/src/em_opt/Makefile b/modules/src/em_opt/Makefile index 943dacce..7874aaa1 100644 --- a/modules/src/em_opt/Makefile +++ b/modules/src/em_opt/Makefile @@ -1,64 +1,84 @@ # $Header$ +EMHOME = ../../.. +INSTALL = $(EMHOME)/modules/install +COMPARE = $(EMHOME)/modules/compare +LIBOPT = libopt.a -# Where to find em home directory +CSRC = nopt.c aux.c mkcalls.c pseudo.c outputdfa.c outcalls.c\ + findworst.c initlex.c -EMHOME=/usr/em -MODLIB=$(EMHOME)/modules/lib +SRCS = Makefile nopt.h parser.h parser.g syntax.l patterns $(CSRC) + +NOFILES=nopt.o dfa.o trans.o incalls.o pseudo.o aux.o mkcalls.o + +POFILES=parser.o syntax.o outputdfa.o outcalls.o findworst.o initlex.o Lpars.o + +GENFILES=Lpars.h Lpars.c parserdummy parser.c syntax.c dfadummy\ + dfa.c dfa.c.save trans.c trans.c.save incalls.c incalls.c.save + +all: $(LIBOPT) + +install: all + $(INSTALL) lib/$(LIBOPT) + +cmp: all + $(COMPARE) lib/$(LIBOPT) + +pr: + @pr $(SRCS) + +opr: + make pr | opr + +clean: + rm -f $(NOFILES) $(POFILES) $(GENFILES) parser core makerror # set HOWMUCH to head -20 to limit number of patterns used +#HOWMUCH=head -20 HOWMUCH=cat LEXLIB=-ll -INCLDIR=-I$(EMHOME)/h -I$(EMHOME)/modules/h -I$(EMHOME)/modules/pkg -I../h +INCLDIR=-I$(EMHOME)/h -I$(EMHOME)/modules/h -I$(EMHOME)/modules/pkg PREFLAGS=$(INCLDIR) -DPRIVATE=static PROFFLAG=-O CFLAGS=$(PREFLAGS) $(PROFFLAG) LLOPT= -GENFILES=Lpars.h Lpars.c parserdummy parser.c syntax.c dfadummy\ - dfa.c dfa.c.save trans.c trans.c.save incalls.c incalls.c.save +$(LIBOPT): dfadummy $(NOFILES) + rm -f $(LIBOPT) + ar rc $(LIBOPT) $(NOFILES) + -sh -c 'ranlib $(LIBOPT)' -all: libopt.a +dfadummy: patterns parser + -mv dfa.c dfa.c.save + -mv trans.c trans.c.save + -mv incalls.c incalls.c.save + -/lib/cpp patterns | $(HOWMUCH) >/tmp/patts + parser /tmp/patts - parser Date: Tue, 27 Jan 1987 14:15:23 +0000 Subject: [PATCH 0557/1625] Ported code to Mantra and general clean up. --- modules/src/em_opt/Makefile | 27 ++++---- modules/src/em_opt/aux.c | 6 +- modules/src/em_opt/nopt.c | 122 +++++---------------------------- modules/src/em_opt/nopt.h | 5 +- modules/src/em_opt/outputdfa.c | 93 +++++++++++++------------ 5 files changed, 85 insertions(+), 168 deletions(-) diff --git a/modules/src/em_opt/Makefile b/modules/src/em_opt/Makefile index 7874aaa1..4ba4de94 100644 --- a/modules/src/em_opt/Makefile +++ b/modules/src/em_opt/Makefile @@ -9,11 +9,11 @@ CSRC = nopt.c aux.c mkcalls.c pseudo.c outputdfa.c outcalls.c\ SRCS = Makefile nopt.h parser.h parser.g syntax.l patterns $(CSRC) -NOFILES=nopt.o dfa.o trans.o incalls.o pseudo.o aux.o mkcalls.o +NOFILES = nopt.o dfa.o trans.o incalls.o pseudo.o aux.o mkcalls.o -POFILES=parser.o syntax.o outputdfa.o outcalls.o findworst.o initlex.o Lpars.o +POFILES = parser.o syntax.o outputdfa.o outcalls.o findworst.o initlex.o Lpars.o -GENFILES=Lpars.h Lpars.c parserdummy parser.c syntax.c dfadummy\ +GENFILES = Lpars.h Lpars.c parserdummy parser.c syntax.c dfadummy\ dfa.c dfa.c.save trans.c trans.c.save incalls.c incalls.c.save all: $(LIBOPT) @@ -34,15 +34,18 @@ clean: rm -f $(NOFILES) $(POFILES) $(GENFILES) parser core makerror # set HOWMUCH to head -20 to limit number of patterns used -#HOWMUCH=head -20 -HOWMUCH=cat +#HOWMUCH = head -20 +HOWMUCH = cat -LEXLIB=-ll -INCLDIR=-I$(EMHOME)/h -I$(EMHOME)/modules/h -I$(EMHOME)/modules/pkg -PREFLAGS=$(INCLDIR) -DPRIVATE=static -PROFFLAG=-O -CFLAGS=$(PREFLAGS) $(PROFFLAG) -LLOPT= +LEXLIB = -ll +INCLDIR = -I$(EMHOME)/h -I$(EMHOME)/modules/h -I$(EMHOME)/modules/pkg +PREFLAGS = $(INCLDIR) -DPRIVATE=static +# Enable the next line to produce a version that output's the line number +# from the patterns file each time an optimization is performed. +#PREFLAGS = $(PREFLAGS) -DSTATS +PROFFLAG = -O +CFLAGS = $(PREFLAGS) $(PROFFLAG) +LLOPT = $(LIBOPT): dfadummy $(NOFILES) rm -f $(LIBOPT) @@ -63,7 +66,7 @@ dfadummy: patterns parser # How to build program to parse patterns table and build c files. -PARSERLIB=$(EMHOME)/lib/em_data.a\ +PARSERLIB = $(EMHOME)/lib/em_data.a\ $(EMHOME)/modules/lib/libprint.a\ $(EMHOME)/modules/lib/liballoc.a\ $(EMHOME)/modules/lib/libstring.a\ diff --git a/modules/src/em_opt/aux.c b/modules/src/em_opt/aux.c index 700fb0e5..2b85e16b 100644 --- a/modules/src/em_opt/aux.c +++ b/modules/src/em_opt/aux.c @@ -12,7 +12,7 @@ OO_rotate(w,amount) return(((w<> (8*OO_WSIZE-amount))&lowmask)); } -OO_samesign(a,b) +OO_signsame(a,b) int a, b; { return( (a ^ b) >= 0); @@ -38,7 +38,7 @@ OO_ufit(val, nbits) return((val&mask) == 0); } -OO_sameext(a1,a2) +OO_extsame(a1,a2) struct instr *a1, *a2; { if(a1->argtype != a2->argtype) return(0); @@ -56,7 +56,7 @@ OO_sameext(a1,a2) } } -OO_samenam(a1,a2) +OO_namsame(a1,a2) struct instr *a1, *a2; { if(a1->argtype != a2->argtype) return(0); diff --git a/modules/src/em_opt/nopt.c b/modules/src/em_opt/nopt.c index 0c41fd04..636d3a29 100644 --- a/modules/src/em_opt/nopt.c +++ b/modules/src/em_opt/nopt.c @@ -3,7 +3,7 @@ static char rcsid[] = "$Header$"; #endif #include "nopt.h" -#define MAXPATTERN 15 +extern int maxpattern; /* Initialized from patterns in dfa.c */ #define MAXBACKUP 50 #define MAXOUTPUT 200 #define MAXFREEI 200 @@ -36,21 +36,7 @@ int OO_WSIZE; /* wordlength */ int OO_PSIZE; /* pointer length */ #ifdef STATS -int sflag = 1; /* pattern statistics output */ -#endif -#ifdef COLLECT -int cflag = 0; /* internal statistics output */ -#define UPDATEMAX(oldmax,n) if(cflag&&n>oldmax) oldmax=n -static int numwrites = 0; -static int numpushs = 0; -static int numbackups = 0; -static int numflushes = 0; -static int numfrees = 0; -static int numdefaults = 0; -static int highestbackup = 0, totalbackup = 0; -static int highestoutput = 0, totaloutput = 0; -static int highestfreei = 0, totalfreei = 0; -static int higheststr = 0, totalstr = 0; +int OO_wrstats = 1; /* pattern statistics output */ #endif C_init(wsize,psize) @@ -76,10 +62,6 @@ C_magic() C_close() { -#ifdef COLLECT - if(cflag) - outputstats(); -#endif O_close(); } @@ -99,7 +81,7 @@ allocmem() { /* Allocate memory for queues on heap */ OO_nxtpatt = OO_patternqueue = - (struct instr **)Malloc(MAXPATTERN*sizeof(struct instr *)); + (struct instr **)Malloc(maxpattern*sizeof(struct instr *)); OO_nxtbackup = OO_bkupqueue = (struct instr **)Malloc(MAXBACKUP*sizeof(struct instr *)); lastbackup = OO_bkupqueue + MAXBACKUP - 1; @@ -115,58 +97,20 @@ allocmem() laststr = strqueue + MAXSTRING - 1; } -#ifdef COLLECT -PRIVATE -outputstats() -{ - int i; - fprint(STDERR,"Total of %d instructions read, %d written\n",numreads,numwrites); - fprint(STDERR,"Total of %d calls to flush\n",numflushes); - fprint(STDERR,"Total of %d calls to myfree\n",numfrees); - fprint(STDERR,"Total of %d instructions pushed back\n",numpushs-numbackups); - fprint(STDERR,"Total of %d instructions backed up\n",numbackups); - fprint(STDERR,"Total of %d calls to dodefault\n",numdefaults); - fprint(STDERR,"Max of highestbackup\t%d\t(%d)\t",highestbackup,MAXBACKUP); - printav(totalbackup); - fprint(STDERR,"Max of highestoutput\t%d\t(%d)\t",highestoutput,MAXOUTPUT); - printav(totaloutput); - fprint(STDERR,"Max of highestfreei\t%d\t(%d)\t",highestfreei,MAXFREEI); - printav(totalfreei); - fprint(STDERR,"Max of higheststr\t%d\t(%d)\t",higheststr,MAXSTRING); - printav(totalstr); -} - -PRIVATE -printav(n) - int n; -{ - fprint(STDERR,"Av.\t%d.%d\n",n/numflushes,(n*10)%numflushes); -} -#endif - OO_free(p) struct instr *p; { -#ifdef DEBUG - fprint(STDERR,"about to free "); - prtinst(p); - fprint(STDERR,"\n"); -#endif -#ifdef COLLECT - if(cflag) - numfrees++; -#endif if(nextifree > lastifree) { #ifdef DEBUG - fprint(STDERR,"Warning: Overflow of freeiqueue-free arg ignored\n"); + fprint(STDERR,"Warning: Overflow of free intr. queue.\n"); + fprint(STDERR,"Ignored free of "); + prtinst(p); + fprint(STDERR,"\n"); printstate("Freea overflow"); #endif return; } *nextifree++ = p; -#ifdef COLLECT - UPDATEMAX(highestfreei,nextifree-freeiqueue); -#endif } PRIVATE char * @@ -179,9 +123,6 @@ freestr(s) fprint(STDERR,"string space overflowed!\n"); sys_stop(S_EXIT); } -#ifdef COLLECT - UPDATEMAX(higheststr,nextstr-strqueue); -#endif return(res); } @@ -194,22 +135,9 @@ OO_flush() struct instr **p; #ifdef DEBUG printstate("Flush"); -#endif -#ifdef COLLECT - if(cflag) { - numflushes++; - totaloutput += nextoutput-outputqueue; - totalbackup += OO_nxtbackup-OO_bkupqueue; - totalfreei += nextifree-freeiqueue; - totalstr += nextstr-strqueue; - } #endif if(OO_noutput) { for(p=outputqueue;popcode = opcode; p->argtype = none_ptyp; - OO_output(p); + OO_out(p); } OO_inop(opcode) @@ -245,7 +173,7 @@ OO_outcst(opcode,cst) p->opcode = opcode; p->argtype = cst_ptyp; p->acst = cst; - OO_output(p); + OO_out(p); } OO_incst(opcode,cst) @@ -265,7 +193,7 @@ OO_outlab(opcode,lab) p->opcode = opcode; p->argtype = cst_ptyp; p->acst = lab; - OO_output(p); + OO_out(p); } OO_inlab(opcode,lab) @@ -286,7 +214,7 @@ OO_outpnam(opcode,pnam) p->opcode = opcode; p->argtype = pro_ptyp; p->apnam = pnam; - OO_output(p); + OO_out(p); } OO_inpnam(opcode,pnam) @@ -308,7 +236,7 @@ OO_outdefilb(opcode,deflb) p->opcode = opcode; p->argtype = lab_ptyp; p->alab = deflb; - OO_output(p); + OO_out(p); } OO_indefilb(opcode,deflb) @@ -344,7 +272,7 @@ OO_outext(opcode,arg,soff) default: fatal("Unexpected type %d in outext",arg->argtype); } - OO_output(p); + OO_out(p); } OO_indnam(opcode,name,off) @@ -373,22 +301,18 @@ OO_indlb(opcode,lab,off) *OO_nxtpatt++ = p; } -OO_output(p) +OO_out(p) struct instr *p; { /* Put the instruction p on the output queue */ if(nextoutput > lastoutput) { #ifdef DEBUG - fprint(STDERR,"Overflow of outputqueue - output flushed\n"); - printstate("Output overflow"); + fprint(STDERR,"Warning: Overflow of outputqueue - output flushed\n"); #endif OO_flush(); } OO_noutput++; *nextoutput++ = p; -#ifdef COLLECT - UPDATEMAX(highestoutput,nextoutput-outputqueue); -#endif } OO_pushback(p) @@ -403,10 +327,6 @@ OO_pushback(p) return; } *OO_nxtbackup++ = p; -#ifdef COLLECT - UPDATEMAX(highestbackup,OO_nxtbackup-OO_bkupqueue); - numpushs++; -#endif } OO_backup(n) @@ -414,10 +334,6 @@ OO_backup(n) { /* copy (up to) n instructions from output to backup queues */ while(n-- && nextoutput>outputqueue) { -#ifdef COLLECT - if(cflag) - numbackups++; -#endif OO_pushback(*(--nextoutput)); OO_noutput--; } @@ -431,16 +347,12 @@ OO_dodefault(numout, numcopy) while(numcopy--) { if(numout) { numout--; - OO_output(*p); + OO_out(*p); } *p++ = *q++; } OO_nxtpatt = p; - while(numout--) OO_output(*p++); -#ifdef COLLECT - if(cflag) - numdefaults++; -#endif + while(numout--) OO_out(*p++); } #ifdef DEBUG diff --git a/modules/src/em_opt/nopt.h b/modules/src/em_opt/nopt.h index d4e31186..a7c2b7dc 100644 --- a/modules/src/em_opt/nopt.h +++ b/modules/src/em_opt/nopt.h @@ -59,11 +59,8 @@ extern int OO_state; extern int OO_noutput; /* number of instructions in output queue */ extern int OO_WSIZE; /* wordlength */ extern int OO_PSIZE; /* pointer length */ -#ifdef DEBUG -extern int dflag; /* debugging output */ -#endif #ifdef STATS -extern int sflag; /* statistics output */ +extern int OO_wrstats; /* statistics output */ #endif #define CST(p) (p->acst) diff --git a/modules/src/em_opt/outputdfa.c b/modules/src/em_opt/outputdfa.c index d46b36c5..b5efa62d 100644 --- a/modules/src/em_opt/outputdfa.c +++ b/modules/src/em_opt/outputdfa.c @@ -13,23 +13,25 @@ outputnopt() fprint(STDERR,"Couldn't open dfa.c for output\n"); sys_stop(S_EXIT); } - outputheaders(); - outputtables(); - outputdfa(); - outputdodefault(); - outputdotrans(); + outheaders(); + outtables(); + outdfa(); + outdodefault(); + outdotrans(); outputincalls(); } PRIVATE -outputheaders() +outheaders() { fprint(ofile,"#include \"nopt.h\"\n"); fprint(ofile,"\n"); + fprint(ofile,"int maxpattern = %d;\n", longestpattern); + fprint(ofile,"\n"); } PRIVATE -outputtables() +outtables() { int s; fprint(ofile,"static struct defact {\n"); @@ -47,7 +49,7 @@ outputtables() } PRIVATE -outputdfa() +outdfa() { int s; struct idf *op; @@ -64,7 +66,7 @@ outputdfa() fprint(ofile,"\t\t\tswitch(OO_state) {\n"); if(!op->id_startpatt) { fprint(ofile,"\t\t\tcase 0: "); - fprint(ofile,"OO_output(*--OO_nxtpatt); "); + fprint(ofile,"OO_out(*--OO_nxtpatt); "); fprint(ofile,"break;\n"); } for(s=0;s<=higheststate;s++) @@ -77,12 +79,12 @@ outputdfa() fprint(ofile,"break;\n"); } } - fprint(ofile,"\t\t\tdefault: defaultaction(); break;\n"); + fprint(ofile,"\t\t\tdefault: dodefaultaction(); break;\n"); fprint(ofile,"\t\t\t}\n"); fprint(ofile,"\t\t\tbreak;\n"); } fprint(ofile,"\t\tdefault:\n"); - fprint(ofile,"\t\t\tif(OO_state) defaultaction();\n"); + fprint(ofile,"\t\t\tif(OO_state) dodefaultaction();\n"); fprint(ofile,"\t\t\telse {\n"); fprint(ofile,"\t\t\t\tOO_flush();\n"); fprint(ofile,"\t\t\t\tOO_mkcalls(*--OO_nxtpatt);\n"); @@ -90,7 +92,7 @@ outputdfa() fprint(ofile,"\t\t\t}\n"); fprint(ofile,"\t\t\tbreak;\n"); fprint(ofile,"\t\tcase OTHER:\n"); - fprint(ofile,"\t\t\tif(OO_state) defaultaction();\n"); + fprint(ofile,"\t\t\tif(OO_state) dodefaultaction();\n"); fprint(ofile,"\t\t\telse {\n"); fprint(ofile,"\t\t\t\tOO_flush();\n"); fprint(ofile,"\t\t\t\tOO_free(*--OO_nxtpatt);\n"); @@ -103,7 +105,7 @@ outputdfa() } PRIVATE -outputmnems(l) +outmnems(l) struct mnems l; { int i; @@ -112,7 +114,7 @@ outputmnems(l) } PRIVATE -outputdotrans() +outdotrans() { int s; int i; @@ -131,15 +133,15 @@ outputdotrans() for(s=0;s<=higheststate;s++) if(actions[s]!=(struct action *)NULL) { fprint(ofile,"\tcase %d: /*",s); - outputmnems(patterns[s]); + outmnems(patterns[s]); fprint(ofile," */\n"); seennontested=0; for(a=actions[s];a!=(struct action *)NULL;a=a->next) { if(a->test!=(struct exp_node *)NULL) { fprint(ofile,"\t\tif("); - outputexp(a->test,s); + outexp(a->test,s); fprint(ofile,") {\n"); - outputoneaction(s,a); + outoneaction(s,a); fprint(ofile,"\t\t\tgoto free%d;\n",patterns[s].m_len); fprint(ofile,"\t\t}\n"); } @@ -149,7 +151,7 @@ outputdotrans() nerrors++; } seennontested++; - outputoneaction(s,a); + outoneaction(s,a); fprint(ofile,"\t\t\tgoto free%d;\n",patterns[s].m_len); } } @@ -166,9 +168,9 @@ outputdotrans() } PRIVATE -outputdodefault() +outdodefault() { - fprint(ofile,"\nstatic defaultaction() {\n"); + fprint(ofile,"\nstatic dodefaultaction() {\n"); fprint(ofile,"\tregister struct defact *p = &defaultactions[OO_state];\n"); fprint(ofile,"\tOO_pushback(*--OO_nxtpatt);\n"); fprint(ofile,"\tOO_dodefault(p->numoutput,p->numcopy);\n"); @@ -177,20 +179,23 @@ outputdodefault() } PRIVATE -outputoneaction(s,a) +outoneaction(s,a) int s; struct action *a; { fprint(ofile,"\t\t/* "); fprint(ofile," -> "); - outputmnems(a->replacement); + outmnems(a->replacement); fprint(ofile," */\n"); - outputrepl(s,patterns[s],a->replacement); + fprint(ofile,"#ifdef STATS\n"); + fprint(ofile,"\t\t\tif(OO_wrstats) fprint(STDERR,\"%d\\n\");\n",a->linenum); + fprint(ofile,"#endif\n"); + outrepl(s,patterns[s],a->replacement); findworst(a->replacement); } PRIVATE -outputrepl(state,patt,repl) +outrepl(state,patt,repl) int state; struct mnems patt,repl; { @@ -210,27 +215,27 @@ outputrepl(state,patt,repl) case CST: case CSTOPT: fprint(ofile,"\t\t\tOO_outcst(op_%s,",mnem); - outputexp(ri->arg,state); + outexp(ri->arg,state); fprint(ofile,");\n"); break; case LAB: fprint(ofile,"\t\t\tOO_outlab(op_%s,",mnem); - outputexp(ri->arg,state); + outexp(ri->arg,state); fprint(ofile,");\n"); break; case DEFILB: fprint(ofile,"\t\t\tOO_outdefilb(op_%s,",mnem); - outputexp(ri->arg,state); + outexp(ri->arg,state); fprint(ofile,");\n"); break; case PNAM: fprint(ofile,"\t\t\tOO_outpnam(op_%s,",mnem); - outputexp(ri->arg,state); + outexp(ri->arg,state); fprint(ofile,");\n"); break; case EXT: fprint(ofile,"\t\t\tOO_outext(op_%s,",mnem); - outputexp(ri->arg,state); + outexp(ri->arg,state); fprint(ofile,");\n"); break; } @@ -238,7 +243,7 @@ outputrepl(state,patt,repl) } PRIVATE -outputexp(e,state) +outexp(e,state) struct exp_node *e; int state; { @@ -262,9 +267,9 @@ outputexp(e,state) case LSHIFT: case RSHIFT: fprint(ofile,"("); - outputexp(e->exp_left,state); - outputop(e->node_type); - outputexp(e->exp_right,state); + outexp(e->exp_left,state); + outop(e->node_type); + outexp(e->exp_right,state); fprint(ofile,")"); break; case NOT: @@ -272,8 +277,8 @@ outputexp(e,state) case UPLUS: case UMINUS: fprint(ofile,"("); - outputop(e->node_type); - outputexp(e->exp_left,state); + outop(e->node_type); + outexp(e->exp_left,state); fprint(ofile,")"); break; case DEFINED: @@ -284,21 +289,21 @@ outputexp(e,state) break; case COMMA: outext(e->exp_left); - fprint(ofile,","); outputexp(e->exp_right,state); + fprint(ofile,","); outexp(e->exp_right,state); break; case SAMESIGN: case SFIT: case UFIT: case ROTATE: - outputop(e->node_type); - outputexp(e->exp_left,state); + outop(e->node_type); + outexp(e->exp_left,state); fprint(ofile,","); - outputexp(e->exp_right,state); + outexp(e->exp_right,state); fprint(ofile,")"); break; case SAMEEXT: case SAMENAM: - outputop(e->node_type); + outop(e->node_type); outext(e->exp_left); fprint(ofile,","); outext(e->exp_right,state); @@ -349,7 +354,7 @@ outext(e) } PRIVATE -outputop(op) +outop(op) int op; { switch(op) { @@ -375,11 +380,11 @@ outputop(op) case COMP: fprint(ofile,"~"); break; case UPLUS: fprint(ofile,"+"); break; case UMINUS: fprint(ofile,"-"); break; - case SAMESIGN: fprint(ofile,"OO_samesign("); break; + case SAMESIGN: fprint(ofile,"OO_signsame("); break; case SFIT: fprint(ofile,"OO_sfit("); break; case UFIT: fprint(ofile,"OO_ufit("); break; case ROTATE: fprint(ofile,"OO_rotate("); break; - case SAMEEXT: fprint(ofile,"OO_sameext("); break; - case SAMENAM: fprint(ofile,"OO_samenam("); break; + case SAMEEXT: fprint(ofile,"OO_extsame("); break; + case SAMENAM: fprint(ofile,"OO_namsame("); break; } } From e49bbfbe1f9d4eaf48acb816dda62a670baacdd6 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 27 Jan 1987 15:57:55 +0000 Subject: [PATCH 0558/1625] Initial revision --- lang/cem/libcc/gen/_c2type.c | 22 +++ lang/cem/libcc/gen/abort.e | 7 + lang/cem/libcc/gen/abs.c | 3 + lang/cem/libcc/gen/asctime.c | 61 +++++++ lang/cem/libcc/gen/atof.c | 80 +++++++++ lang/cem/libcc/gen/atoi.c | 20 +++ lang/cem/libcc/gen/atol.c | 19 +++ lang/cem/libcc/gen/bcmp.c | 12 ++ lang/cem/libcc/gen/bcopy.c | 12 ++ lang/cem/libcc/gen/bfill.c | 8 + lang/cem/libcc/gen/bmove.c | 6 + lang/cem/libcc/gen/bzero.c | 5 + lang/cem/libcc/gen/calloc.c | 16 ++ lang/cem/libcc/gen/closedir.c | 14 ++ lang/cem/libcc/gen/crypt.c | 294 ++++++++++++++++++++++++++++++++ lang/cem/libcc/gen/ctime.c | 11 ++ lang/cem/libcc/gen/ecvt.c | 102 +++++++++++ lang/cem/libcc/gen/execvp.c | 36 ++++ lang/cem/libcc/gen/ffc.c | 10 ++ lang/cem/libcc/gen/ffs.c | 10 ++ lang/cem/libcc/gen/frexp.e | 29 ++++ lang/cem/libcc/gen/gcvt.c | 61 +++++++ lang/cem/libcc/gen/getenv.c | 14 ++ lang/cem/libcc/gen/getlogin.c | 26 +++ lang/cem/libcc/gen/getopt.c | 57 +++++++ lang/cem/libcc/gen/gmtime.c | 39 +++++ lang/cem/libcc/gen/index.c | 9 + lang/cem/libcc/gen/isatty.c | 9 + lang/cem/libcc/gen/l3.c | 24 +++ lang/cem/libcc/gen/ldexp.c | 34 ++++ lang/cem/libcc/gen/localtime.c | 52 ++++++ lang/cem/libcc/gen/malloc.c | 99 +++++++++++ lang/cem/libcc/gen/memccpy.c | 11 ++ lang/cem/libcc/gen/memchr.c | 14 ++ lang/cem/libcc/gen/memcmp.c | 15 ++ lang/cem/libcc/gen/memcpy.c | 16 ++ lang/cem/libcc/gen/memset.c | 12 ++ lang/cem/libcc/gen/mktemp.c | 26 +++ lang/cem/libcc/gen/modf.e | 33 ++++ lang/cem/libcc/gen/monitor.c | 62 +++++++ lang/cem/libcc/gen/opendir.c | 27 +++ lang/cem/libcc/gen/perror.c | 57 +++++++ lang/cem/libcc/gen/procentry.c | 42 +++++ lang/cem/libcc/gen/qsort.c | 133 +++++++++++++++ lang/cem/libcc/gen/rand.c | 13 ++ lang/cem/libcc/gen/readdir.c | 64 +++++++ lang/cem/libcc/gen/rindex.c | 12 ++ lang/cem/libcc/gen/seekdir.c | 37 ++++ lang/cem/libcc/gen/setjmp.e | 147 ++++++++++++++++ lang/cem/libcc/gen/sleep.c | 38 +++++ lang/cem/libcc/gen/stb.c | 11 ++ lang/cem/libcc/gen/strcat.c | 14 ++ lang/cem/libcc/gen/strchr.c | 9 + lang/cem/libcc/gen/strcmp.c | 15 ++ lang/cem/libcc/gen/strcpy.c | 9 + lang/cem/libcc/gen/strcspn.c | 13 ++ lang/cem/libcc/gen/strlen.c | 10 ++ lang/cem/libcc/gen/strncat.c | 22 +++ lang/cem/libcc/gen/strncmp.c | 18 ++ lang/cem/libcc/gen/strncpy.c | 13 ++ lang/cem/libcc/gen/strpbrk.c | 13 ++ lang/cem/libcc/gen/strrchr.c | 12 ++ lang/cem/libcc/gen/strspn.c | 13 ++ lang/cem/libcc/gen/strstr.c | 12 ++ lang/cem/libcc/gen/strtok.c | 25 +++ lang/cem/libcc/gen/swab.c | 10 ++ lang/cem/libcc/gen/telldir.c | 13 ++ lang/cem/libcc/gen/ttyname.c | 43 +++++ lang/cem/libcc/gen/ttyslot.c | 71 ++++++++ lang/cem/libcc/gen/tzset.c | 56 ++++++ lang/cem/libcc/stdio/clearerr.c | 7 + lang/cem/libcc/stdio/data.c | 23 +++ lang/cem/libcc/stdio/doprnt.c | 242 ++++++++++++++++++++++++++ lang/cem/libcc/stdio/doscan.c | 278 ++++++++++++++++++++++++++++++ lang/cem/libcc/stdio/fclose.c | 22 +++ lang/cem/libcc/stdio/fdopen.c | 38 +++++ lang/cem/libcc/stdio/fflush.c | 26 +++ lang/cem/libcc/stdio/fgetc.c | 7 + lang/cem/libcc/stdio/fgets.c | 21 +++ lang/cem/libcc/stdio/fillbuf.c | 37 ++++ lang/cem/libcc/stdio/fltpr.c | 57 +++++++ lang/cem/libcc/stdio/flushbuf.c | 71 ++++++++ lang/cem/libcc/stdio/fopen.c | 56 ++++++ lang/cem/libcc/stdio/fprintf.c | 11 ++ lang/cem/libcc/stdio/fputc.c | 7 + lang/cem/libcc/stdio/fputs.c | 9 + lang/cem/libcc/stdio/fread.c | 25 +++ lang/cem/libcc/stdio/freopen.c | 59 +++++++ lang/cem/libcc/stdio/fscanf.c | 10 ++ lang/cem/libcc/stdio/fseek.c | 39 +++++ lang/cem/libcc/stdio/ftell.c | 25 +++ lang/cem/libcc/stdio/fwrite.c | 23 +++ lang/cem/libcc/stdio/getchar.c | 8 + lang/cem/libcc/stdio/getgrent.c | 115 +++++++++++++ lang/cem/libcc/stdio/getpass.c | 29 ++++ lang/cem/libcc/stdio/getpw.c | 35 ++++ lang/cem/libcc/stdio/getpwent.c | 125 ++++++++++++++ lang/cem/libcc/stdio/gets.c | 17 ++ lang/cem/libcc/stdio/getw.c | 15 ++ lang/cem/libcc/stdio/popen.c | 54 ++++++ lang/cem/libcc/stdio/printf.c | 10 ++ lang/cem/libcc/stdio/putchar.c | 8 + lang/cem/libcc/stdio/puts.c | 10 ++ lang/cem/libcc/stdio/putw.c | 15 ++ lang/cem/libcc/stdio/rewind.c | 7 + lang/cem/libcc/stdio/scanf.c | 10 ++ lang/cem/libcc/stdio/setbuf.c | 20 +++ lang/cem/libcc/stdio/sprintf.c | 19 +++ lang/cem/libcc/stdio/sscanf.c | 17 ++ lang/cem/libcc/stdio/system.c | 24 +++ lang/cem/libcc/stdio/timezone.c | 59 +++++++ lang/cem/libcc/stdio/ungetc.c | 16 ++ 112 files changed, 4068 insertions(+) create mode 100644 lang/cem/libcc/gen/_c2type.c create mode 100644 lang/cem/libcc/gen/abort.e create mode 100644 lang/cem/libcc/gen/abs.c create mode 100644 lang/cem/libcc/gen/asctime.c create mode 100644 lang/cem/libcc/gen/atof.c create mode 100644 lang/cem/libcc/gen/atoi.c create mode 100644 lang/cem/libcc/gen/atol.c create mode 100644 lang/cem/libcc/gen/bcmp.c create mode 100644 lang/cem/libcc/gen/bcopy.c create mode 100644 lang/cem/libcc/gen/bfill.c create mode 100644 lang/cem/libcc/gen/bmove.c create mode 100644 lang/cem/libcc/gen/bzero.c create mode 100644 lang/cem/libcc/gen/calloc.c create mode 100644 lang/cem/libcc/gen/closedir.c create mode 100644 lang/cem/libcc/gen/crypt.c create mode 100644 lang/cem/libcc/gen/ctime.c create mode 100644 lang/cem/libcc/gen/ecvt.c create mode 100644 lang/cem/libcc/gen/execvp.c create mode 100644 lang/cem/libcc/gen/ffc.c create mode 100644 lang/cem/libcc/gen/ffs.c create mode 100644 lang/cem/libcc/gen/frexp.e create mode 100644 lang/cem/libcc/gen/gcvt.c create mode 100644 lang/cem/libcc/gen/getenv.c create mode 100644 lang/cem/libcc/gen/getlogin.c create mode 100644 lang/cem/libcc/gen/getopt.c create mode 100644 lang/cem/libcc/gen/gmtime.c create mode 100644 lang/cem/libcc/gen/index.c create mode 100644 lang/cem/libcc/gen/isatty.c create mode 100644 lang/cem/libcc/gen/l3.c create mode 100644 lang/cem/libcc/gen/ldexp.c create mode 100644 lang/cem/libcc/gen/localtime.c create mode 100644 lang/cem/libcc/gen/malloc.c create mode 100644 lang/cem/libcc/gen/memccpy.c create mode 100644 lang/cem/libcc/gen/memchr.c create mode 100644 lang/cem/libcc/gen/memcmp.c create mode 100644 lang/cem/libcc/gen/memcpy.c create mode 100644 lang/cem/libcc/gen/memset.c create mode 100644 lang/cem/libcc/gen/mktemp.c create mode 100644 lang/cem/libcc/gen/modf.e create mode 100644 lang/cem/libcc/gen/monitor.c create mode 100644 lang/cem/libcc/gen/opendir.c create mode 100644 lang/cem/libcc/gen/perror.c create mode 100644 lang/cem/libcc/gen/procentry.c create mode 100644 lang/cem/libcc/gen/qsort.c create mode 100644 lang/cem/libcc/gen/rand.c create mode 100644 lang/cem/libcc/gen/readdir.c create mode 100644 lang/cem/libcc/gen/rindex.c create mode 100644 lang/cem/libcc/gen/seekdir.c create mode 100644 lang/cem/libcc/gen/setjmp.e create mode 100644 lang/cem/libcc/gen/sleep.c create mode 100644 lang/cem/libcc/gen/stb.c create mode 100644 lang/cem/libcc/gen/strcat.c create mode 100644 lang/cem/libcc/gen/strchr.c create mode 100644 lang/cem/libcc/gen/strcmp.c create mode 100644 lang/cem/libcc/gen/strcpy.c create mode 100644 lang/cem/libcc/gen/strcspn.c create mode 100644 lang/cem/libcc/gen/strlen.c create mode 100644 lang/cem/libcc/gen/strncat.c create mode 100644 lang/cem/libcc/gen/strncmp.c create mode 100644 lang/cem/libcc/gen/strncpy.c create mode 100644 lang/cem/libcc/gen/strpbrk.c create mode 100644 lang/cem/libcc/gen/strrchr.c create mode 100644 lang/cem/libcc/gen/strspn.c create mode 100644 lang/cem/libcc/gen/strstr.c create mode 100644 lang/cem/libcc/gen/strtok.c create mode 100644 lang/cem/libcc/gen/swab.c create mode 100644 lang/cem/libcc/gen/telldir.c create mode 100644 lang/cem/libcc/gen/ttyname.c create mode 100644 lang/cem/libcc/gen/ttyslot.c create mode 100644 lang/cem/libcc/gen/tzset.c create mode 100644 lang/cem/libcc/stdio/clearerr.c create mode 100644 lang/cem/libcc/stdio/data.c create mode 100644 lang/cem/libcc/stdio/doprnt.c create mode 100644 lang/cem/libcc/stdio/doscan.c create mode 100644 lang/cem/libcc/stdio/fclose.c create mode 100644 lang/cem/libcc/stdio/fdopen.c create mode 100644 lang/cem/libcc/stdio/fflush.c create mode 100644 lang/cem/libcc/stdio/fgetc.c create mode 100644 lang/cem/libcc/stdio/fgets.c create mode 100644 lang/cem/libcc/stdio/fillbuf.c create mode 100644 lang/cem/libcc/stdio/fltpr.c create mode 100644 lang/cem/libcc/stdio/flushbuf.c create mode 100644 lang/cem/libcc/stdio/fopen.c create mode 100644 lang/cem/libcc/stdio/fprintf.c create mode 100644 lang/cem/libcc/stdio/fputc.c create mode 100644 lang/cem/libcc/stdio/fputs.c create mode 100644 lang/cem/libcc/stdio/fread.c create mode 100644 lang/cem/libcc/stdio/freopen.c create mode 100644 lang/cem/libcc/stdio/fscanf.c create mode 100644 lang/cem/libcc/stdio/fseek.c create mode 100644 lang/cem/libcc/stdio/ftell.c create mode 100644 lang/cem/libcc/stdio/fwrite.c create mode 100644 lang/cem/libcc/stdio/getchar.c create mode 100644 lang/cem/libcc/stdio/getgrent.c create mode 100644 lang/cem/libcc/stdio/getpass.c create mode 100644 lang/cem/libcc/stdio/getpw.c create mode 100644 lang/cem/libcc/stdio/getpwent.c create mode 100644 lang/cem/libcc/stdio/gets.c create mode 100644 lang/cem/libcc/stdio/getw.c create mode 100644 lang/cem/libcc/stdio/popen.c create mode 100644 lang/cem/libcc/stdio/printf.c create mode 100644 lang/cem/libcc/stdio/putchar.c create mode 100644 lang/cem/libcc/stdio/puts.c create mode 100644 lang/cem/libcc/stdio/putw.c create mode 100644 lang/cem/libcc/stdio/rewind.c create mode 100644 lang/cem/libcc/stdio/scanf.c create mode 100644 lang/cem/libcc/stdio/setbuf.c create mode 100644 lang/cem/libcc/stdio/sprintf.c create mode 100644 lang/cem/libcc/stdio/sscanf.c create mode 100644 lang/cem/libcc/stdio/system.c create mode 100644 lang/cem/libcc/stdio/timezone.c create mode 100644 lang/cem/libcc/stdio/ungetc.c diff --git a/lang/cem/libcc/gen/_c2type.c b/lang/cem/libcc/gen/_c2type.c new file mode 100644 index 00000000..c66616ee --- /dev/null +++ b/lang/cem/libcc/gen/_c2type.c @@ -0,0 +1,22 @@ +/* File : _c2type.c + Author : Richard A. O'Keefe. + Updated: 23 April 1984 + Purpose: Map character codes to types + + The mapping used here is such that we can use it for converting + numbers expressed in a variety of radices to binary as well as for + classifying characters. +*/ + +char _c2type[129] = + { 37, /* EOF == -1 */ + 37, 37, 37, 37, 37, 37, 37, 37, 37, 38, 39, 39, 39, 39, 37, 37, + 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, + 38, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, + 00, 01, 02, 03, 04, 05, 06, 07, 8, 9, 36, 36, 36, 36, 36, 36, + 36, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 36, 36, 36, 36, + 36, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 36, 36, 36, 36 + }; + diff --git a/lang/cem/libcc/gen/abort.e b/lang/cem/libcc/gen/abort.e new file mode 100644 index 00000000..28b3f0d1 --- /dev/null +++ b/lang/cem/libcc/gen/abort.e @@ -0,0 +1,7 @@ +#include + mes 2,EM_WSIZE,EM_PSIZE + exp $abort + pro $abort,0 + loc EILLINS + trp + end diff --git a/lang/cem/libcc/gen/abs.c b/lang/cem/libcc/gen/abs.c new file mode 100644 index 00000000..bd54e264 --- /dev/null +++ b/lang/cem/libcc/gen/abs.c @@ -0,0 +1,3 @@ +abs(i){ + return i < 0 ? -i : i; +} diff --git a/lang/cem/libcc/gen/asctime.c b/lang/cem/libcc/gen/asctime.c new file mode 100644 index 00000000..fc3034ed --- /dev/null +++ b/lang/cem/libcc/gen/asctime.c @@ -0,0 +1,61 @@ +#include + +#define DATE_STR "??? ??? ?? ??:??:?? ????\n" + +static char *days[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; + +static char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; + +static char *two_digits(); +static char *four_digits(); + +char * +asctime(tm) + register struct tm *tm; +{ + static char buf[32]; + register char *pb = buf, *ps; + + strcpy(pb, DATE_STR); + ps = days[tm->tm_wday]; + while (*ps) *pb++ = *ps++; + pb++; + ps = months[tm->tm_mon]; + while (*ps) *pb++ = *ps++; + pb++; + pb = two_digits( + two_digits( + two_digits( + two_digits(pb, tm->tm_mday), + tm->tm_hour), + tm->tm_min), + tm->tm_sec); + four_digits(pb, tm->tm_year+1900); + return(buf); +} + +static char * +two_digits(pb, i) + register char *pb; +{ + *pb = (i / 10) % 10 + '0'; + if (*pb == '0') *pb = ' '; + pb++; + *pb++ = (i % 10) + '0'; + return ++pb; +} + +static char * +four_digits(pb, i) + register char *pb; +{ + i %= 10000; + *pb++ = (i / 1000) + '0'; + i %= 1000; + *pb++ = (i / 100) + '0'; + i %= 100; + *pb++ = (i / 10) + '0'; + *pb++ = (i % 10) + '0'; + return ++pb; +} diff --git a/lang/cem/libcc/gen/atof.c b/lang/cem/libcc/gen/atof.c new file mode 100644 index 00000000..e98cc449 --- /dev/null +++ b/lang/cem/libcc/gen/atof.c @@ -0,0 +1,80 @@ +#ifndef NOFLOAT +#include + +extern double ldexp(); + +double +atof(p) + register char *p; +{ + register int c; + int exp = 0, sign = 1, expsign = 0; + double fl; + double big = (double)(1L << 30) * (1L << 22); + + while (isspace(*p)) p++; + c = *p; + + switch (c) { + case '-': + sign = -1; + case '+': + p++; + } + + fl = 0.0; + while (isdigit(c = *p++)) { + if (fl < big) + fl = 10.0 * fl + (double)(c - '0'); + else + exp++; + } + if (c == '.') { + while (isdigit(c = *p++)) { + if (fl < big) { + fl = 10.0 * fl + (double) (c - '0'); + exp--; + } + } + } + if (fl == 0) return 0; + if (c == 'E' || c == 'e') { + int exp1 = 0; + int sign = 1; + + switch (*p) { + case '-': + sign = -1; + case '+': + p++; + } + while (isdigit(c = *p++)) { + exp1 = 10 * exp1 + c - '0'; + } + exp += sign * exp1; + } + + if (exp < 0) { + expsign = 1; + exp = -exp; + } + + if (exp != 0) { + int oldexp = exp; + double exp5 = 5; + double correction = 1; + + while (exp) { + if (exp % 2) correction *= exp5; + exp /= 2; + exp5 *= exp5; + } + if (expsign) fl = fl / correction; + else fl = fl * correction; + + fl = ldexp(fl, expsign ? -oldexp : oldexp); + } + + return sign * fl; +} +#endif diff --git a/lang/cem/libcc/gen/atoi.c b/lang/cem/libcc/gen/atoi.c new file mode 100644 index 00000000..8692465e --- /dev/null +++ b/lang/cem/libcc/gen/atoi.c @@ -0,0 +1,20 @@ +atoi(s) +register char *s; +{ + register int total = 0; + register unsigned digit; + int minus = 0; + + while (*s == ' ' || *s == '\t') + s++; + if (*s == '+') s++; + else if (*s == '-') { + s++; + minus = 1; + } + while ((digit = *s++ - '0') < 10) { + total *= 10; + total += digit; + } + return(minus ? -total : total); +} diff --git a/lang/cem/libcc/gen/atol.c b/lang/cem/libcc/gen/atol.c new file mode 100644 index 00000000..ef64b61d --- /dev/null +++ b/lang/cem/libcc/gen/atol.c @@ -0,0 +1,19 @@ +long atol(s) +register char *s; +{ + register long total = 0; + register unsigned digit; + int minus = 0; + + while (*s == ' ' || *s == '\t') s++; + if (*s == '+') s++; + else if (*s == '-') { + s++; + minus = 1; + } + while ((digit = *s++ - '0') < 10) { + total *= 10; + total += digit; + } + return(minus ? -total : total); +} diff --git a/lang/cem/libcc/gen/bcmp.c b/lang/cem/libcc/gen/bcmp.c new file mode 100644 index 00000000..cf8c0cbe --- /dev/null +++ b/lang/cem/libcc/gen/bcmp.c @@ -0,0 +1,12 @@ +int +bcmp(b1, b2, n) + register char *b1, *b2; + register int n; +{ + register int i; + + while (n--) { + if (i = *b2++ - *b1++) return i; + } + return 0; +} diff --git a/lang/cem/libcc/gen/bcopy.c b/lang/cem/libcc/gen/bcopy.c new file mode 100644 index 00000000..96b64d69 --- /dev/null +++ b/lang/cem/libcc/gen/bcopy.c @@ -0,0 +1,12 @@ +bcopy(old, new, n) +register char *old, *new; +register int n; +{ +/* Copy a block of data. */ + + if (old <= new && old + (n-1) >= new) { + old += n; new += n; + while (n-- > 0) *--new = *--old; + } + else while (n-- > 0) *new++ = *old++; +} diff --git a/lang/cem/libcc/gen/bfill.c b/lang/cem/libcc/gen/bfill.c new file mode 100644 index 00000000..9a261720 --- /dev/null +++ b/lang/cem/libcc/gen/bfill.c @@ -0,0 +1,8 @@ +bfill(dst, len, fill) + register char *dst; + register int len; + register int fill; +{ + while (--len >= 0) + *dst++ = fill; +} diff --git a/lang/cem/libcc/gen/bmove.c b/lang/cem/libcc/gen/bmove.c new file mode 100644 index 00000000..665bdd56 --- /dev/null +++ b/lang/cem/libcc/gen/bmove.c @@ -0,0 +1,6 @@ +bmove(dst, src, len) + char *dst, *src; + int len; +{ + bcopy(src, dst, len); +} diff --git a/lang/cem/libcc/gen/bzero.c b/lang/cem/libcc/gen/bzero.c new file mode 100644 index 00000000..d4337a04 --- /dev/null +++ b/lang/cem/libcc/gen/bzero.c @@ -0,0 +1,5 @@ +bzero(b, l) + register char *b; +{ + while (l-- > 0) *b++ = 0; +} diff --git a/lang/cem/libcc/gen/calloc.c b/lang/cem/libcc/gen/calloc.c new file mode 100644 index 00000000..24830086 --- /dev/null +++ b/lang/cem/libcc/gen/calloc.c @@ -0,0 +1,16 @@ +#define ALIGN(sz) (((sz) + (sizeof(long) - 1) / sizeof(long)) * sizeof(long)) +char * +calloc(nelem, elsize) + unsigned int nelem, elsize; +{ + register char *p; + register long *q; + unsigned int size = ALIGN(nelem * elsize); + extern char *malloc(); + + p = malloc(size); + if (p == 0) return 0; + q = (long *) (p + size); + while ((char *) q > p) *--q = 0; + return p; +} diff --git a/lang/cem/libcc/gen/closedir.c b/lang/cem/libcc/gen/closedir.c new file mode 100644 index 00000000..0fc2f75a --- /dev/null +++ b/lang/cem/libcc/gen/closedir.c @@ -0,0 +1,14 @@ +#include +#include + +/* + * close a directory. + */ +closedir(dirp) +register DIR *dirp; +{ + close(dirp->dd_fd); + dirp->dd_fd = -1; + dirp->dd_loc = 0; + free(dirp); +} diff --git a/lang/cem/libcc/gen/crypt.c b/lang/cem/libcc/gen/crypt.c new file mode 100644 index 00000000..b9b09f03 --- /dev/null +++ b/lang/cem/libcc/gen/crypt.c @@ -0,0 +1,294 @@ +/* From Andy Tanenbaum's book "Computer Networks", + rewritten in C +*/ + +struct block { + unsigned char b_data[64]; +}; + +struct ordering { + unsigned char o_data[64]; +}; + +static struct block key; + +static struct ordering InitialTr = { + 58,50,42,34,26,18,10, 2,60,52,44,36,28,20,12, 4, + 62,54,46,38,30,22,14, 6,64,56,48,40,32,24,16, 8, + 57,49,41,33,25,17, 9, 1,59,51,43,35,27,19,11, 3, + 61,53,45,37,29,21,13, 5,63,55,47,39,31,23,15, 7, +}; + +static struct ordering FinalTr = { + 40, 8,48,16,56,24,64,32,39, 7,47,15,55,23,63,31, + 38, 6,46,14,54,22,62,30,37, 5,45,13,53,21,61,29, + 36, 4,44,12,52,20,60,28,35, 3,43,11,51,19,59,27, + 34, 2,42,10,50,18,58,26,33, 1,41, 9,49,17,57,25, +}; + +static struct ordering swap = { + 33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48, + 49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64, + 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16, + 17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32, +}; + +static struct ordering KeyTr1 = { + 57,49,41,33,25,17, 9, 1,58,50,42,34,26,18, + 10, 2,59,51,43,35,27,19,11, 3,60,52,44,36, + 63,55,47,39,31,23,15, 7,62,54,46,38,30,22, + 14, 6,61,53,45,37,29,21,13, 5,28,20,12, 4, +}; + +static struct ordering KeyTr2 = { + 14,17,11,24, 1, 5, 3,28,15, 6,21,10, + 23,19,12, 4,26, 8,16, 7,27,20,13, 2, + 41,52,31,37,47,55,30,40,51,45,33,48, + 44,49,39,56,34,53,46,42,50,36,29,32, +}; + +static struct ordering etr = { + 32, 1, 2, 3, 4, 5, 4, 5, 6, 7, 8, 9, + 8, 9,10,11,12,13,12,13,14,15,16,17, + 16,17,18,19,20,21,20,21,22,23,24,25, + 24,25,26,27,28,29,28,29,30,31,32, 1, +}; + +static struct ordering ptr = { + 16, 7,20,21,29,12,28,17, 1,15,23,26, 5,18,31,10, + 2, 8,24,14,32,27, 3, 9,19,13,30, 6,22,11, 4,25, +}; + +static unsigned char s_boxes[8][64] = { +{ 14, 4,13, 1, 2,15,11, 8, 3,10, 6,12, 5, 9, 0, 7, + 0,15, 7, 4,14, 2,13, 1,10, 6,12,11, 9, 5, 3, 8, + 4, 1,14, 8,13, 6, 2,11,15,12, 9, 7, 3,10, 5, 0, + 15,12, 8, 2, 4, 9, 1, 7, 5,11, 3,14,10, 0, 6,13, +}, + +{ 15, 1, 8,14, 6,11, 3, 4, 9, 7, 2,13,12, 0, 5,10, + 3,13, 4, 7,15, 2, 8,14,12, 0, 1,10, 6, 9,11, 5, + 0,14, 7,11,10, 4,13, 1, 5, 8,12, 6, 9, 3, 2,15, + 13, 8,10, 1, 3,15, 4, 2,11, 6, 7,12, 0, 5,14, 9, +}, + +{ 10, 0, 9,14, 6, 3,15, 5, 1,13,12, 7,11, 4, 2, 8, + 13, 7, 0, 9, 3, 4, 6,10, 2, 8, 5,14,12,11,15, 1, + 13, 6, 4, 9, 8,15, 3, 0,11, 1, 2,12, 5,10,14, 7, + 1,10,13, 0, 6, 9, 8, 7, 4,15,14, 3,11, 5, 2,12, +}, + +{ 7,13,14, 3, 0, 6, 9,10, 1, 2, 8, 5,11,12, 4,15, + 13, 8,11, 5, 6,15, 0, 3, 4, 7, 2,12, 1,10,14, 9, + 10, 6, 9, 0,12,11, 7,13,15, 1, 3,14, 5, 2, 8, 4, + 3,15, 0, 6,10, 1,13, 8, 9, 4, 5,11,12, 7, 2,14, +}, + +{ 2,12, 4, 1, 7,10,11, 6, 8, 5, 3,15,13, 0,14, 9, + 14,11, 2,12, 4, 7,13, 1, 5, 0,15,10, 3, 9, 8, 6, + 4, 2, 1,11,10,13, 7, 8,15, 9,12, 5, 6, 3, 0,14, + 11, 8,12, 7, 1,14, 2,13, 6,15, 0, 9,10, 4, 5, 3, +}, + +{ 12, 1,10,15, 9, 2, 6, 8, 0,13, 3, 4,14, 7, 5,11, + 10,15, 4, 2, 7,12, 9, 5, 6, 1,13,14, 0,11, 3, 8, + 9,14,15, 5, 2, 8,12, 3, 7, 0, 4,10, 1,13,11, 6, + 4, 3, 2,12, 9, 5,15,10,11,14, 1, 7, 6, 0, 8,13, +}, + +{ 4,11, 2,14,15, 0, 8,13, 3,12, 9, 7, 5,10, 6, 1, + 13, 0,11, 7, 4, 9, 1,10,14, 3, 5,12, 2,15, 8, 6, + 1, 4,11,13,12, 3, 7,14,10,15, 6, 8, 0, 5, 9, 2, + 6,11,13, 8, 1, 4,10, 7, 9, 5, 0,15,14, 2, 3,12, +}, + +{ 13, 2, 8, 4, 6,15,11, 1,10, 9, 3,14, 5, 0,12, 7, + 1,15,13, 8,10, 3, 7, 4,12, 5, 6,11, 0,14, 9, 2, + 7,11, 4, 1, 9,12,14, 2, 0, 6,10,13,15, 3, 5, 8, + 2, 1,14, 7, 4,10, 8,13,15,12, 9, 0, 3, 5, 6,11, +}, +}; + +static int rots[] = { + 1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1, +}; + +static +transpose(data, t, n) + register struct block *data; + register struct ordering *t; + register int n; +{ + struct block x; + + x = *data; + + while (n-- > 0) { + data->b_data[n] = x.b_data[t->o_data[n] - 1]; + } +} + +static +rotate(key) + register struct block *key; +{ + register unsigned char *p = key->b_data; + register unsigned char *ep = &(key->b_data[55]); + int data0 = key->b_data[0], data28 = key->b_data[28]; + + while (p++ < ep) *(p-1) = *p; + key->b_data[27] = data0; + key->b_data[55] = data28; +} + +static struct ordering *EP = &etr; + +static +f(i, key, a, x) + struct block *key, *a; + register struct block *x; +{ + struct block e, ikey, y; + int k; + register unsigned char *p, *q, *r; + + e = *a; + transpose(&e, EP, 48); + for (k = rots[i]; k; k--) rotate(key); + ikey = *key; + transpose(&ikey, &KeyTr2, 48); + p = &(y.b_data[48]); + q = &(e.b_data[48]); + r = &(ikey.b_data[48]); + while (p > y.b_data) { + *--p = *--q ^ *--r; + } + q = x->b_data; + for (k = 0; k < 8; k++) { + register int xb, r; + + r = *p++ << 5; + r += *p++ << 3; + r += *p++ << 2; + r += *p++ << 1; + r += *p++; + r += *p++ << 4; + + xb = s_boxes[k][r]; + + *q++ = (xb >> 3) & 1; + *q++ = (xb>>2) & 1; + *q++ = (xb>>1) & 1; + *q++ = (xb & 1); + } + transpose(x, &ptr, 32); +} + +setkey(k) + register char *k; +{ + + key = *((struct block *) k); + transpose(&key, &KeyTr1, 56); +} + +encrypt(blck, edflag) + char *blck; +{ + register struct block *p = (struct block *) blck; + register int i; + + transpose(p, &InitialTr, 64); + for (i = 15; i>= 0; i--) { + int j = edflag ? i : 15 - i; + register int k; + struct block b, x; + + b = *p; + for (k = 31; k >= 0; k--) { + p->b_data[k] = b.b_data[k + 32]; + } + f(j, &key, p, &x); + for (k = 31; k >= 0; k--) { + p->b_data[k+32] = b.b_data[k] ^ x.b_data[k]; + } + } + transpose(p, &swap, 64); + transpose(p, &FinalTr, 64); +} + +char * +crypt(pw,salt) + register char *pw; + char *salt; +{ + /* Unfortunately, I had to look at the sources of V7 crypt. + There was no other way to find out what this routine + actually does. + */ + + char pwb[66]; + static char result[16]; + register char *p = pwb; + struct ordering new_etr; + register int i; + + while (*pw && p < &pwb[64]) { + register int j = 7; + + while (j--) { + *p++ = (*pw >> j) & 01; + } + pw++; + *p++ = 0; + } + while (p < &pwb[64]) *p++ = 0; + + setkey(p = pwb); + + while (p < &pwb[66]) *p++ = 0; + + new_etr = etr; + EP = &new_etr; + for (i = 0; i < 2; i++) { + register char c = *salt++; + register int j; + + result[i] = c; + if ( c > 'Z') c -= 6 + 7 + '.'; /* c was a lower case letter */ + else if ( c > '9') c -= 7 + '.';/* c was upper case letter */ + else c -= '.'; /* c was digit, '.' or '/'. */ + /* now, 0 <= c <= 63 */ + for (j = 0; j < 6; j++) { + if ((c >> j) & 01) { + int t = 6*i + j; + int temp = new_etr.o_data[t]; + new_etr.o_data[t] = new_etr.o_data[t+24]; + new_etr.o_data[t+24] = temp; + } + } + } + + if (result[1] == 0) result[1] = result[0]; + + for (i = 0; i < 25; i++) encrypt(pwb,0); + EP = &etr; + + p = pwb; + pw = result+2; + while (p < &pwb[66]) { + register int c = 0; + register int j = 6; + + while (j--) { + c <<= 1; + c |= *p++; + } + c += '.'; /* becomes >= '.' */ + if (c > '9') c += 7; /* not in [./0-9], becomes upper */ + if (c > 'Z') c += 6; /* not in [A-Z], becomes lower */ + *pw++ = c; + } + *pw = 0; + return result; +} diff --git a/lang/cem/libcc/gen/ctime.c b/lang/cem/libcc/gen/ctime.c new file mode 100644 index 00000000..772e3eb8 --- /dev/null +++ b/lang/cem/libcc/gen/ctime.c @@ -0,0 +1,11 @@ +#include + +extern struct tm *localtime(); +extern char *asctime(); + +char * +ctime(clock) + long *clock; +{ + return asctime(localtime(clock)); +} diff --git a/lang/cem/libcc/gen/ecvt.c b/lang/cem/libcc/gen/ecvt.c new file mode 100644 index 00000000..f3548532 --- /dev/null +++ b/lang/cem/libcc/gen/ecvt.c @@ -0,0 +1,102 @@ +#ifndef NOFLOAT +extern double modf(); +static char *cvt(); +#define NDIGITS 128 + +char * +ecvt(value, ndigit, decpt, sign) + double value; + int ndigit, *decpt, *sign; +{ + return cvt(value, ndigit, decpt, sign, 1); +} + +char * +fcvt(value, ndigit, decpt, sign) + double value; + int ndigit, *decpt, *sign; +{ + return cvt(value, ndigit, decpt, sign, 0); +} + +static char * +cvt(value, ndigit, decpt, sign, ecvtflag) + double value; + int ndigit, *decpt, *sign; +{ + double intpart, fractpart; + static char buf[NDIGITS]; + char buf1[NDIGITS]; + register char *pe = buf1; + register char *pb = buf; + int pointpos = 0; + + + if (ndigit < 0) ndigit = 0; + if (ndigit >= NDIGITS - 1) ndigit = NDIGITS - 2; + + *sign = 0; + if (value < 0) { + *sign = 1; + value = -value; + } + + fractpart = modf(value, &intpart); + if (intpart != 0) { + do { /* get digits of integer part, low order digit + first + */ + value = modf(intpart/10, &intpart); + /* compensate for rounding errors, because + the conversion to "int" truncates + */ + *pe++ = (int)((value+.05) * 10) + '0'; + pointpos++; + } while (intpart != 0); + while (pe > buf1) *pb++ = *--pe; + } + else if (value > 0) { + fractpart = value; + while ((value = value*10) < 1) { + fractpart = value; + pointpos--; + } + } + pe = &buf[ndigit]; + if (! ecvtflag) { + /* for fcvt() we need ndigit digits behind the dot */ + pe += pointpos; + if (pe < buf) { + /* pointpos was too far left of the beginning */ + buf[0] = 0; + *decpt = pointpos; + return buf; + } + if (pe > &buf[NDIGITS]) pe = &buf[NDIGITS]; + } + while (pb <= pe) { + fractpart = modf(fractpart * 10, &value); + *pb++ = (int)value + '0'; + } + pe = pb; + *pb += 5; /* round of at the end */ + while (*pb > '9') { + *pb = '0'; + if (pb > buf) ++*--pb; + else { + *pb = '1'; + pointpos++; + if (! ecvtflag) { + /* maybe add another digit at the end, + because the point was shifted right + */ + if (pe > buf) *pe = '0'; + pe++; + } + } + } + *decpt = pointpos; + *pe = '\0'; + return(buf); +} +#endif diff --git a/lang/cem/libcc/gen/execvp.c b/lang/cem/libcc/gen/execvp.c new file mode 100644 index 00000000..165d3311 --- /dev/null +++ b/lang/cem/libcc/gen/execvp.c @@ -0,0 +1,36 @@ +char *getenv(); +char *index(); + +execlp(name, argv) +char *name, *argv; +{ + return(execvp(name, &argv)); +} + +execvp(name, argv) +char *name, **argv; +{ + char *path = getenv("PATH"); + register char *c = ""; + char progname[1024]; + + if (path == 0) path = ":/bin:/usr/bin"; + if (! index(name, '/')) c = path; + + do { + register char *p = progname; + register char *n = name; + char *c1 = c; + + while (*c && *c != ':') { + *p++ = *c++; + } + if (c != c1) *p++ = '/'; + if (*c) c++; + while (*n) *p++ = *n++; + *p = 0; + + execv(progname, argv); + } while (*c); + return(-1); +} diff --git a/lang/cem/libcc/gen/ffc.c b/lang/cem/libcc/gen/ffc.c new file mode 100644 index 00000000..3ab2a24e --- /dev/null +++ b/lang/cem/libcc/gen/ffc.c @@ -0,0 +1,10 @@ +ffc(i) + register int i; +{ + register int n; + + for (n = 8*sizeof(int); n > 0; n--, i >>= 1) + if (!(i&1)) + return (8*sizeof(int) + 1) - n; + return -1; +} diff --git a/lang/cem/libcc/gen/ffs.c b/lang/cem/libcc/gen/ffs.c new file mode 100644 index 00000000..471fdf00 --- /dev/null +++ b/lang/cem/libcc/gen/ffs.c @@ -0,0 +1,10 @@ +ffs(i) + register int i; +{ + register int n; + + for (n = 8*sizeof(int); n > 0; n--, i >>= 1) + if ((i&1)) + return (8*sizeof(int) + 1) - n; + return -1; +} diff --git a/lang/cem/libcc/gen/frexp.e b/lang/cem/libcc/gen/frexp.e new file mode 100644 index 00000000..a3a9701f --- /dev/null +++ b/lang/cem/libcc/gen/frexp.e @@ -0,0 +1,29 @@ +# +/* + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. + * + * This product is part of the Amsterdam Compiler Kit. + * + * Permission to use, sell, duplicate or disclose this software must be + * obtained in writing. Requests for such permissions may be sent to + * + * Dr. Andrew S. Tanenbaum + * Wiskundig Seminarium + * Vrije Universiteit + * Postbox 7161 + * 1007 MC Amsterdam + * The Netherlands + * + */ + + mes 2,EM_WSIZE,EM_PSIZE + exp $frexp + pro $frexp,0 + lal 0 + loi EM_DSIZE + fef EM_DSIZE + lal EM_DSIZE + loi EM_PSIZE + sti EM_WSIZE + ret EM_DSIZE + end diff --git a/lang/cem/libcc/gen/gcvt.c b/lang/cem/libcc/gen/gcvt.c new file mode 100644 index 00000000..d9b12710 --- /dev/null +++ b/lang/cem/libcc/gen/gcvt.c @@ -0,0 +1,61 @@ +#ifndef NOFLOAT +extern char *ecvt(); + +#define NDIGINEXP 2 + +char * +gcvt(value, ndigit, buf) + double value; + char *buf; + register int ndigit; +{ + int sign, dp; + register char *s1, *s2; + register int i; + + s1 = ecvt(value, ndigit, &dp, &sign); + s2 = buf; + if (sign) *s2++ = '-'; + for (i = ndigit - 1; i > 0 && s1[i] == '0'; i--) ndigit--; + if (dp - ndigit > NDIGINEXP + 2 || dp < -NDIGINEXP - 1) { + /* Use E format, otherwise we need too many '0''s */ + dp--; + *s2++ = *s1++; + *s2++ = '.'; + while (--ndigit > 0) *s2++ = *s1++; + *s2++ = 'e'; + if (dp < 0) { + *s2++ = '-'; + dp = -dp; + } + else *s2++ = '+'; + s2 += NDIGINEXP; + for (i = NDIGINEXP; i > 0; i--) { + *--s2 = dp % 10 + '0'; + dp /= 10; + } + return buf; + } + if (dp <= 0) { + if (*s1 != '0') { + /* otherwise the whole number is 0 */ + *s2++ = '.'; + } + while (dp < 0) { + dp++; + *s2++ = '0'; + } + } + for (i = 1; i <= ndigit; i++) { + *s2++ = *s1++; + if (i == dp) *s2++ = '.'; + } + if (i <= dp) { + while (i++ <= dp) *s2++ = '0'; + *s2++ = '.'; + } + if (s2[-1]=='.') s2--; + *s2 = '\0'; + return buf; +} +#endif diff --git a/lang/cem/libcc/gen/getenv.c b/lang/cem/libcc/gen/getenv.c new file mode 100644 index 00000000..687c102c --- /dev/null +++ b/lang/cem/libcc/gen/getenv.c @@ -0,0 +1,14 @@ +char *getenv(name) +register char *name; +{ + extern char **environ; + register char **v = environ, *p, *q; + + while ((p = *v++) != 0) { + q = name; + while (*q && *q++ == *p++) /* nothing */ ; + if (*q || *p != '=') continue; + return(p); + } + return(0); +} diff --git a/lang/cem/libcc/gen/getlogin.c b/lang/cem/libcc/gen/getlogin.c new file mode 100644 index 00000000..5f3f5fb2 --- /dev/null +++ b/lang/cem/libcc/gen/getlogin.c @@ -0,0 +1,26 @@ +#define UTMPFILE "/etc/utmp" + +/* some systems require inclusion of sys/types.h before utmp.h */ +#include +#include + +char * +getlogin() +{ + struct utmp ut; + static char name[sizeof(ut.ut_name) + 1]; + int slotno = ttyslot(); + int fd; + register char *p, *q; + + if (! slotno || !(fd = open(UTMPFILE, 0))) return 0; + lseek(fd, (long) slotno * sizeof(ut), 0); + if (read(fd, (char *) &ut, sizeof(ut)) < sizeof(ut)) return 0; + close(fd); + ut.ut_name[sizeof(ut.ut_name)] = ' '; + p = ut.ut_name; + q = name; + while (*p != ' ') *q++ = *p++; + *q = '\0'; + return name; +} diff --git a/lang/cem/libcc/gen/getopt.c b/lang/cem/libcc/gen/getopt.c new file mode 100644 index 00000000..c0c973a0 --- /dev/null +++ b/lang/cem/libcc/gen/getopt.c @@ -0,0 +1,57 @@ +#include +#define ERR(s, c) if(opterr){\ + fputs(argv[0], stderr);\ + fputs(s, stderr);\ + fputc(c, stderr);\ + fputc('\n', stderr);} + +int opterr = 1; +int optind = 1; +int optopt; +char *optarg; +char *index(); + +int +getopt (argc, argv, opts) +char **argv, *opts; +{ + static int sp = 1; + register c; + register char *cp; + + if (sp == 1) + if (optind >= argc || + argv[optind][0] != '-' || argv[optind][1] == '\0') + return EOF; + else if (strcmp(argv[optind], "--") == NULL) { + optind++; + return EOF; + } + optopt = c = argv[optind][sp]; + if (c == ':' || (cp=index(opts, c)) == NULL) { + ERR (": illegal option -- ", c); + if (argv[optind][++sp] == '\0') { + optind++; + sp = 1; + } + return '?'; + } + if (*++cp == ':') { + if (argv[optind][sp+1] != '\0') + optarg = &argv[optind++][sp+1]; + else if (++optind >= argc) { + ERR (": option requires an argument -- ", c); + sp = 1; + return '?'; + } else + optarg = argv[optind++]; + sp = 1; + } else { + if (argv[optind][++sp] == '\0') { + sp = 1; + optind++; + } + optarg = NULL; + } + return c; +} diff --git a/lang/cem/libcc/gen/gmtime.c b/lang/cem/libcc/gen/gmtime.c new file mode 100644 index 00000000..c337e094 --- /dev/null +++ b/lang/cem/libcc/gen/gmtime.c @@ -0,0 +1,39 @@ +#include + +static int monthsize[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + +#define SECS_DAY 24*60L*60L +#define YEARSIZE(year) ((year) % 4 ? 365 : 366) + +struct tm * +gmtime(clock) + long *clock; +{ + unsigned long cl = *clock; + long dayclock, dayno; + struct tm tm_buf; + register struct tm *pbuf = &tm_buf; + register int *months = monthsize; + int year = 1970; + + dayclock = cl % SECS_DAY; + dayno = cl / SECS_DAY; + + pbuf->tm_sec = dayclock % 60; + pbuf->tm_min = (dayclock % 3600) / 60; + pbuf->tm_hour = dayclock / 3600; + pbuf->tm_wday = (dayno + 4) % 7; /* day 0 was a thursday */ + while (dayno >= YEARSIZE(year)) { + dayno -= YEARSIZE(year); + year++; + } + pbuf->tm_year = year; + pbuf->tm_yday = dayno; + pbuf->tm_isdst = 0; + if (YEARSIZE(year) == 366) monthsize[1] = 29; + while (dayno - *months >= 0) dayno -= *months++; + pbuf->tm_mday = dayno + 1; + pbuf->tm_mon = months - monthsize; + monthsize[1] = 28; + return pbuf; +} diff --git a/lang/cem/libcc/gen/index.c b/lang/cem/libcc/gen/index.c new file mode 100644 index 00000000..2ad8b3b0 --- /dev/null +++ b/lang/cem/libcc/gen/index.c @@ -0,0 +1,9 @@ +char *index(s, c) +register char *s, c; +{ + do { + if (*s == c) + return(s); + } while (*s++ != 0); + return(0); +} diff --git a/lang/cem/libcc/gen/isatty.c b/lang/cem/libcc/gen/isatty.c new file mode 100644 index 00000000..5152801a --- /dev/null +++ b/lang/cem/libcc/gen/isatty.c @@ -0,0 +1,9 @@ +#include + +isatty(f) +{ + struct sgttyb ttyb; + + if (gtty(f, &ttyb) < 0) return 0; + return 1; +} diff --git a/lang/cem/libcc/gen/l3.c b/lang/cem/libcc/gen/l3.c new file mode 100644 index 00000000..c88d079c --- /dev/null +++ b/lang/cem/libcc/gen/l3.c @@ -0,0 +1,24 @@ +ltol3(cp, lp, n) +register char *cp; +register long *lp; +register int n; +{ + while (n-- > 0) { + *cp++ = (*lp >> 16); + *cp++ = (*lp > 8); + *cp++ = *lp; + } +} + +l3tol(lp, cp, n) +register long *lp; +char *cp; +register int n; +{ + unsigned char *a = (unsigned char *) cp; + + while (n-- > 0) { + *lp++ = ((long)(*a)<<16) + ((long)(*(a+1)) << 8) + *(a+2); + a += 3; + } +} diff --git a/lang/cem/libcc/gen/ldexp.c b/lang/cem/libcc/gen/ldexp.c new file mode 100644 index 00000000..08f580e9 --- /dev/null +++ b/lang/cem/libcc/gen/ldexp.c @@ -0,0 +1,34 @@ +#ifndef NOFLOAT +extern double frexp(); + +double +ldexp(fl,exp) + double fl; + int exp; +{ + int sign = 1; + int currexp; + + if (fl<0) { + fl = -fl; + sign = -1; + } + fl = frexp(fl,&currexp); + exp += currexp; + if (exp > 0) { + while (exp>30) { + fl *= (double) (1L << 30); + exp -= 30; + } + fl *= (double) (1L << exp); + } + else { + while (exp<-30) { + fl /= (double) (1L << 30); + exp += 30; + } + fl /= (double) (1L << -exp); + } + return sign * fl; +} +#endif diff --git a/lang/cem/libcc/gen/localtime.c b/lang/cem/libcc/gen/localtime.c new file mode 100644 index 00000000..8f469d83 --- /dev/null +++ b/lang/cem/libcc/gen/localtime.c @@ -0,0 +1,52 @@ +#include + +#define YEARSIZE(year) ((year) % 4 ? 365 : 366) +#define FIRSTSUNDAY(t) (((t)->tm_yday - (t)->tm_wday + 420) % 7) +#define SUNDAY(day, t) ((day) < 58 ? \ + ((day) < FIRSTSUNDAY(t) ? FIRSTSUNDAY(t) : +static int +last_sunday(d, t) + register int d; + register struct tm *t; +{ + int first = FIRSTSUNDAY(t); + + if (d >= 58 && YEARSIZE(t->tm_year)) d++; + if (d < first) return first; + return d - (d - first) % 7; +} + +struct tm * +localtime(clock) + long *clock; +{ + register struct tm *gmt; + long cl; + int begindst, enddst; + extern int daylight; + extern long timezone; + + tzset(); + cl = *clock - timezone; + gmt = gmtime(&cl); + if (daylight) { + /* daylight saving time. + Unfortunately, rules differ for different countries. + Implemented here are heuristics that got it right + in Holland, over the last couple of years. + Of course, there is no algorithm. It is all + politics ... + */ + begindst = last_sunday(89, gmt); /* last Sun before Apr */ + enddst = last_sunday(272, gmt); /* last Sun in Sep */ + if ((gmt->tm_yday>begindst || + (gmt->tm_yday==begindst && gmt->tm_hour>=2)) && + (gmt->tm_ydaytm_yday==enddst && gmt->tm_hour<3))) { + cl += 1*60*60; + gmt = gmtime(&cl); + gmt->tm_isdst++; + } + } + return gmt; +} diff --git a/lang/cem/libcc/gen/malloc.c b/lang/cem/libcc/gen/malloc.c new file mode 100644 index 00000000..aa23cd63 --- /dev/null +++ b/lang/cem/libcc/gen/malloc.c @@ -0,0 +1,99 @@ + +#define CLICK_SIZE 16 +#if EM_WSIZE == EM_PSIZE +typedef unsigned int vir_bytes; +#else +typedef long vir_bytes; +#endif +extern bcopy(); + +#define ALIGN(x, a) (((x) + (a - 1)) & ~(a - 1)) +#define BUSY 1 +#define NEXT(p) (* (char **) (p)) + +#ifdef pdp11 +#define BUGFIX 64 +#else +#define BUGFIX 0 +#endif + +extern char *sbrk(); +static char *bottom, *top; + +static grow(len) +unsigned len; +{ + register char *p; + + p = (char *) ALIGN((vir_bytes) top + sizeof(char *) + len, CLICK_SIZE) + + BUGFIX + - sizeof(char *); + if (p < top || brk(p - BUGFIX) < 0) + return(0); + top = p; + for (p = bottom; NEXT(p) != 0; p = (char *) (* (vir_bytes *) p & ~BUSY)) + ; + NEXT(p) = top; + NEXT(top) = 0; + return(1); +} + +char *malloc(size) +unsigned size; +{ + register char *p, *next, *new; + register unsigned len = ALIGN(size, sizeof(char *)) + sizeof(char *); + + if ((p = bottom) == 0) { + top = bottom = p = sbrk(sizeof(char *)); + NEXT(top) = 0; + } + while ((next = NEXT(p)) != 0) + if ((vir_bytes) next & BUSY) /* already in use */ + p = (char *) ((vir_bytes) next & ~BUSY); + else { + while ((new = NEXT(next)) != 0 && !((vir_bytes) new & BUSY)) + next = new; + if (next - p >= len) { /* fits */ + if ((new = p + len) < next) /* too big */ + NEXT(new) = next; + NEXT(p) = (char *) ((vir_bytes) new | BUSY); + return(p + sizeof(char *)); + } + p = next; + } + return grow(len) ? malloc(size) : 0; +} + +char *realloc(old, size) +char *old; +unsigned size; +{ + register char *p = old - sizeof(char *), *next, *new; + register unsigned len = ALIGN(size, sizeof(char *)) + sizeof(char *), n; + + next = (char *) (* (vir_bytes *) p & ~BUSY); + n = next - old; /* old size */ + while ((new = NEXT(next)) != 0 && !((vir_bytes) new & BUSY)) + next = new; + if (next - p >= len) { /* does it still fit */ + if ((new = p + len) < next) { /* even too big */ + NEXT(new) = next; + NEXT(p) = (char *) ((vir_bytes) new | BUSY); + } + else + NEXT(p) = (char *) ((vir_bytes) next | BUSY); + return(old); + } + if ((new = malloc(size)) == 0) /* it didn't fit */ + return(0); + bcopy(old, new, n); /* n < size */ + * (vir_bytes *) p &= ~BUSY; + return(new); +} + +free(p) +char *p; +{ + * (vir_bytes *) (p - sizeof(char *)) &= ~BUSY; +} diff --git a/lang/cem/libcc/gen/memccpy.c b/lang/cem/libcc/gen/memccpy.c new file mode 100644 index 00000000..608f2117 --- /dev/null +++ b/lang/cem/libcc/gen/memccpy.c @@ -0,0 +1,11 @@ +char * +memccpy(dst, src, c, n) + register char *dst, *src; + register int n; +{ + while (n-- > 0) { + if ((*dst++ = *src++) == c) return (char *) dst; + } + + return 0; +} diff --git a/lang/cem/libcc/gen/memchr.c b/lang/cem/libcc/gen/memchr.c new file mode 100644 index 00000000..4382bff3 --- /dev/null +++ b/lang/cem/libcc/gen/memchr.c @@ -0,0 +1,14 @@ +char * +memchr(s, c, n) +char *s; +register int n; +{ + register unsigned char *s1 = (unsigned char *) s; + + c &= 0377; + while (n-- > 0) { + if (*s1 == c) return (char *) s1; + s1++; + } + return 0; +} diff --git a/lang/cem/libcc/gen/memcmp.c b/lang/cem/libcc/gen/memcmp.c new file mode 100644 index 00000000..430bc37c --- /dev/null +++ b/lang/cem/libcc/gen/memcmp.c @@ -0,0 +1,15 @@ +int +memcmp(s1, s2, n) +register char *s1, *s2; +{ +/* Compare 2 strings. */ + + while (n-- > 0) + if (*s1 != *s2) { + return(*s1 - *s2); + } + s1++; + s2++; + } + return 0; +} diff --git a/lang/cem/libcc/gen/memcpy.c b/lang/cem/libcc/gen/memcpy.c new file mode 100644 index 00000000..f4b3a40f --- /dev/null +++ b/lang/cem/libcc/gen/memcpy.c @@ -0,0 +1,16 @@ +char * +memcpy(s1, s2, n) +register char *s1, *s2; +register int n; +{ +/* Copy a block of data. */ + + char *ret = s1; + + if (s2 <= s1 && s2 + (n-1) >= s1) { + s1 += n; s2 += n; + while (n-- > 0) *--s1 = *--s2; + } + else while (n-- > 0) *s1++ = *s2++; + return ret; +} diff --git a/lang/cem/libcc/gen/memset.c b/lang/cem/libcc/gen/memset.c new file mode 100644 index 00000000..fd9a04fa --- /dev/null +++ b/lang/cem/libcc/gen/memset.c @@ -0,0 +1,12 @@ +char * +memset(s, c, n) + char *s; + register int n; +{ + register char *s1 = s; + + while (n--) { + *s1++ = c; + } + return(s); +} diff --git a/lang/cem/libcc/gen/mktemp.c b/lang/cem/libcc/gen/mktemp.c new file mode 100644 index 00000000..6bc86e19 --- /dev/null +++ b/lang/cem/libcc/gen/mktemp.c @@ -0,0 +1,26 @@ +/* mktemp - make a name for a temporary file */ + +char *mktemp(template) +char *template; +{ + register int pid, k; + register char *p; + + pid = getpid(); /* get process id as semi-unique number */ + p = template; + while (*p) p++; /* find end of string */ + + /* Replace XXXXXX at end of template with pid. */ + while (*--p == 'X') { + *p = '0' + (pid % 10); + pid /= 10; + } + p++; + for (k = 'a'; k <= 'z'; k++) { + *p = k; + if (access(template, 0) < 0) { + return template; + } + } + return("/"); +} diff --git a/lang/cem/libcc/gen/modf.e b/lang/cem/libcc/gen/modf.e new file mode 100644 index 00000000..c10623a7 --- /dev/null +++ b/lang/cem/libcc/gen/modf.e @@ -0,0 +1,33 @@ +# +/* + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. + * + * This product is part of the Amsterdam Compiler Kit. + * + * Permission to use, sell, duplicate or disclose this software must be + * obtained in writing. Requests for such permissions may be sent to + * + * Dr. Andrew S. Tanenbaum + * Wiskundig Seminarium + * Vrije Universiteit + * Postbox 7161 + * 1007 MC Amsterdam + * The Netherlands + * + */ + + mes 2,EM_WSIZE,EM_PSIZE + exp $modf + pro $modf,0 + lal 0 + loi EM_DSIZE + loc 1 + loc EM_WSIZE + loc EM_DSIZE + cif + fif EM_DSIZE + lal EM_DSIZE + loi EM_PSIZE + sti EM_DSIZE + ret EM_DSIZE + end diff --git a/lang/cem/libcc/gen/monitor.c b/lang/cem/libcc/gen/monitor.c new file mode 100644 index 00000000..910ba2e3 --- /dev/null +++ b/lang/cem/libcc/gen/monitor.c @@ -0,0 +1,62 @@ +static int bs; +static char *bp; +static char *bufp; +static int sc; +static int bufs; + +monitor(lowpc, highpc, buffer, bufsize, nfunc) + int (*lowpc)(), (*highpc)(); + char *buffer; +{ + long scale; + + if (lowpc == 0) { + int fd; + + profil((char *) 0, 0, 0, 0); + if ((fd = creat("mon.out", 0666)) < 0 || !bp) return; + write(fd, bp, (int) bs); + close(fd); + return; + } + + bs = bufsize << 1; + bp = buffer; + + *(char **) buffer = (char *) lowpc; + buffer += sizeof(char *); + *(char **) buffer = (char *) highpc; + buffer += sizeof(char *); + *(short *) buffer = nfunc; + buffer += 2; + buffer += (sizeof (char *) + sizeof(long)) * nfunc; + bufsize -= ((sizeof (char *) + sizeof(long)) * nfunc + 2 * sizeof(char *) + sizeof(int)) >> 1; + if (bufsize < 0) return; + scale = ((char *) highpc - (char *) lowpc) >> 1; + if (bufsize < scale) + scale = ((long) bufsize << 15) / scale; + else scale = 0x7fff; + bufp = buffer; + sc = scale << 1; + bufs = bufsize << 1; + profil(buffer, bufs, lowpc, sc); +} + +moncontrol(mode) +{ + profil(bs, bufs, *(char **) bufp, !mode ? 0 : sc); +} + +#define NCOUNTS 300 + +monstartup(lowpc, highpc) + int (*lowpc)(), (*highpc)(); +{ + int sz = (((char *) highpc - (char *) lowpc + 7) & ~7) << 1; + char *s, *sbrk(); + + sz += NCOUNTS * (sizeof(long) + sizeof(char *)) + 2 * sizeof(char *) + sizeof(int); + s = sbrk(sz); + if ((int) s == -1) return; + monitor(lowpc, highpc, s, sz >> 1, NCOUNTS); +} diff --git a/lang/cem/libcc/gen/opendir.c b/lang/cem/libcc/gen/opendir.c new file mode 100644 index 00000000..35e5185b --- /dev/null +++ b/lang/cem/libcc/gen/opendir.c @@ -0,0 +1,27 @@ +#include +#include +#include + +/* + * open a directory. + */ +DIR *opendir(name) +char *name; +{ + register DIR *dirp; + register int fd; + struct stat stbuf; + extern char *malloc(); + + if ((fd = open(name, 0)) == -1) + return NULL; + fstat(fd, &stbuf); + if (((stbuf.st_mode & S_IFDIR) == 0) || + ((dirp = (DIR *)malloc(sizeof (DIR))) == NULL)) { + close (fd); + return NULL; + } + dirp->dd_fd = fd; + dirp->dd_loc = 0; + return dirp; +} diff --git a/lang/cem/libcc/gen/perror.c b/lang/cem/libcc/gen/perror.c new file mode 100644 index 00000000..5dbd9de7 --- /dev/null +++ b/lang/cem/libcc/gen/perror.c @@ -0,0 +1,57 @@ +/* perror(s) print the current error message. */ + +extern int errno; +char *sys_errlist[] = { + "Error 0", + "Not owner", + "No such file or directory", + "No such process", + "Interrupted system call", + "I/O error", + "No such device or address", + "Arg list too long", + "Exec format error", + "Bad file number", + "No children", + "No more processes", + "Not enough core", + "Permission denied", + "Bad address", + "Block device required", + "Mount device busy", + "File exists", + "Cross-device link", + "No such device", + "Not a directory", + "Is a directory", + "Invalid argument", + "File table overflow", + "Too many open files", + "Not a typewriter", + "Text file busy", + "File too large", + "No space left on device", + "Illegal seek", + "Read-only file system", + "Too many links", + "Broken pipe", + "Math argument", + "Result too large" +}; + +int sys_nerr = sizeof(sys_errlist) / sizeof(sys_errlist[0]); + +perror(s) + char *s; +{ + char *c; + if (errno < 0 || errno >= sizeof(sys_errlist) / sizeof(char *)) { + c = "unknown error"; + } else { + c = sys_errlist[errno]; + } + write(2, s, strlen(s)); + write(2, ": ", 2); + write(2, c, strlen(c)); + write(2, "\n", 1); +} diff --git a/lang/cem/libcc/gen/procentry.c b/lang/cem/libcc/gen/procentry.c new file mode 100644 index 00000000..43ebe987 --- /dev/null +++ b/lang/cem/libcc/gen/procentry.c @@ -0,0 +1,42 @@ +/* + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. + * + * This product is part of the Amsterdam Compiler Kit. + * + * Permission to use, sell, duplicate or disclose this software must be + * obtained in writing. Requests for such permissions may be sent to + * + * Dr. Andrew S. Tanenbaum + * Wiskundig Seminarium + * Vrije Universiteit + * Postbox 7161 + * 1007 MC Amsterdam + * The Netherlands + * + */ + +/* Author: E.G. Keizer */ + +static int level = 0 ; +static wrs() ; +procentry(name) char *name ; { + register int count ; + + count=level++ ; + while ( count-- ) { + wrs(" ") ; + } + wrs("Entering ");wrs(name);wrs("\n") ; +} +procexit(name) char *name ; { + register int count ; + + count= --level ; + while ( count-- ) { + wrs(" ") ; + } + wrs("Leaving ");wrs(name);wrs("\n") ; +} +static wrs(s) register char *s ; { + write(2,s,strlen(s)) ; +} diff --git a/lang/cem/libcc/gen/qsort.c b/lang/cem/libcc/gen/qsort.c new file mode 100644 index 00000000..37721dfc --- /dev/null +++ b/lang/cem/libcc/gen/qsort.c @@ -0,0 +1,133 @@ +static qsort1(); +static int (*qcompar)(); +static qexchange(); +static q3exchange(); + +qsort(base, nel, width, compar) + char *base; + int (*compar)(); +{ + qcompar = compar; + qsort1(base, base + (nel - 1) * width, width); +} + +static +qsort1(a1, a2, width) + char *a1, *a2; + register int width; +{ + register char *left, *right; + register char *lefteq, *righteq; + int cmp; + + for (;;) { + if (a2 <= a1) return; + left = a1; + right = a2; + lefteq = righteq = a1 + width * (((a2-a1)+width)/(2*width)); + /* + Pick an element in the middle of the array. + We will collect the equals around it. + "lefteq" and "righteq" indicate the left and right + bounds of the equals respectively. + Smaller elements end up left of it, larger elements end + up right of it. + */ +again: + while (left < lefteq && (cmp = (*qcompar)(left, lefteq)) <= 0) { + if (cmp < 0) { + /* leave it where it is */ + left += width; + } + else { + /* equal, so exchange with the element to + the left of the "equal"-interval. + */ + lefteq -= width; + qexchange(left, lefteq, width); + } + } + while (right > righteq) { + if ((cmp = (*qcompar)(right, righteq)) < 0) { + /* smaller, should go to left part + */ + if (left < lefteq) { + /* yes, we had a larger one at the + left, so we can just exchange + */ + qexchange(left, right, width); + left += width; + right -= width; + goto again; + } + /* no more room at the left part, so we + move the "equal-interval" one place to the + right, and the smaller element to the + left of it. + This is best expressed as a three-way + exchange. + */ + righteq += width; + q3exchange(left, righteq, right, width); + lefteq += width; + left = lefteq; + } + else if (cmp == 0) { + /* equal, so exchange with the element to + the right of the "equal-interval" + */ + righteq += width; + qexchange(right, righteq, width); + } + else /* just leave it */ right -= width; + } + if (left < lefteq) { + /* larger element to the left, but no more room, + so move the "equal-interval" one place to the + left, and the larger element to the right + of it. + */ + lefteq -= width; + q3exchange(right, lefteq, left, width); + righteq -= width; + right = righteq; + goto again; + } + /* now sort the "smaller" part */ + qsort1(a1, lefteq - width, width); + /* and now the larger, saving a subroutine call + because of the for(;;) + */ + a1 = righteq + width; + } + /*NOTREACHED*/ +} + +static +qexchange(p, q, n) + register char *p, *q; + register int n; +{ + register int c; + + while (n-- > 0) { + c = *p; + *p++ = *q; + *q++ = c; + } +} + +static +q3exchange(p, q, r, n) + register char *p, *q, *r; + register int n; +{ + register int c; + + while (n-- > 0) { + c = *p; + *p++ = *r; + *r++ = *q; + *q++ = c; + } +} diff --git a/lang/cem/libcc/gen/rand.c b/lang/cem/libcc/gen/rand.c new file mode 100644 index 00000000..4ff9f975 --- /dev/null +++ b/lang/cem/libcc/gen/rand.c @@ -0,0 +1,13 @@ +static long seed = 1L; + +int rand() +{ + seed = (1103515245L * seed + 12345) & 0x7FFFFFFF; + return((int) ((seed >> 8) & 077777)); +} + +srand(n) + unsigned n; +{ + seed = n; +} diff --git a/lang/cem/libcc/gen/readdir.c b/lang/cem/libcc/gen/readdir.c new file mode 100644 index 00000000..6679dd5b --- /dev/null +++ b/lang/cem/libcc/gen/readdir.c @@ -0,0 +1,64 @@ +#include +#include + +#ifndef BSD4_2 +/* + * read an old stlye directory entry and present it as a new one + */ +#define ODIRSIZ 14 + +struct olddirect { + ino_t od_ino; + char od_name[ODIRSIZ]; +}; +#else +#define olddirect direct +#endif + +/* + * get next entry in a directory. + */ +struct direct *readdir(dirp) +register DIR *dirp; +{ + register struct olddirect *dp; + static struct direct dir; + + for (;;) { + if (dirp->dd_loc == 0) { + dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf, + DIRBLKSIZ); + if (dirp->dd_size <= 0) { + dirp->dd_size = 0; + return NULL; + } +#ifdef BSD4_2 + if (! ((struct direct *) dirp->dd_buf)->d_ino) { + dirp->dd_loc += ((struct direct *)dirp->dd_buf)->d_reclen; + } +#endif + } + if (dirp->dd_loc >= dirp->dd_size) { + dirp->dd_loc = 0; + continue; + } + dp = (struct olddirect *) (dirp->dd_buf + dirp->dd_loc); +#ifndef BSD4_2 + dirp->dd_loc += sizeof (struct olddirect); + if (dp->od_ino == 0) + continue; + dir.d_ino = dp->od_ino; + strncpy(dir.d_name, dp->od_name, ODIRSIZ); + dir.d_name[ODIRSIZ] = '\0'; /* insure null termination */ + dir.d_reclen = DIRSIZ(&dir); + dir.d_namlen = strlen(dir.d_name); +#else + dirp->dd_loc += dp->d_reclen; + dir.d_ino = dp->d_ino; + strcpy(dir.d_name, dp->d_name); + dir.d_reclen = dp->d_reclen; + dir.d_namlen = dp->d_namlen; +#endif + return &dir; + } +} diff --git a/lang/cem/libcc/gen/rindex.c b/lang/cem/libcc/gen/rindex.c new file mode 100644 index 00000000..9fe982af --- /dev/null +++ b/lang/cem/libcc/gen/rindex.c @@ -0,0 +1,12 @@ +char *rindex(s, c) +register char *s, c; +{ + register char *result; + + result = 0; + do + if (*s == c) + result = s; + while (*s++ != 0); + return(result); +} diff --git a/lang/cem/libcc/gen/seekdir.c b/lang/cem/libcc/gen/seekdir.c new file mode 100644 index 00000000..ee2e0d2c --- /dev/null +++ b/lang/cem/libcc/gen/seekdir.c @@ -0,0 +1,37 @@ +#include +#include + +/* + * seek to an entry in a directory. + * Only values returned by "telldir" should be passed to seekdir. + */ +seekdir(dirp, loc) +register DIR *dirp; +long loc; +{ + long curloc, base, offset; + extern long telldir(); + extern struct direct *readdir(); + + curloc = telldir(dirp); + if (loc == curloc) + return; + base = loc & ~(DIRBLKSIZ - 1); + offset = loc & (DIRBLKSIZ - 1); + if (dirp->dd_loc != 0 && offset != 0 && + (curloc & ~(DIRBLKSIZ-1)) == base) { + dirp->dd_loc = offset; + return; + } + (void) lseek(dirp->dd_fd, base, 0); + dirp->dd_loc = 0; + dirp->dd_size = 0; + if (offset == 0) + (void) readdir(dirp); + else { + while (dirp->dd_loc < offset) { + if (readdir(dirp) == (struct direct *) 0) + return; + } + } +} diff --git a/lang/cem/libcc/gen/setjmp.e b/lang/cem/libcc/gen/setjmp.e new file mode 100644 index 00000000..2cd1b063 --- /dev/null +++ b/lang/cem/libcc/gen/setjmp.e @@ -0,0 +1,147 @@ +# + mes 2,EM_WSIZE,EM_PSIZE + + exp $setjmp + pro $setjmp,2*EM_WSIZE + +; setjmp saves the StackPointer and the LocalBase, and the chunk of +; memory between the StackPointer and the ArgumentBase, + its size in a +; buffer, pointed to by the parameter. +; longjump can then restore this buffer and return. +; Notice that this does not work on EM implementations in which every +; procedure frame has a different fragment in memory, because in this case +; the ArgumentBase will point into the fragment of the caller. +; What really is needed is a way to find out the size of the return +; status block. +; On EM-implementations in which the stack grows upwards it is untested, +; as there are no such implementations available now. +; This implementation of setjmp/longjmp +; depends on the assumption that the routine calling +; setjmp does not have register variables, and that it saves all registers +; that are available for variables. + + loc 0 + stl -2*EM_WSIZE + lor 1 ; load StackPointer + lal 0 + loi EM_PSIZE + sti EM_PSIZE ; save it + lxl 0 ; load LocalBase + lal 0 + loi EM_PSIZE + adp EM_PSIZE + sti EM_PSIZE ; save it + lxa 0 ; load ArgumentBase + lal 0 + loi EM_PSIZE + loi EM_PSIZE ; load saved StackPointer + sbs EM_WSIZE ; gives size of block that is to be saved, or negative size + dup EM_WSIZE + zgt *5 + ngi EM_WSIZE + loc 1 + stl -2*EM_WSIZE; one if the stack grows upwards +5 + stl -EM_WSIZE ; save size of block in local + lol -EM_WSIZE + lal 0 + loi EM_PSIZE + adp 2*EM_PSIZE + sti EM_WSIZE ; and also in the buffer + lal 0 + loi EM_PSIZE + loi EM_PSIZE ; load saved StackPointer + lol -2*EM_WSIZE; positive if the stack grows upwards + zle *6 + asp EM_PSIZE + lxa 0 + adp EM_WSIZE ; in this case the source address = ArgumentBase+EM_WSIZE +6 + lal 0 + loi EM_PSIZE + adp 2*EM_PSIZE+EM_WSIZE + ; destination address + lol -EM_WSIZE ; count + bls EM_WSIZE ; block copy + loc 0 + ret EM_WSIZE + end 2*EM_WSIZE + + exp $longjmp + pro $longjmp,2*EM_WSIZE + +; first, find out wether the stack grows upwards + loc 0 + stl -2*EM_WSIZE + lxa 0 + lxl 0 + cmp + zge *7 + loc 1 + stl -2*EM_WSIZE; this local contains 1 if it does, otherwise it contains 0 +7 +; then, adjust StackPointer until it is below the saved StackPointer (or +; above if it grows upwards) +; then push parameters +; then copy the saved block in its proper place +; notice that the parameters can not be used anymore now +; then restore the LocalBase and the Stackpointer and return. +1 + loc 0 +2 + lor 1 + lal 0 + loi EM_PSIZE + loi EM_PSIZE ; saved StackPointer + cmp ; compare with current one + lol -2*EM_WSIZE + zle *8 + zlt *1 + bra *10 +8 + zgt *1 +10 + lal 0 + loi EM_PSIZE + loi EM_PSIZE ; push saved StackPointer + lol EM_PSIZE ; push value to be returned by longjmp + lal 0 + loi EM_PSIZE + adp EM_PSIZE + loi EM_PSIZE ; push saved LocalBase + lal 0 + loi EM_PSIZE + adp 2*EM_PSIZE+EM_WSIZE + ; source address + lal 0 + loi EM_PSIZE + loi EM_PSIZE ; saved stackpointer + lol -2*EM_WSIZE + zle *9 ; if not positive, this is the destination address, + ; otherwise subtract the size of the saved area and add EM_WSIZE + adp EM_WSIZE + lal 0 + loi EM_PSIZE + adp 2*EM_PSIZE + loi EM_WSIZE + ngi EM_WSIZE + ads EM_WSIZE +9 ; destination address + lal 0 + loi EM_PSIZE + adp 2*EM_PSIZE + loi EM_WSIZE ; size + bls EM_WSIZE ; now we have a frame exactly as it was in setjmp, + ; and exactly at the same place + str 0 ; restore LocalBase + stl -EM_WSIZE ; saves the return value + str 1 ; restores the StackPointer + lol -EM_WSIZE + dup EM_WSIZE + zne *3 + ; of course, longjmp may not return 0! + asp EM_WSIZE + loc 1 +3 + ret EM_WSIZE + end 2*EM_WSIZE diff --git a/lang/cem/libcc/gen/sleep.c b/lang/cem/libcc/gen/sleep.c new file mode 100644 index 00000000..02ee2b46 --- /dev/null +++ b/lang/cem/libcc/gen/sleep.c @@ -0,0 +1,38 @@ +#include +#include + +static jmp_buf setjmpbuf; + +static +alfun(){ + longjmp(setjmpbuf, 1); +} /* used with sleep() below */ + +sleep(n) + int n; +{ +/* sleep(n) pauses for 'n' seconds by scheduling an alarm interrupt. */ + unsigned oldalarm; + int (*oldsig)(); + + if (n <= 0) return; + if (setjmp(setjmpbuf)) { + signal(SIGALRM, oldsig); + alarm(oldalarm); + return; + } + oldalarm = alarm(5000); /* Who cares how long, as long as it is long + enough + */ + if (oldalarm > n) oldalarm -= n; + else { + n = oldalarm; + oldalarm = 1; + } + oldsig = signal(SIGALRM, alfun); + alarm(n); + for (;;) { + /* allow for other handlers ... */ + pause(); + } +} diff --git a/lang/cem/libcc/gen/stb.c b/lang/cem/libcc/gen/stb.c new file mode 100644 index 00000000..23ba9d94 --- /dev/null +++ b/lang/cem/libcc/gen/stb.c @@ -0,0 +1,11 @@ +/* $Header$ */ +/* library routine for copying structs */ + +__stb(n, f, t) + register char *f, *t; register n; +{ + if (n > 0) + do + *t++ = *f++; + while (--n); +} diff --git a/lang/cem/libcc/gen/strcat.c b/lang/cem/libcc/gen/strcat.c new file mode 100644 index 00000000..eedce108 --- /dev/null +++ b/lang/cem/libcc/gen/strcat.c @@ -0,0 +1,14 @@ +char *strcat(s1, s2) +register char *s1, *s2; +{ + /* Append s2 to the end of s1. */ + + char *original = s1; + + /* Find the end of s1. */ + while (*s1 != 0) s1++; + + /* Now copy s2 to the end of s1. */ + while (*s1++ = *s2++) /* nothing */ ; + return(original); +} diff --git a/lang/cem/libcc/gen/strchr.c b/lang/cem/libcc/gen/strchr.c new file mode 100644 index 00000000..9c432e52 --- /dev/null +++ b/lang/cem/libcc/gen/strchr.c @@ -0,0 +1,9 @@ +char *strchr(s, c) +register char *s, c; +{ + do { + if (*s == c) + return(s); + } while (*s++ != 0); + return(0); +} diff --git a/lang/cem/libcc/gen/strcmp.c b/lang/cem/libcc/gen/strcmp.c new file mode 100644 index 00000000..fc24df40 --- /dev/null +++ b/lang/cem/libcc/gen/strcmp.c @@ -0,0 +1,15 @@ +int strcmp(s1, s2) +register char *s1, *s2; +{ +/* Compare 2 strings. */ + + for(;;) { + if (*s1 != *s2) { + if (!*s1) return -1; + if (!*s2) return 1; + return(*s1 - *s2); + } + if (*s1++ == 0) return(0); + s2++; + } +} diff --git a/lang/cem/libcc/gen/strcpy.c b/lang/cem/libcc/gen/strcpy.c new file mode 100644 index 00000000..ba8b7d9b --- /dev/null +++ b/lang/cem/libcc/gen/strcpy.c @@ -0,0 +1,9 @@ +char *strcpy(s1, s2) +register char *s1, *s2; +{ +/* Copy s2 to s1. */ + char *original = s1; + + while (*s1++ = *s2++) /* nothing */; + return(original); +} diff --git a/lang/cem/libcc/gen/strcspn.c b/lang/cem/libcc/gen/strcspn.c new file mode 100644 index 00000000..63b21353 --- /dev/null +++ b/lang/cem/libcc/gen/strcspn.c @@ -0,0 +1,13 @@ +int +strcspn(string, notin) + char *string; + char *notin; +{ + register char *s1, *s2; + + for (s1 = string; *s1; s1++) { + for(s2 = notin; *s2 != *s1 && *s2; s2++) /* nothing */ ; + if (*s2) break; + } + return s1 - string; +} diff --git a/lang/cem/libcc/gen/strlen.c b/lang/cem/libcc/gen/strlen.c new file mode 100644 index 00000000..b453633f --- /dev/null +++ b/lang/cem/libcc/gen/strlen.c @@ -0,0 +1,10 @@ +int strlen(s) +char *s; +{ +/* Return length of s. */ + + char *original = s; + + while (*s != 0) s++; + return(s - original); +} diff --git a/lang/cem/libcc/gen/strncat.c b/lang/cem/libcc/gen/strncat.c new file mode 100644 index 00000000..38e9c3d6 --- /dev/null +++ b/lang/cem/libcc/gen/strncat.c @@ -0,0 +1,22 @@ +char *strncat(s1, s2, n) +register char *s1, *s2; +int n; +{ +/* Append s2 to the end of s1, but no more than n characters */ + + char *original = s1; + + if (n <= 0) return(s1); + + /* Find the end of s1. */ + while (*s1 != 0) s1++; + + /* Now copy s2 to the end of s1. */ + while (*s1++ = *s2++) { + if (--n == 0) { + *s1 = 0; + break; + } + } + return(original); +} diff --git a/lang/cem/libcc/gen/strncmp.c b/lang/cem/libcc/gen/strncmp.c new file mode 100644 index 00000000..9df8c86f --- /dev/null +++ b/lang/cem/libcc/gen/strncmp.c @@ -0,0 +1,18 @@ +int +strncmp(s1, s2, n) + register char *s1, *s2; + int n; +{ +/* Compare two strings, but at most n characters. */ + + while (n-- > 0) { + if (*s1 != *s2) { + if (!*s1) return -1; + if (!*s2) return 1; + return(*s1 - *s2); + } + if (*s1++ == 0) break; + s2++; + } + return 0; +} diff --git a/lang/cem/libcc/gen/strncpy.c b/lang/cem/libcc/gen/strncpy.c new file mode 100644 index 00000000..59c52bf9 --- /dev/null +++ b/lang/cem/libcc/gen/strncpy.c @@ -0,0 +1,13 @@ +char +*strncpy(s1, s2, n) +register char *s1, *s2; +int n; +{ +/* Copy s2 to s1, but at most n characters. */ + + char *original = s1; + + while (*s2 && n-- > 0) *s1++ = *s2++; + while (n-- > 0) *s1++ = '\0'; + return(original); +} diff --git a/lang/cem/libcc/gen/strpbrk.c b/lang/cem/libcc/gen/strpbrk.c new file mode 100644 index 00000000..1d0d1042 --- /dev/null +++ b/lang/cem/libcc/gen/strpbrk.c @@ -0,0 +1,13 @@ +char * +strpbrk(string, brk) + register char *string, *brk; +{ + register char *s1; + + while (*string) { + for (s1 = brk; *s1 && *s1 != *string; s1++) /* nothing */ ; + if (*s1) return string; + string++; + } + return 0; +} diff --git a/lang/cem/libcc/gen/strrchr.c b/lang/cem/libcc/gen/strrchr.c new file mode 100644 index 00000000..18b80a94 --- /dev/null +++ b/lang/cem/libcc/gen/strrchr.c @@ -0,0 +1,12 @@ +char *strrchr(s, c) +register char *s, c; +{ + register char *result; + + result = 0; + do + if (*s == c) + result = s; + while (*s++ != 0); + return(result); +} diff --git a/lang/cem/libcc/gen/strspn.c b/lang/cem/libcc/gen/strspn.c new file mode 100644 index 00000000..af68acdc --- /dev/null +++ b/lang/cem/libcc/gen/strspn.c @@ -0,0 +1,13 @@ +int +strspn(string, in) + char *string; + char *in; +{ + register char *s1, *s2; + + for (s1 = string; *s1; s1++) { + for (s2 = in; *s2 && *s2 != *s1; s2++) /* nothing */ ; + if (! *s2) break; + } + return s1 - string; +} diff --git a/lang/cem/libcc/gen/strstr.c b/lang/cem/libcc/gen/strstr.c new file mode 100644 index 00000000..49e9e062 --- /dev/null +++ b/lang/cem/libcc/gen/strstr.c @@ -0,0 +1,12 @@ +/* find first occurrence of wanted in s */ +char * +strstr(s, wanted) + register char *s, *wanted; +{ + int len = strlen(wanted); + + while (*s != *wanted || strncmp(s, wanted, len)) { + if (*s++ == '\0') return 0; + } + return s; +} diff --git a/lang/cem/libcc/gen/strtok.c b/lang/cem/libcc/gen/strtok.c new file mode 100644 index 00000000..e8eb65f4 --- /dev/null +++ b/lang/cem/libcc/gen/strtok.c @@ -0,0 +1,25 @@ +extern char *strpbrk(); + +char * +strtok(string, separators) + register char *string; + char *separators; +{ + register char *s1, *s2; + static char *savestring; + + if (!string) string = savestring; + + if (!string) return 0; + + if (*(s1 = string + strspn(string, separators)) == '\0') { + savestring = 0; + return 0; + } + + if (s2 = strpbrk(s1, separators)) { + *s2++ = '\0'; + } + savestring = s2; + return s1; +} diff --git a/lang/cem/libcc/gen/swab.c b/lang/cem/libcc/gen/swab.c new file mode 100644 index 00000000..54455ce2 --- /dev/null +++ b/lang/cem/libcc/gen/swab.c @@ -0,0 +1,10 @@ +swab(from, to, nbytes) + register char *from, *to; +{ + nbytes /= 2; + while (nbytes-- > 0) { + *(to+1) = *from++; + *to = *from++; + to += 2; + } +} diff --git a/lang/cem/libcc/gen/telldir.c b/lang/cem/libcc/gen/telldir.c new file mode 100644 index 00000000..de5118f1 --- /dev/null +++ b/lang/cem/libcc/gen/telldir.c @@ -0,0 +1,13 @@ +#include +#include + +/* + * return a pointer into a directory + */ +long telldir(dirp) +DIR *dirp; +{ + extern long lseek(); + + return (lseek(dirp->dd_fd, 0L, 1) - dirp->dd_size + dirp->dd_loc); +} diff --git a/lang/cem/libcc/gen/ttyname.c b/lang/cem/libcc/gen/ttyname.c new file mode 100644 index 00000000..f23fd81c --- /dev/null +++ b/lang/cem/libcc/gen/ttyname.c @@ -0,0 +1,43 @@ +#include +#include +#include + +#define DEV "/dev/" + +extern char *strcpy(), *strcat(); + +char * +ttyname(filedes) +{ + static char result[MAXNAMLEN + 1 + 5]; + DIR *dirp; + register struct direct *dp; + struct stat fdstat; + ino_t inode; + dev_t device; + char *name; + + if (! isatty(filedes) || + fstat(filedes, &fdstat) < 0 || + (fdstat.st_mode & S_IFMT) != S_IFCHR || + (dirp = opendir(DEV)) == NULL) { + return 0; + } + + inode = fdstat.st_ino; + device = fdstat.st_rdev; + + while ((dp = readdir(dirp)) != NULL) { + if (dp->d_ino != inode) continue; + strcpy(result, DEV); + strcat(result, dp->d_name); + if (stat(result, &fdstat) < 0) continue; + if (fdstat.st_rdev == device && + (fdstat.st_mode & S_IFMT) == S_IFCHR) { + closedir(dirp); + return result; + } + } + closedir(dirp); + return 0; +} diff --git a/lang/cem/libcc/gen/ttyslot.c b/lang/cem/libcc/gen/ttyslot.c new file mode 100644 index 00000000..b91b12e7 --- /dev/null +++ b/lang/cem/libcc/gen/ttyslot.c @@ -0,0 +1,71 @@ +#ifdef USG +/* some systems require inclusion of sys/types.h before utmp.h */ +#include +#include + +/* system V, so no /etc/ttys file. In this case, scan the + /etc/utmp file +*/ +#define FILENAME "/etc/utmp" +#else +#define FILENAME "/etc/ttys" +#endif + +char *ttyname(); +char *rindex(); + +ttyslot() +{ + register char *tp, *p; + int fd; + int retval = 1; +#ifdef USG + struct utmp buf; +#else + char buf[32]; +#endif + + if (! (tp=ttyname(0)) && ! (tp=ttyname(1)) && !(tp=ttyname(2))) + return 0; + if (! (p = rindex(tp, '/'))) + p = tp; + else + p++; + if ((fd = open(FILENAME, 0)) < 0) return 0; +#ifdef USG + while (read(fd, (char *) &buf, sizeof(buf)) == sizeof(buf)) { + if ((buf.ut_type == INIT_PROCESS || + buf.ut_type == LOGIN_PROCESS || + buf.ut_type == USER_PROCESS || + buf.ut_type == DEAD_PROCESS) && + ! strncmp(buf.ut_line, p, sizeof(buf.ut_line))) { + close(fd); + return retval; + } + retval++; + } + close(fd); + return 0; +#else + for (;;) { + tp = buf; + for (;;) { + if (read(fd, tp, 1) != 1) { + close(fd); + return 0; + } + if (*tp == '\n' || tp >= &buf[31]) { + *tp = 0; + tp = buf+2; + break; + } + } + if (! strcmp(p, tp)) { + close(fd); + return retval; + } + retval++; + } + /*NOTREACHED*/ +#endif +} diff --git a/lang/cem/libcc/gen/tzset.c b/lang/cem/libcc/gen/tzset.c new file mode 100644 index 00000000..1f7a83b8 --- /dev/null +++ b/lang/cem/libcc/gen/tzset.c @@ -0,0 +1,56 @@ +#ifdef BSD4_2 +#include +#else +#ifndef USG +#include +#include +#endif +#endif + +long timezone = -1 * 60; +int daylight = 1; +char *tzname[] = {"MET", "MDT",}; + +tzset() +{ +#ifdef BSD4_2 + struct timeval tval; + struct timezone tzon; + + gettimeofday(&tval, &tzon); + timezone = tzon.tz_minuteswest * 60L; + daylight = tzon.tz_dsttime; +#else +#ifndef USG + struct timeb time; + + ftime(&time); + timezone = time.timezone*60L; + daylight = time.dstflag; +#endif +#endif + + { + extern char *getenv(); + register char *p = getenv("TZ"); + + if (p && *p) { + register int n = 0; + int sign = 1; + + strncpy(tzname[0], p, 3); + p += 3; + if (*(p += 3) == '-') { + sign = -1; + p++; + } + + while(*p >= '0' && *p <= '9') + n = 10 * n + (*p++ - '0'); + n *= sign; + timezone = ((long)(n * 60)) * 60; + daylight = (*p != '\0'); + strncpy(tzname[1], p, 3); + } + } +} diff --git a/lang/cem/libcc/stdio/clearerr.c b/lang/cem/libcc/stdio/clearerr.c new file mode 100644 index 00000000..592e61ad --- /dev/null +++ b/lang/cem/libcc/stdio/clearerr.c @@ -0,0 +1,7 @@ +#include + +clearerr(iop) + FILE *iop; +{ + iop->_flags &= ~(IO_ERR|IO_EOF); +} diff --git a/lang/cem/libcc/stdio/data.c b/lang/cem/libcc/stdio/data.c new file mode 100644 index 00000000..680d37fb --- /dev/null +++ b/lang/cem/libcc/stdio/data.c @@ -0,0 +1,23 @@ +#include + +unsigned char __stdin[BUFSIZ]; +unsigned char __stdout[BUFSIZ]; + +struct _io_buf _stdin = { + 0, 0, IO_READMODE , __stdin, __stdin +}; + +struct _io_buf _stdout = { + 1, 0, IO_WRITEMODE, 0, 0 +}; + +struct _io_buf _stderr = { + 2, 0, IO_WRITEMODE + IO_UNBUFF, NULL, NULL +}; + +struct _io_buf *_io_table[_NFILES] = { + &_stdin, + &_stdout, + &_stderr, + 0 +}; diff --git a/lang/cem/libcc/stdio/doprnt.c b/lang/cem/libcc/stdio/doprnt.c new file mode 100644 index 00000000..d44a491f --- /dev/null +++ b/lang/cem/libcc/stdio/doprnt.c @@ -0,0 +1,242 @@ +#include + +#ifndef NOFLOAT +extern char *_pfloat(); +extern char *_pscien(); +#endif + +static int *nextarg ; + +static geta(p,size) int *p; int size; { + /* get 'size' words from arglist */ + + if ( (int *)&p - &size >0 ) { + p += size; + while ( size-- ) { + *--p = *nextarg--; + } + } else { + while ( size-- ) { + *p++ = *nextarg++ ; + } + } +} + +# define wsize(par) ( (sizeof par) / sizeof (int) ) + + +static char *gnum(f,ip) register char *f; int *ip; { + register int i,c; + + if (*f == '*') { + geta(ip,wsize(i)) ; + f++; + } else { + i = 0; + while ((c = *f - '0') >= 0 && c <= 9) { + i = i*10 + c; + f++; + } + *ip = i; + } + return(f); +} + +#define signbit(par) (1L<<(sizeof par*8 -1)) + +static char *i_compute(val,base,s) unsigned val; char *s; { + int c; + + c= val % base ; + val/= base ; + if (val) + s = i_compute(val,base,s); + *s++ = (c>9 ? c-10+'a' : c+'0'); + return(s); +} + +#ifndef NOLONG +static char *l_compute(l1,d,s) long l1; char *s; { + int c; + long l2; + + if ( l1<0 ) { + /* assumption: d is a multiple of 2 */ + c= l1&1 ; + l2= ( (l1>>1) & ~signbit(l1) ); + l1= l2/(d>>1) ; + c += (l2%(d>>1))<<1 ; + } else { + c= l1 % d ; + l1= l1 / d ; + } + if (l1) + s = l_compute(l1,d,s); + *s++ = (c>9 ? c-10+'a' : c+'0'); + return(s); +} +#endif + +_doprnt(fmt,args,stream) + register char *fmt; int *args ; FILE *stream; +{ + register char *s; +#ifndef NOLONG + long l; + int lflag ; +#else +#define lflag 0 +#endif +#ifndef NOFLOAT + double dbl ; +#endif + int inte ; + unsigned int uint ; + register int j ; + int i,c,rjust,width,ndigit,ndfnd,zfill; + char *oldfmt,*s1,buf[40]; + + nextarg = args; + while (c = *fmt++) { + if (c != '%') { +#ifdef CPM + if (c == '\n') putc('\r',stream); +#endif + putc(c,stream); + continue; + } +#ifndef NOLONG + lflag = 0 ; +#endif + j = 10 ; + rjust = 0; + if (*fmt == '-') { + fmt++; + rjust++; + } + zfill = ' '; + if (*fmt == '0') { + fmt++; + zfill = '0'; + } + fmt = gnum(fmt,&width); + ndigit = 0; ndfnd = 0; + if (*fmt == '.') { + fmt++; oldfmt = fmt; + fmt = gnum(fmt,&ndigit); + ndfnd = (fmt != oldfmt); + } + s = s1 = buf; +#ifndef NOLONG + if ( *fmt == 'l' || *fmt == 'L' ) { + fmt++ ; lflag++ ; + } +#endif + switch (c = *fmt++) { + default: +#ifdef CPM + if (c == '\n') putc('r',stream); +#endif + putc(c,stream); + continue; + case 's': + geta(&s1,wsize(s1)) ; + s = s1; + do { + if (*s == 0) + break; + s++; + } while (--ndigit); + break; + case 'b': + j = 2; + case 'u': + getu: + if ( !lflag ) { + geta(&inte,wsize(inte)) ; + goto i_unsignd ; + } +#ifndef NOLONG + case 'U': + getlu: + geta( &l,wsize(l)) ; + goto l_unsignd ; + case 'B': + j = 2 ; + goto getlu ; + case 'X': + j = 16; + goto getlu ; + case 'O': + j = 8; + goto getlu ; + case 'D': + l_signed: + geta(&l,wsize(l)) ; + if (l < 0) { + *s++ = '-'; + l = -l; + } + goto do_l; + l_unsignd: + if (l && ndigit) + *s++ = '0'; + do_l: + s = l_compute(l,j,s); + break; +#endif + + case 'x': + j = 16; + goto getu ; + case 'o': + j = 8; + goto getu ; + case 'd': + if ( lflag ) goto l_signed; ; + geta(&inte,wsize(inte)) ; + if ( inte<0 ) { + *s++ = '-'; + inte= -inte ; + } + goto do_i ; + i_unsignd: + if (inte && ndigit) + *s++ = '0'; + do_i: + s = i_compute(inte,j,s); + break; + case 'c': + geta ( &uint, wsize(uint)) ; + for ( i= sizeof uint -1 ; i>=0 ; i-- ) { + if ( *s = uint%256 ) s++; + uint/= 256 ; + } + break; +#ifndef NOFLOAT + case 'e': + geta(&dbl,wsize(dbl)) ; + s = _pscien(dbl,s,ndigit,ndfnd); + break; + case 'f': + geta(&dbl,wsize(dbl)) ; + s = _pfloat(dbl,s,ndigit,ndfnd); + break; +#endif + case 'r': + geta(&nextarg,wsize(nextarg)) ; + geta(&oldfmt,wsize(fmt)) ; + fmt=oldfmt; + continue; + } + j = s - s1; + if ((c = width - j) > 0) + if (rjust == 0) + do putc(zfill,stream); + while (--c); + while (--j >= 0) + putc(*s1++,stream); + while (--c >= 0) + putc(zfill,stream); + } +} diff --git a/lang/cem/libcc/stdio/doscan.c b/lang/cem/libcc/stdio/doscan.c new file mode 100644 index 00000000..2800aa86 --- /dev/null +++ b/lang/cem/libcc/stdio/doscan.c @@ -0,0 +1,278 @@ +#include +#include + +union ptr_union { + char *chr_p; + unsigned short *ushort_p; + unsigned int *uint_p; + unsigned long *ulong_p; +#ifndef NOFLOAT + float *float_p; + double *double_p; +#endif +}; + +static char Xtable[128]; + +/* + * the routine that does the job + */ + +_doscanf (iop, format, argp) +register FILE *iop; +char *format; /* the format control string */ +union ptr_union *argp; /* our argument list */ +{ + int done = 0; /* number of items done */ + int base; /* conversion base */ + long val; /* an integer value */ + int sign; /* sign flag */ + int do_assign; /* assignment suppression flag */ + unsigned width; /* width of field */ + int widflag; /* width was specified */ + int longflag; /* true if long */ + int shortflag; /* true if short */ + int done_some; /* true if we have seen some data */ + int reverse; /* reverse the checking in [...] */ + int kind; + register int ic; +#ifndef NOFLOAT + extern double atof(); + int dotseen; + int expseen; + char buffer[128]; +#endif + + ic = getc(iop); + if (ic == EOF) { + done = EOF; + goto quit; + } + + while (1) { + if (isspace(*format)) { + while (isspace (*format)) + ++format; /* skip whitespace */ + while (isspace (ic)) ic = getc(iop); + } + if (!*format) + goto all_done; /* end of format */ + if (ic < 0) + goto quit; /* seen an error */ + if (*format != '%') { + if (ic != *format) + goto all_done; + ++format; + ic = getc(iop); + ++done; + continue; + } + ++format; + do_assign = 1; + if (*format == '*') { + ++format; + do_assign = 0; + } + if (isdigit (*format)) { + widflag = 1; + for (width = 0; isdigit (*format);) + width = width * 10 + *format++ - '0'; + } else + widflag = 0; /* no width spec */ + if (longflag = (tolower (*format) == 'l')) + ++format; + else if (shortflag = (tolower(*format) == 'h')) + ++format; + if (isupper(*format)) { + kind = tolower(*format); + longflag = 1; + } + else kind = *format; + if (kind != 'c') + while (isspace (ic)) + ic = getc(iop); + done_some = 0; /* nothing yet */ + switch (kind) { + case 'o': + base = 8; + goto decimal; + case 'u': + case 'd': + base = 10; + goto decimal; + case 'x': + base = 16; + if (((!widflag) || width >= 2) && ic == '0') { + ic = getc(iop); + if (tolower (ic) == 'x') { + width -= 2; + done_some = 1; + ic = getc(iop); + } else { + ungetc(ic, iop); + ic = '0'; + } + } + decimal: + val = 0L; /* our result value */ + sign = 0; /* assume positive */ + if (!widflag) + width = 0xffff; /* very wide */ + if (width && ic == '+') + ic = getc(iop); + else if (width && ic == '-') { + sign = 1; + ic = getc(iop); + } + while (width--) { + if (isdigit (ic) && ic - '0' < base) + ic -= '0'; + else if (base == 16 && tolower (ic) >= 'a' && tolower (ic) <= 'f') + ic = 10 + tolower (ic) - 'a'; + else + break; + val = val * base + ic; + ic = getc(iop); + done_some = 1; + } + if (do_assign) { + if (sign) + val = -val; + if (longflag) + *(argp++)->ulong_p = (unsigned long) val; + else if (shortflag) + *(argp++)->ushort_p = (unsigned short) val; + else + *(argp++)->uint_p = (unsigned) val; + } + if (done_some) + ++done; + else + goto all_done; + break; + case 'c': + if (!widflag) + width = 1; + while (width-- && ic >= 0) { + if (do_assign) + *(argp)->chr_p++ = (char) ic; + ic = getc(iop); + done_some = 1; + } + if (do_assign) + argp++; /* done with this one */ + if (done_some) + ++done; + break; + case 's': + if (!widflag) + width = 0xffff; + while (width-- && !isspace (ic) && ic > 0) { + if (do_assign) + *(argp)->chr_p++ = (char) ic; + ic = getc(iop); + done_some = 1; + } + if (do_assign) /* terminate the string */ + *(argp++)->chr_p = '\0'; + if (done_some) + ++done; + else + goto all_done; + break; + case '[': + if (!widflag) + width = 0xffff; + + if ( *(++format) == '^' ) { + reverse = 1; + format++; + } else + reverse = 0; + + { register char *c; + for (c = Xtable; c < &Xtable[128]; c++) *c = 0; + } + while (*format && *format != ']') { + Xtable[*format] = 1; + } + if (!*format) + goto quit; + + while (width-- && !isspace (ic) && ic > 0 && + (Xtable[ic] ^ reverse)) { + if (do_assign) + *(argp)->chr_p++ = (char) ic; + ic = getc(iop); + done_some = 1; + } + if (do_assign) /* terminate the string */ + *(argp++)->chr_p = '\0'; + if (done_some) + ++done; + else + goto all_done; + break; +#ifndef NOFLOAT: + case 'e': + case 'f': { + register char *c = buffer; + + if (width >= 128) width = 127; + if (width && (ic == '+' || ic == '-')) { + *c++ = ic; + width--; + ic = getc(iop); + } + while (isdigit(ic) && width) { + width--; + *c++ = ic; + ic = getc(iop); + } + if (ic == '.' && width) { + width--; + *c++ = ic; + ic = getc(iop); + } + while (isdigit(ic) && width) { + width--; + *c++ = ic; + ic = getc(iop); + } + if (width && (ic == 'e' || ic == 'E')) { + width--; + *c++ = ic; + ic = getc(iop); + if (width && (ic == '+' || ic == '-')) { + width--; + *c++ = ic; + ic = getc(iop); + } + } + while (isdigit(ic) && width) { + width--; + *c++ = ic; + ic = getc(iop); + } + if (c == buffer) goto all_done; + *c = 0; + done++; + + if (do_assign) { + if (longflag) + *(argp++)->double_p = atof(buffer); + else + *(argp++)->float_p = atof(buffer); + } + } + break; +#endif + } /* end switch */ + ++format; + } +all_done: + if (ic >= 0) + ungetc(ic, iop); +quit: + return done; +} diff --git a/lang/cem/libcc/stdio/fclose.c b/lang/cem/libcc/stdio/fclose.c new file mode 100644 index 00000000..577b969b --- /dev/null +++ b/lang/cem/libcc/stdio/fclose.c @@ -0,0 +1,22 @@ +#include + +fclose(fp) +FILE *fp; +{ + register int i; + + for (i=0; i<_NFILES; i++) + if (fp == _io_table[i]) { + _io_table[i] = 0; + break; + } + if (i >= _NFILES) + return(EOF); + fflush(fp); + close(fileno(fp)); + if ( io_testflag(fp,IO_MYBUF) && fp->_buf ) + free( fp->_buf ); + free(fp); + return(NULL); +} + diff --git a/lang/cem/libcc/stdio/fdopen.c b/lang/cem/libcc/stdio/fdopen.c new file mode 100644 index 00000000..0574782b --- /dev/null +++ b/lang/cem/libcc/stdio/fdopen.c @@ -0,0 +1,38 @@ +#include + +FILE *fdopen(fd,mode) +char *mode; +{ + register int i; + FILE *fp; + char *malloc(); + int flags = 0; + + if (fd < 0) return NULL; + for (i = 0; _io_table[i] != 0 ; i++) + if ( i >= _NFILES ) + return(NULL); + + switch(*mode) { + case 'r': + flags |= IO_READMODE; + break; + case 'a': + lseek(fd, 0L, 2); + case 'w': + flags |= IO_WRITEMODE; + break; + default: + return NULL; + } + + if (( fp = (FILE *) malloc (sizeof( FILE))) == NULL ) { + return(NULL); + } + + fp->_count = 0; + fp->_fd = fd; + fp->_flags = flags; + _io_table[i] = fp; + return(fp); +} diff --git a/lang/cem/libcc/stdio/fflush.c b/lang/cem/libcc/stdio/fflush.c new file mode 100644 index 00000000..9a271fb9 --- /dev/null +++ b/lang/cem/libcc/stdio/fflush.c @@ -0,0 +1,26 @@ +#include + + +fflush(iop) +FILE *iop; +{ + int count, c1; + + if ( io_testflag(iop,IO_UNBUFF) || !io_testflag(iop,IO_WRITEMODE) ) + return(0); + + count = BUFSIZ - iop->_count; + if ( count <= 0 ) + return(0); + + c1 = write(iop->_fd,iop->_buf,count); + + if ( count == c1 ) { + iop->_count = BUFSIZ; + iop->_ptr = iop->_buf; + return(count); + } + + iop->_flags |= IO_ERR; + return(EOF); +} diff --git a/lang/cem/libcc/stdio/fgetc.c b/lang/cem/libcc/stdio/fgetc.c new file mode 100644 index 00000000..88bb19cc --- /dev/null +++ b/lang/cem/libcc/stdio/fgetc.c @@ -0,0 +1,7 @@ +#include + +fgetc(f) + register FILE *f; +{ + return getc(f); +} diff --git a/lang/cem/libcc/stdio/fgets.c b/lang/cem/libcc/stdio/fgets.c new file mode 100644 index 00000000..c993b86d --- /dev/null +++ b/lang/cem/libcc/stdio/fgets.c @@ -0,0 +1,21 @@ +#include + +char *fgets(str, n, file) +char *str; +unsigned n; +FILE *file; +{ + register int ch; + register char *ptr; + + ptr = str; + while ( --n > 0 && (ch = getc(file)) != EOF){ + *ptr++ = ch; + if ( ch == '\n') + break; + } + if (ch == EOF && ptr==str) + return(NULL); + *ptr = '\0'; + return(str); +} diff --git a/lang/cem/libcc/stdio/fillbuf.c b/lang/cem/libcc/stdio/fillbuf.c new file mode 100644 index 00000000..b91b2826 --- /dev/null +++ b/lang/cem/libcc/stdio/fillbuf.c @@ -0,0 +1,37 @@ +#include + +_fillbuf(iop) +register FILE *iop; +{ + unsigned char ch[_NFILES]; + + iop->_count = 0; + if (fileno(iop) < 0) return EOF; + if ( io_testflag(iop, (IO_EOF | IO_ERR ))) + return (EOF); + + if ( !io_testflag(iop, IO_READMODE) ) + return (EOF); + + if (! io_testflag(iop, IO_UNBUFF) && ! iop->_buf) { + iop->_buf = (unsigned char *) malloc(BUFSIZ); + if (! iop->_buf) iop->_flags |= IO_UNBUFF; + else iop->_flags |= IO_MYBUF; + } + if (! iop->_buf) iop->_buf = &ch[fileno(iop)]; + iop->_ptr = iop->_buf; + iop->_count = read(iop->_fd, iop->_buf, io_testflag(iop, IO_UNBUFF)? 1 : BUFSIZ); + + if (iop->_count <= 0){ + if (iop->_count == 0) { + iop->_flags |= IO_EOF; + } + else + iop->_flags |= IO_ERR; + + return (EOF); + } + iop->_count--; + + return *iop->_ptr++; +} diff --git a/lang/cem/libcc/stdio/fltpr.c b/lang/cem/libcc/stdio/fltpr.c new file mode 100644 index 00000000..5af631ef --- /dev/null +++ b/lang/cem/libcc/stdio/fltpr.c @@ -0,0 +1,57 @@ +#ifndef NOFLOAT +extern char *fcvt(); +extern char *ecvt(); + +char * +_pfloat(r,s,n,b) + double r; + register char *s; +{ + int sign,dp,i; char *s1; + + if (b == 0) + n = 6; + s1 = fcvt(r,n,&dp,&sign); + if (sign) + *s++ = '-'; + if (dp<=0) + *s++ = '0'; + for (i=dp; i>0; i--) + *s++ = *s1++; + if ((i=n) > 0) + *s++ = '.'; + while (++dp <= 0) { + if (--i<0) + break; + *s++ = '0'; + } + while (--i >= 0) + *s++ = *s1++; + return(s); +} + +char *_pscien(r,s,n,b) float r; char *s; { + int sign,dp; char *s1; + + if (b == 0) + n = 7; + else n += 1; + s1 = ecvt(r,n,&dp,&sign); + if (sign) + *s++ = '-'; + *s++ = *s1++; + *s++ = '.'; + while (--n>0) + *s++ = *s1++; + *s++ = 'e'; + if ( r ) --dp ; + if ( dp<0 ) { + *s++ = '-' ; dp= -dp ; + } else { + *s++ = '+' ; + } + *s++ = '0' + (dp/10); + *s++ = '0' + (dp%10); + return(s); +} +#endif diff --git a/lang/cem/libcc/stdio/flushbuf.c b/lang/cem/libcc/stdio/flushbuf.c new file mode 100644 index 00000000..4208646d --- /dev/null +++ b/lang/cem/libcc/stdio/flushbuf.c @@ -0,0 +1,71 @@ +#include + +int +_flushbuf(c, iop) + register FILE *iop; +{ + if (fileno(iop) < 0) return EOF; + if (! io_testflag(iop, IO_UNBUFF)) { + if (iop->_buf == 0) { + if (iop == stdout) { + if (isatty(fileno(stdout))) { + iop->_flags |= IO_UNBUFF; + } + else { + extern unsigned char __stdout[]; + + iop->_buf = iop->_ptr = __stdout; + iop->_count = BUFSIZ; + } + } + else { + extern char *malloc(); + + if (!(iop->_buf = (unsigned char *) malloc(BUFSIZ))) { + iop->_flags |= IO_UNBUFF; + } + else { + iop->_ptr = iop->_buf; + iop->_flags |= IO_MYBUF; + iop->_count = BUFSIZ; + } + } + } + } + + if (io_testflag(iop, IO_UNBUFF)) { + char c1 = c; + + iop->_count = 0; + if (write(fileno(iop), &c1, 1) != 1) { + iop->_flags |= IO_ERR; + return EOF; + } + return c; + } + else { + int count = BUFSIZ - iop->_count; + + iop->_count = BUFSIZ - 1; + iop->_ptr = iop->_buf + 1; + + if (count > 0) { + if (write(fileno(iop), iop->_buf, count) != count) { + *(iop->_buf) = c; + iop->_flags |= IO_ERR; + return EOF; + } + } + *(iop->_buf) = c; + } + return c; +} + +_cleanup() +{ + register int i; + + for ( i = 0 ; i < _NFILES ; i++ ) + if ( _io_table[i] != NULL ) + fclose(_io_table[i]); +} diff --git a/lang/cem/libcc/stdio/fopen.c b/lang/cem/libcc/stdio/fopen.c new file mode 100644 index 00000000..3c6296cc --- /dev/null +++ b/lang/cem/libcc/stdio/fopen.c @@ -0,0 +1,56 @@ +#include + +#define PMODE 0666 + + +FILE *fopen(name,mode) +char *name , *mode; +{ + register int i; + FILE *fp; + char *malloc(); + int fd, + flags = 0; + + for (i = 0; _io_table[i] != 0 ; i++) + if ( i >= _NFILES ) + return(NULL); + + switch(*mode){ + + case 'w': + flags |= IO_WRITEMODE; + fd = creat (name,PMODE); + break; + + case 'a': + flags |= IO_WRITEMODE; + if (( fd = open(name, 1)) < 0 ) + fd = creat(name, PMODE); + if (fd >= 0) lseek(fd,0L,2); + break; + + case 'r': + flags |= IO_READMODE; + if (( fd = open (name, 0)) < 0 ) + return(NULL); + break; + + default: + return(NULL); + } + + + if (fd < 0) return NULL; + + if (( fp = (FILE *) malloc (sizeof( FILE))) == NULL ) { + close(fd); + return(NULL); + } + + fp->_count = 0; + fp->_fd = fd; + fp->_flags = flags; + _io_table[i] = fp; + return(fp); +} diff --git a/lang/cem/libcc/stdio/fprintf.c b/lang/cem/libcc/stdio/fprintf.c new file mode 100644 index 00000000..8e036725 --- /dev/null +++ b/lang/cem/libcc/stdio/fprintf.c @@ -0,0 +1,11 @@ +#include + +fprintf (file, fmt, args) +FILE *file; +char *fmt; +int args; +{ + _doprnt (fmt, &args, file); + if ( io_testflag(file,IO_PERPRINTF) ) + fflush(file); +} diff --git a/lang/cem/libcc/stdio/fputc.c b/lang/cem/libcc/stdio/fputc.c new file mode 100644 index 00000000..de45d918 --- /dev/null +++ b/lang/cem/libcc/stdio/fputc.c @@ -0,0 +1,7 @@ +#include + +fputc(c, iop) + register FILE *iop; +{ + return putc(c, iop); +} diff --git a/lang/cem/libcc/stdio/fputs.c b/lang/cem/libcc/stdio/fputs.c new file mode 100644 index 00000000..7cb723e9 --- /dev/null +++ b/lang/cem/libcc/stdio/fputs.c @@ -0,0 +1,9 @@ +#include + +fputs(s,file) +register char *s; +register FILE *file; +{ + while ( *s ) + putc(*s++,file); +} diff --git a/lang/cem/libcc/stdio/fread.c b/lang/cem/libcc/stdio/fread.c new file mode 100644 index 00000000..ea885a4c --- /dev/null +++ b/lang/cem/libcc/stdio/fread.c @@ -0,0 +1,25 @@ +#include + +fread(ptr, size, count, file) +register char *ptr; +unsigned size, count; +register FILE *file; +{ + int c; + unsigned ndone = 0, s; + + ndone = 0; + if (size) + while ( ndone < count ) { + s = size; + do { + if ((c = getc(file)) != EOF) + *ptr++ = c; + else + return(ndone); + } while (--s); + ndone++; + } + return(ndone); +} + diff --git a/lang/cem/libcc/stdio/freopen.c b/lang/cem/libcc/stdio/freopen.c new file mode 100644 index 00000000..b33659e3 --- /dev/null +++ b/lang/cem/libcc/stdio/freopen.c @@ -0,0 +1,59 @@ +#include + +#define PMODE 0666 + + +FILE *freopen(name,mode,fp) +char *name , *mode; +FILE *fp; +{ + FILE *fp; + char *malloc(); + int fd, + flags = 0; + + close(fileno(fp)); + if (io_testflag(fp, IO_MYBUF) && fp->_buf) free(fp->_buf); + + switch(*mode){ + + case 'w': + flags |= IO_WRITEMODE; + fd = creat (name,PMODE); + break; + + case 'a': + flags |= IO_WRITEMODE; + if (( fd = open(name, 1)) < 0 ) + fd = creat(name, PMODE); + if (fd >= 0) lseek(fd,0L,2); + break; + + case 'r': + flags |= IO_READMODE; + fd = open(name, 0); + break; + + default: + fd = -1; + } + + if (fd < 0) { + register int i; + + for (i = 0; i < _NFILES; i++) { + if (fp == _io_table[i]) { + _io_table[i] = 0; + break; + } + } + free(fp); + return NULL; + } + + fp->_count = 0; + fp->_fd = fd; + fp->_flags = flags; + fp->_buf = 0; + return(fp); +} diff --git a/lang/cem/libcc/stdio/fscanf.c b/lang/cem/libcc/stdio/fscanf.c new file mode 100644 index 00000000..f92aa285 --- /dev/null +++ b/lang/cem/libcc/stdio/fscanf.c @@ -0,0 +1,10 @@ +#include + +int fscanf (fp, format, args) +FILE *fp; +char *format; +unsigned args; +{ + return _doscanf (fp, format, &args); +} + diff --git a/lang/cem/libcc/stdio/fseek.c b/lang/cem/libcc/stdio/fseek.c new file mode 100644 index 00000000..c646d7b2 --- /dev/null +++ b/lang/cem/libcc/stdio/fseek.c @@ -0,0 +1,39 @@ +#include + + +fseek(iop, offset, where) +FILE *iop; +long offset; +{ + int count; + long lseek(); + long pos; + + iop->_flags &= ~(IO_EOF | IO_ERR); + /* Clear both the end of file and error flags */ + + if ( io_testflag(iop,IO_READMODE) ) { + if ( where < 2 && iop->_buf && !io_testflag(iop,IO_UNBUFF) ) { + count = iop->_count; + pos = offset; + + if ( where == 0 ) + pos += count - lseek(fileno(iop), 0L,1); + else + offset -= count; + + if ( count > 0 && pos <= count + && pos >= iop->_buf - iop->_ptr ) { + iop->_ptr += (int) pos; + iop->_count -= (int) pos; + return(0); + } + } + pos = lseek(fileno(iop), offset, where); + iop->_count = 0; + } else if ( io_testflag(iop,IO_WRITEMODE) ) { + fflush(iop); + pos = lseek(fileno(iop), offset, where); + } + return((pos == -1) ? -1 : 0 ); +} diff --git a/lang/cem/libcc/stdio/ftell.c b/lang/cem/libcc/stdio/ftell.c new file mode 100644 index 00000000..6302977d --- /dev/null +++ b/lang/cem/libcc/stdio/ftell.c @@ -0,0 +1,25 @@ +#include + + +long ftell(iop) +FILE *iop; +{ + long result; + long lseek(); + int adjust = 0; + + if ( io_testflag(iop,IO_READMODE) ) + adjust -= iop->_count; + else if ( io_testflag(iop,IO_WRITEMODE) && iop->_buf && !io_testflag(iop,IO_UNBUFF)) + adjust = iop->_ptr - iop->_buf; + else + return(-1); + + result = lseek(fileno(iop), 0L, 1); + + if ( result < 0 ) + return ( result ); + + result += (long) adjust; + return(result); +} diff --git a/lang/cem/libcc/stdio/fwrite.c b/lang/cem/libcc/stdio/fwrite.c new file mode 100644 index 00000000..0f6b51a5 --- /dev/null +++ b/lang/cem/libcc/stdio/fwrite.c @@ -0,0 +1,23 @@ +#include + +fwrite(ptr, size, count, file) +unsigned size, count; +register char *ptr; +register FILE *file; +{ + unsigned s; + unsigned ndone = 0; + + if (size) + while ( ndone < count ) { + s = size; + do { + putc(*ptr++, file); + if (ferror(file)) + return(ndone); + } + while (--s); + ndone++; + } + return(ndone); +} diff --git a/lang/cem/libcc/stdio/getchar.c b/lang/cem/libcc/stdio/getchar.c new file mode 100644 index 00000000..ba4a8580 --- /dev/null +++ b/lang/cem/libcc/stdio/getchar.c @@ -0,0 +1,8 @@ +#include + +#undef getchar + +getchar() +{ + return getc(stdin); +} diff --git a/lang/cem/libcc/stdio/getgrent.c b/lang/cem/libcc/stdio/getgrent.c new file mode 100644 index 00000000..f58082ef --- /dev/null +++ b/lang/cem/libcc/stdio/getgrent.c @@ -0,0 +1,115 @@ +/* + * get entry from group file + * + * By: Patrick van Kleef + */ + +#include + +#define PRIVATE static + +PRIVATE char _gr_file[] = "/etc/group"; +PRIVATE char _grbuf[256]; +PRIVATE char _buffer[1024]; +PRIVATE char *_pnt; +PRIVATE char *_buf; +PRIVATE int _gfd = -1; +PRIVATE int _bufcnt; +PRIVATE struct group grp; + +setgrent () +{ + if (_gfd >= 0) + lseek (_gfd, 0L, 0); + else + _gfd = open (_gr_file, 0); + + _bufcnt = 0; + return (_gfd); +} + + +endgrent () +{ + if (_gfd >= 0) + close (_gfd); + + _gfd = -1; + _bufcnt = 0; +} + + +static getline () +{ + if (_gfd < 0 && setgrent () < 0) + return (0); + + _buf = _grbuf; + do { + if (--_bufcnt <= 0){ + if ((_bufcnt = read (_gfd, _buffer, 1024)) <= 0) + return (0); + else + _pnt = _buffer; + } + *_buf++ = *_pnt++; + } while (*_pnt != '\n'); + _pnt++; + _bufcnt--; + *_buf = 0; + _buf = _grbuf; + return (1); +} + +static skip_period () +{ + while (*_buf != ':') + _buf++; + *_buf++ = '\0'; +} + +struct group *getgrent () +{ + if (getline () == 0) + return (0); + + grp.gr_name = _buf; + skip_period (); + grp.gr_passwd = _buf; + skip_period (); + grp.gr_gid = atoi (_buf); + skip_period (); + return (&grp); +} + +struct group *getgrnam (name) +char *name; +{ + struct group *grp; + + setgrent (); + while ((grp = getgrent ()) != 0) + if (!strcmp (grp -> gr_name, name)) + break; + endgrent (); + if (grp != 0) + return (grp); + else + return (0); +} + +struct group *getgrgid (gid) +int gid; +{ + struct group *grp; + + setgrent (); + while ((grp = getgrent ()) != 0) + if (grp -> gr_gid == gid) + break; + endgrent (); + if (grp != 0) + return (grp); + else + return (0); +} diff --git a/lang/cem/libcc/stdio/getpass.c b/lang/cem/libcc/stdio/getpass.c new file mode 100644 index 00000000..53a6a664 --- /dev/null +++ b/lang/cem/libcc/stdio/getpass.c @@ -0,0 +1,29 @@ +#include +#include + +char * getpass(prompt) +char *prompt; +{ + int i = 0; + struct sgttyb tty, ttysave; + static char pwdbuf[9]; + int fd; + int (*savesig)(); + + if ((fd = open("/dev/tty", 0)) < 0) fd = 0; + savesig = signal(SIGINT, SIG_IGN); + write(2, prompt, strlen(prompt)); + gtty(fd, &tty); + ttysave = tty; + tty.sg_flags &= ~ECHO; + stty(fd, &tty); + i = read(fd, pwdbuf, 9); + while (pwdbuf[i - 1] != '\n') + read(fd, &pwdbuf[i - 1], 1); + pwdbuf[i - 1] = '\0'; + stty(fd, &ttysave); + write(2, "\n", 1); + if (fd != 0) close(fd); + signal(SIGINT, savesig); + return(pwdbuf); +} diff --git a/lang/cem/libcc/stdio/getpw.c b/lang/cem/libcc/stdio/getpw.c new file mode 100644 index 00000000..4dd3eb19 --- /dev/null +++ b/lang/cem/libcc/stdio/getpw.c @@ -0,0 +1,35 @@ +#include + +getpw(uid, buf) + int uid; + char buf[]; +{ + register FILE *pwf; + register int ch, i; + register char *bp; + + pwf = fopen("/etc/passwd", "r"); + if (pwf == NULL) return(1); + + for (;;) { + bp = buf; + while ((ch = getc(pwf)) != '\n') { + if (ch == EOF) return 1; + *bp++ = ch; + } + *bp++ = '\0'; + bp = buf; + for (i = 2; i; i--) { + while ((ch = *bp++) != ':') { + if(ch = '\0') return 1; + } + } + i = 0; + while ((ch = *bp++) != ':') { + if (ch < '0' || ch > '9') return 1; + i = i * 10 + (ch - '0'); + } + if (i == uid) return(0); + } + /*NOTREACHED*/ +} diff --git a/lang/cem/libcc/stdio/getpwent.c b/lang/cem/libcc/stdio/getpwent.c new file mode 100644 index 00000000..376d04be --- /dev/null +++ b/lang/cem/libcc/stdio/getpwent.c @@ -0,0 +1,125 @@ +/* + * get entry from password file + * + * By Patrick van Kleef + * + */ + + +#include + +#define PRIVATE static + + +PRIVATE char _pw_file[] = "/etc/passwd"; +PRIVATE char _pwbuf[256]; +PRIVATE char _buffer[1024]; +PRIVATE char *_pnt; +PRIVATE char *_buf; +PRIVATE int _pw = -1; +PRIVATE int _bufcnt; +PRIVATE struct passwd pwd; + +setpwent() +{ + if (_pw >= 0) + lseek (_pw, 0L, 0); + else + _pw = open (_pw_file, 0); + + _bufcnt = 0; + return (_pw); +} + + +endpwent () +{ + if (_pw >= 0) + close (_pw); + + _pw = -1; + _bufcnt = 0; +} + +static getline () +{ + if (_pw < 0 && setpwent () < 0) + return (0); + _buf = _pwbuf; + do { + if (--_bufcnt <= 0){ + if ((_bufcnt = read (_pw, _buffer, 1024)) <= 0) + return (0); + else + _pnt = _buffer; + } + *_buf++ = *_pnt++; + } while (*_pnt != '\n'); + _pnt++; + _bufcnt--; + *_buf = 0; + _buf = _pwbuf; + return (1); +} + +static skip_period () +{ + while (*_buf != ':') + _buf++; + + *_buf++ = '\0'; +} + +struct passwd *getpwent () +{ + if (getline () == 0) + return (0); + + pwd.pw_name = _buf; + skip_period (); + pwd.pw_passwd = _buf; + skip_period (); + pwd.pw_uid = atoi (_buf); + skip_period (); + pwd.pw_gid = atoi (_buf); + skip_period (); + pwd.pw_gecos = _buf; + skip_period (); + pwd.pw_dir = _buf; + skip_period (); + pwd.pw_shell = _buf; + + return (&pwd); +} + +struct passwd *getpwnam (name) +char *name; +{ + struct passwd *pwd; + + setpwent (); + while ((pwd = getpwent ()) != 0) + if (!strcmp (pwd -> pw_name, name)) + break; + endpwent (); + if (pwd != 0) + return (pwd); + else + return (0); +} + +struct passwd *getpwuid (uid) +int uid; +{ + struct passwd *pwd; + + setpwent (); + while ((pwd = getpwent ()) != 0) + if (pwd -> pw_uid == uid) + break; + endpwent (); + if (pwd != 0) + return (pwd); + else + return (0); +} diff --git a/lang/cem/libcc/stdio/gets.c b/lang/cem/libcc/stdio/gets.c new file mode 100644 index 00000000..5798e6a3 --- /dev/null +++ b/lang/cem/libcc/stdio/gets.c @@ -0,0 +1,17 @@ +#include + +char *gets(str) +char *str; +{ + register int ch; + register char *ptr; + + ptr = str; + while ((ch = getc(stdin)) != EOF && ch != '\n') + *ptr++ = ch; + + if (ch == EOF && ptr==str) + return(NULL); + *ptr = '\0'; + return(str); +} diff --git a/lang/cem/libcc/stdio/getw.c b/lang/cem/libcc/stdio/getw.c new file mode 100644 index 00000000..1ab33fb6 --- /dev/null +++ b/lang/cem/libcc/stdio/getw.c @@ -0,0 +1,15 @@ +#include + +int getw(iop) + register FILE *iop; +{ + register int cnt = sizeof(int); + int w; + register char *p = (char *) &w; + + while (cnt--) { + *p++ = getc(iop); + } + if (foef(iop) || ferror(iop)) return EOF; + return w; +} diff --git a/lang/cem/libcc/stdio/popen.c b/lang/cem/libcc/stdio/popen.c new file mode 100644 index 00000000..e9538900 --- /dev/null +++ b/lang/cem/libcc/stdio/popen.c @@ -0,0 +1,54 @@ +#include +#include + +static int pids[20]; + +FILE * +popen(command, type) + char *command, *type; +{ + int piped[2]; + int Xtype = *type == 'r' ? 0 : *type == 'w' ? 1 : 2; + int pid; + + if (Xtype == 2 || + pipe(piped) < 0 || + (pid = fork()) < 0) return 0; + + if (pid == 0) { + /* child */ + register int *p; + + for (p = pids; p < &pids[20]; p++) { + if (*p) close(p - pids); + } + close(piped[Xtype]); + dup2(piped[!Xtype], !Xtype); + close(piped[!Xtype]); + execl("/bin/sh", "sh", "-c", command, (char *) 0); + _exit(127); /* like system() ??? */ + } + + pids[piped[Xtype]] = pid; + close(piped[!Xtype]); + return fdopen(piped[Xtype], type); +} + +pclose(iop) + FILE *iop; +{ + int fd = fileno(iop); + int status, wret; + int (*intsave)() = signal(SIGINT, SIG_IGN); + int (*quitsave)() = signal(SIGQUIT, SIG_IGN); + + fclose(iop); + while ((wret = wait(&status)) != -1) { + if (wret == pids[fd]) break; + } + if (wret == -1) status = -1; + signal(SIGINT, intsave); + signal(SIGQUIT, quitsave); + pids[fd] = 0; + return status; +} diff --git a/lang/cem/libcc/stdio/printf.c b/lang/cem/libcc/stdio/printf.c new file mode 100644 index 00000000..cc3f0d9a --- /dev/null +++ b/lang/cem/libcc/stdio/printf.c @@ -0,0 +1,10 @@ +#include + +printf (fmt, args) +char *fmt; +int args; +{ + _doprnt (fmt, &args, stdout); + if ( io_testflag(stdout,IO_PERPRINTF) ) + fflush(stdout); +} diff --git a/lang/cem/libcc/stdio/putchar.c b/lang/cem/libcc/stdio/putchar.c new file mode 100644 index 00000000..ebf2d483 --- /dev/null +++ b/lang/cem/libcc/stdio/putchar.c @@ -0,0 +1,8 @@ +#include + +#undef putchar + +putchar(c) +{ + return putc(c, stdout); +} diff --git a/lang/cem/libcc/stdio/puts.c b/lang/cem/libcc/stdio/puts.c new file mode 100644 index 00000000..07fb782c --- /dev/null +++ b/lang/cem/libcc/stdio/puts.c @@ -0,0 +1,10 @@ +#include + +puts(s) +register char *s; +{ + register FILE *file = stdout; + while ( *s ) + putc(*s++,file); + putc('\n', file); +} diff --git a/lang/cem/libcc/stdio/putw.c b/lang/cem/libcc/stdio/putw.c new file mode 100644 index 00000000..2343c1e7 --- /dev/null +++ b/lang/cem/libcc/stdio/putw.c @@ -0,0 +1,15 @@ +#include + +int +putw(w, iop) + register FILE *iop; +{ + register int cnt = sizeof(int); + register char *p = (char *) &w; + + while (cnt--) { + putc(*p++, iop); + } + if (ferror(iop)) return EOF; + return w; +} diff --git a/lang/cem/libcc/stdio/rewind.c b/lang/cem/libcc/stdio/rewind.c new file mode 100644 index 00000000..dd9d8657 --- /dev/null +++ b/lang/cem/libcc/stdio/rewind.c @@ -0,0 +1,7 @@ +#include + +rewind(iop) + FILE *iop; +{ + return fseek(iop, 0L, 0); +} diff --git a/lang/cem/libcc/stdio/scanf.c b/lang/cem/libcc/stdio/scanf.c new file mode 100644 index 00000000..fcdc210c --- /dev/null +++ b/lang/cem/libcc/stdio/scanf.c @@ -0,0 +1,10 @@ +#include + +int scanf (format, args) +char *format; +unsigned args; +{ + return _doscanf (stdin, format, &args); +} + + diff --git a/lang/cem/libcc/stdio/setbuf.c b/lang/cem/libcc/stdio/setbuf.c new file mode 100644 index 00000000..2b857dd5 --- /dev/null +++ b/lang/cem/libcc/stdio/setbuf.c @@ -0,0 +1,20 @@ +#include + + +setbuf(iop, buffer) +register FILE *iop; +char *buffer; +{ + if ( iop->_buf && io_testflag(iop,IO_MYBUF) ) + free(iop->_buf); + + iop->_flags &= ~(IO_MYBUF | IO_UNBUFF | IO_PERPRINTF); + + iop->_buf = (unsigned char *) buffer; + + if ( iop->_buf == NULL ) + iop->_flags |= IO_UNBUFF; + + iop->_ptr = iop->_buf; + iop->_count = 0; +} diff --git a/lang/cem/libcc/stdio/sprintf.c b/lang/cem/libcc/stdio/sprintf.c new file mode 100644 index 00000000..40560b55 --- /dev/null +++ b/lang/cem/libcc/stdio/sprintf.c @@ -0,0 +1,19 @@ +#include + +char *sprintf(buf,format,args) +char *buf, *format; +int args; +{ + FILE _tempfile; + + _tempfile._fd = -1; + _tempfile._flags = IO_WRITEMODE + IO_UNBUFF; + _tempfile._buf = (unsigned char *) buf; + _tempfile._ptr = (unsigned char *) buf; + _tempfile._count = 32767; + + _doprintf(format, &args, &_tempfile); + putc('\0',&_tempfile); + + return buf; +} diff --git a/lang/cem/libcc/stdio/sscanf.c b/lang/cem/libcc/stdio/sscanf.c new file mode 100644 index 00000000..3328b49e --- /dev/null +++ b/lang/cem/libcc/stdio/sscanf.c @@ -0,0 +1,17 @@ +#include + +int sscanf (string, format, args) +char *string; /* source of data */ +char *format; /* control string */ +unsigned args; /* our args */ +{ + FILE _tempfile; + + _tempfile._fd = -1; + _tempfile._flags = IO_READMODE + IO_UNBUFF; + _tempfile._buf = (unsigned char *) string; + _tempfile._ptr = (unsigned char *) string; + _tempfile._count = 32767; + + return _doscanf (&_tempfile, format, &args); +} diff --git a/lang/cem/libcc/stdio/system.c b/lang/cem/libcc/stdio/system.c new file mode 100644 index 00000000..6ffae3dc --- /dev/null +++ b/lang/cem/libcc/stdio/system.c @@ -0,0 +1,24 @@ +#include + +system(str) + char *str; +{ + int pid, exitstatus, waitval; + int i; + + if ((pid = fork()) < 0) return -1; + if (pid == 0) { + for (i = 3; i <= 20; i++) close(i); + execl("/bin/sh", "sh", "-c", str, (char *) 0); + /* get here if execl fails ... */ + _exit(127); /* see manual page */ + } + while ((waitval = wait(&exitstatus)) != pid) { + if (waitval == -1) break; + } + if (waitval == -1) { + /* no child ??? or maybe interrupted ??? */ + exitstatus = -1; + } + return exitstatus; +} diff --git a/lang/cem/libcc/stdio/timezone.c b/lang/cem/libcc/stdio/timezone.c new file mode 100644 index 00000000..31da9dfe --- /dev/null +++ b/lang/cem/libcc/stdio/timezone.c @@ -0,0 +1,59 @@ +static struct zonetable { + int offset; + char *stdzone; + char *dstzone; +} zonetable[] = { + -3*60-30, "NST", 0, /* new foundland ??? */ + -4*60, "AST", "ADT", /* atlanic */ + -5*60, "EST", "EDT", /* eastern */ + -6*60, "CST", "CDT", /* central */ + -7*60, "MST", "MDT", /* mountain */ + -8*60, "PST", "PDT", /* pacific */ + -9*60, "YST", "YDT", /* yukon */ + -10*60, "AST", "ADT", /* aleutian */ + -10*60, "HST", "HDT", /* hawai, never found */ + 0, "GMT", 0, /* Greenwich */ + 0, "WET", "WDT", /* west european, never found */ + 1*60,"MET", "MDT", /* middle european */ + 2*60, "EET", "EDT", /* east european */ + 8*60, "WST", 0, /* west australia */ + 9*60, "JST", 0, /* japan */ + 9*60+30, "CST", 0, /* also australia ??? */ + 10*60, "EST", 0, /* also australia ??? */ + -1 +}; + +char * +timezone(zone, dst) +{ + register struct zonetable *p = zonetable; + static char buf[16]; + register char *c; + int i; + + while (p->offset != -1) { + if (zone == -p->offset) { + if (dst && p->dstzone) return p->dstzone; + if (!dst && p->stdzone) return p->stdzone; + } + p++; + } + *c++ = 'G'; + *c++ = 'M'; + *c++ = 'T'; + if (zone < 0) { + zone = - zone; + *c++ = '+'; + } + else *c++ = '-'; + i = (zone / 60) % 24; + if (i >= 10) { + *c++ = i / 10 + '0'; + } + *c++ = i % 10 + '0'; + i = zone % 60; + *c++ = i / 10 + '0'; + *c++ = i % 10 + '0'; + *c = '\0'; + return buf; +} diff --git a/lang/cem/libcc/stdio/ungetc.c b/lang/cem/libcc/stdio/ungetc.c new file mode 100644 index 00000000..ee88bf2b --- /dev/null +++ b/lang/cem/libcc/stdio/ungetc.c @@ -0,0 +1,16 @@ +#include + +ungetc(ch, iop) +int ch; +FILE *iop; +{ + if ( ch < 0 || !io_testflag(iop,IO_READMODE)) + return EOF; + if (iop->_ptr == iop->_buf) { + if (iop->_count != 0) return EOF; + iop->_ptr++; + } + iop->_count++; + *--iop->_ptr = ch; + return(ch); +} From ddc02a78a042395a2cbb599d8724ffc81096b2f0 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 27 Jan 1987 16:21:02 +0000 Subject: [PATCH 0559/1625] Initial revision --- lang/cem/libcc/gen/LIST | 71 +++++++++++++++++++++++++++++++++++++++ lang/cem/libcc/stdio/LIST | 43 ++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 lang/cem/libcc/gen/LIST create mode 100644 lang/cem/libcc/stdio/LIST diff --git a/lang/cem/libcc/gen/LIST b/lang/cem/libcc/gen/LIST new file mode 100644 index 00000000..24f2814d --- /dev/null +++ b/lang/cem/libcc/gen/LIST @@ -0,0 +1,71 @@ +tail_cc.2g.a +abs.c +atof.c +atoi.c +atol.c +bcmp.c +bfill.c +bmove.c +bzero.c +calloc.c +crypt.c +ctime.c +asctime.c +execvp.c +ffc.c +ffs.c +gcvt.c +ecvt.c +getlogin.c +getopt.c +index.c +l3.c +ldexp.c +localtime.c +gmtime.c +memccpy.c +memchr.c +memcmp.c +memcpy.c +memset.c +mktemp.c +monitor.c +perror.c +procentry.c +qsort.c +rand.c +seekdir.c +sleep.c +stb.c +strstr.c +strchr.c +strcmp.c +strcspn.c +strncat.c +strrchr.c +strtok.c +strpbrk.c +strspn.c +swab.c +telldir.c +ttyslot.c +rindex.c +strncmp.c +ttyname.c +closedir.c +isatty.c +opendir.c +malloc.c +bcopy.c +readdir.c +strcat.c +strcpy.c +strlen.c +tzset.c +getenv.c +strncpy.c +_c2type.c +abort.e +frexp.e +modf.e +setjmp.e diff --git a/lang/cem/libcc/stdio/LIST b/lang/cem/libcc/stdio/LIST new file mode 100644 index 00000000..64fc99d9 --- /dev/null +++ b/lang/cem/libcc/stdio/LIST @@ -0,0 +1,43 @@ +tail_cc.1s.a +clearerr.c +fgetc.c +fgets.c +fprintf.c +fputc.c +fputs.c +fread.c +freopen.c +fscanf.c +ftell.c +fwrite.c +getchar.c +getgrent.c +getpass.c +getpw.c +fopen.c +getpwent.c +gets.c +getw.c +popen.c +fdopen.c +printf.c +doprnt.c +fltpr.c +putchar.c +puts.c +putw.c +rewind.c +fseek.c +scanf.c +setbuf.c +sprintf.c +flushbuf.c +fclose.c +data.c +fflush.c +sscanf.c +doscan.c +fillbuf.c +system.c +timezone.c +ungetc.c From ba16147be467ce4de731ba69f53f73e29317d071 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 27 Jan 1987 16:33:21 +0000 Subject: [PATCH 0560/1625] Initial revision --- include/_tail_cc/ctype.h | 45 +++++++++++++++++++++++++++ include/_tail_cc/stdio.h | 62 ++++++++++++++++++++++++++++++++++++++ include/_tail_cc/sys/dir.h | 34 +++++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 include/_tail_cc/ctype.h create mode 100644 include/_tail_cc/stdio.h create mode 100644 include/_tail_cc/sys/dir.h diff --git a/include/_tail_cc/ctype.h b/include/_tail_cc/ctype.h new file mode 100644 index 00000000..b9e84109 --- /dev/null +++ b/include/_tail_cc/ctype.h @@ -0,0 +1,45 @@ +/* File : ctypes.h + Author : Richard A. O'Keefe. + Updated: 26 April 1984 + Purpose: Reimplement the UNIX ctype(3) library. + + isaneol(c) means that c is a line terminating character. + isalnum, ispunct, isspace, and isaneol are defined on the + range -1..127, i.e. on ASCII U {EOF}, while all the other + macros are defined for any integer. + + isodigit(c) checks for Octal digits. + isxdigit(c) checkx for heXadecimal digits. +*/ + +#define isdigit(c) ((unsigned)((c)-'0') < 10) +#define islower(c) ((unsigned)((c)-'a') < 26) +#define isupper(c) ((unsigned)((c)-'A') < 26) +#define isprint(c) ((unsigned)((c)-' ') < 95) +#define iscntrl(c) ((unsigned)((c)-' ') >= 95) +#define isascii(c) ((unsigned)(c) < 128) +#define isalpha(c) ((unsigned)(((c)|32)-'a') < 26) + +extern char _c2type[]; + +#define isalnum(c) (_c2type[(c)+1] < 36) +#define ispunct(c) (_c2type[(c)+1] == 36) +#define isspace(c) (_c2type[(c)+1] > 37) +#define isaneol(c) (_c2type[(c)+1] > 38) + +#define isxdigit(c) (_c2type[(c)+1] < 16) +#define isodigit(c) ((unsigned)((c)-'0') < 8) + +/* The following "conversion" macros have been in some versions of UNIX + but are not in all. tocntrl is new. The original motivation for ^? + being a name for DEL was that (x)^64 mapped A..Z to ^A..^Z and also + ? to DEL. The trouble is that this trick doesn't work for lower case + letters. The version given here is not mine. I wish it was. It has + the nice property that DEL is mapped to itself (so does EOF). + tolower(c) and toupper(c) are only defined when isalpha(c). +*/ +#define tolower(c) ((c)|32) +#define toupper(c) ((c)&~32) +#define tocntrl(c) (((((c)+1)&~96)-1)&127) +#define toascii(c) ((c)&127) + diff --git a/include/_tail_cc/stdio.h b/include/_tail_cc/stdio.h new file mode 100644 index 00000000..e106f191 --- /dev/null +++ b/include/_tail_cc/stdio.h @@ -0,0 +1,62 @@ +#define BUFSIZ 1024 +#define _NFILES 20 +#define NULL 0 +#define EOF (-1) +#define CMASK 0377 + +#define IO_READMODE 1 +#define IO_WRITEMODE 2 +#define IO_UNBUFF 4 +#define IO_EOF 8 +#define IO_ERR 16 +#define IO_MYBUF 32 +#define IO_PERPRINTF 64 + +#ifndef FILE + +extern struct _io_buf { + int _fd; + int _count; + int _flags; + unsigned char *_buf; + unsigned char *_ptr; +} *_io_table[_NFILES]; + + +#endif /* FILE */ + +#define FILE struct _io_buf + + +#define stdin (_io_table[0]) +#define stdout (_io_table[1]) +#define stderr (_io_table[2]) + +#define getchar() getc(stdin) +#define putchar(c) putc(c,stdout) +#define getc(p) (--(p)->_count >= 0 ? (int) (*(p)->_ptr++) : \ + _fillbuf(p)) +#define putc(c, p) (--(p)->_count >= 0 ? \ + (int) (*(p)->_ptr++ = (c)) : \ + _flushbuf((c),(p))) +#define feof(p) (((p)->_flags & IO_EOF) != 0) +#define ferror(p) (((p)->_flags & IO_ERR) != 0) +#define fileno(p) ((p)->_fd) +#define io_testflag(p,x) ((p)->_flags & (x)) + +/* If you want a stream to be flushed after each printf use: + * + * io_perprintf(stream); + * + * If you want to stop with this kind of buffering use: + * + * io_noperprintf(stream); + */ + +#define io_noperprintf(p) ((p)->_flags &= ~IO_PERPRINTF) +#define io_perprintf(p) ((p)->_flags |= IO_PERPRINTF) + +extern FILE *fopen(), *fdopen(), *freopen(), *popen(); +extern long ftell(); +extern setbuf(), rewind(); +extern char *fgets(), *gets(); diff --git a/include/_tail_cc/sys/dir.h b/include/_tail_cc/sys/dir.h new file mode 100644 index 00000000..256222e0 --- /dev/null +++ b/include/_tail_cc/sys/dir.h @@ -0,0 +1,34 @@ +#ifdef BSD4_2 +#include "/usr/include/sys/dir.h" +#else +#define DIRBLKSIZ 512 +#define MAXNAMLEN 14 +#undef DIRSIZ +#define DIRSIZ(dp) \ + ((sizeof(struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1+3)&~3)) +struct direct { + long d_ino; + short d_reclen; + short d_namlen; + char d_name[MAXNAMLEN+1]; +}; + +struct _dirdesc { + int dd_fd; + long dd_loc; + long dd_size; + char dd_buf[DIRBLKSIZ]; +}; + +typedef struct _dirdesc DIR; + +#ifndef NULL +#define NULL 0 +#endif +extern DIR *opendir(); +extern struct direct *readdir(); +extern long telldir(); +extern seekdir(); +#define rewinddir(dirp) seekdir((dirp), 0L) +extern closedir(); +#endif From adfc562def7e2665914f8ea1db53f84d139e00e7 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 27 Jan 1987 16:44:28 +0000 Subject: [PATCH 0561/1625] Initial revision --- include/_tail_cc/sys/types.h | 28 ++++++++++++++++++++++++++++ include/_tail_mon/sys/types.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 include/_tail_cc/sys/types.h create mode 100644 include/_tail_mon/sys/types.h diff --git a/include/_tail_cc/sys/types.h b/include/_tail_cc/sys/types.h new file mode 100644 index 00000000..c823fc1f --- /dev/null +++ b/include/_tail_cc/sys/types.h @@ -0,0 +1,28 @@ +/* + * Basic system types and major/minor device constructing/busting macros. + */ + +/* major part of a device */ +#define major(x) ((int)(((unsigned)(x)>>8)&0377)) + +/* minor part of a device */ +#define minor(x) ((int)((x)&0377)) + +/* make a device number */ +#define makedev(x,y) ((dev_t)(((x)<<8) | (y))) + +typedef unsigned char u_char; +typedef unsigned short u_short; +typedef unsigned int u_int; +typedef unsigned long u_long; + +typedef struct _physadr { int r[1]; } *physadr; +typedef long daddr_t; +typedef char * caddr_t; +typedef u_short ino_t; +typedef long swblk_t; +typedef long size_t; +typedef long time_t; +typedef long label_t[14]; +typedef short dev_t; +typedef long off_t; diff --git a/include/_tail_mon/sys/types.h b/include/_tail_mon/sys/types.h new file mode 100644 index 00000000..c823fc1f --- /dev/null +++ b/include/_tail_mon/sys/types.h @@ -0,0 +1,28 @@ +/* + * Basic system types and major/minor device constructing/busting macros. + */ + +/* major part of a device */ +#define major(x) ((int)(((unsigned)(x)>>8)&0377)) + +/* minor part of a device */ +#define minor(x) ((int)((x)&0377)) + +/* make a device number */ +#define makedev(x,y) ((dev_t)(((x)<<8) | (y))) + +typedef unsigned char u_char; +typedef unsigned short u_short; +typedef unsigned int u_int; +typedef unsigned long u_long; + +typedef struct _physadr { int r[1]; } *physadr; +typedef long daddr_t; +typedef char * caddr_t; +typedef u_short ino_t; +typedef long swblk_t; +typedef long size_t; +typedef long time_t; +typedef long label_t[14]; +typedef short dev_t; +typedef long off_t; From a5d66b1478dc5720da2ec0ad4d5ef2bc5f8e5e2f Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 27 Jan 1987 16:51:19 +0000 Subject: [PATCH 0562/1625] Added some system V things --- include/_tail_cc/sys/types.h | 8 ++++++++ include/_tail_mon/sys/types.h | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/include/_tail_cc/sys/types.h b/include/_tail_cc/sys/types.h index c823fc1f..a9e8a639 100644 --- a/include/_tail_cc/sys/types.h +++ b/include/_tail_cc/sys/types.h @@ -26,3 +26,11 @@ typedef long time_t; typedef long label_t[14]; typedef short dev_t; typedef long off_t; + +/* system V compatibility: */ +typedef unsigned int uint; +typedef unsigned short ushort; +typedef unsigned char uchar_t; +typedef short cnt_t; +typedef long paddr_t; +typedef long key_t; diff --git a/include/_tail_mon/sys/types.h b/include/_tail_mon/sys/types.h index c823fc1f..a9e8a639 100644 --- a/include/_tail_mon/sys/types.h +++ b/include/_tail_mon/sys/types.h @@ -26,3 +26,11 @@ typedef long time_t; typedef long label_t[14]; typedef short dev_t; typedef long off_t; + +/* system V compatibility: */ +typedef unsigned int uint; +typedef unsigned short ushort; +typedef unsigned char uchar_t; +typedef short cnt_t; +typedef long paddr_t; +typedef long key_t; From 608901719e168c7c54543b5ff9370d64d63ae590 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 27 Jan 1987 20:09:55 +0000 Subject: [PATCH 0563/1625] By default only install tail_cc.1s and tail_cc.2g --- mach/vax4/libcc/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mach/vax4/libcc/Makefile b/mach/vax4/libcc/Makefile index b8100794..cb00adb8 100644 --- a/mach/vax4/libcc/Makefile +++ b/mach/vax4/libcc/Makefile @@ -6,7 +6,7 @@ MON="PREF=mon" "SRC=lang/cem/libcc/mon" LIBM="PREF=m" "SRC=lang/cem/libcc/libm" LIBLN="PREF=ln" "SRC=lang/cem/libcc/libln" -install: cpstdio cpgen cplibm cplibln +install: cpstdio cpgen cpstdio: RANLIB=ranlib ; export RANLIB ;\ @@ -24,7 +24,7 @@ cplibln: RANLIB=ranlib ; export RANLIB ;\ make -f $(MAKEFILE) $(LIBLN) $(MACHDEF) tailcp -cmp: cmpstdio cmpgen cmplib cmplibln +cmp: cmpstdio cmpgen cmpstdio: make -f $(MAKEFILE) $(STDIO) $(MACHDEF) tail From 99723bbacb03c044c9651b9c3547de01d49aa644 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 27 Jan 1987 20:37:46 +0000 Subject: [PATCH 0564/1625] new version for assembler producing .o files --- mach/pmds/libsys/LIST | 2 +- mach/pmds/libsys/Makefile | 33 +++++++++++++++++++++++---------- mach/pmds/libsys/access.s | 9 +++++++-- mach/pmds/libsys/alarm.s | 9 +++++++-- mach/pmds/libsys/cerror.s | 9 +++++++-- mach/pmds/libsys/chmod.s | 9 +++++++-- mach/pmds/libsys/chown.s | 9 +++++++-- mach/pmds/libsys/cleanup.s | 7 ++++++- mach/pmds/libsys/close.s | 9 +++++++-- mach/pmds/libsys/compmodule | 4 ++++ mach/pmds/libsys/creat.s | 9 +++++++-- mach/pmds/libsys/dup.s | 9 +++++++-- mach/pmds/libsys/exec.s | 7 ++++++- mach/pmds/libsys/exit1.s | 7 ++++++- mach/pmds/libsys/exit2.s | 9 +++++++-- mach/pmds/libsys/fork.s | 7 ++++++- mach/pmds/libsys/fstat.s | 9 +++++++-- mach/pmds/libsys/getgid.s | 9 +++++++-- mach/pmds/libsys/getpid.s | 7 ++++++- mach/pmds/libsys/getuid.s | 9 +++++++-- mach/pmds/libsys/gtty.s | 7 ++++++- mach/pmds/libsys/head_em.s | 27 ++++++++++++++++----------- mach/pmds/libsys/ioctl.s | 9 +++++++-- mach/pmds/libsys/kill.s | 9 +++++++-- mach/pmds/libsys/link.s | 7 ++++++- mach/pmds/libsys/lseek.s | 9 +++++++-- mach/pmds/libsys/mknod.s | 9 +++++++-- mach/pmds/libsys/mount.s | 9 +++++++-- mach/pmds/libsys/nice.s | 9 +++++++-- mach/pmds/libsys/open.s | 9 +++++++-- mach/pmds/libsys/pause.s | 7 ++++++- mach/pmds/libsys/pipe.s | 7 ++++++- mach/pmds/libsys/profil.s | 9 +++++++-- mach/pmds/libsys/read.s | 9 +++++++-- mach/pmds/libsys/sbrk.s | 17 +++++++++++------ mach/pmds/libsys/signal.s | 11 ++++++++--- mach/pmds/libsys/stat.s | 7 ++++++- mach/pmds/libsys/stty.s | 7 ++++++- mach/pmds/libsys/time.s | 9 +++++++-- mach/pmds/libsys/unlink.s | 7 ++++++- mach/pmds/libsys/wait.s | 7 ++++++- mach/pmds/libsys/write.s | 9 +++++++-- 42 files changed, 302 insertions(+), 90 deletions(-) create mode 100755 mach/pmds/libsys/compmodule diff --git a/mach/pmds/libsys/LIST b/mach/pmds/libsys/LIST index 5b288000..43cdccb0 100644 --- a/mach/pmds/libsys/LIST +++ b/mach/pmds/libsys/LIST @@ -1,4 +1,4 @@ -tail_mon +libmon_s.a gtty.s stty.s chmod.s diff --git a/mach/pmds/libsys/Makefile b/mach/pmds/libsys/Makefile index d3d832c3..1ae02d21 100644 --- a/mach/pmds/libsys/Makefile +++ b/mach/pmds/libsys/Makefile @@ -1,16 +1,29 @@ -install: - ../../install head_em - ../../install tail_mon +# $Header$ +MACH=pmds +all: libmon_o.a head_em.o -cmp: - -../../compare head_em - -../../compare tail_mon +install: all + ../../install head_em.o head_em + ../../install libmon_o.a tail_mon -clean : + +cmp: all + -../../compare head_em.o head_em + -../../compare libmon_o.a tail_mon + +libmon_o.a: libmon_s.a + ASAR=aal ; export ASAR ;\ + march . libmon_o.a + +head_em.o: head_em.s + $(MACH) -I../../../h -c head_em.s + +clean: + rm -f *.o libmon_o.a opr : - make pr | opr + make pr | opr pr: - @pr `pwd`/head_em - @arch pv tail_mon | pr -h `pwd`/tail_mon + @pr `pwd`/head_em.s + @arch pv libmon_s.a | pr -h `pwd`/libmon_s.a diff --git a/mach/pmds/libsys/access.s b/mach/pmds/libsys/access.s index 24a8235a..b2e4b0fd 100644 --- a/mach/pmds/libsys/access.s +++ b/mach/pmds/libsys/access.s @@ -1,6 +1,11 @@ .define _access +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _access -.text +.sect .text _access: tst.b -40(sp) link a6,#-0 @@ -13,7 +18,7 @@ add.l #8,sp unlk a6 rts __Saccess: trap #0 -.short 0x21 +.data2 0x21 bcc 1f jmp cerror 1: diff --git a/mach/pmds/libsys/alarm.s b/mach/pmds/libsys/alarm.s index 88bcb728..4688339f 100644 --- a/mach/pmds/libsys/alarm.s +++ b/mach/pmds/libsys/alarm.s @@ -1,6 +1,11 @@ .define _alarm +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _alarm -.text +.sect .text _alarm: tst.b -40(sp) link a6,#-0 @@ -11,5 +16,5 @@ add.l #4,sp unlk a6 rts __Salarm: trap #0 -.short 0x1B +.data2 0x1B rts diff --git a/mach/pmds/libsys/cerror.s b/mach/pmds/libsys/cerror.s index d9fff34c..a69e2021 100644 --- a/mach/pmds/libsys/cerror.s +++ b/mach/pmds/libsys/cerror.s @@ -1,9 +1,14 @@ .define cerror +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern cerror cerror: move.l d0,_errno move.l #-1,d0 rts -.bss +.sect .bss _errno: .space 4 -.text +.sect .text diff --git a/mach/pmds/libsys/chmod.s b/mach/pmds/libsys/chmod.s index 3e628769..ba5cae08 100644 --- a/mach/pmds/libsys/chmod.s +++ b/mach/pmds/libsys/chmod.s @@ -1,6 +1,11 @@ .define _chmod +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _chmod -.text +.sect .text _chmod: tst.b -40(sp) link a6,#-0 @@ -13,7 +18,7 @@ add.l #8,sp unlk a6 rts __Schmod: trap #0 -.short 0xF +.data2 0xF bcc 1f jmp cerror 1: diff --git a/mach/pmds/libsys/chown.s b/mach/pmds/libsys/chown.s index 8cd89680..16f602bb 100644 --- a/mach/pmds/libsys/chown.s +++ b/mach/pmds/libsys/chown.s @@ -1,6 +1,11 @@ .define _chown +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _chown -.text +.sect .text _chown: tst.b -40(sp) link a6,#-0 @@ -16,7 +21,7 @@ lea 12(sp),sp unlk a6 rts __Schown: trap #0 -.short 0x10 +.data2 0x10 bcc 1f jmp cerror 1: diff --git a/mach/pmds/libsys/cleanup.s b/mach/pmds/libsys/cleanup.s index ce4a7635..db80fbf1 100644 --- a/mach/pmds/libsys/cleanup.s +++ b/mach/pmds/libsys/cleanup.s @@ -1,5 +1,10 @@ .define __cleanup +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern __cleanup -.text +.sect .text __cleanup: rts diff --git a/mach/pmds/libsys/close.s b/mach/pmds/libsys/close.s index a32ac79c..6432b570 100644 --- a/mach/pmds/libsys/close.s +++ b/mach/pmds/libsys/close.s @@ -1,6 +1,11 @@ .define _close +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _close -.text +.sect .text _close: tst.b -40(sp) link a6,#-0 @@ -12,7 +17,7 @@ add.l #4,sp unlk a6 rts __Sclose: trap #0 -.short 0x6 +.data2 0x6 bcc 1f jmp cerror 1: diff --git a/mach/pmds/libsys/compmodule b/mach/pmds/libsys/compmodule new file mode 100755 index 00000000..38b53355 --- /dev/null +++ b/mach/pmds/libsys/compmodule @@ -0,0 +1,4 @@ +if pmds -c $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 +fi diff --git a/mach/pmds/libsys/creat.s b/mach/pmds/libsys/creat.s index 88df1031..2b1a14b8 100644 --- a/mach/pmds/libsys/creat.s +++ b/mach/pmds/libsys/creat.s @@ -1,6 +1,11 @@ .define _creat +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _creat -.text +.sect .text _creat: tst.b -40(sp) link a6,#-0 @@ -13,7 +18,7 @@ add.l #8,sp unlk a6 rts __Screat: trap #0 -.short 0x8 +.data2 0x8 bcc 1f jmp cerror 1: diff --git a/mach/pmds/libsys/dup.s b/mach/pmds/libsys/dup.s index f189fb53..32583647 100644 --- a/mach/pmds/libsys/dup.s +++ b/mach/pmds/libsys/dup.s @@ -1,7 +1,12 @@ .define _dup .define _dup2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _dup -.text +.sect .text _dup: tst.b -40(sp) link a6,#-0 @@ -29,7 +34,7 @@ rts __Sdup2: or.l #64,4(sp) __Sdup: trap #0 -.short 0x29 +.data2 0x29 bcc 1f jmp cerror 1: diff --git a/mach/pmds/libsys/exec.s b/mach/pmds/libsys/exec.s index 22a8260d..b10f3ead 100644 --- a/mach/pmds/libsys/exec.s +++ b/mach/pmds/libsys/exec.s @@ -1,6 +1,11 @@ .define _execl .define _execve .define _execv +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _execl .extern _execve .extern _execv @@ -14,7 +19,7 @@ _execl: tst.b -48(sp) unlk a6 rts _execve: trap #0 -.short 59 +.data2 59 jmp cerror _execv: tst.b -48(sp) link a6,#0 diff --git a/mach/pmds/libsys/exit1.s b/mach/pmds/libsys/exit1.s index d766750e..d5573381 100644 --- a/mach/pmds/libsys/exit1.s +++ b/mach/pmds/libsys/exit1.s @@ -1,6 +1,11 @@ .define _exit +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _exit -.text +.sect .text _exit: tst.b -40(sp) link a6,#-0 diff --git a/mach/pmds/libsys/exit2.s b/mach/pmds/libsys/exit2.s index ea2bea6f..dec1340b 100644 --- a/mach/pmds/libsys/exit2.s +++ b/mach/pmds/libsys/exit2.s @@ -1,6 +1,11 @@ .define __exit +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern __exit -.text +.sect .text __exit: tst.b -40(sp) link a6,#-0 @@ -12,4 +17,4 @@ add.l #4,sp unlk a6 rts __Sexit: trap #0 -.short 0x1 +.data2 0x1 diff --git a/mach/pmds/libsys/fork.s b/mach/pmds/libsys/fork.s index ca96887d..e9438185 100644 --- a/mach/pmds/libsys/fork.s +++ b/mach/pmds/libsys/fork.s @@ -1,7 +1,12 @@ .define _fork +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _fork _fork: trap #0 -.short 0x2 +.data2 0x2 bra 3f rts 3: diff --git a/mach/pmds/libsys/fstat.s b/mach/pmds/libsys/fstat.s index 3aaee95e..0ba35474 100644 --- a/mach/pmds/libsys/fstat.s +++ b/mach/pmds/libsys/fstat.s @@ -1,6 +1,11 @@ .define _fstat +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _fstat -.text +.sect .text _fstat: tst.b -40(sp) link a6,#-0 @@ -13,7 +18,7 @@ add.l #8,sp unlk a6 rts __Sfstat: trap #0 -.short 0x1C +.data2 0x1C bcc 1f jmp cerror 1: diff --git a/mach/pmds/libsys/getgid.s b/mach/pmds/libsys/getgid.s index 098977ad..9f945f2c 100644 --- a/mach/pmds/libsys/getgid.s +++ b/mach/pmds/libsys/getgid.s @@ -1,12 +1,17 @@ .define _getgid .define _getegid +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _getgid .extern _getegid _getgid: trap #0 -.short 0x2F +.data2 0x2F rts _getegid: trap #0 -.short 0x2F +.data2 0x2F move.l d1,d0 rts diff --git a/mach/pmds/libsys/getpid.s b/mach/pmds/libsys/getpid.s index 75894271..e676b508 100644 --- a/mach/pmds/libsys/getpid.s +++ b/mach/pmds/libsys/getpid.s @@ -1,5 +1,10 @@ .define _getpid +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _getpid _getpid: trap #0 -.short 0x14 +.data2 0x14 rts diff --git a/mach/pmds/libsys/getuid.s b/mach/pmds/libsys/getuid.s index 53f6b0be..487c6fb8 100644 --- a/mach/pmds/libsys/getuid.s +++ b/mach/pmds/libsys/getuid.s @@ -1,12 +1,17 @@ .define _getuid .define _geteuid +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _getuid .extern _geteuid _getuid: trap #0 -.short 0x18 +.data2 0x18 rts _geteuid: trap #0 -.short 0x18 +.data2 0x18 move.l d1,d0 rts diff --git a/mach/pmds/libsys/gtty.s b/mach/pmds/libsys/gtty.s index ee9f096c..50b6e8bf 100644 --- a/mach/pmds/libsys/gtty.s +++ b/mach/pmds/libsys/gtty.s @@ -1,6 +1,11 @@ .define _gtty +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _gtty -.text +.sect .text _gtty: tst.b -40(sp) link a6,#-0 diff --git a/mach/pmds/libsys/head_em.s b/mach/pmds/libsys/head_em.s index 92d4f2e7..6e410b2d 100644 --- a/mach/pmds/libsys/head_em.s +++ b/mach/pmds/libsys/head_em.s @@ -1,12 +1,17 @@ .define CERASE,CKILL,CSTOP,CSTART .define .lino,.filn - .define F_DUM,EXIT - .define begtext,begdata,begbss .define EARRAY,ERANGE,ESET,EIDIVZ,EHEAP,EILLINS,ECASE .define hol0,.reghp,.limhp,.trpim,.trppc .define LINO_AD,FILN_AD +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text + + CERASE = 010 @@ -27,7 +32,7 @@ EHEAP = 17 EILLINS = 18 ECASE = 20 - .text + .sect .text begtext: add.l #2,sp !convert argc from 4-byte to 2-byte pea endbss @@ -37,22 +42,22 @@ begtext: add #010,sp EXIT: - .data + .sect .data begdata: hol0: .lino: - .short 0,0 ! lino + .data2 0,0 ! lino .filn: - .long 0 ! filn + .data4 0 ! filn .reghp: - .long endbss + .data4 endbss .limhp: - .long endbss + .data4 endbss .trppc: - .long 0 + .data4 0 .trpim: - .short 0 + .data2 0 - .bss + .sect .bss begbss: diff --git a/mach/pmds/libsys/ioctl.s b/mach/pmds/libsys/ioctl.s index fea85879..86a784be 100644 --- a/mach/pmds/libsys/ioctl.s +++ b/mach/pmds/libsys/ioctl.s @@ -1,6 +1,11 @@ .define _ioctl +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _ioctl -.text +.sect .text _ioctl: tst.b -40(sp) link a6,#-0 @@ -16,7 +21,7 @@ lea 12(sp),sp unlk a6 rts __Sioctl: trap #0 -.short 0x36 +.data2 0x36 bcc 1f jmp cerror 1: diff --git a/mach/pmds/libsys/kill.s b/mach/pmds/libsys/kill.s index d900ac2b..a880c21e 100644 --- a/mach/pmds/libsys/kill.s +++ b/mach/pmds/libsys/kill.s @@ -1,6 +1,11 @@ .define _kill +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _kill -.text +.sect .text _kill: tst.b -40(sp) link a6,#-0 @@ -15,7 +20,7 @@ add.l #8,sp unlk a6 rts __Skill: trap #0 -.short 0x25 +.data2 0x25 bcc 1f jmp cerror 1: diff --git a/mach/pmds/libsys/link.s b/mach/pmds/libsys/link.s index e1531b95..7a07106a 100644 --- a/mach/pmds/libsys/link.s +++ b/mach/pmds/libsys/link.s @@ -1,7 +1,12 @@ .define _link +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _link _link: trap #0 -.short 0x9 +.data2 0x9 bcc 1f jmp cerror 1: diff --git a/mach/pmds/libsys/lseek.s b/mach/pmds/libsys/lseek.s index 8be8d2bd..c27a93f2 100644 --- a/mach/pmds/libsys/lseek.s +++ b/mach/pmds/libsys/lseek.s @@ -1,6 +1,11 @@ .define _lseek +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _lseek -.text +.sect .text _lseek: tst.b -40(sp) link a6,#-0 @@ -16,7 +21,7 @@ lea 12(sp),sp unlk a6 rts __Slseek: trap #0 -.short 0x13 +.data2 0x13 bcc 1f jmp cerror 1: diff --git a/mach/pmds/libsys/mknod.s b/mach/pmds/libsys/mknod.s index 306035fd..d2f86fe2 100644 --- a/mach/pmds/libsys/mknod.s +++ b/mach/pmds/libsys/mknod.s @@ -1,6 +1,11 @@ .define _mknod +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _mknod -.text +.sect .text _mknod: tst.b -40(sp) link a6,#-0 @@ -16,7 +21,7 @@ lea 12(sp),sp unlk a6 rts __Smknod: trap #0 -.short 0xE +.data2 0xE bcc 1f jmp cerror 1: diff --git a/mach/pmds/libsys/mount.s b/mach/pmds/libsys/mount.s index 84967835..d890ac56 100644 --- a/mach/pmds/libsys/mount.s +++ b/mach/pmds/libsys/mount.s @@ -1,6 +1,11 @@ .define _mount +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _mount -.text +.sect .text _mount: tst.b -40(sp) link a6,#-0 @@ -14,7 +19,7 @@ lea 12(sp),sp unlk a6 rts __Smount: trap #0 -.short 0x15 +.data2 0x15 bcc 1f jmp cerror 1: diff --git a/mach/pmds/libsys/nice.s b/mach/pmds/libsys/nice.s index b264a5d6..6eddc6fa 100644 --- a/mach/pmds/libsys/nice.s +++ b/mach/pmds/libsys/nice.s @@ -1,6 +1,11 @@ .define _nice +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _nice -.text +.sect .text _nice: tst.b -40(sp) link a6,#-0 @@ -12,7 +17,7 @@ add.l #4,sp unlk a6 rts __Snice: trap #0 -.short 0x22 +.data2 0x22 bcc 1f jmp cerror 1: diff --git a/mach/pmds/libsys/open.s b/mach/pmds/libsys/open.s index 6a947622..bb1bd144 100644 --- a/mach/pmds/libsys/open.s +++ b/mach/pmds/libsys/open.s @@ -1,6 +1,11 @@ .define _open +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _open -.text +.sect .text _open: tst.b -40(sp) link a6,#-0 @@ -13,7 +18,7 @@ add.l #8,sp unlk a6 rts __Sopen: trap #0 -.short 0x5 +.data2 0x5 bcc 1f jmp cerror 1: diff --git a/mach/pmds/libsys/pause.s b/mach/pmds/libsys/pause.s index 3ce0e8c9..4db34d46 100644 --- a/mach/pmds/libsys/pause.s +++ b/mach/pmds/libsys/pause.s @@ -1,7 +1,12 @@ .define _pause +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _pause _pause: trap #0 -.short 29 +.data2 29 bcc 1f jmp cerror 1: diff --git a/mach/pmds/libsys/pipe.s b/mach/pmds/libsys/pipe.s index 0b57d35f..8691aa32 100644 --- a/mach/pmds/libsys/pipe.s +++ b/mach/pmds/libsys/pipe.s @@ -1,7 +1,12 @@ .define _pipe +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _pipe _pipe: trap #0 -.short 0x2A +.data2 0x2A bcc 1f jmp cerror 1: diff --git a/mach/pmds/libsys/profil.s b/mach/pmds/libsys/profil.s index 475087c0..054d9b10 100644 --- a/mach/pmds/libsys/profil.s +++ b/mach/pmds/libsys/profil.s @@ -1,6 +1,11 @@ .define _profil +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _profil -.text +.sect .text _profil: tst.b -40(sp) link a6,#-0 @@ -19,5 +24,5 @@ lea 16(sp),sp unlk a6 rts __Sprofil: trap #0 -.short 0x2C +.data2 0x2C rts diff --git a/mach/pmds/libsys/read.s b/mach/pmds/libsys/read.s index ccf421ca..47b3e8ae 100644 --- a/mach/pmds/libsys/read.s +++ b/mach/pmds/libsys/read.s @@ -1,6 +1,11 @@ .define _read +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _read -.text +.sect .text _read: tst.b -40(sp) link a6,#-0 @@ -16,7 +21,7 @@ lea 12(sp),sp unlk a6 rts __Sread: trap #0 -.short 0x3 +.data2 0x3 bcc 1f jmp cerror 1: diff --git a/mach/pmds/libsys/sbrk.s b/mach/pmds/libsys/sbrk.s index 4ec68dce..f9c4d3a7 100644 --- a/mach/pmds/libsys/sbrk.s +++ b/mach/pmds/libsys/sbrk.s @@ -1,7 +1,12 @@ .define _brk .define _sbrk +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _brk -.text +.sect .text _brk: tst.b -40(sp) link a6,#-0 @@ -28,7 +33,7 @@ __Ssbrk: tst.b -8(sp) move.l d0,-(sp) clr.l -(sp) trap #0 -.short 0x11 +.data2 0x11 add.l #8,sp bcc 1f jmp cerror @@ -38,13 +43,13 @@ __Ssbrk: tst.b -8(sp) add.l d1,nd rts __Sbrk: trap #0 -.short 0x11 +.data2 0x11 bcc 1f jmp cerror 1: move.l 4(sp),nd clr.l d0 rts -.data -nd: .long endbss -.text +.sect .data +nd: .data4 endbss +.sect .text diff --git a/mach/pmds/libsys/signal.s b/mach/pmds/libsys/signal.s index d5c86f5d..a091b3fa 100644 --- a/mach/pmds/libsys/signal.s +++ b/mach/pmds/libsys/signal.s @@ -1,4 +1,9 @@ .define _signal +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _signal NSIG=32 _signal: @@ -22,7 +27,7 @@ _signal: move.l d0,-(sp) clr.l -(sp) trap #0 -.short 48 +.data2 48 add.l #12,sp bcs 3f btst #0,d0 @@ -49,6 +54,6 @@ enter: movem.l (sp)+,d0/d1/a0/a1 add.l #4,sp rtr -.bss +.sect .bss dvect: .space 4*NSIG -.text +.sect .text diff --git a/mach/pmds/libsys/stat.s b/mach/pmds/libsys/stat.s index 45dfa755..2d41ec45 100644 --- a/mach/pmds/libsys/stat.s +++ b/mach/pmds/libsys/stat.s @@ -1,7 +1,12 @@ .define _stat +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _stat _stat: trap #0 -.short 0x12 +.data2 0x12 bcc 1f jmp cerror 1: diff --git a/mach/pmds/libsys/stty.s b/mach/pmds/libsys/stty.s index 46a497cd..ddc621c1 100644 --- a/mach/pmds/libsys/stty.s +++ b/mach/pmds/libsys/stty.s @@ -1,6 +1,11 @@ .define _stty +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _stty -.text +.sect .text _stty: tst.b -40(sp) link a6,#-0 diff --git a/mach/pmds/libsys/time.s b/mach/pmds/libsys/time.s index dce23657..a30be11c 100644 --- a/mach/pmds/libsys/time.s +++ b/mach/pmds/libsys/time.s @@ -1,9 +1,14 @@ .define _time .define _ftime +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _time _time: trap #0 -.short 0xD +.data2 0xD tst.l 4(sp) beq 1f move.l 4(sp),a0 @@ -13,7 +18,7 @@ _time: .extern _ftime _ftime: trap #0 -.short 0x23 +.data2 0x23 bcc 1f jmp cerror 1: diff --git a/mach/pmds/libsys/unlink.s b/mach/pmds/libsys/unlink.s index 2093ce74..14fd3b79 100644 --- a/mach/pmds/libsys/unlink.s +++ b/mach/pmds/libsys/unlink.s @@ -1,7 +1,12 @@ .define _unlink +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _unlink _unlink: trap #0 -.short 0xA +.data2 0xA bcc 1f jmp cerror 1: diff --git a/mach/pmds/libsys/wait.s b/mach/pmds/libsys/wait.s index fa84833c..f994c3af 100644 --- a/mach/pmds/libsys/wait.s +++ b/mach/pmds/libsys/wait.s @@ -1,7 +1,12 @@ .define _wait +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _wait _wait: trap #0 -.short 0x7 +.data2 0x7 bcc 1f jmp cerror 1: diff --git a/mach/pmds/libsys/write.s b/mach/pmds/libsys/write.s index 8789104e..c044d2da 100644 --- a/mach/pmds/libsys/write.s +++ b/mach/pmds/libsys/write.s @@ -1,6 +1,11 @@ .define _write +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .extern _write -.text +.sect .text _write: tst.b -40(sp) link a6,#-0 @@ -16,7 +21,7 @@ lea 12(sp),sp unlk a6 rts __Swrite: trap #0 -.short 0x4 +.data2 0x4 bcc 1f jmp cerror 1: From 1ece5220101b4b5b59af87656bd90de26d3ba7bd Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 27 Jan 1987 22:58:33 +0000 Subject: [PATCH 0565/1625] errno was'nt exported --- mach/pmds/libsys/cerror.s | 1 + mach/pmds4/libsys/cerror.s | 1 + 2 files changed, 2 insertions(+) diff --git a/mach/pmds/libsys/cerror.s b/mach/pmds/libsys/cerror.s index a69e2021..944a37e2 100644 --- a/mach/pmds/libsys/cerror.s +++ b/mach/pmds/libsys/cerror.s @@ -1,4 +1,5 @@ .define cerror +.define _errno .sect .text .sect .rom .sect .data diff --git a/mach/pmds4/libsys/cerror.s b/mach/pmds4/libsys/cerror.s index a69e2021..944a37e2 100644 --- a/mach/pmds4/libsys/cerror.s +++ b/mach/pmds4/libsys/cerror.s @@ -1,4 +1,5 @@ .define cerror +.define _errno .sect .text .sect .rom .sect .data From 864d902112d497424248ab4b7dc3c140d43a79c8 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 27 Jan 1987 23:38:02 +0000 Subject: [PATCH 0566/1625] Added action for pc runtime library --- mach/ns/Action | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mach/ns/Action b/mach/ns/Action index 0ba06509..b58ea145 100644 --- a/mach/ns/Action +++ b/mach/ns/Action @@ -1,5 +1,5 @@ name "NS16032 assembler" -dir nas +dir as end name "NS16032 backend" dir cg @@ -13,6 +13,9 @@ end name "NS16032 C libraries" dir libcc end +name "NS16032 PC library" +dir libpc +end name "NS16032 Basic libraries" dir libbc end From 7511caa3dab40873dea622e336bd307b3459ff7d Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 00:11:28 +0000 Subject: [PATCH 0567/1625] floating point constants are no longer fatal --- mach/ns/ncg/mach.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mach/ns/ncg/mach.c b/mach/ns/ncg/mach.c index 1cc07112..0e55a157 100644 --- a/mach/ns/ncg/mach.c +++ b/mach/ns/ncg/mach.c @@ -144,5 +144,14 @@ char *segname[] = { con_float() { - fatal("no reals"); + static int warning_given; + int i; + + if (! warning_given) { + fprintf(stderr, "warning: dummy floating point constant\n"); + warning_given = 1; + } + for (i = argval; i > 0; i -= 4) { + fputs(".data4 0 ! dummy float\n", codefile); + } } From a8f827cab342b14b94a8330a702f62e2f0446c8a Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 12:49:42 +0000 Subject: [PATCH 0568/1625] cc --> $(CC), added -O flag to CFLAGS --- mach/arm/ncg/Makefile | 36 ++++++++++++++++++------------------ mach/i386/ncg/Makefile | 36 ++++++++++++++++++------------------ mach/i80/ncg/Makefile | 36 ++++++++++++++++++------------------ mach/i86/ncg/Makefile | 36 ++++++++++++++++++------------------ mach/m68020/ncg/Makefile | 36 ++++++++++++++++++------------------ mach/m68k2/ncg/Makefile | 36 ++++++++++++++++++------------------ mach/m68k4/ncg/Makefile | 36 ++++++++++++++++++------------------ mach/moon3/ncg/Makefile | 36 ++++++++++++++++++------------------ mach/ns/ncg/Makefile | 36 ++++++++++++++++++------------------ mach/pdp/ncg/Makefile | 36 ++++++++++++++++++------------------ mach/proto/ncg/Makefile | 36 ++++++++++++++++++------------------ 11 files changed, 198 insertions(+), 198 deletions(-) diff --git a/mach/arm/ncg/Makefile b/mach/arm/ncg/Makefile index bc68ab4a..4414dc88 100644 --- a/mach/arm/ncg/Makefile +++ b/mach/arm/ncg/Makefile @@ -8,7 +8,7 @@ CGGFLAGS= PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= -CFLAGS=$(PREFLAGS) $(PFLAGS) +CFLAGS=$(PREFLAGS) $(PFLAGS) -O LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac LIBS=$(EMHOME)/lib/em_data.a @@ -26,41 +26,41 @@ all: make cg cg: tables.o $(OFILES) - cc $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg + $(CC) $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg tables.o: tables.c - cc -c $(PREFLAGS) -I$(CDIR) tables.c + $(CC) -c $(PREFLAGS) -I$(CDIR) tables.c codegen.o: $(CDIR)/codegen.c - cc -c $(CFLAGS) $(CDIR)/codegen.c + $(CC) -c $(CFLAGS) $(CDIR)/codegen.c compute.o: $(CDIR)/compute.c - cc -c $(CFLAGS) $(CDIR)/compute.c + $(CC) -c $(CFLAGS) $(CDIR)/compute.c equiv.o: $(CDIR)/equiv.c - cc -c $(CFLAGS) $(CDIR)/equiv.c + $(CC) -c $(CFLAGS) $(CDIR)/equiv.c fillem.o: $(CDIR)/fillem.c - cc -c $(CFLAGS) $(CDIR)/fillem.c + $(CC) -c $(CFLAGS) $(CDIR)/fillem.c gencode.o: $(CDIR)/gencode.c - cc -c $(CFLAGS) $(CDIR)/gencode.c + $(CC) -c $(CFLAGS) $(CDIR)/gencode.c glosym.o: $(CDIR)/glosym.c - cc -c $(CFLAGS) $(CDIR)/glosym.c + $(CC) -c $(CFLAGS) $(CDIR)/glosym.c main.o: $(CDIR)/main.c - cc -c $(CFLAGS) $(CDIR)/main.c + $(CC) -c $(CFLAGS) $(CDIR)/main.c move.o: $(CDIR)/move.c - cc -c $(CFLAGS) $(CDIR)/move.c + $(CC) -c $(CFLAGS) $(CDIR)/move.c nextem.o: $(CDIR)/nextem.c - cc -c $(CFLAGS) $(CDIR)/nextem.c + $(CC) -c $(CFLAGS) $(CDIR)/nextem.c reg.o: $(CDIR)/reg.c - cc -c $(CFLAGS) $(CDIR)/reg.c + $(CC) -c $(CFLAGS) $(CDIR)/reg.c regvar.o: $(CDIR)/regvar.c - cc -c $(CFLAGS) $(CDIR)/regvar.c + $(CC) -c $(CFLAGS) $(CDIR)/regvar.c salloc.o: $(CDIR)/salloc.c - cc -c $(CFLAGS) $(CDIR)/salloc.c + $(CC) -c $(CFLAGS) $(CDIR)/salloc.c state.o: $(CDIR)/state.c - cc -c $(CFLAGS) $(CDIR)/state.c + $(CC) -c $(CFLAGS) $(CDIR)/state.c subr.o: $(CDIR)/subr.c - cc -c $(CFLAGS) $(CDIR)/subr.c + $(CC) -c $(CFLAGS) $(CDIR)/subr.c var.o: $(CDIR)/var.c - cc -c $(CFLAGS) $(CDIR)/var.c + $(CC) -c $(CFLAGS) $(CDIR)/var.c install: all $(EMHOME)/mach/install cg diff --git a/mach/i386/ncg/Makefile b/mach/i386/ncg/Makefile index bc68ab4a..4414dc88 100644 --- a/mach/i386/ncg/Makefile +++ b/mach/i386/ncg/Makefile @@ -8,7 +8,7 @@ CGGFLAGS= PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= -CFLAGS=$(PREFLAGS) $(PFLAGS) +CFLAGS=$(PREFLAGS) $(PFLAGS) -O LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac LIBS=$(EMHOME)/lib/em_data.a @@ -26,41 +26,41 @@ all: make cg cg: tables.o $(OFILES) - cc $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg + $(CC) $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg tables.o: tables.c - cc -c $(PREFLAGS) -I$(CDIR) tables.c + $(CC) -c $(PREFLAGS) -I$(CDIR) tables.c codegen.o: $(CDIR)/codegen.c - cc -c $(CFLAGS) $(CDIR)/codegen.c + $(CC) -c $(CFLAGS) $(CDIR)/codegen.c compute.o: $(CDIR)/compute.c - cc -c $(CFLAGS) $(CDIR)/compute.c + $(CC) -c $(CFLAGS) $(CDIR)/compute.c equiv.o: $(CDIR)/equiv.c - cc -c $(CFLAGS) $(CDIR)/equiv.c + $(CC) -c $(CFLAGS) $(CDIR)/equiv.c fillem.o: $(CDIR)/fillem.c - cc -c $(CFLAGS) $(CDIR)/fillem.c + $(CC) -c $(CFLAGS) $(CDIR)/fillem.c gencode.o: $(CDIR)/gencode.c - cc -c $(CFLAGS) $(CDIR)/gencode.c + $(CC) -c $(CFLAGS) $(CDIR)/gencode.c glosym.o: $(CDIR)/glosym.c - cc -c $(CFLAGS) $(CDIR)/glosym.c + $(CC) -c $(CFLAGS) $(CDIR)/glosym.c main.o: $(CDIR)/main.c - cc -c $(CFLAGS) $(CDIR)/main.c + $(CC) -c $(CFLAGS) $(CDIR)/main.c move.o: $(CDIR)/move.c - cc -c $(CFLAGS) $(CDIR)/move.c + $(CC) -c $(CFLAGS) $(CDIR)/move.c nextem.o: $(CDIR)/nextem.c - cc -c $(CFLAGS) $(CDIR)/nextem.c + $(CC) -c $(CFLAGS) $(CDIR)/nextem.c reg.o: $(CDIR)/reg.c - cc -c $(CFLAGS) $(CDIR)/reg.c + $(CC) -c $(CFLAGS) $(CDIR)/reg.c regvar.o: $(CDIR)/regvar.c - cc -c $(CFLAGS) $(CDIR)/regvar.c + $(CC) -c $(CFLAGS) $(CDIR)/regvar.c salloc.o: $(CDIR)/salloc.c - cc -c $(CFLAGS) $(CDIR)/salloc.c + $(CC) -c $(CFLAGS) $(CDIR)/salloc.c state.o: $(CDIR)/state.c - cc -c $(CFLAGS) $(CDIR)/state.c + $(CC) -c $(CFLAGS) $(CDIR)/state.c subr.o: $(CDIR)/subr.c - cc -c $(CFLAGS) $(CDIR)/subr.c + $(CC) -c $(CFLAGS) $(CDIR)/subr.c var.o: $(CDIR)/var.c - cc -c $(CFLAGS) $(CDIR)/var.c + $(CC) -c $(CFLAGS) $(CDIR)/var.c install: all $(EMHOME)/mach/install cg diff --git a/mach/i80/ncg/Makefile b/mach/i80/ncg/Makefile index bc68ab4a..4414dc88 100644 --- a/mach/i80/ncg/Makefile +++ b/mach/i80/ncg/Makefile @@ -8,7 +8,7 @@ CGGFLAGS= PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= -CFLAGS=$(PREFLAGS) $(PFLAGS) +CFLAGS=$(PREFLAGS) $(PFLAGS) -O LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac LIBS=$(EMHOME)/lib/em_data.a @@ -26,41 +26,41 @@ all: make cg cg: tables.o $(OFILES) - cc $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg + $(CC) $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg tables.o: tables.c - cc -c $(PREFLAGS) -I$(CDIR) tables.c + $(CC) -c $(PREFLAGS) -I$(CDIR) tables.c codegen.o: $(CDIR)/codegen.c - cc -c $(CFLAGS) $(CDIR)/codegen.c + $(CC) -c $(CFLAGS) $(CDIR)/codegen.c compute.o: $(CDIR)/compute.c - cc -c $(CFLAGS) $(CDIR)/compute.c + $(CC) -c $(CFLAGS) $(CDIR)/compute.c equiv.o: $(CDIR)/equiv.c - cc -c $(CFLAGS) $(CDIR)/equiv.c + $(CC) -c $(CFLAGS) $(CDIR)/equiv.c fillem.o: $(CDIR)/fillem.c - cc -c $(CFLAGS) $(CDIR)/fillem.c + $(CC) -c $(CFLAGS) $(CDIR)/fillem.c gencode.o: $(CDIR)/gencode.c - cc -c $(CFLAGS) $(CDIR)/gencode.c + $(CC) -c $(CFLAGS) $(CDIR)/gencode.c glosym.o: $(CDIR)/glosym.c - cc -c $(CFLAGS) $(CDIR)/glosym.c + $(CC) -c $(CFLAGS) $(CDIR)/glosym.c main.o: $(CDIR)/main.c - cc -c $(CFLAGS) $(CDIR)/main.c + $(CC) -c $(CFLAGS) $(CDIR)/main.c move.o: $(CDIR)/move.c - cc -c $(CFLAGS) $(CDIR)/move.c + $(CC) -c $(CFLAGS) $(CDIR)/move.c nextem.o: $(CDIR)/nextem.c - cc -c $(CFLAGS) $(CDIR)/nextem.c + $(CC) -c $(CFLAGS) $(CDIR)/nextem.c reg.o: $(CDIR)/reg.c - cc -c $(CFLAGS) $(CDIR)/reg.c + $(CC) -c $(CFLAGS) $(CDIR)/reg.c regvar.o: $(CDIR)/regvar.c - cc -c $(CFLAGS) $(CDIR)/regvar.c + $(CC) -c $(CFLAGS) $(CDIR)/regvar.c salloc.o: $(CDIR)/salloc.c - cc -c $(CFLAGS) $(CDIR)/salloc.c + $(CC) -c $(CFLAGS) $(CDIR)/salloc.c state.o: $(CDIR)/state.c - cc -c $(CFLAGS) $(CDIR)/state.c + $(CC) -c $(CFLAGS) $(CDIR)/state.c subr.o: $(CDIR)/subr.c - cc -c $(CFLAGS) $(CDIR)/subr.c + $(CC) -c $(CFLAGS) $(CDIR)/subr.c var.o: $(CDIR)/var.c - cc -c $(CFLAGS) $(CDIR)/var.c + $(CC) -c $(CFLAGS) $(CDIR)/var.c install: all $(EMHOME)/mach/install cg diff --git a/mach/i86/ncg/Makefile b/mach/i86/ncg/Makefile index bc68ab4a..4414dc88 100644 --- a/mach/i86/ncg/Makefile +++ b/mach/i86/ncg/Makefile @@ -8,7 +8,7 @@ CGGFLAGS= PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= -CFLAGS=$(PREFLAGS) $(PFLAGS) +CFLAGS=$(PREFLAGS) $(PFLAGS) -O LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac LIBS=$(EMHOME)/lib/em_data.a @@ -26,41 +26,41 @@ all: make cg cg: tables.o $(OFILES) - cc $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg + $(CC) $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg tables.o: tables.c - cc -c $(PREFLAGS) -I$(CDIR) tables.c + $(CC) -c $(PREFLAGS) -I$(CDIR) tables.c codegen.o: $(CDIR)/codegen.c - cc -c $(CFLAGS) $(CDIR)/codegen.c + $(CC) -c $(CFLAGS) $(CDIR)/codegen.c compute.o: $(CDIR)/compute.c - cc -c $(CFLAGS) $(CDIR)/compute.c + $(CC) -c $(CFLAGS) $(CDIR)/compute.c equiv.o: $(CDIR)/equiv.c - cc -c $(CFLAGS) $(CDIR)/equiv.c + $(CC) -c $(CFLAGS) $(CDIR)/equiv.c fillem.o: $(CDIR)/fillem.c - cc -c $(CFLAGS) $(CDIR)/fillem.c + $(CC) -c $(CFLAGS) $(CDIR)/fillem.c gencode.o: $(CDIR)/gencode.c - cc -c $(CFLAGS) $(CDIR)/gencode.c + $(CC) -c $(CFLAGS) $(CDIR)/gencode.c glosym.o: $(CDIR)/glosym.c - cc -c $(CFLAGS) $(CDIR)/glosym.c + $(CC) -c $(CFLAGS) $(CDIR)/glosym.c main.o: $(CDIR)/main.c - cc -c $(CFLAGS) $(CDIR)/main.c + $(CC) -c $(CFLAGS) $(CDIR)/main.c move.o: $(CDIR)/move.c - cc -c $(CFLAGS) $(CDIR)/move.c + $(CC) -c $(CFLAGS) $(CDIR)/move.c nextem.o: $(CDIR)/nextem.c - cc -c $(CFLAGS) $(CDIR)/nextem.c + $(CC) -c $(CFLAGS) $(CDIR)/nextem.c reg.o: $(CDIR)/reg.c - cc -c $(CFLAGS) $(CDIR)/reg.c + $(CC) -c $(CFLAGS) $(CDIR)/reg.c regvar.o: $(CDIR)/regvar.c - cc -c $(CFLAGS) $(CDIR)/regvar.c + $(CC) -c $(CFLAGS) $(CDIR)/regvar.c salloc.o: $(CDIR)/salloc.c - cc -c $(CFLAGS) $(CDIR)/salloc.c + $(CC) -c $(CFLAGS) $(CDIR)/salloc.c state.o: $(CDIR)/state.c - cc -c $(CFLAGS) $(CDIR)/state.c + $(CC) -c $(CFLAGS) $(CDIR)/state.c subr.o: $(CDIR)/subr.c - cc -c $(CFLAGS) $(CDIR)/subr.c + $(CC) -c $(CFLAGS) $(CDIR)/subr.c var.o: $(CDIR)/var.c - cc -c $(CFLAGS) $(CDIR)/var.c + $(CC) -c $(CFLAGS) $(CDIR)/var.c install: all $(EMHOME)/mach/install cg diff --git a/mach/m68020/ncg/Makefile b/mach/m68020/ncg/Makefile index bc68ab4a..4414dc88 100644 --- a/mach/m68020/ncg/Makefile +++ b/mach/m68020/ncg/Makefile @@ -8,7 +8,7 @@ CGGFLAGS= PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= -CFLAGS=$(PREFLAGS) $(PFLAGS) +CFLAGS=$(PREFLAGS) $(PFLAGS) -O LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac LIBS=$(EMHOME)/lib/em_data.a @@ -26,41 +26,41 @@ all: make cg cg: tables.o $(OFILES) - cc $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg + $(CC) $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg tables.o: tables.c - cc -c $(PREFLAGS) -I$(CDIR) tables.c + $(CC) -c $(PREFLAGS) -I$(CDIR) tables.c codegen.o: $(CDIR)/codegen.c - cc -c $(CFLAGS) $(CDIR)/codegen.c + $(CC) -c $(CFLAGS) $(CDIR)/codegen.c compute.o: $(CDIR)/compute.c - cc -c $(CFLAGS) $(CDIR)/compute.c + $(CC) -c $(CFLAGS) $(CDIR)/compute.c equiv.o: $(CDIR)/equiv.c - cc -c $(CFLAGS) $(CDIR)/equiv.c + $(CC) -c $(CFLAGS) $(CDIR)/equiv.c fillem.o: $(CDIR)/fillem.c - cc -c $(CFLAGS) $(CDIR)/fillem.c + $(CC) -c $(CFLAGS) $(CDIR)/fillem.c gencode.o: $(CDIR)/gencode.c - cc -c $(CFLAGS) $(CDIR)/gencode.c + $(CC) -c $(CFLAGS) $(CDIR)/gencode.c glosym.o: $(CDIR)/glosym.c - cc -c $(CFLAGS) $(CDIR)/glosym.c + $(CC) -c $(CFLAGS) $(CDIR)/glosym.c main.o: $(CDIR)/main.c - cc -c $(CFLAGS) $(CDIR)/main.c + $(CC) -c $(CFLAGS) $(CDIR)/main.c move.o: $(CDIR)/move.c - cc -c $(CFLAGS) $(CDIR)/move.c + $(CC) -c $(CFLAGS) $(CDIR)/move.c nextem.o: $(CDIR)/nextem.c - cc -c $(CFLAGS) $(CDIR)/nextem.c + $(CC) -c $(CFLAGS) $(CDIR)/nextem.c reg.o: $(CDIR)/reg.c - cc -c $(CFLAGS) $(CDIR)/reg.c + $(CC) -c $(CFLAGS) $(CDIR)/reg.c regvar.o: $(CDIR)/regvar.c - cc -c $(CFLAGS) $(CDIR)/regvar.c + $(CC) -c $(CFLAGS) $(CDIR)/regvar.c salloc.o: $(CDIR)/salloc.c - cc -c $(CFLAGS) $(CDIR)/salloc.c + $(CC) -c $(CFLAGS) $(CDIR)/salloc.c state.o: $(CDIR)/state.c - cc -c $(CFLAGS) $(CDIR)/state.c + $(CC) -c $(CFLAGS) $(CDIR)/state.c subr.o: $(CDIR)/subr.c - cc -c $(CFLAGS) $(CDIR)/subr.c + $(CC) -c $(CFLAGS) $(CDIR)/subr.c var.o: $(CDIR)/var.c - cc -c $(CFLAGS) $(CDIR)/var.c + $(CC) -c $(CFLAGS) $(CDIR)/var.c install: all $(EMHOME)/mach/install cg diff --git a/mach/m68k2/ncg/Makefile b/mach/m68k2/ncg/Makefile index bc68ab4a..4414dc88 100644 --- a/mach/m68k2/ncg/Makefile +++ b/mach/m68k2/ncg/Makefile @@ -8,7 +8,7 @@ CGGFLAGS= PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= -CFLAGS=$(PREFLAGS) $(PFLAGS) +CFLAGS=$(PREFLAGS) $(PFLAGS) -O LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac LIBS=$(EMHOME)/lib/em_data.a @@ -26,41 +26,41 @@ all: make cg cg: tables.o $(OFILES) - cc $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg + $(CC) $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg tables.o: tables.c - cc -c $(PREFLAGS) -I$(CDIR) tables.c + $(CC) -c $(PREFLAGS) -I$(CDIR) tables.c codegen.o: $(CDIR)/codegen.c - cc -c $(CFLAGS) $(CDIR)/codegen.c + $(CC) -c $(CFLAGS) $(CDIR)/codegen.c compute.o: $(CDIR)/compute.c - cc -c $(CFLAGS) $(CDIR)/compute.c + $(CC) -c $(CFLAGS) $(CDIR)/compute.c equiv.o: $(CDIR)/equiv.c - cc -c $(CFLAGS) $(CDIR)/equiv.c + $(CC) -c $(CFLAGS) $(CDIR)/equiv.c fillem.o: $(CDIR)/fillem.c - cc -c $(CFLAGS) $(CDIR)/fillem.c + $(CC) -c $(CFLAGS) $(CDIR)/fillem.c gencode.o: $(CDIR)/gencode.c - cc -c $(CFLAGS) $(CDIR)/gencode.c + $(CC) -c $(CFLAGS) $(CDIR)/gencode.c glosym.o: $(CDIR)/glosym.c - cc -c $(CFLAGS) $(CDIR)/glosym.c + $(CC) -c $(CFLAGS) $(CDIR)/glosym.c main.o: $(CDIR)/main.c - cc -c $(CFLAGS) $(CDIR)/main.c + $(CC) -c $(CFLAGS) $(CDIR)/main.c move.o: $(CDIR)/move.c - cc -c $(CFLAGS) $(CDIR)/move.c + $(CC) -c $(CFLAGS) $(CDIR)/move.c nextem.o: $(CDIR)/nextem.c - cc -c $(CFLAGS) $(CDIR)/nextem.c + $(CC) -c $(CFLAGS) $(CDIR)/nextem.c reg.o: $(CDIR)/reg.c - cc -c $(CFLAGS) $(CDIR)/reg.c + $(CC) -c $(CFLAGS) $(CDIR)/reg.c regvar.o: $(CDIR)/regvar.c - cc -c $(CFLAGS) $(CDIR)/regvar.c + $(CC) -c $(CFLAGS) $(CDIR)/regvar.c salloc.o: $(CDIR)/salloc.c - cc -c $(CFLAGS) $(CDIR)/salloc.c + $(CC) -c $(CFLAGS) $(CDIR)/salloc.c state.o: $(CDIR)/state.c - cc -c $(CFLAGS) $(CDIR)/state.c + $(CC) -c $(CFLAGS) $(CDIR)/state.c subr.o: $(CDIR)/subr.c - cc -c $(CFLAGS) $(CDIR)/subr.c + $(CC) -c $(CFLAGS) $(CDIR)/subr.c var.o: $(CDIR)/var.c - cc -c $(CFLAGS) $(CDIR)/var.c + $(CC) -c $(CFLAGS) $(CDIR)/var.c install: all $(EMHOME)/mach/install cg diff --git a/mach/m68k4/ncg/Makefile b/mach/m68k4/ncg/Makefile index bc68ab4a..4414dc88 100644 --- a/mach/m68k4/ncg/Makefile +++ b/mach/m68k4/ncg/Makefile @@ -8,7 +8,7 @@ CGGFLAGS= PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= -CFLAGS=$(PREFLAGS) $(PFLAGS) +CFLAGS=$(PREFLAGS) $(PFLAGS) -O LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac LIBS=$(EMHOME)/lib/em_data.a @@ -26,41 +26,41 @@ all: make cg cg: tables.o $(OFILES) - cc $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg + $(CC) $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg tables.o: tables.c - cc -c $(PREFLAGS) -I$(CDIR) tables.c + $(CC) -c $(PREFLAGS) -I$(CDIR) tables.c codegen.o: $(CDIR)/codegen.c - cc -c $(CFLAGS) $(CDIR)/codegen.c + $(CC) -c $(CFLAGS) $(CDIR)/codegen.c compute.o: $(CDIR)/compute.c - cc -c $(CFLAGS) $(CDIR)/compute.c + $(CC) -c $(CFLAGS) $(CDIR)/compute.c equiv.o: $(CDIR)/equiv.c - cc -c $(CFLAGS) $(CDIR)/equiv.c + $(CC) -c $(CFLAGS) $(CDIR)/equiv.c fillem.o: $(CDIR)/fillem.c - cc -c $(CFLAGS) $(CDIR)/fillem.c + $(CC) -c $(CFLAGS) $(CDIR)/fillem.c gencode.o: $(CDIR)/gencode.c - cc -c $(CFLAGS) $(CDIR)/gencode.c + $(CC) -c $(CFLAGS) $(CDIR)/gencode.c glosym.o: $(CDIR)/glosym.c - cc -c $(CFLAGS) $(CDIR)/glosym.c + $(CC) -c $(CFLAGS) $(CDIR)/glosym.c main.o: $(CDIR)/main.c - cc -c $(CFLAGS) $(CDIR)/main.c + $(CC) -c $(CFLAGS) $(CDIR)/main.c move.o: $(CDIR)/move.c - cc -c $(CFLAGS) $(CDIR)/move.c + $(CC) -c $(CFLAGS) $(CDIR)/move.c nextem.o: $(CDIR)/nextem.c - cc -c $(CFLAGS) $(CDIR)/nextem.c + $(CC) -c $(CFLAGS) $(CDIR)/nextem.c reg.o: $(CDIR)/reg.c - cc -c $(CFLAGS) $(CDIR)/reg.c + $(CC) -c $(CFLAGS) $(CDIR)/reg.c regvar.o: $(CDIR)/regvar.c - cc -c $(CFLAGS) $(CDIR)/regvar.c + $(CC) -c $(CFLAGS) $(CDIR)/regvar.c salloc.o: $(CDIR)/salloc.c - cc -c $(CFLAGS) $(CDIR)/salloc.c + $(CC) -c $(CFLAGS) $(CDIR)/salloc.c state.o: $(CDIR)/state.c - cc -c $(CFLAGS) $(CDIR)/state.c + $(CC) -c $(CFLAGS) $(CDIR)/state.c subr.o: $(CDIR)/subr.c - cc -c $(CFLAGS) $(CDIR)/subr.c + $(CC) -c $(CFLAGS) $(CDIR)/subr.c var.o: $(CDIR)/var.c - cc -c $(CFLAGS) $(CDIR)/var.c + $(CC) -c $(CFLAGS) $(CDIR)/var.c install: all $(EMHOME)/mach/install cg diff --git a/mach/moon3/ncg/Makefile b/mach/moon3/ncg/Makefile index bc68ab4a..4414dc88 100644 --- a/mach/moon3/ncg/Makefile +++ b/mach/moon3/ncg/Makefile @@ -8,7 +8,7 @@ CGGFLAGS= PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= -CFLAGS=$(PREFLAGS) $(PFLAGS) +CFLAGS=$(PREFLAGS) $(PFLAGS) -O LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac LIBS=$(EMHOME)/lib/em_data.a @@ -26,41 +26,41 @@ all: make cg cg: tables.o $(OFILES) - cc $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg + $(CC) $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg tables.o: tables.c - cc -c $(PREFLAGS) -I$(CDIR) tables.c + $(CC) -c $(PREFLAGS) -I$(CDIR) tables.c codegen.o: $(CDIR)/codegen.c - cc -c $(CFLAGS) $(CDIR)/codegen.c + $(CC) -c $(CFLAGS) $(CDIR)/codegen.c compute.o: $(CDIR)/compute.c - cc -c $(CFLAGS) $(CDIR)/compute.c + $(CC) -c $(CFLAGS) $(CDIR)/compute.c equiv.o: $(CDIR)/equiv.c - cc -c $(CFLAGS) $(CDIR)/equiv.c + $(CC) -c $(CFLAGS) $(CDIR)/equiv.c fillem.o: $(CDIR)/fillem.c - cc -c $(CFLAGS) $(CDIR)/fillem.c + $(CC) -c $(CFLAGS) $(CDIR)/fillem.c gencode.o: $(CDIR)/gencode.c - cc -c $(CFLAGS) $(CDIR)/gencode.c + $(CC) -c $(CFLAGS) $(CDIR)/gencode.c glosym.o: $(CDIR)/glosym.c - cc -c $(CFLAGS) $(CDIR)/glosym.c + $(CC) -c $(CFLAGS) $(CDIR)/glosym.c main.o: $(CDIR)/main.c - cc -c $(CFLAGS) $(CDIR)/main.c + $(CC) -c $(CFLAGS) $(CDIR)/main.c move.o: $(CDIR)/move.c - cc -c $(CFLAGS) $(CDIR)/move.c + $(CC) -c $(CFLAGS) $(CDIR)/move.c nextem.o: $(CDIR)/nextem.c - cc -c $(CFLAGS) $(CDIR)/nextem.c + $(CC) -c $(CFLAGS) $(CDIR)/nextem.c reg.o: $(CDIR)/reg.c - cc -c $(CFLAGS) $(CDIR)/reg.c + $(CC) -c $(CFLAGS) $(CDIR)/reg.c regvar.o: $(CDIR)/regvar.c - cc -c $(CFLAGS) $(CDIR)/regvar.c + $(CC) -c $(CFLAGS) $(CDIR)/regvar.c salloc.o: $(CDIR)/salloc.c - cc -c $(CFLAGS) $(CDIR)/salloc.c + $(CC) -c $(CFLAGS) $(CDIR)/salloc.c state.o: $(CDIR)/state.c - cc -c $(CFLAGS) $(CDIR)/state.c + $(CC) -c $(CFLAGS) $(CDIR)/state.c subr.o: $(CDIR)/subr.c - cc -c $(CFLAGS) $(CDIR)/subr.c + $(CC) -c $(CFLAGS) $(CDIR)/subr.c var.o: $(CDIR)/var.c - cc -c $(CFLAGS) $(CDIR)/var.c + $(CC) -c $(CFLAGS) $(CDIR)/var.c install: all $(EMHOME)/mach/install cg diff --git a/mach/ns/ncg/Makefile b/mach/ns/ncg/Makefile index bc68ab4a..4414dc88 100644 --- a/mach/ns/ncg/Makefile +++ b/mach/ns/ncg/Makefile @@ -8,7 +8,7 @@ CGGFLAGS= PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= -CFLAGS=$(PREFLAGS) $(PFLAGS) +CFLAGS=$(PREFLAGS) $(PFLAGS) -O LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac LIBS=$(EMHOME)/lib/em_data.a @@ -26,41 +26,41 @@ all: make cg cg: tables.o $(OFILES) - cc $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg + $(CC) $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg tables.o: tables.c - cc -c $(PREFLAGS) -I$(CDIR) tables.c + $(CC) -c $(PREFLAGS) -I$(CDIR) tables.c codegen.o: $(CDIR)/codegen.c - cc -c $(CFLAGS) $(CDIR)/codegen.c + $(CC) -c $(CFLAGS) $(CDIR)/codegen.c compute.o: $(CDIR)/compute.c - cc -c $(CFLAGS) $(CDIR)/compute.c + $(CC) -c $(CFLAGS) $(CDIR)/compute.c equiv.o: $(CDIR)/equiv.c - cc -c $(CFLAGS) $(CDIR)/equiv.c + $(CC) -c $(CFLAGS) $(CDIR)/equiv.c fillem.o: $(CDIR)/fillem.c - cc -c $(CFLAGS) $(CDIR)/fillem.c + $(CC) -c $(CFLAGS) $(CDIR)/fillem.c gencode.o: $(CDIR)/gencode.c - cc -c $(CFLAGS) $(CDIR)/gencode.c + $(CC) -c $(CFLAGS) $(CDIR)/gencode.c glosym.o: $(CDIR)/glosym.c - cc -c $(CFLAGS) $(CDIR)/glosym.c + $(CC) -c $(CFLAGS) $(CDIR)/glosym.c main.o: $(CDIR)/main.c - cc -c $(CFLAGS) $(CDIR)/main.c + $(CC) -c $(CFLAGS) $(CDIR)/main.c move.o: $(CDIR)/move.c - cc -c $(CFLAGS) $(CDIR)/move.c + $(CC) -c $(CFLAGS) $(CDIR)/move.c nextem.o: $(CDIR)/nextem.c - cc -c $(CFLAGS) $(CDIR)/nextem.c + $(CC) -c $(CFLAGS) $(CDIR)/nextem.c reg.o: $(CDIR)/reg.c - cc -c $(CFLAGS) $(CDIR)/reg.c + $(CC) -c $(CFLAGS) $(CDIR)/reg.c regvar.o: $(CDIR)/regvar.c - cc -c $(CFLAGS) $(CDIR)/regvar.c + $(CC) -c $(CFLAGS) $(CDIR)/regvar.c salloc.o: $(CDIR)/salloc.c - cc -c $(CFLAGS) $(CDIR)/salloc.c + $(CC) -c $(CFLAGS) $(CDIR)/salloc.c state.o: $(CDIR)/state.c - cc -c $(CFLAGS) $(CDIR)/state.c + $(CC) -c $(CFLAGS) $(CDIR)/state.c subr.o: $(CDIR)/subr.c - cc -c $(CFLAGS) $(CDIR)/subr.c + $(CC) -c $(CFLAGS) $(CDIR)/subr.c var.o: $(CDIR)/var.c - cc -c $(CFLAGS) $(CDIR)/var.c + $(CC) -c $(CFLAGS) $(CDIR)/var.c install: all $(EMHOME)/mach/install cg diff --git a/mach/pdp/ncg/Makefile b/mach/pdp/ncg/Makefile index bc68ab4a..4414dc88 100644 --- a/mach/pdp/ncg/Makefile +++ b/mach/pdp/ncg/Makefile @@ -8,7 +8,7 @@ CGGFLAGS= PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= -CFLAGS=$(PREFLAGS) $(PFLAGS) +CFLAGS=$(PREFLAGS) $(PFLAGS) -O LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac LIBS=$(EMHOME)/lib/em_data.a @@ -26,41 +26,41 @@ all: make cg cg: tables.o $(OFILES) - cc $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg + $(CC) $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg tables.o: tables.c - cc -c $(PREFLAGS) -I$(CDIR) tables.c + $(CC) -c $(PREFLAGS) -I$(CDIR) tables.c codegen.o: $(CDIR)/codegen.c - cc -c $(CFLAGS) $(CDIR)/codegen.c + $(CC) -c $(CFLAGS) $(CDIR)/codegen.c compute.o: $(CDIR)/compute.c - cc -c $(CFLAGS) $(CDIR)/compute.c + $(CC) -c $(CFLAGS) $(CDIR)/compute.c equiv.o: $(CDIR)/equiv.c - cc -c $(CFLAGS) $(CDIR)/equiv.c + $(CC) -c $(CFLAGS) $(CDIR)/equiv.c fillem.o: $(CDIR)/fillem.c - cc -c $(CFLAGS) $(CDIR)/fillem.c + $(CC) -c $(CFLAGS) $(CDIR)/fillem.c gencode.o: $(CDIR)/gencode.c - cc -c $(CFLAGS) $(CDIR)/gencode.c + $(CC) -c $(CFLAGS) $(CDIR)/gencode.c glosym.o: $(CDIR)/glosym.c - cc -c $(CFLAGS) $(CDIR)/glosym.c + $(CC) -c $(CFLAGS) $(CDIR)/glosym.c main.o: $(CDIR)/main.c - cc -c $(CFLAGS) $(CDIR)/main.c + $(CC) -c $(CFLAGS) $(CDIR)/main.c move.o: $(CDIR)/move.c - cc -c $(CFLAGS) $(CDIR)/move.c + $(CC) -c $(CFLAGS) $(CDIR)/move.c nextem.o: $(CDIR)/nextem.c - cc -c $(CFLAGS) $(CDIR)/nextem.c + $(CC) -c $(CFLAGS) $(CDIR)/nextem.c reg.o: $(CDIR)/reg.c - cc -c $(CFLAGS) $(CDIR)/reg.c + $(CC) -c $(CFLAGS) $(CDIR)/reg.c regvar.o: $(CDIR)/regvar.c - cc -c $(CFLAGS) $(CDIR)/regvar.c + $(CC) -c $(CFLAGS) $(CDIR)/regvar.c salloc.o: $(CDIR)/salloc.c - cc -c $(CFLAGS) $(CDIR)/salloc.c + $(CC) -c $(CFLAGS) $(CDIR)/salloc.c state.o: $(CDIR)/state.c - cc -c $(CFLAGS) $(CDIR)/state.c + $(CC) -c $(CFLAGS) $(CDIR)/state.c subr.o: $(CDIR)/subr.c - cc -c $(CFLAGS) $(CDIR)/subr.c + $(CC) -c $(CFLAGS) $(CDIR)/subr.c var.o: $(CDIR)/var.c - cc -c $(CFLAGS) $(CDIR)/var.c + $(CC) -c $(CFLAGS) $(CDIR)/var.c install: all $(EMHOME)/mach/install cg diff --git a/mach/proto/ncg/Makefile b/mach/proto/ncg/Makefile index bc68ab4a..4414dc88 100644 --- a/mach/proto/ncg/Makefile +++ b/mach/proto/ncg/Makefile @@ -8,7 +8,7 @@ CGGFLAGS= PREFLAGS=-I$(EMHOME)/h -I. PFLAGS= -CFLAGS=$(PREFLAGS) $(PFLAGS) +CFLAGS=$(PREFLAGS) $(PFLAGS) -O LDFLAGS=-i $(PFLAGS) LINTOPTS=-hbxac LIBS=$(EMHOME)/lib/em_data.a @@ -26,41 +26,41 @@ all: make cg cg: tables.o $(OFILES) - cc $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg + $(CC) $(LDFLAGS) $(OFILES) tables.o $(LIBS) -o cg tables.o: tables.c - cc -c $(PREFLAGS) -I$(CDIR) tables.c + $(CC) -c $(PREFLAGS) -I$(CDIR) tables.c codegen.o: $(CDIR)/codegen.c - cc -c $(CFLAGS) $(CDIR)/codegen.c + $(CC) -c $(CFLAGS) $(CDIR)/codegen.c compute.o: $(CDIR)/compute.c - cc -c $(CFLAGS) $(CDIR)/compute.c + $(CC) -c $(CFLAGS) $(CDIR)/compute.c equiv.o: $(CDIR)/equiv.c - cc -c $(CFLAGS) $(CDIR)/equiv.c + $(CC) -c $(CFLAGS) $(CDIR)/equiv.c fillem.o: $(CDIR)/fillem.c - cc -c $(CFLAGS) $(CDIR)/fillem.c + $(CC) -c $(CFLAGS) $(CDIR)/fillem.c gencode.o: $(CDIR)/gencode.c - cc -c $(CFLAGS) $(CDIR)/gencode.c + $(CC) -c $(CFLAGS) $(CDIR)/gencode.c glosym.o: $(CDIR)/glosym.c - cc -c $(CFLAGS) $(CDIR)/glosym.c + $(CC) -c $(CFLAGS) $(CDIR)/glosym.c main.o: $(CDIR)/main.c - cc -c $(CFLAGS) $(CDIR)/main.c + $(CC) -c $(CFLAGS) $(CDIR)/main.c move.o: $(CDIR)/move.c - cc -c $(CFLAGS) $(CDIR)/move.c + $(CC) -c $(CFLAGS) $(CDIR)/move.c nextem.o: $(CDIR)/nextem.c - cc -c $(CFLAGS) $(CDIR)/nextem.c + $(CC) -c $(CFLAGS) $(CDIR)/nextem.c reg.o: $(CDIR)/reg.c - cc -c $(CFLAGS) $(CDIR)/reg.c + $(CC) -c $(CFLAGS) $(CDIR)/reg.c regvar.o: $(CDIR)/regvar.c - cc -c $(CFLAGS) $(CDIR)/regvar.c + $(CC) -c $(CFLAGS) $(CDIR)/regvar.c salloc.o: $(CDIR)/salloc.c - cc -c $(CFLAGS) $(CDIR)/salloc.c + $(CC) -c $(CFLAGS) $(CDIR)/salloc.c state.o: $(CDIR)/state.c - cc -c $(CFLAGS) $(CDIR)/state.c + $(CC) -c $(CFLAGS) $(CDIR)/state.c subr.o: $(CDIR)/subr.c - cc -c $(CFLAGS) $(CDIR)/subr.c + $(CC) -c $(CFLAGS) $(CDIR)/subr.c var.o: $(CDIR)/var.c - cc -c $(CFLAGS) $(CDIR)/var.c + $(CC) -c $(CFLAGS) $(CDIR)/var.c install: all $(EMHOME)/mach/install cg From 70b121b1758aadbb8b3e00560490c968ee55e663 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 13:00:33 +0000 Subject: [PATCH 0569/1625] Fixed introduced bug --- mach/proto/ncg/gencode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/proto/ncg/gencode.c b/mach/proto/ncg/gencode.c index ca45bc00..7b57d918 100644 --- a/mach/proto/ncg/gencode.c +++ b/mach/proto/ncg/gencode.c @@ -90,7 +90,7 @@ string ad2str(ad) addr_t ad; { else return(mystrcpy(ad.ea_str)); } - sprintf(buf,"%s%c%ld",ad.ea_str,ad.ea_off>=0 ? '+' : '-',(long)ad.ea_off); + sprintf(buf,"%s%c%ld",ad.ea_str,ad.ea_off>=0 ? '+' : ' ',(long)ad.ea_off); return(mystrcpy(buf)); } From 057e137edee7de5a319edff222d139a19f403a7e Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 14:21:56 +0000 Subject: [PATCH 0570/1625] made stdin, stdout, and stderr into compile time constants --- include/_tail_cc/stdio.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/_tail_cc/stdio.h b/include/_tail_cc/stdio.h index e106f191..23bf6acc 100644 --- a/include/_tail_cc/stdio.h +++ b/include/_tail_cc/stdio.h @@ -20,7 +20,7 @@ extern struct _io_buf { int _flags; unsigned char *_buf; unsigned char *_ptr; -} *_io_table[_NFILES]; +} *_io_table[_NFILES], _stdin, _stdout, _stderr; #endif /* FILE */ @@ -28,9 +28,9 @@ extern struct _io_buf { #define FILE struct _io_buf -#define stdin (_io_table[0]) -#define stdout (_io_table[1]) -#define stderr (_io_table[2]) +#define stdin (&_stdin) +#define stdout (&_stdout) +#define stderr (&_stderr) #define getchar() getc(stdin) #define putchar(c) putc(c,stdout) From f6885af31fe99782b30774282a4896c287ea2746 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 14:28:45 +0000 Subject: [PATCH 0571/1625] _doprint -->_doprnt --- lang/cem/libcc/stdio/sprintf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/cem/libcc/stdio/sprintf.c b/lang/cem/libcc/stdio/sprintf.c index 40560b55..a3c52bc5 100644 --- a/lang/cem/libcc/stdio/sprintf.c +++ b/lang/cem/libcc/stdio/sprintf.c @@ -12,7 +12,7 @@ int args; _tempfile._ptr = (unsigned char *) buf; _tempfile._count = 32767; - _doprintf(format, &args, &_tempfile); + _doprnt(format, &args, &_tempfile); putc('\0',&_tempfile); return buf; From 2840140786d5d70f351fe84b1774c160d424dcf3 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 14:38:38 +0000 Subject: [PATCH 0572/1625] bug fix --- lang/cem/libcc/stdio/fflush.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lang/cem/libcc/stdio/fflush.c b/lang/cem/libcc/stdio/fflush.c index 9a271fb9..103ae85e 100644 --- a/lang/cem/libcc/stdio/fflush.c +++ b/lang/cem/libcc/stdio/fflush.c @@ -6,7 +6,9 @@ FILE *iop; { int count, c1; - if ( io_testflag(iop,IO_UNBUFF) || !io_testflag(iop,IO_WRITEMODE) ) + if (!iop->_buf || + io_testflag(iop,IO_UNBUFF) || + !io_testflag(iop,IO_WRITEMODE) ) return(0); count = BUFSIZ - iop->_count; From e8b268a0af67eed34d3d6213c0190bc2bc559820 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 15:03:39 +0000 Subject: [PATCH 0573/1625] adapted to new assembler syntax --- mach/i80/libmon/char.her.s | 5 +++++ mach/i80/libmon/char.nas.s | 5 +++++ mach/i80/libmon/inn2.s | 5 +++++ mach/i80/libmon/mon.s | 5 +++++ mach/i80/libmon/prdec.s | 13 +++++++++---- mach/i80/libmon/prstring.s | 5 +++++ mach/i80/libmon/trp.s | 5 +++++ 7 files changed, 39 insertions(+), 4 deletions(-) diff --git a/mach/i80/libmon/char.her.s b/mach/i80/libmon/char.her.s index c78044b0..2791ae24 100644 --- a/mach/i80/libmon/char.her.s +++ b/mach/i80/libmon/char.her.s @@ -1,4 +1,9 @@ .define getchar, putchar +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! These getchar and putchar routines can be used for HERMAC computer diff --git a/mach/i80/libmon/char.nas.s b/mach/i80/libmon/char.nas.s index 7ac61c23..0604a8dd 100644 --- a/mach/i80/libmon/char.nas.s +++ b/mach/i80/libmon/char.nas.s @@ -1,4 +1,9 @@ .define getchar, putchar +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! These getchar and putchar routines can be used for NASCOM computer. diff --git a/mach/i80/libmon/inn2.s b/mach/i80/libmon/inn2.s index 181b022f..2329a585 100644 --- a/mach/i80/libmon/inn2.s +++ b/mach/i80/libmon/inn2.s @@ -1,4 +1,9 @@ .define .inn2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Bit test on 16 bits set ! Expects on stack: bit number diff --git a/mach/i80/libmon/mon.s b/mach/i80/libmon/mon.s index bdd53170..68b242b1 100644 --- a/mach/i80/libmon/mon.s +++ b/mach/i80/libmon/mon.s @@ -1,4 +1,9 @@ .define .mon +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Monitor call ! Expects on stack: monitor call number diff --git a/mach/i80/libmon/prdec.s b/mach/i80/libmon/prdec.s index e3b32c26..119e595e 100644 --- a/mach/i80/libmon/prdec.s +++ b/mach/i80/libmon/prdec.s @@ -1,4 +1,9 @@ .define prdec +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! print hl-reg as a decimal number. @@ -50,8 +55,8 @@ convert: ret table: - .short 10000 - .short 1000 - .short 100 - .short 10 + .data2 10000 + .data2 1000 + .data2 100 + .data2 10 diff --git a/mach/i80/libmon/prstring.s b/mach/i80/libmon/prstring.s index 5479e0b2..ff5653a5 100644 --- a/mach/i80/libmon/prstring.s +++ b/mach/i80/libmon/prstring.s @@ -1,4 +1,9 @@ .define prstring +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! print a string of characters to the console ! entry: de-reg points to the string diff --git a/mach/i80/libmon/trp.s b/mach/i80/libmon/trp.s index 2665f2cb..647f6360 100644 --- a/mach/i80/libmon/trp.s +++ b/mach/i80/libmon/trp.s @@ -3,6 +3,11 @@ .define efdivz, eiund, efund, econv, estack, eheap, eillins, eoddz .define ecase, ememflt, ebadptr, ebadpc, ebadlae, ebadmon, ebadlin, ebadgto .define eunimpl +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Trap routine ! Expects trap number on stack. From 9016f7a64137bc9b56a683d291912e817103c5c7 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 15:06:01 +0000 Subject: [PATCH 0574/1625] Adapted for new assembler syntax --- mach/i80/libmon/LIST | 3 +-- mach/i80/libmon/Makefile | 35 ++++++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/mach/i80/libmon/LIST b/mach/i80/libmon/LIST index d3e1dc1d..8d90b253 100644 --- a/mach/i80/libmon/LIST +++ b/mach/i80/libmon/LIST @@ -1,8 +1,7 @@ -tail +libsys_s.a mon.s trp.s inn2.s prstring.s prdec.s char.her.s -tail.s diff --git a/mach/i80/libmon/Makefile b/mach/i80/libmon/Makefile index 6dacdfb8..c334b9ba 100644 --- a/mach/i80/libmon/Makefile +++ b/mach/i80/libmon/Makefile @@ -1,16 +1,29 @@ -install: tail - ../../install head.s head_em - ../../install tail tail_sys +# $Header$ +MACH=i80 +all: libsys_o.a head_em.o -cmp: tail - -../../compare head.s head_em - -../../compare tail tail_sys +install: all + ../../install head_em.o head_em + ../../install libsys_o.a tail_sys -tail: - arch cr `cat LIST` -opr: +cmp: all + -../../compare head_em.o head_em + -../../compare libsys_o.a tail_sys + +libsys_o.a: libsys_s.a + ASAR=aal ; export ASAR ;\ + march . libsys_o.a + +head_em.o: head_em.s + $(MACH) -I../../../h -c head_em.s + +clean: + rm -f *.o libsys_o.a + +opr : make pr | opr + pr: - @pr `pwd`/Makefile `pwd`/head.s - @pr -l33 `tail +1 LIST|sort` + @pr `pwd`/head_em.s + @arch pv libsys_s.a | pr -h `pwd`/libsys_s.a From c5a338c87090edc0e30f044f3b40345a7ee99b0a Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 15:06:28 +0000 Subject: [PATCH 0575/1625] Initial revision --- mach/i80/libmon/compmodule | 4 +++ mach/i80/libmon/head_em.s | 53 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100755 mach/i80/libmon/compmodule create mode 100644 mach/i80/libmon/head_em.s diff --git a/mach/i80/libmon/compmodule b/mach/i80/libmon/compmodule new file mode 100755 index 00000000..2e87032c --- /dev/null +++ b/mach/i80/libmon/compmodule @@ -0,0 +1,4 @@ +if i80 -c $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 +fi diff --git a/mach/i80/libmon/head_em.s b/mach/i80/libmon/head_em.s new file mode 100644 index 00000000..b4b3b2d6 --- /dev/null +++ b/mach/i80/libmon/head_em.s @@ -0,0 +1,53 @@ +.define hol0, argv, envp, begbss +.define .ignmask,.reghp,.trapproc,.fra +.define .retadr,.retadr1,.areg,.bcreg,.tmp1 +.define block1, block2, block3 +.define .stop +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text + +.sect .text + lxi h,0x1000 ! stack will grow from 0x1000 downwards + sphl + lxi h,begbss ! clear bss + lxi d,endbss-begbss + mvi c,0 + +2: mov m,c + inx h + dcx d + mov a,e + ora d + jnz 2b + + lxi h,envp ! call main + push h + lxi h,argv + push h + lxi h,0 + push h + call _m_a_i_n +.stop: jmp 0xfb52 + +.sect .bss +begbss: +.trapproc: .space 2 +.ignmask: .space 2 +.sect .data +hol0: .space 8 +.reghp: .data2 endbss +argv: .data2 0 +envp: .data2 0 +.retadr: .space 2 ! used to save return address +.retadr1: .space 2 ! reserve +.bcreg: .space 2 ! used to save localbase +.areg: .space 1 +.tmp1: .space 2 +.fra: .space 8 ! 8 bytes function return area +block1: .space 4 ! used by 32 bits divide and +block2: .space 4 ! multiply routines +block3: .space 4 + From f7b2ba3785a3fb109a7d5e9032b88be0387b391e Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 15:15:28 +0000 Subject: [PATCH 0576/1625] Bug fix --- mach/proto/as/comm6.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mach/proto/as/comm6.c b/mach/proto/as/comm6.c index 7d6f33e0..347f7b92 100644 --- a/mach/proto/as/comm6.c +++ b/mach/proto/as/comm6.c @@ -248,9 +248,11 @@ short s; return; s &= ~S_DOT; assert((s & ~(S_COM|S_VAR|S_TYP)) == 0); +#ifdef ASLD #ifndef THREE_PASS if (s == S_UND) serror("bad relocation"); +#endif #endif /* * always relocation info if S_VAR to solve problems with: From 8e8161302da75e4cfc671ce4c3b9c73f0afaee37 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 15:23:22 +0000 Subject: [PATCH 0577/1625] archive name change: tail --> libem_s.a --- mach/i80/libem/LIST | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/i80/libem/LIST b/mach/i80/libem/LIST index 9e3345cd..9d00eaa9 100644 --- a/mach/i80/libem/LIST +++ b/mach/i80/libem/LIST @@ -1,4 +1,4 @@ -tail +libem_s.a aar2.s adi4.s and.s From 81d22e5f3b840e4040ab48965a5eb469e69850bc Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 15:27:59 +0000 Subject: [PATCH 0578/1625] Adapted to new assembler producing .o files --- mach/i80/libem/Makefile | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/mach/i80/libem/Makefile b/mach/i80/libem/Makefile index 7aef585c..e4ec304d 100644 --- a/mach/i80/libem/Makefile +++ b/mach/i80/libem/Makefile @@ -1,14 +1,29 @@ -install: tail - ../../install tail tail_em +# $Header$ +MACH=i80 +all: libem_o.a end.o -cmp: tail - -../../compare tail tail_em +install: all + ../../install end.o end_em + ../../install libem_o.a tail_em -tail: - arch cr `cat LIST` -opr: +cmp: all + -../../compare end.o end_em + -../../compare libem_o.a tail_em + +libem_o.a: libem_s.a + ASAR=aal ; export ASAR ;\ + march . libem_o.a + +end.o: end.s + $(MACH) -I../../../h -c end.s + +clean: + rm -f *.o libem_o.a + +opr : make pr | opr + pr: - @pr `pwd`/Makefile - @pr -l33 `tail +1 LIST|sort` + @pr `pwd`/end.s + @arch pv libem_s.a | pr -h `pwd`/libem_s.a From 868475b04f301342542b036612d525de7a4031bf Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 15:29:13 +0000 Subject: [PATCH 0579/1625] Initial revision --- mach/i80/libem/compmodule | 4 ++++ 1 file changed, 4 insertions(+) create mode 100755 mach/i80/libem/compmodule diff --git a/mach/i80/libem/compmodule b/mach/i80/libem/compmodule new file mode 100755 index 00000000..2e87032c --- /dev/null +++ b/mach/i80/libem/compmodule @@ -0,0 +1,4 @@ +if i80 -c $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 +fi From ba648025fd9c5f3ce86265e12b679d621e63ea65 Mon Sep 17 00:00:00 2001 From: bruce Date: Wed, 28 Jan 1987 15:39:10 +0000 Subject: [PATCH 0580/1625] Corrected clean option to remove libopt.a --- modules/src/em_opt/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/src/em_opt/Makefile b/modules/src/em_opt/Makefile index 4ba4de94..8a17571e 100644 --- a/modules/src/em_opt/Makefile +++ b/modules/src/em_opt/Makefile @@ -31,7 +31,7 @@ opr: make pr | opr clean: - rm -f $(NOFILES) $(POFILES) $(GENFILES) parser core makerror + rm -f $(NOFILES) $(POFILES) $(GENFILES) parser libopt.a # set HOWMUCH to head -20 to limit number of patterns used #HOWMUCH = head -20 From eaf4aeb78fb75db3b8780423bc4f852db6e9af02 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 16:22:30 +0000 Subject: [PATCH 0581/1625] Avoid bug in VAX assembler. But i don't know what is happening. --- lang/cem/libcc/gen/malloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/cem/libcc/gen/malloc.c b/lang/cem/libcc/gen/malloc.c index aa23cd63..4e7d4dd9 100644 --- a/lang/cem/libcc/gen/malloc.c +++ b/lang/cem/libcc/gen/malloc.c @@ -46,7 +46,7 @@ unsigned size; if ((p = bottom) == 0) { top = bottom = p = sbrk(sizeof(char *)); - NEXT(top) = 0; + NEXT(p) = 0; } while ((next = NEXT(p)) != 0) if ((vir_bytes) next & BUSY) /* already in use */ From e7e899c5284df548898604fdae20ec154d83edde Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 16:52:16 +0000 Subject: [PATCH 0582/1625] Bug fix: %f did not work, if no width was specified --- lang/cem/libcc/stdio/doscan.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lang/cem/libcc/stdio/doscan.c b/lang/cem/libcc/stdio/doscan.c index 2800aa86..77627013 100644 --- a/lang/cem/libcc/stdio/doscan.c +++ b/lang/cem/libcc/stdio/doscan.c @@ -218,6 +218,7 @@ union ptr_union *argp; /* our argument list */ case 'f': { register char *c = buffer; + if (!widflag) width = 127; if (width >= 128) width = 127; if (width && (ic == '+' || ic == '-')) { *c++ = ic; From 2ff11c41664f9497aad46cf62fb95b280eb1f9cc Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 17:02:56 +0000 Subject: [PATCH 0583/1625] declaration of gmtime added --- lang/cem/libcc/gen/localtime.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lang/cem/libcc/gen/localtime.c b/lang/cem/libcc/gen/localtime.c index 8f469d83..b931ee3f 100644 --- a/lang/cem/libcc/gen/localtime.c +++ b/lang/cem/libcc/gen/localtime.c @@ -16,6 +16,8 @@ last_sunday(d, t) return d - (d - first) % 7; } +extern struct tm *gmtime(); + struct tm * localtime(clock) long *clock; From db6bfc5f8a7652183d0c1cdbff8ddc33625ef297 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 17:05:02 +0000 Subject: [PATCH 0584/1625] correction of syntax error --- lang/cem/libcc/gen/memcmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/cem/libcc/gen/memcmp.c b/lang/cem/libcc/gen/memcmp.c index 430bc37c..e3711bbb 100644 --- a/lang/cem/libcc/gen/memcmp.c +++ b/lang/cem/libcc/gen/memcmp.c @@ -4,7 +4,7 @@ register char *s1, *s2; { /* Compare 2 strings. */ - while (n-- > 0) + while (n-- > 0) { if (*s1 != *s2) { return(*s1 - *s2); } From 915e8e65216ae54d30b5eeccc61b3a8587886e6d Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 17:22:25 +0000 Subject: [PATCH 0585/1625] Bug fix: the STR instruction caused a translation with syntax errors --- mach/ns/ncg/table | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mach/ns/ncg/table b/mach/ns/ncg/table index 71f6de5e..5b2080d6 100644 --- a/mach/ns/ncg/table +++ b/mach/ns/ncg/table @@ -235,7 +235,7 @@ jsr tosdst4+label . ret const4:ro . adjspd tossrc4:ro . exit label . -sprd tossrc4:ro, MEMREG:rw . +sprd MEMREG:rw, tossrc4:ro . @@ -2182,12 +2182,12 @@ with src24 gen movw %1, {absolute2, ".ignmask"} pat str $1==0 -with src4 -gen sprd %1, fp +with src4 STACK +gen sprd fp, %1 pat str $1==1 -with src4 -gen sprd %1, sp +with src4 STACK +gen sprd sp, %1 pat str $1==2 with src4 From c555ab4b4e091917e527f00e894424df255537ec Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 17:26:52 +0000 Subject: [PATCH 0586/1625] return exit status 1 when compilation failes --- mach/vax4/libcc/compmodule | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mach/vax4/libcc/compmodule b/mach/vax4/libcc/compmodule index 491f6d25..a794a225 100755 --- a/mach/vax4/libcc/compmodule +++ b/mach/vax4/libcc/compmodule @@ -1,2 +1,4 @@ -${MACH?} -I../../../h ${MACHFL?} $1 1>&2 -echo `basename $1 $2`.o +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 +fi From f35404581b80428e58cf64f8c5f043a1348a09db Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 17:36:21 +0000 Subject: [PATCH 0587/1625] Improvement of conversions --- mach/vax4/cg/table | 33 +-------------------------------- 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/mach/vax4/cg/table b/mach/vax4/cg/table index 2a3044f7..08282b38 100644 --- a/mach/vax4/cg/table +++ b/mach/vax4/cg/table @@ -2105,11 +2105,8 @@ loc loc cii $1==2 && $2==4 | source2or4 | allocate(%[1],REG) "cvtwl\t%[1],%[a]" setcc(%[a]) | %[a] | | -loc loc cii $1==2 && $2==1 | | | | | -loc loc cii $1==4 && $2==1 | | | | | -loc loc cii $1==4 && $2==2 | | | | | loc loc cui $1==$2 | | | | | -loc loc ciu | | | | loc $1 loc $2 cuu | +loc loc ciu $1==$2 | | | | | #ifdef FLOAT4 #ifdef REGVARS loc loc cfi stl $1==4 && $2==4 && inreg($4)==2 @@ -2291,34 +2288,6 @@ loc loc cff ste $1==8 && $2==4 | source8 | loc loc cff $1==8 && $2==4 | source8 | allocate(%[1],REG) "cvtdf\t%[1],%[a]" | %[a] | | -#ifdef REGVARS -loc loc cuu stl $1==2 && $2==4 && inreg($4)==2 - | source2or4 | - remove(regvar($4)) - "movzwl\t%[1],%(regvar($4)%)" - erase(regvar($4)) - setcc(regvar($4)) | | | -#endif REGVARS -loc loc cuu stl $1==2 && $2==4 && $4<0 - | source2or4 | - remove(displaced) - remove(LOCALS,(%[num] <= $4+3 && %[num]+%[size] > $4)) - "movzwl\t%[1],$4(fp)" - setcc({LOCAL4,LB,$4,4}) | | | -loc loc cuu stl $1==2 && $2==4 && $4>=0 - | source2or4 | - remove(displaced) - remove(LOCALS,(%[num] <= $4+3 && %[num]+%[size] > $4)) - "movzwl\t%[1],$4(ap)" - setcc({LOCAL4,AP,$4,4}) | | | -loc loc cuu ste $1==2 && $2==4 | source2or4 | - remove(externals) - "movzwl\t%[1],$4" - setcc({EXTERNAL4,$4}) | | | -loc loc cuu $1==2 && $2==4 | source2or4 | - allocate(%[1],REG) - "movzwl\t%[1],%[a]" - setcc(%[a]) | %[a] | | /**************************************** * Group 9 : Logical instructions * From 5cf0d8b28061ca52678dc83b88de01e58b84ef71 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 18:49:59 +0000 Subject: [PATCH 0588/1625] endbss - begbss is no longer computable by the assembler --- mach/i80/libmon/head_em.s | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mach/i80/libmon/head_em.s b/mach/i80/libmon/head_em.s index b4b3b2d6..2e28aff9 100644 --- a/mach/i80/libmon/head_em.s +++ b/mach/i80/libmon/head_em.s @@ -12,8 +12,14 @@ .sect .text lxi h,0x1000 ! stack will grow from 0x1000 downwards sphl + lxi d,endbss lxi h,begbss ! clear bss - lxi d,endbss-begbss + mov a,e + sub l + mov e,a + mov a,d + sbb h + mov d,a ! de now contains endbss - begbss mvi c,0 2: mov m,c From 101d53394c1b679d5ebfffba90206e8057488d2d Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 18:52:12 +0000 Subject: [PATCH 0589/1625] Initial revision --- mach/i80/libem/end.s | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 mach/i80/libem/end.s diff --git a/mach/i80/libem/end.s b/mach/i80/libem/end.s new file mode 100644 index 00000000..6b9ce418 --- /dev/null +++ b/mach/i80/libem/end.s @@ -0,0 +1,17 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss +.define endtext,enddata,endbss +.define _end,_etext,_edata + + ! $Header$ + .sect .text +endtext: +_etext: + .align 2 + .sect .data +enddata: +_edata: + .align 2 +.sect .endsect +_end: +endbss: + .align 2 From bd517961c33084ae9237ba756427fcd8cde2d62c Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 18:57:04 +0000 Subject: [PATCH 0590/1625] adapted to new assembler --- mach/i80/libem/aar2.s | 5 +++++ mach/i80/libem/adi4.s | 5 +++++ mach/i80/libem/and.s | 5 +++++ mach/i80/libem/blm.s | 5 +++++ mach/i80/libem/cii.s | 5 +++++ mach/i80/libem/cmi4.s | 5 +++++ mach/i80/libem/cms.s | 5 +++++ mach/i80/libem/com.s | 5 +++++ mach/i80/libem/csa.s | 5 +++++ mach/i80/libem/csb.s | 5 +++++ mach/i80/libem/dup.s | 5 +++++ mach/i80/libem/dvi2.s | 7 ++++++- mach/i80/libem/dvi4.s | 5 +++++ mach/i80/libem/exg.s | 5 +++++ mach/i80/libem/flp.s | 5 +++++ mach/i80/libem/inn.s | 5 +++++ mach/i80/libem/ior.s | 5 +++++ mach/i80/libem/lar2.s | 5 +++++ mach/i80/libem/loi.s | 5 +++++ mach/i80/libem/mli2.s | 5 +++++ mach/i80/libem/mli4.s | 5 +++++ mach/i80/libem/mlu2.s | 5 +++++ mach/i80/libem/ngi4.s | 5 +++++ mach/i80/libem/nop.s | 5 +++++ mach/i80/libem/rck.s | 5 +++++ mach/i80/libem/rol4.s | 5 +++++ mach/i80/libem/ror4.s | 5 +++++ mach/i80/libem/sar2.s | 5 +++++ mach/i80/libem/sbi4.s | 5 +++++ mach/i80/libem/set.s | 5 +++++ mach/i80/libem/set2.s | 5 +++++ mach/i80/libem/sli2.s | 5 +++++ mach/i80/libem/sli4.s | 5 +++++ mach/i80/libem/sri2.s | 5 +++++ mach/i80/libem/sri4.s | 5 +++++ mach/i80/libem/sti.s | 5 +++++ mach/i80/libem/xor.s | 5 +++++ 37 files changed, 186 insertions(+), 1 deletion(-) diff --git a/mach/i80/libem/aar2.s b/mach/i80/libem/aar2.s index 11207556..0453fa0a 100644 --- a/mach/i80/libem/aar2.s +++ b/mach/i80/libem/aar2.s @@ -1,4 +1,9 @@ .define .aar2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Load address of array element, decriptor contains 2-bytes integers ! Expects on stack: pointer to array descriptor diff --git a/mach/i80/libem/adi4.s b/mach/i80/libem/adi4.s index 9dba4b57..3d4271a9 100644 --- a/mach/i80/libem/adi4.s +++ b/mach/i80/libem/adi4.s @@ -1,4 +1,9 @@ .define .adi4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Add two 32 bits signed or unsigned integers ! Expects on stack: operands diff --git a/mach/i80/libem/and.s b/mach/i80/libem/and.s index eab8d846..59a0253c 100644 --- a/mach/i80/libem/and.s +++ b/mach/i80/libem/and.s @@ -1,4 +1,9 @@ .define .and +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Any size logical-'and'. ! Expects: size in de-registers diff --git a/mach/i80/libem/blm.s b/mach/i80/libem/blm.s index d7786f88..0ff5b91c 100644 --- a/mach/i80/libem/blm.s +++ b/mach/i80/libem/blm.s @@ -1,4 +1,9 @@ .define .blm +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Block move ! Expects in de-reg: size of block diff --git a/mach/i80/libem/cii.s b/mach/i80/libem/cii.s index 64172b97..7d091da5 100644 --- a/mach/i80/libem/cii.s +++ b/mach/i80/libem/cii.s @@ -1,4 +1,9 @@ .define .cii +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Convert integer to integer ! Expects in a-reg: 1 for signed integer to signed integer (cii) diff --git a/mach/i80/libem/cmi4.s b/mach/i80/libem/cmi4.s index 88166a2a..84c7c7d7 100644 --- a/mach/i80/libem/cmi4.s +++ b/mach/i80/libem/cmi4.s @@ -1,4 +1,9 @@ .define .cmi4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Compare 32 bits integers ! Expects: operands on stack diff --git a/mach/i80/libem/cms.s b/mach/i80/libem/cms.s index 78c691ff..3e4c91d5 100644 --- a/mach/i80/libem/cms.s +++ b/mach/i80/libem/cms.s @@ -1,4 +1,9 @@ .define .cms +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Any size compare ! Expects: size in de-registers diff --git a/mach/i80/libem/com.s b/mach/i80/libem/com.s index 6ed460f8..6f0a4f03 100644 --- a/mach/i80/libem/com.s +++ b/mach/i80/libem/com.s @@ -1,4 +1,9 @@ .define .com +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Complement bytes on top of stack. ! Expects in de-registers: number of bytes diff --git a/mach/i80/libem/csa.s b/mach/i80/libem/csa.s index 74bc9cf8..9470481d 100644 --- a/mach/i80/libem/csa.s +++ b/mach/i80/libem/csa.s @@ -1,4 +1,9 @@ .define .csa +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Case jump ! Expects on stack: address of case descriptor diff --git a/mach/i80/libem/csb.s b/mach/i80/libem/csb.s index 38be66f4..7813c8b3 100644 --- a/mach/i80/libem/csb.s +++ b/mach/i80/libem/csb.s @@ -1,4 +1,9 @@ .define .csb +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Table lookup jump ! Expects on stack: address of case descriptor diff --git a/mach/i80/libem/dup.s b/mach/i80/libem/dup.s index 0804ab48..50e0cc8c 100644 --- a/mach/i80/libem/dup.s +++ b/mach/i80/libem/dup.s @@ -1,4 +1,9 @@ .define .dup +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Duplicate top bytes of stack ! Expects in de-registers: number of bytes to duplicate diff --git a/mach/i80/libem/dvi2.s b/mach/i80/libem/dvi2.s index 8c112950..7498d98d 100644 --- a/mach/i80/libem/dvi2.s +++ b/mach/i80/libem/dvi2.s @@ -1,5 +1,10 @@ - .define .dvi2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text + ! 16 bits signed and unsigned integer divide and remainder routine ! Bit 0 of a-reg is set iff quotient has to be delivered diff --git a/mach/i80/libem/dvi4.s b/mach/i80/libem/dvi4.s index 6dd1a4fd..a25806d0 100644 --- a/mach/i80/libem/dvi4.s +++ b/mach/i80/libem/dvi4.s @@ -1,4 +1,9 @@ .define .dvi4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! 32 bits integer divide and remainder routine ! Bit 0 of a-reg is set iff quotient has to be delivered diff --git a/mach/i80/libem/exg.s b/mach/i80/libem/exg.s index 0f173112..8a345b0f 100644 --- a/mach/i80/libem/exg.s +++ b/mach/i80/libem/exg.s @@ -1,4 +1,9 @@ .define .exg +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Exchange top bytes of stack ! Expects in de-registers the number of bytes to be exchanged. diff --git a/mach/i80/libem/flp.s b/mach/i80/libem/flp.s index 45e8c1f1..404c8d12 100644 --- a/mach/i80/libem/flp.s +++ b/mach/i80/libem/flp.s @@ -3,6 +3,11 @@ .define .zrf4,.zrf8 .define .cfi,.cif,.cuf,.cff,.cfu .define .cmf4,.cmf8 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Floating point is not implemented diff --git a/mach/i80/libem/inn.s b/mach/i80/libem/inn.s index 22ff2e8e..c39b8758 100644 --- a/mach/i80/libem/inn.s +++ b/mach/i80/libem/inn.s @@ -1,4 +1,9 @@ .define .inn +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Any size bit test on set. ! Expects in de-reg: size of set (in bytes) diff --git a/mach/i80/libem/ior.s b/mach/i80/libem/ior.s index f22f7abf..cd7793bc 100644 --- a/mach/i80/libem/ior.s +++ b/mach/i80/libem/ior.s @@ -1,4 +1,9 @@ .define .ior +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Any size inclusive-or. diff --git a/mach/i80/libem/lar2.s b/mach/i80/libem/lar2.s index bbe22486..82658ffb 100644 --- a/mach/i80/libem/lar2.s +++ b/mach/i80/libem/lar2.s @@ -1,4 +1,9 @@ .define .lar2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Load array element, descriptor contains 2-bytes integers ! Expects on stack: pointer to array descriptor diff --git a/mach/i80/libem/loi.s b/mach/i80/libem/loi.s index 46ce4757..6eebb870 100644 --- a/mach/i80/libem/loi.s +++ b/mach/i80/libem/loi.s @@ -1,4 +1,9 @@ .define .loi +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Load indirect ! Expects in de-registers: number of bytes to be loaded diff --git a/mach/i80/libem/mli2.s b/mach/i80/libem/mli2.s index 94680597..64f71568 100644 --- a/mach/i80/libem/mli2.s +++ b/mach/i80/libem/mli2.s @@ -1,4 +1,9 @@ .define .mli2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! 16 bits signed integer multiply ! the algorithm multiples A * B, where A = A0*2^8 + A1 and B = B0*2^8 + B1 diff --git a/mach/i80/libem/mli4.s b/mach/i80/libem/mli4.s index 4a5d0aa1..eab29ddc 100644 --- a/mach/i80/libem/mli4.s +++ b/mach/i80/libem/mli4.s @@ -1,4 +1,9 @@ .define .mli4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! 32 bits signed and unsigned integer multiply routine ! Expects operands on stack diff --git a/mach/i80/libem/mlu2.s b/mach/i80/libem/mlu2.s index 5f1bc5e9..4f4b700f 100644 --- a/mach/i80/libem/mlu2.s +++ b/mach/i80/libem/mlu2.s @@ -1,4 +1,9 @@ .define .mlu2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! 16 bits unsigned multiply routine ! Expects operands on stack diff --git a/mach/i80/libem/ngi4.s b/mach/i80/libem/ngi4.s index 4a12accb..18a8d2ae 100644 --- a/mach/i80/libem/ngi4.s +++ b/mach/i80/libem/ngi4.s @@ -1,4 +1,9 @@ .define .ngi4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Exchange 32 bits integer by its two's complement ! Expects operand on stack diff --git a/mach/i80/libem/nop.s b/mach/i80/libem/nop.s index e897bbe7..c0d31484 100644 --- a/mach/i80/libem/nop.s +++ b/mach/i80/libem/nop.s @@ -1,4 +1,9 @@ .define .nop +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .nop: push b lhld hol0+4 diff --git a/mach/i80/libem/rck.s b/mach/i80/libem/rck.s index 62bc68a0..0bfc3265 100644 --- a/mach/i80/libem/rck.s +++ b/mach/i80/libem/rck.s @@ -1,4 +1,9 @@ .define .rck +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Range check ! Expects on stack: address of range check descriptor diff --git a/mach/i80/libem/rol4.s b/mach/i80/libem/rol4.s index 8f4fcefd..de26f073 100644 --- a/mach/i80/libem/rol4.s +++ b/mach/i80/libem/rol4.s @@ -1,4 +1,9 @@ .define .rol4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Rotate 4 bytes left ! Expects in de-reg: number of rotates diff --git a/mach/i80/libem/ror4.s b/mach/i80/libem/ror4.s index c0712422..83ac56cb 100644 --- a/mach/i80/libem/ror4.s +++ b/mach/i80/libem/ror4.s @@ -1,4 +1,9 @@ .define .ror4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Rotate 4 bytes right ! Expects in de-reg: number of rotates diff --git a/mach/i80/libem/sar2.s b/mach/i80/libem/sar2.s index a1bde058..6e1694ed 100644 --- a/mach/i80/libem/sar2.s +++ b/mach/i80/libem/sar2.s @@ -1,4 +1,9 @@ .define .sar2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Store array element, descriptor contains 2-bytes integers ! Expects on stack: pointer to array descriptor diff --git a/mach/i80/libem/sbi4.s b/mach/i80/libem/sbi4.s index ed6354f6..7cf0e9c4 100644 --- a/mach/i80/libem/sbi4.s +++ b/mach/i80/libem/sbi4.s @@ -1,4 +1,9 @@ .define .sbi4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Subtract two 32 bits signed or unsigned integers. ! Expects operands on stack diff --git a/mach/i80/libem/set.s b/mach/i80/libem/set.s index df0242d9..3f47829e 100644 --- a/mach/i80/libem/set.s +++ b/mach/i80/libem/set.s @@ -1,4 +1,9 @@ .define .set +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Create set with one bit on ! Expects in de-reg: size of set to be created diff --git a/mach/i80/libem/set2.s b/mach/i80/libem/set2.s index 482008c5..4ec1312f 100644 --- a/mach/i80/libem/set2.s +++ b/mach/i80/libem/set2.s @@ -1,4 +1,9 @@ .define .set2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Create 16 bits set with one bit on ! Expects in de-reg: bit number diff --git a/mach/i80/libem/sli2.s b/mach/i80/libem/sli2.s index f7745fd8..c8765d29 100644 --- a/mach/i80/libem/sli2.s +++ b/mach/i80/libem/sli2.s @@ -1,4 +1,9 @@ .define .sli2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Shift 16 bits integer left ! Expects on stack: number of shifts diff --git a/mach/i80/libem/sli4.s b/mach/i80/libem/sli4.s index ec087cf6..b791aae9 100644 --- a/mach/i80/libem/sli4.s +++ b/mach/i80/libem/sli4.s @@ -1,4 +1,9 @@ .define .sli4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Shift 32 bits integer left ! Expects on stack: number of shifts diff --git a/mach/i80/libem/sri2.s b/mach/i80/libem/sri2.s index fa93dfd3..011cd10f 100644 --- a/mach/i80/libem/sri2.s +++ b/mach/i80/libem/sri2.s @@ -1,4 +1,9 @@ .define .sri2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Shift 16 bits signed or unsigned integer right ! Expects in a-reg.: 1 if signed integer diff --git a/mach/i80/libem/sri4.s b/mach/i80/libem/sri4.s index 5205c58c..e6edd589 100644 --- a/mach/i80/libem/sri4.s +++ b/mach/i80/libem/sri4.s @@ -1,4 +1,9 @@ .define .sri4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Shift 32 bits signed or unsigned integer right ! Expects in a-reg.: 1 if signed integer diff --git a/mach/i80/libem/sti.s b/mach/i80/libem/sti.s index 7cd24186..bdaead57 100644 --- a/mach/i80/libem/sti.s +++ b/mach/i80/libem/sti.s @@ -1,4 +1,9 @@ .define .sti +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Store indirect ! Expects on stack: number of bytes to be stored diff --git a/mach/i80/libem/xor.s b/mach/i80/libem/xor.s index 143db954..011e5907 100644 --- a/mach/i80/libem/xor.s +++ b/mach/i80/libem/xor.s @@ -1,4 +1,9 @@ .define .xor +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Any size exclusive-or. From 596f2c86a0a87ccce6681612018f9e77265b6e7d Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 19:02:25 +0000 Subject: [PATCH 0591/1625] .byte --> .data1 --- mach/i80/libmon/char.nas.s | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mach/i80/libmon/char.nas.s b/mach/i80/libmon/char.nas.s index 0604a8dd..0f2db445 100644 --- a/mach/i80/libmon/char.nas.s +++ b/mach/i80/libmon/char.nas.s @@ -47,9 +47,9 @@ fetch: inx h mov a,m jmp 2b ! conversion table for NASCOM characters -tab: .byte 0x0D,0x00 - .byte 0x1B,0x1E - .byte 0x08,0x1D - .byte 0x0A,0x1F - .byte 0x7F,0x00 +tab: .data1 0x0D,0x00 + .data1 0x1B,0x1E + .data1 0x08,0x1D + .data1 0x0A,0x1F + .data1 0x7F,0x00 From f1ecbcd37d39d3f246ca97c5a0ec9bea5f3f9b94 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 22:14:12 +0000 Subject: [PATCH 0592/1625] For generating .o files, aal archives --- mach/i80/libcc/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mach/i80/libcc/Makefile b/mach/i80/libcc/Makefile index a8113395..aa42dea4 100644 --- a/mach/i80/libcc/Makefile +++ b/mach/i80/libcc/Makefile @@ -1,5 +1,6 @@ +SUF=o MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=i80" "SUF=s" +MACHDEF="MACH=i80" "SUF=$(SUF)" "ASAR=aal" STDIO="PREF=cc" "SUB=.1s" "SRC=lang/cem/libcc/stdio" GEN="PREF=cc" "SUB=.2g" "SRC=lang/cem/libcc/gen" MON="PREF=mon" "SRC=lang/cem/libcc/mon" From 12b6ae2d446c3dbc94e729f1e938b0ae929a83fa Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 22:14:40 +0000 Subject: [PATCH 0593/1625] generating .o files --- mach/i80/libcc/compmodule | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mach/i80/libcc/compmodule b/mach/i80/libcc/compmodule index e7e4da63..17151513 100755 --- a/mach/i80/libcc/compmodule +++ b/mach/i80/libcc/compmodule @@ -1,4 +1,4 @@ if ${MACH?ack} -DCPM -I../../../h ${MACHFL?} $1 1>&2 -then echo `basename $1 $2`.s -else rm -f `basename $1 $2`.s +then echo `basename $1 $2`.o +else exit 1 fi From 29cd9e7692a7b6fcb9a339aa3869af4a4a36d051 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 22:17:36 +0000 Subject: [PATCH 0594/1625] generate .o files --- mach/i80/libpc/Makefile | 3 ++- mach/i80/libpc/compmodule | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/mach/i80/libpc/Makefile b/mach/i80/libpc/Makefile index 74fe98db..1c55242d 100644 --- a/mach/i80/libpc/Makefile +++ b/mach/i80/libpc/Makefile @@ -1,5 +1,6 @@ +SUF=o MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=i80" "SUF=s" +MACHDEF="MACH=i80" "SUF=$(SUF)" "ASAR=aal" PCDEF="PREF=pc" "SUB=" "SRC=lang/pc/libpc" install: diff --git a/mach/i80/libpc/compmodule b/mach/i80/libpc/compmodule index e7e4da63..17151513 100755 --- a/mach/i80/libpc/compmodule +++ b/mach/i80/libpc/compmodule @@ -1,4 +1,4 @@ if ${MACH?ack} -DCPM -I../../../h ${MACHFL?} $1 1>&2 -then echo `basename $1 $2`.s -else rm -f `basename $1 $2`.s +then echo `basename $1 $2`.o +else exit 1 fi From 16af17229adc6f15efe3ef6cf09862d9870dfc2a Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 22:23:14 +0000 Subject: [PATCH 0595/1625] syntax error correction --- mach/i80/libem/rck.s | 8 ++++---- mach/i80/libem/rol4.s | 2 +- mach/i80/libem/ror4.s | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mach/i80/libem/rck.s b/mach/i80/libem/rck.s index 0bfc3265..69777ff7 100644 --- a/mach/i80/libem/rck.s +++ b/mach/i80/libem/rck.s @@ -24,7 +24,7 @@ mov b,m inx h mov a,d - xor b + xri b jm 1f ! jump if index and l.b. have different signs mov a,e sub c @@ -32,14 +32,14 @@ sbb b jmp 2f -1: xor b ! now a = d again +1: xri b ! now a = d again 2: cm erange ! trap if index too small mov c,m inx h mov b,m mov a,d - xor b + xri b jm 1f ! jump if index and u.b. have different signs mov a,c sub e @@ -47,7 +47,7 @@ sbb d jmp 2f -1: xor d ! now a = b +1: xri d ! now a = b 2: cm erange ! trap if index is too large lhld .bcreg diff --git a/mach/i80/libem/rol4.s b/mach/i80/libem/rol4.s index de26f073..1199df16 100644 --- a/mach/i80/libem/rol4.s +++ b/mach/i80/libem/rol4.s @@ -10,7 +10,7 @@ ! Expects on stack: operand ! Yields on stack: result -.rol4 pop h +.rol4: pop h shld .retadr mov h,b mov l,c diff --git a/mach/i80/libem/ror4.s b/mach/i80/libem/ror4.s index 83ac56cb..ab3fe346 100644 --- a/mach/i80/libem/ror4.s +++ b/mach/i80/libem/ror4.s @@ -10,7 +10,7 @@ ! Expects on stack: operand ! Yields on stack: result -.ror4 pop h +.ror4: pop h shld .retadr mov h,b mov l,c From 52b0781eeeaff3becec965e237932ae77b3a2395 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 22:26:27 +0000 Subject: [PATCH 0596/1625] generate .o files --- mach/i80/libbc/Makefile | 3 ++- mach/i80/libbc/compmodule | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/mach/i80/libbc/Makefile b/mach/i80/libbc/Makefile index 7d7e95e9..4dd52b75 100644 --- a/mach/i80/libbc/Makefile +++ b/mach/i80/libbc/Makefile @@ -1,5 +1,6 @@ +SUF=o MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=i80" "SUF=s" +MACHDEF="MACH=i80" "SUF=$(SUF)" "ASAR=aal" BCDEF="PREF=bc" "SUB=" "SRC=lang/basic/lib" install: diff --git a/mach/i80/libbc/compmodule b/mach/i80/libbc/compmodule index e7e4da63..17151513 100755 --- a/mach/i80/libbc/compmodule +++ b/mach/i80/libbc/compmodule @@ -1,4 +1,4 @@ if ${MACH?ack} -DCPM -I../../../h ${MACHFL?} $1 1>&2 -then echo `basename $1 $2`.s -else rm -f `basename $1 $2`.s +then echo `basename $1 $2`.o +else exit 1 fi From abd0235f2f5f0b22fbdc83b4af4c0a7a06a302af Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 22:54:52 +0000 Subject: [PATCH 0597/1625] more corrections --- mach/i80/libem/rck.s | 8 ++++---- mach/i80/libem/rol4.s | 2 +- mach/i80/libem/ror4.s | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mach/i80/libem/rck.s b/mach/i80/libem/rck.s index 69777ff7..d7c85c91 100644 --- a/mach/i80/libem/rck.s +++ b/mach/i80/libem/rck.s @@ -24,7 +24,7 @@ mov b,m inx h mov a,d - xri b + xra b jm 1f ! jump if index and l.b. have different signs mov a,e sub c @@ -32,14 +32,14 @@ sbb b jmp 2f -1: xri b ! now a = d again +1: xra b ! now a = d again 2: cm erange ! trap if index too small mov c,m inx h mov b,m mov a,d - xri b + xra b jm 1f ! jump if index and u.b. have different signs mov a,c sub e @@ -47,7 +47,7 @@ sbb d jmp 2f -1: xri d ! now a = b +1: xra d ! now a = b 2: cm erange ! trap if index is too large lhld .bcreg diff --git a/mach/i80/libem/rol4.s b/mach/i80/libem/rol4.s index 1199df16..e5bb1a83 100644 --- a/mach/i80/libem/rol4.s +++ b/mach/i80/libem/rol4.s @@ -16,7 +16,7 @@ mov l,c shld .bcreg -.rol4: pop h ! low-order bytes of operand + pop h ! low-order bytes of operand pop b ! high order bytes of operand mov a,e diff --git a/mach/i80/libem/ror4.s b/mach/i80/libem/ror4.s index ab3fe346..e77d8a74 100644 --- a/mach/i80/libem/ror4.s +++ b/mach/i80/libem/ror4.s @@ -16,7 +16,7 @@ mov l,c shld .bcreg -.ror4: pop h ! low-order bytes of operand + pop h ! low-order bytes of operand pop b ! high order bytes of operand mov a,e From 0230c5802d642eeb9461908b59fddfc47efd9279 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 28 Jan 1987 23:22:07 +0000 Subject: [PATCH 0598/1625] Added IOR, AND, XOR, COM without parameters, because the Pascal runtime system needs at least one of them. Also deleted some old bug circumvention --- mach/ns/ncg/table | 64 +++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/mach/ns/ncg/table b/mach/ns/ncg/table index 5b2080d6..607c1a6f 100644 --- a/mach/ns/ncg/table +++ b/mach/ns/ncg/table @@ -29,7 +29,6 @@ EM_BSIZE=8 PROPERTIES -USELESS /* Bug circumvention */ REG /* Normal registers */ FREG /* Floating point registers */ DFREG(8) /* double floating reg for double precision */ @@ -537,7 +536,6 @@ with exact addr_external yields {absolute8, %1.disp} with exact LOCAL yields {memrel8, fp, %1.ind, 0} pat loi defined($1) -with USELESS with REG STACK uses REG = {const4, $1} gen addd %a, %1 @@ -751,7 +749,6 @@ with regcon4 consrc4 consrc4 move %2, {regrel4, %1.reg, %1.disp+4} pat sti defined($1) -with USELESS with REG STACK uses REG={const4, $1} gen 1: @@ -938,12 +935,10 @@ kills absolute + rel + memregrelcon4 gen ashd {const4, $2}, {absolute4, $1} pat loc sri $2 == 4 -with USELESS with REG gen ashd {const4,0-$1}, %1 yields %1 pat sri $1 == 4 -with USELESS with REG REG gen negd %1, %1 ashd %1, %2 yields %2 @@ -1021,12 +1016,10 @@ with STACK pat slu leaving sli $1 pat loc sru $2 == 4 -with USELESS with REG gen lshd {const4, 0-$1}, %1 yields %1 pat sru $1 == 4 -with USELESS with REG REG gen negd %1, %1 lshd %1, %2 yields %2 @@ -1201,7 +1194,6 @@ pat sbs $1==4 leaving sbi 4 *****************************************************************/ pat inc -with USELESS with REG gen addd {const4,1}, %1 yields %1 with exact STACK @@ -1234,7 +1226,6 @@ kills absolute, rel, memregrelcon4 gen addd {const4,1},{absolute4, $1} pat dec -with USELESS with REG gen addd {const4,0-1}, %1 yields %1 with exact STACK @@ -1424,6 +1415,16 @@ with STACK addr {regrel4, r1, 4}, r1 acbd {const4, 0-4}, r0, {label, "1b"} +pat and !defined($1) +with REG STACK +uses REG + gen addr {memregrel4, sp, 0}, %a + addd %1, %a + 1: + andd {TOS}, {regrel4, %a, 0} + addr {regrel4, %a, 4}, %a + acbd {const4, 0-4}, %1, {label, "1b"} + pat lol ior stl $1==$3 && $2==4 with src4 kills rel, LOCAL %ind-4 < $1 && %ind+4 > $1 @@ -1485,6 +1486,16 @@ with STACK addr {regrel4, r1, 4}, r1 acbd {const4, 0-4}, r0, {label, "1b"} +pat ior !defined($1) +with REG STACK +uses REG + gen addr {memregrel4, sp, 0}, %a + addd %1, %a + 1: + ord {TOS}, {regrel4, %a, 0} + addr {regrel4, %a, 4}, %a + acbd {const4, 0-4}, %1, {label, "1b"} + pat xor $1==4 with src4 REG gen xord %1, %2 yields %2 @@ -1500,8 +1511,17 @@ with STACK addr {regrel4, r1, 4}, r1 acbd {const4, 0-4}, r0, {label, "1b"} +pat xor !defined($1) +with REG STACK +uses REG + gen addr {memregrel4, sp, 0}, %a + addd %1, %a + 1: + xord {TOS}, {regrel4, %a, 0} + addr {regrel4, %a, 4}, %a + acbd {const4, 0-4}, %1, {label, "1b"} + pat com $1==4 -with USELESS with REG gen comd %1, %1 yields %1 @@ -1514,17 +1534,24 @@ with STACK addr {regrel4, r1, 4}, r1 acbd {const4, 0-4}, r0, {label, "1b"} +pat com !defined($1) +with REG STACK +uses REG + gen addr {memregrel4, sp, 0}, %a + 1: + comd {regrel4, %a, 0}, {regrel4, %a, 0} + addr {regrel4, %a, 4}, %a + acbd {const4, 0-4}, %1, {label, "1b"} + pat rol $1 == 4 with src124 REG gen rotd %1, %2 yields %2 pat loc ror $2 == 4 -with USELESS with REG gen rotd {const4, 0-$1}, %1 yields %1 pat ror $1 == 4 -with USELESS with REG REG gen negd %1, %1 rotd %1, %2 yields %2 @@ -1614,19 +1641,16 @@ pat lae aar $2==2 && rom($1,3)==1 && rom($1,1)!=0 adp 0-rom($1,1) pat lae aar $2==2 && rom($1,3)==2 && rom($1,1)==0 -with USELESS with REG gen ashd {const4, 1}, %1 yields %1 leaving adi 2 pat lae aar $2==2 && rom($1,3)==2 && rom($1,1)!=0 -with USELESS with REG gen ashd {const4, 1}, %1 yields {regcon4, %1,(0-2)*rom($1,1)} leaving adi 2 pat lae aar $2==4 && rom($1,3)==4 && rom($1,1)==0 -with USELESS with REG addr_local uses REG gen addr {memregrelsid, %2.ind, fp, %1}, %a @@ -1638,7 +1662,6 @@ uses REG with leaving lae $1 aar $2 pat lae aar $2==4 && rom($1,3)==4 && rom($1,1)!=0 -with USELESS with REG addr_local uses REG gen subd {const4, rom($1,1)}, %1 @@ -1652,13 +1675,11 @@ uses REG with leaving lae $1 aar $2 pat lae lar $2==4 && rom($1,3)==4 && rom($1,1)==0 -with USELESS with REG addr_local yields {memregrelsid, %2.ind, fp, %1} with REG addr_external yields {abssid, %2.disp, %1} with leaving lae $1 lar $2 pat lae lar $2==4 && rom($1,3)==4 && rom($1,1)!=0 -with USELESS with REG addr_local gen subd {const4, rom($1,1)}, %1 yields {memregrelsid, %2.ind, fp, %1} @@ -1692,7 +1713,6 @@ with src4 REG gen indexd %2, {const4, rom($1,3)-1}, %1 yields %2 pat lae aar $2==4 && rom($1,1)!=0 -with USELESS with REG REG gen subd {const4,rom($1,1)}, %1 indexd %2, {const4, rom($1,3)-1}, %1 yields %2 @@ -1985,7 +2005,6 @@ with STACK gen jsr {absolute4, $1} pat cai -with USELESS with REG STACK gen jsr %1 @@ -2020,7 +2039,6 @@ with STACK gen adjspd {const4,0-$1} pat ass $1==4 -with USELESS with REG STACK gen negd %1, %1 adjspd %1 @@ -2030,13 +2048,11 @@ with const4 STACK pat blm $1==0 pat blm $1==4 -with USELESS with REG REG kills allmincon gen move {regrel4, %2, 0}, {regrel4, %1, 0} pat blm $1>4 && $1<=16 -with USELESS with REG REG kills allmincon gen movmd %2, %1, {const4, $1} @@ -2054,7 +2070,6 @@ kills allmincon gen movmd {LOCAL, %2.ind}, {LOCAL, %1.ind}, {const4, $1} pat blm $1>16 -with USELESS with REG REG kills allmincon uses REG={const4,$1} @@ -2065,7 +2080,6 @@ kills allmincon acbd {const4, 0-4}, %a, {label, "1b"} pat bls $1==4 -with USELESS with REG kills ALL gen 1: From 7c67bf5c9343178fefd1a20b08fc30ba9724c1f7 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 29 Jan 1987 09:43:40 +0000 Subject: [PATCH 0599/1625] Corrected syntax error --- util/led/scan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/led/scan.c b/util/led/scan.c index e9d87ae3..d44cf34f 100644 --- a/util/led/scan.c +++ b/util/led/scan.c @@ -509,7 +509,7 @@ startrelo(head) else { index = 20; rd_rew_relos(head); - cnt_relos = head->oh_nrelos; + cnt_relos = head->oh_nrelo; } } From 1a553e6f2d8385c5efe5b4626af8c4d6c024e077 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 29 Jan 1987 10:33:53 +0000 Subject: [PATCH 0600/1625] PC/IX is system 3, not V7 --- mach/i86/libsys/gtty.s | 2 +- mach/i86/libsys/stty.s | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mach/i86/libsys/gtty.s b/mach/i86/libsys/gtty.s index 4e8b0e6c..58569489 100644 --- a/mach/i86/libsys/gtty.s +++ b/mach/i86/libsys/gtty.s @@ -5,7 +5,7 @@ _gtty: push bp mov bp,sp push 6(bp) -mov ax,29704 +mov ax,0x5401 push ax push 4(bp) call _ioctl diff --git a/mach/i86/libsys/stty.s b/mach/i86/libsys/stty.s index 701bb18a..01efaba6 100644 --- a/mach/i86/libsys/stty.s +++ b/mach/i86/libsys/stty.s @@ -5,7 +5,7 @@ _stty: push bp mov bp,sp push 6(bp) -mov ax,29705 +mov ax,0x5402 push ax push 4(bp) call _ioctl From 2076ecc2bf981244dd09979ae25daa3872b6f03d Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 29 Jan 1987 10:46:53 +0000 Subject: [PATCH 0601/1625] Name change. --- mach/i86/libsys/LIST | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/i86/libsys/LIST b/mach/i86/libsys/LIST index 90121971..0e0418e1 100644 --- a/mach/i86/libsys/LIST +++ b/mach/i86/libsys/LIST @@ -1,4 +1,4 @@ -tail_mon.a +libmon_s.a exit.s _exit.s abort.s From 3d505288187104f11db0cf9ed29809b2d49650a6 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 29 Jan 1987 10:47:27 +0000 Subject: [PATCH 0602/1625] Name change of lib, added head_em --- mach/i86/libsys/Makefile | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/mach/i86/libsys/Makefile b/mach/i86/libsys/Makefile index 2e2f7129..c03a0394 100644 --- a/mach/i86/libsys/Makefile +++ b/mach/i86/libsys/Makefile @@ -1,21 +1,27 @@ # $Header$ -MACH=l86 -all: tail_mon +MACH=i86 +all: libmon_o.a head_em.o + install: all - ../../install tail_mon + ../../install libmon_o.a tail_mon + ../../install head_em.o head_em cmp: all - -../../compare tail_mon + -../../compare libmon_o.a tail_mon + -../../compare head_em.o head_em -tail_mon: +libmon_o.a: libmon_s.a ASAR=aal ; export ASAR ;\ - march . tail_mon + march . libmon_o.a +head_em.o: head_em.s + $(MACH) -O -c head_em.s clean: - rm -f *.o + rm -f *.o libmon_o.a opr : make pr | opr pr: - @ar pv tail_mon.a + @pr `pwd`/head_em.s + @arch pv libmon_s.a | pr -h `pwd`/libmon_s.a From ba92464f523a1ad8680d43e86d7fbafbd8fe887e Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 29 Jan 1987 11:01:27 +0000 Subject: [PATCH 0603/1625] Name change of lib --- mach/i86/libem/LIST | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/i86/libem/LIST b/mach/i86/libem/LIST index 4bd01814..a94a4e3f 100644 --- a/mach/i86/libem/LIST +++ b/mach/i86/libem/LIST @@ -1,4 +1,4 @@ -tail_em.a +libem_s.a adi.s and.s cii.s From b9d428f3bb8d5b05ee03e654a27f0c291648a52d Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 29 Jan 1987 11:03:30 +0000 Subject: [PATCH 0604/1625] name change of lib, moved head_em.s to libsys --- mach/i86/libem/Makefile | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/mach/i86/libem/Makefile b/mach/i86/libem/Makefile index c1ebb198..1924bb79 100644 --- a/mach/i86/libem/Makefile +++ b/mach/i86/libem/Makefile @@ -1,33 +1,30 @@ # $Header$ MACH=i86 + +all: libem_o.a end.o + install: all - ../../install head_em.o head_em - ../../install tail_em + ../../install libem_o.a tail_em ../../install end.o end_em cmp: all - -../../compare head_em.o head_em - -../../compare tail_em + -../../compare libem_o.a tail_em -../../compare end.o end_em -all: head_em.o tail_em end.o end.o: end.s - $(MACH) -I../../../h -c end.s + $(MACH) -I../../../h -O -c end.s -head_em.o: head_em.s - $(MACH) -I../../../h -c head_em.s - -tail_em: tail_em.a +libem_o.a: libem_s.a ASAR=aal ; export ASAR ;\ - march . tail_em + march . libem_o.a clean: - rm -f *.o + rm -f *.o libem_o.a + opr : make pr | opr pr: - @pr `pwd`/head_em.s - @arch pv tail_em.a | pr -h `pwd`/tail_em.a + @arch pv libem_s.a | pr -h `pwd`/libem_s.a @pr `pwd`/end.s From cc5353d505419bcbcedf13bc5310b3fa3497ee7a Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 29 Jan 1987 13:01:28 +0000 Subject: [PATCH 0605/1625] don't use a sgttyb struct --- lang/cem/libcc/gen/isatty.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lang/cem/libcc/gen/isatty.c b/lang/cem/libcc/gen/isatty.c index 5152801a..4fa9cad3 100644 --- a/lang/cem/libcc/gen/isatty.c +++ b/lang/cem/libcc/gen/isatty.c @@ -1,8 +1,10 @@ -#include - isatty(f) { - struct sgttyb ttyb; + char buf[128]; + /* not a sgttyb struct; it might not be large enough; + I know for a fact that it is'nt large enough on PC/IX, + where gtty is an ioctl(..., TCGETA, ...) + */ if (gtty(f, &ttyb) < 0) return 0; return 1; From 5aa1b9a80974e4cc44acbc1a87e0309bc1583d0f Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 29 Jan 1987 13:20:23 +0000 Subject: [PATCH 0606/1625] Adapted to current situation --- util/led/WRONG | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/util/led/WRONG b/util/led/WRONG index 226f0e39..99d7cc57 100644 --- a/util/led/WRONG +++ b/util/led/WRONG @@ -3,10 +3,12 @@ Robbert and Ed found while making the linker usable for the 68000 and amoeba. I (Ceriel Jacobs) took the liberty of removing the ones that I fixed from this list. +... Another problem form the commons: -1 - Local commons are not handled by led and not produced by as. - Must, and will be handled by as. + +... + 2 - The commons are allocated at the very end of the first pass, after the initialezed data has been allocated in the segments. The order on which the commons are allocated seems to be random. That way it is impossible @@ -15,11 +17,3 @@ Another problem form the commons: The currently used trick is to declare an extra segment after the segment containing the commons. The first bytre in this segment inmediatly follows the commons and can be used as _end or endbss. - -The archiver (aal) with the automatic ranlib is buggy. -The only thing that seems to work at the moment is creation of a fresh -archive. -replacing/adding/deleting modules is likely to produce libraries -with incorrect ranlib entries. -The major troublemaker seems to be the extra padding byte at the end -of odd sized modules. From 5049da0a213a48efbb464cd53eb78099391317a0 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 29 Jan 1987 14:17:23 +0000 Subject: [PATCH 0607/1625] Initial revision --- util/led/led.6 | 125 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 util/led/led.6 diff --git a/util/led/led.6 b/util/led/led.6 new file mode 100644 index 00000000..a5b1e380 --- /dev/null +++ b/util/led/led.6 @@ -0,0 +1,125 @@ +.TH LED 6ACK +.SH NAME +led \- link editor +.SH SYNOPSIS +.B led +[ option ] ... file ... +.SH DESCRIPTION +.I Led +is a link editor for object modules, +created by one of the ACK assemblers. +It combines several +object programs into one, +resolves external references, +and searches archives. +In the simplest case several object +.I files +are given, and +.I led +combines them, producing +an object module which can be either +fed into a machine specific conversion program +or become the input for a further +.I led +run. +(In the latter case, if there are no unresolved references, +the +.B \-r +option must be given +to preserve the relocation information.)\ +The resulting object file of +.I led +is named +.BR a.out . +.PP +The argument routines are concatenated in the order specified. +The entry point of the output is the +beginning of the first routine. +.PP +If an argument is an archive, its table of contents is searched +for names which are undefined at the point at which the argument +is encountered in the argument list. +This procedure is repeated as long as unresolved references are +satisfied. +.PP +.I Led +understands several options. +The flags +.BR \-c , +.BR \-r , +.BR \-s , +and +.B \-u +should appear before the file names. +.TP +.BI \-a dd:nnnn +The alignment of section +.IR dd , +where +.I dd +is a decimal number, +is set to +.IR nnnn . +If +.I nnnn +starts with `0x', it is hexadecimal, +else if its starts with `0b', it is binary, +else if it starts with `0', it is octal, +else it is decimal. +.TP +.BI \-b dd:nnnn +The base addres in the machine of section +.IR dd , +is set to +.IR nnnn . +The previous remarks about +.I dd +and +.I nnnn +apply. +.TP +.B \-o +The +.I name +argument after +.B \-o +is used as the name of the +.I led +output file, instead of +.BR a.out . +.TP +.B \-r +Generate relocation information in the output file +so that it can be the subject of another +.I led +run. +This flag suppresses the `Undefined:' diagnostic. +.TP +.B \-c +Only effective in combination with +.BR \-r . +Indicates that relocatable output must be produced, but commons must +be resolved. +This may be useful for machines that need a last relocation step +at load time. +.TP +.B \-s +`Strip' the output, that is, remove the name table +and relocation information to save space (but impair the +usefulness of the debuggers). +.TP +.B \-u +Take the following argument as a symbol and enter +it as undefined in the name table. +This is useful for loading wholly from a library, +since initially the name table is empty +and an unresolved reference is needed +to force the loading of the first routine. +.SH FILES +~em/lib/em_led +a.out output file +.SH "SEE ALSO" +ack(1) +arch(1) +ack.out.h(5) +uni_ass(6) From 84e3dc04cd59e0b3aa0a105e8784e3e9f30c844a Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 29 Jan 1987 14:54:26 +0000 Subject: [PATCH 0608/1625] typo fix --- lang/cem/ctest/ctest1/test.c | 2 +- modules/src/object/object.3 | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lang/cem/ctest/ctest1/test.c b/lang/cem/ctest/ctest1/test.c index 4befc978..908d1b24 100644 --- a/lang/cem/ctest/ctest1/test.c +++ b/lang/cem/ctest/ctest1/test.c @@ -859,7 +859,7 @@ test7() /* local records */ #ifndef NOFLOAT if ( fabs ( s2.aaa * s1.aaa - s1.c1 * 5 - 1.0 ) > epsf ) e(36); #else - if ( 5*r1.c1 != 15 ) e(36) ; + if ( 5*s1.c1 != 15 ) e(36) ; #endif } diff --git a/modules/src/object/object.3 b/modules/src/object/object.3 index 2124f823..b0269d8f 100644 --- a/modules/src/object/object.3 +++ b/modules/src/object/object.3 @@ -21,7 +21,7 @@ and write ACK-object files and libraries .PP .B wr_ohead(head) .br -.B struct outsect *head; +.B struct outhead *head; .PP .B wr_sect(sect, cnt) .br @@ -93,7 +93,7 @@ and write ACK-object files and libraries .PP .B rd_ohead(head) .br -.B struct outsect *head; +.B struct outhead *head; .PP .B rd_sect(sect, cnt) .br From b803dc42b966ddcc74e84761b7f3fdca8a36cd4f Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 29 Jan 1987 15:54:46 +0000 Subject: [PATCH 0609/1625] Changed to handle new ack object format --- mach/i80/dl/Makefile | 14 +++++-- mach/i80/dl/mccpm.c | 95 +++++++++++++++++++++++--------------------- mach/i80/dl/nascom.c | 77 +++++++++++++++++++++++------------ 3 files changed, 110 insertions(+), 76 deletions(-) diff --git a/mach/i80/dl/Makefile b/mach/i80/dl/Makefile index dd1f0da8..e922d089 100644 --- a/mach/i80/dl/Makefile +++ b/mach/i80/dl/Makefile @@ -1,16 +1,22 @@ +EMHOME=../../.. +OBJLIB=$(EMHOME)/modules/lib/libobject.a + head: mccpm nascom mccpm: mccpm.c - cc -o mccpm mccpm.c + $(CC) -o mccpm mccpm.c $(OBJLIB) nascom: nascom.c - cc -o nascom nascom.c + $(CC) -o nascom nascom.c $(OBJLIB) -install: +install: head @echo Nothing is installed +cmp: head + @echo Nothing is compared + clean: - rm nascom mccpm + rm -f *.o pr: @pr `pwd`/Makefile `pwd`/mccpm.c `pwd`/nascom.c diff --git a/mach/i80/dl/mccpm.c b/mach/i80/dl/mccpm.c index d9bcb741..44abdc99 100644 --- a/mach/i80/dl/mccpm.c +++ b/mach/i80/dl/mccpm.c @@ -8,8 +8,8 @@ #define MAXBYTE 24 #include +#include char hex[] = "0123456789ABCDEF"; -FILE *fp, *fopen(); char **s; int bytes, bytcnt, checksum; unsigned pc; @@ -27,57 +27,70 @@ char *argv[]; if (argc == 3) if (!(offset = htou(argv[2]))) fatal ("adres error %s\n", argv[2]); - if ((fp = fopen (*++argv,"r")) == NULL) - fatal ("can't open %s\n",*argv); + if (! rd_open(*++argv)) fatal ("can't open %s\n",*argv); else { s = argv; convert (); - fclose (fp); } } convert () { - int c; - do - { - pc = getword (); - pc -= offset; - bytes = getword (); - bytes = getword (); - while (bytes != 0) - { - bytcnt = (bytes < MAXBYTE) ? bytes : MAXBYTE; - bytes -= bytcnt; - checksum = 0; - Irecord (); + struct outhead head; + struct outsect sect[MAXSECT]; + int i; + + rd_ohead(&head); + rd_sect(sect, head.oh_nsect); + for (i = 0; i < head.oh_nsect; i++) { + rd_outsect(i); + pc = sect[i].os_base - offset; + while (sect[i].os_size) { + unsigned int sz = 8096, fl; + extern char *calloc(); + register char *buf; + char *pbuf; + + if (sz > sect[i].os_size) sz = sect[i].os_size; + sect[i].os_size -= sz; + pbuf = buf = calloc(sz, 1); + if (fl = sect[i].os_flen) { + if (fl > sz) fl = sz; + sect[i].os_flen -= fl; + + rd_emit(buf, (long) fl); } - c = getc (fp); - ungetc (c, fp); + while (sz >= MAXBYTE) { + data(MAXBYTE, (int) pc, buf); + checksum = 0; + sz -= MAXBYTE; + buf += MAXBYTE; + pc += MAXBYTE; + } + if (sz > 0) { + data(sz, (int) pc, buf); + checksum = 0; + } + free(pbuf); } - while (c != EOF); + } printf (":00000001FF\n"); } -Irecord () - { +data (sz, pc, buf) + register char *buf; +{ printf (":"); - outbyte (bytcnt); + outbyte (sz); bytcnt += 4; outbyte (pc >> 8); outbyte (pc); outbyte (0); - record (); - } - - -record () - { - while (bytcnt != 0) + while (sz != 0) { - outbyte (getbyte ()); - pc ++; + outbyte (*buf++); + sz--; } outbyte (-checksum); putchar ('\n'); @@ -91,28 +104,18 @@ int b; checksum = (checksum + b) & 0xFF; putchar (hex[(b>>4) & 0xF]); putchar (hex[b & 0xF]); - -- bytcnt; } -getword () - { - int c; - c = getbyte (); - return ((getbyte () << 8) | c ); - } - -getbyte () - { - int c; - if ((c = getc (fp)) == EOF) fatal ("end of %s\n",*s); - return (c); - } fatal (s,a) { printf (s,a); exit (-1); } +rd_fatal() +{ + fatal("Read error\n"); +} /* convert a string of hex digits to an unsigned 16 bit number */ unsigned htou(t) diff --git a/mach/i80/dl/nascom.c b/mach/i80/dl/nascom.c index 81cb90a0..adf044fb 100644 --- a/mach/i80/dl/nascom.c +++ b/mach/i80/dl/nascom.c @@ -2,11 +2,13 @@ * Download Z80 load module into the NASCOM * * Johan Stevenson, Vrije Universiteit, Amsterdam + * Ceriel Jacobs, Vrije Universiteit, Amsterdam */ #include #include #include #include +#include int check; int nascom = 1; @@ -16,10 +18,15 @@ int disp = 0; char hex[] = "0123456789ABCDEF"; +char *progname; + struct sgttyb ttynormal; struct sgttyb ttyraw; int rawmode = 0; +struct outhead ohead; +struct outsect sect[MAXSECT]; + stop(code) { if (rawmode) stty(1, &ttynormal); @@ -27,9 +34,12 @@ stop(code) { } main(argc,argv) char **argv; { - register unsigned nd,pc; + register unsigned nd; + long pc; register char *s; + int i; + progname = argv[0]; while (argc > 1 && argv[1][0] == '-') { switch (argv[1][1]) { case 'u': @@ -56,7 +66,7 @@ main(argc,argv) char **argv; { fprintf(stderr,"usage: %s [flags] [object file]\n",argv[0]); stop(-1); } - if (freopen(s,"r",stdin) == NULL) { + if (! rd_open(s)) { fprintf(stderr,"%s: can't open %s\n",argv[0],s); stop(-1); } @@ -77,24 +87,37 @@ main(argc,argv) char **argv; { stty(1, &ttyraw); sleep(5); } - for (;;) { - pc = get2c(stdin); - if (feof(stdin)) - break; - nd = get2c(stdin); - nd = get2c(stdin); - if (nd > 256) { - fprintf(stderr,"bad format on %s\n",s); - stop(1); + rd_ohead(&ohead); + rd_sect(sect, ohead.oh_nsect); + for (i = 0; i < ohead.oh_nsect; i++) { + rd_outsect(i); + pc = sect[i].os_base; + while (sect[i].os_size) { + unsigned int sz = 8096, fl; + extern char *calloc(); + register char *buf; + char *pbuf; + + if (sz > sect[i].os_size) sz = sect[i].os_size; + sect[i].os_size -= sz; + pbuf = buf = calloc(sz, 1); + if (fl = sect[i].os_flen) { + if (fl > sz) fl = sz; + sect[i].os_flen -= fl; + + rd_emit(buf, (long) fl); + } + while (sz >= 8) { + data(8, (int) pc, buf); + sz -= 8; + buf += 8; + pc += 8; + } + if (sz > 0) { + data(sz, (int) pc, buf); + } + free(pbuf); } - while (nd > 8) { - data(8,pc); - nd -= 8; - pc += 8; - } - if (nd > 0) - data(nd,pc); - assert(feof(stdin) == 0); } putchar('.'); putchar(nl); @@ -103,7 +126,10 @@ main(argc,argv) char **argv; { stop(0); } -data(nd,pc) { +data(nd,pc,buf) + register char *buf; + int pc; +{ register i; check = 0; @@ -112,7 +138,7 @@ data(nd,pc) { byte(pc); for (i = 0; i < nd; i++) { putchar(' '); - byte(getc(stdin)); + byte(*buf++); } while (i < 8) { putchar(' '); @@ -131,9 +157,8 @@ byte(b) { putchar(hex[b & 017]); } -get2c(f) FILE *f; { - register c; - - c = getc(f); - return((getc(f) << 8) | c); +rd_fatal() +{ + fprintf(stderr, "%s: Read error\n", progname); + stop(-1); } From c3acbabd0552baeafd312f8e7e132bfca93ee2ad Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 29 Jan 1987 17:13:37 +0000 Subject: [PATCH 0610/1625] Added a check for unresolved references --- mach/i80/dl/mccpm.c | 6 +++++- mach/i80/dl/nascom.c | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/mach/i80/dl/mccpm.c b/mach/i80/dl/mccpm.c index 44abdc99..b76f142d 100644 --- a/mach/i80/dl/mccpm.c +++ b/mach/i80/dl/mccpm.c @@ -41,6 +41,9 @@ convert () int i; rd_ohead(&head); + if (head.oh_flags & HF_LINK) { + fatal("%s contains unresolved references\n",s); + } rd_sect(sect, head.oh_nsect); for (i = 0; i < head.oh_nsect; i++) { rd_outsect(i); @@ -107,8 +110,9 @@ int b; } fatal (s,a) + char *s, *a; { - printf (s,a); + fprintf (stderr,s,a); exit (-1); } diff --git a/mach/i80/dl/nascom.c b/mach/i80/dl/nascom.c index adf044fb..8373fc8e 100644 --- a/mach/i80/dl/nascom.c +++ b/mach/i80/dl/nascom.c @@ -2,6 +2,7 @@ * Download Z80 load module into the NASCOM * * Johan Stevenson, Vrije Universiteit, Amsterdam + * Adapted (untested) to new ack.out format by * Ceriel Jacobs, Vrije Universiteit, Amsterdam */ #include @@ -63,11 +64,11 @@ main(argc,argv) char **argv; { if (argc == 2) s = argv[1]; else if (argc != 1) { - fprintf(stderr,"usage: %s [flags] [object file]\n",argv[0]); + fprintf(stderr,"usage: %s [flags] [object file]\n",progname); stop(-1); } if (! rd_open(s)) { - fprintf(stderr,"%s: can't open %s\n",argv[0],s); + fprintf(stderr,"%s: can't open %s\n",progname,s); stop(-1); } if (nascom) { @@ -88,6 +89,10 @@ main(argc,argv) char **argv; { sleep(5); } rd_ohead(&ohead); + if (ohead.oh_flags & HF_LINK) { + fprintf(stderr,"%s: %s contains unresolved references\n",progname,s); + stop(-1); + } rd_sect(sect, ohead.oh_nsect); for (i = 0; i < ohead.oh_nsect; i++) { rd_outsect(i); From 3ac219e8ae9a3dd42a4ccca6aeb9537599d8aacb Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 29 Jan 1987 19:37:49 +0000 Subject: [PATCH 0611/1625] Initial revision --- mach/m68020/libcc/Makefile | 37 ++++++++++++++++++++++++++++++++++++ mach/m68020/libcc/compmodule | 6 ++++++ mach/m68020/libpc/Makefile | 20 +++++++++++++++++++ mach/m68020/libpc/compmodule | 6 ++++++ 4 files changed, 69 insertions(+) create mode 100644 mach/m68020/libcc/Makefile create mode 100755 mach/m68020/libcc/compmodule create mode 100644 mach/m68020/libpc/Makefile create mode 100755 mach/m68020/libpc/compmodule diff --git a/mach/m68020/libcc/Makefile b/mach/m68020/libcc/Makefile new file mode 100644 index 00000000..3d767978 --- /dev/null +++ b/mach/m68020/libcc/Makefile @@ -0,0 +1,37 @@ +MAKEFILE=../../proto/libg/Makefile +MACHDEF="MACH=m68020 -DNOFLOAT" "SUF=o" "ASAR=aal" +STDIO="PREF=cc" "SUB=.1s" "SRC=lang/cem/libcc/stdio" +GEN="PREF=cc" "SUB=.2g" "SRC=lang/cem/libcc/gen" +MON="PREF=mon" "SRC=lang/cem/libcc/mon" + +install: cpstdio cpgen + +cpstdio: + make -f $(MAKEFILE) $(STDIO) $(MACHDEF) tailcp +cpgen: + make -f $(MAKEFILE) $(GEN) $(MACHDEF) cp +cpmon: + make -f $(MAKEFILE) $(MON) $(MACHDEF) tailcp + +cmp: cmpstdio cmpgen + +cmpstdio: + make -f $(MAKEFILE) $(STDIO) $(MACHDEF) tail + -../../compare tail_cc.1s +cmpgen: + make -f $(MAKEFILE) $(GEN) $(MACHDEF) head + -../../compare head_cc + make -f $(MAKEFILE) $(GEN) $(MACHDEF) tail + -../../compare tail_cc.2g +cmpmon: + make -f $(MAKEFILE) $(MON) $(MACHDEF) tail + -../../compare tail_mon + +clean: + -rm -f *.old *.[ce$(SUF)] tail* head* + +opr: + make pr | opr + +pr: + @pr Makefile diff --git a/mach/m68020/libcc/compmodule b/mach/m68020/libcc/compmodule new file mode 100755 index 00000000..6327cb99 --- /dev/null +++ b/mach/m68020/libcc/compmodule @@ -0,0 +1,6 @@ +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then + echo `basename $1 $2`.o +else + exit 1 +fi diff --git a/mach/m68020/libpc/Makefile b/mach/m68020/libpc/Makefile new file mode 100644 index 00000000..033df6b3 --- /dev/null +++ b/mach/m68020/libpc/Makefile @@ -0,0 +1,20 @@ +MAKEFILE=../../proto/libg/Makefile +MACHDEF="MACH=m68020 -DNOFLOAT" "SUF=o" "ASAR=aal" +PCDEF="PREF=pc" "SUB=" "SRC=lang/pc/libpc" + +install: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) cp + +cmp: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) all + -../../compare head_pc + -../../compare tail_pc + +clean: + -rm -f *.old *.[ce$(SUF)] tail* head* + +opr: + make pr | opr + +pr: + @pr Makefile diff --git a/mach/m68020/libpc/compmodule b/mach/m68020/libpc/compmodule new file mode 100755 index 00000000..6327cb99 --- /dev/null +++ b/mach/m68020/libpc/compmodule @@ -0,0 +1,6 @@ +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then + echo `basename $1 $2`.o +else + exit 1 +fi From 4b05a76ed1801dc3de4893ab78f84b2ede46885b Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 29 Jan 1987 19:42:53 +0000 Subject: [PATCH 0612/1625] Initial revision --- mach/m68020/ncg/README | 10 ++++++++++ mach/m68k2/ncg/README | 10 ++++++++++ mach/m68k4/ncg/README | 10 ++++++++++ mach/moon3/ncg/README | 10 ++++++++++ 4 files changed, 40 insertions(+) create mode 100644 mach/m68020/ncg/README create mode 100644 mach/m68k2/ncg/README create mode 100644 mach/m68k4/ncg/README create mode 100644 mach/moon3/ncg/README diff --git a/mach/m68020/ncg/README b/mach/m68020/ncg/README new file mode 100644 index 00000000..1a817487 --- /dev/null +++ b/mach/m68020/ncg/README @@ -0,0 +1,10 @@ +The file 'table' in this directory contains a back end table for the +MC68020 processor as well as one for the MC68000. Both tables use 4 bytes +for words as well as for pointers. The table must be preprocessed first +by the C preprocessor. If the -Dm68k4 flag is used when preprocessing, a +code generator for the m68k4 is generated, otherwise a m68020 codegenerator +is produced. (See Makefile: PREFLAGS) +The m68k4 cg can very well be used for the MC68010 processor, for it makes +rather efficient use of the 68010 loop mode. + +The mach.[ch] files are also suitable for both the m68020 and the m68k4. diff --git a/mach/m68k2/ncg/README b/mach/m68k2/ncg/README new file mode 100644 index 00000000..1a817487 --- /dev/null +++ b/mach/m68k2/ncg/README @@ -0,0 +1,10 @@ +The file 'table' in this directory contains a back end table for the +MC68020 processor as well as one for the MC68000. Both tables use 4 bytes +for words as well as for pointers. The table must be preprocessed first +by the C preprocessor. If the -Dm68k4 flag is used when preprocessing, a +code generator for the m68k4 is generated, otherwise a m68020 codegenerator +is produced. (See Makefile: PREFLAGS) +The m68k4 cg can very well be used for the MC68010 processor, for it makes +rather efficient use of the 68010 loop mode. + +The mach.[ch] files are also suitable for both the m68020 and the m68k4. diff --git a/mach/m68k4/ncg/README b/mach/m68k4/ncg/README new file mode 100644 index 00000000..1a817487 --- /dev/null +++ b/mach/m68k4/ncg/README @@ -0,0 +1,10 @@ +The file 'table' in this directory contains a back end table for the +MC68020 processor as well as one for the MC68000. Both tables use 4 bytes +for words as well as for pointers. The table must be preprocessed first +by the C preprocessor. If the -Dm68k4 flag is used when preprocessing, a +code generator for the m68k4 is generated, otherwise a m68020 codegenerator +is produced. (See Makefile: PREFLAGS) +The m68k4 cg can very well be used for the MC68010 processor, for it makes +rather efficient use of the 68010 loop mode. + +The mach.[ch] files are also suitable for both the m68020 and the m68k4. diff --git a/mach/moon3/ncg/README b/mach/moon3/ncg/README new file mode 100644 index 00000000..1a817487 --- /dev/null +++ b/mach/moon3/ncg/README @@ -0,0 +1,10 @@ +The file 'table' in this directory contains a back end table for the +MC68020 processor as well as one for the MC68000. Both tables use 4 bytes +for words as well as for pointers. The table must be preprocessed first +by the C preprocessor. If the -Dm68k4 flag is used when preprocessing, a +code generator for the m68k4 is generated, otherwise a m68020 codegenerator +is produced. (See Makefile: PREFLAGS) +The m68k4 cg can very well be used for the MC68010 processor, for it makes +rather efficient use of the 68010 loop mode. + +The mach.[ch] files are also suitable for both the m68020 and the m68k4. From 28c54cb73f182b66a8185f4cee94ca4a947b6a13 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 29 Jan 1987 19:49:35 +0000 Subject: [PATCH 0613/1625] no F_DUM in dummy float --- mach/m68020/ncg/mach.c | 4 ++-- mach/m68k2/ncg/mach.c | 4 ++-- mach/m68k4/ncg/mach.c | 4 ++-- mach/moon3/ncg/mach.c | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/mach/m68020/ncg/mach.c b/mach/m68020/ncg/mach.c index ec51f8bf..3d3073a5 100644 --- a/mach/m68020/ncg/mach.c +++ b/mach/m68020/ncg/mach.c @@ -63,8 +63,8 @@ static int been_here; fatal("bad fcon size"); fprintf(codefile,".data4\t"); if (argval == 8) - fprintf(codefile,"F_DUM,"); - fprintf(codefile,"F_DUM\n"); + fprintf(codefile,"0,"); + fprintf(codefile,"0 !dummy float\n"); if ( !been_here++) { fprintf(stderr,"Warning : dummy float-constant(s)\n"); diff --git a/mach/m68k2/ncg/mach.c b/mach/m68k2/ncg/mach.c index ec51f8bf..3d3073a5 100644 --- a/mach/m68k2/ncg/mach.c +++ b/mach/m68k2/ncg/mach.c @@ -63,8 +63,8 @@ static int been_here; fatal("bad fcon size"); fprintf(codefile,".data4\t"); if (argval == 8) - fprintf(codefile,"F_DUM,"); - fprintf(codefile,"F_DUM\n"); + fprintf(codefile,"0,"); + fprintf(codefile,"0 !dummy float\n"); if ( !been_here++) { fprintf(stderr,"Warning : dummy float-constant(s)\n"); diff --git a/mach/m68k4/ncg/mach.c b/mach/m68k4/ncg/mach.c index ec51f8bf..3d3073a5 100644 --- a/mach/m68k4/ncg/mach.c +++ b/mach/m68k4/ncg/mach.c @@ -63,8 +63,8 @@ static int been_here; fatal("bad fcon size"); fprintf(codefile,".data4\t"); if (argval == 8) - fprintf(codefile,"F_DUM,"); - fprintf(codefile,"F_DUM\n"); + fprintf(codefile,"0,"); + fprintf(codefile,"0 !dummy float\n"); if ( !been_here++) { fprintf(stderr,"Warning : dummy float-constant(s)\n"); diff --git a/mach/moon3/ncg/mach.c b/mach/moon3/ncg/mach.c index ec51f8bf..3d3073a5 100644 --- a/mach/moon3/ncg/mach.c +++ b/mach/moon3/ncg/mach.c @@ -63,8 +63,8 @@ static int been_here; fatal("bad fcon size"); fprintf(codefile,".data4\t"); if (argval == 8) - fprintf(codefile,"F_DUM,"); - fprintf(codefile,"F_DUM\n"); + fprintf(codefile,"0,"); + fprintf(codefile,"0 !dummy float\n"); if ( !been_here++) { fprintf(stderr,"Warning : dummy float-constant(s)\n"); From ff600bfe9840317caf7e7c46341eee06db50a758 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 29 Jan 1987 19:56:16 +0000 Subject: [PATCH 0614/1625] Deleted NOFLOAT --- mach/m68020/libpc/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mach/m68020/libpc/Makefile b/mach/m68020/libpc/Makefile index 033df6b3..fa76bf1f 100644 --- a/mach/m68020/libpc/Makefile +++ b/mach/m68020/libpc/Makefile @@ -1,5 +1,6 @@ +SUF=o MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=m68020 -DNOFLOAT" "SUF=o" "ASAR=aal" +MACHDEF="MACH=m68020" "SUF=$(SUF)" "ASAR=aal" PCDEF="PREF=pc" "SUB=" "SRC=lang/pc/libpc" install: From 8ada47c0429885b4ef8fa5079ce00de969c52d04 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 29 Jan 1987 19:58:10 +0000 Subject: [PATCH 0615/1625] deleted NOFLOAT --- mach/m68020/libcc/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mach/m68020/libcc/Makefile b/mach/m68020/libcc/Makefile index 3d767978..3869c1d8 100644 --- a/mach/m68020/libcc/Makefile +++ b/mach/m68020/libcc/Makefile @@ -1,5 +1,6 @@ +SUF=o MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=m68020 -DNOFLOAT" "SUF=o" "ASAR=aal" +MACHDEF="MACH=m68020" "SUF=$(SUF)" "ASAR=aal" STDIO="PREF=cc" "SUB=.1s" "SRC=lang/cem/libcc/stdio" GEN="PREF=cc" "SUB=.2g" "SRC=lang/cem/libcc/gen" MON="PREF=mon" "SRC=lang/cem/libcc/mon" From 6130e43d51f56a7017f2363599aaa8b50d0c231f Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 29 Jan 1987 20:03:43 +0000 Subject: [PATCH 0616/1625] Initial revision --- mach/m68020/libbc/Makefile | 21 +++++++++++++++++++++ mach/m68020/libbc/compmodule | 6 ++++++ 2 files changed, 27 insertions(+) create mode 100644 mach/m68020/libbc/Makefile create mode 100755 mach/m68020/libbc/compmodule diff --git a/mach/m68020/libbc/Makefile b/mach/m68020/libbc/Makefile new file mode 100644 index 00000000..3ad7e423 --- /dev/null +++ b/mach/m68020/libbc/Makefile @@ -0,0 +1,21 @@ +SUF=o +MAKEFILE=../../proto/libg/Makefile +MACHDEF="MACH=m68020" "SUF=$(SUF)" "ASAR=aal" +BCDEF="PREF=bc" "SUB=" "SRC=lang/basic/lib" + +install: + make -f $(MAKEFILE) $(BCDEF) $(MACHDEF) tailcp + +cmp: + make -f $(MAKEFILE) $(BCDEF) $(MACHDEF) tail + -../../compare head_bc + -../../compare tail_bc + +clean: + -rm -f *.old *.[ce$(SUF)] tail* head* + +opr: + make pr | opr + +pr: + @pr Makefile diff --git a/mach/m68020/libbc/compmodule b/mach/m68020/libbc/compmodule new file mode 100755 index 00000000..6327cb99 --- /dev/null +++ b/mach/m68020/libbc/compmodule @@ -0,0 +1,6 @@ +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then + echo `basename $1 $2`.o +else + exit 1 +fi From 50348a8e951fabe112392015281b50ce5eccb774 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 29 Jan 1987 20:15:14 +0000 Subject: [PATCH 0617/1625] Initial revision --- mach/m68020/as/mach0.c | 33 +++ mach/m68020/as/mach1.c | 99 +++++++ mach/m68020/as/mach2.c | 65 +++++ mach/m68020/as/mach3.c | 238 ++++++++++++++++ mach/m68020/as/mach4.c | 428 +++++++++++++++++++++++++++++ mach/m68020/as/mach5.c | 609 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 1472 insertions(+) create mode 100644 mach/m68020/as/mach0.c create mode 100644 mach/m68020/as/mach1.c create mode 100644 mach/m68020/as/mach2.c create mode 100644 mach/m68020/as/mach3.c create mode 100644 mach/m68020/as/mach4.c create mode 100644 mach/m68020/as/mach5.c diff --git a/mach/m68020/as/mach0.c b/mach/m68020/as/mach0.c new file mode 100644 index 00000000..f9a80ab4 --- /dev/null +++ b/mach/m68020/as/mach0.c @@ -0,0 +1,33 @@ +/* @(#)mach0.c 1.5 */ +/* + * Motorola 68020 options + */ +#undef BITMAX +#define BITMAX 20000 + +#define THREE_PASS /* branch and offset optimization */ +#define BYTES_REVERSED /* high order byte has lowest address */ +#define WORDS_REVERSED /* high order word has lowest address */ +#define LISTING /* enable listing facilities */ +#define RELOCATION /* generate relocatable code */ +#define DEBUG 1 + +#undef valu_t +#define valu_t long +#undef addr_t +#define addr_t long + +#undef ASC_LPAR +#define ASC_LPAR '{' +#undef ASC_RPAR +#define ASC_RPAR '}' + +#undef ALIGNWORD +#define ALIGNWORD 2 +#undef ALIGNSECT +#define ALIGNSECT 2 + +#undef VALWIDTH +#define VALWIDTH 8 + +#define ASLD diff --git a/mach/m68020/as/mach1.c b/mach/m68020/as/mach1.c new file mode 100644 index 00000000..50e47128 --- /dev/null +++ b/mach/m68020/as/mach1.c @@ -0,0 +1,99 @@ +/* @(#)mach1.c 1.8 */ +/* + * Motorola 68020 dependent C declarations + */ + +#define low3(z) ((short)(z) & 07) +#define low4(z) ((short)(z) & 017) +#define low5(z) ((short)(z) & 037) +#define low6(z) ((short)(z) & 077) + +#define fit3(z) ((((z)-1) & ~07) == 0) +#define fit4(z) (((z) & ~017) == 0) +#define fit5(z) (((z) & ~037) == 0) +#define fit6(z) (((z) & ~077) == 0) +#define fit8(z) (((z) & ~0xFF) == 0) +#define fit16(z) (((z) & ~0xFFFF) == 0) + +#define SIZE_B 0000 +#define SIZE_W 0100 +#define SIZE_L 0200 +#define SIZE_NON 0300 +#define SIZE_DEF SIZE_W + +extern int mrg_1,mrg_2; /* Mode and ReGister */ +extern short ffew_1, ffew_2; /* Full Format Extension Word */ +extern expr_t bd_1,bd_2,od_1,od_2; /* base and outer displacements */ +#ifndef ASLD +extern valu_t bd_rel1,bd_rel2,od_rel1,od_rel2; +#endif + +#ifdef RELOCATION +#ifdef ASLD +#define T_EMIT2(a,b,c,d) t_emit2(a,b,c,0) +#define T_EMIT4(a,b,c,d) t_emit4(a,b,c,0) +#else ALSD +#define T_EMIT2(a,b,c,d) t_emit2(a,b,c,d) +#define T_EMIT4(a,b,c,d) t_emit4(a,b,c,d) +#endif ASLD +#else +#define T_EMIT2(a,b,c,d) t_emit2(a) +#define T_EMIT4(a,b,c,d) t_emit4(a) +#endif + +struct instr_t { + short i_word; /* word to be emitted */ +#ifdef RELOCATION + short i_relotype; + int i_reloinfo; + valu_t i_relonami; +#endif +}; +typedef struct instr_t instr_t; +instr_t instr[30]; /* temporary area for instructions */ +instr_t *instrp; /* index into instr[] */ +int dot_offset; + +/* flags used when reading effective addresses */ +#define INDEX 0300 +#define PRE_INDEX 0100 +#define POST_INDEX 0200 +#define DBL_INDEX 0300 +#define PC_MODE 0400 + +/* addressing mode bits */ +#define DTA 0x01 +#define MEM 0x02 +#define CTR 0x04 +#define ALT 0x08 +#define FITB 0x10 +#define FITW 0x20 +#define PUTW 0x40 +#define PUTL 0x80 + +#ifndef extern +extern short eamode[]; +#else +short eamode[] = { +/* 00A */ DTA |ALT, +/* 01A */ ALT, +/* 02A */ DTA|MEM|CTR|ALT, +/* 03A */ DTA|MEM |ALT, +/* 04A */ DTA|MEM |ALT, +/* 05A */ DTA|MEM|CTR|ALT|FITW|PUTW, /* if relocation wanted, use 06A */ +/* 06A */ DTA|MEM|CTR|ALT |PUTW, /* relocation handled by ea_1() */ +/* 07x */ 0, +/* 070 */ DTA|MEM|CTR|ALT|FITW|PUTW | (RELO2)<<8, +/* 071 */ DTA|MEM|CTR|ALT |PUTL | (RELO4)<<8, +/* 072 */ DTA|MEM|CTR |FITW|PUTW, /* if relocation wanted, use 073 */ +/* 073 */ DTA|MEM|CTR |PUTW, /* relocation handled by ea_1() */ +/* 074x */ 0, +/* 074B */ DTA|MEM |FITB|PUTW | (RELO1)<<8, +/* 074W */ DTA|MEM |FITW|PUTW | (RELO2)<<8, +/* 074L */ DTA|MEM |PUTL | (RELO4)<<8, +}; + /* RELO2 had to go with mode 070, because the assembly + * language programmer can use addresses like + * '(expression).w', which still have to be relocatable. + */ +#endif diff --git a/mach/m68020/as/mach2.c b/mach/m68020/as/mach2.c new file mode 100644 index 00000000..48090cca --- /dev/null +++ b/mach/m68020/as/mach2.c @@ -0,0 +1,65 @@ +/* @(#)mach2.c 1.5 */ +/* + * Motorola 68020 tokens + */ + +%token SIZE +%token DREG +%token AREG +%token PC +%token ZPC +%token CREG +%token SPEC +%token ABCD +%token ADDX +%token ADD +%token AND +%token BITOP +%token BITFIELD +%token BF_TO_D +%token BFINS +%token SHIFT +%token SZ_EA +%token OP_EA +%token OP_NOOP +%token LEA +%token DBR +%token BR +%token OP_EXT +%token OP_RANGE +%token TRAPCC +%token PACK +%token RTM +%token CHK +%token DIVMUL +%token DIVL +%token CMP +%token MOVE +%token MOVEP +%token MOVEM +%token MOVEC +%token MOVES +%token SWAP +%token LINK +%token UNLK +%token TRAP +%token STOP +%token EXG +%token RTD +%token BKPT +%token CALLM +%token CAS +%token CAS2 +%token CP +%token CPBCC +%token CPDBCC +%token CPGEN +%token CPRESTORE +%token CPSAVE +%token CPSCC +%token CPTRAPCC + +%type bcdx op_ea regs rrange +%type reg sizedef sizenon creg +%type off_width abs31 bd_areg_index +%type areg_index areg scale cp_cond diff --git a/mach/m68020/as/mach3.c b/mach/m68020/as/mach3.c new file mode 100644 index 00000000..4396142d --- /dev/null +++ b/mach/m68020/as/mach3.c @@ -0,0 +1,238 @@ +/* @(#)mach3.c 1.4 */ +/* + * Motorola 68020 keywords + */ + +0, SIZE, SIZE_B, ".b", +0, SIZE, SIZE_W, ".w", +0, SIZE, SIZE_L, ".l", + +0, DREG, 00, "d0", +0, DREG, 01, "d1", +0, DREG, 02, "d2", +0, DREG, 03, "d3", +0, DREG, 04, "d4", +0, DREG, 05, "d5", +0, DREG, 06, "d6", +0, DREG, 07, "d7", + +0, AREG, 00, "a0", +0, AREG, 01, "a1", +0, AREG, 02, "a2", +0, AREG, 03, "a3", +0, AREG, 04, "a4", +0, AREG, 05, "a5", +0, AREG, 06, "a6", +0, AREG, 07, "a7", +0, AREG, 07, "sp", + +0, PC, 0, "pc", +0, ZPC, 0, "zpc", + +0, CREG, 04001, "vbr", +0, CREG, 0, "sfc", +0, CREG, 00001, "dfc", +0, CREG, 00002, "cacr", +0, CREG, 04002, "caar", +0, CREG, 04003, "msp", +0, CREG, 04004, "isp", + +0, SPEC, 075, "usp", +0, SPEC, 076, "ccr", +0, SPEC, 077, "sr", + +0, ABCD, 0140400, "abcd", +0, ABCD, 0100400, "sbcd", + +0, ADDX, 0150400, "addx", +0, ADDX, 0110400, "subx", + +0, ADD, 0153300, "add", +0, ADD, 0112700, "sub", + +0, AND, 0141000, "and", +0, AND, 0135000, "eor", +0, AND, 0100000, "or", + +0, BITOP, 0000, "btst", +0, BITOP, 0100, "bchg", +0, BITOP, 0200, "bclr", +0, BITOP, 0300, "bset", + +0, BITFIELD, 0164300, "bftst", +0, BITFIELD, 0165300, "bfchg", +0, BITFIELD, 0166300, "bfclr", +0, BITFIELD, 0167300, "bfset", +0, BF_TO_D, 0164700, "bfextu", +0, BF_TO_D, 0164700, "bfexts", +0, BF_TO_D, 0164700, "bfffo", +0, BFINS, 0167700, "bfins", + +0, SHIFT, 0160340, "asr", +0, SHIFT, 0160740, "asl", +0, SHIFT, 0161350, "lsr", +0, SHIFT, 0161750, "lsl", +0, SHIFT, 0162360, "roxr", +0, SHIFT, 0162760, "roxl", +0, SHIFT, 0163370, "ror", +0, SHIFT, 0163770, "rol", + +0, SZ_EA, 041000|DTA|ALT, "clr", +0, SZ_EA, 042000|DTA|ALT, "neg", +0, SZ_EA, 040000|DTA|ALT, "negx", +0, SZ_EA, 043000|DTA|ALT, "not", +0, SZ_EA, 045000|DTA, "tst", + +0, OP_EA, 044000|DTA|ALT, "nbcd", +0, OP_EA, 045300|DTA|ALT, "tas", +0, OP_EA, 047200|CTR, "jsr", +0, OP_EA, 047300|CTR, "jmp", +0, OP_EA, 044100|CTR, "pea", + +0, OP_EA, 050300, "st", +0, OP_EA, 050700, "sf", +0, OP_EA, 051300, "shi", +0, OP_EA, 051700, "sls", +0, OP_EA, 052300, "scc", +0, OP_EA, 052700, "scs", +0, OP_EA, 053300, "sne", +0, OP_EA, 053700, "seq", +0, OP_EA, 054300, "svc", +0, OP_EA, 054700, "svs", +0, OP_EA, 055300, "spl", +0, OP_EA, 055700, "smi", +0, OP_EA, 056300, "sge", +0, OP_EA, 056700, "slt", +0, OP_EA, 057300, "sgt", +0, OP_EA, 057700, "sle", + +0, OP_NOOP, 047160, "reset", +0, OP_NOOP, 047161, "nop", +0, OP_NOOP, 047163, "rte", +0, OP_NOOP, 047165, "rts", +0, OP_NOOP, 047166, "trapv", +0, OP_NOOP, 047167, "rtr", +0, OP_NOOP, 045374, "illegal", + +0, PACK, 0100500, "pack", +0, PACK, 0100600, "unpk", + +0, DIVMUL, 0100, "divu", +0, DIVMUL, 0101, "divs", +0, DIVMUL, 0000, "mulu", +0, DIVMUL, 0001, "muls", + +0, DIVL, 046100, "divul", +0, DIVL, 046101, "divsl", + +0, BR, 060000, "bra", +0, BR, 060400, "bsr", +0, BR, 061000, "bhi", +0, BR, 061400, "bls", +0, BR, 062000, "bcc", +0, BR, 062400, "bcs", +0, BR, 063000, "bne", +0, BR, 063400, "beq", +0, BR, 064000, "bvc", +0, BR, 064400, "bvs", +0, BR, 065000, "bpl", +0, BR, 065400, "bmi", +0, BR, 066000, "bge", +0, BR, 066400, "blt", +0, BR, 067000, "bgt", +0, BR, 067400, "ble", + +0, DBR, 050310, "dbt", +0, DBR, 050710, "dbf", +0, DBR, 050710, "dbra", +0, DBR, 051310, "dbhi", +0, DBR, 051710, "dbls", +0, DBR, 052310, "dbcc", +0, DBR, 052710, "dbcs", +0, DBR, 053310, "dbne", +0, DBR, 053710, "dbeq", +0, DBR, 054310, "dbvc", +0, DBR, 054710, "dbvs", +0, DBR, 055310, "dbpl", +0, DBR, 055710, "dbmi", +0, DBR, 056310, "dbge", +0, DBR, 056710, "dblt", +0, DBR, 057310, "dbgt", +0, DBR, 057710, "dble", + +0, OP_EXT, 044000, "ext", +0, OP_EXT, 044400, "extb", + +0, OP_RANGE, 04000, "chk2", +0, OP_RANGE, 0, "cmp2", + +0, TRAPCC, 050370, "trapt", +0, TRAPCC, 050770, "trapf", +0, TRAPCC, 051370, "traphi", +0, TRAPCC, 051770, "trapls", +0, TRAPCC, 052370, "trapcc", +0, TRAPCC, 052770, "trapcs", +0, TRAPCC, 053370, "trapeq", +0, TRAPCC, 053770, "trapvc", +0, TRAPCC, 054370, "trapvs", +0, TRAPCC, 054770, "trappl", +0, TRAPCC, 055370, "trapmi", +0, TRAPCC, 055770, "trapge", +0, TRAPCC, 056370, "traplt", +0, TRAPCC, 056770, "trapgt", +0, TRAPCC, 057370, "traple", +0, TRAPCC, 057770, "trapne", + +0, CMP, 0, "cmp", + +0, MOVE, 0, "move", +0, MOVEP, 0, "movep", +0, MOVEM, 0, "movem", +0, MOVES, 0, "moves", +0, MOVEC, 0, "movec", + +0, SWAP, 0, "swap", + +0, LINK, 0, "link", + +0, UNLK, 0, "unlk", + +0, TRAP, 0, "trap", + +0, STOP, 0, "stop", + +0, CHK, 0, "chk", + +0, RTM, 0, "rtm", + +0, EXG, 0, "exg", + +0, LEA, 0, "lea", + +0, RTD, 0, "rtd", + +0, BKPT, 0, "bkpt", + +0, CALLM, 0, "callm", + +0, CAS, 0, "cas", + +0, CAS2, 0, "cas2", + +0, CP, 00000, "c0", +0, CP, 01000, "c1", +0, CP, 02000, "c2", +0, CP, 03000, "c3", +0, CP, 04000, "c4", +0, CP, 05000, "c5", +0, CP, 06000, "c6", +0, CP, 07000, "c7", + +0, CPGEN, 0170000, ".gen", +0, CPSCC, 0170100, ".s", +0, CPDBCC, 0170110, ".db", +0, CPTRAPCC, 0170170, ".trap", +0, CPBCC, 0170200, ".br", /* 'r' to distinguish from SIZE_B + */ +0, CPSAVE, 0170400, ".save", +0, CPRESTORE, 0170500, ".restore", diff --git a/mach/m68020/as/mach4.c b/mach/m68020/as/mach4.c new file mode 100644 index 00000000..ca1634b3 --- /dev/null +++ b/mach/m68020/as/mach4.c @@ -0,0 +1,428 @@ +/* @(#)mach4.c 1.11 */ +/* + * Motorola 68020 syntax rules + */ + +operation + : { instrp = instr; + dot_offset = 0; + } + instruction + { emit_instr(); + } + ; +instruction + : bcdx DREG ',' DREG + { T_EMIT2($1 | $2 | $4<<9,0,0,0);} + | bcdx '-' '(' AREG ')' ',' '-' '(' AREG ')' + { T_EMIT2($1 | $4 | $9<<9 | 010,0,0,0);} + | ADD sizedef ea_ea + { add($1, $2);} + | AND sizenon ea_ea + { and($1, $2);} + | SHIFT sizedef ea_ea + { shift_op($1, $2);} + | SHIFT sizedef ea /* This syntax is also allowed */ + { checksize($2, 2); + T_EMIT2(($1 & 0177700) | mrg_2,0,0,0); + ea_2(SIZE_W, MEM|ALT); + } + | BR expr + { branch($1, $2);} + | DBR DREG ',' expr + { T_EMIT2($1 | $2,0,0,0); + $4.val -= (DOTVAL+dot_offset); + fit(fitw($4.val)); + T_EMIT2(loww($4.val), $4.typ, + RELPC|RELO2, relonami); + } + | BITOP ea_ea + { bitop($1);} + | BITFIELD ea off_width + { bitfield($1, $3);} + | BF_TO_D ea off_width ',' DREG + { bitfield($1, $3 | $5<<12);} + | BFINS DREG ',' ea off_width + { bitfield($1, $5 | $2<<12);} + | DIVMUL sizedef ea ',' DREG + { checksize($2, 2|4); + if ($2 == SIZE_W) { + T_EMIT2((0140300^($1<<8))|mrg_2|$5<<9, + 0, 0, 0); + ea_2(SIZE_W, DTA); + } + else { /* 32 bit dividend or product */ + T_EMIT2((016000 | ($1 & ~1)) | mrg_2, + 0, 0, 0); + T_EMIT2(($1&1)<<11 | $5<<12 | $5, + 0, 0, 0); + ea_2(SIZE_L, DTA); + } + } + | DIVMUL sizedef ea ',' DREG ':' DREG + { /* 64 bit dividend or product */ + checksize($2, 4); + T_EMIT2((016000 | ($1 & ~1)) | mrg_2, 0, 0, 0); + T_EMIT2(($1&1)<<11 | $7<<12 | $5 | 02000,0,0,0); + ea_2(SIZE_L, DTA); + } + | DIVL sizedef ea ',' DREG ':' DREG + { /* 32 bit long division with remainder */ + checksize($2, 4); + T_EMIT2(($1 & ~1) | mrg_2, 0, 0, 0); + T_EMIT2(($1 & 1)<<11 | $7<<12 | $5, 0, 0, 0); + ea_2(SIZE_L, DTA); + } + | LEA ea ',' AREG + { T_EMIT2(040700 | mrg_2 | $4<<9,0,0,0); + ea_2(SIZE_L, CTR); + } + | op_ea ea + { if (mrg_2==074) + serror("bad adressing category"); + T_EMIT2(($1&0177700) | mrg_2,0,0,0); + ea_2($1&0300, $1&017); + } + | OP_NOOP + { T_EMIT2($1,0,0,0);} + | OP_EXT SIZE DREG + { checksize($2, ($1 & 0400) ? 4 : (2|4)); + T_EMIT2($1 | $2+0100 | $3,0,0,0); + } + | OP_RANGE sizedef ea ',' reg + { T_EMIT2(0300 | ($2<<3) | mrg_2,0,0,0); + T_EMIT2($1 | ($5<<12),0,0,0); + ea_2($2, CTR); + } + | TRAPCC SIZE imm + { checksize($2, 2|4); + T_EMIT2($1 | ($2>>6)+1,0,0,0); + ea_2($2, 0); + } + | TRAPCC { T_EMIT2($1 | 4,0,0,0);} + | PACK '-' '(' AREG ')' ',' '-' '(' AREG ')' ',' imm + { T_EMIT2($1 | 1 | $4 | $9<<9, 0, 0, 0); + ea_2(SIZE_W, 0); + } + | PACK DREG ',' DREG ',' imm + { T_EMIT2($1 | $2 | $4<<9, 0, 0, 0); + ea_2(SIZE_W, 0); + } + | CMP sizedef ea_ea + { cmp($2);} + | CHK sizedef ea ',' DREG + { checksize($2, 2|4); + T_EMIT2(040000 | mrg_2 | $5<<9 | + ($2==SIZE_W ? 0600 : 0400), + 0, 0, 0); + ea_2($2, DTA); + } + | MOVE sizenon ea_ea + { move($2);} + | MOVEP sizedef ea_ea + { movep($2);} + | MOVEM sizedef regs ',' notimmreg + { movem(0, $2, $3);} + | MOVEM sizedef notimmreg ',' regs + { movem(1, $2, $5);} + | MOVES sizedef ea_ea + { if (mrg_1 <= 017) { + T_EMIT2(007000 | $2 | mrg_2,0,0,0); + T_EMIT2(mrg_1 << 12 | 04000,0,0,0); + ea_2($2,ALT|MEM); + } else if (mrg_2 <= 017) { + T_EMIT2(007000 | $2 | mrg_1,0,0,0); + T_EMIT2(mrg_2 << 12,0,0,0); + ea_1($2,ALT|MEM); + } else + badoperand(); + } + | MOVEC creg ',' reg + { T_EMIT2(047172,0,0,0); + T_EMIT2($2 | $4<<12,0,0,0); + } + | MOVEC reg ',' creg + { T_EMIT2(047173,0,0,0); + T_EMIT2($4 | $2<<12,0,0,0); + } + | EXG reg ',' reg + { if (($2 & 010) == 0) + T_EMIT2( + (0140500|$4|$2<<9) + + + (($4&010)<<3) + ,0,0,0); + else + T_EMIT2( + (0140600|$2|($4&07)<<9) + - + (($4&010)<<3) + ,0,0,0); + } + | SWAP DREG + { T_EMIT2(044100 | $2,0,0,0);} + | STOP imm + { T_EMIT2(047162, 0, 0, 0); + ea_2(SIZE_W, 0); + } + | LINK sizenon AREG ',' imm + { link($2, $3);} + | UNLK AREG + { T_EMIT2(047130 | $2,0,0,0);} + | TRAP '#' absexp + { fit(fit4($3)); + T_EMIT2(047100|low4($3),0,0,0); + } + | RTD imm + { T_EMIT2(047164,0,0,0); + ea_2(SIZE_W, 0); + } + | BKPT '#' absexp + { fit(($3 & ~07) == 0); + T_EMIT2(044110 | low3($3),0,0,0); + } + | CALLM '#' absexp ',' ea + { fit(fitb($3)); + T_EMIT2(03300 | mrg_2,0,0,0); + T_EMIT2($3,0,0,0); + ea_2(SIZE_L, CTR); + } + | RTM reg + { T_EMIT2(03300 | $2, 0, 0, 0);} + | CAS sizedef DREG ',' DREG ',' ea + { T_EMIT2(04300 | (($2+0100)<<3) | mrg_2,0,0,0); + T_EMIT2($5 | ($3<<6),0,0,0); + ea_2($2, MEM|ALT); + } + | CAS2 sizedef DREG ':' DREG ',' DREG ':' DREG ',' + '(' reg ')' ':' '(' reg ')' + { checksize($2 , 2|4); + T_EMIT2(04374 | (($2+0100)<<3),0,0,0); + T_EMIT2($3 | ($7<<6) | ($12<<12),0,0,0); + T_EMIT2($5 | ($9<<6) | ($16<<12),0,0,0); + } + | /* Coprocessor instructions; syntax may be changed (please). + * No coprocessor defined extension words are emitted. + */ + CP CPBCC cp_cond expr + { cpbcc($2 | $1 | $3, $4); + } + | CP CPDBCC cp_cond DREG ',' expr + { T_EMIT2($2 | $1 | $4,0,0,0); + $6.val -= (DOTVAL+dot_offset); + fit(fitw($6.val)); + T_EMIT2(loww($6.val), $6.typ, + RELPC|RELO2, relonami); + } + | CP CPGEN + { T_EMIT2($2 | $1,0,0,0); + /* NO COMMAND WORD IS EMITTED; + * THIS INSTRUCTIONS IS (STILL) ONE BIG RIDDLE. + * NO EFFECTIVE ADDRESS IS CALCULATED (SYNTAX ?) + */ + } + | CP CPRESTORE ea + { T_EMIT2($2 | $1 | mrg_2,0,0,0); + ea_2(SIZE_W, (mrg_2 & 070)==030 ? 0 : CTR); + } + | CP CPSAVE ea + { T_EMIT2($2 | $1 | mrg_2,0,0,0); + ea_2(SIZE_W,(mrg_2 & 070)==020 ? 0 : CTR|ALT); + } + | CP CPSCC cp_cond ea + { T_EMIT2($2 | $1 | mrg_2,0,0,0); + T_EMIT2($3,0,0,0); + ea_2(SIZE_B,DTA|ALT); + } + | CP CPTRAPCC cp_cond SIZE imm + { checksize($4,2|4); + T_EMIT2($2 | $1 | ($4>>6)+1,0,0,0); + T_EMIT2($3,0,0,0); + ea_2($4, 0); + } + | CP TRAPCC cp_cond + { T_EMIT2($2 | $1 | 4,0,0,0); + T_EMIT2($3,0,0,0); + } + ; +cp_cond : '.' absexp + { fit(fit6($2)); + $$ = low6($2); + } + ; +bcdx : ABCD + | ADDX sizedef + { $$ = $1 | $2;} + ; +creg : CREG + | SPEC { if ($1 != 075) + badoperand(); + $$ = 04000; + } + ; +off_width /* note: these should be curly brackets, but that would + * leave us without brackets for expressions. + */ + : '[' abs31 ':' abs31 ']' + { $$ = ($2<<6) | $4; + } + ; +abs31 : DREG { $$ = 040 | $1;} + | absexp { fit(fit5($1)); + $$ = low5($1); + } + ; +op_ea : OP_EA + | SZ_EA sizedef + { $$ = $1 | $2;} + ; +regs : rrange + | regs '/' rrange + { $$ = $1 | $3;} + ; +rrange : reg + { $$ = 1<<$1;} + | reg '-' reg + { if ($1 > $3) + badoperand(); + for ($$ = 0; $1 <= $3; $1++) + $$ |= (1<<$1); + } + ; +ea : DREG + { mrg_2 = $1;} + | AREG + { mrg_2 = 010 | $1;} + | SPEC + { mrg_2 = $1;} + | { mrg_2 = 0; ffew_2 = 0400; /* initialization */} + notimmreg + | imm + ; +notimmreg + : '(' AREG ')' + { mrg_2 = 020 | $2;} + | '(' AREG ')' '+' + { mrg_2 = 030 | $2;} + | '-' '(' AREG ')' + { mrg_2 = 040 | $3;} + | '(' expr ')' sizenon + { bd_2 = $2; ea7071($4); + RELOMOVE(bd_rel2, relonami); + } + | '(' bd_areg_index ')' + { if ((mrg_2 & INDEX) == 0) + ffew_2 |= 0100; /* suppress index */ + if ( !(mrg_2 & PC_MODE) && + (ffew_2 & 0300) == 0100 && + bd_2.typ==S_ABS && fitw(bd_2.val) + ) + mrg_2 = (loww(bd_2.val)?050:020) | $2; + else { + mrg_2 = (mrg_2&PC_MODE)?073:(060 | $2); + ffew_2 |= 060; /* long displacement */ + } + } + | '(' '[' bd_areg_index ']' index_od ')' + { switch(mrg_2 & INDEX) { + case 0: + ffew_2 |= 0163; /* suppress index */ + break; + case DBL_INDEX: + serror("bad indexing"); + case PRE_INDEX: + ffew_2 |= 063; break; + case POST_INDEX: + ffew_2 |= 067; break; + } + mrg_2 = (mrg_2 & PC_MODE) ? 073 : (060 | $3); + } + ; +imm : '#' expr + { mrg_2 = 074; bd_2 = $2; + RELOMOVE(bd_rel2, relonami); + } + ; +bd_areg_index + : /* empty */ + { $$ = 0; ffew_2 |= 0200; + /* base-reg suppressed */ + bd_2.typ = S_ABS; bd_2.val = (valu_t)0; + /* zero displacement */ + } + | expr { $$ = 0; ffew_2 |= 0300; + bd_2 = $1; + RELOMOVE(bd_rel2, relonami); + } + | areg_index + { bd_2.typ = S_ABS; bd_2.val = (valu_t)0; + } + | expr ',' areg_index + { $$ = $3; bd_2 = $1; + RELOMOVE(bd_rel2, relonami); + } + ; +areg_index + : areg + | index { $$ = 0; + ffew_2 |= 0200; /* base-reg suppressed */ + mrg_2 |= PRE_INDEX; + } + | areg ',' index + { mrg_2 |= PRE_INDEX; + } + ; +areg : AREG + | PC { mrg_2 |= PC_MODE;} + | ZPC { mrg_2 |= PC_MODE; + ffew_2 |= 0200; /* base-reg suppressed */ + } + ; +index : reg sizedef scale + { checksize($2, 2|4); + ffew_2 |= $1<<12 | ($2&0200)<<4 | $3; + } + ; +scale : /* empty */ + { $$ = 0;} + | '*' absexp + { $$ = checkscale($2);} + ; +index_od: /* empty */ + { od_2.typ = S_ABS; od_2.val = (valu_t)0;} + | ',' index + { od_2.typ = S_ABS; od_2.val = (valu_t)0; + mrg_2 |= POST_INDEX; + } + | ',' expr + { od_2 = $2; + RELOMOVE(od_rel2, relonami); + } + | ',' index ',' expr + { od_2 = $4; + mrg_2 |= POST_INDEX; + RELOMOVE(od_rel2, relonami); + } + ; +reg : DREG + | AREG + { $$ = $1 | 010;} + ; +sizedef : /* empty */ + { $$ = SIZE_DEF;} + | SIZE + ; +sizenon : /* empty */ + { $$ = SIZE_NON;} + | SIZE + ; +ea_ea : ea ',' + { mrg_1 = mrg_2; + bd_1 = bd_2; + od_1 = od_2; + ffew_1 = ffew_2; + RELOMOVE(bd_rel1, bd_rel2); + RELOMOVE(od_rel1, od_rel2); + } + ea + ; diff --git a/mach/m68020/as/mach5.c b/mach/m68020/as/mach5.c new file mode 100644 index 00000000..1e232f2e --- /dev/null +++ b/mach/m68020/as/mach5.c @@ -0,0 +1,609 @@ +/* @(#)mach5.c 1.16 */ +/* + * Motorola 68020 auxiliary functions + */ + +/* With pc-relative modes the offset is calulated from the address of the + * extension word. This address is not known until the instruction opcode(s) + * have been emitted. Since this address is unknown, the offset from pc + * cannot be calculated correctly, so it cannot immediately be decided whether + * to use mode 072 (pc-relative with 16 bit offset) or mode 073 (pc_relative + * with possibly 32 bit offset) Because of this, instruction opcodes + * are not really emitted right away, but temporarily stored. This way + * the address of the extension word is known so the offset can be calculated + * correctly and it then can be decided to use mode 072 or 073; this can be + * altered in the instruction opcode, if necessary. For the sake of consistency + * the effective address(es) are also stored temporarily. The instruction is + * then emitted in one go, by emit_instr(). + */ + +emit_instr() +{ + register instr_t *ip; + + for (ip=instr; ipi_word)) { +#ifdef RELOCATION + RELOMOVE(relonami, ip->i_relonami); + if (ip->i_reloinfo) + newrelo(ip->i_relotype, ip->i_reloinfo | RELBR | RELWR); +#endif + } +} + + +#ifdef RELOCATION +t_emit2(word, relotype, reloinfo, relnm) +short word; +short relotype; +valu_t relnm; +#else +t_emit2(word) +short word; +#endif +{ +#ifdef RELOCATION + if (instrp->i_reloinfo = reloinfo) { + RELOMOVE(instrp->i_relonami, relnm); + instrp->i_relotype = relotype; + } +#endif + instrp++->i_word = word; + dot_offset += 2; +} + +#ifdef RELOCATION +t_emit4(words, relotype, reloinfo, relnm) +long words; +short relotype; +valu_t relnm; +#else +t_emit4(words) +long words; +#endif +{ + T_EMIT2((short)(words>>16), relotype, reloinfo, relnm); + T_EMIT2((short)(words), 0, 0, 0); +} + +ea_1(sz, bits) +{ + /* Because displacements come in three sizes (null displacement, + * word and long displacement), each displacement requires + * two bits in the bittable, so two calls to small. Sometimes + * one of these calls is a dummy call. + */ + + register flag; + register sm, sm1, sm2; + + if (mrg_1 > 074) + serror("no specials"); + if ((flag = eamode[mrg_1>>3]) == 0) + if ((flag = eamode[010 + (mrg_1&07)]) == 0) + flag = eamode[015 + (sz>>6)]; + if ((mrg_1 & 070) == 010) + checksize(sz, 2|4); + bits &= ~flag; + if (bits) + serror("bad addressing category"); + if (mrg_1==073 && (ffew_1 & 0200) == 0 && (bd_1.typ & ~S_DOT) == DOTTYP) + bd_1.val -= (DOTVAL + dot_offset); + + if ( (mrg_1==073) || (mrg_1&070)==060 ) { + sm = ( + (mrg_1==073 && (bd_1.typ & ~S_DOT)==DOTTYP) + || + (bd_1.typ == S_ABS) + ); + if (small(sm && fitw(bd_1.val), 2)) { + sm = ( + (sm1 = ((ffew_1 & 0307)==0 && fitb(bd_1.val))) + || + (sm2 = ((ffew_1 & 0307)==0100 && mrg_1==073)) + || + (bd_1.val==0) + ); + if (small(sm,2)) { + if (sm1) { /* brief format extension */ + T_EMIT2((ffew_1&0177000) | lowb(bd_1.val), + 0, 0, 0); + return; + } + if (sm2) { + /* change mode to 072 in opcode word */ + instr->i_word &= ~1; + T_EMIT2(loww(bd_1.val), 0, 0, 0); + return; + } + ffew_1 &= ~040; /* null displacement */ + } + else + ffew_1 &= ~020; /* word displacement */ + } else + sm = small(0,2); /* dummy call */ + + if (ffew_1 & 3) { + sm = (od_1.typ == S_ABS); + if (small(sm && fitw(od_1.val), 2)) + ffew_1 &= small(od_1.val==0, 2) ? ~2 : ~1; + else + sm = small(0,2); /* dummy call */ + } + + assert((ffew_1 & 0410) == 0400); + T_EMIT2(ffew_1, 0, 0, 0); + + assert(ffew_1 & 060); + switch(ffew_1 & 060) { + case 020: + break; + case 040: + T_EMIT2(loww(bd_1.val), 0, 0, 0); + break; + case 060: + T_EMIT4( bd_1.val, + bd_1.typ, + (mrg_1 == 073 && (ffew_1 & 0200) == 0) + ? RELPC|RELO4 + : RELO4, + bd_rel1 + ); + } + + if (ffew_1 & 3) { + switch(ffew_1 & 3) { + case 1: + break; + case 2: + T_EMIT2(loww(od_1.val), 0, 0, 0); + break; + case 3: + T_EMIT4(od_1.val, od_1.typ, RELO4, od_rel1); + } + } + return; /* mode 060 and 073 have been dealt with */ + } + + if (flag & FITW) + if ( + ! fitw(bd_1.val) + && + (mrg_1 != 074 || ! fit16(bd_1.val)) + ) + nofit(); + if (flag & FITB) { + if ( + ! fitb(bd_1.val) + && + (mrg_1 != 074 || ! fit8(bd_1.val)) + ) + nofit(); + if (mrg_1 == 074) + bd_1.val &= 0xFF; + } + if (flag & PUTL) + T_EMIT4(bd_1.val, bd_1.typ, (flag>>8), bd_rel1); + if (flag & PUTW) + T_EMIT2(loww(bd_1.val), bd_1.typ, (flag>>8), bd_rel1); +} + +ea_2(sz, bits) +{ + mrg_1 = mrg_2; + bd_1 = bd_2; + od_1 = od_2; + ffew_1 = ffew_2; + RELOMOVE(bd_rel1, bd_rel2); + RELOMOVE(od_rel1, od_rel2); + ea_1(sz, bits); +} + +checksize(sz, bits) +{ + if ((bits & (1 << (sz>>6))) == 0) + serror("bad size"); +} + +checkscale(val) +valu_t val; +{ + switch(val) { + case 1: return 0; + case 2: return 1<<9; + case 4: return 2<<9; + case 8: return 3<<9; + default: serror("bad scale"); return 0; + } +} + +badoperand() +{ + serror("bad operands"); +} + +shift_op(opc, sz) +{ + if (mrg_1 < 010 && mrg_2 < 010) { + T_EMIT2((opc & 0170470) | sz | mrg_1<<9 | mrg_2, 0, 0, 0); + return; + } + if (bd_1.typ != S_ABS || mrg_1 != 074) { + badoperand(); + return; + } + if (mrg_2 < 010) { + fit(fit3(bd_1.val)); + T_EMIT2((opc & 0170430) | sz | low3(bd_1.val)<<9 | mrg_2,0,0,0); + return; + } + checksize(sz, 2); + fit(bd_1.val == 1); + T_EMIT2((opc & 0177700) | mrg_2, 0, 0, 0); + ea_2(SIZE_W, MEM|ALT); +} + +bitop(opc) +{ + register bits; + + bits = DTA|ALT; + if (opc == 0 && (mrg_1 < 010 || mrg_2 != 074)) + bits = DTA; + if (mrg_1 < 010) { + T_EMIT2(opc | 0400 | mrg_1<<9 | mrg_2, 0, 0, 0); + ea_2(0, bits); + return; + } + if (mrg_1 == 074) { + T_EMIT2(opc | 04000 | mrg_2, 0, 0, 0); + ea_1(SIZE_W, 0); + ea_2(0, bits); + return; + } + badoperand(); +} + +bitfield(opc, extension) +{ + T_EMIT2(opc | mrg_2, 0, 0, 0); + T_EMIT2(extension, 0, 0, 0); + ea_2(SIZE_L, (mrg_2 < 010) ? 0 : (CTR | ALT)); +} + +add(opc, sz) +{ + if ((mrg_2 & 070) == 010) + checksize(sz, 2|4); + if ( + mrg_1 == 074 + && + small( + bd_1.typ==S_ABS && fit3(bd_1.val), + sz==SIZE_L ? 4 : 2 + ) + ) { + T_EMIT2((opc&0400) | 050000 | low3(bd_1.val)<<9 | sz | mrg_2, + 0, 0, 0); + ea_2(sz, ALT); + return; + } + if (mrg_1 == 074 && (mrg_2 & 070) != 010) { + T_EMIT2((opc&03000) | sz | mrg_2, 0, 0, 0); + ea_1(sz, 0); + ea_2(sz, DTA|ALT); + return; + } + if ((mrg_2 & 070) == 010) { + T_EMIT2((opc&0170300) | (mrg_2&7)<<9 | sz<<1 | mrg_1, 0, 0, 0); + ea_1(sz, 0); + return; + } + if (to_dreg(opc, sz, 0)) + return; + if (from_dreg(opc, sz, ALT|MEM)) + return; + badoperand(); +} + +and(opc, sz) +{ + if (mrg_1 == 074 && mrg_2 >= 076) { /* ccr or sr */ + if (sz != SIZE_NON) + checksize(sz, mrg_2==076 ? 1 : 2); + else + sz = (mrg_2==076 ? SIZE_B : SIZE_W); + T_EMIT2((opc&07400) | sz | 074, 0, 0, 0); + ea_1(sz, 0); + return; + } + if (sz == SIZE_NON) + sz = SIZE_DEF; + if (mrg_1 == 074) { + T_EMIT2((opc&07400) | sz | mrg_2, 0, 0, 0); + ea_1(sz, 0); + ea_2(sz, DTA|ALT); + return; + } + if ((opc & 010000) == 0 && to_dreg(opc, sz, DTA)) + return; + if (from_dreg(opc, sz, (opc & 010000) ? DTA|ALT : ALT|MEM)) + return; + badoperand(); +} + +to_dreg(opc, sz, bits) +{ + if ((mrg_2 & 070) != 000) + return(0); + T_EMIT2((opc & 0170000) | sz | (mrg_2&7)<<9 | mrg_1, 0, 0, 0); + ea_1(sz, bits); + return(1); +} + +from_dreg(opc, sz, bits) +{ + if ((mrg_1 & 070) != 000) + return(0); + T_EMIT2((opc & 0170000) | sz | (mrg_1&7)<<9 | 0400 | mrg_2, 0, 0, 0); + ea_2(sz, bits); + return(1); +} + +cmp(sz) +{ + register opc; + + if ((mrg_1&070) == 030 && (mrg_2&070) == 030) { + T_EMIT2(0130410 | sz | (mrg_1&7) | (mrg_2&7)<<9, 0, 0, 0); + return; + } + if (mrg_1 == 074 && (mrg_2 & 070) != 010) { + if (mrg_2==074) + badoperand(); + T_EMIT2(06000 | sz | mrg_2, 0, 0, 0); + ea_1(sz, 0); + ea_2(sz, DTA); + return; + } + if (mrg_2 < 020) { + if (mrg_2 >= 010) { + checksize(sz, 2|4); + opc = 0130300 | sz<<1; + mrg_2 &= 7; + } else + opc = 0130000 | sz; + T_EMIT2(opc | mrg_2<<9 | mrg_1, 0, 0, 0); + ea_1(sz, 0); + return; + } + badoperand(); +} + +link(sz, areg) +{ + if (sz == SIZE_NON) { + if (bd_2.typ == S_ABS && fitw(bd_2.val)) + sz = SIZE_W; + else + sz = SIZE_L; + } + checksize(sz, 2|4); + if (sz == SIZE_W) + T_EMIT2(047120 | areg, 0, 0, 0); + else /* sz == SIZE_L */ + T_EMIT2(044010 | areg, 0, 0, 0); + ea_2(sz, 0); +} + +move(sz) +{ + register opc; + + if (mrg_1 > 074 || mrg_2 > 074) { + move_special(sz); + return; + } + if (sz == SIZE_NON) + sz = SIZE_DEF; + if ( + mrg_2<010 + && + mrg_1==074 + && + sz==SIZE_L + && + small(bd_1.typ==S_ABS && fitb(bd_1.val), 4) + ) { + T_EMIT2(070000 | mrg_2<<9 | lowb(bd_1.val), 0, 0, 0); + return; + } + switch (sz) { + case SIZE_B: opc = 010000; break; + case SIZE_W: opc = 030000; break; + case SIZE_L: opc = 020000; break; + } + T_EMIT2(opc | mrg_1 | (mrg_2&7)<<9 | (mrg_2&070)<<3, 0, 0, 0); + ea_1(sz, 0); + ea_2(sz, ALT); +} + +move_special(sz) +{ + if (mrg_2 >= 076) { + if (sz != SIZE_NON) + checksize(sz, 2); + T_EMIT2(042300 | (mrg_2==076?0:01000) | mrg_1, 0, 0, 0); + ea_1(SIZE_W, DTA); + return; + } + if (mrg_1 >= 076) { + if (sz != SIZE_NON) + checksize(sz, 2); + T_EMIT2(040300 | (mrg_1==076?01000:0) | mrg_2, 0, 0, 0); + ea_2(SIZE_W, DTA|ALT); + return; + } + if (sz != SIZE_NON) + checksize(sz, 4); + if (mrg_1==075 && (mrg_2&070)==010) { + T_EMIT2(047150 | (mrg_2&7), 0, 0, 0); + return; + } + if (mrg_2==075 && (mrg_1&070)==010) { + T_EMIT2(047140 | (mrg_1&7), 0, 0, 0); + return; + } + badoperand(); +} + +movem(dr, sz, regs) +{ + register i; + register r; + + if ((mrg_2>>3) == 04) { + r = regs; regs = 0; + for (i = 0; i < 16; i++) { + regs <<= 1; + if (r & 1) + regs++; + r >>= 1; + } + } + checksize(sz, 2|4); + if ((mrg_2>>3)-3 == dr) + badoperand(); + T_EMIT2(044200 | dr<<10 | (sz & 0200) >> 1 | mrg_2, 0, 0, 0); + T_EMIT2(regs, 0, 0, 0); + i = CTR; + if (dr == 0 && (mrg_2&070) == 040) + i = MEM; + if (dr != 0 && (mrg_2&070) == 030) + i = MEM; + if (dr == 0) + i |= ALT; + ea_2(sz, i); +} + +movep(sz) +{ + checksize(sz, 2|4); + if (mrg_1<010 && (mrg_2&070)==050) { + T_EMIT2(0610 | (sz & 0200)>>1 | mrg_1<<9 | (mrg_2&7), 0, 0, 0); + ea_2(sz, 0); + return; + } + if (mrg_2<010 && (mrg_1&070)==050) { + T_EMIT2(0410 | (sz & 0200)>>1 | mrg_2<<9 | (mrg_1&7), 0, 0, 0); + ea_1(sz, 0); + return; + } + badoperand(); +} + +branch(opc, exp) +expr_t exp; +{ + register sm; + + exp.val -= (DOTVAL + 2); + if ((pass == PASS_2) + && + (exp.val > 0) + && + ((exp.typ & S_DOT) == 0) + ) + exp.val -= DOTGAIN; + sm = fitw(exp.val); + if ((exp.typ & ~S_DOT) != DOTTYP) + sm = 0; + if (small(sm,2)) { + if (small(fitb(exp.val),2)) { + if (exp.val == 0) + T_EMIT2(047161, 0, 0, 0); /* NOP */ + else if (exp.val == -1) { + T_EMIT2(047161, 0, 0, 0); + serror("bad branch offset"); + } else + T_EMIT2(opc | lowb(exp.val), 0, 0, 0); + } else { + T_EMIT2(opc, 0, 0, 0); + T_EMIT2(loww(exp.val), 0, 0, 0); + } + return; + } + sm = small(0,2); /* dummy call; two calls to small per branch */ + T_EMIT2(opc | 0377, 0, 0, 0); /* 4 byte offset */ + T_EMIT4(exp.val, exp.typ, RELPC|RELO4, relonami); +} + +cpbcc(opc, exp) +expr_t exp; +{ + register sm; + + exp.val -= (DOTVAL + 2); + if ((pass == PASS_2) + && + (exp.val > 0) + && + ((exp.typ & S_DOT) == 0) + ) + exp.val -= DOTGAIN; + sm = fitw(exp.val); + if ((exp.typ & ~S_DOT) != DOTTYP) + sm = 0; + if (small(sm,2)) { + T_EMIT2(opc, 0, 0, 0); + T_EMIT2(loww(exp.val), 0, 0, 0); + return; + } + + T_EMIT2(opc | 0100, 0, 0, 0); /* 4 byte offset */ + /* NB: no coprocessor defined extension words are emitted */ + T_EMIT4(exp.val, exp.typ, RELPC|RELO4, relonami); +} + +ea7071(sz) +{ + mrg_2 = 071; + switch (sz) { + case SIZE_B: + badoperand(); + case SIZE_W: + mrg_2 = 070; + case SIZE_L: + return; + case SIZE_NON: + break; + } + /* If this absolute address is in program space, and if we + * can assume that the only references to program space are made + * by instructins like 'jsr', 'jmp', 'lea' and 'pea', it might + * be possible to use a (PC,d16) effective address mode instead + * of absolute long. This is done here. If this scheme is in + * some way undesirable (e.g. when references to program space + * are made by instructions with more than one opcode word or by + * second effective addresses in instructions), the rest + * of this routine can simply be removed and replaced by the + * next two lines (which of course are in comment brackets now). + if (small(bd_2.typ == S_ABS && fitw(bd_2.val), 2)) + mrg_2 = 070; + */ + if (pass == PASS_1) { + /* Reserve a bit in the bittable; in the following + * passes one call to small() will be done, but know yet + * which one, because bd_2.typ cannot be trusted yet. + */ + small(0, 2); + return; + } + if ((bd_2.typ & ~S_DOT) == DOTTYP) { + if (small(fitw(bd_2.val-(DOTVAL+2)), 2)) { + bd_2.val -= (DOTVAL+2); + mrg_2 = 072; + } + } else + if (small(bd_2.typ == S_ABS && fitw(bd_2.val), 2)) + mrg_2 = 070; +} From 04fe54d2705ed51af5e5aaa568cff8fa3f98c001 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 29 Jan 1987 22:10:18 +0000 Subject: [PATCH 0618/1625] Initial revision --- mach/m68020/libem/LIST | 24 +++++++++++ mach/m68020/libem/Makefile | 28 ++++++++++++ mach/m68020/libem/aar.s | 32 ++++++++++++++ mach/m68020/libem/cii.s | 27 ++++++++++++ mach/m68020/libem/cmi.s | 28 ++++++++++++ mach/m68020/libem/cms.s | 25 +++++++++++ mach/m68020/libem/cmu.s | 28 ++++++++++++ mach/m68020/libem/compmodule | 4 ++ mach/m68020/libem/csa.s | 25 +++++++++++ mach/m68020/libem/csb.s | 28 ++++++++++++ mach/m68020/libem/cuu.s | 25 +++++++++++ mach/m68020/libem/cvf.s | 20 +++++++++ mach/m68020/libem/dia.s | 48 +++++++++++++++++++++ mach/m68020/libem/end.s | 20 +++++++++ mach/m68020/libem/exg.s | 20 +++++++++ mach/m68020/libem/fat.s | 11 +++++ mach/m68020/libem/inn.s | 32 ++++++++++++++ mach/m68020/libem/lar.s | 52 ++++++++++++++++++++++ mach/m68020/libem/los.s | 35 +++++++++++++++ mach/m68020/libem/mon.s | 17 ++++++++ mach/m68020/libem/nop.s | 20 +++++++++ mach/m68020/libem/printf.s | 83 ++++++++++++++++++++++++++++++++++++ mach/m68020/libem/sar.s | 54 +++++++++++++++++++++++ mach/m68020/libem/set.s | 33 ++++++++++++++ mach/m68020/libem/shp.s | 26 +++++++++++ mach/m68020/libem/sts.s | 34 +++++++++++++++ mach/m68020/libem/trp.s | 40 +++++++++++++++++ 27 files changed, 819 insertions(+) create mode 100644 mach/m68020/libem/LIST create mode 100644 mach/m68020/libem/Makefile create mode 100644 mach/m68020/libem/aar.s create mode 100644 mach/m68020/libem/cii.s create mode 100644 mach/m68020/libem/cmi.s create mode 100644 mach/m68020/libem/cms.s create mode 100644 mach/m68020/libem/cmu.s create mode 100755 mach/m68020/libem/compmodule create mode 100644 mach/m68020/libem/csa.s create mode 100644 mach/m68020/libem/csb.s create mode 100644 mach/m68020/libem/cuu.s create mode 100644 mach/m68020/libem/cvf.s create mode 100644 mach/m68020/libem/dia.s create mode 100644 mach/m68020/libem/end.s create mode 100644 mach/m68020/libem/exg.s create mode 100644 mach/m68020/libem/fat.s create mode 100644 mach/m68020/libem/inn.s create mode 100644 mach/m68020/libem/lar.s create mode 100644 mach/m68020/libem/los.s create mode 100644 mach/m68020/libem/mon.s create mode 100644 mach/m68020/libem/nop.s create mode 100644 mach/m68020/libem/printf.s create mode 100644 mach/m68020/libem/sar.s create mode 100644 mach/m68020/libem/set.s create mode 100644 mach/m68020/libem/shp.s create mode 100644 mach/m68020/libem/sts.s create mode 100644 mach/m68020/libem/trp.s diff --git a/mach/m68020/libem/LIST b/mach/m68020/libem/LIST new file mode 100644 index 00000000..8479e1ad --- /dev/null +++ b/mach/m68020/libem/LIST @@ -0,0 +1,24 @@ +libem_s.a +aar.s +lar.s +sar.s +csa.s +csb.s +shp.s +set.s +inn.s +fat.s +trp.s +mon.s +nop.s +dia.s +printf.s +cii.s +cuu.s +cmi.s +cms.s +cmu.s +cvf.s +exg.s +los.s +sts.s diff --git a/mach/m68020/libem/Makefile b/mach/m68020/libem/Makefile new file mode 100644 index 00000000..d7303de4 --- /dev/null +++ b/mach/m68020/libem/Makefile @@ -0,0 +1,28 @@ +# $Header$ +MACH=m68020 +all: libem_o.a end.o + +install: all + ../../install libem_o.a tail_em + ../../install end.o end_em + +cmp: all + -../../compare libem_o.a tail_em + -../../compare end.o end_em + +end.o: end.s + $(MACH) -I../../../h -c end.s + +libem_o.a: libem_s.a + ASAR=aal ; export ASAR ;\ + march . libem_o.a + +clean: + rm -f *.o libem_o.a + +opr : + make pr | opr + +pr: + @arch pv libem_s.a | pr -h `pwd`/libem_s.a + @pr `pwd`/end.s diff --git a/mach/m68020/libem/aar.s b/mach/m68020/libem/aar.s new file mode 100644 index 00000000..b8d666c9 --- /dev/null +++ b/mach/m68020/libem/aar.s @@ -0,0 +1,32 @@ +.define .aar +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text + +.aar: ! (on entry d0 contains the integer size in the descriptor) + + cmp.l #4, d0 + beq 9f + move.l #EILLINS, -(sp) + jmp (.fatal) +9: + ! register usage: + ! a0: descriptor address + ! a1: return address + ! d0: index + + ! The address is calculated by taking the relative index + ! (index - lower bound), multiplying that with the element + ! size and adding the result to the array base address. + + move.l (sp)+, a1 ! return address + move.l (sp)+, a0 ! descriptor address + move.l (sp)+, d0 ! index + sub.l (a0), d0 ! relative index + muls.l (8,a0), d0 + move.l (sp)+, a0 ! array base address + add.l d0, a0 ! address of array element + jmp (a1) ! return +.align 2 diff --git a/mach/m68020/libem/cii.s b/mach/m68020/libem/cii.s new file mode 100644 index 00000000..01757dfc --- /dev/null +++ b/mach/m68020/libem/cii.s @@ -0,0 +1,27 @@ +.define .cii +.sect .text +.sect .rom +.sect .data +.sect .bss + +.sect .text +.cii: + move.l (sp)+, a0 ! return address + move.l (sp)+, d0 ! destination size + sub.l (sp)+, d0 ! destination - source size + bgt 1f + sub.l d0, sp ! pop extra bytes + jmp (a0) +1: + clr.l d1 + tst.l (sp) + bne 4f + not.l d1 ! d1 contains sign of source +4: + asr.l #2, d0 + sub.l #1, d0 +2: + move.l d1, -(sp) + dbf d0, 2b + jmp (a0) +.align 2 diff --git a/mach/m68020/libem/cmi.s b/mach/m68020/libem/cmi.s new file mode 100644 index 00000000..4846142b --- /dev/null +++ b/mach/m68020/libem/cmi.s @@ -0,0 +1,28 @@ +.define .cmi +.sect .text +.sect .rom +.sect .data +.sect .bss + +.sect .text + ! on entry d0: # bytes in 1 block + ! on exit d0: result +.cmi: + move.l (sp)+, d2 ! return address + move.l sp, a0 ! address of top block + lea (sp,d0.l), a1 ! address of lower block + move.l d0, d1 + asr.l #2, d0 +1: + cmp.l (a0)+, (a1)+ + bne 2f + sub.l #1, d0 + bne 1b +2: + bge 3f + neg.l d0 ! less +3: + lea (sp,d1.l*2), sp ! new sp; two blocks popped + move.l d2,a0 + jmp (a0) ! return +.align 2 diff --git a/mach/m68020/libem/cms.s b/mach/m68020/libem/cms.s new file mode 100644 index 00000000..ae9945e3 --- /dev/null +++ b/mach/m68020/libem/cms.s @@ -0,0 +1,25 @@ +.define .cms +.sect .text +.sect .rom +.sect .data +.sect .bss + +.sect .text + ! d0 contains set size + ! on exit d0 is zero for equal, non-zero for not equal +.cms: + move.l (sp)+, d2 ! return address + move.l sp, a0 ! address of top block + lea (sp,d0.l), a1 ! address of lower block + move.l d0, d1 + asr.l #2, d0 +1: + cmp.l (a0)+, (a1)+ + bne 2f + sub.l #1, d0 + bne 1b +2: + lea (sp,d1.l*2), sp ! new sp; two blocks popped + move.l d2,a0 + jmp (a0) +.align 2 diff --git a/mach/m68020/libem/cmu.s b/mach/m68020/libem/cmu.s new file mode 100644 index 00000000..8faa6267 --- /dev/null +++ b/mach/m68020/libem/cmu.s @@ -0,0 +1,28 @@ +.define .cmu +.sect .text +.sect .rom +.sect .data +.sect .bss + +.sect .text + ! on entry d0: # bytes in 1 block + ! on exit d0: result +.cmu: + move.l (sp)+, d2 ! return address + move.l sp, a0 ! address of top block + lea (sp,d0.l), a1 ! address of lower block + move.l d0, d1 + asr.l #2, d0 +1: + cmp.l (a0)+, (a1)+ + bne 2f + sub.l #1, d0 + bne 1b ! note: on equal carry is set +2: + bcc 3f + neg.l d0 ! less +3: + lea (sp,d1.l*2), sp ! new sp; two blocks popped + move.l d2, a0 + jmp (a0) +.align 2 diff --git a/mach/m68020/libem/compmodule b/mach/m68020/libem/compmodule new file mode 100755 index 00000000..e42fb932 --- /dev/null +++ b/mach/m68020/libem/compmodule @@ -0,0 +1,4 @@ +if ${MACH?} -c $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 +fi diff --git a/mach/m68020/libem/csa.s b/mach/m68020/libem/csa.s new file mode 100644 index 00000000..1e16c730 --- /dev/null +++ b/mach/m68020/libem/csa.s @@ -0,0 +1,25 @@ +.define .csa +.sect .text +.sect .rom +.sect .data +.sect .bss + +.sect .text + +.csa: + move.l (sp)+, a0 ! jump table address + move.l (a0)+, a1 ! default address + move.l (sp)+, d0 ! index + sub.l (a0)+, d0 ! index - lower bound + blt 1f + cmp.l (a0)+, d0 ! rel. index, upper - lower bound + bgt 1f + move.l (a0,d0.l*4), a1 ! jump address +1: + move.l a1, d0 + beq 2f + jmp (a1) ! jump to specified address +2: + move.l #ECASE, -(sp) + jmp (.fatal) +.align 2 diff --git a/mach/m68020/libem/csb.s b/mach/m68020/libem/csb.s new file mode 100644 index 00000000..e61fc4fa --- /dev/null +++ b/mach/m68020/libem/csb.s @@ -0,0 +1,28 @@ +.define .csb +.sect .text +.sect .rom +.sect .data +.sect .bss + +.sect .text + +.csb: + move.l (sp)+, a0 ! case descriptor + move.l (sp)+, d0 ! index + move.l (a0)+, a1 ! default jump address + move.l (a0)+, d1 ! # entries + beq 3f + sub.l #1, d1 +1: + cmp.l (a0,d1.w*8), d0 + dbeq d1, 1b + bne 3f + move.l (4,a0,d1.w*8), a1 ! jump address +3: + move.l a1, d0 + beq 4f + jmp (a1) +4: + move.l #ECASE, -(sp) + jmp (.fatal) +.align 2 diff --git a/mach/m68020/libem/cuu.s b/mach/m68020/libem/cuu.s new file mode 100644 index 00000000..93917ddf --- /dev/null +++ b/mach/m68020/libem/cuu.s @@ -0,0 +1,25 @@ +.define .ciu, .cui, .cuu +.sect .text +.sect .rom +.sect .data +.sect .bss + +.sect .text + ! only converts between sizes of multiples of four +.ciu: +.cui: +.cuu: + move.l (sp)+, a0 ! return address + move.l (sp)+, d0 ! destination size + sub.l (sp)+, d0 + bgt 1f + sub.l d0, sp + jmp (a0) +1: + asr.l #2, d0 + sub.l #1, d0 +2: + clr.l -(sp) + dbf d0, 2b + jmp (a0) +.align 2 diff --git a/mach/m68020/libem/cvf.s b/mach/m68020/libem/cvf.s new file mode 100644 index 00000000..d6cc588b --- /dev/null +++ b/mach/m68020/libem/cvf.s @@ -0,0 +1,20 @@ +.define .cfi, .cif,.cfu,.cuf,.cff +.sect .text +.sect .rom +.sect .data +.sect .bss + + .sect .text + + ! this is a dummy float conversion routine +.cfi: +.cif: +.cfu: +.cuf: +.cff: + move.l (sp)+, a0 ! return address + move.l (sp)+, d0 ! destination size + sub.l (sp)+, d0 ! diff. in sizes + sub.l d0, sp + jmp (a0) +.align 2 diff --git a/mach/m68020/libem/dia.s b/mach/m68020/libem/dia.s new file mode 100644 index 00000000..8d482b88 --- /dev/null +++ b/mach/m68020/libem/dia.s @@ -0,0 +1,48 @@ +.define .diagnos +.sect .text +.sect .rom +.sect .data +.sect .bss + +space = 040 +del = 0177 + +.sect .data +.range: .data1 space, del-1 +.align 2 + +.sect .text +.diagnos: + movem.l d0/d1/d2/a0, -(sp) + move.l (.lino), -(sp) + move.l (.filn), d2 + beq 1f + move.l d2, a0 + move.l #40, d0 +3: + move.b (a0)+, d1 + beq 2f + cmp2.b (.range), d1 + bcs 1f + dbf d0, 3b +2: + move.l d2, -(sp) + pea (fmt) + jsr (_printf) + lea (8, sp), sp + move.l (28, sp), (sp) + jsr (_printf) + lea (4, sp), sp + movem.l (sp)+, d0/d1/d2/a0 + move.l (sp), (4, sp) + lea (4, sp), sp + rts + +1: + move.l #unknwn, d2 + bra 2b + +.sect .data +fmt: .asciz "%s, line %d: " +unknwn: .asciz "unknown file" +.align 2 diff --git a/mach/m68020/libem/end.s b/mach/m68020/libem/end.s new file mode 100644 index 00000000..bdd78723 --- /dev/null +++ b/mach/m68020/libem/end.s @@ -0,0 +1,20 @@ +.define endtext,enddata,endbss,_etext,_edata,_end +.sect .text + .align 4 +.sect .rom + .align 4 +.sect .data + .align 4 +.sect .bss + .align 4 +.sect .end ! only for declaration of _end and endbss. + + .sect .text +endtext: +_etext: + .sect .data +enddata: +_edata: + .sect .end +_end: +endbss: diff --git a/mach/m68020/libem/exg.s b/mach/m68020/libem/exg.s new file mode 100644 index 00000000..4abbf97b --- /dev/null +++ b/mach/m68020/libem/exg.s @@ -0,0 +1,20 @@ +.define .exg +.sect .text +.sect .rom +.sect .data +.sect .bss + +.sect .text + ! d0 : exchange size in bytes +.exg: + lea (4,sp,d0), a0 ! address of bottom block + lea (4,sp), a1 ! address of top block + asr.l #2, d0 + sub.l #1, d0 +1: + move.l (a1), d1 + move.l (a0), (a1)+ + move.l d1, (a0)+ + dbf d0, 1b + rts +.align 2 diff --git a/mach/m68020/libem/fat.s b/mach/m68020/libem/fat.s new file mode 100644 index 00000000..378dcdd9 --- /dev/null +++ b/mach/m68020/libem/fat.s @@ -0,0 +1,11 @@ +.define .fatal +.sect .text +.sect .rom +.sect .data +.sect .bss + + .sect .text +.fatal: + jsr (.trp) + jmp (EXIT) +.align 2 diff --git a/mach/m68020/libem/inn.s b/mach/m68020/libem/inn.s new file mode 100644 index 00000000..8acd9945 --- /dev/null +++ b/mach/m68020/libem/inn.s @@ -0,0 +1,32 @@ +.define .inn +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text + +.inn: ! d0 bitnumber + ! d1 setsize in bytes + ! on exit: 0 or 1 in d0 + + move.l d2, -(sp) + move.l d0, d2 + asr.l #3, d2 ! offset from sp in bytes + eor.l #3, d2 ! longs are stored in high-to-low order + cmp.l d1, d2 + bge 1f ! bitnumber too large + btst d0, (8,sp,d2.l) + beq 2f + move.l #1, d0 + bra 3f +1: + move.l #ESET, -(sp) + jsr (.trp) +2: + clr.l d0 +3: + move.l (sp)+, d2 + move.l (sp)+, a0 ! return address + add.l d1, sp ! pop bitset + jmp (a0) ! return +.align 2 diff --git a/mach/m68020/libem/lar.s b/mach/m68020/libem/lar.s new file mode 100644 index 00000000..4a9e5046 --- /dev/null +++ b/mach/m68020/libem/lar.s @@ -0,0 +1,52 @@ +.define .lar +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text + ! (on entry d0 contains the integer size in the descriptor) +.lar: + cmp.l #4, d0 + beq 9f + move.l #EILLINS, -(sp) + jmp (.fatal) +9: + ! register usage: + ! a0: descriptor address + ! a1: base address + ! d0: index + ! d1: # bytes / element + ! d2: save return address + + ! For address calculation; see comment in 'aar.s'. + + move.l (sp)+, d2 ! return address + move.l (sp)+, a0 ! descriptor address + move.l (sp)+, d0 ! index + move.l (sp)+, a1 ! array base address + sub.l (a0), d0 ! relative index + move.l (8,a0), d1 ! # bytes / element + cmp.l #1, d1 + bne 2f + clr.l -(sp) + move.b (a1,d0.l), (3,sp) ! one byte element + bra 5f +2: + cmp.l #2, d1 + bne 4f + clr.l -(sp) + move.w (a1,d0.l*2), (2,sp) ! two byte element + bra 5f +4: + muls.l d1, d0 + add.l d0, a1 ! address of 4n byte element + add.l d1, a1 ! because of predecrement + asr.l #2, d1 + sub.l #1, d1 +1: + move.l -(a1), -(sp) + dbf d1, 1b +5: + move.l d2,a0 + jmp (a0) +.align 2 diff --git a/mach/m68020/libem/los.s b/mach/m68020/libem/los.s new file mode 100644 index 00000000..3aa2d016 --- /dev/null +++ b/mach/m68020/libem/los.s @@ -0,0 +1,35 @@ +.define .los +.sect .text +.sect .rom +.sect .data +.sect .bss + + ! d0 : # bytes + ! a0 : source address + ! a1 : return address +.sect .text +.los: + move.l (sp)+, a1 + move.l (sp)+, d0 + move.l (sp)+, a0 + cmp.l #1, d0 + bne 1f + clr.l -(sp) + move.b (a0), (3,sp) !1 byte + bra 3f +1: + cmp.l #2, d0 + bne 2f + clr.l -(sp) + move.w (a0), (2,sp) !2 bytes + bra 3f +2: + add.l d0, a0 !>=4 bytes + asr.l #2, d0 + sub.l #1, d0 + +4: move.l -(a0), -(sp) + dbf d0, 4b +3: + jmp (a1) +.align 2 diff --git a/mach/m68020/libem/mon.s b/mach/m68020/libem/mon.s new file mode 100644 index 00000000..5c5f3698 --- /dev/null +++ b/mach/m68020/libem/mon.s @@ -0,0 +1,17 @@ +.define .mon +.sect .text +.sect .rom +.sect .data +.sect .bss + +.sect .text +.mon: + move.l (sp)+,a0 + pea (fmt) + jsr (.diagnos) + add.l #8, sp + jmp (EXIT) + +.sect .data +fmt: .asciz "system call %d not implemented\n" +.align 2 diff --git a/mach/m68020/libem/nop.s b/mach/m68020/libem/nop.s new file mode 100644 index 00000000..180b6412 --- /dev/null +++ b/mach/m68020/libem/nop.s @@ -0,0 +1,20 @@ +.define .nop +.sect .text +.sect .rom +.sect .data +.sect .bss + +.sect .text +.nop: + move.l (.limhp),-(sp) + move.l (.reghp),-(sp) + pea (12, sp) + move.l (.lino),-(sp) + pea (fmt) + jsr (.diagnos) + lea (20, sp), sp + rts + +.sect .data +fmt: .asciz "test %d, sp 0x%x, .reghp 0x%x, .limhp 0x%x.\n" +.align 2 diff --git a/mach/m68020/libem/printf.s b/mach/m68020/libem/printf.s new file mode 100644 index 00000000..088a08a9 --- /dev/null +++ b/mach/m68020/libem/printf.s @@ -0,0 +1,83 @@ +.define _printf, _putchar, _getal, _char +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .bss +_getal: + .space 12 +_char: + .space 1 + .align 2 +.sect .data +hexs: + .ascii "0123456789abcdef" + .align 2 +.sect .text +_printf: + movem.l d0/d1/d2/a0/a1/a2/a3/a4/a5/a6, -(sp) + lea (44, sp), a6 ! a6 <- address of arguments + move.l (a6)+, a5 ! a5 <- address of format +next: move.b (a5)+, d0 + beq out + cmp.b #'%', d0 + beq procnt +put: move.l d0, -(sp) + jsr (_putchar) ! long argument on stack + tst.l (sp)+ + bra next + +procnt: move.b (a5)+, d0 + cmp.b #'d', d0 ! NOTE: %d means unsigned. + beq digit + cmp.b #'x', d0 + beq hex + cmp.b #'s', d0 + beq string + cmp.b #'%', d0 ! second % has to be printed. + beq put + tst.b -(a5) ! normal char should be printed + bra next + +string: move.l (a6)+, a2 ! a2 <- address of string +sloop: move.b (a2)+, d0 + beq next + move.l d0, -(sp) + jsr (_putchar) ! long argument on stack + tst.l (sp)+ + bra sloop + +digit: move.l (a6)+, d1 ! d1 <- integer + move.l #_getal+12, a2 ! a2 <- ptr to last part of buf + clr.b -(a2) ! stringterminator +1: divul.l #10, d2:d1 ! d1 <- qotient; d2 <- remainder + add.l #'0', d2 + move.b d2, -(a2) + tst.l d1 ! if quotient = 0 then ready + bne 1b + bra sloop ! print digitstring. + +hex: move.l (a6)+, d1 ! d1 <- integer + move.l #_getal+12, a2 ! a2 <- ptr to last part of buf + clr.b -(a2) ! stringterminator + move.l #7, d2 ! loop control +1: move.l d1, d0 + and.l #15, d0 + move.b (hexs,d0.w), -(a2) ! hex digit + asr.l #4, d1 + dbf d2, 1b + bra sloop + +out: + movem.l (sp)+, d0/d1/d2/a0/a1/a2/a3/a4/a5/a6 + rts + + +_putchar: + move.l #1, -(sp) + pea (11,sp) + move.l #1, -(sp) + jsr (_write) + lea (12, sp), sp + rts +.align 2 diff --git a/mach/m68020/libem/sar.s b/mach/m68020/libem/sar.s new file mode 100644 index 00000000..251421fb --- /dev/null +++ b/mach/m68020/libem/sar.s @@ -0,0 +1,54 @@ +.define .sar +.sect .text +.sect .rom +.sect .data +.sect .bss + +.sect .text + ! (on entry d0 contains the integer size in the descriptor) +.sar: + cmp.l #4, d0 + beq 9f + move.l #EILLINS, -(sp) + jmp (.fatal) +9: + ! register usage: + ! a0: descriptor address + ! a1: base address + ! d0: index + ! d1: # bytes / element + ! d2: return address + + ! For address calculation; see comment in 'aar.s'. + ! If the element size is a fraction of EM_WSIZE (4) + ! the calculation is done by adding. + + move.l (sp)+, d2 ! return address + move.l (sp)+, a0 + move.l (sp)+, d0 + move.l (sp)+, a1 + sub.l (a0), d0 + move.l (8,a0), d1 ! # bytes / element + cmp.l #1, d1 + bne 2f + move.l (sp)+, d1 + move.b d1, (a1,d0.l) ! store one byte element + bra 5f +2: + cmp.l #2, d1 + bne 4f + move.l (sp)+, d1 + move.w d1, (a1,d0.l*2) ! store two byte element + bra 5f +4: ! here: 4n byte element + muls.l d1, d0 + add.l d0, a1 ! address of 4n byte element + asr.l #2, d1 + sub.l #1, d1 +1: + move.l (sp)+, (a1)+ + dbf d1, 1b +5: + move.l d2,a0 + jmp (a0) +.align 2 diff --git a/mach/m68020/libem/set.s b/mach/m68020/libem/set.s new file mode 100644 index 00000000..c2a94be6 --- /dev/null +++ b/mach/m68020/libem/set.s @@ -0,0 +1,33 @@ +.define .set +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text + +.set: ! d0 bitnumber + ! d1 setsize in bytes + + move.l (sp)+, a0 + move.l d2, a1 + move.l d1, d2 + asr.l #2, d2 + sub.l #1, d2 +1: + clr.l -(sp) + dbf d2, 1b + + move.l d0, d2 + asr.l #3, d2 ! offset from sp in bytes + eor.l #3, d2 ! longs are stored in high-to-low order + cmp.l d1, d2 + blt 2f + move.l #ESET, -(sp) ! bitnumber too large + move.l a1, d2 + move.l a0, -(sp) + jmp (.trp) +2: + bset d0, (sp, d2.l) + move.l a1, d2 + jmp (a0) ! return +.align 2 diff --git a/mach/m68020/libem/shp.s b/mach/m68020/libem/shp.s new file mode 100644 index 00000000..c7b1945f --- /dev/null +++ b/mach/m68020/libem/shp.s @@ -0,0 +1,26 @@ +.define .strhp +.sect .text +.sect .rom +.sect .data +.sect .bss + + .sect .text +.strhp: + move.l (sp)+, a0 + move.l (sp), d1 ! new heap pointer + cmp.l (.limhp), d1 ! compare new heap pointer with limit + blt 1f + add.l #0x400, d1 + and.l #~0x3ff, d1 + move.l d1, (.limhp) + move.l d1, -(sp) + jsr (_brk) ! allocate 1K bytes of extra storage + add.l #4, sp + bcs 2f +1: + move.l (sp)+, (.reghp) ! store new value + jmp (a0) ! return +2: + move.l #EHEAP, -(sp) + jmp (.fatal) +.align 2 diff --git a/mach/m68020/libem/sts.s b/mach/m68020/libem/sts.s new file mode 100644 index 00000000..a1685f6e --- /dev/null +++ b/mach/m68020/libem/sts.s @@ -0,0 +1,34 @@ +.define .sts +.sect .text +.sect .rom +.sect .data +.sect .bss + + ! d0 : # bytes + ! a0 : destination address + ! a1 : return address +.sect .text +.sts: + move.l (sp)+, a1 + move.l (sp)+, d0 + move.l (sp)+, a0 + cmp.l #1, d0 + bne 1f + move.l (sp)+, d0 + move.b d0, (a0) + bra 4f + +1: cmp.l #2, d0 + bne 2f + move.l (sp)+, d0 + move.w d0, (a0) + bra 4f +2: + asr.l #2, d0 + sub.l #1, d0 +3: + move.l (sp)+, (a0)+ + dbf d0, 3b +4: + jmp (a1) ! return +.align 2 diff --git a/mach/m68020/libem/trp.s b/mach/m68020/libem/trp.s new file mode 100644 index 00000000..f5515e96 --- /dev/null +++ b/mach/m68020/libem/trp.s @@ -0,0 +1,40 @@ +.define .trp +.sect .text +.sect .rom +.sect .data +.sect .bss + + .sect .text +.trp: + movem.l d0/d1/a0, -(sp) + move.l (16, sp), a0 ! return address + move.l (20, sp), d0 ! error number + move.l a0, (20, sp) + move.l d0, (16, sp) + move.l d0,-(sp) + cmp.l #16, d0 + bcc 1f + move.l (.trpim), d1 + btst d0, d1 + bne 3f +1: + move.l (.trppc), a0 + move.l a0, d0 + beq 9f + clr.l (.trppc) + jsr (a0) +3: + add.l #4, sp + movem.l (sp)+, d0/d1/a0 + add.l #4, sp + rts +9: + pea (fmt) + jsr (.diagnos) + lea (4, sp), sp + jsr (__cleanup) + jmp (EXIT) + +.sect .data +fmt: .asciz "trap %d called\n" +.align 2 From dd82e72cd14c9b54dddd9301598848a89c43992e Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 29 Jan 1987 22:36:35 +0000 Subject: [PATCH 0619/1625] Initial revision --- mach/m68020/libsys/README | 66 +++++++++++++++++++++++++++++++++++ mach/m68020/libsys/_exit.s | 10 ++++++ mach/m68020/libsys/access.s | 9 +++++ mach/m68020/libsys/acct.s | 9 +++++ mach/m68020/libsys/alarm.s | 10 ++++++ mach/m68020/libsys/brk.s | 25 +++++++++++++ mach/m68020/libsys/call.s | 28 +++++++++++++++ mach/m68020/libsys/chdir.s | 9 +++++ mach/m68020/libsys/chmod.s | 9 +++++ mach/m68020/libsys/chown.s | 9 +++++ mach/m68020/libsys/chroot.s | 9 +++++ mach/m68020/libsys/cleanup.s | 12 +++++++ mach/m68020/libsys/close.s | 9 +++++ mach/m68020/libsys/compmodule | 4 +++ mach/m68020/libsys/creat.s | 9 +++++ mach/m68020/libsys/dup.s | 9 +++++ mach/m68020/libsys/dup2.s | 10 ++++++ mach/m68020/libsys/errno.s | 9 +++++ mach/m68020/libsys/execl.s | 16 +++++++++ mach/m68020/libsys/execve.s | 9 +++++ mach/m68020/libsys/exit.s | 16 +++++++++ mach/m68020/libsys/fcntl.s | 9 +++++ mach/m68020/libsys/fork.s | 17 +++++++++ mach/m68020/libsys/fstat.s | 9 +++++ mach/m68020/libsys/ftime.s | 9 +++++ mach/m68020/libsys/getegid.s | 11 ++++++ mach/m68020/libsys/getgid.s | 10 ++++++ mach/m68020/libsys/getpid.s | 10 ++++++ mach/m68020/libsys/getuid.s | 10 ++++++ mach/m68020/libsys/gtty.s | 9 +++++ mach/m68020/libsys/ioctl.s | 9 +++++ mach/m68020/libsys/kill.s | 9 +++++ mach/m68020/libsys/link.s | 9 +++++ mach/m68020/libsys/lock.s | 9 +++++ mach/m68020/libsys/lseek.s | 9 +++++ mach/m68020/libsys/mknod.s | 9 +++++ mach/m68020/libsys/mount.s | 9 +++++ mach/m68020/libsys/nice.s | 9 +++++ mach/m68020/libsys/open.s | 9 +++++ mach/m68020/libsys/pause.s | 9 +++++ mach/m68020/libsys/pipe.s | 18 ++++++++++ mach/m68020/libsys/profil.s | 10 ++++++ mach/m68020/libsys/ptrace.s | 11 ++++++ mach/m68020/libsys/read.s | 9 +++++ mach/m68020/libsys/setgid.s | 9 +++++ mach/m68020/libsys/setuid.s | 9 +++++ mach/m68020/libsys/signal.s | 22 ++++++++++++ mach/m68020/libsys/stat.s | 9 +++++ mach/m68020/libsys/stime.s | 10 ++++++ mach/m68020/libsys/stty.s | 9 +++++ mach/m68020/libsys/sync.s | 10 ++++++ mach/m68020/libsys/time.s | 14 ++++++++ mach/m68020/libsys/times.s | 10 ++++++ mach/m68020/libsys/umask.s | 9 +++++ mach/m68020/libsys/umount.s | 9 +++++ mach/m68020/libsys/unlink.s | 9 +++++ mach/m68020/libsys/utime.s | 9 +++++ mach/m68020/libsys/wait.s | 15 ++++++++ mach/m68020/libsys/write.s | 9 +++++ 59 files changed, 690 insertions(+) create mode 100644 mach/m68020/libsys/README create mode 100644 mach/m68020/libsys/_exit.s create mode 100644 mach/m68020/libsys/access.s create mode 100644 mach/m68020/libsys/acct.s create mode 100644 mach/m68020/libsys/alarm.s create mode 100644 mach/m68020/libsys/brk.s create mode 100644 mach/m68020/libsys/call.s create mode 100644 mach/m68020/libsys/chdir.s create mode 100644 mach/m68020/libsys/chmod.s create mode 100644 mach/m68020/libsys/chown.s create mode 100644 mach/m68020/libsys/chroot.s create mode 100644 mach/m68020/libsys/cleanup.s create mode 100644 mach/m68020/libsys/close.s create mode 100755 mach/m68020/libsys/compmodule create mode 100644 mach/m68020/libsys/creat.s create mode 100644 mach/m68020/libsys/dup.s create mode 100644 mach/m68020/libsys/dup2.s create mode 100644 mach/m68020/libsys/errno.s create mode 100644 mach/m68020/libsys/execl.s create mode 100644 mach/m68020/libsys/execve.s create mode 100644 mach/m68020/libsys/exit.s create mode 100644 mach/m68020/libsys/fcntl.s create mode 100644 mach/m68020/libsys/fork.s create mode 100644 mach/m68020/libsys/fstat.s create mode 100644 mach/m68020/libsys/ftime.s create mode 100644 mach/m68020/libsys/getegid.s create mode 100644 mach/m68020/libsys/getgid.s create mode 100644 mach/m68020/libsys/getpid.s create mode 100644 mach/m68020/libsys/getuid.s create mode 100644 mach/m68020/libsys/gtty.s create mode 100644 mach/m68020/libsys/ioctl.s create mode 100644 mach/m68020/libsys/kill.s create mode 100644 mach/m68020/libsys/link.s create mode 100644 mach/m68020/libsys/lock.s create mode 100644 mach/m68020/libsys/lseek.s create mode 100644 mach/m68020/libsys/mknod.s create mode 100644 mach/m68020/libsys/mount.s create mode 100644 mach/m68020/libsys/nice.s create mode 100644 mach/m68020/libsys/open.s create mode 100644 mach/m68020/libsys/pause.s create mode 100644 mach/m68020/libsys/pipe.s create mode 100644 mach/m68020/libsys/profil.s create mode 100644 mach/m68020/libsys/ptrace.s create mode 100644 mach/m68020/libsys/read.s create mode 100644 mach/m68020/libsys/setgid.s create mode 100644 mach/m68020/libsys/setuid.s create mode 100644 mach/m68020/libsys/signal.s create mode 100644 mach/m68020/libsys/stat.s create mode 100644 mach/m68020/libsys/stime.s create mode 100644 mach/m68020/libsys/stty.s create mode 100644 mach/m68020/libsys/sync.s create mode 100644 mach/m68020/libsys/time.s create mode 100644 mach/m68020/libsys/times.s create mode 100644 mach/m68020/libsys/umask.s create mode 100644 mach/m68020/libsys/umount.s create mode 100644 mach/m68020/libsys/unlink.s create mode 100644 mach/m68020/libsys/utime.s create mode 100644 mach/m68020/libsys/wait.s create mode 100644 mach/m68020/libsys/write.s diff --git a/mach/m68020/libsys/README b/mach/m68020/libsys/README new file mode 100644 index 00000000..df9f3de6 --- /dev/null +++ b/mach/m68020/libsys/README @@ -0,0 +1,66 @@ + ! Two system calls (gtty and stty) in the m68000 tail_mon library + ! were not really system calls but they used _ioctl. The m68020 machine + ! the table was tested on used real system calls, and we'll use + ! them here. + ! There were also three calls (ftime, lock and dup2) that were in the + ! m68000 library, but were not included in the list of system calls + ! for the m68020 that was given to me. We'll include them anyway. + ! The original gtty and stty files are included here. + ! Note however that the 68000 machine (the Mantra) needs the parameters + ! to system calls in registers, while the m68020 machine this table was + ! tested on wanted the parameters on the stack + ! + ! Also read the comments in the signal.s file! +! ------------------- dup2.s +! .define _dup2 +! .extern _dup2 +! .sect .text +! .sect .rom +! .sect .data +! .sect .bss +! .sect .text +! _dup2: move.w #0x29,d0 +! move.l (4,sp),a0 +! move.l (8,sp),d1 +! add.l #0x40,a0 +! jmp (call) +! +! +! ! ------------------- gtty.s +! .define _gtty +! .extern _gtty +! .sect .text +! .sect .rom +! .sect .data +! .sect .bss +! .sect .text +! _gtty: +! tst.b (-40,sp) +! link a6,#-0 +! move.l (12,a6),-(sp) +! move.l #29704,-(sp) +! move.l (8,a6),-(sp) +! jsr (_ioctl) +! add.l #12,sp +! unlk a6 +! rts +! +! +! ! ------------------- stty.s +! .define _stty +! .extern _stty +! .sect .text +! .sect .rom +! .sect .data +! .sect .bss +! .sect .text +! _stty: +! tst.b (-40,sp) +! link a6,#-0 +! move.l (12,a6),-(sp) +! move.l #29705,-(sp) +! move.l (8,a6),-(sp) +! jsr (_ioctl) +! add.l #12,sp +! unlk a6 +! rts diff --git a/mach/m68020/libsys/_exit.s b/mach/m68020/libsys/_exit.s new file mode 100644 index 00000000..520d2814 --- /dev/null +++ b/mach/m68020/libsys/_exit.s @@ -0,0 +1,10 @@ +.define __exit +.extern __exit +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +__exit: move.l #0x1,d0 + trap #0 + stop #0 ! was there in 68020 routine diff --git a/mach/m68020/libsys/access.s b/mach/m68020/libsys/access.s new file mode 100644 index 00000000..02274d7b --- /dev/null +++ b/mach/m68020/libsys/access.s @@ -0,0 +1,9 @@ +.define _access +.extern _access +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_access: move.l #0x21,d0 + jmp (callc) diff --git a/mach/m68020/libsys/acct.s b/mach/m68020/libsys/acct.s new file mode 100644 index 00000000..71bb08da --- /dev/null +++ b/mach/m68020/libsys/acct.s @@ -0,0 +1,9 @@ +.define _acct +.extern _acct +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_acct: move.l #0x33,d0 + jmp (callc) diff --git a/mach/m68020/libsys/alarm.s b/mach/m68020/libsys/alarm.s new file mode 100644 index 00000000..18ceb91d --- /dev/null +++ b/mach/m68020/libsys/alarm.s @@ -0,0 +1,10 @@ +.define _alarm +.extern _alarm +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_alarm: move.l #0x1B,d0 + trap #0 + rts diff --git a/mach/m68020/libsys/brk.s b/mach/m68020/libsys/brk.s new file mode 100644 index 00000000..c52c17ec --- /dev/null +++ b/mach/m68020/libsys/brk.s @@ -0,0 +1,25 @@ +.define _brk +.define _sbrk +.extern _brk +.extern _sbrk +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_sbrk: move.l (.reghp),d0 + add.l d0,(4,sp) + move.l #0x11,d0 + trap #0 + bcs lcerror + move.l (.reghp),d0 + move.l d0,a0 + move.l (4,sp),(.reghp) + rts +lcerror: jmp (cerror) +_brk: move.l #0x11,d0 + trap #0 + bcs lcerror + move.l (4,sp),(.reghp) + clr.l d0 + rts diff --git a/mach/m68020/libsys/call.s b/mach/m68020/libsys/call.s new file mode 100644 index 00000000..37ddf9d2 --- /dev/null +++ b/mach/m68020/libsys/call.s @@ -0,0 +1,28 @@ +.define call +.define callc +.define calle +.define cerror +.extern call +.extern callc +.extern calle +.extern cerror +.extern _errno +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +call: trap #0 + bcs cerror + rts +callc: + trap #0 + bcs cerror + clr.l d0 + rts +calle: + trap #0 +cerror: + move.l d0,(_errno) + move.l #-1,d0 + rts diff --git a/mach/m68020/libsys/chdir.s b/mach/m68020/libsys/chdir.s new file mode 100644 index 00000000..b76384af --- /dev/null +++ b/mach/m68020/libsys/chdir.s @@ -0,0 +1,9 @@ +.define _chdir +.extern _chdir +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_chdir: move.l #0xC,d0 + jmp (callc) diff --git a/mach/m68020/libsys/chmod.s b/mach/m68020/libsys/chmod.s new file mode 100644 index 00000000..636671a5 --- /dev/null +++ b/mach/m68020/libsys/chmod.s @@ -0,0 +1,9 @@ +.define _chmod +.extern _chmod +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_chmod: move.l #0xF,d0 + jmp (callc) diff --git a/mach/m68020/libsys/chown.s b/mach/m68020/libsys/chown.s new file mode 100644 index 00000000..ada39b8b --- /dev/null +++ b/mach/m68020/libsys/chown.s @@ -0,0 +1,9 @@ +.define _chown +.extern _chown +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_chown: move.l #0x10,d0 + jmp (callc) diff --git a/mach/m68020/libsys/chroot.s b/mach/m68020/libsys/chroot.s new file mode 100644 index 00000000..85de8069 --- /dev/null +++ b/mach/m68020/libsys/chroot.s @@ -0,0 +1,9 @@ +.define _chroot +.extern _chroot +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_chroot: move.l #0x3D,d0 + jmp (callc) diff --git a/mach/m68020/libsys/cleanup.s b/mach/m68020/libsys/cleanup.s new file mode 100644 index 00000000..ecb859c0 --- /dev/null +++ b/mach/m68020/libsys/cleanup.s @@ -0,0 +1,12 @@ +.define __cleanup +.extern __cleanup +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +__cleanup: +tst.b (-40,sp) +link a6,#-0 +unlk a6 +rts diff --git a/mach/m68020/libsys/close.s b/mach/m68020/libsys/close.s new file mode 100644 index 00000000..45c0f050 --- /dev/null +++ b/mach/m68020/libsys/close.s @@ -0,0 +1,9 @@ +.define _close +.extern _close +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_close: move.l #0x6,d0 + jmp (callc) diff --git a/mach/m68020/libsys/compmodule b/mach/m68020/libsys/compmodule new file mode 100755 index 00000000..e42fb932 --- /dev/null +++ b/mach/m68020/libsys/compmodule @@ -0,0 +1,4 @@ +if ${MACH?} -c $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 +fi diff --git a/mach/m68020/libsys/creat.s b/mach/m68020/libsys/creat.s new file mode 100644 index 00000000..30aabd52 --- /dev/null +++ b/mach/m68020/libsys/creat.s @@ -0,0 +1,9 @@ +.define _creat +.extern _creat +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_creat: move.l #0x8,d0 + jmp (call) diff --git a/mach/m68020/libsys/dup.s b/mach/m68020/libsys/dup.s new file mode 100644 index 00000000..e2f29f2a --- /dev/null +++ b/mach/m68020/libsys/dup.s @@ -0,0 +1,9 @@ +.define _dup +.extern _dup +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_dup: move.l #0x29,d0 + jmp (call) diff --git a/mach/m68020/libsys/dup2.s b/mach/m68020/libsys/dup2.s new file mode 100644 index 00000000..dcdf0e9c --- /dev/null +++ b/mach/m68020/libsys/dup2.s @@ -0,0 +1,10 @@ +.define _dup2 +.extern _dup2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_dup2: move.l #0x29,d0 + add.l #0x40,(4,sp) ! ??? + jmp (call) diff --git a/mach/m68020/libsys/errno.s b/mach/m68020/libsys/errno.s new file mode 100644 index 00000000..adc08301 --- /dev/null +++ b/mach/m68020/libsys/errno.s @@ -0,0 +1,9 @@ +.define _errno +.extern _errno +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .bss +_errno: .space 4 +.sect .text diff --git a/mach/m68020/libsys/execl.s b/mach/m68020/libsys/execl.s new file mode 100644 index 00000000..147716a6 --- /dev/null +++ b/mach/m68020/libsys/execl.s @@ -0,0 +1,16 @@ +.define _execl +.extern _execl +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_execl: link a6,#0 + tst.b (-132,sp) + move.l (_environ),-(sp) + pea (12,sp) + move.l (8,a6),-(sp) + jsr (_execve) + add.l #0xC,sp + unlk a6 + rts diff --git a/mach/m68020/libsys/execve.s b/mach/m68020/libsys/execve.s new file mode 100644 index 00000000..a26107d6 --- /dev/null +++ b/mach/m68020/libsys/execve.s @@ -0,0 +1,9 @@ +.define _execve +.extern _execve +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_execve: move.l #0x3B,d0 + jmp (calle) diff --git a/mach/m68020/libsys/exit.s b/mach/m68020/libsys/exit.s new file mode 100644 index 00000000..77d95a5c --- /dev/null +++ b/mach/m68020/libsys/exit.s @@ -0,0 +1,16 @@ +.define _exit +.extern _exit +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_exit: +tst.b (-40,sp) +link a6,#-0 +jsr (__cleanup) +move.l (8,a6),-(sp) +jsr (__exit) +add.l #4,sp +unlk a6 +rts diff --git a/mach/m68020/libsys/fcntl.s b/mach/m68020/libsys/fcntl.s new file mode 100644 index 00000000..385bcdb0 --- /dev/null +++ b/mach/m68020/libsys/fcntl.s @@ -0,0 +1,9 @@ +.define _fcntl +.extern _fcntl +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_fcntl: move.l #0x3E,d0 + jmp (callc) diff --git a/mach/m68020/libsys/fork.s b/mach/m68020/libsys/fork.s new file mode 100644 index 00000000..a087239e --- /dev/null +++ b/mach/m68020/libsys/fork.s @@ -0,0 +1,17 @@ +.define _fork +.extern _fork +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_fork: move.l #0x2,d0 + trap #0 + bcc 1f ! 68020 way to do it + jmp (cerror) +1: + tst.b d1 + beq 2f + clr.l d0 +2: + rts diff --git a/mach/m68020/libsys/fstat.s b/mach/m68020/libsys/fstat.s new file mode 100644 index 00000000..a9c091a9 --- /dev/null +++ b/mach/m68020/libsys/fstat.s @@ -0,0 +1,9 @@ +.define _fstat +.extern _fstat +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_fstat: move.l #0x1C,d0 + jmp (callc) diff --git a/mach/m68020/libsys/ftime.s b/mach/m68020/libsys/ftime.s new file mode 100644 index 00000000..4b3f05c1 --- /dev/null +++ b/mach/m68020/libsys/ftime.s @@ -0,0 +1,9 @@ +.define _ftime +.extern _ftime +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_ftime: move.l #0x23,d0 + jmp (callc) diff --git a/mach/m68020/libsys/getegid.s b/mach/m68020/libsys/getegid.s new file mode 100644 index 00000000..470f8b30 --- /dev/null +++ b/mach/m68020/libsys/getegid.s @@ -0,0 +1,11 @@ +.define _getegid +.extern _getegid +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_getegid: move.l #0x2F,d0 + trap #0 + move.l d1,d0 + rts diff --git a/mach/m68020/libsys/getgid.s b/mach/m68020/libsys/getgid.s new file mode 100644 index 00000000..ff4dd2ce --- /dev/null +++ b/mach/m68020/libsys/getgid.s @@ -0,0 +1,10 @@ +.define _getgid +.extern _getgid +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_getgid: move.l #0x2F,d0 + trap #0 + rts diff --git a/mach/m68020/libsys/getpid.s b/mach/m68020/libsys/getpid.s new file mode 100644 index 00000000..3d128e43 --- /dev/null +++ b/mach/m68020/libsys/getpid.s @@ -0,0 +1,10 @@ +.define _getpid +.extern _getpid +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_getpid: move.l #0x14,d0 + trap #0 + rts diff --git a/mach/m68020/libsys/getuid.s b/mach/m68020/libsys/getuid.s new file mode 100644 index 00000000..7c884c6c --- /dev/null +++ b/mach/m68020/libsys/getuid.s @@ -0,0 +1,10 @@ +.define _getuid +.extern _getuid +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_getuid: move.l #0x18,d0 + trap #0 + rts diff --git a/mach/m68020/libsys/gtty.s b/mach/m68020/libsys/gtty.s new file mode 100644 index 00000000..72249177 --- /dev/null +++ b/mach/m68020/libsys/gtty.s @@ -0,0 +1,9 @@ +.define _gtty +.extern _gtty +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_gtty: move.l #0x20, d0 + jmp (call) diff --git a/mach/m68020/libsys/ioctl.s b/mach/m68020/libsys/ioctl.s new file mode 100644 index 00000000..9f5d4ecb --- /dev/null +++ b/mach/m68020/libsys/ioctl.s @@ -0,0 +1,9 @@ +.define _ioctl +.extern _ioctl +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_ioctl: move.l #0x36,d0 + jmp (call) diff --git a/mach/m68020/libsys/kill.s b/mach/m68020/libsys/kill.s new file mode 100644 index 00000000..30cc6aae --- /dev/null +++ b/mach/m68020/libsys/kill.s @@ -0,0 +1,9 @@ +.define _kill +.extern _kill +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_kill: move.l #0x25,d0 + jmp (callc) diff --git a/mach/m68020/libsys/link.s b/mach/m68020/libsys/link.s new file mode 100644 index 00000000..fdc468d4 --- /dev/null +++ b/mach/m68020/libsys/link.s @@ -0,0 +1,9 @@ +.define _link +.extern _link +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_link: move.l #0x9,d0 + jmp (callc) diff --git a/mach/m68020/libsys/lock.s b/mach/m68020/libsys/lock.s new file mode 100644 index 00000000..67206532 --- /dev/null +++ b/mach/m68020/libsys/lock.s @@ -0,0 +1,9 @@ +.define _lock +.extern _lock +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_lock: move.l #0x35,d0 + jmp (callc) diff --git a/mach/m68020/libsys/lseek.s b/mach/m68020/libsys/lseek.s new file mode 100644 index 00000000..dfb7a3ce --- /dev/null +++ b/mach/m68020/libsys/lseek.s @@ -0,0 +1,9 @@ +.define _lseek +.extern _lseek +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_lseek: move.l #0x13,d0 + jmp (call) diff --git a/mach/m68020/libsys/mknod.s b/mach/m68020/libsys/mknod.s new file mode 100644 index 00000000..9364c9ff --- /dev/null +++ b/mach/m68020/libsys/mknod.s @@ -0,0 +1,9 @@ +.define _mknod +.extern _mknod +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_mknod: move.l #0xE,d0 + jmp (callc) diff --git a/mach/m68020/libsys/mount.s b/mach/m68020/libsys/mount.s new file mode 100644 index 00000000..bf3083c2 --- /dev/null +++ b/mach/m68020/libsys/mount.s @@ -0,0 +1,9 @@ +.define _mount +.extern _mount +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_mount: move.l #0x15,d0 + jmp (callc) diff --git a/mach/m68020/libsys/nice.s b/mach/m68020/libsys/nice.s new file mode 100644 index 00000000..3c24e59b --- /dev/null +++ b/mach/m68020/libsys/nice.s @@ -0,0 +1,9 @@ +.define _nice +.extern _nice +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_nice: move.l #0x22,d0 + jmp (call) diff --git a/mach/m68020/libsys/open.s b/mach/m68020/libsys/open.s new file mode 100644 index 00000000..b9de1c4c --- /dev/null +++ b/mach/m68020/libsys/open.s @@ -0,0 +1,9 @@ +.define _open +.extern _open +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_open: move.l #0x5,d0 + jmp (call) diff --git a/mach/m68020/libsys/pause.s b/mach/m68020/libsys/pause.s new file mode 100644 index 00000000..30b21a1b --- /dev/null +++ b/mach/m68020/libsys/pause.s @@ -0,0 +1,9 @@ +.define _pause +.extern _pause +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_pause: move.l #0x1D,d0 + jmp (callc) diff --git a/mach/m68020/libsys/pipe.s b/mach/m68020/libsys/pipe.s new file mode 100644 index 00000000..b4e4217a --- /dev/null +++ b/mach/m68020/libsys/pipe.s @@ -0,0 +1,18 @@ +.define _pipe +.extern _pipe +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_pipe: + move.l #0x2A,d0 + trap #0 + bcc 1f + jmp (cerror) +1: + move.l (4,sp),a0 + move.l d0,(a0)+ + move.l d1,(a0) + clr.l d0 + rts diff --git a/mach/m68020/libsys/profil.s b/mach/m68020/libsys/profil.s new file mode 100644 index 00000000..10703e86 --- /dev/null +++ b/mach/m68020/libsys/profil.s @@ -0,0 +1,10 @@ +.define _profil +.extern _profil +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_profil: move.l #0x2C,d0 + trap #0 + rts diff --git a/mach/m68020/libsys/ptrace.s b/mach/m68020/libsys/ptrace.s new file mode 100644 index 00000000..7ceba3fe --- /dev/null +++ b/mach/m68020/libsys/ptrace.s @@ -0,0 +1,11 @@ +.define _ptrace +.extern _ptrace +.extern _errno +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_ptrace: move.l #0x1A,d0 + clr.l (_errno) + jmp (call) diff --git a/mach/m68020/libsys/read.s b/mach/m68020/libsys/read.s new file mode 100644 index 00000000..1602d806 --- /dev/null +++ b/mach/m68020/libsys/read.s @@ -0,0 +1,9 @@ +.define _read +.extern _read +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_read: move.l #0x3,d0 + jmp (call) diff --git a/mach/m68020/libsys/setgid.s b/mach/m68020/libsys/setgid.s new file mode 100644 index 00000000..bba1a291 --- /dev/null +++ b/mach/m68020/libsys/setgid.s @@ -0,0 +1,9 @@ +.define _setgid +.extern _setgid +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_setgid: move.l #0x2E,d0 + jmp (callc) diff --git a/mach/m68020/libsys/setuid.s b/mach/m68020/libsys/setuid.s new file mode 100644 index 00000000..5fda7549 --- /dev/null +++ b/mach/m68020/libsys/setuid.s @@ -0,0 +1,9 @@ +.define _setuid +.extern _setuid +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_setuid: move.l #0x17,d0 + jmp (callc) diff --git a/mach/m68020/libsys/signal.s b/mach/m68020/libsys/signal.s new file mode 100644 index 00000000..1d22e799 --- /dev/null +++ b/mach/m68020/libsys/signal.s @@ -0,0 +1,22 @@ +.define _signal +.extern _signal +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_signal: + move.l #0x30,d0 + jmp (callc) +! NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE +! +! Just as in the m68000 tail_mon library the acual signal system call +! is not called directly by the user, but an `interface'. This `interface' +! does the actual system call. On the m68020 machine the table was tested on +! this `interface' did things that I did not understand, e.g. it called +! a sytem call with number 38, called `_sysm68k'. I couldn't get the signal +! system call get to work properly on that machine, but as it is clear +! that this is in no way to blame to my back end table. +! The system call as presented here does not reset the catch routine: a +! signal that is caught by a user function will be caught every time, not +! just once. I couldn't change this. diff --git a/mach/m68020/libsys/stat.s b/mach/m68020/libsys/stat.s new file mode 100644 index 00000000..73dd9490 --- /dev/null +++ b/mach/m68020/libsys/stat.s @@ -0,0 +1,9 @@ +.define _stat +.extern _stat +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_stat: move.l #0x12,d0 + jmp (callc) diff --git a/mach/m68020/libsys/stime.s b/mach/m68020/libsys/stime.s new file mode 100644 index 00000000..7d0823c8 --- /dev/null +++ b/mach/m68020/libsys/stime.s @@ -0,0 +1,10 @@ +.define _stime +.extern _stime +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_stime: move.l #0x19,d0 + move.l ([4,sp]),(4,sp) + jmp (callc) diff --git a/mach/m68020/libsys/stty.s b/mach/m68020/libsys/stty.s new file mode 100644 index 00000000..469f9c5a --- /dev/null +++ b/mach/m68020/libsys/stty.s @@ -0,0 +1,9 @@ +.define _stty +.extern _stty +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_stty: move.l #0x21, d0 + jmp (call) diff --git a/mach/m68020/libsys/sync.s b/mach/m68020/libsys/sync.s new file mode 100644 index 00000000..3ee77a2c --- /dev/null +++ b/mach/m68020/libsys/sync.s @@ -0,0 +1,10 @@ +.define _sync +.extern _sync +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_sync: move.l #0x24,d0 + trap #0 + rts diff --git a/mach/m68020/libsys/time.s b/mach/m68020/libsys/time.s new file mode 100644 index 00000000..ad82771c --- /dev/null +++ b/mach/m68020/libsys/time.s @@ -0,0 +1,14 @@ +.define _time +.extern _time +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_time: move.l #0xD,d0 + trap #0 + tst.l (4,sp) + beq 1f + move.l d0,([4,sp]) +1: + rts diff --git a/mach/m68020/libsys/times.s b/mach/m68020/libsys/times.s new file mode 100644 index 00000000..e06693f8 --- /dev/null +++ b/mach/m68020/libsys/times.s @@ -0,0 +1,10 @@ +.define _times +.extern _times +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_times: move.l #0x2B,d0 + trap #0 + jmp (call) diff --git a/mach/m68020/libsys/umask.s b/mach/m68020/libsys/umask.s new file mode 100644 index 00000000..b16bf5fc --- /dev/null +++ b/mach/m68020/libsys/umask.s @@ -0,0 +1,9 @@ +.define _umask +.extern _umask +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_umask: move.l #0x3C,d0 + jmp (call) diff --git a/mach/m68020/libsys/umount.s b/mach/m68020/libsys/umount.s new file mode 100644 index 00000000..3940f13a --- /dev/null +++ b/mach/m68020/libsys/umount.s @@ -0,0 +1,9 @@ +.define _umount +.extern _umount +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_umount: move.l #0x16,d0 + jmp (callc) diff --git a/mach/m68020/libsys/unlink.s b/mach/m68020/libsys/unlink.s new file mode 100644 index 00000000..a31a191c --- /dev/null +++ b/mach/m68020/libsys/unlink.s @@ -0,0 +1,9 @@ +.define _unlink +.extern _unlink +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_unlink: move.l #0xA,d0 + jmp (callc) diff --git a/mach/m68020/libsys/utime.s b/mach/m68020/libsys/utime.s new file mode 100644 index 00000000..98070dba --- /dev/null +++ b/mach/m68020/libsys/utime.s @@ -0,0 +1,9 @@ +.define _utime +.extern _utime +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_utime: move.l #0x1E,d0 + jmp (callc) diff --git a/mach/m68020/libsys/wait.s b/mach/m68020/libsys/wait.s new file mode 100644 index 00000000..4ffafbd4 --- /dev/null +++ b/mach/m68020/libsys/wait.s @@ -0,0 +1,15 @@ +.define _wait +.extern _wait +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_wait: move.l #0x7,d0 + trap #0 + bcs cerror + tst.l (4,sp) + beq 1f + move.l d1,([4,sp]) +1: + rts diff --git a/mach/m68020/libsys/write.s b/mach/m68020/libsys/write.s new file mode 100644 index 00000000..cf1f3c3b --- /dev/null +++ b/mach/m68020/libsys/write.s @@ -0,0 +1,9 @@ +.define _write +.extern _write +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_write: move.l #0x4,d0 + jmp (call) From 5381da9185839a2e3bbc47c9668e2cd2e6e59c62 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 29 Jan 1987 22:45:44 +0000 Subject: [PATCH 0620/1625] Initial revision --- mach/m68020/libsys/LIST | 58 +++++++++++++++++++++++++++++++++++++ mach/m68020/libsys/Makefile | 29 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 mach/m68020/libsys/LIST create mode 100644 mach/m68020/libsys/Makefile diff --git a/mach/m68020/libsys/LIST b/mach/m68020/libsys/LIST new file mode 100644 index 00000000..75f6496c --- /dev/null +++ b/mach/m68020/libsys/LIST @@ -0,0 +1,58 @@ +libmon_s.a +exit.s +_exit.s +access.s +acct.s +alarm.s +chdir.s +chmod.s +chown.s +chroot.s +close.s +creat.s +dup.s +dup2.s +execl.s +execve.s +fork.s +ftime.s +getegid.s +getgid.s +getpid.s +getuid.s +stty.s +gtty.s +ioctl.s +kill.s +link.s +lock.s +lseek.s +mknod.s +mount.s +nice.s +open.s +pause.s +pipe.s +profil.s +ptrace.s +read.s +setgid.s +setuid.s +stat.s +stime.s +sync.s +time.s +times.s +umask.s +umount.s +unlink.s +utime.s +write.s +brk.s +wait.s +fstat.s +signal.s +fcntl.s +call.s +cleanup.s +errno.s diff --git a/mach/m68020/libsys/Makefile b/mach/m68020/libsys/Makefile new file mode 100644 index 00000000..5861ef1d --- /dev/null +++ b/mach/m68020/libsys/Makefile @@ -0,0 +1,29 @@ +# $Header$ +MACH=m68020 +all: libmon_o.a head_em.o + +install: all + ../../install head_em.o head_em + ../../install libmon_o.a tail_mon + + +cmp: all + -../../compare head_em.o head_em + -../../compare libmon_o.a tail_mon + +libmon_o.a: libmon_s.a + ASAR=aal ; export ASAR ;\ + march . libmon_o.a + +head_em.o: head_em.s + $(MACH) -I../../../h -c head_em.s + +clean: + rm -f *.o libmon_o.a + +opr : + make pr | opr + +pr: + @pr `pwd`/head_em.s + @arch pv libmon_s.a | pr -h `pwd`/libmon_s.a From 477eee337f309155bf6f6b42fe5122f4f685955a Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 29 Jan 1987 23:25:01 +0000 Subject: [PATCH 0621/1625] Initial revision --- mach/m68020/libsys/head_em.s | 71 ++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 mach/m68020/libsys/head_em.s diff --git a/mach/m68020/libsys/head_em.s b/mach/m68020/libsys/head_em.s new file mode 100644 index 00000000..f69fdb87 --- /dev/null +++ b/mach/m68020/libsys/head_em.s @@ -0,0 +1,71 @@ +.define .lino,.filn +.define EXIT +.define begtext,begdata,begbss +.define EARRAY,ERANGE,ESET,EIDIVZ,EHEAP,EILLINS,ECASE,EBADGTO +.define hol0,.reghp,.limhp,.trpim,.trppc +.sect .text +.sect .rom +.sect .data +.sect .bss + + + +! runtime startof for 68020 machine + + +LINO_AD = 0 +FILN_AD = 4 + +EARRAY = 0 +ERANGE = 1 +ESET = 2 +EIDIVZ = 6 +EHEAP = 17 +EILLINS = 18 +ECASE = 20 +EBADGTO = 27 + + .sect .text +begtext: + move.l d0,(splimit) ! load splimit with the initial stack limit + sub.l #8,sp + move.l (8,sp),(sp) ! argc + lea (12,sp),a0 + move.l a0,(4,sp) ! argv + move.l a0,a1 +1: + tst.l (a0)+ ! null args term? + bne 1b + cmp.l (a1),a0 ! end of 'argv[]' and in *argv[] strings? + blt 2f ! skip if a0 is less than start of *argv[] + sub.l #4,a0 ! else backup one to set env = 0 (NULL) +2: + move.l a0,(8,sp) ! env +! move.l a0, environ ! indir is 0 if no env; not 0 if env +! jsr (initfpu) ! call to dummy floating point init routine + jsr (_m_a_i_n) + move.l d0,(sp) ! no stack cleanup needed +EXIT: + jsr (__exit) + + .sect .data +begdata: +splimit: + .data4 0 ! may be at virtual address 0 with no problem +hol0: +.lino: + .data4 0 ! lino +.filn: + .data4 0 ! filn +.reghp: + .data4 endbss +.limhp: + .data4 endbss +.trppc: + .data4 0 +.trpim: + .data4 0 ! USED TO BE 2 BYTES; IS THIS RIGHT? + + + .sect .bss +begbss: !initialization is not needed because ALL entries are in zero space! From 32ec75b27c66dd7f31dfbf82a15318f67d5cdd7e Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 29 Jan 1987 23:30:46 +0000 Subject: [PATCH 0622/1625] *** empty log message *** --- mach/m68020/libem/compmodule | 2 +- mach/m68020/libsys/compmodule | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mach/m68020/libem/compmodule b/mach/m68020/libem/compmodule index e42fb932..a61e867b 100755 --- a/mach/m68020/libem/compmodule +++ b/mach/m68020/libem/compmodule @@ -1,4 +1,4 @@ -if ${MACH?} -c $1 1>&2 +if m68020 -c $1 1>&2 then echo `basename $1 $2`.o else exit 1 fi diff --git a/mach/m68020/libsys/compmodule b/mach/m68020/libsys/compmodule index e42fb932..a61e867b 100755 --- a/mach/m68020/libsys/compmodule +++ b/mach/m68020/libsys/compmodule @@ -1,4 +1,4 @@ -if ${MACH?} -c $1 1>&2 +if m68020 -c $1 1>&2 then echo `basename $1 $2`.o else exit 1 fi From 8f3c2c8c337cbfbd064fbe1e6180f1be15db21f1 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 30 Jan 1987 09:45:41 +0000 Subject: [PATCH 0623/1625] bug fix --- lang/cem/libcc/gen/isatty.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/cem/libcc/gen/isatty.c b/lang/cem/libcc/gen/isatty.c index 4fa9cad3..aeee7ff7 100644 --- a/lang/cem/libcc/gen/isatty.c +++ b/lang/cem/libcc/gen/isatty.c @@ -6,6 +6,6 @@ isatty(f) where gtty is an ioctl(..., TCGETA, ...) */ - if (gtty(f, &ttyb) < 0) return 0; + if (gtty(f, &buf) < 0) return 0; return 1; } From 838dbf7246a612e97a5d3f70aa6af592ad57ac32 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 30 Jan 1987 10:18:40 +0000 Subject: [PATCH 0624/1625] *** empty log message *** --- mach/ns/libbc/Makefile | 3 ++- mach/ns/libpc/Makefile | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/mach/ns/libbc/Makefile b/mach/ns/libbc/Makefile index 225d8173..334a774c 100644 --- a/mach/ns/libbc/Makefile +++ b/mach/ns/libbc/Makefile @@ -1,5 +1,6 @@ +SUF=o MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=ns" "SUF=o" "ASAR=aal" +MACHDEF="MACH=ns" "SUF=$(SUF)" "ASAR=aal" BCDEF="PREF=bc" "SUB=" "SRC=lang/basic/lib" install: diff --git a/mach/ns/libpc/Makefile b/mach/ns/libpc/Makefile index 0c68be57..d4a03084 100644 --- a/mach/ns/libpc/Makefile +++ b/mach/ns/libpc/Makefile @@ -1,5 +1,6 @@ +SUF=o MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=ns" "SUF=o" "ASAR=aal" +MACHDEF="MACH=ns" "SUF=$(SUF)" "ASAR=aal" PCDEF="PREF=pc" "SUB=" "SRC=lang/pc/libpc" install: From de84a4d04bd1275a81b827031a8bca3a8362e022 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 30 Jan 1987 10:49:21 +0000 Subject: [PATCH 0625/1625] Initial revision --- mach/m68020/ncg/whichone.h | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 mach/m68020/ncg/whichone.h diff --git a/mach/m68020/ncg/whichone.h b/mach/m68020/ncg/whichone.h new file mode 100644 index 00000000..9a5910a1 --- /dev/null +++ b/mach/m68020/ncg/whichone.h @@ -0,0 +1,3 @@ +#ifndef TBL68020 +#define TBL68020 +#endif From b097247c2d47e0b1599e2e1b11caefa79d3e7bb4 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 30 Jan 1987 10:57:17 +0000 Subject: [PATCH 0626/1625] changed #define m68020 to TBL68020. Could otherwize cause problems when translated with ack --- mach/m68020/ncg/mach.c | 12 +- mach/m68020/ncg/mach.h | 18 ++- mach/m68020/ncg/table | 308 ++++++++++++++++++++--------------------- mach/m68k2/ncg/mach.c | 12 +- mach/m68k2/ncg/mach.h | 18 ++- mach/m68k2/ncg/table | 308 ++++++++++++++++++++--------------------- mach/m68k4/ncg/mach.c | 12 +- mach/m68k4/ncg/mach.h | 18 ++- mach/m68k4/ncg/table | 308 ++++++++++++++++++++--------------------- mach/moon3/ncg/mach.c | 12 +- mach/moon3/ncg/mach.h | 18 ++- mach/moon3/ncg/table | 308 ++++++++++++++++++++--------------------- 12 files changed, 660 insertions(+), 692 deletions(-) diff --git a/mach/m68020/ncg/mach.c b/mach/m68020/ncg/mach.c index 3d3073a5..1cd93771 100644 --- a/mach/m68020/ncg/mach.c +++ b/mach/m68020/ncg/mach.c @@ -19,13 +19,7 @@ * machine dependent back end routines for the Motorola 68000, 68010 or 68020 */ -#ifndef m68k4 -#define m68020 -#endif - /* use m68020 when you want a m68020 cg, don't if you want a - * m68k4 cg. The m68k4 cg can be used for both the MC68000 - * and the MC68010. - */ +#include "whichone.h" con_part(sz,w) register sz; word w; { @@ -138,7 +132,7 @@ save() /* initialise register-parameters */ for (p = regsav; p < ®sav[regnr]; p++) { if (p->rs_off >= 0) { -#ifdef m68020 +#ifdef TBL68020 fprintf(codefile,"move.%c (%ld,a6),%s\n", #else fprintf(codefile,"move.%c %ld(a6),%s\n", @@ -196,7 +190,7 @@ regreturn() prolog(nlocals) full nlocals; { -#ifdef m68020 +#ifdef TBL68020 fprintf(codefile,"tst.b (-%ld,sp)\nlink\ta6,#-%ld\n",nlocals+40,nlocals); #else fprintf(codefile,"tst.b -%ld(sp)\nlink\ta6,#-%ld\n",nlocals+40,nlocals); diff --git a/mach/m68020/ncg/mach.h b/mach/m68020/ncg/mach.h index ff2cf66c..48763723 100644 --- a/mach/m68020/ncg/mach.h +++ b/mach/m68020/ncg/mach.h @@ -1,9 +1,12 @@ -#ifndef m68k4 -#define m68020 +#include "whichone.h" + +#ifndef TBL68020 +#ifndef TBL68000 +Something is very wrong here. You must specify the machine: either +TBL68000 or TBL68020, in the file whichone.h, then REMOVE tables.c +and then run "make" again +#endif #endif - /* m68020 should be used for a m68020 cg, and it should - * not be used for a m68k4 cg - */ #define ex_ap(y) fprintf(codefile,".extern %s\n",y) #define in_ap(y) /* nothing */ @@ -20,7 +23,7 @@ #define dlb_fmt "_%d" #define hol_fmt "hol%d" -#ifdef m68020 +#ifdef TBL68020 #define loc_off "(%d,a6)" #define arg_off "(8+%d,a6)" #else @@ -35,5 +38,6 @@ #define modhead ".sect .text\n.sect .rom\n.sect .data\n.sect .bss\n" -#define id_first '_' +#define fmt_id(sf,st) sprintf(st,"_%s",sf) + #define BSS_INIT 0 diff --git a/mach/m68020/ncg/table b/mach/m68020/ncg/table index 6518487a..d6166d16 100644 --- a/mach/m68020/ncg/table +++ b/mach/m68020/ncg/table @@ -6,13 +6,7 @@ ********************************/ -#ifndef m68k4 -#define m68020 -#endif - /* m68020 to be defined if this is the 68020 table. - * The 68000 and 68010 tables are identical. - */ - +#include "whichone.h" #define small(x) ((x)>=1 && (x)<=8) #define nicesize(x) ((x)==1||(x)==2||(x)==4||(x)==8) @@ -107,7 +101,7 @@ llabel = {ADDR bd;} 4 cost(2,0) bd . slabel = {ADDR bd;} 4 cost(0,0) bd . shconst = {INT num;} 4 cost(0,0) "#" num . -#ifndef m68020 +#ifndef TBL68020 /* Part (ii) */ absolute4 = {ADDR bd;} 4 cost(4,8) bd . offsetted4 = {A_REG reg; INT bd;} 4 cost(2,6) bd "(" reg ")" . @@ -133,7 +127,7 @@ regAregXcon = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,8) t_regAregXcon = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,8) . t_regAcon = {A_REG reg; INT bd;} 4 cost(2,6) . -#else m68020 +#else TBL68020 /* Part (iii) */ absolute4 = {ADDR bd;} 4 cost(4,7) "(" bd ")" . offsetted4 = {A_REG reg; INT bd;} 4 cost(2,6) "(" bd "," reg ")" . @@ -216,7 +210,7 @@ DREG_pair = {D_REG reg1; D_REG reg2;} 8 cost(2,0) reg1 ":" reg2 . #define t_regAregXcon regAregXcon #define t_regAcon regAcon -#endif m68020 +#endif TBL68020 SETS @@ -224,7 +218,7 @@ SETS * because cgg is one pass. */ -#ifndef m68020 +#ifndef TBL68020 /* A m68k4 part */ data4 = D_REG + LOCAL + const + post_inc4 + pre_dec4 + indirect4 + offsetted4 + index_off4 + absolute4 + @@ -249,7 +243,7 @@ control1 = indirect1 + offsetted1 + index_off1 + absolute1 . alterable1 = data1 - const . any1 = data1 . -#else m68020 +#else TBL68020 data4 = D_REG + indirect4 + post_inc4 + pre_dec4 + index_off4 + offsetted4 + OFF_off4 + OFF_indoff4 + @@ -282,7 +276,7 @@ control1 = memory1 - (post_inc1 + pre_dec1 + const) . alterable1 = data1 - const . any1 = data1 . /* all four above together */ -#endif m68020 +#endif TBL68020 /* This is a common part */ any = any4 + any2 + any1 . absolute = absolute4 + absolute2 + absolute1 . @@ -293,7 +287,7 @@ pre_post = pre_dec4 + pre_dec2 + pre_dec1 + offsetted = offsetted4 + offsetted2 + offsetted1 . index_off = index_off4 + index_off2 + index_off1 . -#ifndef m68020 +#ifndef TBL68020 /* A m68k4 part */ regind_addr = regAcon + regAregXcon + t_regAcon + t_regAregXcon . address = ext_addr + local_addr + regAcon + regAregXcon . @@ -305,7 +299,7 @@ allexceptcon = ALL - ( D_REG + A_REG + const + t_regAcon + t_regAregXcon ) . use_index = index_off4 + index_off2 + index_off1 . -#else m68020 +#else TBL68020 reg_memind4 = OFF_off4 + OFF_indoff4 + INDOFF_off4 . memind4 = reg_memind4 + @@ -347,7 +341,7 @@ use_indaddr = regAregXcon + use_index = use_index4 + use_index2 + use_index1 + use_indaddr + regX . -#endif m68020 +#endif TBL68020 /* A common part */ posextern = absolute + all_indir . @@ -366,7 +360,7 @@ memalt4 = memory4 * alterable4 . memalt2 = memory2 * alterable2 . memalt1 = memory1 * alterable1 . -#ifndef m68020 +#ifndef TBL68020 /* A m68k4 part */ imm_cmp4 = alterable4 . imm_cmp2 = alterable2 . @@ -376,7 +370,7 @@ test_set4 = datalt4 . test_set2 = datalt2 . test_set1 = datalt1 . -#else m68020 +#else TBL68020 imm_cmp4 = any4 - immediate4 . imm_cmp2 = any2 - const . @@ -386,15 +380,15 @@ test_set4 = data4 - immediate4 . test_set2 = data2 - const . test_set1 = data1 - const . -#endif m68020 +#endif TBL68020 test_set = test_set4 + test_set2 + test_set1 . -#ifndef m68020 +#ifndef TBL68020 t_address = address + t_regAregXcon + t_regAcon . -#else m68020 +#else TBL68020 #define t_address address -#endif m68020 +#endif TBL68020 INSTRUCTIONS @@ -425,12 +419,12 @@ sh "illegal" shconreg:ro, LOCAL:rw:cc cost(0,0). sh "illegal" LOCAL:ro, LOCAL:rw:cc cost(0,0). xxx "illegal" data4:ro, LOCAL:rw:cc cost(0,0). xxx "illegal" LOCAL:ro, alterable4:rw:cc cost(0,0). -#ifdef m68020 +#ifdef TBL68020 divs_l "divs.l" data4:ro, LOCAL:rw:cc cost(0,90). divu_l "divu.l" data4:ro, LOCAL:rw:cc cost(0,78). muls_l "muls.l" data4:ro, LOCAL:rw:cc cost(0,44). mulu_l "mulu.l" data4:ro, LOCAL:rw:cc cost(0,44). -#endif m68020 +#endif TBL68020 add_l "add.l" any4:ro, D_REG:rw:cc cost(2,3). add_l "add.l" any4:ro, A_REG:rw cost(2,3). @@ -517,7 +511,7 @@ bit "illegal" control4:rw:cc cost(2,6). sh "illegal" shconreg:ro, D_REG:rw:cc cost(2,4). shw "illegal" control2:rw:cc cost(2,4). -#ifdef m68020 +#ifdef TBL68020 cmp2_l "cmp2.l" address+control4:ro, genreg:ro kills :cc cost(2,18). divs_l "divs.l" data4:ro, D_REG:rw:cc cost(2,90). divsl_l "divsl.l" data4:ro, DREG_pair:rw kills :cc cost(2,90). @@ -527,9 +521,9 @@ extb_l "extb.l" D_REG:rw:cc cost(2,4). muls_l "muls.l" data4:ro, D_REG:rw:cc cost(2,44). mulu_l "mulu.l" data4:ro, D_REG:rw:cc cost(2,44). pea address+control4+regX cost(2,4). -#else m68020 +#else TBL68020 pea address+control4 cost(2,4). -#endif m68020 +#endif TBL68020 /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * Extra pseudo instruction; it just kills a D_REG; @@ -562,7 +556,7 @@ from const to memalt2 from regAcon %bd==0 to A_REG gen move_l %1.reg, %2 -#ifndef m68020 +#ifndef TBL68020 from t_regAregXcon sfit(%bd, 8) to A_REG gen lea {regAregXcon, %1.reg, %1.xreg, 1, %1.bd}, %2 @@ -576,7 +570,7 @@ from t_regAcon sfit(%bd, 16) to A_REG from t_regAcon to A_REG gen move_l %1.reg, %2 add_l {const, %1.bd}, %2 -#endif m68020 +#endif TBL68020 from address - ext_addr to A_REG gen lea %1, %2 @@ -612,7 +606,7 @@ STACKINGRULES from const %num==0 to STACK gen clr_l {pre_dec4, sp} -#ifndef m68020 +#ifndef TBL68020 from t_regAregXcon sfit(%bd, 8) to STACK gen pea {regAregXcon, %1.reg, %1.xreg, 1, %1.bd} @@ -626,7 +620,7 @@ from t_regAcon sfit(%bd, 16) to STACK from t_regAcon to STACK gen move_l %1.reg, {pre_dec4, sp} add_l {const, %1.bd}, {indirect4, sp} -#endif m68020 +#endif TBL68020 from address - ext_addr to STACK gen pea %1 @@ -648,10 +642,10 @@ from data1 to STACK gen clr_l {pre_dec4, sp} move_b %1, {offsetted1, sp, 3} -#ifdef m68020 +#ifdef TBL68020 from regX to STACK gen pea %1 -#endif m68020 +#endif TBL68020 /* This last stackingrule is never used: whenever regX is put on * the fakestack, some em-instuctions are left that remove it * immediately. However cgg complained about not having a @@ -672,7 +666,7 @@ from STACK gen move_l {post_inc4, sp}, %a yields %a -#ifndef m68020 +#ifndef TBL68020 from t_regAregXcon sfit(%bd, 8) yields {regAregXcon, %1.reg, %1.xreg, 1, %1.bd} @@ -688,7 +682,7 @@ from t_regAcon uses reusing %1, AA_REG=%1.reg gen add_l {const, %1.bd}, %a yields %a -#endif m68020 +#endif TBL68020 from t_address uses reusing %1, AA_REG = %1 @@ -835,7 +829,7 @@ pat lol loc ror stl $1==$4 && small($2) && $3==4 && inreg($1)==reg_any pat lol lol ror stl $1==$4 && inreg($2)==reg_any && $3==4 && inreg($1)==reg_any call lolrshstl("ror.l") -#ifdef m68020 +#ifdef TBL68020 pat lol loc dvi stl $1==$4 && $3==4 && inreg($1)==reg_any kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) gen divs_l {const, $2}, {LOCAL, $1} @@ -861,7 +855,7 @@ pat lol mlu stl $1==$3 && $2==4 && inreg($1)==reg_any with data4 kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) gen mulu_l %1, {LOCAL, $1} -#endif m68020 +#endif TBL68020 pat lil inc sil $1==$3 && inreg($1)==reg_pointer @@ -1126,12 +1120,12 @@ pat ldl leaving lol $1+4 lol $1 pat loe yields {absolute4, $1} pat lil -#ifdef m68020 +#ifdef TBL68020 yields {ILOCAL, $1} -#else m68020 +#else TBL68020 uses AA_REG = {LOCAL, $1} yields {indirect4, %a} -#endif m68020 +#endif TBL68020 /* When using the 'offsetted' intructions regAregXcon cannot be used * for the m68k4; there is no way of knowing about the size of @@ -1145,9 +1139,9 @@ pat lof with A_REG yields {offsetted4, %1, $1} with exact local_addr yields {LOCAL, %1.bd+$1} with exact ext_addr yields {absolute4, %1.bd+$1} -#ifndef m68020 +#ifndef TBL68020 with regAcon yields {offsetted4, %1.reg, %1.bd+$1} -#else m68020 +#else TBL68020 with exact regAcon yields {offsetted4, %1.reg, %1.bd+$1} with exact regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1} with exact offsetted4 yields {OFF_off4, %1.reg, %1.bd, $1} @@ -1165,7 +1159,7 @@ with exact abs_regXcon yields {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od+$1} with exact abs_index4 yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, $1} with exact absind_con yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1} with exact ext_regX yields {abs_index4, %1.sc, %1.xreg, %1.bd+$1} -#endif m68020 +#endif TBL68020 pat lal yields {local_addr, $1} @@ -1176,20 +1170,20 @@ pat lxl $1==0 yields lb pat lxl $1==1 yields {LOCAL, SL} pat lxl $1==2 -#ifdef m68020 +#ifdef TBL68020 yields {OFF_off4, lb, SL, SL} -#else m68020 +#else TBL68020 uses AA_REG = {LOCAL, SL} yields {offsetted4, %a, SL} -#endif m68020 +#endif TBL68020 pat lxl $1==3 -#ifdef m68020 +#ifdef TBL68020 uses AA_REG = {OFF_off4, lb, SL, SL} -#else m68020 +#else TBL68020 uses AA_REG = {LOCAL, SL} gen move {offsetted4, %a, SL}, %a -#endif m68020 +#endif TBL68020 yields {offsetted4, %a, SL} pat lxl $1>3 @@ -1203,20 +1197,20 @@ pat lxl $1>3 pat lxa $1==0 yields {local_addr, SL} pat lxa $1==1 -#ifdef m68020 +#ifdef TBL68020 yields {off_con, lb, SL, SL} -#else m68020 +#else TBL68020 uses AA_REG = {LOCAL, SL} yields {regAcon, %a, SL} -#endif m68020 +#endif TBL68020 pat lxa $1==2 -#ifdef m68020 +#ifdef TBL68020 uses AA_REG = {OFF_off4, lb, SL, SL} -#else m68020 +#else TBL68020 uses AA_REG = {LOCAL, SL} gen move {offsetted4, %a, SL}, %a -#endif m68020 +#endif TBL68020 yields {regAcon, %a, SL} pat lxa $1>2 @@ -1231,10 +1225,10 @@ pat loi $1==1 with A_REG yields {indirect1, %1} with exact local_addr yields {offsetted1, lb, %1.bd} with exact ext_addr yields {absolute1, %1.bd} -#ifndef m68020 +#ifndef TBL68020 with regAcon yields {offsetted1, %1.reg, %1.bd} with regAregXcon yields {index_off1, %1.reg, %1.xreg, %1.sc, %1.bd} -#else m68020 +#else TBL68020 with exact regAcon yields {offsetted1, %1.reg, %1.bd} with exact regAregXcon yields {index_off1, %1.reg, %1.xreg, %1.sc, %1.bd} with exact indirect4 yields {OFF_off1, %1.reg, 0, 0} @@ -1252,16 +1246,16 @@ with exact abs_regXcon yields {ABS_indoff1, %1.sc, %1.xreg, %1.bd, %1.od} with exact abs_index4 yields {ABSIND_off1, %1.sc, %1.xreg, %1.bd, 0} with exact absind_con yields {ABSIND_off1, %1.sc, %1.xreg, %1.bd, %1.od} with exact ext_regX yields {abs_index1, %1.sc, %1.xreg, %1.bd} -#endif m68020 +#endif TBL68020 pat loi $1==2 with A_REG yields {indirect2, %1} with exact local_addr yields {offsetted2, lb, %1.bd} with exact ext_addr yields {absolute2, %1.bd} -#ifndef m68020 +#ifndef TBL68020 with regAcon yields {offsetted2, %1.reg, %1.bd} with regAregXcon yields {index_off2, %1.reg, %1.xreg, %1.sc, %1.bd} -#else m68020 +#else TBL68020 with exact regAcon yields {offsetted2, %1.reg, %1.bd} with exact regAregXcon yields {index_off2, %1.reg, %1.xreg, %1.sc, %1.bd} with exact indirect4 yields {OFF_off2, %1.reg, 0, 0} @@ -1279,16 +1273,16 @@ with exact abs_regXcon yields {ABS_indoff2, %1.sc, %1.xreg, %1.bd, %1.od} with exact abs_index4 yields {ABSIND_off2, %1.sc, %1.xreg, %1.bd, 0} with exact absind_con yields {ABSIND_off2, %1.sc, %1.xreg, %1.bd, %1.od} with exact ext_regX yields {abs_index2, %1.sc, %1.xreg, %1.bd} -#endif m68020 +#endif TBL68020 pat loi $1==4 with A_REG yields {indirect4, %1} with exact local_addr yields {LOCAL, %1.bd} with exact ext_addr yields {absolute4, %1.bd} -#ifndef m68020 +#ifndef TBL68020 with regAcon yields {offsetted4, %1.reg, %1.bd} with regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd} -#else m68020 +#else TBL68020 with exact regAcon yields {offsetted4, %1.reg, %1.bd} with exact regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd} with exact LOCAL yields {ILOCAL, %1.bd} @@ -1306,7 +1300,7 @@ with exact abs_regXcon yields {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od} with exact abs_index4 yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, 0} with exact absind_con yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od} with exact ext_regX yields {abs_index4, %1.sc, %1.xreg, %1.bd} -#endif m68020 +#endif TBL68020 pat loi $1==8 with A_REG yields {offsetted4, %1, 4} @@ -1333,10 +1327,10 @@ with exact local_addr yields {LOCAL, %1.bd+$1+4} {LOCAL, %1.bd+$1} with exact ext_addr yields {absolute4, %1.bd+$1+4} {absolute4, %1.bd+$1} -#ifndef m68020 +#ifndef TBL68020 with regAcon yields {offsetted4, %1.reg, %1.bd+$1+4} {offsetted4, %1.reg, %1.bd+$1} -#else m68020 +#else TBL68020 with exact regAcon yields {offsetted4, %1.reg, %1.bd+$1+4} {offsetted4, %1.reg, %1.bd+$1} with exact regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1+4} @@ -1371,7 +1365,7 @@ with exact absind_con yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1+4} {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1} with exact ext_regX yields {abs_index4, %1.sc, %1.xreg, %1.bd+$1+4} {abs_index4, %1.sc, %1.xreg, %1.bd+$1} -#endif m68020 +#endif TBL68020 pat lpi yields {ext_addr, $1} @@ -1396,13 +1390,13 @@ with exact STACK gen move {post_inc4, sp}, {absolute4, $1} pat sil -#ifdef m68020 +#ifdef TBL68020 with any4 kills allexceptcon gen move %1, {ILOCAL, $1} with exact STACK gen move {post_inc4, sp}, {ILOCAL, $1} -#else m68020 +#else TBL68020 with any4 kills allexceptcon uses AA_REG = {LOCAL, $1} @@ -1410,7 +1404,7 @@ with any4 with exact STACK uses AA_REG = {LOCAL, $1} gen move {post_inc4, sp}, {indirect4, %a} -#endif m68020 +#endif TBL68020 pat stf with A_REG any4 @@ -1424,11 +1418,11 @@ with exact local_addr any4 with exact ext_addr any4 kills allexceptcon gen move %2, {absolute4, %1.bd+$1} -#ifndef m68020 +#ifndef TBL68020 with regAcon any4 kills allexceptcon gen move %2, {offsetted4, %1.reg, %1.bd+$1} -#else m68020 +#else TBL68020 with exact regAcon any4 kills allexceptcon gen move %2, {offsetted4, %1.reg, %1.bd+$1} @@ -1474,7 +1468,7 @@ with exact absind_con any4 with exact ext_regX any4 kills allexceptcon gen move %2, {abs_index4, %1.sc, %1.xreg, %1.bd+$1} -#endif m68020 +#endif TBL68020 pat sti $1==1 with A_REG data1 @@ -1486,14 +1480,14 @@ with exact local_addr data1 with exact ext_addr data1 kills allexceptcon gen move %2, {absolute1, %1.bd} -#ifndef m68020 +#ifndef TBL68020 with regAcon data1 kills allexceptcon gen move %2, {offsetted1, %1.reg, %1.bd} with regAregXcon data1 kills allexceptcon gen move %2, {index_off1, %1.reg, %1.xreg, %1.sc, %1.bd} -#else m68020 +#else TBL68020 with exact regAcon data1 kills allexceptcon gen move %2, {offsetted1, %1.reg, %1.bd} @@ -1539,7 +1533,7 @@ with exact absind_con data1 with exact ext_regX data1 kills allexceptcon gen move %2, {abs_index1, %1.sc, %1.xreg, %1.bd} -#endif m68020 +#endif TBL68020 pat sti $1==2 with A_REG any2 @@ -1551,14 +1545,14 @@ with exact local_addr any2 with exact ext_addr any2 kills allexceptcon gen move %2, {absolute2, %1.bd} -#ifndef m68020 +#ifndef TBL68020 with regAcon any2 kills allexceptcon gen move %2, {offsetted2, %1.reg, %1.bd} with regAregXcon any2 kills allexceptcon gen move %2, {index_off2, %1.reg, %1.xreg, %1.sc, %1.bd} -#else m68020 +#else TBL68020 with exact regAcon any2 kills allexceptcon gen move %2, {offsetted2, %1.reg, %1.bd} @@ -1604,7 +1598,7 @@ with exact absind_con any2 with exact ext_regX any2 kills allexceptcon gen move %2, {abs_index2, %1.sc, %1.xreg, %1.bd} -#endif m68020 +#endif TBL68020 pat sti $1==4 with A_REG any4 @@ -1618,14 +1612,14 @@ with exact local_addr any4 with exact ext_addr any4 kills allexceptcon gen move %2, {absolute4, %1.bd} -#ifndef m68020 +#ifndef TBL68020 with regAcon any4 kills allexceptcon gen move %2, {offsetted4, %1.reg, %1.bd} with regAregXcon any4 kills allexceptcon gen move %2, {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd} -#else m68020 +#else TBL68020 with exact regAcon any4 kills allexceptcon gen move %2, {offsetted4, %1.reg, %1.bd} @@ -1671,7 +1665,7 @@ with exact absind_con any4 with exact ext_regX any4 kills allexceptcon gen move %2, {abs_index4, %1.sc, %1.xreg, %1.bd} -#endif m68020 +#endif TBL68020 pat sti $1>4 with AA_REG STACK @@ -1709,12 +1703,12 @@ with exact ext_addr any4 any4 kills allexceptcon gen move %2, {absolute4, %1.bd+$1} move %3, {absolute4, %1.bd+$1+4} -#ifndef m68020 +#ifndef TBL68020 with regAcon any4 any4 kills allexceptcon gen move %2, {offsetted4, %1.reg, %1.bd+$1} move %3, {offsetted4, %1.reg, %1.bd+$1+4} -#else m68020 +#else TBL68020 with exact regAcon any4 any4 kills allexceptcon gen move %2, {offsetted4, %1.reg, %1.bd+$1} @@ -1775,7 +1769,7 @@ with exact ext_regX any4 any4 kills allexceptcon gen move %2, {abs_index4, %1.sc, %1.xreg, %1.bd+$1} move %3, {abs_index4, %1.sc, %1.xreg, %1.bd+$1+4} -#endif m68020 +#endif TBL68020 @@ -1806,38 +1800,38 @@ with any4 AA_REG gen sub_l %1, %2 yields %2 pat mli $1==4 -#ifdef m68020 +#ifdef TBL68020 with data4 DD_REG gen muls_l %1, %2 yields %2 -#else m68020 +#else TBL68020 with STACK gen jsr {absolute4, ".mli"} yields d1 -#endif m68020 +#endif TBL68020 pat dvi $1==4 -#ifdef m68020 +#ifdef TBL68020 with data4 DD_REG gen divs_l %1, %2 yields %2 -#else m68020 +#else TBL68020 with STACK gen jsr {absolute4, ".dvi"} yields d1 -#endif m68020 +#endif TBL68020 pat rmi $1==4 -#ifdef m68020 +#ifdef TBL68020 with data4 DD_REG uses DD_REG gen divsl_l %1, {DREG_pair, %a, %2} killreg %2 /* !!!! contents of %2 have changed: make this known to cg */ yields %a -#else m68020 +#else TBL68020 with STACK gen jsr {absolute4, ".dvi"} yields d0 -#endif m68020 +#endif TBL68020 pat ngi $1==4 with DD_REG @@ -1863,38 +1857,38 @@ pat adu leaving adi $1 pat sbu leaving sbi $1 pat mlu $1==4 -#ifdef m68020 +#ifdef TBL68020 with data4 DD_REG gen mulu_l %1, %2 yields %2 -#else m68020 +#else TBL68020 with STACK gen jsr {absolute4, ".mlu"} yields d1 -#endif m68020 +#endif TBL68020 pat dvu $1==4 -#ifdef m68020 +#ifdef TBL68020 with data4 DD_REG gen divu_l %1, %2 yields %2 -#else m68020 +#else TBL68020 with STACK gen jsr {absolute4, ".dvu"} yields d1 -#endif m68020 +#endif TBL68020 pat rmu $1==4 -#ifdef m68020 +#ifdef TBL68020 with data4 DD_REG uses DD_REG gen divul_l %1, {DREG_pair, %a, %2} killreg %2 /* !!!! contents of %2 have changed: make this known to cg */ yields %a -#else m68020 +#else TBL68020 with STACK gen jsr {absolute4, ".dvu"} yields d0 -#endif m68020 +#endif TBL68020 pat slu leaving sli $1 @@ -1935,7 +1929,7 @@ with exact regAcon + t_regAcon yields {t_regAcon, %1.reg, %1.bd+$1} with exact regAregXcon + t_regAregXcon yields {t_regAregXcon,%1.reg, %1.xreg, %1.sc, %1.bd+$1} -#ifdef m68020 +#ifdef TBL68020 with exact indirect4 yields {off_con, %1.reg, 0, $1} with exact LOCAL yields {off_con, lb, %1.bd, $1} with exact offsetted4 yields {off_con, %1.reg, %1.bd, $1} @@ -1951,7 +1945,7 @@ with exact abs_regXcon yields {abs_regXcon, %1.sc, %1.xreg, %1.bd, %1.od+$1} with exact abs_index4 yields {absind_con, %1.sc, %1.xreg, %1.bd, $1} with exact absind_con yields {absind_con, %1.sc, %1.xreg, %1.bd, %1.od+$1} with exact ext_regX yields {ext_regX, %1.sc, %1.xreg, %1.bd+$1} -#endif m68020 +#endif TBL68020 pat ads $1==4 with D_REG A_REG yields {regAregXcon, %2, %1, 1, 0} @@ -1961,7 +1955,7 @@ with D_REG local_addr yields {t_regAregXcon, lb, %1, 1, %2.bd} with any4-D_REG AA_REG gen add_l %1, %2 yields %2 -#ifdef m68020 +#ifdef TBL68020 with D_REG yields {regX, 1, %1} leaving ads 4 @@ -2000,7 +1994,7 @@ with exact LOCAL ext_regX yields {off_regXcon, lb, %2.xreg, %2.sc, %1.bd, %2.bd} with exact absolute4 ext_regX yields {abs_regXcon, %2.sc, %2.xreg, %1.bd, %2.bd} -#endif m68020 +#endif TBL68020 /* I WOULD ALSO LIKE THIS: * pat ads @@ -2010,7 +2004,7 @@ with exact absolute4 ext_regX pat sbs $1==4 leaving sbi 4 -#ifdef m68020 +#ifdef TBL68020 pat loc sli ads $1==1 && $2==4 && $3==4 with D_REG yields {regX, 2, %1} leaving ads 4 @@ -2022,7 +2016,7 @@ with D_REG yields {regX, 4, %1} pat loc sli ads $1==3 && $2==4 && $3==4 with D_REG yields {regX, 8, %1} leaving ads 4 -#endif m68020 +#endif TBL68020 /************************************************ @@ -2293,11 +2287,11 @@ pat lae sar $2==4 && nicesize(rom($1,3)) pat lae aar $2==4 && rom($1,3)==1 leaving ads 4 adp 0-rom($1,1) -#ifdef m68020 +#ifdef TBL68020 pat lae aar $2==4 && nicesize(rom($1,3)) with D_REG yields {regX, rom($1,3), %1} leaving ads 4 adp rom($1,3)*(0-rom($1,1)) -#else m68020 +#else TBL68020 pat lae aar $2==4 && rom($1,3)==2 with DD_REG gen asl_l {shconst, 1}, %1 @@ -2315,7 +2309,7 @@ with DD_REG gen asl_l {shconst, 3}, %1 yields %1 leaving ads 4 adp (0 - rom($1,1))<<3 -#endif m68020 +#endif TBL68020 /* I WOULD ALSO LIKE THESE: * pat lae aar $2==4 && defined(rom($1,3)) @@ -2494,14 +2488,14 @@ with A_REG STACK with STACK uses AA_REG = {post_inc4, sp} gen jsr {indirect4, %a} -#ifdef m68020 +#ifdef TBL68020 with exact address kills ALL gen jsr %1 -#else m68020 +#else TBL68020 with address STACK gen jsr %1 -#endif m68020 +#endif TBL68020 pat cal with STACK @@ -2642,12 +2636,12 @@ with STACK uses AA_REG = {ext_addr, $1} gen move_l {offsetted4, %a, 8}, lb move_l {offsetted4, %a, 4}, sp -#ifdef m68020 +#ifdef TBL68020 jmp {OFF_off4, %a, 0, 0} -#else m68020 +#else TBL68020 move_l {indirect4, %a}, %a jmp {indirect4, %a} -#endif m68020 +#endif TBL68020 pat lim yields {absolute4, ".trpim"} @@ -2676,7 +2670,7 @@ with STACK gen jsr {absolute4, ".nop"} pat rck -#ifdef m68020 +#ifdef TBL68020 with ext_addr D_REG gen cmp2_l {absolute4, %1.bd}, %2 bcc {slabel, 1f} @@ -2695,10 +2689,10 @@ with A_REG D_REG pea {absolute4, 1} /* push constant 1 == ERANGE */ jsr {absolute4, ".trp"} 1: yields %2 -#else m68020 +#else TBL68020 with STACK gen jsr {absolute4, ".rck"} -#endif m68020 +#endif TBL68020 pat rtt leaving ret 0 @@ -2715,11 +2709,11 @@ with any4 pat str $1==0 with any4 -#ifdef m68020 +#ifdef TBL68020 kills LOCAL, ILOCAL, all_regind %reg==lb, local_addr -#else m68020 +#else TBL68020 kills LOCAL, all_regind %reg==lb, local_addr -#endif m68020 +#endif TBL68020 gen move %1, lb pat str $1==1 @@ -2752,14 +2746,14 @@ with conreg4 proc lilxxxsil example lil adi sil with conreg4 -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen xxx* %1, {ILOCAL, $1} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen xxx* %1, {indirect4, %a} -#endif m68020 +#endif TBL68020 proc lolcxxxstl example lol loc adi stl kills all_indir, LOCAL %bd==$1 @@ -2770,14 +2764,14 @@ proc loecxxxste example loe loc adi ste gen xxx* {const, $2}, {absolute4, $1} proc lilcxxxsil example lil loc adi sil -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen xxx* {const, $2}, {ILOCAL, $1} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen xxx* {const, $2}, {indirect4, %a} -#endif m68020 +#endif TBL68020 proc lolrxxxstl example lol lol adi stl kills all_indir, LOCAL %bd==$1 @@ -2788,14 +2782,14 @@ proc loerxxxste example loe lol adi ste gen xxx* {LOCAL, $2}, {absolute4, $1} proc lilrxxxsil example lil lol adi sil -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen xxx* {LOCAL, $2}, {ILOCAL, $1} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen xxx* {LOCAL, $2}, {indirect4, %a} -#endif m68020 +#endif TBL68020 pat lol adi stl $1==$3 && $2==4 call lolxxxstl("add.l") pat loe adi ste $1==$3 && $2==4 call loexxxste("add.l") @@ -2830,12 +2824,12 @@ pat lol adp stl $1==$3 pat lil adp sil $1==$3 kills allexceptcon -#ifdef m68020 +#ifdef TBL68020 gen add_l {const, $2}, {ILOCAL, $1} -#else m68020 +#else TBL68020 uses AA_REG = {LOCAL, $1} gen add_l {const, $2}, {indirect4, %a} -#endif m68020 +#endif TBL68020 pat loe adp ste $1==$3 kills posextern @@ -2849,14 +2843,14 @@ pat lol lol adp stl $1==$2 && $1==$4 pat lil lil adp sti $1==$2 && $1==$4 kills allexceptcon -#ifdef m68020 +#ifdef TBL68020 uses AA_REG = {ILOCAL, $1} gen add_l {const, $3}, {ILOCAL, $1} -#else m68020 +#else TBL68020 uses AA_REG, AA_REG = {LOCAL, $1} gen move {indirect4, %b}, %a add_l {const, $3}, {indirect4, %b} -#endif m68020 +#endif TBL68020 yields %a pat loe loe adp ste $1==$2 && $1==$4 @@ -2936,16 +2930,16 @@ proc lloe1shste example loe loc sli ste /* only left */ roxl {absolute2, $1} proc llil1shsil example lil loc sli sil /* only left */ -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen shw* {OFF_off2, lb, $1, 2} roxl {OFF_off2, lb, $1, 0} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen shw* {offsetted2, %a, 2} roxl {indirect2, %a} -#endif m68020 +#endif TBL68020 proc rlol1shstl example lol loc sri stl /* only right */ kills all_indir, LOCAL %bd==$1 @@ -2958,16 +2952,16 @@ proc rloe1shste example loe loc sri ste /* only right */ roxr {absolute2, $1+2} proc rlil1shsil example lil loc sri sil /* only right */ -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen shw* {OFF_off2, lb, $1, 0} roxr {OFF_off2, lb, $1, 2} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen shw* {indirect2, %a} roxr {offsetted2, %a, 2} -#endif m68020 +#endif TBL68020 pat lol loc sli stl $1==$4 && $2==1 && $3==4 call llol1shstl("asl #1,") pat loe loc sli ste $1==$4 && $2==1 && $3==4 call lloe1shste("asl #1,") @@ -3003,14 +2997,14 @@ proc loebitste example loe ngi ste gen bit* {absolute4, $1} proc lilbitsil example lil ngi sil -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen bit* {ILOCAL, $1} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen bit* {indirect4, %a} -#endif m68020 +#endif TBL68020 pat lol ngi stl $1==$3 && $2==4 call lolbitstl("neg.l") pat loe ngi ste $1==$3 && $2==4 call loebitste("neg.l") @@ -3020,24 +3014,24 @@ pat loe com ste $1==$3 && $2==4 call loebitste("not.l") pat lil com sil $1==$3 && $2==4 call lilbitsil("not.l") pat lil inc sil $1==$3 -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen add_l {const, 1}, {ILOCAL, $1} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen add_l {const, 1}, {indirect4, %a} -#endif m68020 +#endif TBL68020 pat lil dec sil $1==$3 -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen sub_l {const, 1}, {ILOCAL, $1} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen sub_l {const, 1}, {indirect4, %a} -#endif m68020 +#endif TBL68020 proc txxand @@ -3256,12 +3250,12 @@ with DD_REG pat loc loc cii $1==1 && $2==4 with DD_REG -#ifdef m68020 +#ifdef TBL68020 gen extb_l %1 yields %1 -#else m68020 +#else TBL68020 gen ext_w %1 ext_l %1 yields %1 -#endif m68020 +#endif TBL68020 pat loc loc ciu $1==$2 /* skip this */ pat loc loc cui $1==$2 /* skip this */ diff --git a/mach/m68k2/ncg/mach.c b/mach/m68k2/ncg/mach.c index 3d3073a5..1cd93771 100644 --- a/mach/m68k2/ncg/mach.c +++ b/mach/m68k2/ncg/mach.c @@ -19,13 +19,7 @@ * machine dependent back end routines for the Motorola 68000, 68010 or 68020 */ -#ifndef m68k4 -#define m68020 -#endif - /* use m68020 when you want a m68020 cg, don't if you want a - * m68k4 cg. The m68k4 cg can be used for both the MC68000 - * and the MC68010. - */ +#include "whichone.h" con_part(sz,w) register sz; word w; { @@ -138,7 +132,7 @@ save() /* initialise register-parameters */ for (p = regsav; p < ®sav[regnr]; p++) { if (p->rs_off >= 0) { -#ifdef m68020 +#ifdef TBL68020 fprintf(codefile,"move.%c (%ld,a6),%s\n", #else fprintf(codefile,"move.%c %ld(a6),%s\n", @@ -196,7 +190,7 @@ regreturn() prolog(nlocals) full nlocals; { -#ifdef m68020 +#ifdef TBL68020 fprintf(codefile,"tst.b (-%ld,sp)\nlink\ta6,#-%ld\n",nlocals+40,nlocals); #else fprintf(codefile,"tst.b -%ld(sp)\nlink\ta6,#-%ld\n",nlocals+40,nlocals); diff --git a/mach/m68k2/ncg/mach.h b/mach/m68k2/ncg/mach.h index ff2cf66c..48763723 100644 --- a/mach/m68k2/ncg/mach.h +++ b/mach/m68k2/ncg/mach.h @@ -1,9 +1,12 @@ -#ifndef m68k4 -#define m68020 +#include "whichone.h" + +#ifndef TBL68020 +#ifndef TBL68000 +Something is very wrong here. You must specify the machine: either +TBL68000 or TBL68020, in the file whichone.h, then REMOVE tables.c +and then run "make" again +#endif #endif - /* m68020 should be used for a m68020 cg, and it should - * not be used for a m68k4 cg - */ #define ex_ap(y) fprintf(codefile,".extern %s\n",y) #define in_ap(y) /* nothing */ @@ -20,7 +23,7 @@ #define dlb_fmt "_%d" #define hol_fmt "hol%d" -#ifdef m68020 +#ifdef TBL68020 #define loc_off "(%d,a6)" #define arg_off "(8+%d,a6)" #else @@ -35,5 +38,6 @@ #define modhead ".sect .text\n.sect .rom\n.sect .data\n.sect .bss\n" -#define id_first '_' +#define fmt_id(sf,st) sprintf(st,"_%s",sf) + #define BSS_INIT 0 diff --git a/mach/m68k2/ncg/table b/mach/m68k2/ncg/table index 6518487a..d6166d16 100644 --- a/mach/m68k2/ncg/table +++ b/mach/m68k2/ncg/table @@ -6,13 +6,7 @@ ********************************/ -#ifndef m68k4 -#define m68020 -#endif - /* m68020 to be defined if this is the 68020 table. - * The 68000 and 68010 tables are identical. - */ - +#include "whichone.h" #define small(x) ((x)>=1 && (x)<=8) #define nicesize(x) ((x)==1||(x)==2||(x)==4||(x)==8) @@ -107,7 +101,7 @@ llabel = {ADDR bd;} 4 cost(2,0) bd . slabel = {ADDR bd;} 4 cost(0,0) bd . shconst = {INT num;} 4 cost(0,0) "#" num . -#ifndef m68020 +#ifndef TBL68020 /* Part (ii) */ absolute4 = {ADDR bd;} 4 cost(4,8) bd . offsetted4 = {A_REG reg; INT bd;} 4 cost(2,6) bd "(" reg ")" . @@ -133,7 +127,7 @@ regAregXcon = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,8) t_regAregXcon = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,8) . t_regAcon = {A_REG reg; INT bd;} 4 cost(2,6) . -#else m68020 +#else TBL68020 /* Part (iii) */ absolute4 = {ADDR bd;} 4 cost(4,7) "(" bd ")" . offsetted4 = {A_REG reg; INT bd;} 4 cost(2,6) "(" bd "," reg ")" . @@ -216,7 +210,7 @@ DREG_pair = {D_REG reg1; D_REG reg2;} 8 cost(2,0) reg1 ":" reg2 . #define t_regAregXcon regAregXcon #define t_regAcon regAcon -#endif m68020 +#endif TBL68020 SETS @@ -224,7 +218,7 @@ SETS * because cgg is one pass. */ -#ifndef m68020 +#ifndef TBL68020 /* A m68k4 part */ data4 = D_REG + LOCAL + const + post_inc4 + pre_dec4 + indirect4 + offsetted4 + index_off4 + absolute4 + @@ -249,7 +243,7 @@ control1 = indirect1 + offsetted1 + index_off1 + absolute1 . alterable1 = data1 - const . any1 = data1 . -#else m68020 +#else TBL68020 data4 = D_REG + indirect4 + post_inc4 + pre_dec4 + index_off4 + offsetted4 + OFF_off4 + OFF_indoff4 + @@ -282,7 +276,7 @@ control1 = memory1 - (post_inc1 + pre_dec1 + const) . alterable1 = data1 - const . any1 = data1 . /* all four above together */ -#endif m68020 +#endif TBL68020 /* This is a common part */ any = any4 + any2 + any1 . absolute = absolute4 + absolute2 + absolute1 . @@ -293,7 +287,7 @@ pre_post = pre_dec4 + pre_dec2 + pre_dec1 + offsetted = offsetted4 + offsetted2 + offsetted1 . index_off = index_off4 + index_off2 + index_off1 . -#ifndef m68020 +#ifndef TBL68020 /* A m68k4 part */ regind_addr = regAcon + regAregXcon + t_regAcon + t_regAregXcon . address = ext_addr + local_addr + regAcon + regAregXcon . @@ -305,7 +299,7 @@ allexceptcon = ALL - ( D_REG + A_REG + const + t_regAcon + t_regAregXcon ) . use_index = index_off4 + index_off2 + index_off1 . -#else m68020 +#else TBL68020 reg_memind4 = OFF_off4 + OFF_indoff4 + INDOFF_off4 . memind4 = reg_memind4 + @@ -347,7 +341,7 @@ use_indaddr = regAregXcon + use_index = use_index4 + use_index2 + use_index1 + use_indaddr + regX . -#endif m68020 +#endif TBL68020 /* A common part */ posextern = absolute + all_indir . @@ -366,7 +360,7 @@ memalt4 = memory4 * alterable4 . memalt2 = memory2 * alterable2 . memalt1 = memory1 * alterable1 . -#ifndef m68020 +#ifndef TBL68020 /* A m68k4 part */ imm_cmp4 = alterable4 . imm_cmp2 = alterable2 . @@ -376,7 +370,7 @@ test_set4 = datalt4 . test_set2 = datalt2 . test_set1 = datalt1 . -#else m68020 +#else TBL68020 imm_cmp4 = any4 - immediate4 . imm_cmp2 = any2 - const . @@ -386,15 +380,15 @@ test_set4 = data4 - immediate4 . test_set2 = data2 - const . test_set1 = data1 - const . -#endif m68020 +#endif TBL68020 test_set = test_set4 + test_set2 + test_set1 . -#ifndef m68020 +#ifndef TBL68020 t_address = address + t_regAregXcon + t_regAcon . -#else m68020 +#else TBL68020 #define t_address address -#endif m68020 +#endif TBL68020 INSTRUCTIONS @@ -425,12 +419,12 @@ sh "illegal" shconreg:ro, LOCAL:rw:cc cost(0,0). sh "illegal" LOCAL:ro, LOCAL:rw:cc cost(0,0). xxx "illegal" data4:ro, LOCAL:rw:cc cost(0,0). xxx "illegal" LOCAL:ro, alterable4:rw:cc cost(0,0). -#ifdef m68020 +#ifdef TBL68020 divs_l "divs.l" data4:ro, LOCAL:rw:cc cost(0,90). divu_l "divu.l" data4:ro, LOCAL:rw:cc cost(0,78). muls_l "muls.l" data4:ro, LOCAL:rw:cc cost(0,44). mulu_l "mulu.l" data4:ro, LOCAL:rw:cc cost(0,44). -#endif m68020 +#endif TBL68020 add_l "add.l" any4:ro, D_REG:rw:cc cost(2,3). add_l "add.l" any4:ro, A_REG:rw cost(2,3). @@ -517,7 +511,7 @@ bit "illegal" control4:rw:cc cost(2,6). sh "illegal" shconreg:ro, D_REG:rw:cc cost(2,4). shw "illegal" control2:rw:cc cost(2,4). -#ifdef m68020 +#ifdef TBL68020 cmp2_l "cmp2.l" address+control4:ro, genreg:ro kills :cc cost(2,18). divs_l "divs.l" data4:ro, D_REG:rw:cc cost(2,90). divsl_l "divsl.l" data4:ro, DREG_pair:rw kills :cc cost(2,90). @@ -527,9 +521,9 @@ extb_l "extb.l" D_REG:rw:cc cost(2,4). muls_l "muls.l" data4:ro, D_REG:rw:cc cost(2,44). mulu_l "mulu.l" data4:ro, D_REG:rw:cc cost(2,44). pea address+control4+regX cost(2,4). -#else m68020 +#else TBL68020 pea address+control4 cost(2,4). -#endif m68020 +#endif TBL68020 /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * Extra pseudo instruction; it just kills a D_REG; @@ -562,7 +556,7 @@ from const to memalt2 from regAcon %bd==0 to A_REG gen move_l %1.reg, %2 -#ifndef m68020 +#ifndef TBL68020 from t_regAregXcon sfit(%bd, 8) to A_REG gen lea {regAregXcon, %1.reg, %1.xreg, 1, %1.bd}, %2 @@ -576,7 +570,7 @@ from t_regAcon sfit(%bd, 16) to A_REG from t_regAcon to A_REG gen move_l %1.reg, %2 add_l {const, %1.bd}, %2 -#endif m68020 +#endif TBL68020 from address - ext_addr to A_REG gen lea %1, %2 @@ -612,7 +606,7 @@ STACKINGRULES from const %num==0 to STACK gen clr_l {pre_dec4, sp} -#ifndef m68020 +#ifndef TBL68020 from t_regAregXcon sfit(%bd, 8) to STACK gen pea {regAregXcon, %1.reg, %1.xreg, 1, %1.bd} @@ -626,7 +620,7 @@ from t_regAcon sfit(%bd, 16) to STACK from t_regAcon to STACK gen move_l %1.reg, {pre_dec4, sp} add_l {const, %1.bd}, {indirect4, sp} -#endif m68020 +#endif TBL68020 from address - ext_addr to STACK gen pea %1 @@ -648,10 +642,10 @@ from data1 to STACK gen clr_l {pre_dec4, sp} move_b %1, {offsetted1, sp, 3} -#ifdef m68020 +#ifdef TBL68020 from regX to STACK gen pea %1 -#endif m68020 +#endif TBL68020 /* This last stackingrule is never used: whenever regX is put on * the fakestack, some em-instuctions are left that remove it * immediately. However cgg complained about not having a @@ -672,7 +666,7 @@ from STACK gen move_l {post_inc4, sp}, %a yields %a -#ifndef m68020 +#ifndef TBL68020 from t_regAregXcon sfit(%bd, 8) yields {regAregXcon, %1.reg, %1.xreg, 1, %1.bd} @@ -688,7 +682,7 @@ from t_regAcon uses reusing %1, AA_REG=%1.reg gen add_l {const, %1.bd}, %a yields %a -#endif m68020 +#endif TBL68020 from t_address uses reusing %1, AA_REG = %1 @@ -835,7 +829,7 @@ pat lol loc ror stl $1==$4 && small($2) && $3==4 && inreg($1)==reg_any pat lol lol ror stl $1==$4 && inreg($2)==reg_any && $3==4 && inreg($1)==reg_any call lolrshstl("ror.l") -#ifdef m68020 +#ifdef TBL68020 pat lol loc dvi stl $1==$4 && $3==4 && inreg($1)==reg_any kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) gen divs_l {const, $2}, {LOCAL, $1} @@ -861,7 +855,7 @@ pat lol mlu stl $1==$3 && $2==4 && inreg($1)==reg_any with data4 kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) gen mulu_l %1, {LOCAL, $1} -#endif m68020 +#endif TBL68020 pat lil inc sil $1==$3 && inreg($1)==reg_pointer @@ -1126,12 +1120,12 @@ pat ldl leaving lol $1+4 lol $1 pat loe yields {absolute4, $1} pat lil -#ifdef m68020 +#ifdef TBL68020 yields {ILOCAL, $1} -#else m68020 +#else TBL68020 uses AA_REG = {LOCAL, $1} yields {indirect4, %a} -#endif m68020 +#endif TBL68020 /* When using the 'offsetted' intructions regAregXcon cannot be used * for the m68k4; there is no way of knowing about the size of @@ -1145,9 +1139,9 @@ pat lof with A_REG yields {offsetted4, %1, $1} with exact local_addr yields {LOCAL, %1.bd+$1} with exact ext_addr yields {absolute4, %1.bd+$1} -#ifndef m68020 +#ifndef TBL68020 with regAcon yields {offsetted4, %1.reg, %1.bd+$1} -#else m68020 +#else TBL68020 with exact regAcon yields {offsetted4, %1.reg, %1.bd+$1} with exact regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1} with exact offsetted4 yields {OFF_off4, %1.reg, %1.bd, $1} @@ -1165,7 +1159,7 @@ with exact abs_regXcon yields {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od+$1} with exact abs_index4 yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, $1} with exact absind_con yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1} with exact ext_regX yields {abs_index4, %1.sc, %1.xreg, %1.bd+$1} -#endif m68020 +#endif TBL68020 pat lal yields {local_addr, $1} @@ -1176,20 +1170,20 @@ pat lxl $1==0 yields lb pat lxl $1==1 yields {LOCAL, SL} pat lxl $1==2 -#ifdef m68020 +#ifdef TBL68020 yields {OFF_off4, lb, SL, SL} -#else m68020 +#else TBL68020 uses AA_REG = {LOCAL, SL} yields {offsetted4, %a, SL} -#endif m68020 +#endif TBL68020 pat lxl $1==3 -#ifdef m68020 +#ifdef TBL68020 uses AA_REG = {OFF_off4, lb, SL, SL} -#else m68020 +#else TBL68020 uses AA_REG = {LOCAL, SL} gen move {offsetted4, %a, SL}, %a -#endif m68020 +#endif TBL68020 yields {offsetted4, %a, SL} pat lxl $1>3 @@ -1203,20 +1197,20 @@ pat lxl $1>3 pat lxa $1==0 yields {local_addr, SL} pat lxa $1==1 -#ifdef m68020 +#ifdef TBL68020 yields {off_con, lb, SL, SL} -#else m68020 +#else TBL68020 uses AA_REG = {LOCAL, SL} yields {regAcon, %a, SL} -#endif m68020 +#endif TBL68020 pat lxa $1==2 -#ifdef m68020 +#ifdef TBL68020 uses AA_REG = {OFF_off4, lb, SL, SL} -#else m68020 +#else TBL68020 uses AA_REG = {LOCAL, SL} gen move {offsetted4, %a, SL}, %a -#endif m68020 +#endif TBL68020 yields {regAcon, %a, SL} pat lxa $1>2 @@ -1231,10 +1225,10 @@ pat loi $1==1 with A_REG yields {indirect1, %1} with exact local_addr yields {offsetted1, lb, %1.bd} with exact ext_addr yields {absolute1, %1.bd} -#ifndef m68020 +#ifndef TBL68020 with regAcon yields {offsetted1, %1.reg, %1.bd} with regAregXcon yields {index_off1, %1.reg, %1.xreg, %1.sc, %1.bd} -#else m68020 +#else TBL68020 with exact regAcon yields {offsetted1, %1.reg, %1.bd} with exact regAregXcon yields {index_off1, %1.reg, %1.xreg, %1.sc, %1.bd} with exact indirect4 yields {OFF_off1, %1.reg, 0, 0} @@ -1252,16 +1246,16 @@ with exact abs_regXcon yields {ABS_indoff1, %1.sc, %1.xreg, %1.bd, %1.od} with exact abs_index4 yields {ABSIND_off1, %1.sc, %1.xreg, %1.bd, 0} with exact absind_con yields {ABSIND_off1, %1.sc, %1.xreg, %1.bd, %1.od} with exact ext_regX yields {abs_index1, %1.sc, %1.xreg, %1.bd} -#endif m68020 +#endif TBL68020 pat loi $1==2 with A_REG yields {indirect2, %1} with exact local_addr yields {offsetted2, lb, %1.bd} with exact ext_addr yields {absolute2, %1.bd} -#ifndef m68020 +#ifndef TBL68020 with regAcon yields {offsetted2, %1.reg, %1.bd} with regAregXcon yields {index_off2, %1.reg, %1.xreg, %1.sc, %1.bd} -#else m68020 +#else TBL68020 with exact regAcon yields {offsetted2, %1.reg, %1.bd} with exact regAregXcon yields {index_off2, %1.reg, %1.xreg, %1.sc, %1.bd} with exact indirect4 yields {OFF_off2, %1.reg, 0, 0} @@ -1279,16 +1273,16 @@ with exact abs_regXcon yields {ABS_indoff2, %1.sc, %1.xreg, %1.bd, %1.od} with exact abs_index4 yields {ABSIND_off2, %1.sc, %1.xreg, %1.bd, 0} with exact absind_con yields {ABSIND_off2, %1.sc, %1.xreg, %1.bd, %1.od} with exact ext_regX yields {abs_index2, %1.sc, %1.xreg, %1.bd} -#endif m68020 +#endif TBL68020 pat loi $1==4 with A_REG yields {indirect4, %1} with exact local_addr yields {LOCAL, %1.bd} with exact ext_addr yields {absolute4, %1.bd} -#ifndef m68020 +#ifndef TBL68020 with regAcon yields {offsetted4, %1.reg, %1.bd} with regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd} -#else m68020 +#else TBL68020 with exact regAcon yields {offsetted4, %1.reg, %1.bd} with exact regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd} with exact LOCAL yields {ILOCAL, %1.bd} @@ -1306,7 +1300,7 @@ with exact abs_regXcon yields {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od} with exact abs_index4 yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, 0} with exact absind_con yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od} with exact ext_regX yields {abs_index4, %1.sc, %1.xreg, %1.bd} -#endif m68020 +#endif TBL68020 pat loi $1==8 with A_REG yields {offsetted4, %1, 4} @@ -1333,10 +1327,10 @@ with exact local_addr yields {LOCAL, %1.bd+$1+4} {LOCAL, %1.bd+$1} with exact ext_addr yields {absolute4, %1.bd+$1+4} {absolute4, %1.bd+$1} -#ifndef m68020 +#ifndef TBL68020 with regAcon yields {offsetted4, %1.reg, %1.bd+$1+4} {offsetted4, %1.reg, %1.bd+$1} -#else m68020 +#else TBL68020 with exact regAcon yields {offsetted4, %1.reg, %1.bd+$1+4} {offsetted4, %1.reg, %1.bd+$1} with exact regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1+4} @@ -1371,7 +1365,7 @@ with exact absind_con yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1+4} {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1} with exact ext_regX yields {abs_index4, %1.sc, %1.xreg, %1.bd+$1+4} {abs_index4, %1.sc, %1.xreg, %1.bd+$1} -#endif m68020 +#endif TBL68020 pat lpi yields {ext_addr, $1} @@ -1396,13 +1390,13 @@ with exact STACK gen move {post_inc4, sp}, {absolute4, $1} pat sil -#ifdef m68020 +#ifdef TBL68020 with any4 kills allexceptcon gen move %1, {ILOCAL, $1} with exact STACK gen move {post_inc4, sp}, {ILOCAL, $1} -#else m68020 +#else TBL68020 with any4 kills allexceptcon uses AA_REG = {LOCAL, $1} @@ -1410,7 +1404,7 @@ with any4 with exact STACK uses AA_REG = {LOCAL, $1} gen move {post_inc4, sp}, {indirect4, %a} -#endif m68020 +#endif TBL68020 pat stf with A_REG any4 @@ -1424,11 +1418,11 @@ with exact local_addr any4 with exact ext_addr any4 kills allexceptcon gen move %2, {absolute4, %1.bd+$1} -#ifndef m68020 +#ifndef TBL68020 with regAcon any4 kills allexceptcon gen move %2, {offsetted4, %1.reg, %1.bd+$1} -#else m68020 +#else TBL68020 with exact regAcon any4 kills allexceptcon gen move %2, {offsetted4, %1.reg, %1.bd+$1} @@ -1474,7 +1468,7 @@ with exact absind_con any4 with exact ext_regX any4 kills allexceptcon gen move %2, {abs_index4, %1.sc, %1.xreg, %1.bd+$1} -#endif m68020 +#endif TBL68020 pat sti $1==1 with A_REG data1 @@ -1486,14 +1480,14 @@ with exact local_addr data1 with exact ext_addr data1 kills allexceptcon gen move %2, {absolute1, %1.bd} -#ifndef m68020 +#ifndef TBL68020 with regAcon data1 kills allexceptcon gen move %2, {offsetted1, %1.reg, %1.bd} with regAregXcon data1 kills allexceptcon gen move %2, {index_off1, %1.reg, %1.xreg, %1.sc, %1.bd} -#else m68020 +#else TBL68020 with exact regAcon data1 kills allexceptcon gen move %2, {offsetted1, %1.reg, %1.bd} @@ -1539,7 +1533,7 @@ with exact absind_con data1 with exact ext_regX data1 kills allexceptcon gen move %2, {abs_index1, %1.sc, %1.xreg, %1.bd} -#endif m68020 +#endif TBL68020 pat sti $1==2 with A_REG any2 @@ -1551,14 +1545,14 @@ with exact local_addr any2 with exact ext_addr any2 kills allexceptcon gen move %2, {absolute2, %1.bd} -#ifndef m68020 +#ifndef TBL68020 with regAcon any2 kills allexceptcon gen move %2, {offsetted2, %1.reg, %1.bd} with regAregXcon any2 kills allexceptcon gen move %2, {index_off2, %1.reg, %1.xreg, %1.sc, %1.bd} -#else m68020 +#else TBL68020 with exact regAcon any2 kills allexceptcon gen move %2, {offsetted2, %1.reg, %1.bd} @@ -1604,7 +1598,7 @@ with exact absind_con any2 with exact ext_regX any2 kills allexceptcon gen move %2, {abs_index2, %1.sc, %1.xreg, %1.bd} -#endif m68020 +#endif TBL68020 pat sti $1==4 with A_REG any4 @@ -1618,14 +1612,14 @@ with exact local_addr any4 with exact ext_addr any4 kills allexceptcon gen move %2, {absolute4, %1.bd} -#ifndef m68020 +#ifndef TBL68020 with regAcon any4 kills allexceptcon gen move %2, {offsetted4, %1.reg, %1.bd} with regAregXcon any4 kills allexceptcon gen move %2, {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd} -#else m68020 +#else TBL68020 with exact regAcon any4 kills allexceptcon gen move %2, {offsetted4, %1.reg, %1.bd} @@ -1671,7 +1665,7 @@ with exact absind_con any4 with exact ext_regX any4 kills allexceptcon gen move %2, {abs_index4, %1.sc, %1.xreg, %1.bd} -#endif m68020 +#endif TBL68020 pat sti $1>4 with AA_REG STACK @@ -1709,12 +1703,12 @@ with exact ext_addr any4 any4 kills allexceptcon gen move %2, {absolute4, %1.bd+$1} move %3, {absolute4, %1.bd+$1+4} -#ifndef m68020 +#ifndef TBL68020 with regAcon any4 any4 kills allexceptcon gen move %2, {offsetted4, %1.reg, %1.bd+$1} move %3, {offsetted4, %1.reg, %1.bd+$1+4} -#else m68020 +#else TBL68020 with exact regAcon any4 any4 kills allexceptcon gen move %2, {offsetted4, %1.reg, %1.bd+$1} @@ -1775,7 +1769,7 @@ with exact ext_regX any4 any4 kills allexceptcon gen move %2, {abs_index4, %1.sc, %1.xreg, %1.bd+$1} move %3, {abs_index4, %1.sc, %1.xreg, %1.bd+$1+4} -#endif m68020 +#endif TBL68020 @@ -1806,38 +1800,38 @@ with any4 AA_REG gen sub_l %1, %2 yields %2 pat mli $1==4 -#ifdef m68020 +#ifdef TBL68020 with data4 DD_REG gen muls_l %1, %2 yields %2 -#else m68020 +#else TBL68020 with STACK gen jsr {absolute4, ".mli"} yields d1 -#endif m68020 +#endif TBL68020 pat dvi $1==4 -#ifdef m68020 +#ifdef TBL68020 with data4 DD_REG gen divs_l %1, %2 yields %2 -#else m68020 +#else TBL68020 with STACK gen jsr {absolute4, ".dvi"} yields d1 -#endif m68020 +#endif TBL68020 pat rmi $1==4 -#ifdef m68020 +#ifdef TBL68020 with data4 DD_REG uses DD_REG gen divsl_l %1, {DREG_pair, %a, %2} killreg %2 /* !!!! contents of %2 have changed: make this known to cg */ yields %a -#else m68020 +#else TBL68020 with STACK gen jsr {absolute4, ".dvi"} yields d0 -#endif m68020 +#endif TBL68020 pat ngi $1==4 with DD_REG @@ -1863,38 +1857,38 @@ pat adu leaving adi $1 pat sbu leaving sbi $1 pat mlu $1==4 -#ifdef m68020 +#ifdef TBL68020 with data4 DD_REG gen mulu_l %1, %2 yields %2 -#else m68020 +#else TBL68020 with STACK gen jsr {absolute4, ".mlu"} yields d1 -#endif m68020 +#endif TBL68020 pat dvu $1==4 -#ifdef m68020 +#ifdef TBL68020 with data4 DD_REG gen divu_l %1, %2 yields %2 -#else m68020 +#else TBL68020 with STACK gen jsr {absolute4, ".dvu"} yields d1 -#endif m68020 +#endif TBL68020 pat rmu $1==4 -#ifdef m68020 +#ifdef TBL68020 with data4 DD_REG uses DD_REG gen divul_l %1, {DREG_pair, %a, %2} killreg %2 /* !!!! contents of %2 have changed: make this known to cg */ yields %a -#else m68020 +#else TBL68020 with STACK gen jsr {absolute4, ".dvu"} yields d0 -#endif m68020 +#endif TBL68020 pat slu leaving sli $1 @@ -1935,7 +1929,7 @@ with exact regAcon + t_regAcon yields {t_regAcon, %1.reg, %1.bd+$1} with exact regAregXcon + t_regAregXcon yields {t_regAregXcon,%1.reg, %1.xreg, %1.sc, %1.bd+$1} -#ifdef m68020 +#ifdef TBL68020 with exact indirect4 yields {off_con, %1.reg, 0, $1} with exact LOCAL yields {off_con, lb, %1.bd, $1} with exact offsetted4 yields {off_con, %1.reg, %1.bd, $1} @@ -1951,7 +1945,7 @@ with exact abs_regXcon yields {abs_regXcon, %1.sc, %1.xreg, %1.bd, %1.od+$1} with exact abs_index4 yields {absind_con, %1.sc, %1.xreg, %1.bd, $1} with exact absind_con yields {absind_con, %1.sc, %1.xreg, %1.bd, %1.od+$1} with exact ext_regX yields {ext_regX, %1.sc, %1.xreg, %1.bd+$1} -#endif m68020 +#endif TBL68020 pat ads $1==4 with D_REG A_REG yields {regAregXcon, %2, %1, 1, 0} @@ -1961,7 +1955,7 @@ with D_REG local_addr yields {t_regAregXcon, lb, %1, 1, %2.bd} with any4-D_REG AA_REG gen add_l %1, %2 yields %2 -#ifdef m68020 +#ifdef TBL68020 with D_REG yields {regX, 1, %1} leaving ads 4 @@ -2000,7 +1994,7 @@ with exact LOCAL ext_regX yields {off_regXcon, lb, %2.xreg, %2.sc, %1.bd, %2.bd} with exact absolute4 ext_regX yields {abs_regXcon, %2.sc, %2.xreg, %1.bd, %2.bd} -#endif m68020 +#endif TBL68020 /* I WOULD ALSO LIKE THIS: * pat ads @@ -2010,7 +2004,7 @@ with exact absolute4 ext_regX pat sbs $1==4 leaving sbi 4 -#ifdef m68020 +#ifdef TBL68020 pat loc sli ads $1==1 && $2==4 && $3==4 with D_REG yields {regX, 2, %1} leaving ads 4 @@ -2022,7 +2016,7 @@ with D_REG yields {regX, 4, %1} pat loc sli ads $1==3 && $2==4 && $3==4 with D_REG yields {regX, 8, %1} leaving ads 4 -#endif m68020 +#endif TBL68020 /************************************************ @@ -2293,11 +2287,11 @@ pat lae sar $2==4 && nicesize(rom($1,3)) pat lae aar $2==4 && rom($1,3)==1 leaving ads 4 adp 0-rom($1,1) -#ifdef m68020 +#ifdef TBL68020 pat lae aar $2==4 && nicesize(rom($1,3)) with D_REG yields {regX, rom($1,3), %1} leaving ads 4 adp rom($1,3)*(0-rom($1,1)) -#else m68020 +#else TBL68020 pat lae aar $2==4 && rom($1,3)==2 with DD_REG gen asl_l {shconst, 1}, %1 @@ -2315,7 +2309,7 @@ with DD_REG gen asl_l {shconst, 3}, %1 yields %1 leaving ads 4 adp (0 - rom($1,1))<<3 -#endif m68020 +#endif TBL68020 /* I WOULD ALSO LIKE THESE: * pat lae aar $2==4 && defined(rom($1,3)) @@ -2494,14 +2488,14 @@ with A_REG STACK with STACK uses AA_REG = {post_inc4, sp} gen jsr {indirect4, %a} -#ifdef m68020 +#ifdef TBL68020 with exact address kills ALL gen jsr %1 -#else m68020 +#else TBL68020 with address STACK gen jsr %1 -#endif m68020 +#endif TBL68020 pat cal with STACK @@ -2642,12 +2636,12 @@ with STACK uses AA_REG = {ext_addr, $1} gen move_l {offsetted4, %a, 8}, lb move_l {offsetted4, %a, 4}, sp -#ifdef m68020 +#ifdef TBL68020 jmp {OFF_off4, %a, 0, 0} -#else m68020 +#else TBL68020 move_l {indirect4, %a}, %a jmp {indirect4, %a} -#endif m68020 +#endif TBL68020 pat lim yields {absolute4, ".trpim"} @@ -2676,7 +2670,7 @@ with STACK gen jsr {absolute4, ".nop"} pat rck -#ifdef m68020 +#ifdef TBL68020 with ext_addr D_REG gen cmp2_l {absolute4, %1.bd}, %2 bcc {slabel, 1f} @@ -2695,10 +2689,10 @@ with A_REG D_REG pea {absolute4, 1} /* push constant 1 == ERANGE */ jsr {absolute4, ".trp"} 1: yields %2 -#else m68020 +#else TBL68020 with STACK gen jsr {absolute4, ".rck"} -#endif m68020 +#endif TBL68020 pat rtt leaving ret 0 @@ -2715,11 +2709,11 @@ with any4 pat str $1==0 with any4 -#ifdef m68020 +#ifdef TBL68020 kills LOCAL, ILOCAL, all_regind %reg==lb, local_addr -#else m68020 +#else TBL68020 kills LOCAL, all_regind %reg==lb, local_addr -#endif m68020 +#endif TBL68020 gen move %1, lb pat str $1==1 @@ -2752,14 +2746,14 @@ with conreg4 proc lilxxxsil example lil adi sil with conreg4 -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen xxx* %1, {ILOCAL, $1} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen xxx* %1, {indirect4, %a} -#endif m68020 +#endif TBL68020 proc lolcxxxstl example lol loc adi stl kills all_indir, LOCAL %bd==$1 @@ -2770,14 +2764,14 @@ proc loecxxxste example loe loc adi ste gen xxx* {const, $2}, {absolute4, $1} proc lilcxxxsil example lil loc adi sil -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen xxx* {const, $2}, {ILOCAL, $1} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen xxx* {const, $2}, {indirect4, %a} -#endif m68020 +#endif TBL68020 proc lolrxxxstl example lol lol adi stl kills all_indir, LOCAL %bd==$1 @@ -2788,14 +2782,14 @@ proc loerxxxste example loe lol adi ste gen xxx* {LOCAL, $2}, {absolute4, $1} proc lilrxxxsil example lil lol adi sil -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen xxx* {LOCAL, $2}, {ILOCAL, $1} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen xxx* {LOCAL, $2}, {indirect4, %a} -#endif m68020 +#endif TBL68020 pat lol adi stl $1==$3 && $2==4 call lolxxxstl("add.l") pat loe adi ste $1==$3 && $2==4 call loexxxste("add.l") @@ -2830,12 +2824,12 @@ pat lol adp stl $1==$3 pat lil adp sil $1==$3 kills allexceptcon -#ifdef m68020 +#ifdef TBL68020 gen add_l {const, $2}, {ILOCAL, $1} -#else m68020 +#else TBL68020 uses AA_REG = {LOCAL, $1} gen add_l {const, $2}, {indirect4, %a} -#endif m68020 +#endif TBL68020 pat loe adp ste $1==$3 kills posextern @@ -2849,14 +2843,14 @@ pat lol lol adp stl $1==$2 && $1==$4 pat lil lil adp sti $1==$2 && $1==$4 kills allexceptcon -#ifdef m68020 +#ifdef TBL68020 uses AA_REG = {ILOCAL, $1} gen add_l {const, $3}, {ILOCAL, $1} -#else m68020 +#else TBL68020 uses AA_REG, AA_REG = {LOCAL, $1} gen move {indirect4, %b}, %a add_l {const, $3}, {indirect4, %b} -#endif m68020 +#endif TBL68020 yields %a pat loe loe adp ste $1==$2 && $1==$4 @@ -2936,16 +2930,16 @@ proc lloe1shste example loe loc sli ste /* only left */ roxl {absolute2, $1} proc llil1shsil example lil loc sli sil /* only left */ -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen shw* {OFF_off2, lb, $1, 2} roxl {OFF_off2, lb, $1, 0} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen shw* {offsetted2, %a, 2} roxl {indirect2, %a} -#endif m68020 +#endif TBL68020 proc rlol1shstl example lol loc sri stl /* only right */ kills all_indir, LOCAL %bd==$1 @@ -2958,16 +2952,16 @@ proc rloe1shste example loe loc sri ste /* only right */ roxr {absolute2, $1+2} proc rlil1shsil example lil loc sri sil /* only right */ -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen shw* {OFF_off2, lb, $1, 0} roxr {OFF_off2, lb, $1, 2} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen shw* {indirect2, %a} roxr {offsetted2, %a, 2} -#endif m68020 +#endif TBL68020 pat lol loc sli stl $1==$4 && $2==1 && $3==4 call llol1shstl("asl #1,") pat loe loc sli ste $1==$4 && $2==1 && $3==4 call lloe1shste("asl #1,") @@ -3003,14 +2997,14 @@ proc loebitste example loe ngi ste gen bit* {absolute4, $1} proc lilbitsil example lil ngi sil -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen bit* {ILOCAL, $1} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen bit* {indirect4, %a} -#endif m68020 +#endif TBL68020 pat lol ngi stl $1==$3 && $2==4 call lolbitstl("neg.l") pat loe ngi ste $1==$3 && $2==4 call loebitste("neg.l") @@ -3020,24 +3014,24 @@ pat loe com ste $1==$3 && $2==4 call loebitste("not.l") pat lil com sil $1==$3 && $2==4 call lilbitsil("not.l") pat lil inc sil $1==$3 -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen add_l {const, 1}, {ILOCAL, $1} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen add_l {const, 1}, {indirect4, %a} -#endif m68020 +#endif TBL68020 pat lil dec sil $1==$3 -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen sub_l {const, 1}, {ILOCAL, $1} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen sub_l {const, 1}, {indirect4, %a} -#endif m68020 +#endif TBL68020 proc txxand @@ -3256,12 +3250,12 @@ with DD_REG pat loc loc cii $1==1 && $2==4 with DD_REG -#ifdef m68020 +#ifdef TBL68020 gen extb_l %1 yields %1 -#else m68020 +#else TBL68020 gen ext_w %1 ext_l %1 yields %1 -#endif m68020 +#endif TBL68020 pat loc loc ciu $1==$2 /* skip this */ pat loc loc cui $1==$2 /* skip this */ diff --git a/mach/m68k4/ncg/mach.c b/mach/m68k4/ncg/mach.c index 3d3073a5..1cd93771 100644 --- a/mach/m68k4/ncg/mach.c +++ b/mach/m68k4/ncg/mach.c @@ -19,13 +19,7 @@ * machine dependent back end routines for the Motorola 68000, 68010 or 68020 */ -#ifndef m68k4 -#define m68020 -#endif - /* use m68020 when you want a m68020 cg, don't if you want a - * m68k4 cg. The m68k4 cg can be used for both the MC68000 - * and the MC68010. - */ +#include "whichone.h" con_part(sz,w) register sz; word w; { @@ -138,7 +132,7 @@ save() /* initialise register-parameters */ for (p = regsav; p < ®sav[regnr]; p++) { if (p->rs_off >= 0) { -#ifdef m68020 +#ifdef TBL68020 fprintf(codefile,"move.%c (%ld,a6),%s\n", #else fprintf(codefile,"move.%c %ld(a6),%s\n", @@ -196,7 +190,7 @@ regreturn() prolog(nlocals) full nlocals; { -#ifdef m68020 +#ifdef TBL68020 fprintf(codefile,"tst.b (-%ld,sp)\nlink\ta6,#-%ld\n",nlocals+40,nlocals); #else fprintf(codefile,"tst.b -%ld(sp)\nlink\ta6,#-%ld\n",nlocals+40,nlocals); diff --git a/mach/m68k4/ncg/mach.h b/mach/m68k4/ncg/mach.h index ff2cf66c..48763723 100644 --- a/mach/m68k4/ncg/mach.h +++ b/mach/m68k4/ncg/mach.h @@ -1,9 +1,12 @@ -#ifndef m68k4 -#define m68020 +#include "whichone.h" + +#ifndef TBL68020 +#ifndef TBL68000 +Something is very wrong here. You must specify the machine: either +TBL68000 or TBL68020, in the file whichone.h, then REMOVE tables.c +and then run "make" again +#endif #endif - /* m68020 should be used for a m68020 cg, and it should - * not be used for a m68k4 cg - */ #define ex_ap(y) fprintf(codefile,".extern %s\n",y) #define in_ap(y) /* nothing */ @@ -20,7 +23,7 @@ #define dlb_fmt "_%d" #define hol_fmt "hol%d" -#ifdef m68020 +#ifdef TBL68020 #define loc_off "(%d,a6)" #define arg_off "(8+%d,a6)" #else @@ -35,5 +38,6 @@ #define modhead ".sect .text\n.sect .rom\n.sect .data\n.sect .bss\n" -#define id_first '_' +#define fmt_id(sf,st) sprintf(st,"_%s",sf) + #define BSS_INIT 0 diff --git a/mach/m68k4/ncg/table b/mach/m68k4/ncg/table index 6518487a..d6166d16 100644 --- a/mach/m68k4/ncg/table +++ b/mach/m68k4/ncg/table @@ -6,13 +6,7 @@ ********************************/ -#ifndef m68k4 -#define m68020 -#endif - /* m68020 to be defined if this is the 68020 table. - * The 68000 and 68010 tables are identical. - */ - +#include "whichone.h" #define small(x) ((x)>=1 && (x)<=8) #define nicesize(x) ((x)==1||(x)==2||(x)==4||(x)==8) @@ -107,7 +101,7 @@ llabel = {ADDR bd;} 4 cost(2,0) bd . slabel = {ADDR bd;} 4 cost(0,0) bd . shconst = {INT num;} 4 cost(0,0) "#" num . -#ifndef m68020 +#ifndef TBL68020 /* Part (ii) */ absolute4 = {ADDR bd;} 4 cost(4,8) bd . offsetted4 = {A_REG reg; INT bd;} 4 cost(2,6) bd "(" reg ")" . @@ -133,7 +127,7 @@ regAregXcon = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,8) t_regAregXcon = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,8) . t_regAcon = {A_REG reg; INT bd;} 4 cost(2,6) . -#else m68020 +#else TBL68020 /* Part (iii) */ absolute4 = {ADDR bd;} 4 cost(4,7) "(" bd ")" . offsetted4 = {A_REG reg; INT bd;} 4 cost(2,6) "(" bd "," reg ")" . @@ -216,7 +210,7 @@ DREG_pair = {D_REG reg1; D_REG reg2;} 8 cost(2,0) reg1 ":" reg2 . #define t_regAregXcon regAregXcon #define t_regAcon regAcon -#endif m68020 +#endif TBL68020 SETS @@ -224,7 +218,7 @@ SETS * because cgg is one pass. */ -#ifndef m68020 +#ifndef TBL68020 /* A m68k4 part */ data4 = D_REG + LOCAL + const + post_inc4 + pre_dec4 + indirect4 + offsetted4 + index_off4 + absolute4 + @@ -249,7 +243,7 @@ control1 = indirect1 + offsetted1 + index_off1 + absolute1 . alterable1 = data1 - const . any1 = data1 . -#else m68020 +#else TBL68020 data4 = D_REG + indirect4 + post_inc4 + pre_dec4 + index_off4 + offsetted4 + OFF_off4 + OFF_indoff4 + @@ -282,7 +276,7 @@ control1 = memory1 - (post_inc1 + pre_dec1 + const) . alterable1 = data1 - const . any1 = data1 . /* all four above together */ -#endif m68020 +#endif TBL68020 /* This is a common part */ any = any4 + any2 + any1 . absolute = absolute4 + absolute2 + absolute1 . @@ -293,7 +287,7 @@ pre_post = pre_dec4 + pre_dec2 + pre_dec1 + offsetted = offsetted4 + offsetted2 + offsetted1 . index_off = index_off4 + index_off2 + index_off1 . -#ifndef m68020 +#ifndef TBL68020 /* A m68k4 part */ regind_addr = regAcon + regAregXcon + t_regAcon + t_regAregXcon . address = ext_addr + local_addr + regAcon + regAregXcon . @@ -305,7 +299,7 @@ allexceptcon = ALL - ( D_REG + A_REG + const + t_regAcon + t_regAregXcon ) . use_index = index_off4 + index_off2 + index_off1 . -#else m68020 +#else TBL68020 reg_memind4 = OFF_off4 + OFF_indoff4 + INDOFF_off4 . memind4 = reg_memind4 + @@ -347,7 +341,7 @@ use_indaddr = regAregXcon + use_index = use_index4 + use_index2 + use_index1 + use_indaddr + regX . -#endif m68020 +#endif TBL68020 /* A common part */ posextern = absolute + all_indir . @@ -366,7 +360,7 @@ memalt4 = memory4 * alterable4 . memalt2 = memory2 * alterable2 . memalt1 = memory1 * alterable1 . -#ifndef m68020 +#ifndef TBL68020 /* A m68k4 part */ imm_cmp4 = alterable4 . imm_cmp2 = alterable2 . @@ -376,7 +370,7 @@ test_set4 = datalt4 . test_set2 = datalt2 . test_set1 = datalt1 . -#else m68020 +#else TBL68020 imm_cmp4 = any4 - immediate4 . imm_cmp2 = any2 - const . @@ -386,15 +380,15 @@ test_set4 = data4 - immediate4 . test_set2 = data2 - const . test_set1 = data1 - const . -#endif m68020 +#endif TBL68020 test_set = test_set4 + test_set2 + test_set1 . -#ifndef m68020 +#ifndef TBL68020 t_address = address + t_regAregXcon + t_regAcon . -#else m68020 +#else TBL68020 #define t_address address -#endif m68020 +#endif TBL68020 INSTRUCTIONS @@ -425,12 +419,12 @@ sh "illegal" shconreg:ro, LOCAL:rw:cc cost(0,0). sh "illegal" LOCAL:ro, LOCAL:rw:cc cost(0,0). xxx "illegal" data4:ro, LOCAL:rw:cc cost(0,0). xxx "illegal" LOCAL:ro, alterable4:rw:cc cost(0,0). -#ifdef m68020 +#ifdef TBL68020 divs_l "divs.l" data4:ro, LOCAL:rw:cc cost(0,90). divu_l "divu.l" data4:ro, LOCAL:rw:cc cost(0,78). muls_l "muls.l" data4:ro, LOCAL:rw:cc cost(0,44). mulu_l "mulu.l" data4:ro, LOCAL:rw:cc cost(0,44). -#endif m68020 +#endif TBL68020 add_l "add.l" any4:ro, D_REG:rw:cc cost(2,3). add_l "add.l" any4:ro, A_REG:rw cost(2,3). @@ -517,7 +511,7 @@ bit "illegal" control4:rw:cc cost(2,6). sh "illegal" shconreg:ro, D_REG:rw:cc cost(2,4). shw "illegal" control2:rw:cc cost(2,4). -#ifdef m68020 +#ifdef TBL68020 cmp2_l "cmp2.l" address+control4:ro, genreg:ro kills :cc cost(2,18). divs_l "divs.l" data4:ro, D_REG:rw:cc cost(2,90). divsl_l "divsl.l" data4:ro, DREG_pair:rw kills :cc cost(2,90). @@ -527,9 +521,9 @@ extb_l "extb.l" D_REG:rw:cc cost(2,4). muls_l "muls.l" data4:ro, D_REG:rw:cc cost(2,44). mulu_l "mulu.l" data4:ro, D_REG:rw:cc cost(2,44). pea address+control4+regX cost(2,4). -#else m68020 +#else TBL68020 pea address+control4 cost(2,4). -#endif m68020 +#endif TBL68020 /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * Extra pseudo instruction; it just kills a D_REG; @@ -562,7 +556,7 @@ from const to memalt2 from regAcon %bd==0 to A_REG gen move_l %1.reg, %2 -#ifndef m68020 +#ifndef TBL68020 from t_regAregXcon sfit(%bd, 8) to A_REG gen lea {regAregXcon, %1.reg, %1.xreg, 1, %1.bd}, %2 @@ -576,7 +570,7 @@ from t_regAcon sfit(%bd, 16) to A_REG from t_regAcon to A_REG gen move_l %1.reg, %2 add_l {const, %1.bd}, %2 -#endif m68020 +#endif TBL68020 from address - ext_addr to A_REG gen lea %1, %2 @@ -612,7 +606,7 @@ STACKINGRULES from const %num==0 to STACK gen clr_l {pre_dec4, sp} -#ifndef m68020 +#ifndef TBL68020 from t_regAregXcon sfit(%bd, 8) to STACK gen pea {regAregXcon, %1.reg, %1.xreg, 1, %1.bd} @@ -626,7 +620,7 @@ from t_regAcon sfit(%bd, 16) to STACK from t_regAcon to STACK gen move_l %1.reg, {pre_dec4, sp} add_l {const, %1.bd}, {indirect4, sp} -#endif m68020 +#endif TBL68020 from address - ext_addr to STACK gen pea %1 @@ -648,10 +642,10 @@ from data1 to STACK gen clr_l {pre_dec4, sp} move_b %1, {offsetted1, sp, 3} -#ifdef m68020 +#ifdef TBL68020 from regX to STACK gen pea %1 -#endif m68020 +#endif TBL68020 /* This last stackingrule is never used: whenever regX is put on * the fakestack, some em-instuctions are left that remove it * immediately. However cgg complained about not having a @@ -672,7 +666,7 @@ from STACK gen move_l {post_inc4, sp}, %a yields %a -#ifndef m68020 +#ifndef TBL68020 from t_regAregXcon sfit(%bd, 8) yields {regAregXcon, %1.reg, %1.xreg, 1, %1.bd} @@ -688,7 +682,7 @@ from t_regAcon uses reusing %1, AA_REG=%1.reg gen add_l {const, %1.bd}, %a yields %a -#endif m68020 +#endif TBL68020 from t_address uses reusing %1, AA_REG = %1 @@ -835,7 +829,7 @@ pat lol loc ror stl $1==$4 && small($2) && $3==4 && inreg($1)==reg_any pat lol lol ror stl $1==$4 && inreg($2)==reg_any && $3==4 && inreg($1)==reg_any call lolrshstl("ror.l") -#ifdef m68020 +#ifdef TBL68020 pat lol loc dvi stl $1==$4 && $3==4 && inreg($1)==reg_any kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) gen divs_l {const, $2}, {LOCAL, $1} @@ -861,7 +855,7 @@ pat lol mlu stl $1==$3 && $2==4 && inreg($1)==reg_any with data4 kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) gen mulu_l %1, {LOCAL, $1} -#endif m68020 +#endif TBL68020 pat lil inc sil $1==$3 && inreg($1)==reg_pointer @@ -1126,12 +1120,12 @@ pat ldl leaving lol $1+4 lol $1 pat loe yields {absolute4, $1} pat lil -#ifdef m68020 +#ifdef TBL68020 yields {ILOCAL, $1} -#else m68020 +#else TBL68020 uses AA_REG = {LOCAL, $1} yields {indirect4, %a} -#endif m68020 +#endif TBL68020 /* When using the 'offsetted' intructions regAregXcon cannot be used * for the m68k4; there is no way of knowing about the size of @@ -1145,9 +1139,9 @@ pat lof with A_REG yields {offsetted4, %1, $1} with exact local_addr yields {LOCAL, %1.bd+$1} with exact ext_addr yields {absolute4, %1.bd+$1} -#ifndef m68020 +#ifndef TBL68020 with regAcon yields {offsetted4, %1.reg, %1.bd+$1} -#else m68020 +#else TBL68020 with exact regAcon yields {offsetted4, %1.reg, %1.bd+$1} with exact regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1} with exact offsetted4 yields {OFF_off4, %1.reg, %1.bd, $1} @@ -1165,7 +1159,7 @@ with exact abs_regXcon yields {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od+$1} with exact abs_index4 yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, $1} with exact absind_con yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1} with exact ext_regX yields {abs_index4, %1.sc, %1.xreg, %1.bd+$1} -#endif m68020 +#endif TBL68020 pat lal yields {local_addr, $1} @@ -1176,20 +1170,20 @@ pat lxl $1==0 yields lb pat lxl $1==1 yields {LOCAL, SL} pat lxl $1==2 -#ifdef m68020 +#ifdef TBL68020 yields {OFF_off4, lb, SL, SL} -#else m68020 +#else TBL68020 uses AA_REG = {LOCAL, SL} yields {offsetted4, %a, SL} -#endif m68020 +#endif TBL68020 pat lxl $1==3 -#ifdef m68020 +#ifdef TBL68020 uses AA_REG = {OFF_off4, lb, SL, SL} -#else m68020 +#else TBL68020 uses AA_REG = {LOCAL, SL} gen move {offsetted4, %a, SL}, %a -#endif m68020 +#endif TBL68020 yields {offsetted4, %a, SL} pat lxl $1>3 @@ -1203,20 +1197,20 @@ pat lxl $1>3 pat lxa $1==0 yields {local_addr, SL} pat lxa $1==1 -#ifdef m68020 +#ifdef TBL68020 yields {off_con, lb, SL, SL} -#else m68020 +#else TBL68020 uses AA_REG = {LOCAL, SL} yields {regAcon, %a, SL} -#endif m68020 +#endif TBL68020 pat lxa $1==2 -#ifdef m68020 +#ifdef TBL68020 uses AA_REG = {OFF_off4, lb, SL, SL} -#else m68020 +#else TBL68020 uses AA_REG = {LOCAL, SL} gen move {offsetted4, %a, SL}, %a -#endif m68020 +#endif TBL68020 yields {regAcon, %a, SL} pat lxa $1>2 @@ -1231,10 +1225,10 @@ pat loi $1==1 with A_REG yields {indirect1, %1} with exact local_addr yields {offsetted1, lb, %1.bd} with exact ext_addr yields {absolute1, %1.bd} -#ifndef m68020 +#ifndef TBL68020 with regAcon yields {offsetted1, %1.reg, %1.bd} with regAregXcon yields {index_off1, %1.reg, %1.xreg, %1.sc, %1.bd} -#else m68020 +#else TBL68020 with exact regAcon yields {offsetted1, %1.reg, %1.bd} with exact regAregXcon yields {index_off1, %1.reg, %1.xreg, %1.sc, %1.bd} with exact indirect4 yields {OFF_off1, %1.reg, 0, 0} @@ -1252,16 +1246,16 @@ with exact abs_regXcon yields {ABS_indoff1, %1.sc, %1.xreg, %1.bd, %1.od} with exact abs_index4 yields {ABSIND_off1, %1.sc, %1.xreg, %1.bd, 0} with exact absind_con yields {ABSIND_off1, %1.sc, %1.xreg, %1.bd, %1.od} with exact ext_regX yields {abs_index1, %1.sc, %1.xreg, %1.bd} -#endif m68020 +#endif TBL68020 pat loi $1==2 with A_REG yields {indirect2, %1} with exact local_addr yields {offsetted2, lb, %1.bd} with exact ext_addr yields {absolute2, %1.bd} -#ifndef m68020 +#ifndef TBL68020 with regAcon yields {offsetted2, %1.reg, %1.bd} with regAregXcon yields {index_off2, %1.reg, %1.xreg, %1.sc, %1.bd} -#else m68020 +#else TBL68020 with exact regAcon yields {offsetted2, %1.reg, %1.bd} with exact regAregXcon yields {index_off2, %1.reg, %1.xreg, %1.sc, %1.bd} with exact indirect4 yields {OFF_off2, %1.reg, 0, 0} @@ -1279,16 +1273,16 @@ with exact abs_regXcon yields {ABS_indoff2, %1.sc, %1.xreg, %1.bd, %1.od} with exact abs_index4 yields {ABSIND_off2, %1.sc, %1.xreg, %1.bd, 0} with exact absind_con yields {ABSIND_off2, %1.sc, %1.xreg, %1.bd, %1.od} with exact ext_regX yields {abs_index2, %1.sc, %1.xreg, %1.bd} -#endif m68020 +#endif TBL68020 pat loi $1==4 with A_REG yields {indirect4, %1} with exact local_addr yields {LOCAL, %1.bd} with exact ext_addr yields {absolute4, %1.bd} -#ifndef m68020 +#ifndef TBL68020 with regAcon yields {offsetted4, %1.reg, %1.bd} with regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd} -#else m68020 +#else TBL68020 with exact regAcon yields {offsetted4, %1.reg, %1.bd} with exact regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd} with exact LOCAL yields {ILOCAL, %1.bd} @@ -1306,7 +1300,7 @@ with exact abs_regXcon yields {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od} with exact abs_index4 yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, 0} with exact absind_con yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od} with exact ext_regX yields {abs_index4, %1.sc, %1.xreg, %1.bd} -#endif m68020 +#endif TBL68020 pat loi $1==8 with A_REG yields {offsetted4, %1, 4} @@ -1333,10 +1327,10 @@ with exact local_addr yields {LOCAL, %1.bd+$1+4} {LOCAL, %1.bd+$1} with exact ext_addr yields {absolute4, %1.bd+$1+4} {absolute4, %1.bd+$1} -#ifndef m68020 +#ifndef TBL68020 with regAcon yields {offsetted4, %1.reg, %1.bd+$1+4} {offsetted4, %1.reg, %1.bd+$1} -#else m68020 +#else TBL68020 with exact regAcon yields {offsetted4, %1.reg, %1.bd+$1+4} {offsetted4, %1.reg, %1.bd+$1} with exact regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1+4} @@ -1371,7 +1365,7 @@ with exact absind_con yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1+4} {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1} with exact ext_regX yields {abs_index4, %1.sc, %1.xreg, %1.bd+$1+4} {abs_index4, %1.sc, %1.xreg, %1.bd+$1} -#endif m68020 +#endif TBL68020 pat lpi yields {ext_addr, $1} @@ -1396,13 +1390,13 @@ with exact STACK gen move {post_inc4, sp}, {absolute4, $1} pat sil -#ifdef m68020 +#ifdef TBL68020 with any4 kills allexceptcon gen move %1, {ILOCAL, $1} with exact STACK gen move {post_inc4, sp}, {ILOCAL, $1} -#else m68020 +#else TBL68020 with any4 kills allexceptcon uses AA_REG = {LOCAL, $1} @@ -1410,7 +1404,7 @@ with any4 with exact STACK uses AA_REG = {LOCAL, $1} gen move {post_inc4, sp}, {indirect4, %a} -#endif m68020 +#endif TBL68020 pat stf with A_REG any4 @@ -1424,11 +1418,11 @@ with exact local_addr any4 with exact ext_addr any4 kills allexceptcon gen move %2, {absolute4, %1.bd+$1} -#ifndef m68020 +#ifndef TBL68020 with regAcon any4 kills allexceptcon gen move %2, {offsetted4, %1.reg, %1.bd+$1} -#else m68020 +#else TBL68020 with exact regAcon any4 kills allexceptcon gen move %2, {offsetted4, %1.reg, %1.bd+$1} @@ -1474,7 +1468,7 @@ with exact absind_con any4 with exact ext_regX any4 kills allexceptcon gen move %2, {abs_index4, %1.sc, %1.xreg, %1.bd+$1} -#endif m68020 +#endif TBL68020 pat sti $1==1 with A_REG data1 @@ -1486,14 +1480,14 @@ with exact local_addr data1 with exact ext_addr data1 kills allexceptcon gen move %2, {absolute1, %1.bd} -#ifndef m68020 +#ifndef TBL68020 with regAcon data1 kills allexceptcon gen move %2, {offsetted1, %1.reg, %1.bd} with regAregXcon data1 kills allexceptcon gen move %2, {index_off1, %1.reg, %1.xreg, %1.sc, %1.bd} -#else m68020 +#else TBL68020 with exact regAcon data1 kills allexceptcon gen move %2, {offsetted1, %1.reg, %1.bd} @@ -1539,7 +1533,7 @@ with exact absind_con data1 with exact ext_regX data1 kills allexceptcon gen move %2, {abs_index1, %1.sc, %1.xreg, %1.bd} -#endif m68020 +#endif TBL68020 pat sti $1==2 with A_REG any2 @@ -1551,14 +1545,14 @@ with exact local_addr any2 with exact ext_addr any2 kills allexceptcon gen move %2, {absolute2, %1.bd} -#ifndef m68020 +#ifndef TBL68020 with regAcon any2 kills allexceptcon gen move %2, {offsetted2, %1.reg, %1.bd} with regAregXcon any2 kills allexceptcon gen move %2, {index_off2, %1.reg, %1.xreg, %1.sc, %1.bd} -#else m68020 +#else TBL68020 with exact regAcon any2 kills allexceptcon gen move %2, {offsetted2, %1.reg, %1.bd} @@ -1604,7 +1598,7 @@ with exact absind_con any2 with exact ext_regX any2 kills allexceptcon gen move %2, {abs_index2, %1.sc, %1.xreg, %1.bd} -#endif m68020 +#endif TBL68020 pat sti $1==4 with A_REG any4 @@ -1618,14 +1612,14 @@ with exact local_addr any4 with exact ext_addr any4 kills allexceptcon gen move %2, {absolute4, %1.bd} -#ifndef m68020 +#ifndef TBL68020 with regAcon any4 kills allexceptcon gen move %2, {offsetted4, %1.reg, %1.bd} with regAregXcon any4 kills allexceptcon gen move %2, {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd} -#else m68020 +#else TBL68020 with exact regAcon any4 kills allexceptcon gen move %2, {offsetted4, %1.reg, %1.bd} @@ -1671,7 +1665,7 @@ with exact absind_con any4 with exact ext_regX any4 kills allexceptcon gen move %2, {abs_index4, %1.sc, %1.xreg, %1.bd} -#endif m68020 +#endif TBL68020 pat sti $1>4 with AA_REG STACK @@ -1709,12 +1703,12 @@ with exact ext_addr any4 any4 kills allexceptcon gen move %2, {absolute4, %1.bd+$1} move %3, {absolute4, %1.bd+$1+4} -#ifndef m68020 +#ifndef TBL68020 with regAcon any4 any4 kills allexceptcon gen move %2, {offsetted4, %1.reg, %1.bd+$1} move %3, {offsetted4, %1.reg, %1.bd+$1+4} -#else m68020 +#else TBL68020 with exact regAcon any4 any4 kills allexceptcon gen move %2, {offsetted4, %1.reg, %1.bd+$1} @@ -1775,7 +1769,7 @@ with exact ext_regX any4 any4 kills allexceptcon gen move %2, {abs_index4, %1.sc, %1.xreg, %1.bd+$1} move %3, {abs_index4, %1.sc, %1.xreg, %1.bd+$1+4} -#endif m68020 +#endif TBL68020 @@ -1806,38 +1800,38 @@ with any4 AA_REG gen sub_l %1, %2 yields %2 pat mli $1==4 -#ifdef m68020 +#ifdef TBL68020 with data4 DD_REG gen muls_l %1, %2 yields %2 -#else m68020 +#else TBL68020 with STACK gen jsr {absolute4, ".mli"} yields d1 -#endif m68020 +#endif TBL68020 pat dvi $1==4 -#ifdef m68020 +#ifdef TBL68020 with data4 DD_REG gen divs_l %1, %2 yields %2 -#else m68020 +#else TBL68020 with STACK gen jsr {absolute4, ".dvi"} yields d1 -#endif m68020 +#endif TBL68020 pat rmi $1==4 -#ifdef m68020 +#ifdef TBL68020 with data4 DD_REG uses DD_REG gen divsl_l %1, {DREG_pair, %a, %2} killreg %2 /* !!!! contents of %2 have changed: make this known to cg */ yields %a -#else m68020 +#else TBL68020 with STACK gen jsr {absolute4, ".dvi"} yields d0 -#endif m68020 +#endif TBL68020 pat ngi $1==4 with DD_REG @@ -1863,38 +1857,38 @@ pat adu leaving adi $1 pat sbu leaving sbi $1 pat mlu $1==4 -#ifdef m68020 +#ifdef TBL68020 with data4 DD_REG gen mulu_l %1, %2 yields %2 -#else m68020 +#else TBL68020 with STACK gen jsr {absolute4, ".mlu"} yields d1 -#endif m68020 +#endif TBL68020 pat dvu $1==4 -#ifdef m68020 +#ifdef TBL68020 with data4 DD_REG gen divu_l %1, %2 yields %2 -#else m68020 +#else TBL68020 with STACK gen jsr {absolute4, ".dvu"} yields d1 -#endif m68020 +#endif TBL68020 pat rmu $1==4 -#ifdef m68020 +#ifdef TBL68020 with data4 DD_REG uses DD_REG gen divul_l %1, {DREG_pair, %a, %2} killreg %2 /* !!!! contents of %2 have changed: make this known to cg */ yields %a -#else m68020 +#else TBL68020 with STACK gen jsr {absolute4, ".dvu"} yields d0 -#endif m68020 +#endif TBL68020 pat slu leaving sli $1 @@ -1935,7 +1929,7 @@ with exact regAcon + t_regAcon yields {t_regAcon, %1.reg, %1.bd+$1} with exact regAregXcon + t_regAregXcon yields {t_regAregXcon,%1.reg, %1.xreg, %1.sc, %1.bd+$1} -#ifdef m68020 +#ifdef TBL68020 with exact indirect4 yields {off_con, %1.reg, 0, $1} with exact LOCAL yields {off_con, lb, %1.bd, $1} with exact offsetted4 yields {off_con, %1.reg, %1.bd, $1} @@ -1951,7 +1945,7 @@ with exact abs_regXcon yields {abs_regXcon, %1.sc, %1.xreg, %1.bd, %1.od+$1} with exact abs_index4 yields {absind_con, %1.sc, %1.xreg, %1.bd, $1} with exact absind_con yields {absind_con, %1.sc, %1.xreg, %1.bd, %1.od+$1} with exact ext_regX yields {ext_regX, %1.sc, %1.xreg, %1.bd+$1} -#endif m68020 +#endif TBL68020 pat ads $1==4 with D_REG A_REG yields {regAregXcon, %2, %1, 1, 0} @@ -1961,7 +1955,7 @@ with D_REG local_addr yields {t_regAregXcon, lb, %1, 1, %2.bd} with any4-D_REG AA_REG gen add_l %1, %2 yields %2 -#ifdef m68020 +#ifdef TBL68020 with D_REG yields {regX, 1, %1} leaving ads 4 @@ -2000,7 +1994,7 @@ with exact LOCAL ext_regX yields {off_regXcon, lb, %2.xreg, %2.sc, %1.bd, %2.bd} with exact absolute4 ext_regX yields {abs_regXcon, %2.sc, %2.xreg, %1.bd, %2.bd} -#endif m68020 +#endif TBL68020 /* I WOULD ALSO LIKE THIS: * pat ads @@ -2010,7 +2004,7 @@ with exact absolute4 ext_regX pat sbs $1==4 leaving sbi 4 -#ifdef m68020 +#ifdef TBL68020 pat loc sli ads $1==1 && $2==4 && $3==4 with D_REG yields {regX, 2, %1} leaving ads 4 @@ -2022,7 +2016,7 @@ with D_REG yields {regX, 4, %1} pat loc sli ads $1==3 && $2==4 && $3==4 with D_REG yields {regX, 8, %1} leaving ads 4 -#endif m68020 +#endif TBL68020 /************************************************ @@ -2293,11 +2287,11 @@ pat lae sar $2==4 && nicesize(rom($1,3)) pat lae aar $2==4 && rom($1,3)==1 leaving ads 4 adp 0-rom($1,1) -#ifdef m68020 +#ifdef TBL68020 pat lae aar $2==4 && nicesize(rom($1,3)) with D_REG yields {regX, rom($1,3), %1} leaving ads 4 adp rom($1,3)*(0-rom($1,1)) -#else m68020 +#else TBL68020 pat lae aar $2==4 && rom($1,3)==2 with DD_REG gen asl_l {shconst, 1}, %1 @@ -2315,7 +2309,7 @@ with DD_REG gen asl_l {shconst, 3}, %1 yields %1 leaving ads 4 adp (0 - rom($1,1))<<3 -#endif m68020 +#endif TBL68020 /* I WOULD ALSO LIKE THESE: * pat lae aar $2==4 && defined(rom($1,3)) @@ -2494,14 +2488,14 @@ with A_REG STACK with STACK uses AA_REG = {post_inc4, sp} gen jsr {indirect4, %a} -#ifdef m68020 +#ifdef TBL68020 with exact address kills ALL gen jsr %1 -#else m68020 +#else TBL68020 with address STACK gen jsr %1 -#endif m68020 +#endif TBL68020 pat cal with STACK @@ -2642,12 +2636,12 @@ with STACK uses AA_REG = {ext_addr, $1} gen move_l {offsetted4, %a, 8}, lb move_l {offsetted4, %a, 4}, sp -#ifdef m68020 +#ifdef TBL68020 jmp {OFF_off4, %a, 0, 0} -#else m68020 +#else TBL68020 move_l {indirect4, %a}, %a jmp {indirect4, %a} -#endif m68020 +#endif TBL68020 pat lim yields {absolute4, ".trpim"} @@ -2676,7 +2670,7 @@ with STACK gen jsr {absolute4, ".nop"} pat rck -#ifdef m68020 +#ifdef TBL68020 with ext_addr D_REG gen cmp2_l {absolute4, %1.bd}, %2 bcc {slabel, 1f} @@ -2695,10 +2689,10 @@ with A_REG D_REG pea {absolute4, 1} /* push constant 1 == ERANGE */ jsr {absolute4, ".trp"} 1: yields %2 -#else m68020 +#else TBL68020 with STACK gen jsr {absolute4, ".rck"} -#endif m68020 +#endif TBL68020 pat rtt leaving ret 0 @@ -2715,11 +2709,11 @@ with any4 pat str $1==0 with any4 -#ifdef m68020 +#ifdef TBL68020 kills LOCAL, ILOCAL, all_regind %reg==lb, local_addr -#else m68020 +#else TBL68020 kills LOCAL, all_regind %reg==lb, local_addr -#endif m68020 +#endif TBL68020 gen move %1, lb pat str $1==1 @@ -2752,14 +2746,14 @@ with conreg4 proc lilxxxsil example lil adi sil with conreg4 -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen xxx* %1, {ILOCAL, $1} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen xxx* %1, {indirect4, %a} -#endif m68020 +#endif TBL68020 proc lolcxxxstl example lol loc adi stl kills all_indir, LOCAL %bd==$1 @@ -2770,14 +2764,14 @@ proc loecxxxste example loe loc adi ste gen xxx* {const, $2}, {absolute4, $1} proc lilcxxxsil example lil loc adi sil -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen xxx* {const, $2}, {ILOCAL, $1} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen xxx* {const, $2}, {indirect4, %a} -#endif m68020 +#endif TBL68020 proc lolrxxxstl example lol lol adi stl kills all_indir, LOCAL %bd==$1 @@ -2788,14 +2782,14 @@ proc loerxxxste example loe lol adi ste gen xxx* {LOCAL, $2}, {absolute4, $1} proc lilrxxxsil example lil lol adi sil -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen xxx* {LOCAL, $2}, {ILOCAL, $1} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen xxx* {LOCAL, $2}, {indirect4, %a} -#endif m68020 +#endif TBL68020 pat lol adi stl $1==$3 && $2==4 call lolxxxstl("add.l") pat loe adi ste $1==$3 && $2==4 call loexxxste("add.l") @@ -2830,12 +2824,12 @@ pat lol adp stl $1==$3 pat lil adp sil $1==$3 kills allexceptcon -#ifdef m68020 +#ifdef TBL68020 gen add_l {const, $2}, {ILOCAL, $1} -#else m68020 +#else TBL68020 uses AA_REG = {LOCAL, $1} gen add_l {const, $2}, {indirect4, %a} -#endif m68020 +#endif TBL68020 pat loe adp ste $1==$3 kills posextern @@ -2849,14 +2843,14 @@ pat lol lol adp stl $1==$2 && $1==$4 pat lil lil adp sti $1==$2 && $1==$4 kills allexceptcon -#ifdef m68020 +#ifdef TBL68020 uses AA_REG = {ILOCAL, $1} gen add_l {const, $3}, {ILOCAL, $1} -#else m68020 +#else TBL68020 uses AA_REG, AA_REG = {LOCAL, $1} gen move {indirect4, %b}, %a add_l {const, $3}, {indirect4, %b} -#endif m68020 +#endif TBL68020 yields %a pat loe loe adp ste $1==$2 && $1==$4 @@ -2936,16 +2930,16 @@ proc lloe1shste example loe loc sli ste /* only left */ roxl {absolute2, $1} proc llil1shsil example lil loc sli sil /* only left */ -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen shw* {OFF_off2, lb, $1, 2} roxl {OFF_off2, lb, $1, 0} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen shw* {offsetted2, %a, 2} roxl {indirect2, %a} -#endif m68020 +#endif TBL68020 proc rlol1shstl example lol loc sri stl /* only right */ kills all_indir, LOCAL %bd==$1 @@ -2958,16 +2952,16 @@ proc rloe1shste example loe loc sri ste /* only right */ roxr {absolute2, $1+2} proc rlil1shsil example lil loc sri sil /* only right */ -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen shw* {OFF_off2, lb, $1, 0} roxr {OFF_off2, lb, $1, 2} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen shw* {indirect2, %a} roxr {offsetted2, %a, 2} -#endif m68020 +#endif TBL68020 pat lol loc sli stl $1==$4 && $2==1 && $3==4 call llol1shstl("asl #1,") pat loe loc sli ste $1==$4 && $2==1 && $3==4 call lloe1shste("asl #1,") @@ -3003,14 +2997,14 @@ proc loebitste example loe ngi ste gen bit* {absolute4, $1} proc lilbitsil example lil ngi sil -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen bit* {ILOCAL, $1} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen bit* {indirect4, %a} -#endif m68020 +#endif TBL68020 pat lol ngi stl $1==$3 && $2==4 call lolbitstl("neg.l") pat loe ngi ste $1==$3 && $2==4 call loebitste("neg.l") @@ -3020,24 +3014,24 @@ pat loe com ste $1==$3 && $2==4 call loebitste("not.l") pat lil com sil $1==$3 && $2==4 call lilbitsil("not.l") pat lil inc sil $1==$3 -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen add_l {const, 1}, {ILOCAL, $1} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen add_l {const, 1}, {indirect4, %a} -#endif m68020 +#endif TBL68020 pat lil dec sil $1==$3 -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen sub_l {const, 1}, {ILOCAL, $1} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen sub_l {const, 1}, {indirect4, %a} -#endif m68020 +#endif TBL68020 proc txxand @@ -3256,12 +3250,12 @@ with DD_REG pat loc loc cii $1==1 && $2==4 with DD_REG -#ifdef m68020 +#ifdef TBL68020 gen extb_l %1 yields %1 -#else m68020 +#else TBL68020 gen ext_w %1 ext_l %1 yields %1 -#endif m68020 +#endif TBL68020 pat loc loc ciu $1==$2 /* skip this */ pat loc loc cui $1==$2 /* skip this */ diff --git a/mach/moon3/ncg/mach.c b/mach/moon3/ncg/mach.c index 3d3073a5..1cd93771 100644 --- a/mach/moon3/ncg/mach.c +++ b/mach/moon3/ncg/mach.c @@ -19,13 +19,7 @@ * machine dependent back end routines for the Motorola 68000, 68010 or 68020 */ -#ifndef m68k4 -#define m68020 -#endif - /* use m68020 when you want a m68020 cg, don't if you want a - * m68k4 cg. The m68k4 cg can be used for both the MC68000 - * and the MC68010. - */ +#include "whichone.h" con_part(sz,w) register sz; word w; { @@ -138,7 +132,7 @@ save() /* initialise register-parameters */ for (p = regsav; p < ®sav[regnr]; p++) { if (p->rs_off >= 0) { -#ifdef m68020 +#ifdef TBL68020 fprintf(codefile,"move.%c (%ld,a6),%s\n", #else fprintf(codefile,"move.%c %ld(a6),%s\n", @@ -196,7 +190,7 @@ regreturn() prolog(nlocals) full nlocals; { -#ifdef m68020 +#ifdef TBL68020 fprintf(codefile,"tst.b (-%ld,sp)\nlink\ta6,#-%ld\n",nlocals+40,nlocals); #else fprintf(codefile,"tst.b -%ld(sp)\nlink\ta6,#-%ld\n",nlocals+40,nlocals); diff --git a/mach/moon3/ncg/mach.h b/mach/moon3/ncg/mach.h index ff2cf66c..48763723 100644 --- a/mach/moon3/ncg/mach.h +++ b/mach/moon3/ncg/mach.h @@ -1,9 +1,12 @@ -#ifndef m68k4 -#define m68020 +#include "whichone.h" + +#ifndef TBL68020 +#ifndef TBL68000 +Something is very wrong here. You must specify the machine: either +TBL68000 or TBL68020, in the file whichone.h, then REMOVE tables.c +and then run "make" again +#endif #endif - /* m68020 should be used for a m68020 cg, and it should - * not be used for a m68k4 cg - */ #define ex_ap(y) fprintf(codefile,".extern %s\n",y) #define in_ap(y) /* nothing */ @@ -20,7 +23,7 @@ #define dlb_fmt "_%d" #define hol_fmt "hol%d" -#ifdef m68020 +#ifdef TBL68020 #define loc_off "(%d,a6)" #define arg_off "(8+%d,a6)" #else @@ -35,5 +38,6 @@ #define modhead ".sect .text\n.sect .rom\n.sect .data\n.sect .bss\n" -#define id_first '_' +#define fmt_id(sf,st) sprintf(st,"_%s",sf) + #define BSS_INIT 0 diff --git a/mach/moon3/ncg/table b/mach/moon3/ncg/table index 6518487a..d6166d16 100644 --- a/mach/moon3/ncg/table +++ b/mach/moon3/ncg/table @@ -6,13 +6,7 @@ ********************************/ -#ifndef m68k4 -#define m68020 -#endif - /* m68020 to be defined if this is the 68020 table. - * The 68000 and 68010 tables are identical. - */ - +#include "whichone.h" #define small(x) ((x)>=1 && (x)<=8) #define nicesize(x) ((x)==1||(x)==2||(x)==4||(x)==8) @@ -107,7 +101,7 @@ llabel = {ADDR bd;} 4 cost(2,0) bd . slabel = {ADDR bd;} 4 cost(0,0) bd . shconst = {INT num;} 4 cost(0,0) "#" num . -#ifndef m68020 +#ifndef TBL68020 /* Part (ii) */ absolute4 = {ADDR bd;} 4 cost(4,8) bd . offsetted4 = {A_REG reg; INT bd;} 4 cost(2,6) bd "(" reg ")" . @@ -133,7 +127,7 @@ regAregXcon = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,8) t_regAregXcon = {A_REG reg; D_REG xreg; INT sc; INT bd;} 4 cost(2,8) . t_regAcon = {A_REG reg; INT bd;} 4 cost(2,6) . -#else m68020 +#else TBL68020 /* Part (iii) */ absolute4 = {ADDR bd;} 4 cost(4,7) "(" bd ")" . offsetted4 = {A_REG reg; INT bd;} 4 cost(2,6) "(" bd "," reg ")" . @@ -216,7 +210,7 @@ DREG_pair = {D_REG reg1; D_REG reg2;} 8 cost(2,0) reg1 ":" reg2 . #define t_regAregXcon regAregXcon #define t_regAcon regAcon -#endif m68020 +#endif TBL68020 SETS @@ -224,7 +218,7 @@ SETS * because cgg is one pass. */ -#ifndef m68020 +#ifndef TBL68020 /* A m68k4 part */ data4 = D_REG + LOCAL + const + post_inc4 + pre_dec4 + indirect4 + offsetted4 + index_off4 + absolute4 + @@ -249,7 +243,7 @@ control1 = indirect1 + offsetted1 + index_off1 + absolute1 . alterable1 = data1 - const . any1 = data1 . -#else m68020 +#else TBL68020 data4 = D_REG + indirect4 + post_inc4 + pre_dec4 + index_off4 + offsetted4 + OFF_off4 + OFF_indoff4 + @@ -282,7 +276,7 @@ control1 = memory1 - (post_inc1 + pre_dec1 + const) . alterable1 = data1 - const . any1 = data1 . /* all four above together */ -#endif m68020 +#endif TBL68020 /* This is a common part */ any = any4 + any2 + any1 . absolute = absolute4 + absolute2 + absolute1 . @@ -293,7 +287,7 @@ pre_post = pre_dec4 + pre_dec2 + pre_dec1 + offsetted = offsetted4 + offsetted2 + offsetted1 . index_off = index_off4 + index_off2 + index_off1 . -#ifndef m68020 +#ifndef TBL68020 /* A m68k4 part */ regind_addr = regAcon + regAregXcon + t_regAcon + t_regAregXcon . address = ext_addr + local_addr + regAcon + regAregXcon . @@ -305,7 +299,7 @@ allexceptcon = ALL - ( D_REG + A_REG + const + t_regAcon + t_regAregXcon ) . use_index = index_off4 + index_off2 + index_off1 . -#else m68020 +#else TBL68020 reg_memind4 = OFF_off4 + OFF_indoff4 + INDOFF_off4 . memind4 = reg_memind4 + @@ -347,7 +341,7 @@ use_indaddr = regAregXcon + use_index = use_index4 + use_index2 + use_index1 + use_indaddr + regX . -#endif m68020 +#endif TBL68020 /* A common part */ posextern = absolute + all_indir . @@ -366,7 +360,7 @@ memalt4 = memory4 * alterable4 . memalt2 = memory2 * alterable2 . memalt1 = memory1 * alterable1 . -#ifndef m68020 +#ifndef TBL68020 /* A m68k4 part */ imm_cmp4 = alterable4 . imm_cmp2 = alterable2 . @@ -376,7 +370,7 @@ test_set4 = datalt4 . test_set2 = datalt2 . test_set1 = datalt1 . -#else m68020 +#else TBL68020 imm_cmp4 = any4 - immediate4 . imm_cmp2 = any2 - const . @@ -386,15 +380,15 @@ test_set4 = data4 - immediate4 . test_set2 = data2 - const . test_set1 = data1 - const . -#endif m68020 +#endif TBL68020 test_set = test_set4 + test_set2 + test_set1 . -#ifndef m68020 +#ifndef TBL68020 t_address = address + t_regAregXcon + t_regAcon . -#else m68020 +#else TBL68020 #define t_address address -#endif m68020 +#endif TBL68020 INSTRUCTIONS @@ -425,12 +419,12 @@ sh "illegal" shconreg:ro, LOCAL:rw:cc cost(0,0). sh "illegal" LOCAL:ro, LOCAL:rw:cc cost(0,0). xxx "illegal" data4:ro, LOCAL:rw:cc cost(0,0). xxx "illegal" LOCAL:ro, alterable4:rw:cc cost(0,0). -#ifdef m68020 +#ifdef TBL68020 divs_l "divs.l" data4:ro, LOCAL:rw:cc cost(0,90). divu_l "divu.l" data4:ro, LOCAL:rw:cc cost(0,78). muls_l "muls.l" data4:ro, LOCAL:rw:cc cost(0,44). mulu_l "mulu.l" data4:ro, LOCAL:rw:cc cost(0,44). -#endif m68020 +#endif TBL68020 add_l "add.l" any4:ro, D_REG:rw:cc cost(2,3). add_l "add.l" any4:ro, A_REG:rw cost(2,3). @@ -517,7 +511,7 @@ bit "illegal" control4:rw:cc cost(2,6). sh "illegal" shconreg:ro, D_REG:rw:cc cost(2,4). shw "illegal" control2:rw:cc cost(2,4). -#ifdef m68020 +#ifdef TBL68020 cmp2_l "cmp2.l" address+control4:ro, genreg:ro kills :cc cost(2,18). divs_l "divs.l" data4:ro, D_REG:rw:cc cost(2,90). divsl_l "divsl.l" data4:ro, DREG_pair:rw kills :cc cost(2,90). @@ -527,9 +521,9 @@ extb_l "extb.l" D_REG:rw:cc cost(2,4). muls_l "muls.l" data4:ro, D_REG:rw:cc cost(2,44). mulu_l "mulu.l" data4:ro, D_REG:rw:cc cost(2,44). pea address+control4+regX cost(2,4). -#else m68020 +#else TBL68020 pea address+control4 cost(2,4). -#endif m68020 +#endif TBL68020 /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * Extra pseudo instruction; it just kills a D_REG; @@ -562,7 +556,7 @@ from const to memalt2 from regAcon %bd==0 to A_REG gen move_l %1.reg, %2 -#ifndef m68020 +#ifndef TBL68020 from t_regAregXcon sfit(%bd, 8) to A_REG gen lea {regAregXcon, %1.reg, %1.xreg, 1, %1.bd}, %2 @@ -576,7 +570,7 @@ from t_regAcon sfit(%bd, 16) to A_REG from t_regAcon to A_REG gen move_l %1.reg, %2 add_l {const, %1.bd}, %2 -#endif m68020 +#endif TBL68020 from address - ext_addr to A_REG gen lea %1, %2 @@ -612,7 +606,7 @@ STACKINGRULES from const %num==0 to STACK gen clr_l {pre_dec4, sp} -#ifndef m68020 +#ifndef TBL68020 from t_regAregXcon sfit(%bd, 8) to STACK gen pea {regAregXcon, %1.reg, %1.xreg, 1, %1.bd} @@ -626,7 +620,7 @@ from t_regAcon sfit(%bd, 16) to STACK from t_regAcon to STACK gen move_l %1.reg, {pre_dec4, sp} add_l {const, %1.bd}, {indirect4, sp} -#endif m68020 +#endif TBL68020 from address - ext_addr to STACK gen pea %1 @@ -648,10 +642,10 @@ from data1 to STACK gen clr_l {pre_dec4, sp} move_b %1, {offsetted1, sp, 3} -#ifdef m68020 +#ifdef TBL68020 from regX to STACK gen pea %1 -#endif m68020 +#endif TBL68020 /* This last stackingrule is never used: whenever regX is put on * the fakestack, some em-instuctions are left that remove it * immediately. However cgg complained about not having a @@ -672,7 +666,7 @@ from STACK gen move_l {post_inc4, sp}, %a yields %a -#ifndef m68020 +#ifndef TBL68020 from t_regAregXcon sfit(%bd, 8) yields {regAregXcon, %1.reg, %1.xreg, 1, %1.bd} @@ -688,7 +682,7 @@ from t_regAcon uses reusing %1, AA_REG=%1.reg gen add_l {const, %1.bd}, %a yields %a -#endif m68020 +#endif TBL68020 from t_address uses reusing %1, AA_REG = %1 @@ -835,7 +829,7 @@ pat lol loc ror stl $1==$4 && small($2) && $3==4 && inreg($1)==reg_any pat lol lol ror stl $1==$4 && inreg($2)==reg_any && $3==4 && inreg($1)==reg_any call lolrshstl("ror.l") -#ifdef m68020 +#ifdef TBL68020 pat lol loc dvi stl $1==$4 && $3==4 && inreg($1)==reg_any kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) gen divs_l {const, $2}, {LOCAL, $1} @@ -861,7 +855,7 @@ pat lol mlu stl $1==$3 && $2==4 && inreg($1)==reg_any with data4 kills LOCAL %bd==$1, use_index %xreg==regvar($1, reg_any) gen mulu_l %1, {LOCAL, $1} -#endif m68020 +#endif TBL68020 pat lil inc sil $1==$3 && inreg($1)==reg_pointer @@ -1126,12 +1120,12 @@ pat ldl leaving lol $1+4 lol $1 pat loe yields {absolute4, $1} pat lil -#ifdef m68020 +#ifdef TBL68020 yields {ILOCAL, $1} -#else m68020 +#else TBL68020 uses AA_REG = {LOCAL, $1} yields {indirect4, %a} -#endif m68020 +#endif TBL68020 /* When using the 'offsetted' intructions regAregXcon cannot be used * for the m68k4; there is no way of knowing about the size of @@ -1145,9 +1139,9 @@ pat lof with A_REG yields {offsetted4, %1, $1} with exact local_addr yields {LOCAL, %1.bd+$1} with exact ext_addr yields {absolute4, %1.bd+$1} -#ifndef m68020 +#ifndef TBL68020 with regAcon yields {offsetted4, %1.reg, %1.bd+$1} -#else m68020 +#else TBL68020 with exact regAcon yields {offsetted4, %1.reg, %1.bd+$1} with exact regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1} with exact offsetted4 yields {OFF_off4, %1.reg, %1.bd, $1} @@ -1165,7 +1159,7 @@ with exact abs_regXcon yields {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od+$1} with exact abs_index4 yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, $1} with exact absind_con yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1} with exact ext_regX yields {abs_index4, %1.sc, %1.xreg, %1.bd+$1} -#endif m68020 +#endif TBL68020 pat lal yields {local_addr, $1} @@ -1176,20 +1170,20 @@ pat lxl $1==0 yields lb pat lxl $1==1 yields {LOCAL, SL} pat lxl $1==2 -#ifdef m68020 +#ifdef TBL68020 yields {OFF_off4, lb, SL, SL} -#else m68020 +#else TBL68020 uses AA_REG = {LOCAL, SL} yields {offsetted4, %a, SL} -#endif m68020 +#endif TBL68020 pat lxl $1==3 -#ifdef m68020 +#ifdef TBL68020 uses AA_REG = {OFF_off4, lb, SL, SL} -#else m68020 +#else TBL68020 uses AA_REG = {LOCAL, SL} gen move {offsetted4, %a, SL}, %a -#endif m68020 +#endif TBL68020 yields {offsetted4, %a, SL} pat lxl $1>3 @@ -1203,20 +1197,20 @@ pat lxl $1>3 pat lxa $1==0 yields {local_addr, SL} pat lxa $1==1 -#ifdef m68020 +#ifdef TBL68020 yields {off_con, lb, SL, SL} -#else m68020 +#else TBL68020 uses AA_REG = {LOCAL, SL} yields {regAcon, %a, SL} -#endif m68020 +#endif TBL68020 pat lxa $1==2 -#ifdef m68020 +#ifdef TBL68020 uses AA_REG = {OFF_off4, lb, SL, SL} -#else m68020 +#else TBL68020 uses AA_REG = {LOCAL, SL} gen move {offsetted4, %a, SL}, %a -#endif m68020 +#endif TBL68020 yields {regAcon, %a, SL} pat lxa $1>2 @@ -1231,10 +1225,10 @@ pat loi $1==1 with A_REG yields {indirect1, %1} with exact local_addr yields {offsetted1, lb, %1.bd} with exact ext_addr yields {absolute1, %1.bd} -#ifndef m68020 +#ifndef TBL68020 with regAcon yields {offsetted1, %1.reg, %1.bd} with regAregXcon yields {index_off1, %1.reg, %1.xreg, %1.sc, %1.bd} -#else m68020 +#else TBL68020 with exact regAcon yields {offsetted1, %1.reg, %1.bd} with exact regAregXcon yields {index_off1, %1.reg, %1.xreg, %1.sc, %1.bd} with exact indirect4 yields {OFF_off1, %1.reg, 0, 0} @@ -1252,16 +1246,16 @@ with exact abs_regXcon yields {ABS_indoff1, %1.sc, %1.xreg, %1.bd, %1.od} with exact abs_index4 yields {ABSIND_off1, %1.sc, %1.xreg, %1.bd, 0} with exact absind_con yields {ABSIND_off1, %1.sc, %1.xreg, %1.bd, %1.od} with exact ext_regX yields {abs_index1, %1.sc, %1.xreg, %1.bd} -#endif m68020 +#endif TBL68020 pat loi $1==2 with A_REG yields {indirect2, %1} with exact local_addr yields {offsetted2, lb, %1.bd} with exact ext_addr yields {absolute2, %1.bd} -#ifndef m68020 +#ifndef TBL68020 with regAcon yields {offsetted2, %1.reg, %1.bd} with regAregXcon yields {index_off2, %1.reg, %1.xreg, %1.sc, %1.bd} -#else m68020 +#else TBL68020 with exact regAcon yields {offsetted2, %1.reg, %1.bd} with exact regAregXcon yields {index_off2, %1.reg, %1.xreg, %1.sc, %1.bd} with exact indirect4 yields {OFF_off2, %1.reg, 0, 0} @@ -1279,16 +1273,16 @@ with exact abs_regXcon yields {ABS_indoff2, %1.sc, %1.xreg, %1.bd, %1.od} with exact abs_index4 yields {ABSIND_off2, %1.sc, %1.xreg, %1.bd, 0} with exact absind_con yields {ABSIND_off2, %1.sc, %1.xreg, %1.bd, %1.od} with exact ext_regX yields {abs_index2, %1.sc, %1.xreg, %1.bd} -#endif m68020 +#endif TBL68020 pat loi $1==4 with A_REG yields {indirect4, %1} with exact local_addr yields {LOCAL, %1.bd} with exact ext_addr yields {absolute4, %1.bd} -#ifndef m68020 +#ifndef TBL68020 with regAcon yields {offsetted4, %1.reg, %1.bd} with regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd} -#else m68020 +#else TBL68020 with exact regAcon yields {offsetted4, %1.reg, %1.bd} with exact regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd} with exact LOCAL yields {ILOCAL, %1.bd} @@ -1306,7 +1300,7 @@ with exact abs_regXcon yields {ABS_indoff4, %1.sc, %1.xreg, %1.bd, %1.od} with exact abs_index4 yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, 0} with exact absind_con yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od} with exact ext_regX yields {abs_index4, %1.sc, %1.xreg, %1.bd} -#endif m68020 +#endif TBL68020 pat loi $1==8 with A_REG yields {offsetted4, %1, 4} @@ -1333,10 +1327,10 @@ with exact local_addr yields {LOCAL, %1.bd+$1+4} {LOCAL, %1.bd+$1} with exact ext_addr yields {absolute4, %1.bd+$1+4} {absolute4, %1.bd+$1} -#ifndef m68020 +#ifndef TBL68020 with regAcon yields {offsetted4, %1.reg, %1.bd+$1+4} {offsetted4, %1.reg, %1.bd+$1} -#else m68020 +#else TBL68020 with exact regAcon yields {offsetted4, %1.reg, %1.bd+$1+4} {offsetted4, %1.reg, %1.bd+$1} with exact regAregXcon yields {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd+$1+4} @@ -1371,7 +1365,7 @@ with exact absind_con yields {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1+4} {ABSIND_off4, %1.sc, %1.xreg, %1.bd, %1.od+$1} with exact ext_regX yields {abs_index4, %1.sc, %1.xreg, %1.bd+$1+4} {abs_index4, %1.sc, %1.xreg, %1.bd+$1} -#endif m68020 +#endif TBL68020 pat lpi yields {ext_addr, $1} @@ -1396,13 +1390,13 @@ with exact STACK gen move {post_inc4, sp}, {absolute4, $1} pat sil -#ifdef m68020 +#ifdef TBL68020 with any4 kills allexceptcon gen move %1, {ILOCAL, $1} with exact STACK gen move {post_inc4, sp}, {ILOCAL, $1} -#else m68020 +#else TBL68020 with any4 kills allexceptcon uses AA_REG = {LOCAL, $1} @@ -1410,7 +1404,7 @@ with any4 with exact STACK uses AA_REG = {LOCAL, $1} gen move {post_inc4, sp}, {indirect4, %a} -#endif m68020 +#endif TBL68020 pat stf with A_REG any4 @@ -1424,11 +1418,11 @@ with exact local_addr any4 with exact ext_addr any4 kills allexceptcon gen move %2, {absolute4, %1.bd+$1} -#ifndef m68020 +#ifndef TBL68020 with regAcon any4 kills allexceptcon gen move %2, {offsetted4, %1.reg, %1.bd+$1} -#else m68020 +#else TBL68020 with exact regAcon any4 kills allexceptcon gen move %2, {offsetted4, %1.reg, %1.bd+$1} @@ -1474,7 +1468,7 @@ with exact absind_con any4 with exact ext_regX any4 kills allexceptcon gen move %2, {abs_index4, %1.sc, %1.xreg, %1.bd+$1} -#endif m68020 +#endif TBL68020 pat sti $1==1 with A_REG data1 @@ -1486,14 +1480,14 @@ with exact local_addr data1 with exact ext_addr data1 kills allexceptcon gen move %2, {absolute1, %1.bd} -#ifndef m68020 +#ifndef TBL68020 with regAcon data1 kills allexceptcon gen move %2, {offsetted1, %1.reg, %1.bd} with regAregXcon data1 kills allexceptcon gen move %2, {index_off1, %1.reg, %1.xreg, %1.sc, %1.bd} -#else m68020 +#else TBL68020 with exact regAcon data1 kills allexceptcon gen move %2, {offsetted1, %1.reg, %1.bd} @@ -1539,7 +1533,7 @@ with exact absind_con data1 with exact ext_regX data1 kills allexceptcon gen move %2, {abs_index1, %1.sc, %1.xreg, %1.bd} -#endif m68020 +#endif TBL68020 pat sti $1==2 with A_REG any2 @@ -1551,14 +1545,14 @@ with exact local_addr any2 with exact ext_addr any2 kills allexceptcon gen move %2, {absolute2, %1.bd} -#ifndef m68020 +#ifndef TBL68020 with regAcon any2 kills allexceptcon gen move %2, {offsetted2, %1.reg, %1.bd} with regAregXcon any2 kills allexceptcon gen move %2, {index_off2, %1.reg, %1.xreg, %1.sc, %1.bd} -#else m68020 +#else TBL68020 with exact regAcon any2 kills allexceptcon gen move %2, {offsetted2, %1.reg, %1.bd} @@ -1604,7 +1598,7 @@ with exact absind_con any2 with exact ext_regX any2 kills allexceptcon gen move %2, {abs_index2, %1.sc, %1.xreg, %1.bd} -#endif m68020 +#endif TBL68020 pat sti $1==4 with A_REG any4 @@ -1618,14 +1612,14 @@ with exact local_addr any4 with exact ext_addr any4 kills allexceptcon gen move %2, {absolute4, %1.bd} -#ifndef m68020 +#ifndef TBL68020 with regAcon any4 kills allexceptcon gen move %2, {offsetted4, %1.reg, %1.bd} with regAregXcon any4 kills allexceptcon gen move %2, {index_off4, %1.reg, %1.xreg, %1.sc, %1.bd} -#else m68020 +#else TBL68020 with exact regAcon any4 kills allexceptcon gen move %2, {offsetted4, %1.reg, %1.bd} @@ -1671,7 +1665,7 @@ with exact absind_con any4 with exact ext_regX any4 kills allexceptcon gen move %2, {abs_index4, %1.sc, %1.xreg, %1.bd} -#endif m68020 +#endif TBL68020 pat sti $1>4 with AA_REG STACK @@ -1709,12 +1703,12 @@ with exact ext_addr any4 any4 kills allexceptcon gen move %2, {absolute4, %1.bd+$1} move %3, {absolute4, %1.bd+$1+4} -#ifndef m68020 +#ifndef TBL68020 with regAcon any4 any4 kills allexceptcon gen move %2, {offsetted4, %1.reg, %1.bd+$1} move %3, {offsetted4, %1.reg, %1.bd+$1+4} -#else m68020 +#else TBL68020 with exact regAcon any4 any4 kills allexceptcon gen move %2, {offsetted4, %1.reg, %1.bd+$1} @@ -1775,7 +1769,7 @@ with exact ext_regX any4 any4 kills allexceptcon gen move %2, {abs_index4, %1.sc, %1.xreg, %1.bd+$1} move %3, {abs_index4, %1.sc, %1.xreg, %1.bd+$1+4} -#endif m68020 +#endif TBL68020 @@ -1806,38 +1800,38 @@ with any4 AA_REG gen sub_l %1, %2 yields %2 pat mli $1==4 -#ifdef m68020 +#ifdef TBL68020 with data4 DD_REG gen muls_l %1, %2 yields %2 -#else m68020 +#else TBL68020 with STACK gen jsr {absolute4, ".mli"} yields d1 -#endif m68020 +#endif TBL68020 pat dvi $1==4 -#ifdef m68020 +#ifdef TBL68020 with data4 DD_REG gen divs_l %1, %2 yields %2 -#else m68020 +#else TBL68020 with STACK gen jsr {absolute4, ".dvi"} yields d1 -#endif m68020 +#endif TBL68020 pat rmi $1==4 -#ifdef m68020 +#ifdef TBL68020 with data4 DD_REG uses DD_REG gen divsl_l %1, {DREG_pair, %a, %2} killreg %2 /* !!!! contents of %2 have changed: make this known to cg */ yields %a -#else m68020 +#else TBL68020 with STACK gen jsr {absolute4, ".dvi"} yields d0 -#endif m68020 +#endif TBL68020 pat ngi $1==4 with DD_REG @@ -1863,38 +1857,38 @@ pat adu leaving adi $1 pat sbu leaving sbi $1 pat mlu $1==4 -#ifdef m68020 +#ifdef TBL68020 with data4 DD_REG gen mulu_l %1, %2 yields %2 -#else m68020 +#else TBL68020 with STACK gen jsr {absolute4, ".mlu"} yields d1 -#endif m68020 +#endif TBL68020 pat dvu $1==4 -#ifdef m68020 +#ifdef TBL68020 with data4 DD_REG gen divu_l %1, %2 yields %2 -#else m68020 +#else TBL68020 with STACK gen jsr {absolute4, ".dvu"} yields d1 -#endif m68020 +#endif TBL68020 pat rmu $1==4 -#ifdef m68020 +#ifdef TBL68020 with data4 DD_REG uses DD_REG gen divul_l %1, {DREG_pair, %a, %2} killreg %2 /* !!!! contents of %2 have changed: make this known to cg */ yields %a -#else m68020 +#else TBL68020 with STACK gen jsr {absolute4, ".dvu"} yields d0 -#endif m68020 +#endif TBL68020 pat slu leaving sli $1 @@ -1935,7 +1929,7 @@ with exact regAcon + t_regAcon yields {t_regAcon, %1.reg, %1.bd+$1} with exact regAregXcon + t_regAregXcon yields {t_regAregXcon,%1.reg, %1.xreg, %1.sc, %1.bd+$1} -#ifdef m68020 +#ifdef TBL68020 with exact indirect4 yields {off_con, %1.reg, 0, $1} with exact LOCAL yields {off_con, lb, %1.bd, $1} with exact offsetted4 yields {off_con, %1.reg, %1.bd, $1} @@ -1951,7 +1945,7 @@ with exact abs_regXcon yields {abs_regXcon, %1.sc, %1.xreg, %1.bd, %1.od+$1} with exact abs_index4 yields {absind_con, %1.sc, %1.xreg, %1.bd, $1} with exact absind_con yields {absind_con, %1.sc, %1.xreg, %1.bd, %1.od+$1} with exact ext_regX yields {ext_regX, %1.sc, %1.xreg, %1.bd+$1} -#endif m68020 +#endif TBL68020 pat ads $1==4 with D_REG A_REG yields {regAregXcon, %2, %1, 1, 0} @@ -1961,7 +1955,7 @@ with D_REG local_addr yields {t_regAregXcon, lb, %1, 1, %2.bd} with any4-D_REG AA_REG gen add_l %1, %2 yields %2 -#ifdef m68020 +#ifdef TBL68020 with D_REG yields {regX, 1, %1} leaving ads 4 @@ -2000,7 +1994,7 @@ with exact LOCAL ext_regX yields {off_regXcon, lb, %2.xreg, %2.sc, %1.bd, %2.bd} with exact absolute4 ext_regX yields {abs_regXcon, %2.sc, %2.xreg, %1.bd, %2.bd} -#endif m68020 +#endif TBL68020 /* I WOULD ALSO LIKE THIS: * pat ads @@ -2010,7 +2004,7 @@ with exact absolute4 ext_regX pat sbs $1==4 leaving sbi 4 -#ifdef m68020 +#ifdef TBL68020 pat loc sli ads $1==1 && $2==4 && $3==4 with D_REG yields {regX, 2, %1} leaving ads 4 @@ -2022,7 +2016,7 @@ with D_REG yields {regX, 4, %1} pat loc sli ads $1==3 && $2==4 && $3==4 with D_REG yields {regX, 8, %1} leaving ads 4 -#endif m68020 +#endif TBL68020 /************************************************ @@ -2293,11 +2287,11 @@ pat lae sar $2==4 && nicesize(rom($1,3)) pat lae aar $2==4 && rom($1,3)==1 leaving ads 4 adp 0-rom($1,1) -#ifdef m68020 +#ifdef TBL68020 pat lae aar $2==4 && nicesize(rom($1,3)) with D_REG yields {regX, rom($1,3), %1} leaving ads 4 adp rom($1,3)*(0-rom($1,1)) -#else m68020 +#else TBL68020 pat lae aar $2==4 && rom($1,3)==2 with DD_REG gen asl_l {shconst, 1}, %1 @@ -2315,7 +2309,7 @@ with DD_REG gen asl_l {shconst, 3}, %1 yields %1 leaving ads 4 adp (0 - rom($1,1))<<3 -#endif m68020 +#endif TBL68020 /* I WOULD ALSO LIKE THESE: * pat lae aar $2==4 && defined(rom($1,3)) @@ -2494,14 +2488,14 @@ with A_REG STACK with STACK uses AA_REG = {post_inc4, sp} gen jsr {indirect4, %a} -#ifdef m68020 +#ifdef TBL68020 with exact address kills ALL gen jsr %1 -#else m68020 +#else TBL68020 with address STACK gen jsr %1 -#endif m68020 +#endif TBL68020 pat cal with STACK @@ -2642,12 +2636,12 @@ with STACK uses AA_REG = {ext_addr, $1} gen move_l {offsetted4, %a, 8}, lb move_l {offsetted4, %a, 4}, sp -#ifdef m68020 +#ifdef TBL68020 jmp {OFF_off4, %a, 0, 0} -#else m68020 +#else TBL68020 move_l {indirect4, %a}, %a jmp {indirect4, %a} -#endif m68020 +#endif TBL68020 pat lim yields {absolute4, ".trpim"} @@ -2676,7 +2670,7 @@ with STACK gen jsr {absolute4, ".nop"} pat rck -#ifdef m68020 +#ifdef TBL68020 with ext_addr D_REG gen cmp2_l {absolute4, %1.bd}, %2 bcc {slabel, 1f} @@ -2695,10 +2689,10 @@ with A_REG D_REG pea {absolute4, 1} /* push constant 1 == ERANGE */ jsr {absolute4, ".trp"} 1: yields %2 -#else m68020 +#else TBL68020 with STACK gen jsr {absolute4, ".rck"} -#endif m68020 +#endif TBL68020 pat rtt leaving ret 0 @@ -2715,11 +2709,11 @@ with any4 pat str $1==0 with any4 -#ifdef m68020 +#ifdef TBL68020 kills LOCAL, ILOCAL, all_regind %reg==lb, local_addr -#else m68020 +#else TBL68020 kills LOCAL, all_regind %reg==lb, local_addr -#endif m68020 +#endif TBL68020 gen move %1, lb pat str $1==1 @@ -2752,14 +2746,14 @@ with conreg4 proc lilxxxsil example lil adi sil with conreg4 -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen xxx* %1, {ILOCAL, $1} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen xxx* %1, {indirect4, %a} -#endif m68020 +#endif TBL68020 proc lolcxxxstl example lol loc adi stl kills all_indir, LOCAL %bd==$1 @@ -2770,14 +2764,14 @@ proc loecxxxste example loe loc adi ste gen xxx* {const, $2}, {absolute4, $1} proc lilcxxxsil example lil loc adi sil -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen xxx* {const, $2}, {ILOCAL, $1} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen xxx* {const, $2}, {indirect4, %a} -#endif m68020 +#endif TBL68020 proc lolrxxxstl example lol lol adi stl kills all_indir, LOCAL %bd==$1 @@ -2788,14 +2782,14 @@ proc loerxxxste example loe lol adi ste gen xxx* {LOCAL, $2}, {absolute4, $1} proc lilrxxxsil example lil lol adi sil -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen xxx* {LOCAL, $2}, {ILOCAL, $1} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen xxx* {LOCAL, $2}, {indirect4, %a} -#endif m68020 +#endif TBL68020 pat lol adi stl $1==$3 && $2==4 call lolxxxstl("add.l") pat loe adi ste $1==$3 && $2==4 call loexxxste("add.l") @@ -2830,12 +2824,12 @@ pat lol adp stl $1==$3 pat lil adp sil $1==$3 kills allexceptcon -#ifdef m68020 +#ifdef TBL68020 gen add_l {const, $2}, {ILOCAL, $1} -#else m68020 +#else TBL68020 uses AA_REG = {LOCAL, $1} gen add_l {const, $2}, {indirect4, %a} -#endif m68020 +#endif TBL68020 pat loe adp ste $1==$3 kills posextern @@ -2849,14 +2843,14 @@ pat lol lol adp stl $1==$2 && $1==$4 pat lil lil adp sti $1==$2 && $1==$4 kills allexceptcon -#ifdef m68020 +#ifdef TBL68020 uses AA_REG = {ILOCAL, $1} gen add_l {const, $3}, {ILOCAL, $1} -#else m68020 +#else TBL68020 uses AA_REG, AA_REG = {LOCAL, $1} gen move {indirect4, %b}, %a add_l {const, $3}, {indirect4, %b} -#endif m68020 +#endif TBL68020 yields %a pat loe loe adp ste $1==$2 && $1==$4 @@ -2936,16 +2930,16 @@ proc lloe1shste example loe loc sli ste /* only left */ roxl {absolute2, $1} proc llil1shsil example lil loc sli sil /* only left */ -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen shw* {OFF_off2, lb, $1, 2} roxl {OFF_off2, lb, $1, 0} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen shw* {offsetted2, %a, 2} roxl {indirect2, %a} -#endif m68020 +#endif TBL68020 proc rlol1shstl example lol loc sri stl /* only right */ kills all_indir, LOCAL %bd==$1 @@ -2958,16 +2952,16 @@ proc rloe1shste example loe loc sri ste /* only right */ roxr {absolute2, $1+2} proc rlil1shsil example lil loc sri sil /* only right */ -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen shw* {OFF_off2, lb, $1, 0} roxr {OFF_off2, lb, $1, 2} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen shw* {indirect2, %a} roxr {offsetted2, %a, 2} -#endif m68020 +#endif TBL68020 pat lol loc sli stl $1==$4 && $2==1 && $3==4 call llol1shstl("asl #1,") pat loe loc sli ste $1==$4 && $2==1 && $3==4 call lloe1shste("asl #1,") @@ -3003,14 +2997,14 @@ proc loebitste example loe ngi ste gen bit* {absolute4, $1} proc lilbitsil example lil ngi sil -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen bit* {ILOCAL, $1} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen bit* {indirect4, %a} -#endif m68020 +#endif TBL68020 pat lol ngi stl $1==$3 && $2==4 call lolbitstl("neg.l") pat loe ngi ste $1==$3 && $2==4 call loebitste("neg.l") @@ -3020,24 +3014,24 @@ pat loe com ste $1==$3 && $2==4 call loebitste("not.l") pat lil com sil $1==$3 && $2==4 call lilbitsil("not.l") pat lil inc sil $1==$3 -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen add_l {const, 1}, {ILOCAL, $1} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen add_l {const, 1}, {indirect4, %a} -#endif m68020 +#endif TBL68020 pat lil dec sil $1==$3 -#ifdef m68020 +#ifdef TBL68020 kills allexceptcon gen sub_l {const, 1}, {ILOCAL, $1} -#else m68020 +#else TBL68020 kills allexceptcon uses AA_REG = {LOCAL, $1} gen sub_l {const, 1}, {indirect4, %a} -#endif m68020 +#endif TBL68020 proc txxand @@ -3256,12 +3250,12 @@ with DD_REG pat loc loc cii $1==1 && $2==4 with DD_REG -#ifdef m68020 +#ifdef TBL68020 gen extb_l %1 yields %1 -#else m68020 +#else TBL68020 gen ext_w %1 ext_l %1 yields %1 -#endif m68020 +#endif TBL68020 pat loc loc ciu $1==$2 /* skip this */ pat loc loc cui $1==$2 /* skip this */ From 312739e522c9e40a560434aa4db3d3a7fc6fe773 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 30 Jan 1987 17:10:51 +0000 Subject: [PATCH 0627/1625] Initial revision --- util/led/ack.out.5 | 316 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 316 insertions(+) create mode 100644 util/led/ack.out.5 diff --git a/util/led/ack.out.5 b/util/led/ack.out.5 new file mode 100644 index 00000000..93a6d096 --- /dev/null +++ b/util/led/ack.out.5 @@ -0,0 +1,316 @@ +.TH "ACK.OUT" 5ACK "July 29, 1986" +.SH NAME +ack.out\ \-\ ACK-assembler and link editor output +.SH SYNOPSIS +.B #include +.SH DESCRIPTION +This manual page discusses the format of object files, as generated by ACK +assemblers and the link editor LED. +The format is designed to be compact, machine independent, and +portable from one machine to another, +so that an object file can be produced on one machine, and +further processed on another. +.ta \w'#define x'u +\w'XXXXXXXX'u +\w'XXXXXXXXXXX'u +.PP +In the following discussion, some structures are defined using +\fBlong\fR and \fBshort\fR as type indicators. +It is assumed that the size of a short is 2 bytes (chars) and that the +size of a long is 4 bytes. +However, these types +have a machine dependent byte and word order. +Therefore, a machine independent representation is chosen for the +object format: +a long consists of two shorts, of which the least significant one +comes first, and a short consists of two bytes, of which the +least significant one comes first. +There is no alignment between various parts and structures in the object +file. +.PP +In general, an object file consists of the following parts: +.PP +.nf +\- a file header +\- a number of section headers +\- the sections themselves +\- a number of relocation structures +\- a symbol table +\- a string area containing the names from the symbol table +.fi +.PP +.B The header. +.br +The header of an object file has the following structure: +.PP +#define ushort unsigned\ short +.PP +.nf +struct outhead { + ushort oh_magic; /* magic number */ + ushort oh_stamp; /* version stamp */ + ushort oh_flags; /* several format flags */ + ushort oh_nsect; /* number of outsect structures */ + ushort oh_nrelo; /* number of outrelo structures */ + ushort oh_nname; /* number of outname structures */ + long oh_nemit; /* length of sections */ + long oh_nchar; /* size of string area */ +}; +.fi +.PP +#define HF_LINK 0x0004 /* unresolved references left */ +.PP +The fields of this structure have the following purpose: +.nr x \w'oh_magic\ \ \ 'u +.IP oh_magic \nxu +A magic number, indicating that this is an object file. +.IP oh_stamp \nxu +A version stamp, used to detect obsolete versions of object files. +.IP oh_flags \nxu +Currently only used for the HF_LINK flag. When this flag is set, the +object file contains unresolved references. +.IP oh_nsect \nxu +The number of sections and section description structures, later on +referred to as \fIoutsect\fR structures. +Usually, there are only a few sections, f.i. a TEXT section, +a ROM section, a DATA section and a BSS section. +Notice that neither the assemblers nor LED know more about them than their +names. +.IP oh_nrelo \nxu +The number of relocation structures, later on referred to as \fIoutrelo\fR +structures. +.IP oh_nname \nxu +The number of symbol table structures, later on referred to as \fIoutname\fR +structures. +.IP oh_nemit \nxu +The total number of bytes in this object file used for the sections themselves. +This field is used to find the relocation and symbol table structures fast. +.IP oh_nchar \nxu +The size of the string area (the number of bytes). +.PP +.B The section descriptions. +.br +The next part of an object file contains the outsect-structures. +An outsect structure has the following layout: +.PP +.nf +struct outsect { + long os_base; /* start address in machine */ + long os_size; /* section size in machine */ + long os_foff; /* start address in file */ + long os_flen; /* section size in file */ + long os_lign; /* section alignment */ +}; +.fi +.PP +The fields in this structure have the following purpose: +.IP os_base \nxu +The start address of this section in the target machine. +This address is determined by LED, +when producing a non-relocatable object file. +It is ignored for relocatable object files. +.IP os_size \nxu +The size of this section on the target machine. +.IP os_foff \nxu +The start address of this section in this file. +.IP os_flen \nxu +The size of this section in this file. +This field does not have to have +the same value as the \fIos_size\fR field! +For instance, an uninitialized +data section probably has \fIos_flen\fR set to 0. +Notice that +the \fIoh_nemit\fR field of the header contains +the sum of all the \fIos_flen\fR fields. +.IP os_lign \nxu +The alignment requirement for this section. The requirement is that +the loader must leave +.IP "" \nxu +\ \ \ \ \ \ \ \fIos_base\fR \fBmod\fR \fIos_lign\fR = 0 +.IP "" \nxu +in tact. +.PP +.B The sections. +.br +The next part of an object file contains the sections themselves. +Usually, the LED program places the sections right behind one another in the +target machine, taking the +alignment requirements into account. However, the user is allowed to give +the start addresses of each section. But if the user gave a start address for +say section 2, but not for section 3, section 3 will be put +right behind section 2. +.PP +.B The relocation structures. +.br +Relocation information is information that allows a program like LED +to combine several object files and produce an executable binary +if there are no unresolved references. +If relocation information is present, it amounts to 8 bytes per +relocatable datum. The information has the following structure: +.PP +.nf +struct outrelo { + char or_type; /* type of reference */ + char or_sect; /* referencing section */ + ushort or_nami; /* referenced symbol index */ + long or_addr; /* referencing address */ +}; +.fi +.PP +.nf +/* + * relocation type bits + */ +#define RELSZ 0x07 /* relocation length */ +#define RELO1 0x01 /* 1 byte */ +#define RELO2 0x02 /* 2 bytes */ +#define RELO4 0x04 /* 4 bytes */ +#define RELPC 0x08 /* pc relative */ +#define RELBR 0x10 /* High order byte lowest address. */ +#define RELWR 0x20 /* High order word lowest address. */ +.fi +.PP +.nf +/* + * section type bits and fields + */ +#define S_TYP 0x007F /* undefined, absolute or relative */ +#define S_EXT 0x0080 /* external flag */ +#define S_ETC 0x7F00 /* for symbolic debug, bypassing 'as' */ +.fi +.PP +.nf +/* + * S_TYP field values + */ +#define S_UND 0x0000 /* undefined item */ +#define S_ABS 0x0001 /* absolute item */ +#define S_MIN 0x0002 /* first user section */ +#define S_MAX S_TYP /* last user section */ +.fi +.PP +The fields of this structure have the following purpose: +.IP or_type \nxu +Contains several flags: One of RELO1, RELO2 and RELO4 is set, indicating the +size of the relocatable datum, RELPC is set when the datum is +relocated pc relative, RELBR and RELWR indicate byte and word order of +the relocatable datum. RELBR and RELWR are needed here. It is not sufficient +to have flags for them in the header of the object file, because some +machines (NS 32016) use several of the possible combinations in their +instruction encoding. +.IP or_sect \nxu +Contains the section number of the referenc\fIing\fR section. This is a number +that lies between S_MIN and S_MAX. The section indicated with number S_MIN +is the first section in the sections-section, etc. +.IP or_addr \nxu +Contains the address of the relocatable datum, in the form of an +offset from the base of the section indicated in the \fIor_sect\fR field. +.IP or_nami \nxu +Usually contains the index of the referenced symbol in the symbol table, +starting at 0. +In this case, the reference is to an undefined external symbol, a common +symbol, or a section name. The relocatable datum then contains +an offset from the indicated symbol or the start of the indicated section. +It may, however, also have the same value as +the \fIoh_nname\fR field of the header. In this case the relocatable datum +is an absolute number, and the datum is relocated pc relative. +The relocatable datum must then be relocated with respect to the +base address of its section. +.PP +.B The symbol table. +.br +This table contains definitions of symbols. It is referred to by +outrelo-structures, and can be used by debuggers. +Entries in this table have the following structure: +.PP +.nf +struct outname { + union { + char *on_ptr; /* symbol name (in core) */ + long on_off; /* symbol name (in file) */ + } on_u; +#define on_mptr on_u.on_ptr +#define on_foff on_u.on_off + ushort on_type; /* symbol type */ + ushort on_desc; /* debug info */ + long on_valu; /* symbol value */ +}; +.fi +.PP +.nf +/* + * S_ETC field values + */ +#define S_SCT 0x0100 /* section names */ +#define S_LIN 0x0200 /* hll source line item */ +#define S_FIL 0x0300 /* hll source file item */ +#define S_MOD 0x0400 /* ass source file item */ +#define S_COM 0x1000 /* Common name */ +.fi +.PP +The members of this structure have the following purpose: +.IP on_foff \nxu +Contains the offset of the name from the beginning of the file. The name +extends from the offset to the next null byte. +.IP on_type \nxu +The S_TYP field of this member contains the section number of the symbol. +Here, this number may be S_ABS for an absolute item, or S_UND, for an +undefined item. The S_EXT flag is set in this member if the symbol is external. +The S_ETC field has the following flags: +S_SCT is set if the symbol represents a section name, +S_COM is set if the symbol represents a common name, +S_LIN is set if the symbol refers to a high level language source line item, +S_FIL is set if the symbol refers to a high level language source file item, +and S_MOD is set if the symbol refers to an assembler source file item. +.IP on_desc \nxu +Currently not used. +.IP on_valu \nxu +Is not used if the symbol refers to an undefined item. For absolute items +it contains the value, for common names it contains the size, and +for anything else it contains the offset from the beginning of the section. +.PP +.B The string area. +.br +The last part of an object file contains the name list. This is just a +sequence of null-terminated strings. +.PP +The relocation information, the symbol table, and the name list do not +have to be present, but then of course we do not have a relocatable +object file. +.PP +.B Miscellaneous defines +.br +The following miscellaneous defines might come in handy when reading +object files: +.PP +.nf +/* + * structure format strings + */ +#define SF_HEAD "22222244" +#define SF_SECT "44444" +#define SF_RELO "1124" +#define SF_NAME "4224" +.fi +.PP +.nf +/* + * structure sizes (bytes in file; add digits in SF_*) + */ +#define SZ_HEAD 20 +#define SZ_SECT 20 +#define SZ_RELO 8 +#define SZ_NAME 12 +.fi +.PP +.nf +/* + * file access macros + */ +#define BADMAGIC(x) ((x).oh_magic!=O_MAGIC) +#define OFF_SECT(x) SZ_HEAD +#define OFF_EMIT(x) (OFF_SECT(x) + ((long)(x).oh_nsect * SZ_SECT)) +#define OFF_RELO(x) (OFF_EMIT(x) + (x).oh_nemit) +#define OFF_NAME(x) (OFF_RELO(x) + ((long)(x).oh_nrelo * SZ_RELO)) +#define OFF_CHAR(x) (OFF_NAME(x) + ((long)(x).oh_nname * SZ_NAME)) +.fi +.SH "SEE ALSO" +led(6), object(3) From 1630b7c0fd9d1555eacd59ffc3838a4406fed1a9 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 30 Jan 1987 18:11:08 +0000 Subject: [PATCH 0628/1625] Error exit when compilation failes --- mach/6500/libpc/compmodule | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mach/6500/libpc/compmodule b/mach/6500/libpc/compmodule index 28461326..881f78da 100755 --- a/mach/6500/libpc/compmodule +++ b/mach/6500/libpc/compmodule @@ -1,2 +1,4 @@ -${MACH?} -I../../../h ${MACHFL?} $1 1>&2 -echo `basename $1 $2`.s +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then echo `basename $1 $2`.s +else exit 1 +fi From 8d6129322091bdd267b5026e236fa867b8cee5ec Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 30 Jan 1987 18:12:57 +0000 Subject: [PATCH 0629/1625] error exit when compilation fails --- mach/6500/libbc/compmodule | 6 ++++-- mach/6500/libcc/compmodule | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/mach/6500/libbc/compmodule b/mach/6500/libbc/compmodule index 28461326..881f78da 100755 --- a/mach/6500/libbc/compmodule +++ b/mach/6500/libbc/compmodule @@ -1,2 +1,4 @@ -${MACH?} -I../../../h ${MACHFL?} $1 1>&2 -echo `basename $1 $2`.s +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then echo `basename $1 $2`.s +else exit 1 +fi diff --git a/mach/6500/libcc/compmodule b/mach/6500/libcc/compmodule index 28461326..881f78da 100755 --- a/mach/6500/libcc/compmodule +++ b/mach/6500/libcc/compmodule @@ -1,2 +1,4 @@ -${MACH?} -I../../../h ${MACHFL?} $1 1>&2 -echo `basename $1 $2`.s +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then echo `basename $1 $2`.s +else exit 1 +fi From 28ffa6115c269d3db63d96bcaac46a7903665ce7 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 30 Jan 1987 18:15:22 +0000 Subject: [PATCH 0630/1625] *** empty log message *** --- mach/6500/libbc/Makefile | 3 ++- mach/6500/libcc/Makefile | 3 ++- mach/6500/libpc/Makefile | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/mach/6500/libbc/Makefile b/mach/6500/libbc/Makefile index 2be55a0a..6bc856bb 100644 --- a/mach/6500/libbc/Makefile +++ b/mach/6500/libbc/Makefile @@ -1,5 +1,6 @@ +SUF=s MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=6500" "SUF=s" +MACHDEF="MACH=6500" "SUF=$(SUF)" BCDEF="PREF=bc" "SUB=" "SRC=lang/basic/lib" install: diff --git a/mach/6500/libcc/Makefile b/mach/6500/libcc/Makefile index 7b71f656..df0b2b35 100644 --- a/mach/6500/libcc/Makefile +++ b/mach/6500/libcc/Makefile @@ -1,5 +1,6 @@ +SUF=s MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=6500" "SUF=s" +MACHDEF="MACH=6500" "SUF=$(SUF)" STDIO="PREF=cc" "SUB=.1s" "SRC=lang/cem/libcc/stdio" GEN="PREF=cc" "SUB=.2g" "SRC=lang/cem/libcc/gen" MON="PREF=mon" "SRC=lang/cem/libcc/mon" diff --git a/mach/6500/libpc/Makefile b/mach/6500/libpc/Makefile index 13271c21..af1866ee 100644 --- a/mach/6500/libpc/Makefile +++ b/mach/6500/libpc/Makefile @@ -1,5 +1,6 @@ +SUF=s MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=6500" "SUF=s" +MACHDEF="MACH=6500" "SUF=$(SUF)" PCDEF="PREF=pc" "SUB=" "SRC=lang/pc/libpc" install: From 288958c81bad02855579e81f3cb5ed2e5b3fb00d Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 30 Jan 1987 18:24:42 +0000 Subject: [PATCH 0631/1625] Made more like other Makefiles --- mach/6500/libem/Makefile | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/mach/6500/libem/Makefile b/mach/6500/libem/Makefile index 55dc6ee7..42daff56 100644 --- a/mach/6500/libem/Makefile +++ b/mach/6500/libem/Makefile @@ -1,23 +1,21 @@ -install: tail_em.s.a tail_em.ve.s.a +all: + +install: ../../install head_em.s head_em - ../../install tail_em.s.a tail_em - ../../install tail_em.ve.s.a tail_em.vend + ../../install libem_s.a tail_em + ../../install end.s end_em -cmp: tail_em.s.a tail_em.ve.s.a +cmp: -../../compare head_em.s head_em - -../../compare tail_em.s.a tail_em - -../../compare tail_em.ve.s.a tail_em.vend - -distr: tail_em.ve.s.a - -tail_em.s.a: - arch cr `cat LIST` - -tail_em.ve.s.a: - arch cr tail_em.ve.s.a end.s + -../../compare libem_s.a tail_em + -../../compare end.s end_em opr: make pr | opr + pr: - @pr `pwd`/Makefile `pwd`/head_em.s - @pr -l33 `tail +1 LIST|sort` `pwd`/end.s + @pr `pwd`/head_em.s + @arch pv libem_s.a | pr -h `pwd`/libem_s.a + @pr `pwd`/end.s + +clean: From d2441d274c4006b6ebb1ed76e88aa9d4849800db Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 30 Jan 1987 18:41:42 +0000 Subject: [PATCH 0632/1625] new assembler syntax --- mach/6500/libem/aar.s | 5 +++++ mach/6500/libem/addsub.s | 5 +++++ mach/6500/libem/adi.s | 5 +++++ mach/6500/libem/adi4.s | 5 +++++ mach/6500/libem/and.s | 5 +++++ mach/6500/libem/asp.s | 5 +++++ mach/6500/libem/blm.s | 5 +++++ mach/6500/libem/cii.s | 5 +++++ mach/6500/libem/cmi.s | 5 +++++ mach/6500/libem/cmi4.s | 5 +++++ mach/6500/libem/cms.s | 5 +++++ mach/6500/libem/cmu.s | 5 +++++ mach/6500/libem/cmu4.s | 5 +++++ mach/6500/libem/com.s | 5 +++++ mach/6500/libem/csa.s | 5 +++++ mach/6500/libem/csb.s | 5 +++++ mach/6500/libem/data.s | 7 ++++++- mach/6500/libem/div4.s | 5 +++++ mach/6500/libem/dum_float.s | 5 +++++ mach/6500/libem/dup.s | 5 +++++ mach/6500/libem/duv4.s | 5 +++++ mach/6500/libem/dvi.s | 5 +++++ mach/6500/libem/dvi4.s | 5 +++++ mach/6500/libem/dvu.s | 5 +++++ mach/6500/libem/dvu4.s | 5 +++++ mach/6500/libem/end.s | 11 ++++++++--- mach/6500/libem/exg.s | 5 +++++ mach/6500/libem/exg2.s | 5 +++++ mach/6500/libem/gto.s | 5 +++++ mach/6500/libem/head_em.s | 14 ++++++++++---- mach/6500/libem/indir.s | 5 +++++ mach/6500/libem/inn.s | 5 +++++ mach/6500/libem/ior.s | 5 +++++ mach/6500/libem/lar.s | 5 +++++ mach/6500/libem/lcs.s | 5 +++++ mach/6500/libem/ldi.s | 5 +++++ mach/6500/libem/locaddr.s | 5 +++++ mach/6500/libem/loi.s | 5 +++++ mach/6500/libem/loi1.s | 5 +++++ mach/6500/libem/loil.s | 5 +++++ mach/6500/libem/lol.s | 5 +++++ mach/6500/libem/los.s | 5 +++++ mach/6500/libem/lxa1.s | 5 +++++ mach/6500/libem/lxa2.s | 5 +++++ mach/6500/libem/lxl.s | 5 +++++ mach/6500/libem/mli.s | 5 +++++ mach/6500/libem/mli4.s | 5 +++++ mach/6500/libem/mlu.s | 5 +++++ mach/6500/libem/mlu4.s | 5 +++++ mach/6500/libem/mon.s | 5 +++++ mach/6500/libem/mul4.s | 5 +++++ mach/6500/libem/ngi.s | 5 +++++ mach/6500/libem/ngi4.s | 5 +++++ mach/6500/libem/print.s | 5 +++++ mach/6500/libem/printhex.s | 5 +++++ mach/6500/libem/printstack.s | 5 +++++ mach/6500/libem/pro.s | 5 +++++ mach/6500/libem/read.s | 5 +++++ mach/6500/libem/ret.s | 5 +++++ mach/6500/libem/rmi.s | 5 +++++ mach/6500/libem/rmi4.s | 5 +++++ mach/6500/libem/rmu.s | 5 +++++ mach/6500/libem/rmu4.s | 5 +++++ mach/6500/libem/rol.s | 5 +++++ mach/6500/libem/rol4.s | 5 +++++ mach/6500/libem/ror.s | 5 +++++ mach/6500/libem/ror4.s | 5 +++++ mach/6500/libem/rtt.s | 5 +++++ mach/6500/libem/sar.s | 5 +++++ mach/6500/libem/sbi.s | 5 +++++ mach/6500/libem/sbi4.s | 5 +++++ mach/6500/libem/sdl.s | 5 +++++ mach/6500/libem/set.s | 5 +++++ mach/6500/libem/sli.s | 5 +++++ mach/6500/libem/sli4.s | 5 +++++ mach/6500/libem/sri.s | 5 +++++ mach/6500/libem/sri4.s | 5 +++++ mach/6500/libem/sti.s | 5 +++++ mach/6500/libem/sti1.s | 5 +++++ mach/6500/libem/stil.s | 5 +++++ mach/6500/libem/stl.s | 5 +++++ mach/6500/libem/sts.s | 5 +++++ mach/6500/libem/teq.s | 5 +++++ mach/6500/libem/test2.s | 5 +++++ mach/6500/libem/testFFh.s | 5 +++++ mach/6500/libem/tge.s | 5 +++++ mach/6500/libem/tgt.s | 5 +++++ mach/6500/libem/tle.s | 5 +++++ mach/6500/libem/tlt.s | 5 +++++ mach/6500/libem/tne.s | 5 +++++ mach/6500/libem/trap.s | 5 +++++ mach/6500/libem/write.s | 5 +++++ mach/6500/libem/xor.s | 5 +++++ mach/6500/libem/zer.s | 5 +++++ mach/6500/libem/zri.s | 5 +++++ 95 files changed, 484 insertions(+), 8 deletions(-) diff --git a/mach/6500/libem/aar.s b/mach/6500/libem/aar.s index 4f65ca87..8ec8eab0 100644 --- a/mach/6500/libem/aar.s +++ b/mach/6500/libem/aar.s @@ -1,4 +1,9 @@ .define Aar +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine gets the address of the array element diff --git a/mach/6500/libem/addsub.s b/mach/6500/libem/addsub.s index 07ad393e..488dba0c 100644 --- a/mach/6500/libem/addsub.s +++ b/mach/6500/libem/addsub.s @@ -1,4 +1,9 @@ .define Addsub +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine is used by the fourbyte addition and subtraction ! routines. diff --git a/mach/6500/libem/adi.s b/mach/6500/libem/adi.s index 7dc95651..a915cf44 100644 --- a/mach/6500/libem/adi.s +++ b/mach/6500/libem/adi.s @@ -1,4 +1,9 @@ .define Adi2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine adds two twobyte integers. ! The first operand is on the top of the stack, the second operand diff --git a/mach/6500/libem/adi4.s b/mach/6500/libem/adi4.s index 80f58f30..3fbf5287 100644 --- a/mach/6500/libem/adi4.s +++ b/mach/6500/libem/adi4.s @@ -1,4 +1,9 @@ .define Adi4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine adds two fourbyte integers, which are on the stack. ! The addresses are initiated by the subroutine Addsub. diff --git a/mach/6500/libem/and.s b/mach/6500/libem/and.s index c626f0eb..84118969 100644 --- a/mach/6500/libem/and.s +++ b/mach/6500/libem/and.s @@ -1,4 +1,9 @@ .define And +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine performs the logical and on two groups of ! atmost 254 bytes. The number of bytes is in register Y. diff --git a/mach/6500/libem/asp.s b/mach/6500/libem/asp.s index 1581942c..e873160d 100644 --- a/mach/6500/libem/asp.s +++ b/mach/6500/libem/asp.s @@ -1,4 +1,9 @@ .define Asp +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine adds an offset to the stackpointer, ! e.g. after the return from a procedurecall. diff --git a/mach/6500/libem/blm.s b/mach/6500/libem/blm.s index df8cb061..8fa4b2b5 100644 --- a/mach/6500/libem/blm.s +++ b/mach/6500/libem/blm.s @@ -1,4 +1,9 @@ .define Blm, Blmnp +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine copies bytes from one place in memory to ! another. The source address is in registerpair AX and is stored diff --git a/mach/6500/libem/cii.s b/mach/6500/libem/cii.s index 1eff4214..7ed2f71e 100644 --- a/mach/6500/libem/cii.s +++ b/mach/6500/libem/cii.s @@ -1,4 +1,9 @@ .define Cii +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine converts integers to integers. ! Convertions of integers with the same source size as destination diff --git a/mach/6500/libem/cmi.s b/mach/6500/libem/cmi.s index ada74148..c53a9854 100644 --- a/mach/6500/libem/cmi.s +++ b/mach/6500/libem/cmi.s @@ -1,4 +1,9 @@ .define Cmi +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine compares on two integers. ! If T is pushed first and than S, the routine will return: diff --git a/mach/6500/libem/cmi4.s b/mach/6500/libem/cmi4.s index 53416360..59d0d202 100644 --- a/mach/6500/libem/cmi4.s +++ b/mach/6500/libem/cmi4.s @@ -1,4 +1,9 @@ .define Cmi4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine compares on fourbyte integers. ! If T is pushed first and than S, the routine will return: diff --git a/mach/6500/libem/cms.s b/mach/6500/libem/cms.s index 1105b16e..a8c98b17 100644 --- a/mach/6500/libem/cms.s +++ b/mach/6500/libem/cms.s @@ -1,4 +1,9 @@ .define Cms +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine compares two groups of bytes, bit for bit. ! The groups can consist of 2 or 4 bytes. This number is in diff --git a/mach/6500/libem/cmu.s b/mach/6500/libem/cmu.s index 5c55ff5f..fac30df3 100644 --- a/mach/6500/libem/cmu.s +++ b/mach/6500/libem/cmu.s @@ -1,4 +1,9 @@ .define Cmu2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine compares two unsigned twobyte integers. ! If T is the first pushed and than S, the routine will return: diff --git a/mach/6500/libem/cmu4.s b/mach/6500/libem/cmu4.s index 2275e9f9..8cb46e66 100644 --- a/mach/6500/libem/cmu4.s +++ b/mach/6500/libem/cmu4.s @@ -1,4 +1,9 @@ .define Cmu4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine compares two unsigned fourbyte integers. ! If T is first pushed and than S the routine will return: diff --git a/mach/6500/libem/com.s b/mach/6500/libem/com.s index 300794f1..5370da04 100644 --- a/mach/6500/libem/com.s +++ b/mach/6500/libem/com.s @@ -1,4 +1,9 @@ .define Com +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine performs a one complement on ! a group of atmost 254 bytes (number in register Y). diff --git a/mach/6500/libem/csa.s b/mach/6500/libem/csa.s index 61a88b5f..268cf40c 100644 --- a/mach/6500/libem/csa.s +++ b/mach/6500/libem/csa.s @@ -1,4 +1,9 @@ .define Csa +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine performs the case jump by indexing. ! The zeropage locations ADDR, ADDR+1 contain the address of diff --git a/mach/6500/libem/csb.s b/mach/6500/libem/csb.s index 37185097..66609813 100644 --- a/mach/6500/libem/csb.s +++ b/mach/6500/libem/csb.s @@ -1,4 +1,9 @@ .define Csb +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine performs the case jump by searching the table. ! The zeropage locations ADDR, ADDR+1 contain the address of the diff --git a/mach/6500/libem/data.s b/mach/6500/libem/data.s index 61da1b98..630a1d9e 100644 --- a/mach/6500/libem/data.s +++ b/mach/6500/libem/data.s @@ -2,12 +2,17 @@ .define ECONV,ESTACK .define EHEAP,EODDZ,ECASE .define EBADMON,EBADLIN,EBADGTO +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This file contains the global data used by the trap routine. ! DATA -.data +.sect .data EARRAY: .asciz "Array bound error\n\r" ERANGE: diff --git a/mach/6500/libem/div4.s b/mach/6500/libem/div4.s index 3cd68a1d..62235091 100644 --- a/mach/6500/libem/div4.s +++ b/mach/6500/libem/div4.s @@ -1,4 +1,9 @@ .define Div4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine performs a signed divide on two fourbyte integers. ! For more detail see dvi.s diff --git a/mach/6500/libem/dum_float.s b/mach/6500/libem/dum_float.s index b4f49702..d5a80d1a 100644 --- a/mach/6500/libem/dum_float.s +++ b/mach/6500/libem/dum_float.s @@ -23,6 +23,11 @@ .define Cfu .define Lfr8 .define Ret8 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Dummy floating point package for 6500 ! every EM floating point instruction results in an diff --git a/mach/6500/libem/dup.s b/mach/6500/libem/dup.s index 22e33ac5..95665866 100644 --- a/mach/6500/libem/dup.s +++ b/mach/6500/libem/dup.s @@ -1,4 +1,9 @@ .define Dup +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine duplicate's the top n (in register Y) bytes. ! N is atmost 256. diff --git a/mach/6500/libem/duv4.s b/mach/6500/libem/duv4.s index 1395a672..551aaa79 100644 --- a/mach/6500/libem/duv4.s +++ b/mach/6500/libem/duv4.s @@ -1,4 +1,9 @@ .define Duv4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine performs an unsigned division on two fourbyte ! unsigned integers. diff --git a/mach/6500/libem/dvi.s b/mach/6500/libem/dvi.s index 3f5d69a2..9d92b5d0 100644 --- a/mach/6500/libem/dvi.s +++ b/mach/6500/libem/dvi.s @@ -1,4 +1,9 @@ .define Dvi2, Div, Duv +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! The subroutine Dvi2 performs a signed division. ! Its operands are on the stack. diff --git a/mach/6500/libem/dvi4.s b/mach/6500/libem/dvi4.s index 5b068ab3..398f43d7 100644 --- a/mach/6500/libem/dvi4.s +++ b/mach/6500/libem/dvi4.s @@ -1,4 +1,9 @@ .define Dvi4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine performs a fourbyte signed division. ! For more details see dvi.s diff --git a/mach/6500/libem/dvu.s b/mach/6500/libem/dvu.s index 1cb6b8df..75558e91 100644 --- a/mach/6500/libem/dvu.s +++ b/mach/6500/libem/dvu.s @@ -1,4 +1,9 @@ .define Dvu2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine performs a twobyte unsigned division ! For more details see dvi.s. diff --git a/mach/6500/libem/dvu4.s b/mach/6500/libem/dvu4.s index 099cf893..cf7232c3 100644 --- a/mach/6500/libem/dvu4.s +++ b/mach/6500/libem/dvu4.s @@ -1,4 +1,9 @@ .define Dvu4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine performs an unsigned division on fourbyte ! integers. For more details see dvi.s diff --git a/mach/6500/libem/end.s b/mach/6500/libem/end.s index 966af2a8..1bb218eb 100644 --- a/mach/6500/libem/end.s +++ b/mach/6500/libem/end.s @@ -1,12 +1,17 @@ .define endtext, enddata, endbss, end +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text -.text +.sect .text endtext: .align 2 -.data +.sect .data .align 2 enddata: -.bss +.sect .bss .align 2 endbss: end: diff --git a/mach/6500/libem/exg.s b/mach/6500/libem/exg.s index 12be6e58..2805b419 100644 --- a/mach/6500/libem/exg.s +++ b/mach/6500/libem/exg.s @@ -1,4 +1,9 @@ .define Exg +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine exchanges two groups of bytes on the top of the ! stack. The groups may consist of atmost 255 bytes. diff --git a/mach/6500/libem/exg2.s b/mach/6500/libem/exg2.s index 0e56587f..0f1849e5 100644 --- a/mach/6500/libem/exg2.s +++ b/mach/6500/libem/exg2.s @@ -1,4 +1,9 @@ .define Exg2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine exchanges two words on top of the stack. ! The top word of the stack is really in the AX registerpair. diff --git a/mach/6500/libem/gto.s b/mach/6500/libem/gto.s index 90d168e0..500ae1d9 100644 --- a/mach/6500/libem/gto.s +++ b/mach/6500/libem/gto.s @@ -1,4 +1,9 @@ .define Gto +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine performs the non_local goto. ! The address of the descriptor is stored in zeropage locations diff --git a/mach/6500/libem/head_em.s b/mach/6500/libem/head_em.s index 614e09ea..873976c4 100644 --- a/mach/6500/libem/head_em.s +++ b/mach/6500/libem/head_em.s @@ -9,6 +9,12 @@ .define RETSIZE, TRAPVAL, STACK, BRANCH .define start, Push, Pop, STACKTh, STACKTl .define F_DUM +.sect .zero +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! DEFINITIONS @@ -51,7 +57,7 @@ STACKTl = 0D0h ! Some zeropage declarations -.zero +.sect .zero RES: .space 76 ! special for the operating system @@ -97,8 +103,8 @@ STACK: .space 1 ! contains the hardware stackpointer on RESERVED: .space 112 ! used by the operating system +.sect .text .base 0E02h ! where to start in the BBC micro -.text ! GENERAL PURPOSE ROUTINES start: @@ -220,8 +226,8 @@ Pop: rts -.data +.sect .data PROGNAME: ! for initialising the programname pointer .asciz "program" -.bss +.sect .bss beginbss: diff --git a/mach/6500/libem/indir.s b/mach/6500/libem/indir.s index 64425128..4ad1c61c 100644 --- a/mach/6500/libem/indir.s +++ b/mach/6500/libem/indir.s @@ -1,4 +1,9 @@ .define Indir +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine performs an indirect procedurecall. ! This must be done this way since the jump instruction diff --git a/mach/6500/libem/inn.s b/mach/6500/libem/inn.s index 3ac1550c..0a1c7f92 100644 --- a/mach/6500/libem/inn.s +++ b/mach/6500/libem/inn.s @@ -1,4 +1,9 @@ .define Inn +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine checks if a certain bit is set in a set ! of n bytes on top of the stack. diff --git a/mach/6500/libem/ior.s b/mach/6500/libem/ior.s index 0ba1a381..961040ae 100644 --- a/mach/6500/libem/ior.s +++ b/mach/6500/libem/ior.s @@ -1,4 +1,9 @@ .define Ior +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine performs the logical inclusive or on two ! groups of bytes. The groups may consist of atmost 254 bytes. diff --git a/mach/6500/libem/lar.s b/mach/6500/libem/lar.s index 15bb581d..8f490bef 100644 --- a/mach/6500/libem/lar.s +++ b/mach/6500/libem/lar.s @@ -1,4 +1,9 @@ .define Lar +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine performs the LAR instruction. ! For details see rapport IR-81. diff --git a/mach/6500/libem/lcs.s b/mach/6500/libem/lcs.s index 7c387f5c..b0385141 100644 --- a/mach/6500/libem/lcs.s +++ b/mach/6500/libem/lcs.s @@ -1,4 +1,9 @@ .define Lcs +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine creates space for locals on procedure entry ! by lowering the stackpointer. diff --git a/mach/6500/libem/ldi.s b/mach/6500/libem/ldi.s index a5b056a7..78723256 100644 --- a/mach/6500/libem/ldi.s +++ b/mach/6500/libem/ldi.s @@ -1,4 +1,9 @@ .define Ldi, Ldo +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! The subroutine Ldi pushes a four byte object onto the stack. ! The address is in registerpair AX. diff --git a/mach/6500/libem/locaddr.s b/mach/6500/libem/locaddr.s index 2156f7e1..3ab776e9 100644 --- a/mach/6500/libem/locaddr.s +++ b/mach/6500/libem/locaddr.s @@ -1,4 +1,9 @@ .define Locaddr +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This routine gets the address of a local which offset is to big. ! The offset is in registerpair AX. diff --git a/mach/6500/libem/loi.s b/mach/6500/libem/loi.s index 45c135ea..70e8dc6a 100644 --- a/mach/6500/libem/loi.s +++ b/mach/6500/libem/loi.s @@ -1,4 +1,9 @@ .define Loi, Lext +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine performs an indirect load on a word of two bytes. ! Lext is used when the address is already in zeropage. diff --git a/mach/6500/libem/loi1.s b/mach/6500/libem/loi1.s index 82109224..956c314f 100644 --- a/mach/6500/libem/loi1.s +++ b/mach/6500/libem/loi1.s @@ -1,4 +1,9 @@ .define Loi1 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This routine loads a one byte object in registerpair AX. diff --git a/mach/6500/libem/loil.s b/mach/6500/libem/loil.s index 4c0e3597..afc4d337 100644 --- a/mach/6500/libem/loil.s +++ b/mach/6500/libem/loil.s @@ -1,4 +1,9 @@ .define Loil +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine pushes an object of size greater than four bytes ! onto the stack. diff --git a/mach/6500/libem/lol.s b/mach/6500/libem/lol.s index 6f1bce05..7acf29c7 100644 --- a/mach/6500/libem/lol.s +++ b/mach/6500/libem/lol.s @@ -1,4 +1,9 @@ .define Lol +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine loads a local in registerpair AX which ! offset from the localbase is to big. diff --git a/mach/6500/libem/los.s b/mach/6500/libem/los.s index 1ba88f66..757b5e0c 100644 --- a/mach/6500/libem/los.s +++ b/mach/6500/libem/los.s @@ -1,4 +1,9 @@ .define Los +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine perfoms the LOS instruction. ! For detail see rapport IR-81. diff --git a/mach/6500/libem/lxa1.s b/mach/6500/libem/lxa1.s index 402ef8b7..867db4ab 100644 --- a/mach/6500/libem/lxa1.s +++ b/mach/6500/libem/lxa1.s @@ -1,4 +1,9 @@ .define Lxa1 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine loads the address of AB zero static levels back. diff --git a/mach/6500/libem/lxa2.s b/mach/6500/libem/lxa2.s index 58df1dcc..4bf4d7c1 100644 --- a/mach/6500/libem/lxa2.s +++ b/mach/6500/libem/lxa2.s @@ -1,4 +1,9 @@ .define Lxa2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine load the address of AB n (255 >= n > 0) static levels ! back. diff --git a/mach/6500/libem/lxl.s b/mach/6500/libem/lxl.s index d72c9fb0..5b3e96f6 100644 --- a/mach/6500/libem/lxl.s +++ b/mach/6500/libem/lxl.s @@ -1,4 +1,9 @@ .define Lxl +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine loads LB n (255 => n > 0) static levels back. diff --git a/mach/6500/libem/mli.s b/mach/6500/libem/mli.s index b441229d..fa347ef2 100644 --- a/mach/6500/libem/mli.s +++ b/mach/6500/libem/mli.s @@ -1,4 +1,9 @@ .define Mli2, Mlinp, Mul +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! The subroutine Mli2 multiplies two signed integers. The integers ! are popped from the stack. diff --git a/mach/6500/libem/mli4.s b/mach/6500/libem/mli4.s index 81b59ff8..629c01b7 100644 --- a/mach/6500/libem/mli4.s +++ b/mach/6500/libem/mli4.s @@ -1,4 +1,9 @@ .define Mli4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine multiplies two signed fourbyte integers ! For more detail see mli.s diff --git a/mach/6500/libem/mlu.s b/mach/6500/libem/mlu.s index c11f835c..6820f88b 100644 --- a/mach/6500/libem/mlu.s +++ b/mach/6500/libem/mlu.s @@ -1,4 +1,9 @@ .define Mlu2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine multiplies two unsigned fourbyte intergers. ! For more details see mli.s diff --git a/mach/6500/libem/mlu4.s b/mach/6500/libem/mlu4.s index 4d6b0436..44b7771b 100644 --- a/mach/6500/libem/mlu4.s +++ b/mach/6500/libem/mlu4.s @@ -1,4 +1,9 @@ .define Mlu4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine multiplies two fourbyte unsigned integers. ! For more details see mli.s diff --git a/mach/6500/libem/mon.s b/mach/6500/libem/mon.s index 69a9dd5b..1d094c51 100644 --- a/mach/6500/libem/mon.s +++ b/mach/6500/libem/mon.s @@ -1,4 +1,9 @@ .define Mon +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine performs some monitor calls. ! The exit call just resets the hardware_stackpointer so diff --git a/mach/6500/libem/mul4.s b/mach/6500/libem/mul4.s index 98d046f4..f378a2d8 100644 --- a/mach/6500/libem/mul4.s +++ b/mach/6500/libem/mul4.s @@ -1,4 +1,9 @@ .define Mul4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine multiplies two fourbyte signed integers. ! For more details see mli.s diff --git a/mach/6500/libem/ngi.s b/mach/6500/libem/ngi.s index d375b199..1c6d50e7 100644 --- a/mach/6500/libem/ngi.s +++ b/mach/6500/libem/ngi.s @@ -1,4 +1,9 @@ .define Ngi2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine negates the integer in registerpair AX. ! The negation is a one's complement plus one. diff --git a/mach/6500/libem/ngi4.s b/mach/6500/libem/ngi4.s index f62cd489..c19600c7 100644 --- a/mach/6500/libem/ngi4.s +++ b/mach/6500/libem/ngi4.s @@ -1,4 +1,9 @@ .define Ngi4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine takes a fourbyte interger and negates it. ! For more details see ngi2.s diff --git a/mach/6500/libem/print.s b/mach/6500/libem/print.s index 7cd70e32..eea8e73d 100644 --- a/mach/6500/libem/print.s +++ b/mach/6500/libem/print.s @@ -1,4 +1,9 @@ .define Mprint +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine prints a zero terminated ascii string. ! The registerpair AX contains the start of the string. diff --git a/mach/6500/libem/printhex.s b/mach/6500/libem/printhex.s index be979a85..0d5c5bd8 100644 --- a/mach/6500/libem/printhex.s +++ b/mach/6500/libem/printhex.s @@ -1,4 +1,9 @@ .define Printhex +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine print the contents of register A to the screen ! in hexadecimal form. diff --git a/mach/6500/libem/printstack.s b/mach/6500/libem/printstack.s index a554d9e5..27f1512a 100644 --- a/mach/6500/libem/printstack.s +++ b/mach/6500/libem/printstack.s @@ -1,4 +1,9 @@ .define Printstack +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This a special subroutine which prints some things to the ! monitorscreen for debugging. diff --git a/mach/6500/libem/pro.s b/mach/6500/libem/pro.s index 27a565fa..066c378e 100644 --- a/mach/6500/libem/pro.s +++ b/mach/6500/libem/pro.s @@ -1,4 +1,9 @@ .define Pro +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This routine is called at the entry of a procedure. ! It saves the localbase of the invoking procedure, and sets the diff --git a/mach/6500/libem/read.s b/mach/6500/libem/read.s index 0f6ab67b..12d2c58b 100644 --- a/mach/6500/libem/read.s +++ b/mach/6500/libem/read.s @@ -1,4 +1,9 @@ .define Mread +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine reads characters from the standard input. ! It ignores the filedes. diff --git a/mach/6500/libem/ret.s b/mach/6500/libem/ret.s index 8002fc1f..ced8f062 100644 --- a/mach/6500/libem/ret.s +++ b/mach/6500/libem/ret.s @@ -1,4 +1,9 @@ .define Ret +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine stores the returnvalue in the return area. ! This area is in zeropage. diff --git a/mach/6500/libem/rmi.s b/mach/6500/libem/rmi.s index 12bc6425..87295bea 100644 --- a/mach/6500/libem/rmi.s +++ b/mach/6500/libem/rmi.s @@ -1,4 +1,9 @@ .define Rmi2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine returns the remainder of a twobyte signed division. ! The sign of the result is as specified in the emtest. diff --git a/mach/6500/libem/rmi4.s b/mach/6500/libem/rmi4.s index 0b221e2e..fdeab611 100644 --- a/mach/6500/libem/rmi4.s +++ b/mach/6500/libem/rmi4.s @@ -1,4 +1,9 @@ .define Rmi4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine returns the remainder of a fourbyte division. diff --git a/mach/6500/libem/rmu.s b/mach/6500/libem/rmu.s index dff2c3c7..82b0cbfb 100644 --- a/mach/6500/libem/rmu.s +++ b/mach/6500/libem/rmu.s @@ -1,4 +1,9 @@ .define Rmu2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine returns the remainder of an twobyte unsigned ! integer division. diff --git a/mach/6500/libem/rmu4.s b/mach/6500/libem/rmu4.s index e3c848cd..8cfc7ead 100644 --- a/mach/6500/libem/rmu4.s +++ b/mach/6500/libem/rmu4.s @@ -1,4 +1,9 @@ .define Rmu4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine returns the remainder of a fourbyte unsigned ! division. diff --git a/mach/6500/libem/rol.s b/mach/6500/libem/rol.s index 34786e2b..b486e32f 100644 --- a/mach/6500/libem/rol.s +++ b/mach/6500/libem/rol.s @@ -1,4 +1,9 @@ .define Rol +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine rotates left an integer n times ! N is in register X. diff --git a/mach/6500/libem/rol4.s b/mach/6500/libem/rol4.s index 5f040727..f58c2810 100644 --- a/mach/6500/libem/rol4.s +++ b/mach/6500/libem/rol4.s @@ -1,4 +1,9 @@ .define Rol4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine rotates left a fourbyte integer n times. ! N is in register X. diff --git a/mach/6500/libem/ror.s b/mach/6500/libem/ror.s index f70db75f..dd54771e 100644 --- a/mach/6500/libem/ror.s +++ b/mach/6500/libem/ror.s @@ -1,4 +1,9 @@ .define Ror +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine rotates right a integer twobyte word. ! The number of rotates is in X. diff --git a/mach/6500/libem/ror4.s b/mach/6500/libem/ror4.s index e0b0d2db..00ad4b00 100644 --- a/mach/6500/libem/ror4.s +++ b/mach/6500/libem/ror4.s @@ -1,4 +1,9 @@ .define Ror4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine rotates right a fourbyte word. ! The number of rotates is in X. diff --git a/mach/6500/libem/rtt.s b/mach/6500/libem/rtt.s index ed2d8b7d..31e1cf3b 100644 --- a/mach/6500/libem/rtt.s +++ b/mach/6500/libem/rtt.s @@ -1,4 +1,9 @@ .define Rtt +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine performs the return from trap. diff --git a/mach/6500/libem/sar.s b/mach/6500/libem/sar.s index 0b482a2c..29605265 100644 --- a/mach/6500/libem/sar.s +++ b/mach/6500/libem/sar.s @@ -1,4 +1,9 @@ .define Sar +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine performs the SAR instruction. ! For details see rapport IR-81. diff --git a/mach/6500/libem/sbi.s b/mach/6500/libem/sbi.s index 8c5c3e39..d445b020 100644 --- a/mach/6500/libem/sbi.s +++ b/mach/6500/libem/sbi.s @@ -1,4 +1,9 @@ .define Sbi2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine subtracts two twobyte signed integers ! and returnes the result in registerpair AX. diff --git a/mach/6500/libem/sbi4.s b/mach/6500/libem/sbi4.s index b4a12a27..3d81396b 100644 --- a/mach/6500/libem/sbi4.s +++ b/mach/6500/libem/sbi4.s @@ -1,4 +1,9 @@ .define Sbi4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine subtracts two fourbyte signed integers. diff --git a/mach/6500/libem/sdl.s b/mach/6500/libem/sdl.s index 11def2b3..6e06a5d9 100644 --- a/mach/6500/libem/sdl.s +++ b/mach/6500/libem/sdl.s @@ -1,4 +1,9 @@ .define Sdi, Sdo +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! The subroutine Sdi takes a fourbyte word and stores it ! at the address in registerpair AX. diff --git a/mach/6500/libem/set.s b/mach/6500/libem/set.s index f64f74f4..8e7fc70e 100644 --- a/mach/6500/libem/set.s +++ b/mach/6500/libem/set.s @@ -1,4 +1,9 @@ .define Set +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine creates a set of n (n <= 256) bytes. ! In this set a certain bit, which number is in registerpair AX, diff --git a/mach/6500/libem/sli.s b/mach/6500/libem/sli.s index 9d195593..e3ae200d 100644 --- a/mach/6500/libem/sli.s +++ b/mach/6500/libem/sli.s @@ -1,4 +1,9 @@ .define Sli2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine shifts a signed or unsigned interger to the ! left n times. diff --git a/mach/6500/libem/sli4.s b/mach/6500/libem/sli4.s index d9c670cd..d7dd4319 100644 --- a/mach/6500/libem/sli4.s +++ b/mach/6500/libem/sli4.s @@ -1,4 +1,9 @@ .define Sli4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine shift a signed or unsigned fourbyte integer ! n times left. N is in register X. diff --git a/mach/6500/libem/sri.s b/mach/6500/libem/sri.s index da44e072..7f980281 100644 --- a/mach/6500/libem/sri.s +++ b/mach/6500/libem/sri.s @@ -1,4 +1,9 @@ .define Sri2, Sru2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! The subroutine Sri2 shifts a signed integer n times right. ! In the case of a negative integer there is signextension. diff --git a/mach/6500/libem/sri4.s b/mach/6500/libem/sri4.s index 46b3b7be..4b5336f3 100644 --- a/mach/6500/libem/sri4.s +++ b/mach/6500/libem/sri4.s @@ -1,4 +1,9 @@ .define Sri4, Sru4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! The subroutine Sri4 shifts a signed fourbyte integer to the ! right n times diff --git a/mach/6500/libem/sti.s b/mach/6500/libem/sti.s index b9772249..76a2d44e 100644 --- a/mach/6500/libem/sti.s +++ b/mach/6500/libem/sti.s @@ -1,4 +1,9 @@ .define Sti, Sext, Stii +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! The subroutine Sti stores an twobyte word at the address which ! is in registerpair AX. diff --git a/mach/6500/libem/sti1.s b/mach/6500/libem/sti1.s index 2665a805..ad93f326 100644 --- a/mach/6500/libem/sti1.s +++ b/mach/6500/libem/sti1.s @@ -1,4 +1,9 @@ .define Sti1 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine stores an onebyte wordfractional at the address ! which is in registerpair AX. diff --git a/mach/6500/libem/stil.s b/mach/6500/libem/stil.s index c44f2979..d19df35a 100644 --- a/mach/6500/libem/stil.s +++ b/mach/6500/libem/stil.s @@ -1,4 +1,9 @@ .define Stil +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine stores indirect a block of bytes if ! the number of bytes is greater than four. diff --git a/mach/6500/libem/stl.s b/mach/6500/libem/stl.s index 353e00b8..5b58f5fc 100644 --- a/mach/6500/libem/stl.s +++ b/mach/6500/libem/stl.s @@ -1,4 +1,9 @@ .define Stl +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine performs the storage of a local which offset ! is to big. diff --git a/mach/6500/libem/sts.s b/mach/6500/libem/sts.s index 8c6ffa94..b2fdbe8c 100644 --- a/mach/6500/libem/sts.s +++ b/mach/6500/libem/sts.s @@ -1,4 +1,9 @@ .define Sts +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine stores indirect a number of bytes. ! The number of bytes is in the registerpair AX. diff --git a/mach/6500/libem/teq.s b/mach/6500/libem/teq.s index a346e618..457bcd01 100644 --- a/mach/6500/libem/teq.s +++ b/mach/6500/libem/teq.s @@ -1,4 +1,9 @@ .define Teq +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine test if the value in registerpair AX is zero ! or nonzero. diff --git a/mach/6500/libem/test2.s b/mach/6500/libem/test2.s index c07497c7..b1c70779 100644 --- a/mach/6500/libem/test2.s +++ b/mach/6500/libem/test2.s @@ -1,4 +1,9 @@ .define Test2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine tests if the value on top of the stack is 2. ! It is used if the size is on top of the stack. diff --git a/mach/6500/libem/testFFh.s b/mach/6500/libem/testFFh.s index a02c4544..695ff0e5 100644 --- a/mach/6500/libem/testFFh.s +++ b/mach/6500/libem/testFFh.s @@ -1,4 +1,9 @@ .define TestFFh +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine tests if the value on top of the stack is <= 256. ! It is used if the istruction argument is on top of the stack. diff --git a/mach/6500/libem/tge.s b/mach/6500/libem/tge.s index 49050fd4..c18bdcbc 100644 --- a/mach/6500/libem/tge.s +++ b/mach/6500/libem/tge.s @@ -1,4 +1,9 @@ .define Tge +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine test if the value in registerpair AX is ! greater than or equal to zero. diff --git a/mach/6500/libem/tgt.s b/mach/6500/libem/tgt.s index e2e5f3ba..68fe07fe 100644 --- a/mach/6500/libem/tgt.s +++ b/mach/6500/libem/tgt.s @@ -1,4 +1,9 @@ .define Tgt +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine tests if the value in registerpair AX is ! greater than zero. diff --git a/mach/6500/libem/tle.s b/mach/6500/libem/tle.s index 073bdbb6..8b7310aa 100644 --- a/mach/6500/libem/tle.s +++ b/mach/6500/libem/tle.s @@ -1,4 +1,9 @@ .define Tle +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine tests if the value in registerpair AX is ! less than or equal to zero. diff --git a/mach/6500/libem/tlt.s b/mach/6500/libem/tlt.s index 557dfdca..5dd26525 100644 --- a/mach/6500/libem/tlt.s +++ b/mach/6500/libem/tlt.s @@ -1,4 +1,9 @@ .define Tlt +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine tests if the value in registerpair AX is ! less than zero. diff --git a/mach/6500/libem/tne.s b/mach/6500/libem/tne.s index aaaf18e4..d90d49ad 100644 --- a/mach/6500/libem/tne.s +++ b/mach/6500/libem/tne.s @@ -1,4 +1,9 @@ .define Tne +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine tests if the value in registerpair AX is ! not equal to zero. diff --git a/mach/6500/libem/trap.s b/mach/6500/libem/trap.s index ef7d9e9d..5ce53f93 100644 --- a/mach/6500/libem/trap.s +++ b/mach/6500/libem/trap.s @@ -1,4 +1,9 @@ .define Trap +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine performs the trap instruction. diff --git a/mach/6500/libem/write.s b/mach/6500/libem/write.s index 4bc1e245..7b87cf44 100644 --- a/mach/6500/libem/write.s +++ b/mach/6500/libem/write.s @@ -1,4 +1,9 @@ .define Mwrite +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine performs the monitor call write. ! Writing is always done to standardoutput. diff --git a/mach/6500/libem/xor.s b/mach/6500/libem/xor.s index 5ef73a7c..5d4455a3 100644 --- a/mach/6500/libem/xor.s +++ b/mach/6500/libem/xor.s @@ -1,4 +1,9 @@ .define Xor +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine performs the exclusive or on two groups of bytes. ! The groups consists of atmost 254 bytes. diff --git a/mach/6500/libem/zer.s b/mach/6500/libem/zer.s index 9c648508..ef5e0d20 100644 --- a/mach/6500/libem/zer.s +++ b/mach/6500/libem/zer.s @@ -1,4 +1,9 @@ .define Zer +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This subroutine puts n (n <=256) zero bytes on top of ! the stack. diff --git a/mach/6500/libem/zri.s b/mach/6500/libem/zri.s index abc75f90..72c95f38 100644 --- a/mach/6500/libem/zri.s +++ b/mach/6500/libem/zri.s @@ -1,4 +1,9 @@ .define Zrl, Zro +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! The subroutine Zrl makes a local zero which offset is to big. ! The offset of the local is in registerpair AX. From 656e2ba6fea62bc944cca7adf72d7ba0d80682c5 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 30 Jan 1987 19:20:31 +0000 Subject: [PATCH 0633/1625] Adapted to new assembler syntax --- mach/6500/cg/mach.c | 14 ++++++-------- mach/6500/cg/mach.h | 11 ++++++----- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/mach/6500/cg/mach.c b/mach/6500/cg/mach.c index 3fe8e7e5..bc49938e 100644 --- a/mach/6500/cg/mach.c +++ b/mach/6500/cg/mach.c @@ -17,13 +17,11 @@ con_part(sz,w) register sz; word w; { } con_mult(sz) word sz; { - long l; + long atol(); if (sz != 4) fatal("bad icon/ucon size"); - l = atol(str); - fprintf(codefile,".short\t%d\n",(int) l); - fprintf(codefile,".short\t%d\n",(int) (l >> 16)); + fprintf(codefile,".data4 %ld\n", atol(str)); } @@ -76,8 +74,8 @@ mes(type) word type; { } char *segname[] = { - ".text", /* SEGTXT */ - ".data", /* SEGCON */ - ".data", /* SEGROM */ - ".bss" /* SEGBSS */ + ".sect .text", /* SEGTXT */ + ".sect .data", /* SEGCON */ + ".sect .rom", /* SEGROM */ + ".sect .bss" /* SEGBSS */ }; diff --git a/mach/6500/cg/mach.h b/mach/6500/cg/mach.h index ddc79113..1adf6677 100644 --- a/mach/6500/cg/mach.h +++ b/mach/6500/cg/mach.h @@ -16,11 +16,12 @@ #define hol_off "%d+hol%d" -#define con_cst(x) fprintf(codefile,".word\t%d\n",x) -#define con_ilb(x) fprintf(codefile,".word\t%s\n",x) -#define con_dlb(x) fprintf(codefile,".word\t%s\n",x) +#define con_cst(x) fprintf(codefile,".data2\t%d\n",x) +#define con_ilb(x) fprintf(codefile,".data2\t%s\n",x) +#define con_dlb(x) fprintf(codefile,".data2\t%s\n",x) -#define modhead "" +#define modhead ".sect .zero; .sect .text; .sect .rom; .sect .data; .sect .bss\n" + +#define fmt_id(ft, fs) sprintf(fs,"_%s",ft) -#define id_first '_' #define BSS_INIT 0 From ab6941e0a6077186ffa204f434e48af2ea227c32 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 30 Jan 1987 19:31:26 +0000 Subject: [PATCH 0634/1625] *** empty log message *** --- mach/6500/dl/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mach/6500/dl/Makefile b/mach/6500/dl/Makefile index 198cae5d..6114ad53 100644 --- a/mach/6500/dl/Makefile +++ b/mach/6500/dl/Makefile @@ -1,7 +1,8 @@ -CFLAGS=-O +EMHOME=../../.. +CFLAGS=-O -I$(EMHOME)/h dl: dl.o - cc -o dl -n dl.o + cc -o dl -n dl.o $(EMHOME)/modules/lib/libobject.a install: dl ../../install dl From d5f5cd09aa78cde2a1a9fcb33d768f521133c1d2 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 30 Jan 1987 19:58:55 +0000 Subject: [PATCH 0635/1625] *** empty log message *** --- mach/em22/libbc/Makefile | 3 ++- mach/em22/libbc/compmodule | 6 ++++-- mach/em22/libpc/Makefile | 3 ++- mach/em22/libpc/compmodule | 6 ++++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/mach/em22/libbc/Makefile b/mach/em22/libbc/Makefile index 2a469460..3b9dc3aa 100644 --- a/mach/em22/libbc/Makefile +++ b/mach/em22/libbc/Makefile @@ -1,5 +1,6 @@ +SUF=m MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=int22" "SUF=m" +MACHDEF="MACH=int22" "SUF=$(SUF)" BCDEF="PREF=bc" "SUB=" "SRC=lang/basic/lib" install: diff --git a/mach/em22/libbc/compmodule b/mach/em22/libbc/compmodule index 330b4aef..1c3c2ecf 100755 --- a/mach/em22/libbc/compmodule +++ b/mach/em22/libbc/compmodule @@ -1,2 +1,4 @@ -${MACH?} -I../../../h ${MACHFL?} -LIB $1 1>&2 -echo `basename $1 $2`.m +if ${MACH?} -I../../../h ${MACHFL?} -LIB $1 1>&2 +then echo `basename $1 $2`.m +else exit 1 +fi diff --git a/mach/em22/libpc/Makefile b/mach/em22/libpc/Makefile index e96da058..9258cacd 100644 --- a/mach/em22/libpc/Makefile +++ b/mach/em22/libpc/Makefile @@ -1,5 +1,6 @@ +SUF=m MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=int" "SUF=m" +MACHDEF="MACH=int" "SUF=$(SUF)" PCDEF="PREF=pc" "SUB=" "SRC=lang/pc/libpc" install: diff --git a/mach/em22/libpc/compmodule b/mach/em22/libpc/compmodule index 330b4aef..1c3c2ecf 100755 --- a/mach/em22/libpc/compmodule +++ b/mach/em22/libpc/compmodule @@ -1,2 +1,4 @@ -${MACH?} -I../../../h ${MACHFL?} -LIB $1 1>&2 -echo `basename $1 $2`.m +if ${MACH?} -I../../../h ${MACHFL?} -LIB $1 1>&2 +then echo `basename $1 $2`.m +else exit 1 +fi From 25aa5bf01ce6d1f6ada497a7a0f17b97bfad7a62 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 30 Jan 1987 20:06:04 +0000 Subject: [PATCH 0636/1625] --- mach/em22/libcc/Makefile | 7 ++++--- mach/em22/libcc/compmodule | 6 ++++-- mach/em24/libbc/Makefile | 3 ++- mach/em24/libbc/compmodule | 6 ++++-- mach/em24/libcc/Makefile | 19 ++++++++++--------- mach/em24/libcc/compmodule | 6 ++++-- mach/em24/libpc/Makefile | 3 ++- mach/em24/libpc/compmodule | 6 ++++-- mach/em44/libbc/Makefile | 3 ++- mach/em44/libbc/compmodule | 6 ++++-- mach/em44/libcc/Makefile | 19 ++++++++++--------- mach/em44/libcc/compmodule | 6 ++++-- mach/em44/libpc/Makefile | 3 ++- mach/em44/libpc/compmodule | 6 ++++-- 14 files changed, 60 insertions(+), 39 deletions(-) diff --git a/mach/em22/libcc/Makefile b/mach/em22/libcc/Makefile index 8c5babec..4f231a86 100644 --- a/mach/em22/libcc/Makefile +++ b/mach/em22/libcc/Makefile @@ -1,12 +1,13 @@ +SUF=m MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=int" "SUF=m" +MACHDEF="MACH=int" "SUF=$(SUF)" STDIO="PREF=cc" "SUB=.1s" "SRC=lang/cem/libcc/stdio" GEN="PREF=cc" "SUB=.2g" "SRC=lang/cem/libcc/gen" MON="PREF=mon" "SRC=lang/cem/libcc/mon" LIBM="PREF=m" "SRC=lang/cem/libcc/libm" LIBLN="PREF=ln" "SRC=lang/cem/libcc/libln" -install: cpstdio cpgen cpmon cplibm cplibln +install: cpstdio cpgen cpmon cpstdio: make -f $(MAKEFILE) $(STDIO) $(MACHDEF) tailcp @@ -19,7 +20,7 @@ cplibm: cplibln: make -f $(MAKEFILE) $(LIBLN) $(MACHDEF) tailcp -cmp: cmpstdio cmpgen cmpmon cmplibm cmplibln +cmp: cmpstdio cmpgen cmpmon cmpstdio: make -f $(MAKEFILE) $(STDIO) $(MACHDEF) tail diff --git a/mach/em22/libcc/compmodule b/mach/em22/libcc/compmodule index 330b4aef..1c3c2ecf 100755 --- a/mach/em22/libcc/compmodule +++ b/mach/em22/libcc/compmodule @@ -1,2 +1,4 @@ -${MACH?} -I../../../h ${MACHFL?} -LIB $1 1>&2 -echo `basename $1 $2`.m +if ${MACH?} -I../../../h ${MACHFL?} -LIB $1 1>&2 +then echo `basename $1 $2`.m +else exit 1 +fi diff --git a/mach/em24/libbc/Makefile b/mach/em24/libbc/Makefile index 49e3164d..3b9dc3aa 100644 --- a/mach/em24/libbc/Makefile +++ b/mach/em24/libbc/Makefile @@ -1,5 +1,6 @@ +SUF=m MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=int24" "SUF=m" +MACHDEF="MACH=int22" "SUF=$(SUF)" BCDEF="PREF=bc" "SUB=" "SRC=lang/basic/lib" install: diff --git a/mach/em24/libbc/compmodule b/mach/em24/libbc/compmodule index 330b4aef..1c3c2ecf 100755 --- a/mach/em24/libbc/compmodule +++ b/mach/em24/libbc/compmodule @@ -1,2 +1,4 @@ -${MACH?} -I../../../h ${MACHFL?} -LIB $1 1>&2 -echo `basename $1 $2`.m +if ${MACH?} -I../../../h ${MACHFL?} -LIB $1 1>&2 +then echo `basename $1 $2`.m +else exit 1 +fi diff --git a/mach/em24/libcc/Makefile b/mach/em24/libcc/Makefile index 971906ef..4f231a86 100644 --- a/mach/em24/libcc/Makefile +++ b/mach/em24/libcc/Makefile @@ -1,12 +1,13 @@ +SUF=m MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=int24" "SUF=m" +MACHDEF="MACH=int" "SUF=$(SUF)" STDIO="PREF=cc" "SUB=.1s" "SRC=lang/cem/libcc/stdio" GEN="PREF=cc" "SUB=.2g" "SRC=lang/cem/libcc/gen" MON="PREF=mon" "SRC=lang/cem/libcc/mon" LIBM="PREF=m" "SRC=lang/cem/libcc/libm" LIBLN="PREF=ln" "SRC=lang/cem/libcc/libln" -install: cpstdio cpgen cpmon cplibm cplibln +install: cpstdio cpgen cpmon cpstdio: make -f $(MAKEFILE) $(STDIO) $(MACHDEF) tailcp @@ -19,25 +20,25 @@ cplibm: cplibln: make -f $(MAKEFILE) $(LIBLN) $(MACHDEF) tailcp -cmp: cmpstdio cmpgen cmpmon cmplibm cmplibln +cmp: cmpstdio cmpgen cmpmon cmpstdio: make -f $(MAKEFILE) $(STDIO) $(MACHDEF) tail - -../../compare tail_cc.1s + -../../compare tail_cc.1s cmpgen: make -f $(MAKEFILE) $(GEN) $(MACHDEF) head - -../../compare head_cc + -../../compare head_cc make -f $(MAKEFILE) $(GEN) $(MACHDEF) tail - -../../compare tail_cc.2g + -../../compare tail_cc.2g cmpmon: make -f $(MAKEFILE) $(MON) $(MACHDEF) tail - -../../compare tail_mon + -../../compare tail_mon cmplibm: make -f $(MAKEFILE) $(LIBM) $(MACHDEF) tail - -../../compare tail_m + -../../compare tail_m cmplibln: make -f $(MAKEFILE) $(LIBLN) $(MACHDEF) tail - -../../compare tail_ln + -../../compare tail_ln clean: -rm -f *.old *.[ce$(SUF)] tail* head* diff --git a/mach/em24/libcc/compmodule b/mach/em24/libcc/compmodule index 330b4aef..1c3c2ecf 100755 --- a/mach/em24/libcc/compmodule +++ b/mach/em24/libcc/compmodule @@ -1,2 +1,4 @@ -${MACH?} -I../../../h ${MACHFL?} -LIB $1 1>&2 -echo `basename $1 $2`.m +if ${MACH?} -I../../../h ${MACHFL?} -LIB $1 1>&2 +then echo `basename $1 $2`.m +else exit 1 +fi diff --git a/mach/em24/libpc/Makefile b/mach/em24/libpc/Makefile index 79770926..9258cacd 100644 --- a/mach/em24/libpc/Makefile +++ b/mach/em24/libpc/Makefile @@ -1,5 +1,6 @@ +SUF=m MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=int24" "SUF=m" +MACHDEF="MACH=int" "SUF=$(SUF)" PCDEF="PREF=pc" "SUB=" "SRC=lang/pc/libpc" install: diff --git a/mach/em24/libpc/compmodule b/mach/em24/libpc/compmodule index 330b4aef..1c3c2ecf 100755 --- a/mach/em24/libpc/compmodule +++ b/mach/em24/libpc/compmodule @@ -1,2 +1,4 @@ -${MACH?} -I../../../h ${MACHFL?} -LIB $1 1>&2 -echo `basename $1 $2`.m +if ${MACH?} -I../../../h ${MACHFL?} -LIB $1 1>&2 +then echo `basename $1 $2`.m +else exit 1 +fi diff --git a/mach/em44/libbc/Makefile b/mach/em44/libbc/Makefile index 4dc2b3ac..3b9dc3aa 100644 --- a/mach/em44/libbc/Makefile +++ b/mach/em44/libbc/Makefile @@ -1,5 +1,6 @@ +SUF=m MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=int44" "SUF=m" +MACHDEF="MACH=int22" "SUF=$(SUF)" BCDEF="PREF=bc" "SUB=" "SRC=lang/basic/lib" install: diff --git a/mach/em44/libbc/compmodule b/mach/em44/libbc/compmodule index 330b4aef..1c3c2ecf 100755 --- a/mach/em44/libbc/compmodule +++ b/mach/em44/libbc/compmodule @@ -1,2 +1,4 @@ -${MACH?} -I../../../h ${MACHFL?} -LIB $1 1>&2 -echo `basename $1 $2`.m +if ${MACH?} -I../../../h ${MACHFL?} -LIB $1 1>&2 +then echo `basename $1 $2`.m +else exit 1 +fi diff --git a/mach/em44/libcc/Makefile b/mach/em44/libcc/Makefile index 9f0eb0f0..4f231a86 100644 --- a/mach/em44/libcc/Makefile +++ b/mach/em44/libcc/Makefile @@ -1,12 +1,13 @@ +SUF=m MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=int44" "SUF=m" +MACHDEF="MACH=int" "SUF=$(SUF)" STDIO="PREF=cc" "SUB=.1s" "SRC=lang/cem/libcc/stdio" GEN="PREF=cc" "SUB=.2g" "SRC=lang/cem/libcc/gen" MON="PREF=mon" "SRC=lang/cem/libcc/mon" LIBM="PREF=m" "SRC=lang/cem/libcc/libm" LIBLN="PREF=ln" "SRC=lang/cem/libcc/libln" -install: cpstdio cpgen cpmon cplibm cplibln cpmon +install: cpstdio cpgen cpmon cpstdio: make -f $(MAKEFILE) $(STDIO) $(MACHDEF) tailcp @@ -19,25 +20,25 @@ cplibm: cplibln: make -f $(MAKEFILE) $(LIBLN) $(MACHDEF) tailcp -cmp: cmpstdio cmpgen cmpmon cmplibm cmplibln +cmp: cmpstdio cmpgen cmpmon cmpstdio: make -f $(MAKEFILE) $(STDIO) $(MACHDEF) tail - -../../compare tail_cc.1s + -../../compare tail_cc.1s cmpgen: make -f $(MAKEFILE) $(GEN) $(MACHDEF) head - -../../compare head_cc + -../../compare head_cc make -f $(MAKEFILE) $(GEN) $(MACHDEF) tail - -../../compare tail_cc.2g + -../../compare tail_cc.2g cmpmon: make -f $(MAKEFILE) $(MON) $(MACHDEF) tail - -../../compare tail_mon + -../../compare tail_mon cmplibm: make -f $(MAKEFILE) $(LIBM) $(MACHDEF) tail - -../../compare tail_m + -../../compare tail_m cmplibln: make -f $(MAKEFILE) $(LIBLN) $(MACHDEF) tail - -../../compare tail_ln + -../../compare tail_ln clean: -rm -f *.old *.[ce$(SUF)] tail* head* diff --git a/mach/em44/libcc/compmodule b/mach/em44/libcc/compmodule index 330b4aef..1c3c2ecf 100755 --- a/mach/em44/libcc/compmodule +++ b/mach/em44/libcc/compmodule @@ -1,2 +1,4 @@ -${MACH?} -I../../../h ${MACHFL?} -LIB $1 1>&2 -echo `basename $1 $2`.m +if ${MACH?} -I../../../h ${MACHFL?} -LIB $1 1>&2 +then echo `basename $1 $2`.m +else exit 1 +fi diff --git a/mach/em44/libpc/Makefile b/mach/em44/libpc/Makefile index e9ad8f68..9258cacd 100644 --- a/mach/em44/libpc/Makefile +++ b/mach/em44/libpc/Makefile @@ -1,5 +1,6 @@ +SUF=m MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=int44" "SUF=m" +MACHDEF="MACH=int" "SUF=$(SUF)" PCDEF="PREF=pc" "SUB=" "SRC=lang/pc/libpc" install: diff --git a/mach/em44/libpc/compmodule b/mach/em44/libpc/compmodule index 330b4aef..1c3c2ecf 100755 --- a/mach/em44/libpc/compmodule +++ b/mach/em44/libpc/compmodule @@ -1,2 +1,4 @@ -${MACH?} -I../../../h ${MACHFL?} -LIB $1 1>&2 -echo `basename $1 $2`.m +if ${MACH?} -I../../../h ${MACHFL?} -LIB $1 1>&2 +then echo `basename $1 $2`.m +else exit 1 +fi From ba65fda5fbc9fc1f3e508e1298f70b3aa888d9a2 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 30 Jan 1987 20:22:52 +0000 Subject: [PATCH 0637/1625] Name change of lib, added head_em --- mach/m68k2/libsys/Makefile | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/mach/m68k2/libsys/Makefile b/mach/m68k2/libsys/Makefile index b3cdc928..e1c963e7 100644 --- a/mach/m68k2/libsys/Makefile +++ b/mach/m68k2/libsys/Makefile @@ -1,21 +1,25 @@ # $Header$ MACH=m68k2 -all: tail_mon +all: libmon_o.a head_em.o + install: all - ../../install tail_mon + ../../install head_em.o head_em + ../../install libmon_o.a tail_mon cmp: all - -../../compare tail_mon + -../../compare head_em.o head_em + -../../compare libmon_o.a tail_mon -tail_mon: +libmon_o.a: libmon_s.a ASAR=aal ; export ASAR ;\ - march . tail_mon + march . libmon_o.a clean: - rm -f *.o + rm -f *.o libmon_o.a opr : make pr | opr pr: - @ar pv tail_mon.a + @pr `pwd`/head_em.s + @arch pv libmon_s.a | pr -h `pwd`/libmon_s.a From 6f5ff0c73b0398faf02fb3d3f3d2bc8c7ba026e0 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 30 Jan 1987 20:23:09 +0000 Subject: [PATCH 0638/1625] name change of lib --- mach/m68k2/libsys/LIST | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/m68k2/libsys/LIST b/mach/m68k2/libsys/LIST index 6bc9b935..35320342 100644 --- a/mach/m68k2/libsys/LIST +++ b/mach/m68k2/libsys/LIST @@ -1,4 +1,4 @@ -tail_mon.a +libmon_s.a exit.s _exit.s access.s From cafba4739062b88d6064f4d67e4ca4824b209108 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 30 Jan 1987 20:24:35 +0000 Subject: [PATCH 0639/1625] machine name change: l68k2 --> m68k2 --- mach/m68k2/libsys/compmodule | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/m68k2/libsys/compmodule b/mach/m68k2/libsys/compmodule index 2949d131..02105f21 100755 --- a/mach/m68k2/libsys/compmodule +++ b/mach/m68k2/libsys/compmodule @@ -1,4 +1,4 @@ -if l68k2 -c $1 1>&2 +if m68k2 -c $1 1>&2 then echo `basename $1 $2`.o else exit 1 fi From 8d7c0ed0908976fef81e08f45c89ef04e6d0ec97 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 30 Jan 1987 20:27:28 +0000 Subject: [PATCH 0640/1625] *** empty log message *** --- mach/m68k2/libem/Makefile | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/mach/m68k2/libem/Makefile b/mach/m68k2/libem/Makefile index 15239122..852e18a0 100644 --- a/mach/m68k2/libem/Makefile +++ b/mach/m68k2/libem/Makefile @@ -1,33 +1,28 @@ # $Header$ MACH=m68k2 +all: libem_o.a end.o + install: all - ../../install head_em.o head_em - ../../install libem_o.a tail_em.rt + ../../install libem_o.a tail_em ../../install end.o end_em cmp: all - -../../compare head_em.o head_em - -../../compare libem_o.a tail_em.rt + -../../compare libem_o.a tail_em -../../compare end.o end_em -all: head_em.o libem_o.a end.o - end.o: end.s $(MACH) -I../../../h -c end.s -head_em.o: head_em.s - $(MACH) -I../../../h -c head_em.s - libem_o.a: libem_s.a ASAR=aal ; export ASAR ;\ march . libem_o.a clean: - rm -f *.o + rm -f *.o libmon_o.a + opr : make pr | opr pr: - @pr `pwd`/head_em.s @arch pv libem_s.a | pr -h `pwd`/libem_s.a @pr `pwd`/end.s From 85096c0c1755f84a8d4957961ebd0c199029f8aa Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 30 Jan 1987 20:39:45 +0000 Subject: [PATCH 0641/1625] *** empty log message *** --- mach/z8000/libbc/Makefile | 3 ++- mach/z8000/libcc/Makefile | 3 ++- mach/z8000/libpc/Makefile | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/mach/z8000/libbc/Makefile b/mach/z8000/libbc/Makefile index ef381a1c..acb32f20 100644 --- a/mach/z8000/libbc/Makefile +++ b/mach/z8000/libbc/Makefile @@ -1,5 +1,6 @@ +SUF=s MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=z8000" "SUF=s" +MACHDEF="MACH=z8000" "SUF=$(SUF)" BCDEF="PREF=bc" "SUB=" "SRC=lang/basic/lib" install: diff --git a/mach/z8000/libcc/Makefile b/mach/z8000/libcc/Makefile index 8004e86b..04e48c74 100644 --- a/mach/z8000/libcc/Makefile +++ b/mach/z8000/libcc/Makefile @@ -1,5 +1,6 @@ +SUF=s MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=z8000" "SUF=s" +MACHDEF="MACH=z8000" "SUF=$(SUF)" STDIO="PREF=cc" "SUB=.1s" "SRC=lang/cem/libcc/stdio" GEN="PREF=cc" "SUB=.2g" "SRC=lang/cem/libcc/gen" MON="PREF=mon" "SRC=lang/cem/libcc/mon" diff --git a/mach/z8000/libpc/Makefile b/mach/z8000/libpc/Makefile index 345d2294..f99b28c3 100644 --- a/mach/z8000/libpc/Makefile +++ b/mach/z8000/libpc/Makefile @@ -1,5 +1,6 @@ +SUF=s MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=z8000" "SUF=s" +MACHDEF="MACH=z8000" "SUF=$(SUF)" PCDEF="PREF=pc" "SUB=" "SRC=lang/pc/libpc" install: From 9a9cdb33f7f864a254ea62447ffba403c6eb842d Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 30 Jan 1987 20:48:31 +0000 Subject: [PATCH 0642/1625] New version --- mach/pmds/cv/cv.c | 288 +++++++++++++++++++++++++++------------------- 1 file changed, 170 insertions(+), 118 deletions(-) diff --git a/mach/pmds/cv/cv.c b/mach/pmds/cv/cv.c index 043f1d71..2f32f16c 100644 --- a/mach/pmds/cv/cv.c +++ b/mach/pmds/cv/cv.c @@ -15,145 +15,161 @@ * */ -char rcs_id[] = "$Header$" ; - /* - * The assumption is that this program is run on the same machine the - * assembler has run. So the assembler's idea of long fits cv's idea. - * The long's produced in the output file have the m68000 format. - * The idea's of the longs read in can be changed with the following - * flags: - * -v Vax longs - * -p Pdp 11 longs - * -m M68000 longs + * Fortunately we sold our PMDS machine. Unfortunately, we also sold the + * documentation that came with it, so I don't know the a.out format + * of the machine. This program is written partly by guessing, and partly from + * an older conversion program for the PMDS, which put the whole program + * in data. The produced object file does not contain a namelist. */ #include +#include -char * prog ; +#define ASSERT(x) switch (2) { case 0: case (x): ; } + +/* + * Header and section table of new format object file. + */ +struct outhead outhead; +struct outsect outsect[S_MAX]; + +char *output_file; +int outputfile_created; + +int rom_in_data; + +char *program ; char flag ; -#define HDR_LENGTH 40 +#define writef(a, b, c) fwrite((a), (b), (int)(c), output) -char hdr[HDR_LENGTH] ; +/* Output file definitions and such */ -main(argc,argv) char **argv; { - long addr,maxaddr; - short count; - - maxaddr=0; + +#define ENTRY 0 +#define HDRSIZE 40 + +char hdr[HDRSIZE]; + + +#define TEXTSG 0 +#define ROMSG 1 +#define DATASG 2 +#define BSSSG 3 +#define LSECT BSSSG+1 +#define NSECT LSECT+1 + +FILE *output; + +main(argc, argv) + int argc; + char *argv[]; +{ + register int nsect; + long magic ; + long textsize ; + long datasize ; + long bsssize; + long symstart; + extern long ftell(); + + output = stdout; + program= argv[0] ; if ( argc>1 && argv[1][0]=='-' ) { flag=argv[1][1] ; argc-- ; argv++ ; } - if (argc != 3) { - fprintf(stderr,"Usage: %s [-[vpm]] VU-a.out pmds-a.out\n",argv[0]); - exit(-1); + switch (argc) { + case 3: if ((output = fopen(argv[2], "w")) == (FILE *)0) + fatal("Can't write %s.\n", argv[2]); + output_file = argv[2]; + outputfile_created = 1; + if (! rd_open(argv[1])) + fatal("Can't read %s.\n", argv[1]); + break; + default:fatal("Usage: %s .\n", argv[0]); } - prog=argv[0] ; - if (freopen(argv[1],"r",stdin)==NULL) { - fprintf(stderr,"%s: ",prog) ; - perror(argv[1]); - exit(-1); + rd_ohead(&outhead); + if (BADMAGIC(outhead)) + fatal("Not an ack object file.\n"); + if (outhead.oh_flags & HF_LINK) + fatal("Contains unresolved references.\n"); + if (outhead.oh_nrelo > 0) + fprintf(stderr, "Warning: relocation information present.\n"); + if ( outhead.oh_nsect!=LSECT && outhead.oh_nsect!=NSECT ) + fatal("Input file must have %d sections, not %ld\n", + NSECT,outhead.oh_nsect) ; + rd_sect(outsect, outhead.oh_nsect); + /* A few checks */ + if ( outsect[TEXTSG].os_base != ENTRY) + fatal("text must start at %d not at 0x%lx\n", ENTRY, + outsect[TEXTSG].os_base) ; + if ( outsect[BSSSG].os_flen != 0 ) + fatal("bss space contains initialized data\n") ; + if ( outsect[BSSSG].os_base != outsect[DATASG].os_base+ + outsect[DATASG].os_size ) + fatal("bss segment must follow data segment\n") ; + if ( outsect[ROMSG].os_lign == 0x8000 ) { + /* 410 file with ROMSG in data space */ + rom_in_data = 1; + magic= 0410 ; + textsize= outsect[TEXTSG].os_size ; + datasize= outsect[ROMSG].os_size + outsect[DATASG].os_size ; + if ( outsect[DATASG].os_base != outsect[ROMSG].os_base+ + outsect[ROMSG].os_size ) + fatal("data segment must follow rom\n") ; + } else + if ( outsect[DATASG].os_lign == 0x8000 ) { + /* 410 file with ROMSG in instruction space */ + rom_in_data = 0; + magic= 0410 ; + textsize= outsect[TEXTSG].os_size + outsect[ROMSG].os_size ; + datasize= outsect[DATASG].os_size ; + if ( outsect[ROMSG].os_base != outsect[TEXTSG].os_base+ + outsect[TEXTSG].os_size ) + fatal("rom segment must follow text\n") ; + } else { + /* Plain 407 file */ + rom_in_data = 1; + magic= 0407 ; + textsize= outsect[TEXTSG].os_size ; + datasize= outsect[ROMSG].os_size + outsect[DATASG].os_size ; + if ( outsect[ROMSG].os_base != outsect[TEXTSG].os_base+ + outsect[TEXTSG].os_size ) + fatal("rom segment must follow text\n") ; + if ( outsect[DATASG].os_base != outsect[ROMSG].os_base+ + outsect[ROMSG].os_size ) + fatal("data segment must follow rom\n") ; } - if (freopen(argv[2],"w",stdout)==NULL) { - fprintf(stderr,"%s: ",prog) ; - perror(argv[2]); - exit(-1); + bsssize = outsect[BSSSG].os_size; + if ( outhead.oh_nsect==NSECT ) { + if ( outsect[LSECT].os_base != outsect[BSSSG].os_base+ + outsect[BSSSG].os_size ) + fatal("end segment must follow bss\n") ; + if ( outsect[LSECT].os_size != 0 ) + fatal("end segment must be empty\n") ; } - while ( getaddr(&addr) && getcnt(&count) ) { - fseek(stdout,addr+HDR_LENGTH,0); - while (count--) { - putchar(getchar()); - if ( ferror(stdout) ) { - fprintf(stderr,"%s: write error\n",prog) ; - unlink(argv[2]) ; /* remove the output */ - exit(2) ; - } - addr++; - } - if (addr>maxaddr) - maxaddr = addr; + + /* Action at last */ + fseek(output,(long) HDRSIZE,0); + emits(&outsect[TEXTSG]) ; + emits(&outsect[ROMSG]) ; + emits(&outsect[DATASG]) ; + fseek(output,0L,0); + sethdr(0, (long) magic); + sethdr(4, textsize); + sethdr(8, datasize); + sethdr(12, bsssize); + writef(hdr, 1, 40); + if ( ferror(output) ) { + fatal("output write error\n") ; } - sethdr(0,0410L) ; /* Magic */ - sethdr(8,maxaddr) ; - fseek(stdout,0L,0); - fwrite(hdr,sizeof(hdr),1,stdout); - if ( ferror(stdout) ) { - fprintf(stderr,"%s: write error\n",prog) ; - unlink(argv[2]) ; /* remove the output */ - exit(2) ; - } - chmod(argv[2],0755); + if ( outputfile_created ) chmod(argv[2],0755); return 0; } -getaddr(p_addr) long *p_addr ; { - char in[4] ; - short out[4] ; - int i ; - - switch ( fread(in,1,4,stdin) ) { - case 0 : return 0 ; - case 4 : break ;; - default : fprintf(stderr,"%s: Illegal input format\n",prog) ; - return 0 ; - } - switch ( flag ) { - case 0 : *p_addr = *((long *)in) ; - return 1 ; - case 'v' : - out[0]=in[0] ; out[1]=in[1] ; - out[2]=in[2] ; out[3]=in[3] ; - break ; - case 'm' : - out[0]=in[3] ; out[1]=in[2] ; - out[2]=in[1] ; out[3]=in[0] ; - break ; - case 'p' : - out[0]=in[2] ; out[1]=in[3] ; - out[2]=in[0] ; out[3]=in[1] ; - break ; - default : - fprintf(stderr,"%s: Unknown conversion %c(%o)\n", - prog,flag,flag) ; - exit(-1) ; - } - for ( i=0 ; i<4 ; i++ ) out[i] &= 0xFF ; - *p_addr = 256 * ( 256 * ( 256 * out[3] + out[2] ) + out[1] ) + out[0]; - return 1 ; -} - -getcnt(p_cnt) short *p_cnt ; { - char in[2] ; - short out[2] ; - int i ; - - switch ( fread(in,1,2,stdin) ) { - case 2 : break ;; - default : fprintf(stderr,"%s: Illegal input format\n",prog) ; - return 0 ; - } - switch ( flag ) { - case 0 : *p_cnt = *((short *)in) ; - return 1 ; - case 'v' : - case 'p' : - out[0]=in[0] ; out[1]=in[1] ; - break ; - case 'm' : - out[0]=in[1] ; out[1]=in[0] ; - break ; - default : - fprintf(stderr,"%s: Unknown conversion %c(%o)\n", - prog,flag,flag) ; - exit(-1) ; - } - for ( i=0 ; i<2 ; i++ ) out[i] &= 0xFF ; - *p_cnt = 256 * out[1] + out[0] ; - return 1 ; -} sethdr(off,val) long val ; { hdr[off] = val>>24 ; @@ -161,3 +177,39 @@ sethdr(off,val) long val ; { hdr[off+2] = val>>8 ; hdr[off+3] = val ; } + +/* + * Transfer the emitted byted from one file to another. + */ +emits(section) struct outsect *section ; { + char *p; + char *calloc(); + long length = section->os_size; + + rd_outsect(section - outsect); + while (section->os_size > 0) { + int i = section->os_size > 10*1024 ? 10*1024 : section->os_size; + + section->os_size -= i; + if (!(p = calloc(i, 1))) { + fatal("No memory.\n"); + } + rd_emit(p, i >= section->os_flen ? section->os_flen:(long) i); + section->os_flen -= i; + writef(p, 1, i); + free(p); + } +} + +/* VARARGS1 */ +fatal(s, a1, a2) + char *s; +{ + fprintf(stderr,"%s: ",program) ; + fprintf(stderr, s, a1, a2); + if (outputfile_created) + unlink(output_file); + exit(-1); +} + +rd_fatal() { fatal("read error.\n"); } From bb9d6b4330ecce5af0cd50d7c184e756ce4a1c58 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 30 Jan 1987 20:50:31 +0000 Subject: [PATCH 0643/1625] *** empty log message *** --- mach/pmds/Action | 8 ++++---- mach/pmds/cv/Makefile | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/mach/pmds/Action b/mach/pmds/Action index 42ad4725..e4c3625c 100644 --- a/mach/pmds/Action +++ b/mach/pmds/Action @@ -1,6 +1,6 @@ -name "PMDS download program(s)" -dir dl +name "Ack.out --> PMDS a.out format conversion program" +dir cv end -name "PMDS EM library" -dir libem +name "PMDS systemcall library" +dir libsys end diff --git a/mach/pmds/cv/Makefile b/mach/pmds/cv/Makefile index cc289a19..421009a7 100644 --- a/mach/pmds/cv/Makefile +++ b/mach/pmds/cv/Makefile @@ -1,7 +1,9 @@ -CFLAGS=-O +EMHOME=../../.. + +CFLAGS=-O -I$(EMHOME)/h cv: cv.o - $(CC) -o cv -n cv.o + $(CC) -o cv -n cv.o $(EMHOME)/modules/lib/libobject.a install: cv ../../install cv From e70f81cd4497a31a783b6596f27eebc2bdfa9627 Mon Sep 17 00:00:00 2001 From: ceriel Date: Sun, 1 Feb 1987 21:04:49 +0000 Subject: [PATCH 0644/1625] Initial revision --- mach/m68020/cv/Makefile | 21 ++++ mach/m68020/cv/cv.c | 273 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 294 insertions(+) create mode 100644 mach/m68020/cv/Makefile create mode 100644 mach/m68020/cv/cv.c diff --git a/mach/m68020/cv/Makefile b/mach/m68020/cv/Makefile new file mode 100644 index 00000000..d3203806 --- /dev/null +++ b/mach/m68020/cv/Makefile @@ -0,0 +1,21 @@ +CFLAGS=-O -I../../../h + +cv: cv.o + $(CC) -o cv -n cv.o + +install: ins_cv +ins_cv: cv + ../../install cv + +cmp: cmp_cv +cmp_cv: cv + -../../compare cv + +opr: + make pr | opr + +pr: + @pr `pwd`/cv.c + +clean: + -rm -f *.o *.old cv diff --git a/mach/m68020/cv/cv.c b/mach/m68020/cv/cv.c new file mode 100644 index 00000000..ccf1ccf2 --- /dev/null +++ b/mach/m68020/cv/cv.c @@ -0,0 +1,273 @@ +/* This is a special cv.c program for testing purposes ; + * it converts to a stripped version of COFF + */ + +#include +#include +#include +#include +#include +#define AOUTHSZ sizeof(AOUTHDR) + +#define ASSERT(x) switch (2) { case 0: case (x): ; } + +/* + * Header and section table of new format object file. + */ +struct outhead outhead; +struct outsect outsect[S_MAX]; + +char *output_file; +int outputfile_created; + +int rom_in_data; + +char *program ; + +char flag ; + +#define readf(a, b, c) fread((a), (b), (int)(c), input) +#define writef(a, b, c) fwrite((a), (b), (int)(c), output) + +/* Output file definitions and such */ + +#define TS 0 +#define DS 1 +#define BS 2 +#define NS 3 + +FILHDR filh; +AOUTHDR aouth; +SCNHDR scnh[NS]; + +#define ENTRY 0 +#define MC68MAGIC 0520 +#define MYFLAGS 01017 + +#define STYP_TEXT 0x20 +#define STYP_DATA 0x40 +#define STYP_BSS 0x80 + + +#define TEXTSG 0 +#define ROMSG 1 +#define DATASG 2 +#define BSSSG 3 +#define LSECT BSSSG+1 +#define NSECT LSECT+1 + + +FILE *input; +FILE *output; + +main(argc, argv) + int argc; + char *argv[]; +{ + register int nsect; + long magic ; + long textsize, datasize, bsssize; + extern long ftell(); + long filepos; + int scn; + + ASSERT(sizeof(struct outhead) == SZ_HEAD); + ASSERT(sizeof(struct outsect) == SZ_SECT); + + input = stdin; output = stdout; + program= argv[0] ; + if ( argc>1 && argv[1][0]=='-' ) { + flag=argv[1][1] ; + argc-- ; argv++ ; + } + switch (argc) { + case 1: break; + case 3: if ((output = fopen(argv[2], "w")) == (FILE *)0) + fatal("Can't write %s.\n", argv[2]); + output_file = argv[2]; + outputfile_created = 1; + /* FALLTHROUGH */ + case 2: if ((input = fopen(argv[1], "r")) == (FILE *)0) + fatal("Can't read %s.\n", argv[1]); + break; + default:fatal("Usage: %s
.\n", argv[0]); + } + if ( !rhead(input,&outhead) ) + fatal("Reading header failed.\n"); + if (BADMAGIC(outhead)) + fatal("Not an ack object file.\n"); + if (outhead.oh_nrelo > 0) + fprintf(stderr, "Warning: relocation information present.\n"); + if ( outhead.oh_nsect!=LSECT && outhead.oh_nsect!=NSECT ) + fatal("Input file must have %d sections, not %ld\n", + NSECT,outhead.oh_nsect) ; + for ( nsect=0 ; nsectos_flen ; + while (n > 0) { + blk = n > BUFSIZ ? BUFSIZ : n; + readf(buffer, 1, blk); + writef(buffer, 1, blk); + n -= blk; + } + if ((n=section->os_size - section->os_flen) > 0) { + fseek(output, n-1, 1); + writef("\0",1,1); + } +} + + +rhead(f,head) struct outhead *head ; FILE *f ; { + char buf[SZ_HEAD] ; + if ( fread(buf,SZ_HEAD,1,f)!=1 ) return 0 ; + iconvert(buf,(char *)head,SF_HEAD) ; + return 1 ; +} + +rsect(f,sect) struct outsect *sect ; FILE *f ; { + char buf[SZ_SECT] ; + if ( fread(buf,SZ_SECT,1,f)!=1 ) return 0 ; + iconvert(buf,(char *)sect,SF_SECT) ; + return 1 ; +} + + +iconvert(buf,str,fmt) char *buf, *str, *fmt ; { + register char *nf, *ni, *no ; + int last, i ; + long value ; + ni=buf ; no=str ; nf=fmt ; + while ( last = *nf++ ) { + last -= '0' ; + if ( last<1 || last >9 ) fatal("illegal out.h format string\n"); + value=0 ; + i=last ; + while ( i-- ) { + value = (value<<8) + (ni[i]&0xFF) ; + } + switch ( last ) { + case 0 : break ; + case 1 : *no= value ; break ; + case 2 : *(unsigned short *)no = value ; break ; + case 4 : *(long *)no = value ; break ; + default : + fatal("illegal out.h format string\n"); + } + ni += last ; no += last ; + } +} + + +/* VARARGS1 */ +fatal(s, a1, a2) + char *s; +{ + fprintf(stderr,"%s: ",program) ; + fprintf(stderr, s, a1, a2); + if (outputfile_created) + unlink(output_file); + exit(-1); +} From c1178591ac19517869c2bdd06aa6643edfcd9b0b Mon Sep 17 00:00:00 2001 From: ceriel Date: Sun, 1 Feb 1987 21:27:52 +0000 Subject: [PATCH 0645/1625] *** empty log message *** --- mach/m68k2/libbc/Makefile | 5 +++-- mach/m68k2/libcc/Makefile | 5 +++-- mach/m68k2/libem/Makefile | 2 +- mach/m68k2/libpc/Makefile | 5 +++-- mach/m68k2/libsys/Makefile | 3 +++ 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/mach/m68k2/libbc/Makefile b/mach/m68k2/libbc/Makefile index 9f9c5c02..0a834976 100644 --- a/mach/m68k2/libbc/Makefile +++ b/mach/m68k2/libbc/Makefile @@ -1,5 +1,6 @@ +SUF=o MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=m68k2" "SUF=o" "ASAR=aal" +MACHDEF="MACH=m68k2" "SUF=$(SUF)" "ASAR=aal" BCDEF="PREF=bc" "SUB=" "SRC=lang/basic/lib" install: @@ -11,7 +12,7 @@ cmp: -../../compare tail_bc clean: - -rm -f *.old *.[ceo] tail* head* + -rm -f *.old *.[ce$(SUF)] tail* head* opr: make pr | opr diff --git a/mach/m68k2/libcc/Makefile b/mach/m68k2/libcc/Makefile index b260f410..7ed3ea56 100644 --- a/mach/m68k2/libcc/Makefile +++ b/mach/m68k2/libcc/Makefile @@ -1,5 +1,6 @@ +SUF=o MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=m68k2 -DNOFLOAT" "SUF=o" "ASAR=aal" +MACHDEF="MACH=m68k2" "SUF=$(SUF)" "ASAR=aal" STDIO="PREF=cc" "SUB=.1s" "SRC=lang/cem/libcc/stdio" GEN="PREF=cc" "SUB=.2g" "SRC=lang/cem/libcc/gen" MON="PREF=mon" "SRC=lang/cem/libcc/mon" @@ -13,7 +14,7 @@ cpgen: cpmon: make -f $(MAKEFILE) $(MON) $(MACHDEF) tailcp -cmp: cmpstdio cmpgen cmpmon +cmp: cmpstdio cmpgen cmpstdio: make -f $(MAKEFILE) $(STDIO) $(MACHDEF) tail diff --git a/mach/m68k2/libem/Makefile b/mach/m68k2/libem/Makefile index 852e18a0..3b6cf538 100644 --- a/mach/m68k2/libem/Makefile +++ b/mach/m68k2/libem/Makefile @@ -18,7 +18,7 @@ libem_o.a: libem_s.a march . libem_o.a clean: - rm -f *.o libmon_o.a + rm -f *.o libem_o.a opr : make pr | opr diff --git a/mach/m68k2/libpc/Makefile b/mach/m68k2/libpc/Makefile index b1525ce9..9a63cb54 100644 --- a/mach/m68k2/libpc/Makefile +++ b/mach/m68k2/libpc/Makefile @@ -1,5 +1,6 @@ +SUF=o MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=m68k2" "SUF=o" "ASAR=aal" +MACHDEF="MACH=m68k2" "SUF=$(SUF)" "ASAR=aal" PCDEF="PREF=pc" "SUB=" "SRC=lang/pc/libpc" install: @@ -11,7 +12,7 @@ cmp: -../../compare tail_pc clean: - -rm -f *.old *.[ceo] tail* head* + -rm -f *.old *.[ce$(SUF)] tail* head* opr: make pr | opr diff --git a/mach/m68k2/libsys/Makefile b/mach/m68k2/libsys/Makefile index e1c963e7..1caeccd0 100644 --- a/mach/m68k2/libsys/Makefile +++ b/mach/m68k2/libsys/Makefile @@ -14,6 +14,9 @@ libmon_o.a: libmon_s.a ASAR=aal ; export ASAR ;\ march . libmon_o.a +head_em.o: head_em.s + $(MACH) -c -I../../../h head_em.s + clean: rm -f *.o libmon_o.a From ccffd75a01a06014fb60fef3d25432740812ca5e Mon Sep 17 00:00:00 2001 From: ceriel Date: Sun, 1 Feb 1987 21:53:24 +0000 Subject: [PATCH 0646/1625] Initial revision --- mach/m68k2/cg/fppsim.h | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 mach/m68k2/cg/fppsim.h diff --git a/mach/m68k2/cg/fppsim.h b/mach/m68k2/cg/fppsim.h new file mode 100644 index 00000000..c41cebf4 --- /dev/null +++ b/mach/m68k2/cg/fppsim.h @@ -0,0 +1,2 @@ +/* #define FPPSIM /* define when using fpp simulator */ +/* #define IEEEFLOAT /* define if it must use IEEE format */ From 675ca71cc780f02cac79cb4076945c0ade513d32 Mon Sep 17 00:00:00 2001 From: ceriel Date: Sun, 1 Feb 1987 22:13:26 +0000 Subject: [PATCH 0647/1625] Adapted to current situation --- mach/m68k2/README | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/mach/m68k2/README b/mach/m68k2/README index 18d5c6e2..777f929d 100644 --- a/mach/m68k2/README +++ b/mach/m68k2/README @@ -4,11 +4,9 @@ and a pointer to be 32 bits. At present it does not support floating point operations. (All EM floating point instructions are translated to the 68000 "trap" instruction.) -The m68k2 back end generates code for the ACK 68000 assembler/linker. +The m68k2 back end generates code for the ACK 68000 assembler. (The mnemonics recognized by this assembler can be found in -"as/mach3.c"). As this assembler/linker does not define an -object (.o) format, it can only link assembly files. Consequently, -all library modules are stored as assembly files. +"as/mach3.c"). Some parts of the back end are system dependent, i.e. they depend on the kind of target 68000 system. @@ -27,13 +25,12 @@ on the kind of target 68000 system. problem. E.g. UniSoft Unix requires a "tst.b N(sp)" instruction This instruction is generated by the routines "prolog()" and "save" in "cg/mach.c". - - The output of the ACK 68000 assembler/linker is an a.out file that + - The output of the ACK 68000 linker is an a.out file that has a different format as an a.out file on your system. (As most 68000 systems have different a.out formats, there is no such thing as "the" 68000 a.out format). So a program is needed to convert the - ACK a.out format (i.e. a series of "emitrecs" as defined in - "as/frame.c") to your a.out format (as defined in - "/usr/include/a.out.h"). The 1-page program "dl/cv.c" does + ACK a.out format to your a.out format (as defined in + "/usr/include/a.out.h"). The program "cv/cv.c" does the job for UniSoft Unix. It probably need only be slightly modified for your system. Note that the program generates no text or bss segments, but only a data segment. @@ -41,14 +38,12 @@ on the kind of target 68000 system. 68000, you will need a program to download the ACK a.out file. The program "dl/dl.c" produces Intel Hex format on standard output from an a.out file. - - The EM runtime start-off ("libem/head_em.s") may have to be modified. + - The EM runtime start-off ("libsys/head_em.s") may have to be modified. It should call the procedure _m_a_i_n with parameters (argc,argv,envp). Usually, Unix will put these on top of the stack before starting the program. Note, however, that for 4-byte systems Unix will provide a 4-byte argc, while _m_a_i_n expects a 2-byte argc; so the value must be shortened to 2 bytes. - The head_em also does a brk() system call to allocate the bss. - (The size of the bss cannot be obtained from an ACK a.out file). The m68k2 code generator translates most EM instructions in line. From 71a74f886487647161f5cfa4332111f08bc207f9 Mon Sep 17 00:00:00 2001 From: ceriel Date: Sun, 1 Feb 1987 22:32:23 +0000 Subject: [PATCH 0648/1625] *** empty log message *** --- mach/i80/dl/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mach/i80/dl/Makefile b/mach/i80/dl/Makefile index e922d089..e684c21e 100644 --- a/mach/i80/dl/Makefile +++ b/mach/i80/dl/Makefile @@ -4,10 +4,10 @@ OBJLIB=$(EMHOME)/modules/lib/libobject.a head: mccpm nascom mccpm: mccpm.c - $(CC) -o mccpm mccpm.c $(OBJLIB) + $(CC) -I$(EMHOME)/h -o mccpm mccpm.c $(OBJLIB) nascom: nascom.c - $(CC) -o nascom nascom.c $(OBJLIB) + $(CC) -I$(EMHOME)/h -o nascom nascom.c $(OBJLIB) install: head @echo Nothing is installed From f2b1cc074459cde4faf4a1a58a89863e8c437af0 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 09:59:02 +0000 Subject: [PATCH 0649/1625] Made floating point stuff depend on a #define: FPPSIM --- mach/m68k2/cg/table | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/mach/m68k2/cg/table b/mach/m68k2/cg/table index c9c2abf5..e5262de6 100644 --- a/mach/m68k2/cg/table +++ b/mach/m68k2/cg/table @@ -30,6 +30,7 @@ */ #define REGVARS +#include "fppsim.h" EM_WSIZE = 2 EM_PSIZE = 4 @@ -1008,6 +1009,7 @@ adu | | | | adi $1 | sbu | | | | sbi $1 | slu | | | | sli $1 | +#ifdef FPPSIM /* Floating point stuff */ adf $1==4 | | remove(ALL) @@ -1051,6 +1053,15 @@ fef $1==4 | | fef $1==8 | | remove(ALL) "jsr .fef8" | | asp 8 lfr 4 loi 12 | +#else not FPPSIM +fef | | | | loc 18 trp | +fif | | | | loc 18 trp | +ngf | | | | loc 18 trp | +adf | | | | loc 18 trp | +sbf | | | | loc 18 trp | +mlf | | | | loc 18 trp | +dvf | | | | loc 18 trp | +#endif FPPSIM @@ -1344,6 +1355,7 @@ loc loc loc cuu $2 == 1 && $3 == 4 && $1 > 0 && $1 < 128 | | | | ldc $1 | /* Floating point stuff */ +#ifdef FPPSYM loc loc cif $1==2 && $2==4 | | remove(ALL) "move.w #$1,-(sp)" @@ -1422,6 +1434,13 @@ loc loc cff $1==8 && $2==4 | | loc loc cff $1==4 && $2==8 | | remove(ALL) "jsr .cff8" | | asp 4 lfr 4 loi 8 | +#else not FPPSIM +cif | | | | loc 18 trp | +cfi | | | | loc 18 trp | +cuf | | | | loc 18 trp | +cfu | | | | loc 18 trp | +cff | | | | loc 18 trp | +#endif FPPSIM /* G R O U P IX : L O G I C A L */ @@ -1855,13 +1874,16 @@ cmp | | remove(ALL) | D1 | | /* floating point */ +#ifdef FPPSIM cmf $1==4 | | remove(ALL) "jsr .cmf4" | | asp 8 lfr 2 | cmf $1==8 | | remove(ALL) "jsr .cmf8" | | asp 16 lfr 2 | - +#else +cmf | | | | loc 18 trp | +#endif cmi tlt and $1==2 && $3==2 | ANY DATAREG DATASCR | "cmp %[1],%[2]" From 9566a0aeab4e882f3e484dcfc196a7b3d95467a9 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 10:16:40 +0000 Subject: [PATCH 0650/1625] Made floating point stuff depend on a #define: FPPSIM --- mach/m68k2/cg/mach.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/mach/m68k2/cg/mach.c b/mach/m68k2/cg/mach.c index 3c5848c1..9f3c7579 100644 --- a/mach/m68k2/cg/mach.c +++ b/mach/m68k2/cg/mach.c @@ -23,7 +23,7 @@ static char rcsid[] = "$Header$"; * machine dependent back end routines for the Motorola 68000 */ -/* #define IEEEFLOAT */ +#include "fppsim.h" #ifdef IEEEFLOAT #include "FP.h" @@ -78,19 +78,24 @@ con_float() { register word sz; register long *l; +#ifdef FPPSIM #ifdef IEEEFLOAT register my_dbl *md; #endif IEEEFLOAT - double d; - char mesg[128]; + double d, atof(); +#else not FPPSIM + static int been_here; +#endif sz = argval; if (sz!= 4 && sz!= 8) { + char mesg[128]; sprintf(mesg,"con_float(): bad fcon size %d %ld\nstr: %s\n\0", sz,sz,str); fatal(mesg); } +#ifdef FPPSIM d = atof(str); l = (long *) &d; @@ -109,6 +114,16 @@ con_float() sz -=4 ; l++; } +#else not FPPSIM + if (! been_here) { + been_here = 1; + fprintf(stderr,"warning: dummy floating constant(s)\n"); + } + while (sz) { + fprintf(codefile,"\t.data4 0 !dummy float\n"); + sz -= 4; + } +#endif } #ifdef REGVARS From a96f04b6fe40c05ce38d1f1aa72160108da2aa22 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 10:25:38 +0000 Subject: [PATCH 0651/1625] Initial revision --- lib/mantra/descr | 53 +++++++++++++++++++++ mach/mantra/libsys/LIST | 64 +++++++++++++++++++++++++ mach/mantra/libsys/Makefile | 29 ++++++++++++ mach/mantra/libsys/_exit.s | 10 ++++ mach/mantra/libsys/access.s | 11 +++++ mach/mantra/libsys/acct.s | 10 ++++ mach/mantra/libsys/alarm.s | 12 +++++ mach/mantra/libsys/brk.s | 27 +++++++++++ mach/mantra/libsys/call.s | 28 +++++++++++ mach/mantra/libsys/chdir.s | 10 ++++ mach/mantra/libsys/chmod.s | 11 +++++ mach/mantra/libsys/chown.s | 12 +++++ mach/mantra/libsys/chroot.s | 10 ++++ mach/mantra/libsys/cleanup.s | 9 ++++ mach/mantra/libsys/close.s | 10 ++++ mach/mantra/libsys/creat.s | 11 +++++ mach/mantra/libsys/dup.s | 10 ++++ mach/mantra/libsys/dup2.s | 17 +++++++ mach/mantra/libsys/errno.s | 9 ++++ mach/mantra/libsys/execl.s | 16 +++++++ mach/mantra/libsys/execle.s | 20 ++++++++ mach/mantra/libsys/execv.s | 16 +++++++ mach/mantra/libsys/execve.s | 12 +++++ mach/mantra/libsys/exit.s | 16 +++++++ mach/mantra/libsys/fcntl.s | 12 +++++ mach/mantra/libsys/fork.s | 17 +++++++ mach/mantra/libsys/fstat.s | 11 +++++ mach/mantra/libsys/ftime.s | 10 ++++ mach/mantra/libsys/getegid.s | 11 +++++ mach/mantra/libsys/getgid.s | 10 ++++ mach/mantra/libsys/getpid.s | 10 ++++ mach/mantra/libsys/getuid.s | 10 ++++ mach/mantra/libsys/gtty.s | 17 +++++++ mach/mantra/libsys/head_em.s | 76 ++++++++++++++++++++++++++++++ mach/mantra/libsys/ioctl.s | 12 +++++ mach/mantra/libsys/kill.s | 11 +++++ mach/mantra/libsys/link.s | 11 +++++ mach/mantra/libsys/lockf.s | 12 +++++ mach/mantra/libsys/lseek.s | 12 +++++ mach/mantra/libsys/mknod.s | 12 +++++ mach/mantra/libsys/mount.s | 12 +++++ mach/mantra/libsys/msg.s | 62 ++++++++++++++++++++++++ mach/mantra/libsys/nice.s | 10 ++++ mach/mantra/libsys/open.s | 11 +++++ mach/mantra/libsys/pause.s | 10 ++++ mach/mantra/libsys/pipe.s | 18 +++++++ mach/mantra/libsys/profil.s | 14 ++++++ mach/mantra/libsys/ptrace.s | 16 +++++++ mach/mantra/libsys/read.s | 12 +++++ mach/mantra/libsys/sem.s | 47 +++++++++++++++++++ mach/mantra/libsys/setgid.s | 10 ++++ mach/mantra/libsys/setuid.s | 10 ++++ mach/mantra/libsys/shm.s | 58 +++++++++++++++++++++++ mach/mantra/libsys/signal.s | 91 ++++++++++++++++++++++++++++++++++++ mach/mantra/libsys/stat.s | 11 +++++ mach/mantra/libsys/stime.s | 15 ++++++ mach/mantra/libsys/stty.s | 17 +++++++ mach/mantra/libsys/sync.s | 10 ++++ mach/mantra/libsys/syscall.s | 26 +++++++++++ mach/mantra/libsys/time.s | 15 ++++++ mach/mantra/libsys/times.s | 11 +++++ mach/mantra/libsys/umask.s | 10 ++++ mach/mantra/libsys/umount.s | 10 ++++ mach/mantra/libsys/unlink.s | 10 ++++ mach/mantra/libsys/utime.s | 11 +++++ mach/mantra/libsys/wait.s | 17 +++++++ mach/mantra/libsys/write.s | 12 +++++ 67 files changed, 1243 insertions(+) create mode 100644 lib/mantra/descr create mode 100644 mach/mantra/libsys/LIST create mode 100644 mach/mantra/libsys/Makefile create mode 100644 mach/mantra/libsys/_exit.s create mode 100644 mach/mantra/libsys/access.s create mode 100644 mach/mantra/libsys/acct.s create mode 100644 mach/mantra/libsys/alarm.s create mode 100644 mach/mantra/libsys/brk.s create mode 100644 mach/mantra/libsys/call.s create mode 100644 mach/mantra/libsys/chdir.s create mode 100644 mach/mantra/libsys/chmod.s create mode 100644 mach/mantra/libsys/chown.s create mode 100644 mach/mantra/libsys/chroot.s create mode 100644 mach/mantra/libsys/cleanup.s create mode 100644 mach/mantra/libsys/close.s create mode 100644 mach/mantra/libsys/creat.s create mode 100644 mach/mantra/libsys/dup.s create mode 100644 mach/mantra/libsys/dup2.s create mode 100644 mach/mantra/libsys/errno.s create mode 100644 mach/mantra/libsys/execl.s create mode 100644 mach/mantra/libsys/execle.s create mode 100644 mach/mantra/libsys/execv.s create mode 100644 mach/mantra/libsys/execve.s create mode 100644 mach/mantra/libsys/exit.s create mode 100644 mach/mantra/libsys/fcntl.s create mode 100644 mach/mantra/libsys/fork.s create mode 100644 mach/mantra/libsys/fstat.s create mode 100644 mach/mantra/libsys/ftime.s create mode 100644 mach/mantra/libsys/getegid.s create mode 100644 mach/mantra/libsys/getgid.s create mode 100644 mach/mantra/libsys/getpid.s create mode 100644 mach/mantra/libsys/getuid.s create mode 100644 mach/mantra/libsys/gtty.s create mode 100644 mach/mantra/libsys/head_em.s create mode 100644 mach/mantra/libsys/ioctl.s create mode 100644 mach/mantra/libsys/kill.s create mode 100644 mach/mantra/libsys/link.s create mode 100644 mach/mantra/libsys/lockf.s create mode 100644 mach/mantra/libsys/lseek.s create mode 100644 mach/mantra/libsys/mknod.s create mode 100644 mach/mantra/libsys/mount.s create mode 100644 mach/mantra/libsys/msg.s create mode 100644 mach/mantra/libsys/nice.s create mode 100644 mach/mantra/libsys/open.s create mode 100644 mach/mantra/libsys/pause.s create mode 100644 mach/mantra/libsys/pipe.s create mode 100644 mach/mantra/libsys/profil.s create mode 100644 mach/mantra/libsys/ptrace.s create mode 100644 mach/mantra/libsys/read.s create mode 100644 mach/mantra/libsys/sem.s create mode 100644 mach/mantra/libsys/setgid.s create mode 100644 mach/mantra/libsys/setuid.s create mode 100644 mach/mantra/libsys/shm.s create mode 100644 mach/mantra/libsys/signal.s create mode 100644 mach/mantra/libsys/stat.s create mode 100644 mach/mantra/libsys/stime.s create mode 100644 mach/mantra/libsys/stty.s create mode 100644 mach/mantra/libsys/sync.s create mode 100644 mach/mantra/libsys/syscall.s create mode 100644 mach/mantra/libsys/time.s create mode 100644 mach/mantra/libsys/times.s create mode 100644 mach/mantra/libsys/umask.s create mode 100644 mach/mantra/libsys/umount.s create mode 100644 mach/mantra/libsys/unlink.s create mode 100644 mach/mantra/libsys/utime.s create mode 100644 mach/mantra/libsys/wait.s create mode 100644 mach/mantra/libsys/write.s diff --git a/lib/mantra/descr b/lib/mantra/descr new file mode 100644 index 00000000..e2cb2b2f --- /dev/null +++ b/lib/mantra/descr @@ -0,0 +1,53 @@ +# $Revision$ +var w=4 +var p=4 +var s=2 +var l=4 +var f=4 +var d=8 +var NAME=mantra4 +var M=m68k4 +var LIB=lib/{M}/tail_ +var RT=lib/{M}/head_ +var CPP_F=-Dunix=unix -Dm68000=m68000 +var INCLUDES=-I{EM}/include/_tail_cc +# 407 align is the default +var ALIGN=-a0:2 -a1:2 -a2:2 -a3:2 +name be + from .m.g + to .s + program {EM}/lib/{M}/cg + args < + stdout + need .e +end +name as + from .s + to .o + program {EM}/lib/m68k2/as + args - -o > < + prep cond +end +name led + from .o.a + to .out + program {EM}/lib/em_led + mapflag -l* LNAME={EM}/{LIB}* + mapflag -i ALIGN=-a0:2 -a1:2 -a2:0x8000 -a3:2 + mapflag -n ALIGN=-a0:2 -a1:2 -a2:0x8000 -a3:2 + mapflag -nr ALIGN=-a0:2 -a1:0x8000 -a2:2 -a3:2 + args (.e:{HEAD}=-b0:0x80000 {ALIGN} {EM}/{RT}em) \ +({RTS}:.b.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \ + (.p:{TAIL}={EM}/{LIB}pc) \ + (.b:{TAIL}={EM}/{LIB}bc) \ + (.b.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \ + (.e:{TAIL}={EM}/{LIB}em {EM}/lib/mantra4/tail_mon {EM}/lib/{M}/end_em) + linker +end +name cv + from .out + to .cv + program {EM}/lib/mantra/cv + args < > + outfile a.out +end diff --git a/mach/mantra/libsys/LIST b/mach/mantra/libsys/LIST new file mode 100644 index 00000000..1a21ff84 --- /dev/null +++ b/mach/mantra/libsys/LIST @@ -0,0 +1,64 @@ +libmon_s.a +exit.s +_exit.s +access.s +acct.s +alarm.s +chdir.s +chmod.s +chown.s +chroot.s +close.s +creat.s +dup.s +dup2.s +execl.s +execle.s +execv.s +execve.s +fcntl.s +fork.s +ftime.s +getegid.s +getgid.s +getpid.s +getuid.s +stty.s +gtty.s +ioctl.s +kill.s +link.s +lseek.s +mknod.s +mount.s +nice.s +open.s +pause.s +pipe.s +profil.s +ptrace.s +read.s +setgid.s +setuid.s +stat.s +stime.s +sync.s +time.s +times.s +umask.s +umount.s +unlink.s +utime.s +write.s +brk.s +wait.s +fstat.s +signal.s +shm.s +sem.s +msg.s +lockf.s +syscall.s +call.s +cleanup.s +errno.s diff --git a/mach/mantra/libsys/Makefile b/mach/mantra/libsys/Makefile new file mode 100644 index 00000000..142afee5 --- /dev/null +++ b/mach/mantra/libsys/Makefile @@ -0,0 +1,29 @@ +# $Header$ +MACH=m68k4 +all: libmon_o.a head_em.o + +install: all + ../../install head_em.o head_em + ../../install libmon_o.a tail_mon + + +cmp: all + -../../compare head_em.o head_em + -../../compare libmon_o.a tail_mon + +libmon_o.a: libmon_s.a + ASAR=aal ; export ASAR ;\ + march . libmon_o.a + +head_em.o: head_em.s + $(MACH) -I../../../h -c head_em.s + +clean: + rm -f *.o libmon_o.a + +opr : + make pr | opr + +pr: + @pr `pwd`/head_em.s + @arch pv libmon_s.a | pr -h `pwd`/libmon_s.a diff --git a/mach/mantra/libsys/_exit.s b/mach/mantra/libsys/_exit.s new file mode 100644 index 00000000..4fab73e8 --- /dev/null +++ b/mach/mantra/libsys/_exit.s @@ -0,0 +1,10 @@ +.define __exit +.extern __exit +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +__exit: move.l #0x1,d0 + move.l 4(sp),a0 + trap #0 diff --git a/mach/mantra/libsys/access.s b/mach/mantra/libsys/access.s new file mode 100644 index 00000000..7b5748ea --- /dev/null +++ b/mach/mantra/libsys/access.s @@ -0,0 +1,11 @@ +.define _access +.extern _access +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_access: move.l #0x21,d0 + move.l 4(sp),a0 + move.l 8(sp),d1 + jmp callc diff --git a/mach/mantra/libsys/acct.s b/mach/mantra/libsys/acct.s new file mode 100644 index 00000000..e04897c9 --- /dev/null +++ b/mach/mantra/libsys/acct.s @@ -0,0 +1,10 @@ +.define _acct +.extern _acct +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_acct: move.l #0x33,d0 + move.l 4(sp),a0 + jmp callc diff --git a/mach/mantra/libsys/alarm.s b/mach/mantra/libsys/alarm.s new file mode 100644 index 00000000..10680ee6 --- /dev/null +++ b/mach/mantra/libsys/alarm.s @@ -0,0 +1,12 @@ +.define _alarm +.extern _alarm +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_alarm: + move.l 4(sp),a0 + move.l #0x1B,d0 + trap #0 + rts diff --git a/mach/mantra/libsys/brk.s b/mach/mantra/libsys/brk.s new file mode 100644 index 00000000..fb5b4285 --- /dev/null +++ b/mach/mantra/libsys/brk.s @@ -0,0 +1,27 @@ +.define _brk +.define _sbrk +.extern _brk +.extern _sbrk +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_sbrk: move.l .reghp,a0 + add.l 4(sp),a0 + move.l #0x11,d0 + trap #0 + bcs lcerror + move.l .reghp,d0 + move.l d0,a0 + add.l 4(sp),a0 + move.l a0,.reghp + rts +lcerror: jmp cerror +_brk: move.l #0x11,d0 + move.l 4(sp),a0 + trap #0 + bcs lcerror + move.l 4(sp),.reghp + clr.l d0 + rts diff --git a/mach/mantra/libsys/call.s b/mach/mantra/libsys/call.s new file mode 100644 index 00000000..de682c1f --- /dev/null +++ b/mach/mantra/libsys/call.s @@ -0,0 +1,28 @@ +.define call +.define callc +.define calle +.define cerror +.extern call +.extern callc +.extern calle +.extern cerror +.extern _errno +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +call: trap #0 + bcs cerror + rts +callc: + trap #0 + bcs cerror + clr.l d0 + rts +calle: + trap #0 +cerror: + move.l d0,_errno + move.l #-1,d0 + rts diff --git a/mach/mantra/libsys/chdir.s b/mach/mantra/libsys/chdir.s new file mode 100644 index 00000000..2ba6798a --- /dev/null +++ b/mach/mantra/libsys/chdir.s @@ -0,0 +1,10 @@ +.define _chdir +.extern _chdir +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_chdir: move.l #0xC,d0 + move.l 4(sp),a0 + jmp callc diff --git a/mach/mantra/libsys/chmod.s b/mach/mantra/libsys/chmod.s new file mode 100644 index 00000000..b51cca54 --- /dev/null +++ b/mach/mantra/libsys/chmod.s @@ -0,0 +1,11 @@ +.define _chmod +.extern _chmod +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_chmod: move.l #0xF,d0 + move.l 4(sp),a0 + move.l 8(sp),d1 + jmp callc diff --git a/mach/mantra/libsys/chown.s b/mach/mantra/libsys/chown.s new file mode 100644 index 00000000..8efe31c8 --- /dev/null +++ b/mach/mantra/libsys/chown.s @@ -0,0 +1,12 @@ +.define _chown +.extern _chown +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_chown: move.l #0x10,d0 + move.l 4(sp),a0 + move.l 8(sp),d1 + move.l 12(sp),a1 + jmp callc diff --git a/mach/mantra/libsys/chroot.s b/mach/mantra/libsys/chroot.s new file mode 100644 index 00000000..b410e4a9 --- /dev/null +++ b/mach/mantra/libsys/chroot.s @@ -0,0 +1,10 @@ +.define _chroot +.extern _chroot +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_chroot: move.l #0x3D,d0 + move.l 4(sp),a0 + jmp callc diff --git a/mach/mantra/libsys/cleanup.s b/mach/mantra/libsys/cleanup.s new file mode 100644 index 00000000..825d8166 --- /dev/null +++ b/mach/mantra/libsys/cleanup.s @@ -0,0 +1,9 @@ +.define __cleanup +.extern __cleanup +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +__cleanup: +rts diff --git a/mach/mantra/libsys/close.s b/mach/mantra/libsys/close.s new file mode 100644 index 00000000..46519fed --- /dev/null +++ b/mach/mantra/libsys/close.s @@ -0,0 +1,10 @@ +.define _close +.extern _close +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_close: move.l #0x6,d0 + move.l 4(sp),a0 + jmp callc diff --git a/mach/mantra/libsys/creat.s b/mach/mantra/libsys/creat.s new file mode 100644 index 00000000..1372f686 --- /dev/null +++ b/mach/mantra/libsys/creat.s @@ -0,0 +1,11 @@ +.define _creat +.extern _creat +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_creat: move.l #0x8,d0 + move.l 4(sp),a0 + move.l 8(sp),d1 + jmp call diff --git a/mach/mantra/libsys/dup.s b/mach/mantra/libsys/dup.s new file mode 100644 index 00000000..e2ec3fee --- /dev/null +++ b/mach/mantra/libsys/dup.s @@ -0,0 +1,10 @@ +.define _dup +.extern _dup +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_dup: move.l #0x29,d0 + move.l 4(sp),a0 + jmp call diff --git a/mach/mantra/libsys/dup2.s b/mach/mantra/libsys/dup2.s new file mode 100644 index 00000000..2286c5b1 --- /dev/null +++ b/mach/mantra/libsys/dup2.s @@ -0,0 +1,17 @@ +.define _dup2 +.extern _dup2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_dup2: +tst.b -40(sp) +link a6,#-0 +move.l 12(a6),-(sp) +move.l #0,-(sp) +move.l 8(a6),-(sp) +jsr _fcntl +add.l #12,sp +unlk a6 +rts diff --git a/mach/mantra/libsys/errno.s b/mach/mantra/libsys/errno.s new file mode 100644 index 00000000..adc08301 --- /dev/null +++ b/mach/mantra/libsys/errno.s @@ -0,0 +1,9 @@ +.define _errno +.extern _errno +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .bss +_errno: .space 4 +.sect .text diff --git a/mach/mantra/libsys/execl.s b/mach/mantra/libsys/execl.s new file mode 100644 index 00000000..ec07bff7 --- /dev/null +++ b/mach/mantra/libsys/execl.s @@ -0,0 +1,16 @@ +.define _execl +.extern _execl +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_execl: link a6,#0 + tst.b -132(sp) + move.l _environ,-(sp) + pea 12(a6) + move.l 8(a6),-(sp) + jsr _execve + add.l #0xC,sp + unlk a6 + rts diff --git a/mach/mantra/libsys/execle.s b/mach/mantra/libsys/execle.s new file mode 100644 index 00000000..0bae3ede --- /dev/null +++ b/mach/mantra/libsys/execle.s @@ -0,0 +1,20 @@ +.define _execle +.extern _execle +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_execle: link a6,#0 + tst.b -48(sp) + lea 12(a6),a0 +1: + tst.l (a0)+ + bne 1b + move.l a0,-(sp) + pea 12(a6) + move.l 8(a6),-(sp) + jsr _execve + add.l #0xC,sp + unlk a6 + rts diff --git a/mach/mantra/libsys/execv.s b/mach/mantra/libsys/execv.s new file mode 100644 index 00000000..e8bb105a --- /dev/null +++ b/mach/mantra/libsys/execv.s @@ -0,0 +1,16 @@ +.define _execv +.extern _execv +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_execv: link a6,#0 + tst.b -48(sp) + move.l _environ,-(sp) + move.l 12(a6),-(sp) + move.l 8(a6),-(sp) + jsr _execve + add.l #0xC,sp + unlk a6 + rts diff --git a/mach/mantra/libsys/execve.s b/mach/mantra/libsys/execve.s new file mode 100644 index 00000000..f7894f64 --- /dev/null +++ b/mach/mantra/libsys/execve.s @@ -0,0 +1,12 @@ +.define _execve +.extern _execve +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_execve: move.l #0x3B,d0 + move.l 4(sp),a0 + move.l 8(sp),d1 + move.l 12(sp),a1 + jmp calle diff --git a/mach/mantra/libsys/exit.s b/mach/mantra/libsys/exit.s new file mode 100644 index 00000000..33e3d650 --- /dev/null +++ b/mach/mantra/libsys/exit.s @@ -0,0 +1,16 @@ +.define _exit +.extern _exit +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_exit: +tst.b -40(sp) +link a6,#-0 +jsr __cleanup +move.l 8(a6),-(sp) +jsr __exit +add.l #4,sp +unlk a6 +rts diff --git a/mach/mantra/libsys/fcntl.s b/mach/mantra/libsys/fcntl.s new file mode 100644 index 00000000..221f2866 --- /dev/null +++ b/mach/mantra/libsys/fcntl.s @@ -0,0 +1,12 @@ +.define _fcntl +.extern _fcntl +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_fcntl: move.l #0x3E,d0 + move.l 4(sp),a0 + move.l 8(sp),d1 + move.l 12(sp),a1 + jmp callc diff --git a/mach/mantra/libsys/fork.s b/mach/mantra/libsys/fork.s new file mode 100644 index 00000000..0ccd4fb1 --- /dev/null +++ b/mach/mantra/libsys/fork.s @@ -0,0 +1,17 @@ +.define _fork +.extern _fork +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_fork: move.l #0x2,d0 + trap #0 + bra 1f + bcc 2f + jmp cerror +1: + !move.l d0,p_uid + clr.l d0 +2: + rts diff --git a/mach/mantra/libsys/fstat.s b/mach/mantra/libsys/fstat.s new file mode 100644 index 00000000..dd8fdc8d --- /dev/null +++ b/mach/mantra/libsys/fstat.s @@ -0,0 +1,11 @@ +.define _fstat +.extern _fstat +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_fstat: move.l #0x1C,d0 + move.l 4(sp),a0 + move.l 8(sp),d1 + jmp callc diff --git a/mach/mantra/libsys/ftime.s b/mach/mantra/libsys/ftime.s new file mode 100644 index 00000000..297a4f85 --- /dev/null +++ b/mach/mantra/libsys/ftime.s @@ -0,0 +1,10 @@ +.define _ftime +.extern _ftime +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_ftime: move.l #0x23,d0 + move.l 4(sp),a0 + jmp callc diff --git a/mach/mantra/libsys/getegid.s b/mach/mantra/libsys/getegid.s new file mode 100644 index 00000000..470f8b30 --- /dev/null +++ b/mach/mantra/libsys/getegid.s @@ -0,0 +1,11 @@ +.define _getegid +.extern _getegid +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_getegid: move.l #0x2F,d0 + trap #0 + move.l d1,d0 + rts diff --git a/mach/mantra/libsys/getgid.s b/mach/mantra/libsys/getgid.s new file mode 100644 index 00000000..ff4dd2ce --- /dev/null +++ b/mach/mantra/libsys/getgid.s @@ -0,0 +1,10 @@ +.define _getgid +.extern _getgid +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_getgid: move.l #0x2F,d0 + trap #0 + rts diff --git a/mach/mantra/libsys/getpid.s b/mach/mantra/libsys/getpid.s new file mode 100644 index 00000000..3d128e43 --- /dev/null +++ b/mach/mantra/libsys/getpid.s @@ -0,0 +1,10 @@ +.define _getpid +.extern _getpid +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_getpid: move.l #0x14,d0 + trap #0 + rts diff --git a/mach/mantra/libsys/getuid.s b/mach/mantra/libsys/getuid.s new file mode 100644 index 00000000..7c884c6c --- /dev/null +++ b/mach/mantra/libsys/getuid.s @@ -0,0 +1,10 @@ +.define _getuid +.extern _getuid +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_getuid: move.l #0x18,d0 + trap #0 + rts diff --git a/mach/mantra/libsys/gtty.s b/mach/mantra/libsys/gtty.s new file mode 100644 index 00000000..8b90d861 --- /dev/null +++ b/mach/mantra/libsys/gtty.s @@ -0,0 +1,17 @@ +.define _gtty +.extern _gtty +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_gtty: +tst.b -40(sp) +link a6,#-0 +move.l 12(a6),-(sp) +move.l #29704,-(sp) +move.l 8(a6),-(sp) +jsr _ioctl +add.l #12,sp +unlk a6 +rts diff --git a/mach/mantra/libsys/head_em.s b/mach/mantra/libsys/head_em.s new file mode 100644 index 00000000..d8ce66df --- /dev/null +++ b/mach/mantra/libsys/head_em.s @@ -0,0 +1,76 @@ +.define .lino,.filn +.define EXIT +.define begtext,begdata,begbss +.define EARRAY,ERANGE,ESET,EIDIVZ,EHEAP,EILLINS,ECASE,EBADGTO +.define hol0,.reghp,.limhp,.trpim,.trppc +.sect .text +.sect .rom +.sect .data +.sect .bss + + + +! EM runtime start-off for the Bleasdale 68000 system + + +LINO_AD = 0 +FILN_AD = 4 + +EARRAY = 0 +ERANGE = 1 +ESET = 2 +EIDIVZ = 6 +EHEAP = 17 +EILLINS = 18 +ECASE = 20 +EBADGTO = 27 + + .sect .text +begtext: + ! Bleasdale puts the argument and environment vectors + ! themselves on top of the stack, instead of POINTERS + ! to these vectors. We get things right here. + move.l 4(sp),a0 + clr.l -4(a0) + move.l sp,a0 + sub.l #8,sp + move.l (a0),(sp) + add.l #4,a0 + move.l a0,4(sp) +1: + tst.l (a0)+ + bne 1b + move.l 4(sp),a1 + cmp.l (a1),a0 + blt 2f + sub.l #4,a0 +2: + move.l a0,8(sp) + + ! Now the stack contains an argc (4 bytes), argv-pointer and + ! envp pointer. + + jsr _m_a_i_n + add #012,sp +EXIT: + jsr __exit + + .sect .data +begdata: +hol0: +.lino: + .data4 0 ! lino +.filn: + .data4 0 ! filn +.reghp: + .data4 endbss +.limhp: + .data4 endbss +.trppc: + .data4 0 +.trpim: + .data4 0 + + + .sect .bss +begbss: !initialization is not needed because ALL entries are in zero space! diff --git a/mach/mantra/libsys/ioctl.s b/mach/mantra/libsys/ioctl.s new file mode 100644 index 00000000..62dbd870 --- /dev/null +++ b/mach/mantra/libsys/ioctl.s @@ -0,0 +1,12 @@ +.define _ioctl +.extern _ioctl +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_ioctl: move.l #0x36,d0 + move.l 4(sp),a0 + move.l 8(sp),d1 + move.l 12(sp),a1 + jmp callc diff --git a/mach/mantra/libsys/kill.s b/mach/mantra/libsys/kill.s new file mode 100644 index 00000000..1af2ec16 --- /dev/null +++ b/mach/mantra/libsys/kill.s @@ -0,0 +1,11 @@ +.define _kill +.extern _kill +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_kill: move.l #0x25,d0 + move.l 4(sp),a0 + move.l 6(sp),d1 + jmp callc diff --git a/mach/mantra/libsys/link.s b/mach/mantra/libsys/link.s new file mode 100644 index 00000000..97e46e49 --- /dev/null +++ b/mach/mantra/libsys/link.s @@ -0,0 +1,11 @@ +.define _link +.extern _link +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_link: move.l #0x9,d0 + move.l 4(sp),a0 + move.l 8(sp),d1 + jmp callc diff --git a/mach/mantra/libsys/lockf.s b/mach/mantra/libsys/lockf.s new file mode 100644 index 00000000..369e17eb --- /dev/null +++ b/mach/mantra/libsys/lockf.s @@ -0,0 +1,12 @@ +.define _lockf +.extern _lockf +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_lockf: move.l #0x38,d0 + move.l 4(sp),a0 + move.l 8(sp),d1 + move.l 12(sp),a1 + jmp callc diff --git a/mach/mantra/libsys/lseek.s b/mach/mantra/libsys/lseek.s new file mode 100644 index 00000000..a992c683 --- /dev/null +++ b/mach/mantra/libsys/lseek.s @@ -0,0 +1,12 @@ +.define _lseek +.extern _lseek +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_lseek: move.l #0x13,d0 + move.l 4(sp),a0 + move.l 8(sp),d1 + move.l 12(sp),a1 + jmp call diff --git a/mach/mantra/libsys/mknod.s b/mach/mantra/libsys/mknod.s new file mode 100644 index 00000000..5df7652a --- /dev/null +++ b/mach/mantra/libsys/mknod.s @@ -0,0 +1,12 @@ +.define _mknod +.extern _mknod +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_mknod: move.l #0xE,d0 + move.l 4(sp),a0 + move.l 8(sp),d1 + move.l 12(sp),a1 + jmp callc diff --git a/mach/mantra/libsys/mount.s b/mach/mantra/libsys/mount.s new file mode 100644 index 00000000..85d3c376 --- /dev/null +++ b/mach/mantra/libsys/mount.s @@ -0,0 +1,12 @@ +.define _mount +.extern _mount +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_mount: move.l #0x15,d0 + move.l 4(sp),a0 + move.l 8(sp),d1 + move.l 12(sp),a1 + jmp callc diff --git a/mach/mantra/libsys/msg.s b/mach/mantra/libsys/msg.s new file mode 100644 index 00000000..0fabafd1 --- /dev/null +++ b/mach/mantra/libsys/msg.s @@ -0,0 +1,62 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _msgsnd +.define _msgctl +.define _msgrcv +.define _msgget +msg = 49 +.extern _msgrcv +.extern _msgctl +.extern _msgsnd +.extern _msgget +.extern _syscall + +_msgget: + link a6,#0 + tst.b -32(sp) + move.l 12(a6),-(sp) + move.l 8(a6),-(sp) + clr.l -(sp) + move.l #msg,-(sp) + jsr _syscall + add #0x10,sp + unlk a6 + rts +_msgctl: + link a6,#0 + tst.b -32(sp) + move.l 16(a6),-(sp) + move.l 12(a6),-(sp) + move.l 8(a6),-(sp) + move.l #1,-(sp) + move.l #msg,-(sp) + jsr _syscall + add #0x14,sp + unlk a6 + rts +_msgrcv: + link a6,#0 + tst.b -32(sp) + move.l 24(a6),-(sp) + move.l 20(a6),-(sp) + move.l 16(a6),-(sp) + move.l 12(a6),-(sp) + move.l 8(a6),-(sp) + move.l #2,-(sp) + move.l #msg,-(sp) + jsr _syscall + add #0x1C,sp + unlk a6 + rts +_msgsnd: + link a6,#0 + tst.b -32(sp) + move.l 20(a6),-(sp) + move.l 16(a6),-(sp) + move.l 12(a6),-(sp) + move.l 8(a6),-(sp) + move.l #3,-(sp) + move.l #msg,-(sp) + jsr _syscall + add #0x18,sp + unlk a6 + rts diff --git a/mach/mantra/libsys/nice.s b/mach/mantra/libsys/nice.s new file mode 100644 index 00000000..1e12910c --- /dev/null +++ b/mach/mantra/libsys/nice.s @@ -0,0 +1,10 @@ +.define _nice +.extern _nice +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_nice: move.l #0x22,d0 + move.l 4(sp),a0 + jmp callc diff --git a/mach/mantra/libsys/open.s b/mach/mantra/libsys/open.s new file mode 100644 index 00000000..56265059 --- /dev/null +++ b/mach/mantra/libsys/open.s @@ -0,0 +1,11 @@ +.define _open +.extern _open +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_open: move.l #0x5,d0 + move.l 4(sp),a0 + move.l 8(sp),d1 + jmp call diff --git a/mach/mantra/libsys/pause.s b/mach/mantra/libsys/pause.s new file mode 100644 index 00000000..fb777eb0 --- /dev/null +++ b/mach/mantra/libsys/pause.s @@ -0,0 +1,10 @@ +.define _pause +.extern _pause +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_pause: move.l #0x1D,d0 + trap #0 + rts diff --git a/mach/mantra/libsys/pipe.s b/mach/mantra/libsys/pipe.s new file mode 100644 index 00000000..96c8cb24 --- /dev/null +++ b/mach/mantra/libsys/pipe.s @@ -0,0 +1,18 @@ +.define _pipe +.extern _pipe +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_pipe: + move.l #0x2A,d0 + trap #0 + bcc 1f + jmp cerror +1: + move.l 4(sp),a0 + move.l d0,(a0)+ + move.l d1,(a0) + clr.l d0 + rts diff --git a/mach/mantra/libsys/profil.s b/mach/mantra/libsys/profil.s new file mode 100644 index 00000000..dc27f5d6 --- /dev/null +++ b/mach/mantra/libsys/profil.s @@ -0,0 +1,14 @@ +.define _profil +.extern _profil +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_profil: move.l #0x2C,d0 + move.l 4(sp),a0 + move.l 8(sp),d1 + move.l 12(sp),a1 + move.l 16(sp),d2 + trap #0 + rts diff --git a/mach/mantra/libsys/ptrace.s b/mach/mantra/libsys/ptrace.s new file mode 100644 index 00000000..70b0b674 --- /dev/null +++ b/mach/mantra/libsys/ptrace.s @@ -0,0 +1,16 @@ +.define _ptrace +.extern _ptrace +.extern _errno +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_ptrace: move.l #0x1A,d0 + move.l 16(sp),a0 + move.l 12(sp),d1 + move.l 8(sp),a1 + move.l 4(sp),d2 + clr.l _errno + trap #0 + rts diff --git a/mach/mantra/libsys/read.s b/mach/mantra/libsys/read.s new file mode 100644 index 00000000..cc02d5f8 --- /dev/null +++ b/mach/mantra/libsys/read.s @@ -0,0 +1,12 @@ +.define _read +.extern _read +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_read: move.l #0x3,d0 + move.l 4(sp),a0 + move.l 8(sp),d1 + move.l 12(sp),a1 + jmp call diff --git a/mach/mantra/libsys/sem.s b/mach/mantra/libsys/sem.s new file mode 100644 index 00000000..a3189592 --- /dev/null +++ b/mach/mantra/libsys/sem.s @@ -0,0 +1,47 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _semctl +.define _semop +.define _semget +sem = 53 +.extern _semop +.extern _semctl +.extern _semget +.extern _syscall + +_semctl: + link a6,#0 + tst.b -32(sp) + move.l 20(a6),-(sp) + move.l 16(a6),-(sp) + move.l 12(a6),-(sp) + move.l 8(a6),-(sp) + clr.l -(sp) + move.l #sem,-(sp) + jsr _syscall + add #0x18,sp + unlk a6 + rts +_semget: + link a6,#0 + tst.b -32(sp) + move.l 16(a6),-(sp) + move.l 12(a6),-(sp) + move.l 8(a6),-(sp) + move.l #1,-(sp) + move.l #sem,-(sp) + jsr _syscall + add #0x14,sp + unlk a6 + rts +_semop: + link a6,#0 + tst.b -32(sp) + move.l 16(a6),-(sp) + move.l 12(a6),-(sp) + move.l 8(a6),-(sp) + move.l #2,-(sp) + move.l #sem,-(sp) + jsr _syscall + add #0x14,sp + unlk a6 + rts diff --git a/mach/mantra/libsys/setgid.s b/mach/mantra/libsys/setgid.s new file mode 100644 index 00000000..fb265378 --- /dev/null +++ b/mach/mantra/libsys/setgid.s @@ -0,0 +1,10 @@ +.define _setgid +.extern _setgid +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_setgid: move.l #0x2E,d0 + move.l 4(sp),a0 + jmp callc diff --git a/mach/mantra/libsys/setuid.s b/mach/mantra/libsys/setuid.s new file mode 100644 index 00000000..ee8f5c1e --- /dev/null +++ b/mach/mantra/libsys/setuid.s @@ -0,0 +1,10 @@ +.define _setuid +.extern _setuid +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_setuid: move.l #0x17,d0 + move.l 4(sp),a0 + jmp callc diff --git a/mach/mantra/libsys/shm.s b/mach/mantra/libsys/shm.s new file mode 100644 index 00000000..73899e22 --- /dev/null +++ b/mach/mantra/libsys/shm.s @@ -0,0 +1,58 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _shmdt +.define _shmat +.define _shmctl +.define _shmget +shm = 52 +.extern _shmdt +.extern _shmat +.extern _shmctl +.extern _shmget +.extern _syscall + +_shmat: + link a6,#0 + tst.b -32(sp) + move.l 16(a6),-(sp) + move.l 12(a6),-(sp) + move.l 8(a6),-(sp) + clr.l -(sp) + move.l #shm,-(sp) + jsr _syscall + add #0x14,sp + unlk a6 + rts +_shmctl: + link a6,#0 + tst.b -32(sp) + move.l 16(a6),-(sp) + move.l 12(a6),-(sp) + move.l 8(a6),-(sp) + move.l #1,-(sp) + move.l #shm,-(sp) + jsr _syscall + add #0x14,sp + unlk a6 + rts +_shmdt: + link a6,#0 + tst.b -144(sp) + move.l 8(a6),-(sp) + move.l #2,-(sp) + move.l #shm,-(sp) + jsr _syscall + add #0xC,sp + unlk a6 + rts +_shmget: + link a6,#0 + tst.b -32(sp) + move.l 16(a6),-(sp) + move.l 12(a6),-(sp) + move.l 8(a6),-(sp) + move.l #3,-(sp) + move.l #shm,-(sp) + jsr _syscall + add #0x14,sp + unlk a6 + rts diff --git a/mach/mantra/libsys/signal.s b/mach/mantra/libsys/signal.s new file mode 100644 index 00000000..fc8ddeb5 --- /dev/null +++ b/mach/mantra/libsys/signal.s @@ -0,0 +1,91 @@ +.define _signal +.extern _signal +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +NSIG=32 +_signal: + move.l 4(sp), d0 + cmp.l #NSIG,d0 + bcc 1f + move.l 8(sp),d1 + move.l d0,a0 + add.l a0,a0 + add.l a0,a0 + add.l #dvect,a0 + move.l (a0),a1 + move.l d1,(a0) + beq 2f + btst #0,d1 + bne 2f + move.l #jmptab,d1 + add.l d0,d1 + add.l d0,d1 +2: + move.l d0,a0 + move.l #0x30,d0 + trap #0 + bcs 3f + btst #0,d0 + bne 4f + move.l a1,d0 +4: + clr.l d1 + rts +1: + move.l #22,d0 +3: + jmp cerror + +jmptab: bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter + bsr enter +enter: + movem.l d0/d1/a0/a1,-(sp) + move.l 16(sp),d0 + sub.l #jmptab+2,d0 + asr.l #1,d0 + move.l d0,-(sp) + move.l d0,a0 + add.l a0,a0 + add.l a0,a0 + add.l #dvect,a0 + move.l (a0),a0 + jsr (a0) + add.l #4,sp + movem.l (sp)+,d0/d1/a0/a1 + add.l #4,sp + rtr +.sect .bss +dvect: .space 4*NSIG diff --git a/mach/mantra/libsys/stat.s b/mach/mantra/libsys/stat.s new file mode 100644 index 00000000..461767bf --- /dev/null +++ b/mach/mantra/libsys/stat.s @@ -0,0 +1,11 @@ +.define _stat +.extern _stat +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_stat: move.l #0x12,d0 + move.l 4(sp),a0 + move.l 8(sp),d1 + jmp callc diff --git a/mach/mantra/libsys/stime.s b/mach/mantra/libsys/stime.s new file mode 100644 index 00000000..46514312 --- /dev/null +++ b/mach/mantra/libsys/stime.s @@ -0,0 +1,15 @@ +.define _stime +.extern _stime +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_stime: move.l #0x19,d0 + move.l 4(sp),a0 + move.l (a0),a0 + trap #0 + bcs 1f + rts +1: + jmp cerror diff --git a/mach/mantra/libsys/stty.s b/mach/mantra/libsys/stty.s new file mode 100644 index 00000000..0de8f974 --- /dev/null +++ b/mach/mantra/libsys/stty.s @@ -0,0 +1,17 @@ +.define _stty +.extern _stty +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_stty: +tst.b -40(sp) +link a6,#-0 +move.l 12(a6),-(sp) +move.l #29705,-(sp) +move.l 8(a6),-(sp) +jsr _ioctl +add.l #12,sp +unlk a6 +rts diff --git a/mach/mantra/libsys/sync.s b/mach/mantra/libsys/sync.s new file mode 100644 index 00000000..3ee77a2c --- /dev/null +++ b/mach/mantra/libsys/sync.s @@ -0,0 +1,10 @@ +.define _sync +.extern _sync +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_sync: move.l #0x24,d0 + trap #0 + rts diff --git a/mach/mantra/libsys/syscall.s b/mach/mantra/libsys/syscall.s new file mode 100644 index 00000000..6230775c --- /dev/null +++ b/mach/mantra/libsys/syscall.s @@ -0,0 +1,26 @@ +.define _syscall +.extern _syscall +.extern cerror +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_syscall: + move.l 4(sp),d0 + move.l 8(sp),a0 + move.l 12(sp),d1 + move.l 16(sp),a1 + movem.l d2/d3/a2,sv + move.l 20(sp),d2 + move.l 24(sp),a2 + move.l 28(sp),d3 + trap #0 + movem.l sv,d2/d3/a2 + bcs 1f + rts + 1: + jmp cerror + +.sect .bss +sv: .space 12 diff --git a/mach/mantra/libsys/time.s b/mach/mantra/libsys/time.s new file mode 100644 index 00000000..e7551c0b --- /dev/null +++ b/mach/mantra/libsys/time.s @@ -0,0 +1,15 @@ +.define _time +.extern _time +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_time: move.l #0xD,d0 + trap #0 + tst.l 4(sp) + beq 1f + move.l 4(sp),a0 + move.l d0,(a0) +1: + rts diff --git a/mach/mantra/libsys/times.s b/mach/mantra/libsys/times.s new file mode 100644 index 00000000..8ed1e1b5 --- /dev/null +++ b/mach/mantra/libsys/times.s @@ -0,0 +1,11 @@ +.define _times +.extern _times +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_times: move.l #0x2B,d0 + move.l 4(sp),a0 + trap #0 + rts diff --git a/mach/mantra/libsys/umask.s b/mach/mantra/libsys/umask.s new file mode 100644 index 00000000..60d22cca --- /dev/null +++ b/mach/mantra/libsys/umask.s @@ -0,0 +1,10 @@ +.define _umask +.extern _umask +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_umask: move.l #0x3C,d0 + move.l 4(sp),a0 + jmp call diff --git a/mach/mantra/libsys/umount.s b/mach/mantra/libsys/umount.s new file mode 100644 index 00000000..4adcab5e --- /dev/null +++ b/mach/mantra/libsys/umount.s @@ -0,0 +1,10 @@ +.define _umount +.extern _umount +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_umount: move.l #0x16,d0 + move.l 4(sp),a0 + jmp callc diff --git a/mach/mantra/libsys/unlink.s b/mach/mantra/libsys/unlink.s new file mode 100644 index 00000000..5d791d58 --- /dev/null +++ b/mach/mantra/libsys/unlink.s @@ -0,0 +1,10 @@ +.define _unlink +.extern _unlink +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_unlink: move.l #0xA,d0 + move.l 4(sp),a0 + jmp callc diff --git a/mach/mantra/libsys/utime.s b/mach/mantra/libsys/utime.s new file mode 100644 index 00000000..48c18e65 --- /dev/null +++ b/mach/mantra/libsys/utime.s @@ -0,0 +1,11 @@ +.define _utime +.extern _utime +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_utime: move.l #0x1E,d0 + move.l 4(sp),a0 + move.l 8(sp),d1 + jmp callc diff --git a/mach/mantra/libsys/wait.s b/mach/mantra/libsys/wait.s new file mode 100644 index 00000000..8bb649b0 --- /dev/null +++ b/mach/mantra/libsys/wait.s @@ -0,0 +1,17 @@ +.define _wait +.extern _wait +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_wait: move.l #0x7,d0 + move.l 4(sp),a0 + trap #0 + bcs cerror + tst.l 4(sp) + beq 1f + move.l 4(sp),a0 + move.l d1,(a0) +1: + rts diff --git a/mach/mantra/libsys/write.s b/mach/mantra/libsys/write.s new file mode 100644 index 00000000..c3888a6f --- /dev/null +++ b/mach/mantra/libsys/write.s @@ -0,0 +1,12 @@ +.define _write +.extern _write +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text +_write: move.l #0x4,d0 + move.l 4(sp),a0 + move.l 8(sp),d1 + move.l 12(sp),a1 + jmp call From cccf23cc9c3257160dda133c0837045d4d6341ba Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 10:45:26 +0000 Subject: [PATCH 0652/1625] Initial revision --- mach/mantra/libsys/compmodule | 4 ++++ 1 file changed, 4 insertions(+) create mode 100755 mach/mantra/libsys/compmodule diff --git a/mach/mantra/libsys/compmodule b/mach/mantra/libsys/compmodule new file mode 100755 index 00000000..1a34d8a6 --- /dev/null +++ b/mach/mantra/libsys/compmodule @@ -0,0 +1,4 @@ +if mantra4 -c $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 +fi From 12df231ada23b7e44602d1754ec7391946e6c0be Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 10:50:09 +0000 Subject: [PATCH 0653/1625] new version for new assembler and new c library --- lib/z8000/descr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/z8000/descr b/lib/z8000/descr index cc603ad2..09665ec9 100644 --- a/lib/z8000/descr +++ b/lib/z8000/descr @@ -9,7 +9,7 @@ var NAME=z8000 var M=z8000 var LIB=lib/{M}/tail_ var RT=lib/{M}/head_ -var INCLUDES=-I{EM}/include -I/usr/include +var INCLUDES=-I{EM}/include/_tail_cc -I{EM}/include/_tail_mon name be from .m.g to .s @@ -31,6 +31,6 @@ name asld (.b:{TAIL}={EM}/{LIB}bc) \ (.b.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \ (.b.c.p:{TAIL}={EM}/{LIB}mon) \ - (.e:{TAIL}={EM}/{LIB}em) + (.e:{TAIL}={EM}/{LIB}em {EM}/lib/z8000/end_em) linker end From 53da6f9e8228a6d52478a06f0ad393a521b6f696 Mon Sep 17 00:00:00 2001 From: em Date: Mon, 2 Feb 1987 10:52:23 +0000 Subject: [PATCH 0654/1625] *** empty log message *** --- lib/6809/descr | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/6809/descr b/lib/6809/descr index f08a013c..085c8969 100644 --- a/lib/6809/descr +++ b/lib/6809/descr @@ -1,6 +1,5 @@ # $Revision$ var w=2 -var i=2 var p=2 var s=2 var l=4 @@ -10,7 +9,9 @@ var NAME=m6809 var M=6809 var LIB=lib/{M}/tail_ var RT=lib/{M}/head_ -var INCLUDES=-I{EM}/include -I/usr/include +var CPP_F= +var INCLUDES=-I{EM}/include/_tail_cc -I{EM}/include/_tail_mon +var ALIGN=-a0:2 -a1:2 -a2:2 -a3:2 name be from .m.g to .s @@ -19,19 +20,24 @@ name be stdout need .e end -name asld - from .s.a - to .out - outfile a.out +name as + from .s + to .o program {EM}/lib/{M}/as + args - -o > < + prep cond +end +name led + from .o.a + to .out + program {EM}/lib/em_led mapflag -l* LNAME={EM}/{LIB}* - mapflag -d* ASFL={ASFL?} -d* - args {ASFL?} (.e:{HEAD}={EM}/{RT}em) \ - ({RTS}:.b.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \ + args -b0:0x800 (.e:{HEAD}={ALIGN} {SEPID?} {EM}/{RT}em) \ +({RTS}:.b.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \ (.p:{TAIL}={EM}/{LIB}pc) \ (.b:{TAIL}={EM}/{LIB}bc) \ (.b.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \ (.b.c.p:{TAIL}={EM}/{LIB}mon) \ - (.e:{TAIL}={EM}/{LIB}em) + (.e:{TAIL}={EM}/{LIB}em {EM}/lib/{M}/end_em) linker end From 4e3b0dbc41357d202738010d553e2133c40912a5 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 10:55:41 +0000 Subject: [PATCH 0655/1625] New version with new assembler, link editor --- lib/i80/descr | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/i80/descr b/lib/i80/descr index 2296aee7..78c10e96 100644 --- a/lib/i80/descr +++ b/lib/i80/descr @@ -5,11 +5,13 @@ var s=2 var l=4 var f=4 var d=8 -var NAME=i8080 +var NAME=i80 var M=i80 var LIB=lib/{M}/tail_ var RT=lib/{M}/head_ -var INCLUDES=-I{EM}/include -I/usr/include +var CPP_F= +var INCLUDES=-I{EM}/include/_tail_cc -I{EM}/include/_tail_mon +var ALIGN=-a0:2 -a1:2 -a2:2 -a3:2 name be from .m.g to .s @@ -18,19 +20,24 @@ name be stdout need .e end -name asld - from .s.a - to .out - outfile a.out +name as + from .s + to .o program {EM}/lib/{M}/as + args - -o > < + prep cond +end +name led + from .o.a + to .out + program {EM}/lib/em_led mapflag -l* LNAME={EM}/{LIB}* - mapflag -i IFILE={EM}/{RT}i - args {IFILE?} (.e:{HEAD}={EM}/{RT}em) \ - ({RTS}:.b.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \ + args -b0:0x1000 (.e:{HEAD}={ALIGN} {SEPID?} {EM}/{RT}em) \ +({RTS}:.b.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \ (.p:{TAIL}={EM}/{LIB}pc) \ (.b:{TAIL}={EM}/{LIB}bc) \ (.b.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \ (.b.c.p:{TAIL}={EM}/{LIB}mon) \ - (.e:{TAIL}={EM}/{LIB}em {EM}/{LIB}sys) + (.e:{TAIL}={EM}/{LIB}em {EM}/{LIB}sys {EM}/lib/{M}/end_em) linker end From d09a89cd8084489ad39209cc11036c5d33bf517a Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 11:07:21 +0000 Subject: [PATCH 0656/1625] *** empty log message *** --- lib/6500/descr | 4 ++-- lib/6800/descr | 2 +- lib/6805/descr | 2 +- lib/em22/descr | 4 ++-- lib/em24/descr | 2 +- lib/em44/descr | 2 +- lib/ns/descr | 29 +++++++++++++++++----------- lib/pmds/descr | 51 ++++++++++++++++++++++++++----------------------- lib/pmds4/descr | 44 +++++++++++++++++++++++++----------------- lib/s2650/descr | 4 ++-- 10 files changed, 82 insertions(+), 62 deletions(-) diff --git a/lib/6500/descr b/lib/6500/descr index 8c5da8c6..21efa05e 100644 --- a/lib/6500/descr +++ b/lib/6500/descr @@ -9,7 +9,7 @@ var NAME=m6500 var M=6500 var LIB=lib/{M}/tail_ var RT=lib/{M}/head_ -var INCLUDES=-I{EM}/include -I/usr/include +var INCLUDES=-I{EM}/include/_tail_cc -I{EM}/include/_tail_mon name be from .m.g to .s @@ -31,6 +31,6 @@ name asld (.b:{TAIL}={EM}/{LIB}bc) \ (.b.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \ (.b.c.p:{TAIL}={EM}/{LIB}mon) \ - (.e:{TAIL}={EM}/{LIB}em {EM}/{LIB}em.vend) + (.e:{TAIL}={EM}/{LIB}em {EM}/lib/{M}/end_em) linker end diff --git a/lib/6800/descr b/lib/6800/descr index c4ab12f3..e2eee989 100644 --- a/lib/6800/descr +++ b/lib/6800/descr @@ -9,7 +9,7 @@ var NAME=m6800 var M=6800 var LIB=lib/{M}/tail_ var RT=lib/{M}/head_ -var INCLUDES=-I{EM}/include -I/usr/include +var INCLUDES=-I{EM}/include/_tail_cc -I{EM}/include/_tail_mon name as from .s.so to .o diff --git a/lib/6805/descr b/lib/6805/descr index 47b7f8a7..be45d842 100644 --- a/lib/6805/descr +++ b/lib/6805/descr @@ -9,7 +9,7 @@ var NAME=m6805 var M=6805 var LIB=lib/{M}/tail_ var RT=lib/{M}/head_ -var INCLUDES=-I{EM}/include -I/usr/include +var INCLUDES=-I{EM}/include/_tail_cc -I{EM}/include/_tail_mon name as from .s.so to .o diff --git a/lib/em22/descr b/lib/em22/descr index 32be1b44..62b677c0 100644 --- a/lib/em22/descr +++ b/lib/em22/descr @@ -10,8 +10,8 @@ var NAME=int22 var LIB=lib/int22/tail_ var RT=lib/int22/head_ var SIZE_FLAG=-sm -var CPP_F=-Dunix -var INCLUDES=-I{EM}/include -I/usr/include +var CPP_F=-Dunix=unix +var INCLUDES=-I{EM}/include/_tail_cc -I{EM}/include/_tail_mon name asld from .k.m.a.g to .out diff --git a/lib/em24/descr b/lib/em24/descr index 8570c8c0..b35298dc 100644 --- a/lib/em24/descr +++ b/lib/em24/descr @@ -11,7 +11,7 @@ var LIB=lib/int24/tail_ var RT=lib/int24/head_ var SIZE_FLAG=-sm var CPP_F=-Dunix -var INCLUDES=-I{EM}/include -I/usr/include +var INCLUDES=-I{EM}/include/_tail_cc -I{EM}/include/_tail_mon name asld from .k.m.a.g to .out diff --git a/lib/em44/descr b/lib/em44/descr index 215bf854..a28af006 100644 --- a/lib/em44/descr +++ b/lib/em44/descr @@ -11,7 +11,7 @@ var LIB=lib/int44/tail_ var RT=lib/int44/head_ var SIZE_FLAG=-sm var CPP_F=-Dunix -var INCLUDES=-I{EM}/include -I/usr/include +var INCLUDES=-I{EM}/include/_tail_cc -I{EM}/include/_tail_mon name asld from .k.m.a.g to .out diff --git a/lib/ns/descr b/lib/ns/descr index dd58316d..42b0638b 100644 --- a/lib/ns/descr +++ b/lib/ns/descr @@ -5,31 +5,38 @@ var s=2 var l=4 var f=4 var d=8 -var NAME=ns16032 var M=ns +var NAME=NS var LIB=lib/{M}/tail_ var RT=lib/{M}/head_ -var INCLUDES=-I{EM}/include -I/usr/include +var CPP_F=-Dunix=unix +var INCLUDES=-I{EM}/include/_tail_cc +var ALIGN=-a0:2 -a1:2 -a2:2 -a3:2 name be from .m.g - to .o + to .s program {EM}/lib/{M}/cg args < stdout need .e end -name asld - from .o.s.a - to .out - outfile a.out +name as + from .s + to .o program {EM}/lib/{M}/as + args - -o > < + prep cond +end +name led + from .o.a + to .out + program {EM}/lib/em_led mapflag -l* LNAME={EM}/{LIB}* - args (.e:{HEAD}={EM}/{RT}em) \ - ({RTS}:.b.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \ + args (.e:{HEAD}={ALIGN} {EM}/{RT}em) \ +({RTS}:.b.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \ (.p:{TAIL}={EM}/{LIB}pc) \ (.b:{TAIL}={EM}/{LIB}bc) \ (.b.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \ - (.b.c.p:{TAIL}={EM}/{LIB}mon) \ - (.e:{TAIL}={EM}/{LIB}em {EM}/{LIB}em.vend) + (.e:{TAIL}={EM}/{LIB}mon {EM}/{LIB}em {EM}/lib/{M}/end_em) linker end diff --git a/lib/pmds/descr b/lib/pmds/descr index 34b56f7f..6a85b7a0 100644 --- a/lib/pmds/descr +++ b/lib/pmds/descr @@ -1,5 +1,4 @@ -# $Revision$ -# Script for use of ACK as cross C-compiler on VAX for PMDS machine +# $Header$ var w=2 var p=4 var s=2 @@ -8,43 +7,47 @@ var f=4 var d=8 var NAME=m68k2 var M=m68k2 -var PMDS=pmds -var LIB=lib/{M}/tail_ -var RT=lib/{M}/head_ -var PMDSLIB=lib/{PMDS}/tail_ -var PMDSRT=lib/{PMDS}/head_ -var INCLUDES=-I{EM}/include -var CPP_F=-Dunix +var LIB=lib/m68k2/tail_ +var RT=lib/m68k2/head_ +var INCLUDES=-I{EM}/include/_tail_cc +var CPP_F=-Dunix=unix -Dm68000=m68000 +# 407 align is the default +var ALIGN=-a0:2 -a1:2 -a2:2 -a3:2 name be - from .m.g - to .o + from .m + to .s program {EM}/lib/{M}/cg args < stdout need .e end -name asld - from .s.a.o - to .out +name as + from .s + to .o program {EM}/lib/{M}/as - mapflag -l - mapflag -d* - mapflag -s* - mapflag -n* - mapflag -i* - args {LFLAG?} (.e:{HEAD}={EM}/{PMDSRT}em) \ - ({RTS}:.b.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \ + args - -o > < + prep cond +end +name led + from .o.a + to .out + program {EM}/lib/em_led + mapflag -l* LNAME={EM}/{LIB}* + mapflag -i ALIGN=-a0:2 -a1:2 -a2:0x8000 -a3:2 + mapflag -n ALIGN=-a0:2 -a1:2 -a2:0x8000 -a3:2 + mapflag -nr ALIGN=-a0:2 -a1:0x8000 -a2:2 -a3:2 + args (.e:{HEAD}= {ALIGN} {EM}/lib/pmds/head_em) \ +({RTS}:.b.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \ (.p:{TAIL}={EM}/{LIB}pc) \ (.b:{TAIL}={EM}/{LIB}bc) \ (.b.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \ - (.e:{TAIL}={EM}/{LIB}em.rt {EM}/{PMDSLIB}mon {EM}/lib/{M}/end_em.s) - prep cond + (.e:{TAIL}={EM}/{LIB}em {EM}/lib/pmds/tail_mon {EM}/lib/{M}/end_em) linker end name cv from .out to .cv - program {EM}/lib/{PMDS}/cv + program {EM}/lib/pmds/cv args < > outfile a.out end diff --git a/lib/pmds4/descr b/lib/pmds4/descr index dee01e4c..067565cd 100644 --- a/lib/pmds4/descr +++ b/lib/pmds4/descr @@ -7,37 +7,47 @@ var f=4 var d=8 var NAME=m68k4 var M=m68k4 -var LIB=mach/m68k4/lib/tail_ -var RT=mach/m68k4/lib/head_ -var INCLUDES=-I{EM}/include +var LIB=lib/{M}/tail_ +var RT=lib/{M}/head_ +var INCLUDES=-I{EM}/include/_tail_cc +var CPP_F=-Dunix=unix -Dm68000=m68000 +# 407 align is default +var ALIGN=-a0:2 -a1:2 -a2:2 -a3:2 name be from .m - to .o + to .s program {EM}/lib/{M}/cg args < stdout need .e end -name asld - from .s.a.o - to .out +name as + from .s + to .o program {EM}/lib/m68k2/as - mapflag -l* LNAME={EM}/{LIB}* - mapflag -d* LFLAG={LFLAG?} -d* - mapflag -s* LFLAG={LFLAG?} -s* - mapflag -n* - mapflag -i* - args {LFLAG?} (.e:{HEAD}={EM}/lib/pmds4/head_em) \ -({RTS}:.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \ -(.p:{TAIL}={EM}/{LIB}pc) (.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \ -(.e:{TAIL}={EM}/{LIB}em {EM}/lib/pmds4/mon {EM}/end_em) + args - -o > < prep cond +end +name led + from .o.a + to .out + program {EM}/lib/em_led + mapflag -l* LNAME={EM}/{LIB}* + mapflag -i ALIGN=-a0:2 -a1:2 -a2:0x8000 -a3:2 + mapflag -n ALIGN=-a0:2 -a1:2 -a2:0x8000 -a3:2 + mapflag -nr ALIGN=-a0:2 -a1:0x8000 -a2:2 -a3:2 + args (.e:{HEAD}={ALIGN} {EM}/lib/pmds4/head_em) \ +({RTS}:.b.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \ + (.p:{TAIL}={EM}/{LIB}pc) \ + (.b:{TAIL}={EM}/{LIB}bc) \ + (.b.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \ + (.e:{TAIL}={EM}/{LIB}em {EM}/lib/pmds4/tail_mon {EM}/lib/{M}/end_em) linker end name cv from .out to .cv - program {EM}/lib/{PMDS}/cv + program {EM}/lib/pmds/cv args < > outfile a.out end diff --git a/lib/s2650/descr b/lib/s2650/descr index d0fe2ea8..1b7a2640 100644 --- a/lib/s2650/descr +++ b/lib/s2650/descr @@ -9,7 +9,7 @@ var NAME=s2650 var M=s2650 var LIB=lib/{M}/tail_ var RT=lib/{M}/head_ -var INCLUDES=-I{EM}/include -I/usr/include +var INCLUDES=-I{EM}/include/_tail_cc -I{EM}/include/_tail_mon name as from .s.so to .o @@ -28,6 +28,6 @@ name led (.b:{TAIL}={EM}/{LIB}bc) \ (.b.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \ (.b.c.p:{TAIL}={EM}/{LIB}mon) \ - (.e:{TAIL}={EM}/{LIB}em) + (.e:{TAIL}={EM}/{LIB}em {EM}/lib/{M}/end_em) linker end From 17b73dc7865999d95a5a9e109cfd96d9bfd2431f Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 11:15:48 +0000 Subject: [PATCH 0657/1625] *** empty log message *** --- lib/m68k2/descr | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/m68k2/descr b/lib/m68k2/descr index ba066443..ee58d2dc 100644 --- a/lib/m68k2/descr +++ b/lib/m68k2/descr @@ -9,8 +9,8 @@ var NAME=m68k2 var M=m68k2 var LIB=lib/{M}/tail_ var RT=lib/{M}/head_ -var CPP_F=-Dunix -var INCLUDES=-I{EM}/include -I/usr/include +var CPP_F=-Dunix=unix -Dm68000=m68000 +var INCLUDES=-I{EM}/include/_tail_cc # 407 align is the default var ALIGN=-a0:2 -a1:2 -a2:2 -a3:2 name be @@ -28,6 +28,15 @@ name as args - -o > < prep cond end +name asopt + from .s + to .so + program {EM}/lib/{M}/top + args + optimizer + stdin + stdout +end name led from .o.a to .out @@ -41,7 +50,7 @@ name led (.p:{TAIL}={EM}/{LIB}pc) \ (.b:{TAIL}={EM}/{LIB}bc) \ (.b.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \ - (.e:{TAIL}={EM}/{LIB}em.rt {EM}/{LIB}mon {EM}/lib/{M}/end_em) + (.e:{TAIL}={EM}/{LIB}em {EM}/{LIB}mon {EM}/lib/{M}/end_em) linker end name cv From a5fa96945f67b82e2fcad9699c4b704dfb29b74a Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 11:22:47 +0000 Subject: [PATCH 0658/1625] *** empty log message *** --- mach/m68k2/Action | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mach/m68k2/Action b/mach/m68k2/Action index ad0eb0da..ececdf45 100644 --- a/mach/m68k2/Action +++ b/mach/m68k2/Action @@ -1,15 +1,11 @@ name "Motorola 68000 assembler" -dir nas +dir as end name "Motorola 68000 2-4 backend" dir cg end -name "Motorola 68000 interpreters" -system m68* -dir int -end name "Motorola 68000 2-4 conversion program" -dir ncv +dir cv end name "Motorola 68000 2-4 C libraries" dir libcc @@ -26,3 +22,7 @@ end name "Motorola 68000 2-4 Basic library" dir libbc end +name "Motorola 68000 interpreters" +system m68* +dir int +end From 32adfddac6c14272e9cb1970faa852cc35de81e8 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 12:44:39 +0000 Subject: [PATCH 0659/1625] version for new assembler --- mach/z80/libmon/Makefile | 47 +++++++--- mach/z80/libmon/char.her.s | 5 ++ mach/z80/libmon/char.nas.s | 17 ++-- mach/z80/libmon/head_em.s | 44 ++++----- mach/z80/libmon/mon.cpm.s | 169 ++++++++++++++++++----------------- mach/z80/libmon/mon.s | 5 ++ mach/z80/libmon/putchr.nas.s | 15 ++-- mach/z80/libmon/putchr.s | 5 ++ mach/z80/libmon/subr.s | 21 +++-- mach/z80/libsys/Makefile | 47 +++++++--- mach/z80/libsys/char.her.s | 5 ++ mach/z80/libsys/char.nas.s | 17 ++-- mach/z80/libsys/head_em.s | 44 ++++----- mach/z80/libsys/mon.cpm.s | 169 ++++++++++++++++++----------------- mach/z80/libsys/mon.s | 5 ++ mach/z80/libsys/putchr.nas.s | 15 ++-- mach/z80/libsys/putchr.s | 5 ++ mach/z80/libsys/subr.s | 21 +++-- 18 files changed, 386 insertions(+), 270 deletions(-) diff --git a/mach/z80/libmon/Makefile b/mach/z80/libmon/Makefile index fbd24f1f..97fc6770 100644 --- a/mach/z80/libmon/Makefile +++ b/mach/z80/libmon/Makefile @@ -1,25 +1,44 @@ -TAIL=tail.hermac +TAIL=libhermac_o.a # Other possibilities are: tail.nascom and tail.cpm +MACH=z80 -all: tail.cpm tail.nascom tail.hermac +all: head_em.o libhermac_o.a libnascom_o.a libcpm_o.a -install: $(TAIL) - ../../install head_em.s head_em - ../../install $(TAIL) tail_sys +install: head_em.o $(TAIL) + ../../install head_em.o head_em + ../../install $(TAIL) tail_mon -cmp: $(TAIL) - -../../compare head_em.s head_em - -../../compare $(TAIL) tail_sys +cmp: head_em.o $(TAIL) + -../../compare head_em.o head_em + -../../compare $(TAIL) tail_mon -tail.cpm: mon.cpm.s +head_em.o: head_em.s + $(MACH) -I../../../h -c head_em.s + +libcpm_o.a: libcpm_s.a + ASAR=aal ; export ASAR; march . libcpm_o.a + +libnascom_o.a: libnascom_s.a + ASAR=aal ; export ASAR; march . libnascom_o.a + +libhermac_o.a: libhermac_s.a + ASAR=aal ; export ASAR; march . libhermac_o.a + +libcpm_s.a: @echo Warning: untested, this is an example - arch cr tail.cpm mon.cpm.s + arch cr libcpm_s.a mon.cpm.s + echo libcpm_s.a > LIST + arch t libcpm_s.a >> LIST -tail.nascom: mon.s char.nas.s - arch cr tail.nascom mon.s char.nas.s +libnascom_s.a: + arch cr libnascom_s.a mon.s char.nas.s + echo libnascom_s.a > LIST + arch t libnascom_s.a >> LIST -tail.hermac: mon.s char.her.s - arch cr tail.hermac mon.s char.her.s +libhermac_s.a: + arch cr libhermac_s.a mon.s char.her.s + echo libhermac_s.a > LIST + arch t libhermac_s.a >> LIST opr: make pr | opr diff --git a/mach/z80/libmon/char.her.s b/mach/z80/libmon/char.her.s index 8ee338af..a6367e91 100644 --- a/mach/z80/libmon/char.her.s +++ b/mach/z80/libmon/char.her.s @@ -1,4 +1,9 @@ .define getchar, putchar +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! These getchar and putchar routines can be used for HERMAC computer diff --git a/mach/z80/libmon/char.nas.s b/mach/z80/libmon/char.nas.s index 2966cdf1..ce11523f 100644 --- a/mach/z80/libmon/char.nas.s +++ b/mach/z80/libmon/char.nas.s @@ -1,9 +1,14 @@ .define putchar,getchar +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! output routine in monitor for the nascom CRT = 0x013B ! output a charcter ! entry: ascii character in a -.text +.sect .text putchar: push hl push bc @@ -22,11 +27,11 @@ fetch: inc hl ld a,(hl) jr 2b ! conversion table for nascom characters -tab: .byte 0x0D,0x00 - .byte 0x1B,0x1E - .byte 0x08,0x1D - .byte 0x0A,0x1F - .byte 0x7F,0x00 +tab: .data1 0x0D,0x00 + .data1 0x1B,0x1E + .data1 0x08,0x1D + .data1 0x0A,0x1F + .data1 0x7F,0x00 KBD = 0x69 get character from keyboard diff --git a/mach/z80/libmon/head_em.s b/mach/z80/libmon/head_em.s index 1f91d0e3..773d637d 100644 --- a/mach/z80/libmon/head_em.s +++ b/mach/z80/libmon/head_em.s @@ -1,6 +1,11 @@ .define EARRAY,ERANGE,EILLINS,EILLSIZE,ECASE,EMON,EHEAP .define hol0,trapproc,trpim,argv,hp,.reghp,envp,begbss,ignmask .define savebc,savede,savehl,saveix,saveaf,saveiy,ebadmon +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text EARRAY = 0 ERANGE = 1 EHEAP = 17 @@ -11,10 +16,9 @@ ebadmon=25 - .base 0x1000 -.text +.sect .text - ! clear .bss + ! clear .sect .bss ld sp,0x7ffe !address of fbase ld de,endbss ld h,d @@ -44,37 +48,37 @@ jp 0x20 -.bss +.sect .bss begbss: -.data +.sect .data hol0: - .word 0,0 - .word 0,0 + .data2 0,0 + .data2 0,0 saveaf: - .word 0 + .data2 0 savebc: - .word 0 + .data2 0 savede: - .word 0 + .data2 0 savehl: - .word 0 + .data2 0 saveix: - .word 0 + .data2 0 saveiy: - .word 0 + .data2 0 ignmask: - .word 0 + .data2 0 hp: - .word 0 + .data2 0 trapproc: - .word 0 + .data2 0 trpim: - .word 0 + .data2 0 argv: - .word 3f + .data2 3f envp: - .word 0 + .data2 0 3: .asciz 'PROGRAM' .reghp: - .word endbss + .data2 endbss diff --git a/mach/z80/libmon/mon.cpm.s b/mach/z80/libmon/mon.cpm.s index 79fd4670..c82ce985 100644 --- a/mach/z80/libmon/mon.cpm.s +++ b/mach/z80/libmon/mon.cpm.s @@ -1,5 +1,10 @@ .define .mon .define uxfinish +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! monitor instruction ! a small collection of UNIX system calls implemented under CP/M @@ -98,21 +103,21 @@ zcount=41 zsave=42 - .errnz filefcb + .assert [ filefcb] <> 0 0: .space maxfiles*filesize filearea = 0b+128 sibuf: - .word 0 + .data2 0 .space 82 siptr: .space 2 saveargs: .space 128 argc: .space 2 -ttymode:.byte 9,9,8,21;.short 06310+RAW*040 ! raw = 040 +ttymode:.data1 9,9,8,21;.data2 06310+RAW*040 ! raw = 040 return: - .word 0,0 + .data2 0,0 uxinit: xor a ld c,maxfiles @@ -155,70 +160,70 @@ uxfinish: jp (hl) systab: - .word e.mon ! ux_indir - .word ux_exit - .word e.mon ! ux_fork - .word ux_read - .word ux_write - .word ux_open - .word ux_close - .word e.mon ! ux_wait - .word ux_creat - .word e.mon ! ux_link - .word ux_unlink - .word e.mon ! ux_exec - .word e.mon ! ux_chdir - .word ux_time - .word e.mon ! ux_mknod - .word e.mon ! ux_chmod - .word e.mon ! ux_chown - .word e.mon ! ux_break - .word e.mon ! ux_stat - .word e.mon ! ux_seek - .word ux_getpid - .word e.mon ! ux_mount - .word e.mon ! ux_umount - .word e.mon ! ux_setuid - .word e.mon ! ux_getuid - .word e.mon ! ux_stime - .word e.mon ! ux_ptrace - .word e.mon ! ux_alarm - .word e.mon ! ux_fstat - .word e.mon ! ux_pause - .word e.mon ! ux_utime - .word e.mon ! ux_stty - .word e.mon ! ux_gtty - .word e.mon ! ux_access - .word e.mon ! ux_nice - .word ux_ftime - .word e.mon ! ux_sync - .word e.mon ! ux_kill - .word unimpld - .word unimpld - .word unimpld - .word e.mon ! ux_dup - .word e.mon ! ux_pipe - .word e.mon ! ux_times - .word e.mon ! ux_prof - .word e.mon ! ux_unused - .word e.mon ! ux_setgid - .word e.mon ! ux_getgid - .word e.mon ! ux_sig - .word unimpld - .word unimpld - .word unimpld - .word unimpld - .word unimpld - .word ux_ioctl - .word unimpld - .word unimpld - .word unimpld - .word unimpld - .word unimpld ! ux_exece - .word e.mon ! ux_umask - .word e.mon ! ux_chroot - .word unimpld - .word unimpld + .data2 e.mon ! ux_indir + .data2 ux_exit + .data2 e.mon ! ux_fork + .data2 ux_read + .data2 ux_write + .data2 ux_open + .data2 ux_close + .data2 e.mon ! ux_wait + .data2 ux_creat + .data2 e.mon ! ux_link + .data2 ux_unlink + .data2 e.mon ! ux_exec + .data2 e.mon ! ux_chdir + .data2 ux_time + .data2 e.mon ! ux_mknod + .data2 e.mon ! ux_chmod + .data2 e.mon ! ux_chown + .data2 e.mon ! ux_break + .data2 e.mon ! ux_stat + .data2 e.mon ! ux_seek + .data2 ux_getpid + .data2 e.mon ! ux_mount + .data2 e.mon ! ux_umount + .data2 e.mon ! ux_setuid + .data2 e.mon ! ux_getuid + .data2 e.mon ! ux_stime + .data2 e.mon ! ux_ptrace + .data2 e.mon ! ux_alarm + .data2 e.mon ! ux_fstat + .data2 e.mon ! ux_pause + .data2 e.mon ! ux_utime + .data2 e.mon ! ux_stty + .data2 e.mon ! ux_gtty + .data2 e.mon ! ux_access + .data2 e.mon ! ux_nice + .data2 ux_ftime + .data2 e.mon ! ux_sync + .data2 e.mon ! ux_kill + .data2 unimpld + .data2 unimpld + .data2 unimpld + .data2 e.mon ! ux_dup + .data2 e.mon ! ux_pipe + .data2 e.mon ! ux_times + .data2 e.mon ! ux_prof + .data2 e.mon ! ux_unused + .data2 e.mon ! ux_setgid + .data2 e.mon ! ux_getgid + .data2 e.mon ! ux_sig + .data2 unimpld + .data2 unimpld + .data2 unimpld + .data2 unimpld + .data2 unimpld + .data2 ux_ioctl + .data2 unimpld + .data2 unimpld + .data2 unimpld + .data2 unimpld + .data2 unimpld ! ux_exece + .data2 e.mon ! ux_umask + .data2 e.mon ! ux_chroot + .data2 unimpld + .data2 unimpld emptyfile: ! searches for a free filestructure @@ -902,23 +907,23 @@ ux_getpid: -retarea: .word 0 ! base of buffer for result values (max 8 bytes) - .word 0 - .word 0 - .word 0 +retarea: .data2 0 ! base of buffer for result values (max 8 bytes) + .data2 0 + .data2 0 + .data2 0 trapproc: - .word 0 + .data2 0 -nextp: .byte 0 +nextp: .data1 0 header: -ntext: .word 0 -ndata: .word 0 -nproc: .word 0 -entry: .word 0 -nline: .word 0 +ntext: .data2 0 +ndata: .data2 0 +nproc: .data2 0 +entry: .data2 0 +nline: .data2 0 -hp: .word 0 -pb: .word 0 -pd: .word 0 +hp: .data2 0 +pb: .data2 0 +pd: .data2 0 diff --git a/mach/z80/libmon/mon.s b/mach/z80/libmon/mon.s index 0e997f14..d6fd207b 100644 --- a/mach/z80/libmon/mon.s +++ b/mach/z80/libmon/mon.s @@ -1,4 +1,9 @@ .define .mon +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Monitor call ! Expects on stack: monitor call number diff --git a/mach/z80/libmon/putchr.nas.s b/mach/z80/libmon/putchr.nas.s index e0dbdeb6..e66a6891 100644 --- a/mach/z80/libmon/putchr.nas.s +++ b/mach/z80/libmon/putchr.nas.s @@ -1,4 +1,9 @@ .define putchr +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! output routine in monitor CRT = 0x013B ! output a charcter @@ -21,8 +26,8 @@ fetch: inc hl ld a,(hl) jr 2b ! conversion table for nascom characters -tab: .byte 0x0D,0x00 - .byte 0x1B,0x1E - .byte 0x08,0x1D - .byte 0x0A,0x1F - .byte 0x7F,0x00 +tab: .data1 0x0D,0x00 + .data1 0x1B,0x1E + .data1 0x08,0x1D + .data1 0x0A,0x1F + .data1 0x7F,0x00 diff --git a/mach/z80/libmon/putchr.s b/mach/z80/libmon/putchr.s index db15bf21..898db469 100644 --- a/mach/z80/libmon/putchr.s +++ b/mach/z80/libmon/putchr.s @@ -1,4 +1,9 @@ .define putchr +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text putchr: push hl diff --git a/mach/z80/libmon/subr.s b/mach/z80/libmon/subr.s index 25304889..d82ca4f9 100644 --- a/mach/z80/libmon/subr.s +++ b/mach/z80/libmon/subr.s @@ -1,4 +1,9 @@ .define _read,_write,_ioctl,_getpid,_open,_close,_exit,_errno +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _read: ld (savebc),bc push af @@ -149,14 +154,14 @@ _close: ret _exit: jp 0x38 -.data +.sect .data _errno: - .word 0 + .data2 0 ! output routine in monitor CRT = 0x013B ! output a charcter ! entry: ascii character in a -.text +.sect .text !putchr: ! push hl ! push bc @@ -175,11 +180,11 @@ CRT = 0x013B ! ld a,(hl) ! jr 2b !! conversion table for nascom characters -!tab: .byte 0x0D,0x00 -! .byte 0x1B,0x1E -! .byte 0x08,0x1D -! .byte 0x0A,0x1F -! .byte 0x7F,0x00 +!tab: .data1 0x0D,0x00 +! .data1 0x1B,0x1E +! .data1 0x08,0x1D +! .data1 0x0A,0x1F +! .data1 0x7F,0x00 KBD = 0x69 ! get character from keyboard diff --git a/mach/z80/libsys/Makefile b/mach/z80/libsys/Makefile index fbd24f1f..97fc6770 100644 --- a/mach/z80/libsys/Makefile +++ b/mach/z80/libsys/Makefile @@ -1,25 +1,44 @@ -TAIL=tail.hermac +TAIL=libhermac_o.a # Other possibilities are: tail.nascom and tail.cpm +MACH=z80 -all: tail.cpm tail.nascom tail.hermac +all: head_em.o libhermac_o.a libnascom_o.a libcpm_o.a -install: $(TAIL) - ../../install head_em.s head_em - ../../install $(TAIL) tail_sys +install: head_em.o $(TAIL) + ../../install head_em.o head_em + ../../install $(TAIL) tail_mon -cmp: $(TAIL) - -../../compare head_em.s head_em - -../../compare $(TAIL) tail_sys +cmp: head_em.o $(TAIL) + -../../compare head_em.o head_em + -../../compare $(TAIL) tail_mon -tail.cpm: mon.cpm.s +head_em.o: head_em.s + $(MACH) -I../../../h -c head_em.s + +libcpm_o.a: libcpm_s.a + ASAR=aal ; export ASAR; march . libcpm_o.a + +libnascom_o.a: libnascom_s.a + ASAR=aal ; export ASAR; march . libnascom_o.a + +libhermac_o.a: libhermac_s.a + ASAR=aal ; export ASAR; march . libhermac_o.a + +libcpm_s.a: @echo Warning: untested, this is an example - arch cr tail.cpm mon.cpm.s + arch cr libcpm_s.a mon.cpm.s + echo libcpm_s.a > LIST + arch t libcpm_s.a >> LIST -tail.nascom: mon.s char.nas.s - arch cr tail.nascom mon.s char.nas.s +libnascom_s.a: + arch cr libnascom_s.a mon.s char.nas.s + echo libnascom_s.a > LIST + arch t libnascom_s.a >> LIST -tail.hermac: mon.s char.her.s - arch cr tail.hermac mon.s char.her.s +libhermac_s.a: + arch cr libhermac_s.a mon.s char.her.s + echo libhermac_s.a > LIST + arch t libhermac_s.a >> LIST opr: make pr | opr diff --git a/mach/z80/libsys/char.her.s b/mach/z80/libsys/char.her.s index 8ee338af..a6367e91 100644 --- a/mach/z80/libsys/char.her.s +++ b/mach/z80/libsys/char.her.s @@ -1,4 +1,9 @@ .define getchar, putchar +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! These getchar and putchar routines can be used for HERMAC computer diff --git a/mach/z80/libsys/char.nas.s b/mach/z80/libsys/char.nas.s index 2966cdf1..ce11523f 100644 --- a/mach/z80/libsys/char.nas.s +++ b/mach/z80/libsys/char.nas.s @@ -1,9 +1,14 @@ .define putchar,getchar +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! output routine in monitor for the nascom CRT = 0x013B ! output a charcter ! entry: ascii character in a -.text +.sect .text putchar: push hl push bc @@ -22,11 +27,11 @@ fetch: inc hl ld a,(hl) jr 2b ! conversion table for nascom characters -tab: .byte 0x0D,0x00 - .byte 0x1B,0x1E - .byte 0x08,0x1D - .byte 0x0A,0x1F - .byte 0x7F,0x00 +tab: .data1 0x0D,0x00 + .data1 0x1B,0x1E + .data1 0x08,0x1D + .data1 0x0A,0x1F + .data1 0x7F,0x00 KBD = 0x69 get character from keyboard diff --git a/mach/z80/libsys/head_em.s b/mach/z80/libsys/head_em.s index 1f91d0e3..773d637d 100644 --- a/mach/z80/libsys/head_em.s +++ b/mach/z80/libsys/head_em.s @@ -1,6 +1,11 @@ .define EARRAY,ERANGE,EILLINS,EILLSIZE,ECASE,EMON,EHEAP .define hol0,trapproc,trpim,argv,hp,.reghp,envp,begbss,ignmask .define savebc,savede,savehl,saveix,saveaf,saveiy,ebadmon +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text EARRAY = 0 ERANGE = 1 EHEAP = 17 @@ -11,10 +16,9 @@ ebadmon=25 - .base 0x1000 -.text +.sect .text - ! clear .bss + ! clear .sect .bss ld sp,0x7ffe !address of fbase ld de,endbss ld h,d @@ -44,37 +48,37 @@ jp 0x20 -.bss +.sect .bss begbss: -.data +.sect .data hol0: - .word 0,0 - .word 0,0 + .data2 0,0 + .data2 0,0 saveaf: - .word 0 + .data2 0 savebc: - .word 0 + .data2 0 savede: - .word 0 + .data2 0 savehl: - .word 0 + .data2 0 saveix: - .word 0 + .data2 0 saveiy: - .word 0 + .data2 0 ignmask: - .word 0 + .data2 0 hp: - .word 0 + .data2 0 trapproc: - .word 0 + .data2 0 trpim: - .word 0 + .data2 0 argv: - .word 3f + .data2 3f envp: - .word 0 + .data2 0 3: .asciz 'PROGRAM' .reghp: - .word endbss + .data2 endbss diff --git a/mach/z80/libsys/mon.cpm.s b/mach/z80/libsys/mon.cpm.s index 79fd4670..c82ce985 100644 --- a/mach/z80/libsys/mon.cpm.s +++ b/mach/z80/libsys/mon.cpm.s @@ -1,5 +1,10 @@ .define .mon .define uxfinish +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! monitor instruction ! a small collection of UNIX system calls implemented under CP/M @@ -98,21 +103,21 @@ zcount=41 zsave=42 - .errnz filefcb + .assert [ filefcb] <> 0 0: .space maxfiles*filesize filearea = 0b+128 sibuf: - .word 0 + .data2 0 .space 82 siptr: .space 2 saveargs: .space 128 argc: .space 2 -ttymode:.byte 9,9,8,21;.short 06310+RAW*040 ! raw = 040 +ttymode:.data1 9,9,8,21;.data2 06310+RAW*040 ! raw = 040 return: - .word 0,0 + .data2 0,0 uxinit: xor a ld c,maxfiles @@ -155,70 +160,70 @@ uxfinish: jp (hl) systab: - .word e.mon ! ux_indir - .word ux_exit - .word e.mon ! ux_fork - .word ux_read - .word ux_write - .word ux_open - .word ux_close - .word e.mon ! ux_wait - .word ux_creat - .word e.mon ! ux_link - .word ux_unlink - .word e.mon ! ux_exec - .word e.mon ! ux_chdir - .word ux_time - .word e.mon ! ux_mknod - .word e.mon ! ux_chmod - .word e.mon ! ux_chown - .word e.mon ! ux_break - .word e.mon ! ux_stat - .word e.mon ! ux_seek - .word ux_getpid - .word e.mon ! ux_mount - .word e.mon ! ux_umount - .word e.mon ! ux_setuid - .word e.mon ! ux_getuid - .word e.mon ! ux_stime - .word e.mon ! ux_ptrace - .word e.mon ! ux_alarm - .word e.mon ! ux_fstat - .word e.mon ! ux_pause - .word e.mon ! ux_utime - .word e.mon ! ux_stty - .word e.mon ! ux_gtty - .word e.mon ! ux_access - .word e.mon ! ux_nice - .word ux_ftime - .word e.mon ! ux_sync - .word e.mon ! ux_kill - .word unimpld - .word unimpld - .word unimpld - .word e.mon ! ux_dup - .word e.mon ! ux_pipe - .word e.mon ! ux_times - .word e.mon ! ux_prof - .word e.mon ! ux_unused - .word e.mon ! ux_setgid - .word e.mon ! ux_getgid - .word e.mon ! ux_sig - .word unimpld - .word unimpld - .word unimpld - .word unimpld - .word unimpld - .word ux_ioctl - .word unimpld - .word unimpld - .word unimpld - .word unimpld - .word unimpld ! ux_exece - .word e.mon ! ux_umask - .word e.mon ! ux_chroot - .word unimpld - .word unimpld + .data2 e.mon ! ux_indir + .data2 ux_exit + .data2 e.mon ! ux_fork + .data2 ux_read + .data2 ux_write + .data2 ux_open + .data2 ux_close + .data2 e.mon ! ux_wait + .data2 ux_creat + .data2 e.mon ! ux_link + .data2 ux_unlink + .data2 e.mon ! ux_exec + .data2 e.mon ! ux_chdir + .data2 ux_time + .data2 e.mon ! ux_mknod + .data2 e.mon ! ux_chmod + .data2 e.mon ! ux_chown + .data2 e.mon ! ux_break + .data2 e.mon ! ux_stat + .data2 e.mon ! ux_seek + .data2 ux_getpid + .data2 e.mon ! ux_mount + .data2 e.mon ! ux_umount + .data2 e.mon ! ux_setuid + .data2 e.mon ! ux_getuid + .data2 e.mon ! ux_stime + .data2 e.mon ! ux_ptrace + .data2 e.mon ! ux_alarm + .data2 e.mon ! ux_fstat + .data2 e.mon ! ux_pause + .data2 e.mon ! ux_utime + .data2 e.mon ! ux_stty + .data2 e.mon ! ux_gtty + .data2 e.mon ! ux_access + .data2 e.mon ! ux_nice + .data2 ux_ftime + .data2 e.mon ! ux_sync + .data2 e.mon ! ux_kill + .data2 unimpld + .data2 unimpld + .data2 unimpld + .data2 e.mon ! ux_dup + .data2 e.mon ! ux_pipe + .data2 e.mon ! ux_times + .data2 e.mon ! ux_prof + .data2 e.mon ! ux_unused + .data2 e.mon ! ux_setgid + .data2 e.mon ! ux_getgid + .data2 e.mon ! ux_sig + .data2 unimpld + .data2 unimpld + .data2 unimpld + .data2 unimpld + .data2 unimpld + .data2 ux_ioctl + .data2 unimpld + .data2 unimpld + .data2 unimpld + .data2 unimpld + .data2 unimpld ! ux_exece + .data2 e.mon ! ux_umask + .data2 e.mon ! ux_chroot + .data2 unimpld + .data2 unimpld emptyfile: ! searches for a free filestructure @@ -902,23 +907,23 @@ ux_getpid: -retarea: .word 0 ! base of buffer for result values (max 8 bytes) - .word 0 - .word 0 - .word 0 +retarea: .data2 0 ! base of buffer for result values (max 8 bytes) + .data2 0 + .data2 0 + .data2 0 trapproc: - .word 0 + .data2 0 -nextp: .byte 0 +nextp: .data1 0 header: -ntext: .word 0 -ndata: .word 0 -nproc: .word 0 -entry: .word 0 -nline: .word 0 +ntext: .data2 0 +ndata: .data2 0 +nproc: .data2 0 +entry: .data2 0 +nline: .data2 0 -hp: .word 0 -pb: .word 0 -pd: .word 0 +hp: .data2 0 +pb: .data2 0 +pd: .data2 0 diff --git a/mach/z80/libsys/mon.s b/mach/z80/libsys/mon.s index 0e997f14..d6fd207b 100644 --- a/mach/z80/libsys/mon.s +++ b/mach/z80/libsys/mon.s @@ -1,4 +1,9 @@ .define .mon +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! Monitor call ! Expects on stack: monitor call number diff --git a/mach/z80/libsys/putchr.nas.s b/mach/z80/libsys/putchr.nas.s index e0dbdeb6..e66a6891 100644 --- a/mach/z80/libsys/putchr.nas.s +++ b/mach/z80/libsys/putchr.nas.s @@ -1,4 +1,9 @@ .define putchr +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! output routine in monitor CRT = 0x013B ! output a charcter @@ -21,8 +26,8 @@ fetch: inc hl ld a,(hl) jr 2b ! conversion table for nascom characters -tab: .byte 0x0D,0x00 - .byte 0x1B,0x1E - .byte 0x08,0x1D - .byte 0x0A,0x1F - .byte 0x7F,0x00 +tab: .data1 0x0D,0x00 + .data1 0x1B,0x1E + .data1 0x08,0x1D + .data1 0x0A,0x1F + .data1 0x7F,0x00 diff --git a/mach/z80/libsys/putchr.s b/mach/z80/libsys/putchr.s index db15bf21..898db469 100644 --- a/mach/z80/libsys/putchr.s +++ b/mach/z80/libsys/putchr.s @@ -1,4 +1,9 @@ .define putchr +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text putchr: push hl diff --git a/mach/z80/libsys/subr.s b/mach/z80/libsys/subr.s index 25304889..d82ca4f9 100644 --- a/mach/z80/libsys/subr.s +++ b/mach/z80/libsys/subr.s @@ -1,4 +1,9 @@ .define _read,_write,_ioctl,_getpid,_open,_close,_exit,_errno +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text _read: ld (savebc),bc push af @@ -149,14 +154,14 @@ _close: ret _exit: jp 0x38 -.data +.sect .data _errno: - .word 0 + .data2 0 ! output routine in monitor CRT = 0x013B ! output a charcter ! entry: ascii character in a -.text +.sect .text !putchr: ! push hl ! push bc @@ -175,11 +180,11 @@ CRT = 0x013B ! ld a,(hl) ! jr 2b !! conversion table for nascom characters -!tab: .byte 0x0D,0x00 -! .byte 0x1B,0x1E -! .byte 0x08,0x1D -! .byte 0x0A,0x1F -! .byte 0x7F,0x00 +!tab: .data1 0x0D,0x00 +! .data1 0x1B,0x1E +! .data1 0x08,0x1D +! .data1 0x0A,0x1F +! .data1 0x7F,0x00 KBD = 0x69 ! get character from keyboard From 6c91577427108fb19165223482cc56b02dab2b89 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 13:07:28 +0000 Subject: [PATCH 0660/1625] generating .o files --- mach/z80/libbc/Makefile | 3 ++- mach/z80/libbc/compmodule | 6 +++--- mach/z80/libcc/Makefile | 3 ++- mach/z80/libcc/compmodule | 6 +++--- mach/z80/libpc/Makefile | 3 ++- mach/z80/libpc/compmodule | 6 +++--- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/mach/z80/libbc/Makefile b/mach/z80/libbc/Makefile index 0b0b4e76..2286d7bc 100644 --- a/mach/z80/libbc/Makefile +++ b/mach/z80/libbc/Makefile @@ -1,5 +1,6 @@ +SUF=o MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=z80" "SUF=s" +MACHDEF="MACH=z80" "SUF=$(SUF)" "ASAR=aal" BCDEF="PREF=bc" "SUB=" "SRC=lang/basic/lib" install: diff --git a/mach/z80/libbc/compmodule b/mach/z80/libbc/compmodule index 9db6d714..a794a225 100755 --- a/mach/z80/libbc/compmodule +++ b/mach/z80/libbc/compmodule @@ -1,4 +1,4 @@ -if ${MACH?ack} -I../../../h ${MACHFL?} $1 1>&2 -then echo `basename $1 $2`.s -else rm -f `basename $1 $2`.s +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 fi diff --git a/mach/z80/libcc/Makefile b/mach/z80/libcc/Makefile index acc68c1b..10b6fea6 100644 --- a/mach/z80/libcc/Makefile +++ b/mach/z80/libcc/Makefile @@ -1,5 +1,6 @@ +SUF=o MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=z80" "SUF=s" +MACHDEF="MACH=z80" "SUF=$(SUF)" "ASAR=aal" STDIO="PREF=cc" "SUB=.1s" "SRC=lang/cem/libcc/stdio" GEN="PREF=cc" "SUB=.2g" "SRC=lang/cem/libcc/gen" MON="PREF=mon" "SRC=lang/cem/libcc/mon" diff --git a/mach/z80/libcc/compmodule b/mach/z80/libcc/compmodule index 9db6d714..a794a225 100755 --- a/mach/z80/libcc/compmodule +++ b/mach/z80/libcc/compmodule @@ -1,4 +1,4 @@ -if ${MACH?ack} -I../../../h ${MACHFL?} $1 1>&2 -then echo `basename $1 $2`.s -else rm -f `basename $1 $2`.s +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 fi diff --git a/mach/z80/libpc/Makefile b/mach/z80/libpc/Makefile index 5128fcec..d56deb59 100644 --- a/mach/z80/libpc/Makefile +++ b/mach/z80/libpc/Makefile @@ -1,5 +1,6 @@ +SUF=o MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=z80" "SUF=s" +MACHDEF="MACH=z80" "SUF=$(SUF)" "ASAR=aal" PCDEF="PREF=pc" "SUB=" "SRC=lang/pc/libpc" install: diff --git a/mach/z80/libpc/compmodule b/mach/z80/libpc/compmodule index 9db6d714..a794a225 100755 --- a/mach/z80/libpc/compmodule +++ b/mach/z80/libpc/compmodule @@ -1,4 +1,4 @@ -if ${MACH?ack} -I../../../h ${MACHFL?} $1 1>&2 -then echo `basename $1 $2`.s -else rm -f `basename $1 $2`.s +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 fi From 0840746aca80afeec00e12516e01d176688458cd Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 13:09:17 +0000 Subject: [PATCH 0661/1625] Added clean-entry, tail_mon --> tail_sys --- mach/z80/libmon/Makefile | 7 +++++-- mach/z80/libsys/Makefile | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/mach/z80/libmon/Makefile b/mach/z80/libmon/Makefile index 97fc6770..f7baeca8 100644 --- a/mach/z80/libmon/Makefile +++ b/mach/z80/libmon/Makefile @@ -6,11 +6,11 @@ all: head_em.o libhermac_o.a libnascom_o.a libcpm_o.a install: head_em.o $(TAIL) ../../install head_em.o head_em - ../../install $(TAIL) tail_mon + ../../install $(TAIL) tail_sys cmp: head_em.o $(TAIL) -../../compare head_em.o head_em - -../../compare $(TAIL) tail_mon + -../../compare $(TAIL) tail_sys head_em.o: head_em.s $(MACH) -I../../../h -c head_em.s @@ -40,6 +40,9 @@ libhermac_s.a: echo libhermac_s.a > LIST arch t libhermac_s.a >> LIST +clean: + rm -f *.o *_o.a out nohup.out Out + opr: make pr | opr pr: diff --git a/mach/z80/libsys/Makefile b/mach/z80/libsys/Makefile index 97fc6770..f7baeca8 100644 --- a/mach/z80/libsys/Makefile +++ b/mach/z80/libsys/Makefile @@ -6,11 +6,11 @@ all: head_em.o libhermac_o.a libnascom_o.a libcpm_o.a install: head_em.o $(TAIL) ../../install head_em.o head_em - ../../install $(TAIL) tail_mon + ../../install $(TAIL) tail_sys cmp: head_em.o $(TAIL) -../../compare head_em.o head_em - -../../compare $(TAIL) tail_mon + -../../compare $(TAIL) tail_sys head_em.o: head_em.s $(MACH) -I../../../h -c head_em.s @@ -40,6 +40,9 @@ libhermac_s.a: echo libhermac_s.a > LIST arch t libhermac_s.a >> LIST +clean: + rm -f *.o *_o.a out nohup.out Out + opr: make pr | opr pr: From aa963110a4c2ee7253a8a6050bb1c4e2842a6fd9 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 13:11:35 +0000 Subject: [PATCH 0662/1625] Initial revision --- mach/z80/libmon/compmodule | 4 ++++ mach/z80/libsys/compmodule | 4 ++++ 2 files changed, 8 insertions(+) create mode 100755 mach/z80/libmon/compmodule create mode 100755 mach/z80/libsys/compmodule diff --git a/mach/z80/libmon/compmodule b/mach/z80/libmon/compmodule new file mode 100755 index 00000000..ec9d18f3 --- /dev/null +++ b/mach/z80/libmon/compmodule @@ -0,0 +1,4 @@ +if z80 -c $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 +fi diff --git a/mach/z80/libsys/compmodule b/mach/z80/libsys/compmodule new file mode 100755 index 00000000..ec9d18f3 --- /dev/null +++ b/mach/z80/libsys/compmodule @@ -0,0 +1,4 @@ +if z80 -c $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 +fi From ceb0f75afadbef591d9e93c6b4e8cc7bb29ca428 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 13:30:20 +0000 Subject: [PATCH 0663/1625] new version for .o --- mach/z80/libem/LIST | 2 +- mach/z80/libem/Makefile | 32 ++++++++++++++++++++++---------- mach/z80/libem/aar.s | 5 +++++ mach/z80/libem/aar2.s | 5 +++++ mach/z80/libem/aaru.s | 5 +++++ mach/z80/libem/and.s | 5 +++++ mach/z80/libem/cii.s | 7 ++++++- mach/z80/libem/cms.s | 5 +++++ mach/z80/libem/cmu.s | 5 +++++ mach/z80/libem/cmu4.s | 9 +++++++-- mach/z80/libem/csa.s | 5 +++++ mach/z80/libem/csb.s | 5 +++++ mach/z80/libem/dvi2.s | 5 +++++ mach/z80/libem/dvi4.s | 17 +++++++++++------ mach/z80/libem/dvu2.s | 5 +++++ mach/z80/libem/dvu4.s | 17 +++++++++++------ mach/z80/libem/end.s | 8 +++++--- mach/z80/libem/exg.s | 5 +++++ mach/z80/libem/gto.s | 5 +++++ mach/z80/libem/hulp.s | 11 ++++++++--- mach/z80/libem/inn.s | 5 +++++ mach/z80/libem/ior.s | 5 +++++ mach/z80/libem/lar.s | 5 +++++ mach/z80/libem/lar2.s | 5 +++++ mach/z80/libem/laru.s | 5 +++++ mach/z80/libem/los.s | 5 +++++ mach/z80/libem/mli2.s | 5 +++++ mach/z80/libem/mli4.s | 9 +++++++-- mach/z80/libem/nop.s | 9 +++++++-- mach/z80/libem/outdec.s | 13 +++++++++---- mach/z80/libem/pstrng.s | 9 +++++++-- mach/z80/libem/rck.s | 5 +++++ mach/z80/libem/rmi2.s | 5 +++++ mach/z80/libem/sar.s | 5 +++++ mach/z80/libem/sar2.s | 5 +++++ mach/z80/libem/saru.s | 5 +++++ mach/z80/libem/sdf.s | 5 +++++ mach/z80/libem/sdl.s | 5 +++++ mach/z80/libem/set.s | 5 +++++ mach/z80/libem/str.s | 5 +++++ mach/z80/libem/sts.s | 5 +++++ mach/z80/libem/trp.s | 5 +++++ mach/z80/libem/unim.s | 5 +++++ mach/z80/libem/xor.s | 5 +++++ 44 files changed, 261 insertions(+), 42 deletions(-) diff --git a/mach/z80/libem/LIST b/mach/z80/libem/LIST index 67c82969..b61d8d8f 100644 --- a/mach/z80/libem/LIST +++ b/mach/z80/libem/LIST @@ -1,4 +1,4 @@ -tail_em.a +libem_s.a aaru.s aar.s aar2.s diff --git a/mach/z80/libem/Makefile b/mach/z80/libem/Makefile index f1db57de..3529a29a 100644 --- a/mach/z80/libem/Makefile +++ b/mach/z80/libem/Makefile @@ -1,17 +1,29 @@ # $Header$ -install: - ../../install tail_em.a tail_em - ../../install tail.s end_em +MACH=z80 +all: libem_o.a end.o -cmp: - -../../compare tail_em.a tail_em - -../../compare tail.s end_em +install: all + ../../install end.o end_em + ../../install libem_o.a tail_em -clean : + +cmp: all + -../../compare end.o end_em + -../../compare libem_o.a tail_em + +libem_o.a: libem_s.a + ASAR=aal ; export ASAR ;\ + march . libem_o.a + +end.o: end.s + $(MACH) -I../../../h -c end.s + +clean: + rm -f *.o libem_o.a opr : - make pr | opr + make pr | opr pr: - @arch pv tail_em.a | pr -h `pwd`/tail_em.a - @pr `pwd`/tail.s + @pr `pwd`/end.s + @arch pv libem_s.a | pr -h `pwd`/libem_s.a diff --git a/mach/z80/libem/aar.s b/mach/z80/libem/aar.s index ded49f52..09b0eb06 100644 --- a/mach/z80/libem/aar.s +++ b/mach/z80/libem/aar.s @@ -1,4 +1,9 @@ .define .aar +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! use .mli2 ! 2-byte descriptor elements diff --git a/mach/z80/libem/aar2.s b/mach/z80/libem/aar2.s index 149eefbd..b7c35080 100644 --- a/mach/z80/libem/aar2.s +++ b/mach/z80/libem/aar2.s @@ -1,4 +1,9 @@ .define .aar2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! special case aar: element size = 2 (statically known) ! parameters: diff --git a/mach/z80/libem/aaru.s b/mach/z80/libem/aaru.s index 650931f9..95f6ae41 100644 --- a/mach/z80/libem/aaru.s +++ b/mach/z80/libem/aaru.s @@ -1,4 +1,9 @@ .define .aaru +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! AAR NOT DEFINED diff --git a/mach/z80/libem/and.s b/mach/z80/libem/and.s index dd02e8a6..3aa04f03 100644 --- a/mach/z80/libem/and.s +++ b/mach/z80/libem/and.s @@ -1,4 +1,9 @@ .define .and +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! auxiliary size 'and' ! parameters: diff --git a/mach/z80/libem/cii.s b/mach/z80/libem/cii.s index 2321874a..d042d65b 100644 --- a/mach/z80/libem/cii.s +++ b/mach/z80/libem/cii.s @@ -1,4 +1,10 @@ .define .cii +.define .cuu +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! cii: convert integer to integer ! parameters: @@ -107,7 +113,6 @@ -.define .cuu ! cuu: convert unsigned to unsigned ! parameters: diff --git a/mach/z80/libem/cms.s b/mach/z80/libem/cms.s index 530f4fc0..8f28ced5 100644 --- a/mach/z80/libem/cms.s +++ b/mach/z80/libem/cms.s @@ -1,4 +1,9 @@ .define .cms +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! any size sets ! parameters: diff --git a/mach/z80/libem/cmu.s b/mach/z80/libem/cmu.s index 738cb615..c0a4ac5f 100644 --- a/mach/z80/libem/cmu.s +++ b/mach/z80/libem/cmu.s @@ -1,4 +1,9 @@ .define .cmu +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! parameters: ! hl : size (#bytes) diff --git a/mach/z80/libem/cmu4.s b/mach/z80/libem/cmu4.s index 5f91c5d6..8cc431cd 100644 --- a/mach/z80/libem/cmu4.s +++ b/mach/z80/libem/cmu4.s @@ -1,4 +1,9 @@ .define .cmu4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! 4 byte cmu and cmi routine ! parameters: @@ -56,5 +61,5 @@ inc hl ld sp,hl jp (ix) -.data -savesp: .word 0 +.sect .data +savesp: .data2 0 diff --git a/mach/z80/libem/csa.s b/mach/z80/libem/csa.s index 3f114c8b..ace728e5 100644 --- a/mach/z80/libem/csa.s +++ b/mach/z80/libem/csa.s @@ -1,4 +1,9 @@ .define .csa +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! this is not a subroutine, but just a ! piece of code that computes the jump- diff --git a/mach/z80/libem/csb.s b/mach/z80/libem/csb.s index 32bdab04..53aa41a1 100644 --- a/mach/z80/libem/csb.s +++ b/mach/z80/libem/csb.s @@ -1,4 +1,9 @@ .define .csb +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! this is not a subroutine, but just a ! piece of code that computes the jump- diff --git a/mach/z80/libem/dvi2.s b/mach/z80/libem/dvi2.s index 986ac487..2b248184 100644 --- a/mach/z80/libem/dvi2.s +++ b/mach/z80/libem/dvi2.s @@ -1,4 +1,9 @@ .define .dvi2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! 16-bit signed division ! parameters: diff --git a/mach/z80/libem/dvi4.s b/mach/z80/libem/dvi4.s index 145df917..d5665609 100644 --- a/mach/z80/libem/dvi4.s +++ b/mach/z80/libem/dvi4.s @@ -1,4 +1,9 @@ .define .dvi4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! 4-byte divide routine for z80 ! parameters: @@ -77,9 +82,9 @@ push bc push de jp (ix) -.data - .flag1: .byte 0 - .flag2: .byte 0 - retaddr:.word 0 - .savebc: .word 0 - .savede: .word 0 +.sect .data + .flag1: .data1 0 + .flag2: .data1 0 + retaddr:.data2 0 + .savebc: .data2 0 + .savede: .data2 0 diff --git a/mach/z80/libem/dvu2.s b/mach/z80/libem/dvu2.s index 06590f70..4512115f 100644 --- a/mach/z80/libem/dvu2.s +++ b/mach/z80/libem/dvu2.s @@ -1,4 +1,9 @@ .define .dvu2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! 16-bit divide ! parameters: diff --git a/mach/z80/libem/dvu4.s b/mach/z80/libem/dvu4.s index eeecec42..d0e3ab89 100644 --- a/mach/z80/libem/dvu4.s +++ b/mach/z80/libem/dvu4.s @@ -1,4 +1,9 @@ .define .dvu4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! 4-byte divide routine for z80 ! parameters: @@ -129,9 +134,9 @@ ld hl,(.retaddr) jp (hl) ! return -.data -.flag: .byte 0 -.low: .word 0 -.iysave: .word 0 -.retaddr: .word 0 -.result: .word 0 +.sect .data +.flag: .data1 0 +.low: .data2 0 +.iysave: .data2 0 +.retaddr: .data2 0 +.result: .data2 0 diff --git a/mach/z80/libem/end.s b/mach/z80/libem/end.s index aead4997..6b9ce418 100644 --- a/mach/z80/libem/end.s +++ b/mach/z80/libem/end.s @@ -1,15 +1,17 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss .define endtext,enddata,endbss .define _end,_etext,_edata - .text + ! $Header$ + .sect .text endtext: _etext: .align 2 - .data + .sect .data enddata: _edata: .align 2 - .bss +.sect .endsect _end: endbss: .align 2 diff --git a/mach/z80/libem/exg.s b/mach/z80/libem/exg.s index d7dc3bdd..149a1e5b 100644 --- a/mach/z80/libem/exg.s +++ b/mach/z80/libem/exg.s @@ -1,4 +1,9 @@ .define .exg +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .exg: pop ix pop de diff --git a/mach/z80/libem/gto.s b/mach/z80/libem/gto.s index 230d6a9b..97aaba84 100644 --- a/mach/z80/libem/gto.s +++ b/mach/z80/libem/gto.s @@ -1,4 +1,9 @@ .define .gto +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .gto: ld e,(hl) diff --git a/mach/z80/libem/hulp.s b/mach/z80/libem/hulp.s index 1f1ffaa3..b287d2ec 100644 --- a/mach/z80/libem/hulp.s +++ b/mach/z80/libem/hulp.s @@ -1,3 +1,8 @@ +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text loop = 100 dvi4: xor a @@ -57,6 +62,6 @@ dvi4: push hl push de jp (iy) -.data - .flag1: .byte 0 - .flag2: .byte 0 +.sect .data + .flag1: .data1 0 + .flag2: .data1 0 diff --git a/mach/z80/libem/inn.s b/mach/z80/libem/inn.s index a6fed767..ddd4b1b8 100644 --- a/mach/z80/libem/inn.s +++ b/mach/z80/libem/inn.s @@ -1,4 +1,9 @@ .define .inn +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! use .unimpld ! any size sets diff --git a/mach/z80/libem/ior.s b/mach/z80/libem/ior.s index 6a6fded7..4e5e1881 100644 --- a/mach/z80/libem/ior.s +++ b/mach/z80/libem/ior.s @@ -1,4 +1,9 @@ .define .ior +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! auxiliary size 'ior' ! parameters: diff --git a/mach/z80/libem/lar.s b/mach/z80/libem/lar.s index 105ebbf9..dbed3117 100644 --- a/mach/z80/libem/lar.s +++ b/mach/z80/libem/lar.s @@ -1,4 +1,9 @@ .define .lar +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! use .mli2 ! 2-byte descriptor elements diff --git a/mach/z80/libem/lar2.s b/mach/z80/libem/lar2.s index e4ce311f..dcc487b3 100644 --- a/mach/z80/libem/lar2.s +++ b/mach/z80/libem/lar2.s @@ -1,4 +1,9 @@ .define .lar2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! special case lar: element size = 2 (statically known) ! parameters: diff --git a/mach/z80/libem/laru.s b/mach/z80/libem/laru.s index 0ad563d4..19c0df5e 100644 --- a/mach/z80/libem/laru.s +++ b/mach/z80/libem/laru.s @@ -1,4 +1,9 @@ .define .laru +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! LAR NOT DEFINED diff --git a/mach/z80/libem/los.s b/mach/z80/libem/los.s index 0799c7e3..e472e215 100644 --- a/mach/z80/libem/los.s +++ b/mach/z80/libem/los.s @@ -1,4 +1,9 @@ .define .los +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text diff --git a/mach/z80/libem/mli2.s b/mach/z80/libem/mli2.s index 28e7a9e7..fc887389 100644 --- a/mach/z80/libem/mli2.s +++ b/mach/z80/libem/mli2.s @@ -1,4 +1,9 @@ .define .mli2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! 16 bit multiply ! parameters: diff --git a/mach/z80/libem/mli4.s b/mach/z80/libem/mli4.s index 0284310c..3fbeb2b0 100644 --- a/mach/z80/libem/mli4.s +++ b/mach/z80/libem/mli4.s @@ -1,4 +1,9 @@ .define .mli4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! 32-bit multiply routine for z80 ! parameters: @@ -70,6 +75,6 @@ ! on stack! put return address in hl push ix ! least sign. 2 bytes of result jp (hl) ! return -.data -.flag: .byte 0 +.sect .data +.flag: .data1 0 .mplier: .space 4 diff --git a/mach/z80/libem/nop.s b/mach/z80/libem/nop.s index 6a61101b..016192f0 100644 --- a/mach/z80/libem/nop.s +++ b/mach/z80/libem/nop.s @@ -1,6 +1,11 @@ - - .define .nop +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text + + ! NOP ! changed into output routine to print linenumber diff --git a/mach/z80/libem/outdec.s b/mach/z80/libem/outdec.s index 74f96982..5a03edf5 100644 --- a/mach/z80/libem/outdec.s +++ b/mach/z80/libem/outdec.s @@ -1,4 +1,9 @@ .define outdec +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! output contents of HL as a sequence ! of decimal digits outdec: @@ -47,7 +52,7 @@ convert: pop bc ret table: - .short 10000 - .short 1000 - .short 100 - .short 10 + .data2 10000 + .data2 1000 + .data2 100 + .data2 10 diff --git a/mach/z80/libem/pstrng.s b/mach/z80/libem/pstrng.s index f3e0885a..d9ebc558 100644 --- a/mach/z80/libem/pstrng.s +++ b/mach/z80/libem/pstrng.s @@ -1,6 +1,11 @@ - - .define pstrng +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text + + ! print a string of characters to the console ! entry: DE points to string ! string terminator is 0x00 diff --git a/mach/z80/libem/rck.s b/mach/z80/libem/rck.s index c98e1ca6..3831042c 100644 --- a/mach/z80/libem/rck.s +++ b/mach/z80/libem/rck.s @@ -1,4 +1,9 @@ .define .rck +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .rck: pop bc pop ix diff --git a/mach/z80/libem/rmi2.s b/mach/z80/libem/rmi2.s index 16cf68b5..c6b8d182 100644 --- a/mach/z80/libem/rmi2.s +++ b/mach/z80/libem/rmi2.s @@ -1,4 +1,9 @@ .define .rmi2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! 16-bit signed remainder ! parameters: diff --git a/mach/z80/libem/sar.s b/mach/z80/libem/sar.s index a89ecdaf..65aec587 100644 --- a/mach/z80/libem/sar.s +++ b/mach/z80/libem/sar.s @@ -1,4 +1,9 @@ .define .sar +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! use .mli2 ! use .trp.z diff --git a/mach/z80/libem/sar2.s b/mach/z80/libem/sar2.s index 9dbe81ef..286738cd 100644 --- a/mach/z80/libem/sar2.s +++ b/mach/z80/libem/sar2.s @@ -1,4 +1,9 @@ .define .sar2 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! special case sar: element size = 2 (statically known) ! parameters: diff --git a/mach/z80/libem/saru.s b/mach/z80/libem/saru.s index b2784e40..1d53cc90 100644 --- a/mach/z80/libem/saru.s +++ b/mach/z80/libem/saru.s @@ -1,4 +1,9 @@ .define .saru +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! SAR NOT DEFINED diff --git a/mach/z80/libem/sdf.s b/mach/z80/libem/sdf.s index 7a3caf15..89e81a41 100644 --- a/mach/z80/libem/sdf.s +++ b/mach/z80/libem/sdf.s @@ -1,4 +1,9 @@ .define .sdf +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! store double offsetted diff --git a/mach/z80/libem/sdl.s b/mach/z80/libem/sdl.s index 643428cc..2acfd85c 100644 --- a/mach/z80/libem/sdl.s +++ b/mach/z80/libem/sdl.s @@ -1,4 +1,9 @@ .define .sdl +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! store double local at any offset ! parameters: diff --git a/mach/z80/libem/set.s b/mach/z80/libem/set.s index 2e698f77..f2251af0 100644 --- a/mach/z80/libem/set.s +++ b/mach/z80/libem/set.s @@ -1,4 +1,9 @@ .define .set +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! use .unimpld ! any size sets diff --git a/mach/z80/libem/str.s b/mach/z80/libem/str.s index 4a4a2b19..70e97f53 100644 --- a/mach/z80/libem/str.s +++ b/mach/z80/libem/str.s @@ -1,4 +1,9 @@ .define .strhp +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .strhp: pop ix diff --git a/mach/z80/libem/sts.s b/mach/z80/libem/sts.s index 89f5cbb9..db1cea32 100644 --- a/mach/z80/libem/sts.s +++ b/mach/z80/libem/sts.s @@ -1,4 +1,9 @@ .define .sts +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! use trp.z ! object size given by 2-byte integer on diff --git a/mach/z80/libem/trp.s b/mach/z80/libem/trp.s index 07f83527..f153b8e3 100644 --- a/mach/z80/libem/trp.s +++ b/mach/z80/libem/trp.s @@ -1,4 +1,9 @@ .define .trp.z +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! changed into output routine to print errornumber diff --git a/mach/z80/libem/unim.s b/mach/z80/libem/unim.s index 53970f3f..fa5e4c59 100644 --- a/mach/z80/libem/unim.s +++ b/mach/z80/libem/unim.s @@ -1,4 +1,9 @@ .define unimpld, e.mon, e.rck, .trp.z, .unimpld +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .unimpld: unimpld: ! used in dispatch table to diff --git a/mach/z80/libem/xor.s b/mach/z80/libem/xor.s index ae882577..b9b12e0b 100644 --- a/mach/z80/libem/xor.s +++ b/mach/z80/libem/xor.s @@ -1,4 +1,9 @@ .define .xor +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! auxiliary size 'xor' ! parameters: From 149ed55bfeb0212e7375d6b552cbb356fca549fe Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 13:36:33 +0000 Subject: [PATCH 0664/1625] Initial revision --- mach/z80/libem/compmodule | 4 ++++ 1 file changed, 4 insertions(+) create mode 100755 mach/z80/libem/compmodule diff --git a/mach/z80/libem/compmodule b/mach/z80/libem/compmodule new file mode 100755 index 00000000..ec9d18f3 --- /dev/null +++ b/mach/z80/libem/compmodule @@ -0,0 +1,4 @@ +if z80 -c $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 +fi From 4064e3e43ff0d307ceffed8e31e9831fbaa5f16d Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 15:28:31 +0000 Subject: [PATCH 0665/1625] bug fix --- mach/z80/as/mach4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/z80/as/mach4.c b/mach/z80/as/mach4.c index d3ee6917..457d3ad4 100644 --- a/mach/z80/as/mach4.c +++ b/mach/z80/as/mach4.c @@ -97,7 +97,7 @@ operation | ROTATE ind { xymem($2,0313); emit1($1 | 06);} | BITS absexp ',' r8 - { fit(fit3($2.val)); + { fit(fit3($2)); emit1(0313); emit1($1 | low3($2)<<3 | $4); } | BITS absexp ',' ind From 19b345f5e0c3c4711a4349193b864a4eb9e94d72 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 16:04:16 +0000 Subject: [PATCH 0666/1625] library name change --- mach/vax4/libbsd4_1a/LIST | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/vax4/libbsd4_1a/LIST b/mach/vax4/libbsd4_1a/LIST index 1e6f6472..a148febb 100644 --- a/mach/vax4/libbsd4_1a/LIST +++ b/mach/vax4/libbsd4_1a/LIST @@ -1,4 +1,4 @@ -tail_mon.a +libmon_s.a exit.c cleanup.c gtty.c From 0b48126a5aca4233b2393c72319b901d53e0b276 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 16:04:52 +0000 Subject: [PATCH 0667/1625] *** empty log message *** --- mach/vax4/libbsd4_1a/Makefile | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/mach/vax4/libbsd4_1a/Makefile b/mach/vax4/libbsd4_1a/Makefile index 92b9aaf6..6dd093d6 100644 --- a/mach/vax4/libbsd4_1a/Makefile +++ b/mach/vax4/libbsd4_1a/Makefile @@ -1,30 +1,31 @@ # $Header$ +all: head_em.o libmon_o.a + install: cp cp: all - ../../install head_em - ../../install tail_mon - rm -f head_em tail_mon + ../../install head_em.o head_em + ../../install libmon_o.a tail_mon cmp: all - -../../compare head_em - -../../compare tail_mon - rm -f head_em tail_mon + -../../compare head_em.o head_em + -../../compare libmon_o.a tail_mon -all: head_em tail_mon -head_em: head_em.s - vax4 -I../../../h -c head_em.s ; mv head_em.o head_em +head_em.o: head_em.s + vax4 -I../../../h -c head_em.s -tail_mon: +libmon_o.a: libmon_s.a ASAR=ar ; export ASAR ;\ RANLIB=ranlib ; export RANLIB ;\ - march . tail_mon + march . libmon_o.a clean: - rm -f *.o + rm -f *.o libmon_o.a + opr: make pr | opr + pr: @pr `pwd`/Makefile `pwd`/head_em.s - @pr -l33 `tail +1 LIST|sort` + @arch pv libmon_s.a | pr -h `pwd`/libmon_s.a From 6deb381f32e1611b47bcbd69b2731efd1cac1210 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 16:06:51 +0000 Subject: [PATCH 0668/1625] Initial revision --- mach/vax4/libsysV_2/Makefile | 31 ++++++++++++++ mach/vax4/libsysV_2/_exit.s | 7 ++++ mach/vax4/libsysV_2/access.s | 11 +++++ mach/vax4/libsysV_2/acct.s | 11 +++++ mach/vax4/libsysV_2/alarm.s | 7 ++++ mach/vax4/libsysV_2/cerror.s | 11 +++++ mach/vax4/libsysV_2/chdir.s | 12 ++++++ mach/vax4/libsysV_2/chmod.s | 12 ++++++ mach/vax4/libsysV_2/chown.s | 12 ++++++ mach/vax4/libsysV_2/chroot.s | 11 +++++ mach/vax4/libsysV_2/cleanup.c | 1 + mach/vax4/libsysV_2/close.s | 12 ++++++ mach/vax4/libsysV_2/compmodule | 4 ++ mach/vax4/libsysV_2/creat.s | 11 +++++ mach/vax4/libsysV_2/dup.s | 11 +++++ mach/vax4/libsysV_2/dup2.c | 6 +++ mach/vax4/libsysV_2/execl.s | 9 ++++ mach/vax4/libsysV_2/execle.s | 11 +++++ mach/vax4/libsysV_2/execv.s | 11 +++++ mach/vax4/libsysV_2/execve.s | 8 ++++ mach/vax4/libsysV_2/exit.c | 1 + mach/vax4/libsysV_2/fcntl.s | 11 +++++ mach/vax4/libsysV_2/fork.s | 14 +++++++ mach/vax4/libsysV_2/fstat.s | 12 ++++++ mach/vax4/libsysV_2/getegid.s | 8 ++++ mach/vax4/libsysV_2/geteuid.s | 8 ++++ mach/vax4/libsysV_2/getgid.s | 7 ++++ mach/vax4/libsysV_2/getpid.s | 7 ++++ mach/vax4/libsysV_2/getppid.s | 8 ++++ mach/vax4/libsysV_2/getuid.s | 7 ++++ mach/vax4/libsysV_2/gtty.s | 11 +++++ mach/vax4/libsysV_2/head_em.s | 76 ++++++++++++++++++++++++++++++++++ mach/vax4/libsysV_2/ioctl.s | 11 +++++ mach/vax4/libsysV_2/kill.s | 12 ++++++ mach/vax4/libsysV_2/link.s | 12 ++++++ mach/vax4/libsysV_2/lseek.s | 11 +++++ mach/vax4/libsysV_2/mknod.s | 12 ++++++ mach/vax4/libsysV_2/mount.s | 12 ++++++ mach/vax4/libsysV_2/msg.s | 61 +++++++++++++++++++++++++++ mach/vax4/libsysV_2/nexect.s | 9 ++++ mach/vax4/libsysV_2/nice.s | 11 +++++ mach/vax4/libsysV_2/open.s | 11 +++++ mach/vax4/libsysV_2/pause.s | 12 ++++++ mach/vax4/libsysV_2/pipe.s | 15 +++++++ mach/vax4/libsysV_2/plock.s | 11 +++++ mach/vax4/libsysV_2/profil.s | 7 ++++ mach/vax4/libsysV_2/ptrace.s | 13 ++++++ mach/vax4/libsysV_2/read.s | 11 +++++ mach/vax4/libsysV_2/sbrk.s | 40 ++++++++++++++++++ mach/vax4/libsysV_2/sem.s | 41 ++++++++++++++++++ mach/vax4/libsysV_2/setgid.s | 12 ++++++ mach/vax4/libsysV_2/setpgrp.s | 20 +++++++++ mach/vax4/libsysV_2/setuid.s | 12 ++++++ mach/vax4/libsysV_2/shm.s | 57 +++++++++++++++++++++++++ mach/vax4/libsysV_2/signal.s | 11 +++++ mach/vax4/libsysV_2/stat.s | 12 ++++++ mach/vax4/libsysV_2/stime.s | 13 ++++++ mach/vax4/libsysV_2/stty.s | 11 +++++ mach/vax4/libsysV_2/sync.s | 7 ++++ mach/vax4/libsysV_2/syscall.s | 12 ++++++ mach/vax4/libsysV_2/time.s | 11 +++++ mach/vax4/libsysV_2/times.s | 11 +++++ mach/vax4/libsysV_2/ulimit.s | 11 +++++ mach/vax4/libsysV_2/umask.s | 11 +++++ mach/vax4/libsysV_2/umount.s | 12 ++++++ mach/vax4/libsysV_2/uname.s | 21 ++++++++++ mach/vax4/libsysV_2/unlink.s | 12 ++++++ mach/vax4/libsysV_2/ustat.s | 20 +++++++++ mach/vax4/libsysV_2/utime.s | 11 +++++ mach/vax4/libsysV_2/wait.s | 15 +++++++ mach/vax4/libsysV_2/write.s | 11 +++++ 71 files changed, 1004 insertions(+) create mode 100644 mach/vax4/libsysV_2/Makefile create mode 100644 mach/vax4/libsysV_2/_exit.s create mode 100644 mach/vax4/libsysV_2/access.s create mode 100644 mach/vax4/libsysV_2/acct.s create mode 100644 mach/vax4/libsysV_2/alarm.s create mode 100644 mach/vax4/libsysV_2/cerror.s create mode 100644 mach/vax4/libsysV_2/chdir.s create mode 100644 mach/vax4/libsysV_2/chmod.s create mode 100644 mach/vax4/libsysV_2/chown.s create mode 100644 mach/vax4/libsysV_2/chroot.s create mode 100644 mach/vax4/libsysV_2/cleanup.c create mode 100644 mach/vax4/libsysV_2/close.s create mode 100755 mach/vax4/libsysV_2/compmodule create mode 100644 mach/vax4/libsysV_2/creat.s create mode 100644 mach/vax4/libsysV_2/dup.s create mode 100644 mach/vax4/libsysV_2/dup2.c create mode 100644 mach/vax4/libsysV_2/execl.s create mode 100644 mach/vax4/libsysV_2/execle.s create mode 100644 mach/vax4/libsysV_2/execv.s create mode 100644 mach/vax4/libsysV_2/execve.s create mode 100644 mach/vax4/libsysV_2/exit.c create mode 100644 mach/vax4/libsysV_2/fcntl.s create mode 100644 mach/vax4/libsysV_2/fork.s create mode 100644 mach/vax4/libsysV_2/fstat.s create mode 100644 mach/vax4/libsysV_2/getegid.s create mode 100644 mach/vax4/libsysV_2/geteuid.s create mode 100644 mach/vax4/libsysV_2/getgid.s create mode 100644 mach/vax4/libsysV_2/getpid.s create mode 100644 mach/vax4/libsysV_2/getppid.s create mode 100644 mach/vax4/libsysV_2/getuid.s create mode 100644 mach/vax4/libsysV_2/gtty.s create mode 100644 mach/vax4/libsysV_2/head_em.s create mode 100644 mach/vax4/libsysV_2/ioctl.s create mode 100644 mach/vax4/libsysV_2/kill.s create mode 100644 mach/vax4/libsysV_2/link.s create mode 100644 mach/vax4/libsysV_2/lseek.s create mode 100644 mach/vax4/libsysV_2/mknod.s create mode 100644 mach/vax4/libsysV_2/mount.s create mode 100644 mach/vax4/libsysV_2/msg.s create mode 100644 mach/vax4/libsysV_2/nexect.s create mode 100644 mach/vax4/libsysV_2/nice.s create mode 100644 mach/vax4/libsysV_2/open.s create mode 100644 mach/vax4/libsysV_2/pause.s create mode 100644 mach/vax4/libsysV_2/pipe.s create mode 100644 mach/vax4/libsysV_2/plock.s create mode 100644 mach/vax4/libsysV_2/profil.s create mode 100644 mach/vax4/libsysV_2/ptrace.s create mode 100644 mach/vax4/libsysV_2/read.s create mode 100644 mach/vax4/libsysV_2/sbrk.s create mode 100644 mach/vax4/libsysV_2/sem.s create mode 100644 mach/vax4/libsysV_2/setgid.s create mode 100644 mach/vax4/libsysV_2/setpgrp.s create mode 100644 mach/vax4/libsysV_2/setuid.s create mode 100644 mach/vax4/libsysV_2/shm.s create mode 100644 mach/vax4/libsysV_2/signal.s create mode 100644 mach/vax4/libsysV_2/stat.s create mode 100644 mach/vax4/libsysV_2/stime.s create mode 100644 mach/vax4/libsysV_2/stty.s create mode 100644 mach/vax4/libsysV_2/sync.s create mode 100644 mach/vax4/libsysV_2/syscall.s create mode 100644 mach/vax4/libsysV_2/time.s create mode 100644 mach/vax4/libsysV_2/times.s create mode 100644 mach/vax4/libsysV_2/ulimit.s create mode 100644 mach/vax4/libsysV_2/umask.s create mode 100644 mach/vax4/libsysV_2/umount.s create mode 100644 mach/vax4/libsysV_2/uname.s create mode 100644 mach/vax4/libsysV_2/unlink.s create mode 100644 mach/vax4/libsysV_2/ustat.s create mode 100644 mach/vax4/libsysV_2/utime.s create mode 100644 mach/vax4/libsysV_2/wait.s create mode 100644 mach/vax4/libsysV_2/write.s diff --git a/mach/vax4/libsysV_2/Makefile b/mach/vax4/libsysV_2/Makefile new file mode 100644 index 00000000..6dd093d6 --- /dev/null +++ b/mach/vax4/libsysV_2/Makefile @@ -0,0 +1,31 @@ +# $Header$ +all: head_em.o libmon_o.a + +install: cp + +cp: all + ../../install head_em.o head_em + ../../install libmon_o.a tail_mon + +cmp: all + -../../compare head_em.o head_em + -../../compare libmon_o.a tail_mon + + +head_em.o: head_em.s + vax4 -I../../../h -c head_em.s + +libmon_o.a: libmon_s.a + ASAR=ar ; export ASAR ;\ + RANLIB=ranlib ; export RANLIB ;\ + march . libmon_o.a + +clean: + rm -f *.o libmon_o.a + +opr: + make pr | opr + +pr: + @pr `pwd`/Makefile `pwd`/head_em.s + @arch pv libmon_s.a | pr -h `pwd`/libmon_s.a diff --git a/mach/vax4/libsysV_2/_exit.s b/mach/vax4/libsysV_2/_exit.s new file mode 100644 index 00000000..6c041483 --- /dev/null +++ b/mach/vax4/libsysV_2/_exit.s @@ -0,0 +1,7 @@ +.set exit,1 +.globl __exit + +__exit: + .word 0x0000 + chmk $exit + halt diff --git a/mach/vax4/libsysV_2/access.s b/mach/vax4/libsysV_2/access.s new file mode 100644 index 00000000..d3e25398 --- /dev/null +++ b/mach/vax4/libsysV_2/access.s @@ -0,0 +1,11 @@ +.set access,33 +.globl _access +.globl cerror + +_access: + .word 0x0000 + chmk $access + bcc ok + jmp cerror +ok: + ret diff --git a/mach/vax4/libsysV_2/acct.s b/mach/vax4/libsysV_2/acct.s new file mode 100644 index 00000000..dc0af6bb --- /dev/null +++ b/mach/vax4/libsysV_2/acct.s @@ -0,0 +1,11 @@ +.set acct,51 +.globl _acct +.globl cerror + +_acct: + .word 0x0000 + chmk $acct + bcc ok + jmp cerror +ok: + ret diff --git a/mach/vax4/libsysV_2/alarm.s b/mach/vax4/libsysV_2/alarm.s new file mode 100644 index 00000000..f35a9814 --- /dev/null +++ b/mach/vax4/libsysV_2/alarm.s @@ -0,0 +1,7 @@ +.set alarm,27 +.globl _alarm + +_alarm: + .word 0x0000 + chmk $alarm + ret diff --git a/mach/vax4/libsysV_2/cerror.s b/mach/vax4/libsysV_2/cerror.s new file mode 100644 index 00000000..3c141fde --- /dev/null +++ b/mach/vax4/libsysV_2/cerror.s @@ -0,0 +1,11 @@ +.globl cerror +.globl _errno + +.data +_errno: .long 0 + +.text +cerror: + movl r0,_errno + mnegl $1,r0 + ret diff --git a/mach/vax4/libsysV_2/chdir.s b/mach/vax4/libsysV_2/chdir.s new file mode 100644 index 00000000..377630d1 --- /dev/null +++ b/mach/vax4/libsysV_2/chdir.s @@ -0,0 +1,12 @@ +.set chdir,12 +.globl _chdir +.globl cerror + +_chdir: + .word 0x0000 + chmk $chdir + bcc ok + jmp cerror +ok: + clrl r0 + ret diff --git a/mach/vax4/libsysV_2/chmod.s b/mach/vax4/libsysV_2/chmod.s new file mode 100644 index 00000000..9166e55a --- /dev/null +++ b/mach/vax4/libsysV_2/chmod.s @@ -0,0 +1,12 @@ +.set chmod,15 +.globl _chmod +.globl cerror + +_chmod: + .word 0x0000 + chmk $chmod + bcc ok + jmp cerror +ok: + clrl r0 + ret diff --git a/mach/vax4/libsysV_2/chown.s b/mach/vax4/libsysV_2/chown.s new file mode 100644 index 00000000..a1fb9cf2 --- /dev/null +++ b/mach/vax4/libsysV_2/chown.s @@ -0,0 +1,12 @@ +.set chown,16 +.globl _chown +.globl cerror + +_chown: + .word 0x0000 + chmk $chown + bcc ok + jmp cerror +ok: + clrl r0 + ret diff --git a/mach/vax4/libsysV_2/chroot.s b/mach/vax4/libsysV_2/chroot.s new file mode 100644 index 00000000..4d4aa008 --- /dev/null +++ b/mach/vax4/libsysV_2/chroot.s @@ -0,0 +1,11 @@ +.set chroot,61 +.globl _chroot +.globl cerror + +_chroot: + .word 0x0000 + chmk $chroot + bcc ok + jmp cerror +ok: + ret diff --git a/mach/vax4/libsysV_2/cleanup.c b/mach/vax4/libsysV_2/cleanup.c new file mode 100644 index 00000000..6cd9c63e --- /dev/null +++ b/mach/vax4/libsysV_2/cleanup.c @@ -0,0 +1 @@ +_cleanup() { } diff --git a/mach/vax4/libsysV_2/close.s b/mach/vax4/libsysV_2/close.s new file mode 100644 index 00000000..706ee240 --- /dev/null +++ b/mach/vax4/libsysV_2/close.s @@ -0,0 +1,12 @@ +.set close,6 +.globl _close +.globl cerror + +_close: + .word 0x0000 + chmk $close + bcc ok + jmp cerror +ok: + clrl r0 + ret diff --git a/mach/vax4/libsysV_2/compmodule b/mach/vax4/libsysV_2/compmodule new file mode 100755 index 00000000..67777e8a --- /dev/null +++ b/mach/vax4/libsysV_2/compmodule @@ -0,0 +1,4 @@ +if vax4 -O -c -I../../../h -I. $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 +fi diff --git a/mach/vax4/libsysV_2/creat.s b/mach/vax4/libsysV_2/creat.s new file mode 100644 index 00000000..34471d01 --- /dev/null +++ b/mach/vax4/libsysV_2/creat.s @@ -0,0 +1,11 @@ +.set creat,8 +.globl _creat +.globl cerror + +_creat: + .word 0x0000 + chmk $creat + bcc ok + jmp cerror +ok: + ret diff --git a/mach/vax4/libsysV_2/dup.s b/mach/vax4/libsysV_2/dup.s new file mode 100644 index 00000000..eaa03752 --- /dev/null +++ b/mach/vax4/libsysV_2/dup.s @@ -0,0 +1,11 @@ +.set dup,41 +.globl _dup +.globl cerror + +_dup: + .word 0x0000 + chmk $dup + bcc ok + jmp cerror +ok: + ret diff --git a/mach/vax4/libsysV_2/dup2.c b/mach/vax4/libsysV_2/dup2.c new file mode 100644 index 00000000..c672adbb --- /dev/null +++ b/mach/vax4/libsysV_2/dup2.c @@ -0,0 +1,6 @@ +int +dup2(oldfd, newfd) +{ + close(newfd); + return fcntl(oldfd, 0, newfd); +} diff --git a/mach/vax4/libsysV_2/execl.s b/mach/vax4/libsysV_2/execl.s new file mode 100644 index 00000000..32261327 --- /dev/null +++ b/mach/vax4/libsysV_2/execl.s @@ -0,0 +1,9 @@ +.globl _execl +.globl _execv + +_execl: + .word 0x0000 + pushab 8(ap) + pushl 4(ap) + calls $2,_execv + ret diff --git a/mach/vax4/libsysV_2/execle.s b/mach/vax4/libsysV_2/execle.s new file mode 100644 index 00000000..8b681825 --- /dev/null +++ b/mach/vax4/libsysV_2/execle.s @@ -0,0 +1,11 @@ +.globl _execle +.globl _execve + +_execle: + .word 0x0000 + movl (ap),r0 + pushl (ap)[r0] + pushab 8(ap) + pushl 4(ap) + calls $3,_execve + ret diff --git a/mach/vax4/libsysV_2/execv.s b/mach/vax4/libsysV_2/execv.s new file mode 100644 index 00000000..60e4d874 --- /dev/null +++ b/mach/vax4/libsysV_2/execv.s @@ -0,0 +1,11 @@ +.globl _execv +.globl _execve +.globl _environ + +_execv: + .word 0x0000 + pushl _environ + pushl 8(ap) + pushl 4(ap) + calls $3,_execve + ret diff --git a/mach/vax4/libsysV_2/execve.s b/mach/vax4/libsysV_2/execve.s new file mode 100644 index 00000000..d894740c --- /dev/null +++ b/mach/vax4/libsysV_2/execve.s @@ -0,0 +1,8 @@ +.set exece,59 +.globl _execve +.globl cerror + +_execve: + .word 0x0000 + chmk $exece + jmp cerror diff --git a/mach/vax4/libsysV_2/exit.c b/mach/vax4/libsysV_2/exit.c new file mode 100644 index 00000000..89d4723d --- /dev/null +++ b/mach/vax4/libsysV_2/exit.c @@ -0,0 +1 @@ +exit(n) { _cleanup(); _exit(n); } diff --git a/mach/vax4/libsysV_2/fcntl.s b/mach/vax4/libsysV_2/fcntl.s new file mode 100644 index 00000000..4ee161e2 --- /dev/null +++ b/mach/vax4/libsysV_2/fcntl.s @@ -0,0 +1,11 @@ +.set fcntl,62 +.globl _fcntl +.globl cerror + +_fcntl: + .word 0x0000 + chmk $fcntl + bcc ok + jmp cerror +ok: + ret diff --git a/mach/vax4/libsysV_2/fork.s b/mach/vax4/libsysV_2/fork.s new file mode 100644 index 00000000..296a97ac --- /dev/null +++ b/mach/vax4/libsysV_2/fork.s @@ -0,0 +1,14 @@ +.set fork,2 +.globl _fork +.globl cerror + +_fork: + .word 0x0000 + chmk $fork + bcc ok + jmp cerror +ok: + blbc r1,out + clrl r0 +out: + ret diff --git a/mach/vax4/libsysV_2/fstat.s b/mach/vax4/libsysV_2/fstat.s new file mode 100644 index 00000000..b3e8d256 --- /dev/null +++ b/mach/vax4/libsysV_2/fstat.s @@ -0,0 +1,12 @@ +.set fstat,28 +.globl _fstat +.globl cerror + +_fstat: + .word 0x0000 + chmk $fstat + bcc ok + jmp cerror +ok: + clrl r0 + ret diff --git a/mach/vax4/libsysV_2/getegid.s b/mach/vax4/libsysV_2/getegid.s new file mode 100644 index 00000000..ab35f849 --- /dev/null +++ b/mach/vax4/libsysV_2/getegid.s @@ -0,0 +1,8 @@ +.set getgid,47 +.globl _getegid + +_getegid: + .word 0x0000 + chmk $getgid + movl r1,r0 + ret diff --git a/mach/vax4/libsysV_2/geteuid.s b/mach/vax4/libsysV_2/geteuid.s new file mode 100644 index 00000000..d5cd917e --- /dev/null +++ b/mach/vax4/libsysV_2/geteuid.s @@ -0,0 +1,8 @@ +.set getuid,24 +.globl _geteuid + +_geteuid: + .word 0x0000 + chmk $getuid + movl r1,r0 + ret diff --git a/mach/vax4/libsysV_2/getgid.s b/mach/vax4/libsysV_2/getgid.s new file mode 100644 index 00000000..0dca6f3c --- /dev/null +++ b/mach/vax4/libsysV_2/getgid.s @@ -0,0 +1,7 @@ +.set getgid,47 +.globl _getgid + +_getgid: + .word 0x0000 + chmk $getgid + ret diff --git a/mach/vax4/libsysV_2/getpid.s b/mach/vax4/libsysV_2/getpid.s new file mode 100644 index 00000000..c51614c5 --- /dev/null +++ b/mach/vax4/libsysV_2/getpid.s @@ -0,0 +1,7 @@ +.set getpid,20 +.globl _getpid + +_getpid: + .word 0x0000 + chmk $getpid + ret diff --git a/mach/vax4/libsysV_2/getppid.s b/mach/vax4/libsysV_2/getppid.s new file mode 100644 index 00000000..59bd5bbb --- /dev/null +++ b/mach/vax4/libsysV_2/getppid.s @@ -0,0 +1,8 @@ +.set getpid,20 +.globl _getppid + +_getppid: + .word 0x0000 + chmk $getpid + movl r1,r0 + ret diff --git a/mach/vax4/libsysV_2/getuid.s b/mach/vax4/libsysV_2/getuid.s new file mode 100644 index 00000000..1764ca31 --- /dev/null +++ b/mach/vax4/libsysV_2/getuid.s @@ -0,0 +1,7 @@ +.set getuid,24 +.globl _getuid + +_getuid: + .word 0x0000 + chmk $getuid + ret diff --git a/mach/vax4/libsysV_2/gtty.s b/mach/vax4/libsysV_2/gtty.s new file mode 100644 index 00000000..09ec1537 --- /dev/null +++ b/mach/vax4/libsysV_2/gtty.s @@ -0,0 +1,11 @@ +.set gtty,32 +.globl _gtty +.globl cerror + +_gtty: + .word 0x0000 + chmk $gtty + bcc ok + jmp cerror +ok: + ret diff --git a/mach/vax4/libsysV_2/head_em.s b/mach/vax4/libsysV_2/head_em.s new file mode 100644 index 00000000..2608535e --- /dev/null +++ b/mach/vax4/libsysV_2/head_em.s @@ -0,0 +1,76 @@ +#include "em_abs.h" + + # $Header$ + +.globl hol0 +.globl .reghp +.globl .trppc +.globl .trpim + + # run time startoff + .word 0 + bispsw $0100 # set FU(0100) + movl 4(sp),r0 + clrl -4(r0) + movl sp,r0 + movl (r0)+,r1 + movl r0,r2 +a1: + tstl (r0)+ + bneq a1 + cmpl r0,(r2) + blssu a2 + tstl -(r0) +a2: + pushl r0 + pushl r2 + pushl r1 + movl $m1,ap + chmk (ap)+ # catch floating point exception + calls $3,_m_a_i_n + movl $m2,ap + movl r0,6(ap) + chmk (ap)+ + halt + + .align 1 +sig8: + .word 0x0000 + pushl 8(ap) + movl (sp)+,ap + pushl tab [ap] + jsb .trp + movl $m1,ap + chmk (ap)+ + ret + + .data +m1: + .word 48 + .long 2 + .long 8 + .long sig8 +m2: + .word 1 + .long 1 + .long 0 +.reghp: + .long _end +hol0: + .space 8 +.trppc: + .space 4 +.trpim: + .long 0 +tab: + .long 0 + .long EIOVFL + .long EIDIVZ + .long EFOVFL + .long EFDIVZ + .long EFUNFL + .long EILLINS + .long EARRAY + .long EFOVFL + .long EFDIVZ + .long EFUNFL diff --git a/mach/vax4/libsysV_2/ioctl.s b/mach/vax4/libsysV_2/ioctl.s new file mode 100644 index 00000000..44128206 --- /dev/null +++ b/mach/vax4/libsysV_2/ioctl.s @@ -0,0 +1,11 @@ +.set ioctl,54 +.globl _ioctl +.globl cerror + +_ioctl: + .word 0x0000 + chmk $ioctl + bcc ok + jmp cerror +ok: + ret diff --git a/mach/vax4/libsysV_2/kill.s b/mach/vax4/libsysV_2/kill.s new file mode 100644 index 00000000..48da70a6 --- /dev/null +++ b/mach/vax4/libsysV_2/kill.s @@ -0,0 +1,12 @@ +.set kill,37 +.globl _kill +.globl cerror + +_kill: + .word 0x0000 + chmk $kill + bcc ok + jmp cerror +ok: + clrl r0 + ret diff --git a/mach/vax4/libsysV_2/link.s b/mach/vax4/libsysV_2/link.s new file mode 100644 index 00000000..b2364f77 --- /dev/null +++ b/mach/vax4/libsysV_2/link.s @@ -0,0 +1,12 @@ +.set link,9 +.globl _link +.globl cerror + +_link: + .word 0x0000 + chmk $link + bcc ok + jmp cerror +ok: + clrl r0 + ret diff --git a/mach/vax4/libsysV_2/lseek.s b/mach/vax4/libsysV_2/lseek.s new file mode 100644 index 00000000..652bdabd --- /dev/null +++ b/mach/vax4/libsysV_2/lseek.s @@ -0,0 +1,11 @@ +.set lseek,19 +.globl _lseek +.globl cerror + +_lseek: + .word 0x0000 + chmk $lseek + bcc ok + jmp cerror +ok: + ret diff --git a/mach/vax4/libsysV_2/mknod.s b/mach/vax4/libsysV_2/mknod.s new file mode 100644 index 00000000..5ed673fd --- /dev/null +++ b/mach/vax4/libsysV_2/mknod.s @@ -0,0 +1,12 @@ +.set mknod,14 +.globl _mknod +.globl cerror + +_mknod: + .word 0x0000 + chmk $mknod + bcc ok + jmp cerror +ok: + clrl r0 + ret diff --git a/mach/vax4/libsysV_2/mount.s b/mach/vax4/libsysV_2/mount.s new file mode 100644 index 00000000..166368c5 --- /dev/null +++ b/mach/vax4/libsysV_2/mount.s @@ -0,0 +1,12 @@ +.set mount,21 +.globl _mount +.globl cerror + +_mount: + .word 0x0000 + chmk $mount + bcc ok + jmp cerror +ok: + clrl r0 + ret diff --git a/mach/vax4/libsysV_2/msg.s b/mach/vax4/libsysV_2/msg.s new file mode 100644 index 00000000..43e614e4 --- /dev/null +++ b/mach/vax4/libsysV_2/msg.s @@ -0,0 +1,61 @@ +.set msg,49 +.globl _msgrcv +.globl _msgctl +.globl _msgsnd +.globl _msgget +.globl cerror + +_msgsnd: + .word 0x0000 + pushl 16(ap) + pushl 12(ap) + pushl 8(ap) + pushl 4(ap) + pushl $3 + calls $5,sys + ret + +_msgrcv: + .word 0x0000 + pushl 20(sp) + pushl 16(ap) + pushl 12(ap) + pushl 8(ap) + pushl 4(ap) + pushl $2 + calls $6,sys1 + ret + +_msgctl: + .word 0x0000 + pushl 12(ap) + pushl 8(ap) + pushl 4(ap) + pushl $1 + calls $4,sys + ret + +_msgget: + .word 0x0000 + pushl 8(ap) + pushl 4(ap) + pushl $0 + calls $3,sys1 + ret + +sys: + .word 0x0000 + chmk $msg + bcc ok + jmp cerror +ok: + clrl r0 + ret + +sys1: + .word 0x0000 + chmk $msg + bcc ok1 + jmp cerror +ok1: + ret diff --git a/mach/vax4/libsysV_2/nexect.s b/mach/vax4/libsysV_2/nexect.s new file mode 100644 index 00000000..148fdb94 --- /dev/null +++ b/mach/vax4/libsysV_2/nexect.s @@ -0,0 +1,9 @@ +.set execve,59 +.globl _exect +.globl cerror + +_exect: + .word 0x0000 + bispsw $0x10 + chmk $execve + jmp cerror diff --git a/mach/vax4/libsysV_2/nice.s b/mach/vax4/libsysV_2/nice.s new file mode 100644 index 00000000..a3d29e9f --- /dev/null +++ b/mach/vax4/libsysV_2/nice.s @@ -0,0 +1,11 @@ +.set nice,34 +.globl _nice +.globl cerror + +_nice: + .word 0x0000 + chmk $nice + bcc ok + jmp cerror +ok: + ret diff --git a/mach/vax4/libsysV_2/open.s b/mach/vax4/libsysV_2/open.s new file mode 100644 index 00000000..3a1d0c40 --- /dev/null +++ b/mach/vax4/libsysV_2/open.s @@ -0,0 +1,11 @@ +.set open,5 +.globl _open +.globl cerror + +_open: + .word 0x0000 + chmk $open + bcc ok + jmp cerror +ok: + ret diff --git a/mach/vax4/libsysV_2/pause.s b/mach/vax4/libsysV_2/pause.s new file mode 100644 index 00000000..71b04b8c --- /dev/null +++ b/mach/vax4/libsysV_2/pause.s @@ -0,0 +1,12 @@ +.set pause,29 +.globl _pause +.globl cerror + +_pause: + .word 0x0000 + chmk $pause + bcc ok + jmp cerror +ok: + clrl r0 + ret diff --git a/mach/vax4/libsysV_2/pipe.s b/mach/vax4/libsysV_2/pipe.s new file mode 100644 index 00000000..49a577c4 --- /dev/null +++ b/mach/vax4/libsysV_2/pipe.s @@ -0,0 +1,15 @@ +.set pipe,42 +.globl _pipe +.globl cerror + +_pipe: + .word 0x0000 + chmk $pipe + bcc ok + jmp cerror +ok: + movl 4(ap),r2 + movl r0,(r2)+ + movl r1,(r2) + clrl r0 + ret diff --git a/mach/vax4/libsysV_2/plock.s b/mach/vax4/libsysV_2/plock.s new file mode 100644 index 00000000..ddc2d390 --- /dev/null +++ b/mach/vax4/libsysV_2/plock.s @@ -0,0 +1,11 @@ +.set plock,45 +.globl _plock +.globl cerror + +_plock: + .word 0x0000 + chmk $plock + bcc ok + jmp cerror +ok: + ret diff --git a/mach/vax4/libsysV_2/profil.s b/mach/vax4/libsysV_2/profil.s new file mode 100644 index 00000000..5dc9f547 --- /dev/null +++ b/mach/vax4/libsysV_2/profil.s @@ -0,0 +1,7 @@ +.set prof,44 +.globl _profil + +_profil: + .word 0x0000 + chmk $prof + ret diff --git a/mach/vax4/libsysV_2/ptrace.s b/mach/vax4/libsysV_2/ptrace.s new file mode 100644 index 00000000..65f4eb8c --- /dev/null +++ b/mach/vax4/libsysV_2/ptrace.s @@ -0,0 +1,13 @@ +.set ptrace,26 +.globl _ptrace +.globl _errno +.globl cerror + +_ptrace: + .word 0x0000 + clrl _errno + chmk $ptrace + bcc ok + jmp cerror +ok: + ret diff --git a/mach/vax4/libsysV_2/read.s b/mach/vax4/libsysV_2/read.s new file mode 100644 index 00000000..74981331 --- /dev/null +++ b/mach/vax4/libsysV_2/read.s @@ -0,0 +1,11 @@ +.set read,3 +.globl _read +.globl cerror + +_read: + .word 0x0000 + chmk $read + bcc ok + jmp cerror +ok: + ret diff --git a/mach/vax4/libsysV_2/sbrk.s b/mach/vax4/libsysV_2/sbrk.s new file mode 100644 index 00000000..3c952cb8 --- /dev/null +++ b/mach/vax4/libsysV_2/sbrk.s @@ -0,0 +1,40 @@ +.set break,17 +.globl _sbrk +.globl _brk +.globl _end +.globl cerror + +_sbrk: + .word 0x0000 + movl nd,r0 + tstl 4(ap) + jeql out + addl3 r0,4(ap),-(sp) + bcs ovfl + pushl $1 + movl ap,r3 + movl sp,ap + chmk $break + bcc ok +ovfl: + jmp cerror +ok: + movl nd,r0 + addl2 4(r3),nd +out: + ret + +.globl _brk + +_brk: + .word 0x0000 + chmk $break + bcc ok2 + jmp cerror +ok2: + movl 4(ap),nd + clrl r0 + ret + + .data +nd: .long _end diff --git a/mach/vax4/libsysV_2/sem.s b/mach/vax4/libsysV_2/sem.s new file mode 100644 index 00000000..2f996c1d --- /dev/null +++ b/mach/vax4/libsysV_2/sem.s @@ -0,0 +1,41 @@ +.set sem,53 +.globl _semctl +.globl _semget +.globl _semop +.globl cerror + +_semop: + .word 0x0000 + pushl 12(ap) + pushl 8(ap) + pushl 4(ap) + pushl $2 + calls $4,sys1 + ret + +_semctl: + .word 0x0000 + pushl 16(ap) + pushl 12(ap) + pushl 8(ap) + pushl 4(ap) + pushl $1 + calls $5,sys1 + ret + +_semget: + .word 0x0000 + pushl 12(ap) + pushl 8(ap) + pushl 4(ap) + pushl $0 + calls $4,sys1 + ret + +sys1: + .word 0x0000 + chmk $sem + bcc ok1 + jmp cerror +ok1: + ret diff --git a/mach/vax4/libsysV_2/setgid.s b/mach/vax4/libsysV_2/setgid.s new file mode 100644 index 00000000..7d84e5c2 --- /dev/null +++ b/mach/vax4/libsysV_2/setgid.s @@ -0,0 +1,12 @@ +.set setgid,46 +.globl _setgid +.globl cerror + +_setgid: + .word 0x0000 + chmk $setgid + bcc ok + jmp cerror +ok: + clrl r0 + ret diff --git a/mach/vax4/libsysV_2/setpgrp.s b/mach/vax4/libsysV_2/setpgrp.s new file mode 100644 index 00000000..c86f3664 --- /dev/null +++ b/mach/vax4/libsysV_2/setpgrp.s @@ -0,0 +1,20 @@ +.set setpgrp,39 +.globl _setpgrp +.globl _getpgrp + +_setpgrp: + .word 0x0000 + pushl $1 + calls $1,pgrp + ret + +_getpgrp: + .word 0x0000 + pushl $0 + calls $1,pgrp + ret + +pgrp: + .word 0x0000 + chmk $setpgrp + ret diff --git a/mach/vax4/libsysV_2/setuid.s b/mach/vax4/libsysV_2/setuid.s new file mode 100644 index 00000000..66592999 --- /dev/null +++ b/mach/vax4/libsysV_2/setuid.s @@ -0,0 +1,12 @@ +.set setuid,23 +.globl _setuid +.globl cerror + +_setuid: + .word 0x0000 + chmk $setuid + bcc ok + jmp cerror +ok: + clrl r0 + ret diff --git a/mach/vax4/libsysV_2/shm.s b/mach/vax4/libsysV_2/shm.s new file mode 100644 index 00000000..132f5b39 --- /dev/null +++ b/mach/vax4/libsysV_2/shm.s @@ -0,0 +1,57 @@ +.set shm,52 +.globl _shmat +.globl _shmctl +.globl _shmdt +.globl _shmget +.globl cerror + +_shmat: + .word 0x0000 + pushl 12(ap) + pushl 8(ap) + pushl 4(ap) + pushl $0 + calls $4,sys1 + ret + +_shmdt: + .word 0x0000 + pushl 4(ap) + pushl $2 + calls $2,sys + ret + +_shmctl: + .word 0x0000 + pushl 12(ap) + pushl 8(ap) + pushl 4(ap) + pushl $1 + calls $4,sys + ret + +_shmget: + .word 0x0000 + pushl 12(ap) + pushl 8(ap) + pushl 4(ap) + pushl $3 + calls $4,sys1 + ret + +sys: + .word 0x0000 + chmk $shm + bcc ok + jmp cerror +ok: + clrl r0 + ret + +sys1: + .word 0x0000 + chmk $shm + bcc ok1 + jmp cerror +ok1: + ret diff --git a/mach/vax4/libsysV_2/signal.s b/mach/vax4/libsysV_2/signal.s new file mode 100644 index 00000000..241de205 --- /dev/null +++ b/mach/vax4/libsysV_2/signal.s @@ -0,0 +1,11 @@ +.set signal,48 +.globl _signal +.globl cerror + +_signal: + .word 0x0000 + chmk $signal + bcc ok + jmp cerror +ok: + ret diff --git a/mach/vax4/libsysV_2/stat.s b/mach/vax4/libsysV_2/stat.s new file mode 100644 index 00000000..82785b1d --- /dev/null +++ b/mach/vax4/libsysV_2/stat.s @@ -0,0 +1,12 @@ +.set stat,18 +.globl _stat +.globl cerror + +_stat: + .word 0x0000 + chmk $stat + bcc ok + jmp cerror +ok: + clrl r0 + ret diff --git a/mach/vax4/libsysV_2/stime.s b/mach/vax4/libsysV_2/stime.s new file mode 100644 index 00000000..9c326702 --- /dev/null +++ b/mach/vax4/libsysV_2/stime.s @@ -0,0 +1,13 @@ +.set stime,25 +.globl _stime +.globl cerror + +_stime: + .word 0x0000 + movl *4(ap),4(ap) + chmk $stime + bcc ok + jmp cerror +ok: + clrl r0 + ret diff --git a/mach/vax4/libsysV_2/stty.s b/mach/vax4/libsysV_2/stty.s new file mode 100644 index 00000000..d752cab4 --- /dev/null +++ b/mach/vax4/libsysV_2/stty.s @@ -0,0 +1,11 @@ +.set stty,31 +.globl _stty +.globl cerror + +_stty: + .word 0x0000 + chmk $stty + bcc ok + jmp cerror +ok: + ret diff --git a/mach/vax4/libsysV_2/sync.s b/mach/vax4/libsysV_2/sync.s new file mode 100644 index 00000000..60b9ae47 --- /dev/null +++ b/mach/vax4/libsysV_2/sync.s @@ -0,0 +1,7 @@ +.set sync,36 +.globl _sync + +_sync: + .word 0x0000 + chmk $sync + ret diff --git a/mach/vax4/libsysV_2/syscall.s b/mach/vax4/libsysV_2/syscall.s new file mode 100644 index 00000000..45e6a7f9 --- /dev/null +++ b/mach/vax4/libsysV_2/syscall.s @@ -0,0 +1,12 @@ +.globl _syscall +.globl cerror + +_syscall: + .word 0x0000 + movl 4(ap),r0 + subl3 $1,(ap)+,(ap) + chmk r0 + bcc ok + jmp cerror +ok: + ret diff --git a/mach/vax4/libsysV_2/time.s b/mach/vax4/libsysV_2/time.s new file mode 100644 index 00000000..f719a312 --- /dev/null +++ b/mach/vax4/libsysV_2/time.s @@ -0,0 +1,11 @@ +.set time,13 +.globl _time + +_time: + .word 0x0000 + chmk $time + movl 4(ap),r1 + beql out + movl r0,(r1) +out: + ret diff --git a/mach/vax4/libsysV_2/times.s b/mach/vax4/libsysV_2/times.s new file mode 100644 index 00000000..bdbbc75c --- /dev/null +++ b/mach/vax4/libsysV_2/times.s @@ -0,0 +1,11 @@ +.set times,43 +.globl _times +.globl cerror + +_times: + .word 0x0000 + chmk $times + bcc ok + jmp cerror +ok: + ret diff --git a/mach/vax4/libsysV_2/ulimit.s b/mach/vax4/libsysV_2/ulimit.s new file mode 100644 index 00000000..fa60ea07 --- /dev/null +++ b/mach/vax4/libsysV_2/ulimit.s @@ -0,0 +1,11 @@ +.set ulimit,63 +.globl _ulimit +.globl cerror + +_ulimit: + .word 0x0000 + chmk $ulimit + bcc ok + jmp cerror +ok: + ret diff --git a/mach/vax4/libsysV_2/umask.s b/mach/vax4/libsysV_2/umask.s new file mode 100644 index 00000000..add8702e --- /dev/null +++ b/mach/vax4/libsysV_2/umask.s @@ -0,0 +1,11 @@ +.set umask,60 +.globl _umask +.globl cerror + +_umask: + .word 0x0000 + chmk $umask + bcc ok + jmp cerror +ok: + ret diff --git a/mach/vax4/libsysV_2/umount.s b/mach/vax4/libsysV_2/umount.s new file mode 100644 index 00000000..2a6d2305 --- /dev/null +++ b/mach/vax4/libsysV_2/umount.s @@ -0,0 +1,12 @@ +.set umount,22 +.globl _umount +.globl cerror + +_umount: + .word 0x0000 + chmk $umount + bcc ok + jmp cerror +ok: + clrl r0 + ret diff --git a/mach/vax4/libsysV_2/uname.s b/mach/vax4/libsysV_2/uname.s new file mode 100644 index 00000000..409f4e75 --- /dev/null +++ b/mach/vax4/libsysV_2/uname.s @@ -0,0 +1,21 @@ +.set utssys,57 + +.globl _uname +.globl cerror + +_uname: + .word 0x0000 + pushl $0 + pushl $0 + pushl 4(ap) + calls $3,sys + ret + +sys: + .word 0x0000 + chmk $utssys + bcc ok + jmp cerror +ok: + clrl r0 + ret diff --git a/mach/vax4/libsysV_2/unlink.s b/mach/vax4/libsysV_2/unlink.s new file mode 100644 index 00000000..f57b642f --- /dev/null +++ b/mach/vax4/libsysV_2/unlink.s @@ -0,0 +1,12 @@ +.set unlink,10 +.globl _unlink +.globl cerror + +_unlink: + .word 0x0000 + chmk $unlink + bcc ok + jmp cerror +ok: + clrl r0 + ret diff --git a/mach/vax4/libsysV_2/ustat.s b/mach/vax4/libsysV_2/ustat.s new file mode 100644 index 00000000..14c867db --- /dev/null +++ b/mach/vax4/libsysV_2/ustat.s @@ -0,0 +1,20 @@ +.set utssys,57 +.globl _ustat +.globl cerror + +_ustat: + .word 0x0000 + pushl $2 + pushl 4(ap) + pushl 8(ap) + calls $3,sys + ret + +sys: + .word 0x0000 + chmk $utssys + bcc ok + jmp cerror +ok: + clrl r0 + ret diff --git a/mach/vax4/libsysV_2/utime.s b/mach/vax4/libsysV_2/utime.s new file mode 100644 index 00000000..d3683dd6 --- /dev/null +++ b/mach/vax4/libsysV_2/utime.s @@ -0,0 +1,11 @@ +.set utime,30 +.globl _utime +.globl cerror + +_utime: + .word 0x0000 + chmk $utime + bcc ok + jmp cerror +ok: + ret diff --git a/mach/vax4/libsysV_2/wait.s b/mach/vax4/libsysV_2/wait.s new file mode 100644 index 00000000..f58b668e --- /dev/null +++ b/mach/vax4/libsysV_2/wait.s @@ -0,0 +1,15 @@ +.set wait,7 +.globl _wait +.globl cerror + +_wait: + .word 0x0000 + chmk $wait + bcc ok + jmp cerror +ok: + tstl 4(ap) + beql out + movl r1,*4(ap) +out: + ret diff --git a/mach/vax4/libsysV_2/write.s b/mach/vax4/libsysV_2/write.s new file mode 100644 index 00000000..f697cbeb --- /dev/null +++ b/mach/vax4/libsysV_2/write.s @@ -0,0 +1,11 @@ +.set write,4 +.globl _write +.globl cerror + +_write: + .word 0x0000 + chmk $write + bcc out + jmp cerror +out: + ret From 37beb265f1ce18a28dff434fc7270ac48dc44b17 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 16:12:55 +0000 Subject: [PATCH 0669/1625] Initial revision --- mach/vax4/libsysV_2/LIST | 69 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 mach/vax4/libsysV_2/LIST diff --git a/mach/vax4/libsysV_2/LIST b/mach/vax4/libsysV_2/LIST new file mode 100644 index 00000000..c16e265d --- /dev/null +++ b/mach/vax4/libsysV_2/LIST @@ -0,0 +1,69 @@ +libmon_s.a +access.s +acct.s +alarm.s +chdir.s +chmod.s +chown.s +chroot.s +creat.s +dup.s +dup2.c +close.s +execl.s +execle.s +execv.s +execve.s +exit.c +cleanup.c +fcntl.s +fork.s +fstat.s +getegid.s +geteuid.s +getgid.s +getpid.s +getppid.s +getuid.s +gtty.s +ioctl.s +kill.s +link.s +lseek.s +mknod.s +mount.s +msg.s +nexect.s +nice.s +open.s +pause.s +pipe.s +plock.s +profil.s +ptrace.s +read.s +sbrk.s +sem.s +setgid.s +setpgrp.s +setuid.s +shm.s +signal.s +stat.s +stime.s +stty.s +sync.s +syscall.s +time.s +times.s +ulimit.s +umask.s +umount.s +uname.s +unlink.s +ustat.s +utime.s +wait.s +write.s +_exit.s +cerror.s From 9fef2e8fceb8afa3f2309483eb8a4f863f524c61 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 16:19:04 +0000 Subject: [PATCH 0670/1625] Name change in library --- mach/vax4/libem/LIST | 2 +- mach/vax4/libem/Makefile | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/mach/vax4/libem/LIST b/mach/vax4/libem/LIST index 8902b319..86d071c0 100644 --- a/mach/vax4/libem/LIST +++ b/mach/vax4/libem/LIST @@ -1,4 +1,4 @@ -tail_em.a +libem_s.a adf.s adi.s and.s diff --git a/mach/vax4/libem/Makefile b/mach/vax4/libem/Makefile index 2177b365..ad79696a 100644 --- a/mach/vax4/libem/Makefile +++ b/mach/vax4/libem/Makefile @@ -1,25 +1,25 @@ # $Header$ +all: libem_o.a + install: cp cp: all - ../../install tail_em - rm -f tail_em + ../../install libem_o.a tail_em cmp: all - -../../compare tail_em - rm -f tail_em + -../../compare libem_o.a tail_em -all: tail_em - -tail_em: +libem_o.a: libem_s.a ASAR=ar ; export ASAR ;\ RANLIB=ranlib ; export RANLIB ;\ - march . tail_em + march . libem_o.a clean: - rm -f *.o + rm -f *.o libem_o.a + opr: make pr | opr + pr: @pr `pwd`/Makefile - @pr -l33 `tail +1 LIST|sort` + @arch pv libem_s.a | pr -h `pwd`/libem_s.a From bbd3a805a204fe65216e46e050684f538a62283c Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 16:21:59 +0000 Subject: [PATCH 0671/1625] *** empty log message *** --- mach/vax4/libbc/Makefile | 3 ++- mach/vax4/libcc/Makefile | 3 ++- mach/vax4/libpc/Makefile | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/mach/vax4/libbc/Makefile b/mach/vax4/libbc/Makefile index 4a2432c5..1573b6da 100644 --- a/mach/vax4/libbc/Makefile +++ b/mach/vax4/libbc/Makefile @@ -1,5 +1,6 @@ +SUF=o MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=vax4" "SUF=o" "ASAR=ar" +MACHDEF="MACH=vax4" "SUF=$(SUF)" "ASAR=ar" BCDEF="PREF=bc" "SUB=" "SRC=lang/basic/lib" install: diff --git a/mach/vax4/libcc/Makefile b/mach/vax4/libcc/Makefile index cb00adb8..43ce0a41 100644 --- a/mach/vax4/libcc/Makefile +++ b/mach/vax4/libcc/Makefile @@ -1,5 +1,6 @@ +SUF=o MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=vax4" "SUF=o" "ASAR=ar" +MACHDEF="MACH=vax4" "SUF=$(SUF)" "ASAR=ar" STDIO="PREF=cc" "SUB=.1s" "SRC=lang/cem/libcc/stdio" GEN="PREF=cc" "SUB=.2g" "SRC=lang/cem/libcc/gen" MON="PREF=mon" "SRC=lang/cem/libcc/mon" diff --git a/mach/vax4/libpc/Makefile b/mach/vax4/libpc/Makefile index 9fbb701a..c22795d0 100644 --- a/mach/vax4/libpc/Makefile +++ b/mach/vax4/libpc/Makefile @@ -1,5 +1,6 @@ +SUF=o MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=vax4" "SUF=o" "ASAR=ar" +MACHDEF="MACH=vax4" "SUF=$(SUF)" "ASAR=ar" PCDEF="PREF=pc" "SUB=" "SRC=lang/pc/libpc" install: From 1832c960dee56969a61a5f402cabfcba3473a16d Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 16:27:36 +0000 Subject: [PATCH 0672/1625] *** empty log message *** --- mach/vax4/Action | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mach/vax4/Action b/mach/vax4/Action index a732fd5d..69655293 100644 --- a/mach/vax4/Action +++ b/mach/vax4/Action @@ -13,3 +13,10 @@ name "Vax 4-4 Basic library" system vax* dir libbc end +name "Vax 4-4 systemcall interface" +system vax* +dir libsys +end +name "Vax target optimizer" +dir top +end From 1f938811003238f26c4e34153c13ef43ff0fcca9 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 16:37:59 +0000 Subject: [PATCH 0673/1625] new definition of ISALNUM --- mach/z80/as/mach0.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mach/z80/as/mach0.c b/mach/z80/as/mach0.c index 0b334c5e..25c518fe 100644 --- a/mach/z80/as/mach0.c +++ b/mach/z80/as/mach0.c @@ -6,3 +6,6 @@ #define THREE_PASS /* distinguish short and long branches */ #define LISTING /* enable listing facilities */ #define RELOCATION + +#undef ISALNUM +#define ISALNUM(c) (isalnum(c) || c == '_' || c == '.') From 84441b2dabf79b0fe1b573a90e393c3fea120fd0 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 16:57:13 +0000 Subject: [PATCH 0674/1625] Initial revision --- mach/m68k4/ncg/whichone.h | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 mach/m68k4/ncg/whichone.h diff --git a/mach/m68k4/ncg/whichone.h b/mach/m68k4/ncg/whichone.h new file mode 100644 index 00000000..e29f53e7 --- /dev/null +++ b/mach/m68k4/ncg/whichone.h @@ -0,0 +1,3 @@ +#ifndef TBL68000 +#define TBL68000 +#endif From b31ed5f29399deff950b8f08c4a2422a623dedfd Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 17:37:18 +0000 Subject: [PATCH 0675/1625] Added pc --- mach/m68k4/Action | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mach/m68k4/Action b/mach/m68k4/Action index 4ed42bfb..9efd6d97 100644 --- a/mach/m68k4/Action +++ b/mach/m68k4/Action @@ -13,3 +13,6 @@ end name "M68000 4-4 Basic libraries" dir libbc end +name "M68000 4-4 Pascal libraries" +dir libpc +end From 714ecbafe3b2b57a35b75ab25bff9c3d895aa356 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 17:40:30 +0000 Subject: [PATCH 0676/1625] *** empty log message *** --- lib/m68k4/descr | 55 +++++++++++++++++++++++++------------ mach/m68k4/libbc/Makefile | 5 ++-- mach/m68k4/libcc/Makefile | 5 ++-- mach/m68k4/libcc/compmodule | 8 ++++-- mach/m68k4/libpc/Makefile | 3 +- mach/m68k4/libpc/compmodule | 6 ++-- mach/m68k4/libsys/LIST | 4 ++- 7 files changed, 58 insertions(+), 28 deletions(-) diff --git a/lib/m68k4/descr b/lib/m68k4/descr index 4a2550e8..a6def773 100644 --- a/lib/m68k4/descr +++ b/lib/m68k4/descr @@ -1,4 +1,4 @@ -# $Revision 2.2$ +# $Revision$ var w=4 var p=4 var s=2 @@ -7,31 +7,50 @@ var f=4 var d=8 var NAME=m68k4 var M=m68k4 -var LIB=lib/m68k4/tail_ -var RT=lib/m68k4/head_ -var INCLUDES=-I{EM}/include -I/usr/include +var LIB=lib/{M}/tail_ +var RT=lib/{M}/head_ +var CPP_F=-Dunix=unix -Dm68000=m68000 +var INCLUDES=-I{EM}/include/_tail_cc +# 407 align is the default +var ALIGN=-a0:2 -a1:2 -a2:2 -a3:2 name be - from .m - to .o + from .m.g + to .s program {EM}/lib/{M}/cg args < stdout need .e end -name asld - from .s.a.o - to .out +name asopt + from .s + to .so + program {EM}/lib/m68k2/top + args + optimizer + stdin + stdout +end +name as + from .s.so + to .o program {EM}/lib/m68k2/as - mapflag -l* LNAME={EM}/{LIB}* - mapflag -d* LFLAG={LFLAG?} -d* - mapflag -s* LFLAG={LFLAG?} -s* - mapflag -n* - mapflag -i* - args {LFLAG?} (.e:{HEAD}={EM}/{RT}em) \ -({RTS}:.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \ -(.p:{TAIL}={EM}/{LIB}pc) (.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \ -(.e:{TAIL}={EM}/{LIB}em {EM}/{LIB}mon {EM}/lib/{M}/end_em) + args - -o > < prep cond +end +name led + from .o.a + to .out + program {EM}/lib/em_led + mapflag -l* LNAME={EM}/{LIB}* + mapflag -i ALIGN=-a0:2 -a1:2 -a2:0x8000 -a3:2 + mapflag -n ALIGN=-a0:2 -a1:2 -a2:0x8000 -a3:2 + mapflag -nr ALIGN=-a0:2 -a1:0x8000 -a2:2 -a3:2 + args (.e:{HEAD}=-b0:0x20000 {ALIGN} {EM}/{RT}em) \ +({RTS}:.b.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \ + (.p:{TAIL}={EM}/{LIB}pc) \ + (.b:{TAIL}={EM}/{LIB}bc) \ + (.b.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \ + (.e:{TAIL}={EM}/{LIB}em {EM}/{LIB}mon {EM}/lib/{M}/end_em) linker end name cv diff --git a/mach/m68k4/libbc/Makefile b/mach/m68k4/libbc/Makefile index a4a75655..7e8bc3ed 100644 --- a/mach/m68k4/libbc/Makefile +++ b/mach/m68k4/libbc/Makefile @@ -1,5 +1,6 @@ +SUF=o MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=m68k4" "SUF=o" "ASAR=aal" +MACHDEF="MACH=m68k4" "SUF=$(SUF)" "ASAR=aal" BCDEF="PREF=bc" "SUB=" "SRC=lang/basic/lib" install: @@ -11,7 +12,7 @@ cmp: -../../compare tail_bc clean: - -rm -f *.old *.[ceo] tail* head* + -rm -f *.old *.[ce$(SUF)] tail* head* opr: make pr | opr diff --git a/mach/m68k4/libcc/Makefile b/mach/m68k4/libcc/Makefile index 8f70d7a0..b3b95577 100644 --- a/mach/m68k4/libcc/Makefile +++ b/mach/m68k4/libcc/Makefile @@ -1,5 +1,6 @@ +SUF=o MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=m68k4" "SUF=o" +MACHDEF="MACH=m68k4 -DNOFLOAT" "SUF=$(SUF)" "ASAR=aal" STDIO="PREF=cc" "SUB=.1s" "SRC=lang/cem/libcc/stdio" GEN="PREF=cc" "SUB=.2g" "SRC=lang/cem/libcc/gen" MON="PREF=mon" "SRC=lang/cem/libcc/mon" @@ -13,7 +14,7 @@ cpgen: cpmon: make -f $(MAKEFILE) $(MON) $(MACHDEF) tailcp -cmp: cmpstdio cmpgen cmpmon +cmp: cmpstdio cmpgen cmpstdio: make -f $(MAKEFILE) $(STDIO) $(MACHDEF) tail diff --git a/mach/m68k4/libcc/compmodule b/mach/m68k4/libcc/compmodule index 491f6d25..6327cb99 100755 --- a/mach/m68k4/libcc/compmodule +++ b/mach/m68k4/libcc/compmodule @@ -1,2 +1,6 @@ -${MACH?} -I../../../h ${MACHFL?} $1 1>&2 -echo `basename $1 $2`.o +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then + echo `basename $1 $2`.o +else + exit 1 +fi diff --git a/mach/m68k4/libpc/Makefile b/mach/m68k4/libpc/Makefile index 926013ca..c3c180fc 100644 --- a/mach/m68k4/libpc/Makefile +++ b/mach/m68k4/libpc/Makefile @@ -1,5 +1,6 @@ +SUF=o MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=m68k4" "SUF=o" +MACHDEF="MACH=m68k4" "SUF=$(SUF)" "ASAR=aal" PCDEF="PREF=pc" "SUB=" "SRC=lang/pc/libpc" install: diff --git a/mach/m68k4/libpc/compmodule b/mach/m68k4/libpc/compmodule index 491f6d25..a794a225 100755 --- a/mach/m68k4/libpc/compmodule +++ b/mach/m68k4/libpc/compmodule @@ -1,2 +1,4 @@ -${MACH?} -I../../../h ${MACHFL?} $1 1>&2 -echo `basename $1 $2`.o +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 +fi diff --git a/mach/m68k4/libsys/LIST b/mach/m68k4/libsys/LIST index 2d595ec4..2abc65bd 100644 --- a/mach/m68k4/libsys/LIST +++ b/mach/m68k4/libsys/LIST @@ -1,4 +1,4 @@ -tail_mon.a +libmon_s.a exit.s _exit.s access.s @@ -12,7 +12,9 @@ close.s creat.s dup.s dup2.s +execle.s execl.s +execv.s execve.s fork.s ftime.s From ef35fd03d8749e92d52261c3f61b79fa46607710 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 19:18:49 +0000 Subject: [PATCH 0677/1625] Initial revision --- mach/mantra/Action | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 mach/mantra/Action diff --git a/mach/mantra/Action b/mach/mantra/Action new file mode 100644 index 00000000..41451b93 --- /dev/null +++ b/mach/mantra/Action @@ -0,0 +1,3 @@ +name "Mantra M68000 4-4 system call library" +dir libsys +end From e0dd6a4bb736b7c2d255dbc3db618d8341efdac1 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 20:14:16 +0000 Subject: [PATCH 0678/1625] Initial revision --- mach/mantra/cv/Makefile | 30 ++++ mach/mantra/cv/Xcv.c | 354 ++++++++++++++++++++++++++++++++++++++++ mach/mantra/cv/cv.c | 316 +++++++++++++++++++++++++++++++++++ 3 files changed, 700 insertions(+) create mode 100644 mach/mantra/cv/Makefile create mode 100644 mach/mantra/cv/Xcv.c create mode 100644 mach/mantra/cv/cv.c diff --git a/mach/mantra/cv/Makefile b/mach/mantra/cv/Makefile new file mode 100644 index 00000000..5b237fcf --- /dev/null +++ b/mach/mantra/cv/Makefile @@ -0,0 +1,30 @@ +EMHOME = ../../.. +LIBOBJ = $(EMHOME)/modules/lib/libobject.a +INCLUDE = $(EMHOME)/h +CFLAGS = -I. -I$(INCLUDE) -O +TARGETS = cv Xcv + +all: $(TARGETS) + +install: all + ../../install cv + ../../install Xcv + +cmp: all + ../../compare cv + ../../compare Xcv + +cv: cv.o + $(CC) $(LDFLAGS) -o cv cv.o $(LIBOBJ) + +Xcv: Xcv.o + $(CC) $(LDFLAGS) -o Xcv Xcv.o $(LIBOBJ) + +clean: + rm -f $(TARGETS) *.o nohup.out Out + +pr: + @pr Makefile cv.c Xcv.c + +opr: + make pr | opr diff --git a/mach/mantra/cv/Xcv.c b/mach/mantra/cv/Xcv.c new file mode 100644 index 00000000..a009fdad --- /dev/null +++ b/mach/mantra/cv/Xcv.c @@ -0,0 +1,354 @@ +/* + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. + * + * This product is part of the Amsterdam Compiler Kit. + * + * Permission to use, sell, duplicate or disclose this software must be + * obtained in writing. Requests for such permissions may be sent to + * + * Dr. Andrew S. Tanenbaum + * Wiskundig Seminarium + * Vrije Universiteit + * Postbox 7161 + * 1007 MC Amsterdam + * The Netherlands + * + */ + +/* + * Convert Mantra object format to ACK object format + */ +#include +#include + +#define FMAGIC 0407 +#define REG 06 + +#define RTEXT 00 +#define RDATA 01 +#define RBSS 02 +#define REXT 03 + +#define RBYTE 00 +#define RWORD 01 +#define RLONG 02 + +struct bhdr { + long fmagic; + long tsize; + long dsize; + long bsize; + long ssize; + long rtsize; + long rdsize; + long entry; +}; + +struct reloc { + char x; +#define setseg(p,s) (p->x = (p->x & ~03) | s) +#define setsiz(p,s) (p->x = (p->x & ~014) | (s << 2)) +#define setdis(p,s) (p->x = (p->x & ~020) | (s << 4)) +#define getseg(p) (p->x&03) +#define getsiz(p) ((p->x >> 2) & 03) +#define getdis(p) ((p->x >> 4) & 01) + char relpad2; + short rsymbol; + long rpos; +}; + +#define N_UNDF 0 +#define N_ABS 01 +#define N_TEXT 02 +#define N_DATA 03 +#define N_BSS 04 +#define N_TYPE 037 +#define N_REG 024 +#define N_FN 037 +#define N_EXT 040 + +#define ASSERT(x) switch (2) { case 0: case (x): ; } + +/* + * Header and section table of new format object file. + */ +struct outhead outhead; +struct outsect outsect[4]; +#define TEXTSG 0 +#define ROMSG 1 +#define DATASG 2 +#define BSSSG 3 + +char *output_file; + +char *program ; + +char flag ; + +#define readf(a, b, c) fread((a), (b), (int)(c), input) + +/* Output file definitions and such */ + +struct bhdr bh; + +#define TOT_HDRSIZE (sizeof(struct bhdr)) + +FILE *input; + +struct outrelo *orelo = 0; +struct outname *oname = 0; +char *strings = 0; +char *txt = 0; +char *data = 0; + +main(argc, argv) + int argc; + char *argv[]; +{ + register struct outsect *p; + char *malloc(); + + input = stdin; + program= argv[0] ; + if ( argc>1 && argv[1][0]=='-' ) { + flag=argv[1][1] ; + argc-- ; argv++ ; + } + switch (argc) { + case 3: if (! wr_open(argv[2])) + fatal("Can't write %s.\n", argv[2]); + output_file = argv[2]; + if ((input = fopen(argv[1], "r")) == (FILE *)0) + fatal("Can't read %s.\n", argv[1]); + break; + default:fatal("Usage: %s .\n", argv[0]); + } + if (! readf(&bh, sizeof(struct bhdr), 1)) rd_fatal(); + if (bh.fmagic != FMAGIC) fatal("bad magic number\n"); + outhead.oh_magic = O_MAGIC; + outhead.oh_stamp = 0; + outhead.oh_nsect = 4; + outhead.oh_nrelo = (bh.rtsize + bh.rdsize) / sizeof(struct reloc); + outhead.oh_flags = outhead.oh_nrelo ? HF_LINK : 0; + outhead.oh_nemit = bh.tsize + bh.dsize; + strings = malloc((unsigned) bh.ssize + 20); + orelo = (struct outrelo *) + malloc(outhead.oh_nrelo * sizeof(struct outrelo)); + oname = (struct outname *) + malloc((unsigned) (bh.ssize / 6 + 3) * sizeof (struct outname)); + txt = malloc(bh.tsize); + data = malloc(bh.dsize); + if (!strings || !orelo || !oname || !txt || !data) { + fatal("No memory\n"); + } + p = &outsect[TEXTSG]; + p->os_base = 0; p->os_size = p->os_flen = bh.tsize; + p->os_foff = OFF_EMIT(outhead); p->os_lign = 1; + p = &outsect[ROMSG]; + p->os_base = p->os_size = p->os_flen = 0; + p->os_foff = OFF_EMIT(outhead) + bh.tsize; p->os_lign = 1; + p = &outsect[DATASG]; + p->os_base = 0; p->os_size = p->os_flen = bh.dsize; + p->os_foff = OFF_EMIT(outhead) + bh.tsize; p->os_lign = 1; + p = &outsect[BSSSG]; + p->os_base = p->os_flen = 0; p->os_size = bh.bsize; + p->os_foff = OFF_EMIT(outhead)+bh.tsize+bh.dsize; p->os_lign = 1; + + if (bh.tsize && ! readf(txt, 1, bh.tsize)) rd_fatal(); + if (bh.dsize && ! readf(data, 1, bh.dsize)) rd_fatal(); + + symtab(oname, strings); + relo(orelo, txt, data); + wr_ohead(&outhead); + wr_sect(outsect, 4); + wr_outsect(TEXTSG); + wr_emit(txt, bh.tsize); + wr_outsect(DATASG); + wr_emit(data,bh.dsize); + wr_relo(orelo, outhead.oh_nrelo); + wr_name(oname, outhead.oh_nname); + wr_string(strings, outhead.oh_nchar); + wr_close(); + return 0; +} + +symtab(name, string) + struct outname *name; + char *string; +{ + register struct outname *oname = name; + register char *strings = string; + register int c; + unsigned nnames = 3; + register long ssize = bh.ssize; + register char *b; + + oname->on_valu = 0; oname->on_foff = 0; oname->on_desc = 0; + oname->on_type = (S_MIN+TEXTSG) | S_SCT; + b = ".text"; while (*strings++ = *b) b++; + oname++; + oname->on_valu = 0; oname->on_foff = strings - string; oname->on_desc = 0; + oname->on_type = (S_MIN+DATASG) | S_SCT; + b = ".data"; while (*strings++ = *b) b++; + oname++; + oname->on_valu = 0; oname->on_foff = strings - string; oname->on_desc = 0; + oname->on_type = (S_MIN+BSSSG) | S_SCT; + b = ".bss"; while (*strings++ = *b) b++; + oname++; + while (ssize > 0) { + c = getc(input); + getc(input); + oname->on_valu = getw(input); + ssize -= 6; + switch(c & ~N_EXT) { + case N_ABS: + oname->on_type = S_ABS; + break; + case N_TEXT: + oname->on_type = S_MIN + TEXTSG; + break; + case N_DATA: + oname->on_type = S_MIN + DATASG; + oname->on_valu -= bh.tsize; + break; + case N_BSS: + oname->on_type = S_MIN + BSSSG; + oname->on_valu -= bh.tsize + bh.dsize; + break; + case N_UNDF: + if (! oname->on_valu) { + oname->on_type = S_UND; + break; + } + oname->on_type = (S_MIN + BSSSG) | S_COM; + break; + case REG: + case N_REG: + case N_FN: + while (ssize > 0 && (getc(input) > 0)) + ssize--; + continue; + default: + fatal("Illegal type field %d in namelist\n", c); + } + if (c & N_EXT) oname->on_type |= S_EXT; + oname->on_desc = 0; + oname->on_foff = strings - string; + nnames++; + while (ssize > 0 && (c = getc(input)) > 0) { + *strings++ = c; + ssize--; + } + ssize--; + *strings++ = c; + oname++; + } + outhead.oh_nname = nnames; + outhead.oh_nchar = strings - string; + oname = name; + ssize = OFF_CHAR(outhead); + while (nnames--) { + oname->on_foff += ssize; + oname++; + } +} + +long +get4(c) + register char *c; +{ + register long l = (long) (*c++ & 0377) << 24; + + l |= (long) (*c++ & 0377) << 16; + l |= (long) (*c++ & 0377) << 8; + l |= (long) (*c++ & 0377); + return l; +} + +put4(l, c) + register char *c; + register long l; +{ + *c++ = (l >> 24); + *c++ = (l >> 16); + *c++ = (l >> 8); + *c = l; +} + +relo(orelo, txt, data) + struct outrelo *orelo; + char *txt, *data; +{ + register struct outrelo *relo = orelo; + register relocnt = outhead.oh_nrelo; + struct reloc rel; + register struct reloc *relp = &rel; + int ndat = bh.rdsize / sizeof(struct reloc); + + while (relocnt-- > 0) { + readf(relp, sizeof(struct reloc), 1); + relo->or_sect = (relocnt >= ndat) ? S_MIN + TEXTSG : + S_MIN + DATASG; + relo->or_addr = relp->rpos; + relo->or_nami = relp->rsymbol + 3; + switch(getseg(relp)) { + case RTEXT: + relo->or_nami = 0; + break; + case RDATA: + relo->or_nami = 1; + break; + case RBSS: + relo->or_nami = 2; + break; + case REXT: + break; + default: + fatal("Error 1 in relocation\n"); + } + switch(getsiz(relp)) { + case RBYTE: + relo->or_type = RELO1|RELBR|RELWR; + break; + case RWORD: + relo->or_type = RELO2|RELBR|RELWR; + break; + case RLONG: { + register char *sct = (relocnt >= ndat ? txt : data) + + relo->or_addr; + long x; + + relo->or_type = RELO4|RELBR|RELWR; + switch((oname + relo->or_nami)->on_type & S_TYP) { + case (S_MIN+DATASG): + x = get4(sct) - bh.tsize; + + put4(x, sct); + break; + case (S_MIN+BSSSG): + if (! ((oname+relo->or_nami)->on_type & S_COM)) + x = get4(sct) - (bh.tsize + bh.dsize); + put4(x, sct); + } + break; + } + default: + fatal("Error 2 in relocation\n"); + } + if (getdis(relp)) relo->or_type |= RELPC; + relo++; + } +} + +/* VARARGS1 */ +fatal(s, a1, a2) + char *s; +{ + fprintf(stderr,"%s: ",program) ; + fprintf(stderr, s, a1, a2); + unlink(output_file); + exit(-1); +} + +wr_fatal() { fatal("Write error\n"); } +rd_fatal() { fatal("Read error\n"); } diff --git a/mach/mantra/cv/cv.c b/mach/mantra/cv/cv.c new file mode 100644 index 00000000..63c55810 --- /dev/null +++ b/mach/mantra/cv/cv.c @@ -0,0 +1,316 @@ +/* + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. + * + * This product is part of the Amsterdam Compiler Kit. + * + * Permission to use, sell, duplicate or disclose this software must be + * obtained in writing. Requests for such permissions may be sent to + * + * Dr. Andrew S. Tanenbaum + * Wiskundig Seminarium + * Vrije Universiteit + * Postbox 7161 + * 1007 MC Amsterdam + * The Netherlands + * + */ + +#include +#include + +#define FMAGIC 0407 +#define NMAGIC 0410 + +struct bhdr { + long fmagic; + long tsize; + long dsize; + long bsize; + long ssize; + long rtsize; + long rdsize; + long entry; +}; + +struct sym { + char stype; + char sympad; + long svalue; +}; + +#define N_UNDF 0 +#define N_ABS 01 +#define N_TEXT 02 +#define N_DATA 03 +#define N_BSS 04 +#define N_EXT 040 + +#define ASSERT(x) switch (2) { case 0: case (x): ; } + +/* + * Header and section table of new format object file. + */ +struct outhead outhead; +struct outsect outsect[S_MAX]; + +char *output_file; +int outputfile_created; + +int rom_in_data; + +char *program ; + +char flag ; + +#define writef(a, b, c) fwrite((a), (b), (int)(c), output) + +/* Output file definitions and such */ + +struct bhdr bh; + +#define ENTRY 0x80000 +#define TOT_HDRSIZE (sizeof(struct bhdr)) + + + +#define TEXTSG 0 +#define ROMSG 1 +#define DATASG 2 +#define BSSSG 3 +#define LSECT BSSSG+1 +#define NSECT LSECT+1 + +FILE *output; + +main(argc, argv) + int argc; + char *argv[]; +{ + register int nsect; + long magic ; + long textsize ; + long datasize ; + long bsssize; + long symstart; + extern long ftell(); + + output = stdout; + program= argv[0] ; + if ( argc>1 && argv[1][0]=='-' ) { + flag=argv[1][1] ; + argc-- ; argv++ ; + } + switch (argc) { + case 3: if ((output = fopen(argv[2], "w")) == (FILE *)0) + fatal("Can't write %s.\n", argv[2]); + output_file = argv[2]; + outputfile_created = 1; + if (! rd_open(argv[1])) + fatal("Can't read %s.\n", argv[1]); + break; + default:fatal("Usage: %s .\n", argv[0]); + } + rd_ohead(&outhead); + if (BADMAGIC(outhead)) + fatal("Not an ack object file.\n"); + if (outhead.oh_flags & HF_LINK) + fatal("Contains unresolved references.\n"); + if (outhead.oh_nrelo > 0) + fprintf(stderr, "Warning: relocation information present.\n"); + if ( outhead.oh_nsect!=LSECT && outhead.oh_nsect!=NSECT ) + fatal("Input file must have %d sections, not %ld\n", + NSECT,outhead.oh_nsect) ; + rd_sect(outsect, outhead.oh_nsect); + /* A few checks */ + if ( outsect[TEXTSG].os_base != ENTRY) + fatal("text must start at %d not at 0x%lx\n", ENTRY, + outsect[TEXTSG].os_base) ; + if ( outsect[BSSSG].os_flen != 0 ) + fatal("bss space contains initialized data\n") ; + if ( outsect[BSSSG].os_base != outsect[DATASG].os_base+ + outsect[DATASG].os_size ) + fatal("bss segment must follow data segment\n") ; + if ( outsect[ROMSG].os_lign == 0x8000 ) { + /* 410 file with ROMSG in data space */ + rom_in_data = 1; + magic= NMAGIC ; + textsize= outsect[TEXTSG].os_size ; + datasize= outsect[ROMSG].os_size + outsect[DATASG].os_size ; + if ( outsect[DATASG].os_base != outsect[ROMSG].os_base+ + outsect[ROMSG].os_size ) + fatal("data segment must follow rom\n") ; + } else + if ( outsect[DATASG].os_lign == 0x8000 ) { + /* 410 file with ROMSG in instruction space */ + rom_in_data = 0; + magic= NMAGIC ; + textsize= outsect[TEXTSG].os_size + outsect[ROMSG].os_size ; + datasize= outsect[DATASG].os_size ; + if ( outsect[ROMSG].os_base != outsect[TEXTSG].os_base+ + outsect[TEXTSG].os_size ) + fatal("rom segment must follow text\n") ; + } else { + /* Plain 407 file */ + rom_in_data = 1; + magic= FMAGIC ; + textsize= outsect[TEXTSG].os_size ; + datasize= outsect[ROMSG].os_size + outsect[DATASG].os_size ; + if ( outsect[ROMSG].os_base != outsect[TEXTSG].os_base+ + outsect[TEXTSG].os_size ) + fatal("rom segment must follow text\n") ; + if ( outsect[DATASG].os_base != outsect[ROMSG].os_base+ + outsect[ROMSG].os_size ) + fatal("data segment must follow rom\n") ; + } + bsssize = outsect[BSSSG].os_size; + if ( outhead.oh_nsect==NSECT ) { + if ( outsect[LSECT].os_base != outsect[BSSSG].os_base+ + outsect[BSSSG].os_size ) + fatal("end segment must follow bss\n") ; + if ( outsect[LSECT].os_size != 0 ) + fatal("end segment must be empty\n") ; + } + + bh.fmagic = magic; + + bh.tsize = textsize; + bh.bsize = bsssize; + bh.dsize = datasize; + bh.entry = ENTRY; + + /* Action at last */ + fseek(output,(long) TOT_HDRSIZE,0); + emits(&outsect[TEXTSG]) ; + emits(&outsect[ROMSG]) ; + emits(&outsect[DATASG]) ; + symstart = ftell(output); + emit_symtab(); + bh.ssize = ftell(output) - symstart; + fseek(output,0L,0); + write_header(&bh); + if ( ferror(output) ) { + fatal("output write error\n") ; + } + if ( outputfile_created ) chmod(argv[2],0755); + return 0; +} + +/* + * Transfer the emitted byted from one file to another. + */ +emits(section) struct outsect *section ; { + char *p; + char *calloc(); + + rd_outsect(section - outsect); + if (!(p = calloc(section->os_size, 1))) { + fatal("No memory.\n"); + } + rd_emit(p, section->os_flen); + writef(p, 1, section->os_size); + free(p); +} + +emit_symtab() +{ + struct outname *ACK_names; + register unsigned short i; + register struct outname *A; + register char x; + register char *p; + extern char *malloc(), *calloc(); + long l; + long off = OFF_CHAR(outhead); + char *chars; + + if ((unsigned) outhead.oh_nchar != outhead.oh_nchar || + !( chars = malloc((unsigned) outhead.oh_nchar))) { + fatal("No memory\n."); + } + rd_string(chars,outhead.oh_nchar); + if ((unsigned) outhead.oh_nname != outhead.oh_nname || + !(A = (struct outname *) + calloc(outhead.oh_nname, sizeof(struct outname)))) { + fatal("No memory.\n"); + } + ACK_names = A; + rd_name(ACK_names, outhead.oh_nname); + for (i = 0; i < outhead.oh_nname; i++, A++) { + if ((A->on_type & S_TYP) >= S_MIN + LSECT || + A->on_foff == 0) continue; + switch(A->on_type & S_TYP) { + case S_UND: + x = N_UNDF; + break; + case S_ABS: + x = N_ABS; + break; + case S_MIN + TEXTSG: + x = N_TEXT; + break; + case S_MIN + ROMSG: + x = (rom_in_data ? N_DATA : N_TEXT); + break; + case S_MIN + DATASG: + x = N_DATA; + break; + case S_MIN + BSSSG: + x = N_BSS; + break; + default: + fprintf(stderr,"warning: unknown s_type: %d\n", + A->on_type & S_TYP); + } + if (A->on_type & S_EXT) x |= N_EXT; + putc(x,output); + putc(0,output); + write_long(A->on_valu); + l = A->on_foff - off; + if (l < 0 || l >= outhead.oh_nchar) { + fatal("bad on_off: %ld\n",l); + } + p = &chars[l]; + while (x = *p++) { + putc(x,output); + } + putc('\0',output); + } +} + +write_long(l) + register long l; +{ + /* write long "l" in 68000 order + */ + + putc((int) (l >> 24), output); + putc((int) (l >> 16), output); + putc((int) (l >> 8), output); + putc((int) l, output); +} + +write_header(h) + register struct bhdr *h; +{ + write_long(h->fmagic); + write_long(h->tsize); + write_long(h->dsize); + write_long(h->bsize); + write_long(h->ssize); + write_long(h->rtsize); + write_long(h->rdsize); + write_long(h->entry); +} + +/* VARARGS1 */ +fatal(s, a1, a2) + char *s; +{ + fprintf(stderr,"%s: ",program) ; + fprintf(stderr, s, a1, a2); + if (outputfile_created) + unlink(output_file); + exit(-1); +} + +rd_fatal() { fatal("read error.\n"); } From 2c7909536bda1cbb94e8f02d59acf0ad5e94dd26 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 20:23:42 +0000 Subject: [PATCH 0679/1625] Added target optimizer --- mach/m68k2/Action | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mach/m68k2/Action b/mach/m68k2/Action index ececdf45..10fe8e7a 100644 --- a/mach/m68k2/Action +++ b/mach/m68k2/Action @@ -7,6 +7,9 @@ end name "Motorola 68000 2-4 conversion program" dir cv end +name "Motorola 68000 target optimizer" +dir opt +end name "Motorola 68000 2-4 C libraries" dir libcc end From 19512a1250c901d7eadcecf6982edcaaaf3700f7 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 20:31:55 +0000 Subject: [PATCH 0680/1625] *** empty log message *** --- lib/m68k2/descr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/m68k2/descr b/lib/m68k2/descr index ee58d2dc..9377b566 100644 --- a/lib/m68k2/descr +++ b/lib/m68k2/descr @@ -22,7 +22,7 @@ name be need .e end name as - from .s + from .s.so to .o program {EM}/lib/{M}/as args - -o > < From 04e6b14aa799b35067dea9d7b1be2ada49cef0b9 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 20:36:15 +0000 Subject: [PATCH 0681/1625] added asopt --- lib/mantra/descr | 13 +++++++++++-- lib/pmds/descr | 11 ++++++++++- lib/pmds4/descr | 11 ++++++++++- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/lib/mantra/descr b/lib/mantra/descr index e2cb2b2f..51069d4f 100644 --- a/lib/mantra/descr +++ b/lib/mantra/descr @@ -5,7 +5,7 @@ var s=2 var l=4 var f=4 var d=8 -var NAME=mantra4 +var NAME=m68k4 var M=m68k4 var LIB=lib/{M}/tail_ var RT=lib/{M}/head_ @@ -21,8 +21,17 @@ name be stdout need .e end -name as +name asopt from .s + to .so + program {EM}/lib/m68k2/top + args + optimizer + stdin + stdout +end +name as + from .s.so to .o program {EM}/lib/m68k2/as args - -o > < diff --git a/lib/pmds/descr b/lib/pmds/descr index 6a85b7a0..aa1ee5d4 100644 --- a/lib/pmds/descr +++ b/lib/pmds/descr @@ -21,8 +21,17 @@ name be stdout need .e end -name as +name asopt from .s + to .so + program {EM}/lib/{M}/top + args + optimizer + stdin + stdout +end +name as + from .s.so to .o program {EM}/lib/{M}/as args - -o > < diff --git a/lib/pmds4/descr b/lib/pmds4/descr index 067565cd..bb4444ba 100644 --- a/lib/pmds4/descr +++ b/lib/pmds4/descr @@ -21,8 +21,17 @@ name be stdout need .e end -name as +name asopt from .s + to .so + program {EM}/lib/m68k2/top + args + optimizer + stdin + stdout +end +name as + from .s.so to .o program {EM}/lib/m68k2/as args - -o > < From bbc14378b5b005c9d1d6ba91c9b30f78b4f0ce67 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 20:40:04 +0000 Subject: [PATCH 0682/1625] back-end must accept .g files --- lib/pmds/descr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pmds/descr b/lib/pmds/descr index aa1ee5d4..111f229f 100644 --- a/lib/pmds/descr +++ b/lib/pmds/descr @@ -14,7 +14,7 @@ var CPP_F=-Dunix=unix -Dm68000=m68000 # 407 align is the default var ALIGN=-a0:2 -a1:2 -a2:2 -a3:2 name be - from .m + from .m.g to .s program {EM}/lib/{M}/cg args < From aaa80e81cb71428fe82f278d7887f4bf9d61aa32 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 20:40:59 +0000 Subject: [PATCH 0683/1625] backend must accept .g files --- lib/pmds4/descr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pmds4/descr b/lib/pmds4/descr index bb4444ba..3ee1f294 100644 --- a/lib/pmds4/descr +++ b/lib/pmds4/descr @@ -14,7 +14,7 @@ var CPP_F=-Dunix=unix -Dm68000=m68000 # 407 align is default var ALIGN=-a0:2 -a1:2 -a2:2 -a3:2 name be - from .m + from .m.g to .s program {EM}/lib/{M}/cg args < From 620b935f96b9d7e4792e55227757669e27fcb536 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 20:48:02 +0000 Subject: [PATCH 0684/1625] ASP with negative argument wasn't accepted --- mach/z80/cg/table | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/z80/cg/table b/mach/z80/cg/table index 71e26554..fd05c71e 100644 --- a/mach/z80/cg/table +++ b/mach/z80/cg/table @@ -1271,7 +1271,7 @@ ret | | remove(ALL) asp $1 == 0 | | | | | -asp $1 > 0 | STACK | remove(ALL) allocate(HL_REG) +asp $1 != 0 | STACK | remove(ALL) allocate(HL_REG) move({IMMEDIATE,$1} , HL) "add hl,sp" "ld sp,hl" From 34d0a602d9019b318c93fe538bea401b393c4338 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 20:54:56 +0000 Subject: [PATCH 0685/1625] obeyed a warning --- lang/cem/libcc/gen/isatty.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/cem/libcc/gen/isatty.c b/lang/cem/libcc/gen/isatty.c index aeee7ff7..b68171fe 100644 --- a/lang/cem/libcc/gen/isatty.c +++ b/lang/cem/libcc/gen/isatty.c @@ -6,6 +6,6 @@ isatty(f) where gtty is an ioctl(..., TCGETA, ...) */ - if (gtty(f, &buf) < 0) return 0; + if (gtty(f, buf) < 0) return 0; return 1; } From 9ff6538f47e8a0fea40323dc5803112af6d8830c Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 21:01:10 +0000 Subject: [PATCH 0686/1625] pdp instead of pdp11 --- lang/cem/libcc/gen/malloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/cem/libcc/gen/malloc.c b/lang/cem/libcc/gen/malloc.c index 4e7d4dd9..9df169c2 100644 --- a/lang/cem/libcc/gen/malloc.c +++ b/lang/cem/libcc/gen/malloc.c @@ -11,7 +11,7 @@ extern bcopy(); #define BUSY 1 #define NEXT(p) (* (char **) (p)) -#ifdef pdp11 +#ifdef pdp #define BUGFIX 64 #else #define BUGFIX 0 From 3b818e9decc692a20e936f2d677975a7240fa4e2 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 2 Feb 1987 21:49:57 +0000 Subject: [PATCH 0687/1625] ??? --- mach/z80/as/mach4.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/mach/z80/as/mach4.c b/mach/z80/as/mach4.c index 457d3ad4..f8af5c11 100644 --- a/mach/z80/as/mach4.c +++ b/mach/z80/as/mach4.c @@ -321,15 +321,11 @@ index : '(' R16 '+' expr ')' } | '(' R16 '-' expr ')' { -#ifdef ASLD if ($2!=IX && $2!=IY) serror("register error"); fit(fitb($4.val)); exp_ind = $4; RELOMOVE(rel_ind, relonami); $$ = $2; -#else ASLD - serror("relocation error"); -#endif ASLD } ; ind : indir From f48736787531d462ff9e512c98e2ebe2665586c9 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 3 Feb 1987 09:50:31 +0000 Subject: [PATCH 0688/1625] *** empty log message *** --- mach/em24/libcc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/em24/libcc/Makefile b/mach/em24/libcc/Makefile index 4f231a86..ac31df01 100644 --- a/mach/em24/libcc/Makefile +++ b/mach/em24/libcc/Makefile @@ -1,6 +1,6 @@ SUF=m MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=int" "SUF=$(SUF)" +MACHDEF="MACH=int24" "SUF=$(SUF)" STDIO="PREF=cc" "SUB=.1s" "SRC=lang/cem/libcc/stdio" GEN="PREF=cc" "SUB=.2g" "SRC=lang/cem/libcc/gen" MON="PREF=mon" "SRC=lang/cem/libcc/mon" From ecb94a711e0f2a31520a4e36698d63ba0a7818c0 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 3 Feb 1987 09:52:40 +0000 Subject: [PATCH 0689/1625] int --> int24 --- mach/em24/libpc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/em24/libpc/Makefile b/mach/em24/libpc/Makefile index 9258cacd..fa0095b0 100644 --- a/mach/em24/libpc/Makefile +++ b/mach/em24/libpc/Makefile @@ -1,6 +1,6 @@ SUF=m MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=int" "SUF=$(SUF)" +MACHDEF="MACH=int24" "SUF=$(SUF)" PCDEF="PREF=pc" "SUB=" "SRC=lang/pc/libpc" install: From 33c8c84b35e7e19e06109c7ef7a1f2e7f0e235d6 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 3 Feb 1987 09:53:20 +0000 Subject: [PATCH 0690/1625] int22 --> int24 --- mach/em24/libbc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/em24/libbc/Makefile b/mach/em24/libbc/Makefile index 3b9dc3aa..192b73ae 100644 --- a/mach/em24/libbc/Makefile +++ b/mach/em24/libbc/Makefile @@ -1,6 +1,6 @@ SUF=m MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=int22" "SUF=$(SUF)" +MACHDEF="MACH=int24" "SUF=$(SUF)" BCDEF="PREF=bc" "SUB=" "SRC=lang/basic/lib" install: From e3f9f5c9a6e26fcf25118daf66d9f4c8fb520867 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 3 Feb 1987 09:55:06 +0000 Subject: [PATCH 0691/1625] int22 --> int44 --- mach/em44/libbc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/em44/libbc/Makefile b/mach/em44/libbc/Makefile index 3b9dc3aa..53cc307d 100644 --- a/mach/em44/libbc/Makefile +++ b/mach/em44/libbc/Makefile @@ -1,6 +1,6 @@ SUF=m MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=int22" "SUF=$(SUF)" +MACHDEF="MACH=int44" "SUF=$(SUF)" BCDEF="PREF=bc" "SUB=" "SRC=lang/basic/lib" install: From 076d1f315e3a9f340bd19e4fcf1216ac45e6cca8 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 3 Feb 1987 09:55:47 +0000 Subject: [PATCH 0692/1625] int --> int44 --- mach/em44/libcc/Makefile | 2 +- mach/em44/libpc/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mach/em44/libcc/Makefile b/mach/em44/libcc/Makefile index 4f231a86..2449ec3c 100644 --- a/mach/em44/libcc/Makefile +++ b/mach/em44/libcc/Makefile @@ -1,6 +1,6 @@ SUF=m MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=int" "SUF=$(SUF)" +MACHDEF="MACH=int44" "SUF=$(SUF)" STDIO="PREF=cc" "SUB=.1s" "SRC=lang/cem/libcc/stdio" GEN="PREF=cc" "SUB=.2g" "SRC=lang/cem/libcc/gen" MON="PREF=mon" "SRC=lang/cem/libcc/mon" diff --git a/mach/em44/libpc/Makefile b/mach/em44/libpc/Makefile index 9258cacd..5c8cc09f 100644 --- a/mach/em44/libpc/Makefile +++ b/mach/em44/libpc/Makefile @@ -1,6 +1,6 @@ SUF=m MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=int" "SUF=$(SUF)" +MACHDEF="MACH=int44" "SUF=$(SUF)" PCDEF="PREF=pc" "SUB=" "SRC=lang/pc/libpc" install: From b65f42aa7af742bdebcb2ff10f82e3db866297a7 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 3 Feb 1987 09:57:57 +0000 Subject: [PATCH 0693/1625] int --> int22 --- mach/em22/libcc/Makefile | 2 +- mach/em22/libpc/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mach/em22/libcc/Makefile b/mach/em22/libcc/Makefile index 4f231a86..6026230e 100644 --- a/mach/em22/libcc/Makefile +++ b/mach/em22/libcc/Makefile @@ -1,6 +1,6 @@ SUF=m MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=int" "SUF=$(SUF)" +MACHDEF="MACH=int22" "SUF=$(SUF)" STDIO="PREF=cc" "SUB=.1s" "SRC=lang/cem/libcc/stdio" GEN="PREF=cc" "SUB=.2g" "SRC=lang/cem/libcc/gen" MON="PREF=mon" "SRC=lang/cem/libcc/mon" diff --git a/mach/em22/libpc/Makefile b/mach/em22/libpc/Makefile index 9258cacd..e61a0f44 100644 --- a/mach/em22/libpc/Makefile +++ b/mach/em22/libpc/Makefile @@ -1,6 +1,6 @@ SUF=m MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=int" "SUF=$(SUF)" +MACHDEF="MACH=int22" "SUF=$(SUF)" PCDEF="PREF=pc" "SUB=" "SRC=lang/pc/libpc" install: From 596c36ac43cbcc55e715fc1db943e0ec3968a0d5 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 3 Feb 1987 13:09:27 +0000 Subject: [PATCH 0694/1625] lock ??? --- mach/z80/int/dl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mach/z80/int/dl.c b/mach/z80/int/dl.c index 1ee84ca5..72a70df1 100644 --- a/mach/z80/int/dl.c +++ b/mach/z80/int/dl.c @@ -67,8 +67,8 @@ main(argc,argv) char **argv; { freopen(s,"w",stdout); } first = 1; osg = 0; - uid = getuid(); - lock(1); + /* uid = getuid(); */ + /* lock(1); */ for (;;) { pc = get2c(stdin); if (feof(stdin)) From 8932b2b60e033fd8d5691dc066f84fb76f94c8aa Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 3 Feb 1987 13:23:38 +0000 Subject: [PATCH 0695/1625] adapted to new assembler syntax --- mach/z80/int/atof.s | 55 ++- mach/z80/int/dvi4.s | 18 +- mach/z80/int/dvu4.s | 17 +- mach/z80/int/eb.s | 10 +- mach/z80/int/em.s | 1112 +++++++++++++++++-------------------------- 5 files changed, 492 insertions(+), 720 deletions(-) diff --git a/mach/z80/int/atof.s b/mach/z80/int/atof.s index 26c0a2e2..c9856527 100644 --- a/mach/z80/int/atof.s +++ b/mach/z80/int/atof.s @@ -1,10 +1,16 @@ - .data +.define atof +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text + .sect .data ! Set of variables -big: .byte 0 - .byte 0 - .byte 0x40 - .byte 24 ! 2^23 +big: .data1 0 + .data1 0 + .data1 0x40 + .data1 24 ! 2^23 negfrac:.space 1 negexp: .space 1 begzero: @@ -15,17 +21,17 @@ eexp: .space 2 flexp: .space 4 exp5: .space 4 endzero: -ten: .byte 0 - .byte 0 - .byte 0x50 - .byte 4 ! 10 -dig: .byte 0 - .byte 0 -fildig: .byte 0 ! here a number from 0 to 31 will be converted flt. - .byte 7 +ten: .data1 0 + .data1 0 + .data1 0x50 + .data1 4 ! 10 +dig: .data1 0 + .data1 0 +fildig: .data1 0 ! here a number from 0 to 31 will be converted flt. + .data1 7 bexp: .space 2 - .text + .sect .text atof: ! entry with stringpointer in hl ! exit with pointer to float in hl push ix @@ -177,25 +183,25 @@ atof: ! entry with stringpointer in hl 1: bit 0,l jr z,2f call xflt - .word flexp,exp5,fpmult,4,flexp + .data2 flexp,exp5,fpmult,4,flexp 2: sra h rr l ld a,h or l jr z,3f call xflt - .word exp5,exp5,fpmult,4,exp5 + .data2 exp5,exp5,fpmult,4,exp5 jr 1b 3: ld hl,negexp ld a,(bexp) bit 7,(hl) jr z,1f call xflt - .word flexp,fl,fpdiv,4,fl + .data2 flexp,fl,fpdiv,4,fl neg jr 2f 1: call xflt - .word flexp,fl,fpmult,4,fl + .data2 flexp,fl,fpmult,4,fl 2: ld b,a ld a,(fl+3) add a,b @@ -204,9 +210,9 @@ atof: ! entry with stringpointer in hl bit 7,a jr z,1f call xflt - .word fl,fl,fpcomp,4,fl + .data2 fl,fl,fpcomp,4,fl 1: call xflt - .word fl,fl,fpnorm,4,fl + .data2 fl,fl,fpnorm,4,fl ld hl,fl pop af pop de @@ -217,19 +223,19 @@ atof: ! entry with stringpointer in hl cmpbigfl: call xflt - .word big,fl,fpcmf,0 + .data2 big,fl,fpcmf,0 ld a,(fpac+1) bit 7,a ret mulandadd: call xflt - .word fl,ten,fpmult,4,fl + .data2 fl,ten,fpmult,4,fl ld a,7 ld (fildig+1),a call xflt - .word dig,dig,fpnorm,4,dig + .data2 dig,dig,fpnorm,4,dig call xflt - .word fl,dig,fpadd,4,fl + .data2 fl,dig,fpadd,4,fl ret xflt: @@ -278,3 +284,4 @@ xflt: pop af ex (sp),iy ret +.align 256 diff --git a/mach/z80/int/dvi4.s b/mach/z80/int/dvi4.s index cf1ccbce..14443011 100644 --- a/mach/z80/int/dvi4.s +++ b/mach/z80/int/dvi4.s @@ -1,3 +1,9 @@ +.define .dvi4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text .dvi4: pop hl ld (retaddr),hl @@ -66,9 +72,9 @@ push bc push de jp (iy) -.data - .flag1: .byte 0 - .flag2: .byte 0 - retaddr:.word 0 - .savebc: .word 0 - .savede: .word 0 +.sect .data + .flag1: .data1 0 + .flag2: .data1 0 + retaddr:.data2 0 + .savebc: .data2 0 + .savede: .data2 0 diff --git a/mach/z80/int/dvu4.s b/mach/z80/int/dvu4.s index f0489664..0800213e 100644 --- a/mach/z80/int/dvu4.s +++ b/mach/z80/int/dvu4.s @@ -1,4 +1,9 @@ .define .dvu4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! 4-byte divide routine for z80 ! parameters: @@ -129,9 +134,9 @@ ld hl,(.retaddr) jp (hl) ! return -.data -.flag: .byte 0 -.low: .word 0 -.iysave: .word 0 -.retaddr: .word 0 -.result: .word 0 +.sect .data +.flag: .data1 0 +.low: .data2 0 +.iysave: .data2 0 +.retaddr: .data2 0 +.result: .data2 0 diff --git a/mach/z80/int/eb.s b/mach/z80/int/eb.s index 875035ed..a2dc854d 100644 --- a/mach/z80/int/eb.s +++ b/mach/z80/int/eb.s @@ -1,2 +1,10 @@ - .bss +.define eb +.define ebp4 +.sect .text +.sect .rom +.sect .data eb: + .data4 0 +ebp4: +.sect .bss +.sect .text diff --git a/mach/z80/int/em.s b/mach/z80/int/em.s index 4e82dd11..a7e7fa3f 100644 --- a/mach/z80/int/em.s +++ b/mach/z80/int/em.s @@ -1,4 +1,9 @@ # +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! This program is an EM interpreter for the Z80. ! Register pair bc is used to hold lb. ! Register ix is used to hold the EM program counter. @@ -56,8 +61,6 @@ !--------------------------- Initialization --------------------------- - .base 0x100 - jp init ! 3 byte instruction. !------------------------- MAIN DISPATCH ------------------------------ @@ -66,535 +69,276 @@ ! must be put on a page boundary -dispat = . - 3 ! base of dispatch table -! .byte loc.0 /256 -! .byte loc.1 /256 -! .byte loc.2 /256 - .byte loc.3 /256 - .byte loc.4 /256 - .byte loc.5 /256 - .byte loc.6 /256 - .byte loc.7 /256 - .byte loc.8 /256 - .byte loc.9 /256 - .byte loc.10 /256 - .byte loc.11 /256 - .byte loc.12 /256 - .byte loc.13 /256 - .byte loc.14 /256 - .byte loc.15 /256 - .byte loc.16 /256 - .byte loc.17 /256 - .byte loc.18 /256 - .byte loc.19 /256 - .byte loc.20 /256 - .byte loc.21 /256 - .byte loc.22 /256 - .byte loc.23 /256 - .byte loc.24 /256 - .byte loc.25 /256 - .byte loc.26 /256 - .byte loc.27 /256 - .byte loc.28 /256 - .byte loc.29 /256 - .byte loc.30 /256 - .byte loc.31 /256 - .byte loc.32 /256 - .byte loc.33 /256 - .byte aar.2 /256 - .byte adf.s0 /256 - .byte adi.2 /256 - .byte adi.4 /256 - .byte adp.l /256 - .byte adp.1 /256 - .byte adp.2 /256 - .byte adp.s0 /256 - .byte adp.sm1 /256 - .byte ads.2 /256 - .byte and.2 /256 - .byte asp.2 /256 - .byte asp.4 /256 - .byte asp.6 /256 - .byte asp.8 /256 - .byte asp.10 /256 - .byte asp.w0 /256 - .byte beq.l /256 - .byte beq.s0 /256 - .byte bge.s0 /256 - .byte bgt.s0 /256 - .byte ble.s0 /256 - .byte blm.s0 /256 - .byte blt.s0 /256 - .byte bne.s0 /256 - .byte bra.l /256 - .byte bra.sm1 /256 - .byte bra.sm2 /256 - .byte bra.s0 /256 - .byte bra.s1 /256 - .byte cal.1 /256 - .byte cal.2 /256 - .byte cal.3 /256 - .byte cal.4 /256 - .byte cal.5 /256 - .byte cal.6 /256 - .byte cal.7 /256 - .byte cal.8 /256 - .byte cal.9 /256 - .byte cal.10 /256 - .byte cal.11 /256 - .byte cal.12 /256 - .byte cal.13 /256 - .byte cal.14 /256 - .byte cal.15 /256 - .byte cal.16 /256 - .byte cal.17 /256 - .byte cal.18 /256 - .byte cal.19 /256 - .byte cal.20 /256 - .byte cal.21 /256 - .byte cal.22 /256 - .byte cal.23 /256 - .byte cal.24 /256 - .byte cal.25 /256 - .byte cal.26 /256 - .byte cal.27 /256 - .byte cal.28 /256 - .byte cal.s0 /256 - .byte cff.z /256 - .byte cif.z /256 - .byte cii.z /256 - .byte cmf.s0 /256 - .byte cmi.2 /256 - .byte cmi.4 /256 - .byte cmp.z /256 - .byte cms.s0 /256 - .byte csa.2 /256 - .byte csb.2 /256 - .byte dec.z /256 - .byte dee.w0 /256 - .byte del.wm1 /256 - .byte dup.2 /256 - .byte dvf.s0 /256 - .byte dvi.2 /256 - .byte fil.l /256 - .byte inc.z /256 - .byte ine.l /256 - .byte ine.w0 /256 - .byte inl.m2 /256 - .byte inl.m4 /256 - .byte inl.m6 /256 - .byte inl.wm1 /256 - .byte inn.s0 /256 - .byte ior.2 /256 - .byte ior.s0 /256 - .byte lae.l /256 - .byte lae.w0 /256 - .byte lae.w1 /256 - .byte lae.w2 /256 - .byte lae.w3 /256 - .byte lae.w4 /256 - .byte lae.w5 /256 - .byte lae.w6 /256 - .byte lal.p /256 - .byte lal.n /256 - .byte lal.0 /256 - .byte lal.m1 /256 - .byte lal.w0 /256 - .byte lal.wm1 /256 - .byte lal.wm2 /256 - .byte lar.2 /256 - .byte ldc.0 /256 - .byte lde.l /256 - .byte lde.w0 /256 - .byte ldl.0 /256 - .byte ldl.wm1 /256 - .byte lfr.2 /256 - .byte lfr.4 /256 - .byte lfr.s0 /256 - .byte lil.wm1 /256 - .byte lil.w0 /256 - .byte lil.0 /256 - .byte lil.2 /256 - .byte lin.l /256 - .byte lin.s0 /256 - .byte lni.z /256 - .byte loc.l /256 - .byte loc.m1 /256 - .byte loc.s0 /256 - .byte loc.sm1 /256 - .byte loe.l /256 - .byte loe.w0 /256 - .byte loe.w1 /256 - .byte loe.w2 /256 - .byte loe.w3 /256 - .byte loe.w4 /256 - .byte lof.l /256 - .byte lof.2 /256 - .byte lof.4 /256 - .byte lof.6 /256 - .byte lof.8 /256 - .byte lof.s0 /256 - .byte loi.l /256 - .byte loi.1 /256 - .byte loi.2 /256 - .byte loi.4 /256 - .byte loi.6 /256 - .byte loi.8 /256 - .byte loi.s0 /256 - .byte lol.p /256 - .byte lol.n /256 - .byte lol.0 /256 - .byte lol.2 /256 - .byte lol.4 /256 - .byte lol.6 /256 - .byte lol.m2 /256 - .byte lol.m4 /256 - .byte lol.m6 /256 - .byte lol.m8 /256 - .byte lol.m10 /256 - .byte lol.m12 /256 - .byte lol.m14 /256 - .byte lol.m16 /256 - .byte lol.w0 /256 - .byte lol.wm1 /256 - .byte lxa.1 /256 - .byte lxl.1 /256 - .byte lxl.2 /256 - .byte mlf.s0 /256 - .byte mli.2 /256 - .byte mli.4 /256 - .byte rck.2 /256 - .byte ret.0 /256 - .byte ret.2 /256 - .byte ret.s0 /256 - .byte rmi.2 /256 - .byte sar.2 /256 - .byte sbf.s0 /256 - .byte sbi.2 /256 - .byte sbi.4 /256 - .byte sdl.wm1 /256 - .byte set.s0 /256 - .byte sil.wm1 /256 - .byte sil.w0 /256 - .byte sli.2 /256 - .byte ste.l /256 - .byte ste.w0 /256 - .byte ste.w1 /256 - .byte ste.w2 /256 - .byte stf.l /256 - .byte stf.2 /256 - .byte stf.4 /256 - .byte stf.s0 /256 - .byte sti.1 /256 - .byte sti.2 /256 - .byte sti.4 /256 - .byte sti.6 /256 - .byte sti.8 /256 - .byte sti.s0 /256 - .byte stl.p /256 - .byte stl.n /256 - .byte stl.p0 /256 - .byte stl.p2 /256 - .byte stl.m2 /256 - .byte stl.m4 /256 - .byte stl.m6 /256 - .byte stl.m8 /256 - .byte stl.m10 /256 - .byte stl.wm1 /256 - .byte teq.z /256 - .byte tgt.z /256 - .byte tlt.z /256 - .byte tne.z /256 - .byte zeq.l /256 - .byte zeq.s0 /256 - .byte zeq.s1 /256 - .byte zer.s0 /256 - .byte zge.s0 /256 - .byte zgt.s0 /256 - .byte zle.s0 /256 - .byte zlt.s0 /256 - .byte zne.s0 /256 - .byte zne.sm1 /256 - .byte zre.l /256 - .byte zre.w0 /256 - .byte zrl.m2 /256 - .byte zrl.m4 /256 - .byte zrl.wm1 /256 - .byte zrl.n /256 - .byte loop1 /256 - .byte loop2 /256 - - .errnz .-dispat-256 - - .byte loc.0 %256 - .byte loc.1 %256 - .byte loc.2 %256 - .byte loc.3 %256 - .byte loc.4 %256 - .byte loc.5 %256 - .byte loc.6 %256 - .byte loc.7 %256 - .byte loc.8 %256 - .byte loc.9 %256 - .byte loc.10 %256 - .byte loc.11 %256 - .byte loc.12 %256 - .byte loc.13 %256 - .byte loc.14 %256 - .byte loc.15 %256 - .byte loc.16 %256 - .byte loc.17 %256 - .byte loc.18 %256 - .byte loc.19 %256 - .byte loc.20 %256 - .byte loc.21 %256 - .byte loc.22 %256 - .byte loc.23 %256 - .byte loc.24 %256 - .byte loc.25 %256 - .byte loc.26 %256 - .byte loc.27 %256 - .byte loc.28 %256 - .byte loc.29 %256 - .byte loc.30 %256 - .byte loc.31 %256 - .byte loc.32 %256 - .byte loc.33 %256 - .byte aar.2 %256 - .byte adf.s0 %256 - .byte adi.2 %256 - .byte adi.4 %256 - .byte adp.l %256 - .byte adp.1 %256 - .byte adp.2 %256 - .byte adp.s0 %256 - .byte adp.sm1 %256 - .byte ads.2 %256 - .byte and.2 %256 - .byte asp.2 %256 - .byte asp.4 %256 - .byte asp.6 %256 - .byte asp.8 %256 - .byte asp.10 %256 - .byte asp.w0 %256 - .byte beq.l %256 - .byte beq.s0 %256 - .byte bge.s0 %256 - .byte bgt.s0 %256 - .byte ble.s0 %256 - .byte blm.s0 %256 - .byte blt.s0 %256 - .byte bne.s0 %256 - .byte bra.l %256 - .byte bra.sm1 %256 - .byte bra.sm2 %256 - .byte bra.s0 %256 - .byte bra.s1 %256 - .byte cal.1 %256 - .byte cal.2 %256 - .byte cal.3 %256 - .byte cal.4 %256 - .byte cal.5 %256 - .byte cal.6 %256 - .byte cal.7 %256 - .byte cal.8 %256 - .byte cal.9 %256 - .byte cal.10 %256 - .byte cal.11 %256 - .byte cal.12 %256 - .byte cal.13 %256 - .byte cal.14 %256 - .byte cal.15 %256 - .byte cal.16 %256 - .byte cal.17 %256 - .byte cal.18 %256 - .byte cal.19 %256 - .byte cal.20 %256 - .byte cal.21 %256 - .byte cal.22 %256 - .byte cal.23 %256 - .byte cal.24 %256 - .byte cal.25 %256 - .byte cal.26 %256 - .byte cal.27 %256 - .byte cal.28 %256 - .byte cal.s0 %256 - .byte cff.z %256 - .byte cif.z %256 - .byte cii.z %256 - .byte cmf.s0 %256 - .byte cmi.2 %256 - .byte cmi.4 %256 - .byte cmp.z %256 - .byte cms.s0 %256 - .byte csa.2 %256 - .byte csb.2 %256 - .byte dec.z %256 - .byte dee.w0 %256 - .byte del.wm1 %256 - .byte dup.2 %256 - .byte dvf.s0 %256 - .byte dvi.2 %256 - .byte fil.l %256 - .byte inc.z %256 - .byte ine.l %256 - .byte ine.w0 %256 - .byte inl.m2 %256 - .byte inl.m4 %256 - .byte inl.m6 %256 - .byte inl.wm1 %256 - .byte inn.s0 %256 - .byte ior.2 %256 - .byte ior.s0 %256 - .byte lae.l %256 - .byte lae.w0 %256 - .byte lae.w1 %256 - .byte lae.w2 %256 - .byte lae.w3 %256 - .byte lae.w4 %256 - .byte lae.w5 %256 - .byte lae.w6 %256 - .byte lal.p %256 - .byte lal.n %256 - .byte lal.0 %256 - .byte lal.m1 %256 - .byte lal.w0 %256 - .byte lal.wm1 %256 - .byte lal.wm2 %256 - .byte lar.2 %256 - .byte ldc.0 %256 - .byte lde.l %256 - .byte lde.w0 %256 - .byte ldl.0 %256 - .byte ldl.wm1 %256 - .byte lfr.2 %256 - .byte lfr.4 %256 - .byte lfr.s0 %256 - .byte lil.wm1 %256 - .byte lil.w0 %256 - .byte lil.0 %256 - .byte lil.2 %256 - .byte lin.l %256 - .byte lin.s0 %256 - .byte lni.z %256 - .byte loc.l %256 - .byte loc.m1 %256 - .byte loc.s0 %256 - .byte loc.sm1 %256 - .byte loe.l %256 - .byte loe.w0 %256 - .byte loe.w1 %256 - .byte loe.w2 %256 - .byte loe.w3 %256 - .byte loe.w4 %256 - .byte lof.l %256 - .byte lof.2 %256 - .byte lof.4 %256 - .byte lof.6 %256 - .byte lof.8 %256 - .byte lof.s0 %256 - .byte loi.l %256 - .byte loi.1 %256 - .byte loi.2 %256 - .byte loi.4 %256 - .byte loi.6 %256 - .byte loi.8 %256 - .byte loi.s0 %256 - .byte lol.p %256 - .byte lol.n %256 - .byte lol.0 %256 - .byte lol.2 %256 - .byte lol.4 %256 - .byte lol.6 %256 - .byte lol.m2 %256 - .byte lol.m4 %256 - .byte lol.m6 %256 - .byte lol.m8 %256 - .byte lol.m10 %256 - .byte lol.m12 %256 - .byte lol.m14 %256 - .byte lol.m16 %256 - .byte lol.w0 %256 - .byte lol.wm1 %256 - .byte lxa.1 %256 - .byte lxl.1 %256 - .byte lxl.2 %256 - .byte mlf.s0 %256 - .byte mli.2 %256 - .byte mli.4 %256 - .byte rck.2 %256 - .byte ret.0 %256 - .byte ret.2 %256 - .byte ret.s0 %256 - .byte rmi.2 %256 - .byte sar.2 %256 - .byte sbf.s0 %256 - .byte sbi.2 %256 - .byte sbi.4 %256 - .byte sdl.wm1 %256 - .byte set.s0 %256 - .byte sil.wm1 %256 - .byte sil.w0 %256 - .byte sli.2 %256 - .byte ste.l %256 - .byte ste.w0 %256 - .byte ste.w1 %256 - .byte ste.w2 %256 - .byte stf.l %256 - .byte stf.2 %256 - .byte stf.4 %256 - .byte stf.s0 %256 - .byte sti.1 %256 - .byte sti.2 %256 - .byte sti.4 %256 - .byte sti.6 %256 - .byte sti.8 %256 - .byte sti.s0 %256 - .byte stl.p %256 - .byte stl.n %256 - .byte stl.p0 %256 - .byte stl.p2 %256 - .byte stl.m2 %256 - .byte stl.m4 %256 - .byte stl.m6 %256 - .byte stl.m8 %256 - .byte stl.m10 %256 - .byte stl.wm1 %256 - .byte teq.z %256 - .byte tgt.z %256 - .byte tlt.z %256 - .byte tne.z %256 - .byte zeq.l %256 - .byte zeq.s0 %256 - .byte zeq.s1 %256 - .byte zer.s0 %256 - .byte zge.s0 %256 - .byte zgt.s0 %256 - .byte zle.s0 %256 - .byte zlt.s0 %256 - .byte zne.s0 %256 - .byte zne.sm1 %256 - .byte zre.l %256 - .byte zre.w0 %256 - .byte zrl.m2 %256 - .byte zrl.m4 %256 - .byte zrl.wm1 %256 - .byte zrl.n %256 - .byte loop1 %256 - .byte loop2 %256 - - .errnz .-dispat-512 +.data1 0 ! fourth byte +dispat = . - 4 ! base of dispatch table +! .data2 loc.0 +! .data2 loc.1 + .data2 loc.2 + .data2 loc.3 + .data2 loc.4 + .data2 loc.5 + .data2 loc.6 + .data2 loc.7 + .data2 loc.8 + .data2 loc.9 + .data2 loc.10 + .data2 loc.11 + .data2 loc.12 + .data2 loc.13 + .data2 loc.14 + .data2 loc.15 + .data2 loc.16 + .data2 loc.17 + .data2 loc.18 + .data2 loc.19 + .data2 loc.20 + .data2 loc.21 + .data2 loc.22 + .data2 loc.23 + .data2 loc.24 + .data2 loc.25 + .data2 loc.26 + .data2 loc.27 + .data2 loc.28 + .data2 loc.29 + .data2 loc.30 + .data2 loc.31 + .data2 loc.32 + .data2 loc.33 + .data2 aar.2 + .data2 adf.s0 + .data2 adi.2 + .data2 adi.4 + .data2 adp.l + .data2 adp.1 + .data2 adp.2 + .data2 adp.s0 + .data2 adp.sm1 + .data2 ads.2 + .data2 and.2 + .data2 asp.2 + .data2 asp.4 + .data2 asp.6 + .data2 asp.8 + .data2 asp.10 + .data2 asp.w0 + .data2 beq.l + .data2 beq.s0 + .data2 bge.s0 + .data2 bgt.s0 + .data2 ble.s0 + .data2 blm.s0 + .data2 blt.s0 + .data2 bne.s0 + .data2 bra.l + .data2 bra.sm1 + .data2 bra.sm2 + .data2 bra.s0 + .data2 bra.s1 + .data2 cal.1 + .data2 cal.2 + .data2 cal.3 + .data2 cal.4 + .data2 cal.5 + .data2 cal.6 + .data2 cal.7 + .data2 cal.8 + .data2 cal.9 + .data2 cal.10 + .data2 cal.11 + .data2 cal.12 + .data2 cal.13 + .data2 cal.14 + .data2 cal.15 + .data2 cal.16 + .data2 cal.17 + .data2 cal.18 + .data2 cal.19 + .data2 cal.20 + .data2 cal.21 + .data2 cal.22 + .data2 cal.23 + .data2 cal.24 + .data2 cal.25 + .data2 cal.26 + .data2 cal.27 + .data2 cal.28 + .data2 cal.s0 + .data2 cff.z + .data2 cif.z + .data2 cii.z + .data2 cmf.s0 + .data2 cmi.2 + .data2 cmi.4 + .data2 cmp.z + .data2 cms.s0 + .data2 csa.2 + .data2 csb.2 + .data2 dec.z + .data2 dee.w0 + .data2 del.wm1 + .data2 dup.2 + .data2 dvf.s0 + .data2 dvi.2 + .data2 fil.l + .data2 inc.z + .data2 ine.l + .data2 ine.w0 + .data2 inl.m2 + .data2 inl.m4 + .data2 inl.m6 + .data2 inl.wm1 + .data2 inn.s0 + .data2 ior.2 + .data2 ior.s0 + .data2 lae.l + .data2 lae.w0 + .data2 lae.w1 + .data2 lae.w2 + .data2 lae.w3 + .data2 lae.w4 + .data2 lae.w5 + .data2 lae.w6 + .data2 lal.p + .data2 lal.n + .data2 lal.0 + .data2 lal.m1 + .data2 lal.w0 + .data2 lal.wm1 + .data2 lal.wm2 + .data2 lar.2 + .data2 ldc.0 + .data2 lde.l + .data2 lde.w0 + .data2 ldl.0 + .data2 ldl.wm1 + .data2 lfr.2 + .data2 lfr.4 + .data2 lfr.s0 + .data2 lil.wm1 + .data2 lil.w0 + .data2 lil.0 + .data2 lil.2 + .data2 lin.l + .data2 lin.s0 + .data2 lni.z + .data2 loc.l + .data2 loc.m1 + .data2 loc.s0 + .data2 loc.sm1 + .data2 loe.l + .data2 loe.w0 + .data2 loe.w1 + .data2 loe.w2 + .data2 loe.w3 + .data2 loe.w4 + .data2 lof.l + .data2 lof.2 + .data2 lof.4 + .data2 lof.6 + .data2 lof.8 + .data2 lof.s0 + .data2 loi.l + .data2 loi.1 + .data2 loi.2 + .data2 loi.4 + .data2 loi.6 + .data2 loi.8 + .data2 loi.s0 + .data2 lol.p + .data2 lol.n + .data2 lol.0 + .data2 lol.2 + .data2 lol.4 + .data2 lol.6 + .data2 lol.m2 + .data2 lol.m4 + .data2 lol.m6 + .data2 lol.m8 + .data2 lol.m10 + .data2 lol.m12 + .data2 lol.m14 + .data2 lol.m16 + .data2 lol.w0 + .data2 lol.wm1 + .data2 lxa.1 + .data2 lxl.1 + .data2 lxl.2 + .data2 mlf.s0 + .data2 mli.2 + .data2 mli.4 + .data2 rck.2 + .data2 ret.0 + .data2 ret.2 + .data2 ret.s0 + .data2 rmi.2 + .data2 sar.2 + .data2 sbf.s0 + .data2 sbi.2 + .data2 sbi.4 + .data2 sdl.wm1 + .data2 set.s0 + .data2 sil.wm1 + .data2 sil.w0 + .data2 sli.2 + .data2 ste.l + .data2 ste.w0 + .data2 ste.w1 + .data2 ste.w2 + .data2 stf.l + .data2 stf.2 + .data2 stf.4 + .data2 stf.s0 + .data2 sti.1 + .data2 sti.2 + .data2 sti.4 + .data2 sti.6 + .data2 sti.8 + .data2 sti.s0 + .data2 stl.p + .data2 stl.n + .data2 stl.p0 + .data2 stl.p2 + .data2 stl.m2 + .data2 stl.m4 + .data2 stl.m6 + .data2 stl.m8 + .data2 stl.m10 + .data2 stl.wm1 + .data2 teq.z + .data2 tgt.z + .data2 tlt.z + .data2 tne.z + .data2 zeq.l + .data2 zeq.s0 + .data2 zeq.s1 + .data2 zer.s0 + .data2 zge.s0 + .data2 zgt.s0 + .data2 zle.s0 + .data2 zlt.s0 + .data2 zne.s0 + .data2 zne.sm1 + .data2 zre.l + .data2 zre.w0 + .data2 zrl.m2 + .data2 zrl.m4 + .data2 zrl.wm1 + .data2 zrl.n + .data2 loop1 + .data2 loop2 !----------------- END OF MAIN DISPATCH ------------------------------- +xxx: + .data2 loc.0 + .data2 loc.1 init: ld sp,(bdos+1) ! address of fbase - ld hl,dispat - ld (hl),loc.0/256 - inc hl - ld (hl),loc.1/256 - inc hl - ld (hl),loc.2/256 + ld hl,xxx + ld de,dispat + ld bc,4 + ldir call uxinit warmstart: ld sp,(bdos+1) ! address of fbase @@ -642,7 +386,7 @@ warmstart: jr nz,1b ! now program text has been read,so start read- ld iy,0 ! ing data descriptors, (nextp) (was hl) is - ld ix,eb+eb%2 ! pointer into DMA,ix is pointer into global + ld ix,eb ! pointer into DMA,ix is pointer into global ! data area,iy is #bytes pushed in last instr (used for repeat) rddata: ld hl,(ndata) ld a,h @@ -716,7 +460,7 @@ rddata: ld hl,(ndata) jr z,3f ld hl,(pb) jr 4f -3: ld hl,eb+eb%2 +3: ld hl,eb jr 4f 2: ld hl,0 4: ld (ntext),hl ! ntext is used here to hold base address of @@ -845,17 +589,18 @@ getb: push hl ! getb reads 1 byte in register c from standard !------------------------- Main loop of the interpreter --------------- phl: push hl -loop: - .errnz dispat%256 - ld l,(ix) ! l = opcode byte - inc ix ! advance program counter - ld h,dispat/256 ! hl=address of high byte of jumpaddress - ld d,(hl) ! d=high byte of jump address - inc h ! hl=address of low byte of jumpaddress - ld e,(hl) ! de=jumpaddress - xor a ! clear a and carry - ld h,a ! and clear h - ex de,hl ! d:=0; hl:=jumpaddress +loop: ld e,(ix) ! e = opcode byte + inc ix ! advance EM program counter to next byte + ld hl,dispat ! hl = address of dispatching table + xor a + ld d,a + add hl,de ! compute address of routine for this opcode + add hl,de ! hl = address of routine to dispatch to + ld d,(hl) ! e = low byte of routine address + inc hl ! hl now points to 2nd byte of routine address + ld h,(hl) ! h = high byte of routine address + ld l,d ! hl = address of routine + ld d,a jp (hl) ! go execute the routine loop1: ld e,(ix) ! e = opcode byte @@ -1022,7 +767,7 @@ loe.w2: inc d loe.w1: inc d loe.w0: ld e,(ix) inc ix - ld hl,eb+eb%2 + ld hl,eb add hl,de add hl,de jr ipsh @@ -1099,7 +844,7 @@ lae.w2: inc d lae.w1: inc d lae.w0: ld e,(ix) inc ix - ld hl,eb+eb%2 + ld hl,eb add hl,de add hl,de jr phl @@ -1108,7 +853,7 @@ lae.l: ld d,(ix) inc ix ld e,(ix) inc ix - ld hl,eb+eb%2 + ld hl,eb add hl,de jr phl @@ -1163,7 +908,7 @@ lxl.s: ld a,(ix) inc hl inc hl inc hl - .errnz .-2b-zone + .assert [ .-2b-zone] == 0 ld e,(hl) inc hl ld h,(hl) @@ -1192,7 +937,7 @@ lxa.s: ld a,(ix) lpb.z: pop hl - .errnz zone/256 + .assert [ zone/256] == 0 ld e,zone add hl,de jr phl @@ -1275,7 +1020,7 @@ lde.w2: inc d lde.w1: inc d lde.w0: ld e,(ix) inc ix - ld hl,eb+eb%2 + ld hl,eb add hl,de add hl,de jr dipsh @@ -1382,7 +1127,7 @@ ste.w2: inc d ste.w1: inc d ste.w0: ld e,(ix) inc ix - ld hl,eb+eb%2 + ld hl,eb add hl,de add hl,de jr ipop @@ -1491,7 +1236,7 @@ sde.l: ld d,(ix) inc ix ld e,(ix) inc ix - ld hl,eb+eb%2 + ld hl,eb 2: add hl,de 1: pop de ld (hl),e @@ -1518,7 +1263,7 @@ adi.z: adu.z: pop de 9: call chk24 - .word adi.2,adi.4 + .data2 adi.2,adi.4 adi.l: adu.l: ld d,(ix) ! I guess a routine chk24.l could do this job inc ix @@ -1562,7 +1307,7 @@ sbi.z: sbu.z: pop de 9: call chk24 - .word sbi.2,sbi.4 + .data2 sbi.2,sbi.4 sbi.l: sbu.l: ld d,(ix) inc ix @@ -1586,7 +1331,7 @@ ngi.z: pop de 9: call chk24 - .word ngi.2,ngi.4 + .data2 ngi.2,ngi.4 ngi.l: ld d,(ix) inc ix @@ -1604,7 +1349,7 @@ mli.z: mlu.z: pop de 9: call chk24 - .word mli.2,mli.4 + .data2 mli.2,mli.4 mli.l: mlu.l: ld d,(ix) inc ix @@ -1643,7 +1388,7 @@ dvi.z: pop de 9: call chk24 - .word dvi.2,dvi.4 + .data2 dvi.2,dvi.4 dvi.l: ld d,(ix) inc ix @@ -1708,7 +1453,7 @@ dvu.z: pop de 9: call chk24 - .word dvu.2,dvu.4 + .data2 dvu.2,dvu.4 dvu.l: ld d,(ix) inc ix @@ -1750,7 +1495,7 @@ rmi.z: pop de 9: call chk24 - .word rmi.2,rmi.4 + .data2 rmi.2,rmi.4 rmi.l: ld d,(ix) inc ix @@ -1835,7 +1580,7 @@ rmu.z: pop de 9: call chk24 - .word rmu.2,rmu.4 + .data2 rmu.2,rmu.4 rmu.l: ld d,(ix) inc ix @@ -1876,7 +1621,7 @@ slu.z: sli.z: pop de 9: call chk24 - .word sli.2,sli.4 + .data2 sli.2,sli.4 slu.l: sli.l: ld d,(ix) @@ -1922,7 +1667,7 @@ sri.z: pop de 9: call chk24 - .word sri.2,sri.4 + .data2 sri.2,sri.4 sri.l: ld d,(ix) inc ix @@ -1968,7 +1713,7 @@ sru.z: pop de 9: call chk24 - .word sru.2,sru.4 + .data2 sru.2,sru.4 sru.l: ld d,(ix) inc ix @@ -2014,7 +1759,7 @@ rol.z: pop de 9: call chk24 - .word rol.2,rol.4 + .data2 rol.2,rol.4 rol.l: ld d,(ix) inc ix @@ -2057,7 +1802,7 @@ ror.z: pop de 9: call chk24 - .word ror.2,ror.4 + .data2 ror.2,ror.4 ror.l: ld d,(ix) inc ix @@ -2162,7 +1907,7 @@ ine.w2: inc d ine.w1: inc d ine.w0: ld e,(ix) inc ix - ld hl,eb+eb%2 + ld hl,eb add hl,de add hl,de jr 1b @@ -2202,7 +1947,7 @@ dee.w2: inc d dee.w1: inc d dee.w0: ld e,(ix) inc ix - ld hl,eb+eb%2 + ld hl,eb add hl,de add hl,de jr 1b @@ -3008,15 +2753,15 @@ cal.s0: ld e,(ix) inc ix cal: push ix ! entry point for main program of interpreter push bc - ld hl,(eb+eb%2) + ld hl,(eb) push hl - ld hl,(eb+eb%2+4) + ld hl,(ebp4) push hl ! temporary tracing facility ! NOP it if you don't want it push de - ld de,(eb+eb%2+4) - ld hl,(eb+eb%2) + ld de,(ebp4) + ld hl,(eb) call prline pop de ! end of temporary tracing @@ -3105,9 +2850,9 @@ ret.0: ld l,c ld sp,hl pop hl - ld (eb+eb%2+4),hl + ld (ebp4),hl pop hl - ld (eb+eb%2),hl + ld (eb),hl pop bc ! old LB pop ix ! reta push ix ! check to see if reta = boot (= 0) @@ -3151,8 +2896,8 @@ trp.z: ld c,printstring ld de,2f call bdos - ld de,(eb+eb%2+4) - ld hl,(eb+eb%2) + ld de,(ebp4) + ld hl,(eb) call prline 0: pop iy ! LB @@ -3222,7 +2967,7 @@ rtt.z=ret.0 nop.z: push bc ld iy,1f+12 - ld hl,(eb+eb%2) + ld hl,(eb) call octnr ld iy,1f+20 ld hl,0 @@ -3460,29 +3205,29 @@ lin.l: ld d,(ix) inc ix lin.s0: ld e,(ix) inc ix - ld (eb+eb%2),de + ld (eb),de jr loop ! FIL fil.z: pop hl 1: - ld (eb+eb%2+4),hl + ld (ebp4),hl jr loop fil.l: ld h,(ix) inc ix ld l,(ix) inc ix - ld de,eb+eb%2 + ld de,eb add hl,de jr 1b ! LNI -lni.z: ld hl,(eb+eb%2) +lni.z: ld hl,(eb) inc hl - ld (eb+eb%2),hl + ld (eb),hl jr loop @@ -3672,7 +3417,7 @@ docmf: cfi.z: pop de call chk24 - .word 1f,0f + .data2 1f,0f 1: ld iy,1f jr pop4 1: pop hl @@ -3702,7 +3447,7 @@ cif.z: 1: pop de call chk24 - .word 1f,0f + .data2 1f,0f 1: pop hl ld (fpac),hl push bc @@ -3998,19 +3743,19 @@ long2: ld a,(ix) zcount=41 zsave=42 - .errnz filefcb + .assert [ filefcb] == 0 0: .space maxfiles*filesize filearea = 0b+128 sibuf: - .word 0 + .data2 0 .space 82 siptr: .space 2 saveargs: .space 128 argv: .space 40 ! not more than 20 args argc: .space 2 -ttymode:.byte 9,9,8,21;.short 06310+RAW*040 ! raw = 040 +ttymode:.data1 9,9,8,21;.data2 06310+RAW*040 ! raw = 040 uxinit: xor a @@ -4068,8 +3813,9 @@ makeargv: jr 4b 9: push ix pop hl - ld de,-argv - add hl,de + ld de,argv + or a + sbc hl,de srl h;rr l ld (argc),hl ld (ix+0),0 @@ -4094,70 +3840,70 @@ mon.z: jp (hl) systab: - .word ux_indir - .word ux_exit - .word ux_fork - .word ux_read - .word ux_write - .word ux_open - .word ux_close - .word ux_wait - .word ux_creat - .word ux_link - .word ux_unlink - .word ux_exec - .word ux_chdir - .word ux_time - .word ux_mknod - .word ux_chmod - .word ux_chown - .word ux_break - .word ux_stat - .word ux_seek - .word ux_getpid - .word ux_mount - .word ux_umount - .word ux_setuid - .word ux_getuid - .word ux_stime - .word ux_ptrace - .word ux_alarm - .word ux_fstat - .word ux_pause - .word ux_utime - .word ux_stty - .word ux_gtty - .word ux_access - .word ux_nice - .word ux_ftime - .word ux_sync - .word ux_kill - .word unimpld - .word unimpld - .word unimpld - .word ux_dup - .word ux_pipe - .word ux_times - .word ux_prof - .word ux_unused - .word ux_setgid - .word ux_getgid - .word ux_sig - .word unimpld - .word unimpld - .word unimpld - .word unimpld - .word unimpld - .word ux_ioctl - .word unimpld - .word unimpld - .word unimpld - .word unimpld - .word ux_exece - .word ux_umask - .word ux_chroot - .word unimpld - .word unimpld + .data2 ux_indir + .data2 ux_exit + .data2 ux_fork + .data2 ux_read + .data2 ux_write + .data2 ux_open + .data2 ux_close + .data2 ux_wait + .data2 ux_creat + .data2 ux_link + .data2 ux_unlink + .data2 ux_exec + .data2 ux_chdir + .data2 ux_time + .data2 ux_mknod + .data2 ux_chmod + .data2 ux_chown + .data2 ux_break + .data2 ux_stat + .data2 ux_seek + .data2 ux_getpid + .data2 ux_mount + .data2 ux_umount + .data2 ux_setuid + .data2 ux_getuid + .data2 ux_stime + .data2 ux_ptrace + .data2 ux_alarm + .data2 ux_fstat + .data2 ux_pause + .data2 ux_utime + .data2 ux_stty + .data2 ux_gtty + .data2 ux_access + .data2 ux_nice + .data2 ux_ftime + .data2 ux_sync + .data2 ux_kill + .data2 unimpld + .data2 unimpld + .data2 unimpld + .data2 ux_dup + .data2 ux_pipe + .data2 ux_times + .data2 ux_prof + .data2 ux_unused + .data2 ux_setgid + .data2 ux_getgid + .data2 ux_sig + .data2 unimpld + .data2 unimpld + .data2 unimpld + .data2 unimpld + .data2 unimpld + .data2 ux_ioctl + .data2 unimpld + .data2 unimpld + .data2 unimpld + .data2 unimpld + .data2 ux_exece + .data2 ux_umask + .data2 ux_chroot + .data2 unimpld + .data2 unimpld emptyfile: ! searches for a free filestructure @@ -4884,49 +4630,49 @@ ux_exece: dispat1: ! base for escaped opcodes -.word aar.l, aar.z, adf.l, adf.z, adi.l, adi.z, ads.l, ads.z -.word adu.l, adu.z, and.l, and.z, asp.l, ass.l, ass.z, bge.l -.word bgt.l, ble.l, blm.l, bls.l, bls.z, blt.l, bne.l, cai.z -.word cal.l, cfi.z, cfu.z, ciu.z, cmf.l, cmf.z, cmi.l, cmi.z -.word cms.l, cms.z, cmu.l, cmu.z, com.l, com.z, csa.l, csa.z -.word csb.l, csb.z, cuf.z, cui.z, cuu.z, dee.l, del.p, del.n -.word dup.l, dus.l, dus.z, dvf.l, dvf.z, dvi.l, dvi.z, dvu.l -.word dvu.z, fef.l, fef.z, fif.l, fif.z, inl.p, inl.n, inn.l -.word inn.z, ior.l, ior.z, lar.l, lar.z, ldc.l, ldf.l, ldl.p -.word ldl.n, lfr.l, lil.p, lil.n, lim.z, los.l, los.z, lor.s0 -.word lpi.l, lxa.l, lxl.l, mlf.l, mlf.z, mli.l, mli.z, mlu.l -.word mlu.z, mon.z, ngf.l, ngf.z, ngi.l, ngi.z, nop.z, rck.l -.word rck.z, ret.l, rmi.l, rmi.z, rmu.l, rmu.z, rol.l, rol.z -.word ror.l, ror.z, rtt.z, sar.l, sar.z, sbf.l, sbf.z, sbi.l -.word sbi.z, sbs.l, sbs.z, sbu.l, sbu.z, sde.l, sdf.l, sdl.p -.word sdl.n, set.l, set.z, sig.z, sil.p, sil.n, sim.z, sli.l -.word sli.z, slu.l, slu.z, sri.l, sri.z, sru.l, sru.z, sti.l -.word sts.l, sts.z, str.s0, tge.z, tle.z, trp.z, xor.l, xor.z -.word zer.l, zer.z, zge.l, zgt.l, zle.l, zlt.l, zne.l, zrf.l -.word zrf.z, zrl.p, dch.z, exg.s0, exg.l, exg.z, lpb.z +.data2 aar.l, aar.z, adf.l, adf.z, adi.l, adi.z, ads.l, ads.z +.data2 adu.l, adu.z, and.l, and.z, asp.l, ass.l, ass.z, bge.l +.data2 bgt.l, ble.l, blm.l, bls.l, bls.z, blt.l, bne.l, cai.z +.data2 cal.l, cfi.z, cfu.z, ciu.z, cmf.l, cmf.z, cmi.l, cmi.z +.data2 cms.l, cms.z, cmu.l, cmu.z, com.l, com.z, csa.l, csa.z +.data2 csb.l, csb.z, cuf.z, cui.z, cuu.z, dee.l, del.p, del.n +.data2 dup.l, dus.l, dus.z, dvf.l, dvf.z, dvi.l, dvi.z, dvu.l +.data2 dvu.z, fef.l, fef.z, fif.l, fif.z, inl.p, inl.n, inn.l +.data2 inn.z, ior.l, ior.z, lar.l, lar.z, ldc.l, ldf.l, ldl.p +.data2 ldl.n, lfr.l, lil.p, lil.n, lim.z, los.l, los.z, lor.s0 +.data2 lpi.l, lxa.l, lxl.l, mlf.l, mlf.z, mli.l, mli.z, mlu.l +.data2 mlu.z, mon.z, ngf.l, ngf.z, ngi.l, ngi.z, nop.z, rck.l +.data2 rck.z, ret.l, rmi.l, rmi.z, rmu.l, rmu.z, rol.l, rol.z +.data2 ror.l, ror.z, rtt.z, sar.l, sar.z, sbf.l, sbf.z, sbi.l +.data2 sbi.z, sbs.l, sbs.z, sbu.l, sbu.z, sde.l, sdf.l, sdl.p +.data2 sdl.n, set.l, set.z, sig.z, sil.p, sil.n, sim.z, sli.l +.data2 sli.z, slu.l, slu.z, sri.l, sri.z, sru.l, sru.z, sti.l +.data2 sts.l, sts.z, str.s0, tge.z, tle.z, trp.z, xor.l, xor.z +.data2 zer.l, zer.z, zge.l, zgt.l, zle.l, zlt.l, zne.l, zrf.l +.data2 zrf.z, zrl.p, dch.z, exg.s0, exg.l, exg.z, lpb.z dispat2: ! base for 4 byte offsets -.word ldc.f +.data2 ldc.f -ignmask: .word 0 ! ignore mask (variable) -retarea: .word 0 ! base of buffer for result values (max 8 bytes) - .word 0 - .word 0 - .word 0 +ignmask: .data2 0 ! ignore mask (variable) +retarea: .data2 0 ! base of buffer for result values (max 8 bytes) + .data2 0 + .data2 0 + .data2 0 trapproc: - .word 0 + .data2 0 -nextp: .byte 0 +nextp: .data1 0 header: -ntext: .word 0 -ndata: .word 0 -nproc: .word 0 -entry: .word 0 -nline: .word 0 +ntext: .data2 0 +ndata: .data2 0 +nproc: .data2 0 +entry: .data2 0 +nline: .data2 0 -hp: .word 0 -pb: .word 0 -pd: .word 0 +hp: .data2 0 +pb: .data2 0 +pd: .data2 0 From 7877b641fa7180766ce33ad16d17d340f997c90b Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 3 Feb 1987 13:32:24 +0000 Subject: [PATCH 0696/1625] adapted to new assembler syntax --- mach/z80/int/fpp.s | 19 ++++++++++++++++--- mach/z80/int/mli4.s | 9 +++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/mach/z80/int/fpp.s b/mach/z80/int/fpp.s index fbec1550..7f099c57 100644 --- a/mach/z80/int/fpp.s +++ b/mach/z80/int/fpp.s @@ -1,3 +1,10 @@ +.define fpac, fpadd, fpcdf, fpcfd, fpcfi, fpcif, fpcmf, fpcomp +.define fpdiv, fpfef, fpfif, fpmult, fpop, fpsub, fpnorm +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! floating point pakket voor Z80 ! geimplementeerd zoals beschreven in ! Electronica top internationaal. @@ -16,7 +23,6 @@ fol: .space 1 fon: .space 1 fom: .space 1 fox: .space 1 - .errnz xa/256-fox/256 fpsub: call fpcomp ! inverteer fpacc @@ -99,11 +105,15 @@ addmor: djnz addmor ! herhaal dit 4 keer jr fpnorm +yyy: + .data2 fom + fpmult: call setsgn add a,(hl) ! bereken exponent produkt ld (hl),a ! fax exponent produkt - ld l,fom%256 + ld a,(yyy) + ld l,a ex de,hl ! gebruik de als wijzer xor a ld h,a @@ -244,9 +254,12 @@ tstacc: init: ld hl,xa ! initialiseer nog een paar registers ld (hl),c + ld a,(xxx) + ld l,a ld a,(fox) - ld l,fax%256 ret +xxx: + .data2 fax fpcif: ld de,(fpac) ! integer to convert diff --git a/mach/z80/int/mli4.s b/mach/z80/int/mli4.s index ce7927ef..3c82d368 100644 --- a/mach/z80/int/mli4.s +++ b/mach/z80/int/mli4.s @@ -1,4 +1,9 @@ .define .mli4 +.sect .text +.sect .rom +.sect .data +.sect .bss +.sect .text ! 32-bit multiply routine for z80 ! parameters: @@ -70,6 +75,6 @@ ! on stack; put return address in hl push ix ! least sign. 2 bytes of result jp (hl) ! return -.data -.flag: .byte 0 +.sect .data +.flag: .data1 0 .mplier: .space 4 From 032200ac65fcadcf16e19c1485231e2f1ce5a57f Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 3 Feb 1987 14:36:29 +0000 Subject: [PATCH 0697/1625] *** empty log message *** --- lib/em24/descr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/em24/descr b/lib/em24/descr index b35298dc..196f91d0 100644 --- a/lib/em24/descr +++ b/lib/em24/descr @@ -10,7 +10,7 @@ var NAME=int24 var LIB=lib/int24/tail_ var RT=lib/int24/head_ var SIZE_FLAG=-sm -var CPP_F=-Dunix +var CPP_F=-Dunix=unix var INCLUDES=-I{EM}/include/_tail_cc -I{EM}/include/_tail_mon name asld from .k.m.a.g From 5281bed8e4e3199e4d0c9888113996d0c0815c5c Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 3 Feb 1987 14:47:45 +0000 Subject: [PATCH 0698/1625] Added pascal lib --- mach/em44/Action | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mach/em44/Action b/mach/em44/Action index 4ca90474..e507c112 100644 --- a/mach/em44/Action +++ b/mach/em44/Action @@ -1,6 +1,9 @@ name "4-4 Interpreter C libraries" dir libcc end +name "4-4 Interpreter Pascal library" +dir libpc +end name "4-4 Interpreter Basic library" dir libbc end From 9a2534840b601343af8da1ecefc6055c14443913 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 3 Feb 1987 14:50:30 +0000 Subject: [PATCH 0699/1625] *** empty log message *** --- lib/em44/descr | 2 +- lib/z80/descr | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/em44/descr b/lib/em44/descr index a28af006..b20e3999 100644 --- a/lib/em44/descr +++ b/lib/em44/descr @@ -10,7 +10,7 @@ var NAME=int44 var LIB=lib/int44/tail_ var RT=lib/int44/head_ var SIZE_FLAG=-sm -var CPP_F=-Dunix +var CPP_F=-Dunix=unix var INCLUDES=-I{EM}/include/_tail_cc -I{EM}/include/_tail_mon name asld from .k.m.a.g diff --git a/lib/z80/descr b/lib/z80/descr index c565537c..98a4a3f6 100644 --- a/lib/z80/descr +++ b/lib/z80/descr @@ -9,7 +9,7 @@ var NAME=z80 var M=z80 var LIB=lib/{M}/tail_ var RT=lib/{M}/head_ -var INCLUDES=-I{EM}/include -I/usr/include +var INCLUDES=-I{EM}/include/_tail_cc -I{EM}/include/_tail_mon name be from .m.g to .s @@ -18,14 +18,20 @@ name be stdout need .e end -name asld - from .s.a +name as + from .s.so + to .o + program {EM}/lib/{M}/as + args - -o > < + prep cond +end +name led + from .o.a to .out outfile a.out - program {EM}/lib/{M}/as + program {EM}/lib/em_led mapflag -l* LNAME={EM}/{LIB}* - mapflag -i - args (.e:{HEAD}={EM}/{RT}em) \ + args -b0:0x1000 ( .e:{HEAD}={EM}/{RT}em) \ ({RTS}:.b.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \ (.p:{TAIL}={EM}/{LIB}pc) \ (.b:{TAIL}={EM}/{LIB}bc) \ From 549ecc492b0d116435d41f79a5983049f5b24a10 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 3 Feb 1987 14:55:15 +0000 Subject: [PATCH 0700/1625] new include directories --- lib/descr/int | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/descr/int b/lib/descr/int index 32be1b44..62b677c0 100644 --- a/lib/descr/int +++ b/lib/descr/int @@ -10,8 +10,8 @@ var NAME=int22 var LIB=lib/int22/tail_ var RT=lib/int22/head_ var SIZE_FLAG=-sm -var CPP_F=-Dunix -var INCLUDES=-I{EM}/include -I/usr/include +var CPP_F=-Dunix=unix +var INCLUDES=-I{EM}/include/_tail_cc -I{EM}/include/_tail_mon name asld from .k.m.a.g to .out From 5655616903e46e747c3102a6cf82939e477d54c6 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 3 Feb 1987 14:57:24 +0000 Subject: [PATCH 0701/1625] *** empty log message *** --- lib/vax4/descr.src | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/vax4/descr.src b/lib/vax4/descr.src index 87194ec3..b1dc7d3d 100644 --- a/lib/vax4/descr.src +++ b/lib/vax4/descr.src @@ -9,8 +9,9 @@ var M=vax4 var NAME=vax4 var LIB=lib/{M}/tail_ var RT=lib/{M}/head_ -var CPP_F=-Dunix -var INCLUDES=-I{EM}/include -I/usr/include +var CPP_F=-Dunix=unix -Dvax=vax +var INCLUDES=-I{EM}/include/_tail_cc +var M2SYSLIB=-I{EM}/lib/{M}/m2 name be from .m.g to .s @@ -22,8 +23,8 @@ end name asopt from .s to .so - program /bin/sed - args -f {EM}/lib/{M}/sedf + program {EM}/lib/{M}/top + args optimizer stdin stdout @@ -42,11 +43,13 @@ name ld program /bin/ld mapflag -l* LNAME={EM}/{LIB}* args (.e:{HEAD}={EM}/{RT}em) \ - ({RTS}:.b.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \ + ({RTS}:.b.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) \ + ({RTS}:.mod={EM}/{RT}m2) -o > < \ (.p:{TAIL}={EM}/{LIB}pc) \ (.b:{TAIL}={EM}/{LIB}bc) \ (.b.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \ - (.b.c.p:{TAIL}={EM}/{LIB}mon) \ - (.e:{TAIL}={EM}/{LIB}em) + (.mod:{TAIL}={EM}/{LIB}m2.1 {EM}/{LIB}m2.2 {EM}/{LIB}m2.3) \ + (.e:{TAIL}={EM}/{LIB}em) \ + (.b.c.p.mod:{TAIL}={EM}/{LIB}mon) linker end From d6cb339c6c841a92cb22fe8cd00d49d858e8ad1b Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 3 Feb 1987 14:59:54 +0000 Subject: [PATCH 0702/1625] Initial revision --- lib/m68020/descr | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 lib/m68020/descr diff --git a/lib/m68020/descr b/lib/m68020/descr new file mode 100644 index 00000000..afe972b1 --- /dev/null +++ b/lib/m68020/descr @@ -0,0 +1,43 @@ +# $Revision$ +var w=4 +var p=4 +var s=2 +var l=4 +var f=4 +var d=8 +var NAME=m68020 +var M=m68020 +var LIB=lib/{M}/tail_ +var RT=lib/{M}/head_ +var CPP_F=-Dunix=unix +var INCLUDES=-I{EM}/include/_tail_cc +# 410 align is the default +var ALIGN=-a0:2 -a1:2 -a2:0x10000 -a3:2 +name be + from .m.g + to .s + program {EM}/lib/{M}/cg + args < + stdout + need .e +end +name as + from .s.so + to .o + program {EM}/lib/{M}/as + args - -o > < + prep cond +end +name led + from .o.a + to .out + program {EM}/lib/em_led + mapflag -l* LNAME={EM}/{LIB}* + args (.e:{HEAD}= {ALIGN} {EM}/{RT}em) \ +({RTS}:.b.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \ + (.p:{TAIL}={EM}/{LIB}pc) \ + (.b:{TAIL}={EM}/{LIB}bc) \ + (.b.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \ + (.e:{TAIL}={EM}/{LIB}em {EM}/{LIB}mon {EM}/lib/{M}/end_em) + linker +end From 703b6cf608545d036f5a134cf7b16d82cd104267 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 3 Feb 1987 23:28:09 +0000 Subject: [PATCH 0703/1625] Strings and character constants now stop at end-of-line, unless escaped by a backslash --- util/cpp/preprocess.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/util/cpp/preprocess.c b/util/cpp/preprocess.c index 394770c3..fd5fa21e 100644 --- a/util/cpp/preprocess.c +++ b/util/cpp/preprocess.c @@ -122,18 +122,23 @@ preprocess(fn) do { echo(c); LoadChar(c); - if (c == '\\') { - echo(c); - LoadChar(c); - } if (c == '\n') { ++LineNumber; lineno++; + break; } else if (c == EOI) { flush(op-_obuf); return; } + if (c == '\\') { + echo(c); + LoadChar(c); + if (c == '\n') { + ++LineNumber; + lineno++; + } + } } while (c != stopc); echo(c); From 348e83181692be2ef5231c8cbbf39c3543c1d0dd Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 4 Feb 1987 10:35:30 +0000 Subject: [PATCH 0704/1625] Initial revision --- mach/z80/int/dlbin.c | 167 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 mach/z80/int/dlbin.c diff --git a/mach/z80/int/dlbin.c b/mach/z80/int/dlbin.c new file mode 100644 index 00000000..bdf6fc7e --- /dev/null +++ b/mach/z80/int/dlbin.c @@ -0,0 +1,167 @@ +/* + * Download Z80 load module into the RC702 + * + * Adapted (untested) to new ack.out format by + * Ceriel Jacobs, Vrije Universiteit, Amsterdam + */ +#include +#include +#include + +int disp = 0; + +char hex[] = "0123456789ABCDEF"; + +#define DATTYPE 0 +#define EOFTYPE 1 +#define SEGTYPE 2 +#define PCTYPE 3 + +#define MAXBYTE 32 + +char *progname; + +struct outhead ohead; +struct outsect sect[MAXSECT]; + +long pc; + +main(argc,argv) char **argv; { + register unsigned nd; + register char *s; + int first = 1; + int i; + + progname = argv[0]; + while (argc > 1 && argv[1][0] == '-') { + switch (argv[1][1]) { + case 'd': + /* displacement at load time */ + disp = atoi(&argv[1][2]); + break; + } + argc--; + argv++; + } + s = "a.out"; + if (argc == 2) + s = argv[1]; + else if (argc != 1) { + fprintf(stderr,"usage: %s [flags] [object file]\n",progname); + exit(-1); + } + if (! rd_open(s)) { + fprintf(stderr,"%s: can't open %s\n",progname,s); + exit(-1); + } + rd_ohead(&ohead); + if (ohead.oh_flags & HF_LINK) { + fprintf(stderr,"%s: %s contains unresolved references\n",progname,s); + exit(-1); + } + rd_sect(sect, ohead.oh_nsect); + for (i = 0; i < ohead.oh_nsect; i++) { + rd_outsect(i); + pc = sect[i].os_base; + if (first) { + first = 0; + putchar('L'); + putchar('S'); + } + segment(i); + while (sect[i].os_size) { + unsigned int sz = 8096, fl; + extern char *calloc(); + register char *buf; + char *pbuf; + + if (sz > sect[i].os_size) sz = sect[i].os_size; + sect[i].os_size -= sz; + pbuf = buf = calloc(sz, 1); + if (fl = sect[i].os_flen) { + if (fl > sz) fl = sz; + sect[i].os_flen -= fl; + + rd_emit(buf, (long) fl); + } + while (sz >= MAXBYTE) { + data(MAXBYTE, (int) pc, buf); + sz -= MAXBYTE; + buf += MAXBYTE; + pc += MAXBYTE; + } + if (sz > 0) { + data(sz, (int) pc, buf); + } + free(pbuf); + } + } + if (first == 0) eof(); + exit(0); +} + +segment(sg) { + + newline(2,0,SEGTYPE); + word(sg); + endline(); +} + +data(nd,pc,buf) + register char *buf; + int pc; +{ + register i; + + newline(nd, pc+disp, DATTYPE); + for (i = 0; i < nd; i++) { + byte(*buf++); + } + endline(); +} + +int check, bytecount; + +newline(n,pc,typ) { + + check = 0; + bytecount = n+5; + putchar('\n'); /* added instruction */ + putchar(':'); + byte(n); + word(pc); + byte(typ); +} + +endline() { + + byte(-check); + assert(bytecount == 0); +} + +word(w) { + + byte(w>>8); + byte(w); +} + +byte(b) { + + check += b; + bytecount--; + putchar(hex[(b>>4) & 017]); + putchar(hex[b & 017]); +} + +rd_fatal() +{ + fprintf(stderr, "%s: Read error\n", progname); + exit(-1); +} + +eof() { + + newline(0,0,EOFTYPE); + byte(0xFF); + putchar('\n'); +} From 6c483b837b619fcfb9141b544245c4138bfa3dc0 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 4 Feb 1987 10:39:27 +0000 Subject: [PATCH 0705/1625] *** empty log message *** --- mach/z80/int/Makefile | 43 +++++++++++++++++++++++++++++++++++++++++-- mach/z80/int/READ_ME | 14 +++++++++++--- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/mach/z80/int/Makefile b/mach/z80/int/Makefile index 139a7e29..76934792 100644 --- a/mach/z80/int/Makefile +++ b/mach/z80/int/Makefile @@ -1,4 +1,43 @@ -CFLAGS=-O +EMHOME=../../.. +SRC = em.s atof.s fpp.s mli4.s dvu4.s dvi4.s eb.s +OBJ = em.o atof.o fpp.o mli4.o dvu4.o dvi4.o eb.o +DLSRC = dl.c dlbin.c +LIBOBJ = $(EMHOME)/modules/lib/libobject.a + +CFLAGS = -O -I$(EMHOME)/h + +.s.o: + z80 -c -I$(EMHOME)/h $*.s + +all: int.hex dl dlbin cv + +install: all + @echo "nothing is installed" + +cmp: all + @echo "nothing is compared" + +clean: + rm -f *.o a.out dl dlbin *.hex cv + +pr: + @pr Makefile $(SRC) $(DLSRC) cv.c + +opr: + make pr | opr + +a.out: $(OBJ) + $(EMHOME)/lib/em_led -b0:0x100 -a0:2 -a1:2 -a2:2 -a3:2 $(OBJ) + +int.hex: a.out dlbin + ./dlbin a.out > int.hex + ./dosort int.hex dl: dl.o - cc -n -o dl dl.o + $(CC) -n -o dl dl.o + +dlbin: dlbin.o + $(CC) -n -o dlbin dlbin.o $(LIBOBJ) + +cv: cv.o + $(CC) -n -o cv cv.o diff --git a/mach/z80/int/READ_ME b/mach/z80/int/READ_ME index 6b2a6a43..4451b708 100644 --- a/mach/z80/int/READ_ME +++ b/mach/z80/int/READ_ME @@ -1,8 +1,12 @@ The interpreter contained here is tested under CP/M on a RC702 Z80 -microcomputer. Make it by typing `doas'. -E.out files to interpret must be made with a special Pascal library -using whatever means available, because the UNIX and CP/M conventions +microcomputer. Make it by typing `make'. +E.out files to interpret must be made with a special Pascal library, +which can be obtained by compiling the Pascal library with -DCPM, +because the UNIX and CP/M conventions about end of file and end of line differ. +Also, the size of "double" must be 4 bytes. +To accomplish this, use the "int22" ack-description file from this +directory, by putting it in the directory where you perform the compilation. Then the following sequence can be used to transmit it to CP/M. cv file.cv dl file.cv file.hex @@ -21,3 +25,7 @@ De Boelelaan 1081 1081 HV Amsterdam Holland ..!decvax!mcvax!vu44!sater + +Also, some changes have been made to convert the interpreter to the +new assembler syntax. This has never been tested, because we don't have +the target machine anymore. From dbbcc69edb7e5e87d30830e9e5fb98c41be3d003 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 4 Feb 1987 10:40:32 +0000 Subject: [PATCH 0706/1625] Initial revision --- mach/z80/int/int22 | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 mach/z80/int/int22 diff --git a/mach/z80/int/int22 b/mach/z80/int/int22 new file mode 100644 index 00000000..62e8802e --- /dev/null +++ b/mach/z80/int/int22 @@ -0,0 +1,31 @@ +# $Revision$ +var w=2 +var p=2 +var s=2 +var l=4 +var f=4 +var d=4 +var M=int +var NAME=int22 +var LIB=lib/int22/tail_ +var RT=lib/int22/head_ +var SIZE_FLAG=-sm +var CPP_F=-DCPM=CPM +var INCLUDES=-I{EM}/include/_tail_cc -I{EM}/include/_tail_mon +name asld + from .k.m.a.g + to .out + outfile e.out + program {EM}/lib/em_ass + mapflag -l* LNAME={EM}/{LIB}* + mapflag -+* ASS_F={ASS_F?} -+* + mapflag --* ASS_F={ASS_F?} --* + mapflag -s* SIZE_FLAG=-s* + args {SIZE_FLAG} \ + ({RTS}:.b.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \ + (.p:{TAIL}={EM}/{LIB}pc) \ + (.b:{TAIL}={EM}/{LIB}bc) \ + (.b.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \ + (.b.c.p:{TAIL}={EM}/{LIB}mon) + linker +end From f335d09875b589583ad646798049ed7bf3d5d231 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 4 Feb 1987 12:45:43 +0000 Subject: [PATCH 0707/1625] Initial revision --- util/cmisc/cclash.1 | 24 ++++++++++++++++++++++++ util/cmisc/cid.1 | 33 +++++++++++++++++++++++++++++++++ util/cmisc/mkdep.1 | 24 ++++++++++++++++++++++++ util/cmisc/prid.1 | 12 ++++++++++++ 4 files changed, 93 insertions(+) create mode 100644 util/cmisc/cclash.1 create mode 100644 util/cmisc/cid.1 create mode 100644 util/cmisc/mkdep.1 create mode 100644 util/cmisc/prid.1 diff --git a/util/cmisc/cclash.1 b/util/cmisc/cclash.1 new file mode 100644 index 00000000..35ece401 --- /dev/null +++ b/util/cmisc/cclash.1 @@ -0,0 +1,24 @@ +.TH CCLASH 1ACK +.SH NAME +cclash \- report clashing identifiers in C-programs +.SH SYNOPSIS +.B cclash [ -l ] [ -c | -m ] +[ file ... ] +.SH DESCRIPTION +.I Cclash +prints all identifiers that don't differ in the first characters. +The default value for is 8. +.PP +The +.B -m +option indicates that #define's must be generated for clashing identifiers. +This is of course only useful if your preprocessor can distinguish between +them. +.PP +The +.B -c +option indicates that a oldname=newname line must be generated for each +clashing identifier. This is useful input for +.IR cid (1). +.SH "SEE ALSO" +cid(1) diff --git a/util/cmisc/cid.1 b/util/cmisc/cid.1 new file mode 100644 index 00000000..3c1799cb --- /dev/null +++ b/util/cmisc/cid.1 @@ -0,0 +1,33 @@ +.TH CID 1ACK +.SH NAME +cid \- change identifiers not occurring in C comment, strings and +character constants. +.SH SYNOPSIS +.B cid +[options] [file ..] +.SH DESCRIPTION +.I Cid +copies the files, or standard input if no files are specified, to +standard output replacing the specified identifiers +by some text, defined by the caller in an option or on a file. +.br +.I Options +is a list of one or more of the following options: +.IP \fB\-D\fP\fIname\fP=\fItext\fP +.br +replace each occurence of \fIname\fP by \fItext\fP. +.I Text +may be empty, in which case the identifier is deleted. +.IP \fB\-D\fP\fIname\fP +.br +Delete all occurences of \fIname\fP. +.IP \fB\-F\fP\fIfile\fP +.br +Read substitute commands of the form "\fIname\fP=\fItext\fP", each on +a single line, from file \fIfile\fP. +.SH SEE ALSO +prid(1), cclash(1) +.SH DIAGNOSTICS +Supposed to be self explanatory. +.SH BUGS +The syntax of the substitute definitions is not (well) checked. diff --git a/util/cmisc/mkdep.1 b/util/cmisc/mkdep.1 new file mode 100644 index 00000000..7c42ecd5 --- /dev/null +++ b/util/cmisc/mkdep.1 @@ -0,0 +1,24 @@ +.TH MKDEP 1ACK +.SH NAME +mkdep \- dependency generator for C-programs +.SH SYNOPSYS +.B mkdep +file ... +.SH DESCRIPTION +.I Mkdep +scans the files in the argument list for C-preprocessor lines of the form +.DS +#include "\fIfile1\fp" +.DE +and produces for each file \fIarg\fR in the argument list a line of the form +.DS +\fIarg\fR: \fIfile1\fR \fIfile2\fR ... +.DE +where \fIfile1\fR, \fIfile2\fR, etc. are filenames included by \fIarg\fR, or +by a file included by \fIarg\fR, etc. +.PP +Only files in the current directory are scanned. +.SH "SEE ALSO" +make(1) +.SH BUGS +Should be able to handle files from other directories diff --git a/util/cmisc/prid.1 b/util/cmisc/prid.1 new file mode 100644 index 00000000..99eced70 --- /dev/null +++ b/util/cmisc/prid.1 @@ -0,0 +1,12 @@ +.TH PRID 1ACK +.SH NAME +prid \- print identifiers in C-programs longer than a certain length +.SH SYNOPSIS +.B prid [ -l ] +[ file ... ] +.SH DESCRIPTION +.I Prid +prints all identifiers with length >= . +The default value for is 8. +.SH "SEE ALSO" +cclash(1), cid(1) From 38746e18a44ec990690ac6f2b12e7652f1674c10 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 4 Feb 1987 12:51:31 +0000 Subject: [PATCH 0708/1625] Added "cmp" entry --- util/cmisc/Makefile | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/util/cmisc/Makefile b/util/cmisc/Makefile index ea0063a1..fda4909d 100644 --- a/util/cmisc/Makefile +++ b/util/cmisc/Makefile @@ -1,16 +1,31 @@ EM = ../.. EMBIN = $(EM)/bin +EMMAN = $(EM)/man CFLAGS = -O LDFLAGS = TARGETS = mkdep cid cclash prid -all: $(TARGETS) +all: mkdep cid cclash prid install: all - cp $(TARGETS) $(EMBIN) + rm -f $(EMBIN)/mkdep $(EMBIN)/cid $(EMBIN)/cclash $(EMBIN)/prid + cp mkdep cid cclash prid $(EMBIN) + rm -f $(EMMAN)/mkdep.1 $(EMMAN)/cid.1 $(EMMAN)/cclash.1 $(EMMAN)/prid.1 + cp mkdep cid cclash prid $(EMBIN) + cp mkdep.1 cid.1 cclash.1 prid.1 $(EMMAN) + +cmp: all + -cmp mkdep $(EMBIN)/mkdep + -cmp cid $(EMBIN)/cid + -cmp cclash $(EMBIN)/cclash + -cmp prid $(EMBIN)/prid + -cmp mkdep.1 $(EMMAN)/mkdep.1 + -cmp cid.1 $(EMMAN)/cid.1 + -cmp cclash.1 $(EMMAN)/cclash.1 + -cmp prid.1 $(EMMAN)/prid.1 clean: - rm -f *.o $(TARGETS) + rm -f *.o mkdep cid cclash prid mkdep: mkdep.o $(CC) $(LDFLAGS) -o mkdep mkdep.o From ecaf4711a65507d182de2e40035ce2199d869388 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 4 Feb 1987 12:54:03 +0000 Subject: [PATCH 0709/1625] Added "pr" and "opr" entries --- util/cmisc/Makefile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/util/cmisc/Makefile b/util/cmisc/Makefile index fda4909d..9d9395b0 100644 --- a/util/cmisc/Makefile +++ b/util/cmisc/Makefile @@ -27,6 +27,13 @@ cmp: all clean: rm -f *.o mkdep cid cclash prid +pr: + @pr `pwd`/Makefile `pwd`/mkdep.c `pwd`/cclash.c `pwd`/cid.c \ + `pwd`/prid.c `pwd`/GCIPM.c + +opr: + make pr | opr + mkdep: mkdep.o $(CC) $(LDFLAGS) -o mkdep mkdep.o From f76c69335c59dde068f9e178a707dccc77f72fc2 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 4 Feb 1987 13:04:51 +0000 Subject: [PATCH 0710/1625] removed the lflag, added check for '/' in filenames --- util/cmisc/mkdep.c | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/util/cmisc/mkdep.c b/util/cmisc/mkdep.c index a9e0700b..d17b0b98 100644 --- a/util/cmisc/mkdep.c +++ b/util/cmisc/mkdep.c @@ -14,8 +14,6 @@ struct namelist *freelist; struct namelist *new_namelist(); struct namelist *nl = 0; -int lflag = 0; /* produce vertical list of included files */ - char *Malloc(u) unsigned u; { @@ -86,20 +84,12 @@ print_namelist(nm, nlp) struct namelist *nlp; { if (nlp) { - if (lflag) { - while (nlp) { - printf("%s\n", nlp->name); - nlp = nlp->next; - } - } - else { printf("%s:", nm); while (nlp) { printf(" %s", nlp->name); nlp = nlp->next; } printf("\n"); - } } } @@ -109,22 +99,6 @@ main(argc, argv) int err = 0; progname = *argv++; - if (**argv == '-') { - register char *s = *argv++; - - argc--; - while (*++s) { - switch (*s) { - case 'l': - lflag = 1; - break; - default: - fprintf(stderr, "use: %s [-l] file ...\n", - progname); - return 0; - } - } - } while (--argc > 0) { free_namelist(nl); nl = 0; @@ -135,6 +109,16 @@ main(argc, argv) return err ? 1 : 0; } +int +contains_slash(s) + register char *s; +{ + while (*s) { + if (*s++ == '/') return 1; + } + return 0; +} + dofile(fn) char *fn; { @@ -147,6 +131,12 @@ dofile(fn) return 0; } + if (contains_slash(fn)) { + fprintf(stderr, "%s: (warning) %s not in current directory; not checked\n", progname, fn); + fclose(fp); + return 1; + } + while (fgets(buf, BSIZ, fp) != NULL) if (nm = include_line(buf)) { add_name(nm); From f231711f77025e45413d194dfe6e473d5f910f75 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 4 Feb 1987 13:09:02 +0000 Subject: [PATCH 0711/1625] *** empty log message *** --- util/amisc/Makefile | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/util/amisc/Makefile b/util/amisc/Makefile index 2d72e5cc..0b73ea66 100644 --- a/util/amisc/Makefile +++ b/util/amisc/Makefile @@ -1,33 +1,35 @@ -# @(#)Makefile 1.1 EM = ../.. BINDIR = $(EM)/bin +MANDIR = $(EM)/man +LIBDIR = $(EM)/modules/lib h = $(EM)/h CFLAGS = -n -O -I$h -ALL = anm asize astrip aal -OFILES = anm.o asize.o astrip.o aal.o -CFILES = anm.c asize.c astrip.c aal.c +ALL = anm asize astrip +OFILES = anm.o asize.o astrip.o +CFILES = anm.c asize.c astrip.c +LIBS = $(LIBDIR)/libobject.a all: $(ALL) anm: anm.c - $(CC) $(CFLAGS) -o anm anm.c + $(CC) $(CFLAGS) -o anm anm.c $(LIBS) asize: asize.c - $(CC) $(CFLAGS) -o asize asize.c + $(CC) $(CFLAGS) -o asize asize.c $(LIBS) astrip: astrip.c - $(CC) $(CFLAGS) -o astrip astrip.c -aal: aal.c - $(CC) $(CFLAGS) -DAUTORAN -o aal aal.c + $(CC) $(CFLAGS) -o astrip astrip.c $(LIBS) install: all - for i in $(ALL); do cp $$i $(BINDIR)/$$i; done + for i in $(ALL); do rm -f $(BINDIR)/$$i; cp $$i $(BINDIR)/$$i; done + for i in anm.1 asize.1 astrip.1; do rm -f $(MANDIR)/$$i; cp $$i $(MANDIR)/$$i; done cmp: all - for i in $(ALL); do cmp $$i $(BINDIR)/$$i; done + -for i in $(ALL); do cmp $$i $(BINDIR)/$$i; done + -for i in anm.1 astrip.1 asize.1 ; do cmp $$i $(MANDIR)/$$i; done clean: ; rm -f $(ALL) $(OFILES) -pr: $(CFILES) - @pr -n Makefile $(CFILES) +pr: + @pr `pwd`/Makefile `pwd`/anm.c `pwd`/astrip.c `pwd`/asize.c opr: make pr | opr From c81beeed686e93ff32b9a2b42be1404d0eb866f8 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 4 Feb 1987 13:10:17 +0000 Subject: [PATCH 0712/1625] Initial revision --- util/amisc/anm.1 | 74 +++++++++++++++++++++++++++++++++++++++++++++ util/amisc/asize.1 | 17 +++++++++++ util/amisc/astrip.1 | 17 +++++++++++ 3 files changed, 108 insertions(+) create mode 100644 util/amisc/anm.1 create mode 100644 util/amisc/asize.1 create mode 100644 util/amisc/astrip.1 diff --git a/util/amisc/anm.1 b/util/amisc/anm.1 new file mode 100644 index 00000000..e1892795 --- /dev/null +++ b/util/amisc/anm.1 @@ -0,0 +1,74 @@ +.TH ANM 1ACK +.SH NAME +anm \- print name list +.SH SYNOPSIS +.B anm +[ +.B \-gnoprus +] +[ file ... ] +.SH DESCRIPTION +.I Anm +prints the name list (symbol table) of each ack.out(5) format object +.I file +in the argument list. +If no +.I file +is given, the symbols in +`a.out' +are listed. +.PP +Each symbol name is preceded by its value, a section indicator +and a type indicator. +A section indicator can be +.SM +.B U +(undefined symbol), +.SM +.B A +(absolute symbol), a section number (section related symbol), +or +.SM +.B - +(other symbol). +A type indicator can be +.SM +.B F +(filename), +.SM +.B M +(module name), +.SM +.B E +(external (global) symbol), +or +.SM +.B - +(local symbol). +The output is sorted alphabetically. +.PP +Options are: +.TP +.B \-g +Print only external (global) symbols. +.TP +.B \-n +Sort numerically rather than alphabetically. +.TP +.B \-o +Prepend file name to each output line rather than only once. +.TP +.B \-p +Don't sort; print in symbol-table order. +.TP +.B \-r +Sort in reverse order. +.TP +.B \-u +Print only undefined symbols. +.TP +.B \-s +Sort in section order. +.sh FILES +.SH SEE ALSO +ack.out(5) diff --git a/util/amisc/asize.1 b/util/amisc/asize.1 new file mode 100644 index 00000000..96d8fd91 --- /dev/null +++ b/util/amisc/asize.1 @@ -0,0 +1,17 @@ +.TH ASIZE 1ACK +.SH NAME +asize \- size of an object file +.SH SYNOPSIS +.B asize +[ file ... ] +.SH DESCRIPTION +.I Asize +prints the (decimal) number of bytes +required by the different sections, +and their sum in decimal and hexadecimal, +of each ack.out(5) format object file argument. +If no file is specified, +`a.out' +is used. +.SH "SEE ALSO" +ack.out(5) diff --git a/util/amisc/astrip.1 b/util/amisc/astrip.1 new file mode 100644 index 00000000..d7fd6ade --- /dev/null +++ b/util/amisc/astrip.1 @@ -0,0 +1,17 @@ +.TH ASTRIP 1ACK +.SH NAME +astrip \- remove symbols and relocation information +.SH SYNOPSIS +.B astrip +file ... +.SH DESCRIPTION +.I Astrip +removes the symbol +table and relocation information ordinarily attached to the +ack.out(5) format object files. +This is useful to save space after a program has been +debugged. +.SH FILES +/tmp/s? temporary file +.SH "SEE ALSO" +ack.out(5) From b2a28142bd71f9531823fdba5ee76b4055bcd932 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 4 Feb 1987 15:09:31 +0000 Subject: [PATCH 0713/1625] adapted to new assembler syntax --- mach/pdp/cg/mach.c | 13 ++++++++++--- mach/pdp/cg/mach.h | 12 +++++++++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/mach/pdp/cg/mach.c b/mach/pdp/cg/mach.c index 24602f09..07fd9445 100644 --- a/mach/pdp/cg/mach.c +++ b/mach/pdp/cg/mach.c @@ -45,12 +45,12 @@ con_part(sz,w) register sz; word w; { } con_mult(sz) word sz; { - long l; + long l, atol(); if (sz != 4) fatal("bad icon/ucon size"); #ifdef ACK_ASS - fprintf(codefile,".long %s\n",str); + fprintf(codefile,".data4 %s\n",str); #else l = atol(str); fprintf(codefile,"\t%o;%o\n",(int)(l>>16),(int)l); @@ -70,7 +70,7 @@ con_float() { if (argval != 4 && argval != 8) fatal("bad fcon size"); - fprintf(codefile,".long\t"); + fprintf(codefile,".data4\t"); if (argval == 8) fprintf(codefile,"F_DUM,"); fprintf(codefile,"F_DUM\n"); @@ -236,8 +236,15 @@ mes(type) word type; { } char *segname[] = { +#ifdef ACK_ASS + ".sect .text", /* SEGTXT */ + ".sect .data", /* SEGCON */ + ".sect .rom", /* SEGROM */ + ".sect .bss" /* SEGBSS */ +#else ".text", /* SEGTXT */ ".data", /* SEGCON */ ".data", /* SEGROM */ ".bss" /* SEGBSS */ +#endif }; diff --git a/mach/pdp/cg/mach.h b/mach/pdp/cg/mach.h index eae2d579..92b9cf75 100644 --- a/mach/pdp/cg/mach.h +++ b/mach/pdp/cg/mach.h @@ -33,14 +33,20 @@ #define hol_off "0%o+hol%d" #ifdef ACK_ASS -#define con_cst(x) fprintf(codefile,".short 0%o\n",x) -#define con_ilb(x) fprintf(codefile,".short %s\n",x) -#define con_dlb(x) fprintf(codefile,".short %s\n",x) +#define con_cst(x) fprintf(codefile,".data2 0%o\n",x) +#define con_ilb(x) fprintf(codefile,".data2 %s\n",x) +#define con_dlb(x) fprintf(codefile,".data2 %s\n",x) #else #define con_cst(x) fprintf(codefile,"0%o\n",x) #define con_ilb(x) fprintf(codefile,"%s\n",x) #define con_dlb(x) fprintf(codefile,"%s\n",x) #endif +#ifdef ACK_ASS +#define modhead ".sect .text; .sect .rom; .sect .data; .sect .bss\n" +#define fmt_id(f,t) sprintf(t,"_%s",f) +#else #define id_first '_' +#endif + #define BSS_INIT 0 From c43aa963d868ac4b69d4295f322cd3611a085b90 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 4 Feb 1987 15:11:51 +0000 Subject: [PATCH 0714/1625] Added some neccessary NC's --- mach/pdp/cg/table | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/mach/pdp/cg/table b/mach/pdp/cg/table index 8b275f5a..d0141c74 100644 --- a/mach/pdp/cg/table +++ b/mach/pdp/cg/table @@ -400,35 +400,35 @@ sti $1==1 | REG source1or2 | ... | regind2 source1or2 | INDSTORE move(%[2],{reginddef1,%[1.reg],%[1.ind]}) | | | -sti $1==4 | dadres2 FLT_REG | +sti $1==4 | NC dadres2 FLT_REG | INDSTORE "movfo %[2],*%[1]" samecc | | | -... | dadres2 ftolong | +... | NC dadres2 ftolong | INDSTORE "setl\nmovfi %[2.reg],*%[1]\nseti" samecc | | | -... | regconst2 FLT_REG | +... | NC regconst2 FLT_REG | INDSTORE "movfo %[2],%[1.ind](%[1.reg])" samecc | | | -... | regconst2 ftolong | +... | NC regconst2 ftolong | INDSTORE "setl\nmovfi %[2.reg],%[1.ind](%[1.reg])\nseti" samecc | | | -... | ADDR_LOCAL FLT_REG | +... | NC ADDR_LOCAL FLT_REG | INDSTORE "movfo %[2],%[1.ind](r5)" samecc | | | -... | ADDR_LOCAL ftolong | +... | NC ADDR_LOCAL ftolong | INDSTORE "setl\nmovfi %[2.reg],%[1.ind](r5)\nseti" samecc | | | -... | ADDR_EXTERNAL FLT_REG | +... | NC ADDR_EXTERNAL FLT_REG | INDSTORE "movfo %[2],%[1.ind]" samecc | | | -... | ADDR_EXTERNAL ftolong | +... | NC ADDR_EXTERNAL ftolong | INDSTORE "setl\nmovfi %[2.reg],%[1.ind]\nseti" samecc | | | @@ -440,19 +440,19 @@ sti $1==4 | dadres2 FLT_REG | "mov (sp)+,(%[1])+" "mov (sp)+,(%[1])" erase(%[1]) | | | (4,2040) -sti $1==8 | dadres2 DBL_REG | +sti $1==8 | NC dadres2 DBL_REG | INDSTORE "movf %[2],*%[1]" samecc | | | -... | regconst2 DBL_REG | +... | NC regconst2 DBL_REG | INDSTORE "movf %[2],%[1.ind](%[1.reg])" samecc | | | -... | ADDR_LOCAL DBL_REG | +... | NC ADDR_LOCAL DBL_REG | INDSTORE "movf %[2],%[1.ind](r5)" samecc | | | -... | ADDR_EXTERNAL DBL_REG | +... | NC ADDR_EXTERNAL DBL_REG | INDSTORE "movf %[2],%[1.ind]" samecc | | | From 345fa61777bbb60cb156d500ccb5b850108301d7 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 4 Feb 1987 15:31:50 +0000 Subject: [PATCH 0715/1625] *** empty log message *** --- mach/pdp/libbc/Makefile | 3 ++- mach/pdp/libbc/compmodule | 6 ++++-- mach/pdp/libcc/Makefile | 7 ++++--- mach/pdp/libcc/compmodule | 6 ++++-- mach/pdp/libpc/Makefile | 8 ++++---- mach/pdp/libpc/compmodule | 6 ++++-- 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/mach/pdp/libbc/Makefile b/mach/pdp/libbc/Makefile index 7e516a90..3d6791ca 100644 --- a/mach/pdp/libbc/Makefile +++ b/mach/pdp/libbc/Makefile @@ -1,5 +1,6 @@ +SUF=o MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=pdp" "SUF=o" "ASAR=ar" +MACHDEF="MACH=pdp" "SUF=$(SUF)" "ASAR=ar" BCDEF="PREF=bc" "SUB=" "SRC=lang/basic/lib" install: diff --git a/mach/pdp/libbc/compmodule b/mach/pdp/libbc/compmodule index 491f6d25..a794a225 100755 --- a/mach/pdp/libbc/compmodule +++ b/mach/pdp/libbc/compmodule @@ -1,2 +1,4 @@ -${MACH?} -I../../../h ${MACHFL?} $1 1>&2 -echo `basename $1 $2`.o +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 +fi diff --git a/mach/pdp/libcc/Makefile b/mach/pdp/libcc/Makefile index 5ebb62db..37540670 100644 --- a/mach/pdp/libcc/Makefile +++ b/mach/pdp/libcc/Makefile @@ -1,12 +1,13 @@ +SUF=o MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=pdp" "SUF=o" "ASAR=ar" +MACHDEF="MACH=pdp" "SUF=$(SUF)" "ASAR=ar" STDIO="PREF=cc" "SUB=.1s" "SRC=lang/cem/libcc/stdio" GEN="PREF=cc" "SUB=.2g" "SRC=lang/cem/libcc/gen" MON="PREF=mon" "SRC=lang/cem/libcc/mon" LIBM="PREF=m" "SRC=lang/cem/libcc/libm" LIBLN="PREF=ln" "SRC=lang/cem/libcc/libln" -install: cpstdio cpgen cplibm cplibln +install: cpstdio cpgen cpstdio: make -f $(MAKEFILE) $(STDIO) $(MACHDEF) tailcp @@ -19,7 +20,7 @@ cplibm: cplibln: make -f $(MAKEFILE) $(LIBLN) $(MACHDEF) tailcp -cmp: cmpstdio cmpgen cmplibm cmplibln +cmp: cmpstdio cmpgen cmpstdio: make -f $(MAKEFILE) $(STDIO) $(MACHDEF) tail diff --git a/mach/pdp/libcc/compmodule b/mach/pdp/libcc/compmodule index 491f6d25..a794a225 100755 --- a/mach/pdp/libcc/compmodule +++ b/mach/pdp/libcc/compmodule @@ -1,2 +1,4 @@ -${MACH?} -I../../../h ${MACHFL?} $1 1>&2 -echo `basename $1 $2`.o +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 +fi diff --git a/mach/pdp/libpc/Makefile b/mach/pdp/libpc/Makefile index ddc6a8e6..b29dee4e 100644 --- a/mach/pdp/libpc/Makefile +++ b/mach/pdp/libpc/Makefile @@ -1,15 +1,15 @@ +SUF=o MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=pdp -Rbe-p2" "SUF=s" "ASAR=ar" +MACHDEF="MACH=pdp -Rbe-p2" "SUF=$(SUF)" "ASAR=ar" PCDEF="PREF=pc" "SUB=" "SRC=lang/pc/libpc" -LIBDIR=../lib install: make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) cp cmp: make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) all - cmp head_pc $(LIBDIR)/head_pc - cmp tail_pc $(LIBDIR)/tail_pc + -../../compare head_pc + -../../compare tail_pc clean: -rm -f *.old *.[ce$(SUF)] tail* head* diff --git a/mach/pdp/libpc/compmodule b/mach/pdp/libpc/compmodule index 491f6d25..a794a225 100755 --- a/mach/pdp/libpc/compmodule +++ b/mach/pdp/libpc/compmodule @@ -1,2 +1,4 @@ -${MACH?} -I../../../h ${MACHFL?} $1 1>&2 -echo `basename $1 $2`.o +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 +fi From fe66ff871a21bfd358e939722c4a3779976f9464 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 4 Feb 1987 15:39:00 +0000 Subject: [PATCH 0716/1625] Name change of archive --- mach/pdp/libem/LIST | 2 +- mach/pdp/libem/Makefile | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/mach/pdp/libem/LIST b/mach/pdp/libem/LIST index b5ba9485..aeadc40d 100644 --- a/mach/pdp/libem/LIST +++ b/mach/pdp/libem/LIST @@ -1,4 +1,4 @@ -tail_em.s.a +libem_s.a RT.s adf.s adi.s diff --git a/mach/pdp/libem/Makefile b/mach/pdp/libem/Makefile index bbad255b..c58a41ed 100644 --- a/mach/pdp/libem/Makefile +++ b/mach/pdp/libem/Makefile @@ -1,28 +1,28 @@ +all: head_em.o libem_o.a install: cp cp: all - ../../install head_em - ../../install tail_em - rm -f head_em tail_em + ../../install head_em.o head_em + ../../install libem_o.a tail_em cmp: all - -../../compare head_em - -../../compare tail_em - rm -f head_em tail_em + -../../compare head_em.o head_em + -../../compare libem_o.a tail_em -all: head_em tail_em -head_em: head_em.s - pdp -c head_em.s ; mv head_em.o head_em +head_em.o: head_em.s + pdp -c head_em.s -tail_em: - march . tail_em +libem_o.a: libem_s.a + march . libem_o.a clean: - rm -f *.o + rm -f *.o libem_o.a + opr: make pr | opr + pr: @pr `pwd`/Makefile `pwd`/head_em.s - pr -l33 `tail +1 LIST|sort` + @arch pv libem_s.a | pr -h `pwd`/libem_s.a From 6532d40ba09e4d36faab95cc205384ac5838bacd Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 4 Feb 1987 15:41:00 +0000 Subject: [PATCH 0717/1625] Added definition for ASAR --- mach/pdp/libem/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/pdp/libem/Makefile b/mach/pdp/libem/Makefile index c58a41ed..ee017a73 100644 --- a/mach/pdp/libem/Makefile +++ b/mach/pdp/libem/Makefile @@ -15,7 +15,7 @@ head_em.o: head_em.s pdp -c head_em.s libem_o.a: libem_s.a - march . libem_o.a + ASAR=ar ; export ASAR ; march . libem_o.a clean: rm -f *.o libem_o.a From 6cf214a0f414727613e69f11ca62f2f1731ca6f3 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 4 Feb 1987 15:47:57 +0000 Subject: [PATCH 0718/1625] archive name change --- mach/pdp/libsys/LIST | 2 +- mach/pdp/libsys/Makefile | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/mach/pdp/libsys/LIST b/mach/pdp/libsys/LIST index 0db8f411..408d1d37 100644 --- a/mach/pdp/libsys/LIST +++ b/mach/pdp/libsys/LIST @@ -1,4 +1,4 @@ -tail_mon.a +libmon_s.a exit.c cleanup.c stty.c diff --git a/mach/pdp/libsys/Makefile b/mach/pdp/libsys/Makefile index 733850b9..10311ee7 100644 --- a/mach/pdp/libsys/Makefile +++ b/mach/pdp/libsys/Makefile @@ -1,25 +1,24 @@ # $Header$ +all: libmon_o.a + install: cp cp: all - ../../install tail_mon - rm -f head_em tail_mon + ../../install libmon_o.a tail_mon cmp: all - -../../compare tail_mon - rm -f head_em tail_mon + -../../compare libmon_o.a tail_mon -all: tail_mon - -tail_mon: +libmon_o.a: libmon_s.a ASAR=ar ; export ASAR ;\ - RANLIB=ranlib ; export RANLIB ;\ - march . tail_mon + march . libmon_o.a clean: - rm -f *.o + rm -f *.o libmon_o.a + opr: make pr | opr + pr: - @pr `pwd`/Makefile `pwd`/head_em.s - @pr -l33 `tail +1 LIST|sort` + @pr `pwd`/Makefile + @arch pv libmon_s.a | pr -h `pwd`/libmon_s.a From bcb8e8b19fb60356a67b929000618188eeae398a Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 4 Feb 1987 15:51:35 +0000 Subject: [PATCH 0719/1625] Added libsys, top --- mach/pdp/Action | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mach/pdp/Action b/mach/pdp/Action index fbe1967a..3051d78c 100644 --- a/mach/pdp/Action +++ b/mach/pdp/Action @@ -4,6 +4,9 @@ end name "PDP 11 backend" dir cg end +name "PDP 11 target optimizer" +dir top +end name "PDP 11 interpreter" system pdp* dir int @@ -16,6 +19,10 @@ name "PDP 11 EM library" system pdp* dir libem end +name "PDP 11 systemcall library" +system pdp* +dir libsys +end name "PDP 11 Pascal library" system pdp* dir libpc From 33bd214f179d7565eedae76302053d09251394c6 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 4 Feb 1987 15:55:32 +0000 Subject: [PATCH 0720/1625] Added asopt --- lib/pdp/descr | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/pdp/descr b/lib/pdp/descr index cf1586f4..1940e169 100644 --- a/lib/pdp/descr +++ b/lib/pdp/descr @@ -9,8 +9,8 @@ var M=pdp var NAME=pdp var LIB=lib/{M}/tail_ var RT=lib/{M}/head_ -var CPP_F=-Dunix -var INCLUDES=-I{EM}/include -I/usr/include +var CPP_F=-Dunix=unix +var INCLUDES=-I{EM}/include/_tail_cc name be from .m.g to .s @@ -19,8 +19,17 @@ name be stdout need .e end -name as +name asopt from .s + to .so + program {EM}/lib/{M}/top + args + optimizer + stdin + stdout +end +name as + from .s.so to .o program /bin/as args - -o > < @@ -37,6 +46,6 @@ name ld (.p:{TAIL}={EM}/{LIB}pc) \ (.b:{TAIL}={EM}/{LIB}bc) \ (.b.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \ - (.e:{TAIL}={EM}/{LIB}em) (.b.c.p:{TAIL}=/lib/libc.a) + (.e:{TAIL}={EM}/{LIB}em {EM}/{LIB}mon) linker end From bdd440386817f96add43593e1639f14fda6ff010 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 4 Feb 1987 16:03:54 +0000 Subject: [PATCH 0721/1625] fixed error in call of C_con_scon --- modules/src/em_code/em_code.3X | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/src/em_code/em_code.3X b/modules/src/em_code/em_code.3X index 872bbcbc..37a5464a 100644 --- a/modules/src/em_code/em_code.3X +++ b/modules/src/em_code/em_code.3X @@ -241,7 +241,7 @@ A sequence of calls to get this, is .RS .nf C_con_icon("23", (arith)4); -C_con_scon("hello world"); +C_con_scon("hello world", (arith) 11); C_con_dlb((label)12, (arith)0); C_con_dnam("table", (arith)12); C_con_ilb((label)33); From 5de07ddceb9ca2505d8f6a32baa11141e9fe7e73 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 4 Feb 1987 16:21:03 +0000 Subject: [PATCH 0722/1625] *** empty log message *** --- mach/i86/libbc/Makefile | 3 ++- mach/i86/libcc/Makefile | 3 ++- mach/i86/libpc/Makefile | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/mach/i86/libbc/Makefile b/mach/i86/libbc/Makefile index 0b1a1cb5..ea5efd82 100644 --- a/mach/i86/libbc/Makefile +++ b/mach/i86/libbc/Makefile @@ -1,5 +1,6 @@ +SUF=o MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=i86" "SUF=o" "ASAR=aal" +MACHDEF="MACH=i86" "SUF=$(SUF)" "ASAR=aal" BCDEF="PREF=bc" "SUB=" "SRC=lang/basic/lib" install: diff --git a/mach/i86/libcc/Makefile b/mach/i86/libcc/Makefile index 07b125b0..bd7ef764 100644 --- a/mach/i86/libcc/Makefile +++ b/mach/i86/libcc/Makefile @@ -1,5 +1,6 @@ +SUF=o MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=i86" "SUF=o" "ASAR=aal" +MACHDEF="MACH=i86" "SUF=$(SUF)" "ASAR=aal" STDIO="PREF=cc" "SUB=.1s" "SRC=lang/cem/libcc/stdio" GEN="PREF=cc" "SUB=.2g" "SRC=lang/cem/libcc/gen" MON="PREF=mon" "SRC=lang/cem/libcc/mon" diff --git a/mach/i86/libpc/Makefile b/mach/i86/libpc/Makefile index 546722ac..500b08a8 100644 --- a/mach/i86/libpc/Makefile +++ b/mach/i86/libpc/Makefile @@ -1,5 +1,6 @@ +SUF=o MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=i86" "SUF=o" "ASAR=aal" +MACHDEF="MACH=i86" "SUF=$(SUF)" "ASAR=aal" PCDEF="PREF=pc" "SUB=" "SRC=lang/pc/libpc" install: From 2d964549c9dd7b1461cc126b318768a139b125f1 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 4 Feb 1987 16:44:15 +0000 Subject: [PATCH 0723/1625] Initial revision --- mach/i86/cv/Makefile | 25 ++++ mach/i86/cv/cv.c | 290 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 315 insertions(+) create mode 100644 mach/i86/cv/Makefile create mode 100644 mach/i86/cv/cv.c diff --git a/mach/i86/cv/Makefile b/mach/i86/cv/Makefile new file mode 100644 index 00000000..5cfa97a6 --- /dev/null +++ b/mach/i86/cv/Makefile @@ -0,0 +1,25 @@ +EMHOME = ../../.. +LIBOBJ = $(EMHOME)/modules/lib/libobject.a +INCLUDE = $(EMHOME)/h +CFLAGS = -I. -I$(INCLUDE) -O +TARGETS = cv + +all: $(TARGETS) + +install: all + ../../install cv + +cmp: all + ../../compare cv + +cv: cv.o + $(CC) $(LDFLAGS) -o cv cv.o $(LIBOBJ) + +clean: + rm -f $(TARGETS) *.o nohup.out Out + +pr: + @pr Makefile cv.c + +opr: + make pr | opr diff --git a/mach/i86/cv/cv.c b/mach/i86/cv/cv.c new file mode 100644 index 00000000..3afafbf0 --- /dev/null +++ b/mach/i86/cv/cv.c @@ -0,0 +1,290 @@ +/* + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. + * + * This product is part of the Amsterdam Compiler Kit. + * + * Permission to use, sell, duplicate or disclose this software must be + * obtained in writing. Requests for such permissions may be sent to + * + * Dr. Andrew S. Tanenbaum + * Wiskundig Seminarium + * Vrije Universiteit + * Postbox 7161 + * 1007 MC Amsterdam + * The Netherlands + * + */ + +/* + * This program converts ack.out format to PC/IX a.out format. + * It uses ~em/modules/lib/libobject.a. + */ + +#include + +struct exec { + unsigned char a_magic[2]; + unsigned char a_flags; + unsigned char a_cpu; + unsigned char a_hdrlen; + unsigned char a_unused; + unsigned short a_version; + long a_text; + long a_data; + long a_bss; + long a_entry; + long a_misc; + long a_syms; +}; + +struct nlist +{ char n_name[8]; + long n_value; + unsigned char n_sclass; + unsigned char n_numaux; + unsigned short n_type; +}; + +#include + +#ifndef NORCSID +static char rcs_id[] = "$Header$" ; +#endif + +#define ENTRY 0x0 /* entry point */ + +/* + * Header and section table of new format object file. + */ +struct outhead outhead; +struct outsect outsect[S_MAX]; + +struct exec exec; + +char *output_file; +int outputfile_created; +int output; + +char *program ; + +char flag ; + +/* Output file definitions and such */ + +#define TEXTSG 0 +#define ROMSG 1 +#define DATASG 2 +#define BSSSG 3 +#define LSECT BSSSG+1 +#define NSECT LSECT+1 + +main(argc, argv) + int argc; + char *argv[]; +{ + register int nsect; + long magic ; + long textsize ; + long datasize ; + long bsssize; + long symstart; + register struct exec *e = &exec; + + output = 1; + program= argv[0] ; + if ( argc>1 && argv[1][0]=='-' ) { + flag=argv[1][1] ; + argc-- ; argv++ ; + } + switch (argc) { + case 1: rd_fdopen(0); + break; + case 3: if ((output = creat(argv[2], 0644)) < 0) { + fatal("Can't write %s.\n", argv[2]); + } + output_file = argv[2]; + outputfile_created = 1; + /* FALLTHROUGH */ + case 2: + if (! rd_open(argv[1])) + fatal("Can't read %s.\n", argv[1]); + break; + default:fatal("Usage: %s
.\n", argv[0]); + } + rd_ohead(&outhead); + if (BADMAGIC(outhead)) + fatal("Not an ack object file.\n"); + if (outhead.oh_flags & HF_LINK) + fatal("Contains unresolved references.\n"); + if (outhead.oh_nrelo > 0) + fprintf(stderr, "Warning: relocation information present.\n"); + if ( outhead.oh_nsect!=LSECT && outhead.oh_nsect!=NSECT ) + fatal("Input file must have %d sections, not %ld\n", + NSECT,outhead.oh_nsect) ; + rd_sect(outsect, outhead.oh_nsect); + while (outsect[TEXTSG].os_size % outsect[TEXTSG].os_lign) + outsect[TEXTSG].os_size++; + while (outsect[ROMSG].os_size % outsect[ROMSG].os_lign) + outsect[ROMSG].os_size++; + while (outsect[DATASG].os_size % outsect[DATASG].os_lign) + outsect[DATASG].os_size++; + /* A few checks */ + if ( outsect[TEXTSG].os_base != ENTRY) + fatal("text must start at %d not at 0x%lx\n", ENTRY, + outsect[TEXTSG].os_base) ; + if ( outsect[BSSSG].os_flen != 0 ) + fatal("bss space contains initialized data\n") ; + if ( outsect[BSSSG].os_base != outsect[DATASG].os_base+ + outsect[DATASG].os_size ) + fatal("bss segment must follow data segment\n") ; + + e->a_magic[0] = 01; + e->a_magic[1] = 03; + e->a_cpu = 04; + e->a_hdrlen = 32; + e->a_text = outsect[TEXTSG].os_size; + e->a_data = outsect[ROMSG].os_size + outsect[DATASG].os_size; + e->a_bss = outsect[BSSSG].os_size; + e->a_entry = outsect[TEXTSG].os_base; + e->a_syms = (long) outhead.oh_nname * sizeof (struct nlist); + e->a_misc = 0x10000; + if ( outsect[ROMSG].os_base == 0x0 ) { + /* Separate I/D */ + e->a_flags = 0x20; + if ( outsect[DATASG].os_base != outsect[ROMSG].os_base+ + outsect[ROMSG].os_size ) + fatal("data segment must follow rom\n") ; + } else { + e->a_flags = 0x10; + if ( outsect[ROMSG].os_base != outsect[TEXTSG].os_base+ + outsect[TEXTSG].os_size ) + fatal("rom segment must follow text\n") ; + if ( outsect[DATASG].os_base != outsect[ROMSG].os_base+ + outsect[ROMSG].os_size ) + fatal("data segment must follow rom\n") ; + } + if ( outhead.oh_nsect==NSECT ) { + if ( outsect[LSECT].os_base != outsect[BSSSG].os_base+ + outsect[BSSSG].os_size ) + fatal("end segment must follow bss\n") ; + if ( outsect[LSECT].os_size != 0 ) + fatal("end segment must be empty\n") ; + } + + /* Action at last */ + write(output, (char *) e, 32); + emits(&outsect[TEXTSG]) ; + emits(&outsect[ROMSG]) ; + emits(&outsect[DATASG]) ; + emit_symtab(); + if ( outputfile_created ) chmod(argv[2],0755); + return 0; +} + +/* + * Transfer the emitted byted from one file to another. + */ +emits(section) struct outsect *section ; { + register long n ; + register int blk; + char buffer[BUFSIZ]; + + n= section->os_flen ; + rd_outsect(section - outsect); + while (n > 0) { + blk = n > BUFSIZ ? BUFSIZ : n; + rd_emit(buffer, (long) blk); + write(output, buffer, blk); + n -= blk; + } + if ((n = section->os_size - section->os_flen) > 0) { + for (blk = BUFSIZ - 1; blk >= 0; blk--) { + buffer[blk] = 0; + } + while (n > 0) { + blk = n > BUFSIZ ? BUFSIZ : n; + write(output, buffer, blk); + n -= blk; + } + } +} + +emit_symtab() +{ + struct outname ACK_name; /* symbol table entry in ACK format */ + struct nlist IX_name; /* symbol table entry in PC/IX format */ + register unsigned short i; + + char x; + long y; + extern char *malloc(); + char *chars; + long l; + long off = OFF_CHAR(outhead); + int j; + char *p; + + chars = malloc(outhead.oh_nchar); + rd_string(chars,outhead.oh_nchar); + for (i = 0; i < outhead.oh_nname; i++) { + rd_name(&ACK_name, 1); + switch(ACK_name.on_type & S_TYP) { + case S_UND: + IX_name.n_sclass = 0; + break; + case S_ABS: + IX_name.n_sclass = 01; + break; + case S_MIN + TEXTSG: + IX_name.n_sclass = 02; + break; + case S_MIN + ROMSG: + case S_MIN + DATASG: + IX_name.n_sclass = 03; + break; + case S_MIN + BSSSG: + case S_MIN + LSECT: + IX_name.n_sclass = 04; + break; + default: + fprintf(stderr,"warning: unknown s_type: %d\n", + ACK_name.on_type & S_TYP); + } + if (ACK_name.on_type & S_EXT) IX_name.n_sclass |= 020; + IX_name.n_value = ACK_name.on_valu; + if (ACK_name.on_foff == 0) { + p = "\0\0"; + } + else { + l = ACK_name.on_foff - off; + if (l < 0 || l >= outhead.oh_nchar) { + fatal("bad on_off: %ld\n",l); + } + p = &chars[l]; + } + for (j = 0; j < 8; j++) { + IX_name.n_name[j] = *p++; + if (*p == '\0') break; + } + for (j++; j < 8; j++) { + IX_name.n_name[j] = 0; + } + write(output, (char *) &IX_name, sizeof(struct nlist)); + } +} + +/* VARARGS1 */ +fatal(s, a1, a2) + char *s; +{ + fprintf(stderr,"%s: ",program) ; + fprintf(stderr, s, a1, a2); + if (outputfile_created) + unlink(output_file); + exit(1); +} + +rd_fatal() +{ + fatal("read error\n"); +} From 5c0d0f6cc204cfc5ebafc580f3790077c14f9dd9 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 4 Feb 1987 17:22:08 +0000 Subject: [PATCH 0724/1625] Added a few "nocoercions :" --- mach/i86/cg/table | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mach/i86/cg/table b/mach/i86/cg/table index 82049d18..3929bd02 100644 --- a/mach/i86/cg/table +++ b/mach/i86/cg/table @@ -365,7 +365,7 @@ sti $1==2 | ADDREG regorconst | ... | nocoercions : reg_off STACK | remove(referals) "pop %[1]" samecc | | | -... | ADDR_LOCAL | | | stl %[1.ind] | +... | nocoercions : ADDR_LOCAL | | | stl %[1.ind] | ... | bpreg_off regorconst | remove(all_locals) remove(indexed) @@ -462,7 +462,7 @@ sdf | ADDREG regorconst regorconst | "pop $1+%[1]" "pop %($1+2%)+%[1]" samecc | | | /* Funny things happen when the sign changes in the stl parameters */ -... | ADDR_LOCAL | | | stl %[1.ind]+$1 stl %[1.ind]+$1+2 | +... | nocoercions: ADDR_LOCAL | | | stl %[1.ind]+$1 stl %[1.ind]+$1+2 | ... | bpreg_off regorconst regorconst | remove(all_locals) remove(indexed) From f79c3a006727e031fae2cfd159c49b9d17985b80 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 4 Feb 1987 17:43:20 +0000 Subject: [PATCH 0725/1625] *** empty log message *** --- mach/proto/cg/subr.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mach/proto/cg/subr.c b/mach/proto/cg/subr.c index a3801ffc..036fd9a7 100644 --- a/mach/proto/cg/subr.c +++ b/mach/proto/cg/subr.c @@ -59,8 +59,8 @@ match(tp,tep,optexp) register token_p tp; register set_p tep; { return(result.e_v.e_con); } -instance(instno,token) token_p token; { - inst_p inp; +instance(instno,token) register token_p token; { + register inst_p inp; int i; token_p tp; struct reginfo *rp; @@ -138,8 +138,8 @@ instance(instno,token) token_p token; { } } -cinstance(instno,token,tp,regno) token_p token,tp; { - inst_p inp; +cinstance(instno,token,tp,regno) register token_p token,tp; { + register inst_p inp; int i; struct reginfo *rp; result_t result; From 0985c42fdd7f0c55cbfa2591d946febb1790e274 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 5 Feb 1987 13:17:00 +0000 Subject: [PATCH 0726/1625] *** empty log message *** --- util/LLgen/LLgen.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/LLgen/LLgen.1 b/util/LLgen/LLgen.1 index 622a11a6..08d8f2f6 100644 --- a/util/LLgen/LLgen.1 +++ b/util/LLgen/LLgen.1 @@ -1,5 +1,5 @@ .\" $Header$ -.TH LLGEN 1 +.TH LLGEN 1ACK .SH NAME LLgen, an extended LL(1) parser generator .SH SYNOPSIS From 89b5f5c8c487e6093a6c447dca37dda8614030ce Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 5 Feb 1987 13:20:03 +0000 Subject: [PATCH 0727/1625] Added manual page --- util/LLgen/Makefile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/util/LLgen/Makefile b/util/LLgen/Makefile index 9b798f92..25850c35 100644 --- a/util/LLgen/Makefile +++ b/util/LLgen/Makefile @@ -2,24 +2,28 @@ EMHOME=../.. INSTALLDIR=$(EMHOME)/bin LIBDIR=$(EMHOME)/lib/LLgen +MANDIR=$(EMHOME)/man -all: cmp +all: + cd src; make clean: -cd src; make clean install: cd src; make - rm -f $(INSTALLDIR)/LLgen $(LIBDIR)/rec $(LIBDIR)/incl + rm -f $(INSTALLDIR)/LLgen $(LIBDIR)/rec $(LIBDIR)/incl $(MANDIR)/LLgen.1 cp src/LLgen $(INSTALLDIR)/LLgen cp lib/rec $(LIBDIR)/rec cp lib/incl $(LIBDIR)/incl + cp LLgen.1 $(MANDIR)/LLgen.1 cmp: cd src; make -cmp src/LLgen $(INSTALLDIR)/LLgen -cmp lib/rec $(LIBDIR)/rec -cmp lib/incl $(LIBDIR)/incl + -cmp LLgen.1 $(MANDIR)/LLgen.1 distr: cd src; make distr From ae00be75929dd02bb6ccf7b283907e1dc096fa67 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 5 Feb 1987 14:11:46 +0000 Subject: [PATCH 0728/1625] *** empty log message *** --- util/led/Makefile | 2 ++ util/led/const.h | 1 + util/led/main.c | 10 +++++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/util/led/Makefile b/util/led/Makefile index 916fa5ef..d1f2f16d 100644 --- a/util/led/Makefile +++ b/util/led/Makefile @@ -29,6 +29,8 @@ led: $(OFILES) install:led cp led $(LIBDIR)/em_led + cp led.6 $(EM)/man/led.6 + cp ack.out.5 $(EM)/man/ack.out.5 cmp: led cmp led $(LIBDIR)/em_led diff --git a/util/led/const.h b/util/led/const.h index 7252e9c8..445122f7 100644 --- a/util/led/const.h +++ b/util/led/const.h @@ -10,6 +10,7 @@ typedef int bool; #define RFLAG 0x01 /* -r flag given. */ #define SFLAG 0x02 /* -s flag given. */ +#define CFLAG 0x04 /* -c flag given. */ #define PLAIN 0 /* Input file is a normal file. */ #define ARCHIVE 1 /* Input file is an archive. */ diff --git a/util/led/main.c b/util/led/main.c index a372d85b..3b7e2376 100644 --- a/util/led/main.c +++ b/util/led/main.c @@ -131,6 +131,13 @@ first_pass(argv) fatal("usage: -b
:"); setbase(sectno, number(++argp)); break; + case 'c': + /* + * Might be used in combination with 'r', to produce + * relocatable output, but handle commons now. + */ + flagword |= CFLAG; + break; #ifndef NDEBUG case 'd': DEB = 1; @@ -413,10 +420,11 @@ complete_sections() outsect[sectindex].os_foff = foff; foff += outsect[sectindex].os_flen; - if (flagword & RFLAG) + if ((flagword & RFLAG) && !(flagword & CFLAG)) continue; outsect[sectindex].os_size += sect_comm[sectindex]; + if (flagword & RFLAG) outsect[sectindex].os_lign = tstbit(sectindex, lignmap) ? sect_lign[sectindex] : 1; if (tstbit(sectindex, basemap)) { From c925f197394ff55d918d3c45d157218d00db51fa Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 5 Feb 1987 14:47:04 +0000 Subject: [PATCH 0729/1625] *** empty log message *** --- util/misc/em_decode.6 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/misc/em_decode.6 b/util/misc/em_decode.6 index d1901baa..359071a3 100644 --- a/util/misc/em_decode.6 +++ b/util/misc/em_decode.6 @@ -1,5 +1,5 @@ .\" $Header$ -.TH EM_DECODE VI +.TH EM_DECODE 6ACK .ad .SH NAME em_decode,em_encode \- compact to readable EM and v.v. @@ -37,4 +37,4 @@ ack(I) .SH DIAGNOSTICS Error messages are intended to be self-explanatory. .SH AUTHOR -Johan Stevenson, Vrije Universiteit. +Ceriel Jacobs, Vrije Universiteit From 199c6a9041e8de1183acef820d4a3b2f11dc0b87 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 5 Feb 1987 14:47:22 +0000 Subject: [PATCH 0730/1625] Adapted to the use of "convert.c" --- util/misc/Makefile | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/util/misc/Makefile b/util/misc/Makefile index 32cd9ad0..063d44a2 100644 --- a/util/misc/Makefile +++ b/util/misc/Makefile @@ -3,36 +3,50 @@ d=../.. h=$d/h l=$d/lib +ml=$d/modules/lib +mh=$d/modules/h DEC_PATH=decode ENC_PATH=encode DATA_PATH=$l/em_data.a +DECLIBS=$(ml)/libread_emk.a $(ml)/libeme.a $(ml)/libprint.a $(ml)/libstring.a \ + $(ml)/libsystem.a +ENCLIBS=$(ml)/libread_emeV.a $(ml)/libemk.a $(ml)/libprint.a $(ml)/libstring.a \ + $(ml)/libsystem.a +HFILES=$h/em_mnem.h $h/em_spec.h $h/em_pseu.h $h/em_flag.h $h/em_ptyp.h \ + $h/em_mes.h $(mh)/em.h $(mh)/em_comp.h -CFLAGS=-O -I$h +CFLAGS=-O -I$(mh) -I$h all: $(DEC_PATH) $(ENC_PATH) $(DEC_PATH): decode.o $(DATA_PATH) - cc -n -o $(DEC_PATH) decode.o $(DATA_PATH) + cc -n -o $(DEC_PATH) decode.o $(DECLIBS) $(DATA_PATH) $(ENC_PATH): encode.o $(DATA_PATH) - cc -n -o $(ENC_PATH) encode.o $(DATA_PATH) + cc -n -o $(ENC_PATH) encode.o $(ENCLIBS) $(DATA_PATH) -encode.o: $h/em_spec.h $h/em_pseu.h $h/em_flag.h $h/em_ptyp.h $h/em_mes.h +convert.o: $(HFILES) -decode.o: $h/em_spec.h $h/em_pseu.h $h/em_flag.h $h/em_ptyp.h $h/em_mes.h +encode.o: convert.o + cp convert.o encode.o + +decode.o: convert.o + cp convert.o decode.o clean: rm -f $(DEC_PATH) $(ENC_PATH) *.o *.old + install : all + rm -f $l/em_$(DEC_PATH) $l/em_$(ENC_PATH) cp $(DEC_PATH) $l/em_$(DEC_PATH) cp $(ENC_PATH) $l/em_$(ENC_PATH) cmp : all - cmp $(DEC_PATH) $l/$(DEC_PATH) - cmp $(ENC_PATH) $l/$(ENC_PATH) + cmp $(DEC_PATH) $l/em_$(DEC_PATH) + cmp $(ENC_PATH) $l/em_$(ENC_PATH) opr: make pr ^ opr pr: - @pr -n Makefile decode.c encode.c + @pr -n Makefile convert.c From edc821065d831213a23769e4f760d8391597d157 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 5 Feb 1987 14:47:47 +0000 Subject: [PATCH 0731/1625] Initial revision --- util/misc/convert.c | 87 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 util/misc/convert.c diff --git a/util/misc/convert.c b/util/misc/convert.c new file mode 100644 index 00000000..44df72d3 --- /dev/null +++ b/util/misc/convert.c @@ -0,0 +1,87 @@ +#ifndef NORCSID +static char rcsid[] = "$Header$"; +#endif + +/* This program converts either human-readable or compact EM + assembly code to calls of the procedure-interface. + It must be linked with two libraries: + - a library to read EM code, according to read_em(3) + - a library implementing the em_code(3) interface. + Thus, this program could serve as an EM_encoder, an + EM_decoder, or some code generator, depending on how it is + linked. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +char *filename; /* Name of input file */ +int errors; /* Number of errors */ + +main(argc,argv) + char **argv; +{ + struct e_instr *EM_getinstr(); + register struct e_instr *p; + register struct e_args *ap; + + if (argc >= 2) { + filename = argv[1]; + } + else filename = 0; + if (!EM_open(filename)) { + fatal(EM_error); + } + p = EM_getinstr(); + C_init((arith) EM_wordsize, (arith) EM_pointersize); + if (argc >= 3) { + if (!C_open(argv[2])) { + fatal("C_open failed"); + } + } + else if (!C_open( (char *) 0)) fatal("C_open failed"); + C_magic(); + while (p) { + if (p->em_type == EM_FATAL) { + fatal("EM_getinstr: %s", EM_error); + } + if (p->em_type == EM_ERROR) { + error("EM_getinstr: %s", EM_error); + continue; + } + if (!EM_mkcalls(p)) { + error("EM_mkcalls: %s", EM_error); + } + p = EM_getinstr(); + } + C_close(); + EM_close(); + return errors ? 1 : 0; +} + +/* VARARGS */ +error(s,a1,a2,a3,a4) + char *s; +{ + fprintf(stderr, + "%s, line %d: ", + filename ? filename : "standard input", + EM_lineno); + fprintf(stderr,s,a1,a2,a3,a4); + putc('\n', stderr); + errors++; +} + +/* VARARGS */ +fatal(s,a1,a2,a3,a4) + char *s; +{ + error(s,a1,a2,a3,a4); + exit(1); +} From 663e5e493bea6681fd5bcfd70b0bdc92044ee23c Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 5 Feb 1987 14:58:24 +0000 Subject: [PATCH 0732/1625] Added line_prefix.h --- util/cpp/Parameters | 4 ++++ util/cpp/preprocess.c | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/util/cpp/Parameters b/util/cpp/Parameters index 74694b52..f949a562 100644 --- a/util/cpp/Parameters +++ b/util/cpp/Parameters @@ -69,3 +69,7 @@ #define DOBITS 1 /* use trick to reduce symboltable accesses */ +!File: line_prefix.h +#define LINE_PREFIX "#" /* prefix for generated line directives, + either "#" or "#line" + */ diff --git a/util/cpp/preprocess.c b/util/cpp/preprocess.c index fd5fa21e..884684e8 100644 --- a/util/cpp/preprocess.c +++ b/util/cpp/preprocess.c @@ -9,6 +9,7 @@ #include "idf.h" #include "idfsize.h" #include "bits.h" +#include "line_prefix.h" char _obuf[OBUFSIZE]; @@ -51,8 +52,10 @@ preprocess(fn) char Xbuf[256]; register char *p = Xbuf; - sprint(p, "# %d \"%s\"\n", LineNumber, - FileName); + sprint(p, "%s %d \"%s\"\n", + LINE_PREFIX, + LineNumber, + FileName); while (*p) { echo(*p++); } From d859083131451164d79bc1fbffb676953cf3cb5f Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 5 Feb 1987 16:22:42 +0000 Subject: [PATCH 0733/1625] bug fix --- lang/cem/libcc/gen/getenv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/cem/libcc/gen/getenv.c b/lang/cem/libcc/gen/getenv.c index 687c102c..2793023a 100644 --- a/lang/cem/libcc/gen/getenv.c +++ b/lang/cem/libcc/gen/getenv.c @@ -8,7 +8,7 @@ register char *name; q = name; while (*q && *q++ == *p++) /* nothing */ ; if (*q || *p != '=') continue; - return(p); + return(p+1); } return(0); } From aef695245f10d4c3be460969396e656865cfd793 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 5 Feb 1987 16:39:39 +0000 Subject: [PATCH 0734/1625] bug fix --- modules/src/read_em/mkcalls.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/src/read_em/mkcalls.c b/modules/src/read_em/mkcalls.c index bcced4df..fb329efb 100644 --- a/modules/src/read_em/mkcalls.c +++ b/modules/src/read_em/mkcalls.c @@ -111,7 +111,7 @@ EM_dopseudo(opcode, args) register struct e_args *args2, *args3; arg = c_getarg(args, cst_ptyp); - args2 = c_getarg(arg, arg_ptyp); + args2 = c_getarg(arg, par_ptyp); args3 = c_getarg(args2, cst_ptyp); args3 = c_getarg(args3, 0); switch(arg->em_argtype) { @@ -170,7 +170,7 @@ EM_dopseudo(opcode, args) register struct e_args *args2, *args3; arg = c_getarg(args, cst_ptyp); - args2 = c_getarg(arg, arg_ptyp); + args2 = c_getarg(arg, par_ptyp); args3 = c_getarg(args2, cst_ptyp); args3 = c_getarg(args3, 0); switch(arg->em_argtype) { From d652231c6b94643a0a913f669ce86a4f95e87c9f Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 5 Feb 1987 17:00:14 +0000 Subject: [PATCH 0735/1625] Added another structure for improved recursion detection --- util/cpp/macro.h | 18 ++++++++++++++++++ util/cpp/replace.c | 36 +++++++++++++++++++++++++----------- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/util/cpp/macro.h b/util/cpp/macro.h index b04953a7..ffa70b37 100644 --- a/util/cpp/macro.h +++ b/util/cpp/macro.h @@ -36,6 +36,24 @@ extern char *std_alloc(); #endif #define free_macro(p) st_free(p, &h_macro, sizeof(struct macro)) +struct mlist { + struct mlist *next; + struct macro *m_mac; + char *m_repl; +}; + +/* allocation definitions of struct mlist */ +extern char *st_alloc(); +extern struct mlist *h_mlist; +#ifdef DEBUG +extern int cnt_mlist; +extern char *std_alloc(); +#define new_mlist() ((struct mlist *) std_alloc((char **)&h_mlist, sizeof(struct mlist), 20, &cnt_mlist)) +#else +#define new_mlist() ((struct mlist *) st_alloc((char **)&h_mlist, sizeof(struct mlist), 20)) +#endif +#define free_mlist(p) st_free(p, &h_mlist, sizeof(struct mlist)) + /* `token' numbers of keywords of command-line processor */ diff --git a/util/cpp/replace.c b/util/cpp/replace.c index 846cadf5..7bc959ce 100644 --- a/util/cpp/replace.c +++ b/util/cpp/replace.c @@ -17,7 +17,7 @@ char *strcpy(), *strcat(); char *long2str(); -PRIVATE struct macro *ReplaceList; /* list of currently active macros */ +PRIVATE struct mlist *ReplaceList; /* list of currently active macros */ EXPORT int replace(idef) @@ -36,6 +36,7 @@ replace(idef) register char c; char **actpars, **getactuals(); char *reptext, *macro2buffer(); + register struct mlist *repl; int size; if (mac->mc_flag & NOREPLACE) { @@ -70,27 +71,36 @@ replace(idef) if (mac->mc_flag & FUNC) { struct idf *param = findidf(*actpars); + repl = new_mlist(); if (param && param->id_macro) reptext = "1"; else reptext = "0"; InsertText(reptext, 1); - mac->next = ReplaceList; - ReplaceList = mac; + + repl->next = ReplaceList; + ReplaceList = repl; + repl->m_mac = mac; return 1; } } + + repl = new_mlist(); + repl->m_mac = mac; if (mac->mc_flag & FUNC) /* this macro leads to special action */ macro_func(idef); if (mac->mc_nps <= 0) { - mac->mc_flag |= NOREPLACE; reptext = mac->mc_text; size = mac->mc_length; + mac->mc_flag |= NOREPLACE; /* a file called __FILE__ ??? */ + } + else { + reptext = macro2buffer(idef, actpars, &size); /* create input buffer */ + repl->m_repl = reptext; } - else reptext = macro2buffer(idef, actpars, &size); /* create input buffer */ InsertText(reptext, size); - mac->next = ReplaceList; - ReplaceList = mac; + repl->next = ReplaceList; + ReplaceList = repl; return 1; } @@ -182,14 +192,18 @@ DoUnstack() EXPORT EnableMacros() { - register struct macro *p = ReplaceList; + register struct mlist *p = ReplaceList; assert(Unstacked > 0); while (Unstacked > 0) { + struct mlist *nxt = p->next; + assert(p != 0); - p->mc_flag &= ~NOREPLACE; - p->mc_count = 0; - p = p->next; + p->m_mac->mc_flag &= ~NOREPLACE; + if (p->m_mac->mc_count) p->m_mac->mc_count--; + if (p->m_repl) free(p->m_repl); + free_mlist(p); + p = nxt; Unstacked--; } ReplaceList = p; From ca983350255f88d0f55220bf34a1d3e596060304 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 5 Feb 1987 17:01:12 +0000 Subject: [PATCH 0736/1625] new dependencies --- util/cpp/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/cpp/Makefile b/util/cpp/Makefile index 18ffbf25..adb5db22 100644 --- a/util/cpp/Makefile +++ b/util/cpp/Makefile @@ -148,7 +148,7 @@ init.o: charoffset.h class.h idf.h interface.h macro.h input.o: file_info.h input.h inputtype.h main.o: file_info.h idfsize.h options.o: charoffset.h class.h idf.h idfsize.h macro.h maxincl.h -preprocess.o: LLlex.h bits.h charoffset.h class.h dobits.h file_info.h idf.h idfsize.h input.h inputtype.h maxincl.h obufsize.h +preprocess.o: LLlex.h bits.h charoffset.h class.h dobits.h file_info.h idf.h idfsize.h input.h inputtype.h line_prefix.h maxincl.h obufsize.h replace.o: LLlex.h charoffset.h class.h debug.h file_info.h idf.h input.h inputtype.h interface.h macro.h pathlength.h textsize.h scan.o: charoffset.h class.h idf.h input.h inputtype.h interface.h lapbuf.h macro.h nparams.h skip.o: LLlex.h charoffset.h class.h file_info.h input.h inputtype.h From d71e9a7356b3bece0d76cc5016945a4a51e44b94 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 5 Feb 1987 17:02:16 +0000 Subject: [PATCH 0737/1625] *** empty log message *** --- util/cpp/next.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/util/cpp/next.c b/util/cpp/next.c index 64ff5ff2..3d37a39b 100644 --- a/util/cpp/next.c +++ b/util/cpp/next.c @@ -1,5 +1,7 @@ #include "debug.h" struct macro *h_macro = 0; +struct mlist *h_mlist = 0; #ifdef DEBUG int cnt_macro = 0; +int cnt_mlist = 0; #endif From b0bf0e7e359e7fc8df69570f6e316a9c1b1304b0 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 5 Feb 1987 18:33:44 +0000 Subject: [PATCH 0738/1625] bug fix --- modules/src/read_em/read_em.c | 5 ++++- modules/src/read_em/readk.c | 19 +++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/modules/src/read_em/read_em.c b/modules/src/read_em/read_em.c index a72f5866..e0ddce80 100644 --- a/modules/src/read_em/read_em.c +++ b/modules/src/read_em/read_em.c @@ -54,7 +54,10 @@ _fill() #define STRSIZ 256 /* Maximum length of strings */ static struct e_instr emhead; /* Where we put the head */ -static struct e_args emargs[NARGS]; /* Where we put the arguments */ +static struct e_args emargs[NARGS+2]; /* Where we put the arguments. + We need some more because some + arguments are constructed + */ static struct e_args *i_emargs; #define argentry() (i_emargs++) static struct string { diff --git a/modules/src/read_em/readk.c b/modules/src/read_em/readk.c index 1ba9df64..49aa26d9 100644 --- a/modules/src/read_em/readk.c +++ b/modules/src/read_em/readk.c @@ -132,16 +132,17 @@ getarg(typset) case sp_doff: /* A data label + offset */ { - register struct e_args *ap1, *ap2; + register struct e_args *ap1; ap1 = getarg(lab_ptyp); - ap2 = getarg(cst_ptyp); *ap = *ap1; - if (ap->em_argtype == sof_ptyp) { /* non-numeric label */ - ap->em_soff = ap2->em_cst; + i_emargs--; + ap1 = getarg(cst_ptyp); + if (argtyp == sof_ptyp) { /* non-numeric label */ + ap->em_soff = ap1->em_cst; } - else ap->em_noff = ap2->em_cst; - i_emargs -= 2; + else ap->em_noff = ap1->em_cst; + i_emargs--; break; } @@ -149,10 +150,10 @@ getarg(typset) case sp_ucon: /* An unsigned constant */ case sp_fcon: /* A floating constant */ { - register struct e_args *ap1; register struct string *p; - ap1 = getarg(cst_ptyp); + ap->em_size = getarg(cst_ptyp)->em_cst; + i_emargs--; p = getstring(0); #ifdef CHECKING if (state & INSTRING) { @@ -161,8 +162,6 @@ getarg(typset) #endif CHECKING ap->em_argtype = ptyp(i); ap->em_str = p->str; - ap->em_size = ap1->em_cst; - i_emargs--; break; } From cd44ff20741b78e8d00ffd8c50b64120becd6497 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 5 Feb 1987 18:37:12 +0000 Subject: [PATCH 0739/1625] another bug fix --- modules/src/read_em/readk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/src/read_em/readk.c b/modules/src/read_em/readk.c index 49aa26d9..1e147882 100644 --- a/modules/src/read_em/readk.c +++ b/modules/src/read_em/readk.c @@ -138,7 +138,7 @@ getarg(typset) *ap = *ap1; i_emargs--; ap1 = getarg(cst_ptyp); - if (argtyp == sof_ptyp) { /* non-numeric label */ + if (ap->em_argtype == sof_ptyp) { /* non-numeric label */ ap->em_soff = ap1->em_cst; } else ap->em_noff = ap1->em_cst; From 3df309f1107d3885e22067d83c719c6cb8e214ae Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 5 Feb 1987 19:14:55 +0000 Subject: [PATCH 0740/1625] just for fun: do not call empty rules. --- util/LLgen/src/gencode.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/util/LLgen/src/gencode.c b/util/LLgen/src/gencode.c index 1d17f08c..f78ff4d1 100644 --- a/util/LLgen/src/gencode.c +++ b/util/LLgen/src/gencode.c @@ -458,16 +458,21 @@ rulecode(p,safety,mustscan,mustpop) register p_gram p; { safety = NOSCANDONE; break; } case NONTERM : { - register p_nont n; + register p_nont n = &nonterms[g_getnont(p)]; - n = &nonterms[g_getnont(p)]; if (safety == NOSCANDONE && - getntsafe(n) < NOSCANDONE) fputs(c_read, f); + getntsafe(n) < NOSCANDONE) { + safety = getntsafe(n); + fputs(c_read, f); + } if (toplevel == 0 && (g_gettype(n->n_rule) != ALTERNATION || getntsafe(n) <= SAFESCANDONE)) { genpop(findindex(n->n_contains)); } + if (g_gettype(n->n_rule) == EORULE && + safety == getntout(n) && + ! g_getnpar(p)) break; fprintf(f,"L%d_%s(\n",g_getnont(p), n->n_name); if (g_getnpar(p)) { controlline(); From f52816824c1ea7ad5576f6580e5ddf11fa7bb836 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 5 Feb 1987 19:19:01 +0000 Subject: [PATCH 0741/1625] Adapted some constants --- util/ncgg/param.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/util/ncgg/param.h b/util/ncgg/param.h index 1d82c1b5..21ed4f6f 100644 --- a/util/ncgg/param.h +++ b/util/ncgg/param.h @@ -6,25 +6,25 @@ #define MAXREGS 40 #define MAXPROPS 30 -#define MAXTOKENS 60 -#define MAXATT 3 -#define MAXSETS 100 -#define MAXINSTR 100 +#define MAXTOKENS 100 +#define MAXATT 6 +#define MAXSETS 150 +#define MAXINSTR 200 #define MAXSTRINGS 250 -#define MAXNODES 300 +#define MAXNODES 500 #define EMPATMAX 20 -#define MAXPATTERNS 20 +#define MAXPATTERNS 40 #define MAXALLREG 5 #define MAXINSTANCES 300 -#define MAXMOVES 20 +#define MAXMOVES 40 #define MAXTESTS 10 #define MAXSTACKS 30 -#define MAXCOERCS 25 +#define MAXCOERCS 50 #define MAXSPLCOERC 20 -#define MAXSPLIT 2 +#define MAXSPLIT 3 #define MAXPATBYTES 7000 -#define MAXREGVAR 8 -#define MAXSOURCELINES 4000 +#define MAXREGVAR 10 +#define MAXSOURCELINES 6000 /* end of tunable constants */ From 1c5bb57ecfaae1081739476df68e3c7fdecb5da4 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 5 Feb 1987 19:20:54 +0000 Subject: [PATCH 0742/1625] Added code to kill regvar(...) --- util/ncgg/cgg.y | 17 ++++++++++++++--- util/ncgg/output.c | 18 ++++++++---------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/util/ncgg/cgg.y b/util/ncgg/cgg.y index 8c1974e9..f61d5871 100644 --- a/util/ncgg/cgg.y +++ b/util/ncgg/cgg.y @@ -95,7 +95,7 @@ iocc_t iops[20]; %type register propno att_list_el_type tokenset_no %type adornlist optstar optuses optregvar regvartype optregvartype %type emarg tokarg subreg allreg optsecondstring -%type expr +%type expr regvarexpr %type tokeninstance %type optexpr optexact optstack %type tokenset @@ -770,7 +770,14 @@ kill_list_el $$->vi_int[1]=$3; cursetno = -1; } - ; + | regvarexpr + { NEW($$,struct varinfo); + $$->vi_next = 0; + $$->vi_int[0] = -($1.ex_index + 1); + $$->vi_int[1] = 0; + } + ; + allocates : /* empty */ { $$ = 0; nallreg=0;} @@ -1055,7 +1062,11 @@ expr { $$ = make_expr(TYPINT,EX_INREG,i_expr($3),0); } | regvartype { $$ = make_expr(TYPINT,EX_CON, $1+1, 0); } - | REGVAR '(' expr optregvartype ')' + | regvarexpr + ; + +regvarexpr + : REGVAR '(' expr optregvartype ')' { $$ = regvar_expr($3,$4); } ; diff --git a/util/ncgg/output.c b/util/ncgg/output.c index 0175fb12..260b834b 100644 --- a/util/ncgg/output.c +++ b/util/ncgg/output.c @@ -121,6 +121,9 @@ errorexit() { #define codeint(x) fprintf(code," %d",x) #define codenl() fprintf(code,"\n") #else +#define codenl() +#define code8nl(x) code8(x) + code8(x) { codeindex++; @@ -130,11 +133,6 @@ code8(x) { putc(x,code); } -code8nl(x) { - - code8(x); -} - code53(x,y) { code8(x+(y<<5)); @@ -151,8 +149,6 @@ codeint(x) { } } -codenl() { -} #endif int prevind=0; int npatbytes= -1; @@ -686,12 +682,14 @@ varinfo *kills,*allocates,*generates,*yields,*leaving; code53(DO_REMOVE,1); codeint(vp->vi_int[0]); codeint(vp->vi_int[1]); - codenl(); - } else { + } else if (vp->vi_int[1] >= 0) { code53(DO_REMOVE,0); codeint(vp->vi_int[0]); - codenl(); + } else { + code8(DO_RREMOVE); + codeint(vp->vi_int[0]); } + codenl(); } nremoves=0; for(vp=generates;vp!=0;vp=vp->vi_next) { From 4616cd6ef098503c6fcc66c8036a791d5dc14b82 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 5 Feb 1987 20:39:11 +0000 Subject: [PATCH 0743/1625] Bug fix --- lang/cem/libcc/gen/ecvt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/cem/libcc/gen/ecvt.c b/lang/cem/libcc/gen/ecvt.c index f3548532..0217eb10 100644 --- a/lang/cem/libcc/gen/ecvt.c +++ b/lang/cem/libcc/gen/ecvt.c @@ -78,7 +78,7 @@ cvt(value, ndigit, decpt, sign, ecvtflag) fractpart = modf(fractpart * 10, &value); *pb++ = (int)value + '0'; } - pe = pb; + pb = pe; *pb += 5; /* round of at the end */ while (*pb > '9') { *pb = '0'; From 64506faad2ebf93b62522d19f0a52f5e7ebcf91a Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 5 Feb 1987 20:47:30 +0000 Subject: [PATCH 0744/1625] array bound check added --- lang/cem/libcc/gen/ecvt.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lang/cem/libcc/gen/ecvt.c b/lang/cem/libcc/gen/ecvt.c index 0217eb10..4be5e665 100644 --- a/lang/cem/libcc/gen/ecvt.c +++ b/lang/cem/libcc/gen/ecvt.c @@ -28,12 +28,12 @@ cvt(value, ndigit, decpt, sign, ecvtflag) static char buf[NDIGITS]; char buf1[NDIGITS]; register char *pe = buf1; - register char *pb = buf; + register char *pb; int pointpos = 0; if (ndigit < 0) ndigit = 0; - if (ndigit >= NDIGITS - 1) ndigit = NDIGITS - 2; + if (ndigit >= NDIGITS - 10) ndigit = NDIGITS - 11; *sign = 0; if (value < 0) { @@ -50,6 +50,11 @@ cvt(value, ndigit, decpt, sign, ecvtflag) /* compensate for rounding errors, because the conversion to "int" truncates */ + if (pe >= &buf1[NDIGITS]) { + pb = &buf1[NDIGITS-10]; + while (pb > buf1) *--pb = *--pe; + pe = &buf[NDIGITS-10]; + } *pe++ = (int)((value+.05) * 10) + '0'; pointpos++; } while (intpart != 0); @@ -61,6 +66,7 @@ cvt(value, ndigit, decpt, sign, ecvtflag) fractpart = value; pointpos--; } + pb = &buf[0]; } pe = &buf[ndigit]; if (! ecvtflag) { From 1f26e86834cbb99150cc98e9596aee806e7f80ac Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 5 Feb 1987 20:54:27 +0000 Subject: [PATCH 0745/1625] buffer names: _sibuf and _sobuf --- lang/cem/libcc/stdio/data.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lang/cem/libcc/stdio/data.c b/lang/cem/libcc/stdio/data.c index 680d37fb..29e13360 100644 --- a/lang/cem/libcc/stdio/data.c +++ b/lang/cem/libcc/stdio/data.c @@ -1,10 +1,10 @@ #include -unsigned char __stdin[BUFSIZ]; -unsigned char __stdout[BUFSIZ]; +unsigned char _sobuf[BUFSIZ]; +unsigned char _sibuf[BUFSIZ]; struct _io_buf _stdin = { - 0, 0, IO_READMODE , __stdin, __stdin + 0, 0, IO_READMODE , _sibuf, _sibuf }; struct _io_buf _stdout = { From 566ff7b6cfc2da762019528cf5ea73aa09a5b8cf Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 5 Feb 1987 20:56:06 +0000 Subject: [PATCH 0746/1625] output buffer is now called _sobuf --- lang/cem/libcc/stdio/flushbuf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lang/cem/libcc/stdio/flushbuf.c b/lang/cem/libcc/stdio/flushbuf.c index 4208646d..6dc91815 100644 --- a/lang/cem/libcc/stdio/flushbuf.c +++ b/lang/cem/libcc/stdio/flushbuf.c @@ -12,9 +12,9 @@ _flushbuf(c, iop) iop->_flags |= IO_UNBUFF; } else { - extern unsigned char __stdout[]; + extern unsigned char _sobuf[]; - iop->_buf = iop->_ptr = __stdout; + iop->_buf = iop->_ptr = _sobuf; iop->_count = BUFSIZ; } } From 273eb0e2d164b41c60f02e456084cc6d7441627f Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 5 Feb 1987 21:04:40 +0000 Subject: [PATCH 0747/1625] *** empty log message *** --- lang/cem/libcc/gen/localtime.c | 9 +++++---- lang/cem/libcc/gen/tzset.c | 24 ++++++++++++++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/lang/cem/libcc/gen/localtime.c b/lang/cem/libcc/gen/localtime.c index b931ee3f..b8e205ff 100644 --- a/lang/cem/libcc/gen/localtime.c +++ b/lang/cem/libcc/gen/localtime.c @@ -25,13 +25,13 @@ localtime(clock) register struct tm *gmt; long cl; int begindst, enddst; - extern int daylight; - extern long timezone; + extern int __daylight; + extern long __timezone; tzset(); - cl = *clock - timezone; + cl = *clock - __timezone; gmt = gmtime(&cl); - if (daylight) { + if (__daylight) { /* daylight saving time. Unfortunately, rules differ for different countries. Implemented here are heuristics that got it right @@ -45,6 +45,7 @@ localtime(clock) (gmt->tm_yday==begindst && gmt->tm_hour>=2)) && (gmt->tm_ydaytm_yday==enddst && gmt->tm_hour<3))) { + /* it all happens between 2 and 3 */ cl += 1*60*60; gmt = gmtime(&cl); gmt->tm_isdst++; diff --git a/lang/cem/libcc/gen/tzset.c b/lang/cem/libcc/gen/tzset.c index 1f7a83b8..4c74df8f 100644 --- a/lang/cem/libcc/gen/tzset.c +++ b/lang/cem/libcc/gen/tzset.c @@ -7,9 +7,15 @@ #endif #endif +#ifdef USG long timezone = -1 * 60; int daylight = 1; char *tzname[] = {"MET", "MDT",}; +#endif + +long __timezone = -1 * 60; +int __daylight = 1; +char *__tzname[] = {"MET", "MDT", }; tzset() { @@ -18,15 +24,15 @@ tzset() struct timezone tzon; gettimeofday(&tval, &tzon); - timezone = tzon.tz_minuteswest * 60L; - daylight = tzon.tz_dsttime; + __timezone = tzon.tz_minuteswest * 60L; + __daylight = tzon.tz_dsttime; #else #ifndef USG struct timeb time; ftime(&time); - timezone = time.timezone*60L; - daylight = time.dstflag; + __timezone = time.timezone*60L; + __daylight = time.dstflag; #endif #endif @@ -48,9 +54,15 @@ tzset() while(*p >= '0' && *p <= '9') n = 10 * n + (*p++ - '0'); n *= sign; - timezone = ((long)(n * 60)) * 60; - daylight = (*p != '\0'); + __timezone = ((long)(n * 60)) * 60; + __daylight = (*p != '\0'); strncpy(tzname[1], p, 3); } } +#ifdef USG + timezone = __timezone; + daylight = __daylight; + tzname[0] = __tzname[0]; + tzname[1] = __tzname[1]; +#endif } From ce3981e051fa680692317d1f23d07869f8a50574 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 5 Feb 1987 21:07:09 +0000 Subject: [PATCH 0748/1625] typo --- lang/cem/libcc/gen/tzset.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lang/cem/libcc/gen/tzset.c b/lang/cem/libcc/gen/tzset.c index 4c74df8f..d379627f 100644 --- a/lang/cem/libcc/gen/tzset.c +++ b/lang/cem/libcc/gen/tzset.c @@ -44,7 +44,7 @@ tzset() register int n = 0; int sign = 1; - strncpy(tzname[0], p, 3); + strncpy(__tzname[0], p, 3); p += 3; if (*(p += 3) == '-') { sign = -1; @@ -56,7 +56,7 @@ tzset() n *= sign; __timezone = ((long)(n * 60)) * 60; __daylight = (*p != '\0'); - strncpy(tzname[1], p, 3); + strncpy(__tzname[1], p, 3); } } #ifdef USG From 70a44a040dbd50982741befda381f53d616e797d Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 5 Feb 1987 21:36:42 +0000 Subject: [PATCH 0749/1625] bug fixes --- lang/cem/libcc/gen/gmtime.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lang/cem/libcc/gen/gmtime.c b/lang/cem/libcc/gen/gmtime.c index c337e094..3ed85968 100644 --- a/lang/cem/libcc/gen/gmtime.c +++ b/lang/cem/libcc/gen/gmtime.c @@ -2,16 +2,16 @@ static int monthsize[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; -#define SECS_DAY 24*60L*60L +#define SECS_DAY (24*60L*60L) #define YEARSIZE(year) ((year) % 4 ? 365 : 366) struct tm * gmtime(clock) long *clock; { - unsigned long cl = *clock; + long cl = *clock; long dayclock, dayno; - struct tm tm_buf; + static struct tm tm_buf; register struct tm *pbuf = &tm_buf; register int *months = monthsize; int year = 1970; @@ -27,7 +27,7 @@ gmtime(clock) dayno -= YEARSIZE(year); year++; } - pbuf->tm_year = year; + pbuf->tm_year = year - 1900; pbuf->tm_yday = dayno; pbuf->tm_isdst = 0; if (YEARSIZE(year) == 366) monthsize[1] = 29; From ed80d2dea911c666b98014ae219e9e46ddd98e71 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 6 Feb 1987 10:03:18 +0000 Subject: [PATCH 0750/1625] bug fix --- util/misc/convert.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/util/misc/convert.c b/util/misc/convert.c index 44df72d3..7e67df01 100644 --- a/util/misc/convert.c +++ b/util/misc/convert.c @@ -53,9 +53,8 @@ main(argc,argv) } if (p->em_type == EM_ERROR) { error("EM_getinstr: %s", EM_error); - continue; } - if (!EM_mkcalls(p)) { + else if (!EM_mkcalls(p)) { error("EM_mkcalls: %s", EM_error); } p = EM_getinstr(); From 6bcbcc62c2889be77705695dd3c18da4762ab5e5 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 6 Feb 1987 10:27:57 +0000 Subject: [PATCH 0751/1625] bug fix --- modules/src/read_em/reade.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/src/read_em/reade.c b/modules/src/read_em/reade.c index 16ba0c0f..7c71bb36 100644 --- a/modules/src/read_em/reade.c +++ b/modules/src/read_em/reade.c @@ -619,7 +619,12 @@ gethead() argnum = 1; for (;;) { EM_lineno++; - if ((c = getbyte()) == EOF) return 0; + c = getbyte(); + if (c == COMMENTSTARTER) { + do c = getbyte(); + while (c != '\n' && c != EOF); + } + if (c == EOF) return 0; if (c == '\n') continue; if (isspace(c)) { c = nospace(); From 3c05aa66c1c538a63bc2daacad0fa07e4145aa5a Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 6 Feb 1987 10:37:09 +0000 Subject: [PATCH 0752/1625] bug fix --- lang/cem/libcc/stdio/flushbuf.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lang/cem/libcc/stdio/flushbuf.c b/lang/cem/libcc/stdio/flushbuf.c index 6dc91815..90bf01ff 100644 --- a/lang/cem/libcc/stdio/flushbuf.c +++ b/lang/cem/libcc/stdio/flushbuf.c @@ -14,8 +14,8 @@ _flushbuf(c, iop) else { extern unsigned char _sobuf[]; - iop->_buf = iop->_ptr = _sobuf; - iop->_count = BUFSIZ; + iop->_buf = _sobuf; + iop->_count = BUFSIZ-1; } } else { @@ -25,11 +25,11 @@ _flushbuf(c, iop) iop->_flags |= IO_UNBUFF; } else { - iop->_ptr = iop->_buf; iop->_flags |= IO_MYBUF; - iop->_count = BUFSIZ; + iop->_count = BUFSIZ-1; } } + iop->_ptr = iop->_buf; } } @@ -44,7 +44,7 @@ _flushbuf(c, iop) return c; } else { - int count = BUFSIZ - iop->_count; + int count = iop->_ptr - iop->_buf; iop->_count = BUFSIZ - 1; iop->_ptr = iop->_buf + 1; From 48f0eb8a06cc17e9d0b9156259cbc25510fa9cc9 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 6 Feb 1987 11:09:26 +0000 Subject: [PATCH 0753/1625] bug fix --- lang/cem/libcc/stdio/fillbuf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/cem/libcc/stdio/fillbuf.c b/lang/cem/libcc/stdio/fillbuf.c index b91b2826..4e9d3e37 100644 --- a/lang/cem/libcc/stdio/fillbuf.c +++ b/lang/cem/libcc/stdio/fillbuf.c @@ -3,7 +3,7 @@ _fillbuf(iop) register FILE *iop; { - unsigned char ch[_NFILES]; + static unsigned char ch[_NFILES]; iop->_count = 0; if (fileno(iop) < 0) return EOF; From 2e571491b969f66ee94bd36557aa13e8bdb9db78 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 6 Feb 1987 13:28:01 +0000 Subject: [PATCH 0754/1625] bug fix --- lang/cem/libcc/gen/ecvt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lang/cem/libcc/gen/ecvt.c b/lang/cem/libcc/gen/ecvt.c index 4be5e665..478d5423 100644 --- a/lang/cem/libcc/gen/ecvt.c +++ b/lang/cem/libcc/gen/ecvt.c @@ -58,6 +58,7 @@ cvt(value, ndigit, decpt, sign, ecvtflag) *pe++ = (int)((value+.05) * 10) + '0'; pointpos++; } while (intpart != 0); + pb = buf; while (pe > buf1) *pb++ = *--pe; } else if (value > 0) { @@ -103,6 +104,6 @@ cvt(value, ndigit, decpt, sign, ecvtflag) } *decpt = pointpos; *pe = '\0'; - return(buf); + return buf; } #endif From b248ec9c8fb8422dbb6a8f3206e11554fadb8f32 Mon Sep 17 00:00:00 2001 From: bruce Date: Fri, 6 Feb 1987 14:13:22 +0000 Subject: [PATCH 0755/1625] Use awk program to generate distinct C_xxx routines in separate files. --- modules/src/em_opt/Makefile | 62 ++++++++------ modules/src/em_opt/mkcalls.c | 150 ++++++++++++---------------------- modules/src/em_opt/outcalls.c | 32 +++----- 3 files changed, 97 insertions(+), 147 deletions(-) diff --git a/modules/src/em_opt/Makefile b/modules/src/em_opt/Makefile index 8a17571e..1c9539ac 100644 --- a/modules/src/em_opt/Makefile +++ b/modules/src/em_opt/Makefile @@ -4,17 +4,38 @@ INSTALL = $(EMHOME)/modules/install COMPARE = $(EMHOME)/modules/compare LIBOPT = libopt.a -CSRC = nopt.c aux.c mkcalls.c pseudo.c outputdfa.c outcalls.c\ +# set HOWMUCH to head -20 to limit number of patterns used +#HOWMUCH = head -20 +HOWMUCH = cat + +LEXLIB = -ll +INCLDIR = -I$(EMHOME)/h -I$(EMHOME)/modules/h -I$(EMHOME)/modules/pkg +PREFLAGS = $(INCLDIR) -DPRIVATE=static +# Enable the next line to produce a version that output's the line number +# from the patterns file each time an optimization is performed. +#PREFLAG = $(PREFLAGS) -DSTATS +PROFFLAG = -O +CFLAGS = $(PREFLAGS) $(PROFFLAG) +LLOPT = +CMD = '$(CC) -c $(CFLAGS)' + +.SUFFIXES: .d .r + +.r.d:; CMD=$(CMD); export CMD; awk -f makefuns.awk $*.r | sh + touch $@ + +CSRC = nopt.c aux.c mkcalls.c outputdfa.c outcalls.c\ findworst.c initlex.c -SRCS = Makefile nopt.h parser.h parser.g syntax.l patterns $(CSRC) +SRCS = Makefile nopt.h parser.h parser.g syntax.l pseudo.r patterns $(CSRC) -NOFILES = nopt.o dfa.o trans.o incalls.o pseudo.o aux.o mkcalls.o +NOFILES = nopt.o dfa.o trans.o aux.o mkcalls.o POFILES = parser.o syntax.o outputdfa.o outcalls.o findworst.o initlex.o Lpars.o GENFILES = Lpars.h Lpars.c parserdummy parser.c syntax.c dfadummy\ - dfa.c dfa.c.save trans.c trans.c.save incalls.c incalls.c.save + dfa.c dfa.c.save trans.c trans.c.save incalls.d incalls.r\ + incalls.r.save pseudo.d all: $(LIBOPT) @@ -31,37 +52,25 @@ opr: make pr | opr clean: + rm -f C_*.o + rm -f C_*.c rm -f $(NOFILES) $(POFILES) $(GENFILES) parser libopt.a -# set HOWMUCH to head -20 to limit number of patterns used -#HOWMUCH = head -20 -HOWMUCH = cat - -LEXLIB = -ll -INCLDIR = -I$(EMHOME)/h -I$(EMHOME)/modules/h -I$(EMHOME)/modules/pkg -PREFLAGS = $(INCLDIR) -DPRIVATE=static -# Enable the next line to produce a version that output's the line number -# from the patterns file each time an optimization is performed. -#PREFLAGS = $(PREFLAGS) -DSTATS -PROFFLAG = -O -CFLAGS = $(PREFLAGS) $(PROFFLAG) -LLOPT = - -$(LIBOPT): dfadummy $(NOFILES) +$(LIBOPT): dfadummy $(NOFILES) pseudo.d incalls.d rm -f $(LIBOPT) - ar rc $(LIBOPT) $(NOFILES) + ar rc $(LIBOPT) C_*.o $(NOFILES) -sh -c 'ranlib $(LIBOPT)' dfadummy: patterns parser -mv dfa.c dfa.c.save -mv trans.c trans.c.save - -mv incalls.c incalls.c.save + -mv incalls.r incalls.r.save -/lib/cpp patterns | $(HOWMUCH) >/tmp/patts parser opcode) { case op_aar: - if(p->argtype!=none_ptyp) O_aar(p->acst); - else O_aar_narg(); break; + O_aar(p->acst); break; case op_adf: - if(p->argtype!=none_ptyp) O_adf(p->acst); - else O_adf_narg(); break; + O_adf(p->acst); break; case op_adi: - if(p->argtype!=none_ptyp) O_adi(p->acst); - else O_adi_narg(); break; + O_adi(p->acst); break; case op_adp: O_adp(p->acst); break; case op_ads: - if(p->argtype!=none_ptyp) O_ads(p->acst); - else O_ads_narg(); break; + O_ads(p->acst); break; case op_adu: - if(p->argtype!=none_ptyp) O_adu(p->acst); - else O_adu_narg(); break; + O_adu(p->acst); break; case op_and: - if(p->argtype!=none_ptyp) O_and(p->acst); - else O_and_narg(); break; + O_and(p->acst); break; case op_asp: O_asp(p->acst); break; case op_ass: - if(p->argtype!=none_ptyp) O_ass(p->acst); - else O_ass_narg(); break; + O_ass(p->acst); break; case op_beq: O_beq((label)p->acst); break; case op_bge: @@ -44,8 +37,7 @@ OO_mkcalls(p) case op_blm: O_blm(p->acst); break; case op_bls: - if(p->argtype!=none_ptyp) O_bls(p->acst); - else O_bls_narg(); break; + O_bls(p->acst); break; case op_blt: O_blt((label)p->acst); break; case op_bne: @@ -69,28 +61,21 @@ OO_mkcalls(p) case op_ciu: O_ciu(); break; case op_cmf: - if(p->argtype!=none_ptyp) O_cmf(p->acst); - else O_cmf_narg(); break; + O_cmf(p->acst); break; case op_cmi: - if(p->argtype!=none_ptyp) O_cmi(p->acst); - else O_cmi_narg(); break; + O_cmi(p->acst); break; case op_cmp: O_cmp(); break; case op_cms: - if(p->argtype!=none_ptyp) O_cms(p->acst); - else O_cms_narg(); break; + O_cms(p->acst); break; case op_cmu: - if(p->argtype!=none_ptyp) O_cmu(p->acst); - else O_cmu_narg(); break; + O_cmu(p->acst); break; case op_com: - if(p->argtype!=none_ptyp) O_com(p->acst); - else O_com_narg(); break; + O_com(p->acst); break; case op_csa: - if(p->argtype!=none_ptyp) O_csa(p->acst); - else O_csa_narg(); break; + O_csa(p->acst); break; case op_csb: - if(p->argtype!=none_ptyp) O_csb(p->acst); - else O_csb_narg(); break; + O_csb(p->acst); break; case op_cuf: O_cuf(); break; case op_cui: @@ -109,26 +94,19 @@ OO_mkcalls(p) case op_dup: O_dup(p->acst); break; case op_dus: - if(p->argtype!=none_ptyp) O_dus(p->acst); - else O_dus_narg(); break; + O_dus(p->acst); break; case op_dvf: - if(p->argtype!=none_ptyp) O_dvf(p->acst); - else O_dvf_narg(); break; + O_dvf(p->acst); break; case op_dvi: - if(p->argtype!=none_ptyp) O_dvi(p->acst); - else O_dvi_narg(); break; + O_dvi(p->acst); break; case op_dvu: - if(p->argtype!=none_ptyp) O_dvu(p->acst); - else O_dvu_narg(); break; + O_dvu(p->acst); break; case op_exg: - if(p->argtype!=none_ptyp) O_exg(p->acst); - else O_exg_narg(); break; + O_exg(p->acst); break; case op_fef: - if(p->argtype!=none_ptyp) O_fef(p->acst); - else O_fef_narg(); break; + O_fef(p->acst); break; case op_fif: - if(p->argtype!=none_ptyp) O_fif(p->acst); - else O_fif_narg(); break; + O_fif(p->acst); break; case op_fil: if(p->argtype==nof_ptyp) O_fil_dlb(p->adlb, p->anoff); else O_fil_dnam(p->adnam, p->asoff); break; @@ -143,11 +121,9 @@ OO_mkcalls(p) case op_inl: O_inl(p->acst); break; case op_inn: - if(p->argtype!=none_ptyp) O_inn(p->acst); - else O_inn_narg(); break; + O_inn(p->acst); break; case op_ior: - if(p->argtype!=none_ptyp) O_ior(p->acst); - else O_ior_narg(); break; + O_ior(p->acst); break; case op_lab: O_df_ilb(p->alab); break; case op_lae: @@ -156,8 +132,7 @@ OO_mkcalls(p) case op_lal: O_lal(p->acst); break; case op_lar: - if(p->argtype!=none_ptyp) O_lar(p->acst); - else O_lar_narg(); break; + O_lar(p->acst); break; case op_ldc: O_ldc(p->acst); break; case op_lde: @@ -191,8 +166,7 @@ OO_mkcalls(p) case op_lor: O_lor(p->acst); break; case op_los: - if(p->argtype!=none_ptyp) O_los(p->acst); - else O_los_narg(); break; + O_los(p->acst); break; case op_lpb: O_lpb(); break; case op_lpi: @@ -202,58 +176,43 @@ OO_mkcalls(p) case op_lxl: O_lxl(p->acst); break; case op_mlf: - if(p->argtype!=none_ptyp) O_mlf(p->acst); - else O_mlf_narg(); break; + O_mlf(p->acst); break; case op_mli: - if(p->argtype!=none_ptyp) O_mli(p->acst); - else O_mli_narg(); break; + O_mli(p->acst); break; case op_mlu: - if(p->argtype!=none_ptyp) O_mlu(p->acst); - else O_mlu_narg(); break; + O_mlu(p->acst); break; case op_mon: O_mon(); break; case op_ngf: - if(p->argtype!=none_ptyp) O_ngf(p->acst); - else O_ngf_narg(); break; + O_ngf(p->acst); break; case op_ngi: - if(p->argtype!=none_ptyp) O_ngi(p->acst); - else O_ngi_narg(); break; + O_ngi(p->acst); break; case op_nop: O_nop(); break; case op_rck: - if(p->argtype!=none_ptyp) O_rck(p->acst); - else O_rck_narg(); break; + O_rck(p->acst); break; case op_ret: O_ret(p->acst); break; case op_rmi: - if(p->argtype!=none_ptyp) O_rmi(p->acst); - else O_rmi_narg(); break; + O_rmi(p->acst); break; case op_rmu: - if(p->argtype!=none_ptyp) O_rmu(p->acst); - else O_rmu_narg(); break; + O_rmu(p->acst); break; case op_rol: - if(p->argtype!=none_ptyp) O_rol(p->acst); - else O_rol_narg(); break; + O_rol(p->acst); break; case op_ror: - if(p->argtype!=none_ptyp) O_ror(p->acst); - else O_ror_narg(); break; + O_ror(p->acst); break; case op_rtt: O_rtt(); break; case op_sar: - if(p->argtype!=none_ptyp) O_sar(p->acst); - else O_sar_narg(); break; + O_sar(p->acst); break; case op_sbf: - if(p->argtype!=none_ptyp) O_sbf(p->acst); - else O_sbf_narg(); break; + O_sbf(p->acst); break; case op_sbi: - if(p->argtype!=none_ptyp) O_sbi(p->acst); - else O_sbi_narg(); break; + O_sbi(p->acst); break; case op_sbs: - if(p->argtype!=none_ptyp) O_sbs(p->acst); - else O_sbs_narg(); break; + O_sbs(p->acst); break; case op_sbu: - if(p->argtype!=none_ptyp) O_sbu(p->acst); - else O_sbu_narg(); break; + O_sbu(p->acst); break; case op_sde: if(p->argtype==nof_ptyp) O_sde_dlb(p->adlb, p->anoff); else O_sde_dnam(p->adnam, p->asoff); break; @@ -262,8 +221,7 @@ OO_mkcalls(p) case op_sdl: O_sdl(p->acst); break; case op_set: - if(p->argtype!=none_ptyp) O_set(p->acst); - else O_set_narg(); break; + O_set(p->acst); break; case op_sig: O_sig(); break; case op_sil: @@ -271,17 +229,13 @@ OO_mkcalls(p) case op_sim: O_sim(); break; case op_sli: - if(p->argtype!=none_ptyp) O_sli(p->acst); - else O_sli_narg(); break; + O_sli(p->acst); break; case op_slu: - if(p->argtype!=none_ptyp) O_slu(p->acst); - else O_slu_narg(); break; + O_slu(p->acst); break; case op_sri: - if(p->argtype!=none_ptyp) O_sri(p->acst); - else O_sri_narg(); break; + O_sri(p->acst); break; case op_sru: - if(p->argtype!=none_ptyp) O_sru(p->acst); - else O_sru_narg(); break; + O_sru(p->acst); break; case op_ste: if(p->argtype==nof_ptyp) O_ste_dlb(p->adlb, p->anoff); else O_ste_dnam(p->adnam, p->asoff); break; @@ -294,8 +248,7 @@ OO_mkcalls(p) case op_str: O_str(p->acst); break; case op_sts: - if(p->argtype!=none_ptyp) O_sts(p->acst); - else O_sts_narg(); break; + O_sts(p->acst); break; case op_teq: O_teq(); break; case op_tge: @@ -311,13 +264,11 @@ OO_mkcalls(p) case op_trp: O_trp(); break; case op_xor: - if(p->argtype!=none_ptyp) O_xor(p->acst); - else O_xor_narg(); break; + O_xor(p->acst); break; case op_zeq: O_zeq((label)p->acst); break; case op_zer: - if(p->argtype!=none_ptyp) O_zer(p->acst); - else O_zer_narg(); break; + O_zer(p->acst); break; case op_zge: O_zge((label)p->acst); break; case op_zgt: @@ -332,8 +283,7 @@ OO_mkcalls(p) if(p->argtype==nof_ptyp) O_zre_dlb(p->adlb, p->anoff); else O_zre_dnam(p->adnam, p->asoff); break; case op_zrf: - if(p->argtype!=none_ptyp) O_zrf(p->acst); - else O_zrf_narg(); break; + O_zrf(p->acst); break; case op_zrl: O_zrl(p->acst); break; } diff --git a/modules/src/em_opt/outcalls.c b/modules/src/em_opt/outcalls.c index 17c1d86d..30830dde 100644 --- a/modules/src/em_opt/outcalls.c +++ b/modules/src/em_opt/outcalls.c @@ -9,17 +9,16 @@ outputincalls() struct idf *op; int opcode; char *s; - if(!sys_open("incalls.c",OP_WRITE,&ofile)) { - fprint(STDERR,"Fatal Error: cannot open output file incalls.c\n"); + if(!sys_open("incalls.r",OP_WRITE,&ofile)) { + fprint(STDERR,"Fatal Error: cannot open output file incalls.r\n"); sys_stop(S_EXIT); } - fprint(ofile,"#include \"nopt.h\"\n\n"); for(op=ops;op!=(struct idf *)NULL;op=op->id_nextidf) { opcode = op->id_opcode; s = op->id_text; switch(op->id_argfmt) { case NOARG: - fprint(ofile,"\nC_%s() {\n",s); + fprint(ofile,"%s\t|\t|\n",s); if(op->id_used) { fprint(ofile,"\tOO_inop(op_%s);\n",s); fprint(ofile,"\tOO_dfa(op_%s);\n",s); @@ -28,10 +27,9 @@ outputincalls() fprint(ofile,"\tFLUSHDFA();\n"); fprint(ofile,"\tO_%s();\n",s); } - fprint(ofile,"}\n",s); break; case CSTOPT: - fprint(ofile,"\nC_%s_narg() {\n",s); + fprint(ofile,"%s_narg\t|\t|\n",s); if(op->id_used) { fprint(ofile,"\tOO_inop(op_%s);\n",s); fprint(ofile,"\tOO_dfa(op_%s);\n",s); @@ -40,10 +38,9 @@ outputincalls() fprint(ofile,"\tFLUSHDFA();\n"); fprint(ofile,"\tO_%s_narg();\n",s); } - fprint(ofile,"}\n",s); /* fall thru */ case CST: - fprint(ofile,"\nC_%s(n) int n; {\n",s); + fprint(ofile,"%s\t| int:n\t|\n",s); if(op->id_used) { fprint(ofile,"\tOO_incst(op_%s,n);\n",s); fprint(ofile,"\tOO_dfa(op_%s);\n",s); @@ -52,10 +49,9 @@ outputincalls() fprint(ofile,"\tFLUSHDFA();\n"); fprint(ofile,"\tO_%s(n);\n",s); } - fprint(ofile,"}\n",s); break; case DEFILB: - fprint(ofile,"\nC_df_ilb(l) label l; {\n"); + fprint(ofile,"df_ilb\t| label:l\t|\n"); if(op->id_used) { fprint(ofile,"\tOO_indefilb(op_%s,l);\n",s); fprint(ofile,"\tOO_dfa(op_%s);\n",s); @@ -64,10 +60,9 @@ outputincalls() fprint(ofile,"\tFLUSHDFA();\n"); fprint(ofile,"\tO_df_ilb(l);\n",s); } - fprint(ofile,"}\n",s); break; case PNAM: - fprint(ofile,"\nC_%s(s) char *s; {\n",s); + fprint(ofile,"%s\t| char *:s\t|\n",s); if(op->id_used) { fprint(ofile,"\tOO_inpnam(op_%s,s);\n",s); fprint(ofile,"\tOO_dfa(op_%s);\n",s); @@ -76,10 +71,9 @@ outputincalls() fprint(ofile,"\tFLUSHDFA();\n"); fprint(ofile,"\tO_%s(s);\n",s); } - fprint(ofile,"}\n",s); break; case LAB: - fprint(ofile,"\nC_%s(l) label l; {\n",s); + fprint(ofile,"%s\t| label:l\t|\n",s); if(op->id_used) { fprint(ofile,"\tOO_inlab(op_%s,l);\n",s); fprint(ofile,"\tOO_dfa(op_%s);\n",s); @@ -88,10 +82,9 @@ outputincalls() fprint(ofile,"\tFLUSHDFA();\n"); fprint(ofile,"\tO_%s(l);\n",s); } - fprint(ofile,"}\n",s); break; case EXT: - fprint(ofile,"\nC_%s(n) int n; {\n",s); + fprint(ofile,"%s\t| int:n\t|\n",s); if(op->id_used) { fprint(ofile,"\tOO_incst(op_%s,n);\n",s); fprint(ofile,"\tOO_dfa(op_%s);\n",s); @@ -100,8 +93,7 @@ outputincalls() fprint(ofile,"\tFLUSHDFA();\n"); fprint(ofile,"\tO_%s(n);\n",s); } - fprint(ofile,"}\n",s); - fprint(ofile,"\nC_%s_dnam(s,n) char *s; int n; {\n",s); + fprint(ofile,"%s_dnam\t| char *:s int:n\t|\n",s); if(op->id_used) { fprint(ofile,"\tOO_indnam(op_%s,s,n);\n",s); fprint(ofile,"\tOO_dfa(op_%s);\n",s); @@ -110,8 +102,7 @@ outputincalls() fprint(ofile,"\tFLUSHDFA();\n"); fprint(ofile,"\tO_%s_dnam(s,n);\n",s); } - fprint(ofile,"}\n",s); - fprint(ofile,"\nC_%s_dlb(l,n) label l; int n; {\n",s); + fprint(ofile,"%s_dlb\t| label:l int:n\t|\n",s); if(op->id_used) { fprint(ofile,"\tOO_indlb(op_%s,l,n);\n",s); fprint(ofile,"\tOO_dfa(op_%s);\n",s); @@ -120,7 +111,6 @@ outputincalls() fprint(ofile,"\tFLUSHDFA();\n"); fprint(ofile,"\tO_%s_dlb(l,n);\n",s); } - fprint(ofile,"}\n",s); break; } } From 6c606a1b23368c3194265d5b29616d844f9fb610 Mon Sep 17 00:00:00 2001 From: bruce Date: Fri, 6 Feb 1987 14:15:49 +0000 Subject: [PATCH 0756/1625] Initial revision --- modules/src/em_opt/makefuns.awk | 59 +++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 modules/src/em_opt/makefuns.awk diff --git a/modules/src/em_opt/makefuns.awk b/modules/src/em_opt/makefuns.awk new file mode 100644 index 00000000..e140fdaf --- /dev/null +++ b/modules/src/em_opt/makefuns.awk @@ -0,0 +1,59 @@ +BEGIN { + FS = "|"; + seenproc = 0; + CC="${CMD}" + } +/^%/ {} +/^$/ {} +/^[a-z]/ && $3 !~ /.*NOTIMPLEMENTED.*/ { + if(seenproc) { + print "}" + print "--EOF--" + printf "if %s C_%s.c\n",CC,nam + printf "then :\nelse exit 1\nfi\n" + printf "rm -f C_%s.c\n",nam + } + seenproc = 1 + $1 = substr($1,1,index($1,"\t")-1); + nam = $1 + printf "cat > C_%s.c << '--EOF--'\n",$1 + print "#include \"nopt.h\"" + printf "C_%s(",$1 + nparms = split($2,parms,":"); + for(p=1;p Date: Fri, 6 Feb 1987 14:21:04 +0000 Subject: [PATCH 0757/1625] Changed name from .c to .r and now in format required by awk. --- modules/src/em_opt/pseudo.r | 413 +++++------------------------------- 1 file changed, 58 insertions(+), 355 deletions(-) diff --git a/modules/src/em_opt/pseudo.r b/modules/src/em_opt/pseudo.r index 5e4d6099..a758cb4b 100644 --- a/modules/src/em_opt/pseudo.r +++ b/modules/src/em_opt/pseudo.r @@ -1,471 +1,174 @@ -#ifndef NORCSID -static char rcsid[] = "$Header$"; -#endif - -#include "nopt.h" - -C_df_dlb(l) - label l; -{ +df_dlb | label:l | FLUSHDFA(); O_df_dlb(l); -} - -C_df_dnam(s) - char * s; -{ +df_dnam | char *:s | FLUSHDFA(); O_df_dnam(s); -} - -C_pro(s,l) - char * s; - arith l; -{ +pro | char *:s arith:l | FLUSHDFA(); O_pro(s,l); -} - -C_pro_narg(s) - char * s; -{ +pro_narg | char *:s | FLUSHDFA(); O_pro_narg(s); -} - -C_end(l) - arith l; -{ +end | arith:l | FLUSHDFA(); O_end(l); -} - -C_end_narg() -{ +end_narg | | FLUSHDFA(); O_end_narg(); -} - -C_exa_dnam(s) - char * s; -{ +exa_dnam | char *:s | FLUSHDFA(); O_exa_dnam(s); -} - -C_exa_dlb(l) - label l; -{ +exa_dlb | label:l | FLUSHDFA(); O_exa_dlb(l); -} - -C_exp(s) - char * s; -{ +exp | char *:s | FLUSHDFA(); O_exp(s); -} - -C_ina_dnam(s) - char * s; -{ +ina_dnam | char *:s | FLUSHDFA(); O_ina_dnam(s); -} - -C_ina_dlb(l) - label l; -{ +ina_dlb | label:l | FLUSHDFA(); O_ina_dlb(l); -} - -C_inp(s) - char * s; -{ +inp | char *:s | FLUSHDFA(); O_inp(s); -} - -C_bss_cst(n,w,i) - arith n; - arith w; - int i; -{ +bss_cst | arith:n arith:w int:i | FLUSHDFA(); O_bss_cst(n,w,i); -} - -C_bss_icon(n,s,sz,i) - arith n; - char * s; - arith sz; - int i; -{ +bss_icon | arith:n char *:s arith:sz int:i | FLUSHDFA(); O_bss_icon(n,s,sz,i); -} - -C_bss_ucon(n,s,sz,i) - arith n; - char * s; - arith sz; - int i; -{ +bss_ucon | arith:n char *:s arith:sz int:i | FLUSHDFA(); O_bss_ucon(n,s,sz,i); -} - -C_bss_fcon(n,s,sz,i) - arith n; - char * s; - arith sz; - int i; -{ +bss_fcon | arith:n char *:s arith:sz int:i | FLUSHDFA(); O_bss_fcon(n,s,sz,i); -} - -C_bss_dnam(n,s,offs,i) - arith n; - char * s; - arith offs; - int i; -{ +bss_dnam | arith:n char *:s arith:offs int:i | FLUSHDFA(); O_bss_dnam(n,s,offs,i); -} - -C_bss_dlb(n,l,offs,i) - arith n; - label l; - arith offs; - int i; -{ +bss_dlb | arith:n label:l arith:offs int:i | FLUSHDFA(); O_bss_dlb(n,l,offs,i); -} - -C_bss_ilb(n,l,i) - arith n; - label l; - int i; -{ +bss_ilb | arith:n label:l int:i | FLUSHDFA(); O_bss_ilb(n,l,i); -} - -C_bss_pnam(n,s,i) - arith n; - char * s; - int i; -{ +bss_pnam | arith:n char *:s int:i | FLUSHDFA(); O_bss_pnam(n,s,i); -} - -C_hol_cst(n,w,i) - arith n; - arith w; - int i; -{ +hol_cst | arith:n arith:w int:i | FLUSHDFA(); O_hol_cst(n,w,i); -} - -C_hol_icon(n,s,sz,i) - arith n; - char * s; - arith sz; - int i; -{ +hol_icon | arith:n char *:s arith:sz int:i | FLUSHDFA(); O_hol_icon(n,s,sz,i); -} - -C_hol_ucon(n,s,sz,i) - arith n; - char * s; - arith sz; - int i; -{ +hol_ucon | arith:n char *:s arith:sz int:i | FLUSHDFA(); O_hol_ucon(n,s,sz,i); -} - -C_hol_fcon(n,s,sz,i) - arith n; - char * s; - arith sz; - int i; -{ +hol_fcon | arith:n char *:s arith:sz int:i | FLUSHDFA(); O_hol_fcon(n,s,sz,i); -} - -C_hol_dnam(n,s,offs,i) - arith n; - char * s; - arith offs; - int i; -{ +hol_dnam | arith:n char *:s arith:offs int:i | FLUSHDFA(); O_hol_dnam(n,s,offs,i); -} - -C_hol_dlb(n,l,offs,i) - arith n; - label l; - arith offs; - int i; -{ +hol_dlb | arith:n label:l arith:offs int:i | FLUSHDFA(); O_hol_dlb(n,l,offs,i); -} - -C_hol_ilb(n,l,i) - arith n; - label l; - int i; -{ +hol_ilb | arith:n label:l int:i | FLUSHDFA(); O_hol_ilb(n,l,i); -} - -C_hol_pnam(n,s,i) - arith n; - char * s; - int i; -{ +hol_pnam | arith:n char *:s int:i | FLUSHDFA(); O_hol_pnam(n,s,i); -} - -C_con_cst(l) - arith l; -{ +con_cst | arith:l | FLUSHDFA(); O_con_cst(l); -} - -C_con_icon(val,siz) - char * val; - arith siz; -{ +con_icon | char *:val arith:siz | FLUSHDFA(); O_con_icon(val,siz); -} - -C_con_ucon(val,siz) - char * val; - arith siz; -{ +con_ucon | char *:val arith:siz | FLUSHDFA(); O_con_ucon(val,siz); -} - -C_con_fcon(val,siz) - char * val; - arith siz; -{ +con_fcon | char *:val arith:siz | FLUSHDFA(); O_con_fcon(val,siz); -} - -C_con_scon(str,siz) - char * str; - arith siz; -{ +con_scon | char *:str arith:siz | FLUSHDFA(); O_con_scon(str,siz); -} - -C_con_dnam(str,val) - char * str; - arith val; -{ +con_dnam | char *:str arith:val | FLUSHDFA(); O_con_dnam(str,val); -} - -C_con_dlb(l,val) - label l; - arith val; -{ +con_dlb | label:l arith:val | FLUSHDFA(); O_con_dlb(l,val); -} - -C_con_ilb(l) - label l; -{ +con_ilb | label:l | FLUSHDFA(); O_con_ilb(l); -} - -C_con_pnam(str) - char * str; -{ +con_pnam | char *:str | FLUSHDFA(); O_con_pnam(str); -} - -C_rom_cst(l) - arith l; -{ +rom_cst | arith:l | FLUSHDFA(); O_rom_cst(l); -} - -C_rom_icon(val,siz) - char * val; - arith siz; -{ +rom_icon | char *:val arith:siz | FLUSHDFA(); O_rom_icon(val,siz); -} - -C_rom_ucon(val,siz) - char * val; - arith siz; -{ +rom_ucon | char *:val arith:siz | FLUSHDFA(); O_rom_ucon(val,siz); -} - -C_rom_fcon(val,siz) - char * val; - arith siz; -{ +rom_fcon | char *:val arith:siz | FLUSHDFA(); O_rom_fcon(val,siz); -} - -C_rom_scon(str,siz) - char * str; - arith siz; -{ +rom_scon | char *:str arith:siz | FLUSHDFA(); O_rom_scon(str,siz); -} - -C_rom_dnam(str,val) - char * str; - arith val; -{ +rom_dnam | char *:str arith:val | FLUSHDFA(); O_rom_dnam(str,val); -} - -C_rom_dlb(l,val) - label l; - arith val; -{ +rom_dlb | label:l arith:val | FLUSHDFA(); O_rom_dlb(l,val); -} - -C_rom_ilb(l) - label l; -{ +rom_ilb | label:l | FLUSHDFA(); O_rom_ilb(l); -} - -C_rom_pnam(str) - char * str; -{ +rom_pnam | char *:str | FLUSHDFA(); O_rom_pnam(str); -} - -C_cst(l) - arith l; -{ +cst | arith:l | FLUSHDFA(); O_cst(l); -} - -C_icon(val,siz) - char * val; - arith siz; -{ +icon | char *:val arith:siz | FLUSHDFA(); O_icon(val,siz); -} - -C_ucon(val,siz) - char * val; - arith siz; -{ +ucon | char *:val arith:siz | FLUSHDFA(); O_ucon(val,siz); -} - -C_fcon(val,siz) - char * val; - arith siz; -{ +fcon | char *:val arith:siz | FLUSHDFA(); O_fcon(val,siz); -} - -C_scon(str,siz) - char * str; - arith siz; -{ +scon | char *:str arith:siz | FLUSHDFA(); O_scon(str,siz); -} - -C_dnam(str,val) - char * str; - arith val; -{ +dnam | char *:str arith:val | FLUSHDFA(); O_dnam(str,val); -} - -C_dlb(l,val) - label l; - arith val; -{ +dlb | label:l arith:val | FLUSHDFA(); O_dlb(l,val); -} - -C_ilb(l) - label l; -{ +ilb | label:l | FLUSHDFA(); O_ilb(l); -} - -C_pnam(str) - char * str; -{ +pnam | char *:str | FLUSHDFA(); O_pnam(str); -} - -C_mes_begin(ms) - int ms; -{ +mes_begin | int:ms | FLUSHDFA(); O_mes_begin(ms); -} - -C_mes_end() -{ +mes_end | | FLUSHDFA(); O_mes_end(); -} - -C_exc(c1,c2) - arith c1; - arith c2; -{ +exc | arith:c1 arith:c2 | FLUSHDFA(); O_exc(c1,c2); -} From 7135529c9745d4fc143a2c46d0a5b8a8b180d84b Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 6 Feb 1987 14:44:56 +0000 Subject: [PATCH 0758/1625] did not work with bloody vax assemblerr --- lang/cem/libcc/stdio/ungetc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lang/cem/libcc/stdio/ungetc.c b/lang/cem/libcc/stdio/ungetc.c index ee88bf2b..ef191969 100644 --- a/lang/cem/libcc/stdio/ungetc.c +++ b/lang/cem/libcc/stdio/ungetc.c @@ -2,8 +2,10 @@ ungetc(ch, iop) int ch; -FILE *iop; +register FILE *iop; { + unsigned char *p; + if ( ch < 0 || !io_testflag(iop,IO_READMODE)) return EOF; if (iop->_ptr == iop->_buf) { @@ -11,6 +13,7 @@ FILE *iop; iop->_ptr++; } iop->_count++; - *--iop->_ptr = ch; + p = --(iop->_ptr); /* ??? Bloody vax assembler !!! */ + *p = ch; return(ch); } From abb48b7aa8940a0eca25da6b8e6c3610c2309acf Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 6 Feb 1987 14:50:57 +0000 Subject: [PATCH 0759/1625] bug fix --- lang/cem/libcc/gen/ecvt.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lang/cem/libcc/gen/ecvt.c b/lang/cem/libcc/gen/ecvt.c index 478d5423..3d514767 100644 --- a/lang/cem/libcc/gen/ecvt.c +++ b/lang/cem/libcc/gen/ecvt.c @@ -61,13 +61,15 @@ cvt(value, ndigit, decpt, sign, ecvtflag) pb = buf; while (pe > buf1) *pb++ = *--pe; } - else if (value > 0) { - fractpart = value; - while ((value = value*10) < 1) { - fractpart = value; - pointpos--; - } + else { pb = &buf[0]; + if (value > 0) { + fractpart = value; + while ((value = value*10) < 1) { + fractpart = value; + pointpos--; + } + } } pe = &buf[ndigit]; if (! ecvtflag) { From 53aa98ed09bc4c055fc72104fbfdb6a1a8d3a39c Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 6 Feb 1987 23:38:35 +0000 Subject: [PATCH 0760/1625] Bug fix (INPUT, not STDIN !!!) --- util/topgen/LLlex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/topgen/LLlex.c b/util/topgen/LLlex.c index 3b4b0f53..646664c0 100644 --- a/util/topgen/LLlex.c +++ b/util/topgen/LLlex.c @@ -85,7 +85,7 @@ LLlex() { dot.t_tokno = PATTERN_SEPARATOR; return PATTERN_SEPARATOR; } - ungetc(c,stdin); + ungetc(c,input); dot.t_tokno = OTHER; return OTHER; case open_bracket : From 180407bce1532d1791504587957f538c7fbbd1d4 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 6 Feb 1987 23:40:25 +0000 Subject: [PATCH 0761/1625] Another one. --- util/topgen/LLlex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/topgen/LLlex.c b/util/topgen/LLlex.c index 646664c0..3cd613ab 100644 --- a/util/topgen/LLlex.c +++ b/util/topgen/LLlex.c @@ -54,7 +54,7 @@ LLlex() { else c = getc(input); } else { - ungetc(c, stdin); + ungetc(c, input); c = '/'; break; } From f9a9655012351f264c03e3bf23e8613fa12fe989 Mon Sep 17 00:00:00 2001 From: ceriel Date: Sat, 7 Feb 1987 00:04:05 +0000 Subject: [PATCH 0762/1625] Added some "registers" --- mach/proto/top/queue.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mach/proto/top/queue.c b/mach/proto/top/queue.c index 3cf1e59c..c704479a 100644 --- a/mach/proto/top/queue.c +++ b/mach/proto/top/queue.c @@ -2,7 +2,7 @@ #include "queue.h" empty_queue(q) - queue q; + register queue q; { q->head = q->tail = (instr_p) 0; q->qlen = 0; @@ -15,7 +15,7 @@ int empty(q) } remove_head(q) - queue q; + register queue q; { if ( (q->head = q->head->fw) == (instr_p) 0) { q->tail = (instr_p) 0; @@ -41,8 +41,8 @@ add(q,instr) } insert(q,instr) - queue q; - instr_p instr; + register queue q; + register instr_p instr; { if (q->qlen++ == 0) { q->head = q->tail = instr; @@ -56,7 +56,7 @@ insert(q,instr) } join_queues(q1,q2) - queue q1,q2; + register queue q1,q2; { if (q1->qlen > 0) { q2->qlen += q1->qlen; From c22605844ad12f270d53b42507551e6fd48a3825 Mon Sep 17 00:00:00 2001 From: ceriel Date: Sat, 7 Feb 1987 00:13:56 +0000 Subject: [PATCH 0763/1625] Changed hash function, added "registers" --- mach/proto/top/top.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/mach/proto/top/top.c b/mach/proto/top/top.c index 11ea8247..c4af8ecd 100644 --- a/mach/proto/top/top.c +++ b/mach/proto/top/top.c @@ -89,14 +89,14 @@ bool try_hashentry(list,window) int *list; queue window; { - int *pp; + register int *pp; patdescr_p p; for (pp = list; *pp != -1; pp++) { p = &patterns[*pp]; if (check_pattern(p,window) && check_operands(p,window) && - check_constraint(p-patterns)) { + check_constraint(*pp)) { xform(p,window); return TRUE; } @@ -131,8 +131,8 @@ int hash(w) */ for (sum=i=0,p=ip->opc;*p;i += 3) - sum += (*p++)<<(i&07); - return(sum%127); + sum += (*p++)<<(i&03); + return(sum%128); } /* Fill the working window until it contains at least 'len' items. @@ -140,9 +140,9 @@ int hash(w) */ fill_window(w,len) - queue w; + register queue w; { - instr_p ip; + register instr_p ip; while(qlength(w) < len) { if ((ip = read_instr()) == NIL) break; @@ -166,7 +166,7 @@ write_first(w) /* Try to recognize the opcode part of an instruction */ set_opcode(ip) - instr_p ip; + register instr_p ip; { register char *p,*q; char *qlim; @@ -227,8 +227,8 @@ bool check_operands(p,w) patdescr_p p; queue w; { - instr_p ip; - idescr_p id_p; + register instr_p ip; + register idescr_p id_p; int n; /* fprintf(stderr,"try pattern %d\n",p-patterns); */ @@ -295,9 +295,9 @@ bool opmatch(t,s) /* Try to recognize the operands of an instruction */ bool split_operands(ip) - instr_p ip; + register instr_p ip; { - int i; + register int i; bool res; if (strcmp(ip->opc,"labdef") ==0) { @@ -313,9 +313,9 @@ bool split_operands(ip) labeldef(ip) - instr_p ip; + register instr_p ip; { - char *p; + register char *p; int oplen; p = ip->rest_line; @@ -409,7 +409,7 @@ bool rstrip(str,ctxt) bool unify(str,v) char *str; - struct variable *v; + register struct variable *v; { if (v->vstate == UNINSTANTIATED) { v->vstate = INSTANTIATED; @@ -447,10 +447,10 @@ xform(p,w) */ replacement(p,w) - patdescr_p p; + register patdescr_p p; queue w; { - idescr_p id_p; + register idescr_p id_p; for (id_p = &p->repl[p->replen-1]; id_p >= p->repl; id_p--) { insert(w,gen_instr(id_p)); @@ -470,7 +470,7 @@ instr_p gen_instr(id_p) { char *opc; instr_p ip; - templ_p t; + register templ_p t; register char *s; bool islabdef; int n; From 18649b3ef5a32712d02f8bb9036fb68b25539b81 Mon Sep 17 00:00:00 2001 From: ceriel Date: Sat, 7 Feb 1987 00:14:51 +0000 Subject: [PATCH 0764/1625] changed hash function --- util/topgen/hash.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/topgen/hash.c b/util/topgen/hash.c index c8c45826..f0665e90 100644 --- a/util/topgen/hash.c +++ b/util/topgen/hash.c @@ -23,8 +23,8 @@ hash(string) char *string; { if (strcmp(string,"ANY") == 0) return 128; for (sum=i=0,p=string;*p;i += 3) - sum += (*p++)<<(i&07); - return sum % 127; + sum += (*p++)<<(i&03); + return sum % 128; } From b4217fcc84cd257e03cc3bf9826bf4a01c41d768 Mon Sep 17 00:00:00 2001 From: ceriel Date: Sat, 7 Feb 1987 00:35:16 +0000 Subject: [PATCH 0765/1625] *** empty log message *** --- mach/proto/top/top.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/mach/proto/top/top.c b/mach/proto/top/top.c index c4af8ecd..62f498d1 100644 --- a/mach/proto/top/top.c +++ b/mach/proto/top/top.c @@ -155,9 +155,9 @@ fill_window(w,len) write_first(w) queue w; { - instr_p ip; + register instr_p ip = qhead(w); - write_instr(ip = qhead(w)); + fputs(ip->line, stdout); remove_head(w); oldinstr(ip); } @@ -524,14 +524,15 @@ static bool junk_state = FALSE; /* TRUE while processing a very long line */ instr_p read_instr() { - register instr_p ip; + instr_p ip; register int c; register char *p; + register FILE *inp = stdin; char *plim; ip = newinstr(); plim = &ip->line[MAXLINELEN]; - if (( c = getchar()) == EOF) return NIL; + if (( c = getc(inp)) == EOF) return NIL; for (p = ip->line; p < plim;) { *p++ = c; if (c == '\n') { @@ -540,26 +541,15 @@ instr_p read_instr() junk_state = FALSE; return ip; } - c = getchar(); + c = getc(inp); } - ungetc(c,stdin); + ungetc(c,inp); *p = '\0'; junk_state = ip->state = JUNK; return ip; } -write_instr(ip) - instr_p ip; -{ - register char *p; - - for (p = ip->line; *p != '\0'; p++) { - putchar(*p); - } -} - - /* Core allocation. * As all instruction struct have the same size we can re-use every struct. From ca3b97ff34e3b22e9e519272e8305582120c3840 Mon Sep 17 00:00:00 2001 From: ceriel Date: Sat, 7 Feb 1987 00:45:06 +0000 Subject: [PATCH 0766/1625] Added some patterns, and avoided a bug in the VAX assembler --- mach/vax4/cg/table | 69 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 5 deletions(-) diff --git a/mach/vax4/cg/table b/mach/vax4/cg/table index 08282b38..a72501d5 100644 --- a/mach/vax4/cg/table +++ b/mach/vax4/cg/table @@ -4,6 +4,16 @@ /*#define DORCK /* define if you want RCK */ #define FLOAT4 /* define if you want better 4-byte FP arithmetic */ #define FLOAT8 /* define if you want better 8-byte FP arithmetic */ +#define ASBUG_AVOID /* define if you want to avoid a bug in the BSD 4.1 VAX + assembler, that sometimes generates "*1" for + (r1). This is avoided by generating 0(r1), which is + optimized by the assembler to (r1). + */ +#ifdef ASBUG_AVOID +#define REGDEFFORMAT "0(%[reg])" +#else +#define REGDEFFORMAT "(%[reg])" +#endif #define NC nocoercions : #define BSIZE 4 @@ -91,10 +101,10 @@ EXTERNAL4 = {STRING ind;} 4 cost=(4,6) "%[ind]" EXTERNAL8 = {STRING ind;} 8 cost=(4,9) "%[ind]" DOUBLE = {STRING ind;} 4 cost=(4,6) "$%[ind]" /* Now tokens for the target machine */ -regdef1 = {REGISTER reg;} 4 cost=(0,3) "(%[reg])" -regdef2 = {REGISTER reg;} 4 cost=(0,3) "(%[reg])" -regdef4 = {REGISTER reg;} 4 cost=(0,3) "(%[reg])" -regdef8 = {REGISTER reg;} 8 cost=(0,6) "(%[reg])" +regdef1 = {REGISTER reg;} 4 cost=(0,3) REGDEFFORMAT +regdef2 = {REGISTER reg;} 4 cost=(0,3) REGDEFFORMAT +regdef4 = {REGISTER reg;} 4 cost=(0,3) REGDEFFORMAT +regdef8 = {REGISTER reg;} 8 cost=(0,6) REGDEFFORMAT #ifdef REGVARS reginc1 = {REGISTER reg;} 4 cost=(0,3) "(%[reg])+" reginc2 = {REGISTER reg;} 4 cost=(0,3) "(%[reg])+" @@ -271,7 +281,7 @@ loc $1>=256 && $1<65536 | | | {CONST2,$1} | | loc | | | {CONST4,$1} | | ldc | | | {CONST8,$1} | | #ifdef REGVARS -lol inreg($1)==2 | | | regvar($1) | | +lol inreg($1)==2 | | REMREG($1) | regvar($1) | | #endif REGVARS lol $1 < 0 | | | {LOCAL4,LB,$1,4} | | lol $1 >= 0 | | | {LOCAL4,AP,$1,4} | | @@ -676,6 +686,11 @@ adi sil $1==4 && inreg($2)==2 REMEXTANDLOC "addl3\t%[1],%[2],(%(regvar($2)%))" setcc({regdef4,regvar($2)}) | | | +adi lol stf $1==4 && inreg($2)==2 + | source4 source4 | + REMEXTANDLOC + "addl3\t%[1],%[2],$3(%(regvar($2)%))" + setcc({displ4,regvar($2),tostring($3)}) | | | #endif REGVARS adi sil $1==4 && $2<0 | source4 source4 | @@ -729,6 +744,11 @@ sbi sil $1==4 && inreg($2)==2 REMEXTANDLOC "subl3\t%[1],%[2],(%(regvar($2)%))" setcc({regdef4,regvar($2)}) | | | +sbi lol stf $1==4 && inreg($2)==2 + | source4 source4 | + REMEXTANDLOC + "subl3\t%[1],%[2],$3(%(regvar($2)%))" + setcc({displ4,regvar($2),tostring($3)}) | | | #endif REGVARS sbi sil $1==4 && $2<0 | source4 source4 | @@ -786,6 +806,11 @@ mli sil $1==4 && inreg($2)==2 REMEXTANDLOC "mull3\t%[1],%[2],(%(regvar($2)%))" setcc({regdef4,regvar($2)}) | | | +mli lol stf $1==4 && inreg($2)==2 + | source4 source4 | + REMEXTANDLOC + "mull3\t%[1],%[2],$3(%(regvar($2)%))" + setcc({displ4,regvar($2),tostring($3)}) | | | #endif REGVARS mli sil $1==4 && $2<0 | source4 source4 | @@ -839,6 +864,11 @@ dvi sil $1==4 && inreg($2)==2 REMEXTANDLOC "divl3\t%[1],%[2],(%(regvar($2)%))" setcc({regdef4,regvar($2)}) | | | +dvi lol stf $1==4 && inreg($2)==2 + | source4 source4 | + REMEXTANDLOC + "divl3\t%[1],%[2],$3(%(regvar($2)%))" + setcc({displ4,regvar($2),tostring($3)}) | | | #endif REGVARS dvi sil $1==4 && $2<0 | source4 source4 | @@ -902,6 +932,14 @@ rmi sil $1==4 && inreg($2)==2 "mull2\t%[1],%[a]" "subl3\t%[a],%[2],(%(regvar($2)%))" setcc({regdef4,regvar($2)}) | | | +rmi lol stf $1==4 && inreg($2)==2 + | Xsource4 Xsource4 | + REMEXTANDLOC + allocate(REG) + "divl3\t%[1],%[2],%[a]" + "mull2\t%[1],%[a]" + "subl3\t%[1],%[2],$3(%(regvar($2)%))" + setcc({displ4,regvar($2),tostring($3)}) | | | #endif REGVARS rmi sil $1==4 && $2<0 | Xsource4 Xsource4 | @@ -961,6 +999,11 @@ ngi sil $1==4 && inreg($2)==2 REMEXTANDLOC "mnegl\t%[1],(%(regvar($2)%))" setcc({regdef4,regvar($2)}) | | | +ngi lol stf $1==4 && inreg($2)==2 + | source4 | + REMEXTANDLOC + "mnegl\t%[1],$3(%(regvar($2)%))" + setcc({displ4,regvar($2),tostring($3)}) | | | #endif REGVARS ngi sil $1==4 && $2<0 | source4 | @@ -1010,6 +1053,11 @@ sli sil $1==4 && inreg($2)==2 REMEXTANDLOC "ashl\t%[1],%[2],(%(regvar($2)%))" setcc({regdef4,regvar($2)}) | | | +sli lol stf $1==4 && inreg($2)==2 + | source4 source4 | + REMEXTANDLOC + "ashl\t%[1],%[2],$3(%(regvar($2)%))" + setcc({displ4,regvar($2),tostring($3)}) | | | #endif REGVARS sli sil $1==4 && $2<0 | source4 source4 | @@ -1092,6 +1140,17 @@ sri sil $1==4 && inreg($2)==2 REMEXTANDLOC "ashl\t$$%(0-%[1.num]%),%[2],(%(regvar($2)%))" setcc({regdef4,regvar($2)}) | | | (6,10)+%[1]+%[2] +sri lol stf $1==4 && inreg($2)==2 + | source4 source4 | + REMEXTANDLOC + allocate(%[1], REG) + "mnegl\t%[1],%[a]" + "ashl\t%[a],%[2],$3(%(regvar($2)%))" + setcc({displ4,regvar($2),tostring($3)}) | | | (9,14)+%[1]+%[2] +... | NC CONST source4 | + REMEXTANDLOC + "ashl\t$$%(0-%[1.num]%),%[2],$3(%(regvar($2)%))" + setcc({displ4,regvar($2),tostring($3)}) | | | (6,10)+%[1]+%[2] #endif REGVARS sri sil $1==4 && $2<0 | source4 source4 | From 16c989588cded06d1f14fe79338546853bb0a006 Mon Sep 17 00:00:00 2001 From: ceriel Date: Sat, 7 Feb 1987 00:52:30 +0000 Subject: [PATCH 0767/1625] Remove .m files before recreating them. The existing ones might have another owner, so that you cannot write them --- lang/pc/pem/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lang/pc/pem/Makefile b/lang/pc/pem/Makefile index 89953c4a..f1925c9e 100644 --- a/lang/pc/pem/Makefile +++ b/lang/pc/pem/Makefile @@ -36,11 +36,11 @@ install: pem cp pem $(PEM) distr: - rm -f pem22.p ; ln pem.p pem22.p + rm -f pem22.[mp] ; ln pem.p pem22.p apc -mpdp -c.m -I$h pem22.p ; rm -f pem22.p - rm -f pem24.p ; ln pem.p pem24.p + rm -f pem24.[mp] ; ln pem.p pem24.p apc -mvax2 -c.m -I$h pem24.p ; rm -f pem24.p - rm -f pem44.p ; ln pem.p pem44.p + rm -f pem44.[mp] ; ln pem.p pem44.p apc -mvax4 -c.m -I$h pem44.p ; rm -f pem44.p clean: From 921b3ed5f167427a0f0362b174061a7eeafbff0b Mon Sep 17 00:00:00 2001 From: ceriel Date: Sat, 7 Feb 1987 00:56:42 +0000 Subject: [PATCH 0768/1625] target optimizer directory name is "top", not "opt" --- mach/m68k2/Action | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/m68k2/Action b/mach/m68k2/Action index 10fe8e7a..9e0885cf 100644 --- a/mach/m68k2/Action +++ b/mach/m68k2/Action @@ -8,7 +8,7 @@ name "Motorola 68000 2-4 conversion program" dir cv end name "Motorola 68000 target optimizer" -dir opt +dir top end name "Motorola 68000 2-4 C libraries" dir libcc From b5dc37b50a8e8ca15ecead45c3021c0f155586d9 Mon Sep 17 00:00:00 2001 From: ceriel Date: Sat, 7 Feb 1987 01:50:48 +0000 Subject: [PATCH 0769/1625] Changed an assertion that was no longer valid --- mach/proto/ncg/subr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/proto/ncg/subr.c b/mach/proto/ncg/subr.c index 0805141f..ed67ca22 100644 --- a/mach/proto/ncg/subr.c +++ b/mach/proto/ncg/subr.c @@ -368,7 +368,7 @@ instsize(tinstno,tp) token_p tp; { default: assert(FALSE); case IN_COPY: - assert(inp->in_info[0]==1); + assert(inp->in_info[0]<=1); #if MAXMEMBERS!=0 if (inp->in_info[1]==0) #endif From 6896b5cb7e1c4da329909a047b62f0442a599edd Mon Sep 17 00:00:00 2001 From: ceriel Date: Sat, 7 Feb 1987 02:57:09 +0000 Subject: [PATCH 0770/1625] Added "opt2" to the clean entry --- util/opt/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/opt/Makefile b/util/opt/Makefile index 988b2743..7d2ff552 100644 --- a/util/opt/Makefile +++ b/util/opt/Makefile @@ -81,7 +81,7 @@ sizes: opt -nm opt | sort -n| /usr/plain/bin/map clean: - rm -f *.o opt mktab mktab.c scan.c pattern.c + rm -f *.o opt mktab mktab.c scan.c pattern.c opt2 Out regnoglob.c: reg.c cp reg.c regnoglob.c From 5e4afca1635b95d8f938edac8e53acc7f8f9559a Mon Sep 17 00:00:00 2001 From: ceriel Date: Sat, 7 Feb 1987 02:58:47 +0000 Subject: [PATCH 0771/1625] Added cpp to the "clean" entry --- util/cpp/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/cpp/Makefile b/util/cpp/Makefile index adb5db22..e9936acb 100644 --- a/util/cpp/Makefile +++ b/util/cpp/Makefile @@ -134,7 +134,7 @@ lint: cfiles lint -bx $(CDEFS) $(SRC) >lint.out clean: - rm -f $(LCSRC) $(OBJ) $(GENERATED) $(GSRC) $(GHSRC) chtab.o chtab + rm -f $(LCSRC) $(OBJ) $(GENERATED) $(GSRC) $(GHSRC) chtab.o chtab cpp Out #AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO LLlex.o: LLlex.h Lpars.h bits.h charoffset.h class.h dobits.h file_info.h idf.h idfsize.h input.h inputtype.h numsize.h strsize.h From 0621a865c9b38a5dbf441f341af977ccabc741ee Mon Sep 17 00:00:00 2001 From: ceriel Date: Sat, 7 Feb 1987 03:56:34 +0000 Subject: [PATCH 0772/1625] The added ',' separator in token declarations did not work (reported by Kees Bot, Edwin Scheffer). This is corrected (I hope). --- util/ncgg/cgg.y | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/util/ncgg/cgg.y b/util/ncgg/cgg.y index f61d5871..96e4649e 100644 --- a/util/ncgg/cgg.y +++ b/util/ncgg/cgg.y @@ -86,7 +86,7 @@ iocc_t iops[20]; %token TIMEFACTOR SIZEFACTOR %token COST %type prop_list property ident_list ident_list_el -%type att_list att_list_el att_list_el_list structdecl optcost optformat +%type att_list att_list_el att_list_el_list att_ident structdecl optcost optformat %type kills allocates yields leaving %type generates kill_list kill_list_el uselist uselist_el genlist yieldlist %type leavelist leavelist_el gen_instruction @@ -302,28 +302,28 @@ att_list : /* empty */ { $$ = 0; } | att_list_el att_list - { $1->vi_next = $2; $$ = $1; } + { $$ = $1; while ($$->vi_next) $$ = $$->vi_next; + $$->vi_next = $2; $$ = $1; + } ; att_list_el - : att_list_el_type IDENT - { NEW ($$,struct varinfo); - $$->vi_int[0] = $1; - $$->vi_str[0] = $2; - att_type = $1; - } - att_list_el_list ';' - { $3->vi_next = $4; - $$ = $3; - } + : att_list_el_type + { att_type = $1; } + att_list_el_list + ';' + { $$ = $3; } ; att_list_el_list - : /* empty */ - { $$ = 0; } - | ',' IDENT att_list_el_list + : att_ident + | att_ident ',' att_list_el_list + { $1->vi_next = $3; $$ = $1; } + ; +att_ident + : IDENT { NEW($$, struct varinfo); - $$->vi_next = $3; + $$->vi_next = 0; $$->vi_int[0] = att_type; - $$->vi_str[0] = $2; + $$->vi_str[0] = $1; } ; att_list_el_type From 520644440acc48e7d7848329151adc56d4d1f444 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 9 Feb 1987 10:46:18 +0000 Subject: [PATCH 0773/1625] belonging to new version of pascal compiler --- h/pc_size.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/h/pc_size.h b/h/pc_size.h index 8545063f..5ae6a090 100644 --- a/h/pc_size.h +++ b/h/pc_size.h @@ -1,13 +1,10 @@ -/* fundamental */ + +/*fundamental */ #define sz_byte 1 #define sz_bool 1 #define sz_char 1 -/* fixed for the time being */ -#define sz_word 2 -#define sz_int 2 -#define sz_long 4 - +/* target machine characteristics */ /* variable (see pc.c) */ #define sz_addr sizes[0] #define sz_real sizes[1] @@ -15,7 +12,10 @@ #define sz_buff sizes[3] #define sz_mset sizes[4] #define sz_iset sizes[5] +#define sz_word sizes[6] +#define sz_int sizes[7] +#define sz_long sizes[8] -#define sz_last 5 +#define sz_last 8 #define sz_proc 2*sz_addr From 398a70cf772f18bd0f843b455dd63f113658d66c Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 9 Feb 1987 14:54:29 +0000 Subject: [PATCH 0774/1625] *** empty log message *** --- modules/src/alloc/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/src/alloc/Makefile b/modules/src/alloc/Makefile index a5371920..25934250 100644 --- a/modules/src/alloc/Makefile +++ b/modules/src/alloc/Makefile @@ -16,7 +16,7 @@ OBJECTS = botch.o clear.o st_alloc.o Malloc.o std_alloc.o all: liballoc.a -liballoc.a: all +liballoc.a: $(OBJECTS) ar cr liballoc.a $(OBJECTS) -sh -c 'ranlib liballoc.a' @@ -25,7 +25,7 @@ install: all $(INSTALL) man/alloc.3 $(INSTALL) h/alloc.h -cmp: liballoc.a +cmp: all $(COMPARE) lib/liballoc.a $(COMPARE) man/alloc.3 $(COMPARE) h/alloc.h From e2136f386c5f75f09ae4579dfefa6f10e275c556 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 9 Feb 1987 14:55:59 +0000 Subject: [PATCH 0775/1625] Initial revision --- modules/src/assert/BadAssert.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 modules/src/assert/BadAssert.c diff --git a/modules/src/assert/BadAssert.c b/modules/src/assert/BadAssert.c new file mode 100644 index 00000000..aa099500 --- /dev/null +++ b/modules/src/assert/BadAssert.c @@ -0,0 +1,34 @@ +/* _BadAssertion: used for debugging purposes. It should give an error message + indicated by the parameters, and then give a core dump +*/ + +#include + +static +wr_num(fd, n) + File *fd; + int n; +{ + char s[2]; + + s[1] = '\0'; + if (n >= 10) { + wr_num(fd, n/10); + } + s[0] = (n % 10) + '0'; + (void) sys_write(fd, s, 1); +} + +_BadAssertion(file, lineno, assertion) + char *file, *assertion; + int lineno; +{ + + (void) sys_write(STDERR, file, strlen(file)); + (void) sys_write(STDERR, ", line ", 7); + wr_num(STDERR, lineno); + (void) sys_write(STDERR, ": assertion \"", 13); + (void) sys_write(STDERR, assertion, strlen(assertion)); + (void) sys_write(STDERR, "\" failed\n", 9); + sys_stop(S_ABORT); +} From 8950c32d5e177970be5d1cdc22f587296f5e8447 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 9 Feb 1987 15:06:09 +0000 Subject: [PATCH 0776/1625] changed so that it prints a separate line for each dependancy --- util/cmisc/mkdep.1 | 6 ++++-- util/cmisc/mkdep.c | 4 +--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/util/cmisc/mkdep.1 b/util/cmisc/mkdep.1 index 7c42ecd5..97f389fd 100644 --- a/util/cmisc/mkdep.1 +++ b/util/cmisc/mkdep.1 @@ -10,9 +10,11 @@ scans the files in the argument list for C-preprocessor lines of the form .DS #include "\fIfile1\fp" .DE -and produces for each file \fIarg\fR in the argument list a line of the form +and produces for each file \fIarg\fR in the argument list lines of the form .DS -\fIarg\fR: \fIfile1\fR \fIfile2\fR ... +\fIarg\fR: \fIfile1\fR +\fIarg\fR: \fIfile2\fR +... .DE where \fIfile1\fR, \fIfile2\fR, etc. are filenames included by \fIarg\fR, or by a file included by \fIarg\fR, etc. diff --git a/util/cmisc/mkdep.c b/util/cmisc/mkdep.c index d17b0b98..b4a0dfbc 100644 --- a/util/cmisc/mkdep.c +++ b/util/cmisc/mkdep.c @@ -84,12 +84,10 @@ print_namelist(nm, nlp) struct namelist *nlp; { if (nlp) { - printf("%s:", nm); while (nlp) { - printf(" %s", nlp->name); + printf("%s: %s\n", nm, nlp->name); nlp = nlp->next; } - printf("\n"); } } From 9ff348b6751371629fda9b8825d0a504fbb0765b Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 9 Feb 1987 15:26:16 +0000 Subject: [PATCH 0777/1625] Initial revision --- include/_tail_cc/assert.h | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 include/_tail_cc/assert.h diff --git a/include/_tail_cc/assert.h b/include/_tail_cc/assert.h new file mode 100644 index 00000000..5cd6c435 --- /dev/null +++ b/include/_tail_cc/assert.h @@ -0,0 +1,11 @@ +/* $Header$ */ +/* A S S E R T I O N M A C R O D E F I N I T I O N */ + +#ifndef NDEBUG +/* Note: this macro uses parameter substitution inside strings */ +#define assert(exp) (exp || (fprintf(stderr,"Assertion \"%s\" failed: file %s, line %d\n", "exp", __FILE__, __LINE__), exit(1))) +#define _assert(exp) (exp || (fprintf(stderr,"Assertion \"%s\" failed: file %s, line %d\n", "exp", __FILE__, __LINE__), exit(1))) +#else +#define assert(exp) (1) +#define _assert(exp) (1) +#endif NDEBUG From 56e99309d73a8d1cba50479bc790cc51c6607d24 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 9 Feb 1987 16:26:56 +0000 Subject: [PATCH 0778/1625] Removed a %03x, which does not work on USG systems --- mach/m68020/ncg/mach.h | 2 +- mach/m68k2/ncg/mach.h | 2 +- mach/m68k4/ncg/mach.h | 2 +- mach/moon3/ncg/mach.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mach/m68020/ncg/mach.h b/mach/m68020/ncg/mach.h index 48763723..ad65af19 100644 --- a/mach/m68020/ncg/mach.h +++ b/mach/m68020/ncg/mach.h @@ -19,7 +19,7 @@ and then run "make" again #define pop_fmt "(sp)+" #define cst_fmt "%ld" #define off_fmt "%ld" -#define ilb_fmt "I%03x%x" +#define ilb_fmt "I%x_%x" #define dlb_fmt "_%d" #define hol_fmt "hol%d" diff --git a/mach/m68k2/ncg/mach.h b/mach/m68k2/ncg/mach.h index 48763723..ad65af19 100644 --- a/mach/m68k2/ncg/mach.h +++ b/mach/m68k2/ncg/mach.h @@ -19,7 +19,7 @@ and then run "make" again #define pop_fmt "(sp)+" #define cst_fmt "%ld" #define off_fmt "%ld" -#define ilb_fmt "I%03x%x" +#define ilb_fmt "I%x_%x" #define dlb_fmt "_%d" #define hol_fmt "hol%d" diff --git a/mach/m68k4/ncg/mach.h b/mach/m68k4/ncg/mach.h index 48763723..ad65af19 100644 --- a/mach/m68k4/ncg/mach.h +++ b/mach/m68k4/ncg/mach.h @@ -19,7 +19,7 @@ and then run "make" again #define pop_fmt "(sp)+" #define cst_fmt "%ld" #define off_fmt "%ld" -#define ilb_fmt "I%03x%x" +#define ilb_fmt "I%x_%x" #define dlb_fmt "_%d" #define hol_fmt "hol%d" diff --git a/mach/moon3/ncg/mach.h b/mach/moon3/ncg/mach.h index 48763723..ad65af19 100644 --- a/mach/moon3/ncg/mach.h +++ b/mach/moon3/ncg/mach.h @@ -19,7 +19,7 @@ and then run "make" again #define pop_fmt "(sp)+" #define cst_fmt "%ld" #define off_fmt "%ld" -#define ilb_fmt "I%03x%x" +#define ilb_fmt "I%x_%x" #define dlb_fmt "_%d" #define hol_fmt "hol%d" From 68220884132a609d40a5f473dfdbc2ec154dc24f Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 9 Feb 1987 16:29:15 +0000 Subject: [PATCH 0779/1625] changed directory: nas --> as --- mach/6500/as/Makefile | 2 +- mach/6800/as/Makefile | 2 +- mach/6805/as/Makefile | 2 +- mach/6809/as/Makefile | 2 +- mach/arm/as/Makefile | 2 +- mach/i386/as/Makefile | 2 +- mach/i80/as/Makefile | 2 +- mach/i86/as/Makefile | 2 +- mach/m68020/as/Makefile | 2 +- mach/m68k2/as/Makefile | 2 +- mach/ns/as/Makefile | 2 +- mach/pdp/as/Makefile | 2 +- mach/proto/as/Makefile | 2 +- mach/s2650/as/Makefile | 2 +- mach/vax4/as/Makefile | 2 +- mach/z80/as/Makefile | 2 +- mach/z8000/as/Makefile | 2 +- 17 files changed, 17 insertions(+), 17 deletions(-) diff --git a/mach/6500/as/Makefile b/mach/6500/as/Makefile index becc0d3d..1eb3b3c0 100644 --- a/mach/6500/as/Makefile +++ b/mach/6500/as/Makefile @@ -2,7 +2,7 @@ EM = ../../.. h = $(EM)/h LIBOBJ = $(EM)/modules/lib/libobject.a -CDIR = $(EM)/mach/proto/nas +CDIR = $(EM)/mach/proto/as CPP = $(EM)/lib/cpp DEF = diff --git a/mach/6800/as/Makefile b/mach/6800/as/Makefile index becc0d3d..1eb3b3c0 100644 --- a/mach/6800/as/Makefile +++ b/mach/6800/as/Makefile @@ -2,7 +2,7 @@ EM = ../../.. h = $(EM)/h LIBOBJ = $(EM)/modules/lib/libobject.a -CDIR = $(EM)/mach/proto/nas +CDIR = $(EM)/mach/proto/as CPP = $(EM)/lib/cpp DEF = diff --git a/mach/6805/as/Makefile b/mach/6805/as/Makefile index becc0d3d..1eb3b3c0 100644 --- a/mach/6805/as/Makefile +++ b/mach/6805/as/Makefile @@ -2,7 +2,7 @@ EM = ../../.. h = $(EM)/h LIBOBJ = $(EM)/modules/lib/libobject.a -CDIR = $(EM)/mach/proto/nas +CDIR = $(EM)/mach/proto/as CPP = $(EM)/lib/cpp DEF = diff --git a/mach/6809/as/Makefile b/mach/6809/as/Makefile index becc0d3d..1eb3b3c0 100644 --- a/mach/6809/as/Makefile +++ b/mach/6809/as/Makefile @@ -2,7 +2,7 @@ EM = ../../.. h = $(EM)/h LIBOBJ = $(EM)/modules/lib/libobject.a -CDIR = $(EM)/mach/proto/nas +CDIR = $(EM)/mach/proto/as CPP = $(EM)/lib/cpp DEF = diff --git a/mach/arm/as/Makefile b/mach/arm/as/Makefile index becc0d3d..1eb3b3c0 100644 --- a/mach/arm/as/Makefile +++ b/mach/arm/as/Makefile @@ -2,7 +2,7 @@ EM = ../../.. h = $(EM)/h LIBOBJ = $(EM)/modules/lib/libobject.a -CDIR = $(EM)/mach/proto/nas +CDIR = $(EM)/mach/proto/as CPP = $(EM)/lib/cpp DEF = diff --git a/mach/i386/as/Makefile b/mach/i386/as/Makefile index becc0d3d..1eb3b3c0 100644 --- a/mach/i386/as/Makefile +++ b/mach/i386/as/Makefile @@ -2,7 +2,7 @@ EM = ../../.. h = $(EM)/h LIBOBJ = $(EM)/modules/lib/libobject.a -CDIR = $(EM)/mach/proto/nas +CDIR = $(EM)/mach/proto/as CPP = $(EM)/lib/cpp DEF = diff --git a/mach/i80/as/Makefile b/mach/i80/as/Makefile index becc0d3d..1eb3b3c0 100644 --- a/mach/i80/as/Makefile +++ b/mach/i80/as/Makefile @@ -2,7 +2,7 @@ EM = ../../.. h = $(EM)/h LIBOBJ = $(EM)/modules/lib/libobject.a -CDIR = $(EM)/mach/proto/nas +CDIR = $(EM)/mach/proto/as CPP = $(EM)/lib/cpp DEF = diff --git a/mach/i86/as/Makefile b/mach/i86/as/Makefile index becc0d3d..1eb3b3c0 100644 --- a/mach/i86/as/Makefile +++ b/mach/i86/as/Makefile @@ -2,7 +2,7 @@ EM = ../../.. h = $(EM)/h LIBOBJ = $(EM)/modules/lib/libobject.a -CDIR = $(EM)/mach/proto/nas +CDIR = $(EM)/mach/proto/as CPP = $(EM)/lib/cpp DEF = diff --git a/mach/m68020/as/Makefile b/mach/m68020/as/Makefile index becc0d3d..1eb3b3c0 100644 --- a/mach/m68020/as/Makefile +++ b/mach/m68020/as/Makefile @@ -2,7 +2,7 @@ EM = ../../.. h = $(EM)/h LIBOBJ = $(EM)/modules/lib/libobject.a -CDIR = $(EM)/mach/proto/nas +CDIR = $(EM)/mach/proto/as CPP = $(EM)/lib/cpp DEF = diff --git a/mach/m68k2/as/Makefile b/mach/m68k2/as/Makefile index becc0d3d..1eb3b3c0 100644 --- a/mach/m68k2/as/Makefile +++ b/mach/m68k2/as/Makefile @@ -2,7 +2,7 @@ EM = ../../.. h = $(EM)/h LIBOBJ = $(EM)/modules/lib/libobject.a -CDIR = $(EM)/mach/proto/nas +CDIR = $(EM)/mach/proto/as CPP = $(EM)/lib/cpp DEF = diff --git a/mach/ns/as/Makefile b/mach/ns/as/Makefile index becc0d3d..1eb3b3c0 100644 --- a/mach/ns/as/Makefile +++ b/mach/ns/as/Makefile @@ -2,7 +2,7 @@ EM = ../../.. h = $(EM)/h LIBOBJ = $(EM)/modules/lib/libobject.a -CDIR = $(EM)/mach/proto/nas +CDIR = $(EM)/mach/proto/as CPP = $(EM)/lib/cpp DEF = diff --git a/mach/pdp/as/Makefile b/mach/pdp/as/Makefile index becc0d3d..1eb3b3c0 100644 --- a/mach/pdp/as/Makefile +++ b/mach/pdp/as/Makefile @@ -2,7 +2,7 @@ EM = ../../.. h = $(EM)/h LIBOBJ = $(EM)/modules/lib/libobject.a -CDIR = $(EM)/mach/proto/nas +CDIR = $(EM)/mach/proto/as CPP = $(EM)/lib/cpp DEF = diff --git a/mach/proto/as/Makefile b/mach/proto/as/Makefile index becc0d3d..1eb3b3c0 100644 --- a/mach/proto/as/Makefile +++ b/mach/proto/as/Makefile @@ -2,7 +2,7 @@ EM = ../../.. h = $(EM)/h LIBOBJ = $(EM)/modules/lib/libobject.a -CDIR = $(EM)/mach/proto/nas +CDIR = $(EM)/mach/proto/as CPP = $(EM)/lib/cpp DEF = diff --git a/mach/s2650/as/Makefile b/mach/s2650/as/Makefile index becc0d3d..1eb3b3c0 100644 --- a/mach/s2650/as/Makefile +++ b/mach/s2650/as/Makefile @@ -2,7 +2,7 @@ EM = ../../.. h = $(EM)/h LIBOBJ = $(EM)/modules/lib/libobject.a -CDIR = $(EM)/mach/proto/nas +CDIR = $(EM)/mach/proto/as CPP = $(EM)/lib/cpp DEF = diff --git a/mach/vax4/as/Makefile b/mach/vax4/as/Makefile index becc0d3d..1eb3b3c0 100644 --- a/mach/vax4/as/Makefile +++ b/mach/vax4/as/Makefile @@ -2,7 +2,7 @@ EM = ../../.. h = $(EM)/h LIBOBJ = $(EM)/modules/lib/libobject.a -CDIR = $(EM)/mach/proto/nas +CDIR = $(EM)/mach/proto/as CPP = $(EM)/lib/cpp DEF = diff --git a/mach/z80/as/Makefile b/mach/z80/as/Makefile index becc0d3d..1eb3b3c0 100644 --- a/mach/z80/as/Makefile +++ b/mach/z80/as/Makefile @@ -2,7 +2,7 @@ EM = ../../.. h = $(EM)/h LIBOBJ = $(EM)/modules/lib/libobject.a -CDIR = $(EM)/mach/proto/nas +CDIR = $(EM)/mach/proto/as CPP = $(EM)/lib/cpp DEF = diff --git a/mach/z8000/as/Makefile b/mach/z8000/as/Makefile index becc0d3d..1eb3b3c0 100644 --- a/mach/z8000/as/Makefile +++ b/mach/z8000/as/Makefile @@ -2,7 +2,7 @@ EM = ../../.. h = $(EM)/h LIBOBJ = $(EM)/modules/lib/libobject.a -CDIR = $(EM)/mach/proto/nas +CDIR = $(EM)/mach/proto/as CPP = $(EM)/lib/cpp DEF = From 1a2c8dd860cfc1b3505a42080b9bfa947f9da74f Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 9 Feb 1987 16:33:49 +0000 Subject: [PATCH 0780/1625] removed something that would not work on System V --- mach/pdp/ncg/mach.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/pdp/ncg/mach.h b/mach/pdp/ncg/mach.h index 7bacb57b..b487a717 100644 --- a/mach/pdp/ncg/mach.h +++ b/mach/pdp/ncg/mach.h @@ -10,7 +10,7 @@ #define cst_fmt "$0%o" #define off_fmt "0%o" -#define ilb_fmt "I%03x%x" +#define ilb_fmt "I%x_%x" #define dlb_fmt "_%d" #define hol_fmt "hol%d" From 2051a4ff62709ab59fd891d0eada7266add6aa92 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 9 Feb 1987 16:35:24 +0000 Subject: [PATCH 0781/1625] %03x --> %x_, because the former does not work on System V --- mach/pdp/cg/mach.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/pdp/cg/mach.h b/mach/pdp/cg/mach.h index 92b9cf75..c150323b 100644 --- a/mach/pdp/cg/mach.h +++ b/mach/pdp/cg/mach.h @@ -26,7 +26,7 @@ #define cst_fmt "$0%o" #define off_fmt "0%o" -#define ilb_fmt "I%03x%x" +#define ilb_fmt "I%x_%x" #define dlb_fmt "_%d" #define hol_fmt "hol%d" From 425570290b70ca7ef4814263cd2bbb41666a7fe3 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 9 Feb 1987 16:39:05 +0000 Subject: [PATCH 0782/1625] *** empty log message *** --- mach/z80/cg/mach.c | 28 +++++++++++++++++++--------- mach/z80/cg/mach.h | 13 +++++++------ 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/mach/z80/cg/mach.c b/mach/z80/cg/mach.c index 89abf0c9..16108fcc 100644 --- a/mach/z80/cg/mach.c +++ b/mach/z80/cg/mach.c @@ -43,18 +43,28 @@ con_part(sz,w) register sz; word w; { } con_mult(sz) word sz; { - long l; + long atol(); if (argval != 4) fatal("bad icon/ucon size"); - l = atol(str); - fprintf(codefile,".short\t%d\n",(int)l); - fprintf(codefile,".short\t%d\n",(int)(l>>16)); + fprintf(codefile, ".data4\t%ld\n", atol(str)); } con_float() { + static int been_here; + int sz = argval; - fatal("no reals"); + if (sz != 4 && sz != 8) { + fatal("bad fcon size"); + } + if (! been_here) { + been_here = 1; + fprintf(stderr,"warning: dummy floating constant(s)\n"); + } + while (sz) { + fprintf(codefile, ".data4 0 !dummy float\n"); + sz -= 4; + } } @@ -96,8 +106,8 @@ mes(type) word type ; { } char *segname[] = { - ".text", - ".data", - ".data", - ".bss" + ".sect .text", + ".sect .data", + ".sect .rom", + ".sect .bss" }; diff --git a/mach/z80/cg/mach.h b/mach/z80/cg/mach.h index 8648d8c7..60972b10 100644 --- a/mach/z80/cg/mach.h +++ b/mach/z80/cg/mach.h @@ -12,7 +12,7 @@ #define cst_fmt "%d" #define off_fmt "%d" -#define ilb_fmt "I%03x%x" +#define ilb_fmt "I%x_%x" #define dlb_fmt "_%d" #define hol_fmt "hol%d" @@ -20,11 +20,12 @@ #define arg_off "4+%d(bp)" #define hol_off "%d+hol%d" -#define con_cst(x) fprintf(codefile,".word\t%d\n",x) -#define con_ilb(x) fprintf(codefile,".word\t%s\n",x) -#define con_dlb(x) fprintf(codefile,".word\t%s\n",x) +#define con_cst(x) fprintf(codefile,".data2\t%d\n",x) +#define con_ilb(x) fprintf(codefile,".data2\t%s\n",x) +#define con_dlb(x) fprintf(codefile,".data2\t%s\n",x) -#define modhead "" +#define modhead ".sect .text; .sect .rom; .sect .data; .sect .bss\n" + +#define fmt_id(fs, ft) sprintf(ft, "_%s", fs) -#define id_first '_' #define BSS_INIT 0 From 3a83eeb52d3a210846b41b756c1643293b253810 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 9 Feb 1987 16:47:04 +0000 Subject: [PATCH 0783/1625] removed %0 stuff --- mach/6500/cg/mach.h | 2 +- mach/i86/cg/mach.h | 2 +- mach/m68k2/cg/mach.h | 2 +- mach/ns/ncg/mach.h | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mach/6500/cg/mach.h b/mach/6500/cg/mach.h index 1adf6677..d8068ad6 100644 --- a/mach/6500/cg/mach.h +++ b/mach/6500/cg/mach.h @@ -10,7 +10,7 @@ #define cst_fmt "%d" #define off_fmt "%d" -#define ilb_fmt "I%03x%x" +#define ilb_fmt "I%x_%x" #define dlb_fmt "_%d" #define hol_fmt "hol%d" diff --git a/mach/i86/cg/mach.h b/mach/i86/cg/mach.h index 8410ca9a..ec3b070e 100644 --- a/mach/i86/cg/mach.h +++ b/mach/i86/cg/mach.h @@ -12,7 +12,7 @@ #define cst_fmt "%d" #define off_fmt "%d" -#define ilb_fmt "I%03x%x" +#define ilb_fmt "I%x_%x" #define dlb_fmt "_%d" #define hol_fmt "hol%d" diff --git a/mach/m68k2/cg/mach.h b/mach/m68k2/cg/mach.h index 8a385ffb..521cb1ae 100644 --- a/mach/m68k2/cg/mach.h +++ b/mach/m68k2/cg/mach.h @@ -9,7 +9,7 @@ #define pop_fmt "(sp)+" #define cst_fmt "%ld" #define off_fmt "%ld" -#define ilb_fmt "I%03x%x" +#define ilb_fmt "I%x_%x" #define dlb_fmt "_%d" #define hol_fmt "hol%d" diff --git a/mach/ns/ncg/mach.h b/mach/ns/ncg/mach.h index 225c9dcd..cdb6ff5d 100644 --- a/mach/ns/ncg/mach.h +++ b/mach/ns/ncg/mach.h @@ -1,4 +1,4 @@ -/* $Header$ */ +$Header$ */ #define ex_ap(y) fprintf(codefile,".extern %s\n",y) #define in_ap(y) /* nothing */ @@ -10,7 +10,7 @@ #define cst_fmt "%ld" #define off_fmt "%ld" -#define ilb_fmt "I%03x%x" +#define ilb_fmt "I%x_%x" #define dlb_fmt "_%d" #define hol_fmt "hol%d" From f256688bac262adf00627129bab4e109b09c6c19 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 9 Feb 1987 16:49:13 +0000 Subject: [PATCH 0784/1625] Adapted to new assembler --- mach/i80/ncg/mach.c | 26 +++++++++++++++++--------- mach/i80/ncg/mach.h | 13 ++++++++----- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/mach/i80/ncg/mach.c b/mach/i80/ncg/mach.c index 4482e423..5a9ab636 100644 --- a/mach/i80/ncg/mach.c +++ b/mach/i80/ncg/mach.c @@ -41,19 +41,27 @@ con_part(sz,w) register sz; word w; { part_size += sz; } +long atol(); + con_mult(sz) word sz; { - long l; if (argval != 4) fatal("bad icon/ucon size"); - l = atol(str); - fprintf(codefile,".short\t%d\n",(int)l); - fprintf(codefile,".short\t%d\n",(int)(l>>16)); + fprintf(codefile,".data4\t%ld\n",atol(str)); } con_float() { + static int warning_given; + int i = argval; - fatal("no reals"); + if (!warning_given) { + fprintf(stderr, "warning: dummy floating point constant\n"); + warning_given = 1; + } + while (i > 0) { + fputs(".data4 0 !dummy float\n", codefile); + i -= 4; + } } @@ -93,8 +101,8 @@ mes(type) word type ; { } char *segname[] = { - ".text", - ".data", - ".data", - ".bss" + ".sect .text", + ".sect .data", + ".sect .rom", + ".sect .bss" }; diff --git a/mach/i80/ncg/mach.h b/mach/i80/ncg/mach.h index 87382854..151bd740 100644 --- a/mach/i80/ncg/mach.h +++ b/mach/i80/ncg/mach.h @@ -9,15 +9,18 @@ #define cst_fmt "%d" #define off_fmt "%d" -#define ilb_fmt "I%03x%x" +#define ilb_fmt "I%x_%x" #define dlb_fmt "_%d" #define hol_fmt "hol%d" #define hol_off "%d+hol%d" -#define con_cst(x) fprintf(codefile,".word\t%d\n",x) -#define con_ilb(x) fprintf(codefile,".word\t%s\n",x) -#define con_dlb(x) fprintf(codefile,".word\t%s\n",x) +#define con_cst(x) fprintf(codefile,".data2\t%d\n",x) +#define con_ilb(x) fprintf(codefile,".data2\t%s\n",x) +#define con_dlb(x) fprintf(codefile,".data2\t%s\n",x) + +#define fmt_id(sf, st) sprintf(st,"_%s",sf) + +#define modhead ".sect .text; .sect .rom; .sect .data; .sect .bss\n" -#define id_first '_' #define BSS_INIT 0 From ebb69da27958ca6d387ceab43c265f20cd90d897 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 9 Feb 1987 16:57:40 +0000 Subject: [PATCH 0785/1625] make to work on System V --- lang/cem/ctest/ctdivers/ops.c | 200 +++++++++++++++++----------------- 1 file changed, 100 insertions(+), 100 deletions(-) diff --git a/lang/cem/ctest/ctdivers/ops.c b/lang/cem/ctest/ctdivers/ops.c index bfc4e7f8..b7184bb4 100644 --- a/lang/cem/ctest/ctdivers/ops.c +++ b/lang/cem/ctest/ctdivers/ops.c @@ -48,41 +48,41 @@ ushift() { printf("Unsigned shifts by constants\n") ; u = 0150715 ; - printf(" u = %06o\n",u) ; - printf(" u>>0 %06o\n", u>>0 ) ; - printf(" u>>1 %06o\n", u>>1 ) ; - printf(" u>>2 %06o\n", u>>2 ) ; - printf(" u>>3 %06o\n", u>>3 ) ; - printf(" u>>4 %06o\n", u>>4 ) ; - printf(" u>>5 %06o\n", u>>5 ) ; - printf(" u>>6 %06o\n", u>>6 ) ; - printf(" u>>7 %06o\n", u>>7 ) ; - printf(" u>>8 %06o\n", u>>8 ) ; - printf(" u>>9 %06o\n", u>>9 ) ; - printf(" u>>10 %06o\n", u>>10 ) ; - printf(" u>>11 %06o\n", u>>11 ) ; - printf(" u>>12 %06o\n", u>>12 ) ; - printf(" u>>13 %06o\n", u>>13 ) ; - printf(" u>>14 %06o\n", u>>14 ) ; - printf(" u>>15 %06o\n", u>>15 ) ; - printf(" u>>16 %06o\n", u>>16 ) ; - printf(" u<<0 %06o\n", u<<0 ) ; - printf(" u<<1 %06o\n", u<<1 ) ; - printf(" u<<2 %06o\n", u<<2 ) ; - printf(" u<<3 %06o\n", u<<3 ) ; - printf(" u<<4 %06o\n", u<<4 ) ; - printf(" u<<5 %06o\n", u<<5 ) ; - printf(" u<<6 %06o\n", u<<6 ) ; - printf(" u<<7 %06o\n", u<<7 ) ; - printf(" u<<8 %06o\n", u<<8 ) ; - printf(" u<<9 %06o\n", u<<9 ) ; - printf(" u<<10 %06o\n", u<<10 ) ; - printf(" u<<11 %06o\n", u<<11 ) ; - printf(" u<<12 %06o\n", u<<12 ) ; - printf(" u<<13 %06o\n", u<<13 ) ; - printf(" u<<14 %06o\n", u<<14 ) ; - printf(" u<<15 %06o\n", u<<15 ) ; - printf(" u<<16 %06o\n", u<<16 ) ; + printf(" u = %6o\n",u) ; + printf(" u>>0 %6o\n", u>>0 ) ; + printf(" u>>1 %6o\n", u>>1 ) ; + printf(" u>>2 %6o\n", u>>2 ) ; + printf(" u>>3 %6o\n", u>>3 ) ; + printf(" u>>4 %6o\n", u>>4 ) ; + printf(" u>>5 %6o\n", u>>5 ) ; + printf(" u>>6 %6o\n", u>>6 ) ; + printf(" u>>7 %6o\n", u>>7 ) ; + printf(" u>>8 %6o\n", u>>8 ) ; + printf(" u>>9 %6o\n", u>>9 ) ; + printf(" u>>10 %6o\n", u>>10 ) ; + printf(" u>>11 %6o\n", u>>11 ) ; + printf(" u>>12 %6o\n", u>>12 ) ; + printf(" u>>13 %6o\n", u>>13 ) ; + printf(" u>>14 %6o\n", u>>14 ) ; + printf(" u>>15 %6o\n", u>>15 ) ; + printf(" u>>16 %6o\n", u>>16 ) ; + printf(" u<<0 %6o\n", u<<0 ) ; + printf(" u<<1 %6o\n", u<<1 ) ; + printf(" u<<2 %6o\n", u<<2 ) ; + printf(" u<<3 %6o\n", u<<3 ) ; + printf(" u<<4 %6o\n", u<<4 ) ; + printf(" u<<5 %6o\n", u<<5 ) ; + printf(" u<<6 %6o\n", u<<6 ) ; + printf(" u<<7 %6o\n", u<<7 ) ; + printf(" u<<8 %6o\n", u<<8 ) ; + printf(" u<<9 %6o\n", u<<9 ) ; + printf(" u<<10 %6o\n", u<<10 ) ; + printf(" u<<11 %6o\n", u<<11 ) ; + printf(" u<<12 %6o\n", u<<12 ) ; + printf(" u<<13 %6o\n", u<<13 ) ; + printf(" u<<14 %6o\n", u<<14 ) ; + printf(" u<<15 %6o\n", u<<15 ) ; + printf(" u<<16 %6o\n", u<<16 ) ; } lshift() { @@ -90,71 +90,71 @@ lshift() { printf("Long shifts by constants\n") ; ll = 400000L - 0532 ; - printf(" ll = %011O\n",ll) ; - printf(" ll>>0 %011O\n", ll>>0 ) ; - printf(" ll>>1 %011O\n", ll>>1 ) ; - printf(" ll>>2 %011O\n", ll>>2 ) ; - printf(" ll>>3 %011O\n", ll>>3 ) ; - printf(" ll>>4 %011O\n", ll>>4 ) ; - printf(" ll>>5 %011O\n", ll>>5 ) ; - printf(" ll>>6 %011O\n", ll>>6 ) ; - printf(" ll>>7 %011O\n", ll>>7 ) ; - printf(" ll>>8 %011O\n", ll>>8 ) ; - printf(" ll>>9 %011O\n", ll>>9 ) ; - printf(" ll>>10 %011O\n", ll>>10 ) ; - printf(" ll>>11 %011O\n", ll>>11 ) ; - printf(" ll>>12 %011O\n", ll>>12 ) ; - printf(" ll>>13 %011O\n", ll>>13 ) ; - printf(" ll>>14 %011O\n", ll>>14 ) ; - printf(" ll>>15 %011O\n", ll>>15 ) ; - printf(" ll>>16 %011O\n", ll>>16 ) ; - printf(" ll>>17 %011O\n", ll>>17 ) ; - printf(" ll>>18 %011O\n", ll>>18 ) ; - printf(" ll>>19 %011O\n", ll>>19 ) ; - printf(" ll>>20 %011O\n", ll>>20 ) ; - printf(" ll>>21 %011O\n", ll>>21 ) ; - printf(" ll>>22 %011O\n", ll>>22 ) ; - printf(" ll>>23 %011O\n", ll>>23 ) ; - printf(" ll>>24 %011O\n", ll>>24 ) ; - printf(" ll>>25 %011O\n", ll>>25 ) ; - printf(" ll>>26 %011O\n", ll>>26 ) ; - printf(" ll>>27 %011O\n", ll>>27 ) ; - printf(" ll>>28 %011O\n", ll>>28 ) ; - printf(" ll>>29 %011O\n", ll>>29 ) ; - printf(" ll>>30 %011O\n", ll>>30 ) ; - printf(" ll>>31 %011O\n", ll>>31 ) ; + printf(" ll = %11lo\n",ll) ; + printf(" ll>>0 %11lo\n", ll>>0 ) ; + printf(" ll>>1 %11lo\n", ll>>1 ) ; + printf(" ll>>2 %11lo\n", ll>>2 ) ; + printf(" ll>>3 %11lo\n", ll>>3 ) ; + printf(" ll>>4 %11lo\n", ll>>4 ) ; + printf(" ll>>5 %11lo\n", ll>>5 ) ; + printf(" ll>>6 %11lo\n", ll>>6 ) ; + printf(" ll>>7 %11lo\n", ll>>7 ) ; + printf(" ll>>8 %11lo\n", ll>>8 ) ; + printf(" ll>>9 %11lo\n", ll>>9 ) ; + printf(" ll>>10 %11lo\n", ll>>10 ) ; + printf(" ll>>11 %11lo\n", ll>>11 ) ; + printf(" ll>>12 %11lo\n", ll>>12 ) ; + printf(" ll>>13 %11lo\n", ll>>13 ) ; + printf(" ll>>14 %11lo\n", ll>>14 ) ; + printf(" ll>>15 %11lo\n", ll>>15 ) ; + printf(" ll>>16 %11lo\n", ll>>16 ) ; + printf(" ll>>17 %11lo\n", ll>>17 ) ; + printf(" ll>>18 %11lo\n", ll>>18 ) ; + printf(" ll>>19 %11lo\n", ll>>19 ) ; + printf(" ll>>20 %11lo\n", ll>>20 ) ; + printf(" ll>>21 %11lo\n", ll>>21 ) ; + printf(" ll>>22 %11lo\n", ll>>22 ) ; + printf(" ll>>23 %11lo\n", ll>>23 ) ; + printf(" ll>>24 %11lo\n", ll>>24 ) ; + printf(" ll>>25 %11lo\n", ll>>25 ) ; + printf(" ll>>26 %11lo\n", ll>>26 ) ; + printf(" ll>>27 %11lo\n", ll>>27 ) ; + printf(" ll>>28 %11lo\n", ll>>28 ) ; + printf(" ll>>29 %11lo\n", ll>>29 ) ; + printf(" ll>>30 %11lo\n", ll>>30 ) ; + printf(" ll>>31 %11lo\n", ll>>31 ) ; ll = 1 ; - printf(" ll<<0 %011O\n", ll<<0 ) ; - printf(" ll<<1 %011O\n", ll<<1 ) ; - printf(" ll<<2 %011O\n", ll<<2 ) ; - printf(" ll<<3 %011O\n", ll<<3 ) ; - printf(" ll<<4 %011O\n", ll<<4 ) ; - printf(" ll<<5 %011O\n", ll<<5 ) ; - printf(" ll<<6 %011O\n", ll<<6 ) ; - printf(" ll<<7 %011O\n", ll<<7 ) ; - printf(" ll<<8 %011O\n", ll<<8 ) ; - printf(" ll<<9 %011O\n", ll<<9 ) ; - printf(" ll<<10 %011O\n", ll<<10 ) ; - printf(" ll<<11 %011O\n", ll<<11 ) ; - printf(" ll<<12 %011O\n", ll<<12 ) ; - printf(" ll<<13 %011O\n", ll<<13 ) ; - printf(" ll<<14 %011O\n", ll<<14 ) ; - printf(" ll<<15 %011O\n", ll<<15 ) ; - printf(" ll<<16 %011O\n", ll<<16 ) ; - printf(" ll<<17 %011O\n", ll<<17 ) ; - printf(" ll<<18 %011O\n", ll<<18 ) ; - printf(" ll<<19 %011O\n", ll<<19 ) ; - printf(" ll<<20 %011O\n", ll<<20 ) ; - printf(" ll<<21 %011O\n", ll<<21 ) ; - printf(" ll<<22 %011O\n", ll<<22 ) ; - printf(" ll<<23 %011O\n", ll<<23 ) ; - printf(" ll<<24 %011O\n", ll<<24 ) ; - printf(" ll<<25 %011O\n", ll<<25 ) ; - printf(" ll<<26 %011O\n", ll<<26 ) ; - printf(" ll<<27 %011O\n", ll<<27 ) ; - printf(" ll<<28 %011O\n", ll<<28 ) ; - printf(" ll<<29 %011O\n", ll<<29 ) ; - printf(" ll<<30 %011O\n", ll<<30 ) ; + printf(" ll<<0 %11lo\n", ll<<0 ) ; + printf(" ll<<1 %11lo\n", ll<<1 ) ; + printf(" ll<<2 %11lo\n", ll<<2 ) ; + printf(" ll<<3 %11lo\n", ll<<3 ) ; + printf(" ll<<4 %11lo\n", ll<<4 ) ; + printf(" ll<<5 %11lo\n", ll<<5 ) ; + printf(" ll<<6 %11lo\n", ll<<6 ) ; + printf(" ll<<7 %11lo\n", ll<<7 ) ; + printf(" ll<<8 %11lo\n", ll<<8 ) ; + printf(" ll<<9 %11lo\n", ll<<9 ) ; + printf(" ll<<10 %11lo\n", ll<<10 ) ; + printf(" ll<<11 %11lo\n", ll<<11 ) ; + printf(" ll<<12 %11lo\n", ll<<12 ) ; + printf(" ll<<13 %11lo\n", ll<<13 ) ; + printf(" ll<<14 %11lo\n", ll<<14 ) ; + printf(" ll<<15 %11lo\n", ll<<15 ) ; + printf(" ll<<16 %11lo\n", ll<<16 ) ; + printf(" ll<<17 %11lo\n", ll<<17 ) ; + printf(" ll<<18 %11lo\n", ll<<18 ) ; + printf(" ll<<19 %11lo\n", ll<<19 ) ; + printf(" ll<<20 %11lo\n", ll<<20 ) ; + printf(" ll<<21 %11lo\n", ll<<21 ) ; + printf(" ll<<22 %11lo\n", ll<<22 ) ; + printf(" ll<<23 %11lo\n", ll<<23 ) ; + printf(" ll<<24 %11lo\n", ll<<24 ) ; + printf(" ll<<25 %11lo\n", ll<<25 ) ; + printf(" ll<<26 %11lo\n", ll<<26 ) ; + printf(" ll<<27 %11lo\n", ll<<27 ) ; + printf(" ll<<28 %11lo\n", ll<<28 ) ; + printf(" ll<<29 %11lo\n", ll<<29 ) ; + printf(" ll<<30 %11lo\n", ll<<30 ) ; } uadd() { unsigned u ; @@ -162,6 +162,6 @@ uadd() { u = 32760 ; for ( i=0 ; i<=16 ; ++i ) { - printf("%2d %06o\n",i,u+i) ; + printf("%2d %6o\n",i,u+i) ; } } From 571a8d051cb87dcc47e8c198abc03053d07bbd8f Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 9 Feb 1987 17:00:23 +0000 Subject: [PATCH 0786/1625] made to work on system V --- lang/cem/ctest/ctinit/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/cem/ctest/ctinit/init.c b/lang/cem/ctest/ctinit/init.c index 48b3779f..468c1e1e 100644 --- a/lang/cem/ctest/ctinit/init.c +++ b/lang/cem/ctest/ctinit/init.c @@ -187,7 +187,7 @@ long lo6 = ( 0==1 ? -1L : 1L ) ; plong() { printf("long\n\n") ; - printf("lo1\t%D\nlo2\t%D\nlo3\t%D\nlo4\t%D\nlo5\t%D\nlo6\t%D\n\n", + printf("lo1\t%ld\nlo2\t%ld\nlo3\t%ld\nlo4\t%ld\nlo5\t%ld\nlo6\t%ld\n\n", lo1,lo2,lo3,lo4,lo5,lo6 ) ; } From e8c7db81ad906638d026942378a5a237e7da0032 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 9 Feb 1987 17:06:20 +0000 Subject: [PATCH 0787/1625] replaced some %D's by %ld --- util/ass/ass50.c | 2 +- util/ass/ass60.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/util/ass/ass50.c b/util/ass/ass50.c index 6b3663dc..111b6dda 100644 --- a/util/ass/ass50.c +++ b/util/ass/ass50.c @@ -66,7 +66,7 @@ pass_5() { #ifdef JOHAN if ( jflag ) { extern char em_mnem[][4] ; - printf("%s %D\n",em_mnem[ope],off1) ; + printf("%s %ld\n",em_mnem[ope],off1) ; } #endif diff --git a/util/ass/ass60.c b/util/ass/ass60.c index 2a6e1c15..a02efcd2 100644 --- a/util/ass/ass60.c +++ b/util/ass/ass60.c @@ -87,7 +87,7 @@ dump(n) if (d_flag==0) return; if ( (n==0 && d_flag) || (n==4 && d_flag>=2) || (n<100 && d_flag>=3) ) { printf("\nEM1-assembler ***** pass %1d complete:\n",n); - printf("current size %D\n",prog_size) ; + printf("current size %ld\n",prog_size) ; printf(" %9.9s%9.9s%14.14s%8.8s%8.8s\n", "instr_nr", "type1","addr1","length","format"); for (ln = pstate.s_fline ; ln ; From e4cdbe938714b999afb48203e0981c37b7047a0d Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 9 Feb 1987 17:10:29 +0000 Subject: [PATCH 0788/1625] replaced a %04x --- util/ack/ack.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/ack/ack.h b/util/ack/ack.h index 0153e994..4a2c98f4 100644 --- a/util/ack/ack.h +++ b/util/ack/ack.h @@ -7,7 +7,7 @@ /****************************************************************************/ #define FRONTENDS "fe" /* The front-end definitions */ -#define TMPNAME "Ack%04x" /* Naming of temp. files */ +#define TMPNAME "Ack_%x" /* Naming of temp. files */ /****************************************************************************/ /* Internal mnemonics, should not be tinkered with */ From 3aefa51e6301664143240262853337cca0293c21 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 9 Feb 1987 17:28:22 +0000 Subject: [PATCH 0789/1625] replaced some %D's --- util/ego/cs/cs_avail.c | 2 +- util/ego/cs/cs_debug.c | 12 ++++++------ util/ego/cs/cs_elim.c | 2 +- util/ego/ra/ra.c | 6 +++--- util/ego/ra/ra_profits.c | 4 ++-- util/ego/share/show.c | 8 ++++---- util/ego/ud/ud.c | 4 ++-- util/ego/ud/ud_copy.c | 8 ++++---- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/util/ego/cs/cs_avail.c b/util/ego/cs/cs_avail.c index 930b592f..a7c4039f 100644 --- a/util/ego/cs/cs_avail.c +++ b/util/ego/cs/cs_avail.c @@ -101,7 +101,7 @@ STATIC entity_p result_local(size, l) if (INSTR(l)==op_stl && size==ws || INSTR(l)==op_sdl && size==2*ws) { enp = getentity(l, &dummy); if (is_regvar(enp->en_loc)) { - OUTTRACE("save local found, %D(LB)", enp->en_loc); + OUTTRACE("save local found, %ld(LB)", enp->en_loc); return enp; } } diff --git a/util/ego/cs/cs_debug.c b/util/ego/cs/cs_debug.c index 0d4cdbdf..7de5bd2b 100644 --- a/util/ego/cs/cs_debug.c +++ b/util/ego/cs/cs_debug.c @@ -35,7 +35,7 @@ STATIC showinstr(lnp) fprintf(stderr," %d", OBJ(lnp)->o_id); break; case OPOFFSET: - fprintf(stderr," %D", OFFSET(lnp)); + fprintf(stderr," %ld", OFFSET(lnp)); break; default: fprintf(stderr," ?"); @@ -114,26 +114,26 @@ OUTENTITIES() register entity_p rep = en_elem(i); fprintf(stderr,"%s,", enkinds[rep->en_kind]); - fprintf(stderr,"size %D,", rep->en_size); + fprintf(stderr,"size %ld,", rep->en_size); fprintf(stderr,"valno %d,", rep->en_vn); switch (rep->en_kind) { case ENCONST: - fprintf(stderr,"$%D\n", rep->en_val); + fprintf(stderr,"$%ld\n", rep->en_val); break; case ENLOCAL: case ENALOCAL: - fprintf(stderr,"%D(LB)\n", rep->en_loc); + fprintf(stderr,"%ld(LB)\n", rep->en_loc); break; case ENINDIR: fprintf(stderr,"*%d\n", rep->en_ind); break; case ENOFFSETTED: case ENAOFFSETTED: - fprintf(stderr,"%D(%d)\n", rep->en_off, rep->en_base); + fprintf(stderr,"%ld(%d)\n", rep->en_off, rep->en_base); break; case ENALOCBASE: case ENAARGBASE: - fprintf(stderr,"%D levels\n", rep->en_levels); + fprintf(stderr,"%ld levels\n", rep->en_levels); break; case ENARRELEM: fprintf(stderr,"%d[%d], ",rep->en_arbase,rep->en_index); diff --git a/util/ego/cs/cs_elim.c b/util/ego/cs/cs_elim.c index 33f295fe..4312e811 100644 --- a/util/ego/cs/cs_elim.c +++ b/util/ego/cs/cs_elim.c @@ -270,7 +270,7 @@ eliminate(pp) if (ravp->av_saveloc != (entity_p) 0) { tmp = ravp->av_saveloc->en_loc; mes = find_mesreg(tmp); - OUTVERBOSE("re-using %D(LB)", tmp); + OUTVERBOSE("re-using %ld(LB)", tmp); } else { tmp = tmplocal(pp, ravp->av_size); mes = gen_mesreg(tmp, ravp, pp); diff --git a/util/ego/ra/ra.c b/util/ego/ra/ra.c index 48df6d09..336212f7 100644 --- a/util/ego/ra/ra.c +++ b/util/ego/ra/ra.c @@ -436,7 +436,7 @@ print_items(items,p) printf("id of external = %d\n", item->i_t.it_obj->o_id); } else { - printf("offset = %D\n", + printf("offset = %ld\n", item->i_t.it_off); } printf("regtype = %s\n",str_regtypes[item->it_regtype]); @@ -476,7 +476,7 @@ print_allocs(list) fprintf(stderr,"id = %d]\n", item->i_t.it_proc->p_id); break; default: - fprintf(stderr,"offset = %D]\n", item->i_t.it_off); + fprintf(stderr,"offset = %ld]\n", item->i_t.it_off); } fprintf(stderr,"#usages(static) = %d\n",al->al_susecount); fprintf(stderr,"#usages(dyn) = %d\n",al->al_dusecount); @@ -494,7 +494,7 @@ print_allocs(list) } fprintf(stderr,"} \n"); fprintf(stderr,"profits = %d\n",al->al_profits); - fprintf(stderr,"dummy local = %D\n",al->al_dummy); + fprintf(stderr,"dummy local = %ld\n",al->al_dummy); fprintf(stderr,"regnr = %d\n",al->al_regnr); } } diff --git a/util/ego/ra/ra_profits.c b/util/ego/ra/ra_profits.c index 3c725a03..66e72b26 100644 --- a/util/ego/ra/ra_profits.c +++ b/util/ego/ra/ra_profits.c @@ -90,7 +90,7 @@ allocscore(itemtyp,localtyp,size,off,totyp,time_out,space_out) *time_out = (m == (cond_p) 0 ? -1 : map_value(m,off,TRUE)); *space_out = (m == (cond_p) 0 ? -1 : map_value(m,off,FALSE)); /* - printf("itemtyp = %d, localtyp = %d off = %D\n",itemtyp,localtyp,off); + printf("itemtyp = %d, localtyp = %d off = %ld\n",itemtyp,localtyp,off); printf("ALLOCSCORE = (%d,%d)\n",*time_out,*space_out); */ } @@ -126,7 +126,7 @@ opening_cost(itemtyp,localtyp,off,time_out,space_out) *time_out = (m == (cond_p) 0 ? 1000 : map_value(m,off,TRUE)); *space_out = (m == (cond_p) 0 ? 1000 : map_value(m,off,FALSE)); /* - printf("itemtyp = %d, localtyp = %d off = %D\n",itemtyp,localtyp,off); + printf("itemtyp = %d, localtyp = %d off = %ld\n",itemtyp,localtyp,off); printf("OPEN_COST = (%d,%d)\n",*time_out,*space_out); */ } diff --git a/util/ego/share/show.c b/util/ego/share/show.c index 684ac755..a2835bc8 100644 --- a/util/ego/share/show.c +++ b/util/ego/share/show.c @@ -28,10 +28,10 @@ extern byte em_flag[]; #define space1() printf(" ") char format[] = " %-11s%d\n"; -char lformat[] = " %-11s%D\n"; +char lformat[] = " %-11s%ld\n"; char sformat[] = " %-10s%s\n"; char dformat[] = " %-11s%d\n"; -char oformat[] = " %-11s%D\n"; +char oformat[] = " %-11s%ld\n"; @@ -263,7 +263,7 @@ showinstr() printf(" *%d",getshort()); break; case OPOFFSET: - printf(" %D", getoff()); + printf(" %ld", getoff()); break; case OPLIST: arglist(); @@ -296,7 +296,7 @@ arglist() printf(" *%d",getshort()); break; case ARGOFF: - printf(" %D", getoff()); + printf(" %ld", getoff()); break; case ARGICN: case ARGUCN: diff --git a/util/ego/ud/ud.c b/util/ego/ud/ud.c index 7616a5e6..4c9bb21d 100644 --- a/util/ego/ud/ud.c +++ b/util/ego/ud/ud.c @@ -266,7 +266,7 @@ pr_localtab() { for (i = 1; i <= nrlocals; i++) { lc = locals[i]; printf("LOCAL %d\n",i); - printf(" offset= %D\n",lc->lc_off); + printf(" offset= %ld\n",lc->lc_off); printf(" size= %d\n",lc->lc_size); printf(" flags= %d\n",lc->lc_flags); } @@ -305,7 +305,7 @@ pr_defs() printf("%d\n",SHORT(l)); break; case OPOFFSET: - printf("%D\n",OFFSET(l)); + printf("%ld\n",OFFSET(l)); break; case OPOBJECT: printf("%d\n",OBJ(l)->o_id); diff --git a/util/ego/ud/ud_copy.c b/util/ego/ud/ud_copy.c index 3e351f6e..401dcc0c 100644 --- a/util/ego/ud/ud_copy.c +++ b/util/ego/ud/ud_copy.c @@ -323,21 +323,21 @@ fold_var(old,new,b) if (TYPE(old) == OPOBJECT) { printf("global var."); } else { - printf("local var. with off. %D",off_set(old)); + printf("local var. with off. %ld",off_set(old)); find_local(off_set(old),&nr,&ok); assert(ok); loc = locals[nr]; - printf(",score %D",loc->lc_score); + printf(",score %ld",loc->lc_score); } printf(" replaced by "); if (TYPE(new) == OPOBJECT) { printf("global var."); } else { - printf("local var. with off. %D",off_set(new)); + printf("local var. with off. %ld",off_set(new)); find_local(off_set(new),&nr,&ok); assert(ok); loc = locals[nr]; - printf(",score %D",loc->lc_score); + printf(",score %ld",loc->lc_score); } printf("\n"); END DEBUG */ From d611ec64edd4659ccfb31158541d4a16aa1e1b73 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 9 Feb 1987 17:31:25 +0000 Subject: [PATCH 0790/1625] replaced a %D --- util/ego/cj/cj.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/ego/cj/cj.c b/util/ego/cj/cj.c index bc4a250b..b870abb6 100644 --- a/util/ego/cj/cj.c +++ b/util/ego/cj/cj.c @@ -334,7 +334,7 @@ STATIC showinstr(lnp) line_p lnp; { case OPOBJECT: printf(" %d", OBJ(lnp)->o_id); break; case OPOFFSET: - printf(" %D", OFFSET(lnp)); break; + printf(" %ld", OFFSET(lnp)); break; default: printf(" ?"); break; } From 4b6cb7d86c066ddab330436bf61c41e64e3a298b Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 9 Feb 1987 17:41:25 +0000 Subject: [PATCH 0791/1625] removed some %0 stuff --- util/ncgg/output.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/util/ncgg/output.c b/util/ncgg/output.c index 260b834b..853b2bc6 100644 --- a/util/ncgg/output.c +++ b/util/ncgg/output.c @@ -387,7 +387,8 @@ outenodes() { outstrings() { register i; - register char *p,c; + register char *p; + register int c; extern char * filename; if (tabledebug) @@ -396,8 +397,14 @@ outstrings() { for(i=0;i>6) + '0', ((c&070)>>3)+'0', + (c&07)+'0'); + } + else fprintf(ctable, "%c",c); + } fprintf(ctable,"\",\n"); } fprintf(ctable,"};\n\n"); @@ -411,7 +418,7 @@ outsets() { for (sp=l_sets;sp< &l_sets[nsets]; sp++) { fprintf(ctable,"{%3d,{",sp->set_size); for (i=0;iset_val[i]&0xFFFF); + fprintf(ctable,"0x%x,",sp->set_val[i]&0xFFFF); fprintf(ctable,"}},\n"); } fprintf(ctable,"};\n\n"); @@ -496,7 +503,7 @@ outproplists() { register regno; for(propno=0;propno Date: Mon, 9 Feb 1987 17:55:46 +0000 Subject: [PATCH 0792/1625] Added local optimization of lin to lni. --- modules/src/em_opt/mkcalls.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/modules/src/em_opt/mkcalls.c b/modules/src/em_opt/mkcalls.c index 71bf9bf3..69c70a60 100644 --- a/modules/src/em_opt/mkcalls.c +++ b/modules/src/em_opt/mkcalls.c @@ -4,6 +4,8 @@ static char rcsid[] = "$Header$"; #include "nopt.h" +static Linenumber = 0; /* Local optimization of lin to lni if possible */ + OO_mkcalls(p) struct instr *p; { @@ -108,6 +110,7 @@ OO_mkcalls(p) case op_fif: O_fif(p->acst); break; case op_fil: + Linenumber = 0; if(p->argtype==nof_ptyp) O_fil_dlb(p->adlb, p->anoff); else O_fil_dnam(p->adnam, p->asoff); break; case op_gto: @@ -125,6 +128,7 @@ OO_mkcalls(p) case op_ior: O_ior(p->acst); break; case op_lab: + Linenumber = 0; O_df_ilb(p->alab); break; case op_lae: if(p->argtype==nof_ptyp) O_lae_dlb(p->adlb, p->anoff); @@ -149,9 +153,18 @@ OO_mkcalls(p) case op_lim: O_lim(); break; case op_lin: - O_lin(p->acst); break; + if(Linenumber && p->acst == ++Linenumber) { + O_lni(); + } + else { + O_lin(p->acst); + Linenumber = p->acst; + } + break; case op_lni: - O_lni(); break; + O_lni(); + Linenumber++; + break; case op_loc: O_loc(p->acst); break; case op_loe: From 01fa23d1dac45586046a286ea48baf75854880f2 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 9 Feb 1987 22:48:14 +0000 Subject: [PATCH 0793/1625] replaced some more %D's --- lang/cem/ctest/ctinit/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/cem/ctest/ctinit/init.c b/lang/cem/ctest/ctinit/init.c index 468c1e1e..1a99d28b 100644 --- a/lang/cem/ctest/ctinit/init.c +++ b/lang/cem/ctest/ctinit/init.c @@ -237,7 +237,7 @@ pstruct() { st1.s_ca[1],sta[0].s_ca[1],sta[1].s_ca[1],sta[2].s_ca[1]) ; printf("s_ca[2]\t%15d%15d%15d%15d\n", st1.s_ca[2],sta[0].s_ca[2],sta[1].s_ca[2],sta[2].s_ca[2]) ; - printf("s_l\t%15D%15D%15D%15D\n", + printf("s_l\t%15ld%15ld%15ld%15ld\n", st1.s_l,sta[0].s_l,sta[1].s_l,sta[2].s_l) ; #ifndef NOFLOAT printf("s_f\t %13e %13e %13e %13e\n\n", From f7690cec10c18d46d53fc35de0c6c53c9132101e Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 9 Feb 1987 23:19:42 +0000 Subject: [PATCH 0794/1625] many changes: fixes and efficiency-oriented --- lang/cem/cemcom/Makefile.erik | 4 ++-- lang/cem/cemcom/Parameters | 4 ++-- lang/cem/cemcom/Version.c | 1 + lang/cem/cemcom/arith.c | 30 ++++++++++++++++++++----- lang/cem/cemcom/asm.c | 4 ++-- lang/cem/cemcom/cem.c | 4 +--- lang/cem/cemcom/cemcom.1 | 24 +++++++------------- lang/cem/cemcom/ch7.c | 4 ++-- lang/cem/cemcom/code.c | 31 ++++++++++++++++++++++++-- lang/cem/cemcom/conversion.c | 12 +++++----- lang/cem/cemcom/cstoper.c | 2 +- lang/cem/cemcom/declar.g | 41 ++++++++++++++--------------------- lang/cem/cemcom/eval.c | 23 +++++--------------- lang/cem/cemcom/expr.c | 22 ++++++++++--------- lang/cem/cemcom/expression.g | 21 +++++------------- lang/cem/cemcom/init.c | 2 +- lang/cem/cemcom/input.c | 2 +- lang/cem/cemcom/label.c | 6 ++--- lang/cem/cemcom/macro.str | 8 +++++++ lang/cem/cemcom/main.c | 21 +++++++++++------- lang/cem/cemcom/options.c | 33 ++++++++++++++++------------ lang/cem/cemcom/program.g | 14 +++++------- lang/cem/cemcom/replace.c | 39 +++++++++++++++++++++++---------- lang/cem/cemcom/scan.c | 2 +- lang/cem/cemcom/stack.c | 7 +++--- lang/cem/cemcom/statement.g | 3 +-- 26 files changed, 200 insertions(+), 164 deletions(-) create mode 100644 lang/cem/cemcom/Version.c diff --git a/lang/cem/cemcom/Makefile.erik b/lang/cem/cemcom/Makefile.erik index c0eba725..47c1dc49 100644 --- a/lang/cem/cemcom/Makefile.erik +++ b/lang/cem/cemcom/Makefile.erik @@ -236,10 +236,10 @@ input.o: file_info.h input.h inputtype.h nopp.h domacro.o: LLlex.h Lpars.h arith.h assert.h botch_free.h class.h debug.h file_info.h idf.h idfsize.h ifdepth.h input.h interface.h macro.h nofloat.h nopp.h nparams.h parbufsize.h spec_arith.h textsize.h replace.o: LLlex.h arith.h assert.h class.h debug.h file_info.h idf.h input.h interface.h macro.h nofloat.h nopp.h pathlength.h spec_arith.h static.h strsize.h init.o: class.h idf.h interface.h macro.h nopp.h -options.o: align.h arith.h botch_free.h class.h idf.h idfsize.h macro.h maxincl.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h use_tmp.h +options.o: align.h arith.h botch_free.h class.h dataflow.h idf.h idfsize.h macro.h maxincl.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h use_tmp.h scan.o: class.h idf.h input.h interface.h lapbuf.h macro.h nopp.h nparams.h skip.o: LLlex.h arith.h class.h file_info.h input.h interface.h nofloat.h nopp.h spec_arith.h -stack.o: Lpars.h arith.h botch_free.h debug.h def.h idf.h level.h mes.h nobitfield.h nofloat.h nopp.h spec_arith.h stack.h struct.h type.h use_tmp.h +stack.o: Lpars.h arith.h botch_free.h debug.h def.h idf.h level.h mes.h nobitfield.h nofloat.h nopp.h spec_arith.h stack.h struct.h type.h type.o: Lpars.h align.h arith.h botch_free.h def.h idf.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h type.h ch7mon.o: Lpars.h arith.h botch_free.h def.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h label.o: Lpars.h arith.h def.h idf.h label.h level.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h diff --git a/lang/cem/cemcom/Parameters b/lang/cem/cemcom/Parameters index 9e1cf547..00972e5f 100644 --- a/lang/cem/cemcom/Parameters +++ b/lang/cem/cemcom/Parameters @@ -13,7 +13,7 @@ !File: idfsize.h -#define IDFSIZE 30 /* maximum significant length of an identifier */ +#define IDFSIZE 64 /* maximum significant length of an identifier */ !File: numsize.h @@ -86,7 +86,7 @@ !File: debug.h -#define DEBUG 1 /* perform various self-tests */ +#undef DEBUG 1 /* perform various self-tests */ !File: use_tmp.h diff --git a/lang/cem/cemcom/Version.c b/lang/cem/cemcom/Version.c new file mode 100644 index 00000000..45b43e4c --- /dev/null +++ b/lang/cem/cemcom/Version.c @@ -0,0 +1 @@ +static char Version[] = "ACK CEM compiler Version 3.1"; diff --git a/lang/cem/cemcom/arith.c b/lang/cem/cemcom/arith.c index 62cfae76..a7304e38 100644 --- a/lang/cem/cemcom/arith.c +++ b/lang/cem/cemcom/arith.c @@ -124,6 +124,7 @@ ch76pointer(expp, oper, tp) int any2arith(expp, oper) register struct expr **expp; + register int oper; { /* Turns any expression into int_type, long_type or double_type. @@ -211,14 +212,31 @@ arith2arith(tp, oper, expr) int int2int(expp, tp) register struct expr **expp; - struct type *tp; + register struct type *tp; { /* The expression *expp, which is of some integral type, is converted to the integral type tp. */ if (is_cp_cst(*expp)) { + register struct type *tp1 = (*expp)->ex_type; + (*expp)->ex_type = tp; + if (! tp1->tp_unsigned && tp->tp_unsigned) { + /* Avoid "unreal" overflow warnings, such as + caused by f.i.: + unsigned int x = ~0; + unsigned int y = -1; + */ + extern long full_mask[]; + long remainder = (*expp)->VL_VALUE & + ~full_mask[tp->tp_size]; + + if (remainder == 0 || + remainder == ~full_mask[tp->tp_size]) { + (*expp)->VL_VALUE &= ~remainder; + } + } cut_size(*expp); } else { @@ -230,7 +248,7 @@ int2int(expp, tp) #ifndef NOFLOAT int int2float(expp, tp) - struct expr **expp; + register struct expr **expp; struct type *tp; { /* The expression *expp, which is of some integral type, is @@ -255,7 +273,7 @@ float2int(expp, tp) } float2float(expp, tp) - struct expr **expp; + register struct expr **expp; struct type *tp; { /* The expression *expp, which is of some floating type, is @@ -273,7 +291,7 @@ float2float(expp, tp) #endif NOFLOAT array2pointer(expp) - struct expr **expp; + register struct expr **expp; { /* The expression, which must be an array, is converted to a pointer. @@ -326,7 +344,7 @@ opnd2logical(expp, oper) register struct expr **expp; int oper; { - register int fund; + int fund; if ((*expp)->ex_type->tp_fund == FUNCTION) function2pointer(expp); @@ -478,7 +496,7 @@ field2arith(expp) ch7bin(expp, '&', intexpr(fd->fd_mask, INT)); } else { /* take care of the sign bit: sign extend if needed */ - register arith bits_in_type = atype->tp_size * 8; + arith bits_in_type = atype->tp_size * 8; ch7bin(expp, LEFT, intexpr(bits_in_type - fd->fd_width - fd->fd_shift, diff --git a/lang/cem/cemcom/asm.c b/lang/cem/cemcom/asm.c index 56f02e41..8f872f86 100644 --- a/lang/cem/cemcom/asm.c +++ b/lang/cem/cemcom/asm.c @@ -1,12 +1,12 @@ /* $Header$ */ /* A S M */ +/*ARGSUSED*/ code_asm(s, l) char *s; int l; { /* 'asm' '(' string ')' ';' */ - s = s; l = l; - error("\"asm instruction not implemented", s); + error("\"asm\" instruction not implemented"); } diff --git a/lang/cem/cemcom/cem.c b/lang/cem/cemcom/cem.c index 1607dfb5..172c52e6 100644 --- a/lang/cem/cemcom/cem.c +++ b/lang/cem/cemcom/cem.c @@ -166,6 +166,7 @@ main(argc, argv) set_traps(trap); ProgCall = *argv++; + append(&CEM_FLAGS, "-L"); while (--argc > 0) { if (*(str = *argv++) != '-') { append(&SRCFILES, str); @@ -269,9 +270,6 @@ main(argc, argv) case 'O': append(&O_FLAGS, "-O"); break; - case 'p': - append(&CEM_FLAGS, "-p"); - break; case 'R': if (str[2] == '\0') append(&CEM_FLAGS, str); diff --git a/lang/cem/cemcom/cemcom.1 b/lang/cem/cemcom/cemcom.1 index 87c7f766..703be456 100644 --- a/lang/cem/cemcom/cemcom.1 +++ b/lang/cem/cemcom/cemcom.1 @@ -16,23 +16,12 @@ When the preprocessor is invoked to run stand-alone, \fIdestination\fP needs not be specified. .br \fIOptions\fP is a, possibly empty, sequence of the following combinations: -.IP \fB\-C\fR -list the sequence of input tokens while maintaining the comments. .IP \fB\-D\fIname\fR=\fItext\fR .br define \fIname\fR as a macro with \fItext\fR as its replacement text. .IP \fB\-D\fIname\fR .br the same as \fB\-D\fIname\fR=1. -.IP \fB\-E\fR -list the sequence of input tokens and delete any comments. -Control lines of the form -.RS -.RS -#\fBline\fR <\fIinteger\fR> "\fIfilename\fR" -.RE -are generated whenever needed. -.RE .IP \fB\-I\fIdirname\fR .br insert \fIdirname\fR in the list of include directories. @@ -46,8 +35,13 @@ machine. don't generate the EM \fBfil\fR and \fBlin\fR instructions that usually are generated to enable an interpreter to keep track of the current location in the source code. -.IP \fB\-P\fR -like \fB\-E\fR but without #\fBline\fR control lines. +.IP \fB\-p\fR +generate code at each procedure entry to call the routine +.BR procentry , +and at each return to call the routine +.BE procexit . +These routines are supplied with one parameter, a pointer to a +string containing the name of the procedure. .IP \fB\-R\fR interpret the input as restricted C (according to the language as described in \fIThe C programming language\fR by Kernighan and Ritchie.) @@ -75,12 +69,10 @@ This feature can be used in various shell scripts and surrounding programs to force a certain option to be handed over to \fBcemcom\fR. .LP .SH FILES -.IR /usr/em/lib/em_cemcom : +.IR ~em/lib/em_cemcom : the compiler .SH DIAGNOSTICS All warning and error messages are written on standard error output. -.SH BUGS -Feel free to report them to erikb@vu44.uucp .SH REFERENCE Baalbergen, E.H., D. Grune, M. Waage ;"\fIThe CEM compiler\fR", Informatica Manual IM-4 diff --git a/lang/cem/cemcom/ch7.c b/lang/cem/cemcom/ch7.c index bd7fcce2..d88852b2 100644 --- a/lang/cem/cemcom/ch7.c +++ b/lang/cem/cemcom/ch7.c @@ -340,7 +340,7 @@ ch7asgn(expp, oper, expr) */ int is_integral_type(tp) - struct type *tp; + register struct type *tp; { switch (tp->tp_fund) { case CHAR: @@ -360,7 +360,7 @@ is_integral_type(tp) int is_arith_type(tp) - struct type *tp; + register struct type *tp; { switch (tp->tp_fund) { case CHAR: diff --git a/lang/cem/cemcom/code.c b/lang/cem/cemcom/code.c index 18b7a1f4..8b3c88b9 100644 --- a/lang/cem/cemcom/code.c +++ b/lang/cem/cemcom/code.c @@ -203,6 +203,7 @@ begin_proc(name, def) /* to be called when entering a procedure */ lab_count = (label) 1; return_label = text_label(); return_expr_occurred = 0; + prc_entry(name); if (! options['L']) { /* profiling */ if (strcmp(last_fn_given, FileName) != 0) { /* previous function came from other file */ @@ -237,9 +238,11 @@ end_proc(fbytes, nbytes) if (options['d']) DfaEndFunction(); #endif DATAFLOW + prc_exit(); C_ret((arith)0); if (return_expr_occurred != 0) { C_df_ilb(return_label); + prc_exit(); if (func_res_label != 0) { C_lae_dlb(func_res_label, (arith)0); store_block(func_tp->tp_size, func_tp->tp_align); @@ -268,6 +271,7 @@ do_return() { /* do_return generates a direct return */ /* isn't a jump to the return label smarter ??? */ + prc_exit(); C_ret((arith)0); } @@ -386,7 +390,7 @@ code_declaration(idf, expr, lvl, sc) loc_init(expr, id) struct expr *expr; - struct idf *id; + register struct idf *id; { /* loc_init() generates code for the assignment of expression expr to the local variable described by id. @@ -550,6 +554,29 @@ unstack_stmt() which may contain break or continue */ register struct stmt_block *sbp = stmt_stack; - stmt_stack = stmt_stack->next; + stmt_stack = sbp->next; free_stmt_block(sbp); } + +static label l1; + +prc_entry(name) + char *name; +{ + if (options['p']) { + C_df_dlb(l1 = data_label()); + C_rom_scon(name, (arith) (strlen(name) + 1)); + C_lae_dlb(l1); + C_cal("procentry"); + C_asp(pointer_size); + } +} + +prc_exit() +{ + if (options['p']) { + C_lae_dlb(l1); + C_cal("procexit"); + C_asp(pointer_size); + } +} diff --git a/lang/cem/cemcom/conversion.c b/lang/cem/cemcom/conversion.c index bbb8914b..6e55474c 100644 --- a/lang/cem/cemcom/conversion.c +++ b/lang/cem/cemcom/conversion.c @@ -25,15 +25,13 @@ */ conversion(from_type, to_type) - struct type *from_type, *to_type; + register struct type *from_type, *to_type; { - arith from_size; - arith to_size; + register arith from_size = from_type->tp_size; + register arith to_size = to_type->tp_size; if (from_type == to_type) /* a little optimisation */ return; - from_size = from_type->tp_size; - to_size = to_type->tp_size; switch (fundamental(from_type)) { case T_SIGNED: switch (fundamental(to_type)) { @@ -50,7 +48,7 @@ conversion(from_type, to_type) #ifndef NOFLOAT case T_FLOATING: C_loc(from_size < word_size ? word_size : from_size); - C_loc(to_size < word_size ? word_size : to_size); + C_loc(to_size); C_cif(); break; #endif NOFLOAT @@ -75,7 +73,7 @@ conversion(from_type, to_type) break; #ifndef NOFLOAT case T_FLOATING: - C_loc(from_size < word_size ? word_size : from_size); + C_loc(from_size); C_loc(to_size < word_size ? word_size : to_size); switch (fundamental(to_type)) { case T_SIGNED: diff --git a/lang/cem/cemcom/cstoper.c b/lang/cem/cemcom/cstoper.c index 82f1e3f6..dabd2d91 100644 --- a/lang/cem/cemcom/cstoper.c +++ b/lang/cem/cemcom/cstoper.c @@ -184,7 +184,7 @@ cut_size(expr) /* The constant value of the expression expr is made to conform to the size of the type of the expression. */ - arith o1 = expr->VL_VALUE; + register arith o1 = expr->VL_VALUE; int uns = expr->ex_type->tp_unsigned; int size = (int) expr->ex_type->tp_size; diff --git a/lang/cem/cemcom/declar.g b/lang/cem/cemcom/declar.g index b2f795b4..a2524cc8 100644 --- a/lang/cem/cemcom/declar.g +++ b/lang/cem/cemcom/declar.g @@ -56,7 +56,7 @@ declaration makes all hope of writing a specific grammar for typedefs illusory. */ -decl_specifiers /* non-empty */ (struct decspecs *ds;) +decl_specifiers /* non-empty */ (register struct decspecs *ds;) /* Reads a non-empty decl_specifiers and fills the struct decspecs *ds. */ @@ -75,8 +75,7 @@ decl_specifiers /* non-empty */ (struct decspecs *ds;) ; /* 8.1 */ -other_specifier(struct decspecs *ds;): -[ +other_specifier(register struct decspecs *ds;): [ AUTO | STATIC | EXTERN | TYPEDEF | REGISTER ] { if (ds->ds_sc_given) error("repeated storage class specifier"); @@ -97,7 +96,6 @@ other_specifier(struct decspecs *ds;): error("unsigned specified twice"); else ds->ds_unsigned = 1; } -] ; /* 8.2 */ @@ -117,15 +115,13 @@ type_specifier(struct type **tpp;) {*tpp = Ds.ds_type;} ; -single_type_specifier(struct decspecs *ds;): -[ +single_type_specifier(register struct decspecs *ds;): TYPE_IDENTIFIER /* this includes INT, CHAR, etc. */ {idf2type(dot.tk_idf, &ds->ds_type);} | struct_or_union_specifier(&ds->ds_type) | enum_specifier(&ds->ds_type) -] ; /* 8.3 */ @@ -134,7 +130,7 @@ init_declarator_list(struct decspecs *ds;): [ ',' init_declarator(ds) ]* ; -init_declarator(struct decspecs *ds;) +init_declarator(register struct decspecs *ds;) { struct declarator Dc; struct expr *expr = (struct expr *) 0; @@ -164,13 +160,12 @@ init_declarator(struct decspecs *ds;) we just include the (formal) parameter list in the declarator description list dc. */ -declarator(struct declarator *dc;) +declarator(register struct declarator *dc;) { arith count; struct formal *fm = 0; } : -[ primary_declarator(dc) [%while(1) /* int i (M + 2) / 4; is a function, not an @@ -190,15 +185,12 @@ declarator(struct declarator *dc;) | '*' declarator(dc) {add_decl_unary(dc, POINTER, (arith)0, NO_PARAMS);} -] ; -primary_declarator(struct declarator *dc;) : -[ +primary_declarator(register struct declarator *dc;) : identifier(&dc->dc_idf) | '(' declarator(dc) ')' -] ; arrayer(arith *sizep;) @@ -229,7 +221,7 @@ formal(struct formal **fmp;) : identifier(&idf) { - struct formal *new = new_formal(); + register struct formal *new = new_formal(); new->fm_idf = idf; new->next = *fmp; @@ -238,7 +230,7 @@ formal(struct formal **fmp;) ; /* Change 2 */ -enum_specifier(struct type **tpp;) +enum_specifier(register struct type **tpp;) { struct idf *idf; arith l = (arith)0; @@ -260,7 +252,7 @@ enum_specifier(struct type **tpp;) ] ; -enumerator_pack(struct type *tp; arith *lp;) : +enumerator_pack(register struct type *tp; arith *lp;) : '{' enumerator(tp, lp) [%while(AHEAD != '}') /* >>> conflict on ',' */ @@ -294,10 +286,11 @@ enumerator(struct type *tp; arith *lp;) ; /* 8.5 */ -struct_or_union_specifier(struct type **tpp;) +struct_or_union_specifier(register struct type **tpp;) { int fund; - struct idf *idf; + struct idf *idfX; + register struct idf *idf; } : [ STRUCT | UNION ] @@ -308,7 +301,7 @@ struct_or_union_specifier(struct type **tpp;) } struct_declaration_pack(*tpp) | - identifier(&idf) + identifier(&idfX) { idf = idfX; } [ { declare_struct(fund, idf, tpp); @@ -325,7 +318,7 @@ struct_or_union_specifier(struct type **tpp;) ] ; -struct_declaration_pack(struct type *stp;) +struct_declaration_pack(register struct type *stp;) { struct sdef **sdefp = &stp->tp_sdef; arith size = (arith)0; @@ -402,7 +395,7 @@ bit_expression(struct field **fd;) ; /* 8.6 */ -initializer(struct idf *idf; struct expr **expp;) : +initializer(register struct idf *idf; register struct expr **expp;) : [ '=' | @@ -440,10 +433,9 @@ cast(struct type **tpp;) {struct declarator Dc;} : /* This code is an abject copy of that of 'declarator', for lack of a two-level grammar. */ -abstract_declarator(struct declarator *dc;) +abstract_declarator(register struct declarator *dc;) {arith count;} : -[ primary_abstract_declarator(dc) [ '(' ')' @@ -455,7 +447,6 @@ abstract_declarator(struct declarator *dc;) | '*' abstract_declarator(dc) {add_decl_unary(dc, POINTER, (arith)0, NO_PARAMS);} -] ; primary_abstract_declarator(struct declarator *dc;) : diff --git a/lang/cem/cemcom/eval.c b/lang/cem/cemcom/eval.c index ee501954..61a6ea7a 100644 --- a/lang/cem/cemcom/eval.c +++ b/lang/cem/cemcom/eval.c @@ -554,11 +554,11 @@ EVAL(expr, val, code, true_label, false_label) if (gencode) { EVAL(right, RVAL, TRUE, l_true, l_false); - C_df_ilb(l_false); - C_loc((arith)0); - C_bra(l_end); C_df_ilb(l_true); C_loc((arith)1); + C_bra(l_end); + C_df_ilb(l_false); + C_loc((arith)0); C_df_ilb(l_end); } else { @@ -578,23 +578,10 @@ EVAL(expr, val, code, true_label, false_label) break; case '!': if (true_label == 0) { + EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL); if (gencode) { - label l_true = text_label(); - label l_false = text_label(); - label l_end = text_label(); - - EVAL(right, RVAL, TRUE, l_false, - l_true); - C_df_ilb(l_false); - C_loc((arith)0); - C_bra(l_end); - C_df_ilb(l_true); - C_loc((arith)1); - C_df_ilb(l_end); + C_teq(); } - else - EVAL(right, RVAL, FALSE, NO_LABEL, - NO_LABEL); } else EVAL(right, RVAL, gencode, false_label, diff --git a/lang/cem/cemcom/expr.c b/lang/cem/cemcom/expr.c index 5d27d6a4..2991fead 100644 --- a/lang/cem/cemcom/expr.c +++ b/lang/cem/cemcom/expr.c @@ -102,7 +102,7 @@ rank_of_expression(ex) } check_conditional(expr, oper, pos_descr) - struct expr *expr; + register struct expr *expr; char *pos_descr; { /* Warn if restricted C is in effect and the expression expr, @@ -115,27 +115,29 @@ check_conditional(expr, oper, pos_descr) } dot2expr(expp) - register struct expr **expp; + struct expr **expp; { /* The token in dot is converted into an expression, a pointer to which is stored in *expp. */ - *expp = new_expr(); - (*expp)->ex_file = dot.tk_file; - (*expp)->ex_line = dot.tk_line; + register struct expr *ex = new_expr(); + + *expp = ex; + ex->ex_file = dot.tk_file; + ex->ex_line = dot.tk_line; switch (DOT) { case IDENTIFIER: - idf2expr(*expp); + idf2expr(ex); break; case STRING: - string2expr(*expp); + string2expr(ex); break; case INTEGER: - int2expr(*expp); + int2expr(ex); break; #ifndef NOFLOAT case FLOATING: - float2expr(*expp); + float2expr(ex); break; #endif NOFLOAT default: @@ -294,7 +296,7 @@ fill_int_expr(ex, ivalue, fund) struct expr * new_oper(tp, e1, oper, e2) struct type *tp; - struct expr *e1, *e2; + register struct expr *e1, *e2; { /* A new expression is constructed which consists of the operator oper which has e1 and e2 as operands; for a diff --git a/lang/cem/cemcom/expression.g b/lang/cem/cemcom/expression.g index 9d9a4fdb..2536b152 100644 --- a/lang/cem/cemcom/expression.g +++ b/lang/cem/cemcom/expression.g @@ -15,7 +15,6 @@ extern struct expr *intexpr(); /* 7 */ initial_value(struct expr **expp;) : -[ assignment_expression(expp) { if ((*expp)->ex_type->tp_fund == ARRAY) @@ -23,7 +22,6 @@ initial_value(struct expr **expp;) : } | initial_value_pack(expp) -] ; initial_value_pack(struct expr **expp;) : @@ -48,8 +46,7 @@ initial_value_list(struct expr **expp;) /* 7.1 */ -primary(struct expr **expp;) : -[ +primary(register struct expr **expp;) : IDENTIFIER {dot2expr(expp);} | @@ -60,10 +57,9 @@ primary(struct expr **expp;) : | '(' expression(expp) ')' {(*expp)->ex_flags |= EX_PARENS;} -] ; -secundary(struct expr **expp;) : +secundary(register struct expr **expp;) : primary(expp) [ index_pack(expp) @@ -124,10 +120,10 @@ postfixed(struct expr **expp;) %first first_of_type_specifier, type_specifier; -unary(struct expr **expp;) +unary(register struct expr **expp;) {struct type *tp; int oper;} : -[%if (first_of_type_specifier(AHEAD)) +%if (first_of_type_specifier(AHEAD)) cast(&tp) unary(expp) { ch7cast(expp, CAST, tp); (*expp)->ex_flags |= EX_CAST; @@ -139,10 +135,9 @@ unary(struct expr **expp;) {ch7mon(oper, expp);} | size_of(expp) -] ; -size_of(struct expr **expp;) +size_of(register struct expr **expp;) {struct type *tp;} : SIZEOF @@ -273,11 +268,9 @@ unop(int *oper;) : ; postop(int *oper;): -[ PLUSPLUS {*oper = POSTINCR;} | MINMIN {*oper = POSTDECR;} -] ; multop: @@ -311,8 +304,7 @@ binop(int *oper;) : {*oper = DOT;} ; -asgnop(int *oper;): -[ +asgnop(register int *oper;): '=' {*oper = DOT;} | '+' '=' {*oper = PLUSAB;} @@ -344,7 +336,6 @@ asgnop(int *oper;): symbol2str(DOT)); *oper = DOT; } -] ; constant(struct expr **expp;) : diff --git a/lang/cem/cemcom/init.c b/lang/cem/cemcom/init.c index ab462841..21a3d7cb 100644 --- a/lang/cem/cemcom/init.c +++ b/lang/cem/cemcom/init.c @@ -46,7 +46,7 @@ init_pp() register struct mkey *mk = &mkey[0]; while (mk->mk_reserved) { - struct idf *idf = str2idf(mk->mk_reserved); + register struct idf *idf = str2idf(mk->mk_reserved); if (idf->id_resmac) fatal("maximum identifier length insufficient"); diff --git a/lang/cem/cemcom/input.c b/lang/cem/cemcom/input.c index c3625037..30ea84f2 100644 --- a/lang/cem/cemcom/input.c +++ b/lang/cem/cemcom/input.c @@ -12,7 +12,7 @@ struct file_info finfo; #ifndef NOPP char * getwdir(fn) - char *fn; + register char *fn; { register char *p; char *strrindex(); diff --git a/lang/cem/cemcom/label.c b/lang/cem/cemcom/label.c index 0ced30b0..391fa87c 100644 --- a/lang/cem/cemcom/label.c +++ b/lang/cem/cemcom/label.c @@ -32,7 +32,7 @@ apply_label(idf) } enter_label(idf, defining) - struct idf *idf; + register struct idf *idf; { /* The identifier idf is entered as a label. If it is new, it is entered into the idf list with the largest possible @@ -40,7 +40,7 @@ enter_label(idf, defining) If defining, the label comes from a label statement. */ if (idf->id_def) { - struct def *def = idf->id_def; + register struct def *def = idf->id_def; if (def->df_sc == LABEL) { if (defining && def->df_initialized) @@ -79,7 +79,7 @@ enter_label(idf, defining) } unstack_label(idf) - struct idf *idf; + register struct idf *idf; { /* The scope in which the label idf occurred is left. */ diff --git a/lang/cem/cemcom/macro.str b/lang/cem/cemcom/macro.str index 2772b4d0..023d5763 100644 --- a/lang/cem/cemcom/macro.str +++ b/lang/cem/cemcom/macro.str @@ -29,6 +29,14 @@ struct macro { /* ALLOCDEF "macro" 20 */ +struct mlist { + struct mlist *next; + struct macro *m_mac; + char *m_repl; +}; + +/* ALLOCDEF "mlist" 20 */ + /* `token' numbers of keywords of command-line processor */ #define K_UNKNOWN 0 diff --git a/lang/cem/cemcom/main.c b/lang/cem/cemcom/main.c index 4a97f5e3..12e71ff3 100644 --- a/lang/cem/cemcom/main.c +++ b/lang/cem/cemcom/main.c @@ -109,7 +109,6 @@ main(argc, argv) } char *source = 0; -char *destination = 0; char *nmlist = 0; @@ -127,16 +126,21 @@ compile(argc, argv) char tmpf[256]; #endif char *result; + register char *destination = 0; +#ifdef DEBUG #ifndef NOPP - int pp_only = options['E'] || options['P']; + int pp_only = options['E'] || options['P'] || options['C']; #endif NOPP +#endif switch (argc) { case 1: +#ifdef DEBUG #ifndef NOPP if (!pp_only) #endif NOPP +#endif fatal("%s: destination file not specified", prog_name); break; case 2: @@ -173,21 +177,22 @@ compile(argc, argv) #endif NOPP PushLex(); +#ifdef DEBUG #ifndef NOPP if (pp_only) /* run the preprocessor as if it is stand-alone */ preprocess(); - else { + else #endif NOPP +#endif DEBUG + { #ifdef USE_TMP if (!options['N']) { init_code(tmpfile); } else - init_code(destination); -#else USE_TMP - init_code(destination); #endif USE_TMP + init_code(destination); /* compile the source text */ C_program(); @@ -208,9 +213,7 @@ compile(argc, argv) if (options['f'] || options['t']) dumpidftab("end of main", options['f'] ? 0 : 0); #endif DEBUG -#ifndef NOPP } -#endif NOPP PopLex(); } @@ -302,6 +305,7 @@ init_specials(si) } } +#ifdef DEBUG #ifndef NOPP preprocess() { @@ -373,6 +377,7 @@ preprocess() } } #endif NOPP +#endif DEBUG #ifdef USE_TMP AppendFile(src, dst) diff --git a/lang/cem/cemcom/options.c b/lang/cem/cemcom/options.c index 67f82cf6..66cf9eb5 100644 --- a/lang/cem/cemcom/options.c +++ b/lang/cem/cemcom/options.c @@ -15,6 +15,7 @@ #include "sizes.h" #include "align.h" #include "use_tmp.h" +#include "dataflow.h" #ifndef NOPP extern char *inctable[MAXINCL]; @@ -41,6 +42,19 @@ do_option(text) options[*text] = 1; /* flags, debug options etc. */ break; +#ifdef DATAFLOW + case 'd': +#endif DATAFLOW + case 'p': /* procentry/procexit */ + case 'L' : /* no fil/lin */ + case 'n': /* use no registers */ + case 'w': /* no warnings will be given */ + case 'R': /* strict version */ + options[*(text-1)] = 1; + break; + +#ifdef ___XXX___ +deleted, is now a debug-flag case 'C' : /* E option + comment output */ #ifndef NOPP options['E'] = 1; @@ -49,6 +63,7 @@ do_option(text) warning("-C option ignored"); #endif NOPP break; +#endif ___XXX___ case 'D' : { /* -Dname : predefine name */ #ifndef NOPP @@ -86,6 +101,7 @@ do_option(text) break; } +#ifdef ___XXX___ case 'E' : /* run preprocessor only, with # */ #ifndef NOPP options['E'] = 1; @@ -93,6 +109,7 @@ do_option(text) warning("-E option ignored"); #endif NOPP break; +#endif ___XXX___ case 'I' : /* -Ipath : insert "path" into include list */ #ifndef NOPP @@ -115,10 +132,6 @@ do_option(text) #endif NOPP break; - case 'L' : - options['L'] = 1; /* no fil/lin */ - break; - case 'M': /* maximum identifier length */ idfsize = txt2int(&text); if (*text || idfsize <= 0) @@ -135,6 +148,7 @@ do_option(text) #endif USE_TMP break; +#ifdef ___XXX___ case 'P' : /* run preprocessor stand-alone, without #'s */ #ifndef NOPP options['E'] = 1; @@ -143,10 +157,7 @@ do_option(text) warning("-P option ignored"); #endif NOPP break; - - case 'R': - options['R'] = 1; - break; +#endif ___XXX___ #ifdef USE_TMP case 'T' : @@ -255,12 +266,6 @@ do_option(text) } break; } - case 'n': - options['n'] = 1; /* use no registers */ - break; - case 'w': - options['w'] = 1; /* no warnings will be given */ - break; } } diff --git a/lang/cem/cemcom/program.g b/lang/cem/cemcom/program.g index c818df55..f0e57579 100644 --- a/lang/cem/cemcom/program.g +++ b/lang/cem/cemcom/program.g @@ -63,12 +63,13 @@ extern error(); control_if_expression { - struct expr *expr; + struct expr *exprX; } : - constant_expression(&expr) + constant_expression(&exprX) { #ifndef NOPP + register struct expr *expr = exprX; if (expr->ex_flags & EX_SIZEOF) expr_error(expr, "sizeof not allowed in preprocessor"); @@ -113,7 +114,6 @@ external_definition Ds = null_decspecs; Dc = null_declarator; } -[ ext_decl_specifiers(&Ds) [ declarator(&Dc) @@ -133,19 +133,17 @@ external_definition {remove_declarator(&Dc);} | asm_statement /* top level, would you believe */ -] ; ext_decl_specifiers(struct decspecs *ds;) : -[%prefer /* the thin ice in R.M. 11.1 */ +%prefer /* the thin ice in R.M. 11.1 */ decl_specifiers(ds) | empty {do_decspecs(ds);} -] ; -non_function(struct decspecs *ds; struct declarator *dc;) +non_function(register struct decspecs *ds; register struct declarator *dc;) { struct expr *expr = (struct expr *) 0; } @@ -168,7 +166,7 @@ function(struct declarator *dc;) arith fbytes, nbytes; } : - { struct idf *idf = dc->dc_idf; + { register struct idf *idf = dc->dc_idf; init_idf(idf); stack_level(); /* L_FORMAL1 declarations */ diff --git a/lang/cem/cemcom/replace.c b/lang/cem/cemcom/replace.c index cc0c49d7..d4f0dc13 100644 --- a/lang/cem/cemcom/replace.c +++ b/lang/cem/cemcom/replace.c @@ -21,7 +21,7 @@ char *strcpy(), *strcat(); char *long2str(); -PRIVATE struct macro *ReplaceList; /* list of currently active macros */ +PRIVATE struct mlist *ReplaceList; /* list of currently active macros */ EXPORT int replace(idef) @@ -37,7 +37,8 @@ replace(idef) some error has occurred. */ register struct macro *mac = idef->id_macro; - register char c; + register struct mlist *repl; + register int c; char **actpars, **getactuals(); char *reptext, *macro2buffer(); int size; @@ -74,24 +75,34 @@ replace(idef) if (mac->mc_flag & FUNC) { struct idf *param = str2idf(*actpars); + repl = new_mlist(); if (param->id_macro) reptext = "1"; else reptext = "0"; InsertText(reptext, 1); - mac->next = ReplaceList; - ReplaceList = mac; + repl->next = ReplaceList; + ReplaceList = repl; + repl->m_mac = mac; return 1; } } + repl = new_mlist(); + repl->m_mac = mac; if (mac->mc_flag & FUNC) /* this macro leads to special action */ macro_func(idef); - if (mac->mc_nps <= 0) + if (mac->mc_nps <= 0) { + reptext = mac->mc_text; + size = mac->mc_length; mac->mc_flag |= NOREPLACE; - reptext = macro2buffer(idef, actpars, &size); /* create input buffer */ + } + else { + reptext = macro2buffer(idef, actpars, &size); /* create input buffer */ + repl->m_repl = reptext; + } InsertText(reptext, size); - mac->next = ReplaceList; - ReplaceList = mac; + repl->next = ReplaceList; + ReplaceList = repl; return 1; } @@ -181,14 +192,18 @@ DoUnstack() EXPORT EnableMacros() { - register struct macro *p = ReplaceList; + register struct mlist *p = ReplaceList; ASSERT(Unstacked > 0); while (Unstacked > 0) { + struct mlist *nxt = p->next; + ASSERT(p != 0); - p->mc_flag &= ~NOREPLACE; - p->mc_count = 0; - p = p->next; + p->m_mac->mc_flag &= ~NOREPLACE; + if (p->m_mac->mc_count) p->m_mac->mc_count--; + if (p->m_repl) free(p->m_repl); + free_mlist(p); + p = nxt; Unstacked--; } ReplaceList = p; diff --git a/lang/cem/cemcom/scan.c b/lang/cem/cemcom/scan.c index 2dde8b79..f8ec10af 100644 --- a/lang/cem/cemcom/scan.c +++ b/lang/cem/cemcom/scan.c @@ -31,7 +31,7 @@ PRIVATE int nr_of_params; /* number of actuals read until now */ PRIVATE char ** getactuals(idef) - struct idf *idef; + register struct idf *idef; { /* getactuals() collects the actual parameters and turns them into a list of strings, a pointer to which is returned. diff --git a/lang/cem/cemcom/stack.c b/lang/cem/cemcom/stack.c index 206a8f76..bdb80208 100644 --- a/lang/cem/cemcom/stack.c +++ b/lang/cem/cemcom/stack.c @@ -40,12 +40,13 @@ stack_level() { /* A new level is added on top of the identifier stack. */ register struct stack_level *stl = new_stack_level(); + register struct stack_level *loclev = local_level; - local_level->sl_next = stl; - stl->sl_previous = local_level; + loclev->sl_next = stl; + stl->sl_previous = loclev; stl->sl_level = ++level; stl->sl_local_offset = - stl->sl_max_block = local_level->sl_local_offset; + stl->sl_max_block = loclev->sl_local_offset; local_level = stl; } diff --git a/lang/cem/cemcom/statement.g b/lang/cem/cemcom/statement.g index 2d379320..8a210b0c 100644 --- a/lang/cem/cemcom/statement.g +++ b/lang/cem/cemcom/statement.g @@ -28,7 +28,7 @@ extern int level; /* 9 */ statement : -[%if (AHEAD != ':') +%if (AHEAD != ':') expression_statement | label ':' statement @@ -60,7 +60,6 @@ statement ';' | asm_statement -] ; expression_statement From 9b899c2889ba69b9463595cb45b31bfc6944b797 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 10 Feb 1987 09:27:44 +0000 Subject: [PATCH 0795/1625] Initial revision --- lang/cem/cemcom/Makefile | 235 ++++++++++++++++++++++++++++++++++++++ lang/cem/cemcom/Resolve | 56 +++++++++ lang/cem/cemcom/nmclash.c | 5 + 3 files changed, 296 insertions(+) create mode 100644 lang/cem/cemcom/Makefile create mode 100755 lang/cem/cemcom/Resolve create mode 100644 lang/cem/cemcom/nmclash.c diff --git a/lang/cem/cemcom/Makefile b/lang/cem/cemcom/Makefile new file mode 100644 index 00000000..39250fcd --- /dev/null +++ b/lang/cem/cemcom/Makefile @@ -0,0 +1,235 @@ +# $Header$ +# M A K E F I L E F O R A C K C - C O M P I L E R + +# Machine and environ dependent definitions +EMHOME = ../../.. +MKDEP = $(EMHOME)/bin/mkdep +PRID = $(EMHOME)/bin/prid +CID = $(EMHOME)/bin/cid + +# Libraries and EM interface definitions +SYSLIB = $(EMHOME)/modules/lib/libsystem.a +EMKLIB = $(EMHOME)/modules/lib/libemk.a +EMELIB = $(EMHOME)/modules/lib/libeme.a +STRLIB = $(EMHOME)/modules/lib/libstring.a +PRTLIB = $(EMHOME)/modules/lib/libprint.a +EMMESLIB = $(EMHOME)/modules/lib/libem_mes.a +INPLIB = $(EMHOME)/modules/lib/libinput.a +ALLOCLIB = $(EMHOME)/modules/lib/liballoc.a +MALLOC = $(EMHOME)/modules/lib/malloc.o +LIBS = $(INPLIB) $(EMMESLIB) $(EMKLIB) $(PRTLIB) $(STRLIB) \ + $(ALLOCLIB) $(MALLOC) $(SYSLIB) +ELIBS = $(INPLIB) $(EMMESLIB) $(EMELIB) $(PRTLIB) $(STRLIB) \ + $(ALLOCLIB) $(MALLOC) $(SYSLIB) +LIB_INCLUDES = -I$(EMHOME)/modules/h -I$(EMHOME)/modules/pkg +EM_INCLUDES = -I$(EMHOME)/h +SYSLLIB = $(EMHOME)/modules/lib/llib-lsys.ln +EMKLLIB = $(EMHOME)/modules/lib/llib-lemk.ln +EMELLIB = $(EMHOME)/modules/lib/llib-leme.ln +STRLLIB = $(EMHOME)/modules/lib/llib-lstr.ln +PRTLLIB = $(EMHOME)/modules/lib/llib-lprint.ln +EMMESLLIB = $(EMHOME)/modules/lib/llib-lmes.ln +INPLLIB = $(EMHOME)/modules/lib/llib-linput.ln +ALLOCLLIB = $(EMHOME)/modules/lib/llib-lalloc.ln +LINTLIBS = +#LINTLIBS = $(EMMESLLIB) $(EMKLLIB) $(PRTLLIB) $(STRLLIB) $(SYSLLIB) $(ALLOCLLIB) +CURRDIR = . + +COPTIONS = + +# What parser generator to use and how +GEN = $(EMHOME)/bin/LLgen +GENOPTIONS = + +# Special #defines during compilation +CDEFS = $(EM_INCLUDES) $(LIB_INCLUDES) +CFLAGS = $(CDEFS) $(COPTIONS) -O + +# Grammar files and their objects +LSRC = tokenfile.g declar.g statement.g expression.g program.g +LCSRC = tokenfile.c declar.c statement.c expression.c program.c Lpars.c +LOBJ = tokenfile.o declar.o statement.o expression.o program.o Lpars.o + +# Objects of hand-written C files +CSRC = main.c idf.c declarator.c decspecs.c struct.c \ + expr.c ch7.c ch7bin.c cstoper.c arith.c \ + asm.c code.c dumpidf.c error.c field.c\ + tokenname.c LLlex.c LLmessage.c \ + input.c domacro.c replace.c init.c options.c \ + scan.c skip.c stack.c type.c ch7mon.c label.c eval.c \ + switch.c ival.c conversion.c \ + blocks.c dataflow.c +COBJ = main.o idf.o declarator.o decspecs.o struct.o \ + expr.o ch7.o ch7bin.o cstoper.o arith.o \ + asm.o code.o dumpidf.o error.o field.o\ + tokenname.o LLlex.o LLmessage.o \ + input.o domacro.o replace.o init.o options.o \ + scan.o skip.o stack.o type.o ch7mon.o label.o eval.o \ + switch.o ival.o conversion.o \ + blocks.o dataflow.o + +# Objects of other generated C files +GCSRC = char.c symbol2str.c next.c +GOBJ = char.o symbol2str.o next.o + +# generated source files +GHSTRSRC = code.h declar.h decspecs.h def.h expr.h field.h \ + idf.h macro.h stack.h stmt.h struct.h switch.h type.h +GSRC = $(GCSRC) $(GHSTRSRC) + +# .h files generated by `make hfiles'; PLEASE KEEP THIS UP-TO-DATE! +GHSRC = botch_free.h dataflow.h debug.h density.h errout.h \ + idepth.h idfsize.h ifdepth.h inputtype.h lapbuf.h \ + maxincl.h nobitfield.h nofloat.h nopp.h \ + nparams.h numsize.h parbufsize.h pathlength.h \ + strsize.h target_sizes.h textsize.h use_tmp.h spec_arith.h static.h + +HFILES = LLlex.h align.h arith.h assert.h atw.h class.h faulty.h \ + input.h interface.h label.h level.h mes.h sizes.h specials.h \ + $(GHSRC) $(GHSTRSRC) tokenname.h Lpars.h file_info.h + +# generated files, for 'make clean' only +GENERATED = tab tokenfile.g Lpars.h LLfiles LL.output lint.out \ + print Xref lxref hfiles Cfiles $(GHSRC) $(GSRC) longnames $(LCSRC) + +# include files containing ALLOCDEF specifications +NEXTFILES = code.str declar.str decspecs.str def.str expr.str field.str \ + idf.str macro.str stack.str stmt.str struct.str switch.str type.str + +OBJ = $(COBJ) $(LOBJ) $(GOBJ) +SRC = $(CSRC) $(LCSRC) $(GCSRC) + +#EXCLEXCLEXCLEXCL + +.SUFFIXES: .str .h +.str.h: + ./make.allocd <$*.str >$*.h + +Main: Cfiles + sh -c 'if $(CC) nmclash.c > /dev/null 2>&1 ; then make $(CURRDIR)/main ; else sh Resolve main ; fi' + @rm -f nmclash.o a.out + +Emain: Cfiles + sh -c 'if $(CC) nmclash.c > /dev/null 2>&1 ; then make $(CURRDIR)/emain ; else sh Resolve emain ; fi' + @rm -f nmclash.o a.out + +install: Main + rm -f $(EMHOME)/lib/em_cemcom + cp $(CURRDIR)/main $(EMHOME)/lib/em_cemcom + +clean: + rm -f $(OBJ) $(GENERATED) + (cd .. ; rm -rf Xsrc) + +lint: Cfiles + sh -c 'if $(CC) nmclash.c > /dev/null 2>&1 ; then make Xlint ; else sh Resolve Xlint ; fi' + @rm -f nmclash.o a.out + +longnames: $(SRC) $(HFILES) + sh -c 'if test -f longnames ; then $(PRID) -l7 longnames $? > Xlongnames ; mv Xlongnames longnames ; else $(PRID) -l7 $? > longnames ; fi' + +# entry points not to be used directly + +Cfiles: hfiles LLfiles $(GENCFILES) $(GHSTRSRC) $(GHSRC) makefile + echo $(SRC) $(HFILES) > Cfiles + +hfiles: ./make.hfiles Parameters + ./make.hfiles Parameters + @touch hfiles + +LLfiles: $(LSRC) + $(GEN) $(GENOPTIONS) $(LSRC) + @touch LLfiles + +tokenfile.g: tokenname.c make.tokfile + tokenfile.g + +symbol2str.c: tokenname.c make.tokcase + symbol2str.c + +char.c: tab char.tab + tab -fchar.tab >char.c + +tab: + $(CC) tab.c -o tab + +next.c: make.next $(NEXTFILES) + ./make.next $(NEXTFILES) >next.c + +code.h: make.allocd +declar.h: make.allocd +decspecs.h: make.allocd +def.h: make.allocd +expr.h: make.allocd +field.h: make.allocd +idf.h: make.allocd +macro.h: make.allocd +stack.h: make.allocd +stmt.h: make.allocd +struct.h: make.allocd +switch.h: make.allocd +type.h: make.allocd + +depend: Cfiles + sed '/^#AUTOAUTO/,$$d' makefile >makefile.new + echo '#AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO' >>makefile.new + $(MKDEP) $(SRC) | sed 's/\.c:/.o:/' >>makefile.new + mv makefile makefile.old + mv makefile.new makefile + +#INCLINCLINCLINCL + +$(CURRDIR)/main: $(OBJ) $(CURRDIR)/makefile + $(CC) $(COPTIONS) $(LFLAGS) $(OBJ) $(LIBS) -o $(CURRDIR)/main + size $(CURRDIR)/main + +$(CURRDIR)/emain: $(OBJ) $(CURRDIR)/makefile + $(CC) $(COPTIONS) $(LFLAGS) $(OBJ) $(ELIBS) -o $(CURRDIR)/emain + size $(CURRDIR)/emain + +Xlint: + lint $(CDEFS) $(LINTFLAGS) $(SRC) + +#AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO +main.o: LLlex.h Lpars.h arith.h debug.h declar.h file_info.h idf.h input.h inputtype.h level.h maxincl.h nobitfield.h nofloat.h nopp.h spec_arith.h specials.h target_sizes.h tokenname.h type.h use_tmp.h +idf.o: LLlex.h Lpars.h align.h arith.h assert.h botch_free.h debug.h declar.h decspecs.h def.h file_info.h idf.h idfsize.h label.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h specials.h stack.h struct.h type.h +declarator.o: Lpars.h arith.h botch_free.h declar.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h type.h +decspecs.o: Lpars.h arith.h decspecs.h def.h level.h nobitfield.h nofloat.h spec_arith.h type.h +struct.o: LLlex.h Lpars.h align.h arith.h assert.h botch_free.h debug.h def.h field.h file_info.h idf.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h stack.h struct.h type.h +expr.o: LLlex.h Lpars.h arith.h botch_free.h declar.h decspecs.h def.h expr.h file_info.h idf.h label.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h type.h +ch7.o: Lpars.h arith.h assert.h debug.h def.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h struct.h type.h +ch7bin.o: Lpars.h arith.h botch_free.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h struct.h type.h +cstoper.o: Lpars.h arith.h assert.h debug.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h target_sizes.h type.h +arith.o: Lpars.h arith.h botch_free.h expr.h field.h idf.h label.h mes.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h +code.o: LLlex.h Lpars.h arith.h assert.h atw.h botch_free.h code.h dataflow.h debug.h declar.h decspecs.h def.h expr.h file_info.h idf.h label.h level.h mes.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h specials.h stack.h stmt.h type.h use_tmp.h +dumpidf.o: Lpars.h arith.h debug.h def.h expr.h field.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h stack.h static.h struct.h type.h +error.o: LLlex.h arith.h debug.h errout.h expr.h file_info.h label.h nofloat.h nopp.h spec_arith.h tokenname.h use_tmp.h +field.o: Lpars.h arith.h assert.h code.h debug.h expr.h field.h idf.h label.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h type.h +tokenname.o: LLlex.h Lpars.h arith.h file_info.h idf.h nofloat.h nopp.h spec_arith.h tokenname.h +LLlex.o: LLlex.h Lpars.h arith.h assert.h class.h debug.h def.h file_info.h idf.h idfsize.h input.h nofloat.h nopp.h numsize.h sizes.h spec_arith.h strsize.h +LLmessage.o: LLlex.h Lpars.h arith.h file_info.h idf.h nofloat.h nopp.h spec_arith.h +input.o: file_info.h input.h inputtype.h nopp.h +domacro.o: LLlex.h Lpars.h arith.h assert.h botch_free.h class.h debug.h file_info.h idf.h idfsize.h ifdepth.h input.h interface.h macro.h nofloat.h nopp.h nparams.h parbufsize.h spec_arith.h textsize.h +replace.o: LLlex.h arith.h assert.h class.h debug.h file_info.h idf.h input.h interface.h macro.h nofloat.h nopp.h pathlength.h spec_arith.h static.h strsize.h +init.o: class.h idf.h interface.h macro.h nopp.h +options.o: align.h arith.h botch_free.h class.h dataflow.h idf.h idfsize.h macro.h maxincl.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h use_tmp.h +scan.o: class.h idf.h input.h interface.h lapbuf.h macro.h nopp.h nparams.h +skip.o: LLlex.h arith.h class.h file_info.h input.h interface.h nofloat.h nopp.h spec_arith.h +stack.o: Lpars.h arith.h botch_free.h debug.h def.h idf.h level.h mes.h nobitfield.h nofloat.h nopp.h spec_arith.h stack.h struct.h type.h +type.o: Lpars.h align.h arith.h botch_free.h def.h idf.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h type.h +ch7mon.o: Lpars.h arith.h botch_free.h def.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h +label.o: Lpars.h arith.h def.h idf.h label.h level.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h +eval.o: Lpars.h align.h arith.h assert.h atw.h code.h dataflow.h debug.h def.h expr.h idf.h label.h level.h mes.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h stack.h type.h +switch.o: Lpars.h arith.h assert.h botch_free.h code.h debug.h density.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h switch.h type.h +ival.o: Lpars.h align.h arith.h assert.h class.h debug.h def.h expr.h field.h idf.h label.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h struct.h type.h +conversion.o: Lpars.h arith.h nobitfield.h nofloat.h sizes.h spec_arith.h type.h +blocks.o: arith.h atw.h label.h nofloat.h sizes.h spec_arith.h stack.h +dataflow.o: dataflow.h +tokenfile.o: Lpars.h +declar.o: LLlex.h Lpars.h arith.h debug.h declar.h decspecs.h def.h expr.h field.h file_info.h idf.h label.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h struct.h type.h +statement.o: LLlex.h Lpars.h arith.h botch_free.h code.h debug.h def.h expr.h file_info.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h stack.h type.h +expression.o: LLlex.h Lpars.h arith.h expr.h file_info.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h +program.o: LLlex.h Lpars.h arith.h code.h declar.h decspecs.h def.h expr.h file_info.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h +Lpars.o: Lpars.h +char.o: class.h +symbol2str.o: Lpars.h diff --git a/lang/cem/cemcom/Resolve b/lang/cem/cemcom/Resolve new file mode 100755 index 00000000..5522cc6f --- /dev/null +++ b/lang/cem/cemcom/Resolve @@ -0,0 +1,56 @@ +: create a directory Xsrc with name clashes resolved +: and run make in that directory +: '$Header$' + +case $# in +1) + ;; +*) echo "$0: one argument expected" 1>&2 + exit 1 + ;; +esac +PW=`pwd` +case $1 in +main|emain) + target=$PW/$1 + ;; +Xlint) + target=$1 + ;; +*) echo "$0: $1: Illegal argument" 1>&2 + exit 1 + ;; +esac +if test -d ../Xsrc +then + : +else mkdir ../Xsrc +fi +make longnames +: remove code generating routines from the clashes list as they are defines. +: code generating routine names start with C_ +sed '/^C_/d' < longnames > tmp$$ +cclash -c -l7 tmp$$ > ../Xsrc/Xclashes +rm -f tmp$$ +cd ../Xsrc +if cmp -s Xclashes clashes +then + : +else + mv Xclashes clashes +fi +rm -f makefile +ed - $PW/makefile <<'EOF' +/^#EXCLEXCL/,/^#INCLINCL/d +w makefile +q +EOF +for i in `cat $PW/Cfiles` +do + cat >> makefile < $i +EOF +done +make CURRDIR=$PW $target diff --git a/lang/cem/cemcom/nmclash.c b/lang/cem/cemcom/nmclash.c new file mode 100644 index 00000000..95a9489e --- /dev/null +++ b/lang/cem/cemcom/nmclash.c @@ -0,0 +1,5 @@ +/* Accepted if many characters of long names are significant */ +/* $Header$ */ +abcdefghijklmnopr() { } +abcdefghijklmnopq() { } +main() { } From 9d48a6cff8308c1bb3e05179bcc1df0ca9e4af25 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 10 Feb 1987 09:34:45 +0000 Subject: [PATCH 0796/1625] *** empty log message *** --- mach/m68020/ncg/README | 10 +++++----- mach/m68k2/ncg/README | 10 +++++----- mach/m68k4/ncg/README | 10 +++++----- mach/moon3/ncg/README | 10 +++++----- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/mach/m68020/ncg/README b/mach/m68020/ncg/README index 1a817487..327b53ab 100644 --- a/mach/m68020/ncg/README +++ b/mach/m68020/ncg/README @@ -1,10 +1,10 @@ The file 'table' in this directory contains a back end table for the MC68020 processor as well as one for the MC68000. Both tables use 4 bytes for words as well as for pointers. The table must be preprocessed first -by the C preprocessor. If the -Dm68k4 flag is used when preprocessing, a -code generator for the m68k4 is generated, otherwise a m68020 codegenerator -is produced. (See Makefile: PREFLAGS) -The m68k4 cg can very well be used for the MC68010 processor, for it makes -rather efficient use of the 68010 loop mode. +by the C preprocessor. +The file "whichone.h" specifies which code generator is generated: +it #defines either TBL68000 or TBL86020. +The m68k4(TBL68000) cg can very well be used for the MC68010 processor, +for it makes rather efficient use of the 68010 loop mode. The mach.[ch] files are also suitable for both the m68020 and the m68k4. diff --git a/mach/m68k2/ncg/README b/mach/m68k2/ncg/README index 1a817487..327b53ab 100644 --- a/mach/m68k2/ncg/README +++ b/mach/m68k2/ncg/README @@ -1,10 +1,10 @@ The file 'table' in this directory contains a back end table for the MC68020 processor as well as one for the MC68000. Both tables use 4 bytes for words as well as for pointers. The table must be preprocessed first -by the C preprocessor. If the -Dm68k4 flag is used when preprocessing, a -code generator for the m68k4 is generated, otherwise a m68020 codegenerator -is produced. (See Makefile: PREFLAGS) -The m68k4 cg can very well be used for the MC68010 processor, for it makes -rather efficient use of the 68010 loop mode. +by the C preprocessor. +The file "whichone.h" specifies which code generator is generated: +it #defines either TBL68000 or TBL86020. +The m68k4(TBL68000) cg can very well be used for the MC68010 processor, +for it makes rather efficient use of the 68010 loop mode. The mach.[ch] files are also suitable for both the m68020 and the m68k4. diff --git a/mach/m68k4/ncg/README b/mach/m68k4/ncg/README index 1a817487..327b53ab 100644 --- a/mach/m68k4/ncg/README +++ b/mach/m68k4/ncg/README @@ -1,10 +1,10 @@ The file 'table' in this directory contains a back end table for the MC68020 processor as well as one for the MC68000. Both tables use 4 bytes for words as well as for pointers. The table must be preprocessed first -by the C preprocessor. If the -Dm68k4 flag is used when preprocessing, a -code generator for the m68k4 is generated, otherwise a m68020 codegenerator -is produced. (See Makefile: PREFLAGS) -The m68k4 cg can very well be used for the MC68010 processor, for it makes -rather efficient use of the 68010 loop mode. +by the C preprocessor. +The file "whichone.h" specifies which code generator is generated: +it #defines either TBL68000 or TBL86020. +The m68k4(TBL68000) cg can very well be used for the MC68010 processor, +for it makes rather efficient use of the 68010 loop mode. The mach.[ch] files are also suitable for both the m68020 and the m68k4. diff --git a/mach/moon3/ncg/README b/mach/moon3/ncg/README index 1a817487..327b53ab 100644 --- a/mach/moon3/ncg/README +++ b/mach/moon3/ncg/README @@ -1,10 +1,10 @@ The file 'table' in this directory contains a back end table for the MC68020 processor as well as one for the MC68000. Both tables use 4 bytes for words as well as for pointers. The table must be preprocessed first -by the C preprocessor. If the -Dm68k4 flag is used when preprocessing, a -code generator for the m68k4 is generated, otherwise a m68020 codegenerator -is produced. (See Makefile: PREFLAGS) -The m68k4 cg can very well be used for the MC68010 processor, for it makes -rather efficient use of the 68010 loop mode. +by the C preprocessor. +The file "whichone.h" specifies which code generator is generated: +it #defines either TBL68000 or TBL86020. +The m68k4(TBL68000) cg can very well be used for the MC68010 processor, +for it makes rather efficient use of the 68010 loop mode. The mach.[ch] files are also suitable for both the m68020 and the m68k4. From 3e36418cedf61fb329fb6dc342927e10e371db2b Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 10 Feb 1987 09:39:40 +0000 Subject: [PATCH 0797/1625] Removed some more "%...D"s --- util/ass/ass60.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/util/ass/ass60.c b/util/ass/ass60.c index a02efcd2..2ab9f245 100644 --- a/util/ass/ass60.c +++ b/util/ass/ass60.c @@ -110,7 +110,7 @@ if ( (n==0 && d_flag) || (n==4 && d_flag>=2) || (n<100 && d_flag>=3) ) { printf("p "); break; } - printf(" %9.9s%14D", + printf(" %9.9s%14ld", typestr[ln->type1type1 : CONST], nicepr(ln->type1,&ln->ad)) ; if ( ln->opoff != NO_OFF ) @@ -182,11 +182,11 @@ if ( ( (n==0 || n>=100) && d_flag) || (n<=1 && d_flag>=2) ) { printf("\nData relocation\n") ; printf("\n\t%10s %10s %10s\n","offset","type","value"); for ( rl=f_data ; rl ; rl= rl->r_next ) { - printf("\t%10D %10s ",rl->r_off,r_data[rl->r_typ]); + printf("\t%10ld %10s ",rl->r_off,r_data[rl->r_typ]); switch(rl->r_typ) { case RELADR: case RELHEAD: - printf("%10D\n",rl->r_val.rel_i) ; + printf("%10ld\n",rl->r_val.rel_i) ; break ; case RELGLO: printf("%8.8s\n",rl->r_val.rel_gp->g_name) ; @@ -201,10 +201,10 @@ if ( ( (n==0 || n>=100) && d_flag) || (n<=1 && d_flag>=2) ) { printf("\n\nText relocation\n") ; printf("\n\t%10s %10s %10s\n","offset","flags","value"); for ( rl=f_text; rl ; rl= rl->r_next ) { - printf("\t%10D %10s ", + printf("\t%10ld %10s ", rl->r_off,pflags(opchoice[rl->r_typ&~RELMNS])) ; if ( rl->r_typ&RELMNS ) - printf("%10D\n",rl->r_val.rel_i) ; + printf("%10ld\n",rl->r_val.rel_i) ; else printf("\n") ; } } From 20d5f799674a1b0695c4f677a10096778aa7df1d Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 10 Feb 1987 09:49:50 +0000 Subject: [PATCH 0798/1625] removed some %0 stuff --- util/cgg/bootgram.y | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/util/cgg/bootgram.y b/util/cgg/bootgram.y index 4e9bff12..7359f969 100644 --- a/util/cgg/bootgram.y +++ b/util/cgg/bootgram.y @@ -1876,7 +1876,12 @@ finishio() { p=codestrings[i]; fprintf(cfile,"\t\""); while (*p) { - fprintf(cfile, !isascii(*p) || iscntrl(*p) ? "\\%03o" : "%c", (*p)&BMASK); + register int c = (*p) & BMASK; + if (! isascii(c) || iscntrl(c)) { + fprintf(cfile,"\\%c%c%c",((c>>6) &03)+'0', + ((c>>3)&07)+'0',(c&07)+'0'); + } + else putc(c, cfile); p++; } fprintf(cfile,"\",\n"); @@ -1944,7 +1949,7 @@ finishio() { c3coercs[i].c3_codep); fprintf(cfile,"};\n\n"); for (i=0;irregvar<0 && (machprops[i].propset.set_val[j>>4]&(1<<(j&017)))) @@ -1954,7 +1959,7 @@ finishio() { } fprintf(cfile,"struct reginfo **reglist[] = {\n"); for (i=0;i Date: Tue, 10 Feb 1987 12:49:08 +0000 Subject: [PATCH 0799/1625] removed some %0's --- doc/cg.doc | 2 +- doc/ncg.doc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/cg.doc b/doc/cg.doc index 32ff45fe..342fe8d0 100644 --- a/doc/cg.doc +++ b/doc/cg.doc @@ -1121,7 +1121,7 @@ Example mach.h for the PDP-11 #define cst_fmt "$%d." #define off_fmt "%d." -#define ilb_fmt "I%02x%x" +#define ilb_fmt "I%x_%x" #define dlb_fmt "_%d" #define hol_fmt "hol%d" diff --git a/doc/ncg.doc b/doc/ncg.doc index 16614b87..a470d242 100644 --- a/doc/ncg.doc +++ b/doc/ncg.doc @@ -2097,7 +2097,7 @@ Example mach.h for the PDP-11 #define cst_fmt "$%d." #define off_fmt "%d." -#define ilb_fmt "I%02x%x" +#define ilb_fmt "I%x_%x" #define dlb_fmt "_%d" #define hol_fmt "hol%d" From 0065209b5ac5aa4c0288680dafe67cefa51276e8 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 10 Feb 1987 16:50:32 +0000 Subject: [PATCH 0800/1625] Added some code to handle -Oego,opt,asopt and the like. By default, optimizers can be excluded by giving them a negative priority in the description files. This is currently done for the global optimizer --- util/ack/data.h | 4 +++- util/ack/main.c | 2 ++ util/ack/scan.c | 7 ++++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/util/ack/data.h b/util/ack/data.h index 5208efc9..f9f6d1a1 100644 --- a/util/ack/data.h +++ b/util/ack/data.h @@ -5,7 +5,9 @@ EXTERN char *stopsuffix; /* Suffix to stop at */ EXTERN char *machine; /* The machine id */ EXTERN char *callname; /* argv[0] */ -EXTERN char *rts; /* The runtime-system id */ +EXTERN char *rts; /* The runtime-system */ +EXTERN char *rtsuf; /* The runtime-system module suffix */ +EXTERN char *Optlist; /* Which optimizers */ EXTERN list_head arguments; /* List of arguments */ EXTERN list_head flags; /* List of flags */ diff --git a/util/ack/main.c b/util/ack/main.c index e4432de5..3a68bf28 100644 --- a/util/ack/main.c +++ b/util/ack/main.c @@ -175,6 +175,8 @@ vieuwargs(argc,argv) char **argv ; { hide=YES ; break ; case 'O': Optflag++ ; + Optlist= &argp[2] ; + eaten=1 ; break ; case 'v': if ( argp[2] ) { v_flag += atoi(&argp[2]) ; diff --git a/util/ack/scan.c b/util/ack/scan.c index a43193fc..67f00b43 100644 --- a/util/ack/scan.c +++ b/util/ack/scan.c @@ -84,6 +84,7 @@ try(f_scan,suffix) list_elem *f_scan; char *suffix; { scan_found(); return ; } + if (! f_scan) return; scanlist(f_scan, scan) { trafo= t_cont(*scan) ; if ( satisfy(trafo,suffix) ) { @@ -129,10 +130,10 @@ try(f_scan,suffix) list_elem *f_scan; char *suffix; { scan_found() ; return ; } - if ( l_next(*scan) ) { - try(l_next(*scan),trafo->t_out); + if (! l_next(*scan) && !stopsuffix) { + scan_found() ; } else { - if ( !stopsuffix ) scan_found() ; + try(l_next(*scan),trafo->t_out); } trafo->t_scan= NO ; } From 13ab16643c39f948569110fd84f39161f355dc04 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 10 Feb 1987 16:51:57 +0000 Subject: [PATCH 0801/1625] Added some code to handle -Oego,opt,asopt etc --- util/ack/rmach.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/util/ack/rmach.c b/util/ack/rmach.c index 16b3c893..8b3af83d 100644 --- a/util/ack/rmach.c +++ b/util/ack/rmach.c @@ -102,6 +102,21 @@ setlist(name) char *name ; { #endif } +static int inoptlist(nm) + char *nm ; +{ + register char *p=Optlist ; + + while ( p && *p ) { + register char *q=nm ; + + while ( *q!='\0' && *q++==*p ) p++ ; + if ( *q=='\0' && ( *p=='\0' || *p==',' ) ) return 1 ; + while ( *p!='\0' && *p++!=',' ) /* nothing */ ; + } + return 0; +} + intrf() { register trf *new ; register char *ptr ; @@ -266,6 +281,10 @@ intrf() { if ( new->t_needed ) vprint("\tneeded: %s\n",new->t_needed) ; } #endif + if ( new->t_optim && inoptlist(new->t_name) ) { + new->t_priority++ ; + if ( new->t_priority < 0 ) new->t_priority=0 ; + } l_add(&tr_list,(char *)new) ; } From 3a69039b734d31b04a021e16fb47841f15df4764 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 10 Feb 1987 17:18:16 +0000 Subject: [PATCH 0802/1625] *** empty log message *** --- mach/6500/cg/table | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mach/6500/cg/table b/mach/6500/cg/table index fa3f8cbb..5ce2ae9c 100644 --- a/mach/6500/cg/table +++ b/mach/6500/cg/table @@ -1558,7 +1558,10 @@ cii | R16 | | | | cui | | | | cii | ciu | | | | cii | -cuu | | | | asp 4 | +cuu | | | | cii | +loc loc cui $1==$2 | | | | | +loc loc ciu $1==$2 | | | | | +loc loc cuu $1==2 && $2==4 | | | | loc 0 | /* GROUP 9 - LOGICAL */ From 93ebbf2e71e02876fc1e1b77ad7c76ef7af2d0cf Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 11 Feb 1987 12:47:45 +0000 Subject: [PATCH 0803/1625] when printing floats in "e"-format, trailing zeros are significant! --- lang/basic/lib/print.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/lang/basic/lib/print.c b/lang/basic/lib/print.c index a335f968..16c48598 100644 --- a/lang/basic/lib/print.c +++ b/lang/basic/lib/print.c @@ -31,25 +31,31 @@ _str(f,buffer) double f; char *buffer; { - char *c; - c= buffer; + register char *c = buffer; + int eformat = 0; if( f>=0){ - if( f> 1.0e8) + if( f> 1.0e8) { + eformat = 1; sprintf(buffer," %e",f); + } else sprintf(buffer," %f",f); c++; }else { - if(-f> 1.0e8) + if(-f> 1.0e8) { + eformat = 1; sprintf(buffer,"-%e",-f); + } else sprintf(buffer,"-%f",-f); } - for( ; *c && *c!= ' ';c++) ; - c--; - while( c>buffer && *c== '0') - { - *c= 0;c--; + if (! eformat) { + for( ; *c && *c!= ' ';c++) ; + c--; + while( c>buffer && *c== '0') + { + *c= 0;c--; + } + if( *c=='.') *c=0; } - if( *c=='.') *c=0; strcat(buffer," "); } _prfnum(f) From eba2613668ea659e0d6a7b44c86f3808fed329cd Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 11 Feb 1987 14:29:27 +0000 Subject: [PATCH 0804/1625] many bug fixes --- lang/basic/src.old/basic.lex | 40 +++++++++++++++++++---------------- lang/basic/src.old/basic.yacc | 29 ++++++++++++++----------- lang/basic/src.old/gencode.c | 7 ++++-- lang/basic/src.old/graph.c | 2 +- lang/basic/src.old/parsepar.c | 10 +++++---- lang/basic/src.old/util.c | 20 ++++++++++++------ 6 files changed, 64 insertions(+), 44 deletions(-) diff --git a/lang/basic/src.old/basic.lex b/lang/basic/src.old/basic.lex index 526b37cf..b901ca63 100644 --- a/lang/basic/src.old/basic.lex +++ b/lang/basic/src.old/basic.lex @@ -44,12 +44,11 @@ Key keywords [] ={ "else", ELSESYM, 0, 0, "end", ENDSYM, 0, 0, "eof", FUNCTION, EOFSYM, 0, +"eqv", BOOLOP, EQVSYM, 0, "erase", ILLEGAL, 0, 0, "error", ERRORSYM, 0, 0, "err", ERRSYM, 0, 0, "erl", ERLSYM, 0, 0, -"else", ELSESYM, 0, 0, -"eqv", BOOLOP, EQVSYM, 0, "exp", FUNCTION, EXPSYM, 0, "field", FIELDSYM, 0, 0, "fix", FUNCTION, FIXSYM, 0, @@ -309,23 +308,29 @@ readconstant() number() { long i1; - double f,dec; - int minflag; + double atof(); register char *c; + int overflow = 0; + char cx; i1=0; c=cptr; while(isdigit(*c)){ i1= i1*10 + *c-'0'; + if (i1 < 0) overflow = 1; c++; } - cptr=c; if( *c != '.'){ - if( i1> MAXINT || i1 MAXINT || i1': if( *(c+1)=='='){ c++;c++;cptr=c; yylval.integer= GESYM;return(RELOP); diff --git a/lang/basic/src.old/basic.yacc b/lang/basic/src.old/basic.yacc index 091956bc..10c1d20c 100644 --- a/lang/basic/src.old/basic.yacc +++ b/lang/basic/src.old/basic.yacc @@ -15,7 +15,6 @@ %token ERRSYM %token ERLSYM %token ERRORSYM -%token ELSESYM %token FIELDSYM %token FORSYM %token FUNCTION @@ -353,8 +352,8 @@ format : USINGSYM STRVALUE ';' { loadstr($2);} | /* empty */ {formatstring=0;} printlist: expression { printstmt($1); $$=1;} - | ',' { zone(0); $$=0;} - | ';' { zone(1); $$=0;} + | ',' { zone(1); $$=0;} + | ';' { zone(0); $$=0;} | printlist expression { printstmt($2); $$=1;} | printlist ',' { zone(1);$$=0;} | printlist ';' { zone(0);$$=0;} @@ -405,25 +404,31 @@ indexed : identifier '(' {newarrayload($1);} ; -expression: negation - | negation BOOLOP expression {$$=boolop($1,$3,$2);} +expression: + negation + | expression BOOLOP expression {$$=boolop($1,$3,$2);} + ; negation: NOTSYM compare {$$=boolop($2,0,NOTSYM);} | compare ; + compare : sum | sum RELOP sum {$$=relop($1,$3,$2);} | sum '=' sum {$$=relop($1,$3,'=');} + ; sum : term - | term '-' sum {$$=plusmin($1,$3,'-');} - | term '+' sum {$$=plusmin($1,$3,'+');} + | sum '-' sum {$$=plusmin($1,$3,'-');} + | sum '+' sum {$$=plusmin($1,$3,'+');} + ; term : factor | factor '^' factor {$$=power($1,$3);} - | factor '*' term {$$=muldiv($1,$3,'*');} - | factor '\\' term {$$=muldiv($1,$3,'\\');} - | factor '/' term {$$=muldiv($1,$3,'/');} - | factor MODSYM term {$$=muldiv($1,$3,MODSYM);} + | term '*' term {$$=muldiv($1,$3,'*');} + | term '\\' term {$$=muldiv($1,$3,'\\');} + | term '/' term {$$=muldiv($1,$3,'/');} + | term MODSYM term {$$=muldiv($1,$3,MODSYM);} + ; factor : INTVALUE {$$=loadint(ival);} | '(' expression ')' {$$=$2;} | '-' factor { $$=negate($2);} @@ -440,7 +445,7 @@ factor : INTVALUE {$$=loadint(ival);} | funcname { $$=fcnend(0);} | funcname funccall ')' { $$=fcnend($2);} | MIDSYM '$' midparms - { warning("Unsupported function call"); + { emcode("cal","$_mid"); emcode("asp",EMINTSIZE); emcode("asp",EMINTSIZE); diff --git a/lang/basic/src.old/gencode.c b/lang/basic/src.old/gencode.c index 8efd79f5..024fb451 100644 --- a/lang/basic/src.old/gencode.c +++ b/lang/basic/src.old/gencode.c @@ -50,8 +50,11 @@ int nr; /* save location on tmpfile */ currline->offset= ftell(tmpfile); fprintf(tmpfile,"%d\n",currline->emlabel); - fprintf(tmpfile," lin %d\n",nr); - emlinecount += 2; + emlinecount++; + if (! nolins) { + fprintf(tmpfile," lin %d\n",nr); + emlinecount++; + } if( tronoff || traceflag) { emcode("loc",itoa(nr)); emcode("cal","$_trace"); diff --git a/lang/basic/src.old/graph.c b/lang/basic/src.old/graph.c index c09b65db..545d499d 100644 --- a/lang/basic/src.old/graph.c +++ b/lang/basic/src.old/graph.c @@ -45,7 +45,7 @@ linewarnings() { if( !srchline(l->linenr)) { - printf("ERROR: line %d not defined\n",l->linenr); + fprintf(stderr,"ERROR: line %d not defined\n",l->linenr); errorcnt++; } l=l->nextlist; diff --git a/lang/basic/src.old/parsepar.c b/lang/basic/src.old/parsepar.c index 15ef90b9..df016ff4 100644 --- a/lang/basic/src.old/parsepar.c +++ b/lang/basic/src.old/parsepar.c @@ -4,12 +4,12 @@ static char rcs_id[] = "$Header$" ; #endif -int listing; /* -l listing required */ +int listing; /* -E listing required */ int debug; /* -d compiler debugging */ -int wflag=1; /* -w no warnings */ +int wflag=0; /* -w no warnings */ int hflag=0; /* -h to split EM program */ int traceflag=0; /* generate line tracing code */ -int nolins=0; /* generate no LIN statements */ +int nolins=0; /* -l: generate no LIN statements */ parseparams(argc,argv) int argc; @@ -37,8 +37,9 @@ char **argv; threshold= THRESHOLD; break; case 'd': debug++; break; - case 'l': nolins++; break; /* no EM lin statements */ + case 'L': nolins++; break; /* no EM lin statements */ case 'E': listing++; break; /* generate full listing */ + case 'w': wflag++; break; } else { /* new input file */ switch ( files++ ) { @@ -49,4 +50,5 @@ char **argv; default:fatal("Too many file arguments") ; } } + if (files < 3) fatal("Too few file arguments"); } diff --git a/lang/basic/src.old/util.c b/lang/basic/src.old/util.c index 7ef314dc..3a1d2acc 100644 --- a/lang/basic/src.old/util.c +++ b/lang/basic/src.old/util.c @@ -12,29 +12,35 @@ int errorcnt; warning(str) char *str; { - printf("WARNING:%s\n",str); + if (! wflag) Xerror("WARNING",str); } error(str) char *str; { - extern int listing,yylineno; - if( !listing) printf("LINE %d:",yylineno); - printf("ERROR:%s\n",str); + Xerror("ERROR",str); errorcnt++; } +Xerror(type,str) +char *str; +char *type; +{ + extern int listing,yylineno; + if( !listing) fprintf(stderr,"LINE %d:",yylineno); + fprintf(stderr,"%s:%s\n",type,str); +} fatal(str) char *str; { - printf("FATAL:%s\n",str); + Xerror("FATAL",str); exit(-1); } notyetimpl() { - printf("WARNING: not yet implemented\n"); + warning("not yet implemented"); } illegalcmd() { - printf("WARNING: illegal command\n"); + warning("illegal command"); } char *itoa(i) int i; From 800cfe496e4190d51105d08a8c909adea1727b93 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 11 Feb 1987 14:49:14 +0000 Subject: [PATCH 0805/1625] other place for include files --- lib/i86/descr | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/i86/descr b/lib/i86/descr index 89fbb865..c313e65a 100644 --- a/lib/i86/descr +++ b/lib/i86/descr @@ -10,7 +10,7 @@ var M=i86 var LIB=lib/{M}/tail_ var RT=lib/{M}/head_ var CPP_F=-Dunix -var INCLUDES=-I{EM}/include -I/usr/include +var INCLUDES=-I{EM}/include/_tail_cc var ALIGN=-a0:2 -a1:2 -a2:2 -a3:2 name be from .m.g @@ -21,7 +21,7 @@ name be need .e end name as - from .s + from .s.so to .o program {EM}/lib/{M}/as args - -o > < @@ -44,7 +44,7 @@ end name cv from .out to .cv - program {EM}/lib/{M}/cv_ix + program {EM}/lib/{M}/cv args < > outfile a.out end From 711710211c36ccb50a935f6647ea73bcdd767140 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 11 Feb 1987 15:41:09 +0000 Subject: [PATCH 0806/1625] *** empty log message *** --- lang/basic/src.old/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/basic/src.old/Makefile b/lang/basic/src.old/Makefile index d6d2f82e..dfc174e7 100644 --- a/lang/basic/src.old/Makefile +++ b/lang/basic/src.old/Makefile @@ -5,7 +5,7 @@ h=$d/h l=$d/lib INSTALL=$l/em_bem -CFLAGS = -I$h +CFLAGS = -I$h -O FILES= bem.o y.tab.o symbols.o initialize.o compile.o \ parsepar.o yywrap.o gencode.o util.o graph.o \ From 3ef739b3e6b8719cff4a6d71e716ababec54c78f Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 11 Feb 1987 16:05:25 +0000 Subject: [PATCH 0807/1625] bug fix: csa descriptors contained upb instead of upb - lwb. --- lang/basic/src.old/graph.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lang/basic/src.old/graph.c b/lang/basic/src.old/graph.c index 545d499d..ee0c86c0 100644 --- a/lang/basic/src.old/graph.c +++ b/lang/basic/src.old/graph.c @@ -220,7 +220,7 @@ int type; descr= genlabel(); firstlabel=genlabel(); fprintf(tmpfile,"l%d\n",descr); emlinecount++; - fprintf(tmpfile," rom *%d,1,%d\n",firstlabel,jumpcnt); emlinecount++; + fprintf(tmpfile," rom *%d,1,%d\n",firstlabel,jumpcnt-1); emlinecount++; l= jumphead; while( l) { @@ -244,7 +244,7 @@ int type; descr= genlabel(); firstlabel=genlabel(); fprintf(tmpfile,"l%d\n",descr); emlinecount++; - fprintf(tmpfile," rom *%d,1,%d\n",firstlabel,jumpcnt); emlinecount++; + fprintf(tmpfile," rom *%d,1,%d\n",firstlabel,jumpcnt-1); emlinecount++; l= jumphead; while( l) { From 5bf0a04c21ea5e45fea2dac4f5112cc22a63249d Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 12 Feb 1987 10:56:16 +0000 Subject: [PATCH 0808/1625] Initial revision --- include/_tail_mon/sys/timeb.h | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 include/_tail_mon/sys/timeb.h diff --git a/include/_tail_mon/sys/timeb.h b/include/_tail_mon/sys/timeb.h new file mode 100644 index 00000000..66311242 --- /dev/null +++ b/include/_tail_mon/sys/timeb.h @@ -0,0 +1,6 @@ +struct timeb { + time_t time; + u_short millitm; + short timezone; + short dstflag; +}; From 058899081dade0e61f4d29daeea16ebb398ca00f Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 12 Feb 1987 13:36:55 +0000 Subject: [PATCH 0809/1625] exporting EODDZ, etc --- mach/i86/libsys/head_em.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/i86/libsys/head_em.s b/mach/i86/libsys/head_em.s index 956765b1..ce19ce8f 100644 --- a/mach/i86/libsys/head_em.s +++ b/mach/i86/libsys/head_em.s @@ -2,7 +2,7 @@ .define begtext,begdata,begbss .define hol0,.reghp,.limhp,.trppc,.ignmask -.define ERANGE,ESET,EHEAP,ECASE,EILLINS +.define ERANGE,ESET,EHEAP,ECASE,EILLINS,EIDIVZ,EODDZ .extern _end .extern np From dea3101fba70523788d23dd63082ece313d99bc8 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 12 Feb 1987 13:54:37 +0000 Subject: [PATCH 0810/1625] forgot a continue. --- util/led/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/led/main.c b/util/led/main.c index 3b7e2376..1b395887 100644 --- a/util/led/main.c +++ b/util/led/main.c @@ -424,7 +424,7 @@ complete_sections() continue; outsect[sectindex].os_size += sect_comm[sectindex]; - if (flagword & RFLAG) + if (flagword & RFLAG) continue; outsect[sectindex].os_lign = tstbit(sectindex, lignmap) ? sect_lign[sectindex] : 1; if (tstbit(sectindex, basemap)) { From 6b92209e5151130aaefa2b925f99634eccbcab3c Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 13 Feb 1987 09:40:08 +0000 Subject: [PATCH 0811/1625] Made to work with some other compilers --- modules/src/object/rd_bytes.c | 9 +++++++-- modules/src/object/wr_bytes.c | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/modules/src/object/rd_bytes.c b/modules/src/object/rd_bytes.c index e46f4cb4..3c9822ff 100644 --- a/modules/src/object/rd_bytes.c +++ b/modules/src/object/rd_bytes.c @@ -1,5 +1,10 @@ #define MININT (1 << (sizeof(int) * 8 - 1)) -#define MAXCHUNK (-(MININT + 1)) /* Highest count we write(2). */ +#define MAXCHUNK (~MININT) /* Highest count we read(2). */ +/* Unfortunately, MAXCHUNK is too large with some compilers. Put it in + an int! +*/ + +int maxchunk = MAXCHUNK; /* * We don't have to worry about byte order here. @@ -12,7 +17,7 @@ rd_bytes(fd, string, cnt) { while (cnt) { - register int n = cnt >= MAXCHUNK ? MAXCHUNK : cnt; + register int n = cnt >= maxchunk ? maxchunk : cnt; if (read(fd, string, n) != n) rd_fatal(); diff --git a/modules/src/object/wr_bytes.c b/modules/src/object/wr_bytes.c index 8dccc4b1..55e8932e 100644 --- a/modules/src/object/wr_bytes.c +++ b/modules/src/object/wr_bytes.c @@ -1,5 +1,10 @@ #define MININT (1 << (sizeof(int) * 8 - 1)) -#define MAXCHUNK (-(MININT + 1)) /* Highest count we write(2). */ +#define MAXCHUNK (~MININT) /* Highest count we write(2). */ +/* Notice that MAXCHUNK itself might be too large with some compilers. + You have to put it in an int! +*/ + +int maxchunk = MAXCHUNK; /* * Just write "cnt" bytes to file-descriptor "fd". @@ -10,7 +15,7 @@ wr_bytes(fd, string, cnt) { while (cnt) { - register int n = cnt >= MAXCHUNK ? MAXCHUNK : cnt; + register int n = cnt >= maxchunk ? maxchunk : cnt; if (write(fd, string, n) != n) wr_fatal(); From e40457dada03aa63283a9bfb35d5b778a843a921 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 13 Feb 1987 12:41:31 +0000 Subject: [PATCH 0812/1625] Some extra patterns added. --- mach/i86/cg/table | 65 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 14 deletions(-) diff --git a/mach/i86/cg/table b/mach/i86/cg/table index 3929bd02..5d56006a 100644 --- a/mach/i86/cg/table +++ b/mach/i86/cg/table @@ -193,6 +193,8 @@ loc | | | {ANYCON, $1} | | ldc | | | {ANYCON, highw(1)} {ANYCON, loww(1)} | | lol | | | {LOCAL2, $1, 2} | | loe | | | {EXTERN2, $1} | | +loe loe $1==$2 | | allocate(ADDREG={EXTERN2, $1}) | %[a] %[a] | | +lol lol $1==$2 | | allocate(ADDREG={LOCAL2, $1, 2})| %[a] %[a] | | lil | | allocate(ADDREG={ind_regoff2, bp, tostring($1)}) | {ind_reg2, %[a]} | | lof | nocoercions : reg_off | @@ -804,6 +806,7 @@ adp $1==1 | nocoercions : reg_off | | ... | X_REG | "inc %[1]" erase(%[1]) setcc(%[1]) | %[1] | | (1,2) +... | X_ADDREG | | {reg_off, %[1], tostring($1)} | | adp $1 == 0-1 | nocoercions : reg_off | | {reg_off, %[1.reg],%[1.off]+tostring($1)} | | ... | nocoercions : ADDR_EXTERN | | @@ -814,6 +817,7 @@ adp $1 == 0-1 | nocoercions : reg_off | | ... | X_REG | "dec %[1]" erase(%[1]) setcc(%[1]) | %[1] | | (1,2) +... | X_ADDREG | | {reg_off, %[1], tostring($1)} | | adp | nocoercions : reg_off | | {reg_off, %[1.reg],%[1.off]+"+"+tostring($1)} | | ... | nocoercions : ADDR_EXTERN | | @@ -975,21 +979,29 @@ lol adi stl $1==$3 && $2==2 | regorconst | remove(locals, %[ind]>=$1 && %[ind]<$1+2 ) "add $1(bp),%[1]" setcc({LOCAL2, $1, 2}) | | | +ldl adi sdl $1==$3 && $2==4 | regorconst regorconst | + remove(indexed) + remove(locals, %[ind]>=$1 && %[ind]<$1+4 ) + "add $1(bp),%[1]" + "adc %($1+2%)(bp),%[2]" | | | lol ngi stl $1==$3 && $2==2 | | remove(indexed) remove(locals, %[ind]>=$1 && %[ind]<$1+2 ) "neg $1(bp)" setcc({LOCAL2, $1, 2}) | | | +ldl ngi sdl $1==$3 && $2==4 | | + remove(indexed) + remove(locals, %[ind]>=$1 && %[ind]<$1+4 ) + "neg $1(bp)" + "neg %($1+2%)(bp)" + "sbb %($1+2%)(bp,0" | | | lol ads stl $1==$3 && $2==2 | regorconst | remove(indexed) remove(locals, %[ind]>=$1 && %[ind]<$1+2 ) "add $1(bp),%[1]" setcc({LOCAL2, $1, 2}) | | | -lol adp stl $1==$3 | | - remove(indexed) - remove(locals, %[ind]>=$1 && %[ind]<$1+2 ) - "add $1(bp),$2" - setcc({LOCAL2, $1, 2}) | | | +lol lol adp stl $1==$2 && $1==$4 | | + allocate(ADDREG={LOCAL2,$1,2}) | %[a] | lol $2 adp $3 stl $2 | lol adp stl $1==$3 && $2==1 | | remove(indexed) remove(locals, %[ind]>=$1 && %[ind]<$1+2 ) @@ -1000,6 +1012,11 @@ lol adp stl $1==$3 && $2==0-1 | | remove(locals, %[ind]>=$1 && %[ind]<$1+2 ) "dec $1(bp)" setcc({LOCAL2, $1, 2}) | | | +lol adp stl $1==$3 | | + remove(indexed) + remove(locals, %[ind]>=$1 && %[ind]<$1+2 ) + "add $1(bp),$2" + setcc({LOCAL2, $1, 2}) | | | lol and stl $1==$3 && $2==2 | regorconst | remove(indexed) remove(locals, %[ind]>=$1 && %[ind]<$1+2 ) @@ -1030,11 +1047,6 @@ lil ads sil $1==$3 && $2==2 | regorconst | remove(referals) "add (%[a]),%[1]" setcc({ind_reg2, %[a]}) | | | -lil adp sil $1==$3 | | - allocate(ADDREG={LOCAL2, $1, 2}) - remove(referals) - "add (%[a]),$2" - setcc({ind_reg2, %[a]}) | | | lil adp sil $1==$3 && $2==1 | | allocate(ADDREG={LOCAL2, $1, 2}) remove(referals) @@ -1045,6 +1057,11 @@ lil adp sil $1==$3 && $2==0-1 | | remove(referals) "dec (%[a])" setcc({ind_reg2, %[a]}) | | | +lil adp sil $1==$3 | | + allocate(ADDREG={LOCAL2, $1, 2}) + remove(referals) + "add (%[a]),$2" + setcc({ind_reg2, %[a]}) | | | lil and sil $1==$3 && $2==2 | regorconst | allocate(ADDREG={LOCAL2, $1, 2}) remove(referals) @@ -1064,18 +1081,25 @@ loe adi ste $1==$3 && $2==2 | regorconst | remove(indirects) "add ($1),%[1]" setcc({EXTERN2, $1}) | | | +lde adi sde $1==$3 && $2==4 | regorconst regorconst | + remove(indirects) + "add ($1),%[1]" + "adc ($1+2),%[2]" | | | loe ngi ste $1==$3 && $2==2 | | remove(indirects) "neg ($1)" setcc({EXTERN2, $1}) | | | +lde ngi sde $1==$3 && $2==4 | | + remove(indirects) + "neg ($1)" + "neg ($1+2)" + "sbb ($1+2),0" | | | loe ads ste $1==$3 && $2==2 | regorconst | remove(indirects) "add ($1),%[1]" setcc({EXTERN2, $1}) | | | -loe adp ste $1==$3 | | - remove(indirects) - "add ($1),$2" - setcc({EXTERN2, $1}) | | | +loe loe adp ste $1==$4 && $1==$4 | | + allocate(ADDREG={EXTERN2,$1}) | %[a] | loe $1 adp $3 ste $1 | loe adp ste $1==$3 && $2==1 | | remove(indirects) "inc ($1)" @@ -1084,6 +1108,10 @@ loe adp ste $1==$3 && $2==0-1 | | remove(indirects) "dec ($1)" setcc({EXTERN2, $1}) | | | +loe adp ste $1==$3 | | + remove(indirects) + "add ($1),$2" + setcc({EXTERN2, $1}) | | | loe and ste $1==$3 && $2==2 | regorconst | remove(indirects) "and ($1),%[1]" @@ -1129,11 +1157,19 @@ cff | CXREG DXREG | loc loc cii $1==1 && $2==2 | ACC | "cbw" samecc | ax | |(1,2) +... | ACC1 | + "cbw" + samecc | ax | |(1,2) loc loc cii $1==1 && $2==4 | ACC | allocate(DXREG) "cbw" "cwd" samecc | dx ax | |(2,7) +... | ACC1 | + allocate(DXREG) + "cbw" + "cwd" + samecc | dx ax | |(2,7) loc loc cii $1==2 && $2==4 | ACC | allocate(DXREG) "cwd" @@ -2135,6 +2171,7 @@ csb !defined($1)| rm-SIREG-DIREG X_SIREG X_DXREG | "jmp .csb2" erase(%[2]) erase(%[3]) | | | dup $1==2 | REG | | %[1] %[1] | | +... | ACC1 | | %[1] %[1] | | dup $1==4 | REG REG | | %[2] %[1] %[2] %[1] | | dup | | remove(ALL) move({ANYCON, $1}, cx) From a32f5d2a293f63e4aebe47266f81fbeff7a9beb6 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 13 Feb 1987 12:44:33 +0000 Subject: [PATCH 0813/1625] Added some buffering for writes --- mach/proto/as/comm4.c | 1 + mach/proto/as/comm6.c | 85 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 70 insertions(+), 16 deletions(-) diff --git a/mach/proto/as/comm4.c b/mach/proto/as/comm4.c index 3bfec2bc..db522c06 100644 --- a/mach/proto/as/comm4.c +++ b/mach/proto/as/comm4.c @@ -109,6 +109,7 @@ char **argv; pass_23(PASS_2); #endif pass_23(PASS_3); + oflush(); wr_close(); stop(); } diff --git a/mach/proto/as/comm6.c b/mach/proto/as/comm6.c index 347f7b92..6b2efc87 100644 --- a/mach/proto/as/comm6.c +++ b/mach/proto/as/comm6.c @@ -236,10 +236,23 @@ valu_t bytes; } #ifdef RELOCATION +static int nrelo; +static struct outrelo relobuf[100]; + +struct outrelo * +neworelo() +{ + if (nrelo == 100) { + wr_relo(relobuf, 100); + nrelo = 0; + } + return &relobuf[nrelo++]; +} + newrelo(s, n) short s; { - struct outrelo outrelo; + register struct outrelo *outrelo; int iscomm; if (rflag == 0) @@ -271,12 +284,13 @@ short s; return; } s &= ~S_VAR; - outrelo.or_type = (char)n; - outrelo.or_sect = (char)DOTTYP; + outrelo = neworelo(); + outrelo->or_type = (char)n; + outrelo->or_sect = (char)DOTTYP; #ifndef ASLD if (s == S_UND || iscomm) { assert(relonami != 0); - outrelo.or_nami = relonami-1; + outrelo->or_nami = relonami-1; relonami = 0; } else #endif @@ -285,28 +299,58 @@ short s; /* * use first non existing entry (argh) */ - outrelo.or_nami = outhead.oh_nname; + outrelo->or_nami = outhead.oh_nname; } else { /* * section symbols are at the end */ - outrelo.or_nami = outhead.oh_nname + outrelo->or_nami = outhead.oh_nname - outhead.oh_nsect + (s - S_MIN) ; } - outrelo.or_addr = (long)DOTVAL; - wr_relo(&outrelo, 1); + outrelo->or_addr = (long)DOTVAL; } #endif +static char sbuf[1024]; +static char *psbuf = sbuf; + +mwr_string(nm,len) + register char *nm; +{ + register char *q = psbuf; + + while (len--) { + *q++ = *nm++; + if (q == &sbuf[1024]) { + wr_string(sbuf,1024L); + q = sbuf; + } + } + psbuf = q; +} + +static struct outname obuf[100]; +static int nnames; + +static struct outname * +newoname() +{ + if (nnames == 100) { + wr_name(obuf,100); + nnames = 0; + } + return &obuf[nnames++]; +} + newsymb(name, type, desc, valu) register char *name; short type; short desc; valu_t valu; { - struct outname outname; + register struct outname *outname; if (name && *name == 0) name = 0; @@ -318,18 +362,27 @@ valu_t valu; return; } nname++; + outname = newoname(); if (name) { int len = strlen(name) + 1; - wr_string(name, len); - outname.on_foff = outhead.oh_nchar; + mwr_string(name, len); + outname->on_foff = outhead.oh_nchar; outhead.oh_nchar += len; } else - outname.on_foff = 0; - outname.on_type = type; - outname.on_desc = desc; - outname.on_valu = valu & ~((0xFFFFFFFF)<<(8*sizeof(valu_t))); - wr_name(&outname, 1); + outname->on_foff = 0; + outname->on_type = type; + outname->on_desc = desc; + outname->on_valu = valu & ~((0xFFFFFFFF)<<(8*sizeof(valu_t))); +} + +oflush() +{ +#ifdef RELOCATION + if (nrelo) wr_relo(relobuf,nrelo); +#endif + if (nnames) wr_name(obuf,nnames); + if (psbuf > sbuf) wr_string(sbuf, (long) (psbuf - sbuf)); } new_common(ip) From d64215e42ea98fc6e3ad81602bec7a03d126c36b Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 13 Feb 1987 13:39:30 +0000 Subject: [PATCH 0814/1625] Adapted to search for description files in either ~em/lib/descr/ or ~em/lib//descr --- util/ack/mktables.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/util/ack/mktables.c b/util/ack/mktables.c index 9adb9f44..bbdaed24 100644 --- a/util/ack/mktables.c +++ b/util/ack/mktables.c @@ -68,8 +68,15 @@ stop(filled) { } FILE *do_open(file) char *file ; { + FILE *fd; + strcpy(tail,file) ; - return fopen(dname,"r") ; + strcat(tail,"/"); + strcat(tail,"descr"); + if ((fd = fopen(dname,"r")) != NULL) return fd; + strcpy(tail,"descr/"); + strcat(tail,file); + return fopen(dname,"r"); } readm() { From 4bb65ddbf32c45c2b31dce3318f050c4930bee4b Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 13 Feb 1987 14:20:10 +0000 Subject: [PATCH 0815/1625] Added a "-f" flag to the "rm" --- lang/cem/ctest/ctgen/run1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/cem/ctest/ctgen/run1 b/lang/cem/ctest/ctgen/run1 index 4e958763..55277e7f 100755 --- a/lang/cem/ctest/ctgen/run1 +++ b/lang/cem/ctest/ctgen/run1 @@ -1,3 +1,3 @@ make "TS=$1" make "P=$1" -fk ../makefile $2 -rm $1.[ckmos] +rm -f $1.[ckmos] From e3edfec6e9a2747f64756a7813727f2e16349d20 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 13 Feb 1987 15:27:35 +0000 Subject: [PATCH 0816/1625] Added "standard" entries, rerun mkdep --- lang/cem/cemcom/Makefile | 585 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 542 insertions(+), 43 deletions(-) diff --git a/lang/cem/cemcom/Makefile b/lang/cem/cemcom/Makefile index 39250fcd..119158b6 100644 --- a/lang/cem/cemcom/Makefile +++ b/lang/cem/cemcom/Makefile @@ -58,7 +58,7 @@ CSRC = main.c idf.c declarator.c decspecs.c struct.c \ input.c domacro.c replace.c init.c options.c \ scan.c skip.c stack.c type.c ch7mon.c label.c eval.c \ switch.c ival.c conversion.c \ - blocks.c dataflow.c + blocks.c dataflow.c Version.c COBJ = main.o idf.o declarator.o decspecs.o struct.o \ expr.o ch7.o ch7bin.o cstoper.o arith.o \ asm.o code.o dumpidf.o error.o field.o\ @@ -66,27 +66,31 @@ COBJ = main.o idf.o declarator.o decspecs.o struct.o \ input.o domacro.o replace.o init.o options.o \ scan.o skip.o stack.o type.o ch7mon.o label.o eval.o \ switch.o ival.o conversion.o \ - blocks.o dataflow.o + blocks.o dataflow.o Version.o # Objects of other generated C files GCSRC = char.c symbol2str.c next.c GOBJ = char.o symbol2str.o next.o +STRSRC = code.str declar.str decspecs.str def.str expr.str field.str \ + idf.str macro.str stack.str stmt.str struct.str switch.str type.str # generated source files GHSTRSRC = code.h declar.h decspecs.h def.h expr.h field.h \ idf.h macro.h stack.h stmt.h struct.h switch.h type.h GSRC = $(GCSRC) $(GHSTRSRC) -# .h files generated by `make hfiles'; PLEASE KEEP THIS UP-TO-DATE! +# .h files generated by `make hfiles LLfiles'; PLEASE KEEP THIS UP-TO-DATE! GHSRC = botch_free.h dataflow.h debug.h density.h errout.h \ idepth.h idfsize.h ifdepth.h inputtype.h lapbuf.h \ maxincl.h nobitfield.h nofloat.h nopp.h \ - nparams.h numsize.h parbufsize.h pathlength.h \ + nparams.h numsize.h parbufsize.h pathlength.h Lpars.h \ strsize.h target_sizes.h textsize.h use_tmp.h spec_arith.h static.h -HFILES = LLlex.h align.h arith.h assert.h atw.h class.h faulty.h \ +HSRC = LLlex.h align.h arith.h assert.h atw.h class.h faulty.h \ input.h interface.h label.h level.h mes.h sizes.h specials.h \ - $(GHSRC) $(GHSTRSRC) tokenname.h Lpars.h file_info.h + file_info.h tokenname.h + +HFILES = $(HSRC) $(GHSRC) $(GHSTRSRC) # generated files, for 'make clean' only GENERATED = tab tokenfile.g Lpars.h LLfiles LL.output lint.out \ @@ -117,6 +121,15 @@ install: Main rm -f $(EMHOME)/lib/em_cemcom cp $(CURRDIR)/main $(EMHOME)/lib/em_cemcom +cmp: Main + -cmp $(CURRDIR)/main $(EMHOME)/lib/em_cemcom + +pr: + @pr makefile make.* tab.c char.tab Parameters $(HSRC) $(STRSRC) $(LSRC) $(CSRC) + +opr: + make pr | opr + clean: rm -f $(OBJ) $(GENERATED) (cd .. ; rm -rf Xsrc) @@ -191,45 +204,531 @@ Xlint: lint $(CDEFS) $(LINTFLAGS) $(SRC) #AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO -main.o: LLlex.h Lpars.h arith.h debug.h declar.h file_info.h idf.h input.h inputtype.h level.h maxincl.h nobitfield.h nofloat.h nopp.h spec_arith.h specials.h target_sizes.h tokenname.h type.h use_tmp.h -idf.o: LLlex.h Lpars.h align.h arith.h assert.h botch_free.h debug.h declar.h decspecs.h def.h file_info.h idf.h idfsize.h label.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h specials.h stack.h struct.h type.h -declarator.o: Lpars.h arith.h botch_free.h declar.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h type.h -decspecs.o: Lpars.h arith.h decspecs.h def.h level.h nobitfield.h nofloat.h spec_arith.h type.h -struct.o: LLlex.h Lpars.h align.h arith.h assert.h botch_free.h debug.h def.h field.h file_info.h idf.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h stack.h struct.h type.h -expr.o: LLlex.h Lpars.h arith.h botch_free.h declar.h decspecs.h def.h expr.h file_info.h idf.h label.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h type.h -ch7.o: Lpars.h arith.h assert.h debug.h def.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h struct.h type.h -ch7bin.o: Lpars.h arith.h botch_free.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h struct.h type.h -cstoper.o: Lpars.h arith.h assert.h debug.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h target_sizes.h type.h -arith.o: Lpars.h arith.h botch_free.h expr.h field.h idf.h label.h mes.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h -code.o: LLlex.h Lpars.h arith.h assert.h atw.h botch_free.h code.h dataflow.h debug.h declar.h decspecs.h def.h expr.h file_info.h idf.h label.h level.h mes.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h specials.h stack.h stmt.h type.h use_tmp.h -dumpidf.o: Lpars.h arith.h debug.h def.h expr.h field.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h stack.h static.h struct.h type.h -error.o: LLlex.h arith.h debug.h errout.h expr.h file_info.h label.h nofloat.h nopp.h spec_arith.h tokenname.h use_tmp.h -field.o: Lpars.h arith.h assert.h code.h debug.h expr.h field.h idf.h label.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h type.h -tokenname.o: LLlex.h Lpars.h arith.h file_info.h idf.h nofloat.h nopp.h spec_arith.h tokenname.h -LLlex.o: LLlex.h Lpars.h arith.h assert.h class.h debug.h def.h file_info.h idf.h idfsize.h input.h nofloat.h nopp.h numsize.h sizes.h spec_arith.h strsize.h -LLmessage.o: LLlex.h Lpars.h arith.h file_info.h idf.h nofloat.h nopp.h spec_arith.h -input.o: file_info.h input.h inputtype.h nopp.h -domacro.o: LLlex.h Lpars.h arith.h assert.h botch_free.h class.h debug.h file_info.h idf.h idfsize.h ifdepth.h input.h interface.h macro.h nofloat.h nopp.h nparams.h parbufsize.h spec_arith.h textsize.h -replace.o: LLlex.h arith.h assert.h class.h debug.h file_info.h idf.h input.h interface.h macro.h nofloat.h nopp.h pathlength.h spec_arith.h static.h strsize.h -init.o: class.h idf.h interface.h macro.h nopp.h -options.o: align.h arith.h botch_free.h class.h dataflow.h idf.h idfsize.h macro.h maxincl.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h use_tmp.h -scan.o: class.h idf.h input.h interface.h lapbuf.h macro.h nopp.h nparams.h -skip.o: LLlex.h arith.h class.h file_info.h input.h interface.h nofloat.h nopp.h spec_arith.h -stack.o: Lpars.h arith.h botch_free.h debug.h def.h idf.h level.h mes.h nobitfield.h nofloat.h nopp.h spec_arith.h stack.h struct.h type.h -type.o: Lpars.h align.h arith.h botch_free.h def.h idf.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h type.h -ch7mon.o: Lpars.h arith.h botch_free.h def.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h -label.o: Lpars.h arith.h def.h idf.h label.h level.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h -eval.o: Lpars.h align.h arith.h assert.h atw.h code.h dataflow.h debug.h def.h expr.h idf.h label.h level.h mes.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h stack.h type.h -switch.o: Lpars.h arith.h assert.h botch_free.h code.h debug.h density.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h switch.h type.h -ival.o: Lpars.h align.h arith.h assert.h class.h debug.h def.h expr.h field.h idf.h label.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h struct.h type.h -conversion.o: Lpars.h arith.h nobitfield.h nofloat.h sizes.h spec_arith.h type.h -blocks.o: arith.h atw.h label.h nofloat.h sizes.h spec_arith.h stack.h +main.o: LLlex.h +main.o: Lpars.h +main.o: arith.h +main.o: debug.h +main.o: declar.h +main.o: file_info.h +main.o: idf.h +main.o: input.h +main.o: inputtype.h +main.o: level.h +main.o: maxincl.h +main.o: nobitfield.h +main.o: nofloat.h +main.o: nopp.h +main.o: spec_arith.h +main.o: specials.h +main.o: target_sizes.h +main.o: tokenname.h +main.o: type.h +main.o: use_tmp.h +idf.o: LLlex.h +idf.o: Lpars.h +idf.o: align.h +idf.o: arith.h +idf.o: assert.h +idf.o: botch_free.h +idf.o: debug.h +idf.o: declar.h +idf.o: decspecs.h +idf.o: def.h +idf.o: file_info.h +idf.o: idf.h +idf.o: idfsize.h +idf.o: label.h +idf.o: level.h +idf.o: nobitfield.h +idf.o: nofloat.h +idf.o: nopp.h +idf.o: sizes.h +idf.o: spec_arith.h +idf.o: specials.h +idf.o: stack.h +idf.o: struct.h +idf.o: type.h +declarator.o: Lpars.h +declarator.o: arith.h +declarator.o: botch_free.h +declarator.o: declar.h +declarator.o: expr.h +declarator.o: idf.h +declarator.o: label.h +declarator.o: nobitfield.h +declarator.o: nofloat.h +declarator.o: nopp.h +declarator.o: sizes.h +declarator.o: spec_arith.h +declarator.o: type.h +decspecs.o: Lpars.h +decspecs.o: arith.h +decspecs.o: decspecs.h +decspecs.o: def.h +decspecs.o: level.h +decspecs.o: nobitfield.h +decspecs.o: nofloat.h +decspecs.o: spec_arith.h +decspecs.o: type.h +struct.o: LLlex.h +struct.o: Lpars.h +struct.o: align.h +struct.o: arith.h +struct.o: assert.h +struct.o: botch_free.h +struct.o: debug.h +struct.o: def.h +struct.o: field.h +struct.o: file_info.h +struct.o: idf.h +struct.o: level.h +struct.o: nobitfield.h +struct.o: nofloat.h +struct.o: nopp.h +struct.o: sizes.h +struct.o: spec_arith.h +struct.o: stack.h +struct.o: struct.h +struct.o: type.h +expr.o: LLlex.h +expr.o: Lpars.h +expr.o: arith.h +expr.o: botch_free.h +expr.o: declar.h +expr.o: decspecs.h +expr.o: def.h +expr.o: expr.h +expr.o: file_info.h +expr.o: idf.h +expr.o: label.h +expr.o: level.h +expr.o: nobitfield.h +expr.o: nofloat.h +expr.o: nopp.h +expr.o: sizes.h +expr.o: spec_arith.h +expr.o: type.h +ch7.o: Lpars.h +ch7.o: arith.h +ch7.o: assert.h +ch7.o: debug.h +ch7.o: def.h +ch7.o: expr.h +ch7.o: idf.h +ch7.o: label.h +ch7.o: nobitfield.h +ch7.o: nofloat.h +ch7.o: nopp.h +ch7.o: spec_arith.h +ch7.o: struct.h +ch7.o: type.h +ch7bin.o: Lpars.h +ch7bin.o: arith.h +ch7bin.o: botch_free.h +ch7bin.o: expr.h +ch7bin.o: idf.h +ch7bin.o: label.h +ch7bin.o: nobitfield.h +ch7bin.o: nofloat.h +ch7bin.o: nopp.h +ch7bin.o: spec_arith.h +ch7bin.o: struct.h +ch7bin.o: type.h +cstoper.o: Lpars.h +cstoper.o: arith.h +cstoper.o: assert.h +cstoper.o: debug.h +cstoper.o: expr.h +cstoper.o: idf.h +cstoper.o: label.h +cstoper.o: nobitfield.h +cstoper.o: nofloat.h +cstoper.o: nopp.h +cstoper.o: sizes.h +cstoper.o: spec_arith.h +cstoper.o: target_sizes.h +cstoper.o: type.h +arith.o: Lpars.h +arith.o: arith.h +arith.o: botch_free.h +arith.o: expr.h +arith.o: field.h +arith.o: idf.h +arith.o: label.h +arith.o: mes.h +arith.o: nobitfield.h +arith.o: nofloat.h +arith.o: nopp.h +arith.o: spec_arith.h +arith.o: type.h +code.o: LLlex.h +code.o: Lpars.h +code.o: arith.h +code.o: assert.h +code.o: atw.h +code.o: botch_free.h +code.o: code.h +code.o: dataflow.h +code.o: debug.h +code.o: declar.h +code.o: decspecs.h +code.o: def.h +code.o: expr.h +code.o: file_info.h +code.o: idf.h +code.o: label.h +code.o: level.h +code.o: mes.h +code.o: nobitfield.h +code.o: nofloat.h +code.o: nopp.h +code.o: sizes.h +code.o: spec_arith.h +code.o: specials.h +code.o: stack.h +code.o: stmt.h +code.o: type.h +code.o: use_tmp.h +dumpidf.o: Lpars.h +dumpidf.o: arith.h +dumpidf.o: debug.h +dumpidf.o: def.h +dumpidf.o: expr.h +dumpidf.o: field.h +dumpidf.o: idf.h +dumpidf.o: label.h +dumpidf.o: nobitfield.h +dumpidf.o: nofloat.h +dumpidf.o: nopp.h +dumpidf.o: spec_arith.h +dumpidf.o: stack.h +dumpidf.o: static.h +dumpidf.o: struct.h +dumpidf.o: type.h +error.o: LLlex.h +error.o: arith.h +error.o: debug.h +error.o: errout.h +error.o: expr.h +error.o: file_info.h +error.o: label.h +error.o: nofloat.h +error.o: nopp.h +error.o: spec_arith.h +error.o: tokenname.h +error.o: use_tmp.h +field.o: Lpars.h +field.o: arith.h +field.o: assert.h +field.o: code.h +field.o: debug.h +field.o: expr.h +field.o: field.h +field.o: idf.h +field.o: label.h +field.o: nobitfield.h +field.o: nofloat.h +field.o: nopp.h +field.o: sizes.h +field.o: spec_arith.h +field.o: type.h +tokenname.o: LLlex.h +tokenname.o: Lpars.h +tokenname.o: arith.h +tokenname.o: file_info.h +tokenname.o: idf.h +tokenname.o: nofloat.h +tokenname.o: nopp.h +tokenname.o: spec_arith.h +tokenname.o: tokenname.h +LLlex.o: LLlex.h +LLlex.o: Lpars.h +LLlex.o: arith.h +LLlex.o: assert.h +LLlex.o: class.h +LLlex.o: debug.h +LLlex.o: def.h +LLlex.o: file_info.h +LLlex.o: idf.h +LLlex.o: idfsize.h +LLlex.o: input.h +LLlex.o: nofloat.h +LLlex.o: nopp.h +LLlex.o: numsize.h +LLlex.o: sizes.h +LLlex.o: spec_arith.h +LLlex.o: strsize.h +LLmessage.o: LLlex.h +LLmessage.o: Lpars.h +LLmessage.o: arith.h +LLmessage.o: file_info.h +LLmessage.o: idf.h +LLmessage.o: nofloat.h +LLmessage.o: nopp.h +LLmessage.o: spec_arith.h +input.o: file_info.h +input.o: input.h +input.o: inputtype.h +input.o: nopp.h +domacro.o: LLlex.h +domacro.o: Lpars.h +domacro.o: arith.h +domacro.o: assert.h +domacro.o: botch_free.h +domacro.o: class.h +domacro.o: debug.h +domacro.o: file_info.h +domacro.o: idf.h +domacro.o: idfsize.h +domacro.o: ifdepth.h +domacro.o: input.h +domacro.o: interface.h +domacro.o: macro.h +domacro.o: nofloat.h +domacro.o: nopp.h +domacro.o: nparams.h +domacro.o: parbufsize.h +domacro.o: spec_arith.h +domacro.o: textsize.h +replace.o: LLlex.h +replace.o: arith.h +replace.o: assert.h +replace.o: class.h +replace.o: debug.h +replace.o: file_info.h +replace.o: idf.h +replace.o: input.h +replace.o: interface.h +replace.o: macro.h +replace.o: nofloat.h +replace.o: nopp.h +replace.o: pathlength.h +replace.o: spec_arith.h +replace.o: static.h +replace.o: strsize.h +init.o: class.h +init.o: idf.h +init.o: interface.h +init.o: macro.h +init.o: nopp.h +options.o: align.h +options.o: arith.h +options.o: botch_free.h +options.o: class.h +options.o: dataflow.h +options.o: idf.h +options.o: idfsize.h +options.o: macro.h +options.o: maxincl.h +options.o: nobitfield.h +options.o: nofloat.h +options.o: nopp.h +options.o: sizes.h +options.o: spec_arith.h +options.o: use_tmp.h +scan.o: class.h +scan.o: idf.h +scan.o: input.h +scan.o: interface.h +scan.o: lapbuf.h +scan.o: macro.h +scan.o: nopp.h +scan.o: nparams.h +skip.o: LLlex.h +skip.o: arith.h +skip.o: class.h +skip.o: file_info.h +skip.o: input.h +skip.o: interface.h +skip.o: nofloat.h +skip.o: nopp.h +skip.o: spec_arith.h +stack.o: Lpars.h +stack.o: arith.h +stack.o: botch_free.h +stack.o: debug.h +stack.o: def.h +stack.o: idf.h +stack.o: level.h +stack.o: mes.h +stack.o: nobitfield.h +stack.o: nofloat.h +stack.o: nopp.h +stack.o: spec_arith.h +stack.o: stack.h +stack.o: struct.h +stack.o: type.h +type.o: Lpars.h +type.o: align.h +type.o: arith.h +type.o: botch_free.h +type.o: def.h +type.o: idf.h +type.o: nobitfield.h +type.o: nofloat.h +type.o: nopp.h +type.o: sizes.h +type.o: spec_arith.h +type.o: type.h +ch7mon.o: Lpars.h +ch7mon.o: arith.h +ch7mon.o: botch_free.h +ch7mon.o: def.h +ch7mon.o: expr.h +ch7mon.o: idf.h +ch7mon.o: label.h +ch7mon.o: nobitfield.h +ch7mon.o: nofloat.h +ch7mon.o: nopp.h +ch7mon.o: spec_arith.h +ch7mon.o: type.h +label.o: Lpars.h +label.o: arith.h +label.o: def.h +label.o: idf.h +label.o: label.h +label.o: level.h +label.o: nobitfield.h +label.o: nofloat.h +label.o: nopp.h +label.o: spec_arith.h +label.o: type.h +eval.o: Lpars.h +eval.o: align.h +eval.o: arith.h +eval.o: assert.h +eval.o: atw.h +eval.o: code.h +eval.o: dataflow.h +eval.o: debug.h +eval.o: def.h +eval.o: expr.h +eval.o: idf.h +eval.o: label.h +eval.o: level.h +eval.o: mes.h +eval.o: nobitfield.h +eval.o: nofloat.h +eval.o: nopp.h +eval.o: sizes.h +eval.o: spec_arith.h +eval.o: stack.h +eval.o: type.h +switch.o: Lpars.h +switch.o: arith.h +switch.o: assert.h +switch.o: botch_free.h +switch.o: code.h +switch.o: debug.h +switch.o: density.h +switch.o: expr.h +switch.o: idf.h +switch.o: label.h +switch.o: nobitfield.h +switch.o: nofloat.h +switch.o: nopp.h +switch.o: spec_arith.h +switch.o: switch.h +switch.o: type.h +ival.o: Lpars.h +ival.o: align.h +ival.o: arith.h +ival.o: assert.h +ival.o: class.h +ival.o: debug.h +ival.o: def.h +ival.o: expr.h +ival.o: field.h +ival.o: idf.h +ival.o: label.h +ival.o: level.h +ival.o: nobitfield.h +ival.o: nofloat.h +ival.o: nopp.h +ival.o: sizes.h +ival.o: spec_arith.h +ival.o: struct.h +ival.o: type.h +conversion.o: Lpars.h +conversion.o: arith.h +conversion.o: nobitfield.h +conversion.o: nofloat.h +conversion.o: sizes.h +conversion.o: spec_arith.h +conversion.o: type.h +blocks.o: arith.h +blocks.o: atw.h +blocks.o: label.h +blocks.o: nofloat.h +blocks.o: sizes.h +blocks.o: spec_arith.h +blocks.o: stack.h dataflow.o: dataflow.h tokenfile.o: Lpars.h -declar.o: LLlex.h Lpars.h arith.h debug.h declar.h decspecs.h def.h expr.h field.h file_info.h idf.h label.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h struct.h type.h -statement.o: LLlex.h Lpars.h arith.h botch_free.h code.h debug.h def.h expr.h file_info.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h stack.h type.h -expression.o: LLlex.h Lpars.h arith.h expr.h file_info.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h -program.o: LLlex.h Lpars.h arith.h code.h declar.h decspecs.h def.h expr.h file_info.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h +declar.o: LLlex.h +declar.o: Lpars.h +declar.o: arith.h +declar.o: debug.h +declar.o: declar.h +declar.o: decspecs.h +declar.o: def.h +declar.o: expr.h +declar.o: field.h +declar.o: file_info.h +declar.o: idf.h +declar.o: label.h +declar.o: nobitfield.h +declar.o: nofloat.h +declar.o: nopp.h +declar.o: sizes.h +declar.o: spec_arith.h +declar.o: struct.h +declar.o: type.h +statement.o: LLlex.h +statement.o: Lpars.h +statement.o: arith.h +statement.o: botch_free.h +statement.o: code.h +statement.o: debug.h +statement.o: def.h +statement.o: expr.h +statement.o: file_info.h +statement.o: idf.h +statement.o: label.h +statement.o: nobitfield.h +statement.o: nofloat.h +statement.o: nopp.h +statement.o: spec_arith.h +statement.o: stack.h +statement.o: type.h +expression.o: LLlex.h +expression.o: Lpars.h +expression.o: arith.h +expression.o: expr.h +expression.o: file_info.h +expression.o: idf.h +expression.o: label.h +expression.o: nobitfield.h +expression.o: nofloat.h +expression.o: nopp.h +expression.o: spec_arith.h +expression.o: type.h +program.o: LLlex.h +program.o: Lpars.h +program.o: arith.h +program.o: code.h +program.o: declar.h +program.o: decspecs.h +program.o: def.h +program.o: expr.h +program.o: file_info.h +program.o: idf.h +program.o: label.h +program.o: nobitfield.h +program.o: nofloat.h +program.o: nopp.h +program.o: spec_arith.h +program.o: type.h Lpars.o: Lpars.h char.o: class.h symbol2str.o: Lpars.h From 8fb55701276e40d63b80bb9274024086336c96ba Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 13 Feb 1987 15:30:27 +0000 Subject: [PATCH 0817/1625] minor update --- lang/cem/cemcom/Makefile.erik | 562 +++++++++++++++++++++++++++++++--- 1 file changed, 524 insertions(+), 38 deletions(-) diff --git a/lang/cem/cemcom/Makefile.erik b/lang/cem/cemcom/Makefile.erik index 47c1dc49..dd19bb83 100644 --- a/lang/cem/cemcom/Makefile.erik +++ b/lang/cem/cemcom/Makefile.erik @@ -72,7 +72,7 @@ COBJ = main.o idf.o declarator.o decspecs.o struct.o \ input.o domacro.o replace.o init.o options.o \ scan.o skip.o stack.o type.o ch7mon.o label.o eval.o \ switch.o ival.o conversion.o \ - blocks.o dataflow.o + blocks.o dataflow.o Version.o # Objects of other generated C files GOBJ = char.o symbol2str.o next.o @@ -215,45 +215,531 @@ sim: cfiles $(SIM) $(SIMFLAGS) `sources $(COBJ)` $(GSRC) $(LSRC) #AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO -main.o: LLlex.h Lpars.h arith.h debug.h declar.h file_info.h idf.h input.h inputtype.h level.h maxincl.h nobitfield.h nofloat.h nopp.h spec_arith.h specials.h target_sizes.h tokenname.h type.h use_tmp.h -idf.o: LLlex.h Lpars.h align.h arith.h assert.h botch_free.h debug.h declar.h decspecs.h def.h file_info.h idf.h idfsize.h label.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h specials.h stack.h struct.h type.h -declarator.o: Lpars.h arith.h botch_free.h declar.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h type.h -decspecs.o: Lpars.h arith.h decspecs.h def.h level.h nobitfield.h nofloat.h spec_arith.h type.h -struct.o: LLlex.h Lpars.h align.h arith.h assert.h botch_free.h debug.h def.h field.h file_info.h idf.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h stack.h struct.h type.h -expr.o: LLlex.h Lpars.h arith.h botch_free.h declar.h decspecs.h def.h expr.h file_info.h idf.h label.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h type.h -ch7.o: Lpars.h arith.h assert.h debug.h def.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h struct.h type.h -ch7bin.o: Lpars.h arith.h botch_free.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h struct.h type.h -cstoper.o: Lpars.h arith.h assert.h debug.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h target_sizes.h type.h -arith.o: Lpars.h arith.h botch_free.h expr.h field.h idf.h label.h mes.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h -code.o: LLlex.h Lpars.h arith.h assert.h atw.h botch_free.h code.h dataflow.h debug.h declar.h decspecs.h def.h expr.h file_info.h idf.h label.h level.h mes.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h specials.h stack.h stmt.h type.h use_tmp.h -dumpidf.o: Lpars.h arith.h debug.h def.h expr.h field.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h stack.h static.h struct.h type.h -error.o: LLlex.h arith.h debug.h errout.h expr.h file_info.h label.h nofloat.h nopp.h spec_arith.h tokenname.h use_tmp.h -field.o: Lpars.h arith.h assert.h code.h debug.h expr.h field.h idf.h label.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h type.h -tokenname.o: LLlex.h Lpars.h arith.h file_info.h idf.h nofloat.h nopp.h spec_arith.h tokenname.h -LLlex.o: LLlex.h Lpars.h arith.h assert.h class.h debug.h def.h file_info.h idf.h idfsize.h input.h nofloat.h nopp.h numsize.h sizes.h spec_arith.h strsize.h -LLmessage.o: LLlex.h Lpars.h arith.h file_info.h idf.h nofloat.h nopp.h spec_arith.h -input.o: file_info.h input.h inputtype.h nopp.h -domacro.o: LLlex.h Lpars.h arith.h assert.h botch_free.h class.h debug.h file_info.h idf.h idfsize.h ifdepth.h input.h interface.h macro.h nofloat.h nopp.h nparams.h parbufsize.h spec_arith.h textsize.h -replace.o: LLlex.h arith.h assert.h class.h debug.h file_info.h idf.h input.h interface.h macro.h nofloat.h nopp.h pathlength.h spec_arith.h static.h strsize.h -init.o: class.h idf.h interface.h macro.h nopp.h -options.o: align.h arith.h botch_free.h class.h dataflow.h idf.h idfsize.h macro.h maxincl.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h use_tmp.h -scan.o: class.h idf.h input.h interface.h lapbuf.h macro.h nopp.h nparams.h -skip.o: LLlex.h arith.h class.h file_info.h input.h interface.h nofloat.h nopp.h spec_arith.h -stack.o: Lpars.h arith.h botch_free.h debug.h def.h idf.h level.h mes.h nobitfield.h nofloat.h nopp.h spec_arith.h stack.h struct.h type.h -type.o: Lpars.h align.h arith.h botch_free.h def.h idf.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h type.h -ch7mon.o: Lpars.h arith.h botch_free.h def.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h -label.o: Lpars.h arith.h def.h idf.h label.h level.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h -eval.o: Lpars.h align.h arith.h assert.h atw.h code.h dataflow.h debug.h def.h expr.h idf.h label.h level.h mes.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h stack.h type.h -switch.o: Lpars.h arith.h assert.h botch_free.h code.h debug.h density.h expr.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h switch.h type.h -ival.o: Lpars.h align.h arith.h assert.h class.h debug.h def.h expr.h field.h idf.h label.h level.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h struct.h type.h -conversion.o: Lpars.h arith.h nobitfield.h nofloat.h sizes.h spec_arith.h type.h -blocks.o: arith.h atw.h label.h nofloat.h sizes.h spec_arith.h stack.h +main.o: LLlex.h +main.o: Lpars.h +main.o: arith.h +main.o: debug.h +main.o: declar.h +main.o: file_info.h +main.o: idf.h +main.o: input.h +main.o: inputtype.h +main.o: level.h +main.o: maxincl.h +main.o: nobitfield.h +main.o: nofloat.h +main.o: nopp.h +main.o: spec_arith.h +main.o: specials.h +main.o: target_sizes.h +main.o: tokenname.h +main.o: type.h +main.o: use_tmp.h +idf.o: LLlex.h +idf.o: Lpars.h +idf.o: align.h +idf.o: arith.h +idf.o: assert.h +idf.o: botch_free.h +idf.o: debug.h +idf.o: declar.h +idf.o: decspecs.h +idf.o: def.h +idf.o: file_info.h +idf.o: idf.h +idf.o: idfsize.h +idf.o: label.h +idf.o: level.h +idf.o: nobitfield.h +idf.o: nofloat.h +idf.o: nopp.h +idf.o: sizes.h +idf.o: spec_arith.h +idf.o: specials.h +idf.o: stack.h +idf.o: struct.h +idf.o: type.h +declarator.o: Lpars.h +declarator.o: arith.h +declarator.o: botch_free.h +declarator.o: declar.h +declarator.o: expr.h +declarator.o: idf.h +declarator.o: label.h +declarator.o: nobitfield.h +declarator.o: nofloat.h +declarator.o: nopp.h +declarator.o: sizes.h +declarator.o: spec_arith.h +declarator.o: type.h +decspecs.o: Lpars.h +decspecs.o: arith.h +decspecs.o: decspecs.h +decspecs.o: def.h +decspecs.o: level.h +decspecs.o: nobitfield.h +decspecs.o: nofloat.h +decspecs.o: spec_arith.h +decspecs.o: type.h +struct.o: LLlex.h +struct.o: Lpars.h +struct.o: align.h +struct.o: arith.h +struct.o: assert.h +struct.o: botch_free.h +struct.o: debug.h +struct.o: def.h +struct.o: field.h +struct.o: file_info.h +struct.o: idf.h +struct.o: level.h +struct.o: nobitfield.h +struct.o: nofloat.h +struct.o: nopp.h +struct.o: sizes.h +struct.o: spec_arith.h +struct.o: stack.h +struct.o: struct.h +struct.o: type.h +expr.o: LLlex.h +expr.o: Lpars.h +expr.o: arith.h +expr.o: botch_free.h +expr.o: declar.h +expr.o: decspecs.h +expr.o: def.h +expr.o: expr.h +expr.o: file_info.h +expr.o: idf.h +expr.o: label.h +expr.o: level.h +expr.o: nobitfield.h +expr.o: nofloat.h +expr.o: nopp.h +expr.o: sizes.h +expr.o: spec_arith.h +expr.o: type.h +ch7.o: Lpars.h +ch7.o: arith.h +ch7.o: assert.h +ch7.o: debug.h +ch7.o: def.h +ch7.o: expr.h +ch7.o: idf.h +ch7.o: label.h +ch7.o: nobitfield.h +ch7.o: nofloat.h +ch7.o: nopp.h +ch7.o: spec_arith.h +ch7.o: struct.h +ch7.o: type.h +ch7bin.o: Lpars.h +ch7bin.o: arith.h +ch7bin.o: botch_free.h +ch7bin.o: expr.h +ch7bin.o: idf.h +ch7bin.o: label.h +ch7bin.o: nobitfield.h +ch7bin.o: nofloat.h +ch7bin.o: nopp.h +ch7bin.o: spec_arith.h +ch7bin.o: struct.h +ch7bin.o: type.h +cstoper.o: Lpars.h +cstoper.o: arith.h +cstoper.o: assert.h +cstoper.o: debug.h +cstoper.o: expr.h +cstoper.o: idf.h +cstoper.o: label.h +cstoper.o: nobitfield.h +cstoper.o: nofloat.h +cstoper.o: nopp.h +cstoper.o: sizes.h +cstoper.o: spec_arith.h +cstoper.o: target_sizes.h +cstoper.o: type.h +arith.o: Lpars.h +arith.o: arith.h +arith.o: botch_free.h +arith.o: expr.h +arith.o: field.h +arith.o: idf.h +arith.o: label.h +arith.o: mes.h +arith.o: nobitfield.h +arith.o: nofloat.h +arith.o: nopp.h +arith.o: spec_arith.h +arith.o: type.h +code.o: LLlex.h +code.o: Lpars.h +code.o: arith.h +code.o: assert.h +code.o: atw.h +code.o: botch_free.h +code.o: code.h +code.o: dataflow.h +code.o: debug.h +code.o: declar.h +code.o: decspecs.h +code.o: def.h +code.o: expr.h +code.o: file_info.h +code.o: idf.h +code.o: label.h +code.o: level.h +code.o: mes.h +code.o: nobitfield.h +code.o: nofloat.h +code.o: nopp.h +code.o: sizes.h +code.o: spec_arith.h +code.o: specials.h +code.o: stack.h +code.o: stmt.h +code.o: type.h +code.o: use_tmp.h +dumpidf.o: Lpars.h +dumpidf.o: arith.h +dumpidf.o: debug.h +dumpidf.o: def.h +dumpidf.o: expr.h +dumpidf.o: field.h +dumpidf.o: idf.h +dumpidf.o: label.h +dumpidf.o: nobitfield.h +dumpidf.o: nofloat.h +dumpidf.o: nopp.h +dumpidf.o: spec_arith.h +dumpidf.o: stack.h +dumpidf.o: static.h +dumpidf.o: struct.h +dumpidf.o: type.h +error.o: LLlex.h +error.o: arith.h +error.o: debug.h +error.o: errout.h +error.o: expr.h +error.o: file_info.h +error.o: label.h +error.o: nofloat.h +error.o: nopp.h +error.o: spec_arith.h +error.o: tokenname.h +error.o: use_tmp.h +field.o: Lpars.h +field.o: arith.h +field.o: assert.h +field.o: code.h +field.o: debug.h +field.o: expr.h +field.o: field.h +field.o: idf.h +field.o: label.h +field.o: nobitfield.h +field.o: nofloat.h +field.o: nopp.h +field.o: sizes.h +field.o: spec_arith.h +field.o: type.h +tokenname.o: LLlex.h +tokenname.o: Lpars.h +tokenname.o: arith.h +tokenname.o: file_info.h +tokenname.o: idf.h +tokenname.o: nofloat.h +tokenname.o: nopp.h +tokenname.o: spec_arith.h +tokenname.o: tokenname.h +LLlex.o: LLlex.h +LLlex.o: Lpars.h +LLlex.o: arith.h +LLlex.o: assert.h +LLlex.o: class.h +LLlex.o: debug.h +LLlex.o: def.h +LLlex.o: file_info.h +LLlex.o: idf.h +LLlex.o: idfsize.h +LLlex.o: input.h +LLlex.o: nofloat.h +LLlex.o: nopp.h +LLlex.o: numsize.h +LLlex.o: sizes.h +LLlex.o: spec_arith.h +LLlex.o: strsize.h +LLmessage.o: LLlex.h +LLmessage.o: Lpars.h +LLmessage.o: arith.h +LLmessage.o: file_info.h +LLmessage.o: idf.h +LLmessage.o: nofloat.h +LLmessage.o: nopp.h +LLmessage.o: spec_arith.h +input.o: file_info.h +input.o: input.h +input.o: inputtype.h +input.o: nopp.h +domacro.o: LLlex.h +domacro.o: Lpars.h +domacro.o: arith.h +domacro.o: assert.h +domacro.o: botch_free.h +domacro.o: class.h +domacro.o: debug.h +domacro.o: file_info.h +domacro.o: idf.h +domacro.o: idfsize.h +domacro.o: ifdepth.h +domacro.o: input.h +domacro.o: interface.h +domacro.o: macro.h +domacro.o: nofloat.h +domacro.o: nopp.h +domacro.o: nparams.h +domacro.o: parbufsize.h +domacro.o: spec_arith.h +domacro.o: textsize.h +replace.o: LLlex.h +replace.o: arith.h +replace.o: assert.h +replace.o: class.h +replace.o: debug.h +replace.o: file_info.h +replace.o: idf.h +replace.o: input.h +replace.o: interface.h +replace.o: macro.h +replace.o: nofloat.h +replace.o: nopp.h +replace.o: pathlength.h +replace.o: spec_arith.h +replace.o: static.h +replace.o: strsize.h +init.o: class.h +init.o: idf.h +init.o: interface.h +init.o: macro.h +init.o: nopp.h +options.o: align.h +options.o: arith.h +options.o: botch_free.h +options.o: class.h +options.o: dataflow.h +options.o: idf.h +options.o: idfsize.h +options.o: macro.h +options.o: maxincl.h +options.o: nobitfield.h +options.o: nofloat.h +options.o: nopp.h +options.o: sizes.h +options.o: spec_arith.h +options.o: use_tmp.h +scan.o: class.h +scan.o: idf.h +scan.o: input.h +scan.o: interface.h +scan.o: lapbuf.h +scan.o: macro.h +scan.o: nopp.h +scan.o: nparams.h +skip.o: LLlex.h +skip.o: arith.h +skip.o: class.h +skip.o: file_info.h +skip.o: input.h +skip.o: interface.h +skip.o: nofloat.h +skip.o: nopp.h +skip.o: spec_arith.h +stack.o: Lpars.h +stack.o: arith.h +stack.o: botch_free.h +stack.o: debug.h +stack.o: def.h +stack.o: idf.h +stack.o: level.h +stack.o: mes.h +stack.o: nobitfield.h +stack.o: nofloat.h +stack.o: nopp.h +stack.o: spec_arith.h +stack.o: stack.h +stack.o: struct.h +stack.o: type.h +type.o: Lpars.h +type.o: align.h +type.o: arith.h +type.o: botch_free.h +type.o: def.h +type.o: idf.h +type.o: nobitfield.h +type.o: nofloat.h +type.o: nopp.h +type.o: sizes.h +type.o: spec_arith.h +type.o: type.h +ch7mon.o: Lpars.h +ch7mon.o: arith.h +ch7mon.o: botch_free.h +ch7mon.o: def.h +ch7mon.o: expr.h +ch7mon.o: idf.h +ch7mon.o: label.h +ch7mon.o: nobitfield.h +ch7mon.o: nofloat.h +ch7mon.o: nopp.h +ch7mon.o: spec_arith.h +ch7mon.o: type.h +label.o: Lpars.h +label.o: arith.h +label.o: def.h +label.o: idf.h +label.o: label.h +label.o: level.h +label.o: nobitfield.h +label.o: nofloat.h +label.o: nopp.h +label.o: spec_arith.h +label.o: type.h +eval.o: Lpars.h +eval.o: align.h +eval.o: arith.h +eval.o: assert.h +eval.o: atw.h +eval.o: code.h +eval.o: dataflow.h +eval.o: debug.h +eval.o: def.h +eval.o: expr.h +eval.o: idf.h +eval.o: label.h +eval.o: level.h +eval.o: mes.h +eval.o: nobitfield.h +eval.o: nofloat.h +eval.o: nopp.h +eval.o: sizes.h +eval.o: spec_arith.h +eval.o: stack.h +eval.o: type.h +switch.o: Lpars.h +switch.o: arith.h +switch.o: assert.h +switch.o: botch_free.h +switch.o: code.h +switch.o: debug.h +switch.o: density.h +switch.o: expr.h +switch.o: idf.h +switch.o: label.h +switch.o: nobitfield.h +switch.o: nofloat.h +switch.o: nopp.h +switch.o: spec_arith.h +switch.o: switch.h +switch.o: type.h +ival.o: Lpars.h +ival.o: align.h +ival.o: arith.h +ival.o: assert.h +ival.o: class.h +ival.o: debug.h +ival.o: def.h +ival.o: expr.h +ival.o: field.h +ival.o: idf.h +ival.o: label.h +ival.o: level.h +ival.o: nobitfield.h +ival.o: nofloat.h +ival.o: nopp.h +ival.o: sizes.h +ival.o: spec_arith.h +ival.o: struct.h +ival.o: type.h +conversion.o: Lpars.h +conversion.o: arith.h +conversion.o: nobitfield.h +conversion.o: nofloat.h +conversion.o: sizes.h +conversion.o: spec_arith.h +conversion.o: type.h +blocks.o: arith.h +blocks.o: atw.h +blocks.o: label.h +blocks.o: nofloat.h +blocks.o: sizes.h +blocks.o: spec_arith.h +blocks.o: stack.h dataflow.o: dataflow.h tokenfile.o: Lpars.h -declar.o: LLlex.h Lpars.h arith.h debug.h declar.h decspecs.h def.h expr.h field.h file_info.h idf.h label.h nobitfield.h nofloat.h nopp.h sizes.h spec_arith.h struct.h type.h -statement.o: LLlex.h Lpars.h arith.h botch_free.h code.h debug.h def.h expr.h file_info.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h stack.h type.h -expression.o: LLlex.h Lpars.h arith.h expr.h file_info.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h -program.o: LLlex.h Lpars.h arith.h code.h declar.h decspecs.h def.h expr.h file_info.h idf.h label.h nobitfield.h nofloat.h nopp.h spec_arith.h type.h +declar.o: LLlex.h +declar.o: Lpars.h +declar.o: arith.h +declar.o: debug.h +declar.o: declar.h +declar.o: decspecs.h +declar.o: def.h +declar.o: expr.h +declar.o: field.h +declar.o: file_info.h +declar.o: idf.h +declar.o: label.h +declar.o: nobitfield.h +declar.o: nofloat.h +declar.o: nopp.h +declar.o: sizes.h +declar.o: spec_arith.h +declar.o: struct.h +declar.o: type.h +statement.o: LLlex.h +statement.o: Lpars.h +statement.o: arith.h +statement.o: botch_free.h +statement.o: code.h +statement.o: debug.h +statement.o: def.h +statement.o: expr.h +statement.o: file_info.h +statement.o: idf.h +statement.o: label.h +statement.o: nobitfield.h +statement.o: nofloat.h +statement.o: nopp.h +statement.o: spec_arith.h +statement.o: stack.h +statement.o: type.h +expression.o: LLlex.h +expression.o: Lpars.h +expression.o: arith.h +expression.o: expr.h +expression.o: file_info.h +expression.o: idf.h +expression.o: label.h +expression.o: nobitfield.h +expression.o: nofloat.h +expression.o: nopp.h +expression.o: spec_arith.h +expression.o: type.h +program.o: LLlex.h +program.o: Lpars.h +program.o: arith.h +program.o: code.h +program.o: declar.h +program.o: decspecs.h +program.o: def.h +program.o: expr.h +program.o: file_info.h +program.o: idf.h +program.o: label.h +program.o: nobitfield.h +program.o: nofloat.h +program.o: nopp.h +program.o: spec_arith.h +program.o: type.h Lpars.o: Lpars.h char.o: class.h symbol2str.o: Lpars.h From e07cdb34e9dd59f7d965abba9f572be12207397b Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 16 Feb 1987 09:49:32 +0000 Subject: [PATCH 0818/1625] Prevented looping of the code generator on illegal zer instructions --- mach/vax4/cg/table | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/vax4/cg/table b/mach/vax4/cg/table index a72501d5..5d79af35 100644 --- a/mach/vax4/cg/table +++ b/mach/vax4/cg/table @@ -2059,7 +2059,7 @@ zrf $1==8 | | allocate(QREG) zer $1==4 | | | {CONST4,0} | | zer $1==8 | | allocate(QREG) "clrq\t%[a]" | %[a] | | -zer $1<=32 | STACK | +zer $1>8&&$1<=32 | STACK | "clrq\t-(sp)" | | zer $1-8 | zer defined($1) | STACK | move({CONST4,$1/4},R0) From accba721dc9cde99277a3864758680db7f27b31c Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 16 Feb 1987 21:36:05 +0000 Subject: [PATCH 0819/1625] Another adaption to allow for user intervention BEFORE error recovery --- util/LLgen/lib/incl | 2 +- util/LLgen/lib/rec | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/util/LLgen/lib/incl b/util/LLgen/lib/incl index 9ce5edd5..9049cf9c 100644 --- a/util/LLgen/lib/incl +++ b/util/LLgen/lib/incl @@ -9,7 +9,7 @@ extern int LLsymb; extern char LLsets[]; #define LL_SAFE(x) /* Nothing */ -#define LL_SSCANDONE(x) if (LLsymb != x) LLmessage(x); else +#define LL_SSCANDONE(x) if (LLsymb != x) LLerror(x); else #define LL_SCANDONE(x) if (LLsymb != x) LLerror(x); else #define LL_T_NOSCANDONE(x) LLscan(x) diff --git a/util/LLgen/lib/rec b/util/LLgen/lib/rec index a8d08352..9f35841b 100644 --- a/util/LLgen/lib/rec +++ b/util/LLgen/lib/rec @@ -62,13 +62,17 @@ LLerror(t) { return; } #endif +#ifdef LL_USERHOOK + LL_USERHOOK(t); + LLread(); +#endif LL_USERHOOK if ((LLcsymb = LLindex[LLsymb]) < 0) { LLmessage(0); LLread(); } i = LLindex[t]; LLtcnt[i]++; - if (LLskip()) /* nothing */; + if (LLdoskip()) /* nothing */; LLtcnt[i]--; if (LLsymb != t) LLmessage(t); } @@ -90,6 +94,15 @@ LLnext(n) { } LLskip() { +#ifdef LL_USERHOOK + LL_USERHOOK(0); + LLread(); +#endif LL_USERHOOK + return LLdoskip(); +} + +LLdoskip() +{ register int i; int retval; int LLi, LLb; From 593efda0465ec72f98257fa437c6bf0f3766d20a Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 16 Feb 1987 21:38:52 +0000 Subject: [PATCH 0820/1625] adapted to allow for user intervention before error recovery --- util/LLgen/src/LLgen.g | 15 +++++++++++---- util/LLgen/src/extern.h | 1 + util/LLgen/src/gencode.c | 10 +++++++--- util/LLgen/src/global.c | 1 + util/LLgen/src/tokens.g | 2 ++ 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/util/LLgen/src/LLgen.g b/util/LLgen/src/LLgen.g index dbd3ece2..9155f983 100644 --- a/util/LLgen/src/LLgen.g +++ b/util/LLgen/src/LLgen.g @@ -127,16 +127,23 @@ def { register string p; } start = ff; } | C_LEXICAL C_IDENT + /* + * Declaration of a name for the lexical analyser. + * May appear only once + */ { if (!lexical) { lexical = store(lextoken.t_string); } else error(linecount,"Duplicate %%lexical"); } ';' - /* - * Declaration of a name for the lexical analyser. - * May appear only once - */ + | C_ONERROR C_IDENT + { if (! onerror) { + onerror = store(lextoken.t_string); + } + else error(linecount,"Duplicate %%onerror"); + } + ';' | action(0) { acount++; } /* * A global C-declaration diff --git a/util/LLgen/src/extern.h b/util/LLgen/src/extern.h index 81563af5..a021d78c 100644 --- a/util/LLgen/src/extern.h +++ b/util/LLgen/src/extern.h @@ -63,6 +63,7 @@ extern struct order *sorder, *porder; extern string e_noopen; /* Error message string used often */ extern int verbose; /* Level of verbosity */ extern string lexical; /* name of lexical analyser */ +extern string onerror; /* name of user error handler */ extern int ntneeded; /* ntneeded = 1 if nonterminals are included * in the sets. */ diff --git a/util/LLgen/src/gencode.c b/util/LLgen/src/gencode.c index f78ff4d1..209f9ab1 100644 --- a/util/LLgen/src/gencode.c +++ b/util/LLgen/src/gencode.c @@ -168,12 +168,13 @@ genrecovery() { } } i = maxptr - setptr; - fprintf(fpars, + fprintf(f, "#define LL_LEXI %s\n#define LL_SSIZE %d\n#define LL_NSETS %d\n#define LL_NTERMINALS %d\n", lexical, nbytes, i > 0 ? i : 1, ntokens); + if (onerror) fprintf(f,"#define LL_USERHOOK %s\n", onerror); /* Now generate the routines that call the startsymbols */ for (st = start; st; st = st->ff_next) { fputs(st->ff_name, f); @@ -471,8 +472,11 @@ rulecode(p,safety,mustscan,mustpop) register p_gram p; { genpop(findindex(n->n_contains)); } if (g_gettype(n->n_rule) == EORULE && - safety == getntout(n) && - ! g_getnpar(p)) break; + safety <= getntout(n) && + ! g_getnpar(p)) { + safety = getntout(n); + break; + } fprintf(f,"L%d_%s(\n",g_getnont(p), n->n_name); if (g_getnpar(p)) { controlline(); diff --git a/util/LLgen/src/global.c b/util/LLgen/src/global.c index ebd1061d..0dce2063 100644 --- a/util/LLgen/src/global.c +++ b/util/LLgen/src/global.c @@ -58,6 +58,7 @@ string f_input; string e_noopen = "Cannot open %s"; int verbose; string lexical; +string onerror; int ntneeded; int ntprint; # ifndef NDEBUG diff --git a/util/LLgen/src/tokens.g b/util/LLgen/src/tokens.g index 54c88383..8e3d76b6 100644 --- a/util/LLgen/src/tokens.g +++ b/util/LLgen/src/tokens.g @@ -67,6 +67,7 @@ STATIC string vallookup(); %token C_PERSISTENT ; %token C_FIRST ; %token C_LEXICAL ; +%token C_ONERROR ; %token C_AVOID ; %token C_PREFER ; %token C_DEFAULT ; @@ -100,6 +101,7 @@ static t_keyw resword[] = { { "first", C_FIRST }, { "start", C_START }, { "lexical", C_LEXICAL }, + { "onerror", C_ONERROR }, { 0, 0 } }; From cde7698e9b548e754e0b0fe7c10c4d267e3edb68 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 16 Feb 1987 21:42:18 +0000 Subject: [PATCH 0821/1625] Added doc on %onerror, and some other minor mods --- doc/LLgen/LLgen.n | 53 +++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/doc/LLgen/LLgen.n b/doc/LLgen/LLgen.n index 2071a965..a3da0f27 100644 --- a/doc/LLgen/LLgen.n +++ b/doc/LLgen/LLgen.n @@ -2,11 +2,11 @@ .\" Run this paper off with .\" refer [options] -p LLgen.refs LLgen.doc | [n]eqn | tbl | (nt)roff -ms .if '\*(>.'' \{\ -. if '\*(.>'' \{\ +. if '\*(<.'' \{\ . if n .ds >. . . if n .ds >, , -. if t .ds .> . -. if t .ds ,> ,\ +. if t .ds <. . +. if t .ds <, ,\ \}\ \} .cs 5 22u @@ -75,10 +75,10 @@ will be called for the rest of this document. It is assumed that the reader has some knowledge of LL(1) grammars and recursive descent parsers. -For a survey on the subject, see . -.[ +For a survey on the subject, see reference +.[ ( griffiths -.] +.]). .PP Extended LL(1) parsers are an extension of LL(1) parsers. They are derived from an Extended Context-Free (ECF) syntax instead of a Context-Free @@ -92,7 +92,7 @@ Section 4 provides a description of the way the \fILLgen\fR user can associate actions with the syntax. These actions must be written in the programming -language C , +language C, .[ kernighan ritchie .] @@ -117,15 +117,15 @@ Appendix A gives a summary of the input syntax. Appendix B gives an example. It is very instructive to compare this example with the one -given in . -.[ +given in reference +.[ ( yacc -.] +.]). It demonstrates the struggle \fILLparse\fR and other LL(1) parsers have with expressions. Appendix C gives an example of the \fILLgen\fR features allowing the user to recompile only those output files that -have changed, using the \fImake\fR program . +have changed, using the \fImake\fR program. .[ make .] @@ -396,10 +396,10 @@ To avoid name-conflicts with identifiers generated by Error Recovery .PP The error recovery technique used by \fILLgen\fR is a -modification of the one presented in . -.[ +modification of the one presented in reference +.[ ( automatic construction error correcting -.] +.]). It is based on \fBdefault choices\fR, which just are what the word says, default choices at every point in the grammar where there is a @@ -551,10 +551,10 @@ The conflicts can be examined by inspecting the verbose The conflicts can be resolved by rewriting the grammar or by using \fBconflict resolvers\fR. The mechanism described here is based on the attributed parsing -of . -.[ +of reference +.[ ( milton -.] +.]). .PP An alternation conflict can be resolved by putting an \fBif condition\fR in front of the first conflicting production. @@ -650,6 +650,17 @@ lexical analyzer, with the proper attributes. So, the lexical analyzer must have a facility to push back one token. .PP +The user may also supply his own error recovery routines, or handle +errors differently. For this purpose, the name of a routine to be called +when an error occurs may be declared using the keyword \fB%onerror\fR. +This routine takes one parameter, which is either the token number of the +token expected, or 0. In the last case, the error occurred at a choice. +In both cases, the routine must ensure that the next call to the lexical +analyser returns the token that replaces the current one. Of course, +that could well be the current one, in which case +.I LLparse +recovers from the error. +.PP The user must supply a lexical analyzer to read the input stream and break it up into tokens, which are passed to .I LLparse. @@ -670,7 +681,7 @@ The default name for the lexical analyzer is "yylex". The reason for this funny name is that a useful tool for constructing lexical analyzers is the .I Lex -program , +program, .[ lex .] @@ -689,6 +700,8 @@ The lexical analyzer must signal the end of input to \fILLparse\fR by returning a number less than or equal to zero. .bp +.SH +References .[ $LIST$ .] @@ -724,6 +737,7 @@ version of \fILLgen\fR is written with \fILLgen\fR. %token PREFER; /* %prefer */ %token DEFAULT; /* %default */ %token LEXICAL; /* %lexical */ +%token ONERROR; /* %onerror */ %token FIRST; /* %first */ /* @@ -753,6 +767,9 @@ declaration | LEXICAL IDENTIFIER ';' + | ONERROR + IDENTIFIER + ';' | rule ; From 7d6342021f3c573e55e6d891abee78b83703523d Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 17 Feb 1987 15:07:15 +0000 Subject: [PATCH 0822/1625] *** empty log message *** --- util/ack/Makefile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/util/ack/Makefile b/util/ack/Makefile index 18c91a41..8c6c48cb 100644 --- a/util/ack/Makefile +++ b/util/ack/Makefile @@ -6,12 +6,12 @@ DSRC=list.c data.c main.c scan.c svars.c trans.c util.c rmach.c run.c grows.c\ ISRC=dmach.c intable.c OBJ=list.o data.o main.o scan.o svars.o trans.o util.o rmach.o run.o \ dmach.o intable.o grows.o files.o -ACKDIR=$(EMHOME)/lib/ack +ACKDIR=$(EMHOME)/lib/ FE=fe INTABLES=pdp int -LNTABLES=acc apc abc vax2 vax4 i86 ix m68k2 m68k4 pmds pmds4 z8000\ -int22 int24 int44 6500 6800 6805 6809 i80 ns s2650 z80 -INCLUDES=-I $(EMHOME)/h +LNTABLES=acc apc abc vax4 i86 m68k2 m68k4 pmds pmds4 mantra mantra4 \ + m68020 z8000 int22 int24 int44 6500 6800 6805 6809 i80 ns s2650 z80 +INCLUDES=-I$(EMHOME)/h CFLAGS=-O -n $(INCLUDES) BINDIR=$(EMHOME)/bin MODDIR=$(EMHOME)/modules/lib @@ -49,7 +49,7 @@ files.o main.o rmach.o : $(EMHOME)/h/em_path.h main.o : $(EMHOME)/h/local.h -malloc.o svars.o: ack.h +svars.o: ack.h dmach.c intable.c: mktables dmach.h : mktables $(ACKDIR) # $(FE) $(INTABLES) @@ -59,7 +59,7 @@ mktables: mktables.c cc -o mktables mktables.c pr: - @pr Makefile $(HFILES) $(DSRC) $(ACKDIR)/* + @pr Makefile $(HFILES) $(DSRC) @(cd pc ; make pr) opr: From 1a88c7d883fc771539e3a3c04d5e328c37e786bd Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 18 Feb 1987 10:47:55 +0000 Subject: [PATCH 0823/1625] cardinality of sets was wrong! --- util/ncgg/hall.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/ncgg/hall.c b/util/ncgg/hall.c index 94eb5504..4bb5a0a1 100644 --- a/util/ncgg/hall.c +++ b/util/ncgg/hall.c @@ -57,7 +57,7 @@ card(sp) register short *sp; { register sum,i; sum=0; - for(i=0;i<8*SETSIZE;i++) + for(i=0;i<8*sizeof(short)*SETSIZE;i++) if (BIT(sp,i)) sum++; return(sum); From 5477964f632785d672a3bdb6c21c2379f7038906 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 18 Feb 1987 16:41:57 +0000 Subject: [PATCH 0824/1625] *** empty log message *** --- mach/i86/libsys/brk.s | 4 ++-- mach/i86/libsys/head_em.s | 6 ------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/mach/i86/libsys/brk.s b/mach/i86/libsys/brk.s index 0ddc5874..1f775498 100644 --- a/mach/i86/libsys/brk.s +++ b/mach/i86/libsys/brk.s @@ -3,7 +3,7 @@ .define xbrk .define np .extern _brk -.extern xbrk +.extern xbrk,endbss .extern np, cerror _brk: mov bx,sp @@ -35,5 +35,5 @@ xbrk: pop di ret .sect .data -np: .data2 0 +np: .data2 endbss .sect .text diff --git a/mach/i86/libsys/head_em.s b/mach/i86/libsys/head_em.s index ce19ce8f..6656ed4e 100644 --- a/mach/i86/libsys/head_em.s +++ b/mach/i86/libsys/head_em.s @@ -4,7 +4,6 @@ .define hol0,.reghp,.limhp,.trppc,.ignmask .define ERANGE,ESET,EHEAP,ECASE,EILLINS,EIDIVZ,EODDZ .extern _end -.extern np ERANGE = 1 ESET = 2 @@ -26,11 +25,6 @@ begtext: push ax push bx push cx - mov (np),begbss - mov bx,endbss - push bx - call _brk ! allocate space for bss - pop si xor bp,bp call _m_a_i_n int 0x81 From 506d59a93965e1c2752844b47c4fcea2af9181e0 Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 19 Feb 1987 11:28:14 +0000 Subject: [PATCH 0825/1625] Added description of strzero --- modules/src/string/string.3 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/src/string/string.3 b/modules/src/string/string.3 index e4ea42d1..27de210e 100644 --- a/modules/src/string/string.3 +++ b/modules/src/string/string.3 @@ -141,6 +141,11 @@ or zero if does not occur in .IR s . .PP +.I Strzero +turns +.I s +into a null string. +.PP .I Bts2str turns a row of .I n From 88da4849b449d24d53775471dfa74b66ed5cec0d Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 20 Feb 1987 14:36:01 +0000 Subject: [PATCH 0826/1625] Initial revision --- mach/sun2/cv/cv.c | 560 ++++++++++++++++++++++++++++++++++ mach/sun3/Action | 6 + mach/sun3/cv/Makefile | 25 ++ mach/sun3/cv/cv.c | 560 ++++++++++++++++++++++++++++++++++ mach/sun3/libsys/LIST | 159 ++++++++++ mach/sun3/libsys/Makefile | 29 ++ mach/sun3/libsys/_exit.s | 7 + mach/sun3/libsys/accept.s | 4 + mach/sun3/libsys/access.s | 4 + mach/sun3/libsys/acct.s | 4 + mach/sun3/libsys/adjtime.s | 4 + mach/sun3/libsys/alarm.c | 13 + mach/sun3/libsys/async_dem.s | 4 + mach/sun3/libsys/bind.s | 4 + mach/sun3/libsys/cerror.s | 9 + mach/sun3/libsys/chdir.s | 4 + mach/sun3/libsys/chmod.s | 4 + mach/sun3/libsys/chown.s | 4 + mach/sun3/libsys/chroot.s | 4 + mach/sun3/libsys/cleanup.c | 1 + mach/sun3/libsys/close.s | 4 + mach/sun3/libsys/compmodule | 4 + mach/sun3/libsys/connect.s | 4 + mach/sun3/libsys/creat.s | 4 + mach/sun3/libsys/dup.s | 4 + mach/sun3/libsys/dup2.s | 4 + mach/sun3/libsys/execl.c | 8 + mach/sun3/libsys/execle.c | 9 + mach/sun3/libsys/execv.c | 7 + mach/sun3/libsys/execve.s | 4 + mach/sun3/libsys/exit.c | 5 + mach/sun3/libsys/exportfs.s | 4 + mach/sun3/libsys/fchmod.s | 4 + mach/sun3/libsys/fchown.s | 4 + mach/sun3/libsys/fcntl.s | 4 + mach/sun3/libsys/flock.s | 4 + mach/sun3/libsys/fork.s | 14 + mach/sun3/libsys/fstat.s | 4 + mach/sun3/libsys/fstatfs.s | 4 + mach/sun3/libsys/fsync.s | 4 + mach/sun3/libsys/ftime.c | 15 + mach/sun3/libsys/ftruncate.s | 4 + mach/sun3/libsys/getdirent.s | 4 + mach/sun3/libsys/getdomnam.s | 4 + mach/sun3/libsys/getdopt.s | 4 + mach/sun3/libsys/getdtabsz.s | 4 + mach/sun3/libsys/getegid.s | 8 + mach/sun3/libsys/geteuid.s | 8 + mach/sun3/libsys/getfh.s | 4 + mach/sun3/libsys/getgid.s | 4 + mach/sun3/libsys/getgroups.s | 4 + mach/sun3/libsys/gethostid.s | 4 + mach/sun3/libsys/gethostnam.s | 4 + mach/sun3/libsys/getitimer.s | 4 + mach/sun3/libsys/getpagesiz.s | 4 + mach/sun3/libsys/getpeernam.s | 4 + mach/sun3/libsys/getpgrp.s | 4 + mach/sun3/libsys/getpid.s | 4 + mach/sun3/libsys/getppid.s | 8 + mach/sun3/libsys/getprio.s | 4 + mach/sun3/libsys/getrlimit.s | 4 + mach/sun3/libsys/getrusage.s | 4 + mach/sun3/libsys/getsocknam.s | 4 + mach/sun3/libsys/getsockopt.s | 4 + mach/sun3/libsys/gettimday.s | 4 + mach/sun3/libsys/getuid.s | 4 + mach/sun3/libsys/gtty.c | 7 + mach/sun3/libsys/head_em.s | 65 ++++ mach/sun3/libsys/ioctl.s | 4 + mach/sun3/libsys/kill.s | 4 + mach/sun3/libsys/killpg.s | 4 + mach/sun3/libsys/link.s | 4 + mach/sun3/libsys/listen.s | 4 + mach/sun3/libsys/lockf.c | 43 +++ mach/sun3/libsys/lseek.s | 4 + mach/sun3/libsys/lstat.s | 4 + mach/sun3/libsys/madvise.s | 4 + mach/sun3/libsys/mincore.s | 4 + mach/sun3/libsys/mkdir.s | 4 + mach/sun3/libsys/mknod.s | 4 + mach/sun3/libsys/mmap.s | 4 + mach/sun3/libsys/mount.s | 4 + mach/sun3/libsys/mprotect.s | 4 + mach/sun3/libsys/mremap.s | 4 + mach/sun3/libsys/msg.s | 18 ++ mach/sun3/libsys/msgsys.s | 4 + mach/sun3/libsys/munmap.s | 4 + mach/sun3/libsys/nfssvc.s | 4 + mach/sun3/libsys/nice.c | 13 + mach/sun3/libsys/open.s | 4 + mach/sun3/libsys/pause.c | 3 + mach/sun3/libsys/pipe.s | 14 + mach/sun3/libsys/plock.c | 8 + mach/sun3/libsys/profil.s | 4 + mach/sun3/libsys/ptrace.s | 7 + mach/sun3/libsys/quotactl.s | 4 + mach/sun3/libsys/read.s | 4 + mach/sun3/libsys/readlink.s | 4 + mach/sun3/libsys/readv.s | 4 + mach/sun3/libsys/reboot.s | 10 + mach/sun3/libsys/recv.s | 4 + mach/sun3/libsys/recvfrom.s | 4 + mach/sun3/libsys/recvmsg.s | 4 + mach/sun3/libsys/rename.s | 4 + mach/sun3/libsys/rmdir.s | 4 + mach/sun3/libsys/sbrk.s | 41 +++ mach/sun3/libsys/select.s | 4 + mach/sun3/libsys/sem.s | 15 + mach/sun3/libsys/semsys.s | 4 + mach/sun3/libsys/send.s | 4 + mach/sun3/libsys/sendmsg.s | 4 + mach/sun3/libsys/sendto.s | 4 + mach/sun3/libsys/setdomnam.s | 4 + mach/sun3/libsys/setdopt.s | 4 + mach/sun3/libsys/setgid.c | 4 + mach/sun3/libsys/setgroups.s | 4 + mach/sun3/libsys/sethostnam.s | 4 + mach/sun3/libsys/setitimer.s | 4 + mach/sun3/libsys/setpgrp.s | 4 + mach/sun3/libsys/setprio.s | 4 + mach/sun3/libsys/setregid.s | 4 + mach/sun3/libsys/setreuid.s | 4 + mach/sun3/libsys/setrlimit.s | 4 + mach/sun3/libsys/setsockopt.s | 4 + mach/sun3/libsys/settimday.s | 4 + mach/sun3/libsys/setuid.c | 4 + mach/sun3/libsys/shm.s | 18 ++ mach/sun3/libsys/shmsys.s | 4 + mach/sun3/libsys/shutdown.s | 4 + mach/sun3/libsys/sigblock.s | 4 + mach/sun3/libsys/signal.c | 25 ++ mach/sun3/libsys/sigpause.s | 4 + mach/sun3/libsys/sigsetmask.s | 4 + mach/sun3/libsys/sigstack.s | 4 + mach/sun3/libsys/sigtramp.s | 17 ++ mach/sun3/libsys/sigvec.c | 35 +++ mach/sun3/libsys/socket.s | 4 + mach/sun3/libsys/socketpair.s | 4 + mach/sun3/libsys/sstk.s | 4 + mach/sun3/libsys/stat.s | 4 + mach/sun3/libsys/statfs.s | 4 + mach/sun3/libsys/stime.c | 9 + mach/sun3/libsys/stty.c | 7 + mach/sun3/libsys/swapon.s | 4 + mach/sun3/libsys/symlink.s | 4 + mach/sun3/libsys/sync.s | 4 + mach/sun3/libsys/syscall.h | 127 ++++++++ mach/sun3/libsys/syscall.s | 14 + mach/sun3/libsys/tell.c | 7 + mach/sun3/libsys/time.c | 12 + mach/sun3/libsys/times.c | 16 + mach/sun3/libsys/truncate.s | 4 + mach/sun3/libsys/ulimit.c | 26 ++ mach/sun3/libsys/umask.s | 4 + mach/sun3/libsys/uname.c | 26 ++ mach/sun3/libsys/unlink.s | 4 + mach/sun3/libsys/unmount.s | 4 + mach/sun3/libsys/ustat.s | 4 + mach/sun3/libsys/utime.c | 13 + mach/sun3/libsys/utimes.s | 4 + mach/sun3/libsys/vadvise.s | 4 + mach/sun3/libsys/vfork.s | 18 ++ mach/sun3/libsys/vhangup.s | 4 + mach/sun3/libsys/wait.s | 15 + mach/sun3/libsys/wait3.s | 18 ++ mach/sun3/libsys/write.s | 4 + mach/sun3/libsys/writev.s | 4 + 167 files changed, 2574 insertions(+) create mode 100644 mach/sun2/cv/cv.c create mode 100644 mach/sun3/Action create mode 100644 mach/sun3/cv/Makefile create mode 100644 mach/sun3/cv/cv.c create mode 100644 mach/sun3/libsys/LIST create mode 100644 mach/sun3/libsys/Makefile create mode 100644 mach/sun3/libsys/_exit.s create mode 100644 mach/sun3/libsys/accept.s create mode 100644 mach/sun3/libsys/access.s create mode 100644 mach/sun3/libsys/acct.s create mode 100644 mach/sun3/libsys/adjtime.s create mode 100644 mach/sun3/libsys/alarm.c create mode 100644 mach/sun3/libsys/async_dem.s create mode 100644 mach/sun3/libsys/bind.s create mode 100644 mach/sun3/libsys/cerror.s create mode 100644 mach/sun3/libsys/chdir.s create mode 100644 mach/sun3/libsys/chmod.s create mode 100644 mach/sun3/libsys/chown.s create mode 100644 mach/sun3/libsys/chroot.s create mode 100644 mach/sun3/libsys/cleanup.c create mode 100644 mach/sun3/libsys/close.s create mode 100755 mach/sun3/libsys/compmodule create mode 100644 mach/sun3/libsys/connect.s create mode 100644 mach/sun3/libsys/creat.s create mode 100644 mach/sun3/libsys/dup.s create mode 100644 mach/sun3/libsys/dup2.s create mode 100644 mach/sun3/libsys/execl.c create mode 100644 mach/sun3/libsys/execle.c create mode 100644 mach/sun3/libsys/execv.c create mode 100644 mach/sun3/libsys/execve.s create mode 100644 mach/sun3/libsys/exit.c create mode 100644 mach/sun3/libsys/exportfs.s create mode 100644 mach/sun3/libsys/fchmod.s create mode 100644 mach/sun3/libsys/fchown.s create mode 100644 mach/sun3/libsys/fcntl.s create mode 100644 mach/sun3/libsys/flock.s create mode 100644 mach/sun3/libsys/fork.s create mode 100644 mach/sun3/libsys/fstat.s create mode 100644 mach/sun3/libsys/fstatfs.s create mode 100644 mach/sun3/libsys/fsync.s create mode 100644 mach/sun3/libsys/ftime.c create mode 100644 mach/sun3/libsys/ftruncate.s create mode 100644 mach/sun3/libsys/getdirent.s create mode 100644 mach/sun3/libsys/getdomnam.s create mode 100644 mach/sun3/libsys/getdopt.s create mode 100644 mach/sun3/libsys/getdtabsz.s create mode 100644 mach/sun3/libsys/getegid.s create mode 100644 mach/sun3/libsys/geteuid.s create mode 100644 mach/sun3/libsys/getfh.s create mode 100644 mach/sun3/libsys/getgid.s create mode 100644 mach/sun3/libsys/getgroups.s create mode 100644 mach/sun3/libsys/gethostid.s create mode 100644 mach/sun3/libsys/gethostnam.s create mode 100644 mach/sun3/libsys/getitimer.s create mode 100644 mach/sun3/libsys/getpagesiz.s create mode 100644 mach/sun3/libsys/getpeernam.s create mode 100644 mach/sun3/libsys/getpgrp.s create mode 100644 mach/sun3/libsys/getpid.s create mode 100644 mach/sun3/libsys/getppid.s create mode 100644 mach/sun3/libsys/getprio.s create mode 100644 mach/sun3/libsys/getrlimit.s create mode 100644 mach/sun3/libsys/getrusage.s create mode 100644 mach/sun3/libsys/getsocknam.s create mode 100644 mach/sun3/libsys/getsockopt.s create mode 100644 mach/sun3/libsys/gettimday.s create mode 100644 mach/sun3/libsys/getuid.s create mode 100644 mach/sun3/libsys/gtty.c create mode 100644 mach/sun3/libsys/head_em.s create mode 100644 mach/sun3/libsys/ioctl.s create mode 100644 mach/sun3/libsys/kill.s create mode 100644 mach/sun3/libsys/killpg.s create mode 100644 mach/sun3/libsys/link.s create mode 100644 mach/sun3/libsys/listen.s create mode 100644 mach/sun3/libsys/lockf.c create mode 100644 mach/sun3/libsys/lseek.s create mode 100644 mach/sun3/libsys/lstat.s create mode 100644 mach/sun3/libsys/madvise.s create mode 100644 mach/sun3/libsys/mincore.s create mode 100644 mach/sun3/libsys/mkdir.s create mode 100644 mach/sun3/libsys/mknod.s create mode 100644 mach/sun3/libsys/mmap.s create mode 100644 mach/sun3/libsys/mount.s create mode 100644 mach/sun3/libsys/mprotect.s create mode 100644 mach/sun3/libsys/mremap.s create mode 100644 mach/sun3/libsys/msg.s create mode 100644 mach/sun3/libsys/msgsys.s create mode 100644 mach/sun3/libsys/munmap.s create mode 100644 mach/sun3/libsys/nfssvc.s create mode 100644 mach/sun3/libsys/nice.c create mode 100644 mach/sun3/libsys/open.s create mode 100644 mach/sun3/libsys/pause.c create mode 100644 mach/sun3/libsys/pipe.s create mode 100644 mach/sun3/libsys/plock.c create mode 100644 mach/sun3/libsys/profil.s create mode 100644 mach/sun3/libsys/ptrace.s create mode 100644 mach/sun3/libsys/quotactl.s create mode 100644 mach/sun3/libsys/read.s create mode 100644 mach/sun3/libsys/readlink.s create mode 100644 mach/sun3/libsys/readv.s create mode 100644 mach/sun3/libsys/reboot.s create mode 100644 mach/sun3/libsys/recv.s create mode 100644 mach/sun3/libsys/recvfrom.s create mode 100644 mach/sun3/libsys/recvmsg.s create mode 100644 mach/sun3/libsys/rename.s create mode 100644 mach/sun3/libsys/rmdir.s create mode 100644 mach/sun3/libsys/sbrk.s create mode 100644 mach/sun3/libsys/select.s create mode 100644 mach/sun3/libsys/sem.s create mode 100644 mach/sun3/libsys/semsys.s create mode 100644 mach/sun3/libsys/send.s create mode 100644 mach/sun3/libsys/sendmsg.s create mode 100644 mach/sun3/libsys/sendto.s create mode 100644 mach/sun3/libsys/setdomnam.s create mode 100644 mach/sun3/libsys/setdopt.s create mode 100644 mach/sun3/libsys/setgid.c create mode 100644 mach/sun3/libsys/setgroups.s create mode 100644 mach/sun3/libsys/sethostnam.s create mode 100644 mach/sun3/libsys/setitimer.s create mode 100644 mach/sun3/libsys/setpgrp.s create mode 100644 mach/sun3/libsys/setprio.s create mode 100644 mach/sun3/libsys/setregid.s create mode 100644 mach/sun3/libsys/setreuid.s create mode 100644 mach/sun3/libsys/setrlimit.s create mode 100644 mach/sun3/libsys/setsockopt.s create mode 100644 mach/sun3/libsys/settimday.s create mode 100644 mach/sun3/libsys/setuid.c create mode 100644 mach/sun3/libsys/shm.s create mode 100644 mach/sun3/libsys/shmsys.s create mode 100644 mach/sun3/libsys/shutdown.s create mode 100644 mach/sun3/libsys/sigblock.s create mode 100644 mach/sun3/libsys/signal.c create mode 100644 mach/sun3/libsys/sigpause.s create mode 100644 mach/sun3/libsys/sigsetmask.s create mode 100644 mach/sun3/libsys/sigstack.s create mode 100644 mach/sun3/libsys/sigtramp.s create mode 100644 mach/sun3/libsys/sigvec.c create mode 100644 mach/sun3/libsys/socket.s create mode 100644 mach/sun3/libsys/socketpair.s create mode 100644 mach/sun3/libsys/sstk.s create mode 100644 mach/sun3/libsys/stat.s create mode 100644 mach/sun3/libsys/statfs.s create mode 100644 mach/sun3/libsys/stime.c create mode 100644 mach/sun3/libsys/stty.c create mode 100644 mach/sun3/libsys/swapon.s create mode 100644 mach/sun3/libsys/symlink.s create mode 100644 mach/sun3/libsys/sync.s create mode 100644 mach/sun3/libsys/syscall.h create mode 100644 mach/sun3/libsys/syscall.s create mode 100644 mach/sun3/libsys/tell.c create mode 100644 mach/sun3/libsys/time.c create mode 100644 mach/sun3/libsys/times.c create mode 100644 mach/sun3/libsys/truncate.s create mode 100644 mach/sun3/libsys/ulimit.c create mode 100644 mach/sun3/libsys/umask.s create mode 100644 mach/sun3/libsys/uname.c create mode 100644 mach/sun3/libsys/unlink.s create mode 100644 mach/sun3/libsys/unmount.s create mode 100644 mach/sun3/libsys/ustat.s create mode 100644 mach/sun3/libsys/utime.c create mode 100644 mach/sun3/libsys/utimes.s create mode 100644 mach/sun3/libsys/vadvise.s create mode 100644 mach/sun3/libsys/vfork.s create mode 100644 mach/sun3/libsys/vhangup.s create mode 100644 mach/sun3/libsys/wait.s create mode 100644 mach/sun3/libsys/wait3.s create mode 100644 mach/sun3/libsys/write.s create mode 100644 mach/sun3/libsys/writev.s diff --git a/mach/sun2/cv/cv.c b/mach/sun2/cv/cv.c new file mode 100644 index 00000000..f516428c --- /dev/null +++ b/mach/sun2/cv/cv.c @@ -0,0 +1,560 @@ +/* + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. + * + * This product is part of the Amsterdam Compiler Kit. + * + * Permission to use, sell, duplicate or disclose this software must be + * obtained in writing. Requests for such permissions may be sent to + * + * Dr. Andrew S. Tanenbaum + * Wiskundig Seminarium + * Vrije Universiteit + * Postbox 7161 + * 1007 MC Amsterdam + * The Netherlands + * + */ + +/* + * Convert ACK a.out file to SUN3 object format. + */ + +#include +#include +#include + +long lseek(); + +#define OMAGIC 0407 /* old-fashioned */ +#define NMAGIC 0410 /* text write protexted */ +#define ZMAGIC 0413 /* demand paging */ + +#define MACH 2 + +struct bhdr { + short machtype; + short magic; + long tsize; + long dsize; + long bsize; + long ssize; + long entry; + long rtsize; + long rdsize; +}; + +struct machrelo { + long address; + long relodata; +}; +#define setpcrel(X,f) (X |= (f<<7)) +#define setsymbolnum(X,n) (X = (X & 0377) | ((long)n << 8)) +#define setextern(X,f) (X |= (f << 4)) +#define setlength(X,l) (X = (X & ~0x60)|((long) l << 5)) + +struct sym { + long name; + char type; + char other; + short desc; + long value; +}; + +#define N_UNDF 0 +#define N_ABS 02 +#define N_TEXT 04 +#define N_DATA 06 +#define N_BSS 010 +#define N_EXT 01 +#define N_FN 0x1f + +/* + * Header and section table of new format object file. + */ +struct outhead outhead; +struct outsect outsect[S_MAX]; + +char *output_file; +int outputfile_created; +long magic; + +int rom_in_data; + +char *program ; + +char flag ; + +/* Output file definitions and such */ + +struct bhdr bh; + +#define ENTRY 0x02000 +#define TOT_HDRSIZE (sizeof(struct bhdr)) + + + +#define TEXTSG 0 +#define ROMSG 1 +#define DATASG 2 +#define BSSSG 3 +#define LSECT BSSSG+1 +#define NSECT LSECT+1 + +int output; + +int unresolved; +long textsize ; +long datasize ; +long bsssize; + +main(argc, argv) + int argc; + char *argv[]; +{ + register int nsect; + + program= argv[0] ; + if ( argc>1 && argv[1][0]=='-' ) { + flag=argv[1][1] ; + argc-- ; argv++ ; + } + switch (argc) { + case 3: if ((output = creat(argv[2], 0644)) < 0 || + (close(output), output = open(argv[2],2)) < 0) + fatal("Can't write %s.\n", argv[2]); + output_file = argv[2]; + outputfile_created = 1; + if (! rd_open(argv[1])) + fatal("Can't read %s.\n", argv[1]); + break; + default:fatal("Usage: %s .\n", argv[0]); + } + rd_ohead(&outhead); + if (BADMAGIC(outhead)) + fatal("Not an ack object file.\n"); + if (outhead.oh_flags & HF_LINK) { + unresolved++; + fprintf(stderr,"Warning: contains unresolved references.\n"); + } + else if (outhead.oh_nrelo > 0) + fprintf(stderr, "Warning: relocation information present.\n"); + if ( outhead.oh_nsect!=LSECT && outhead.oh_nsect!=NSECT ) + fatal("Input file must have %d sections, not %ld\n", + NSECT,outhead.oh_nsect) ; + rd_sect(outsect, outhead.oh_nsect); + /* A few checks */ + if ( outsect[BSSSG].os_flen != 0 ) + fatal("bss space contains initialized data\n") ; + if ( !unresolved && outsect[BSSSG].os_base != outsect[DATASG].os_base+ + outsect[DATASG].os_size ) + fatal("bss segment must follow data segment\n") ; + if ( outsect[ROMSG].os_lign == 0x20000 ) { + /* 410/413 file with ROMSG in data space */ + rom_in_data = 1; + magic= NMAGIC ; + textsize= outsect[TEXTSG].os_size ; + datasize= outsect[ROMSG].os_size + outsect[DATASG].os_size ; + if ( outsect[DATASG].os_base != outsect[ROMSG].os_base+ + outsect[ROMSG].os_size ) + fatal("data segment must follow rom\n") ; + } else + if ( outsect[DATASG].os_lign == 0x20000 ) { + /* 410/413 file with ROMSG in instruction space */ + rom_in_data = 0; + magic= NMAGIC ; + textsize= outsect[TEXTSG].os_size + outsect[ROMSG].os_size ; + datasize= outsect[DATASG].os_size ; + if ( outsect[ROMSG].os_base != outsect[TEXTSG].os_base+ + outsect[TEXTSG].os_size ) + fatal("rom segment must follow text\n") ; + } else { + /* Plain 407 file */ + rom_in_data = 0; + magic= OMAGIC ; + textsize= outsect[TEXTSG].os_size + outsect[ROMSG].os_size ; + datasize= outsect[DATASG].os_size ; + if (!unresolved) { + if (outsect[ROMSG].os_base != outsect[TEXTSG].os_base+ + outsect[TEXTSG].os_size ) + fatal("rom segment must follow text\n") ; + if ( outsect[DATASG].os_base != outsect[ROMSG].os_base+ + outsect[ROMSG].os_size ) + fatal("data segment must follow rom\n") ; + } + } + if (outsect[TEXTSG].os_base == TOT_HDRSIZE+ENTRY) { + if (magic != NMAGIC) { + fatal("illegal alignments.\n"); + } + magic = ZMAGIC; + textsize = (textsize + TOT_HDRSIZE + (0x2000 - 1)) & ~(0x2000 - 1); + datasize = (datasize + (0x2000 - 1)) & ~(0x2000 - 1); + } + bsssize = outsect[BSSSG].os_size; + if ( outhead.oh_nsect==NSECT ) { + if ( outsect[LSECT].os_base != outsect[BSSSG].os_base+ + outsect[BSSSG].os_size ) + fatal("end segment must follow bss\n") ; + if ( outsect[LSECT].os_size != 0 ) + fatal("end segment must be empty\n") ; + } + + if (magic != OMAGIC && unresolved) { + fatal("unresolved references with wrong magic number\n"); + } + + if ((magic == ZMAGIC && outsect[TEXTSG].os_base != TOT_HDRSIZE+ENTRY) || + (magic != ZMAGIC && !unresolved && outsect[TEXTSG].os_base != ENTRY)) { + fatal("Illegal entry point.\n"); + } + + bh.magic = magic; + bh.machtype = MACH; + bh.tsize = textsize; + bh.bsize = bsssize; + bh.dsize = datasize; + bh.rtsize = 0; + bh.rdsize = 0; + if (magic == ZMAGIC) bh.entry = TOT_HDRSIZE+ENTRY; + else if (!unresolved) bh.entry = ENTRY; + else bh.entry = 0; + + /* Action at last */ + lseek(output,(long) TOT_HDRSIZE,0); + emits(&outsect[TEXTSG]) ; + if (rom_in_data && magic == ZMAGIC) { + lseek(output,textsize,0); + } + emits(&outsect[ROMSG]) ; + if (!rom_in_data && magic == ZMAGIC) { + lseek(output,textsize,0); + } + emits(&outsect[DATASG]) ; + if (magic == ZMAGIC) { + lseek(output,textsize + datasize,0); + } + if (unresolved) emit_relo(); + emit_symtab(); + bh.ssize = outhead.oh_nname * sizeof(struct sym); + lseek(output,0L,0); + cvshort(&(bh.machtype)); + cvshort(&(bh.magic)); + cvlong(&(bh.tsize)); + cvlong(&(bh.dsize)); + cvlong(&(bh.bsize)); + cvlong(&(bh.ssize)); + cvlong(&(bh.entry)); + cvlong(&(bh.rtsize)); + cvlong(&(bh.rdsize)); + writef(&bh, 1, (long) TOT_HDRSIZE); + if ( outputfile_created && !unresolved ) chmod(argv[2],0755); + return 0; +} + +writef(addr,sz,cnt) + char *addr; + long cnt; +{ + cnt *= sz; + + while (cnt) { + int i = cnt >= 0x4000 ? 0x4000 : cnt; + + cnt -= i; + if (write(output, addr, i) < i) { + fatal("write error\n"); + } + addr += i; + } +} + +/* + * Transfer the emitted byted from one file to another. + */ +emits(section) struct outsect *section ; { + char *p; + char *calloc(); + long sz = section->os_flen; + + rd_outsect(section - outsect); + while (sz) { + unsigned int i = (sz >= 0x4000 ? 0x4000 : sz); + if (!(p = calloc(i, 1))) { + fatal("No memory.\n"); + } + rd_emit(p, i); + if (write(output, p, i) < i) { + fatal("write error.\n"); + } + free(p); + sz -= i; + } + + sz = section->os_size - section->os_flen; + while (sz) { + unsigned int i = (sz >= 0x4000 ? 0x4000 : sz); + if (!(p = calloc(i, 1))) { + fatal("No memory.\n"); + } + if (write(output, p, i) < i) { + fatal("write error.\n"); + } + free(p); + sz -= i; + } +} + +struct outname *ACKnames; + +emit_relo() +{ + struct outrelo *ACKrelo; + struct machrelo *MACHtrelo,*MACHdrelo; + register struct outrelo *ap; + register struct machrelo *mtp, *mdp; + unsigned int cnt = outhead.oh_nrelo; + + ACKrelo = (struct outrelo *) calloc(cnt, sizeof(struct outrelo)); + MACHtrelo = (struct machrelo *) calloc(cnt, sizeof(struct machrelo)); + MACHdrelo = (struct machrelo *) calloc(cnt, sizeof(struct machrelo)); + ACKnames = (struct outname *) calloc(outhead.oh_nname, sizeof(struct outname)); + if (!(ap = ACKrelo) || !(mtp = MACHtrelo) || !(mdp = MACHdrelo) || + !ACKnames) { + fatal("No memory.\n"); + } + rd_relo(ACKrelo, cnt); + rd_name(ACKnames, outhead.oh_nname); + while (cnt-- != 0) { + register struct machrelo *mp; + + if (ap->or_sect - S_MIN <= ROMSG) mp = mtp++; + else mp = mdp++; + setlength(mp->relodata,(ap->or_type&RELSZ) >> 1); + setpcrel(mp->relodata,(ap->or_type&RELPC != 0)); + mp->address = ap->or_addr; + if (ap->or_sect == ROMSG+S_MIN) { + mp->address += outsect[TEXTSG].os_size; + } + if (ap->or_nami < outhead.oh_nname) { + if (ACKnames[ap->or_nami].on_type & S_EXT) { + setsymbolnum(mp->relodata, ap->or_nami); + setextern(mp->relodata,1); + } + else { + patch(ap, &ACKnames[ap->or_nami], mp); + } + } + else { + setsymbolnum(mp->relodata, N_ABS); + } + cvlong(&(mp->address)); + cvlong(&(mp->relodata)); + ap++; + } + bh.rtsize = (char *) mtp - (char *) MACHtrelo; + bh.rdsize = (char *) mdp - (char *) MACHdrelo; + writef(MACHtrelo, 1, bh.rtsize); + writef(MACHdrelo, 1, bh.rdsize); + free(ACKrelo); + free(MACHtrelo); + free(MACHdrelo); +} + +long +get(sz) +{ + char buf[10]; + long l = 0; + register char *p = buf; + + read(output,buf,sz); + while (sz--) { + l = (l << 8) | (*p++ & 0377); + } +} + +put(l,sz) + long l; +{ + char buf[10]; + register char *p; + + *p++ = l >> 24; + *p++ = l >> 16; + *p++ = l >> 8; + *p++ = l; + p -= sz; + if (write(output, p, sz) < sz) { + fatal("write error.\n"); + } +} + +patch(ap, an, mp) + register struct outrelo *ap; + register struct outname *an; + register struct machrelo *mp; +{ + int whichsect = (an->on_type & S_TYP) - S_MIN; + long correction = 0; + long where = TOT_HDRSIZE+ap->or_addr; + long X; + long here; + int sz; + + if (!(an->on_type & S_SCT)) { + fprintf(stderr,"funny on_type %x\n", an->on_type); + } + switch(whichsect) { + case TEXTSG: + setsymbolnum(mp->relodata,N_TEXT); + return; + case DATASG: + correction = outsect[ROMSG].os_size + outsect[TEXTSG].os_size; + setsymbolnum(mp->relodata,N_DATA); + break; + case ROMSG: + correction += outsect[TEXTSG].os_size; + setsymbolnum(mp->relodata,N_TEXT); + break; + default: + assert(0); + } + + switch(ap->or_sect - S_MIN) { + case DATASG: + where += outsect[ROMSG].os_size; + case ROMSG: + where += outsect[TEXTSG].os_size; + case TEXTSG: + break; + default: + assert(0); + } + here = lseek(output, 0L, 1); + lseek(output, where, 0); + sz = ap->or_type & RELSZ; + X = get(sz) + correction; + lseek(output, where, 0); + put(X,sz); + lseek(output, here, 0); +} + +cvlong(l) + long *l; +{ + long x = *l; + char *p = (char *) l; + + *p++ = x >> 24; + *p++ = x >> 16; + *p++ = x >> 8; + *p = x; +} + +cvshort(s) + short *s; +{ + short x = *s; + char *p = (char *) s; + + *p++ = x >> 8; + *p = x; +} + +emit_symtab() +{ + register unsigned short i = outhead.oh_nname; + register struct outname *A; + struct sym *MACHnames; + register struct sym *M; + extern char *malloc(), *calloc(); + char *chars; + long offX = OFF_CHAR(outhead) - 4; + + if (!(A = ACKnames)) { + if (!(A = (struct outname *) + calloc(i, sizeof(struct outname)))) { + fatal("No memory.\n"); + } + rd_name(A, outhead.oh_nname); + } + if (!(M = (struct sym *) calloc(i, sizeof(struct sym)))) { + fatal("No memory.\n"); + } + MACHnames = M; + ACKnames = A; + for (; i; i--, A++, M++) { + M->value = A->on_valu; + switch(A->on_type & S_TYP) { + case S_UND: + M->type = N_UNDF; + break; + case S_ABS: + M->type = N_ABS; + break; + case S_MIN + TEXTSG: + if (! A->on_type & S_COM) { + M->value += outsect[TEXTSG].os_base; + } + M->type = N_TEXT; + break; + case S_MIN + ROMSG: + M->type = (rom_in_data ? N_DATA : N_TEXT); + if (! A->on_type & S_COM) { + M->value += outsect[ROMSG].os_base; + } + break; + case S_MIN + DATASG: + M->type = N_DATA; + if (! A->on_type & S_COM) { + M->value += outsect[DATASG].os_base; + } + break; + case S_MIN + BSSSG: + M->type = N_BSS; + if (! A->on_type & S_COM) { + M->value += outsect[BSSSG].os_base; + } + break; + case S_MIN + LSECT: + M->type = N_BSS; + if (! A->on_type & S_COM) { + M->value += outsect[LSECT].os_base; + } + break; + default: + fprintf(stderr,"warning: unknown s_type: %d\n", + A->on_type & S_TYP); + } + if (A->on_type & S_EXT) M->type |= N_EXT; + if (M->name = A->on_foff) { + M->name -= offX; + } + cvlong(&(M->name)); + cvlong(&(M->value)); + } + writef(MACHnames, sizeof(struct sym), (long) outhead.oh_nname); + free(MACHnames); + free(ACKnames); + if ((unsigned) outhead.oh_nchar != outhead.oh_nchar || + !( chars = malloc((unsigned) outhead.oh_nchar))) { + fatal("No memory\n."); + } + put(outhead.oh_nchar+4,4); + rd_string(chars,outhead.oh_nchar); + writef(chars, 1, outhead.oh_nchar); + free(chars); +} + +/* VARARGS1 */ +fatal(s, a1, a2) + char *s; +{ + fprintf(stderr,"%s: ",program) ; + fprintf(stderr, s, a1, a2); + if (outputfile_created) + unlink(output_file); + exit(-1); +} + +rd_fatal() { fatal("read error.\n"); } diff --git a/mach/sun3/Action b/mach/sun3/Action new file mode 100644 index 00000000..ecfe36b9 --- /dev/null +++ b/mach/sun3/Action @@ -0,0 +1,6 @@ +name "Ack.out --> SUN 68020 a.out format conversion program" +dir cv +end +name "SUN 68020 systemcall library" +dir libsys +end diff --git a/mach/sun3/cv/Makefile b/mach/sun3/cv/Makefile new file mode 100644 index 00000000..5cfa97a6 --- /dev/null +++ b/mach/sun3/cv/Makefile @@ -0,0 +1,25 @@ +EMHOME = ../../.. +LIBOBJ = $(EMHOME)/modules/lib/libobject.a +INCLUDE = $(EMHOME)/h +CFLAGS = -I. -I$(INCLUDE) -O +TARGETS = cv + +all: $(TARGETS) + +install: all + ../../install cv + +cmp: all + ../../compare cv + +cv: cv.o + $(CC) $(LDFLAGS) -o cv cv.o $(LIBOBJ) + +clean: + rm -f $(TARGETS) *.o nohup.out Out + +pr: + @pr Makefile cv.c + +opr: + make pr | opr diff --git a/mach/sun3/cv/cv.c b/mach/sun3/cv/cv.c new file mode 100644 index 00000000..f516428c --- /dev/null +++ b/mach/sun3/cv/cv.c @@ -0,0 +1,560 @@ +/* + * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. + * + * This product is part of the Amsterdam Compiler Kit. + * + * Permission to use, sell, duplicate or disclose this software must be + * obtained in writing. Requests for such permissions may be sent to + * + * Dr. Andrew S. Tanenbaum + * Wiskundig Seminarium + * Vrije Universiteit + * Postbox 7161 + * 1007 MC Amsterdam + * The Netherlands + * + */ + +/* + * Convert ACK a.out file to SUN3 object format. + */ + +#include +#include +#include + +long lseek(); + +#define OMAGIC 0407 /* old-fashioned */ +#define NMAGIC 0410 /* text write protexted */ +#define ZMAGIC 0413 /* demand paging */ + +#define MACH 2 + +struct bhdr { + short machtype; + short magic; + long tsize; + long dsize; + long bsize; + long ssize; + long entry; + long rtsize; + long rdsize; +}; + +struct machrelo { + long address; + long relodata; +}; +#define setpcrel(X,f) (X |= (f<<7)) +#define setsymbolnum(X,n) (X = (X & 0377) | ((long)n << 8)) +#define setextern(X,f) (X |= (f << 4)) +#define setlength(X,l) (X = (X & ~0x60)|((long) l << 5)) + +struct sym { + long name; + char type; + char other; + short desc; + long value; +}; + +#define N_UNDF 0 +#define N_ABS 02 +#define N_TEXT 04 +#define N_DATA 06 +#define N_BSS 010 +#define N_EXT 01 +#define N_FN 0x1f + +/* + * Header and section table of new format object file. + */ +struct outhead outhead; +struct outsect outsect[S_MAX]; + +char *output_file; +int outputfile_created; +long magic; + +int rom_in_data; + +char *program ; + +char flag ; + +/* Output file definitions and such */ + +struct bhdr bh; + +#define ENTRY 0x02000 +#define TOT_HDRSIZE (sizeof(struct bhdr)) + + + +#define TEXTSG 0 +#define ROMSG 1 +#define DATASG 2 +#define BSSSG 3 +#define LSECT BSSSG+1 +#define NSECT LSECT+1 + +int output; + +int unresolved; +long textsize ; +long datasize ; +long bsssize; + +main(argc, argv) + int argc; + char *argv[]; +{ + register int nsect; + + program= argv[0] ; + if ( argc>1 && argv[1][0]=='-' ) { + flag=argv[1][1] ; + argc-- ; argv++ ; + } + switch (argc) { + case 3: if ((output = creat(argv[2], 0644)) < 0 || + (close(output), output = open(argv[2],2)) < 0) + fatal("Can't write %s.\n", argv[2]); + output_file = argv[2]; + outputfile_created = 1; + if (! rd_open(argv[1])) + fatal("Can't read %s.\n", argv[1]); + break; + default:fatal("Usage: %s .\n", argv[0]); + } + rd_ohead(&outhead); + if (BADMAGIC(outhead)) + fatal("Not an ack object file.\n"); + if (outhead.oh_flags & HF_LINK) { + unresolved++; + fprintf(stderr,"Warning: contains unresolved references.\n"); + } + else if (outhead.oh_nrelo > 0) + fprintf(stderr, "Warning: relocation information present.\n"); + if ( outhead.oh_nsect!=LSECT && outhead.oh_nsect!=NSECT ) + fatal("Input file must have %d sections, not %ld\n", + NSECT,outhead.oh_nsect) ; + rd_sect(outsect, outhead.oh_nsect); + /* A few checks */ + if ( outsect[BSSSG].os_flen != 0 ) + fatal("bss space contains initialized data\n") ; + if ( !unresolved && outsect[BSSSG].os_base != outsect[DATASG].os_base+ + outsect[DATASG].os_size ) + fatal("bss segment must follow data segment\n") ; + if ( outsect[ROMSG].os_lign == 0x20000 ) { + /* 410/413 file with ROMSG in data space */ + rom_in_data = 1; + magic= NMAGIC ; + textsize= outsect[TEXTSG].os_size ; + datasize= outsect[ROMSG].os_size + outsect[DATASG].os_size ; + if ( outsect[DATASG].os_base != outsect[ROMSG].os_base+ + outsect[ROMSG].os_size ) + fatal("data segment must follow rom\n") ; + } else + if ( outsect[DATASG].os_lign == 0x20000 ) { + /* 410/413 file with ROMSG in instruction space */ + rom_in_data = 0; + magic= NMAGIC ; + textsize= outsect[TEXTSG].os_size + outsect[ROMSG].os_size ; + datasize= outsect[DATASG].os_size ; + if ( outsect[ROMSG].os_base != outsect[TEXTSG].os_base+ + outsect[TEXTSG].os_size ) + fatal("rom segment must follow text\n") ; + } else { + /* Plain 407 file */ + rom_in_data = 0; + magic= OMAGIC ; + textsize= outsect[TEXTSG].os_size + outsect[ROMSG].os_size ; + datasize= outsect[DATASG].os_size ; + if (!unresolved) { + if (outsect[ROMSG].os_base != outsect[TEXTSG].os_base+ + outsect[TEXTSG].os_size ) + fatal("rom segment must follow text\n") ; + if ( outsect[DATASG].os_base != outsect[ROMSG].os_base+ + outsect[ROMSG].os_size ) + fatal("data segment must follow rom\n") ; + } + } + if (outsect[TEXTSG].os_base == TOT_HDRSIZE+ENTRY) { + if (magic != NMAGIC) { + fatal("illegal alignments.\n"); + } + magic = ZMAGIC; + textsize = (textsize + TOT_HDRSIZE + (0x2000 - 1)) & ~(0x2000 - 1); + datasize = (datasize + (0x2000 - 1)) & ~(0x2000 - 1); + } + bsssize = outsect[BSSSG].os_size; + if ( outhead.oh_nsect==NSECT ) { + if ( outsect[LSECT].os_base != outsect[BSSSG].os_base+ + outsect[BSSSG].os_size ) + fatal("end segment must follow bss\n") ; + if ( outsect[LSECT].os_size != 0 ) + fatal("end segment must be empty\n") ; + } + + if (magic != OMAGIC && unresolved) { + fatal("unresolved references with wrong magic number\n"); + } + + if ((magic == ZMAGIC && outsect[TEXTSG].os_base != TOT_HDRSIZE+ENTRY) || + (magic != ZMAGIC && !unresolved && outsect[TEXTSG].os_base != ENTRY)) { + fatal("Illegal entry point.\n"); + } + + bh.magic = magic; + bh.machtype = MACH; + bh.tsize = textsize; + bh.bsize = bsssize; + bh.dsize = datasize; + bh.rtsize = 0; + bh.rdsize = 0; + if (magic == ZMAGIC) bh.entry = TOT_HDRSIZE+ENTRY; + else if (!unresolved) bh.entry = ENTRY; + else bh.entry = 0; + + /* Action at last */ + lseek(output,(long) TOT_HDRSIZE,0); + emits(&outsect[TEXTSG]) ; + if (rom_in_data && magic == ZMAGIC) { + lseek(output,textsize,0); + } + emits(&outsect[ROMSG]) ; + if (!rom_in_data && magic == ZMAGIC) { + lseek(output,textsize,0); + } + emits(&outsect[DATASG]) ; + if (magic == ZMAGIC) { + lseek(output,textsize + datasize,0); + } + if (unresolved) emit_relo(); + emit_symtab(); + bh.ssize = outhead.oh_nname * sizeof(struct sym); + lseek(output,0L,0); + cvshort(&(bh.machtype)); + cvshort(&(bh.magic)); + cvlong(&(bh.tsize)); + cvlong(&(bh.dsize)); + cvlong(&(bh.bsize)); + cvlong(&(bh.ssize)); + cvlong(&(bh.entry)); + cvlong(&(bh.rtsize)); + cvlong(&(bh.rdsize)); + writef(&bh, 1, (long) TOT_HDRSIZE); + if ( outputfile_created && !unresolved ) chmod(argv[2],0755); + return 0; +} + +writef(addr,sz,cnt) + char *addr; + long cnt; +{ + cnt *= sz; + + while (cnt) { + int i = cnt >= 0x4000 ? 0x4000 : cnt; + + cnt -= i; + if (write(output, addr, i) < i) { + fatal("write error\n"); + } + addr += i; + } +} + +/* + * Transfer the emitted byted from one file to another. + */ +emits(section) struct outsect *section ; { + char *p; + char *calloc(); + long sz = section->os_flen; + + rd_outsect(section - outsect); + while (sz) { + unsigned int i = (sz >= 0x4000 ? 0x4000 : sz); + if (!(p = calloc(i, 1))) { + fatal("No memory.\n"); + } + rd_emit(p, i); + if (write(output, p, i) < i) { + fatal("write error.\n"); + } + free(p); + sz -= i; + } + + sz = section->os_size - section->os_flen; + while (sz) { + unsigned int i = (sz >= 0x4000 ? 0x4000 : sz); + if (!(p = calloc(i, 1))) { + fatal("No memory.\n"); + } + if (write(output, p, i) < i) { + fatal("write error.\n"); + } + free(p); + sz -= i; + } +} + +struct outname *ACKnames; + +emit_relo() +{ + struct outrelo *ACKrelo; + struct machrelo *MACHtrelo,*MACHdrelo; + register struct outrelo *ap; + register struct machrelo *mtp, *mdp; + unsigned int cnt = outhead.oh_nrelo; + + ACKrelo = (struct outrelo *) calloc(cnt, sizeof(struct outrelo)); + MACHtrelo = (struct machrelo *) calloc(cnt, sizeof(struct machrelo)); + MACHdrelo = (struct machrelo *) calloc(cnt, sizeof(struct machrelo)); + ACKnames = (struct outname *) calloc(outhead.oh_nname, sizeof(struct outname)); + if (!(ap = ACKrelo) || !(mtp = MACHtrelo) || !(mdp = MACHdrelo) || + !ACKnames) { + fatal("No memory.\n"); + } + rd_relo(ACKrelo, cnt); + rd_name(ACKnames, outhead.oh_nname); + while (cnt-- != 0) { + register struct machrelo *mp; + + if (ap->or_sect - S_MIN <= ROMSG) mp = mtp++; + else mp = mdp++; + setlength(mp->relodata,(ap->or_type&RELSZ) >> 1); + setpcrel(mp->relodata,(ap->or_type&RELPC != 0)); + mp->address = ap->or_addr; + if (ap->or_sect == ROMSG+S_MIN) { + mp->address += outsect[TEXTSG].os_size; + } + if (ap->or_nami < outhead.oh_nname) { + if (ACKnames[ap->or_nami].on_type & S_EXT) { + setsymbolnum(mp->relodata, ap->or_nami); + setextern(mp->relodata,1); + } + else { + patch(ap, &ACKnames[ap->or_nami], mp); + } + } + else { + setsymbolnum(mp->relodata, N_ABS); + } + cvlong(&(mp->address)); + cvlong(&(mp->relodata)); + ap++; + } + bh.rtsize = (char *) mtp - (char *) MACHtrelo; + bh.rdsize = (char *) mdp - (char *) MACHdrelo; + writef(MACHtrelo, 1, bh.rtsize); + writef(MACHdrelo, 1, bh.rdsize); + free(ACKrelo); + free(MACHtrelo); + free(MACHdrelo); +} + +long +get(sz) +{ + char buf[10]; + long l = 0; + register char *p = buf; + + read(output,buf,sz); + while (sz--) { + l = (l << 8) | (*p++ & 0377); + } +} + +put(l,sz) + long l; +{ + char buf[10]; + register char *p; + + *p++ = l >> 24; + *p++ = l >> 16; + *p++ = l >> 8; + *p++ = l; + p -= sz; + if (write(output, p, sz) < sz) { + fatal("write error.\n"); + } +} + +patch(ap, an, mp) + register struct outrelo *ap; + register struct outname *an; + register struct machrelo *mp; +{ + int whichsect = (an->on_type & S_TYP) - S_MIN; + long correction = 0; + long where = TOT_HDRSIZE+ap->or_addr; + long X; + long here; + int sz; + + if (!(an->on_type & S_SCT)) { + fprintf(stderr,"funny on_type %x\n", an->on_type); + } + switch(whichsect) { + case TEXTSG: + setsymbolnum(mp->relodata,N_TEXT); + return; + case DATASG: + correction = outsect[ROMSG].os_size + outsect[TEXTSG].os_size; + setsymbolnum(mp->relodata,N_DATA); + break; + case ROMSG: + correction += outsect[TEXTSG].os_size; + setsymbolnum(mp->relodata,N_TEXT); + break; + default: + assert(0); + } + + switch(ap->or_sect - S_MIN) { + case DATASG: + where += outsect[ROMSG].os_size; + case ROMSG: + where += outsect[TEXTSG].os_size; + case TEXTSG: + break; + default: + assert(0); + } + here = lseek(output, 0L, 1); + lseek(output, where, 0); + sz = ap->or_type & RELSZ; + X = get(sz) + correction; + lseek(output, where, 0); + put(X,sz); + lseek(output, here, 0); +} + +cvlong(l) + long *l; +{ + long x = *l; + char *p = (char *) l; + + *p++ = x >> 24; + *p++ = x >> 16; + *p++ = x >> 8; + *p = x; +} + +cvshort(s) + short *s; +{ + short x = *s; + char *p = (char *) s; + + *p++ = x >> 8; + *p = x; +} + +emit_symtab() +{ + register unsigned short i = outhead.oh_nname; + register struct outname *A; + struct sym *MACHnames; + register struct sym *M; + extern char *malloc(), *calloc(); + char *chars; + long offX = OFF_CHAR(outhead) - 4; + + if (!(A = ACKnames)) { + if (!(A = (struct outname *) + calloc(i, sizeof(struct outname)))) { + fatal("No memory.\n"); + } + rd_name(A, outhead.oh_nname); + } + if (!(M = (struct sym *) calloc(i, sizeof(struct sym)))) { + fatal("No memory.\n"); + } + MACHnames = M; + ACKnames = A; + for (; i; i--, A++, M++) { + M->value = A->on_valu; + switch(A->on_type & S_TYP) { + case S_UND: + M->type = N_UNDF; + break; + case S_ABS: + M->type = N_ABS; + break; + case S_MIN + TEXTSG: + if (! A->on_type & S_COM) { + M->value += outsect[TEXTSG].os_base; + } + M->type = N_TEXT; + break; + case S_MIN + ROMSG: + M->type = (rom_in_data ? N_DATA : N_TEXT); + if (! A->on_type & S_COM) { + M->value += outsect[ROMSG].os_base; + } + break; + case S_MIN + DATASG: + M->type = N_DATA; + if (! A->on_type & S_COM) { + M->value += outsect[DATASG].os_base; + } + break; + case S_MIN + BSSSG: + M->type = N_BSS; + if (! A->on_type & S_COM) { + M->value += outsect[BSSSG].os_base; + } + break; + case S_MIN + LSECT: + M->type = N_BSS; + if (! A->on_type & S_COM) { + M->value += outsect[LSECT].os_base; + } + break; + default: + fprintf(stderr,"warning: unknown s_type: %d\n", + A->on_type & S_TYP); + } + if (A->on_type & S_EXT) M->type |= N_EXT; + if (M->name = A->on_foff) { + M->name -= offX; + } + cvlong(&(M->name)); + cvlong(&(M->value)); + } + writef(MACHnames, sizeof(struct sym), (long) outhead.oh_nname); + free(MACHnames); + free(ACKnames); + if ((unsigned) outhead.oh_nchar != outhead.oh_nchar || + !( chars = malloc((unsigned) outhead.oh_nchar))) { + fatal("No memory\n."); + } + put(outhead.oh_nchar+4,4); + rd_string(chars,outhead.oh_nchar); + writef(chars, 1, outhead.oh_nchar); + free(chars); +} + +/* VARARGS1 */ +fatal(s, a1, a2) + char *s; +{ + fprintf(stderr,"%s: ",program) ; + fprintf(stderr, s, a1, a2); + if (outputfile_created) + unlink(output_file); + exit(-1); +} + +rd_fatal() { fatal("read error.\n"); } diff --git a/mach/sun3/libsys/LIST b/mach/sun3/libsys/LIST new file mode 100644 index 00000000..2b746292 --- /dev/null +++ b/mach/sun3/libsys/LIST @@ -0,0 +1,159 @@ +libmon_s.a +accept.s +access.s +acct.s +adjtime.s +alarm.c +async_dem.s +bind.s +cerror.s +chdir.s +chmod.s +chown.s +chroot.s +cleanup.c +close.s +connect.s +creat.s +dup.s +dup2.s +execl.c +execle.c +execv.c +execve.s +exit.c +exportfs.s +fchmod.s +fchown.s +fcntl.s +flock.s +fork.s +fstat.s +fstatfs.s +fsync.s +ftime.c +ftruncate.s +getdirent.s +getdomnam.s +getdopt.s +getdtabsz.s +getfh.s +getgid.s +getgroups.s +gethostid.s +gethostnam.s +getitimer.s +getpagesiz.s +getpeernam.s +getpgrp.s +getpid.s +getprio.s +getrlimit.s +getrusage.s +getsocknam.s +getsockopt.s +gettimday.s +getuid.s +ioctl.s +kill.s +killpg.s +link.s +listen.s +lseek.s +lstat.s +madvise.s +mincore.s +mkdir.s +mknod.s +mmap.s +mount.s +mprotect.s +mremap.s +msgsys.s +munmap.s +nfssvc.s +nice.c +open.s +pause.c +pipe.s +profil.s +ptrace.s +quotactl.s +read.s +readlink.s +readv.s +reboot.s +recv.s +recvfrom.s +recvmsg.s +rename.s +rmdir.s +sbrk.s +select.s +semsys.s +send.s +sendmsg.s +sendto.s +setdomnam.s +setdopt.s +setgroups.s +sethostnam.s +setitimer.s +setpgrp.s +setprio.s +setregid.s +setreuid.s +setrlimit.s +setsockopt.s +settimday.s +shmsys.s +shutdown.s +sigblock.s +signal.c +sigpause.s +sigsetmask.s +sigstack.s +sigtramp.s +sigvec.c +socket.s +socketpair.s +sstk.s +stat.s +statfs.s +swapon.s +symlink.s +sync.s +syscall.s +time.c +times.c +truncate.s +umask.s +unlink.s +unmount.s +ustat.s +utime.c +utimes.s +vhangup.s +wait.s +write.s +writev.s +_exit.s +stty.c +gtty.c +getegid.s +geteuid.s +getppid.s +lockf.c +msg.s +plock.c +sem.s +setgid.c +setuid.c +shm.s +stime.c +tell.c +ulimit.c +uname.c +vadvise.s +vfork.s +wait3.s diff --git a/mach/sun3/libsys/Makefile b/mach/sun3/libsys/Makefile new file mode 100644 index 00000000..5861ef1d --- /dev/null +++ b/mach/sun3/libsys/Makefile @@ -0,0 +1,29 @@ +# $Header$ +MACH=m68020 +all: libmon_o.a head_em.o + +install: all + ../../install head_em.o head_em + ../../install libmon_o.a tail_mon + + +cmp: all + -../../compare head_em.o head_em + -../../compare libmon_o.a tail_mon + +libmon_o.a: libmon_s.a + ASAR=aal ; export ASAR ;\ + march . libmon_o.a + +head_em.o: head_em.s + $(MACH) -I../../../h -c head_em.s + +clean: + rm -f *.o libmon_o.a + +opr : + make pr | opr + +pr: + @pr `pwd`/head_em.s + @arch pv libmon_s.a | pr -h `pwd`/libmon_s.a diff --git a/mach/sun3/libsys/_exit.s b/mach/sun3/libsys/_exit.s new file mode 100644 index 00000000..c7347ad6 --- /dev/null +++ b/mach/sun3/libsys/_exit.s @@ -0,0 +1,7 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define __exit +__exit: + pea (SYS_exit) + trap #0 + jmp (cerror) diff --git a/mach/sun3/libsys/accept.s b/mach/sun3/libsys/accept.s new file mode 100644 index 00000000..c7746ab2 --- /dev/null +++ b/mach/sun3/libsys/accept.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _accept +_accept: SYSTEM(SYS_accept) diff --git a/mach/sun3/libsys/access.s b/mach/sun3/libsys/access.s new file mode 100644 index 00000000..203953ed --- /dev/null +++ b/mach/sun3/libsys/access.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _access +_access: SYSTEM(SYS_access) diff --git a/mach/sun3/libsys/acct.s b/mach/sun3/libsys/acct.s new file mode 100644 index 00000000..d28b968f --- /dev/null +++ b/mach/sun3/libsys/acct.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _acct +_acct: SYSTEM(SYS_acct) diff --git a/mach/sun3/libsys/adjtime.s b/mach/sun3/libsys/adjtime.s new file mode 100644 index 00000000..524996de --- /dev/null +++ b/mach/sun3/libsys/adjtime.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _adjtime +_adjtime: SYSTEM(SYS_adjtime) diff --git a/mach/sun3/libsys/alarm.c b/mach/sun3/libsys/alarm.c new file mode 100644 index 00000000..ddbf2442 --- /dev/null +++ b/mach/sun3/libsys/alarm.c @@ -0,0 +1,13 @@ +unsigned +alarm(n) + unsigned n; +{ + struct { long l1,l2,l3,l4; } t1,t2; + t1.l1 = 0; + t1.l2 = 0; + t1.l4 = 0; + t1.l3 = n; + if (setitimer(0,&t1,&t2) < 0) return -1; + if (t2.l4) t2.l3++; + return t2.l3; +} diff --git a/mach/sun3/libsys/async_dem.s b/mach/sun3/libsys/async_dem.s new file mode 100644 index 00000000..cba18f34 --- /dev/null +++ b/mach/sun3/libsys/async_dem.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _async_daemon +_async_daemon: SYSTEM(SYS_async_daemon) diff --git a/mach/sun3/libsys/bind.s b/mach/sun3/libsys/bind.s new file mode 100644 index 00000000..28441a49 --- /dev/null +++ b/mach/sun3/libsys/bind.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _bind +_bind: SYSTEM(SYS_bind) diff --git a/mach/sun3/libsys/cerror.s b/mach/sun3/libsys/cerror.s new file mode 100644 index 00000000..985bb56f --- /dev/null +++ b/mach/sun3/libsys/cerror.s @@ -0,0 +1,9 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define cerror,_errno +cerror: + move.l d0,(_errno) + move.l #-1,d0 + rts + +.sect .bss +_errno: .space 4 diff --git a/mach/sun3/libsys/chdir.s b/mach/sun3/libsys/chdir.s new file mode 100644 index 00000000..2deb808c --- /dev/null +++ b/mach/sun3/libsys/chdir.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _chdir +_chdir: SYSTEM(SYS_chdir) diff --git a/mach/sun3/libsys/chmod.s b/mach/sun3/libsys/chmod.s new file mode 100644 index 00000000..cf8d3669 --- /dev/null +++ b/mach/sun3/libsys/chmod.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _chmod +_chmod: SYSTEM(SYS_chmod) diff --git a/mach/sun3/libsys/chown.s b/mach/sun3/libsys/chown.s new file mode 100644 index 00000000..ff635d56 --- /dev/null +++ b/mach/sun3/libsys/chown.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _chown +_chown: SYSTEM(SYS_chown) diff --git a/mach/sun3/libsys/chroot.s b/mach/sun3/libsys/chroot.s new file mode 100644 index 00000000..a8a16163 --- /dev/null +++ b/mach/sun3/libsys/chroot.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _chroot +_chroot: SYSTEM(SYS_chroot) diff --git a/mach/sun3/libsys/cleanup.c b/mach/sun3/libsys/cleanup.c new file mode 100644 index 00000000..6cd9c63e --- /dev/null +++ b/mach/sun3/libsys/cleanup.c @@ -0,0 +1 @@ +_cleanup() { } diff --git a/mach/sun3/libsys/close.s b/mach/sun3/libsys/close.s new file mode 100644 index 00000000..8e7b0ac5 --- /dev/null +++ b/mach/sun3/libsys/close.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _close +_close: SYSTEM(SYS_close) diff --git a/mach/sun3/libsys/compmodule b/mach/sun3/libsys/compmodule new file mode 100755 index 00000000..58dc66c6 --- /dev/null +++ b/mach/sun3/libsys/compmodule @@ -0,0 +1,4 @@ +if m68020 -c -L $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 +fi diff --git a/mach/sun3/libsys/connect.s b/mach/sun3/libsys/connect.s new file mode 100644 index 00000000..b2ee0430 --- /dev/null +++ b/mach/sun3/libsys/connect.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _connect +_connect: SYSTEM(SYS_connect) diff --git a/mach/sun3/libsys/creat.s b/mach/sun3/libsys/creat.s new file mode 100644 index 00000000..1cd2f235 --- /dev/null +++ b/mach/sun3/libsys/creat.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _creat +_creat: SYSTEM(SYS_creat) diff --git a/mach/sun3/libsys/dup.s b/mach/sun3/libsys/dup.s new file mode 100644 index 00000000..dcaa2752 --- /dev/null +++ b/mach/sun3/libsys/dup.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _dup +_dup: SYSTEM(SYS_dup) diff --git a/mach/sun3/libsys/dup2.s b/mach/sun3/libsys/dup2.s new file mode 100644 index 00000000..bb32d50c --- /dev/null +++ b/mach/sun3/libsys/dup2.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _dup2 +_dup2: SYSTEM(SYS_dup2) diff --git a/mach/sun3/libsys/execl.c b/mach/sun3/libsys/execl.c new file mode 100644 index 00000000..9989439b --- /dev/null +++ b/mach/sun3/libsys/execl.c @@ -0,0 +1,8 @@ +execl(name,args) + char *name; + int args; +{ + extern char **environ; + + execve(name,&args,environ); +} diff --git a/mach/sun3/libsys/execle.c b/mach/sun3/libsys/execle.c new file mode 100644 index 00000000..aed03638 --- /dev/null +++ b/mach/sun3/libsys/execle.c @@ -0,0 +1,9 @@ +execle(name,args) + char *name; + char *args; +{ + char **p = &args; + while (*p++) ; + + execve(name,&args,*p); +} diff --git a/mach/sun3/libsys/execv.c b/mach/sun3/libsys/execv.c new file mode 100644 index 00000000..200486f6 --- /dev/null +++ b/mach/sun3/libsys/execv.c @@ -0,0 +1,7 @@ +execv(name,args) + char *name; + char **args; +{ + extern char **environ; + execve(name,args,environ); +} diff --git a/mach/sun3/libsys/execve.s b/mach/sun3/libsys/execve.s new file mode 100644 index 00000000..915c86dd --- /dev/null +++ b/mach/sun3/libsys/execve.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _execve +_execve: SYSTEM(SYS_execve) diff --git a/mach/sun3/libsys/exit.c b/mach/sun3/libsys/exit.c new file mode 100644 index 00000000..afd54b3f --- /dev/null +++ b/mach/sun3/libsys/exit.c @@ -0,0 +1,5 @@ +exit(n) +{ + _cleanup(); + _exit(n); +} diff --git a/mach/sun3/libsys/exportfs.s b/mach/sun3/libsys/exportfs.s new file mode 100644 index 00000000..d406ccb0 --- /dev/null +++ b/mach/sun3/libsys/exportfs.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _exportfs +_exportfs: SYSTEM(SYS_exportfs) diff --git a/mach/sun3/libsys/fchmod.s b/mach/sun3/libsys/fchmod.s new file mode 100644 index 00000000..b2cb8d87 --- /dev/null +++ b/mach/sun3/libsys/fchmod.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _fchmod +_fchmod: SYSTEM(SYS_fchmod) diff --git a/mach/sun3/libsys/fchown.s b/mach/sun3/libsys/fchown.s new file mode 100644 index 00000000..38627b89 --- /dev/null +++ b/mach/sun3/libsys/fchown.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _fchown +_fchown: SYSTEM(SYS_fchown) diff --git a/mach/sun3/libsys/fcntl.s b/mach/sun3/libsys/fcntl.s new file mode 100644 index 00000000..c8baec29 --- /dev/null +++ b/mach/sun3/libsys/fcntl.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _fcntl +_fcntl: SYSTEM(SYS_fcntl) diff --git a/mach/sun3/libsys/flock.s b/mach/sun3/libsys/flock.s new file mode 100644 index 00000000..d98cd8d2 --- /dev/null +++ b/mach/sun3/libsys/flock.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _flock +_flock: SYSTEM(SYS_flock) diff --git a/mach/sun3/libsys/fork.s b/mach/sun3/libsys/fork.s new file mode 100644 index 00000000..5afda047 --- /dev/null +++ b/mach/sun3/libsys/fork.s @@ -0,0 +1,14 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _fork +_fork: + pea (SYS_fork) + trap #0 + bcs 1f + tst.l d1 + beq 2f + clr.l d0 +2: + rts +1: + jmp (cerror) diff --git a/mach/sun3/libsys/fstat.s b/mach/sun3/libsys/fstat.s new file mode 100644 index 00000000..c3df3de7 --- /dev/null +++ b/mach/sun3/libsys/fstat.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _fstat +_fstat: SYSTEM(SYS_fstat) diff --git a/mach/sun3/libsys/fstatfs.s b/mach/sun3/libsys/fstatfs.s new file mode 100644 index 00000000..f151cb1d --- /dev/null +++ b/mach/sun3/libsys/fstatfs.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _fstatfs +_fstatfs: SYSTEM(SYS_fstatfs) diff --git a/mach/sun3/libsys/fsync.s b/mach/sun3/libsys/fsync.s new file mode 100644 index 00000000..444b6148 --- /dev/null +++ b/mach/sun3/libsys/fsync.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _fsync +_fsync: SYSTEM(SYS_fsync) diff --git a/mach/sun3/libsys/ftime.c b/mach/sun3/libsys/ftime.c new file mode 100644 index 00000000..af4047c3 --- /dev/null +++ b/mach/sun3/libsys/ftime.c @@ -0,0 +1,15 @@ +#include + +ftime(p) + struct { time_t time; unsigned short millitm; + short timezone; short dstflag; } *p; +{ + struct { long l1,l2; } t1,t2; + + if (gettimeofday(&t1,&t2) < 0) return -1; + p->time = t1.l1; + p->millitm = t1.l2/1000; + p->dstflag = t2.l2; + p->timezone = t2.l1; + return 0; +} diff --git a/mach/sun3/libsys/ftruncate.s b/mach/sun3/libsys/ftruncate.s new file mode 100644 index 00000000..37ba7a64 --- /dev/null +++ b/mach/sun3/libsys/ftruncate.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _ftruncate +_ftruncate: SYSTEM(SYS_ftruncate) diff --git a/mach/sun3/libsys/getdirent.s b/mach/sun3/libsys/getdirent.s new file mode 100644 index 00000000..2ae28723 --- /dev/null +++ b/mach/sun3/libsys/getdirent.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _getdirentries +_getdirentries: SYSTEM(SYS_getdirentries) diff --git a/mach/sun3/libsys/getdomnam.s b/mach/sun3/libsys/getdomnam.s new file mode 100644 index 00000000..172e9f0a --- /dev/null +++ b/mach/sun3/libsys/getdomnam.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _getdomainname +_getdomainname: SYSTEM(SYS_getdomainname) diff --git a/mach/sun3/libsys/getdopt.s b/mach/sun3/libsys/getdopt.s new file mode 100644 index 00000000..27c97957 --- /dev/null +++ b/mach/sun3/libsys/getdopt.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _getdopt +_getdopt: SYSTEM(SYS_getdopt) diff --git a/mach/sun3/libsys/getdtabsz.s b/mach/sun3/libsys/getdtabsz.s new file mode 100644 index 00000000..db274311 --- /dev/null +++ b/mach/sun3/libsys/getdtabsz.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _getdtablesize +_getdtablesize: SYSTEM(SYS_getdtablesize) diff --git a/mach/sun3/libsys/getegid.s b/mach/sun3/libsys/getegid.s new file mode 100644 index 00000000..d191387a --- /dev/null +++ b/mach/sun3/libsys/getegid.s @@ -0,0 +1,8 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _getegid +_getegid: + pea (SYS_getgid) + trap #0 + move.l d1,d0 + rts diff --git a/mach/sun3/libsys/geteuid.s b/mach/sun3/libsys/geteuid.s new file mode 100644 index 00000000..4b181ac4 --- /dev/null +++ b/mach/sun3/libsys/geteuid.s @@ -0,0 +1,8 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _geteuid +_geteuid: + pea (SYS_getuid) + trap #0 + move.l d1,d0 + rts diff --git a/mach/sun3/libsys/getfh.s b/mach/sun3/libsys/getfh.s new file mode 100644 index 00000000..cbe86653 --- /dev/null +++ b/mach/sun3/libsys/getfh.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _getfh +_getfh: SYSTEM(SYS_getfh) diff --git a/mach/sun3/libsys/getgid.s b/mach/sun3/libsys/getgid.s new file mode 100644 index 00000000..76569d05 --- /dev/null +++ b/mach/sun3/libsys/getgid.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _getgid +_getgid: SYSTEM(SYS_getgid) diff --git a/mach/sun3/libsys/getgroups.s b/mach/sun3/libsys/getgroups.s new file mode 100644 index 00000000..e9da4d8a --- /dev/null +++ b/mach/sun3/libsys/getgroups.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _getgroups +_getgroups: SYSTEM(SYS_getgroups) diff --git a/mach/sun3/libsys/gethostid.s b/mach/sun3/libsys/gethostid.s new file mode 100644 index 00000000..07db17a6 --- /dev/null +++ b/mach/sun3/libsys/gethostid.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _gethostid +_gethostid: SYSTEM(SYS_gethostid) diff --git a/mach/sun3/libsys/gethostnam.s b/mach/sun3/libsys/gethostnam.s new file mode 100644 index 00000000..107643f0 --- /dev/null +++ b/mach/sun3/libsys/gethostnam.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _gethostname +_gethostname: SYSTEM(SYS_gethostname) diff --git a/mach/sun3/libsys/getitimer.s b/mach/sun3/libsys/getitimer.s new file mode 100644 index 00000000..8d33cb8b --- /dev/null +++ b/mach/sun3/libsys/getitimer.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _getitimer +_getitimer: SYSTEM(SYS_getitimer) diff --git a/mach/sun3/libsys/getpagesiz.s b/mach/sun3/libsys/getpagesiz.s new file mode 100644 index 00000000..7c8c7145 --- /dev/null +++ b/mach/sun3/libsys/getpagesiz.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _getpagesize +_getpagesize: SYSTEM(SYS_getpagesize) diff --git a/mach/sun3/libsys/getpeernam.s b/mach/sun3/libsys/getpeernam.s new file mode 100644 index 00000000..d1e6e382 --- /dev/null +++ b/mach/sun3/libsys/getpeernam.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _getpeername +_getpeername: SYSTEM(SYS_getpeername) diff --git a/mach/sun3/libsys/getpgrp.s b/mach/sun3/libsys/getpgrp.s new file mode 100644 index 00000000..904c10a9 --- /dev/null +++ b/mach/sun3/libsys/getpgrp.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _getpgrp +_getpgrp: SYSTEM(SYS_getpgrp) diff --git a/mach/sun3/libsys/getpid.s b/mach/sun3/libsys/getpid.s new file mode 100644 index 00000000..192e55f1 --- /dev/null +++ b/mach/sun3/libsys/getpid.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _getpid +_getpid: SYSTEM(SYS_getpid) diff --git a/mach/sun3/libsys/getppid.s b/mach/sun3/libsys/getppid.s new file mode 100644 index 00000000..e44e431d --- /dev/null +++ b/mach/sun3/libsys/getppid.s @@ -0,0 +1,8 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _getppid +_getppid: + pea (SYS_getpid) + trap #0 + move.l d1,d0 + rts diff --git a/mach/sun3/libsys/getprio.s b/mach/sun3/libsys/getprio.s new file mode 100644 index 00000000..1e35849a --- /dev/null +++ b/mach/sun3/libsys/getprio.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _getpriority +_getpriority: SYSTEM(SYS_getpriority) diff --git a/mach/sun3/libsys/getrlimit.s b/mach/sun3/libsys/getrlimit.s new file mode 100644 index 00000000..076d0228 --- /dev/null +++ b/mach/sun3/libsys/getrlimit.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _getrlimit +_getrlimit: SYSTEM(SYS_getrlimit) diff --git a/mach/sun3/libsys/getrusage.s b/mach/sun3/libsys/getrusage.s new file mode 100644 index 00000000..091010d9 --- /dev/null +++ b/mach/sun3/libsys/getrusage.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _getrusage +_getrusage: SYSTEM(SYS_getrusage) diff --git a/mach/sun3/libsys/getsocknam.s b/mach/sun3/libsys/getsocknam.s new file mode 100644 index 00000000..477e0b1f --- /dev/null +++ b/mach/sun3/libsys/getsocknam.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _getsockname +_getsockname: SYSTEM(SYS_getsockname) diff --git a/mach/sun3/libsys/getsockopt.s b/mach/sun3/libsys/getsockopt.s new file mode 100644 index 00000000..20878c20 --- /dev/null +++ b/mach/sun3/libsys/getsockopt.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _getsockopt +_getsockopt: SYSTEM(SYS_getsockopt) diff --git a/mach/sun3/libsys/gettimday.s b/mach/sun3/libsys/gettimday.s new file mode 100644 index 00000000..63c8c8a2 --- /dev/null +++ b/mach/sun3/libsys/gettimday.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _gettimeofday +_gettimeofday: SYSTEM(SYS_gettimeofday) diff --git a/mach/sun3/libsys/getuid.s b/mach/sun3/libsys/getuid.s new file mode 100644 index 00000000..86dd28fe --- /dev/null +++ b/mach/sun3/libsys/getuid.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _getuid +_getuid: SYSTEM(SYS_getuid) diff --git a/mach/sun3/libsys/gtty.c b/mach/sun3/libsys/gtty.c new file mode 100644 index 00000000..7f42ea1f --- /dev/null +++ b/mach/sun3/libsys/gtty.c @@ -0,0 +1,7 @@ +#include +int gtty(fildes,argp) + int fildes ; + struct sgttyb *argp ; +{ + return ioctl(fildes,TIOCGETP,argp) ; +} diff --git a/mach/sun3/libsys/head_em.s b/mach/sun3/libsys/head_em.s new file mode 100644 index 00000000..36dd0b3f --- /dev/null +++ b/mach/sun3/libsys/head_em.s @@ -0,0 +1,65 @@ +.define .lino,.filn +.define EXIT +.define begtext,begdata,begbss +.define EARRAY,ERANGE,ESET,EIDIVZ,EHEAP,EILLINS,ECASE,EBADGTO +.define hol0,.reghp,.limhp,.trpim,.trppc +.sect .text +.sect .rom +.sect .data +.sect .bss + + + +! runtime startof for 68020 machine + + +LINO_AD = 0 +FILN_AD = 4 + +EARRAY = 0 +ERANGE = 1 +ESET = 2 +EIDIVZ = 6 +EHEAP = 17 +EILLINS = 18 +ECASE = 20 +EBADGTO = 27 + + .sect .text +begtext: + move.l (sp),d2 + lea (4,sp),a0 + move.l d2,d1 + add.l #1,d1 + asl.l #2,d1 + move.l a0,a1 + add.l d1,a1 + pea (a1) + pea (a0) + move.l d2,-(sp) + move.l #0,a6 + jsr (_m_a_i_n) + move.l d0,(sp) ! no stack cleanup needed +EXIT: + jsr (_exit) + + .sect .data +begdata: + .data4 0 ! may be at virtual address 0 with no problem +hol0: +.lino: + .data4 0 ! lino +.filn: + .data4 0 ! filn +.reghp: + .data4 endbss +.limhp: + .data4 endbss +.trppc: + .data4 0 +.trpim: + .data4 0 ! USED TO BE 2 BYTES; IS THIS RIGHT? + + + .sect .bss +begbss: !initialization is not needed because ALL entries are in zero space! diff --git a/mach/sun3/libsys/ioctl.s b/mach/sun3/libsys/ioctl.s new file mode 100644 index 00000000..1d90f161 --- /dev/null +++ b/mach/sun3/libsys/ioctl.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _ioctl +_ioctl: SYSTEM(SYS_ioctl) diff --git a/mach/sun3/libsys/kill.s b/mach/sun3/libsys/kill.s new file mode 100644 index 00000000..ad723cca --- /dev/null +++ b/mach/sun3/libsys/kill.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _kill +_kill: SYSTEM(SYS_kill) diff --git a/mach/sun3/libsys/killpg.s b/mach/sun3/libsys/killpg.s new file mode 100644 index 00000000..8318d618 --- /dev/null +++ b/mach/sun3/libsys/killpg.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _killpg +_killpg: SYSTEM(SYS_killpg) diff --git a/mach/sun3/libsys/link.s b/mach/sun3/libsys/link.s new file mode 100644 index 00000000..1968b8e2 --- /dev/null +++ b/mach/sun3/libsys/link.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _link +_link: SYSTEM(SYS_link) diff --git a/mach/sun3/libsys/listen.s b/mach/sun3/libsys/listen.s new file mode 100644 index 00000000..e0c5e8aa --- /dev/null +++ b/mach/sun3/libsys/listen.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _listen +_listen: SYSTEM(SYS_listen) diff --git a/mach/sun3/libsys/lockf.c b/mach/sun3/libsys/lockf.c new file mode 100644 index 00000000..43764d48 --- /dev/null +++ b/mach/sun3/libsys/lockf.c @@ -0,0 +1,43 @@ +#include +lockf(fildes, mode, size) + long size; +{ + struct { + short type, whence; long start, end; short pid; + } x; + int i = 8; + extern int errno; + + x.type = 2; + x.whence = 1; + x.start = 0; + x.end = size; + switch(mode) { + case 0: + x.type = 3; + break; + case 1: + i = 9; + break; + case 2: + break; + case 3: + if (fcntl(fildes,7,&x) == -1) { + return -1; + } + if (x.type == 3) { + return 0; + } + errno = EACCES; + return -1; + default: + errno = EINVAL; + return -1; + } + if (fcntl(fildes,i,&x) == -1) { + if (errno = 79) { + errno = 78; + } + return -1; + } +} diff --git a/mach/sun3/libsys/lseek.s b/mach/sun3/libsys/lseek.s new file mode 100644 index 00000000..ea2f18ef --- /dev/null +++ b/mach/sun3/libsys/lseek.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _lseek +_lseek: SYSTEM(SYS_lseek) diff --git a/mach/sun3/libsys/lstat.s b/mach/sun3/libsys/lstat.s new file mode 100644 index 00000000..b6e4ffe9 --- /dev/null +++ b/mach/sun3/libsys/lstat.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _lstat +_lstat: SYSTEM(SYS_lstat) diff --git a/mach/sun3/libsys/madvise.s b/mach/sun3/libsys/madvise.s new file mode 100644 index 00000000..310b5d48 --- /dev/null +++ b/mach/sun3/libsys/madvise.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _madvise +_madvise: SYSTEM(SYS_madvise) diff --git a/mach/sun3/libsys/mincore.s b/mach/sun3/libsys/mincore.s new file mode 100644 index 00000000..d7968530 --- /dev/null +++ b/mach/sun3/libsys/mincore.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _mincore +_mincore: SYSTEM(SYS_mincore) diff --git a/mach/sun3/libsys/mkdir.s b/mach/sun3/libsys/mkdir.s new file mode 100644 index 00000000..63128046 --- /dev/null +++ b/mach/sun3/libsys/mkdir.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _mkdir +_mkdir: SYSTEM(SYS_mkdir) diff --git a/mach/sun3/libsys/mknod.s b/mach/sun3/libsys/mknod.s new file mode 100644 index 00000000..75577fb0 --- /dev/null +++ b/mach/sun3/libsys/mknod.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _mknod +_mknod: SYSTEM(SYS_mknod) diff --git a/mach/sun3/libsys/mmap.s b/mach/sun3/libsys/mmap.s new file mode 100644 index 00000000..323b7ef1 --- /dev/null +++ b/mach/sun3/libsys/mmap.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _mmap +_mmap: SYSTEM(SYS_mmap) diff --git a/mach/sun3/libsys/mount.s b/mach/sun3/libsys/mount.s new file mode 100644 index 00000000..bc55d3a5 --- /dev/null +++ b/mach/sun3/libsys/mount.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _mount +_mount: SYSTEM(SYS_mount) diff --git a/mach/sun3/libsys/mprotect.s b/mach/sun3/libsys/mprotect.s new file mode 100644 index 00000000..eda5fa6e --- /dev/null +++ b/mach/sun3/libsys/mprotect.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _mprotect +_mprotect: SYSTEM(SYS_mprotect) diff --git a/mach/sun3/libsys/mremap.s b/mach/sun3/libsys/mremap.s new file mode 100644 index 00000000..7506f662 --- /dev/null +++ b/mach/sun3/libsys/mremap.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _mremap +_mremap: SYSTEM(SYS_mremap) diff --git a/mach/sun3/libsys/msg.s b/mach/sun3/libsys/msg.s new file mode 100644 index 00000000..f6b5871e --- /dev/null +++ b/mach/sun3/libsys/msg.s @@ -0,0 +1,18 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _msgget,_msgctl,_msgrcv,_msgsnd +_msgget: + pea (0) + bra 1f +_msgctl: + pea (1) + bra 1f +_msgrcv: + pea (2) + bra 1f +_msgsnd: + pea (3) +1: + move.l (4,sp),d0 + move.l (sp),(4,sp) + move.l d0,(sp) + jmp (_msgsys) diff --git a/mach/sun3/libsys/msgsys.s b/mach/sun3/libsys/msgsys.s new file mode 100644 index 00000000..e1771586 --- /dev/null +++ b/mach/sun3/libsys/msgsys.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _msgsys +_msgsys: SYSTEM(SYS_msgsys) diff --git a/mach/sun3/libsys/munmap.s b/mach/sun3/libsys/munmap.s new file mode 100644 index 00000000..8f420d19 --- /dev/null +++ b/mach/sun3/libsys/munmap.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _munmap +_munmap: SYSTEM(SYS_munmap) diff --git a/mach/sun3/libsys/nfssvc.s b/mach/sun3/libsys/nfssvc.s new file mode 100644 index 00000000..0082a793 --- /dev/null +++ b/mach/sun3/libsys/nfssvc.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _nfssvc +_nfssvc: SYSTEM(SYS_nfssvc) diff --git a/mach/sun3/libsys/nice.c b/mach/sun3/libsys/nice.c new file mode 100644 index 00000000..23505669 --- /dev/null +++ b/mach/sun3/libsys/nice.c @@ -0,0 +1,13 @@ +nice(incr) +{ + extern int errno; + int sav = errno; + int prio; + + errno = 0; + prio = getpriority(0,0); + if (prio == -1 && errno) return -1; + if (setpriority(0,0,prio+incr) < 0) return -1; + errno = sav; + return 0; +} diff --git a/mach/sun3/libsys/open.s b/mach/sun3/libsys/open.s new file mode 100644 index 00000000..9419b0bf --- /dev/null +++ b/mach/sun3/libsys/open.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _open +_open: SYSTEM(SYS_open) diff --git a/mach/sun3/libsys/pause.c b/mach/sun3/libsys/pause.c new file mode 100644 index 00000000..97c0242e --- /dev/null +++ b/mach/sun3/libsys/pause.c @@ -0,0 +1,3 @@ +pause() { + sigpause(sigblock()); +} diff --git a/mach/sun3/libsys/pipe.s b/mach/sun3/libsys/pipe.s new file mode 100644 index 00000000..1af4b8d5 --- /dev/null +++ b/mach/sun3/libsys/pipe.s @@ -0,0 +1,14 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _pipe +_pipe: + pea (SYS_pipe) + trap #0 + bcs 1f + move.l (4,sp),a0 + move.l d0,(a0)+ + move.l d1,(a0) + clr.l d0 + rts +1: + jmp (cerror) diff --git a/mach/sun3/libsys/plock.c b/mach/sun3/libsys/plock.c new file mode 100644 index 00000000..22a58c80 --- /dev/null +++ b/mach/sun3/libsys/plock.c @@ -0,0 +1,8 @@ +#include +plock(op) +{ + extern int errno; + + errno = EPERM; + return -1; +} diff --git a/mach/sun3/libsys/profil.s b/mach/sun3/libsys/profil.s new file mode 100644 index 00000000..be107bf2 --- /dev/null +++ b/mach/sun3/libsys/profil.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _profil +_profil: SYSTEM(SYS_profil) diff --git a/mach/sun3/libsys/ptrace.s b/mach/sun3/libsys/ptrace.s new file mode 100644 index 00000000..1f2a6a98 --- /dev/null +++ b/mach/sun3/libsys/ptrace.s @@ -0,0 +1,7 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _ptrace +.extern _errno +_ptrace: + clr.l (_errno) + SYSTEM(SYS_ptrace) diff --git a/mach/sun3/libsys/quotactl.s b/mach/sun3/libsys/quotactl.s new file mode 100644 index 00000000..88a2469a --- /dev/null +++ b/mach/sun3/libsys/quotactl.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _quotactl +_quotactl: SYSTEM(SYS_quotactl) diff --git a/mach/sun3/libsys/read.s b/mach/sun3/libsys/read.s new file mode 100644 index 00000000..de9df797 --- /dev/null +++ b/mach/sun3/libsys/read.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _read +_read: SYSTEM(SYS_read) diff --git a/mach/sun3/libsys/readlink.s b/mach/sun3/libsys/readlink.s new file mode 100644 index 00000000..18fd7330 --- /dev/null +++ b/mach/sun3/libsys/readlink.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _readlink +_readlink: SYSTEM(SYS_readlink) diff --git a/mach/sun3/libsys/readv.s b/mach/sun3/libsys/readv.s new file mode 100644 index 00000000..43c5cc88 --- /dev/null +++ b/mach/sun3/libsys/readv.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _readv +_readv: SYSTEM(SYS_readv) diff --git a/mach/sun3/libsys/reboot.s b/mach/sun3/libsys/reboot.s new file mode 100644 index 00000000..4aff452d --- /dev/null +++ b/mach/sun3/libsys/reboot.s @@ -0,0 +1,10 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _reboot +_reboot: + pea (SYS_reboot) + trap #0 + bcs 1f + stop #0 +1: + jmp (cerror) diff --git a/mach/sun3/libsys/recv.s b/mach/sun3/libsys/recv.s new file mode 100644 index 00000000..16fd7a5c --- /dev/null +++ b/mach/sun3/libsys/recv.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _recv +_recv: SYSTEM(SYS_recv) diff --git a/mach/sun3/libsys/recvfrom.s b/mach/sun3/libsys/recvfrom.s new file mode 100644 index 00000000..1c94feaf --- /dev/null +++ b/mach/sun3/libsys/recvfrom.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _recvfrom +_recvfrom: SYSTEM(SYS_recvfrom) diff --git a/mach/sun3/libsys/recvmsg.s b/mach/sun3/libsys/recvmsg.s new file mode 100644 index 00000000..9bac2736 --- /dev/null +++ b/mach/sun3/libsys/recvmsg.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _recvmsg +_recvmsg: SYSTEM(SYS_recvmsg) diff --git a/mach/sun3/libsys/rename.s b/mach/sun3/libsys/rename.s new file mode 100644 index 00000000..79b51bcf --- /dev/null +++ b/mach/sun3/libsys/rename.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _rename +_rename: SYSTEM(SYS_rename) diff --git a/mach/sun3/libsys/rmdir.s b/mach/sun3/libsys/rmdir.s new file mode 100644 index 00000000..34395d04 --- /dev/null +++ b/mach/sun3/libsys/rmdir.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _rmdir +_rmdir: SYSTEM(SYS_rmdir) diff --git a/mach/sun3/libsys/sbrk.s b/mach/sun3/libsys/sbrk.s new file mode 100644 index 00000000..b67d5800 --- /dev/null +++ b/mach/sun3/libsys/sbrk.s @@ -0,0 +1,41 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _sbrk,_brk +_sbrk: + move.l (4,sp),d0 + add.l #3,d0 + move.l #~3,d1 + and.l d1,d0 + move.l d0,a0 + move.l (curbrk),d0 + add.l #3,d0 + and.l d1,d0 + move.l d0,(curbrk) + add.l d0,a0 + move.l a0,(4,sp) + pea (17) ! not SYS_sbrk + trap #0 + bcs 1f + move.l (curbrk),d0 + move.l (4,sp),(curbrk) + rts +1: + jmp (cerror) + +_brk: + move.l (4,sp),d0 + add.l #3,d0 + move.l #~3,d1 + and.l d1,d0 + move.l d0,(4,sp) + pea (17) + trap #0 + bcs 1f + move.l (4,sp),(curbrk) + clr.l d0 + rts +1: + jmp (cerror) + +.sect .data +curbrk: .data4 endbss diff --git a/mach/sun3/libsys/select.s b/mach/sun3/libsys/select.s new file mode 100644 index 00000000..7f0425b7 --- /dev/null +++ b/mach/sun3/libsys/select.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _select +_select: SYSTEM(SYS_select) diff --git a/mach/sun3/libsys/sem.s b/mach/sun3/libsys/sem.s new file mode 100644 index 00000000..30de39ec --- /dev/null +++ b/mach/sun3/libsys/sem.s @@ -0,0 +1,15 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _semget,_semctl,_semop +_semget: + pea (1) + bra 1f +_semctl: + pea (0) + bra 1f +_semop: + pea (2) +1: + move.l (4,sp),d0 + move.l (sp),(4,sp) + move.l d0,(sp) + jmp (_semsys) diff --git a/mach/sun3/libsys/semsys.s b/mach/sun3/libsys/semsys.s new file mode 100644 index 00000000..9ae7bc08 --- /dev/null +++ b/mach/sun3/libsys/semsys.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _semsys +_semsys: SYSTEM(SYS_semsys) diff --git a/mach/sun3/libsys/send.s b/mach/sun3/libsys/send.s new file mode 100644 index 00000000..72970434 --- /dev/null +++ b/mach/sun3/libsys/send.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _send +_send: SYSTEM(SYS_send) diff --git a/mach/sun3/libsys/sendmsg.s b/mach/sun3/libsys/sendmsg.s new file mode 100644 index 00000000..3d38f3b6 --- /dev/null +++ b/mach/sun3/libsys/sendmsg.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _sendmsg +_sendmsg: SYSTEM(SYS_sendmsg) diff --git a/mach/sun3/libsys/sendto.s b/mach/sun3/libsys/sendto.s new file mode 100644 index 00000000..22d75232 --- /dev/null +++ b/mach/sun3/libsys/sendto.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _sendto +_sendto: SYSTEM(SYS_sendto) diff --git a/mach/sun3/libsys/setdomnam.s b/mach/sun3/libsys/setdomnam.s new file mode 100644 index 00000000..3bfeb0c1 --- /dev/null +++ b/mach/sun3/libsys/setdomnam.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _setdomainname +_setdomainname: SYSTEM(SYS_setdomainname) diff --git a/mach/sun3/libsys/setdopt.s b/mach/sun3/libsys/setdopt.s new file mode 100644 index 00000000..65674e89 --- /dev/null +++ b/mach/sun3/libsys/setdopt.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _setdopt +_setdopt: SYSTEM(SYS_setdopt) diff --git a/mach/sun3/libsys/setgid.c b/mach/sun3/libsys/setgid.c new file mode 100644 index 00000000..3137b1b0 --- /dev/null +++ b/mach/sun3/libsys/setgid.c @@ -0,0 +1,4 @@ +setgid(u) +{ + setregid(u,u); +} diff --git a/mach/sun3/libsys/setgroups.s b/mach/sun3/libsys/setgroups.s new file mode 100644 index 00000000..f3ad691d --- /dev/null +++ b/mach/sun3/libsys/setgroups.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _setgroups +_setgroups: SYSTEM(SYS_setgroups) diff --git a/mach/sun3/libsys/sethostnam.s b/mach/sun3/libsys/sethostnam.s new file mode 100644 index 00000000..b4756c76 --- /dev/null +++ b/mach/sun3/libsys/sethostnam.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _sethostname +_sethostname: SYSTEM(SYS_sethostname) diff --git a/mach/sun3/libsys/setitimer.s b/mach/sun3/libsys/setitimer.s new file mode 100644 index 00000000..acdf385c --- /dev/null +++ b/mach/sun3/libsys/setitimer.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _setitimer +_setitimer: SYSTEM(SYS_setitimer) diff --git a/mach/sun3/libsys/setpgrp.s b/mach/sun3/libsys/setpgrp.s new file mode 100644 index 00000000..9ef2fd62 --- /dev/null +++ b/mach/sun3/libsys/setpgrp.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _setpgrp +_setpgrp: SYSTEM(SYS_setpgrp) diff --git a/mach/sun3/libsys/setprio.s b/mach/sun3/libsys/setprio.s new file mode 100644 index 00000000..0004f5bd --- /dev/null +++ b/mach/sun3/libsys/setprio.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _setpriority +_setpriority: SYSTEM(SYS_setpriority) diff --git a/mach/sun3/libsys/setregid.s b/mach/sun3/libsys/setregid.s new file mode 100644 index 00000000..9c4206b1 --- /dev/null +++ b/mach/sun3/libsys/setregid.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _setregid +_setregid: SYSTEM(SYS_setregid) diff --git a/mach/sun3/libsys/setreuid.s b/mach/sun3/libsys/setreuid.s new file mode 100644 index 00000000..b0a9d85e --- /dev/null +++ b/mach/sun3/libsys/setreuid.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _setreuid +_setreuid: SYSTEM(SYS_setreuid) diff --git a/mach/sun3/libsys/setrlimit.s b/mach/sun3/libsys/setrlimit.s new file mode 100644 index 00000000..8f39b3fa --- /dev/null +++ b/mach/sun3/libsys/setrlimit.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _setrlimit +_setrlimit: SYSTEM(SYS_setrlimit) diff --git a/mach/sun3/libsys/setsockopt.s b/mach/sun3/libsys/setsockopt.s new file mode 100644 index 00000000..8a0a340c --- /dev/null +++ b/mach/sun3/libsys/setsockopt.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _setsockopt +_setsockopt: SYSTEM(SYS_setsockopt) diff --git a/mach/sun3/libsys/settimday.s b/mach/sun3/libsys/settimday.s new file mode 100644 index 00000000..30f7ed92 --- /dev/null +++ b/mach/sun3/libsys/settimday.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _settimeofday +_settimeofday: SYSTEM(SYS_settimeofday) diff --git a/mach/sun3/libsys/setuid.c b/mach/sun3/libsys/setuid.c new file mode 100644 index 00000000..bf851e10 --- /dev/null +++ b/mach/sun3/libsys/setuid.c @@ -0,0 +1,4 @@ +setuid(u) +{ + setreuid(u,u); +} diff --git a/mach/sun3/libsys/shm.s b/mach/sun3/libsys/shm.s new file mode 100644 index 00000000..54b58f3a --- /dev/null +++ b/mach/sun3/libsys/shm.s @@ -0,0 +1,18 @@ +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _shmget,_shmctl,_shmrcv,_shmsnd +_shmget: + pea (3) + bra 1f +_shmctl: + pea (1) + bra 1f +_shmat: + pea (4) + bra 1f +_shmdt: + pea (2) +1: + move.l (4,sp),d0 + move.l (sp),(4,sp) + move.l d0,(sp) + jmp (_shmsys) diff --git a/mach/sun3/libsys/shmsys.s b/mach/sun3/libsys/shmsys.s new file mode 100644 index 00000000..8f3f9f1a --- /dev/null +++ b/mach/sun3/libsys/shmsys.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _shmsys +_shmsys: SYSTEM(SYS_shmsys) diff --git a/mach/sun3/libsys/shutdown.s b/mach/sun3/libsys/shutdown.s new file mode 100644 index 00000000..a7400a13 --- /dev/null +++ b/mach/sun3/libsys/shutdown.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _shutdown +_shutdown: SYSTEM(SYS_shutdown) diff --git a/mach/sun3/libsys/sigblock.s b/mach/sun3/libsys/sigblock.s new file mode 100644 index 00000000..fd2393d1 --- /dev/null +++ b/mach/sun3/libsys/sigblock.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _sigblock +_sigblock: SYSTEM(SYS_sigblock) diff --git a/mach/sun3/libsys/signal.c b/mach/sun3/libsys/signal.c new file mode 100644 index 00000000..5c829ae1 --- /dev/null +++ b/mach/sun3/libsys/signal.c @@ -0,0 +1,25 @@ +static long masks[32]; +static long flags[32]; +int (* +signal(sig,handler))() + int (*handler)(); +{ + struct { + int (*sv_handler)(); + long sv_mask; + long sv_flags; + } v, ov; + + v.sv_handler = handler; + v.sv_mask = masks[sig]; + v.sv_flags = flags[sig]; + if (sigvec(sig,&v, &ov) < 0) return (int (*)()) -1; + if (v.sv_mask != ov.sv_mask || v.sv_flags != ov.sv_flags) { + v.sv_mask = ov.sv_mask; + masks[sig] = ov.sv_mask; + v.sv_flags = ov.sv_flags; + flags[sig] = ov.sv_flags; + if (sigvec(sig,&v,(char *) 0) < 0) return (int (*)()) -1; + } + return ov.sv_handler; +} diff --git a/mach/sun3/libsys/sigpause.s b/mach/sun3/libsys/sigpause.s new file mode 100644 index 00000000..b58223d2 --- /dev/null +++ b/mach/sun3/libsys/sigpause.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _sigpause +_sigpause: SYSTEM(SYS_sigpause) diff --git a/mach/sun3/libsys/sigsetmask.s b/mach/sun3/libsys/sigsetmask.s new file mode 100644 index 00000000..fab366a8 --- /dev/null +++ b/mach/sun3/libsys/sigsetmask.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _sigsetmask +_sigsetmask: SYSTEM(SYS_sigsetmask) diff --git a/mach/sun3/libsys/sigstack.s b/mach/sun3/libsys/sigstack.s new file mode 100644 index 00000000..efbf6d87 --- /dev/null +++ b/mach/sun3/libsys/sigstack.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _sigstack +_sigstack: SYSTEM(SYS_sigstack) diff --git a/mach/sun3/libsys/sigtramp.s b/mach/sun3/libsys/sigtramp.s new file mode 100644 index 00000000..188fa0ee --- /dev/null +++ b/mach/sun3/libsys/sigtramp.s @@ -0,0 +1,17 @@ +.sect .text +.define __sigtramp +__sigtramp: + movem.l d0/d1/a0/a1,-(sp) + move.l (_sigfunc),a0 + move.l (0x14,sp),d0 + lsl.l #2,d0 + move.l (a0,d0),a0 + move.l (0x1c,sp),-(sp) + move.l (0x1c,sp),-(sp) + move.l (0x1c,sp),-(sp) + jsr (a0) + add.l #12,sp + movem.l (sp)+,d0/d1/a0/a1 + add.l #8,sp + pea (0x8b) + trap #0 diff --git a/mach/sun3/libsys/sigvec.c b/mach/sun3/libsys/sigvec.c new file mode 100644 index 00000000..d3e9205d --- /dev/null +++ b/mach/sun3/libsys/sigvec.c @@ -0,0 +1,35 @@ +#include "syscall.h" +#include +struct sigvec { int (*handler)(); int mask,flags; }; +int (*(_sigfunc[32]))(); +extern int _sigtramp(); + +sigvec(sig,vec,ovec) + register struct sigvec *vec; + struct sigvec *ovec; +{ + struct sigvec tmp; + int (*old)(); + + if ((unsigned) sig >= 32) { + errno = EINVAL; + return -1; + } + old = _sigfunc[sig]; + if (vec) { + tmp = *vec; + vec = &tmp; + if (vec->handler && vec->handler != (int (*)()) 1) { + _sigfunc[sig] = vec->handler; + vec->handler = _sigtramp; + } + } + if (syscall(SYS_sigvec,sig,vec,ovec) < 0) { + _sigfunc[sig] = old; + return -1; + } + if (ovec->handler == _sigtramp) { + ovec->handler = old; + } + return 0; +} diff --git a/mach/sun3/libsys/socket.s b/mach/sun3/libsys/socket.s new file mode 100644 index 00000000..6494aee7 --- /dev/null +++ b/mach/sun3/libsys/socket.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _socket +_socket: SYSTEM(SYS_socket) diff --git a/mach/sun3/libsys/socketpair.s b/mach/sun3/libsys/socketpair.s new file mode 100644 index 00000000..f02d06e5 --- /dev/null +++ b/mach/sun3/libsys/socketpair.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _socketpair +_socketpair: SYSTEM(SYS_socketpair) diff --git a/mach/sun3/libsys/sstk.s b/mach/sun3/libsys/sstk.s new file mode 100644 index 00000000..30f6900e --- /dev/null +++ b/mach/sun3/libsys/sstk.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _sstk +_sstk: SYSTEM(SYS_sstk) diff --git a/mach/sun3/libsys/stat.s b/mach/sun3/libsys/stat.s new file mode 100644 index 00000000..37067e6a --- /dev/null +++ b/mach/sun3/libsys/stat.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _stat +_stat: SYSTEM(SYS_stat) diff --git a/mach/sun3/libsys/statfs.s b/mach/sun3/libsys/statfs.s new file mode 100644 index 00000000..8af106a3 --- /dev/null +++ b/mach/sun3/libsys/statfs.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _statfs +_statfs: SYSTEM(SYS_statfs) diff --git a/mach/sun3/libsys/stime.c b/mach/sun3/libsys/stime.c new file mode 100644 index 00000000..3b5b15f5 --- /dev/null +++ b/mach/sun3/libsys/stime.c @@ -0,0 +1,9 @@ +stime(tp) + long *tp; +{ + struct { long l1,l2; } x; + + x.l1 = *tp; + x.l2 = 0; + settimeofday(&x, (char *) 0); +} diff --git a/mach/sun3/libsys/stty.c b/mach/sun3/libsys/stty.c new file mode 100644 index 00000000..222310cc --- /dev/null +++ b/mach/sun3/libsys/stty.c @@ -0,0 +1,7 @@ +#include +int stty(fildes,argp) + int fildes ; + struct sgttyb *argp ; +{ + return ioctl(fildes,TIOCSETP,argp) ; +} diff --git a/mach/sun3/libsys/swapon.s b/mach/sun3/libsys/swapon.s new file mode 100644 index 00000000..d6947896 --- /dev/null +++ b/mach/sun3/libsys/swapon.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _swapon +_swapon: SYSTEM(SYS_swapon) diff --git a/mach/sun3/libsys/symlink.s b/mach/sun3/libsys/symlink.s new file mode 100644 index 00000000..b7e9372b --- /dev/null +++ b/mach/sun3/libsys/symlink.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _symlink +_symlink: SYSTEM(SYS_symlink) diff --git a/mach/sun3/libsys/sync.s b/mach/sun3/libsys/sync.s new file mode 100644 index 00000000..24cf538b --- /dev/null +++ b/mach/sun3/libsys/sync.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _sync +_sync: SYSTEM(SYS_sync) diff --git a/mach/sun3/libsys/syscall.h b/mach/sun3/libsys/syscall.h new file mode 100644 index 00000000..48911ca6 --- /dev/null +++ b/mach/sun3/libsys/syscall.h @@ -0,0 +1,127 @@ +#define SYSTEM(sys) pea (sys); trap #0; bcs 1f; rts; 1: jmp (cerror) +#define SYS_exit 1 +#define SYS_fork 2 +#define SYS_read 3 +#define SYS_write 4 +#define SYS_open 5 +#define SYS_close 6 +#define SYS_creat 8 +#define SYS_link 9 +#define SYS_unlink 10 +#define SYS_execv 11 +#define SYS_chdir 12 +#define SYS_mknod 14 +#define SYS_chmod 15 +#define SYS_chown 16 +#define SYS_lseek 19 +#define SYS_getpid 20 +#define SYS_getuid 24 +#define SYS_ptrace 26 +#define SYS_access 33 +#define SYS_sync 36 +#define SYS_kill 37 +#define SYS_stat 38 +#define SYS_lstat 40 +#define SYS_dup 41 +#define SYS_pipe 42 +#define SYS_profil 44 +#define SYS_getgid 47 +#define SYS_acct 51 +#define SYS_ioctl 54 +#define SYS_reboot 55 +#define SYS_symlink 57 +#define SYS_readlink 58 +#define SYS_execve 59 +#define SYS_umask 60 +#define SYS_chroot 61 +#define SYS_fstat 62 +#define SYS_getpagesize 64 +#define SYS_mremap 65 +#define SYS_vfork 66 +#define SYS_sbrk 69 +#define SYS_sstk 70 +#define SYS_mmap 71 +#define SYS_vadvise 72 +#define SYS_munmap 73 +#define SYS_mprotect 74 +#define SYS_madvise 75 +#define SYS_vhangup 76 +#define SYS_mincore 78 +#define SYS_getgroups 79 +#define SYS_setgroups 80 +#define SYS_getpgrp 81 +#define SYS_setpgrp 82 +#define SYS_setitimer 83 +#define SYS_wait 84 +#define SYS_swapon 85 +#define SYS_getitimer 86 +#define SYS_gethostname 87 +#define SYS_sethostname 88 +#define SYS_getdtablesize 89 +#define SYS_dup2 90 +#define SYS_getdopt 91 +#define SYS_fcntl 92 +#define SYS_select 93 +#define SYS_setdopt 94 +#define SYS_fsync 95 +#define SYS_setpriority 96 +#define SYS_socket 97 +#define SYS_connect 98 +#define SYS_accept 99 +#define SYS_getpriority 100 +#define SYS_send 101 +#define SYS_recv 102 +#define SYS_bind 104 +#define SYS_setsockopt 105 +#define SYS_listen 106 +#define SYS_sigvec 108 +#define SYS_sigblock 109 +#define SYS_sigsetmask 110 +#define SYS_sigpause 111 +#define SYS_sigstack 112 +#define SYS_recvmsg 113 +#define SYS_sendmsg 114 +#define SYS_gettimeofday 116 +#define SYS_getrusage 117 +#define SYS_getsockopt 118 +#define SYS_readv 120 +#define SYS_writev 121 +#define SYS_settimeofday 122 +#define SYS_fchown 123 +#define SYS_fchmod 124 +#define SYS_recvfrom 125 +#define SYS_setreuid 126 +#define SYS_setregid 127 +#define SYS_rename 128 +#define SYS_truncate 129 +#define SYS_ftruncate 130 +#define SYS_flock 131 +#define SYS_sendto 133 +#define SYS_shutdown 134 +#define SYS_socketpair 135 +#define SYS_mkdir 136 +#define SYS_rmdir 137 +#define SYS_utimes 138 +#define SYS_adjtime 140 +#define SYS_getpeername 141 +#define SYS_gethostid 142 +#define SYS_getrlimit 144 +#define SYS_setrlimit 145 +#define SYS_killpg 146 +#define SYS_getsockname 150 +#define SYS_nfssvc 155 +#define SYS_getdirentries 156 +#define SYS_statfs 157 +#define SYS_fstatfs 158 +#define SYS_unmount 159 +#define SYS_async_daemon 160 +#define SYS_getfh 161 +#define SYS_getdomainname 162 +#define SYS_setdomainname 163 +#define SYS_quotactl 165 +#define SYS_exportfs 166 +#define SYS_mount 167 +#define SYS_ustat 168 +#define SYS_semsys 169 +#define SYS_msgsys 170 +#define SYS_shmsys 171 diff --git a/mach/sun3/libsys/syscall.s b/mach/sun3/libsys/syscall.s new file mode 100644 index 00000000..5e732061 --- /dev/null +++ b/mach/sun3/libsys/syscall.s @@ -0,0 +1,14 @@ +.sect .text +.define _syscall +_syscall: + move.l (4,sp),d0 + move.l (sp),(4,sp) + move.l d0,(sp) + trap #0 + bcs 1f + move.l (sp),a0 + jmp (a0) +1: + move.l (sp),a0 + move.l a0,-(sp) + jmp (cerror) diff --git a/mach/sun3/libsys/tell.c b/mach/sun3/libsys/tell.c new file mode 100644 index 00000000..49e2a917 --- /dev/null +++ b/mach/sun3/libsys/tell.c @@ -0,0 +1,7 @@ +long +tell(f) +{ + long lseek(); + + return lseek(f, 0L, 1); +} diff --git a/mach/sun3/libsys/time.c b/mach/sun3/libsys/time.c new file mode 100644 index 00000000..3dd1eeae --- /dev/null +++ b/mach/sun3/libsys/time.c @@ -0,0 +1,12 @@ +long +time(loc) + long *loc; +{ + struct { long l1,l2; } t1; + + if (gettimeofday(&t1, (char *) 0) < 0) { + return -1; + } + if (loc) *loc = t1.l1; + return t1.l1; +} diff --git a/mach/sun3/libsys/times.c b/mach/sun3/libsys/times.c new file mode 100644 index 00000000..4e23d92b --- /dev/null +++ b/mach/sun3/libsys/times.c @@ -0,0 +1,16 @@ +#include + +#define Xval(xx) ((xx).l1*60+(xx).l2/(100000/6)) + +times(bp) + struct { time_t l1,l2,l3,l4;} *bp; +{ + struct { struct { long l1,l2; }s1,s2; long x[20]; } t; + if (getrusage(0,&t) < 0) return -1; + bp->l1 = Xval(t.s1); + bp->l2 = Xval(t.s2); + if (getrusage(-1,&t) < 0) return -1; + bp->l3 = Xval(t.s1); + bp->l4 = Xval(t.s2); + return 0; +} diff --git a/mach/sun3/libsys/truncate.s b/mach/sun3/libsys/truncate.s new file mode 100644 index 00000000..c9296606 --- /dev/null +++ b/mach/sun3/libsys/truncate.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _truncate +_truncate: SYSTEM(SYS_truncate) diff --git a/mach/sun3/libsys/ulimit.c b/mach/sun3/libsys/ulimit.c new file mode 100644 index 00000000..0e3715b3 --- /dev/null +++ b/mach/sun3/libsys/ulimit.c @@ -0,0 +1,26 @@ +#include + +ulimit(cmd, newlimit) + long newlimit; +{ + extern int errno; + struct { + long soft, hard; + } x; + + switch(cmd) { + case 1: + if (getrlimit(1, &x) < 0) return -1; + return ((x.soft + 511) & ~511) >> 9; + case 2: + x.soft = x.hard = (newlimit << 9); + if (setrlimit(1, &x) < 0) return -1; + return x.soft; + case 3: + if (getrlimit(2, &x) < 0) return -1; + return x.soft; + default: + errno = EINVAL; + return -1; + } +} diff --git a/mach/sun3/libsys/umask.s b/mach/sun3/libsys/umask.s new file mode 100644 index 00000000..cf1102eb --- /dev/null +++ b/mach/sun3/libsys/umask.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _umask +_umask: SYSTEM(SYS_umask) diff --git a/mach/sun3/libsys/uname.c b/mach/sun3/libsys/uname.c new file mode 100644 index 00000000..4670c25c --- /dev/null +++ b/mach/sun3/libsys/uname.c @@ -0,0 +1,26 @@ +extern int errno; + +struct utsname { + char sysname[9],nodename[9],release[9],version[9],machine[9]; +}; + +static char def_node[] = "unknown"; +static char rel[] = "4.2BSD"; +static char ver[] = "vm"; +static char mach[] = "sun"; + +uname(nm) + register struct utsname *nm; +{ + register char *p = nm->nodename; + + while (p <= nm->release) *p++ = 0; + if (gethostname(nm->nodename,9) == -1) { + strcpy(nm->nodename, def_node); + } + strncpy(nm->sysname,nm->nodename,9); + strncpy(nm->release,rel,9); + strncpy(nm->version,ver,9); + strncpy(nm->machine,mach,9); + return 0; +} diff --git a/mach/sun3/libsys/unlink.s b/mach/sun3/libsys/unlink.s new file mode 100644 index 00000000..f2507682 --- /dev/null +++ b/mach/sun3/libsys/unlink.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _unlink +_unlink: SYSTEM(SYS_unlink) diff --git a/mach/sun3/libsys/unmount.s b/mach/sun3/libsys/unmount.s new file mode 100644 index 00000000..4e23bd9f --- /dev/null +++ b/mach/sun3/libsys/unmount.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _unmount +_unmount: SYSTEM(SYS_unmount) diff --git a/mach/sun3/libsys/ustat.s b/mach/sun3/libsys/ustat.s new file mode 100644 index 00000000..cc03ac0f --- /dev/null +++ b/mach/sun3/libsys/ustat.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _ustat +_ustat: SYSTEM(SYS_ustat) diff --git a/mach/sun3/libsys/utime.c b/mach/sun3/libsys/utime.c new file mode 100644 index 00000000..a3804e33 --- /dev/null +++ b/mach/sun3/libsys/utime.c @@ -0,0 +1,13 @@ +#include + +utime(file, timep) + char *file; + time_t timep[2]; +{ + struct { long l1,l2,l3,l4; } x; + + x.l2 = x.l4 = 0; + x.l1 = timep[0]; + x.l3 = timep[1]; + utimes(file,&x); +} diff --git a/mach/sun3/libsys/utimes.s b/mach/sun3/libsys/utimes.s new file mode 100644 index 00000000..4cfa34cb --- /dev/null +++ b/mach/sun3/libsys/utimes.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _utimes +_utimes: SYSTEM(SYS_utimes) diff --git a/mach/sun3/libsys/vadvise.s b/mach/sun3/libsys/vadvise.s new file mode 100644 index 00000000..b21b4d69 --- /dev/null +++ b/mach/sun3/libsys/vadvise.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _vadvise +_vadvise: SYSTEM(SYS_vadvise) diff --git a/mach/sun3/libsys/vfork.s b/mach/sun3/libsys/vfork.s new file mode 100644 index 00000000..5ee9cace --- /dev/null +++ b/mach/sun3/libsys/vfork.s @@ -0,0 +1,18 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _vfork +_vfork: + move.l (sp)+,a0 + pea (SYS_vfork) + trap #0 + bcs 1f + tst.l d1 + bne 2f + jmp (a0) +1: + move.l d0,(_errno) + move.l #-1,d0 + jmp (a0) +2: + clr.l d0 + jmp (a0) diff --git a/mach/sun3/libsys/vhangup.s b/mach/sun3/libsys/vhangup.s new file mode 100644 index 00000000..d322320d --- /dev/null +++ b/mach/sun3/libsys/vhangup.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _vhangup +_vhangup: SYSTEM(SYS_vhangup) diff --git a/mach/sun3/libsys/wait.s b/mach/sun3/libsys/wait.s new file mode 100644 index 00000000..42ece9ee --- /dev/null +++ b/mach/sun3/libsys/wait.s @@ -0,0 +1,15 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _wait +_wait: + pea (SYS_wait) + trap #0 + bcs 1f + tst.l (4,sp) + beq 2f + move.l (4,sp),a0 + move.l d1,(a0) +2: + rts +1: + jmp (cerror) diff --git a/mach/sun3/libsys/wait3.s b/mach/sun3/libsys/wait3.s new file mode 100644 index 00000000..d55b6aca --- /dev/null +++ b/mach/sun3/libsys/wait3.s @@ -0,0 +1,18 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _wait3 +_wait3: + move.l (8,sp),d0 + move.l (12,sp),d1 + pea (SYS_wait) + or.b #0x1f,ccr + trap #0 + bcc 1f + jmp (cerror) +1: + tst.l (4,sp) + beq 1f + move.l (4,sp),a0 + move.l d1,(a0) +1: + rts diff --git a/mach/sun3/libsys/write.s b/mach/sun3/libsys/write.s new file mode 100644 index 00000000..3ace177a --- /dev/null +++ b/mach/sun3/libsys/write.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _write +_write: SYSTEM(SYS_write) diff --git a/mach/sun3/libsys/writev.s b/mach/sun3/libsys/writev.s new file mode 100644 index 00000000..89f4f528 --- /dev/null +++ b/mach/sun3/libsys/writev.s @@ -0,0 +1,4 @@ +#include "syscall.h" +.sect .text; .sect .rom; .sect .data; .sect .bss; .sect .text +.define _writev +_writev: SYSTEM(SYS_writev) From 957013759acec6a47ac733fb2ac8ab343cd85d58 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 20 Feb 1987 17:33:06 +0000 Subject: [PATCH 0827/1625] Bug fix --- mach/proto/cg/reg.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mach/proto/cg/reg.c b/mach/proto/cg/reg.c index b9db3a4c..187c9248 100644 --- a/mach/proto/cg/reg.c +++ b/mach/proto/cg/reg.c @@ -73,17 +73,21 @@ erasereg(regno) { register struct reginfo *rp; register int i; +#if MAXMEMBERS==0 rp = &machregs[regno]; rp->r_contents.t_token = 0; for (i=0;ir_contents.t_att[i].aw = 0; -#if MAXMEMBERS==0 awayreg(regno); #else for (rp=machregs;rpr_clash[regno>>4]&(1<<(regno&017))) + if (rp->r_clash[regno>>4]&(1<<(regno&017))) { + rp->r_contents.t_token = 0; + for (i=0;ir_contents.t_att[i].aw = 0; awayreg(rp-machregs); + } #endif } From b7e8220b5e9871862c07b24e464ef41140098479 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 20 Feb 1987 17:35:08 +0000 Subject: [PATCH 0828/1625] bug fix --- mach/proto/ncg/reg.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mach/proto/ncg/reg.c b/mach/proto/ncg/reg.c index 9f645fbe..b71d06d4 100644 --- a/mach/proto/ncg/reg.c +++ b/mach/proto/ncg/reg.c @@ -73,17 +73,21 @@ erasereg(regno) { register struct reginfo *rp; register int i; +#if MAXMEMBERS==0 rp = &machregs[regno]; rp->r_contents.t_token = 0; for (i=0;ir_contents.t_att[i].aw = 0; -#if MAXMEMBERS==0 awayreg(regno); #else for (rp=machregs+1;rpr_clash[regno>>4]&(1<<(regno&017))) + if (rp->r_clash[regno>>4]&(1<<(regno&017))) { + rp->r_contents.t_token = 0; + for (i=0;ir_contents.t_att[i].aw = 0; awayreg(rp-machregs); + } #endif } From 7c4a3f48a01f66f8bd30b5bb1d217d37f58f8ca0 Mon Sep 17 00:00:00 2001 From: ceriel Date: Sat, 21 Feb 1987 22:20:10 +0000 Subject: [PATCH 0829/1625] An attempt to make "erasereg" a little more efficient, as it seems often to be called to erase the condition codes. --- mach/proto/cg/reg.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mach/proto/cg/reg.c b/mach/proto/cg/reg.c index 187c9248..3b394eca 100644 --- a/mach/proto/cg/reg.c +++ b/mach/proto/cg/reg.c @@ -73,14 +73,19 @@ erasereg(regno) { register struct reginfo *rp; register int i; -#if MAXMEMBERS==0 +#if MAXMEMBERS!=0 + if (regno == 1) { /* condition codes */ +#endif rp = &machregs[regno]; rp->r_contents.t_token = 0; for (i=0;ir_contents.t_att[i].aw = 0; +#if MAXMEMBERS == 0 awayreg(regno); + #else + } else for (rp=machregs;rpr_clash[regno>>4]&(1<<(regno&017))) { rp->r_contents.t_token = 0; From cbcea69fad6ed635b32f1952cd6a27c1ccaf54ca Mon Sep 17 00:00:00 2001 From: ceriel Date: Sat, 21 Feb 1987 22:26:39 +0000 Subject: [PATCH 0830/1625] Initial revision --- lib/sun3/descr | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 lib/sun3/descr diff --git a/lib/sun3/descr b/lib/sun3/descr new file mode 100644 index 00000000..4612d758 --- /dev/null +++ b/lib/sun3/descr @@ -0,0 +1,55 @@ +# $Revision$ +var w=4 +var p=4 +var s=2 +var l=4 +var f=4 +var d=8 +var NAME=m68020 +var P=m68020 +var M=sun +var LIB=lib/{P}/tail_ +var RT=lib/{P}/head_ +var CPP_F=-Dunix=unix +var INCLUDES=-I{EM}/include/_tail_cc +# 413 align is the default, rom in text +var ALIGN=-a0:2 -a1:2 -a2:0x20000 -a3:2 -b0:0x2020 +name be + from .m.g + to .s + program {EM}/lib/{P}/cg + args < + stdout + need .e +end +name as + from .s.so + to .o + program {EM}/lib/{P}/as + args - -o > < + prep cond +end +name led + from .o.a + to .out + program {EM}/lib/em_led + mapflag -l* LNAME={EM}/{LIB}* + mapflag -n ALIGN=-a0:2 -a1:2 -a2:0x20000 -a3:2 -b0:0x2000 + mapflag -nr ALIGN=-a0:2 -a1:0x20000 -a2:2 -a3:2 -b0:0x2000 + mapflag -N ALIGN=-a0:2 -a1:2 -a2:2 -a3:2 -b0:0x2000 + mapflag -r ALIGN=-a0:2 -a1:0x20000 -a2:2 -a3:2 -b0:0x2020 + args (.e:{HEAD}= {ALIGN} {EM}/lib/{M}/head_em) \ +({RTS}:.b.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \ + (.p:{TAIL}={EM}/{LIB}pc) \ + (.b:{TAIL}={EM}/{LIB}bc) \ + (.b.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \ + (.e:{TAIL}={EM}/{LIB}em {EM}/lib/{M}/tail_mon {EM}/lib/{P}/end_em) + linker +end +name cv + from .out + to .cv + program {EM}/lib/{M}/cv + args < > + outfile a.out +end From af4bc8a874adaacf4890d9e115fb58a61b6d06e9 Mon Sep 17 00:00:00 2001 From: ceriel Date: Sun, 22 Feb 1987 15:28:26 +0000 Subject: [PATCH 0831/1625] better versions, bug fixes in compiler --- lang/basic/test/buzzword.b.g | 8 ++++---- lang/basic/test/gunner.b.g | 2 +- lang/basic/test/opg1.b.g | 2 +- lang/basic/test/opg6.b.g | 24 ++++++++++++------------ lang/basic/test/test10.b.g | 3 ++- lang/basic/test/test22.b.g | 2 +- lang/basic/test/test26.b.g | 4 ++-- lang/basic/test/test27.b.g | 3 +-- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/lang/basic/test/buzzword.b.g b/lang/basic/test/buzzword.b.g index c58bb160..89a8dd3d 100644 --- a/lang/basic/test/buzzword.b.g +++ b/lang/basic/test/buzzword.b.g @@ -5,8 +5,8 @@ acceptablewords to work into your material. The words don't actually mean anything, but they sound great. the procedure: -Think of any three numbers between 0 and 9, enter -them after the '?' separated by commas. your -buzzword will be printed out. Typing 100 for -each of your choices stops this program. + Think of any three numbers between 0 and 9, enter + them after the '?' separated by commas. your + buzzword will be printed out. Typing 100 for + each of your choices stops this program. What are your three numbers?LINE 260:ERROR 2: Out of data diff --git a/lang/basic/test/gunner.b.g b/lang/basic/test/gunner.b.g index 75ae3ec8..37ae5c0e 100644 --- a/lang/basic/test/gunner.b.g +++ b/lang/basic/test/gunner.b.g @@ -9,7 +9,7 @@ end the enemy will destroy you! maximum range of your gun is 46500 yards. - distance to the target is 43000 yards.... + distance to the target is 42956 yards.... elevation?LINE 410:ERROR 2: Out of data diff --git a/lang/basic/test/opg1.b.g b/lang/basic/test/opg1.b.g index 17bd3247..a9b931e0 100644 --- a/lang/basic/test/opg1.b.g +++ b/lang/basic/test/opg1.b.g @@ -1 +1 @@ -percent interest is 0.000173 +percent interest is 6.918919 diff --git a/lang/basic/test/opg6.b.g b/lang/basic/test/opg6.b.g index e7b51cfd..35068dae 100644 --- a/lang/basic/test/opg6.b.g +++ b/lang/basic/test/opg6.b.g @@ -4,15 +4,15 @@ fahrenheit centrigrade kelvin rankin - 144 0.00496 273.00496 604 - 36 0.138889 273.138889 496 - 110 0.007123 273.007123 570 - 98 0.008418 273.008418 558 - 63 0.017921 273.017921 523 - 26 -0.092593 272.907407 486 - 14 -0.030864 272.969136 474 - 78 0.012077 273.012077 538 - 66 0.01634 273.01634 526 - 51 0.02924 273.02924 511 - 107 0.007407 273.007407 567 - 2 -0.018519 272.981481 462 + 144 62.222222 335.222222 604 + 36 2.222222 275.222222 496 + 110 43.333333 316.333333 570 + 98 36.666667 309.666667 558 + 63 17.222222 290.222222 523 + 26 -3.333333 269.666667 486 + 14 -10 263 474 + 78 25.555556 298.555556 538 + 66 18.888889 291.888889 526 + 51 10.555556 283.555556 511 + 107 41.666667 314.666667 567 + 2 -16.666667 256.333333 462 diff --git a/lang/basic/test/test10.b.g b/lang/basic/test/test10.b.g index 835ea60c..b350b049 100644 --- a/lang/basic/test/test10.b.g +++ b/lang/basic/test/test10.b.g @@ -2,4 +2,5 @@ line130 line140 line150 -LINE 120:ERROR 1: RETURN without GOSUB + 4 end +Break in 121 diff --git a/lang/basic/test/test22.b.g b/lang/basic/test/test22.b.g index 8881da2d..fb73be7b 100644 --- a/lang/basic/test/test22.b.g +++ b/lang/basic/test/test22.b.g @@ -1,4 +1,4 @@ hello brave new world handicap try to read beyond -ÿ +LINE 70:ERROR 2: Out of data diff --git a/lang/basic/test/test26.b.g b/lang/basic/test/test26.b.g index c102d0b8..77236de5 100644 --- a/lang/basic/test/test26.b.g +++ b/lang/basic/test/test26.b.g @@ -9,8 +9,8 @@ chra 0 cos 1 0.000796 -0.999999 0.540302 sin 0 1 0.001593 -0.841471 exp 1 4.806648 23.103867 0.367879 -hex0 10 ffff -oct0 20 177777 +hex0 10 ffffffff +oct0 20 37777777777 len 0 3 1 tan 0 1255.765592 -0.001593 -1.557408 sqr 0 1.252996 1.772005 diff --git a/lang/basic/test/test27.b.g b/lang/basic/test/test27.b.g index 5475f1cd..32de3dd6 100644 --- a/lang/basic/test/test27.b.g +++ b/lang/basic/test/test27.b.g @@ -4,5 +4,4 @@ 160 true 170 true yes or no -? 0 - 0 +?LINE 190:ERROR 2: Out of data From 435edfa24ee016c73c7070a4e54e32d913cf6d67 Mon Sep 17 00:00:00 2001 From: ceriel Date: Sun, 22 Feb 1987 15:56:31 +0000 Subject: [PATCH 0832/1625] remove temporary --- lang/basic/src.old/util.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lang/basic/src.old/util.c b/lang/basic/src.old/util.c index 3a1d2acc..2905abd4 100644 --- a/lang/basic/src.old/util.c +++ b/lang/basic/src.old/util.c @@ -32,6 +32,7 @@ fatal(str) char *str; { Xerror("FATAL",str); + unlink(tmpfname); exit(-1); } notyetimpl() From 7471081794a3b51cde6430a3829a535bf9198d47 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 23 Feb 1987 09:18:41 +0000 Subject: [PATCH 0833/1625] Delete temporary --- lang/basic/src.old/bem.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lang/basic/src.old/bem.c b/lang/basic/src.old/bem.c index c91d6067..9a818c65 100644 --- a/lang/basic/src.old/bem.c +++ b/lang/basic/src.old/bem.c @@ -39,7 +39,10 @@ char **argv; /* compile source programs */ compileprogram(program); linewarnings(); - if( errorcnt) exit(-1); + if( errorcnt) { + unlink(tmpfname); + exit(-1); + } /* process em object files */ simpleprogram(); } From 9a664abf316dbf06f18c6c18ccb9e82860544556 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 23 Feb 1987 09:21:29 +0000 Subject: [PATCH 0834/1625] Current results --- lang/basic/test/Out.std | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lang/basic/test/Out.std b/lang/basic/test/Out.std index 16023944..eb5b81eb 100644 --- a/lang/basic/test/Out.std +++ b/lang/basic/test/Out.std @@ -1,8 +1,7 @@ for i in bull.b buzzword.b checker.b creator.b grafiek.b gunner.b learn.b opg1.b opg2.b opg3.b opg4.b opg5.b opg6.b som4.b test01.b test02.b test03.b test04.b test05.b test06.b test07.b test08.b test09.b test10.b test11.b test12.b test13.b test14.b test15.b test16.b test17.b test19.b test20.b test21.b test22.b test23.b test24.b test25.b test26.b test27.b test28.b test29.b test30.b test31.b test32.b test33.b test34.b test35.b ; do runcmp $i ; done bull.b ------- execution error(s)-*- Ok buzzword.b ------- execution error(s)-*- Ok -checker.b FATAL:improper file creation permission -------- compilation error(s) +checker.b ------- execution error(s)-*- Ok creator.b Undefined: __inkey ------- compilation error(s) @@ -25,7 +24,7 @@ test06.b -*- Ok test07.b ------- execution error(s)-*- Ok test08.b -*- Ok test09.b -*- Ok -test10.b ------- execution error(s)-*- Ok +test10.b -*- Ok test11.b -*- Ok test12.b -*- Ok test13.b -*- Ok @@ -36,12 +35,12 @@ test17.b ------- execution error(s)-*- Ok test19.b ------- execution error(s)-*- Ok test20.b -*- Ok test21.b -*- Ok -test22.b -*- Ok +test22.b ------- execution error(s)-*- Ok test23.b ------- execution error(s)-*- Ok test24.b -*- Ok test25.b -*- Ok test26.b -*- Ok -test27.b -*- Ok +test27.b ------- execution error(s)-*- Ok test28.b ------- execution error(s)-*- Ok test29.b -*- Ok test30.b ------- execution error(s)-*- Ok From 4e47313118e3f89601c392dc86aea64cbad67e5d Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 23 Feb 1987 09:22:33 +0000 Subject: [PATCH 0835/1625] Initial revision --- lang/basic/test/checker.b.g | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 lang/basic/test/checker.b.g diff --git a/lang/basic/test/checker.b.g b/lang/basic/test/checker.b.g new file mode 100644 index 00000000..ce033507 --- /dev/null +++ b/lang/basic/test/checker.b.g @@ -0,0 +1,35 @@ +This program will play checkers. The computer us X, +and you are 0. The computer will go first, -note: squares +are printed in the form-(X,Y) and sq. 1.1 is the bottom left! +do not attempt a double jump or your piece might just +disappear (same for triple!) + Wait for the computer to move!!!!!! + +retry + +retry + +retry + +retry + +retry + +retry + +retry + +retry + +retry + +retry + +retry + +retry + +retry + +retry +LINE 11300:ERROR 1: RETURN without GOSUB From 3fd2cf0a01bd4f32e0ed3a898b1b86008bd4b57d Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 23 Feb 1987 10:50:15 +0000 Subject: [PATCH 0836/1625] *** empty log message *** --- util/LLgen/lib/rec | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/util/LLgen/lib/rec b/util/LLgen/lib/rec index 9f35841b..03d19ad3 100644 --- a/util/LLgen/lib/rec +++ b/util/LLgen/lib/rec @@ -62,17 +62,17 @@ LLerror(t) { return; } #endif -#ifdef LL_USERHOOK - LL_USERHOOK(t); - LLread(); -#endif LL_USERHOOK if ((LLcsymb = LLindex[LLsymb]) < 0) { LLmessage(0); LLread(); } i = LLindex[t]; LLtcnt[i]++; - if (LLdoskip()) /* nothing */; +#ifdef LL_USERHOOK + if (LLdoskip(t)) /* nothing */; +#else + if (LLskip()) /* nothing */; +#endif LLtcnt[i]--; if (LLsymb != t) LLmessage(t); } @@ -95,14 +95,11 @@ LLnext(n) { LLskip() { #ifdef LL_USERHOOK - LL_USERHOOK(0); - LLread(); -#endif LL_USERHOOK - return LLdoskip(); + return LLdoskip(0); } -LLdoskip() -{ +LLdoskip(exp) { +#endif LL_USERHOOK register int i; int retval; int LLi, LLb; @@ -117,8 +114,16 @@ LLdoskip() if (LLsets[LL_SSIZE*i+LLi] & LLb) return retval; } } - retval = 1; +#ifdef LL_USERHOOK + { + int old = LLsymb; + LL_USERHOOK(exp); + LLread(); + if (LLsymb != old) continue; + } +#endif LL_USERHOOK LLmessage(0); + retval = 1; LLread(); } /* NOTREACHED */ From 7eb42b32b5d049398810fcbbf535aec9d46ba872 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 23 Feb 1987 11:01:13 +0000 Subject: [PATCH 0837/1625] Some minor improvements --- util/opt/patterns | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/util/opt/patterns b/util/opt/patterns index 78dd06a5..0248b490 100644 --- a/util/opt/patterns +++ b/util/opt/patterns @@ -183,9 +183,9 @@ loc lol adi loc $3==w: lol $2 loc $1 adi w loc $4 loc lol adi inc $3==w: lol $2 loc $1 adi w inc loc lol adi dec $3==w: lol $2 loc $1 adi w dec ldc lde mli $3==2*w: lde $2 ldc $1 mli 2*w -ldc lde adi $3==2*w: lde $2 ldc $1 adi 2*w +ldc lde adi ldc $3==2*w: lde $2 ldc $1 adi 2*w ldc $4 ldc ldl mli $3==2*w: ldl $2 ldc $1 mli 2*w -ldc ldl adi $3==2*w: ldl $2 ldc $1 adi 2*w +ldc ldl adi ldc $3==2*w: ldl $2 ldc $1 adi 2*w ldc $4 loc mli $1==2 && $2==w: loc 1 sli w loc mli $1==4 && $2==w: loc 2 sli w loc mli $1==8 && $2==w: loc 3 sli w @@ -381,7 +381,7 @@ loc loc loc $1==0 && $2==0 && $3==0 : zer 3*w zer loc defined($1) && $2==0: zer $1+w #endif loi loc and $1==1 && $3==w && ($2&255)==255: loi 1 -loi loc loc cii $1=0 && $5<128 && $6==w: loi 1 loc $5 cmi w zeq $7 loi loc loc cii loc cmi zne $1==1 && $2==1 && $3==w && $5>=0 && $5<128 && $6==w: loi 1 loc $5 cmi w zne $7 @@ -497,11 +497,17 @@ ldf loc inn $3==2*w && $2>=0 && $2<16*w : lof $1+($2/(8*w))*w loc $2&(8*w-1) inn w loc inn $1<0 || $1>=8*$2 : asp $2 loc 0 lol loc adi stl $3==w && $1==$4 : loc $2 lol $1 adi w stl $4 +ldl ldc adi sdl $3==2*w && $1==$4 : ldc $2 ldl $1 adi 2*w sdl $4 lol loe adi stl $3==w && $1==$4 : loe $2 lol $1 adi w stl $4 +ldl lde adi sdl $3==2*w && $1==$4 : lde $2 ldl $1 adi 2*w sdl $4 lol lol adi stl $3==w && $1==$4 && $1!=$2 : lol $2 lol $1 adi w stl $4 +ldl ldl adi sdl $3==2*w && $1==$4 &&$1!=$2 : ldl $2 ldl $1 adi 2*w sdl $4 loe loc adi ste $3==w && $1==$4 : loc $2 loe $1 adi w ste $4 +lde ldc adi sde $3==2*w && $1==$4 : ldc $2 lde $1 adi 2*w sde $4 loe loe adi ste $3==w && $1==$4 && $1!=$2 : loe $2 loe $1 adi w ste $4 +lde lde adi sde $3==2*w && $1==$4 && $1!=$2 : lde $2 lde $1 adi 2*w sde $4 loe lol adi ste $3==w && $1==$4 : lol $2 loe $1 adi w ste $4 +lde ldl adi sde $3==2*w && $1==$4 : ldl $2 lde $1 adi 2*w sde $4 lol loc ior stl $3==w && $1==$4 : loc $2 lol $1 ior w stl $4 lol loe ior stl $3==w && $1==$4 : loe $2 lol $1 ior w stl $4 lol lol ior stl $3==w && $1==$4 && $1!=$2 : lol $2 lol $1 ior w stl $4 From 19edf7ae067736d12f0007e1a079abdccc0435ee Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 23 Feb 1987 11:02:31 +0000 Subject: [PATCH 0838/1625] Added a dependency --- util/opt/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/util/opt/Makefile b/util/opt/Makefile index 7d2ff552..24e402b7 100644 --- a/util/opt/Makefile +++ b/util/opt/Makefile @@ -51,6 +51,8 @@ pattern.c: patterns mktab mktab: mktab.o $(LIBS) cc $(CFLAGS) mktab.o $(LIBS) $(LEXLIB) -o mktab +mktab.o: scan.c + depend: regglob.c regnoglob.c pattern.c sed '/^#AUTOAUTO/,$$d' Makefile >Makefile.new echo '#AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO' >> Makefile.new From 4c84af0a68c9353508a9a9e1481bbcbbbf9b723e Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 23 Feb 1987 11:23:46 +0000 Subject: [PATCH 0839/1625] *** empty log message *** --- modules/src/idf/idf.3 | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/modules/src/idf/idf.3 b/modules/src/idf/idf.3 index eb2ff5fb..52afdc73 100644 --- a/modules/src/idf/idf.3 +++ b/modules/src/idf/idf.3 @@ -1,7 +1,7 @@ .TH IDF 3ACK "March 17, 1986" .UC .SH NAME -init_idf, str2idf\ \-\ a namelist module +init_idf, str2idf, findidf\ \-\ a namelist module .SH SYNOPSIS .PP .B init_idf() @@ -59,7 +59,7 @@ The function creates an entry for it if necessary. A pointer to this entry is returned. If \fIcpy\fR is non-zero, a copy of the \fItag\fR is made, otherwise the \fItag\fR itself is used. -The entry has the following structure, defined in \fIinp_pkg.spec\fR: +The entry has the following structure, defined in \fIidf_pkg.spec\fR: .PP .nf struct idf { @@ -77,12 +77,10 @@ The field \fInext\fR is used for internal information and must not be changed by the user of this module. .PP The function \fIfindidf\fP searches for the string \fItag\fP in the -namelist, but returns 0 when it is'nt present. +namelist, but returns 0 when it is not present. .SH "MODULES USED" alloc(3) .SH FILES ~em/modules/pkg/idf_pkg.spec .br ~em/modules/pkg/idf_pkg.body -.SH DIAGNOSTICS -\fIstr2idf\fP returns a null pointer if there is no memory available. From e7761cca10f2c77ccc74de4cbc44353f15d09c1d Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 23 Feb 1987 11:38:15 +0000 Subject: [PATCH 0840/1625] Added No_Mem --- modules/src/alloc/Makefile | 5 +++-- modules/src/alloc/Malloc.c | 13 +++---------- modules/src/alloc/alloc.3 | 4 +++- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/modules/src/alloc/Makefile b/modules/src/alloc/Makefile index 25934250..964238a9 100644 --- a/modules/src/alloc/Makefile +++ b/modules/src/alloc/Makefile @@ -10,9 +10,10 @@ SOURCES = alloc.h\ botch.c\ clear.c\ st_alloc.c\ - std_alloc.c + std_alloc.c \ + No_Mem.c -OBJECTS = botch.o clear.o st_alloc.o Malloc.o std_alloc.o +OBJECTS = botch.o clear.o st_alloc.o Malloc.o std_alloc.o No_Mem.o all: liballoc.a diff --git a/modules/src/alloc/Malloc.c b/modules/src/alloc/Malloc.c index 97b7cddf..63dee388 100644 --- a/modules/src/alloc/Malloc.c +++ b/modules/src/alloc/Malloc.c @@ -14,20 +14,13 @@ #include "in_all.h" #include "alloc.h" -PRIVATE -m_fatal() { - - (void) sys_write(2, "Out of memory\n", 14); - sys_stop(S_EXIT); -} - EXPORT char * Malloc(sz) unsigned int sz; { char *res = malloc(sz); - if (res == 0) m_fatal(); + if (res == 0) No_Mem(); return res; } @@ -42,7 +35,7 @@ Salloc(str, sz) char *res = malloc(sz); register char *m = res; - if (m == 0) m_fatal(); + if (m == 0) No_Mem(); while (sz--) *m++ = *str++; return res; @@ -54,6 +47,6 @@ Srealloc(str, sz) unsigned int sz; { str = realloc(str, sz); - if (str == 0) m_fatal(); + if (str == 0) No_Mem(); return str; } diff --git a/modules/src/alloc/alloc.3 b/modules/src/alloc/alloc.3 index 3a71beb2..5afc88fc 100644 --- a/modules/src/alloc/alloc.3 +++ b/modules/src/alloc/alloc.3 @@ -70,4 +70,6 @@ These last two routines are best used in a macro. malloc(3) .SH DIAGNOSTICS \fIMalloc\fR, \fISalloc\fR, \fISrealloc\fR, and \fIst_alloc\fR -give an error message and stop execution if there is no memory available. +call a routine \fINo_Mem\fR if there is no memory available. This routine +is not supposed to return. A default one, that +gives an error message and stops execution, is provided. From a72685c2b5ddc6fa32b7f5bc43b6580146645bb2 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 23 Feb 1987 11:38:21 +0000 Subject: [PATCH 0841/1625] Initial revision --- modules/src/alloc/No_Mem.c | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 modules/src/alloc/No_Mem.c diff --git a/modules/src/alloc/No_Mem.c b/modules/src/alloc/No_Mem.c new file mode 100644 index 00000000..72c9025a --- /dev/null +++ b/modules/src/alloc/No_Mem.c @@ -0,0 +1,7 @@ +#include + +No_Mem() +{ + (void) sys_write(2, "Out of memory\n", 14); + sys_stop(S_EXIT); +} From 6445b233186fda7c24b365b9504b74b4b83a72d4 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 23 Feb 1987 13:08:54 +0000 Subject: [PATCH 0842/1625] bug fixes: - assignment operators for bit fields were wrong - some conversions for characters were wrong - result of assignment operator sometimes had wrong size - character constant \377 was 255, not -1 - string constant generation was clumsy --- lang/cem/cemcom/LLlex.c | 1 + lang/cem/cemcom/conversion.c | 28 +++++++++++++++------ lang/cem/cemcom/eval.c | 48 ++++++++++++++++++++++-------------- lang/cem/cemcom/field.c | 16 ++++++++---- lang/cem/cemcom/ival.c | 31 ++++++++++++++--------- 5 files changed, 82 insertions(+), 42 deletions(-) diff --git a/lang/cem/cemcom/LLlex.c b/lang/cem/cemcom/LLlex.c index f3a5771e..08032df1 100644 --- a/lang/cem/cemcom/LLlex.c +++ b/lang/cem/cemcom/LLlex.c @@ -309,6 +309,7 @@ firstline: LineNumber++; ch = quoted(ch); } + if (ch >= 128) ch -= 256; val = val*256 + ch; size++; LoadChar(ch); diff --git a/lang/cem/cemcom/conversion.c b/lang/cem/cemcom/conversion.c index 6e55474c..decd7ab6 100644 --- a/lang/cem/cemcom/conversion.c +++ b/lang/cem/cemcom/conversion.c @@ -32,22 +32,35 @@ conversion(from_type, to_type) if (from_type == to_type) /* a little optimisation */ return; + if (to_size < word_size) to_size = word_size; switch (fundamental(from_type)) { case T_SIGNED: switch (fundamental(to_type)) { case T_SIGNED: C_loc(from_size); - C_loc(to_size < word_size ? word_size : to_size); + C_loc(to_size); C_cii(); break; case T_UNSIGNED: - C_loc(from_size < word_size ? word_size : from_size); - C_loc(to_size < word_size ? word_size : to_size); + if (from_size < word_size) { + C_loc(from_size); + C_loc(word_size); + C_cii(); + from_size = word_size; + } + C_loc(from_size); + C_loc(to_size); C_ciu(); break; #ifndef NOFLOAT case T_FLOATING: - C_loc(from_size < word_size ? word_size : from_size); + if (from_size < word_size) { + C_loc(from_size); + C_loc(word_size); + C_cii(); + from_size = word_size; + } + C_loc(from_size); C_loc(to_size); C_cif(); break; @@ -55,8 +68,9 @@ conversion(from_type, to_type) } break; case T_UNSIGNED: - C_loc(from_size < word_size ? word_size : from_size); - C_loc(to_size < word_size ? word_size : to_size); + if (from_size < word_size) from_size = word_size; + C_loc(from_size); + C_loc(to_size); switch (fundamental(to_type)) { case T_SIGNED: C_cui(); @@ -74,7 +88,7 @@ conversion(from_type, to_type) #ifndef NOFLOAT case T_FLOATING: C_loc(from_size); - C_loc(to_size < word_size ? word_size : to_size); + C_loc(to_size); switch (fundamental(to_type)) { case T_SIGNED: C_cfi(); diff --git a/lang/cem/cemcom/eval.c b/lang/cem/cemcom/eval.c index 61a6ea7a..8b7d9d7f 100644 --- a/lang/cem/cemcom/eval.c +++ b/lang/cem/cemcom/eval.c @@ -395,32 +395,42 @@ EVAL(expr, val, code, true_label, false_label) } } if (newcode) { - conversion(left->ex_type, tp); if (gencode && (oper == POSTINCR || oper == POSTDECR)) - C_dup(tp->tp_size); + C_dup(ATW(left->ex_type->tp_size)); + conversion(left->ex_type, tp); } EVAL(right, RVAL, newcode, NO_LABEL, NO_LABEL); if (newcode) { + int dupval = gencode && oper != POSTINCR && + oper != POSTDECR; assop(tp, oper); - if (gencode && oper != POSTINCR && - oper != POSTDECR) - C_dup(tp->tp_size); conversion(tp, left->ex_type); - } - if (newcode && compl == 0) - store_val(&(left->ex_object.ex_value), - left->ex_type); - else - if (compl == 1) { - EVAL(left, LVAL, newcode, NO_LABEL, NO_LABEL); - if (newcode) C_sti(left->ex_type->tp_size); - } - else if (newcode) { - C_lal(tmp); /* always init'd */ - C_loi(pointer_size); - C_sti(left->ex_type->tp_size); - free_tmp_var(old_offset); + if (compl == 0) { + store_val(&(left->ex_object.ex_value), + left->ex_type); + if (dupval) load_val(left, RVAL); + } + else if (compl == 1) { + EVAL(left, LVAL,1, NO_LABEL, NO_LABEL); + C_sti(left->ex_type->tp_size); + if (dupval) { + EVAL(left, LVAL, 1, NO_LABEL, + NO_LABEL); + C_loi(left->ex_type->tp_size); + } + } + else { + C_lal(tmp); /* always init'd */ + C_loi(pointer_size); + C_sti(left->ex_type->tp_size); + if (dupval) { + C_lal(tmp); + C_loi(pointer_size); + C_loi(left->ex_type->tp_size); + } + free_tmp_var(old_offset); + } } break; } diff --git a/lang/cem/cemcom/field.c b/lang/cem/cemcom/field.c index 63c1b61b..0a34db00 100644 --- a/lang/cem/cemcom/field.c +++ b/lang/cem/cemcom/field.c @@ -99,13 +99,19 @@ eval_field(expr, code) C_sti(pointer_size); C_loi(asize); } - C_loc((arith)fd->fd_shift); - if (atype->tp_unsigned) + if (atype->tp_unsigned) { + C_loc((arith)fd->fd_shift); C_sru(asize); - else + C_loc(fd->fd_mask); + C_and(asize); + } + else { + arith bits_in_type = asize * 8; + C_loc(bits_in_type - (fd->fd_width + fd->fd_shift)); + C_sli(asize); + C_loc(bits_in_type - fd->fd_width); C_sri(asize); - C_loc(fd->fd_mask); - C_and(asize); + } if (code == TRUE && (op == POSTINCR || op == POSTDECR)) C_dup(asize); conversion(atype, rightop->ex_type); diff --git a/lang/cem/cemcom/ival.c b/lang/cem/cemcom/ival.c index b64577d9..87a4a71c 100644 --- a/lang/cem/cemcom/ival.c +++ b/lang/cem/cemcom/ival.c @@ -4,6 +4,7 @@ #include "nofloat.h" #include #include "debug.h" +#include #include "nobitfield.h" #include "arith.h" #include "align.h" @@ -469,12 +470,11 @@ ch_array(tpp, ex) struct expr *ex; { register struct type *tp = *tpp; - register arith length; - register char *s = ex->SG_VALUE; - register arith ntopad; + register arith length = ex->SG_LEN; + char *s; + arith ntopad; ASSERT(ex->ex_class == String); - length = ex->SG_LEN; if (tp->tp_size == (arith)-1) { /* set the dimension */ tp = *tpp = construct_type(ARRAY, tp->tp_up, length); @@ -497,19 +497,28 @@ ch_array(tpp, ex) ntopad = align(dim, word_align) - length; } /* throw out the characters of the already prepared string */ - while (length-- > 0) - C_con_ucon(long2str((long)*s++ & 0xFF, 10), (arith)1); - /* pad the allocated memory (the alignment has been calculated) */ - while (ntopad-- > 0) - con_nullbyte(); + s = Malloc((int) (length + ntopad)); + clear(s, (int) (length + ntopad)); + strncpy(s, ex->SG_VALUE, (int) length); + str_cst(s, (int) (length + ntopad)); + free(s); } +/* As long as some parts of the pipeline cannot handle very long string + constants, string constants are written out in chunks +*/ str_cst(str, len) register char *str; register int len; { - while (len-- > 0) - C_con_ucon(long2str((long)*str++ & 0xFF, 10), (arith)1); + arith chunksize = ((127 + word_size) / word_size) * word_size; + + while (len > chunksize) { + C_con_scon(str, chunksize); + len -= chunksize; + str += chunksize; + } + C_con_scon(str, (arith) len); } #ifndef NOBITFIELD From ffa788536fbb4f3a9fabfcdc43b5823441577603 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 23 Feb 1987 14:06:17 +0000 Subject: [PATCH 0843/1625] *** empty log message *** --- modules/src/em_code/k/em.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/src/em_code/k/em.c b/modules/src/em_code/k/em.c index f38e2a33..7f6d179b 100644 --- a/modules/src/em_code/k/em.c +++ b/modules/src/em_code/k/em.c @@ -27,7 +27,7 @@ static File *ofp = 0; static flush() { if (sys_write(ofp, &obuf[0], opp - &obuf[0]) == 0) { - sys_stop(S_ABORT); + C_failed(); } opp = &obuf[0]; } From 57e07411f08d4afe19c71769737bd3dc4a5822c6 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 23 Feb 1987 14:14:35 +0000 Subject: [PATCH 0844/1625] Initial revision --- modules/src/em_code/e/C_failed.c | 7 +++++++ modules/src/em_code/k/C_failed.c | 7 +++++++ 2 files changed, 14 insertions(+) create mode 100644 modules/src/em_code/e/C_failed.c create mode 100644 modules/src/em_code/k/C_failed.c diff --git a/modules/src/em_code/e/C_failed.c b/modules/src/em_code/e/C_failed.c new file mode 100644 index 00000000..a37d34f3 --- /dev/null +++ b/modules/src/em_code/e/C_failed.c @@ -0,0 +1,7 @@ +#include + +C_failed() +{ + sys_write(2,"write failed\n",13); + sys_stop(S_EXIT); +} diff --git a/modules/src/em_code/k/C_failed.c b/modules/src/em_code/k/C_failed.c new file mode 100644 index 00000000..a37d34f3 --- /dev/null +++ b/modules/src/em_code/k/C_failed.c @@ -0,0 +1,7 @@ +#include + +C_failed() +{ + sys_write(2,"write failed\n",13); + sys_stop(S_EXIT); +} From 9e3161b2d8634296bfa63515c805ea3c73cd8b84 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 23 Feb 1987 14:22:16 +0000 Subject: [PATCH 0845/1625] *** empty log message *** --- modules/src/em_code/Makefile | 4 ++-- modules/src/em_code/em_code.3X | 14 ++++++++------ modules/src/em_code/make.fun | 1 + 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/modules/src/em_code/Makefile b/modules/src/em_code/Makefile index 4aeca135..88fe5d11 100644 --- a/modules/src/em_code/Makefile +++ b/modules/src/em_code/Makefile @@ -17,11 +17,11 @@ compare: all em_code.3: em_code.3X tbl < em_code.3X > em_code.3 -libeme.a: make.sh e/em_private.h e/em.c +libeme.a: make.sh e/em_private.h e/em.c e/C_failed.c EMHOME=$(EMHOME); export EMHOME; sh make.sh e -sh -c 'ranlib libeme.a' -libemk.a: make.sh k/em_private.h k/em.c +libemk.a: make.sh k/em_private.h k/em.c k/C_failed.c EMHOME=$(EMHOME); export EMHOME; sh make.sh k -sh -c 'ranlib libemk.a' diff --git a/modules/src/em_code/em_code.3X b/modules/src/em_code/em_code.3X index 37a5464a..0e11895c 100644 --- a/modules/src/em_code/em_code.3X +++ b/modules/src/em_code/em_code.3X @@ -408,13 +408,15 @@ Informatica Rapport IR-81, Vrije Universiteit, Amsterdam, 1983. .SH DIAGNOSTICS .I C_open returns 1 if the open is successful and 0 if not. -The other routines do not give any information about their completion. +.PP +When a write fails, the routine +.I C_failed +is called. The user can override its default definition by supplying his +own. The default just gives an error message and quits. .SH BUGS -.IP \(bu -Feel free to report them to the author. -.IP \(bu It is not possible to indicate that the argument of .B C_con_cst () must be seen as an unsigned value. -.SH AUTHOR -Erik Baalbergen +.PP +.I C_failed +is never called when generating readable EM code. diff --git a/modules/src/em_code/make.fun b/modules/src/em_code/make.fun index 15363c5a..37822553 100755 --- a/modules/src/em_code/make.fun +++ b/modules/src/em_code/make.fun @@ -41,6 +41,7 @@ rm -f *.o . $a cc -c -O -I$1 -I$EMHOME/modules/h -I$EMHOME/h $1/em.c +cc -c -O -I$1 -I$EMHOME/modules/h -I$EMHOME/h $1/C_failed.c mv em.o em$1.o rm -f libem$1.a ar rc libem$1.a *.o From 68495f54bc0be73088af7d2ebabb23666b709ffa Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 23 Feb 1987 15:48:27 +0000 Subject: [PATCH 0846/1625] bug fix --- util/ncgg/output.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/ncgg/output.c b/util/ncgg/output.c index 853b2bc6..5baf74ec 100644 --- a/util/ncgg/output.c +++ b/util/ncgg/output.c @@ -689,12 +689,12 @@ varinfo *kills,*allocates,*generates,*yields,*leaving; code53(DO_REMOVE,1); codeint(vp->vi_int[0]); codeint(vp->vi_int[1]); - } else if (vp->vi_int[1] >= 0) { + } else if (vp->vi_int[0] >= 0) { code53(DO_REMOVE,0); codeint(vp->vi_int[0]); } else { code8(DO_RREMOVE); - codeint(vp->vi_int[0]); + codeint(-vp->vi_int[0] - 1); } codenl(); } From cbd521f14f2fb724dc66705de5c94ae1bba0d6ab Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 23 Feb 1987 18:28:42 +0000 Subject: [PATCH 0847/1625] *** empty log message *** --- mach/sun3/libsys/setgid.c | 2 +- mach/sun3/libsys/setuid.c | 2 +- mach/sun3/libsys/stime.c | 2 +- mach/sun3/libsys/utime.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mach/sun3/libsys/setgid.c b/mach/sun3/libsys/setgid.c index 3137b1b0..c51a4d02 100644 --- a/mach/sun3/libsys/setgid.c +++ b/mach/sun3/libsys/setgid.c @@ -1,4 +1,4 @@ setgid(u) { - setregid(u,u); + return setregid(u,u); } diff --git a/mach/sun3/libsys/setuid.c b/mach/sun3/libsys/setuid.c index bf851e10..04a87340 100644 --- a/mach/sun3/libsys/setuid.c +++ b/mach/sun3/libsys/setuid.c @@ -1,4 +1,4 @@ setuid(u) { - setreuid(u,u); + return setreuid(u,u); } diff --git a/mach/sun3/libsys/stime.c b/mach/sun3/libsys/stime.c index 3b5b15f5..b13ee43b 100644 --- a/mach/sun3/libsys/stime.c +++ b/mach/sun3/libsys/stime.c @@ -5,5 +5,5 @@ stime(tp) x.l1 = *tp; x.l2 = 0; - settimeofday(&x, (char *) 0); + return settimeofday(&x, (char *) 0); } diff --git a/mach/sun3/libsys/utime.c b/mach/sun3/libsys/utime.c index a3804e33..8c265e1d 100644 --- a/mach/sun3/libsys/utime.c +++ b/mach/sun3/libsys/utime.c @@ -9,5 +9,5 @@ utime(file, timep) x.l2 = x.l4 = 0; x.l1 = timep[0]; x.l3 = timep[1]; - utimes(file,&x); + return utimes(file,&x); } From 7abb75aa7e2a25c4a5bcafa1a650844e5424a40f Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 23 Feb 1987 18:58:58 +0000 Subject: [PATCH 0848/1625] Initial revision --- mach/vax4/libbsd4_2/LIST | 131 +++++++++++++++++++++++++++++++ mach/vax4/libbsd4_2/_exit.s | 3 + mach/vax4/libbsd4_2/accept.s | 3 + mach/vax4/libbsd4_2/access.s | 3 + mach/vax4/libbsd4_2/acct.s | 3 + mach/vax4/libbsd4_2/alarm.c | 13 +++ mach/vax4/libbsd4_2/bind.s | 3 + mach/vax4/libbsd4_2/brk.s | 29 +++++++ mach/vax4/libbsd4_2/cerror.s | 5 ++ mach/vax4/libbsd4_2/chdir.s | 3 + mach/vax4/libbsd4_2/chmod.s | 3 + mach/vax4/libbsd4_2/chown.s | 3 + mach/vax4/libbsd4_2/chroot.s | 3 + mach/vax4/libbsd4_2/cleanup.c | 1 + mach/vax4/libbsd4_2/close.s | 3 + mach/vax4/libbsd4_2/connect.s | 3 + mach/vax4/libbsd4_2/creat.s | 3 + mach/vax4/libbsd4_2/dup.s | 3 + mach/vax4/libbsd4_2/dup2.s | 3 + mach/vax4/libbsd4_2/execl.s | 8 ++ mach/vax4/libbsd4_2/execle.s | 8 ++ mach/vax4/libbsd4_2/exect.s | 5 ++ mach/vax4/libbsd4_2/execv.s | 8 ++ mach/vax4/libbsd4_2/execve.s | 3 + mach/vax4/libbsd4_2/exit.c | 5 ++ mach/vax4/libbsd4_2/fchmod.s | 3 + mach/vax4/libbsd4_2/fchown.s | 3 + mach/vax4/libbsd4_2/fcntl.s | 3 + mach/vax4/libbsd4_2/flock.s | 3 + mach/vax4/libbsd4_2/fork.s | 10 +++ mach/vax4/libbsd4_2/fstat.s | 3 + mach/vax4/libbsd4_2/fsync.s | 3 + mach/vax4/libbsd4_2/ftime.c | 15 ++++ mach/vax4/libbsd4_2/ftruncate.s | 3 + mach/vax4/libbsd4_2/getdtabsz.s | 3 + mach/vax4/libbsd4_2/getegid.s | 5 ++ mach/vax4/libbsd4_2/geteuid.s | 5 ++ mach/vax4/libbsd4_2/getgid.s | 3 + mach/vax4/libbsd4_2/getgroups.s | 3 + mach/vax4/libbsd4_2/gethostid.s | 3 + mach/vax4/libbsd4_2/gethostnam.s | 3 + mach/vax4/libbsd4_2/getitimer.s | 3 + mach/vax4/libbsd4_2/getpagesiz.s | 3 + mach/vax4/libbsd4_2/getpeernam.s | 3 + mach/vax4/libbsd4_2/getpgrp.s | 3 + mach/vax4/libbsd4_2/getpid.s | 3 + mach/vax4/libbsd4_2/getppid.s | 5 ++ mach/vax4/libbsd4_2/getprio.s | 3 + mach/vax4/libbsd4_2/getrlimit.s | 3 + mach/vax4/libbsd4_2/getrusage.s | 3 + mach/vax4/libbsd4_2/getsocknam.s | 3 + mach/vax4/libbsd4_2/getsockopt.s | 3 + mach/vax4/libbsd4_2/gettimday.s | 3 + mach/vax4/libbsd4_2/getuid.s | 3 + mach/vax4/libbsd4_2/gtty.c | 7 ++ mach/vax4/libbsd4_2/ioctl.s | 3 + mach/vax4/libbsd4_2/kill.s | 3 + mach/vax4/libbsd4_2/killpg.s | 3 + mach/vax4/libbsd4_2/link.s | 3 + mach/vax4/libbsd4_2/listen.s | 3 + mach/vax4/libbsd4_2/lseek.s | 3 + mach/vax4/libbsd4_2/lstat.s | 3 + mach/vax4/libbsd4_2/mkdir.s | 3 + mach/vax4/libbsd4_2/mknod.s | 3 + mach/vax4/libbsd4_2/mount.s | 5 ++ mach/vax4/libbsd4_2/nice.c | 13 +++ mach/vax4/libbsd4_2/open.s | 3 + mach/vax4/libbsd4_2/pause.c | 3 + mach/vax4/libbsd4_2/pipe.s | 8 ++ mach/vax4/libbsd4_2/profil.s | 3 + mach/vax4/libbsd4_2/ptrace.s | 4 + mach/vax4/libbsd4_2/quota.s | 3 + mach/vax4/libbsd4_2/read.s | 3 + mach/vax4/libbsd4_2/readlink.s | 3 + mach/vax4/libbsd4_2/readv.s | 3 + mach/vax4/libbsd4_2/reboot.s | 4 + mach/vax4/libbsd4_2/recv.s | 3 + mach/vax4/libbsd4_2/recvfrom.s | 3 + mach/vax4/libbsd4_2/recvmsg.s | 3 + mach/vax4/libbsd4_2/rename.s | 3 + mach/vax4/libbsd4_2/rmdir.s | 3 + mach/vax4/libbsd4_2/select.s | 3 + mach/vax4/libbsd4_2/send.s | 3 + mach/vax4/libbsd4_2/sendmsg.s | 3 + mach/vax4/libbsd4_2/sendto.s | 3 + mach/vax4/libbsd4_2/setgid.c | 4 + mach/vax4/libbsd4_2/setgroups.s | 3 + mach/vax4/libbsd4_2/sethostid.s | 3 + mach/vax4/libbsd4_2/sethostnam.s | 3 + mach/vax4/libbsd4_2/setitimer.s | 3 + mach/vax4/libbsd4_2/setpgrp.s | 3 + mach/vax4/libbsd4_2/setprio.s | 3 + mach/vax4/libbsd4_2/setquota.s | 3 + mach/vax4/libbsd4_2/setregid.s | 3 + mach/vax4/libbsd4_2/setreuid.s | 3 + mach/vax4/libbsd4_2/setrlimit.s | 3 + mach/vax4/libbsd4_2/setsockopt.s | 3 + mach/vax4/libbsd4_2/settimday.s | 3 + mach/vax4/libbsd4_2/setuid.c | 4 + mach/vax4/libbsd4_2/shutdown.s | 3 + mach/vax4/libbsd4_2/sigblock.s | 3 + mach/vax4/libbsd4_2/signal.c | 25 ++++++ mach/vax4/libbsd4_2/sigpause.s | 3 + mach/vax4/libbsd4_2/sigsetmask.s | 3 + mach/vax4/libbsd4_2/sigstack.s | 3 + mach/vax4/libbsd4_2/sigvec.s | 3 + mach/vax4/libbsd4_2/socket.s | 3 + mach/vax4/libbsd4_2/socketpair.s | 3 + mach/vax4/libbsd4_2/stat.s | 3 + mach/vax4/libbsd4_2/stime.c | 9 +++ mach/vax4/libbsd4_2/stty.c | 7 ++ mach/vax4/libbsd4_2/swapon.s | 3 + mach/vax4/libbsd4_2/symlink.s | 3 + mach/vax4/libbsd4_2/sync.s | 3 + mach/vax4/libbsd4_2/syscall.h | 118 ++++++++++++++++++++++++++++ mach/vax4/libbsd4_2/syscall.s | 9 +++ mach/vax4/libbsd4_2/tell.c | 7 ++ mach/vax4/libbsd4_2/time.c | 12 +++ mach/vax4/libbsd4_2/times.c | 16 ++++ mach/vax4/libbsd4_2/truncate.s | 3 + mach/vax4/libbsd4_2/umask.s | 3 + mach/vax4/libbsd4_2/umount.s | 3 + mach/vax4/libbsd4_2/unlink.s | 3 + mach/vax4/libbsd4_2/utime.c | 13 +++ mach/vax4/libbsd4_2/utimes.s | 3 + mach/vax4/libbsd4_2/vadvise.s | 3 + mach/vax4/libbsd4_2/vfork.s | 17 ++++ mach/vax4/libbsd4_2/vhangup.s | 3 + mach/vax4/libbsd4_2/wait.s | 8 ++ mach/vax4/libbsd4_2/wait3.s | 14 ++++ mach/vax4/libbsd4_2/write.s | 3 + mach/vax4/libbsd4_2/writev.s | 3 + 132 files changed, 848 insertions(+) create mode 100644 mach/vax4/libbsd4_2/LIST create mode 100644 mach/vax4/libbsd4_2/_exit.s create mode 100644 mach/vax4/libbsd4_2/accept.s create mode 100644 mach/vax4/libbsd4_2/access.s create mode 100644 mach/vax4/libbsd4_2/acct.s create mode 100644 mach/vax4/libbsd4_2/alarm.c create mode 100644 mach/vax4/libbsd4_2/bind.s create mode 100644 mach/vax4/libbsd4_2/brk.s create mode 100644 mach/vax4/libbsd4_2/cerror.s create mode 100644 mach/vax4/libbsd4_2/chdir.s create mode 100644 mach/vax4/libbsd4_2/chmod.s create mode 100644 mach/vax4/libbsd4_2/chown.s create mode 100644 mach/vax4/libbsd4_2/chroot.s create mode 100644 mach/vax4/libbsd4_2/cleanup.c create mode 100644 mach/vax4/libbsd4_2/close.s create mode 100644 mach/vax4/libbsd4_2/connect.s create mode 100644 mach/vax4/libbsd4_2/creat.s create mode 100644 mach/vax4/libbsd4_2/dup.s create mode 100644 mach/vax4/libbsd4_2/dup2.s create mode 100644 mach/vax4/libbsd4_2/execl.s create mode 100644 mach/vax4/libbsd4_2/execle.s create mode 100644 mach/vax4/libbsd4_2/exect.s create mode 100644 mach/vax4/libbsd4_2/execv.s create mode 100644 mach/vax4/libbsd4_2/execve.s create mode 100644 mach/vax4/libbsd4_2/exit.c create mode 100644 mach/vax4/libbsd4_2/fchmod.s create mode 100644 mach/vax4/libbsd4_2/fchown.s create mode 100644 mach/vax4/libbsd4_2/fcntl.s create mode 100644 mach/vax4/libbsd4_2/flock.s create mode 100644 mach/vax4/libbsd4_2/fork.s create mode 100644 mach/vax4/libbsd4_2/fstat.s create mode 100644 mach/vax4/libbsd4_2/fsync.s create mode 100644 mach/vax4/libbsd4_2/ftime.c create mode 100644 mach/vax4/libbsd4_2/ftruncate.s create mode 100644 mach/vax4/libbsd4_2/getdtabsz.s create mode 100644 mach/vax4/libbsd4_2/getegid.s create mode 100644 mach/vax4/libbsd4_2/geteuid.s create mode 100644 mach/vax4/libbsd4_2/getgid.s create mode 100644 mach/vax4/libbsd4_2/getgroups.s create mode 100644 mach/vax4/libbsd4_2/gethostid.s create mode 100644 mach/vax4/libbsd4_2/gethostnam.s create mode 100644 mach/vax4/libbsd4_2/getitimer.s create mode 100644 mach/vax4/libbsd4_2/getpagesiz.s create mode 100644 mach/vax4/libbsd4_2/getpeernam.s create mode 100644 mach/vax4/libbsd4_2/getpgrp.s create mode 100644 mach/vax4/libbsd4_2/getpid.s create mode 100644 mach/vax4/libbsd4_2/getppid.s create mode 100644 mach/vax4/libbsd4_2/getprio.s create mode 100644 mach/vax4/libbsd4_2/getrlimit.s create mode 100644 mach/vax4/libbsd4_2/getrusage.s create mode 100644 mach/vax4/libbsd4_2/getsocknam.s create mode 100644 mach/vax4/libbsd4_2/getsockopt.s create mode 100644 mach/vax4/libbsd4_2/gettimday.s create mode 100644 mach/vax4/libbsd4_2/getuid.s create mode 100644 mach/vax4/libbsd4_2/gtty.c create mode 100644 mach/vax4/libbsd4_2/ioctl.s create mode 100644 mach/vax4/libbsd4_2/kill.s create mode 100644 mach/vax4/libbsd4_2/killpg.s create mode 100644 mach/vax4/libbsd4_2/link.s create mode 100644 mach/vax4/libbsd4_2/listen.s create mode 100644 mach/vax4/libbsd4_2/lseek.s create mode 100644 mach/vax4/libbsd4_2/lstat.s create mode 100644 mach/vax4/libbsd4_2/mkdir.s create mode 100644 mach/vax4/libbsd4_2/mknod.s create mode 100644 mach/vax4/libbsd4_2/mount.s create mode 100644 mach/vax4/libbsd4_2/nice.c create mode 100644 mach/vax4/libbsd4_2/open.s create mode 100644 mach/vax4/libbsd4_2/pause.c create mode 100644 mach/vax4/libbsd4_2/pipe.s create mode 100644 mach/vax4/libbsd4_2/profil.s create mode 100644 mach/vax4/libbsd4_2/ptrace.s create mode 100644 mach/vax4/libbsd4_2/quota.s create mode 100644 mach/vax4/libbsd4_2/read.s create mode 100644 mach/vax4/libbsd4_2/readlink.s create mode 100644 mach/vax4/libbsd4_2/readv.s create mode 100644 mach/vax4/libbsd4_2/reboot.s create mode 100644 mach/vax4/libbsd4_2/recv.s create mode 100644 mach/vax4/libbsd4_2/recvfrom.s create mode 100644 mach/vax4/libbsd4_2/recvmsg.s create mode 100644 mach/vax4/libbsd4_2/rename.s create mode 100644 mach/vax4/libbsd4_2/rmdir.s create mode 100644 mach/vax4/libbsd4_2/select.s create mode 100644 mach/vax4/libbsd4_2/send.s create mode 100644 mach/vax4/libbsd4_2/sendmsg.s create mode 100644 mach/vax4/libbsd4_2/sendto.s create mode 100644 mach/vax4/libbsd4_2/setgid.c create mode 100644 mach/vax4/libbsd4_2/setgroups.s create mode 100644 mach/vax4/libbsd4_2/sethostid.s create mode 100644 mach/vax4/libbsd4_2/sethostnam.s create mode 100644 mach/vax4/libbsd4_2/setitimer.s create mode 100644 mach/vax4/libbsd4_2/setpgrp.s create mode 100644 mach/vax4/libbsd4_2/setprio.s create mode 100644 mach/vax4/libbsd4_2/setquota.s create mode 100644 mach/vax4/libbsd4_2/setregid.s create mode 100644 mach/vax4/libbsd4_2/setreuid.s create mode 100644 mach/vax4/libbsd4_2/setrlimit.s create mode 100644 mach/vax4/libbsd4_2/setsockopt.s create mode 100644 mach/vax4/libbsd4_2/settimday.s create mode 100644 mach/vax4/libbsd4_2/setuid.c create mode 100644 mach/vax4/libbsd4_2/shutdown.s create mode 100644 mach/vax4/libbsd4_2/sigblock.s create mode 100644 mach/vax4/libbsd4_2/signal.c create mode 100644 mach/vax4/libbsd4_2/sigpause.s create mode 100644 mach/vax4/libbsd4_2/sigsetmask.s create mode 100644 mach/vax4/libbsd4_2/sigstack.s create mode 100644 mach/vax4/libbsd4_2/sigvec.s create mode 100644 mach/vax4/libbsd4_2/socket.s create mode 100644 mach/vax4/libbsd4_2/socketpair.s create mode 100644 mach/vax4/libbsd4_2/stat.s create mode 100644 mach/vax4/libbsd4_2/stime.c create mode 100644 mach/vax4/libbsd4_2/stty.c create mode 100644 mach/vax4/libbsd4_2/swapon.s create mode 100644 mach/vax4/libbsd4_2/symlink.s create mode 100644 mach/vax4/libbsd4_2/sync.s create mode 100644 mach/vax4/libbsd4_2/syscall.h create mode 100644 mach/vax4/libbsd4_2/syscall.s create mode 100644 mach/vax4/libbsd4_2/tell.c create mode 100644 mach/vax4/libbsd4_2/time.c create mode 100644 mach/vax4/libbsd4_2/times.c create mode 100644 mach/vax4/libbsd4_2/truncate.s create mode 100644 mach/vax4/libbsd4_2/umask.s create mode 100644 mach/vax4/libbsd4_2/umount.s create mode 100644 mach/vax4/libbsd4_2/unlink.s create mode 100644 mach/vax4/libbsd4_2/utime.c create mode 100644 mach/vax4/libbsd4_2/utimes.s create mode 100644 mach/vax4/libbsd4_2/vadvise.s create mode 100644 mach/vax4/libbsd4_2/vfork.s create mode 100644 mach/vax4/libbsd4_2/vhangup.s create mode 100644 mach/vax4/libbsd4_2/wait.s create mode 100644 mach/vax4/libbsd4_2/wait3.s create mode 100644 mach/vax4/libbsd4_2/write.s create mode 100644 mach/vax4/libbsd4_2/writev.s diff --git a/mach/vax4/libbsd4_2/LIST b/mach/vax4/libbsd4_2/LIST new file mode 100644 index 00000000..8ea4f331 --- /dev/null +++ b/mach/vax4/libbsd4_2/LIST @@ -0,0 +1,131 @@ +libmon_s.a +accept.s +access.s +acct.s +alarm.c +bind.s +brk.s +cerror.s +chdir.s +chmod.s +chown.s +chroot.s +close.s +connect.s +creat.s +dup.s +dup2.s +execl.s +execle.s +exect.s +execv.s +execve.s +exit.c +_exit.s +cleanup.c +fchmod.s +fchown.s +fcntl.s +flock.s +fork.s +fstat.s +fsync.s +ftime.c +ftruncate.s +getdtabsz.s +getegid.s +geteuid.s +getgid.s +getgroups.s +gethostid.s +gethostnam.s +getitimer.s +getpagesiz.s +getpeernam.s +getpgrp.s +getpid.s +getppid.s +getrlimit.s +getsocknam.s +getsockopt.s +getuid.s +gtty.c +kill.s +killpg.s +link.s +listen.s +lstat.s +mkdir.s +mknod.s +mount.s +nice.c +getprio.s +open.s +pause.c +pipe.s +profil.s +ptrace.s +quota.s +read.s +readlink.s +readv.s +reboot.s +recv.s +recvfrom.s +recvmsg.s +rename.s +rmdir.s +select.s +send.s +sendmsg.s +sendto.s +setgid.c +setgroups.s +sethostid.s +sethostnam.s +setitimer.s +setpgrp.s +setprio.s +setquota.s +setregid.s +setrlimit.s +setsockopt.s +setuid.c +setreuid.s +shutdown.s +sigblock.s +signal.c +sigpause.s +sigsetmask.s +sigstack.s +sigvec.s +socket.s +socketpair.s +stat.s +stime.c +settimday.s +stty.c +ioctl.s +swapon.s +symlink.s +sync.s +syscall.s +tell.c +lseek.s +time.c +gettimday.s +times.c +getrusage.s +truncate.s +umask.s +umount.s +unlink.s +utime.c +utimes.s +vadvise.s +vfork.s +vhangup.s +wait.s +wait3.s +write.s +writev.s diff --git a/mach/vax4/libbsd4_2/_exit.s b/mach/vax4/libbsd4_2/_exit.s new file mode 100644 index 00000000..eb7e0ae7 --- /dev/null +++ b/mach/vax4/libbsd4_2/_exit.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(__exit) +SYSTEM(SYS_exit) diff --git a/mach/vax4/libbsd4_2/accept.s b/mach/vax4/libbsd4_2/accept.s new file mode 100644 index 00000000..babb7a4f --- /dev/null +++ b/mach/vax4/libbsd4_2/accept.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_accept) +SYSTEM(SYS_accept) diff --git a/mach/vax4/libbsd4_2/access.s b/mach/vax4/libbsd4_2/access.s new file mode 100644 index 00000000..43f2d75b --- /dev/null +++ b/mach/vax4/libbsd4_2/access.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_access) +SYSTEM(SYS_access) diff --git a/mach/vax4/libbsd4_2/acct.s b/mach/vax4/libbsd4_2/acct.s new file mode 100644 index 00000000..7552ca7d --- /dev/null +++ b/mach/vax4/libbsd4_2/acct.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_acct) +SYSTEM(SYS_acct) diff --git a/mach/vax4/libbsd4_2/alarm.c b/mach/vax4/libbsd4_2/alarm.c new file mode 100644 index 00000000..ddbf2442 --- /dev/null +++ b/mach/vax4/libbsd4_2/alarm.c @@ -0,0 +1,13 @@ +unsigned +alarm(n) + unsigned n; +{ + struct { long l1,l2,l3,l4; } t1,t2; + t1.l1 = 0; + t1.l2 = 0; + t1.l4 = 0; + t1.l3 = n; + if (setitimer(0,&t1,&t2) < 0) return -1; + if (t2.l4) t2.l3++; + return t2.l3; +} diff --git a/mach/vax4/libbsd4_2/bind.s b/mach/vax4/libbsd4_2/bind.s new file mode 100644 index 00000000..f0aa6741 --- /dev/null +++ b/mach/vax4/libbsd4_2/bind.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_bind) +SYSTEM(SYS_bind) diff --git a/mach/vax4/libbsd4_2/brk.s b/mach/vax4/libbsd4_2/brk.s new file mode 100644 index 00000000..22020bc3 --- /dev/null +++ b/mach/vax4/libbsd4_2/brk.s @@ -0,0 +1,29 @@ +#include "syscall.h" +.globl _end +DEFINE(_brk) + cmpl 4(ap),min + bgeq ok + movl min,4(ap) +ok: + chmk $17 + bcs err + movl 4(ap),cur + clrl r0 + ret +err: + jmp cerror + +DEFINE(_sbrk) + addl3 cur,4(ap),-(sp) + bcs err + pushl $1 + movl ap,r3 + movl sp,ap + chmk $17 + bcs err + movl cur,r0 + addl2 4(r3),cur + ret +.data +min: .long _end +cur: .long _end diff --git a/mach/vax4/libbsd4_2/cerror.s b/mach/vax4/libbsd4_2/cerror.s new file mode 100644 index 00000000..cbd332aa --- /dev/null +++ b/mach/vax4/libbsd4_2/cerror.s @@ -0,0 +1,5 @@ + .globl _errno +cerror: + movl r0,_errno + mnegl $1,r0 + ret diff --git a/mach/vax4/libbsd4_2/chdir.s b/mach/vax4/libbsd4_2/chdir.s new file mode 100644 index 00000000..6d424af5 --- /dev/null +++ b/mach/vax4/libbsd4_2/chdir.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_chdir) +SYSTEM(SYS_chdir) diff --git a/mach/vax4/libbsd4_2/chmod.s b/mach/vax4/libbsd4_2/chmod.s new file mode 100644 index 00000000..a03aec02 --- /dev/null +++ b/mach/vax4/libbsd4_2/chmod.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_chmod) +SYSTEM(SYS_chmod) diff --git a/mach/vax4/libbsd4_2/chown.s b/mach/vax4/libbsd4_2/chown.s new file mode 100644 index 00000000..f1d1c474 --- /dev/null +++ b/mach/vax4/libbsd4_2/chown.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_chwon) +SYSTEM(SYS_chwon) diff --git a/mach/vax4/libbsd4_2/chroot.s b/mach/vax4/libbsd4_2/chroot.s new file mode 100644 index 00000000..7d910a90 --- /dev/null +++ b/mach/vax4/libbsd4_2/chroot.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_chroot) +SYSTEM(SYS_chroot) diff --git a/mach/vax4/libbsd4_2/cleanup.c b/mach/vax4/libbsd4_2/cleanup.c new file mode 100644 index 00000000..6cd9c63e --- /dev/null +++ b/mach/vax4/libbsd4_2/cleanup.c @@ -0,0 +1 @@ +_cleanup() { } diff --git a/mach/vax4/libbsd4_2/close.s b/mach/vax4/libbsd4_2/close.s new file mode 100644 index 00000000..0226d29b --- /dev/null +++ b/mach/vax4/libbsd4_2/close.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_close) +SYSTEM(SYS_close) diff --git a/mach/vax4/libbsd4_2/connect.s b/mach/vax4/libbsd4_2/connect.s new file mode 100644 index 00000000..2ec2c5aa --- /dev/null +++ b/mach/vax4/libbsd4_2/connect.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_connect) +SYSTEM(SYS_connect) diff --git a/mach/vax4/libbsd4_2/creat.s b/mach/vax4/libbsd4_2/creat.s new file mode 100644 index 00000000..f34f949b --- /dev/null +++ b/mach/vax4/libbsd4_2/creat.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_creat) +SYSTEM(SYS_creat) diff --git a/mach/vax4/libbsd4_2/dup.s b/mach/vax4/libbsd4_2/dup.s new file mode 100644 index 00000000..727018d4 --- /dev/null +++ b/mach/vax4/libbsd4_2/dup.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_dup) +SYSTEM(SYS_dup) diff --git a/mach/vax4/libbsd4_2/dup2.s b/mach/vax4/libbsd4_2/dup2.s new file mode 100644 index 00000000..95f3c723 --- /dev/null +++ b/mach/vax4/libbsd4_2/dup2.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_dup2) +SYSTEM(SYS_dup2) diff --git a/mach/vax4/libbsd4_2/execl.s b/mach/vax4/libbsd4_2/execl.s new file mode 100644 index 00000000..5bc463c7 --- /dev/null +++ b/mach/vax4/libbsd4_2/execl.s @@ -0,0 +1,8 @@ +#include "syscall.h" +.globl _environ +DEFINE(_execl) + pushl _environ + pushab 8(ap) + pushl 4(ap) + calls $3,_execve + ret diff --git a/mach/vax4/libbsd4_2/execle.s b/mach/vax4/libbsd4_2/execle.s new file mode 100644 index 00000000..5a8c9070 --- /dev/null +++ b/mach/vax4/libbsd4_2/execle.s @@ -0,0 +1,8 @@ +#include "syscall.h" +DEFINE(_execle) + movl (ap),r0 + pushl (ap)[r0] + pushab 8(ap) + pushl 4(ap) + calls $3,_execve + ret diff --git a/mach/vax4/libbsd4_2/exect.s b/mach/vax4/libbsd4_2/exect.s new file mode 100644 index 00000000..dbcea6cb --- /dev/null +++ b/mach/vax4/libbsd4_2/exect.s @@ -0,0 +1,5 @@ +#include "syscall.h" +DEFINE(_exect) + bispsw $16 + chmk $SYS_execve + jmp cerror diff --git a/mach/vax4/libbsd4_2/execv.s b/mach/vax4/libbsd4_2/execv.s new file mode 100644 index 00000000..d40da804 --- /dev/null +++ b/mach/vax4/libbsd4_2/execv.s @@ -0,0 +1,8 @@ +#include "syscall.h" +.globl _environ +DEFINE(_execv) + pushl _environ + pushl 8(ap) + pushl 4(ap) + calls $3,_execve + ret diff --git a/mach/vax4/libbsd4_2/execve.s b/mach/vax4/libbsd4_2/execve.s new file mode 100644 index 00000000..c962d57f --- /dev/null +++ b/mach/vax4/libbsd4_2/execve.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_execve) +SYSTEM(SYS_execve) diff --git a/mach/vax4/libbsd4_2/exit.c b/mach/vax4/libbsd4_2/exit.c new file mode 100644 index 00000000..afd54b3f --- /dev/null +++ b/mach/vax4/libbsd4_2/exit.c @@ -0,0 +1,5 @@ +exit(n) +{ + _cleanup(); + _exit(n); +} diff --git a/mach/vax4/libbsd4_2/fchmod.s b/mach/vax4/libbsd4_2/fchmod.s new file mode 100644 index 00000000..313c87f7 --- /dev/null +++ b/mach/vax4/libbsd4_2/fchmod.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_fchmod) +SYSTEM(SYS_fchmod) diff --git a/mach/vax4/libbsd4_2/fchown.s b/mach/vax4/libbsd4_2/fchown.s new file mode 100644 index 00000000..c0276550 --- /dev/null +++ b/mach/vax4/libbsd4_2/fchown.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_fchown) +SYSTEM(SYS_fchown) diff --git a/mach/vax4/libbsd4_2/fcntl.s b/mach/vax4/libbsd4_2/fcntl.s new file mode 100644 index 00000000..7e6e35cb --- /dev/null +++ b/mach/vax4/libbsd4_2/fcntl.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_fcntl) +SYSTEM(SYS_fcntl) diff --git a/mach/vax4/libbsd4_2/flock.s b/mach/vax4/libbsd4_2/flock.s new file mode 100644 index 00000000..e4567ee3 --- /dev/null +++ b/mach/vax4/libbsd4_2/flock.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_flock) +SYSTEM(SYS_flock) diff --git a/mach/vax4/libbsd4_2/fork.s b/mach/vax4/libbsd4_2/fork.s new file mode 100644 index 00000000..548ccc05 --- /dev/null +++ b/mach/vax4/libbsd4_2/fork.s @@ -0,0 +1,10 @@ +#include "syscall.h" +DEFINE(_fork) + chmk $SYS_fork + bcs err + jlbc r1,parent + clrl r0 +parent: + ret +err: + jmp cerror diff --git a/mach/vax4/libbsd4_2/fstat.s b/mach/vax4/libbsd4_2/fstat.s new file mode 100644 index 00000000..54b5d296 --- /dev/null +++ b/mach/vax4/libbsd4_2/fstat.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_fstat) +SYSTEM(SYS_fstat) diff --git a/mach/vax4/libbsd4_2/fsync.s b/mach/vax4/libbsd4_2/fsync.s new file mode 100644 index 00000000..54d15b3b --- /dev/null +++ b/mach/vax4/libbsd4_2/fsync.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_fsync) +SYSTEM(SYS_fsync) diff --git a/mach/vax4/libbsd4_2/ftime.c b/mach/vax4/libbsd4_2/ftime.c new file mode 100644 index 00000000..af4047c3 --- /dev/null +++ b/mach/vax4/libbsd4_2/ftime.c @@ -0,0 +1,15 @@ +#include + +ftime(p) + struct { time_t time; unsigned short millitm; + short timezone; short dstflag; } *p; +{ + struct { long l1,l2; } t1,t2; + + if (gettimeofday(&t1,&t2) < 0) return -1; + p->time = t1.l1; + p->millitm = t1.l2/1000; + p->dstflag = t2.l2; + p->timezone = t2.l1; + return 0; +} diff --git a/mach/vax4/libbsd4_2/ftruncate.s b/mach/vax4/libbsd4_2/ftruncate.s new file mode 100644 index 00000000..eadfb125 --- /dev/null +++ b/mach/vax4/libbsd4_2/ftruncate.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_ftruncate) +SYSTEM(SYS_ftruncate) diff --git a/mach/vax4/libbsd4_2/getdtabsz.s b/mach/vax4/libbsd4_2/getdtabsz.s new file mode 100644 index 00000000..02c7ae8a --- /dev/null +++ b/mach/vax4/libbsd4_2/getdtabsz.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_getdtablesize) +SYSTEM(SYS_getdtablesize) diff --git a/mach/vax4/libbsd4_2/getegid.s b/mach/vax4/libbsd4_2/getegid.s new file mode 100644 index 00000000..e34d623e --- /dev/null +++ b/mach/vax4/libbsd4_2/getegid.s @@ -0,0 +1,5 @@ +#include "syscall.h" +DEFINE(_getegid) +SYSNORET(SYS_getgid) + movl r1,r0 + ret diff --git a/mach/vax4/libbsd4_2/geteuid.s b/mach/vax4/libbsd4_2/geteuid.s new file mode 100644 index 00000000..39b7775b --- /dev/null +++ b/mach/vax4/libbsd4_2/geteuid.s @@ -0,0 +1,5 @@ +#include "syscall.h" +DEFINE(_geteuid) +SYSNORET(SYS_getuid) + movl r1,r0 + ret diff --git a/mach/vax4/libbsd4_2/getgid.s b/mach/vax4/libbsd4_2/getgid.s new file mode 100644 index 00000000..ba6c3342 --- /dev/null +++ b/mach/vax4/libbsd4_2/getgid.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_getgid) +SYSTEM(SYS_getgid) diff --git a/mach/vax4/libbsd4_2/getgroups.s b/mach/vax4/libbsd4_2/getgroups.s new file mode 100644 index 00000000..a7ab0efc --- /dev/null +++ b/mach/vax4/libbsd4_2/getgroups.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_getgroups) +SYSTEM(SYS_getgroups) diff --git a/mach/vax4/libbsd4_2/gethostid.s b/mach/vax4/libbsd4_2/gethostid.s new file mode 100644 index 00000000..7d3aaf0b --- /dev/null +++ b/mach/vax4/libbsd4_2/gethostid.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_gethostid) +SYSTEM(SYS_gethostid) diff --git a/mach/vax4/libbsd4_2/gethostnam.s b/mach/vax4/libbsd4_2/gethostnam.s new file mode 100644 index 00000000..2b6c9510 --- /dev/null +++ b/mach/vax4/libbsd4_2/gethostnam.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_gethostname) +SYSTEM(SYS_gethostname) diff --git a/mach/vax4/libbsd4_2/getitimer.s b/mach/vax4/libbsd4_2/getitimer.s new file mode 100644 index 00000000..81d850c2 --- /dev/null +++ b/mach/vax4/libbsd4_2/getitimer.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_getitimer) +SYSTEM(SYS_getitimer) diff --git a/mach/vax4/libbsd4_2/getpagesiz.s b/mach/vax4/libbsd4_2/getpagesiz.s new file mode 100644 index 00000000..e8a48922 --- /dev/null +++ b/mach/vax4/libbsd4_2/getpagesiz.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_getpagesize) +SYSTEM(SYS_getpagesize) diff --git a/mach/vax4/libbsd4_2/getpeernam.s b/mach/vax4/libbsd4_2/getpeernam.s new file mode 100644 index 00000000..d0e53e55 --- /dev/null +++ b/mach/vax4/libbsd4_2/getpeernam.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_getpeername) +SYSTEM(SYS_getpeername) diff --git a/mach/vax4/libbsd4_2/getpgrp.s b/mach/vax4/libbsd4_2/getpgrp.s new file mode 100644 index 00000000..c19d1b1f --- /dev/null +++ b/mach/vax4/libbsd4_2/getpgrp.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_getpgrp) +SYSTEM(SYS_getpgrp) diff --git a/mach/vax4/libbsd4_2/getpid.s b/mach/vax4/libbsd4_2/getpid.s new file mode 100644 index 00000000..6d07fe6c --- /dev/null +++ b/mach/vax4/libbsd4_2/getpid.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_getpid) +SYSTEM(SYS_getpid) diff --git a/mach/vax4/libbsd4_2/getppid.s b/mach/vax4/libbsd4_2/getppid.s new file mode 100644 index 00000000..2742de1a --- /dev/null +++ b/mach/vax4/libbsd4_2/getppid.s @@ -0,0 +1,5 @@ +#include "syscall.h" +DEFINE(_getppid) +SYSNORET(SYS_getpid) + movl r1,r0 + ret diff --git a/mach/vax4/libbsd4_2/getprio.s b/mach/vax4/libbsd4_2/getprio.s new file mode 100644 index 00000000..34d7ad23 --- /dev/null +++ b/mach/vax4/libbsd4_2/getprio.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_getpriority) +SYSTEM(SYS_getpriority) diff --git a/mach/vax4/libbsd4_2/getrlimit.s b/mach/vax4/libbsd4_2/getrlimit.s new file mode 100644 index 00000000..8b2b0988 --- /dev/null +++ b/mach/vax4/libbsd4_2/getrlimit.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_getrlimit) +SYSTEM(SYS_getrlimit) diff --git a/mach/vax4/libbsd4_2/getrusage.s b/mach/vax4/libbsd4_2/getrusage.s new file mode 100644 index 00000000..a30bcde0 --- /dev/null +++ b/mach/vax4/libbsd4_2/getrusage.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_getrusage) +SYSTEM(SYS_getrusage) diff --git a/mach/vax4/libbsd4_2/getsocknam.s b/mach/vax4/libbsd4_2/getsocknam.s new file mode 100644 index 00000000..889439bb --- /dev/null +++ b/mach/vax4/libbsd4_2/getsocknam.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_getsockname) +SYSTEM(SYS_getsockname) diff --git a/mach/vax4/libbsd4_2/getsockopt.s b/mach/vax4/libbsd4_2/getsockopt.s new file mode 100644 index 00000000..34143d5c --- /dev/null +++ b/mach/vax4/libbsd4_2/getsockopt.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_getsockopt) +SYSTEM(SYS_getsockopt) diff --git a/mach/vax4/libbsd4_2/gettimday.s b/mach/vax4/libbsd4_2/gettimday.s new file mode 100644 index 00000000..7a528475 --- /dev/null +++ b/mach/vax4/libbsd4_2/gettimday.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_gettimeofday) +SYSTEM(SYS_gettimeofday) diff --git a/mach/vax4/libbsd4_2/getuid.s b/mach/vax4/libbsd4_2/getuid.s new file mode 100644 index 00000000..c32ef035 --- /dev/null +++ b/mach/vax4/libbsd4_2/getuid.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_getuid) +SYSTEM(SYS_getuid) diff --git a/mach/vax4/libbsd4_2/gtty.c b/mach/vax4/libbsd4_2/gtty.c new file mode 100644 index 00000000..7f42ea1f --- /dev/null +++ b/mach/vax4/libbsd4_2/gtty.c @@ -0,0 +1,7 @@ +#include +int gtty(fildes,argp) + int fildes ; + struct sgttyb *argp ; +{ + return ioctl(fildes,TIOCGETP,argp) ; +} diff --git a/mach/vax4/libbsd4_2/ioctl.s b/mach/vax4/libbsd4_2/ioctl.s new file mode 100644 index 00000000..bcb79106 --- /dev/null +++ b/mach/vax4/libbsd4_2/ioctl.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_ioctl) +SYSTEM(SYS_ioctl) diff --git a/mach/vax4/libbsd4_2/kill.s b/mach/vax4/libbsd4_2/kill.s new file mode 100644 index 00000000..abecfbcd --- /dev/null +++ b/mach/vax4/libbsd4_2/kill.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_kill) +SYSTEM(SYS_kill) diff --git a/mach/vax4/libbsd4_2/killpg.s b/mach/vax4/libbsd4_2/killpg.s new file mode 100644 index 00000000..e6f362c3 --- /dev/null +++ b/mach/vax4/libbsd4_2/killpg.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_killpg) +SYSTEM(SYS_killpg) diff --git a/mach/vax4/libbsd4_2/link.s b/mach/vax4/libbsd4_2/link.s new file mode 100644 index 00000000..26ecc041 --- /dev/null +++ b/mach/vax4/libbsd4_2/link.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_link) +SYSTEM(SYS_link) diff --git a/mach/vax4/libbsd4_2/listen.s b/mach/vax4/libbsd4_2/listen.s new file mode 100644 index 00000000..d932140f --- /dev/null +++ b/mach/vax4/libbsd4_2/listen.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_listen) +SYSTEM(SYS_listen) diff --git a/mach/vax4/libbsd4_2/lseek.s b/mach/vax4/libbsd4_2/lseek.s new file mode 100644 index 00000000..608e1163 --- /dev/null +++ b/mach/vax4/libbsd4_2/lseek.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_lseek) +SYSTEM(SYS_lseek) diff --git a/mach/vax4/libbsd4_2/lstat.s b/mach/vax4/libbsd4_2/lstat.s new file mode 100644 index 00000000..7bf45eea --- /dev/null +++ b/mach/vax4/libbsd4_2/lstat.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_lstat) +SYSTEM(SYS_lstat) diff --git a/mach/vax4/libbsd4_2/mkdir.s b/mach/vax4/libbsd4_2/mkdir.s new file mode 100644 index 00000000..a297b48b --- /dev/null +++ b/mach/vax4/libbsd4_2/mkdir.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_mkdir) +SYSTEM(SYS_mkdir) diff --git a/mach/vax4/libbsd4_2/mknod.s b/mach/vax4/libbsd4_2/mknod.s new file mode 100644 index 00000000..9dbaf7e1 --- /dev/null +++ b/mach/vax4/libbsd4_2/mknod.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_mknod) +SYSTEM(SYS_mknod) diff --git a/mach/vax4/libbsd4_2/mount.s b/mach/vax4/libbsd4_2/mount.s new file mode 100644 index 00000000..619259c0 --- /dev/null +++ b/mach/vax4/libbsd4_2/mount.s @@ -0,0 +1,5 @@ +#include "syscall.h" +DEFINE(_mount) +SYSNORET(SYS_mount) + clrl r0 + ret diff --git a/mach/vax4/libbsd4_2/nice.c b/mach/vax4/libbsd4_2/nice.c new file mode 100644 index 00000000..23505669 --- /dev/null +++ b/mach/vax4/libbsd4_2/nice.c @@ -0,0 +1,13 @@ +nice(incr) +{ + extern int errno; + int sav = errno; + int prio; + + errno = 0; + prio = getpriority(0,0); + if (prio == -1 && errno) return -1; + if (setpriority(0,0,prio+incr) < 0) return -1; + errno = sav; + return 0; +} diff --git a/mach/vax4/libbsd4_2/open.s b/mach/vax4/libbsd4_2/open.s new file mode 100644 index 00000000..edcdb2f3 --- /dev/null +++ b/mach/vax4/libbsd4_2/open.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_open) +SYSTEM(SYS_open) diff --git a/mach/vax4/libbsd4_2/pause.c b/mach/vax4/libbsd4_2/pause.c new file mode 100644 index 00000000..97c0242e --- /dev/null +++ b/mach/vax4/libbsd4_2/pause.c @@ -0,0 +1,3 @@ +pause() { + sigpause(sigblock()); +} diff --git a/mach/vax4/libbsd4_2/pipe.s b/mach/vax4/libbsd4_2/pipe.s new file mode 100644 index 00000000..27fa9f91 --- /dev/null +++ b/mach/vax4/libbsd4_2/pipe.s @@ -0,0 +1,8 @@ +#include "syscall.h" +DEFINE(_pipe) +SYSNORET(SYS_pipe) + movl 4(ap),r2 + movl r0,(r2)+ + movl r1,(r2) + clrl r0 + ret diff --git a/mach/vax4/libbsd4_2/profil.s b/mach/vax4/libbsd4_2/profil.s new file mode 100644 index 00000000..2e4671e6 --- /dev/null +++ b/mach/vax4/libbsd4_2/profil.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_profil) +SYSTEM(SYS_profil) diff --git a/mach/vax4/libbsd4_2/ptrace.s b/mach/vax4/libbsd4_2/ptrace.s new file mode 100644 index 00000000..511b695e --- /dev/null +++ b/mach/vax4/libbsd4_2/ptrace.s @@ -0,0 +1,4 @@ +#include "syscall.h" +DEFINE(_ptrace) + clrl _errno +SYSTEM(SYS_ptrace) diff --git a/mach/vax4/libbsd4_2/quota.s b/mach/vax4/libbsd4_2/quota.s new file mode 100644 index 00000000..160b1c4e --- /dev/null +++ b/mach/vax4/libbsd4_2/quota.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_quota) +SYSTEM(SYS_quota) diff --git a/mach/vax4/libbsd4_2/read.s b/mach/vax4/libbsd4_2/read.s new file mode 100644 index 00000000..abff733d --- /dev/null +++ b/mach/vax4/libbsd4_2/read.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_read) +SYSTEM(SYS_read) diff --git a/mach/vax4/libbsd4_2/readlink.s b/mach/vax4/libbsd4_2/readlink.s new file mode 100644 index 00000000..5573bbf7 --- /dev/null +++ b/mach/vax4/libbsd4_2/readlink.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_readlink) +SYSTEM(SYS_readlink) diff --git a/mach/vax4/libbsd4_2/readv.s b/mach/vax4/libbsd4_2/readv.s new file mode 100644 index 00000000..969b14f6 --- /dev/null +++ b/mach/vax4/libbsd4_2/readv.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_readv) +SYSTEM(SYS_readv) diff --git a/mach/vax4/libbsd4_2/reboot.s b/mach/vax4/libbsd4_2/reboot.s new file mode 100644 index 00000000..70b690ee --- /dev/null +++ b/mach/vax4/libbsd4_2/reboot.s @@ -0,0 +1,4 @@ +#include "syscall.h" +DEFINE(_reboot) +SYSNORET(SYS_reboot) + halt diff --git a/mach/vax4/libbsd4_2/recv.s b/mach/vax4/libbsd4_2/recv.s new file mode 100644 index 00000000..f1dc07d9 --- /dev/null +++ b/mach/vax4/libbsd4_2/recv.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_recv) +SYSTEM(SYS_recv) diff --git a/mach/vax4/libbsd4_2/recvfrom.s b/mach/vax4/libbsd4_2/recvfrom.s new file mode 100644 index 00000000..7f2e155f --- /dev/null +++ b/mach/vax4/libbsd4_2/recvfrom.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_recvfrom) +SYSTEM(SYS_recvfrom) diff --git a/mach/vax4/libbsd4_2/recvmsg.s b/mach/vax4/libbsd4_2/recvmsg.s new file mode 100644 index 00000000..88afc984 --- /dev/null +++ b/mach/vax4/libbsd4_2/recvmsg.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_recvmsg) +SYSTEM(SYS_recvmsg) diff --git a/mach/vax4/libbsd4_2/rename.s b/mach/vax4/libbsd4_2/rename.s new file mode 100644 index 00000000..a892b06b --- /dev/null +++ b/mach/vax4/libbsd4_2/rename.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_rename) +SYSTEM(SYS_rename) diff --git a/mach/vax4/libbsd4_2/rmdir.s b/mach/vax4/libbsd4_2/rmdir.s new file mode 100644 index 00000000..35b1296a --- /dev/null +++ b/mach/vax4/libbsd4_2/rmdir.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_rmdir) +SYSTEM(SYS_rmdir) diff --git a/mach/vax4/libbsd4_2/select.s b/mach/vax4/libbsd4_2/select.s new file mode 100644 index 00000000..d2da4073 --- /dev/null +++ b/mach/vax4/libbsd4_2/select.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_select) +SYSTEM(SYS_select) diff --git a/mach/vax4/libbsd4_2/send.s b/mach/vax4/libbsd4_2/send.s new file mode 100644 index 00000000..9c10ce5d --- /dev/null +++ b/mach/vax4/libbsd4_2/send.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_send) +SYSTEM(SYS_send) diff --git a/mach/vax4/libbsd4_2/sendmsg.s b/mach/vax4/libbsd4_2/sendmsg.s new file mode 100644 index 00000000..b78abca6 --- /dev/null +++ b/mach/vax4/libbsd4_2/sendmsg.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_sendmsg) +SYSTEM(SYS_sendmsg) diff --git a/mach/vax4/libbsd4_2/sendto.s b/mach/vax4/libbsd4_2/sendto.s new file mode 100644 index 00000000..6d3e7100 --- /dev/null +++ b/mach/vax4/libbsd4_2/sendto.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_sendto) +SYSTEM(SYS_sendto) diff --git a/mach/vax4/libbsd4_2/setgid.c b/mach/vax4/libbsd4_2/setgid.c new file mode 100644 index 00000000..c51a4d02 --- /dev/null +++ b/mach/vax4/libbsd4_2/setgid.c @@ -0,0 +1,4 @@ +setgid(u) +{ + return setregid(u,u); +} diff --git a/mach/vax4/libbsd4_2/setgroups.s b/mach/vax4/libbsd4_2/setgroups.s new file mode 100644 index 00000000..c3571c34 --- /dev/null +++ b/mach/vax4/libbsd4_2/setgroups.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_setgroups) +SYSTEM(SYS_setgroups) diff --git a/mach/vax4/libbsd4_2/sethostid.s b/mach/vax4/libbsd4_2/sethostid.s new file mode 100644 index 00000000..ffab90d3 --- /dev/null +++ b/mach/vax4/libbsd4_2/sethostid.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_sethostid) +SYSTEM(SYS_sethostid) diff --git a/mach/vax4/libbsd4_2/sethostnam.s b/mach/vax4/libbsd4_2/sethostnam.s new file mode 100644 index 00000000..7a947e7a --- /dev/null +++ b/mach/vax4/libbsd4_2/sethostnam.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_sethostname) +SYSTEM(SYS_sethostname) diff --git a/mach/vax4/libbsd4_2/setitimer.s b/mach/vax4/libbsd4_2/setitimer.s new file mode 100644 index 00000000..8b1f18e4 --- /dev/null +++ b/mach/vax4/libbsd4_2/setitimer.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_setitimer) +SYSTEM(SYS_setitimer) diff --git a/mach/vax4/libbsd4_2/setpgrp.s b/mach/vax4/libbsd4_2/setpgrp.s new file mode 100644 index 00000000..8dda5263 --- /dev/null +++ b/mach/vax4/libbsd4_2/setpgrp.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_setpgrp) +SYSTEM(SYS_setpgrp) diff --git a/mach/vax4/libbsd4_2/setprio.s b/mach/vax4/libbsd4_2/setprio.s new file mode 100644 index 00000000..6fd1af9c --- /dev/null +++ b/mach/vax4/libbsd4_2/setprio.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_setpriority) +SYSTEM(SYS_setpriority) diff --git a/mach/vax4/libbsd4_2/setquota.s b/mach/vax4/libbsd4_2/setquota.s new file mode 100644 index 00000000..0a313154 --- /dev/null +++ b/mach/vax4/libbsd4_2/setquota.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_setquota) +SYSTEM(SYS_setquota) diff --git a/mach/vax4/libbsd4_2/setregid.s b/mach/vax4/libbsd4_2/setregid.s new file mode 100644 index 00000000..39d8d965 --- /dev/null +++ b/mach/vax4/libbsd4_2/setregid.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_setregid) +SYSTEM(SYS_setregid) diff --git a/mach/vax4/libbsd4_2/setreuid.s b/mach/vax4/libbsd4_2/setreuid.s new file mode 100644 index 00000000..fa63cbd6 --- /dev/null +++ b/mach/vax4/libbsd4_2/setreuid.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_setreuid) +SYSTEM(SYS_setreuid) diff --git a/mach/vax4/libbsd4_2/setrlimit.s b/mach/vax4/libbsd4_2/setrlimit.s new file mode 100644 index 00000000..6713d983 --- /dev/null +++ b/mach/vax4/libbsd4_2/setrlimit.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_setrlimit) +SYSTEM(SYS_setrlimit) diff --git a/mach/vax4/libbsd4_2/setsockopt.s b/mach/vax4/libbsd4_2/setsockopt.s new file mode 100644 index 00000000..1bc1bcb3 --- /dev/null +++ b/mach/vax4/libbsd4_2/setsockopt.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_setsockopt) +SYSTEM(SYS_setsockopt) diff --git a/mach/vax4/libbsd4_2/settimday.s b/mach/vax4/libbsd4_2/settimday.s new file mode 100644 index 00000000..1aef4f42 --- /dev/null +++ b/mach/vax4/libbsd4_2/settimday.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_settimeofday) +SYSTEM(SYS_settimeofday) diff --git a/mach/vax4/libbsd4_2/setuid.c b/mach/vax4/libbsd4_2/setuid.c new file mode 100644 index 00000000..04a87340 --- /dev/null +++ b/mach/vax4/libbsd4_2/setuid.c @@ -0,0 +1,4 @@ +setuid(u) +{ + return setreuid(u,u); +} diff --git a/mach/vax4/libbsd4_2/shutdown.s b/mach/vax4/libbsd4_2/shutdown.s new file mode 100644 index 00000000..b0dc1349 --- /dev/null +++ b/mach/vax4/libbsd4_2/shutdown.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_shutdown) +SYSTEM(SYS_shutdown) diff --git a/mach/vax4/libbsd4_2/sigblock.s b/mach/vax4/libbsd4_2/sigblock.s new file mode 100644 index 00000000..608f017d --- /dev/null +++ b/mach/vax4/libbsd4_2/sigblock.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_sigblock) +SYSTEM(SYS_sigblock) diff --git a/mach/vax4/libbsd4_2/signal.c b/mach/vax4/libbsd4_2/signal.c new file mode 100644 index 00000000..5c829ae1 --- /dev/null +++ b/mach/vax4/libbsd4_2/signal.c @@ -0,0 +1,25 @@ +static long masks[32]; +static long flags[32]; +int (* +signal(sig,handler))() + int (*handler)(); +{ + struct { + int (*sv_handler)(); + long sv_mask; + long sv_flags; + } v, ov; + + v.sv_handler = handler; + v.sv_mask = masks[sig]; + v.sv_flags = flags[sig]; + if (sigvec(sig,&v, &ov) < 0) return (int (*)()) -1; + if (v.sv_mask != ov.sv_mask || v.sv_flags != ov.sv_flags) { + v.sv_mask = ov.sv_mask; + masks[sig] = ov.sv_mask; + v.sv_flags = ov.sv_flags; + flags[sig] = ov.sv_flags; + if (sigvec(sig,&v,(char *) 0) < 0) return (int (*)()) -1; + } + return ov.sv_handler; +} diff --git a/mach/vax4/libbsd4_2/sigpause.s b/mach/vax4/libbsd4_2/sigpause.s new file mode 100644 index 00000000..1d3fb951 --- /dev/null +++ b/mach/vax4/libbsd4_2/sigpause.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_sigpause) +SYSTEM(SYS_sigpause) diff --git a/mach/vax4/libbsd4_2/sigsetmask.s b/mach/vax4/libbsd4_2/sigsetmask.s new file mode 100644 index 00000000..a4034d44 --- /dev/null +++ b/mach/vax4/libbsd4_2/sigsetmask.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_sigsetmask) +SYSTEM(SYS_sigsetmask) diff --git a/mach/vax4/libbsd4_2/sigstack.s b/mach/vax4/libbsd4_2/sigstack.s new file mode 100644 index 00000000..bd143e0f --- /dev/null +++ b/mach/vax4/libbsd4_2/sigstack.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_sigstack) +SYSTEM(SYS_sigstack) diff --git a/mach/vax4/libbsd4_2/sigvec.s b/mach/vax4/libbsd4_2/sigvec.s new file mode 100644 index 00000000..c19c2175 --- /dev/null +++ b/mach/vax4/libbsd4_2/sigvec.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_sigvec) +SYSTEM(SYS_sigvec) diff --git a/mach/vax4/libbsd4_2/socket.s b/mach/vax4/libbsd4_2/socket.s new file mode 100644 index 00000000..dd032e4c --- /dev/null +++ b/mach/vax4/libbsd4_2/socket.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_socket) +SYSTEM(SYS_socket) diff --git a/mach/vax4/libbsd4_2/socketpair.s b/mach/vax4/libbsd4_2/socketpair.s new file mode 100644 index 00000000..513c51c2 --- /dev/null +++ b/mach/vax4/libbsd4_2/socketpair.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_socketpair) +SYSTEM(SYS_socketpair) diff --git a/mach/vax4/libbsd4_2/stat.s b/mach/vax4/libbsd4_2/stat.s new file mode 100644 index 00000000..abdf8530 --- /dev/null +++ b/mach/vax4/libbsd4_2/stat.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_stat) +SYSTEM(SYS_stat) diff --git a/mach/vax4/libbsd4_2/stime.c b/mach/vax4/libbsd4_2/stime.c new file mode 100644 index 00000000..b13ee43b --- /dev/null +++ b/mach/vax4/libbsd4_2/stime.c @@ -0,0 +1,9 @@ +stime(tp) + long *tp; +{ + struct { long l1,l2; } x; + + x.l1 = *tp; + x.l2 = 0; + return settimeofday(&x, (char *) 0); +} diff --git a/mach/vax4/libbsd4_2/stty.c b/mach/vax4/libbsd4_2/stty.c new file mode 100644 index 00000000..222310cc --- /dev/null +++ b/mach/vax4/libbsd4_2/stty.c @@ -0,0 +1,7 @@ +#include +int stty(fildes,argp) + int fildes ; + struct sgttyb *argp ; +{ + return ioctl(fildes,TIOCSETP,argp) ; +} diff --git a/mach/vax4/libbsd4_2/swapon.s b/mach/vax4/libbsd4_2/swapon.s new file mode 100644 index 00000000..62d94a49 --- /dev/null +++ b/mach/vax4/libbsd4_2/swapon.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_swapon) +SYSTEM(SYS_swapon) diff --git a/mach/vax4/libbsd4_2/symlink.s b/mach/vax4/libbsd4_2/symlink.s new file mode 100644 index 00000000..ea02c675 --- /dev/null +++ b/mach/vax4/libbsd4_2/symlink.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_symlink) +SYSTEM(SYS_symlink) diff --git a/mach/vax4/libbsd4_2/sync.s b/mach/vax4/libbsd4_2/sync.s new file mode 100644 index 00000000..03eeae67 --- /dev/null +++ b/mach/vax4/libbsd4_2/sync.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_sync) +SYSTEM(SYS_sync) diff --git a/mach/vax4/libbsd4_2/syscall.h b/mach/vax4/libbsd4_2/syscall.h new file mode 100644 index 00000000..b870d11b --- /dev/null +++ b/mach/vax4/libbsd4_2/syscall.h @@ -0,0 +1,118 @@ +#define DEFINE(sysn) .globl sysn; .align 1; sysn: .word 0 +#define SYSTEM(sys) chmk $sys; bcs err; ret; err: jmp cerror +#define SYSNORET(sys) chmk $sys; bcc ok; jmp cerror; ok: +#define SYS_exit 1 +#define SYS_fork 2 +#define SYS_read 3 +#define SYS_write 4 +#define SYS_open 5 +#define SYS_close 6 +#define SYS_creat 8 +#define SYS_link 9 +#define SYS_unlink 10 +#define SYS_execv 11 +#define SYS_chdir 12 +#define SYS_mknod 14 +#define SYS_chmod 15 +#define SYS_chown 16 +#define SYS_lseek 19 +#define SYS_getpid 20 +#define SYS_mount 21 +#define SYS_umount 22 +#define SYS_getuid 24 +#define SYS_ptrace 26 +#define SYS_access 33 +#define SYS_sync 36 +#define SYS_kill 37 +#define SYS_stat 38 +#define SYS_lstat 40 +#define SYS_dup 41 +#define SYS_pipe 42 +#define SYS_profil 44 +#define SYS_getgid 47 +#define SYS_acct 51 +#define SYS_ioctl 54 +#define SYS_reboot 55 +#define SYS_symlink 57 +#define SYS_readlink 58 +#define SYS_execve 59 +#define SYS_umask 60 +#define SYS_chroot 61 +#define SYS_fstat 62 +#define SYS_getpagesize 64 +#define SYS_mremap 65 +#define SYS_vfork 65 +#define SYS_sbrk 69 +#define SYS_sstk 70 +#define SYS_mmap 71 +#define SYS_vadvise 72 +#define SYS_munmap 73 +#define SYS_mprotect 74 +#define SYS_madvise 75 +#define SYS_vhangup 76 +#define SYS_mincore 78 +#define SYS_getgroups 79 +#define SYS_setgroups 80 +#define SYS_getpgrp 81 +#define SYS_setpgrp 82 +#define SYS_setitimer 83 +#define SYS_wait 84 +#define SYS_swapon 85 +#define SYS_getitimer 86 +#define SYS_gethostname 87 +#define SYS_sethostname 88 +#define SYS_getdtablesize 89 +#define SYS_dup2 90 +#define SYS_getdopt 91 +#define SYS_fcntl 92 +#define SYS_select 93 +#define SYS_setdopt 94 +#define SYS_fsync 95 +#define SYS_setpriority 96 +#define SYS_socket 97 +#define SYS_connect 98 +#define SYS_accept 99 +#define SYS_getpriority 100 +#define SYS_send 101 +#define SYS_recv 102 +#define SYS_bind 104 +#define SYS_setsockopt 105 +#define SYS_listen 106 +#define SYS_sigvec 108 +#define SYS_sigblock 109 +#define SYS_sigsetmask 110 +#define SYS_sigpause 111 +#define SYS_sigstack 112 +#define SYS_recvmsg 113 +#define SYS_sendmsg 114 +#define SYS_gettimeofday 116 +#define SYS_getrusage 117 +#define SYS_getsockopt 118 +#define SYS_readv 120 +#define SYS_writev 121 +#define SYS_settimeofday 122 +#define SYS_fchown 123 +#define SYS_fchmod 124 +#define SYS_recvfrom 125 +#define SYS_setreuid 126 +#define SYS_setregid 127 +#define SYS_rename 128 +#define SYS_truncate 129 +#define SYS_ftruncate 130 +#define SYS_flock 131 +#define SYS_sendto 133 +#define SYS_shutdown 134 +#define SYS_socketpair 135 +#define SYS_mkdir 136 +#define SYS_rmdir 137 +#define SYS_utimes 138 +#define SYS_revoke 140 +#define SYS_getpeername 141 +#define SYS_gethostid 142 +#define SYS_sethostid 143 +#define SYS_getrlimit 144 +#define SYS_setrlimit 145 +#define SYS_killpg 146 +#define SYS_setquota 148 +#define SYS_quota 149 +#define SYS_getsockname 150 diff --git a/mach/vax4/libbsd4_2/syscall.s b/mach/vax4/libbsd4_2/syscall.s new file mode 100644 index 00000000..14be0650 --- /dev/null +++ b/mach/vax4/libbsd4_2/syscall.s @@ -0,0 +1,9 @@ +#include "syscall.h" +DEFINE(_syscall) + movl 4(ap),r0 + subl3 $1,(ap)+,(ap) + chmk r0 + bcs err + ret +err: + jmp cerror diff --git a/mach/vax4/libbsd4_2/tell.c b/mach/vax4/libbsd4_2/tell.c new file mode 100644 index 00000000..49e2a917 --- /dev/null +++ b/mach/vax4/libbsd4_2/tell.c @@ -0,0 +1,7 @@ +long +tell(f) +{ + long lseek(); + + return lseek(f, 0L, 1); +} diff --git a/mach/vax4/libbsd4_2/time.c b/mach/vax4/libbsd4_2/time.c new file mode 100644 index 00000000..3dd1eeae --- /dev/null +++ b/mach/vax4/libbsd4_2/time.c @@ -0,0 +1,12 @@ +long +time(loc) + long *loc; +{ + struct { long l1,l2; } t1; + + if (gettimeofday(&t1, (char *) 0) < 0) { + return -1; + } + if (loc) *loc = t1.l1; + return t1.l1; +} diff --git a/mach/vax4/libbsd4_2/times.c b/mach/vax4/libbsd4_2/times.c new file mode 100644 index 00000000..4e23d92b --- /dev/null +++ b/mach/vax4/libbsd4_2/times.c @@ -0,0 +1,16 @@ +#include + +#define Xval(xx) ((xx).l1*60+(xx).l2/(100000/6)) + +times(bp) + struct { time_t l1,l2,l3,l4;} *bp; +{ + struct { struct { long l1,l2; }s1,s2; long x[20]; } t; + if (getrusage(0,&t) < 0) return -1; + bp->l1 = Xval(t.s1); + bp->l2 = Xval(t.s2); + if (getrusage(-1,&t) < 0) return -1; + bp->l3 = Xval(t.s1); + bp->l4 = Xval(t.s2); + return 0; +} diff --git a/mach/vax4/libbsd4_2/truncate.s b/mach/vax4/libbsd4_2/truncate.s new file mode 100644 index 00000000..45c5e2e7 --- /dev/null +++ b/mach/vax4/libbsd4_2/truncate.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_truncate) +SYSTEM(SYS_truncate) diff --git a/mach/vax4/libbsd4_2/umask.s b/mach/vax4/libbsd4_2/umask.s new file mode 100644 index 00000000..11229baa --- /dev/null +++ b/mach/vax4/libbsd4_2/umask.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_umask) +SYSTEM(SYS_umask) diff --git a/mach/vax4/libbsd4_2/umount.s b/mach/vax4/libbsd4_2/umount.s new file mode 100644 index 00000000..88d9ca5b --- /dev/null +++ b/mach/vax4/libbsd4_2/umount.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_umount) +SYSTEM(SYS_umount) diff --git a/mach/vax4/libbsd4_2/unlink.s b/mach/vax4/libbsd4_2/unlink.s new file mode 100644 index 00000000..830a0ab7 --- /dev/null +++ b/mach/vax4/libbsd4_2/unlink.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_unlink) +SYSTEM(SYS_unlink) diff --git a/mach/vax4/libbsd4_2/utime.c b/mach/vax4/libbsd4_2/utime.c new file mode 100644 index 00000000..8c265e1d --- /dev/null +++ b/mach/vax4/libbsd4_2/utime.c @@ -0,0 +1,13 @@ +#include + +utime(file, timep) + char *file; + time_t timep[2]; +{ + struct { long l1,l2,l3,l4; } x; + + x.l2 = x.l4 = 0; + x.l1 = timep[0]; + x.l3 = timep[1]; + return utimes(file,&x); +} diff --git a/mach/vax4/libbsd4_2/utimes.s b/mach/vax4/libbsd4_2/utimes.s new file mode 100644 index 00000000..7d4ab021 --- /dev/null +++ b/mach/vax4/libbsd4_2/utimes.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_utimes) +SYSTEM(SYS_utimes) diff --git a/mach/vax4/libbsd4_2/vadvise.s b/mach/vax4/libbsd4_2/vadvise.s new file mode 100644 index 00000000..b71fb183 --- /dev/null +++ b/mach/vax4/libbsd4_2/vadvise.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_vadvise) +SYSTEM(SYS_vadvise) diff --git a/mach/vax4/libbsd4_2/vfork.s b/mach/vax4/libbsd4_2/vfork.s new file mode 100644 index 00000000..3f5a7210 --- /dev/null +++ b/mach/vax4/libbsd4_2/vfork.s @@ -0,0 +1,17 @@ +#include "syscall.h" +DEFINE(_vfork) + movl 16(fp),r2 + movab newret,16(fp) + ret # cleans stack +newret: + chmk $SYS_vfork + bcs err + tstl r1 + beql parent + clrl r0 +parent: + jmp (r2) +err: + movl r0,_errno + mnegl $1,r0 + jmp (r2) diff --git a/mach/vax4/libbsd4_2/vhangup.s b/mach/vax4/libbsd4_2/vhangup.s new file mode 100644 index 00000000..f6da68d7 --- /dev/null +++ b/mach/vax4/libbsd4_2/vhangup.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_vhangup) +SYSTEM(SYS_vhangup) diff --git a/mach/vax4/libbsd4_2/wait.s b/mach/vax4/libbsd4_2/wait.s new file mode 100644 index 00000000..0807bdf6 --- /dev/null +++ b/mach/vax4/libbsd4_2/wait.s @@ -0,0 +1,8 @@ +#include "syscall.h" +DEFINE(_wait) +SYSNORET(SYS_wait) + tstl 4(ap) + beql out + movl r1,*4(ap) +out: + ret diff --git a/mach/vax4/libbsd4_2/wait3.s b/mach/vax4/libbsd4_2/wait3.s new file mode 100644 index 00000000..9ac2829d --- /dev/null +++ b/mach/vax4/libbsd4_2/wait3.s @@ -0,0 +1,14 @@ +#include "syscall.h" +DEFINE(_wait3) + movl 8(ap),r0 + movl 12(ap),r1 + bispsw $0xf + chmk $SYS_wait + bcs err + tstl 4(ap) + beql out + movl r1,*4(ap) +out: + ret +err: + jmp cerror diff --git a/mach/vax4/libbsd4_2/write.s b/mach/vax4/libbsd4_2/write.s new file mode 100644 index 00000000..9d373749 --- /dev/null +++ b/mach/vax4/libbsd4_2/write.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_write) +SYSTEM(SYS_write) diff --git a/mach/vax4/libbsd4_2/writev.s b/mach/vax4/libbsd4_2/writev.s new file mode 100644 index 00000000..49e531b3 --- /dev/null +++ b/mach/vax4/libbsd4_2/writev.s @@ -0,0 +1,3 @@ +#include "syscall.h" +DEFINE(_writev) +SYSTEM(SYS_writev) From 60b338229d2c94e5710657acc5742a8d76f9792f Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 23 Feb 1987 19:04:27 +0000 Subject: [PATCH 0849/1625] Initial revision --- mach/vax4/libbsd4_2/compmodule | 4 ++++ 1 file changed, 4 insertions(+) create mode 100755 mach/vax4/libbsd4_2/compmodule diff --git a/mach/vax4/libbsd4_2/compmodule b/mach/vax4/libbsd4_2/compmodule new file mode 100755 index 00000000..3b054dea --- /dev/null +++ b/mach/vax4/libbsd4_2/compmodule @@ -0,0 +1,4 @@ +if vax4 -O -c -L -I../../../h -I. $1 1>&2 +then echo `basename $1 $2`.o +else exit 1 +fi From 45a81b468a43e2f38f68159a9c368538cd92172e Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 23 Feb 1987 19:08:18 +0000 Subject: [PATCH 0850/1625] *** empty log message *** --- mach/vax4/libbsd4_2/head_em.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/vax4/libbsd4_2/head_em.s b/mach/vax4/libbsd4_2/head_em.s index 1afad8bc..f162fba2 100644 --- a/mach/vax4/libbsd4_2/head_em.s +++ b/mach/vax4/libbsd4_2/head_em.s @@ -1,5 +1,5 @@ #include "em_abs.h" -#include "/usr/include/syscall.h" +#include "syscall.h" # $Header$ From 91433ce4366ab70e2f4c8050223a18d72bdc62f4 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 23 Feb 1987 19:14:34 +0000 Subject: [PATCH 0851/1625] Initial revision --- util/ego/descr/m68020.descr | 103 ++++++++++++++++++++++++++++++++++++ util/ego/descr/m68k4.descr | 103 ++++++++++++++++++++++++++++++++++++ 2 files changed, 206 insertions(+) create mode 100644 util/ego/descr/m68020.descr create mode 100644 util/ego/descr/m68k4.descr diff --git a/util/ego/descr/m68020.descr b/util/ego/descr/m68020.descr new file mode 100644 index 00000000..a692a3df --- /dev/null +++ b/util/ego/descr/m68020.descr @@ -0,0 +1,103 @@ +wordsize: 4 +pointersize: 4 +%%RA +general registers: 5 +address registers: 4 +floating point registers: 0 + +register score parameters: + local variable: + (2 cases) + pointer,pointer + (1 size) + default -> (6,3) + general,general + (1 size) + default -> (4,2) + address of local variable: + (2 cases) + pointer,pointer + (1 size) + default -> (0,0) + general,pointer + (1 size) + default -> (2,2) + constant: + (2 sizes) + in_0_8 -> (0,0) + default -> (2,2) + double constant: + (1 size) + default -> (-1,-1) + address of global variable: + (1 size) + default -> (4,4) + address of procedure: + (1 size) + default -> (2,4) + +opening cost parameters: + local variable: + (2 cases) + pointer + (1 size) + default -> (6,4) + general + (1 size) + default -> (8,4) + address of local variable: + (2 cases) + pointer + (1 size) + default -> (4,2) + general + (1 size) + general -> (4,2) + constant: + (1 size) + default -> (4,4) + double constant: + (1 size) + default -> (1000,1000) + address of global variable: + (1 size) + default -> (6,6) + address of procedure: + (1 size) + default -> (6,6) + +register save costs: + (11 cases) + 0 -> (0,0) + 1 -> (12,4) + 2 -> (24,8) + 3 -> (34,8) + 4 -> (42,8) + 5 -> (50,8) + 6 -> (58,8) + 7 -> (66,8) + 8 -> (84,8) + 9 -> (92,8) + 0 -> (0,0) +%%UD +access costs of global variables: + (1 size) + default -> (7,4) +access costs of local variables: + (1 size) + default -> (4,2) +%%SR +overflow harmful?: no +array bound harmful?: no +%%CS +#include "../../../h/em_mnem.h" +first time then space: +addressing modes: op_adp op_lof op_ldf op_loi op_dch op_lpb -1 + op_adp op_lof op_ldf op_loi op_dch op_lpb -1 +cheap operations: -1 -1 +lexical tresholds: 1 1 +indirection limit: 8 +do sli if index?: yes yes +forbidden operators: -1 -1 +%%SP +global stack pollution allowed?: no diff --git a/util/ego/descr/m68k4.descr b/util/ego/descr/m68k4.descr new file mode 100644 index 00000000..a692a3df --- /dev/null +++ b/util/ego/descr/m68k4.descr @@ -0,0 +1,103 @@ +wordsize: 4 +pointersize: 4 +%%RA +general registers: 5 +address registers: 4 +floating point registers: 0 + +register score parameters: + local variable: + (2 cases) + pointer,pointer + (1 size) + default -> (6,3) + general,general + (1 size) + default -> (4,2) + address of local variable: + (2 cases) + pointer,pointer + (1 size) + default -> (0,0) + general,pointer + (1 size) + default -> (2,2) + constant: + (2 sizes) + in_0_8 -> (0,0) + default -> (2,2) + double constant: + (1 size) + default -> (-1,-1) + address of global variable: + (1 size) + default -> (4,4) + address of procedure: + (1 size) + default -> (2,4) + +opening cost parameters: + local variable: + (2 cases) + pointer + (1 size) + default -> (6,4) + general + (1 size) + default -> (8,4) + address of local variable: + (2 cases) + pointer + (1 size) + default -> (4,2) + general + (1 size) + general -> (4,2) + constant: + (1 size) + default -> (4,4) + double constant: + (1 size) + default -> (1000,1000) + address of global variable: + (1 size) + default -> (6,6) + address of procedure: + (1 size) + default -> (6,6) + +register save costs: + (11 cases) + 0 -> (0,0) + 1 -> (12,4) + 2 -> (24,8) + 3 -> (34,8) + 4 -> (42,8) + 5 -> (50,8) + 6 -> (58,8) + 7 -> (66,8) + 8 -> (84,8) + 9 -> (92,8) + 0 -> (0,0) +%%UD +access costs of global variables: + (1 size) + default -> (7,4) +access costs of local variables: + (1 size) + default -> (4,2) +%%SR +overflow harmful?: no +array bound harmful?: no +%%CS +#include "../../../h/em_mnem.h" +first time then space: +addressing modes: op_adp op_lof op_ldf op_loi op_dch op_lpb -1 + op_adp op_lof op_ldf op_loi op_dch op_lpb -1 +cheap operations: -1 -1 +lexical tresholds: 1 1 +indirection limit: 8 +do sli if index?: yes yes +forbidden operators: -1 -1 +%%SP +global stack pollution allowed?: no From cb8731da1979e67168b93772c3543fd85d2436bd Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 23 Feb 1987 19:15:33 +0000 Subject: [PATCH 0852/1625] updated to current situation --- util/ego/descr/vax4.descr | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/util/ego/descr/vax4.descr b/util/ego/descr/vax4.descr index 524c5f87..bee2b677 100644 --- a/util/ego/descr/vax4.descr +++ b/util/ego/descr/vax4.descr @@ -78,14 +78,16 @@ opening cost parameters: default -> (6,7) register save costs: - (8 cases) + (10 cases) 0 -> (0,0) - 1 -> (3,1) - 2 -> (7,3) - 3 -> (20,4) - 4 -> (20,4) - 5 -> (20,4) - 6 -> (20,4) + 1 -> (1,0) + 2 -> (2,0) + 3 -> (3,0) + 4 -> (4,0) + 5 -> (5,0) + 6 -> (6,0) + 7 -> (7,0) + 8 -> (8,0) 0 -> (0,0) %%UD access costs of global variables: @@ -104,11 +106,13 @@ array bound harmful?: no first time then space: addressing modes: op_adp op_lof op_ldf op_loi op_dch op_lpb -1 op_adp op_lof op_ldf op_loi op_dch op_lpb -1 -cheap operations: op_cii op_cui op_cfi op_ciu op_cff op_cuu op_cif -1 - op_cii op_cui op_cfi op_ciu op_cff op_cuu op_cif -1 -lexical tresholds: 1 1 +cheap operations: op_cii op_cui op_cfi op_ciu op_cff op_cuu op_cif + op_cmi op_cmu op_cmf op_cms op_cmp -1 + op_cii op_cui op_cfi op_ciu op_cff op_cuu op_cif + op_cmi op_cmu op_cmf op_cms op_cmp -1 +lexical thresholds: 1 1 indirection limit: 8 do sli if index?: no no forbidden operators: -1 -1 %%SP -global stack pollution allowed?: no +global stack pollution allowed?: yes From 8dcf088bf3ad8376827985f017d39c9462f79480 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 23 Feb 1987 19:18:57 +0000 Subject: [PATCH 0853/1625] *** empty log message *** --- util/ego/descr/Makefile | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/util/ego/descr/Makefile b/util/ego/descr/Makefile index 1bba9efd..c82336dc 100644 --- a/util/ego/descr/Makefile +++ b/util/ego/descr/Makefile @@ -1,17 +1,17 @@ - EMHOME=../../.. EMH=$(EMHOME)/h EMLIB=$(EMHOME)/lib SHARE=../share +CPP=$(EMLIB)/cpp LDFLAGS=-i CPPFLAGS=-DVERBOSE -DNOTCOMPACT CFLAGS=$(CPPFLAGS) -O LINTFLAGS=-phbac -SOURCES = i86.descr m68k2.descr pdp.descr vax2.descr vax4.descr +SOURCES = i86.descr m68k2.descr pdp.descr vax4.descr m68k4.descr m68020.descr -TARGETS = i86descr m68k2descr vax2descr vax4descr pdpdescr +TARGETS = i86descr m68k2descr vax4descr pdpdescr m68k4descr m68020descr PRFILES = Makefile descr.sed $(SOURCES) @@ -20,14 +20,12 @@ all: $(TARGETS) install: all ../install i86descr ../install m68k2descr - ../install vax2descr ../install vax4descr ../install pdpdescr cmp: all -../compare i86descr -../compare m68k2descr - -../compare vax2descr -../compare vax4descr -../compare pdpdescr @@ -49,8 +47,11 @@ pdpdescr: pdp.descr descr.sed m68k2descr: m68k2.descr descr.sed $(CPP) -P -I$(EMH) m68k2.descr | sed -f descr.sed > m68k2descr -vax2descr: vax2.descr descr.sed - $(CPP) -P -I$(EMH) vax2.descr | sed -f descr.sed > vax2descr +m68k4descr: m68k4.descr descr.sed + $(CPP) -P -I$(EMH) m68k4.descr | sed -f descr.sed > m68k4descr + +m68020descr: m68020.descr descr.sed + $(CPP) -P -I$(EMH) m68020.descr | sed -f descr.sed > m68020descr vax4descr: vax4.descr descr.sed $(CPP) -P -I$(EMH) vax4.descr | sed -f descr.sed > vax4descr From 9b44d7d82895812d2275ac9381c01a21e6472732 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 23 Feb 1987 19:38:14 +0000 Subject: [PATCH 0854/1625] Initial revision --- mach/sun3/libcc/Makefile | 38 ++++++++++++++++++++++++++++++++++++++ mach/sun3/libcc/compmodule | 6 ++++++ 2 files changed, 44 insertions(+) create mode 100644 mach/sun3/libcc/Makefile create mode 100755 mach/sun3/libcc/compmodule diff --git a/mach/sun3/libcc/Makefile b/mach/sun3/libcc/Makefile new file mode 100644 index 00000000..c4ab9d4c --- /dev/null +++ b/mach/sun3/libcc/Makefile @@ -0,0 +1,38 @@ +SUF=o +MAKEFILE=../../proto/libg/Makefile +MACHDEF="MACH=sun3" "SUF=$(SUF)" "ASAR=aal" +STDIO="PREF=cc" "SUB=.1s" "SRC=lang/cem/libcc/stdio" +GEN="PREF=cc" "SUB=.2g" "SRC=lang/cem/libcc/gen" +MON="PREF=mon" "SRC=lang/cem/libcc/mon" + +install: cpstdio cpgen + +cpstdio: + make -f $(MAKEFILE) $(STDIO) $(MACHDEF) tailcp +cpgen: + make -f $(MAKEFILE) $(GEN) $(MACHDEF) cp +cpmon: + make -f $(MAKEFILE) $(MON) $(MACHDEF) tailcp + +cmp: cmpstdio cmpgen + +cmpstdio: + make -f $(MAKEFILE) $(STDIO) $(MACHDEF) tail + -../../compare tail_cc.1s +cmpgen: + make -f $(MAKEFILE) $(GEN) $(MACHDEF) head + -../../compare head_cc + make -f $(MAKEFILE) $(GEN) $(MACHDEF) tail + -../../compare tail_cc.2g +cmpmon: + make -f $(MAKEFILE) $(MON) $(MACHDEF) tail + -../../compare tail_mon + +clean: + -rm -f *.old *.[ce$(SUF)] tail* head* + +opr: + make pr | opr + +pr: + @pr Makefile diff --git a/mach/sun3/libcc/compmodule b/mach/sun3/libcc/compmodule new file mode 100755 index 00000000..1b2935c7 --- /dev/null +++ b/mach/sun3/libcc/compmodule @@ -0,0 +1,6 @@ +if ${MACH?} -I../../../h -DBSD4_2 ${MACHFL?} $1 1>&2 +then + echo `basename $1 $2`.o +else + exit 1 +fi From 41c6ffff756344e0068e496324353a5cd05c6ef6 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 23 Feb 1987 19:39:57 +0000 Subject: [PATCH 0855/1625] *** empty log message *** --- lib/sun3/descr | 24 +++++++++++++----------- mach/sun3/Action | 3 +++ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/sun3/descr b/lib/sun3/descr index 4612d758..a13561eb 100644 --- a/lib/sun3/descr +++ b/lib/sun3/descr @@ -5,11 +5,13 @@ var s=2 var l=4 var f=4 var d=8 -var NAME=m68020 -var P=m68020 -var M=sun +var NAME=sun +var M=m68020 +var P=sun3 var LIB=lib/{P}/tail_ var RT=lib/{P}/head_ +var PLIB=lib/{M}/tail_ +var PRT=lib/{M}/head_ var CPP_F=-Dunix=unix var INCLUDES=-I{EM}/include/_tail_cc # 413 align is the default, rom in text @@ -17,7 +19,7 @@ var ALIGN=-a0:2 -a1:2 -a2:0x20000 -a3:2 -b0:0x2020 name be from .m.g to .s - program {EM}/lib/{P}/cg + program {EM}/lib/{M}/cg args < stdout need .e @@ -25,7 +27,7 @@ end name as from .s.so to .o - program {EM}/lib/{P}/as + program {EM}/lib/{M}/as args - -o > < prep cond end @@ -38,18 +40,18 @@ name led mapflag -nr ALIGN=-a0:2 -a1:0x20000 -a2:2 -a3:2 -b0:0x2000 mapflag -N ALIGN=-a0:2 -a1:2 -a2:2 -a3:2 -b0:0x2000 mapflag -r ALIGN=-a0:2 -a1:0x20000 -a2:2 -a3:2 -b0:0x2020 - args (.e:{HEAD}= {ALIGN} {EM}/lib/{M}/head_em) \ -({RTS}:.b.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \ - (.p:{TAIL}={EM}/{LIB}pc) \ - (.b:{TAIL}={EM}/{LIB}bc) \ + args (.e:{HEAD}= {ALIGN} {EM}/{RT}em) \ +({RTS}:.b.c={EM}/{RT}cc) ({RTS}:.p={EM}/{PRT}pc) -o > < \ + (.p:{TAIL}={EM}/{PLIB}pc) \ + (.b:{TAIL}={EM}/{PLIB}bc) \ (.b.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \ - (.e:{TAIL}={EM}/{LIB}em {EM}/lib/{M}/tail_mon {EM}/lib/{P}/end_em) + (.e:{TAIL}={EM}/{PLIB}em {EM}/{LIB}mon {EM}/lib/{M}/end_em) linker end name cv from .out to .cv - program {EM}/lib/{M}/cv + program {EM}/lib/{P}/cv args < > outfile a.out end diff --git a/mach/sun3/Action b/mach/sun3/Action index ecfe36b9..3f492caf 100644 --- a/mach/sun3/Action +++ b/mach/sun3/Action @@ -4,3 +4,6 @@ end name "SUN 68020 systemcall library" dir libsys end +name "SUN 68020 C libraries" +dir libcc +end From 8490d753d85399d66071d9e3fd6aedb391bfd07a Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 23 Feb 1987 19:47:00 +0000 Subject: [PATCH 0856/1625] Initial revision --- mach/mantra/libcc/Makefile | 38 ++++++++++++++++++++++++++++++++++++ mach/mantra/libcc/compmodule | 6 ++++++ 2 files changed, 44 insertions(+) create mode 100644 mach/mantra/libcc/Makefile create mode 100755 mach/mantra/libcc/compmodule diff --git a/mach/mantra/libcc/Makefile b/mach/mantra/libcc/Makefile new file mode 100644 index 00000000..4d500d2e --- /dev/null +++ b/mach/mantra/libcc/Makefile @@ -0,0 +1,38 @@ +SUF=o +MAKEFILE=../../proto/libg/Makefile +MACHDEF="MACH=mantra4" "SUF=$(SUF)" "ASAR=aal" +STDIO="PREF=cc" "SUB=.1s" "SRC=lang/cem/libcc/stdio" +GEN="PREF=cc" "SUB=.2g" "SRC=lang/cem/libcc/gen" +MON="PREF=mon" "SRC=lang/cem/libcc/mon" + +install: cpstdio cpgen + +cpstdio: + make -f $(MAKEFILE) $(STDIO) $(MACHDEF) tailcp +cpgen: + make -f $(MAKEFILE) $(GEN) $(MACHDEF) cp +cpmon: + make -f $(MAKEFILE) $(MON) $(MACHDEF) tailcp + +cmp: cmpstdio cmpgen + +cmpstdio: + make -f $(MAKEFILE) $(STDIO) $(MACHDEF) tail + -../../compare tail_cc.1s +cmpgen: + make -f $(MAKEFILE) $(GEN) $(MACHDEF) head + -../../compare head_cc + make -f $(MAKEFILE) $(GEN) $(MACHDEF) tail + -../../compare tail_cc.2g +cmpmon: + make -f $(MAKEFILE) $(MON) $(MACHDEF) tail + -../../compare tail_mon + +clean: + -rm -f *.old *.[ce$(SUF)] tail* head* + +opr: + make pr | opr + +pr: + @pr Makefile diff --git a/mach/mantra/libcc/compmodule b/mach/mantra/libcc/compmodule new file mode 100755 index 00000000..09b343ad --- /dev/null +++ b/mach/mantra/libcc/compmodule @@ -0,0 +1,6 @@ +if ${MACH?} -DUSG -I../../../h ${MACHFL?} $1 1>&2 +then + echo `basename $1 $2`.o +else + exit 1 +fi From a431218b404c59411185e6ab27b5452796bd6804 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 23 Feb 1987 19:48:17 +0000 Subject: [PATCH 0857/1625] *** empty log message *** --- mach/mantra/Action | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mach/mantra/Action b/mach/mantra/Action index 41451b93..b5657559 100644 --- a/mach/mantra/Action +++ b/mach/mantra/Action @@ -1,3 +1,6 @@ name "Mantra M68000 4-4 system call library" dir libsys end +name "Mantra 68000 4-4 C libraries" +dir libcc +end From 7c72adf5ec8f63b53f7e06ef61f2493fc47aa635 Mon Sep 17 00:00:00 2001 From: em Date: Mon, 23 Feb 1987 22:35:21 +0000 Subject: [PATCH 0858/1625] cleanup --> clean --- lang/cem/ctest/ctprof/makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/cem/ctest/ctprof/makefile b/lang/cem/ctest/ctprof/makefile index e910410c..dc9283e1 100644 --- a/lang/cem/ctest/ctprof/makefile +++ b/lang/cem/ctest/ctprof/makefile @@ -29,7 +29,7 @@ pr: opr: make pr | opr -cleanup: +clean: -rm -f *.[kosme] *.old transI transM cmpI cmpM: From 77348673ef6e6a5aeb13a88fb898a78ec976820b Mon Sep 17 00:00:00 2001 From: em Date: Mon, 23 Feb 1987 22:38:45 +0000 Subject: [PATCH 0859/1625] do not generate .c files when cleaninmg up --- lang/cem/ctest/ctgen/run1 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lang/cem/ctest/ctgen/run1 b/lang/cem/ctest/ctgen/run1 index 55277e7f..cc5cbae6 100755 --- a/lang/cem/ctest/ctgen/run1 +++ b/lang/cem/ctest/ctgen/run1 @@ -1,3 +1,9 @@ +case $2 in +clean) + ;; +*) make "TS=$1" +;; +esac make "P=$1" -fk ../makefile $2 rm -f $1.[ckmos] From 2ad56b351c1df1cd0d82369adad6ad2147dd71d7 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 23 Feb 1987 22:49:20 +0000 Subject: [PATCH 0860/1625] *** empty log message *** --- lib/mantra/descr | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/mantra/descr b/lib/mantra/descr index 51069d4f..a8819979 100644 --- a/lib/mantra/descr +++ b/lib/mantra/descr @@ -9,6 +9,8 @@ var NAME=m68k4 var M=m68k4 var LIB=lib/{M}/tail_ var RT=lib/{M}/head_ +var NLIB=lib/mantra4/tail_ +var NRT=lib/mantra4/head_ var CPP_F=-Dunix=unix -Dm68000=m68000 var INCLUDES=-I{EM}/include/_tail_cc # 407 align is the default @@ -45,12 +47,12 @@ name led mapflag -i ALIGN=-a0:2 -a1:2 -a2:0x8000 -a3:2 mapflag -n ALIGN=-a0:2 -a1:2 -a2:0x8000 -a3:2 mapflag -nr ALIGN=-a0:2 -a1:0x8000 -a2:2 -a3:2 - args (.e:{HEAD}=-b0:0x80000 {ALIGN} {EM}/{RT}em) \ -({RTS}:.b.c={EM}/{RT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \ + args (.e:{HEAD}=-b0:0x80000 {ALIGN} {EM}/{NRT}em) \ +({RTS}:.b.c={EM}/{NRT}cc) ({RTS}:.p={EM}/{RT}pc) -o > < \ (.p:{TAIL}={EM}/{LIB}pc) \ (.b:{TAIL}={EM}/{LIB}bc) \ - (.b.c:{TAIL}={EM}/{LIB}cc.1s {EM}/{LIB}cc.2g) \ - (.e:{TAIL}={EM}/{LIB}em {EM}/lib/mantra4/tail_mon {EM}/lib/{M}/end_em) + (.b.c:{TAIL}={EM}/{NLIB}cc.1s {EM}/{NLIB}cc.2g) \ + (.e:{TAIL}={EM}/{LIB}em {EM}/{NLIB}mon {EM}/lib/{M}/end_em) linker end name cv From e57daaabcb5c37391b033df889db0d387f8534b7 Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 23 Feb 1987 23:28:06 +0000 Subject: [PATCH 0861/1625] *** empty log message *** --- util/ack/ack.1.X | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/util/ack/ack.1.X b/util/ack/ack.1.X index a55c859e..d12c9616 100644 --- a/util/ack/ack.1.X +++ b/util/ack/ack.1.X @@ -142,10 +142,9 @@ These routines are supplied with one parameter, a pointer to a string containing the name of the routine. .SB optimizing .IP \-O -Use as many optimizers as possible. -\fIAck\fP can almost always use the EM peephole optimizer. -Sometimes the global optimizer or machine-dependent -optimizers can be used. +.IP \-Oopt1,opt2,... +Try to use the named optimizers, or, if no optimizers are given, +try using the peephole optimizer and a target optimizer. .IP \-L Disable the generation of code by the front ends to record line number and source file name at run-time. @@ -172,7 +171,7 @@ This flag tells the peephole optimizer .RF em_opt VI to add information about the visibility of the names used to each output module. -This is needed by most +This is needed by assembler/linkers when these modules are to be inserted in libraries. .SB interpreter @@ -227,13 +226,14 @@ are passed to the loaders, as for flags. .SH PREPROCESSOR All C source programs are run through the preprocessor before they are fed to the compiler proper. -Other human readable sources (Pascal programs and +On larger machines, the compiler has a built in preprocessor. +Other human readable sources (Pascal or Basic programs and machine assembly) are only preprocessed when they start with a \`#\'. .PP \fIAck\fP adds a few macro definitions when it calls the preprocessor. These macro\'s contain the word- and pointer-size and the sizes -of some basic types used by the Pascal and/or C compiler. +of some basic types used by the Pascal, Basic and/or C compiler. All sizes are in bytes. .sp 1 .TS @@ -248,7 +248,6 @@ The name of the \fImachine\fP or something like it when the machine name is numeric is also defined (as 1). .PP The default directories searched for include files differ for each machine. -Some machines do not even use \fI/usr/include\fP. .SH PROGRAMS \fIAck\fP uses one or more programs in each phase of the transformation. @@ -272,14 +271,15 @@ input:name:output:description \&.k .m:decode:.e:Produce human readable EM assembly \&.k .m:emass:e.out:Linker producing EM machine code [1] \&.m:be:.s:backend -\&.s:asld:a.out:Assembler/linker producing machine code +\&.s:asld:.out:Assembler/linker producing machine code in Ack a.out format \&.s:as:.o:Assembler \&.o:ld:a.out:Linker producing machine code +\&.o:led:.out:Linker producing machine code in Ack a.out format .TE .in -2 .SH "SEE ALSO" .PD 0 -em_opt(VI), em_ass(VI), em_cg(VI) +em_opt(6), em_ass(6), em_cg(6), ack.out(5) .IP [1] A.S. Tanenbaum, Hans van Staveren, Ed Keizer and Johan Stevenson \fIDescription of a machine architecture for use with From 306c0a82cdb0c08931f01399fc153286c93cddad Mon Sep 17 00:00:00 2001 From: ceriel Date: Mon, 23 Feb 1987 23:35:42 +0000 Subject: [PATCH 0862/1625] *** empty log message *** --- util/ack/Makefile | 11 ++++++++--- util/ncgg/param.h | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/util/ack/Makefile b/util/ack/Makefile index 8c6c48cb..586080b8 100644 --- a/util/ack/Makefile +++ b/util/ack/Makefile @@ -6,14 +6,16 @@ DSRC=list.c data.c main.c scan.c svars.c trans.c util.c rmach.c run.c grows.c\ ISRC=dmach.c intable.c OBJ=list.o data.o main.o scan.o svars.o trans.o util.o rmach.o run.o \ dmach.o intable.o grows.o files.o -ACKDIR=$(EMHOME)/lib/ +ACKDIR=$(EMHOME)/lib/descr FE=fe INTABLES=pdp int LNTABLES=acc apc abc vax4 i86 m68k2 m68k4 pmds pmds4 mantra mantra4 \ - m68020 z8000 int22 int24 int44 6500 6800 6805 6809 i80 ns s2650 z80 + m68020 z8000 int22 int24 int44 6500 6800 6805 6809 i80 ns s2650 z80 \ + sun3 INCLUDES=-I$(EMHOME)/h CFLAGS=-O -n $(INCLUDES) BINDIR=$(EMHOME)/bin +MANDIR=$(EMHOME)/man MODDIR=$(EMHOME)/modules/lib head: ack @@ -24,10 +26,13 @@ install: ack -cd $(BINDIR) ; \ for i in $(INTABLES) $(LNTABLES) ; do rm -f $$i ; ln ack $$i ; done (cd pc ; make install ) + rm -f $(MANDIR)/man/ack.1 + cp ack.1 $(MANDIR)/man/ack.1 cmp: ack - cmp ack $(BINDIR)/ack + -cmp ack $(BINDIR)/ack (cd pc ; make cmp ) + -cmp ack.1 $(MANDIR)/ack.1 clean: -rm -f *.old *.o ack diff --git a/util/ncgg/param.h b/util/ncgg/param.h index 21ed4f6f..e5841adc 100644 --- a/util/ncgg/param.h +++ b/util/ncgg/param.h @@ -15,7 +15,7 @@ #define EMPATMAX 20 #define MAXPATTERNS 40 #define MAXALLREG 5 -#define MAXINSTANCES 300 +#define MAXINSTANCES 500 #define MAXMOVES 40 #define MAXTESTS 10 #define MAXSTACKS 30 From 9d3d4fa61a2520e890706c7795a55f1a88949ec3 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 24 Feb 1987 10:00:37 +0000 Subject: [PATCH 0863/1625] 4/4, new C cmpiler --- lang/cem/ctest/ctconv/conv.cem.g | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lang/cem/ctest/ctconv/conv.cem.g b/lang/cem/ctest/ctconv/conv.cem.g index 9dc42b05..1469bfd1 100644 --- a/lang/cem/ctest/ctconv/conv.cem.g +++ b/lang/cem/ctest/ctconv/conv.cem.g @@ -1,25 +1,25 @@ -(int) '\377' = 255 +(int) '\377' = -1 (long) -1 = -1 (float) 12 = 12.000000 (int) 3.14 = 3 (int) 32767L = 32767 (int) -32768L = -32768 -(char) 128L = 128 -(char) 0377 = 255 -(char) -1 = 255 +(char) 128L = -128 +(char) 0377 = -1 +(char) -1 = -1 (char) 10000 = 16 From character char 127, int 127, unsigned 177, long 127 float 127.000000 - char 255, int 255, unsigned 377, long 255 - float 255.000000 - char 255, int 255, unsigned 377, long 255 - float 255.000000 + char -1, int -1, unsigned 37777777777, long -1 + float -1.000000 + char -1, int -1, unsigned 37777777777, long -1 + float -1.000000 From integer - char 192, int -64, unsigned 177700, long -64 + char -64, int -64, unsigned 37777777700, long -64 float -64.000000 From long - char 253, int -3, unsigned 177775, long -3 + char -3, int -3, unsigned 37777777775, long -3 float -3.000000 From float char 121, int 121, unsigned 171, long 121, float 121.500000 From 72f780676b4b7d8e48815db55d288b7777878972 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 24 Feb 1987 10:15:46 +0000 Subject: [PATCH 0864/1625] 4/4, new C compiler --- lang/cem/ctest/ctdivers/ops.cem.g | 206 ++++++++++++++--------------- lang/cem/ctest/ctgen/bf.cem.g | 118 ++++++++--------- lang/cem/ctest/ctgen/clu.cem.g | 52 ++++---- lang/cem/ctest/ctgen/ec.cem.g | 24 ++-- lang/cem/ctest/ctgen/ei.cem.g | 10 +- lang/cem/ctest/ctgen/eu.cem.g | 52 ++++---- lang/cem/ctest/ctgen/id.cem.g | 72 ++++++++++ lang/cem/ctest/ctgen/lc.cem.g | 24 ++-- lang/cem/ctest/ctgen/li.cem.g | 10 +- lang/cem/ctest/ctgen/lu.cem.g | 52 ++++---- lang/cem/ctest/ctinit/init.cem.g | 6 +- lang/cem/ctest/ctmargt/margt.cem.g | 8 +- lang/cem/ctest/ctsys/tfork.cem.g | 4 +- 13 files changed, 356 insertions(+), 282 deletions(-) create mode 100644 lang/cem/ctest/ctgen/id.cem.g diff --git a/lang/cem/ctest/ctdivers/ops.cem.g b/lang/cem/ctest/ctdivers/ops.cem.g index 1c4eb2cb..9c8a0e62 100644 --- a/lang/cem/ctest/ctdivers/ops.cem.g +++ b/lang/cem/ctest/ctdivers/ops.cem.g @@ -4,112 +4,112 @@ a 0, b -32, c 0, d -32 Unsigned shifts by constants u = 150715 u>>0 150715 - u>>1 064346 - u>>2 032163 - u>>3 015071 - u>>4 006434 - u>>5 003216 - u>>6 001507 - u>>7 000643 - u>>8 000321 - u>>9 000150 - u>>10 000064 - u>>11 000032 - u>>12 000015 - u>>13 000006 - u>>14 000003 - u>>15 000001 - u>>16 000000 + u>>1 64346 + u>>2 32163 + u>>3 15071 + u>>4 6434 + u>>5 3216 + u>>6 1507 + u>>7 643 + u>>8 321 + u>>9 150 + u>>10 64 + u>>11 32 + u>>12 15 + u>>13 6 + u>>14 3 + u>>15 1 + u>>16 0 u<<0 150715 - u<<1 121632 - u<<2 043464 - u<<3 107150 - u<<4 016320 - u<<5 034640 - u<<6 071500 - u<<7 163200 - u<<8 146400 - u<<9 115000 - u<<10 032000 - u<<11 064000 - u<<12 150000 - u<<13 120000 - u<<14 040000 - u<<15 100000 - u<<16 000000 + u<<1 321632 + u<<2 643464 + u<<3 1507150 + u<<4 3216320 + u<<5 6434640 + u<<6 15071500 + u<<7 32163200 + u<<8 64346400 + u<<9 150715000 + u<<10 321632000 + u<<11 643464000 + u<<12 1507150000 + u<<13 3216320000 + u<<14 6434640000 + u<<15 15071500000 + u<<16 32163200000 Long shifts by constants - ll = 00001414446 - ll>>0 00001414446 - ll>>1 00000606223 - ll>>2 00000303111 - ll>>3 00000141444 - ll>>4 00000060622 - ll>>5 00000030311 - ll>>6 00000014144 - ll>>7 00000006062 - ll>>8 00000003031 - ll>>9 00000001414 - ll>>10 00000000606 - ll>>11 00000000303 - ll>>12 00000000141 - ll>>13 00000000060 - ll>>14 00000000030 - ll>>15 00000000014 - ll>>16 00000000006 - ll>>17 00000000003 - ll>>18 00000000001 - ll>>19 00000000000 - ll>>20 00000000000 - ll>>21 00000000000 - ll>>22 00000000000 - ll>>23 00000000000 - ll>>24 00000000000 - ll>>25 00000000000 - ll>>26 00000000000 - ll>>27 00000000000 - ll>>28 00000000000 - ll>>29 00000000000 - ll>>30 00000000000 - ll>>31 00000000000 - ll<<0 00000000001 - ll<<1 00000000002 - ll<<2 00000000004 - ll<<3 00000000010 - ll<<4 00000000020 - ll<<5 00000000040 - ll<<6 00000000100 - ll<<7 00000000200 - ll<<8 00000000400 - ll<<9 00000001000 - ll<<10 00000002000 - ll<<11 00000004000 - ll<<12 00000010000 - ll<<13 00000020000 - ll<<14 00000040000 - ll<<15 00000100000 - ll<<16 00000200000 - ll<<17 00000400000 - ll<<18 00001000000 - ll<<19 00002000000 - ll<<20 00004000000 - ll<<21 00010000000 - ll<<22 00020000000 - ll<<23 00040000000 - ll<<24 00100000000 - ll<<25 00200000000 - ll<<26 00400000000 - ll<<27 01000000000 - ll<<28 02000000000 - ll<<29 04000000000 + ll = 1414446 + ll>>0 1414446 + ll>>1 606223 + ll>>2 303111 + ll>>3 141444 + ll>>4 60622 + ll>>5 30311 + ll>>6 14144 + ll>>7 6062 + ll>>8 3031 + ll>>9 1414 + ll>>10 606 + ll>>11 303 + ll>>12 141 + ll>>13 60 + ll>>14 30 + ll>>15 14 + ll>>16 6 + ll>>17 3 + ll>>18 1 + ll>>19 0 + ll>>20 0 + ll>>21 0 + ll>>22 0 + ll>>23 0 + ll>>24 0 + ll>>25 0 + ll>>26 0 + ll>>27 0 + ll>>28 0 + ll>>29 0 + ll>>30 0 + ll>>31 0 + ll<<0 1 + ll<<1 2 + ll<<2 4 + ll<<3 10 + ll<<4 20 + ll<<5 40 + ll<<6 100 + ll<<7 200 + ll<<8 400 + ll<<9 1000 + ll<<10 2000 + ll<<11 4000 + ll<<12 10000 + ll<<13 20000 + ll<<14 40000 + ll<<15 100000 + ll<<16 200000 + ll<<17 400000 + ll<<18 1000000 + ll<<19 2000000 + ll<<20 4000000 + ll<<21 10000000 + ll<<22 20000000 + ll<<23 40000000 + ll<<24 100000000 + ll<<25 200000000 + ll<<26 400000000 + ll<<27 1000000000 + ll<<28 2000000000 + ll<<29 4000000000 ll<<30 10000000000 - 0 077770 - 1 077771 - 2 077772 - 3 077773 - 4 077774 - 5 077775 - 6 077776 - 7 077777 + 0 77770 + 1 77771 + 2 77772 + 3 77773 + 4 77774 + 5 77775 + 6 77776 + 7 77777 8 100000 9 100001 10 100002 diff --git a/lang/cem/ctest/ctgen/bf.cem.g b/lang/cem/ctest/ctgen/bf.cem.g index 122205a1..34995b28 100644 --- a/lang/cem/ctest/ctgen/bf.cem.g +++ b/lang/cem/ctest/ctgen/bf.cem.g @@ -20,92 +20,92 @@ bfs.bf1 >= bfs.bf2 bfs.bf1 < bfs.bf2 bfs.bf1 > bfs.bf2 bfs.bf1 ? bfs.bf1 : bfs.bf2 -bfs.bf3 = bfs.bf1 1 -bfs.bf3 += bfs.bf1 0 -bfs.bf3 -= bfs.bf1 254 -bfs.bf3 /= bfs.bf1 255 +bfs.bf3 = bfs.bf1 -1 +bfs.bf3 += bfs.bf1 -2 +bfs.bf3 -= bfs.bf1 0 +bfs.bf3 /= bfs.bf1 1 bfs.bf3 %= bfs.bf1 0 -bfs.bf3 *= bfs.bf1 255 -bfs.bf3 &= bfs.bf1 1 -bfs.bf3 |= bfs.bf1 255 -bfs.bf3 ^= bfs.bf1 254 -bfs.bf3 <<= 1 254 -bfs.bf3 >>= 1 127 +bfs.bf3 *= bfs.bf1 1 +bfs.bf3 &= bfs.bf1 -1 +bfs.bf3 |= bfs.bf1 -1 +bfs.bf3 ^= bfs.bf1 0 +bfs.bf3 <<= 1 -2 +bfs.bf3 >>= 1 -1 bfs.bf3 ++ 0 -bfs.bf3 -- 254 --- bfs.bf3 254 +bfs.bf3 -- -2 +-- bfs.bf3 -2 ++ bfs.bf3 0 -bfs.bf4 = ( bfs.bf1 + bfs.bf2 ) 9 -bfs.bf4 = ( bfs.bf1 - bfs.bf2 ) -7 +bfs.bf4 = ( bfs.bf1 + bfs.bf2 ) -9 +bfs.bf4 = ( bfs.bf1 - bfs.bf2 ) 7 bfs.bf4 = ( bfs.bf1 / bfs.bf2 ) 0 -bfs.bf4 = ( bfs.bf1 % bfs.bf2 ) 1 +bfs.bf4 = ( bfs.bf1 % bfs.bf2 ) -1 bfs.bf4 = ( bfs.bf1 * bfs.bf2 ) 8 -bfs.bf4 = ( bfs.bf1 & bfs.bf2 ) 0 -bfs.bf4 = ( bfs.bf1 | bfs.bf2 ) 9 -bfs.bf4 = ( bfs.bf1 ^ bfs.bf2 ) 9 +bfs.bf4 = ( bfs.bf1 & bfs.bf2 ) -8 +bfs.bf4 = ( bfs.bf1 | bfs.bf2 ) -1 +bfs.bf4 = ( bfs.bf1 ^ bfs.bf2 ) 7 bfs.bf4 = ( bfs.bf1 || bfs.bf2 ) 1 bfs.bf4 = ( bfs.bf1 && bfs.bf2 ) 1 -bfs.bf4 = ( bfs.bf1 << 1 ) 2 -bfs.bf4 = ( bfs.bf1 >> 1 ) 0 -bfs.bf4 = ( -bfs.bf1 ) -1 +bfs.bf4 = ( bfs.bf1 << 1 ) -2 +bfs.bf4 = ( bfs.bf1 >> 1 ) -1 +bfs.bf4 = ( -bfs.bf1 ) 1 bfs.bf4 = ( !bfs.bf1 ) 0 -bfs.bf4 = ( ~bfs.bf1 ) -2 +bfs.bf4 = ( ~bfs.bf1 ) 0 bfs.bf4 = ( bfs.bf1 == bfs.bf2 ) 0 bfs.bf4 = ( bfs.bf1 != bfs.bf2 ) 1 -bfs.bf4 = ( bfs.bf1 <= bfs.bf2 ) 1 -bfs.bf4 = ( bfs.bf1 >= bfs.bf2 ) 0 -bfs.bf4 = ( bfs.bf1 < bfs.bf2 ) 1 -bfs.bf4 = ( bfs.bf1 > bfs.bf2 ) 0 -bfs.bf4 = ( bfs.bf1 ? bfs.bf1 : bfs.bf2 ) 1 -bfs.bf4 = ( bfs.bf3 = bfs.bf1 ) 1 1 -bfs.bf4 = ( bfs.bf3 += bfs.bf1 ) 0 0 -bfs.bf4 = ( bfs.bf3 -= bfs.bf1 ) 254 254 -bfs.bf4 = ( bfs.bf3 /= bfs.bf1 ) 255 255 +bfs.bf4 = ( bfs.bf1 <= bfs.bf2 ) 0 +bfs.bf4 = ( bfs.bf1 >= bfs.bf2 ) 1 +bfs.bf4 = ( bfs.bf1 < bfs.bf2 ) 0 +bfs.bf4 = ( bfs.bf1 > bfs.bf2 ) 1 +bfs.bf4 = ( bfs.bf1 ? bfs.bf1 : bfs.bf2 ) -1 +bfs.bf4 = ( bfs.bf3 = bfs.bf1 ) -1 -1 +bfs.bf4 = ( bfs.bf3 += bfs.bf1 ) -2 -2 +bfs.bf4 = ( bfs.bf3 -= bfs.bf1 ) 0 0 +bfs.bf4 = ( bfs.bf3 /= bfs.bf1 ) 1 1 bfs.bf4 = ( bfs.bf3 %= bfs.bf1 ) 0 0 -bfs.bf4 = ( bfs.bf3 *= bfs.bf1 ) 255 255 -bfs.bf4 = ( bfs.bf3 &= bfs.bf1 ) 1 1 -bfs.bf4 = ( bfs.bf3 |= bfs.bf1 ) 255 255 -bfs.bf4 = ( bfs.bf3 ^= bfs.bf1 ) 254 254 -bfs.bf4 = ( bfs.bf3 <<= 1 ) 254 254 -bfs.bf4 = ( bfs.bf3 >>= 1 ) 127 127 -bfs.bf4 = ( bfs.bf3 ++ ) 0 255 -bfs.bf4 = ( bfs.bf3 -- ) 254 255 -bfs.bf4 = ( -- bfs.bf3 ) 254 254 +bfs.bf4 = ( bfs.bf3 *= bfs.bf1 ) 1 1 +bfs.bf4 = ( bfs.bf3 &= bfs.bf1 ) -1 -1 +bfs.bf4 = ( bfs.bf3 |= bfs.bf1 ) -1 -1 +bfs.bf4 = ( bfs.bf3 ^= bfs.bf1 ) 0 0 +bfs.bf4 = ( bfs.bf3 <<= 1 ) -2 -2 +bfs.bf4 = ( bfs.bf3 >>= 1 ) -1 -1 +bfs.bf4 = ( bfs.bf3 ++ ) 0 -1 +bfs.bf4 = ( bfs.bf3 -- ) -2 -1 +bfs.bf4 = ( -- bfs.bf3 ) -2 -2 bfs.bf4 = ( ++ bfs.bf3 ) 0 0 yes if ( bfs.bf1 + bfs.bf2 ) yes() ; else no() yes if ( bfs.bf1 - bfs.bf2 ) yes() ; else no() no if ( bfs.bf1 / bfs.bf2 ) yes() ; else no() yes if ( bfs.bf1 % bfs.bf2 ) yes() ; else no() yes if ( bfs.bf1 * bfs.bf2 ) yes() ; else no() -no if ( bfs.bf1 & bfs.bf2 ) yes() ; else no() +yes if ( bfs.bf1 & bfs.bf2 ) yes() ; else no() yes if ( bfs.bf1 | bfs.bf2 ) yes() ; else no() yes if ( bfs.bf1 ^ bfs.bf2 ) yes() ; else no() yes if ( bfs.bf1 || bfs.bf2 ) yes() ; else no() yes if ( bfs.bf1 && bfs.bf2 ) yes() ; else no() yes if ( bfs.bf1 << 1 ) yes() ; else no() -no if ( bfs.bf1 >> 1 ) yes() ; else no() +yes if ( bfs.bf1 >> 1 ) yes() ; else no() yes if ( -bfs.bf1 ) yes() ; else no() no if ( !bfs.bf1 ) yes() ; else no() -yes if ( ~bfs.bf1 ) yes() ; else no() +no if ( ~bfs.bf1 ) yes() ; else no() no if ( bfs.bf1 == bfs.bf2 ) yes() ; else no() yes if ( bfs.bf1 != bfs.bf2 ) yes() ; else no() -yes if ( bfs.bf1 <= bfs.bf2 ) yes() ; else no() -no if ( bfs.bf1 >= bfs.bf2 ) yes() ; else no() -yes if ( bfs.bf1 < bfs.bf2 ) yes() ; else no() -no if ( bfs.bf1 > bfs.bf2 ) yes() ; else no() +no if ( bfs.bf1 <= bfs.bf2 ) yes() ; else no() +yes if ( bfs.bf1 >= bfs.bf2 ) yes() ; else no() +no if ( bfs.bf1 < bfs.bf2 ) yes() ; else no() +yes if ( bfs.bf1 > bfs.bf2 ) yes() ; else no() yes if ( bfs.bf1 ? bfs.bf1 : bfs.bf2 ) yes() ; else no() -yes if ( bfs.bf3 = bfs.bf1 ) yes() ; else no() 1 -no if ( bfs.bf3 += bfs.bf1 ) yes() ; else no() 0 -yes if ( bfs.bf3 -= bfs.bf1 ) yes() ; else no() 254 -yes if ( bfs.bf3 /= bfs.bf1 ) yes() ; else no() 255 +yes if ( bfs.bf3 = bfs.bf1 ) yes() ; else no() -1 +yes if ( bfs.bf3 += bfs.bf1 ) yes() ; else no() -2 +no if ( bfs.bf3 -= bfs.bf1 ) yes() ; else no() 0 +yes if ( bfs.bf3 /= bfs.bf1 ) yes() ; else no() 1 no if ( bfs.bf3 %= bfs.bf1 ) yes() ; else no() 0 -yes if ( bfs.bf3 *= bfs.bf1 ) yes() ; else no() 255 -yes if ( bfs.bf3 &= bfs.bf1 ) yes() ; else no() 1 -yes if ( bfs.bf3 |= bfs.bf1 ) yes() ; else no() 255 -yes if ( bfs.bf3 ^= bfs.bf1 ) yes() ; else no() 254 -yes if ( bfs.bf3 <<= 1 ) yes() ; else no() 254 -yes if ( bfs.bf3 >>= 1 ) yes() ; else no() 127 +yes if ( bfs.bf3 *= bfs.bf1 ) yes() ; else no() 1 +yes if ( bfs.bf3 &= bfs.bf1 ) yes() ; else no() -1 +yes if ( bfs.bf3 |= bfs.bf1 ) yes() ; else no() -1 +no if ( bfs.bf3 ^= bfs.bf1 ) yes() ; else no() 0 +yes if ( bfs.bf3 <<= 1 ) yes() ; else no() -2 +yes if ( bfs.bf3 >>= 1 ) yes() ; else no() -1 yes if ( bfs.bf3 ++ ) yes() ; else no() 0 -yes if ( bfs.bf3 -- ) yes() ; else no() 254 -yes if ( -- bfs.bf3 ) yes() ; else no() 254 +yes if ( bfs.bf3 -- ) yes() ; else no() -2 +yes if ( -- bfs.bf3 ) yes() ; else no() -2 no if ( ++ bfs.bf3 ) yes() ; else no() 0 diff --git a/lang/cem/ctest/ctgen/clu.cem.g b/lang/cem/ctest/ctgen/clu.cem.g index ed4e098a..b1797f6e 100644 --- a/lang/cem/ctest/ctgen/clu.cem.g +++ b/lang/cem/ctest/ctgen/clu.cem.g @@ -20,52 +20,52 @@ 40000 < 8012 40000 > 8012 40000 ? 40000 : 8012 -x = 40000 -25536 -x += 40000 -25526 -x -= 40000 25546 +x = 40000 40000 +x += 40000 40010 +x -= 40000 -39990 x /= 40000 0 x %= 40000 10 -x *= 40000 6784 +x *= 40000 400000 x &= 40000 0 -x |= 40000 -25526 -x ^= 40000 -25526 +x |= 40000 40010 +x ^= 40000 40010 x <<= 9 5120 x >>= 9 0 x ++ 11 x -- 9 -- x 9 ++ x 11 -y = ( 40000 + 8012 ) -17524 +y = ( 40000 + 8012 ) 48012 y = ( 40000 - 8012 ) 31988 y = ( 40000 / 8012 ) 4 y = ( 40000 % 8012 ) 7952 -y = ( 40000 * 8012 ) 8960 +y = ( 40000 * 8012 ) 320480000 y = ( 40000 & 8012 ) 7232 -y = ( 40000 | 8012 ) -24756 -y = ( 40000 ^ 8012 ) -31988 +y = ( 40000 | 8012 ) 40780 +y = ( 40000 ^ 8012 ) 33548 y = ( 40000 || 8012 ) 1 y = ( 40000 && 8012 ) 1 -y = ( 40000 << 9 ) -32768 +y = ( 40000 << 9 ) 20480000 y = ( 40000 >> 9 ) 78 -y = ( -40000 ) 25536 +y = ( -40000 ) -40000 y = ( !40000 ) 0 -y = ( ~40000 ) 25535 +y = ( ~40000 ) -40001 y = ( 40000 == 8012 ) 0 y = ( 40000 != 8012 ) 1 y = ( 40000 <= 8012 ) 0 y = ( 40000 >= 8012 ) 1 y = ( 40000 < 8012 ) 0 y = ( 40000 > 8012 ) 1 -y = ( 40000 ? 40000 : 8012 ) -25536 -y = ( x = 40000 ) -25536 -25536 -y = ( x += 40000 ) -25526 -25526 -y = ( x -= 40000 ) 25546 25546 +y = ( 40000 ? 40000 : 8012 ) 40000 +y = ( x = 40000 ) 40000 40000 +y = ( x += 40000 ) 40010 40010 +y = ( x -= 40000 ) -39990 -39990 y = ( x /= 40000 ) 0 0 y = ( x %= 40000 ) 10 10 -y = ( x *= 40000 ) 6784 6784 +y = ( x *= 40000 ) 400000 400000 y = ( x &= 40000 ) 0 0 -y = ( x |= 40000 ) -25526 -25526 -y = ( x ^= 40000 ) -25526 -25526 +y = ( x |= 40000 ) 40010 40010 +y = ( x ^= 40000 ) 40010 40010 y = ( x <<= 9 ) 5120 5120 y = ( x >>= 9 ) 0 0 y = ( x ++ ) 11 10 @@ -94,15 +94,15 @@ yes if ( 40000 >= 8012 ) yes() ; else no() no if ( 40000 < 8012 ) yes() ; else no() yes if ( 40000 > 8012 ) yes() ; else no() yes if ( 40000 ? 40000 : 8012 ) yes() ; else no() -yes if ( x = 40000 ) yes() ; else no() -25536 -yes if ( x += 40000 ) yes() ; else no() -25526 -yes if ( x -= 40000 ) yes() ; else no() 25546 +yes if ( x = 40000 ) yes() ; else no() 40000 +yes if ( x += 40000 ) yes() ; else no() 40010 +yes if ( x -= 40000 ) yes() ; else no() -39990 no if ( x /= 40000 ) yes() ; else no() 0 yes if ( x %= 40000 ) yes() ; else no() 10 -yes if ( x *= 40000 ) yes() ; else no() 6784 +yes if ( x *= 40000 ) yes() ; else no() 400000 no if ( x &= 40000 ) yes() ; else no() 0 -yes if ( x |= 40000 ) yes() ; else no() -25526 -yes if ( x ^= 40000 ) yes() ; else no() -25526 +yes if ( x |= 40000 ) yes() ; else no() 40010 +yes if ( x ^= 40000 ) yes() ; else no() 40010 yes if ( x <<= 9 ) yes() ; else no() 5120 no if ( x >>= 9 ) yes() ; else no() 0 yes if ( x ++ ) yes() ; else no() 11 diff --git a/lang/cem/ctest/ctgen/ec.cem.g b/lang/cem/ctest/ctgen/ec.cem.g index 8972fadd..66881130 100644 --- a/lang/cem/ctest/ctgen/ec.cem.g +++ b/lang/cem/ctest/ctgen/ec.cem.g @@ -22,21 +22,21 @@ '0' ? '0' : '1' x = '0' 48 x += '0' 58 -x -= '0' 218 +x -= '0' -38 x /= '0' 0 x %= '0' 10 -x *= '0' 224 +x *= '0' -32 x &= '0' 0 x |= '0' 58 x ^= '0' 58 -x <<= 4 160 +x <<= 4 -96 x >>= 4 0 x ++ 11 x -- 9 -- x 9 ++ x 11 y = ( '0' + '1' ) 97 -y = ( '0' - '1' ) 255 +y = ( '0' - '1' ) -1 y = ( '0' / '1' ) 0 y = ( '0' % '1' ) 48 y = ( '0' * '1' ) 48 @@ -47,9 +47,9 @@ y = ( '0' || '1' ) 1 y = ( '0' && '1' ) 1 y = ( '0' << 4 ) 0 y = ( '0' >> 4 ) 3 -y = ( -'0' ) 208 +y = ( -'0' ) -48 y = ( !'0' ) 0 -y = ( ~'0' ) 207 +y = ( ~'0' ) -49 y = ( '0' == '1' ) 0 y = ( '0' != '1' ) 1 y = ( '0' <= '1' ) 1 @@ -59,14 +59,14 @@ y = ( '0' > '1' ) 0 y = ( '0' ? '0' : '1' ) 48 y = ( x = '0' ) 48 48 y = ( x += '0' ) 58 58 -y = ( x -= '0' ) 218 218 +y = ( x -= '0' ) -38 -38 y = ( x /= '0' ) 0 0 y = ( x %= '0' ) 10 10 -y = ( x *= '0' ) 224 224 +y = ( x *= '0' ) -32 -32 y = ( x &= '0' ) 0 0 y = ( x |= '0' ) 58 58 y = ( x ^= '0' ) 58 58 -y = ( x <<= 4 ) 160 160 +y = ( x <<= 4 ) -96 -96 y = ( x >>= 4 ) 0 0 y = ( x ++ ) 11 10 y = ( x -- ) 9 10 @@ -96,14 +96,14 @@ no if ( '0' > '1' ) yes() ; else no() yes if ( '0' ? '0' : '1' ) yes() ; else no() yes if ( x = '0' ) yes() ; else no() 48 yes if ( x += '0' ) yes() ; else no() 58 -yes if ( x -= '0' ) yes() ; else no() 218 +yes if ( x -= '0' ) yes() ; else no() -38 no if ( x /= '0' ) yes() ; else no() 0 yes if ( x %= '0' ) yes() ; else no() 10 -yes if ( x *= '0' ) yes() ; else no() 224 +yes if ( x *= '0' ) yes() ; else no() -32 no if ( x &= '0' ) yes() ; else no() 0 yes if ( x |= '0' ) yes() ; else no() 58 yes if ( x ^= '0' ) yes() ; else no() 58 -yes if ( x <<= 4 ) yes() ; else no() 160 +yes if ( x <<= 4 ) yes() ; else no() -96 no if ( x >>= 4 ) yes() ; else no() 0 yes if ( x ++ ) yes() ; else no() 11 yes if ( x -- ) yes() ; else no() 9 diff --git a/lang/cem/ctest/ctgen/ei.cem.g b/lang/cem/ctest/ctgen/ei.cem.g index fa2e6133..a3c3aefb 100644 --- a/lang/cem/ctest/ctgen/ei.cem.g +++ b/lang/cem/ctest/ctgen/ei.cem.g @@ -29,7 +29,7 @@ x *= 4 1020 x &= 4 4 x |= 4 255 x ^= 4 251 -x <<= 15 -32768 +x <<= 15 8355840 x >>= 15 0 x ++ 256 x -- 254 @@ -45,7 +45,7 @@ y = ( 4 | 5 ) 5 y = ( 4 ^ 5 ) 1 y = ( 4 || 5 ) 1 y = ( 4 && 5 ) 1 -y = ( 4 << 15 ) 0 +y = ( 4 << 15 ) 131072 y = ( 4 >> 15 ) 0 y = ( -4 ) -4 y = ( !4 ) 0 @@ -66,7 +66,7 @@ y = ( x *= 4 ) 1020 1020 y = ( x &= 4 ) 4 4 y = ( x |= 4 ) 255 255 y = ( x ^= 4 ) 251 251 -y = ( x <<= 15 ) -32768 -32768 +y = ( x <<= 15 ) 8355840 8355840 y = ( x >>= 15 ) 0 0 y = ( x ++ ) 256 255 y = ( x -- ) 254 255 @@ -82,7 +82,7 @@ yes if ( 4 | 5 ) yes() ; else no() yes if ( 4 ^ 5 ) yes() ; else no() yes if ( 4 || 5 ) yes() ; else no() yes if ( 4 && 5 ) yes() ; else no() -no if ( 4 << 15 ) yes() ; else no() +yes if ( 4 << 15 ) yes() ; else no() no if ( 4 >> 15 ) yes() ; else no() yes if ( -4 ) yes() ; else no() no if ( !4 ) yes() ; else no() @@ -103,7 +103,7 @@ yes if ( x *= 4 ) yes() ; else no() 1020 yes if ( x &= 4 ) yes() ; else no() 4 yes if ( x |= 4 ) yes() ; else no() 255 yes if ( x ^= 4 ) yes() ; else no() 251 -yes if ( x <<= 15 ) yes() ; else no() -32768 +yes if ( x <<= 15 ) yes() ; else no() 8355840 no if ( x >>= 15 ) yes() ; else no() 0 yes if ( x ++ ) yes() ; else no() 256 yes if ( x -- ) yes() ; else no() 254 diff --git a/lang/cem/ctest/ctgen/eu.cem.g b/lang/cem/ctest/ctgen/eu.cem.g index ed4e098a..b1797f6e 100644 --- a/lang/cem/ctest/ctgen/eu.cem.g +++ b/lang/cem/ctest/ctgen/eu.cem.g @@ -20,52 +20,52 @@ 40000 < 8012 40000 > 8012 40000 ? 40000 : 8012 -x = 40000 -25536 -x += 40000 -25526 -x -= 40000 25546 +x = 40000 40000 +x += 40000 40010 +x -= 40000 -39990 x /= 40000 0 x %= 40000 10 -x *= 40000 6784 +x *= 40000 400000 x &= 40000 0 -x |= 40000 -25526 -x ^= 40000 -25526 +x |= 40000 40010 +x ^= 40000 40010 x <<= 9 5120 x >>= 9 0 x ++ 11 x -- 9 -- x 9 ++ x 11 -y = ( 40000 + 8012 ) -17524 +y = ( 40000 + 8012 ) 48012 y = ( 40000 - 8012 ) 31988 y = ( 40000 / 8012 ) 4 y = ( 40000 % 8012 ) 7952 -y = ( 40000 * 8012 ) 8960 +y = ( 40000 * 8012 ) 320480000 y = ( 40000 & 8012 ) 7232 -y = ( 40000 | 8012 ) -24756 -y = ( 40000 ^ 8012 ) -31988 +y = ( 40000 | 8012 ) 40780 +y = ( 40000 ^ 8012 ) 33548 y = ( 40000 || 8012 ) 1 y = ( 40000 && 8012 ) 1 -y = ( 40000 << 9 ) -32768 +y = ( 40000 << 9 ) 20480000 y = ( 40000 >> 9 ) 78 -y = ( -40000 ) 25536 +y = ( -40000 ) -40000 y = ( !40000 ) 0 -y = ( ~40000 ) 25535 +y = ( ~40000 ) -40001 y = ( 40000 == 8012 ) 0 y = ( 40000 != 8012 ) 1 y = ( 40000 <= 8012 ) 0 y = ( 40000 >= 8012 ) 1 y = ( 40000 < 8012 ) 0 y = ( 40000 > 8012 ) 1 -y = ( 40000 ? 40000 : 8012 ) -25536 -y = ( x = 40000 ) -25536 -25536 -y = ( x += 40000 ) -25526 -25526 -y = ( x -= 40000 ) 25546 25546 +y = ( 40000 ? 40000 : 8012 ) 40000 +y = ( x = 40000 ) 40000 40000 +y = ( x += 40000 ) 40010 40010 +y = ( x -= 40000 ) -39990 -39990 y = ( x /= 40000 ) 0 0 y = ( x %= 40000 ) 10 10 -y = ( x *= 40000 ) 6784 6784 +y = ( x *= 40000 ) 400000 400000 y = ( x &= 40000 ) 0 0 -y = ( x |= 40000 ) -25526 -25526 -y = ( x ^= 40000 ) -25526 -25526 +y = ( x |= 40000 ) 40010 40010 +y = ( x ^= 40000 ) 40010 40010 y = ( x <<= 9 ) 5120 5120 y = ( x >>= 9 ) 0 0 y = ( x ++ ) 11 10 @@ -94,15 +94,15 @@ yes if ( 40000 >= 8012 ) yes() ; else no() no if ( 40000 < 8012 ) yes() ; else no() yes if ( 40000 > 8012 ) yes() ; else no() yes if ( 40000 ? 40000 : 8012 ) yes() ; else no() -yes if ( x = 40000 ) yes() ; else no() -25536 -yes if ( x += 40000 ) yes() ; else no() -25526 -yes if ( x -= 40000 ) yes() ; else no() 25546 +yes if ( x = 40000 ) yes() ; else no() 40000 +yes if ( x += 40000 ) yes() ; else no() 40010 +yes if ( x -= 40000 ) yes() ; else no() -39990 no if ( x /= 40000 ) yes() ; else no() 0 yes if ( x %= 40000 ) yes() ; else no() 10 -yes if ( x *= 40000 ) yes() ; else no() 6784 +yes if ( x *= 40000 ) yes() ; else no() 400000 no if ( x &= 40000 ) yes() ; else no() 0 -yes if ( x |= 40000 ) yes() ; else no() -25526 -yes if ( x ^= 40000 ) yes() ; else no() -25526 +yes if ( x |= 40000 ) yes() ; else no() 40010 +yes if ( x ^= 40000 ) yes() ; else no() 40010 yes if ( x <<= 9 ) yes() ; else no() 5120 no if ( x >>= 9 ) yes() ; else no() 0 yes if ( x ++ ) yes() ; else no() 11 diff --git a/lang/cem/ctest/ctgen/id.cem.g b/lang/cem/ctest/ctgen/id.cem.g new file mode 100644 index 00000000..d7b33241 --- /dev/null +++ b/lang/cem/ctest/ctgen/id.cem.g @@ -0,0 +1,72 @@ +(-40) + 300 +(-40) - 300 +(-40) / 300 +(-40) * 300 +(-40) || 300 +(-40) && 300 +-(-40) +!(-40) +(-40) == 300 +(-40) != 300 +(-40) <= 300 +(-40) >= 300 +(-40) < 300 +(-40) > 300 +(-40) ? (-40) : 300 +x = (-40) -4.000000e+01 +x += (-40) -3.685850e+01 +x -= (-40) 4.314150e+01 +x /= (-40) -7.853750e-02 +x *= (-40) -1.256600e+02 +x ++ 4.141500e+00 +x -- 2.141500e+00 +-- x 2.141500e+00 +++ x 4.141500e+00 +y = ( (-40) + 300 ) 17538 +y = ( (-40) - 300 ) 50346 +y = ( (-40) / 300 ) 0 +y = ( (-40) * 300 ) -2147432645 +y = ( (-40) || 300 ) 16512 +y = ( (-40) && 300 ) 16512 +y = ( -(-40) ) 17184 +y = ( !(-40) ) 0 +y = ( (-40) == 300 ) 0 +y = ( (-40) != 300 ) 16512 +y = ( (-40) <= 300 ) 16512 +y = ( (-40) >= 300 ) 0 +y = ( (-40) < 300 ) 16512 +y = ( (-40) > 300 ) 0 +y = ( (-40) ? (-40) : 300 ) 49952 +y = ( x = (-40) ) -4.000000e+01 49952 +y = ( x += (-40) ) -3.685850e+01 1864024851 +y = ( x -= (-40) ) 4.314150e+01 -1864023252 +y = ( x /= (-40) ) -7.853750e-02 -666583392 +y = ( x *= (-40) ) -1.256600e+02 1374405627 +y = ( x ++ ) 4.141500e+00 240533833 +y = ( x -- ) 2.141500e+00 240533833 +y = ( -- x ) 2.141500e+00 240533769 +y = ( ++ x ) 4.141500e+00 -2027208316 +yes if ( (-40) + 300 ) yes() ; else no() +yes if ( (-40) - 300 ) yes() ; else no() +no if ( (-40) / 300 ) yes() ; else no() +yes if ( (-40) * 300 ) yes() ; else no() +yes if ( (-40) || 300 ) yes() ; else no() +yes if ( (-40) && 300 ) yes() ; else no() +yes if ( -(-40) ) yes() ; else no() +no if ( !(-40) ) yes() ; else no() +no if ( (-40) == 300 ) yes() ; else no() +yes if ( (-40) != 300 ) yes() ; else no() +yes if ( (-40) <= 300 ) yes() ; else no() +no if ( (-40) >= 300 ) yes() ; else no() +yes if ( (-40) < 300 ) yes() ; else no() +no if ( (-40) > 300 ) yes() ; else no() +yes if ( (-40) ? (-40) : 300 ) yes() ; else no() +yes if ( x = (-40) ) yes() ; else no() -4.000000e+01 +yes if ( x += (-40) ) yes() ; else no() -3.685850e+01 +yes if ( x -= (-40) ) yes() ; else no() 4.314150e+01 +yes if ( x /= (-40) ) yes() ; else no() -7.853750e-02 +yes if ( x *= (-40) ) yes() ; else no() -1.256600e+02 +yes if ( x ++ ) yes() ; else no() 4.141500e+00 +yes if ( x -- ) yes() ; else no() 2.141500e+00 +yes if ( -- x ) yes() ; else no() 2.141500e+00 +yes if ( ++ x ) yes() ; else no() 4.141500e+00 diff --git a/lang/cem/ctest/ctgen/lc.cem.g b/lang/cem/ctest/ctgen/lc.cem.g index 8972fadd..66881130 100644 --- a/lang/cem/ctest/ctgen/lc.cem.g +++ b/lang/cem/ctest/ctgen/lc.cem.g @@ -22,21 +22,21 @@ '0' ? '0' : '1' x = '0' 48 x += '0' 58 -x -= '0' 218 +x -= '0' -38 x /= '0' 0 x %= '0' 10 -x *= '0' 224 +x *= '0' -32 x &= '0' 0 x |= '0' 58 x ^= '0' 58 -x <<= 4 160 +x <<= 4 -96 x >>= 4 0 x ++ 11 x -- 9 -- x 9 ++ x 11 y = ( '0' + '1' ) 97 -y = ( '0' - '1' ) 255 +y = ( '0' - '1' ) -1 y = ( '0' / '1' ) 0 y = ( '0' % '1' ) 48 y = ( '0' * '1' ) 48 @@ -47,9 +47,9 @@ y = ( '0' || '1' ) 1 y = ( '0' && '1' ) 1 y = ( '0' << 4 ) 0 y = ( '0' >> 4 ) 3 -y = ( -'0' ) 208 +y = ( -'0' ) -48 y = ( !'0' ) 0 -y = ( ~'0' ) 207 +y = ( ~'0' ) -49 y = ( '0' == '1' ) 0 y = ( '0' != '1' ) 1 y = ( '0' <= '1' ) 1 @@ -59,14 +59,14 @@ y = ( '0' > '1' ) 0 y = ( '0' ? '0' : '1' ) 48 y = ( x = '0' ) 48 48 y = ( x += '0' ) 58 58 -y = ( x -= '0' ) 218 218 +y = ( x -= '0' ) -38 -38 y = ( x /= '0' ) 0 0 y = ( x %= '0' ) 10 10 -y = ( x *= '0' ) 224 224 +y = ( x *= '0' ) -32 -32 y = ( x &= '0' ) 0 0 y = ( x |= '0' ) 58 58 y = ( x ^= '0' ) 58 58 -y = ( x <<= 4 ) 160 160 +y = ( x <<= 4 ) -96 -96 y = ( x >>= 4 ) 0 0 y = ( x ++ ) 11 10 y = ( x -- ) 9 10 @@ -96,14 +96,14 @@ no if ( '0' > '1' ) yes() ; else no() yes if ( '0' ? '0' : '1' ) yes() ; else no() yes if ( x = '0' ) yes() ; else no() 48 yes if ( x += '0' ) yes() ; else no() 58 -yes if ( x -= '0' ) yes() ; else no() 218 +yes if ( x -= '0' ) yes() ; else no() -38 no if ( x /= '0' ) yes() ; else no() 0 yes if ( x %= '0' ) yes() ; else no() 10 -yes if ( x *= '0' ) yes() ; else no() 224 +yes if ( x *= '0' ) yes() ; else no() -32 no if ( x &= '0' ) yes() ; else no() 0 yes if ( x |= '0' ) yes() ; else no() 58 yes if ( x ^= '0' ) yes() ; else no() 58 -yes if ( x <<= 4 ) yes() ; else no() 160 +yes if ( x <<= 4 ) yes() ; else no() -96 no if ( x >>= 4 ) yes() ; else no() 0 yes if ( x ++ ) yes() ; else no() 11 yes if ( x -- ) yes() ; else no() 9 diff --git a/lang/cem/ctest/ctgen/li.cem.g b/lang/cem/ctest/ctgen/li.cem.g index fa2e6133..a3c3aefb 100644 --- a/lang/cem/ctest/ctgen/li.cem.g +++ b/lang/cem/ctest/ctgen/li.cem.g @@ -29,7 +29,7 @@ x *= 4 1020 x &= 4 4 x |= 4 255 x ^= 4 251 -x <<= 15 -32768 +x <<= 15 8355840 x >>= 15 0 x ++ 256 x -- 254 @@ -45,7 +45,7 @@ y = ( 4 | 5 ) 5 y = ( 4 ^ 5 ) 1 y = ( 4 || 5 ) 1 y = ( 4 && 5 ) 1 -y = ( 4 << 15 ) 0 +y = ( 4 << 15 ) 131072 y = ( 4 >> 15 ) 0 y = ( -4 ) -4 y = ( !4 ) 0 @@ -66,7 +66,7 @@ y = ( x *= 4 ) 1020 1020 y = ( x &= 4 ) 4 4 y = ( x |= 4 ) 255 255 y = ( x ^= 4 ) 251 251 -y = ( x <<= 15 ) -32768 -32768 +y = ( x <<= 15 ) 8355840 8355840 y = ( x >>= 15 ) 0 0 y = ( x ++ ) 256 255 y = ( x -- ) 254 255 @@ -82,7 +82,7 @@ yes if ( 4 | 5 ) yes() ; else no() yes if ( 4 ^ 5 ) yes() ; else no() yes if ( 4 || 5 ) yes() ; else no() yes if ( 4 && 5 ) yes() ; else no() -no if ( 4 << 15 ) yes() ; else no() +yes if ( 4 << 15 ) yes() ; else no() no if ( 4 >> 15 ) yes() ; else no() yes if ( -4 ) yes() ; else no() no if ( !4 ) yes() ; else no() @@ -103,7 +103,7 @@ yes if ( x *= 4 ) yes() ; else no() 1020 yes if ( x &= 4 ) yes() ; else no() 4 yes if ( x |= 4 ) yes() ; else no() 255 yes if ( x ^= 4 ) yes() ; else no() 251 -yes if ( x <<= 15 ) yes() ; else no() -32768 +yes if ( x <<= 15 ) yes() ; else no() 8355840 no if ( x >>= 15 ) yes() ; else no() 0 yes if ( x ++ ) yes() ; else no() 256 yes if ( x -- ) yes() ; else no() 254 diff --git a/lang/cem/ctest/ctgen/lu.cem.g b/lang/cem/ctest/ctgen/lu.cem.g index 7dd221ea..be2a6aae 100644 --- a/lang/cem/ctest/ctgen/lu.cem.g +++ b/lang/cem/ctest/ctgen/lu.cem.g @@ -20,52 +20,52 @@ x >= 8012 x < 8012 x > 8012 x ? x : 8012 -z = x -25302 -z += x -25292 -z -= x 25312 +z = x 40234 +z += x 40244 +z -= x -40224 z /= x 0 z %= x 10 -z *= x 9124 +z *= x 402340 z &= x 10 -z |= x -25302 -z ^= x -25312 +z |= x 40234 +z ^= x 40224 z <<= 9 5120 z >>= 9 0 z ++ 11 z -- 9 -- z 9 ++ z 11 -y = ( x + 8012 ) -17290 +y = ( x + 8012 ) 48246 y = ( x - 8012 ) 32222 y = ( x / 8012 ) 5 y = ( x % 8012 ) 174 -y = ( x * 8012 ) -16776 +y = ( x * 8012 ) 322354808 y = ( x & 8012 ) 7432 -y = ( x | 8012 ) -24722 -y = ( x ^ 8012 ) -32154 +y = ( x | 8012 ) 40814 +y = ( x ^ 8012 ) 33382 y = ( x || 8012 ) 1 y = ( x && 8012 ) 1 -y = ( x << 9 ) 21504 +y = ( x << 9 ) 20599808 y = ( x >> 9 ) 78 -y = ( -x ) 25302 +y = ( -x ) -40234 y = ( !x ) 0 -y = ( ~x ) 25301 +y = ( ~x ) -40235 y = ( x == 8012 ) 0 y = ( x != 8012 ) 1 y = ( x <= 8012 ) 0 y = ( x >= 8012 ) 1 y = ( x < 8012 ) 0 y = ( x > 8012 ) 1 -y = ( x ? x : 8012 ) -25302 -y = ( z = x ) -25302 -25302 -y = ( z += x ) -25292 -25292 -y = ( z -= x ) 25312 25312 +y = ( x ? x : 8012 ) 40234 +y = ( z = x ) 40234 40234 +y = ( z += x ) 40244 40244 +y = ( z -= x ) -40224 -40224 y = ( z /= x ) 0 0 y = ( z %= x ) 10 10 -y = ( z *= x ) 9124 9124 +y = ( z *= x ) 402340 402340 y = ( z &= x ) 10 10 -y = ( z |= x ) -25302 -25302 -y = ( z ^= x ) -25312 -25312 +y = ( z |= x ) 40234 40234 +y = ( z ^= x ) 40224 40224 y = ( z <<= 9 ) 5120 5120 y = ( z >>= 9 ) 0 0 y = ( z ++ ) 11 10 @@ -94,15 +94,15 @@ yes if ( x >= 8012 ) yes() ; else no() no if ( x < 8012 ) yes() ; else no() yes if ( x > 8012 ) yes() ; else no() yes if ( x ? x : 8012 ) yes() ; else no() -yes if ( z = x ) yes() ; else no() -25302 -yes if ( z += x ) yes() ; else no() -25292 -yes if ( z -= x ) yes() ; else no() 25312 +yes if ( z = x ) yes() ; else no() 40234 +yes if ( z += x ) yes() ; else no() 40244 +yes if ( z -= x ) yes() ; else no() -40224 no if ( z /= x ) yes() ; else no() 0 yes if ( z %= x ) yes() ; else no() 10 -yes if ( z *= x ) yes() ; else no() 9124 +yes if ( z *= x ) yes() ; else no() 402340 yes if ( z &= x ) yes() ; else no() 10 -yes if ( z |= x ) yes() ; else no() -25302 -yes if ( z ^= x ) yes() ; else no() -25312 +yes if ( z |= x ) yes() ; else no() 40234 +yes if ( z ^= x ) yes() ; else no() 40224 yes if ( z <<= 9 ) yes() ; else no() 5120 no if ( z >>= 9 ) yes() ; else no() 0 yes if ( z ++ ) yes() ; else no() 11 diff --git a/lang/cem/ctest/ctinit/init.cem.g b/lang/cem/ctest/ctinit/init.cem.g index 6f1803cc..7c0e00ca 100644 --- a/lang/cem/ctest/ctinit/init.cem.g +++ b/lang/cem/ctest/ctinit/init.cem.g @@ -45,7 +45,7 @@ fl2 2.00000000000000000000e+00 fl2 2.00000000000000000000e+00 fl4 4.00000000000000000000e+00 fl5 2.93873587705571892581e-39 -fl6 1.70141173319264427000e+38 +fl6 1.70141173319264428000e+38 fl7 0.00000000000000000000e+00 fla1 fla2 fla3 1.000000e+00 -1.000000e+00 1.100000e+01 @@ -107,6 +107,6 @@ s_f 0.000000e+00 -1.000000e+01 0.000000e+00 0.000000e+00 bit fields: -sizeof stb 6 -stb 1 2 3 4 3 6 7 +sizeof stb 8 +stb -1 -2 3 4 -1 6 7 diff --git a/lang/cem/ctest/ctmargt/margt.cem.g b/lang/cem/ctest/ctmargt/margt.cem.g index 15bf3f30..27fc0cc2 100644 --- a/lang/cem/ctest/ctmargt/margt.cem.g +++ b/lang/cem/ctest/ctmargt/margt.cem.g @@ -2,6 +2,8 @@ main called with argc = 1 Arguments: margt.cem Environment: - HOME=/other/keie - PATH=:/other/keie/bin:/bin:/usr/bin - TERM=MiniBee + HOME=/usr/em + PATH=:/bin:/usr/ucb:/usr/local:/usr/bin:/usr/em/bin + SHELL=/usr/local/esh + TERM=dialup + USER=em diff --git a/lang/cem/ctest/ctsys/tfork.cem.g b/lang/cem/ctest/ctsys/tfork.cem.g index 8021a812..96f239a8 100644 --- a/lang/cem/ctest/ctsys/tfork.cem.g +++ b/lang/cem/ctest/ctsys/tfork.cem.g @@ -1,3 +1,3 @@ -childno N -Child N, status 0x800 +childno 16276 +Child 16276, status 0x800 fork/wait ok From 8ec6a1de4bb8e6574a7e39ef3041297e1e0c110d Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 24 Feb 1987 10:45:54 +0000 Subject: [PATCH 0865/1625] still referred to BadAssertion.c instead of BadAssert.c --- modules/src/assert/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/src/assert/Makefile b/modules/src/assert/Makefile index cc5b6cc8..7afc2796 100644 --- a/modules/src/assert/Makefile +++ b/modules/src/assert/Makefile @@ -7,8 +7,8 @@ COMPARE = $(MODULES)/compare all: libassert.a -libassert.a: BadAssertion.o - ar r libassert.a BadAssertion.o +libassert.a: BadAssert.o + ar r libassert.a BadAssert.o -sh -c 'ranlib libassert.a' install: all @@ -22,7 +22,7 @@ cmp: all $(COMPARE) h/assert.h pr: - @pr Makefile assert.h BadAssertion.c + @pr Makefile assert.h BadAssert.c opr: make pr | opr From 501293d45881f0c5f91637cd581897d3fc31f1c6 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 24 Feb 1987 10:49:54 +0000 Subject: [PATCH 0866/1625] solved a problem with include files --- lang/cem/libcc/gen/getlogin.c | 26 +++++++++++++++++++++++--- lang/cem/libcc/gen/ttyslot.c | 26 ++++++++++++++++++-------- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/lang/cem/libcc/gen/getlogin.c b/lang/cem/libcc/gen/getlogin.c index 5f3f5fb2..5fb25f42 100644 --- a/lang/cem/libcc/gen/getlogin.c +++ b/lang/cem/libcc/gen/getlogin.c @@ -1,8 +1,28 @@ #define UTMPFILE "/etc/utmp" -/* some systems require inclusion of sys/types.h before utmp.h */ -#include -#include +#ifdef USG +struct utmp { + char ut_name[8]; + char ut_id[4]; + char ut_line[12]; + short ut_pid; + short ut_type; + struct exit_status { + short e_termination; + short e_exit; + } ut_exit; + long ut_time; +}; +#else +struct utmp { + char ut_line[8]; + char ut_name[8]; +#ifdef BSD4_2 + char ut_host[16]; +#endif + long ut_time; +}; +#endif char * getlogin() diff --git a/lang/cem/libcc/gen/ttyslot.c b/lang/cem/libcc/gen/ttyslot.c index b91b12e7..d9969e07 100644 --- a/lang/cem/libcc/gen/ttyslot.c +++ b/lang/cem/libcc/gen/ttyslot.c @@ -1,11 +1,19 @@ #ifdef USG -/* some systems require inclusion of sys/types.h before utmp.h */ -#include -#include - /* system V, so no /etc/ttys file. In this case, scan the /etc/utmp file */ +struct utmp { + char ut_name[8]; + char ut_id[4]; + char ut_line[12]; + short ut_pid; + short ut_type; + struct exit_status { + short e_termination; + short e_exit; + } ut_exit; + long ut_time; +}; #define FILENAME "/etc/utmp" #else #define FILENAME "/etc/ttys" @@ -34,10 +42,12 @@ ttyslot() if ((fd = open(FILENAME, 0)) < 0) return 0; #ifdef USG while (read(fd, (char *) &buf, sizeof(buf)) == sizeof(buf)) { - if ((buf.ut_type == INIT_PROCESS || - buf.ut_type == LOGIN_PROCESS || - buf.ut_type == USER_PROCESS || - buf.ut_type == DEAD_PROCESS) && + /* processes associated with a terminal ... + unfortunately we cannot use the include file because + some systems have a different one ... + INIT_PROCESS, DEAD_PROCESS, USER_PROCESS, LOGIN_PROCESS + */ + if ((buf.ut_type >= 5 && buf.ut_type <= 8) && ! strncmp(buf.ut_line, p, sizeof(buf.ut_line))) { close(fd); return retval; From 388162ef561e8107de0f9429bbc619c3136aca17 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 24 Feb 1987 10:54:20 +0000 Subject: [PATCH 0867/1625] solved some problems with include files --- lang/cem/libcc/gen/tzset.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lang/cem/libcc/gen/tzset.c b/lang/cem/libcc/gen/tzset.c index d379627f..04a85f81 100644 --- a/lang/cem/libcc/gen/tzset.c +++ b/lang/cem/libcc/gen/tzset.c @@ -1,9 +1,20 @@ #ifdef BSD4_2 -#include +struct timeval { + long tv_sec, tv_usec; +}; +struct timezone { + int tz_minuteswest, tz_dsttime; +}; #else #ifndef USG #include -#include +struct timeb +{ + time_t time; + ushort millitm; + short timezone; + short dstflag; +}; #endif #endif From a67f2c7dc44127518b17a197d33785824b3d16fe Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 24 Feb 1987 11:17:50 +0000 Subject: [PATCH 0868/1625] Initial revision --- include/_tail_cc/sys/stat.h | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 include/_tail_cc/sys/stat.h diff --git a/include/_tail_cc/sys/stat.h b/include/_tail_cc/sys/stat.h new file mode 100644 index 00000000..86fd17c2 --- /dev/null +++ b/include/_tail_cc/sys/stat.h @@ -0,0 +1,48 @@ +struct stat { + dev_t st_dev; + ino_t st_ino; + u_short st_mode; + short st_nlink; + short st_uid; + short st_gid; + dev_t st_rdev; + off_t st_size; + time_t st_atime; +#ifdef BSD4_2 + long st_spare1; +#endif + time_t st_mtime; +#ifdef BSD4_2 + long st_spare2; +#endif + time_t st_ctime; +#ifdef BSD4_2 + long st_spare3; + long st_blksize; + long st_blocks; + long st_spare4[2]; +#endif +}; + +#define S_IFMT 0170000 +#define S_IFDIR 0040000 +#define S_IFCHR 0020000 +#define S_IFBLK 0060000 +#define S_IFREG 0100000 +#ifndef BSD4_2 +#ifndef USG +#define S_IFMPC 0030000 +#define S_IFMPB 0070000 +#else +#define S_IFIFO 0010000 +#endif +#else +#define S_IFLNK 0120000 +#define S_IFSOCK 0140000 +#endif +#define S_ISUID 0004000 +#define S_ISGID 0002000 +#define S_ISVTX 0001000 +#define S_IREAD 0000400 +#define S_IWRITE 0000200 +#define S_IEXEC 0000100 From c6a689bcbd3449694dffebb3359e8d3191a06c75 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 24 Feb 1987 12:38:21 +0000 Subject: [PATCH 0869/1625] An #endif was missing --- modules/src/object/rd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/src/object/rd.c b/modules/src/object/rd.c index aae7db6c..71156002 100644 --- a/modules/src/object/rd.c +++ b/modules/src/object/rd.c @@ -14,6 +14,7 @@ extern long lseek(); #define PARTDBUG 4 #else #define PARTDBUG 3 +#endif #define NPARTS (PARTDBUG + 1) static long offset[MAXSECT]; From ad48036f17964223d40176139c8b5cebc0f3b893 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 24 Feb 1987 13:10:59 +0000 Subject: [PATCH 0870/1625] *** empty log message *** --- include/_tail_cc/sys/dir.h | 17 +++++++++-------- lang/cem/libcc/gen/closedir.c | 3 ++- lang/cem/libcc/gen/opendir.c | 15 +++++++++++++++ lang/cem/libcc/gen/readdir.c | 2 +- lang/cem/libcc/gen/seekdir.c | 16 ++++++---------- 5 files changed, 33 insertions(+), 20 deletions(-) diff --git a/include/_tail_cc/sys/dir.h b/include/_tail_cc/sys/dir.h index 256222e0..ef327d41 100644 --- a/include/_tail_cc/sys/dir.h +++ b/include/_tail_cc/sys/dir.h @@ -1,8 +1,9 @@ #ifdef BSD4_2 -#include "/usr/include/sys/dir.h" +#define MAXNAMLEN 255 #else -#define DIRBLKSIZ 512 #define MAXNAMLEN 14 +#endif +#define DIRBLKSIZ 512 #undef DIRSIZ #define DIRSIZ(dp) \ ((sizeof(struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1+3)&~3)) @@ -17,7 +18,8 @@ struct _dirdesc { int dd_fd; long dd_loc; long dd_size; - char dd_buf[DIRBLKSIZ]; + char *dd_buf; + int dd_bsize; }; typedef struct _dirdesc DIR; @@ -25,10 +27,9 @@ typedef struct _dirdesc DIR; #ifndef NULL #define NULL 0 #endif -extern DIR *opendir(); +extern DIR *opendir(); extern struct direct *readdir(); -extern long telldir(); -extern seekdir(); +extern long telldir(); +extern seekdir(); #define rewinddir(dirp) seekdir((dirp), 0L) -extern closedir(); -#endif +extern closedir(); diff --git a/lang/cem/libcc/gen/closedir.c b/lang/cem/libcc/gen/closedir.c index 0fc2f75a..d7f71c64 100644 --- a/lang/cem/libcc/gen/closedir.c +++ b/lang/cem/libcc/gen/closedir.c @@ -10,5 +10,6 @@ register DIR *dirp; close(dirp->dd_fd); dirp->dd_fd = -1; dirp->dd_loc = 0; - free(dirp); + free(dirp->dd_buf); + free((char *)dirp); } diff --git a/lang/cem/libcc/gen/opendir.c b/lang/cem/libcc/gen/opendir.c index 35e5185b..f0174281 100644 --- a/lang/cem/libcc/gen/opendir.c +++ b/lang/cem/libcc/gen/opendir.c @@ -21,6 +21,21 @@ char *name; close (fd); return NULL; } + if ((int) stbuf.st_size == stbuf.st_size && + (dirp->dd_buf = malloc((unsigned) stbuf.st_size))) { + dirp->dd_bsize = stbuf.st_size; + } + else if (dirp->dd_buf = malloc(8*DIRBLKSIZ)) { + dirp->dd_bsize = 8 * DIRBLKSIZ; + } + else if (dirp->dd_buf = malloc(DIRBLKSIZ)) { + dirp->dd_bsize = DIRBLKSIZ; + } + else { + close(fd); + free((char *) dirp); + return NULL; + } dirp->dd_fd = fd; dirp->dd_loc = 0; return dirp; diff --git a/lang/cem/libcc/gen/readdir.c b/lang/cem/libcc/gen/readdir.c index 6679dd5b..fb8ea603 100644 --- a/lang/cem/libcc/gen/readdir.c +++ b/lang/cem/libcc/gen/readdir.c @@ -27,7 +27,7 @@ register DIR *dirp; for (;;) { if (dirp->dd_loc == 0) { dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf, - DIRBLKSIZ); + dirp->dd_bsize); if (dirp->dd_size <= 0) { dirp->dd_size = 0; return NULL; diff --git a/lang/cem/libcc/gen/seekdir.c b/lang/cem/libcc/gen/seekdir.c index ee2e0d2c..caaf9c7a 100644 --- a/lang/cem/libcc/gen/seekdir.c +++ b/lang/cem/libcc/gen/seekdir.c @@ -16,22 +16,18 @@ long loc; curloc = telldir(dirp); if (loc == curloc) return; - base = loc & ~(DIRBLKSIZ - 1); - offset = loc & (DIRBLKSIZ - 1); + offset = loc % dirp->dd_bsize; + base = loc - offset; if (dirp->dd_loc != 0 && offset != 0 && - (curloc & ~(DIRBLKSIZ-1)) == base) { + (curloc - (curloc % dirp->dd_bsize)) == base) { dirp->dd_loc = offset; return; } (void) lseek(dirp->dd_fd, base, 0); dirp->dd_loc = 0; dirp->dd_size = 0; - if (offset == 0) - (void) readdir(dirp); - else { - while (dirp->dd_loc < offset) { - if (readdir(dirp) == (struct direct *) 0) - return; - } + while (dirp->dd_loc < offset) { + if (readdir(dirp) == (struct direct *) 0) + return; } } From c93b184562b17ca437715a3aacb3b2699759d019 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 24 Feb 1987 13:47:23 +0000 Subject: [PATCH 0871/1625] *** empty log message *** --- lang/cem/ctest/makefile | 8 ++++++-- lang/cem/ctest/makefile.i86 | 8 ++++++-- lang/cem/ctest/makefile.int | 8 ++++++-- lang/cem/ctest/makefile.std | 8 ++++++-- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/lang/cem/ctest/makefile b/lang/cem/ctest/makefile index f3fe6bde..639bbc46 100644 --- a/lang/cem/ctest/makefile +++ b/lang/cem/ctest/makefile @@ -3,7 +3,11 @@ CEM=acc head: echo use run -diffs: $P.pcc.r $P.cc.r $P.cem.r +diffs: $P.cc.r $P.cem.r + echo two compiler diff + -diff $P.*.r + +diffs3: $P.pcc.r $P.cc.r $P.cem.r echo three compiler diff -diff3 $P.*.r | tee diffs egen: $P.e @@ -46,4 +50,4 @@ opr: make pr | opr clean: - -rm -f $P.[kmsoe] core a.out *.old + -rm -f $P.[kmsoe] $P.*.r core a.out *.old diff --git a/lang/cem/ctest/makefile.i86 b/lang/cem/ctest/makefile.i86 index aa5adf49..5fec701b 100644 --- a/lang/cem/ctest/makefile.i86 +++ b/lang/cem/ctest/makefile.i86 @@ -3,7 +3,11 @@ CEM=i86 -DNOFLOAT head: echo use run -diffs: $P.pcc.r $P.cc.r $P.cem.r +diffs: $P.cc.r $P.cem.r + echo two compiler diff + -diff $P.*.r + +diffs3: $P.pcc.r $P.cc.r $P.cem.r echo three compiler diff -diff3 $P.*.r | tee diffs egen: $P.e @@ -47,4 +51,4 @@ opr: make pr | opr clean: - -rm -f $P.[kmsoe] core a.out *.old + -rm -f $P.[kmsoe] $P.*.r core a.out *.old diff --git a/lang/cem/ctest/makefile.int b/lang/cem/ctest/makefile.int index 37d9fde5..82c77f0b 100644 --- a/lang/cem/ctest/makefile.int +++ b/lang/cem/ctest/makefile.int @@ -3,7 +3,11 @@ CEM=int -O head: echo use run -diffs: $P.pcc.r $P.cc.r $P.cem.r +diffs: $P.cc.r $P.cem.r + echo two compiler diff + -diff $P.*.r + +diffs3: $P.pcc.r $P.cc.r $P.cem.r echo three compiler diff -diff3 $P.*.r | tee diffs egen: $P.e @@ -46,4 +50,4 @@ opr: make pr | opr clean: - -rm -f $P.[kmsoe] core a.out *.old + -rm -f $P.[kmsoe] $P.*.r core a.out *.old diff --git a/lang/cem/ctest/makefile.std b/lang/cem/ctest/makefile.std index f3fe6bde..639bbc46 100644 --- a/lang/cem/ctest/makefile.std +++ b/lang/cem/ctest/makefile.std @@ -3,7 +3,11 @@ CEM=acc head: echo use run -diffs: $P.pcc.r $P.cc.r $P.cem.r +diffs: $P.cc.r $P.cem.r + echo two compiler diff + -diff $P.*.r + +diffs3: $P.pcc.r $P.cc.r $P.cem.r echo three compiler diff -diff3 $P.*.r | tee diffs egen: $P.e @@ -46,4 +50,4 @@ opr: make pr | opr clean: - -rm -f $P.[kmsoe] core a.out *.old + -rm -f $P.[kmsoe] $P.*.r core a.out *.old From 8007fc350d6eca88fa503b57e67ee710aa00e118 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 24 Feb 1987 15:32:48 +0000 Subject: [PATCH 0872/1625] vi Ma --- util/cpp/cpp.6 | 190 ++++++++----------------------------------------- 1 file changed, 31 insertions(+), 159 deletions(-) diff --git a/util/cpp/cpp.6 b/util/cpp/cpp.6 index 523ff376..3644ddd4 100644 --- a/util/cpp/cpp.6 +++ b/util/cpp/cpp.6 @@ -1,57 +1,47 @@ -.TH CPP VI +.TH CPP 6ACK .SH NAME cpp \- C Pre-Processor .SH SYNOPSIS -cpp [\-options] files +cpp [\-options] [ file ] .SH DESCRIPTION .I Cpp -reads one or more files, expands macros and include +reads a file, expands macros and include files, and writes an input file for the C compiler. -All output is to cpp.tmp (cpp.tmp.c on Unix). +All output is to standard output. .br -The following options are supported. On non-Unix systems, -options may be given in either case. -.IP -Ofile -Output to this file, instead of the default. -.IP -S -Output to stdout, instead of the default. -.IP -Idirectory -Add this directory to the list of +The following options are supported. +.IP -\fBI\fIdirectory\fR +.br +add this directory to the list of directories searched for #include "..." and #include <...> commands. Note that there is no space between the "-I" and the directory string. More than one -I command is permitted. -.IP -L -.I Cpp -transmits line number information to -the C compiler by outputting "#line " records. -If the -L option is given, this record will be transmitted -as "#", allowing the output of -.I cpp -to be input to a compiler -without an intervening preprocessor without error. -.IP -Dname=value -Define the name as if the programmer wrote +.IP -\fBI\fR +end the list of directories to be searched, and also do not look in +default places. +.IP -\fBD\fIname\fR=\fItext\fR .br -.nf - #define name value -.fi +define +.I name +as a macro with +.I text +as its replacement text. +.IP -\fBD\fIname\fR +the same as -\fBD\fIname\fR=1. +.IP +.IP -\fBU\fIname\fR .br -at the start of the first file. If "=value" is not -given, a value of "1" will be used. -.br -On non-unix systems, all alphabetic text will be forced -to upper-case. -.br -.IP -Uname -Undefine the name as if -.br -.nf - #undef name -.fi -.br -were given. On non-Unix systems, "name" will be forced to -upper-case. +undefine the macro name +.IR name . +.IP -\fBC\fR +leave comments in. By default, C-comments are deleted. +.IP -\fBP\fR +do not generate line directives +.IP -\fBM\fIn\fR +set maximum identifier length to +.IR n . +.PP The following names are always available unless undefined: .RS .IP __FILE__ @@ -63,121 +53,3 @@ The line number being compiled. The date and time of compilation as a Unix ctime quoted string (the trailing newline is removed). .RE -Thus, -.br -.nf - printf("Bug at line %s,", __LINE__); - printf(" source file %s", __FILE__); - printf(" compiled on %s", __DATE__); -.fi -.IP --Xnumber -Enable debugging code. If no value is -given, a value of 1 will be used. (For maintenence of -.I cpp -only.) -.SH "COMMENTS IN MACRO TEXT AND ARGUMENT CONCATENATION" -.br -Comments are removed from the input text. The comment -characters serve as an invisible token delimiter. Thus, -the macro -.nf - #define CAT(a, b) b/**/a - int value = CAT(1, 2); -.fi -Will generate "int value = 21;". -.br -A better way of concatenating arguments is as follows: -.nf - #define I(x)x - #define CAT(x,y)I(x)y - int value = CAT(1, 2); -.fi -If the above macros are defined without extraneous -spaces, they will be transportable to other implementations. -.br -.SH DIFFERENCES -.br -The following is a list of differences between this -pre-processor and the Unix V7 preprocessor which was -written by John Reiser. It is probably not complete. -.IP o -Macro formal parameters are recognized within -quoted strings and character constants in macro definitions. -For example, -.nf - #define foo(a) "Today is a" - printf(foo(tuesday)); -.fi -Would print "Today is tuesday". -.br -Recognition of formal parameters in macro replacement -strings is not permitted by the Draft ANSI C Standard. -It is permitted in this implementation if cpp was -compiled with the STRING_FORMAL parameter set appropriately. -.br -Unlike Reiser's implementation, the '\e' "quote next character" -does just that. I.e. -.nf - #define foo(a) "Today is \ea a" - printf(foo(tuesday)); -.fi -Would print "Today is a tuesday". Note that this may -not be portable. -.IP o -Reiser's implementation removes "escaped" linefeeds -(The two character sequence \e) within macros. This -implementation preserves them. For example, a macro which -generates control commands might be written -.nf - #define foo(a, b) \e - #define a b \e -.fi -.nf - foo(fubar, foobar) - int fubar; -.fi -The above would generate "int foobar;" and a warning message. -Reiser's scan is slightly different. -.SH "ANSI C STANDARD" -.I Cpp -implements most of the ANSI draft standard. -You should be aware of the following: -.IP o -In the draft standard, the \en (backslash-newline) -character is "invisible" to all processing. In this implementation, -it is invisible to strings, but acts a "whitespace" (token-delimiter) -outside of strings. This considerably simplifies error -message handling. -.IP o -The following extensions to C are processed by cpp: -.nf -.sp 1 -.ta 4n 27n - #elif expression (#else #if) - '\exNNN' (Hexadecimal constants) - '\ea' (Ascii BELL) - '\ev' (Ascii VT) - #if defined NAME (1 if defined, 0 if not) - #if defined (NAME) (1 if defined, 0 if not) - unary + (gag me with a spoon) -.fi -.IP o -The draft standard has extended C, adding a string -concatenation operator, where -.br -.nf - "foo" "bar" -.fi -.br -is regarded as the single string "foobar". It is not clear -from the draft standard whether this applies to pre-processing -if macro formals are recognized in strings. -.SH "ERROR MESSAGES" -.br -Many. -.br -.SH AUTHOR -.br -Martin Minow -.br From 4c068c7d5f0c7158c68f5f401d63b2521dc08e72 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 24 Feb 1987 15:36:34 +0000 Subject: [PATCH 0873/1625] *** empty log message *** --- util/cpp/Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/util/cpp/Makefile b/util/cpp/Makefile index e9936acb..dafae388 100644 --- a/util/cpp/Makefile +++ b/util/cpp/Makefile @@ -4,6 +4,7 @@ EMHOME=../.. MODULES=$(EMHOME)/modules MODULESLIB=$(MODULES)/lib BIN=$(EMHOME)/lib +MANDIR=$(EMHOME)/man # Some paths @@ -106,9 +107,12 @@ cfiles: hfiles LLfiles $(GSRC) install: all rm -f $(CEMPP) cp cpp $(CEMPP) + mr -f $(MANDIR)/cpp.6 + cp cpp.6 $(MANDIR)/cpp.6 cmp: all - cmp cpp $(CEMPP) + -cmp cpp $(CEMPP) + -cmp cpp.6 $(MANDIR)/cpp.6 pr: @pr $(PRFILES) From 879f8666e4b78b3adf44f21dba5be88b6596972b Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 24 Feb 1987 15:41:16 +0000 Subject: [PATCH 0874/1625] renamed a parameters because a local had the same name --- lang/cem/cemcom/eval.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lang/cem/cemcom/eval.c b/lang/cem/cemcom/eval.c index 8b7d9d7f..32b3f5b0 100644 --- a/lang/cem/cemcom/eval.c +++ b/lang/cem/cemcom/eval.c @@ -899,17 +899,17 @@ store_val(vl, tp) - static variable - local variable */ -load_val(expr, val) +load_val(expr, rlval) register struct expr *expr; /* expression containing the value */ - int val; /* generate either LVAL or RVAL */ + int rlval; /* generate either LVAL or RVAL */ { register struct type *tp = expr->ex_type; - int rvalue = (val == RVAL && expr->ex_lvalue != 0); + int rvalue = (rlval == RVAL && expr->ex_lvalue != 0); arith size = tp->tp_size; int tpalign = tp->tp_align; int al_on_word; register int inword, indword; - arith val = expr->VL_VALUE; + register arith val = expr->VL_VALUE; if (expr->VL_CLASS == Const) { if (rvalue) { /* absolute addressing */ From a0f21c5acd53696d1bb9f0d46def582e9f8fde54 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 24 Feb 1987 15:44:46 +0000 Subject: [PATCH 0875/1625] *** empty log message *** --- util/ncgg/ncgg.6 | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/util/ncgg/ncgg.6 b/util/ncgg/ncgg.6 index 11dc99fe..43e77dd0 100644 --- a/util/ncgg/ncgg.6 +++ b/util/ncgg/ncgg.6 @@ -1,5 +1,5 @@ .\" $Header$ -.TH CGG VI +.TH NCGG 6ACK .ad .SH NAME cgg \- Code table translating utility @@ -19,7 +19,7 @@ Generate pseudo code for table debugging. This gives better information when the resulting code generator is run with the debug flag on. It also generates the file lineset that can be used as the -bittable described under the -u option of em_cg(VI). +bittable described under the -u option of em_ncg(6). .IP -v Give statistics about table usage at end of program. Normally only the tables that have been used more than 75% @@ -31,9 +31,7 @@ code If the -c flag was given .br lineset If the -d flag was given .SH "SEE ALSO" -ack(I) -.br -em_cg(VI) +ack(1), em_ncg(6) .PD 0 .IP [1] A.S. Tanenbaum, Hans van Staveren, Ed Keizer and Johan From b300e35b4ca47103f546d415233e2c23920c3816 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 24 Feb 1987 15:47:05 +0000 Subject: [PATCH 0876/1625] Added ncgg.6 --- util/ncgg/Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/util/ncgg/Makefile b/util/ncgg/Makefile index 1e1a4461..5a81d70b 100644 --- a/util/ncgg/Makefile +++ b/util/ncgg/Makefile @@ -5,6 +5,7 @@ OFILES=cgg.o subr.o main.o coerc.o enterkeyw.o error.o emlookup.o expr.o instruc SOURCES=*.h cgg.y scan.l cvtkeywords keywords coerc.c emlookup.c error.c expr.c hall.c instruct.c iocc.c lookup.c main.c output.c set.c strlookup.c subr.c var.c EMHOME=../.. EMH=$(EMHOME)/h +MANDIR=$(EMHOME)/man CFLAGS=-O -I$(EMH) YFLAGS=-v -d LDFLAGS=-i @@ -16,9 +17,12 @@ cgg: cgg.o $(OFILES) output.o install: cgg rm -f $(EMHOME)/lib/ncgg cp cgg $(EMHOME)/lib/ncgg + rm -f $(MANDIR)/ncgg.6 + cp ncgg.6 $(MANDIR)/ncgg.6 cmp: cgg - cmp cgg $(EMHOME)/lib/ncgg + -cmp cgg $(EMHOME)/lib/ncgg + -cmp ncgg.6 $(MANDIR)/ncgg.6 debugcgg: cgg.o $(OFILES) debugoutput.o cc $(LDFLAGS) $(OFILES) debugoutput.o $(EMHOME)/lib/em_data.a -ll -o cgg From 406137be122ddb7b924fe73487614059139fab88 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 24 Feb 1987 16:07:04 +0000 Subject: [PATCH 0877/1625] *** empty log message *** --- lang/pc/pem/Makefile | 11 ++++++++--- lang/pc/pem/em_pem.6 | 8 ++++---- util/ass/Makefile | 7 ++++++- util/ass/em_ass.6 | 6 +++--- util/opt/Makefile | 3 +++ util/opt/em_opt.6 | 4 ++-- 6 files changed, 26 insertions(+), 13 deletions(-) diff --git a/lang/pc/pem/Makefile b/lang/pc/pem/Makefile index f1925c9e..c0b088fa 100644 --- a/lang/pc/pem/Makefile +++ b/lang/pc/pem/Makefile @@ -10,6 +10,7 @@ ACC=acc PEM=$d/lib/pc_pem PEM_OUT=$d/lib/pc_pem.out +MAN=$d/man/em_pem.6 HEAD=$h/em_spec.h $h/em_pseu.h $h/em_mnem.h $h/em_mes.h $h/pc_size.h LDFLAG=-i @@ -30,18 +31,22 @@ pem.m: pem.p $(HEAD) fi cmp: pem - cmp pem $(PEM) + -cmp pem $(PEM) + -cmp em_pem.6 $(MAN) install: pem + rm -f $(PEM) cp pem $(PEM) + rm -f $(MAN) + cp em_pem.6 $(MAN) distr: rm -f pem22.[mp] ; ln pem.p pem22.p apc -mpdp -c.m -I$h pem22.p ; rm -f pem22.p rm -f pem24.[mp] ; ln pem.p pem24.p - apc -mvax2 -c.m -I$h pem24.p ; rm -f pem24.p + apc -mm68k2 -c.m -I$h pem24.p ; rm -f pem24.p rm -f pem44.[mp] ; ln pem.p pem44.p - apc -mvax4 -c.m -I$h pem44.p ; rm -f pem44.p + apc -mm68k4 -c.m -I$h pem44.p ; rm -f pem44.p clean: -rm -f pem pem.out *.[os] *.old diff --git a/lang/pc/pem/em_pem.6 b/lang/pc/pem/em_pem.6 index 6943b467..36940e21 100644 --- a/lang/pc/pem/em_pem.6 +++ b/lang/pc/pem/em_pem.6 @@ -1,9 +1,9 @@ -.TH PC_PEM VI +.TH PC_PEM 6ACK .ad .SH NAME pc_pem \- Pascal to EM compiler .SH SYNOPSIS -/usr/em/lib/pc_pem compact errors +~em/lib/pc_pem compact errors .SH DESCRIPTION Pem is a Pascal compiler producing compact EM assembly code. The EM machine is described in [1]. @@ -39,13 +39,13 @@ ISO/TC97/SC5-N462, received November 1979. .IP [4] J.W.Stevenson "The Amsterdam Compiler Kit Pascal reference manual". .br -(try \fInroff /usr/em/doc/pcref.doc\fP) +(try \fInroff ~em/doc/pcref.doc\fP) .IP [5] \fIack\fP(I) .SH DIAGNOSTICS Compilation errors are written to the error file. Positive error numbers are used for irrecoverable errors, negative ones for warnings. -\fIAck\fP searches the file /usr/em/etc/pc_errors to find +\fIAck\fP searches the file ~em/etc/pc_errors to find the corresponding messages. .SH AUTHOR Johan Stevenson, Vrije Universiteit. diff --git a/util/ass/Makefile b/util/ass/Makefile index fafb0710..5f526c1f 100644 --- a/util/ass/Makefile +++ b/util/ass/Makefile @@ -2,6 +2,7 @@ d=../.. l=$d/lib h=$d/h +m=$d/man ASS_PATH=$l/em_ass SEP_OPT=-i @@ -14,10 +15,14 @@ clean: -rm -f ass-i ass-n *.o maktab *.old asstb.c install : all + rm -f $(ASS_PATH) cp ass$(SEP_OPT) $(ASS_PATH) + rm -f $m/em_ass.6 + cp em_ass.6 $m/em_ass.6 cmp : all - cmp ass$(SEP_OPT) $(ASS_PATH) + -cmp ass$(SEP_OPT) $(ASS_PATH) + -cmp em_ass.6 $m/em_ass.6 lint: ass00.c ass30.c ass40.c ass50.c ass60.c ass70.c \ ass80.c assci.c assda.c assrl.c asstb.c asscm.c diff --git a/util/ass/em_ass.6 b/util/ass/em_ass.6 index eeb753d9..b0f7fde3 100644 --- a/util/ass/em_ass.6 +++ b/util/ass/em_ass.6 @@ -1,10 +1,10 @@ .\" $Header$ -.TH EM_ASS VI +.TH EM_ASS 6ACK .ad .SH NAME em_ass \- EM assembler/loader .SH SYNOPSIS -/usr/em/lib/em_ass [options] argument ... +~em/lib/em_ass [options] argument ... .SH DESCRIPTION Em_ass assembles and links EM modules. Arguments may be flags, EM modules or libraries. @@ -48,7 +48,7 @@ Note that it is not possible to do a partial load; loading starts from compact EM code and produces binary EM code. No symbol table and no relocation bits are produced. .SH "SEE ALSO" -ack(I), arch(I) +ack(1), arch(1) .PD 0 .IP [1] A.S. Tanenbaum, Hans van Staveren, Ed Keizer and Johan diff --git a/util/opt/Makefile b/util/opt/Makefile index 24e402b7..1506642d 100644 --- a/util/opt/Makefile +++ b/util/opt/Makefile @@ -36,6 +36,7 @@ test: opt testopt cmp : all -cmp opt $(EMHOME)/lib/em_opt -cmp opt2 $(EMHOME)/lib/em_opt2 + -cmp em_opt.6 $(EMHOME)/man/em_opt.6 install:all -size opt $(EMHOME)/lib/em_opt @@ -44,6 +45,8 @@ install:all -size opt2 $(EMHOME)/lib/em_opt2 rm -f $(EMHOME)/lib/em_opt2 cp opt2 $(EMHOME)/lib/em_opt2 + rm -f $(EMHOME)/man/em_opt.6 + cp em_opt.6 $(EMHOME)/man/em_opt.6 pattern.c: patterns mktab /lib/cpp patterns | mktab > pattern.c diff --git a/util/opt/em_opt.6 b/util/opt/em_opt.6 index a8b4b9d2..7c351d8b 100644 --- a/util/opt/em_opt.6 +++ b/util/opt/em_opt.6 @@ -1,10 +1,10 @@ .\" $Header$ -.TH EM_OPT VI +.TH EM_OPT 6ACK .ad .SH NAME em_opt \- EM peephole optimizer .SH SYNOPSIS -/usr/em/lib/em_opt [-Ln] [ argument ] +~em/lib/em_opt [-Ln] [ argument ] .SH DESCRIPTION Em_opt reads a compact EM-program, argument or standard input, and produces another compact EM program on standard output From aef723333975c0ca4e14fecc3a6298ebbdf50d09 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 24 Feb 1987 16:36:22 +0000 Subject: [PATCH 0878/1625] Adapted to new distr3 --- distr/mkf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/distr/mkf b/distr/mkf index 145a2e32..2d8faace 100755 --- a/distr/mkf +++ b/distr/mkf @@ -1,10 +1,10 @@ -if co -q -rdistr2 $DESTDIR/$1/$2 >/dev/null 2>&1 +if co -q -rdistr3 $DESTDIR/$1/$2 >/dev/null 2>&1 then chmod +w $DESTDIR/$1/$2 elif co -q $DESTDIR/$1/$2 >/dev/null 2>&1 then chmod +w $DESTDIR/$1/$2 - echo -- $1/$2 no distr2 yet + echo -- $1/$2 no distr3 yet elif grep LIST .distr >/dev/null 2>&1 && (test "$2" = "`head -1 $DESTDIR/$1/LIST`") >/dev/null 2>&1 && ${DA-false} "$1" "$2" From a58e69e038de35377531955ef4342a77a73e0128 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 24 Feb 1987 16:41:01 +0000 Subject: [PATCH 0879/1625] many new things --- Action | 51 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/Action b/Action index 9cbfe00c..c99b53be 100644 --- a/Action +++ b/Action @@ -7,19 +7,25 @@ end name "EM definition" dir etc end -name "C preprocessor" -dir util/cpp +name "LL(1) Parser generator" +dir util/LLgen end name "EM definition library" dir util/data end name "Modules" -dir modules +dir modules/src indir end +name "C preprocessor" +dir util/cpp +end name "C utilities" dir util/cmisc end +name "ACK object utilities" +dir util/amisc +end name "Encode/Decode" dir util/misc end @@ -32,6 +38,10 @@ end name "EM Peephole optimizer" dir util/opt end +name "EM Global optimizer" +dir util/ego +indir +end name "ACK archiver" dir util/arch end @@ -41,14 +51,17 @@ end name "Bootstrap for backend tables" dir util/cgg end -name "LL(1) Parser generator" -dir util/LLgen -end name "Bootstrap for newest form of backend tables" dir util/ncgg end +name "LED link editor" +dir util/led +end +name "TOPGEN target optimizer generator" +dir util/topgen +end name "C frontend" -dir lang/cem/comp +dir lang/cem/cemcom end name "Basic frontend" dir lang/basic/src @@ -89,10 +102,6 @@ name "4-4 Interpreter support" dir mach/int44 indir end -name "IBM PC/IX support" -dir mach/ix -indir -end name "Motorola 68000 2-4 support" dir mach/m68k2 indir @@ -117,18 +126,30 @@ name "PMDS 4/4 support" dir mach/pmds4 indir end +name "Mantra 68000 System V.0 support" +dir mach/mantra +indir +end +name "Mantra 68000 System V.0 4/4 support" +dir mach/mantra4 +indir +end name "Signetics 2650 support" dir mach/s2650 indir end -name "Vax 2-4 support" -dir mach/vax2 -indir -end name "Vax 4-4 support" dir mach/vax4 indir end +name "M68020 System V/68 support" +dir mach/m68020 +indir +end +name "Sun 3 M68020 support" +dir mach/sun3 +indir +end name "Z80 support" dir mach/z80 indir From 01708de3fe2a88fcd256381e98241bd276d58389 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 24 Feb 1987 17:05:53 +0000 Subject: [PATCH 0880/1625] Initial revision --- lang/occam/comp/Makefile | 27 ++ lang/occam/comp/builtin.c | 74 +++++ lang/occam/comp/code.c | 607 +++++++++++++++++++++++++++++++++ lang/occam/comp/code.h | 19 ++ lang/occam/comp/em.c | 405 ++++++++++++++++++++++ lang/occam/comp/em.h | 21 ++ lang/occam/comp/expr.c | 471 ++++++++++++++++++++++++++ lang/occam/comp/expr.h | 61 ++++ lang/occam/comp/keytab.c | 82 +++++ lang/occam/comp/lex.l | 344 +++++++++++++++++++ lang/occam/comp/occam.g | 684 ++++++++++++++++++++++++++++++++++++++ lang/occam/comp/report.c | 19 ++ lang/occam/comp/sizes.h | 5 + lang/occam/comp/symtab.c | 202 +++++++++++ lang/occam/comp/symtab.h | 91 +++++ lang/occam/comp/token.h | 11 + 16 files changed, 3123 insertions(+) create mode 100644 lang/occam/comp/Makefile create mode 100644 lang/occam/comp/builtin.c create mode 100644 lang/occam/comp/code.c create mode 100644 lang/occam/comp/code.h create mode 100644 lang/occam/comp/em.c create mode 100644 lang/occam/comp/em.h create mode 100644 lang/occam/comp/expr.c create mode 100644 lang/occam/comp/expr.h create mode 100644 lang/occam/comp/keytab.c create mode 100644 lang/occam/comp/lex.l create mode 100644 lang/occam/comp/occam.g create mode 100644 lang/occam/comp/report.c create mode 100644 lang/occam/comp/sizes.h create mode 100644 lang/occam/comp/symtab.c create mode 100644 lang/occam/comp/symtab.h create mode 100644 lang/occam/comp/token.h diff --git a/lang/occam/comp/Makefile b/lang/occam/comp/Makefile new file mode 100644 index 00000000..e8608d09 --- /dev/null +++ b/lang/occam/comp/Makefile @@ -0,0 +1,27 @@ +GFILES= occam.g +PRIMARY= occam.o Lpars.o keytab.o lex.yy.o code.o em.o +SECUNDARY= symtab.o expr.o builtin.o +TERTIARY= report.o +LLOPT= +LIBRARY= -lln libemk.a libsystem.a + +all: + make dummy + make oc + +dummy: $(GFILES) + LLgen $(LLOPT) $(GFILES) + touch dummy + +oc: $(PRIMARY) $(SECUNDARY) $(TERTIARY) + $(CC) -o oc $(PRIMARY) $(SECUNDARY) $(TERTIARY) $(LIBRARY) + +lex.yy.c: lex.l + lex lex.l + +$(PRIMARY): Lpars.h +occam.o keytab.o: token.h +occam.o $(SECUNDARY): symtab.h expr.h +$(PRIMARY) $(SECUNDARY): sizes.h +occam.o code.o: code.h +code.o em.o: em.h diff --git a/lang/occam/comp/builtin.c b/lang/occam/comp/builtin.c new file mode 100644 index 00000000..f1c7a913 --- /dev/null +++ b/lang/occam/comp/builtin.c @@ -0,0 +1,74 @@ +#include +#include "symtab.h" +#include "expr.h" +#include "sizes.h" + +void init_builtins() +/* Insert all builtin names into the outermost symbol table (first statement + * is sym_down() ). Note that this table is never destroy()ed, so static + * initializers may be used. + */ +{ + union type_info info; + + static char file[]="file"; + + static struct par_list + open_list[] = { + { &open_list[1], nil, T_VAR }, /* File descriptor */ + { &open_list[2], nil, T_VALUE|T_ARR }, /* File name */ + { nil, nil, T_VALUE|T_ARR } /* "r", "w", "a" */ + }, + close_list[]= { + { nil, nil, T_VALUE } /* File descriptor */ + }, + exit_list[]= { + { nil, nil, T_VALUE } /* Exit code */ + }; + + sym_down(); /* Add level of symbols above all others */ + + /* CHAN file[20], input=file[0], output=file[1], error=file[2]: */ + + info.vc.st.builtin=file; + info.vc.offset=0; + insert(file, T_CHAN|T_ARR|T_BUILTIN, _NFILE, info); + + info.vc.st.builtin=file; + info.vc.offset=0; + insert("input", T_CHAN|T_BUILTIN, 1, info); + + info.vc.st.builtin=file; + info.vc.offset=wz+pz; + insert("output", T_CHAN|T_BUILTIN, 1, info); + + info.vc.st.builtin=file; + info.vc.offset=2*(wz+pz); + insert("error", T_CHAN|T_BUILTIN, 1, info); + + /* DEF EOF= -1, TEXT= -2, RAW= -3: */ + + info.const=new_const(-1L); + insert("EOF", T_CONST|T_BUILTIN, 0, info); + + info.const=new_const(-2L); + insert("TEXT", T_CONST|T_BUILTIN, 0, info); + + info.const=new_const(-3L); + insert("RAW", T_CONST|T_BUILTIN, 0, info); + + /* PROC open(VAR fd, VALUE name[], mode[])= .... : */ + info.proc.st.builtin="b_open"; + info.proc.pars=open_list; + insert("open", T_PROC|T_BUILTIN, 0, info); + + /* PROC close(VALUE fd)= .... : */ + info.proc.st.builtin="b_close"; + info.proc.pars=close_list; + insert("close", T_PROC|T_BUILTIN, 0, info); + + /* PROC exit(VALUE code)= .... : */ + info.proc.st.builtin="b_exit"; + info.proc.pars=exit_list; + insert("exit", T_PROC|T_BUILTIN, 0, info); +} diff --git a/lang/occam/comp/code.c b/lang/occam/comp/code.c new file mode 100644 index 00000000..d8a75237 --- /dev/null +++ b/lang/occam/comp/code.c @@ -0,0 +1,607 @@ +#include "em.h" +#include "expr.h" +#include "symtab.h" +#include "sizes.h" +#include "Lpars.h" +#include "code.h" + +extern err; + +static void subscript(); +enum addr_val { address, value }; + +void code_val(e) register struct expr *e; +/* Compile e for its value, which is put on the stack. */ +{ + register struct expr *left, *right; + + if (err) return; + + switch(e->kind) { + case E_NODE: + left=e->u.node.left; + right=e->u.node.right; + + switch (e->u.node.op) { + case '+': + case '-': + case '*': + case '/': + case BS: + code_val(left); + code_val(right); + xxi(e->u.node.op); + break; + case '<': + case '>': + case LE: + case GE: + case NE: + case '=': + code_val(left); + code_val(right); + cmi(); + Txx(e->u.node.op); + break; + case AFTER: + code_val(left); + code_val(right); + xxi('-'); + cvw(); + tst(); + Txx('>'); + break; + case BA: + code_val(left); + code_val(right); + and(); + break; + case BO: + code_val(left); + code_val(right); + ior(); + break; + case BX: + code_val(left); + code_val(right); + xor(); + break; + case AND: + case OR: { + int T=0, F=0, L=0; + + code_bool(e, positive, &T, &F); + Label(T); + Loc(-1L); + branch(&L); + Label(F); + Loc(0L); + Label(L); + }break; + case LS: + code_val(left); + code_val(right); + cvw(); + sli(); + break; + case RS: + code_val(left); + code_val(right); + cvw(); + sri(); + break; + case '~': + code_val(left); + ngi(); + break; + case NOT: + code_val(left); + com(); + break; + case '[': + subscript(e, value); + break; + } + break; + case E_VAR: { + register struct symbol *var=e->u.var; + + if (var->type&T_BUILTIN) + Loe(var->info.vc.st.builtin, var->info.vc.offset); + else + if (var->info.vc.st.level==curr_level) + if (var->type&T_PARAM && (var->type&T_TYPE)!=T_VALUE) + Lil(var->info.vc.offset); + else + Lol(var->info.vc.offset); + else { + if (var->info.vc.offset<0) + lxl(curr_level-var->info.vc.st.level); + else + lxa(curr_level-var->info.vc.st.level); + if (var->type&T_PARAM && (var->type&T_TYPE)!=T_VALUE) + Lif(var->info.vc.offset); + else + Lof(var->info.vc.offset); + } + }break; + case E_CONST: + Loc(e->u.const); + break; + case E_NOW: + cal("now"); + lfr(vz); + break; + } +} + +static void subscript(e, av) register struct expr *e; enum addr_val av; +/* Produce code to compute the address or value of e->left[e->right] or + * the address of e->left[e->right->left FOR e->right->right]. + */ +{ + register char *des; + register struct expr *left; + register struct expr *index; + + code_addr(left=e->u.node.left); + + if ((index=e->u.node.right)->kind==E_NODE && index->u.node.op==FOR) + index=index->u.node.left; + + if (left->arr_siz==0) { + if ((left->type&T_TYPE)==T_CHAN) + des="maxcdes"; + else + des= e->type&T_BYTE ? "maxbdes" : "maxwdes"; + } else { + register lsiz=left->arr_siz; + + if (left->type&T_BYTE && !(e->type&T_BYTE)) + lsiz/=vz; + else + if (!(left->type&T_BYTE) && e->type&T_BYTE) + lsiz*=vz; + + if (e->type&T_ARR) + lsiz-=(e->arr_siz -1); + + if (constant(index)) { + if (index->u.const<0 || index->u.const>=lsiz) { + warning("constant index outside vector"); + lin(); + loc(0); + trp(); + } + } else { + loc(lsiz); + + if ((left->type&T_TYPE)==T_CHAN) + des="chandes"; + else + des= e->type&T_BYTE ? "bytedes" : "worddes"; + ste(des, wz); + } + } + if (constant(index)) { + register offset=index->u.const; + + if ((left->type&T_TYPE)==T_CHAN) + offset*=(wz+vz); + else + if ( !(e->type&T_BYTE) ) + offset*=vz; + + if (av==address) + adp(offset); + else { + if (e->type&T_BYTE) { + adp(offset); + loi(1); + cwv(); + } else + Lof(offset); + } + } else { + code_val(index); + cvw(); + lin(); + lae(des, 0); + if (av==address) { + aar(); + } else { + lar(); + if (e->type&T_BYTE) cwv(); + } + } +} + +void code_addr(e) register struct expr *e; +/* The address of e is wat we want. */ +{ + if (err) return; + + switch(e->kind) { + case E_NODE: + subscript(e, address); + break; + case E_VAR: { /* variable or channel */ + register struct symbol *var=e->u.var; + + if (var->type&T_BUILTIN) + lae(var->info.vc.st.builtin, var->info.vc.offset); + else + if (var->info.vc.st.level==curr_level) + if (var->type&T_PARAM + && (var->type&(T_TYPE|T_ARR))!=T_VALUE) + Lolp(var->info.vc.offset); + else + lal(var->info.vc.offset); + else { + if (var->info.vc.offset<0) + lxl(curr_level-var->info.vc.st.level); + else + lxa(curr_level-var->info.vc.st.level); + if (var->type&T_PARAM + && (var->type&(T_TYPE|T_ARR))!=T_VALUE) + Lofp(var->info.vc.offset); + else + adp(var->info.vc.offset); + } + } break; + case E_TABLE: + case E_BTAB: + laedot(e->u.tab); + break; + } +} + +void code_bool(e, pos, T, F) + register struct expr *e; + register pos; + register int *T, *F; +/* if e = pos then + fall through or jump to T; + else + jump to F; + fi + */ +{ + register Default=0; + + if (err) return; + + if (e->kind==E_NODE) { + register struct expr *left=e->u.node.left; + register struct expr *right=e->u.node.right; + + switch(e->u.node.op) { + case '<': + case '>': + case LE: + case GE: + case NE: + case '=': + case AFTER: + code_val(left); + code_val(right); + bxx(pos, e->u.node.op, new_label(F)); + break; + case AND: + case OR: + if ((e->u.node.op==AND && pos) + || (e->u.node.op==OR && !pos) + ) { + int L=0; + code_bool(left, pos, &L, F); + Label(L); + code_bool(right, pos, T, F); + } else { + int L=0; + code_bool(left, !pos, &L, T); + Label(L); + code_bool(right, pos, T, F); + } + break; + case NOT: + code_bool(left, !pos, T, F); + break; + default: + Default=1; + } + } else + Default=1; + + if (Default) { + code_val(e); + if (vz>wz) { + ldc0(); + cmi(); + } else + tst(); + if (pos) zeq(new_label(F)); else zne(new_label(F)); + } +} + +void code_assignment(e) register struct expr *e; +/* e->left := e->right */ +{ + register struct expr *left=e->u.node.left; + register struct expr *right=e->u.node.right; + + if (left->type&T_ARR) { + register siz=left->arr_siz; + + code_addr(right); + code_addr(left); + blm(left->type&T_BYTE ? siz : siz*vz); + } else { + code_val(right); + code_addr(left); + sti(left->type&T_BYTE ? 1 : vz); + } +} + +void code_input(e) register struct expr *e; +/* Input one v from c ? v0; v1; ... */ +{ + if (e==nil) { + lae("any", 0); + cal("chan_in"); + asp(pz); + } else + if (e->type&T_ARR) { + loc(e->arr_siz); + code_addr(e); + cal(e->type&T_BYTE ? "c_ba_in" : "c_wa_in"); + asp(pz+wz); + } else { + code_addr(e); + cal(e->type&T_BYTE ? "cbyte_in" : "chan_in"); + asp(pz); + } +} + +void code_output(e) register struct expr *e; +/* Output one e from c ? e0; e1; ... */ +{ + if (e==nil) { + Loc(0L); + cal("chan_out"); + asp(vz); + } else + if (e->type&T_ARR) { + loc(e->arr_siz); + code_addr(e); + cal(e->type&T_BYTE ? "c_ba_out" : "c_wa_out"); + asp(pz+wz); + } else { + code_val(e); + cal("chan_out"); + asp(vz); + } +} + +void code_any(e, NO) register struct expr *e; int *NO; +/* Test if the channel (push address on stack) has input. If not so remove the + * channel pointer and jump to NO. Otherwise input values. + */ +{ + int YES=0; + register struct expr_list *elp; + + if (err) return; + + code_addr(e->u.io.chan); + cal("chan_any"); + lfr(wz); + tst(); + zne(new_label(&YES)); + asp(pz); + branch(NO); + Label(YES); + elp=e->u.io.args; + while (elp!=nil) { + code_input(elp->arg); + elp=elp->next; + } + asp(pz); +} + +void code_void(e) register struct expr *e; +/* Assignment, I/O, or procedure call. */ +{ + if (err) return; + + switch (e->kind) { + case E_NODE: /* Must be assignment */ + code_assignment(e); + break; + case E_IO: { + register struct expr_list *elp; + + code_addr(e->u.io.chan); + + elp=e->u.io.args; + while (elp!=nil) { + if (e->u.io.out) + code_output(elp->arg); + else + code_input(elp->arg); + elp=elp->next; + } + asp(pz); + } + break; + case E_CALL: { + register size=0; + register struct expr_list *elp=e->u.call.args; + register struct symbol *proc=e->u.call.proc->u.var; + register struct par_list *pars=proc->info.proc.pars; + + while (elp!=nil) { + if (pars->type==T_VALUE) { + code_val(elp->arg); + size+=vz; + } else { + code_addr(elp->arg); + size+=pz; + } + elp=elp->next; + pars=pars->next; + } + if (proc->type&T_BUILTIN) { + cal(proc->info.proc.st.builtin); + asp(size); + } else { + if (proc->info.proc.st.level>curr_level) { + /* Call down */ + lor0(); + } else + if (proc->info.proc.st.level==curr_level) { + /* Call at same level */ + Lolp(0); + } else { + /* Call up */ + lxa(curr_level-proc->info.proc.st.level); + loi(pz); + } + cal(proc_label(proc->info.proc.label, proc->name)); + asp(size+pz); + if (proc->info.proc.file!=curr_file) fil(); + } + } break; + } +} + +void prologue(proc) register struct symbol *proc; +/* Open up the scope for a new proc definition. */ +{ + static P=0; + + if (err) return; + + proc->info.proc.st.level= ++curr_level; + proc->info.proc.file= curr_file; + proc->info.proc.label= ++P; + curr_offset=min_offset=0; + pro(proc_label(proc->info.proc.label, proc->name)); + if (curr_level==1) fil(); +} + +void epilogue(proc) register struct symbol *proc; +/* Close the scope of a proc def. */ +{ + if (err) return; + + curr_level--; + ret(0); + _end(-min_offset); +} + +void rep_init(v, e1, e2, r_info) + struct symbol *v; + register struct expr *e1, *e2; + register struct replicator *r_info; +/* Compile v=[e1 FOR e2]. Info tells rep_test what decisions rep_init makes. */ +{ + if (err) return; + + r_info->BEGIN=r_info->END=0; + + code_val(e1); + Stl(v->info.vc.offset); + + if (!constant(e1) || !constant(e2)) { + if (constant(e2) && word_constant(e2->u.const)) { + r_info->counter=memory(wz); + loc((int) e2->u.const); + stl(r_info->counter); + } else { + r_info->counter=memory(vz); + code_val(e2); + Stl(r_info->counter); + } + } + if (!constant(e2) || e2->u.const<=0L) + branch(&r_info->END); + Label(new_label(&r_info->BEGIN)); +} + +void rep_test(v, e1, e2, r_info) + register struct symbol *v; + register struct expr *e1, *e2; + register struct replicator *r_info; +{ + if (err) return; + + Inl(v->info.vc.offset); + + if (constant(e1) && constant(e2)) { + Lol(v->info.vc.offset); + Loc(e1->u.const+e2->u.const); + if (vz>wz) { + cmi(); + zlt(r_info->BEGIN); + } else + blt(r_info->BEGIN); + Label(r_info->END); + } else { + if (constant(e2) && word_constant(e2->u.const)) { + del(r_info->counter); + Label(r_info->END); + lol(r_info->counter); + tst(); + } else { + Del(r_info->counter); + Label(r_info->END); + Lol(r_info->counter); + if (vz>wz) { + ldc0(); + cmi(); + } else + tst(); + } + zgt(r_info->BEGIN); + } +} + +void chan_init(info, arr_siz) union type_info *info; int arr_siz; +/* Garbage disposal unit for fresh channels. */ +{ + if (err) return; + + loc(arr_siz); + lal(info->vc.offset); + cal("c_init"); + asp(wz+pz); +} + +void leader() +{ + init(); + openfile((char *) nil); + magic(); + meswp(); + maxdes(); +} + +void header() +{ + exp("main"); + pro("main"); + init_rt(); + main_fil(); +} + +void trailer() +{ + if (err) + meserr(); + else { + loc(0); + ret(wz); + _end(-min_offset); + } + closefile(); +} diff --git a/lang/occam/comp/code.h b/lang/occam/comp/code.h new file mode 100644 index 00000000..34f9dd0d --- /dev/null +++ b/lang/occam/comp/code.h @@ -0,0 +1,19 @@ +struct replicator { /* Info transferred from rep_init to rep_test */ + int counter; + int BEGIN; + int END; +}; + +void rep_init(), rep_test(); + +void code_val(), code_addr(), code_void(); +void code_assignment(), code_input(), code_any(), code_output(); + +void code_bool(); +#define positive 1 /* Use positive logic for boolean expression */ +#define negative 0 /* Use negative logic, i.e. 0 = true */ + +void epilogue(), prologue(); +void leader(), header(), trailer(); + +void chan_init(); diff --git a/lang/occam/comp/em.c b/lang/occam/comp/em.c new file mode 100644 index 00000000..814b1c1f --- /dev/null +++ b/lang/occam/comp/em.c @@ -0,0 +1,405 @@ +#include +#include "sizes.h" +#include "Lpars.h" +#include "em_arith.h" +#include "em_label.h" +#include "em.h" + +/* This file is used to shield code.c as much as possible from em dependant + * details. It introduces some call overhead but not enough for a coffee + * break. (Sorry) + * Note that functions with a leading upper case letter normally decide between + * word or double word arith. + */ + +int wz, pz; +static Lab=0; +char *malloc(); + +void init() +{ + C_init((arith) wz, (arith) pz); +} + +void openfile(file) char *file; +{ + C_open(file); +} + +void meswp() +{ + C_mes_begin(2); + C_cst((arith) wz); + C_cst((arith) pz); + C_mes_end(); +} + +void maxdes() +{ + C_df_dnam("maxcdes"); + rom(wz, 0L); rom(wz, -1L); rom(wz, (long) (wz+pz)); + C_df_dnam("maxwdes"); + rom(wz, 0L); rom(wz, -1L); rom(wz, (long) vz); + C_df_dnam("maxbdes"); + rom(wz, 0L); rom(wz, -1L); rom(wz, 1L); +} + +int new_label(L) register *L; +{ + if (*L==0) *L= ++Lab; + return *L; +} + +void Label(L) register L; +{ + if (L!=0) C_df_ilb((label) L); +} + +static Dot_label=0; + +int new_dot_label(L) int *L; +{ + return *L= ++Dot_label; +} + +void dot_label(L) int L; +{ + C_df_dlb((label) L); +} + +void branch(L) int *L; +{ + C_bra((label) new_label(L)); +} + +char *proc_label(L, name) register L; register char *name; +{ + static char *lab=nil; + register char *n; + + if (lab!=nil) free(lab); + + lab=malloc(strlen(name)+(1+sizeof(int)*3+1)); + /* That is: P\0 */ + + sprintf(lab, "P%d", L); + + n=lab+strlen(lab); + + while (*name!=0) { + *n++ = *name=='.' ? '_' : *name; + name++; + } + *n=0; + return lab; +} + +void magic() /* magic? should be called invisible */ +{ + C_magic(); +} + +void cwv() +{ + if (vz>wz) { + C_loc((arith) wz); + C_loc((arith) vz); + C_cii(); + } +} + +void cvw() +{ + if (vz>wz) { + C_loc((arith) vz); + C_loc((arith) wz); + C_cii(); + } +} + +void Loc(const) long const; +{ + if (vz>wz) C_ldc((arith) const); else C_loc((arith) const); +} + +void Lol(offset) int offset; +{ + if (vz>wz) C_ldl((arith) offset); else C_lol((arith) offset); +} + +void Lolp(offset) int offset; +{ + if (pz>wz) C_ldl((arith) offset); else C_lol((arith) offset); +} + +void Lil(offset) register offset; +{ + if (vz>wz) { + Lolp(offset); + C_loi((arith) vz); + } else + C_lil((arith) offset); +} + +void Lof(offset) int offset; +{ + if (vz>wz) C_ldf((arith) offset); else C_lof((arith) offset); +} + +void Lofp(offset) int offset; +{ + if (pz>wz) C_ldf((arith) offset); else C_lof((arith) offset); +} + +void Lif(offset) register offset; +{ + Lofp(offset); + C_loi((arith) vz); +} + +void Stl(offset) int offset; +{ + if (vz>wz) C_sdl((arith) offset); else C_stl((arith) offset); +} + +void Inl(offset) register offset; +{ + if (vz>wz) { + C_ldl((arith) offset); + C_ldc((arith) 1); + C_adi((arith) vz); + C_sdl((arith) offset); + } else + C_inl((arith) offset); +} + +void Del(offset) register offset; +{ + if (vz>wz) { + C_ldl((arith) offset); + C_ldc((arith) 1); + C_sbi((arith) vz); + C_sdl((arith) offset); + } else + C_del((arith) offset); +} + +void Loe(name, offset) char *name; int offset; +{ + if (vz>wz) + C_lde_dnam(name, (arith) offset); + else + C_loe_dnam(name, (arith) offset); +} + +typedef int (*pfi)(); + +static int operators[]= { '<', '>', '=', GE, LE, NE }; + +extern C_blt(), C_bgt(), C_beq(), C_bge(), C_ble(), C_bne(); +extern C_tlt(), C_tgt(), C_teq(), C_tge(), C_tle(), C_tne(); +extern C_zlt(), C_zgt(), C_zeq(), C_zge(), C_zle(), C_zne(); + +static pfi C_bxx[]= { C_blt, C_bgt, C_beq, C_bge, C_ble, C_bne }; +static pfi C_txx[]= { C_tlt, C_tgt, C_teq, C_tge, C_tle, C_tne }; +static pfi C_zxx[]= { C_zlt, C_zgt, C_zeq, C_zge, C_zle, C_zne }; + +void bxx(pos, op, L) register pos, op, L; +{ + register i; + + if (op==AFTER) { + C_sbi((arith) vz); + if (vz>wz) { + C_ldc((arith) 0); + C_cmi((arith) vz); + } + if (pos) C_zle((label) L); else C_zgt((label) L); + } else { + for (i=0; operators[i]!=op; i++) ; + if (pos && (i+=3)>=6) i-=6; + if (vz>wz) { + C_cmi((arith) vz); + (C_zxx[i])((label) L); + } else { + (C_bxx[i])((label) L); + } + } +} + +void Txx(op) register int op; +{ + register i; + + for (i=0; operators[i]!=op; i++) ; + + (C_txx[i])(); + cwv(); + C_ngi((arith) vz); +} + +extern C_adi(), C_sbi(), C_mli(), C_dvi(), C_rmi(); + +void xxi(op) register op; +{ + static int operators[]= { '+', '-', '*', '/', BS }; + static pfi C_xxi[]= { C_adi, C_sbi, C_mli, C_dvi, C_rmi }; + register i; + + for (i=0; operators[i]!=op; i++) ; + + (C_xxi[i])((arith) vz); +} + +void aar() { C_aar((arith) wz); } +void adp(offset) int offset; { C_adp((arith) offset); } +void and() { C_and((arith) vz); } +void asp(size) int size; { C_asp((arith) size); } +void blm(size) int size; { C_blm((arith) size); } +void blt(lab) int lab; { C_blt((label) lab); } +void cal(lab) char *lab; { C_cal(lab); } +void cmi() { C_cmi((arith) vz); } +void com() { C_com((arith) vz); } +void del(offset) int offset; { C_del((arith) offset); } +void _end(size) int size; { C_end((arith) size); } +void exp(lab) char *lab; { C_exp(lab); } +void ior() { C_ior((arith) vz); } +void lae(lab, offset) char *lab; int offset; + { C_lae_dnam(lab, (arith) offset); } +void laedot(lab) int lab; { C_lae_dlb((label) lab, (arith) 0); } +void lal(offset) int offset; { C_lal((arith) offset); } +void lar() { C_lar((arith) wz); } +void ldc0() { C_ldc((arith) 0); } +void ldl(offset) int offset; { C_ldl((arith) offset); } +void lfr(size) int size; { C_lfr((arith) size); } +void loc(cst) int cst; { C_loc((arith) cst); } +void loi(size) int size; { C_loi((arith) size); } +void lol(offset) int offset; { C_lol((arith) offset); } +void lor0() { C_lor((arith) 0); } +void lxa(offset) int offset; { C_lxa((arith) offset); } +void lxl(offset) int offset; { C_lxl((arith) offset); } +void meserr() { C_mes_begin(0); C_mes_end(); } +void ngi() { C_ngi((arith) vz); } +void pro(lab) char *lab; { C_pro_narg(lab); } +void ret(size) int size; { C_ret((arith) size); } +void init_rt() { C_cal("init"); } +void sli() { C_sli((arith) vz); } +void sri() { C_sri((arith) vz); } +void ste(lab, offset) char *lab; int offset; + { C_ste_dnam(lab, (arith) offset); } +void sti(size) int size; { C_sti((arith) size); } +void stl(offset) int offset; { C_stl((arith) offset); } +void trp() { C_trp(); } +void tst() { /* No flags in EM */ } +void xor() { C_xor((arith) vz); } +void zeq(lab) int lab; { C_zeq((label) lab); } +void zgt(lab) int lab; { C_zgt((label) lab); } +void zlt(lab) int lab; { C_zlt((label) lab); } +void zne(lab) int lab; { C_zne((label) lab); } + +char *itoa(i) long i; +{ + static char a[sizeof(long)*3]; + sprintf(a, "%D", i); + return a; +} + +void rom(size, c) int size; long c; +{ + C_rom_icon(itoa(c), (arith) size); +} + +void lin() +{ + static oldline=0; + extern yylineno; + + if (yylineno!=oldline) + C_lin((arith) (oldline=yylineno)); +} + +static struct ftree { + char *file; + int lab; + struct ftree *left, *right; +} std_f = { "stdin", 0, nil, nil }, *curr_f= &std_f, *main_f=nil; + +char *curr_file="stdin"; + +static void do_fil(f) struct ftree *f; +{ + if (f->lab==0) { + dot_label(new_dot_label(&f->lab)); + C_rom_scon(f->file, (arith) strlen(f->file)); + } + C_fil_dlb((label) f->lab); +} + +void fil() +{ + do_fil(curr_f); +} + +void main_fil() +{ + do_fil(main_f==nil ? &std_f : main_f); +} + +int set_file(f) char *f; +{ + char *strcpy(); + static struct ftree *ftop=nil; + register struct ftree *pf, **apf= &ftop; + register cmp; + + while ((pf= *apf)!=nil && (cmp=strcmp(f, pf->file))!=0) + apf= cmp<0 ? &pf->left : &pf->right; + + if (pf==nil) { + *apf= pf= (struct ftree *) malloc(sizeof *pf); + pf->file=strcpy(malloc(strlen(f)+1), f); + pf->lab=0; + pf->left=pf->right=nil; + } + curr_f=pf; + curr_file=pf->file; + if (main_f==nil) { + main_f=curr_f; + return 0; + } else + return curr_f!=main_f; +} + +void par_begin() +{ + C_lal((arith) curr_offset); + C_cal("pc_begin"); + C_asp((arith) pz); +} + +void par_fork(NONZERO) int *NONZERO; +{ + C_cal("pc_fork"); + C_lfr((arith) wz); + C_zne((label) new_label(NONZERO)); +} + +void resumenext() +{ + C_cal("resumene"); +} + +void no_deadlock() +{ + C_zre_dnam("deadlock", (arith) 0); +} + +void par_end() +{ + C_cal("parend"); +} + +void closefile() +{ + C_close(); +} diff --git a/lang/occam/comp/em.h b/lang/occam/comp/em.h new file mode 100644 index 00000000..3ead9964 --- /dev/null +++ b/lang/occam/comp/em.h @@ -0,0 +1,21 @@ +#ifndef nil +#define nil 0 +#endif + +#define word_constant(c) (-32768L<=(c) && (c)<=32767L) +void Label(), dot_label(), branch(); +int new_label(), new_dot_label(); +char *proc_label(); +extern char *curr_file; + +void cwv(), cvw(); +void bxx(), Loc(), Lol(), Lolp(), Lil(), Lof(), Lofp(), Lif(); +void Txx(), xxi(), Stl(), Inl(), Del(), Loe(); +void cmi(), ngi(), and(), ior(), xor(), sli(), sri(), com(), lar(), lxl(); +void lxa(), lfr(), ste(), lae(), aar(), lal(), adp(), ldc0(), zeq(), zne(); +void zlt(), zgt(), blm(), sti(), cal(), asp(), loc(), lor0(), loi(), pro(); +void ret(), _end(), stl(), laedot(), del(), lol(), ldl(), meswp(), meserr(); +void init_rt(), exp(), rom(), blt(), magic(), lin(), tst(), fil(), trp(); +void main_fil(), init(), openfile(), closefile(), maxdes(); + +void par_begin(), par_fork(), par_end(), resumenext(), no_deadlock(); diff --git a/lang/occam/comp/expr.c b/lang/occam/comp/expr.c new file mode 100644 index 00000000..621d0876 --- /dev/null +++ b/lang/occam/comp/expr.c @@ -0,0 +1,471 @@ +#include "symtab.h" +#include "sizes.h" +#include "expr.h" +#include "Lpars.h" + +static void rvalue(), assignable(), inputable(), outputable(), subscriptable(); +static void assigned(); + +/* The new_* functions make use of the used() and assinged() functions to + * make known what is done to a variable. + */ + +struct expr *new_node(op, left, right, byte) + int op; + register struct expr *left, *right; + int byte; +/* Makes a new node with given operator, left and right operand. + * Constant folding is done if possible. + */ +{ + if (op!=FOR && constant(left) && (right==nil || constant(right))) { + register long lc, rc; + + lc=left->u.const; + rc=right->u.const; + + switch (op) { + case '+': lc+=rc; break; + case '-': lc-=rc; break; + case '*': lc*=rc; break; + case '/': if (rc==0L) + report("division by zero"); + else + lc/=rc; + break; + case BS: lc%=rc; break; + case '<': lc= lc': lc= lc>rc ? -1L : 0L; break; + case LE: lc= lc<=rc ? -1L : 0L; break; + case GE: lc= lc>=rc ? -1L : 0L; break; + case NE: lc= lc!=rc ? -1L : 0L; break; + case '=': lc= lc==rc ? -1L : 0L; break; + case AFTER: lc= (lc-rc)>0 ? -1L : 0L; break; + case BA: lc&=rc; break; + case BO: lc|=rc; break; + case BX: lc^=rc; break; + case AND: lc= lc&&rc ? -1L : 0L; break; + case OR: lc= lc||rc ? -1L : 0L; break; + case LS: lc<<=rc; break; + case RS: lc>>=rc; break; + case '~': lc= -lc; break; + case NOT: lc= ~lc; break; + default: + report("illegal operator on constants"); + } + destroy(right); + + left->u.const=lc; + return left; + } else { + register struct expr *pe; + int type=0, arr_siz=1; + + switch (op) { + case '+': case '-': case '*': case '/': + case BS: case '<': case '>': case LE: + case GE: case NE: case '=': case AFTER: + case BA: case BO: case BX: case AND: + case OR: case LS: case RS: + rvalue(left); + rvalue(right); + type=T_VALUE; + break; + case '~': + case NOT: + rvalue(left); + type=T_VALUE; + break; + case AS: + assignable(left, right); + type=T_VOID; + break; + case '[': + subscriptable(left, right, byte, &type, &arr_siz); + break; + } + pe= (struct expr *) malloc(sizeof *pe); + + pe->kind=E_NODE; + pe->type=type; + pe->arr_siz=arr_siz; + pe->u.node.op=op; + pe->u.node.left=left; + pe->u.node.right=right; + + return pe; + } +} + +struct expr *new_var(var) + register struct symbol *var; +/* Given a variable an expression node is constructed. Note the changes in + * type! T_VAR becomes T_VALUE with flag T_LVALUE. + */ +{ + register struct expr *pe; + + pe= (struct expr *) malloc(sizeof *pe); + + pe->kind=E_VAR; + + if ((var->type&T_TYPE)==T_VAR || var->type&T_NOTDECL) { + pe->type=(var->type&(~T_TYPE)); + pe->type|=T_VALUE|T_LVALUE; + } else + pe->type=var->type; + + pe->arr_siz=var->arr_siz; + + pe->u.var=var; + + return pe; +} + +struct expr *new_const(const) + long const; +/* Make a constant, which is a VALUE, of course. */ +{ + register struct expr *pe; + + pe= (struct expr *) malloc(sizeof *pe); + + pe->kind=E_CONST; + pe->type=T_VALUE; + pe->u.const=const; + + return pe; +} + +struct expr *new_table(kind, tab) + register kind; + register struct table *tab; +/* One table is being made, it is no doubt a VALUEd ARRay, but maybe even a + * BYTE array. A label is reserved for it and the individual elements are + * rommified. + */ +{ + register struct expr *pe; + + pe= (struct expr *) malloc(sizeof *pe); + + pe->kind=kind; + pe->type=T_VALUE|T_ARR; + if (kind==E_BTAB) pe->type|=T_BYTE; + dot_label(new_dot_label(&pe->u.tab)); + + pe->arr_siz=0; + while (tab!=nil) { + register struct table *junk=tab; + + rom(kind==E_BTAB ? 1 : vz, tab->val); + + tab=tab->next; + pe->arr_siz++; + free(junk); + } + + return pe; +} + +struct expr *copy_const(e) struct expr *e; +/* If you double it up, you've got one you can throw away. (Or do something + * useful with). + */ +{ + register struct expr *c; + + c= (struct expr *) malloc(sizeof *c); + + *c= *e; + return c; +} + +struct expr *new_now() +/* Now is the time to make a VALUE cell for the clock. */ +{ + register struct expr *pe; + + pe= (struct expr *) malloc(sizeof *pe); + + pe->kind=E_NOW; + pe->type=T_VALUE; + + return pe; +} + +struct expr *new_io(out, chan, args) + int out; + register struct expr *chan; + struct expr_list *args; +/* Either c ? v0; v1; v2; ... (out=0) or c ! e0; e1; e2; ... (out=1). */ +{ + register struct expr *pe; + + if ( ( (chan->type&T_TYPE) != T_CHAN || (chan->type&T_ARR) ) + && ! (chan->type&T_NOTDECL) + ) + report("channel variable expected"); + used(chan); + + pe= (struct expr *) malloc(sizeof *pe); + + pe->kind=E_IO; + pe->type=T_VOID; + pe->u.io.out=out; + pe->u.io.chan=chan; + pe->u.io.args=args; + + return pe; +} + +struct expr *new_call(proc, args) + struct expr *proc; + struct expr_list *args; +/* Dial proc(arg1, arg2, ...) and you'll hear the tone of this function. + * Dialing yourself is not allowed, but it will work if you ignore the + * compiler generated noise. + */ +{ + register struct expr *pe; + + pe= (struct expr *) malloc(sizeof *pe); + + used(proc); + + check_recursion(proc); + + pe->kind=E_CALL; + pe->type=T_VOID; + pe->u.call.proc=proc; + pe->u.call.args=args; + + return pe; +} + +void table_add(aapt, val) register struct table ***aapt; long val; +/* Adds a value to a table using a hook to a hook. */ +{ + register struct table *pt; + + pt= (struct table *) malloc(sizeof *pt); + + pt->val=val; + pt->next= **aapt; + + **aapt=pt; + *aapt= &pt->next; +} + +void expr_list_add(aaelp, arg) + register struct expr_list ***aaelp; + struct expr *arg; +/* Another add, this time for actual arguments and the like. */ +{ + register struct expr_list *elp; + + elp= (struct expr_list *) malloc(sizeof *elp); + + elp->arg=arg; + elp->next= **aaelp; + **aaelp=elp; + *aaelp= &elp->next; +} + +void check_io(out, arg) int out; struct expr *arg; +{ + if (out) + outputable(arg); + else + inputable(arg); +} + +void check_wait(e) struct expr *e; +{ + if ((e->type&T_TYPE)!=T_VALUE) + report("WAIT process needs valued operand"); +} + +static void assigned(e) register struct expr *e; +/* Tries to tell e that it is assigned to. */ +{ + if (e->kind==E_VAR || (e->kind==E_NODE && e->u.node.op=='[' + && (e=e->u.node.left)->kind==E_VAR) + ) { + register struct symbol *var; + + if ((var=e->u.var)->type&T_REP) { + warning("replicator index %s may not be assigned", + var->name); + var->type&= ~T_REP; + } + var->type|=T_ASSIGNED; + } +} + +void used(e) register struct expr *e; +{ + if (e->kind==E_VAR || (e->kind==E_NODE && e->u.node.op=='[' + && (e=e->u.node.left)->kind==E_VAR) + ) { + register struct symbol *var; + + if ( ! ( (var=e->u.var)->type&(T_ASSIGNED|T_BUILTIN)) + && (var->type&T_TYPE)==T_VAR + && var->info.vc.st.level==curr_level) + warning("%s used before assigned", var->name); + var->type|=(T_USED|T_ASSIGNED); + } +} + +static void rvalue(e) register struct expr *e; +{ + if ((e->type&T_TYPE)!=T_VALUE || e->type&T_ARR) + report("illegal operand of arithmetic operator"); + used(e); +} + +static void assignable(l, r) register struct expr *l, *r; +/* See if l can be assigned r. */ +{ + if ( ! ( (l->type&T_LVALUE && (r->type&T_TYPE)==T_VALUE + && (l->type&T_ARR)==(r->type&T_ARR)) + || (l->type|r->type)&T_NOTDECL + )) + report("operands of assignment are not conformable"); + else + if (l->type&T_ARR && ! ( (l->type|r->type)&T_NOTDECL ) ) { + register lsiz=l->arr_siz, rsiz=r->arr_siz; + + if (lsiz!=0 && rsiz!=0 && lsiz!=rsiz) + report("arrays have incompatible sizes"); + } + used(r); + assigned(l); + +} + +static void inputable(e) struct expr *e; +{ + if ( ! (e->type&T_LVALUE) ) + report("operand of input process can't be assigned"); + + assigned(e); +} + +static void outputable(e) struct expr *e; +{ + if ( ! ( (e->type&T_TYPE)==T_VALUE ) ) + report("operand of output process has no value"); + used(e); +} + +static void subscriptable(l, r, byte, atype, arr_siz) + register struct expr *l, *r; + register byte; + int *atype, *arr_siz; +/* Tries to subscript l by r, returning type and array size for slices. */ +{ + register type= (l->type&T_TYPE)|byte; + + if ( !(l->type&(T_ARR|T_NOTDECL) ) ) + report("indexing on a non-array"); + else + if ( ! ( (r->type&T_TYPE)==T_VALUE + || (r->kind==E_NODE && r->u.node.op==FOR) + ) ) + report("index is not computable"); + + type|=(l->type&T_LVALUE); + + if (r->kind==E_NODE && r->u.node.op==FOR) { + type|=T_ARR; + if (r->u.node.right->kind!=E_CONST) + report("slice must be of constant size"); + else + *arr_siz=r->u.node.right->u.const; + used(r->u.node.left); + } else + used(r); + *atype=type; +} + +void check_param(aform, act, err) + struct par_list **aform; + register struct expr *act; + int *err; +/* Test if formal parameter *aform corresponds with actual act. Err returns + * error status. The aform hook is set to the next formal after the check. + */ +{ + register struct par_list *form= *aform; + register struct expr *left; + register struct symbol *var; + static char NONCORR[]="actual and formal parameter don't correspond"; + + if (form==nil) { + if (! *err) { + report("too many actual parameters"); + *err=1; + } + return; + } + + if ((form->type&T_ARR)!=(act->type&T_ARR) && !(act->type&T_NOTDECL) ) { + report(NONCORR); + } else { + switch (form->type&T_TYPE) { + case T_VAR: + if ( ! ( + (act->type&T_TYPE)==T_VALUE + && act->type&T_LVALUE + && !(act->type&T_BYTE) + )) + report(NONCORR); + assigned(act); + used(act); + break; + case T_CHAN: + if((act->type&T_TYPE)!=T_CHAN && !(act->type&T_NOTDECL)) + report(NONCORR); + used(act); + break; + case T_VALUE: + if ((act->type&T_TYPE)!=T_VALUE) + report(NONCORR); + used(act); + break; + } + } + *aform= form->next; +} + +void destroy(e) register struct expr *e; +/* Opposite of making. */ +{ + if (e!=nil) { + switch (e->kind) { + case E_NODE: + destroy(e->u.node.left); + destroy(e->u.node.right); + break; + case E_IO: + case E_CALL: + destroy(e->kind==E_IO ? e->u.io.chan : e->u.call.proc); + { + register struct expr_list *elp, *junk; + + elp= e->kind==E_IO ? e->u.io.args : e->u.call.args; + + while (elp!=nil) { + destroy(elp->arg); + junk=elp; + elp=elp->next; + free(junk); + } + } + break; + } + free(e); + } +} diff --git a/lang/occam/comp/expr.h b/lang/occam/comp/expr.h new file mode 100644 index 00000000..3b59035b --- /dev/null +++ b/lang/occam/comp/expr.h @@ -0,0 +1,61 @@ +#define E_NODE 0 +#define E_VAR 1 /* Variable *or* channel */ +#define E_CONST 2 +#define E_TABLE 3 +#define E_BTAB 4 +#define E_NOW 5 +#define E_IO 6 +#define E_CALL 7 + +struct table { + long val; + struct table *next; +}; + +struct expr; + +struct expr_list { + struct expr *arg; + struct expr_list *next; +}; + +struct expr { + short kind; + short type; + int arr_siz; + union { + struct { + int op; + struct expr *left, *right; + } node; + + struct symbol *var; + + long const; + + int tab; + + struct { + int out; + struct expr *chan; + struct expr_list *args; + } io; + + struct { + struct expr *proc; + struct expr_list *args; + } call; + } u; +}; + +struct expr *new_node(), *new_var(), *new_const(), *new_table(), *new_now(); +struct expr *new_io(), *new_call(), *copy_const(); +void table_add(), expr_list_add(); +void check_param(), check_io(), check_wait(); +void destroy(), used(); + +#define valueless(e) (((e)->type&T_TYPE)==T_VOID) +#define valued(e) (((e)->type&T_TYPE)==T_VALUE) +#define input_process(e) ((e)->kind==E_IO && !(e)->u.io.out) +#define constant(e) ((e)->kind==E_CONST) +#define arr_constant(e) ((e)->kind==E_TABLE || (e)->kind==E_BTAB) diff --git a/lang/occam/comp/keytab.c b/lang/occam/comp/keytab.c new file mode 100644 index 00000000..3ebec19e --- /dev/null +++ b/lang/occam/comp/keytab.c @@ -0,0 +1,82 @@ +/* keytab.c */ +# include "Lpars.h" +# include + +# define NKEYWORDS ((sizeof keytab) / (sizeof *keytab)) +# define MAXKEYLEN 8 + +typedef struct { + int k_token; + char *k_str; +} KTAB; + +KTAB keytab[] = { + { AFTER, "AFTER" }, { ALLOCATE, "ALLOCATE" }, + { ALT, "ALT" }, { AND, "AND" }, + { ANY, "ANY" }, { BYTE, "BYTE" }, + { CHAN, "CHAN" }, { DEF, "DEF" }, + { FALSE, "FALSE" }, { FOR, "FOR" }, + { IF, "IF" }, { LOAD, "LOAD" }, + { NOT, "NOT" }, { NOW, "NOW" }, + { OR, "OR" }, { PAR, "PAR" }, + { PLACED, "PLACED" }, { PORT, "PORT" }, + { PRI, "PRI" }, { PROC, "PROC" }, + { SEQ, "SEQ" }, { SKIP, "SKIP" }, + { TABLE, "TABLE" }, { TRUE, "TRUE" }, + { VALUE, "VALUE" }, { VAR, "VAR" }, + { WAIT, "WAIT" }, { WHILE, "WHILE" }, +}; + +/* + * The table of keywords is searched for the occurence of `str', + * if found the corresponding token number is returned, + * otherwise IDENTIFIER is the returned token number. + */ +keyword(str) char *str; +{ + register int high= NKEYWORDS-1; + register int low= 0; + register int i, cmp; + char *lowerupper(); + register char *key; + + if ((key=lowerupper(str))==0) return IDENTIFIER; + + do { + i= (high+low) / 2; + if ((cmp= strcmp(key, keytab[i].k_str)) == 0) break; + else if (cmp > 0) low= i+1; + else high= i-1; + } while (low <= high); + + return low<=high ? keytab[i].k_token : IDENTIFIER; +} + +char *lowerupper(str) register char *str; +{ + static char keyword[MAXKEYLEN+1]; + register char *key=keyword; + + if (islower(*str)) { + do + *key++ = toupper(*str++); + while (keyk_token == key) return kp->k_str; + + return 0; +} diff --git a/lang/occam/comp/lex.l b/lang/occam/comp/lex.l new file mode 100644 index 00000000..86f1277e --- /dev/null +++ b/lang/occam/comp/lex.l @@ -0,0 +1,344 @@ +%{ +/* lex.l */ +# include +# include "token.h" +# include "Lpars.h" + +# define TAB 8 /* Size of a acsii tab (\t) in spaces */ +# if (TAB&(TAB-1))!=0 +# define TABSTOP(ind) ((ind)+TAB-(ind)%TAB) +# else +# define TABSTOP(ind) (((ind)+TAB)&(~(TAB-1))) +# endif + +char *malloc(), *strcpy(); + +struct token token; +int ind=0; /* Indentation level of current line */ +static int tab=0; /* First indentation found */ + +int included=0; /* Is current file included? */ +%} + +%% +'((\*[^\n])|([^'\n*]))*' { + if ((token.t_lval=char_constant(yytext+1))== -1L) + report("%s not a character constant", yytext); + + return CHAR_CONST; +} +'[^'\n]*'? { + report("missing '."); + token.t_lval= -1L; + + return CHAR_CONST; +} +\"((\*[^\n])|([^"\n*]))*\" { + char *string(); + + token.t_sval=string(yytext); + + return STRING; +} +\"[^"\n]*\"? { + report("missing \"."); + token.t_sval=""; + + return STRING; +} +#[ \t]*"line"?[ \t]*[0-9]+[ \t]*\"[^"\n]*\" { + set_line_file(yytext); + tab=0; +} +#[A-Fa-f0-9]+ { + long hex_number(); + + token.t_lval=hex_number(yytext+1); + + return NUMBER; +} +[0-9]+ { + long number(); + + token.t_lval=number(yytext); + + return NUMBER; +} +[A-Za-z][A-Za-z0-9.]* { + register key; + + if ((key=keyword(yytext))==IDENTIFIER) + token.t_sval=strcpy(malloc(yyleng+1), yytext); + + return key; +} +\n[ \f\t]*/"--" {/* Line with only a comment, don't set tab */} + +\n[ \f\t]* { + + ind=indentation(yytext+1); + if (tab==0) + tab=ind; + else + if (ind%tab!=0) + warning("indentation not on a %d space boundary", tab); +} +[ \f\t] { /* Nothing */ } +[-=<>:,;+*/\[\]()?!&] return yytext[0]; + +"\\" return BS; +":=" return AS; +"<=" return LE; +">=" return GE; +"<>" return NE; +"<<" return LS; +">>" return RS; +"/\\" return BA; +"\\/" return BO; +"><" return BX; + +"--"[^\n]* { /* Comment is skipped */ } +. { + warning((' '<=yytext[0] && yytext[0]<0177) ? "%s'%c')" : "%soctal: %o)", + "bad character seen (", yytext[0]&0377); +} +%% +char *string(s) char *s; +{ + register c; + register char *p= s; + char *str= s; + + str++; p++; + while (*str != '"') { + if ((c=character(&str)) != -1) + *p++= c; + else + return ""; + } + + *p=0; + *s=p-(s+1); + return s; +} + +long number(s) register char *s; +{ + static char max_str[]="2147483647"; + int maxlen=sizeof max_str-1; + long atol(); + long num; + + while (*s=='0') { /* skip leading nulls */ + *s++; + yyleng--; + } + + if (*s==0) + num=0L; + else { + if ((yyleng>maxlen) || (yyleng==maxlen && strcmp(s, max_str)>0)) + warning("integer constant overflow."); + + num=atol(s); + } + + return num; +} + +long hex_number(s) register char *s; +{ + long number=0L; + + while (*s) + number=(number<<4)+hextoint(*s++); + + return number; +} + +int hextoint(c) register c; +{ + register val; + + if (islower(c)) + val=(c-'a')+10; + else + if (isupper(c)) + val=(c-'A')+10; + else + val=c-'0'; + + return val; +} + +int character(S) register char **S; +{ + register char *s= *S; + register c, cc; + + if ((c= *s++)=='*') { + switch (c= *s++) { + case 'c': + cc='\r'; + break; + case 'n': + cc='\n'; + break; + case 't': + cc='\t'; + break; + case 's': + cc=' '; + break; + case '#': + if (isxdigit(c= *s++) && isxdigit(*s)) { + cc= (hextoint(c)<<4)+hextoint(*s++); + break; + } else { + report("two digit hexadecimal const expected."); + return -1; + } + default: + cc=c; + break; + } + } else + cc=c; + + *S=s; + return cc; +} + +int char_constant(s) char *s; +{ + register cc; + + cc=character(&s); + + return (*s=='\'' && cc!= -1) ? cc : -1; +} + +int indentation(s) register char *s; +{ + register in=0, c; + + while (c= *s++) { + if (c=='\t') + in=TABSTOP(in); + else + if (c=='\f') + in=0; + else + in++; + } + + return in; +} + +int tabulated(oind, ind) register oind, ind; +{ + if (tab>0 && ind>oind+tab) + warning("process' indentation too large (changed to %d tab%s)", + oind/tab+1, oind>=tab ? "s" : ""); + return ind>oind; +} + +int rep_tk=0; +struct token rep_token; + +void repeat_token(tk) +{ + rep_tk=tk; + rep_token=token; +} + +scanner() +{ + register tk; + + if (rep_tk>0) { + tk=rep_tk;; + rep_tk=0; + token=rep_token; + return tk; + } else + return yylex(); +} + +char *tokenname(tk, inst) register tk, inst; +{ + if (tk<0400) { + static char c[7]; + + if (' '=", "<>", "<<", ">>", "/\\", + "\\/", "><", "\\" + }; + register i; + static char qopc[5]; + + for (i=0; op[i]!=tk; i++) ; + sprintf(qopc, "'%s'", opc[i]); + return qopc; + } + } + } +} + +set_line_file(l) register char *l; +{ + register char *file; + + while (*l<'0' || *l>'9') l++; + + yylineno=0; + while ('0'<=*l && *l<='9') + yylineno=yylineno*10+(*l++ - '0'); + + yylineno--; + + while (*l++!='"'); + + file=l; + while (*l++!='"'); + *--l=0; + + included=set_file(file); +} diff --git a/lang/occam/comp/occam.g b/lang/occam/comp/occam.g new file mode 100644 index 00000000..737aee7e --- /dev/null +++ b/lang/occam/comp/occam.g @@ -0,0 +1,684 @@ +/* OCCAM */ +{ +#include "token.h" +#include "symtab.h" +#include "expr.h" +#include "code.h" +#include "sizes.h" + +#define MAXERRORS 10 /* Maximum number of insert/delete errors */ + +static void nonconst(), nonpositive(), rep_cleanup(), check_assoc(); +void init_builtins(); + +extern int yylineno, LLsymb; +union type_info info, none; +} +%token AFTER, ALLOCATE, ALT, AND, ANY, BYTE, CHAN, DEF, FALSE, FOR, IF, LOAD; +%token NOT, NOW, OR, PAR, PLACED, PORT, PRI, PROC, SEQ, SKIP, TABLE, TRUE; +%token VALUE, VAR, WAIT, WHILE; +%token IDENTIFIER, NUMBER, CHAR_CONST, STRING; +%token AS, LE, GE, NE, LS, RS, BA, BO, BX, BS; + +%start occam, program; + +program : { init_builtins(); + header(); + } + process + ; + +process : primitive + | construct + | { sym_down(); } + declaration ':' process + { sym_up(); } + ; + +primitive { struct expr *e; } : + statement(&e) { if (!valueless(e)) + report("primitive may not have a value"); + code_void(e); + destroy(e); + } + | WAIT val_expr(&e) { int BEGIN=0, END=0, TEST=0; + check_wait(e); + no_deadlock(); + branch(&TEST); + Label(new_label(&BEGIN)); + resumenext(); + Label(TEST); + code_bool(e, positive, &END, &BEGIN); + Label(END); + destroy(e); + } + | SKIP + ; + +guard(register *F;) { struct expr *e1, *e2; + register full_guard=0; + int T=0; + static char EXPECT_INP[]="input process expected as guard"; + } : + expression(&e1) + [ '&' { full_guard=1; + if (!valued(e1)) + report("boolean part of guard has no value"); + code_bool(e1, positive, &T, F); + Label(T); + } + [ statement(&e2) + { if (!input_process(e2)) + report(EXPECT_INP); + code_any(e2, F); + destroy(e2); + } + | WAIT val_expr(&e2) + { check_wait(e2); + code_bool(e2, positive, &T, F); + Label(T); + destroy(e2); + } + | SKIP + ] + ]? + { if (!full_guard) { + if (!input_process(e1)) + report(EXPECT_INP); + code_any(e1, F); + } + destroy(e1); + } + | WAIT val_expr(&e1) + { check_wait(e1); + code_bool(e1, positive, &T, F); + Label(T); + destroy(e1); + } + | SKIP + ; + +guarded_process(register *END;) { struct symbol *v; + struct expr *e1, *e2; + struct replicator to_test; + register line, oind; + int F=0; + } : + guard(&F) process { branch(END); + Label(F); + } + | ALT { line=yylineno; oind=ind; } + [ %if (line==yylineno) + replicator(&v, &e1, &e2) + { rep_init(v, e1, e2, &to_test); } + guarded_process(END) + { rep_test(v, e1, e2, &to_test); + rep_cleanup(e1, e2); + } + | + [ %while (tabulated(oind, ind)) guarded_process(END) ]* + ] + ; + +conditional(register *END; ) { struct symbol *v; + struct expr *e1, *e2; + struct replicator to_test; + register line, oind; + int T=0, F=0; + } : + val_expr(&e1) { if (!valued(e1)) + report("conditional needs valued expression"); + code_bool(e1, positive, &T, &F); + Label(T); + destroy(e1); + } + process + { branch(END); + Label(F); + } + | IF { line=yylineno; oind=ind; } + [ %if (line==yylineno) + replicator(&v, &e1, &e2) + { rep_init(v, e1, e2, &to_test); } + conditional(END) + { rep_test(v, e1, e2, &to_test); + rep_cleanup(e1, e2); + } + | + [ %while (tabulated(oind, ind)) conditional(END) ]* + ] + ; + +replicator(register struct symbol **s; register struct expr **e1, **e2; ) + { register char *index; }: + IDENTIFIER { index=token.t_sval; } + '=' '[' val_expr(e1) FOR val_expr(e2) ']' + { if (!valued(*e1) || !valued(*e2)) + report("replicator needs valued expressions"); + sym_down(); + var_memory(&info, T_VAR, 1); + *s=insert(index, + T_VAR|T_REP|T_USED|T_ASSIGNED, 1, info); + } + ; + +construct { struct symbol *v; + struct expr *e1, *e2; + struct replicator to_test; + register line, oind; + int BEGIN=0, END=0, NONZERO; + }: + SEQ { line=yylineno; oind=ind; } + [ %if (line==yylineno) + replicator(&v, &e1, &e2) + { rep_init(v, e1, e2, &to_test); } + process + { rep_test(v, e1, e2, &to_test); + rep_cleanup(e1, e2); + } + | + [ %while (tabulated(oind, ind)) process ]* + ] + | PRI ? + [ PAR { line=yylineno; oind=ind; + par_begin(); + } + [ %if (line==yylineno) + replicator(&v, &e1, &e2) + { rep_init(v, e1, e2, &to_test); + NONZERO=0; + par_fork(&NONZERO); + } + process + { branch(&END); + Label(NONZERO); + rep_test(v, e1, e2, &to_test); + rep_cleanup(e1, e2); + } + | + [ %while (tabulated(oind, ind)) + { NONZERO=0; + par_fork(&NONZERO); + } + process + { branch(&END); + Label(NONZERO); + } + ]* + ] + { Label(END); + par_end(); + } + | ALT { line=yylineno; oind=ind; + no_deadlock(); + Label(new_label(&BEGIN)); + } + [ %if (line==yylineno) + replicator(&v, &e1, &e2) + { rep_init(v, e1, e2, &to_test); } + guarded_process(&END) + { rep_test(v, e1, e2, &to_test); + rep_cleanup(e1, e2); + } + | + [ %while (tabulated(oind, ind)) guarded_process(&END) + ]* + ] + { resumenext(); + branch(&BEGIN); + Label(END); + } + ] + | IF { line=yylineno; oind=ind; } + [ %if (line==yylineno) + replicator(&v, &e1, &e2) + { rep_init(v, e1, e2, &to_test); } + conditional(&END) + { rep_test(v, e1, e2, &to_test); + rep_cleanup(e1, e2); + } + | + [ %while (tabulated(oind, ind)) conditional(&END) ]* + ] + { Label(END); } + | WHILE val_expr(&e1) { if (!valued(e1)) + report("WHILE needs valued expression"); + branch(&END); + Label(new_label(&BEGIN)); + } + process + { int DONE=0; + Label(END); + code_bool(e1, negative, &DONE, &BEGIN); + Label(DONE); + destroy(e1); + } + ; + +subscript(register *byte; register struct expr **e; ) + { struct expr *e1; + register slice=0, err=0; + } : + '[' { *byte=0; } + [ BYTE { *byte=T_BYTE; } + ]? + val_expr(e) { if (!valued(*e)) + err++; + } + [ FOR expression(&e1) + { static char siz[]="slize size"; + if (!constant(e1)) { + if (!err) + nonconst(siz); + destroy(e1); + e1=new_const(0L); + } else + if (e1->u.const<=0) + nonpositive(siz); + *e=new_node(FOR, *e, e1); + slice=1; + } + ]? + ']' + { if (err) + report(slice ? + "slice must be '[' value FOR constant ']'" : + "subscript needs valued expression"); + } + ; + +chan { register type, arr_siz=1; register char *name; struct expr *e; }: + IDENTIFIER { type=T_CHAN; + name=token.t_sval; + } + [ '[' expression(&e) ']' + { static char siz[]="channel array size"; + if (!constant(e)) + nonconst(siz); + else + if (e->u.const<0) + nonpositive(siz); + else + arr_siz=e->u.const; + destroy(e); + type|=T_ARR; + } + ]? + { chan_memory(&info, arr_siz); + chan_init(&info, arr_siz); + insert(name, type, arr_siz, info); + } + ; + +var { register type, byte=0, arr_siz=1; + register char *name; + struct expr *e; + }: + IDENTIFIER { type=T_VAR; name=token.t_sval; } + [ '[' + [ BYTE { byte=T_BYTE; } + ]? + expression(&e) ']' + { static char siz[]="variable array size"; + if (!constant(e)) + nonconst(siz); + else + if (e->u.const<=0) + nonpositive(siz); + else + arr_siz=e->u.const; + destroy(e); + type|=T_ARR|byte; + } + ]? + { var_memory(&info, type, arr_siz); + insert(name, type, arr_siz, info); + } + ; + +const_def { register char *name; struct expr *e; }: + IDENTIFIER { name=token.t_sval; } + '=' expression(&e) + { if (!constant(e) && !arr_constant(e)) + nonconst("expression in constant definition"); + info.const=e; + insert(name, T_CONST|T_USED, 0, info); + } + ; + +form_parm(register struct par_list ***aapars; register *g_type;) + { register char *name; + register type= *g_type; + }: + [ VAR { type=T_VAR|T_ASSIGNED|T_USED; } + | CHAN { type=T_CHAN; } + | VALUE { type=T_VALUE|T_ASSIGNED; } + ]? + IDENTIFIER { + if (type<0) { + report("VAR, CHAN or VALUE expected"); + type=T_VAR; + } + name=token.t_sval; + *g_type=type; + } + [ '[' ']' + { type|=T_ARR; } + ]? + { pars_add(aapars, type&(T_TYPE|T_ARR), + insert(name, type|T_PARAM, 0, none)); + } + ; + +form_parms(struct par_list **apars;) { int type= -1; }: + '(' form_parm(&apars, &type) + [ ',' form_parm(&apars, &type) + ]* + ')' + ; + +declaration: + VAR + var [ ',' var ]* + | CHAN + chan [ ',' chan ]* + | DEF + const_def [ ',' const_def ]* + | proc_declaration + ; + +proc_declaration { struct par_list *pars=nil; + register struct symbol *proc; + int OVER=0; + register old_min_offset; + }: + PROC IDENTIFIER { branch(&OVER); + proc=insert(token.t_sval, + T_PROC|T_RECURS, 0, none); + old_min_offset=min_offset; + sym_down(); + prologue(proc); + } + form_parms(&pars) ? { form_offsets(pars); + proc->info.proc.pars=pars; + } + '=' process { epilogue(proc); + sym_up(); + proc->type&= ~T_RECURS; + min_offset=old_min_offset; + Label(OVER); + } + ; + +vector_constant(register struct expr **e;) + { struct table *pt=nil, **apt= &pt; + register Tlen=0; + }: + table(e) + | STRING { register char *ps= token.t_sval; + register len; + + Tlen+= len= (*ps++ & 0377); + while (--len>=0) + table_add(&apt, (long) *ps++); + } + [ %while (1) STRING + { register char *ps= token.t_sval; + register len; + + Tlen+= len= (*ps++ & 0377); + while (--len>=0) + table_add(&apt, (long) *ps++); + } + ]* + { apt= &pt; + table_add(&apt, (long) Tlen); + *e=new_table(E_BTAB, pt); + } + ; + +item(register struct expr **e;) + { struct expr *e1; + register struct symbol *var; + struct par_list *pars=nil; + register line, oind; + int byte, err=0, subs_call=0; + struct expr_list *elp=nil, **aelp= &elp; + }: + IDENTIFIER { line=yylineno; + oind=ind; + var=searchall(token.t_sval); + + if (var_constant(var)) + *e=copy_const(var->info.const); + else { + if (var_proc(var)) + pars=var->info.proc.pars; + *e=new_var(var); + } + } + [ %while (line==yylineno || tabulated(oind, ind)) + [ subscript(&byte, &e1) + { *e=new_node('[', *e, e1, byte); } + | '(' { if (!var_declared(var)) { + var->type=T_PROC|T_USED|T_NOTDECL; + var->info.proc.pars=nil; + err=1; + } + if (!var_proc(var)) { + report("%s is not a named process", + var->name); + err=1; + } + } + expression(&e1) + { check_param(&pars, e1, &err); + expr_list_add(&aelp, e1); + } + [ ',' expression(&e1) + { check_param(&pars, e1, &err); + expr_list_add(&aelp, e1); + } + ]* + { + if (pars!=nil) + report("too few actual parameters"); + } + ')' + { *e=new_call(*e, elp); } + ] + { subs_call=1; } + ]? + { if (!subs_call && var_proc(var)) { + if (pars!=nil) + report("no actual parameters"); + *e=new_call(*e, nil); + } + } + | vector_constant(e) + [ subscript(&byte, &e1) + { *e=new_node('[', *e, e1, byte); } + ]? + ; + +statement(register struct expr **e;) + { struct expr *e1; + struct expr_list *elp=nil, **aelp= &elp; + register out; + }: + item(e) + [ AS expression(&e1) + { *e=new_node(AS, *e, e1); } + | [ + '?' { out=0; } + | '!' { out=1; } + ] + io_arg(&e1) + { if (e1!=nil) check_io(out, e1); + expr_list_add(&aelp, e1); + } + [ %while (1) ';' io_arg(&e1) + { if (e1!=nil) check_io(out, e1); + expr_list_add(&aelp, e1); + } + ]* + { *e=new_io(out, *e, elp); } + ]? + ; + +io_arg(struct expr **e; ) : + expression(e) + | ANY { *e=nil; } + ; + +table(register struct expr **e;) + { struct table *pt=nil, **apt= &pt; + struct expr *e1; + register type; + }: + TABLE '[' { type=E_TABLE; } + [ BYTE { type=E_BTAB; } + ]? + expression(&e1) { if (!constant(e1)) + nonconst("table element"); + else + table_add(&apt, e1->u.const); + destroy(e1); + } + [ ',' expression(&e1) + { if (!constant(e1)) + nonconst("table element"); + else + table_add(&apt, e1->u.const); + destroy(e1); + } + ]* + { *e=new_table(type, pt); } + ']' + ; + +arithmetic_op: '+' | '-' | '*' | '/' | BS + ; + +comparison_op: '<' | '>' | LE | GE | NE | '=' | AFTER + ; + +logical_op: BA | BO | BX + ; + +boolean_op: AND | OR + ; + +shift_op: LS | RS + ; + +monadic_op(register *op;): + '-' { *op='~'; } + | NOT { *op=NOT; } + ; + +operator: arithmetic_op | comparison_op | logical_op | boolean_op | shift_op + ; + +element(register struct expr **e;) : + %default NUMBER { *e=new_const(token.t_lval); } + | statement(e) + | TRUE { *e=new_const(-1L); } + | FALSE { *e=new_const(0L); } + | NOW { *e=new_now(); } + | CHAR_CONST { *e=new_const(token.t_lval); } + | '(' expression(e) ')' { if (valueless(*e)) + warning("primitive should not be parenthesized"); + } + ; + +expression(register struct expr **e;) + { int op=0; + struct expr *e1; + }: + element(e) + [ %while (1) { if (op!=0) check_assoc(op, LLsymb); + op=LLsymb; + } + operator element(&e1) + { *e=new_node(op, *e, e1); } + ]* + | monadic_op(&op) element(&e1) + { *e=new_node(op, e1, nil); } + ; + +val_expr(register struct expr **e;) : + expression(e) { used(*e); } + ; + +%lexical scanner; +{ +int err=0; +#include + +main(argc, argv) register argc; register char **argv; +{ + wz= (argc>1 && strcmp(argv[1], "4")==0) ? 4 : 2; + pz= (argc>2 && strcmp(argv[2], "4")==0) ? 4 : wz; + + leader(); + occam(); + trailer(); + + exit(err); +} + +LLmessage(tk) register tk; +{ + static errors=0; + + if (tk>0) { + repeat_token(LLsymb); + warning("syntax error: %s expected (inserted)", tokenname(tk, 1)); + } else + if (tk==0) + warning("syntax error: bad token %s (deleted)", tokenname(LLsymb, 0)); + else { /* tk<0 */ + fprintf(stderr, "Compiler stack overflow. Compiler ends."); + err=1; trailer(); exit(1); + } + if (++errors==MAXERRORS) { + fprintf(stderr, "Too many insert/delete errors. Compiler ends.\n"); + err=1; trailer(); exit(1); + } +} + +static void nonconst(siz) char *siz; +{ + report("%s should be a constant", siz); +} + +static void nonpositive(siz) char *siz; +{ + report("%s must be positive", siz); +} + +static void rep_cleanup(e1, e2) struct expr *e1, *e2; +{ + destroy(e1); + destroy(e2); + sym_up(); +} + +static void check_assoc(prev_op, op) register prev_op, op; +{ + switch (op) { + char prev[5]; + case '+': case '*': + case AND: case OR: + case BA: case BO: case BX: + if (prev_op==op) break; + default: + strcpy(prev, tokenname(prev_op, 0)); + + warning("Operators %s and %s don't associate", + prev, tokenname(op, 0) + ); + } +} +} diff --git a/lang/occam/comp/report.c b/lang/occam/comp/report.c new file mode 100644 index 00000000..e7385c64 --- /dev/null +++ b/lang/occam/comp/report.c @@ -0,0 +1,19 @@ +#include + +extern int err, yylineno; +extern char *curr_file; + +report(fmt, arg1, arg2, arg3) char *fmt; +{ + fprintf(stderr, "%s (%d) F: ", curr_file, yylineno); + fprintf(stderr, fmt, arg1, arg2, arg3); + putc('\n', stderr); + err=1; +} + +warning(fmt, arg1, arg2, arg3) char *fmt, *arg1; +{ + fprintf(stderr, "%s (%d) E: ", curr_file, yylineno); + fprintf(stderr, fmt, arg1, arg2, arg3); + putc('\n', stderr); +} diff --git a/lang/occam/comp/sizes.h b/lang/occam/comp/sizes.h new file mode 100644 index 00000000..df0b3c7b --- /dev/null +++ b/lang/occam/comp/sizes.h @@ -0,0 +1,5 @@ +/* Variable size, wordsize, pointer size. Offsets for local variables. */ + +#define vz 4 +extern int wz, pz; +extern int curr_level, curr_offset, min_offset; diff --git a/lang/occam/comp/symtab.c b/lang/occam/comp/symtab.c new file mode 100644 index 00000000..40494262 --- /dev/null +++ b/lang/occam/comp/symtab.c @@ -0,0 +1,202 @@ +#include "symtab.h" +#include "expr.h" +#include "sizes.h" + +int curr_level=0; /* Current local level */ +int curr_offset=0; /* Current offset within this level */ +int min_offset=0; /* Minimum of all offsets within current level */ + +static struct symtab *sym_table=nil; + +char *malloc(); + +static struct symbol **search_sym(tree, name) + struct symbol **tree; + char *name; +/* Returns a hook in the tree to the where the given name is or should be. */ +{ + register struct symbol **aps=tree, *ps; + register cmp; + + while ((ps= *aps)!=nil && (cmp=strcmp(name, ps->name))!=0) + aps= cmp<0 ? &ps->left : &ps->right; + + return aps; +} + +struct symbol *insert(name, type, arr_siz, info) + char *name; + int type, arr_siz; + union type_info info; +/* Inserts an object with given name and other info into the current symbol + * tree. A pointer is returned to the inserted symbol so that more info may + * or changed. Nil is returned on redeclaration. + */ +{ + register struct symbol **aps, *ps; + extern included; + + if (*(aps=search_sym(&sym_table->local, name))!=nil) { + report("%s redeclared", name); + return nil; + } + + ps= (struct symbol *) malloc(sizeof *ps); + + ps->name=name; + + if (included && curr_level==0) /* Top_level symbol in include file */ + type|=T_USED; /* are always used */ + ps->type=type; + ps->arr_siz=arr_siz; + ps->info=info; + ps->left=ps->right=nil; + *aps=ps; + + return ps; +} + +struct symbol *searchall(name) char *name; +/* Searches for name in all symbol trees from the inner to the outermost. + * If it can't be found then it is inserted as undefined. + */ +{ + register struct symtab *tab=sym_table; + register struct symbol *ps; + + while (tab!=nil) { + if ((ps= *search_sym(&tab->local, name))!=nil) return ps; + + tab=tab->global; + } + report("%s not declared", name); + return insert(name, T_NOTDECL, 0, none); +} + +void check_recursion(proc) + register struct expr *proc; +{ + if (proc->kind==E_VAR && proc->u.var->type&T_RECURS) + warning("recursion not allowed"); +} + +void sym_down() +{ + register struct symtab *ps; + + ps= (struct symtab *) malloc(sizeof *ps); + + ps->local=nil; + ps->global=sym_table; + ps->old_offset=curr_offset; + + sym_table=ps; +} + +static void sym_destroy(ps) register struct symbol *ps; +{ + if (ps!=nil) { + sym_destroy(ps->left); + sym_destroy(ps->right); + if ( !(ps->type&T_NOTDECL) ) { + if ( !(ps->type&T_USED) ) + warning("%s: never used", ps->name); + else + if ( !(ps->type&T_ASSIGNED) && (ps->type&T_TYPE)==T_VAR) + warning("%s: never assigned", ps->name); + } + if ((ps->type&T_TYPE)==T_PROC) { + register struct par_list *par, *junk; + + par=ps->info.proc.pars; + while (par!=nil) { + junk=par; + par=par->next; + free(junk); + } + } else + if ((ps->type&T_TYPE)==T_CONST) + destroy(ps->info.const); + free(ps->name); + free(ps); + } +} + +void sym_up() +{ + register struct symtab *ps; + + ps=sym_table->global; + curr_offset=sym_table->old_offset; + + sym_destroy(sym_table->local); + free(sym_table); + + sym_table=ps; +} + +void var_memory(info, type, n) register union type_info *info; int type, n; +/* Reserves local memory for an object, and stores it in its info field. */ +{ + info->vc.st.level=curr_level; + curr_offset-= (type&T_BYTE) ? (n+wz-1) & (~(wz-1)) : n*vz; + info->vc.offset=curr_offset; + if (curr_offsetvc.st.level=curr_level; + info->vc.offset= curr_offset-=n*(vz+wz); + if (curr_offsettype=type; + pl->var=var; + pl->next= **aapars; + + **aapars=pl; + *aapars= &pl->next; +} + +int form_offsets(pars) register struct par_list *pars; +/* Recursively assign offsets to formal variables. */ +{ + register struct symbol *var; + + if (pars==nil) return pz; + + if ((var=pars->var)!=nil) { + register offset=form_offsets(pars->next); + + switch (var->type&T_TYPE) { + case T_VAR: + case T_CHAN: + var->info.vc.st.level=curr_level; + var->info.vc.offset=offset; + return offset+pz; + case T_VALUE: + var->info.vc.st.level=curr_level; + var->info.vc.offset=offset; + return offset+ ((var->type&T_ARR) ? pz : vz); + } + } +} diff --git a/lang/occam/comp/symtab.h b/lang/occam/comp/symtab.h new file mode 100644 index 00000000..48cd7da2 --- /dev/null +++ b/lang/occam/comp/symtab.h @@ -0,0 +1,91 @@ +#ifndef nil +#define nil 0 +#endif + + /* Symbol/Expression type: */ +#define T_VAR 0x0000 +#define T_CHAN 0x0001 +#define T_CONST 0x0002 +#define T_VALUE 0x0003 +#define T_PROC 0x0004 +#define T_NOW 0x0005 +#define T_VOID 0x0006 + +#define T_TYPE 0x0007 /* Mask for type bits */ + + /* Flags: */ +#define T_ARR 0x0008 /* Object is an array */ +#define T_BYTE 0x0010 /* Object is a byte array if T_ARR */ +#define T_PARAM 0x0020 /* Formal parameter */ +#define T_LVALUE 0x0040 /* This object may be assigned */ +#define T_NOTDECL 0x0080 /* If you didn't declare it */ +#define T_USED 0x0100 /* If you've used it */ +#define T_ASSIGNED 0x0200 /* Or assigned it */ +#define T_REP 0x0400 /* Replicator index */ +#define T_BUILTIN 0x0800 /* Builtin name */ +#define T_RECURS 0x1000 /* This proc is now compiled */ +/* Note that some types and flags are only used for symbols, and others only + * for expressions. + */ + +struct symbol; + +struct par_list { /* List of parameter types for a proc object */ + struct par_list *next; + struct symbol *var; /* The formal parameter while visible */ + int type; /* Its type */ +}; + +struct expr; + +union storage { /* An object is found */ + int level; /* either at a certain local level */ + char *builtin; /* or using a global builtin name */ +}; + +union type_info { + struct { + union storage st; + int offset; /* from its local level or builtin name */ + } vc; /* Variable or channel */ + + struct expr *const; + + struct { + union storage st; + char *file; /* file it is in */ + int label; /* A unique id*/ + struct par_list *pars; + } proc; +}; + +struct symbol { + char *name; + short type; + int arr_siz; + union type_info info; + struct symbol *left, *right; +}; + +struct symtab { + struct symbol *local; + struct symtab *global; + int old_offset; +}; + +struct symbol *insert(); +struct symbol *searchall(); + +void sym_down(); +void sym_up(); +void var_memory(), chan_memory(); + +void pars_add(); +int form_offsets(); +void check_recursion(); + +#define var_constant(v) (((v)->type&T_TYPE)==T_CONST) +#define var_proc(v) (((v)->type&T_TYPE)==T_PROC) +#define var_declared(v) (! ((v)->type&T_NOTDECL)) + +extern union type_info none; diff --git a/lang/occam/comp/token.h b/lang/occam/comp/token.h new file mode 100644 index 00000000..b25f2ee4 --- /dev/null +++ b/lang/occam/comp/token.h @@ -0,0 +1,11 @@ +/* token.h */ + +extern struct token { + long t_lval; + char *t_sval; +} token; + +extern ind; +void repeat_token(); +char *tokenname(); +int tabulated(); From ce60eeea91cb93ac22b47f0315431fb82352ba16 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 24 Feb 1987 18:36:02 +0000 Subject: [PATCH 0881/1625] Initial revision --- lang/occam/lib/AR2 | 11 +++ lang/occam/lib/AR4 | 11 +++ lang/occam/lib/Makefile | 28 +++++++ lang/occam/lib/builtin.c | 75 ++++++++++++++++++ lang/occam/lib/channel.c | 152 +++++++++++++++++++++++++++++++++++++ lang/occam/lib/co.c | 115 ++++++++++++++++++++++++++++ lang/occam/lib/em2.e | 52 +++++++++++++ lang/occam/lib/em4.e | 49 ++++++++++++ lang/occam/lib/ocm_chan.h | 47 ++++++++++++ lang/occam/lib/ocm_parco.h | 18 +++++ lang/occam/lib/ocm_proc.h | 52 +++++++++++++ lang/occam/lib/ocrt.c | 52 +++++++++++++ lang/occam/lib/par.c | 92 ++++++++++++++++++++++ lang/occam/lib/par_em2.e | 53 +++++++++++++ lang/occam/lib/par_em4.e | 46 +++++++++++ lang/occam/lib/par_vax.s | 51 +++++++++++++ lang/occam/lib/parco.c | 130 +++++++++++++++++++++++++++++++ 17 files changed, 1034 insertions(+) create mode 100755 lang/occam/lib/AR2 create mode 100755 lang/occam/lib/AR4 create mode 100644 lang/occam/lib/Makefile create mode 100644 lang/occam/lib/builtin.c create mode 100644 lang/occam/lib/channel.c create mode 100644 lang/occam/lib/co.c create mode 100644 lang/occam/lib/em2.e create mode 100644 lang/occam/lib/em4.e create mode 100644 lang/occam/lib/ocm_chan.h create mode 100644 lang/occam/lib/ocm_parco.h create mode 100644 lang/occam/lib/ocm_proc.h create mode 100644 lang/occam/lib/ocrt.c create mode 100644 lang/occam/lib/par.c create mode 100644 lang/occam/lib/par_em2.e create mode 100644 lang/occam/lib/par_em4.e create mode 100644 lang/occam/lib/par_vax.s create mode 100644 lang/occam/lib/parco.c diff --git a/lang/occam/lib/AR2 b/lang/occam/lib/AR2 new file mode 100755 index 00000000..d249beb9 --- /dev/null +++ b/lang/occam/lib/AR2 @@ -0,0 +1,11 @@ +#!/bin/sh +case $# in + 0) ar ru /user0/bot/lib/lib2.a *.o + ranlib /user0/bot/lib/lib2.a + rm -f *.o + ;; + *) keys=$1 + shift + ar $keys /user0/bot/lib/lib2.a $* + ;; +esac diff --git a/lang/occam/lib/AR4 b/lang/occam/lib/AR4 new file mode 100755 index 00000000..0560c4a8 --- /dev/null +++ b/lang/occam/lib/AR4 @@ -0,0 +1,11 @@ +#!/bin/sh +case $# in + 0) ar ru /user0/bot/lib/lib4.a *.o + ranlib /user0/bot/lib/lib4.a + rm -f *.o + ;; + *) keys=$1 + shift + ar $keys /user0/bot/lib/lib4.a $* + ;; +esac diff --git a/lang/occam/lib/Makefile b/lang/occam/lib/Makefile new file mode 100644 index 00000000..357ab5fb --- /dev/null +++ b/lang/occam/lib/Makefile @@ -0,0 +1,28 @@ +PRIMITIVES= par_vax.s +PARALLEL= parco.c par.c co.c +OCRT= ocrt.c builtin.c channel.c chan_struct.c + +COMMON= $(PRIMITIVES) $(PARALLEL) $(OCRT) + +SIZE2= em2.e +SIZE4= em4.e + +LIB2= /user0/bot/lib/lib2.a +LIB4= /user0/bot/lib/lib4.a + +ACK2= vax2 +ACK4= vax4 + +all: lib2 lib4 + +lib2: $(COMMON) $(SIZE2) + rm -f *.o $(LIB2) + $(ACK2) -c.o -L -Dvoid=char -Dptrdiff=long $(COMMON) $(SIZE2) + ar cq $(LIB2) *.o + rm -f *.o + +lib4: $(COMMON) $(SIZE4) + rm -f *.o $(LIB4) + $(ACK4) -c.o -L -Dvoid=char $(COMMON) $(SIZE4) + ar cq $(LIB4) *.o + rm -f *.o diff --git a/lang/occam/lib/builtin.c b/lang/occam/lib/builtin.c new file mode 100644 index 00000000..37ed2e89 --- /dev/null +++ b/lang/occam/lib/builtin.c @@ -0,0 +1,75 @@ +/* builtin.c - built in named processes */ +#include "channel.h" +#ifndef nil +#define nil 0 +#endif + +extern int errno; + +static void nullterm(s) register char *s; +/* Change Occam string to C string */ +{ + register len= (*s & 0377); + register char *p; + + while (--len>=0) { + p=s++; + *p = *s; + } + *s=0; +} + +static void lenterm(s) register char *s; +/* Change C string to Occam string */ +{ + register i=0; + register c0, c1; + + c0=0; + do { + c1=s[i]; + s[i++]=c0; + c0=c1; + } while (c0!=0); + *s= i-1; +} + +void b_open(mode, name, index) register char *mode, *name; long *index; +/* PROC open(VAR index, VALUE name[], mode[])= */ +{ + register FILE *fp; + register i; + + nullterm(name); + nullterm(mode); + + fp=fopen(name, mode); + + lenterm(name); + lenterm(mode); + + if (fp==nil) + *index= -errno; + else { + /* Find free file channel, there must be one free! */ + + for (i=0; (file[i].f.flgs&C_F_INUSE)!=0; i++) ; + + file[i].f.flgs|=C_F_INUSE; + unix_file[i]=fp; + *index=i; + } +} + +void b_close(index) long index; +/* PROC close(VALUE index)= */ +{ + fclose(unix_file[index]); + file[index].f.flgs&= ~C_F_INUSE; +} + +void b_exit(code) long code; +/* PROC exit(VALUE code)= */ +{ + exit((int) code); +} diff --git a/lang/occam/lib/channel.c b/lang/occam/lib/channel.c new file mode 100644 index 00000000..630f932f --- /dev/null +++ b/lang/occam/lib/channel.c @@ -0,0 +1,152 @@ +/* channel.c - basic channel handling routines */ +#include +#include +#include +#include "channel.h" + +static void disaster(); + +void c_init(c, z) register chan *c; register unsigned z; +/* Initialise an array of interprocess channels declared as: CHAN c[z]. */ +{ + do { + c->type=C_T_CHAN; + (c++)->c.synch=C_S_FREE; + } while (--z!=0); +} + +void chan_in(v, c) long *v; register chan *c; +/* Reads a value from channel c and returns it through v. */ +{ + switch(c->type) { + case C_T_FILE: + if ((c->f.flgs&C_F_READAHEAD)!=0) { + *v=(c->f.preread&0377); + c->f.flgs&= ~C_F_READAHEAD; + } else { + register FILE *fp= unix_file[c->f.index]; + + *v= feof(fp) ? C_F_EOF : getc(fp); + } + break; + case C_T_CHAN: + deadlock=0; /* Wait for value to arrive */ + while (c->c.synch!=C_S_ANY) resumenext(); + + *v=c->c.val; + c->c.synch=C_S_ACK; /* Acknowledge receipt */ + break; + default: + disaster(); + } +} + +void chan_out(v, c) long v; register chan *c; +/* Send value v through channel c. */ +{ + switch(c->type) { + case C_T_FILE: { + register FILE *fp= unix_file[c->f.index]; + struct sgttyb tty; + + if ((v& ~0xff)==0) /* Plain character */ + putc( (int) v, fp); + else + if (v==C_F_TEXT) { + ioctl(fileno(fp), TIOCGETP, &tty); + tty.sg_flags&= ~CBREAK; + tty.sg_flags|= ECHO|CRMOD; + ioctl(fileno(fp), TIOCSETN, &tty); + } else + if (v==C_F_RAW) { + ioctl(fileno(fp), TIOCGETP, &tty); + tty.sg_flags|= CBREAK; + tty.sg_flags&= ~(ECHO|CRMOD); + ioctl(fileno(fp), TIOCSETN, &tty); + } + } break; + case C_T_CHAN: + deadlock=0; /* Wait until channel is free */ + while (c->c.synch!=C_S_FREE) resumenext(); + + c->c.val=v; + c->c.synch=C_S_ANY; /* Channel has data */ + + deadlock=0; /* Wait for acknowledgement */ + while (c->c.synch!=C_S_ACK) resumenext(); + + c->c.synch=C_S_FREE; /* Back to normal */ + break; + default: + disaster(); + } +} + +static int timeout(); + +int chan_any(c) register chan *c; +{ + switch (c->type) { + case C_T_FILE: + if ((c->f.flgs&C_F_READAHEAD)!=0) + return 1; + else { + register FILE *fp= unix_file[c->f.index]; + + if (feof(fp)) + return 1; + else { + extern int errno; + register ch; + + deadlock=0; + /* No deadlock while waiting for key */ + + signal(SIGALRM, timeout); + alarm(1); + + errno=0; + ch=getc(fp); + + signal(SIGALRM, SIG_IGN); + alarm(0); + + if (errno==EINTR) + return 0; + else { + if (!feof(fp)) { + c->f.flgs|=C_F_READAHEAD; + c->f.preread=ch; + } + return 1; + } + } + } + case C_T_CHAN: + return c->c.synch==C_S_ANY; + default: + disaster(); + } +} + +/* The ch=getc(fp) in the above function calls read(2) to do its task, but if + * there's no input on the file (pipe or terminal) then the read will block. + * To stop this read from blocking, we use the fact that if the read is + * interrupted by a signal that is caught by the program, then the read returns + * error EINTR after the signal is processed. Thus we use a one second alarm + * to interrupt the read with a trap to timeout(). But since the alarm signal + * may occur *before* the read is called, it is continuously restarted in + * timeout() to prevent it from getting lost. + */ + +static int timeout(sig) +{ + signal(SIGALRM, timeout); + alarm(1); +} + +static void disaster() +{ + write(2, "Fatal error: Channel variable corrupted\n", 40); + abort(); +} diff --git a/lang/occam/lib/co.c b/lang/occam/lib/co.c new file mode 100644 index 00000000..88d3d72b --- /dev/null +++ b/lang/occam/lib/co.c @@ -0,0 +1,115 @@ +/* co.c - Routines to handle coroutines */ +#include "process.h" + +static void search(), RESUMERR(); + +void resume(id) identification id; +/* Stops the current process, by saving its stack, and searches for the + * process with identification 'id' in the group the running process + * belongs to. If 'id' cannot be found then repeat these actions with + * the running process' parent. If 'id' is found it is activated. It + * is a fatal error if 'id' cannot be found. + */ +{ + if (group!=nil) { + register wordsize size; + + size=top_size(group->s_brk); + (*group->active)->stack=alloc((unsigned) size); + + if (top_save(size, (*group->active)->stack)) + search(id); + else { + free((*group->active)->stack); + load_betweens(); + } + } else + RESUMERR(); +} + +static void search(id) identification id; +/* Searches for the process with identification 'id'. + * If the process is found it is activated and its process tree is + * traversed to find the running process. + */ +{ + register struct process **aproc, *proc; + + for(;;) { + aproc= &group->first; + + while (*aproc!=nil && (*aproc)->id!=id) + aproc= &(*aproc)->next; + + if (*aproc!=nil) break; + + save_between(group); + + if ((group=group->up)==nil) + RESUMERR(); + } + group->active=aproc; + proc= *aproc; + highest_group=group; + + while (proc->down!=nil) { + group=proc->down; + proc= *group->active; + } + top_load(proc->stack); +} + +static void delete_group(group) struct procgroup *group; +/* Removes the whole group and sub-groups recursively from the running + * process. + */ +{ + register struct process *proc, *next; + + proc=group->first; + + while (proc!=nil) { + if (proc->down!=nil) + delete_group(proc->down); + else + free(proc->stack); + next=proc->next; + free( (void *) proc); + proc=next; + } + delete_between(group); + free( (void *) group); +} + +void coend() +{ + register struct process *proc, *next; + register struct procgroup *junk; + + proc=group->first; + + while (proc!=nil) { + if (proc!= *group->active) { + if (proc->down!=nil) + delete_group(proc->down); + else + free(proc->stack); + } + next=proc->next; + free( (void *) proc); + proc=next; + } + delete_between(group); + junk=group; + group=group->up; + free( (void *) junk); + + if (group!=nil) + (*group->active)->down=nil; +} + +static void RESUMERR() +{ + write(2, "RESUMERR\n", 9); + abort(); +} diff --git a/lang/occam/lib/em2.e b/lang/occam/lib/em2.e new file mode 100644 index 00000000..fb81a1ed --- /dev/null +++ b/lang/occam/lib/em2.e @@ -0,0 +1,52 @@ + mes 2,2,4 + +oldtrp + bss 4, 0, 0 + + exp $init + pro $init, 0 + loc -321-1 + sim + lpi $catch1 + sig + sde oldtrp + cal $initfile + ret 0 + end 0 + + pro $catch1, 0 + lde oldtrp + sig + asp 4 + loe 0 + lde 4 + lol 0 + cal $catch + asp 8 + lol 0 + trp + rtt + end 0 + + exp $now + pro $now, 12 + zre deadlock + lal -12 + loc 35 + mon + asp 2 + ldl -12 + ret 4 + end 12 + + exp $block_mo + pro $block_mo, 0 + ldl 4 + ldl 8 + ldl 0 + loc 4 + loc 2 + cuu + bls 2 + ret 0 + end 0 diff --git a/lang/occam/lib/em4.e b/lang/occam/lib/em4.e new file mode 100644 index 00000000..ff948932 --- /dev/null +++ b/lang/occam/lib/em4.e @@ -0,0 +1,49 @@ + mes 2,4,4 + +oldtrp + bss 4, 0, 0 + + exp $init + pro $init, 0 + loc -321-1 + sim + lpi $catch1 + sig + ste oldtrp + cal $initfile + ret 0 + end 0 + + pro $catch1, 0 + loe oldtrp + sig + asp 4 + loe 0 + loe 4 + lol 0 + cal $catch + asp 12 + lol 0 + trp + rtt + end 0 + + exp $now + pro $now, 12 + zre deadlock + lal -12 + loc 35 + mon + asp 4 + lol -12 + ret 4 + end 12 + + exp $block_mo + pro $block_mo, 0 + lol 4 + lol 8 + lol 0 + bls 4 + ret 0 + end 0 diff --git a/lang/occam/lib/ocm_chan.h b/lang/occam/lib/ocm_chan.h new file mode 100644 index 00000000..1d456061 --- /dev/null +++ b/lang/occam/lib/ocm_chan.h @@ -0,0 +1,47 @@ +/* channel.h - channel definitions */ +#include +#include "parco.h" + +typedef union channel { + struct { /* Interprocess channel */ + char _type; /* Channel type, see note */ + char synch; /* State in channel synchronization */ + long val; /* Transmitted value */ + } c; + struct { /* File channel */ + char _type; /* Dummy field, see note */ + char index; /* Index in the file array */ + char flgs; /* Status flags: in use & readahead */ + char preread; /* Possible preread character */ + } f; +} chan; +#define type c._type /* Channel type */ +/* Note: The channel type should not be part of each structure in chan. But + * the C alignment rules would make chan about 50% bigger if we had done it + * the right way. Note that the order of fields in a struct cannot be a problem + * as long as struct c is the largest within the union. + */ + +#define C_T_CHAN 0 /* Type of a interprocess channel */ +#define C_T_FILE 1 /* Type of a file channel */ + +#define C_S_FREE 0 /* IP channel is free */ +#define C_S_ANY 1 /* IP channel contains data */ +#define C_S_ACK 2 /* IP channel data is removed */ + +#define C_F_EOF (-1L) /* File channel returns EOF */ +#define C_F_TEXT (-2L) /* File channel becomes line oriented */ +#define C_F_RAW (-3L) /* File channel becomes character oriented */ + +#define C_F_INUSE 0x01 /* File channel is connected to a UNIX file */ +#define C_F_READAHEAD 0x02 /* File channel has a preread character */ + +extern chan file[_NFILE]; /* Array of file channels */ +extern FILE *unix_file[_NFILE]; /* Pointers to buffered UNIX files */ + +void c_init(); + +void chan_in(), cbyte_in(), c_wa_in(), c_ba_in(); +void chan_out(), c_wa_out(), c_ba_out(); + +int chan_any(); diff --git a/lang/occam/lib/ocm_parco.h b/lang/occam/lib/ocm_parco.h new file mode 100644 index 00000000..1588d43c --- /dev/null +++ b/lang/occam/lib/ocm_parco.h @@ -0,0 +1,18 @@ +/* parco.h - Define names for simulation routines + * + * This file is to be included by users of the higher-level routines + * + */ + +void pc_begin(), resumenext(), parend(), resume(), coend(); +int pc_fork(); + +#define nullid ((int *) 0 - (int *) 0) + /* I.e. a 0 of type "pointer difference" */ + +#define parbegin(sbrk) pc_begin(sbrk, nullid) +#define parfork() pc_fork(nullid) +#define cobegin(sbrk, id) pc_begin(sbrk, id) +#define cofork(id) pc_fork(id) + +extern int deadlock; diff --git a/lang/occam/lib/ocm_proc.h b/lang/occam/lib/ocm_proc.h new file mode 100644 index 00000000..fcc9503b --- /dev/null +++ b/lang/occam/lib/ocm_proc.h @@ -0,0 +1,52 @@ +/* process.h - Define administration types and functions + * + * This file is to be included by implementors of the higher + * level routines + * + */ +#include "parco.h" + +#ifndef ptrdiff /* This type must be able to hold a pointer difference */ +#define ptrdiff int /* Define as long int if necessary */ +#endif + +#define nil 0 +void *alloc(), free(); + +typedef ptrdiff wordsize, identification; + +wordsize top_size(); +int top_save(); +void top_load(); /* Primitives */ + +struct procgroup; + +struct process { + struct process *next; /* Next process in the same group */ + struct procgroup *down; /* Process group running under this process */ + void *stack; /* Pointer to the saved stack top */ + identification id; /* Coroutine identification */ +}; + +#define init_between __i_b__ /* These names are hidden */ +#define save_between __s_b__ +#define load_betweens __l_b__ +#define delete_between __d_b__ + +void init_between(), save_between(), load_betweens(), delete_between(); + +struct procgroup { + struct process **active;/* Active process within this group */ + struct procgroup *up; /* The group that this group belongs to */ + struct process *first; /* List of processes belonging to this group */ + void *s_brk; /* Point where the stack is split */ + void *between; /* Stack space between s_brk and up->s_brk */ +}; + +#define group __grp__ /* Ignore this please */ +#define highest_group __hgrp__ + +extern struct procgroup *group; /* Current running group */ +extern struct procgroup *highest_group; /* highest group that has been seen + * while searching for a process + */ diff --git a/lang/occam/lib/ocrt.c b/lang/occam/lib/ocrt.c new file mode 100644 index 00000000..c39eff3c --- /dev/null +++ b/lang/occam/lib/ocrt.c @@ -0,0 +1,52 @@ +/* ocrt.c - Occam runtime support */ +#include "channel.h" + +int chandes[]= { 0, 0, sizeof(int)+sizeof(long) }; +int worddes[]= { 0, 0, sizeof(long) }; +int bytedes[]= { 0, 0, 1 }; +long any; + +void catch(sig, file, line) int sig; char *file; int line; +/* Catches traps in the occam program */ +{ + register char *mes; + + switch (sig) { + case 0: + mes="array bound error"; + break; + case 6: + mes="division by zero"; + break; + case 8: + mes="undefined variable"; + break; + default: + return; + } + fprintf(stderr, "%s (%d) F: %s\n", file, line, mes); + abort(); +} + +chan file[_NFILE]; +FILE *unix_file[_NFILE]; + +void initfile() +{ + register i; + register chan *c=file; + + for (i=0; i<_NFILE; i++) { + c->type=C_T_FILE; + c->f.flgs=0; + (c++)->f.index=i; + } + file[0].f.flgs|=C_F_INUSE; + unix_file[0]=stdin; + + file[1].f.flgs|=C_F_INUSE; + unix_file[1]=stdout; + + file[2].f.flgs|=C_F_INUSE; + unix_file[2]=stderr; +} diff --git a/lang/occam/lib/par.c b/lang/occam/lib/par.c new file mode 100644 index 00000000..ef3c4598 --- /dev/null +++ b/lang/occam/lib/par.c @@ -0,0 +1,92 @@ +/* par.c - Routines to simulate parallelism */ +#include "process.h" + +static void search_next(), DEADLOCK(); + +void resumenext() +/* Stops the current process, by saving its stack, and determines a new one + * to restart. In case the root of the process tree is passed more then once, + * without a process having done something useful, we'll have a deadlock. + */ +{ + if (group!=nil) { + register struct process *proc= *group->active; + register wordsize size; + + size=top_size(group->s_brk); + proc->stack=alloc((unsigned) size); + + if (top_save(size, proc->stack)) { + group->active= &proc->next; + search_next(); + } else { + free(proc->stack); + load_betweens(); + } + } else + if (++deadlock>1) DEADLOCK(); +} + +static void search_next() +/* Tries to resume the active process, if this is not possible, the process + * tree will be searched for another process. If the process tree is fully + * traversed, search will restart at the root of the tree. + */ +{ + while (*group->active==nil && group->up!=nil) { + save_between(group); + + group=group->up; + + group->active= &(*group->active)->next; + } + + if (*group->active==nil) { + if (++deadlock>1) DEADLOCK(); + group->active= &group->first; + } + + highest_group=group; + + while ((*group->active)->down!=nil) { + group=(*group->active)->down; + group->active= &group->first; + } + top_load((*group->active)->stack); +} + +void parend() +/* Deletes the current process from its process group and searches for a new + * process to run. The entire group is removed if this is the last process in + * the group, execution then continues with the process that set up this group + * in the first place. + */ +{ + register struct process *junk; + + junk= *group->active; + *group->active=junk->next; + free((void *) junk); + + if (group->first==nil) { + register struct procgroup *junk; + + delete_between(group); + + junk=group; + group=group->up; + free((void *) junk); + + if (group!=nil) + (*group->active)->down=nil; + } else { + deadlock=0; + search_next(); + } +} + +static void DEADLOCK() +{ + write(2, "DEADLOCK\n", 9); + abort(); +} diff --git a/lang/occam/lib/par_em2.e b/lang/occam/lib/par_em2.e new file mode 100644 index 00000000..ed45d527 --- /dev/null +++ b/lang/occam/lib/par_em2.e @@ -0,0 +1,53 @@ + mes 2,2,4 + exp $top_size + pro $top_size, 14 + ldl 0 ; s_brk + lor 1 ; s_brk SP + sbs 4 ; s_brk-SP + ret 4 ; return size of block to be saved + end 14 + + exp $top_save + pro $top_save, 0 + loe 0 + lde 4 ; load line number and file name + lim ; ignore mask + lor 0 ; LB + ldl 0 ; size of block + loc 4 + loc 2 + cuu + dup 2 + stl 0 ; push & store size in 2 bytes + lor 1 ; SP (the SP BEFORE pushing) + lor 1 ; SP (address of stack top to save) + ldl 4 ; area + lol 0 ; size + bls 2 ; move whole block + asp 18 ; remove the lot from the stack + loc 1 + ret 2 ; return 1 + end 0 + + exp $top_load + pro $top_load, 0 + ldl 0 + dup 4 + sde area ; copy area pointer from argument 0 + loi 4 ; load indirect to + str 1 ; restore SP + lde area ; load area, note that the SP is now correct + lor 1 ; SP (the SP AFTER, see above) + lde area + lof 4 ; size of block + bls 2 ; move block back (SP becomes the SP BEFORE again!) + asp 2 ; drop size + str 0 ; LB + sim ; ignore mask + sde 4 + ste 0 ; line and file + loc 0 + ret 2 ; return 0 + end 0 +area + bss 4,0,0 diff --git a/lang/occam/lib/par_em4.e b/lang/occam/lib/par_em4.e new file mode 100644 index 00000000..b47cffbd --- /dev/null +++ b/lang/occam/lib/par_em4.e @@ -0,0 +1,46 @@ + mes 2,4,4 + exp $top_size + pro $top_size, 20 + lol 0 ; s_brk + lor 1 ; s_brk SP + sbs 4 ; s_brk-SP + ret 4 ; return size of block to be saved + end 20 + + exp $top_save + pro $top_save, 0 + lde 0 ; load line number and file name + lim ; ignore mask + lor 0 ; LB + lol 0 ; size of block + lor 1 ; SP (the SP BEFORE pushing) + lor 1 ; SP (address of stack top to save) + lol 4 ; area + lol 0 ; size + bls 4 ; move whole block + asp 24 ; remove the lot from the stack + loc 1 + ret 4 ; return 1 + end 0 + + exp $top_load + pro $top_load, 0 + lol 0 + dup 4 + ste area ; copy area pointer from argument 0 + loi 4 ; load indirect to + str 1 ; restore sp + loe area ; load area, note that the SP is now correct + lor 1 ; SP (the SP AFTER, see above) + loe area + lof 4 ; size of block + bls 4 ; move block back (SP becomes the SP BEFORE again!) + asp 4 ; drop size + str 0 ; LB + sim ; ignore mask + sde 0 ; line and file + loc 0 + ret 4 ; return 0 + end 0 +area + bss 4,0,0 diff --git a/lang/occam/lib/par_vax.s b/lang/occam/lib/par_vax.s new file mode 100644 index 00000000..04ab0a97 --- /dev/null +++ b/lang/occam/lib/par_vax.s @@ -0,0 +1,51 @@ + # VAX code for the top_* primitives + + .set BIG, 0x8000 # 32K chunk per movc3 + .text + .align 1 + .globl _top_size + .globl _top_save + .globl _top_load + +_top_size: .word 0x0000 + subl3 sp, 4(ap), r0 # bytes between stack pointer and break + addl2 $(8+6+1)*4, r0 # add 8 regs, 6 pushed longwords (line, file, + ret # ap, fp, size, sp) and 1 extra argument + +_top_save: .word 0x0ff0 # save regs r4-r11 + movq hol0, -(sp) # push line number and file name + movq ap, -(sp) # push LB equivalents ap and fp + pushl 4(ap) # push size + pushal -4(sp) # push sp (the sp AFTER pushing) + movl $BIG, r6 # chunk size in r6 + movl 4(ap), r7 # size of block to move + movl sp, r1 # source address + movl 8(ap), r3 # destination address + cmpl r7, r6 + jlequ 0f +1: movc3 r6, (r1), (r3) # move chunk of the block, add r6 to r1 and r3 + subl2 r6, r7 + cmpl r7, r6 + jgtru 1b +0: movc3 r7, (r1), (r3) # move what's left + movl $1, r0 # return 1 + ret + +_top_load: .word 0x0000 + movl 4(ap), r1 # source + movl (r1), sp # restore sp + movl $BIG, r6 # chunk size + movl 4(r1), r7 # size + movl sp, r3 # destination + cmpl r7, r6 + jlequ 0f +1: movc3 r6, (r1), (r3) # move chunk of the block back + subl2 r6, r7 + cmpl r7, r6 + jgtru 1b +0: movc3 r7, (r1), (r3) # move what's left back + addl2 $8, sp # pop saved sp and size + movq (sp)+, ap # pop LB's + movq (sp)+, hol0 # pop line and file + clrl r0 # return 0 + ret diff --git a/lang/occam/lib/parco.c b/lang/occam/lib/parco.c new file mode 100644 index 00000000..55d7979b --- /dev/null +++ b/lang/occam/lib/parco.c @@ -0,0 +1,130 @@ +/* parco.c - Common routines for simulating parallelism or coroutines on + * machines with downward growing stacks + */ +#include "process.h" + +struct procgroup *group=nil, *highest_group; + +int deadlock=0; + +void pc_begin(s_brk, id) + register void *s_brk; + identification id; +/* Sets up a group of processes and puts the current process in it */ +{ + register struct procgroup *pg; + register struct process *p; + + pg= (struct procgroup *) alloc(sizeof *pg); + p= (struct process *) alloc(sizeof *p); + + pg->s_brk= s_brk==nil ? (void *) (&id +1) : s_brk; + pg->up=group; + pg->first=p; + pg->active= &pg->first; + + p->next=nil; + p->down=nil; + p->id=id; + + if (group!=nil) + (*group->active)->down=pg; + + group=pg; + init_between(group); +} + +int pc_fork(id) identification id; +/* Makes a copy of the stack top of the calling function and creates an + * entry for it in the current process group. Pc_fork() returns 1 in the + * current process, 0 in the copied process. The current process runs first. + */ +{ + register struct process *newp; + register wordsize size; + + newp= (struct process *) alloc(sizeof *newp); + + newp->down=nil; + newp->id=id; + + newp->next= *group->active; + *group->active= newp; + group->active= &newp->next; + + size=top_size(group->s_brk); + newp->stack=alloc((unsigned) size); + + if (top_save(size, newp->stack)) + return 1; + else { + free(newp->stack); + load_betweens(); + return 0; + } +} + +void init_between(group) register struct procgroup *group; +/* Allocates memory to hold the stack space between s_brk and up->s_brk. */ +{ + register wordsize size; + + if (group->up==nil + || (size= (wordsize) group->up->s_brk - (wordsize) group->s_brk)==0) + group->between=nil; + else + group->between=alloc((unsigned) size); +} + +void block_move(); + +void save_between(group) register struct procgroup *group; +/* Saves the stack space between s_brk and up->s_brk. */ +{ + register wordsize size; + + if (group->between!=nil) { + size= (wordsize) group->up->s_brk - (wordsize) group->s_brk; + block_move(size, group->s_brk, group->between); + } +} + +void load_betweens() +/* All stack pieces between s_brk and up->s_brk from the current group + * upto the 'highest_group' are loaded onto the stack at the right + * place (i.e. s_brk). + */ +{ + register struct procgroup *gr=group, *up; + register wordsize size; + + while (gr!=highest_group) { + up=gr->up; + if (gr->between!=nil) { + size= (wordsize) up->s_brk - (wordsize) gr->s_brk; + + block_move(size, gr->between, gr->s_brk); + } + gr=up; + } +} + +void delete_between(group) register struct procgroup *group; +/* Deallocates the stack space between s_brk and up->s_brk. */ +{ + if (group->between!=nil) + free(group->between); +} + +void *malloc(); + +void *alloc(size) unsigned size; +{ + register void *mem; + + if ((mem=malloc(size))==nil) { + write(2, "Heap error\n", 14); + abort(); + } + return mem; +} From 04dbef011ad532ac1b6121b77a5ea8a60365745f Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 24 Feb 1987 18:41:53 +0000 Subject: [PATCH 0882/1625] *** empty log message *** --- util/ack/Makefile | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/util/ack/Makefile b/util/ack/Makefile index 586080b8..94d04a98 100644 --- a/util/ack/Makefile +++ b/util/ack/Makefile @@ -18,9 +18,9 @@ BINDIR=$(EMHOME)/bin MANDIR=$(EMHOME)/man MODDIR=$(EMHOME)/modules/lib -head: ack +head: ack ack.1 -install: ack +install: ack ack.1 rm -f $(BINDIR)/ack cp ack $(BINDIR)/ack -cd $(BINDIR) ; \ @@ -29,13 +29,16 @@ install: ack rm -f $(MANDIR)/man/ack.1 cp ack.1 $(MANDIR)/man/ack.1 -cmp: ack +cmp: ack ack.1 -cmp ack $(BINDIR)/ack (cd pc ; make cmp ) -cmp ack.1 $(MANDIR)/ack.1 +ack.1: ack.1.X + tbl < ack.1.X > ack.1 + clean: - -rm -f *.old *.o ack + -rm -f *.old *.o ack ack.1 (cd pc ; make clean ) ack: $(OBJ) From a11db5e8cd5b054d68b2c6ddc34e78c4d8514f81 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 25 Feb 1987 11:04:30 +0000 Subject: [PATCH 0883/1625] *** empty log message *** --- mach/vax4/libbc/Makefile | 1 - mach/vax4/libbc/compmodule | 8 ++++++-- mach/vax4/libpc/compmodule | 8 ++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/mach/vax4/libbc/Makefile b/mach/vax4/libbc/Makefile index 1573b6da..c3b833f0 100644 --- a/mach/vax4/libbc/Makefile +++ b/mach/vax4/libbc/Makefile @@ -9,7 +9,6 @@ install: cmp: make -f $(MAKEFILE) $(BCDEF) $(MACHDEF) tail - -../../compare head_bc -../../compare tail_bc clean: diff --git a/mach/vax4/libbc/compmodule b/mach/vax4/libbc/compmodule index 491f6d25..6327cb99 100755 --- a/mach/vax4/libbc/compmodule +++ b/mach/vax4/libbc/compmodule @@ -1,2 +1,6 @@ -${MACH?} -I../../../h ${MACHFL?} $1 1>&2 -echo `basename $1 $2`.o +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then + echo `basename $1 $2`.o +else + exit 1 +fi diff --git a/mach/vax4/libpc/compmodule b/mach/vax4/libpc/compmodule index 491f6d25..6327cb99 100755 --- a/mach/vax4/libpc/compmodule +++ b/mach/vax4/libpc/compmodule @@ -1,2 +1,6 @@ -${MACH?} -I../../../h ${MACHFL?} $1 1>&2 -echo `basename $1 $2`.o +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then + echo `basename $1 $2`.o +else + exit 1 +fi From 472d7ea2d5ea8bc29b43d284cdc56cb563d82324 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 25 Feb 1987 13:47:15 +0000 Subject: [PATCH 0884/1625] *** empty log message *** --- doc/LLgen/Makefile | 8 ++------ doc/top/Makefile | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/doc/LLgen/Makefile b/doc/LLgen/Makefile index 0f056482..8aee6815 100644 --- a/doc/LLgen/Makefile +++ b/doc/LLgen/Makefile @@ -1,12 +1,8 @@ # $Header$ -MS=-ms EQN=eqn -NROFF=nroff REFER=refer TBL=tbl -SUF=pr -../LLgen.$(SUF): LLgen.doc LLgen.refs - $(REFER) -sA+T -p LLgen.refs LLgen.doc | $(EQN) | $(TBL) | \ - $(NROFF) $(MS) > $@ +../LLgen.doc: LLgen.n LLgen.refs + $(REFER) -sA+T -p LLgen.refs LLgen.n | $(EQN) | $(TBL) > $@ diff --git a/doc/top/Makefile b/doc/top/Makefile index a572b6d3..acd50d8b 100644 --- a/doc/top/Makefile +++ b/doc/top/Makefile @@ -1,11 +1,7 @@ # $Header$ -MS=-ms -NROFF=nroff REFER=refer TBL=tbl -SUF=pr -../top.$(SUF): top.n refs.top - $(REFER) -sA+T -l4,2 -p refs.top top.n | $(TBL) | \ - $(NROFF) $(MS) > $@ +../top.doc: top.n refs.top + $(REFER) -sA+T -l4,2 -p refs.top top.n | $(TBL) > $@ From ddbeb5aba5b44a6a2fa085ef752b10e71f692f0f Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 25 Feb 1987 16:41:09 +0000 Subject: [PATCH 0885/1625] my version (CJ) --- lang/occam/lib/LIST | 11 +++++++ lang/occam/lib/builtin.c | 2 +- lang/occam/lib/channel.c | 10 +++---- lang/occam/lib/co.c | 2 +- lang/occam/lib/misc.e | 49 +++++++++++++++++++++++++++++++ lang/occam/lib/now.c | 8 +++++ lang/occam/lib/ocrt.c | 8 ++--- lang/occam/lib/par.c | 2 +- lang/occam/lib/par_misc.e | 62 +++++++++++++++++++++++++++++++++++++++ lang/occam/lib/parco.c | 2 +- 10 files changed, 143 insertions(+), 13 deletions(-) create mode 100644 lang/occam/lib/LIST create mode 100644 lang/occam/lib/misc.e create mode 100644 lang/occam/lib/now.c create mode 100644 lang/occam/lib/par_misc.e diff --git a/lang/occam/lib/LIST b/lang/occam/lib/LIST new file mode 100644 index 00000000..b1256766 --- /dev/null +++ b/lang/occam/lib/LIST @@ -0,0 +1,11 @@ +tail_ocm.a +builtin.c +chan_struct.c +channel.c +co.c +now.c +par.c +parco.c +misc.e +ocrt.c +par_misc.e diff --git a/lang/occam/lib/builtin.c b/lang/occam/lib/builtin.c index 37ed2e89..71c77efb 100644 --- a/lang/occam/lib/builtin.c +++ b/lang/occam/lib/builtin.c @@ -1,5 +1,5 @@ /* builtin.c - built in named processes */ -#include "channel.h" +#include "ocm_chan.h" #ifndef nil #define nil 0 #endif diff --git a/lang/occam/lib/channel.c b/lang/occam/lib/channel.c index 630f932f..1c4ce966 100644 --- a/lang/occam/lib/channel.c +++ b/lang/occam/lib/channel.c @@ -2,7 +2,7 @@ #include #include #include -#include "channel.h" +#include "ocm_chan.h" static void disaster(); @@ -53,16 +53,16 @@ void chan_out(v, c) long v; register chan *c; putc( (int) v, fp); else if (v==C_F_TEXT) { - ioctl(fileno(fp), TIOCGETP, &tty); + gtty(fileno(fp), &tty); tty.sg_flags&= ~CBREAK; tty.sg_flags|= ECHO|CRMOD; - ioctl(fileno(fp), TIOCSETN, &tty); + stty(fileno(fp), &tty); } else if (v==C_F_RAW) { - ioctl(fileno(fp), TIOCGETP, &tty); + gtty(fileno(fp), &tty); tty.sg_flags|= CBREAK; tty.sg_flags&= ~(ECHO|CRMOD); - ioctl(fileno(fp), TIOCSETN, &tty); + stty(fileno(fp), &tty); } } break; case C_T_CHAN: diff --git a/lang/occam/lib/co.c b/lang/occam/lib/co.c index 88d3d72b..ff803887 100644 --- a/lang/occam/lib/co.c +++ b/lang/occam/lib/co.c @@ -1,5 +1,5 @@ /* co.c - Routines to handle coroutines */ -#include "process.h" +#include "ocm_proc.h" static void search(), RESUMERR(); diff --git a/lang/occam/lib/misc.e b/lang/occam/lib/misc.e new file mode 100644 index 00000000..abfc7b62 --- /dev/null +++ b/lang/occam/lib/misc.e @@ -0,0 +1,49 @@ +# + mes 2,EM_WSIZE,EM_PSIZE + +oldtrp + bss EM_PSIZE, 0, 0 + + exp $init + pro $init, 0 + loc -321-1 + sim + lpi $catch1 + sig + lae oldtrp + sti EM_PSIZE + cal $initfile + ret 0 + end 0 + + pro $catch1, 0 + lae oldtrp + loi EM_PSIZE + sig + asp EM_PSIZE + loe 0 + lae 4 + loi EM_PSIZE + lol 0 + cal $catch + asp 2*EM_WSIZE+EM_PSIZE + lol 0 + trp + rtt + end 0 + + exp $block_move + pro $block_move, 0 + lal 4 + loi EM_PSIZE + lal 8 + loi EM_PSIZE + + lal 0 + loi EM_LSIZE + loc EM_LSIZE + loc EM_WSIZE + cuu + bls EM_WSIZE + ret 0 + end 0 diff --git a/lang/occam/lib/now.c b/lang/occam/lib/now.c new file mode 100644 index 00000000..9ce234d0 --- /dev/null +++ b/lang/occam/lib/now.c @@ -0,0 +1,8 @@ +long now() +{ + extern int deadlock; + long time(); + + deadlock = 0; + return time((long *) 0); +} diff --git a/lang/occam/lib/ocrt.c b/lang/occam/lib/ocrt.c index c39eff3c..e3061d93 100644 --- a/lang/occam/lib/ocrt.c +++ b/lang/occam/lib/ocrt.c @@ -1,5 +1,5 @@ /* ocrt.c - Occam runtime support */ -#include "channel.h" +#include "ocm_chan.h" int chandes[]= { 0, 0, sizeof(int)+sizeof(long) }; int worddes[]= { 0, 0, sizeof(long) }; @@ -28,15 +28,15 @@ void catch(sig, file, line) int sig; char *file; int line; abort(); } -chan file[_NFILE]; -FILE *unix_file[_NFILE]; +chan file[20]; +FILE *unix_file[20]; void initfile() { register i; register chan *c=file; - for (i=0; i<_NFILE; i++) { + for (i=0; i<20; i++) { c->type=C_T_FILE; c->f.flgs=0; (c++)->f.index=i; diff --git a/lang/occam/lib/par.c b/lang/occam/lib/par.c index ef3c4598..9830ec43 100644 --- a/lang/occam/lib/par.c +++ b/lang/occam/lib/par.c @@ -1,5 +1,5 @@ /* par.c - Routines to simulate parallelism */ -#include "process.h" +#include "ocm_proc.h" static void search_next(), DEADLOCK(); diff --git a/lang/occam/lib/par_misc.e b/lang/occam/lib/par_misc.e new file mode 100644 index 00000000..3d181ade --- /dev/null +++ b/lang/occam/lib/par_misc.e @@ -0,0 +1,62 @@ +# + mes 2,EM_WSIZE,EM_PSIZE + exp $top_size + pro $top_size, 3*EM_WSIZE+3*EM_PSIZE + mes 11 + lal 0 + loi EM_PSIZE ; s_brk + lor 1 ; s_brk SP + sbs EM_PSIZE ; s_brk-SP + ret EM_PSIZE ; return size of block to be saved + end 3*EM_WSIZE+3*EM_PSIZE + + exp $top_save + pro $top_save, 0 + loe 0 + lae 4 ; load line number and file name + loi EM_PSIZE + lim ; ignore mask + lor 0 ; LB + lal 0 + loi EM_PSIZE ; size of block + loc EM_PSIZE + loc EM_WSIZE + cuu + dup EM_WSIZE + stl 0 ; push & store size in 2 bytes + lor 1 ; SP (the SP BEFORE pushing) + lor 1 ; SP (address of stack top to save) + lal EM_PSIZE ; area + loi EM_PSIZE + lol 0 ; size + bls EM_WSIZE ; move whole block + asp 3*EM_PSIZE+3*EM_WSIZE ; remove the lot from the stack + loc 1 + ret EM_WSIZE ; return 1 + end 0 + + exp $top_load + pro $top_load, 0 + lal 0 + loi EM_PSIZE + dup EM_PSIZE + loi EM_PSIZE + sti EM_PSIZE ; copy pointer from argument 0 to new frame + loi EM_PSIZE ; load indirect to + str 1 ; restore SP + dup EM_PSIZE ; givesargument 0 again + lor 1 ; SP (the SP AFTER, see above) + lor 1 + adp EM_PSIZE + loi EM_PSIZE + lof EM_PSIZE ; size of block + bls EM_WSIZE ; move block back (SP becomes the SP BEFORE again!) + asp EM_WSIZE ; drop size + str 0 ; LB + sim ; ignore mask + lae EM_PSIZE + sti EM_PSIZE + ste 0 ; line and file + loc 0 + ret EM_WSIZE ; return 0 + end 0 diff --git a/lang/occam/lib/parco.c b/lang/occam/lib/parco.c index 55d7979b..26c114e1 100644 --- a/lang/occam/lib/parco.c +++ b/lang/occam/lib/parco.c @@ -1,7 +1,7 @@ /* parco.c - Common routines for simulating parallelism or coroutines on * machines with downward growing stacks */ -#include "process.h" +#include "ocm_proc.h" struct procgroup *group=nil, *highest_group; From 022c39ec18fef206d57bcab5220087508a1eb1a8 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 25 Feb 1987 16:41:54 +0000 Subject: [PATCH 0886/1625] Initial revision --- lang/occam/lib/chan_strct.c | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 lang/occam/lib/chan_strct.c diff --git a/lang/occam/lib/chan_strct.c b/lang/occam/lib/chan_strct.c new file mode 100644 index 00000000..5fcb3e8b --- /dev/null +++ b/lang/occam/lib/chan_strct.c @@ -0,0 +1,39 @@ +/* chan_struct.c - channel routines for more structured objects */ +#include "ocm_chan.h" + +void cbyte_in(b, c) char *b; chan *c; +{ + long v; + chan_in(&v, c); + *b= (char) v; +} + +void c_wa_in(a, z, c) register long *a; register unsigned z; register chan *c; +{ + do + chan_in(a++, c); + while (--z!=0); +} + +void c_ba_in(a, z, c) register char *a; register unsigned z; register chan *c; +{ + do { + long v; + chan_in(&v, c); + *a++ = (char) v; + } while (--z!=0); +} + +void c_wa_out(a, z, c) register long *a; register unsigned z; register chan *c; +{ + do + chan_out(*a++, c); + while (--z!=0); +} + +void c_ba_out(a, z, c) register char *a; register unsigned z; register chan *c; +{ + do + chan_out((long) (*a++ &0377), c); + while (--z!=0); +} From 4aa4410a0879d2392cd327fd7aae5aec751f7ee2 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 25 Feb 1987 16:42:41 +0000 Subject: [PATCH 0887/1625] *** empty log message *** --- lang/occam/lib/LIST | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/occam/lib/LIST b/lang/occam/lib/LIST index b1256766..e2772a19 100644 --- a/lang/occam/lib/LIST +++ b/lang/occam/lib/LIST @@ -1,6 +1,6 @@ tail_ocm.a builtin.c -chan_struct.c +chan_strct.c channel.c co.c now.c From fec9150769d94f08816fa869323a18239c2e5ad4 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 25 Feb 1987 16:56:31 +0000 Subject: [PATCH 0888/1625] my version (CJ) --- lang/occam/comp/Makefile | 29 +++++++++++-- lang/occam/comp/builtin.c | 21 +++++----- lang/occam/comp/em.c | 26 ++++++------ lang/occam/comp/em.h | 1 + lang/occam/comp/lex.l | 8 ++-- lang/occam/comp/occam.g | 85 +++++++++++++++++++++++++++++++++------ lang/occam/comp/report.c | 22 ++++++---- lang/occam/comp/sizes.h | 3 +- lang/occam/comp/symtab.c | 6 +-- 9 files changed, 146 insertions(+), 55 deletions(-) diff --git a/lang/occam/comp/Makefile b/lang/occam/comp/Makefile index e8608d09..033e954a 100644 --- a/lang/occam/comp/Makefile +++ b/lang/occam/comp/Makefile @@ -1,12 +1,19 @@ +EMHOME = ../../.. +MODLIB = $(EMHOME)/modules/lib +INCL = -I$(EMHOME)/modules/h GFILES= occam.g PRIMARY= occam.o Lpars.o keytab.o lex.yy.o code.o em.o SECUNDARY= symtab.o expr.o builtin.o TERTIARY= report.o LLOPT= -LIBRARY= -lln libemk.a libsystem.a +LIBRARY= $(MODLIB)/libem_mes.a $(MODLIB)/libemk.a \ + $(MODLIB)/libprint.a $(MODLIB)/libstring.a \ + $(MODLIB)/libsystem.a -lln +CFLAGS = -O $(INCL) +HSRC = code.h em.h expr.h sizes.h symtab.h token.h +CSRC = builtin.c code.c em.c expr.c keytab.c report.c symtab.c -all: - make dummy +all: dummy make oc dummy: $(GFILES) @@ -19,6 +26,22 @@ oc: $(PRIMARY) $(SECUNDARY) $(TERTIARY) lex.yy.c: lex.l lex lex.l +install: all + rm -f $(EMHOME)/lib/em_occam + cp oc $(EMHOME)/lib/em_occam + +cmp: all + -cmp oc $(EMHOME)/lib/em_occam + +pr: + @pr Makefile $(HSRC) occam.g lex.l $(CSRC) + +opr: + make pr | opr + +clean: + rm -f lex.yy.c occam.c *.o oc + $(PRIMARY): Lpars.h occam.o keytab.o: token.h occam.o $(SECUNDARY): symtab.h expr.h diff --git a/lang/occam/comp/builtin.c b/lang/occam/comp/builtin.c index f1c7a913..be705a82 100644 --- a/lang/occam/comp/builtin.c +++ b/lang/occam/comp/builtin.c @@ -1,4 +1,3 @@ -#include #include "symtab.h" #include "expr.h" #include "sizes.h" @@ -32,43 +31,43 @@ void init_builtins() info.vc.st.builtin=file; info.vc.offset=0; - insert(file, T_CHAN|T_ARR|T_BUILTIN, _NFILE, info); + insert(file, T_CHAN|T_ARR|T_BUILTIN, 20, &info); info.vc.st.builtin=file; info.vc.offset=0; - insert("input", T_CHAN|T_BUILTIN, 1, info); + insert("input", T_CHAN|T_BUILTIN, 1, &info); info.vc.st.builtin=file; info.vc.offset=wz+pz; - insert("output", T_CHAN|T_BUILTIN, 1, info); + insert("output", T_CHAN|T_BUILTIN, 1, &info); info.vc.st.builtin=file; info.vc.offset=2*(wz+pz); - insert("error", T_CHAN|T_BUILTIN, 1, info); + insert("error", T_CHAN|T_BUILTIN, 1, &info); /* DEF EOF= -1, TEXT= -2, RAW= -3: */ info.const=new_const(-1L); - insert("EOF", T_CONST|T_BUILTIN, 0, info); + insert("EOF", T_CONST|T_BUILTIN, 0, &info); info.const=new_const(-2L); - insert("TEXT", T_CONST|T_BUILTIN, 0, info); + insert("TEXT", T_CONST|T_BUILTIN, 0, &info); info.const=new_const(-3L); - insert("RAW", T_CONST|T_BUILTIN, 0, info); + insert("RAW", T_CONST|T_BUILTIN, 0, &info); /* PROC open(VAR fd, VALUE name[], mode[])= .... : */ info.proc.st.builtin="b_open"; info.proc.pars=open_list; - insert("open", T_PROC|T_BUILTIN, 0, info); + insert("open", T_PROC|T_BUILTIN, 0, &info); /* PROC close(VALUE fd)= .... : */ info.proc.st.builtin="b_close"; info.proc.pars=close_list; - insert("close", T_PROC|T_BUILTIN, 0, info); + insert("close", T_PROC|T_BUILTIN, 0, &info); /* PROC exit(VALUE code)= .... : */ info.proc.st.builtin="b_exit"; info.proc.pars=exit_list; - insert("exit", T_PROC|T_BUILTIN, 0, info); + insert("exit", T_PROC|T_BUILTIN, 0, &info); } diff --git a/lang/occam/comp/em.c b/lang/occam/comp/em.c index 814b1c1f..b05cac01 100644 --- a/lang/occam/comp/em.c +++ b/lang/occam/comp/em.c @@ -1,8 +1,6 @@ -#include #include "sizes.h" #include "Lpars.h" -#include "em_arith.h" -#include "em_label.h" +#include #include "em.h" /* This file is used to shield code.c as much as possible from em dependant @@ -12,7 +10,8 @@ * word or double word arith. */ -int wz, pz; +int wz = 4, pz = 4, vz = 4; +int Lflag; static Lab=0; char *malloc(); @@ -23,15 +22,14 @@ void init() void openfile(file) char *file; { - C_open(file); + if (C_open(file) < 0) { + fatal("Could not open output file"); + } } void meswp() { - C_mes_begin(2); - C_cst((arith) wz); - C_cst((arith) pz); - C_mes_end(); + C_ms_emx((arith) wz, (arith) pz); } void maxdes() @@ -82,7 +80,7 @@ char *proc_label(L, name) register L; register char *name; lab=malloc(strlen(name)+(1+sizeof(int)*3+1)); /* That is: P\0 */ - sprintf(lab, "P%d", L); + sprint(lab, "P%d", L); n=lab+strlen(lab); @@ -278,7 +276,7 @@ void lol(offset) int offset; { C_lol((arith) offset); } void lor0() { C_lor((arith) 0); } void lxa(offset) int offset; { C_lxa((arith) offset); } void lxl(offset) int offset; { C_lxl((arith) offset); } -void meserr() { C_mes_begin(0); C_mes_end(); } +void meserr() { C_ms_err(); } void ngi() { C_ngi((arith) vz); } void pro(lab) char *lab; { C_pro_narg(lab); } void ret(size) int size; { C_ret((arith) size); } @@ -300,7 +298,7 @@ void zne(lab) int lab; { C_zne((label) lab); } char *itoa(i) long i; { static char a[sizeof(long)*3]; - sprintf(a, "%D", i); + sprint(a, "%ld", i); return a; } @@ -314,6 +312,7 @@ void lin() static oldline=0; extern yylineno; + if (Lflag) return; if (yylineno!=oldline) C_lin((arith) (oldline=yylineno)); } @@ -328,9 +327,10 @@ char *curr_file="stdin"; static void do_fil(f) struct ftree *f; { + if (Lflag) return; if (f->lab==0) { dot_label(new_dot_label(&f->lab)); - C_rom_scon(f->file, (arith) strlen(f->file)); + C_rom_scon(f->file, (arith) (strlen(f->file)+1)); } C_fil_dlb((label) f->lab); } diff --git a/lang/occam/comp/em.h b/lang/occam/comp/em.h index 3ead9964..9b86490b 100644 --- a/lang/occam/comp/em.h +++ b/lang/occam/comp/em.h @@ -19,3 +19,4 @@ void init_rt(), exp(), rom(), blt(), magic(), lin(), tst(), fil(), trp(); void main_fil(), init(), openfile(), closefile(), maxdes(); void par_begin(), par_fork(), par_end(), resumenext(), no_deadlock(); +extern int Lflag; diff --git a/lang/occam/comp/lex.l b/lang/occam/comp/lex.l index 86f1277e..dc644b25 100644 --- a/lang/occam/comp/lex.l +++ b/lang/occam/comp/lex.l @@ -271,9 +271,9 @@ char *tokenname(tk, inst) register tk, inst; static char c[7]; if (' ' +#include #define MAXERRORS 10 /* Maximum number of insert/delete errors */ @@ -158,7 +160,7 @@ replicator(register struct symbol **s; register struct expr **e1, **e2; ) sym_down(); var_memory(&info, T_VAR, 1); *s=insert(index, - T_VAR|T_REP|T_USED|T_ASSIGNED, 1, info); + T_VAR|T_REP|T_USED|T_ASSIGNED, 1, &info); } ; @@ -306,7 +308,7 @@ chan { register type, arr_siz=1; register char *name; struct expr *e; }: ]? { chan_memory(&info, arr_siz); chan_init(&info, arr_siz); - insert(name, type, arr_siz, info); + insert(name, type, arr_siz, &info); } ; @@ -332,7 +334,7 @@ var { register type, byte=0, arr_siz=1; } ]? { var_memory(&info, type, arr_siz); - insert(name, type, arr_siz, info); + insert(name, type, arr_siz, &info); } ; @@ -342,7 +344,7 @@ const_def { register char *name; struct expr *e; }: { if (!constant(e) && !arr_constant(e)) nonconst("expression in constant definition"); info.const=e; - insert(name, T_CONST|T_USED, 0, info); + insert(name, T_CONST|T_USED, 0, &info); } ; @@ -366,7 +368,7 @@ form_parm(register struct par_list ***aapars; register *g_type;) { type|=T_ARR; } ]? { pars_add(aapars, type&(T_TYPE|T_ARR), - insert(name, type|T_PARAM, 0, none)); + insert(name, type|T_PARAM, 0, &none)); } ; @@ -394,7 +396,7 @@ proc_declaration { struct par_list *pars=nil; }: PROC IDENTIFIER { branch(&OVER); proc=insert(token.t_sval, - T_PROC|T_RECURS, 0, none); + T_PROC|T_RECURS, 0, &none); old_min_offset=min_offset; sym_down(); prologue(proc); @@ -614,12 +616,14 @@ val_expr(register struct expr **e;) : %lexical scanner; { int err=0; -#include main(argc, argv) register argc; register char **argv; { - wz= (argc>1 && strcmp(argv[1], "4")==0) ? 4 : 2; - pz= (argc>2 && strcmp(argv[2], "4")==0) ? 4 : wz; + while (argc > 1 && argv[1][0] == '-') { + do_option(&argv[1][1]); + argc--; + argv++; + } leader(); occam(); @@ -628,6 +632,64 @@ main(argc, argv) register argc; register char **argv; exit(err); } +do_option(text) + char *text; +{ + extern int Lflag; + + switch(*text++) { + + default: + fatal("illegal option: %c", *--text); + + case 'L' : /* no fil/lin */ + Lflag++; + break; + case 'V' : /* set object sizes and alignment requirements */ + { + arith size, align; + char c; + + while (c = *text++) { + size = txt2int(&text); + switch (c) { + case 'w': /* word */ + if (size != (arith)0) + wz = size; + break; + case 'p': /* pointer */ + if (size != (arith)0) + pz = size; + break; + case 'l': /* long */ + if (size != (arith)0) + vz = size; + break; + default: + fatal("-V: bad type indicator %c\n", c); + } + } + break; + } + } +} + +int +txt2int(tp) + char **tp; +{ + /* the integer pointed to by *tp is read, while increasing + *tp; the resulting value is yielded. + */ + register int val = 0, ch; + + while (ch = **tp, ch >= '0' && ch <= '9') { + val = val * 10 + ch - '0'; + (*tp)++; + } + return val; +} + LLmessage(tk) register tk; { static errors=0; @@ -639,11 +701,10 @@ LLmessage(tk) register tk; if (tk==0) warning("syntax error: bad token %s (deleted)", tokenname(LLsymb, 0)); else { /* tk<0 */ - fprintf(stderr, "Compiler stack overflow. Compiler ends."); - err=1; trailer(); exit(1); + warning("syntax error: garbage at end of program"); } if (++errors==MAXERRORS) { - fprintf(stderr, "Too many insert/delete errors. Compiler ends.\n"); + fprint(STDERR, "Too many insert/delete errors. Compiler ends.\n"); err=1; trailer(); exit(1); } } diff --git a/lang/occam/comp/report.c b/lang/occam/comp/report.c index e7385c64..4dfe7564 100644 --- a/lang/occam/comp/report.c +++ b/lang/occam/comp/report.c @@ -1,19 +1,27 @@ -#include +#include extern int err, yylineno; extern char *curr_file; report(fmt, arg1, arg2, arg3) char *fmt; { - fprintf(stderr, "%s (%d) F: ", curr_file, yylineno); - fprintf(stderr, fmt, arg1, arg2, arg3); - putc('\n', stderr); + fprint(STDERR, "%s (%d) F: ", curr_file, yylineno); + fprint(STDERR, fmt, arg1, arg2, arg3); + fprint(STDERR,"\n"); err=1; } warning(fmt, arg1, arg2, arg3) char *fmt, *arg1; { - fprintf(stderr, "%s (%d) E: ", curr_file, yylineno); - fprintf(stderr, fmt, arg1, arg2, arg3); - putc('\n', stderr); + fprint(STDERR, "%s (%d) E: ", curr_file, yylineno); + fprint(STDERR, fmt, arg1, arg2, arg3); + fprint(STDERR,"\n"); +} + +fatal(fmt, arg1, arg2, arg3) char *fmt, *arg1; +{ + fprint(STDERR, "%s (%d) X: ", curr_file, yylineno); + fprint(STDERR, fmt, arg1, arg2, arg3); + fprint(STDERR,"\n"); + exit(1); } diff --git a/lang/occam/comp/sizes.h b/lang/occam/comp/sizes.h index df0b3c7b..a4f211b2 100644 --- a/lang/occam/comp/sizes.h +++ b/lang/occam/comp/sizes.h @@ -1,5 +1,4 @@ /* Variable size, wordsize, pointer size. Offsets for local variables. */ -#define vz 4 -extern int wz, pz; +extern int wz, pz, vz; extern int curr_level, curr_offset, min_offset; diff --git a/lang/occam/comp/symtab.c b/lang/occam/comp/symtab.c index 40494262..48e738f9 100644 --- a/lang/occam/comp/symtab.c +++ b/lang/occam/comp/symtab.c @@ -27,7 +27,7 @@ static struct symbol **search_sym(tree, name) struct symbol *insert(name, type, arr_siz, info) char *name; int type, arr_siz; - union type_info info; + union type_info *info; /* Inserts an object with given name and other info into the current symbol * tree. A pointer is returned to the inserted symbol so that more info may * or changed. Nil is returned on redeclaration. @@ -49,7 +49,7 @@ struct symbol *insert(name, type, arr_siz, info) type|=T_USED; /* are always used */ ps->type=type; ps->arr_siz=arr_siz; - ps->info=info; + ps->info= *info; ps->left=ps->right=nil; *aps=ps; @@ -70,7 +70,7 @@ struct symbol *searchall(name) char *name; tab=tab->global; } report("%s not declared", name); - return insert(name, T_NOTDECL, 0, none); + return insert(name, T_NOTDECL, 0, &none); } void check_recursion(proc) From f60da36c5bc1780748cb33774d842c2ca4ee61b6 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 25 Feb 1987 16:58:32 +0000 Subject: [PATCH 0889/1625] *** empty log message *** --- lang/occam/lib/par_misc.e | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/occam/lib/par_misc.e b/lang/occam/lib/par_misc.e index 3d181ade..d96bc67c 100644 --- a/lang/occam/lib/par_misc.e +++ b/lang/occam/lib/par_misc.e @@ -54,7 +54,7 @@ asp EM_WSIZE ; drop size str 0 ; LB sim ; ignore mask - lae EM_PSIZE + lae 4 sti EM_PSIZE ste 0 ; line and file loc 0 From 75a0c4d5f2910a6fbcd1d366e4f613b5d7213742 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 25 Feb 1987 17:14:10 +0000 Subject: [PATCH 0890/1625] Initial revision --- lang/occam/test/Huffman.ocm | 193 +++++++++++++++++++++++++++ lang/occam/test/READ_ME | 1 + lang/occam/test/aatob.ocm | 25 ++++ lang/occam/test/copy.ocm | 26 ++++ lang/occam/test/key.ocm | 14 ++ lang/occam/test/lifegame.ocm | 248 +++++++++++++++++++++++++++++++++++ lang/occam/test/matmul.ocm | 98 ++++++++++++++ lang/occam/test/sort.ocm | 49 +++++++ lang/occam/test/tst.ocm | 24 ++++ lang/occam/test/use_prnt.ocm | 17 +++ lang/occam/test/xxtoy.ocm | 32 +++++ 11 files changed, 727 insertions(+) create mode 100644 lang/occam/test/Huffman.ocm create mode 100644 lang/occam/test/READ_ME create mode 100644 lang/occam/test/aatob.ocm create mode 100644 lang/occam/test/copy.ocm create mode 100644 lang/occam/test/key.ocm create mode 100644 lang/occam/test/lifegame.ocm create mode 100644 lang/occam/test/matmul.ocm create mode 100644 lang/occam/test/sort.ocm create mode 100644 lang/occam/test/tst.ocm create mode 100644 lang/occam/test/use_prnt.ocm create mode 100644 lang/occam/test/xxtoy.ocm diff --git a/lang/occam/test/Huffman.ocm b/lang/occam/test/Huffman.ocm new file mode 100644 index 00000000..a4174368 --- /dev/null +++ b/lang/occam/test/Huffman.ocm @@ -0,0 +1,193 @@ +def + bits.in.character = 8, + number.of.characters= 1 << bits.in.character, + number.of.codes = number.of.characters + 1, + character.mask = not ((not 0) << bits.in.character): + +def + root = 0, size.of.tree = (2* number.of.codes)-1, not.a.node = size.of.tree: + +var + escape, weight[size.of.tree], + children[size.of.tree], parent[size.of.tree], + character[size.of.tree], representative[number.of.characters] : + +proc construct.tree = + -- Create a tree for the encoding in which every character is escaped + seq + escape := root + weight[escape] := 1 + children[escape] := root -- it is a leaf + seq ch= [0 for number.of.characters] + representative[ch] := not.a.node : + +proc create.leaf(var new.leaf, value ch) = + -- Extend the tree by fision of the escape leaf into two new leaves + var new.escape: + seq + new.leaf := escape + 1 + new.escape := escape + 2 + + children[escape] := new.leaf -- escape is the new parent + + weight[new.leaf] := 0 + children[new.leaf] := root + parent[new.leaf] := escape + character[new.leaf] := ch + representative[ch /\ character.mask] := new.leaf + + weight[new.escape] := 1 + children[new.escape]:= root + parent[new.escape] := escape + + escape := new.escape : + +proc swap.trees(value i, j) = + -- Exchange disjoint sub-trees routed at i and j + proc swap.words(var p,q) = + -- Exchange values stored in p and q + var t: + seq + t := p + p := q + q := t : + + proc adjust.offspring(value i) = + -- Restore downstream pointers to node i + if + children[i] = root + representative[character[i] /\ character.mask] := i + children[i] <> root + seq child=[children[i] for 2] + parent[child] := i : + + seq + swap.words(children[i], children[j]) + swap.words(character[i], character[j]) + adjust.offspring(i) + adjust.offspring(j) : + +proc increment.frequency(value ch) = + -- Adjust the weights of all relevant nodes to account for one more occurence + -- of the character ch, and adjust the shape of the tree if necessary + var node: + seq + if + representative[ch /\ character.mask] <> not.a.node + node := representative[ch /\ character.mask] + representative[ch /\ character.mask] = not.a.node + create.leaf(node, ch) + while node <> root + if + weight[node-1] > weight[node] + seq + weight[node] := weight[node] + 1 + node := parent[node] + weight[node-1] = weight[node] + if i= [1 for (node-root)-1] + weight[(node-i)-1] > weight[node] + seq + swap.trees(node, node-i) + node := node-i + weight[root] := weight[root] + 1 : + +proc encode.character(chan output, value ch) = + -- Transmit the encoding of ch along output + def size.of.encoding = bits.in.character + (number.of.codes - 1) : + var encoding[size.of.encoding], length, node: + seq + if + representative[ch /\ character.mask] <> not.a.node + seq + length := 0 + node := representative[ch /\ character.mask] + representative[ch /\ character.mask] = not.a.node + seq + seq i=[0 for bits.in.character] + encoding[i] := (ch >> i) /\ 1 -- i'th bit of unencoded ch + length := bits.in.character + node := escape + while node <> root + seq + encoding[length] := node - children[parent[node]] + length := length + 1 + node := parent[node] + seq i= [1 for length] + output ! encoding[length-i] : + +proc decode.character(chan input, var ch) = + -- Receive an encoding along input and store the corresponding character in ch + var node: + seq + node := root + while children[node] <> root + var bit: + seq + input ? bit + node := children[node] + bit + if + node < escape + ch := character[node] + node = escape + var bit: + seq + input ? bit + ch := -bit + seq i= [2 for bits.in.character - 1] + seq + input ? bit + ch := (ch << 1) \/ bit : + +def end.of.message = -1: + +proc copy.encoding(chan source, sink) = + -- Read a stream of characters from source, until signalled on end.of.source, + -- and transmit their encodings in sequence along sink, followed by that of + -- end.of.message, maintaining throughout the encoding tree for the encoding + -- determined by the cumulative frequencies of the characters transmitted + var more.characters.expected: + seq + construct.tree + more.characters.expected := true + while more.characters.expected + var ch: + seq + source ? ch + if + ch <> end.of.message + seq + encode.character(sink, ch) + increment.frequency(ch) + ch = end.of.message + more.characters.expected := false + encode.character(sink, end.of.message) : + +proc copy.decoding(chan source, sink) = + -- Read the encodings of a stream of characters, up to and including the + -- encoding of end.of.message, from source and transmit the corresponding + -- characters along sink, maintaining the encoding tree for encoding + -- determined by the cumulative frequencies of the characters received + var more.characters.expected: + seq + construct.tree + more.characters.expected := true + while more.characters.expected + var ch: + seq + decode.character(source, ch) + if + ch <> end.of.message + seq + sink ! ch + increment.frequency(ch) + ch = end.of.message + more.characters.expected:=false : + +var choose: +seq + input ? choose + if + choose='e' + copy.encoding(input, output) + choose='d' + copy.decoding(input, output) diff --git a/lang/occam/test/READ_ME b/lang/occam/test/READ_ME new file mode 100644 index 00000000..baa24c03 --- /dev/null +++ b/lang/occam/test/READ_ME @@ -0,0 +1 @@ +This directory only contains some Occam programs, not a testset. diff --git a/lang/occam/test/aatob.ocm b/lang/occam/test/aatob.ocm new file mode 100644 index 00000000..a2338ab0 --- /dev/null +++ b/lang/occam/test/aatob.ocm @@ -0,0 +1,25 @@ +def otherwise=true: + +proc xxtoy(chan in, out, value x, y)= + var c: + seq + c:= not EOF + while c<>EOF + seq + in ? c + if + c=x + seq + in ? c + if + c=x + out ! y + otherwise + out ! x; c + otherwise + out ! c +: +chan link: +par + xxtoy(input, link, 'a', 'b') + xxtoy(link, output, 'b', 'c') diff --git a/lang/occam/test/copy.ocm b/lang/occam/test/copy.ocm new file mode 100644 index 00000000..dff3f4fc --- /dev/null +++ b/lang/occam/test/copy.ocm @@ -0,0 +1,26 @@ +def N=10: + +proc copy(chan in, out)= + var char: + seq + char:='x' + while char<>EOF + seq + in ? char + out ! char +: + +chan junk[N]: +par + copy(input, junk[0]) + + par i=[0 FOR N-1] + copy(junk[i], junk[i+1]) + + var char: + seq + junk[N-1] ? char + while char<>EOF + seq + output ! char + junk[N-1] ? char diff --git a/lang/occam/test/key.ocm b/lang/occam/test/key.ocm new file mode 100644 index 00000000..e840b78a --- /dev/null +++ b/lang/occam/test/key.ocm @@ -0,0 +1,14 @@ +#include "dec.ocm" +var ch: +seq + output ! RAW + + input ? ch + + seq i=[0 for 10] + seq + decout(output, ch, 0) + output ! '*n' + input ? ch + + output ! TEXT diff --git a/lang/occam/test/lifegame.ocm b/lang/occam/test/lifegame.ocm new file mode 100644 index 00000000..8a82f353 --- /dev/null +++ b/lang/occam/test/lifegame.ocm @@ -0,0 +1,248 @@ +def otherwise=true: + +def dead=0, alive= not dead: + +def radius=1, + diameter= (2*radius)+1, + neighbours= (diameter*diameter)-1: + +proc calculate.next.state(chan link[], value in[], state, var next.state)= + var count: + seq + var state.of.neighbour[neighbours]: + seq + par i=[0 for neighbours] + link[in[i]] ? state.of.neighbour[i] + count:=0 + seq i=[0 for neighbours] + if + state.of.neighbour[i]=alive + count:=count+1 + state.of.neighbour[i]=dead + skip + if + count<2 + next.state:=dead + count=2 + next.state:=state + count=3 + next.state:=alive + count>3 + next.state:=dead +: + +proc broadcast.present.state(chan link[], value out[], state)= + par i=[0 for neighbours] + link[out[i]] ! state +: + +def set.state=1, ask.state=2, terminate=3: + +proc cell(chan link[], value in[], out[], chan control, sense)= + var state, instruction: + seq + state:=dead + control ? instruction + while instruction <> terminate + seq + if + instruction=set.state + control ? state + instruction=ask.state + var next.state: + seq + par + broadcast.present.state(link, out, state) + seq + calculate.next.state(link, in, state, + next.state) + sense ! (state<>next.state); next.state + + state:=next.state + + control ? instruction +: + +def array.width=5, array.height=5: +def number.of.cells=array.height*array.width, + number.of.links=neighbours*number.of.cells: + +proc initialize(value x, y, var in[], out[])= + seq delta.x=[-radius for diameter] + seq delta.y=[-radius for diameter] + var direction: + seq + direction:=delta.x+(diameter*delta.y) + if + direction<>0 + var index, process: + seq + process:=x+(array.width*y) + index:=(neighbours+direction) \ (neighbours+1) + out[index]:=index+(neighbours*process) + + process:=((x+delta.x+array.width) \ array.width) + + (array.width* + ((y+delta.y+array.height) \ array.height)) + index:=(neighbours-direction) \ (neighbours+1) + in[index]:=index+(neighbours*process) + direction=0 + skip +: + +def control= not ((not 0)<<5), escape=control/\'[': + +proc move.cursor(chan screen, value x, y)= + screen ! escape; '='; '*s'+y; '*s'+x +: + +proc initialize.display(chan screen)= + screen ! control /\ 'Z' +: + +proc clean.up.display(chan screen)= + move.cursor(screen, 0, array.height) +: + +proc display.state(chan screen, value x, y, state)= + seq + move.cursor(screen, x, y) + if + state=alive + screen ! '**' + state=dead + screen ! '*s' +: + +proc generation(chan screen, control[], sense[], var active)= + seq + seq cell=[0 for number.of.cells] + control[cell] ! ask.state + active:=false + seq cell=[0 for number.of.cells] + var changed, next.state: + seq + sense[cell] ? changed; next.state + if + changed + seq + display.state(screen, cell\array.width, + cell/array.width, next.state) + active:=true + not changed + skip +: + +proc edit(chan keyboard, screen, control[])= + def ctrl= not ((not 0)<<5): + def left.key= 'h', right.key= 'l', up.key= 'k', down.key= 'j', + uproot.key= '*s', plant.key= '**', plant.key2= '8': + var x, y, editing, ch: + seq + x:=array.width/2 + y:=array.height/2 + editing:=true + while editing + seq + move.cursor(screen, x, y) + keyboard ? ch + if + (ch=left.key) and (x>0) + x:=x-1 + (ch=right.key) and (x<(array.width-1)) + x:=x+1 + (ch=up.key) and (y>0) + y:=y-1 + (ch=down.key) and (y<(array.height-1)) + y:=y+1 + (ch=uproot.key) or (ch=plant.key) or (ch=plant.key2) + var state: + seq + state:=(dead /\ (ch=uproot.key)) \/ + (alive /\ ((ch=plant.key) or (ch=plant.key2))) + control[x+(array.width*y)] ! set.state; state + display.state(screen, x, y, state) + (ch='q') or (ch='Q') + editing:=false + otherwise + skip +: + +def idle=1, editing=2, single.stepping=3, free.running=4, terminated=5: + +proc display.activity(chan screen, value activity)= + seq + move.cursor(screen, array.width+1, array.height+2) + + proc write.string(value str[])= + seq i=[1 for str[byte 0]] + screen ! str[byte i] + : + if + activity=idle + write.string("Idle") + activity=editing + write.string("Edit") + activity=single.stepping + write.string("Step") + activity=free.running + write.string("Busy") + activity=terminated + write.string("Done") +: + +proc controller(chan keyboard, screen, control[], sense[])= + var activity: + seq + activity:=idle + initialize.display(screen) + while activity<>terminated + seq + display.activity(screen, activity) + var ch: + pri alt + (activity <> editing) & keyboard ? ch + if + (ch='q') or (ch='Q') + activity:=terminated + (ch='i') or (ch='I') + activity:=idle + (ch='e') or (ch='E') + activity:=editing + (ch='r') or (ch='R') + activity:=free.running + (ch='s') or (ch='S') + activity:=single.stepping + (activity=editing) & skip + seq + edit(keyboard, screen, control) + activity:=idle + (activity=free.running) or (activity=single.stepping) & skip + var changing: + seq + generation(screen, control, sense, changing) + if + (activity=single.stepping) or (not changing) + activity:=idle + (activity=free.running) and changing + skip + display.activity(screen, activity) + seq cell=[0 for number.of.cells] + control[cell] ! terminate + clean.up.display(screen) +: + +chan link[number.of.links], control[number.of.cells], sense[number.of.cells]: +seq + output ! RAW + par + controller(input, output, control, sense) + + par x=[0 for array.width] + par y=[0 for array.height] + var in[neighbours], out[neighbours]: + seq + initialize(x, y, in, out) + cell(link, in, out, control[x+(array.width*y)], + sense[x+(array.width*y)]) + output ! TEXT diff --git a/lang/occam/test/matmul.ocm b/lang/occam/test/matmul.ocm new file mode 100644 index 00000000..be558f65 --- /dev/null +++ b/lang/occam/test/matmul.ocm @@ -0,0 +1,98 @@ +#include "dec.ocm" + +proc prompt(value str[])= + seq i=[1 for str[byte 0]] + output ! str[byte i] +: +def N=20 : + +var n: +var A[N*N], x[N], k[N], y[N] : + +proc initialise= + var c: + seq + prompt("n?*n") + c:='*s' + decin(input, n, c) + + prompt("A?*n") + seq i= [0 for n] + seq j= [0 for n] + decin(input, A[(i*n)+j], c) + + prompt("x?*n") + seq i= [0 for n] + decin(input, x[i], c) + + prompt("k?*n") + seq i= [0 for n] + decin(input, k[i], c) : + +proc produce.xj(value j, chan south) = + -- north row: source of x values + while true + south ! x[j] : + +proc consume.yi(value i, chan east) = + -- west column: read y values + east ? y[i] : + +proc offset(value ki, chan west) = + -- east column: source of k offsets + while true + west ! ki : + +proc multiplier(value aij, chan north, south, west, east) = + -- middle: responsible for a values + var xj, aij.times.xj, yi : + seq + north ? xj + while true + seq + par + south ! xj + aij.times.xj:= aij*xj + east ? yi + par + west ! yi+aij.times.xj + north ? xj : + +proc sink(chan north) = + -- south row: sink for unused outputs + while true + north ? any : + +seq + initialise + + chan north.south[(N+1)*N], east.west[N*(N+1)] : + par + par j= [0 for n] -- producer of co-ordinates x[j] + produce.xj(j, north.south[j]) + + par -- the matrix multiplier + par i= [0 for n] + offset(k[i], east.west[(n*n)+i]) + par i= [0 for n] + par j= [0 for n] + multiplier(A[(n*i)+j], + north.south[(n*i)+j], + north.south[(n*(i+1))+j], + east.west[i+(n*j)], + east.west[i+(n*(j+1))]) + par j= [0 for n] + sink(north.south[(n*n)+j]) + + seq + par i= [0 for n]-- consumer of transformed co-ordinates + consume.yi(i, east.west[i]) + + seq i= [0 for n] + seq + output ! 'y'; '[' + decout(output, i, 0) + output ! ']'; '=' + decout(output, y[i], 5) + output ! '*n' + exit(0) diff --git a/lang/occam/test/sort.ocm b/lang/occam/test/sort.ocm new file mode 100644 index 00000000..a220cff8 --- /dev/null +++ b/lang/occam/test/sort.ocm @@ -0,0 +1,49 @@ +-- This file contains a recursive call to sorter, so this is not really Occam. +#include "dec.ocm" + +var c: +seq + c:='*s' + proc comparator(value num, chan in, out)= + var old.num, new.num: + seq + old.num:=num + in ? new.num + while new.num + seq + in ? new.num + if + new.num<=old.num + out ! true; new.num + new.num>old.num + seq + out ! true; old.num + old.num:=new.num + in ? new.num + out ! true; old.num; false + : + proc sorter(chan out)= + chan in: + var num: + seq + decin(input, num, c) + if + c<0 + out ! false + c>=0 + par + sorter(in) + comparator(num, in, out) + : + chan out: + var num: + par + sorter(out) + seq + out ? num + while num + seq + out ? num + decout(output, num, 0) + output ! '*n' + out ? num diff --git a/lang/occam/test/tst.ocm b/lang/occam/test/tst.ocm new file mode 100644 index 00000000..7064d84e --- /dev/null +++ b/lang/occam/test/tst.ocm @@ -0,0 +1,24 @@ +#include +#include + +var fmt[byte 100]: +var d, c: +seq + input ? c + decin(input, d, c) + while c<>EOF + seq + chan link: + par + printd(link, "XXXX %%%ds XXXXX*#00", d) + var c, i: + seq + i:=0 + link ? c + while c<>0 + seq + i:=i+1 + fmt[byte i]:=c + link ? c + prints("XXXX %s XXXXX", "YYYYY") + decin(input, d, c) diff --git a/lang/occam/test/use_prnt.ocm b/lang/occam/test/use_prnt.ocm new file mode 100644 index 00000000..6b0ab188 --- /dev/null +++ b/lang/occam/test/use_prnt.ocm @@ -0,0 +1,17 @@ +#include +#include + +seq + printd(output, "philosopher %d eats ice*n", 2048) + printd(output, "phil. %20d also*n", 65536) + chan link: + par + printd(link, "%d times %d makes 100*n", 10) + + var c: + seq + c:='x' + while c<>'*n' + seq + link ? c + output ! c diff --git a/lang/occam/test/xxtoy.ocm b/lang/occam/test/xxtoy.ocm new file mode 100644 index 00000000..d2f2cb23 --- /dev/null +++ b/lang/occam/test/xxtoy.ocm @@ -0,0 +1,32 @@ +def otherwise=true: + +def NLET= ('z'-'a')+1: + +proc xxtoy(chan in, out, value x, y)= + var c: + seq + c:= not EOF + while c<>EOF + seq + in ? c + if + c=x + seq + in ? c + if + c=x + out ! y + otherwise + out ! x; c + otherwise + out ! c +: +chan link[NLET-1]: + +par + xxtoy(input, link[0], 'a', 'b') + + par i=[0 for NLET-2] + xxtoy(link[i], link[i+1], i+'b', i+'c') + + xxtoy(link[NLET-2], output, 'y', 'z') From da0d5fda242004caa64b19867be6e68e1b341f3d Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 25 Feb 1987 18:30:22 +0000 Subject: [PATCH 0891/1625] Initial revision --- lang/occam/test/Makefile | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 lang/occam/test/Makefile diff --git a/lang/occam/test/Makefile b/lang/occam/test/Makefile new file mode 100644 index 00000000..caf85228 --- /dev/null +++ b/lang/occam/test/Makefile @@ -0,0 +1,42 @@ +.SUFFIXES: .ocm + +.ocm.o: + ack -c $< + +ALL = Huffman aatob copy key lifegame matmul sort tst use_prnt xxtoy + +all: $(ALL) + +install: all + +cmp: all + +clean: + rm -f *.o $(ALL) nohup.out + +pr: + @pr Makefile *.ocm + +opr: + make pr | opr + +Huffman: Huffman.o + ack -.ocm -o Huffman Huffman.o +use_prnt: use_prnt.o + ack -.ocm -o use_prnt use_prnt.o +xxtoy: xxtoy.o + ack -.ocm -o xxtoy xxtoy.o +aatob: aatob.o + ack -.ocm -o aatob aatob.o +copy: copy.o + ack -.ocm -o copy copy.o +key: key.o + ack -.ocm -o key key.o +lifegame: lifegame.o + ack -.ocm -o lifegame lifegame.o +matmul: matmul.o + ack -.ocm -o matmul matmul.o +sort: sort.o + ack -.ocm -o sort sort.o +tst: tst.o + ack -.ocm -o tst tst.o From 87c7762c6206b621e058d45ed95488fce758f004 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 25 Feb 1987 18:54:14 +0000 Subject: [PATCH 0892/1625] *** empty log message *** --- util/ack/ack.1.X | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/util/ack/ack.1.X b/util/ack/ack.1.X index d12c9616..8c8ff874 100644 --- a/util/ack/ack.1.X +++ b/util/ack/ack.1.X @@ -24,6 +24,8 @@ ack \- Amsterdam Compiler Kit .br \fBint\fP arguments .br +\fBocm\fP arguments +.br \fImachine\fP arguments .SH DESCRIPTION This program transforms sources in several @@ -60,6 +62,8 @@ Pascal program. C module. .IP .b Basic program. +.IP .ocm +Occam program. .IP .e EM assembly module in human readable form. .IP .k @@ -157,7 +161,7 @@ routines for systems calls needed by both C and Pascal. When linking multiple \fI.o\fP or \fI.m\fP files created by separate calls of \fIack\fP together, \fIack\fP cannot deduce the run-time system needed, -unless called as \fIapc\fP or \fIacc\fP. +unless called as \fIapc\fP, \fIabc\P, \fIocm\fP or \fIacc\fP. This flag serves to tell \fIack\fP which runtime system is needed in such a case. For example: "ack \-c x.c ; ack \-.c x.o". @@ -168,7 +172,7 @@ These flags tell \fIack\fP to include the libraries needed when a file with \fIsuffix\fP would be included in the arguments. .IP \-LIB This flag tells the peephole optimizer -.RF em_opt VI +.RF em_opt 6 to add information about the visibility of the names used to each output module. This is needed by @@ -266,15 +270,20 @@ input:name:output:description \&.c:cem:.k:C front end [4,5,6] \&.p:pc:.k:Pascal front end [2,3,6] \&.b:abc:.k:Basic front end [6,8] +\&.ocm:ocm:.k:Occam front end [9] \&.e:encode:.k:Compactify EM assembly language [1] \&.k:opt:.m:EM peephole optimizer \&.k .m:decode:.e:Produce human readable EM assembly \&.k .m:emass:e.out:Linker producing EM machine code [1] -\&.m:be:.s:backend -\&.s:asld:.out:Assembler/linker producing machine code in Ack a.out format -\&.s:as:.o:Assembler -\&.o:ld:a.out:Linker producing machine code -\&.o:led:.out:Linker producing machine code in Ack a.out format +\&.m:ego:.gk:EM global optimizer [10] +\&.gk:opt2:.g:Second EM peephole optimizer +\&.m .g:be:.s:backend +\&.s:asopt:.so:target opotimizer +\&.s .so:asld:.out:Assembler/linker, Ack object format +\&.s .so:as:.o:Assembler, relocatable object +\&.o:ld:a.out:Linker, machine a.out format +\&.o:led:.out:Linker, Ack object format +\&.o:cv:a.out:Conversion from Ack object to machine object .TE .in -2 .SH "SEE ALSO" @@ -283,7 +292,7 @@ em_opt(6), em_ass(6), em_cg(6), ack.out(5) .IP [1] A.S. Tanenbaum, Hans van Staveren, Ed Keizer and Johan Stevenson \fIDescription of a machine architecture for use with -block structured languages\fP Informatica report IR-81. +block structured languages\fP, Informatica rapport IR-81. .IP [2] K. Jensen and N. Wirth \fIPASCAL, User manual and report\fP Springer Verlag. @@ -300,6 +309,11 @@ Amsterdam Compiler Kit, reference manuals and UNIX manual pages. E.G. Keizer, Ack description file reference manual. .IP [8] M.L. Kersten, \fIThe ABC compiler\fP. +.IP [9] +Kees Bot and Edwin Scheffer, \fIAn Occam Compiler\fP, IM-6. +.IP [10] +H.E. Bal, \fIThe design and implementation of the EM Global Optimizer\fP, +Informatica rapport IR-99. .PD .SH DIAGNOSTICS .PD From 838085ac2b01da9c5f53d2e3e34fe91b72a64516 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 25 Feb 1987 19:00:04 +0000 Subject: [PATCH 0893/1625] adapted for new C-compiler --- lang/cem/ctest/Out2.nf.std | 591 +++++++++++++++++++------ lang/cem/ctest/Out2.std | 596 +++++++++++++++++++++----- lang/cem/ctest/Out4.nf.std | 857 ++++++++----------------------------- lang/cem/ctest/Out4.std | 574 +++---------------------- 4 files changed, 1210 insertions(+), 1408 deletions(-) diff --git a/lang/cem/ctest/Out2.nf.std b/lang/cem/ctest/Out2.nf.std index 29053b77..35d21e44 100644 --- a/lang/cem/ctest/Out2.nf.std +++ b/lang/cem/ctest/Out2.nf.std @@ -1,33 +1,33 @@ -Fri Feb 15 14:24:12 MET 1985 +Wed Feb 25 13:13:37 MET 1987 ***** ctconv -acc -DNOFLOAT conv.c +vax2 -DNOFLOAT conv.c conv.c -"conv.c", line 48: warning: Overflow in constant expression +"conv.c", line 48: (warning) overflow in constant expression running conv.cem comparing conv 2a3,4 > (float) 12 = 12.000000 > (int) 3.14 = 3 11,$c13,$ -< char 255, int 255, unsigned 377, long 255 -< char 255, int 255, unsigned 377, long 255 +< char -1, int -1, unsigned 177777, long -1 +< char -1, int -1, unsigned 177777, long -1 < From integer -< char 192, int -64, unsigned 177700, long -64 +< char -64, int -64, unsigned 177700, long -64 < From long -< char 253, int -3, unsigned 177775, long -3 +< char -3, int -3, unsigned 177775, long -3 < a[l] (l==3) -17 < a[3l] -17 --- > float 127.000000 -> char 255, int 255, unsigned 377, long 255 -> float 255.000000 -> char 255, int 255, unsigned 377, long 255 -> float 255.000000 +> char -1, int -1, unsigned 37777777777, long -1 +> float -1.000000 +> char -1, int -1, unsigned 37777777777, long -1 +> float -1.000000 > From integer -> char 192, int -64, unsigned 177700, long -64 +> char -64, int -64, unsigned 37777777700, long -64 > float -64.000000 > From long -> char 253, int -3, unsigned 177775, long -3 +> char -3, int -3, unsigned 37777777775, long -3 > float -3.000000 > From float > char 121, int 121, unsigned 171, long 121, float 121.500000 @@ -37,23 +37,57 @@ comparing conv > a[l] (l==3) -17 > a[3l] -17 ***** ctdecl -acc -DNOFLOAT decl.c +vax2 -DNOFLOAT decl.c decl.c running decl.cem comparing decl ***** ctdivers -acc -DNOFLOAT ops.c +vax2 -DNOFLOAT ops.c ops.c running ops.cem comparing ops +24,39c24,39 +< u<<1 121632 +< u<<2 43464 +< u<<3 107150 +< u<<4 16320 +< u<<5 34640 +< u<<6 71500 +< u<<7 163200 +< u<<8 146400 +< u<<9 115000 +< u<<10 32000 +< u<<11 64000 +< u<<12 150000 +< u<<13 120000 +< u<<14 40000 +< u<<15 100000 +< u<<16 0 +--- +> u<<1 321632 +> u<<2 643464 +> u<<3 1507150 +> u<<4 3216320 +> u<<5 6434640 +> u<<6 15071500 +> u<<7 32163200 +> u<<8 64346400 +> u<<9 150715000 +> u<<10 321632000 +> u<<11 643464000 +> u<<12 1507150000 +> u<<13 3216320000 +> u<<14 6434640000 +> u<<15 15071500000 +> u<<16 32163200000 ***** cterr -acc -DNOFLOAT bugs.c +vax2 -DNOFLOAT bugs.c bugs.c -"bugs.c", line 98: warning: Overflow in constant expression +"bugs.c", line 98: (warning) overflow in constant expression running bugs.cem comparing bugs ***** ctest1 -acc -DNOFLOAT test.c +vax2 -DNOFLOAT test.c test.c running test.cem comparing test @@ -62,49 +96,28 @@ comparing test --- > End of test program, 11 tests completed, 0 errors detected ***** ctest2 -acc -DNOFLOAT t7.c +vax2 -DNOFLOAT t7.c t7.c -"t7.c", line 163: warning: statement not reached -"t7.c", line 180: warning: statement not reached -"t7.c", line 184: warning: statement not reached -"t7.c", line 188: warning: statement not reached -"t7.c", line 192: warning: statement not reached -"t7.c", line 196: warning: statement not reached -"t7.c", line 200: warning: statement not reached -"t7.c", line 207: warning: statement not reached -"t7.c", line 209: warning: statement not reached -"t7.c", line 213: warning: statement not reached -"t7.c", line 215: warning: statement not reached -"t7.c", line 289: warning: statement not reached -"t7.c", line 296: warning: statement not reached -"t7.c", line 302: warning: statement not reached -"t7.c", line 309: warning: statement not reached -"t7.c", line 345: warning: statement not reached -"t7.c", line 346: warning: statement not reached -"t7.c", line 347: warning: statement not reached -"t7.c", line 348: warning: statement not reached -"t7.c", line 350: warning: statement not reached -"t7.c", line 454: warning: statement not reached -"t7.c", line 563: warning: statement not reached -"t7.c", line 591: warning: statement not reached running t7.cem comparing t7 ***** ctest3 -acc -DNOFLOAT test2.c +vax2 -DNOFLOAT test2.c test2.c +"test2.c", line 459: (warning) conversion of pointer to int loses accuracy +"test2.c", line 459: (warning) conversion of pointer to int loses accuracy running test2.cem comparing test2 ***** ctest5 -acc -DNOFLOAT test1.c +vax2 -DNOFLOAT test1.c test1.c -"test1.c", line 386: warning: illegal pointer combination -"test1.c", line 387: warning: illegal pointer combination -"test1.c", line 388: warning: illegal pointer combination -"test1.c", line 400: warning: illegal pointer combination -"test1.c", line 423: warning: illegal pointer combination -"test1.c", line 424: warning: illegal pointer combination -"test1.c", line 425: warning: illegal pointer combination -"test1.c", line 437: warning: illegal pointer combination +"test1.c", line 386: (warning) incompatible pointers in = +"test1.c", line 387: (warning) incompatible pointers in = +"test1.c", line 388: (warning) incompatible pointers in = +"test1.c", line 400: (warning) incompatible pointers in = +"test1.c", line 423: (warning) incompatible pointers in = +"test1.c", line 424: (warning) incompatible pointers in = +"test1.c", line 425: (warning) incompatible pointers in = +"test1.c", line 437: (warning) incompatible pointers in = running test1.cem comparing test1 1,$c1,$ @@ -116,105 +129,445 @@ comparing test1 > 11 tests completed. Number of errors = 1 ***** ctgen sed -f bf.sed bf.c -acc -DNOFLOAT bf.c +vax2 -DNOFLOAT bf.c bf.c running bf.cem comparing bf sed -f cel.sed cel.c -acc -DNOFLOAT cel.c +vax2 -DNOFLOAT cel.c cel.c running cel.cem comparing cel sed -f clu.sed clu.c -acc -DNOFLOAT clu.c +vax2 -DNOFLOAT clu.c clu.c -"clu.c", line 60: warning: Overflow in constant expression -"clu.c", line 66: warning: Overflow in constant expression +"clu.c", line 60: (warning) overflow in unsigned constant expression +"clu.c", line 66: (warning) overflow in unsigned constant expression running clu.cem comparing clu +23,31c23,31 +< x = 40000 -25536 +< x += 40000 -25526 +< x -= 40000 25546 +< x /= 40000 0 +< x %= 40000 10 +< x *= 40000 6784 +< x &= 40000 0 +< x |= 40000 -25526 +< x ^= 40000 -25526 +--- +> x = 40000 40000 +> x += 40000 40010 +> x -= 40000 -39990 +> x /= 40000 0 +> x %= 40000 10 +> x *= 40000 400000 +> x &= 40000 0 +> x |= 40000 40010 +> x ^= 40000 40010 +38c38 +< y = ( 40000 + 8012 ) -17524 +--- +> y = ( 40000 + 8012 ) 48012 +42,52c42,52 +< y = ( 40000 * 8012 ) 8960 +< y = ( 40000 & 8012 ) 7232 +< y = ( 40000 | 8012 ) -24756 +< y = ( 40000 ^ 8012 ) -31988 +< y = ( 40000 || 8012 ) 1 +< y = ( 40000 && 8012 ) 1 +< y = ( 40000 << 9 ) -32768 +< y = ( 40000 >> 9 ) 78 +< y = ( -40000 ) 25536 +< y = ( !40000 ) 0 +< y = ( ~40000 ) 25535 +--- +> y = ( 40000 * 8012 ) 320480000 +> y = ( 40000 & 8012 ) 7232 +> y = ( 40000 | 8012 ) 40780 +> y = ( 40000 ^ 8012 ) 33548 +> y = ( 40000 || 8012 ) 1 +> y = ( 40000 && 8012 ) 1 +> y = ( 40000 << 9 ) 20480000 +> y = ( 40000 >> 9 ) 78 +> y = ( -40000 ) -40000 +> y = ( !40000 ) 0 +> y = ( ~40000 ) -40001 +59,68c59,68 +< y = ( 40000 ? 40000 : 8012 ) -25536 +< y = ( x = 40000 ) -25536 -25536 +< y = ( x += 40000 ) -25526 -25526 +< y = ( x -= 40000 ) 25546 25546 +< y = ( x /= 40000 ) 0 0 +< y = ( x %= 40000 ) 10 10 +< y = ( x *= 40000 ) 6784 6784 +< y = ( x &= 40000 ) 0 0 +< y = ( x |= 40000 ) -25526 -25526 +< y = ( x ^= 40000 ) -25526 -25526 +--- +> y = ( 40000 ? 40000 : 8012 ) 40000 +> y = ( x = 40000 ) 40000 40000 +> y = ( x += 40000 ) 40010 40010 +> y = ( x -= 40000 ) -39990 -39990 +> y = ( x /= 40000 ) 0 0 +> y = ( x %= 40000 ) 10 10 +> y = ( x *= 40000 ) 400000 400000 +> y = ( x &= 40000 ) 0 0 +> y = ( x |= 40000 ) 40010 40010 +> y = ( x ^= 40000 ) 40010 40010 +97,105c97,105 +< yes if ( x = 40000 ) yes() ; else no() -25536 +< yes if ( x += 40000 ) yes() ; else no() -25526 +< yes if ( x -= 40000 ) yes() ; else no() 25546 +< no if ( x /= 40000 ) yes() ; else no() 0 +< yes if ( x %= 40000 ) yes() ; else no() 10 +< yes if ( x *= 40000 ) yes() ; else no() 6784 +< no if ( x &= 40000 ) yes() ; else no() 0 +< yes if ( x |= 40000 ) yes() ; else no() -25526 +< yes if ( x ^= 40000 ) yes() ; else no() -25526 +--- +> yes if ( x = 40000 ) yes() ; else no() 40000 +> yes if ( x += 40000 ) yes() ; else no() 40010 +> yes if ( x -= 40000 ) yes() ; else no() -39990 +> no if ( x /= 40000 ) yes() ; else no() 0 +> yes if ( x %= 40000 ) yes() ; else no() 10 +> yes if ( x *= 40000 ) yes() ; else no() 400000 +> no if ( x &= 40000 ) yes() ; else no() 0 +> yes if ( x |= 40000 ) yes() ; else no() 40010 +> yes if ( x ^= 40000 ) yes() ; else no() 40010 sed -f ec.sed ec.c -acc -DNOFLOAT ec.c +vax2 -DNOFLOAT ec.c ec.c -"ec.c", line 58: warning: Overflow in constant expression -"ec.c", line 64: warning: Overflow in constant expression +"ec.c", line 58: (warning) overflow in constant expression +"ec.c", line 64: (warning) overflow in constant expression running ec.cem comparing ec sed -f ef.sed ef.c -acc -DNOFLOAT ef.c +vax2 -DNOFLOAT ef.c ef.c running ef.cem comparing ef sed -f ei.sed ei.c -acc -DNOFLOAT ei.c +vax2 -DNOFLOAT ei.c ei.c -"ei.c", line 22: warning: Overflow in constant expression -"ei.c", line 65: warning: Overflow in constant expression -"ei.c", line 108: warning: Overflow in constant expression +"ei.c", line 22: (warning) overflow in constant expression +"ei.c", line 65: (warning) overflow in constant expression +"ei.c", line 108: (warning) overflow in constant expression running ei.cem comparing ei +32c32 +< x <<= 15 -32768 +--- +> x <<= 15 8355840 +48c48 +< y = ( 4 << 15 ) 0 +--- +> y = ( 4 << 15 ) 131072 +69c69 +< y = ( x <<= 15 ) -32768 -32768 +--- +> y = ( x <<= 15 ) 8355840 8355840 +85c85 +< no if ( 4 << 15 ) yes() ; else no() +--- +> yes if ( 4 << 15 ) yes() ; else no() +106c106 +< yes if ( x <<= 15 ) yes() ; else no() -32768 +--- +> yes if ( x <<= 15 ) yes() ; else no() 8355840 sed -f el.sed el.c -acc -DNOFLOAT el.c +vax2 -DNOFLOAT el.c el.c running el.cem comparing el sed -f eu.sed eu.c -acc -DNOFLOAT eu.c +vax2 -DNOFLOAT eu.c eu.c -"eu.c", line 58: warning: Overflow in constant expression -"eu.c", line 64: warning: Overflow in constant expression +"eu.c", line 58: (warning) overflow in unsigned constant expression +"eu.c", line 64: (warning) overflow in unsigned constant expression running eu.cem comparing eu +23,31c23,31 +< x = 40000 -25536 +< x += 40000 -25526 +< x -= 40000 25546 +< x /= 40000 0 +< x %= 40000 10 +< x *= 40000 6784 +< x &= 40000 0 +< x |= 40000 -25526 +< x ^= 40000 -25526 +--- +> x = 40000 40000 +> x += 40000 40010 +> x -= 40000 -39990 +> x /= 40000 0 +> x %= 40000 10 +> x *= 40000 400000 +> x &= 40000 0 +> x |= 40000 40010 +> x ^= 40000 40010 +38c38 +< y = ( 40000 + 8012 ) -17524 +--- +> y = ( 40000 + 8012 ) 48012 +42,52c42,52 +< y = ( 40000 * 8012 ) 8960 +< y = ( 40000 & 8012 ) 7232 +< y = ( 40000 | 8012 ) -24756 +< y = ( 40000 ^ 8012 ) -31988 +< y = ( 40000 || 8012 ) 1 +< y = ( 40000 && 8012 ) 1 +< y = ( 40000 << 9 ) -32768 +< y = ( 40000 >> 9 ) 78 +< y = ( -40000 ) 25536 +< y = ( !40000 ) 0 +< y = ( ~40000 ) 25535 +--- +> y = ( 40000 * 8012 ) 320480000 +> y = ( 40000 & 8012 ) 7232 +> y = ( 40000 | 8012 ) 40780 +> y = ( 40000 ^ 8012 ) 33548 +> y = ( 40000 || 8012 ) 1 +> y = ( 40000 && 8012 ) 1 +> y = ( 40000 << 9 ) 20480000 +> y = ( 40000 >> 9 ) 78 +> y = ( -40000 ) -40000 +> y = ( !40000 ) 0 +> y = ( ~40000 ) -40001 +59,68c59,68 +< y = ( 40000 ? 40000 : 8012 ) -25536 +< y = ( x = 40000 ) -25536 -25536 +< y = ( x += 40000 ) -25526 -25526 +< y = ( x -= 40000 ) 25546 25546 +< y = ( x /= 40000 ) 0 0 +< y = ( x %= 40000 ) 10 10 +< y = ( x *= 40000 ) 6784 6784 +< y = ( x &= 40000 ) 0 0 +< y = ( x |= 40000 ) -25526 -25526 +< y = ( x ^= 40000 ) -25526 -25526 +--- +> y = ( 40000 ? 40000 : 8012 ) 40000 +> y = ( x = 40000 ) 40000 40000 +> y = ( x += 40000 ) 40010 40010 +> y = ( x -= 40000 ) -39990 -39990 +> y = ( x /= 40000 ) 0 0 +> y = ( x %= 40000 ) 10 10 +> y = ( x *= 40000 ) 400000 400000 +> y = ( x &= 40000 ) 0 0 +> y = ( x |= 40000 ) 40010 40010 +> y = ( x ^= 40000 ) 40010 40010 +97,105c97,105 +< yes if ( x = 40000 ) yes() ; else no() -25536 +< yes if ( x += 40000 ) yes() ; else no() -25526 +< yes if ( x -= 40000 ) yes() ; else no() 25546 +< no if ( x /= 40000 ) yes() ; else no() 0 +< yes if ( x %= 40000 ) yes() ; else no() 10 +< yes if ( x *= 40000 ) yes() ; else no() 6784 +< no if ( x &= 40000 ) yes() ; else no() 0 +< yes if ( x |= 40000 ) yes() ; else no() -25526 +< yes if ( x ^= 40000 ) yes() ; else no() -25526 +--- +> yes if ( x = 40000 ) yes() ; else no() 40000 +> yes if ( x += 40000 ) yes() ; else no() 40010 +> yes if ( x -= 40000 ) yes() ; else no() -39990 +> no if ( x /= 40000 ) yes() ; else no() 0 +> yes if ( x %= 40000 ) yes() ; else no() 10 +> yes if ( x *= 40000 ) yes() ; else no() 400000 +> no if ( x &= 40000 ) yes() ; else no() 0 +> yes if ( x |= 40000 ) yes() ; else no() 40010 +> yes if ( x ^= 40000 ) yes() ; else no() 40010 sed -f id.sed id.c -acc -DNOFLOAT id.c +vax2 -DNOFLOAT id.c id.c running id.cem comparing id +26,28c26,28 +< y = ( (-40) - 300 ) -15190 +< y = ( (-40) / 300 ) 0 +< y = ( (-40) * 300 ) -14533 +--- +> y = ( (-40) - 300 ) 50346 +> y = ( (-40) / 300 ) 0 +> y = ( (-40) * 300 ) -2147432645 +39,48c39,48 +< y = ( (-40) ? (-40) : 300 ) -15584 +< y = ( x = (-40) ) -4.000000e+01 -15584 +< y = ( x += (-40) ) -3.685850e+01 -15597 +< y = ( x -= (-40) ) 4.314150e+01 17196 +< y = ( x /= (-40) ) -7.853750e-02 -16736 +< y = ( x *= (-40) ) -1.256600e+02 -15365 +< y = ( x ++ ) 4.141500e+00 16713 +< y = ( x -- ) 2.141500e+00 16713 +< y = ( -- x ) 2.141500e+00 16649 +< y = ( ++ x ) 4.141500e+00 16772 +--- +> y = ( (-40) ? (-40) : 300 ) 49952 +> y = ( x = (-40) ) -4.000000e+01 49952 +> y = ( x += (-40) ) -3.685850e+01 1864024851 +> y = ( x -= (-40) ) 4.314150e+01 -1864023252 +> y = ( x /= (-40) ) -7.853750e-02 -666583392 +> y = ( x *= (-40) ) -1.256600e+02 1374405627 +> y = ( x ++ ) 4.141500e+00 240533833 +> y = ( x -- ) 2.141500e+00 240533833 +> y = ( -- x ) 2.141500e+00 240533769 +> y = ( ++ x ) 4.141500e+00 -2027208316 sed -f lc.sed lc.c -acc -DNOFLOAT lc.c +vax2 -DNOFLOAT lc.c lc.c -"lc.c", line 60: warning: Overflow in constant expression -"lc.c", line 66: warning: Overflow in constant expression +"lc.c", line 60: (warning) overflow in constant expression +"lc.c", line 66: (warning) overflow in constant expression running lc.cem comparing lc sed -f ld.sed ld.c -acc -DNOFLOAT ld.c +vax2 -DNOFLOAT ld.c ld.c running ld.cem comparing ld sed -f lf.sed lf.c -acc -DNOFLOAT lf.c +vax2 -DNOFLOAT lf.c lf.c running lf.cem comparing lf sed -f li.sed li.c -acc -DNOFLOAT li.c +vax2 -DNOFLOAT li.c li.c -"li.c", line 22: warning: Overflow in constant expression -"li.c", line 67: warning: Overflow in constant expression -"li.c", line 112: warning: Overflow in constant expression +"li.c", line 22: (warning) overflow in constant expression +"li.c", line 67: (warning) overflow in constant expression +"li.c", line 112: (warning) overflow in constant expression running li.cem comparing li +32c32 +< x <<= 15 -32768 +--- +> x <<= 15 8355840 +48c48 +< y = ( 4 << 15 ) 0 +--- +> y = ( 4 << 15 ) 131072 +69c69 +< y = ( x <<= 15 ) -32768 -32768 +--- +> y = ( x <<= 15 ) 8355840 8355840 +85c85 +< no if ( 4 << 15 ) yes() ; else no() +--- +> yes if ( 4 << 15 ) yes() ; else no() +106c106 +< yes if ( x <<= 15 ) yes() ; else no() -32768 +--- +> yes if ( x <<= 15 ) yes() ; else no() 8355840 sed -f ll.sed ll.c -acc -DNOFLOAT ll.c +vax2 -DNOFLOAT ll.c ll.c running ll.cem comparing ll sed -f lu.sed lu.c -acc -DNOFLOAT lu.c +vax2 -DNOFLOAT lu.c lu.c running lu.cem comparing lu +23,31c23,31 +< z = x -25302 +< z += x -25292 +< z -= x 25312 +< z /= x 0 +< z %= x 10 +< z *= x 9124 +< z &= x 10 +< z |= x -25302 +< z ^= x -25312 +--- +> z = x 40234 +> z += x 40244 +> z -= x -40224 +> z /= x 0 +> z %= x 10 +> z *= x 402340 +> z &= x 10 +> z |= x 40234 +> z ^= x 40224 +38c38 +< y = ( x + 8012 ) -17290 +--- +> y = ( x + 8012 ) 48246 +42,52c42,52 +< y = ( x * 8012 ) -16776 +< y = ( x & 8012 ) 7432 +< y = ( x | 8012 ) -24722 +< y = ( x ^ 8012 ) -32154 +< y = ( x || 8012 ) 1 +< y = ( x && 8012 ) 1 +< y = ( x << 9 ) 21504 +< y = ( x >> 9 ) 78 +< y = ( -x ) 25302 +< y = ( !x ) 0 +< y = ( ~x ) 25301 +--- +> y = ( x * 8012 ) 322354808 +> y = ( x & 8012 ) 7432 +> y = ( x | 8012 ) 40814 +> y = ( x ^ 8012 ) 33382 +> y = ( x || 8012 ) 1 +> y = ( x && 8012 ) 1 +> y = ( x << 9 ) 20599808 +> y = ( x >> 9 ) 78 +> y = ( -x ) -40234 +> y = ( !x ) 0 +> y = ( ~x ) -40235 +59,68c59,68 +< y = ( x ? x : 8012 ) -25302 +< y = ( z = x ) -25302 -25302 +< y = ( z += x ) -25292 -25292 +< y = ( z -= x ) 25312 25312 +< y = ( z /= x ) 0 0 +< y = ( z %= x ) 10 10 +< y = ( z *= x ) 9124 9124 +< y = ( z &= x ) 10 10 +< y = ( z |= x ) -25302 -25302 +< y = ( z ^= x ) -25312 -25312 +--- +> y = ( x ? x : 8012 ) 40234 +> y = ( z = x ) 40234 40234 +> y = ( z += x ) 40244 40244 +> y = ( z -= x ) -40224 -40224 +> y = ( z /= x ) 0 0 +> y = ( z %= x ) 10 10 +> y = ( z *= x ) 402340 402340 +> y = ( z &= x ) 10 10 +> y = ( z |= x ) 40234 40234 +> y = ( z ^= x ) 40224 40224 +97,105c97,105 +< yes if ( z = x ) yes() ; else no() -25302 +< yes if ( z += x ) yes() ; else no() -25292 +< yes if ( z -= x ) yes() ; else no() 25312 +< no if ( z /= x ) yes() ; else no() 0 +< yes if ( z %= x ) yes() ; else no() 10 +< yes if ( z *= x ) yes() ; else no() 9124 +< yes if ( z &= x ) yes() ; else no() 10 +< yes if ( z |= x ) yes() ; else no() -25302 +< yes if ( z ^= x ) yes() ; else no() -25312 +--- +> yes if ( z = x ) yes() ; else no() 40234 +> yes if ( z += x ) yes() ; else no() 40244 +> yes if ( z -= x ) yes() ; else no() -40224 +> no if ( z /= x ) yes() ; else no() 0 +> yes if ( z %= x ) yes() ; else no() 10 +> yes if ( z *= x ) yes() ; else no() 402340 +> yes if ( z &= x ) yes() ; else no() 10 +> yes if ( z |= x ) yes() ; else no() 40234 +> yes if ( z ^= x ) yes() ; else no() 40224 ***** ctill ----- All program(s) in this directory should fail to compile. -acc -DNOFLOAT noarg.c +vax2 -DNOFLOAT noarg.c noarg.c -"noarg.c", line 10: declared argument name is missing +"noarg.c", line 10: name not in parameter list *** Error code 1 `gen' not remade because of errors ***** ctinit -acc -DNOFLOAT init.c +vax2 -DNOFLOAT init.c init.c -"init.c", line 183: warning: Overflow in constant expression (U-) +"init.c", line 183: (warning) overflow in constant expression running init.cem comparing init 41,$c41,$ @@ -223,7 +576,7 @@ comparing init < lo1 14 < lo2 -17 < lo3 2147483647 -< lo4 -2147483648 +< lo4 0 < lo5 0 < lo6 1 < @@ -240,7 +593,7 @@ comparing init < bit fields: < < sizeof stb 6 -< stb 1 2 3 4 3 6 7 +< stb -1 -2 3 4 -1 6 7 < --- > Floats: @@ -250,7 +603,7 @@ comparing init > fl2 2.00000000000000000000e+00 > fl4 4.00000000000000000000e+00 > fl5 2.93873587705571892581e-39 -> fl6 1.70141173319264427000e+38 +> fl6 1.70141173319264428000e+38 > fl7 0.00000000000000000000e+00 > fla1 fla2 fla3 > 1.000000e+00 -1.000000e+00 1.100000e+01 @@ -312,63 +665,57 @@ comparing init > > bit fields: > -> sizeof stb 6 -> stb 1 2 3 4 3 6 7 +> sizeof stb 8 +> stb -1 -2 3 4 -1 6 7 > ***** ctmargt -acc -DNOFLOAT margt.c +vax2 -DNOFLOAT margt.c margt.c running margt.cem comparing margt 5,$c5,$ -< BELL= -< BIN=/user0/keie/bin -< CDPATH=:/usr/em/util:/usr/em/mach:/usr/em/lang -< DIT=/user0/keie/ditroff/troff/a.out -< HOME=/usr/em -< MAILHEADER=To: botter!vu44!mcvax!%t -< Subject: Re: %S -< Newsgroups: %n -< In-Reply-To: %i -< %(%[references]!=^$?References\: %[references] -< )Organization: %o -< Cc: -< Bcc: -< -< -< PATH=:/user0/keie/bin:/usr/local:/usr/ucb:/bin:/usr/bin:/usr/em/bin:/usr/new -< SHELL=/usr/local/dsh -< TERM=d80 -< TERMCAP=ME|ampex|d80|dialogue|dialogue80:am:bs:pt:if=/usr/lib/tabset/stdcrt:cl=\E;:cm=\E=%+\040%+\040:al=10\EE:ic=3\EQ:im=:ei=:dl=10\ER:dc=\EW:is=\EA:ho=^^:ce=\ET:cd=\EY:so=\Ej:se=\Ek:us=\El:ue=\Em:ul:li#24:co#80:nd=^L:up=^K:we=\Eo:ws=\En -< USER=keie +< CDPATH=:~:~em:/usr/spool +< CWD=/usr/em/lang/cem/ctest/ctmargt +< ESHKEYS=dcl=^?:dcl=^H:dcr=^D:dlr=^K:dtm=^W:dwl=^[h:dew=^[d:eof=^[^C:eof=^X^C:eof=^X^F:exp=^u:fcl=^[?:fcr=^[/:gcl=^B:gcr=^F:gll=^A:glr=^E:gwl=^[b:gew=^[f:hlp=^[H:hst=^_:int=^G:lnx=^V:prh=^P:rdr=^L:rtn=^J:rtn=^M:stm=^@:tab=^I:xgm=^X^X:xpl=^[^J:xpl=^[^M:yn< k=^Y:ipl=^N +< HOME=/user0/ceriel +< M2PATH=.:/user0/ceriel/modula-2/lib/m2v +< PAGER=/user0/ceriel/bin/yap +< PATH=/user0/ceriel/bin:/usr/local:/usr/ucb:/bin:/usr/bin:/usr/em/bin:/usr/new::/user0/ceriel/modula-2/bin/m2v +< REFS=/user0/ceriel/etc/refer/refs +< SHELL=/usr/local/esh +< TERM=sun +< TERMCAP=Mu|sun:li#34:co#80:cl=^L:cm=\E[%i%d;%dH:nd=\E[C:up=\E[A:am:bs:mi:ms:ce=\E[K:cd=\E[J:so=\E[7m:se=\E[m:kd=\E[B:kl=\E[D:ku=\E[A:kr=\E[C:kh=\E[H:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:al=\E[L:dl=\E[M:im=:ei=:ic=\E[@:dc=\E[P +< USER=ceriel --- -> HOME=/other/keie -> PATH=:/other/keie/bin:/bin:/usr/bin -> TERM=MiniBee +> HOME=/usr/em +> PATH=:/bin:/usr/ucb:/usr/local:/usr/bin:/usr/em/bin +> SHELL=/usr/local/esh +> TERM=dialup +> USER=em ***** ctprof test profiling procentry.c -acc -DNOFLOAT tp.c procentry.k +vax2 -DNOFLOAT tp.c procentry.k tp.c procentry.k running tp comparing tp ***** ctstruct -acc -DNOFLOAT str.c +vax2 -DNOFLOAT str.c str.c running str.cem comparing str ***** ctsys -acc -DNOFLOAT tfork.c +vax2 -DNOFLOAT tfork.c tfork.c running tfork.cem comparing tfork 1,$c1,$ -< childno 5207 -< Child 5207, status 0x800 +< childno 15195 +< Child 15195, status 0x800 < fork/wait ok --- -> childno N -> Child N, status 0x800 +> childno 16276 +> Child 16276, status 0x800 > fork/wait ok -Fri Feb 15 15:55:48 MET 1985 +Wed Feb 25 14:53:48 MET 1987 diff --git a/lang/cem/ctest/Out2.std b/lang/cem/ctest/Out2.std index 1caecbe5..7cf2c123 100644 --- a/lang/cem/ctest/Out2.std +++ b/lang/cem/ctest/Out2.std @@ -1,233 +1,617 @@ -Fri Feb 15 12:15:05 MET 1985 +Tue Feb 24 16:31:18 MET 1987 ***** ctconv -acc conv.c +vax2 conv.c conv.c -"conv.c", line 48: warning: Overflow in constant expression +"conv.c", line 48: (warning) overflow in constant expression running conv.cem comparing conv +14,22c14,22 +< char -1, int -1, unsigned 177777, long -1 +< float -1.000000 +< char -1, int -1, unsigned 177777, long -1 +< float -1.000000 +< From integer +< char -64, int -64, unsigned 177700, long -64 +< float -64.000000 +< From long +< char -3, int -3, unsigned 177775, long -3 +--- +> char -1, int -1, unsigned 37777777777, long -1 +> float -1.000000 +> char -1, int -1, unsigned 37777777777, long -1 +> float -1.000000 +> From integer +> char -64, int -64, unsigned 37777777700, long -64 +> float -64.000000 +> From long +> char -3, int -3, unsigned 37777777775, long -3 ***** ctdecl -acc decl.c +vax2 decl.c decl.c running decl.cem comparing decl ***** ctdivers -acc ops.c +vax2 ops.c ops.c running ops.cem comparing ops +24,39c24,39 +< u<<1 121632 +< u<<2 43464 +< u<<3 107150 +< u<<4 16320 +< u<<5 34640 +< u<<6 71500 +< u<<7 163200 +< u<<8 146400 +< u<<9 115000 +< u<<10 32000 +< u<<11 64000 +< u<<12 150000 +< u<<13 120000 +< u<<14 40000 +< u<<15 100000 +< u<<16 0 +--- +> u<<1 321632 +> u<<2 643464 +> u<<3 1507150 +> u<<4 3216320 +> u<<5 6434640 +> u<<6 15071500 +> u<<7 32163200 +> u<<8 64346400 +> u<<9 150715000 +> u<<10 321632000 +> u<<11 643464000 +> u<<12 1507150000 +> u<<13 3216320000 +> u<<14 6434640000 +> u<<15 15071500000 +> u<<16 32163200000 ***** cterr -acc bugs.c +vax2 bugs.c bugs.c -"bugs.c", line 98: warning: Overflow in constant expression +"bugs.c", line 98: (warning) overflow in constant expression running bugs.cem comparing bugs ***** ctest1 -acc test.c +vax2 test.c test.c running test.cem comparing test ***** ctest2 -acc t7.c +vax2 t7.c t7.c -"t7.c", line 163: warning: statement not reached -"t7.c", line 180: warning: statement not reached -"t7.c", line 184: warning: statement not reached -"t7.c", line 188: warning: statement not reached -"t7.c", line 192: warning: statement not reached -"t7.c", line 196: warning: statement not reached -"t7.c", line 200: warning: statement not reached -"t7.c", line 207: warning: statement not reached -"t7.c", line 209: warning: statement not reached -"t7.c", line 213: warning: statement not reached -"t7.c", line 215: warning: statement not reached -"t7.c", line 289: warning: statement not reached -"t7.c", line 296: warning: statement not reached -"t7.c", line 302: warning: statement not reached -"t7.c", line 309: warning: statement not reached -"t7.c", line 345: warning: statement not reached -"t7.c", line 346: warning: statement not reached -"t7.c", line 347: warning: statement not reached -"t7.c", line 348: warning: statement not reached -"t7.c", line 350: warning: statement not reached -"t7.c", line 454: warning: statement not reached -"t7.c", line 563: warning: statement not reached -"t7.c", line 591: warning: statement not reached running t7.cem comparing t7 ***** ctest3 -acc test2.c +vax2 test2.c test2.c +"test2.c", line 459: (warning) conversion of pointer to int loses accuracy +"test2.c", line 459: (warning) conversion of pointer to int loses accuracy running test2.cem comparing test2 ***** ctest5 -acc test1.c +vax2 test1.c test1.c -"test1.c", line 386: warning: illegal pointer combination -"test1.c", line 387: warning: illegal pointer combination -"test1.c", line 388: warning: illegal pointer combination -"test1.c", line 400: warning: illegal pointer combination -"test1.c", line 423: warning: illegal pointer combination -"test1.c", line 424: warning: illegal pointer combination -"test1.c", line 425: warning: illegal pointer combination -"test1.c", line 437: warning: illegal pointer combination +"test1.c", line 386: (warning) incompatible pointers in = +"test1.c", line 387: (warning) incompatible pointers in = +"test1.c", line 388: (warning) incompatible pointers in = +"test1.c", line 400: (warning) incompatible pointers in = +"test1.c", line 423: (warning) incompatible pointers in = +"test1.c", line 424: (warning) incompatible pointers in = +"test1.c", line 425: (warning) incompatible pointers in = +"test1.c", line 437: (warning) incompatible pointers in = running test1.cem comparing test1 ***** ctgen sed -f bf.sed bf.c -acc bf.c +vax2 bf.c bf.c running bf.cem comparing bf sed -f cel.sed cel.c -acc cel.c +vax2 cel.c cel.c running cel.cem comparing cel sed -f clu.sed clu.c -acc clu.c +vax2 clu.c clu.c -"clu.c", line 60: warning: Overflow in constant expression -"clu.c", line 66: warning: Overflow in constant expression +"clu.c", line 60: (warning) overflow in unsigned constant expression +"clu.c", line 66: (warning) overflow in unsigned constant expression running clu.cem comparing clu +23,31c23,31 +< x = 40000 -25536 +< x += 40000 -25526 +< x -= 40000 25546 +< x /= 40000 0 +< x %= 40000 10 +< x *= 40000 6784 +< x &= 40000 0 +< x |= 40000 -25526 +< x ^= 40000 -25526 +--- +> x = 40000 40000 +> x += 40000 40010 +> x -= 40000 -39990 +> x /= 40000 0 +> x %= 40000 10 +> x *= 40000 400000 +> x &= 40000 0 +> x |= 40000 40010 +> x ^= 40000 40010 +38c38 +< y = ( 40000 + 8012 ) -17524 +--- +> y = ( 40000 + 8012 ) 48012 +42,52c42,52 +< y = ( 40000 * 8012 ) 8960 +< y = ( 40000 & 8012 ) 7232 +< y = ( 40000 | 8012 ) -24756 +< y = ( 40000 ^ 8012 ) -31988 +< y = ( 40000 || 8012 ) 1 +< y = ( 40000 && 8012 ) 1 +< y = ( 40000 << 9 ) -32768 +< y = ( 40000 >> 9 ) 78 +< y = ( -40000 ) 25536 +< y = ( !40000 ) 0 +< y = ( ~40000 ) 25535 +--- +> y = ( 40000 * 8012 ) 320480000 +> y = ( 40000 & 8012 ) 7232 +> y = ( 40000 | 8012 ) 40780 +> y = ( 40000 ^ 8012 ) 33548 +> y = ( 40000 || 8012 ) 1 +> y = ( 40000 && 8012 ) 1 +> y = ( 40000 << 9 ) 20480000 +> y = ( 40000 >> 9 ) 78 +> y = ( -40000 ) -40000 +> y = ( !40000 ) 0 +> y = ( ~40000 ) -40001 +59,68c59,68 +< y = ( 40000 ? 40000 : 8012 ) -25536 +< y = ( x = 40000 ) -25536 -25536 +< y = ( x += 40000 ) -25526 -25526 +< y = ( x -= 40000 ) 25546 25546 +< y = ( x /= 40000 ) 0 0 +< y = ( x %= 40000 ) 10 10 +< y = ( x *= 40000 ) 6784 6784 +< y = ( x &= 40000 ) 0 0 +< y = ( x |= 40000 ) -25526 -25526 +< y = ( x ^= 40000 ) -25526 -25526 +--- +> y = ( 40000 ? 40000 : 8012 ) 40000 +> y = ( x = 40000 ) 40000 40000 +> y = ( x += 40000 ) 40010 40010 +> y = ( x -= 40000 ) -39990 -39990 +> y = ( x /= 40000 ) 0 0 +> y = ( x %= 40000 ) 10 10 +> y = ( x *= 40000 ) 400000 400000 +> y = ( x &= 40000 ) 0 0 +> y = ( x |= 40000 ) 40010 40010 +> y = ( x ^= 40000 ) 40010 40010 +97,105c97,105 +< yes if ( x = 40000 ) yes() ; else no() -25536 +< yes if ( x += 40000 ) yes() ; else no() -25526 +< yes if ( x -= 40000 ) yes() ; else no() 25546 +< no if ( x /= 40000 ) yes() ; else no() 0 +< yes if ( x %= 40000 ) yes() ; else no() 10 +< yes if ( x *= 40000 ) yes() ; else no() 6784 +< no if ( x &= 40000 ) yes() ; else no() 0 +< yes if ( x |= 40000 ) yes() ; else no() -25526 +< yes if ( x ^= 40000 ) yes() ; else no() -25526 +--- +> yes if ( x = 40000 ) yes() ; else no() 40000 +> yes if ( x += 40000 ) yes() ; else no() 40010 +> yes if ( x -= 40000 ) yes() ; else no() -39990 +> no if ( x /= 40000 ) yes() ; else no() 0 +> yes if ( x %= 40000 ) yes() ; else no() 10 +> yes if ( x *= 40000 ) yes() ; else no() 400000 +> no if ( x &= 40000 ) yes() ; else no() 0 +> yes if ( x |= 40000 ) yes() ; else no() 40010 +> yes if ( x ^= 40000 ) yes() ; else no() 40010 sed -f ec.sed ec.c -acc ec.c +vax2 ec.c ec.c -"ec.c", line 58: warning: Overflow in constant expression -"ec.c", line 64: warning: Overflow in constant expression +"ec.c", line 58: (warning) overflow in constant expression +"ec.c", line 64: (warning) overflow in constant expression running ec.cem comparing ec sed -f ef.sed ef.c -acc ef.c +vax2 ef.c ef.c running ef.cem comparing ef sed -f ei.sed ei.c -acc ei.c +vax2 ei.c ei.c -"ei.c", line 22: warning: Overflow in constant expression -"ei.c", line 65: warning: Overflow in constant expression -"ei.c", line 108: warning: Overflow in constant expression +"ei.c", line 22: (warning) overflow in constant expression +"ei.c", line 65: (warning) overflow in constant expression +"ei.c", line 108: (warning) overflow in constant expression running ei.cem comparing ei +32c32 +< x <<= 15 -32768 +--- +> x <<= 15 8355840 +48c48 +< y = ( 4 << 15 ) 0 +--- +> y = ( 4 << 15 ) 131072 +69c69 +< y = ( x <<= 15 ) -32768 -32768 +--- +> y = ( x <<= 15 ) 8355840 8355840 +85c85 +< no if ( 4 << 15 ) yes() ; else no() +--- +> yes if ( 4 << 15 ) yes() ; else no() +106c106 +< yes if ( x <<= 15 ) yes() ; else no() -32768 +--- +> yes if ( x <<= 15 ) yes() ; else no() 8355840 sed -f el.sed el.c -acc el.c +vax2 el.c el.c running el.cem comparing el sed -f eu.sed eu.c -acc eu.c +vax2 eu.c eu.c -"eu.c", line 58: warning: Overflow in constant expression -"eu.c", line 64: warning: Overflow in constant expression +"eu.c", line 58: (warning) overflow in unsigned constant expression +"eu.c", line 64: (warning) overflow in unsigned constant expression running eu.cem comparing eu +23,31c23,31 +< x = 40000 -25536 +< x += 40000 -25526 +< x -= 40000 25546 +< x /= 40000 0 +< x %= 40000 10 +< x *= 40000 6784 +< x &= 40000 0 +< x |= 40000 -25526 +< x ^= 40000 -25526 +--- +> x = 40000 40000 +> x += 40000 40010 +> x -= 40000 -39990 +> x /= 40000 0 +> x %= 40000 10 +> x *= 40000 400000 +> x &= 40000 0 +> x |= 40000 40010 +> x ^= 40000 40010 +38c38 +< y = ( 40000 + 8012 ) -17524 +--- +> y = ( 40000 + 8012 ) 48012 +42,52c42,52 +< y = ( 40000 * 8012 ) 8960 +< y = ( 40000 & 8012 ) 7232 +< y = ( 40000 | 8012 ) -24756 +< y = ( 40000 ^ 8012 ) -31988 +< y = ( 40000 || 8012 ) 1 +< y = ( 40000 && 8012 ) 1 +< y = ( 40000 << 9 ) -32768 +< y = ( 40000 >> 9 ) 78 +< y = ( -40000 ) 25536 +< y = ( !40000 ) 0 +< y = ( ~40000 ) 25535 +--- +> y = ( 40000 * 8012 ) 320480000 +> y = ( 40000 & 8012 ) 7232 +> y = ( 40000 | 8012 ) 40780 +> y = ( 40000 ^ 8012 ) 33548 +> y = ( 40000 || 8012 ) 1 +> y = ( 40000 && 8012 ) 1 +> y = ( 40000 << 9 ) 20480000 +> y = ( 40000 >> 9 ) 78 +> y = ( -40000 ) -40000 +> y = ( !40000 ) 0 +> y = ( ~40000 ) -40001 +59,68c59,68 +< y = ( 40000 ? 40000 : 8012 ) -25536 +< y = ( x = 40000 ) -25536 -25536 +< y = ( x += 40000 ) -25526 -25526 +< y = ( x -= 40000 ) 25546 25546 +< y = ( x /= 40000 ) 0 0 +< y = ( x %= 40000 ) 10 10 +< y = ( x *= 40000 ) 6784 6784 +< y = ( x &= 40000 ) 0 0 +< y = ( x |= 40000 ) -25526 -25526 +< y = ( x ^= 40000 ) -25526 -25526 +--- +> y = ( 40000 ? 40000 : 8012 ) 40000 +> y = ( x = 40000 ) 40000 40000 +> y = ( x += 40000 ) 40010 40010 +> y = ( x -= 40000 ) -39990 -39990 +> y = ( x /= 40000 ) 0 0 +> y = ( x %= 40000 ) 10 10 +> y = ( x *= 40000 ) 400000 400000 +> y = ( x &= 40000 ) 0 0 +> y = ( x |= 40000 ) 40010 40010 +> y = ( x ^= 40000 ) 40010 40010 +97,105c97,105 +< yes if ( x = 40000 ) yes() ; else no() -25536 +< yes if ( x += 40000 ) yes() ; else no() -25526 +< yes if ( x -= 40000 ) yes() ; else no() 25546 +< no if ( x /= 40000 ) yes() ; else no() 0 +< yes if ( x %= 40000 ) yes() ; else no() 10 +< yes if ( x *= 40000 ) yes() ; else no() 6784 +< no if ( x &= 40000 ) yes() ; else no() 0 +< yes if ( x |= 40000 ) yes() ; else no() -25526 +< yes if ( x ^= 40000 ) yes() ; else no() -25526 +--- +> yes if ( x = 40000 ) yes() ; else no() 40000 +> yes if ( x += 40000 ) yes() ; else no() 40010 +> yes if ( x -= 40000 ) yes() ; else no() -39990 +> no if ( x /= 40000 ) yes() ; else no() 0 +> yes if ( x %= 40000 ) yes() ; else no() 10 +> yes if ( x *= 40000 ) yes() ; else no() 400000 +> no if ( x &= 40000 ) yes() ; else no() 0 +> yes if ( x |= 40000 ) yes() ; else no() 40010 +> yes if ( x ^= 40000 ) yes() ; else no() 40010 sed -f id.sed id.c -acc id.c +vax2 id.c id.c running id.cem comparing id +26,28c26,28 +< y = ( (-40) - 300 ) -15190 +< y = ( (-40) / 300 ) 0 +< y = ( (-40) * 300 ) -14533 +--- +> y = ( (-40) - 300 ) 50346 +> y = ( (-40) / 300 ) 0 +> y = ( (-40) * 300 ) -2147432645 +39,48c39,48 +< y = ( (-40) ? (-40) : 300 ) -15584 +< y = ( x = (-40) ) -4.000000e+01 -15584 +< y = ( x += (-40) ) -3.685850e+01 -15597 +< y = ( x -= (-40) ) 4.314150e+01 17196 +< y = ( x /= (-40) ) -7.853750e-02 -16736 +< y = ( x *= (-40) ) -1.256600e+02 -15365 +< y = ( x ++ ) 4.141500e+00 16713 +< y = ( x -- ) 2.141500e+00 16713 +< y = ( -- x ) 2.141500e+00 16649 +< y = ( ++ x ) 4.141500e+00 16772 +--- +> y = ( (-40) ? (-40) : 300 ) 49952 +> y = ( x = (-40) ) -4.000000e+01 49952 +> y = ( x += (-40) ) -3.685850e+01 1864024851 +> y = ( x -= (-40) ) 4.314150e+01 -1864023252 +> y = ( x /= (-40) ) -7.853750e-02 -666583392 +> y = ( x *= (-40) ) -1.256600e+02 1374405627 +> y = ( x ++ ) 4.141500e+00 240533833 +> y = ( x -- ) 2.141500e+00 240533833 +> y = ( -- x ) 2.141500e+00 240533769 +> y = ( ++ x ) 4.141500e+00 -2027208316 sed -f lc.sed lc.c -acc lc.c +vax2 lc.c lc.c -"lc.c", line 60: warning: Overflow in constant expression -"lc.c", line 66: warning: Overflow in constant expression +"lc.c", line 60: (warning) overflow in constant expression +"lc.c", line 66: (warning) overflow in constant expression running lc.cem comparing lc sed -f ld.sed ld.c -acc ld.c +vax2 ld.c ld.c running ld.cem comparing ld sed -f lf.sed lf.c -acc lf.c +vax2 lf.c lf.c running lf.cem comparing lf sed -f li.sed li.c -acc li.c +vax2 li.c li.c -"li.c", line 22: warning: Overflow in constant expression -"li.c", line 67: warning: Overflow in constant expression -"li.c", line 112: warning: Overflow in constant expression +"li.c", line 22: (warning) overflow in constant expression +"li.c", line 67: (warning) overflow in constant expression +"li.c", line 112: (warning) overflow in constant expression running li.cem comparing li +32c32 +< x <<= 15 -32768 +--- +> x <<= 15 8355840 +48c48 +< y = ( 4 << 15 ) 0 +--- +> y = ( 4 << 15 ) 131072 +69c69 +< y = ( x <<= 15 ) -32768 -32768 +--- +> y = ( x <<= 15 ) 8355840 8355840 +85c85 +< no if ( 4 << 15 ) yes() ; else no() +--- +> yes if ( 4 << 15 ) yes() ; else no() +106c106 +< yes if ( x <<= 15 ) yes() ; else no() -32768 +--- +> yes if ( x <<= 15 ) yes() ; else no() 8355840 sed -f ll.sed ll.c -acc ll.c +vax2 ll.c ll.c running ll.cem comparing ll sed -f lu.sed lu.c -acc lu.c +vax2 lu.c lu.c running lu.cem comparing lu +23,31c23,31 +< z = x -25302 +< z += x -25292 +< z -= x 25312 +< z /= x 0 +< z %= x 10 +< z *= x 9124 +< z &= x 10 +< z |= x -25302 +< z ^= x -25312 +--- +> z = x 40234 +> z += x 40244 +> z -= x -40224 +> z /= x 0 +> z %= x 10 +> z *= x 402340 +> z &= x 10 +> z |= x 40234 +> z ^= x 40224 +38c38 +< y = ( x + 8012 ) -17290 +--- +> y = ( x + 8012 ) 48246 +42,52c42,52 +< y = ( x * 8012 ) -16776 +< y = ( x & 8012 ) 7432 +< y = ( x | 8012 ) -24722 +< y = ( x ^ 8012 ) -32154 +< y = ( x || 8012 ) 1 +< y = ( x && 8012 ) 1 +< y = ( x << 9 ) 21504 +< y = ( x >> 9 ) 78 +< y = ( -x ) 25302 +< y = ( !x ) 0 +< y = ( ~x ) 25301 +--- +> y = ( x * 8012 ) 322354808 +> y = ( x & 8012 ) 7432 +> y = ( x | 8012 ) 40814 +> y = ( x ^ 8012 ) 33382 +> y = ( x || 8012 ) 1 +> y = ( x && 8012 ) 1 +> y = ( x << 9 ) 20599808 +> y = ( x >> 9 ) 78 +> y = ( -x ) -40234 +> y = ( !x ) 0 +> y = ( ~x ) -40235 +59,68c59,68 +< y = ( x ? x : 8012 ) -25302 +< y = ( z = x ) -25302 -25302 +< y = ( z += x ) -25292 -25292 +< y = ( z -= x ) 25312 25312 +< y = ( z /= x ) 0 0 +< y = ( z %= x ) 10 10 +< y = ( z *= x ) 9124 9124 +< y = ( z &= x ) 10 10 +< y = ( z |= x ) -25302 -25302 +< y = ( z ^= x ) -25312 -25312 +--- +> y = ( x ? x : 8012 ) 40234 +> y = ( z = x ) 40234 40234 +> y = ( z += x ) 40244 40244 +> y = ( z -= x ) -40224 -40224 +> y = ( z /= x ) 0 0 +> y = ( z %= x ) 10 10 +> y = ( z *= x ) 402340 402340 +> y = ( z &= x ) 10 10 +> y = ( z |= x ) 40234 40234 +> y = ( z ^= x ) 40224 40224 +97,105c97,105 +< yes if ( z = x ) yes() ; else no() -25302 +< yes if ( z += x ) yes() ; else no() -25292 +< yes if ( z -= x ) yes() ; else no() 25312 +< no if ( z /= x ) yes() ; else no() 0 +< yes if ( z %= x ) yes() ; else no() 10 +< yes if ( z *= x ) yes() ; else no() 9124 +< yes if ( z &= x ) yes() ; else no() 10 +< yes if ( z |= x ) yes() ; else no() -25302 +< yes if ( z ^= x ) yes() ; else no() -25312 +--- +> yes if ( z = x ) yes() ; else no() 40234 +> yes if ( z += x ) yes() ; else no() 40244 +> yes if ( z -= x ) yes() ; else no() -40224 +> no if ( z /= x ) yes() ; else no() 0 +> yes if ( z %= x ) yes() ; else no() 10 +> yes if ( z *= x ) yes() ; else no() 402340 +> yes if ( z &= x ) yes() ; else no() 10 +> yes if ( z |= x ) yes() ; else no() 40234 +> yes if ( z ^= x ) yes() ; else no() 40224 ***** ctill ----- All program(s) in this directory should fail to compile. -acc noarg.c +vax2 noarg.c noarg.c -"noarg.c", line 10: declared argument name is missing +"noarg.c", line 10: name not in parameter list *** Error code 1 `gen' not remade because of errors ***** ctinit -acc init.c +vax2 init.c init.c -"init.c", line 183: warning: Overflow in constant expression (U-) +"init.c", line 183: (warning) overflow in constant expression running init.cem comparing init +48c48 +< fl6 1.70141173319264427000e+38 +--- +> fl6 1.70141173319264428000e+38 +92c92 +< lo4 0 +--- +> lo4 -2147483648 +110,$c110,$ +< sizeof stb 6 +< stb -1 -2 3 4 -1 6 7 +< +--- +> sizeof stb 8 +> stb -1 -2 3 4 -1 6 7 +> ***** ctmargt -acc margt.c +vax2 margt.c margt.c running margt.cem comparing margt 5,$c5,$ -< BELL= -< BIN=/usr/em/bin -< CDPATH=:/usr/em/util:/usr/em/mach:/usr/em/lang -< DIT=/usr/em/ditroff/troff/a.out -< HOME=/usr/em -< MAILHEADER=To: botter!vu44!mcvax!%t -< Subject: Re: %S -< Newsgroups: %n -< In-Reply-To: %i -< %(%[references]!=^$?References\: %[references] -< )Organization: %o -< Cc: -< Bcc: -< -< -< PATH=:/usr/em/bin:/usr/local:/usr/ucb:/bin:/usr/bin:/usr/em/bin:/usr/new -< SHELL=/usr/local/dsh -< TERM=d80 -< USER=keie +< CDPATH=:~:~em:/usr/spool +< CWD=/usr/em/lang/cem/ctest/ctmargt +< ESHKEYS=dcl=^?:dcl=^H:dcr=^D:dlr=^K:dtm=^W:dwl=^[h:dew=^[d:eof=^[^C:eof=^X^C:eof=^X^F:exp=^u:fcl=^[?:fcr=^[/:gcl=^B:gcr=^F:gll=^A:glr=^E:gwl=^[b:gew=^[f:hlp=^[H:hst=^_:int=^G:lnx=^V:prh=^P:rdr=^L:rtn=^J:rtn=^M:stm=^@:tab=^I:xgm=^X^X:xpl=^[^J:xpl=^[^M:yn< k=^Y:ipl=^N +< HOME=/user0/ceriel +< M2PATH=.:/user0/ceriel/modula-2/lib/m2v +< PAGER=/user0/ceriel/bin/yap +< PATH=/user0/ceriel/bin:/usr/local:/usr/ucb:/bin:/usr/bin:/usr/em/bin:/usr/new::/user0/ceriel/modula-2/bin/m2v +< REFS=/user0/ceriel/etc/refer/refs +< SHELL=/usr/local/esh +< TERM=sun +< TERMCAP=Mu|sun:li#34:co#80:cl=^L:cm=\E[%i%d;%dH:nd=\E[C:up=\E[A:am:bs:mi:ms:ce=\E[K:cd=\E[J:so=\E[7m:se=\E[m:kd=\E[B:kl=\E[D:ku=\E[A:kr=\E[C:kh=\E[H:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:al=\E[L:dl=\E[M:im=:ei=:ic=\E[@:dc=\E[P +< USER=ceriel --- -> HOME=/other/keie -> PATH=:/other/keie/bin:/bin:/usr/bin -> TERM=MiniBee +> HOME=/usr/em +> PATH=:/bin:/usr/ucb:/usr/local:/usr/bin:/usr/em/bin +> SHELL=/usr/local/esh +> TERM=dialup +> USER=em ***** ctprof test profiling procentry.c -acc tp.c procentry.k +vax2 tp.c procentry.k tp.c procentry.k running tp comparing tp ***** ctstruct -acc str.c +vax2 str.c str.c running str.cem comparing str ***** ctsys -acc tfork.c +vax2 tfork.c tfork.c running tfork.cem comparing tfork 1,$c1,$ -< childno 1928 -< Child 1928, status 0x800 +< childno 3050 +< Child 3050, status 0x800 < fork/wait ok --- -> childno N -> Child N, status 0x800 +> childno 16276 +> Child 16276, status 0x800 > fork/wait ok -Fri Feb 15 13:29:05 MET 1985 +Tue Feb 24 17:56:16 MET 1987 diff --git a/lang/cem/ctest/Out4.nf.std b/lang/cem/ctest/Out4.nf.std index 0bb40477..638f48e6 100644 --- a/lang/cem/ctest/Out4.nf.std +++ b/lang/cem/ctest/Out4.nf.std @@ -1,33 +1,33 @@ -Fri Mar 15 14:44:59 GMT 1985 +Wed Feb 25 11:07:00 MET 1987 ***** ctconv -acc -mm68k4 -DNOFLOAT conv.c +vax4 -DNOFLOAT conv.c conv.c -"conv.c", line 48: warning: Overflow in constant expression +"conv.c", line 48: (warning) overflow in constant expression running conv.cem comparing conv 2a3,4 > (float) 12 = 12.000000 > (int) 3.14 = 3 11,$c13,$ -< char 255, int 255, unsigned 377, long 255 -< char 255, int 255, unsigned 377, long 255 +< char -1, int -1, unsigned 37777777777, long -1 +< char -1, int -1, unsigned 37777777777, long -1 < From integer -< char 192, int -64, unsigned 37777777700, long -64 +< char -64, int -64, unsigned 37777777700, long -64 < From long -< char 253, int -3, unsigned 37777777775, long -3 +< char -3, int -3, unsigned 37777777775, long -3 < a[l] (l==3) -17 < a[3l] -17 --- > float 127.000000 -> char 255, int 255, unsigned 377, long 255 -> float 255.000000 -> char 255, int 255, unsigned 377, long 255 -> float 255.000000 +> char -1, int -1, unsigned 37777777777, long -1 +> float -1.000000 +> char -1, int -1, unsigned 37777777777, long -1 +> float -1.000000 > From integer -> char 192, int -64, unsigned 177700, long -64 +> char -64, int -64, unsigned 37777777700, long -64 > float -64.000000 > From long -> char 253, int -3, unsigned 177775, long -3 +> char -3, int -3, unsigned 37777777775, long -3 > float -3.000000 > From float > char 121, int 121, unsigned 171, long 121, float 121.500000 @@ -37,57 +37,24 @@ comparing conv > a[l] (l==3) -17 > a[3l] -17 ***** ctdecl -acc -mm68k4 -DNOFLOAT decl.c +vax4 -DNOFLOAT decl.c decl.c running decl.cem comparing decl ***** ctdivers -acc -mm68k4 -DNOFLOAT ops.c +vax4 -DNOFLOAT ops.c ops.c running ops.cem comparing ops -24,39c24,39 -< u<<1 321632 -< u<<2 643464 -< u<<3 1507150 -< u<<4 3216320 -< u<<5 6434640 -< u<<6 15071500 -< u<<7 32163200 -< u<<8 64346400 -< u<<9 150715000 -< u<<10 321632000 -< u<<11 643464000 -< u<<12 1507150000 -< u<<13 3216320000 -< u<<14 6434640000 -< u<<15 15071500000 -< u<<16 32163200000 ---- -> u<<1 121632 -> u<<2 043464 -> u<<3 107150 -> u<<4 016320 -> u<<5 034640 -> u<<6 071500 -> u<<7 163200 -> u<<8 146400 -> u<<9 115000 -> u<<10 032000 -> u<<11 064000 -> u<<12 150000 -> u<<13 120000 -> u<<14 040000 -> u<<15 100000 -> u<<16 000000 ***** cterr -acc -mm68k4 -DNOFLOAT bugs.c +vax4 -DNOFLOAT bugs.c bugs.c -"bugs.c", line 98: warning: Overflow in constant expression +"bugs.c", line 98: (warning) overflow in constant expression running bugs.cem +*** Error code -37 (ignored) comparing bugs ***** ctest1 -acc -mm68k4 -DNOFLOAT test.c +vax4 -DNOFLOAT test.c test.c running test.cem comparing test @@ -96,49 +63,26 @@ comparing test --- > End of test program, 11 tests completed, 0 errors detected ***** ctest2 -acc -mm68k4 -DNOFLOAT t7.c +vax4 -DNOFLOAT t7.c t7.c -"t7.c", line 163: warning: statement not reached -"t7.c", line 180: warning: statement not reached -"t7.c", line 184: warning: statement not reached -"t7.c", line 188: warning: statement not reached -"t7.c", line 192: warning: statement not reached -"t7.c", line 196: warning: statement not reached -"t7.c", line 200: warning: statement not reached -"t7.c", line 207: warning: statement not reached -"t7.c", line 209: warning: statement not reached -"t7.c", line 213: warning: statement not reached -"t7.c", line 215: warning: statement not reached -"t7.c", line 289: warning: statement not reached -"t7.c", line 296: warning: statement not reached -"t7.c", line 302: warning: statement not reached -"t7.c", line 309: warning: statement not reached -"t7.c", line 345: warning: statement not reached -"t7.c", line 346: warning: statement not reached -"t7.c", line 347: warning: statement not reached -"t7.c", line 348: warning: statement not reached -"t7.c", line 350: warning: statement not reached -"t7.c", line 454: warning: statement not reached -"t7.c", line 563: warning: statement not reached -"t7.c", line 591: warning: statement not reached running t7.cem comparing t7 ***** ctest3 -acc -mm68k4 -DNOFLOAT test2.c +vax4 -DNOFLOAT test2.c test2.c running test2.cem comparing test2 ***** ctest5 -acc -mm68k4 -DNOFLOAT test1.c +vax4 -DNOFLOAT test1.c test1.c -"test1.c", line 386: warning: illegal pointer combination -"test1.c", line 387: warning: illegal pointer combination -"test1.c", line 388: warning: illegal pointer combination -"test1.c", line 400: warning: illegal pointer combination -"test1.c", line 423: warning: illegal pointer combination -"test1.c", line 424: warning: illegal pointer combination -"test1.c", line 425: warning: illegal pointer combination -"test1.c", line 437: warning: illegal pointer combination +"test1.c", line 386: (warning) incompatible pointers in = +"test1.c", line 387: (warning) incompatible pointers in = +"test1.c", line 388: (warning) incompatible pointers in = +"test1.c", line 400: (warning) incompatible pointers in = +"test1.c", line 423: (warning) incompatible pointers in = +"test1.c", line 424: (warning) incompatible pointers in = +"test1.c", line 425: (warning) incompatible pointers in = +"test1.c", line 437: (warning) incompatible pointers in = running test1.cem comparing test1 1,$c1,$ @@ -150,679 +94,242 @@ comparing test1 > 11 tests completed. Number of errors = 1 ***** ctgen sed -f bf.sed bf.c -acc -mm68k4 -DNOFLOAT bf.c +vax4 -DNOFLOAT bf.c bf.c running bf.cem comparing bf -39c39 -< bfs.bf4 = ( bfs.bf1 - bfs.bf2 ) 65529 ---- -> bfs.bf4 = ( bfs.bf1 - bfs.bf2 ) -7 -50,52c50,52 -< bfs.bf4 = ( -bfs.bf1 ) 65535 -< bfs.bf4 = ( !bfs.bf1 ) 0 -< bfs.bf4 = ( ~bfs.bf1 ) 65534 ---- -> bfs.bf4 = ( -bfs.bf1 ) -1 -> bfs.bf4 = ( !bfs.bf1 ) 0 -> bfs.bf4 = ( ~bfs.bf1 ) -2 sed -f cel.sed cel.c -acc -mm68k4 -DNOFLOAT cel.c +vax4 -DNOFLOAT cel.c cel.c running cel.cem comparing cel sed -f clu.sed clu.c -acc -mm68k4 -DNOFLOAT clu.c +vax4 -DNOFLOAT clu.c clu.c running clu.cem comparing clu -23,31c23,31 -< x = 40000 40000 -< x += 40000 40010 -< x -= 40000 -39990 -< x /= 40000 0 -< x %= 40000 10 -< x *= 40000 400000 -< x &= 40000 0 -< x |= 40000 40010 -< x ^= 40000 40010 ---- -> x = 40000 -25536 -> x += 40000 -25526 -> x -= 40000 25546 -> x /= 40000 0 -> x %= 40000 10 -> x *= 40000 6784 -> x &= 40000 0 -> x |= 40000 -25526 -> x ^= 40000 -25526 -38c38 -< y = ( 40000 + 8012 ) 48012 ---- -> y = ( 40000 + 8012 ) -17524 -42,52c42,52 -< y = ( 40000 * 8012 ) 320480000 -< y = ( 40000 & 8012 ) 7232 -< y = ( 40000 | 8012 ) 40780 -< y = ( 40000 ^ 8012 ) 33548 -< y = ( 40000 || 8012 ) 1 -< y = ( 40000 && 8012 ) 1 -< y = ( 40000 << 9 ) 20480000 -< y = ( 40000 >> 9 ) 78 -< y = ( -40000 ) -40000 -< y = ( !40000 ) 0 -< y = ( ~40000 ) -40001 ---- -> y = ( 40000 * 8012 ) 8960 -> y = ( 40000 & 8012 ) 7232 -> y = ( 40000 | 8012 ) -24756 -> y = ( 40000 ^ 8012 ) -31988 -> y = ( 40000 || 8012 ) 1 -> y = ( 40000 && 8012 ) 1 -> y = ( 40000 << 9 ) -32768 -> y = ( 40000 >> 9 ) 78 -> y = ( -40000 ) 25536 -> y = ( !40000 ) 0 -> y = ( ~40000 ) 25535 -59,68c59,68 -< y = ( 40000 ? 40000 : 8012 ) 40000 -< y = ( x = 40000 ) 40000 40000 -< y = ( x += 40000 ) 40010 40010 -< y = ( x -= 40000 ) -39990 -39990 -< y = ( x /= 40000 ) 0 0 -< y = ( x %= 40000 ) 10 10 -< y = ( x *= 40000 ) 400000 400000 -< y = ( x &= 40000 ) 0 0 -< y = ( x |= 40000 ) 40010 40010 -< y = ( x ^= 40000 ) 40010 40010 ---- -> y = ( 40000 ? 40000 : 8012 ) -25536 -> y = ( x = 40000 ) -25536 -25536 -> y = ( x += 40000 ) -25526 -25526 -> y = ( x -= 40000 ) 25546 25546 -> y = ( x /= 40000 ) 0 0 -> y = ( x %= 40000 ) 10 10 -> y = ( x *= 40000 ) 6784 6784 -> y = ( x &= 40000 ) 0 0 -> y = ( x |= 40000 ) -25526 -25526 -> y = ( x ^= 40000 ) -25526 -25526 -97,105c97,105 -< yes if ( x = 40000 ) yes() ; else no() 40000 -< yes if ( x += 40000 ) yes() ; else no() 40010 -< yes if ( x -= 40000 ) yes() ; else no() -39990 -< no if ( x /= 40000 ) yes() ; else no() 0 -< yes if ( x %= 40000 ) yes() ; else no() 10 -< yes if ( x *= 40000 ) yes() ; else no() 400000 -< no if ( x &= 40000 ) yes() ; else no() 0 -< yes if ( x |= 40000 ) yes() ; else no() 40010 -< yes if ( x ^= 40000 ) yes() ; else no() 40010 ---- -> yes if ( x = 40000 ) yes() ; else no() -25536 -> yes if ( x += 40000 ) yes() ; else no() -25526 -> yes if ( x -= 40000 ) yes() ; else no() 25546 -> no if ( x /= 40000 ) yes() ; else no() 0 -> yes if ( x %= 40000 ) yes() ; else no() 10 -> yes if ( x *= 40000 ) yes() ; else no() 6784 -> no if ( x &= 40000 ) yes() ; else no() 0 -> yes if ( x |= 40000 ) yes() ; else no() -25526 -> yes if ( x ^= 40000 ) yes() ; else no() -25526 sed -f ec.sed ec.c -acc -mm68k4 -DNOFLOAT ec.c +vax4 -DNOFLOAT ec.c ec.c -"ec.c", line 58: warning: Overflow in constant expression -"ec.c", line 64: warning: Overflow in constant expression +"ec.c", line 58: (warning) overflow in constant expression +"ec.c", line 64: (warning) overflow in constant expression running ec.cem comparing ec sed -f ef.sed ef.c -acc -mm68k4 -DNOFLOAT ef.c +vax4 -DNOFLOAT ef.c ef.c -Warning : dummy float-constant(s) running ef.cem -*** Error code 18 (ignored) comparing ef -5,$c5,$ -< ef.c, line 13: trap 18 called ---- -> .4e-5 || .3e-5 -> .4e-5 && .3e-5 -> -.4e-5 -> !.4e-5 -> .4e-5 == .3e-5 -> .4e-5 != .3e-5 -> .4e-5 <= .3e-5 -> .4e-5 >= .3e-5 -> .4e-5 < .3e-5 -> .4e-5 > .3e-5 -> .4e-5 ? .4e-5 : .3e-5 -> x = .4e-5 4.000000e-06 -> x += .4e-5 3.141504e+00 -> x -= .4e-5 3.141496e+00 -> x /= .4e-5 7.853750e+05 -> x *= .4e-5 1.256600e-05 -> x ++ 4.141500e+00 -> x -- 2.141500e+00 -> -- x 2.141500e+00 -> ++ x 4.141500e+00 -> y = ( .4e-5 + .3e-5 ) 7.000000e-06 -> y = ( .4e-5 - .3e-5 ) 1.000000e-06 -> y = ( .4e-5 / .3e-5 ) 1.333333e+00 -> y = ( .4e-5 * .3e-5 ) 1.200000e-11 -> y = ( .4e-5 || .3e-5 ) 1.000000e+00 -> y = ( .4e-5 && .3e-5 ) 1.000000e+00 -> y = ( -.4e-5 ) -4.000000e-06 -> y = ( !.4e-5 ) 0.000000e+00 -> y = ( .4e-5 == .3e-5 ) 0.000000e+00 -> y = ( .4e-5 != .3e-5 ) 1.000000e+00 -> y = ( .4e-5 <= .3e-5 ) 0.000000e+00 -> y = ( .4e-5 >= .3e-5 ) 1.000000e+00 -> y = ( .4e-5 < .3e-5 ) 0.000000e+00 -> y = ( .4e-5 > .3e-5 ) 1.000000e+00 -> y = ( .4e-5 ? .4e-5 : .3e-5 ) 4.000000e-06 -> y = ( x = .4e-5 ) 4.000000e-06 4.000000e-06 -> y = ( x += .4e-5 ) 3.141504e+00 3.141504e+00 -> y = ( x -= .4e-5 ) 3.141496e+00 3.141496e+00 -> y = ( x /= .4e-5 ) 7.853750e+05 7.853750e+05 -> y = ( x *= .4e-5 ) 1.256600e-05 1.256600e-05 -> y = ( x ++ ) 4.141500e+00 3.141500e+00 -> y = ( x -- ) 2.141500e+00 3.141500e+00 -> y = ( -- x ) 2.141500e+00 2.141500e+00 -> y = ( ++ x ) 4.141500e+00 4.141500e+00 -> yes if ( .4e-5 + .3e-5 ) yes() ; else no() -> yes if ( .4e-5 - .3e-5 ) yes() ; else no() -> yes if ( .4e-5 / .3e-5 ) yes() ; else no() -> yes if ( .4e-5 * .3e-5 ) yes() ; else no() -> yes if ( .4e-5 || .3e-5 ) yes() ; else no() -> yes if ( .4e-5 && .3e-5 ) yes() ; else no() -> yes if ( -.4e-5 ) yes() ; else no() -> no if ( !.4e-5 ) yes() ; else no() -> no if ( .4e-5 == .3e-5 ) yes() ; else no() -> yes if ( .4e-5 != .3e-5 ) yes() ; else no() -> no if ( .4e-5 <= .3e-5 ) yes() ; else no() -> yes if ( .4e-5 >= .3e-5 ) yes() ; else no() -> no if ( .4e-5 < .3e-5 ) yes() ; else no() -> yes if ( .4e-5 > .3e-5 ) yes() ; else no() -> yes if ( .4e-5 ? .4e-5 : .3e-5 ) yes() ; else no() -> yes if ( x = .4e-5 ) yes() ; else no() 4.000000e-06 -> yes if ( x += .4e-5 ) yes() ; else no() 3.141504e+00 -> yes if ( x -= .4e-5 ) yes() ; else no() 3.141496e+00 -> yes if ( x /= .4e-5 ) yes() ; else no() 7.853750e+05 -> yes if ( x *= .4e-5 ) yes() ; else no() 1.256600e-05 -> yes if ( x ++ ) yes() ; else no() 4.141500e+00 -> yes if ( x -- ) yes() ; else no() 2.141500e+00 -> yes if ( -- x ) yes() ; else no() 2.141500e+00 -> yes if ( ++ x ) yes() ; else no() 4.141500e+00 sed -f ei.sed ei.c -acc -mm68k4 -DNOFLOAT ei.c +vax4 -DNOFLOAT ei.c ei.c running ei.cem comparing ei -32c32 -< x <<= 15 8355840 ---- -> x <<= 15 -32768 -48c48 -< y = ( 4 << 15 ) 131072 ---- -> y = ( 4 << 15 ) 0 -69c69 -< y = ( x <<= 15 ) 8355840 8355840 ---- -> y = ( x <<= 15 ) -32768 -32768 -85c85 -< yes if ( 4 << 15 ) yes() ; else no() ---- -> no if ( 4 << 15 ) yes() ; else no() -106c106 -< yes if ( x <<= 15 ) yes() ; else no() 8355840 ---- -> yes if ( x <<= 15 ) yes() ; else no() -32768 sed -f el.sed el.c -acc -mm68k4 -DNOFLOAT el.c +vax4 -DNOFLOAT el.c el.c running el.cem comparing el sed -f eu.sed eu.c -acc -mm68k4 -DNOFLOAT eu.c +vax4 -DNOFLOAT eu.c eu.c running eu.cem comparing eu -23,31c23,31 -< x = 40000 40000 -< x += 40000 40010 -< x -= 40000 -39990 -< x /= 40000 0 -< x %= 40000 10 -< x *= 40000 400000 -< x &= 40000 0 -< x |= 40000 40010 -< x ^= 40000 40010 ---- -> x = 40000 -25536 -> x += 40000 -25526 -> x -= 40000 25546 -> x /= 40000 0 -> x %= 40000 10 -> x *= 40000 6784 -> x &= 40000 0 -> x |= 40000 -25526 -> x ^= 40000 -25526 -38c38 -< y = ( 40000 + 8012 ) 48012 ---- -> y = ( 40000 + 8012 ) -17524 -42,52c42,52 -< y = ( 40000 * 8012 ) 320480000 -< y = ( 40000 & 8012 ) 7232 -< y = ( 40000 | 8012 ) 40780 -< y = ( 40000 ^ 8012 ) 33548 -< y = ( 40000 || 8012 ) 1 -< y = ( 40000 && 8012 ) 1 -< y = ( 40000 << 9 ) 20480000 -< y = ( 40000 >> 9 ) 78 -< y = ( -40000 ) -40000 -< y = ( !40000 ) 0 -< y = ( ~40000 ) -40001 ---- -> y = ( 40000 * 8012 ) 8960 -> y = ( 40000 & 8012 ) 7232 -> y = ( 40000 | 8012 ) -24756 -> y = ( 40000 ^ 8012 ) -31988 -> y = ( 40000 || 8012 ) 1 -> y = ( 40000 && 8012 ) 1 -> y = ( 40000 << 9 ) -32768 -> y = ( 40000 >> 9 ) 78 -> y = ( -40000 ) 25536 -> y = ( !40000 ) 0 -> y = ( ~40000 ) 25535 -59,68c59,68 -< y = ( 40000 ? 40000 : 8012 ) 40000 -< y = ( x = 40000 ) 40000 40000 -< y = ( x += 40000 ) 40010 40010 -< y = ( x -= 40000 ) -39990 -39990 -< y = ( x /= 40000 ) 0 0 -< y = ( x %= 40000 ) 10 10 -< y = ( x *= 40000 ) 400000 400000 -< y = ( x &= 40000 ) 0 0 -< y = ( x |= 40000 ) 40010 40010 -< y = ( x ^= 40000 ) 40010 40010 ---- -> y = ( 40000 ? 40000 : 8012 ) -25536 -> y = ( x = 40000 ) -25536 -25536 -> y = ( x += 40000 ) -25526 -25526 -> y = ( x -= 40000 ) 25546 25546 -> y = ( x /= 40000 ) 0 0 -> y = ( x %= 40000 ) 10 10 -> y = ( x *= 40000 ) 6784 6784 -> y = ( x &= 40000 ) 0 0 -> y = ( x |= 40000 ) -25526 -25526 -> y = ( x ^= 40000 ) -25526 -25526 -97,105c97,105 -< yes if ( x = 40000 ) yes() ; else no() 40000 -< yes if ( x += 40000 ) yes() ; else no() 40010 -< yes if ( x -= 40000 ) yes() ; else no() -39990 -< no if ( x /= 40000 ) yes() ; else no() 0 -< yes if ( x %= 40000 ) yes() ; else no() 10 -< yes if ( x *= 40000 ) yes() ; else no() 400000 -< no if ( x &= 40000 ) yes() ; else no() 0 -< yes if ( x |= 40000 ) yes() ; else no() 40010 -< yes if ( x ^= 40000 ) yes() ; else no() 40010 ---- -> yes if ( x = 40000 ) yes() ; else no() -25536 -> yes if ( x += 40000 ) yes() ; else no() -25526 -> yes if ( x -= 40000 ) yes() ; else no() 25546 -> no if ( x /= 40000 ) yes() ; else no() 0 -> yes if ( x %= 40000 ) yes() ; else no() 10 -> yes if ( x *= 40000 ) yes() ; else no() 6784 -> no if ( x &= 40000 ) yes() ; else no() 0 -> yes if ( x |= 40000 ) yes() ; else no() -25526 -> yes if ( x ^= 40000 ) yes() ; else no() -25526 +sed -f id.sed id.c +vax4 -DNOFLOAT id.c +id.c +running id.cem +comparing id sed -f lc.sed lc.c -acc -mm68k4 -DNOFLOAT lc.c +vax4 -DNOFLOAT lc.c lc.c -"lc.c", line 60: warning: Overflow in constant expression -"lc.c", line 66: warning: Overflow in constant expression +"lc.c", line 60: (warning) overflow in constant expression +"lc.c", line 66: (warning) overflow in constant expression running lc.cem comparing lc sed -f ld.sed ld.c -acc -mm68k4 -DNOFLOAT ld.c +vax4 -DNOFLOAT ld.c ld.c -Warning : dummy float-constant(s) running ld.cem -*** Error code 18 (ignored) comparing ld -5,$c5,$ -< ld.c, line 13: trap 18 called ---- -> .4e-5 || .3e-5 -> .4e-5 && .3e-5 -> -.4e-5 -> !.4e-5 -> .4e-5 == .3e-5 -> .4e-5 != .3e-5 -> .4e-5 <= .3e-5 -> .4e-5 >= .3e-5 -> .4e-5 < .3e-5 -> .4e-5 > .3e-5 -> .4e-5 ? .4e-5 : .3e-5 -> x = .4e-5 4.000000e-06 -> x += .4e-5 3.141504e+00 -> x -= .4e-5 3.141496e+00 -> x /= .4e-5 7.853750e+05 -> x *= .4e-5 1.256600e-05 -> x ++ 4.141500e+00 -> x -- 2.141500e+00 -> -- x 2.141500e+00 -> ++ x 4.141500e+00 -> y = ( .4e-5 + .3e-5 ) 7.000000e-06 -> y = ( .4e-5 - .3e-5 ) 1.000000e-06 -> y = ( .4e-5 / .3e-5 ) 1.333333e+00 -> y = ( .4e-5 * .3e-5 ) 1.200000e-11 -> y = ( .4e-5 || .3e-5 ) 1.000000e+00 -> y = ( .4e-5 && .3e-5 ) 1.000000e+00 -> y = ( -.4e-5 ) -4.000000e-06 -> y = ( !.4e-5 ) 0.000000e+00 -> y = ( .4e-5 == .3e-5 ) 0.000000e+00 -> y = ( .4e-5 != .3e-5 ) 1.000000e+00 -> y = ( .4e-5 <= .3e-5 ) 0.000000e+00 -> y = ( .4e-5 >= .3e-5 ) 1.000000e+00 -> y = ( .4e-5 < .3e-5 ) 0.000000e+00 -> y = ( .4e-5 > .3e-5 ) 1.000000e+00 -> y = ( .4e-5 ? .4e-5 : .3e-5 ) 4.000000e-06 -> y = ( x = .4e-5 ) 4.000000e-06 4.000000e-06 -> y = ( x += .4e-5 ) 3.141504e+00 3.141504e+00 -> y = ( x -= .4e-5 ) 3.141496e+00 3.141496e+00 -> y = ( x /= .4e-5 ) 7.853750e+05 7.853750e+05 -> y = ( x *= .4e-5 ) 1.256600e-05 1.256600e-05 -> y = ( x ++ ) 4.141500e+00 3.141500e+00 -> y = ( x -- ) 2.141500e+00 3.141500e+00 -> y = ( -- x ) 2.141500e+00 2.141500e+00 -> y = ( ++ x ) 4.141500e+00 4.141500e+00 -> yes if ( .4e-5 + .3e-5 ) yes() ; else no() -> yes if ( .4e-5 - .3e-5 ) yes() ; else no() -> yes if ( .4e-5 / .3e-5 ) yes() ; else no() -> yes if ( .4e-5 * .3e-5 ) yes() ; else no() -> yes if ( .4e-5 || .3e-5 ) yes() ; else no() -> yes if ( .4e-5 && .3e-5 ) yes() ; else no() -> yes if ( -.4e-5 ) yes() ; else no() -> no if ( !.4e-5 ) yes() ; else no() -> no if ( .4e-5 == .3e-5 ) yes() ; else no() -> yes if ( .4e-5 != .3e-5 ) yes() ; else no() -> no if ( .4e-5 <= .3e-5 ) yes() ; else no() -> yes if ( .4e-5 >= .3e-5 ) yes() ; else no() -> no if ( .4e-5 < .3e-5 ) yes() ; else no() -> yes if ( .4e-5 > .3e-5 ) yes() ; else no() -> yes if ( .4e-5 ? .4e-5 : .3e-5 ) yes() ; else no() -> yes if ( x = .4e-5 ) yes() ; else no() 4.000000e-06 -> yes if ( x += .4e-5 ) yes() ; else no() 3.141504e+00 -> yes if ( x -= .4e-5 ) yes() ; else no() 3.141496e+00 -> yes if ( x /= .4e-5 ) yes() ; else no() 7.853750e+05 -> yes if ( x *= .4e-5 ) yes() ; else no() 1.256600e-05 -> yes if ( x ++ ) yes() ; else no() 4.141500e+00 -> yes if ( x -- ) yes() ; else no() 2.141500e+00 -> yes if ( -- x ) yes() ; else no() 2.141500e+00 -> yes if ( ++ x ) yes() ; else no() 4.141500e+00 sed -f lf.sed lf.c -acc -mm68k4 -DNOFLOAT lf.c +vax4 -DNOFLOAT lf.c lf.c -Warning : dummy float-constant(s) running lf.cem -*** Error code 18 (ignored) comparing lf -1,$c1,$ -< lf.c, line 8: trap 18 called ---- -> .4e-5 + .3e-5 -> .4e-5 - .3e-5 -> .4e-5 / .3e-5 -> .4e-5 * .3e-5 -> .4e-5 || .3e-5 -> .4e-5 && .3e-5 -> -.4e-5 -> !.4e-5 -> .4e-5 == .3e-5 -> .4e-5 != .3e-5 -> .4e-5 <= .3e-5 -> .4e-5 >= .3e-5 -> .4e-5 < .3e-5 -> .4e-5 > .3e-5 -> .4e-5 ? .4e-5 : .3e-5 -> x = .4e-5 4.000000e-06 -> x += .4e-5 3.141504e+00 -> x -= .4e-5 3.141496e+00 -> x /= .4e-5 7.853750e+05 -> x *= .4e-5 1.256600e-05 -> x ++ 4.141500e+00 -> x -- 2.141500e+00 -> -- x 2.141500e+00 -> ++ x 4.141500e+00 -> y = ( .4e-5 + .3e-5 ) 7.000000e-06 -> y = ( .4e-5 - .3e-5 ) 1.000000e-06 -> y = ( .4e-5 / .3e-5 ) 1.333333e+00 -> y = ( .4e-5 * .3e-5 ) 1.200000e-11 -> y = ( .4e-5 || .3e-5 ) 1.000000e+00 -> y = ( .4e-5 && .3e-5 ) 1.000000e+00 -> y = ( -.4e-5 ) -4.000000e-06 -> y = ( !.4e-5 ) 0.000000e+00 -> y = ( .4e-5 == .3e-5 ) 0.000000e+00 -> y = ( .4e-5 != .3e-5 ) 1.000000e+00 -> y = ( .4e-5 <= .3e-5 ) 0.000000e+00 -> y = ( .4e-5 >= .3e-5 ) 1.000000e+00 -> y = ( .4e-5 < .3e-5 ) 0.000000e+00 -> y = ( .4e-5 > .3e-5 ) 1.000000e+00 -> y = ( .4e-5 ? .4e-5 : .3e-5 ) 4.000000e-06 -> y = ( x = .4e-5 ) 4.000000e-06 4.000000e-06 -> y = ( x += .4e-5 ) 3.141504e+00 3.141504e+00 -> y = ( x -= .4e-5 ) 3.141496e+00 3.141496e+00 -> y = ( x /= .4e-5 ) 7.853750e+05 7.853750e+05 -> y = ( x *= .4e-5 ) 1.256600e-05 1.256600e-05 -> y = ( x ++ ) 4.141500e+00 3.141500e+00 -> y = ( x -- ) 2.141500e+00 3.141500e+00 -> y = ( -- x ) 2.141500e+00 2.141500e+00 -> y = ( ++ x ) 4.141500e+00 4.141500e+00 -> yes if ( .4e-5 + .3e-5 ) yes() ; else no() -> yes if ( .4e-5 - .3e-5 ) yes() ; else no() -> yes if ( .4e-5 / .3e-5 ) yes() ; else no() -> yes if ( .4e-5 * .3e-5 ) yes() ; else no() -> yes if ( .4e-5 || .3e-5 ) yes() ; else no() -> yes if ( .4e-5 && .3e-5 ) yes() ; else no() -> yes if ( -.4e-5 ) yes() ; else no() -> no if ( !.4e-5 ) yes() ; else no() -> no if ( .4e-5 == .3e-5 ) yes() ; else no() -> yes if ( .4e-5 != .3e-5 ) yes() ; else no() -> no if ( .4e-5 <= .3e-5 ) yes() ; else no() -> yes if ( .4e-5 >= .3e-5 ) yes() ; else no() -> no if ( .4e-5 < .3e-5 ) yes() ; else no() -> yes if ( .4e-5 > .3e-5 ) yes() ; else no() -> yes if ( .4e-5 ? .4e-5 : .3e-5 ) yes() ; else no() -> yes if ( x = .4e-5 ) yes() ; else no() 4.000000e-06 -> yes if ( x += .4e-5 ) yes() ; else no() 3.141504e+00 -> yes if ( x -= .4e-5 ) yes() ; else no() 3.141496e+00 -> yes if ( x /= .4e-5 ) yes() ; else no() 7.853750e+05 -> yes if ( x *= .4e-5 ) yes() ; else no() 1.256600e-05 -> yes if ( x ++ ) yes() ; else no() 4.141500e+00 -> yes if ( x -- ) yes() ; else no() 2.141500e+00 -> yes if ( -- x ) yes() ; else no() 2.141500e+00 -> yes if ( ++ x ) yes() ; else no() 4.141500e+00 sed -f li.sed li.c -acc -mm68k4 -DNOFLOAT li.c +vax4 -DNOFLOAT li.c li.c running li.cem comparing li -32c32 -< x <<= 15 8355840 ---- -> x <<= 15 -32768 -48c48 -< y = ( 4 << 15 ) 131072 ---- -> y = ( 4 << 15 ) 0 -69c69 -< y = ( x <<= 15 ) 8355840 8355840 ---- -> y = ( x <<= 15 ) -32768 -32768 -85c85 -< yes if ( 4 << 15 ) yes() ; else no() ---- -> no if ( 4 << 15 ) yes() ; else no() -106c106 -< yes if ( x <<= 15 ) yes() ; else no() 8355840 ---- -> yes if ( x <<= 15 ) yes() ; else no() -32768 sed -f ll.sed ll.c -acc -mm68k4 -DNOFLOAT ll.c +vax4 -DNOFLOAT ll.c ll.c running ll.cem comparing ll sed -f lu.sed lu.c -acc -mm68k4 -DNOFLOAT lu.c +vax4 -DNOFLOAT lu.c lu.c running lu.cem comparing lu -23,31c23,31 -< z = x 40234 -< z += x 40244 -< z -= x -40224 -< z /= x 0 -< z %= x 10 -< z *= x 402340 -< z &= x 10 -< z |= x 40234 -< z ^= x 40224 ---- -> z = x -25302 -> z += x -25292 -> z -= x 25312 -> z /= x 0 -> z %= x 10 -> z *= x 9124 -> z &= x 10 -> z |= x -25302 -> z ^= x -25312 -38c38 -< y = ( x + 8012 ) 48246 ---- -> y = ( x + 8012 ) -17290 -42,52c42,52 -< y = ( x * 8012 ) 322354808 -< y = ( x & 8012 ) 7432 -< y = ( x | 8012 ) 40814 -< y = ( x ^ 8012 ) 33382 -< y = ( x || 8012 ) 1 -< y = ( x && 8012 ) 1 -< y = ( x << 9 ) 20599808 -< y = ( x >> 9 ) 78 -< y = ( -x ) -40234 -< y = ( !x ) 0 -< y = ( ~x ) -40235 ---- -> y = ( x * 8012 ) -16776 -> y = ( x & 8012 ) 7432 -> y = ( x | 8012 ) -24722 -> y = ( x ^ 8012 ) -32154 -> y = ( x || 8012 ) 1 -> y = ( x && 8012 ) 1 -> y = ( x << 9 ) 21504 -> y = ( x >> 9 ) 78 -> y = ( -x ) 25302 -> y = ( !x ) 0 -> y = ( ~x ) 25301 -59,68c59,68 -< y = ( x ? x : 8012 ) 40234 -< y = ( z = x ) 40234 40234 -< y = ( z += x ) 40244 40244 -< y = ( z -= x ) -40224 -40224 -< y = ( z /= x ) 0 0 -< y = ( z %= x ) 10 10 -< y = ( z *= x ) 402340 402340 -< y = ( z &= x ) 10 10 -< y = ( z |= x ) 40234 40234 -< y = ( z ^= x ) 40224 40224 ---- -> y = ( x ? x : 8012 ) -25302 -> y = ( z = x ) -25302 -25302 -> y = ( z += x ) -25292 -25292 -> y = ( z -= x ) 25312 25312 -> y = ( z /= x ) 0 0 -> y = ( z %= x ) 10 10 -> y = ( z *= x ) 9124 9124 -> y = ( z &= x ) 10 10 -> y = ( z |= x ) -25302 -25302 -> y = ( z ^= x ) -25312 -25312 -97,105c97,105 -< yes if ( z = x ) yes() ; else no() 40234 -< yes if ( z += x ) yes() ; else no() 40244 -< yes if ( z -= x ) yes() ; else no() -40224 -< no if ( z /= x ) yes() ; else no() 0 -< yes if ( z %= x ) yes() ; else no() 10 -< yes if ( z *= x ) yes() ; else no() 402340 -< yes if ( z &= x ) yes() ; else no() 10 -< yes if ( z |= x ) yes() ; else no() 40234 -< yes if ( z ^= x ) yes() ; else no() 40224 ---- -> yes if ( z = x ) yes() ; else no() -25302 -> yes if ( z += x ) yes() ; else no() -25292 -> yes if ( z -= x ) yes() ; else no() 25312 -> no if ( z /= x ) yes() ; else no() 0 -> yes if ( z %= x ) yes() ; else no() 10 -> yes if ( z *= x ) yes() ; else no() 9124 -> yes if ( z &= x ) yes() ; else no() 10 -> yes if ( z |= x ) yes() ; else no() -25302 -> yes if ( z ^= x ) yes() ; else no() -25312 ***** ctill ----- All program(s) in this directory should fail to compile. -acc -mm68k4 -DNOFLOAT noarg.c +vax4 -DNOFLOAT noarg.c noarg.c -"noarg.c", line 10: declared argument name is missing +"noarg.c", line 10: name not in parameter list *** Error code 1 `gen' not remade because of errors ***** ctinit -acc -mm68k4 -DNOFLOAT init.c +vax4 -DNOFLOAT init.c init.c -"init.c", line 183: warning: Overflow in constant expression (U-) -"init.c", line 224: compiler problem: initialization alignment error -*** Error code 1 -`gen' not remade because of errors +running init.cem +comparing init +41,$c41,$ +< long +< +< lo1 14 +< lo2 -17 +< lo3 2147483647 +< lo4 -2147483648 +< lo5 0 +< lo6 1 +< +< structures +< +< st1 sta[0..2] +< s_i 0 1 2 3 +< s_ca[0] 0 97 0 0 +< s_ca[1] 0 98 0 0 +< s_ca[2] 0 99 0 0 +< s_l 0 10 0 0 +< (sta[0].s_s1)->s_i = 1 +< +< bit fields: +< +< sizeof stb 8 +< stb -1 -2 3 4 -1 6 7 +< +--- +> Floats: +> +> fl1 0.00000000000000000000e+00 +> fl2 2.00000000000000000000e+00 +> fl2 2.00000000000000000000e+00 +> fl4 4.00000000000000000000e+00 +> fl5 2.93873587705571892581e-39 +> fl6 1.70141173319264428000e+38 +> fl7 0.00000000000000000000e+00 +> fla1 fla2 fla3 +> 1.000000e+00 -1.000000e+00 1.100000e+01 +> 3.000000e+00 -3.000000e+00 0.000000e+00 +> 5.000000e+00 -5.000000e+00 0.000000e+00 +> 2.000000e+00 -2.000000e+00 1.200000e+01 +> 4.000000e+00 -4.000000e+00 0.000000e+00 +> 6.000000e+00 -6.000000e+00 0.000000e+00 +> 3.000000e+00 -3.000000e+00 1.300000e+01 +> 5.000000e+00 -5.000000e+00 0.000000e+00 +> 7.000000e+00 -7.000000e+00 0.000000e+00 +> 0.000000e+00 0.000000e+00 1.400000e+01 +> 0.000000e+00 0.000000e+00 0.000000e+00 +> 0.000000e+00 0.000000e+00 0.000000e+00 +> +> Doubles: +> +> dbl1 0.00000000000000000000e+00 +> dbl2 2.00000000000000000000e+00 +> dbl2 2.00000000000000000000e+00 +> dbl4 4.00000000000000000000e+00 +> dbl5 2.93873600000000034793e-39 +> dbl6 1.70141170000000000000e+38 +> dbl7 0.00000000000000000000e+00 +> dbla1 dbla2 dbla3 +> 1.000000e+00 -1.000000e+00 1.100000e+01 +> 3.000000e+00 -3.000000e+00 0.000000e+00 +> 5.000000e+00 -5.000000e+00 0.000000e+00 +> 2.000000e+00 -2.000000e+00 1.200000e+01 +> 4.000000e+00 -4.000000e+00 0.000000e+00 +> 6.000000e+00 -6.000000e+00 0.000000e+00 +> 3.000000e+00 -3.000000e+00 1.300000e+01 +> 5.000000e+00 -5.000000e+00 0.000000e+00 +> 7.000000e+00 -7.000000e+00 0.000000e+00 +> 0.000000e+00 0.000000e+00 1.400000e+01 +> 0.000000e+00 0.000000e+00 0.000000e+00 +> 0.000000e+00 0.000000e+00 0.000000e+00 +> +> long +> +> lo1 14 +> lo2 -17 +> lo3 2147483647 +> lo4 -2147483648 +> lo5 0 +> lo6 1 +> +> structures +> +> st1 sta[0..2] +> s_i 0 1 2 3 +> s_ca[0] 0 97 0 0 +> s_ca[1] 0 98 0 0 +> s_ca[2] 0 99 0 0 +> s_l 0 10 0 0 +> s_f 0.000000e+00 -1.000000e+01 0.000000e+00 0.000000e+00 +> +> (sta[0].s_s1)->s_i = 1 +> +> bit fields: +> +> sizeof stb 8 +> stb -1 -2 3 4 -1 6 7 +> ***** ctmargt -acc -mm68k4 -DNOFLOAT margt.c +vax4 -DNOFLOAT margt.c margt.c running margt.cem comparing margt 5,$c5,$ -< HOME=/usr/em -< NAME=em -< PATH=:/bin/:/usr/bin:/usr/em/bin -< SHELL=/bin/sh -< TERM=d80 +< CDPATH=:~:~em:/usr/spool +< CWD=/usr/em/lang/cem/ctest/ctmargt +< ESHKEYS=dcl=^?:dcl=^H:dcr=^D:dlr=^K:dtm=^W:dwl=^[h:dew=^[d:eof=^[^C:eof=^X^C:eof=^X^F:exp=^u:fcl=^[?:fcr=^[/:gcl=^B:gcr=^F:gll=^A:glr=^E:gwl=^[b:gew=^[f:hlp=^[H:hst=^_:int=^G:lnx=^V:prh=^P:rdr=^L:rtn=^J:rtn=^M:stm=^@:tab=^I:xgm=^X^X:xpl=^[^J:xpl=^[^M:yn< k=^Y:ipl=^N +< HOME=/user0/ceriel +< M2PATH=.:/user0/ceriel/modula-2/lib/m2v +< PAGER=/user0/ceriel/bin/yap +< PATH=/user0/ceriel/bin:/usr/local:/usr/ucb:/bin:/usr/bin:/usr/em/bin:/usr/new::/user0/ceriel/modula-2/bin/m2v +< REFS=/user0/ceriel/etc/refer/refs +< SHELL=/usr/local/esh +< TERM=sun +< TERMCAP=Mu|sun:li#34:co#80:cl=^L:cm=\E[%i%d;%dH:nd=\E[C:up=\E[A:am:bs:mi:ms:ce=\E[K:cd=\E[J:so=\E[7m:se=\E[m:kd=\E[B:kl=\E[D:ku=\E[A:kr=\E[C:kh=\E[H:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:al=\E[L:dl=\E[M:im=:ei=:ic=\E[@:dc=\E[P +< USER=ceriel --- -> HOME=/other/keie -> PATH=:/other/keie/bin:/bin:/usr/bin -> TERM=MiniBee +> HOME=/usr/em +> PATH=:/bin:/usr/ucb:/usr/local:/usr/bin:/usr/em/bin +> SHELL=/usr/local/esh +> TERM=dialup +> USER=em ***** ctprof test profiling procentry.c -acc -mm68k4 -DNOFLOAT tp.c procentry.k +vax4 -DNOFLOAT tp.c procentry.k tp.c procentry.k running tp comparing tp -sh: 3905 Memory fault - core dumped -*** Error code -117 (ignored) ***** ctstruct -acc -mm68k4 -DNOFLOAT str.c +vax4 -DNOFLOAT str.c str.c running str.cem comparing str ***** ctsys -acc -mm68k4 -DNOFLOAT tfork.c +vax4 -DNOFLOAT tfork.c tfork.c running tfork.cem comparing tfork 1,$c1,$ -< childno 3944 -< Child 3944, status 0x800 +< childno 11517 +< Child 11517, status 0x800 < fork/wait ok --- -> childno N -> Child N, status 0x800 +> childno 16276 +> Child 16276, status 0x800 > fork/wait ok -Fri Mar 15 16:15:13 GMT 1985 +Wed Feb 25 13:05:57 MET 1987 diff --git a/lang/cem/ctest/Out4.std b/lang/cem/ctest/Out4.std index 136b96be..8a7791b5 100644 --- a/lang/cem/ctest/Out4.std +++ b/lang/cem/ctest/Out4.std @@ -1,631 +1,195 @@ -Tue Feb 5 15:35:34 MET 1985 +Tue Feb 24 13:49:31 MET 1987 ***** ctconv -vax4 conv.c +acc conv.c conv.c -"conv.c", line 41: warning: Overflow in constant expression +"conv.c", line 48: (warning) overflow in constant expression running conv.cem comparing conv -16,18c16,18 -< char 192, int -64, unsigned 37777777700, long -64, float -64.000000 -< From long -< char 253, int -3, unsigned 37777777775, long -3, float -3.000000 ---- -> char 192, int -64, unsigned 177700, long -64, float -64.000000 -> From long -> char 253, int -3, unsigned 177775, long -3, float -3.000000 ***** ctdecl -vax4 decl.c +acc decl.c decl.c running decl.cem comparing decl ***** ctdivers -vax4 ops.c +acc ops.c ops.c running ops.cem comparing ops -24,39c24,39 -< u<<1 321632 -< u<<2 643464 -< u<<3 1507150 -< u<<4 3216320 -< u<<5 6434640 -< u<<6 15071500 -< u<<7 32163200 -< u<<8 64346400 -< u<<9 150715000 -< u<<10 321632000 -< u<<11 643464000 -< u<<12 1507150000 -< u<<13 3216320000 -< u<<14 6434640000 -< u<<15 15071500000 -< u<<16 32163200000 ---- -> u<<1 121632 -> u<<2 043464 -> u<<3 107150 -> u<<4 016320 -> u<<5 034640 -> u<<6 071500 -> u<<7 163200 -> u<<8 146400 -> u<<9 115000 -> u<<10 032000 -> u<<11 064000 -> u<<12 150000 -> u<<13 120000 -> u<<14 040000 -> u<<15 100000 -> u<<16 000000 ***** cterr -vax4 bugs.c +acc bugs.c bugs.c -"bugs.c", line 92: warning: Overflow in constant expression +"bugs.c", line 98: (warning) overflow in constant expression running bugs.cem +*** Error code -21 (ignored) comparing bugs ***** ctest1 -vax4 test.c +acc test.c test.c running test.cem comparing test ***** ctest2 -vax4 t7.c +acc t7.c t7.c -"t7.c", line 161: warning: statement not reached -"t7.c", line 178: warning: statement not reached -"t7.c", line 182: warning: statement not reached -"t7.c", line 186: warning: statement not reached -"t7.c", line 190: warning: statement not reached -"t7.c", line 194: warning: statement not reached -"t7.c", line 198: warning: statement not reached -"t7.c", line 205: warning: statement not reached -"t7.c", line 207: warning: statement not reached -"t7.c", line 211: warning: statement not reached -"t7.c", line 213: warning: statement not reached -"t7.c", line 287: warning: statement not reached -"t7.c", line 294: warning: statement not reached -"t7.c", line 300: warning: statement not reached -"t7.c", line 307: warning: statement not reached -"t7.c", line 343: warning: statement not reached -"t7.c", line 344: warning: statement not reached -"t7.c", line 345: warning: statement not reached -"t7.c", line 346: warning: statement not reached -"t7.c", line 348: warning: statement not reached -"t7.c", line 452: warning: statement not reached -"t7.c", line 561: warning: statement not reached -"t7.c", line 589: warning: statement not reached running t7.cem comparing t7 ***** ctest3 -vax4 test2.c +acc test2.c test2.c running test2.cem comparing test2 ***** ctest5 -vax4 test1.c +acc test1.c test1.c -"test1.c", line 101: warning: Illegal shift count in constant expression -"test1.c", line 370: warning: illegal pointer combination -"test1.c", line 371: warning: illegal pointer combination -"test1.c", line 372: warning: illegal pointer combination -"test1.c", line 384: warning: illegal pointer combination -"test1.c", line 407: warning: illegal pointer combination -"test1.c", line 408: warning: illegal pointer combination -"test1.c", line 409: warning: illegal pointer combination -"test1.c", line 421: warning: illegal pointer combination +"test1.c", line 386: (warning) incompatible pointers in = +"test1.c", line 387: (warning) incompatible pointers in = +"test1.c", line 388: (warning) incompatible pointers in = +"test1.c", line 400: (warning) incompatible pointers in = +"test1.c", line 423: (warning) incompatible pointers in = +"test1.c", line 424: (warning) incompatible pointers in = +"test1.c", line 425: (warning) incompatible pointers in = +"test1.c", line 437: (warning) incompatible pointers in = running test1.cem comparing test1 ***** ctgen sed -f bf.sed bf.c -vax4 bf.c +acc bf.c bf.c running bf.cem comparing bf -39c39 -< bfs.bf4 = ( bfs.bf1 - bfs.bf2 ) 65529 ---- -> bfs.bf4 = ( bfs.bf1 - bfs.bf2 ) -7 -50,52c50,52 -< bfs.bf4 = ( -bfs.bf1 ) 65535 -< bfs.bf4 = ( !bfs.bf1 ) 0 -< bfs.bf4 = ( ~bfs.bf1 ) 65534 ---- -> bfs.bf4 = ( -bfs.bf1 ) -1 -> bfs.bf4 = ( !bfs.bf1 ) 0 -> bfs.bf4 = ( ~bfs.bf1 ) -2 sed -f cel.sed cel.c -vax4 cel.c +acc cel.c cel.c running cel.cem comparing cel sed -f clu.sed clu.c -vax4 clu.c +acc clu.c clu.c running clu.cem comparing clu -23,31c23,31 -< x = 40000 40000 -< x += 40000 40010 -< x -= 40000 -39990 -< x /= 40000 0 -< x %= 40000 10 -< x *= 40000 400000 -< x &= 40000 0 -< x |= 40000 40010 -< x ^= 40000 40010 ---- -> x = 40000 -25536 -> x += 40000 -25526 -> x -= 40000 25546 -> x /= 40000 0 -> x %= 40000 10 -> x *= 40000 6784 -> x &= 40000 0 -> x |= 40000 -25526 -> x ^= 40000 -25526 -38c38 -< y = ( 40000 + 8012 ) 48012 ---- -> y = ( 40000 + 8012 ) -17524 -42,52c42,52 -< y = ( 40000 * 8012 ) 320480000 -< y = ( 40000 & 8012 ) 7232 -< y = ( 40000 | 8012 ) 40780 -< y = ( 40000 ^ 8012 ) 33548 -< y = ( 40000 || 8012 ) 1 -< y = ( 40000 && 8012 ) 1 -< y = ( 40000 << 9 ) 20480000 -< y = ( 40000 >> 9 ) 78 -< y = ( -40000 ) -40000 -< y = ( !40000 ) 0 -< y = ( ~40000 ) -40001 ---- -> y = ( 40000 * 8012 ) 8960 -> y = ( 40000 & 8012 ) 7232 -> y = ( 40000 | 8012 ) -24756 -> y = ( 40000 ^ 8012 ) -31988 -> y = ( 40000 || 8012 ) 1 -> y = ( 40000 && 8012 ) 1 -> y = ( 40000 << 9 ) -32768 -> y = ( 40000 >> 9 ) 78 -> y = ( -40000 ) 25536 -> y = ( !40000 ) 0 -> y = ( ~40000 ) 25535 -59,68c59,68 -< y = ( 40000 ? 40000 : 8012 ) 40000 -< y = ( x = 40000 ) 40000 40000 -< y = ( x += 40000 ) 40010 40010 -< y = ( x -= 40000 ) -39990 -39990 -< y = ( x /= 40000 ) 0 0 -< y = ( x %= 40000 ) 10 10 -< y = ( x *= 40000 ) 400000 400000 -< y = ( x &= 40000 ) 0 0 -< y = ( x |= 40000 ) 40010 40010 -< y = ( x ^= 40000 ) 40010 40010 ---- -> y = ( 40000 ? 40000 : 8012 ) -25536 -> y = ( x = 40000 ) -25536 -25536 -> y = ( x += 40000 ) -25526 -25526 -> y = ( x -= 40000 ) 25546 25546 -> y = ( x /= 40000 ) 0 0 -> y = ( x %= 40000 ) 10 10 -> y = ( x *= 40000 ) 6784 6784 -> y = ( x &= 40000 ) 0 0 -> y = ( x |= 40000 ) -25526 -25526 -> y = ( x ^= 40000 ) -25526 -25526 -97,105c97,105 -< yes if ( x = 40000 ) yes() ; else no() 40000 -< yes if ( x += 40000 ) yes() ; else no() 40010 -< yes if ( x -= 40000 ) yes() ; else no() -39990 -< no if ( x /= 40000 ) yes() ; else no() 0 -< yes if ( x %= 40000 ) yes() ; else no() 10 -< yes if ( x *= 40000 ) yes() ; else no() 400000 -< no if ( x &= 40000 ) yes() ; else no() 0 -< yes if ( x |= 40000 ) yes() ; else no() 40010 -< yes if ( x ^= 40000 ) yes() ; else no() 40010 ---- -> yes if ( x = 40000 ) yes() ; else no() -25536 -> yes if ( x += 40000 ) yes() ; else no() -25526 -> yes if ( x -= 40000 ) yes() ; else no() 25546 -> no if ( x /= 40000 ) yes() ; else no() 0 -> yes if ( x %= 40000 ) yes() ; else no() 10 -> yes if ( x *= 40000 ) yes() ; else no() 6784 -> no if ( x &= 40000 ) yes() ; else no() 0 -> yes if ( x |= 40000 ) yes() ; else no() -25526 -> yes if ( x ^= 40000 ) yes() ; else no() -25526 sed -f ec.sed ec.c -vax4 ec.c +acc ec.c ec.c -"ec.c", line 58: warning: Overflow in constant expression -"ec.c", line 64: warning: Overflow in constant expression +"ec.c", line 58: (warning) overflow in constant expression +"ec.c", line 64: (warning) overflow in constant expression running ec.cem comparing ec sed -f ef.sed ef.c -vax4 ef.c +acc ef.c ef.c running ef.cem comparing ef sed -f ei.sed ei.c -vax4 ei.c +acc ei.c ei.c running ei.cem comparing ei -32c32 -< x <<= 15 8355840 ---- -> x <<= 15 -32768 -48c48 -< y = ( 4 << 15 ) 131072 ---- -> y = ( 4 << 15 ) 0 -69c69 -< y = ( x <<= 15 ) 8355840 8355840 ---- -> y = ( x <<= 15 ) -32768 -32768 -85c85 -< yes if ( 4 << 15 ) yes() ; else no() ---- -> no if ( 4 << 15 ) yes() ; else no() -106c106 -< yes if ( x <<= 15 ) yes() ; else no() 8355840 ---- -> yes if ( x <<= 15 ) yes() ; else no() -32768 sed -f el.sed el.c -vax4 el.c +acc el.c el.c running el.cem comparing el sed -f eu.sed eu.c -vax4 eu.c +acc eu.c eu.c running eu.cem comparing eu -23,31c23,31 -< x = 40000 40000 -< x += 40000 40010 -< x -= 40000 -39990 -< x /= 40000 0 -< x %= 40000 10 -< x *= 40000 400000 -< x &= 40000 0 -< x |= 40000 40010 -< x ^= 40000 40010 ---- -> x = 40000 -25536 -> x += 40000 -25526 -> x -= 40000 25546 -> x /= 40000 0 -> x %= 40000 10 -> x *= 40000 6784 -> x &= 40000 0 -> x |= 40000 -25526 -> x ^= 40000 -25526 -38c38 -< y = ( 40000 + 8012 ) 48012 ---- -> y = ( 40000 + 8012 ) -17524 -42,52c42,52 -< y = ( 40000 * 8012 ) 320480000 -< y = ( 40000 & 8012 ) 7232 -< y = ( 40000 | 8012 ) 40780 -< y = ( 40000 ^ 8012 ) 33548 -< y = ( 40000 || 8012 ) 1 -< y = ( 40000 && 8012 ) 1 -< y = ( 40000 << 9 ) 20480000 -< y = ( 40000 >> 9 ) 78 -< y = ( -40000 ) -40000 -< y = ( !40000 ) 0 -< y = ( ~40000 ) -40001 ---- -> y = ( 40000 * 8012 ) 8960 -> y = ( 40000 & 8012 ) 7232 -> y = ( 40000 | 8012 ) -24756 -> y = ( 40000 ^ 8012 ) -31988 -> y = ( 40000 || 8012 ) 1 -> y = ( 40000 && 8012 ) 1 -> y = ( 40000 << 9 ) -32768 -> y = ( 40000 >> 9 ) 78 -> y = ( -40000 ) 25536 -> y = ( !40000 ) 0 -> y = ( ~40000 ) 25535 -59,68c59,68 -< y = ( 40000 ? 40000 : 8012 ) 40000 -< y = ( x = 40000 ) 40000 40000 -< y = ( x += 40000 ) 40010 40010 -< y = ( x -= 40000 ) -39990 -39990 -< y = ( x /= 40000 ) 0 0 -< y = ( x %= 40000 ) 10 10 -< y = ( x *= 40000 ) 400000 400000 -< y = ( x &= 40000 ) 0 0 -< y = ( x |= 40000 ) 40010 40010 -< y = ( x ^= 40000 ) 40010 40010 ---- -> y = ( 40000 ? 40000 : 8012 ) -25536 -> y = ( x = 40000 ) -25536 -25536 -> y = ( x += 40000 ) -25526 -25526 -> y = ( x -= 40000 ) 25546 25546 -> y = ( x /= 40000 ) 0 0 -> y = ( x %= 40000 ) 10 10 -> y = ( x *= 40000 ) 6784 6784 -> y = ( x &= 40000 ) 0 0 -> y = ( x |= 40000 ) -25526 -25526 -> y = ( x ^= 40000 ) -25526 -25526 -97,105c97,105 -< yes if ( x = 40000 ) yes() ; else no() 40000 -< yes if ( x += 40000 ) yes() ; else no() 40010 -< yes if ( x -= 40000 ) yes() ; else no() -39990 -< no if ( x /= 40000 ) yes() ; else no() 0 -< yes if ( x %= 40000 ) yes() ; else no() 10 -< yes if ( x *= 40000 ) yes() ; else no() 400000 -< no if ( x &= 40000 ) yes() ; else no() 0 -< yes if ( x |= 40000 ) yes() ; else no() 40010 -< yes if ( x ^= 40000 ) yes() ; else no() 40010 ---- -> yes if ( x = 40000 ) yes() ; else no() -25536 -> yes if ( x += 40000 ) yes() ; else no() -25526 -> yes if ( x -= 40000 ) yes() ; else no() 25546 -> no if ( x /= 40000 ) yes() ; else no() 0 -> yes if ( x %= 40000 ) yes() ; else no() 10 -> yes if ( x *= 40000 ) yes() ; else no() 6784 -> no if ( x &= 40000 ) yes() ; else no() 0 -> yes if ( x |= 40000 ) yes() ; else no() -25526 -> yes if ( x ^= 40000 ) yes() ; else no() -25526 sed -f id.sed id.c -vax4 id.c +acc id.c id.c running id.cem comparing id -26,28c26,28 -< y = ( (-40) - 300 ) 50346 -< y = ( (-40) / 300 ) 0 -< y = ( (-40) * 300 ) -2147432645 ---- -> y = ( (-40) - 300 ) -15190 -> y = ( (-40) / 300 ) 0 -> y = ( (-40) * 300 ) -14533 -39,48c39,48 -< y = ( (-40) ? (-40) : 300 ) 49952 -< y = ( x = (-40) ) -4.000000e+01 49952 -< y = ( x += (-40) ) -3.685850e+01 1864024851 -< y = ( x -= (-40) ) 4.314150e+01 -1864023252 -< y = ( x /= (-40) ) -7.853750e-02 -666583392 -< y = ( x *= (-40) ) -1.256600e+02 1374405627 -< y = ( x ++ ) 4.141500e+00 240533833 -< y = ( x -- ) 2.141500e+00 240533833 -< y = ( -- x ) 2.141500e+00 240533769 -< y = ( ++ x ) 4.141500e+00 -2027208316 ---- -> y = ( (-40) ? (-40) : 300 ) -15584 -> y = ( x = (-40) ) -4.000000e+01 -15584 -> y = ( x += (-40) ) -3.685850e+01 -15597 -> y = ( x -= (-40) ) 4.314150e+01 17196 -> y = ( x /= (-40) ) -7.853750e-02 -16736 -> y = ( x *= (-40) ) -1.256600e+02 -15365 -> y = ( x ++ ) 4.141500e+00 16713 -> y = ( x -- ) 2.141500e+00 16713 -> y = ( -- x ) 2.141500e+00 16649 -> y = ( ++ x ) 4.141500e+00 16772 sed -f lc.sed lc.c -vax4 lc.c +acc lc.c lc.c -"lc.c", line 60: warning: Overflow in constant expression -"lc.c", line 66: warning: Overflow in constant expression +"lc.c", line 60: (warning) overflow in constant expression +"lc.c", line 66: (warning) overflow in constant expression running lc.cem comparing lc sed -f ld.sed ld.c -vax4 ld.c +acc ld.c ld.c running ld.cem comparing ld sed -f lf.sed lf.c -vax4 lf.c +acc lf.c lf.c running lf.cem comparing lf sed -f li.sed li.c -vax4 li.c +acc li.c li.c running li.cem comparing li -32c32 -< x <<= 15 8355840 ---- -> x <<= 15 -32768 -48c48 -< y = ( 4 << 15 ) 131072 ---- -> y = ( 4 << 15 ) 0 -69c69 -< y = ( x <<= 15 ) 8355840 8355840 ---- -> y = ( x <<= 15 ) -32768 -32768 -85c85 -< yes if ( 4 << 15 ) yes() ; else no() ---- -> no if ( 4 << 15 ) yes() ; else no() -106c106 -< yes if ( x <<= 15 ) yes() ; else no() 8355840 ---- -> yes if ( x <<= 15 ) yes() ; else no() -32768 sed -f ll.sed ll.c -vax4 ll.c +acc ll.c ll.c running ll.cem comparing ll sed -f lu.sed lu.c -vax4 lu.c +acc lu.c lu.c running lu.cem comparing lu -23,31c23,31 -< z = x 40234 -< z += x 40244 -< z -= x -40224 -< z /= x 0 -< z %= x 10 -< z *= x 402340 -< z &= x 10 -< z |= x 40234 -< z ^= x 40224 ---- -> z = x -25302 -> z += x -25292 -> z -= x 25312 -> z /= x 0 -> z %= x 10 -> z *= x 9124 -> z &= x 10 -> z |= x -25302 -> z ^= x -25312 -38c38 -< y = ( x + 8012 ) 48246 ---- -> y = ( x + 8012 ) -17290 -42,52c42,52 -< y = ( x * 8012 ) 322354808 -< y = ( x & 8012 ) 7432 -< y = ( x | 8012 ) 40814 -< y = ( x ^ 8012 ) 33382 -< y = ( x || 8012 ) 1 -< y = ( x && 8012 ) 1 -< y = ( x << 9 ) 20599808 -< y = ( x >> 9 ) 78 -< y = ( -x ) -40234 -< y = ( !x ) 0 -< y = ( ~x ) -40235 ---- -> y = ( x * 8012 ) -16776 -> y = ( x & 8012 ) 7432 -> y = ( x | 8012 ) -24722 -> y = ( x ^ 8012 ) -32154 -> y = ( x || 8012 ) 1 -> y = ( x && 8012 ) 1 -> y = ( x << 9 ) 21504 -> y = ( x >> 9 ) 78 -> y = ( -x ) 25302 -> y = ( !x ) 0 -> y = ( ~x ) 25301 -59,68c59,68 -< y = ( x ? x : 8012 ) 40234 -< y = ( z = x ) 40234 40234 -< y = ( z += x ) 40244 40244 -< y = ( z -= x ) -40224 -40224 -< y = ( z /= x ) 0 0 -< y = ( z %= x ) 10 10 -< y = ( z *= x ) 402340 402340 -< y = ( z &= x ) 10 10 -< y = ( z |= x ) 40234 40234 -< y = ( z ^= x ) 40224 40224 ---- -> y = ( x ? x : 8012 ) -25302 -> y = ( z = x ) -25302 -25302 -> y = ( z += x ) -25292 -25292 -> y = ( z -= x ) 25312 25312 -> y = ( z /= x ) 0 0 -> y = ( z %= x ) 10 10 -> y = ( z *= x ) 9124 9124 -> y = ( z &= x ) 10 10 -> y = ( z |= x ) -25302 -25302 -> y = ( z ^= x ) -25312 -25312 -97,105c97,105 -< yes if ( z = x ) yes() ; else no() 40234 -< yes if ( z += x ) yes() ; else no() 40244 -< yes if ( z -= x ) yes() ; else no() -40224 -< no if ( z /= x ) yes() ; else no() 0 -< yes if ( z %= x ) yes() ; else no() 10 -< yes if ( z *= x ) yes() ; else no() 402340 -< yes if ( z &= x ) yes() ; else no() 10 -< yes if ( z |= x ) yes() ; else no() 40234 -< yes if ( z ^= x ) yes() ; else no() 40224 ---- -> yes if ( z = x ) yes() ; else no() -25302 -> yes if ( z += x ) yes() ; else no() -25292 -> yes if ( z -= x ) yes() ; else no() 25312 -> no if ( z /= x ) yes() ; else no() 0 -> yes if ( z %= x ) yes() ; else no() 10 -> yes if ( z *= x ) yes() ; else no() 9124 -> yes if ( z &= x ) yes() ; else no() 10 -> yes if ( z |= x ) yes() ; else no() -25302 -> yes if ( z ^= x ) yes() ; else no() -25312 ***** ctill ------ An missing argument error should be reported -vax4 noarg.c +----- All program(s) in this directory should fail to compile. +acc noarg.c noarg.c -"noarg.c", line 8: declared argument name is missing +"noarg.c", line 10: name not in parameter list *** Error code 1 `gen' not remade because of errors ***** ctinit -vax4 init.c +acc init.c init.c -"init.c", line 179: warning: Overflow in constant expression (U-) running init.cem comparing init -48c48 -< fl6 1.70141173319264427000e+38 ---- -> fl6 1.70141163178059625000e+38 -110,$c110,$ -< sizeof stb 8 -< stb 1 2 3 4 3 6 7 -< ---- -> sizeof stb 6 -> stb 1 2 3 4 3 6 7 -> ***** ctmargt -vax4 margt.c +acc margt.c margt.c running margt.cem comparing margt 5,$c5,$ -< BELL= -< BIN=/user0/keie/bin -< CDPATH=:/usr/em/util:/usr/em/mach:/usr/em/lang -< DIT=/user0/keie/ditroff/troff/a.out -< HOME=/usr/em -< MAILHEADER=To: botter!vu44!mcvax!%t -< Subject: Re: %S -< Newsgroups: %n -< In-Reply-To: %i -< %(%[references]!=^$?References\: %[references] -< )Organization: %o -< Cc: -< Bcc: -< -< -< PATH=:/user0/keie/bin:/usr/local:/usr/ucb:/bin:/usr/bin:/usr/em/bin:/usr/new -< SHELL=/usr/local/dsh -< TERM=d80 -< TERMCAP=ME|ampex|d80|dialogue|dialogue80:am:bs:pt:if=/usr/lib/tabset/stdcrt:cl=\E;:cm=\E=%+\040%+\040:al=10\EE:ic=3\EQ:im=:ei=:dl=10\ER:dc=\EW:is=\EA:ho=^^:ce=\ET:cd=\EY:so=\Ej:se=\Ek:us=\El:ue=\Em:ul:li#24:co#80:nd=^L:up=^K:we=\Eo:ws=\En -< USER=keie +< CDPATH=:~:~em:/usr/spool +< CWD=/usr/em/lang/cem/ctest/ctmargt +< ESHKEYS=dcl=^?:dcl=^H:dcr=^D:dlr=^K:dtm=^W:dwl=^[h:dew=^[d:eof=^[^C:eof=^X^C:eof=^X^F:exp=^u:fcl=^[?:fcr=^[/:gcl=^B:gcr=^F:gll=^A:glr=^E:gwl=^[b:gew=^[f:hlp=^[H:hst=^_:int=^G:lnx=^V:prh=^P:rdr=^L:rtn=^J:rtn=^M:stm=^@:tab=^I:xgm=^X^X:xpl=^[^J:xpl=^[^M:yn< k=^Y:ipl=^N +< HOME=/user0/ceriel +< M2PATH=.:/user0/ceriel/modula-2/lib/m2v +< PAGER=/user0/ceriel/bin/yap +< PATH=/user0/ceriel/bin:/usr/local:/usr/ucb:/bin:/usr/bin:/usr/em/bin:/usr/new::/user0/ceriel/modula-2/bin/m2v +< REFS=/user0/ceriel/etc/refer/refs +< SHELL=/usr/local/esh +< TERM=sun +< TERMCAP=Mu|sun:li#34:co#80:cl=^L:cm=\E[%i%d;%dH:nd=\E[C:up=\E[A:am:bs:mi:ms:ce=\E[K:cd=\E[J:so=\E[7m:se=\E[m:kd=\E[B:kl=\E[D:ku=\E[A:kr=\E[C:kh=\E[H:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:al=\E[L:dl=\E[M:im=:ei=:ic=\E[@:dc=\E[P +< USER=ceriel --- -> HOME=/other/keie -> PATH=:/other/keie/bin:/bin:/usr/bin -> TERM=MiniBee +> HOME=/usr/em +> PATH=:/bin:/usr/ucb:/usr/local:/usr/bin:/usr/em/bin +> SHELL=/usr/local/esh +> TERM=dialup +> USER=em ***** ctprof test profiling procentry.c -vax4 tp.c procentry.k +acc tp.c procentry.k tp.c procentry.k running tp comparing tp ***** ctstruct -vax4 str.c +acc str.c str.c running str.cem comparing str ***** ctsys -vax4 tfork.c +acc tfork.c tfork.c running tfork.cem comparing tfork 1,$c1,$ -< childno 6340 -< Child 6340, status 0x800 +< childno 1066 +< Child 1066, status 0x800 < fork/wait ok --- -> childno N -> Child N, status 0x800 +> childno 16276 +> Child 16276, status 0x800 > fork/wait ok -Tue Feb 5 17:29:23 MET 1985 +Tue Feb 24 16:01:13 MET 1987 From b3e7c737bb0f7be9734cb3ae6f664ad86a62af06 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 25 Feb 1987 19:05:21 +0000 Subject: [PATCH 0894/1625] Added occam --- mach/vax4/Action | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mach/vax4/Action b/mach/vax4/Action index 69655293..2c1db956 100644 --- a/mach/vax4/Action +++ b/mach/vax4/Action @@ -9,6 +9,10 @@ name "Vax 4-4 EM library" system vax* dir libem end +name "Vax 4-4 Occam library" +system vax* +dir liboc +end name "Vax 4-4 Basic library" system vax* dir libbc From 9e73976081c8b45d45b5b107d2ca1396fc72e505 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 25 Feb 1987 19:10:01 +0000 Subject: [PATCH 0895/1625] *** empty log message *** --- util/ack/Makefile | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/util/ack/Makefile b/util/ack/Makefile index 94d04a98..4a40deea 100644 --- a/util/ack/Makefile +++ b/util/ack/Makefile @@ -9,11 +9,12 @@ OBJ=list.o data.o main.o scan.o svars.o trans.o util.o rmach.o run.o \ ACKDIR=$(EMHOME)/lib/descr FE=fe INTABLES=pdp int -LNTABLES=acc apc abc vax4 i86 m68k2 m68k4 pmds pmds4 mantra mantra4 \ +LNTABLES=acc apc abc ocm vax4 i86 m68k2 m68k4 pmds pmds4 mantra mantra4 \ m68020 z8000 int22 int24 int44 6500 6800 6805 6809 i80 ns s2650 z80 \ sun3 INCLUDES=-I$(EMHOME)/h -CFLAGS=-O -n $(INCLUDES) +CFLAGS=-O $(INCLUDES) +LDFLAGS=-i BINDIR=$(EMHOME)/bin MANDIR=$(EMHOME)/man MODDIR=$(EMHOME)/modules/lib @@ -26,8 +27,8 @@ install: ack ack.1 -cd $(BINDIR) ; \ for i in $(INTABLES) $(LNTABLES) ; do rm -f $$i ; ln ack $$i ; done (cd pc ; make install ) - rm -f $(MANDIR)/man/ack.1 - cp ack.1 $(MANDIR)/man/ack.1 + rm -f $(MANDIR)/ack.1 + cp ack.1 $(MANDIR)/ack.1 cmp: ack ack.1 -cmp ack $(BINDIR)/ack @@ -42,7 +43,7 @@ clean: (cd pc ; make clean ) ack: $(OBJ) - $(CC) -o ack $(CFLAGS) $(OBJ) $(MODDIR)/libstring.a + $(CC) $(LDFLAGS) -o ack $(OBJ) $(MODDIR)/libstring.a grows.o files.o list.o run.o \ data.o main.o scan.o trans.o rmach.o util.o : ack.h list.h From 739e8b3ec930a1ea565c62c035f5f7648c4e6aa8 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 25 Feb 1987 19:16:28 +0000 Subject: [PATCH 0896/1625] Initial revision --- mach/vax4/liboc/Makefile | 21 +++++++++++++++++++++ mach/vax4/liboc/compmodule | 6 ++++++ 2 files changed, 27 insertions(+) create mode 100644 mach/vax4/liboc/Makefile create mode 100755 mach/vax4/liboc/compmodule diff --git a/mach/vax4/liboc/Makefile b/mach/vax4/liboc/Makefile new file mode 100644 index 00000000..3bed223d --- /dev/null +++ b/mach/vax4/liboc/Makefile @@ -0,0 +1,21 @@ +SUF=o +MAKEFILE=../../proto/libg/Makefile +MACHDEF="MACH=vax4" "SUF=$(SUF)" "ASAR=ar" +PCDEF="PREF=ocm" "SUB=" "SRC=lang/occam/lib" + +install: + RANLIB=ranlib ; export RANLIB ;\ + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) tailcp + +cmp: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) tail + -../../compare tail_ocm + +clean: + -rm -f *.old *.[ce$(SUF)] tail* + +opr: + make pr | opr + +pr: + @pr Makefile diff --git a/mach/vax4/liboc/compmodule b/mach/vax4/liboc/compmodule new file mode 100755 index 00000000..6327cb99 --- /dev/null +++ b/mach/vax4/liboc/compmodule @@ -0,0 +1,6 @@ +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then + echo `basename $1 $2`.o +else + exit 1 +fi From 91ccde72914bc5223f79de86712dc221e2d80f26 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 25 Feb 1987 19:40:22 +0000 Subject: [PATCH 0897/1625] Added OPccam --- mach/em24/Action | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mach/em24/Action b/mach/em24/Action index d29cd593..46eba49f 100644 --- a/mach/em24/Action +++ b/mach/em24/Action @@ -7,3 +7,6 @@ end name "2-4 Interpreter Basic library" dir libbc end +name "2-4 Interpreter Occam library" +dir liboc +end From 660f68aa1e8034372a71132b39f306f590282b45 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 25 Feb 1987 19:44:22 +0000 Subject: [PATCH 0898/1625] Adeded Occam --- mach/i86/Action | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mach/i86/Action b/mach/i86/Action index 9c24923d..6cf501fc 100644 --- a/mach/i86/Action +++ b/mach/i86/Action @@ -4,9 +4,6 @@ end name "Intel 8086 backend" dir cg end -name "Intel 8086 download program(s)" -dir dl -end name "Intel 8086 C libraries" dir libcc end @@ -16,9 +13,15 @@ end name "Intel 8086 Pascal library" dir libpc end -name "Intel 8086 Stand-alone io library" -dir saio +name "Intel 8086 PC/IX systemcall library" +dir libsys end name "Intel 8086 Basic library" dir libbc end +name "Intel 8086 Occam library" +dir liboc +end +name "Intel 8086 conversion program from ack.out --> PC/IX a.out" +dir cv +end From 489f75a1049d030940e6333fd14f0e89ddb7ad33 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 25 Feb 1987 19:45:17 +0000 Subject: [PATCH 0899/1625] Initial revision --- mach/6500/liboc/Makefile | 20 ++++++++++++++++++++ mach/6500/liboc/compmodule | 6 ++++++ mach/em22/liboc/Makefile | 20 ++++++++++++++++++++ mach/em22/liboc/compmodule | 6 ++++++ mach/em24/liboc/Makefile | 20 ++++++++++++++++++++ mach/em24/liboc/compmodule | 6 ++++++ mach/em44/liboc/Makefile | 20 ++++++++++++++++++++ mach/em44/liboc/compmodule | 6 ++++++ mach/i80/liboc/Makefile | 20 ++++++++++++++++++++ mach/i80/liboc/compmodule | 6 ++++++ mach/i86/liboc/Makefile | 20 ++++++++++++++++++++ mach/i86/liboc/compmodule | 6 ++++++ mach/m68020/Action | 24 ++++++++++++++++++++++++ mach/m68020/liboc/Makefile | 20 ++++++++++++++++++++ mach/m68020/liboc/compmodule | 6 ++++++ mach/m68k2/liboc/Makefile | 20 ++++++++++++++++++++ mach/m68k2/liboc/compmodule | 6 ++++++ mach/m68k4/liboc/Makefile | 20 ++++++++++++++++++++ mach/m68k4/liboc/compmodule | 6 ++++++ mach/ns/liboc/Makefile | 20 ++++++++++++++++++++ mach/ns/liboc/compmodule | 6 ++++++ mach/pdp/liboc/Makefile | 21 +++++++++++++++++++++ mach/pdp/liboc/compmodule | 6 ++++++ mach/z80/liboc/Makefile | 20 ++++++++++++++++++++ mach/z80/liboc/compmodule | 6 ++++++ mach/z8000/liboc/Makefile | 20 ++++++++++++++++++++ mach/z8000/liboc/compmodule | 6 ++++++ 27 files changed, 363 insertions(+) create mode 100644 mach/6500/liboc/Makefile create mode 100755 mach/6500/liboc/compmodule create mode 100644 mach/em22/liboc/Makefile create mode 100755 mach/em22/liboc/compmodule create mode 100644 mach/em24/liboc/Makefile create mode 100755 mach/em24/liboc/compmodule create mode 100644 mach/em44/liboc/Makefile create mode 100755 mach/em44/liboc/compmodule create mode 100644 mach/i80/liboc/Makefile create mode 100755 mach/i80/liboc/compmodule create mode 100644 mach/i86/liboc/Makefile create mode 100755 mach/i86/liboc/compmodule create mode 100644 mach/m68020/Action create mode 100644 mach/m68020/liboc/Makefile create mode 100755 mach/m68020/liboc/compmodule create mode 100644 mach/m68k2/liboc/Makefile create mode 100755 mach/m68k2/liboc/compmodule create mode 100644 mach/m68k4/liboc/Makefile create mode 100755 mach/m68k4/liboc/compmodule create mode 100644 mach/ns/liboc/Makefile create mode 100755 mach/ns/liboc/compmodule create mode 100644 mach/pdp/liboc/Makefile create mode 100755 mach/pdp/liboc/compmodule create mode 100644 mach/z80/liboc/Makefile create mode 100755 mach/z80/liboc/compmodule create mode 100644 mach/z8000/liboc/Makefile create mode 100755 mach/z8000/liboc/compmodule diff --git a/mach/6500/liboc/Makefile b/mach/6500/liboc/Makefile new file mode 100644 index 00000000..54288d34 --- /dev/null +++ b/mach/6500/liboc/Makefile @@ -0,0 +1,20 @@ +SUF=s +MAKEFILE=../../proto/libg/Makefile +MACHDEF="MACH=6500" "SUF=$(SUF)" +PCDEF="PREF=ocm" "SUB=" "SRC=lang/occam/lib" + +install: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) tailcp + +cmp: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) tail + -../../compare tail_ocm + +clean: + -rm -f *.old *.[ce$(SUF)] tail* + +opr: + make pr | opr + +pr: + @pr Makefile diff --git a/mach/6500/liboc/compmodule b/mach/6500/liboc/compmodule new file mode 100755 index 00000000..8dba8a44 --- /dev/null +++ b/mach/6500/liboc/compmodule @@ -0,0 +1,6 @@ +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then + echo `basename $1 $2`.s +else + exit 1 +fi diff --git a/mach/em22/liboc/Makefile b/mach/em22/liboc/Makefile new file mode 100644 index 00000000..6c55f94d --- /dev/null +++ b/mach/em22/liboc/Makefile @@ -0,0 +1,20 @@ +SUF=m +MAKEFILE=../../proto/libg/Makefile +MACHDEF="MACH=int22" "SUF=$(SUF)" +PCDEF="PREF=ocm" "SUB=" "SRC=lang/occam/lib" + +install: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) tailcp + +cmp: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) tail + -../../compare tail_ocm + +clean: + -rm -f *.old *.[ce$(SUF)] tail* + +opr: + make pr | opr + +pr: + @pr Makefile diff --git a/mach/em22/liboc/compmodule b/mach/em22/liboc/compmodule new file mode 100755 index 00000000..8b30d1fd --- /dev/null +++ b/mach/em22/liboc/compmodule @@ -0,0 +1,6 @@ +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then + echo `basename $1 $2`.m +else + exit 1 +fi diff --git a/mach/em24/liboc/Makefile b/mach/em24/liboc/Makefile new file mode 100644 index 00000000..1b91894b --- /dev/null +++ b/mach/em24/liboc/Makefile @@ -0,0 +1,20 @@ +SUF=m +MAKEFILE=../../proto/libg/Makefile +MACHDEF="MACH=int24" "SUF=$(SUF)" +PCDEF="PREF=ocm" "SUB=" "SRC=lang/occam/lib" + +install: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) tailcp + +cmp: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) tail + -../../compare tail_ocm + +clean: + -rm -f *.old *.[ce$(SUF)] tail* + +opr: + make pr | opr + +pr: + @pr Makefile diff --git a/mach/em24/liboc/compmodule b/mach/em24/liboc/compmodule new file mode 100755 index 00000000..8b30d1fd --- /dev/null +++ b/mach/em24/liboc/compmodule @@ -0,0 +1,6 @@ +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then + echo `basename $1 $2`.m +else + exit 1 +fi diff --git a/mach/em44/liboc/Makefile b/mach/em44/liboc/Makefile new file mode 100644 index 00000000..647303d2 --- /dev/null +++ b/mach/em44/liboc/Makefile @@ -0,0 +1,20 @@ +SUF=m +MAKEFILE=../../proto/libg/Makefile +MACHDEF="MACH=int44" "SUF=$(SUF)" +PCDEF="PREF=ocm" "SUB=" "SRC=lang/occam/lib" + +install: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) tailcp + +cmp: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) tail + -../../compare tail_ocm + +clean: + -rm -f *.old *.[ce$(SUF)] tail* + +opr: + make pr | opr + +pr: + @pr Makefile diff --git a/mach/em44/liboc/compmodule b/mach/em44/liboc/compmodule new file mode 100755 index 00000000..8b30d1fd --- /dev/null +++ b/mach/em44/liboc/compmodule @@ -0,0 +1,6 @@ +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then + echo `basename $1 $2`.m +else + exit 1 +fi diff --git a/mach/i80/liboc/Makefile b/mach/i80/liboc/Makefile new file mode 100644 index 00000000..68eb6a2c --- /dev/null +++ b/mach/i80/liboc/Makefile @@ -0,0 +1,20 @@ +SUF=o +MAKEFILE=../../proto/libg/Makefile +MACHDEF="MACH=i80" "SUF=$(SUF)" "ASAR=aal" +PCDEF="PREF=ocm" "SUB=" "SRC=lang/occam/lib" + +install: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) tailcp + +cmp: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) tail + -../../compare tail_ocm + +clean: + -rm -f *.old *.[ce$(SUF)] tail* + +opr: + make pr | opr + +pr: + @pr Makefile diff --git a/mach/i80/liboc/compmodule b/mach/i80/liboc/compmodule new file mode 100755 index 00000000..6327cb99 --- /dev/null +++ b/mach/i80/liboc/compmodule @@ -0,0 +1,6 @@ +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then + echo `basename $1 $2`.o +else + exit 1 +fi diff --git a/mach/i86/liboc/Makefile b/mach/i86/liboc/Makefile new file mode 100644 index 00000000..17324df5 --- /dev/null +++ b/mach/i86/liboc/Makefile @@ -0,0 +1,20 @@ +SUF=o +MAKEFILE=../../proto/libg/Makefile +MACHDEF="MACH=i86" "SUF=$(SUF)" "ASAR=aal" +PCDEF="PREF=ocm" "SUB=" "SRC=lang/occam/lib" + +install: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) tailcp + +cmp: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) tail + -../../compare tail_ocm + +clean: + -rm -f *.old *.[ce$(SUF)] tail* + +opr: + make pr | opr + +pr: + @pr Makefile diff --git a/mach/i86/liboc/compmodule b/mach/i86/liboc/compmodule new file mode 100755 index 00000000..6327cb99 --- /dev/null +++ b/mach/i86/liboc/compmodule @@ -0,0 +1,6 @@ +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then + echo `basename $1 $2`.o +else + exit 1 +fi diff --git a/mach/m68020/Action b/mach/m68020/Action new file mode 100644 index 00000000..6c34fdbd --- /dev/null +++ b/mach/m68020/Action @@ -0,0 +1,24 @@ +name "M68020 assembler" +dir as +end +name "M68020 backend" +dir ncg +end +name "M68020 EM library" +dir libem +end +name "M68020 system call library" +dir libsys +end +name "M68020 C libraries" +dir libcc +end +name "M68020 PC library" +dir libpc +end +name "M68020 Basic library" +dir libbc +end +name "M68020 Occam library" +dir liboc +end diff --git a/mach/m68020/liboc/Makefile b/mach/m68020/liboc/Makefile new file mode 100644 index 00000000..b985fb35 --- /dev/null +++ b/mach/m68020/liboc/Makefile @@ -0,0 +1,20 @@ +SUF=o +MAKEFILE=../../proto/libg/Makefile +MACHDEF="MACH=m68020" "SUF=$(SUF)" "ASAR=aal" +PCDEF="PREF=ocm" "SUB=" "SRC=lang/occam/lib" + +install: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) tailcp + +cmp: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) tail + -../../compare tail_ocm + +clean: + -rm -f *.old *.[ce$(SUF)] tail* + +opr: + make pr | opr + +pr: + @pr Makefile diff --git a/mach/m68020/liboc/compmodule b/mach/m68020/liboc/compmodule new file mode 100755 index 00000000..6327cb99 --- /dev/null +++ b/mach/m68020/liboc/compmodule @@ -0,0 +1,6 @@ +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then + echo `basename $1 $2`.o +else + exit 1 +fi diff --git a/mach/m68k2/liboc/Makefile b/mach/m68k2/liboc/Makefile new file mode 100644 index 00000000..2b4f9059 --- /dev/null +++ b/mach/m68k2/liboc/Makefile @@ -0,0 +1,20 @@ +SUF=o +MAKEFILE=../../proto/libg/Makefile +MACHDEF="MACH=m68k2" "SUF=$(SUF)" "ASAR=aal" +PCDEF="PREF=ocm" "SUB=" "SRC=lang/occam/lib" + +install: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) tailcp + +cmp: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) tail + -../../compare tail_ocm + +clean: + -rm -f *.old *.[ce$(SUF)] tail* + +opr: + make pr | opr + +pr: + @pr Makefile diff --git a/mach/m68k2/liboc/compmodule b/mach/m68k2/liboc/compmodule new file mode 100755 index 00000000..6327cb99 --- /dev/null +++ b/mach/m68k2/liboc/compmodule @@ -0,0 +1,6 @@ +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then + echo `basename $1 $2`.o +else + exit 1 +fi diff --git a/mach/m68k4/liboc/Makefile b/mach/m68k4/liboc/Makefile new file mode 100644 index 00000000..1da3ddb9 --- /dev/null +++ b/mach/m68k4/liboc/Makefile @@ -0,0 +1,20 @@ +SUF=o +MAKEFILE=../../proto/libg/Makefile +MACHDEF="MACH=m68k4" "SUF=$(SUF)" +PCDEF="PREF=ocm" "SUB=" "SRC=lang/occam/lib" + +install: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) tailcp + +cmp: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) tail + -../../compare tail_ocm + +clean: + -rm -f *.old *.[ce$(SUF)] tail* + +opr: + make pr | opr + +pr: + @pr Makefile diff --git a/mach/m68k4/liboc/compmodule b/mach/m68k4/liboc/compmodule new file mode 100755 index 00000000..6327cb99 --- /dev/null +++ b/mach/m68k4/liboc/compmodule @@ -0,0 +1,6 @@ +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then + echo `basename $1 $2`.o +else + exit 1 +fi diff --git a/mach/ns/liboc/Makefile b/mach/ns/liboc/Makefile new file mode 100644 index 00000000..28ecb4bb --- /dev/null +++ b/mach/ns/liboc/Makefile @@ -0,0 +1,20 @@ +SUF=o +MAKEFILE=../../proto/libg/Makefile +MACHDEF="MACH=ns" "SUF=$(SUF)" "ASAR=aal" +PCDEF="PREF=ocm" "SUB=" "SRC=lang/occam/lib" + +install: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) tailcp + +cmp: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) tail + -../../compare tail_ocm + +clean: + -rm -f *.old *.[ce$(SUF)] tail* + +opr: + make pr | opr + +pr: + @pr Makefile diff --git a/mach/ns/liboc/compmodule b/mach/ns/liboc/compmodule new file mode 100755 index 00000000..6327cb99 --- /dev/null +++ b/mach/ns/liboc/compmodule @@ -0,0 +1,6 @@ +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then + echo `basename $1 $2`.o +else + exit 1 +fi diff --git a/mach/pdp/liboc/Makefile b/mach/pdp/liboc/Makefile new file mode 100644 index 00000000..3447c000 --- /dev/null +++ b/mach/pdp/liboc/Makefile @@ -0,0 +1,21 @@ +SUF=o +MAKEFILE=../../proto/libg/Makefile +MACHDEF="MACH=pdp" "SUF=$(SUF)" "ASAR=ar" +PCDEF="PREF=ocm" "SUB=" "SRC=lang/occam/lib" + +install: + RANLIB=ranlib ; export RANLIB ;\ + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) tailcp + +cmp: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) tail + -../../compare tail_ocm + +clean: + -rm -f *.old *.[ce$(SUF)] tail* + +opr: + make pr | opr + +pr: + @pr Makefile diff --git a/mach/pdp/liboc/compmodule b/mach/pdp/liboc/compmodule new file mode 100755 index 00000000..6327cb99 --- /dev/null +++ b/mach/pdp/liboc/compmodule @@ -0,0 +1,6 @@ +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then + echo `basename $1 $2`.o +else + exit 1 +fi diff --git a/mach/z80/liboc/Makefile b/mach/z80/liboc/Makefile new file mode 100644 index 00000000..5d0f79d6 --- /dev/null +++ b/mach/z80/liboc/Makefile @@ -0,0 +1,20 @@ +SUF=o +MAKEFILE=../../proto/libg/Makefile +MACHDEF="MACH=z80" "SUF=$(SUF)" "ASAR=aal" +PCDEF="PREF=ocm" "SUB=" "SRC=lang/occam/lib" + +install: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) tailcp + +cmp: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) tail + -../../compare tail_ocm + +clean: + -rm -f *.old *.[ce$(SUF)] tail* + +opr: + make pr | opr + +pr: + @pr Makefile diff --git a/mach/z80/liboc/compmodule b/mach/z80/liboc/compmodule new file mode 100755 index 00000000..6327cb99 --- /dev/null +++ b/mach/z80/liboc/compmodule @@ -0,0 +1,6 @@ +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then + echo `basename $1 $2`.o +else + exit 1 +fi diff --git a/mach/z8000/liboc/Makefile b/mach/z8000/liboc/Makefile new file mode 100644 index 00000000..47930326 --- /dev/null +++ b/mach/z8000/liboc/Makefile @@ -0,0 +1,20 @@ +SUF=s +MAKEFILE=../../proto/libg/Makefile +MACHDEF="MACH=z8000" "SUF=$(SUF)" +PCDEF="PREF=ocm" "SUB=" "SRC=lang/occam/lib" + +install: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) tailcp + +cmp: + make -f $(MAKEFILE) $(PCDEF) $(MACHDEF) tail + -../../compare tail_ocm + +clean: + -rm -f *.old *.[ce$(SUF)] tail* + +opr: + make pr | opr + +pr: + @pr Makefile diff --git a/mach/z8000/liboc/compmodule b/mach/z8000/liboc/compmodule new file mode 100755 index 00000000..8dba8a44 --- /dev/null +++ b/mach/z8000/liboc/compmodule @@ -0,0 +1,6 @@ +if ${MACH?} -I../../../h ${MACHFL?} $1 1>&2 +then + echo `basename $1 $2`.s +else + exit 1 +fi From 1415aebba4f93d41a2dd85a9bbdc4345aab96424 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 25 Feb 1987 19:45:18 +0000 Subject: [PATCH 0900/1625] *** empty log message *** --- mach/m68k4/liboc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mach/m68k4/liboc/Makefile b/mach/m68k4/liboc/Makefile index 1da3ddb9..e3d7e952 100644 --- a/mach/m68k4/liboc/Makefile +++ b/mach/m68k4/liboc/Makefile @@ -1,6 +1,6 @@ SUF=o MAKEFILE=../../proto/libg/Makefile -MACHDEF="MACH=m68k4" "SUF=$(SUF)" +MACHDEF="MACH=m68k4" "SUF=$(SUF)" "ASAR=aal" PCDEF="PREF=ocm" "SUB=" "SRC=lang/occam/lib" install: From 9e8f56104456d0e72ec08ac5130cf3e7f2d96c3b Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 25 Feb 1987 19:45:49 +0000 Subject: [PATCH 0901/1625] Added Occam --- mach/6500/Action | 3 +++ mach/em22/Action | 3 +++ mach/em44/Action | 3 +++ mach/i80/Action | 3 +++ mach/m68k2/Action | 3 +++ mach/m68k4/Action | 7 +++++-- mach/ns/Action | 5 ++++- mach/z80/Action | 3 +++ mach/z8000/Action | 3 +++ 9 files changed, 30 insertions(+), 3 deletions(-) diff --git a/mach/6500/Action b/mach/6500/Action index f44879f1..efbbfe1c 100644 --- a/mach/6500/Action +++ b/mach/6500/Action @@ -19,3 +19,6 @@ end name "MSC6500 Basic library" dir libbc end +name "MSC6500 Occam library" +dir liboc +end diff --git a/mach/em22/Action b/mach/em22/Action index afe32803..65d5b5cc 100644 --- a/mach/em22/Action +++ b/mach/em22/Action @@ -7,3 +7,6 @@ end name "2-2 Interpreter Basic library" dir libbc end +name "2-2 Interpreter Occam library" +dir liboc +end diff --git a/mach/em44/Action b/mach/em44/Action index e507c112..d94afd87 100644 --- a/mach/em44/Action +++ b/mach/em44/Action @@ -7,3 +7,6 @@ end name "4-4 Interpreter Basic library" dir libbc end +name "4-4 Interpreter Occam library" +dir liboc +end diff --git a/mach/i80/Action b/mach/i80/Action index 28050e3a..dd521e83 100644 --- a/mach/i80/Action +++ b/mach/i80/Action @@ -10,6 +10,9 @@ end name "Intel 8080 Basic library" dir libbc end +name "Intel 8080 Occam library" +dir liboc +end name "Intel 8080 C libraries" dir libcc end diff --git a/mach/m68k2/Action b/mach/m68k2/Action index 9e0885cf..080cc47d 100644 --- a/mach/m68k2/Action +++ b/mach/m68k2/Action @@ -25,6 +25,9 @@ end name "Motorola 68000 2-4 Basic library" dir libbc end +name "Motorola 68000 2-4 Occam library" +dir liboc +end name "Motorola 68000 interpreters" system m68* dir int diff --git a/mach/m68k4/Action b/mach/m68k4/Action index 9efd6d97..e2b44c99 100644 --- a/mach/m68k4/Action +++ b/mach/m68k4/Action @@ -10,9 +10,12 @@ end name "M68000 4-4 C libraries" dir libcc end -name "M68000 4-4 Basic libraries" +name "M68000 4-4 Basic library" dir libbc end -name "M68000 4-4 Pascal libraries" +name "M68000 4-4 Pascal library" dir libpc end +name "M68000 4-4 Occam library" +dir liboc +end diff --git a/mach/ns/Action b/mach/ns/Action index b58ea145..d7419057 100644 --- a/mach/ns/Action +++ b/mach/ns/Action @@ -16,6 +16,9 @@ end name "NS16032 PC library" dir libpc end -name "NS16032 Basic libraries" +name "NS16032 Basic library" dir libbc end +name "NS16032 Occam library" +dir liboc +end diff --git a/mach/z80/Action b/mach/z80/Action index d0480948..9abd7dd7 100644 --- a/mach/z80/Action +++ b/mach/z80/Action @@ -7,6 +7,9 @@ end name "Z80 Basic library" dir libbc end +name "Z80 Occam library" +dir liboc +end name "Z80 C libraries" dir libcc end diff --git a/mach/z8000/Action b/mach/z8000/Action index 6134c947..a1c42c26 100644 --- a/mach/z8000/Action +++ b/mach/z8000/Action @@ -16,3 +16,6 @@ end name "Zilog Z8000 Basic library" dir libbc end +name "Zilog Z8000 Occam library" +dir liboc +end From 7ae5f0b764bff0208935c77e3397481e0967c91f Mon Sep 17 00:00:00 2001 From: ceriel Date: Thu, 26 Feb 1987 09:55:46 +0000 Subject: [PATCH 0902/1625] Initial revision --- h/ocm_chan.h | 47 ++++++++++++++++++++++++++++++++++++++++++ h/ocm_parco.h | 18 +++++++++++++++++ h/ocm_proc.h | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 h/ocm_chan.h create mode 100644 h/ocm_parco.h create mode 100644 h/ocm_proc.h diff --git a/h/ocm_chan.h b/h/ocm_chan.h new file mode 100644 index 00000000..ff66f859 --- /dev/null +++ b/h/ocm_chan.h @@ -0,0 +1,47 @@ +/* ocm_chan.h - channel definitions */ +#include +#include "ocm_parco.h" + +typedef union channel { + struct { /* Interprocess channel */ + char _type; /* Channel type, see note */ + char synch; /* State in channel synchronization */ + long val; /* Transmitted value */ + } c; + struct { /* File channel */ + char _type; /* Dummy field, see note */ + char index; /* Index in the file array */ + char flgs; /* Status flags: in use & readahead */ + char preread; /* Possible preread character */ + } f; +} chan; +#define type c._type /* Channel type */ +/* Note: The channel type should not be part of each structure in chan. But + * the C alignment rules would make chan about 50% bigger if we had done it + * the right way. Note that the order of fields in a struct cannot be a problem + * as long as struct c is the largest within the union. + */ + +#define C_T_CHAN 0 /* Type of a interprocess channel */ +#define C_T_FILE 1 /* Type of a file channel */ + +#define C_S_FREE 0 /* IP channel is free */ +#define C_S_ANY 1 /* IP channel contains data */ +#define C_S_ACK 2 /* IP channel data is removed */ + +#define C_F_EOF (-1L) /* File channel returns EOF */ +#define C_F_TEXT (-2L) /* File channel becomes line oriented */ +#define C_F_RAW (-3L) /* File channel becomes character oriented */ + +#define C_F_INUSE 0x01 /* File channel is connected to a UNIX file */ +#define C_F_READAHEAD 0x02 /* File channel has a preread character */ + +extern chan file[20]; /* Array of file channels */ +extern FILE *unix_file[20]; /* Pointers to buffered UNIX files */ + +void c_init(); + +void chan_in(), cbyte_in(), c_wa_in(), c_ba_in(); +void chan_out(), c_wa_out(), c_ba_out(); + +int chan_any(); diff --git a/h/ocm_parco.h b/h/ocm_parco.h new file mode 100644 index 00000000..1588d43c --- /dev/null +++ b/h/ocm_parco.h @@ -0,0 +1,18 @@ +/* parco.h - Define names for simulation routines + * + * This file is to be included by users of the higher-level routines + * + */ + +void pc_begin(), resumenext(), parend(), resume(), coend(); +int pc_fork(); + +#define nullid ((int *) 0 - (int *) 0) + /* I.e. a 0 of type "pointer difference" */ + +#define parbegin(sbrk) pc_begin(sbrk, nullid) +#define parfork() pc_fork(nullid) +#define cobegin(sbrk, id) pc_begin(sbrk, id) +#define cofork(id) pc_fork(id) + +extern int deadlock; diff --git a/h/ocm_proc.h b/h/ocm_proc.h new file mode 100644 index 00000000..3f716e81 --- /dev/null +++ b/h/ocm_proc.h @@ -0,0 +1,56 @@ +/* process.h - Define administration types and functions + * + * This file is to be included by implementors of the higher + * level routines + * + */ +#include "ocm_parco.h" + +#ifndef ptrdiff /* This type must be able to hold a pointer difference */ +#if EM_WSIZE